nox-mem 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/db.js +61 -2
  17. package/dist/embed.js +23 -2
  18. package/dist/index.js +3 -23
  19. package/dist/knowledge-graph.js +20 -0
  20. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  21. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  22. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  23. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  24. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  25. package/dist/lib/answer/provider.js +29 -4
  26. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  27. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  28. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  29. package/dist/lib/events/__tests__/bus.test.js +208 -0
  30. package/dist/lib/ingest-router.js +0 -43
  31. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  32. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  33. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  34. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  35. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  36. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  37. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  38. package/dist/mcp-server.js +2 -1
  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/dist/version.js +22 -0
  51. package/package.json +3 -4
  52. package/dist/api/answer.d.ts +0 -116
  53. package/dist/api/answer.validate-patch.d.ts +0 -72
  54. package/dist/api/brief-diversity.d.ts +0 -64
  55. package/dist/api/brief.d.ts +0 -114
  56. package/dist/api/conflict.d.ts +0 -33
  57. package/dist/api/conflict.js +0 -143
  58. package/dist/api/cors.d.ts +0 -73
  59. package/dist/api/events-stream-limited.d.ts +0 -133
  60. package/dist/api/events-stream-limited.js +0 -217
  61. package/dist/api/events-stream.d.ts +0 -53
  62. package/dist/api/events-stream.js +0 -125
  63. package/dist/api/export.d.ts +0 -42
  64. package/dist/api/export.js +0 -85
  65. package/dist/api/health-confidence-adapter.d.ts +0 -29
  66. package/dist/api/health-confidence-adapter.js +0 -73
  67. package/dist/api/health-confidence.d.ts +0 -36
  68. package/dist/api/health-confidence.js +0 -141
  69. package/dist/api/hooks.d.ts +0 -50
  70. package/dist/api/hooks.js +0 -115
  71. package/dist/api/import.d.ts +0 -38
  72. package/dist/api/import.js +0 -87
  73. package/dist/api/ingest-event.d.ts +0 -65
  74. package/dist/api/mark.d.ts +0 -42
  75. package/dist/api/mark.js +0 -127
  76. package/dist/api/server-deps-a2.d.ts +0 -55
  77. package/dist/api/server-deps-a2.js +0 -138
  78. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  79. package/dist/api/server-deps-l2-l3.js +0 -123
  80. package/dist/api/server-deps-p1.d.ts +0 -84
  81. package/dist/api/server-deps-p2.d.ts +0 -32
  82. package/dist/api/server-deps-p2.js +0 -84
  83. package/dist/api/server-deps-p5.d.ts +0 -66
  84. package/dist/api/server-deps-p5.js +0 -139
  85. package/dist/api/viewer-static.d.ts +0 -30
  86. package/dist/api/viewer-static.js +0 -102
  87. package/dist/api/wire-up.d.ts +0 -54
  88. package/dist/api-impact.d.ts +0 -30
  89. package/dist/api-server.d.ts +0 -2
  90. package/dist/backfill-fts-anchor.d.ts +0 -15
  91. package/dist/backfill-source-type.d.ts +0 -20
  92. package/dist/churn.d.ts +0 -31
  93. package/dist/cli/answer.d.ts +0 -66
  94. package/dist/cli/conflict.d.ts +0 -38
  95. package/dist/cli/conflict.js +0 -282
  96. package/dist/cli/export.d.ts +0 -51
  97. package/dist/cli/export.js +0 -280
  98. package/dist/cli/hooks.d.ts +0 -54
  99. package/dist/cli/hooks.js +0 -133
  100. package/dist/cli/import.d.ts +0 -52
  101. package/dist/cli/import.js +0 -274
  102. package/dist/cli/mark.d.ts +0 -33
  103. package/dist/cli/mark.js +0 -130
  104. package/dist/cli/ocr-batch.d.ts +0 -12
  105. package/dist/cli/ocr-batch.js +0 -411
  106. package/dist/cli/snapshot-main.d.ts +0 -30
  107. package/dist/cli/snapshot-main.js +0 -47
  108. package/dist/cli/viewer.d.ts +0 -35
  109. package/dist/cli/viewer.js +0 -71
  110. package/dist/cli-telemetry.d.ts +0 -36
  111. package/dist/cli-telemetry.js +0 -150
  112. package/dist/compact.d.ts +0 -7
  113. package/dist/consolidate.d.ts +0 -18
  114. package/dist/consolidation.d.ts +0 -32
  115. package/dist/cross-agent-v2.d.ts +0 -45
  116. package/dist/cross-search.d.ts +0 -11
  117. package/dist/crystallize.d.ts +0 -43
  118. package/dist/db.d.ts +0 -11
  119. package/dist/dedup.d.ts +0 -1
  120. package/dist/detect-changes.d.ts +0 -29
  121. package/dist/digest.d.ts +0 -1
  122. package/dist/doctor.d.ts +0 -1
  123. package/dist/embed.d.ts +0 -57
  124. package/dist/evals.d.ts +0 -176
  125. package/dist/evals.js +0 -351
  126. package/dist/generate-user-profile.d.ts +0 -18
  127. package/dist/graphify-ingest.d.ts +0 -18
  128. package/dist/impact.d.ts +0 -39
  129. package/dist/index.d.ts +0 -2
  130. package/dist/ingest-entity.d.ts +0 -44
  131. package/dist/ingest.d.ts +0 -13
  132. package/dist/kg-llm.d.ts +0 -39
  133. package/dist/knowledge-graph.d.ts +0 -72
  134. package/dist/lib/answer/config.d.ts +0 -41
  135. package/dist/lib/answer/index.d.ts +0 -47
  136. package/dist/lib/answer/prompt.d.ts +0 -37
  137. package/dist/lib/answer/provider.d.ts +0 -47
  138. package/dist/lib/answer/retrieval.d.ts +0 -36
  139. package/dist/lib/answer/telemetry.d.ts +0 -99
  140. package/dist/lib/answer/types.d.ts +0 -108
  141. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  142. package/dist/lib/api/safe-error-message.d.ts +0 -70
  143. package/dist/lib/archive/common-passwords.d.ts +0 -37
  144. package/dist/lib/archive/common-passwords.js +0 -753
  145. package/dist/lib/archive/encryption.d.ts +0 -81
  146. package/dist/lib/archive/encryption.js +0 -236
  147. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  148. package/dist/lib/archive/enforce-strength.js +0 -70
  149. package/dist/lib/archive/entropy.d.ts +0 -34
  150. package/dist/lib/archive/entropy.js +0 -180
  151. package/dist/lib/archive/export-locking.d.ts +0 -102
  152. package/dist/lib/archive/export-locking.js +0 -202
  153. package/dist/lib/archive/format.d.ts +0 -20
  154. package/dist/lib/archive/format.js +0 -174
  155. package/dist/lib/archive/index.d.ts +0 -23
  156. package/dist/lib/archive/index.js +0 -17
  157. package/dist/lib/archive/manifest.d.ts +0 -53
  158. package/dist/lib/archive/manifest.js +0 -183
  159. package/dist/lib/archive/migration.d.ts +0 -36
  160. package/dist/lib/archive/migration.js +0 -100
  161. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  162. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  163. package/dist/lib/archive/orchestrator.d.ts +0 -166
  164. package/dist/lib/archive/orchestrator.js +0 -428
  165. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  166. package/dist/lib/archive/serializers/chunks.js +0 -113
  167. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  168. package/dist/lib/archive/serializers/embeddings.js +0 -115
  169. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  170. package/dist/lib/archive/serializers/kg.js +0 -184
  171. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  172. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  173. package/dist/lib/archive/server-deps.d.ts +0 -131
  174. package/dist/lib/archive/server-deps.js +0 -232
  175. package/dist/lib/archive/strength.d.ts +0 -50
  176. package/dist/lib/archive/strength.js +0 -77
  177. package/dist/lib/archive/types.d.ts +0 -159
  178. package/dist/lib/archive/types.js +0 -45
  179. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  180. package/dist/lib/archive/unpack-streaming.js +0 -255
  181. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  182. package/dist/lib/confidence/config.d.ts +0 -37
  183. package/dist/lib/confidence/config.js +0 -107
  184. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  185. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  186. package/dist/lib/confidence/db-shim.d.ts +0 -47
  187. package/dist/lib/confidence/db-shim.js +0 -141
  188. package/dist/lib/confidence/mark.d.ts +0 -58
  189. package/dist/lib/confidence/mark.js +0 -168
  190. package/dist/lib/confidence/ranking.d.ts +0 -69
  191. package/dist/lib/confidence/ranking.js +0 -101
  192. package/dist/lib/confidence/search-filter.d.ts +0 -44
  193. package/dist/lib/confidence/search-filter.js +0 -103
  194. package/dist/lib/confidence/types.d.ts +0 -146
  195. package/dist/lib/confidence/types.js +0 -20
  196. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  197. package/dist/lib/confidence/write-hooks.js +0 -159
  198. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  199. package/dist/lib/conflict/audit-fk-check.js +0 -131
  200. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  201. package/dist/lib/conflict/audit-writer.js +0 -133
  202. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  203. package/dist/lib/conflict/db-singleton.js +0 -61
  204. package/dist/lib/conflict/db.d.ts +0 -27
  205. package/dist/lib/conflict/db.js +0 -20
  206. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  207. package/dist/lib/conflict/detector-direct.js +0 -105
  208. package/dist/lib/conflict/evidence.d.ts +0 -24
  209. package/dist/lib/conflict/evidence.js +0 -76
  210. package/dist/lib/conflict/index.d.ts +0 -14
  211. package/dist/lib/conflict/index.js +0 -12
  212. package/dist/lib/conflict/scheduler.d.ts +0 -78
  213. package/dist/lib/conflict/scheduler.js +0 -111
  214. package/dist/lib/conflict/shadow.d.ts +0 -75
  215. package/dist/lib/conflict/shadow.js +0 -161
  216. package/dist/lib/conflict/types.d.ts +0 -133
  217. package/dist/lib/conflict/types.js +0 -19
  218. package/dist/lib/cost-cap.d.ts +0 -94
  219. package/dist/lib/deps/deps-registry.d.ts +0 -111
  220. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  221. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  222. package/dist/lib/eval-batch.d.ts +0 -34
  223. package/dist/lib/eval-batch.js +0 -103
  224. package/dist/lib/eval-metrics.d.ts +0 -36
  225. package/dist/lib/eval-metrics.js +0 -95
  226. package/dist/lib/eval.d.ts +0 -106
  227. package/dist/lib/eval.js +0 -343
  228. package/dist/lib/events/bus.d.ts +0 -135
  229. package/dist/lib/fts-anchor.d.ts +0 -1
  230. package/dist/lib/hooks/classifier.d.ts +0 -47
  231. package/dist/lib/hooks/classifier.js +0 -129
  232. package/dist/lib/hooks/config.d.ts +0 -49
  233. package/dist/lib/hooks/config.js +0 -106
  234. package/dist/lib/hooks/decorators.d.ts +0 -35
  235. package/dist/lib/hooks/decorators.js +0 -59
  236. package/dist/lib/hooks/pipeline.d.ts +0 -76
  237. package/dist/lib/hooks/pipeline.js +0 -213
  238. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  239. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  240. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  241. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  242. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  243. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  244. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  245. package/dist/lib/hooks/rate-limit.js +0 -122
  246. package/dist/lib/hooks/server-deps.d.ts +0 -61
  247. package/dist/lib/hooks/server-deps.js +0 -92
  248. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  249. package/dist/lib/hooks/source-allowlist.js +0 -53
  250. package/dist/lib/hooks/types.d.ts +0 -129
  251. package/dist/lib/hooks/types.js +0 -24
  252. package/dist/lib/hooks/worker.d.ts +0 -56
  253. package/dist/lib/hooks/worker.js +0 -150
  254. package/dist/lib/ingest-router.d.ts +0 -25
  255. package/dist/lib/ocr-detector.d.ts +0 -61
  256. package/dist/lib/ocr-detector.js +0 -138
  257. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  258. package/dist/lib/ocr-engine-stub.js +0 -190
  259. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  260. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  261. package/dist/lib/ocr-jobs.d.ts +0 -67
  262. package/dist/lib/ocr-jobs.js +0 -129
  263. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  264. package/dist/lib/op-audit.d.ts +0 -71
  265. package/dist/lib/privacy-br/detector.d.ts +0 -42
  266. package/dist/lib/privacy-br/detector.js +0 -130
  267. package/dist/lib/privacy-br/index.d.ts +0 -20
  268. package/dist/lib/privacy-br/index.js +0 -20
  269. package/dist/lib/privacy-br/integration.d.ts +0 -71
  270. package/dist/lib/privacy-br/integration.js +0 -74
  271. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  272. package/dist/lib/privacy-br/patterns.js +0 -434
  273. package/dist/lib/privacy-br/redact.d.ts +0 -42
  274. package/dist/lib/privacy-br/redact.js +0 -103
  275. package/dist/lib/privacy-br/types.d.ts +0 -55
  276. package/dist/lib/privacy-br/types.js +0 -25
  277. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  278. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  279. package/dist/lib/regex-extract/index.d.ts +0 -14
  280. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  281. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  282. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  283. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  284. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  285. package/dist/lib/regex-extract/types.d.ts +0 -48
  286. package/dist/lib/reranker.d.ts +0 -80
  287. package/dist/lib/shadow-tracker.d.ts +0 -191
  288. package/dist/lib/shadow-tracker.js +0 -384
  289. package/dist/lib/spo-injection.d.ts +0 -52
  290. package/dist/lib/telemetry-collector.d.ts +0 -158
  291. package/dist/lib/telemetry-collector.js +0 -249
  292. package/dist/lib/temporal-detector.d.ts +0 -27
  293. package/dist/lib/viewer/auth.d.ts +0 -37
  294. package/dist/lib/viewer/auth.js +0 -70
  295. package/dist/lib/viewer/backpressure.d.ts +0 -59
  296. package/dist/lib/viewer/backpressure.js +0 -100
  297. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  298. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  299. package/dist/lib/viewer/broadcast.d.ts +0 -66
  300. package/dist/lib/viewer/broadcast.js +0 -96
  301. package/dist/lib/viewer/event-types.d.ts +0 -132
  302. package/dist/lib/viewer/event-types.js +0 -74
  303. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  304. package/dist/lib/viewer/instrumentation.js +0 -224
  305. package/dist/lib/viewer/migration.d.ts +0 -23
  306. package/dist/lib/viewer/migration.js +0 -56
  307. package/dist/lib/viewer/redaction.d.ts +0 -44
  308. package/dist/lib/viewer/redaction.js +0 -139
  309. package/dist/lib/viewer/session.d.ts +0 -51
  310. package/dist/lib/viewer/session.js +0 -87
  311. package/dist/mcp/tools/answer.d.ts +0 -94
  312. package/dist/mcp/tools/archive.d.ts +0 -152
  313. package/dist/mcp/tools/archive.js +0 -170
  314. package/dist/mcp/tools/conflict.d.ts +0 -44
  315. package/dist/mcp/tools/conflict.js +0 -130
  316. package/dist/mcp/tools/hooks.d.ts +0 -29
  317. package/dist/mcp/tools/hooks.js +0 -78
  318. package/dist/mcp/tools/mark.d.ts +0 -38
  319. package/dist/mcp/tools/mark.js +0 -82
  320. package/dist/mcp/tools/viewer.d.ts +0 -58
  321. package/dist/mcp/tools/viewer.js +0 -64
  322. package/dist/mcp-server.d.ts +0 -2
  323. package/dist/metrics.d.ts +0 -3
  324. package/dist/noise-filter.d.ts +0 -18
  325. package/dist/notion-sync.d.ts +0 -7
  326. package/dist/notion-sync.js +0 -97
  327. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  328. package/dist/observability/adapters/a3-adapter.js +0 -83
  329. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  330. package/dist/observability/adapters/p1-adapter.js +0 -63
  331. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  332. package/dist/observability/adapters/p5-adapter.js +0 -71
  333. package/dist/observability/cardinality.d.ts +0 -61
  334. package/dist/observability/cardinality.js +0 -300
  335. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  336. package/dist/observability/collectors/db-stats.collector.js +0 -88
  337. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  338. package/dist/observability/collectors/eventbus.collector.js +0 -50
  339. package/dist/observability/collectors/process.collector.d.ts +0 -7
  340. package/dist/observability/collectors/process.collector.js +0 -93
  341. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  342. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  343. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  344. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  345. package/dist/observability/exporter.d.ts +0 -30
  346. package/dist/observability/exporter.js +0 -182
  347. package/dist/observability/index.d.ts +0 -22
  348. package/dist/observability/index.js +0 -21
  349. package/dist/observability/metrics.d.ts +0 -53
  350. package/dist/observability/metrics.js +0 -213
  351. package/dist/observability/privacy-guard.d.ts +0 -32
  352. package/dist/observability/privacy-guard.js +0 -116
  353. package/dist/observability/record.d.ts +0 -83
  354. package/dist/observability/record.js +0 -217
  355. package/dist/observability/registry.d.ts +0 -60
  356. package/dist/observability/registry.js +0 -93
  357. package/dist/observability/types.d.ts +0 -115
  358. package/dist/observability/types.js +0 -235
  359. package/dist/observability.d.ts +0 -131
  360. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  361. package/dist/plugins/nox-hooks/index.js +0 -99
  362. package/dist/primer.d.ts +0 -1
  363. package/dist/privacy/filter.d.ts +0 -27
  364. package/dist/privacy/patterns.d.ts +0 -29
  365. package/dist/privacy/tag-parser.d.ts +0 -24
  366. package/dist/project-context-gen.d.ts +0 -10
  367. package/dist/providers/embedding/gemini.d.ts +0 -73
  368. package/dist/providers/embedding/openai.d.ts +0 -76
  369. package/dist/providers/embedding/types.d.ts +0 -39
  370. package/dist/providers/embedding/voyage.d.ts +0 -36
  371. package/dist/providers/index.d.ts +0 -116
  372. package/dist/providers/llm/anthropic.d.ts +0 -29
  373. package/dist/providers/llm/chain.d.ts +0 -99
  374. package/dist/providers/llm/gemini.d.ts +0 -48
  375. package/dist/providers/llm/openai.d.ts +0 -64
  376. package/dist/providers/llm/types.d.ts +0 -47
  377. package/dist/providers/telemetry.d.ts +0 -87
  378. package/dist/providers/types.d.ts +0 -42
  379. package/dist/query-entity-count.d.ts +0 -54
  380. package/dist/reflect.d.ts +0 -26
  381. package/dist/reindex-errors.d.ts +0 -7
  382. package/dist/reindex.d.ts +0 -16
  383. package/dist/retention.d.ts +0 -40
  384. package/dist/salience.d.ts +0 -85
  385. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  386. package/dist/search-dedup.d.ts +0 -44
  387. package/dist/search-expansion.d.ts +0 -20
  388. package/dist/search.d.ts +0 -62
  389. package/dist/seh-detector.d.ts +0 -31
  390. package/dist/self-improve.d.ts +0 -1
  391. package/dist/session-distill.d.ts +0 -29
  392. package/dist/session-update.d.ts +0 -1
  393. package/dist/shared-memory.d.ts +0 -24
  394. package/dist/stats.d.ts +0 -1
  395. package/dist/temporal-retrieval.d.ts +0 -132
  396. package/dist/tier-manager.d.ts +0 -69
  397. package/dist/vectorize.d.ts +0 -16
  398. package/dist/watch.d.ts +0 -8
@@ -1,116 +0,0 @@
1
- /**
2
- * src/api/answer.ts — P1 T9: POST /api/answer.
3
- *
4
- * Framework-agnostic handler. Production `src/api/server.ts` mounts it via
5
- * a 5-line Fastify (or Express) adapter:
6
- *
7
- * fastify.post('/api/answer', async (req, reply) => {
8
- * const out = await handleAnswerRequest({
9
- * body: req.body,
10
- * headers: req.headers as Record<string, string | undefined>,
11
- * answer: realAnswer,
12
- * telemetryStore: getTelemetryStore(),
13
- * });
14
- * reply.code(out.status);
15
- * for (const [k, v] of Object.entries(out.headers)) reply.header(k, v);
16
- * return out.body;
17
- * });
18
- *
19
- * Same shape — kickoff §6 status codes:
20
- * 200 ok / 400 invalid body / 422 hallucination after retry /
21
- * 502 LLM unreachable / 503 retrieval empty / 504 timeout
22
- *
23
- * Response also sets X-Trace-Id, X-Model-Used, X-Retry-Count.
24
- *
25
- * Auth: this handler does NOT enforce auth — `src/api/server.ts` chains the
26
- * existing `requireApiToken()` middleware in front of it (same mechanism
27
- * as the other 7 routes). Documented as a precondition.
28
- */
29
- import type { AnswerOpts, AnswerResult } from "../lib/answer/index.js";
30
- import { type TelemetryStore } from "../lib/answer/telemetry.js";
31
- export interface AnswerHttpRequest {
32
- question: string;
33
- top_k?: number;
34
- max_tokens?: number;
35
- provider?: string;
36
- model?: string;
37
- temperature?: number;
38
- no_citations?: boolean;
39
- trace_id?: string;
40
- }
41
- export interface AnswerHttpResponseSuccess {
42
- answer: string;
43
- citations: AnswerResult["citations"];
44
- metadata: AnswerResult["metadata"];
45
- trace_id: string;
46
- }
47
- export interface AnswerHttpResponseError {
48
- error: true;
49
- reason: string;
50
- message: string;
51
- trace_id: string;
52
- }
53
- export type AnswerHttpResponse = AnswerHttpResponseSuccess | AnswerHttpResponseError;
54
- export interface HandleAnswerArgs {
55
- /** Parsed JSON body (or raw string we coerce). */
56
- body: unknown;
57
- /** Headers (case-insensitive lookups expected by caller). */
58
- headers?: Record<string, string | string[] | undefined>;
59
- /** Auth check seam: when present, must return true to allow. Default: allow. */
60
- authCheck?: (headers: Record<string, string | string[] | undefined>) => boolean;
61
- /** Test seam — replace answer() under test. */
62
- answer?: (opts: AnswerOpts) => Promise<AnswerResult>;
63
- /** Optional telemetry sink. */
64
- telemetryStore?: TelemetryStore;
65
- /** Session correlation passthrough (from middleware). */
66
- sessionId?: string | null;
67
- }
68
- export interface HandlerOutput {
69
- status: number;
70
- headers: Record<string, string>;
71
- body: AnswerHttpResponse;
72
- }
73
- export declare function validateBody(body: unknown): AnswerHttpRequest;
74
- export declare function statusFromReason(reason: string): number;
75
- export declare function handleAnswerRequest(args: HandleAnswerArgs): Promise<HandlerOutput>;
76
- export declare const REQUEST_SCHEMA: {
77
- readonly $schema: "http://json-schema.org/draft-07/schema#";
78
- readonly type: "object";
79
- readonly required: readonly ["question"];
80
- readonly additionalProperties: false;
81
- readonly properties: {
82
- readonly question: {
83
- readonly type: "string";
84
- readonly minLength: 1;
85
- readonly maxLength: 2000;
86
- };
87
- readonly top_k: {
88
- readonly type: "integer";
89
- readonly minimum: 1;
90
- readonly maximum: 20;
91
- };
92
- readonly max_tokens: {
93
- readonly type: "integer";
94
- readonly minimum: 64;
95
- readonly maximum: 8192;
96
- };
97
- readonly provider: {
98
- readonly type: "string";
99
- };
100
- readonly model: {
101
- readonly type: "string";
102
- };
103
- readonly temperature: {
104
- readonly type: "number";
105
- readonly minimum: 0;
106
- readonly maximum: 1;
107
- };
108
- readonly no_citations: {
109
- readonly type: "boolean";
110
- };
111
- readonly trace_id: {
112
- readonly type: "string";
113
- readonly maxLength: 64;
114
- };
115
- };
116
- };
@@ -1,72 +0,0 @@
1
- /**
2
- * G4 — Validator/schema drift patch for /api/answer
3
- *
4
- * Gap identified in THREAT-MODEL.md §3.1 (DoS / validator drift):
5
- * "top_k schema declares max=20 but validateBody() doesn't enforce it.
6
- * User could request top_k=10000 and crash service."
7
- *
8
- * This file documents the exact patch to apply to staged-P1/edits/src/api/answer.ts.
9
- * The validateBody() function must enforce ALL OpenAPI schema constraints at runtime,
10
- * not just type checks.
11
- *
12
- * Ref: THREAT-MODEL.md G4 (medium priority).
13
- */
14
- /**
15
- * ValidationError shape for 422 responses:
16
- *
17
- * { error: "Validation failed", details: { field: string, got: unknown, max?: number, min?: number } }
18
- */
19
- export interface ValidationDetails {
20
- field: string;
21
- got: unknown;
22
- max?: number;
23
- min?: number;
24
- reason?: string;
25
- }
26
- export declare class ValidationError extends Error {
27
- readonly status = 422;
28
- readonly reason = "validation_failed";
29
- readonly details: ValidationDetails;
30
- constructor(details: ValidationDetails);
31
- }
32
- /**
33
- * Schema constraints aligned with OpenAPI JSON schema in answer.ts.
34
- * Single source of truth — change here only, no duplication.
35
- */
36
- export declare const ANSWER_CONSTRAINTS: {
37
- readonly question: {
38
- readonly minLength: 1;
39
- readonly maxLength: 2000;
40
- };
41
- readonly top_k: {
42
- readonly min: 1;
43
- readonly max: 20;
44
- };
45
- readonly max_tokens: {
46
- readonly min: 64;
47
- readonly max: 8192;
48
- };
49
- readonly temperature: {
50
- readonly min: 0;
51
- readonly max: 1;
52
- };
53
- readonly trace_id: {
54
- readonly maxLength: 64;
55
- };
56
- };
57
- /**
58
- * validateBodyStrict — drop-in replacement for validateBody() in answer.ts.
59
- *
60
- * Differences from original:
61
- * 1. top_k: enforces min=1, max=20 (rejects 10000 → 422)
62
- * 2. max_tokens: enforces min=64, max=8192
63
- * 3. temperature: enforces min=0, max=1
64
- * 4. All violations return 422 with structured ValidationError (not 400 HttpError)
65
- *
66
- * Backward compatibility: callers that catch HttpError(400) should also handle
67
- * ValidationError(422). Existing smoke tests remain green since valid payloads
68
- * pass all checks.
69
- */
70
- export declare function validateAnswerConstraints(field: "top_k", value: number): void;
71
- export declare function validateAnswerConstraints(field: "max_tokens", value: number): void;
72
- export declare function validateAnswerConstraints(field: "temperature", value: number): void;
@@ -1,64 +0,0 @@
1
- /**
2
- * D2 — Brief diversity/novelty term (re-rank pós-salience DENTRO do brief).
3
- *
4
- * Spec (memoria-nox): specs/2026-06-07-D2-brief-diversity-term.md
5
- * Origem: D1 (feedback loop do canário, 2026-06-07) + D3 (medição limpa,
6
- * 2026-06-13). D3 cravou: 83 chunks distintos servem ~6.700 serves/dia
7
- * (0,18% diversidade), mediana 48d, 19/81 high-pain≥0.9, e 510-931 chunks
8
- * recentes relevantes nunca servidos. Follow-up rate via search/answer é
9
- * NÃO-mensurável (3 buscas genuínas / 0 answers em 7d) — gate redesenhado
10
- * sobre diversidade + freshness + high-pain floor, sem follow-up.
11
- *
12
- * Invariantes (§2 da spec — NÃO violar):
13
- * 1. NÃO forka `calculateSalience` (regra #5/#17 do repo). O termo de
14
- * diversidade é re-rank pós-salience APENAS dentro do brief — nunca
15
- * um peso novo na fórmula (que afetaria search também).
16
- * 2. Read-only sobre `chunks` (promessa F1: access_count intocado). A
17
- * serve-history vem de `brief_log` (tabela própria).
18
- * 3. Fail-open: diversidade nunca derruba o priming.
19
- * 4. High-pain floor: incidents pain ≥ PAIN_FLOOR são imunes ao penalty.
20
- *
21
- * Este módulo só carrega lógica PURA (config + penalty + diff). As queries
22
- * (serveCounts, fetchFreshCandidates) e a integração com buildBrief vivem em
23
- * brief.ts, onde o pool/pick já existem.
24
- */
25
- export type DiversityMode = "off" | "shadow" | "active";
26
- export interface DiversityConfig {
27
- mode: DiversityMode;
28
- /** Janela "já servido" pro penalty (SQL modifier, ex "-72 hours"). */
29
- windowSql: string;
30
- /** Força do novelty penalty. penalty = min(pMax, λ·log1p(n_serves)). */
31
- lambda: number;
32
- /** Teto do penalty (≈ 1 termo de salience). Impede zerar candidatos. */
33
- pMax: number;
34
- /** pain ≥ painFloor ⇒ penalty = 0 (incidents críticos imunes). */
35
- painFloor: number;
36
- /** Nº de slots reservados pra freshness (novidade recente relevante). */
37
- freshSlots: number;
38
- /** Piso de relevância pro freshness slot (não trazer lixo recente). */
39
- freshMinImp: number;
40
- freshMinPain: number;
41
- /** Idade máx (dias) pra contar como "recente" no freshness slot. */
42
- freshMaxAgeDays: number;
43
- }
44
- /** Defaults conservadores calibrados em D3 (2026-06-13). */
45
- export declare const DIVERSITY_DEFAULTS: Omit<DiversityConfig, "mode">;
46
- /** Lê NOX_BRIEF_DIVERSITY* do env; default off + calibração D3. */
47
- export declare function diversityConfigFromEnv(env?: Record<string, string | undefined>): DiversityConfig;
48
- /**
49
- * Novelty penalty (parte A). Satura em log pra que servir 2.000× ≈ servir 100×;
50
- * cap em pMax pra nunca esmagar; floor de pain pra blindar incidents críticos.
51
- */
52
- export declare function noveltyPenalty(nServes: number, pain: number, cfg: DiversityConfig): number;
53
- /** brief_score = salience − penalty (re-rank pós-salience, invariante #1). */
54
- export declare function briefScore(salience: number, nServes: number, pain: number, cfg: DiversityConfig): number;
55
- export interface BriefDiff {
56
- current_ids: number[];
57
- alt_ids: number[];
58
- would_enter: number[];
59
- would_leave: number[];
60
- fresh_added: number[];
61
- churn: number;
62
- }
63
- /** Diff estrutural pro shadow log (gate D2 mede sobre isto + brief_log real). */
64
- export declare function diffBriefs(currentIds: number[], altIds: number[], freshIds?: number[]): BriefDiff;
@@ -1,114 +0,0 @@
1
- /**
2
- * F1 — GET /api/brief (Session Priming Loop, fase 1)
3
- *
4
- * Pointer-pattern priming digest: top-N chunks por salience filtrados por
5
- * escopo. Toda sessão (agente OpenClaw, Claude Code Mac, qualquer cliente
6
- * MCP/HTTP) nasce contextualizada sem search cego.
7
- *
8
- * Specs (memoria-nox):
9
- * - PRD: specs/2026-06-04-session-priming-loop.md (§6 contrato)
10
- * - Impl: specs/2026-06-04-F1-api-brief-implementation.md (T0 findings)
11
- *
12
- * Invariantes:
13
- * - Read-only sobre `chunks`. NÃO toca `chunks.access_count` — o sinal
14
- * orgânico fica 100% puro pro audit mensal do Cipher (high-pain órfãos).
15
- * Tracking de serving vai pra tabela própria `brief_log`.
16
- * - NÃO altera scoring de search (regra #5 do repo) — consome
17
- * `calculateSalience` canônica as-is, sem fork nem pesos próprios.
18
- * - Framework-agnostic (mesmo padrão de src/api/conflict.ts): handler puro
19
- * testável; api-server.ts faz o dispatch HTTP.
20
- *
21
- * Scope mapping (T0 2026-06-04, validado em prod 100.5k chunks):
22
- * - agent → `sessions/<persona>/%` (cipher 7.6k, atlas 3.8k…)
23
- * - scope → `memory/mac-docs/<scope>/%` (NUVIVI, PESSOAL, PPR…)
24
- * | `shared/imports/Claude/Projetos/<scope>/%`
25
- * | `shared/imports/<scope>/%`
26
- * | `<scope>/%` (namespaces top-level)
27
- * - global → sem filtro de path
28
- *
29
- * Changelog:
30
- * - v1.1 (gate T7): age por source_date; dedup exato (title,one_liner);
31
- * strip HTML no one_liner.
32
- * - v1.2 (gate F3 real, Nox): (a) collapse de near-dups por Jaccard de
33
- * tokens; (b) com `agent`, união garantida agente ∪ scope/global
34
- * (~n/2 slots cada, backfill mútuo).
35
- */
36
- import { type DiversityConfig, type BriefDiff } from "./brief-diversity.js";
37
- interface PreparedStatement {
38
- all(...args: unknown[]): unknown[];
39
- get(...args: unknown[]): unknown;
40
- run(...args: unknown[]): unknown;
41
- }
42
- export interface BriefDb {
43
- prepare(sql: string): PreparedStatement;
44
- exec(sql: string): void;
45
- }
46
- export interface BriefItem {
47
- id: number;
48
- title: string;
49
- one_liner: string;
50
- type: string | null;
51
- pain: number;
52
- salience: number;
53
- age_days: number;
54
- }
55
- export interface BriefResult {
56
- scope: string;
57
- agent?: string;
58
- generated_at: string;
59
- items: BriefItem[];
60
- token_estimate: number;
61
- }
62
- export type BriefResponse = {
63
- status: number;
64
- body: unknown;
65
- } | {
66
- status: number;
67
- text: string;
68
- };
69
- export interface BriefParams {
70
- scope: string;
71
- agent?: string;
72
- n: number;
73
- format: "json" | "text";
74
- sinceSql?: string;
75
- }
76
- export declare function parseBriefParams(q: Record<string, string>): {
77
- ok: true;
78
- params: BriefParams;
79
- } | {
80
- ok: false;
81
- error: string;
82
- };
83
- /** Escapa metachars do LIKE (`%`, `_`, `\`) no trecho dinâmico — os wildcards
84
- * `%` dos patterns são adicionados depois. Queries usam `ESCAPE '\'`. */
85
- export declare function escapeLike(s: string): string;
86
- export declare function scopePatterns(scope: string, agent?: string): string[];
87
- export declare function tokenSignature(title: string, oneLiner: string): Set<string>;
88
- export declare function isNearDup(a: Set<string>, b: Set<string>): boolean;
89
- /** Primeira linha "de conteúdo": pula vazias, fences de frontmatter (---) e
90
- * marcação estrutural; strip de tags HTML (docs OCR/import vazam <u> etc.),
91
- * heading/list markers; cap ONE_LINER_MAX. */
92
- export declare function extractOneLiner(text: string | null | undefined): string;
93
- /** Datas do SQLite vêm "YYYY-MM-DD HH:MM:SS" (UTC) ou "YYYY-MM-DD" (source_date).
94
- * Date.parse direto trata date-only como UTC; o formato com espaço precisa
95
- * virar ISO + Z explícito pra não cair em timezone local. */
96
- export declare function parseDbDateMs(ref: string): number;
97
- export declare function titleFromSourceFile(sourceFile: string | null | undefined): string;
98
- export declare function ensureBriefLog(db: BriefDb): void;
99
- /** Test-only: reseta o memo de criação (cada DB de teste é novo). */
100
- export declare function _resetBriefLogMemo(): void;
101
- export declare function buildBrief(db: BriefDb, params: BriefParams, nowMs?: number): BriefResult;
102
- /** Parte A — nº de serves por chunk na janela T (1 query agregada, índice
103
- * idx_brief_log_chunk). Read-only sobre brief_log; tabela própria. */
104
- export declare function serveCounts(db: BriefDb, ids: number[], windowSql: string): Map<number, number>;
105
- /** D2 — buildBrief com diversidade (A novelty penalty + B freshness slot).
106
- * Retorna o surface do `mode` + o brief atual + o diff (pra shadow log). */
107
- export declare function buildBriefDiverse(db: BriefDb, params: BriefParams, cfg: DiversityConfig, nowMs?: number): {
108
- current: BriefResult;
109
- alt: BriefResult;
110
- diff: BriefDiff;
111
- };
112
- export declare function renderBriefText(result: BriefResult): string;
113
- export declare function handleBrief(db: BriefDb, query: Record<string, string>): BriefResponse;
114
- export {};
@@ -1,33 +0,0 @@
1
- /**
2
- * L2 T8 — HTTP API handlers.
3
- *
4
- * Endpoints (mounted on nox-mem-api at :18802):
5
- * GET /api/conflict?status=open&limit=20 → list audit rows
6
- * GET /api/conflict/:id → row + evidence
7
- * POST /api/conflict/:id/resolve → write resolution
8
- *
9
- * Implementation is framework-agnostic: pure handlers operating on
10
- * a `RequestInput` shape so they can be wired to Express, native http,
11
- * or tested directly. No external HTTP library imported.
12
- *
13
- * All responses are JSON. Errors return {error: ...} with HTTP status.
14
- */
15
- import type { DBHandle } from "../lib/conflict/db.js";
16
- export interface RequestInput {
17
- method: "GET" | "POST";
18
- path: string;
19
- query?: Record<string, string | undefined>;
20
- body?: unknown;
21
- /** Caller actor id — populated from session/auth middleware in production. */
22
- actor?: string;
23
- }
24
- export interface ApiResponse {
25
- status: number;
26
- body: unknown;
27
- }
28
- /**
29
- * Dispatch incoming request to the appropriate handler. Returns 404 when
30
- * the path does not match any conflict endpoint (caller can fall through
31
- * to other routes).
32
- */
33
- export declare function dispatchConflictApi(db: DBHandle, req: RequestInput): ApiResponse;
@@ -1,143 +0,0 @@
1
- /**
2
- * L2 T8 — HTTP API handlers.
3
- *
4
- * Endpoints (mounted on nox-mem-api at :18802):
5
- * GET /api/conflict?status=open&limit=20 → list audit rows
6
- * GET /api/conflict/:id → row + evidence
7
- * POST /api/conflict/:id/resolve → write resolution
8
- *
9
- * Implementation is framework-agnostic: pure handlers operating on
10
- * a `RequestInput` shape so they can be wired to Express, native http,
11
- * or tested directly. No external HTTP library imported.
12
- *
13
- * All responses are JSON. Errors return {error: ...} with HTTP status.
14
- */
15
- import { getConflictById, listConflicts, updateConflictStatus, } from "../lib/conflict/audit-writer.js";
16
- import { collectEvidence } from "../lib/conflict/evidence.js";
17
- const VALID_STATUSES = [
18
- "open",
19
- "reviewed",
20
- "resolved_pick_one",
21
- "resolved_both_valid",
22
- "resolved_merged",
23
- "dismissed",
24
- ];
25
- /**
26
- * Dispatch incoming request to the appropriate handler. Returns 404 when
27
- * the path does not match any conflict endpoint (caller can fall through
28
- * to other routes).
29
- */
30
- export function dispatchConflictApi(db, req) {
31
- const { method, path } = req;
32
- if (method === "GET" && path === "/api/conflict") {
33
- return handleList(db, req);
34
- }
35
- const idMatch = /^\/api\/conflict\/(\d+)$/.exec(path);
36
- if (method === "GET" && idMatch) {
37
- return handleShow(db, Number(idMatch[1]));
38
- }
39
- const resolveMatch = /^\/api\/conflict\/(\d+)\/resolve$/.exec(path);
40
- if (method === "POST" && resolveMatch) {
41
- return handleResolve(db, Number(resolveMatch[1]), req);
42
- }
43
- return { status: 404, body: { error: "not_found", path } };
44
- }
45
- function handleList(db, req) {
46
- const statusParam = req.query?.status ?? "open";
47
- if (!VALID_STATUSES.includes(statusParam)) {
48
- return {
49
- status: 400,
50
- body: { error: "invalid_status", value: statusParam },
51
- };
52
- }
53
- const limitParam = req.query?.limit;
54
- let limit = 20;
55
- if (limitParam !== undefined) {
56
- const n = Number(limitParam);
57
- if (!Number.isFinite(n) || n <= 0 || n > 500) {
58
- return { status: 400, body: { error: "invalid_limit", value: limitParam } };
59
- }
60
- limit = n;
61
- }
62
- const rows = listConflicts(db, statusParam, limit);
63
- return { status: 200, body: { count: rows.length, rows } };
64
- }
65
- function handleShow(db, id) {
66
- const row = getConflictById(db, id);
67
- if (!row)
68
- return { status: 404, body: { error: "conflict_not_found", id } };
69
- const conflict = {
70
- kind: row.kind,
71
- subject_entity_id: row.subject_entity_id,
72
- predicate: row.predicate,
73
- variants: row.variants,
74
- };
75
- const evidence = collectEvidence(db, conflict);
76
- return { status: 200, body: { row, evidence } };
77
- }
78
- function handleResolve(db, id, req) {
79
- const row = getConflictById(db, id);
80
- if (!row)
81
- return { status: 404, body: { error: "conflict_not_found", id } };
82
- const body = req.body;
83
- if (!body || typeof body !== "object") {
84
- return { status: 400, body: { error: "missing_body" } };
85
- }
86
- const kind = body.kind;
87
- const VALID_KIND = ["pick_one", "both_valid", "merged", "dismissed"];
88
- if (!kind || !VALID_KIND.includes(kind)) {
89
- return { status: 400, body: { error: "invalid_kind", value: kind } };
90
- }
91
- const actor = req.actor ?? "api";
92
- let resolution;
93
- switch (kind) {
94
- case "pick_one":
95
- if (typeof body.picked_relation_id !== "number") {
96
- return { status: 400, body: { error: "picked_relation_id_required" } };
97
- }
98
- resolution = {
99
- status: "resolved_pick_one",
100
- resolution_kind: "pick_one",
101
- resolved_by: actor,
102
- picked_relation_id: body.picked_relation_id,
103
- notes: body.notes,
104
- };
105
- break;
106
- case "both_valid":
107
- resolution = {
108
- status: "resolved_both_valid",
109
- resolution_kind: "both_valid",
110
- resolved_by: actor,
111
- notes: body.notes,
112
- };
113
- break;
114
- case "merged":
115
- if (typeof body.merge_target !== "string" || body.merge_target === "") {
116
- return { status: 400, body: { error: "merge_target_required" } };
117
- }
118
- resolution = {
119
- status: "resolved_merged",
120
- resolution_kind: "merged",
121
- resolved_by: actor,
122
- merge_target: body.merge_target,
123
- notes: body.notes,
124
- };
125
- break;
126
- case "dismissed":
127
- resolution = {
128
- status: "dismissed",
129
- resolution_kind: "dismissed",
130
- resolved_by: actor,
131
- notes: body.notes,
132
- };
133
- break;
134
- }
135
- try {
136
- updateConflictStatus(db, id, resolution);
137
- }
138
- catch (err) {
139
- return { status: 409, body: { error: "resolution_failed", message: err.message } };
140
- }
141
- const updated = getConflictById(db, id);
142
- return { status: 200, body: { row: updated } };
143
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * src/api/cors.ts — Server-side CORS handler for nox-mem API.
3
- *
4
- * Scope: Allows browser extensions (Chrome MV3 + Firefox) to call
5
- * http://127.0.0.1:18802 without CORS blocks. Required by P7 extension
6
- * (PR #96).
7
- *
8
- * Security posture:
9
- * - Default allowlist: chrome-extension://* and moz-extension://* only.
10
- * - NO `Access-Control-Allow-Origin: *` — reflects only matched origins.
11
- * - Extra origins opt-in via NOX_CORS_EXTRA_ORIGINS env var (comma-separated
12
- * regex strings). Requires explicit operator action; not enabled by default.
13
- * - Regex patterns are anchored and strict (chrome IDs are exactly 32
14
- * lowercase alpha chars; Firefox UUIDs are exactly 36-char hex with dashes).
15
- * - Must be called BEFORE routing so OPTIONS preflight short-circuits.
16
- *
17
- * Usage in api-server.ts:
18
- *
19
- * import { applyCorsHeaders, handlePreflight } from "./api/cors.js";
20
- *
21
- * async function handleRequest(req: IncomingMessage, res: ServerResponse) {
22
- * if (handlePreflight(req, res)) return; // OPTIONS → 204 + headers
23
- * applyCorsHeaders(req, res); // all other methods
24
- * // ... existing routing ...
25
- * }
26
- */
27
- import type { IncomingMessage, ServerResponse } from "node:http";
28
- /**
29
- * Checks whether `origin` matches any of the allowed patterns.
30
- * Returns `true` if matched, `false` otherwise.
31
- */
32
- export declare function isOriginAllowed(origin: string, extraOrigins?: RegExp[]): boolean;
33
- export interface CorsOptions {
34
- /** Additional origin regexes beyond the built-in extension patterns. */
35
- extraOrigins?: RegExp[];
36
- /**
37
- * Set Access-Control-Allow-Credentials: true.
38
- * Only useful when the caller uses `withCredentials: true` in XHR/fetch.
39
- * Off by default — extensions don't need it for basic JSON calls.
40
- */
41
- allowCredentials?: boolean;
42
- }
43
- /**
44
- * Applies CORS headers to `res` if `req.headers.origin` is in the allowlist.
45
- * No-op when:
46
- * - Request has no Origin header (same-origin or non-browser request).
47
- * - Origin does not match any allowed pattern.
48
- *
49
- * Sets:
50
- * - `Access-Control-Allow-Origin` — echoes the matched origin (never "*")
51
- * - `Vary: Origin` — prevents caching cross-origin mismatch
52
- * - `Access-Control-Allow-Methods` — GET, POST, OPTIONS
53
- * - `Access-Control-Allow-Headers` — Content-Type, Authorization
54
- * - `Access-Control-Max-Age` — 86400 (24 h preflight cache)
55
- * - `Access-Control-Allow-Credentials` — only when opts.allowCredentials
56
- */
57
- export declare function applyCorsHeaders(req: IncomingMessage, res: ServerResponse, opts?: CorsOptions): void;
58
- /**
59
- * Handles an HTTP OPTIONS preflight request.
60
- *
61
- * If `req.method === "OPTIONS"`:
62
- * - Applies CORS headers (if origin matches)
63
- * - Responds 204 No Content
64
- * - Returns `true` — caller must stop processing
65
- *
66
- * If method is not OPTIONS:
67
- * - Returns `false` — caller continues routing normally
68
- *
69
- * Pattern:
70
- *
71
- * if (handlePreflight(req, res)) return;
72
- */
73
- export declare function handlePreflight(req: IncomingMessage, res: ServerResponse, opts?: CorsOptions): boolean;