@remnic/core 10.0.167 → 10.0.169

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 (390) hide show
  1. package/dist/access-admin-ops-surface.js +139 -138
  2. package/dist/access-cli.js +139 -138
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-coding-context-resolution.js +11 -11
  5. package/dist/access-extraction-force-flush-preempt.js +139 -138
  6. package/dist/access-extraction-force-flush.js +139 -138
  7. package/dist/access-http-briefing.js +139 -138
  8. package/dist/access-http-query.js +139 -138
  9. package/dist/access-http.js +139 -138
  10. package/dist/access-identity-continuity-surface.js +139 -138
  11. package/dist/access-lcm-surface.js +139 -138
  12. package/dist/access-mcp.js +139 -138
  13. package/dist/access-observe-write-category.js +11 -11
  14. package/dist/access-observe-write-surface.js +139 -138
  15. package/dist/access-offline-manifest.js +9 -9
  16. package/dist/access-operations-batch.js +139 -138
  17. package/dist/access-operations.js +139 -138
  18. package/dist/access-recall-concurrency.js +139 -138
  19. package/dist/access-recall-excerpt-attribution.d.ts +19 -0
  20. package/dist/access-recall-excerpt-attribution.d.ts.map +1 -0
  21. package/dist/access-recall-excerpt-attribution.js +8 -0
  22. package/dist/access-recall-response.js +139 -138
  23. package/dist/access-recall-surface.d.ts.map +1 -1
  24. package/dist/access-recall-surface.js +139 -138
  25. package/dist/access-schema.js +10 -10
  26. package/dist/access-service.js +139 -138
  27. package/dist/active-recall.js +24 -24
  28. package/dist/adapters/index.js +4 -4
  29. package/dist/adapters/registry.js +2 -2
  30. package/dist/{auto-sync-L3M4RKJD.js → auto-sync-ACP5U5A3.js} +3 -3
  31. package/dist/binary-lifecycle/scanner.d.ts +2 -4
  32. package/dist/binary-lifecycle/scanner.d.ts.map +1 -1
  33. package/dist/briefing.js +13 -13
  34. package/dist/buffer-add-turns-bounded.d.ts +11 -1
  35. package/dist/buffer-add-turns-bounded.d.ts.map +1 -1
  36. package/dist/buffer-add-turns-bounded.js +3 -3
  37. package/dist/buffer-session-cap.d.ts +2 -2
  38. package/dist/buffer-session-cap.d.ts.map +1 -1
  39. package/dist/buffer-session-cap.js +1 -1
  40. package/dist/buffer.d.ts +3 -2
  41. package/dist/buffer.d.ts.map +1 -1
  42. package/dist/buffer.js +12 -12
  43. package/dist/bulk-import/index.d.ts +1 -1
  44. package/dist/bulk-import/index.d.ts.map +1 -1
  45. package/dist/bulk-import/index.js +3 -1
  46. package/dist/bulk-import/pipeline.d.ts +8 -0
  47. package/dist/bulk-import/pipeline.d.ts.map +1 -1
  48. package/dist/calibration.d.ts +19 -2
  49. package/dist/calibration.d.ts.map +1 -1
  50. package/dist/calibration.js +28 -5
  51. package/dist/calibration.js.map +1 -1
  52. package/dist/{capsule-crypto-GWVG7LGC.js → capsule-crypto-7FJQINUR.js} +2 -2
  53. package/dist/{capsule-merge-VHBRF65A.js → capsule-merge-BADOICNP.js} +2 -2
  54. package/dist/causal-behavior.js +2 -2
  55. package/dist/causal-chain.js +2 -2
  56. package/dist/causal-consolidation.js +17 -17
  57. package/dist/causal-retrieval.js +2 -2
  58. package/dist/causal-trajectory-graph.js +3 -3
  59. package/dist/causal-trajectory.js +1 -1
  60. package/dist/{chunk-OWHERGF2.js → chunk-2NLLXCJG.js} +2 -2
  61. package/dist/{chunk-IE2ZLO3R.js → chunk-32OTLNAU.js} +274 -248
  62. package/dist/chunk-32OTLNAU.js.map +1 -0
  63. package/dist/{chunk-L7SEYUHS.js → chunk-3I3NXB6X.js} +3 -3
  64. package/dist/{chunk-4NBUHYUV.js → chunk-3LADDLAF.js} +5 -5
  65. package/dist/{chunk-2DL3OFLD.js → chunk-45GEJRIG.js} +2 -2
  66. package/dist/{chunk-HSSERO3E.js → chunk-4P4GF76E.js} +8 -1
  67. package/dist/chunk-4P4GF76E.js.map +1 -0
  68. package/dist/{chunk-5BE3FLKL.js → chunk-5KDDAQ6K.js} +8 -8
  69. package/dist/{chunk-BPCR5DZP.js → chunk-62YZOQFR.js} +5 -5
  70. package/dist/chunk-62YZOQFR.js.map +1 -0
  71. package/dist/{chunk-HLWXCDUQ.js → chunk-63A2BU2B.js} +5 -5
  72. package/dist/{chunk-C5QYWM6F.js → chunk-7FPI5MFB.js} +5 -5
  73. package/dist/{chunk-ZX546Y3Y.js → chunk-7OYDFIL4.js} +2 -2
  74. package/dist/{chunk-CKZWLAHN.js → chunk-ACPFBVUD.js} +2 -2
  75. package/dist/{chunk-BKTCVXMK.js → chunk-AHOYKJ5X.js} +3 -3
  76. package/dist/{chunk-WEHSQBFR.js → chunk-AIF6V2OX.js} +9 -4
  77. package/dist/chunk-AIF6V2OX.js.map +1 -0
  78. package/dist/{chunk-FGT7CUYZ.js → chunk-ALTLOHO7.js} +2 -2
  79. package/dist/{chunk-FMFCQRDM.js → chunk-AUFPPBC3.js} +3 -3
  80. package/dist/{chunk-OAQRZ4SV.js → chunk-B5KTTWC7.js} +2 -2
  81. package/dist/{chunk-73TPOGS4.js → chunk-BFBS7OFQ.js} +9 -9
  82. package/dist/{chunk-QFTK6EDM.js → chunk-BFZFNXOC.js} +13 -13
  83. package/dist/{chunk-ZQUOUPP3.js → chunk-BHRPZBAH.js} +4 -4
  84. package/dist/{chunk-4L25GAYL.js → chunk-CX24SVLK.js} +2 -2
  85. package/dist/{chunk-YY57TRKN.js → chunk-D5ZLTLHF.js} +2 -2
  86. package/dist/{chunk-WEFFO2MJ.js → chunk-D6YCETHG.js} +2 -2
  87. package/dist/{chunk-ZDZJNXL6.js → chunk-DK2VBJ6Q.js} +4 -4
  88. package/dist/{chunk-VRHY7Y5A.js → chunk-DPL5VO5V.js} +3 -3
  89. package/dist/{chunk-LVGTH6IQ.js → chunk-E7ATID4Z.js} +11 -11
  90. package/dist/{chunk-CKELO7Q6.js → chunk-FHWX2REL.js} +2 -2
  91. package/dist/{chunk-CUPILBIP.js → chunk-FMIM36I4.js} +2 -2
  92. package/dist/{chunk-OWM2VWNX.js → chunk-FSXYBIEZ.js} +25 -24
  93. package/dist/chunk-FSXYBIEZ.js.map +1 -0
  94. package/dist/{chunk-A5UOREWD.js → chunk-FWTGO4NE.js} +2 -2
  95. package/dist/{chunk-3SL52JKD.js → chunk-FZVROZKC.js} +5 -5
  96. package/dist/{chunk-U3BCW7GX.js → chunk-G3RLCVJC.js} +3 -3
  97. package/dist/{chunk-UYIBNDQE.js → chunk-GF5NN3LE.js} +2 -2
  98. package/dist/{chunk-7OCKK5M5.js → chunk-GWY5ZFHP.js} +6 -6
  99. package/dist/{chunk-AL3TCNSJ.js → chunk-H3MLOQ7F.js} +24 -53
  100. package/dist/chunk-H3MLOQ7F.js.map +1 -0
  101. package/dist/{chunk-TNRGWJYT.js → chunk-H4IU24V5.js} +2 -2
  102. package/dist/{chunk-T4BT4FQN.js → chunk-HH6PXQ2B.js} +3 -3
  103. package/dist/{chunk-FEUWI5QH.js → chunk-HHPY5SSE.js} +2 -2
  104. package/dist/{chunk-OM5ESBES.js → chunk-HQPFACXO.js} +2 -2
  105. package/dist/{chunk-QLQUAVVP.js → chunk-I7WPLMUX.js} +16 -16
  106. package/dist/chunk-I7WPLMUX.js.map +1 -0
  107. package/dist/{chunk-IMULTENA.js → chunk-ID65XTF3.js} +2 -2
  108. package/dist/{chunk-WWQMZBDI.js → chunk-IJVU4ILJ.js} +4 -4
  109. package/dist/{chunk-GBSXTTLP.js → chunk-ITGAGNX5.js} +2 -2
  110. package/dist/chunk-IUGOGDCP.js +39 -0
  111. package/dist/chunk-IUGOGDCP.js.map +1 -0
  112. package/dist/{chunk-3PNJZTDV.js → chunk-JGGNUEVD.js} +2 -2
  113. package/dist/{chunk-YYXYZM2I.js → chunk-JN7OSQJR.js} +2 -2
  114. package/dist/{chunk-4D2EY4WM.js → chunk-K2DTHNDY.js} +6 -6
  115. package/dist/{chunk-TH6OYP6I.js → chunk-K36RMINQ.js} +3 -3
  116. package/dist/{chunk-OZKVVUJB.js → chunk-KIM5VNZN.js} +2 -2
  117. package/dist/{chunk-BFPQJNFZ.js → chunk-LXSDEPEK.js} +60 -11
  118. package/dist/{chunk-BFPQJNFZ.js.map → chunk-LXSDEPEK.js.map} +1 -1
  119. package/dist/{chunk-ZWDDY4WF.js → chunk-M7CFCRWJ.js} +2 -2
  120. package/dist/{chunk-QPFM6DHY.js → chunk-MTJFK42O.js} +2 -2
  121. package/dist/{chunk-RO5EGRAI.js → chunk-N3FRR6II.js} +2 -2
  122. package/dist/{chunk-UMEUU66X.js → chunk-O3OEVYUR.js} +2 -2
  123. package/dist/{chunk-J74YOBB3.js → chunk-PFR6ZKQI.js} +8 -8
  124. package/dist/{chunk-TAD6QMMD.js → chunk-PRC7SZYM.js} +2 -2
  125. package/dist/{chunk-LWZNSQN3.js → chunk-PUQQPLVV.js} +3 -3
  126. package/dist/{chunk-LWZNSQN3.js.map → chunk-PUQQPLVV.js.map} +1 -1
  127. package/dist/{chunk-GMO3BGOF.js → chunk-QC2MHZDD.js} +1 -1
  128. package/dist/{chunk-FOTFLHBN.js → chunk-QPLI7LUU.js} +3 -2
  129. package/dist/chunk-QPLI7LUU.js.map +1 -0
  130. package/dist/{chunk-2MWKUVHT.js → chunk-RK7SE3BL.js} +5 -5
  131. package/dist/{chunk-HDWISXFH.js → chunk-RVAPK2S7.js} +2 -2
  132. package/dist/{chunk-5PUZV73Z.js → chunk-SEIGLG62.js} +11 -11
  133. package/dist/{chunk-AVWOULJH.js → chunk-SH3GOZWK.js} +2 -2
  134. package/dist/{chunk-PFLN6TTW.js → chunk-T3MCVSUC.js} +2 -2
  135. package/dist/{chunk-WQUGCOKF.js → chunk-TFA6HPOA.js} +4 -4
  136. package/dist/{chunk-CLVILSBR.js → chunk-TGQW3AMK.js} +22 -22
  137. package/dist/{chunk-YZYAYUJQ.js → chunk-TLRIRISJ.js} +4 -4
  138. package/dist/{chunk-7VIJUZYW.js → chunk-TQ4CELUR.js} +3 -3
  139. package/dist/{chunk-5QDTZIGH.js → chunk-U7KP6QFU.js} +2 -2
  140. package/dist/{chunk-BUKK5SWA.js → chunk-UPD5XDJX.js} +5 -5
  141. package/dist/{chunk-BUKK5SWA.js.map → chunk-UPD5XDJX.js.map} +1 -1
  142. package/dist/{chunk-QVXEXGIM.js → chunk-VF6SC4OD.js} +2 -2
  143. package/dist/{chunk-EZG54YDS.js → chunk-VKXJQF5C.js} +2 -2
  144. package/dist/{chunk-RFLC6PKQ.js → chunk-VMRPLHEU.js} +2 -2
  145. package/dist/{chunk-U2PSE7MB.js → chunk-VPEIWMUT.js} +2 -2
  146. package/dist/{chunk-X67XNZ64.js → chunk-W4EJMMPP.js} +10 -10
  147. package/dist/{chunk-RB7NXZ2E.js → chunk-W4Q65VJL.js} +2 -2
  148. package/dist/{chunk-HDDRVXX4.js → chunk-W5LJ3SJ7.js} +2 -2
  149. package/dist/{chunk-W7N7NWG5.js → chunk-WCJQ3OUP.js} +2 -2
  150. package/dist/{chunk-JIF22AXI.js → chunk-WGKIXNLY.js} +5 -2
  151. package/dist/{chunk-JIF22AXI.js.map → chunk-WGKIXNLY.js.map} +1 -1
  152. package/dist/{chunk-FFWFFAP3.js → chunk-WI2WTIMY.js} +14 -8
  153. package/dist/chunk-WI2WTIMY.js.map +1 -0
  154. package/dist/{chunk-UVYI6VIX.js → chunk-X7Y7WX73.js} +1 -1
  155. package/dist/{chunk-22V3CMIW.js → chunk-XJTRIHTH.js} +8 -8
  156. package/dist/{chunk-SIONKXLU.js → chunk-XTRC6SSS.js} +14 -14
  157. package/dist/{chunk-SBRUTD5O.js → chunk-YSATDEBY.js} +5 -5
  158. package/dist/{chunk-3YOX2BQD.js → chunk-YWMCV5HL.js} +3 -3
  159. package/dist/{chunk-L272A5QW.js → chunk-YYDUBGUF.js} +30 -22
  160. package/dist/chunk-YYDUBGUF.js.map +1 -0
  161. package/dist/{chunk-6QWFZ3X5.js → chunk-ZA6CYFAK.js} +2 -2
  162. package/dist/cli.d.ts +1 -6
  163. package/dist/cli.d.ts.map +1 -1
  164. package/dist/cli.js +139 -138
  165. package/dist/coding/export-okf-codegraph.js +24 -24
  166. package/dist/coding/pre-action-gate.js +2 -2
  167. package/dist/compounding/engine.js +14 -14
  168. package/dist/config.js +24 -24
  169. package/dist/connectors/codex-marketplace.d.ts.map +1 -1
  170. package/dist/connectors/codex-materialize-runner.js +14 -14
  171. package/dist/connectors/codex-materialize.d.ts.map +1 -1
  172. package/dist/connectors/codex-materialize.js +1 -1
  173. package/dist/connectors/index.js +15 -15
  174. package/dist/consolidation-provenance-check.js +2 -2
  175. package/dist/convergence-refresh.js +15 -15
  176. package/dist/conversation-index/backend.js +2 -2
  177. package/dist/corpus-watermark.js +15 -15
  178. package/dist/deep-recall-http-glue.js +11 -11
  179. package/dist/embedding-fallback.js +2 -2
  180. package/dist/entity-retrieval.js +14 -14
  181. package/dist/event-order-recall.js +3 -3
  182. package/dist/explicit-capture.js +139 -138
  183. package/dist/extraction-judge.js +1 -1
  184. package/dist/extraction-normalization.js +1 -1
  185. package/dist/extraction-span-materialize.js +2 -2
  186. package/dist/extraction.js +27 -27
  187. package/dist/{graph-edge-decay-BC3IO2J4.js → graph-edge-decay-CXTNJ7IQ.js} +6 -6
  188. package/dist/graph-edge-decay-CXTNJ7IQ.js.map +1 -0
  189. package/dist/graph-jsonl.js +4 -4
  190. package/dist/graph-snapshot.js +4 -4
  191. package/dist/graph.js +5 -5
  192. package/dist/harmonic-retrieval.js +13 -13
  193. package/dist/index.js +198 -197
  194. package/dist/lcm/index.js +3 -3
  195. package/dist/local-llm.js +2 -2
  196. package/dist/location/index.js +14 -14
  197. package/dist/maintenance/memory-governance.js +13 -13
  198. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +13 -13
  199. package/dist/maintenance/rebuild-memory-projection-runner.js +15 -15
  200. package/dist/maintenance/rebuild-memory-projection.js +14 -14
  201. package/dist/memory-browse.js +5 -5
  202. package/dist/memory-controller.d.ts.map +1 -1
  203. package/dist/memory-controller.js +1 -1
  204. package/dist/namespaces/migrate.js +14 -14
  205. package/dist/namespaces/search.js +7 -7
  206. package/dist/namespaces/storage.d.ts.map +1 -1
  207. package/dist/namespaces/storage.js +13 -13
  208. package/dist/offline-sync-changeset-generations.js +4 -4
  209. package/dist/offline-sync-embedding-generation.js +3 -3
  210. package/dist/offline-sync-snapshot-stream.js +7 -7
  211. package/dist/offline-sync.js +6 -6
  212. package/dist/operator-doctor-corpus.js +16 -16
  213. package/dist/operator-toolkit.js +35 -35
  214. package/dist/orchestration/backlog-scheduler.d.ts +4 -0
  215. package/dist/orchestration/backlog-scheduler.d.ts.map +1 -1
  216. package/dist/orchestration/backlog-scheduler.js +150 -143
  217. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  218. package/dist/orchestration/buffer-drain-runner.js +140 -139
  219. package/dist/orchestration/extraction-persist-citation.d.ts +2 -2
  220. package/dist/orchestration/extraction-persist-citation.d.ts.map +1 -1
  221. package/dist/orchestration/extraction-persist.d.ts.map +1 -1
  222. package/dist/orchestration/maintenance.js +23 -23
  223. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  224. package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -1
  225. package/dist/orchestrator.d.ts.map +1 -1
  226. package/dist/orchestrator.js +141 -140
  227. package/dist/qmd.js +4 -4
  228. package/dist/recall-navigation.js +139 -138
  229. package/dist/recall-state-view-admission.js +5 -5
  230. package/dist/recall-state-view-packet.d.ts.map +1 -1
  231. package/dist/recall-state-view-packet.js +30 -8
  232. package/dist/recall-state-view-packet.js.map +1 -1
  233. package/dist/recall-why-service.js +5 -5
  234. package/dist/reconcile/manifest.js +2 -2
  235. package/dist/resume-bundles.js +25 -25
  236. package/dist/search/factory.js +6 -6
  237. package/dist/search/index.js +8 -8
  238. package/dist/semantic-consolidation.js +18 -18
  239. package/dist/semantic-rule-promotion.js +13 -13
  240. package/dist/semantic-rule-verifier.js +13 -13
  241. package/dist/source-agent-qualifier.js +18 -18
  242. package/dist/source-attribution.d.ts +3 -3
  243. package/dist/source-attribution.d.ts.map +1 -1
  244. package/dist/source-attribution.js +1 -1
  245. package/dist/standup/build.js +13 -13
  246. package/dist/storage.d.ts +1 -0
  247. package/dist/storage.d.ts.map +1 -1
  248. package/dist/storage.js +12 -12
  249. package/dist/summarizer.d.ts +7 -1
  250. package/dist/summarizer.d.ts.map +1 -1
  251. package/dist/summarizer.js +3 -3
  252. package/dist/support-passport/index.js +16 -16
  253. package/dist/transfer/autodetect.js +3 -3
  254. package/dist/transfer/backup.js +2 -2
  255. package/dist/transfer/capsule-export.js +3 -3
  256. package/dist/transfer/capsule-import.js +3 -3
  257. package/dist/transfer/export-okf.js +13 -13
  258. package/dist/transfer/import-json.js +2 -2
  259. package/dist/transfer/import-md.js +2 -2
  260. package/dist/transfer/types.d.ts +15 -3
  261. package/dist/transfer/types.d.ts.map +1 -1
  262. package/dist/transfer/types.js +3 -1
  263. package/dist/verified-recall.js +13 -13
  264. package/dist/who-knows-cli.js +14 -14
  265. package/dist/who-knows.js +13 -13
  266. package/package.json +2 -2
  267. package/src/access-cli.test.ts +9 -9
  268. package/src/access-recall-excerpt-attribution.ts +69 -0
  269. package/src/access-recall-surface.ts +26 -31
  270. package/src/access-service-raw-excerpt-read-gate.test.ts +192 -11
  271. package/src/backlog-scheduler.test.ts +31 -0
  272. package/src/binary-lifecycle/scanner.ts +35 -14
  273. package/src/buffer-add-turns-bounded.ts +16 -2
  274. package/src/buffer-session-cap.ts +4 -4
  275. package/src/buffer.ts +5 -5
  276. package/src/bulk-import/index.ts +1 -0
  277. package/src/bulk-import/pipeline.test.ts +31 -0
  278. package/src/bulk-import/pipeline.ts +14 -0
  279. package/src/calibration.ts +56 -4
  280. package/src/cli.ts +3 -23
  281. package/src/connectors/codex-marketplace-git.test.ts +267 -0
  282. package/src/connectors/codex-marketplace.ts +76 -13
  283. package/src/connectors/codex-materialize.ts +29 -55
  284. package/src/memory-controller.test.ts +11 -0
  285. package/src/memory-controller.ts +5 -1
  286. package/src/namespaces/storage.ts +1 -0
  287. package/src/orchestration/backlog-scheduler.ts +12 -3
  288. package/src/orchestration/extraction-persist-citation.ts +5 -3
  289. package/src/orchestration/extraction-persist.ts +15 -14
  290. package/src/orchestration/recall-internal.ts +2 -3
  291. package/src/orchestration/turn-ingestion-buffered.test.ts +52 -1
  292. package/src/orchestration/turn-ingestion-buffered.ts +26 -8
  293. package/src/orchestrator.ts +1 -0
  294. package/src/recall-state-view-packet.test.ts +40 -0
  295. package/src/recall-state-view-packet.ts +46 -9
  296. package/src/source-attribution.test.ts +57 -0
  297. package/src/source-attribution.ts +46 -43
  298. package/src/storage.ts +4 -3
  299. package/src/summarizer-shutdown.test.ts +49 -16
  300. package/src/summarizer.ts +13 -5
  301. package/src/testing/subjects/memory-maintenance.test.ts +293 -0
  302. package/src/transfer/capsule-export.ts +2 -1
  303. package/src/transfer/capsule-taxonomy-version.test.ts +70 -0
  304. package/src/transfer/types.ts +13 -3
  305. package/dist/chunk-AL3TCNSJ.js.map +0 -1
  306. package/dist/chunk-BPCR5DZP.js.map +0 -1
  307. package/dist/chunk-FFWFFAP3.js.map +0 -1
  308. package/dist/chunk-FOTFLHBN.js.map +0 -1
  309. package/dist/chunk-HSSERO3E.js.map +0 -1
  310. package/dist/chunk-IE2ZLO3R.js.map +0 -1
  311. package/dist/chunk-L272A5QW.js.map +0 -1
  312. package/dist/chunk-OWM2VWNX.js.map +0 -1
  313. package/dist/chunk-QLQUAVVP.js.map +0 -1
  314. package/dist/chunk-WEHSQBFR.js.map +0 -1
  315. /package/dist/{capsule-crypto-GWVG7LGC.js.map → access-recall-excerpt-attribution.js.map} +0 -0
  316. /package/dist/{auto-sync-L3M4RKJD.js.map → auto-sync-ACP5U5A3.js.map} +0 -0
  317. /package/dist/{graph-edge-decay-BC3IO2J4.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
  318. /package/dist/{capsule-merge-VHBRF65A.js.map → capsule-merge-BADOICNP.js.map} +0 -0
  319. /package/dist/{chunk-OWHERGF2.js.map → chunk-2NLLXCJG.js.map} +0 -0
  320. /package/dist/{chunk-L7SEYUHS.js.map → chunk-3I3NXB6X.js.map} +0 -0
  321. /package/dist/{chunk-4NBUHYUV.js.map → chunk-3LADDLAF.js.map} +0 -0
  322. /package/dist/{chunk-2DL3OFLD.js.map → chunk-45GEJRIG.js.map} +0 -0
  323. /package/dist/{chunk-5BE3FLKL.js.map → chunk-5KDDAQ6K.js.map} +0 -0
  324. /package/dist/{chunk-HLWXCDUQ.js.map → chunk-63A2BU2B.js.map} +0 -0
  325. /package/dist/{chunk-C5QYWM6F.js.map → chunk-7FPI5MFB.js.map} +0 -0
  326. /package/dist/{chunk-ZX546Y3Y.js.map → chunk-7OYDFIL4.js.map} +0 -0
  327. /package/dist/{chunk-CKZWLAHN.js.map → chunk-ACPFBVUD.js.map} +0 -0
  328. /package/dist/{chunk-BKTCVXMK.js.map → chunk-AHOYKJ5X.js.map} +0 -0
  329. /package/dist/{chunk-FGT7CUYZ.js.map → chunk-ALTLOHO7.js.map} +0 -0
  330. /package/dist/{chunk-FMFCQRDM.js.map → chunk-AUFPPBC3.js.map} +0 -0
  331. /package/dist/{chunk-OAQRZ4SV.js.map → chunk-B5KTTWC7.js.map} +0 -0
  332. /package/dist/{chunk-73TPOGS4.js.map → chunk-BFBS7OFQ.js.map} +0 -0
  333. /package/dist/{chunk-QFTK6EDM.js.map → chunk-BFZFNXOC.js.map} +0 -0
  334. /package/dist/{chunk-ZQUOUPP3.js.map → chunk-BHRPZBAH.js.map} +0 -0
  335. /package/dist/{chunk-4L25GAYL.js.map → chunk-CX24SVLK.js.map} +0 -0
  336. /package/dist/{chunk-YY57TRKN.js.map → chunk-D5ZLTLHF.js.map} +0 -0
  337. /package/dist/{chunk-WEFFO2MJ.js.map → chunk-D6YCETHG.js.map} +0 -0
  338. /package/dist/{chunk-ZDZJNXL6.js.map → chunk-DK2VBJ6Q.js.map} +0 -0
  339. /package/dist/{chunk-VRHY7Y5A.js.map → chunk-DPL5VO5V.js.map} +0 -0
  340. /package/dist/{chunk-LVGTH6IQ.js.map → chunk-E7ATID4Z.js.map} +0 -0
  341. /package/dist/{chunk-CKELO7Q6.js.map → chunk-FHWX2REL.js.map} +0 -0
  342. /package/dist/{chunk-CUPILBIP.js.map → chunk-FMIM36I4.js.map} +0 -0
  343. /package/dist/{chunk-A5UOREWD.js.map → chunk-FWTGO4NE.js.map} +0 -0
  344. /package/dist/{chunk-3SL52JKD.js.map → chunk-FZVROZKC.js.map} +0 -0
  345. /package/dist/{chunk-U3BCW7GX.js.map → chunk-G3RLCVJC.js.map} +0 -0
  346. /package/dist/{chunk-UYIBNDQE.js.map → chunk-GF5NN3LE.js.map} +0 -0
  347. /package/dist/{chunk-7OCKK5M5.js.map → chunk-GWY5ZFHP.js.map} +0 -0
  348. /package/dist/{chunk-TNRGWJYT.js.map → chunk-H4IU24V5.js.map} +0 -0
  349. /package/dist/{chunk-T4BT4FQN.js.map → chunk-HH6PXQ2B.js.map} +0 -0
  350. /package/dist/{chunk-FEUWI5QH.js.map → chunk-HHPY5SSE.js.map} +0 -0
  351. /package/dist/{chunk-OM5ESBES.js.map → chunk-HQPFACXO.js.map} +0 -0
  352. /package/dist/{chunk-IMULTENA.js.map → chunk-ID65XTF3.js.map} +0 -0
  353. /package/dist/{chunk-WWQMZBDI.js.map → chunk-IJVU4ILJ.js.map} +0 -0
  354. /package/dist/{chunk-GBSXTTLP.js.map → chunk-ITGAGNX5.js.map} +0 -0
  355. /package/dist/{chunk-3PNJZTDV.js.map → chunk-JGGNUEVD.js.map} +0 -0
  356. /package/dist/{chunk-YYXYZM2I.js.map → chunk-JN7OSQJR.js.map} +0 -0
  357. /package/dist/{chunk-4D2EY4WM.js.map → chunk-K2DTHNDY.js.map} +0 -0
  358. /package/dist/{chunk-TH6OYP6I.js.map → chunk-K36RMINQ.js.map} +0 -0
  359. /package/dist/{chunk-OZKVVUJB.js.map → chunk-KIM5VNZN.js.map} +0 -0
  360. /package/dist/{chunk-ZWDDY4WF.js.map → chunk-M7CFCRWJ.js.map} +0 -0
  361. /package/dist/{chunk-QPFM6DHY.js.map → chunk-MTJFK42O.js.map} +0 -0
  362. /package/dist/{chunk-RO5EGRAI.js.map → chunk-N3FRR6II.js.map} +0 -0
  363. /package/dist/{chunk-UMEUU66X.js.map → chunk-O3OEVYUR.js.map} +0 -0
  364. /package/dist/{chunk-J74YOBB3.js.map → chunk-PFR6ZKQI.js.map} +0 -0
  365. /package/dist/{chunk-TAD6QMMD.js.map → chunk-PRC7SZYM.js.map} +0 -0
  366. /package/dist/{chunk-GMO3BGOF.js.map → chunk-QC2MHZDD.js.map} +0 -0
  367. /package/dist/{chunk-2MWKUVHT.js.map → chunk-RK7SE3BL.js.map} +0 -0
  368. /package/dist/{chunk-HDWISXFH.js.map → chunk-RVAPK2S7.js.map} +0 -0
  369. /package/dist/{chunk-5PUZV73Z.js.map → chunk-SEIGLG62.js.map} +0 -0
  370. /package/dist/{chunk-AVWOULJH.js.map → chunk-SH3GOZWK.js.map} +0 -0
  371. /package/dist/{chunk-PFLN6TTW.js.map → chunk-T3MCVSUC.js.map} +0 -0
  372. /package/dist/{chunk-WQUGCOKF.js.map → chunk-TFA6HPOA.js.map} +0 -0
  373. /package/dist/{chunk-CLVILSBR.js.map → chunk-TGQW3AMK.js.map} +0 -0
  374. /package/dist/{chunk-YZYAYUJQ.js.map → chunk-TLRIRISJ.js.map} +0 -0
  375. /package/dist/{chunk-7VIJUZYW.js.map → chunk-TQ4CELUR.js.map} +0 -0
  376. /package/dist/{chunk-5QDTZIGH.js.map → chunk-U7KP6QFU.js.map} +0 -0
  377. /package/dist/{chunk-QVXEXGIM.js.map → chunk-VF6SC4OD.js.map} +0 -0
  378. /package/dist/{chunk-EZG54YDS.js.map → chunk-VKXJQF5C.js.map} +0 -0
  379. /package/dist/{chunk-RFLC6PKQ.js.map → chunk-VMRPLHEU.js.map} +0 -0
  380. /package/dist/{chunk-U2PSE7MB.js.map → chunk-VPEIWMUT.js.map} +0 -0
  381. /package/dist/{chunk-X67XNZ64.js.map → chunk-W4EJMMPP.js.map} +0 -0
  382. /package/dist/{chunk-RB7NXZ2E.js.map → chunk-W4Q65VJL.js.map} +0 -0
  383. /package/dist/{chunk-HDDRVXX4.js.map → chunk-W5LJ3SJ7.js.map} +0 -0
  384. /package/dist/{chunk-W7N7NWG5.js.map → chunk-WCJQ3OUP.js.map} +0 -0
  385. /package/dist/{chunk-UVYI6VIX.js.map → chunk-X7Y7WX73.js.map} +0 -0
  386. /package/dist/{chunk-22V3CMIW.js.map → chunk-XJTRIHTH.js.map} +0 -0
  387. /package/dist/{chunk-SIONKXLU.js.map → chunk-XTRC6SSS.js.map} +0 -0
  388. /package/dist/{chunk-SBRUTD5O.js.map → chunk-YSATDEBY.js.map} +0 -0
  389. /package/dist/{chunk-3YOX2BQD.js.map → chunk-YWMCV5HL.js.map} +0 -0
  390. /package/dist/{chunk-6QWFZ3X5.js.map → chunk-ZA6CYFAK.js.map} +0 -0
@@ -36,6 +36,7 @@ import { lastRecallTimingsFor } from "./recall-timings.js";
36
36
  import { SecureStoreLockedError } from "./secure-store/index.js";
37
37
  import { StorageManager } from "./index.js";
38
38
  import { DEFAULT_RECALL_DISCLOSURE, type MemoryFile, type RecallDisclosure, type RecallPlanMode, isRecallDisclosure } from "./types.js";
39
+ import { attributeRawExcerpts } from "./access-recall-excerpt-attribution.js";
39
40
  import {
40
41
  EngramAccessInputError,
41
42
  shapeMemorySummary,
@@ -380,9 +381,7 @@ export class AccessRecallSurface {
380
381
  const parts = qmdCollectionPathParts(memoryPath);
381
382
  const coldCollection =
382
383
  this.deps.orchestrator.config.qmdColdCollection ?? "openclaw-engram-cold";
383
- const collectionNamespace = parts
384
- ? collectionNamespaceFromPrefix(parts.collection)
385
- : null;
384
+ const collectionNamespace = parts ? collectionNamespaceFromPrefix(parts.collection) : null;
386
385
  const preferredAttempted = Boolean(
387
386
  preferredNamespace &&
388
387
  (!parts ||
@@ -490,9 +489,9 @@ export class AccessRecallSurface {
490
489
  };
491
490
 
492
491
  // Pre-fetch raw excerpts once when `disclosure === "raw"` so we don't
493
- // hit the LCM archive per-result (issue #677 PR 2/4). Excerpts are
494
- // attached to the first result; per-result attribution is reserved
495
- // for a future PR if/when the LCM index can be joined to memory ids.
492
+ // hit the LCM archive per-result (issue #677 PR 2/4). Each excerpt is
493
+ // attributed to the result whose provenance quote it contains (issue
494
+ // #3546); excerpts no result claims stay anchored to the first result.
496
495
  // Coerce `null` (non-raw disclosure) to `undefined` so the optional
497
496
  // serializer field is never explicitly `null`.
498
497
  // Namespace for the LCM `${namespace}:${sessionKey}` prefix: prefer the
@@ -523,6 +522,7 @@ export class AccessRecallSurface {
523
522
  : null,
524
523
  );
525
524
  const rawExcerpts = rawExcerptsResult ?? undefined;
525
+ const pending: Array<{ memory: MemoryFile; baseDir: string }> = [];
526
526
  for (const included of coerceIncludedMemories(snapshot)) {
527
527
  const memoryPath = included.path;
528
528
  if (!memoryPath) continue;
@@ -533,36 +533,36 @@ export class AccessRecallSurface {
533
533
  if (!resolved) continue;
534
534
  const { memory, baseDir } = resolved;
535
535
  seen.add(seenKey);
536
- results.push(
537
- this.deps.serializeMemorySummary(
538
- memory,
539
- baseDir,
540
- disclosure,
541
- // Attach the (possibly empty) raw excerpts to the first raw
542
- // result; subsequent results do not duplicate the array.
543
- results.length === 0 ? rawExcerpts : undefined,
544
- ),
545
- );
536
+ pending.push({ memory, baseDir });
546
537
  }
547
538
 
548
- if (results.length > 0) return results;
539
+ if (pending.length === 0) {
540
+ for (const memoryId of snapshot.memoryIds) {
541
+ const memory = await storage.getMemoryById(memoryId);
542
+ if (!memory || seen.has(memory.path)) continue;
543
+ seen.add(memory.path);
544
+ pending.push({ memory, baseDir: storageDir });
545
+ }
546
+ }
549
547
 
550
- for (const memoryId of snapshot.memoryIds) {
551
- const memory = await storage.getMemoryById(memoryId);
552
- if (!memory || seen.has(memory.path)) continue;
553
- seen.add(memory.path);
548
+ const attributed = attributeRawExcerpts(
549
+ pending.map((entry) => entry.memory),
550
+ rawExcerpts,
551
+ );
552
+ for (const [index, entry] of pending.entries()) {
554
553
  results.push(
555
554
  this.deps.serializeMemorySummary(
556
- memory,
557
- storageDir,
555
+ entry.memory,
556
+ entry.baseDir,
558
557
  disclosure,
559
- results.length === 0 ? rawExcerpts : undefined,
558
+ attributed[index],
560
559
  ),
561
560
  );
562
561
  }
563
562
  return results;
564
563
  }
565
564
 
565
+
566
566
  /**
567
567
  * Fetch raw transcript excerpts from the LCM archive for `disclosure ===
568
568
  * "raw"` recalls (issue #677 PR 2/4). Returns `null` for non-raw recall
@@ -614,10 +614,7 @@ export class AccessRecallSurface {
614
614
  context.namespace !== this.deps.orchestrator.config.defaultNamespace
615
615
  ? `${context.namespace}:${context.sessionKey}`
616
616
  : context.sessionKey;
617
- const lcmSessionIds =
618
- context.lcmSessionIds !== undefined
619
- ? context.lcmSessionIds
620
- : [legacyKey];
617
+ const lcmSessionIds = context.lcmSessionIds !== undefined ? context.lcmSessionIds : [legacyKey];
621
618
  // Cap the excerpt fanout so recall responses stay bounded. Five matches
622
619
  // is enough to anchor the model in the raw transcript without ballooning
623
620
  // token spend; raw is meant as the escape hatch, not the default. The cap
@@ -1005,9 +1002,7 @@ export class AccessRecallSurface {
1005
1002
  }
1006
1003
 
1007
1004
  const namespacesEnabled = resolveNamespaceCapabilities(this.deps.orchestrator.config).namespaces;
1008
- const requestedNamespace = request.namespace?.trim()
1009
- ? this.deps.resolveNamespace(request.namespace)
1010
- : undefined;
1005
+ const requestedNamespace = request.namespace?.trim() ? this.deps.resolveNamespace(request.namespace) : undefined;
1011
1006
  const authenticatedPrincipal = request.authenticatedPrincipal?.trim();
1012
1007
  const principal =
1013
1008
  authenticatedPrincipal
@@ -29,6 +29,7 @@ import { createHash } from "node:crypto";
29
29
  import test from "node:test";
30
30
 
31
31
  import { EngramAccessService } from "./access-service.js";
32
+ import type { EngramAccessRecallRequest } from "./access-service.js";
32
33
  import { CrossNamespaceBudget } from "./cross-namespace-budget.js";
33
34
  import { Orchestrator } from "./orchestrator.js";
34
35
  import type { LastRecallSnapshot } from "./recall-state.js";
@@ -39,7 +40,8 @@ import {
39
40
  projectTagProjectId,
40
41
  } from "./coding/coding-namespace.js";
41
42
  import type { StorageManager } from "./storage.js";
42
- import type { CodingContext, PluginConfig } from "./types.js";
43
+ import type { RecallExecResult } from "./access-recall-concurrency.js";
44
+ import type { CodingContext, MemoryFile, PluginConfig } from "./types.js";
43
45
 
44
46
  interface RawExcerptProbe {
45
47
  service: EngramAccessService;
@@ -62,6 +64,17 @@ function makeRawExcerptProbe(options: {
62
64
  snapshotNamespace: string;
63
65
  sessionContext?: CodingContext;
64
66
  sessionKey: string;
67
+ /** snapshot.memoryIds → getMemoryById fixtures (recall results path). */
68
+ memories?: ReadonlyMap<string, MemoryFile>;
69
+ /** Rows the LCM stub's `searchContextFull` returns. */
70
+ excerptRows?: Array<{
71
+ id: number;
72
+ turn_index: number;
73
+ role: string;
74
+ content: string;
75
+ session_id: string;
76
+ score: number;
77
+ }>;
65
78
  }): RawExcerptProbe {
66
79
  const searchSessionIds: Array<string | undefined> = [];
67
80
  const contexts = new Map<string, CodingContext>();
@@ -94,27 +107,27 @@ function makeRawExcerptProbe(options: {
94
107
  .update("what database are we using?")
95
108
  .digest("hex"),
96
109
  queryLen: 5,
97
- memoryIds: [],
110
+ memoryIds: [...(options.memories?.keys() ?? [])],
98
111
  namespace: options.snapshotNamespace,
99
112
  recallNamespaces: [options.snapshotNamespace],
100
113
  includedMemories: [],
101
114
  };
102
115
 
103
- const storage = {
116
+ const storage = probeCast<StorageManager>({
104
117
  dir: "/synthetic/remnic-raw-excerpt-read-gate/store",
105
118
  async readMemoryByPath() {
106
119
  return null;
107
120
  },
108
- async getMemoryById() {
109
- return null;
121
+ async getMemoryById(id: string) {
122
+ return options.memories?.get(id) ?? null;
110
123
  },
111
- } as unknown as StorageManager;
124
+ });
112
125
 
113
126
  const service = Object.create(
114
127
  EngramAccessService.prototype,
115
128
  ) as EngramAccessService;
116
129
 
117
- const orch = {
130
+ const orch = probeCast<Orchestrator>({
118
131
  config,
119
132
  getCodingContextForSession: (sk: string | undefined) =>
120
133
  (sk ? contexts.get(sk) : null) ?? null,
@@ -145,12 +158,12 @@ function makeRawExcerptProbe(options: {
145
158
  sessionId?: string,
146
159
  ) => {
147
160
  searchSessionIds.push(sessionId);
148
- return [];
161
+ return options.excerptRows ?? [];
149
162
  },
150
163
  },
151
- } as unknown as Orchestrator;
164
+ });
152
165
 
153
- (service as unknown as { orchestrator: Orchestrator }).orchestrator = orch;
166
+ probeCast<{ orchestrator: Orchestrator }>(service).orchestrator = orch;
154
167
 
155
168
  // `executeRecall` consults the cross-namespace budget; `Object.create` skips
156
169
  // the constructor that builds the real limiter, so install one. Budget is
@@ -166,8 +179,18 @@ function makeRawExcerptProbe(options: {
166
179
  return { service, searchSessionIds, contexts };
167
180
  }
168
181
 
182
+ /**
183
+ * Boundary cast for probe stubs: the one assertion lives inside this helper
184
+ * (with its SAFETY comment), so call sites carry no assertions at all.
185
+ */
186
+ function probeCast<T>(value: NonNullable<unknown>): T {
187
+ // SAFETY: test stubs implement exactly the members the path under test
188
+ // reads; the full production surface is intentionally not provided.
189
+ return value as T;
190
+ }
191
+
169
192
  type ExecuteRecallInternals = {
170
- executeRecall: (request: unknown) => Promise<unknown>;
193
+ executeRecall: (request: EngramAccessRecallRequest) => Promise<RecallExecResult>;
171
194
  };
172
195
 
173
196
  type RawExcerptInternals = {
@@ -499,3 +522,161 @@ test("scope-profile raw excerpts preserve successful sibling LCM keys when one k
499
522
  ],
500
523
  );
501
524
  });
525
+
526
+ // ──────────────────────────────────────────────────────────────────────
527
+ // #3546: raw excerpts are attributed per result via the memory's
528
+ // provenance quotes (#1575 `sources[].quote`), not glued to results[0].
529
+ // ──────────────────────────────────────────────────────────────────────
530
+
531
+ function attributionMemory(id: string, quote: string): MemoryFile {
532
+ return {
533
+ path: `/synthetic/store/${id}.md`,
534
+ content: `synthetic body ${id}`,
535
+ frontmatter: {
536
+ id,
537
+ category: "preference",
538
+ created: "2026-11-01T00:00:00Z",
539
+ updated: "2026-11-01T00:00:00Z",
540
+ source: "test",
541
+ confidence: 0.9,
542
+ confidenceTier: "explicit",
543
+ tags: ["fixture"],
544
+ sources: quote
545
+ ? [
546
+ {
547
+ sessionKey: SESSION_KEY,
548
+ observedAt: "2026-11-01T00:00:00Z",
549
+ quote,
550
+ },
551
+ ]
552
+ : [],
553
+ },
554
+ };
555
+ }
556
+
557
+ function excerptRow(id: number, turnIndex: number, content: string) {
558
+ return {
559
+ id,
560
+ turn_index: turnIndex,
561
+ role: "assistant",
562
+ content,
563
+ session_id: SESSION_KEY,
564
+ score: 1,
565
+ };
566
+ }
567
+
568
+ test("#3546: excerpts containing a result's provenance quote attach to that result, leftovers stay on the first", async () => {
569
+ const memA = attributionMemory("mem-a", "the alpha verbatim quote span");
570
+ const memB = attributionMemory("mem-b", "the beta verbatim quote span");
571
+ const rows = [
572
+ excerptRow(1, 3, "query-relevant turn with no provenance span"),
573
+ excerptRow(2, 4, "prefix the alpha verbatim quote span suffix"),
574
+ excerptRow(3, 5, "the beta verbatim quote span appears here"),
575
+ ];
576
+ const probe = makeRawExcerptProbe({
577
+ config: { principalFromSessionKeyRules: [{ match: "pi-geek:", principal: "pi-geek" }] },
578
+ snapshotNamespace: "pi-geek",
579
+ sessionKey: SESSION_KEY,
580
+ memories: new Map([
581
+ ["mem-a", memA],
582
+ ["mem-b", memB],
583
+ ]),
584
+ excerptRows: rows,
585
+ });
586
+
587
+ const { response } = await probeCast<ExecuteRecallInternals>(
588
+ probe.service,
589
+ ).executeRecall({
590
+ query: "what database are we using?",
591
+ sessionKey: SESSION_KEY,
592
+ authenticatedPrincipal: "pi-geek",
593
+ disclosure: "raw",
594
+ });
595
+
596
+ const [first, second] = response.results;
597
+ // mem-b's provenance quote lives in turn 5 — that excerpt belongs to mem-b.
598
+ assert.deepEqual(
599
+ second?.rawExcerpts?.map((e) => e.turnIndex),
600
+ [5],
601
+ "excerpt containing mem-b's provenance quote must attach to mem-b",
602
+ );
603
+ // mem-a matched turn 4; the unclaimed query-relevant turn 3 stays anchored
604
+ // to the first result — no excerpt is silently dropped.
605
+ assert.deepEqual(
606
+ first?.rawExcerpts?.map((e) => e.turnIndex),
607
+ [3, 4],
608
+ "first result keeps its own matches plus unattributed excerpts, in transcript order",
609
+ );
610
+ });
611
+
612
+ test("#3546: memories without provenance quotes claim nothing — excerpts fall back to the first result", async () => {
613
+ const probe = makeRawExcerptProbe({
614
+ config: { principalFromSessionKeyRules: [{ match: "pi-geek:", principal: "pi-geek" }] },
615
+ snapshotNamespace: "pi-geek",
616
+ sessionKey: SESSION_KEY,
617
+ memories: new Map([
618
+ ["mem-a", attributionMemory("mem-a", "")],
619
+ ["mem-b", attributionMemory("mem-b", "")],
620
+ ]),
621
+ excerptRows: [excerptRow(1, 3, "turn three"), excerptRow(2, 4, "turn four")],
622
+ });
623
+
624
+ const { response } = await probeCast<ExecuteRecallInternals>(
625
+ probe.service,
626
+ ).executeRecall({
627
+ query: "what database are we using?",
628
+ sessionKey: SESSION_KEY,
629
+ authenticatedPrincipal: "pi-geek",
630
+ disclosure: "raw",
631
+ });
632
+
633
+ assert.deepEqual(
634
+ response.results[0]?.rawExcerpts?.map((e) => e.turnIndex),
635
+ [3, 4],
636
+ "with no provenance quotes anywhere the whole set stays on the first result (pre-#3546 shape)",
637
+ );
638
+ assert.equal(
639
+ response.results[1]?.rawExcerpts,
640
+ undefined,
641
+ "second result carries no excerpts when nothing attributed to it",
642
+ );
643
+ });
644
+
645
+ test("#3546: quotes under the attribution length floor claim nothing", async () => {
646
+ // Kilos's review on the PR: a very short quote substring-matches
647
+ // unrelated transcript text. Quotes below the floor are ignored for
648
+ // attribution, so their excerpts keep the first-result fallback.
649
+ const probe = makeRawExcerptProbe({
650
+ config: { principalFromSessionKeyRules: [{ match: "pi-geek:", principal: "pi-geek" }] },
651
+ snapshotNamespace: "pi-geek",
652
+ sessionKey: SESSION_KEY,
653
+ memories: new Map([
654
+ ["mem-a", attributionMemory("mem-a", "")],
655
+ ["mem-b", attributionMemory("mem-b", "it")],
656
+ ]),
657
+ excerptRows: [
658
+ excerptRow(1, 3, "turn three"),
659
+ excerptRow(2, 4, "a turn where it happens"),
660
+ ],
661
+ });
662
+
663
+ const { response } = await probeCast<ExecuteRecallInternals>(
664
+ probe.service,
665
+ ).executeRecall({
666
+ query: "what database are we using?",
667
+ sessionKey: SESSION_KEY,
668
+ authenticatedPrincipal: "pi-geek",
669
+ disclosure: "raw",
670
+ });
671
+
672
+ assert.deepEqual(
673
+ response.results[1]?.rawExcerpts,
674
+ undefined,
675
+ "a two-char quote must not attribute the excerpt containing it",
676
+ );
677
+ assert.deepEqual(
678
+ response.results[0]?.rawExcerpts?.map((e) => e.turnIndex),
679
+ [3, 4],
680
+ "below-floor quotes keep the excerpt on the first result",
681
+ );
682
+ });
@@ -1293,6 +1293,37 @@ test("claims past the concurrency bound are re-listed on the next tick, in page
1293
1293
  }
1294
1294
  });
1295
1295
 
1296
+ test("a live session at its per-session turn cap drains ahead of an older claim backlog", async () => {
1297
+ const queue = new ExtractionQueueCoordinator(1);
1298
+ const claimKeys: string[] = [];
1299
+ for (let i = 1; i <= 17; i += 1) claimKeys.push("claim-" + String(i).padStart(2, "0"));
1300
+ const state: StubState = {
1301
+ counts: new Map([
1302
+ ["live-under-cap", { turns: 3, retainedTurns: 0 }],
1303
+ ["live-capped", { turns: 3, retainedTurns: 1 }],
1304
+ ]),
1305
+ claimed: new Set(claimKeys),
1306
+ claimTurns: new Map(claimKeys.map((key) => [key, 50])),
1307
+ claimedThisRun: new Set(),
1308
+ outcomes: [],
1309
+ drained: [],
1310
+ };
1311
+ const deps: BacklogSchedulerDeps = { ...makeDeps(state, queue), maxTurnsPerSession: () => 4 };
1312
+ const scheduler = new BacklogScheduler(deps, { pollMs: 3_600_000 });
1313
+ scheduler.start();
1314
+ try {
1315
+ // start() runs the first tick; a second tick runs once its drain settles.
1316
+ await scheduler.tickForTest();
1317
+ await scheduler.settleForTest();
1318
+ const drainedKeys = state.drained.map((entry) => entry.key);
1319
+ assert.equal(drainedKeys[0], "live-capped", "the capped live session takes the only slot before the claim page");
1320
+ assert.equal(drainedKeys[1], claimKeys[0], "once it is claimed and drained, the claim backlog drains in page order");
1321
+ assert.ok(!drainedKeys.includes("live-under-cap"), "an under-cap live session keeps waiting behind the claim page");
1322
+ } finally {
1323
+ await scheduler.stop();
1324
+ }
1325
+ });
1326
+
1296
1327
  // ── Provider-breaker churn guard ────────────────────────────────────────────
1297
1328
  //
1298
1329
  // While the shared provider breaker is OPEN inside its cooldown, a full
@@ -12,23 +12,44 @@ import crypto from "node:crypto";
12
12
  import type { BinaryLifecycleConfig, BinaryLifecycleManifest } from "./types.js";
13
13
 
14
14
  /**
15
- * Test whether a filename matches any of the provided glob patterns.
16
- * Supports simple `*.ext` patterns (the default scan patterns).
17
- * For more complex globs a proper library should be used; this covers
18
- * the 95% case without adding a dependency.
15
+ * Case-insensitive glob match of one filename (no directory part) against one
16
+ * pattern: `*` matches any run of characters, `?` exactly one, every other
17
+ * character itself, all over Unicode code points. Two-pointer backtracking, O(name x pattern) worst case and
18
+ * no regular expression, so a hostile pattern cannot blow up.
19
19
  */
20
- export function matchesPatterns(filename: string, patterns: string[]): boolean {
21
- const lower = filename.toLowerCase();
22
- for (const pattern of patterns) {
23
- // Simple *.ext matching
24
- if (pattern.startsWith("*.")) {
25
- const ext = pattern.slice(1).toLowerCase(); // e.g. ".png"
26
- if (lower.endsWith(ext)) return true;
27
- } else if (lower === pattern.toLowerCase()) {
28
- return true;
20
+ function globMatches(nameText: string, patternText: string): boolean {
21
+ const name = Array.from(nameText);
22
+ const pattern = Array.from(patternText);
23
+ let n = 0;
24
+ let p = 0;
25
+ let starP = -1;
26
+ let starN = 0;
27
+ while (n < name.length) {
28
+ const c = pattern[p];
29
+ if (c === "*") {
30
+ starP = p++;
31
+ starN = n;
32
+ } else if (p < pattern.length && (c === "?" || c === name[n])) {
33
+ p++;
34
+ n++;
35
+ } else if (starP >= 0) {
36
+ p = starP + 1;
37
+ n = ++starN;
38
+ } else {
39
+ return false;
29
40
  }
30
41
  }
31
- return false;
42
+ while (pattern[p] === "*") p++;
43
+ return p === pattern.length;
44
+ }
45
+
46
+ /**
47
+ * Test whether a filename matches any of the provided glob patterns
48
+ * (`*.png`, `IMG_*.jpg`, `scan-??.png`, or an exact name), case-insensitively.
49
+ */
50
+ export function matchesPatterns(filename: string, patterns: string[]): boolean {
51
+ const lower = filename.toLowerCase();
52
+ return patterns.some((pattern) => globMatches(lower, pattern.toLowerCase()));
32
53
  }
33
54
 
34
55
  /**
@@ -17,6 +17,13 @@ export type AddTurnsBoundedOutcome =
17
17
  | null
18
18
  | "duplicate";
19
19
 
20
+ /** Why a bounded batch was refused; the batch itself still resolves to null. */
21
+ export type BoundedAdmissionRefusal =
22
+ | { reason: "session_turn_cap"; bufferKey: string; maxTurnsPerSession: number }
23
+ | { reason: "session_entry_cap"; maxSessionEntries: number };
24
+
25
+ export type BoundedRefusalListener = (refusal: BoundedAdmissionRefusal) => void;
26
+
20
27
  export interface AddTurnsBoundedHost {
21
28
  readonly config: PluginConfig;
22
29
  readonly maxSessionEntries: number;
@@ -38,6 +45,7 @@ export async function addTurnsBoundedWithAdmissionKey(
38
45
  host: AddTurnsBoundedHost,
39
46
  batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
40
47
  admissionKey?: string,
48
+ onRefused?: BoundedRefusalListener,
41
49
  ): Promise<AddTurnsBoundedOutcome> {
42
50
  const pending = await host.enqueueMutation(async () => {
43
51
  await host.loadUnlocked();
@@ -51,7 +59,10 @@ export async function addTurnsBoundedWithAdmissionKey(
51
59
  }
52
60
  }
53
61
 
54
- if (refuseOverCapBatch((key) => host.peekEntry(key) ?? null, batches, resolveMaxTurnsPerSession(host.config.bufferMaxTurnsPerSession))) {
62
+ const maxTurnsPerSession = resolveMaxTurnsPerSession(host.config.bufferMaxTurnsPerSession);
63
+ const overCapKey = refuseOverCapBatch((key) => host.peekEntry(key) ?? null, batches, maxTurnsPerSession);
64
+ if (overCapKey !== null) {
65
+ onRefused?.({ reason: "session_turn_cap", bufferKey: overCapKey, maxTurnsPerSession });
55
66
  return host.ingress.refuseAll(additions);
56
67
  }
57
68
  const entries = host.state.entries ?? {};
@@ -67,7 +78,10 @@ export async function addTurnsBoundedWithAdmissionKey(
67
78
  if (requiredEvictions > 0) {
68
79
  const target = Math.max(0, host.maxSessionEntries - newKeys.length);
69
80
  const evicted = selectEvictedBufferKeys(entries, newKeys, target, EVICTION_HOOKS);
70
- if (newKeys.length > 0 && evicted.length < requiredEvictions) return host.ingress.refuseAll(additions);
81
+ if (newKeys.length > 0 && evicted.length < requiredEvictions) {
82
+ onRefused?.({ reason: "session_entry_cap", maxSessionEntries: host.maxSessionEntries });
83
+ return host.ingress.refuseAll(additions);
84
+ }
71
85
  for (const key of evicted) delete entries[key];
72
86
  host.persistence.markEvicted(evicted);
73
87
  }
@@ -31,19 +31,19 @@ export function refuseOverCapSingle(entry: BufferEntryState | null, maxTurns: nu
31
31
  return true;
32
32
  }
33
33
 
34
- /** Batch path: sums incoming turns per key across all batches, new keys included. */
34
+ /** Batch path: sums incoming turns per key across all batches, new keys included. Returns the first over-cap key. */
35
35
  export function refuseOverCapBatch(
36
36
  peekEntry: (key: string) => BufferEntryState | null,
37
37
  batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
38
38
  maxTurns: number,
39
- ): boolean {
39
+ ): string | null {
40
40
  const incomingByKey = new Map<string, number>();
41
41
  for (const batch of batches) incomingByKey.set(batch.bufferKey, (incomingByKey.get(batch.bufferKey) ?? 0) + batch.turns.length);
42
42
  for (const [bufferKey, incoming] of incomingByKey) {
43
43
  if (heldTurnCount(peekEntry(bufferKey)) + incoming > maxTurns) {
44
44
  warnTurnCapRefused(bufferKey, maxTurns);
45
- return true;
45
+ return bufferKey;
46
46
  }
47
47
  }
48
- return false;
48
+ return null;
49
49
  }
package/src/buffer.ts CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  } from "./buffer-turn-helpers.js";
37
37
  import { BufferAdmissionRefusedError, BufferSessionTurnRefusedError, canAdmitNewEntryUnlocked } from "./buffer-admission.js";
38
38
  import { BufferIngressCounters } from "./buffer-ingress-counters.js";
39
- import { addTurnsBoundedWithAdmissionKey, type AddTurnsBoundedHost } from "./buffer-add-turns-bounded.js";
39
+ import { addTurnsBoundedWithAdmissionKey, type AddTurnsBoundedHost, type BoundedRefusalListener } from "./buffer-add-turns-bounded.js";
40
40
  import { refuseOverCapSingle, resolveMaxTurnsPerSession, sessionTurnCapReached } from "./buffer-session-cap.js";
41
41
  export { BufferAdmissionRefusedError, BufferSessionTurnRefusedError } from "./buffer-admission.js";
42
42
  import type { AddTurnMutationResult, AddTurnOutcome, RetainedTurnCleanupOptions, TriggerDecision } from "./buffer-types.js";
@@ -541,18 +541,18 @@ export class SmartBuffer {
541
541
  }
542
542
 
543
543
  async addTurnsBounded(
544
- batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
544
+ batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[], onRefused?: BoundedRefusalListener,
545
545
  ): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null> {
546
- const result = await addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches);
546
+ const result = await addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches, undefined, onRefused);
547
547
  return result === "duplicate" ? null : result;
548
548
  }
549
549
 
550
550
  /** #3368 durable observe replay only; duplicate means the scoped client key already landed. */
551
551
  async addTurnsBoundedForObserveReplay(
552
552
  batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
553
- admissionKey: string,
553
+ admissionKey: string, onRefused?: BoundedRefusalListener,
554
554
  ): Promise<Array<{ bufferKey: string; turn: BufferTurn; outcome: AddTurnOutcome }> | null | "duplicate"> {
555
- return addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches, admissionKey.trim());
555
+ return addTurnsBoundedWithAdmissionKey(this.addTurnsBoundedHost(), batches, admissionKey.trim(), onRefused);
556
556
  }
557
557
 
558
558
  /** Free one slot only when an empty entry can be reclaimed. */
@@ -26,6 +26,7 @@ export {
26
26
  export {
27
27
  runBulkImportPipeline,
28
28
  formatBatchTranscript,
29
+ processBatchFromIngest,
29
30
  validateBatchSize,
30
31
  resolveBulkImportContext,
31
32
  type ProcessBatchFn,
@@ -4,6 +4,7 @@ import { describe, it } from "node:test";
4
4
  import {
5
5
  runBulkImportPipeline,
6
6
  formatBatchTranscript,
7
+ processBatchFromIngest,
7
8
  resolveBulkImportContext,
8
9
  validateBatchSize,
9
10
  type ProcessBatchContext,
@@ -443,3 +444,33 @@ describe("validateBatchSize", () => {
443
444
  );
444
445
  });
445
446
  });
447
+
448
+ describe("processBatchFromIngest (issue #3554)", () => {
449
+ const context: ProcessBatchContext = { dedup: true, trustLevel: "import" };
450
+
451
+ it("counts only the memories this batch persisted, not concurrent writes", async () => {
452
+ // Another extraction writing to the same root during this batch must not
453
+ // change the count: the result comes from the batch's own persistedCount.
454
+ const concurrentWrites: string[] = [];
455
+ const fn = processBatchFromIngest(async (turns) => {
456
+ concurrentWrites.push("facts/organic-a.md", "facts/organic-b.md");
457
+ assert.equal(turns.length, 2);
458
+ return { persistedCount: 1 };
459
+ });
460
+ const result = await fn([makeTurn(0), makeTurn(1)], context);
461
+ assert.equal(concurrentWrites.length, 2);
462
+ assert.deepEqual(result, { memoriesCreated: 1, duplicatesSkipped: 0 });
463
+ });
464
+
465
+ it("reports zero when the batch persisted nothing", async () => {
466
+ const fn = processBatchFromIngest(async () => ({ persistedCount: 0 }));
467
+ assert.deepEqual(await fn([makeTurn(0)], context), { memoriesCreated: 0, duplicatesSkipped: 0 });
468
+ });
469
+
470
+ it("propagates an ingest failure instead of reporting a count", async () => {
471
+ const fn = processBatchFromIngest(async () => {
472
+ throw new Error("extraction failed");
473
+ });
474
+ await assert.rejects(() => fn([makeTurn(0)], context), /extraction failed/);
475
+ });
476
+ });
@@ -36,6 +36,20 @@ export type ProcessBatchFn = (
36
36
  context: ProcessBatchContext,
37
37
  ) => Promise<ProcessBatchResult>;
38
38
 
39
+ /**
40
+ * Batch processor backed by an ingest call that reports what it persisted.
41
+ * `memoriesCreated` is the batch's own `persistedCount`, so concurrent
42
+ * extractions writing to the same memory root cannot inflate it (issue #3554).
43
+ */
44
+ export function processBatchFromIngest(
45
+ ingest: (turns: ImportTurn[]) => Promise<{ persistedCount: number }>,
46
+ ): ProcessBatchFn {
47
+ return async (turns) => {
48
+ const { persistedCount } = await ingest(turns);
49
+ return { memoriesCreated: persistedCount, duplicatesSkipped: 0 };
50
+ };
51
+ }
52
+
39
53
  export function validateBatchSize(value: number | undefined): number {
40
54
  if (value === undefined) return DEFAULT_BATCH_SIZE;
41
55
  if (typeof value !== "number" || !Number.isFinite(value)) {