nox-mem 3.1.1 → 3.2.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 (398) 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/crystallize.js +3 -5
  17. package/dist/db.js +61 -2
  18. package/dist/embed.js +23 -2
  19. package/dist/index.js +1 -22
  20. package/dist/knowledge-graph.js +20 -0
  21. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  22. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  23. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  24. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  25. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  26. package/dist/lib/answer/provider.js +29 -4
  27. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  28. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  29. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  30. package/dist/lib/events/__tests__/bus.test.js +208 -0
  31. package/dist/lib/ingest-router.js +0 -43
  32. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  33. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  34. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  35. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  36. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  37. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  38. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  39. package/dist/privacy/__tests__/filter.test.js +352 -0
  40. package/dist/providers/__tests__/conformance-extended.test.js +249 -0
  41. package/dist/providers/__tests__/conformance.test.js +98 -0
  42. package/dist/providers/__tests__/cost-cap.test.js +151 -0
  43. package/dist/providers/__tests__/e2e-real.test.js +79 -0
  44. package/dist/providers/__tests__/factory.test.js +80 -0
  45. package/dist/providers/__tests__/fallback.test.js +223 -0
  46. package/dist/providers/__tests__/gemini.test.js +191 -0
  47. package/dist/providers/__tests__/health.test.js +128 -0
  48. package/dist/providers/__tests__/telemetry.test.js +219 -0
  49. package/dist/reindex.js +2 -2
  50. package/package.json +3 -4
  51. package/dist/api/answer.d.ts +0 -116
  52. package/dist/api/answer.validate-patch.d.ts +0 -72
  53. package/dist/api/brief-diversity.d.ts +0 -64
  54. package/dist/api/brief.d.ts +0 -114
  55. package/dist/api/conflict.d.ts +0 -33
  56. package/dist/api/conflict.js +0 -143
  57. package/dist/api/cors.d.ts +0 -73
  58. package/dist/api/events-stream-limited.d.ts +0 -133
  59. package/dist/api/events-stream-limited.js +0 -217
  60. package/dist/api/events-stream.d.ts +0 -53
  61. package/dist/api/events-stream.js +0 -125
  62. package/dist/api/export.d.ts +0 -42
  63. package/dist/api/export.js +0 -85
  64. package/dist/api/health-confidence-adapter.d.ts +0 -29
  65. package/dist/api/health-confidence-adapter.js +0 -73
  66. package/dist/api/health-confidence.d.ts +0 -36
  67. package/dist/api/health-confidence.js +0 -141
  68. package/dist/api/hooks.d.ts +0 -50
  69. package/dist/api/hooks.js +0 -115
  70. package/dist/api/import.d.ts +0 -38
  71. package/dist/api/import.js +0 -87
  72. package/dist/api/ingest-event.d.ts +0 -65
  73. package/dist/api/mark.d.ts +0 -42
  74. package/dist/api/mark.js +0 -127
  75. package/dist/api/server-deps-a2.d.ts +0 -55
  76. package/dist/api/server-deps-a2.js +0 -138
  77. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  78. package/dist/api/server-deps-l2-l3.js +0 -123
  79. package/dist/api/server-deps-p1.d.ts +0 -84
  80. package/dist/api/server-deps-p2.d.ts +0 -32
  81. package/dist/api/server-deps-p2.js +0 -84
  82. package/dist/api/server-deps-p5.d.ts +0 -66
  83. package/dist/api/server-deps-p5.js +0 -139
  84. package/dist/api/viewer-static.d.ts +0 -30
  85. package/dist/api/viewer-static.js +0 -102
  86. package/dist/api/wire-up.d.ts +0 -54
  87. package/dist/api-impact.d.ts +0 -30
  88. package/dist/api-server.d.ts +0 -2
  89. package/dist/backfill-fts-anchor.d.ts +0 -15
  90. package/dist/backfill-source-type.d.ts +0 -20
  91. package/dist/churn.d.ts +0 -31
  92. package/dist/cli/answer.d.ts +0 -66
  93. package/dist/cli/conflict.d.ts +0 -38
  94. package/dist/cli/conflict.js +0 -282
  95. package/dist/cli/export.d.ts +0 -51
  96. package/dist/cli/export.js +0 -280
  97. package/dist/cli/hooks.d.ts +0 -54
  98. package/dist/cli/hooks.js +0 -133
  99. package/dist/cli/import.d.ts +0 -52
  100. package/dist/cli/import.js +0 -274
  101. package/dist/cli/mark.d.ts +0 -33
  102. package/dist/cli/mark.js +0 -130
  103. package/dist/cli/ocr-batch.d.ts +0 -12
  104. package/dist/cli/ocr-batch.js +0 -411
  105. package/dist/cli/snapshot-main.d.ts +0 -30
  106. package/dist/cli/snapshot-main.js +0 -47
  107. package/dist/cli/viewer.d.ts +0 -35
  108. package/dist/cli/viewer.js +0 -71
  109. package/dist/cli-telemetry.d.ts +0 -36
  110. package/dist/cli-telemetry.js +0 -150
  111. package/dist/compact.d.ts +0 -7
  112. package/dist/consolidate.d.ts +0 -18
  113. package/dist/consolidation.d.ts +0 -32
  114. package/dist/cross-agent-v2.d.ts +0 -45
  115. package/dist/cross-search.d.ts +0 -11
  116. package/dist/crystallize.d.ts +0 -43
  117. package/dist/db.d.ts +0 -11
  118. package/dist/dedup.d.ts +0 -1
  119. package/dist/detect-changes.d.ts +0 -29
  120. package/dist/digest.d.ts +0 -1
  121. package/dist/doctor.d.ts +0 -1
  122. package/dist/embed.d.ts +0 -57
  123. package/dist/evals.d.ts +0 -176
  124. package/dist/evals.js +0 -351
  125. package/dist/generate-user-profile.d.ts +0 -18
  126. package/dist/graphify-ingest.d.ts +0 -18
  127. package/dist/impact.d.ts +0 -39
  128. package/dist/index.d.ts +0 -2
  129. package/dist/ingest-entity.d.ts +0 -44
  130. package/dist/ingest.d.ts +0 -13
  131. package/dist/kg-llm.d.ts +0 -39
  132. package/dist/knowledge-graph.d.ts +0 -72
  133. package/dist/lib/answer/config.d.ts +0 -41
  134. package/dist/lib/answer/index.d.ts +0 -47
  135. package/dist/lib/answer/prompt.d.ts +0 -37
  136. package/dist/lib/answer/provider.d.ts +0 -47
  137. package/dist/lib/answer/retrieval.d.ts +0 -36
  138. package/dist/lib/answer/telemetry.d.ts +0 -99
  139. package/dist/lib/answer/types.d.ts +0 -108
  140. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  141. package/dist/lib/api/safe-error-message.d.ts +0 -70
  142. package/dist/lib/archive/common-passwords.d.ts +0 -37
  143. package/dist/lib/archive/common-passwords.js +0 -753
  144. package/dist/lib/archive/encryption.d.ts +0 -81
  145. package/dist/lib/archive/encryption.js +0 -236
  146. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  147. package/dist/lib/archive/enforce-strength.js +0 -70
  148. package/dist/lib/archive/entropy.d.ts +0 -34
  149. package/dist/lib/archive/entropy.js +0 -180
  150. package/dist/lib/archive/export-locking.d.ts +0 -102
  151. package/dist/lib/archive/export-locking.js +0 -202
  152. package/dist/lib/archive/format.d.ts +0 -20
  153. package/dist/lib/archive/format.js +0 -174
  154. package/dist/lib/archive/index.d.ts +0 -23
  155. package/dist/lib/archive/index.js +0 -17
  156. package/dist/lib/archive/manifest.d.ts +0 -53
  157. package/dist/lib/archive/manifest.js +0 -183
  158. package/dist/lib/archive/migration.d.ts +0 -36
  159. package/dist/lib/archive/migration.js +0 -100
  160. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  161. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  162. package/dist/lib/archive/orchestrator.d.ts +0 -166
  163. package/dist/lib/archive/orchestrator.js +0 -428
  164. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  165. package/dist/lib/archive/serializers/chunks.js +0 -113
  166. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  167. package/dist/lib/archive/serializers/embeddings.js +0 -115
  168. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  169. package/dist/lib/archive/serializers/kg.js +0 -184
  170. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  171. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  172. package/dist/lib/archive/server-deps.d.ts +0 -131
  173. package/dist/lib/archive/server-deps.js +0 -232
  174. package/dist/lib/archive/strength.d.ts +0 -50
  175. package/dist/lib/archive/strength.js +0 -77
  176. package/dist/lib/archive/types.d.ts +0 -159
  177. package/dist/lib/archive/types.js +0 -45
  178. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  179. package/dist/lib/archive/unpack-streaming.js +0 -255
  180. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  181. package/dist/lib/confidence/config.d.ts +0 -37
  182. package/dist/lib/confidence/config.js +0 -107
  183. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  184. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  185. package/dist/lib/confidence/db-shim.d.ts +0 -47
  186. package/dist/lib/confidence/db-shim.js +0 -141
  187. package/dist/lib/confidence/mark.d.ts +0 -58
  188. package/dist/lib/confidence/mark.js +0 -168
  189. package/dist/lib/confidence/ranking.d.ts +0 -69
  190. package/dist/lib/confidence/ranking.js +0 -101
  191. package/dist/lib/confidence/search-filter.d.ts +0 -44
  192. package/dist/lib/confidence/search-filter.js +0 -103
  193. package/dist/lib/confidence/types.d.ts +0 -146
  194. package/dist/lib/confidence/types.js +0 -20
  195. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  196. package/dist/lib/confidence/write-hooks.js +0 -159
  197. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  198. package/dist/lib/conflict/audit-fk-check.js +0 -131
  199. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  200. package/dist/lib/conflict/audit-writer.js +0 -133
  201. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  202. package/dist/lib/conflict/db-singleton.js +0 -61
  203. package/dist/lib/conflict/db.d.ts +0 -27
  204. package/dist/lib/conflict/db.js +0 -20
  205. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  206. package/dist/lib/conflict/detector-direct.js +0 -105
  207. package/dist/lib/conflict/evidence.d.ts +0 -24
  208. package/dist/lib/conflict/evidence.js +0 -76
  209. package/dist/lib/conflict/index.d.ts +0 -14
  210. package/dist/lib/conflict/index.js +0 -12
  211. package/dist/lib/conflict/scheduler.d.ts +0 -78
  212. package/dist/lib/conflict/scheduler.js +0 -111
  213. package/dist/lib/conflict/shadow.d.ts +0 -75
  214. package/dist/lib/conflict/shadow.js +0 -161
  215. package/dist/lib/conflict/types.d.ts +0 -133
  216. package/dist/lib/conflict/types.js +0 -19
  217. package/dist/lib/cost-cap.d.ts +0 -94
  218. package/dist/lib/deps/deps-registry.d.ts +0 -111
  219. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  220. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  221. package/dist/lib/eval-batch.d.ts +0 -34
  222. package/dist/lib/eval-batch.js +0 -103
  223. package/dist/lib/eval-metrics.d.ts +0 -36
  224. package/dist/lib/eval-metrics.js +0 -95
  225. package/dist/lib/eval.d.ts +0 -106
  226. package/dist/lib/eval.js +0 -343
  227. package/dist/lib/events/bus.d.ts +0 -135
  228. package/dist/lib/fts-anchor.d.ts +0 -1
  229. package/dist/lib/hooks/classifier.d.ts +0 -47
  230. package/dist/lib/hooks/classifier.js +0 -129
  231. package/dist/lib/hooks/config.d.ts +0 -49
  232. package/dist/lib/hooks/config.js +0 -106
  233. package/dist/lib/hooks/decorators.d.ts +0 -35
  234. package/dist/lib/hooks/decorators.js +0 -59
  235. package/dist/lib/hooks/pipeline.d.ts +0 -76
  236. package/dist/lib/hooks/pipeline.js +0 -213
  237. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  238. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  239. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  240. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  241. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  242. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  243. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  244. package/dist/lib/hooks/rate-limit.js +0 -122
  245. package/dist/lib/hooks/server-deps.d.ts +0 -61
  246. package/dist/lib/hooks/server-deps.js +0 -92
  247. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  248. package/dist/lib/hooks/source-allowlist.js +0 -53
  249. package/dist/lib/hooks/types.d.ts +0 -129
  250. package/dist/lib/hooks/types.js +0 -24
  251. package/dist/lib/hooks/worker.d.ts +0 -56
  252. package/dist/lib/hooks/worker.js +0 -150
  253. package/dist/lib/ingest-router.d.ts +0 -25
  254. package/dist/lib/ocr-detector.d.ts +0 -61
  255. package/dist/lib/ocr-detector.js +0 -138
  256. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  257. package/dist/lib/ocr-engine-stub.js +0 -190
  258. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  259. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  260. package/dist/lib/ocr-jobs.d.ts +0 -67
  261. package/dist/lib/ocr-jobs.js +0 -129
  262. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  263. package/dist/lib/op-audit.d.ts +0 -71
  264. package/dist/lib/privacy-br/detector.d.ts +0 -42
  265. package/dist/lib/privacy-br/detector.js +0 -130
  266. package/dist/lib/privacy-br/index.d.ts +0 -20
  267. package/dist/lib/privacy-br/index.js +0 -20
  268. package/dist/lib/privacy-br/integration.d.ts +0 -71
  269. package/dist/lib/privacy-br/integration.js +0 -74
  270. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  271. package/dist/lib/privacy-br/patterns.js +0 -434
  272. package/dist/lib/privacy-br/redact.d.ts +0 -42
  273. package/dist/lib/privacy-br/redact.js +0 -103
  274. package/dist/lib/privacy-br/types.d.ts +0 -55
  275. package/dist/lib/privacy-br/types.js +0 -25
  276. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  277. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  278. package/dist/lib/regex-extract/index.d.ts +0 -14
  279. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  280. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  281. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  282. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  283. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  284. package/dist/lib/regex-extract/types.d.ts +0 -48
  285. package/dist/lib/reranker.d.ts +0 -80
  286. package/dist/lib/shadow-tracker.d.ts +0 -191
  287. package/dist/lib/shadow-tracker.js +0 -384
  288. package/dist/lib/spo-injection.d.ts +0 -52
  289. package/dist/lib/telemetry-collector.d.ts +0 -158
  290. package/dist/lib/telemetry-collector.js +0 -249
  291. package/dist/lib/temporal-detector.d.ts +0 -27
  292. package/dist/lib/viewer/auth.d.ts +0 -37
  293. package/dist/lib/viewer/auth.js +0 -70
  294. package/dist/lib/viewer/backpressure.d.ts +0 -59
  295. package/dist/lib/viewer/backpressure.js +0 -100
  296. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  297. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  298. package/dist/lib/viewer/broadcast.d.ts +0 -66
  299. package/dist/lib/viewer/broadcast.js +0 -96
  300. package/dist/lib/viewer/event-types.d.ts +0 -132
  301. package/dist/lib/viewer/event-types.js +0 -74
  302. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  303. package/dist/lib/viewer/instrumentation.js +0 -224
  304. package/dist/lib/viewer/migration.d.ts +0 -23
  305. package/dist/lib/viewer/migration.js +0 -56
  306. package/dist/lib/viewer/redaction.d.ts +0 -44
  307. package/dist/lib/viewer/redaction.js +0 -139
  308. package/dist/lib/viewer/session.d.ts +0 -51
  309. package/dist/lib/viewer/session.js +0 -87
  310. package/dist/mcp/tools/answer.d.ts +0 -94
  311. package/dist/mcp/tools/archive.d.ts +0 -152
  312. package/dist/mcp/tools/archive.js +0 -170
  313. package/dist/mcp/tools/conflict.d.ts +0 -44
  314. package/dist/mcp/tools/conflict.js +0 -130
  315. package/dist/mcp/tools/hooks.d.ts +0 -29
  316. package/dist/mcp/tools/hooks.js +0 -78
  317. package/dist/mcp/tools/mark.d.ts +0 -38
  318. package/dist/mcp/tools/mark.js +0 -82
  319. package/dist/mcp/tools/viewer.d.ts +0 -58
  320. package/dist/mcp/tools/viewer.js +0 -64
  321. package/dist/mcp-server.d.ts +0 -2
  322. package/dist/metrics.d.ts +0 -3
  323. package/dist/noise-filter.d.ts +0 -18
  324. package/dist/notion-sync.d.ts +0 -7
  325. package/dist/notion-sync.js +0 -97
  326. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  327. package/dist/observability/adapters/a3-adapter.js +0 -83
  328. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  329. package/dist/observability/adapters/p1-adapter.js +0 -63
  330. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  331. package/dist/observability/adapters/p5-adapter.js +0 -71
  332. package/dist/observability/cardinality.d.ts +0 -61
  333. package/dist/observability/cardinality.js +0 -300
  334. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  335. package/dist/observability/collectors/db-stats.collector.js +0 -88
  336. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  337. package/dist/observability/collectors/eventbus.collector.js +0 -50
  338. package/dist/observability/collectors/process.collector.d.ts +0 -7
  339. package/dist/observability/collectors/process.collector.js +0 -93
  340. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  341. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  342. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  343. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  344. package/dist/observability/exporter.d.ts +0 -30
  345. package/dist/observability/exporter.js +0 -182
  346. package/dist/observability/index.d.ts +0 -22
  347. package/dist/observability/index.js +0 -21
  348. package/dist/observability/metrics.d.ts +0 -53
  349. package/dist/observability/metrics.js +0 -213
  350. package/dist/observability/privacy-guard.d.ts +0 -32
  351. package/dist/observability/privacy-guard.js +0 -116
  352. package/dist/observability/record.d.ts +0 -83
  353. package/dist/observability/record.js +0 -217
  354. package/dist/observability/registry.d.ts +0 -60
  355. package/dist/observability/registry.js +0 -93
  356. package/dist/observability/types.d.ts +0 -115
  357. package/dist/observability/types.js +0 -235
  358. package/dist/observability.d.ts +0 -131
  359. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  360. package/dist/plugins/nox-hooks/index.js +0 -99
  361. package/dist/primer.d.ts +0 -1
  362. package/dist/privacy/filter.d.ts +0 -27
  363. package/dist/privacy/patterns.d.ts +0 -29
  364. package/dist/privacy/tag-parser.d.ts +0 -24
  365. package/dist/project-context-gen.d.ts +0 -10
  366. package/dist/providers/embedding/gemini.d.ts +0 -73
  367. package/dist/providers/embedding/openai.d.ts +0 -76
  368. package/dist/providers/embedding/types.d.ts +0 -39
  369. package/dist/providers/embedding/voyage.d.ts +0 -36
  370. package/dist/providers/index.d.ts +0 -116
  371. package/dist/providers/llm/anthropic.d.ts +0 -29
  372. package/dist/providers/llm/chain.d.ts +0 -99
  373. package/dist/providers/llm/gemini.d.ts +0 -48
  374. package/dist/providers/llm/openai.d.ts +0 -64
  375. package/dist/providers/llm/types.d.ts +0 -47
  376. package/dist/providers/telemetry.d.ts +0 -87
  377. package/dist/providers/types.d.ts +0 -42
  378. package/dist/query-entity-count.d.ts +0 -54
  379. package/dist/reflect.d.ts +0 -26
  380. package/dist/reindex-errors.d.ts +0 -7
  381. package/dist/reindex.d.ts +0 -16
  382. package/dist/retention.d.ts +0 -40
  383. package/dist/salience.d.ts +0 -85
  384. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  385. package/dist/search-dedup.d.ts +0 -44
  386. package/dist/search-expansion.d.ts +0 -20
  387. package/dist/search.d.ts +0 -62
  388. package/dist/seh-detector.d.ts +0 -31
  389. package/dist/self-improve.d.ts +0 -1
  390. package/dist/session-distill.d.ts +0 -29
  391. package/dist/session-update.d.ts +0 -1
  392. package/dist/shared-memory.d.ts +0 -24
  393. package/dist/stats.d.ts +0 -1
  394. package/dist/temporal-retrieval.d.ts +0 -132
  395. package/dist/tier-manager.d.ts +0 -69
  396. package/dist/vectorize.d.ts +0 -16
  397. package/dist/version.d.ts +0 -1
  398. package/dist/watch.d.ts +0 -8
@@ -1,191 +0,0 @@
1
- /**
2
- * shadow-tracker.ts — F10 Phase D shadow tracker
3
- *
4
- * Records side-by-side comparisons between a baseline ranker and a shadow
5
- * (candidate) ranker for the same query. Used to validate ranking changes
6
- * BEFORE flipping the active path (per memory [[shadow-mode-for-ranking-changes]]).
7
- *
8
- * Data flow:
9
- * 1. `recordShadowComparison(feature, query, baseline, shadow, metrics)` is
10
- * called from the search hot-path (post-result, before response write).
11
- * 2. The collector computes a delta_pct from the supplied scalar metric
12
- * (or, when result-sets are passed without scalar metrics, from a
13
- * rank-difference fallback).
14
- * 3. The event is stored in BOTH:
15
- * a) an in-memory 24h × 1h ring buffer keyed by feature, used by the
16
- * dashboard endpoint for fast aggregation.
17
- * b) the `shadow_runs` SQLite table for long-tail audit (append-only).
18
- *
19
- * Design principles:
20
- * - Pattern mirrors `telemetry-collector.ts` from Phase C: synchronous, no
21
- * external deps, ring-buffer eviction lazy on record().
22
- * - Persistence is best-effort: a DB write failure logs to stderr but does
23
- * NOT throw, so the search hot-path is never broken by observability.
24
- * - SQLite handle is injected (not import-time singleton), so tests use
25
- * in-memory DBs and prod uses the shared connection from db.ts.
26
- *
27
- * Spec: docs/ROADMAP.md F10 Phase D
28
- * Cross-link: src/lib/shadow-tracker-schema.sql, api-server.shadow-wire-up.md
29
- */
30
- /** A single ranking result row. Shape is intentionally loose — the tracker only
31
- * uses `id` (for rank-diff) and ignores the rest. */
32
- export interface ResultRow {
33
- id: string | number;
34
- score?: number;
35
- [k: string]: unknown;
36
- }
37
- export type ResultSet = ResultRow[];
38
- export interface ShadowComparison {
39
- /** Epoch ms when the comparison was recorded */
40
- ts: number;
41
- /** Feature name (e.g. "temporal-spike-v2", "salience-v2") */
42
- feature: string;
43
- /** Privacy-preserving hash of the query text */
44
- query_hash: string;
45
- /** Scalar metric for baseline (nullable: caller may only supply IDs) */
46
- baseline_value: number | null;
47
- /** Scalar metric for shadow */
48
- shadow_value: number | null;
49
- /** (shadow - baseline) / baseline * 100; null if baseline is 0 or null */
50
- delta_pct: number | null;
51
- /** Arbitrary per-feature payload (parsed JSON or raw object) */
52
- metadata: Record<string, unknown>;
53
- }
54
- export interface ShadowFeatureBucket {
55
- /** Start of this 1h bucket (epoch ms, floored to the hour) */
56
- hour_ts: number;
57
- label: string;
58
- count: number;
59
- sum_delta_pct: number;
60
- sum_delta_sq: number;
61
- win_count: number;
62
- regression_count: number;
63
- neutral_count: number;
64
- }
65
- export interface ShadowAggregate {
66
- feature: string;
67
- count: number;
68
- win_count: number;
69
- regression_count: number;
70
- neutral_count: number;
71
- mean_delta_pct: number | null;
72
- std_dev: number | null;
73
- buckets: ShadowFeatureBucket[];
74
- }
75
- export interface ShadowResponse {
76
- window: {
77
- hours: number;
78
- bucket_size_hours: number;
79
- from_ts: number;
80
- to_ts: number;
81
- };
82
- /** When ?feature=<name> was passed, this is a single-element array. */
83
- features: ShadowAggregate[];
84
- /** Latest N comparisons for drill-down (only when ?feature=<name> is set) */
85
- latest_runs: ShadowComparison[];
86
- generated_at_ms: number;
87
- }
88
- /** Minimal SQLite handle shape (better-sqlite3-compatible). Kept loose for testability. */
89
- export interface ShadowDB {
90
- prepare(sql: string): {
91
- run(...params: unknown[]): {
92
- lastInsertRowid?: number | bigint;
93
- };
94
- all(...params: unknown[]): unknown[];
95
- get(...params: unknown[]): unknown;
96
- };
97
- exec(sql: string): void;
98
- }
99
- /** Stable SHA-256 (truncated) of the query string. Privacy-preserving (no
100
- * way to recover the query text from the hash). */
101
- export declare function hashQuery(query: string): string;
102
- declare function hourFloor(ts: number): number;
103
- declare function hourLabel(ts: number): string;
104
- declare function emptyBucket(hour_ts: number): ShadowFeatureBucket;
105
- /** Compute (shadow - baseline) / baseline * 100. Returns null when baseline is
106
- * zero, null, or undefined. */
107
- export declare function computeDeltaPct(baseline: number | null | undefined, shadow: number | null | undefined): number | null;
108
- /** Fallback delta when the caller did not supply a scalar metric: compute
109
- * Kendall-style rank-difference normalised to [-100, +100] where positive
110
- * means shadow promoted more of the baseline's top results. */
111
- export declare function rankDifferenceDelta(baseline: ResultSet, shadow: ResultSet): number;
112
- export declare class ShadowTracker {
113
- /** Ring buffer: Map<feature, Map<hour_ts, ShadowFeatureBucket>> */
114
- private buckets;
115
- /** Per-feature ring of latest comparisons for drill-down. */
116
- private latest;
117
- /** Optional DB handle for append-only persistence. */
118
- private db;
119
- /** Cumulative count of skipped DB writes (failure or no-handle). Exposed for ops visibility. */
120
- private skippedPersist;
121
- constructor(db?: ShadowDB | null);
122
- /** Inject or replace the DB handle (used by tests + lazy wire-up). */
123
- setDB(db: ShadowDB | null): void;
124
- /**
125
- * Record a shadow comparison.
126
- *
127
- * @param feature Feature name. Required, non-empty.
128
- * @param query Query text (will be hashed, not stored verbatim).
129
- * @param baseline Baseline result-set (used for rank-diff fallback).
130
- * @param shadow Shadow result-set (used for rank-diff fallback).
131
- * @param metrics Optional scalar metrics. If `metric_name` is set, the
132
- * corresponding `baseline`/`shadow` keys drive delta_pct.
133
- * Otherwise delta_pct falls back to rank-difference.
134
- * @param nowMs Override of `Date.now()` for tests.
135
- */
136
- recordShadowComparison(feature: string, query: string, baseline: ResultSet, shadow: ResultSet, metrics?: Record<string, number | string>, nowMs?: number): ShadowComparison;
137
- /** Update the per-feature ring buffer + roll old buckets. */
138
- private _updateRingBuffer;
139
- private _updateLatestRing;
140
- private _evict;
141
- /** Best-effort SQLite persistence. Never throws — failures bump skippedPersist. */
142
- private _persist;
143
- /**
144
- * Aggregate shadow stats for the dashboard endpoint.
145
- *
146
- * @param featureFilter When set, returns only that feature (+ latest_runs).
147
- * @param windowHours 1..24
148
- * @param nowMs Override "now" for tests.
149
- */
150
- query(featureFilter?: string | null, windowHours?: number, nowMs?: number): ShadowResponse;
151
- /** Exposed for tests. */
152
- _reset(): void;
153
- /** Exposed for ops visibility. */
154
- getSkippedPersistCount(): number;
155
- /** Exposed for tests — number of features currently held. */
156
- _featureCount(): number;
157
- }
158
- /** Module-scope singleton consumed by api-server.ts wire-up. Tests use
159
- * fresh instances or call `_reset()` between cases. */
160
- export declare const tracker: ShadowTracker;
161
- /**
162
- * Hot-path API: record one shadow comparison. Mirrors `recordRequest` shape
163
- * from the Phase C telemetry collector.
164
- *
165
- * @param feature Feature name (required).
166
- * @param query Query text (will be hashed).
167
- * @param baseline Baseline result-set.
168
- * @param shadow Shadow result-set.
169
- * @param metrics Optional scalar metrics: pass `{ baseline, shadow }` to use
170
- * scalar delta; omit to fall back to rank-diff.
171
- */
172
- export declare function recordShadowComparison(feature: string, query: string, baseline: ResultSet, shadow: ResultSet, metrics?: Record<string, number | string>): ShadowComparison;
173
- /**
174
- * Handler for GET /api/observability/shadow.
175
- * Query params:
176
- * feature (optional) Filter to a single feature name.
177
- * window (default 24h) Hours to include (1..24).
178
- * bucket (default 1h) Reserved for future sub-hour buckets.
179
- */
180
- export declare function handleObsShadow(params: Record<string, string>): ShadowResponse;
181
- /** Parse "24h"/"6h"/"12" → integer hours clamped to [1, 24]. */
182
- export declare function parseWindowParam(raw: string): number;
183
- export declare const _internals: {
184
- BUCKET_SIZE_MS: number;
185
- MAX_BUCKETS: number;
186
- MAX_LATEST_PER_FEATURE: number;
187
- hourFloor: typeof hourFloor;
188
- hourLabel: typeof hourLabel;
189
- emptyBucket: typeof emptyBucket;
190
- };
191
- export {};
@@ -1,384 +0,0 @@
1
- /**
2
- * shadow-tracker.ts — F10 Phase D shadow tracker
3
- *
4
- * Records side-by-side comparisons between a baseline ranker and a shadow
5
- * (candidate) ranker for the same query. Used to validate ranking changes
6
- * BEFORE flipping the active path (per memory [[shadow-mode-for-ranking-changes]]).
7
- *
8
- * Data flow:
9
- * 1. `recordShadowComparison(feature, query, baseline, shadow, metrics)` is
10
- * called from the search hot-path (post-result, before response write).
11
- * 2. The collector computes a delta_pct from the supplied scalar metric
12
- * (or, when result-sets are passed without scalar metrics, from a
13
- * rank-difference fallback).
14
- * 3. The event is stored in BOTH:
15
- * a) an in-memory 24h × 1h ring buffer keyed by feature, used by the
16
- * dashboard endpoint for fast aggregation.
17
- * b) the `shadow_runs` SQLite table for long-tail audit (append-only).
18
- *
19
- * Design principles:
20
- * - Pattern mirrors `telemetry-collector.ts` from Phase C: synchronous, no
21
- * external deps, ring-buffer eviction lazy on record().
22
- * - Persistence is best-effort: a DB write failure logs to stderr but does
23
- * NOT throw, so the search hot-path is never broken by observability.
24
- * - SQLite handle is injected (not import-time singleton), so tests use
25
- * in-memory DBs and prod uses the shared connection from db.ts.
26
- *
27
- * Spec: docs/ROADMAP.md F10 Phase D
28
- * Cross-link: src/lib/shadow-tracker-schema.sql, api-server.shadow-wire-up.md
29
- */
30
- import { createHash } from "node:crypto";
31
- // ── Constants ─────────────────────────────────────────────────────────────────
32
- const BUCKET_SIZE_MS = 60 * 60 * 1000; // 1h
33
- const MAX_BUCKETS = 24;
34
- /** Latest N rows kept per feature in memory for drill-down. */
35
- const MAX_LATEST_PER_FEATURE = 10;
36
- // ── Hashing ───────────────────────────────────────────────────────────────────
37
- /** Stable SHA-256 (truncated) of the query string. Privacy-preserving (no
38
- * way to recover the query text from the hash). */
39
- export function hashQuery(query) {
40
- return createHash("sha256").update(query).digest("hex").slice(0, 16);
41
- }
42
- // ── Delta helpers ─────────────────────────────────────────────────────────────
43
- function hourFloor(ts) {
44
- return Math.floor(ts / BUCKET_SIZE_MS) * BUCKET_SIZE_MS;
45
- }
46
- function hourLabel(ts) {
47
- return new Date(ts).toISOString().slice(0, 13) + ":00Z";
48
- }
49
- function emptyBucket(hour_ts) {
50
- return {
51
- hour_ts,
52
- label: hourLabel(hour_ts),
53
- count: 0,
54
- sum_delta_pct: 0,
55
- sum_delta_sq: 0,
56
- win_count: 0,
57
- regression_count: 0,
58
- neutral_count: 0,
59
- };
60
- }
61
- /** Compute (shadow - baseline) / baseline * 100. Returns null when baseline is
62
- * zero, null, or undefined. */
63
- export function computeDeltaPct(baseline, shadow) {
64
- if (baseline === null || baseline === undefined)
65
- return null;
66
- if (shadow === null || shadow === undefined)
67
- return null;
68
- if (baseline === 0)
69
- return null;
70
- return ((shadow - baseline) / baseline) * 100;
71
- }
72
- /** Fallback delta when the caller did not supply a scalar metric: compute
73
- * Kendall-style rank-difference normalised to [-100, +100] where positive
74
- * means shadow promoted more of the baseline's top results. */
75
- export function rankDifferenceDelta(baseline, shadow) {
76
- if (baseline.length === 0 && shadow.length === 0)
77
- return 0;
78
- if (baseline.length === 0)
79
- return 100; // any result is an improvement over nothing
80
- if (shadow.length === 0)
81
- return -100;
82
- const baselineIds = baseline.map((r) => String(r.id));
83
- const shadowIds = shadow.map((r) => String(r.id));
84
- const baselineRank = new Map();
85
- baselineIds.forEach((id, i) => baselineRank.set(id, i));
86
- // For each item in the shadow's top-K, find how much it moved up vs baseline
87
- let totalDelta = 0;
88
- let counted = 0;
89
- const K = Math.min(baselineIds.length, shadowIds.length, 10);
90
- for (let i = 0; i < K; i++) {
91
- const id = shadowIds[i];
92
- if (id === undefined)
93
- continue;
94
- const baselineIdx = baselineRank.get(id);
95
- if (baselineIdx === undefined) {
96
- // New item — count as a positive move (capped at +K)
97
- totalDelta += K;
98
- }
99
- else {
100
- totalDelta += baselineIdx - i; // baseline at pos 5, shadow at pos 0 → +5
101
- }
102
- counted++;
103
- }
104
- if (counted === 0)
105
- return 0;
106
- // Normalise: max possible per-item delta is K (item went from worst to best).
107
- return Math.max(-100, Math.min(100, (totalDelta / (counted * K)) * 100));
108
- }
109
- // ── ShadowTracker class ───────────────────────────────────────────────────────
110
- export class ShadowTracker {
111
- /** Ring buffer: Map<feature, Map<hour_ts, ShadowFeatureBucket>> */
112
- buckets = new Map();
113
- /** Per-feature ring of latest comparisons for drill-down. */
114
- latest = new Map();
115
- /** Optional DB handle for append-only persistence. */
116
- db = null;
117
- /** Cumulative count of skipped DB writes (failure or no-handle). Exposed for ops visibility. */
118
- skippedPersist = 0;
119
- constructor(db) {
120
- this.db = db ?? null;
121
- }
122
- /** Inject or replace the DB handle (used by tests + lazy wire-up). */
123
- setDB(db) {
124
- this.db = db;
125
- }
126
- /**
127
- * Record a shadow comparison.
128
- *
129
- * @param feature Feature name. Required, non-empty.
130
- * @param query Query text (will be hashed, not stored verbatim).
131
- * @param baseline Baseline result-set (used for rank-diff fallback).
132
- * @param shadow Shadow result-set (used for rank-diff fallback).
133
- * @param metrics Optional scalar metrics. If `metric_name` is set, the
134
- * corresponding `baseline`/`shadow` keys drive delta_pct.
135
- * Otherwise delta_pct falls back to rank-difference.
136
- * @param nowMs Override of `Date.now()` for tests.
137
- */
138
- recordShadowComparison(feature, query, baseline, shadow, metrics = {}, nowMs) {
139
- if (!feature || feature.length === 0) {
140
- throw new Error("shadow-tracker: feature must be a non-empty string");
141
- }
142
- const ts = nowMs ?? Date.now();
143
- const query_hash = hashQuery(query);
144
- let baseline_value = null;
145
- let shadow_value = null;
146
- let delta_pct = null;
147
- const baselineMetric = metrics["baseline"];
148
- const shadowMetric = metrics["shadow"];
149
- if (typeof baselineMetric === "number" &&
150
- typeof shadowMetric === "number" &&
151
- Number.isFinite(baselineMetric) &&
152
- Number.isFinite(shadowMetric)) {
153
- baseline_value = baselineMetric;
154
- shadow_value = shadowMetric;
155
- delta_pct = computeDeltaPct(baseline_value, shadow_value);
156
- }
157
- else {
158
- // Fallback: use rank-difference scaled to delta_pct semantics.
159
- delta_pct = rankDifferenceDelta(baseline, shadow);
160
- }
161
- const metadata = {
162
- ...metrics,
163
- baseline_size: baseline.length,
164
- shadow_size: shadow.length,
165
- baseline_top_ids: baseline.slice(0, 5).map((r) => r.id),
166
- shadow_top_ids: shadow.slice(0, 5).map((r) => r.id),
167
- };
168
- const comparison = {
169
- ts,
170
- feature,
171
- query_hash,
172
- baseline_value,
173
- shadow_value,
174
- delta_pct,
175
- metadata,
176
- };
177
- this._updateRingBuffer(comparison);
178
- this._updateLatestRing(comparison);
179
- this._persist(comparison);
180
- return comparison;
181
- }
182
- /** Update the per-feature ring buffer + roll old buckets. */
183
- _updateRingBuffer(c) {
184
- const hour_ts = hourFloor(c.ts);
185
- let featureMap = this.buckets.get(c.feature);
186
- if (!featureMap) {
187
- featureMap = new Map();
188
- this.buckets.set(c.feature, featureMap);
189
- }
190
- this._evict(featureMap, hour_ts);
191
- let bucket = featureMap.get(hour_ts);
192
- if (!bucket) {
193
- bucket = emptyBucket(hour_ts);
194
- featureMap.set(hour_ts, bucket);
195
- }
196
- bucket.count++;
197
- const d = c.delta_pct;
198
- if (d === null) {
199
- bucket.neutral_count++;
200
- }
201
- else {
202
- bucket.sum_delta_pct += d;
203
- bucket.sum_delta_sq += d * d;
204
- if (d > 0)
205
- bucket.win_count++;
206
- else if (d < 0)
207
- bucket.regression_count++;
208
- else
209
- bucket.neutral_count++;
210
- }
211
- }
212
- _updateLatestRing(c) {
213
- let ring = this.latest.get(c.feature);
214
- if (!ring) {
215
- ring = [];
216
- this.latest.set(c.feature, ring);
217
- }
218
- ring.push(c);
219
- while (ring.length > MAX_LATEST_PER_FEATURE)
220
- ring.shift();
221
- }
222
- _evict(featureMap, currentHour) {
223
- const oldestKept = currentHour - (MAX_BUCKETS - 1) * BUCKET_SIZE_MS;
224
- for (const [ts] of featureMap) {
225
- if (ts < oldestKept)
226
- featureMap.delete(ts);
227
- }
228
- }
229
- /** Best-effort SQLite persistence. Never throws — failures bump skippedPersist. */
230
- _persist(c) {
231
- if (!this.db) {
232
- this.skippedPersist++;
233
- return;
234
- }
235
- try {
236
- const stmt = this.db.prepare(`INSERT INTO shadow_runs (ts, feature, query_hash, baseline_value, shadow_value, delta_pct, metadata)
237
- VALUES (?, ?, ?, ?, ?, ?, ?)`);
238
- stmt.run(c.ts, c.feature, c.query_hash, c.baseline_value, c.shadow_value, c.delta_pct, JSON.stringify(c.metadata));
239
- }
240
- catch (err) {
241
- this.skippedPersist++;
242
- // Mirror telemetry-collector silence policy: stderr only, do not throw.
243
- process.stderr.write(`[shadow-tracker] persist failed for feature=${c.feature}: ${err.message}\n`);
244
- }
245
- }
246
- /**
247
- * Aggregate shadow stats for the dashboard endpoint.
248
- *
249
- * @param featureFilter When set, returns only that feature (+ latest_runs).
250
- * @param windowHours 1..24
251
- * @param nowMs Override "now" for tests.
252
- */
253
- query(featureFilter = null, windowHours = 24, nowMs) {
254
- const now = nowMs ?? Date.now();
255
- const window_hours = Math.max(1, Math.min(MAX_BUCKETS, Math.floor(windowHours)));
256
- const to_ts = hourFloor(now) + BUCKET_SIZE_MS;
257
- const from_ts = to_ts - window_hours * BUCKET_SIZE_MS;
258
- const features = [];
259
- const featureNames = featureFilter
260
- ? [featureFilter]
261
- : Array.from(this.buckets.keys()).sort();
262
- for (const featureName of featureNames) {
263
- const featureMap = this.buckets.get(featureName);
264
- const buckets = [];
265
- let count = 0;
266
- let win = 0;
267
- let regression = 0;
268
- let neutral = 0;
269
- let sumDelta = 0;
270
- let sumDeltaSq = 0;
271
- for (let ts = from_ts; ts < to_ts; ts += BUCKET_SIZE_MS) {
272
- const bucket = featureMap?.get(ts) ?? emptyBucket(ts);
273
- buckets.push(bucket);
274
- count += bucket.count;
275
- win += bucket.win_count;
276
- regression += bucket.regression_count;
277
- neutral += bucket.neutral_count;
278
- sumDelta += bucket.sum_delta_pct;
279
- sumDeltaSq += bucket.sum_delta_sq;
280
- }
281
- const measured = count - neutral;
282
- const mean_delta_pct = measured > 0 ? sumDelta / measured : null;
283
- // Sample standard deviation requires ≥2 measured points.
284
- let std_dev = null;
285
- if (measured >= 2 && mean_delta_pct !== null) {
286
- const variance = sumDeltaSq / measured - mean_delta_pct * mean_delta_pct;
287
- std_dev = variance > 0 ? Math.sqrt(variance) : 0;
288
- }
289
- features.push({
290
- feature: featureName,
291
- count,
292
- win_count: win,
293
- regression_count: regression,
294
- neutral_count: neutral,
295
- mean_delta_pct,
296
- std_dev,
297
- buckets,
298
- });
299
- }
300
- // Drill-down: latest N runs for the filtered feature only.
301
- let latest_runs = [];
302
- if (featureFilter) {
303
- const ring = this.latest.get(featureFilter) ?? [];
304
- latest_runs = ring
305
- .filter((c) => c.ts >= from_ts)
306
- .slice(-MAX_LATEST_PER_FEATURE)
307
- .reverse(); // newest first
308
- }
309
- return {
310
- window: {
311
- hours: window_hours,
312
- bucket_size_hours: 1,
313
- from_ts,
314
- to_ts,
315
- },
316
- features,
317
- latest_runs,
318
- generated_at_ms: now,
319
- };
320
- }
321
- /** Exposed for tests. */
322
- _reset() {
323
- this.buckets.clear();
324
- this.latest.clear();
325
- this.skippedPersist = 0;
326
- }
327
- /** Exposed for ops visibility. */
328
- getSkippedPersistCount() {
329
- return this.skippedPersist;
330
- }
331
- /** Exposed for tests — number of features currently held. */
332
- _featureCount() {
333
- return this.buckets.size;
334
- }
335
- }
336
- // ── Singleton + wire-up helpers ───────────────────────────────────────────────
337
- /** Module-scope singleton consumed by api-server.ts wire-up. Tests use
338
- * fresh instances or call `_reset()` between cases. */
339
- export const tracker = new ShadowTracker();
340
- /**
341
- * Hot-path API: record one shadow comparison. Mirrors `recordRequest` shape
342
- * from the Phase C telemetry collector.
343
- *
344
- * @param feature Feature name (required).
345
- * @param query Query text (will be hashed).
346
- * @param baseline Baseline result-set.
347
- * @param shadow Shadow result-set.
348
- * @param metrics Optional scalar metrics: pass `{ baseline, shadow }` to use
349
- * scalar delta; omit to fall back to rank-diff.
350
- */
351
- export function recordShadowComparison(feature, query, baseline, shadow, metrics = {}) {
352
- return tracker.recordShadowComparison(feature, query, baseline, shadow, metrics);
353
- }
354
- /**
355
- * Handler for GET /api/observability/shadow.
356
- * Query params:
357
- * feature (optional) Filter to a single feature name.
358
- * window (default 24h) Hours to include (1..24).
359
- * bucket (default 1h) Reserved for future sub-hour buckets.
360
- */
361
- export function handleObsShadow(params) {
362
- const feature = params["feature"]?.trim() || null;
363
- const windowHours = parseWindowParam(params["window"] ?? "24h");
364
- return tracker.query(feature, windowHours);
365
- }
366
- /** Parse "24h"/"6h"/"12" → integer hours clamped to [1, 24]. */
367
- export function parseWindowParam(raw) {
368
- const m = /^(\d+)h?$/i.exec(raw.trim());
369
- if (!m || !m[1])
370
- return 24;
371
- const n = parseInt(m[1], 10);
372
- if (!Number.isFinite(n) || n < 1)
373
- return 24;
374
- return Math.min(MAX_BUCKETS, n);
375
- }
376
- // ── Internals for tests ───────────────────────────────────────────────────────
377
- export const _internals = {
378
- BUCKET_SIZE_MS,
379
- MAX_BUCKETS,
380
- MAX_LATEST_PER_FEATURE,
381
- hourFloor,
382
- hourLabel,
383
- emptyBucket,
384
- };
@@ -1,52 +0,0 @@
1
- import Database from "better-sqlite3";
2
- export type VaultFactsMode = "off" | "shadow" | "active";
3
- export interface VaultTriple {
4
- subject: string;
5
- relation: string;
6
- object: string;
7
- confidence: number | null;
8
- reason?: string | null;
9
- }
10
- export declare function getMode(): VaultFactsMode;
11
- export declare function getK(): number;
12
- export declare function pickBudget(query: string): number;
13
- /**
14
- * Match query tokens against kg_entities.name (case-insensitive exact match).
15
- * v1 minimal: no NER, no fuzzy. Returns deduped list of matched entity names.
16
- */
17
- export declare function extractCandidateEntities(query: string, db: Database.Database): string[];
18
- /**
19
- * Lookup top-K SPO triples touching given entity names.
20
- * JOIN with kg_entities to resolve FK ids → names.
21
- * ORDER BY confidence DESC NULLS LAST, then created_at DESC.
22
- */
23
- export declare function lookupTopK(entityNames: string[], db: Database.Database, k: number): VaultTriple[];
24
- /**
25
- * Format triples as <vault-facts> XML-like block.
26
- * Returns null if no triples (avoid empty block).
27
- * Truncates each field to 80 chars to bound token usage.
28
- */
29
- export declare function formatVaultFacts(triples: VaultTriple[]): string | null;
30
- /**
31
- * Estimate token usage roughly (chars/4 heuristic).
32
- * Used to enforce budget cap.
33
- */
34
- export declare function estimateTokens(s: string): number;
35
- /**
36
- * Trim triples list to fit token budget.
37
- */
38
- export declare function applyBudget(triples: VaultTriple[], budget: number): VaultTriple[];
39
- /**
40
- * Top-level orchestrator. Returns VaultFacts result or null if disabled/empty.
41
- * Logs telemetry when enabled (shadow or active).
42
- */
43
- export interface VaultFactsResult {
44
- block: string | null;
45
- mode: VaultFactsMode;
46
- surface: boolean;
47
- entities: number;
48
- triples: number;
49
- tokens: number;
50
- budget: number;
51
- }
52
- export declare function getVaultFacts(query: string, db: Database.Database): VaultFactsResult;