@remnic/core 1.1.12 → 1.1.14

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 (1324) hide show
  1. package/dist/access-cli.d.ts +2 -1
  2. package/dist/access-cli.js +263 -82
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-http.d.ts +26 -60
  5. package/dist/access-http.js +43 -29
  6. package/dist/access-mcp.d.ts +24 -6
  7. package/dist/access-mcp.js +35 -28
  8. package/dist/access-schema.d.ts +9 -6
  9. package/dist/access-schema.js +7 -5
  10. package/dist/access-service-DcCDmNYC.d.ts +1542 -0
  11. package/dist/access-service.d.ts +25 -7
  12. package/dist/access-service.js +33 -26
  13. package/dist/active-memory-bridge.js +2 -2
  14. package/dist/active-recall.js +11 -3
  15. package/dist/active-recall.js.map +1 -1
  16. package/dist/adapters/claude-code.d.ts +24 -0
  17. package/dist/adapters/claude-code.js +9 -0
  18. package/dist/adapters/codex.d.ts +25 -0
  19. package/dist/adapters/codex.js +9 -0
  20. package/dist/adapters/hermes.d.ts +35 -0
  21. package/dist/adapters/hermes.js +9 -0
  22. package/dist/adapters/index.d.ts +6 -0
  23. package/dist/adapters/index.js +26 -0
  24. package/dist/adapters/registry.d.ts +20 -0
  25. package/dist/adapters/registry.js +13 -0
  26. package/dist/adapters/replit.d.ts +28 -0
  27. package/dist/adapters/replit.js +9 -0
  28. package/dist/adapters/types.d.ts +43 -0
  29. package/dist/adapters/types.js +8 -0
  30. package/dist/bootstrap.d.ts +20 -5
  31. package/dist/boxes.d.ts +7 -0
  32. package/dist/boxes.js +1 -1
  33. package/dist/briefing.d.ts +5 -3
  34. package/dist/briefing.js +9 -6
  35. package/dist/buffer-surprise-report.js +1 -1
  36. package/dist/buffer.d.ts +18 -4
  37. package/dist/buffer.js +1 -1
  38. package/dist/calibration.js +4 -4
  39. package/dist/capsule-cli.d.ts +4 -4
  40. package/dist/capsule-cli.js +1 -1
  41. package/dist/capsule-crypto-5CYAGVC5.js +18 -0
  42. package/dist/capsule-merge-4MGKE7C5.js +189 -0
  43. package/dist/causal-behavior.d.ts +8 -28
  44. package/dist/causal-behavior.js +6 -3
  45. package/dist/causal-behavior.js.map +1 -1
  46. package/dist/causal-chain.js +3 -2
  47. package/dist/causal-consolidation.d.ts +1 -1
  48. package/dist/causal-consolidation.js +24 -13
  49. package/dist/causal-consolidation.js.map +1 -1
  50. package/dist/causal-retrieval.js +3 -3
  51. package/dist/causal-trajectory.js +1 -1
  52. package/dist/chunk-25MQ7IHJ.js +427 -0
  53. package/dist/chunk-25MQ7IHJ.js.map +1 -0
  54. package/dist/chunk-2F2W355T.js +256 -0
  55. package/dist/chunk-2F2W355T.js.map +1 -0
  56. package/dist/chunk-2KI4QFHU.js +228 -0
  57. package/dist/chunk-2KI4QFHU.js.map +1 -0
  58. package/dist/chunk-2PRQG7PV.js +86 -0
  59. package/dist/chunk-2PRQG7PV.js.map +1 -0
  60. package/dist/chunk-2QR3XXIC.js +2272 -0
  61. package/dist/chunk-2QR3XXIC.js.map +1 -0
  62. package/dist/chunk-2WWLHTZY.js +121 -0
  63. package/dist/chunk-326G7DJK.js +2185 -0
  64. package/dist/chunk-326G7DJK.js.map +1 -0
  65. package/dist/chunk-34DQE4KF.js +174 -0
  66. package/dist/chunk-34DQE4KF.js.map +1 -0
  67. package/dist/chunk-3APJ5EVB.js +601 -0
  68. package/dist/chunk-3APJ5EVB.js.map +1 -0
  69. package/dist/chunk-3HPAPHUK.js +51 -0
  70. package/dist/chunk-3HPAPHUK.js.map +1 -0
  71. package/dist/chunk-3JXBXXM2.js +69 -0
  72. package/dist/chunk-3JXBXXM2.js.map +1 -0
  73. package/dist/chunk-3KW65B36.js +681 -0
  74. package/dist/chunk-3KW65B36.js.map +1 -0
  75. package/dist/chunk-3UXOZBHV.js +20 -0
  76. package/dist/chunk-3UXOZBHV.js.map +1 -0
  77. package/dist/chunk-3VAL7ZL2.js +266 -0
  78. package/dist/chunk-3VAL7ZL2.js.map +1 -0
  79. package/dist/chunk-3Y4P7RXM.js +31 -0
  80. package/dist/chunk-3Y4P7RXM.js.map +1 -0
  81. package/dist/chunk-47VWKCAF.js +273 -0
  82. package/dist/chunk-47VWKCAF.js.map +1 -0
  83. package/dist/chunk-4CRG46BG.js +271 -0
  84. package/dist/chunk-5375UYTQ.js +914 -0
  85. package/dist/chunk-5375UYTQ.js.map +1 -0
  86. package/dist/chunk-56K5QLHX.js +506 -0
  87. package/dist/chunk-56K5QLHX.js.map +1 -0
  88. package/dist/chunk-5RGLBDQF.js +596 -0
  89. package/dist/chunk-5RGLBDQF.js.map +1 -0
  90. package/dist/chunk-5UZXUTVO.js +9 -0
  91. package/dist/chunk-5UZXUTVO.js.map +1 -0
  92. package/dist/chunk-65PG43EQ.js +105 -0
  93. package/dist/chunk-65PG43EQ.js.map +1 -0
  94. package/dist/chunk-66DHUKLO.js +57 -0
  95. package/dist/chunk-66DHUKLO.js.map +1 -0
  96. package/dist/chunk-6FC5EGNV.js +46 -0
  97. package/dist/chunk-6FC5EGNV.js.map +1 -0
  98. package/dist/chunk-6H2TESSP.js +62 -0
  99. package/dist/chunk-6H2TESSP.js.map +1 -0
  100. package/dist/chunk-6LVVDPJ4.js +32 -0
  101. package/dist/chunk-6LVVDPJ4.js.map +1 -0
  102. package/dist/chunk-6RVI47ZR.js +159 -0
  103. package/dist/chunk-6RVI47ZR.js.map +1 -0
  104. package/dist/chunk-7AAT6G4Q.js +5117 -0
  105. package/dist/chunk-7AAT6G4Q.js.map +1 -0
  106. package/dist/chunk-7DTASS5T.js +29 -0
  107. package/dist/chunk-7DTASS5T.js.map +1 -0
  108. package/dist/chunk-7IASACLB.js +596 -0
  109. package/dist/chunk-7MNMYOFP.js +32 -0
  110. package/dist/chunk-7MNMYOFP.js.map +1 -0
  111. package/dist/chunk-7N4KAIGN.js +133 -0
  112. package/dist/chunk-7N4KAIGN.js.map +1 -0
  113. package/dist/chunk-7OZ53EXP.js +101 -0
  114. package/dist/chunk-7OZ53EXP.js.map +1 -0
  115. package/dist/chunk-7XYTQGCC.js +134 -0
  116. package/dist/chunk-7XYTQGCC.js.map +1 -0
  117. package/dist/chunk-A2XUIMJ3.js +341 -0
  118. package/dist/chunk-A2XUIMJ3.js.map +1 -0
  119. package/dist/chunk-AGZQD76C.js +201 -0
  120. package/dist/chunk-AGZQD76C.js.map +1 -0
  121. package/dist/chunk-APO3DCMU.js +361 -0
  122. package/dist/chunk-APO3DCMU.js.map +1 -0
  123. package/dist/chunk-BFBF3XEF.js +283 -0
  124. package/dist/chunk-BFBF3XEF.js.map +1 -0
  125. package/dist/chunk-BJ3KMYTB.js +1974 -0
  126. package/dist/chunk-BJ3KMYTB.js.map +1 -0
  127. package/dist/chunk-CHEL3SKB.js +6758 -0
  128. package/dist/chunk-CHEL3SKB.js.map +1 -0
  129. package/dist/chunk-CQZRLNMV.js +1491 -0
  130. package/dist/chunk-CQZRLNMV.js.map +1 -0
  131. package/dist/chunk-D46YSIYX.js +892 -0
  132. package/dist/chunk-D46YSIYX.js.map +1 -0
  133. package/dist/chunk-DINWEURR.js +648 -0
  134. package/dist/chunk-DINWEURR.js.map +1 -0
  135. package/dist/chunk-DK5LDEQM.js +530 -0
  136. package/dist/chunk-DK5LDEQM.js.map +1 -0
  137. package/dist/chunk-DOM4GKSW.js +34 -0
  138. package/dist/chunk-DOM4GKSW.js.map +1 -0
  139. package/dist/chunk-EDTHC6UD.js +1075 -0
  140. package/dist/chunk-EFJ3MQ4V.js +721 -0
  141. package/dist/chunk-EHRTFRWW.js +89 -0
  142. package/dist/chunk-EHRTFRWW.js.map +1 -0
  143. package/dist/chunk-FAJ7FZYM.js +11 -0
  144. package/dist/chunk-FAJ7FZYM.js.map +1 -0
  145. package/dist/chunk-FBYESMQ2.js +570 -0
  146. package/dist/chunk-FDU6HUUL.js +147 -0
  147. package/dist/chunk-FF4KLI5W.js +99 -0
  148. package/dist/chunk-FF4KLI5W.js.map +1 -0
  149. package/dist/chunk-FIT6DMX6.js +310 -0
  150. package/dist/chunk-FIT6DMX6.js.map +1 -0
  151. package/dist/chunk-FJ43PRLT.js +272 -0
  152. package/dist/chunk-FJ43PRLT.js.map +1 -0
  153. package/dist/chunk-FKFMOY3N.js +32 -0
  154. package/dist/chunk-FKFMOY3N.js.map +1 -0
  155. package/dist/chunk-FLTNHQK6.js +262 -0
  156. package/dist/chunk-FLTNHQK6.js.map +1 -0
  157. package/dist/chunk-GA454ALV.js +12436 -0
  158. package/dist/chunk-GA454ALV.js.map +1 -0
  159. package/dist/chunk-GGKRUQOO.js +228 -0
  160. package/dist/chunk-GIF42EW3.js +63 -0
  161. package/dist/chunk-GIF42EW3.js.map +1 -0
  162. package/dist/chunk-GL6I6MEQ.js +647 -0
  163. package/dist/chunk-H3ME6L6D.js +709 -0
  164. package/dist/chunk-H3ME6L6D.js.map +1 -0
  165. package/dist/chunk-HHLLAQGZ.js +1 -0
  166. package/dist/chunk-HXXBL2KD.js +2040 -0
  167. package/dist/chunk-I5V2VDIW.js +219 -0
  168. package/dist/chunk-I5V2VDIW.js.map +1 -0
  169. package/dist/chunk-I6K5FBRQ.js +35 -0
  170. package/dist/chunk-I6K5FBRQ.js.map +1 -0
  171. package/dist/chunk-ICRIXAP2.js +121 -0
  172. package/dist/chunk-ICRIXAP2.js.map +1 -0
  173. package/dist/chunk-J4EB7DNW.js +11 -0
  174. package/dist/chunk-J4EB7DNW.js.map +1 -0
  175. package/dist/chunk-JLFA7DQG.js +62 -0
  176. package/dist/chunk-JLFA7DQG.js.map +1 -0
  177. package/dist/chunk-KJTKLXTH.js +9 -0
  178. package/dist/chunk-KJTKLXTH.js.map +1 -0
  179. package/dist/chunk-KLAO5DGL.js +917 -0
  180. package/dist/chunk-KLAO5DGL.js.map +1 -0
  181. package/dist/chunk-KNKUID7G.js +183 -0
  182. package/dist/chunk-KOSORCJG.js +624 -0
  183. package/dist/chunk-KOSORCJG.js.map +1 -0
  184. package/dist/chunk-KUJVMMZQ.js +1262 -0
  185. package/dist/chunk-KUJVMMZQ.js.map +1 -0
  186. package/dist/chunk-LCR46JY5.js +123 -0
  187. package/dist/chunk-LCR46JY5.js.map +1 -0
  188. package/dist/chunk-LLQ2LLWF.js +148 -0
  189. package/dist/chunk-LLQ2LLWF.js.map +1 -0
  190. package/dist/chunk-LPMVBPA3.js +236 -0
  191. package/dist/chunk-LT3NLYSI.js +50 -0
  192. package/dist/chunk-LT3NLYSI.js.map +1 -0
  193. package/dist/chunk-LUDTDZLK.js +287 -0
  194. package/dist/chunk-LUDTDZLK.js.map +1 -0
  195. package/dist/chunk-M23FSH32.js +3963 -0
  196. package/dist/chunk-M23FSH32.js.map +1 -0
  197. package/dist/chunk-MC26UJIM.js +118 -0
  198. package/dist/chunk-ME6ESPZU.js +119 -0
  199. package/dist/chunk-ME6ESPZU.js.map +1 -0
  200. package/dist/chunk-MGKYQQYF.js +272 -0
  201. package/dist/chunk-MJFNCJXV.js +66 -0
  202. package/dist/chunk-MJFNCJXV.js.map +1 -0
  203. package/dist/chunk-MSWG7JI6.js +237 -0
  204. package/dist/chunk-MSWG7JI6.js.map +1 -0
  205. package/dist/chunk-MT25YHYH.js +141 -0
  206. package/dist/chunk-MT25YHYH.js.map +1 -0
  207. package/dist/chunk-MT4HVDUZ.js +53 -0
  208. package/dist/chunk-MY6TPVXW.js +219 -0
  209. package/dist/chunk-N2D6GXBM.js +267 -0
  210. package/dist/chunk-N2D6GXBM.js.map +1 -0
  211. package/dist/chunk-NJ3MJQZX.js +46 -0
  212. package/dist/chunk-NJ3MJQZX.js.map +1 -0
  213. package/dist/chunk-NMZY542O.js +335 -0
  214. package/dist/chunk-NMZY542O.js.map +1 -0
  215. package/dist/chunk-NNVTUXEB.js +23 -0
  216. package/dist/chunk-NZL6GGQE.js +375 -0
  217. package/dist/chunk-NZL6GGQE.js.map +1 -0
  218. package/dist/chunk-P4NEIHUT.js +108 -0
  219. package/dist/chunk-P7FMDTKL.js +103 -0
  220. package/dist/chunk-P7FMDTKL.js.map +1 -0
  221. package/dist/chunk-PHK3HARR.js +32 -0
  222. package/dist/chunk-PHK3HARR.js.map +1 -0
  223. package/dist/chunk-PIRJPV5T.js +98 -0
  224. package/dist/chunk-PIRJPV5T.js.map +1 -0
  225. package/dist/chunk-PK7H5L6Y.js +159 -0
  226. package/dist/chunk-PK7H5L6Y.js.map +1 -0
  227. package/dist/chunk-PR5FBTFU.js +233 -0
  228. package/dist/chunk-PR5FBTFU.js.map +1 -0
  229. package/dist/chunk-PU63GXWS.js +174 -0
  230. package/dist/chunk-PU63GXWS.js.map +1 -0
  231. package/dist/chunk-PZIAX57I.js +124 -0
  232. package/dist/chunk-PZIAX57I.js.map +1 -0
  233. package/dist/chunk-Q7P4WJDP.js +26 -0
  234. package/dist/chunk-Q7P4WJDP.js.map +1 -0
  235. package/dist/chunk-QQUAB63I.js +63 -0
  236. package/dist/chunk-QQUAB63I.js.map +1 -0
  237. package/dist/chunk-QRNI5JBH.js +18 -0
  238. package/dist/chunk-RHY3HH7P.js +601 -0
  239. package/dist/chunk-RHY3HH7P.js.map +1 -0
  240. package/dist/chunk-RRF5UOBJ.js +91 -0
  241. package/dist/chunk-RXDLTSWT.js +124 -0
  242. package/dist/chunk-RXDLTSWT.js.map +1 -0
  243. package/dist/chunk-RYED3SPJ.js +42 -0
  244. package/dist/chunk-RYED3SPJ.js.map +1 -0
  245. package/dist/chunk-S7KDBTWT.js +106 -0
  246. package/dist/chunk-S7KDBTWT.js.map +1 -0
  247. package/dist/chunk-SEDEKFYQ.js +1 -0
  248. package/dist/chunk-TECVW3JP.js +36 -0
  249. package/dist/chunk-TECVW3JP.js.map +1 -0
  250. package/dist/chunk-TFO23QT4.js +88 -0
  251. package/dist/chunk-TFO23QT4.js.map +1 -0
  252. package/dist/chunk-TK4UEOSK.js +76 -0
  253. package/dist/chunk-TK4UEOSK.js.map +1 -0
  254. package/dist/chunk-TKWGAOLV.js +122 -0
  255. package/dist/chunk-TKWGAOLV.js.map +1 -0
  256. package/dist/chunk-TMM4S4IJ.js +597 -0
  257. package/dist/chunk-TMM4S4IJ.js.map +1 -0
  258. package/dist/chunk-TMQLARTH.js +188 -0
  259. package/dist/chunk-TMQLARTH.js.map +1 -0
  260. package/dist/chunk-TPDBFYEG.js +130 -0
  261. package/dist/chunk-TPDBFYEG.js.map +1 -0
  262. package/dist/chunk-TPMQ3G6Z.js +145 -0
  263. package/dist/chunk-TPMQ3G6Z.js.map +1 -0
  264. package/dist/chunk-TZOLIGIG.js +61 -0
  265. package/dist/chunk-TZOLIGIG.js.map +1 -0
  266. package/dist/chunk-U3PN77QT.js +113 -0
  267. package/dist/chunk-U3WSW6PZ.js +277 -0
  268. package/dist/chunk-U4SCL7B7.js +640 -0
  269. package/dist/chunk-U4SCL7B7.js.map +1 -0
  270. package/dist/chunk-UWK5OXUJ.js +156 -0
  271. package/dist/chunk-UWK5OXUJ.js.map +1 -0
  272. package/dist/chunk-UWVJF25J.js +74 -0
  273. package/dist/chunk-UXHQAFNA.js +1317 -0
  274. package/dist/chunk-UXHQAFNA.js.map +1 -0
  275. package/dist/chunk-V5OCT34X.js +1 -0
  276. package/dist/chunk-VLXA6PI2.js +304 -0
  277. package/dist/chunk-VLXA6PI2.js.map +1 -0
  278. package/dist/chunk-VNO6ZJ35.js +500 -0
  279. package/dist/chunk-VNO6ZJ35.js.map +1 -0
  280. package/dist/chunk-VW676BEI.js +827 -0
  281. package/dist/chunk-VW676BEI.js.map +1 -0
  282. package/dist/chunk-W3LR522O.js +2296 -0
  283. package/dist/chunk-W4L6CZKA.js +96 -0
  284. package/dist/chunk-W4L6CZKA.js.map +1 -0
  285. package/dist/chunk-W4RVMTHR.js +372 -0
  286. package/dist/chunk-W4RVMTHR.js.map +1 -0
  287. package/dist/chunk-WEHSQBFR.js +188 -0
  288. package/dist/chunk-WEHSQBFR.js.map +1 -0
  289. package/dist/chunk-WELDCG6C.js +380 -0
  290. package/dist/chunk-WELDCG6C.js.map +1 -0
  291. package/dist/chunk-WZYKANL3.js +2800 -0
  292. package/dist/chunk-WZYKANL3.js.map +1 -0
  293. package/dist/chunk-XIG5PDM7.js +48 -0
  294. package/dist/chunk-XJNBEDFE.js +193 -0
  295. package/dist/chunk-XJNBEDFE.js.map +1 -0
  296. package/dist/chunk-XVVIG67A.js +291 -0
  297. package/dist/chunk-XVVIG67A.js.map +1 -0
  298. package/dist/chunk-XVZ7B3HG.js +135 -0
  299. package/dist/chunk-YBPYIAA5.js +73 -0
  300. package/dist/chunk-YBPYIAA5.js.map +1 -0
  301. package/dist/chunk-Z734BLO3.js +21 -0
  302. package/dist/chunk-Z734BLO3.js.map +1 -0
  303. package/dist/chunk-ZKSK55RC.js +269 -0
  304. package/dist/chunk-ZKSK55RC.js.map +1 -0
  305. package/dist/chunk-ZTFCYYEZ.js +69 -0
  306. package/dist/chunk-ZTFCYYEZ.js.map +1 -0
  307. package/dist/chunk-ZY2MNJR6.js +329 -0
  308. package/dist/chunk-ZY2MNJR6.js.map +1 -0
  309. package/dist/cli-D3VpkVwB.d.ts +1136 -0
  310. package/dist/cli.d.ts +39 -10
  311. package/dist/cli.js +108 -49
  312. package/dist/commitment-ledger.js +1 -1
  313. package/dist/compat/checks.d.ts +5 -0
  314. package/dist/compat/checks.js +11 -0
  315. package/dist/compat/checks.js.map +1 -0
  316. package/dist/compat/types.d.ts +30 -0
  317. package/dist/compat/types.js +1 -0
  318. package/dist/compat/types.js.map +1 -0
  319. package/dist/compounding/engine.d.ts +221 -0
  320. package/dist/compounding/engine.js +32 -0
  321. package/dist/compounding/engine.js.map +1 -0
  322. package/dist/compounding/preference-consolidator.d.ts +92 -0
  323. package/dist/compounding/preference-consolidator.js +553 -0
  324. package/dist/compounding/preference-consolidator.js.map +1 -0
  325. package/dist/config.d.ts +4 -2
  326. package/dist/config.js +9 -4
  327. package/dist/conflict-policy-DyJ2wd-h.d.ts +4 -0
  328. package/dist/connectors/codex-materialize-runner.d.ts +64 -0
  329. package/dist/connectors/codex-materialize-runner.js +33 -0
  330. package/dist/connectors/codex-materialize-runner.js.map +1 -0
  331. package/dist/connectors/codex-materialize.d.ts +195 -0
  332. package/dist/connectors/codex-materialize.js +38 -0
  333. package/dist/connectors/codex-materialize.js.map +1 -0
  334. package/dist/connectors/index.d.ts +444 -0
  335. package/dist/connectors/index.js +115 -0
  336. package/dist/connectors/index.js.map +1 -0
  337. package/dist/connectors-cli-CwbyjGR7.d.ts +257 -0
  338. package/dist/connectors-cli.d.ts +1 -1
  339. package/dist/consolidation-provenance-check.d.ts +3 -1
  340. package/dist/consolidation-undo.d.ts +3 -1
  341. package/dist/contradiction/index.d.ts +258 -0
  342. package/dist/contradiction/index.js +43 -0
  343. package/dist/contradiction/index.js.map +1 -0
  344. package/dist/contradiction-review-ATP4S6IC.js +30 -0
  345. package/dist/contradiction-review-ATP4S6IC.js.map +1 -0
  346. package/dist/contradiction-scan-5A4IDZV5.js +13 -0
  347. package/dist/contradiction-scan-5A4IDZV5.js.map +1 -0
  348. package/dist/conversation-index/backend.d.ts +97 -0
  349. package/dist/conversation-index/backend.js +13 -0
  350. package/dist/conversation-index/backend.js.map +1 -0
  351. package/dist/conversation-index/chunker.d.ts +16 -0
  352. package/dist/conversation-index/chunker.js +8 -0
  353. package/dist/conversation-index/chunker.js.map +1 -0
  354. package/dist/conversation-index/cleanup.d.ts +11 -0
  355. package/dist/conversation-index/cleanup.js +9 -0
  356. package/dist/conversation-index/cleanup.js.map +1 -0
  357. package/dist/conversation-index/faiss-adapter.d.ts +6 -0
  358. package/dist/conversation-index/faiss-adapter.js +16 -0
  359. package/dist/conversation-index/faiss-adapter.js.map +1 -0
  360. package/dist/conversation-index/indexer.d.ts +23 -0
  361. package/dist/conversation-index/indexer.js +15 -0
  362. package/dist/conversation-index/indexer.js.map +1 -0
  363. package/dist/conversation-index/search.d.ts +6 -0
  364. package/dist/conversation-index/search.js +11 -0
  365. package/dist/conversation-index/search.js.map +1 -0
  366. package/dist/embedding-fallback.js +2 -2
  367. package/dist/enrichment/index.d.ts +163 -0
  368. package/dist/enrichment/index.js +18 -0
  369. package/dist/enrichment/index.js.map +1 -0
  370. package/dist/entity-retrieval.d.ts +4 -2
  371. package/dist/entity-retrieval.js +8 -5
  372. package/dist/evals.js +1 -1
  373. package/dist/explicit-capture.d.ts +20 -5
  374. package/dist/explicit-capture.js +2 -2
  375. package/dist/extraction-judge-training.js +1 -1
  376. package/dist/extraction.js +8 -8
  377. package/dist/faiss-adapter-CzPghc4C.d.ts +70 -0
  378. package/dist/fallback-llm.d.ts +2 -0
  379. package/dist/fallback-llm.js +4 -4
  380. package/dist/graph-edge-decay-5DI5GUNL.js +207 -0
  381. package/dist/index.d.ts +66 -711
  382. package/dist/index.js +556 -2680
  383. package/dist/index.js.map +1 -1
  384. package/dist/lcm/archive.d.ts +89 -0
  385. package/dist/lcm/archive.js +12 -0
  386. package/dist/lcm/archive.js.map +1 -0
  387. package/dist/lcm/dag.d.ts +48 -0
  388. package/dist/lcm/dag.js +8 -0
  389. package/dist/lcm/dag.js.map +1 -0
  390. package/dist/lcm/engine.d.ts +116 -0
  391. package/dist/lcm/engine.js +20 -0
  392. package/dist/lcm/engine.js.map +1 -0
  393. package/dist/lcm/index.d.ts +12 -0
  394. package/dist/lcm/index.js +44 -0
  395. package/dist/lcm/index.js.map +1 -0
  396. package/dist/lcm/queue.d.ts +62 -0
  397. package/dist/lcm/queue.js +8 -0
  398. package/dist/lcm/queue.js.map +1 -0
  399. package/dist/lcm/recall.d.ts +20 -0
  400. package/dist/lcm/recall.js +8 -0
  401. package/dist/lcm/recall.js.map +1 -0
  402. package/dist/lcm/schema.d.ts +16 -0
  403. package/dist/lcm/schema.js +14 -0
  404. package/dist/lcm/schema.js.map +1 -0
  405. package/dist/lcm/summarizer.d.ts +38 -0
  406. package/dist/lcm/summarizer.js +12 -0
  407. package/dist/lcm/summarizer.js.map +1 -0
  408. package/dist/lcm/tools.d.ts +29 -0
  409. package/dist/lcm/tools.js +8 -0
  410. package/dist/lcm/tools.js.map +1 -0
  411. package/dist/live-connectors-runner.js +5 -5
  412. package/dist/local-llm.js +3 -3
  413. package/dist/maintenance/archive-observations.d.ts +18 -0
  414. package/dist/maintenance/archive-observations.js +8 -0
  415. package/dist/maintenance/archive-observations.js.map +1 -0
  416. package/dist/maintenance/backup-stamp.d.ts +3 -0
  417. package/dist/maintenance/backup-stamp.js +8 -0
  418. package/dist/maintenance/backup-stamp.js.map +1 -0
  419. package/dist/maintenance/memory-governance-cron.d.ts +85 -0
  420. package/dist/maintenance/memory-governance-cron.js +22 -0
  421. package/dist/maintenance/memory-governance-cron.js.map +1 -0
  422. package/dist/maintenance/memory-governance.d.ts +137 -0
  423. package/dist/maintenance/memory-governance.js +40 -0
  424. package/dist/maintenance/memory-governance.js.map +1 -0
  425. package/dist/maintenance/migrate-observations.d.ts +18 -0
  426. package/dist/maintenance/migrate-observations.js +9 -0
  427. package/dist/maintenance/migrate-observations.js.map +1 -0
  428. package/dist/maintenance/observation-ledger-utils.d.ts +10 -0
  429. package/dist/maintenance/observation-ledger-utils.js +10 -0
  430. package/dist/maintenance/observation-ledger-utils.js.map +1 -0
  431. package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +15 -0
  432. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +28 -0
  433. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js.map +1 -0
  434. package/dist/maintenance/rebuild-memory-projection.d.ts +77 -0
  435. package/dist/maintenance/rebuild-memory-projection.js +35 -0
  436. package/dist/maintenance/rebuild-memory-projection.js.map +1 -0
  437. package/dist/maintenance/rebuild-observations.d.ts +17 -0
  438. package/dist/maintenance/rebuild-observations.js +9 -0
  439. package/dist/maintenance/rebuild-observations.js.map +1 -0
  440. package/dist/mcp-memory-inspector-app.d.ts +24 -6
  441. package/dist/memory-projection-store.d.ts +108 -3
  442. package/dist/memory-projection-store.js +2 -1
  443. package/dist/memory-worth-outcomes.d.ts +4 -2
  444. package/dist/migrate/from-engram.d.ts +24 -0
  445. package/dist/migrate/from-engram.js +12 -0
  446. package/dist/migrate/from-engram.js.map +1 -0
  447. package/dist/namespaces/migrate.d.ts +50 -0
  448. package/dist/namespaces/migrate.js +50 -0
  449. package/dist/namespaces/migrate.js.map +1 -0
  450. package/dist/namespaces/principal.d.ts +17 -0
  451. package/dist/namespaces/principal.js +16 -0
  452. package/dist/namespaces/principal.js.map +1 -0
  453. package/dist/namespaces/search.d.ts +46 -0
  454. package/dist/namespaces/search.js +28 -0
  455. package/dist/namespaces/search.js.map +1 -0
  456. package/dist/namespaces/storage.d.ts +32 -0
  457. package/dist/namespaces/storage.js +28 -0
  458. package/dist/namespaces/storage.js.map +1 -0
  459. package/dist/network/tailscale.d.ts +41 -0
  460. package/dist/network/tailscale.js +9 -0
  461. package/dist/network/tailscale.js.map +1 -0
  462. package/dist/network/webdav.d.ts +39 -0
  463. package/dist/network/webdav.js +10 -0
  464. package/dist/network/webdav.js.map +1 -0
  465. package/dist/objective-state-writers.js +2 -2
  466. package/dist/operator-toolkit.d.ts +4 -2
  467. package/dist/operator-toolkit.js +32 -14
  468. package/dist/opik-exporter.js +2 -2
  469. package/dist/opik-exporter.js.map +1 -1
  470. package/dist/orchestrator-DuWl9Hwx.d.ts +1244 -0
  471. package/dist/orchestrator.d.ts +22 -7
  472. package/dist/orchestrator.js +79 -44
  473. package/dist/path-MR5JPYOP.js +9 -0
  474. package/dist/path-MR5JPYOP.js.map +1 -0
  475. package/dist/qmd-recall-cache.d.ts +1 -1
  476. package/dist/qmd.d.ts +102 -3
  477. package/dist/qmd.js +23 -5
  478. package/dist/recall-explain-renderer.js +3 -3
  479. package/dist/recall-xray-cli.js +4 -4
  480. package/dist/recall-xray-renderer.js +3 -3
  481. package/dist/recall-xray.js +2 -2
  482. package/dist/replay/normalizers/chatgpt.d.ts +6 -0
  483. package/dist/replay/normalizers/chatgpt.js +11 -0
  484. package/dist/replay/normalizers/chatgpt.js.map +1 -0
  485. package/dist/replay/normalizers/claude.d.ts +6 -0
  486. package/dist/replay/normalizers/claude.js +11 -0
  487. package/dist/replay/normalizers/claude.js.map +1 -0
  488. package/dist/replay/normalizers/openclaw.d.ts +6 -0
  489. package/dist/replay/normalizers/openclaw.js +11 -0
  490. package/dist/replay/normalizers/openclaw.js.map +1 -0
  491. package/dist/replay/normalizers/shared.d.ts +16 -0
  492. package/dist/replay/normalizers/shared.js +14 -0
  493. package/dist/replay/normalizers/shared.js.map +1 -0
  494. package/dist/replay/runner.d.ts +35 -0
  495. package/dist/replay/runner.js +16 -0
  496. package/dist/replay/runner.js.map +1 -0
  497. package/dist/replay/types.d.ts +57 -0
  498. package/dist/replay/types.js +19 -0
  499. package/dist/replay/types.js.map +1 -0
  500. package/dist/resolution-B7FNQSSP.js +12 -0
  501. package/dist/resolution-B7FNQSSP.js.map +1 -0
  502. package/dist/resolve-provider-secret.js +2 -2
  503. package/dist/resume-bundles.js +8 -6
  504. package/dist/retrieval-agents.d.ts +1 -1
  505. package/dist/routing/engine.d.ts +35 -0
  506. package/dist/routing/engine.js +16 -0
  507. package/dist/routing/engine.js.map +1 -0
  508. package/dist/routing/store.d.ts +27 -0
  509. package/dist/routing/store.js +10 -0
  510. package/dist/routing/store.js.map +1 -0
  511. package/dist/runtime/better-sqlite.d.ts +8 -0
  512. package/dist/runtime/better-sqlite.js +10 -0
  513. package/dist/runtime/better-sqlite.js.map +1 -0
  514. package/dist/runtime/child-process.d.ts +32 -0
  515. package/dist/runtime/child-process.js +10 -0
  516. package/dist/runtime/child-process.js.map +1 -0
  517. package/dist/runtime/env.d.ts +5 -0
  518. package/dist/runtime/env.js +12 -0
  519. package/dist/runtime/env.js.map +1 -0
  520. package/dist/schemas.d.ts +22 -22
  521. package/dist/sdk-compat.js +1 -1
  522. package/dist/search/document-scanner.d.ts +22 -0
  523. package/dist/search/document-scanner.js +8 -0
  524. package/dist/search/document-scanner.js.map +1 -0
  525. package/dist/search/embed-helper.d.ts +35 -0
  526. package/dist/search/embed-helper.js +9 -0
  527. package/dist/search/embed-helper.js.map +1 -0
  528. package/dist/search/factory.d.ts +32 -0
  529. package/dist/search/factory.js +29 -0
  530. package/dist/search/factory.js.map +1 -0
  531. package/dist/search/index.d.ts +15 -0
  532. package/dist/search/index.js +50 -0
  533. package/dist/search/index.js.map +1 -0
  534. package/dist/search/lancedb-backend.d.ts +51 -0
  535. package/dist/search/lancedb-backend.js +10 -0
  536. package/dist/search/lancedb-backend.js.map +1 -0
  537. package/dist/search/meilisearch-backend.d.ts +48 -0
  538. package/dist/search/meilisearch-backend.js +10 -0
  539. package/dist/search/meilisearch-backend.js.map +1 -0
  540. package/dist/search/noop-backend.d.ts +26 -0
  541. package/dist/search/noop-backend.js +8 -0
  542. package/dist/search/noop-backend.js.map +1 -0
  543. package/dist/search/orama-backend.d.ts +53 -0
  544. package/dist/search/orama-backend.js +10 -0
  545. package/dist/search/orama-backend.js.map +1 -0
  546. package/dist/search/port.d.ts +61 -0
  547. package/dist/search/port.js +1 -0
  548. package/dist/search/port.js.map +1 -0
  549. package/dist/search/remote-backend.d.ts +39 -0
  550. package/dist/search/remote-backend.js +9 -0
  551. package/dist/search/remote-backend.js.map +1 -0
  552. package/dist/secure-store/index.d.ts +890 -0
  553. package/dist/secure-store/index.js +156 -0
  554. package/dist/secure-store/index.js.map +1 -0
  555. package/dist/semantic-VwGI14Ok.d.ts +69 -0
  556. package/dist/semantic-consolidation-4HkHWgeI.d.ts +180 -0
  557. package/dist/semantic-consolidation.d.ts +2 -2
  558. package/dist/semantic-consolidation.js +13 -6
  559. package/dist/semantic-rule-promotion.js +8 -5
  560. package/dist/semantic-rule-verifier.js +8 -5
  561. package/dist/shared-context/manager.d.ts +131 -0
  562. package/dist/shared-context/manager.js +15 -0
  563. package/dist/shared-context/manager.js.map +1 -0
  564. package/dist/skills-registry.js +13 -1
  565. package/dist/skills-registry.js.map +1 -1
  566. package/dist/state-store-VZU2IA53.js +16 -0
  567. package/dist/state-store-VZU2IA53.js.map +1 -0
  568. package/dist/storage-paths.d.ts +9 -0
  569. package/dist/storage-paths.js +20 -0
  570. package/dist/storage-paths.js.map +1 -0
  571. package/dist/storage.d.ts +3 -1
  572. package/dist/storage.js +7 -4
  573. package/dist/summarizer.d.ts +5 -0
  574. package/dist/summarizer.js +9 -8
  575. package/dist/summary-snapshot.js +2 -1
  576. package/dist/surfaces/dreams.d.ts +16 -0
  577. package/dist/surfaces/dreams.js +282 -0
  578. package/dist/surfaces/dreams.js.map +1 -0
  579. package/dist/surfaces/heartbeat.d.ts +17 -0
  580. package/dist/surfaces/heartbeat.js +265 -0
  581. package/dist/surfaces/heartbeat.js.map +1 -0
  582. package/dist/temporal-supersession.d.ts +3 -1
  583. package/dist/threading.d.ts +5 -0
  584. package/dist/threading.js +2 -1
  585. package/dist/tier-migration.d.ts +4 -2
  586. package/dist/tokens.js +2 -2
  587. package/dist/transcript.d.ts +15 -1
  588. package/dist/transcript.js +2 -1
  589. package/dist/transfer/autodetect.d.ts +4 -0
  590. package/dist/transfer/autodetect.js +15 -0
  591. package/dist/transfer/autodetect.js.map +1 -0
  592. package/dist/transfer/backup.d.ts +21 -0
  593. package/dist/transfer/backup.js +17 -0
  594. package/dist/transfer/backup.js.map +1 -0
  595. package/dist/transfer/capsule-export.d.ts +113 -0
  596. package/dist/transfer/capsule-export.js +19 -0
  597. package/dist/transfer/capsule-export.js.map +1 -0
  598. package/dist/transfer/capsule-import.d.ts +124 -0
  599. package/dist/transfer/capsule-import.js +16 -0
  600. package/dist/transfer/capsule-import.js.map +1 -0
  601. package/dist/transfer/constants.d.ts +13 -0
  602. package/dist/transfer/constants.js +12 -0
  603. package/dist/transfer/constants.js.map +1 -0
  604. package/dist/transfer/export-json.d.ts +11 -0
  605. package/dist/transfer/export-json.js +11 -0
  606. package/dist/transfer/export-json.js.map +1 -0
  607. package/dist/transfer/export-md.d.ts +10 -0
  608. package/dist/transfer/export-md.js +13 -0
  609. package/dist/transfer/export-md.js.map +1 -0
  610. package/dist/transfer/export-sqlite.d.ts +9 -0
  611. package/dist/transfer/export-sqlite.js +12 -0
  612. package/dist/transfer/export-sqlite.js.map +1 -0
  613. package/dist/transfer/fs-utils.d.ts +61 -0
  614. package/dist/transfer/fs-utils.js +40 -0
  615. package/dist/transfer/fs-utils.js.map +1 -0
  616. package/dist/transfer/import-json.d.ts +16 -0
  617. package/dist/transfer/import-json.js +13 -0
  618. package/dist/transfer/import-json.js.map +1 -0
  619. package/dist/transfer/import-md.d.ts +14 -0
  620. package/dist/transfer/import-md.js +11 -0
  621. package/dist/transfer/import-md.js.map +1 -0
  622. package/dist/transfer/import-sqlite.d.ts +14 -0
  623. package/dist/transfer/import-sqlite.js +12 -0
  624. package/dist/transfer/import-sqlite.js.map +1 -0
  625. package/dist/transfer/sqlite-schema.d.ts +4 -0
  626. package/dist/transfer/sqlite-schema.js +10 -0
  627. package/dist/transfer/sqlite-schema.js.map +1 -0
  628. package/dist/transfer/types.d.ts +916 -0
  629. package/dist/transfer/types.js +30 -0
  630. package/dist/transfer/types.js.map +1 -0
  631. package/dist/types.d.ts +28 -1
  632. package/dist/types.js +1 -1
  633. package/dist/verified-recall.js +9 -6
  634. package/dist/work/board.d.ts +43 -0
  635. package/dist/work/board.js +14 -0
  636. package/dist/work/board.js.map +1 -0
  637. package/dist/work/boundary.d.ts +8 -0
  638. package/dist/work/boundary.js +14 -0
  639. package/dist/work/boundary.js.map +1 -0
  640. package/dist/work/storage.d.ts +39 -0
  641. package/dist/work/storage.js +11 -0
  642. package/dist/work/storage.js.map +1 -0
  643. package/dist/work/types.d.ts +75 -0
  644. package/dist/work/types.js +1 -0
  645. package/dist/work/types.js.map +1 -0
  646. package/package.json +2767 -6
  647. package/scripts/faiss_index.py +816 -0
  648. package/scripts/faiss_requirements.txt +3 -0
  649. package/skills/remnic-entities/SKILL.md +51 -0
  650. package/skills/remnic-memory-workflow/SKILL.md +61 -0
  651. package/skills/remnic-recall/SKILL.md +51 -0
  652. package/skills/remnic-remember/SKILL.md +56 -0
  653. package/skills/remnic-search/SKILL.md +51 -0
  654. package/skills/remnic-status/SKILL.md +51 -0
  655. package/src/abort-error.test.ts +49 -0
  656. package/src/abort-error.ts +46 -0
  657. package/src/abstraction-nodes.ts +162 -0
  658. package/src/access-audit.test.ts +178 -0
  659. package/src/access-audit.ts +125 -0
  660. package/src/access-cli.test.ts +439 -0
  661. package/src/access-cli.ts +438 -0
  662. package/src/access-http.test.ts +225 -0
  663. package/src/access-http.ts +1899 -0
  664. package/src/access-idempotency.ts +232 -0
  665. package/src/access-mcp.test.ts +568 -0
  666. package/src/access-mcp.ts +3056 -0
  667. package/src/access-schema-pi.test.ts +60 -0
  668. package/src/access-schema.ts +522 -0
  669. package/src/access-service-namespace.test.ts +123 -0
  670. package/src/access-service.ts +5629 -0
  671. package/src/action-confidence.test.ts +206 -0
  672. package/src/action-confidence.ts +466 -0
  673. package/src/active-memory-bridge.test.ts +285 -0
  674. package/src/active-memory-bridge.ts +217 -0
  675. package/src/active-recall.test.ts +484 -0
  676. package/src/active-recall.ts +459 -0
  677. package/src/adapters/claude-code.ts +56 -0
  678. package/src/adapters/codex.ts +57 -0
  679. package/src/adapters/hermes.ts +64 -0
  680. package/src/adapters/index.ts +6 -0
  681. package/src/adapters/registry.ts +41 -0
  682. package/src/adapters/replit.ts +55 -0
  683. package/src/adapters/types.ts +51 -0
  684. package/src/behavior-learner.ts +144 -0
  685. package/src/behavior-signals.ts +73 -0
  686. package/src/binary-lifecycle/backend.ts +117 -0
  687. package/src/binary-lifecycle/index.ts +35 -0
  688. package/src/binary-lifecycle/manifest.ts +79 -0
  689. package/src/binary-lifecycle/pipeline.ts +352 -0
  690. package/src/binary-lifecycle/scanner.ts +89 -0
  691. package/src/binary-lifecycle/types.ts +89 -0
  692. package/src/bootstrap.ts +178 -0
  693. package/src/boxes.ts +521 -0
  694. package/src/briefing.test.ts +1535 -0
  695. package/src/briefing.ts +1382 -0
  696. package/src/buffer-session.test.ts +443 -0
  697. package/src/buffer-surprise-report.ts +176 -0
  698. package/src/buffer-surprise-telemetry.test.ts +606 -0
  699. package/src/buffer-surprise-trigger.test.ts +766 -0
  700. package/src/buffer-surprise.test.ts +339 -0
  701. package/src/buffer-surprise.ts +203 -0
  702. package/src/buffer.ts +900 -0
  703. package/src/bulk-import/cli-command.test.ts +204 -0
  704. package/src/bulk-import/index.ts +34 -0
  705. package/src/bulk-import/pipeline.test.ts +445 -0
  706. package/src/bulk-import/pipeline.ts +178 -0
  707. package/src/bulk-import/registry.test.ts +151 -0
  708. package/src/bulk-import/registry.ts +72 -0
  709. package/src/bulk-import/types.test.ts +272 -0
  710. package/src/bulk-import/types.ts +145 -0
  711. package/src/calibration.ts +394 -0
  712. package/src/capsule-cli.test.ts +398 -0
  713. package/src/capsule-cli.ts +565 -0
  714. package/src/causal-behavior.ts +308 -0
  715. package/src/causal-chain.ts +419 -0
  716. package/src/causal-consolidation.ts +370 -0
  717. package/src/causal-retrieval.ts +286 -0
  718. package/src/causal-trajectory-graph.ts +60 -0
  719. package/src/causal-trajectory.ts +303 -0
  720. package/src/chunking.ts +220 -0
  721. package/src/citations.ts +232 -0
  722. package/src/cli.ts +9403 -0
  723. package/src/codex-cli-fallback.ts +162 -0
  724. package/src/codex-thread-key.ts +1 -0
  725. package/src/coding/access-coding-context.test.ts +197 -0
  726. package/src/coding/coding-branch-scope.test.ts +281 -0
  727. package/src/coding/coding-namespace.test.ts +360 -0
  728. package/src/coding/coding-namespace.ts +412 -0
  729. package/src/coding/coding-orchestrator.test.ts +249 -0
  730. package/src/coding/git-context.test.ts +507 -0
  731. package/src/coding/git-context.ts +336 -0
  732. package/src/coding/mcp-set-coding-context.test.ts +174 -0
  733. package/src/coding/review-context.test.ts +316 -0
  734. package/src/coding/review-context.ts +349 -0
  735. package/src/coding/wire-coding-context.test.ts +468 -0
  736. package/src/commitment-ledger.test.ts +78 -0
  737. package/src/commitment-ledger.ts +337 -0
  738. package/src/compat/checks.test.ts +206 -0
  739. package/src/compat/checks.ts +716 -0
  740. package/src/compat/types.ts +33 -0
  741. package/src/compounding/engine.ts +1686 -0
  742. package/src/compounding/preference-consolidator.ts +778 -0
  743. package/src/compression-optimizer.ts +312 -0
  744. package/src/config.test.ts +930 -0
  745. package/src/config.ts +3807 -0
  746. package/src/connectors/codex/instructions.md +160 -0
  747. package/src/connectors/codex/resources/namespace-cheatsheet.md +48 -0
  748. package/src/connectors/codex-marketplace.ts +500 -0
  749. package/src/connectors/codex-materialize-runner.ts +212 -0
  750. package/src/connectors/codex-materialize.ts +983 -0
  751. package/src/connectors/coerce.ts +62 -0
  752. package/src/connectors/index.test.ts +1570 -0
  753. package/src/connectors/index.ts +3222 -0
  754. package/src/connectors/live/framework.ts +164 -0
  755. package/src/connectors/live/github.test.ts +1218 -0
  756. package/src/connectors/live/github.ts +1068 -0
  757. package/src/connectors/live/gmail.test.ts +1706 -0
  758. package/src/connectors/live/gmail.ts +1293 -0
  759. package/src/connectors/live/google-drive.test.ts +696 -0
  760. package/src/connectors/live/google-drive.ts +724 -0
  761. package/src/connectors/live/index.ts +101 -0
  762. package/src/connectors/live/live-connectors.test.ts +689 -0
  763. package/src/connectors/live/notion.test.ts +1109 -0
  764. package/src/connectors/live/notion.ts +978 -0
  765. package/src/connectors/live/registry.ts +103 -0
  766. package/src/connectors/live/state-store.ts +399 -0
  767. package/src/connectors/live/transient-errors.ts +150 -0
  768. package/src/connectors/weclone-installer.test.ts +850 -0
  769. package/src/connectors-cli.ts +513 -0
  770. package/src/console/state.test.ts +224 -0
  771. package/src/console/state.ts +514 -0
  772. package/src/console/trace.test.ts +813 -0
  773. package/src/console/trace.ts +603 -0
  774. package/src/console/tui.test.ts +582 -0
  775. package/src/console/tui.ts +508 -0
  776. package/src/consolidation-operator.ts +182 -0
  777. package/src/consolidation-provenance-check.ts +551 -0
  778. package/src/consolidation-undo.ts +718 -0
  779. package/src/contradiction/contradiction-judge.test.ts +189 -0
  780. package/src/contradiction/contradiction-judge.ts +333 -0
  781. package/src/contradiction/contradiction-review.ts +574 -0
  782. package/src/contradiction/contradiction-scan.ts +504 -0
  783. package/src/contradiction/contradiction.test.ts +2230 -0
  784. package/src/contradiction/index.ts +37 -0
  785. package/src/contradiction/resolution.ts +383 -0
  786. package/src/conversation-index/backend.ts +323 -0
  787. package/src/conversation-index/chunker.ts +47 -0
  788. package/src/conversation-index/cleanup.ts +53 -0
  789. package/src/conversation-index/faiss-adapter.ts +384 -0
  790. package/src/conversation-index/indexer.test.ts +164 -0
  791. package/src/conversation-index/indexer.ts +192 -0
  792. package/src/conversation-index/search.ts +37 -0
  793. package/src/cross-namespace-budget.test.ts +275 -0
  794. package/src/cross-namespace-budget.ts +365 -0
  795. package/src/cue-anchors.ts +163 -0
  796. package/src/curation/index.ts +544 -0
  797. package/src/dashboard-runtime.ts +337 -0
  798. package/src/day-summary.ts +122 -0
  799. package/src/dedup/index.ts +330 -0
  800. package/src/dedup/semantic.test.ts +1577 -0
  801. package/src/dedup/semantic.ts +148 -0
  802. package/src/delinearize.ts +193 -0
  803. package/src/direct-answer-wiring.test.ts +473 -0
  804. package/src/direct-answer-wiring.ts +180 -0
  805. package/src/direct-answer.test.ts +484 -0
  806. package/src/direct-answer.ts +273 -0
  807. package/src/embedding-fallback.ts +565 -0
  808. package/src/enrichment/audit.ts +89 -0
  809. package/src/enrichment/index.ts +27 -0
  810. package/src/enrichment/pipeline.ts +197 -0
  811. package/src/enrichment/provider-registry.ts +85 -0
  812. package/src/enrichment/types.ts +100 -0
  813. package/src/enrichment/web-search-provider.ts +63 -0
  814. package/src/entity-retrieval.ts +774 -0
  815. package/src/entity-schema.ts +239 -0
  816. package/src/evals.ts +1312 -0
  817. package/src/event-order-recall.test.ts +4164 -0
  818. package/src/event-order-recall.ts +2802 -0
  819. package/src/evidence-pack.test.ts +89 -0
  820. package/src/evidence-pack.ts +388 -0
  821. package/src/explicit-capture.ts +530 -0
  822. package/src/explicit-cue-recall.test.ts +3019 -0
  823. package/src/explicit-cue-recall.ts +5545 -0
  824. package/src/extraction-judge-telemetry.ts +234 -0
  825. package/src/extraction-judge-training.ts +221 -0
  826. package/src/extraction-judge.ts +846 -0
  827. package/src/extraction-timeout.test.ts +265 -0
  828. package/src/extraction.ts +2719 -0
  829. package/src/fallback-llm.test.ts +1060 -0
  830. package/src/fallback-llm.ts +918 -0
  831. package/src/focused-list-recall.test.ts +734 -0
  832. package/src/focused-list-recall.ts +1160 -0
  833. package/src/graph-dashboard-diff.ts +35 -0
  834. package/src/graph-dashboard-key.ts +5 -0
  835. package/src/graph-dashboard-parser.ts +104 -0
  836. package/src/graph-edge-reinforcement.ts +192 -0
  837. package/src/graph-events.ts +151 -0
  838. package/src/graph-recall.test.ts +164 -0
  839. package/src/graph-recall.ts +189 -0
  840. package/src/graph-retrieval.test.ts +809 -0
  841. package/src/graph-retrieval.ts +823 -0
  842. package/src/graph-snapshot.ts +329 -0
  843. package/src/graph.ts +813 -0
  844. package/src/harmonic-retrieval.ts +223 -0
  845. package/src/himem.ts +154 -0
  846. package/src/hygiene.ts +87 -0
  847. package/src/identity-continuity.ts +333 -0
  848. package/src/importance.ts +328 -0
  849. package/src/importers/base.test.ts +294 -0
  850. package/src/importers/base.ts +436 -0
  851. package/src/importers/index.ts +21 -0
  852. package/src/index.ts +1204 -0
  853. package/src/intent.ts +154 -0
  854. package/src/json-extract.ts +85 -0
  855. package/src/json-store.ts +42 -0
  856. package/src/lcm/archive.ts +617 -0
  857. package/src/lcm/dag.ts +199 -0
  858. package/src/lcm/engine.ts +645 -0
  859. package/src/lcm/index.ts +7 -0
  860. package/src/lcm/queue.test.ts +178 -0
  861. package/src/lcm/queue.ts +200 -0
  862. package/src/lcm/recall.ts +117 -0
  863. package/src/lcm/schema.ts +154 -0
  864. package/src/lcm/summarizer.ts +235 -0
  865. package/src/lcm/tools.ts +191 -0
  866. package/src/lcm-engine.test.ts +660 -0
  867. package/src/legacy-hook-compat.test.ts +20 -0
  868. package/src/legacy-hook-compat.ts +45 -0
  869. package/src/lifecycle.ts +289 -0
  870. package/src/live-connectors-runner.ts +385 -0
  871. package/src/local-llm-qos.test.ts +303 -0
  872. package/src/local-llm-thinking.test.ts +292 -0
  873. package/src/local-llm.ts +1464 -0
  874. package/src/logger.ts +49 -0
  875. package/src/maintenance/archive-observations.ts +147 -0
  876. package/src/maintenance/backup-stamp.ts +3 -0
  877. package/src/maintenance/dreams-ledger.ts +516 -0
  878. package/src/maintenance/first-start-migration.ts +362 -0
  879. package/src/maintenance/forget.test.ts +206 -0
  880. package/src/maintenance/forget.ts +126 -0
  881. package/src/maintenance/graph-edge-decay.test.ts +409 -0
  882. package/src/maintenance/graph-edge-decay.ts +394 -0
  883. package/src/maintenance/memory-governance-cron.ts +447 -0
  884. package/src/maintenance/memory-governance.ts +1039 -0
  885. package/src/maintenance/migrate-observations.ts +216 -0
  886. package/src/maintenance/observation-ledger-utils.ts +54 -0
  887. package/src/maintenance/pattern-reinforcement.test.ts +875 -0
  888. package/src/maintenance/pattern-reinforcement.ts +369 -0
  889. package/src/maintenance/purge.ts +334 -0
  890. package/src/maintenance/rebuild-memory-lifecycle-ledger.ts +78 -0
  891. package/src/maintenance/rebuild-memory-projection.ts +1234 -0
  892. package/src/maintenance/rebuild-observations.ts +178 -0
  893. package/src/maintenance/tier-stats.test.ts +378 -0
  894. package/src/maintenance/tier-stats.ts +222 -0
  895. package/src/mcp-memory-inspector-app.ts +421 -0
  896. package/src/memory-action-policy.ts +80 -0
  897. package/src/memory-cache.ts +208 -0
  898. package/src/memory-extension/claude-code-publisher.ts +51 -0
  899. package/src/memory-extension/codex-publisher.ts +149 -0
  900. package/src/memory-extension/hermes-publisher.ts +51 -0
  901. package/src/memory-extension/index.ts +100 -0
  902. package/src/memory-extension/shared-instructions.ts +133 -0
  903. package/src/memory-extension/types.ts +86 -0
  904. package/src/memory-extension-host/host-discovery.ts +276 -0
  905. package/src/memory-extension-host/index.ts +14 -0
  906. package/src/memory-extension-host/render-extensions-block.ts +73 -0
  907. package/src/memory-extension-host/types.ts +21 -0
  908. package/src/memory-lifecycle-ledger-utils.ts +116 -0
  909. package/src/memory-projection-format.ts +11 -0
  910. package/src/memory-projection-store.ts +951 -0
  911. package/src/memory-provenance.test.ts +196 -0
  912. package/src/memory-provenance.ts +484 -0
  913. package/src/memory-worth-bench.test.ts +71 -0
  914. package/src/memory-worth-bench.ts +265 -0
  915. package/src/memory-worth-filter.test.ts +209 -0
  916. package/src/memory-worth-filter.ts +204 -0
  917. package/src/memory-worth-frontmatter.test.ts +311 -0
  918. package/src/memory-worth-outcomes.test.ts +316 -0
  919. package/src/memory-worth-outcomes.ts +286 -0
  920. package/src/memory-worth.test.ts +317 -0
  921. package/src/memory-worth.ts +215 -0
  922. package/src/message-parts/index.ts +806 -0
  923. package/src/message-parts/message-parts.test.ts +421 -0
  924. package/src/migrate/from-engram.ts +789 -0
  925. package/src/model-registry.ts +313 -0
  926. package/src/models-json.ts +76 -0
  927. package/src/namespaces/migrate.ts +187 -0
  928. package/src/namespaces/path.ts +25 -0
  929. package/src/namespaces/principal.test.ts +195 -0
  930. package/src/namespaces/principal.ts +86 -0
  931. package/src/namespaces/search.test.ts +105 -0
  932. package/src/namespaces/search.ts +233 -0
  933. package/src/namespaces/storage.ts +74 -0
  934. package/src/native-knowledge.ts +1823 -0
  935. package/src/negative.ts +72 -0
  936. package/src/network/tailscale.ts +179 -0
  937. package/src/network/webdav.ts +385 -0
  938. package/src/objective-state-writers.ts +951 -0
  939. package/src/objective-state.ts +320 -0
  940. package/src/onboarding/index.ts +529 -0
  941. package/src/openai-chat-compat.ts +56 -0
  942. package/src/operator-toolkit.ts +2132 -0
  943. package/src/opik-exporter.test.ts +72 -0
  944. package/src/opik-exporter.ts +587 -0
  945. package/src/orchestrator-extraction-queue.test.ts +197 -0
  946. package/src/orchestrator-flush.test.ts +1171 -0
  947. package/src/orchestrator-pattern-reinforcement.test.ts +128 -0
  948. package/src/orchestrator-source-attribution.test.ts +701 -0
  949. package/src/orchestrator.ts +16368 -0
  950. package/src/page-versioning.ts +450 -0
  951. package/src/patterns-cli.ts +574 -0
  952. package/src/peers/index.ts +54 -0
  953. package/src/peers/migrate-from-identity-anchor.test.ts +291 -0
  954. package/src/peers/migrate-from-identity-anchor.ts +350 -0
  955. package/src/peers/peers.test.ts +419 -0
  956. package/src/peers/profile-reasoner.ts +694 -0
  957. package/src/peers/storage.ts +1350 -0
  958. package/src/peers/types.ts +138 -0
  959. package/src/plugin-id.ts +84 -0
  960. package/src/policy-runtime.ts +209 -0
  961. package/src/procedural/procedure-miner.ts +150 -0
  962. package/src/procedural/procedure-recall.ts +93 -0
  963. package/src/procedural/procedure-stats.ts +213 -0
  964. package/src/procedural/procedure-types.ts +132 -0
  965. package/src/procedural/reinforcement-core.test.ts +132 -0
  966. package/src/procedural/reinforcement-core.ts +73 -0
  967. package/src/profiling.test.ts +263 -0
  968. package/src/profiling.ts +435 -0
  969. package/src/projection/index.ts +398 -0
  970. package/src/qmd-recall-cache.test.ts +138 -0
  971. package/src/qmd-recall-cache.ts +111 -0
  972. package/src/qmd.test.ts +258 -0
  973. package/src/qmd.ts +2614 -0
  974. package/src/reasoning-trace-recall.ts +201 -0
  975. package/src/reasoning-trace-types.ts +235 -0
  976. package/src/recall-audit-anomaly.test.ts +246 -0
  977. package/src/recall-audit-anomaly.ts +297 -0
  978. package/src/recall-audit.test.ts +51 -0
  979. package/src/recall-audit.ts +72 -0
  980. package/src/recall-budget-config.test.ts +87 -0
  981. package/src/recall-disclosure-escalation.test.ts +196 -0
  982. package/src/recall-disclosure-escalation.ts +158 -0
  983. package/src/recall-disclosure-shaping.test.ts +146 -0
  984. package/src/recall-disclosure.test.ts +214 -0
  985. package/src/recall-explain-renderer.test.ts +140 -0
  986. package/src/recall-explain-renderer.ts +356 -0
  987. package/src/recall-mmr.test.ts +808 -0
  988. package/src/recall-mmr.ts +607 -0
  989. package/src/recall-qos.test.ts +85 -0
  990. package/src/recall-qos.ts +82 -0
  991. package/src/recall-query-policy.ts +221 -0
  992. package/src/recall-state.test.ts +233 -0
  993. package/src/recall-state.ts +456 -0
  994. package/src/recall-tag-filter.ts +143 -0
  995. package/src/recall-tokenization.ts +35 -0
  996. package/src/recall-xray-cli.test.ts +118 -0
  997. package/src/recall-xray-cli.ts +100 -0
  998. package/src/recall-xray-disclosure-telemetry.test.ts +183 -0
  999. package/src/recall-xray-renderer.test.ts +539 -0
  1000. package/src/recall-xray-renderer.ts +487 -0
  1001. package/src/recall-xray.test.ts +503 -0
  1002. package/src/recall-xray.ts +621 -0
  1003. package/src/reconstruct.ts +41 -0
  1004. package/src/release-changelog.ts +35 -0
  1005. package/src/relevance.ts +67 -0
  1006. package/src/replay/normalizers/chatgpt.ts +133 -0
  1007. package/src/replay/normalizers/claude.ts +102 -0
  1008. package/src/replay/normalizers/openclaw.ts +119 -0
  1009. package/src/replay/normalizers/shared.ts +69 -0
  1010. package/src/replay/runner.ts +197 -0
  1011. package/src/replay/types.ts +143 -0
  1012. package/src/rerank.test.ts +48 -0
  1013. package/src/rerank.ts +176 -0
  1014. package/src/resolve-auth-token.test.ts +226 -0
  1015. package/src/resolve-auth-token.ts +151 -0
  1016. package/src/resolve-provider-secret.test.ts +187 -0
  1017. package/src/resolve-provider-secret.ts +410 -0
  1018. package/src/response-guidance-recall.test.ts +3952 -0
  1019. package/src/response-guidance-recall.ts +4431 -0
  1020. package/src/resume-bundles.ts +415 -0
  1021. package/src/retrieval-agents.ts +623 -0
  1022. package/src/retrieval-tiers.ts +25 -0
  1023. package/src/retrieval.ts +104 -0
  1024. package/src/review/index.test.ts +201 -0
  1025. package/src/review/index.ts +536 -0
  1026. package/src/routing/engine.ts +162 -0
  1027. package/src/routing/store.ts +321 -0
  1028. package/src/runtime/better-sqlite.test.ts +32 -0
  1029. package/src/runtime/better-sqlite.ts +76 -0
  1030. package/src/runtime/child-process.ts +67 -0
  1031. package/src/runtime/env.ts +48 -0
  1032. package/src/sanitize.ts +58 -0
  1033. package/src/schemas.ts +449 -0
  1034. package/src/sdk-compat.ts +87 -0
  1035. package/src/search/document-scanner.ts +96 -0
  1036. package/src/search/embed-helper.ts +142 -0
  1037. package/src/search/factory.ts +189 -0
  1038. package/src/search/index.ts +10 -0
  1039. package/src/search/lancedb-backend.ts +342 -0
  1040. package/src/search/meilisearch-backend.ts +232 -0
  1041. package/src/search/noop-backend.ts +57 -0
  1042. package/src/search/orama-backend.ts +358 -0
  1043. package/src/search/port.ts +86 -0
  1044. package/src/search/remote-backend.ts +124 -0
  1045. package/src/secure-store/cipher.ts +271 -0
  1046. package/src/secure-store/cli-handlers.ts +355 -0
  1047. package/src/secure-store/cli-renderer.ts +131 -0
  1048. package/src/secure-store/header.ts +373 -0
  1049. package/src/secure-store/index.ts +137 -0
  1050. package/src/secure-store/kdf.ts +263 -0
  1051. package/src/secure-store/keyring.ts +106 -0
  1052. package/src/secure-store/metadata.ts +394 -0
  1053. package/src/secure-store/passphrase-reader.ts +252 -0
  1054. package/src/secure-store/secure-fs.ts +571 -0
  1055. package/src/secure-store/secure-store.test.ts +755 -0
  1056. package/src/semantic-chunking.ts +545 -0
  1057. package/src/semantic-consolidation.test.ts +182 -0
  1058. package/src/semantic-consolidation.ts +432 -0
  1059. package/src/semantic-rule-promotion.ts +183 -0
  1060. package/src/semantic-rule-verifier.ts +160 -0
  1061. package/src/session-integrity.ts +569 -0
  1062. package/src/session-observer-bands.ts +11 -0
  1063. package/src/session-observer-state.ts +346 -0
  1064. package/src/session-toggles.test.ts +96 -0
  1065. package/src/session-toggles.ts +159 -0
  1066. package/src/shared-context/manager.ts +810 -0
  1067. package/src/signal.ts +84 -0
  1068. package/src/skills-registry.test.ts +277 -0
  1069. package/src/skills-registry.ts +120 -0
  1070. package/src/source-attribution-roundtrip.test.ts +215 -0
  1071. package/src/source-attribution.test.ts +1425 -0
  1072. package/src/source-attribution.ts +639 -0
  1073. package/src/spaces/index.ts +627 -0
  1074. package/src/storage-paths.ts +117 -0
  1075. package/src/storage.ts +6657 -0
  1076. package/src/store-contract.ts +55 -0
  1077. package/src/summarizer.ts +844 -0
  1078. package/src/summary-snapshot.test.ts +681 -0
  1079. package/src/summary-snapshot.ts +238 -0
  1080. package/src/surfaces/dreams.test.ts +394 -0
  1081. package/src/surfaces/dreams.ts +346 -0
  1082. package/src/surfaces/heartbeat.test.ts +415 -0
  1083. package/src/surfaces/heartbeat.ts +325 -0
  1084. package/src/sync/index.ts +308 -0
  1085. package/src/targeted-fact-recall.test.ts +1694 -0
  1086. package/src/targeted-fact-recall.ts +2905 -0
  1087. package/src/taxonomy/default-taxonomy.ts +87 -0
  1088. package/src/taxonomy/index.ts +26 -0
  1089. package/src/taxonomy/resolver-doc-generator.ts +57 -0
  1090. package/src/taxonomy/resolver.ts +184 -0
  1091. package/src/taxonomy/taxonomy-loader.ts +186 -0
  1092. package/src/taxonomy/types.ts +48 -0
  1093. package/src/telemetry-transcript.ts +70 -0
  1094. package/src/temporal-index.ts +890 -0
  1095. package/src/temporal-supersession.test.ts +2703 -0
  1096. package/src/temporal-supersession.ts +493 -0
  1097. package/src/temporal-validity.test.ts +448 -0
  1098. package/src/temporal-validity.ts +123 -0
  1099. package/src/threading.ts +395 -0
  1100. package/src/tier-migration.ts +124 -0
  1101. package/src/tier-routing.ts +102 -0
  1102. package/src/tmt.ts +462 -0
  1103. package/src/tokens.test.ts +178 -0
  1104. package/src/tokens.ts +279 -0
  1105. package/src/topics.ts +147 -0
  1106. package/src/training-export/cli-date-validation.test.ts +258 -0
  1107. package/src/training-export/converter.test.ts +452 -0
  1108. package/src/training-export/converter.ts +319 -0
  1109. package/src/training-export/date-parse.ts +117 -0
  1110. package/src/training-export/index.ts +26 -0
  1111. package/src/training-export/registry.test.ts +85 -0
  1112. package/src/training-export/registry.ts +57 -0
  1113. package/src/training-export/types.ts +31 -0
  1114. package/src/transcript.ts +1179 -0
  1115. package/src/transfer/autodetect.ts +30 -0
  1116. package/src/transfer/backup.ts +138 -0
  1117. package/src/transfer/capsule-crypto.ts +485 -0
  1118. package/src/transfer/capsule-encrypt.test.ts +690 -0
  1119. package/src/transfer/capsule-export.ts +543 -0
  1120. package/src/transfer/capsule-fork.ts +375 -0
  1121. package/src/transfer/capsule-import.ts +564 -0
  1122. package/src/transfer/capsule-merge.ts +433 -0
  1123. package/src/transfer/conflict-policy.ts +16 -0
  1124. package/src/transfer/constants.ts +13 -0
  1125. package/src/transfer/exclusions.ts +37 -0
  1126. package/src/transfer/export-json.ts +65 -0
  1127. package/src/transfer/export-md.ts +59 -0
  1128. package/src/transfer/export-sqlite.ts +52 -0
  1129. package/src/transfer/fs-utils.ts +269 -0
  1130. package/src/transfer/import-json.ts +108 -0
  1131. package/src/transfer/import-md.ts +84 -0
  1132. package/src/transfer/import-sqlite.ts +100 -0
  1133. package/src/transfer/integrity.ts +71 -0
  1134. package/src/transfer/sqlite-schema.ts +16 -0
  1135. package/src/transfer/types.ts +297 -0
  1136. package/src/trust-zones.ts +1186 -0
  1137. package/src/types.ts +3074 -0
  1138. package/src/user-model.test.ts +124 -0
  1139. package/src/user-model.ts +162 -0
  1140. package/src/utility-learner.ts +353 -0
  1141. package/src/utility-runtime.ts +88 -0
  1142. package/src/utility-telemetry.ts +215 -0
  1143. package/src/utils/category-dir.ts +44 -0
  1144. package/src/utils/errno.ts +6 -0
  1145. package/src/utils/iso-timestamp.test.ts +37 -0
  1146. package/src/utils/iso-timestamp.ts +164 -0
  1147. package/src/utils/path.ts +26 -0
  1148. package/src/verified-recall.ts +138 -0
  1149. package/src/version-utils.test.ts +10 -0
  1150. package/src/version-utils.ts +9 -0
  1151. package/src/whitespace.ts +10 -0
  1152. package/src/work/board.ts +359 -0
  1153. package/src/work/boundary.ts +107 -0
  1154. package/src/work/storage.ts +436 -0
  1155. package/src/work/types.ts +82 -0
  1156. package/src/work-product-ledger.ts +265 -0
  1157. package/dist/access-service-DDjzFALq.d.ts +0 -2088
  1158. package/dist/capsule-crypto-SJS5VVAP.js +0 -18
  1159. package/dist/capsule-export-7QNCBZOQ.js +0 -17
  1160. package/dist/capsule-import-EPBHD2EN.js +0 -16
  1161. package/dist/capsule-merge-DI7PNQ2H.js +0 -189
  1162. package/dist/chunk-23ZZK64Y.js +0 -26
  1163. package/dist/chunk-23ZZK64Y.js.map +0 -1
  1164. package/dist/chunk-242S3I2A.js +0 -647
  1165. package/dist/chunk-2LGMW3DJ.js +0 -111
  1166. package/dist/chunk-3B6KIRBH.js +0 -5213
  1167. package/dist/chunk-3B6KIRBH.js.map +0 -1
  1168. package/dist/chunk-457A4P3L.js +0 -119
  1169. package/dist/chunk-457A4P3L.js.map +0 -1
  1170. package/dist/chunk-4IS4SXIQ.js +0 -2040
  1171. package/dist/chunk-4YM32CRU.js +0 -721
  1172. package/dist/chunk-6TBWYBJ3.js +0 -236
  1173. package/dist/chunk-74EMIVE4.js +0 -329
  1174. package/dist/chunk-74EMIVE4.js.map +0 -1
  1175. package/dist/chunk-767ODGE6.js +0 -183
  1176. package/dist/chunk-7V22HTMD.js +0 -623
  1177. package/dist/chunk-7V22HTMD.js.map +0 -1
  1178. package/dist/chunk-7ZM3BFKK.js +0 -9705
  1179. package/dist/chunk-7ZM3BFKK.js.map +0 -1
  1180. package/dist/chunk-AQJNPMOA.js +0 -643
  1181. package/dist/chunk-AQJNPMOA.js.map +0 -1
  1182. package/dist/chunk-ASAITVLA.js +0 -64
  1183. package/dist/chunk-ASAITVLA.js.map +0 -1
  1184. package/dist/chunk-BBE34QBJ.js +0 -275
  1185. package/dist/chunk-BBE34QBJ.js.map +0 -1
  1186. package/dist/chunk-BZSQEPRW.js +0 -14710
  1187. package/dist/chunk-BZSQEPRW.js.map +0 -1
  1188. package/dist/chunk-CPKTBRS2.js +0 -891
  1189. package/dist/chunk-CPKTBRS2.js.map +0 -1
  1190. package/dist/chunk-D4GAOFF6.js +0 -562
  1191. package/dist/chunk-D4GAOFF6.js.map +0 -1
  1192. package/dist/chunk-D54LZC5L.js +0 -147
  1193. package/dist/chunk-DF3RVK3X.js +0 -119
  1194. package/dist/chunk-DF3RVK3X.js.map +0 -1
  1195. package/dist/chunk-DZZPC36E.js +0 -1451
  1196. package/dist/chunk-DZZPC36E.js.map +0 -1
  1197. package/dist/chunk-E2UCDP5S.js +0 -570
  1198. package/dist/chunk-E6K4NIEU.js +0 -747
  1199. package/dist/chunk-E6K4NIEU.js.map +0 -1
  1200. package/dist/chunk-EEQLFRUM.js +0 -89
  1201. package/dist/chunk-ETOW6ACV.js +0 -158
  1202. package/dist/chunk-ETOW6ACV.js.map +0 -1
  1203. package/dist/chunk-FMEBPEAO.js +0 -347
  1204. package/dist/chunk-FMEBPEAO.js.map +0 -1
  1205. package/dist/chunk-FQDPCE3I.js +0 -1837
  1206. package/dist/chunk-FQDPCE3I.js.map +0 -1
  1207. package/dist/chunk-FYIYMQ5N.js +0 -221
  1208. package/dist/chunk-FYIYMQ5N.js.map +0 -1
  1209. package/dist/chunk-G2WADRQ3.js +0 -219
  1210. package/dist/chunk-G4SK7DSQ.js +0 -121
  1211. package/dist/chunk-GVPWB7EY.js +0 -390
  1212. package/dist/chunk-GVPWB7EY.js.map +0 -1
  1213. package/dist/chunk-HELQZFZO.js +0 -1075
  1214. package/dist/chunk-HL5LRPNA.js +0 -1914
  1215. package/dist/chunk-HL5LRPNA.js.map +0 -1
  1216. package/dist/chunk-HQZVVSVB.js +0 -147
  1217. package/dist/chunk-HQZVVSVB.js.map +0 -1
  1218. package/dist/chunk-HY3L4WKC.js +0 -2195
  1219. package/dist/chunk-HY3L4WKC.js.map +0 -1
  1220. package/dist/chunk-IB3BFHGN.js +0 -228
  1221. package/dist/chunk-IXEJRKCZ.js +0 -18
  1222. package/dist/chunk-JBMSGZEQ.js +0 -441
  1223. package/dist/chunk-JBMSGZEQ.js.map +0 -1
  1224. package/dist/chunk-JESOB2HO.js +0 -108
  1225. package/dist/chunk-JKDVIE52.js +0 -272
  1226. package/dist/chunk-JRNQ3RNA.js +0 -284
  1227. package/dist/chunk-JRNQ3RNA.js.map +0 -1
  1228. package/dist/chunk-K6WK37A6.js +0 -865
  1229. package/dist/chunk-K6WK37A6.js.map +0 -1
  1230. package/dist/chunk-MARWOCVP.js +0 -48
  1231. package/dist/chunk-MNU6ZBWT.js +0 -4454
  1232. package/dist/chunk-MNU6ZBWT.js.map +0 -1
  1233. package/dist/chunk-N5AKDXAI.js +0 -74
  1234. package/dist/chunk-OA3L7BFR.js +0 -183
  1235. package/dist/chunk-OA3L7BFR.js.map +0 -1
  1236. package/dist/chunk-OR64ZGRZ.js +0 -23
  1237. package/dist/chunk-P77UEOU2.js +0 -1521
  1238. package/dist/chunk-P77UEOU2.js.map +0 -1
  1239. package/dist/chunk-PH4C2U43.js +0 -239
  1240. package/dist/chunk-PH4C2U43.js.map +0 -1
  1241. package/dist/chunk-RVPLBATS.js +0 -1586
  1242. package/dist/chunk-RVPLBATS.js.map +0 -1
  1243. package/dist/chunk-U5JMRGKX.js +0 -340
  1244. package/dist/chunk-U5JMRGKX.js.map +0 -1
  1245. package/dist/chunk-URB2WSKZ.js +0 -350
  1246. package/dist/chunk-URB2WSKZ.js.map +0 -1
  1247. package/dist/chunk-UVMUAWVT.js +0 -596
  1248. package/dist/chunk-WEJG4TB5.js +0 -118
  1249. package/dist/chunk-X7HPGUVG.js +0 -271
  1250. package/dist/chunk-XAMBKFQS.js +0 -2777
  1251. package/dist/chunk-XAMBKFQS.js.map +0 -1
  1252. package/dist/chunk-XJKFSSDW.js +0 -726
  1253. package/dist/chunk-XJKFSSDW.js.map +0 -1
  1254. package/dist/chunk-XMHBH5H6.js +0 -283
  1255. package/dist/chunk-XMHBH5H6.js.map +0 -1
  1256. package/dist/chunk-XMVFHBHT.js +0 -277
  1257. package/dist/chunk-Y3VMVTYX.js +0 -53
  1258. package/dist/chunk-YNB73F22.js +0 -137
  1259. package/dist/chunk-YNB73F22.js.map +0 -1
  1260. package/dist/chunk-Z2E7VW55.js +0 -335
  1261. package/dist/chunk-Z2E7VW55.js.map +0 -1
  1262. package/dist/chunk-ZG7PTKBK.js +0 -2296
  1263. package/dist/chunk-ZNQN6ZTA.js +0 -135
  1264. package/dist/chunk-ZVTKDVVM.js +0 -827
  1265. package/dist/chunk-ZVTKDVVM.js.map +0 -1
  1266. package/dist/cli-BR8KpIU0.d.ts +0 -1259
  1267. package/dist/codex-materialize-CQlLTzke.d.ts +0 -139
  1268. package/dist/connectors-cli-DFGtY2DB.d.ts +0 -257
  1269. package/dist/contradiction-review-5LTTVDQV.js +0 -22
  1270. package/dist/contradiction-scan-QTXAMBUA.js +0 -414
  1271. package/dist/contradiction-scan-QTXAMBUA.js.map +0 -1
  1272. package/dist/engine-35M5BKQ7.js +0 -28
  1273. package/dist/fs-utils-IRVUFB6G.js +0 -30
  1274. package/dist/graph-edge-decay-PWB63GRE.js +0 -207
  1275. package/dist/memory-governance-IMPQZXFC.js +0 -37
  1276. package/dist/memory-projection-store-CY8TU40w.d.ts +0 -222
  1277. package/dist/orchestrator-DDMPqU6R.d.ts +0 -1792
  1278. package/dist/path-RMTY5Y5A.js +0 -9
  1279. package/dist/port-B6VEDIkC.d.ts +0 -53
  1280. package/dist/resolution-YGIBORXI.js +0 -101
  1281. package/dist/resolution-YGIBORXI.js.map +0 -1
  1282. package/dist/secure-store-4R2GSO7S.js +0 -156
  1283. package/dist/semantic-consolidation-ByBXb-sf.d.ts +0 -180
  1284. package/dist/state-store-3EH7HYIN.js +0 -16
  1285. package/dist/types-V3FJ26TF.js +0 -30
  1286. /package/dist/{capsule-crypto-SJS5VVAP.js.map → adapters/claude-code.js.map} +0 -0
  1287. /package/dist/{capsule-export-7QNCBZOQ.js.map → adapters/codex.js.map} +0 -0
  1288. /package/dist/{capsule-import-EPBHD2EN.js.map → adapters/hermes.js.map} +0 -0
  1289. /package/dist/{contradiction-review-5LTTVDQV.js.map → adapters/index.js.map} +0 -0
  1290. /package/dist/{engine-35M5BKQ7.js.map → adapters/registry.js.map} +0 -0
  1291. /package/dist/{fs-utils-IRVUFB6G.js.map → adapters/replit.js.map} +0 -0
  1292. /package/dist/{memory-governance-IMPQZXFC.js.map → adapters/types.js.map} +0 -0
  1293. /package/dist/{path-RMTY5Y5A.js.map → capsule-crypto-5CYAGVC5.js.map} +0 -0
  1294. /package/dist/{capsule-merge-DI7PNQ2H.js.map → capsule-merge-4MGKE7C5.js.map} +0 -0
  1295. /package/dist/{chunk-G4SK7DSQ.js.map → chunk-2WWLHTZY.js.map} +0 -0
  1296. /package/dist/{chunk-X7HPGUVG.js.map → chunk-4CRG46BG.js.map} +0 -0
  1297. /package/dist/{chunk-UVMUAWVT.js.map → chunk-7IASACLB.js.map} +0 -0
  1298. /package/dist/{chunk-HELQZFZO.js.map → chunk-EDTHC6UD.js.map} +0 -0
  1299. /package/dist/{chunk-4YM32CRU.js.map → chunk-EFJ3MQ4V.js.map} +0 -0
  1300. /package/dist/{chunk-E2UCDP5S.js.map → chunk-FBYESMQ2.js.map} +0 -0
  1301. /package/dist/{chunk-D54LZC5L.js.map → chunk-FDU6HUUL.js.map} +0 -0
  1302. /package/dist/{chunk-IB3BFHGN.js.map → chunk-GGKRUQOO.js.map} +0 -0
  1303. /package/dist/{chunk-242S3I2A.js.map → chunk-GL6I6MEQ.js.map} +0 -0
  1304. /package/dist/{secure-store-4R2GSO7S.js.map → chunk-HHLLAQGZ.js.map} +0 -0
  1305. /package/dist/{chunk-4IS4SXIQ.js.map → chunk-HXXBL2KD.js.map} +0 -0
  1306. /package/dist/{chunk-767ODGE6.js.map → chunk-KNKUID7G.js.map} +0 -0
  1307. /package/dist/{chunk-6TBWYBJ3.js.map → chunk-LPMVBPA3.js.map} +0 -0
  1308. /package/dist/{chunk-WEJG4TB5.js.map → chunk-MC26UJIM.js.map} +0 -0
  1309. /package/dist/{chunk-JKDVIE52.js.map → chunk-MGKYQQYF.js.map} +0 -0
  1310. /package/dist/{chunk-Y3VMVTYX.js.map → chunk-MT4HVDUZ.js.map} +0 -0
  1311. /package/dist/{chunk-G2WADRQ3.js.map → chunk-MY6TPVXW.js.map} +0 -0
  1312. /package/dist/{chunk-OR64ZGRZ.js.map → chunk-NNVTUXEB.js.map} +0 -0
  1313. /package/dist/{chunk-JESOB2HO.js.map → chunk-P4NEIHUT.js.map} +0 -0
  1314. /package/dist/{chunk-IXEJRKCZ.js.map → chunk-QRNI5JBH.js.map} +0 -0
  1315. /package/dist/{chunk-EEQLFRUM.js.map → chunk-RRF5UOBJ.js.map} +0 -0
  1316. /package/dist/{state-store-3EH7HYIN.js.map → chunk-SEDEKFYQ.js.map} +0 -0
  1317. /package/dist/{chunk-2LGMW3DJ.js.map → chunk-U3PN77QT.js.map} +0 -0
  1318. /package/dist/{chunk-XMVFHBHT.js.map → chunk-U3WSW6PZ.js.map} +0 -0
  1319. /package/dist/{chunk-N5AKDXAI.js.map → chunk-UWVJF25J.js.map} +0 -0
  1320. /package/dist/{types-V3FJ26TF.js.map → chunk-V5OCT34X.js.map} +0 -0
  1321. /package/dist/{chunk-ZG7PTKBK.js.map → chunk-W3LR522O.js.map} +0 -0
  1322. /package/dist/{chunk-MARWOCVP.js.map → chunk-XIG5PDM7.js.map} +0 -0
  1323. /package/dist/{chunk-ZNQN6ZTA.js.map → chunk-XVZ7B3HG.js.map} +0 -0
  1324. /package/dist/{graph-edge-decay-PWB63GRE.js.map → graph-edge-decay-5DI5GUNL.js.map} +0 -0
@@ -1,1914 +0,0 @@
1
- import {
2
- QmdClient
3
- } from "./chunk-P77UEOU2.js";
4
- import {
5
- launchProcess
6
- } from "./chunk-OR64ZGRZ.js";
7
- import {
8
- isSafeRouteNamespace
9
- } from "./chunk-2LGMW3DJ.js";
10
- import {
11
- StorageManager
12
- } from "./chunk-3B6KIRBH.js";
13
- import {
14
- log
15
- } from "./chunk-2ODBA7MQ.js";
16
-
17
- // src/search/noop-backend.ts
18
- var NoopSearchBackend = class {
19
- async probe() {
20
- return false;
21
- }
22
- isAvailable() {
23
- return false;
24
- }
25
- debugStatus() {
26
- return "backend=noop";
27
- }
28
- async search(_query, _collection, _maxResults, _options, _execution) {
29
- return [];
30
- }
31
- async searchGlobal(_query, _maxResults, _execution) {
32
- return [];
33
- }
34
- async bm25Search(_query, _collection, _maxResults, _execution) {
35
- return [];
36
- }
37
- async vectorSearch(_query, _collection, _maxResults, _execution) {
38
- return [];
39
- }
40
- async hybridSearch(_query, _collection, _maxResults, _execution) {
41
- return [];
42
- }
43
- async update(_execution) {
44
- }
45
- async updateCollection(_collection, _execution) {
46
- }
47
- updatesAllCollections() {
48
- return false;
49
- }
50
- async embed() {
51
- }
52
- async embedCollection(_collection) {
53
- }
54
- async ensureCollection(_memoryDir) {
55
- return "skipped";
56
- }
57
- };
58
-
59
- // src/search/document-scanner.ts
60
- import path from "path";
61
- import { readdir, readFile } from "fs/promises";
62
- function parseFrontmatter(raw) {
63
- const normalized = raw.replace(/\r\n/g, "\n");
64
- const match = normalized.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
65
- if (!match) return null;
66
- const fmBlock = match[1];
67
- const body = (match[2] ?? "").trim();
68
- const data = {};
69
- for (const line of fmBlock.split("\n")) {
70
- const colonIdx = line.indexOf(":");
71
- if (colonIdx === -1) continue;
72
- const key = line.slice(0, colonIdx).trim();
73
- const value = line.slice(colonIdx + 1).trim();
74
- data[key] = value;
75
- }
76
- return { data, body };
77
- }
78
- async function scanDir(dir) {
79
- const docs = [];
80
- try {
81
- const entries = await readdir(dir, { withFileTypes: true });
82
- for (const entry of entries) {
83
- const fullPath = path.join(dir, entry.name);
84
- if (entry.isDirectory()) {
85
- const sub = await scanDir(fullPath);
86
- docs.push(...sub);
87
- } else if (entry.name.endsWith(".md")) {
88
- try {
89
- const raw = await readFile(fullPath, "utf-8");
90
- const parsed = parseFrontmatter(raw);
91
- const body = parsed ? parsed.body : raw.trim();
92
- const docid = parsed?.data.id || path.basename(entry.name, ".md");
93
- docs.push({
94
- docid,
95
- path: fullPath,
96
- content: body,
97
- snippet: body.slice(0, 200)
98
- });
99
- } catch {
100
- }
101
- }
102
- }
103
- } catch {
104
- }
105
- return docs;
106
- }
107
- async function scanMemoryDir(memoryDir) {
108
- const factsDir = path.join(memoryDir, "facts");
109
- const correctionsDir = path.join(memoryDir, "corrections");
110
- const proceduresDir = path.join(memoryDir, "procedures");
111
- const reasoningTracesDir = path.join(memoryDir, "reasoning-traces");
112
- const [facts, corrections, procedures, reasoningTraces] = await Promise.all([
113
- scanDir(factsDir),
114
- scanDir(correctionsDir),
115
- scanDir(proceduresDir),
116
- scanDir(reasoningTracesDir)
117
- ]);
118
- return [...facts, ...corrections, ...procedures, ...reasoningTraces];
119
- }
120
-
121
- // src/search/lancedb-backend.ts
122
- var LanceDbBackend = class {
123
- dbPath;
124
- collection;
125
- embedHelper;
126
- memoryDir;
127
- embeddingDimension;
128
- available = false;
129
- db = null;
130
- lanceModule = null;
131
- constructor(opts) {
132
- this.dbPath = opts.dbPath;
133
- this.collection = opts.collection;
134
- this.embedHelper = opts.embedHelper;
135
- this.memoryDir = opts.memoryDir;
136
- this.embeddingDimension = opts.embeddingDimension;
137
- }
138
- async probe() {
139
- try {
140
- await this.ensureDb();
141
- this.available = true;
142
- return true;
143
- } catch (err) {
144
- log.debug(`LanceDbBackend probe failed: ${err}`);
145
- this.available = false;
146
- return false;
147
- }
148
- }
149
- isAvailable() {
150
- return this.available;
151
- }
152
- debugStatus() {
153
- return `backend=lancedb available=${this.available} dbPath=${this.dbPath}`;
154
- }
155
- async search(query, _collection, maxResults, _options, _execution) {
156
- return this.hybridSearch(query, _collection, maxResults);
157
- }
158
- async searchGlobal(query, maxResults, _execution) {
159
- const limit = maxResults ?? 10;
160
- if (!this.available) return [];
161
- try {
162
- const db = await this.ensureDb();
163
- const tableNames = await db.tableNames();
164
- const allResults = [];
165
- for (const name of tableNames) {
166
- try {
167
- const table = await db.openTable(name);
168
- const results = await this.searchTable(table, query, "hybrid", limit);
169
- allResults.push(...results);
170
- } catch {
171
- }
172
- }
173
- allResults.sort((a, b) => b.score - a.score);
174
- return allResults.slice(0, limit);
175
- } catch (err) {
176
- log.debug(`LanceDbBackend searchGlobal failed: ${err}`);
177
- return [];
178
- }
179
- }
180
- async bm25Search(query, collection, maxResults, _execution) {
181
- const table = await this.ensureTableForCollection(collection ?? this.collection);
182
- if (!table) return [];
183
- return this.searchTable(table, query, "fts", maxResults ?? 10);
184
- }
185
- async vectorSearch(query, collection, maxResults, _execution) {
186
- const table = await this.ensureTableForCollection(collection ?? this.collection);
187
- if (!table) return [];
188
- return this.searchTable(table, query, "vector", maxResults ?? 10);
189
- }
190
- async hybridSearch(query, collection, maxResults, _execution) {
191
- const table = await this.ensureTableForCollection(collection ?? this.collection);
192
- if (!table) return [];
193
- return this.searchTable(table, query, "hybrid", maxResults ?? 10);
194
- }
195
- async update(execution) {
196
- await this.updateCollection(this.collection, execution);
197
- }
198
- async updateCollection(collection, _execution) {
199
- const table = await this.ensureTableForCollection(collection);
200
- if (!table) return;
201
- const docs = await scanMemoryDir(this.memoryDir);
202
- if (docs.length === 0) {
203
- try {
204
- const db = await this.ensureDb();
205
- await db.dropTable(collection).catch(() => {
206
- });
207
- if (collection === this.collection) this.table = null;
208
- } catch {
209
- }
210
- return;
211
- }
212
- const rows = docs.map((d) => ({
213
- docid: d.docid,
214
- path: d.path,
215
- content: d.content,
216
- snippet: d.snippet,
217
- vector: new Array(this.embeddingDimension).fill(0)
218
- }));
219
- try {
220
- const db = await this.ensureDb();
221
- await db.dropTable(collection).catch(() => {
222
- });
223
- if (collection === this.collection) this.table = null;
224
- const newTable = await db.createTable(collection, rows);
225
- try {
226
- await newTable.createIndex("content", { config: this.lanceIndex.fts() });
227
- } catch {
228
- }
229
- if (collection === this.collection) this.table = newTable;
230
- } catch (err) {
231
- log.debug(`LanceDbBackend update failed: ${err}`);
232
- }
233
- }
234
- async embed() {
235
- await this.embedCollection(this.collection);
236
- }
237
- async embedCollection(collection) {
238
- if (!this.embedHelper.isAvailable()) return;
239
- const table = await this.ensureTableForCollection(collection);
240
- if (!table) return;
241
- try {
242
- const allRows = await table.query().select(["docid", "content", "vector"]).toArray();
243
- const needsEmbed = allRows.filter((row) => {
244
- const vec = row.vector;
245
- if (!vec || typeof vec !== "object") return true;
246
- const arr = Array.from(vec);
247
- return arr.length === 0 || arr.every((v) => v === 0);
248
- });
249
- if (needsEmbed.length === 0) return;
250
- const texts = needsEmbed.map((row) => row.content);
251
- const vectors = await this.embedHelper.embedBatch(texts);
252
- for (let i = 0; i < needsEmbed.length; i++) {
253
- const vec = vectors[i];
254
- if (!vec) continue;
255
- const docid = needsEmbed[i].docid;
256
- await table.update({ where: `docid = '${docid.replace(/'/g, "''")}'`, values: { vector: vec } });
257
- }
258
- } catch (err) {
259
- log.debug(`LanceDbBackend embed failed: ${err}`);
260
- }
261
- }
262
- async ensureCollection(_memoryDir) {
263
- try {
264
- await this.ensureTable();
265
- return "present";
266
- } catch {
267
- return "missing";
268
- }
269
- }
270
- table = null;
271
- get lanceIndex() {
272
- return this.lanceModule.Index ?? this.lanceModule.default?.Index;
273
- }
274
- async ensureDb() {
275
- if (this.db) return this.db;
276
- if (!this.lanceModule) {
277
- this.lanceModule = await import("@lancedb/lancedb");
278
- }
279
- const connect = this.lanceModule.connect ?? this.lanceModule.default?.connect;
280
- this.db = await connect(this.dbPath);
281
- return this.db;
282
- }
283
- async ensureTableForCollection(collection) {
284
- if (collection === this.collection) return this.ensureTable();
285
- const db = await this.ensureDb();
286
- const tables = await db.tableNames();
287
- if (tables.includes(collection)) {
288
- return await db.openTable(collection);
289
- }
290
- const emptyRow = {
291
- docid: "__placeholder__",
292
- path: "",
293
- content: "",
294
- snippet: "",
295
- vector: new Array(this.embeddingDimension).fill(0)
296
- };
297
- const newTable = await db.createTable(collection, [emptyRow]);
298
- try {
299
- await newTable.createIndex("content", { config: this.lanceIndex.fts() });
300
- } catch {
301
- }
302
- try {
303
- await newTable.delete("docid = '__placeholder__'");
304
- } catch {
305
- }
306
- return newTable;
307
- }
308
- async ensureTable() {
309
- if (this.table) return this.table;
310
- const db = await this.ensureDb();
311
- const tables = await db.tableNames();
312
- if (tables.includes(this.collection)) {
313
- this.table = await db.openTable(this.collection);
314
- return this.table;
315
- }
316
- const emptyRow = {
317
- docid: "__placeholder__",
318
- path: "",
319
- content: "",
320
- snippet: "",
321
- vector: new Array(this.embeddingDimension).fill(0)
322
- };
323
- this.table = await db.createTable(this.collection, [emptyRow]);
324
- try {
325
- await this.table.createIndex("content", { config: this.lanceIndex.fts() });
326
- } catch {
327
- }
328
- try {
329
- await this.table.delete("docid = '__placeholder__'");
330
- } catch {
331
- }
332
- return this.table;
333
- }
334
- async searchTable(table, query, mode, limit) {
335
- try {
336
- if (mode === "fts") {
337
- const results = await table.search(query, "fts").limit(limit).toArray();
338
- return this.mapRows(results);
339
- }
340
- if (mode === "vector") {
341
- const vec2 = await this.embedHelper.embed(query);
342
- if (!vec2) {
343
- const results2 = await table.search(query, "fts").limit(limit).toArray();
344
- return this.mapRows(results2);
345
- }
346
- const results = await table.search(vec2).limit(limit).toArray();
347
- return this.mapRows(results);
348
- }
349
- const vec = await this.embedHelper.embed(query);
350
- if (!vec) {
351
- const results = await table.search(query, "fts").limit(limit).toArray();
352
- return this.mapRows(results);
353
- }
354
- try {
355
- const results = await table.search(query, "hybrid").vector(vec).limit(limit).toArray();
356
- return this.mapRows(results);
357
- } catch {
358
- const results = await table.search(vec).limit(limit).toArray();
359
- return this.mapRows(results);
360
- }
361
- } catch (err) {
362
- log.debug(`LanceDbBackend search (${mode}) failed: ${err}`);
363
- return [];
364
- }
365
- }
366
- mapRows(rows) {
367
- return (rows ?? []).filter((row) => row.docid && row.docid !== "__placeholder__").map((row) => ({
368
- docid: row.docid ?? "",
369
- path: row.path ?? "",
370
- snippet: row.snippet ?? row.content?.slice(0, 200) ?? "",
371
- score: row._relevance_score ?? (row._distance != null ? 1 / (1 + (row._distance ?? 0)) : 0.5)
372
- }));
373
- }
374
- };
375
-
376
- // src/search/meilisearch-backend.ts
377
- var MeilisearchBackend = class {
378
- host;
379
- apiKey;
380
- collection;
381
- timeoutMs;
382
- autoIndex;
383
- memoryDir;
384
- available = false;
385
- client = null;
386
- meiliModule = null;
387
- constructor(opts) {
388
- this.host = opts.host;
389
- this.apiKey = opts.apiKey;
390
- this.collection = opts.collection;
391
- this.timeoutMs = opts.timeoutMs ?? 3e4;
392
- this.autoIndex = opts.autoIndex ?? false;
393
- this.memoryDir = opts.memoryDir;
394
- }
395
- async probe() {
396
- try {
397
- const client = await this.ensureClient();
398
- await client.health();
399
- this.available = true;
400
- return true;
401
- } catch (err) {
402
- log.debug(`MeilisearchBackend probe failed: ${err}`);
403
- this.available = false;
404
- return false;
405
- }
406
- }
407
- isAvailable() {
408
- return this.available;
409
- }
410
- debugStatus() {
411
- return `backend=meilisearch available=${this.available} host=${this.host}`;
412
- }
413
- async search(query, collection, maxResults, _options, _execution) {
414
- try {
415
- return await this.doSearch(query, maxResults ?? 10, { hybrid: { semanticRatio: 0.5, embedder: "default" } }, collection, true);
416
- } catch {
417
- return this.bm25Search(query, collection, maxResults);
418
- }
419
- }
420
- async searchGlobal(query, maxResults, _execution) {
421
- const limit = maxResults ?? 10;
422
- if (!this.available) return [];
423
- try {
424
- const client = await this.ensureClient();
425
- const indexes = await client.getIndexes();
426
- const queries = (indexes.results ?? []).map((idx) => ({
427
- indexUid: idx.uid,
428
- q: query,
429
- limit,
430
- showRankingScore: true
431
- }));
432
- if (queries.length === 0) return [];
433
- const multiResult = await client.multiSearch({ queries });
434
- const allResults = [];
435
- for (const result of multiResult.results ?? []) {
436
- allResults.push(...this.mapHits(result.hits ?? []));
437
- }
438
- allResults.sort((a, b) => b.score - a.score);
439
- return allResults.slice(0, limit);
440
- } catch (err) {
441
- log.debug(`MeilisearchBackend searchGlobal failed: ${err}`);
442
- return [];
443
- }
444
- }
445
- async bm25Search(query, collection, maxResults, _execution) {
446
- return this.doSearch(query, maxResults ?? 10, void 0, collection);
447
- }
448
- async vectorSearch(query, collection, maxResults, _execution) {
449
- return this.doSearch(query, maxResults ?? 10, { hybrid: { semanticRatio: 1, embedder: "default" } }, collection);
450
- }
451
- async hybridSearch(query, collection, maxResults, _execution) {
452
- return this.doSearch(query, maxResults ?? 10, { hybrid: { semanticRatio: 0.5, embedder: "default" } }, collection);
453
- }
454
- async update(execution) {
455
- await this.updateCollection(this.collection, execution);
456
- }
457
- async updateCollection(collection, _execution) {
458
- if (!this.autoIndex || !this.memoryDir) return;
459
- if (!this.available) return;
460
- try {
461
- const client = await this.ensureClient();
462
- const docs = await scanMemoryDir(this.memoryDir);
463
- const index = client.index(collection);
464
- const meilDocs = docs.map((d) => ({
465
- id: d.docid,
466
- path: d.path,
467
- content: d.content,
468
- snippet: d.snippet
469
- }));
470
- const addTask = await index.addDocuments(meilDocs, { primaryKey: "id" });
471
- await client.waitForTask(addTask.taskUid, { timeOutMs: this.timeoutMs });
472
- const currentIds = new Set(docs.map((d) => d.docid));
473
- try {
474
- const PAGE_SIZE = 1e3;
475
- let offset = 0;
476
- let staleIds = [];
477
- let hasMore = true;
478
- while (hasMore) {
479
- const page = await index.getDocuments({ limit: PAGE_SIZE, offset, fields: ["id"] });
480
- const results = page.results ?? [];
481
- for (const doc of results) {
482
- const id = doc.id;
483
- if (!currentIds.has(id)) staleIds.push(id);
484
- }
485
- offset += results.length;
486
- hasMore = results.length === PAGE_SIZE;
487
- }
488
- if (staleIds.length > 0) {
489
- const delTask = await index.deleteDocuments(staleIds);
490
- await client.waitForTask(delTask.taskUid, { timeOutMs: this.timeoutMs });
491
- }
492
- } catch {
493
- }
494
- } catch (err) {
495
- log.debug(`MeilisearchBackend update failed: ${err}`);
496
- }
497
- }
498
- async embed() {
499
- }
500
- async embedCollection(collection) {
501
- }
502
- async ensureCollection(_memoryDir) {
503
- if (!this.available) return "skipped";
504
- try {
505
- const client = await this.ensureClient();
506
- try {
507
- await client.getIndex(this.collection);
508
- return "present";
509
- } catch {
510
- await client.createIndex(this.collection, { primaryKey: "id" });
511
- return "present";
512
- }
513
- } catch {
514
- return "skipped";
515
- }
516
- }
517
- async ensureClient() {
518
- if (this.client) return this.client;
519
- if (!this.meiliModule) {
520
- this.meiliModule = await import("meilisearch");
521
- }
522
- const MeiliSearch = this.meiliModule.MeiliSearch ?? this.meiliModule.default?.MeiliSearch;
523
- this.client = new MeiliSearch({
524
- host: this.host,
525
- apiKey: this.apiKey,
526
- timeout: this.timeoutMs
527
- });
528
- return this.client;
529
- }
530
- async doSearch(query, limit, extra, collection, rethrow = false) {
531
- if (!this.available) return [];
532
- try {
533
- const client = await this.ensureClient();
534
- const index = client.index(collection ?? this.collection);
535
- const result = await index.search(query, { limit, showRankingScore: true, ...extra });
536
- return this.mapHits(result.hits ?? []);
537
- } catch (err) {
538
- log.debug(`MeilisearchBackend search failed: ${err}`);
539
- if (rethrow) throw err;
540
- return [];
541
- }
542
- }
543
- mapHits(hits) {
544
- return hits.map((hit) => ({
545
- docid: hit.id ?? "",
546
- path: hit.path ?? "",
547
- snippet: hit._formatted?.content ?? hit.snippet ?? hit.content?.slice(0, 200) ?? "",
548
- score: hit._rankingScore ?? 0.5
549
- }));
550
- }
551
- };
552
-
553
- // src/search/orama-backend.ts
554
- import path2 from "path";
555
- import { mkdir, readdir as readdir2, readFile as readFile2, writeFile } from "fs/promises";
556
- var OramaBackend = class {
557
- dbPath;
558
- collection;
559
- embedHelper;
560
- memoryDir;
561
- embeddingDimension;
562
- available = false;
563
- db = null;
564
- oramaModule = null;
565
- persistModule = null;
566
- constructor(opts) {
567
- this.dbPath = opts.dbPath;
568
- this.collection = opts.collection;
569
- this.embedHelper = opts.embedHelper;
570
- this.memoryDir = opts.memoryDir;
571
- this.embeddingDimension = opts.embeddingDimension;
572
- }
573
- async probe() {
574
- try {
575
- await this.ensureModules();
576
- await this.ensureDb();
577
- this.available = true;
578
- return true;
579
- } catch (err) {
580
- log.debug(`OramaBackend probe failed: ${err}`);
581
- this.available = false;
582
- return false;
583
- }
584
- }
585
- isAvailable() {
586
- return this.available;
587
- }
588
- debugStatus() {
589
- return `backend=orama available=${this.available} dbPath=${this.dbPath}`;
590
- }
591
- async search(query, _collection, maxResults, _options, _execution) {
592
- return this.hybridSearch(query, _collection, maxResults);
593
- }
594
- async searchGlobal(query, maxResults, _execution) {
595
- const limit = maxResults ?? 10;
596
- if (!this.available) return [];
597
- try {
598
- const files = await this.listDbFiles();
599
- const allResults = [];
600
- for (const file of files) {
601
- const db = await this.loadDbFromFile(file);
602
- if (!db) continue;
603
- const results = await this.searchDb(db, query, "hybrid", limit);
604
- allResults.push(...results);
605
- }
606
- allResults.sort((a, b) => b.score - a.score);
607
- return allResults.slice(0, limit);
608
- } catch (err) {
609
- log.debug(`OramaBackend searchGlobal failed: ${err}`);
610
- return [];
611
- }
612
- }
613
- async bm25Search(query, collection, maxResults, _execution) {
614
- const db = await this.ensureDbForCollection(collection ?? this.collection);
615
- if (!db) return [];
616
- return this.searchDb(db, query, "fulltext", maxResults ?? 10);
617
- }
618
- async vectorSearch(query, collection, maxResults, _execution) {
619
- const db = await this.ensureDbForCollection(collection ?? this.collection);
620
- if (!db) return [];
621
- return this.searchDb(db, query, "vector", maxResults ?? 10);
622
- }
623
- async hybridSearch(query, collection, maxResults, _execution) {
624
- const db = await this.ensureDbForCollection(collection ?? this.collection);
625
- if (!db) return [];
626
- return this.searchDb(db, query, "hybrid", maxResults ?? 10);
627
- }
628
- async update(execution) {
629
- await this.updateCollection(this.collection, execution);
630
- }
631
- async updateCollection(collection, _execution) {
632
- const db = await this.ensureDbForCollection(collection);
633
- if (!db) return;
634
- const { search: oramaSearch, insert, remove, count } = this.oramaModule;
635
- const docs = await scanMemoryDir(this.memoryDir);
636
- const docMap = new Map(docs.map((d) => [d.docid, d]));
637
- const { update: oramaUpdate } = this.oramaModule;
638
- const existingDocs = /* @__PURE__ */ new Map();
639
- const existingCount = await count(db);
640
- if (existingCount > 0) {
641
- const allHits = await oramaSearch(db, { term: "", limit: existingCount + 100 });
642
- for (const hit of allHits.hits) {
643
- if (!docMap.has(hit.document.id)) {
644
- await remove(db, hit.id);
645
- } else {
646
- existingDocs.set(hit.document.id, {
647
- internalId: hit.id,
648
- vector: hit.document.vector
649
- });
650
- }
651
- }
652
- }
653
- for (const doc of docs) {
654
- const existing = existingDocs.get(doc.docid);
655
- if (existing) {
656
- const payload = {
657
- id: doc.docid,
658
- path: doc.path,
659
- content: doc.content,
660
- snippet: doc.snippet
661
- };
662
- if (existing.vector && existing.vector.length > 0) {
663
- payload.vector = existing.vector;
664
- }
665
- try {
666
- await oramaUpdate(db, existing.internalId, payload);
667
- } catch {
668
- }
669
- } else {
670
- try {
671
- await insert(db, {
672
- id: doc.docid,
673
- path: doc.path,
674
- content: doc.content,
675
- snippet: doc.snippet
676
- });
677
- } catch {
678
- }
679
- }
680
- }
681
- await this.persistDbForCollection(db, collection);
682
- }
683
- async embed() {
684
- await this.embedCollection(this.collection);
685
- }
686
- async embedCollection(collection) {
687
- if (!this.embedHelper.isAvailable()) return;
688
- const db = await this.ensureDbForCollection(collection);
689
- if (!db) return;
690
- const { search: oramaSearch, update: oramaUpdate, count } = this.oramaModule;
691
- const existingCount = await count(db);
692
- if (existingCount === 0) return;
693
- const allHits = await oramaSearch(db, { term: "", limit: existingCount + 100 });
694
- const needsEmbed = allHits.hits.filter((h) => !h.document.vector || h.document.vector.length === 0);
695
- if (needsEmbed.length === 0) return;
696
- const texts = needsEmbed.map((h) => h.document.content);
697
- const vectors = await this.embedHelper.embedBatch(texts);
698
- for (let i = 0; i < needsEmbed.length; i++) {
699
- const vec = vectors[i];
700
- if (!vec) continue;
701
- const doc = needsEmbed[i].document;
702
- await oramaUpdate(db, needsEmbed[i].id, {
703
- id: doc.id,
704
- path: doc.path,
705
- content: doc.content,
706
- snippet: doc.snippet,
707
- vector: vec
708
- });
709
- }
710
- await this.persistDbForCollection(db, collection);
711
- }
712
- async ensureCollection(_memoryDir) {
713
- try {
714
- await this.ensureModules();
715
- await this.ensureDb();
716
- return "present";
717
- } catch {
718
- return "missing";
719
- }
720
- }
721
- async ensureModules() {
722
- if (this.oramaModule && this.persistModule) return;
723
- this.oramaModule = await import("@orama/orama");
724
- this.persistModule = await import("@orama/plugin-data-persistence");
725
- }
726
- async ensureDb() {
727
- if (this.db) return this.db;
728
- await this.ensureModules();
729
- await mkdir(this.dbPath, { recursive: true });
730
- const filePath = this.dbFilePath(this.collection);
731
- try {
732
- const raw = await readFile2(filePath, "utf-8");
733
- this.db = await this.persistModule.restore("json", raw);
734
- return this.db;
735
- } catch {
736
- }
737
- const { create } = this.oramaModule;
738
- const schema = {
739
- id: "string",
740
- path: "string",
741
- content: "string",
742
- snippet: "string"
743
- };
744
- if (this.embedHelper.isAvailable()) {
745
- schema.vector = `vector[${this.embeddingDimension}]`;
746
- }
747
- this.db = await create({ schema });
748
- return this.db;
749
- }
750
- async ensureDbForCollection(collection) {
751
- if (collection === this.collection) return this.ensureDb();
752
- await this.ensureModules();
753
- await mkdir(this.dbPath, { recursive: true });
754
- const filePath = this.dbFilePath(collection);
755
- try {
756
- const raw = await readFile2(filePath, "utf-8");
757
- return await this.persistModule.restore("json", raw);
758
- } catch {
759
- }
760
- const { create } = this.oramaModule;
761
- const schema = {
762
- id: "string",
763
- path: "string",
764
- content: "string",
765
- snippet: "string"
766
- };
767
- if (this.embedHelper.isAvailable()) {
768
- schema.vector = `vector[${this.embeddingDimension}]`;
769
- }
770
- return await create({ schema });
771
- }
772
- async persistDbForCollection(db, collection) {
773
- const data = await this.persistModule.persist(db, "json");
774
- const filePath = this.dbFilePath(collection);
775
- await mkdir(path2.dirname(filePath), { recursive: true });
776
- await writeFile(filePath, data, "utf-8");
777
- }
778
- dbFilePath(collection) {
779
- return path2.join(this.dbPath, `${collection}.msp`);
780
- }
781
- async listDbFiles() {
782
- try {
783
- const entries = await readdir2(this.dbPath);
784
- return entries.filter((e) => e.endsWith(".msp")).map((e) => path2.join(this.dbPath, e));
785
- } catch {
786
- return [];
787
- }
788
- }
789
- async loadDbFromFile(filePath) {
790
- try {
791
- await this.ensureModules();
792
- const raw = await readFile2(filePath, "utf-8");
793
- return await this.persistModule.restore("json", raw);
794
- } catch {
795
- return null;
796
- }
797
- }
798
- async searchDb(db, query, mode, limit) {
799
- const { search: oramaSearch } = this.oramaModule;
800
- try {
801
- let searchParams;
802
- if (mode === "fulltext") {
803
- searchParams = { term: query, limit };
804
- } else if (mode === "vector") {
805
- const vec = await this.embedHelper.embed(query);
806
- if (!vec) {
807
- searchParams = { term: query, limit };
808
- } else {
809
- searchParams = { mode: "vector", vector: { value: vec, property: "vector" }, limit };
810
- }
811
- } else {
812
- const vec = await this.embedHelper.embed(query);
813
- if (!vec) {
814
- searchParams = { term: query, limit };
815
- } else {
816
- searchParams = { mode: "hybrid", term: query, vector: { value: vec, property: "vector" }, limit };
817
- }
818
- }
819
- const result = await oramaSearch(db, searchParams);
820
- return (result.hits ?? []).map((hit) => ({
821
- docid: hit.document?.id ?? "",
822
- path: hit.document?.path ?? "",
823
- snippet: hit.document?.snippet ?? hit.document?.content?.slice(0, 200) ?? "",
824
- score: hit.score ?? 0
825
- }));
826
- } catch (err) {
827
- log.debug(`OramaBackend search (${mode}) failed: ${err}`);
828
- return [];
829
- }
830
- }
831
- };
832
-
833
- // src/conversation-index/indexer.ts
834
- import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
835
- import path3 from "path";
836
- function sanitizeSessionKey(sessionKey) {
837
- const raw = typeof sessionKey === "string" && sessionKey.trim().length > 0 ? sessionKey : "unknown-session";
838
- return raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "_").slice(0, 200);
839
- }
840
- async function writeConversationChunks(rootDir, chunks) {
841
- const written = [];
842
- for (const c of chunks) {
843
- const safe = sanitizeSessionKey(c.sessionKey);
844
- const date = c.startTs.slice(0, 10);
845
- const dir = path3.join(rootDir, safe, date);
846
- await mkdir2(dir, { recursive: true });
847
- const fp = path3.join(dir, `${c.id}.md`);
848
- const content = `---
849
- kind: conversation_chunk
850
- sessionKey: ${c.sessionKey}
851
- startTs: ${c.startTs}
852
- endTs: ${c.endTs}
853
- ---
854
-
855
- ` + c.text + "\n";
856
- await writeFile2(fp, content, "utf-8");
857
- written.push(fp);
858
- }
859
- return written;
860
- }
861
- async function upsertConversationChunksFailOpen(adapter, chunks) {
862
- if (!adapter) {
863
- return { upserted: 0, skipped: true, reason: "adapter-unavailable" };
864
- }
865
- try {
866
- const upserted = await adapter.upsertChunks(chunks);
867
- return { upserted, skipped: false };
868
- } catch (err) {
869
- log.debug(`conversation index FAISS upsert failed (fail-open): ${err}`);
870
- return { upserted: 0, skipped: true, reason: "adapter-error" };
871
- }
872
- }
873
- async function rebuildConversationChunksFailOpen(adapter, chunks) {
874
- if (!adapter) {
875
- return { rebuilt: 0, skipped: true, reason: "adapter-unavailable" };
876
- }
877
- try {
878
- const rebuilt = await adapter.rebuildChunks(chunks);
879
- return { rebuilt, skipped: false };
880
- } catch (err) {
881
- log.debug(`conversation index FAISS rebuild failed (fail-open): ${err}`);
882
- return { rebuilt: 0, skipped: true, reason: "adapter-error" };
883
- }
884
- }
885
-
886
- // src/search/factory.ts
887
- import path5 from "path";
888
-
889
- // src/search/remote-backend.ts
890
- var RemoteSearchBackend = class {
891
- baseUrl;
892
- apiKey;
893
- timeoutMs;
894
- available = false;
895
- constructor(opts) {
896
- let url = opts.baseUrl;
897
- while (url.endsWith("/")) url = url.slice(0, -1);
898
- this.baseUrl = url;
899
- this.apiKey = opts.apiKey;
900
- this.timeoutMs = opts.timeoutMs ?? 3e4;
901
- }
902
- async probe() {
903
- try {
904
- const res = await fetch(`${this.baseUrl}/health`, {
905
- method: "GET",
906
- headers: this.headers(),
907
- signal: AbortSignal.timeout(this.timeoutMs)
908
- });
909
- this.available = res.ok;
910
- return this.available;
911
- } catch (err) {
912
- log.debug(`RemoteSearchBackend probe failed: ${err}`);
913
- this.available = false;
914
- return false;
915
- }
916
- }
917
- isAvailable() {
918
- return this.available;
919
- }
920
- debugStatus() {
921
- return `backend=remote available=${this.available} baseUrl=${this.baseUrl}`;
922
- }
923
- async search(query, collection, maxResults, _options, execution) {
924
- return this.post("/search/deep", { query, collection, maxResults }, execution);
925
- }
926
- async searchGlobal(query, maxResults, execution) {
927
- return this.post("/search/deep", { query, maxResults }, execution);
928
- }
929
- async bm25Search(query, collection, maxResults, execution) {
930
- return this.post("/search/bm25", { query, collection, maxResults }, execution);
931
- }
932
- async vectorSearch(query, collection, maxResults, execution) {
933
- return this.post("/search/vector", { query, collection, maxResults }, execution);
934
- }
935
- async hybridSearch(query, collection, maxResults, execution) {
936
- return this.post("/search/hybrid", { query, collection, maxResults }, execution);
937
- }
938
- async update(_execution) {
939
- }
940
- async updateCollection(_collection, _execution) {
941
- }
942
- async embed() {
943
- }
944
- async embedCollection(_collection) {
945
- }
946
- async ensureCollection(_memoryDir) {
947
- return "skipped";
948
- }
949
- headers() {
950
- const h = { "Content-Type": "application/json" };
951
- if (this.apiKey) {
952
- h["Authorization"] = `Bearer ${this.apiKey}`;
953
- }
954
- return h;
955
- }
956
- async post(endpoint, body, execution) {
957
- if (!this.available) return [];
958
- try {
959
- const res = await fetch(`${this.baseUrl}${endpoint}`, {
960
- method: "POST",
961
- headers: this.headers(),
962
- body: JSON.stringify(body),
963
- signal: execution?.signal ? AbortSignal.any([execution.signal, AbortSignal.timeout(this.timeoutMs)]) : AbortSignal.timeout(this.timeoutMs)
964
- });
965
- if (!res.ok) {
966
- log.debug(`RemoteSearchBackend ${endpoint} returned ${res.status}`);
967
- return [];
968
- }
969
- const data = await res.json();
970
- if (!Array.isArray(data)) return [];
971
- return data;
972
- } catch (err) {
973
- log.debug(`RemoteSearchBackend ${endpoint} failed: ${err}`);
974
- return [];
975
- }
976
- }
977
- };
978
-
979
- // src/search/embed-helper.ts
980
- var DEFAULT_OPENAI_MODEL = "text-embedding-3-small";
981
- var EmbedHelper = class {
982
- // undefined = not yet resolved
983
- constructor(config) {
984
- this.config = config;
985
- }
986
- config;
987
- provider;
988
- /**
989
- * Whether an embedding provider is available.
990
- * Resolves the provider on first call.
991
- */
992
- isAvailable() {
993
- if (this.provider === void 0) {
994
- this.provider = this.resolveProvider();
995
- }
996
- return this.provider !== null;
997
- }
998
- /**
999
- * Embed a single text string. Returns null if no provider is available.
1000
- */
1001
- async embed(text) {
1002
- const provider = this.getProvider();
1003
- if (!provider) return null;
1004
- return this.callEmbed(text, provider);
1005
- }
1006
- /**
1007
- * Embed a batch of texts. Returns an array parallel to input; entries are null on failure.
1008
- */
1009
- async embedBatch(texts, batchSize = 32) {
1010
- const provider = this.getProvider();
1011
- if (!provider) return texts.map(() => null);
1012
- const results = new Array(texts.length).fill(null);
1013
- for (let i = 0; i < texts.length; i += batchSize) {
1014
- const batch = texts.slice(i, i + batchSize);
1015
- const batchResults = await Promise.all(batch.map((t) => this.callEmbed(t, provider)));
1016
- for (let j = 0; j < batchResults.length; j++) {
1017
- results[i + j] = batchResults[j];
1018
- }
1019
- }
1020
- return results;
1021
- }
1022
- getProvider() {
1023
- if (this.provider === void 0) {
1024
- this.provider = this.resolveProvider();
1025
- }
1026
- return this.provider;
1027
- }
1028
- resolveProvider() {
1029
- if (!this.config.embeddingFallbackEnabled) return null;
1030
- const preferred = this.config.embeddingFallbackProvider;
1031
- const providers = preferred === "auto" ? ["openai", "local"] : [preferred];
1032
- for (const p of providers) {
1033
- if (p === "openai" && this.config.openaiApiKey) {
1034
- const baseUrl = this.config.openaiBaseUrl ?? "https://api.openai.com/v1";
1035
- return {
1036
- type: "openai",
1037
- model: DEFAULT_OPENAI_MODEL,
1038
- endpoint: `${baseUrl.replace(/\/$/, "")}/embeddings`,
1039
- headers: {
1040
- "Content-Type": "application/json",
1041
- Authorization: `Bearer ${this.config.openaiApiKey}`
1042
- }
1043
- };
1044
- }
1045
- if (p === "local" && this.config.localLlmEnabled && this.config.localLlmUrl) {
1046
- const base = this.config.localLlmUrl.replace(/\/$/, "");
1047
- const endpoint = /\/v1$/i.test(base) ? `${base}/embeddings` : `${base}/v1/embeddings`;
1048
- const headers = {
1049
- "Content-Type": "application/json",
1050
- ...this.config.localLlmHeaders ?? {}
1051
- };
1052
- if (this.config.localLlmApiKey && this.config.localLlmAuthHeader !== false) {
1053
- headers.Authorization = `Bearer ${this.config.localLlmApiKey}`;
1054
- }
1055
- return {
1056
- type: "local",
1057
- model: this.config.localLlmModel || DEFAULT_OPENAI_MODEL,
1058
- endpoint,
1059
- headers
1060
- };
1061
- }
1062
- }
1063
- return null;
1064
- }
1065
- async callEmbed(input, provider) {
1066
- try {
1067
- const res = await fetch(provider.endpoint, {
1068
- method: "POST",
1069
- headers: provider.headers,
1070
- body: JSON.stringify({
1071
- model: provider.model,
1072
- input: input.slice(0, 8e3),
1073
- encoding_format: "float"
1074
- }),
1075
- signal: AbortSignal.timeout(3e4)
1076
- });
1077
- if (!res.ok) {
1078
- log.debug(`EmbedHelper request failed: ${provider.type} ${res.status}`);
1079
- return null;
1080
- }
1081
- const payload = await res.json();
1082
- const vector = payload?.data?.[0]?.embedding;
1083
- if (!Array.isArray(vector)) return null;
1084
- return vector.map((n) => {
1085
- const v = Number(n);
1086
- return Number.isFinite(v) ? v : 0;
1087
- });
1088
- } catch (err) {
1089
- log.debug(`EmbedHelper error: ${err}`);
1090
- return null;
1091
- }
1092
- }
1093
- };
1094
-
1095
- // src/conversation-index/faiss-adapter.ts
1096
- import { fileURLToPath } from "url";
1097
- import path4 from "path";
1098
- var FaissAdapterError = class extends Error {
1099
- constructor(message, code) {
1100
- super(message);
1101
- this.code = code;
1102
- this.name = "FaissAdapterError";
1103
- }
1104
- code;
1105
- };
1106
- function parseSidecarManifest(result) {
1107
- const manifest = result.manifest;
1108
- if (!manifest || typeof manifest.version !== "number" || typeof manifest.modelId !== "string" || typeof manifest.normalizedModelId !== "string" || typeof manifest.dimension !== "number" || typeof manifest.chunkCount !== "number" || typeof manifest.updatedAt !== "string" || typeof manifest.lastSuccessfulRebuildAt !== "string") {
1109
- return void 0;
1110
- }
1111
- return {
1112
- version: manifest.version,
1113
- modelId: manifest.modelId,
1114
- normalizedModelId: manifest.normalizedModelId,
1115
- dimension: manifest.dimension,
1116
- chunkCount: manifest.chunkCount,
1117
- updatedAt: manifest.updatedAt,
1118
- lastSuccessfulRebuildAt: manifest.lastSuccessfulRebuildAt
1119
- };
1120
- }
1121
- function resolveDefaultFaissScriptPath(fromModuleUrl = import.meta.url) {
1122
- const currentFile = fileURLToPath(fromModuleUrl);
1123
- const moduleDir = path4.dirname(currentFile);
1124
- if (moduleDir.endsWith(`${path4.sep}conversation-index`)) {
1125
- return path4.resolve(moduleDir, "..", "..", "scripts", "faiss_index.py");
1126
- }
1127
- return path4.resolve(moduleDir, "..", "scripts", "faiss_index.py");
1128
- }
1129
- var FaissConversationIndexAdapter = class {
1130
- constructor(config) {
1131
- this.config = config;
1132
- this.pythonBin = config.pythonBin && config.pythonBin.trim().length > 0 ? config.pythonBin.trim() : "python3";
1133
- this.scriptPath = config.scriptPath && config.scriptPath.trim().length > 0 ? config.scriptPath.trim() : resolveDefaultFaissScriptPath();
1134
- this.indexPath = path4.isAbsolute(config.indexDir) ? config.indexDir : path4.join(config.memoryDir, config.indexDir);
1135
- this.spawnFn = config.spawnFn ?? launchProcess;
1136
- }
1137
- config;
1138
- pythonBin;
1139
- scriptPath;
1140
- indexPath;
1141
- spawnFn;
1142
- async upsertChunks(chunks) {
1143
- if (this.config.maxBatchSize <= 0) return 0;
1144
- let totalUpserted = 0;
1145
- for (let offset = 0; offset < chunks.length; offset += this.config.maxBatchSize) {
1146
- const batch = chunks.slice(offset, offset + this.config.maxBatchSize);
1147
- if (batch.length === 0) continue;
1148
- const payload = {
1149
- modelId: this.config.modelId,
1150
- indexPath: this.indexPath,
1151
- chunks: batch.map((chunk) => ({
1152
- id: chunk.id,
1153
- sessionKey: chunk.sessionKey,
1154
- text: chunk.text,
1155
- startTs: chunk.startTs,
1156
- endTs: chunk.endTs
1157
- }))
1158
- };
1159
- const result = await this.runCommand("upsert", payload, this.config.upsertTimeoutMs);
1160
- const upserted = result.upserted;
1161
- if (typeof upserted !== "number" || !Number.isFinite(upserted)) {
1162
- throw new FaissAdapterError("FAISS sidecar produced malformed upsert response", "malformed_output");
1163
- }
1164
- totalUpserted += Math.max(0, Math.floor(upserted));
1165
- }
1166
- return totalUpserted;
1167
- }
1168
- async searchChunks(query, topK) {
1169
- const requestedTopK = Number.isFinite(topK) ? Math.floor(topK) : 0;
1170
- const boundedTopK = this.config.maxSearchK > 0 ? Math.max(0, Math.min(requestedTopK, this.config.maxSearchK)) : 0;
1171
- if (boundedTopK <= 0 || query.trim().length === 0) return [];
1172
- const payload = {
1173
- modelId: this.config.modelId,
1174
- indexPath: this.indexPath,
1175
- query,
1176
- topK: boundedTopK
1177
- };
1178
- const result = await this.runCommand("search", payload, this.config.searchTimeoutMs);
1179
- if (!Array.isArray(result.results)) {
1180
- throw new FaissAdapterError("FAISS sidecar produced malformed search response", "malformed_output");
1181
- }
1182
- const rows = result.results;
1183
- return rows.filter(
1184
- (row) => row && typeof row.path === "string" && typeof row.snippet === "string" && typeof row.score === "number"
1185
- ).map((row) => ({ path: row.path, snippet: row.snippet, score: row.score }));
1186
- }
1187
- async health() {
1188
- const payload = {
1189
- modelId: this.config.modelId,
1190
- indexPath: this.indexPath
1191
- };
1192
- const result = await this.runCommand("health", payload, this.config.healthTimeoutMs);
1193
- if (result.status !== "ok" && result.status !== "degraded" && result.status !== "error") {
1194
- throw new FaissAdapterError("FAISS sidecar produced malformed health response", "malformed_output");
1195
- }
1196
- return {
1197
- ok: result.ok === true,
1198
- status: result.status,
1199
- indexPath: this.indexPath,
1200
- message: typeof result.error === "string" && result.error.length > 0 ? result.error : void 0,
1201
- manifest: parseSidecarManifest(result)
1202
- };
1203
- }
1204
- async inspect() {
1205
- const payload = {
1206
- modelId: this.config.modelId,
1207
- indexPath: this.indexPath
1208
- };
1209
- const result = await this.runCommand("inspect", payload, this.config.healthTimeoutMs);
1210
- if (result.status !== "ok" && result.status !== "degraded" && result.status !== "error") {
1211
- throw new FaissAdapterError("FAISS sidecar produced malformed inspect response", "malformed_output");
1212
- }
1213
- return {
1214
- ok: result.ok === true,
1215
- status: result.status,
1216
- indexPath: this.indexPath,
1217
- message: typeof result.error === "string" && result.error.length > 0 ? result.error : void 0,
1218
- manifest: parseSidecarManifest(result),
1219
- metadata: {
1220
- chunkCount: result.metadata && typeof result.metadata.chunkCount === "number" ? result.metadata.chunkCount : 0,
1221
- hasIndex: result.metadata?.hasIndex === true,
1222
- hasMetadata: result.metadata?.hasMetadata === true,
1223
- hasManifest: result.metadata?.hasManifest === true
1224
- }
1225
- };
1226
- }
1227
- async rebuildChunks(chunks) {
1228
- if (this.config.maxBatchSize <= 0) return 0;
1229
- const firstBatch = chunks.slice(0, this.config.maxBatchSize);
1230
- const rebuildPayload = {
1231
- modelId: this.config.modelId,
1232
- indexPath: this.indexPath,
1233
- chunks: firstBatch.map((chunk) => ({
1234
- id: chunk.id,
1235
- sessionKey: chunk.sessionKey,
1236
- text: chunk.text,
1237
- startTs: chunk.startTs,
1238
- endTs: chunk.endTs
1239
- }))
1240
- };
1241
- const result = await this.runCommand("rebuild", rebuildPayload, this.config.upsertTimeoutMs);
1242
- const rebuilt = result.rebuilt;
1243
- if (typeof rebuilt !== "number" || !Number.isFinite(rebuilt)) {
1244
- throw new FaissAdapterError("FAISS sidecar produced malformed rebuild response", "malformed_output");
1245
- }
1246
- const rebuildCount = Math.max(0, Math.floor(rebuilt));
1247
- const remaining = chunks.slice(firstBatch.length);
1248
- if (remaining.length === 0) return rebuildCount;
1249
- const upserted = await this.upsertChunks(remaining);
1250
- return rebuildCount + upserted;
1251
- }
1252
- async runCommand(command, payload, timeoutMs) {
1253
- const args = [this.scriptPath, command];
1254
- const child = this.spawnFn(this.pythonBin, args, {
1255
- stdio: ["pipe", "pipe", "pipe"]
1256
- });
1257
- if (!child.stdin || !child.stdout || !child.stderr) {
1258
- throw new FaissAdapterError(
1259
- `FAISS sidecar missing stdio pipes (${command})`,
1260
- "non_zero_exit"
1261
- );
1262
- }
1263
- const stdinPipe = child.stdin;
1264
- const stdoutPipe = child.stdout;
1265
- const stderrPipe = child.stderr;
1266
- const stdoutChunks = [];
1267
- const stderrChunks = [];
1268
- let timedOut = false;
1269
- const timer = timeoutMs > 0 ? setTimeout(() => {
1270
- timedOut = true;
1271
- child.kill("SIGKILL");
1272
- }, timeoutMs) : void 0;
1273
- stdoutPipe.on("data", (chunk) => {
1274
- stdoutChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
1275
- });
1276
- stderrPipe.on("data", (chunk) => {
1277
- stderrChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
1278
- });
1279
- let code;
1280
- try {
1281
- stdinPipe.write(JSON.stringify(payload));
1282
- stdinPipe.end();
1283
- code = await new Promise((resolve, reject) => {
1284
- const rejectAsProcessError = (err) => {
1285
- const msg = err instanceof Error ? err.message : String(err);
1286
- reject(new FaissAdapterError(`FAISS sidecar stream/process error (${command}): ${msg}`, "non_zero_exit"));
1287
- };
1288
- child.once("error", rejectAsProcessError);
1289
- stdinPipe.once("error", rejectAsProcessError);
1290
- child.once("close", (exitCode) => resolve(exitCode));
1291
- });
1292
- } catch (err) {
1293
- if (err instanceof FaissAdapterError) throw err;
1294
- const msg = err instanceof Error ? err.message : String(err);
1295
- throw new FaissAdapterError(`FAISS sidecar stream/process error (${command}): ${msg}`, "non_zero_exit");
1296
- } finally {
1297
- if (timer) clearTimeout(timer);
1298
- }
1299
- const stdout = Buffer.concat(stdoutChunks).toString("utf-8").trim();
1300
- const stderr = Buffer.concat(stderrChunks).toString("utf-8").trim();
1301
- if (timedOut) {
1302
- throw new FaissAdapterError(
1303
- `FAISS sidecar command timed out (${command}, ${timeoutMs}ms)`,
1304
- "timeout"
1305
- );
1306
- }
1307
- if (code !== 0) {
1308
- throw new FaissAdapterError(
1309
- `FAISS sidecar exited non-zero (${command}, code=${code ?? "null"})${stderr ? `: ${stderr}` : ""}`,
1310
- "non_zero_exit"
1311
- );
1312
- }
1313
- if (stdout.length === 0) {
1314
- throw new FaissAdapterError(
1315
- `FAISS sidecar produced empty output (${command})`,
1316
- "malformed_output"
1317
- );
1318
- }
1319
- let parsed;
1320
- try {
1321
- parsed = JSON.parse(stdout);
1322
- } catch {
1323
- throw new FaissAdapterError(
1324
- `FAISS sidecar produced malformed JSON (${command})`,
1325
- "malformed_output"
1326
- );
1327
- }
1328
- if (parsed.ok === false) {
1329
- const message = typeof parsed.error === "string" && parsed.error.length > 0 ? parsed.error : `FAISS sidecar command failed (${command})`;
1330
- throw new FaissAdapterError(message, "non_zero_exit");
1331
- }
1332
- if (parsed.ok !== true) {
1333
- throw new FaissAdapterError(
1334
- `FAISS sidecar produced malformed success envelope (${command})`,
1335
- "malformed_output"
1336
- );
1337
- }
1338
- return parsed;
1339
- }
1340
- };
1341
- async function failOpenFaissHealth(adapter) {
1342
- if (!adapter) {
1343
- return { ok: false, status: "error", indexPath: "", message: "adapter-unavailable" };
1344
- }
1345
- try {
1346
- return await adapter.health();
1347
- } catch (err) {
1348
- log.debug(`faiss adapter health failed (fail-open): ${err}`);
1349
- return { ok: false, status: "error", indexPath: "", message: "adapter-error" };
1350
- }
1351
- }
1352
-
1353
- // src/conversation-index/search.ts
1354
- async function searchConversationIndex(qmd, query, maxResults) {
1355
- try {
1356
- const results = await qmd.search(query, void 0, maxResults);
1357
- return results.map((r) => ({ path: r.path, snippet: r.snippet, score: r.score }));
1358
- } catch (err) {
1359
- log.debug(`conversation index search failed: ${err}`);
1360
- return [];
1361
- }
1362
- }
1363
- async function searchConversationIndexFaissFailOpen(adapter, query, maxResults) {
1364
- if (!adapter) return [];
1365
- try {
1366
- return await adapter.searchChunks(query, maxResults);
1367
- } catch (err) {
1368
- log.debug(`conversation index FAISS search failed (fail-open): ${err}`);
1369
- return [];
1370
- }
1371
- }
1372
-
1373
- // src/conversation-index/backend.ts
1374
- function createConversationIndexBackend(options) {
1375
- if (!options.enabled) return void 0;
1376
- const getQmd = options.getQmd ?? (() => options.qmd);
1377
- const getFaiss = options.getFaiss ?? (() => options.faiss);
1378
- if (options.backend === "faiss") {
1379
- return createFaissBackend(getFaiss);
1380
- }
1381
- return createQmdBackend(getQmd, options.collectionDir);
1382
- }
1383
- function createQmdBackend(getQmd, collectionDir) {
1384
- return {
1385
- kind: "qmd",
1386
- async initialize() {
1387
- const qmd = getQmd();
1388
- if (!qmd) {
1389
- return {
1390
- enabled: true,
1391
- logLevel: "warn",
1392
- message: "Conversation index QMD: not available search backend disabled or unsupported"
1393
- };
1394
- }
1395
- const available = await qmd.probe();
1396
- if (!available) {
1397
- return {
1398
- enabled: true,
1399
- logLevel: "warn",
1400
- message: `Conversation index QMD: not available ${qmd.debugStatus()}`
1401
- };
1402
- }
1403
- const collectionState = await qmd.ensureCollection(collectionDir);
1404
- if (collectionState === "missing") {
1405
- return {
1406
- enabled: false,
1407
- logLevel: "warn",
1408
- message: "Conversation index collection missing; disabling conversation semantic recall for this runtime"
1409
- };
1410
- }
1411
- if (collectionState === "unknown") {
1412
- return {
1413
- enabled: true,
1414
- logLevel: "warn",
1415
- message: "Conversation index collection check unavailable; keeping conversation semantic recall enabled for fail-open behavior"
1416
- };
1417
- }
1418
- if (collectionState === "skipped") {
1419
- return {
1420
- enabled: true,
1421
- logLevel: "debug",
1422
- message: "Conversation index collection check skipped in daemon-only mode"
1423
- };
1424
- }
1425
- return {
1426
- enabled: true,
1427
- logLevel: "info",
1428
- message: `Conversation index QMD: available ${qmd.debugStatus()}`
1429
- };
1430
- },
1431
- async search(query, maxResults) {
1432
- const qmd = getQmd();
1433
- if (!qmd || !qmd.isAvailable()) return [];
1434
- return searchConversationIndex(qmd, query, maxResults);
1435
- },
1436
- async update(_chunks, options) {
1437
- const qmd = getQmd();
1438
- if (!qmd || !qmd.isAvailable()) return { embedded: false };
1439
- await qmd.update();
1440
- if (options.embed) {
1441
- await qmd.embed();
1442
- return { embedded: true };
1443
- }
1444
- return { embedded: false };
1445
- },
1446
- async rebuild(_chunks, options) {
1447
- const qmd = getQmd();
1448
- if (!qmd || !qmd.isAvailable()) return { embedded: false, rebuilt: false };
1449
- await qmd.update();
1450
- if (options.embed) {
1451
- await qmd.embed();
1452
- return { embedded: true, rebuilt: true };
1453
- }
1454
- return { embedded: false, rebuilt: true };
1455
- },
1456
- async health() {
1457
- const qmd = getQmd();
1458
- let qmdAvailable = !!qmd?.isAvailable();
1459
- if (!qmdAvailable && qmd) {
1460
- try {
1461
- qmdAvailable = await qmd.probe();
1462
- } catch {
1463
- qmdAvailable = false;
1464
- }
1465
- }
1466
- return {
1467
- backend: "qmd",
1468
- status: qmdAvailable ? "ok" : "degraded",
1469
- qmdAvailable
1470
- };
1471
- },
1472
- async inspect() {
1473
- const qmd = getQmd();
1474
- let qmdAvailable = !!qmd?.isAvailable();
1475
- if (!qmdAvailable && qmd) {
1476
- try {
1477
- qmdAvailable = await qmd.probe();
1478
- } catch {
1479
- qmdAvailable = false;
1480
- }
1481
- }
1482
- return {
1483
- backend: "qmd",
1484
- status: qmdAvailable ? "ok" : "degraded",
1485
- available: qmdAvailable,
1486
- indexPath: collectionDir,
1487
- supportsIncrementalUpdate: true,
1488
- message: qmd ? void 0 : "Conversation index QMD runtime unavailable",
1489
- metadata: {
1490
- chunkCount: null,
1491
- qmdAvailable,
1492
- debugStatus: qmd?.debugStatus()
1493
- }
1494
- };
1495
- }
1496
- };
1497
- }
1498
- function createFaissBackend(getFaiss) {
1499
- return {
1500
- kind: "faiss",
1501
- async initialize() {
1502
- const health = await failOpenFaissHealth(getFaiss());
1503
- return health.status === "ok" ? {
1504
- enabled: true,
1505
- logLevel: "info",
1506
- message: `Conversation index FAISS: available (status=${health.status})`
1507
- } : {
1508
- enabled: true,
1509
- logLevel: "warn",
1510
- message: `Conversation index FAISS: degraded (${health.message ?? health.status})`
1511
- };
1512
- },
1513
- async search(query, maxResults) {
1514
- return searchConversationIndexFaissFailOpen(getFaiss(), query, maxResults);
1515
- },
1516
- async update(chunks, _options) {
1517
- await upsertConversationChunksFailOpen(getFaiss(), chunks);
1518
- return { embedded: false };
1519
- },
1520
- async rebuild(chunks, _options) {
1521
- const result = await rebuildConversationChunksFailOpen(getFaiss(), chunks);
1522
- return { embedded: false, rebuilt: result.skipped !== true };
1523
- },
1524
- async health() {
1525
- const faiss = await failOpenFaissHealth(getFaiss());
1526
- return {
1527
- backend: "faiss",
1528
- status: faiss.status === "ok" ? "ok" : "degraded",
1529
- message: faiss.message,
1530
- faiss
1531
- };
1532
- },
1533
- async inspect() {
1534
- const adapter = getFaiss();
1535
- if (!adapter) {
1536
- return {
1537
- backend: "faiss",
1538
- status: "degraded",
1539
- available: false,
1540
- indexPath: "",
1541
- supportsIncrementalUpdate: true,
1542
- message: "Conversation index FAISS runtime unavailable",
1543
- metadata: {
1544
- chunkCount: 0,
1545
- hasIndex: false,
1546
- hasMetadata: false,
1547
- hasManifest: false
1548
- }
1549
- };
1550
- }
1551
- try {
1552
- const inspection = await adapter.inspect();
1553
- return {
1554
- backend: "faiss",
1555
- status: inspection.status === "ok" ? "ok" : "degraded",
1556
- available: inspection.status === "ok",
1557
- indexPath: inspection.indexPath,
1558
- supportsIncrementalUpdate: true,
1559
- message: inspection.message,
1560
- metadata: {
1561
- chunkCount: inspection.metadata.chunkCount,
1562
- hasIndex: inspection.metadata.hasIndex,
1563
- hasMetadata: inspection.metadata.hasMetadata,
1564
- hasManifest: inspection.metadata.hasManifest,
1565
- manifest: inspection.manifest
1566
- }
1567
- };
1568
- } catch (err) {
1569
- const fallback = await failOpenFaissHealth(adapter);
1570
- return {
1571
- backend: "faiss",
1572
- status: "degraded",
1573
- available: false,
1574
- indexPath: fallback.indexPath,
1575
- supportsIncrementalUpdate: true,
1576
- message: fallback.message ?? String(err),
1577
- metadata: {
1578
- chunkCount: fallback.manifest?.chunkCount ?? 0,
1579
- hasIndex: false,
1580
- hasMetadata: false,
1581
- hasManifest: !!fallback.manifest,
1582
- manifest: fallback.manifest
1583
- }
1584
- };
1585
- }
1586
- }
1587
- };
1588
- }
1589
-
1590
- // src/search/factory.ts
1591
- function resolveNonQmdBackend(config) {
1592
- const backend = config.searchBackend ?? "qmd";
1593
- const collection = config.qmdCollection;
1594
- if (backend === "noop") {
1595
- return new NoopSearchBackend();
1596
- }
1597
- if (backend === "remote") {
1598
- const baseUrl = config.remoteSearchBaseUrl || "http://localhost:8181";
1599
- if (!config.remoteSearchBaseUrl) {
1600
- log.warn("searchBackend is 'remote' but remoteSearchBaseUrl is not configured; using default http://localhost:8181");
1601
- }
1602
- return new RemoteSearchBackend({
1603
- baseUrl,
1604
- apiKey: config.remoteSearchApiKey,
1605
- timeoutMs: config.remoteSearchTimeoutMs
1606
- });
1607
- }
1608
- if (backend === "lancedb") {
1609
- const embedHelper = new EmbedHelper(config);
1610
- return new LanceDbBackend({
1611
- dbPath: config.lanceDbPath,
1612
- collection,
1613
- embedHelper,
1614
- memoryDir: config.memoryDir,
1615
- embeddingDimension: config.lanceEmbeddingDimension
1616
- });
1617
- }
1618
- if (backend === "meilisearch") {
1619
- return new MeilisearchBackend({
1620
- host: config.meilisearchHost,
1621
- apiKey: config.meilisearchApiKey,
1622
- collection,
1623
- timeoutMs: config.meilisearchTimeoutMs,
1624
- autoIndex: config.meilisearchAutoIndex,
1625
- memoryDir: config.memoryDir
1626
- });
1627
- }
1628
- if (backend === "orama") {
1629
- const embedHelper = new EmbedHelper(config);
1630
- return new OramaBackend({
1631
- dbPath: config.oramaDbPath,
1632
- collection,
1633
- embedHelper,
1634
- memoryDir: config.memoryDir,
1635
- embeddingDimension: config.oramaEmbeddingDimension
1636
- });
1637
- }
1638
- return void 0;
1639
- }
1640
- function qmdOptions(config) {
1641
- return {
1642
- slowLog: {
1643
- enabled: config.slowLogEnabled,
1644
- thresholdMs: config.slowLogThresholdMs
1645
- },
1646
- updateTimeoutMs: config.qmdUpdateTimeoutMs,
1647
- updateMinIntervalMs: config.qmdUpdateMinIntervalMs,
1648
- qmdPath: config.qmdPath,
1649
- daemonUrl: config.qmdDaemonEnabled ? config.qmdDaemonUrl : void 0,
1650
- daemonRecheckIntervalMs: config.qmdDaemonRecheckIntervalMs
1651
- };
1652
- }
1653
- function createSearchBackend(config) {
1654
- const nonQmd = resolveNonQmdBackend(config);
1655
- if (nonQmd) return nonQmd;
1656
- if (!config.qmdEnabled) {
1657
- return new NoopSearchBackend();
1658
- }
1659
- return new QmdClient(config.qmdCollection, config.qmdMaxResults, qmdOptions(config));
1660
- }
1661
- function createConversationSearchBackend(config) {
1662
- if (!config.conversationIndexEnabled || config.conversationIndexBackend !== "qmd") {
1663
- return void 0;
1664
- }
1665
- const backend = config.searchBackend ?? "qmd";
1666
- if (backend === "noop") return void 0;
1667
- if (!config.qmdEnabled) return void 0;
1668
- return new QmdClient(
1669
- config.conversationIndexQmdCollection,
1670
- Math.max(6, config.conversationRecallTopK),
1671
- qmdOptions(config)
1672
- );
1673
- }
1674
- function createConversationIndexRuntime(config, overrides) {
1675
- const qmd = createConversationSearchBackend(config);
1676
- const faiss = config.conversationIndexEnabled && config.conversationIndexBackend === "faiss" ? new FaissConversationIndexAdapter({
1677
- memoryDir: config.memoryDir,
1678
- scriptPath: config.conversationIndexFaissScriptPath,
1679
- pythonBin: config.conversationIndexFaissPythonBin,
1680
- modelId: config.conversationIndexFaissModelId,
1681
- indexDir: config.conversationIndexFaissIndexDir,
1682
- upsertTimeoutMs: config.conversationIndexFaissUpsertTimeoutMs,
1683
- searchTimeoutMs: config.conversationIndexFaissSearchTimeoutMs,
1684
- healthTimeoutMs: config.conversationIndexFaissHealthTimeoutMs,
1685
- maxBatchSize: config.conversationIndexFaissMaxBatchSize,
1686
- maxSearchK: config.conversationIndexFaissMaxSearchK
1687
- }) : void 0;
1688
- const backend = createConversationIndexBackend({
1689
- enabled: config.conversationIndexEnabled,
1690
- backend: config.conversationIndexBackend,
1691
- getQmd: () => overrides?.getQmd?.() ?? qmd,
1692
- getFaiss: () => overrides?.getFaiss?.() ?? faiss,
1693
- collectionDir: path5.join(config.memoryDir, "conversation-index")
1694
- });
1695
- return { qmd, faiss, backend };
1696
- }
1697
-
1698
- // src/namespaces/storage.ts
1699
- import path6 from "path";
1700
- import { access } from "fs/promises";
1701
- async function exists(p) {
1702
- try {
1703
- await access(p);
1704
- return true;
1705
- } catch {
1706
- return false;
1707
- }
1708
- }
1709
- var NamespaceStorageRouter = class {
1710
- constructor(config) {
1711
- this.config = config;
1712
- }
1713
- config;
1714
- cache = /* @__PURE__ */ new Map();
1715
- defaultNsRootResolved = null;
1716
- async defaultNamespaceRoot() {
1717
- if (this.defaultNsRootResolved) return this.defaultNsRootResolved;
1718
- if (!this.config.namespacesEnabled) {
1719
- this.defaultNsRootResolved = this.config.memoryDir;
1720
- return this.defaultNsRootResolved;
1721
- }
1722
- const nsDir = path6.join(this.config.memoryDir, "namespaces", this.config.defaultNamespace);
1723
- this.defaultNsRootResolved = await exists(nsDir) ? nsDir : this.config.memoryDir;
1724
- return this.defaultNsRootResolved;
1725
- }
1726
- namespaceRootSync(namespace) {
1727
- if (!this.config.namespacesEnabled) return this.config.memoryDir;
1728
- if (namespace === this.config.defaultNamespace) {
1729
- return this.defaultNsRootResolved ?? this.config.memoryDir;
1730
- }
1731
- return path6.join(this.config.memoryDir, "namespaces", namespace);
1732
- }
1733
- async storageFor(namespace) {
1734
- const ns = namespace || this.config.defaultNamespace;
1735
- if (ns !== this.config.defaultNamespace && !isSafeRouteNamespace(ns)) {
1736
- throw new Error(`unsafe namespace: ${ns}`);
1737
- }
1738
- if (this.cache.has(ns)) return this.cache.get(ns);
1739
- if (ns === this.config.defaultNamespace) {
1740
- await this.defaultNamespaceRoot();
1741
- }
1742
- const root = this.namespaceRootSync(ns);
1743
- const sm = new StorageManager(root, this.config.entitySchemas);
1744
- sm.citationTemplate = this.config.inlineSourceAttributionFormat;
1745
- this.cache.set(ns, sm);
1746
- return sm;
1747
- }
1748
- };
1749
-
1750
- // src/namespaces/search.ts
1751
- function namespaceCollectionName(baseCollection, namespace, options) {
1752
- const trimmed = namespace.trim();
1753
- const defaultNamespace = options?.defaultNamespace?.trim() || "default";
1754
- if (options?.useLegacyDefaultCollection === true && trimmed === defaultNamespace) {
1755
- return baseCollection;
1756
- }
1757
- const normalized = trimmed.toLowerCase().replace(/[^a-z0-9._-]+/g, "-");
1758
- let start = 0;
1759
- let end = normalized.length;
1760
- while (start < end && normalized[start] === "-") start += 1;
1761
- while (end > start && normalized[end - 1] === "-") end -= 1;
1762
- const token = normalized.slice(start, end) || defaultNamespace;
1763
- return `${baseCollection}--ns--${token}`;
1764
- }
1765
- var NamespaceSearchRouter = class {
1766
- constructor(config, storageRouter, createBackend = createSearchBackend) {
1767
- this.config = config;
1768
- this.storageRouter = storageRouter;
1769
- this.createBackend = createBackend;
1770
- }
1771
- config;
1772
- storageRouter;
1773
- createBackend;
1774
- cache = /* @__PURE__ */ new Map();
1775
- async collectionForNamespace(namespace) {
1776
- return (await this.backendRecordFor(namespace)).collection;
1777
- }
1778
- async searchAcrossNamespaces(options) {
1779
- const query = options.query.trim();
1780
- if (!query) return [];
1781
- const maxResults = Math.max(0, Math.floor(options.maxResults ?? this.config.qmdMaxResults));
1782
- if (maxResults === 0) return [];
1783
- const method = options.mode ?? "search";
1784
- const namespaces = Array.from(new Set(options.namespaces.map((value) => value.trim()).filter(Boolean)));
1785
- if (namespaces.length === 0) return [];
1786
- const resultsByNamespace = await Promise.all(
1787
- namespaces.map(async (namespace) => {
1788
- const record = await this.backendRecordFor(namespace);
1789
- if (!record.available || record.collectionState === "missing") return [];
1790
- switch (method) {
1791
- case "hybrid":
1792
- return await record.backend.hybridSearch(query, void 0, maxResults, options.execution);
1793
- case "bm25":
1794
- return await record.backend.bm25Search(query, void 0, maxResults, options.execution);
1795
- case "vector":
1796
- return await record.backend.vectorSearch(query, void 0, maxResults, options.execution);
1797
- default:
1798
- return await record.backend.search(
1799
- query,
1800
- void 0,
1801
- maxResults,
1802
- options.searchOptions,
1803
- options.execution
1804
- );
1805
- }
1806
- })
1807
- );
1808
- return mergeNamespaceSearchResults(resultsByNamespace, maxResults);
1809
- }
1810
- /**
1811
- * Update all namespace backends.
1812
- * Returns the number of backends for which an update was attempted
1813
- * (i.e., available and collection present). Callers can treat 0 as a
1814
- * signal that no backend was eligible — useful for success-verification in
1815
- * startup-sync when namespacesEnabled is true.
1816
- */
1817
- async updateNamespaces(namespaces, execution) {
1818
- const unique = Array.from(new Set(namespaces.map((value) => value.trim()).filter(Boolean)));
1819
- const eligible = (await Promise.all(
1820
- unique.map(async (namespace) => {
1821
- const record = await this.backendRecordFor(namespace);
1822
- return record.available && record.collectionState !== "missing" ? record : null;
1823
- })
1824
- )).filter((record) => record !== null);
1825
- const globalRecord = eligible.find((record) => record.backend.updatesAllCollections?.() === true);
1826
- const scopedRecords = globalRecord ? eligible.filter((record) => record.backend.updatesAllCollections?.() !== true) : eligible;
1827
- await Promise.all([
1828
- globalRecord ? globalRecord.backend.update(execution) : Promise.resolve(),
1829
- ...scopedRecords.map((record) => record.backend.update(execution))
1830
- ]);
1831
- return (globalRecord ? 1 : 0) + scopedRecords.length;
1832
- }
1833
- async embedNamespaces(namespaces) {
1834
- const unique = Array.from(new Set(namespaces.map((value) => value.trim()).filter(Boolean)));
1835
- await Promise.all(
1836
- unique.map(async (namespace) => {
1837
- const record = await this.backendRecordFor(namespace);
1838
- if (!record.available || record.collectionState === "missing") return;
1839
- await record.backend.embed();
1840
- })
1841
- );
1842
- }
1843
- async ensureNamespaceCollection(namespace) {
1844
- const record = await this.backendRecordFor(namespace);
1845
- return record.collectionState;
1846
- }
1847
- /** Clear cached backend records so the next access re-probes availability. */
1848
- clearCache() {
1849
- this.cache.clear();
1850
- }
1851
- async backendRecordFor(namespace) {
1852
- const key = namespace.trim() || this.config.defaultNamespace;
1853
- const existing = this.cache.get(key);
1854
- if (existing) return await existing;
1855
- const pending = (async () => {
1856
- const storage = await this.storageRouter.storageFor(key);
1857
- const useLegacyDefaultCollection = key === this.config.defaultNamespace && storage.dir === this.config.memoryDir;
1858
- const scopedConfig = {
1859
- ...this.config,
1860
- memoryDir: storage.dir,
1861
- qmdCollection: namespaceCollectionName(this.config.qmdCollection, key, {
1862
- defaultNamespace: this.config.defaultNamespace,
1863
- useLegacyDefaultCollection
1864
- })
1865
- };
1866
- const backend = this.createBackend(scopedConfig);
1867
- const available = await backend.probe().catch(() => false);
1868
- const collectionState = available ? await backend.ensureCollection(storage.dir).catch(() => "unknown") : "unknown";
1869
- return {
1870
- backend,
1871
- collection: scopedConfig.qmdCollection,
1872
- memoryDir: storage.dir,
1873
- available,
1874
- collectionState
1875
- };
1876
- })();
1877
- this.cache.set(key, pending);
1878
- return await pending;
1879
- }
1880
- };
1881
- function mergeNamespaceSearchResults(lists, maxResults) {
1882
- const merged = /* @__PURE__ */ new Map();
1883
- for (const list of lists) {
1884
- for (const result of list) {
1885
- const key = result.path || result.docid;
1886
- const existing = merged.get(key);
1887
- if (!existing) {
1888
- merged.set(key, result);
1889
- continue;
1890
- }
1891
- if (result.score > existing.score) {
1892
- merged.set(key, {
1893
- ...result,
1894
- snippet: existing.snippet || result.snippet || ""
1895
- });
1896
- }
1897
- }
1898
- }
1899
- return [...merged.values()].sort((a, b) => b.score - a.score).slice(0, maxResults);
1900
- }
1901
-
1902
- export {
1903
- NoopSearchBackend,
1904
- LanceDbBackend,
1905
- MeilisearchBackend,
1906
- OramaBackend,
1907
- writeConversationChunks,
1908
- createSearchBackend,
1909
- createConversationIndexRuntime,
1910
- NamespaceStorageRouter,
1911
- namespaceCollectionName,
1912
- NamespaceSearchRouter
1913
- };
1914
- //# sourceMappingURL=chunk-HL5LRPNA.js.map