[GH-ISSUE #1553] [Issue]: Long-Term Memory server: split the 2,740-line subject identity file into four files #1545

Closed
opened 2026-10-23 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/1553

Originally assigned to: @Promansis on GitHub.

Summary

The Long-Term Memory server keeps all of subject identity in one file, identity/subject-identity.ts, which is 2,740 lines long. Name text rules, the trusted subject catalog's lookup index and matchers, building and loading that catalog from the roster and stored notes, and resolving a batch's subjects all sit side by side, so a change to one of them means reading through the rest. This issue splits the file into four files, each importing only from the ones before it. It is a pure move with no behavior change.

Affected package

long-term-memory 1.4.78 (upstream/staging 8602e266d).

  • S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory
  • S/identity/subject-identity.ts: 2,740 lines, 99 top-level statements.
  • Seven server files import from it: S/extraction/evidence-unit-extraction.ts, S/extraction/source-extraction.ts, S/extraction/source-processing.ts, S/identity/identity-repair.ts, S/identity/subject-choice-review.ts, S/routes/maintenance.ts, S/routes/notes.ts. Four regression files load it with a dynamic import() of the module path: the routes, extraction-graph, local-characters and storage tests.

Expected behavior

  • The code lives in four files under S/identity/, ordered so each imports only from the ones above it, which rules out a cycle between them.
  • subject-identity.ts keeps its name and the resolution code, so importers of what stays need no change.
  • docs/ARCHITECTURE.md lists the three new files in its identity/ row.
  • Every extraction, identity repair, subject review and route path behaves exactly as before.

Actual behavior

All of it is in one file:

Part Lines Symbols Holds
identity/subject-names.ts (new) 365 23 Name text rules: proper-name and NPC patterns, generic role names, Hangul particles, edit distance, identifier normalizing. Reads no note and no catalog.
identity/subject-matching.ts (new) 479 31 The catalog's types, its lookup index and the matchers that read it (direct, fuzzy, trait prefix, relationship, legacy, collision diagnosis), plus subject key and sort helpers.
identity/subject-catalog.ts (new) 647 22 Building and loading the trusted catalog from the roster and stored notes, the prompt catalog, and checking stored notes against it. The only new part that reads storage, as the original did.
identity/subject-identity.ts (kept) 1,339 23 Resolution: preparing a context and resolving a batch's subject names, unit subjects and link targets.

(The table is the proposed split; line counts are from a dry run on 8602e266d, after Prettier.)

Steps to reproduce

  1. wc -l S/identity/subject-identity.ts on upstream/staging: 2,740 lines.

Minimal fix

  1. One scripted move. A script outside the repository moves each top-level statement of subject-identity.ts, by symbol name and unchanged, into its part file, adds the imports each part needs, and runs Prettier on the touched files. A check compares every moved statement with the original: 98 of 99 verbatim on the dry run (ignoring an added export); the 99th, matchTrustedNameRelation, differs only by Prettier wrapping its now longer signature. The PR describes the script.
  2. Importers. The script rewrites the import of each moved name in the seven server files and four regression files above, one specifier per target file. No re-export shim is left in subject-identity.ts, so each name has one import path.
  3. Newly exported names. 36 names that were private to the file are used by another part, so they become exports. None is re-exported from a package entry point, so the package surface does not change.
  4. Docs. Add subject-names, subject-matching and subject-catalog to the identity/ row of docs/ARCHITECTURE.md.
  5. Release. The built server.mjs changes only in module order and one extra createHash import from node:crypto (+42 bytes); client.js is unchanged. 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 two existing type-only cycles do not involve these files), the strict package typecheck (the three 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.78
  • Install type: source
  • OS + version: n/a
  • Browser or app shell: n/a

Logs, screenshots, or video

n/a

Additional context

Tracker item ST-2 (structural audit, step 4; also RT-6). The shared schema file was split the same way in #1536, and the server files were moved into area folders in #1463. Any open PR that edits subject-identity.ts or one of the importers' import lines will conflict with this one: #1552 adds to the extraction-graph test, so this lands after it, with the script re-run on the then-current staging.

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/1553 Originally assigned to: @Promansis on GitHub. ## Summary The Long-Term Memory server keeps all of subject identity in one file, `identity/subject-identity.ts`, which is 2,740 lines long. Name text rules, the trusted subject catalog's lookup index and matchers, building and loading that catalog from the roster and stored notes, and resolving a batch's subjects all sit side by side, so a change to one of them means reading through the rest. This issue splits the file into four files, each importing only from the ones before it. It is a pure move with no behavior change. ## Affected package `long-term-memory` 1.4.78 (`upstream/staging` 8602e266d). - `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` - `S/identity/subject-identity.ts`: 2,740 lines, 99 top-level statements. - Seven server files import from it: `S/extraction/evidence-unit-extraction.ts`, `S/extraction/source-extraction.ts`, `S/extraction/source-processing.ts`, `S/identity/identity-repair.ts`, `S/identity/subject-choice-review.ts`, `S/routes/maintenance.ts`, `S/routes/notes.ts`. Four regression files load it with a dynamic `import()` of the module path: the routes, extraction-graph, local-characters and storage tests. ## Expected behavior - The code lives in four files under `S/identity/`, ordered so each imports only from the ones above it, which rules out a cycle between them. - `subject-identity.ts` keeps its name and the resolution code, so importers of what stays need no change. - `docs/ARCHITECTURE.md` lists the three new files in its `identity/` row. - Every extraction, identity repair, subject review and route path behaves exactly as before. ## Actual behavior All of it is in one file: | Part | Lines | Symbols | Holds | | --- | ---: | ---: | --- | | `identity/subject-names.ts` (new) | 365 | 23 | Name text rules: proper-name and NPC patterns, generic role names, Hangul particles, edit distance, identifier normalizing. Reads no note and no catalog. | | `identity/subject-matching.ts` (new) | 479 | 31 | The catalog's types, its lookup index and the matchers that read it (direct, fuzzy, trait prefix, relationship, legacy, collision diagnosis), plus subject key and sort helpers. | | `identity/subject-catalog.ts` (new) | 647 | 22 | Building and loading the trusted catalog from the roster and stored notes, the prompt catalog, and checking stored notes against it. The only new part that reads storage, as the original did. | | `identity/subject-identity.ts` (kept) | 1,339 | 23 | Resolution: preparing a context and resolving a batch's subject names, unit subjects and link targets. | (The table is the proposed split; line counts are from a dry run on 8602e266d, after Prettier.) ## Steps to reproduce 1. `wc -l S/identity/subject-identity.ts` on `upstream/staging`: 2,740 lines. ## Minimal fix 1. **One scripted move.** A script outside the repository moves each top-level statement of `subject-identity.ts`, by symbol name and unchanged, into its part file, adds the imports each part needs, and runs Prettier on the touched files. A check compares every moved statement with the original: 98 of 99 verbatim on the dry run (ignoring an added `export`); the 99th, `matchTrustedNameRelation`, differs only by Prettier wrapping its now longer signature. The PR describes the script. 2. **Importers.** The script rewrites the import of each moved name in the seven server files and four regression files above, one specifier per target file. No re-export shim is left in `subject-identity.ts`, so each name has one import path. 3. **Newly exported names.** 36 names that were private to the file are used by another part, so they become exports. None is re-exported from a package entry point, so the package surface does not change. 4. **Docs.** Add `subject-names`, `subject-matching` and `subject-catalog` to the `identity/` row of `docs/ARCHITECTURE.md`. 5. **Release.** The built `server.mjs` changes only in module order and one extra `createHash` import from `node:crypto` (+42 bytes); `client.js` is unchanged. 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 two existing type-only cycles do not involve these files), the strict package typecheck (the three 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.78 - Install type: source - OS + version: n/a - Browser or app shell: n/a ## Logs, screenshots, or video n/a ## Additional context Tracker item ST-2 (structural audit, step 4; also RT-6). The shared schema file was split the same way in #1536, and the server files were moved into area folders in #1463. Any open PR that edits `subject-identity.ts` or one of the importers' import lines will conflict with this one: #1552 adds to the extraction-graph test, so this lands after it, with the script re-run on the then-current `staging`. ## 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-23 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#1545
No description provided.