[GH-ISSUE #1536] [Issue]: Long-Term Memory shared layer: split the 3,282-line schema file into ten area files #1514

Closed
opened 2026-10-22 04:02:50 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1536

Originally assigned to: @Promansis on GitHub.

Summary

The Long-Term Memory shared layer keeps every zod schema and its type in one file, schema.ts, which is 3,282 lines long. Settings, notes, indexes, drafts, sources, recall reports and the backup format sit side by side, so a change to one area means scrolling through all of them, and constants.ts and schema.ts import each other's types. This issue splits the file into ten area files behind a barrel. It is a pure move with no behavior change.

Affected package

long-term-memory 1.4.69 (upstream/staging 5984f0784).

  • SH = packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory
  • SH/schema.ts: 3,282 lines. About 95 files import it through ./schema.js or a relative path to it: 58 server files, 30 client files, 6 shared files (including the shared index.ts, which re-exports it) and the tests.
  • SH/constants.ts reads four types from ./schema.js, while the settings, drafts, sources and backup schemas read its prompt constants: a type-only import cycle.

Expected behavior

  • SH/schema.ts becomes a barrel of export * from "./schema/<part>.js", so every importer keeps its specifier.
  • The code lives in ten files under SH/schema/, each holding one area. Each file imports only from the files before it, so every schema is defined before it is used and the files cannot form a cycle.
  • docs/ARCHITECTURE.md names the schema/ folder and what each file holds.
  • Every endpoint, recall, extraction, storage and settings path behaves exactly as before.

Actual behavior

All of it is in one file:

Part Lines Holds
schema/primitives.ts 337 Ids, titles, statuses, modes, vault folders and id prefixes, timestamps, safe paths, subjects, scope, links, importance, relationship dimensions, provenance, interop source, identity match basis, extraction effort and verbosity. Imports nothing local.
schema/settings.ts 474 Global, extraction (prompt templates and legacy-mode folding), policies, retrieval, retention and agent settings.
schema/debug.ts 60 Debug event status, phase, error and event.
schema/recall.ts 95 Last-injection and recall-attempt reports, semantic and index-load outcomes, usage.
schema/notes.ts 735 Evidence units, sections and contributions, conflicts, the note, bulk actions, vault events, transfer, section rename and delete, fork.
schema/indexes.ts 369 Chunks; embedding, BM25, graph, keyword and metadata indexes; index state, status, integrity and repair.
schema/identity.ts 210 Identity repair, subject identity review and decisions, saved identity choices.
schema/drafts.ts 604 Drafts, mutations, extraction outcome, diagnostics and accounting, review, preflight, rejected suggestions, extract-source requests.
schema/sources.ts 471 Sources workspace requests and responses: interop and lorebook previews, source details, importing source notes.
schema/backup.ts 46 The backup schema, which reads settings, notes and drafts, so it comes last.

(The table is the proposed split; line counts are from a dry run on 5984f0784.)

Steps to reproduce

  1. wc -l SH/schema.ts on upstream/staging: 3,282 lines.
  2. SH/constants.ts:1-2 import types from ./schema.js; SH/schema.ts imports prompt constants from ./constants.js.

Minimal fix

  1. One scripted move. A script outside the repository moves each top-level statement of schema.ts, by symbol name and unchanged, into its part file, adds the imports each part needs, and leaves schema.ts as the ten-line barrel. A check compares every moved statement with the original (377 of 377 verbatim on the dry run, ignoring an added export). The PR describes the script.
  2. The cycle. constants.ts's two import type lines point at ./schema/primitives.js instead of ./schema.js, since primitives.ts imports nothing from constants.ts. These are the only specifiers outside schema/ that change.
  3. Newly exported names. Seven names that were private to schema.ts are used by a later part, so they become exports, and through the barrel and the shared index.ts part of the shared package surface: LTM_EXTRACTION_MODES, ltmStringRecordSchema, ltmIdentifierSchema, hasLocalCharacterSubject, allowedStoredNoteIdPrefixes, ltmPoliciesConfigSchema, ltmRetrievalConfigSchema. None collides with an existing name. Listing the old exports one by one in the barrel (about 600 names) would keep the surface identical, but every new schema would then need a barrel edit, so the barrel stays export *.
  4. Docs. Add the schema/ folder and its files to docs/ARCHITECTURE.md.
  5. Release. The built server.mjs gains one import { z } from "zod" per part (zod is external in the server build); client.js changes only in module order. Rebuild the package and ship it as a patch release.

Regression proof

No behavior changes, so no new regression. The proof is the move check above, the import-cycle check (value cycles 0 before and after; the constants.ts–schema.ts type cycle is gone), the strict package typecheck (the ten new files are in its scope), npm run check, and every Long-Term Memory regression suite unchanged and passing.

Environment

  • Marinara Engine version: n/a (source structure)
  • Package version: long-term-memory 1.4.69
  • Install type: source
  • OS + version: n/a
  • Browser or app shell: n/a

Logs, screenshots, or video

n/a

Additional context

Tracker item ST-4 (structural audit, step 6). The server files were moved into area folders the same way in #1463. Any open PR that edits schema.ts will conflict with this one and must re-apply its change in the new part file; none is open.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1536 Originally assigned to: @Promansis on GitHub. ## Summary The Long-Term Memory shared layer keeps every zod schema and its type in one file, `schema.ts`, which is 3,282 lines long. Settings, notes, indexes, drafts, sources, recall reports and the backup format sit side by side, so a change to one area means scrolling through all of them, and `constants.ts` and `schema.ts` import each other's types. This issue splits the file into ten area files behind a barrel. It is a pure move with no behavior change. ## Affected package `long-term-memory` 1.4.69 (`upstream/staging` 5984f0784). - `SH` = `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory` - `SH/schema.ts`: 3,282 lines. About 95 files import it through `./schema.js` or a relative path to it: 58 server files, 30 client files, 6 shared files (including the shared `index.ts`, which re-exports it) and the tests. - `SH/constants.ts` reads four types from `./schema.js`, while the settings, drafts, sources and backup schemas read its prompt constants: a type-only import cycle. ## Expected behavior - `SH/schema.ts` becomes a barrel of `export * from "./schema/<part>.js"`, so every importer keeps its specifier. - The code lives in ten files under `SH/schema/`, each holding one area. Each file imports only from the files before it, so every schema is defined before it is used and the files cannot form a cycle. - `docs/ARCHITECTURE.md` names the `schema/` folder and what each file holds. - Every endpoint, recall, extraction, storage and settings path behaves exactly as before. ## Actual behavior All of it is in one file: | Part | Lines | Holds | | --- | ---: | --- | | `schema/primitives.ts` | 337 | Ids, titles, statuses, modes, vault folders and id prefixes, timestamps, safe paths, subjects, scope, links, importance, relationship dimensions, provenance, interop source, identity match basis, extraction effort and verbosity. Imports nothing local. | | `schema/settings.ts` | 474 | Global, extraction (prompt templates and legacy-mode folding), policies, retrieval, retention and agent settings. | | `schema/debug.ts` | 60 | Debug event status, phase, error and event. | | `schema/recall.ts` | 95 | Last-injection and recall-attempt reports, semantic and index-load outcomes, usage. | | `schema/notes.ts` | 735 | Evidence units, sections and contributions, conflicts, the note, bulk actions, vault events, transfer, section rename and delete, fork. | | `schema/indexes.ts` | 369 | Chunks; embedding, BM25, graph, keyword and metadata indexes; index state, status, integrity and repair. | | `schema/identity.ts` | 210 | Identity repair, subject identity review and decisions, saved identity choices. | | `schema/drafts.ts` | 604 | Drafts, mutations, extraction outcome, diagnostics and accounting, review, preflight, rejected suggestions, extract-source requests. | | `schema/sources.ts` | 471 | Sources workspace requests and responses: interop and lorebook previews, source details, importing source notes. | | `schema/backup.ts` | 46 | The backup schema, which reads settings, notes and drafts, so it comes last. | (The table is the proposed split; line counts are from a dry run on 5984f0784.) ## Steps to reproduce 1. `wc -l SH/schema.ts` on `upstream/staging`: 3,282 lines. 2. `SH/constants.ts:1-2` import types from `./schema.js`; `SH/schema.ts` imports prompt constants from `./constants.js`. ## Minimal fix 1. **One scripted move.** A script outside the repository moves each top-level statement of `schema.ts`, by symbol name and unchanged, into its part file, adds the imports each part needs, and leaves `schema.ts` as the ten-line barrel. A check compares every moved statement with the original (377 of 377 verbatim on the dry run, ignoring an added `export`). The PR describes the script. 2. **The cycle.** `constants.ts`'s two `import type` lines point at `./schema/primitives.js` instead of `./schema.js`, since `primitives.ts` imports nothing from `constants.ts`. These are the only specifiers outside `schema/` that change. 3. **Newly exported names.** Seven names that were private to `schema.ts` are used by a later part, so they become exports, and through the barrel and the shared `index.ts` part of the shared package surface: `LTM_EXTRACTION_MODES`, `ltmStringRecordSchema`, `ltmIdentifierSchema`, `hasLocalCharacterSubject`, `allowedStoredNoteIdPrefixes`, `ltmPoliciesConfigSchema`, `ltmRetrievalConfigSchema`. None collides with an existing name. Listing the old exports one by one in the barrel (about 600 names) would keep the surface identical, but every new schema would then need a barrel edit, so the barrel stays `export *`. 4. **Docs.** Add the `schema/` folder and its files to `docs/ARCHITECTURE.md`. 5. **Release.** The built `server.mjs` gains one `import { z } from "zod"` per part (zod is external in the server build); `client.js` changes only in module order. Rebuild the package and ship it as a patch release. ## Regression proof No behavior changes, so no new regression. The proof is the move check above, the import-cycle check (value cycles 0 before and after; the `constants.ts`–`schema.ts` type cycle is gone), the strict package typecheck (the ten new files are in its scope), `npm run check`, and every Long-Term Memory regression suite unchanged and passing. ## Environment - Marinara Engine version: n/a (source structure) - Package version: `long-term-memory` 1.4.69 - Install type: source - OS + version: n/a - Browser or app shell: n/a ## Logs, screenshots, or video n/a ## Additional context Tracker item ST-4 (structural audit, step 6). The server files were moved into area folders the same way in #1463. Any open PR that edits `schema.ts` will conflict with this one and must re-apply its change in the new part file; none is open. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-22 04:02:50 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1514
No description provided.