@psiclawops/hypermem 0.9.1 → 0.9.2

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 (914) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/INSTALL.md +9 -0
  3. package/dist/adaptive-lifecycle.d.ts +81 -0
  4. package/dist/adaptive-lifecycle.d.ts.map +1 -0
  5. package/dist/adaptive-lifecycle.js +190 -0
  6. package/dist/background-indexer.d.ts +161 -0
  7. package/dist/background-indexer.d.ts.map +1 -0
  8. package/dist/background-indexer.js +1263 -0
  9. package/dist/budget-policy.d.ts +22 -0
  10. package/dist/budget-policy.d.ts.map +1 -0
  11. package/dist/budget-policy.js +32 -0
  12. package/dist/cache.d.ts +148 -0
  13. package/dist/cache.d.ts.map +1 -0
  14. package/dist/cache.js +571 -0
  15. package/dist/compaction-fence.d.ts +97 -0
  16. package/dist/compaction-fence.d.ts.map +1 -0
  17. package/dist/compaction-fence.js +174 -0
  18. package/dist/composition-snapshot-integrity.d.ts +36 -0
  19. package/dist/composition-snapshot-integrity.d.ts.map +1 -0
  20. package/dist/composition-snapshot-integrity.js +131 -0
  21. package/dist/composition-snapshot-runtime.d.ts +59 -0
  22. package/dist/composition-snapshot-runtime.d.ts.map +1 -0
  23. package/dist/composition-snapshot-runtime.js +250 -0
  24. package/dist/composition-snapshot-store.d.ts +44 -0
  25. package/dist/composition-snapshot-store.d.ts.map +1 -0
  26. package/dist/composition-snapshot-store.js +117 -0
  27. package/dist/compositor.d.ts +518 -0
  28. package/dist/compositor.d.ts.map +1 -0
  29. package/dist/compositor.js +4280 -0
  30. package/dist/content-type-classifier.d.ts +41 -0
  31. package/dist/content-type-classifier.d.ts.map +1 -0
  32. package/dist/content-type-classifier.js +181 -0
  33. package/dist/context-backfill.d.ts +46 -0
  34. package/dist/context-backfill.d.ts.map +1 -0
  35. package/dist/context-backfill.js +113 -0
  36. package/dist/context-store.d.ts +131 -0
  37. package/dist/context-store.d.ts.map +1 -0
  38. package/dist/context-store.js +279 -0
  39. package/dist/contradiction-audit-store.d.ts +54 -0
  40. package/dist/contradiction-audit-store.d.ts.map +1 -0
  41. package/dist/contradiction-audit-store.js +88 -0
  42. package/dist/contradiction-detector.d.ts +78 -0
  43. package/dist/contradiction-detector.d.ts.map +1 -0
  44. package/dist/contradiction-detector.js +362 -0
  45. package/dist/contradiction-resolution-policy.d.ts +21 -0
  46. package/dist/contradiction-resolution-policy.d.ts.map +1 -0
  47. package/dist/contradiction-resolution-policy.js +17 -0
  48. package/dist/cross-agent.d.ts +74 -0
  49. package/dist/cross-agent.d.ts.map +1 -0
  50. package/dist/cross-agent.js +271 -0
  51. package/dist/db.d.ts +131 -0
  52. package/dist/db.d.ts.map +1 -0
  53. package/dist/db.js +410 -0
  54. package/dist/degradation.d.ts +102 -0
  55. package/dist/degradation.d.ts.map +1 -0
  56. package/dist/degradation.js +141 -0
  57. package/dist/desired-state-store.d.ts +100 -0
  58. package/dist/desired-state-store.d.ts.map +1 -0
  59. package/dist/desired-state-store.js +222 -0
  60. package/dist/doc-chunk-store.d.ts +159 -0
  61. package/dist/doc-chunk-store.d.ts.map +1 -0
  62. package/dist/doc-chunk-store.js +441 -0
  63. package/dist/doc-chunker.d.ts +99 -0
  64. package/dist/doc-chunker.d.ts.map +1 -0
  65. package/dist/doc-chunker.js +324 -0
  66. package/dist/dreaming-promoter.d.ts +124 -0
  67. package/dist/dreaming-promoter.d.ts.map +1 -0
  68. package/dist/dreaming-promoter.js +447 -0
  69. package/dist/episode-store.d.ts +49 -0
  70. package/dist/episode-store.d.ts.map +1 -0
  71. package/dist/episode-store.js +135 -0
  72. package/dist/expertise-store.d.ts +129 -0
  73. package/dist/expertise-store.d.ts.map +1 -0
  74. package/dist/expertise-store.js +342 -0
  75. package/dist/fact-store.d.ts +90 -0
  76. package/dist/fact-store.d.ts.map +1 -0
  77. package/dist/fact-store.js +283 -0
  78. package/dist/fleet-store.d.ts +144 -0
  79. package/dist/fleet-store.d.ts.map +1 -0
  80. package/dist/fleet-store.js +276 -0
  81. package/dist/fos-mod.d.ts +178 -0
  82. package/dist/fos-mod.d.ts.map +1 -0
  83. package/dist/fos-mod.js +416 -0
  84. package/dist/hybrid-retrieval.d.ts +102 -0
  85. package/dist/hybrid-retrieval.d.ts.map +1 -0
  86. package/dist/hybrid-retrieval.js +429 -0
  87. package/dist/image-eviction.d.ts +49 -0
  88. package/dist/image-eviction.d.ts.map +1 -0
  89. package/dist/image-eviction.js +251 -0
  90. package/dist/index.d.ts +735 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +1542 -0
  93. package/dist/keystone-scorer.d.ts +51 -0
  94. package/dist/keystone-scorer.d.ts.map +1 -0
  95. package/dist/keystone-scorer.js +52 -0
  96. package/dist/knowledge-graph.d.ts +110 -0
  97. package/dist/knowledge-graph.d.ts.map +1 -0
  98. package/dist/knowledge-graph.js +305 -0
  99. package/dist/knowledge-lint.d.ts +31 -0
  100. package/dist/knowledge-lint.d.ts.map +1 -0
  101. package/dist/knowledge-lint.js +155 -0
  102. package/dist/knowledge-store.d.ts +75 -0
  103. package/dist/knowledge-store.d.ts.map +1 -0
  104. package/dist/knowledge-store.js +270 -0
  105. package/dist/library-schema.d.ts +31 -0
  106. package/dist/library-schema.d.ts.map +1 -0
  107. package/dist/library-schema.js +1357 -0
  108. package/dist/message-store.d.ts +181 -0
  109. package/dist/message-store.d.ts.map +1 -0
  110. package/dist/message-store.js +577 -0
  111. package/dist/metrics-dashboard.d.ts +131 -0
  112. package/dist/metrics-dashboard.d.ts.map +1 -0
  113. package/dist/metrics-dashboard.js +298 -0
  114. package/dist/obsidian-exporter.d.ts +57 -0
  115. package/dist/obsidian-exporter.d.ts.map +1 -0
  116. package/dist/obsidian-exporter.js +274 -0
  117. package/dist/obsidian-watcher.d.ts +147 -0
  118. package/dist/obsidian-watcher.d.ts.map +1 -0
  119. package/dist/obsidian-watcher.js +403 -0
  120. package/dist/open-domain.d.ts +46 -0
  121. package/dist/open-domain.d.ts.map +1 -0
  122. package/dist/open-domain.js +125 -0
  123. package/dist/preference-store.d.ts +54 -0
  124. package/dist/preference-store.d.ts.map +1 -0
  125. package/dist/preference-store.js +109 -0
  126. package/dist/preservation-gate.d.ts +82 -0
  127. package/dist/preservation-gate.d.ts.map +1 -0
  128. package/dist/preservation-gate.js +150 -0
  129. package/dist/proactive-pass.d.ts +63 -0
  130. package/dist/proactive-pass.d.ts.map +1 -0
  131. package/dist/proactive-pass.js +293 -0
  132. package/dist/profiles.d.ts +46 -0
  133. package/dist/profiles.d.ts.map +1 -0
  134. package/dist/profiles.js +262 -0
  135. package/dist/provider-translator.d.ts +50 -0
  136. package/dist/provider-translator.d.ts.map +1 -0
  137. package/dist/provider-translator.js +403 -0
  138. package/dist/rate-limiter.d.ts +76 -0
  139. package/dist/rate-limiter.d.ts.map +1 -0
  140. package/dist/rate-limiter.js +179 -0
  141. package/dist/repair-tool-pairs.d.ts +38 -0
  142. package/dist/repair-tool-pairs.d.ts.map +1 -0
  143. package/dist/repair-tool-pairs.js +209 -0
  144. package/dist/replay-recovery.d.ts +29 -0
  145. package/dist/replay-recovery.d.ts.map +1 -0
  146. package/dist/replay-recovery.js +82 -0
  147. package/dist/reranker.d.ts +95 -0
  148. package/dist/reranker.d.ts.map +1 -0
  149. package/dist/reranker.js +308 -0
  150. package/dist/retrieval-policy.d.ts +51 -0
  151. package/dist/retrieval-policy.d.ts.map +1 -0
  152. package/dist/retrieval-policy.js +77 -0
  153. package/dist/schema.d.ts +15 -0
  154. package/dist/schema.d.ts.map +1 -0
  155. package/dist/schema.js +327 -0
  156. package/dist/secret-scanner.d.ts +51 -0
  157. package/dist/secret-scanner.d.ts.map +1 -0
  158. package/dist/secret-scanner.js +248 -0
  159. package/dist/seed.d.ts +108 -0
  160. package/dist/seed.d.ts.map +1 -0
  161. package/dist/seed.js +179 -0
  162. package/dist/session-flusher.d.ts +53 -0
  163. package/dist/session-flusher.d.ts.map +1 -0
  164. package/dist/session-flusher.js +69 -0
  165. package/dist/session-topic-map.d.ts +41 -0
  166. package/dist/session-topic-map.d.ts.map +1 -0
  167. package/dist/session-topic-map.js +77 -0
  168. package/dist/spawn-context.d.ts +54 -0
  169. package/dist/spawn-context.d.ts.map +1 -0
  170. package/dist/spawn-context.js +159 -0
  171. package/dist/system-store.d.ts +73 -0
  172. package/dist/system-store.d.ts.map +1 -0
  173. package/dist/system-store.js +182 -0
  174. package/dist/temporal-store.d.ts +81 -0
  175. package/dist/temporal-store.d.ts.map +1 -0
  176. package/dist/temporal-store.js +149 -0
  177. package/dist/tool-artifact-store.d.ts +98 -0
  178. package/dist/tool-artifact-store.d.ts.map +1 -0
  179. package/dist/tool-artifact-store.js +244 -0
  180. package/dist/topic-detector.d.ts +35 -0
  181. package/dist/topic-detector.d.ts.map +1 -0
  182. package/dist/topic-detector.js +249 -0
  183. package/dist/topic-store.d.ts +51 -0
  184. package/dist/topic-store.d.ts.map +1 -0
  185. package/dist/topic-store.js +175 -0
  186. package/dist/topic-synthesizer.d.ts +71 -0
  187. package/dist/topic-synthesizer.d.ts.map +1 -0
  188. package/dist/topic-synthesizer.js +426 -0
  189. package/dist/trigger-registry.d.ts +63 -0
  190. package/dist/trigger-registry.d.ts.map +1 -0
  191. package/dist/trigger-registry.js +171 -0
  192. package/dist/types.d.ts +1085 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +9 -0
  195. package/dist/vector-store.d.ts +180 -0
  196. package/dist/vector-store.d.ts.map +1 -0
  197. package/dist/vector-store.js +1041 -0
  198. package/dist/version.d.ts +34 -0
  199. package/dist/version.d.ts.map +1 -0
  200. package/dist/version.js +44 -0
  201. package/dist/wiki-page-emitter.d.ts +65 -0
  202. package/dist/wiki-page-emitter.d.ts.map +1 -0
  203. package/dist/wiki-page-emitter.js +258 -0
  204. package/dist/work-store.d.ts +112 -0
  205. package/dist/work-store.d.ts.map +1 -0
  206. package/dist/work-store.js +273 -0
  207. package/docs/MEMORY_MD_AUTHORING.md +3 -3
  208. package/docs/ROADMAP.md +2 -2
  209. package/install.sh +34 -0
  210. package/memory-plugin/package.json +5 -3
  211. package/node_modules/sqlite-vec/README.md +1 -0
  212. package/node_modules/sqlite-vec/index.cjs +46 -0
  213. package/node_modules/sqlite-vec/index.d.ts +17 -0
  214. package/node_modules/sqlite-vec/index.mjs +47 -0
  215. package/node_modules/sqlite-vec/package.json +1 -0
  216. package/node_modules/sqlite-vec-linux-x64/README.md +1 -0
  217. package/node_modules/sqlite-vec-linux-x64/package.json +1 -0
  218. package/node_modules/sqlite-vec-linux-x64/vec0.so +0 -0
  219. package/node_modules/zod/LICENSE +21 -0
  220. package/node_modules/zod/README.md +208 -0
  221. package/node_modules/zod/index.cjs +33 -0
  222. package/node_modules/zod/index.d.cts +4 -0
  223. package/node_modules/zod/index.d.ts +4 -0
  224. package/node_modules/zod/index.js +4 -0
  225. package/node_modules/zod/locales/index.cjs +17 -0
  226. package/node_modules/zod/locales/index.d.cts +1 -0
  227. package/node_modules/zod/locales/index.d.ts +1 -0
  228. package/node_modules/zod/locales/index.js +1 -0
  229. package/node_modules/zod/locales/package.json +6 -0
  230. package/node_modules/zod/mini/index.cjs +32 -0
  231. package/node_modules/zod/mini/index.d.cts +3 -0
  232. package/node_modules/zod/mini/index.d.ts +3 -0
  233. package/node_modules/zod/mini/index.js +3 -0
  234. package/node_modules/zod/mini/package.json +6 -0
  235. package/node_modules/zod/package.json +135 -0
  236. package/node_modules/zod/src/index.ts +4 -0
  237. package/node_modules/zod/src/locales/index.ts +1 -0
  238. package/node_modules/zod/src/mini/index.ts +3 -0
  239. package/node_modules/zod/src/v3/ZodError.ts +330 -0
  240. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  241. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  242. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  243. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  244. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  245. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  246. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  247. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  248. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  249. package/node_modules/zod/src/v3/errors.ts +13 -0
  250. package/node_modules/zod/src/v3/external.ts +6 -0
  251. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  252. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  253. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  254. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  255. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  256. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  257. package/node_modules/zod/src/v3/index.ts +4 -0
  258. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  259. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  260. package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
  261. package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
  262. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
  263. package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
  264. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
  265. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
  266. package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
  267. package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
  268. package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
  269. package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
  270. package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
  271. package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
  272. package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
  273. package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
  274. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
  275. package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
  276. package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
  277. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  278. package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
  279. package/node_modules/zod/src/v3/tests/error.test.ts +551 -0
  280. package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
  281. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  282. package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
  283. package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
  284. package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
  285. package/node_modules/zod/src/v3/tests/intersection.test.ts +110 -0
  286. package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
  287. package/node_modules/zod/src/v3/tests/language-server.test.ts +207 -0
  288. package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
  289. package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
  290. package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
  291. package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
  292. package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
  293. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  294. package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
  295. package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
  296. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  297. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  298. package/node_modules/zod/src/v3/tests/object.test.ts +434 -0
  299. package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
  300. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
  301. package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
  302. package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
  303. package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
  304. package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
  305. package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
  306. package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
  307. package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
  308. package/node_modules/zod/src/v3/tests/readonly.test.ts +194 -0
  309. package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
  310. package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
  311. package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
  312. package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
  313. package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
  314. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
  315. package/node_modules/zod/src/v3/tests/string.test.ts +916 -0
  316. package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
  317. package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
  318. package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
  319. package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
  320. package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
  321. package/node_modules/zod/src/v3/types.ts +5138 -0
  322. package/node_modules/zod/src/v4/classic/checks.ts +32 -0
  323. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  324. package/node_modules/zod/src/v4/classic/compat.ts +70 -0
  325. package/node_modules/zod/src/v4/classic/errors.ts +82 -0
  326. package/node_modules/zod/src/v4/classic/external.ts +51 -0
  327. package/node_modules/zod/src/v4/classic/from-json-schema.ts +643 -0
  328. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  329. package/node_modules/zod/src/v4/classic/iso.ts +90 -0
  330. package/node_modules/zod/src/v4/classic/parse.ts +82 -0
  331. package/node_modules/zod/src/v4/classic/schemas.ts +2409 -0
  332. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  333. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +59 -0
  334. package/node_modules/zod/src/v4/classic/tests/array.test.ts +264 -0
  335. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +210 -0
  336. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  337. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  338. package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  339. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +54 -0
  340. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +106 -0
  341. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +276 -0
  342. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  343. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +573 -0
  344. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +562 -0
  345. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  346. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
  347. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  348. package/node_modules/zod/src/v4/classic/tests/date.test.ts +62 -0
  349. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +302 -0
  350. package/node_modules/zod/src/v4/classic/tests/default.test.ts +365 -0
  351. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  352. package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  353. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +661 -0
  354. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +285 -0
  355. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +595 -0
  356. package/node_modules/zod/src/v4/classic/tests/error.test.ts +711 -0
  357. package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
  358. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
  359. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  360. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +734 -0
  361. package/node_modules/zod/src/v4/classic/tests/function.test.ts +360 -0
  362. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  363. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +68 -0
  364. package/node_modules/zod/src/v4/classic/tests/index.test.ts +939 -0
  365. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +60 -0
  366. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +198 -0
  367. package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
  368. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +227 -0
  369. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +117 -0
  370. package/node_modules/zod/src/v4/classic/tests/map.test.ts +330 -0
  371. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  372. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  373. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
  374. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  375. package/node_modules/zod/src/v4/classic/tests/number.test.ts +270 -0
  376. package/node_modules/zod/src/v4/classic/tests/object.test.ts +640 -0
  377. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +223 -0
  378. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +427 -0
  379. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +211 -0
  380. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
  381. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +74 -0
  382. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +282 -0
  383. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  384. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  385. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  386. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +252 -0
  387. package/node_modules/zod/src/v4/classic/tests/record.test.ts +632 -0
  388. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +582 -0
  389. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +570 -0
  390. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +243 -0
  391. package/node_modules/zod/src/v4/classic/tests/set.test.ts +181 -0
  392. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +134 -0
  393. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
  394. package/node_modules/zod/src/v4/classic/tests/string.test.ts +1175 -0
  395. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +106 -0
  396. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +771 -0
  397. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  398. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +2990 -0
  399. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +361 -0
  400. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +183 -0
  401. package/node_modules/zod/src/v4/classic/tests/union.test.ts +219 -0
  402. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  403. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
  404. package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
  405. package/node_modules/zod/src/v4/core/api.ts +1798 -0
  406. package/node_modules/zod/src/v4/core/checks.ts +1293 -0
  407. package/node_modules/zod/src/v4/core/config.ts +15 -0
  408. package/node_modules/zod/src/v4/core/core.ts +138 -0
  409. package/node_modules/zod/src/v4/core/doc.ts +44 -0
  410. package/node_modules/zod/src/v4/core/errors.ts +448 -0
  411. package/node_modules/zod/src/v4/core/index.ts +16 -0
  412. package/node_modules/zod/src/v4/core/json-schema-generator.ts +126 -0
  413. package/node_modules/zod/src/v4/core/json-schema-processors.ts +667 -0
  414. package/node_modules/zod/src/v4/core/json-schema.ts +147 -0
  415. package/node_modules/zod/src/v4/core/parse.ts +195 -0
  416. package/node_modules/zod/src/v4/core/regexes.ts +183 -0
  417. package/node_modules/zod/src/v4/core/registries.ts +105 -0
  418. package/node_modules/zod/src/v4/core/schemas.ts +4538 -0
  419. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  420. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  421. package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
  422. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  423. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  424. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +181 -0
  425. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  426. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  427. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  428. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  429. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +83 -0
  430. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +67 -0
  431. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  432. package/node_modules/zod/src/v4/core/to-json-schema.ts +613 -0
  433. package/node_modules/zod/src/v4/core/util.ts +966 -0
  434. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  435. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  436. package/node_modules/zod/src/v4/index.ts +4 -0
  437. package/node_modules/zod/src/v4/locales/ar.ts +115 -0
  438. package/node_modules/zod/src/v4/locales/az.ts +111 -0
  439. package/node_modules/zod/src/v4/locales/be.ts +176 -0
  440. package/node_modules/zod/src/v4/locales/bg.ts +128 -0
  441. package/node_modules/zod/src/v4/locales/ca.ts +116 -0
  442. package/node_modules/zod/src/v4/locales/cs.ts +118 -0
  443. package/node_modules/zod/src/v4/locales/da.ts +123 -0
  444. package/node_modules/zod/src/v4/locales/de.ts +116 -0
  445. package/node_modules/zod/src/v4/locales/en.ts +119 -0
  446. package/node_modules/zod/src/v4/locales/eo.ts +118 -0
  447. package/node_modules/zod/src/v4/locales/es.ts +141 -0
  448. package/node_modules/zod/src/v4/locales/fa.ts +126 -0
  449. package/node_modules/zod/src/v4/locales/fi.ts +121 -0
  450. package/node_modules/zod/src/v4/locales/fr-CA.ts +116 -0
  451. package/node_modules/zod/src/v4/locales/fr.ts +116 -0
  452. package/node_modules/zod/src/v4/locales/he.ts +246 -0
  453. package/node_modules/zod/src/v4/locales/hu.ts +117 -0
  454. package/node_modules/zod/src/v4/locales/hy.ts +164 -0
  455. package/node_modules/zod/src/v4/locales/id.ts +115 -0
  456. package/node_modules/zod/src/v4/locales/index.ts +49 -0
  457. package/node_modules/zod/src/v4/locales/is.ts +119 -0
  458. package/node_modules/zod/src/v4/locales/it.ts +116 -0
  459. package/node_modules/zod/src/v4/locales/ja.ts +114 -0
  460. package/node_modules/zod/src/v4/locales/ka.ts +123 -0
  461. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  462. package/node_modules/zod/src/v4/locales/km.ts +119 -0
  463. package/node_modules/zod/src/v4/locales/ko.ts +121 -0
  464. package/node_modules/zod/src/v4/locales/lt.ts +239 -0
  465. package/node_modules/zod/src/v4/locales/mk.ts +118 -0
  466. package/node_modules/zod/src/v4/locales/ms.ts +115 -0
  467. package/node_modules/zod/src/v4/locales/nl.ts +121 -0
  468. package/node_modules/zod/src/v4/locales/no.ts +116 -0
  469. package/node_modules/zod/src/v4/locales/ota.ts +117 -0
  470. package/node_modules/zod/src/v4/locales/pl.ts +118 -0
  471. package/node_modules/zod/src/v4/locales/ps.ts +126 -0
  472. package/node_modules/zod/src/v4/locales/pt.ts +116 -0
  473. package/node_modules/zod/src/v4/locales/ru.ts +176 -0
  474. package/node_modules/zod/src/v4/locales/sl.ts +118 -0
  475. package/node_modules/zod/src/v4/locales/sv.ts +119 -0
  476. package/node_modules/zod/src/v4/locales/ta.ts +118 -0
  477. package/node_modules/zod/src/v4/locales/th.ts +119 -0
  478. package/node_modules/zod/src/v4/locales/tr.ts +111 -0
  479. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  480. package/node_modules/zod/src/v4/locales/uk.ts +117 -0
  481. package/node_modules/zod/src/v4/locales/ur.ts +119 -0
  482. package/node_modules/zod/src/v4/locales/uz.ts +116 -0
  483. package/node_modules/zod/src/v4/locales/vi.ts +117 -0
  484. package/node_modules/zod/src/v4/locales/yo.ts +124 -0
  485. package/node_modules/zod/src/v4/locales/zh-CN.ts +116 -0
  486. package/node_modules/zod/src/v4/locales/zh-TW.ts +115 -0
  487. package/node_modules/zod/src/v4/mini/checks.ts +32 -0
  488. package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
  489. package/node_modules/zod/src/v4/mini/external.ts +40 -0
  490. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  491. package/node_modules/zod/src/v4/mini/iso.ts +66 -0
  492. package/node_modules/zod/src/v4/mini/parse.ts +14 -0
  493. package/node_modules/zod/src/v4/mini/schemas.ts +1916 -0
  494. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +24 -0
  495. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +129 -0
  496. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +94 -0
  497. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +144 -0
  498. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +529 -0
  499. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +36 -0
  500. package/node_modules/zod/src/v4/mini/tests/error.test.ts +22 -0
  501. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +5 -0
  502. package/node_modules/zod/src/v4/mini/tests/index.test.ts +963 -0
  503. package/node_modules/zod/src/v4/mini/tests/number.test.ts +95 -0
  504. package/node_modules/zod/src/v4/mini/tests/object.test.ts +227 -0
  505. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  506. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +275 -0
  507. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
  508. package/node_modules/zod/src/v4/mini/tests/string.test.ts +347 -0
  509. package/node_modules/zod/src/v4-mini/index.ts +3 -0
  510. package/node_modules/zod/v3/ZodError.cjs +138 -0
  511. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  512. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  513. package/node_modules/zod/v3/ZodError.js +133 -0
  514. package/node_modules/zod/v3/errors.cjs +17 -0
  515. package/node_modules/zod/v3/errors.d.cts +5 -0
  516. package/node_modules/zod/v3/errors.d.ts +5 -0
  517. package/node_modules/zod/v3/errors.js +9 -0
  518. package/node_modules/zod/v3/external.cjs +22 -0
  519. package/node_modules/zod/v3/external.d.cts +6 -0
  520. package/node_modules/zod/v3/external.d.ts +6 -0
  521. package/node_modules/zod/v3/external.js +6 -0
  522. package/node_modules/zod/v3/helpers/enumUtil.cjs +2 -0
  523. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  524. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  525. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  526. package/node_modules/zod/v3/helpers/errorUtil.cjs +9 -0
  527. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  528. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  529. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  530. package/node_modules/zod/v3/helpers/parseUtil.cjs +124 -0
  531. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  532. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  533. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  534. package/node_modules/zod/v3/helpers/partialUtil.cjs +2 -0
  535. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  536. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  537. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  538. package/node_modules/zod/v3/helpers/typeAliases.cjs +2 -0
  539. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  540. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  541. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  542. package/node_modules/zod/v3/helpers/util.cjs +137 -0
  543. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  544. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  545. package/node_modules/zod/v3/helpers/util.js +133 -0
  546. package/node_modules/zod/v3/index.cjs +33 -0
  547. package/node_modules/zod/v3/index.d.cts +4 -0
  548. package/node_modules/zod/v3/index.d.ts +4 -0
  549. package/node_modules/zod/v3/index.js +4 -0
  550. package/node_modules/zod/v3/locales/en.cjs +112 -0
  551. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  552. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  553. package/node_modules/zod/v3/locales/en.js +109 -0
  554. package/node_modules/zod/v3/package.json +6 -0
  555. package/node_modules/zod/v3/standard-schema.cjs +2 -0
  556. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  557. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  558. package/node_modules/zod/v3/standard-schema.js +1 -0
  559. package/node_modules/zod/v3/types.cjs +3777 -0
  560. package/node_modules/zod/v3/types.d.cts +1034 -0
  561. package/node_modules/zod/v3/types.d.ts +1034 -0
  562. package/node_modules/zod/v3/types.js +3695 -0
  563. package/node_modules/zod/v4/classic/checks.cjs +33 -0
  564. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  565. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  566. package/node_modules/zod/v4/classic/checks.js +1 -0
  567. package/node_modules/zod/v4/classic/coerce.cjs +47 -0
  568. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  569. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  570. package/node_modules/zod/v4/classic/coerce.js +17 -0
  571. package/node_modules/zod/v4/classic/compat.cjs +61 -0
  572. package/node_modules/zod/v4/classic/compat.d.cts +50 -0
  573. package/node_modules/zod/v4/classic/compat.d.ts +50 -0
  574. package/node_modules/zod/v4/classic/compat.js +31 -0
  575. package/node_modules/zod/v4/classic/errors.cjs +74 -0
  576. package/node_modules/zod/v4/classic/errors.d.cts +30 -0
  577. package/node_modules/zod/v4/classic/errors.d.ts +30 -0
  578. package/node_modules/zod/v4/classic/errors.js +48 -0
  579. package/node_modules/zod/v4/classic/external.cjs +73 -0
  580. package/node_modules/zod/v4/classic/external.d.cts +15 -0
  581. package/node_modules/zod/v4/classic/external.d.ts +15 -0
  582. package/node_modules/zod/v4/classic/external.js +20 -0
  583. package/node_modules/zod/v4/classic/from-json-schema.cjs +610 -0
  584. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  585. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  586. package/node_modules/zod/v4/classic/from-json-schema.js +584 -0
  587. package/node_modules/zod/v4/classic/index.cjs +33 -0
  588. package/node_modules/zod/v4/classic/index.d.cts +4 -0
  589. package/node_modules/zod/v4/classic/index.d.ts +4 -0
  590. package/node_modules/zod/v4/classic/index.js +4 -0
  591. package/node_modules/zod/v4/classic/iso.cjs +60 -0
  592. package/node_modules/zod/v4/classic/iso.d.cts +22 -0
  593. package/node_modules/zod/v4/classic/iso.d.ts +22 -0
  594. package/node_modules/zod/v4/classic/iso.js +30 -0
  595. package/node_modules/zod/v4/classic/package.json +6 -0
  596. package/node_modules/zod/v4/classic/parse.cjs +41 -0
  597. package/node_modules/zod/v4/classic/parse.d.cts +31 -0
  598. package/node_modules/zod/v4/classic/parse.d.ts +31 -0
  599. package/node_modules/zod/v4/classic/parse.js +15 -0
  600. package/node_modules/zod/v4/classic/schemas.cjs +1272 -0
  601. package/node_modules/zod/v4/classic/schemas.d.cts +739 -0
  602. package/node_modules/zod/v4/classic/schemas.d.ts +739 -0
  603. package/node_modules/zod/v4/classic/schemas.js +1157 -0
  604. package/node_modules/zod/v4/core/api.cjs +1222 -0
  605. package/node_modules/zod/v4/core/api.d.cts +304 -0
  606. package/node_modules/zod/v4/core/api.d.ts +304 -0
  607. package/node_modules/zod/v4/core/api.js +1082 -0
  608. package/node_modules/zod/v4/core/checks.cjs +601 -0
  609. package/node_modules/zod/v4/core/checks.d.cts +278 -0
  610. package/node_modules/zod/v4/core/checks.d.ts +278 -0
  611. package/node_modules/zod/v4/core/checks.js +575 -0
  612. package/node_modules/zod/v4/core/core.cjs +83 -0
  613. package/node_modules/zod/v4/core/core.d.cts +70 -0
  614. package/node_modules/zod/v4/core/core.d.ts +70 -0
  615. package/node_modules/zod/v4/core/core.js +76 -0
  616. package/node_modules/zod/v4/core/doc.cjs +39 -0
  617. package/node_modules/zod/v4/core/doc.d.cts +14 -0
  618. package/node_modules/zod/v4/core/doc.d.ts +14 -0
  619. package/node_modules/zod/v4/core/doc.js +35 -0
  620. package/node_modules/zod/v4/core/errors.cjs +213 -0
  621. package/node_modules/zod/v4/core/errors.d.cts +220 -0
  622. package/node_modules/zod/v4/core/errors.d.ts +220 -0
  623. package/node_modules/zod/v4/core/errors.js +182 -0
  624. package/node_modules/zod/v4/core/index.cjs +47 -0
  625. package/node_modules/zod/v4/core/index.d.cts +16 -0
  626. package/node_modules/zod/v4/core/index.d.ts +16 -0
  627. package/node_modules/zod/v4/core/index.js +16 -0
  628. package/node_modules/zod/v4/core/json-schema-generator.cjs +99 -0
  629. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  630. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  631. package/node_modules/zod/v4/core/json-schema-generator.js +95 -0
  632. package/node_modules/zod/v4/core/json-schema-processors.cjs +648 -0
  633. package/node_modules/zod/v4/core/json-schema-processors.d.cts +49 -0
  634. package/node_modules/zod/v4/core/json-schema-processors.d.ts +49 -0
  635. package/node_modules/zod/v4/core/json-schema-processors.js +605 -0
  636. package/node_modules/zod/v4/core/json-schema.cjs +2 -0
  637. package/node_modules/zod/v4/core/json-schema.d.cts +88 -0
  638. package/node_modules/zod/v4/core/json-schema.d.ts +88 -0
  639. package/node_modules/zod/v4/core/json-schema.js +1 -0
  640. package/node_modules/zod/v4/core/package.json +6 -0
  641. package/node_modules/zod/v4/core/parse.cjs +131 -0
  642. package/node_modules/zod/v4/core/parse.d.cts +49 -0
  643. package/node_modules/zod/v4/core/parse.d.ts +49 -0
  644. package/node_modules/zod/v4/core/parse.js +93 -0
  645. package/node_modules/zod/v4/core/regexes.cjs +166 -0
  646. package/node_modules/zod/v4/core/regexes.d.cts +79 -0
  647. package/node_modules/zod/v4/core/regexes.d.ts +79 -0
  648. package/node_modules/zod/v4/core/regexes.js +133 -0
  649. package/node_modules/zod/v4/core/registries.cjs +56 -0
  650. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  651. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  652. package/node_modules/zod/v4/core/registries.js +51 -0
  653. package/node_modules/zod/v4/core/schemas.cjs +2124 -0
  654. package/node_modules/zod/v4/core/schemas.d.cts +1146 -0
  655. package/node_modules/zod/v4/core/schemas.d.ts +1146 -0
  656. package/node_modules/zod/v4/core/schemas.js +2093 -0
  657. package/node_modules/zod/v4/core/standard-schema.cjs +2 -0
  658. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  659. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  660. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  661. package/node_modules/zod/v4/core/to-json-schema.cjs +446 -0
  662. package/node_modules/zod/v4/core/to-json-schema.d.cts +114 -0
  663. package/node_modules/zod/v4/core/to-json-schema.d.ts +114 -0
  664. package/node_modules/zod/v4/core/to-json-schema.js +437 -0
  665. package/node_modules/zod/v4/core/util.cjs +710 -0
  666. package/node_modules/zod/v4/core/util.d.cts +199 -0
  667. package/node_modules/zod/v4/core/util.d.ts +199 -0
  668. package/node_modules/zod/v4/core/util.js +651 -0
  669. package/node_modules/zod/v4/core/versions.cjs +8 -0
  670. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  671. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  672. package/node_modules/zod/v4/core/versions.js +5 -0
  673. package/node_modules/zod/v4/index.cjs +22 -0
  674. package/node_modules/zod/v4/index.d.cts +3 -0
  675. package/node_modules/zod/v4/index.d.ts +3 -0
  676. package/node_modules/zod/v4/index.js +3 -0
  677. package/node_modules/zod/v4/locales/ar.cjs +133 -0
  678. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  679. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  680. package/node_modules/zod/v4/locales/ar.js +106 -0
  681. package/node_modules/zod/v4/locales/az.cjs +132 -0
  682. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  683. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  684. package/node_modules/zod/v4/locales/az.js +105 -0
  685. package/node_modules/zod/v4/locales/be.cjs +183 -0
  686. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  687. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  688. package/node_modules/zod/v4/locales/be.js +156 -0
  689. package/node_modules/zod/v4/locales/bg.cjs +147 -0
  690. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  691. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  692. package/node_modules/zod/v4/locales/bg.js +120 -0
  693. package/node_modules/zod/v4/locales/ca.cjs +134 -0
  694. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  695. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  696. package/node_modules/zod/v4/locales/ca.js +107 -0
  697. package/node_modules/zod/v4/locales/cs.cjs +138 -0
  698. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  699. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  700. package/node_modules/zod/v4/locales/cs.js +111 -0
  701. package/node_modules/zod/v4/locales/da.cjs +142 -0
  702. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  703. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  704. package/node_modules/zod/v4/locales/da.js +115 -0
  705. package/node_modules/zod/v4/locales/de.cjs +135 -0
  706. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  707. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  708. package/node_modules/zod/v4/locales/de.js +108 -0
  709. package/node_modules/zod/v4/locales/en.cjs +136 -0
  710. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  711. package/node_modules/zod/v4/locales/en.d.ts +4 -0
  712. package/node_modules/zod/v4/locales/en.js +109 -0
  713. package/node_modules/zod/v4/locales/eo.cjs +136 -0
  714. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  715. package/node_modules/zod/v4/locales/eo.d.ts +4 -0
  716. package/node_modules/zod/v4/locales/eo.js +109 -0
  717. package/node_modules/zod/v4/locales/es.cjs +159 -0
  718. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  719. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  720. package/node_modules/zod/v4/locales/es.js +132 -0
  721. package/node_modules/zod/v4/locales/fa.cjs +141 -0
  722. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  723. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  724. package/node_modules/zod/v4/locales/fa.js +114 -0
  725. package/node_modules/zod/v4/locales/fi.cjs +139 -0
  726. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  727. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  728. package/node_modules/zod/v4/locales/fi.js +112 -0
  729. package/node_modules/zod/v4/locales/fr-CA.cjs +134 -0
  730. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  731. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  732. package/node_modules/zod/v4/locales/fr-CA.js +107 -0
  733. package/node_modules/zod/v4/locales/fr.cjs +135 -0
  734. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  735. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  736. package/node_modules/zod/v4/locales/fr.js +108 -0
  737. package/node_modules/zod/v4/locales/he.cjs +241 -0
  738. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  739. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  740. package/node_modules/zod/v4/locales/he.js +214 -0
  741. package/node_modules/zod/v4/locales/hu.cjs +135 -0
  742. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  743. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  744. package/node_modules/zod/v4/locales/hu.js +108 -0
  745. package/node_modules/zod/v4/locales/hy.cjs +174 -0
  746. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  747. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  748. package/node_modules/zod/v4/locales/hy.js +147 -0
  749. package/node_modules/zod/v4/locales/id.cjs +133 -0
  750. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  751. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  752. package/node_modules/zod/v4/locales/id.js +106 -0
  753. package/node_modules/zod/v4/locales/index.cjs +104 -0
  754. package/node_modules/zod/v4/locales/index.d.cts +49 -0
  755. package/node_modules/zod/v4/locales/index.d.ts +49 -0
  756. package/node_modules/zod/v4/locales/index.js +49 -0
  757. package/node_modules/zod/v4/locales/is.cjs +136 -0
  758. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  759. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  760. package/node_modules/zod/v4/locales/is.js +109 -0
  761. package/node_modules/zod/v4/locales/it.cjs +135 -0
  762. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  763. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  764. package/node_modules/zod/v4/locales/it.js +108 -0
  765. package/node_modules/zod/v4/locales/ja.cjs +134 -0
  766. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  767. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  768. package/node_modules/zod/v4/locales/ja.js +107 -0
  769. package/node_modules/zod/v4/locales/ka.cjs +139 -0
  770. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  771. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  772. package/node_modules/zod/v4/locales/ka.js +112 -0
  773. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  774. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  775. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  776. package/node_modules/zod/v4/locales/kh.js +5 -0
  777. package/node_modules/zod/v4/locales/km.cjs +137 -0
  778. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  779. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  780. package/node_modules/zod/v4/locales/km.js +110 -0
  781. package/node_modules/zod/v4/locales/ko.cjs +138 -0
  782. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  783. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  784. package/node_modules/zod/v4/locales/ko.js +111 -0
  785. package/node_modules/zod/v4/locales/lt.cjs +230 -0
  786. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  787. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  788. package/node_modules/zod/v4/locales/lt.js +203 -0
  789. package/node_modules/zod/v4/locales/mk.cjs +136 -0
  790. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  791. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  792. package/node_modules/zod/v4/locales/mk.js +109 -0
  793. package/node_modules/zod/v4/locales/ms.cjs +134 -0
  794. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  795. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  796. package/node_modules/zod/v4/locales/ms.js +107 -0
  797. package/node_modules/zod/v4/locales/nl.cjs +137 -0
  798. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  799. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  800. package/node_modules/zod/v4/locales/nl.js +110 -0
  801. package/node_modules/zod/v4/locales/no.cjs +135 -0
  802. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  803. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  804. package/node_modules/zod/v4/locales/no.js +108 -0
  805. package/node_modules/zod/v4/locales/ota.cjs +136 -0
  806. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  807. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  808. package/node_modules/zod/v4/locales/ota.js +109 -0
  809. package/node_modules/zod/v4/locales/package.json +6 -0
  810. package/node_modules/zod/v4/locales/pl.cjs +136 -0
  811. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  812. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  813. package/node_modules/zod/v4/locales/pl.js +109 -0
  814. package/node_modules/zod/v4/locales/ps.cjs +141 -0
  815. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  816. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  817. package/node_modules/zod/v4/locales/ps.js +114 -0
  818. package/node_modules/zod/v4/locales/pt.cjs +135 -0
  819. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  820. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  821. package/node_modules/zod/v4/locales/pt.js +108 -0
  822. package/node_modules/zod/v4/locales/ru.cjs +183 -0
  823. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  824. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  825. package/node_modules/zod/v4/locales/ru.js +156 -0
  826. package/node_modules/zod/v4/locales/sl.cjs +136 -0
  827. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  828. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  829. package/node_modules/zod/v4/locales/sl.js +109 -0
  830. package/node_modules/zod/v4/locales/sv.cjs +137 -0
  831. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  832. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  833. package/node_modules/zod/v4/locales/sv.js +110 -0
  834. package/node_modules/zod/v4/locales/ta.cjs +137 -0
  835. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  836. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  837. package/node_modules/zod/v4/locales/ta.js +110 -0
  838. package/node_modules/zod/v4/locales/th.cjs +137 -0
  839. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  840. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  841. package/node_modules/zod/v4/locales/th.js +110 -0
  842. package/node_modules/zod/v4/locales/tr.cjs +132 -0
  843. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  844. package/node_modules/zod/v4/locales/tr.d.ts +4 -0
  845. package/node_modules/zod/v4/locales/tr.js +105 -0
  846. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  847. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  848. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  849. package/node_modules/zod/v4/locales/ua.js +5 -0
  850. package/node_modules/zod/v4/locales/uk.cjs +135 -0
  851. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  852. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  853. package/node_modules/zod/v4/locales/uk.js +108 -0
  854. package/node_modules/zod/v4/locales/ur.cjs +137 -0
  855. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  856. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  857. package/node_modules/zod/v4/locales/ur.js +110 -0
  858. package/node_modules/zod/v4/locales/uz.cjs +136 -0
  859. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  860. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  861. package/node_modules/zod/v4/locales/uz.js +109 -0
  862. package/node_modules/zod/v4/locales/vi.cjs +135 -0
  863. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  864. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  865. package/node_modules/zod/v4/locales/vi.js +108 -0
  866. package/node_modules/zod/v4/locales/yo.cjs +134 -0
  867. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  868. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  869. package/node_modules/zod/v4/locales/yo.js +107 -0
  870. package/node_modules/zod/v4/locales/zh-CN.cjs +136 -0
  871. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  872. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  873. package/node_modules/zod/v4/locales/zh-CN.js +109 -0
  874. package/node_modules/zod/v4/locales/zh-TW.cjs +134 -0
  875. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  876. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  877. package/node_modules/zod/v4/locales/zh-TW.js +107 -0
  878. package/node_modules/zod/v4/mini/checks.cjs +34 -0
  879. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  880. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  881. package/node_modules/zod/v4/mini/checks.js +1 -0
  882. package/node_modules/zod/v4/mini/coerce.cjs +52 -0
  883. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  884. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  885. package/node_modules/zod/v4/mini/coerce.js +22 -0
  886. package/node_modules/zod/v4/mini/external.cjs +63 -0
  887. package/node_modules/zod/v4/mini/external.d.cts +12 -0
  888. package/node_modules/zod/v4/mini/external.d.ts +12 -0
  889. package/node_modules/zod/v4/mini/external.js +14 -0
  890. package/node_modules/zod/v4/mini/index.cjs +32 -0
  891. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  892. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  893. package/node_modules/zod/v4/mini/index.js +3 -0
  894. package/node_modules/zod/v4/mini/iso.cjs +64 -0
  895. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  896. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  897. package/node_modules/zod/v4/mini/iso.js +34 -0
  898. package/node_modules/zod/v4/mini/package.json +6 -0
  899. package/node_modules/zod/v4/mini/parse.cjs +16 -0
  900. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  901. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  902. package/node_modules/zod/v4/mini/parse.js +1 -0
  903. package/node_modules/zod/v4/mini/schemas.cjs +1046 -0
  904. package/node_modules/zod/v4/mini/schemas.d.cts +427 -0
  905. package/node_modules/zod/v4/mini/schemas.d.ts +427 -0
  906. package/node_modules/zod/v4/mini/schemas.js +925 -0
  907. package/node_modules/zod/v4/package.json +6 -0
  908. package/node_modules/zod/v4-mini/index.cjs +32 -0
  909. package/node_modules/zod/v4-mini/index.d.cts +3 -0
  910. package/node_modules/zod/v4-mini/index.d.ts +3 -0
  911. package/node_modules/zod/v4-mini/index.js +3 -0
  912. package/node_modules/zod/v4-mini/package.json +6 -0
  913. package/package.json +3 -1
  914. package/plugin/package.json +6 -4
@@ -0,0 +1,1263 @@
1
+ /**
2
+ * hypermem Background Indexer
3
+ *
4
+ * Processes message history to extract structured knowledge:
5
+ * - Facts: atomic pieces of learned information
6
+ * - Episodes: significant events worth remembering
7
+ * - Topics: conversation threads and their lifecycle
8
+ * - Knowledge: durable structured entries (domain + key)
9
+ *
10
+ * Runs as a periodic background task, processing unindexed messages
11
+ * in batches. Each batch is scored, classified, and stored in L4 (library.db).
12
+ *
13
+ * Design principles:
14
+ * - No LLM dependency: extraction uses pattern matching + heuristics
15
+ * - Idempotent: tracks watermarks per agent to avoid reprocessing
16
+ * - Bounded: processes N messages per tick to avoid blocking
17
+ * - Observable: logs extraction stats for monitoring
18
+ */
19
+ import { lintKnowledge } from './knowledge-lint.js';
20
+ import { MessageStore } from './message-store.js';
21
+ import { runNoiseSweep, runToolDecay } from './proactive-pass.js';
22
+ import { TopicSynthesizer } from './topic-synthesizer.js';
23
+ import { runDreamingPassForFleet } from './dreaming-promoter.js';
24
+ import { FactStore } from './fact-store.js';
25
+ import { EpisodeStore } from './episode-store.js';
26
+ import { TopicStore } from './topic-store.js';
27
+ import { KnowledgeStore } from './knowledge-store.js';
28
+ import { TemporalStore } from './temporal-store.js';
29
+ import { ContradictionDetector } from './contradiction-detector.js';
30
+ import { ContradictionAuditStore } from './contradiction-audit-store.js';
31
+ import { DEFAULT_CONTRADICTION_POLICY } from './contradiction-resolution-policy.js';
32
+ import { isSafeForSharedVisibility } from './secret-scanner.js';
33
+ // ─── Agent-to-Domain Map ────────────────────────────────────────
34
+ // Maps well-known agent IDs to their primary domain.
35
+ // Used to populate the `domain` column on extracted facts so that
36
+ // domain-scoped retrieval (e.g. getActiveFacts({ domain: 'infrastructure' }))
37
+ // returns results. New agents default to 'general'.
38
+ //
39
+ // ── EXAMPLE DATA ──────────────────────────────────────────────────
40
+ // The agent names below (agent1, director1, etc.) are PLACEHOLDERS.
41
+ // Replace them with your own agent IDs and domain labels to match
42
+ // your fleet. Single-agent installs don't need to edit this:
43
+ // unknown agents fall through to 'general' automatically.
44
+ // See INSTALL.md § "Configure your fleet" for details.
45
+ // ─────────────────────────────────────────────────────────────────
46
+ const AGENT_DOMAIN_MAP = {
47
+ agent1: 'infrastructure',
48
+ director2: 'infrastructure',
49
+ director1: 'infrastructure',
50
+ director3: 'infrastructure',
51
+ agent2: 'product',
52
+ director4: 'product',
53
+ director5: 'product',
54
+ director6: 'product',
55
+ agent3: 'security',
56
+ director7: 'security',
57
+ director8: 'security',
58
+ agent4: 'ux',
59
+ agent6: 'governance',
60
+ agent5: 'strategy',
61
+ specialist1: 'development',
62
+ specialist2: 'communications',
63
+ main: 'general',
64
+ 'channel-mini': 'general',
65
+ };
66
+ /**
67
+ * Derive a domain label for a fact based on agent ID.
68
+ * Falls back to 'general' for unknown agents.
69
+ */
70
+ function domainForAgent(agentId) {
71
+ return AGENT_DOMAIN_MAP[agentId] ?? 'general';
72
+ }
73
+ function extractFactCandidates(content) {
74
+ const facts = [];
75
+ if (!content || content.length < 20)
76
+ return facts;
77
+ // Decision patterns: "decided to", "agreed on", "choosing", "going with" — high confidence (0.75)
78
+ const decisionPatterns = [
79
+ /(?:we |I |they )?(?:decided|agreed|chose|selected|committed) (?:to |on |that )(.{20,200})/gi,
80
+ /(?:going|went) with (.{10,150})/gi,
81
+ /decision:\s*(.{10,200})/gi,
82
+ ];
83
+ // Learned/discovered patterns — medium-high confidence (0.65)
84
+ const learnedPatterns = [
85
+ /(?:learned|discovered|found out|realized|noticed) (?:that |)(.{20,200})/gi,
86
+ /turns out (?:that |)(.{20,200})/gi,
87
+ /(?:TIL|FYI|note to self)[:\s]+(.{10,200})/gi,
88
+ ];
89
+ // Config/setting patterns — medium confidence (0.60); matches more promiscuously
90
+ const configPatterns = [
91
+ /(?:set|changed|updated|configured) (\S+ to .{5,150})/gi,
92
+ /(?:model|config|setting)[:\s]+(\S+\s*(?:→|->|=|is)\s*.{5,100})/gi,
93
+ ];
94
+ // Preference patterns — medium confidence (0.60)
95
+ const preferencePatterns = [
96
+ /(?:prefer|always use|never use|don't use|avoid) (.{10,150})/gi,
97
+ /(?:operator|operator) (?:wants|prefers|likes|hates|dislikes) (.{10,150})/gi,
98
+ ];
99
+ // Operational patterns: deployments, incidents, fixes — high confidence (0.70)
100
+ const operationalPatterns = [
101
+ /(?:deployed|shipped|released|rolled back|reverted) (.{10,200})/gi,
102
+ /(?:outage|incident|failure|broke|broken|crashed)(?:: | — | - )(.{10,200})/gi,
103
+ /(?:fixed|resolved|patched|hotfixed) (.{10,200})/gi,
104
+ ];
105
+ const patternGroups = [
106
+ { patterns: decisionPatterns, confidence: 0.75 },
107
+ { patterns: learnedPatterns, confidence: 0.65 },
108
+ { patterns: configPatterns, confidence: 0.60 },
109
+ { patterns: preferencePatterns, confidence: 0.60 },
110
+ { patterns: operationalPatterns, confidence: 0.70 },
111
+ ];
112
+ for (const { patterns, confidence } of patternGroups) {
113
+ for (const pattern of patterns) {
114
+ let match;
115
+ // Reset lastIndex for global patterns
116
+ pattern.lastIndex = 0;
117
+ while ((match = pattern.exec(content)) !== null) {
118
+ const candidate = match[1].trim();
119
+ // Quality gate: reject noise that matched patterns but isn't a real fact
120
+ if (!isQualityFact(candidate))
121
+ continue;
122
+ facts.push({ content: candidate, confidence });
123
+ }
124
+ }
125
+ }
126
+ return facts;
127
+ }
128
+ /**
129
+ * TUNE-011: Quality gate for fact extraction.
130
+ * Rejects pattern matches that are code, table fragments, questions,
131
+ * or too short to be meaningful facts.
132
+ */
133
+ /**
134
+ * Operational boilerplate phrases that appear frequently across sessions
135
+ * but carry zero signal value. High knn similarity makes them *worse*
136
+ * retrieval candidates — they match everything and contaminate episodes.
137
+ */
138
+ const OPERATIONAL_BOILERPLATE = [
139
+ /timed?\s*out\s*waiting/i,
140
+ /message\s*was\s*delivered/i,
141
+ /no\s*reply\s*(back\s*)?yet/i,
142
+ /picked?\s*it\s*up\s*on\s*(next\s*)?heartbeat/i,
143
+ /session\s*not\s*found/i,
144
+ /\bretrying\b/i,
145
+ /tool\s*call\s*failed/i,
146
+ /exec\s*completed/i,
147
+ /no\s*reply\s*needed/i,
148
+ /still\s*waiting/i,
149
+ /will\s*pick\s*(it\s*)?up\s*(on\s*(next|the))?/i,
150
+ /message\s*is\s*in\s*(his|her|their|the)\s*queue/i,
151
+ /sent\s+to\s+(agent6|agent2|agent4|agent3|agent5|agent1)/i,
152
+ /dispatched\s+(it\s+)?to/i,
153
+ /timed\s*out\s*after/i,
154
+ /\bNO_REPLY\b/,
155
+ ];
156
+ function isQualityFact(content) {
157
+ // Too short — sentence fragments
158
+ if (content.length < 40)
159
+ return false;
160
+ // Too long — likely captured a paragraph, not a fact
161
+ if (content.length > 300)
162
+ return false;
163
+ // Fewer than 5 words — fragment
164
+ const wordCount = content.split(/\s+/).filter(w => w.length > 0).length;
165
+ if (wordCount < 5)
166
+ return false;
167
+ // Questions — not assertions of fact
168
+ if (content.trimEnd().endsWith('?'))
169
+ return false;
170
+ // Code indicators: braces, arrows, imports, variable declarations
171
+ if (/^[\s{}\[\]|`]/.test(content))
172
+ return false; // starts with structural char
173
+ if (/[{}].*[{}]/.test(content))
174
+ return false; // contains paired braces (code blocks)
175
+ if (/^\s*(import|export|const|let|var|function|class|interface|type|return|if|for|while|switch)\s/i.test(content))
176
+ return false;
177
+ if (/=>\s*[{(]/.test(content))
178
+ return false; // arrow functions
179
+ if (/SELECT\s|INSERT\s|UPDATE\s|DELETE\s|CREATE\s/i.test(content))
180
+ return false; // SQL
181
+ // Table cell fragments: contains pipe-delimited cells
182
+ if (/\|.*\|.*\|/.test(content))
183
+ return false;
184
+ // Regex patterns leaked from source
185
+ if (/\/[^/]+\/[gimsuvy]*[,;]/.test(content))
186
+ return false;
187
+ // Raw file paths without context (tool output, not facts)
188
+ if (/^\/[\w/.-]+$/.test(content.trim()))
189
+ return false;
190
+ // Markdown formatting artifacts
191
+ if (content.startsWith('```') || content.startsWith('---') || content.startsWith('==='))
192
+ return false;
193
+ // Git output
194
+ if (/^[a-f0-9]{7,40}\s/.test(content) || /^\+\+\+|^---\s[ab]\//.test(content))
195
+ return false;
196
+ if (/^\d+ files? changed/.test(content))
197
+ return false;
198
+ // Stack traces
199
+ if (/^\s*at\s+\S+\s+\(/.test(content) || /node:internal/.test(content))
200
+ return false;
201
+ // High non-alpha ratio indicates code/data, not natural language
202
+ const alphaChars = (content.match(/[a-zA-Z]/g) || []).length;
203
+ if (alphaChars / content.length < 0.5)
204
+ return false;
205
+ // TUNE-013: External/untrusted content markers — web search excerpts,
206
+ // external doc pulls, and injected context blocks should never become facts.
207
+ if (/<<<\s*(END_EXTERNAL|BEGIN_EXTERNAL|EXTERNAL_UNTRUSTED|UNTRUSTED_CONTENT)/i.test(content))
208
+ return false;
209
+ if (/EXTERNAL_UNTRUSTED_CONTENT\s+id=/.test(content))
210
+ return false;
211
+ // TUNE-013: Multi-paragraph content — real extracted facts are single sentences.
212
+ // More than 2 newlines means we captured a paragraph or structured block, not a fact.
213
+ const newlineCount = (content.match(/\n/g) || []).length;
214
+ if (newlineCount > 2)
215
+ return false;
216
+ // TUNE-013: URL-heavy content — external source snippets, not actionable facts
217
+ const urlMatches = content.match(/https?:\/\/\S+/g) || [];
218
+ if (urlMatches.length >= 2)
219
+ return false; // one URL in a fact is ok; multiple = source snippet
220
+ // TUNE-013: Content starting with a markdown heading is section text, not a fact
221
+ if (/^#{1,4}\s/.test(content.trim()))
222
+ return false;
223
+ // TUNE-014: Operational boilerplate — phrases common across sessions that produce
224
+ // high knn similarity scores but carry zero signal. They cross-contaminate episodes.
225
+ for (const pattern of OPERATIONAL_BOILERPLATE) {
226
+ if (pattern.test(content))
227
+ return false;
228
+ }
229
+ return true;
230
+ }
231
+ /**
232
+ * Classify a message for episode significance.
233
+ * Returns episode type and significance score, or null if not significant.
234
+ */
235
+ function classifyEpisode(msg) {
236
+ const content = msg.textContent || '';
237
+ if (!content || content.length < 50)
238
+ return null; // Raised from 30
239
+ // Skip heartbeats
240
+ if (msg.isHeartbeat)
241
+ return null;
242
+ // Skip messages that are primarily code/data output (tool results, logs)
243
+ const alphaRatio = (content.match(/[a-zA-Z]/g) || []).length / content.length;
244
+ if (alphaRatio < 0.4)
245
+ return null;
246
+ // Skip messages that start with structural output indicators
247
+ if (/^[\s]*[{[\d|#=+\-]/.test(content) && content.length < 200)
248
+ return null;
249
+ const lower = content.toLowerCase();
250
+ // ── Negation-aware incident detection ──────────────────────
251
+ // Only trigger on actual incidents, not "zero failures" or "no crashes"
252
+ const incidentTerms = ['outage', 'incident', 'failure', 'crash', 'broke', 'broken', 'emergency'];
253
+ const negationPrefixes = ['no ', 'zero ', 'without ', '0 ', 'never ', 'fixed ', 'resolved '];
254
+ const hasIncidentTerm = incidentTerms.some(term => lower.includes(term));
255
+ const isNegated = hasIncidentTerm && incidentTerms.some(term => {
256
+ const idx = lower.indexOf(term);
257
+ if (idx < 0)
258
+ return false;
259
+ const prefix = lower.substring(Math.max(0, idx - 15), idx).toLowerCase();
260
+ return negationPrefixes.some(neg => prefix.includes(neg.trimEnd()));
261
+ });
262
+ if (hasIncidentTerm && !isNegated && content.length > 100) {
263
+ // Genuine incident — verify it's describing a problem, not analyzing code
264
+ if (!/^\s*(\/\/|#|\*|\/\*|```|import|const|function)/.test(content)) {
265
+ const summary = content.slice(0, 200);
266
+ return { type: 'incident', significance: 0.9, summary };
267
+ }
268
+ }
269
+ // Deployment events (high significance)
270
+ if (/(?:deployed|shipped|released|went live|now live|go live)/i.test(content) &&
271
+ content.length > 60) {
272
+ const summary = content.slice(0, 200);
273
+ return { type: 'deployment', significance: 0.8, summary };
274
+ }
275
+ // Architecture decisions (high significance)
276
+ if (/(?:decided on|chose|committed to|architecture|design decision)/i.test(content) &&
277
+ content.length > 80) {
278
+ const summary = content.slice(0, 200);
279
+ return { type: 'decision', significance: 0.7, summary };
280
+ }
281
+ // Discovery/insight (medium significance)
282
+ if (/(?:discovered|found|realized|root cause|turns out)/i.test(content) && content.length > 80) {
283
+ const summary = content.slice(0, 200);
284
+ return { type: 'discovery', significance: 0.5, summary };
285
+ }
286
+ // Config changes (medium significance) — TUNE-004: raised to 0.5
287
+ if (/(?:changed|updated|migrated|switched|model.*(?:→|->|to))/i.test(content) && content.length > 60) {
288
+ // Skip if it's just a tool output confirmation
289
+ if (/^Successfully replaced|^\[main [a-f0-9]|^ok \d+ -/.test(content))
290
+ return null;
291
+ const summary = content.slice(0, 200);
292
+ return { type: 'config_change', significance: 0.5, summary };
293
+ }
294
+ // Milestone/completion (medium significance)
295
+ if (/(?:completed|finished|done|milestone|all tests pass|all green)/i.test(content) &&
296
+ content.length > 60) {
297
+ // Skip tool output that happens to contain "done"
298
+ if (/^Successfully|^\[main|^ok \d+/.test(content))
299
+ return null;
300
+ const summary = content.slice(0, 200);
301
+ return { type: 'milestone', significance: 0.5, summary };
302
+ }
303
+ return null;
304
+ }
305
+ /**
306
+ * Extract knowledge candidates — structured (domain, key, value) tuples.
307
+ */
308
+ function extractKnowledgeCandidates(content, agentId) {
309
+ const results = [];
310
+ if (!content || content.length < 30)
311
+ return results;
312
+ // TUNE-012: Broadened path extraction.
313
+ // Real messages use paths inline without explicit prefixes like "located at".
314
+ // Match any absolute path that's at least 3 segments deep (filters /tmp, /etc noise).
315
+ const pathMatches = content.matchAll(/(?:`([/][\w./-]{10,})`|(?:^|[\s:=])(\/home\/[\w./-]{10,}|\/opt\/[\w./-]{10,}|\/var\/[\w./-]{10,}))/gm);
316
+ for (const match of pathMatches) {
317
+ const value = (match[1] || match[2]).replace(/[`'".,;:)]+$/, '').trim();
318
+ if (value.length > 10 && value.split('/').length >= 4) {
319
+ const segments = value.split('/').filter(s => s.length > 0);
320
+ const lastSeg = segments[segments.length - 1] || '';
321
+ // Reject truncated paths (last segment < 3 chars unless it's a known ext)
322
+ if (lastSeg.length < 3 && !lastSeg.includes('.'))
323
+ continue;
324
+ const key = lastSeg || segments[segments.length - 2] || 'unknown';
325
+ results.push({ domain: 'paths', key, value });
326
+ }
327
+ }
328
+ // Explicit location references (original patterns, kept for completeness)
329
+ const locationPatterns = [
330
+ /(?:path|located at|lives at|stored at|found at|repo at|running at)[:\s]+(`[^`]+`|\/\S+)/gi,
331
+ /(?:workspace|directory|repo|project)[:\s]+(`[^`]+`|\/\S+)/gi,
332
+ ];
333
+ for (const pattern of locationPatterns) {
334
+ pattern.lastIndex = 0;
335
+ let match;
336
+ while ((match = pattern.exec(content)) !== null) {
337
+ const value = match[1].replace(/[`'".,;:)]+/g, '').trim();
338
+ if (value.startsWith('/') && value.length > 10 && !results.some(r => r.value === value)) {
339
+ const key = value.split('/').pop() || 'unknown';
340
+ results.push({ domain: 'paths', key, value });
341
+ }
342
+ }
343
+ }
344
+ // Service/port patterns — broadened to catch "port NNNN" and "on :NNNN"
345
+ const servicePatterns = [
346
+ /(\S+)\s+(?:runs on|listening on|port|on port)\s+(\d{2,5})/gi,
347
+ /(?:service|server|daemon)\s+(\S+)\s+(?:on |at |: )(\S+)/gi,
348
+ /(?:localhost|127\.0\.0\.1):(\d{2,5})\b/gi,
349
+ ];
350
+ for (const pattern of servicePatterns) {
351
+ pattern.lastIndex = 0;
352
+ let match;
353
+ while ((match = pattern.exec(content)) !== null) {
354
+ if (pattern.source.includes('localhost')) {
355
+ // localhost:PORT pattern — key is the port, value is the URL
356
+ results.push({ domain: 'services', key: `port:${match[1]}`, value: match[0] });
357
+ }
358
+ else {
359
+ results.push({ domain: 'services', key: match[1], value: match[2] });
360
+ }
361
+ }
362
+ }
363
+ // Agent identity patterns — broadened
364
+ const identityPatterns = [
365
+ /(\w+)\s+(?:is|was)\s+(?:the\s+)?(\w+)\s+(?:seat|director|specialist|council)/gi,
366
+ /(\w+)\s+(?:reports to|owned by|managed by)\s+(\w+)/gi,
367
+ /(?:agents?|directors?|seats?)[:\s]+(\w+)(?:\s*[,/]\s*(\w+))+/gi,
368
+ ];
369
+ for (const pattern of identityPatterns) {
370
+ pattern.lastIndex = 0;
371
+ let match;
372
+ while ((match = pattern.exec(content)) !== null) {
373
+ if (match[2]) {
374
+ results.push({ domain: 'fleet', key: match[1].toLowerCase(), value: `${match[1]} ${match[2]}` });
375
+ }
376
+ }
377
+ }
378
+ // Dedup by domain+key
379
+ const seen = new Set();
380
+ return results.filter(r => {
381
+ const k = `${r.domain}:${r.key}`;
382
+ if (seen.has(k))
383
+ return false;
384
+ seen.add(k);
385
+ return true;
386
+ });
387
+ }
388
+ /**
389
+ * Detect conversation topic from message content.
390
+ * Returns a topic name candidate or null.
391
+ */
392
+ function detectTopic(content) {
393
+ if (!content || content.length < 50)
394
+ return null;
395
+ // Product/project name detection
396
+ const productMatch = content.match(/\b(HyperMem|ClawText|ClawDash|ClawCanvas|ClawCouncil|ClawTomation|OpenClaw|ClawDispatch)\b/i);
397
+ if (productMatch)
398
+ return productMatch[1];
399
+ // Infrastructure topic detection
400
+ if (/\b(?:redis|sqlite|database|migration|deployment|docker|nginx)\b/i.test(content)) {
401
+ return 'infrastructure';
402
+ }
403
+ // Security topic detection
404
+ if (/\b(?:security|auth|permission|access|token|credential)\b/i.test(content)) {
405
+ return 'security';
406
+ }
407
+ return null;
408
+ }
409
+ // ─── Background Indexer ─────────────────────────────────────────
410
+ export class BackgroundIndexer {
411
+ getMessageDb;
412
+ getLibraryDb;
413
+ listAgents;
414
+ getCursor;
415
+ config;
416
+ dreamerConfig;
417
+ globalWritePolicy;
418
+ contradictionPolicy;
419
+ intervalHandle = null;
420
+ running = false;
421
+ vectorStore = null;
422
+ synthesizer = null;
423
+ tickCount = 0;
424
+ /** Circuit breaker: consecutive tick failure count. Resets on success. */
425
+ consecutiveFailures = 0;
426
+ /** True when the indexer is running in backoff mode due to repeated failures. */
427
+ inBackoff = false;
428
+ _conversationLastProcessed = new Map();
429
+ lastMaintenanceDiagnostics = null;
430
+ constructor(config, getMessageDb, getLibraryDb, listAgents, getCursor, dreamerConfig, globalWritePolicy, contradictionPolicy) {
431
+ this.getMessageDb = getMessageDb;
432
+ this.getLibraryDb = getLibraryDb;
433
+ this.listAgents = listAgents;
434
+ this.getCursor = getCursor;
435
+ // Initialize synthesizer if libraryDb accessor is available
436
+ if (getLibraryDb) {
437
+ const libDb = getLibraryDb();
438
+ if (libDb) {
439
+ this.synthesizer = new TopicSynthesizer(libDb, (agentId) => {
440
+ if (!getMessageDb)
441
+ return null;
442
+ try {
443
+ return getMessageDb(agentId);
444
+ }
445
+ catch {
446
+ return null;
447
+ }
448
+ });
449
+ }
450
+ }
451
+ this.config = {
452
+ enabled: config?.enabled ?? true,
453
+ factExtractionMode: config?.factExtractionMode ?? 'tiered',
454
+ topicDormantAfter: config?.topicDormantAfter ?? '24h',
455
+ topicClosedAfter: config?.topicClosedAfter ?? '7d',
456
+ factDecayRate: config?.factDecayRate ?? 0.01,
457
+ episodeSignificanceThreshold: config?.episodeSignificanceThreshold ?? 0.5,
458
+ periodicInterval: config?.periodicInterval ?? 60000, // 1 minute
459
+ batchSize: config?.batchSize ?? 128,
460
+ maxMessagesPerTick: config?.maxMessagesPerTick ?? 500,
461
+ maxActiveConversations: config?.maxActiveConversations ?? 5,
462
+ recentConversationCooldownMs: config?.recentConversationCooldownMs ?? 30000,
463
+ maxCandidatesPerPass: config?.maxCandidatesPerPass ?? 200,
464
+ };
465
+ this.dreamerConfig = dreamerConfig ?? {};
466
+ this.globalWritePolicy = globalWritePolicy ?? 'deny';
467
+ this.contradictionPolicy = contradictionPolicy ?? DEFAULT_CONTRADICTION_POLICY;
468
+ }
469
+ /**
470
+ * Set the vector store for embedding new facts/episodes at index time.
471
+ * Optional — if not set, indexer runs without embedding (FTS5-only mode).
472
+ */
473
+ setVectorStore(vs) {
474
+ this.vectorStore = vs;
475
+ }
476
+ /**
477
+ * Start periodic indexing.
478
+ */
479
+ start() {
480
+ if (!this.config.enabled)
481
+ return;
482
+ if (this.intervalHandle)
483
+ return;
484
+ // Startup integrity check — catch corruption before the first tick writes anything.
485
+ if (this.getLibraryDb) {
486
+ try {
487
+ const libDb = this.getLibraryDb();
488
+ if (libDb) {
489
+ const row = libDb.prepare('PRAGMA quick_check').get();
490
+ if (row?.integrity_check && row.integrity_check !== 'ok') {
491
+ console.error('[indexer] ⚠️ library.db integrity check failed: ' + row.integrity_check + '\n' +
492
+ '[indexer] Recovery: stop OpenClaw, run ' +
493
+ '`sqlite3 ~/.openclaw/hypermem/library.db ".recover" | sqlite3 ~/.openclaw/hypermem/library_recovered.db`' +
494
+ ', swap the files, and restart. If recovery fails, delete library.db — the indexer rebuilds from message history.');
495
+ // Don't start the interval — nothing will succeed with a corrupt DB.
496
+ return;
497
+ }
498
+ }
499
+ }
500
+ catch (err) {
501
+ // If we can't even open the DB, log and bail — don't start the interval.
502
+ console.error('[indexer] Could not open library.db for integrity check:', err.message);
503
+ return;
504
+ }
505
+ }
506
+ // Run once immediately
507
+ this.tick().catch(err => {
508
+ this._handleTickError(err, 'initial');
509
+ });
510
+ // Run episode vector backfill once at startup (no-op if already done)
511
+ if (this.vectorStore && this.getLibraryDb) {
512
+ this.backfillEpisodeVectors().catch(err => {
513
+ console.error('[indexer] Episode backfill failed:', err);
514
+ });
515
+ }
516
+ // Then periodically
517
+ this.intervalHandle = setInterval(() => {
518
+ this.tick().catch(err => {
519
+ this._handleTickError(err, 'periodic');
520
+ });
521
+ }, this.config.periodicInterval);
522
+ console.log(`[indexer] Started with interval ${this.config.periodicInterval}ms, batchSize ${this.config.batchSize}, maxPerTick ${this.config.maxMessagesPerTick}`);
523
+ }
524
+ /**
525
+ * Circuit breaker for tick failures.
526
+ *
527
+ * - Tracks consecutive failures.
528
+ * - After 3 failures, logs actionable recovery guidance once, then switches
529
+ * the indexer to 10× backoff interval so it stops spamming the log.
530
+ * - On the next successful tick, resets state and restores normal interval.
531
+ */
532
+ _handleTickError(err, phase) {
533
+ this.consecutiveFailures++;
534
+ const msg = err instanceof Error ? err.message : String(err);
535
+ const isSqliteCorrupt = msg.includes('database disk image is malformed') ||
536
+ msg.includes('SQLITE_CORRUPT') ||
537
+ (err instanceof Error && 'code' in err && err.code === 'ERR_SQLITE_ERROR');
538
+ if (this.consecutiveFailures < 3) {
539
+ // First 1–2 failures: log normally.
540
+ console.error(`[indexer] ${phase === 'initial' ? 'Initial' : 'Periodic'} tick failed (attempt ${this.consecutiveFailures}/3):`, err);
541
+ return;
542
+ }
543
+ if (this.consecutiveFailures === 3) {
544
+ // Third failure: log once with recovery instructions, then enter backoff.
545
+ if (isSqliteCorrupt) {
546
+ console.error(`[indexer] ⛔ Tick failed 3 times consecutively — library.db appears corrupted. Entering backoff mode.\n` +
547
+ `[indexer] Recovery steps:\n` +
548
+ `[indexer] 1. Stop OpenClaw: openclaw gateway stop\n` +
549
+ `[indexer] 2. Check damage: sqlite3 ~/.openclaw/hypermem/library.db "PRAGMA integrity_check"\n` +
550
+ `[indexer] 3. Attempt recovery: sqlite3 ~/.openclaw/hypermem/library.db ".recover" | sqlite3 ~/.openclaw/hypermem/library_recovered.db\n` +
551
+ `[indexer] 4. Swap: mv library.db library_corrupt.bak && mv library_recovered.db library.db\n` +
552
+ `[indexer] 5. If recovery fails, delete library.db — the indexer rebuilds from message history on next start.\n` +
553
+ `[indexer] 6. Restart: openclaw gateway start\n` +
554
+ `[indexer] Indexer will retry every ${(this.config.periodicInterval * 10) / 60000} minutes until then.`);
555
+ }
556
+ else {
557
+ console.error(`[indexer] ⛔ Tick failed 3 times consecutively (${msg}). Entering backoff mode. ` +
558
+ `Will retry every ${(this.config.periodicInterval * 10) / 60000} minutes.`);
559
+ }
560
+ // Switch to backoff interval.
561
+ this.inBackoff = true;
562
+ if (this.intervalHandle) {
563
+ clearInterval(this.intervalHandle);
564
+ }
565
+ this.intervalHandle = setInterval(() => {
566
+ this.tick().catch(backoffErr => {
567
+ this._handleTickError(backoffErr, 'periodic');
568
+ });
569
+ }, this.config.periodicInterval * 10);
570
+ return;
571
+ }
572
+ // Beyond 3: silent (already logged, in backoff — don't spam).
573
+ }
574
+ /**
575
+ * Reset the circuit breaker and restore normal interval after a successful tick.
576
+ * Called at the end of a successful tick().
577
+ */
578
+ _resetCircuitBreaker() {
579
+ if (this.consecutiveFailures === 0)
580
+ return;
581
+ const wasInBackoff = this.inBackoff;
582
+ this.consecutiveFailures = 0;
583
+ this.inBackoff = false;
584
+ if (wasInBackoff) {
585
+ // Restore normal interval.
586
+ if (this.intervalHandle)
587
+ clearInterval(this.intervalHandle);
588
+ this.intervalHandle = setInterval(() => {
589
+ this.tick().catch(err => {
590
+ this._handleTickError(err, 'periodic');
591
+ });
592
+ }, this.config.periodicInterval);
593
+ console.log('[indexer] Circuit breaker reset — tick succeeded, restored normal interval.');
594
+ }
595
+ }
596
+ /**
597
+ * Stop periodic indexing.
598
+ */
599
+ stop() {
600
+ if (this.intervalHandle) {
601
+ clearInterval(this.intervalHandle);
602
+ this.intervalHandle = null;
603
+ }
604
+ }
605
+ /**
606
+ * Run one indexing pass across all agents.
607
+ */
608
+ async tick() {
609
+ if (this.running) {
610
+ console.log('[indexer] Skipping tick — previous run still active');
611
+ return [];
612
+ }
613
+ this.running = true;
614
+ const results = [];
615
+ let tickSucceeded = false;
616
+ try {
617
+ if (!this.listAgents || !this.getMessageDb || !this.getLibraryDb) {
618
+ console.warn('[indexer] Missing database accessors — skipping');
619
+ return [];
620
+ }
621
+ const agents = this.listAgents();
622
+ const libraryDb = this.getLibraryDb();
623
+ let tickTotal = 0;
624
+ for (const agentId of agents) {
625
+ if (tickTotal >= this.config.maxMessagesPerTick) {
626
+ console.log(`[indexer] maxMessagesPerTick (${this.config.maxMessagesPerTick}) reached — deferring remaining agents`);
627
+ break;
628
+ }
629
+ try {
630
+ const stats = await this.processAgent(agentId, libraryDb);
631
+ tickTotal += stats.messagesProcessed;
632
+ if (stats.messagesProcessed > 0 || stats.tombstoned > 0) {
633
+ results.push(stats);
634
+ }
635
+ }
636
+ catch (err) {
637
+ const msg = err instanceof Error ? err.message : String(err);
638
+ console.error(`[indexer] Failed to process ${agentId}: ${msg}`);
639
+ }
640
+ }
641
+ if (results.length > 0) {
642
+ const totalMessages = results.reduce((s, r) => s + r.messagesProcessed, 0);
643
+ const totalFacts = results.reduce((s, r) => s + r.factsExtracted, 0);
644
+ const totalEpisodes = results.reduce((s, r) => s + r.episodesRecorded, 0);
645
+ const totalTombstoned = results.reduce((s, r) => s + r.tombstoned, 0);
646
+ const tombstonedPart = totalTombstoned > 0 ? `, ${totalTombstoned} tombstoned` : '';
647
+ console.log(`[indexer] Tick complete: ${totalMessages} messages → ${totalFacts} facts, ${totalEpisodes} episodes${tombstonedPart}`);
648
+ }
649
+ // Run decay on every tick
650
+ this.applyDecay(libraryDb);
651
+ // Topic synthesis — run for each agent after main indexer tick
652
+ if (this.synthesizer) {
653
+ for (const agentId of agents) {
654
+ try {
655
+ const synthResult = this.synthesizer.tick(agentId);
656
+ if (synthResult.topicsSynthesized > 0) {
657
+ console.log(`[indexer] Synthesized ${synthResult.topicsSynthesized} topics for ${agentId}, ${synthResult.knowledgeEntriesWritten} knowledge entries`);
658
+ }
659
+ }
660
+ catch {
661
+ // Non-fatal
662
+ }
663
+ }
664
+ }
665
+ // Knowledge lint — every LINT_FREQUENCY ticks
666
+ this.tickCount++;
667
+ if (this.tickCount % 10 === 0 && this.getLibraryDb) {
668
+ try {
669
+ const libDb = this.getLibraryDb();
670
+ if (libDb) {
671
+ const lint = lintKnowledge(libDb);
672
+ if (lint.staleDecayed > 0 || lint.coverageGaps.length > 0) {
673
+ console.log(`[indexer] Lint: ${lint.staleDecayed} stale decayed, ${lint.orphansFound} orphans, ${lint.coverageGaps.length} coverage gaps`);
674
+ }
675
+ }
676
+ }
677
+ catch {
678
+ // Non-fatal
679
+ }
680
+ }
681
+ // Dreaming promotion pass — every tickInterval ticks (default 12 = ~1hr)
682
+ const dreamerEnabled = this.dreamerConfig.enabled ?? false;
683
+ const dreamerTickInterval = this.dreamerConfig.tickInterval ?? 12;
684
+ if (dreamerEnabled && this.tickCount % dreamerTickInterval === 0 && this.getLibraryDb) {
685
+ try {
686
+ const libDb = this.getLibraryDb();
687
+ if (libDb) {
688
+ const dreamResults = await runDreamingPassForFleet(agents, libDb, this.dreamerConfig);
689
+ const totalPromoted = dreamResults.reduce((s, r) => s + r.promoted, 0);
690
+ if (totalPromoted > 0) {
691
+ console.log(`[indexer] Dreaming: promoted ${totalPromoted} facts across ${dreamResults.length} agents`);
692
+ }
693
+ }
694
+ }
695
+ catch (err) {
696
+ // Non-fatal — dreaming failures never block indexing
697
+ console.warn('[indexer] Dreaming pass failed (non-fatal):', err.message);
698
+ }
699
+ }
700
+ // Run proactive passes on each agent's message DB
701
+ const maintStart = Date.now();
702
+ let maintConsidered = 0;
703
+ let maintSkipped = 0;
704
+ let maintScanned = 0;
705
+ let maintMutated = 0;
706
+ let maintExitReason = 'complete';
707
+ const maxConvs = this.config.maxActiveConversations ?? 5;
708
+ const cooldownMs = this.config.recentConversationCooldownMs ?? 30000;
709
+ const maxCandidates = this.config.maxCandidatesPerPass ?? 200;
710
+ const now = Date.now();
711
+ for (const agentId of agents) {
712
+ const messageDb = this.getMessageDb(agentId);
713
+ if (!messageDb)
714
+ continue;
715
+ let convRows;
716
+ try {
717
+ convRows = messageDb.prepare(`SELECT id FROM conversations WHERE agent_id = ? AND status = 'active' ORDER BY updated_at DESC LIMIT ?`).all(agentId, maxConvs);
718
+ }
719
+ catch {
720
+ continue;
721
+ }
722
+ if (convRows.length === 0) {
723
+ if (maintExitReason === 'complete')
724
+ maintExitReason = 'no-conversations';
725
+ continue;
726
+ }
727
+ for (const conv of convRows) {
728
+ maintConsidered++;
729
+ const lastProcessed = this._conversationLastProcessed.get(conv.id) ?? 0;
730
+ if (now - lastProcessed < cooldownMs) {
731
+ maintSkipped++;
732
+ continue;
733
+ }
734
+ maintScanned++;
735
+ // Any successful scan means we're in a real working state —
736
+ // clear any stale 'no-conversations' marker from an earlier agent.
737
+ if (maintExitReason === 'no-conversations')
738
+ maintExitReason = 'complete';
739
+ const noiseSweepResult = runNoiseSweep(messageDb, conv.id, 20, maxCandidates);
740
+ const toolDecayResult = runToolDecay(messageDb, conv.id, 40, maxCandidates);
741
+ const changed = noiseSweepResult.messagesDeleted + toolDecayResult.messagesUpdated;
742
+ if (changed > 0) {
743
+ maintMutated += changed;
744
+ console.log(`[indexer] Proactive pass (conv ${conv.id}): swept ${noiseSweepResult.messagesDeleted} noise msgs, ` +
745
+ `decayed ${toolDecayResult.messagesUpdated} tool results (${toolDecayResult.bytesFreed} bytes freed)`);
746
+ }
747
+ this._conversationLastProcessed.set(conv.id, now);
748
+ if (maintMutated >= maxCandidates) {
749
+ maintExitReason = 'cap-reached';
750
+ break;
751
+ }
752
+ }
753
+ if (maintExitReason === 'cap-reached')
754
+ break;
755
+ }
756
+ this.lastMaintenanceDiagnostics = {
757
+ considered: maintConsidered,
758
+ skipped: maintSkipped,
759
+ scanned: maintScanned,
760
+ mutated: maintMutated,
761
+ durationMs: Date.now() - maintStart,
762
+ exitReason: maintExitReason,
763
+ };
764
+ if (maintScanned > 0) {
765
+ console.log(`[indexer] Maintenance: considered=${maintConsidered} skipped=${maintSkipped} scanned=${maintScanned} mutated=${maintMutated} ` +
766
+ `duration=${this.lastMaintenanceDiagnostics.durationMs}ms exit=${maintExitReason}`);
767
+ }
768
+ // If we reach here, the tick completed without throwing.
769
+ tickSucceeded = true;
770
+ }
771
+ finally {
772
+ if (tickSucceeded)
773
+ this._resetCircuitBreaker();
774
+ this.running = false;
775
+ }
776
+ return results;
777
+ }
778
+ /**
779
+ * Process a single agent's unindexed messages.
780
+ *
781
+ * When a cursor fetcher is available, messages are split into two tiers:
782
+ * - Post-cursor (id > cursor.lastSentId): "unseen" by the model, high-signal priority
783
+ * - Pre-cursor (id <= cursor.lastSentId): already in the model's context window, lower priority
784
+ * Post-cursor messages are processed first. This ensures the indexer prioritizes
785
+ * content the model hasn't seen yet — decisions, incidents, and discoveries that
786
+ * happened between context windows.
787
+ */
788
+ async processAgent(agentId, libraryDb) {
789
+ const start = Date.now();
790
+ const messageDb = this.getMessageDb(agentId);
791
+ const messageStore = new MessageStore(messageDb);
792
+ const factStore = new FactStore(libraryDb);
793
+ const episodeStore = new EpisodeStore(libraryDb);
794
+ const topicStore = new TopicStore(libraryDb);
795
+ const knowledgeStore = new KnowledgeStore(libraryDb);
796
+ const temporalStore = new TemporalStore(libraryDb);
797
+ // Get watermark — last processed message ID for this agent
798
+ const watermark = this.getWatermark(libraryDb, agentId);
799
+ const lastProcessedId = watermark?.lastMessageId ?? 0;
800
+ // Fetch unindexed messages (batch size from config)
801
+ const messages = this.getUnindexedMessages(messageDb, agentId, lastProcessedId, this.config.batchSize);
802
+ if (messages.length === 0) {
803
+ // Even with no new messages, run tombstone cleanup in case supersedes
804
+ // were written externally (e.g. via FactStore.markSuperseded()).
805
+ let tombstoned = 0;
806
+ if (this.vectorStore) {
807
+ tombstoned = this.vectorStore.tombstoneSuperseded();
808
+ }
809
+ return {
810
+ agentId,
811
+ messagesProcessed: 0,
812
+ factsExtracted: 0,
813
+ episodesRecorded: 0,
814
+ topicsUpdated: 0,
815
+ knowledgeUpserted: 0,
816
+ tombstoned,
817
+ postCursorMessages: 0,
818
+ contradictionAuditsLogged: 0,
819
+ contradictionsAutoSuperseded: 0,
820
+ contradictionsAutoInvalidated: 0,
821
+ elapsedMs: Date.now() - start,
822
+ };
823
+ }
824
+ // ── Cursor-aware prioritization ──────────────────────────────
825
+ // Fetch the cursor boundary to split messages into post-cursor (unseen)
826
+ // and pre-cursor (already in context). Post-cursor messages are processed
827
+ // first — they're the highest signal for fact/episode extraction.
828
+ let cursorBoundary = 0;
829
+ if (this.getCursor) {
830
+ try {
831
+ // Get session key from the first message's conversation
832
+ const sessionKey = this.getSessionKeyForMessage(messageDb, messages[0].conversationId);
833
+ if (sessionKey) {
834
+ const cursor = await this.getCursor(agentId, sessionKey);
835
+ if (cursor) {
836
+ cursorBoundary = cursor.lastSentId;
837
+ }
838
+ }
839
+ }
840
+ catch {
841
+ // Cursor fetch is best-effort — fall through to default ordering
842
+ }
843
+ }
844
+ // Sort: post-cursor messages first (highest signal), then pre-cursor.
845
+ // Within each tier, maintain original (ascending) order.
846
+ const postCursor = messages.filter(m => m.id > cursorBoundary);
847
+ const preCursor = messages.filter(m => m.id <= cursorBoundary);
848
+ const ordered = [...postCursor, ...preCursor];
849
+ let factsExtracted = 0;
850
+ let episodesRecorded = 0;
851
+ let topicsUpdated = 0;
852
+ let knowledgeUpserted = 0;
853
+ let supersededFacts = 0;
854
+ let contradictionAuditsLogged = 0;
855
+ let contradictionsAutoSuperseded = 0;
856
+ let contradictionsAutoInvalidated = 0;
857
+ let maxMessageId = lastProcessedId;
858
+ const contradictionDetector = new ContradictionDetector(factStore, this.vectorStore ?? undefined, {
859
+ autoResolve: false,
860
+ maxCandidates: 6,
861
+ minSimilarity: 0.45,
862
+ });
863
+ const contradictionAuditStore = new ContradictionAuditStore(libraryDb);
864
+ for (const msg of ordered) {
865
+ const content = msg.textContent || '';
866
+ if (msg.id > maxMessageId)
867
+ maxMessageId = msg.id;
868
+ // Skip heartbeats and very short messages
869
+ if (msg.isHeartbeat || content.length < 30)
870
+ continue;
871
+ // 1. Extract facts (TUNE-003: confidence varies by extraction pattern type)
872
+ const factCandidates = extractFactCandidates(content);
873
+ for (const { content: factContent, confidence: factConfidence } of factCandidates) {
874
+ try {
875
+ const factDomain = domainForAgent(agentId);
876
+ // 1. Detect contradictions BEFORE addFact (operates on existing facts only)
877
+ const contradictionResult = await contradictionDetector.detectOnIngest(agentId, {
878
+ content: factContent,
879
+ domain: factDomain,
880
+ });
881
+ const topContradictions = contradictionResult.contradictions.slice(0, 3);
882
+ // 2. addFact first — we need fact.id for supersede linkage
883
+ const fact = factStore.addFact(agentId, factContent, {
884
+ scope: 'agent',
885
+ domain: factDomain,
886
+ confidence: factConfidence,
887
+ sourceType: 'indexer',
888
+ sourceSessionKey: this.getSessionKeyForMessage(messageDb, msg.conversationId),
889
+ sourceRef: `msg:${msg.id}`,
890
+ });
891
+ factsExtracted++;
892
+ // 3. Apply contradiction policy for each candidate (now we have fact.id)
893
+ for (const candidate of topContradictions) {
894
+ const score = candidate.contradictionScore;
895
+ let auditStatus = 'pending';
896
+ if (score >= this.contradictionPolicy.autoSupersedeThreshold) {
897
+ const didSupersede = factStore.markSuperseded(candidate.existingFactId, fact.id);
898
+ if (didSupersede) {
899
+ contradictionsAutoSuperseded++;
900
+ // Immediately remove stale vector so it cannot surface in KNN recall
901
+ if (this.vectorStore) {
902
+ this.vectorStore.removeItem('facts', candidate.existingFactId);
903
+ }
904
+ }
905
+ auditStatus = 'auto-superseded';
906
+ }
907
+ else if (score >= this.contradictionPolicy.autoInvalidateThreshold) {
908
+ const didInvalidate = factStore.invalidateFact(candidate.existingFactId);
909
+ if (didInvalidate) {
910
+ contradictionsAutoInvalidated++;
911
+ }
912
+ auditStatus = 'auto-invalidated';
913
+ }
914
+ if (this.contradictionPolicy.alwaysAudit || auditStatus === 'pending') {
915
+ contradictionAuditStore.recordFactAudit(agentId, { content: factContent, domain: factDomain }, candidate, { sourceRef: `msg:${msg.id}`, status: auditStatus });
916
+ contradictionAuditsLogged++;
917
+ }
918
+ }
919
+ // ── Supersedes detection ─────────────────────────────────
920
+ // Check if the newly extracted fact supersedes an existing one.
921
+ // A supersede is detected when an existing active fact shares the
922
+ // same 60-char prefix (same topic, different phrasing/update).
923
+ if (fact.id) {
924
+ // Index into temporal store (ingest_at as proxy, confidence=0.5)
925
+ temporalStore.indexFact(fact.id, agentId, fact.createdAt);
926
+ const oldFactId = factStore.findSupersedableByContent(agentId, factContent);
927
+ if (oldFactId !== null && oldFactId !== fact.id) {
928
+ const didSupersede = factStore.markSuperseded(oldFactId, fact.id);
929
+ if (didSupersede) {
930
+ supersededFacts++;
931
+ // Immediately remove the stale vector so it can't surface in KNN recall
932
+ if (this.vectorStore) {
933
+ this.vectorStore.removeItem('facts', oldFactId);
934
+ }
935
+ }
936
+ }
937
+ }
938
+ // Embed new fact for semantic recall (best-effort, non-blocking)
939
+ if (this.vectorStore && fact.id) {
940
+ this.vectorStore.indexItem('facts', fact.id, factContent, fact.domain || undefined)
941
+ .catch(() => { });
942
+ }
943
+ }
944
+ catch {
945
+ // Duplicate or constraint violation — skip
946
+ }
947
+ }
948
+ // 2. Classify episodes
949
+ const episode = classifyEpisode(msg);
950
+ if (episode && episode.significance >= this.config.episodeSignificanceThreshold) {
951
+ // Secret gate: shared visibility requires clean content.
952
+ // Downgrade to 'private' rather than drop, so we don't lose the episode.
953
+ const episodeVisibility = isSafeForSharedVisibility(episode.summary) ? 'org' : 'private';
954
+ try {
955
+ const recorded = episodeStore.record(agentId, episode.type, episode.summary, {
956
+ significance: episode.significance,
957
+ visibility: episodeVisibility,
958
+ sessionKey: this.getSessionKeyForMessage(messageDb, msg.conversationId),
959
+ sourceMessageId: msg.id,
960
+ });
961
+ episodesRecorded++;
962
+ // Embed episodes at sig>=0.5 (lowered from 0.7 — discovery/config_change events
963
+ // at sig=0.5 are real operational events, not noise).
964
+ if (this.vectorStore && recorded?.id && episode.significance >= 0.5) {
965
+ this.vectorStore.indexItem('episodes', recorded.id, episode.summary, episode.type)
966
+ .catch(() => { });
967
+ }
968
+ }
969
+ catch {
970
+ // Skip duplicate episodes
971
+ }
972
+ }
973
+ // 3. Detect and update topics
974
+ const topicName = detectTopic(content);
975
+ if (topicName && topicName.trim().length >= 3) {
976
+ try {
977
+ const msgSessionKey = this.getSessionKeyForMessage(messageDb, msg.conversationId) || '';
978
+ // findOrCreate handles case-insensitive dedup at the schema level;
979
+ // always touch afterward so message_count reflects real activity
980
+ // rather than sitting at 0 forever (which made every topic an orphan).
981
+ const topic = topicStore.findOrCreate(agentId, topicName, `Auto-detected from conversation`);
982
+ topicStore.touch(topic.id, msgSessionKey, 1);
983
+ topicsUpdated++;
984
+ }
985
+ catch {
986
+ // Skip topic creation/touch errors
987
+ }
988
+ }
989
+ // 4. Extract knowledge candidates
990
+ const knowledgeCandidates = extractKnowledgeCandidates(content, agentId);
991
+ for (const { domain, key, value } of knowledgeCandidates) {
992
+ try {
993
+ knowledgeStore.upsert(agentId, domain, key, value, {
994
+ sourceType: 'indexer',
995
+ sourceRef: `msg:${msg.id}`,
996
+ });
997
+ knowledgeUpserted++;
998
+ }
999
+ catch {
1000
+ // Skip duplicates
1001
+ }
1002
+ }
1003
+ }
1004
+ // Update watermark
1005
+ this.setWatermark(libraryDb, agentId, maxMessageId);
1006
+ // Run tombstone pass: remove vector entries for any facts marked superseded
1007
+ // (covers both the supersedes detected above and external markSuperseded calls).
1008
+ let tombstoned = 0;
1009
+ if (this.vectorStore) {
1010
+ tombstoned = this.vectorStore.tombstoneSuperseded();
1011
+ }
1012
+ return {
1013
+ agentId,
1014
+ messagesProcessed: messages.length,
1015
+ factsExtracted,
1016
+ episodesRecorded,
1017
+ topicsUpdated,
1018
+ knowledgeUpserted,
1019
+ tombstoned,
1020
+ contradictionAuditsLogged,
1021
+ contradictionsAutoSuperseded,
1022
+ contradictionsAutoInvalidated,
1023
+ postCursorMessages: postCursor.length,
1024
+ elapsedMs: Date.now() - start,
1025
+ };
1026
+ }
1027
+ /**
1028
+ * Fetch unindexed messages for an agent.
1029
+ */
1030
+ getUnindexedMessages(db, agentId, afterId, limit) {
1031
+ const rows = db.prepare(`
1032
+ SELECT m.*, c.session_key
1033
+ FROM messages m
1034
+ JOIN conversations c ON m.conversation_id = c.id
1035
+ WHERE m.agent_id = ? AND m.id > ?
1036
+ ORDER BY m.id ASC
1037
+ LIMIT ?
1038
+ `).all(agentId, afterId, limit);
1039
+ return rows.map(row => ({
1040
+ id: row.id,
1041
+ conversationId: row.conversation_id,
1042
+ agentId: row.agent_id,
1043
+ role: row.role,
1044
+ textContent: row.text_content || null,
1045
+ toolCalls: row.tool_calls ? JSON.parse(row.tool_calls) : null,
1046
+ toolResults: row.tool_results ? JSON.parse(row.tool_results) : null,
1047
+ metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
1048
+ messageIndex: row.message_index,
1049
+ tokenCount: row.token_count || null,
1050
+ isHeartbeat: row.is_heartbeat === 1,
1051
+ createdAt: row.created_at,
1052
+ }));
1053
+ }
1054
+ /**
1055
+ * Get the session key for a conversation ID.
1056
+ */
1057
+ getSessionKeyForMessage(db, conversationId) {
1058
+ const row = db.prepare('SELECT session_key FROM conversations WHERE id = ?').get(conversationId);
1059
+ return row?.session_key;
1060
+ }
1061
+ /**
1062
+ * Get the indexing watermark for an agent.
1063
+ */
1064
+ getWatermark(libraryDb, agentId) {
1065
+ // Ensure watermarks table exists
1066
+ libraryDb.prepare(`
1067
+ CREATE TABLE IF NOT EXISTS indexer_watermarks (
1068
+ agent_id TEXT PRIMARY KEY,
1069
+ last_message_id INTEGER NOT NULL DEFAULT 0,
1070
+ last_run_at TEXT NOT NULL
1071
+ )
1072
+ `).run();
1073
+ const row = libraryDb.prepare('SELECT agent_id, last_message_id, last_run_at FROM indexer_watermarks WHERE agent_id = ?').get(agentId);
1074
+ if (!row)
1075
+ return null;
1076
+ return {
1077
+ agentId: row.agent_id,
1078
+ lastMessageId: row.last_message_id,
1079
+ lastRunAt: row.last_run_at,
1080
+ };
1081
+ }
1082
+ /**
1083
+ * Set the indexing watermark for an agent.
1084
+ */
1085
+ setWatermark(libraryDb, agentId, lastMessageId) {
1086
+ const now = new Date().toISOString();
1087
+ libraryDb.prepare(`
1088
+ INSERT INTO indexer_watermarks (agent_id, last_message_id, last_run_at)
1089
+ VALUES (?, ?, ?)
1090
+ ON CONFLICT(agent_id) DO UPDATE SET
1091
+ last_message_id = excluded.last_message_id,
1092
+ last_run_at = excluded.last_run_at
1093
+ `).run(agentId, lastMessageId, now);
1094
+ }
1095
+ /**
1096
+ * Apply time-based decay to facts.
1097
+ * Increases decay_score for older facts, making them less relevant.
1098
+ */
1099
+ applyDecay(libraryDb) {
1100
+ const rate = this.config.factDecayRate;
1101
+ // Decay facts that haven't been referenced recently
1102
+ libraryDb.prepare(`
1103
+ UPDATE facts
1104
+ SET decay_score = MIN(1.0, decay_score + ?)
1105
+ WHERE superseded_by IS NULL
1106
+ AND decay_score < 1.0
1107
+ AND updated_at < datetime('now', '-1 day')
1108
+ `).run(rate);
1109
+ // Decay episodes older than 7 days
1110
+ libraryDb.prepare(`
1111
+ UPDATE episodes
1112
+ SET decay_score = MIN(1.0, decay_score + ?)
1113
+ WHERE decay_score < 1.0
1114
+ AND created_at < datetime('now', '-7 days')
1115
+ `).run(rate * 0.5);
1116
+ // Mark dormant topics
1117
+ const dormantThreshold = this.parseDuration(this.config.topicDormantAfter);
1118
+ if (dormantThreshold > 0) {
1119
+ // Compute threshold timestamp in JS and pass as parameter — avoids SQL template interpolation.
1120
+ const dormantBefore = new Date(Date.now() - dormantThreshold * 1000).toISOString();
1121
+ libraryDb.prepare(`
1122
+ UPDATE topics
1123
+ SET status = 'dormant'
1124
+ WHERE status = 'active'
1125
+ AND updated_at < ?
1126
+ `).run(dormantBefore);
1127
+ }
1128
+ // Close old dormant topics
1129
+ const closedThreshold = this.parseDuration(this.config.topicClosedAfter);
1130
+ if (closedThreshold > 0) {
1131
+ const closedBefore = new Date(Date.now() - closedThreshold * 1000).toISOString();
1132
+ libraryDb.prepare(`
1133
+ UPDATE topics
1134
+ SET status = 'closed'
1135
+ WHERE status = 'dormant'
1136
+ AND updated_at < ?
1137
+ `).run(closedBefore);
1138
+ }
1139
+ }
1140
+ /**
1141
+ * Parse a duration string like "24h", "7d" into seconds.
1142
+ */
1143
+ parseDuration(dur) {
1144
+ const match = dur.match(/^(\d+)\s*(h|d|m|s)$/);
1145
+ if (!match)
1146
+ return 0;
1147
+ const val = parseInt(match[1]);
1148
+ switch (match[2]) {
1149
+ case 's': return val;
1150
+ case 'm': return val * 60;
1151
+ case 'h': return val * 3600;
1152
+ case 'd': return val * 86400;
1153
+ default: return 0;
1154
+ }
1155
+ }
1156
+ /**
1157
+ * One-time backfill: embed episodes with sig>=0.5 that were missed by the
1158
+ * old >=0.7 vectorization threshold.
1159
+ *
1160
+ * Gated by a system_state flag 'indexer:episode_backfill_v1' so it runs
1161
+ * exactly once even across gateway restarts. Safe to re-run manually
1162
+ * (delete the flag row first) if re-backfill is ever needed.
1163
+ */
1164
+ async backfillEpisodeVectors() {
1165
+ if (!this.vectorStore || !this.getLibraryDb)
1166
+ return;
1167
+ const libraryDb = this.getLibraryDb();
1168
+ const BACKFILL_FLAG = 'episode_backfill_v1';
1169
+ // Ensure system_state table exists (schema may not have been applied yet)
1170
+ try {
1171
+ libraryDb.prepare(`
1172
+ CREATE TABLE IF NOT EXISTS system_state (
1173
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
1174
+ category TEXT NOT NULL,
1175
+ key TEXT NOT NULL,
1176
+ value TEXT,
1177
+ updated_at TEXT NOT NULL,
1178
+ updated_by TEXT,
1179
+ ttl TEXT,
1180
+ UNIQUE(category, key)
1181
+ )
1182
+ `).run();
1183
+ }
1184
+ catch {
1185
+ // Table already exists — safe to ignore
1186
+ }
1187
+ // Check if backfill already completed
1188
+ const existing = libraryDb.prepare("SELECT value FROM system_state WHERE category = 'indexer' AND key = ?").get(BACKFILL_FLAG);
1189
+ if (existing) {
1190
+ // Already done
1191
+ return;
1192
+ }
1193
+ console.log('[indexer] Starting episode vector backfill (sig>=0.5, not yet vectorized)...');
1194
+ // Find episodes with sig>=0.5 that have no vec_index_map entry.
1195
+ // We join against vec_index_map using a fallback: if the table is in a
1196
+ // separate DB (vectors.db), we query it directly via the VectorStore.
1197
+ let episodes;
1198
+ try {
1199
+ episodes = libraryDb.prepare(`
1200
+ SELECT id, summary, event_type
1201
+ FROM episodes
1202
+ WHERE significance >= 0.5
1203
+ ORDER BY created_at DESC
1204
+ `).all();
1205
+ }
1206
+ catch {
1207
+ console.warn('[indexer] Backfill: could not query episodes table');
1208
+ return;
1209
+ }
1210
+ let queued = 0;
1211
+ let skipped = 0;
1212
+ for (const ep of episodes) {
1213
+ // Check if already vectorized
1214
+ if (this.vectorStore.hasItem('episodes', ep.id)) {
1215
+ skipped++;
1216
+ continue;
1217
+ }
1218
+ try {
1219
+ await this.vectorStore.indexItem('episodes', ep.id, ep.summary, ep.event_type);
1220
+ queued++;
1221
+ }
1222
+ catch {
1223
+ // Non-fatal — keep going
1224
+ }
1225
+ }
1226
+ // Mark backfill complete
1227
+ const now = new Date().toISOString();
1228
+ libraryDb.prepare(`
1229
+ INSERT INTO system_state (category, key, value, updated_at, updated_by)
1230
+ VALUES ('indexer', ?, ?, ?, 'indexer')
1231
+ ON CONFLICT(category, key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
1232
+ `).run(BACKFILL_FLAG, JSON.stringify({ completedAt: now, queued, skipped }), now);
1233
+ console.log(`[indexer] Episode backfill complete: ${queued} queued, ${skipped} already vectorized`);
1234
+ }
1235
+ /**
1236
+ * Get current watermarks for all agents.
1237
+ */
1238
+ getWatermarks(libraryDb) {
1239
+ try {
1240
+ const rows = libraryDb.prepare('SELECT agent_id, last_message_id, last_run_at FROM indexer_watermarks ORDER BY agent_id').all();
1241
+ return rows.map(r => ({
1242
+ agentId: r.agent_id,
1243
+ lastMessageId: r.last_message_id,
1244
+ lastRunAt: r.last_run_at,
1245
+ }));
1246
+ }
1247
+ catch {
1248
+ return [];
1249
+ }
1250
+ }
1251
+ }
1252
+ // ─── Standalone runner ──────────────────────────────────────────
1253
+ /**
1254
+ * Create and start a background indexer connected to hypermem databases.
1255
+ * Used by the hook or a standalone daemon.
1256
+ */
1257
+ export function createIndexer(getMessageDb, getLibraryDb, listAgents, config, getCursor, vectorStore, dreamerConfig, globalWritePolicy) {
1258
+ const indexer = new BackgroundIndexer(config, getMessageDb, getLibraryDb, listAgents, getCursor, dreamerConfig, globalWritePolicy);
1259
+ if (vectorStore)
1260
+ indexer.setVectorStore(vectorStore);
1261
+ return indexer;
1262
+ }
1263
+ //# sourceMappingURL=background-indexer.js.map