@remnic/core 1.0.2 → 1.1.0

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 (385) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/abort-error.d.ts +32 -0
  4. package/dist/abort-error.js +11 -0
  5. package/dist/access-cli.d.ts +13 -3
  6. package/dist/access-cli.js +96 -80
  7. package/dist/access-cli.js.map +1 -1
  8. package/dist/access-http.d.ts +12 -4
  9. package/dist/access-http.js +25 -18
  10. package/dist/access-mcp.d.ts +32 -4
  11. package/dist/access-mcp.js +16 -1
  12. package/dist/access-schema.d.ts +28 -28
  13. package/dist/access-schema.js +1 -1
  14. package/dist/access-service-HmO1Trrx.d.ts +732 -0
  15. package/dist/access-service.d.ts +15 -601
  16. package/dist/access-service.js +21 -15
  17. package/dist/active-memory-bridge.d.ts +66 -0
  18. package/dist/active-memory-bridge.js +11 -0
  19. package/dist/active-memory-bridge.js.map +1 -0
  20. package/dist/active-recall.d.ts +96 -0
  21. package/dist/active-recall.js +308 -0
  22. package/dist/active-recall.js.map +1 -0
  23. package/dist/behavior-learner.js +1 -1
  24. package/dist/bootstrap.d.ts +6 -3
  25. package/dist/bootstrap.js +2 -2
  26. package/dist/boxes.js +2 -2
  27. package/dist/briefing.d.ts +169 -0
  28. package/dist/briefing.js +52 -0
  29. package/dist/briefing.js.map +1 -0
  30. package/dist/buffer.d.ts +19 -5
  31. package/dist/buffer.js +2 -2
  32. package/dist/calibration.js +6 -6
  33. package/dist/causal-behavior.js +5 -5
  34. package/dist/causal-chain.js +3 -3
  35. package/dist/causal-consolidation.d.ts +22 -2
  36. package/dist/causal-consolidation.js +36 -9
  37. package/dist/causal-consolidation.js.map +1 -1
  38. package/dist/causal-retrieval.js +6 -6
  39. package/dist/causal-trajectory-graph.js +1 -1
  40. package/dist/causal-trajectory.d.ts +14 -1
  41. package/dist/causal-trajectory.js +5 -1
  42. package/dist/{chunk-KWBU5S5U.js → chunk-2ODBA7MQ.js} +9 -3
  43. package/dist/chunk-2ODBA7MQ.js.map +1 -0
  44. package/dist/{chunk-ZJLY4QSU.js → chunk-37UIFYWO.js} +130 -6
  45. package/dist/chunk-37UIFYWO.js.map +1 -0
  46. package/dist/chunk-3PG3H5TD.js +7 -0
  47. package/dist/chunk-3PG3H5TD.js.map +1 -0
  48. package/dist/{chunk-NTTLPF7F.js → chunk-3QFQGRHO.js} +5 -5
  49. package/dist/{chunk-QDOSNLB4.js → chunk-3QHL5ABG.js} +17 -15
  50. package/dist/chunk-3QHL5ABG.js.map +1 -0
  51. package/dist/{chunk-6UJQNRIO.js → chunk-3SV6CQHO.js} +92 -33
  52. package/dist/chunk-3SV6CQHO.js.map +1 -0
  53. package/dist/{chunk-U4PV25RD.js → chunk-3WHVNEN7.js} +1 -1
  54. package/dist/chunk-3WHVNEN7.js.map +1 -0
  55. package/dist/{chunk-XUHI52HK.js → chunk-44ICJRF3.js} +98 -10
  56. package/dist/chunk-44ICJRF3.js.map +1 -0
  57. package/dist/{chunk-HG2NKWR2.js → chunk-47UU5PU2.js} +49 -10
  58. package/dist/chunk-47UU5PU2.js.map +1 -0
  59. package/dist/chunk-4DJQYKMN.js +187 -0
  60. package/dist/chunk-4DJQYKMN.js.map +1 -0
  61. package/dist/chunk-4KAN3GZ3.js +225 -0
  62. package/dist/chunk-4KAN3GZ3.js.map +1 -0
  63. package/dist/chunk-4LACOVZX.js +813 -0
  64. package/dist/chunk-4LACOVZX.js.map +1 -0
  65. package/dist/{chunk-ORZMT74A.js → chunk-4NRAJUDS.js} +11 -1
  66. package/dist/chunk-4NRAJUDS.js.map +1 -0
  67. package/dist/{chunk-B7LOFDVE.js → chunk-4WMCPJWX.js} +8 -3
  68. package/dist/chunk-4WMCPJWX.js.map +1 -0
  69. package/dist/{chunk-G3AG3KZN.js → chunk-5IZL4DCV.js} +2 -2
  70. package/dist/{chunk-BRK4ODMI.js → chunk-5NPGSAVB.js} +2 -2
  71. package/dist/{chunk-QANCTXQF.js → chunk-6LX5ORAS.js} +3 -3
  72. package/dist/chunk-6MKAMLQL.js +16 -0
  73. package/dist/chunk-6MKAMLQL.js.map +1 -0
  74. package/dist/{chunk-ESSMF2FR.js → chunk-6PFRXT4K.js} +15 -6
  75. package/dist/chunk-6PFRXT4K.js.map +1 -0
  76. package/dist/{chunk-UIYZ5T3I.js → chunk-6UJ47TVX.js} +8 -8
  77. package/dist/chunk-6ZH4TU6I.js +245 -0
  78. package/dist/chunk-6ZH4TU6I.js.map +1 -0
  79. package/dist/{chunk-L5RPWGFK.js → chunk-7DHTMOND.js} +2 -2
  80. package/dist/{chunk-L7WO3MZ4.js → chunk-7ECD5ATE.js} +2 -2
  81. package/dist/{chunk-Q6FETXJA.js → chunk-7SEAZFFB.js} +2 -2
  82. package/dist/{chunk-V4YC4LUK.js → chunk-7WQ6SLIE.js} +175 -63
  83. package/dist/chunk-7WQ6SLIE.js.map +1 -0
  84. package/dist/chunk-ALXMCZEU.js +332 -0
  85. package/dist/chunk-ALXMCZEU.js.map +1 -0
  86. package/dist/{chunk-TVVVQQAK.js → chunk-BLKTA7MM.js} +58 -24
  87. package/dist/chunk-BLKTA7MM.js.map +1 -0
  88. package/dist/{chunk-SCHEKPYH.js → chunk-C2EFFULQ.js} +1 -1
  89. package/dist/{chunk-GJR6D6KC.js → chunk-D654IBA6.js} +2 -2
  90. package/dist/{chunk-OTFNI3OO.js → chunk-DEPL3635.js} +1828 -401
  91. package/dist/chunk-DEPL3635.js.map +1 -0
  92. package/dist/{chunk-UYSKNO6E.js → chunk-DHHP2Z4X.js} +15 -4
  93. package/dist/chunk-DHHP2Z4X.js.map +1 -0
  94. package/dist/{chunk-UV2FO7J4.js → chunk-E6K4NIEU.js} +2 -2
  95. package/dist/{chunk-T4WRIV2C.js → chunk-EABGC2TL.js} +2 -2
  96. package/dist/chunk-EJI5XIBB.js +232 -0
  97. package/dist/chunk-EJI5XIBB.js.map +1 -0
  98. package/dist/{chunk-ONRU4L2N.js → chunk-FEMOX5AD.js} +2 -2
  99. package/dist/{chunk-IFFFR3MR.js → chunk-FSFEQI74.js} +3 -3
  100. package/dist/chunk-G4SK7DSQ.js +121 -0
  101. package/dist/chunk-G4SK7DSQ.js.map +1 -0
  102. package/dist/{chunk-WWIQTB2Y.js → chunk-GGD5W7TB.js} +9 -2
  103. package/dist/chunk-GGD5W7TB.js.map +1 -0
  104. package/dist/{chunk-QWUUMMIK.js → chunk-GV6NLQ4X.js} +1355 -80
  105. package/dist/chunk-GV6NLQ4X.js.map +1 -0
  106. package/dist/{chunk-2PO5ZRKV.js → chunk-GZCUW5IC.js} +16 -3
  107. package/dist/chunk-GZCUW5IC.js.map +1 -0
  108. package/dist/{chunk-AAI7JARD.js → chunk-HMDCOMYU.js} +8 -11
  109. package/dist/chunk-HMDCOMYU.js.map +1 -0
  110. package/dist/chunk-IQT3XTKW.js +121 -0
  111. package/dist/chunk-IQT3XTKW.js.map +1 -0
  112. package/dist/{chunk-J3BT33K7.js → chunk-ITRLGI2T.js} +5 -5
  113. package/dist/{chunk-BDFZXRSO.js → chunk-J4IYOZZ5.js} +15 -2
  114. package/dist/chunk-J4IYOZZ5.js.map +1 -0
  115. package/dist/{chunk-J47FNDR7.js → chunk-JIU55F3X.js} +7 -7
  116. package/dist/{chunk-MDDAA2AO.js → chunk-JL2PU6AI.js} +17 -6
  117. package/dist/chunk-JL2PU6AI.js.map +1 -0
  118. package/dist/{chunk-ZKYI7UVO.js → chunk-JR4ZC3G4.js} +2 -2
  119. package/dist/{chunk-UCYSTFZR.js → chunk-JRNQ3RNA.js} +2 -2
  120. package/dist/{chunk-GPGBSNKM.js → chunk-K4FLSOR5.js} +2 -2
  121. package/dist/chunk-KVE7R4CG.js +320 -0
  122. package/dist/chunk-KVE7R4CG.js.map +1 -0
  123. package/dist/chunk-LAYN4LDC.js +267 -0
  124. package/dist/chunk-LAYN4LDC.js.map +1 -0
  125. package/dist/{chunk-ISY75RLM.js → chunk-MBJHSA7F.js} +344 -7
  126. package/dist/chunk-MBJHSA7F.js.map +1 -0
  127. package/dist/{chunk-PGK3VUHN.js → chunk-MTLYEMJB.js} +3 -2
  128. package/dist/chunk-MTLYEMJB.js.map +1 -0
  129. package/dist/{chunk-QY2BHY5O.js → chunk-MVTHXUBX.js} +297 -34
  130. package/dist/chunk-MVTHXUBX.js.map +1 -0
  131. package/dist/{chunk-LP47L3ZX.js → chunk-N42IWANG.js} +5 -5
  132. package/dist/{chunk-YNI4S5WT.js → chunk-N53K2EXC.js} +2 -2
  133. package/dist/{chunk-763GUIOU.js → chunk-NBNN5GOB.js} +2 -2
  134. package/dist/{chunk-CXWFUJR2.js → chunk-NQEVYWX6.js} +195 -5
  135. package/dist/chunk-NQEVYWX6.js.map +1 -0
  136. package/dist/{chunk-KL4CP4SB.js → chunk-O5ETUNBT.js} +17 -5
  137. package/dist/chunk-O5ETUNBT.js.map +1 -0
  138. package/dist/{chunk-OOSWAUYB.js → chunk-ODWDQNRE.js} +2 -2
  139. package/dist/chunk-OIT5QGG4.js +80 -0
  140. package/dist/chunk-OIT5QGG4.js.map +1 -0
  141. package/dist/{chunk-HLBYLYRD.js → chunk-PAORGQRI.js} +70 -13
  142. package/dist/chunk-PAORGQRI.js.map +1 -0
  143. package/dist/chunk-PVGDJXVK.js +21 -0
  144. package/dist/chunk-PVGDJXVK.js.map +1 -0
  145. package/dist/{chunk-OTAVQCSF.js → chunk-PYXS46O7.js} +2 -2
  146. package/dist/chunk-QDW3E4RD.js +108 -0
  147. package/dist/chunk-QDW3E4RD.js.map +1 -0
  148. package/dist/{chunk-YNCQ7E4M.js → chunk-QDYXG4CS.js} +4 -3
  149. package/dist/chunk-QDYXG4CS.js.map +1 -0
  150. package/dist/{chunk-HLXVTBF3.js → chunk-QNJMBKFK.js} +3 -2
  151. package/dist/chunk-QNJMBKFK.js.map +1 -0
  152. package/dist/{chunk-4A24LIM2.js → chunk-S75M5ZRK.js} +2 -2
  153. package/dist/chunk-SYUK3VLY.js +789 -0
  154. package/dist/chunk-SYUK3VLY.js.map +1 -0
  155. package/dist/{chunk-QCCCQT3O.js → chunk-TBBDFYXW.js} +2 -2
  156. package/dist/chunk-TBBDFYXW.js.map +1 -0
  157. package/dist/chunk-U66YHYC7.js +31 -0
  158. package/dist/chunk-U66YHYC7.js.map +1 -0
  159. package/dist/{chunk-MWGVGUIS.js → chunk-UEYA6UC7.js} +36 -4
  160. package/dist/chunk-UEYA6UC7.js.map +1 -0
  161. package/dist/{chunk-M5KEYE5E.js → chunk-URB2WSKZ.js} +2 -2
  162. package/dist/chunk-UVJFDP7P.js +202 -0
  163. package/dist/chunk-UVJFDP7P.js.map +1 -0
  164. package/dist/chunk-W6SL7OFG.js +180 -0
  165. package/dist/chunk-W6SL7OFG.js.map +1 -0
  166. package/dist/chunk-WBSAYXVI.js +7945 -0
  167. package/dist/chunk-WBSAYXVI.js.map +1 -0
  168. package/dist/{chunk-M5ZBBBJI.js → chunk-XZ2TIKGC.js} +39 -9
  169. package/dist/chunk-XZ2TIKGC.js.map +1 -0
  170. package/dist/chunk-Y4FHOFJ2.js +140 -0
  171. package/dist/chunk-Y4FHOFJ2.js.map +1 -0
  172. package/dist/chunk-YDBIWGNI.js +298 -0
  173. package/dist/chunk-YDBIWGNI.js.map +1 -0
  174. package/dist/chunk-YNB73F22.js +137 -0
  175. package/dist/chunk-YNB73F22.js.map +1 -0
  176. package/dist/{chunk-IZME7KW2.js → chunk-ZVBB3T7V.js} +31 -12
  177. package/dist/chunk-ZVBB3T7V.js.map +1 -0
  178. package/dist/chunking.js +1 -1
  179. package/dist/citations.d.ts +67 -0
  180. package/dist/citations.js +13 -0
  181. package/dist/citations.js.map +1 -0
  182. package/dist/cli-BneVIEvh.d.ts +1240 -0
  183. package/dist/cli.d.ts +32 -1147
  184. package/dist/cli.js +150 -7092
  185. package/dist/cli.js.map +1 -1
  186. package/dist/codex-materialize-CQlLTzke.d.ts +139 -0
  187. package/dist/codex-thread-key.d.ts +3 -0
  188. package/dist/codex-thread-key.js +7 -0
  189. package/dist/codex-thread-key.js.map +1 -0
  190. package/dist/config.js +3 -2
  191. package/dist/connectors/codex/instructions.md +160 -0
  192. package/dist/connectors/codex/resources/namespace-cheatsheet.md +48 -0
  193. package/dist/contradiction-review-WIUBAR52.js +21 -0
  194. package/dist/contradiction-review-WIUBAR52.js.map +1 -0
  195. package/dist/contradiction-scan-GR33PONM.js +376 -0
  196. package/dist/contradiction-scan-GR33PONM.js.map +1 -0
  197. package/dist/day-summary.d.ts +7 -2
  198. package/dist/day-summary.js +5 -2
  199. package/dist/direct-answer-wiring.d.ts +77 -0
  200. package/dist/direct-answer-wiring.js +75 -0
  201. package/dist/direct-answer-wiring.js.map +1 -0
  202. package/dist/direct-answer.d.ts +106 -0
  203. package/dist/direct-answer.js +10 -0
  204. package/dist/direct-answer.js.map +1 -0
  205. package/dist/embedding-fallback.d.ts +96 -2
  206. package/dist/embedding-fallback.js +6 -4
  207. package/dist/{engine-2A6J4XEX.js → engine-5TIQBYZR.js} +10 -7
  208. package/dist/engine-5TIQBYZR.js.map +1 -0
  209. package/dist/entity-retrieval.d.ts +3 -2
  210. package/dist/entity-retrieval.js +10 -7
  211. package/dist/entity-schema.d.ts +11 -0
  212. package/dist/entity-schema.js +19 -0
  213. package/dist/entity-schema.js.map +1 -0
  214. package/dist/explicit-capture.d.ts +6 -3
  215. package/dist/explicit-capture.js +2 -2
  216. package/dist/extraction-judge.d.ts +66 -0
  217. package/dist/extraction-judge.js +18 -0
  218. package/dist/extraction-judge.js.map +1 -0
  219. package/dist/extraction.d.ts +1 -0
  220. package/dist/extraction.js +12 -10
  221. package/dist/fallback-llm.d.ts +11 -2
  222. package/dist/fallback-llm.js +4 -4
  223. package/dist/graph.js +1 -1
  224. package/dist/harmonic-retrieval.js +2 -1
  225. package/dist/importance.d.ts +11 -1
  226. package/dist/importance.js +3 -1
  227. package/dist/index.d.ts +1027 -9
  228. package/dist/index.js +3303 -349
  229. package/dist/index.js.map +1 -1
  230. package/dist/intent.d.ts +2 -1
  231. package/dist/intent.js +3 -1
  232. package/dist/lifecycle.js +1 -1
  233. package/dist/local-llm.d.ts +10 -3
  234. package/dist/local-llm.js +2 -2
  235. package/dist/logger.d.ts +1 -1
  236. package/dist/logger.js +1 -1
  237. package/dist/memory-cache.d.ts +2 -2
  238. package/dist/memory-cache.js +1 -1
  239. package/dist/{memory-projection-store-NxMkbocT.d.ts → memory-projection-store-DeSXPh1j.d.ts} +1 -1
  240. package/dist/memory-projection-store.d.ts +1 -1
  241. package/dist/model-registry.js +2 -2
  242. package/dist/models-json.js +2 -2
  243. package/dist/native-knowledge.js +2 -2
  244. package/dist/negative.js +2 -2
  245. package/dist/operator-toolkit.js +20 -15
  246. package/dist/{orchestrator-zTa-Qo-1.d.ts → orchestrator-DRYA6_lW.d.ts} +273 -9
  247. package/dist/orchestrator.d.ts +6 -3
  248. package/dist/orchestrator.js +76 -63
  249. package/dist/page-versioning.d.ts +77 -0
  250. package/dist/page-versioning.js +15 -0
  251. package/dist/page-versioning.js.map +1 -0
  252. package/dist/plugin-id.d.ts +37 -0
  253. package/dist/plugin-id.js +11 -0
  254. package/dist/plugin-id.js.map +1 -0
  255. package/dist/policy-runtime.js +2 -2
  256. package/dist/profiling.js +2 -2
  257. package/dist/qmd.d.ts +5 -2
  258. package/dist/qmd.js +4 -3
  259. package/dist/recall-audit.d.ts +20 -0
  260. package/dist/recall-audit.js +50 -0
  261. package/dist/recall-audit.js.map +1 -0
  262. package/dist/recall-mmr.d.ts +152 -0
  263. package/dist/recall-mmr.js +17 -0
  264. package/dist/recall-mmr.js.map +1 -0
  265. package/dist/recall-qos.js +2 -2
  266. package/dist/recall-state.d.ts +28 -1
  267. package/dist/recall-state.js +2 -2
  268. package/dist/relevance.js +2 -2
  269. package/dist/resolution-QBTDHTG7.js +100 -0
  270. package/dist/resolution-QBTDHTG7.js.map +1 -0
  271. package/dist/resolve-provider-secret.d.ts +24 -1
  272. package/dist/resolve-provider-secret.js +4 -2
  273. package/dist/resume-bundles.js +6 -5
  274. package/dist/retrieval-agents.js +2 -2
  275. package/dist/retrieval.js +2 -2
  276. package/dist/schemas.d.ts +412 -54
  277. package/dist/schemas.js +3 -1
  278. package/dist/sdk-compat.d.ts +2 -0
  279. package/dist/sdk-compat.js +6 -3
  280. package/dist/sdk-compat.js.map +1 -1
  281. package/dist/semantic-chunking.d.ts +87 -0
  282. package/dist/semantic-chunking.js +20 -0
  283. package/dist/semantic-chunking.js.map +1 -0
  284. package/dist/semantic-consolidation-DrvSYRdB.d.ts +119 -0
  285. package/dist/semantic-consolidation.d.ts +4 -42
  286. package/dist/semantic-consolidation.js +23 -2
  287. package/dist/semantic-rule-promotion.js +9 -6
  288. package/dist/semantic-rule-verifier.js +10 -7
  289. package/dist/session-observer-state.js +2 -2
  290. package/dist/session-toggles.d.ts +22 -0
  291. package/dist/session-toggles.js +116 -0
  292. package/dist/session-toggles.js.map +1 -0
  293. package/dist/skills-registry.d.ts +47 -0
  294. package/dist/skills-registry.js +48 -0
  295. package/dist/skills-registry.js.map +1 -0
  296. package/dist/source-attribution.d.ts +169 -0
  297. package/dist/source-attribution.js +27 -0
  298. package/dist/source-attribution.js.map +1 -0
  299. package/dist/storage.d.ts +171 -10
  300. package/dist/storage.js +16 -5
  301. package/dist/summarizer.js +7 -7
  302. package/dist/temporal-supersession.d.ts +127 -0
  303. package/dist/temporal-supersession.js +20 -0
  304. package/dist/temporal-supersession.js.map +1 -0
  305. package/dist/threading.js +2 -2
  306. package/dist/tier-migration.d.ts +2 -1
  307. package/dist/tier-routing.js +2 -2
  308. package/dist/tokens.d.ts +21 -1
  309. package/dist/tokens.js +5 -1
  310. package/dist/transcript.js +2 -2
  311. package/dist/types-DJhqDJUV.d.ts +50 -0
  312. package/dist/types.d.ts +529 -3
  313. package/dist/types.js +1 -1
  314. package/dist/utility-learner.js +2 -2
  315. package/dist/utility-runtime.js +3 -3
  316. package/dist/verified-recall.js +11 -8
  317. package/dist/whitespace.d.ts +4 -0
  318. package/dist/whitespace.js +9 -0
  319. package/dist/whitespace.js.map +1 -0
  320. package/package.json +14 -8
  321. package/dist/chunk-2CJCWDMR.js +0 -87
  322. package/dist/chunk-2CJCWDMR.js.map +0 -1
  323. package/dist/chunk-2PO5ZRKV.js.map +0 -1
  324. package/dist/chunk-6UJQNRIO.js.map +0 -1
  325. package/dist/chunk-AAI7JARD.js.map +0 -1
  326. package/dist/chunk-B7LOFDVE.js.map +0 -1
  327. package/dist/chunk-BDFZXRSO.js.map +0 -1
  328. package/dist/chunk-CXWFUJR2.js.map +0 -1
  329. package/dist/chunk-DORBM6OB.js +0 -81
  330. package/dist/chunk-DORBM6OB.js.map +0 -1
  331. package/dist/chunk-ESSMF2FR.js.map +0 -1
  332. package/dist/chunk-HG2NKWR2.js.map +0 -1
  333. package/dist/chunk-HLBYLYRD.js.map +0 -1
  334. package/dist/chunk-HLXVTBF3.js.map +0 -1
  335. package/dist/chunk-ISY75RLM.js.map +0 -1
  336. package/dist/chunk-IZME7KW2.js.map +0 -1
  337. package/dist/chunk-KL4CP4SB.js.map +0 -1
  338. package/dist/chunk-KWBU5S5U.js.map +0 -1
  339. package/dist/chunk-M5ZBBBJI.js.map +0 -1
  340. package/dist/chunk-MDDAA2AO.js.map +0 -1
  341. package/dist/chunk-MWGVGUIS.js.map +0 -1
  342. package/dist/chunk-ORZMT74A.js.map +0 -1
  343. package/dist/chunk-OTFNI3OO.js.map +0 -1
  344. package/dist/chunk-PGK3VUHN.js.map +0 -1
  345. package/dist/chunk-QCCCQT3O.js.map +0 -1
  346. package/dist/chunk-QDOSNLB4.js.map +0 -1
  347. package/dist/chunk-QPKFPHOO.js +0 -178
  348. package/dist/chunk-QPKFPHOO.js.map +0 -1
  349. package/dist/chunk-QWUUMMIK.js.map +0 -1
  350. package/dist/chunk-QY2BHY5O.js.map +0 -1
  351. package/dist/chunk-TVVVQQAK.js.map +0 -1
  352. package/dist/chunk-U4PV25RD.js.map +0 -1
  353. package/dist/chunk-UYSKNO6E.js.map +0 -1
  354. package/dist/chunk-V4YC4LUK.js.map +0 -1
  355. package/dist/chunk-WWIQTB2Y.js.map +0 -1
  356. package/dist/chunk-XUHI52HK.js.map +0 -1
  357. package/dist/chunk-YNCQ7E4M.js.map +0 -1
  358. package/dist/chunk-ZJLY4QSU.js.map +0 -1
  359. /package/dist/{engine-2A6J4XEX.js.map → abort-error.js.map} +0 -0
  360. /package/dist/{chunk-NTTLPF7F.js.map → chunk-3QFQGRHO.js.map} +0 -0
  361. /package/dist/{chunk-G3AG3KZN.js.map → chunk-5IZL4DCV.js.map} +0 -0
  362. /package/dist/{chunk-BRK4ODMI.js.map → chunk-5NPGSAVB.js.map} +0 -0
  363. /package/dist/{chunk-QANCTXQF.js.map → chunk-6LX5ORAS.js.map} +0 -0
  364. /package/dist/{chunk-UIYZ5T3I.js.map → chunk-6UJ47TVX.js.map} +0 -0
  365. /package/dist/{chunk-L5RPWGFK.js.map → chunk-7DHTMOND.js.map} +0 -0
  366. /package/dist/{chunk-L7WO3MZ4.js.map → chunk-7ECD5ATE.js.map} +0 -0
  367. /package/dist/{chunk-Q6FETXJA.js.map → chunk-7SEAZFFB.js.map} +0 -0
  368. /package/dist/{chunk-SCHEKPYH.js.map → chunk-C2EFFULQ.js.map} +0 -0
  369. /package/dist/{chunk-GJR6D6KC.js.map → chunk-D654IBA6.js.map} +0 -0
  370. /package/dist/{chunk-UV2FO7J4.js.map → chunk-E6K4NIEU.js.map} +0 -0
  371. /package/dist/{chunk-T4WRIV2C.js.map → chunk-EABGC2TL.js.map} +0 -0
  372. /package/dist/{chunk-ONRU4L2N.js.map → chunk-FEMOX5AD.js.map} +0 -0
  373. /package/dist/{chunk-IFFFR3MR.js.map → chunk-FSFEQI74.js.map} +0 -0
  374. /package/dist/{chunk-J3BT33K7.js.map → chunk-ITRLGI2T.js.map} +0 -0
  375. /package/dist/{chunk-J47FNDR7.js.map → chunk-JIU55F3X.js.map} +0 -0
  376. /package/dist/{chunk-ZKYI7UVO.js.map → chunk-JR4ZC3G4.js.map} +0 -0
  377. /package/dist/{chunk-UCYSTFZR.js.map → chunk-JRNQ3RNA.js.map} +0 -0
  378. /package/dist/{chunk-GPGBSNKM.js.map → chunk-K4FLSOR5.js.map} +0 -0
  379. /package/dist/{chunk-LP47L3ZX.js.map → chunk-N42IWANG.js.map} +0 -0
  380. /package/dist/{chunk-YNI4S5WT.js.map → chunk-N53K2EXC.js.map} +0 -0
  381. /package/dist/{chunk-763GUIOU.js.map → chunk-NBNN5GOB.js.map} +0 -0
  382. /package/dist/{chunk-OOSWAUYB.js.map → chunk-ODWDQNRE.js.map} +0 -0
  383. /package/dist/{chunk-OTAVQCSF.js.map → chunk-PYXS46O7.js.map} +0 -0
  384. /package/dist/{chunk-4A24LIM2.js.map → chunk-S75M5ZRK.js.map} +0 -0
  385. /package/dist/{chunk-M5KEYE5E.js.map → chunk-URB2WSKZ.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/buffer.ts"],"sourcesContent":["import { log } from \"./logger.js\";\nimport { scanSignals } from \"./signal.js\";\nimport type { StorageManager } from \"./storage.js\";\nimport type {\n BufferEntryState,\n BufferState,\n BufferTurn,\n PluginConfig,\n SignalLevel,\n} from \"./types.js\";\n\nexport type TriggerDecision = \"extract_now\" | \"extract_batch\" | \"keep_buffering\";\n\nconst MAX_BUFFER_ENTRY_COUNT = 200;\n\nexport class SmartBuffer {\n private state: BufferState;\n private loaded = false;\n\n constructor(\n private readonly config: PluginConfig,\n private readonly storage: StorageManager,\n ) {\n this.state = { turns: [], lastExtractionAt: null, extractionCount: 0 };\n }\n\n private entryFor(key: string): BufferEntryState {\n this.state.entries ??= {};\n const existing = this.state.entries[key];\n if (existing) return existing;\n const created: BufferEntryState = {\n turns: [],\n lastExtractionAt: null,\n extractionCount: 0,\n };\n this.state.entries[key] = created;\n return created;\n }\n\n private peekEntry(key: string): BufferEntryState | null {\n const existing = this.state.entries?.[key];\n if (existing) return existing;\n if (key !== \"default\") return null;\n return {\n turns: Array.isArray(this.state.turns) ? this.state.turns : [],\n lastExtractionAt: this.state.lastExtractionAt ?? null,\n extractionCount:\n typeof this.state.extractionCount === \"number\" ? this.state.extractionCount : 0,\n };\n }\n\n private normalizeState(state: BufferState): BufferState {\n const entries = state.entries ?? {};\n if (!entries.default) {\n entries.default = {\n turns: Array.isArray(state.turns) ? [...state.turns] : [],\n lastExtractionAt: state.lastExtractionAt ?? null,\n extractionCount:\n typeof state.extractionCount === \"number\" ? state.extractionCount : 0,\n };\n }\n return {\n turns: entries.default.turns,\n lastExtractionAt: entries.default.lastExtractionAt,\n extractionCount: entries.default.extractionCount,\n entries,\n };\n }\n\n private entryActivityAt(entry: BufferEntryState): number {\n const lastTurnAt = entry.turns.reduce((latest, turn) => {\n const parsed = Date.parse(turn.timestamp);\n return Number.isFinite(parsed) ? Math.max(latest, parsed) : latest;\n }, -1);\n const lastExtractionAt =\n typeof entry.lastExtractionAt === \"string\"\n ? Date.parse(entry.lastExtractionAt)\n : Number.NaN;\n return Math.max(\n lastTurnAt,\n Number.isFinite(lastExtractionAt) ? lastExtractionAt : -1,\n );\n }\n\n private pruneEntries(retainKeys: string[]): void {\n const entries = this.state.entries;\n if (!entries) return;\n const keys = Object.keys(entries);\n if (keys.length <= MAX_BUFFER_ENTRY_COUNT) return;\n\n const insertionOrder = new Map(keys.map((key, index) => [key, index]));\n const removable = keys\n .filter((key) => key !== \"default\" && !retainKeys.includes(key))\n .filter((key) => (entries[key]?.turns.length ?? 0) === 0)\n .sort((left, right) => {\n const leftAt = this.entryActivityAt(entries[left] ?? {\n turns: [],\n lastExtractionAt: null,\n extractionCount: 0,\n });\n const rightAt = this.entryActivityAt(entries[right] ?? {\n turns: [],\n lastExtractionAt: null,\n extractionCount: 0,\n });\n if (leftAt !== rightAt) return leftAt - rightAt;\n return (insertionOrder.get(left) ?? 0) - (insertionOrder.get(right) ?? 0);\n });\n\n const removableCount = Math.max(0, keys.length - MAX_BUFFER_ENTRY_COUNT);\n for (const key of removable.slice(0, removableCount)) {\n delete entries[key];\n }\n }\n\n async load(): Promise<void> {\n if (this.loaded) return;\n this.state = this.normalizeState(await this.storage.loadBuffer());\n this.loaded = true;\n }\n\n /**\n * Reset the buffer to an empty, usable state.\n * Called when the persisted buffer file is corrupt and load() fails,\n * so the buffer can still accept new turns for the rest of the session.\n */\n resetToEmpty(): void {\n this.state = { turns: [], lastExtractionAt: null, extractionCount: 0 };\n this.loaded = true;\n }\n\n async save(): Promise<void> {\n await this.storage.saveBuffer(this.state);\n }\n\n async addTurn(bufferKey: string, turn: BufferTurn): Promise<TriggerDecision> {\n await this.load();\n const entry = this.entryFor(bufferKey);\n entry.turns.push(turn);\n if (bufferKey === \"default\") {\n this.state.turns = entry.turns;\n }\n\n const signal = scanSignals(turn.content, this.config.highSignalPatterns);\n const decision = this.evaluate(entry, signal.level);\n\n log.debug(\n `buffer[${bufferKey}]: ${entry.turns.length} turns, signal=${signal.level}, decision=${decision}`,\n );\n\n this.pruneEntries([bufferKey]);\n await this.save();\n return decision;\n }\n\n private evaluate(entry: BufferEntryState, signalLevel: SignalLevel): TriggerDecision {\n if (this.config.triggerMode === \"smart\") {\n if (signalLevel === \"high\") return \"extract_now\";\n\n if (entry.turns.length >= this.config.bufferMaxTurns) {\n return \"extract_batch\";\n }\n\n if (entry.lastExtractionAt) {\n const elapsed =\n Date.now() - new Date(entry.lastExtractionAt).getTime();\n if (elapsed >= this.config.bufferMaxMinutes * 60_000) {\n return \"extract_batch\";\n }\n }\n\n return \"keep_buffering\";\n }\n\n if (this.config.triggerMode === \"every_n\") {\n return entry.turns.length >= this.config.bufferMaxTurns\n ? \"extract_batch\"\n : \"keep_buffering\";\n }\n\n if (this.config.triggerMode === \"time_based\") {\n if (!entry.lastExtractionAt) {\n return entry.turns.length >= this.config.bufferMaxTurns\n ? \"extract_batch\"\n : \"keep_buffering\";\n }\n const elapsed =\n Date.now() - new Date(entry.lastExtractionAt).getTime();\n return elapsed >= this.config.bufferMaxMinutes * 60_000\n ? \"extract_batch\"\n : \"keep_buffering\";\n }\n\n return \"keep_buffering\";\n }\n\n getTurns(bufferKey = \"default\"): BufferTurn[] {\n const entry = this.peekEntry(bufferKey);\n if (!entry) return [];\n return [...entry.turns];\n }\n\n async findBufferKeyForSession(sessionKey: string): Promise<string | null> {\n const bufferKeys = await this.findBufferKeysForSession(sessionKey);\n return bufferKeys[0] ?? null;\n }\n\n async findBufferKeysForSession(sessionKey: string): Promise<string[]> {\n if (typeof sessionKey !== \"string\" || sessionKey.length === 0) return [];\n await this.load();\n\n const matches: string[] = [];\n const directEntry = this.peekEntry(sessionKey);\n if ((directEntry?.turns.length ?? 0) > 0) {\n matches.push(sessionKey);\n }\n\n const entries = this.state.entries ?? {};\n for (const [bufferKey, entry] of Object.entries(entries)) {\n if (\n !matches.includes(bufferKey) &&\n entry.turns.some(\n (turn) =>\n typeof turn.sessionKey === \"string\" && turn.sessionKey === sessionKey,\n )\n ) {\n matches.push(bufferKey);\n }\n }\n\n return matches;\n }\n\n async clearAfterExtraction(bufferKey = \"default\"): Promise<void> {\n await this.load();\n const entry = this.entryFor(bufferKey);\n entry.turns = [];\n entry.lastExtractionAt = new Date().toISOString();\n entry.extractionCount += 1;\n if (bufferKey === \"default\") {\n this.state.turns = entry.turns;\n this.state.lastExtractionAt = entry.lastExtractionAt;\n this.state.extractionCount = entry.extractionCount;\n }\n this.pruneEntries([bufferKey]);\n await this.save();\n }\n\n getExtractionCount(bufferKey = \"default\"): number {\n return this.peekEntry(bufferKey)?.extractionCount ?? 0;\n }\n}\n"],"mappings":";;;;;;;;AAaA,IAAM,yBAAyB;AAExB,IAAM,cAAN,MAAkB;AAAA,EAIvB,YACmB,QACA,SACjB;AAFiB;AACA;AAEjB,SAAK,QAAQ,EAAE,OAAO,CAAC,GAAG,kBAAkB,MAAM,iBAAiB,EAAE;AAAA,EACvE;AAAA,EAJmB;AAAA,EACA;AAAA,EALX;AAAA,EACA,SAAS;AAAA,EAST,SAAS,KAA+B;AAC9C,SAAK,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,EACT;AAAA,EAEA,MAAM,qBAAqB,YAAY,WAA0B;AAC/D,UAAM,KAAK,KAAK;AAChB,UAAM,QAAQ,KAAK,SAAS,SAAS;AACrC,UAAM,QAAQ,CAAC;AACf,UAAM,oBAAmB,oBAAI,KAAK,GAAE,YAAY;AAChD,UAAM,mBAAmB;AACzB,QAAI,cAAc,WAAW;AAC3B,WAAK,MAAM,QAAQ,MAAM;AACzB,WAAK,MAAM,mBAAmB,MAAM;AACpC,WAAK,MAAM,kBAAkB,MAAM;AAAA,IACrC;AACA,SAAK,aAAa,CAAC,SAAS,CAAC;AAC7B,UAAM,KAAK,KAAK;AAAA,EAClB;AAAA,EAEA,mBAAmB,YAAY,WAAmB;AAChD,WAAO,KAAK,UAAU,SAAS,GAAG,mBAAmB;AAAA,EACvD;AACF;","names":[]}
@@ -0,0 +1,180 @@
1
+ import {
2
+ log
3
+ } from "./chunk-2ODBA7MQ.js";
4
+
5
+ // src/temporal-supersession.ts
6
+ function normalizeSupersessionKey(raw) {
7
+ return raw.trim().toLowerCase().replace(/[\s\-]+/g, "-").replace(/^-+|-+$/g, "");
8
+ }
9
+ function computeSupersessionKey(entityRef, attributeName) {
10
+ if (!entityRef || typeof entityRef !== "string") return null;
11
+ if (!attributeName || typeof attributeName !== "string") return null;
12
+ const entity = normalizeSupersessionKey(entityRef);
13
+ const attr = normalizeSupersessionKey(attributeName);
14
+ if (entity.length === 0 || attr.length === 0) return null;
15
+ return `${entity}::${attr}`;
16
+ }
17
+ function supersessionKeysForFact(spec) {
18
+ if (!spec.entityRef) return [];
19
+ if (!spec.structuredAttributes) return [];
20
+ const keys = [];
21
+ for (const attrName of Object.keys(spec.structuredAttributes)) {
22
+ const key = computeSupersessionKey(spec.entityRef, attrName);
23
+ if (key) keys.push(key);
24
+ }
25
+ return keys;
26
+ }
27
+ function lookupAttributeByNormalizedKey(attributes, rawKey) {
28
+ const normalizedTarget = normalizeSupersessionKey(rawKey);
29
+ for (const [k, v] of Object.entries(attributes)) {
30
+ if (normalizeSupersessionKey(k) === normalizedTarget) return v;
31
+ }
32
+ return void 0;
33
+ }
34
+ function shouldSupersedeExisting(args) {
35
+ const { candidate, newEntityRef, newAttributes, newCreatedAt, newMemoryId } = args;
36
+ if (candidate.id === newMemoryId) return null;
37
+ if (candidate.status && candidate.status !== "active") return null;
38
+ if (!candidate.entityRef) return null;
39
+ if (!candidate.structuredAttributes) return null;
40
+ const candidateEntityNorm = normalizeSupersessionKey(candidate.entityRef);
41
+ const newEntityNorm = normalizeSupersessionKey(newEntityRef);
42
+ if (candidateEntityNorm !== newEntityNorm) return null;
43
+ const candidateCreated = Date.parse(candidate.created);
44
+ const newCreated = Date.parse(newCreatedAt);
45
+ if (!Number.isFinite(candidateCreated) || !Number.isFinite(newCreated)) return null;
46
+ if (candidateCreated >= newCreated) return null;
47
+ const matchedKeys = [];
48
+ for (const [attrName, newValue] of Object.entries(newAttributes)) {
49
+ const candidateValue = lookupAttributeByNormalizedKey(
50
+ candidate.structuredAttributes,
51
+ attrName
52
+ );
53
+ if (candidateValue === void 0) continue;
54
+ if (normalizeValue(String(candidateValue)) === normalizeValue(newValue)) continue;
55
+ const key = computeSupersessionKey(newEntityRef, attrName);
56
+ if (key) matchedKeys.push(key);
57
+ }
58
+ return matchedKeys.length > 0 ? { matchedKeys } : null;
59
+ }
60
+ function normalizeValue(v) {
61
+ return v.trim().toLowerCase();
62
+ }
63
+ async function applyTemporalSupersession(args) {
64
+ const empty = { supersededIds: [], matchedKeys: [] };
65
+ if (!args.enabled) return empty;
66
+ if (!args.entityRef) return empty;
67
+ if (!args.structuredAttributes) return empty;
68
+ if (Object.keys(args.structuredAttributes).length === 0) return empty;
69
+ const newKeys = supersessionKeysForFact({
70
+ entityRef: args.entityRef,
71
+ structuredAttributes: args.structuredAttributes
72
+ });
73
+ if (newKeys.length === 0) return empty;
74
+ let hotMemories;
75
+ try {
76
+ hotMemories = await args.storage.readAllMemories();
77
+ } catch (err) {
78
+ log.warn(`temporal-supersession: readAllMemories failed: ${err}`);
79
+ return empty;
80
+ }
81
+ const newMemoryFile = hotMemories.find((m) => m.frontmatter.id === args.newMemoryId);
82
+ const persistedCreatedAt = args.useCallerTimestamp ? args.createdAt : newMemoryFile?.frontmatter.created ?? args.createdAt;
83
+ const supersededIds = [];
84
+ const matchedKeys = /* @__PURE__ */ new Set();
85
+ const processedIds = /* @__PURE__ */ new Set();
86
+ let coldMemories;
87
+ try {
88
+ coldMemories = await args.storage.readAllColdMemories();
89
+ } catch (err) {
90
+ log.warn(`temporal-supersession: readAllColdMemories failed: ${err}`);
91
+ coldMemories = [];
92
+ }
93
+ const allCandidates = [...hotMemories, ...coldMemories];
94
+ for (const memory of allCandidates) {
95
+ if (memory.frontmatter.id === args.newMemoryId) continue;
96
+ const dedupeKey = memory.frontmatter.id ?? memory.path;
97
+ if (processedIds.has(dedupeKey)) continue;
98
+ const decision = shouldSupersedeExisting({
99
+ candidate: memory.frontmatter,
100
+ newEntityRef: args.entityRef,
101
+ newAttributes: args.structuredAttributes,
102
+ newCreatedAt: persistedCreatedAt,
103
+ newMemoryId: args.newMemoryId
104
+ });
105
+ if (!decision) {
106
+ processedIds.add(dedupeKey);
107
+ continue;
108
+ }
109
+ try {
110
+ const fresh = await args.storage.readMemoryByPath(memory.path);
111
+ if (!fresh) {
112
+ log.debug(
113
+ `[engram] temporal supersession skipped candidate ${memory.frontmatter.id}: no longer readable at ${memory.path} \u2014 leaving id available for alternate tier`
114
+ );
115
+ continue;
116
+ }
117
+ processedIds.add(dedupeKey);
118
+ const freshStatus = fresh.frontmatter.status ?? "active";
119
+ if (freshStatus !== "active" || fresh.frontmatter.supersededBy) {
120
+ log.debug(
121
+ `[engram] temporal supersession skipped candidate ${memory.frontmatter.id}: already superseded by concurrent writer`
122
+ );
123
+ continue;
124
+ }
125
+ const oldCreatedMs = new Date(fresh.frontmatter.created).getTime();
126
+ const newCreatedMs = new Date(persistedCreatedAt).getTime();
127
+ const argCreatedMs = new Date(args.createdAt).getTime();
128
+ const maxMs = Math.max(
129
+ Number.isFinite(oldCreatedMs) ? oldCreatedMs : 0,
130
+ Number.isFinite(newCreatedMs) ? newCreatedMs : 0,
131
+ Number.isFinite(argCreatedMs) ? argCreatedMs : 0
132
+ );
133
+ const supersededAt = new Date(maxMs).toISOString();
134
+ const wrote = await args.storage.writeMemoryFrontmatter(
135
+ fresh,
136
+ {
137
+ status: "superseded",
138
+ supersededBy: args.newMemoryId,
139
+ supersededAt,
140
+ updated: supersededAt
141
+ },
142
+ {
143
+ actor: "temporal-supersession",
144
+ reasonCode: "structured-attribute-update",
145
+ relatedMemoryIds: [args.newMemoryId]
146
+ }
147
+ );
148
+ if (wrote) {
149
+ supersededIds.push(memory.frontmatter.id);
150
+ for (const key of decision.matchedKeys) matchedKeys.add(key);
151
+ }
152
+ } catch (err) {
153
+ log.warn(
154
+ `temporal-supersession: failed to mark ${memory.frontmatter.id} superseded: ${err}`
155
+ );
156
+ }
157
+ }
158
+ if (supersededIds.length > 0) {
159
+ log.debug(
160
+ `temporal-supersession: marked ${supersededIds.length} memories superseded by ${args.newMemoryId} (keys=${Array.from(matchedKeys).join(",")})`
161
+ );
162
+ }
163
+ return { supersededIds, matchedKeys: Array.from(matchedKeys) };
164
+ }
165
+ function shouldFilterSupersededFromRecall(frontmatter, options) {
166
+ if (!options.enabled) return false;
167
+ if (options.includeInRecall) return false;
168
+ return frontmatter.status === "superseded";
169
+ }
170
+
171
+ export {
172
+ normalizeSupersessionKey,
173
+ computeSupersessionKey,
174
+ supersessionKeysForFact,
175
+ lookupAttributeByNormalizedKey,
176
+ shouldSupersedeExisting,
177
+ applyTemporalSupersession,
178
+ shouldFilterSupersededFromRecall
179
+ };
180
+ //# sourceMappingURL=chunk-W6SL7OFG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/temporal-supersession.ts"],"sourcesContent":["/**\n * Temporal Supersession (issue #375)\n *\n * When a new fact lands with `structuredAttributes` keyed on a known\n * `entityRef`, any prior fact whose supersession key collides with the new\n * fact's key is marked `status: \"superseded\"` and linked via\n * `supersededBy` / `supersededAt`. Recall filters those superseded memories\n * by default so agents see only the \"current\" value per entity attribute.\n *\n * The algorithm is intentionally O(N) over the memory corpus per write, but\n * skips cheaply when the new fact has no structuredAttributes. It reuses the\n * cached `readAllMemories()` path so cost is amortized with the rest of the\n * write pipeline.\n */\nimport type { MemoryFile, MemoryFrontmatter } from \"./types.js\";\nimport type { StorageManager } from \"./storage.js\";\nimport { log } from \"./logger.js\";\n\n/**\n * Shared normalization for supersession key components.\n *\n * Trims surrounding whitespace, lowercases, then collapses any run of\n * whitespace OR hyphens to a single hyphen, and strips any leading/trailing\n * hyphens that result. Both `computeSupersessionKey` and\n * `lookupAttributeByNormalizedKey` must use this so that keys produced at\n * write time and keys used at lookup time are identical regardless of how\n * the LLM encoded whitespace, hyphens, or casing (Finding B fix).\n *\n * Symmetry guarantee: `\"foo bar\"`, `\"foo-bar\"`, `\"foo - bar\"`, and\n * `\"foo bar\"` all canonicalize to `\"foo-bar\"`.\n *\n * Exported so external tests can verify the canonical form.\n */\nexport function normalizeSupersessionKey(raw: string): string {\n return raw\n .trim()\n .toLowerCase()\n .replace(/[\\s\\-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\n\n/**\n * Stable supersession key for an (entityRef, attributeName) pair.\n *\n * The algorithm is:\n * - normalize the entityRef (trim, lower-case, collapse whitespace)\n * - normalize the attributeName the same way\n * - join with `::`\n *\n * Exported so tests and tools can recompute it without depending on storage.\n */\nexport function computeSupersessionKey(\n entityRef: string | undefined,\n attributeName: string,\n): string | null {\n if (!entityRef || typeof entityRef !== \"string\") return null;\n if (!attributeName || typeof attributeName !== \"string\") return null;\n const entity = normalizeSupersessionKey(entityRef);\n const attr = normalizeSupersessionKey(attributeName);\n if (entity.length === 0 || attr.length === 0) return null;\n return `${entity}::${attr}`;\n}\n\n/**\n * Compute the full set of supersession keys for a fact with structured\n * attributes. Returns an empty array if no keys can be derived.\n */\nexport function supersessionKeysForFact(spec: {\n entityRef?: string;\n structuredAttributes?: Record<string, string>;\n}): string[] {\n if (!spec.entityRef) return [];\n if (!spec.structuredAttributes) return [];\n const keys: string[] = [];\n for (const attrName of Object.keys(spec.structuredAttributes)) {\n const key = computeSupersessionKey(spec.entityRef, attrName);\n if (key) keys.push(key);\n }\n return keys;\n}\n\n/**\n * Look up a structured-attribute value by a raw key, normalizing both sides\n * with `normalizeSupersessionKey` before comparing. This ensures that keys\n * written by the LLM with mixed case, surrounding whitespace, or internal\n * whitespace (e.g. `\"City\"`, `\" city \"`, `\"job title\"`, `\"job-title\"`)\n * are all matched against normalized keys produced by `computeSupersessionKey`\n * (Finding B fix — uses the same helper so both sides are identical).\n *\n * The storage format is NOT changed — we only normalize at lookup time.\n */\nexport function lookupAttributeByNormalizedKey(\n attributes: Record<string, unknown>,\n rawKey: string,\n): unknown {\n const normalizedTarget = normalizeSupersessionKey(rawKey);\n for (const [k, v] of Object.entries(attributes)) {\n if (normalizeSupersessionKey(k) === normalizedTarget) return v;\n }\n return undefined;\n}\n\n/**\n * Decide whether an existing memory should be superseded by a newly-written\n * memory that carries the supplied supersession key set.\n *\n * Only memories that:\n * - are currently `active`\n * - share an `entityRef` with the new fact\n * - share at least one supersession key with the new fact\n * - are older than the new fact\n * - have a conflicting value (different string) for the overlapping key\n * are eligible. This keeps supersession local to the attribute that actually\n * changed — if fact A sets `{city: Austin, tool: vim}` and fact B sets\n * `{city: NYC}`, only the city attribute is superseded, not the tool.\n */\nexport function shouldSupersedeExisting(args: {\n candidate: MemoryFrontmatter;\n newEntityRef: string;\n newAttributes: Record<string, string>;\n newCreatedAt: string;\n newMemoryId: string;\n}): { matchedKeys: string[] } | null {\n const { candidate, newEntityRef, newAttributes, newCreatedAt, newMemoryId } = args;\n\n if (candidate.id === newMemoryId) return null;\n if (candidate.status && candidate.status !== \"active\") return null;\n if (!candidate.entityRef) return null;\n if (!candidate.structuredAttributes) return null;\n\n // Reuse the shared `normalizeSupersessionKey` helper so this comparison\n // cannot drift from the canonical form used to build supersession keys\n // elsewhere in this file.\n const candidateEntityNorm = normalizeSupersessionKey(candidate.entityRef);\n const newEntityNorm = normalizeSupersessionKey(newEntityRef);\n if (candidateEntityNorm !== newEntityNorm) return null;\n\n // Must be older than the new fact — equal timestamps are ignored to avoid\n // races within the same millisecond.\n const candidateCreated = Date.parse(candidate.created);\n const newCreated = Date.parse(newCreatedAt);\n if (!Number.isFinite(candidateCreated) || !Number.isFinite(newCreated)) return null;\n if (candidateCreated >= newCreated) return null;\n\n const matchedKeys: string[] = [];\n for (const [attrName, newValue] of Object.entries(newAttributes)) {\n // Use normalized key lookup so mixed-case or whitespace-padded keys\n // stored by the LLM are matched correctly (Finding 2 fix).\n const candidateValue = lookupAttributeByNormalizedKey(\n candidate.structuredAttributes,\n attrName,\n );\n if (candidateValue === undefined) continue;\n // Only supersede on conflicting values — identical values are a no-op.\n if (normalizeValue(String(candidateValue)) === normalizeValue(newValue)) continue;\n const key = computeSupersessionKey(newEntityRef, attrName);\n if (key) matchedKeys.push(key);\n }\n\n return matchedKeys.length > 0 ? { matchedKeys } : null;\n}\n\nfunction normalizeValue(v: string): string {\n return v.trim().toLowerCase();\n}\n\nexport interface TemporalSupersessionResult {\n supersededIds: string[];\n matchedKeys: string[];\n}\n\n/**\n * Scan existing memories and mark any that are superseded by the\n * just-written memory. Fails open on I/O errors — the new memory is already\n * on disk, and supersession is a best-effort hygiene step.\n */\nexport async function applyTemporalSupersession(args: {\n storage: StorageManager;\n newMemoryId: string;\n entityRef?: string;\n structuredAttributes?: Record<string, string>;\n createdAt: string;\n enabled: boolean;\n /**\n * When true, skip the persisted `frontmatter.created` lookup and use\n * `args.createdAt` directly as the ordering anchor. Set this on the\n * hash-dedup short-circuit path where `newMemoryId` points to an existing\n * OLD fact (no new file is written) and its persisted timestamp would be\n * stale relative to the incoming promotion event (PR #402 Finding Uyui).\n */\n useCallerTimestamp?: boolean;\n}): Promise<TemporalSupersessionResult> {\n const empty: TemporalSupersessionResult = { supersededIds: [], matchedKeys: [] };\n if (!args.enabled) return empty;\n if (!args.entityRef) return empty;\n if (!args.structuredAttributes) return empty;\n if (Object.keys(args.structuredAttributes).length === 0) return empty;\n\n const newKeys = supersessionKeysForFact({\n entityRef: args.entityRef,\n structuredAttributes: args.structuredAttributes,\n });\n if (newKeys.length === 0) return empty;\n\n let hotMemories: MemoryFile[];\n try {\n hotMemories = await args.storage.readAllMemories();\n } catch (err) {\n log.warn(`temporal-supersession: readAllMemories failed: ${err}`);\n return empty;\n }\n\n // Finding 1 fix: use the on-disk `frontmatter.created` of the newly-written\n // memory rather than a wall-clock timestamp sampled after `writeMemory`\n // returns. In concurrent writers the two can differ by enough to cause\n // wrong-direction supersession. If the memory is not yet visible in the\n // cache (edge case during fast concurrent writes) fall back to args.createdAt.\n //\n // PR #402 round-12 (Finding Uyui): on the hash-dedup early-return path the\n // caller supplies the OLD matching fact's id as `newMemoryId` (no new file is\n // written). That makes `newMemoryFile.frontmatter.created` an arbitrarily\n // old timestamp. When `args.useCallerTimestamp` is set the caller explicitly\n // opts out of the persisted-timestamp lookup so `args.createdAt` (the current\n // wall-clock) is used directly, keeping ordering correct regardless of how\n // old the matching fact is.\n const newMemoryFile = hotMemories.find((m) => m.frontmatter.id === args.newMemoryId);\n const persistedCreatedAt = args.useCallerTimestamp\n ? args.createdAt\n : (newMemoryFile?.frontmatter.created ?? args.createdAt);\n\n const supersededIds: string[] = [];\n const matchedKeys = new Set<string>();\n\n // Process hot then cold. Hot-then-cold ordering is safer because hot\n // writes are more frequent and the CAS re-read guards against double-writes.\n // A Set<string> of already-processed ids ensures that a memory visible in\n // both tiers (same logical memory with different filesystem paths during a\n // migration race) is processed at most once. Keying on `frontmatter.id`\n // is correct because the same logical memory has the same id regardless of\n // which tier's directory it currently lives in (PR #402 Finding 1 fix).\n // Fall back to path-based keying when id is absent (defensive).\n const processedIds = new Set<string>();\n\n // Finding UOGi fix (round-6): readAllColdMemories() performs a full uncached\n // recursive directory scan of cold/. After Finding UTsP broadened the scan\n // to cover the entire cold root (not just facts/+corrections/), the per-call\n // cost grows with the cold tree size.\n //\n // The fix is a TTL-based in-memory cache inside StorageManager\n // (readAllColdMemories caches its result for COLD_SCAN_CACHE_TTL_MS) that is\n // shared across consecutive supersession calls within the same write burst.\n // The cache is invalidated automatically on any hot→cold demotion (which\n // calls invalidateAllMemoriesCache, which also clears the cold cache) and\n // expires after the TTL as a safety net.\n //\n // This means back-to-back structured-attribute writes in the same burst\n // (e.g. batch extraction) pay the cold I/O cost at most once, not N times.\n // Correctness is preserved because the cache TTL ensures eventual consistency\n // and the invalidation hook covers the hot→cold path.\n\n let coldMemories: MemoryFile[];\n try {\n coldMemories = await args.storage.readAllColdMemories();\n } catch (err) {\n log.warn(`temporal-supersession: readAllColdMemories failed: ${err}`);\n coldMemories = [];\n }\n\n // Combine hot and cold memories into a single scan. New memory itself is\n // excluded inline. We do NOT skip cold scan when hot produced zero\n // supersessions — the P1 finding is precisely that stale cold facts leak\n // when hot has no hits.\n const allCandidates: MemoryFile[] = [...hotMemories, ...coldMemories];\n\n for (const memory of allCandidates) {\n if (memory.frontmatter.id === args.newMemoryId) continue;\n const dedupeKey = memory.frontmatter.id ?? memory.path;\n if (processedIds.has(dedupeKey)) continue;\n // NOTE: do NOT call processedIds.add(dedupeKey) here. We defer marking\n // the id as processed until AFTER the CAS re-read succeeds. If we mark\n // it here and the re-read fails (e.g. the hot entry has already been\n // migrated to cold storage), the same logical id that appears later in\n // the cold tier scan would be silently skipped, leaving a stale cold\n // fact unsuperseded. Deferring ensures that a failed primary-tier read\n // grants the alternate tier a chance to process the same id (PR #402\n // round-6 Finding 1 fix).\n\n const decision = shouldSupersedeExisting({\n candidate: memory.frontmatter,\n newEntityRef: args.entityRef,\n newAttributes: args.structuredAttributes,\n newCreatedAt: persistedCreatedAt,\n newMemoryId: args.newMemoryId,\n });\n if (!decision) {\n // No supersession decision — safe to mark as processed now so the\n // alternate tier doesn't re-evaluate an identical non-matching entry.\n processedIds.add(dedupeKey);\n continue;\n }\n\n try {\n // CAS-style re-read immediately before the write. `readAllMemories()`\n // is a snapshot — with concurrent writers, another run may have already\n // superseded this candidate since we loaded it. If we blindly trust the\n // snapshot we can clobber a newer `supersededBy` link with a stale one.\n //\n // File storage offers no true locking, so the best we can do is:\n // 1. re-read the exact file we're about to mutate\n // 2. verify status is still \"active\" and no `supersededBy` is set\n // 3. only then issue the write\n // If the re-read shows a newer concurrent writer beat us to it, skip.\n // This CAS pattern applies equally to hot and cold tier candidates.\n // Mark as processed AFTER confirming the candidate is readable so that\n // a migration-race read failure on the hot entry does not silently\n // prevent the cold entry from being evaluated (Finding 1, round 6).\n const fresh = await args.storage.readMemoryByPath(memory.path);\n if (!fresh) {\n log.debug(\n `[engram] temporal supersession skipped candidate ${memory.frontmatter.id}: no longer readable at ${memory.path} — leaving id available for alternate tier`,\n );\n // Do NOT add to processedIds — allow the cold-tier copy to be\n // evaluated in the next iteration of the same scan.\n continue;\n }\n // Candidate is readable — mark the id as processed now to prevent the\n // alternate tier from double-writing.\n processedIds.add(dedupeKey);\n const freshStatus = fresh.frontmatter.status ?? \"active\";\n if (freshStatus !== \"active\" || fresh.frontmatter.supersededBy) {\n log.debug(\n `[engram] temporal supersession skipped candidate ${memory.frontmatter.id}: already superseded by concurrent writer`,\n );\n continue;\n }\n\n // Finding 2 fix: the `supersededAt` / `updated` timestamps written to the\n // old fact must never run backwards relative to its own persisted\n // `created` timestamp. If the caller-supplied `args.createdAt` (which\n // represents \"when the new replacing fact was authored\") is earlier than\n // either the new fact's persisted `created` (T_new) or the old fact's\n // persisted `created` (T_old), we'd be writing a nonsensical\n // `supersededAt` that precedes the old memory's own creation. Clamp to\n // the monotonic maximum so time only moves forward.\n // This monotonic clamp is applied for both hot and cold tier writes.\n const oldCreatedMs = new Date(fresh.frontmatter.created).getTime();\n const newCreatedMs = new Date(persistedCreatedAt).getTime();\n const argCreatedMs = new Date(args.createdAt).getTime();\n const maxMs = Math.max(\n Number.isFinite(oldCreatedMs) ? oldCreatedMs : 0,\n Number.isFinite(newCreatedMs) ? newCreatedMs : 0,\n Number.isFinite(argCreatedMs) ? argCreatedMs : 0,\n );\n const supersededAt = new Date(maxMs).toISOString();\n\n const wrote = await args.storage.writeMemoryFrontmatter(\n fresh,\n {\n status: \"superseded\",\n supersededBy: args.newMemoryId,\n supersededAt,\n updated: supersededAt,\n },\n {\n actor: \"temporal-supersession\",\n reasonCode: \"structured-attribute-update\",\n relatedMemoryIds: [args.newMemoryId],\n },\n );\n if (wrote) {\n supersededIds.push(memory.frontmatter.id);\n for (const key of decision.matchedKeys) matchedKeys.add(key);\n }\n } catch (err) {\n log.warn(\n `temporal-supersession: failed to mark ${memory.frontmatter.id} superseded: ${err}`,\n );\n }\n }\n\n if (supersededIds.length > 0) {\n log.debug(\n `temporal-supersession: marked ${supersededIds.length} memories superseded by ${args.newMemoryId} (keys=${Array.from(matchedKeys).join(\",\")})`,\n );\n }\n\n return { supersededIds, matchedKeys: Array.from(matchedKeys) };\n}\n\n/**\n * Recall-side filter: returns true when the candidate should be excluded\n * from recall because it has been temporally superseded. When\n * `includeInRecall` is true, this always returns false (the fact is kept),\n * matching the audit/history opt-in described in the config.\n */\nexport function shouldFilterSupersededFromRecall(\n frontmatter: MemoryFrontmatter,\n options: { enabled: boolean; includeInRecall: boolean },\n): boolean {\n if (!options.enabled) return false;\n if (options.includeInRecall) return false;\n return frontmatter.status === \"superseded\";\n}\n"],"mappings":";;;;;AAiCO,SAAS,yBAAyB,KAAqB;AAC5D,SAAO,IACJ,KAAK,EACL,YAAY,EACZ,QAAQ,YAAY,GAAG,EACvB,QAAQ,YAAY,EAAE;AAC3B;AAYO,SAAS,uBACd,WACA,eACe;AACf,MAAI,CAAC,aAAa,OAAO,cAAc,SAAU,QAAO;AACxD,MAAI,CAAC,iBAAiB,OAAO,kBAAkB,SAAU,QAAO;AAChE,QAAM,SAAS,yBAAyB,SAAS;AACjD,QAAM,OAAO,yBAAyB,aAAa;AAC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