@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,789 @@
1
+ import {
2
+ discoverMemoryExtensions,
3
+ renderExtensionsBlock,
4
+ resolveExtensionsRoot
5
+ } from "./chunk-EJI5XIBB.js";
6
+ import {
7
+ countRecallTokenOverlap,
8
+ normalizeRecallTokens
9
+ } from "./chunk-DT5TVLJE.js";
10
+ import {
11
+ StorageManager
12
+ } from "./chunk-GV6NLQ4X.js";
13
+ import {
14
+ log
15
+ } from "./chunk-2ODBA7MQ.js";
16
+
17
+ // src/connectors/codex-materialize-runner.ts
18
+ import path2 from "path";
19
+ import { existsSync as existsSync2 } from "fs";
20
+
21
+ // src/connectors/codex-materialize.ts
22
+ import {
23
+ createHash
24
+ } from "crypto";
25
+ import {
26
+ existsSync,
27
+ mkdirSync,
28
+ readdirSync,
29
+ readFileSync,
30
+ renameSync,
31
+ rmSync,
32
+ statSync,
33
+ unlinkSync,
34
+ writeFileSync
35
+ } from "fs";
36
+ import path from "path";
37
+ var MATERIALIZE_VERSION = 1;
38
+ var SENTINEL_FILE = ".remnic-managed";
39
+ var TMP_DIR = ".remnic-tmp";
40
+ var OWNED_FILES = /* @__PURE__ */ new Set([
41
+ "memory_summary.md",
42
+ "MEMORY.md",
43
+ "raw_memories.md"
44
+ ]);
45
+ var ROLLOUT_SUBDIR = "rollout_summaries";
46
+ function materializeForNamespace(namespace, options) {
47
+ const logger = options.logger ?? {
48
+ info: (msg) => log.info(`[codex-materialize] ${msg}`),
49
+ warn: (msg) => log.warn(`[codex-materialize] ${msg}`),
50
+ debug: (msg) => log.debug(`[codex-materialize] ${msg}`)
51
+ };
52
+ const codexHome = resolveCodexHome(options.codexHome);
53
+ const memoriesDir = path.join(codexHome, "memories");
54
+ const now = options.now ?? /* @__PURE__ */ new Date();
55
+ const maxSummaryTokens = typeof options.maxSummaryTokens === "number" && options.maxSummaryTokens >= 0 ? options.maxSummaryTokens : 4500;
56
+ const rolloutRetentionDays = typeof options.rolloutRetentionDays === "number" && options.rolloutRetentionDays >= 0 ? options.rolloutRetentionDays : 30;
57
+ const sentinelPath = path.join(memoriesDir, SENTINEL_FILE);
58
+ const existingSentinel = readSentinel(sentinelPath);
59
+ if (!existingSentinel) {
60
+ if (existsSync(memoriesDir)) {
61
+ logger.warn(
62
+ `sentinel ${SENTINEL_FILE} missing in ${memoriesDir}; skipping materialization to preserve hand-edits`
63
+ );
64
+ } else {
65
+ logger.debug?.(
66
+ `skipping materialization \u2014 ${memoriesDir} does not exist (user not opted in)`
67
+ );
68
+ }
69
+ return {
70
+ namespace,
71
+ memoriesDir,
72
+ wrote: false,
73
+ skippedNoSentinel: true,
74
+ skippedIdempotent: false,
75
+ filesWritten: [],
76
+ contentHash: ""
77
+ };
78
+ }
79
+ mkdirSync(memoriesDir, { recursive: true });
80
+ const memories = [...options.memories];
81
+ const rolloutsSupplied = options.rolloutSummaries !== void 0;
82
+ const rolloutSummaries = options.rolloutSummaries ?? [];
83
+ const retainedRollouts = pruneRollouts(rolloutSummaries, rolloutRetentionDays, now);
84
+ const dedupedRollouts = [];
85
+ const seenNames = /* @__PURE__ */ new Map();
86
+ const parseTs = (value) => {
87
+ if (!value) return Number.NEGATIVE_INFINITY;
88
+ const parsed = Date.parse(value);
89
+ return Number.isFinite(parsed) ? parsed : Number.NEGATIVE_INFINITY;
90
+ };
91
+ for (const r of retainedRollouts) {
92
+ const name = `${sanitizeSlug(r.slug)}.md`;
93
+ const existingIdx = seenNames.get(name);
94
+ if (existingIdx === void 0) {
95
+ seenNames.set(name, dedupedRollouts.length);
96
+ dedupedRollouts.push(r);
97
+ continue;
98
+ }
99
+ const existing = dedupedRollouts[existingIdx];
100
+ if (parseTs(r.updatedAt) > parseTs(existing.updatedAt)) {
101
+ dedupedRollouts[existingIdx] = r;
102
+ }
103
+ }
104
+ const memorySummary = renderMemorySummary({
105
+ namespace,
106
+ memories,
107
+ rolloutSummaries: dedupedRollouts,
108
+ maxTokens: maxSummaryTokens
109
+ });
110
+ const memoryMd = renderMemoryMd({
111
+ namespace,
112
+ memories,
113
+ rolloutSummaries: dedupedRollouts
114
+ });
115
+ const validation = validateMemoryMd(memoryMd);
116
+ if (!validation.valid) {
117
+ const reason = validation.errors.join("; ");
118
+ logger.warn(`MEMORY.md failed schema validation: ${reason}`);
119
+ throw new Error(`codex-materialize: MEMORY.md schema validation failed: ${reason}`);
120
+ }
121
+ const rawMemories = renderRawMemories({ memories });
122
+ const rolloutFiles = dedupedRollouts.map((r) => ({
123
+ name: `${sanitizeSlug(r.slug)}.md`,
124
+ body: renderRolloutSummary(r)
125
+ }));
126
+ const hash = computeContentHash({
127
+ namespace,
128
+ memorySummary,
129
+ memoryMd,
130
+ rawMemories,
131
+ rolloutFiles
132
+ });
133
+ if (existingSentinel.content_hash === hash) {
134
+ const requiredFiles = [
135
+ path.join(memoriesDir, "memory_summary.md"),
136
+ path.join(memoriesDir, "MEMORY.md"),
137
+ path.join(memoriesDir, "raw_memories.md"),
138
+ ...rolloutFiles.map((r) => path.join(memoriesDir, ROLLOUT_SUBDIR, r.name))
139
+ ];
140
+ const allPresent = requiredFiles.every((f) => existsSync(f));
141
+ if (allPresent) {
142
+ logger.debug?.(`no-op materialization for namespace=${namespace} (hash unchanged)`);
143
+ return {
144
+ namespace,
145
+ memoriesDir,
146
+ wrote: false,
147
+ skippedNoSentinel: false,
148
+ skippedIdempotent: true,
149
+ filesWritten: [],
150
+ contentHash: hash
151
+ };
152
+ }
153
+ logger.debug?.(
154
+ `hash unchanged for namespace=${namespace} but managed file missing \u2014 forcing rewrite`
155
+ );
156
+ }
157
+ const runTag = `${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
158
+ const tmpDir = path.join(memoriesDir, `${TMP_DIR}-${runTag}`);
159
+ const TMP_STALE_MS = 60 * 60 * 1e3;
160
+ const wallClockMs = Date.now();
161
+ try {
162
+ for (const entry of readdirSync(memoriesDir, { withFileTypes: true })) {
163
+ if (!entry.isDirectory()) continue;
164
+ if (!entry.name.startsWith(TMP_DIR)) continue;
165
+ const stalePath = path.join(memoriesDir, entry.name);
166
+ try {
167
+ const stat = statSync(stalePath);
168
+ if (wallClockMs - stat.mtimeMs < TMP_STALE_MS) continue;
169
+ rmSync(stalePath, { recursive: true, force: true });
170
+ } catch {
171
+ }
172
+ }
173
+ } catch {
174
+ }
175
+ mkdirSync(tmpDir, { recursive: true });
176
+ mkdirSync(path.join(tmpDir, ROLLOUT_SUBDIR), { recursive: true });
177
+ const filesWritten = [];
178
+ writeFileSync(path.join(tmpDir, "memory_summary.md"), memorySummary);
179
+ filesWritten.push("memory_summary.md");
180
+ writeFileSync(path.join(tmpDir, "MEMORY.md"), memoryMd);
181
+ filesWritten.push("MEMORY.md");
182
+ writeFileSync(path.join(tmpDir, "raw_memories.md"), rawMemories);
183
+ filesWritten.push("raw_memories.md");
184
+ for (const rollout of rolloutFiles) {
185
+ writeFileSync(path.join(tmpDir, ROLLOUT_SUBDIR, rollout.name), rollout.body);
186
+ filesWritten.push(path.join(ROLLOUT_SUBDIR, rollout.name));
187
+ }
188
+ for (const rel of ["memory_summary.md", "MEMORY.md", "raw_memories.md"]) {
189
+ const src = path.join(tmpDir, rel);
190
+ const dest = path.join(memoriesDir, rel);
191
+ renameSync(src, dest);
192
+ }
193
+ const destRolloutsDir = path.join(memoriesDir, ROLLOUT_SUBDIR);
194
+ mkdirSync(destRolloutsDir, { recursive: true });
195
+ if (rolloutsSupplied) {
196
+ const retainedRolloutNames = new Set(rolloutFiles.map((r) => r.name));
197
+ try {
198
+ for (const entry of readdirSync(destRolloutsDir, { withFileTypes: true })) {
199
+ if (!entry.isFile()) continue;
200
+ if (!entry.name.endsWith(".md")) continue;
201
+ if (retainedRolloutNames.has(entry.name)) continue;
202
+ try {
203
+ unlinkSync(path.join(destRolloutsDir, entry.name));
204
+ } catch {
205
+ }
206
+ }
207
+ } catch {
208
+ }
209
+ }
210
+ for (const rollout of rolloutFiles) {
211
+ const src = path.join(tmpDir, ROLLOUT_SUBDIR, rollout.name);
212
+ const dest = path.join(destRolloutsDir, rollout.name);
213
+ renameSync(src, dest);
214
+ }
215
+ const sentinel = {
216
+ version: MATERIALIZE_VERSION,
217
+ namespace,
218
+ updated_at: now.toISOString(),
219
+ content_hash: hash
220
+ };
221
+ writeFileSync(sentinelPath, `${JSON.stringify(sentinel, null, 2)}
222
+ `);
223
+ try {
224
+ rmSync(tmpDir, { recursive: true, force: true });
225
+ } catch {
226
+ }
227
+ logger.info(
228
+ `materialized namespace=${namespace} files=${filesWritten.length} hash=${hash.slice(0, 12)}`
229
+ );
230
+ return {
231
+ namespace,
232
+ memoriesDir,
233
+ wrote: true,
234
+ skippedNoSentinel: false,
235
+ skippedIdempotent: false,
236
+ filesWritten,
237
+ contentHash: hash
238
+ };
239
+ }
240
+ function ensureSentinel(memoriesDir, namespace, now = /* @__PURE__ */ new Date()) {
241
+ mkdirSync(memoriesDir, { recursive: true });
242
+ const sentinelPath = path.join(memoriesDir, SENTINEL_FILE);
243
+ if (existsSync(sentinelPath)) return;
244
+ const sentinel = {
245
+ version: MATERIALIZE_VERSION,
246
+ namespace,
247
+ updated_at: now.toISOString(),
248
+ content_hash: ""
249
+ };
250
+ writeFileSync(sentinelPath, `${JSON.stringify(sentinel, null, 2)}
251
+ `);
252
+ }
253
+ function renderMemorySummary(ctx) {
254
+ const lines = [];
255
+ lines.push("# Memory Summary");
256
+ lines.push("");
257
+ lines.push(`_namespace: ${ctx.namespace}_`);
258
+ lines.push(`_source: remnic_`);
259
+ lines.push("");
260
+ const highValue = selectSummaryMemories(ctx.memories, 12);
261
+ if (highValue.length > 0) {
262
+ lines.push("## Top memories");
263
+ lines.push("");
264
+ for (const mem of highValue) {
265
+ lines.push(`- ${oneLineSummary(mem)}`);
266
+ }
267
+ lines.push("");
268
+ }
269
+ if (ctx.rolloutSummaries.length > 0) {
270
+ lines.push("## Recent rollouts");
271
+ lines.push("");
272
+ const sorted = [...ctx.rolloutSummaries].sort((a, b) => (b.updatedAt ?? "").localeCompare(a.updatedAt ?? "")).slice(0, 5);
273
+ for (const r of sorted) {
274
+ const when = r.updatedAt ? ` (${r.updatedAt})` : "";
275
+ lines.push(`- ${r.slug}${when}`);
276
+ }
277
+ lines.push("");
278
+ }
279
+ const full = lines.join("\n").replace(/\n+$/u, "\n");
280
+ return truncateToTokenBudget(full, ctx.maxTokens);
281
+ }
282
+ function renderMemoryMd(ctx) {
283
+ const lines = [];
284
+ lines.push(`# Task Group: ${ctx.namespace}`);
285
+ lines.push(`scope: ${ctx.namespace}`);
286
+ lines.push(`applies_to: cwd=*; reuse_rule=namespace-match`);
287
+ lines.push("");
288
+ const byCategory = groupMemoriesByCategory(ctx.memories);
289
+ let taskIndex = 1;
290
+ if (byCategory.size === 0) {
291
+ lines.push(`## Task ${taskIndex}: baseline \u2014 no memories yet`);
292
+ lines.push("");
293
+ lines.push("### rollout_summary_files");
294
+ for (const r of ctx.rolloutSummaries) {
295
+ lines.push(
296
+ `- rollout_summaries/${sanitizeSlug(r.slug)}.md (cwd=${r.cwd ?? "*"}, rollout_path=${r.rolloutPath ?? ""}, updated_at=${r.updatedAt ?? ""}, thread_id=${r.threadId ?? ""})`
297
+ );
298
+ }
299
+ if (ctx.rolloutSummaries.length === 0) {
300
+ lines.push("- (none)");
301
+ }
302
+ lines.push("");
303
+ lines.push("### keywords");
304
+ lines.push(`- ${ctx.namespace}`);
305
+ lines.push("");
306
+ taskIndex += 1;
307
+ } else {
308
+ for (const [category, mems] of byCategory) {
309
+ lines.push(`## Task ${taskIndex}: ${category} memories, outcome=surface-to-codex`);
310
+ lines.push("");
311
+ lines.push("### rollout_summary_files");
312
+ const relevantRollouts = ctx.rolloutSummaries.slice(0, 5);
313
+ if (relevantRollouts.length === 0) {
314
+ lines.push("- (none)");
315
+ } else {
316
+ for (const r of relevantRollouts) {
317
+ lines.push(
318
+ `- rollout_summaries/${sanitizeSlug(r.slug)}.md (cwd=${r.cwd ?? "*"}, rollout_path=${r.rolloutPath ?? ""}, updated_at=${r.updatedAt ?? ""}, thread_id=${r.threadId ?? ""})`
319
+ );
320
+ }
321
+ }
322
+ lines.push("");
323
+ lines.push("### keywords");
324
+ const keywords = collectKeywords(mems, category, ctx.namespace);
325
+ lines.push(`- ${keywords.join(", ")}`);
326
+ lines.push("");
327
+ taskIndex += 1;
328
+ }
329
+ }
330
+ lines.push("## User preferences");
331
+ const prefs = pickCategory(ctx.memories, ["preference"]);
332
+ if (prefs.length === 0) {
333
+ lines.push("- (none recorded)");
334
+ } else {
335
+ for (const pref of prefs.slice(0, 20)) {
336
+ lines.push(`- ${oneLineSummary(pref)}`);
337
+ }
338
+ }
339
+ lines.push("");
340
+ lines.push("## Reusable knowledge");
341
+ const knowledge = pickCategory(ctx.memories, ["fact", "decision", "principle", "rule", "skill"]);
342
+ if (knowledge.length === 0) {
343
+ lines.push("- (none recorded)");
344
+ } else {
345
+ for (const mem of knowledge.slice(0, 30)) {
346
+ lines.push(`- ${oneLineSummary(mem)}`);
347
+ }
348
+ }
349
+ lines.push("");
350
+ lines.push("## Failures and how to do differently");
351
+ const corrections = pickCategory(ctx.memories, ["correction"]);
352
+ if (corrections.length === 0) {
353
+ lines.push("- (none recorded)");
354
+ } else {
355
+ for (const mem of corrections.slice(0, 20)) {
356
+ lines.push(`- ${oneLineSummary(mem)}`);
357
+ }
358
+ }
359
+ lines.push("");
360
+ return lines.join("\n");
361
+ }
362
+ function renderRawMemories(ctx) {
363
+ const sorted = [...ctx.memories].sort((a, b) => {
364
+ const aUpdated = a.frontmatter.updated ?? a.frontmatter.created ?? "";
365
+ const bUpdated = b.frontmatter.updated ?? b.frontmatter.created ?? "";
366
+ return bUpdated.localeCompare(aUpdated);
367
+ });
368
+ const lines = ["# Raw Memories", "", "_source: remnic \u2014 latest first_", ""];
369
+ for (const mem of sorted) {
370
+ const fm = mem.frontmatter;
371
+ const id = fm.id ?? "unknown";
372
+ const category = fm.category ?? "unknown";
373
+ const updated = fm.updated ?? fm.created ?? "";
374
+ lines.push(`## ${id} (${category}, updated=${updated})`);
375
+ lines.push("");
376
+ lines.push(mem.content.trim());
377
+ lines.push("");
378
+ }
379
+ return lines.join("\n");
380
+ }
381
+ function renderRolloutSummary(input) {
382
+ const lines = [];
383
+ lines.push(`# Rollout Summary: ${input.slug}`);
384
+ lines.push("");
385
+ const meta = [];
386
+ if (input.cwd) meta.push(`cwd=${input.cwd}`);
387
+ if (input.rolloutPath) meta.push(`rollout_path=${input.rolloutPath}`);
388
+ if (input.updatedAt) meta.push(`updated_at=${input.updatedAt}`);
389
+ if (input.threadId) meta.push(`thread_id=${input.threadId}`);
390
+ if (meta.length > 0) {
391
+ lines.push(`_${meta.join("; ")}_`);
392
+ lines.push("");
393
+ }
394
+ if (input.keywords && input.keywords.length > 0) {
395
+ lines.push(`**keywords:** ${input.keywords.join(", ")}`);
396
+ lines.push("");
397
+ }
398
+ lines.push(input.body.trim());
399
+ lines.push("");
400
+ return lines.join("\n");
401
+ }
402
+ function validateMemoryMd(content) {
403
+ const errors = [];
404
+ const lines = content.split(/\r?\n/u);
405
+ const taskGroupIndex = lines.findIndex((l) => /^#\s+Task Group:\s+\S+/u.test(l));
406
+ if (taskGroupIndex === -1) {
407
+ errors.push("missing `# Task Group:` header");
408
+ } else {
409
+ const tail = lines.slice(taskGroupIndex + 1, taskGroupIndex + 5);
410
+ if (!tail.some((l) => /^scope:\s*\S+/u.test(l))) {
411
+ errors.push("missing `scope:` line under Task Group header");
412
+ }
413
+ if (!tail.some((l) => /^applies_to:\s*\S+/u.test(l))) {
414
+ errors.push("missing `applies_to:` line under Task Group header");
415
+ }
416
+ }
417
+ const taskHeaders = lines.filter((l) => /^##\s+Task\s+\d+:/u.test(l));
418
+ if (taskHeaders.length === 0) {
419
+ errors.push("at least one `## Task N:` section is required");
420
+ }
421
+ const sectionRegex = /^##\s+/u;
422
+ for (let i = 0; i < lines.length; i++) {
423
+ if (!/^##\s+Task\s+\d+:/u.test(lines[i])) continue;
424
+ let hasRollout = false;
425
+ let hasKeywords = false;
426
+ for (let j = i + 1; j < lines.length; j++) {
427
+ if (sectionRegex.test(lines[j])) break;
428
+ if (/^###\s+rollout_summary_files\s*$/u.test(lines[j])) hasRollout = true;
429
+ if (/^###\s+keywords\s*$/u.test(lines[j])) hasKeywords = true;
430
+ }
431
+ if (!hasRollout) errors.push(`task block at line ${i + 1} missing \`### rollout_summary_files\``);
432
+ if (!hasKeywords) errors.push(`task block at line ${i + 1} missing \`### keywords\``);
433
+ }
434
+ const requiredSections = [
435
+ /^##\s+User preferences\s*$/u,
436
+ /^##\s+Reusable knowledge\s*$/u,
437
+ /^##\s+Failures and how to do differently\s*$/u
438
+ ];
439
+ for (const re of requiredSections) {
440
+ if (!lines.some((l) => re.test(l))) {
441
+ errors.push(`missing required section: ${re.source}`);
442
+ }
443
+ }
444
+ return { valid: errors.length === 0, errors };
445
+ }
446
+ function resolveCodexHome(override) {
447
+ if (override && override.trim().length > 0) return override;
448
+ const fromEnv = process.env.CODEX_HOME;
449
+ if (fromEnv && fromEnv.trim().length > 0) return fromEnv;
450
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
451
+ return path.join(home, ".codex");
452
+ }
453
+ function readSentinel(sentinelPath) {
454
+ if (!existsSync(sentinelPath)) return null;
455
+ try {
456
+ const raw = readFileSync(sentinelPath, "utf-8");
457
+ const parsed = JSON.parse(raw);
458
+ if (typeof parsed !== "object" || parsed === null) return null;
459
+ return {
460
+ version: typeof parsed.version === "number" ? parsed.version : MATERIALIZE_VERSION,
461
+ namespace: typeof parsed.namespace === "string" ? parsed.namespace : "",
462
+ updated_at: typeof parsed.updated_at === "string" ? parsed.updated_at : "",
463
+ content_hash: typeof parsed.content_hash === "string" ? parsed.content_hash : ""
464
+ };
465
+ } catch {
466
+ return null;
467
+ }
468
+ }
469
+ function selectSummaryMemories(memories, limit) {
470
+ const scored = memories.filter((m) => !m.frontmatter.status || m.frontmatter.status === "active").map((m) => {
471
+ const confidence = typeof m.frontmatter.confidence === "number" ? m.frontmatter.confidence : 0;
472
+ const importance = typeof m.frontmatter.importance === "object" && m.frontmatter.importance !== null && typeof m.frontmatter.importance.score === "number" ? m.frontmatter.importance.score ?? 0 : 0;
473
+ const updated = m.frontmatter.updated ?? m.frontmatter.created ?? "";
474
+ return { memory: m, score: importance * 2 + confidence, updated };
475
+ });
476
+ scored.sort((a, b) => {
477
+ if (b.score !== a.score) return b.score - a.score;
478
+ return b.updated.localeCompare(a.updated);
479
+ });
480
+ return scored.slice(0, limit).map((s) => s.memory);
481
+ }
482
+ function oneLineSummary(memory) {
483
+ const raw = memory.content.replace(/\s+/gu, " ").trim();
484
+ if (raw.length <= 160) return raw;
485
+ return `${raw.slice(0, 157)}...`;
486
+ }
487
+ function groupMemoriesByCategory(memories) {
488
+ const map = /* @__PURE__ */ new Map();
489
+ for (const memory of memories) {
490
+ if (memory.frontmatter.status && memory.frontmatter.status !== "active") continue;
491
+ const category = memory.frontmatter.category ?? "unknown";
492
+ const list = map.get(category) ?? [];
493
+ list.push(memory);
494
+ map.set(category, list);
495
+ }
496
+ return map;
497
+ }
498
+ function pickCategory(memories, categories) {
499
+ const allowed = new Set(categories);
500
+ return memories.filter(
501
+ (m) => (!m.frontmatter.status || m.frontmatter.status === "active") && allowed.has(m.frontmatter.category ?? "")
502
+ );
503
+ }
504
+ function collectKeywords(memories, category, namespace) {
505
+ const keywords = /* @__PURE__ */ new Set();
506
+ keywords.add(category);
507
+ keywords.add(namespace);
508
+ for (const mem of memories.slice(0, 10)) {
509
+ for (const tag of mem.frontmatter.tags ?? []) {
510
+ if (typeof tag === "string" && tag.trim().length > 0) keywords.add(tag.trim());
511
+ }
512
+ }
513
+ return [...keywords].slice(0, 16);
514
+ }
515
+ function pruneRollouts(rollouts, retentionDays, now) {
516
+ if (retentionDays < 0) return rollouts;
517
+ const cutoffMs = now.getTime() - retentionDays * 24 * 60 * 60 * 1e3;
518
+ return rollouts.filter((r) => {
519
+ if (!r.updatedAt) return true;
520
+ const t = Date.parse(r.updatedAt);
521
+ if (!Number.isFinite(t)) return true;
522
+ return t >= cutoffMs;
523
+ });
524
+ }
525
+ function sanitizeSlug(slug) {
526
+ return slug.toLowerCase().replace(/[^a-z0-9._-]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 96) || "rollout";
527
+ }
528
+ function approximateTokenCount(text) {
529
+ const trimmed = text.trim();
530
+ if (trimmed.length === 0) return 0;
531
+ return trimmed.split(/\s+/u).length;
532
+ }
533
+ function truncateToTokenBudget(text, maxTokens) {
534
+ if (maxTokens <= 0) return "";
535
+ if (approximateTokenCount(text) <= maxTokens) return text;
536
+ const lineMarker = "_[truncated for summary budget]_";
537
+ const tailMarker = "[truncated]";
538
+ const lineMarkerTokens = approximateTokenCount(lineMarker);
539
+ const tailMarkerTokens = approximateTokenCount(tailMarker);
540
+ const lines = text.split(/\r?\n/u);
541
+ const lineBudget = Math.max(0, maxTokens - lineMarkerTokens);
542
+ while (lines.length > 0 && approximateTokenCount(lines.join("\n")) > lineBudget) {
543
+ lines.pop();
544
+ }
545
+ lines.push(lineMarker);
546
+ let result = lines.join("\n");
547
+ if (approximateTokenCount(result) > maxTokens) {
548
+ const tokens = result.split(/\s+/u);
549
+ const keep = Math.max(0, maxTokens - tailMarkerTokens);
550
+ result = keep > 0 ? `${tokens.slice(0, keep).join(" ")} ${tailMarker}` : tailMarker;
551
+ }
552
+ return result;
553
+ }
554
+ function computeContentHash(input) {
555
+ const hash = createHash("sha256");
556
+ hash.update(`v${MATERIALIZE_VERSION}
557
+ `);
558
+ hash.update(`namespace=${input.namespace}
559
+ `);
560
+ hash.update("---memory_summary---\n");
561
+ hash.update(input.memorySummary);
562
+ hash.update("\n---memory_md---\n");
563
+ hash.update(input.memoryMd);
564
+ hash.update("\n---raw_memories---\n");
565
+ hash.update(input.rawMemories);
566
+ const sortedRollouts = [...input.rolloutFiles].sort((a, b) => a.name.localeCompare(b.name));
567
+ for (const r of sortedRollouts) {
568
+ hash.update(`
569
+ ---rollout:${r.name}---
570
+ `);
571
+ hash.update(r.body);
572
+ }
573
+ return hash.digest("hex");
574
+ }
575
+ function describeMemoriesDir(memoriesDir) {
576
+ if (!existsSync(memoriesDir)) return null;
577
+ const sentinelPath = path.join(memoriesDir, SENTINEL_FILE);
578
+ const sentinel = readSentinel(sentinelPath);
579
+ const files = [];
580
+ for (const entry of readdirSync(memoriesDir, { withFileTypes: true })) {
581
+ if (entry.isFile() && OWNED_FILES.has(entry.name)) files.push(entry.name);
582
+ }
583
+ const rolloutsDir = path.join(memoriesDir, ROLLOUT_SUBDIR);
584
+ if (existsSync(rolloutsDir)) {
585
+ try {
586
+ for (const entry of readdirSync(rolloutsDir, { withFileTypes: true })) {
587
+ if (entry.isFile() && entry.name.endsWith(".md")) {
588
+ files.push(path.join(ROLLOUT_SUBDIR, entry.name));
589
+ }
590
+ }
591
+ } catch {
592
+ }
593
+ }
594
+ return {
595
+ exists: true,
596
+ hasSentinel: sentinel !== null,
597
+ files: files.sort(),
598
+ sentinel
599
+ };
600
+ }
601
+
602
+ // src/connectors/codex-materialize-runner.ts
603
+ async function runCodexMaterialize(options) {
604
+ const cfg = options.config;
605
+ if (!cfg.codexMaterializeMemories) {
606
+ log.debug(`[codex-materialize] skipped \u2014 codexMaterializeMemories=false`);
607
+ return null;
608
+ }
609
+ if (options.reason === "session_end" && cfg.codexMaterializeOnSessionEnd === false) {
610
+ log.debug(
611
+ `[codex-materialize] skipped \u2014 session-end disabled via codexMaterializeOnSessionEnd=false`
612
+ );
613
+ return null;
614
+ }
615
+ const namespace = resolveNamespace(options.namespace, cfg);
616
+ const memoryDir = options.memoryDir ?? cfg.memoryDir;
617
+ if (!memoryDir) {
618
+ log.warn(`[codex-materialize] skipped \u2014 no memoryDir available`);
619
+ return null;
620
+ }
621
+ let memories;
622
+ if (options.memories) {
623
+ memories = options.memories;
624
+ } else {
625
+ const nsDir = resolveNamespaceDir(memoryDir, namespace, cfg);
626
+ const storage = new StorageManager(nsDir);
627
+ try {
628
+ memories = await storage.readAllMemories();
629
+ } catch (error) {
630
+ log.warn(
631
+ `[codex-materialize] skipped \u2014 failed to read memories from ${nsDir}: ${error instanceof Error ? error.message : String(error)}`
632
+ );
633
+ return null;
634
+ }
635
+ }
636
+ const result = materializeForNamespace(namespace, {
637
+ memories,
638
+ codexHome: options.codexHome,
639
+ maxSummaryTokens: cfg.codexMaterializeMaxSummaryTokens,
640
+ rolloutRetentionDays: cfg.codexMaterializeRolloutRetentionDays,
641
+ rolloutSummaries: options.rolloutSummaries,
642
+ now: options.now
643
+ });
644
+ if (options.reason) {
645
+ log.debug(
646
+ `[codex-materialize] ran reason=${options.reason} wrote=${result.wrote} files=${result.filesWritten.length}`
647
+ );
648
+ }
649
+ return result;
650
+ }
651
+ async function runPostConsolidationMaterialize(logPrefix, options) {
652
+ if (!options.config.codexMaterializeMemories) return null;
653
+ if (!options.config.codexMaterializeOnConsolidation) return null;
654
+ try {
655
+ return await runCodexMaterialize({
656
+ config: options.config,
657
+ namespace: options.namespace,
658
+ memories: options.memories,
659
+ memoryDir: options.memoryDir,
660
+ codexHome: options.codexHome,
661
+ rolloutSummaries: options.rolloutSummaries,
662
+ now: options.now,
663
+ reason: "consolidation"
664
+ });
665
+ } catch (error) {
666
+ log.warn(
667
+ `${logPrefix} Codex materialize post-hook failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`
668
+ );
669
+ return null;
670
+ }
671
+ }
672
+ function resolveNamespace(override, cfg) {
673
+ const requested = (override ?? cfg.codexMaterializeNamespace ?? "auto").trim();
674
+ if (requested.length === 0 || requested === "auto") {
675
+ return cfg.defaultNamespace && cfg.defaultNamespace.length > 0 ? cfg.defaultNamespace : "default";
676
+ }
677
+ return requested;
678
+ }
679
+ function resolveNamespaceDir(memoryDir, namespace, cfg) {
680
+ if (!cfg.namespacesEnabled) return memoryDir;
681
+ const ns = namespace || cfg.defaultNamespace || "default";
682
+ const namespacedRoot = path2.join(memoryDir, "namespaces", ns);
683
+ if (ns === cfg.defaultNamespace) {
684
+ return existsSync2(namespacedRoot) ? namespacedRoot : memoryDir;
685
+ }
686
+ return namespacedRoot;
687
+ }
688
+
689
+ // src/semantic-consolidation.ts
690
+ function findSimilarClusters(memories, config) {
691
+ const excluded = new Set(config.excludeCategories);
692
+ const byCategory = /* @__PURE__ */ new Map();
693
+ for (const m of memories) {
694
+ const cat = m.frontmatter.category;
695
+ if (excluded.has(cat)) continue;
696
+ if (m.frontmatter.status && m.frontmatter.status !== "active") continue;
697
+ const list = byCategory.get(cat) ?? [];
698
+ list.push(m);
699
+ byCategory.set(cat, list);
700
+ }
701
+ const clusters = [];
702
+ let totalCandidates = 0;
703
+ for (const [category, mems] of byCategory) {
704
+ if (totalCandidates >= config.maxPerRun) break;
705
+ const tokenized = mems.map((m) => ({
706
+ memory: m,
707
+ tokens: new Set(normalizeRecallTokens(m.content, []))
708
+ }));
709
+ const clustered = /* @__PURE__ */ new Set();
710
+ for (let i = 0; i < tokenized.length && totalCandidates < config.maxPerRun; i++) {
711
+ if (clustered.has(tokenized[i].memory.frontmatter.id)) continue;
712
+ const cluster = [tokenized[i].memory];
713
+ let totalOverlap = 0;
714
+ let comparisons = 0;
715
+ for (let j = i + 1; j < tokenized.length; j++) {
716
+ if (clustered.has(tokenized[j].memory.frontmatter.id)) continue;
717
+ const aTokens = tokenized[i].tokens;
718
+ const bTokens = tokenized[j].tokens;
719
+ if (aTokens.size === 0 || bTokens.size === 0) continue;
720
+ const overlap = countRecallTokenOverlap(aTokens, [...bTokens].join(" "));
721
+ const maxTokens = Math.max(aTokens.size, bTokens.size);
722
+ const score = maxTokens > 0 ? overlap / maxTokens : 0;
723
+ if (score >= config.threshold) {
724
+ cluster.push(tokenized[j].memory);
725
+ totalOverlap += score;
726
+ comparisons++;
727
+ if (totalCandidates + cluster.length >= config.maxPerRun) break;
728
+ }
729
+ }
730
+ if (cluster.length >= config.minClusterSize) {
731
+ for (const m of cluster) clustered.add(m.frontmatter.id);
732
+ clusters.push({
733
+ category,
734
+ memories: cluster,
735
+ overlapScore: comparisons > 0 ? totalOverlap / comparisons : 0
736
+ });
737
+ totalCandidates += cluster.length;
738
+ }
739
+ }
740
+ }
741
+ return clusters;
742
+ }
743
+ function buildConsolidationPrompt(cluster) {
744
+ const memoryTexts = cluster.memories.map(
745
+ (m, i) => `Memory ${i + 1} (${m.frontmatter.id}, created ${m.frontmatter.created}):
746
+ ${m.content}`
747
+ ).join("\n\n");
748
+ return `You are a memory consolidation system. The following ${cluster.memories.length} memories in the "${cluster.category}" category contain overlapping information.
749
+
750
+ Synthesize them into ONE canonical memory that:
751
+ 1. Preserves ALL unique information from every source memory
752
+ 2. Removes redundancy and repetition
753
+ 3. Uses clear, concise language
754
+ 4. Maintains the same category and tone
755
+ 5. Does NOT add information that isn't in the sources
756
+
757
+ ${memoryTexts}
758
+
759
+ Write ONLY the consolidated memory content (no metadata, no explanation, no preamble):`;
760
+ }
761
+ function parseConsolidationResponse(response) {
762
+ return response.trim();
763
+ }
764
+ async function buildExtensionsBlockForConsolidation(config) {
765
+ if (!config.memoryExtensionsEnabled) return "";
766
+ const root = resolveExtensionsRoot(config);
767
+ const extensions = await discoverMemoryExtensions(root, log);
768
+ if (extensions.length === 0) return "";
769
+ return renderExtensionsBlock(extensions);
770
+ }
771
+ async function materializeAfterSemanticConsolidation(options) {
772
+ return runPostConsolidationMaterialize("[semantic-consolidation]", options);
773
+ }
774
+
775
+ export {
776
+ MATERIALIZE_VERSION,
777
+ SENTINEL_FILE,
778
+ materializeForNamespace,
779
+ ensureSentinel,
780
+ describeMemoriesDir,
781
+ runCodexMaterialize,
782
+ runPostConsolidationMaterialize,
783
+ findSimilarClusters,
784
+ buildConsolidationPrompt,
785
+ parseConsolidationResponse,
786
+ buildExtensionsBlockForConsolidation,
787
+ materializeAfterSemanticConsolidation
788
+ };
789
+ //# sourceMappingURL=chunk-SYUK3VLY.js.map