nox-mem 3.0.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 (457) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -0
  3. package/dist/api/answer.d.ts +116 -0
  4. package/dist/api/answer.js +274 -0
  5. package/dist/api/answer.validate-patch.d.ts +72 -0
  6. package/dist/api/answer.validate-patch.js +52 -0
  7. package/dist/api/brief-diversity.d.ts +64 -0
  8. package/dist/api/brief-diversity.js +91 -0
  9. package/dist/api/brief.d.ts +114 -0
  10. package/dist/api/brief.js +524 -0
  11. package/dist/api/conflict.d.ts +33 -0
  12. package/dist/api/conflict.js +143 -0
  13. package/dist/api/cors.d.ts +73 -0
  14. package/dist/api/cors.js +124 -0
  15. package/dist/api/events-stream-limited.d.ts +133 -0
  16. package/dist/api/events-stream-limited.js +217 -0
  17. package/dist/api/events-stream.d.ts +53 -0
  18. package/dist/api/events-stream.js +125 -0
  19. package/dist/api/export.d.ts +42 -0
  20. package/dist/api/export.js +85 -0
  21. package/dist/api/health-confidence-adapter.d.ts +29 -0
  22. package/dist/api/health-confidence-adapter.js +73 -0
  23. package/dist/api/health-confidence.d.ts +36 -0
  24. package/dist/api/health-confidence.js +141 -0
  25. package/dist/api/hooks.d.ts +50 -0
  26. package/dist/api/hooks.js +115 -0
  27. package/dist/api/import.d.ts +38 -0
  28. package/dist/api/import.js +87 -0
  29. package/dist/api/ingest-event.d.ts +65 -0
  30. package/dist/api/ingest-event.js +153 -0
  31. package/dist/api/mark.d.ts +42 -0
  32. package/dist/api/mark.js +127 -0
  33. package/dist/api/server-deps-a2.d.ts +55 -0
  34. package/dist/api/server-deps-a2.js +138 -0
  35. package/dist/api/server-deps-l2-l3.d.ts +68 -0
  36. package/dist/api/server-deps-l2-l3.js +123 -0
  37. package/dist/api/server-deps-p1.d.ts +84 -0
  38. package/dist/api/server-deps-p1.js +156 -0
  39. package/dist/api/server-deps-p2.d.ts +32 -0
  40. package/dist/api/server-deps-p2.js +84 -0
  41. package/dist/api/server-deps-p5.d.ts +66 -0
  42. package/dist/api/server-deps-p5.js +139 -0
  43. package/dist/api/viewer-static.d.ts +30 -0
  44. package/dist/api/viewer-static.js +102 -0
  45. package/dist/api/wire-up.d.ts +54 -0
  46. package/dist/api/wire-up.js +521 -0
  47. package/dist/api-impact.d.ts +30 -0
  48. package/dist/api-impact.js +196 -0
  49. package/dist/api-server.d.ts +2 -0
  50. package/dist/api-server.js +614 -0
  51. package/dist/backfill-fts-anchor.d.ts +15 -0
  52. package/dist/backfill-fts-anchor.js +97 -0
  53. package/dist/backfill-source-type.d.ts +20 -0
  54. package/dist/backfill-source-type.js +182 -0
  55. package/dist/churn.d.ts +31 -0
  56. package/dist/churn.js +98 -0
  57. package/dist/cli/answer.d.ts +66 -0
  58. package/dist/cli/answer.js +287 -0
  59. package/dist/cli/conflict.d.ts +38 -0
  60. package/dist/cli/conflict.js +282 -0
  61. package/dist/cli/export.d.ts +51 -0
  62. package/dist/cli/export.js +280 -0
  63. package/dist/cli/hooks.d.ts +54 -0
  64. package/dist/cli/hooks.js +133 -0
  65. package/dist/cli/import.d.ts +52 -0
  66. package/dist/cli/import.js +274 -0
  67. package/dist/cli/mark.d.ts +33 -0
  68. package/dist/cli/mark.js +130 -0
  69. package/dist/cli/ocr-batch.d.ts +12 -0
  70. package/dist/cli/ocr-batch.js +411 -0
  71. package/dist/cli/snapshot-main.d.ts +30 -0
  72. package/dist/cli/snapshot-main.js +47 -0
  73. package/dist/cli/viewer.d.ts +35 -0
  74. package/dist/cli/viewer.js +71 -0
  75. package/dist/cli-telemetry.d.ts +36 -0
  76. package/dist/cli-telemetry.js +150 -0
  77. package/dist/compact.d.ts +7 -0
  78. package/dist/compact.js +147 -0
  79. package/dist/consolidate.d.ts +18 -0
  80. package/dist/consolidate.js +475 -0
  81. package/dist/consolidation.d.ts +32 -0
  82. package/dist/consolidation.js +212 -0
  83. package/dist/cross-agent-v2.d.ts +45 -0
  84. package/dist/cross-agent-v2.js +271 -0
  85. package/dist/cross-search.d.ts +11 -0
  86. package/dist/cross-search.js +119 -0
  87. package/dist/crystallize.d.ts +43 -0
  88. package/dist/crystallize.js +111 -0
  89. package/dist/db.d.ts +11 -0
  90. package/dist/db.js +388 -0
  91. package/dist/dedup.d.ts +1 -0
  92. package/dist/dedup.js +106 -0
  93. package/dist/detect-changes.d.ts +29 -0
  94. package/dist/detect-changes.js +236 -0
  95. package/dist/digest.d.ts +1 -0
  96. package/dist/digest.js +205 -0
  97. package/dist/doctor.d.ts +1 -0
  98. package/dist/doctor.js +71 -0
  99. package/dist/embed.d.ts +45 -0
  100. package/dist/embed.js +257 -0
  101. package/dist/evals.d.ts +176 -0
  102. package/dist/evals.js +351 -0
  103. package/dist/generate-user-profile.d.ts +18 -0
  104. package/dist/generate-user-profile.js +163 -0
  105. package/dist/graphify-ingest.d.ts +18 -0
  106. package/dist/graphify-ingest.js +158 -0
  107. package/dist/impact.d.ts +39 -0
  108. package/dist/impact.js +143 -0
  109. package/dist/index.d.ts +2 -0
  110. package/dist/index.js +689 -0
  111. package/dist/ingest-entity.d.ts +44 -0
  112. package/dist/ingest-entity.js +197 -0
  113. package/dist/ingest.d.ts +13 -0
  114. package/dist/ingest.js +210 -0
  115. package/dist/kg-llm.d.ts +39 -0
  116. package/dist/kg-llm.js +295 -0
  117. package/dist/knowledge-graph.d.ts +72 -0
  118. package/dist/knowledge-graph.js +507 -0
  119. package/dist/lib/answer/config.d.ts +41 -0
  120. package/dist/lib/answer/config.js +70 -0
  121. package/dist/lib/answer/index.d.ts +47 -0
  122. package/dist/lib/answer/index.js +221 -0
  123. package/dist/lib/answer/prompt.d.ts +37 -0
  124. package/dist/lib/answer/prompt.js +88 -0
  125. package/dist/lib/answer/provider.d.ts +47 -0
  126. package/dist/lib/answer/provider.js +101 -0
  127. package/dist/lib/answer/retrieval.d.ts +36 -0
  128. package/dist/lib/answer/retrieval.js +92 -0
  129. package/dist/lib/answer/telemetry.d.ts +99 -0
  130. package/dist/lib/answer/telemetry.js +154 -0
  131. package/dist/lib/answer/types.d.ts +108 -0
  132. package/dist/lib/answer/types.js +1 -0
  133. package/dist/lib/api/error-leak-fix.d.ts +54 -0
  134. package/dist/lib/api/error-leak-fix.js +55 -0
  135. package/dist/lib/api/safe-error-message.d.ts +70 -0
  136. package/dist/lib/api/safe-error-message.js +122 -0
  137. package/dist/lib/archive/common-passwords.d.ts +37 -0
  138. package/dist/lib/archive/common-passwords.js +753 -0
  139. package/dist/lib/archive/encryption.d.ts +81 -0
  140. package/dist/lib/archive/encryption.js +236 -0
  141. package/dist/lib/archive/enforce-strength.d.ts +54 -0
  142. package/dist/lib/archive/enforce-strength.js +70 -0
  143. package/dist/lib/archive/entropy.d.ts +34 -0
  144. package/dist/lib/archive/entropy.js +180 -0
  145. package/dist/lib/archive/export-locking.d.ts +102 -0
  146. package/dist/lib/archive/export-locking.js +202 -0
  147. package/dist/lib/archive/format.d.ts +20 -0
  148. package/dist/lib/archive/format.js +174 -0
  149. package/dist/lib/archive/index.d.ts +23 -0
  150. package/dist/lib/archive/index.js +17 -0
  151. package/dist/lib/archive/manifest.d.ts +53 -0
  152. package/dist/lib/archive/manifest.js +183 -0
  153. package/dist/lib/archive/migration.d.ts +36 -0
  154. package/dist/lib/archive/migration.js +100 -0
  155. package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
  156. package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
  157. package/dist/lib/archive/orchestrator.d.ts +166 -0
  158. package/dist/lib/archive/orchestrator.js +428 -0
  159. package/dist/lib/archive/serializers/chunks.d.ts +30 -0
  160. package/dist/lib/archive/serializers/chunks.js +113 -0
  161. package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
  162. package/dist/lib/archive/serializers/embeddings.js +115 -0
  163. package/dist/lib/archive/serializers/kg.d.ts +28 -0
  164. package/dist/lib/archive/serializers/kg.js +184 -0
  165. package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
  166. package/dist/lib/archive/serializers/ops_audit.js +97 -0
  167. package/dist/lib/archive/server-deps.d.ts +131 -0
  168. package/dist/lib/archive/server-deps.js +232 -0
  169. package/dist/lib/archive/strength.d.ts +50 -0
  170. package/dist/lib/archive/strength.js +77 -0
  171. package/dist/lib/archive/types.d.ts +159 -0
  172. package/dist/lib/archive/types.js +45 -0
  173. package/dist/lib/archive/unpack-streaming.d.ts +70 -0
  174. package/dist/lib/archive/unpack-streaming.js +255 -0
  175. package/dist/lib/auth/localhost-guard.d.ts +106 -0
  176. package/dist/lib/auth/localhost-guard.js +164 -0
  177. package/dist/lib/confidence/config.d.ts +37 -0
  178. package/dist/lib/confidence/config.js +107 -0
  179. package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
  180. package/dist/lib/confidence/db-shim-singleton.js +41 -0
  181. package/dist/lib/confidence/db-shim.d.ts +47 -0
  182. package/dist/lib/confidence/db-shim.js +141 -0
  183. package/dist/lib/confidence/mark.d.ts +58 -0
  184. package/dist/lib/confidence/mark.js +168 -0
  185. package/dist/lib/confidence/ranking.d.ts +69 -0
  186. package/dist/lib/confidence/ranking.js +101 -0
  187. package/dist/lib/confidence/search-filter.d.ts +44 -0
  188. package/dist/lib/confidence/search-filter.js +103 -0
  189. package/dist/lib/confidence/types.d.ts +146 -0
  190. package/dist/lib/confidence/types.js +20 -0
  191. package/dist/lib/confidence/write-hooks.d.ts +50 -0
  192. package/dist/lib/confidence/write-hooks.js +159 -0
  193. package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
  194. package/dist/lib/conflict/audit-fk-check.js +131 -0
  195. package/dist/lib/conflict/audit-writer.d.ts +39 -0
  196. package/dist/lib/conflict/audit-writer.js +133 -0
  197. package/dist/lib/conflict/db-singleton.d.ts +28 -0
  198. package/dist/lib/conflict/db-singleton.js +61 -0
  199. package/dist/lib/conflict/db.d.ts +27 -0
  200. package/dist/lib/conflict/db.js +20 -0
  201. package/dist/lib/conflict/detector-direct.d.ts +21 -0
  202. package/dist/lib/conflict/detector-direct.js +105 -0
  203. package/dist/lib/conflict/evidence.d.ts +24 -0
  204. package/dist/lib/conflict/evidence.js +76 -0
  205. package/dist/lib/conflict/index.d.ts +14 -0
  206. package/dist/lib/conflict/index.js +12 -0
  207. package/dist/lib/conflict/scheduler.d.ts +78 -0
  208. package/dist/lib/conflict/scheduler.js +111 -0
  209. package/dist/lib/conflict/shadow.d.ts +75 -0
  210. package/dist/lib/conflict/shadow.js +161 -0
  211. package/dist/lib/conflict/types.d.ts +133 -0
  212. package/dist/lib/conflict/types.js +19 -0
  213. package/dist/lib/cost-cap.d.ts +94 -0
  214. package/dist/lib/cost-cap.js +129 -0
  215. package/dist/lib/deps/deps-registry.d.ts +111 -0
  216. package/dist/lib/deps/deps-registry.js +209 -0
  217. package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
  218. package/dist/lib/error-sanitizer/middleware.js +100 -0
  219. package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
  220. package/dist/lib/error-sanitizer/sanitize.js +202 -0
  221. package/dist/lib/eval-batch.d.ts +34 -0
  222. package/dist/lib/eval-batch.js +103 -0
  223. package/dist/lib/eval-metrics.d.ts +36 -0
  224. package/dist/lib/eval-metrics.js +95 -0
  225. package/dist/lib/eval.d.ts +106 -0
  226. package/dist/lib/eval.js +343 -0
  227. package/dist/lib/events/bus.d.ts +135 -0
  228. package/dist/lib/events/bus.js +95 -0
  229. package/dist/lib/fts-anchor.d.ts +1 -0
  230. package/dist/lib/fts-anchor.js +131 -0
  231. package/dist/lib/hooks/classifier.d.ts +47 -0
  232. package/dist/lib/hooks/classifier.js +129 -0
  233. package/dist/lib/hooks/config.d.ts +49 -0
  234. package/dist/lib/hooks/config.js +106 -0
  235. package/dist/lib/hooks/decorators.d.ts +35 -0
  236. package/dist/lib/hooks/decorators.js +59 -0
  237. package/dist/lib/hooks/pipeline.d.ts +76 -0
  238. package/dist/lib/hooks/pipeline.js +213 -0
  239. package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
  240. package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
  241. package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
  242. package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
  243. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
  244. package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
  245. package/dist/lib/hooks/rate-limit.d.ts +54 -0
  246. package/dist/lib/hooks/rate-limit.js +122 -0
  247. package/dist/lib/hooks/server-deps.d.ts +61 -0
  248. package/dist/lib/hooks/server-deps.js +92 -0
  249. package/dist/lib/hooks/source-allowlist.d.ts +26 -0
  250. package/dist/lib/hooks/source-allowlist.js +53 -0
  251. package/dist/lib/hooks/types.d.ts +129 -0
  252. package/dist/lib/hooks/types.js +24 -0
  253. package/dist/lib/hooks/worker.d.ts +56 -0
  254. package/dist/lib/hooks/worker.js +150 -0
  255. package/dist/lib/ingest-router.d.ts +25 -0
  256. package/dist/lib/ingest-router.js +103 -0
  257. package/dist/lib/ocr-detector.d.ts +61 -0
  258. package/dist/lib/ocr-detector.js +138 -0
  259. package/dist/lib/ocr-engine-stub.d.ts +48 -0
  260. package/dist/lib/ocr-engine-stub.js +190 -0
  261. package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
  262. package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
  263. package/dist/lib/ocr-jobs.d.ts +67 -0
  264. package/dist/lib/ocr-jobs.js +129 -0
  265. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
  266. package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
  267. package/dist/lib/op-audit.d.ts +71 -0
  268. package/dist/lib/op-audit.js +777 -0
  269. package/dist/lib/privacy-br/detector.d.ts +42 -0
  270. package/dist/lib/privacy-br/detector.js +130 -0
  271. package/dist/lib/privacy-br/index.d.ts +20 -0
  272. package/dist/lib/privacy-br/index.js +20 -0
  273. package/dist/lib/privacy-br/integration.d.ts +71 -0
  274. package/dist/lib/privacy-br/integration.js +74 -0
  275. package/dist/lib/privacy-br/patterns.d.ts +117 -0
  276. package/dist/lib/privacy-br/patterns.js +434 -0
  277. package/dist/lib/privacy-br/redact.d.ts +42 -0
  278. package/dist/lib/privacy-br/redact.js +103 -0
  279. package/dist/lib/privacy-br/types.d.ts +55 -0
  280. package/dist/lib/privacy-br/types.js +25 -0
  281. package/dist/lib/regex-extract/extractor.d.ts +30 -0
  282. package/dist/lib/regex-extract/extractor.js +91 -0
  283. package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
  284. package/dist/lib/regex-extract/frontmatter.js +169 -0
  285. package/dist/lib/regex-extract/index.d.ts +14 -0
  286. package/dist/lib/regex-extract/index.js +14 -0
  287. package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
  288. package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
  289. package/dist/lib/regex-extract/patterns.d.ts +61 -0
  290. package/dist/lib/regex-extract/patterns.js +91 -0
  291. package/dist/lib/regex-extract/production-wire.d.ts +128 -0
  292. package/dist/lib/regex-extract/production-wire.js +202 -0
  293. package/dist/lib/regex-extract/reconcile.d.ts +162 -0
  294. package/dist/lib/regex-extract/reconcile.js +210 -0
  295. package/dist/lib/regex-extract/strip-code.d.ts +24 -0
  296. package/dist/lib/regex-extract/strip-code.js +52 -0
  297. package/dist/lib/regex-extract/types.d.ts +48 -0
  298. package/dist/lib/regex-extract/types.js +25 -0
  299. package/dist/lib/reranker.d.ts +80 -0
  300. package/dist/lib/reranker.js +324 -0
  301. package/dist/lib/shadow-tracker.d.ts +191 -0
  302. package/dist/lib/shadow-tracker.js +384 -0
  303. package/dist/lib/spo-injection.d.ts +52 -0
  304. package/dist/lib/spo-injection.js +166 -0
  305. package/dist/lib/telemetry-collector.d.ts +158 -0
  306. package/dist/lib/telemetry-collector.js +249 -0
  307. package/dist/lib/temporal-detector.d.ts +27 -0
  308. package/dist/lib/temporal-detector.js +81 -0
  309. package/dist/lib/viewer/auth.d.ts +37 -0
  310. package/dist/lib/viewer/auth.js +70 -0
  311. package/dist/lib/viewer/backpressure.d.ts +59 -0
  312. package/dist/lib/viewer/backpressure.js +100 -0
  313. package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
  314. package/dist/lib/viewer/broadcast-singleton.js +49 -0
  315. package/dist/lib/viewer/broadcast.d.ts +66 -0
  316. package/dist/lib/viewer/broadcast.js +96 -0
  317. package/dist/lib/viewer/event-types.d.ts +132 -0
  318. package/dist/lib/viewer/event-types.js +74 -0
  319. package/dist/lib/viewer/instrumentation.d.ts +106 -0
  320. package/dist/lib/viewer/instrumentation.js +224 -0
  321. package/dist/lib/viewer/migration.d.ts +23 -0
  322. package/dist/lib/viewer/migration.js +56 -0
  323. package/dist/lib/viewer/redaction.d.ts +44 -0
  324. package/dist/lib/viewer/redaction.js +139 -0
  325. package/dist/lib/viewer/session.d.ts +51 -0
  326. package/dist/lib/viewer/session.js +87 -0
  327. package/dist/mcp/tools/answer.d.ts +94 -0
  328. package/dist/mcp/tools/answer.js +213 -0
  329. package/dist/mcp/tools/archive.d.ts +152 -0
  330. package/dist/mcp/tools/archive.js +170 -0
  331. package/dist/mcp/tools/conflict.d.ts +44 -0
  332. package/dist/mcp/tools/conflict.js +130 -0
  333. package/dist/mcp/tools/hooks.d.ts +29 -0
  334. package/dist/mcp/tools/hooks.js +78 -0
  335. package/dist/mcp/tools/mark.d.ts +38 -0
  336. package/dist/mcp/tools/mark.js +82 -0
  337. package/dist/mcp/tools/viewer.d.ts +58 -0
  338. package/dist/mcp/tools/viewer.js +64 -0
  339. package/dist/mcp-server.d.ts +2 -0
  340. package/dist/mcp-server.js +395 -0
  341. package/dist/metrics.d.ts +3 -0
  342. package/dist/metrics.js +59 -0
  343. package/dist/noise-filter.d.ts +18 -0
  344. package/dist/noise-filter.js +142 -0
  345. package/dist/notion-sync.d.ts +7 -0
  346. package/dist/notion-sync.js +97 -0
  347. package/dist/observability/adapters/a3-adapter.d.ts +63 -0
  348. package/dist/observability/adapters/a3-adapter.js +83 -0
  349. package/dist/observability/adapters/p1-adapter.d.ts +49 -0
  350. package/dist/observability/adapters/p1-adapter.js +63 -0
  351. package/dist/observability/adapters/p5-adapter.d.ts +36 -0
  352. package/dist/observability/adapters/p5-adapter.js +71 -0
  353. package/dist/observability/cardinality.d.ts +61 -0
  354. package/dist/observability/cardinality.js +300 -0
  355. package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
  356. package/dist/observability/collectors/db-stats.collector.js +88 -0
  357. package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
  358. package/dist/observability/collectors/eventbus.collector.js +50 -0
  359. package/dist/observability/collectors/process.collector.d.ts +7 -0
  360. package/dist/observability/collectors/process.collector.js +93 -0
  361. package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
  362. package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
  363. package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
  364. package/dist/observability/collectors/search-telemetry.collector.js +76 -0
  365. package/dist/observability/exporter.d.ts +30 -0
  366. package/dist/observability/exporter.js +182 -0
  367. package/dist/observability/index.d.ts +22 -0
  368. package/dist/observability/index.js +21 -0
  369. package/dist/observability/metrics.d.ts +53 -0
  370. package/dist/observability/metrics.js +213 -0
  371. package/dist/observability/privacy-guard.d.ts +32 -0
  372. package/dist/observability/privacy-guard.js +116 -0
  373. package/dist/observability/record.d.ts +83 -0
  374. package/dist/observability/record.js +217 -0
  375. package/dist/observability/registry.d.ts +60 -0
  376. package/dist/observability/registry.js +93 -0
  377. package/dist/observability/types.d.ts +115 -0
  378. package/dist/observability/types.js +235 -0
  379. package/dist/observability.d.ts +131 -0
  380. package/dist/observability.js +234 -0
  381. package/dist/plugins/nox-hooks/index.d.ts +61 -0
  382. package/dist/plugins/nox-hooks/index.js +99 -0
  383. package/dist/primer.d.ts +1 -0
  384. package/dist/primer.js +100 -0
  385. package/dist/privacy/filter.d.ts +27 -0
  386. package/dist/privacy/filter.js +74 -0
  387. package/dist/privacy/patterns.d.ts +29 -0
  388. package/dist/privacy/patterns.js +178 -0
  389. package/dist/privacy/tag-parser.d.ts +24 -0
  390. package/dist/privacy/tag-parser.js +29 -0
  391. package/dist/project-context-gen.d.ts +10 -0
  392. package/dist/project-context-gen.js +106 -0
  393. package/dist/providers/embedding/gemini.d.ts +73 -0
  394. package/dist/providers/embedding/gemini.js +118 -0
  395. package/dist/providers/embedding/openai.d.ts +76 -0
  396. package/dist/providers/embedding/openai.js +123 -0
  397. package/dist/providers/embedding/types.d.ts +39 -0
  398. package/dist/providers/embedding/types.js +1 -0
  399. package/dist/providers/embedding/voyage.d.ts +36 -0
  400. package/dist/providers/embedding/voyage.js +29 -0
  401. package/dist/providers/index.d.ts +116 -0
  402. package/dist/providers/index.js +158 -0
  403. package/dist/providers/llm/anthropic.d.ts +29 -0
  404. package/dist/providers/llm/anthropic.js +28 -0
  405. package/dist/providers/llm/chain.d.ts +99 -0
  406. package/dist/providers/llm/chain.js +213 -0
  407. package/dist/providers/llm/gemini.d.ts +48 -0
  408. package/dist/providers/llm/gemini.js +96 -0
  409. package/dist/providers/llm/openai.d.ts +64 -0
  410. package/dist/providers/llm/openai.js +109 -0
  411. package/dist/providers/llm/types.d.ts +47 -0
  412. package/dist/providers/llm/types.js +1 -0
  413. package/dist/providers/telemetry.d.ts +87 -0
  414. package/dist/providers/telemetry.js +156 -0
  415. package/dist/providers/types.d.ts +42 -0
  416. package/dist/providers/types.js +59 -0
  417. package/dist/query-entity-count.d.ts +54 -0
  418. package/dist/query-entity-count.js +171 -0
  419. package/dist/reflect.d.ts +26 -0
  420. package/dist/reflect.js +290 -0
  421. package/dist/reindex-errors.d.ts +7 -0
  422. package/dist/reindex-errors.js +21 -0
  423. package/dist/reindex.d.ts +16 -0
  424. package/dist/reindex.js +293 -0
  425. package/dist/retention.d.ts +40 -0
  426. package/dist/retention.js +86 -0
  427. package/dist/salience.d.ts +85 -0
  428. package/dist/salience.js +245 -0
  429. package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
  430. package/dist/scripts/migrate-v17-ops-audit.js +70 -0
  431. package/dist/search-dedup.d.ts +44 -0
  432. package/dist/search-dedup.js +137 -0
  433. package/dist/search-expansion.d.ts +20 -0
  434. package/dist/search-expansion.js +99 -0
  435. package/dist/search.d.ts +62 -0
  436. package/dist/search.js +582 -0
  437. package/dist/seh-detector.d.ts +31 -0
  438. package/dist/seh-detector.js +201 -0
  439. package/dist/self-improve.d.ts +1 -0
  440. package/dist/self-improve.js +189 -0
  441. package/dist/session-distill.d.ts +29 -0
  442. package/dist/session-distill.js +325 -0
  443. package/dist/session-update.d.ts +1 -0
  444. package/dist/session-update.js +54 -0
  445. package/dist/shared-memory.d.ts +24 -0
  446. package/dist/shared-memory.js +104 -0
  447. package/dist/stats.d.ts +1 -0
  448. package/dist/stats.js +44 -0
  449. package/dist/temporal-retrieval.d.ts +132 -0
  450. package/dist/temporal-retrieval.js +495 -0
  451. package/dist/tier-manager.d.ts +69 -0
  452. package/dist/tier-manager.js +225 -0
  453. package/dist/vectorize.d.ts +16 -0
  454. package/dist/vectorize.js +91 -0
  455. package/dist/watch.d.ts +8 -0
  456. package/dist/watch.js +124 -0
  457. package/package.json +74 -0
@@ -0,0 +1,111 @@
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 { runConflictPass, resolveMode } from "./shadow.js";
21
+ /**
22
+ * Parse a restricted cron expression `M H * * *`. v1 explicitly rejects
23
+ * non-trivial DOM/month/DOW patterns to keep the scheduler boring.
24
+ */
25
+ export function parseCronExpression(expr) {
26
+ const parts = expr.trim().split(/\s+/);
27
+ if (parts.length !== 5) {
28
+ throw new Error(`cron expression must have 5 fields, got ${parts.length}: '${expr}'`);
29
+ }
30
+ const [m, h, dom, month, dow] = parts;
31
+ const min = Number(m);
32
+ const hr = Number(h);
33
+ if (!Number.isFinite(min) || min < 0 || min > 59) {
34
+ throw new Error(`invalid cron minute: ${m}`);
35
+ }
36
+ if (!Number.isFinite(hr) || hr < 0 || hr > 23) {
37
+ throw new Error(`invalid cron hour: ${h}`);
38
+ }
39
+ if (dom !== "*" || month !== "*" || dow !== "*") {
40
+ throw new Error(`cron v1 supports only 'M H * * *' (got dom=${dom}, month=${month}, dow=${dow})`);
41
+ }
42
+ return { minute: min, hour: hr, dom: "*", month: "*", dow: "*" };
43
+ }
44
+ /**
45
+ * Returns next-run unix-ms timestamp at or after `now`, in local timezone
46
+ * (caller passes tzOffsetMinutes relative to UTC; default -180 = BRT).
47
+ */
48
+ export function nextRunAfter(now, cron, tzOffsetMinutes = -180) {
49
+ // Move "now" into local time
50
+ const localNow = new Date(now + tzOffsetMinutes * 60_000);
51
+ const candidate = new Date(localNow);
52
+ candidate.setUTCSeconds(0, 0);
53
+ candidate.setUTCHours(cron.hour, cron.minute, 0, 0);
54
+ if (candidate.getTime() <= localNow.getTime()) {
55
+ candidate.setUTCDate(candidate.getUTCDate() + 1);
56
+ }
57
+ // Translate back to UTC
58
+ return candidate.getTime() - tzOffsetMinutes * 60_000;
59
+ }
60
+ /**
61
+ * Should we run a scan now? True when `now >= nextRunAfter(lastRunAt)`.
62
+ * On first run (lastRunAt is null), returns true only if the scheduled
63
+ * time has already passed at least once today.
64
+ */
65
+ export function shouldRunScan(now, lastRunAt, cron, tzOffsetMinutes = -180) {
66
+ if (lastRunAt == null) {
67
+ const next = nextRunAfter(now - 24 * 3600_000, cron, tzOffsetMinutes);
68
+ return next <= now;
69
+ }
70
+ const next = nextRunAfter(lastRunAt, cron, tzOffsetMinutes);
71
+ return now >= next;
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 function runScheduledScan(db, opts = {}) {
79
+ const cronExpr = opts.cronExpr ?? process.env.NOX_CONFLICT_SCAN_CRON ?? "0 3 * * *";
80
+ const cron = parseCronExpression(cronExpr);
81
+ const tz = opts.tzOffsetMinutes ?? -180;
82
+ const now = opts.now ?? Date.now();
83
+ const lastRun = opts.lastRunAt ?? null;
84
+ const mode = opts.modeOverride ?? resolveMode();
85
+ // Even if scheduler is wired in, conflict mode disabled prevents writes.
86
+ // We still surface 'disabled' so the daemon log shows the explicit gate.
87
+ if (mode === "disabled") {
88
+ return {
89
+ ran: false,
90
+ reason: "disabled",
91
+ result: null,
92
+ nextRunAt: nextRunAfter(now, cron, tz),
93
+ };
94
+ }
95
+ const due = shouldRunScan(now, lastRun, cron, tz);
96
+ if (!due) {
97
+ return {
98
+ ran: false,
99
+ reason: lastRun == null ? "first_run" : "not_due",
100
+ result: null,
101
+ nextRunAt: nextRunAfter(now, cron, tz),
102
+ };
103
+ }
104
+ const result = runConflictPass(db, opts.detectorOpts ?? {}, mode);
105
+ return {
106
+ ran: true,
107
+ reason: lastRun == null ? "first_run" : "due",
108
+ result,
109
+ nextRunAt: nextRunAfter(now, cron, tz),
110
+ };
111
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * L2 T6 — Shadow-mode wrapper.
3
+ *
4
+ * Honors CLAUDE.md regra crítica #5 (ranking changes need ≥7d shadow baseline)
5
+ * + spec regra de ouro #1 (shadow-first; default disabled).
6
+ *
7
+ * Mode selector lives in env `NOX_CONFLICT_MODE`:
8
+ * - 'disabled' (default) — no detection runs, no rows inserted, no telemetry.
9
+ * `runConflictPass` returns synthetic { mode:'disabled' } with zero counts.
10
+ * - 'shadow' — detection runs, conflict_audit rows inserted with
11
+ * shadow_mode=1, NO surface annotations on retrieved relations.
12
+ * - 'active' — detection runs, conflict_audit rows inserted with
13
+ * shadow_mode=0, surface annotations available via `annotateRelations`
14
+ * for callers (e.g. P1 answer pipeline) to display "⚠ conflicting info".
15
+ *
16
+ * Telemetry: `getShadowTelemetry(db)` exposes status counts + last scan ts +
17
+ * mode. Plug into `/api/health.conflictDetection`.
18
+ */
19
+ import type { DBHandle } from "./db.js";
20
+ import type { ConflictMode, ConflictStatus, DetectorOptions, VariantRelation } from "./types.js";
21
+ export interface PassResult {
22
+ mode: ConflictMode;
23
+ scanned_at: number;
24
+ detected: number;
25
+ recorded: number;
26
+ deduplicated: number;
27
+ /** New audit row ids (excludes dedupe hits). */
28
+ audit_ids: number[];
29
+ }
30
+ export interface ShadowTelemetry {
31
+ mode: ConflictMode;
32
+ last_scan_at: number | null;
33
+ counts: Record<ConflictStatus, number>;
34
+ /** True when an `active` row exists — informational only. */
35
+ has_active_rows: boolean;
36
+ }
37
+ /**
38
+ * Resolve mode from env (with explicit override option). Default: 'disabled'.
39
+ */
40
+ export declare function resolveMode(envOverride?: string): ConflictMode;
41
+ /**
42
+ * Run a single conflict-detection pass under the current mode.
43
+ *
44
+ * - 'disabled' → no DB writes, returns empty result
45
+ * - 'shadow' / 'active' → detect + record + (active only) annotate
46
+ */
47
+ export declare function runConflictPass(db: DBHandle, opts?: DetectorOptions, modeOverride?: ConflictMode): PassResult;
48
+ /**
49
+ * Annotate a set of relation ids with conflict flags. In shadow mode this is
50
+ * a no-op (returns empty Set). In active mode, returns the subset of input
51
+ * relation ids that appear in any OPEN conflict_audit row.
52
+ *
53
+ * Callers (e.g. P1 answer composer) pass the candidate set; only flagged ids
54
+ * are surfaced as "⚠ conflicting info" in the response payload.
55
+ */
56
+ export declare function annotateRelations(db: DBHandle, relationIds: readonly number[], modeOverride?: ConflictMode): Set<number>;
57
+ /**
58
+ * Telemetry surface — drop into /api/health.conflictDetection.
59
+ */
60
+ export declare function getShadowTelemetry(db: DBHandle, modeOverride?: ConflictMode): ShadowTelemetry;
61
+ /** Test-only: reset module-level scan timestamp. */
62
+ export declare function _resetLastScanForTests(): void;
63
+ /** Surface conflicting variants for a relation id list — returns the variants
64
+ * bundled with their conflict id. Useful for richer UI than a simple Set. */
65
+ export declare function getConflictsForRelations(db: DBHandle, relationIds: readonly number[]): Array<{
66
+ conflict_id: number;
67
+ predicate: string;
68
+ variants: VariantRelation[];
69
+ }>;
70
+ /** Build an instance to share state across modules — pattern used by API. */
71
+ export interface ConflictContext {
72
+ mode: ConflictMode;
73
+ db: DBHandle;
74
+ }
75
+ export declare function makeConflictContext(db: DBHandle): ConflictContext;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * L2 T6 — Shadow-mode wrapper.
3
+ *
4
+ * Honors CLAUDE.md regra crítica #5 (ranking changes need ≥7d shadow baseline)
5
+ * + spec regra de ouro #1 (shadow-first; default disabled).
6
+ *
7
+ * Mode selector lives in env `NOX_CONFLICT_MODE`:
8
+ * - 'disabled' (default) — no detection runs, no rows inserted, no telemetry.
9
+ * `runConflictPass` returns synthetic { mode:'disabled' } with zero counts.
10
+ * - 'shadow' — detection runs, conflict_audit rows inserted with
11
+ * shadow_mode=1, NO surface annotations on retrieved relations.
12
+ * - 'active' — detection runs, conflict_audit rows inserted with
13
+ * shadow_mode=0, surface annotations available via `annotateRelations`
14
+ * for callers (e.g. P1 answer pipeline) to display "⚠ conflicting info".
15
+ *
16
+ * Telemetry: `getShadowTelemetry(db)` exposes status counts + last scan ts +
17
+ * mode. Plug into `/api/health.conflictDetection`.
18
+ */
19
+ import { detectDirectConflicts } from "./detector-direct.js";
20
+ import { collectEvidence } from "./evidence.js";
21
+ import { recordConflict, statusCounts } from "./audit-writer.js";
22
+ import { DEFAULT_CONFLICT_MODE } from "./types.js";
23
+ /**
24
+ * Resolve mode from env (with explicit override option). Default: 'disabled'.
25
+ */
26
+ export function resolveMode(envOverride) {
27
+ const raw = (envOverride ?? process.env.NOX_CONFLICT_MODE ?? "").toLowerCase().trim();
28
+ if (raw === "shadow")
29
+ return "shadow";
30
+ if (raw === "active")
31
+ return "active";
32
+ if (raw === "disabled" || raw === "")
33
+ return DEFAULT_CONFLICT_MODE;
34
+ // Unknown value → safe default 'disabled' (avoid surprise activation).
35
+ return "disabled";
36
+ }
37
+ let _lastScanAt = null;
38
+ /**
39
+ * Run a single conflict-detection pass under the current mode.
40
+ *
41
+ * - 'disabled' → no DB writes, returns empty result
42
+ * - 'shadow' / 'active' → detect + record + (active only) annotate
43
+ */
44
+ export function runConflictPass(db, opts = {}, modeOverride) {
45
+ const mode = modeOverride ?? resolveMode();
46
+ const now = Date.now();
47
+ if (mode === "disabled") {
48
+ return {
49
+ mode,
50
+ scanned_at: now,
51
+ detected: 0,
52
+ recorded: 0,
53
+ deduplicated: 0,
54
+ audit_ids: [],
55
+ };
56
+ }
57
+ const conflicts = detectDirectConflicts(db, { ...opts, scan_ts: now });
58
+ const shadow = mode === "shadow" ? 1 : 0;
59
+ const auditIds = [];
60
+ let recorded = 0;
61
+ let dedup = 0;
62
+ for (const c of conflicts) {
63
+ const ev = collectEvidence(db, c);
64
+ const r = recordConflict(db, c, ev, { shadow_mode: shadow });
65
+ if (r.deduplicated) {
66
+ dedup++;
67
+ }
68
+ else {
69
+ recorded++;
70
+ auditIds.push(r.id);
71
+ }
72
+ }
73
+ _lastScanAt = now;
74
+ return {
75
+ mode,
76
+ scanned_at: now,
77
+ detected: conflicts.length,
78
+ recorded,
79
+ deduplicated: dedup,
80
+ audit_ids: auditIds,
81
+ };
82
+ }
83
+ /**
84
+ * Annotate a set of relation ids with conflict flags. In shadow mode this is
85
+ * a no-op (returns empty Set). In active mode, returns the subset of input
86
+ * relation ids that appear in any OPEN conflict_audit row.
87
+ *
88
+ * Callers (e.g. P1 answer composer) pass the candidate set; only flagged ids
89
+ * are surfaced as "⚠ conflicting info" in the response payload.
90
+ */
91
+ export function annotateRelations(db, relationIds, modeOverride) {
92
+ const mode = modeOverride ?? resolveMode();
93
+ if (mode !== "active")
94
+ return new Set();
95
+ if (relationIds.length === 0)
96
+ return new Set();
97
+ // Pull all OPEN audit rows once — typical scale is dozens to low hundreds.
98
+ // For large scans we'd push into SQL; v1 keeps the API simple.
99
+ const rows = db
100
+ .prepare(`SELECT target_relation_ids FROM conflict_audit WHERE status = ? LIMIT 500`)
101
+ .all("open");
102
+ const flagged = new Set();
103
+ for (const r of rows) {
104
+ const ids = typeof r.target_relation_ids === "string"
105
+ ? JSON.parse(r.target_relation_ids)
106
+ : r.target_relation_ids;
107
+ for (const id of ids) {
108
+ if (relationIds.includes(id))
109
+ flagged.add(id);
110
+ }
111
+ }
112
+ return flagged;
113
+ }
114
+ /**
115
+ * Telemetry surface — drop into /api/health.conflictDetection.
116
+ */
117
+ export function getShadowTelemetry(db, modeOverride) {
118
+ const mode = modeOverride ?? resolveMode();
119
+ const counts = statusCounts(db);
120
+ const hasActiveRows = mode === "active";
121
+ return {
122
+ mode,
123
+ last_scan_at: _lastScanAt,
124
+ counts,
125
+ has_active_rows: hasActiveRows,
126
+ };
127
+ }
128
+ /** Test-only: reset module-level scan timestamp. */
129
+ export function _resetLastScanForTests() {
130
+ _lastScanAt = null;
131
+ }
132
+ /** Surface conflicting variants for a relation id list — returns the variants
133
+ * bundled with their conflict id. Useful for richer UI than a simple Set. */
134
+ export function getConflictsForRelations(db, relationIds) {
135
+ if (relationIds.length === 0)
136
+ return [];
137
+ const rows = db
138
+ .prepare(`SELECT * FROM conflict_audit WHERE status = ? LIMIT 500`)
139
+ .all("open");
140
+ const out = [];
141
+ for (const r of rows) {
142
+ const trIds = typeof r.target_relation_ids === "string"
143
+ ? JSON.parse(r.target_relation_ids)
144
+ : r.target_relation_ids;
145
+ const overlap = trIds.some((id) => relationIds.includes(id));
146
+ if (!overlap)
147
+ continue;
148
+ const variants = typeof r.variants === "string"
149
+ ? JSON.parse(r.variants)
150
+ : r.variants;
151
+ out.push({
152
+ conflict_id: Number(r.id),
153
+ predicate: String(r.predicate),
154
+ variants,
155
+ });
156
+ }
157
+ return out;
158
+ }
159
+ export function makeConflictContext(db) {
160
+ return { db, mode: resolveMode() };
161
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * L2 conflict-detection — shared types.
3
+ *
4
+ * Cross-ref: specs/2026-05-17-L2-conflict-detection.md §2 (conflict types) + §3 (schema).
5
+ *
6
+ * v1 scope: ConflictKind='direct' end-to-end. 'temporal_supersede' gated on schema
7
+ * (kg_relations.created_at present from v19). 'value_drift' and 'multi_target'
8
+ * are forward-looking — accepted by schema CHECK but not produced by the v1 detector.
9
+ *
10
+ * **Iron law**: v1 NEVER mutates kg_relations. All resolution is recorded in
11
+ * conflict_audit (append-only, see types.ConflictStatus). Caller may, separately
12
+ * and explicitly, choose to call kg-relations APIs to mark superseded — but that
13
+ * flow is OUT of scope for L2 T1-T12.
14
+ */
15
+ /** Conflict taxonomy (matches conflict_audit.kind CHECK constraint). */
16
+ export type ConflictKind = "direct" | "temporal_supersede" | "value_drift" | "multi_target";
17
+ /** Audit-row lifecycle (matches conflict_audit.status CHECK constraint). */
18
+ export type ConflictStatus = "open" | "reviewed" | "resolved_pick_one" | "resolved_both_valid" | "resolved_merged" | "dismissed";
19
+ /** Resolution flavor stored on terminal rows. */
20
+ export type ResolutionKind = "pick_one" | "both_valid" | "merged" | "dismissed";
21
+ /** Extraction provenance — propagated from kg_relations.extraction_method. */
22
+ export type ExtractionMethod = "regex_only" | "gemini_only" | "regex_primary_gemini_secondary" | "frontmatter" | "manual";
23
+ /** Detector mode selector (NOX_CONFLICT_MODE env var). */
24
+ export type ConflictMode = "disabled" | "shadow" | "active";
25
+ /** Single relation involved in a conflict — snapshot at detection time. */
26
+ export interface VariantRelation {
27
+ relation_id: number;
28
+ target_entity_id: number;
29
+ /** Optional human label for target entity (joined from kg_entities if available). */
30
+ target_label?: string;
31
+ confidence: number;
32
+ extraction_method?: ExtractionMethod | null;
33
+ evidence_chunk_id?: number | null;
34
+ created_at: number;
35
+ /** True when this relation was previously touched by a human resolve (immutable per §6.3). */
36
+ user_marked?: boolean;
37
+ }
38
+ /** Detected conflict (in-memory, pre-audit). */
39
+ export interface Conflict {
40
+ /** Always undefined until persisted by audit-writer.recordConflict(). */
41
+ id?: number;
42
+ kind: ConflictKind;
43
+ /** Subject entity id (kg_entities.id). */
44
+ subject_entity_id: number;
45
+ /** Optional human label for subject — convenience for display, joined when available. */
46
+ subject_label?: string;
47
+ predicate: string;
48
+ variants: VariantRelation[];
49
+ /** epoch_ms — when the detector scan ran. Defaults to NOW. */
50
+ detected_at?: number;
51
+ }
52
+ /** Audit-row shape (matches conflict_audit table columns). */
53
+ export interface ConflictAuditRow {
54
+ id: number;
55
+ ts: number;
56
+ kind: ConflictKind;
57
+ subject_entity_id: number;
58
+ predicate: string;
59
+ /** Parsed from JSON storage. */
60
+ target_relation_ids: number[];
61
+ /** Parsed from JSON storage. */
62
+ variants: VariantRelation[];
63
+ status: ConflictStatus;
64
+ resolved_by: string | null;
65
+ resolved_at: number | null;
66
+ resolution_kind: ResolutionKind | null;
67
+ picked_relation_id: number | null;
68
+ merge_target: string | null;
69
+ notes: string | null;
70
+ shadow_mode: 0 | 1;
71
+ }
72
+ /** Evidence chunk attached to a variant relation (joined from chunks table). */
73
+ export interface EvidenceChunk {
74
+ chunk_id: number;
75
+ /** Short snippet (≤320 chars) of the chunk content. */
76
+ snippet: string;
77
+ /** Full content length (caller can decide to render full). */
78
+ full_length: number;
79
+ ts: number;
80
+ source_session_id?: string | null;
81
+ /** Chunk-level confidence (chunks.confidence, v19). */
82
+ chunk_confidence?: number | null;
83
+ provenance_kind?: string | null;
84
+ }
85
+ /** Evidence bundle: one variant + its supporting chunks. */
86
+ export interface VariantEvidence {
87
+ variant: VariantRelation;
88
+ chunks: EvidenceChunk[];
89
+ /** Aggregate score combining relation.confidence + chunk.confidence (avg) — informational. */
90
+ weighted_score: number;
91
+ }
92
+ /** Full evidence record for a conflict. */
93
+ export interface ConflictEvidence {
94
+ conflict_subject_entity_id: number;
95
+ predicate: string;
96
+ variants: VariantEvidence[];
97
+ }
98
+ /** Detector options. */
99
+ export interface DetectorOptions {
100
+ /**
101
+ * Minimum confidence floor for a relation to be considered "active" by the detector.
102
+ * Default 0.5 (spec §3 — don't surface low-confidence noise).
103
+ */
104
+ min_confidence?: number;
105
+ /** Allowlist of predicates to scan (overrides blocklist). */
106
+ predicate_allowlist?: string[];
107
+ /** Blocklist of predicates (ignored). */
108
+ predicate_blocklist?: string[];
109
+ /** Maximum conflicts to return (0 = unlimited). */
110
+ limit?: number;
111
+ /**
112
+ * Optional weighting bias for extraction_method.
113
+ * Defaults to 1.0 for all methods (no bias).
114
+ * Use {regex_only: 1.1, gemini_only: 0.9} to favor deterministic regex picks.
115
+ */
116
+ extraction_method_weights?: Partial<Record<ExtractionMethod, number>>;
117
+ /** epoch_ms — record this as detected_at on resulting conflicts. Defaults to NOW. */
118
+ scan_ts?: number;
119
+ }
120
+ /** Resolution input passed to audit-writer.updateConflictStatus(). */
121
+ export interface ResolutionInput {
122
+ status: Exclude<ConflictStatus, "open" | "reviewed">;
123
+ resolved_by: string;
124
+ resolution_kind: ResolutionKind;
125
+ picked_relation_id?: number;
126
+ merge_target?: string;
127
+ notes?: string;
128
+ }
129
+ /** Constants — defaults referenced across modules. */
130
+ export declare const DEFAULT_MIN_CONFIDENCE = 0.5;
131
+ export declare const DEFAULT_SCAN_LIMIT = 500;
132
+ export declare const DEFAULT_EVIDENCE_SNIPPET_LEN = 320;
133
+ export declare const DEFAULT_CONFLICT_MODE: ConflictMode;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * L2 conflict-detection — shared types.
3
+ *
4
+ * Cross-ref: specs/2026-05-17-L2-conflict-detection.md §2 (conflict types) + §3 (schema).
5
+ *
6
+ * v1 scope: ConflictKind='direct' end-to-end. 'temporal_supersede' gated on schema
7
+ * (kg_relations.created_at present from v19). 'value_drift' and 'multi_target'
8
+ * are forward-looking — accepted by schema CHECK but not produced by the v1 detector.
9
+ *
10
+ * **Iron law**: v1 NEVER mutates kg_relations. All resolution is recorded in
11
+ * conflict_audit (append-only, see types.ConflictStatus). Caller may, separately
12
+ * and explicitly, choose to call kg-relations APIs to mark superseded — but that
13
+ * flow is OUT of scope for L2 T1-T12.
14
+ */
15
+ /** Constants — defaults referenced across modules. */
16
+ export const DEFAULT_MIN_CONFIDENCE = 0.5;
17
+ export const DEFAULT_SCAN_LIMIT = 500;
18
+ export const DEFAULT_EVIDENCE_SNIPPET_LEN = 320;
19
+ export const DEFAULT_CONFLICT_MODE = "disabled";
@@ -0,0 +1,94 @@
1
+ /**
2
+ * src/lib/cost-cap.ts — Daily cost cap mechanism (T10 / spec T12).
3
+ *
4
+ * `CostCappedProvider` wraps any LLMProvider with a daily/hourly budget cap.
5
+ * Tracks tokens × $/token from `PRICE_TABLE_USD_PER_1M` (or custom table).
6
+ *
7
+ * Configuration:
8
+ * NOX_PROVIDER_DAILY_USD_CAP=50.00 (default)
9
+ * NOX_PROVIDER_DAILY_USD_CAP_BYPASS=1 (explicit bypass — writes audit row)
10
+ *
11
+ * Cap check pre-call: if today's SUM(cost_usd) >= cap → throw CostCapExceededError.
12
+ * Reset interval: daily at UTC midnight (rolling window configurable).
13
+ *
14
+ * INVARIANTS:
15
+ * - CostCapExceededError MUST NOT contain prompt content — only counts.
16
+ * - Bypass MUST write an audit record (never silent).
17
+ * - Cap check must complete within 200ms of window start crossing.
18
+ * - This module has NO SQLite dependency — it uses in-memory state.
19
+ * Production callers inject an `accumulatedCostFn` that queries provider_telemetry.
20
+ */
21
+ import type { LLMProvider, CompleteOpts, CompleteResult } from "../providers/llm/types.js";
22
+ import type { HealthStatus } from "../providers/types.js";
23
+ /** Thrown when the daily spend cap is exceeded. MUST NOT contain prompt content. */
24
+ export declare class CostCapExceededError extends Error {
25
+ readonly capUsd: number;
26
+ readonly spentUsd: number;
27
+ readonly resetAtUtc: string;
28
+ constructor(capUsd: number, spentUsd: number, resetAtUtc: string);
29
+ }
30
+ /**
31
+ * Price table: USD per 1M tokens (input).
32
+ * Sources: public pricing pages as of 2026-05.
33
+ * These are used for real-time cost estimation — reconcile vs invoice monthly.
34
+ */
35
+ export declare const PRICE_TABLE_USD_PER_1M_INPUT: Record<string, number>;
36
+ export declare const PRICE_TABLE_USD_PER_1M_OUTPUT: Record<string, number>;
37
+ /** Estimate cost in USD from token counts + model name. Returns 0 if model unknown. */
38
+ export declare function estimateCostUsd(model: string, tokensIn: number, tokensOut: number): number;
39
+ export interface BypassAuditRecord {
40
+ ts: number;
41
+ capUsd: number;
42
+ spentUsd: number;
43
+ model: string;
44
+ providerId: string;
45
+ }
46
+ export interface CostCapOpts {
47
+ /** Provider to wrap. */
48
+ provider: LLMProvider;
49
+ /**
50
+ * Daily cap in USD. Default: 50.00.
51
+ * Overridden by `NOX_PROVIDER_DAILY_USD_CAP` env at construction time.
52
+ */
53
+ capUsd?: number;
54
+ /**
55
+ * Async function that returns total USD spent today (since midnight UTC).
56
+ * In production this queries `SUM(cost_usd)` from `provider_telemetry`.
57
+ * Default: in-memory accumulator (resets on process restart).
58
+ */
59
+ accumulatedCostFn?: () => Promise<number>;
60
+ /**
61
+ * Whether the bypass env var is active. Default: reads `NOX_PROVIDER_DAILY_USD_CAP_BYPASS`.
62
+ * Pass env seam for testing.
63
+ */
64
+ bypassFn?: () => boolean;
65
+ /**
66
+ * Callback to record bypass events (replaces ops_audit write in isolated module).
67
+ * In production the API layer wires this to `withOpAudit()`.
68
+ */
69
+ onBypass?: (record: BypassAuditRecord) => void;
70
+ /**
71
+ * Callback to accumulate cost after a successful call.
72
+ * Production: inserts row into provider_telemetry.
73
+ * Default: updates in-memory accumulator.
74
+ */
75
+ onCost?: (costUsd: number, model: string, providerId: string) => void;
76
+ /** Env override for tests. */
77
+ env?: NodeJS.ProcessEnv;
78
+ }
79
+ /** Reset the in-memory accumulator (test utility). */
80
+ export declare function resetInMemoryAccumulator(): void;
81
+ export declare class CostCappedProvider implements LLMProvider {
82
+ readonly name: string;
83
+ readonly model: string;
84
+ readonly contextWindow: number;
85
+ private readonly provider;
86
+ private readonly capUsd;
87
+ private readonly accumulatedCostFn;
88
+ private readonly bypassFn;
89
+ private readonly onBypass?;
90
+ private readonly onCost;
91
+ constructor(opts: CostCapOpts);
92
+ complete(opts: CompleteOpts): Promise<CompleteResult>;
93
+ healthCheck(): Promise<HealthStatus>;
94
+ }