[GH-ISSUE #1463] [Issue]: Long-Term Memory server: move the 68 flat server files into area folders #743

Closed
opened 2026-10-20 17:30:17 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

The Long-Term Memory server has 68 source files in one flat folder; routes/ is its only subfolder. The files fall into clear areas (persistence, recall, extraction, identity, drafts, maintenance), but the folder doesn't show them, and docs/ARCHITECTURE.md has no module map. This issue moves the files into one folder per area and adds that map. It is a pure move with no behavior change. (Tracker items ST-3 and ST-1, from the structural audit.)

Affected package

long-term-memory 1.4.53 (upstream/staging 40ff75368).

  • S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory
  • Every file in S/ except routes/. The server files import each other through relative specifiers (./storage.js, and ../../../../shared/... for the shared layer).
  • 17 test files under tests/ import server files by path, including tests/long-term-memory-source-paths.mjs.
  • The build (scripts/build-feature-packages.mjs:92), the catalog validator (scripts/validate-catalog.mjs:248) and the CI path filters all treat S as a whole directory, so subfolders need no script change. Nothing in S resolves paths at runtime (import.meta, __dirname), and no client or shared file imports from S.

Expected behavior

  • The server files live in area folders. Only the host entry points and shared utilities stay at the top level.
  • docs/ARCHITECTURE.md lists each folder, what it owns and its files.
  • Every endpoint, recall, extraction and storage path behaves exactly as before.

Actual behavior

68 files sit side by side in S/. Finding 3 of the structural audit grouped them by name; the grouping below was checked against their importers at 40ff75368:

Folder Files
top level (unchanged) server-entry, runtime, package-runtime, routes, settings, default-config, service-error, ltm-utils (8)
persistence/ storage, mutation-transaction, atomic-json, paths, vault-lock, vault-snapshot, stored-note, index-state, index-quarantine, retention, backup-restore, restore-recovery, activity-index, section-contributions (14)
recall/ chunking, bm25, keyword-extract, keyword-index, hangul-lexical, graph, metadata-index, ranking, budget, prompt, prompt-text, retrieval, rebuild, embedding-adapter, generation-injection, usage (16)
extraction/ evidence-unit-compiler, evidence-unit-extraction, evidence-unit-validation, structured-summary-normalizer, source-extraction, source-processing, source-hash, dedup, candidate-reconciliation, scoped-targets, extraction-config (11)
identity/ subject-identity, subject-choice-review, subject-equality, identity-repair, note-fork-repair, chat-scope, scope-links (7)
drafts/ draft-projector, draft-review, draft-store, reconciliation, rejected-suggestions (5)
maintenance/ maintenance, note-transfer, legacy-adoption, legacy-source-quarantine, debug-log (5)
sources/ interop, source-identity (2)
routes/ (unchanged) drafts, imports, maintenance, notes, settings, shared (6)

Two placements differ from the audit's sketch:

  • activity-index and section-contributions go in persistence/, because only storage, mutation and retention code imports them.
  • interop (Engine chat import) and source-identity (used only by interop) go in sources/. That is where the planned conversation-transcript source will live, so interop moves once.

Steps to reproduce

  1. git ls-tree --name-only upstream/staging S/: 68 files and one folder.
  2. docs/ARCHITECTURE.md names individual modules in its sections but has no map from area to files.

Minimal fix

  1. One scripted move.
    • git mv each file into its folder, as in the table above.
    • Rewrite only the relative import specifiers that the move breaks:
      • in the moved files themselves, including their ../../../../shared/... imports, which gain one ../;
      • in the top-level files and routes/*.ts;
      • in the 17 test files.
    • Change no other line, so git detects every move as a rename.
    • The rewrite script stays outside the repository. The PR describes it.
  2. Tests. Update ltmSourcePaths.interop in tests/long-term-memory-source-paths.mjs and each direct or ${source}/… server import in the tests. Assertions stay unchanged.
  3. Docs (ST-1).
    • Add a "Server modules" section to docs/ARCHITECTURE.md: one row per folder with its responsibility and files, plus the allowed direction of imports (persistence/ is the bottom layer).
    • Prefix the module names the other sections already cite with their folder where that helps.
  4. Release. server.mjs is minified, contains no source paths, and orders modules by import graph, so the rebuild is expected to be byte-identical.
    • If it is: no version bump, CHANGELOG entry, zip or catalog change.
    • If it isn't: a patch release at land, with a one-line CHANGELOG entry saying that the server files were reorganized with no behavior change.

Not included

  • Splitting subject-identity.ts (2,735 lines) or storage.ts (ST-2), or schema.ts (ST-4).
  • Renaming interop.ts or any of the look-alike file names (audit finding 6).
  • Client or shared folders.
  • A lint rule that enforces the import direction.

Regression proof

  • node scripts/typecheck-packages.mjs long-term-memory passes, so every rewritten specifier resolves.
  • After the rebuild, cmp of server.mjs and client.js against upstream/staging (or the patch-release path from step 4).
  • git diff -M --summary upstream/staging lists 60 renames and no delete/add pairs. Only the 8 top-level files remain in S/.
  • The full LTM suite (test-ltm.sh all, with MARINARA_AGENTS_ROOT and MARINARA_ENGINE_ROOT set) and test-fast.sh, because every server file moves.
  • npm run check and the AGENTS.md baseline validators.

Environment

  • Marinara Engine version: any (no runtime change)
  • Package version: long-term-memory 1.4.53 (upstream/staging 40ff75368)
  • Install type: source
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. Structural audit (2026-10-15, LTM 1.4.38), step 5 and finding 9, re-checked at 40ff75368 on 2026-10-19.

Additional context

  • Tracker items ST-3 and ST-1. Step 3 of the audit (the routes.ts split) shipped in #1419. The six-file import loop from step 4 was removed in #1416, so the move no longer stretches a loop across folders.
  • Timing: this conflicts with every open LTM server branch, so it lands while none is open. None is open on 2026-10-19.

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 18, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1463 Originally assigned to: @Promansis on GitHub. ## Summary The Long-Term Memory server has 68 source files in one flat folder; `routes/` is its only subfolder. The files fall into clear areas (persistence, recall, extraction, identity, drafts, maintenance), but the folder doesn't show them, and `docs/ARCHITECTURE.md` has no module map. This issue moves the files into one folder per area and adds that map. It is a pure move with no behavior change. (Tracker items ST-3 and ST-1, from the structural audit.) ## Affected package `long-term-memory` 1.4.53 (`upstream/staging` 40ff75368). - `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` - Every file in `S/` except `routes/`. The server files import each other through relative specifiers (`./storage.js`, and `../../../../shared/...` for the shared layer). - 17 test files under `tests/` import server files by path, including `tests/long-term-memory-source-paths.mjs`. - The build (`scripts/build-feature-packages.mjs:92`), the catalog validator (`scripts/validate-catalog.mjs:248`) and the CI path filters all treat `S` as a whole directory, so subfolders need no script change. Nothing in `S` resolves paths at runtime (`import.meta`, `__dirname`), and no client or shared file imports from `S`. ## Expected behavior - The server files live in area folders. Only the host entry points and shared utilities stay at the top level. - `docs/ARCHITECTURE.md` lists each folder, what it owns and its files. - Every endpoint, recall, extraction and storage path behaves exactly as before. ## Actual behavior 68 files sit side by side in `S/`. Finding 3 of the structural audit grouped them by name; the grouping below was checked against their importers at 40ff75368: | Folder | Files | |---|---| | top level (unchanged) | `server-entry`, `runtime`, `package-runtime`, `routes`, `settings`, `default-config`, `service-error`, `ltm-utils` (8) | | `persistence/` | `storage`, `mutation-transaction`, `atomic-json`, `paths`, `vault-lock`, `vault-snapshot`, `stored-note`, `index-state`, `index-quarantine`, `retention`, `backup-restore`, `restore-recovery`, `activity-index`, `section-contributions` (14) | | `recall/` | `chunking`, `bm25`, `keyword-extract`, `keyword-index`, `hangul-lexical`, `graph`, `metadata-index`, `ranking`, `budget`, `prompt`, `prompt-text`, `retrieval`, `rebuild`, `embedding-adapter`, `generation-injection`, `usage` (16) | | `extraction/` | `evidence-unit-compiler`, `evidence-unit-extraction`, `evidence-unit-validation`, `structured-summary-normalizer`, `source-extraction`, `source-processing`, `source-hash`, `dedup`, `candidate-reconciliation`, `scoped-targets`, `extraction-config` (11) | | `identity/` | `subject-identity`, `subject-choice-review`, `subject-equality`, `identity-repair`, `note-fork-repair`, `chat-scope`, `scope-links` (7) | | `drafts/` | `draft-projector`, `draft-review`, `draft-store`, `reconciliation`, `rejected-suggestions` (5) | | `maintenance/` | `maintenance`, `note-transfer`, `legacy-adoption`, `legacy-source-quarantine`, `debug-log` (5) | | `sources/` | `interop`, `source-identity` (2) | | `routes/` (unchanged) | `drafts`, `imports`, `maintenance`, `notes`, `settings`, `shared` (6) | Two placements differ from the audit's sketch: - `activity-index` and `section-contributions` go in `persistence/`, because only storage, mutation and retention code imports them. - `interop` (Engine chat import) and `source-identity` (used only by `interop`) go in `sources/`. That is where the planned conversation-transcript source will live, so `interop` moves once. ## Steps to reproduce 1. `git ls-tree --name-only upstream/staging S/`: 68 files and one folder. 2. `docs/ARCHITECTURE.md` names individual modules in its sections but has no map from area to files. ## Minimal fix 1. **One scripted move.** - `git mv` each file into its folder, as in the table above. - Rewrite only the relative import specifiers that the move breaks: - in the moved files themselves, including their `../../../../shared/...` imports, which gain one `../`; - in the top-level files and `routes/*.ts`; - in the 17 test files. - Change no other line, so git detects every move as a rename. - The rewrite script stays outside the repository. The PR describes it. 2. **Tests.** Update `ltmSourcePaths.interop` in `tests/long-term-memory-source-paths.mjs` and each direct or `${source}/…` server import in the tests. Assertions stay unchanged. 3. **Docs (ST-1).** - Add a "Server modules" section to `docs/ARCHITECTURE.md`: one row per folder with its responsibility and files, plus the allowed direction of imports (`persistence/` is the bottom layer). - Prefix the module names the other sections already cite with their folder where that helps. 4. **Release.** `server.mjs` is minified, contains no source paths, and orders modules by import graph, so the rebuild is expected to be byte-identical. - If it is: no version bump, CHANGELOG entry, zip or catalog change. - If it isn't: a patch release at land, with a one-line CHANGELOG entry saying that the server files were reorganized with no behavior change. **Not included** - Splitting `subject-identity.ts` (2,735 lines) or `storage.ts` (ST-2), or `schema.ts` (ST-4). - Renaming `interop.ts` or any of the look-alike file names (audit finding 6). - Client or shared folders. - A lint rule that enforces the import direction. ## Regression proof - `node scripts/typecheck-packages.mjs long-term-memory` passes, so every rewritten specifier resolves. - After the rebuild, `cmp` of `server.mjs` and `client.js` against `upstream/staging` (or the patch-release path from step 4). - `git diff -M --summary upstream/staging` lists 60 renames and no delete/add pairs. Only the 8 top-level files remain in `S/`. - The full LTM suite (`test-ltm.sh all`, with `MARINARA_AGENTS_ROOT` and `MARINARA_ENGINE_ROOT` set) and `test-fast.sh`, because every server file moves. - `npm run check` and the AGENTS.md baseline validators. ## Environment - Marinara Engine version: any (no runtime change) - Package version: long-term-memory 1.4.53 (`upstream/staging` 40ff75368) - Install type: source - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. Structural audit (2026-10-15, LTM 1.4.38), step 5 and finding 9, re-checked at 40ff75368 on 2026-10-19. ## Additional context - Tracker items ST-3 and ST-1. Step 3 of the audit (the `routes.ts` split) shipped in #1419. The six-file import loop from step 4 was removed in #1416, so the move no longer stretches a loop across folders. - **Timing:** this conflicts with every open LTM server branch, so it lands while none is open. None is open on 2026-10-19. ## 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-20 17:30:17 +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#743
No description provided.