@remnic/core 10.0.168 → 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 (376) hide show
  1. package/dist/access-admin-ops-surface.js +138 -137
  2. package/dist/access-cli.js +138 -137
  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 +138 -137
  6. package/dist/access-extraction-force-flush.js +138 -137
  7. package/dist/access-http-briefing.js +138 -137
  8. package/dist/access-http-query.js +138 -137
  9. package/dist/access-http.js +138 -137
  10. package/dist/access-identity-continuity-surface.js +138 -137
  11. package/dist/access-lcm-surface.js +138 -137
  12. package/dist/access-mcp.js +138 -137
  13. package/dist/access-observe-write-category.js +11 -11
  14. package/dist/access-observe-write-surface.js +138 -137
  15. package/dist/access-offline-manifest.js +9 -9
  16. package/dist/access-operations-batch.js +138 -137
  17. package/dist/access-operations.js +138 -137
  18. package/dist/access-recall-concurrency.js +138 -137
  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 +138 -137
  23. package/dist/access-recall-surface.d.ts.map +1 -1
  24. package/dist/access-recall-surface.js +138 -137
  25. package/dist/access-schema.js +10 -10
  26. package/dist/access-service.js +138 -137
  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/calibration.d.ts +19 -2
  44. package/dist/calibration.d.ts.map +1 -1
  45. package/dist/calibration.js +28 -5
  46. package/dist/calibration.js.map +1 -1
  47. package/dist/{capsule-crypto-GWVG7LGC.js → capsule-crypto-7FJQINUR.js} +2 -2
  48. package/dist/{capsule-merge-VHBRF65A.js → capsule-merge-BADOICNP.js} +2 -2
  49. package/dist/causal-behavior.js +2 -2
  50. package/dist/causal-chain.js +2 -2
  51. package/dist/causal-consolidation.js +17 -17
  52. package/dist/causal-retrieval.js +2 -2
  53. package/dist/causal-trajectory-graph.js +3 -3
  54. package/dist/causal-trajectory.js +1 -1
  55. package/dist/{chunk-OWHERGF2.js → chunk-2NLLXCJG.js} +2 -2
  56. package/dist/{chunk-D6BOOYNJ.js → chunk-32OTLNAU.js} +271 -237
  57. package/dist/chunk-32OTLNAU.js.map +1 -0
  58. package/dist/{chunk-L7SEYUHS.js → chunk-3I3NXB6X.js} +3 -3
  59. package/dist/{chunk-4NBUHYUV.js → chunk-3LADDLAF.js} +5 -5
  60. package/dist/{chunk-2DL3OFLD.js → chunk-45GEJRIG.js} +2 -2
  61. package/dist/{chunk-5BE3FLKL.js → chunk-5KDDAQ6K.js} +8 -8
  62. package/dist/{chunk-BPCR5DZP.js → chunk-62YZOQFR.js} +5 -5
  63. package/dist/chunk-62YZOQFR.js.map +1 -0
  64. package/dist/{chunk-HLWXCDUQ.js → chunk-63A2BU2B.js} +5 -5
  65. package/dist/{chunk-MOUSHJAR.js → chunk-7FPI5MFB.js} +5 -5
  66. package/dist/{chunk-ZX546Y3Y.js → chunk-7OYDFIL4.js} +2 -2
  67. package/dist/{chunk-CKZWLAHN.js → chunk-ACPFBVUD.js} +2 -2
  68. package/dist/{chunk-BKTCVXMK.js → chunk-AHOYKJ5X.js} +3 -3
  69. package/dist/{chunk-WEHSQBFR.js → chunk-AIF6V2OX.js} +9 -4
  70. package/dist/chunk-AIF6V2OX.js.map +1 -0
  71. package/dist/{chunk-FGT7CUYZ.js → chunk-ALTLOHO7.js} +2 -2
  72. package/dist/{chunk-FMFCQRDM.js → chunk-AUFPPBC3.js} +3 -3
  73. package/dist/{chunk-OAQRZ4SV.js → chunk-B5KTTWC7.js} +2 -2
  74. package/dist/{chunk-73TPOGS4.js → chunk-BFBS7OFQ.js} +9 -9
  75. package/dist/{chunk-QFTK6EDM.js → chunk-BFZFNXOC.js} +13 -13
  76. package/dist/{chunk-ZQUOUPP3.js → chunk-BHRPZBAH.js} +4 -4
  77. package/dist/{chunk-4L25GAYL.js → chunk-CX24SVLK.js} +2 -2
  78. package/dist/{chunk-YY57TRKN.js → chunk-D5ZLTLHF.js} +2 -2
  79. package/dist/{chunk-WEFFO2MJ.js → chunk-D6YCETHG.js} +2 -2
  80. package/dist/{chunk-ZDZJNXL6.js → chunk-DK2VBJ6Q.js} +4 -4
  81. package/dist/{chunk-VRHY7Y5A.js → chunk-DPL5VO5V.js} +3 -3
  82. package/dist/{chunk-LVGTH6IQ.js → chunk-E7ATID4Z.js} +11 -11
  83. package/dist/{chunk-CKELO7Q6.js → chunk-FHWX2REL.js} +2 -2
  84. package/dist/{chunk-CUPILBIP.js → chunk-FMIM36I4.js} +2 -2
  85. package/dist/{chunk-OWM2VWNX.js → chunk-FSXYBIEZ.js} +25 -24
  86. package/dist/chunk-FSXYBIEZ.js.map +1 -0
  87. package/dist/{chunk-A5UOREWD.js → chunk-FWTGO4NE.js} +2 -2
  88. package/dist/{chunk-3SL52JKD.js → chunk-FZVROZKC.js} +5 -5
  89. package/dist/{chunk-U3BCW7GX.js → chunk-G3RLCVJC.js} +3 -3
  90. package/dist/{chunk-UYIBNDQE.js → chunk-GF5NN3LE.js} +2 -2
  91. package/dist/{chunk-7OCKK5M5.js → chunk-GWY5ZFHP.js} +6 -6
  92. package/dist/{chunk-AL3TCNSJ.js → chunk-H3MLOQ7F.js} +24 -53
  93. package/dist/chunk-H3MLOQ7F.js.map +1 -0
  94. package/dist/{chunk-TNRGWJYT.js → chunk-H4IU24V5.js} +2 -2
  95. package/dist/{chunk-T4BT4FQN.js → chunk-HH6PXQ2B.js} +3 -3
  96. package/dist/{chunk-FEUWI5QH.js → chunk-HHPY5SSE.js} +2 -2
  97. package/dist/{chunk-OM5ESBES.js → chunk-HQPFACXO.js} +2 -2
  98. package/dist/{chunk-QLQUAVVP.js → chunk-I7WPLMUX.js} +16 -16
  99. package/dist/chunk-I7WPLMUX.js.map +1 -0
  100. package/dist/{chunk-IMULTENA.js → chunk-ID65XTF3.js} +2 -2
  101. package/dist/{chunk-WWQMZBDI.js → chunk-IJVU4ILJ.js} +4 -4
  102. package/dist/{chunk-GBSXTTLP.js → chunk-ITGAGNX5.js} +2 -2
  103. package/dist/chunk-IUGOGDCP.js +39 -0
  104. package/dist/chunk-IUGOGDCP.js.map +1 -0
  105. package/dist/{chunk-3PNJZTDV.js → chunk-JGGNUEVD.js} +2 -2
  106. package/dist/{chunk-YYXYZM2I.js → chunk-JN7OSQJR.js} +2 -2
  107. package/dist/{chunk-4D2EY4WM.js → chunk-K2DTHNDY.js} +6 -6
  108. package/dist/{chunk-TH6OYP6I.js → chunk-K36RMINQ.js} +3 -3
  109. package/dist/{chunk-OZKVVUJB.js → chunk-KIM5VNZN.js} +2 -2
  110. package/dist/{chunk-BFPQJNFZ.js → chunk-LXSDEPEK.js} +60 -11
  111. package/dist/{chunk-BFPQJNFZ.js.map → chunk-LXSDEPEK.js.map} +1 -1
  112. package/dist/{chunk-ZWDDY4WF.js → chunk-M7CFCRWJ.js} +2 -2
  113. package/dist/{chunk-QPFM6DHY.js → chunk-MTJFK42O.js} +2 -2
  114. package/dist/{chunk-RO5EGRAI.js → chunk-N3FRR6II.js} +2 -2
  115. package/dist/{chunk-UMEUU66X.js → chunk-O3OEVYUR.js} +2 -2
  116. package/dist/{chunk-J74YOBB3.js → chunk-PFR6ZKQI.js} +8 -8
  117. package/dist/{chunk-TAD6QMMD.js → chunk-PRC7SZYM.js} +2 -2
  118. package/dist/{chunk-LWZNSQN3.js → chunk-PUQQPLVV.js} +3 -3
  119. package/dist/{chunk-LWZNSQN3.js.map → chunk-PUQQPLVV.js.map} +1 -1
  120. package/dist/{chunk-GMO3BGOF.js → chunk-QC2MHZDD.js} +1 -1
  121. package/dist/{chunk-FOTFLHBN.js → chunk-QPLI7LUU.js} +3 -2
  122. package/dist/chunk-QPLI7LUU.js.map +1 -0
  123. package/dist/{chunk-2MWKUVHT.js → chunk-RK7SE3BL.js} +5 -5
  124. package/dist/{chunk-HDWISXFH.js → chunk-RVAPK2S7.js} +2 -2
  125. package/dist/{chunk-5PUZV73Z.js → chunk-SEIGLG62.js} +11 -11
  126. package/dist/{chunk-AVWOULJH.js → chunk-SH3GOZWK.js} +2 -2
  127. package/dist/{chunk-PFLN6TTW.js → chunk-T3MCVSUC.js} +2 -2
  128. package/dist/{chunk-WQUGCOKF.js → chunk-TFA6HPOA.js} +4 -4
  129. package/dist/{chunk-CLVILSBR.js → chunk-TGQW3AMK.js} +22 -22
  130. package/dist/{chunk-YZYAYUJQ.js → chunk-TLRIRISJ.js} +4 -4
  131. package/dist/{chunk-7VIJUZYW.js → chunk-TQ4CELUR.js} +3 -3
  132. package/dist/{chunk-5QDTZIGH.js → chunk-U7KP6QFU.js} +2 -2
  133. package/dist/{chunk-BUKK5SWA.js → chunk-UPD5XDJX.js} +5 -5
  134. package/dist/{chunk-BUKK5SWA.js.map → chunk-UPD5XDJX.js.map} +1 -1
  135. package/dist/{chunk-QVXEXGIM.js → chunk-VF6SC4OD.js} +2 -2
  136. package/dist/{chunk-EZG54YDS.js → chunk-VKXJQF5C.js} +2 -2
  137. package/dist/{chunk-RFLC6PKQ.js → chunk-VMRPLHEU.js} +2 -2
  138. package/dist/{chunk-U2PSE7MB.js → chunk-VPEIWMUT.js} +2 -2
  139. package/dist/{chunk-X67XNZ64.js → chunk-W4EJMMPP.js} +10 -10
  140. package/dist/{chunk-RB7NXZ2E.js → chunk-W4Q65VJL.js} +2 -2
  141. package/dist/{chunk-HDDRVXX4.js → chunk-W5LJ3SJ7.js} +2 -2
  142. package/dist/{chunk-W7N7NWG5.js → chunk-WCJQ3OUP.js} +2 -2
  143. package/dist/{chunk-JIF22AXI.js → chunk-WGKIXNLY.js} +5 -2
  144. package/dist/{chunk-JIF22AXI.js.map → chunk-WGKIXNLY.js.map} +1 -1
  145. package/dist/{chunk-FFWFFAP3.js → chunk-WI2WTIMY.js} +14 -8
  146. package/dist/chunk-WI2WTIMY.js.map +1 -0
  147. package/dist/{chunk-UVYI6VIX.js → chunk-X7Y7WX73.js} +1 -1
  148. package/dist/{chunk-22V3CMIW.js → chunk-XJTRIHTH.js} +8 -8
  149. package/dist/{chunk-SIONKXLU.js → chunk-XTRC6SSS.js} +14 -14
  150. package/dist/{chunk-SBRUTD5O.js → chunk-YSATDEBY.js} +5 -5
  151. package/dist/{chunk-3YOX2BQD.js → chunk-YWMCV5HL.js} +3 -3
  152. package/dist/{chunk-L272A5QW.js → chunk-YYDUBGUF.js} +30 -22
  153. package/dist/chunk-YYDUBGUF.js.map +1 -0
  154. package/dist/{chunk-6QWFZ3X5.js → chunk-ZA6CYFAK.js} +2 -2
  155. package/dist/cli.js +138 -137
  156. package/dist/coding/export-okf-codegraph.js +24 -24
  157. package/dist/coding/pre-action-gate.js +2 -2
  158. package/dist/compounding/engine.js +14 -14
  159. package/dist/config.js +24 -24
  160. package/dist/connectors/codex-marketplace.d.ts.map +1 -1
  161. package/dist/connectors/codex-materialize-runner.js +14 -14
  162. package/dist/connectors/codex-materialize.d.ts.map +1 -1
  163. package/dist/connectors/codex-materialize.js +1 -1
  164. package/dist/connectors/index.js +15 -15
  165. package/dist/consolidation-provenance-check.js +2 -2
  166. package/dist/convergence-refresh.js +15 -15
  167. package/dist/conversation-index/backend.js +2 -2
  168. package/dist/corpus-watermark.js +15 -15
  169. package/dist/deep-recall-http-glue.js +11 -11
  170. package/dist/embedding-fallback.js +2 -2
  171. package/dist/entity-retrieval.js +14 -14
  172. package/dist/event-order-recall.js +3 -3
  173. package/dist/explicit-capture.js +138 -137
  174. package/dist/extraction-judge.js +1 -1
  175. package/dist/extraction-normalization.js +1 -1
  176. package/dist/extraction-span-materialize.js +2 -2
  177. package/dist/extraction.js +27 -27
  178. package/dist/{graph-edge-decay-BC3IO2J4.js → graph-edge-decay-CXTNJ7IQ.js} +6 -6
  179. package/dist/graph-edge-decay-CXTNJ7IQ.js.map +1 -0
  180. package/dist/graph-jsonl.js +4 -4
  181. package/dist/graph-snapshot.js +4 -4
  182. package/dist/graph.js +5 -5
  183. package/dist/harmonic-retrieval.js +13 -13
  184. package/dist/index.js +197 -196
  185. package/dist/lcm/index.js +3 -3
  186. package/dist/local-llm.js +2 -2
  187. package/dist/location/index.js +14 -14
  188. package/dist/maintenance/memory-governance.js +13 -13
  189. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +13 -13
  190. package/dist/maintenance/rebuild-memory-projection-runner.js +15 -15
  191. package/dist/maintenance/rebuild-memory-projection.js +14 -14
  192. package/dist/memory-browse.js +5 -5
  193. package/dist/memory-controller.d.ts.map +1 -1
  194. package/dist/memory-controller.js +1 -1
  195. package/dist/namespaces/migrate.js +14 -14
  196. package/dist/namespaces/search.js +7 -7
  197. package/dist/namespaces/storage.d.ts.map +1 -1
  198. package/dist/namespaces/storage.js +13 -13
  199. package/dist/offline-sync-changeset-generations.js +4 -4
  200. package/dist/offline-sync-embedding-generation.js +3 -3
  201. package/dist/offline-sync-snapshot-stream.js +7 -7
  202. package/dist/offline-sync.js +6 -6
  203. package/dist/operator-doctor-corpus.js +16 -16
  204. package/dist/operator-toolkit.js +35 -35
  205. package/dist/orchestration/backlog-scheduler.d.ts +4 -0
  206. package/dist/orchestration/backlog-scheduler.d.ts.map +1 -1
  207. package/dist/orchestration/backlog-scheduler.js +149 -142
  208. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  209. package/dist/orchestration/buffer-drain-runner.js +139 -138
  210. package/dist/orchestration/extraction-persist-citation.d.ts +2 -2
  211. package/dist/orchestration/extraction-persist-citation.d.ts.map +1 -1
  212. package/dist/orchestration/extraction-persist.d.ts.map +1 -1
  213. package/dist/orchestration/maintenance.js +23 -23
  214. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  215. package/dist/orchestration/turn-ingestion-buffered.d.ts.map +1 -1
  216. package/dist/orchestrator.d.ts.map +1 -1
  217. package/dist/orchestrator.js +140 -139
  218. package/dist/qmd.js +4 -4
  219. package/dist/recall-navigation.js +138 -137
  220. package/dist/recall-state-view-admission.js +5 -5
  221. package/dist/recall-state-view-packet.d.ts.map +1 -1
  222. package/dist/recall-state-view-packet.js +30 -8
  223. package/dist/recall-state-view-packet.js.map +1 -1
  224. package/dist/recall-why-service.js +5 -5
  225. package/dist/reconcile/manifest.js +2 -2
  226. package/dist/resume-bundles.js +25 -25
  227. package/dist/search/factory.js +6 -6
  228. package/dist/search/index.js +8 -8
  229. package/dist/semantic-consolidation.js +18 -18
  230. package/dist/semantic-rule-promotion.js +13 -13
  231. package/dist/semantic-rule-verifier.js +13 -13
  232. package/dist/source-agent-qualifier.js +18 -18
  233. package/dist/source-attribution.d.ts +3 -3
  234. package/dist/source-attribution.d.ts.map +1 -1
  235. package/dist/source-attribution.js +1 -1
  236. package/dist/standup/build.js +13 -13
  237. package/dist/storage.d.ts +1 -0
  238. package/dist/storage.d.ts.map +1 -1
  239. package/dist/storage.js +12 -12
  240. package/dist/summarizer.d.ts +7 -1
  241. package/dist/summarizer.d.ts.map +1 -1
  242. package/dist/summarizer.js +3 -3
  243. package/dist/support-passport/index.js +16 -16
  244. package/dist/transfer/autodetect.js +3 -3
  245. package/dist/transfer/backup.js +2 -2
  246. package/dist/transfer/capsule-export.js +3 -3
  247. package/dist/transfer/capsule-import.js +3 -3
  248. package/dist/transfer/export-okf.js +13 -13
  249. package/dist/transfer/import-json.js +2 -2
  250. package/dist/transfer/import-md.js +2 -2
  251. package/dist/transfer/types.d.ts +15 -3
  252. package/dist/transfer/types.d.ts.map +1 -1
  253. package/dist/transfer/types.js +3 -1
  254. package/dist/verified-recall.js +13 -13
  255. package/dist/who-knows-cli.js +14 -14
  256. package/dist/who-knows.js +13 -13
  257. package/package.json +2 -2
  258. package/src/access-cli.test.ts +9 -9
  259. package/src/access-recall-excerpt-attribution.ts +69 -0
  260. package/src/access-recall-surface.ts +23 -21
  261. package/src/access-service-raw-excerpt-read-gate.test.ts +192 -11
  262. package/src/backlog-scheduler.test.ts +31 -0
  263. package/src/binary-lifecycle/scanner.ts +35 -14
  264. package/src/buffer-add-turns-bounded.ts +16 -2
  265. package/src/buffer-session-cap.ts +4 -4
  266. package/src/buffer.ts +5 -5
  267. package/src/calibration.ts +56 -4
  268. package/src/connectors/codex-marketplace-git.test.ts +267 -0
  269. package/src/connectors/codex-marketplace.ts +76 -13
  270. package/src/connectors/codex-materialize.ts +29 -55
  271. package/src/memory-controller.test.ts +11 -0
  272. package/src/memory-controller.ts +5 -1
  273. package/src/namespaces/storage.ts +1 -0
  274. package/src/orchestration/backlog-scheduler.ts +12 -3
  275. package/src/orchestration/extraction-persist-citation.ts +5 -3
  276. package/src/orchestration/extraction-persist.ts +15 -14
  277. package/src/orchestration/recall-internal.ts +2 -3
  278. package/src/orchestration/turn-ingestion-buffered.test.ts +52 -1
  279. package/src/orchestration/turn-ingestion-buffered.ts +26 -8
  280. package/src/orchestrator.ts +1 -0
  281. package/src/recall-state-view-packet.test.ts +40 -0
  282. package/src/recall-state-view-packet.ts +46 -9
  283. package/src/source-attribution.test.ts +57 -0
  284. package/src/source-attribution.ts +46 -43
  285. package/src/storage.ts +4 -3
  286. package/src/summarizer-shutdown.test.ts +49 -16
  287. package/src/summarizer.ts +13 -5
  288. package/src/testing/subjects/memory-maintenance.test.ts +293 -0
  289. package/src/transfer/capsule-export.ts +2 -1
  290. package/src/transfer/capsule-taxonomy-version.test.ts +70 -0
  291. package/src/transfer/types.ts +13 -3
  292. package/dist/chunk-AL3TCNSJ.js.map +0 -1
  293. package/dist/chunk-BPCR5DZP.js.map +0 -1
  294. package/dist/chunk-D6BOOYNJ.js.map +0 -1
  295. package/dist/chunk-FFWFFAP3.js.map +0 -1
  296. package/dist/chunk-FOTFLHBN.js.map +0 -1
  297. package/dist/chunk-L272A5QW.js.map +0 -1
  298. package/dist/chunk-OWM2VWNX.js.map +0 -1
  299. package/dist/chunk-QLQUAVVP.js.map +0 -1
  300. package/dist/chunk-WEHSQBFR.js.map +0 -1
  301. /package/dist/{capsule-crypto-GWVG7LGC.js.map → access-recall-excerpt-attribution.js.map} +0 -0
  302. /package/dist/{auto-sync-L3M4RKJD.js.map → auto-sync-ACP5U5A3.js.map} +0 -0
  303. /package/dist/{graph-edge-decay-BC3IO2J4.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
  304. /package/dist/{capsule-merge-VHBRF65A.js.map → capsule-merge-BADOICNP.js.map} +0 -0
  305. /package/dist/{chunk-OWHERGF2.js.map → chunk-2NLLXCJG.js.map} +0 -0
  306. /package/dist/{chunk-L7SEYUHS.js.map → chunk-3I3NXB6X.js.map} +0 -0
  307. /package/dist/{chunk-4NBUHYUV.js.map → chunk-3LADDLAF.js.map} +0 -0
  308. /package/dist/{chunk-2DL3OFLD.js.map → chunk-45GEJRIG.js.map} +0 -0
  309. /package/dist/{chunk-5BE3FLKL.js.map → chunk-5KDDAQ6K.js.map} +0 -0
  310. /package/dist/{chunk-HLWXCDUQ.js.map → chunk-63A2BU2B.js.map} +0 -0
  311. /package/dist/{chunk-MOUSHJAR.js.map → chunk-7FPI5MFB.js.map} +0 -0
  312. /package/dist/{chunk-ZX546Y3Y.js.map → chunk-7OYDFIL4.js.map} +0 -0
  313. /package/dist/{chunk-CKZWLAHN.js.map → chunk-ACPFBVUD.js.map} +0 -0
  314. /package/dist/{chunk-BKTCVXMK.js.map → chunk-AHOYKJ5X.js.map} +0 -0
  315. /package/dist/{chunk-FGT7CUYZ.js.map → chunk-ALTLOHO7.js.map} +0 -0
  316. /package/dist/{chunk-FMFCQRDM.js.map → chunk-AUFPPBC3.js.map} +0 -0
  317. /package/dist/{chunk-OAQRZ4SV.js.map → chunk-B5KTTWC7.js.map} +0 -0
  318. /package/dist/{chunk-73TPOGS4.js.map → chunk-BFBS7OFQ.js.map} +0 -0
  319. /package/dist/{chunk-QFTK6EDM.js.map → chunk-BFZFNXOC.js.map} +0 -0
  320. /package/dist/{chunk-ZQUOUPP3.js.map → chunk-BHRPZBAH.js.map} +0 -0
  321. /package/dist/{chunk-4L25GAYL.js.map → chunk-CX24SVLK.js.map} +0 -0
  322. /package/dist/{chunk-YY57TRKN.js.map → chunk-D5ZLTLHF.js.map} +0 -0
  323. /package/dist/{chunk-WEFFO2MJ.js.map → chunk-D6YCETHG.js.map} +0 -0
  324. /package/dist/{chunk-ZDZJNXL6.js.map → chunk-DK2VBJ6Q.js.map} +0 -0
  325. /package/dist/{chunk-VRHY7Y5A.js.map → chunk-DPL5VO5V.js.map} +0 -0
  326. /package/dist/{chunk-LVGTH6IQ.js.map → chunk-E7ATID4Z.js.map} +0 -0
  327. /package/dist/{chunk-CKELO7Q6.js.map → chunk-FHWX2REL.js.map} +0 -0
  328. /package/dist/{chunk-CUPILBIP.js.map → chunk-FMIM36I4.js.map} +0 -0
  329. /package/dist/{chunk-A5UOREWD.js.map → chunk-FWTGO4NE.js.map} +0 -0
  330. /package/dist/{chunk-3SL52JKD.js.map → chunk-FZVROZKC.js.map} +0 -0
  331. /package/dist/{chunk-U3BCW7GX.js.map → chunk-G3RLCVJC.js.map} +0 -0
  332. /package/dist/{chunk-UYIBNDQE.js.map → chunk-GF5NN3LE.js.map} +0 -0
  333. /package/dist/{chunk-7OCKK5M5.js.map → chunk-GWY5ZFHP.js.map} +0 -0
  334. /package/dist/{chunk-TNRGWJYT.js.map → chunk-H4IU24V5.js.map} +0 -0
  335. /package/dist/{chunk-T4BT4FQN.js.map → chunk-HH6PXQ2B.js.map} +0 -0
  336. /package/dist/{chunk-FEUWI5QH.js.map → chunk-HHPY5SSE.js.map} +0 -0
  337. /package/dist/{chunk-OM5ESBES.js.map → chunk-HQPFACXO.js.map} +0 -0
  338. /package/dist/{chunk-IMULTENA.js.map → chunk-ID65XTF3.js.map} +0 -0
  339. /package/dist/{chunk-WWQMZBDI.js.map → chunk-IJVU4ILJ.js.map} +0 -0
  340. /package/dist/{chunk-GBSXTTLP.js.map → chunk-ITGAGNX5.js.map} +0 -0
  341. /package/dist/{chunk-3PNJZTDV.js.map → chunk-JGGNUEVD.js.map} +0 -0
  342. /package/dist/{chunk-YYXYZM2I.js.map → chunk-JN7OSQJR.js.map} +0 -0
  343. /package/dist/{chunk-4D2EY4WM.js.map → chunk-K2DTHNDY.js.map} +0 -0
  344. /package/dist/{chunk-TH6OYP6I.js.map → chunk-K36RMINQ.js.map} +0 -0
  345. /package/dist/{chunk-OZKVVUJB.js.map → chunk-KIM5VNZN.js.map} +0 -0
  346. /package/dist/{chunk-ZWDDY4WF.js.map → chunk-M7CFCRWJ.js.map} +0 -0
  347. /package/dist/{chunk-QPFM6DHY.js.map → chunk-MTJFK42O.js.map} +0 -0
  348. /package/dist/{chunk-RO5EGRAI.js.map → chunk-N3FRR6II.js.map} +0 -0
  349. /package/dist/{chunk-UMEUU66X.js.map → chunk-O3OEVYUR.js.map} +0 -0
  350. /package/dist/{chunk-J74YOBB3.js.map → chunk-PFR6ZKQI.js.map} +0 -0
  351. /package/dist/{chunk-TAD6QMMD.js.map → chunk-PRC7SZYM.js.map} +0 -0
  352. /package/dist/{chunk-GMO3BGOF.js.map → chunk-QC2MHZDD.js.map} +0 -0
  353. /package/dist/{chunk-2MWKUVHT.js.map → chunk-RK7SE3BL.js.map} +0 -0
  354. /package/dist/{chunk-HDWISXFH.js.map → chunk-RVAPK2S7.js.map} +0 -0
  355. /package/dist/{chunk-5PUZV73Z.js.map → chunk-SEIGLG62.js.map} +0 -0
  356. /package/dist/{chunk-AVWOULJH.js.map → chunk-SH3GOZWK.js.map} +0 -0
  357. /package/dist/{chunk-PFLN6TTW.js.map → chunk-T3MCVSUC.js.map} +0 -0
  358. /package/dist/{chunk-WQUGCOKF.js.map → chunk-TFA6HPOA.js.map} +0 -0
  359. /package/dist/{chunk-CLVILSBR.js.map → chunk-TGQW3AMK.js.map} +0 -0
  360. /package/dist/{chunk-YZYAYUJQ.js.map → chunk-TLRIRISJ.js.map} +0 -0
  361. /package/dist/{chunk-7VIJUZYW.js.map → chunk-TQ4CELUR.js.map} +0 -0
  362. /package/dist/{chunk-5QDTZIGH.js.map → chunk-U7KP6QFU.js.map} +0 -0
  363. /package/dist/{chunk-QVXEXGIM.js.map → chunk-VF6SC4OD.js.map} +0 -0
  364. /package/dist/{chunk-EZG54YDS.js.map → chunk-VKXJQF5C.js.map} +0 -0
  365. /package/dist/{chunk-RFLC6PKQ.js.map → chunk-VMRPLHEU.js.map} +0 -0
  366. /package/dist/{chunk-U2PSE7MB.js.map → chunk-VPEIWMUT.js.map} +0 -0
  367. /package/dist/{chunk-X67XNZ64.js.map → chunk-W4EJMMPP.js.map} +0 -0
  368. /package/dist/{chunk-RB7NXZ2E.js.map → chunk-W4Q65VJL.js.map} +0 -0
  369. /package/dist/{chunk-HDDRVXX4.js.map → chunk-W5LJ3SJ7.js.map} +0 -0
  370. /package/dist/{chunk-W7N7NWG5.js.map → chunk-WCJQ3OUP.js.map} +0 -0
  371. /package/dist/{chunk-UVYI6VIX.js.map → chunk-X7Y7WX73.js.map} +0 -0
  372. /package/dist/{chunk-22V3CMIW.js.map → chunk-XJTRIHTH.js.map} +0 -0
  373. /package/dist/{chunk-SIONKXLU.js.map → chunk-XTRC6SSS.js.map} +0 -0
  374. /package/dist/{chunk-SBRUTD5O.js.map → chunk-YSATDEBY.js.map} +0 -0
  375. /package/dist/{chunk-3YOX2BQD.js.map → chunk-YWMCV5HL.js.map} +0 -0
  376. /package/dist/{chunk-6QWFZ3X5.js.map → chunk-ZA6CYFAK.js.map} +0 -0
@@ -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. */
@@ -416,19 +416,71 @@ export async function synthesizeCalibrationRules(
416
416
 
417
417
  // ─── Recall Section ──────────────────────────────────────────────────────────
418
418
 
419
+ /**
420
+ * Lexical similarity score in `[0, 1]` between a query and a calibration
421
+ * rule — the same token-overlap idiom as `session-experience-recall.ts`
422
+ * (Jaccard over lowercase tokens longer than two chars). Shared code so
423
+ * the ranker and any future embedding scorer share one field mapping:
424
+ * the rule's *when/how* text, not its id.
425
+ */
426
+ export function calibrationRuleQueryScore(
427
+ rule: CalibrationRule,
428
+ query: string,
429
+ ): number {
430
+ const norm = (s: string) =>
431
+ s
432
+ .toLowerCase()
433
+ .split(/[^a-z0-9]+/)
434
+ .filter((t) => t.length > 2);
435
+ const queryTokens = new Set(norm(query));
436
+ const ruleTokens = new Set(
437
+ norm(
438
+ `${rule.condition} ${rule.modelTendency} ${rule.userExpectation} ${rule.calibration}`,
439
+ ),
440
+ );
441
+ if (queryTokens.size === 0 || ruleTokens.size === 0) return 0;
442
+ let inter = 0;
443
+ for (const t of queryTokens) {
444
+ if (ruleTokens.has(t)) inter++;
445
+ }
446
+ const union = new Set([...queryTokens, ...ruleTokens]);
447
+ return inter / Math.max(1, union.size);
448
+ }
449
+
450
+ /**
451
+ * Order calibration rules by query relevance (issue #3552). Highest
452
+ * lexical-similarity first; ties and all-zero scores keep index order, so
453
+ * an unscoreable query yields the historical include-all ordering.
454
+ */
455
+ export function rankCalibrationRulesForQuery(
456
+ rules: readonly CalibrationRule[],
457
+ query: string,
458
+ ): CalibrationRule[] {
459
+ return rules
460
+ .map((rule, index) => ({ rule, index, score: calibrationRuleQueryScore(rule, query) }))
461
+ .sort((a, b) => b.score - a.score || a.index - b.index)
462
+ .map((entry) => entry.rule);
463
+ }
464
+
419
465
  /**
420
466
  * Build a recall section from calibration rules relevant to the current query.
421
- * Uses the LLM to select which rules apply to the current context.
467
+ * Rules are similarity-ranked against the query before `maxRules` and
468
+ * `maxChars` caps apply, so relevant rules win the budget instead of
469
+ * whichever happen to sit earliest in the index. When nothing matches
470
+ * the query the index order is preserved — the include-all fallback.
422
471
  */
423
472
  export function buildCalibrationRecallSection(
424
473
  rules: CalibrationRule[],
425
474
  query: string,
426
475
  maxChars: number = 1200,
476
+ maxRules?: number,
427
477
  ): string | null {
428
478
  if (rules.length === 0) return null;
429
479
 
430
- // Simple relevance: include all rules (they're already filtered to this user)
431
- // In production, could use embedding similarity to filter
480
+ const ranked = rankCalibrationRulesForQuery(rules, query);
481
+ const selected =
482
+ maxRules !== undefined ? ranked.slice(0, Math.max(0, maxRules)) : ranked;
483
+
432
484
  const lines: string[] = [
433
485
  "## Model Calibration (learned from past corrections)",
434
486
  "",
@@ -438,7 +490,7 @@ export function buildCalibrationRecallSection(
438
490
 
439
491
  let totalChars = lines.join("\n").length;
440
492
 
441
- for (const rule of rules) {
493
+ for (const rule of selected) {
442
494
  const line = `- **${rule.condition}**: ${rule.modelTendency} → Instead: ${rule.calibration}`;
443
495
  if (totalChars + line.length + 1 > maxChars) break;
444
496
  lines.push(line);