nox-mem 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (397) hide show
  1. package/README.md +24 -16
  2. package/dist/__tests__/brief-diversity.test.js +266 -0
  3. package/dist/__tests__/brief.test.js +287 -0
  4. package/dist/__tests__/churn.test.js +66 -0
  5. package/dist/__tests__/edge-typing.test.js +99 -0
  6. package/dist/__tests__/ingest-event.test.js +151 -0
  7. package/dist/__tests__/op-audit-e2e.test.js +130 -0
  8. package/dist/__tests__/pragma-alignment.test.js +123 -0
  9. package/dist/__tests__/reranker.test.js +326 -0
  10. package/dist/__tests__/retention.test.js +99 -0
  11. package/dist/__tests__/search-track-access.test.js +49 -0
  12. package/dist/__tests__/spo-injection.test.js +172 -0
  13. package/dist/__tests__/temporal-detector.test.js +103 -0
  14. package/dist/api/wire-up.js +12 -381
  15. package/dist/api-server.js +6 -102
  16. package/dist/db.js +61 -2
  17. package/dist/embed.js +23 -2
  18. package/dist/index.js +1 -22
  19. package/dist/knowledge-graph.js +20 -0
  20. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  21. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  22. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  23. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  24. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  25. package/dist/lib/answer/provider.js +29 -4
  26. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  27. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  28. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  29. package/dist/lib/events/__tests__/bus.test.js +208 -0
  30. package/dist/lib/ingest-router.js +0 -43
  31. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  32. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  33. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  34. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  35. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  36. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  37. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  38. package/dist/privacy/__tests__/filter.test.js +352 -0
  39. package/dist/providers/__tests__/conformance-extended.test.js +249 -0
  40. package/dist/providers/__tests__/conformance.test.js +98 -0
  41. package/dist/providers/__tests__/cost-cap.test.js +151 -0
  42. package/dist/providers/__tests__/e2e-real.test.js +79 -0
  43. package/dist/providers/__tests__/factory.test.js +80 -0
  44. package/dist/providers/__tests__/fallback.test.js +223 -0
  45. package/dist/providers/__tests__/gemini.test.js +191 -0
  46. package/dist/providers/__tests__/health.test.js +128 -0
  47. package/dist/providers/__tests__/telemetry.test.js +219 -0
  48. package/dist/reindex.js +2 -2
  49. package/package.json +3 -4
  50. package/dist/api/answer.d.ts +0 -116
  51. package/dist/api/answer.validate-patch.d.ts +0 -72
  52. package/dist/api/brief-diversity.d.ts +0 -64
  53. package/dist/api/brief.d.ts +0 -114
  54. package/dist/api/conflict.d.ts +0 -33
  55. package/dist/api/conflict.js +0 -143
  56. package/dist/api/cors.d.ts +0 -73
  57. package/dist/api/events-stream-limited.d.ts +0 -133
  58. package/dist/api/events-stream-limited.js +0 -217
  59. package/dist/api/events-stream.d.ts +0 -53
  60. package/dist/api/events-stream.js +0 -125
  61. package/dist/api/export.d.ts +0 -42
  62. package/dist/api/export.js +0 -85
  63. package/dist/api/health-confidence-adapter.d.ts +0 -29
  64. package/dist/api/health-confidence-adapter.js +0 -73
  65. package/dist/api/health-confidence.d.ts +0 -36
  66. package/dist/api/health-confidence.js +0 -141
  67. package/dist/api/hooks.d.ts +0 -50
  68. package/dist/api/hooks.js +0 -115
  69. package/dist/api/import.d.ts +0 -38
  70. package/dist/api/import.js +0 -87
  71. package/dist/api/ingest-event.d.ts +0 -65
  72. package/dist/api/mark.d.ts +0 -42
  73. package/dist/api/mark.js +0 -127
  74. package/dist/api/server-deps-a2.d.ts +0 -55
  75. package/dist/api/server-deps-a2.js +0 -138
  76. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  77. package/dist/api/server-deps-l2-l3.js +0 -123
  78. package/dist/api/server-deps-p1.d.ts +0 -84
  79. package/dist/api/server-deps-p2.d.ts +0 -32
  80. package/dist/api/server-deps-p2.js +0 -84
  81. package/dist/api/server-deps-p5.d.ts +0 -66
  82. package/dist/api/server-deps-p5.js +0 -139
  83. package/dist/api/viewer-static.d.ts +0 -30
  84. package/dist/api/viewer-static.js +0 -102
  85. package/dist/api/wire-up.d.ts +0 -54
  86. package/dist/api-impact.d.ts +0 -30
  87. package/dist/api-server.d.ts +0 -2
  88. package/dist/backfill-fts-anchor.d.ts +0 -15
  89. package/dist/backfill-source-type.d.ts +0 -20
  90. package/dist/churn.d.ts +0 -31
  91. package/dist/cli/answer.d.ts +0 -66
  92. package/dist/cli/conflict.d.ts +0 -38
  93. package/dist/cli/conflict.js +0 -282
  94. package/dist/cli/export.d.ts +0 -51
  95. package/dist/cli/export.js +0 -280
  96. package/dist/cli/hooks.d.ts +0 -54
  97. package/dist/cli/hooks.js +0 -133
  98. package/dist/cli/import.d.ts +0 -52
  99. package/dist/cli/import.js +0 -274
  100. package/dist/cli/mark.d.ts +0 -33
  101. package/dist/cli/mark.js +0 -130
  102. package/dist/cli/ocr-batch.d.ts +0 -12
  103. package/dist/cli/ocr-batch.js +0 -411
  104. package/dist/cli/snapshot-main.d.ts +0 -30
  105. package/dist/cli/snapshot-main.js +0 -47
  106. package/dist/cli/viewer.d.ts +0 -35
  107. package/dist/cli/viewer.js +0 -71
  108. package/dist/cli-telemetry.d.ts +0 -36
  109. package/dist/cli-telemetry.js +0 -150
  110. package/dist/compact.d.ts +0 -7
  111. package/dist/consolidate.d.ts +0 -18
  112. package/dist/consolidation.d.ts +0 -32
  113. package/dist/cross-agent-v2.d.ts +0 -45
  114. package/dist/cross-search.d.ts +0 -11
  115. package/dist/crystallize.d.ts +0 -43
  116. package/dist/db.d.ts +0 -11
  117. package/dist/dedup.d.ts +0 -1
  118. package/dist/detect-changes.d.ts +0 -29
  119. package/dist/digest.d.ts +0 -1
  120. package/dist/doctor.d.ts +0 -1
  121. package/dist/embed.d.ts +0 -57
  122. package/dist/evals.d.ts +0 -176
  123. package/dist/evals.js +0 -351
  124. package/dist/generate-user-profile.d.ts +0 -18
  125. package/dist/graphify-ingest.d.ts +0 -18
  126. package/dist/impact.d.ts +0 -39
  127. package/dist/index.d.ts +0 -2
  128. package/dist/ingest-entity.d.ts +0 -44
  129. package/dist/ingest.d.ts +0 -13
  130. package/dist/kg-llm.d.ts +0 -39
  131. package/dist/knowledge-graph.d.ts +0 -72
  132. package/dist/lib/answer/config.d.ts +0 -41
  133. package/dist/lib/answer/index.d.ts +0 -47
  134. package/dist/lib/answer/prompt.d.ts +0 -37
  135. package/dist/lib/answer/provider.d.ts +0 -47
  136. package/dist/lib/answer/retrieval.d.ts +0 -36
  137. package/dist/lib/answer/telemetry.d.ts +0 -99
  138. package/dist/lib/answer/types.d.ts +0 -108
  139. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  140. package/dist/lib/api/safe-error-message.d.ts +0 -70
  141. package/dist/lib/archive/common-passwords.d.ts +0 -37
  142. package/dist/lib/archive/common-passwords.js +0 -753
  143. package/dist/lib/archive/encryption.d.ts +0 -81
  144. package/dist/lib/archive/encryption.js +0 -236
  145. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  146. package/dist/lib/archive/enforce-strength.js +0 -70
  147. package/dist/lib/archive/entropy.d.ts +0 -34
  148. package/dist/lib/archive/entropy.js +0 -180
  149. package/dist/lib/archive/export-locking.d.ts +0 -102
  150. package/dist/lib/archive/export-locking.js +0 -202
  151. package/dist/lib/archive/format.d.ts +0 -20
  152. package/dist/lib/archive/format.js +0 -174
  153. package/dist/lib/archive/index.d.ts +0 -23
  154. package/dist/lib/archive/index.js +0 -17
  155. package/dist/lib/archive/manifest.d.ts +0 -53
  156. package/dist/lib/archive/manifest.js +0 -183
  157. package/dist/lib/archive/migration.d.ts +0 -36
  158. package/dist/lib/archive/migration.js +0 -100
  159. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  160. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  161. package/dist/lib/archive/orchestrator.d.ts +0 -166
  162. package/dist/lib/archive/orchestrator.js +0 -428
  163. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  164. package/dist/lib/archive/serializers/chunks.js +0 -113
  165. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  166. package/dist/lib/archive/serializers/embeddings.js +0 -115
  167. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  168. package/dist/lib/archive/serializers/kg.js +0 -184
  169. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  170. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  171. package/dist/lib/archive/server-deps.d.ts +0 -131
  172. package/dist/lib/archive/server-deps.js +0 -232
  173. package/dist/lib/archive/strength.d.ts +0 -50
  174. package/dist/lib/archive/strength.js +0 -77
  175. package/dist/lib/archive/types.d.ts +0 -159
  176. package/dist/lib/archive/types.js +0 -45
  177. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  178. package/dist/lib/archive/unpack-streaming.js +0 -255
  179. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  180. package/dist/lib/confidence/config.d.ts +0 -37
  181. package/dist/lib/confidence/config.js +0 -107
  182. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  183. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  184. package/dist/lib/confidence/db-shim.d.ts +0 -47
  185. package/dist/lib/confidence/db-shim.js +0 -141
  186. package/dist/lib/confidence/mark.d.ts +0 -58
  187. package/dist/lib/confidence/mark.js +0 -168
  188. package/dist/lib/confidence/ranking.d.ts +0 -69
  189. package/dist/lib/confidence/ranking.js +0 -101
  190. package/dist/lib/confidence/search-filter.d.ts +0 -44
  191. package/dist/lib/confidence/search-filter.js +0 -103
  192. package/dist/lib/confidence/types.d.ts +0 -146
  193. package/dist/lib/confidence/types.js +0 -20
  194. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  195. package/dist/lib/confidence/write-hooks.js +0 -159
  196. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  197. package/dist/lib/conflict/audit-fk-check.js +0 -131
  198. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  199. package/dist/lib/conflict/audit-writer.js +0 -133
  200. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  201. package/dist/lib/conflict/db-singleton.js +0 -61
  202. package/dist/lib/conflict/db.d.ts +0 -27
  203. package/dist/lib/conflict/db.js +0 -20
  204. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  205. package/dist/lib/conflict/detector-direct.js +0 -105
  206. package/dist/lib/conflict/evidence.d.ts +0 -24
  207. package/dist/lib/conflict/evidence.js +0 -76
  208. package/dist/lib/conflict/index.d.ts +0 -14
  209. package/dist/lib/conflict/index.js +0 -12
  210. package/dist/lib/conflict/scheduler.d.ts +0 -78
  211. package/dist/lib/conflict/scheduler.js +0 -111
  212. package/dist/lib/conflict/shadow.d.ts +0 -75
  213. package/dist/lib/conflict/shadow.js +0 -161
  214. package/dist/lib/conflict/types.d.ts +0 -133
  215. package/dist/lib/conflict/types.js +0 -19
  216. package/dist/lib/cost-cap.d.ts +0 -94
  217. package/dist/lib/deps/deps-registry.d.ts +0 -111
  218. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  219. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  220. package/dist/lib/eval-batch.d.ts +0 -34
  221. package/dist/lib/eval-batch.js +0 -103
  222. package/dist/lib/eval-metrics.d.ts +0 -36
  223. package/dist/lib/eval-metrics.js +0 -95
  224. package/dist/lib/eval.d.ts +0 -106
  225. package/dist/lib/eval.js +0 -343
  226. package/dist/lib/events/bus.d.ts +0 -135
  227. package/dist/lib/fts-anchor.d.ts +0 -1
  228. package/dist/lib/hooks/classifier.d.ts +0 -47
  229. package/dist/lib/hooks/classifier.js +0 -129
  230. package/dist/lib/hooks/config.d.ts +0 -49
  231. package/dist/lib/hooks/config.js +0 -106
  232. package/dist/lib/hooks/decorators.d.ts +0 -35
  233. package/dist/lib/hooks/decorators.js +0 -59
  234. package/dist/lib/hooks/pipeline.d.ts +0 -76
  235. package/dist/lib/hooks/pipeline.js +0 -213
  236. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  237. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  238. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  239. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  240. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  241. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  242. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  243. package/dist/lib/hooks/rate-limit.js +0 -122
  244. package/dist/lib/hooks/server-deps.d.ts +0 -61
  245. package/dist/lib/hooks/server-deps.js +0 -92
  246. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  247. package/dist/lib/hooks/source-allowlist.js +0 -53
  248. package/dist/lib/hooks/types.d.ts +0 -129
  249. package/dist/lib/hooks/types.js +0 -24
  250. package/dist/lib/hooks/worker.d.ts +0 -56
  251. package/dist/lib/hooks/worker.js +0 -150
  252. package/dist/lib/ingest-router.d.ts +0 -25
  253. package/dist/lib/ocr-detector.d.ts +0 -61
  254. package/dist/lib/ocr-detector.js +0 -138
  255. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  256. package/dist/lib/ocr-engine-stub.js +0 -190
  257. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  258. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  259. package/dist/lib/ocr-jobs.d.ts +0 -67
  260. package/dist/lib/ocr-jobs.js +0 -129
  261. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  262. package/dist/lib/op-audit.d.ts +0 -71
  263. package/dist/lib/privacy-br/detector.d.ts +0 -42
  264. package/dist/lib/privacy-br/detector.js +0 -130
  265. package/dist/lib/privacy-br/index.d.ts +0 -20
  266. package/dist/lib/privacy-br/index.js +0 -20
  267. package/dist/lib/privacy-br/integration.d.ts +0 -71
  268. package/dist/lib/privacy-br/integration.js +0 -74
  269. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  270. package/dist/lib/privacy-br/patterns.js +0 -434
  271. package/dist/lib/privacy-br/redact.d.ts +0 -42
  272. package/dist/lib/privacy-br/redact.js +0 -103
  273. package/dist/lib/privacy-br/types.d.ts +0 -55
  274. package/dist/lib/privacy-br/types.js +0 -25
  275. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  276. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  277. package/dist/lib/regex-extract/index.d.ts +0 -14
  278. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  279. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  280. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  281. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  282. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  283. package/dist/lib/regex-extract/types.d.ts +0 -48
  284. package/dist/lib/reranker.d.ts +0 -80
  285. package/dist/lib/shadow-tracker.d.ts +0 -191
  286. package/dist/lib/shadow-tracker.js +0 -384
  287. package/dist/lib/spo-injection.d.ts +0 -52
  288. package/dist/lib/telemetry-collector.d.ts +0 -158
  289. package/dist/lib/telemetry-collector.js +0 -249
  290. package/dist/lib/temporal-detector.d.ts +0 -27
  291. package/dist/lib/viewer/auth.d.ts +0 -37
  292. package/dist/lib/viewer/auth.js +0 -70
  293. package/dist/lib/viewer/backpressure.d.ts +0 -59
  294. package/dist/lib/viewer/backpressure.js +0 -100
  295. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  296. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  297. package/dist/lib/viewer/broadcast.d.ts +0 -66
  298. package/dist/lib/viewer/broadcast.js +0 -96
  299. package/dist/lib/viewer/event-types.d.ts +0 -132
  300. package/dist/lib/viewer/event-types.js +0 -74
  301. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  302. package/dist/lib/viewer/instrumentation.js +0 -224
  303. package/dist/lib/viewer/migration.d.ts +0 -23
  304. package/dist/lib/viewer/migration.js +0 -56
  305. package/dist/lib/viewer/redaction.d.ts +0 -44
  306. package/dist/lib/viewer/redaction.js +0 -139
  307. package/dist/lib/viewer/session.d.ts +0 -51
  308. package/dist/lib/viewer/session.js +0 -87
  309. package/dist/mcp/tools/answer.d.ts +0 -94
  310. package/dist/mcp/tools/archive.d.ts +0 -152
  311. package/dist/mcp/tools/archive.js +0 -170
  312. package/dist/mcp/tools/conflict.d.ts +0 -44
  313. package/dist/mcp/tools/conflict.js +0 -130
  314. package/dist/mcp/tools/hooks.d.ts +0 -29
  315. package/dist/mcp/tools/hooks.js +0 -78
  316. package/dist/mcp/tools/mark.d.ts +0 -38
  317. package/dist/mcp/tools/mark.js +0 -82
  318. package/dist/mcp/tools/viewer.d.ts +0 -58
  319. package/dist/mcp/tools/viewer.js +0 -64
  320. package/dist/mcp-server.d.ts +0 -2
  321. package/dist/metrics.d.ts +0 -3
  322. package/dist/noise-filter.d.ts +0 -18
  323. package/dist/notion-sync.d.ts +0 -7
  324. package/dist/notion-sync.js +0 -97
  325. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  326. package/dist/observability/adapters/a3-adapter.js +0 -83
  327. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  328. package/dist/observability/adapters/p1-adapter.js +0 -63
  329. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  330. package/dist/observability/adapters/p5-adapter.js +0 -71
  331. package/dist/observability/cardinality.d.ts +0 -61
  332. package/dist/observability/cardinality.js +0 -300
  333. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  334. package/dist/observability/collectors/db-stats.collector.js +0 -88
  335. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  336. package/dist/observability/collectors/eventbus.collector.js +0 -50
  337. package/dist/observability/collectors/process.collector.d.ts +0 -7
  338. package/dist/observability/collectors/process.collector.js +0 -93
  339. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  340. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  341. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  342. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  343. package/dist/observability/exporter.d.ts +0 -30
  344. package/dist/observability/exporter.js +0 -182
  345. package/dist/observability/index.d.ts +0 -22
  346. package/dist/observability/index.js +0 -21
  347. package/dist/observability/metrics.d.ts +0 -53
  348. package/dist/observability/metrics.js +0 -213
  349. package/dist/observability/privacy-guard.d.ts +0 -32
  350. package/dist/observability/privacy-guard.js +0 -116
  351. package/dist/observability/record.d.ts +0 -83
  352. package/dist/observability/record.js +0 -217
  353. package/dist/observability/registry.d.ts +0 -60
  354. package/dist/observability/registry.js +0 -93
  355. package/dist/observability/types.d.ts +0 -115
  356. package/dist/observability/types.js +0 -235
  357. package/dist/observability.d.ts +0 -131
  358. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  359. package/dist/plugins/nox-hooks/index.js +0 -99
  360. package/dist/primer.d.ts +0 -1
  361. package/dist/privacy/filter.d.ts +0 -27
  362. package/dist/privacy/patterns.d.ts +0 -29
  363. package/dist/privacy/tag-parser.d.ts +0 -24
  364. package/dist/project-context-gen.d.ts +0 -10
  365. package/dist/providers/embedding/gemini.d.ts +0 -73
  366. package/dist/providers/embedding/openai.d.ts +0 -76
  367. package/dist/providers/embedding/types.d.ts +0 -39
  368. package/dist/providers/embedding/voyage.d.ts +0 -36
  369. package/dist/providers/index.d.ts +0 -116
  370. package/dist/providers/llm/anthropic.d.ts +0 -29
  371. package/dist/providers/llm/chain.d.ts +0 -99
  372. package/dist/providers/llm/gemini.d.ts +0 -48
  373. package/dist/providers/llm/openai.d.ts +0 -64
  374. package/dist/providers/llm/types.d.ts +0 -47
  375. package/dist/providers/telemetry.d.ts +0 -87
  376. package/dist/providers/types.d.ts +0 -42
  377. package/dist/query-entity-count.d.ts +0 -54
  378. package/dist/reflect.d.ts +0 -26
  379. package/dist/reindex-errors.d.ts +0 -7
  380. package/dist/reindex.d.ts +0 -16
  381. package/dist/retention.d.ts +0 -40
  382. package/dist/salience.d.ts +0 -85
  383. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  384. package/dist/search-dedup.d.ts +0 -44
  385. package/dist/search-expansion.d.ts +0 -20
  386. package/dist/search.d.ts +0 -62
  387. package/dist/seh-detector.d.ts +0 -31
  388. package/dist/self-improve.d.ts +0 -1
  389. package/dist/session-distill.d.ts +0 -29
  390. package/dist/session-update.d.ts +0 -1
  391. package/dist/shared-memory.d.ts +0 -24
  392. package/dist/stats.d.ts +0 -1
  393. package/dist/temporal-retrieval.d.ts +0 -132
  394. package/dist/tier-manager.d.ts +0 -69
  395. package/dist/vectorize.d.ts +0 -16
  396. package/dist/version.d.ts +0 -1
  397. package/dist/watch.d.ts +0 -8
@@ -1,133 +0,0 @@
1
- /**
2
- * L2 T5 — Audit writer (append-only).
3
- *
4
- * - `recordConflict(db, conflict, evidence?)` — INSERT new audit row.
5
- * Idempotency: skips when an OPEN row already exists for the same
6
- * (subject_entity_id, predicate) — the v21 schema lets us use the partial
7
- * index `idx_conflict_audit_open` for a fast existence check.
8
- *
9
- * - `updateConflictStatus(db, id, resolution)` — UPDATE status + resolution
10
- * columns ONLY. Raw conflict data (kind/subject/predicate/target_relation_ids/
11
- * variants/ts) is immutable per the v21 triggers. Status transitions
12
- * matching a terminal-row reopen are blocked by trigger
13
- * `trg_conflict_audit_no_reopen`.
14
- *
15
- * Regra de ouro #2 (v1 NEVER mutates kg_relations) is honored — this module
16
- * touches conflict_audit only.
17
- */
18
- const INSERT_SQL = `
19
- INSERT INTO conflict_audit (kind, subject_entity_id, predicate, target_relation_ids, variants, status, shadow_mode)
20
- VALUES (?, ?, ?, ?, ?, ?, ?)
21
- `.trim();
22
- const UPDATE_SQL = `
23
- UPDATE conflict_audit
24
- SET status = ?, resolution_kind = ?, resolved_by = ?, resolved_at = ?, picked_relation_id = ?, merge_target = ?, notes = ?
25
- WHERE id = ?
26
- `.trim();
27
- const EXISTS_OPEN_SQL = `
28
- SELECT id FROM conflict_audit
29
- WHERE subject_entity_id = ? AND predicate = ? AND status = ?
30
- LIMIT 1
31
- `.trim();
32
- const GET_BY_ID_SQL = `SELECT * FROM conflict_audit WHERE id = ?`;
33
- const LIST_BY_STATUS_SQL = `SELECT * FROM conflict_audit WHERE status = ? LIMIT 500`;
34
- const COUNT_BY_STATUS_SQL = `SELECT status, COUNT(*) AS count FROM conflict_audit GROUP BY status`;
35
- export function recordConflict(db, conflict, evidence = null, opts = {}) {
36
- const shadowMode = opts.shadow_mode ?? 1;
37
- const status = opts.initial_status ?? "open";
38
- if (!opts.force) {
39
- const existing = db
40
- .prepare(EXISTS_OPEN_SQL)
41
- .get(conflict.subject_entity_id, conflict.predicate, "open");
42
- if (existing) {
43
- return { id: Number(existing.id), deduplicated: true };
44
- }
45
- }
46
- const targetIds = conflict.variants.map((v) => v.relation_id);
47
- const variantsJson = JSON.stringify(enrichVariantsWithEvidence(conflict.variants, evidence));
48
- const res = db
49
- .prepare(INSERT_SQL)
50
- .run(conflict.kind, conflict.subject_entity_id, conflict.predicate, JSON.stringify(targetIds), variantsJson, status, shadowMode);
51
- return { id: Number(res.lastInsertRowid), deduplicated: false };
52
- }
53
- export function updateConflictStatus(db, id, resolution) {
54
- const now = Date.now();
55
- const picked = resolution.picked_relation_id ?? null;
56
- const merge = resolution.merge_target ?? null;
57
- const notes = resolution.notes ?? null;
58
- // Defensive validation — picked_relation_id required for pick_one.
59
- if (resolution.resolution_kind === "pick_one" && picked == null) {
60
- throw new Error("pick_one resolution requires picked_relation_id (got null/undefined)");
61
- }
62
- if (resolution.resolution_kind === "merged" && (merge == null || merge === "")) {
63
- throw new Error("merged resolution requires non-empty merge_target");
64
- }
65
- // Trigger trg_conflict_audit_no_reopen will block invalid transitions.
66
- db.prepare(UPDATE_SQL).run(resolution.status, resolution.resolution_kind, resolution.resolved_by, now, picked, merge, notes, id);
67
- }
68
- export function getConflictById(db, id) {
69
- const row = db.prepare(GET_BY_ID_SQL).get(id);
70
- if (!row)
71
- return null;
72
- return rowToAudit(row);
73
- }
74
- export function listConflicts(db, status = "open", limit = 50) {
75
- const safeLimit = Math.max(1, Math.min(500, limit));
76
- const sql = `SELECT * FROM conflict_audit WHERE status = ? LIMIT ${safeLimit}`;
77
- const rows = db.prepare(sql).all(status);
78
- return rows.map(rowToAudit);
79
- }
80
- /** Aggregate counts by status — used by shadow telemetry. */
81
- export function statusCounts(db) {
82
- const empty = {
83
- open: 0,
84
- reviewed: 0,
85
- resolved_pick_one: 0,
86
- resolved_both_valid: 0,
87
- resolved_merged: 0,
88
- dismissed: 0,
89
- };
90
- const rows = db.prepare(COUNT_BY_STATUS_SQL).all();
91
- for (const r of rows) {
92
- if (r.status in empty) {
93
- empty[r.status] = Number(r.count);
94
- }
95
- }
96
- return empty;
97
- }
98
- // ─────────────────────────────────────────────────────────────────────────────
99
- // Internal helpers
100
- // ─────────────────────────────────────────────────────────────────────────────
101
- function enrichVariantsWithEvidence(variants, evidence) {
102
- if (!evidence)
103
- return variants;
104
- const byId = new Map();
105
- for (const v of variants)
106
- byId.set(v.relation_id, v);
107
- return evidence.variants.map((ve) => ({
108
- ...ve.variant,
109
- evidence_chunks: ve.chunks,
110
- weighted_score: ve.weighted_score,
111
- }));
112
- }
113
- function rowToAudit(row) {
114
- const trIds = row.target_relation_ids;
115
- const variants = row.variants;
116
- return {
117
- id: Number(row.id),
118
- ts: Number(row.ts),
119
- kind: row.kind,
120
- subject_entity_id: Number(row.subject_entity_id),
121
- predicate: String(row.predicate),
122
- target_relation_ids: typeof trIds === "string" ? JSON.parse(trIds) : trIds ?? [],
123
- variants: typeof variants === "string" ? JSON.parse(variants) : variants ?? [],
124
- status: row.status,
125
- resolved_by: row.resolved_by ?? null,
126
- resolved_at: row.resolved_at == null ? null : Number(row.resolved_at),
127
- resolution_kind: row.resolution_kind ?? null,
128
- picked_relation_id: row.picked_relation_id == null ? null : Number(row.picked_relation_id),
129
- merge_target: row.merge_target ?? null,
130
- notes: row.notes ?? null,
131
- shadow_mode: (Number(row.shadow_mode) === 0 ? 0 : 1),
132
- };
133
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * src/lib/conflict/db-singleton.ts — Wave O T4 (L2 piece).
3
- *
4
- * Wire-up.ts expects `lib/conflict/db.js::getConflictDb(): DBHandle`.
5
- * staged-L2 ships only the `DBHandle` interface — no factory. This adapter
6
- * adds the factory.
7
- *
8
- * Apply step appends one line to staged-L2's `db.ts`:
9
- *
10
- * export { getConflictDb, resetConflictDbForTests } from "./db-singleton.js";
11
- *
12
- * Resolution path: `getConflictDb()` delegates to `deps-registry.getDb()`,
13
- * sharing the same nox-mem.db connection used by every other pillar.
14
- *
15
- * Schema dep: L2 reads/writes `conflict_audit` (created by L2 migration v18).
16
- * When the table is missing the upstream `dispatchConflictApi` returns 500;
17
- * the wire-up's G5 sanitizer catches it and returns a redacted 500.
18
- *
19
- * Build-time: ESM TLA loads deps-registry at module init.
20
- */
21
- type DBHandle = unknown;
22
- export declare function getConflictDb(): DBHandle | null;
23
- /** Warm up the singleton at boot. Returns the handle once ready. */
24
- export declare function ensureConflictDb(): Promise<DBHandle | null>;
25
- /** Inject a fake DB for tests. Pass null to clear. */
26
- export declare function __setConflictDbForTests(db: DBHandle | null): void;
27
- export declare function resetConflictDbForTests(): void;
28
- export {};
@@ -1,61 +0,0 @@
1
- /**
2
- * src/lib/conflict/db-singleton.ts — Wave O T4 (L2 piece).
3
- *
4
- * Wire-up.ts expects `lib/conflict/db.js::getConflictDb(): DBHandle`.
5
- * staged-L2 ships only the `DBHandle` interface — no factory. This adapter
6
- * adds the factory.
7
- *
8
- * Apply step appends one line to staged-L2's `db.ts`:
9
- *
10
- * export { getConflictDb, resetConflictDbForTests } from "./db-singleton.js";
11
- *
12
- * Resolution path: `getConflictDb()` delegates to `deps-registry.getDb()`,
13
- * sharing the same nox-mem.db connection used by every other pillar.
14
- *
15
- * Schema dep: L2 reads/writes `conflict_audit` (created by L2 migration v18).
16
- * When the table is missing the upstream `dispatchConflictApi` returns 500;
17
- * the wire-up's G5 sanitizer catches it and returns a redacted 500.
18
- *
19
- * Build-time: ESM TLA loads deps-registry at module init.
20
- */
21
- import { getDb } from "../deps/deps-registry.js";
22
- let _override = null;
23
- /**
24
- * Sync accessor — wire-up calls `dbMod.getConflictDb()` synchronously.
25
- * We warm up the singleton in deps-registry at first call.
26
- *
27
- * Returns `null` when no DB is available; wire-up's null-check then emits
28
- * 503 not_implemented.
29
- */
30
- let _cached;
31
- export function getConflictDb() {
32
- if (_override !== null)
33
- return _override;
34
- if (_cached !== undefined)
35
- return _cached ?? null;
36
- // Kick off the async resolve; the first call may return null until the
37
- // warmup completes. Production startup invokes `await ensureConflictDb()`
38
- // in the API boot sequence.
39
- void warmup();
40
- return _cached ?? null;
41
- }
42
- async function warmup() {
43
- if (_cached !== undefined)
44
- return;
45
- const db = await getDb();
46
- _cached = db;
47
- }
48
- /** Warm up the singleton at boot. Returns the handle once ready. */
49
- export async function ensureConflictDb() {
50
- await warmup();
51
- return _cached ?? null;
52
- }
53
- // ─── Test seam ───────────────────────────────────────────────────────────────
54
- /** Inject a fake DB for tests. Pass null to clear. */
55
- export function __setConflictDbForTests(db) {
56
- _override = db;
57
- }
58
- export function resetConflictDbForTests() {
59
- _override = null;
60
- _cached = undefined;
61
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Minimal DB abstraction for L2 staged code.
3
- *
4
- * The production codebase wires better-sqlite3 directly. To keep this staged
5
- * package zero-dependency for tests (and avoid forcing a `npm install` to run
6
- * the test suite), we expose a tiny interface that matches the better-sqlite3
7
- * `Statement`/`Database` shape. Real callers pass `Database.prototype` from
8
- * better-sqlite3; tests pass a synchronous in-memory fake (see
9
- * `__tests__/fakes.ts`).
10
- */
11
- export interface RunResult {
12
- changes: number;
13
- lastInsertRowid: number | bigint;
14
- }
15
- export interface PreparedStatement {
16
- run(...params: unknown[]): RunResult;
17
- get(...params: unknown[]): unknown;
18
- all(...params: unknown[]): unknown[];
19
- iterate?(...params: unknown[]): IterableIterator<unknown>;
20
- }
21
- export interface DBHandle {
22
- prepare(sql: string): PreparedStatement;
23
- exec(sql: string): void;
24
- transaction?<T>(fn: () => T): () => T;
25
- pragma?(query: string): unknown;
26
- }
27
- export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "./db-singleton.js";
@@ -1,20 +0,0 @@
1
- /**
2
- * Minimal DB abstraction for L2 staged code.
3
- *
4
- * The production codebase wires better-sqlite3 directly. To keep this staged
5
- * package zero-dependency for tests (and avoid forcing a `npm install` to run
6
- * the test suite), we expose a tiny interface that matches the better-sqlite3
7
- * `Statement`/`Database` shape. Real callers pass `Database.prototype` from
8
- * better-sqlite3; tests pass a synchronous in-memory fake (see
9
- * `__tests__/fakes.ts`).
10
- */
11
- // ─── Singleton factory (adapter apply step) ────────────────────────────────
12
- // Wire-up.ts resolves `lib/conflict/db.js::getConflictDb()`. The singleton
13
- // lives in the staged-wire-up-adapters layer; we re-export it here so the
14
- // `tryImport("../lib/conflict/db.js")` call in wire-up.ts finds the symbol.
15
- //
16
- // `ensureConflictDb()` MUST be awaited during API boot to pre-warm the
17
- // async better-sqlite3 open before the first synchronous `getConflictDb()`
18
- // call. Without it, the first request arrives before warmup() resolves and
19
- // getConflictDb() returns null → wire-up emits 503 not_implemented.
20
- export { getConflictDb, ensureConflictDb, resetConflictDbForTests, __setConflictDbForTests, } from "./db-singleton.js";
@@ -1,21 +0,0 @@
1
- /**
2
- * L2 T3 — Direct conflict detector (Type 1).
3
- *
4
- * Algorithm (spec §4.1):
5
- * 1. Group active kg_relations by (source_entity_id, predicate)
6
- * 2. Flag groups where COUNT(DISTINCT target_entity_id) > 1
7
- * 3. Hydrate each group with per-variant metadata (confidence, extraction
8
- * method, evidence chunk, created_at)
9
- * 4. Apply allowlist/blocklist + extraction_method weight bias
10
- *
11
- * v1 scope: produces `kind='direct'` conflicts only. Type 3 (temporal
12
- * supersession) is a downstream refinement — left for L2.1 ranking phase.
13
- *
14
- * Defensive checks (spec §3 regra de ouro #4 — confidence threshold gate):
15
- * - min_confidence default 0.5 (filtered in SQL via parameter)
16
- * - superseded relations (superseded_by_relation_id IS NOT NULL) excluded
17
- * by SQL clause; this preserves discoverability but keeps detector quiet
18
- */
19
- import type { DBHandle } from "./db.js";
20
- import { type Conflict, type DetectorOptions } from "./types.js";
21
- export declare function detectDirectConflicts(db: DBHandle, opts?: DetectorOptions): Conflict[];
@@ -1,105 +0,0 @@
1
- /**
2
- * L2 T3 — Direct conflict detector (Type 1).
3
- *
4
- * Algorithm (spec §4.1):
5
- * 1. Group active kg_relations by (source_entity_id, predicate)
6
- * 2. Flag groups where COUNT(DISTINCT target_entity_id) > 1
7
- * 3. Hydrate each group with per-variant metadata (confidence, extraction
8
- * method, evidence chunk, created_at)
9
- * 4. Apply allowlist/blocklist + extraction_method weight bias
10
- *
11
- * v1 scope: produces `kind='direct'` conflicts only. Type 3 (temporal
12
- * supersession) is a downstream refinement — left for L2.1 ranking phase.
13
- *
14
- * Defensive checks (spec §3 regra de ouro #4 — confidence threshold gate):
15
- * - min_confidence default 0.5 (filtered in SQL via parameter)
16
- * - superseded relations (superseded_by_relation_id IS NOT NULL) excluded
17
- * by SQL clause; this preserves discoverability but keeps detector quiet
18
- */
19
- import { DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
20
- const DETECTOR_SQL = `
21
- SELECT
22
- source_entity_id,
23
- predicate,
24
- COUNT(DISTINCT target_entity_id) AS distinct_targets,
25
- GROUP_CONCAT(id) AS relation_ids_csv
26
- FROM kg_relations
27
- WHERE confidence >= ?
28
- AND superseded_by_relation_id IS NULL
29
- GROUP BY source_entity_id, predicate
30
- HAVING COUNT(DISTINCT target_entity_id) > 1
31
- `.trim();
32
- const HYDRATE_SQL = `
33
- SELECT id, target_entity_id, confidence, extraction_method, evidence_chunk_id, created_at, user_marked
34
- FROM kg_relations
35
- WHERE source_entity_id = ? AND predicate = ? AND confidence >= ? AND superseded_by_relation_id IS NULL
36
- `.trim();
37
- const ENTITY_LABEL_SQL = `SELECT id, name FROM kg_entities WHERE id = ?`;
38
- export function detectDirectConflicts(db, opts = {}) {
39
- const minConf = opts.min_confidence ?? DEFAULT_MIN_CONFIDENCE;
40
- const limit = opts.limit ?? DEFAULT_SCAN_LIMIT;
41
- const scanTs = opts.scan_ts ?? Date.now();
42
- // Confidence threshold validation — protect against pathological inputs.
43
- if (minConf < 0 || minConf > 1) {
44
- throw new RangeError(`min_confidence out of range [0..1]: ${minConf}`);
45
- }
46
- const allow = opts.predicate_allowlist?.length
47
- ? new Set(opts.predicate_allowlist)
48
- : null;
49
- const block = opts.predicate_blocklist?.length
50
- ? new Set(opts.predicate_blocklist)
51
- : null;
52
- const weights = opts.extraction_method_weights ?? {};
53
- const groups = db.prepare(DETECTOR_SQL).all(minConf);
54
- const conflicts = [];
55
- for (const g of groups) {
56
- if (allow && !allow.has(g.predicate))
57
- continue;
58
- if (block && block.has(g.predicate))
59
- continue;
60
- const variantRows = db
61
- .prepare(HYDRATE_SQL)
62
- .all(g.source_entity_id, g.predicate, minConf);
63
- // Apply extraction_method weighting — annotate confidence with bias.
64
- // Weight is multiplicative; default 1.0 (no bias).
65
- const variants = variantRows.map((r) => {
66
- const w = (r.extraction_method && weights[r.extraction_method]) ?? 1.0;
67
- // Clamp adjusted confidence to [0,1] — weighted bias must never push
68
- // outside the canonical CHECK constraint range.
69
- const adjusted = Math.max(0, Math.min(1, r.confidence * w));
70
- return {
71
- relation_id: r.id,
72
- target_entity_id: r.target_entity_id,
73
- confidence: adjusted,
74
- extraction_method: r.extraction_method,
75
- evidence_chunk_id: r.evidence_chunk_id,
76
- created_at: r.created_at,
77
- user_marked: Boolean(r.user_marked),
78
- };
79
- });
80
- // Distinct-target invariant after weighting: a group might collapse if
81
- // weighting pulled all variants below minConf — re-check.
82
- const distinctTargets = new Set(variants.map((v) => v.target_entity_id));
83
- if (distinctTargets.size < 2)
84
- continue;
85
- // Try to resolve subject label (cheap join — single row per conflict).
86
- let subjectLabel;
87
- const entRow = db
88
- .prepare(ENTITY_LABEL_SQL)
89
- .get(g.source_entity_id);
90
- if (entRow?.name)
91
- subjectLabel = entRow.name;
92
- const kind = distinctTargets.size > 2 ? "multi_target" : "direct";
93
- conflicts.push({
94
- kind,
95
- subject_entity_id: g.source_entity_id,
96
- subject_label: subjectLabel,
97
- predicate: g.predicate,
98
- variants,
99
- detected_at: scanTs,
100
- });
101
- if (limit > 0 && conflicts.length >= limit)
102
- break;
103
- }
104
- return conflicts;
105
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * L2 T4 — Evidence collector.
3
- *
4
- * Joins kg_relations.evidence_chunk_id → chunks.*, returning a ranked evidence
5
- * bundle per conflict. Used by:
6
- * - audit-writer (variants serialized into conflict_audit.variants JSON)
7
- * - CLI `conflict show <id>`
8
- * - HTTP `GET /api/conflict/:id`
9
- *
10
- * Ranking heuristic — within a single conflict, variants are returned in
11
- * (a) created_at DESC (recency) then (b) confidence DESC — newer + higher
12
- * confidence first. The weighted_score is informational: avg(relation.conf,
13
- * chunk.conf) — surfaces "does the chunk back up the relation's confidence?"
14
- *
15
- * Snippet is truncated to DEFAULT_EVIDENCE_SNIPPET_LEN with an ellipsis marker.
16
- * Caller can request full content via chunk_id lookup.
17
- */
18
- import type { DBHandle } from "./db.js";
19
- import { type Conflict, type ConflictEvidence } from "./types.js";
20
- export interface CollectEvidenceOptions {
21
- /** Snippet length cap. Default DEFAULT_EVIDENCE_SNIPPET_LEN (320). */
22
- snippet_len?: number;
23
- }
24
- export declare function collectEvidence(db: DBHandle, conflict: Conflict, opts?: CollectEvidenceOptions): ConflictEvidence;
@@ -1,76 +0,0 @@
1
- /**
2
- * L2 T4 — Evidence collector.
3
- *
4
- * Joins kg_relations.evidence_chunk_id → chunks.*, returning a ranked evidence
5
- * bundle per conflict. Used by:
6
- * - audit-writer (variants serialized into conflict_audit.variants JSON)
7
- * - CLI `conflict show <id>`
8
- * - HTTP `GET /api/conflict/:id`
9
- *
10
- * Ranking heuristic — within a single conflict, variants are returned in
11
- * (a) created_at DESC (recency) then (b) confidence DESC — newer + higher
12
- * confidence first. The weighted_score is informational: avg(relation.conf,
13
- * chunk.conf) — surfaces "does the chunk back up the relation's confidence?"
14
- *
15
- * Snippet is truncated to DEFAULT_EVIDENCE_SNIPPET_LEN with an ellipsis marker.
16
- * Caller can request full content via chunk_id lookup.
17
- */
18
- import { DEFAULT_EVIDENCE_SNIPPET_LEN, } from "./types.js";
19
- export function collectEvidence(db, conflict, opts = {}) {
20
- const snippetLen = opts.snippet_len ?? DEFAULT_EVIDENCE_SNIPPET_LEN;
21
- if (snippetLen <= 0) {
22
- throw new RangeError(`snippet_len must be > 0: ${snippetLen}`);
23
- }
24
- // Sort variants for stable display order.
25
- const sorted = [...conflict.variants].sort((a, b) => {
26
- if (b.created_at !== a.created_at)
27
- return b.created_at - a.created_at;
28
- return b.confidence - a.confidence;
29
- });
30
- const variants = sorted.map((v) => {
31
- const chunks = [];
32
- if (v.evidence_chunk_id != null) {
33
- // Single-id IN clause — fake & real both accept this shape.
34
- const rows = db
35
- .prepare(`SELECT id, content, ts, source_session_id, confidence, provenance_kind FROM chunks WHERE id = ?`)
36
- .all(v.evidence_chunk_id);
37
- for (const r of rows) {
38
- chunks.push({
39
- chunk_id: r.id,
40
- snippet: snippet(r.content, snippetLen),
41
- full_length: r.content?.length ?? 0,
42
- ts: r.ts,
43
- source_session_id: r.source_session_id,
44
- chunk_confidence: r.confidence,
45
- provenance_kind: r.provenance_kind,
46
- });
47
- }
48
- }
49
- // weighted_score: avg of relation + chunk confidence (or relation alone if no chunk)
50
- let weighted = v.confidence;
51
- if (chunks.length > 0) {
52
- const chunkConfs = chunks
53
- .map((c) => c.chunk_confidence ?? null)
54
- .filter((c) => c != null);
55
- if (chunkConfs.length > 0) {
56
- const avg = chunkConfs.reduce((a, b) => a + b, 0) / chunkConfs.length;
57
- weighted = (v.confidence + avg) / 2;
58
- }
59
- }
60
- return { variant: v, chunks, weighted_score: weighted };
61
- });
62
- return {
63
- conflict_subject_entity_id: conflict.subject_entity_id,
64
- predicate: conflict.predicate,
65
- variants,
66
- };
67
- }
68
- function snippet(content, max) {
69
- if (!content)
70
- return "";
71
- // Collapse whitespace for a clean snippet — the original chunk is intact in DB.
72
- const flat = content.replace(/\s+/g, " ").trim();
73
- if (flat.length <= max)
74
- return flat;
75
- return flat.slice(0, max - 1).trimEnd() + "…";
76
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * L2 conflict-detection — public re-exports.
3
- *
4
- * Consumers (CLI, HTTP, MCP, daemon) should import from here, not from
5
- * sibling modules directly. This is the stable surface.
6
- */
7
- export type { Conflict, ConflictAuditRow, ConflictEvidence, ConflictKind, ConflictMode, ConflictStatus, DetectorOptions, EvidenceChunk, ExtractionMethod, ResolutionInput, ResolutionKind, VariantEvidence, VariantRelation, } from "./types.js";
8
- export { DEFAULT_CONFLICT_MODE, DEFAULT_EVIDENCE_SNIPPET_LEN, DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
9
- export { detectDirectConflicts } from "./detector-direct.js";
10
- export { collectEvidence } from "./evidence.js";
11
- export { recordConflict, updateConflictStatus, getConflictById, listConflicts, statusCounts, type RecordOptions, type RecordResult, } from "./audit-writer.js";
12
- export { resolveMode, runConflictPass, annotateRelations, getShadowTelemetry, getConflictsForRelations, makeConflictContext, type ConflictContext, type PassResult, type ShadowTelemetry, } from "./shadow.js";
13
- export { parseCronExpression, nextRunAfter, shouldRunScan, runScheduledScan, type ParsedCron, type SchedulerOptions, type ScheduledRunResult, } from "./scheduler.js";
14
- export type { DBHandle, PreparedStatement, RunResult } from "./db.js";
@@ -1,12 +0,0 @@
1
- /**
2
- * L2 conflict-detection — public re-exports.
3
- *
4
- * Consumers (CLI, HTTP, MCP, daemon) should import from here, not from
5
- * sibling modules directly. This is the stable surface.
6
- */
7
- export { DEFAULT_CONFLICT_MODE, DEFAULT_EVIDENCE_SNIPPET_LEN, DEFAULT_MIN_CONFIDENCE, DEFAULT_SCAN_LIMIT, } from "./types.js";
8
- export { detectDirectConflicts } from "./detector-direct.js";
9
- export { collectEvidence } from "./evidence.js";
10
- export { recordConflict, updateConflictStatus, getConflictById, listConflicts, statusCounts, } from "./audit-writer.js";
11
- export { resolveMode, runConflictPass, annotateRelations, getShadowTelemetry, getConflictsForRelations, makeConflictContext, } from "./shadow.js";
12
- export { parseCronExpression, nextRunAfter, shouldRunScan, runScheduledScan, } from "./scheduler.js";
@@ -1,78 +0,0 @@
1
- /**
2
- * L2 T10 — Periodic scanner scaffolding (cron pattern).
3
- *
4
- * NOT an actual scheduler — daemon-side opt-in cron scaffold. The real
5
- * nox-mem daemon is `nox-mem-api` (port 18802). This module exposes:
6
- * - `parseCronExpression(expr)` — minimal validator + next-run calculator
7
- * for the limited set of cron expressions we expect (M H * * *).
8
- * - `shouldRunScan(now, lastRunAt, cronExpr, tzOffsetMinutes)` — pure
9
- * decision function for "is it time to scan?"
10
- * - `runScheduledScan(db, opts)` — idempotent scan wrapper that records
11
- * the last-run timestamp.
12
- *
13
- * Default cron: `0 3 * * *` (03:00 BRT — after backup-all at 02:00).
14
- * Env var: `NOX_CONFLICT_SCAN_CRON`.
15
- *
16
- * Idempotency: skipping conflicts already open is handled at audit-writer
17
- * dedupe layer (see audit-writer.recordConflict). This module only handles
18
- * "should the pass run now?" — not what to do once running.
19
- */
20
- import type { DBHandle } from "./db.js";
21
- import type { PassResult } from "./shadow.js";
22
- import type { DetectorOptions, ConflictMode } from "./types.js";
23
- export interface ParsedCron {
24
- /** Minute 0-59 */
25
- minute: number;
26
- /** Hour 0-23 */
27
- hour: number;
28
- /** Day-of-month — '*' allowed; v1 only supports '*' */
29
- dom: "*";
30
- /** Month — '*' only */
31
- month: "*";
32
- /** Day-of-week — '*' only */
33
- dow: "*";
34
- }
35
- /**
36
- * Parse a restricted cron expression `M H * * *`. v1 explicitly rejects
37
- * non-trivial DOM/month/DOW patterns to keep the scheduler boring.
38
- */
39
- export declare function parseCronExpression(expr: string): ParsedCron;
40
- /**
41
- * Returns next-run unix-ms timestamp at or after `now`, in local timezone
42
- * (caller passes tzOffsetMinutes relative to UTC; default -180 = BRT).
43
- */
44
- export declare function nextRunAfter(now: number, cron: ParsedCron, tzOffsetMinutes?: number): number;
45
- /**
46
- * Should we run a scan now? True when `now >= nextRunAfter(lastRunAt)`.
47
- * On first run (lastRunAt is null), returns true only if the scheduled
48
- * time has already passed at least once today.
49
- */
50
- export declare function shouldRunScan(now: number, lastRunAt: number | null, cron: ParsedCron, tzOffsetMinutes?: number): boolean;
51
- export interface SchedulerState {
52
- lastRunAt: number | null;
53
- cron: ParsedCron;
54
- tzOffsetMinutes: number;
55
- mode: ConflictMode;
56
- }
57
- export interface SchedulerOptions {
58
- cronExpr?: string;
59
- tzOffsetMinutes?: number;
60
- modeOverride?: ConflictMode;
61
- detectorOpts?: DetectorOptions;
62
- /** Test hook — current time. Defaults to Date.now(). */
63
- now?: number;
64
- /** Test hook — last-run timestamp from previous invocation. */
65
- lastRunAt?: number | null;
66
- }
67
- export interface ScheduledRunResult {
68
- ran: boolean;
69
- reason: "first_run" | "due" | "not_due" | "disabled";
70
- result: PassResult | null;
71
- nextRunAt: number;
72
- }
73
- /**
74
- * Decide-then-run scaffold. Caller manages persistence of lastRunAt
75
- * (DB row, file, in-memory) and threads it through. Idempotent: same
76
- * (now, lastRunAt) input returns the same decision.
77
- */
78
- export declare function runScheduledScan(db: DBHandle, opts?: SchedulerOptions): ScheduledRunResult;