@remnic/core 9.69.10 → 9.69.12

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 (580) hide show
  1. package/dist/access-admin-ops-surface.d.ts +15 -13
  2. package/dist/access-admin-ops-surface.js +46 -34
  3. package/dist/access-authorization-probe.d.ts +13 -11
  4. package/dist/access-authorization-probe.js +47 -35
  5. package/dist/access-boundary.d.ts +13 -11
  6. package/dist/access-boundary.js +46 -34
  7. package/dist/access-cli.js +108 -97
  8. package/dist/access-cli.js.map +1 -1
  9. package/dist/access-coding-context-resolution.d.ts +2 -1
  10. package/dist/access-extraction-force-flush.d.ts +13 -11
  11. package/dist/access-extraction-force-flush.js +46 -34
  12. package/dist/access-health-types.d.ts +2 -1
  13. package/dist/access-http-lcm-compaction.d.ts +13 -11
  14. package/dist/access-http-lifecycle-flush.d.ts +13 -11
  15. package/dist/access-http-offline-stream.d.ts +13 -11
  16. package/dist/access-http-query.d.ts +3 -2
  17. package/dist/access-http-query.js +48 -36
  18. package/dist/access-http.d.ts +14 -12
  19. package/dist/access-http.js +67 -53
  20. package/dist/access-identity-continuity-surface.d.ts +10 -9
  21. package/dist/access-identity-continuity-surface.js +46 -34
  22. package/dist/access-lcm-surface.d.ts +13 -11
  23. package/dist/access-lcm-surface.js +46 -34
  24. package/dist/access-mcp-output-schemas.js +1 -1
  25. package/dist/access-mcp.d.ts +13 -11
  26. package/dist/access-mcp.js +58 -45
  27. package/dist/access-memory-search-fanout.d.ts +3 -2
  28. package/dist/{access-namespace-preflight-S8fhQcCo.d.ts → access-namespace-preflight-Cy0yPsaE.d.ts} +1 -1
  29. package/dist/access-namespace-preflight.d.ts +4 -3
  30. package/dist/access-namespace-preflight.js +46 -34
  31. package/dist/access-observe-write-surface.d.ts +15 -13
  32. package/dist/access-observe-write-surface.js +46 -34
  33. package/dist/access-offline-manifest.d.ts +10 -9
  34. package/dist/access-offline-manifest.js +3 -3
  35. package/dist/access-operations-batch.js +49 -37
  36. package/dist/access-operations.d.ts +19 -17
  37. package/dist/access-operations.js +54 -42
  38. package/dist/access-recall-concurrency.d.ts +13 -11
  39. package/dist/access-recall-concurrency.js +46 -34
  40. package/dist/access-recall-response.d.ts +13 -11
  41. package/dist/access-recall-response.js +46 -34
  42. package/dist/access-recall-surface.d.ts +13 -11
  43. package/dist/access-recall-surface.js +46 -34
  44. package/dist/access-schema.d.ts +107 -90
  45. package/dist/access-schema.js +7 -5
  46. package/dist/{access-service-DcfM0Vf0.d.ts → access-service-Baz5xW5X.d.ts} +89 -72
  47. package/dist/access-service-helpers.d.ts +13 -11
  48. package/dist/access-service.d.ts +13 -11
  49. package/dist/access-service.js +46 -34
  50. package/dist/access-surface-catalog.d.ts +13 -11
  51. package/dist/access-surface-catalog.js +50 -36
  52. package/dist/access-surface-catalog.js.map +1 -1
  53. package/dist/access-wearables-meetings-surface.d.ts +4 -3
  54. package/dist/action-confidence.d.ts +2 -1
  55. package/dist/active-memory-bridge.d.ts +2 -1
  56. package/dist/active-recall.d.ts +2 -1
  57. package/dist/active-recall.js +6 -5
  58. package/dist/active-recall.js.map +1 -1
  59. package/dist/adapters/index.js +4 -4
  60. package/dist/adapters/registry.js +2 -2
  61. package/dist/ambient-provenance.d.ts +2 -1
  62. package/dist/artifact-search.d.ts +2 -1
  63. package/dist/behavior-learner.d.ts +2 -1
  64. package/dist/behavior-signals.d.ts +2 -1
  65. package/dist/bootstrap.d.ts +10 -9
  66. package/dist/briefing-window.d.ts +3 -2
  67. package/dist/briefing.d.ts +3 -2
  68. package/dist/briefing.js +13 -13
  69. package/dist/buffer-surprise-report.d.ts +2 -1
  70. package/dist/buffer-turn-helpers.d.ts +2 -1
  71. package/dist/buffer.d.ts +3 -2
  72. package/dist/bulk-import/index.d.ts +4 -3
  73. package/dist/calibration.d.ts +2 -1
  74. package/dist/capabilities.d.ts +2 -1
  75. package/dist/{catalog-BmBXTtOs.d.ts → catalog-9X8WpZNO.d.ts} +1 -1
  76. package/dist/causal-behavior.d.ts +2 -1
  77. package/dist/causal-behavior.js +2 -2
  78. package/dist/causal-chain.js +2 -2
  79. package/dist/causal-consolidation.d.ts +2 -1
  80. package/dist/causal-consolidation.js +16 -16
  81. package/dist/causal-retrieval.js +2 -2
  82. package/dist/causal-trajectory-graph.d.ts +2 -1
  83. package/dist/causal-trajectory-graph.js +2 -2
  84. package/dist/causal-trajectory.js +1 -1
  85. package/dist/{chunk-D5VPIJN3.js → chunk-227WJVPY.js} +2 -2
  86. package/dist/{chunk-Y3BWCIY2.js → chunk-2EHDPHMD.js} +2 -2
  87. package/dist/{chunk-2LKW6OO7.js → chunk-2XJDAEAM.js} +2 -2
  88. package/dist/{chunk-P23JWI3D.js → chunk-3ITTF7YH.js} +52 -52
  89. package/dist/{chunk-3DT2F5OI.js → chunk-3YKOFCKP.js} +11 -6
  90. package/dist/chunk-3YKOFCKP.js.map +1 -0
  91. package/dist/{chunk-NGP2FPB2.js → chunk-4UVDLNHQ.js} +2 -2
  92. package/dist/{chunk-HXWOVCS6.js → chunk-4WIKMOE3.js} +44 -22
  93. package/dist/chunk-4WIKMOE3.js.map +1 -0
  94. package/dist/{chunk-6RPB2TDG.js → chunk-5HO3QBAD.js} +11 -6
  95. package/dist/chunk-5HO3QBAD.js.map +1 -0
  96. package/dist/{chunk-AYWPIH4M.js → chunk-5P2KNFJZ.js} +149 -25
  97. package/dist/chunk-5P2KNFJZ.js.map +1 -0
  98. package/dist/{chunk-FJMIQTMH.js → chunk-5YQ7RFSO.js} +2 -2
  99. package/dist/{chunk-KQAFEZQX.js → chunk-7LCGFUMB.js} +4 -4
  100. package/dist/{chunk-EESYTBXV.js → chunk-7NCUHD5U.js} +2 -2
  101. package/dist/{chunk-X574KX52.js → chunk-7ZMU4XQT.js} +2 -2
  102. package/dist/{chunk-SG3Z67FB.js → chunk-APZXA4WI.js} +2 -2
  103. package/dist/{chunk-2QSZNTDO.js → chunk-AU7Q3LSC.js} +4 -4
  104. package/dist/{chunk-VGMRI4J6.js → chunk-B75VCEX5.js} +4 -4
  105. package/dist/{chunk-D35XLYQ7.js → chunk-BE4Y6GK6.js} +11 -11
  106. package/dist/{chunk-ELKD5PCD.js → chunk-BEXFNGQ3.js} +3 -3
  107. package/dist/{chunk-U5SRTYFS.js → chunk-BFDOBESV.js} +2 -2
  108. package/dist/{chunk-OLT3YTDH.js → chunk-BIJAWZYW.js} +4 -4
  109. package/dist/{chunk-FU2NYFX6.js → chunk-BO4PWIJY.js} +3 -3
  110. package/dist/{chunk-JMAG7WZ7.js → chunk-BX6GW4KC.js} +2 -2
  111. package/dist/chunk-CC37E3QM.js +198 -0
  112. package/dist/chunk-CC37E3QM.js.map +1 -0
  113. package/dist/{chunk-J2R275FN.js → chunk-CTCGHNWN.js} +4 -4
  114. package/dist/{chunk-X5PIDJ3L.js → chunk-DA4ZMCBU.js} +3 -3
  115. package/dist/{chunk-IVAW3HBF.js → chunk-DH3V7RCQ.js} +21 -13
  116. package/dist/chunk-DH3V7RCQ.js.map +1 -0
  117. package/dist/chunk-DXFG2VGN.js +50 -0
  118. package/dist/chunk-DXFG2VGN.js.map +1 -0
  119. package/dist/{chunk-4OFKZAJG.js → chunk-EAARGPWI.js} +2 -1
  120. package/dist/chunk-EAARGPWI.js.map +1 -0
  121. package/dist/{chunk-H6RSANGQ.js → chunk-ETZ7KKOS.js} +2 -2
  122. package/dist/{chunk-K4E3Y3ZX.js → chunk-G7VEQEMG.js} +2 -1
  123. package/dist/chunk-G7VEQEMG.js.map +1 -0
  124. package/dist/{chunk-XZBXINXZ.js → chunk-GIC6BASP.js} +4 -4
  125. package/dist/{chunk-SXQZMC7R.js → chunk-GR4C3FHT.js} +2 -2
  126. package/dist/{chunk-7DYGPGCT.js → chunk-H5IIBGDM.js} +2 -2
  127. package/dist/{chunk-CNNXMIS6.js → chunk-HFRGCNFY.js} +10 -10
  128. package/dist/chunk-HRATODNO.js +28 -0
  129. package/dist/chunk-HRATODNO.js.map +1 -0
  130. package/dist/{chunk-MAG6M3B6.js → chunk-HTOWFFAI.js} +2 -2
  131. package/dist/chunk-HUSTM6PU.js +27 -0
  132. package/dist/chunk-HUSTM6PU.js.map +1 -0
  133. package/dist/{chunk-FOCMJEHH.js → chunk-I4QAH4SY.js} +3 -3
  134. package/dist/{chunk-FSGCXGK6.js → chunk-I6DUKBUI.js} +2 -2
  135. package/dist/{chunk-VI637ILW.js → chunk-IN673LEP.js} +48 -15
  136. package/dist/chunk-IN673LEP.js.map +1 -0
  137. package/dist/{chunk-6FUMA6AA.js → chunk-JGXMA6HL.js} +2 -2
  138. package/dist/{chunk-TA7UZZMW.js → chunk-JHTF22NQ.js} +2 -2
  139. package/dist/{chunk-DZ3CNJPB.js → chunk-LDOQE34V.js} +2 -2
  140. package/dist/{chunk-MEW53VQJ.js → chunk-LDWIPYJ6.js} +7 -7
  141. package/dist/{chunk-227UFSEQ.js → chunk-LEPOP46W.js} +4 -4
  142. package/dist/{chunk-KJTSWJZN.js → chunk-LF6SHWVV.js} +2 -2
  143. package/dist/{chunk-G6OZZX7P.js → chunk-LJAP4KSW.js} +2 -2
  144. package/dist/{chunk-NV6BTBUI.js → chunk-LJNLLNEM.js} +2 -2
  145. package/dist/{chunk-FFFZEF6B.js → chunk-LUDXSSTW.js} +2 -2
  146. package/dist/{chunk-PCH2CVCS.js → chunk-LWBSEYW3.js} +6 -6
  147. package/dist/chunk-M6RORUO5.js +59 -0
  148. package/dist/chunk-M6RORUO5.js.map +1 -0
  149. package/dist/{chunk-FMUJGGKW.js → chunk-M7DGN6JZ.js} +3 -3
  150. package/dist/{chunk-TZIHB2LP.js → chunk-MNH2GM4O.js} +5 -5
  151. package/dist/{chunk-RACZB5HT.js → chunk-N37X5RU7.js} +4 -4
  152. package/dist/{chunk-LK4TOYPU.js → chunk-NF3NMAG7.js} +2 -2
  153. package/dist/{chunk-QL4U3SJA.js → chunk-NHLEFBE2.js} +11 -3
  154. package/dist/chunk-NHLEFBE2.js.map +1 -0
  155. package/dist/chunk-NN5CQTAJ.js +42 -0
  156. package/dist/chunk-NN5CQTAJ.js.map +1 -0
  157. package/dist/{chunk-AG46P24C.js → chunk-NNBZS3DY.js} +4 -4
  158. package/dist/{chunk-LZ2JTO7N.js → chunk-OASGWNYL.js} +2 -2
  159. package/dist/chunk-OEDW4ER7.js +62 -0
  160. package/dist/chunk-OEDW4ER7.js.map +1 -0
  161. package/dist/{chunk-C2JCVZWX.js → chunk-OLBZ2WGG.js} +2 -2
  162. package/dist/{chunk-Z3SQEEB6.js → chunk-OUKBMQ2O.js} +2 -2
  163. package/dist/{chunk-XXW32OL7.js → chunk-OYV6RKPM.js} +1 -1
  164. package/dist/chunk-OYV6RKPM.js.map +1 -0
  165. package/dist/{chunk-2Z3DG5CQ.js → chunk-P6GKRT2H.js} +1 -1
  166. package/dist/{chunk-UGA6PZTX.js → chunk-P7LVYPIX.js} +3 -3
  167. package/dist/{chunk-26JWBSWD.js → chunk-PGCZLHRB.js} +11 -3
  168. package/dist/chunk-PGCZLHRB.js.map +1 -0
  169. package/dist/{chunk-VE45LRCE.js → chunk-QRDSXR3V.js} +2 -2
  170. package/dist/{chunk-KS67VHXA.js → chunk-QUVWFZOU.js} +2 -2
  171. package/dist/{chunk-AI4QFDPR.js → chunk-R7FXPG4T.js} +2 -2
  172. package/dist/chunk-RF2SMMPP.js +37 -0
  173. package/dist/chunk-RF2SMMPP.js.map +1 -0
  174. package/dist/{chunk-X66BHMAU.js → chunk-RJ57OOCD.js} +2 -2
  175. package/dist/chunk-S5G2LAL7.js +354 -0
  176. package/dist/chunk-S5G2LAL7.js.map +1 -0
  177. package/dist/{chunk-VXMKW7YN.js → chunk-TRLCMLX7.js} +2 -2
  178. package/dist/{chunk-ELCMVOQT.js → chunk-V3HUBF7T.js} +2 -2
  179. package/dist/{chunk-KMIAD7JR.js → chunk-VHAKBUBD.js} +2 -2
  180. package/dist/{chunk-GS5IFIVE.js → chunk-VYD63IFH.js} +3 -3
  181. package/dist/chunk-VZIAVM72.js +49 -0
  182. package/dist/chunk-VZIAVM72.js.map +1 -0
  183. package/dist/chunk-WTWQA7BB.js +28 -0
  184. package/dist/chunk-WTWQA7BB.js.map +1 -0
  185. package/dist/{chunk-TBRG2SYY.js → chunk-X4FIZAVQ.js} +94 -52
  186. package/dist/chunk-X4FIZAVQ.js.map +1 -0
  187. package/dist/{chunk-WSFPNCRA.js → chunk-XFPHV65N.js} +2 -2
  188. package/dist/{chunk-JCUG7AXZ.js → chunk-XJJYSX6F.js} +4 -4
  189. package/dist/{chunk-I6DURYZI.js → chunk-XMIAU4CO.js} +2 -2
  190. package/dist/{chunk-PJIGYPO5.js → chunk-XQGFIAG7.js} +2 -2
  191. package/dist/{chunk-B2URC6LJ.js → chunk-YWN3GYI2.js} +2 -2
  192. package/dist/{chunk-TG6JEJDV.js → chunk-Z33VUMKY.js} +3 -3
  193. package/dist/{cli-CFpMhqz5.d.ts → cli-CMtkGBdz.d.ts} +5 -5
  194. package/dist/cli.d.ts +15 -13
  195. package/dist/cli.js +88 -77
  196. package/dist/coding/export-okf-codegraph.d.ts +2 -1
  197. package/dist/coding/export-okf-codegraph.js +13 -13
  198. package/dist/coding/pre-action-gate.d.ts +2 -1
  199. package/dist/coding/pre-action-gate.js +2 -2
  200. package/dist/compounding/engine.d.ts +3 -2
  201. package/dist/compounding/engine.js +15 -14
  202. package/dist/compounding/preference-consolidator.d.ts +2 -1
  203. package/dist/compression-optimizer.d.ts +2 -1
  204. package/dist/config.d.ts +2 -1
  205. package/dist/config.js +6 -5
  206. package/dist/connectors/codex-materialize-runner.d.ts +2 -1
  207. package/dist/connectors/codex-materialize-runner.js +13 -13
  208. package/dist/connectors/codex-materialize.d.ts +2 -1
  209. package/dist/connectors/index.d.ts +2 -1
  210. package/dist/connectors/index.js +13 -13
  211. package/dist/consolidation-provenance-check.d.ts +3 -2
  212. package/dist/consolidation-undo.d.ts +3 -2
  213. package/dist/contradiction/index.d.ts +4 -3
  214. package/dist/converge-config.d.ts +2 -1
  215. package/dist/convergence-refresh.d.ts +3 -2
  216. package/dist/convergence-refresh.js +15 -15
  217. package/dist/conversation-index/backend.d.ts +2 -1
  218. package/dist/conversation-index/backend.js +2 -2
  219. package/dist/conversation-index/chunker.d.ts +2 -1
  220. package/dist/conversation-index/faiss-adapter.d.ts +2 -1
  221. package/dist/conversation-index/indexer.d.ts +2 -1
  222. package/dist/conversation-index/search.d.ts +2 -1
  223. package/dist/corpus-watermark.d.ts +2 -1
  224. package/dist/corpus-watermark.js +15 -15
  225. package/dist/cross-lingual-recall.d.ts +2 -1
  226. package/dist/day-summary.d.ts +2 -1
  227. package/dist/deep-recall-config.d.ts +32 -0
  228. package/dist/deep-recall-config.js +12 -0
  229. package/dist/deep-recall-http-glue.d.ts +170 -0
  230. package/dist/deep-recall-http-glue.js +31 -0
  231. package/dist/deep-recall-http-glue.js.map +1 -0
  232. package/dist/deep-recall-mcp-tools.d.ts +144 -0
  233. package/dist/deep-recall-mcp-tools.js +8 -0
  234. package/dist/deep-recall-mcp-tools.js.map +1 -0
  235. package/dist/deep-recall-policy-llm.d.ts +37 -0
  236. package/dist/deep-recall-policy-llm.js +19 -0
  237. package/dist/deep-recall-policy-llm.js.map +1 -0
  238. package/dist/deep-recall-renderer.d.ts +16 -0
  239. package/dist/deep-recall-renderer.js +8 -0
  240. package/dist/deep-recall-renderer.js.map +1 -0
  241. package/dist/deep-recall-seeds.d.ts +83 -0
  242. package/dist/deep-recall-seeds.js +8 -0
  243. package/dist/deep-recall-seeds.js.map +1 -0
  244. package/dist/deep-recall.d.ts +97 -0
  245. package/dist/deep-recall.js +13 -0
  246. package/dist/deep-recall.js.map +1 -0
  247. package/dist/delinearize.d.ts +2 -1
  248. package/dist/dependency-propagation-config.d.ts +2 -1
  249. package/dist/{dependency-propagation-delivery-BC3bCEet.d.ts → dependency-propagation-delivery-BZGUecZf.d.ts} +1 -1
  250. package/dist/direct-answer-wiring.d.ts +2 -1
  251. package/dist/direct-answer.d.ts +2 -1
  252. package/dist/embedding-fallback.d.ts +2 -1
  253. package/dist/enrichment/index.d.ts +2 -1
  254. package/dist/entity-origin-fields.d.ts +2 -1
  255. package/dist/entity-retrieval.d.ts +3 -2
  256. package/dist/entity-retrieval.js +13 -13
  257. package/dist/entity-schema.d.ts +2 -1
  258. package/dist/episodic-context.d.ts +2 -1
  259. package/dist/eval-trajectory-contracts.d.ts +2 -1
  260. package/dist/eval-trajectory-store.d.ts +2 -1
  261. package/dist/eval-trajectory.d.ts +2 -1
  262. package/dist/explicit-capture.d.ts +10 -9
  263. package/dist/external-wiki-access.d.ts +13 -11
  264. package/dist/external-wiki-access.js +47 -35
  265. package/dist/external-wiki-collection-registration.d.ts +2 -1
  266. package/dist/external-wiki-collection.d.ts +2 -1
  267. package/dist/external-wiki-mcp-tools.d.ts +13 -11
  268. package/dist/extraction-error-classification.d.ts +2 -1
  269. package/dist/extraction-faithfulness.d.ts +2 -1
  270. package/dist/extraction-judge-telemetry.d.ts +2 -1
  271. package/dist/extraction-judge-training.d.ts +2 -1
  272. package/dist/extraction-judge.d.ts +2 -1
  273. package/dist/extraction-liveness.d.ts +2 -1
  274. package/dist/extraction-normalization.d.ts +2 -1
  275. package/dist/extraction-prompt.d.ts +2 -1
  276. package/dist/extraction-source-grounding-rules.d.ts +2 -1
  277. package/dist/extraction-source-grounding.d.ts +2 -1
  278. package/dist/extraction.d.ts +2 -1
  279. package/dist/extraction.js +15 -15
  280. package/dist/fallback-llm.d.ts +2 -1
  281. package/dist/graph-dashboard-diff.d.ts +2 -1
  282. package/dist/graph-dashboard-key.d.ts +2 -1
  283. package/dist/graph-dashboard-parser.d.ts +2 -1
  284. package/dist/{graph-edge-decay-DGTBFALQ.js → graph-edge-decay-FXGELBFA.js} +4 -4
  285. package/dist/graph-edge-decay-FXGELBFA.js.map +1 -0
  286. package/dist/graph-edge-reinforcement.d.ts +2 -1
  287. package/dist/graph-path-reconstruction.d.ts +2 -1
  288. package/dist/graph-path-scoring.d.ts +2 -1
  289. package/dist/graph-snapshot.d.ts +2 -1
  290. package/dist/graph-snapshot.js +3 -3
  291. package/dist/graph.d.ts +2 -1
  292. package/dist/graph.js +2 -2
  293. package/dist/harmonic-construction.js +3 -3
  294. package/dist/harmonic-retrieval.d.ts +38 -2
  295. package/dist/harmonic-retrieval.js +12 -3
  296. package/dist/importance.d.ts +2 -1
  297. package/dist/importers/index.d.ts +2 -1
  298. package/dist/in-flight-reads.d.ts +2 -1
  299. package/dist/{index-D4hS9uxK.d.ts → index-B4iTvT-w.d.ts} +2 -2
  300. package/dist/index.d.ts +701 -699
  301. package/dist/index.js +126 -115
  302. package/dist/intent.d.ts +2 -1
  303. package/dist/lcm/engine.d.ts +2 -1
  304. package/dist/lcm/index.d.ts +2 -1
  305. package/dist/lcm/tools.d.ts +2 -1
  306. package/dist/lifecycle.d.ts +2 -1
  307. package/dist/live-connectors-runner.d.ts +2 -1
  308. package/dist/local-llm.d.ts +2 -1
  309. package/dist/local-model-endpoint.d.ts +2 -1
  310. package/dist/location/index.d.ts +4 -3
  311. package/dist/location/index.js +15 -15
  312. package/dist/maintenance/memory-governance.d.ts +2 -1
  313. package/dist/maintenance/memory-governance.js +13 -13
  314. package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +3 -2
  315. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +13 -13
  316. package/dist/maintenance/rebuild-memory-projection.d.ts +3 -2
  317. package/dist/maintenance/rebuild-memory-projection.js +14 -14
  318. package/dist/{maintenance-BRcc3Hx8.d.ts → maintenance-BBpNqEeJ.d.ts} +3 -3
  319. package/dist/mcp-memory-inspector-app.d.ts +13 -11
  320. package/dist/mcp-read-only-tools.js +1 -1
  321. package/dist/memory-action-policy.d.ts +2 -1
  322. package/dist/memory-cache.d.ts +2 -1
  323. package/dist/memory-controller.d.ts +2 -1
  324. package/dist/memory-lifecycle-ledger-utils.d.ts +2 -1
  325. package/dist/memory-projection-store.d.ts +2 -1
  326. package/dist/memory-provenance.d.ts +2 -1
  327. package/dist/memory-snapshot.d.ts +2 -1
  328. package/dist/memory-subject-cli.d.ts +13 -11
  329. package/dist/memory-subject.d.ts +13 -11
  330. package/dist/memory-worth-outcomes.d.ts +3 -2
  331. package/dist/models-json.d.ts +2 -1
  332. package/dist/namespaces/migrate.d.ts +4 -3
  333. package/dist/namespaces/migrate.js +14 -14
  334. package/dist/namespaces/principal.d.ts +2 -1
  335. package/dist/namespaces/search.d.ts +2 -1
  336. package/dist/namespaces/search.js +9 -9
  337. package/dist/namespaces/storage.d.ts +4 -3
  338. package/dist/namespaces/storage.js +13 -13
  339. package/dist/native-knowledge.d.ts +2 -1
  340. package/dist/offline-sync-impression-drain.d.ts +2 -1
  341. package/dist/offline-sync.js +2 -2
  342. package/dist/operator-doctor-corpus.d.ts +2 -1
  343. package/dist/operator-doctor-corpus.js +16 -16
  344. package/dist/operator-doctor-replica.d.ts +2 -1
  345. package/dist/operator-toolkit.d.ts +4 -3
  346. package/dist/operator-toolkit.js +29 -28
  347. package/dist/orchestration/compression-guideline-coordinator.d.ts +3 -2
  348. package/dist/orchestration/maintenance.d.ts +5 -4
  349. package/dist/orchestration/maintenance.js +21 -21
  350. package/dist/{orchestrator-Btq9lzAN.d.ts → orchestrator-DglY1H0w.d.ts} +8 -8
  351. package/dist/orchestrator.d.ts +10 -9
  352. package/dist/orchestrator.js +108 -97
  353. package/dist/patterns-cli.d.ts +2 -1
  354. package/dist/{pipeline-CZoNdFb5.d.ts → pipeline-C7qRsy6g.d.ts} +1 -1
  355. package/dist/policy-runtime.d.ts +2 -1
  356. package/dist/proactive-contention.d.ts +2 -1
  357. package/dist/provenance.d.ts +2 -1
  358. package/dist/{public-http-C9-CHc40.d.ts → public-http-CU-Cwwdb.d.ts} +1 -1
  359. package/dist/{qmd-VIjSCKIE.d.ts → qmd-YRLTa3AE.d.ts} +1 -1
  360. package/dist/qmd-preflight.d.ts +3 -2
  361. package/dist/qmd-recall-cache.d.ts +2 -1
  362. package/dist/qmd.d.ts +3 -2
  363. package/dist/recall-concurrency-config.d.ts +2 -1
  364. package/dist/recall-deep-expand-select.js +4 -44
  365. package/dist/recall-deep-expand-select.js.map +1 -1
  366. package/dist/recall-deep-frontier.js +4 -23
  367. package/dist/recall-deep-frontier.js.map +1 -1
  368. package/dist/recall-deep-rewrite.js +4 -23
  369. package/dist/recall-deep-rewrite.js.map +1 -1
  370. package/dist/recall-disclosure-escalation.d.ts +2 -1
  371. package/dist/recall-explain-renderer.d.ts +2 -1
  372. package/dist/recall-explain-renderer.js +3 -3
  373. package/dist/recall-memory-map.d.ts +2 -1
  374. package/dist/recall-navigate-access.d.ts +2 -1
  375. package/dist/recall-navigate-access.js +2 -2
  376. package/dist/recall-navigate-disclosure.d.ts +2 -1
  377. package/dist/recall-navigate-disclosure.js +1 -1
  378. package/dist/recall-navigate.d.ts +2 -1
  379. package/dist/recall-navigate.js +2 -2
  380. package/dist/recall-planner-llm.d.ts +2 -1
  381. package/dist/recall-state.d.ts +2 -1
  382. package/dist/recall-tag-filter.d.ts +2 -1
  383. package/dist/recall-timings.d.ts +2 -1
  384. package/dist/recall-xray-cli.d.ts +2 -1
  385. package/dist/recall-xray-cli.js +4 -4
  386. package/dist/recall-xray-renderer.d.ts +2 -1
  387. package/dist/recall-xray-renderer.js +3 -3
  388. package/dist/recall-xray.d.ts +2 -1
  389. package/dist/recall-xray.js +2 -2
  390. package/dist/reconcile/cursor.d.ts +2 -1
  391. package/dist/reconcile/manifest.d.ts +2 -1
  392. package/dist/reconcile/plan.d.ts +2 -1
  393. package/dist/replay/normalizers/chatgpt.d.ts +2 -1
  394. package/dist/replay/normalizers/claude.d.ts +2 -1
  395. package/dist/replay/normalizers/openclaw.d.ts +2 -1
  396. package/dist/replay/normalizers/shared.d.ts +2 -1
  397. package/dist/replay/runner.d.ts +2 -1
  398. package/dist/replay/types.d.ts +2 -1
  399. package/dist/replica-divergence.d.ts +2 -1
  400. package/dist/replica-peers-config.d.ts +2 -1
  401. package/dist/resolve-auth-token.d.ts +2 -1
  402. package/dist/resume-bundles.js +7 -6
  403. package/dist/retrieval-agents.d.ts +3 -2
  404. package/dist/retrieval-tiers.d.ts +2 -1
  405. package/dist/routing/engine.d.ts +2 -1
  406. package/dist/routing/store.d.ts +2 -1
  407. package/dist/salvage-envelope.d.ts +2 -1
  408. package/dist/schemas.d.ts +176 -176
  409. package/dist/{scope-profiles-DqbxQXIS.d.ts → scope-profiles-BVvqVzJX.d.ts} +1 -1
  410. package/dist/search/embed-helper.d.ts +2 -1
  411. package/dist/search/factory.d.ts +2 -1
  412. package/dist/search/factory.js +8 -8
  413. package/dist/search/index.d.ts +2 -1
  414. package/dist/search/index.js +13 -13
  415. package/dist/search/lancedb-backend.d.ts +2 -1
  416. package/dist/search/lancedb-backend.js +2 -2
  417. package/dist/search/meilisearch-backend.d.ts +2 -1
  418. package/dist/search/meilisearch-backend.js +2 -2
  419. package/dist/search/noop-backend.d.ts +2 -1
  420. package/dist/search/orama-backend.d.ts +2 -1
  421. package/dist/search/orama-backend.js +2 -2
  422. package/dist/search/port.d.ts +2 -1
  423. package/dist/search/remote-backend.d.ts +2 -1
  424. package/dist/{semantic-consolidation-DW3rEUoW.d.ts → semantic-consolidation-BzCI6Kuu.d.ts} +1 -1
  425. package/dist/semantic-consolidation.d.ts +3 -2
  426. package/dist/semantic-consolidation.js +14 -14
  427. package/dist/semantic-rule-promotion.js +13 -13
  428. package/dist/semantic-rule-verifier.d.ts +2 -1
  429. package/dist/semantic-rule-verifier.js +13 -13
  430. package/dist/{service-B2vJU_Bx.d.ts → service-DQ3Gscy5.d.ts} +2 -2
  431. package/dist/session-observer-bands.d.ts +2 -1
  432. package/dist/session-observer-state.d.ts +2 -1
  433. package/dist/shared-context/manager.d.ts +43 -7
  434. package/dist/shared-context/manager.js +2 -1
  435. package/dist/signal.d.ts +2 -1
  436. package/dist/source-agent-qualifier.d.ts +2 -1
  437. package/dist/source-agent-qualifier.js +13 -13
  438. package/dist/standup/build.js +13 -13
  439. package/dist/{storage-6fn7BPmb.d.ts → storage-DmTbQdD0.d.ts} +1 -1
  440. package/dist/storage.d.ts +3 -2
  441. package/dist/storage.js +12 -12
  442. package/dist/subject-config.d.ts +2 -1
  443. package/dist/summarizer.d.ts +2 -1
  444. package/dist/summary-snapshot.d.ts +2 -1
  445. package/dist/support-passport/index.d.ts +16 -14
  446. package/dist/support-passport/index.js +49 -37
  447. package/dist/temporal-supersession.d.ts +3 -2
  448. package/dist/temporal-timeline-recall.d.ts +2 -1
  449. package/dist/temporal-validity.d.ts +2 -1
  450. package/dist/threading.d.ts +2 -1
  451. package/dist/tier-migration.d.ts +3 -2
  452. package/dist/tier-routing.d.ts +2 -1
  453. package/dist/topics.d.ts +2 -1
  454. package/dist/transcript.d.ts +2 -1
  455. package/dist/transfer/capsule-export.js +2 -2
  456. package/dist/transfer/capsule-import.js +2 -2
  457. package/dist/transfer/export-okf.d.ts +2 -1
  458. package/dist/transfer/export-okf.js +14 -14
  459. package/dist/transfer/types.d.ts +78 -78
  460. package/dist/trust-score-stage.d.ts +2 -1
  461. package/dist/trust-score.d.ts +2 -1
  462. package/dist/{types-eM7QIcX2.d.ts → types-CLRTESSD.d.ts} +3 -1
  463. package/dist/types.d.ts +2 -1
  464. package/dist/types.js +1 -1
  465. package/dist/utility-runtime.d.ts +2 -1
  466. package/dist/verified-recall.js +13 -13
  467. package/dist/who-knows-cli.d.ts +13 -11
  468. package/dist/who-knows-cli.js +14 -14
  469. package/dist/who-knows.d.ts +13 -11
  470. package/dist/who-knows.js +13 -13
  471. package/dist/write-envelope.d.ts +2 -1
  472. package/package.json +2 -2
  473. package/src/access-boundary.ts +1 -0
  474. package/src/access-http.ts +5 -5
  475. package/src/access-mcp-output-schemas.ts +1 -0
  476. package/src/access-mcp.ts +3 -3
  477. package/src/access-operations-batch.ts +3 -1
  478. package/src/access-schema.ts +12 -0
  479. package/src/access-service.ts +162 -5
  480. package/src/access-surface-catalog.ts +2 -0
  481. package/src/cli/deep-recall-commands.ts +60 -0
  482. package/src/cli.ts +2 -2
  483. package/src/config.test.ts +19 -0
  484. package/src/config.ts +7 -0
  485. package/src/deep-recall-config.ts +83 -0
  486. package/src/deep-recall-http-glue.ts +75 -0
  487. package/src/deep-recall-mcp-tools.ts +33 -0
  488. package/src/deep-recall-policy-llm.ts +65 -0
  489. package/src/deep-recall-renderer.ts +41 -0
  490. package/src/deep-recall-seeds.ts +134 -0
  491. package/src/deep-recall-surface.test.ts +902 -0
  492. package/src/deep-recall.test.ts +348 -0
  493. package/src/deep-recall.ts +572 -0
  494. package/src/harmonic-retrieval.ts +78 -25
  495. package/src/mcp-read-only-tools.ts +1 -0
  496. package/src/shared-context/envelope-at.test.ts +23 -0
  497. package/src/shared-context/envelope-at.ts +12 -6
  498. package/src/shared-context/envelope-io.ts +184 -0
  499. package/src/shared-context/envelope-wiring.test.ts +193 -0
  500. package/src/shared-context/governance.ts +28 -9
  501. package/src/shared-context/iso-instant.ts +43 -0
  502. package/src/shared-context/manager.ts +74 -15
  503. package/src/shared-context/provenance.ts +3 -26
  504. package/src/shared-context/write-origin.test.ts +145 -0
  505. package/src/types.ts +3 -1
  506. package/dist/chunk-26JWBSWD.js.map +0 -1
  507. package/dist/chunk-3DT2F5OI.js.map +0 -1
  508. package/dist/chunk-4OFKZAJG.js.map +0 -1
  509. package/dist/chunk-6RPB2TDG.js.map +0 -1
  510. package/dist/chunk-AYWPIH4M.js.map +0 -1
  511. package/dist/chunk-HXWOVCS6.js.map +0 -1
  512. package/dist/chunk-IVAW3HBF.js.map +0 -1
  513. package/dist/chunk-K4E3Y3ZX.js.map +0 -1
  514. package/dist/chunk-QL4U3SJA.js.map +0 -1
  515. package/dist/chunk-TBRG2SYY.js.map +0 -1
  516. package/dist/chunk-VI637ILW.js.map +0 -1
  517. package/dist/chunk-XXW32OL7.js.map +0 -1
  518. /package/dist/{chunk-D5VPIJN3.js.map → chunk-227WJVPY.js.map} +0 -0
  519. /package/dist/{chunk-Y3BWCIY2.js.map → chunk-2EHDPHMD.js.map} +0 -0
  520. /package/dist/{chunk-2LKW6OO7.js.map → chunk-2XJDAEAM.js.map} +0 -0
  521. /package/dist/{chunk-P23JWI3D.js.map → chunk-3ITTF7YH.js.map} +0 -0
  522. /package/dist/{chunk-NGP2FPB2.js.map → chunk-4UVDLNHQ.js.map} +0 -0
  523. /package/dist/{chunk-FJMIQTMH.js.map → chunk-5YQ7RFSO.js.map} +0 -0
  524. /package/dist/{chunk-KQAFEZQX.js.map → chunk-7LCGFUMB.js.map} +0 -0
  525. /package/dist/{chunk-EESYTBXV.js.map → chunk-7NCUHD5U.js.map} +0 -0
  526. /package/dist/{chunk-X574KX52.js.map → chunk-7ZMU4XQT.js.map} +0 -0
  527. /package/dist/{chunk-SG3Z67FB.js.map → chunk-APZXA4WI.js.map} +0 -0
  528. /package/dist/{chunk-2QSZNTDO.js.map → chunk-AU7Q3LSC.js.map} +0 -0
  529. /package/dist/{chunk-VGMRI4J6.js.map → chunk-B75VCEX5.js.map} +0 -0
  530. /package/dist/{chunk-D35XLYQ7.js.map → chunk-BE4Y6GK6.js.map} +0 -0
  531. /package/dist/{chunk-ELKD5PCD.js.map → chunk-BEXFNGQ3.js.map} +0 -0
  532. /package/dist/{chunk-U5SRTYFS.js.map → chunk-BFDOBESV.js.map} +0 -0
  533. /package/dist/{chunk-OLT3YTDH.js.map → chunk-BIJAWZYW.js.map} +0 -0
  534. /package/dist/{chunk-FU2NYFX6.js.map → chunk-BO4PWIJY.js.map} +0 -0
  535. /package/dist/{chunk-JMAG7WZ7.js.map → chunk-BX6GW4KC.js.map} +0 -0
  536. /package/dist/{chunk-J2R275FN.js.map → chunk-CTCGHNWN.js.map} +0 -0
  537. /package/dist/{chunk-X5PIDJ3L.js.map → chunk-DA4ZMCBU.js.map} +0 -0
  538. /package/dist/{chunk-H6RSANGQ.js.map → chunk-ETZ7KKOS.js.map} +0 -0
  539. /package/dist/{chunk-XZBXINXZ.js.map → chunk-GIC6BASP.js.map} +0 -0
  540. /package/dist/{chunk-SXQZMC7R.js.map → chunk-GR4C3FHT.js.map} +0 -0
  541. /package/dist/{chunk-7DYGPGCT.js.map → chunk-H5IIBGDM.js.map} +0 -0
  542. /package/dist/{chunk-CNNXMIS6.js.map → chunk-HFRGCNFY.js.map} +0 -0
  543. /package/dist/{chunk-MAG6M3B6.js.map → chunk-HTOWFFAI.js.map} +0 -0
  544. /package/dist/{chunk-FOCMJEHH.js.map → chunk-I4QAH4SY.js.map} +0 -0
  545. /package/dist/{chunk-FSGCXGK6.js.map → chunk-I6DUKBUI.js.map} +0 -0
  546. /package/dist/{chunk-6FUMA6AA.js.map → chunk-JGXMA6HL.js.map} +0 -0
  547. /package/dist/{chunk-TA7UZZMW.js.map → chunk-JHTF22NQ.js.map} +0 -0
  548. /package/dist/{chunk-DZ3CNJPB.js.map → chunk-LDOQE34V.js.map} +0 -0
  549. /package/dist/{chunk-MEW53VQJ.js.map → chunk-LDWIPYJ6.js.map} +0 -0
  550. /package/dist/{chunk-227UFSEQ.js.map → chunk-LEPOP46W.js.map} +0 -0
  551. /package/dist/{chunk-KJTSWJZN.js.map → chunk-LF6SHWVV.js.map} +0 -0
  552. /package/dist/{chunk-G6OZZX7P.js.map → chunk-LJAP4KSW.js.map} +0 -0
  553. /package/dist/{chunk-NV6BTBUI.js.map → chunk-LJNLLNEM.js.map} +0 -0
  554. /package/dist/{chunk-FFFZEF6B.js.map → chunk-LUDXSSTW.js.map} +0 -0
  555. /package/dist/{chunk-PCH2CVCS.js.map → chunk-LWBSEYW3.js.map} +0 -0
  556. /package/dist/{chunk-FMUJGGKW.js.map → chunk-M7DGN6JZ.js.map} +0 -0
  557. /package/dist/{chunk-TZIHB2LP.js.map → chunk-MNH2GM4O.js.map} +0 -0
  558. /package/dist/{chunk-RACZB5HT.js.map → chunk-N37X5RU7.js.map} +0 -0
  559. /package/dist/{chunk-LK4TOYPU.js.map → chunk-NF3NMAG7.js.map} +0 -0
  560. /package/dist/{chunk-AG46P24C.js.map → chunk-NNBZS3DY.js.map} +0 -0
  561. /package/dist/{chunk-LZ2JTO7N.js.map → chunk-OASGWNYL.js.map} +0 -0
  562. /package/dist/{chunk-C2JCVZWX.js.map → chunk-OLBZ2WGG.js.map} +0 -0
  563. /package/dist/{chunk-Z3SQEEB6.js.map → chunk-OUKBMQ2O.js.map} +0 -0
  564. /package/dist/{chunk-2Z3DG5CQ.js.map → chunk-P6GKRT2H.js.map} +0 -0
  565. /package/dist/{chunk-UGA6PZTX.js.map → chunk-P7LVYPIX.js.map} +0 -0
  566. /package/dist/{chunk-VE45LRCE.js.map → chunk-QRDSXR3V.js.map} +0 -0
  567. /package/dist/{chunk-KS67VHXA.js.map → chunk-QUVWFZOU.js.map} +0 -0
  568. /package/dist/{chunk-AI4QFDPR.js.map → chunk-R7FXPG4T.js.map} +0 -0
  569. /package/dist/{chunk-X66BHMAU.js.map → chunk-RJ57OOCD.js.map} +0 -0
  570. /package/dist/{chunk-VXMKW7YN.js.map → chunk-TRLCMLX7.js.map} +0 -0
  571. /package/dist/{chunk-ELCMVOQT.js.map → chunk-V3HUBF7T.js.map} +0 -0
  572. /package/dist/{chunk-KMIAD7JR.js.map → chunk-VHAKBUBD.js.map} +0 -0
  573. /package/dist/{chunk-GS5IFIVE.js.map → chunk-VYD63IFH.js.map} +0 -0
  574. /package/dist/{chunk-WSFPNCRA.js.map → chunk-XFPHV65N.js.map} +0 -0
  575. /package/dist/{chunk-JCUG7AXZ.js.map → chunk-XJJYSX6F.js.map} +0 -0
  576. /package/dist/{chunk-I6DURYZI.js.map → chunk-XMIAU4CO.js.map} +0 -0
  577. /package/dist/{chunk-PJIGYPO5.js.map → chunk-XQGFIAG7.js.map} +0 -0
  578. /package/dist/{chunk-B2URC6LJ.js.map → chunk-YWN3GYI2.js.map} +0 -0
  579. /package/dist/{chunk-TG6JEJDV.js.map → chunk-Z33VUMKY.js.map} +0 -0
  580. /package/dist/{graph-edge-decay-DGTBFALQ.js.map → deep-recall-config.js.map} +0 -0
@@ -0,0 +1,572 @@
1
+ /**
2
+ * Budgeted deep-recall loop (issue #2332, harmonic series P4).
3
+ *
4
+ * REFINE / EXPAND / STOP retrieval over the abstraction-node + cue-anchor
5
+ * graph built by issue #2329, blended with QMD search. This is the deep
6
+ * surface ONLY — never wired into `before_prompt_build` or any recall
7
+ * section (that latency disqualifies the hot path; see the issue).
8
+ *
9
+ * The loop is dependency-injected: seeding, graph loading, memory loading,
10
+ * and the policy LLM call arrive as `DeepRecallDeps`, so the loop is
11
+ * deterministic under a scripted fake policy (tests) and thin when the
12
+ * access service wires real deps. Pure decision helpers are reused from
13
+ * the `recall-deep-*` primitives — never re-implemented here.
14
+ */
15
+
16
+ import { z } from "zod";
17
+ import type { AbstractionNode } from "./abstraction-nodes.js";
18
+ import type { CueAnchor } from "./cue-anchors.js";
19
+ import { compareDeterministicStrings } from "./deterministic-order.js";
20
+ import { extractJsonCandidates, stripCodeFences } from "./json-extract.js";
21
+ import { rankDeepRecallFrontier } from "./recall-deep-frontier.js";
22
+ import { selectExpandNodeIds } from "./recall-deep-expand-select.js";
23
+ import { validateRefineRewrite } from "./recall-deep-rewrite.js";
24
+ import type { DeepRecallConfig } from "./deep-recall-config.js";
25
+
26
+ export type { DeepRecallConfig } from "./deep-recall-config.js";
27
+
28
+ export interface DeepRecallEntry {
29
+ memoryId: string;
30
+ /** Trimmed to 500 chars for state rendering; full content only in final output. */
31
+ content: string;
32
+ /** Seed similarity, or expansion inheritance (parent score * 0.8). */
33
+ score: number;
34
+ origin: "seed" | "refine" | "expand";
35
+ /** anchorValue that linked the entry, when origin === "expand". */
36
+ viaAnchor?: string;
37
+ }
38
+
39
+ export interface DeepRecallFrontierItem {
40
+ nodeId: string;
41
+ title: string;
42
+ /** e.g. `shares anchor "<anchorValue>" with <memoryId>`. */
43
+ reason: string;
44
+ sharedAnchorCount: number;
45
+ /** Working-set memory the anchor was shared with; drives expansion scoring. */
46
+ parentMemoryId: string;
47
+ parentScore: number;
48
+ anchorValue: string;
49
+ }
50
+
51
+ export interface DeepRecallTraceStep {
52
+ step: number;
53
+ action: "REFINE" | "EXPAND" | "STOP" | "BUDGET_EXHAUSTED";
54
+ /** Rewritten query, chosen nodeIds, or stop reason. */
55
+ detail: string;
56
+ workingSetSize: number;
57
+ frontierSize: number;
58
+ durationMs: number;
59
+ }
60
+
61
+ export interface DeepRecallResult {
62
+ /** false only for backend failure — NEVER conflated with empty (§22). */
63
+ ok: boolean;
64
+ error?: "backend_unavailable" | "timeout" | "disabled";
65
+ entries: DeepRecallEntry[];
66
+ trace: DeepRecallTraceStep[];
67
+ }
68
+
69
+ export interface DeepRecallGraphSnapshot {
70
+ nodes: AbstractionNode[];
71
+ anchors: CueAnchor[];
72
+ }
73
+
74
+ export interface DeepRecallSeedHit {
75
+ memoryId: string;
76
+ score: number;
77
+ }
78
+
79
+ export type DeepRecallSeedResult =
80
+ | { ok: true; results: DeepRecallSeedHit[] }
81
+ | { ok: false; error: "backend_unavailable" };
82
+
83
+ export interface DeepRecallMemoryView {
84
+ memoryId: string;
85
+ content: string;
86
+ active: boolean;
87
+ }
88
+
89
+ export interface DeepRecallDeps {
90
+ config: DeepRecallConfig;
91
+ /** QMD (or equivalent) seed search. A thrown error means backend failure. */
92
+ searchSeed(query: string, limit: number): Promise<DeepRecallSeedHit[]>;
93
+ /** Nodes + anchors, loaded once per invocation. */
94
+ loadGraph(): Promise<DeepRecallGraphSnapshot>;
95
+ /** Namespace-scoped memory-by-id read; null when absent from the caller's namespace (§30). */
96
+ loadMemory(memoryId: string): Promise<DeepRecallMemoryView | null>;
97
+ /** Raw policy LLM output (JSON text); null when the call failed. */
98
+ callPolicy(statePrompt: string, timeoutMs: number): Promise<string | null>;
99
+ nowMs?(): number;
100
+ }
101
+
102
+ const PolicyActionSchema = z.object({
103
+ action: z.enum(["REFINE", "EXPAND", "STOP"]),
104
+ refinedQuery: z.string().optional().nullable(),
105
+ expandNodeIds: z.array(z.string()).optional().nullable(),
106
+ reason: z.string(),
107
+ });
108
+
109
+ type PolicyAction = z.infer<typeof PolicyActionSchema>;
110
+
111
+ const MAX_SOURCE_MEMORY_IDS_PER_NODE = 5;
112
+ const EXPAND_SCORE_INHERITANCE = 0.8;
113
+ const STATE_WORKING_SET_ENTRIES = 12;
114
+ const STATE_ENTRY_SNIPPET_CHARS = 200;
115
+
116
+ /** Thrown when the shared whole-invocation deadline expires mid-await. */
117
+ class DeepRecallDeadlineExceeded extends Error {
118
+ constructor() {
119
+ super("deep recall total timeout reached");
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Race one dependency call against the SHARED whole-invocation deadline.
125
+ *
126
+ * `deadlineMs` is an absolute instant computed once per invocation, so every
127
+ * await subtracts elapsed time instead of restarting the budget, and a stalled
128
+ * seed search, graph load, or memory read can no longer outlive the documented
129
+ * `totalTimeoutMs` just because the deadline is only *checked* between steps.
130
+ * An infinite deadline (`totalTimeoutMs: 0`, a documented disable value) passes
131
+ * the work through untouched — no timer, no wrapper.
132
+ */
133
+ async function withDeadline<T>(work: Promise<T>, deadlineMs: number, now: () => number): Promise<T> {
134
+ if (!Number.isFinite(deadlineMs)) return await work;
135
+ const remaining = deadlineMs - now();
136
+ if (remaining <= 0) throw new DeepRecallDeadlineExceeded();
137
+ // The timer stays REFERENCED: it is the only thing keeping the loop alive
138
+ // when the awaited dependency never settles, which is precisely the case the
139
+ // deadline exists for. It is always cleared in the `finally`.
140
+ const expiry = Promise.withResolvers<never>();
141
+ const timer = setTimeout(() => expiry.reject(new DeepRecallDeadlineExceeded()), remaining);
142
+ try {
143
+ return await Promise.race([work, expiry.promise]);
144
+ } finally {
145
+ clearTimeout(timer);
146
+ }
147
+ }
148
+
149
+ function parsePolicyOutput(raw: string | null): PolicyAction | null {
150
+ if (raw === null) return null;
151
+ const candidates = [stripCodeFences(raw), ...extractJsonCandidates(raw)];
152
+ for (const candidate of candidates) {
153
+ if (candidate.trim().length === 0) continue;
154
+ try {
155
+ const parsed = PolicyActionSchema.safeParse(JSON.parse(candidate));
156
+ if (parsed.success) return parsed.data;
157
+ } catch {
158
+ // try the next candidate
159
+ }
160
+ }
161
+ return null;
162
+ }
163
+
164
+ interface WorkingEntry extends DeepRecallEntry {
165
+ content: string;
166
+ }
167
+
168
+ function mergeIntoWorkingSet(
169
+ workingSet: Map<string, WorkingEntry>,
170
+ hits: readonly DeepRecallSeedHit[],
171
+ origin: "seed" | "refine",
172
+ contentFor: (memoryId: string) => string
173
+ ): void {
174
+ for (const hit of hits) {
175
+ if (typeof hit.memoryId !== "string" || hit.memoryId.length === 0) continue;
176
+ if (typeof hit.score !== "number" || !Number.isFinite(hit.score)) continue;
177
+ const existing = workingSet.get(hit.memoryId);
178
+ // Duplicates keep the higher score and the earlier origin (§13: one
179
+ // content form, one merge rule, everywhere).
180
+ if (existing && existing.score >= hit.score) continue;
181
+ workingSet.set(hit.memoryId, {
182
+ memoryId: hit.memoryId,
183
+ content: contentFor(hit.memoryId),
184
+ score: hit.score,
185
+ origin: existing ? existing.origin : origin,
186
+ ...(existing?.viaAnchor ? { viaAnchor: existing.viaAnchor } : {}),
187
+ });
188
+ }
189
+ }
190
+
191
+ interface FrontierIndex {
192
+ memoryIdToNodeIds: Map<string, string[]>;
193
+ nodeIdToNode: Map<string, AbstractionNode>;
194
+ nodeIdToAnchorIds: Map<string, string[]>;
195
+ anchorIdToAnchor: Map<string, CueAnchor>;
196
+ }
197
+
198
+ function buildFrontierIndex(graph: DeepRecallGraphSnapshot): FrontierIndex {
199
+ const memoryIdToNodeIds = new Map<string, string[]>();
200
+ const nodeIdToNode = new Map<string, AbstractionNode>();
201
+ for (const node of graph.nodes) {
202
+ nodeIdToNode.set(node.nodeId, node);
203
+ for (const memoryId of node.sourceMemoryIds ?? []) {
204
+ const list = memoryIdToNodeIds.get(memoryId) ?? [];
205
+ list.push(node.nodeId);
206
+ memoryIdToNodeIds.set(memoryId, list);
207
+ }
208
+ }
209
+ const nodeIdToAnchorIds = new Map<string, string[]>();
210
+ const anchorIdToAnchor = new Map<string, CueAnchor>();
211
+ for (const anchor of graph.anchors) {
212
+ anchorIdToAnchor.set(anchor.anchorId, anchor);
213
+ for (const nodeRef of anchor.nodeRefs) {
214
+ const list = nodeIdToAnchorIds.get(nodeRef) ?? [];
215
+ list.push(anchor.anchorId);
216
+ nodeIdToAnchorIds.set(nodeRef, list);
217
+ }
218
+ }
219
+ return { memoryIdToNodeIds, nodeIdToNode, nodeIdToAnchorIds, anchorIdToAnchor };
220
+ }
221
+
222
+ /**
223
+ * A candidate node adds nothing when every source memory the EXPAND path would
224
+ * load is already in the working set (or when it has none): offering it as an
225
+ * unretrieved candidate lets the policy burn steps re-expanding a node that can
226
+ * only re-add what is already present.
227
+ */
228
+ function nodeAddsNothing(node: AbstractionNode, workingSet: ReadonlyMap<string, WorkingEntry>): boolean {
229
+ return (node.sourceMemoryIds ?? [])
230
+ .slice(0, MAX_SOURCE_MEMORY_IDS_PER_NODE)
231
+ .every((memoryId) => workingSet.has(memoryId));
232
+ }
233
+
234
+ /**
235
+ * Frontier refresh (after every working-set change): for each working-set
236
+ * memory, anchors whose nodeRefs include a node listing that memory make
237
+ * every OTHER referenced node a frontier candidate. Ranked by the shared
238
+ * pure helper (shared-anchor count desc, nodeId asc — total comparator).
239
+ *
240
+ * Nodes in `expandedNodeIds` are dropped: a node EXPAND already followed is
241
+ * not an unretrieved candidate, even when some of its source memories never
242
+ * entered the working set (an inactive or foreign read is skipped), so
243
+ * re-offering it would let the policy spend every remaining step adding
244
+ * nothing.
245
+ */
246
+ function refreshFrontier(
247
+ workingSet: ReadonlyMap<string, WorkingEntry>,
248
+ graph: FrontierGraph,
249
+ expandedNodeIds: ReadonlySet<string>
250
+ ): DeepRecallFrontierItem[] {
251
+ const index = graph.index;
252
+ interface Candidate {
253
+ nodeId: string;
254
+ sharedAnchorCount: number;
255
+ parentMemoryId: string;
256
+ parentScore: number;
257
+ anchorValue: string;
258
+ }
259
+ const byNodeId = new Map<string, Candidate>();
260
+ for (const [memoryId, entry] of workingSet) {
261
+ for (const nodeId of index.memoryIdToNodeIds.get(memoryId) ?? []) {
262
+ for (const anchorId of index.nodeIdToAnchorIds.get(nodeId) ?? []) {
263
+ const anchor = index.anchorIdToAnchor.get(anchorId);
264
+ if (!anchor) continue;
265
+ for (const otherNodeRef of anchor.nodeRefs) {
266
+ if (otherNodeRef === nodeId) continue;
267
+ if (expandedNodeIds.has(otherNodeRef)) continue;
268
+ const otherNode = index.nodeIdToNode.get(otherNodeRef);
269
+ if (!otherNode || nodeAddsNothing(otherNode, workingSet)) continue;
270
+ const current = byNodeId.get(otherNodeRef);
271
+ if (current === undefined || entry.score > current.parentScore) {
272
+ byNodeId.set(otherNodeRef, {
273
+ nodeId: otherNodeRef,
274
+ sharedAnchorCount: (current?.sharedAnchorCount ?? 0) + 1,
275
+ parentMemoryId: memoryId,
276
+ parentScore: entry.score,
277
+ anchorValue: anchor.anchorValue,
278
+ });
279
+ } else {
280
+ current.sharedAnchorCount += 1;
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ const ranked = rankDeepRecallFrontier([...byNodeId.values()]);
287
+ return ranked.flatMap((rankedCandidate) => {
288
+ const candidate = byNodeId.get(rankedCandidate.nodeId);
289
+ const node = index.nodeIdToNode.get(rankedCandidate.nodeId);
290
+ if (!candidate || !node) return [];
291
+ return [
292
+ {
293
+ nodeId: candidate.nodeId,
294
+ title: node.title,
295
+ reason: `shares anchor "${candidate.anchorValue}" with ${candidate.parentMemoryId}`,
296
+ sharedAnchorCount: rankedCandidate.sharedAnchorCount,
297
+ parentMemoryId: candidate.parentMemoryId,
298
+ parentScore: candidate.parentScore,
299
+ anchorValue: candidate.anchorValue,
300
+ },
301
+ ];
302
+ });
303
+ }
304
+
305
+ interface FrontierGraph {
306
+ index: FrontierIndex;
307
+ }
308
+
309
+
310
+ function renderStatePrompt(input: {
311
+ query: string;
312
+ workingSet: ReadonlyMap<string, WorkingEntry>;
313
+ frontier: readonly DeepRecallFrontierItem[];
314
+ stepsRemaining: number;
315
+ }): string {
316
+ const lines: string[] = [
317
+ "You are guiding a multi-hop memory retrieval loop. Pick exactly one action.",
318
+ "REFINE when the retrieved memories look misaligned with the question (return a rewritten query).",
319
+ "EXPAND to follow named frontier nodes that plausibly hold the answer (return their nodeIds).",
320
+ "STOP when the working set is sufficient to answer.",
321
+ "",
322
+ `QUESTION: ${input.query}`,
323
+ `STEPS REMAINING: ${input.stepsRemaining}`,
324
+ "",
325
+ "WORKING SET (retrieved memories):",
326
+ ];
327
+ const entries = [...input.workingSet.values()]
328
+ .sort((a, b) => b.score - a.score || compareDeterministicStrings(a.memoryId, b.memoryId))
329
+ .slice(0, STATE_WORKING_SET_ENTRIES);
330
+ if (entries.length === 0) lines.push("(empty)");
331
+ for (const entry of entries) {
332
+ const snippet = entry.content.slice(0, STATE_ENTRY_SNIPPET_CHARS).replace(/\s+/g, " ");
333
+ lines.push(`- ${entry.memoryId} (score=${entry.score.toFixed(3)}, origin=${entry.origin}): ${snippet}`);
334
+ }
335
+ lines.push("", "FRONTIER (anchor-linked candidates not yet retrieved):");
336
+ if (input.frontier.length === 0) lines.push("(empty)");
337
+ for (const item of input.frontier) {
338
+ lines.push(`- ${item.nodeId}: ${item.title} — ${item.reason}`);
339
+ }
340
+ lines.push(
341
+ "",
342
+ 'Respond with JSON only: {"action":"REFINE","refinedQuery":"...","reason":"..."}',
343
+ 'or {"action":"EXPAND","expandNodeIds":["..."],"reason":"..."}',
344
+ 'or {"action":"STOP","reason":"..."}',
345
+ );
346
+ return lines.join("\n");
347
+ }
348
+
349
+ function finalRank(entries: readonly DeepRecallEntry[]): DeepRecallEntry[] {
350
+ return [...entries].sort(
351
+ (a, b) => b.score - a.score || compareDeterministicStrings(a.memoryId, b.memoryId)
352
+ );
353
+ }
354
+
355
+ /**
356
+ * The budgeted loop. Seed (QMD + graph) -> policy steps -> ranked, capped
357
+ * output. Only a SEED backend failure returns `ok: false`; timeout and
358
+ * budget exhaustion mid-loop return the partial working set with
359
+ * `ok: true` and a BUDGET_EXHAUSTED trace tail.
360
+ */
361
+ export async function runBudgetedDeepRecall(deps: DeepRecallDeps, query: string): Promise<DeepRecallResult> {
362
+ const cfg = deps.config;
363
+ const now = deps.nowMs ?? Date.now;
364
+ const startedMs = now();
365
+ const deadlineMs = cfg.totalTimeoutMs > 0 ? startedMs + cfg.totalTimeoutMs : Number.POSITIVE_INFINITY;
366
+
367
+ const trace: DeepRecallTraceStep[] = [];
368
+ const contentCache = new Map<string, string>();
369
+ const contentFor = (memoryId: string): string => contentCache.get(memoryId) ?? "";
370
+ const workingSet = new Map<string, WorkingEntry>();
371
+ let graph: FrontierGraph = { index: buildFrontierIndex({ nodes: [], anchors: [] }) };
372
+ // Nodes already followed by EXPAND leave the frontier for good.
373
+ const expandedNodeIds = new Set<string>();
374
+ /**
375
+ * Hydrate one working-set entry from `loadMemory`, DROPPING it when the read
376
+ * is missing or reports a non-active memory: QMD can still index a memory
377
+ * whose governance status moved out of the active set, and hydrating it
378
+ * would surface content the active-set check excluded.
379
+ */
380
+ const hydrateOrDrop = async (memoryId: string): Promise<void> => {
381
+ const memory = await withDeadline(deps.loadMemory(memoryId), deadlineMs, now);
382
+ if (!memory || !memory.active) {
383
+ workingSet.delete(memoryId);
384
+ contentCache.delete(memoryId);
385
+ return;
386
+ }
387
+ contentCache.set(memoryId, memory.content);
388
+ const entry = workingSet.get(memoryId);
389
+ if (entry) entry.content = memory.content;
390
+ };
391
+ // Pre-policy work (seed search, graph load, seed hydration) is bounded by the
392
+ // SAME deadline as the policy calls; exhausting it here yields the partial
393
+ // working set rather than blocking the later check from ever running.
394
+ let exhaustedDetail: string | null = null;
395
+ try {
396
+ const seedHits = await withDeadline(deps.searchSeed(query, cfg.maxResults), deadlineMs, now);
397
+ mergeIntoWorkingSet(workingSet, seedHits, "seed", contentFor);
398
+ } catch (err) {
399
+ if (!(err instanceof DeepRecallDeadlineExceeded)) {
400
+ // Seed backend failure is the only ok:false path (§22: an empty index
401
+ // proceeds; a thrown search does not).
402
+ return { ok: false, error: "backend_unavailable", entries: [], trace: [] };
403
+ }
404
+ exhaustedDetail = "total timeout reached during seed search";
405
+ }
406
+ if (exhaustedDetail === null) {
407
+ try {
408
+ graph = { index: buildFrontierIndex(await withDeadline(deps.loadGraph(), deadlineMs, now)) };
409
+ // Seed hydration also enforces the active set: a stale or non-active
410
+ // QMD hit leaves the working set instead of being hydrated in place.
411
+ for (const memoryId of [...workingSet.keys()]) {
412
+ await hydrateOrDrop(memoryId);
413
+ }
414
+ } catch (err) {
415
+ if (!(err instanceof DeepRecallDeadlineExceeded)) throw err;
416
+ exhaustedDetail = "total timeout reached loading the graph or hydrating seeds";
417
+ }
418
+ }
419
+
420
+ let frontier = refreshFrontier(workingSet, graph, expandedNodeIds);
421
+ let currentQuery = query;
422
+ let refinesUsed = 0;
423
+
424
+ const pushStep = (step: number, action: DeepRecallTraceStep["action"], detail: string, stepStartMs: number): void => {
425
+ trace.push({
426
+ step,
427
+ action,
428
+ detail,
429
+ workingSetSize: workingSet.size,
430
+ frontierSize: frontier.length,
431
+ durationMs: Math.max(0, now() - stepStartMs),
432
+ });
433
+ };
434
+
435
+ if (exhaustedDetail !== null) {
436
+ // Pre-policy work already spent the whole-invocation budget: report the
437
+ // partial working set (ok:true, §22) instead of starting a policy call
438
+ // that cannot finish inside the deadline.
439
+ pushStep(0, "BUDGET_EXHAUSTED", exhaustedDetail, startedMs);
440
+ } else if (cfg.maxSteps <= 0) {
441
+ // `maxSteps: 0` is a documented disable value (§33): seed-only retrieval,
442
+ // with no policy call at all. The zero check dominates the step threshold
443
+ // instead of relying on the loop condition falling through.
444
+ pushStep(0, "STOP", "policy loop disabled (maxSteps=0)", startedMs);
445
+ }
446
+ let step = 0;
447
+ try {
448
+ while (exhaustedDetail === null && cfg.maxSteps > 0 && step < cfg.maxSteps) {
449
+ const stepStartMs = now();
450
+ if (now() >= deadlineMs) {
451
+ pushStep(step, "BUDGET_EXHAUSTED", "total timeout reached before policy call", stepStartMs);
452
+ break;
453
+ }
454
+ // Two independent axes bound the policy call: its own per-step timeout and
455
+ // whatever is left of the shared deadline. `stepTimeoutMs: 0` disables only
456
+ // its own axis (§33) — a finite total budget still applies, so the call can
457
+ // never outlive `totalTimeoutMs`. `timeoutMs: 0` reaches the policy only
458
+ // when BOTH axes are disabled.
459
+ const stepBudgetMs = cfg.stepTimeoutMs > 0 ? cfg.stepTimeoutMs : Number.POSITIVE_INFINITY;
460
+ const effectiveBudgetMs = Math.min(stepBudgetMs, deadlineMs - now());
461
+ const timeoutMs = Number.isFinite(effectiveBudgetMs) ? Math.max(1, effectiveBudgetMs) : 0;
462
+ const raw = await withDeadline(
463
+ deps.callPolicy(
464
+ renderStatePrompt({ query: currentQuery, workingSet, frontier, stepsRemaining: cfg.maxSteps - step }),
465
+ timeoutMs
466
+ ),
467
+ deadlineMs,
468
+ now
469
+ );
470
+ const parsed = parsePolicyOutput(raw);
471
+ if (parsed === null) {
472
+ pushStep(step, "STOP", "invalid_policy_output", stepStartMs);
473
+ break;
474
+ }
475
+ if (parsed.action === "STOP") {
476
+ pushStep(step, "STOP", parsed.reason || "policy stop", stepStartMs);
477
+ break;
478
+ }
479
+ if (parsed.action === "REFINE") {
480
+ const rewrite = validateRefineRewrite({
481
+ currentQuery,
482
+ refinedQuery: parsed.refinedQuery ?? null,
483
+ refinesUsed,
484
+ });
485
+ if (!rewrite.ok) {
486
+ pushStep(step, "STOP", rewrite.reason, stepStartMs);
487
+ break;
488
+ }
489
+ currentQuery = rewrite.refinedQuery;
490
+ refinesUsed += 1;
491
+ try {
492
+ const refinedHits = await withDeadline(deps.searchSeed(currentQuery, cfg.maxResults), deadlineMs, now);
493
+ mergeIntoWorkingSet(workingSet, refinedHits, "refine", contentFor);
494
+ for (const hit of refinedHits) {
495
+ if (workingSet.has(hit.memoryId) && !contentCache.has(hit.memoryId)) {
496
+ await hydrateOrDrop(hit.memoryId);
497
+ }
498
+ }
499
+ } catch (err) {
500
+ // Re-search failure mid-loop is partial, not fatal (§22): the loop
501
+ // keeps what it has and the policy decides the next move. Deadline
502
+ // expiry is NOT a partial failure — it ends the invocation.
503
+ if (err instanceof DeepRecallDeadlineExceeded) throw err;
504
+ }
505
+ frontier = refreshFrontier(workingSet, graph, expandedNodeIds);
506
+ pushStep(step, "REFINE", currentQuery, stepStartMs);
507
+ step += 1;
508
+ continue;
509
+ }
510
+ // EXPAND. A configured ceiling of 0 is a documented no-op limit (§33):
511
+ // the action is honored but selects nothing.
512
+ const selection =
513
+ cfg.maxExpandPerStep <= 0
514
+ ? { ok: true as const, nodeIds: [] as string[], truncated: false }
515
+ : selectExpandNodeIds({
516
+ frontierIds: frontier.map((item) => item.nodeId),
517
+ requestedIds: parsed.expandNodeIds ?? [],
518
+ maxExpandPerStep: cfg.maxExpandPerStep,
519
+ });
520
+ if (!selection.ok) {
521
+ pushStep(step, "STOP", "invalid_policy_output", stepStartMs);
522
+ break;
523
+ }
524
+ const chosen = new Map(frontier.map((item) => [item.nodeId, item]));
525
+ for (const nodeId of selection.nodeIds) {
526
+ const item = chosen.get(nodeId);
527
+ const node = graph.index.nodeIdToNode.get(nodeId);
528
+ if (!item || !node) continue;
529
+ for (const memoryId of (node.sourceMemoryIds ?? []).slice(0, MAX_SOURCE_MEMORY_IDS_PER_NODE)) {
530
+ if (workingSet.has(memoryId)) continue;
531
+ const memory = await withDeadline(deps.loadMemory(memoryId), deadlineMs, now);
532
+ // Only active memories enter the working set (§41); a null read
533
+ // (foreign namespace, §30) skips the same way.
534
+ if (!memory || !memory.active) continue;
535
+ workingSet.set(memoryId, {
536
+ memoryId,
537
+ content: memory.content,
538
+ score: item.parentScore * EXPAND_SCORE_INHERITANCE,
539
+ origin: "expand",
540
+ viaAnchor: item.anchorValue,
541
+ });
542
+ contentCache.set(memoryId, memory.content);
543
+ }
544
+ expandedNodeIds.add(nodeId);
545
+ }
546
+ frontier = refreshFrontier(workingSet, graph, expandedNodeIds);
547
+ pushStep(step, "EXPAND", selection.nodeIds.join(", "), stepStartMs);
548
+ step += 1;
549
+ }
550
+ } catch (err) {
551
+ if (!(err instanceof DeepRecallDeadlineExceeded)) throw err;
552
+ // A dependency call inside a step outran the shared deadline: the per-step
553
+ // timeout is not the wall clock, so record exhaustion and keep the partial
554
+ // working set. durationMs spans the whole invocation.
555
+ pushStep(step, "BUDGET_EXHAUSTED", "total timeout reached mid-step", startedMs);
556
+ }
557
+
558
+ if (cfg.maxSteps > 0 && step >= cfg.maxSteps && trace[trace.length - 1]?.action !== "STOP") {
559
+ pushStep(step, "BUDGET_EXHAUSTED", "maxSteps policy calls reached", startedMs);
560
+ // durationMs for the exhaustion marker is the whole invocation so far.
561
+ const marker = trace[trace.length - 1];
562
+ if (marker) marker.durationMs = Math.max(0, now() - startedMs);
563
+ }
564
+
565
+ // Final output carries full content; the 200-char trim is state rendering only.
566
+ const entries = finalRank([...workingSet.values()]).map((entry) => ({ ...entry }));
567
+ return {
568
+ ok: true,
569
+ entries: cfg.maxResults > 0 ? entries.slice(0, cfg.maxResults) : [],
570
+ trace,
571
+ };
572
+ }