@remnic/core 1.1.2 → 1.1.4

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 (489) hide show
  1. package/dist/abort-error.js +1 -0
  2. package/dist/abstraction-nodes.js +1 -0
  3. package/dist/access-audit.js +1 -0
  4. package/dist/access-cli.js +72 -47
  5. package/dist/access-cli.js.map +1 -1
  6. package/dist/access-http.d.ts +50 -5
  7. package/dist/access-http.js +39 -16
  8. package/dist/access-idempotency.js +1 -0
  9. package/dist/access-mcp.d.ts +10 -5
  10. package/dist/access-mcp.js +38 -14
  11. package/dist/access-schema.d.ts +133 -13
  12. package/dist/access-schema.js +20 -1
  13. package/dist/access-service-CtXFnprR.d.ts +2033 -0
  14. package/dist/access-service.d.ts +11 -6
  15. package/dist/access-service.js +40 -15
  16. package/dist/active-memory-bridge.js +1 -0
  17. package/dist/active-recall.js +1 -0
  18. package/dist/active-recall.js.map +1 -1
  19. package/dist/behavior-learner.js +1 -0
  20. package/dist/behavior-learner.js.map +1 -1
  21. package/dist/behavior-signals.js +1 -0
  22. package/dist/bootstrap.d.ts +6 -4
  23. package/dist/bootstrap.js +1 -0
  24. package/dist/boxes.js +1 -0
  25. package/dist/briefing.d.ts +9 -5
  26. package/dist/briefing.js +10 -7
  27. package/dist/buffer-surprise-report.js +1 -0
  28. package/dist/buffer-surprise.js +1 -0
  29. package/dist/buffer.d.ts +1 -1
  30. package/dist/buffer.js +1 -0
  31. package/dist/calibration.d.ts +8 -1
  32. package/dist/calibration.js +10 -2
  33. package/dist/calibration.js.map +1 -1
  34. package/dist/capsule-cli.d.ts +137 -0
  35. package/dist/capsule-cli.js +34 -0
  36. package/dist/capsule-crypto-5CYAGVC5.js +18 -0
  37. package/dist/capsule-export-NZQPOTQ4.js +17 -0
  38. package/dist/capsule-export-NZQPOTQ4.js.map +1 -0
  39. package/dist/capsule-import-SDCUXLEV.js +16 -0
  40. package/dist/capsule-import-SDCUXLEV.js.map +1 -0
  41. package/dist/capsule-merge-DI7PNQ2H.js +189 -0
  42. package/dist/capsule-merge-DI7PNQ2H.js.map +1 -0
  43. package/dist/causal-behavior.js +1 -0
  44. package/dist/causal-behavior.js.map +1 -1
  45. package/dist/causal-chain.js +1 -0
  46. package/dist/causal-consolidation.js +12 -9
  47. package/dist/causal-consolidation.js.map +1 -1
  48. package/dist/causal-retrieval.js +2 -1
  49. package/dist/causal-retrieval.js.map +1 -1
  50. package/dist/causal-trajectory-graph.js +4 -1
  51. package/dist/causal-trajectory-graph.js.map +1 -1
  52. package/dist/causal-trajectory.js +2 -1
  53. package/dist/chunk-2LSZVONP.js +67 -0
  54. package/dist/chunk-2LSZVONP.js.map +1 -0
  55. package/dist/chunk-32KD5IHZ.js +245 -0
  56. package/dist/chunk-32KD5IHZ.js.map +1 -0
  57. package/dist/chunk-3KIS4VGT.js +228 -0
  58. package/dist/chunk-3KIS4VGT.js.map +1 -0
  59. package/dist/chunk-3LCWFNVS.js +350 -0
  60. package/dist/chunk-3LCWFNVS.js.map +1 -0
  61. package/dist/chunk-43EKP2UK.js +26 -0
  62. package/dist/chunk-43EKP2UK.js.map +1 -0
  63. package/dist/chunk-457A4P3L.js +119 -0
  64. package/dist/chunk-457A4P3L.js.map +1 -0
  65. package/dist/{chunk-TMYO7B5P.js → chunk-47WOM4YW.js} +2 -2
  66. package/dist/{chunk-FVA6TGI3.js → chunk-52PDY6GD.js} +42 -2
  67. package/dist/chunk-52PDY6GD.js.map +1 -0
  68. package/dist/{chunk-ULYOGL6R.js → chunk-5HRY2WRF.js} +7 -3
  69. package/dist/chunk-5HRY2WRF.js.map +1 -0
  70. package/dist/{chunk-BOUYNNYD.js → chunk-67YLUWLG.js} +32 -13
  71. package/dist/{chunk-BOUYNNYD.js.map → chunk-67YLUWLG.js.map} +1 -1
  72. package/dist/chunk-6TBWYBJ3.js +236 -0
  73. package/dist/chunk-6TBWYBJ3.js.map +1 -0
  74. package/dist/chunk-74EMIVE4.js +329 -0
  75. package/dist/chunk-74EMIVE4.js.map +1 -0
  76. package/dist/chunk-74WWN7ZW.js +82 -0
  77. package/dist/chunk-74WWN7ZW.js.map +1 -0
  78. package/dist/chunk-A6XUJE5D.js +126 -0
  79. package/dist/chunk-A6XUJE5D.js.map +1 -0
  80. package/dist/{chunk-STGWEHYR.js → chunk-AEMBDV7M.js} +1187 -62
  81. package/dist/chunk-AEMBDV7M.js.map +1 -0
  82. package/dist/{chunk-PVICZTKG.js → chunk-AGZHRWPT.js} +5 -5
  83. package/dist/{chunk-PVICZTKG.js.map → chunk-AGZHRWPT.js.map} +1 -1
  84. package/dist/chunk-AJA46VX5.js +393 -0
  85. package/dist/chunk-AJA46VX5.js.map +1 -0
  86. package/dist/chunk-ASIQZXYO.js +277 -0
  87. package/dist/chunk-ASIQZXYO.js.map +1 -0
  88. package/dist/{chunk-DG6YMRDC.js → chunk-B2TL6GA2.js} +2 -2
  89. package/dist/chunk-BJMBJZ2Y.js +290 -0
  90. package/dist/chunk-BJMBJZ2Y.js.map +1 -0
  91. package/dist/chunk-BT7NVCML.js +79 -0
  92. package/dist/chunk-BT7NVCML.js.map +1 -0
  93. package/dist/chunk-CK5NTM2S.js +454 -0
  94. package/dist/chunk-CK5NTM2S.js.map +1 -0
  95. package/dist/{chunk-AYXIPSZO.js → chunk-CRU27Q4J.js} +2 -2
  96. package/dist/{chunk-UWB5LMWY.js → chunk-CUI2STX6.js} +526 -24
  97. package/dist/chunk-CUI2STX6.js.map +1 -0
  98. package/dist/{chunk-CUPFXL3J.js → chunk-EGEPUGN4.js} +4 -4
  99. package/dist/chunk-EGEPUGN4.js.map +1 -0
  100. package/dist/{chunk-3OGMS3PE.js → chunk-F5VQOQ2E.js} +3 -2
  101. package/dist/chunk-F5VQOQ2E.js.map +1 -0
  102. package/dist/chunk-FP2373TW.js +149 -0
  103. package/dist/chunk-FP2373TW.js.map +1 -0
  104. package/dist/{chunk-RBBWYEFJ.js → chunk-G2WADRQ3.js} +1 -1
  105. package/dist/chunk-G7D6GZ5J.js +48 -0
  106. package/dist/chunk-G7D6GZ5J.js.map +1 -0
  107. package/dist/chunk-H7XKCNR6.js +60 -0
  108. package/dist/chunk-H7XKCNR6.js.map +1 -0
  109. package/dist/{chunk-LOIMBRDE.js → chunk-HIRKCQGF.js} +1994 -412
  110. package/dist/chunk-HIRKCQGF.js.map +1 -0
  111. package/dist/chunk-IXEJRKCZ.js +18 -0
  112. package/dist/chunk-IXEJRKCZ.js.map +1 -0
  113. package/dist/chunk-IYY4MCPG.js +275 -0
  114. package/dist/chunk-IYY4MCPG.js.map +1 -0
  115. package/dist/{chunk-BECYBZLX.js → chunk-JWSENLQI.js} +502 -22
  116. package/dist/chunk-JWSENLQI.js.map +1 -0
  117. package/dist/chunk-KNKUID7G.js +183 -0
  118. package/dist/chunk-KNKUID7G.js.map +1 -0
  119. package/dist/chunk-L2IO2QPY.js +2036 -0
  120. package/dist/chunk-L2IO2QPY.js.map +1 -0
  121. package/dist/{chunk-ZAIM4TUE.js → chunk-LW2NMHDW.js} +46 -1
  122. package/dist/chunk-LW2NMHDW.js.map +1 -0
  123. package/dist/chunk-MDYG7VI7.js +48 -0
  124. package/dist/chunk-MDYG7VI7.js.map +1 -0
  125. package/dist/{chunk-VDX363PS.js → chunk-MUELDH4F.js} +10 -3
  126. package/dist/chunk-MUELDH4F.js.map +1 -0
  127. package/dist/chunk-MXC3AP5I.js +74 -0
  128. package/dist/chunk-MXC3AP5I.js.map +1 -0
  129. package/dist/chunk-NN3TS5BM.js +147 -0
  130. package/dist/chunk-NN3TS5BM.js.map +1 -0
  131. package/dist/{chunk-3YGHKTBF.js → chunk-NZS2BLTP.js} +963 -326
  132. package/dist/chunk-NZS2BLTP.js.map +1 -0
  133. package/dist/chunk-OA3L7BFR.js +183 -0
  134. package/dist/chunk-OA3L7BFR.js.map +1 -0
  135. package/dist/chunk-OZHRDTDX.js +240 -0
  136. package/dist/chunk-OZHRDTDX.js.map +1 -0
  137. package/dist/chunk-PCUKNJAZ.js +165 -0
  138. package/dist/chunk-PCUKNJAZ.js.map +1 -0
  139. package/dist/{chunk-6PFRXT4K.js → chunk-PFV5C235.js} +11 -6
  140. package/dist/chunk-PFV5C235.js.map +1 -0
  141. package/dist/chunk-PZ5AY32C.js +10 -0
  142. package/dist/chunk-PZ5AY32C.js.map +1 -0
  143. package/dist/{chunk-Y7R2XJ5Q.js → chunk-Q7FJ5ZHM.js} +6 -2
  144. package/dist/chunk-Q7FJ5ZHM.js.map +1 -0
  145. package/dist/{chunk-WCLICCGB.js → chunk-RILIVK4O.js} +91 -4
  146. package/dist/chunk-RILIVK4O.js.map +1 -0
  147. package/dist/{chunk-C2EFFULQ.js → chunk-RK2Y4XOM.js} +163 -20
  148. package/dist/chunk-RK2Y4XOM.js.map +1 -0
  149. package/dist/{chunk-TP4FZJIZ.js → chunk-RULE4VG5.js} +5 -1
  150. package/dist/chunk-RULE4VG5.js.map +1 -0
  151. package/dist/{chunk-PVPWZSSI.js → chunk-SMA4IMHV.js} +19 -3
  152. package/dist/chunk-SMA4IMHV.js.map +1 -0
  153. package/dist/{chunk-6YJHX2DL.js → chunk-TIFRGAKO.js} +242 -22
  154. package/dist/chunk-TIFRGAKO.js.map +1 -0
  155. package/dist/chunk-TUFG6VXY.js +875 -0
  156. package/dist/chunk-TUFG6VXY.js.map +1 -0
  157. package/dist/chunk-TYEOAFH3.js +251 -0
  158. package/dist/chunk-TYEOAFH3.js.map +1 -0
  159. package/dist/chunk-UKJAGEXH.js +260 -0
  160. package/dist/chunk-UKJAGEXH.js.map +1 -0
  161. package/dist/{chunk-KVBLZUKV.js → chunk-USFPPRAF.js} +93 -3
  162. package/dist/chunk-USFPPRAF.js.map +1 -0
  163. package/dist/{chunk-NBVAS5MT.js → chunk-V7TEH5I2.js} +6 -6
  164. package/dist/{chunk-GA5P7RST.js → chunk-VTJVUHRK.js} +22 -36
  165. package/dist/chunk-VTJVUHRK.js.map +1 -0
  166. package/dist/{chunk-SPI27QT6.js → chunk-W7WWT4FJ.js} +9 -4
  167. package/dist/chunk-W7WWT4FJ.js.map +1 -0
  168. package/dist/chunk-WIICJPET.js +45 -0
  169. package/dist/chunk-WIICJPET.js.map +1 -0
  170. package/dist/{chunk-VBVG2M5G.js → chunk-WPGJYVUH.js} +6 -2
  171. package/dist/chunk-WPGJYVUH.js.map +1 -0
  172. package/dist/{chunk-4HQS2HPX.js → chunk-WSZIHQBK.js} +29 -9
  173. package/dist/{chunk-4HQS2HPX.js.map → chunk-WSZIHQBK.js.map} +1 -1
  174. package/dist/{chunk-NZLQTHS5.js → chunk-WW3QQF4H.js} +4 -1
  175. package/dist/chunk-WW3QQF4H.js.map +1 -0
  176. package/dist/{chunk-DIXB44VE.js → chunk-X6VBWOVZ.js} +28 -13
  177. package/dist/chunk-X6VBWOVZ.js.map +1 -0
  178. package/dist/{chunk-XXVWLXSG.js → chunk-XQ4EJLUD.js} +64 -92
  179. package/dist/chunk-XQ4EJLUD.js.map +1 -0
  180. package/dist/{chunk-OC5OXUQ4.js → chunk-XRCYKJ3V.js} +780 -17
  181. package/dist/chunk-XRCYKJ3V.js.map +1 -0
  182. package/dist/{chunk-F5VP6YCB.js → chunk-Y4A6M3B6.js} +573 -156
  183. package/dist/chunk-Y4A6M3B6.js.map +1 -0
  184. package/dist/chunk-YNJHCGDT.js +309 -0
  185. package/dist/chunk-YNJHCGDT.js.map +1 -0
  186. package/dist/{chunk-L7IXWRYE.js → chunk-ZIBOQULP.js} +22 -13
  187. package/dist/chunk-ZIBOQULP.js.map +1 -0
  188. package/dist/{chunk-W6SL7OFG.js → chunk-ZTSE2ZJ6.js} +12 -2
  189. package/dist/{chunk-W6SL7OFG.js.map → chunk-ZTSE2ZJ6.js.map} +1 -1
  190. package/dist/chunking.js +1 -0
  191. package/dist/cipher-GVE2GQ5H.js +28 -0
  192. package/dist/cipher-GVE2GQ5H.js.map +1 -0
  193. package/dist/citations.js +1 -0
  194. package/dist/{cli-BkeRaYfk.d.ts → cli-lMql2FCr.d.ts} +26 -7
  195. package/dist/cli.d.ts +11 -6
  196. package/dist/cli.js +69 -34
  197. package/dist/codex-thread-key.js +1 -0
  198. package/dist/commitment-ledger.js +1 -0
  199. package/dist/compression-optimizer.js +1 -0
  200. package/dist/config.d.ts +2 -1
  201. package/dist/config.js +4 -1
  202. package/dist/connectors-cli-DFGtY2DB.d.ts +257 -0
  203. package/dist/connectors-cli.d.ts +2 -0
  204. package/dist/connectors-cli.js +22 -0
  205. package/dist/connectors-cli.js.map +1 -0
  206. package/dist/consolidation-operator.d.ts +65 -5
  207. package/dist/consolidation-operator.js +6 -1
  208. package/dist/consolidation-provenance-check.d.ts +1 -1
  209. package/dist/consolidation-provenance-check.js +3 -2
  210. package/dist/consolidation-undo.d.ts +1 -1
  211. package/dist/consolidation-undo.js +1 -0
  212. package/dist/consolidation-undo.js.map +1 -1
  213. package/dist/{contradiction-review-WIUBAR52.js → contradiction-review-5LTTVDQV.js} +2 -1
  214. package/dist/contradiction-review-5LTTVDQV.js.map +1 -0
  215. package/dist/{contradiction-scan-E3GJTI4F.js → contradiction-scan-3Z6YW7YA.js} +2 -1
  216. package/dist/{contradiction-scan-E3GJTI4F.js.map → contradiction-scan-3Z6YW7YA.js.map} +1 -1
  217. package/dist/cross-namespace-budget.js +1 -0
  218. package/dist/cue-anchors.js +1 -0
  219. package/dist/dashboard-runtime.js +1 -0
  220. package/dist/day-summary.js +1 -0
  221. package/dist/delinearize.js +1 -0
  222. package/dist/direct-answer-wiring.js +1 -0
  223. package/dist/direct-answer.js +1 -0
  224. package/dist/dreams-ledger-LR2NBAZE.js +286 -0
  225. package/dist/dreams-ledger-LR2NBAZE.js.map +1 -0
  226. package/dist/embedding-fallback.js +1 -0
  227. package/dist/engine-O6YWKQM3.js +28 -0
  228. package/dist/engine-O6YWKQM3.js.map +1 -0
  229. package/dist/entity-retrieval.d.ts +1 -1
  230. package/dist/entity-retrieval.js +10 -7
  231. package/dist/entity-schema.js +1 -0
  232. package/dist/evals.js +1 -0
  233. package/dist/evidence-pack.d.ts +16 -0
  234. package/dist/evidence-pack.js +8 -0
  235. package/dist/evidence-pack.js.map +1 -0
  236. package/dist/explicit-capture.d.ts +6 -4
  237. package/dist/explicit-capture.js +1 -0
  238. package/dist/extraction-judge-telemetry.js +1 -0
  239. package/dist/extraction-judge-training.js +1 -0
  240. package/dist/extraction-judge.js +1 -0
  241. package/dist/extraction.js +8 -7
  242. package/dist/fallback-llm.js +3 -2
  243. package/dist/first-start-migration-4MHQEOSD.js +263 -0
  244. package/dist/first-start-migration-4MHQEOSD.js.map +1 -0
  245. package/dist/forget-PLR6J5DN.js +69 -0
  246. package/dist/forget-PLR6J5DN.js.map +1 -0
  247. package/dist/framework-CyHYDcri.d.ts +153 -0
  248. package/dist/fs-utils-IRVUFB6G.js +30 -0
  249. package/dist/fs-utils-IRVUFB6G.js.map +1 -0
  250. package/dist/graph-dashboard-diff.js +1 -0
  251. package/dist/graph-dashboard-key.js +1 -0
  252. package/dist/graph-dashboard-parser.js +1 -0
  253. package/dist/graph-edge-decay-PWB63GRE.js +207 -0
  254. package/dist/graph-edge-decay-PWB63GRE.js.map +1 -0
  255. package/dist/graph-edge-reinforcement.d.ts +81 -0
  256. package/dist/graph-edge-reinforcement.js +24 -0
  257. package/dist/graph-edge-reinforcement.js.map +1 -0
  258. package/dist/graph-events.d.ts +87 -0
  259. package/dist/graph-events.js +14 -0
  260. package/dist/graph-events.js.map +1 -0
  261. package/dist/graph-recall.js +1 -0
  262. package/dist/graph-retrieval.js +1 -0
  263. package/dist/graph-snapshot.d.ts +112 -0
  264. package/dist/graph-snapshot.js +19 -0
  265. package/dist/graph-snapshot.js.map +1 -0
  266. package/dist/graph.d.ts +105 -7
  267. package/dist/graph.js +20 -3
  268. package/dist/harmonic-retrieval.js +1 -0
  269. package/dist/himem.js +1 -0
  270. package/dist/hygiene.js +1 -0
  271. package/dist/identity-continuity.js +1 -0
  272. package/dist/importance.js +1 -0
  273. package/dist/index.d.ts +574 -13
  274. package/dist/index.js +337 -69
  275. package/dist/index.js.map +1 -1
  276. package/dist/intent.js +1 -0
  277. package/dist/json-extract.js +1 -0
  278. package/dist/json-store.js +1 -0
  279. package/dist/kdf-7S6RWKLZ.js +26 -0
  280. package/dist/kdf-7S6RWKLZ.js.map +1 -0
  281. package/dist/legacy-hook-compat.js +1 -0
  282. package/dist/legacy-hook-compat.js.map +1 -1
  283. package/dist/lifecycle.js +1 -0
  284. package/dist/live-connectors-runner.d.ts +48 -0
  285. package/dist/live-connectors-runner.js +17 -0
  286. package/dist/live-connectors-runner.js.map +1 -0
  287. package/dist/local-llm.js +1 -0
  288. package/dist/logger.js +1 -0
  289. package/dist/memory-action-policy.js +1 -0
  290. package/dist/memory-cache.d.ts +2 -1
  291. package/dist/memory-cache.js +4 -1
  292. package/dist/memory-governance-JZHZDOLN.js +37 -0
  293. package/dist/memory-governance-JZHZDOLN.js.map +1 -0
  294. package/dist/memory-lifecycle-ledger-utils.d.ts +2 -1
  295. package/dist/memory-lifecycle-ledger-utils.js +4 -1
  296. package/dist/memory-projection-format.js +1 -0
  297. package/dist/{memory-projection-store-DeSXPh1j.d.ts → memory-projection-store-CY8TU40w.d.ts} +2 -1
  298. package/dist/memory-projection-store.d.ts +1 -1
  299. package/dist/memory-projection-store.js +2 -1
  300. package/dist/memory-worth-bench.js +1 -0
  301. package/dist/memory-worth-bench.js.map +1 -1
  302. package/dist/memory-worth-filter.js +1 -0
  303. package/dist/memory-worth-outcomes.d.ts +1 -1
  304. package/dist/memory-worth-outcomes.js +1 -0
  305. package/dist/memory-worth.js +1 -0
  306. package/dist/metadata-FC3XPDRQ.js +21 -0
  307. package/dist/metadata-FC3XPDRQ.js.map +1 -0
  308. package/dist/migrate-from-identity-anchor-TTEDEJGX.js +8 -0
  309. package/dist/migrate-from-identity-anchor-TTEDEJGX.js.map +1 -0
  310. package/dist/model-registry.js +1 -0
  311. package/dist/models-json.js +1 -0
  312. package/dist/native-knowledge.js +1 -0
  313. package/dist/negative.js +1 -0
  314. package/dist/objective-state-writers.js +1 -0
  315. package/dist/objective-state-writers.js.map +1 -1
  316. package/dist/objective-state.js +1 -0
  317. package/dist/openai-chat-compat.js +1 -0
  318. package/dist/operator-toolkit.d.ts +46 -2
  319. package/dist/operator-toolkit.js +29 -17
  320. package/dist/opik-exporter.js +1 -0
  321. package/dist/opik-exporter.js.map +1 -1
  322. package/dist/{orchestrator-CmJ-NTdJ.d.ts → orchestrator-ChkesB8U.d.ts} +177 -13
  323. package/dist/orchestrator.d.ts +6 -4
  324. package/dist/orchestrator.js +57 -41
  325. package/dist/page-versioning.js +1 -0
  326. package/dist/path-RMTY5Y5A.js +9 -0
  327. package/dist/path-RMTY5Y5A.js.map +1 -0
  328. package/dist/patterns-cli.d.ts +160 -0
  329. package/dist/patterns-cli.js +29 -0
  330. package/dist/patterns-cli.js.map +1 -0
  331. package/dist/peers-6OSQ3NK6.js +44 -0
  332. package/dist/peers-6OSQ3NK6.js.map +1 -0
  333. package/dist/plugin-id.js +1 -0
  334. package/dist/policy-runtime.js +1 -0
  335. package/dist/{port-BADbLZU5.d.ts → port-hqGnoStS.d.ts} +6 -0
  336. package/dist/profiling.js +1 -0
  337. package/dist/purge-6ATBGT77.js +205 -0
  338. package/dist/purge-6ATBGT77.js.map +1 -0
  339. package/dist/qmd-recall-cache.d.ts +1 -1
  340. package/dist/qmd-recall-cache.js +1 -0
  341. package/dist/qmd.d.ts +2 -1
  342. package/dist/qmd.js +4 -3
  343. package/dist/reasoning-trace-recall.js +1 -0
  344. package/dist/reasoning-trace-types.js +1 -0
  345. package/dist/recall-audit-anomaly.js +1 -0
  346. package/dist/recall-audit.js +1 -0
  347. package/dist/recall-disclosure-escalation.d.ts +84 -0
  348. package/dist/recall-disclosure-escalation.js +14 -0
  349. package/dist/recall-disclosure-escalation.js.map +1 -0
  350. package/dist/recall-explain-renderer.js +4 -1
  351. package/dist/recall-mmr.js +1 -0
  352. package/dist/recall-qos.js +1 -0
  353. package/dist/recall-query-policy.js +1 -0
  354. package/dist/recall-state.d.ts +7 -0
  355. package/dist/recall-state.js +2 -1
  356. package/dist/recall-tag-filter.d.ts +56 -0
  357. package/dist/recall-tag-filter.js +14 -0
  358. package/dist/recall-tag-filter.js.map +1 -0
  359. package/dist/recall-tokenization.js +1 -0
  360. package/dist/recall-xray-cli.d.ts +9 -2
  361. package/dist/recall-xray-cli.js +9 -4
  362. package/dist/recall-xray-renderer.js +4 -1
  363. package/dist/recall-xray.d.ts +116 -2
  364. package/dist/recall-xray.js +9 -3
  365. package/dist/reconstruct.js +1 -0
  366. package/dist/release-changelog.js +2 -0
  367. package/dist/release-changelog.js.map +1 -1
  368. package/dist/relevance.js +1 -0
  369. package/dist/rerank.js +1 -0
  370. package/dist/{resolution-QBTDHTG7.js → resolution-YGIBORXI.js} +2 -1
  371. package/dist/{resolution-QBTDHTG7.js.map → resolution-YGIBORXI.js.map} +1 -1
  372. package/dist/resolve-auth-token.d.ts +51 -0
  373. package/dist/resolve-auth-token.js +12 -0
  374. package/dist/resolve-auth-token.js.map +1 -0
  375. package/dist/resolve-provider-secret.d.ts +9 -1
  376. package/dist/resolve-provider-secret.js +4 -1
  377. package/dist/resume-bundles.js +4 -3
  378. package/dist/retrieval-agents.d.ts +1 -1
  379. package/dist/retrieval-agents.js +1 -0
  380. package/dist/retrieval-tiers.js +1 -0
  381. package/dist/retrieval.js +1 -0
  382. package/dist/sanitize.js +1 -0
  383. package/dist/schemas.d.ts +15 -2
  384. package/dist/schemas.js +2 -1
  385. package/dist/sdk-compat.js +1 -0
  386. package/dist/sdk-compat.js.map +1 -1
  387. package/dist/secure-store-4R2GSO7S.js +156 -0
  388. package/dist/secure-store-4R2GSO7S.js.map +1 -0
  389. package/dist/semantic-chunking.js +1 -0
  390. package/dist/{semantic-consolidation-CxJU6MJk.d.ts → semantic-consolidation-ByBXb-sf.d.ts} +3 -3
  391. package/dist/semantic-consolidation.d.ts +2 -2
  392. package/dist/semantic-consolidation.js +12 -7
  393. package/dist/semantic-rule-promotion.d.ts +1 -1
  394. package/dist/semantic-rule-promotion.js +10 -7
  395. package/dist/semantic-rule-verifier.d.ts +1 -1
  396. package/dist/semantic-rule-verifier.js +10 -7
  397. package/dist/session-integrity.js +1 -0
  398. package/dist/session-observer-bands.js +1 -0
  399. package/dist/session-observer-state.js +1 -0
  400. package/dist/session-toggles.js +2 -0
  401. package/dist/session-toggles.js.map +1 -1
  402. package/dist/signal.js +1 -0
  403. package/dist/skills-registry.js +2 -0
  404. package/dist/skills-registry.js.map +1 -1
  405. package/dist/source-attribution.js +1 -0
  406. package/dist/state-NCHQ4TRG.js +8 -0
  407. package/dist/state-NCHQ4TRG.js.map +1 -0
  408. package/dist/state-store-3EH7HYIN.js +16 -0
  409. package/dist/state-store-3EH7HYIN.js.map +1 -0
  410. package/dist/storage.d.ts +76 -2
  411. package/dist/storage.js +9 -6
  412. package/dist/store-contract.js +1 -0
  413. package/dist/summarizer.js +5 -4
  414. package/dist/summary-snapshot.js +1 -0
  415. package/dist/temporal-index.js +1 -0
  416. package/dist/temporal-supersession.d.ts +1 -1
  417. package/dist/temporal-supersession.js +2 -1
  418. package/dist/temporal-validity.d.ts +52 -0
  419. package/dist/temporal-validity.js +14 -0
  420. package/dist/temporal-validity.js.map +1 -0
  421. package/dist/threading.js +1 -0
  422. package/dist/tier-migration.d.ts +2 -2
  423. package/dist/tier-migration.js +1 -0
  424. package/dist/tier-routing.js +1 -0
  425. package/dist/tier-stats-62ZVDFKS.js +152 -0
  426. package/dist/tier-stats-62ZVDFKS.js.map +1 -0
  427. package/dist/tmt.js +1 -0
  428. package/dist/tokens.js +1 -0
  429. package/dist/topics.js +1 -0
  430. package/dist/trace-C5ETWBEF.js +290 -0
  431. package/dist/trace-C5ETWBEF.js.map +1 -0
  432. package/dist/transcript.js +1 -0
  433. package/dist/trust-zones.js +1 -0
  434. package/dist/tui-RI7P6PBS.js +13 -0
  435. package/dist/tui-RI7P6PBS.js.map +1 -0
  436. package/dist/types-V3FJ26TF.js +30 -0
  437. package/dist/types-V3FJ26TF.js.map +1 -0
  438. package/dist/types.d.ts +634 -9
  439. package/dist/types.js +10 -3
  440. package/dist/utility-learner.js +1 -0
  441. package/dist/utility-runtime.js +1 -0
  442. package/dist/utility-telemetry.js +1 -0
  443. package/dist/verified-recall.js +10 -7
  444. package/dist/version-utils.js +1 -0
  445. package/dist/whitespace.js +1 -0
  446. package/dist/work-product-ledger.js +1 -0
  447. package/package.json +7 -3
  448. package/scripts/ensure-better-sqlite3.mjs +124 -0
  449. package/dist/access-service-Br8ZydTK.d.ts +0 -827
  450. package/dist/chunk-3OGMS3PE.js.map +0 -1
  451. package/dist/chunk-3YGHKTBF.js.map +0 -1
  452. package/dist/chunk-6PFRXT4K.js.map +0 -1
  453. package/dist/chunk-6YJHX2DL.js.map +0 -1
  454. package/dist/chunk-BECYBZLX.js.map +0 -1
  455. package/dist/chunk-C2EFFULQ.js.map +0 -1
  456. package/dist/chunk-CUPFXL3J.js.map +0 -1
  457. package/dist/chunk-DIXB44VE.js.map +0 -1
  458. package/dist/chunk-F5VP6YCB.js.map +0 -1
  459. package/dist/chunk-FVA6TGI3.js.map +0 -1
  460. package/dist/chunk-GA5P7RST.js.map +0 -1
  461. package/dist/chunk-KVBLZUKV.js.map +0 -1
  462. package/dist/chunk-L7IXWRYE.js.map +0 -1
  463. package/dist/chunk-LOIMBRDE.js.map +0 -1
  464. package/dist/chunk-LTCGGW2D.js +0 -14
  465. package/dist/chunk-LTCGGW2D.js.map +0 -1
  466. package/dist/chunk-NZLQTHS5.js.map +0 -1
  467. package/dist/chunk-OC5OXUQ4.js.map +0 -1
  468. package/dist/chunk-PVPWZSSI.js.map +0 -1
  469. package/dist/chunk-SPI27QT6.js.map +0 -1
  470. package/dist/chunk-STGWEHYR.js.map +0 -1
  471. package/dist/chunk-TP4FZJIZ.js.map +0 -1
  472. package/dist/chunk-ULYOGL6R.js.map +0 -1
  473. package/dist/chunk-UWB5LMWY.js.map +0 -1
  474. package/dist/chunk-VBVG2M5G.js.map +0 -1
  475. package/dist/chunk-VDX363PS.js.map +0 -1
  476. package/dist/chunk-WCLICCGB.js.map +0 -1
  477. package/dist/chunk-X6GF3FX2.js +0 -26
  478. package/dist/chunk-X6GF3FX2.js.map +0 -1
  479. package/dist/chunk-XXVWLXSG.js.map +0 -1
  480. package/dist/chunk-Y7R2XJ5Q.js.map +0 -1
  481. package/dist/chunk-ZAIM4TUE.js.map +0 -1
  482. package/dist/engine-72LSIWQP.js +0 -23
  483. /package/dist/{contradiction-review-WIUBAR52.js.map → capsule-cli.js.map} +0 -0
  484. /package/dist/{engine-72LSIWQP.js.map → capsule-crypto-5CYAGVC5.js.map} +0 -0
  485. /package/dist/{chunk-TMYO7B5P.js.map → chunk-47WOM4YW.js.map} +0 -0
  486. /package/dist/{chunk-DG6YMRDC.js.map → chunk-B2TL6GA2.js.map} +0 -0
  487. /package/dist/{chunk-AYXIPSZO.js.map → chunk-CRU27Q4J.js.map} +0 -0
  488. /package/dist/{chunk-RBBWYEFJ.js.map → chunk-G2WADRQ3.js.map} +0 -0
  489. /package/dist/{chunk-NBVAS5MT.js.map → chunk-V7TEH5I2.js.map} +0 -0
@@ -1,14 +1,21 @@
1
+ import {
2
+ importCapsule
3
+ } from "./chunk-3KIS4VGT.js";
4
+ import {
5
+ applyTagFilter,
6
+ normalizeTags,
7
+ parseTagMatch
8
+ } from "./chunk-BT7NVCML.js";
9
+ import {
10
+ decideDisclosureEscalation
11
+ } from "./chunk-H7XKCNR6.js";
1
12
  import {
2
13
  toRecallExplainJson
3
- } from "./chunk-ZAIM4TUE.js";
14
+ } from "./chunk-LW2NMHDW.js";
4
15
  import {
5
- buildProposedActions,
6
- buildQualityScore,
7
- groupActionsByStatus,
8
- listMemoryGovernanceRuns,
9
- readMemoryGovernanceRunArtifact,
10
- runMemoryGovernance
11
- } from "./chunk-3OGMS3PE.js";
16
+ clusterByKey,
17
+ resolveGitContext
18
+ } from "./chunk-NN3TS5BM.js";
12
19
  import {
13
20
  getTrustZoneStoreStatus,
14
21
  isTrustZoneName,
@@ -18,28 +25,48 @@ import {
18
25
  seedTrustZoneDemoDataset,
19
26
  summarizeTrustZonePromotionReadiness
20
27
  } from "./chunk-EQINRHYR.js";
28
+ import {
29
+ estimateRecallTokens
30
+ } from "./chunk-USFPPRAF.js";
31
+ import {
32
+ buildProposedActions,
33
+ buildQualityScore,
34
+ groupActionsByStatus,
35
+ listMemoryGovernanceRuns,
36
+ readMemoryGovernanceRunArtifact,
37
+ runMemoryGovernance
38
+ } from "./chunk-F5VQOQ2E.js";
21
39
  import {
22
40
  recordMemoryOutcome
23
41
  } from "./chunk-EIR5VLIH.js";
42
+ import {
43
+ buildGraphSnapshot
44
+ } from "./chunk-PCUKNJAZ.js";
45
+ import {
46
+ persistExplicitCapture,
47
+ queueExplicitCaptureForReview,
48
+ validateExplicitCaptureInput
49
+ } from "./chunk-3FPTCC3Z.js";
24
50
  import {
25
51
  wrapWorkLayerContext
26
52
  } from "./chunk-EEQLFRUM.js";
53
+ import {
54
+ formatProfileTraceAscii
55
+ } from "./chunk-NBNN5GOB.js";
27
56
  import {
28
57
  buildProcedurePersistBody,
29
58
  normalizeProcedureSteps
30
59
  } from "./chunk-QDW3E4RD.js";
31
- import {
32
- persistExplicitCapture,
33
- queueExplicitCaptureForReview,
34
- validateExplicitCaptureInput
35
- } from "./chunk-3FPTCC3Z.js";
36
60
  import {
37
61
  CrossNamespaceBudget
38
62
  } from "./chunk-GDFS42HT.js";
39
63
  import {
40
64
  filterTrajectoriesByLookbackDays,
41
65
  readCausalTrajectoryRecords
42
- } from "./chunk-RBBWYEFJ.js";
66
+ } from "./chunk-G2WADRQ3.js";
67
+ import {
68
+ defaultCapsulesDir
69
+ } from "./chunk-74EMIVE4.js";
43
70
  import {
44
71
  canReadNamespace,
45
72
  canWriteNamespace,
@@ -52,21 +79,25 @@ import {
52
79
  buildBriefing,
53
80
  parseBriefingFocus,
54
81
  parseBriefingWindow
55
- } from "./chunk-L7IXWRYE.js";
82
+ } from "./chunk-ZIBOQULP.js";
56
83
  import {
57
84
  parseEntityFile
58
- } from "./chunk-F5VP6YCB.js";
85
+ } from "./chunk-Y4A6M3B6.js";
86
+ import {
87
+ DEFAULT_RECALL_DISCLOSURE,
88
+ isRecallDisclosure
89
+ } from "./chunk-43EKP2UK.js";
59
90
  import {
60
91
  inferMemoryStatus,
61
92
  toMemoryPathRel
62
- } from "./chunk-TP4FZJIZ.js";
93
+ } from "./chunk-RULE4VG5.js";
63
94
  import {
64
95
  normalizeProjectionPreview,
65
96
  normalizeProjectionTags
66
97
  } from "./chunk-SCU65EZI.js";
67
98
  import {
68
99
  getMemoryProjectionPath
69
- } from "./chunk-BOUYNNYD.js";
100
+ } from "./chunk-67YLUWLG.js";
70
101
  import {
71
102
  log
72
103
  } from "./chunk-2ODBA7MQ.js";
@@ -77,9 +108,16 @@ import {
77
108
  AccessIdempotencyStore,
78
109
  hashAccessIdempotencyPayload
79
110
  } from "./chunk-XKECPATV.js";
111
+ import {
112
+ exportCapsule
113
+ } from "./chunk-IYY4MCPG.js";
80
114
 
81
115
  // src/access-service.ts
82
116
  import { stat } from "fs/promises";
117
+ import * as nodeFs from "fs/promises";
118
+ import { constants as fsConstants } from "fs";
119
+ import { createHash } from "crypto";
120
+ import { ZodError } from "zod";
83
121
 
84
122
  // src/work/storage.ts
85
123
  import path from "path";
@@ -747,13 +785,7 @@ async function runProcedureMining(options) {
747
785
  causalTrajectoryStoreDir: trajectoryDir
748
786
  });
749
787
  const recent = filterTrajectoriesByLookbackDays(trajectories, cfg.lookbackDays);
750
- const clusters = /* @__PURE__ */ new Map();
751
- for (const t of recent) {
752
- const key = clusterKey(t);
753
- const arr = clusters.get(key) ?? [];
754
- arr.push(t);
755
- clusters.set(key, arr);
756
- }
788
+ const clusters = clusterByKey(recent, clusterKey);
757
789
  let clustersProcessed = 0;
758
790
  let proceduresWritten = 0;
759
791
  for (const [key, group] of clusters) {
@@ -906,8 +938,21 @@ function formatProcedureStatsText(report) {
906
938
  }
907
939
 
908
940
  // src/access-service.ts
941
+ import * as nodePath from "path";
909
942
  var EngramAccessInputError = class extends Error {
910
943
  };
944
+ var cachedPackageVersion = null;
945
+ async function getPackageVersion() {
946
+ if (cachedPackageVersion !== null) return cachedPackageVersion;
947
+ try {
948
+ const raw = await nodeFs.readFile(new URL("../package.json", import.meta.url), "utf-8");
949
+ const parsed = JSON.parse(raw);
950
+ cachedPackageVersion = typeof parsed.version === "string" && parsed.version.length > 0 ? parsed.version : "unknown";
951
+ } catch {
952
+ cachedPackageVersion = "unknown";
953
+ }
954
+ return cachedPackageVersion;
955
+ }
911
956
  function normalizeTrustZoneInputError(error) {
912
957
  const message = error instanceof Error ? error.message : null;
913
958
  if (!message) {
@@ -1020,6 +1065,23 @@ function compareBrowseMemory(sort, left, right) {
1020
1065
  return rightUpdated.localeCompare(leftUpdated) || rightCreated.localeCompare(leftCreated) || left.frontmatter.id.localeCompare(right.frontmatter.id);
1021
1066
  }
1022
1067
  }
1068
+ function shapeMemorySummary(memory, baseDir, disclosure, rawExcerpts) {
1069
+ const includeFullContent = disclosure === "section" || disclosure === "raw";
1070
+ return {
1071
+ id: memory.frontmatter.id,
1072
+ path: memory.path,
1073
+ category: memory.frontmatter.category,
1074
+ status: inferMemoryStatus(memory.frontmatter, toMemoryPathRel(baseDir, memory.path)),
1075
+ created: memory.frontmatter.created,
1076
+ updated: memory.frontmatter.updated,
1077
+ tags: normalizeProjectionTags(memory.frontmatter.tags),
1078
+ entityRef: memory.frontmatter.entityRef,
1079
+ preview: normalizeProjectionPreview(memory.content),
1080
+ ...disclosure !== void 0 ? { disclosure } : {},
1081
+ ...includeFullContent ? { content: memory.content } : {},
1082
+ ...disclosure === "raw" && rawExcerpts !== void 0 ? { rawExcerpts } : {}
1083
+ };
1084
+ }
1023
1085
  var EngramAccessService = class {
1024
1086
  constructor(orchestrator) {
1025
1087
  this.orchestrator = orchestrator;
@@ -1127,29 +1189,90 @@ var EngramAccessService = class {
1127
1189
  graph
1128
1190
  } : void 0;
1129
1191
  }
1130
- async serializeRecallResults(snapshot) {
1192
+ async serializeRecallResults(snapshot, disclosure, rawContext = null) {
1131
1193
  if (!snapshot) return [];
1132
1194
  const namespace = snapshot.namespace ? this.resolveNamespace(snapshot.namespace) : this.orchestrator.config.defaultNamespace;
1133
1195
  const storage = await this.orchestrator.getStorage(namespace);
1134
1196
  const storageDir = storage.dir;
1135
1197
  const results = [];
1136
1198
  const seen = /* @__PURE__ */ new Set();
1199
+ const rawExcerptsResult = await this.fetchRawExcerpts(
1200
+ disclosure,
1201
+ rawContext ? { ...rawContext, namespace } : null
1202
+ );
1203
+ const rawExcerpts = rawExcerptsResult ?? void 0;
1137
1204
  for (const memoryPath of snapshot.resultPaths ?? []) {
1138
1205
  if (!memoryPath || seen.has(memoryPath)) continue;
1139
1206
  const memory = await storage.readMemoryByPath(memoryPath);
1140
1207
  if (!memory) continue;
1141
1208
  seen.add(memoryPath);
1142
- results.push(this.serializeMemorySummary(memory, storageDir));
1209
+ results.push(
1210
+ this.serializeMemorySummary(
1211
+ memory,
1212
+ storageDir,
1213
+ disclosure,
1214
+ // Attach the (possibly empty) raw excerpts to the first raw
1215
+ // result; subsequent results do not duplicate the array.
1216
+ results.length === 0 ? rawExcerpts : void 0
1217
+ )
1218
+ );
1143
1219
  }
1144
1220
  if (results.length > 0) return results;
1145
1221
  for (const memoryId of snapshot.memoryIds) {
1146
1222
  const memory = await storage.getMemoryById(memoryId);
1147
1223
  if (!memory || seen.has(memory.path)) continue;
1148
1224
  seen.add(memory.path);
1149
- results.push(this.serializeMemorySummary(memory, storageDir));
1225
+ results.push(
1226
+ this.serializeMemorySummary(
1227
+ memory,
1228
+ storageDir,
1229
+ disclosure,
1230
+ results.length === 0 ? rawExcerpts : void 0
1231
+ )
1232
+ );
1150
1233
  }
1151
1234
  return results;
1152
1235
  }
1236
+ /**
1237
+ * Fetch raw transcript excerpts from the LCM archive for `disclosure ===
1238
+ * "raw"` recalls (issue #677 PR 2/4). Returns `null` for non-raw recall
1239
+ * depths, an empty array when LCM is disabled / not initialized / has no
1240
+ * matches, and an array of LCM-side excerpts otherwise. Errors are
1241
+ * swallowed and treated as "no excerpts" so a failing LCM never breaks
1242
+ * the recall response.
1243
+ *
1244
+ * Namespace handling: LCM archival prefixes non-default-namespace
1245
+ * sessions with `${namespace}:${sessionKey}` (see `observe()` around
1246
+ * line 2498), so the lookup must mirror that prefix or raw recalls in
1247
+ * non-default namespaces miss their own excerpts.
1248
+ */
1249
+ async fetchRawExcerpts(disclosure, context) {
1250
+ if (disclosure !== "raw") return null;
1251
+ if (!context || !context.query) return [];
1252
+ if (!context.sessionKey) return [];
1253
+ const lcm = this.orchestrator.lcmEngine;
1254
+ if (!lcm || !lcm.enabled) return [];
1255
+ try {
1256
+ const lcmSessionKey = context.namespace && context.namespace !== this.orchestrator.config.defaultNamespace ? `${context.namespace}:${context.sessionKey}` : context.sessionKey;
1257
+ const rows = await lcm.searchContextFull(
1258
+ context.query,
1259
+ // Cap the excerpt fanout so recall responses stay bounded. Five
1260
+ // matches is enough to anchor the model in the raw transcript
1261
+ // without ballooning token spend; raw is meant as the escape
1262
+ // hatch, not the default.
1263
+ 5,
1264
+ lcmSessionKey
1265
+ );
1266
+ return rows.map((r) => ({
1267
+ turnIndex: r.turn_index,
1268
+ role: r.role,
1269
+ content: r.content,
1270
+ sessionId: r.session_id
1271
+ }));
1272
+ } catch {
1273
+ return [];
1274
+ }
1275
+ }
1153
1276
  async handleIdempotentWrite(options) {
1154
1277
  if (options.skip === true) {
1155
1278
  return options.execute();
@@ -1205,8 +1328,8 @@ var EngramAccessService = class {
1205
1328
  async withIdempotencyLock(key, fn) {
1206
1329
  const previous = this.idempotencyLocks.get(key) ?? Promise.resolve();
1207
1330
  let release;
1208
- const current = new Promise((resolve) => {
1209
- release = resolve;
1331
+ const current = new Promise((resolve2) => {
1332
+ release = resolve2;
1210
1333
  });
1211
1334
  const queued = previous.then(() => current, () => current);
1212
1335
  this.idempotencyLocks.set(key, queued);
@@ -1350,17 +1473,81 @@ var EngramAccessService = class {
1350
1473
  defaultBranch: ctx.defaultBranch
1351
1474
  });
1352
1475
  }
1476
+ /**
1477
+ * Auto-resolve and attach a coding context for a session when one is not
1478
+ * already present. Resolves from `projectTag` (highest priority after
1479
+ * explicit `codingContext`), then from `cwd` via git detection.
1480
+ *
1481
+ * This is a no-op when:
1482
+ * - `sessionKey` is missing
1483
+ * - the session already has a coding context attached
1484
+ * - codingMode.projectScope is disabled (CLAUDE.md #30)
1485
+ * - neither `cwd` nor `projectTag` is provided
1486
+ *
1487
+ * Never throws — git resolution failures are silently ignored because not
1488
+ * being in a repo is a normal runtime state.
1489
+ */
1490
+ async maybeAttachCodingContext(sessionKey, options) {
1491
+ if (!sessionKey) return;
1492
+ if (!this.orchestrator.config.codingMode?.projectScope) return;
1493
+ if (this.orchestrator.getCodingContextForSession(sessionKey)) return;
1494
+ if (typeof options.projectTag === "string" && options.projectTag.trim().length > 0) {
1495
+ const tag = options.projectTag.trim();
1496
+ this.orchestrator.setCodingContextForSession(sessionKey, {
1497
+ projectId: `tag:${tag}`,
1498
+ branch: null,
1499
+ rootPath: `tag:${tag}`,
1500
+ defaultBranch: null
1501
+ });
1502
+ return;
1503
+ }
1504
+ if (typeof options.cwd === "string" && options.cwd.trim().length > 0) {
1505
+ try {
1506
+ const gitCtx = await resolveGitContext(options.cwd);
1507
+ if (gitCtx) {
1508
+ this.setCodingContext({
1509
+ sessionKey,
1510
+ codingContext: {
1511
+ projectId: gitCtx.projectId,
1512
+ branch: gitCtx.branch,
1513
+ rootPath: gitCtx.rootPath,
1514
+ defaultBranch: gitCtx.defaultBranch
1515
+ }
1516
+ });
1517
+ }
1518
+ } catch {
1519
+ }
1520
+ }
1521
+ }
1353
1522
  async recall(request) {
1354
1523
  const query = request.query.trim();
1355
1524
  if (query.length === 0) {
1356
1525
  throw new EngramAccessInputError("query is required");
1357
1526
  }
1527
+ const callerProvidedDisclosure = request.disclosure !== void 0 && request.disclosure !== null;
1528
+ const requestedDisclosure = (() => {
1529
+ if (!callerProvidedDisclosure) {
1530
+ return DEFAULT_RECALL_DISCLOSURE;
1531
+ }
1532
+ if (!isRecallDisclosure(request.disclosure)) {
1533
+ throw new EngramAccessInputError(
1534
+ `disclosure must be one of: chunk, section, raw (got: ${String(request.disclosure)})`
1535
+ );
1536
+ }
1537
+ return request.disclosure;
1538
+ })();
1358
1539
  if (request.codingContext !== void 0 && request.sessionKey) {
1359
1540
  this.setCodingContext({
1360
1541
  sessionKey: request.sessionKey,
1361
1542
  codingContext: request.codingContext
1362
1543
  });
1363
1544
  }
1545
+ if (request.codingContext === void 0 && request.sessionKey) {
1546
+ await this.maybeAttachCodingContext(request.sessionKey, {
1547
+ cwd: request.cwd,
1548
+ projectTag: request.projectTag
1549
+ });
1550
+ }
1364
1551
  const namespaceOverride = this.resolveRecallNamespace(request.namespace, request.sessionKey);
1365
1552
  const namespace = namespaceOverride ?? this.orchestrator.config.defaultNamespace;
1366
1553
  const mode = this.normalizeRecallMode(request.mode);
@@ -1421,16 +1608,77 @@ var EngramAccessService = class {
1421
1608
  this.budget.gc();
1422
1609
  }
1423
1610
  const topK = Number.isFinite(request.topK) ? Math.max(0, Math.floor(request.topK ?? 0)) : void 0;
1611
+ let asOf;
1612
+ if (request.asOf !== void 0 && request.asOf !== null) {
1613
+ if (typeof request.asOf !== "string" || request.asOf.trim().length === 0) {
1614
+ throw new EngramAccessInputError(
1615
+ "asOf must be a non-empty ISO 8601 timestamp string"
1616
+ );
1617
+ }
1618
+ const parsed = Date.parse(request.asOf);
1619
+ if (!Number.isFinite(parsed)) {
1620
+ throw new EngramAccessInputError(
1621
+ `asOf must be a parseable ISO 8601 timestamp (got: "${request.asOf}")`
1622
+ );
1623
+ }
1624
+ asOf = request.asOf;
1625
+ }
1424
1626
  const recallOptions = {
1425
1627
  namespace: namespaceOverride,
1426
1628
  topK,
1427
- mode
1629
+ mode,
1630
+ ...asOf !== void 0 ? { asOf } : {},
1631
+ ...request.includeLowConfidence === true ? { includeLowConfidence: true } : {}
1428
1632
  };
1429
1633
  const startedAt = Date.now();
1430
1634
  const context = await this.orchestrator.recall(query, request.sessionKey, recallOptions);
1431
1635
  const snapshot = request.sessionKey ? this.orchestrator.lastRecall.get(request.sessionKey) : null;
1432
1636
  const effectiveNamespace = snapshot?.namespace ? this.resolveNamespace(snapshot.namespace) : namespace;
1433
- const results = await this.serializeRecallResults(snapshot);
1637
+ const resultsReturned = snapshot?.memoryIds?.length ?? 0;
1638
+ const appliedTopK = snapshot?.budgetsApplied?.appliedTopK;
1639
+ const configMaxResults = typeof this.orchestrator.config.qmdMaxResults === "number" && Number.isFinite(this.orchestrator.config.qmdMaxResults) && this.orchestrator.config.qmdMaxResults > 0 ? this.orchestrator.config.qmdMaxResults : 0;
1640
+ const topKDenominator = typeof appliedTopK === "number" && Number.isFinite(appliedTopK) && appliedTopK > 0 ? Math.max(appliedTopK, resultsReturned) : typeof topK === "number" && topK > 0 ? Math.max(topK, resultsReturned) : Math.max(configMaxResults, resultsReturned, 1);
1641
+ const topKConfidence = snapshot && topKDenominator > 0 ? Math.min(1, resultsReturned / topKDenominator) : void 0;
1642
+ const escalationDecision = decideDisclosureEscalation({
1643
+ mode: this.orchestrator.config.recallDisclosureEscalation,
1644
+ threshold: this.orchestrator.config.recallDisclosureEscalationThreshold,
1645
+ originalDisclosure: requestedDisclosure,
1646
+ callerProvidedDisclosure,
1647
+ topKConfidence
1648
+ });
1649
+ const disclosure = escalationDecision.effective;
1650
+ let results = await this.serializeRecallResults(snapshot, disclosure, {
1651
+ query,
1652
+ sessionKey: request.sessionKey
1653
+ });
1654
+ const filterTags = normalizeTags(request.tags);
1655
+ let tagMatchMode;
1656
+ try {
1657
+ tagMatchMode = parseTagMatch(request.tagMatch);
1658
+ } catch (err) {
1659
+ throw new EngramAccessInputError(
1660
+ err instanceof Error ? err.message : String(err)
1661
+ );
1662
+ }
1663
+ let effectiveContext = context;
1664
+ if (filterTags && filterTags.length > 0) {
1665
+ const beforeIds = results.map((r) => r.id);
1666
+ const { results: admitted } = applyTagFilter(results, {
1667
+ tags: filterTags,
1668
+ tagMatch: tagMatchMode
1669
+ });
1670
+ results = admitted;
1671
+ const admittedIds = new Set(results.map((r) => r.id));
1672
+ const droppedAny = beforeIds.some((id) => !admittedIds.has(id));
1673
+ if (droppedAny) {
1674
+ effectiveContext = results.map((r) => {
1675
+ const content = typeof r.content === "string" ? r.content ?? "" : "";
1676
+ const preview = typeof r.preview === "string" ? r.preview ?? "" : "";
1677
+ return content || preview;
1678
+ }).filter((s) => s.length > 0).join("\n\n");
1679
+ }
1680
+ }
1681
+ const filteredMemoryIds = filterTags && filterTags.length > 0 ? results.map((r) => r.id) : snapshot?.memoryIds ?? [];
1434
1682
  const debug = await this.buildRecallDebug(
1435
1683
  snapshot,
1436
1684
  effectiveNamespace,
@@ -1451,8 +1699,13 @@ var EngramAccessService = class {
1451
1699
  trigger: "access-surface",
1452
1700
  queryText: query,
1453
1701
  candidateMemoryIds: snapshot?.memoryIds ?? [],
1454
- summary: context.slice(0, 200) || null,
1455
- injectedChars: context.length,
1702
+ // Audit must reflect what was actually injected, not what
1703
+ // recall produced before the tag filter. Using `context`
1704
+ // (pre-filter) overstates injectedChars and can leak content
1705
+ // from excluded memories into the audit summary (cursor
1706
+ // Medium on PR #712).
1707
+ summary: effectiveContext.slice(0, 200) || null,
1708
+ injectedChars: effectiveContext.length,
1456
1709
  toggleState: "enabled",
1457
1710
  latencyMs: Date.now() - startedAt,
1458
1711
  plannerMode: snapshot?.plannerMode ?? mode,
@@ -1471,15 +1724,16 @@ var EngramAccessService = class {
1471
1724
  query,
1472
1725
  sessionKey: request.sessionKey,
1473
1726
  namespace: effectiveNamespace,
1474
- context,
1475
- count: snapshot?.memoryIds.length ?? results.length,
1476
- memoryIds: snapshot?.memoryIds ?? [],
1727
+ context: effectiveContext,
1728
+ count: filterTags && filterTags.length > 0 ? results.length : snapshot?.memoryIds.length ?? results.length,
1729
+ memoryIds: filteredMemoryIds,
1477
1730
  results,
1478
1731
  recordedAt: snapshot?.recordedAt,
1479
1732
  traceId: snapshot?.traceId,
1480
1733
  plannerMode: snapshot?.plannerMode ?? mode,
1481
1734
  fallbackUsed: snapshot?.fallbackUsed ?? false,
1482
1735
  sourcesUsed: snapshot?.sourcesUsed ?? [],
1736
+ disclosure,
1483
1737
  budgetsApplied: snapshot?.budgetsApplied,
1484
1738
  auditAnomalies,
1485
1739
  budgetWarning: budgetDecision.reason === "warn-over-soft" ? budgetDecision : void 0,
@@ -1551,6 +1805,11 @@ var EngramAccessService = class {
1551
1805
  if (query.trim().length === 0) {
1552
1806
  throw new Error("recallXray: query is required and must be non-empty");
1553
1807
  }
1808
+ if (request.disclosure !== void 0 && !isRecallDisclosure(request.disclosure)) {
1809
+ throw new EngramAccessInputError(
1810
+ `recallXray: disclosure must be one of: chunk, section, raw (got: ${String(request.disclosure)})`
1811
+ );
1812
+ }
1554
1813
  const namespacesEnabled = this.orchestrator.config.namespacesEnabled;
1555
1814
  const requestedNamespace = request.namespace?.trim() ? this.resolveNamespace(request.namespace) : void 0;
1556
1815
  const authenticatedPrincipal = request.authenticatedPrincipal?.trim();
@@ -1579,8 +1838,8 @@ var EngramAccessService = class {
1579
1838
  const previousQueue = this.xrayQueue;
1580
1839
  let release = () => {
1581
1840
  };
1582
- this.xrayQueue = new Promise((resolve) => {
1583
- release = resolve;
1841
+ this.xrayQueue = new Promise((resolve2) => {
1842
+ release = resolve2;
1584
1843
  });
1585
1844
  await previousQueue;
1586
1845
  try {
@@ -1601,11 +1860,98 @@ var EngramAccessService = class {
1601
1860
  // (CLAUDE.md rule 42).
1602
1861
  ...authenticatedPrincipal ? { principalOverride: authenticatedPrincipal } : {}
1603
1862
  });
1604
- const snapshot = this.orchestrator.getLastXraySnapshot();
1605
- if (!snapshot) return { snapshotFound: false };
1606
- if (requestedNamespace && snapshot.namespace !== requestedNamespace) {
1863
+ const rawSnapshot = this.orchestrator.getLastXraySnapshot();
1864
+ if (!rawSnapshot) return { snapshotFound: false };
1865
+ if (requestedNamespace && rawSnapshot.namespace !== requestedNamespace) {
1607
1866
  return { snapshotFound: false };
1608
1867
  }
1868
+ let snapshot = rawSnapshot;
1869
+ const xrayFilterTags = normalizeTags(request.tags);
1870
+ let xrayTagMatch;
1871
+ try {
1872
+ xrayTagMatch = parseTagMatch(request.tagMatch);
1873
+ } catch (err) {
1874
+ throw new EngramAccessInputError(
1875
+ err instanceof Error ? err.message : String(err)
1876
+ );
1877
+ }
1878
+ if (xrayFilterTags && xrayFilterTags.length > 0) {
1879
+ const namespace = snapshot.namespace ? this.resolveNamespace(snapshot.namespace) : this.orchestrator.config.defaultNamespace;
1880
+ const tagsByIndex = await Promise.all(
1881
+ snapshot.results.map(async (result) => {
1882
+ try {
1883
+ const storage = await this.orchestrator.getStorage(namespace);
1884
+ const memory = await storage.readMemoryByPath(result.path);
1885
+ const t = memory?.frontmatter?.tags;
1886
+ return Array.isArray(t) ? normalizeProjectionTags(t) : [];
1887
+ } catch {
1888
+ return [];
1889
+ }
1890
+ })
1891
+ );
1892
+ const tagged = snapshot.results.map((result, index) => ({
1893
+ result,
1894
+ tags: tagsByIndex[index] ?? []
1895
+ }));
1896
+ const { results: admittedTagged, trace } = applyTagFilter(tagged, {
1897
+ tags: xrayFilterTags,
1898
+ tagMatch: xrayTagMatch
1899
+ });
1900
+ const admittedResults = admittedTagged.map((entry) => entry.result);
1901
+ const filters = trace ? [...snapshot.filters, trace] : snapshot.filters;
1902
+ snapshot = { ...snapshot, results: admittedResults, filters };
1903
+ }
1904
+ if (request.disclosure !== void 0) {
1905
+ const disclosure = request.disclosure;
1906
+ const namespace = snapshot.namespace ? this.resolveNamespace(snapshot.namespace) : this.orchestrator.config.defaultNamespace;
1907
+ const trimmedSessionKey = request.sessionKey?.trim() || void 0;
1908
+ const rawExcerpts = disclosure === "raw" ? await this.fetchRawExcerpts(disclosure, {
1909
+ query,
1910
+ ...trimmedSessionKey ? { sessionKey: trimmedSessionKey } : {},
1911
+ namespace
1912
+ }) : null;
1913
+ const rawExcerptText = rawExcerpts && rawExcerpts.length > 0 ? rawExcerpts.map((e) => e.content).join("\n") : "";
1914
+ const memoryByIndex = await Promise.all(
1915
+ snapshot.results.map(async (result) => {
1916
+ try {
1917
+ const storage = await this.orchestrator.getStorage(namespace);
1918
+ return await storage.readMemoryByPath(result.path);
1919
+ } catch {
1920
+ return null;
1921
+ }
1922
+ })
1923
+ );
1924
+ const firstReadableIndex = memoryByIndex.findIndex((m) => m !== null);
1925
+ const baseDir = (await this.orchestrator.getStorage(namespace)).dir;
1926
+ const decorated = snapshot.results.map((result, index) => {
1927
+ const memory = memoryByIndex[index];
1928
+ if (!memory) {
1929
+ return { ...result, disclosure };
1930
+ }
1931
+ const shaped = shapeMemorySummary(
1932
+ memory,
1933
+ baseDir,
1934
+ disclosure,
1935
+ disclosure === "raw" && index === firstReadableIndex && rawExcerpts && rawExcerpts.length > 0 ? rawExcerpts : void 0
1936
+ );
1937
+ return {
1938
+ ...result,
1939
+ disclosure,
1940
+ estimatedTokens: estimateRecallTokens(JSON.stringify(shaped))
1941
+ };
1942
+ });
1943
+ if (disclosure === "raw" && firstReadableIndex === -1 && rawExcerptText.length > 0 && decorated.length > 0) {
1944
+ decorated[0] = {
1945
+ ...decorated[0],
1946
+ disclosure,
1947
+ estimatedTokens: estimateRecallTokens(rawExcerptText)
1948
+ };
1949
+ }
1950
+ return {
1951
+ snapshotFound: true,
1952
+ snapshot: { ...snapshot, results: decorated }
1953
+ };
1954
+ }
1609
1955
  return { snapshotFound: true, snapshot };
1610
1956
  } finally {
1611
1957
  release();
@@ -2074,6 +2420,10 @@ var EngramAccessService = class {
2074
2420
  };
2075
2421
  }
2076
2422
  async governanceRun(request, principal) {
2423
+ const deepSleep = this.orchestrator.config.dreamsPhases.deepSleep;
2424
+ if (deepSleep.enabled === false && deepSleep.enabledExplicitlySet === true) {
2425
+ throw new Error("memory governance is disabled by dreams.phases.deepSleep.enabled=false");
2426
+ }
2077
2427
  const resolvedNamespace = this.resolveWritableNamespace(
2078
2428
  request.namespace,
2079
2429
  void 0,
@@ -2130,6 +2480,66 @@ var EngramAccessService = class {
2130
2480
  skippedReason: result.skippedReason
2131
2481
  };
2132
2482
  }
2483
+ async liveConnectorsRun(request = {}, principal) {
2484
+ this.resolveWritableNamespace(
2485
+ void 0,
2486
+ void 0,
2487
+ request.authenticatedPrincipal ?? principal
2488
+ );
2489
+ return this.orchestrator.runLiveConnectors({
2490
+ force: request.force === true
2491
+ });
2492
+ }
2493
+ /**
2494
+ * Run the pattern-reinforcement maintenance job (issue #687 PR 2/4).
2495
+ *
2496
+ * Cluster duplicate non-procedural memories and reinforce the
2497
+ * canonical (most-recent) member. Gated on
2498
+ * `patternReinforcementEnabled` — when disabled, returns
2499
+ * `{ ran: false, skippedReason: "disabled" }` so the cron payload
2500
+ * surface in CI logs cleanly.
2501
+ *
2502
+ * Resolves the namespace via the same writable path used by
2503
+ * `procedureMiningRun` so cross-tenant writes are impossible
2504
+ * (CLAUDE.md rule 42).
2505
+ *
2506
+ * Delegates the run to `orchestrator.runPatternReinforcement` so
2507
+ * the cadence floor (`patternReinforcementCadenceMs`) is enforced
2508
+ * uniformly across cron + MCP paths (PR #730 review feedback,
2509
+ * Codex P2). Accepts `force: true` for ad-hoc operator runs that
2510
+ * must bypass the cadence floor — mirrors the pattern used by
2511
+ * other maintenance MCP tools.
2512
+ */
2513
+ async patternReinforcementRun(request = {}, principal) {
2514
+ const resolvedNamespace = this.resolveWritableNamespace(
2515
+ request.namespace,
2516
+ void 0,
2517
+ request.authenticatedPrincipal ?? principal
2518
+ );
2519
+ const outcome = await this.orchestrator.runPatternReinforcement({
2520
+ namespace: resolvedNamespace,
2521
+ force: request.force === true
2522
+ });
2523
+ if (!outcome.ran) {
2524
+ return {
2525
+ namespace: resolvedNamespace,
2526
+ ran: false,
2527
+ skippedReason: outcome.skippedReason,
2528
+ clustersFound: 0,
2529
+ canonicalsUpdated: 0,
2530
+ duplicatesSuperseded: 0
2531
+ };
2532
+ }
2533
+ const result = outcome.result;
2534
+ return {
2535
+ namespace: resolvedNamespace,
2536
+ ran: true,
2537
+ clustersFound: result.clustersFound,
2538
+ canonicalsUpdated: result.canonicalsUpdated,
2539
+ duplicatesSuperseded: result.duplicatesSuperseded,
2540
+ result
2541
+ };
2542
+ }
2133
2543
  /**
2134
2544
  * Procedural memory stats (issue #567 PR 5/5). Read-only — resolves the
2135
2545
  * namespace via the same path used by `recallExplain` / `trustZoneStatus`
@@ -2147,6 +2557,147 @@ var EngramAccessService = class {
2147
2557
  });
2148
2558
  return { namespace: resolvedNamespace, ...report };
2149
2559
  }
2560
+ async memorySummarizeHourly() {
2561
+ await this.orchestrator.summarizer.runHourly();
2562
+ return {
2563
+ ok: true,
2564
+ message: "Hourly summarization completed. Check the summaries directory for results."
2565
+ };
2566
+ }
2567
+ async conversationIndexUpdate(request = {}) {
2568
+ if (!this.orchestrator.config.conversationIndexEnabled) {
2569
+ return {
2570
+ enabled: false,
2571
+ sessions: 0,
2572
+ chunks: 0,
2573
+ skipped: 0,
2574
+ skippedSessionKeys: [],
2575
+ embeddedRuns: 0,
2576
+ reason: "disabled"
2577
+ };
2578
+ }
2579
+ const hours = typeof request.hours === "number" && Number.isFinite(request.hours) ? Math.max(1, Math.floor(request.hours)) : 24;
2580
+ let sessionKey;
2581
+ if (request.sessionKey !== void 0) {
2582
+ if (typeof request.sessionKey !== "string" || request.sessionKey.trim().length === 0) {
2583
+ throw new EngramAccessInputError("sessionKey must be a non-empty string when provided");
2584
+ }
2585
+ sessionKey = request.sessionKey.trim();
2586
+ }
2587
+ if (sessionKey) {
2588
+ const result = await this.orchestrator.updateConversationIndex(
2589
+ sessionKey,
2590
+ hours,
2591
+ { embed: request.embed }
2592
+ );
2593
+ return {
2594
+ enabled: true,
2595
+ sessionKey,
2596
+ sessions: 1,
2597
+ chunks: result.chunks,
2598
+ skipped: result.skipped ? 1 : 0,
2599
+ skippedSessionKeys: result.skipped ? [sessionKey] : [],
2600
+ embeddedRuns: result.embedded ? 1 : 0,
2601
+ reason: result.reason,
2602
+ retryAfterMs: result.retryAfterMs
2603
+ };
2604
+ }
2605
+ const sessionKeys = await this.orchestrator.transcript.listSessionKeys();
2606
+ let chunks = 0;
2607
+ let skipped = 0;
2608
+ const skippedSessionKeys = [];
2609
+ let embeddedRuns = 0;
2610
+ for (const sessionKey2 of sessionKeys) {
2611
+ const result = await this.orchestrator.updateConversationIndex(
2612
+ sessionKey2,
2613
+ hours,
2614
+ { embed: request.embed }
2615
+ );
2616
+ chunks += result.chunks;
2617
+ if (result.skipped) {
2618
+ skipped += 1;
2619
+ skippedSessionKeys.push(sessionKey2);
2620
+ }
2621
+ if (result.embedded) {
2622
+ embeddedRuns += 1;
2623
+ }
2624
+ }
2625
+ return {
2626
+ enabled: true,
2627
+ sessions: sessionKeys.length,
2628
+ chunks,
2629
+ skipped,
2630
+ skippedSessionKeys,
2631
+ embeddedRuns
2632
+ };
2633
+ }
2634
+ async profilingReport(request = {}) {
2635
+ const profiler = this.orchestrator.profiler;
2636
+ if (!profiler.isEnabled) {
2637
+ return {
2638
+ enabled: false,
2639
+ reason: "disabled",
2640
+ message: "Profiling is disabled. Set profilingEnabled: true in your plugin config to enable."
2641
+ };
2642
+ }
2643
+ const format = request.format ?? "ascii";
2644
+ if (format !== "ascii" && format !== "json") {
2645
+ throw new EngramAccessInputError("format must be one of: ascii, json");
2646
+ }
2647
+ const limit = request.limit ?? 5;
2648
+ if (!Number.isInteger(limit) || limit < 1 || limit > 20) {
2649
+ throw new EngramAccessInputError("limit must be an integer between 1 and 20");
2650
+ }
2651
+ const traces = profiler.getRecentTraces(limit);
2652
+ const stats = profiler.getStats();
2653
+ const bottleneck = profiler.identifyBottleneck();
2654
+ if (format === "json") {
2655
+ return {
2656
+ enabled: true,
2657
+ format,
2658
+ traces,
2659
+ stats,
2660
+ bottleneck
2661
+ };
2662
+ }
2663
+ const lines = [];
2664
+ lines.push("Engram Profiling Report");
2665
+ lines.push("=".repeat(60));
2666
+ lines.push("");
2667
+ const allBuckets = [
2668
+ ["byKind", stats.byKind],
2669
+ ["bySpan", stats.bySpan]
2670
+ ];
2671
+ const hasStats = allBuckets.some(([, entries]) => Object.keys(entries).length > 0);
2672
+ if (hasStats) {
2673
+ lines.push("Aggregate Stats (all retained traces):");
2674
+ for (const [bucket, entries] of allBuckets) {
2675
+ for (const [key, summary] of Object.entries(entries)) {
2676
+ lines.push(
2677
+ ` ${bucket}/${key}: avg=${summary.avgMs}ms p50=${summary.p50Ms}ms p95=${summary.p95Ms}ms max=${summary.maxMs}ms (n=${summary.count})`
2678
+ );
2679
+ }
2680
+ }
2681
+ lines.push("");
2682
+ }
2683
+ if (bottleneck) {
2684
+ lines.push(`Bottleneck: ${bottleneck}`);
2685
+ lines.push("");
2686
+ }
2687
+ if (traces.length === 0) {
2688
+ lines.push("No traces recorded yet. Trigger a recall or extraction to see timing data.");
2689
+ } else {
2690
+ for (const trace of traces) {
2691
+ lines.push(formatProfileTraceAscii(trace));
2692
+ lines.push("");
2693
+ }
2694
+ }
2695
+ return {
2696
+ enabled: true,
2697
+ format,
2698
+ report: lines.join("\n")
2699
+ };
2700
+ }
2150
2701
  async trustZoneStatus(namespace, principal) {
2151
2702
  const resolvedNamespace = this.resolveReadableNamespace(namespace, principal);
2152
2703
  const storage = await this.orchestrator.getStorage(resolvedNamespace);
@@ -2320,18 +2871,8 @@ var EngramAccessService = class {
2320
2871
  frontmatter: memory.frontmatter
2321
2872
  };
2322
2873
  }
2323
- serializeMemorySummary(memory, baseDir) {
2324
- return {
2325
- id: memory.frontmatter.id,
2326
- path: memory.path,
2327
- category: memory.frontmatter.category,
2328
- status: inferMemoryStatus(memory.frontmatter, toMemoryPathRel(baseDir, memory.path)),
2329
- created: memory.frontmatter.created,
2330
- updated: memory.frontmatter.updated,
2331
- tags: normalizeProjectionTags(memory.frontmatter.tags),
2332
- entityRef: memory.frontmatter.entityRef,
2333
- preview: normalizeProjectionPreview(memory.content)
2334
- };
2874
+ serializeMemorySummary(memory, baseDir, disclosure, rawExcerpts) {
2875
+ return shapeMemorySummary(memory, baseDir, disclosure, rawExcerpts);
2335
2876
  }
2336
2877
  async observe(request) {
2337
2878
  if (!request.sessionKey || typeof request.sessionKey !== "string" || request.sessionKey.trim().length === 0) {
@@ -2353,6 +2894,10 @@ var EngramAccessService = class {
2353
2894
  request.sessionKey,
2354
2895
  request.authenticatedPrincipal
2355
2896
  );
2897
+ await this.maybeAttachCodingContext(request.sessionKey, {
2898
+ cwd: request.cwd,
2899
+ projectTag: request.projectTag
2900
+ });
2356
2901
  const lcmSessionKey = namespace !== this.orchestrator.config.defaultNamespace ? `${namespace}:${request.sessionKey}` : request.sessionKey;
2357
2902
  let lcmArchived = false;
2358
2903
  if (this.orchestrator.lcmEngine && this.orchestrator.lcmEngine.enabled) {
@@ -2540,6 +3085,14 @@ var EngramAccessService = class {
2540
3085
  if (!anchor) return { found: false, message: "No identity anchor found yet. Use identity_anchor_update to create one." };
2541
3086
  return { found: true, anchor };
2542
3087
  }
3088
+ /**
3089
+ * @deprecated since issue #679 PR 5/5 — the identity-anchor model is
3090
+ * superseded by the peer registry. Use `peerSet({ id: "self", ... })` or
3091
+ * `remnic peer set self` to update the self peer's identity kernel, and
3092
+ * `remnic peer migrate` to seed `peers/self/identity.md` from existing
3093
+ * legacy anchor data. This method continues to function for backward
3094
+ * compatibility but will be removed in a future major version.
3095
+ */
2543
3096
  async identityAnchorUpdate(request) {
2544
3097
  if (!this.orchestrator.config.identityContinuityEnabled) {
2545
3098
  return { enabled: false, reason: "Identity continuity is disabled." };
@@ -2934,6 +3487,80 @@ ${next}`);
2934
3487
  const explanation = await this.orchestrator.explainLastGraphRecall({ namespace });
2935
3488
  return { explanation };
2936
3489
  }
3490
+ /**
3491
+ * Read-only graph snapshot for the admin pane (issue #691 PR 2/5).
3492
+ *
3493
+ * Reads adjacency from the JSONL edge store written by `GraphIndex` and
3494
+ * resolves node metadata via the namespaced storage manager. Namespace
3495
+ * resolution mirrors the read-side path used by `recall` /
3496
+ * `procedureStats`, so multi-principal deployments can't leak edges from
3497
+ * a peer namespace (CLAUDE.md rule 42).
3498
+ */
3499
+ async graphSnapshot(request, authenticatedPrincipal) {
3500
+ const namespace = this.resolveReadableNamespace(
3501
+ request.namespace,
3502
+ authenticatedPrincipal
3503
+ );
3504
+ const storage = await this.orchestrator.getStorage(namespace);
3505
+ const cfg = this.orchestrator.config;
3506
+ let namespaceRootReal;
3507
+ try {
3508
+ namespaceRootReal = await nodeFs.realpath(storage.dir);
3509
+ } catch {
3510
+ namespaceRootReal = nodePath.resolve(storage.dir);
3511
+ }
3512
+ const namespaceRootWithSep = namespaceRootReal.endsWith(nodePath.sep) ? namespaceRootReal : namespaceRootReal + nodePath.sep;
3513
+ const loadNode = async (relPath) => {
3514
+ if (nodePath.isAbsolute(relPath)) {
3515
+ log.warn(
3516
+ `graphSnapshot: rejected absolute edge endpoint (len=${relPath.length}) outside namespace root`
3517
+ );
3518
+ return null;
3519
+ }
3520
+ const candidate = nodePath.resolve(namespaceRootReal, relPath);
3521
+ if (candidate !== namespaceRootReal && !candidate.startsWith(namespaceRootWithSep)) {
3522
+ log.warn(
3523
+ `graphSnapshot: rejected traversing edge endpoint (len=${relPath.length}) outside namespace root`
3524
+ );
3525
+ return null;
3526
+ }
3527
+ let canonical;
3528
+ try {
3529
+ canonical = await nodeFs.realpath(candidate);
3530
+ } catch {
3531
+ canonical = candidate;
3532
+ }
3533
+ if (canonical !== namespaceRootReal && !canonical.startsWith(namespaceRootWithSep)) {
3534
+ log.warn(
3535
+ `graphSnapshot: rejected symlinked edge endpoint (len=${relPath.length}) that resolved outside namespace root`
3536
+ );
3537
+ return null;
3538
+ }
3539
+ const memory = await storage.readMemoryByPath(canonical);
3540
+ if (!memory) return null;
3541
+ const fm = memory.frontmatter;
3542
+ return {
3543
+ category: fm.category ?? "unknown",
3544
+ label: fm.id ?? nodePath.basename(canonical, nodePath.extname(canonical)),
3545
+ updated: fm.updated
3546
+ };
3547
+ };
3548
+ return buildGraphSnapshot({
3549
+ memoryDir: namespaceRootReal,
3550
+ graphConfig: {
3551
+ entityGraphEnabled: cfg.entityGraphEnabled === true,
3552
+ timeGraphEnabled: cfg.timeGraphEnabled === true,
3553
+ causalGraphEnabled: cfg.causalGraphEnabled === true
3554
+ },
3555
+ request: {
3556
+ limit: request.limit,
3557
+ since: request.since,
3558
+ focusNodeId: request.focusNodeId,
3559
+ categories: request.categories
3560
+ },
3561
+ loadNode
3562
+ });
3563
+ }
2937
3564
  async memoryFeedback(request) {
2938
3565
  if (!this.orchestrator.config.feedbackEnabled) {
2939
3566
  return {
@@ -2990,22 +3617,82 @@ ${next}`);
2990
3617
  });
2991
3618
  return { promoted: true, memoryId: request.memoryId };
2992
3619
  }
3620
+ async memoryActionApply(request) {
3621
+ const actionTypes = /* @__PURE__ */ new Set([
3622
+ "store_episode",
3623
+ "store_note",
3624
+ "update_note",
3625
+ "create_artifact",
3626
+ "summarize_node",
3627
+ "discard",
3628
+ "link_graph"
3629
+ ]);
3630
+ if (!actionTypes.has(request.action)) {
3631
+ throw new EngramAccessInputError(
3632
+ `memory_action_apply: invalid action ${JSON.stringify(request.action)}`
3633
+ );
3634
+ }
3635
+ if (this.orchestrator.config.contextCompressionActionsEnabled !== true) {
3636
+ throw new EngramAccessInputError(
3637
+ "memory_action_apply is disabled; enable contextCompressionActionsEnabled to use this tool"
3638
+ );
3639
+ }
3640
+ const outcome = request.outcome ?? "skipped";
3641
+ if (outcome !== "applied" && outcome !== "skipped" && outcome !== "failed") {
3642
+ throw new EngramAccessInputError(
3643
+ `memory_action_apply: outcome must be "applied", "skipped", or "failed"; got ${JSON.stringify(outcome)}`
3644
+ );
3645
+ }
3646
+ const resolvedNs = this.resolveWritableNamespace(
3647
+ request.namespace,
3648
+ request.sessionKey,
3649
+ request.principal
3650
+ );
3651
+ const inputSummaryParts = [
3652
+ request.content,
3653
+ request.category ? `category=${request.category}` : void 0,
3654
+ request.linkTargetId ? `linkTargetId=${request.linkTargetId}` : void 0,
3655
+ request.linkType ? `linkType=${request.linkType}` : void 0,
3656
+ typeof request.linkStrength === "number" ? `linkStrength=${request.linkStrength}` : void 0,
3657
+ request.artifactType ? `artifactType=${request.artifactType}` : void 0,
3658
+ typeof request.execute === "boolean" ? `execute=${request.execute}` : void 0
3659
+ ].filter((part) => typeof part === "string" && part.length > 0);
3660
+ const event = {
3661
+ action: request.action,
3662
+ outcome,
3663
+ namespace: resolvedNs,
3664
+ actor: "access.memory_action_apply",
3665
+ subsystem: "access.memory_action_apply",
3666
+ reason: request.reason,
3667
+ memoryId: request.memoryId,
3668
+ sourceSessionKey: request.sessionKey,
3669
+ inputSummary: inputSummaryParts.length > 0 ? inputSummaryParts.join(" | ").slice(0, 500) : void 0,
3670
+ dryRun: request.dryRun === true,
3671
+ promptHash: typeof request.sourcePrompt === "string" && request.sourcePrompt.length > 0 ? createHash("sha256").update(request.sourcePrompt).digest("hex") : void 0
3672
+ };
3673
+ const preview = this.orchestrator.previewMemoryActionEvent(event);
3674
+ if (request.dryRun === true) {
3675
+ return { recorded: false, dryRun: true, event: preview };
3676
+ }
3677
+ const recorded = await this.orchestrator.appendMemoryActionEvent(event);
3678
+ return { recorded, event: preview };
3679
+ }
2993
3680
  async contextCheckpoint(request) {
2994
3681
  const resolvedNs = this.resolveWritableNamespace(request.namespace, request.sessionKey, request.principal);
2995
3682
  const storage = await this.orchestrator.getStorage(resolvedNs);
2996
3683
  const storageDir = storage.dir;
2997
3684
  const { writeFile: writeFile2, mkdir: mkdir2 } = await import("fs/promises");
2998
- const { join, resolve } = await import("path");
3685
+ const { join: join2, resolve: resolve2 } = await import("path");
2999
3686
  const safeKey = request.sessionKey.replace(/[^a-zA-Z0-9_-]/g, "_");
3000
3687
  if (!safeKey) throw new EngramAccessInputError("sessionKey is required");
3001
- const checkpointDir = join(storageDir, "checkpoints", safeKey);
3002
- const resolved = resolve(checkpointDir);
3003
- if (!resolved.startsWith(resolve(storageDir))) {
3688
+ const checkpointDir = join2(storageDir, "checkpoints", safeKey);
3689
+ const resolved = resolve2(checkpointDir);
3690
+ if (!resolved.startsWith(resolve2(storageDir))) {
3004
3691
  throw new EngramAccessInputError("Invalid sessionKey");
3005
3692
  }
3006
3693
  await mkdir2(checkpointDir, { recursive: true });
3007
3694
  const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3008
- const filePath = join(checkpointDir, `checkpoint-${ts}.md`);
3695
+ const filePath = join2(checkpointDir, `checkpoint-${ts}.md`);
3009
3696
  await writeFile2(filePath, request.context, "utf-8");
3010
3697
  return { saved: true };
3011
3698
  }
@@ -3040,8 +3727,8 @@ ${next}`);
3040
3727
  );
3041
3728
  const memoryIds = [];
3042
3729
  for (const entry of request.entries) {
3043
- const basename = entry.path.split("/").pop() ?? entry.path;
3044
- const id = basename.endsWith(".md") ? basename.slice(0, -3) : basename;
3730
+ const basename2 = entry.path.split("/").pop() ?? entry.path;
3731
+ const id = basename2.endsWith(".md") ? basename2.slice(0, -3) : basename2;
3045
3732
  if (id.length > 0) {
3046
3733
  memoryIds.push(id);
3047
3734
  }
@@ -3059,10 +3746,196 @@ ${next}`);
3059
3746
  }
3060
3747
  return { submitted: memoryIds.length, matched: matchedIds.length };
3061
3748
  }
3749
+ // ── Operator Console state (issue #688 PR 2/3) ────────────────────────────
3750
+ /**
3751
+ * Gather a point-in-time `ConsoleStateSnapshot` from the orchestrator.
3752
+ *
3753
+ * Principal-aware: `resolveReadableNamespace` enforces ACL before the
3754
+ * snapshot is gathered, so callers cannot read a namespace they don't
3755
+ * have read access to (CLAUDE.md rule 42). The resolved namespace's
3756
+ * storage directory is forwarded as `config.memoryDir` so the ledger-
3757
+ * tail reader in `gatherConsoleState` scans the correct namespace root
3758
+ * rather than the global root. Read-only — never mutates orchestrator state.
3759
+ */
3760
+ async consoleState(namespace, principal) {
3761
+ const resolvedNamespace = this.resolveReadableNamespace(namespace, principal);
3762
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
3763
+ const { gatherConsoleState } = await import("./state-NCHQ4TRG.js");
3764
+ const orchestratorProxy = Object.create(this.orchestrator, {
3765
+ config: {
3766
+ value: { ...this.orchestrator.config, memoryDir: storage.dir },
3767
+ enumerable: true,
3768
+ configurable: true
3769
+ }
3770
+ });
3771
+ return gatherConsoleState(orchestratorProxy);
3772
+ }
3773
+ // ── Peer Registry surfaces (issue #679 PR 4/5) ────────────────────────────
3774
+ /**
3775
+ * List all registered peers. Returns the array of `Peer` objects in
3776
+ * deterministic alphabetical order (mirroring `listPeers` storage semantics).
3777
+ */
3778
+ async peerList() {
3779
+ const { listPeers } = await import("./peers-6OSQ3NK6.js");
3780
+ const peers = await listPeers(this.orchestrator.config.memoryDir);
3781
+ return { peers };
3782
+ }
3783
+ /**
3784
+ * Get a single peer by id. Returns `{ found: false }` when the peer does
3785
+ * not exist rather than throwing, matching the `memoryGet` / `entityGet`
3786
+ * pattern used throughout the service.
3787
+ */
3788
+ async peerGet(peerId) {
3789
+ const peers = await import("./peers-6OSQ3NK6.js");
3790
+ const validateId = peers.assertValidPeerId;
3791
+ try {
3792
+ validateId(peerId);
3793
+ } catch (err) {
3794
+ throw new EngramAccessInputError(err.message);
3795
+ }
3796
+ const peer = await peers.readPeer(this.orchestrator.config.memoryDir, peerId);
3797
+ if (!peer) return { found: false };
3798
+ return { found: true, peer };
3799
+ }
3800
+ /**
3801
+ * Upsert a peer. Writes `peers/{id}/identity.md`. On first write the
3802
+ * `createdAt` timestamp is set to now; on subsequent writes only
3803
+ * `displayName` and `notes` are mutated (kind and createdAt are immutable
3804
+ * once set, per the storage contract).
3805
+ *
3806
+ * Returns `{ created: true }` on first write, `{ created: false }` on update.
3807
+ */
3808
+ async peerSet(input) {
3809
+ const peers = await import("./peers-6OSQ3NK6.js");
3810
+ const validateId = peers.assertValidPeerId;
3811
+ const { id } = input;
3812
+ try {
3813
+ validateId(id);
3814
+ } catch (err) {
3815
+ throw new EngramAccessInputError(err.message);
3816
+ }
3817
+ const memoryDir = this.orchestrator.config.memoryDir;
3818
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3819
+ const existing = await peers.readPeer(memoryDir, id);
3820
+ const ALLOWED_KINDS = /* @__PURE__ */ new Set(["self", "human", "agent", "integration"]);
3821
+ if (!existing) {
3822
+ const kind = input.kind ?? "human";
3823
+ if (!ALLOWED_KINDS.has(kind)) {
3824
+ throw new EngramAccessInputError(
3825
+ `peer kind must be one of ${[...ALLOWED_KINDS].join(", ")}`
3826
+ );
3827
+ }
3828
+ const newPeer = {
3829
+ id,
3830
+ kind,
3831
+ displayName: input.displayName ?? id,
3832
+ createdAt: now,
3833
+ updatedAt: now,
3834
+ ...typeof input.notes === "string" ? { notes: input.notes } : {}
3835
+ };
3836
+ await peers.writePeer(memoryDir, newPeer);
3837
+ return { ok: true, created: true, peer: newPeer };
3838
+ }
3839
+ const updated = {
3840
+ id: existing.id,
3841
+ kind: existing.kind,
3842
+ createdAt: existing.createdAt,
3843
+ updatedAt: now,
3844
+ displayName: input.displayName !== void 0 ? input.displayName : existing.displayName,
3845
+ ...input.notes !== void 0 ? { notes: input.notes } : existing.notes !== void 0 ? { notes: existing.notes } : {}
3846
+ };
3847
+ await peers.writePeer(memoryDir, updated);
3848
+ return { ok: true, created: false, peer: updated };
3849
+ }
3850
+ /**
3851
+ * Delete a peer by removing `peers/{id}/identity.md`. If the file does not
3852
+ * exist the call is a no-op (idempotent). The peer directory itself
3853
+ * (`peers/{id}/`) is intentionally left in place — profile and interaction
3854
+ * log data are not destroyed.
3855
+ */
3856
+ async peerDelete(peerId) {
3857
+ const peers = await import("./peers-6OSQ3NK6.js");
3858
+ const validateId = peers.assertValidPeerId;
3859
+ try {
3860
+ validateId(peerId);
3861
+ } catch (err) {
3862
+ throw new EngramAccessInputError(err.message);
3863
+ }
3864
+ const deleted = await peers.deletePeer(this.orchestrator.config.memoryDir, peerId);
3865
+ return { ok: true, deleted };
3866
+ }
3867
+ /**
3868
+ * Destructively purge the entire peer directory for a given peerId —
3869
+ * `identity.md`, `profile.md`, `interactions.log.md`, and any other
3870
+ * files in `peers/{id}/`. Requires `confirm: "yes"` to prevent
3871
+ * accidental invocation.
3872
+ *
3873
+ * This is the DESTRUCTIVE counterpart to `peerDelete`, which only
3874
+ * removes `identity.md`. All companion files are permanently removed.
3875
+ *
3876
+ * Returns `{ ok: true, purged: true }` when the directory existed and
3877
+ * was removed; `{ ok: true, purged: false }` when the directory did
3878
+ * not exist (idempotent no-op).
3879
+ */
3880
+ async peerForget(peerId, opts) {
3881
+ const peers = await import("./peers-6OSQ3NK6.js");
3882
+ const validateId = peers.assertValidPeerId;
3883
+ try {
3884
+ validateId(peerId);
3885
+ } catch (err) {
3886
+ throw new EngramAccessInputError(err.message);
3887
+ }
3888
+ if (opts.confirm !== "yes") {
3889
+ throw new EngramAccessInputError(
3890
+ "peerForget requires confirm: 'yes' to prevent accidental data loss"
3891
+ );
3892
+ }
3893
+ const result = await peers.forgetPeer(this.orchestrator.config.memoryDir, peerId, {
3894
+ confirm: "yes"
3895
+ });
3896
+ return { ok: true, purged: result.purged };
3897
+ }
3898
+ /**
3899
+ * Get the evolving cognitive profile for a peer. Returns `{ found: false }`
3900
+ * when no profile file exists yet (profile is written by the async reasoner,
3901
+ * PR 2/5). The peer identity itself need not exist for a profile to exist,
3902
+ * but in practice the reasoner only writes profiles for registered peers.
3903
+ */
3904
+ async peerProfileGet(peerId) {
3905
+ const peers = await import("./peers-6OSQ3NK6.js");
3906
+ const validateId = peers.assertValidPeerId;
3907
+ try {
3908
+ validateId(peerId);
3909
+ } catch (err) {
3910
+ throw new EngramAccessInputError(err.message);
3911
+ }
3912
+ const profile = await peers.readPeerProfile(this.orchestrator.config.memoryDir, peerId);
3913
+ if (!profile) return { found: false };
3914
+ return { found: true, profile };
3915
+ }
3062
3916
  // ── Contradiction Review (issue #520) ──────────────────────────────────────
3063
3917
  get memoryDir() {
3064
3918
  return this.orchestrator.config.memoryDir;
3065
3919
  }
3920
+ /**
3921
+ * Resolve the storage directory for a given namespace. Used by the SSE
3922
+ * graph-event handler to subscribe to the correct per-namespace bus rather
3923
+ * than the global root (CLAUDE.md rule 42 — read/write paths must resolve
3924
+ * through the same namespace layer).
3925
+ *
3926
+ * `principal` must be the transport-bound request principal (from
3927
+ * `resolveRequestPrincipal`). When namespaces are enabled, an absent
3928
+ * principal causes `resolveReadableNamespace` to throw an auth error,
3929
+ * matching the behaviour of every other authenticated read path.
3930
+ *
3931
+ * Falls back to `this.memoryDir` when namespaces are disabled or the
3932
+ * namespace is absent, matching the behaviour of every other read path.
3933
+ */
3934
+ async getMemoryDirForNamespace(namespace, principal) {
3935
+ const resolved = this.resolveReadableNamespace(namespace, principal);
3936
+ const storage = await this.orchestrator.getStorage(resolved);
3937
+ return storage.dir;
3938
+ }
3066
3939
  get storageRef() {
3067
3940
  return this.orchestrator.storage;
3068
3941
  }
@@ -3087,6 +3960,257 @@ ${next}`);
3087
3960
  };
3088
3961
  };
3089
3962
  }
3963
+ /**
3964
+ * Import a capsule archive into the orchestrator's memory directory.
3965
+ *
3966
+ * Delegates directly to the standalone {@link importCapsuleFn} function.
3967
+ * The `root` parameter defaults to the orchestrator's `memoryDir` when
3968
+ * omitted, so callers that only have access to the service do not need to
3969
+ * thread the config value through.
3970
+ *
3971
+ * `versioning` defaults to the orchestrator's page-versioning config so
3972
+ * `mode: "overwrite"` automatically snapshots prior content without the
3973
+ * caller having to construct the config object.
3974
+ */
3975
+ async capsuleImport(opts) {
3976
+ const { namespace, principal, root: explicitRoot, memoryDir: explicitMemoryDir, ...importOptions } = opts;
3977
+ const resolvedNamespace = this.resolveWritableNamespace(namespace, void 0, principal);
3978
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
3979
+ const root = explicitRoot ?? storage.dir;
3980
+ const memoryDir = explicitMemoryDir ?? this.orchestrator.config.memoryDir;
3981
+ const versioning = importOptions.versioning ?? {
3982
+ enabled: this.orchestrator.config.versioningEnabled,
3983
+ maxVersionsPerPage: this.orchestrator.config.versioningMaxPerPage,
3984
+ sidecarDir: this.orchestrator.config.versioningSidecarDir
3985
+ };
3986
+ await this.validateCapsuleImportArchivePath(importOptions.archivePath);
3987
+ try {
3988
+ return await importCapsule({ ...importOptions, root, memoryDir, versioning });
3989
+ } catch (err) {
3990
+ const message = err instanceof Error ? err.message : String(err);
3991
+ if (this.isCapsuleImportArchiveInputError(err, message)) {
3992
+ throw new EngramAccessInputError(`capsule import failed: ${message}`);
3993
+ }
3994
+ throw err;
3995
+ }
3996
+ }
3997
+ async validateCapsuleImportArchivePath(archivePath) {
3998
+ let archiveStat;
3999
+ try {
4000
+ archiveStat = await stat(archivePath);
4001
+ } catch (err) {
4002
+ if (!this.isCapsuleImportPathInputFsError(err)) throw err;
4003
+ const message = err instanceof Error ? err.message : String(err);
4004
+ throw new EngramAccessInputError(`capsule import failed: archive is not readable: ${message}`);
4005
+ }
4006
+ if (!archiveStat.isFile()) {
4007
+ throw new EngramAccessInputError("capsule import failed: archivePath must point to a file");
4008
+ }
4009
+ try {
4010
+ await nodeFs.access(archivePath, fsConstants.R_OK);
4011
+ } catch (err) {
4012
+ if (!this.isCapsuleImportPathInputFsError(err)) throw err;
4013
+ const message = err instanceof Error ? err.message : String(err);
4014
+ throw new EngramAccessInputError(`capsule import failed: archive is not readable: ${message}`);
4015
+ }
4016
+ }
4017
+ isCapsuleImportPathInputFsError(err) {
4018
+ const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
4019
+ return code === "ENOENT" || code === "ENOTDIR" || code === "EACCES" || code === "EPERM" || code === "ELOOP";
4020
+ }
4021
+ isCapsuleImportArchiveInputError(err, message) {
4022
+ if (err instanceof ZodError) return true;
4023
+ const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
4024
+ if (typeof code === "string" && code.startsWith("Z_")) return true;
4025
+ return message.startsWith("importCapsule: archive") || message.startsWith("importCapsule: bundle") || message.startsWith("importCapsule: manifest") || message.startsWith("importCapsule: record") || /incorrect header check|invalid stored block lengths|not in gzip format|unexpected end of file/i.test(message);
4026
+ }
4027
+ /**
4028
+ * Export a capsule archive from the orchestrator's memory directory.
4029
+ *
4030
+ * HTTP and future MCP surfaces use this rather than calling the transfer
4031
+ * helper directly so namespace ACL checks stay consistent with the archive
4032
+ * write side effect. The exporter still owns archive construction and
4033
+ * validation.
4034
+ */
4035
+ async capsuleExport(opts) {
4036
+ const { namespace, principal, root: explicitRoot, memoryDir: explicitMemoryDir, ...exportOptions } = opts;
4037
+ const resolvedNamespace = this.resolveWritableNamespace(namespace, void 0, principal);
4038
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
4039
+ const root = explicitRoot ?? storage.dir;
4040
+ const memoryDir = explicitMemoryDir ?? this.orchestrator.config.memoryDir;
4041
+ const pluginVersion = exportOptions.pluginVersion ?? await getPackageVersion();
4042
+ return exportCapsule({
4043
+ ...exportOptions,
4044
+ pluginVersion,
4045
+ root,
4046
+ memoryDir: exportOptions.encrypt === true ? memoryDir : void 0
4047
+ });
4048
+ }
4049
+ /**
4050
+ * List capsule archives in the namespace-scoped capsule store.
4051
+ *
4052
+ * MCP uses this access-layer method instead of reading arbitrary paths so
4053
+ * capsule discovery remains bound to the same namespace ACLs as export and
4054
+ * import.
4055
+ */
4056
+ async capsuleList(options) {
4057
+ const resolvedNamespace = this.resolveReadableNamespace(options?.namespace, options?.principal);
4058
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
4059
+ const capsulesDir = defaultCapsulesDir(storage.dir);
4060
+ let dirEntries;
4061
+ try {
4062
+ const capsulesDirStat = await nodeFs.lstat(capsulesDir);
4063
+ if (capsulesDirStat.isSymbolicLink()) {
4064
+ throw new EngramAccessInputError("capsule list failed: capsule store directory must not be a symlink");
4065
+ }
4066
+ if (!capsulesDirStat.isDirectory()) {
4067
+ throw new EngramAccessInputError("capsule list failed: capsule store path must be a directory");
4068
+ }
4069
+ dirEntries = await nodeFs.readdir(capsulesDir, { withFileTypes: true });
4070
+ } catch (err) {
4071
+ const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
4072
+ if (code === "ENOENT") {
4073
+ return { namespace: resolvedNamespace, capsulesDir, capsules: [] };
4074
+ }
4075
+ throw err;
4076
+ }
4077
+ const archiveNames = dirEntries.filter(
4078
+ (entry) => entry.isFile() && (entry.name.endsWith(".capsule.json.gz") || entry.name.endsWith(".capsule.json.gz.enc"))
4079
+ ).map((entry) => entry.name).sort();
4080
+ const capsules = [];
4081
+ for (const archiveName of archiveNames) {
4082
+ const archivePath = nodePath.join(capsulesDir, archiveName);
4083
+ const id = archiveName.replace(/\.capsule\.json\.gz\.enc$/, "").replace(/\.capsule\.json\.gz$/, "");
4084
+ const manifestPath = nodePath.join(capsulesDir, `${id}.manifest.json`);
4085
+ let createdAt = null;
4086
+ let pluginVersion = null;
4087
+ let fileCount = null;
4088
+ let description = null;
4089
+ let manifestPathOrNull = manifestPath;
4090
+ try {
4091
+ const manifestStat = await nodeFs.lstat(manifestPath);
4092
+ if (manifestStat.isSymbolicLink() || !manifestStat.isFile()) {
4093
+ capsules.push({
4094
+ id,
4095
+ archivePath,
4096
+ manifestPath: manifestPathOrNull,
4097
+ createdAt,
4098
+ pluginVersion,
4099
+ fileCount,
4100
+ description
4101
+ });
4102
+ continue;
4103
+ }
4104
+ const raw = await nodeFs.readFile(manifestPath, "utf-8");
4105
+ const sidecar = JSON.parse(raw);
4106
+ createdAt = typeof sidecar.createdAt === "string" ? sidecar.createdAt : null;
4107
+ pluginVersion = typeof sidecar.pluginVersion === "string" ? sidecar.pluginVersion : null;
4108
+ fileCount = Array.isArray(sidecar.files) ? sidecar.files.length : null;
4109
+ const capsule = sidecar.capsule;
4110
+ description = capsule && typeof capsule.description === "string" ? capsule.description : null;
4111
+ } catch (err) {
4112
+ const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
4113
+ if (code === "ENOENT") {
4114
+ manifestPathOrNull = null;
4115
+ }
4116
+ }
4117
+ capsules.push({
4118
+ id,
4119
+ archivePath,
4120
+ manifestPath: manifestPathOrNull,
4121
+ createdAt,
4122
+ pluginVersion,
4123
+ fileCount,
4124
+ description
4125
+ });
4126
+ }
4127
+ return { namespace: resolvedNamespace, capsulesDir, capsules };
4128
+ }
4129
+ // ── Dreams pipeline telemetry surfaces (issue #678 PR 3+4) ──────────────
4130
+ /**
4131
+ * Return per-phase Dreams telemetry for the last N hours (default 24).
4132
+ */
4133
+ async dreamsStatus(options) {
4134
+ const { getDreamsStatus, normalizeDreamsStatusWindowHours } = await import("./dreams-ledger-LR2NBAZE.js");
4135
+ let windowHours;
4136
+ try {
4137
+ windowHours = normalizeDreamsStatusWindowHours(options?.windowHours);
4138
+ } catch (error) {
4139
+ throw new EngramAccessInputError(error instanceof Error ? error.message : String(error));
4140
+ }
4141
+ const resolvedNamespace = this.resolveReadableNamespace(options?.namespace, options?.principal);
4142
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
4143
+ return getDreamsStatus(storage.dir, windowHours);
4144
+ }
4145
+ /**
4146
+ * Manually invoke a single Dreams phase pass (PR 4/4).
4147
+ *
4148
+ * Deep-sleep delegates to memory governance (shadow → dry-run, apply → live).
4149
+ * Light-sleep and REM scan the observation ledger and memory corpus
4150
+ * respectively, returning the same telemetry shape as a scheduled run.
4151
+ */
4152
+ async dreamsRun(options) {
4153
+ const { runDreamsPhase } = await import("./dreams-ledger-LR2NBAZE.js");
4154
+ const validPhases = ["lightSleep", "rem", "deepSleep"];
4155
+ if (!validPhases.includes(options.phase)) {
4156
+ throw new EngramAccessInputError(
4157
+ `Invalid phase: ${String(options.phase)}. Must be one of: ${validPhases.join(", ")}`
4158
+ );
4159
+ }
4160
+ const deepSleep = this.orchestrator.config.dreamsPhases.deepSleep;
4161
+ if (options.phase === "deepSleep" && deepSleep.enabled === false && deepSleep.enabledExplicitlySet === true) {
4162
+ throw new EngramAccessInputError(
4163
+ "memory governance is disabled by dreams.phases.deepSleep.enabled=false"
4164
+ );
4165
+ }
4166
+ const dryRun = options.dryRun === true;
4167
+ const resolvedNamespace = this.resolveWritableNamespace(
4168
+ options.namespace,
4169
+ void 0,
4170
+ options.authenticatedPrincipal
4171
+ );
4172
+ const storage = await this.orchestrator.getStorage(resolvedNamespace);
4173
+ const memoryDir = storage.dir;
4174
+ const phaseRunner = dryRun || options.phase === "deepSleep" ? void 0 : async (_opts) => {
4175
+ if (_opts.phase === "lightSleep") {
4176
+ const result3 = await this.orchestrator.runLifecyclePolicyNow(storage);
4177
+ return {
4178
+ itemsProcessed: result3.memoriesAssessed,
4179
+ notes: `scored ${result3.memoriesAssessed} memories`
4180
+ };
4181
+ }
4182
+ const result2 = await this.orchestrator.runSemanticConsolidationNow({
4183
+ dryRun: false,
4184
+ storage
4185
+ });
4186
+ const itemsProcessed = result2.clusters.reduce(
4187
+ (sum, cluster) => sum + cluster.memories.length,
4188
+ 0
4189
+ );
4190
+ return {
4191
+ itemsProcessed,
4192
+ notes: `REM consolidation found ${result2.clustersFound} clusters`
4193
+ };
4194
+ };
4195
+ const governanceRunner = options.phase === "deepSleep" ? async (_opts) => {
4196
+ return this.orchestrator.runDeepSleepGovernanceNow({
4197
+ storage,
4198
+ dryRun: _opts.dryRun
4199
+ });
4200
+ } : void 0;
4201
+ const result = await runDreamsPhase(
4202
+ { memoryDir, phase: options.phase, dryRun },
4203
+ governanceRunner,
4204
+ phaseRunner
4205
+ );
4206
+ return {
4207
+ phase: result.phase,
4208
+ dryRun: result.dryRun,
4209
+ durationMs: result.durationMs,
4210
+ itemsProcessed: result.itemsProcessed,
4211
+ notes: result.notes
4212
+ };
4213
+ }
3090
4214
  };
3091
4215
 
3092
4216
  export {
@@ -3095,6 +4219,7 @@ export {
3095
4219
  formatProcedureStatsText,
3096
4220
  EngramAccessInputError,
3097
4221
  ENGRAM_ACCESS_WRITE_SCHEMA_VERSION,
4222
+ shapeMemorySummary,
3098
4223
  EngramAccessService
3099
4224
  };
3100
- //# sourceMappingURL=chunk-STGWEHYR.js.map
4225
+ //# sourceMappingURL=chunk-AEMBDV7M.js.map