@psiclawops/hypermem 0.8.5 → 0.9.1

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 (933) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +36 -1
  3. package/INSTALL.md +132 -9
  4. package/README.md +119 -272
  5. package/bench/README.md +42 -0
  6. package/bench/data-access-bench.mjs +380 -0
  7. package/bin/hypermem-bench.mjs +2 -0
  8. package/bin/hypermem-doctor.mjs +412 -0
  9. package/bin/hypermem-model-audit.mjs +339 -0
  10. package/bin/hypermem-status.mjs +491 -70
  11. package/docs/DIAGNOSTICS.md +205 -0
  12. package/docs/INTEGRATION_VALIDATION.md +186 -0
  13. package/docs/MIGRATION.md +9 -6
  14. package/docs/MIGRATION_GUIDE.md +125 -101
  15. package/docs/ROADMAP.md +247 -20
  16. package/docs/TUNING.md +19 -5
  17. package/install.sh +152 -401
  18. package/memory-plugin/LICENSE +190 -0
  19. package/memory-plugin/README.md +20 -0
  20. package/memory-plugin/package.json +3 -3
  21. package/package.json +19 -4
  22. package/plugin/LICENSE +190 -0
  23. package/plugin/README.md +20 -0
  24. package/plugin/package.json +4 -4
  25. package/scripts/install-runtime.mjs +12 -1
  26. package/dist/background-indexer.d.ts +0 -161
  27. package/dist/background-indexer.d.ts.map +0 -1
  28. package/dist/background-indexer.js +0 -1263
  29. package/dist/budget-policy.d.ts +0 -22
  30. package/dist/budget-policy.d.ts.map +0 -1
  31. package/dist/budget-policy.js +0 -27
  32. package/dist/cache.d.ts +0 -147
  33. package/dist/cache.d.ts.map +0 -1
  34. package/dist/cache.js +0 -569
  35. package/dist/compaction-fence.d.ts +0 -97
  36. package/dist/compaction-fence.d.ts.map +0 -1
  37. package/dist/compaction-fence.js +0 -174
  38. package/dist/compositor-utils.d.ts +0 -31
  39. package/dist/compositor-utils.d.ts.map +0 -1
  40. package/dist/compositor-utils.js +0 -47
  41. package/dist/compositor.d.ts +0 -394
  42. package/dist/compositor.d.ts.map +0 -1
  43. package/dist/compositor.js +0 -3632
  44. package/dist/content-hash.d.ts +0 -43
  45. package/dist/content-hash.d.ts.map +0 -1
  46. package/dist/content-hash.js +0 -75
  47. package/dist/content-type-classifier.d.ts +0 -41
  48. package/dist/content-type-classifier.d.ts.map +0 -1
  49. package/dist/content-type-classifier.js +0 -181
  50. package/dist/context-backfill.d.ts +0 -46
  51. package/dist/context-backfill.d.ts.map +0 -1
  52. package/dist/context-backfill.js +0 -113
  53. package/dist/context-store.d.ts +0 -131
  54. package/dist/context-store.d.ts.map +0 -1
  55. package/dist/context-store.js +0 -279
  56. package/dist/contradiction-audit-store.d.ts +0 -54
  57. package/dist/contradiction-audit-store.d.ts.map +0 -1
  58. package/dist/contradiction-audit-store.js +0 -88
  59. package/dist/contradiction-detector.d.ts +0 -78
  60. package/dist/contradiction-detector.d.ts.map +0 -1
  61. package/dist/contradiction-detector.js +0 -362
  62. package/dist/contradiction-resolution-policy.d.ts +0 -21
  63. package/dist/contradiction-resolution-policy.d.ts.map +0 -1
  64. package/dist/contradiction-resolution-policy.js +0 -17
  65. package/dist/cross-agent.d.ts +0 -74
  66. package/dist/cross-agent.d.ts.map +0 -1
  67. package/dist/cross-agent.js +0 -271
  68. package/dist/db.d.ts +0 -131
  69. package/dist/db.d.ts.map +0 -1
  70. package/dist/db.js +0 -410
  71. package/dist/degradation.d.ts +0 -102
  72. package/dist/degradation.d.ts.map +0 -1
  73. package/dist/degradation.js +0 -141
  74. package/dist/desired-state-store.d.ts +0 -100
  75. package/dist/desired-state-store.d.ts.map +0 -1
  76. package/dist/desired-state-store.js +0 -222
  77. package/dist/doc-chunk-store.d.ts +0 -140
  78. package/dist/doc-chunk-store.d.ts.map +0 -1
  79. package/dist/doc-chunk-store.js +0 -391
  80. package/dist/doc-chunker.d.ts +0 -99
  81. package/dist/doc-chunker.d.ts.map +0 -1
  82. package/dist/doc-chunker.js +0 -324
  83. package/dist/dreaming-promoter.d.ts +0 -124
  84. package/dist/dreaming-promoter.d.ts.map +0 -1
  85. package/dist/dreaming-promoter.js +0 -447
  86. package/dist/episode-store.d.ts +0 -49
  87. package/dist/episode-store.d.ts.map +0 -1
  88. package/dist/episode-store.js +0 -135
  89. package/dist/expertise-store.d.ts +0 -129
  90. package/dist/expertise-store.d.ts.map +0 -1
  91. package/dist/expertise-store.js +0 -342
  92. package/dist/fact-store.d.ts +0 -90
  93. package/dist/fact-store.d.ts.map +0 -1
  94. package/dist/fact-store.js +0 -283
  95. package/dist/fleet-store.d.ts +0 -144
  96. package/dist/fleet-store.d.ts.map +0 -1
  97. package/dist/fleet-store.js +0 -276
  98. package/dist/fos-mod.d.ts +0 -178
  99. package/dist/fos-mod.d.ts.map +0 -1
  100. package/dist/fos-mod.js +0 -416
  101. package/dist/hybrid-retrieval.d.ts +0 -64
  102. package/dist/hybrid-retrieval.d.ts.map +0 -1
  103. package/dist/hybrid-retrieval.js +0 -344
  104. package/dist/image-eviction.d.ts +0 -49
  105. package/dist/image-eviction.d.ts.map +0 -1
  106. package/dist/image-eviction.js +0 -251
  107. package/dist/index.d.ts +0 -718
  108. package/dist/index.d.ts.map +0 -1
  109. package/dist/index.js +0 -1469
  110. package/dist/keystone-scorer.d.ts +0 -51
  111. package/dist/keystone-scorer.d.ts.map +0 -1
  112. package/dist/keystone-scorer.js +0 -52
  113. package/dist/knowledge-graph.d.ts +0 -110
  114. package/dist/knowledge-graph.d.ts.map +0 -1
  115. package/dist/knowledge-graph.js +0 -305
  116. package/dist/knowledge-lint.d.ts +0 -31
  117. package/dist/knowledge-lint.d.ts.map +0 -1
  118. package/dist/knowledge-lint.js +0 -155
  119. package/dist/knowledge-store.d.ts +0 -72
  120. package/dist/knowledge-store.d.ts.map +0 -1
  121. package/dist/knowledge-store.js +0 -247
  122. package/dist/library-schema.d.ts +0 -27
  123. package/dist/library-schema.d.ts.map +0 -1
  124. package/dist/library-schema.js +0 -1343
  125. package/dist/message-store.d.ts +0 -181
  126. package/dist/message-store.d.ts.map +0 -1
  127. package/dist/message-store.js +0 -573
  128. package/dist/metrics-dashboard.d.ts +0 -114
  129. package/dist/metrics-dashboard.d.ts.map +0 -1
  130. package/dist/metrics-dashboard.js +0 -260
  131. package/dist/obsidian-exporter.d.ts +0 -57
  132. package/dist/obsidian-exporter.d.ts.map +0 -1
  133. package/dist/obsidian-exporter.js +0 -274
  134. package/dist/obsidian-watcher.d.ts +0 -147
  135. package/dist/obsidian-watcher.d.ts.map +0 -1
  136. package/dist/obsidian-watcher.js +0 -403
  137. package/dist/open-domain.d.ts +0 -46
  138. package/dist/open-domain.d.ts.map +0 -1
  139. package/dist/open-domain.js +0 -125
  140. package/dist/preference-store.d.ts +0 -54
  141. package/dist/preference-store.d.ts.map +0 -1
  142. package/dist/preference-store.js +0 -109
  143. package/dist/preservation-gate.d.ts +0 -82
  144. package/dist/preservation-gate.d.ts.map +0 -1
  145. package/dist/preservation-gate.js +0 -150
  146. package/dist/proactive-pass.d.ts +0 -63
  147. package/dist/proactive-pass.d.ts.map +0 -1
  148. package/dist/proactive-pass.js +0 -293
  149. package/dist/profiles.d.ts +0 -46
  150. package/dist/profiles.d.ts.map +0 -1
  151. package/dist/profiles.js +0 -262
  152. package/dist/provider-translator.d.ts +0 -50
  153. package/dist/provider-translator.d.ts.map +0 -1
  154. package/dist/provider-translator.js +0 -403
  155. package/dist/rate-limiter.d.ts +0 -76
  156. package/dist/rate-limiter.d.ts.map +0 -1
  157. package/dist/rate-limiter.js +0 -179
  158. package/dist/repair-tool-pairs.d.ts +0 -38
  159. package/dist/repair-tool-pairs.d.ts.map +0 -1
  160. package/dist/repair-tool-pairs.js +0 -209
  161. package/dist/replay-recovery.d.ts +0 -29
  162. package/dist/replay-recovery.d.ts.map +0 -1
  163. package/dist/replay-recovery.js +0 -82
  164. package/dist/reranker.d.ts +0 -95
  165. package/dist/reranker.d.ts.map +0 -1
  166. package/dist/reranker.js +0 -308
  167. package/dist/retrieval-policy.d.ts +0 -51
  168. package/dist/retrieval-policy.d.ts.map +0 -1
  169. package/dist/retrieval-policy.js +0 -77
  170. package/dist/schema.d.ts +0 -15
  171. package/dist/schema.d.ts.map +0 -1
  172. package/dist/schema.js +0 -300
  173. package/dist/secret-scanner.d.ts +0 -51
  174. package/dist/secret-scanner.d.ts.map +0 -1
  175. package/dist/secret-scanner.js +0 -248
  176. package/dist/seed.d.ts +0 -108
  177. package/dist/seed.d.ts.map +0 -1
  178. package/dist/seed.js +0 -177
  179. package/dist/session-flusher.d.ts +0 -53
  180. package/dist/session-flusher.d.ts.map +0 -1
  181. package/dist/session-flusher.js +0 -69
  182. package/dist/session-topic-map.d.ts +0 -41
  183. package/dist/session-topic-map.d.ts.map +0 -1
  184. package/dist/session-topic-map.js +0 -77
  185. package/dist/spawn-context.d.ts +0 -54
  186. package/dist/spawn-context.d.ts.map +0 -1
  187. package/dist/spawn-context.js +0 -159
  188. package/dist/system-store.d.ts +0 -73
  189. package/dist/system-store.d.ts.map +0 -1
  190. package/dist/system-store.js +0 -182
  191. package/dist/temporal-store.d.ts +0 -81
  192. package/dist/temporal-store.d.ts.map +0 -1
  193. package/dist/temporal-store.js +0 -149
  194. package/dist/tool-artifact-store.d.ts +0 -98
  195. package/dist/tool-artifact-store.d.ts.map +0 -1
  196. package/dist/tool-artifact-store.js +0 -244
  197. package/dist/topic-detector.d.ts +0 -35
  198. package/dist/topic-detector.d.ts.map +0 -1
  199. package/dist/topic-detector.js +0 -249
  200. package/dist/topic-store.d.ts +0 -51
  201. package/dist/topic-store.d.ts.map +0 -1
  202. package/dist/topic-store.js +0 -175
  203. package/dist/topic-synthesizer.d.ts +0 -51
  204. package/dist/topic-synthesizer.d.ts.map +0 -1
  205. package/dist/topic-synthesizer.js +0 -316
  206. package/dist/trigger-registry.d.ts +0 -63
  207. package/dist/trigger-registry.d.ts.map +0 -1
  208. package/dist/trigger-registry.js +0 -163
  209. package/dist/types.d.ts +0 -815
  210. package/dist/types.d.ts.map +0 -1
  211. package/dist/types.js +0 -9
  212. package/dist/vector-store.d.ts +0 -180
  213. package/dist/vector-store.d.ts.map +0 -1
  214. package/dist/vector-store.js +0 -1041
  215. package/dist/version.d.ts +0 -34
  216. package/dist/version.d.ts.map +0 -1
  217. package/dist/version.js +0 -34
  218. package/dist/wiki-page-emitter.d.ts +0 -65
  219. package/dist/wiki-page-emitter.d.ts.map +0 -1
  220. package/dist/wiki-page-emitter.js +0 -258
  221. package/dist/work-store.d.ts +0 -112
  222. package/dist/work-store.d.ts.map +0 -1
  223. package/dist/work-store.js +0 -273
  224. package/memory-plugin/dist/index.d.ts +0 -24
  225. package/memory-plugin/dist/index.d.ts.map +0 -1
  226. package/memory-plugin/dist/index.js +0 -300
  227. package/memory-plugin/dist/index.js.map +0 -1
  228. package/node_modules/sqlite-vec/README.md +0 -1
  229. package/node_modules/sqlite-vec/index.cjs +0 -46
  230. package/node_modules/sqlite-vec/index.d.ts +0 -17
  231. package/node_modules/sqlite-vec/index.mjs +0 -47
  232. package/node_modules/sqlite-vec/package.json +0 -1
  233. package/node_modules/sqlite-vec-linux-x64/README.md +0 -1
  234. package/node_modules/sqlite-vec-linux-x64/package.json +0 -1
  235. package/node_modules/sqlite-vec-linux-x64/vec0.so +0 -0
  236. package/node_modules/zod/LICENSE +0 -21
  237. package/node_modules/zod/README.md +0 -208
  238. package/node_modules/zod/index.cjs +0 -33
  239. package/node_modules/zod/index.d.cts +0 -4
  240. package/node_modules/zod/index.d.ts +0 -4
  241. package/node_modules/zod/index.js +0 -4
  242. package/node_modules/zod/locales/index.cjs +0 -17
  243. package/node_modules/zod/locales/index.d.cts +0 -1
  244. package/node_modules/zod/locales/index.d.ts +0 -1
  245. package/node_modules/zod/locales/index.js +0 -1
  246. package/node_modules/zod/locales/package.json +0 -6
  247. package/node_modules/zod/mini/index.cjs +0 -32
  248. package/node_modules/zod/mini/index.d.cts +0 -3
  249. package/node_modules/zod/mini/index.d.ts +0 -3
  250. package/node_modules/zod/mini/index.js +0 -3
  251. package/node_modules/zod/mini/package.json +0 -6
  252. package/node_modules/zod/package.json +0 -135
  253. package/node_modules/zod/src/index.ts +0 -4
  254. package/node_modules/zod/src/locales/index.ts +0 -1
  255. package/node_modules/zod/src/mini/index.ts +0 -3
  256. package/node_modules/zod/src/v3/ZodError.ts +0 -330
  257. package/node_modules/zod/src/v3/benchmarks/datetime.ts +0 -58
  258. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +0 -80
  259. package/node_modules/zod/src/v3/benchmarks/index.ts +0 -59
  260. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +0 -57
  261. package/node_modules/zod/src/v3/benchmarks/object.ts +0 -69
  262. package/node_modules/zod/src/v3/benchmarks/primitives.ts +0 -162
  263. package/node_modules/zod/src/v3/benchmarks/realworld.ts +0 -63
  264. package/node_modules/zod/src/v3/benchmarks/string.ts +0 -55
  265. package/node_modules/zod/src/v3/benchmarks/union.ts +0 -80
  266. package/node_modules/zod/src/v3/errors.ts +0 -13
  267. package/node_modules/zod/src/v3/external.ts +0 -6
  268. package/node_modules/zod/src/v3/helpers/enumUtil.ts +0 -17
  269. package/node_modules/zod/src/v3/helpers/errorUtil.ts +0 -8
  270. package/node_modules/zod/src/v3/helpers/parseUtil.ts +0 -176
  271. package/node_modules/zod/src/v3/helpers/partialUtil.ts +0 -34
  272. package/node_modules/zod/src/v3/helpers/typeAliases.ts +0 -2
  273. package/node_modules/zod/src/v3/helpers/util.ts +0 -224
  274. package/node_modules/zod/src/v3/index.ts +0 -4
  275. package/node_modules/zod/src/v3/locales/en.ts +0 -124
  276. package/node_modules/zod/src/v3/standard-schema.ts +0 -113
  277. package/node_modules/zod/src/v3/tests/Mocker.ts +0 -54
  278. package/node_modules/zod/src/v3/tests/all-errors.test.ts +0 -157
  279. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +0 -28
  280. package/node_modules/zod/src/v3/tests/array.test.ts +0 -71
  281. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +0 -388
  282. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +0 -46
  283. package/node_modules/zod/src/v3/tests/base.test.ts +0 -29
  284. package/node_modules/zod/src/v3/tests/bigint.test.ts +0 -55
  285. package/node_modules/zod/src/v3/tests/branded.test.ts +0 -53
  286. package/node_modules/zod/src/v3/tests/catch.test.ts +0 -220
  287. package/node_modules/zod/src/v3/tests/coerce.test.ts +0 -133
  288. package/node_modules/zod/src/v3/tests/complex.test.ts +0 -70
  289. package/node_modules/zod/src/v3/tests/custom.test.ts +0 -31
  290. package/node_modules/zod/src/v3/tests/date.test.ts +0 -32
  291. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +0 -186
  292. package/node_modules/zod/src/v3/tests/default.test.ts +0 -112
  293. package/node_modules/zod/src/v3/tests/description.test.ts +0 -33
  294. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +0 -315
  295. package/node_modules/zod/src/v3/tests/enum.test.ts +0 -80
  296. package/node_modules/zod/src/v3/tests/error.test.ts +0 -551
  297. package/node_modules/zod/src/v3/tests/firstparty.test.ts +0 -87
  298. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +0 -21
  299. package/node_modules/zod/src/v3/tests/function.test.ts +0 -261
  300. package/node_modules/zod/src/v3/tests/generics.test.ts +0 -48
  301. package/node_modules/zod/src/v3/tests/instanceof.test.ts +0 -37
  302. package/node_modules/zod/src/v3/tests/intersection.test.ts +0 -110
  303. package/node_modules/zod/src/v3/tests/language-server.source.ts +0 -76
  304. package/node_modules/zod/src/v3/tests/language-server.test.ts +0 -207
  305. package/node_modules/zod/src/v3/tests/literal.test.ts +0 -36
  306. package/node_modules/zod/src/v3/tests/map.test.ts +0 -110
  307. package/node_modules/zod/src/v3/tests/masking.test.ts +0 -4
  308. package/node_modules/zod/src/v3/tests/mocker.test.ts +0 -19
  309. package/node_modules/zod/src/v3/tests/nan.test.ts +0 -24
  310. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +0 -87
  311. package/node_modules/zod/src/v3/tests/nullable.test.ts +0 -42
  312. package/node_modules/zod/src/v3/tests/number.test.ts +0 -176
  313. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +0 -29
  314. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +0 -29
  315. package/node_modules/zod/src/v3/tests/object.test.ts +0 -434
  316. package/node_modules/zod/src/v3/tests/optional.test.ts +0 -42
  317. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +0 -23
  318. package/node_modules/zod/src/v3/tests/parser.test.ts +0 -41
  319. package/node_modules/zod/src/v3/tests/partials.test.ts +0 -243
  320. package/node_modules/zod/src/v3/tests/pickomit.test.ts +0 -111
  321. package/node_modules/zod/src/v3/tests/pipeline.test.ts +0 -29
  322. package/node_modules/zod/src/v3/tests/preprocess.test.ts +0 -186
  323. package/node_modules/zod/src/v3/tests/primitive.test.ts +0 -440
  324. package/node_modules/zod/src/v3/tests/promise.test.ts +0 -90
  325. package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -194
  326. package/node_modules/zod/src/v3/tests/record.test.ts +0 -171
  327. package/node_modules/zod/src/v3/tests/recursive.test.ts +0 -197
  328. package/node_modules/zod/src/v3/tests/refine.test.ts +0 -313
  329. package/node_modules/zod/src/v3/tests/safeparse.test.ts +0 -27
  330. package/node_modules/zod/src/v3/tests/set.test.ts +0 -142
  331. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +0 -83
  332. package/node_modules/zod/src/v3/tests/string.test.ts +0 -916
  333. package/node_modules/zod/src/v3/tests/transformer.test.ts +0 -233
  334. package/node_modules/zod/src/v3/tests/tuple.test.ts +0 -90
  335. package/node_modules/zod/src/v3/tests/unions.test.ts +0 -57
  336. package/node_modules/zod/src/v3/tests/validations.test.ts +0 -133
  337. package/node_modules/zod/src/v3/tests/void.test.ts +0 -15
  338. package/node_modules/zod/src/v3/types.ts +0 -5138
  339. package/node_modules/zod/src/v4/classic/checks.ts +0 -32
  340. package/node_modules/zod/src/v4/classic/coerce.ts +0 -27
  341. package/node_modules/zod/src/v4/classic/compat.ts +0 -70
  342. package/node_modules/zod/src/v4/classic/errors.ts +0 -82
  343. package/node_modules/zod/src/v4/classic/external.ts +0 -51
  344. package/node_modules/zod/src/v4/classic/from-json-schema.ts +0 -643
  345. package/node_modules/zod/src/v4/classic/index.ts +0 -5
  346. package/node_modules/zod/src/v4/classic/iso.ts +0 -90
  347. package/node_modules/zod/src/v4/classic/parse.ts +0 -82
  348. package/node_modules/zod/src/v4/classic/schemas.ts +0 -2409
  349. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +0 -26
  350. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +0 -59
  351. package/node_modules/zod/src/v4/classic/tests/array.test.ts +0 -264
  352. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +0 -210
  353. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +0 -381
  354. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +0 -68
  355. package/node_modules/zod/src/v4/classic/tests/base.test.ts +0 -7
  356. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +0 -54
  357. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +0 -106
  358. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +0 -276
  359. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +0 -20
  360. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +0 -573
  361. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +0 -562
  362. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +0 -160
  363. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +0 -374
  364. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +0 -40
  365. package/node_modules/zod/src/v4/classic/tests/date.test.ts +0 -62
  366. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +0 -302
  367. package/node_modules/zod/src/v4/classic/tests/default.test.ts +0 -365
  368. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +0 -27
  369. package/node_modules/zod/src/v4/classic/tests/description.test.ts +0 -32
  370. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +0 -661
  371. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +0 -285
  372. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +0 -595
  373. package/node_modules/zod/src/v4/classic/tests/error.test.ts +0 -711
  374. package/node_modules/zod/src/v4/classic/tests/file.test.ts +0 -96
  375. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +0 -179
  376. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +0 -26
  377. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +0 -734
  378. package/node_modules/zod/src/v4/classic/tests/function.test.ts +0 -360
  379. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +0 -72
  380. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +0 -68
  381. package/node_modules/zod/src/v4/classic/tests/index.test.ts +0 -939
  382. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +0 -60
  383. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +0 -198
  384. package/node_modules/zod/src/v4/classic/tests/json.test.ts +0 -109
  385. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +0 -227
  386. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +0 -117
  387. package/node_modules/zod/src/v4/classic/tests/map.test.ts +0 -330
  388. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +0 -21
  389. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +0 -168
  390. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +0 -101
  391. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +0 -22
  392. package/node_modules/zod/src/v4/classic/tests/number.test.ts +0 -270
  393. package/node_modules/zod/src/v4/classic/tests/object.test.ts +0 -640
  394. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +0 -223
  395. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +0 -427
  396. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +0 -211
  397. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +0 -101
  398. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +0 -74
  399. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +0 -282
  400. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +0 -175
  401. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +0 -81
  402. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +0 -23
  403. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -252
  404. package/node_modules/zod/src/v4/classic/tests/record.test.ts +0 -632
  405. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +0 -582
  406. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +0 -570
  407. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +0 -243
  408. package/node_modules/zod/src/v4/classic/tests/set.test.ts +0 -181
  409. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +0 -134
  410. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +0 -125
  411. package/node_modules/zod/src/v4/classic/tests/string.test.ts +0 -1175
  412. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +0 -106
  413. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +0 -771
  414. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +0 -438
  415. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +0 -2990
  416. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +0 -361
  417. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +0 -183
  418. package/node_modules/zod/src/v4/classic/tests/union.test.ts +0 -219
  419. package/node_modules/zod/src/v4/classic/tests/url.test.ts +0 -13
  420. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +0 -283
  421. package/node_modules/zod/src/v4/classic/tests/void.test.ts +0 -12
  422. package/node_modules/zod/src/v4/core/api.ts +0 -1798
  423. package/node_modules/zod/src/v4/core/checks.ts +0 -1293
  424. package/node_modules/zod/src/v4/core/config.ts +0 -15
  425. package/node_modules/zod/src/v4/core/core.ts +0 -138
  426. package/node_modules/zod/src/v4/core/doc.ts +0 -44
  427. package/node_modules/zod/src/v4/core/errors.ts +0 -448
  428. package/node_modules/zod/src/v4/core/index.ts +0 -16
  429. package/node_modules/zod/src/v4/core/json-schema-generator.ts +0 -126
  430. package/node_modules/zod/src/v4/core/json-schema-processors.ts +0 -667
  431. package/node_modules/zod/src/v4/core/json-schema.ts +0 -147
  432. package/node_modules/zod/src/v4/core/parse.ts +0 -195
  433. package/node_modules/zod/src/v4/core/regexes.ts +0 -183
  434. package/node_modules/zod/src/v4/core/registries.ts +0 -105
  435. package/node_modules/zod/src/v4/core/schemas.ts +0 -4538
  436. package/node_modules/zod/src/v4/core/standard-schema.ts +0 -159
  437. package/node_modules/zod/src/v4/core/tests/extend.test.ts +0 -59
  438. package/node_modules/zod/src/v4/core/tests/index.test.ts +0 -46
  439. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +0 -124
  440. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +0 -22
  441. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +0 -181
  442. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +0 -379
  443. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +0 -46
  444. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +0 -128
  445. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +0 -69
  446. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +0 -83
  447. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +0 -67
  448. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +0 -45
  449. package/node_modules/zod/src/v4/core/to-json-schema.ts +0 -613
  450. package/node_modules/zod/src/v4/core/util.ts +0 -966
  451. package/node_modules/zod/src/v4/core/versions.ts +0 -5
  452. package/node_modules/zod/src/v4/core/zsf.ts +0 -323
  453. package/node_modules/zod/src/v4/index.ts +0 -4
  454. package/node_modules/zod/src/v4/locales/ar.ts +0 -115
  455. package/node_modules/zod/src/v4/locales/az.ts +0 -111
  456. package/node_modules/zod/src/v4/locales/be.ts +0 -176
  457. package/node_modules/zod/src/v4/locales/bg.ts +0 -128
  458. package/node_modules/zod/src/v4/locales/ca.ts +0 -116
  459. package/node_modules/zod/src/v4/locales/cs.ts +0 -118
  460. package/node_modules/zod/src/v4/locales/da.ts +0 -123
  461. package/node_modules/zod/src/v4/locales/de.ts +0 -116
  462. package/node_modules/zod/src/v4/locales/en.ts +0 -119
  463. package/node_modules/zod/src/v4/locales/eo.ts +0 -118
  464. package/node_modules/zod/src/v4/locales/es.ts +0 -141
  465. package/node_modules/zod/src/v4/locales/fa.ts +0 -126
  466. package/node_modules/zod/src/v4/locales/fi.ts +0 -121
  467. package/node_modules/zod/src/v4/locales/fr-CA.ts +0 -116
  468. package/node_modules/zod/src/v4/locales/fr.ts +0 -116
  469. package/node_modules/zod/src/v4/locales/he.ts +0 -246
  470. package/node_modules/zod/src/v4/locales/hu.ts +0 -117
  471. package/node_modules/zod/src/v4/locales/hy.ts +0 -164
  472. package/node_modules/zod/src/v4/locales/id.ts +0 -115
  473. package/node_modules/zod/src/v4/locales/index.ts +0 -49
  474. package/node_modules/zod/src/v4/locales/is.ts +0 -119
  475. package/node_modules/zod/src/v4/locales/it.ts +0 -116
  476. package/node_modules/zod/src/v4/locales/ja.ts +0 -114
  477. package/node_modules/zod/src/v4/locales/ka.ts +0 -123
  478. package/node_modules/zod/src/v4/locales/kh.ts +0 -7
  479. package/node_modules/zod/src/v4/locales/km.ts +0 -119
  480. package/node_modules/zod/src/v4/locales/ko.ts +0 -121
  481. package/node_modules/zod/src/v4/locales/lt.ts +0 -239
  482. package/node_modules/zod/src/v4/locales/mk.ts +0 -118
  483. package/node_modules/zod/src/v4/locales/ms.ts +0 -115
  484. package/node_modules/zod/src/v4/locales/nl.ts +0 -121
  485. package/node_modules/zod/src/v4/locales/no.ts +0 -116
  486. package/node_modules/zod/src/v4/locales/ota.ts +0 -117
  487. package/node_modules/zod/src/v4/locales/pl.ts +0 -118
  488. package/node_modules/zod/src/v4/locales/ps.ts +0 -126
  489. package/node_modules/zod/src/v4/locales/pt.ts +0 -116
  490. package/node_modules/zod/src/v4/locales/ru.ts +0 -176
  491. package/node_modules/zod/src/v4/locales/sl.ts +0 -118
  492. package/node_modules/zod/src/v4/locales/sv.ts +0 -119
  493. package/node_modules/zod/src/v4/locales/ta.ts +0 -118
  494. package/node_modules/zod/src/v4/locales/th.ts +0 -119
  495. package/node_modules/zod/src/v4/locales/tr.ts +0 -111
  496. package/node_modules/zod/src/v4/locales/ua.ts +0 -7
  497. package/node_modules/zod/src/v4/locales/uk.ts +0 -117
  498. package/node_modules/zod/src/v4/locales/ur.ts +0 -119
  499. package/node_modules/zod/src/v4/locales/uz.ts +0 -116
  500. package/node_modules/zod/src/v4/locales/vi.ts +0 -117
  501. package/node_modules/zod/src/v4/locales/yo.ts +0 -124
  502. package/node_modules/zod/src/v4/locales/zh-CN.ts +0 -116
  503. package/node_modules/zod/src/v4/locales/zh-TW.ts +0 -115
  504. package/node_modules/zod/src/v4/mini/checks.ts +0 -32
  505. package/node_modules/zod/src/v4/mini/coerce.ts +0 -27
  506. package/node_modules/zod/src/v4/mini/external.ts +0 -40
  507. package/node_modules/zod/src/v4/mini/index.ts +0 -3
  508. package/node_modules/zod/src/v4/mini/iso.ts +0 -66
  509. package/node_modules/zod/src/v4/mini/parse.ts +0 -14
  510. package/node_modules/zod/src/v4/mini/schemas.ts +0 -1916
  511. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +0 -24
  512. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +0 -129
  513. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +0 -94
  514. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +0 -144
  515. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +0 -529
  516. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +0 -36
  517. package/node_modules/zod/src/v4/mini/tests/error.test.ts +0 -22
  518. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +0 -5
  519. package/node_modules/zod/src/v4/mini/tests/index.test.ts +0 -963
  520. package/node_modules/zod/src/v4/mini/tests/number.test.ts +0 -95
  521. package/node_modules/zod/src/v4/mini/tests/object.test.ts +0 -227
  522. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +0 -43
  523. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +0 -275
  524. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +0 -50
  525. package/node_modules/zod/src/v4/mini/tests/string.test.ts +0 -347
  526. package/node_modules/zod/src/v4-mini/index.ts +0 -3
  527. package/node_modules/zod/v3/ZodError.cjs +0 -138
  528. package/node_modules/zod/v3/ZodError.d.cts +0 -164
  529. package/node_modules/zod/v3/ZodError.d.ts +0 -164
  530. package/node_modules/zod/v3/ZodError.js +0 -133
  531. package/node_modules/zod/v3/errors.cjs +0 -17
  532. package/node_modules/zod/v3/errors.d.cts +0 -5
  533. package/node_modules/zod/v3/errors.d.ts +0 -5
  534. package/node_modules/zod/v3/errors.js +0 -9
  535. package/node_modules/zod/v3/external.cjs +0 -22
  536. package/node_modules/zod/v3/external.d.cts +0 -6
  537. package/node_modules/zod/v3/external.d.ts +0 -6
  538. package/node_modules/zod/v3/external.js +0 -6
  539. package/node_modules/zod/v3/helpers/enumUtil.cjs +0 -2
  540. package/node_modules/zod/v3/helpers/enumUtil.d.cts +0 -8
  541. package/node_modules/zod/v3/helpers/enumUtil.d.ts +0 -8
  542. package/node_modules/zod/v3/helpers/enumUtil.js +0 -1
  543. package/node_modules/zod/v3/helpers/errorUtil.cjs +0 -9
  544. package/node_modules/zod/v3/helpers/errorUtil.d.cts +0 -9
  545. package/node_modules/zod/v3/helpers/errorUtil.d.ts +0 -9
  546. package/node_modules/zod/v3/helpers/errorUtil.js +0 -6
  547. package/node_modules/zod/v3/helpers/parseUtil.cjs +0 -124
  548. package/node_modules/zod/v3/helpers/parseUtil.d.cts +0 -78
  549. package/node_modules/zod/v3/helpers/parseUtil.d.ts +0 -78
  550. package/node_modules/zod/v3/helpers/parseUtil.js +0 -109
  551. package/node_modules/zod/v3/helpers/partialUtil.cjs +0 -2
  552. package/node_modules/zod/v3/helpers/partialUtil.d.cts +0 -8
  553. package/node_modules/zod/v3/helpers/partialUtil.d.ts +0 -8
  554. package/node_modules/zod/v3/helpers/partialUtil.js +0 -1
  555. package/node_modules/zod/v3/helpers/typeAliases.cjs +0 -2
  556. package/node_modules/zod/v3/helpers/typeAliases.d.cts +0 -2
  557. package/node_modules/zod/v3/helpers/typeAliases.d.ts +0 -2
  558. package/node_modules/zod/v3/helpers/typeAliases.js +0 -1
  559. package/node_modules/zod/v3/helpers/util.cjs +0 -137
  560. package/node_modules/zod/v3/helpers/util.d.cts +0 -85
  561. package/node_modules/zod/v3/helpers/util.d.ts +0 -85
  562. package/node_modules/zod/v3/helpers/util.js +0 -133
  563. package/node_modules/zod/v3/index.cjs +0 -33
  564. package/node_modules/zod/v3/index.d.cts +0 -4
  565. package/node_modules/zod/v3/index.d.ts +0 -4
  566. package/node_modules/zod/v3/index.js +0 -4
  567. package/node_modules/zod/v3/locales/en.cjs +0 -112
  568. package/node_modules/zod/v3/locales/en.d.cts +0 -3
  569. package/node_modules/zod/v3/locales/en.d.ts +0 -3
  570. package/node_modules/zod/v3/locales/en.js +0 -109
  571. package/node_modules/zod/v3/package.json +0 -6
  572. package/node_modules/zod/v3/standard-schema.cjs +0 -2
  573. package/node_modules/zod/v3/standard-schema.d.cts +0 -102
  574. package/node_modules/zod/v3/standard-schema.d.ts +0 -102
  575. package/node_modules/zod/v3/standard-schema.js +0 -1
  576. package/node_modules/zod/v3/types.cjs +0 -3777
  577. package/node_modules/zod/v3/types.d.cts +0 -1034
  578. package/node_modules/zod/v3/types.d.ts +0 -1034
  579. package/node_modules/zod/v3/types.js +0 -3695
  580. package/node_modules/zod/v4/classic/checks.cjs +0 -33
  581. package/node_modules/zod/v4/classic/checks.d.cts +0 -1
  582. package/node_modules/zod/v4/classic/checks.d.ts +0 -1
  583. package/node_modules/zod/v4/classic/checks.js +0 -1
  584. package/node_modules/zod/v4/classic/coerce.cjs +0 -47
  585. package/node_modules/zod/v4/classic/coerce.d.cts +0 -17
  586. package/node_modules/zod/v4/classic/coerce.d.ts +0 -17
  587. package/node_modules/zod/v4/classic/coerce.js +0 -17
  588. package/node_modules/zod/v4/classic/compat.cjs +0 -61
  589. package/node_modules/zod/v4/classic/compat.d.cts +0 -50
  590. package/node_modules/zod/v4/classic/compat.d.ts +0 -50
  591. package/node_modules/zod/v4/classic/compat.js +0 -31
  592. package/node_modules/zod/v4/classic/errors.cjs +0 -74
  593. package/node_modules/zod/v4/classic/errors.d.cts +0 -30
  594. package/node_modules/zod/v4/classic/errors.d.ts +0 -30
  595. package/node_modules/zod/v4/classic/errors.js +0 -48
  596. package/node_modules/zod/v4/classic/external.cjs +0 -73
  597. package/node_modules/zod/v4/classic/external.d.cts +0 -15
  598. package/node_modules/zod/v4/classic/external.d.ts +0 -15
  599. package/node_modules/zod/v4/classic/external.js +0 -20
  600. package/node_modules/zod/v4/classic/from-json-schema.cjs +0 -610
  601. package/node_modules/zod/v4/classic/from-json-schema.d.cts +0 -12
  602. package/node_modules/zod/v4/classic/from-json-schema.d.ts +0 -12
  603. package/node_modules/zod/v4/classic/from-json-schema.js +0 -584
  604. package/node_modules/zod/v4/classic/index.cjs +0 -33
  605. package/node_modules/zod/v4/classic/index.d.cts +0 -4
  606. package/node_modules/zod/v4/classic/index.d.ts +0 -4
  607. package/node_modules/zod/v4/classic/index.js +0 -4
  608. package/node_modules/zod/v4/classic/iso.cjs +0 -60
  609. package/node_modules/zod/v4/classic/iso.d.cts +0 -22
  610. package/node_modules/zod/v4/classic/iso.d.ts +0 -22
  611. package/node_modules/zod/v4/classic/iso.js +0 -30
  612. package/node_modules/zod/v4/classic/package.json +0 -6
  613. package/node_modules/zod/v4/classic/parse.cjs +0 -41
  614. package/node_modules/zod/v4/classic/parse.d.cts +0 -31
  615. package/node_modules/zod/v4/classic/parse.d.ts +0 -31
  616. package/node_modules/zod/v4/classic/parse.js +0 -15
  617. package/node_modules/zod/v4/classic/schemas.cjs +0 -1272
  618. package/node_modules/zod/v4/classic/schemas.d.cts +0 -739
  619. package/node_modules/zod/v4/classic/schemas.d.ts +0 -739
  620. package/node_modules/zod/v4/classic/schemas.js +0 -1157
  621. package/node_modules/zod/v4/core/api.cjs +0 -1222
  622. package/node_modules/zod/v4/core/api.d.cts +0 -304
  623. package/node_modules/zod/v4/core/api.d.ts +0 -304
  624. package/node_modules/zod/v4/core/api.js +0 -1082
  625. package/node_modules/zod/v4/core/checks.cjs +0 -601
  626. package/node_modules/zod/v4/core/checks.d.cts +0 -278
  627. package/node_modules/zod/v4/core/checks.d.ts +0 -278
  628. package/node_modules/zod/v4/core/checks.js +0 -575
  629. package/node_modules/zod/v4/core/core.cjs +0 -83
  630. package/node_modules/zod/v4/core/core.d.cts +0 -70
  631. package/node_modules/zod/v4/core/core.d.ts +0 -70
  632. package/node_modules/zod/v4/core/core.js +0 -76
  633. package/node_modules/zod/v4/core/doc.cjs +0 -39
  634. package/node_modules/zod/v4/core/doc.d.cts +0 -14
  635. package/node_modules/zod/v4/core/doc.d.ts +0 -14
  636. package/node_modules/zod/v4/core/doc.js +0 -35
  637. package/node_modules/zod/v4/core/errors.cjs +0 -213
  638. package/node_modules/zod/v4/core/errors.d.cts +0 -220
  639. package/node_modules/zod/v4/core/errors.d.ts +0 -220
  640. package/node_modules/zod/v4/core/errors.js +0 -182
  641. package/node_modules/zod/v4/core/index.cjs +0 -47
  642. package/node_modules/zod/v4/core/index.d.cts +0 -16
  643. package/node_modules/zod/v4/core/index.d.ts +0 -16
  644. package/node_modules/zod/v4/core/index.js +0 -16
  645. package/node_modules/zod/v4/core/json-schema-generator.cjs +0 -99
  646. package/node_modules/zod/v4/core/json-schema-generator.d.cts +0 -65
  647. package/node_modules/zod/v4/core/json-schema-generator.d.ts +0 -65
  648. package/node_modules/zod/v4/core/json-schema-generator.js +0 -95
  649. package/node_modules/zod/v4/core/json-schema-processors.cjs +0 -648
  650. package/node_modules/zod/v4/core/json-schema-processors.d.cts +0 -49
  651. package/node_modules/zod/v4/core/json-schema-processors.d.ts +0 -49
  652. package/node_modules/zod/v4/core/json-schema-processors.js +0 -605
  653. package/node_modules/zod/v4/core/json-schema.cjs +0 -2
  654. package/node_modules/zod/v4/core/json-schema.d.cts +0 -88
  655. package/node_modules/zod/v4/core/json-schema.d.ts +0 -88
  656. package/node_modules/zod/v4/core/json-schema.js +0 -1
  657. package/node_modules/zod/v4/core/package.json +0 -6
  658. package/node_modules/zod/v4/core/parse.cjs +0 -131
  659. package/node_modules/zod/v4/core/parse.d.cts +0 -49
  660. package/node_modules/zod/v4/core/parse.d.ts +0 -49
  661. package/node_modules/zod/v4/core/parse.js +0 -93
  662. package/node_modules/zod/v4/core/regexes.cjs +0 -166
  663. package/node_modules/zod/v4/core/regexes.d.cts +0 -79
  664. package/node_modules/zod/v4/core/regexes.d.ts +0 -79
  665. package/node_modules/zod/v4/core/regexes.js +0 -133
  666. package/node_modules/zod/v4/core/registries.cjs +0 -56
  667. package/node_modules/zod/v4/core/registries.d.cts +0 -35
  668. package/node_modules/zod/v4/core/registries.d.ts +0 -35
  669. package/node_modules/zod/v4/core/registries.js +0 -51
  670. package/node_modules/zod/v4/core/schemas.cjs +0 -2124
  671. package/node_modules/zod/v4/core/schemas.d.cts +0 -1146
  672. package/node_modules/zod/v4/core/schemas.d.ts +0 -1146
  673. package/node_modules/zod/v4/core/schemas.js +0 -2093
  674. package/node_modules/zod/v4/core/standard-schema.cjs +0 -2
  675. package/node_modules/zod/v4/core/standard-schema.d.cts +0 -126
  676. package/node_modules/zod/v4/core/standard-schema.d.ts +0 -126
  677. package/node_modules/zod/v4/core/standard-schema.js +0 -1
  678. package/node_modules/zod/v4/core/to-json-schema.cjs +0 -446
  679. package/node_modules/zod/v4/core/to-json-schema.d.cts +0 -114
  680. package/node_modules/zod/v4/core/to-json-schema.d.ts +0 -114
  681. package/node_modules/zod/v4/core/to-json-schema.js +0 -437
  682. package/node_modules/zod/v4/core/util.cjs +0 -710
  683. package/node_modules/zod/v4/core/util.d.cts +0 -199
  684. package/node_modules/zod/v4/core/util.d.ts +0 -199
  685. package/node_modules/zod/v4/core/util.js +0 -651
  686. package/node_modules/zod/v4/core/versions.cjs +0 -8
  687. package/node_modules/zod/v4/core/versions.d.cts +0 -5
  688. package/node_modules/zod/v4/core/versions.d.ts +0 -5
  689. package/node_modules/zod/v4/core/versions.js +0 -5
  690. package/node_modules/zod/v4/index.cjs +0 -22
  691. package/node_modules/zod/v4/index.d.cts +0 -3
  692. package/node_modules/zod/v4/index.d.ts +0 -3
  693. package/node_modules/zod/v4/index.js +0 -3
  694. package/node_modules/zod/v4/locales/ar.cjs +0 -133
  695. package/node_modules/zod/v4/locales/ar.d.cts +0 -5
  696. package/node_modules/zod/v4/locales/ar.d.ts +0 -4
  697. package/node_modules/zod/v4/locales/ar.js +0 -106
  698. package/node_modules/zod/v4/locales/az.cjs +0 -132
  699. package/node_modules/zod/v4/locales/az.d.cts +0 -5
  700. package/node_modules/zod/v4/locales/az.d.ts +0 -4
  701. package/node_modules/zod/v4/locales/az.js +0 -105
  702. package/node_modules/zod/v4/locales/be.cjs +0 -183
  703. package/node_modules/zod/v4/locales/be.d.cts +0 -5
  704. package/node_modules/zod/v4/locales/be.d.ts +0 -4
  705. package/node_modules/zod/v4/locales/be.js +0 -156
  706. package/node_modules/zod/v4/locales/bg.cjs +0 -147
  707. package/node_modules/zod/v4/locales/bg.d.cts +0 -5
  708. package/node_modules/zod/v4/locales/bg.d.ts +0 -4
  709. package/node_modules/zod/v4/locales/bg.js +0 -120
  710. package/node_modules/zod/v4/locales/ca.cjs +0 -134
  711. package/node_modules/zod/v4/locales/ca.d.cts +0 -5
  712. package/node_modules/zod/v4/locales/ca.d.ts +0 -4
  713. package/node_modules/zod/v4/locales/ca.js +0 -107
  714. package/node_modules/zod/v4/locales/cs.cjs +0 -138
  715. package/node_modules/zod/v4/locales/cs.d.cts +0 -5
  716. package/node_modules/zod/v4/locales/cs.d.ts +0 -4
  717. package/node_modules/zod/v4/locales/cs.js +0 -111
  718. package/node_modules/zod/v4/locales/da.cjs +0 -142
  719. package/node_modules/zod/v4/locales/da.d.cts +0 -5
  720. package/node_modules/zod/v4/locales/da.d.ts +0 -4
  721. package/node_modules/zod/v4/locales/da.js +0 -115
  722. package/node_modules/zod/v4/locales/de.cjs +0 -135
  723. package/node_modules/zod/v4/locales/de.d.cts +0 -5
  724. package/node_modules/zod/v4/locales/de.d.ts +0 -4
  725. package/node_modules/zod/v4/locales/de.js +0 -108
  726. package/node_modules/zod/v4/locales/en.cjs +0 -136
  727. package/node_modules/zod/v4/locales/en.d.cts +0 -5
  728. package/node_modules/zod/v4/locales/en.d.ts +0 -4
  729. package/node_modules/zod/v4/locales/en.js +0 -109
  730. package/node_modules/zod/v4/locales/eo.cjs +0 -136
  731. package/node_modules/zod/v4/locales/eo.d.cts +0 -5
  732. package/node_modules/zod/v4/locales/eo.d.ts +0 -4
  733. package/node_modules/zod/v4/locales/eo.js +0 -109
  734. package/node_modules/zod/v4/locales/es.cjs +0 -159
  735. package/node_modules/zod/v4/locales/es.d.cts +0 -5
  736. package/node_modules/zod/v4/locales/es.d.ts +0 -4
  737. package/node_modules/zod/v4/locales/es.js +0 -132
  738. package/node_modules/zod/v4/locales/fa.cjs +0 -141
  739. package/node_modules/zod/v4/locales/fa.d.cts +0 -5
  740. package/node_modules/zod/v4/locales/fa.d.ts +0 -4
  741. package/node_modules/zod/v4/locales/fa.js +0 -114
  742. package/node_modules/zod/v4/locales/fi.cjs +0 -139
  743. package/node_modules/zod/v4/locales/fi.d.cts +0 -5
  744. package/node_modules/zod/v4/locales/fi.d.ts +0 -4
  745. package/node_modules/zod/v4/locales/fi.js +0 -112
  746. package/node_modules/zod/v4/locales/fr-CA.cjs +0 -134
  747. package/node_modules/zod/v4/locales/fr-CA.d.cts +0 -5
  748. package/node_modules/zod/v4/locales/fr-CA.d.ts +0 -4
  749. package/node_modules/zod/v4/locales/fr-CA.js +0 -107
  750. package/node_modules/zod/v4/locales/fr.cjs +0 -135
  751. package/node_modules/zod/v4/locales/fr.d.cts +0 -5
  752. package/node_modules/zod/v4/locales/fr.d.ts +0 -4
  753. package/node_modules/zod/v4/locales/fr.js +0 -108
  754. package/node_modules/zod/v4/locales/he.cjs +0 -241
  755. package/node_modules/zod/v4/locales/he.d.cts +0 -5
  756. package/node_modules/zod/v4/locales/he.d.ts +0 -4
  757. package/node_modules/zod/v4/locales/he.js +0 -214
  758. package/node_modules/zod/v4/locales/hu.cjs +0 -135
  759. package/node_modules/zod/v4/locales/hu.d.cts +0 -5
  760. package/node_modules/zod/v4/locales/hu.d.ts +0 -4
  761. package/node_modules/zod/v4/locales/hu.js +0 -108
  762. package/node_modules/zod/v4/locales/hy.cjs +0 -174
  763. package/node_modules/zod/v4/locales/hy.d.cts +0 -5
  764. package/node_modules/zod/v4/locales/hy.d.ts +0 -4
  765. package/node_modules/zod/v4/locales/hy.js +0 -147
  766. package/node_modules/zod/v4/locales/id.cjs +0 -133
  767. package/node_modules/zod/v4/locales/id.d.cts +0 -5
  768. package/node_modules/zod/v4/locales/id.d.ts +0 -4
  769. package/node_modules/zod/v4/locales/id.js +0 -106
  770. package/node_modules/zod/v4/locales/index.cjs +0 -104
  771. package/node_modules/zod/v4/locales/index.d.cts +0 -49
  772. package/node_modules/zod/v4/locales/index.d.ts +0 -49
  773. package/node_modules/zod/v4/locales/index.js +0 -49
  774. package/node_modules/zod/v4/locales/is.cjs +0 -136
  775. package/node_modules/zod/v4/locales/is.d.cts +0 -5
  776. package/node_modules/zod/v4/locales/is.d.ts +0 -4
  777. package/node_modules/zod/v4/locales/is.js +0 -109
  778. package/node_modules/zod/v4/locales/it.cjs +0 -135
  779. package/node_modules/zod/v4/locales/it.d.cts +0 -5
  780. package/node_modules/zod/v4/locales/it.d.ts +0 -4
  781. package/node_modules/zod/v4/locales/it.js +0 -108
  782. package/node_modules/zod/v4/locales/ja.cjs +0 -134
  783. package/node_modules/zod/v4/locales/ja.d.cts +0 -5
  784. package/node_modules/zod/v4/locales/ja.d.ts +0 -4
  785. package/node_modules/zod/v4/locales/ja.js +0 -107
  786. package/node_modules/zod/v4/locales/ka.cjs +0 -139
  787. package/node_modules/zod/v4/locales/ka.d.cts +0 -5
  788. package/node_modules/zod/v4/locales/ka.d.ts +0 -4
  789. package/node_modules/zod/v4/locales/ka.js +0 -112
  790. package/node_modules/zod/v4/locales/kh.cjs +0 -12
  791. package/node_modules/zod/v4/locales/kh.d.cts +0 -5
  792. package/node_modules/zod/v4/locales/kh.d.ts +0 -5
  793. package/node_modules/zod/v4/locales/kh.js +0 -5
  794. package/node_modules/zod/v4/locales/km.cjs +0 -137
  795. package/node_modules/zod/v4/locales/km.d.cts +0 -5
  796. package/node_modules/zod/v4/locales/km.d.ts +0 -4
  797. package/node_modules/zod/v4/locales/km.js +0 -110
  798. package/node_modules/zod/v4/locales/ko.cjs +0 -138
  799. package/node_modules/zod/v4/locales/ko.d.cts +0 -5
  800. package/node_modules/zod/v4/locales/ko.d.ts +0 -4
  801. package/node_modules/zod/v4/locales/ko.js +0 -111
  802. package/node_modules/zod/v4/locales/lt.cjs +0 -230
  803. package/node_modules/zod/v4/locales/lt.d.cts +0 -5
  804. package/node_modules/zod/v4/locales/lt.d.ts +0 -4
  805. package/node_modules/zod/v4/locales/lt.js +0 -203
  806. package/node_modules/zod/v4/locales/mk.cjs +0 -136
  807. package/node_modules/zod/v4/locales/mk.d.cts +0 -5
  808. package/node_modules/zod/v4/locales/mk.d.ts +0 -4
  809. package/node_modules/zod/v4/locales/mk.js +0 -109
  810. package/node_modules/zod/v4/locales/ms.cjs +0 -134
  811. package/node_modules/zod/v4/locales/ms.d.cts +0 -5
  812. package/node_modules/zod/v4/locales/ms.d.ts +0 -4
  813. package/node_modules/zod/v4/locales/ms.js +0 -107
  814. package/node_modules/zod/v4/locales/nl.cjs +0 -137
  815. package/node_modules/zod/v4/locales/nl.d.cts +0 -5
  816. package/node_modules/zod/v4/locales/nl.d.ts +0 -4
  817. package/node_modules/zod/v4/locales/nl.js +0 -110
  818. package/node_modules/zod/v4/locales/no.cjs +0 -135
  819. package/node_modules/zod/v4/locales/no.d.cts +0 -5
  820. package/node_modules/zod/v4/locales/no.d.ts +0 -4
  821. package/node_modules/zod/v4/locales/no.js +0 -108
  822. package/node_modules/zod/v4/locales/ota.cjs +0 -136
  823. package/node_modules/zod/v4/locales/ota.d.cts +0 -5
  824. package/node_modules/zod/v4/locales/ota.d.ts +0 -4
  825. package/node_modules/zod/v4/locales/ota.js +0 -109
  826. package/node_modules/zod/v4/locales/package.json +0 -6
  827. package/node_modules/zod/v4/locales/pl.cjs +0 -136
  828. package/node_modules/zod/v4/locales/pl.d.cts +0 -5
  829. package/node_modules/zod/v4/locales/pl.d.ts +0 -4
  830. package/node_modules/zod/v4/locales/pl.js +0 -109
  831. package/node_modules/zod/v4/locales/ps.cjs +0 -141
  832. package/node_modules/zod/v4/locales/ps.d.cts +0 -5
  833. package/node_modules/zod/v4/locales/ps.d.ts +0 -4
  834. package/node_modules/zod/v4/locales/ps.js +0 -114
  835. package/node_modules/zod/v4/locales/pt.cjs +0 -135
  836. package/node_modules/zod/v4/locales/pt.d.cts +0 -5
  837. package/node_modules/zod/v4/locales/pt.d.ts +0 -4
  838. package/node_modules/zod/v4/locales/pt.js +0 -108
  839. package/node_modules/zod/v4/locales/ru.cjs +0 -183
  840. package/node_modules/zod/v4/locales/ru.d.cts +0 -5
  841. package/node_modules/zod/v4/locales/ru.d.ts +0 -4
  842. package/node_modules/zod/v4/locales/ru.js +0 -156
  843. package/node_modules/zod/v4/locales/sl.cjs +0 -136
  844. package/node_modules/zod/v4/locales/sl.d.cts +0 -5
  845. package/node_modules/zod/v4/locales/sl.d.ts +0 -4
  846. package/node_modules/zod/v4/locales/sl.js +0 -109
  847. package/node_modules/zod/v4/locales/sv.cjs +0 -137
  848. package/node_modules/zod/v4/locales/sv.d.cts +0 -5
  849. package/node_modules/zod/v4/locales/sv.d.ts +0 -4
  850. package/node_modules/zod/v4/locales/sv.js +0 -110
  851. package/node_modules/zod/v4/locales/ta.cjs +0 -137
  852. package/node_modules/zod/v4/locales/ta.d.cts +0 -5
  853. package/node_modules/zod/v4/locales/ta.d.ts +0 -4
  854. package/node_modules/zod/v4/locales/ta.js +0 -110
  855. package/node_modules/zod/v4/locales/th.cjs +0 -137
  856. package/node_modules/zod/v4/locales/th.d.cts +0 -5
  857. package/node_modules/zod/v4/locales/th.d.ts +0 -4
  858. package/node_modules/zod/v4/locales/th.js +0 -110
  859. package/node_modules/zod/v4/locales/tr.cjs +0 -132
  860. package/node_modules/zod/v4/locales/tr.d.cts +0 -5
  861. package/node_modules/zod/v4/locales/tr.d.ts +0 -4
  862. package/node_modules/zod/v4/locales/tr.js +0 -105
  863. package/node_modules/zod/v4/locales/ua.cjs +0 -12
  864. package/node_modules/zod/v4/locales/ua.d.cts +0 -5
  865. package/node_modules/zod/v4/locales/ua.d.ts +0 -5
  866. package/node_modules/zod/v4/locales/ua.js +0 -5
  867. package/node_modules/zod/v4/locales/uk.cjs +0 -135
  868. package/node_modules/zod/v4/locales/uk.d.cts +0 -5
  869. package/node_modules/zod/v4/locales/uk.d.ts +0 -4
  870. package/node_modules/zod/v4/locales/uk.js +0 -108
  871. package/node_modules/zod/v4/locales/ur.cjs +0 -137
  872. package/node_modules/zod/v4/locales/ur.d.cts +0 -5
  873. package/node_modules/zod/v4/locales/ur.d.ts +0 -4
  874. package/node_modules/zod/v4/locales/ur.js +0 -110
  875. package/node_modules/zod/v4/locales/uz.cjs +0 -136
  876. package/node_modules/zod/v4/locales/uz.d.cts +0 -5
  877. package/node_modules/zod/v4/locales/uz.d.ts +0 -4
  878. package/node_modules/zod/v4/locales/uz.js +0 -109
  879. package/node_modules/zod/v4/locales/vi.cjs +0 -135
  880. package/node_modules/zod/v4/locales/vi.d.cts +0 -5
  881. package/node_modules/zod/v4/locales/vi.d.ts +0 -4
  882. package/node_modules/zod/v4/locales/vi.js +0 -108
  883. package/node_modules/zod/v4/locales/yo.cjs +0 -134
  884. package/node_modules/zod/v4/locales/yo.d.cts +0 -5
  885. package/node_modules/zod/v4/locales/yo.d.ts +0 -4
  886. package/node_modules/zod/v4/locales/yo.js +0 -107
  887. package/node_modules/zod/v4/locales/zh-CN.cjs +0 -136
  888. package/node_modules/zod/v4/locales/zh-CN.d.cts +0 -5
  889. package/node_modules/zod/v4/locales/zh-CN.d.ts +0 -4
  890. package/node_modules/zod/v4/locales/zh-CN.js +0 -109
  891. package/node_modules/zod/v4/locales/zh-TW.cjs +0 -134
  892. package/node_modules/zod/v4/locales/zh-TW.d.cts +0 -5
  893. package/node_modules/zod/v4/locales/zh-TW.d.ts +0 -4
  894. package/node_modules/zod/v4/locales/zh-TW.js +0 -107
  895. package/node_modules/zod/v4/mini/checks.cjs +0 -34
  896. package/node_modules/zod/v4/mini/checks.d.cts +0 -1
  897. package/node_modules/zod/v4/mini/checks.d.ts +0 -1
  898. package/node_modules/zod/v4/mini/checks.js +0 -1
  899. package/node_modules/zod/v4/mini/coerce.cjs +0 -52
  900. package/node_modules/zod/v4/mini/coerce.d.cts +0 -7
  901. package/node_modules/zod/v4/mini/coerce.d.ts +0 -7
  902. package/node_modules/zod/v4/mini/coerce.js +0 -22
  903. package/node_modules/zod/v4/mini/external.cjs +0 -63
  904. package/node_modules/zod/v4/mini/external.d.cts +0 -12
  905. package/node_modules/zod/v4/mini/external.d.ts +0 -12
  906. package/node_modules/zod/v4/mini/external.js +0 -14
  907. package/node_modules/zod/v4/mini/index.cjs +0 -32
  908. package/node_modules/zod/v4/mini/index.d.cts +0 -3
  909. package/node_modules/zod/v4/mini/index.d.ts +0 -3
  910. package/node_modules/zod/v4/mini/index.js +0 -3
  911. package/node_modules/zod/v4/mini/iso.cjs +0 -64
  912. package/node_modules/zod/v4/mini/iso.d.cts +0 -22
  913. package/node_modules/zod/v4/mini/iso.d.ts +0 -22
  914. package/node_modules/zod/v4/mini/iso.js +0 -34
  915. package/node_modules/zod/v4/mini/package.json +0 -6
  916. package/node_modules/zod/v4/mini/parse.cjs +0 -16
  917. package/node_modules/zod/v4/mini/parse.d.cts +0 -1
  918. package/node_modules/zod/v4/mini/parse.d.ts +0 -1
  919. package/node_modules/zod/v4/mini/parse.js +0 -1
  920. package/node_modules/zod/v4/mini/schemas.cjs +0 -1046
  921. package/node_modules/zod/v4/mini/schemas.d.cts +0 -427
  922. package/node_modules/zod/v4/mini/schemas.d.ts +0 -427
  923. package/node_modules/zod/v4/mini/schemas.js +0 -925
  924. package/node_modules/zod/v4/package.json +0 -6
  925. package/node_modules/zod/v4-mini/index.cjs +0 -32
  926. package/node_modules/zod/v4-mini/index.d.cts +0 -3
  927. package/node_modules/zod/v4-mini/index.d.ts +0 -3
  928. package/node_modules/zod/v4-mini/index.js +0 -3
  929. package/node_modules/zod/v4-mini/package.json +0 -6
  930. package/plugin/dist/index.d.ts +0 -179
  931. package/plugin/dist/index.d.ts.map +0 -1
  932. package/plugin/dist/index.js +0 -3209
  933. package/plugin/dist/index.js.map +0 -1
@@ -1,1263 +0,0 @@
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 (alice, 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
- alice: 'infrastructure',
48
- director2: 'infrastructure',
49
- director1: 'infrastructure',
50
- director3: 'infrastructure',
51
- bob: 'product',
52
- director4: 'product',
53
- director5: 'product',
54
- director6: 'product',
55
- dave: 'security',
56
- director7: 'security',
57
- director8: 'security',
58
- agent4: 'ux',
59
- carol: 'governance',
60
- oscar: '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) (?: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+(carol|bob|agent4|dave|oscar|alice)/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|dashboard|canvas|council|automation|OpenClaw|dispatch)\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