@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
@@ -171,6 +171,7 @@ export class ExtractionPersistCoordinator {
171
171
  ): Promise<ExtractionPersistResult> {
172
172
  const citationEnabled = resolvePipelineProcessingCapabilities(this.deps.config).inlineSourceAttribution === true;
173
173
  const citationTemplate = this.deps.config.inlineSourceAttributionFormat;
174
+ const citationHistory = this.deps.config.inlineSourceAttributionFormatHistory;
174
175
  const factDedupEnabled = resolveRecallAuxiliaryCapabilities(this.deps.config).factDeduplication;
175
176
  const harmonicConstructionEnabled = resolveCapabilities(this.deps.config).harmonicRetrieval;
176
177
  const harmonicAnchorsEnabled =
@@ -189,7 +190,7 @@ export class ExtractionPersistCoordinator {
189
190
  const promotedCopyProbe = createBatchPromotedCopyProbe(this.deps.config, this.deps.getStorageRouter, scopeProfileWritePlan); // #2330 finding F: one promoted-copy scan per namespace per batch
190
191
 
191
192
  const normalizeStoredHashSource = (raw: string): string =>
192
- normalizeStoredHashSourceContent(raw, citationEnabled, citationTemplate);
193
+ normalizeStoredHashSourceContent(raw, citationEnabled, citationTemplate, citationHistory);
193
194
  const citationContextBase: Omit<CitationContext, "ts"> = citationEnabled
194
195
  ? {
195
196
  agent: sourceContext?.principal,
@@ -197,7 +198,7 @@ export class ExtractionPersistCoordinator {
197
198
  }
198
199
  : {};
199
200
  const applyInlineCitation = (content: string): string =>
200
- applyInlineCitationToContent(content, citationEnabled, citationTemplate, citationContextBase);
201
+ applyInlineCitationToContent(content, citationEnabled, citationTemplate, citationContextBase, citationHistory);
201
202
  const persistedIds: string[] = [];
202
203
  const memoryPathById = new Map<string, string>();
203
204
  const anchorSnapshots = new ExtractionAnchorSnapshot({
@@ -385,8 +386,8 @@ export class ExtractionPersistCoordinator {
385
386
  );
386
387
  if (targets.length === 0) return [];
387
388
  const rawContent =
388
- citationEnabled && hasCitationForTemplate(options.content, citationTemplate)
389
- ? stripCitationForTemplate(options.content, citationTemplate)
389
+ citationEnabled && hasCitationForTemplate(options.content, citationTemplate, citationHistory)
390
+ ? stripCitationForTemplate(options.content, citationTemplate, citationHistory)
390
391
  : options.content;
391
392
  const citedContent = applyInlineCitation(rawContent);
392
393
  const sanitizedBase = sanitizeMemoryContent(rawContent);
@@ -617,8 +618,8 @@ export class ExtractionPersistCoordinator {
617
618
  // uses the exact body writeMemory stores (#369/#401, #402 round-6).
618
619
  const rawContent =
619
620
  citationEnabled &&
620
- hasCitationForTemplate(options.content, citationTemplate)
621
- ? stripCitationForTemplate(options.content, citationTemplate)
621
+ hasCitationForTemplate(options.content, citationTemplate, citationHistory)
622
+ ? stripCitationForTemplate(options.content, citationTemplate, citationHistory)
622
623
  : options.content;
623
624
  const citedContent = applyInlineCitation(rawContent);
624
625
  const sanitizedBase = sanitizeMemoryContent(rawContent);
@@ -996,8 +997,8 @@ export class ExtractionPersistCoordinator {
996
997
  // Build the same dedupContent the promotion functions hash on so the
997
998
  // content-hash lookup in the helper matches what was stored.
998
999
  const rawContent =
999
- citationEnabled && hasCitationForTemplate(args.content, citationTemplate)
1000
- ? stripCitationForTemplate(args.content, citationTemplate)
1000
+ citationEnabled && hasCitationForTemplate(args.content, citationTemplate, citationHistory)
1001
+ ? stripCitationForTemplate(args.content, citationTemplate, citationHistory)
1001
1002
  : args.content;
1002
1003
  const sanitizedBase = sanitizeMemoryContent(rawContent);
1003
1004
  // #2014 round 3: promoted copies were written from SALVAGE envelopes,
@@ -1659,8 +1660,8 @@ export class ExtractionPersistCoordinator {
1659
1660
  // the title alone, so distinct step lists are not collapsed (issue #519).
1660
1661
  const canonicalContentForHash =
1661
1662
  citationEnabled &&
1662
- hasCitationForTemplate(fact.content, citationTemplate)
1663
- ? stripCitationForTemplate(fact.content, citationTemplate)
1663
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
1664
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
1664
1665
  : fact.content;
1665
1666
  const contentHashDedupKey =
1666
1667
  writeCategory === "procedure"
@@ -2161,8 +2162,8 @@ export class ExtractionPersistCoordinator {
2161
2162
  // via stripCitationForTemplate before calling hasFactContentHash.
2162
2163
  const rawChunkedContent =
2163
2164
  citationEnabled &&
2164
- hasCitationForTemplate(fact.content, citationTemplate)
2165
- ? stripCitationForTemplate(fact.content, citationTemplate)
2165
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
2166
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
2166
2167
  : fact.content;
2167
2168
  const citedChunkedContent = applyInlineCitation(rawChunkedContent);
2168
2169
  const parentWriteEnvelope = composeSalvagedExtractionEnvelope(
@@ -2416,8 +2417,8 @@ export class ExtractionPersistCoordinator {
2416
2417
  try {
2417
2418
  const canonicalChunkedContent =
2418
2419
  citationEnabled &&
2419
- hasCitationForTemplate(fact.content, citationTemplate)
2420
- ? stripCitationForTemplate(fact.content, citationTemplate)
2420
+ hasCitationForTemplate(fact.content, citationTemplate, citationHistory)
2421
+ ? stripCitationForTemplate(fact.content, citationTemplate, citationHistory)
2421
2422
  : fact.content;
2422
2423
  // #1645: do NOT register a tombstone-blocked fact's content in the
2423
2424
  // dedup index — writeMemory already skipped it (rule 44). Re-adding
@@ -1368,9 +1368,8 @@ export class RecallInternalCoordinator {
1368
1368
  return null;
1369
1369
  }
1370
1370
  const section = buildCalibrationRecallSection(
1371
- rules.slice(0, this.deps.config.calibrationMaxRulesPerRecall),
1372
- retrievalQuery,
1373
- this.deps.config.calibrationMaxChars,
1371
+ rules, retrievalQuery, this.deps.config.calibrationMaxChars,
1372
+ this.deps.config.calibrationMaxRulesPerRecall,
1374
1373
  );
1375
1374
  recordRecallSectionMetric({
1376
1375
  section: "calibrationRules",
@@ -3,8 +3,9 @@ import test from "node:test";
3
3
 
4
4
  import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
5
5
  import type { AddTurnOutcome } from "../buffer-types.js";
6
+ import { SmartBuffer } from "../buffer.js";
6
7
  import { parseConfig } from "../config.js";
7
- import type { BufferTurn, PluginConfig } from "../types.js";
8
+ import type { BufferEntryState, BufferState, BufferTurn, PluginConfig } from "../types.js";
8
9
  import { ingestReplayBatchBuffered } from "./turn-ingestion-buffered.js";
9
10
  import type { TurnIngestionDeps } from "./turn-ingestion.js";
10
11
 
@@ -222,3 +223,53 @@ test("buffered ingest: LCM archive observes raw turns per session and honors arc
222
223
  await ingestReplayBatchBuffered(deps, bySession, { writeNamespaceOverride: "ns-work", archiveLcm: false });
223
224
  assert.equal(observed.length, 0);
224
225
  });
226
+
227
+ function realBufferDeps(config: PluginConfig, entries: Record<string, BufferEntryState>) {
228
+ const initial: BufferState = { turns: [], lastExtractionAt: null, extractionCount: 0, entries };
229
+ const storage = { loadBuffer: async () => structuredClone(initial), saveBuffer: async () => {} };
230
+ // SAFETY: the stub implements the load/save surface SmartBuffer reads; the cast only satisfies StorageManager.
231
+ const buffer = new SmartBuffer(config, storage as never);
232
+ const deps: Deps = { config, buffer, lcmEngine: null, queueBufferedExtraction: async () => {} };
233
+ return deps;
234
+ }
235
+
236
+ function heldTurns(sessionKey: string, count: number): BufferTurn[] {
237
+ return Array.from({ length: count }, (_, i) => ({ ...turn(`held ${i}`), sessionKey, acceptedCapture: true }));
238
+ }
239
+
240
+ test("buffered ingest: a session at its turn cap is refused with the per-session turn cap reason, not entry capacity", async () => {
241
+ const config = parseConfig({ memoryDir: "/tmp/remnic-buffered-test", bufferSaveDebounceMs: 0, bufferMaxTurnsPerSession: 4 });
242
+ const deps = realBufferDeps(config, {
243
+ "pi:full": { turns: heldTurns("pi:full", 4), lastExtractionAt: null, extractionCount: 0 },
244
+ });
245
+
246
+ await assert.rejects(
247
+ ingestReplayBatchBuffered(deps, new Map([["pi:full", [turn("one too many")]]]), { writeNamespaceOverride: "ns-work" }),
248
+ (err: Error) => {
249
+ assert.ok(err instanceof ReplayAdmissionRefusedError, "still the retryable admission class");
250
+ assert.match(err.message, /per-session turn cap \(4\)/);
251
+ assert.match(err.message, /pi:full/);
252
+ assert.doesNotMatch(err.message, /entry capacity/);
253
+ return true;
254
+ },
255
+ );
256
+ });
257
+
258
+ test("buffered ingest: a new session refused at the session-entry cap keeps the entry capacity reason", async () => {
259
+ const config = parseConfig({ memoryDir: "/tmp/remnic-buffered-test", bufferSaveDebounceMs: 0, bufferMaxSessions: 3 });
260
+ const deps = realBufferDeps(config, {
261
+ "pi:a": { turns: heldTurns("pi:a", 1), lastExtractionAt: null, extractionCount: 0 },
262
+ "pi:b": { turns: heldTurns("pi:b", 1), lastExtractionAt: null, extractionCount: 0 },
263
+ });
264
+
265
+ await assert.rejects(
266
+ ingestReplayBatchBuffered(deps, new Map([["pi:new", [turn("new session")]]]), { writeNamespaceOverride: "ns-work" }),
267
+ (err: Error) => {
268
+ assert.ok(err instanceof ReplayAdmissionRefusedError);
269
+ assert.match(err.message, /session-entry cap \(3\)/);
270
+ assert.match(err.message, /entry capacity/, "operators grepping the old text still find entry-cap refusals");
271
+ assert.doesNotMatch(err.message, /per-session turn cap/);
272
+ return true;
273
+ },
274
+ );
275
+ });
@@ -1,6 +1,7 @@
1
1
  /** Buffered durable replay ingest (#3368 split from turn-ingestion.ts — 1200-line ratchet). */
2
2
 
3
3
  import { ReplayAdmissionRefusedError, StorageTargetRequiredError } from "../buffer-admission.js";
4
+ import type { BoundedAdmissionRefusal } from "../buffer-add-turns-bounded.js";
4
5
  import { resolveNamespaceCapabilities } from "../capabilities.js";
5
6
  import type { BufferTurn, CodingContext } from "../types.js";
6
7
  import type { ResolvedScopeProfilePlan } from "../namespaces/scope-profiles.js";
@@ -38,16 +39,15 @@ export async function ingestReplayBatchBuffered(
38
39
  };
39
40
  const admissionKey = options.bufferAdmissionIdempotencyKey?.trim();
40
41
  const batches = [...bySession].map(([bufferKey, sessionTurns]) => ({ bufferKey, turns: sessionTurns.map(pin) }));
42
+ let refusal: BoundedAdmissionRefusal | undefined;
43
+ const onRefused = (reason: BoundedAdmissionRefusal): void => {
44
+ refusal = reason;
45
+ };
41
46
  const outcomes = admissionKey
42
- ? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey)
43
- : await deps.buffer.addTurnsBounded(batches);
47
+ ? await deps.buffer.addTurnsBoundedForObserveReplay(batches, admissionKey, onRefused)
48
+ : await deps.buffer.addTurnsBounded(batches, onRefused);
44
49
  if (outcomes === "duplicate") return;
45
- if (outcomes === null) {
46
- const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
47
- throw new ReplayAdmissionRefusedError(
48
- `durable observe capture refused: extraction buffer at entry capacity for batch containing ${refusedKey}`,
49
- );
50
- }
50
+ if (outcomes === null) throw replayRefusal(refusal, batches);
51
51
 
52
52
  await deps.buffer.flushPendingSave({ throwOnFailure: true });
53
53
 
@@ -72,3 +72,21 @@ export async function ingestReplayBatchBuffered(
72
72
  }
73
73
  }
74
74
  }
75
+
76
+ function replayRefusal(
77
+ refusal: BoundedAdmissionRefusal | undefined,
78
+ batches: readonly { bufferKey: string; turns: readonly BufferTurn[] }[],
79
+ ): ReplayAdmissionRefusedError {
80
+ if (refusal?.reason === "session_turn_cap") {
81
+ return new ReplayAdmissionRefusedError(
82
+ `durable observe capture refused: session ${refusal.bufferKey} holds the per-session turn cap ` +
83
+ `(${refusal.maxTurnsPerSession}) of unextracted turns; retry after extraction drains it`,
84
+ );
85
+ }
86
+ const refusedKey = batches.find((batch) => batch.turns.length > 0)?.bufferKey ?? "unknown";
87
+ const cap = refusal?.reason === "session_entry_cap" ? ` (${refusal.maxSessionEntries})` : "";
88
+ return new ReplayAdmissionRefusedError(
89
+ `durable observe capture refused: extraction buffer at entry capacity, session-entry cap${cap} ` +
90
+ `full for batch containing ${refusedKey}`,
91
+ );
92
+ }
@@ -1520,6 +1520,7 @@ export class Orchestrator {
1520
1520
  // Propagate the inline-attribution template so the storage layer can strip
1521
1521
  // citations from legacy facts during the hash-index rebuild path.
1522
1522
  this.storage.citationTemplate = config.inlineSourceAttributionFormat;
1523
+ this.storage.citationTemplateHistory = config.inlineSourceAttributionFormatHistory;
1523
1524
  // #1522: bind the post-write catalog touch at the storage chokepoint.
1524
1525
  if (config.defaultNamespace) this.storageRouter.bindCatalogWriteHook(this.storage, config.defaultNamespace);
1525
1526
  // Wire page-level versioning (issue #371)
@@ -156,3 +156,43 @@ test("input entries are not mutated", () => {
156
156
  buildStateEvidencePackets(entries);
157
157
  assert.deepEqual(entries, snapshot);
158
158
  });
159
+
160
+ test("shared chain suffixes resolve each entry at its own depth — #3565", () => {
161
+ // Diamond: two predecessors share one suffix chain. A memoized walk must
162
+ // give every entry its OWN depth (a1/a2 = 3, b = 2, c = 1), not the depth
163
+ // of whichever entry populated the cache entry it shared.
164
+ const entries: StateViewEntry[] = [
165
+ { memoryId: "head", stateLabel: "current" },
166
+ { memoryId: "a1", stateLabel: "historical", supersededById: "b" },
167
+ { memoryId: "a2", stateLabel: "historical", supersededById: "b" },
168
+ { memoryId: "b", stateLabel: "historical", supersededById: "c" },
169
+ { memoryId: "c", stateLabel: "historical", supersededById: "head" },
170
+ ];
171
+ const out = buildStateEvidencePackets(entries);
172
+ assert.deepEqual(out, {
173
+ packets: [{ headId: "head", historyIds: ["c", "b", "a1", "a2"] }],
174
+ orphanHistoryIds: [],
175
+ });
176
+ });
177
+
178
+ test("a long chain resolves in one pass, preserving per-entry depth order — #3565", () => {
179
+ // 600-entry chain: nearest-to-head ordering must hold end-to-end. Guards
180
+ // the O(n) memoized walk against off-by-one depth corruption at scale.
181
+ const n = 600;
182
+ const entries: StateViewEntry[] = [{ memoryId: "head", stateLabel: "current" }];
183
+ for (let i = n - 1; i >= 0; i--) {
184
+ entries.push({
185
+ memoryId: `h${i}`,
186
+ stateLabel: "historical",
187
+ supersededById: i === n - 1 ? "head" : `h${i + 1}`,
188
+ });
189
+ }
190
+ const out = buildStateEvidencePackets(entries);
191
+ const packet = out.packets.find((p) => p.headId === "head");
192
+ assert.ok(packet);
193
+ assert.equal(packet.historyIds.length, n);
194
+ assert.deepEqual(
195
+ packet.historyIds,
196
+ Array.from({ length: n }, (_, i) => `h${n - 1 - i}`),
197
+ );
198
+ });
@@ -47,25 +47,63 @@ interface Attachment {
47
47
  * stop at the first current/transition successor. Returns undefined when the
48
48
  * walk dead-ends (no or blank successor, successor id absent from the input)
49
49
  * or revisits an id (cycle), so callers treat the entry as an orphan.
50
+ *
51
+ * `resolved` memoizes per-entry outcomes across calls (#3565): every id
52
+ * traversed gets its own cached resolution (its own depth), so one long
53
+ * chain resolves in a single pass instead of O(n^2) re-walks.
50
54
  */
51
55
  function resolveHead(
52
56
  entry: StateViewEntry,
53
57
  byId: ReadonlyMap<string, StateViewEntry>,
58
+ resolved: Map<string, HeadResolution | undefined>,
54
59
  ): HeadResolution | undefined {
55
- const visited = new Set<string>();
60
+ const cached = resolved.get(entry.memoryId);
61
+ if (cached !== undefined || resolved.has(entry.memoryId)) return cached;
62
+ const path: string[] = [entry.memoryId];
63
+ const visited = new Set<string>(path);
56
64
  let current = entry;
57
65
  let depth = 0;
58
66
  for (;;) {
59
67
  const successorId = current.supersededById;
60
- if (successorId === undefined || successorId.trim() === "") return undefined;
61
- const successor = byId.get(successorId);
62
- if (successor === undefined) return undefined;
68
+ const successor =
69
+ successorId === undefined || successorId.trim() === ""
70
+ ? undefined
71
+ : byId.get(successorId);
72
+ if (successor === undefined || successorId === undefined) break;
73
+ const hit = resolved.get(successorId);
74
+ if (hit !== undefined || resolved.has(successorId)) {
75
+ // A node with a known outcome: splice its resolution on with an
76
+ // offset, or propagate the dead-end.
77
+ const result =
78
+ hit === undefined
79
+ ? undefined
80
+ : { headId: hit.headId, depth: depth + 1 + hit.depth };
81
+ for (let i = 0; i < path.length; i++) {
82
+ resolved.set(
83
+ path[i],
84
+ result === undefined
85
+ ? undefined
86
+ : { headId: result.headId, depth: result.depth - i },
87
+ );
88
+ }
89
+ return result;
90
+ }
63
91
  depth += 1;
64
- if (successor.stateLabel !== "historical") return { headId: successorId, depth };
65
- if (visited.has(successorId)) return undefined;
92
+ if (successor.stateLabel !== "historical") {
93
+ // Head found: every path node resolves to it at its own depth.
94
+ for (let i = 0; i < path.length; i++) {
95
+ resolved.set(path[i], { headId: successorId, depth: depth - i });
96
+ }
97
+ return { headId: successorId, depth };
98
+ }
99
+ if (visited.has(successorId)) break;
66
100
  visited.add(successorId);
101
+ path.push(successorId);
67
102
  current = successor;
68
103
  }
104
+ // Dead-end or cycle: every node on the path is an orphan.
105
+ for (const id of path) resolved.set(id, undefined);
106
+ return undefined;
69
107
  }
70
108
 
71
109
  function compareStrings(a: string, b: string): number {
@@ -97,12 +135,11 @@ export function buildStateEvidencePackets(
97
135
  if (!byId.has(entry.memoryId)) byId.set(entry.memoryId, entry);
98
136
  }
99
137
 
100
- // ponytail: per-entry chain walks are O(n^2) on one long chain; recall-sized
101
- // result sets stay tiny, memoize if packet building ever moves offline.
102
138
  const packets: StateEvidencePacket[] = [];
103
139
  const packetByHead = new Map<string, StateEvidencePacket>();
104
140
  const attachments: Attachment[] = [];
105
141
  const orphanHistoryIds: string[] = [];
142
+ const resolved = new Map<string, HeadResolution | undefined>();
106
143
 
107
144
  for (const [id, entry] of byId) {
108
145
  if (entry.stateLabel !== "historical") {
@@ -111,7 +148,7 @@ export function buildStateEvidencePackets(
111
148
  packets.push(packet);
112
149
  continue;
113
150
  }
114
- const head = resolveHead(entry, byId);
151
+ const head = resolveHead(entry, byId, resolved);
115
152
  if (head === undefined) orphanHistoryIds.push(id);
116
153
  else attachments.push({ headId: head.headId, historyId: id, depth: head.depth });
117
154
  }
@@ -1518,3 +1518,60 @@ test("citation matcher resists polynomial ReDoS on hostile unterminated input (C
1518
1518
  const valid = parseAllCitations("body [Source: doc-1 , 2026-06-08 ]");
1519
1519
  assert.equal(valid.length, 1);
1520
1520
  });
1521
+
1522
+ test("#3567 hasCitationForTemplate: default fast path consults configured prior templates", () => {
1523
+ // Fact written while a custom template was configured; config later reverted
1524
+ // to the default. The marker does not match the default shape, so the old
1525
+ // `template === DEFAULT_CITATION_FORMAT` fast path returned false and the
1526
+ // body was double-cited / hash-mismatched on reprocess.
1527
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1528
+ const body = "Latency improved after the index rebuild.";
1529
+ const cited = attachCitation(
1530
+ body,
1531
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1532
+ priorTemplate,
1533
+ );
1534
+
1535
+ // The prior template is out of history: the miss stands (documents the
1536
+ // operator contract — list prior formats in inlineSourceAttributionFormatHistory).
1537
+ assert.equal(hasCitationForTemplate(cited, DEFAULT_CITATION_FORMAT), false);
1538
+
1539
+ // With the prior template declared, the same check detects it.
1540
+ assert.equal(
1541
+ hasCitationForTemplate(cited, DEFAULT_CITATION_FORMAT, [priorTemplate]),
1542
+ true,
1543
+ );
1544
+ });
1545
+
1546
+ test("#3567 stripCitationForTemplate strips a prior-template marker under a reverted config", () => {
1547
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1548
+ const body = "Latency improved after the index rebuild.";
1549
+ const cited = attachCitation(
1550
+ body,
1551
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1552
+ priorTemplate,
1553
+ );
1554
+
1555
+ assert.equal(
1556
+ stripCitationForTemplate(cited, DEFAULT_CITATION_FORMAT, [priorTemplate]),
1557
+ body,
1558
+ );
1559
+ });
1560
+
1561
+ test("#3567 attachCitation does not double-cite a body carrying a prior-template marker", () => {
1562
+ const priorTemplate = "[src:{agent}/{session}@{date}]";
1563
+ const body = "Latency improved after the index rebuild.";
1564
+ const cited = attachCitation(
1565
+ body,
1566
+ { agent: "scout", session: "agent:scout:alpha", ts: "2026-04-10T14:25:07Z" },
1567
+ priorTemplate,
1568
+ );
1569
+
1570
+ const reattached = attachCitation(
1571
+ cited,
1572
+ { agent: "planner", session: "agent:planner:main", ts: "2026-06-01T00:00:00Z" },
1573
+ DEFAULT_CITATION_FORMAT,
1574
+ [priorTemplate],
1575
+ );
1576
+ assert.equal(reattached, cited);
1577
+ });
@@ -407,40 +407,34 @@ function templateMatcher(template: string): RegExp | null {
407
407
  * `[Source: ...]` marker detection which is always available via
408
408
  * {@link hasCitation}.
409
409
  */
410
- export function hasCitationForTemplate(text: string, template: string): boolean {
410
+ export function hasCitationForTemplate(
411
+ text: string,
412
+ template: string,
413
+ priorTemplates: readonly string[] = [],
414
+ ): boolean {
411
415
  if (typeof text !== "string" || text.length === 0) return false;
412
416
  // Always accept the default format as a fallback so facts tagged before a
413
417
  // configuration change are not double-tagged on reprocessing.
414
418
  if (hasCitation(text)) return true;
415
- // If the configured template matches the default, we're done.
416
- //
417
- // Known limitation (Thread 2 — Codex P2): this fast path exits without
418
- // checking whether the content carries a citation from a DIFFERENT custom
419
- // template that was active before the config was changed back to the default.
420
- // Such a fact would be detected by `hasCitation` above only if the prior
421
- // custom template happened to match the default `[Source: ...]` pattern.
422
- // In practice, template changes mid-stream are rare, and the false-negative
423
- // (missing an old custom citation) produces a benign duplicate citation rather
424
- // than data loss. A full fix would require storing the citation template used
425
- // at write time in the frontmatter and checking that here.
426
- if (template === DEFAULT_CITATION_FORMAT) return false;
427
-
428
- // Fully-literal template (no placeholders): exact inclusion check.
429
- if (!PLACEHOLDER_REGEX.test(template)) {
430
- // Reset lastIndex because PLACEHOLDER_REGEX is declared with /g.
419
+ // Probe the current template plus every declared prior format
420
+ // (`inlineSourceAttributionFormatHistory`, issue #3567). A fact written
421
+ // while a different template was configured is detected here instead of
422
+ // being double-cited or hashed with its marker intact on reprocess.
423
+ // citationTemplatesToRecognize drops undetectable shapes, so an
424
+ // all-placeholder prior cannot false-positive.
425
+ for (const candidate of citationTemplatesToRecognize(template, priorTemplates)) {
426
+ if (candidate === DEFAULT_CITATION_FORMAT) continue;
431
427
  PLACEHOLDER_REGEX.lastIndex = 0;
432
- return text.includes(template);
433
- }
434
- // Reset lastIndex after the .test() probe above.
435
- PLACEHOLDER_REGEX.lastIndex = 0;
436
-
437
- const matcher = templateMatcher(template);
438
- if (!matcher) {
439
- // All-placeholder template: cannot build a reliable matcher. See the
440
- // docstring — callers should not rely on dedup for this shape.
441
- return false;
428
+ if (!PLACEHOLDER_REGEX.test(candidate)) {
429
+ PLACEHOLDER_REGEX.lastIndex = 0;
430
+ if (text.includes(candidate)) return true;
431
+ continue;
432
+ }
433
+ PLACEHOLDER_REGEX.lastIndex = 0;
434
+ const matcher = templateMatcher(candidate);
435
+ if (matcher?.test(text)) return true;
442
436
  }
443
- return matcher.test(text);
437
+ return false;
444
438
  }
445
439
 
446
440
  /**
@@ -573,9 +567,10 @@ export function attachCitation(
573
567
  text: string,
574
568
  ctx: CitationContext,
575
569
  template: string = DEFAULT_CITATION_FORMAT,
570
+ priorTemplates: readonly string[] = [],
576
571
  ): string {
577
572
  if (typeof text !== "string") return text as unknown as string;
578
- if (hasCitationForTemplate(text, template)) return text;
573
+ if (hasCitationForTemplate(text, template, priorTemplates)) return text;
579
574
  const trimmedEnd = trimTrailingWhitespace(text);
580
575
  if (trimmedEnd.length === 0) return text;
581
576
  const citation = formatCitation(ctx, template);
@@ -730,28 +725,36 @@ export function stripCitation(text: string): string {
730
725
  export function stripCitationForTemplate(
731
726
  text: string,
732
727
  template: string,
728
+ priorTemplates: readonly string[] = [],
733
729
  ): string {
734
730
  if (typeof text !== "string" || text.length === 0) return text;
735
731
 
736
- // First pass: the default-format marker, if any. A second pass below still
737
- // runs — a body can carry the default marker AND the custom template's
738
- // marker, and canonicalization must remove every recognized form.
739
- const afterDefault = hasCitation(text) ? stripCitation(text) : text;
732
+ // First pass: the default-format marker, if any. Later passes still run —
733
+ // a body can carry the default marker AND markers from the current or a
734
+ // prior configured template, and canonicalization must remove every
735
+ // recognized form.
736
+ let out = hasCitation(text) ? stripCitation(text) : text;
740
737
 
741
- if (!hasCitationForTemplate(afterDefault, template)) return afterDefault;
738
+ for (const candidate of citationTemplatesToRecognize(template, priorTemplates)) {
739
+ if (candidate === DEFAULT_CITATION_FORMAT) continue;
740
+ out = stripSingleTemplateCitation(out, candidate);
741
+ }
742
+ return out;
743
+ }
742
744
 
745
+ // Strips every marker `template` produces — literal templates by exact
746
+ // match, placeholder templates via the compiled matcher. Undetectable
747
+ // (all-placeholder) shapes leave the text unchanged.
748
+ function stripSingleTemplateCitation(text: string, template: string): string {
743
749
  PLACEHOLDER_REGEX.lastIndex = 0;
744
750
  if (!PLACEHOLDER_REGEX.test(template)) {
745
751
  PLACEHOLDER_REGEX.lastIndex = 0;
746
- return stripExactLiteralCitation(afterDefault, template);
752
+ return stripExactLiteralCitation(text, template);
747
753
  }
748
754
  PLACEHOLDER_REGEX.lastIndex = 0;
749
755
 
750
- // Build the template matcher. hasCitationForTemplate already returned true,
751
- // which means templateMatcher produced a non-null result. The null branch
752
- // here is a defensive fallback only — the default pass already ran.
753
756
  const matcher = templateMatcher(template);
754
- if (!matcher) return afterDefault;
757
+ if (!matcher) return text;
755
758
 
756
759
  // The matcher regex was built without the global flag; add it for exec loop.
757
760
  const globalMatcher = new RegExp(
@@ -762,12 +765,12 @@ export function stripCitationForTemplate(
762
765
  let lastIndex = 0;
763
766
  let match: RegExpExecArray | null;
764
767
 
765
- while ((match = globalMatcher.exec(afterDefault)) !== null) {
768
+ while ((match = globalMatcher.exec(text)) !== null) {
766
769
  const matchEnd = match.index + match[0].length;
767
- const enclosure = enclosingDelimiterRange(afterDefault, match.index, matchEnd);
770
+ const enclosure = enclosingDelimiterRange(text, match.index, matchEnd);
768
771
  const removalStart = enclosure?.start ?? match.index;
769
772
  const removalEnd = enclosure?.end ?? matchEnd;
770
- const before = afterDefault.slice(lastIndex, removalStart).replace(/[ \t]+$/, "");
773
+ const before = text.slice(lastIndex, removalStart).replace(/[ \t]+$/, "");
771
774
  result += before;
772
775
  lastIndex = removalEnd;
773
776
  // Guard against zero-width matches causing an infinite loop.
@@ -776,7 +779,7 @@ export function stripCitationForTemplate(
776
779
  }
777
780
  }
778
781
 
779
- const after = afterDefault.slice(lastIndex).replace(/^[ \t]+/, "");
782
+ const after = text.slice(lastIndex).replace(/^[ \t]+/, "");
780
783
  if (after.length > 0) {
781
784
  if (result.length > 0) result += " ";
782
785
  result += after;
package/src/storage.ts CHANGED
@@ -1923,6 +1923,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
1923
1923
  private offlineSyncDigestCacheWriteTimer: ReturnType<typeof setTimeout> | null = null;
1924
1924
  /** Optional: set by the orchestrator after construction to enable template-aware citation stripping during legacy hash rebuild. */
1925
1925
  citationTemplate: string = DEFAULT_CITATION_FORMAT;
1926
+ citationTemplateHistory: string[] = [];
1926
1927
  /** Post-write catalog hook (#1522). Installed by the namespace router; fire-and-forget. */
1927
1928
  onCatalogWrite?: () => void;
1928
1929
  /** Post-write embedding hook (#2019). Installed by the orchestrator; fire-and-forget. */
@@ -3142,7 +3143,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
3142
3143
  // and the normalized-text tier must match re-extraction, which hashes
3143
3144
  // the citation-stripped contentHashSource. Idempotent on pre-stripped
3144
3145
  // text (e.g. recordSupersession).
3145
- const strippedRawContent = stripCitationForTemplate(input.rawContent, this.citationTemplate);
3146
+ const strippedRawContent = stripCitationForTemplate(input.rawContent, this.citationTemplate, this.citationTemplateHistory);
3146
3147
  // Canonicalization + post-append recheck (#2213) live in the helper.
3147
3148
  return await entityRefs.appendCanonicalizedTombstone(
3148
3149
  this.stateDir,
@@ -3212,7 +3213,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
3212
3213
  const all = [...(await this.readAllMemories()), ...(await this.readAllColdMemories())];
3213
3214
  // Pure projection (lifecycle/tombstones.ts) keeps this method thin (#1520).
3214
3215
  const retired = collectRetiredMemoriesForRebuild(all, {
3215
- stripCitation: (text) => stripCitationForTemplate(text, this.citationTemplate),
3216
+ stripCitation: (text) => stripCitationForTemplate(text, this.citationTemplate, this.citationTemplateHistory),
3216
3217
  supersessionKeysForFact,
3217
3218
  });
3218
3219
  return await store.rebuild(retired);
@@ -3428,7 +3429,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
3428
3429
  }
3429
3430
  private storedContentIdentityCandidates(content: string): string[] {
3430
3431
  return storedContentIdentityCandidates(content, (value) =>
3431
- hasCitationForTemplate(value, this.citationTemplate) ? stripCitationForTemplate(value, this.citationTemplate) : value
3432
+ hasCitationForTemplate(value, this.citationTemplate, this.citationTemplateHistory) ? stripCitationForTemplate(value, this.citationTemplate, this.citationTemplateHistory) : value
3432
3433
  );
3433
3434
  }
3434
3435