@remnic/core 9.3.757 → 9.3.759

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/access-admin-ops-surface.d.ts +2 -2
  2. package/dist/access-admin-ops-surface.js +20 -20
  3. package/dist/access-audit.js +2 -2
  4. package/dist/access-boundary.d.ts +2 -2
  5. package/dist/access-boundary.js +21 -21
  6. package/dist/access-cli.js +68 -68
  7. package/dist/access-http.d.ts +2 -2
  8. package/dist/access-http.js +28 -28
  9. package/dist/access-identity-continuity-surface.d.ts +166 -0
  10. package/dist/access-identity-continuity-surface.js +128 -0
  11. package/dist/access-lcm-surface.d.ts +2 -2
  12. package/dist/access-lcm-surface.js +20 -20
  13. package/dist/access-mcp.d.ts +2 -2
  14. package/dist/access-mcp.js +27 -27
  15. package/dist/access-observe-write-surface.d.ts +2 -2
  16. package/dist/access-observe-write-surface.js +20 -20
  17. package/dist/access-operations-batch.js +24 -24
  18. package/dist/access-operations.d.ts +2 -2
  19. package/dist/access-operations.js +26 -26
  20. package/dist/access-recall-surface.d.ts +2 -2
  21. package/dist/access-recall-surface.js +20 -20
  22. package/dist/access-schema.js +5 -5
  23. package/dist/{access-service-CJwcDoQp.d.ts → access-service-BW-gb3DL.d.ts} +4 -3
  24. package/dist/access-service.d.ts +2 -2
  25. package/dist/access-service.js +20 -20
  26. package/dist/access-surface-catalog.d.ts +2 -2
  27. package/dist/bootstrap.d.ts +1 -1
  28. package/dist/briefing.js +3 -3
  29. package/dist/{capsule-crypto-RAARDY3M.js → capsule-crypto-CZJSLEFG.js} +2 -2
  30. package/dist/causal-behavior.js +2 -2
  31. package/dist/causal-chain.js +2 -2
  32. package/dist/causal-consolidation.js +8 -8
  33. package/dist/causal-retrieval.js +2 -2
  34. package/dist/causal-trajectory-graph.js +2 -2
  35. package/dist/causal-trajectory.js +1 -1
  36. package/dist/{chunk-EEIROWEG.js → chunk-2BFLDH5F.js} +2 -2
  37. package/dist/{chunk-UPSAT4PY.js → chunk-2MR3MFQB.js} +2 -2
  38. package/dist/{chunk-MQQO56LN.js → chunk-2XE4F3VZ.js} +30 -30
  39. package/dist/{chunk-6A76LSX6.js → chunk-3JBW3GHN.js} +2 -2
  40. package/dist/{chunk-IZP62CEF.js → chunk-3QLPBCFG.js} +4 -4
  41. package/dist/{chunk-LNQUAJNC.js → chunk-437S3G37.js} +1 -1
  42. package/dist/{chunk-GI7PRVMV.js → chunk-6CUUFFU7.js} +2 -2
  43. package/dist/{chunk-6FYRCQ7K.js → chunk-7HWOEYHW.js} +2 -2
  44. package/dist/{chunk-AGNBY3VG.js → chunk-APJQ6UEA.js} +4 -4
  45. package/dist/{chunk-PXHY2E3S.js → chunk-AZSSKOG6.js} +4 -4
  46. package/dist/{chunk-XKUYMM34.js → chunk-DTSOB2YF.js} +2 -2
  47. package/dist/{chunk-6DMTYBNY.js → chunk-EGQ3AVZV.js} +2 -2
  48. package/dist/{chunk-XROP4ZHB.js → chunk-EHQ5HO5T.js} +4 -4
  49. package/dist/{chunk-KTULX4YO.js → chunk-FLVL4L3L.js} +4 -4
  50. package/dist/{chunk-2NTWULEQ.js → chunk-FYJWEGYP.js} +2 -2
  51. package/dist/{chunk-7HJ3XBMD.js → chunk-ILVF6TIY.js} +2 -2
  52. package/dist/{chunk-L5DU7THE.js → chunk-IOZZG75J.js} +2 -2
  53. package/dist/{chunk-4L2KHKLY.js → chunk-IZLGHKWA.js} +271 -197
  54. package/dist/chunk-IZLGHKWA.js.map +1 -0
  55. package/dist/{chunk-AINK3KDE.js → chunk-LLVKDFNU.js} +2 -2
  56. package/dist/{chunk-GIJDW2YO.js → chunk-M2AAYJVI.js} +3 -3
  57. package/dist/{chunk-CYWCKFCL.js → chunk-M5QKGHCR.js} +5 -5
  58. package/dist/{chunk-ZL3Y3ZTQ.js → chunk-OLEBPUZ7.js} +5 -5
  59. package/dist/{chunk-ZG2WP425.js → chunk-ORAK3LNZ.js} +2 -2
  60. package/dist/{chunk-SUN6XVNI.js → chunk-P26O6R3Q.js} +3 -3
  61. package/dist/{chunk-FFPH47IX.js → chunk-PKRRBRY2.js} +2 -2
  62. package/dist/{chunk-PHWBKQHK.js → chunk-QOM3F6YW.js} +8 -8
  63. package/dist/{chunk-FBS6V6LJ.js → chunk-QQJMVF6P.js} +4 -4
  64. package/dist/{chunk-T3UW6NRQ.js → chunk-QUGPXPFJ.js} +7 -7
  65. package/dist/{chunk-LVMVYLNB.js → chunk-SLAZZXBU.js} +2 -2
  66. package/dist/{chunk-RQXVVENY.js → chunk-SMLMH7S5.js} +174 -135
  67. package/dist/chunk-SMLMH7S5.js.map +1 -0
  68. package/dist/{chunk-IR6ATBUI.js → chunk-SN2EWIAI.js} +2 -2
  69. package/dist/{chunk-ZE7GJ76H.js → chunk-SQNED75R.js} +1 -1
  70. package/dist/{chunk-PMBWVQ7D.js → chunk-TQT3USCG.js} +2 -2
  71. package/dist/{chunk-7K5Q6COX.js → chunk-TVVEYCNW.js} +4 -4
  72. package/dist/{chunk-I65IQD7Y.js → chunk-WIXQ3F5P.js} +2 -2
  73. package/dist/{chunk-IF6BTZCB.js → chunk-XQT5GSWU.js} +2 -2
  74. package/dist/{chunk-5PHPNUZN.js → chunk-YP23FQPT.js} +288 -233
  75. package/dist/chunk-YP23FQPT.js.map +1 -0
  76. package/dist/{chunk-QVQG7W2H.js → chunk-ZEQVS6AZ.js} +2 -2
  77. package/dist/{chunk-CTGK5VK3.js → chunk-ZQNCHPTZ.js} +2 -2
  78. package/dist/{cli-cZyANcmY.d.ts → cli-D551dnva.d.ts} +2 -2
  79. package/dist/cli.d.ts +3 -3
  80. package/dist/cli.js +46 -46
  81. package/dist/compounding/engine.js +3 -3
  82. package/dist/connectors/codex-materialize-runner.js +3 -3
  83. package/dist/connectors/index.js +3 -3
  84. package/dist/contradiction/index.js +4 -4
  85. package/dist/entity-retrieval.js +3 -3
  86. package/dist/explicit-capture.d.ts +1 -1
  87. package/dist/{first-start-migration-RYY7PPGF.js → first-start-migration-DY6YCRC2.js} +4 -4
  88. package/dist/{graph-edge-decay-U2GKDAVM.js → graph-edge-decay-RXUCJIN4.js} +4 -4
  89. package/dist/graph-edge-decay-RXUCJIN4.js.map +1 -0
  90. package/dist/graph-snapshot.js +3 -3
  91. package/dist/graph.js +2 -2
  92. package/dist/index.d.ts +4 -4
  93. package/dist/index.js +85 -85
  94. package/dist/lcm/index.js +3 -3
  95. package/dist/maintenance/memory-governance.js +3 -3
  96. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
  97. package/dist/maintenance/rebuild-memory-projection.js +4 -4
  98. package/dist/mcp-memory-inspector-app.d.ts +2 -2
  99. package/dist/namespaces/migrate.js +7 -7
  100. package/dist/namespaces/search.js +3 -3
  101. package/dist/namespaces/storage.js +3 -3
  102. package/dist/operator-toolkit.js +12 -12
  103. package/dist/orchestration/maintenance.js +5 -5
  104. package/dist/{orchestrator-Xm6sK5jw.d.ts → orchestrator-BnM187cb.d.ts} +2 -1
  105. package/dist/orchestrator.d.ts +1 -1
  106. package/dist/orchestrator.js +70 -70
  107. package/dist/search/factory.js +2 -2
  108. package/dist/search/index.js +4 -4
  109. package/dist/semantic-consolidation.js +4 -4
  110. package/dist/semantic-rule-promotion.js +3 -3
  111. package/dist/semantic-rule-verifier.js +3 -3
  112. package/dist/storage.d.ts +3 -4
  113. package/dist/storage.js +2 -2
  114. package/dist/transfer/backup.js +3 -3
  115. package/dist/transfer/capsule-export.js +4 -4
  116. package/dist/transfer/capsule-import.js +3 -3
  117. package/dist/transfer/import-sqlite.js +2 -2
  118. package/dist/verified-recall.js +3 -3
  119. package/package.json +2 -2
  120. package/src/access-identity-continuity-surface.test.ts +374 -0
  121. package/src/access-identity-continuity-surface.ts +322 -0
  122. package/src/access-service.ts +23 -171
  123. package/src/orchestration/recall-background-writes.ts +24 -0
  124. package/src/orchestration/recall-entry.ts +5 -0
  125. package/src/orchestration/recall-internal.ts +15 -11
  126. package/src/orchestration/recall-introspection.ts +5 -0
  127. package/src/orchestrator-background-writes.test.ts +101 -0
  128. package/src/orchestrator.ts +13 -13
  129. package/src/storage/identity-continuity-store.ts +223 -0
  130. package/src/storage-contract/round-trip.test.ts +5 -0
  131. package/src/storage.ts +27 -145
  132. package/src/trust-score-recall-paths.test.ts +2 -0
  133. package/dist/chunk-4L2KHKLY.js.map +0 -1
  134. package/dist/chunk-5PHPNUZN.js.map +0 -1
  135. package/dist/chunk-RQXVVENY.js.map +0 -1
  136. /package/dist/{capsule-crypto-RAARDY3M.js.map → access-identity-continuity-surface.js.map} +0 -0
  137. /package/dist/{graph-edge-decay-U2GKDAVM.js.map → capsule-crypto-CZJSLEFG.js.map} +0 -0
  138. /package/dist/{chunk-EEIROWEG.js.map → chunk-2BFLDH5F.js.map} +0 -0
  139. /package/dist/{chunk-UPSAT4PY.js.map → chunk-2MR3MFQB.js.map} +0 -0
  140. /package/dist/{chunk-MQQO56LN.js.map → chunk-2XE4F3VZ.js.map} +0 -0
  141. /package/dist/{chunk-6A76LSX6.js.map → chunk-3JBW3GHN.js.map} +0 -0
  142. /package/dist/{chunk-IZP62CEF.js.map → chunk-3QLPBCFG.js.map} +0 -0
  143. /package/dist/{chunk-LNQUAJNC.js.map → chunk-437S3G37.js.map} +0 -0
  144. /package/dist/{chunk-GI7PRVMV.js.map → chunk-6CUUFFU7.js.map} +0 -0
  145. /package/dist/{chunk-6FYRCQ7K.js.map → chunk-7HWOEYHW.js.map} +0 -0
  146. /package/dist/{chunk-AGNBY3VG.js.map → chunk-APJQ6UEA.js.map} +0 -0
  147. /package/dist/{chunk-PXHY2E3S.js.map → chunk-AZSSKOG6.js.map} +0 -0
  148. /package/dist/{chunk-XKUYMM34.js.map → chunk-DTSOB2YF.js.map} +0 -0
  149. /package/dist/{chunk-6DMTYBNY.js.map → chunk-EGQ3AVZV.js.map} +0 -0
  150. /package/dist/{chunk-XROP4ZHB.js.map → chunk-EHQ5HO5T.js.map} +0 -0
  151. /package/dist/{chunk-KTULX4YO.js.map → chunk-FLVL4L3L.js.map} +0 -0
  152. /package/dist/{chunk-2NTWULEQ.js.map → chunk-FYJWEGYP.js.map} +0 -0
  153. /package/dist/{chunk-7HJ3XBMD.js.map → chunk-ILVF6TIY.js.map} +0 -0
  154. /package/dist/{chunk-L5DU7THE.js.map → chunk-IOZZG75J.js.map} +0 -0
  155. /package/dist/{chunk-AINK3KDE.js.map → chunk-LLVKDFNU.js.map} +0 -0
  156. /package/dist/{chunk-GIJDW2YO.js.map → chunk-M2AAYJVI.js.map} +0 -0
  157. /package/dist/{chunk-CYWCKFCL.js.map → chunk-M5QKGHCR.js.map} +0 -0
  158. /package/dist/{chunk-ZL3Y3ZTQ.js.map → chunk-OLEBPUZ7.js.map} +0 -0
  159. /package/dist/{chunk-ZG2WP425.js.map → chunk-ORAK3LNZ.js.map} +0 -0
  160. /package/dist/{chunk-SUN6XVNI.js.map → chunk-P26O6R3Q.js.map} +0 -0
  161. /package/dist/{chunk-FFPH47IX.js.map → chunk-PKRRBRY2.js.map} +0 -0
  162. /package/dist/{chunk-PHWBKQHK.js.map → chunk-QOM3F6YW.js.map} +0 -0
  163. /package/dist/{chunk-FBS6V6LJ.js.map → chunk-QQJMVF6P.js.map} +0 -0
  164. /package/dist/{chunk-T3UW6NRQ.js.map → chunk-QUGPXPFJ.js.map} +0 -0
  165. /package/dist/{chunk-LVMVYLNB.js.map → chunk-SLAZZXBU.js.map} +0 -0
  166. /package/dist/{chunk-IR6ATBUI.js.map → chunk-SN2EWIAI.js.map} +0 -0
  167. /package/dist/{chunk-ZE7GJ76H.js.map → chunk-SQNED75R.js.map} +0 -0
  168. /package/dist/{chunk-PMBWVQ7D.js.map → chunk-TQT3USCG.js.map} +0 -0
  169. /package/dist/{chunk-7K5Q6COX.js.map → chunk-TVVEYCNW.js.map} +0 -0
  170. /package/dist/{chunk-I65IQD7Y.js.map → chunk-WIXQ3F5P.js.map} +0 -0
  171. /package/dist/{chunk-IF6BTZCB.js.map → chunk-XQT5GSWU.js.map} +0 -0
  172. /package/dist/{chunk-QVQG7W2H.js.map → chunk-ZEQVS6AZ.js.map} +0 -0
  173. /package/dist/{chunk-CTGK5VK3.js.map → chunk-ZQNCHPTZ.js.map} +0 -0
  174. /package/dist/{first-start-migration-RYY7PPGF.js.map → first-start-migration-DY6YCRC2.js.map} +0 -0
package/src/storage.ts CHANGED
@@ -7,6 +7,7 @@ import { log } from "./logger.js";
7
7
  import { MemoryReadStore } from "./storage/memory-read-store.js";
8
8
  import { selfDeps } from "./orchestration/self-deps.js";
9
9
  import { EntityStore } from "./storage/entity-store.js";
10
+ import { IdentityContinuityStore } from "./storage/identity-continuity-store.js";
10
11
  import { isErrnoCode } from "./utils/errno.js";
11
12
  import { RECALL_FALLBACK_DIRS, getCategoryDir, categoryDirName } from "./utils/category-dir.js";
12
13
  import { assertPathInsideRoot } from "./utils/path-containment.js";
@@ -113,15 +114,6 @@ import {
113
114
  normalizeProjectionPreview,
114
115
  normalizeProjectionTags,
115
116
  } from "./memory-projection-format.js";
116
- import {
117
- closeContinuityIncidentRecord,
118
- createContinuityIncidentRecord,
119
- parseContinuityIncident,
120
- parseContinuityImprovementLoops,
121
- reviewContinuityLoopInMarkdown,
122
- serializeContinuityIncident,
123
- upsertContinuityLoopInMarkdown,
124
- } from "./identity-continuity.js";
125
117
  import { parseFlexibleIsoTimestamp } from "./utils/iso-timestamp.js";
126
118
  // stripCitation import removed: legacy rebuild fallback was replaced by a
127
119
  // skip-with-warning strategy (Finding 1 — Uhol). See ensureFactHashIndexAuthoritative.
@@ -2560,6 +2552,18 @@ export class StorageManager {
2560
2552
  return this._entityStore;
2561
2553
  }
2562
2554
 
2555
+ /** IdentityContinuityStore (storage.ts decomposition). Lazy; selfDeps live wiring. */
2556
+ private _identityContinuityStore: IdentityContinuityStore | undefined;
2557
+
2558
+ private get identityContinuityStore(): IdentityContinuityStore {
2559
+ if (!this._identityContinuityStore) {
2560
+ this._identityContinuityStore = new IdentityContinuityStore(
2561
+ selfDeps<ConstructorParameters<typeof IdentityContinuityStore>[0]>(this),
2562
+ );
2563
+ }
2564
+ return this._identityContinuityStore;
2565
+ }
2566
+
2563
2567
  get dir(): string {
2564
2568
  return this.baseDir;
2565
2569
  }
@@ -5355,137 +5359,60 @@ export class StorageManager {
5355
5359
  }
5356
5360
 
5357
5361
  async writeIdentityAnchor(content: string): Promise<void> {
5358
- await this.ensureDirectories();
5359
- await this.writeStorageSecureFile(this.identityAnchorPath, content);
5362
+ return this.identityContinuityStore.writeIdentityAnchor(content);
5360
5363
  }
5361
5364
 
5362
5365
  async readIdentityAnchor(): Promise<string | null> {
5363
- try {
5364
- return await this.readStorageSecureFile(this.identityAnchorPath);
5365
- } catch (err) {
5366
- if (!isErrnoCode(err, "ENOENT")) throw err;
5367
- return null;
5368
- }
5366
+ return this.identityContinuityStore.readIdentityAnchor();
5369
5367
  }
5370
5368
 
5371
5369
  async appendContinuityIncident(input: ContinuityIncidentOpenInput): Promise<ContinuityIncidentRecord> {
5372
- await this.ensureDirectories();
5373
- const now = new Date();
5374
- const nowIso = now.toISOString();
5375
- const date = nowIso.slice(0, 10);
5376
- const id = this.generateId("incident");
5377
- const incident = createContinuityIncidentRecord(id, input, nowIso);
5378
- const filePath = path.join(this.identityIncidentsDir, `${date}-${id}.md`);
5379
- await this.writeStorageSecureFile(filePath, serializeContinuityIncident(incident));
5380
- return { ...incident, filePath };
5370
+ return this.identityContinuityStore.appendContinuityIncident(input);
5381
5371
  }
5382
5372
 
5383
5373
  async readContinuityIncidents(
5384
5374
  limit: number = 200,
5385
5375
  state: "open" | "closed" | "all" = "all",
5386
5376
  ): Promise<ContinuityIncidentRecord[]> {
5387
- const normalizedLimit = Number.isFinite(limit) ? Math.floor(limit) : 0;
5388
- const cappedLimit = Math.max(0, normalizedLimit);
5389
- if (cappedLimit === 0) return [];
5390
-
5391
- try {
5392
- const candidates = await this.readContinuityIncidentFileNames();
5393
- const incidents: ContinuityIncidentRecord[] = [];
5394
-
5395
- for (const file of candidates) {
5396
- if (incidents.length >= cappedLimit) break;
5397
- const filePath = path.join(this.identityIncidentsDir, file);
5398
- try {
5399
- const raw = await this.readStorageSecureFile(filePath);
5400
- const parsed = parseContinuityIncident(raw);
5401
- if (!parsed) continue;
5402
- if (state !== "all" && parsed.state !== state) continue;
5403
- incidents.push({ ...parsed, filePath });
5404
- } catch (err) {
5405
- if (err instanceof SecureStoreLockedError) throw err;
5406
- // Fail-open on malformed/missing files.
5407
- }
5408
- }
5409
- return incidents;
5410
- } catch (err) {
5411
- if (err instanceof SecureStoreLockedError) throw err;
5412
- if (!isErrnoCode(err, "ENOENT")) throw err;
5413
- return [];
5414
- }
5377
+ return this.identityContinuityStore.readContinuityIncidents(limit, state);
5415
5378
  }
5416
5379
 
5417
5380
  async closeContinuityIncident(
5418
5381
  id: string,
5419
5382
  closure: ContinuityIncidentCloseInput,
5420
5383
  ): Promise<ContinuityIncidentRecord | null> {
5421
- const directFilePath = await this.findContinuityIncidentFilePathById(id);
5422
- const target = directFilePath ? await this.readContinuityIncidentFile(directFilePath) : null;
5423
- if (!target || !directFilePath) return null;
5424
- if (target.state === "closed") return target;
5425
-
5426
- const closed = closeContinuityIncidentRecord(target, closure, new Date().toISOString());
5427
- await this.writeStorageSecureFile(directFilePath, serializeContinuityIncident(closed));
5428
- return { ...closed, filePath: directFilePath };
5384
+ return this.identityContinuityStore.closeContinuityIncident(id, closure);
5429
5385
  }
5430
5386
 
5431
5387
  async writeIdentityAudit(period: "weekly" | "monthly", key: string, content: string): Promise<string> {
5432
- await this.ensureDirectories();
5433
- const safeKey = this.sanitizeIdentityAuditKey(key);
5434
- const dir = period === "weekly" ? this.identityAuditsWeeklyDir : this.identityAuditsMonthlyDir;
5435
- const filePath = path.join(dir, `${safeKey}.md`);
5436
- await this.writeStorageSecureFile(filePath, content);
5437
- return filePath;
5388
+ return this.identityContinuityStore.writeIdentityAudit(period, key, content);
5438
5389
  }
5439
5390
 
5440
5391
  async readIdentityAudit(period: "weekly" | "monthly", key: string): Promise<string | null> {
5441
- try {
5442
- const safeKey = this.sanitizeIdentityAuditKey(key);
5443
- const dir = period === "weekly" ? this.identityAuditsWeeklyDir : this.identityAuditsMonthlyDir;
5444
- return await this.readStorageSecureFile(path.join(dir, `${safeKey}.md`));
5445
- } catch (err) {
5446
- if (err instanceof Error && err.message === "Invalid identity audit key") return null;
5447
- if (!isErrnoCode(err, "ENOENT")) throw err;
5448
- return null;
5449
- }
5392
+ return this.identityContinuityStore.readIdentityAudit(period, key);
5450
5393
  }
5451
5394
 
5452
5395
  async writeIdentityImprovementLoops(content: string): Promise<void> {
5453
- await this.ensureDirectories();
5454
- await this.writeStorageSecureFile(this.identityImprovementLoopsPath, content);
5396
+ return this.identityContinuityStore.writeIdentityImprovementLoops(content);
5455
5397
  }
5456
5398
 
5457
5399
  async readIdentityImprovementLoops(): Promise<string | null> {
5458
- try {
5459
- return await this.readStorageSecureFile(this.identityImprovementLoopsPath);
5460
- } catch (err) {
5461
- if (!isErrnoCode(err, "ENOENT")) throw err;
5462
- return null;
5463
- }
5400
+ return this.identityContinuityStore.readIdentityImprovementLoops();
5464
5401
  }
5465
5402
 
5466
5403
  async readIdentityImprovementLoopRegister(): Promise<ContinuityImprovementLoop[]> {
5467
- const raw = await this.readIdentityImprovementLoops();
5468
- if (!raw) return [];
5469
- return parseContinuityImprovementLoops(raw);
5404
+ return this.identityContinuityStore.readIdentityImprovementLoopRegister();
5470
5405
  }
5471
5406
 
5472
5407
  async upsertIdentityImprovementLoop(input: ContinuityLoopUpsertInput): Promise<ContinuityImprovementLoop> {
5473
- const nowIso = new Date().toISOString();
5474
- const raw = await this.readIdentityImprovementLoops();
5475
- const { markdown, loop } = upsertContinuityLoopInMarkdown(raw, input, nowIso);
5476
- await this.writeIdentityImprovementLoops(markdown);
5477
- return loop;
5408
+ return this.identityContinuityStore.upsertIdentityImprovementLoop(input);
5478
5409
  }
5479
5410
 
5480
5411
  async reviewIdentityImprovementLoop(
5481
5412
  id: string,
5482
5413
  input: ContinuityLoopReviewInput,
5483
5414
  ): Promise<ContinuityImprovementLoop | null> {
5484
- const raw = await this.readIdentityImprovementLoops();
5485
- const { markdown, loop } = reviewContinuityLoopInMarkdown(raw, id, input, new Date().toISOString());
5486
- if (!loop) return null;
5487
- await this.writeIdentityImprovementLoops(markdown);
5488
- return loop;
5415
+ return this.identityContinuityStore.reviewIdentityImprovementLoop(id, input);
5489
5416
  }
5490
5417
 
5491
5418
  // ---------------------------------------------------------------------------
@@ -5498,50 +5425,6 @@ export class StorageManager {
5498
5425
  return `${prefix}-${ts}-${rand}`;
5499
5426
  }
5500
5427
 
5501
- private async readContinuityIncidentFileNames(): Promise<string[]> {
5502
- const files = await readdir(this.identityIncidentsDir);
5503
- return files
5504
- .filter((file) => file.endsWith(".md"))
5505
- .sort()
5506
- .reverse();
5507
- }
5508
-
5509
- private async readContinuityIncidentFile(filePath: string): Promise<ContinuityIncidentRecord | null> {
5510
- try {
5511
- const raw = await this.readStorageSecureFile(filePath);
5512
- const parsed = parseContinuityIncident(raw);
5513
- return parsed ? { ...parsed, filePath } : null;
5514
- } catch (err) {
5515
- if (err instanceof SecureStoreLockedError) throw err;
5516
- return null;
5517
- }
5518
- }
5519
-
5520
- private async findContinuityIncidentFilePathById(id: string): Promise<string | null> {
5521
- const fileNames = await this.readContinuityIncidentFileNames();
5522
- const directMatch = fileNames.find((name) => name.endsWith(`-${id}.md`));
5523
- if (directMatch) {
5524
- const directPath = path.join(this.identityIncidentsDir, directMatch);
5525
- const parsed = await this.readContinuityIncidentFile(directPath);
5526
- if (parsed?.id === id) return directPath;
5527
- }
5528
-
5529
- for (const fileName of fileNames) {
5530
- const filePath = path.join(this.identityIncidentsDir, fileName);
5531
- const parsed = await this.readContinuityIncidentFile(filePath);
5532
- if (parsed?.id === id) return filePath;
5533
- }
5534
- return null;
5535
- }
5536
-
5537
- private sanitizeIdentityAuditKey(key: string): string {
5538
- const trimmed = key.trim();
5539
- if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(trimmed) || trimmed.includes("..")) {
5540
- throw new Error("Invalid identity audit key");
5541
- }
5542
- return trimmed;
5543
- }
5544
-
5545
5428
  async writeQuestion(
5546
5429
  question: string,
5547
5430
  context: string,
@@ -5580,9 +5463,7 @@ export class StorageManager {
5580
5463
  filePath: string;
5581
5464
  }>
5582
5465
  > {
5583
- return this.memoryReadStore.readQuestions(
5584
- opts,
5585
- );
5466
+ return this.memoryReadStore.readQuestions(opts);
5586
5467
  }
5587
5468
 
5588
5469
  /** Invalidate the questions cache (call after writing a question). */
@@ -5652,6 +5533,7 @@ export class StorageManager {
5652
5533
  `resolvedAt: "${new Date().toISOString()}"\n---\n\n`,
5653
5534
  );
5654
5535
  await this.writeStorageSecureFile(q.filePath, raw);
5536
+ this.invalidateQuestionsCache();
5655
5537
  log.debug(`resolved question ${id}`);
5656
5538
  return true;
5657
5539
  }
@@ -119,6 +119,7 @@ test("TrustScore runs on the recent-scan path: trust map reaches the X-ray snaps
119
119
  );
120
120
  }
121
121
  } finally {
122
+ await orchestrator.destroy();
122
123
  await rm(memoryDir, { recursive: true, force: true });
123
124
  }
124
125
  });
@@ -152,6 +153,7 @@ test("TrustScore quarantine excludes a contradicted memory from injection but su
152
153
  "quarantined result carries a human-readable reason",
153
154
  );
154
155
  } finally {
156
+ await orchestrator.destroy();
155
157
  await rm(memoryDir, { recursive: true, force: true });
156
158
  }
157
159
  });