@remnic/core 9.3.663 → 9.3.664

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 (143) hide show
  1. package/dist/access-cli.js +25 -23
  2. package/dist/access-cli.js.map +1 -1
  3. package/dist/access-http.js +20 -18
  4. package/dist/access-mcp.js +19 -17
  5. package/dist/access-schema.js +4 -3
  6. package/dist/access-service.js +17 -15
  7. package/dist/briefing.js +5 -4
  8. package/dist/{capsule-merge-T2JRE46P.js → capsule-merge-GK5E647P.js} +3 -2
  9. package/dist/{capsule-merge-T2JRE46P.js.map → capsule-merge-GK5E647P.js.map} +1 -1
  10. package/dist/causal-consolidation.js +6 -5
  11. package/dist/causal-consolidation.js.map +1 -1
  12. package/dist/{chunk-2KDQI363.js → chunk-2HEZXPYU.js} +4 -4
  13. package/dist/chunk-5GPPACXK.js +16 -0
  14. package/dist/chunk-5GPPACXK.js.map +1 -0
  15. package/dist/{chunk-F6O7IOS3.js → chunk-6JBKHTQD.js} +2 -2
  16. package/dist/{chunk-TBLGI2LT.js → chunk-7ILWCUWH.js} +5 -3
  17. package/dist/{chunk-TBLGI2LT.js.map → chunk-7ILWCUWH.js.map} +1 -1
  18. package/dist/{chunk-AL4RAJL5.js → chunk-7XH7VJN4.js} +6 -4
  19. package/dist/chunk-7XH7VJN4.js.map +1 -0
  20. package/dist/{chunk-Q4CAQGKQ.js → chunk-AER6MT24.js} +12 -21
  21. package/dist/chunk-AER6MT24.js.map +1 -0
  22. package/dist/{chunk-DHGSZ3UD.js → chunk-ARV3AUOM.js} +2 -2
  23. package/dist/{chunk-PXVFMQLD.js → chunk-BZG2CWOQ.js} +3 -3
  24. package/dist/{chunk-ANJOULTP.js → chunk-C7AF236A.js} +2 -2
  25. package/dist/{chunk-FZC2WSDB.js → chunk-DOCTITOP.js} +2 -2
  26. package/dist/{chunk-WOQIHC67.js → chunk-DQY7NJ5L.js} +2 -2
  27. package/dist/{chunk-NMPEJV5M.js → chunk-DSLUOQDY.js} +2 -2
  28. package/dist/{chunk-A7EF2XRO.js → chunk-EXXBA5OM.js} +30 -8
  29. package/dist/chunk-EXXBA5OM.js.map +1 -0
  30. package/dist/{chunk-QXHBWFR3.js → chunk-IHG6CC7T.js} +2 -2
  31. package/dist/{chunk-4KDLCMLK.js → chunk-IROWLAWG.js} +5 -5
  32. package/dist/{chunk-ILXTATKK.js → chunk-J2HSAU72.js} +5 -5
  33. package/dist/chunk-J2HSAU72.js.map +1 -0
  34. package/dist/{chunk-DFAXGZKI.js → chunk-JIX3ZL2J.js} +8 -8
  35. package/dist/{chunk-GY3V3SUI.js → chunk-KHGE6PMF.js} +2 -2
  36. package/dist/{chunk-TGOOJCGA.js → chunk-LIERUFPO.js} +76 -54
  37. package/dist/chunk-LIERUFPO.js.map +1 -0
  38. package/dist/{chunk-HSCJYHYV.js → chunk-NLF54XMD.js} +49 -19
  39. package/dist/chunk-NLF54XMD.js.map +1 -0
  40. package/dist/{chunk-TWAJICBN.js → chunk-OHJFJ4HI.js} +2 -2
  41. package/dist/{chunk-WSQG37DV.js → chunk-OUWAQVDJ.js} +2 -2
  42. package/dist/{chunk-ZLDUQWT2.js → chunk-PWWWLD7D.js} +2 -2
  43. package/dist/{chunk-ZJH723NM.js → chunk-Q5ZU3RNY.js} +2 -2
  44. package/dist/{chunk-35HP3TGR.js → chunk-ROHLEUTH.js} +4 -4
  45. package/dist/{chunk-5RIRL3XL.js → chunk-RS25QOKZ.js} +2 -2
  46. package/dist/{chunk-RQGR3ETH.js → chunk-T2AN3BSP.js} +2 -2
  47. package/dist/{chunk-UAU5U5ML.js → chunk-UDJLF3BO.js} +2 -2
  48. package/dist/{chunk-ALEPI75L.js → chunk-VF4XKTX3.js} +6 -4
  49. package/dist/{chunk-ALEPI75L.js.map → chunk-VF4XKTX3.js.map} +1 -1
  50. package/dist/{chunk-AX5O25EF.js → chunk-VH6EIKVS.js} +152 -190
  51. package/dist/chunk-VH6EIKVS.js.map +1 -0
  52. package/dist/chunk-VS2IYZRU.js +43 -0
  53. package/dist/chunk-VS2IYZRU.js.map +1 -0
  54. package/dist/{chunk-YYQRVNSV.js → chunk-XB5P5P2L.js} +6 -6
  55. package/dist/{chunk-D2EFNQMY.js → chunk-XW3W4PV4.js} +2 -2
  56. package/dist/{chunk-5AYAZN45.js → chunk-YKX63GBK.js} +5 -5
  57. package/dist/{chunk-TYIXG4VR.js → chunk-YW52BQSU.js} +2 -2
  58. package/dist/{cli-C6twwe84.d.ts → cli-BQRqR9N-.d.ts} +12 -1
  59. package/dist/cli.d.ts +1 -1
  60. package/dist/cli.js +32 -28
  61. package/dist/compounding/engine.js +5 -4
  62. package/dist/connectors/codex-materialize-runner.js +5 -4
  63. package/dist/connectors/index.js +5 -4
  64. package/dist/consolidation-provenance-check.js +3 -2
  65. package/dist/consolidation-undo.js +2 -1
  66. package/dist/consolidation-undo.js.map +1 -1
  67. package/dist/entity-retrieval.js +5 -4
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.js +39 -36
  70. package/dist/index.js.map +1 -1
  71. package/dist/maintenance/memory-governance.js +6 -4
  72. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +5 -4
  73. package/dist/maintenance/rebuild-memory-projection.js +7 -5
  74. package/dist/namespaces/migrate.js +13 -11
  75. package/dist/namespaces/search.js +8 -6
  76. package/dist/namespaces/storage.js +5 -4
  77. package/dist/offline-sync.js +3 -2
  78. package/dist/operator-toolkit.js +16 -14
  79. package/dist/orchestrator.js +21 -19
  80. package/dist/page-versioning.js +2 -1
  81. package/dist/schemas.d.ts +22 -22
  82. package/dist/search/document-scanner.d.ts +11 -7
  83. package/dist/search/document-scanner.js +3 -1
  84. package/dist/search/factory.js +7 -5
  85. package/dist/search/index.js +7 -5
  86. package/dist/search/lancedb-backend.js +4 -2
  87. package/dist/search/meilisearch-backend.js +4 -2
  88. package/dist/search/orama-backend.js +4 -2
  89. package/dist/secure-store/index.js +3 -2
  90. package/dist/semantic-consolidation.js +6 -5
  91. package/dist/semantic-rule-promotion.js +5 -4
  92. package/dist/semantic-rule-verifier.js +5 -4
  93. package/dist/storage.d.ts +17 -3
  94. package/dist/storage.js +4 -3
  95. package/dist/transfer/capsule-import.js +3 -2
  96. package/dist/transfer/types.d.ts +12 -12
  97. package/dist/verified-recall.js +5 -4
  98. package/package.json +1 -1
  99. package/src/cli.ts +62 -23
  100. package/src/consolidation-provenance-check.ts +7 -6
  101. package/src/maintenance/memory-governance.ts +47 -7
  102. package/src/orchestrator.ts +84 -58
  103. package/src/page-versioning.ts +7 -4
  104. package/src/search/document-scanner.test.ts +29 -0
  105. package/src/search/document-scanner.ts +17 -29
  106. package/src/secure-store/secure-fs.ts +19 -5
  107. package/src/secure-store/secure-store.test.ts +28 -0
  108. package/src/storage.ts +42 -43
  109. package/src/training-export/converter.test.ts +19 -0
  110. package/src/training-export/converter.ts +8 -5
  111. package/src/utils/category-dir.ts +10 -4
  112. package/src/utils/path-containment.ts +40 -0
  113. package/dist/chunk-A7EF2XRO.js.map +0 -1
  114. package/dist/chunk-AL4RAJL5.js.map +0 -1
  115. package/dist/chunk-AX5O25EF.js.map +0 -1
  116. package/dist/chunk-HSCJYHYV.js.map +0 -1
  117. package/dist/chunk-ILXTATKK.js.map +0 -1
  118. package/dist/chunk-Q4CAQGKQ.js.map +0 -1
  119. package/dist/chunk-TGOOJCGA.js.map +0 -1
  120. /package/dist/{chunk-2KDQI363.js.map → chunk-2HEZXPYU.js.map} +0 -0
  121. /package/dist/{chunk-F6O7IOS3.js.map → chunk-6JBKHTQD.js.map} +0 -0
  122. /package/dist/{chunk-DHGSZ3UD.js.map → chunk-ARV3AUOM.js.map} +0 -0
  123. /package/dist/{chunk-PXVFMQLD.js.map → chunk-BZG2CWOQ.js.map} +0 -0
  124. /package/dist/{chunk-ANJOULTP.js.map → chunk-C7AF236A.js.map} +0 -0
  125. /package/dist/{chunk-FZC2WSDB.js.map → chunk-DOCTITOP.js.map} +0 -0
  126. /package/dist/{chunk-WOQIHC67.js.map → chunk-DQY7NJ5L.js.map} +0 -0
  127. /package/dist/{chunk-NMPEJV5M.js.map → chunk-DSLUOQDY.js.map} +0 -0
  128. /package/dist/{chunk-QXHBWFR3.js.map → chunk-IHG6CC7T.js.map} +0 -0
  129. /package/dist/{chunk-4KDLCMLK.js.map → chunk-IROWLAWG.js.map} +0 -0
  130. /package/dist/{chunk-DFAXGZKI.js.map → chunk-JIX3ZL2J.js.map} +0 -0
  131. /package/dist/{chunk-GY3V3SUI.js.map → chunk-KHGE6PMF.js.map} +0 -0
  132. /package/dist/{chunk-TWAJICBN.js.map → chunk-OHJFJ4HI.js.map} +0 -0
  133. /package/dist/{chunk-WSQG37DV.js.map → chunk-OUWAQVDJ.js.map} +0 -0
  134. /package/dist/{chunk-ZLDUQWT2.js.map → chunk-PWWWLD7D.js.map} +0 -0
  135. /package/dist/{chunk-ZJH723NM.js.map → chunk-Q5ZU3RNY.js.map} +0 -0
  136. /package/dist/{chunk-35HP3TGR.js.map → chunk-ROHLEUTH.js.map} +0 -0
  137. /package/dist/{chunk-5RIRL3XL.js.map → chunk-RS25QOKZ.js.map} +0 -0
  138. /package/dist/{chunk-RQGR3ETH.js.map → chunk-T2AN3BSP.js.map} +0 -0
  139. /package/dist/{chunk-UAU5U5ML.js.map → chunk-UDJLF3BO.js.map} +0 -0
  140. /package/dist/{chunk-YYQRVNSV.js.map → chunk-XB5P5P2L.js.map} +0 -0
  141. /package/dist/{chunk-D2EFNQMY.js.map → chunk-XW3W4PV4.js.map} +0 -0
  142. /package/dist/{chunk-5AYAZN45.js.map → chunk-YKX63GBK.js.map} +0 -0
  143. /package/dist/{chunk-TYIXG4VR.js.map → chunk-YW52BQSU.js.map} +0 -0
@@ -1,3 +1,10 @@
1
+ import {
2
+ assertPathInsideRoot
3
+ } from "./chunk-5GPPACXK.js";
4
+ import {
5
+ RECALL_FALLBACK_DIRS
6
+ } from "./chunk-VS2IYZRU.js";
7
+
1
8
  // src/search/document-scanner.ts
2
9
  import path from "path";
3
10
  import { lstat, readdir, readFile, realpath } from "fs/promises";
@@ -66,15 +73,6 @@ async function scanDir(dir, memoryRootReal) {
66
73
  function isNodeError(err) {
67
74
  return typeof err === "object" && err !== null && "code" in err;
68
75
  }
69
- function pathIsInside(parent, child) {
70
- const relative = path.relative(parent, child);
71
- return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
72
- }
73
- function assertPathInsideRoot(rootReal, candidateReal, originalPath) {
74
- if (!pathIsInside(rootReal, candidateReal)) {
75
- throw new Error(`Refusing to scan memory path outside memoryDir: ${originalPath}`);
76
- }
77
- }
78
76
  async function scanMemoryDir(memoryDir) {
79
77
  let memoryRootReal;
80
78
  try {
@@ -85,20 +83,13 @@ async function scanMemoryDir(memoryDir) {
85
83
  }
86
84
  throw err;
87
85
  }
88
- const factsDir = path.join(memoryDir, "facts");
89
- const correctionsDir = path.join(memoryDir, "corrections");
90
- const proceduresDir = path.join(memoryDir, "procedures");
91
- const reasoningTracesDir = path.join(memoryDir, "reasoning-traces");
92
- const [facts, corrections, procedures, reasoningTraces] = await Promise.all([
93
- scanDir(factsDir, memoryRootReal),
94
- scanDir(correctionsDir, memoryRootReal),
95
- scanDir(proceduresDir, memoryRootReal),
96
- scanDir(reasoningTracesDir, memoryRootReal)
97
- ]);
98
- return [...facts, ...corrections, ...procedures, ...reasoningTraces];
86
+ const perDir = await Promise.all(
87
+ RECALL_FALLBACK_DIRS.map((dir) => scanDir(path.join(memoryDir, dir), memoryRootReal))
88
+ );
89
+ return perDir.flat();
99
90
  }
100
91
 
101
92
  export {
102
93
  scanMemoryDir
103
94
  };
104
- //# sourceMappingURL=chunk-Q4CAQGKQ.js.map
95
+ //# sourceMappingURL=chunk-AER6MT24.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/search/document-scanner.ts"],"sourcesContent":["import path from \"node:path\";\nimport { lstat, readdir, readFile, realpath } from \"node:fs/promises\";\nimport { RECALL_FALLBACK_DIRS } from \"../utils/category-dir.js\";\nimport { assertPathInsideRoot } from \"../utils/path-containment.js\";\n\nexport interface IndexableDocument {\n /** Memory ID from frontmatter or filename stem */\n docid: string;\n /** Absolute file path */\n path: string;\n /** Markdown body (no YAML frontmatter) */\n content: string;\n /** First ~200 chars for display */\n snippet: string;\n}\n\n/**\n * Parse YAML frontmatter from a markdown string.\n * Returns the frontmatter key-value pairs and body, or null if no frontmatter block.\n */\nfunction parseFrontmatter(raw: string): { data: Record<string, string>; body: string } | null {\n // Support both LF and CRLF line endings\n const normalized = raw.replace(/\\r\\n/g, \"\\n\");\n const match = normalized.match(/^---\\n([\\s\\S]*?)\\n---\\n?([\\s\\S]*)$/);\n if (!match) return null;\n\n const fmBlock = match[1];\n const body = (match[2] ?? \"\").trim();\n const data: Record<string, string> = {};\n\n for (const line of fmBlock.split(\"\\n\")) {\n const colonIdx = line.indexOf(\":\");\n if (colonIdx === -1) continue;\n const key = line.slice(0, colonIdx).trim();\n const value = line.slice(colonIdx + 1).trim();\n data[key] = value;\n }\n\n return { data, body };\n}\n\n/**\n * Recursively scan a directory for `.md` files and return IndexableDocuments.\n */\nasync function scanDir(dir: string, memoryRootReal: string): Promise<IndexableDocument[]> {\n const docs: IndexableDocument[] = [];\n try {\n const dirStat = await lstat(dir);\n if (dirStat.isSymbolicLink()) {\n throw new Error(`Refusing to scan symlinked memory category directory: ${dir}`);\n }\n if (!dirStat.isDirectory()) {\n const error = new Error(`Memory category path is not a directory: ${dir}`) as NodeJS.ErrnoException;\n error.code = \"ENOTDIR\";\n throw error;\n }\n assertPathInsideRoot(memoryRootReal, await realpath(dir), dir);\n\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isSymbolicLink()) continue;\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n assertPathInsideRoot(memoryRootReal, await realpath(fullPath), fullPath);\n const sub = await scanDir(fullPath, memoryRootReal);\n docs.push(...sub);\n } else if (entry.name.endsWith(\".md\")) {\n try {\n assertPathInsideRoot(memoryRootReal, await realpath(fullPath), fullPath);\n const raw = await readFile(fullPath, \"utf-8\");\n const parsed = parseFrontmatter(raw);\n const body = parsed ? parsed.body : raw.trim();\n const docid = parsed?.data.id || path.basename(entry.name, \".md\");\n docs.push({\n docid,\n path: fullPath,\n content: body,\n snippet: body.slice(0, 200),\n });\n } catch {\n // Skip unreadable files\n }\n }\n }\n } catch (err) {\n if (isNodeError(err) && err.code === \"ENOENT\") {\n // Optional category directories may not exist yet.\n return docs;\n }\n throw err;\n }\n return docs;\n}\n\nfunction isNodeError(err: unknown): err is NodeJS.ErrnoException {\n return typeof err === \"object\" && err !== null && \"code\" in err;\n}\n\n/**\n * Scan every recall category subdir of memoryDir for indexable markdown\n * documents. The directory set is derived from `RECALL_FALLBACK_DIRS`\n * (utils/category-dir.ts → ALL_CATEGORY_DIRS minus non-recall queue dirs) —\n * the single source of truth — so adding a new category never requires\n * touching this scanner. Non-QMD backends (Orama / Meilisearch / LanceDB)\n * build their index through this helper; deriving from RECALL_FALLBACK_DIRS\n * keeps them in parity with writeMemory's category-dir routing (issue #1546)\n * and the QMD filesystem-fallback corpus. reasoning-traces/ and the other\n * category dirs are covered automatically (issue #564 PR 3 no longer needs a\n * hand-maintained list). scanDir tolerates missing dirs (ENOENT), so category\n * dirs that do not exist yet are skipped.\n */\nexport async function scanMemoryDir(memoryDir: string): Promise<IndexableDocument[]> {\n let memoryRootReal: string;\n try {\n memoryRootReal = await realpath(memoryDir);\n } catch (err) {\n if (isNodeError(err) && err.code === \"ENOENT\") {\n return [];\n }\n throw err;\n }\n const perDir = await Promise.all(\n RECALL_FALLBACK_DIRS.map((dir) => scanDir(path.join(memoryDir, dir), memoryRootReal)),\n );\n return perDir.flat();\n}\n"],"mappings":";;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAS,OAAO,SAAS,UAAU,gBAAgB;AAmBnD,SAAS,iBAAiB,KAAoE;AAE5F,QAAM,aAAa,IAAI,QAAQ,SAAS,IAAI;AAC5C,QAAM,QAAQ,WAAW,M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SAAS,QAAQ,GAAG,QAAQ;AACvE,gBAAM,MAAM,MAAM,SAAS,UAAU,OAAO;AAC5C,gBAAM,SAAS,iBAAiB,GAAG;AACnC,gBAAM,OAAO,SAAS,OAAO,OAAO,IAAI,KAAK;AAC7C,gBAAM,QAAQ,QAAQ,KAAK,MAAM,KAAK,SAAS,MAAM,MAAM,KAAK;AAChE,eAAK,KAAK;AAAA,YACR;AAAA,YACA,MAAM;AAAA,YACN,SAAS;AAAA,YACT,SAAS,KAAK,MAAM,GAAG,GAAG;AAAA,UAC5B,CAAC;AAAA,QACH,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,QAAI,YAAY,GAAG,KAAK,IAAI,SAAS,UAAU;AAE7C,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACA,SAAO;AACT;AAEA,SAAS,YAAY,KAA4C;AAC/D,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,UAAU;AAC9D;AAeA,eAAsB,cAAc,WAAiD;AACnF,MAAI;AACJ,MAAI;AACF,qBAAiB,MAAM,SAAS,SAAS;AAAA,EAC3C,SAAS,KAAK;AACZ,QAAI,YAAY,GAAG,KAAK,IAAI,SAAS,UAAU;AAC7C,aAAO,CAAC;AAAA,IACV;AACA,UAAM;AAAA,EACR;AACA,QAAM,SAAS,MAAM,QAAQ;AAAA,IAC3B,qBAAqB,IAAI,CAAC,QAAQ,QAAQ,KAAK,KAAK,WAAW,GAAG,GAAG,cAAc,CAAC;AAAA,EACtF;AACA,SAAO,OAAO,KAAK;AACrB;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createVersion
3
- } from "./chunk-ALEPI75L.js";
3
+ } from "./chunk-VF4XKTX3.js";
4
4
  import {
5
5
  parseExportBundle
6
6
  } from "./chunk-WEHSQBFR.js";
@@ -227,4 +227,4 @@ function mintForkId(capsuleId, originalId, now) {
227
227
  export {
228
228
  importCapsule
229
229
  };
230
- //# sourceMappingURL=chunk-DHGSZ3UD.js.map
230
+ //# sourceMappingURL=chunk-ARV3AUOM.js.map
@@ -10,10 +10,10 @@ import {
10
10
  import {
11
11
  listMemoryGovernanceRuns,
12
12
  readMemoryGovernanceRunArtifact
13
- } from "./chunk-A7EF2XRO.js";
13
+ } from "./chunk-EXXBA5OM.js";
14
14
  import {
15
15
  StorageManager
16
- } from "./chunk-AX5O25EF.js";
16
+ } from "./chunk-VH6EIKVS.js";
17
17
  import {
18
18
  MEMORY_LIFECYCLE_EVENT_SORT_ORDER,
19
19
  buildLifecycleEventsForMemory,
@@ -929,4 +929,4 @@ export {
929
929
  verifyMemoryProjection,
930
930
  repairMemoryProjection
931
931
  };
932
- //# sourceMappingURL=chunk-PXVFMQLD.js.map
932
+ //# sourceMappingURL=chunk-BZG2CWOQ.js.map
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-3UXOZBHV.js";
8
8
  import {
9
9
  StorageManager
10
- } from "./chunk-AX5O25EF.js";
10
+ } from "./chunk-VH6EIKVS.js";
11
11
  import {
12
12
  isSafeRouteNamespace
13
13
  } from "./chunk-U3PN77QT.js";
@@ -118,4 +118,4 @@ export {
118
118
  runCodexMaterialize,
119
119
  runPostConsolidationMaterialize
120
120
  };
121
- //# sourceMappingURL=chunk-ANJOULTP.js.map
121
+ //# sourceMappingURL=chunk-C7AF236A.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  scanMemoryDir
3
- } from "./chunk-Q4CAQGKQ.js";
3
+ } from "./chunk-AER6MT24.js";
4
4
  import {
5
5
  isSearchAborted,
6
6
  throwIfSearchAborted
@@ -245,4 +245,4 @@ function isMeilisearchIndexNotFoundError(err) {
245
245
  export {
246
246
  MeilisearchBackend
247
247
  };
248
- //# sourceMappingURL=chunk-FZC2WSDB.js.map
248
+ //# sourceMappingURL=chunk-DOCTITOP.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSearchBackend
3
- } from "./chunk-35HP3TGR.js";
3
+ } from "./chunk-ROHLEUTH.js";
4
4
  import {
5
5
  namespaceIdentityToken,
6
6
  normalizeNamespaceIdentity
@@ -401,4 +401,4 @@ export {
401
401
  namespaceCollectionName,
402
402
  NamespaceSearchRouter
403
403
  };
404
- //# sourceMappingURL=chunk-WOQIHC67.js.map
404
+ //# sourceMappingURL=chunk-DQY7NJ5L.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  StorageManager
3
- } from "./chunk-AX5O25EF.js";
3
+ } from "./chunk-VH6EIKVS.js";
4
4
  import {
5
5
  getCachedRuleMemories,
6
6
  setCachedRuleMemories
@@ -117,4 +117,4 @@ export {
117
117
  compareVerifiedSemanticRuleResults,
118
118
  searchVerifiedSemanticRules
119
119
  };
120
- //# sourceMappingURL=chunk-NMPEJV5M.js.map
120
+ //# sourceMappingURL=chunk-DSLUOQDY.js.map
@@ -1,13 +1,19 @@
1
+ import {
2
+ assertPathInsideRoot
3
+ } from "./chunk-5GPPACXK.js";
1
4
  import {
2
5
  StorageManager
3
- } from "./chunk-AX5O25EF.js";
6
+ } from "./chunk-VH6EIKVS.js";
4
7
  import {
5
8
  decideLifecycleTransition
6
9
  } from "./chunk-TBBDFYXW.js";
10
+ import {
11
+ RECALL_FALLBACK_DIRS
12
+ } from "./chunk-VS2IYZRU.js";
7
13
 
8
14
  // src/maintenance/memory-governance.ts
9
15
  import path from "path";
10
- import { mkdir, readFile, readdir, rm, writeFile } from "fs/promises";
16
+ import { lstat, mkdir, readFile, readdir, realpath, rm, writeFile } from "fs/promises";
11
17
  var RULE_VERSION = "memory-governance.v2";
12
18
  var SEMANTIC_DUPLICATE_MIN_TOKENS = 6;
13
19
  var SEMANTIC_DUPLICATE_MIN_JACCARD = 0.66;
@@ -168,18 +174,27 @@ function buildExplicitCaptureReviewEntries(memories, lifecycleEvents) {
168
174
  relatedMemoryIds: []
169
175
  }));
170
176
  }
171
- async function listMarkdownFiles(root) {
177
+ async function listMarkdownFiles(root, containmentRoot) {
172
178
  const files = [];
173
179
  const walk = async (dir) => {
174
180
  try {
181
+ const dirStat = await lstat(dir);
182
+ if (dirStat.isSymbolicLink() || !dirStat.isDirectory()) return;
183
+ assertPathInsideRoot(containmentRoot, await realpath(dir), dir);
175
184
  const entries = await readdir(dir, { withFileTypes: true });
176
185
  for (const entry of entries) {
186
+ if (entry.isSymbolicLink()) continue;
177
187
  const fullPath = path.join(dir, entry.name);
178
188
  if (entry.isDirectory()) {
179
189
  await walk(fullPath);
180
190
  continue;
181
191
  }
182
192
  if (entry.isFile() && entry.name.endsWith(".md")) {
193
+ try {
194
+ assertPathInsideRoot(containmentRoot, await realpath(fullPath), fullPath);
195
+ } catch {
196
+ continue;
197
+ }
183
198
  files.push(fullPath);
184
199
  }
185
200
  }
@@ -194,10 +209,17 @@ function malformedMemoryId(memoryDir, filePath) {
194
209
  }
195
210
  async function buildMalformedImportEntries(memoryDir, storage, parsedMemories, candidateFiles) {
196
211
  const parsedPaths = new Set(parsedMemories.map((memory) => memory.path));
197
- const filesToInspect = candidateFiles ?? [
198
- ...await listMarkdownFiles(path.join(memoryDir, "facts")),
199
- ...await listMarkdownFiles(path.join(memoryDir, "corrections"))
200
- ];
212
+ let containmentRoot = null;
213
+ try {
214
+ containmentRoot = await realpath(memoryDir);
215
+ } catch {
216
+ containmentRoot = null;
217
+ }
218
+ const filesToInspect = candidateFiles ?? (containmentRoot === null ? [] : (await Promise.all(
219
+ RECALL_FALLBACK_DIRS.map(
220
+ (dir) => listMarkdownFiles(path.join(memoryDir, dir), containmentRoot)
221
+ )
222
+ )).flat());
201
223
  const entries = [];
202
224
  for (const filePath of filesToInspect) {
203
225
  if (parsedPaths.has(filePath)) continue;
@@ -729,4 +751,4 @@ export {
729
751
  listMemoryGovernanceRuns,
730
752
  readMemoryGovernanceRunArtifact
731
753
  };
732
- //# sourceMappingURL=chunk-A7EF2XRO.js.map
754
+ //# sourceMappingURL=chunk-EXXBA5OM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/maintenance/memory-governance.ts"],"sourcesContent":["import path from \"node:path\";\nimport { lstat, mkdir, readFile, readdir, realpath, rm, writeFile } from \"node:fs/promises\";\nimport { StorageManager } from \"../storage.js\";\nimport { decideLifecycleTransition } from \"../lifecycle.js\";\nimport type { MemoryFile, MemoryStatus } from \"../types.js\";\nimport { RECALL_FALLBACK_DIRS } from \"../utils/category-dir.js\";\nimport { assertPathInsideRoot } from \"../utils/path-containment.js\";\n\nexport type MemoryGovernanceMode = \"shadow\" | \"apply\";\nexport type MemoryGovernanceReasonCode =\n | \"exact_duplicate\"\n | \"semantic_duplicate_candidate\"\n | \"disputed_memory\"\n | \"speculative_low_confidence\"\n | \"archive_candidate\"\n | \"explicit_capture_review\"\n | \"malformed_import\";\n\nexport interface MemoryGovernanceReviewQueueEntry {\n entryId: string;\n memoryId: string;\n path: string;\n reasonCode: MemoryGovernanceReasonCode;\n severity: \"low\" | \"medium\" | \"high\";\n suggestedAction: \"set_status\" | \"archive\";\n suggestedStatus?: Extract<MemoryStatus, \"pending_review\" | \"quarantined\" | \"rejected\">;\n relatedMemoryIds: string[];\n}\n\nexport interface MemoryGovernanceAppliedAction {\n action: \"set_status\" | \"archive\";\n memoryId: string;\n reasonCode: MemoryGovernanceReviewQueueEntry[\"reasonCode\"];\n beforeStatus: MemoryStatus;\n afterStatus?: MemoryStatus;\n originalPath: string;\n currentPath: string;\n}\n\ninterface MemoryGovernanceRestoreEntry {\n action: MemoryGovernanceAppliedAction[\"action\"];\n memoryId: string;\n reasonCode: MemoryGovernanceReviewQueueEntry[\"reasonCode\"];\n originalPath: string;\n currentPath: string;\n beforeRaw: string;\n expectedCurrentRaw?: string;\n applied: boolean;\n}\n\nexport interface MemoryGovernanceRestoreManifest {\n runId: string;\n createdAt: string;\n entries: MemoryGovernanceRestoreEntry[];\n}\n\nexport interface MemoryGovernanceSummary {\n schemaVersion: 1;\n runId: string;\n traceId: string;\n mode: MemoryGovernanceMode;\n createdAt: string;\n scannedMemories: number;\n reviewQueueCount: number;\n proposedActionCount: number;\n appliedActionCount: number;\n ruleVersion: string;\n}\n\nexport interface MemoryGovernanceMetrics {\n reviewReasons: Record<MemoryGovernanceReasonCode, number>;\n proposedStatuses: Record<string, number>;\n keptMemoryCount: number;\n qualityScore: MemoryGovernanceQualityScore;\n}\n\nexport interface MemoryGovernanceQualityScore {\n score: number;\n maxScore: 100;\n grade: \"excellent\" | \"good\" | \"fair\" | \"poor\";\n deductions: Array<{\n reasonCode: MemoryGovernanceReasonCode;\n count: number;\n pointsLost: number;\n }>;\n}\n\nexport interface MemoryGovernanceTransitionReport {\n proposed: Record<string, MemoryGovernanceAppliedAction[]>;\n applied: Record<string, MemoryGovernanceAppliedAction[]>;\n}\n\nexport interface MemoryGovernanceManifest {\n schemaVersion: 1;\n runId: string;\n traceId: string;\n mode: MemoryGovernanceMode;\n createdAt: string;\n ruleVersion: string;\n artifacts: Record<string, string>;\n}\n\nexport interface MemoryGovernanceRunResult {\n runId: string;\n traceId: string;\n mode: MemoryGovernanceMode;\n summary: MemoryGovernanceSummary;\n summaryPath: string;\n reviewQueuePath: string;\n qualityScorePath: string;\n transitionReportPath: string;\n reportPath: string;\n keptMemoriesPath: string;\n appliedActionsPath: string;\n metricsPath: string;\n manifestPath: string;\n restorePath?: string;\n reviewQueue: MemoryGovernanceReviewQueueEntry[];\n proposedActions: MemoryGovernanceAppliedAction[];\n appliedActions: MemoryGovernanceAppliedAction[];\n}\n\nexport interface RestoreMemoryGovernanceRunResult {\n runId: string;\n restoredActions: number;\n restorePath: string;\n}\n\nexport interface RunMemoryGovernanceOptions {\n memoryDir: string;\n mode: MemoryGovernanceMode;\n now?: Date;\n maxMemories?: number;\n batchSize?: number;\n recentDays?: number;\n}\n\nexport interface RestoreMemoryGovernanceRunOptions {\n memoryDir: string;\n runId: string;\n now?: Date;\n}\n\nexport const RULE_VERSION = \"memory-governance.v2\";\nconst SEMANTIC_DUPLICATE_MIN_TOKENS = 6;\nconst SEMANTIC_DUPLICATE_MIN_JACCARD = 0.66;\nconst QUALITY_SCORE_WEIGHTS: Record<MemoryGovernanceReasonCode, number> = {\n exact_duplicate: 6,\n semantic_duplicate_candidate: 4,\n disputed_memory: 15,\n speculative_low_confidence: 8,\n archive_candidate: 2,\n explicit_capture_review: 5,\n malformed_import: 12,\n};\n\nfunction governanceRunsDir(memoryDir: string): string {\n return path.join(memoryDir, \"state\", \"memory-governance\", \"runs\");\n}\n\nfunction governanceRunDir(memoryDir: string, runId: string): string {\n return path.join(governanceRunsDir(memoryDir), runId);\n}\n\nfunction governanceRestorePath(memoryDir: string, runId: string): string {\n return path.join(governanceRunDir(memoryDir, runId), \"restore.json\");\n}\n\nfunction buildRunId(now: Date): string {\n return `gov-${now.toISOString().replace(/[:.]/g, \"-\")}`;\n}\n\nfunction plannedArchivePath(memoryDir: string, originalPath: string, now: Date): string {\n return path.join(\n memoryDir,\n \"archive\",\n now.toISOString().slice(0, 10),\n path.basename(originalPath),\n );\n}\n\nfunction normalizeContent(content: string): string {\n return content.trim().replace(/\\s+/g, \" \").toLowerCase();\n}\n\nfunction statusOf(memory: MemoryFile): MemoryStatus {\n return memory.frontmatter.status ?? \"active\";\n}\n\nfunction parseIsoMs(value?: string): number | null {\n if (!value) return null;\n const ms = Date.parse(value);\n return Number.isFinite(ms) ? ms : null;\n}\n\nfunction daysSince(value: string | undefined, now: Date): number {\n const ts = parseIsoMs(value);\n if (ts === null) return 365;\n return Math.max(0, (now.getTime() - ts) / 86_400_000);\n}\n\nfunction compareCanonicalPreference(left: MemoryFile, right: MemoryFile): number {\n if (left.frontmatter.confidence !== right.frontmatter.confidence) {\n return (right.frontmatter.confidence ?? 0) - (left.frontmatter.confidence ?? 0);\n }\n return left.frontmatter.created.localeCompare(right.frontmatter.created);\n}\n\nfunction proposedStatusPriority(status: MemoryStatus): number {\n switch (status) {\n case \"quarantined\":\n return 4;\n case \"rejected\":\n return 3;\n case \"archived\":\n return 2;\n case \"pending_review\":\n return 1;\n default:\n return 0;\n }\n}\n\nfunction proposedActionPriority(action: MemoryGovernanceAppliedAction): number {\n if (action.action === \"archive\") {\n return proposedStatusPriority(\"archived\");\n }\n return proposedStatusPriority(action.afterStatus ?? \"active\");\n}\n\nfunction tokenizeSemanticContent(content: string): string[] {\n return Array.from(\n new Set(\n normalizeContent(content)\n .replaceAll(/[^\\p{L}\\p{N}]+/gu, \" \")\n .split(\" \")\n .filter((token) => token.length >= 4),\n ),\n );\n}\n\nfunction jaccardSimilarity(left: string[], right: string[]): number {\n if (left.length === 0 || right.length === 0) return 0;\n const leftSet = new Set(left);\n const rightSet = new Set(right);\n let intersection = 0;\n for (const token of leftSet) {\n if (rightSet.has(token)) intersection += 1;\n }\n const union = new Set([...leftSet, ...rightSet]).size;\n return union > 0 ? intersection / union : 0;\n}\n\nfunction sameSemanticDuplicateScope(left: MemoryFile, right: MemoryFile): boolean {\n if (left.frontmatter.category !== right.frontmatter.category) return false;\n const leftEntityRef = left.frontmatter.entityRef?.trim();\n const rightEntityRef = right.frontmatter.entityRef?.trim();\n if (leftEntityRef && rightEntityRef && leftEntityRef !== rightEntityRef) return false;\n return true;\n}\n\nfunction buildSemanticDuplicateEntries(activeMemories: MemoryFile[]): MemoryGovernanceReviewQueueEntry[] {\n const reviewQueue: MemoryGovernanceReviewQueueEntry[] = [];\n const ordered = [...activeMemories].sort(compareCanonicalPreference);\n const tokensByMemoryId = new Map(\n ordered.map((memory) => [memory.frontmatter.id, tokenizeSemanticContent(memory.content)] as const),\n );\n const claimed = new Set<string>();\n\n for (let candidateIndex = 1; candidateIndex < ordered.length; candidateIndex += 1) {\n const candidate = ordered[candidateIndex];\n if (claimed.has(candidate.frontmatter.id)) continue;\n const candidateTokens = tokensByMemoryId.get(candidate.frontmatter.id) ?? [];\n if (candidateTokens.length < SEMANTIC_DUPLICATE_MIN_TOKENS) continue;\n const candidateNormalized = normalizeContent(candidate.content);\n\n for (let canonicalIndex = 0; canonicalIndex < candidateIndex; canonicalIndex += 1) {\n const canonical = ordered[canonicalIndex];\n if (!sameSemanticDuplicateScope(canonical, candidate)) continue;\n const canonicalNormalized = normalizeContent(canonical.content);\n if (canonicalNormalized === candidateNormalized) continue;\n const canonicalTokens = tokensByMemoryId.get(canonical.frontmatter.id) ?? [];\n if (canonicalTokens.length < SEMANTIC_DUPLICATE_MIN_TOKENS) continue;\n\n const shorter = Math.min(candidateTokens.length, canonicalTokens.length);\n const longer = Math.max(candidateTokens.length, canonicalTokens.length);\n if (shorter / longer < 0.6) continue;\n if (jaccardSimilarity(candidateTokens, canonicalTokens) < SEMANTIC_DUPLICATE_MIN_JACCARD) continue;\n\n reviewQueue.push({\n entryId: `review:${candidate.frontmatter.id}:semantic_duplicate_candidate`,\n memoryId: candidate.frontmatter.id,\n path: candidate.path,\n reasonCode: \"semantic_duplicate_candidate\",\n severity: \"medium\",\n suggestedAction: \"set_status\",\n suggestedStatus: \"pending_review\",\n relatedMemoryIds: [canonical.frontmatter.id],\n });\n claimed.add(candidate.frontmatter.id);\n break;\n }\n }\n\n return reviewQueue;\n}\n\nfunction buildExplicitCaptureReviewEntries(\n memories: MemoryFile[],\n lifecycleEvents: Array<{\n memoryId: string;\n eventType: string;\n reasonCode?: string;\n }>,\n): MemoryGovernanceReviewQueueEntry[] {\n const explicitQueuedIds = new Set(\n lifecycleEvents\n .filter((event) => event.eventType === \"explicit_capture_queued\")\n .map((event) => event.memoryId),\n );\n\n return memories\n .filter((memory) => {\n if (statusOf(memory) !== \"pending_review\") return false;\n const tags = memory.frontmatter.tags ?? [];\n if (tags.includes(\"queued-review\")) return true;\n if (explicitQueuedIds.has(memory.frontmatter.id)) return true;\n return memory.frontmatter.source === \"explicit-review\" || memory.frontmatter.source === \"explicit-inline-review\";\n })\n .map((memory) => ({\n entryId: `review:${memory.frontmatter.id}:explicit_capture_review`,\n memoryId: memory.frontmatter.id,\n path: memory.path,\n reasonCode: \"explicit_capture_review\" as const,\n severity: \"medium\" as const,\n suggestedAction: \"set_status\" as const,\n suggestedStatus: \"pending_review\" as const,\n relatedMemoryIds: [],\n }));\n}\n\n/**\n * List every `*.md` under `root`, refusing to follow symlinked directories or\n * entries that resolve outside `containmentRoot` (a realpath-resolved memory\n * store root). Mirrors the containment guard in consolidation-provenance's\n * walkMarkdownFiles / the CLI walker, reusing the shared assertPathInsideRoot\n * (rule 22). Without this, a symlinked category dir (e.g. decisions/ → outside\n * memoryDir) would be walked and its files surfaced by the malformed-import\n * governance sweep — an out-of-store info leak.\n */\nasync function listMarkdownFiles(root: string, containmentRoot: string): Promise<string[]> {\n const files: string[] = [];\n const walk = async (dir: string) => {\n try {\n const dirStat = await lstat(dir);\n if (dirStat.isSymbolicLink() || !dirStat.isDirectory()) return;\n assertPathInsideRoot(containmentRoot, await realpath(dir), dir);\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isSymbolicLink()) continue; // never follow symlinked entries\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n continue;\n }\n if (entry.isFile() && entry.name.endsWith(\".md\")) {\n try {\n assertPathInsideRoot(containmentRoot, await realpath(fullPath), fullPath);\n } catch {\n continue; // poisoned entry escaping the root — skip it.\n }\n files.push(fullPath);\n }\n }\n } catch {\n // Absent dir (ENOENT), symlinked/out-of-root dir, or containment\n // violation — skip this subtree without aborting the sweep.\n }\n };\n\n await walk(root);\n return files;\n}\n\nfunction malformedMemoryId(memoryDir: string, filePath: string): string {\n return `malformed:${path.relative(memoryDir, filePath).replaceAll(path.sep, \"/\")}`;\n}\n\nasync function buildMalformedImportEntries(\n memoryDir: string,\n storage: StorageManager,\n parsedMemories: MemoryFile[],\n candidateFiles?: string[],\n): Promise<MemoryGovernanceReviewQueueEntry[]> {\n const parsedPaths = new Set(parsedMemories.map((memory) => memory.path));\n // Inspect every recall category directory (RECALL_FALLBACK_DIRS — the single\n // source of truth) so malformed files under newly-routed categories\n // (decisions/, preferences/, ...) are surfaced too, not just facts/ (#1546).\n // Resolve the containment root (realpath) once and thread it into the walker\n // so a symlinked category dir can't escape memoryDir. If memoryDir itself\n // can't be resolved, there is nothing valid to inspect.\n let containmentRoot: string | null = null;\n try {\n containmentRoot = await realpath(memoryDir);\n } catch {\n containmentRoot = null;\n }\n const filesToInspect =\n candidateFiles ??\n (containmentRoot === null\n ? []\n : (\n await Promise.all(\n RECALL_FALLBACK_DIRS.map((dir) =>\n listMarkdownFiles(path.join(memoryDir, dir), containmentRoot as string),\n ),\n )\n ).flat());\n const entries: MemoryGovernanceReviewQueueEntry[] = [];\n\n for (const filePath of filesToInspect) {\n if (parsedPaths.has(filePath)) continue;\n const parsed = await storage.readMemoryByPath(filePath);\n if (parsed) continue;\n entries.push({\n entryId: `review:${malformedMemoryId(memoryDir, filePath)}:malformed_import`,\n memoryId: malformedMemoryId(memoryDir, filePath),\n path: filePath,\n reasonCode: \"malformed_import\",\n severity: \"high\",\n suggestedAction: \"set_status\",\n suggestedStatus: \"quarantined\",\n relatedMemoryIds: [],\n });\n }\n\n return entries;\n}\n\nasync function buildReviewQueue(\n memoryDir: string,\n storage: StorageManager,\n memories: MemoryFile[],\n now: Date,\n options: {\n malformedCandidateFiles?: string[];\n } = {},\n): Promise<MemoryGovernanceReviewQueueEntry[]> {\n const reviewQueue: MemoryGovernanceReviewQueueEntry[] = [];\n const activeMemories = memories.filter((memory) => statusOf(memory) === \"active\");\n const duplicateBuckets = new Map<string, MemoryFile[]>();\n\n for (const memory of activeMemories) {\n const key = `${memory.frontmatter.category}:${normalizeContent(memory.content)}`;\n const bucket = duplicateBuckets.get(key) ?? [];\n bucket.push(memory);\n duplicateBuckets.set(key, bucket);\n }\n\n for (const bucket of duplicateBuckets.values()) {\n if (bucket.length < 2) continue;\n const ordered = [...bucket].sort(compareCanonicalPreference);\n const canonical = ordered[0];\n for (const duplicate of ordered.slice(1)) {\n reviewQueue.push({\n entryId: `review:${duplicate.frontmatter.id}:exact_duplicate`,\n memoryId: duplicate.frontmatter.id,\n path: duplicate.path,\n reasonCode: \"exact_duplicate\",\n severity: \"medium\",\n suggestedAction: \"set_status\",\n suggestedStatus: \"pending_review\",\n relatedMemoryIds: canonical ? [canonical.frontmatter.id] : [],\n });\n }\n }\n\n reviewQueue.push(...buildSemanticDuplicateEntries(activeMemories));\n\n for (const memory of activeMemories) {\n if (memory.frontmatter.verificationState === \"disputed\") {\n reviewQueue.push({\n entryId: `review:${memory.frontmatter.id}:disputed_memory`,\n memoryId: memory.frontmatter.id,\n path: memory.path,\n reasonCode: \"disputed_memory\",\n severity: \"high\",\n suggestedAction: \"set_status\",\n suggestedStatus: \"quarantined\",\n relatedMemoryIds: [],\n });\n }\n\n if (\n memory.frontmatter.confidenceTier === \"speculative\"\n && (memory.frontmatter.confidence ?? 0) <= 0.25\n ) {\n reviewQueue.push({\n entryId: `review:${memory.frontmatter.id}:speculative_low_confidence`,\n memoryId: memory.frontmatter.id,\n path: memory.path,\n reasonCode: \"speculative_low_confidence\",\n severity: \"medium\",\n suggestedAction: \"set_status\",\n suggestedStatus: \"pending_review\",\n relatedMemoryIds: [],\n });\n }\n\n const lifecycle = decideLifecycleTransition(memory, {}, now);\n const staleForArchive = memory.frontmatter.lifecycleState === \"stale\"\n && daysSince(memory.frontmatter.updated ?? memory.frontmatter.created, now) >= 180;\n if ((lifecycle.nextState === \"archived\" && lifecycle.changed) || staleForArchive) {\n reviewQueue.push({\n entryId: `review:${memory.frontmatter.id}:archive_candidate`,\n memoryId: memory.frontmatter.id,\n path: memory.path,\n reasonCode: \"archive_candidate\",\n severity: \"low\",\n suggestedAction: \"archive\",\n relatedMemoryIds: [],\n });\n }\n }\n\n const lifecycleEvents = await storage.readMemoryLifecycleEvents(Number.MAX_SAFE_INTEGER);\n reviewQueue.push(...buildExplicitCaptureReviewEntries(memories, lifecycleEvents));\n reviewQueue.push(...await buildMalformedImportEntries(\n memoryDir,\n storage,\n memories,\n options.malformedCandidateFiles,\n ));\n\n return reviewQueue;\n}\n\nexport function buildProposedActions(\n reviewQueue: MemoryGovernanceReviewQueueEntry[],\n memories: MemoryFile[],\n): MemoryGovernanceAppliedAction[] {\n const byMemory = new Map(memories.map((memory) => [memory.frontmatter.id, memory]));\n const selected = new Map<string, MemoryGovernanceAppliedAction>();\n\n for (const entry of reviewQueue) {\n const memory = byMemory.get(entry.memoryId);\n if (!memory) continue;\n const currentStatus = statusOf(memory);\n if (\n entry.suggestedAction === \"set_status\"\n && entry.suggestedStatus\n && entry.suggestedStatus === currentStatus\n ) {\n continue;\n }\n const candidate: MemoryGovernanceAppliedAction = {\n action: entry.suggestedAction,\n memoryId: entry.memoryId,\n reasonCode: entry.reasonCode,\n beforeStatus: currentStatus,\n afterStatus: entry.suggestedStatus,\n originalPath: memory.path,\n currentPath: memory.path,\n };\n\n const existing = selected.get(entry.memoryId);\n if (!existing) {\n selected.set(entry.memoryId, candidate);\n continue;\n }\n\n const existingPriority = proposedActionPriority(existing);\n const candidatePriority = proposedActionPriority(candidate);\n if (candidatePriority > existingPriority) {\n selected.set(entry.memoryId, candidate);\n }\n }\n\n return [...selected.values()];\n}\n\nfunction buildMetrics(\n reviewQueue: MemoryGovernanceReviewQueueEntry[],\n proposedActions: MemoryGovernanceAppliedAction[],\n scannedMemories: number,\n): MemoryGovernanceMetrics {\n const reviewReasons: MemoryGovernanceMetrics[\"reviewReasons\"] = {\n exact_duplicate: 0,\n semantic_duplicate_candidate: 0,\n disputed_memory: 0,\n speculative_low_confidence: 0,\n archive_candidate: 0,\n explicit_capture_review: 0,\n malformed_import: 0,\n };\n const proposedStatuses: Record<string, number> = {};\n\n for (const entry of reviewQueue) {\n reviewReasons[entry.reasonCode] += 1;\n }\n\n for (const action of proposedActions) {\n const effectiveStatus = action.afterStatus ?? (action.action === \"archive\" ? \"archived\" : undefined);\n if (!effectiveStatus) continue;\n proposedStatuses[effectiveStatus] = (proposedStatuses[effectiveStatus] ?? 0) + 1;\n }\n\n return {\n reviewReasons,\n proposedStatuses,\n keptMemoryCount: Math.max(0, scannedMemories - proposedActions.length),\n qualityScore: buildQualityScore(reviewReasons),\n };\n}\n\nexport function buildQualityScore(\n reviewReasons: Record<MemoryGovernanceReasonCode, number>,\n): MemoryGovernanceQualityScore {\n const deductions = Object.entries(reviewReasons)\n .map(([reasonCode, count]) => ({\n reasonCode: reasonCode as MemoryGovernanceReasonCode,\n count,\n pointsLost: count * QUALITY_SCORE_WEIGHTS[reasonCode as MemoryGovernanceReasonCode],\n }))\n .filter((entry) => entry.count > 0)\n .sort((left, right) => right.pointsLost - left.pointsLost);\n const totalPointsLost = deductions.reduce((sum, entry) => sum + entry.pointsLost, 0);\n const score = Math.max(0, 100 - totalPointsLost);\n const grade = score >= 90 ? \"excellent\"\n : score >= 75 ? \"good\"\n : score >= 50 ? \"fair\"\n : \"poor\";\n return {\n score,\n maxScore: 100,\n grade,\n deductions,\n };\n}\n\nexport function groupActionsByStatus(\n actions: MemoryGovernanceAppliedAction[],\n): Record<string, MemoryGovernanceAppliedAction[]> {\n const grouped: Record<string, MemoryGovernanceAppliedAction[]> = {};\n for (const action of actions) {\n const status = action.afterStatus ?? (action.action === \"archive\" ? \"archived\" : \"unchanged\");\n const bucket = grouped[status] ?? [];\n bucket.push(action);\n grouped[status] = bucket;\n }\n return grouped;\n}\n\nasync function safeRead(filePath: string): Promise<string | null> {\n try {\n return await readFile(filePath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\nasync function persistRestoreManifest(\n memoryDir: string,\n manifest: MemoryGovernanceRestoreManifest,\n): Promise<string> {\n const restorePath = governanceRestorePath(memoryDir, manifest.runId);\n await mkdir(path.dirname(restorePath), { recursive: true });\n await writeFile(restorePath, JSON.stringify(manifest, null, 2), \"utf-8\");\n return restorePath;\n}\n\nasync function writeGovernanceArtifacts(options: {\n memoryDir: string;\n runId: string;\n traceId: string;\n summary: MemoryGovernanceSummary;\n metrics: MemoryGovernanceMetrics;\n qualityScore: MemoryGovernanceQualityScore;\n transitionReport: MemoryGovernanceTransitionReport;\n keptMemoryIds: string[];\n reviewQueue: MemoryGovernanceReviewQueueEntry[];\n proposedActions: MemoryGovernanceAppliedAction[];\n appliedActions: MemoryGovernanceAppliedAction[];\n restoreManifest?: MemoryGovernanceRestoreManifest;\n}): Promise<\n Pick<\n MemoryGovernanceRunResult,\n | \"summaryPath\"\n | \"reviewQueuePath\"\n | \"qualityScorePath\"\n | \"transitionReportPath\"\n | \"reportPath\"\n | \"keptMemoriesPath\"\n | \"appliedActionsPath\"\n | \"metricsPath\"\n | \"manifestPath\"\n | \"restorePath\"\n >\n> {\n const runDir = governanceRunDir(options.memoryDir, options.runId);\n await mkdir(runDir, { recursive: true });\n\n const summaryPath = path.join(runDir, \"summary.json\");\n const reviewQueuePath = path.join(runDir, \"review-queue.json\");\n const qualityScorePath = path.join(runDir, \"quality-score.json\");\n const transitionReportPath = path.join(runDir, \"status-transitions.json\");\n const reportPath = path.join(runDir, \"report.md\");\n const keptMemoriesPath = path.join(runDir, \"kept-memories.json\");\n const appliedActionsPath = path.join(runDir, \"applied-actions.json\");\n const metricsPath = path.join(runDir, \"metrics.json\");\n const manifestPath = path.join(runDir, \"manifest.json\");\n const restorePath = options.restoreManifest ? governanceRestorePath(options.memoryDir, options.runId) : undefined;\n\n await writeFile(summaryPath, JSON.stringify(options.summary, null, 2), \"utf-8\");\n await writeFile(reviewQueuePath, JSON.stringify(options.reviewQueue, null, 2), \"utf-8\");\n await writeFile(qualityScorePath, JSON.stringify(options.qualityScore, null, 2), \"utf-8\");\n await writeFile(transitionReportPath, JSON.stringify(options.transitionReport, null, 2), \"utf-8\");\n await writeFile(keptMemoriesPath, JSON.stringify(options.keptMemoryIds, null, 2), \"utf-8\");\n await writeFile(appliedActionsPath, JSON.stringify(options.appliedActions, null, 2), \"utf-8\");\n await writeFile(metricsPath, JSON.stringify(options.metrics, null, 2), \"utf-8\");\n await writeFile(\n reportPath,\n [\n `# Memory Governance Run ${options.runId}`,\n \"\",\n `- Trace ID: ${options.traceId}`,\n `- Mode: ${options.summary.mode}`,\n `- Scanned memories: ${options.summary.scannedMemories}`,\n `- Kept memories: ${options.metrics.keptMemoryCount}`,\n `- Review queue entries: ${options.summary.reviewQueueCount}`,\n `- Proposed actions: ${options.summary.proposedActionCount}`,\n `- Applied actions: ${options.summary.appliedActionCount}`,\n `- Quality score: ${options.qualityScore.score}/${options.qualityScore.maxScore} (${options.qualityScore.grade})`,\n \"\",\n \"## Metrics\",\n ...Object.entries(options.metrics.reviewReasons).map(([reason, count]) => `- ${reason}: ${count}`),\n ...(Object.entries(options.metrics.proposedStatuses).length > 0\n ? Object.entries(options.metrics.proposedStatuses).map(([status, count]) => `- proposed ${status}: ${count}`)\n : [\"- proposed statuses: (none)\"]),\n \"\",\n \"## Quality Score\",\n ...(options.qualityScore.deductions.length > 0\n ? options.qualityScore.deductions.map((entry) => `- ${entry.reasonCode}: ${entry.count} -> -${entry.pointsLost}`)\n : [\"- no deductions\"]),\n \"\",\n \"## Proposed Actions\",\n ...(options.proposedActions.length > 0\n ? options.proposedActions.map((action) =>\n `- ${action.memoryId}: ${action.action}${action.afterStatus ? ` -> ${action.afterStatus}` : \"\"} [${action.reasonCode}]`,\n )\n : [\"- (empty)\"]),\n \"\",\n \"## Applied Actions\",\n ...(options.appliedActions.length > 0\n ? options.appliedActions.map((action) =>\n `- ${action.memoryId}: ${action.action}${action.afterStatus ? ` -> ${action.afterStatus}` : \"\"} [${action.reasonCode}]`,\n )\n : [\"- (empty)\"]),\n \"\",\n \"## Review Queue\",\n ...(options.reviewQueue.length > 0\n ? options.reviewQueue.map((entry) =>\n `- ${entry.memoryId}: ${entry.reasonCode} -> ${entry.suggestedAction}${entry.suggestedStatus ? ` (${entry.suggestedStatus})` : \"\"}`,\n )\n : [\"- (empty)\"]),\n ].join(\"\\n\"),\n \"utf-8\",\n );\n const manifest: MemoryGovernanceManifest = {\n schemaVersion: 1,\n runId: options.runId,\n traceId: options.traceId,\n mode: options.summary.mode,\n createdAt: options.summary.createdAt,\n ruleVersion: options.summary.ruleVersion,\n artifacts: {\n summary: summaryPath,\n reviewQueue: reviewQueuePath,\n qualityScore: qualityScorePath,\n transitionReport: transitionReportPath,\n report: reportPath,\n keptMemories: keptMemoriesPath,\n appliedActions: appliedActionsPath,\n metrics: metricsPath,\n ...(restorePath ? { restore: restorePath } : {}),\n },\n };\n await writeFile(manifestPath, JSON.stringify(manifest, null, 2), \"utf-8\");\n if (restorePath && options.restoreManifest && await safeRead(restorePath) === null) {\n await writeFile(restorePath, JSON.stringify(options.restoreManifest, null, 2), \"utf-8\");\n }\n\n return {\n summaryPath,\n reviewQueuePath,\n qualityScorePath,\n transitionReportPath,\n reportPath,\n keptMemoriesPath,\n appliedActionsPath,\n metricsPath,\n manifestPath,\n restorePath,\n };\n}\n\nexport async function runMemoryGovernance(\n options: RunMemoryGovernanceOptions,\n): Promise<MemoryGovernanceRunResult> {\n const now = options.now ?? new Date();\n const runId = buildRunId(now);\n const traceId = runId;\n const storage = new StorageManager(options.memoryDir);\n const boundedScan =\n options.maxMemories !== undefined ||\n options.recentDays !== undefined ||\n options.batchSize !== undefined;\n const normalizedRecentDays = typeof options.recentDays === \"number\" && Number.isFinite(options.recentDays)\n ? Math.max(1, Math.floor(options.recentDays))\n : undefined;\n const updatedAfter = normalizedRecentDays !== undefined\n ? new Date(now.getTime() - normalizedRecentDays * 86_400_000)\n : undefined;\n const memoryWindow = boundedScan\n ? await storage.readMemoriesWindow({\n maxMemories: options.maxMemories,\n batchSize: options.batchSize,\n updatedAfter,\n })\n : undefined;\n const memories = memoryWindow?.memories ?? await storage.readAllMemories();\n const reviewQueue = await buildReviewQueue(options.memoryDir, storage, memories, now, {\n malformedCandidateFiles: memoryWindow?.filePaths,\n });\n const proposedActions = buildProposedActions(reviewQueue, memories);\n const reviewEntryByActionKey = new Map(\n reviewQueue.map((entry) => [`${entry.memoryId}:${entry.reasonCode}`, entry] as const),\n );\n const metrics = buildMetrics(reviewQueue, proposedActions, memories.length);\n const transitionReport: MemoryGovernanceTransitionReport = {\n proposed: groupActionsByStatus(proposedActions),\n applied: {},\n };\n const memoryPathById = new Map(memories.map((memory) => [memory.frontmatter.id, memory.path] as const));\n const targetedMemoryIds = new Set(proposedActions.map((action) => action.memoryId));\n const keptMemoryIds = memories\n .map((memory) => memory.frontmatter.id)\n .filter((memoryId) => !targetedMemoryIds.has(memoryId));\n const appliedActions: MemoryGovernanceAppliedAction[] = [];\n const restoreEntries: MemoryGovernanceRestoreEntry[] = [];\n const restoreEntryByMemoryId = new Map<string, MemoryGovernanceRestoreEntry>();\n\n if (options.mode === \"apply\") {\n for (const action of proposedActions) {\n const memoryPath = memoryPathById.get(action.memoryId) ?? null;\n if (!memoryPath) continue;\n const memory = await storage.readMemoryByPath(memoryPath);\n if (!memory) continue;\n if (memory.frontmatter.id !== action.memoryId) continue;\n const beforeRaw = await safeRead(memory.path);\n if (!beforeRaw) continue;\n const entry: MemoryGovernanceRestoreEntry = {\n action: action.action,\n memoryId: action.memoryId,\n reasonCode: action.reasonCode,\n originalPath: memory.path,\n currentPath: action.action === \"archive\"\n ? plannedArchivePath(options.memoryDir, memory.path, now)\n : memory.path,\n beforeRaw,\n applied: false,\n };\n restoreEntries.push(entry);\n restoreEntryByMemoryId.set(action.memoryId, entry);\n }\n\n const restoreManifest: MemoryGovernanceRestoreManifest = {\n runId,\n createdAt: now.toISOString(),\n entries: restoreEntries,\n };\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n\n for (const action of proposedActions) {\n const memoryPath = memoryPathById.get(action.memoryId) ?? null;\n if (!memoryPath) continue;\n const memory = await storage.readMemoryByPath(memoryPath);\n if (!memory) continue;\n if (memory.frontmatter.id !== action.memoryId) continue;\n const restoreEntry = restoreEntryByMemoryId.get(action.memoryId);\n if (!restoreEntry) continue;\n\n if (action.action === \"archive\") {\n const reviewEntry = reviewEntryByActionKey.get(`${action.memoryId}:${action.reasonCode}`);\n restoreEntry.applied = true;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n const archivedPath = await storage.archiveMemory(memory, {\n at: now,\n actor: \"memory-governance.apply\",\n reasonCode: action.reasonCode,\n ruleVersion: RULE_VERSION,\n relatedMemoryIds: reviewEntry?.relatedMemoryIds ?? [],\n correlationId: traceId,\n });\n if (!archivedPath) {\n restoreEntry.applied = false;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n continue;\n }\n restoreEntry.currentPath = archivedPath;\n restoreEntry.expectedCurrentRaw = await safeRead(archivedPath) ?? undefined;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n appliedActions.push({\n ...action,\n currentPath: archivedPath,\n afterStatus: \"archived\",\n });\n continue;\n }\n\n if (!action.afterStatus || action.beforeStatus === action.afterStatus) continue;\n const reviewEntry = reviewEntryByActionKey.get(`${action.memoryId}:${action.reasonCode}`);\n restoreEntry.applied = true;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n const updated = await storage.writeMemoryFrontmatter(memory, {\n status: action.afterStatus,\n updated: now.toISOString(),\n }, {\n actor: \"memory-governance.apply\",\n reasonCode: action.reasonCode,\n ruleVersion: RULE_VERSION,\n relatedMemoryIds: reviewEntry?.relatedMemoryIds ?? [],\n correlationId: traceId,\n });\n if (!updated) {\n restoreEntry.applied = false;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n continue;\n }\n restoreEntry.expectedCurrentRaw = await safeRead(memory.path) ?? undefined;\n await persistRestoreManifest(options.memoryDir, restoreManifest);\n appliedActions.push({\n ...action,\n currentPath: memory.path,\n });\n }\n }\n\n const summary: MemoryGovernanceSummary = {\n schemaVersion: 1,\n runId,\n traceId,\n mode: options.mode,\n createdAt: now.toISOString(),\n scannedMemories: memories.length,\n reviewQueueCount: reviewQueue.length,\n proposedActionCount: proposedActions.length,\n appliedActionCount: appliedActions.length,\n ruleVersion: RULE_VERSION,\n };\n const restoreManifest = options.mode === \"apply\"\n ? {\n runId,\n createdAt: now.toISOString(),\n entries: restoreEntries,\n }\n : undefined;\n transitionReport.applied = groupActionsByStatus(appliedActions);\n const paths = await writeGovernanceArtifacts({\n memoryDir: options.memoryDir,\n runId,\n traceId,\n summary,\n metrics,\n qualityScore: metrics.qualityScore,\n transitionReport,\n keptMemoryIds,\n reviewQueue,\n proposedActions,\n appliedActions,\n restoreManifest,\n });\n\n return {\n runId,\n traceId,\n mode: options.mode,\n summary,\n ...paths,\n reviewQueue,\n proposedActions,\n appliedActions,\n };\n}\n\nexport async function restoreMemoryGovernanceRun(\n options: RestoreMemoryGovernanceRunOptions,\n): Promise<RestoreMemoryGovernanceRunResult> {\n void options.now;\n const restorePath = governanceRestorePath(options.memoryDir, options.runId);\n const raw = JSON.parse(await readFile(restorePath, \"utf-8\")) as MemoryGovernanceRestoreManifest;\n let restoredActions = 0;\n\n for (const entry of [...raw.entries].reverse()) {\n if (!entry.applied) {\n continue;\n }\n const currentRaw = await safeRead(entry.currentPath);\n if (entry.expectedCurrentRaw && currentRaw !== entry.expectedCurrentRaw) {\n throw new Error(`restore conflict for ${entry.memoryId}: current contents diverged from governance run`);\n }\n if (entry.action === \"archive\") {\n await rm(entry.currentPath, { force: true });\n }\n await mkdir(path.dirname(entry.originalPath), { recursive: true });\n await writeFile(entry.originalPath, entry.beforeRaw, \"utf-8\");\n restoredActions += 1;\n }\n\n return {\n runId: raw.runId,\n restoredActions,\n restorePath,\n };\n}\n\nexport async function listMemoryGovernanceRuns(memoryDir: string): Promise<string[]> {\n try {\n return (await readdir(governanceRunsDir(memoryDir))).sort().reverse();\n } catch {\n return [];\n }\n}\n\nexport async function readMemoryGovernanceRunArtifact(\n memoryDir: string,\n runId: string,\n): Promise<{\n summary: MemoryGovernanceSummary;\n metrics: MemoryGovernanceMetrics;\n qualityScore: MemoryGovernanceQualityScore;\n keptMemoryIds: string[];\n reviewQueue: MemoryGovernanceReviewQueueEntry[];\n appliedActions: MemoryGovernanceAppliedAction[];\n transitionReport: MemoryGovernanceTransitionReport;\n report: string;\n manifest: MemoryGovernanceManifest;\n restore?: MemoryGovernanceRestoreManifest;\n}> {\n const runDir = governanceRunDir(memoryDir, runId);\n const summary = JSON.parse(await readFile(path.join(runDir, \"summary.json\"), \"utf-8\")) as MemoryGovernanceSummary;\n const metrics = JSON.parse(await readFile(path.join(runDir, \"metrics.json\"), \"utf-8\")) as MemoryGovernanceMetrics;\n metrics.qualityScore ??= buildQualityScore(metrics.reviewReasons);\n const keptMemoryIds = JSON.parse(await readFile(path.join(runDir, \"kept-memories.json\"), \"utf-8\")) as string[];\n const reviewQueue = JSON.parse(\n await readFile(path.join(runDir, \"review-queue.json\"), \"utf-8\"),\n ) as MemoryGovernanceReviewQueueEntry[];\n const appliedActions = JSON.parse(\n await readFile(path.join(runDir, \"applied-actions.json\"), \"utf-8\"),\n ) as MemoryGovernanceAppliedAction[];\n const qualityScoreRaw = await safeRead(path.join(runDir, \"quality-score.json\"));\n const transitionReportRaw = await safeRead(path.join(runDir, \"status-transitions.json\"));\n const manifest = JSON.parse(\n await readFile(path.join(runDir, \"manifest.json\"), \"utf-8\"),\n ) as MemoryGovernanceManifest;\n const report = await readFile(path.join(runDir, \"report.md\"), \"utf-8\");\n const restoreRaw = await safeRead(path.join(runDir, \"restore.json\"));\n const qualityScore = qualityScoreRaw\n ? JSON.parse(qualityScoreRaw) as MemoryGovernanceQualityScore\n : metrics.qualityScore ?? buildQualityScore(metrics.reviewReasons);\n const transitionReport = transitionReportRaw\n ? JSON.parse(transitionReportRaw) as MemoryGovernanceTransitionReport\n : {\n proposed: {},\n applied: groupActionsByStatus(appliedActions),\n };\n return {\n summary,\n metrics,\n qualityScore,\n keptMemoryIds,\n reviewQueue,\n appliedActions,\n transitionReport,\n report,\n manifest,\n restore: restoreRaw ? JSON.parse(restoreRaw) as MemoryGovernanceRestoreManifest : undefined,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAS,OAAO,OAAO,UAAU,SAAS,UAAU,IAAI,iBAAiB;AA8IlE,IAAM,eAAe;AAC5B,IAAM,gCAAgC;AACtC,IAAM,iCAAiC;AACvC,IAAM,wBAAoE;AAAA,EACxE,iBAAiB;AAAA,EACjB,8BAA8B;AAAA,EAC9B,iBAAi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OAAO,CAAC;AACjG,QAAM,cAAc,KAAK;AAAA,IACvB,MAAM,SAAS,KAAK,KAAK,QAAQ,mBAAmB,GAAG,OAAO;AAAA,EAChE;AACA,QAAM,iBAAiB,KAAK;AAAA,IAC1B,MAAM,SAAS,KAAK,KAAK,QAAQ,sBAAsB,GAAG,OAAO;AAAA,EACnE;AACA,QAAM,kBAAkB,MAAM,SAAS,KAAK,KAAK,QAAQ,oBAAoB,CAAC;AAC9E,QAAM,sBAAsB,MAAM,SAAS,KAAK,KAAK,QAAQ,yBAAyB,CAAC;AACvF,QAAM,WAAW,KAAK;AAAA,IACpB,MAAM,SAAS,KAAK,KAAK,QAAQ,eAAe,GAAG,OAAO;AAAA,EAC5D;AACA,QAAM,SAAS,MAAM,SAAS,KAAK,KAAK,QAAQ,WAAW,GAAG,OAAO;AACrE,QAAM,aAAa,MAAM,SAAS,KAAK,KAAK,QAAQ,cAAc,CAAC;AACnE,QAAM,eAAe,kBACjB,KAAK,MAAM,eAAe,IAC1B,QAAQ,gBAAgB,kBAAkB,QAAQ,aAAa;AACnE,QAAM,mBAAmB,sBACrB,KAAK,MAAM,mBAAmB,IAC9B;AAAA,IACE,UAAU,CAAC;AAAA,IACX,SAAS,qBAAqB,cAAc;AAAA,EAC9C;AACJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,aAAa,KAAK,MAAM,UAAU,IAAuC;AAAA,EACpF;AACF;","names":["restoreManifest","reviewEntry"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  StorageManager
3
- } from "./chunk-AX5O25EF.js";
3
+ } from "./chunk-VH6EIKVS.js";
4
4
 
5
5
  // src/semantic-rule-promotion.ts
6
6
  import { createHash, randomUUID } from "crypto";
@@ -529,4 +529,4 @@ export {
529
529
  setSemanticRulePromotionTestHooks,
530
530
  promoteSemanticRuleFromMemory
531
531
  };
532
- //# sourceMappingURL=chunk-QXHBWFR3.js.map
532
+ //# sourceMappingURL=chunk-IHG6CC7T.js.map
@@ -6,10 +6,10 @@ import {
6
6
  } from "./chunk-7WV3F5DQ.js";
7
7
  import {
8
8
  EngramMcpServer
9
- } from "./chunk-2KDQI363.js";
9
+ } from "./chunk-2HEZXPYU.js";
10
10
  import {
11
11
  EngramAccessInputError
12
- } from "./chunk-DFAXGZKI.js";
12
+ } from "./chunk-JIX3ZL2J.js";
13
13
  import {
14
14
  projectTagProjectId
15
15
  } from "./chunk-GYSYLGNE.js";
@@ -30,12 +30,12 @@ import {
30
30
  } from "./chunk-2ODBA7MQ.js";
31
31
  import {
32
32
  validateRequest
33
- } from "./chunk-UAU5U5ML.js";
33
+ } from "./chunk-UDJLF3BO.js";
34
34
  import {
35
35
  OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
36
36
  OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
37
37
  OFFLINE_SYNC_SNAPSHOT_BASE_MAX_BODY_BYTES
38
- } from "./chunk-ZLDUQWT2.js";
38
+ } from "./chunk-PWWWLD7D.js";
39
39
 
40
40
  // src/access-http.ts
41
41
  import { createServer } from "http";
@@ -2030,4 +2030,4 @@ function positiveIntQueryParam(value, label) {
2030
2030
  export {
2031
2031
  EngramAccessHttpServer
2032
2032
  };
2033
- //# sourceMappingURL=chunk-4KDLCMLK.js.map
2033
+ //# sourceMappingURL=chunk-IROWLAWG.js.map
@@ -10,6 +10,9 @@ import {
10
10
  parseEnvelope,
11
11
  seal
12
12
  } from "./chunk-A6XUJE5D.js";
13
+ import {
14
+ RECALL_FALLBACK_DIRS
15
+ } from "./chunk-VS2IYZRU.js";
13
16
 
14
17
  // src/secure-store/secure-fs.ts
15
18
  import { createCipheriv, randomBytes, randomUUID } from "crypto";
@@ -402,10 +405,7 @@ function normalizeStorageRelativePath(rel) {
402
405
  return normalized;
403
406
  }
404
407
  var ENCRYPTABLE_MARKDOWN_STORAGE_ROOTS = /* @__PURE__ */ new Set([
405
- "facts",
406
- "corrections",
407
- "procedures",
408
- "reasoning-traces",
408
+ ...RECALL_FALLBACK_DIRS,
409
409
  "artifacts",
410
410
  "archive",
411
411
  "entities",
@@ -453,4 +453,4 @@ export {
453
453
  migrateMemoryDirToEncrypted,
454
454
  decryptMemoryDirToPlaintext
455
455
  };
456
- //# sourceMappingURL=chunk-ILXTATKK.js.map
456
+ //# sourceMappingURL=chunk-J2HSAU72.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/secure-store/secure-fs.ts"],"sourcesContent":["/**\n * Transparent file-level encryption for the secure-store module.\n *\n * Issue #690 (PR 3/4) — storage.ts integration layer.\n *\n * This module sits between the raw filesystem and StorageManager.\n * Every memory file is either:\n * - a plain UTF-8 text file (legacy, back-compat), or\n * - a REMNIC-ENC sealed file (AES-256-GCM, see format below).\n *\n * On-disk format\n * --------------\n * Encrypted files begin with a 9-byte magic header:\n *\n * REMNIC-ENC (7 ASCII bytes)\n * VER (1 byte, currently 0x01)\n * FLAGS (1 byte, reserved, must be 0x00)\n *\n * Followed immediately by a `seal()` envelope from `cipher.ts`:\n *\n * [VERSION:1][SALT:16][IV:12][AUTHTAG:16][CIPHERTEXT:...]\n *\n * The magic header makes encrypted files sniffable without attempting\n * a full `open()` call and gives operators a clear signal that the\n * file cannot be read by opening it in an editor.\n *\n * AAD\n * ---\n * The file path relative to the memory root is bound as Associated\n * Authenticated Data (AAD) on both encrypt and decrypt. This means\n * moving or renaming an encrypted file without re-encrypting it will\n * cause auth-tag failure on the next read — the file is tied to its\n * path. Callers that move files must re-encrypt them.\n *\n * Back-compat\n * -----------\n * `readMaybeEncryptedFile` transparently handles both formats: if the\n * file does NOT start with the magic bytes, it is returned as-is (plain\n * text). This lets an operator migrate incrementally: newly-written\n * files are encrypted while existing files continue to be read in plain\n * form until `migrateMemoryDirToEncrypted` is run.\n *\n * Naming: `secure-fs.ts` (not `vault-fs.ts`) — see `kdf.ts` naming note.\n */\n\nimport { createCipheriv, randomBytes, randomUUID } from \"node:crypto\";\nimport { lstat, mkdir, open as openFile, readFile, readdir, rename, unlink, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport {\n AUTH_TAG_LENGTH,\n ENVELOPE_HEADER_SIZE,\n ENVELOPE_LAYOUT,\n ENVELOPE_SALT_LENGTH,\n ENVELOPE_VERSION,\n IV_LENGTH,\n generateSalt,\n open as openEnvelope,\n parseEnvelope,\n seal,\n} from \"./cipher.js\";\nimport { RECALL_FALLBACK_DIRS } from \"../utils/category-dir.js\";\n\n// ---------------------------------------------------------------------------\n// Error classes\n// ---------------------------------------------------------------------------\n\n/**\n * Thrown when a read is attempted but the keyring entry for this\n * store is absent (i.e. `secure-store unlock` has not been run\n * since the last daemon start).\n */\nexport class SecureStoreLockedError extends Error {\n constructor(message = \"secure-store is locked — run `remnic secure-store unlock` to decrypt\") {\n super(message);\n this.name = \"SecureStoreLockedError\";\n }\n}\n\n/**\n * Thrown when `open()` fails because the auth tag does not validate.\n * This covers both wrong-key and tampered-ciphertext scenarios —\n * intentionally indistinguishable from the caller's perspective.\n */\nexport class SecureStoreDecryptError extends Error {\n constructor(message = \"secure-store decryption failed — wrong key or tampered ciphertext\") {\n super(message);\n this.name = \"SecureStoreDecryptError\";\n }\n}\n\n// ---------------------------------------------------------------------------\n// Magic header\n// ---------------------------------------------------------------------------\n\n/** Magic bytes: the ASCII string \"REMNIC-ENC\" (10 bytes). */\nexport const MAGIC_BYTES = Buffer.from(\"REMNIC-ENC\", \"ascii\");\n\n/** Current on-disk version byte. */\nexport const FILE_FORMAT_VERSION = 0x01;\n\n/** Reserved flags byte — must be 0x00. */\nexport const FILE_FORMAT_FLAGS = 0x00;\n\n/** Total size of the magic header prefix (magic + version + flags). */\nexport const MAGIC_HEADER_SIZE = MAGIC_BYTES.length + 2; // 12 bytes\n\n// ---------------------------------------------------------------------------\n// Detection\n// ---------------------------------------------------------------------------\n\n/**\n * Return true iff `buf` begins with the REMNIC-ENC magic header.\n * Does not validate the envelope; just identifies the format.\n */\nexport function isEncryptedFile(buf: Uint8Array): boolean {\n if (buf.length < MAGIC_HEADER_SIZE) return false;\n const b = Buffer.isBuffer(buf) ? buf : Buffer.from(buf);\n return b.subarray(0, MAGIC_BYTES.length).equals(MAGIC_BYTES);\n}\n\n// ---------------------------------------------------------------------------\n// Encrypt / decrypt file body\n// ---------------------------------------------------------------------------\n\n/**\n * Encrypt `plain` (UTF-8 content of a memory file) and return a\n * Buffer ready to write to disk.\n *\n * @param plain Plain-text file content (UTF-8 string or Buffer).\n * @param key 32-byte AES-256 key from the keyring.\n * @param aad Optional associated data — defaults to empty if omitted.\n * Callers should pass the file path relative to memoryDir\n * so the ciphertext is bound to its location.\n */\nexport function encryptFileBody(plain: string | Buffer, key: Buffer, aad?: Buffer): Buffer {\n const plainBuf = typeof plain === \"string\" ? Buffer.from(plain, \"utf8\") : plain;\n const salt = generateSalt();\n const envelope = seal(key, salt, plainBuf, aad ? { aad } : {});\n\n const header = Buffer.alloc(MAGIC_HEADER_SIZE);\n MAGIC_BYTES.copy(header, 0);\n header.writeUInt8(FILE_FORMAT_VERSION, MAGIC_BYTES.length);\n header.writeUInt8(FILE_FORMAT_FLAGS, MAGIC_BYTES.length + 1);\n\n return Buffer.concat([header, envelope]);\n}\n\n/**\n * Decrypt a buffer produced by `encryptFileBody` and return the\n * original UTF-8 content.\n *\n * Throws `SecureStoreDecryptError` on auth failure (wrong key or\n * tampered ciphertext). Throws a plain `Error` for structural problems\n * (truncated buffer, wrong magic, unsupported version).\n */\nexport function decryptFileBody(buf: Buffer, key: Buffer, aad?: Buffer): Buffer {\n if (!isEncryptedFile(buf)) {\n throw new Error(\"decryptFileBody: buffer does not start with REMNIC-ENC magic header\");\n }\n const version = buf.readUInt8(MAGIC_BYTES.length);\n if (version !== FILE_FORMAT_VERSION) {\n throw new Error(\n `decryptFileBody: unsupported file format version ${version} (this build supports ${FILE_FORMAT_VERSION})`\n );\n }\n const flags = buf.readUInt8(MAGIC_BYTES.length + 1);\n if (flags !== FILE_FORMAT_FLAGS) {\n throw new Error(`decryptFileBody: unknown flags byte 0x${flags.toString(16).padStart(2, \"0\")}`);\n }\n const envelope = buf.subarray(MAGIC_HEADER_SIZE);\n parseEnvelope(envelope);\n try {\n return openEnvelope(key, envelope, aad ? { aad } : {});\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new SecureStoreDecryptError(`secure-store decryption failed: ${msg}`);\n }\n}\n\nfunction buildHeaderAad(salt: Uint8Array): Buffer {\n const out = Buffer.alloc(1 + ENVELOPE_SALT_LENGTH);\n out.writeUInt8(ENVELOPE_VERSION, 0);\n Buffer.from(salt).copy(out, 1);\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// Path → AAD helper\n// ---------------------------------------------------------------------------\n\n/**\n * Build the AAD buffer for a file at `filePath` relative to\n * `memoryDir`. The AAD binds the ciphertext to its path so a\n * file cannot be silently relocated without re-encryption.\n *\n * When `memoryDir` is supplied and `filePath` is absolute, the\n * relative sub-path is used. Otherwise `filePath` is used verbatim.\n */\nexport function filePathAad(filePath: string, memoryDir?: string): Buffer {\n let rel = filePath;\n if (memoryDir && path.isAbsolute(filePath)) {\n rel = path.relative(memoryDir, filePath);\n }\n return Buffer.from(rel, \"utf8\");\n}\n\n// ---------------------------------------------------------------------------\n// High-level read / write helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Read a file from `filePath`.\n *\n * - If the file is plaintext (no magic header), return its content\n * as-is — back-compat with unencrypted stores.\n * - If the file is encrypted AND `key` is provided, decrypt and return\n * the plaintext content.\n * - If the file is encrypted AND `key` is null, throw\n * `SecureStoreLockedError`.\n *\n * @param filePath Absolute path to the file.\n * @param key 32-byte AES-256 key, or null when the store is locked.\n * @param memoryDir Memory root for path-bound AAD. Should be absolute.\n */\nexport async function readMaybeEncryptedFileBuffer(\n filePath: string,\n key: Buffer | null,\n memoryDir?: string\n): Promise<Buffer> {\n const buf = await readFile(filePath);\n if (!isEncryptedFile(buf)) {\n // Plain file — legacy or unencrypted store.\n return buf;\n }\n // Encrypted — key required.\n if (key === null) {\n throw new SecureStoreLockedError(\n `secure-store is locked — cannot read encrypted file at ${filePath}. Run \\`remnic secure-store unlock\\` to decrypt.`\n );\n }\n return decryptFileBodyForPath(buf, key, filePath, memoryDir);\n}\n\nexport async function readMaybeEncryptedFile(\n filePath: string,\n key: Buffer | null,\n memoryDir?: string\n): Promise<string> {\n return (await readMaybeEncryptedFileBuffer(filePath, key, memoryDir)).toString(\"utf8\");\n}\n\nexport interface WriteMaybeEncryptedFileOptions {\n /**\n * File mode bits. Default 0o600 (owner read/write only).\n * Applied only on create; existing files inherit their existing mode.\n */\n mode?: number;\n /**\n * If true, write atomically via a temp file + rename (CLAUDE.md gotcha #54).\n * Default true.\n */\n atomic?: boolean;\n}\n\n/**\n * Write `content` to `filePath`.\n *\n * - If `key` is provided and non-null, encrypt the content first.\n * - If `key` is null, write the content as plain UTF-8 (unencrypted store).\n *\n * Writes atomically: content is written to a unique temp file\n * first, then renamed into place (CLAUDE.md gotcha #54 — never delete\n * before write).\n */\nexport async function writeMaybeEncryptedFile(\n filePath: string,\n content: string | Buffer,\n key: Buffer | null,\n options: WriteMaybeEncryptedFileOptions = {},\n memoryDir?: string\n): Promise<void> {\n const { mode = 0o600, atomic = true } = options;\n await mkdir(path.dirname(filePath), { recursive: true });\n\n let data: Buffer | string;\n if (key !== null) {\n const aad = filePathAad(filePath, memoryDir);\n data = encryptFileBody(content, key, aad);\n } else {\n data = content;\n }\n\n if (atomic) {\n const tempPath = uniqueAtomicTempPath(filePath, \"tmp\");\n try {\n await writeFile(tempPath, data, { mode });\n await rename(tempPath, filePath);\n } catch (err) {\n // Best-effort cleanup of the temp file.\n try {\n await unlink(tempPath);\n } catch {\n // ignore\n }\n throw err;\n }\n } else {\n await writeFile(filePath, data, { mode });\n }\n}\n\nexport async function writeMaybeEncryptedFileFromChunks(\n filePath: string,\n chunks: AsyncIterable<Buffer>,\n key: Buffer | null,\n options: WriteMaybeEncryptedFileOptions = {},\n memoryDir?: string\n): Promise<void> {\n const { mode = 0o600, atomic = true } = options;\n await mkdir(path.dirname(filePath), { recursive: true });\n const writePath = atomic ? `${filePath}.tmp-${process.pid}-${Date.now()}` : filePath;\n let completed = false;\n try {\n const handle = await openFile(writePath, \"w\", mode);\n try {\n if (key !== null) {\n const salt = generateSalt();\n const iv = randomBytes(IV_LENGTH);\n const header = Buffer.alloc(MAGIC_HEADER_SIZE + ENVELOPE_HEADER_SIZE);\n MAGIC_BYTES.copy(header, 0);\n header.writeUInt8(FILE_FORMAT_VERSION, MAGIC_BYTES.length);\n header.writeUInt8(FILE_FORMAT_FLAGS, MAGIC_BYTES.length + 1);\n const envelopeOffset = MAGIC_HEADER_SIZE;\n header.writeUInt8(ENVELOPE_VERSION, envelopeOffset + ENVELOPE_LAYOUT.version);\n salt.copy(header, envelopeOffset + ENVELOPE_LAYOUT.salt);\n iv.copy(header, envelopeOffset + ENVELOPE_LAYOUT.iv);\n await handle.write(header);\n\n const cipher = createCipheriv(\"aes-256-gcm\", key, iv, { authTagLength: AUTH_TAG_LENGTH });\n const aad = filePathAad(filePath, memoryDir);\n cipher.setAAD(Buffer.concat([buildHeaderAad(salt), aad]));\n for await (const chunk of chunks) {\n if (chunk.length === 0) continue;\n const encrypted = cipher.update(chunk);\n if (encrypted.length > 0) await handle.write(encrypted);\n }\n const final = cipher.final();\n if (final.length > 0) await handle.write(final);\n const authTag = cipher.getAuthTag();\n await handle.write(authTag, 0, authTag.length, MAGIC_HEADER_SIZE + ENVELOPE_LAYOUT.authTag);\n } else {\n for await (const chunk of chunks) {\n if (chunk.length > 0) await handle.write(chunk);\n }\n }\n } finally {\n await handle.close();\n }\n if (atomic) {\n await rename(writePath, filePath);\n }\n completed = true;\n } finally {\n if (!completed && atomic) {\n await unlink(writePath).catch(() => {});\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Migration\n// ---------------------------------------------------------------------------\n\nexport interface MigrateResult {\n /** Number of files successfully encrypted. */\n encrypted: number;\n /** Number of files already encrypted (skipped). */\n skipped: number;\n /** Files that failed to encrypt (path → error message). */\n errors: Array<{ filePath: string; error: string }>;\n}\n\nexport interface DecryptResult {\n /** Number of files successfully decrypted back to plaintext. */\n decrypted: number;\n /** Number of files already plaintext (skipped). */\n skipped: number;\n /** Files that failed to decrypt (path → error message). */\n errors: Array<{ filePath: string; error: string }>;\n}\n\n/**\n * Walk `dir` recursively, find encryptable storage-managed files that are not\n * yet encrypted, and re-write them as encrypted files under `key`.\n *\n * Safety rules per CLAUDE.md gotchas #54 and #25:\n * 1. A page-version snapshot is taken (via `createVersion`) BEFORE\n * each overwrite so the plaintext version is preserved in history.\n * Since this module has no direct access to `page-versioning.ts`\n * internals, callers who have page-versioning configured should\n * pass `onBeforeEncrypt` to take the snapshot.\n * 2. The new encrypted content is written to a temp file first,\n * then renamed atomically — never deleted before written.\n * 3. If encryption of any file fails, the error is recorded and the\n * original file is left intact (partial migration is safe).\n *\n * @param dir Absolute path to the memory directory.\n * @param key 32-byte AES-256 key.\n * @param onBeforeEncrypt Optional callback invoked before encrypting\n * each file. Can be used to take page-version\n * snapshots. Errors here are non-fatal.\n */\nexport async function migrateMemoryDirToEncrypted(\n dir: string,\n key: Buffer,\n onBeforeEncrypt?: (filePath: string) => Promise<void>\n): Promise<MigrateResult> {\n const result: MigrateResult = { encrypted: 0, skipped: 0, errors: [] };\n\n const files = await collectEncryptableStorageFiles(dir);\n for (const filePath of files) {\n try {\n const buf = await readFile(filePath);\n if (isEncryptedFile(buf)) {\n result.skipped++;\n continue;\n }\n // Call optional pre-encryption hook (e.g. page-version snapshot).\n if (onBeforeEncrypt) {\n try {\n await onBeforeEncrypt(filePath);\n } catch {\n // Non-fatal — continue with encryption even if snapshot fails.\n }\n }\n const content = buf.toString(\"utf8\");\n const aad = filePathAad(filePath, dir);\n const encrypted = encryptFileBody(content, key, aad);\n\n // Atomic write: temp → rename (gotcha #54).\n const tempPath = uniqueAtomicTempPath(filePath, \"enc-tmp\");\n try {\n await writeFile(tempPath, encrypted, { mode: 0o600 });\n await rename(tempPath, filePath);\n result.encrypted++;\n } catch (writeErr) {\n // Clean up temp file, leave original intact.\n try {\n const { unlink } = await import(\"node:fs/promises\");\n await unlink(tempPath);\n } catch {\n // ignore\n }\n throw writeErr;\n }\n } catch (err) {\n result.errors.push({\n filePath,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n return result;\n}\n\n/**\n * Walk `dir` recursively, find storage-managed encrypted files, and\n * re-write them as plaintext under the same paths.\n *\n * This is the reversible counterpart to {@link migrateMemoryDirToEncrypted}.\n * It only touches files under the same storage-managed roots, skips\n * plaintext files, skips symlinks, excludes `.secure-store/`, and writes\n * each plaintext replacement via temp-file + rename so a per-file failure\n * leaves the ciphertext intact.\n */\nexport async function decryptMemoryDirToPlaintext(dir: string, key: Buffer): Promise<DecryptResult> {\n const result: DecryptResult = { decrypted: 0, skipped: 0, errors: [] };\n\n const files = await collectStorageManagedFiles(dir, isDecryptableStoragePath);\n for (const filePath of files) {\n try {\n const buf = await readFile(filePath);\n if (!isEncryptedFile(buf)) {\n result.skipped++;\n continue;\n }\n\n const plaintext = decryptFileBodyForPath(buf, key, filePath, dir);\n const tempPath = uniqueAtomicTempPath(filePath, \"dec-tmp\");\n try {\n await writeFile(tempPath, plaintext, { mode: 0o600 });\n await rename(tempPath, filePath);\n result.decrypted++;\n } catch (writeErr) {\n try {\n await unlink(tempPath);\n } catch {\n // ignore cleanup errors; original ciphertext is still intact.\n }\n throw writeErr;\n }\n } catch (err) {\n result.errors.push({\n filePath,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction uniqueAtomicTempPath(filePath: string, label: string): string {\n return `${filePath}.${label}-${process.pid}-${Date.now()}-${randomUUID()}`;\n}\n\nfunction decryptFileBodyForPath(buf: Buffer, key: Buffer, filePath: string, memoryDir?: string): Buffer {\n const aad = filePathAad(filePath, memoryDir);\n try {\n return decryptFileBody(buf, key, aad);\n } catch (err) {\n if (!(err instanceof SecureStoreDecryptError)) {\n throw err;\n }\n const legacyRoot = legacyNamespaceAadRootForFile(filePath, memoryDir);\n if (legacyRoot) {\n try {\n return decryptFileBody(buf, key, filePathAad(filePath, legacyRoot));\n } catch {\n // Fall through to the namespace-reader fallback below.\n }\n }\n\n const topLevelRoot = topLevelAadRootForNamespaceReader(filePath, memoryDir);\n if (topLevelRoot) {\n try {\n return decryptFileBody(buf, key, filePathAad(filePath, topLevelRoot));\n } catch {\n // Preserve the caller-facing error from the canonical decrypt attempt.\n }\n }\n\n throw err;\n }\n}\n\nfunction topLevelAadRootForNamespaceReader(filePath: string, memoryDir?: string): string | null {\n if (!memoryDir || !path.isAbsolute(filePath)) return null;\n const resolvedMemoryDir = path.resolve(memoryDir);\n const rel = path.relative(resolvedMemoryDir, filePath);\n if (rel === \"\" || rel.startsWith(\"..\") || path.isAbsolute(rel)) return null;\n const parts = resolvedMemoryDir.split(path.sep);\n if (parts.length < 3 || parts.at(-2) !== \"namespaces\" || !parts.at(-1)) return null;\n const topLevelRoot = parts.slice(0, -2).join(path.sep) || path.sep;\n const topRel = path.relative(topLevelRoot, filePath);\n if (topRel === \"\" || topRel.startsWith(\"..\") || path.isAbsolute(topRel)) {\n return null;\n }\n const topParts = topRel.split(path.sep);\n if (topParts[0] !== \"namespaces\" || topParts[1] !== parts.at(-1)) {\n return null;\n }\n return topLevelRoot;\n}\n\nfunction legacyNamespaceAadRootForFile(filePath: string, memoryDir?: string): string | null {\n if (!memoryDir || !path.isAbsolute(filePath)) return null;\n const rel = path.relative(memoryDir, filePath);\n if (rel === \"\" || rel.startsWith(\"..\") || path.isAbsolute(rel)) return null;\n const parts = rel.split(path.sep);\n if (parts[0] === \"namespaces\" && parts.length >= 3 && parts[1]) {\n return path.join(memoryDir, \"namespaces\", parts[1]);\n }\n return null;\n}\n\n/**\n * Recursively collect files under `dir` that are read through the\n * storage-layer secure-store helpers, excluding symlinked entries and\n * `.secure-store/` metadata.\n */\nasync function collectEncryptableStorageFiles(dir: string, rootDir = dir): Promise<string[]> {\n return collectStorageManagedFiles(dir, isEncryptableStoragePath, rootDir);\n}\n\n/**\n * Recursively collect regular files under storage-managed roots, excluding\n * symlinked entries and `.secure-store/` metadata. This broader collector is\n * used by the decrypt/disable path so future encrypted sidecars can be\n * restored without requiring extension-specific logic.\n */\nasync function collectStorageManagedFiles(\n dir: string,\n includeFile: (filePath: string, rootDir: string) => boolean,\n rootDir = dir\n): Promise<string[]> {\n const results: string[] = [];\n let scanDir = dir;\n let scanRootDir = rootDir;\n if (path.resolve(dir) === path.resolve(rootDir)) {\n const normalizedRoot = await resolveStorageManagedRootForScan(dir);\n if (!normalizedRoot) return results;\n scanDir = normalizedRoot;\n scanRootDir = normalizedRoot;\n }\n let names: string[];\n try {\n names = await readdir(scanDir, { encoding: \"utf8\" });\n } catch {\n return results;\n }\n for (const name of names) {\n if (name.startsWith(\".secure-store\")) continue;\n const full = path.join(scanDir, name);\n let isDir = false;\n let isFile = false;\n try {\n const s = await lstat(full);\n if (s.isSymbolicLink()) continue;\n isDir = s.isDirectory();\n isFile = s.isFile();\n } catch {\n continue;\n }\n if (isDir) {\n const sub = await collectStorageManagedFiles(full, includeFile, scanRootDir);\n results.push(...sub);\n } else if (isFile && includeFile(full, scanRootDir)) {\n results.push(full);\n }\n }\n return results;\n}\n\nasync function resolveStorageManagedRootForScan(dir: string): Promise<string | null> {\n const lstatPath = normalizePathForLstat(dir);\n let stat: Awaited<ReturnType<typeof lstat>>;\n try {\n stat = await lstat(lstatPath);\n } catch (error) {\n if (isFsErrorWithCode(error, \"ENOENT\")) return null;\n throw error;\n }\n if (stat.isSymbolicLink()) {\n throw new Error(`secure-store migration root must not be a symlink: ${dir}`);\n }\n if (!stat.isDirectory()) {\n throw new Error(`secure-store migration root must be a directory: ${dir}`);\n }\n return lstatPath;\n}\n\nfunction normalizePathForLstat(filePath: string): string {\n return stripTrailingPathSeparators(path.normalize(filePath));\n}\n\nfunction isFsErrorWithCode(error: unknown, code: string): boolean {\n return typeof error === \"object\" && error !== null && (error as { code?: unknown }).code === code;\n}\n\nfunction stripTrailingPathSeparators(filePath: string): string {\n const root = path.parse(filePath).root;\n let end = filePath.length;\n while (\n end > root.length &&\n (filePath[end - 1] === path.sep || filePath[end - 1] === path.posix.sep || filePath[end - 1] === path.win32.sep)\n ) {\n end -= 1;\n }\n return end === filePath.length ? filePath : filePath.slice(0, end);\n}\n\nfunction isEncryptableStoragePath(filePath: string, rootDir: string): boolean {\n const rel = path.relative(rootDir, filePath);\n if (rel === \"\" || rel.startsWith(\"..\") || path.isAbsolute(rel)) return false;\n const normalized = normalizeStorageRelativePath(rel);\n if (normalized === \"profile.md\") return true;\n if (isEncryptableStateSidecar(normalized)) return true;\n if (isEncryptableSummarySidecar(normalized)) return true;\n const firstSegment = normalized.split(\"/\", 1)[0];\n return ENCRYPTABLE_MARKDOWN_STORAGE_ROOTS.has(firstSegment) && normalized.endsWith(\".md\");\n}\n\nfunction isDecryptableStoragePath(filePath: string, rootDir: string): boolean {\n if (isEncryptableStoragePath(filePath, rootDir)) return true;\n const rel = path.relative(rootDir, filePath);\n if (rel === \"\" || rel.startsWith(\"..\") || path.isAbsolute(rel)) return false;\n const normalized = normalizeStorageRelativePath(rel);\n const firstSegment = normalized.split(\"/\", 1)[0];\n return DECRYPTABLE_SIDECAR_ROOTS.has(firstSegment);\n}\n\nfunction normalizeStorageRelativePath(rel: string): string {\n const normalized = rel.split(path.sep).join(\"/\");\n const parts = normalized.split(\"/\");\n if (parts[0] === \"namespaces\" && parts.length >= 3) {\n return parts.slice(2).join(\"/\");\n }\n return normalized;\n}\n\n// Every recall MEMORY category directory (facts/ + the CATEGORY_DIR_MAP memory\n// dirs) must be encryptable at rest — #1546 routes decision/preference/moment/...\n// memories into their own dirs, so hardcoding only facts/corrections/procedures/\n// reasoning-traces would silently write those categories in plaintext on\n// encrypted stores. RECALL_FALLBACK_DIRS is the single source of truth for that\n// set; the extra non-category markdown roots (artifacts/archive/entities/\n// identity) are appended.\n//\n// questions/ is deliberately EXCLUDED (RECALL_FALLBACK_DIRS omits the non-memory\n// queue dirs): the question queue is written/resolved through plain readFile/\n// writeFile (StorageManager.writeQuestion/resolveQuestion), NOT the secure-file\n// helpers. Encrypting questions/ here would make migration seal those files,\n// after which resolveQuestion() would read ciphertext as UTF-8, fail to update\n// the frontmatter, and overwrite/corrupt the file while returning success\n// (codex #1563 review). Keeping questions/ plaintext preserves the queue's\n// existing behavior; #1546 does not change question encryption.\nconst ENCRYPTABLE_MARKDOWN_STORAGE_ROOTS = new Set<string>([\n ...RECALL_FALLBACK_DIRS,\n \"artifacts\",\n \"archive\",\n \"entities\",\n \"identity\",\n]);\n\nconst ENCRYPTABLE_STATE_SIDECARS = new Set([\n \"state/behavior-signals.jsonl\",\n \"state/buffer-surprise-ledger.jsonl\",\n \"state/buffer.json\",\n \"state/compression-guideline-draft-state.json\",\n \"state/compression-guideline-state.json\",\n \"state/compression-guidelines.draft.md\",\n \"state/compression-guidelines.md\",\n \"state/entity-synthesis-queue.json\",\n \"state/fact-hashes.txt\",\n \"state/memory-actions.jsonl\",\n \"state/memory-lifecycle-ledger.jsonl\",\n \"state/meta.json\",\n \"state/reextract-jobs.jsonl\",\n \"state/topics.json\",\n]);\n\nfunction isEncryptableStateSidecar(normalized: string): boolean {\n return ENCRYPTABLE_STATE_SIDECARS.has(normalized);\n}\n\nfunction isEncryptableSummarySidecar(normalized: string): boolean {\n return normalized.startsWith(\"summaries/\") && normalized.endsWith(\".json\");\n}\n\nconst DECRYPTABLE_SIDECAR_ROOTS = new Set([\"state\", \"indexes\", \"index\", \"provenance\"]);\n"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,SAAS,gBAAgB,aAAa,kBAAkB;AACxD,SAAS,OAAO,OAAO,QAAQ,UAAU,UAAU,SAAS,QAAQ,QAAQ,iBAAiB;AAC7F,OAAO,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AAM,eAAe,WAAW,MAAM,KAAK,CAAC,EAAE,CAAC;AAC/C,SAAO,0BAA0B,IAAI,YAAY;AACnD;AAEA,SAAS,6BAA6B,KAAqB;AACzD,QAAM,aAAa,IAAI,MAAM,KAAK,GAAG,EAAE,KAAK,GAAG;AAC/C,QAAM,QAAQ,WAAW,MAAM,GAAG;AAClC,MAAI,MAAM,CAAC,MAAM,gBAAgB,MAAM,UAAU,GAAG;AAClD,WAAO,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG;AAAA,EAChC;AACA,SAAO;AACT;AAkBA,IAAM,qCAAqC,oBAAI,IAAY;AAAA,EACzD,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,6BAA6B,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,0BAA0B,YAA6B;AAC9D,SAAO,2BAA2B,IAAI,UAAU;AAClD;AAEA,SAAS,4BAA4B,YAA6B;AAChE,SAAO,WAAW,WAAW,YAAY,KAAK,WAAW,SAAS,OAAO;AAC3E;AAEA,IAAM,4BAA4B,oBAAI,IAAI,CAAC,SAAS,WAAW,SAAS,YAAY,CAAC;","names":["unlink"]}
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-GDB4J2H3.js";
9
9
  import {
10
10
  importCapsule
11
- } from "./chunk-DHGSZ3UD.js";
11
+ } from "./chunk-ARV3AUOM.js";
12
12
  import {
13
13
  decideDisclosureEscalation
14
14
  } from "./chunk-H7XKCNR6.js";
@@ -27,7 +27,7 @@ import {
27
27
  listMemoryGovernanceRuns,
28
28
  readMemoryGovernanceRunArtifact,
29
29
  runMemoryGovernance
30
- } from "./chunk-A7EF2XRO.js";
30
+ } from "./chunk-EXXBA5OM.js";
31
31
  import {
32
32
  clusterByKey,
33
33
  combineNamespaces,
@@ -55,7 +55,7 @@ import {
55
55
  } from "./chunk-2MXEVL75.js";
56
56
  import {
57
57
  namespaceCollectionName
58
- } from "./chunk-WOQIHC67.js";
58
+ } from "./chunk-DQY7NJ5L.js";
59
59
  import {
60
60
  namespaceIdentityFromToken
61
61
  } from "./chunk-ZFXCQPNO.js";
@@ -94,10 +94,10 @@ import {
94
94
  buildBriefing,
95
95
  parseBriefingFocus,
96
96
  parseBriefingWindow
97
- } from "./chunk-GY3V3SUI.js";
97
+ } from "./chunk-KHGE6PMF.js";
98
98
  import {
99
99
  parseEntityFile
100
- } from "./chunk-AX5O25EF.js";
100
+ } from "./chunk-VH6EIKVS.js";
101
101
  import {
102
102
  DEFAULT_RECALL_DISCLOSURE,
103
103
  isRecallDisclosure
@@ -152,10 +152,10 @@ import {
152
152
  buildOfflineSyncSnapshotFromBase,
153
153
  iterateOfflineSyncSnapshotFileRecords,
154
154
  readOfflineSyncFileContentChunk
155
- } from "./chunk-ZLDUQWT2.js";
155
+ } from "./chunk-PWWWLD7D.js";
156
156
  import {
157
157
  SecureStoreLockedError
158
- } from "./chunk-ILXTATKK.js";
158
+ } from "./chunk-J2HSAU72.js";
159
159
  import {
160
160
  evaluateActionConfidence
161
161
  } from "./chunk-AH2JUU6X.js";
@@ -5579,4 +5579,4 @@ export {
5579
5579
  shapeMemorySummary,
5580
5580
  EngramAccessService
5581
5581
  };
5582
- //# sourceMappingURL=chunk-DFAXGZKI.js.map
5582
+ //# sourceMappingURL=chunk-JIX3ZL2J.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  StorageManager,
3
3
  normalizeEntityName
4
- } from "./chunk-AX5O25EF.js";
4
+ } from "./chunk-VH6EIKVS.js";
5
5
  import {
6
6
  extractJsonCandidates
7
7
  } from "./chunk-RGMVMVMF.js";
@@ -870,4 +870,4 @@ export {
870
870
  resolveBriefingSaveDir,
871
871
  briefingFilename
872
872
  };
873
- //# sourceMappingURL=chunk-GY3V3SUI.js.map
873
+ //# sourceMappingURL=chunk-KHGE6PMF.js.map