nox-mem 3.1.1 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/README.md +24 -16
  2. package/dist/__tests__/brief-diversity.test.js +266 -0
  3. package/dist/__tests__/brief.test.js +287 -0
  4. package/dist/__tests__/churn.test.js +66 -0
  5. package/dist/__tests__/edge-typing.test.js +99 -0
  6. package/dist/__tests__/ingest-event.test.js +151 -0
  7. package/dist/__tests__/op-audit-e2e.test.js +130 -0
  8. package/dist/__tests__/pragma-alignment.test.js +123 -0
  9. package/dist/__tests__/reranker.test.js +326 -0
  10. package/dist/__tests__/retention.test.js +99 -0
  11. package/dist/__tests__/search-track-access.test.js +49 -0
  12. package/dist/__tests__/spo-injection.test.js +172 -0
  13. package/dist/__tests__/temporal-detector.test.js +103 -0
  14. package/dist/api/wire-up.js +12 -381
  15. package/dist/api-server.js +6 -102
  16. package/dist/crystallize.js +3 -5
  17. package/dist/db.js +61 -2
  18. package/dist/embed.js +23 -2
  19. package/dist/index.js +1 -22
  20. package/dist/knowledge-graph.js +20 -0
  21. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  22. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  23. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  24. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  25. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  26. package/dist/lib/answer/provider.js +29 -4
  27. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  28. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  29. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  30. package/dist/lib/events/__tests__/bus.test.js +208 -0
  31. package/dist/lib/ingest-router.js +0 -43
  32. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  33. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  34. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  35. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  36. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  37. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  38. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  39. package/dist/privacy/__tests__/filter.test.js +352 -0
  40. package/dist/providers/__tests__/conformance-extended.test.js +249 -0
  41. package/dist/providers/__tests__/conformance.test.js +98 -0
  42. package/dist/providers/__tests__/cost-cap.test.js +151 -0
  43. package/dist/providers/__tests__/e2e-real.test.js +79 -0
  44. package/dist/providers/__tests__/factory.test.js +80 -0
  45. package/dist/providers/__tests__/fallback.test.js +223 -0
  46. package/dist/providers/__tests__/gemini.test.js +191 -0
  47. package/dist/providers/__tests__/health.test.js +128 -0
  48. package/dist/providers/__tests__/telemetry.test.js +219 -0
  49. package/dist/reindex.js +2 -2
  50. package/package.json +3 -4
  51. package/dist/api/answer.d.ts +0 -116
  52. package/dist/api/answer.validate-patch.d.ts +0 -72
  53. package/dist/api/brief-diversity.d.ts +0 -64
  54. package/dist/api/brief.d.ts +0 -114
  55. package/dist/api/conflict.d.ts +0 -33
  56. package/dist/api/conflict.js +0 -143
  57. package/dist/api/cors.d.ts +0 -73
  58. package/dist/api/events-stream-limited.d.ts +0 -133
  59. package/dist/api/events-stream-limited.js +0 -217
  60. package/dist/api/events-stream.d.ts +0 -53
  61. package/dist/api/events-stream.js +0 -125
  62. package/dist/api/export.d.ts +0 -42
  63. package/dist/api/export.js +0 -85
  64. package/dist/api/health-confidence-adapter.d.ts +0 -29
  65. package/dist/api/health-confidence-adapter.js +0 -73
  66. package/dist/api/health-confidence.d.ts +0 -36
  67. package/dist/api/health-confidence.js +0 -141
  68. package/dist/api/hooks.d.ts +0 -50
  69. package/dist/api/hooks.js +0 -115
  70. package/dist/api/import.d.ts +0 -38
  71. package/dist/api/import.js +0 -87
  72. package/dist/api/ingest-event.d.ts +0 -65
  73. package/dist/api/mark.d.ts +0 -42
  74. package/dist/api/mark.js +0 -127
  75. package/dist/api/server-deps-a2.d.ts +0 -55
  76. package/dist/api/server-deps-a2.js +0 -138
  77. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  78. package/dist/api/server-deps-l2-l3.js +0 -123
  79. package/dist/api/server-deps-p1.d.ts +0 -84
  80. package/dist/api/server-deps-p2.d.ts +0 -32
  81. package/dist/api/server-deps-p2.js +0 -84
  82. package/dist/api/server-deps-p5.d.ts +0 -66
  83. package/dist/api/server-deps-p5.js +0 -139
  84. package/dist/api/viewer-static.d.ts +0 -30
  85. package/dist/api/viewer-static.js +0 -102
  86. package/dist/api/wire-up.d.ts +0 -54
  87. package/dist/api-impact.d.ts +0 -30
  88. package/dist/api-server.d.ts +0 -2
  89. package/dist/backfill-fts-anchor.d.ts +0 -15
  90. package/dist/backfill-source-type.d.ts +0 -20
  91. package/dist/churn.d.ts +0 -31
  92. package/dist/cli/answer.d.ts +0 -66
  93. package/dist/cli/conflict.d.ts +0 -38
  94. package/dist/cli/conflict.js +0 -282
  95. package/dist/cli/export.d.ts +0 -51
  96. package/dist/cli/export.js +0 -280
  97. package/dist/cli/hooks.d.ts +0 -54
  98. package/dist/cli/hooks.js +0 -133
  99. package/dist/cli/import.d.ts +0 -52
  100. package/dist/cli/import.js +0 -274
  101. package/dist/cli/mark.d.ts +0 -33
  102. package/dist/cli/mark.js +0 -130
  103. package/dist/cli/ocr-batch.d.ts +0 -12
  104. package/dist/cli/ocr-batch.js +0 -411
  105. package/dist/cli/snapshot-main.d.ts +0 -30
  106. package/dist/cli/snapshot-main.js +0 -47
  107. package/dist/cli/viewer.d.ts +0 -35
  108. package/dist/cli/viewer.js +0 -71
  109. package/dist/cli-telemetry.d.ts +0 -36
  110. package/dist/cli-telemetry.js +0 -150
  111. package/dist/compact.d.ts +0 -7
  112. package/dist/consolidate.d.ts +0 -18
  113. package/dist/consolidation.d.ts +0 -32
  114. package/dist/cross-agent-v2.d.ts +0 -45
  115. package/dist/cross-search.d.ts +0 -11
  116. package/dist/crystallize.d.ts +0 -43
  117. package/dist/db.d.ts +0 -11
  118. package/dist/dedup.d.ts +0 -1
  119. package/dist/detect-changes.d.ts +0 -29
  120. package/dist/digest.d.ts +0 -1
  121. package/dist/doctor.d.ts +0 -1
  122. package/dist/embed.d.ts +0 -57
  123. package/dist/evals.d.ts +0 -176
  124. package/dist/evals.js +0 -351
  125. package/dist/generate-user-profile.d.ts +0 -18
  126. package/dist/graphify-ingest.d.ts +0 -18
  127. package/dist/impact.d.ts +0 -39
  128. package/dist/index.d.ts +0 -2
  129. package/dist/ingest-entity.d.ts +0 -44
  130. package/dist/ingest.d.ts +0 -13
  131. package/dist/kg-llm.d.ts +0 -39
  132. package/dist/knowledge-graph.d.ts +0 -72
  133. package/dist/lib/answer/config.d.ts +0 -41
  134. package/dist/lib/answer/index.d.ts +0 -47
  135. package/dist/lib/answer/prompt.d.ts +0 -37
  136. package/dist/lib/answer/provider.d.ts +0 -47
  137. package/dist/lib/answer/retrieval.d.ts +0 -36
  138. package/dist/lib/answer/telemetry.d.ts +0 -99
  139. package/dist/lib/answer/types.d.ts +0 -108
  140. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  141. package/dist/lib/api/safe-error-message.d.ts +0 -70
  142. package/dist/lib/archive/common-passwords.d.ts +0 -37
  143. package/dist/lib/archive/common-passwords.js +0 -753
  144. package/dist/lib/archive/encryption.d.ts +0 -81
  145. package/dist/lib/archive/encryption.js +0 -236
  146. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  147. package/dist/lib/archive/enforce-strength.js +0 -70
  148. package/dist/lib/archive/entropy.d.ts +0 -34
  149. package/dist/lib/archive/entropy.js +0 -180
  150. package/dist/lib/archive/export-locking.d.ts +0 -102
  151. package/dist/lib/archive/export-locking.js +0 -202
  152. package/dist/lib/archive/format.d.ts +0 -20
  153. package/dist/lib/archive/format.js +0 -174
  154. package/dist/lib/archive/index.d.ts +0 -23
  155. package/dist/lib/archive/index.js +0 -17
  156. package/dist/lib/archive/manifest.d.ts +0 -53
  157. package/dist/lib/archive/manifest.js +0 -183
  158. package/dist/lib/archive/migration.d.ts +0 -36
  159. package/dist/lib/archive/migration.js +0 -100
  160. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  161. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  162. package/dist/lib/archive/orchestrator.d.ts +0 -166
  163. package/dist/lib/archive/orchestrator.js +0 -428
  164. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  165. package/dist/lib/archive/serializers/chunks.js +0 -113
  166. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  167. package/dist/lib/archive/serializers/embeddings.js +0 -115
  168. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  169. package/dist/lib/archive/serializers/kg.js +0 -184
  170. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  171. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  172. package/dist/lib/archive/server-deps.d.ts +0 -131
  173. package/dist/lib/archive/server-deps.js +0 -232
  174. package/dist/lib/archive/strength.d.ts +0 -50
  175. package/dist/lib/archive/strength.js +0 -77
  176. package/dist/lib/archive/types.d.ts +0 -159
  177. package/dist/lib/archive/types.js +0 -45
  178. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  179. package/dist/lib/archive/unpack-streaming.js +0 -255
  180. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  181. package/dist/lib/confidence/config.d.ts +0 -37
  182. package/dist/lib/confidence/config.js +0 -107
  183. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  184. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  185. package/dist/lib/confidence/db-shim.d.ts +0 -47
  186. package/dist/lib/confidence/db-shim.js +0 -141
  187. package/dist/lib/confidence/mark.d.ts +0 -58
  188. package/dist/lib/confidence/mark.js +0 -168
  189. package/dist/lib/confidence/ranking.d.ts +0 -69
  190. package/dist/lib/confidence/ranking.js +0 -101
  191. package/dist/lib/confidence/search-filter.d.ts +0 -44
  192. package/dist/lib/confidence/search-filter.js +0 -103
  193. package/dist/lib/confidence/types.d.ts +0 -146
  194. package/dist/lib/confidence/types.js +0 -20
  195. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  196. package/dist/lib/confidence/write-hooks.js +0 -159
  197. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  198. package/dist/lib/conflict/audit-fk-check.js +0 -131
  199. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  200. package/dist/lib/conflict/audit-writer.js +0 -133
  201. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  202. package/dist/lib/conflict/db-singleton.js +0 -61
  203. package/dist/lib/conflict/db.d.ts +0 -27
  204. package/dist/lib/conflict/db.js +0 -20
  205. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  206. package/dist/lib/conflict/detector-direct.js +0 -105
  207. package/dist/lib/conflict/evidence.d.ts +0 -24
  208. package/dist/lib/conflict/evidence.js +0 -76
  209. package/dist/lib/conflict/index.d.ts +0 -14
  210. package/dist/lib/conflict/index.js +0 -12
  211. package/dist/lib/conflict/scheduler.d.ts +0 -78
  212. package/dist/lib/conflict/scheduler.js +0 -111
  213. package/dist/lib/conflict/shadow.d.ts +0 -75
  214. package/dist/lib/conflict/shadow.js +0 -161
  215. package/dist/lib/conflict/types.d.ts +0 -133
  216. package/dist/lib/conflict/types.js +0 -19
  217. package/dist/lib/cost-cap.d.ts +0 -94
  218. package/dist/lib/deps/deps-registry.d.ts +0 -111
  219. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  220. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  221. package/dist/lib/eval-batch.d.ts +0 -34
  222. package/dist/lib/eval-batch.js +0 -103
  223. package/dist/lib/eval-metrics.d.ts +0 -36
  224. package/dist/lib/eval-metrics.js +0 -95
  225. package/dist/lib/eval.d.ts +0 -106
  226. package/dist/lib/eval.js +0 -343
  227. package/dist/lib/events/bus.d.ts +0 -135
  228. package/dist/lib/fts-anchor.d.ts +0 -1
  229. package/dist/lib/hooks/classifier.d.ts +0 -47
  230. package/dist/lib/hooks/classifier.js +0 -129
  231. package/dist/lib/hooks/config.d.ts +0 -49
  232. package/dist/lib/hooks/config.js +0 -106
  233. package/dist/lib/hooks/decorators.d.ts +0 -35
  234. package/dist/lib/hooks/decorators.js +0 -59
  235. package/dist/lib/hooks/pipeline.d.ts +0 -76
  236. package/dist/lib/hooks/pipeline.js +0 -213
  237. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  238. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  239. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  240. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  241. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  242. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  243. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  244. package/dist/lib/hooks/rate-limit.js +0 -122
  245. package/dist/lib/hooks/server-deps.d.ts +0 -61
  246. package/dist/lib/hooks/server-deps.js +0 -92
  247. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  248. package/dist/lib/hooks/source-allowlist.js +0 -53
  249. package/dist/lib/hooks/types.d.ts +0 -129
  250. package/dist/lib/hooks/types.js +0 -24
  251. package/dist/lib/hooks/worker.d.ts +0 -56
  252. package/dist/lib/hooks/worker.js +0 -150
  253. package/dist/lib/ingest-router.d.ts +0 -25
  254. package/dist/lib/ocr-detector.d.ts +0 -61
  255. package/dist/lib/ocr-detector.js +0 -138
  256. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  257. package/dist/lib/ocr-engine-stub.js +0 -190
  258. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  259. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  260. package/dist/lib/ocr-jobs.d.ts +0 -67
  261. package/dist/lib/ocr-jobs.js +0 -129
  262. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  263. package/dist/lib/op-audit.d.ts +0 -71
  264. package/dist/lib/privacy-br/detector.d.ts +0 -42
  265. package/dist/lib/privacy-br/detector.js +0 -130
  266. package/dist/lib/privacy-br/index.d.ts +0 -20
  267. package/dist/lib/privacy-br/index.js +0 -20
  268. package/dist/lib/privacy-br/integration.d.ts +0 -71
  269. package/dist/lib/privacy-br/integration.js +0 -74
  270. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  271. package/dist/lib/privacy-br/patterns.js +0 -434
  272. package/dist/lib/privacy-br/redact.d.ts +0 -42
  273. package/dist/lib/privacy-br/redact.js +0 -103
  274. package/dist/lib/privacy-br/types.d.ts +0 -55
  275. package/dist/lib/privacy-br/types.js +0 -25
  276. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  277. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  278. package/dist/lib/regex-extract/index.d.ts +0 -14
  279. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  280. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  281. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  282. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  283. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  284. package/dist/lib/regex-extract/types.d.ts +0 -48
  285. package/dist/lib/reranker.d.ts +0 -80
  286. package/dist/lib/shadow-tracker.d.ts +0 -191
  287. package/dist/lib/shadow-tracker.js +0 -384
  288. package/dist/lib/spo-injection.d.ts +0 -52
  289. package/dist/lib/telemetry-collector.d.ts +0 -158
  290. package/dist/lib/telemetry-collector.js +0 -249
  291. package/dist/lib/temporal-detector.d.ts +0 -27
  292. package/dist/lib/viewer/auth.d.ts +0 -37
  293. package/dist/lib/viewer/auth.js +0 -70
  294. package/dist/lib/viewer/backpressure.d.ts +0 -59
  295. package/dist/lib/viewer/backpressure.js +0 -100
  296. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  297. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  298. package/dist/lib/viewer/broadcast.d.ts +0 -66
  299. package/dist/lib/viewer/broadcast.js +0 -96
  300. package/dist/lib/viewer/event-types.d.ts +0 -132
  301. package/dist/lib/viewer/event-types.js +0 -74
  302. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  303. package/dist/lib/viewer/instrumentation.js +0 -224
  304. package/dist/lib/viewer/migration.d.ts +0 -23
  305. package/dist/lib/viewer/migration.js +0 -56
  306. package/dist/lib/viewer/redaction.d.ts +0 -44
  307. package/dist/lib/viewer/redaction.js +0 -139
  308. package/dist/lib/viewer/session.d.ts +0 -51
  309. package/dist/lib/viewer/session.js +0 -87
  310. package/dist/mcp/tools/answer.d.ts +0 -94
  311. package/dist/mcp/tools/archive.d.ts +0 -152
  312. package/dist/mcp/tools/archive.js +0 -170
  313. package/dist/mcp/tools/conflict.d.ts +0 -44
  314. package/dist/mcp/tools/conflict.js +0 -130
  315. package/dist/mcp/tools/hooks.d.ts +0 -29
  316. package/dist/mcp/tools/hooks.js +0 -78
  317. package/dist/mcp/tools/mark.d.ts +0 -38
  318. package/dist/mcp/tools/mark.js +0 -82
  319. package/dist/mcp/tools/viewer.d.ts +0 -58
  320. package/dist/mcp/tools/viewer.js +0 -64
  321. package/dist/mcp-server.d.ts +0 -2
  322. package/dist/metrics.d.ts +0 -3
  323. package/dist/noise-filter.d.ts +0 -18
  324. package/dist/notion-sync.d.ts +0 -7
  325. package/dist/notion-sync.js +0 -97
  326. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  327. package/dist/observability/adapters/a3-adapter.js +0 -83
  328. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  329. package/dist/observability/adapters/p1-adapter.js +0 -63
  330. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  331. package/dist/observability/adapters/p5-adapter.js +0 -71
  332. package/dist/observability/cardinality.d.ts +0 -61
  333. package/dist/observability/cardinality.js +0 -300
  334. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  335. package/dist/observability/collectors/db-stats.collector.js +0 -88
  336. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  337. package/dist/observability/collectors/eventbus.collector.js +0 -50
  338. package/dist/observability/collectors/process.collector.d.ts +0 -7
  339. package/dist/observability/collectors/process.collector.js +0 -93
  340. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  341. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  342. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  343. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  344. package/dist/observability/exporter.d.ts +0 -30
  345. package/dist/observability/exporter.js +0 -182
  346. package/dist/observability/index.d.ts +0 -22
  347. package/dist/observability/index.js +0 -21
  348. package/dist/observability/metrics.d.ts +0 -53
  349. package/dist/observability/metrics.js +0 -213
  350. package/dist/observability/privacy-guard.d.ts +0 -32
  351. package/dist/observability/privacy-guard.js +0 -116
  352. package/dist/observability/record.d.ts +0 -83
  353. package/dist/observability/record.js +0 -217
  354. package/dist/observability/registry.d.ts +0 -60
  355. package/dist/observability/registry.js +0 -93
  356. package/dist/observability/types.d.ts +0 -115
  357. package/dist/observability/types.js +0 -235
  358. package/dist/observability.d.ts +0 -131
  359. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  360. package/dist/plugins/nox-hooks/index.js +0 -99
  361. package/dist/primer.d.ts +0 -1
  362. package/dist/privacy/filter.d.ts +0 -27
  363. package/dist/privacy/patterns.d.ts +0 -29
  364. package/dist/privacy/tag-parser.d.ts +0 -24
  365. package/dist/project-context-gen.d.ts +0 -10
  366. package/dist/providers/embedding/gemini.d.ts +0 -73
  367. package/dist/providers/embedding/openai.d.ts +0 -76
  368. package/dist/providers/embedding/types.d.ts +0 -39
  369. package/dist/providers/embedding/voyage.d.ts +0 -36
  370. package/dist/providers/index.d.ts +0 -116
  371. package/dist/providers/llm/anthropic.d.ts +0 -29
  372. package/dist/providers/llm/chain.d.ts +0 -99
  373. package/dist/providers/llm/gemini.d.ts +0 -48
  374. package/dist/providers/llm/openai.d.ts +0 -64
  375. package/dist/providers/llm/types.d.ts +0 -47
  376. package/dist/providers/telemetry.d.ts +0 -87
  377. package/dist/providers/types.d.ts +0 -42
  378. package/dist/query-entity-count.d.ts +0 -54
  379. package/dist/reflect.d.ts +0 -26
  380. package/dist/reindex-errors.d.ts +0 -7
  381. package/dist/reindex.d.ts +0 -16
  382. package/dist/retention.d.ts +0 -40
  383. package/dist/salience.d.ts +0 -85
  384. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  385. package/dist/search-dedup.d.ts +0 -44
  386. package/dist/search-expansion.d.ts +0 -20
  387. package/dist/search.d.ts +0 -62
  388. package/dist/seh-detector.d.ts +0 -31
  389. package/dist/self-improve.d.ts +0 -1
  390. package/dist/session-distill.d.ts +0 -29
  391. package/dist/session-update.d.ts +0 -1
  392. package/dist/shared-memory.d.ts +0 -24
  393. package/dist/stats.d.ts +0 -1
  394. package/dist/temporal-retrieval.d.ts +0 -132
  395. package/dist/tier-manager.d.ts +0 -69
  396. package/dist/vectorize.d.ts +0 -16
  397. package/dist/version.d.ts +0 -1
  398. package/dist/watch.d.ts +0 -8
@@ -1,57 +0,0 @@
1
- /**
2
- * G17 — Constant-time response shape for /api/hooks/status (Wave G)
3
- *
4
- * BACKGROUND
5
- * `GET /api/hooks/status` currently returns `rateLimitTokens` from
6
- * `inspectQueue().rateLimitTokens`. An attacker monitoring this value
7
- * can:
8
- * - Detect when capture is busy (tokens trend down → user is active).
9
- * - Time their own probes to land between legitimate captures.
10
- * - Inferring capture cadence reveals user activity patterns, an
11
- * indirect side-channel even when the actual payloads are private.
12
- *
13
- * THREAT (G17, R-P2-3)
14
- * `rateLimitTokens` oracle reveals capture activity to anyone with
15
- * access to `/api/hooks/status` (which is itself a low-effort read
16
- * endpoint).
17
- *
18
- * FIX
19
- * - Omit (zero-out, not delete) `rateLimitTokens` by default.
20
- * - Always return the same response shape — `rateLimitTokens: null`.
21
- * "Constant-time" here = constant *shape* (no field absence/presence
22
- * toggle), so introspection can't fingerprint the env config.
23
- * - Operators can opt back in via `NOX_HOOK_EXPOSE_TOKENS=1` for ops
24
- * debugging (with a boot WARN logged).
25
- *
26
- * Backward compat:
27
- * - Field still present (null) — clients reading `body.rateLimitTokens`
28
- * don't crash; they just see null.
29
- * - Opt-in env restores legacy behavior.
30
- */
31
- export interface SanitizeStatusInput {
32
- /** Raw token count from inspectQueue() — may be number or null/undefined. */
33
- rateLimitTokens?: number | null;
34
- }
35
- export interface SanitizeStatusResult {
36
- rateLimitTokens: number | null;
37
- /** True when env opt-in was honored; useful for telemetry. */
38
- exposed: boolean;
39
- }
40
- export declare function readExposeTokensFlag(env?: NodeJS.ProcessEnv): boolean;
41
- /**
42
- * Take the raw `rateLimitTokens` value and return what should be exposed
43
- * in the response body. Default: always null. Opt-in: pass through.
44
- */
45
- export declare function sanitizeRateLimitTokens(input: SanitizeStatusInput, env?: NodeJS.ProcessEnv): SanitizeStatusResult;
46
- /**
47
- * Boot-time WARN helper. Caller invokes once on startup if hooks API
48
- * is mounted.
49
- */
50
- export declare function checkExposeTokensAtBoot(logger?: {
51
- warn: (msg: string) => void;
52
- }, env?: NodeJS.ProcessEnv): boolean;
53
- export declare function statusBodyWithSanitizedTokens<B extends Record<string, unknown>>(body: B & {
54
- rateLimitTokens?: number | null;
55
- }, env?: NodeJS.ProcessEnv): B & {
56
- rateLimitTokens: number | null;
57
- };
@@ -1,69 +0,0 @@
1
- /**
2
- * G17 — Constant-time response shape for /api/hooks/status (Wave G)
3
- *
4
- * BACKGROUND
5
- * `GET /api/hooks/status` currently returns `rateLimitTokens` from
6
- * `inspectQueue().rateLimitTokens`. An attacker monitoring this value
7
- * can:
8
- * - Detect when capture is busy (tokens trend down → user is active).
9
- * - Time their own probes to land between legitimate captures.
10
- * - Inferring capture cadence reveals user activity patterns, an
11
- * indirect side-channel even when the actual payloads are private.
12
- *
13
- * THREAT (G17, R-P2-3)
14
- * `rateLimitTokens` oracle reveals capture activity to anyone with
15
- * access to `/api/hooks/status` (which is itself a low-effort read
16
- * endpoint).
17
- *
18
- * FIX
19
- * - Omit (zero-out, not delete) `rateLimitTokens` by default.
20
- * - Always return the same response shape — `rateLimitTokens: null`.
21
- * "Constant-time" here = constant *shape* (no field absence/presence
22
- * toggle), so introspection can't fingerprint the env config.
23
- * - Operators can opt back in via `NOX_HOOK_EXPOSE_TOKENS=1` for ops
24
- * debugging (with a boot WARN logged).
25
- *
26
- * Backward compat:
27
- * - Field still present (null) — clients reading `body.rateLimitTokens`
28
- * don't crash; they just see null.
29
- * - Opt-in env restores legacy behavior.
30
- */
31
- export function readExposeTokensFlag(env = process.env) {
32
- return env.NOX_HOOK_EXPOSE_TOKENS === "1";
33
- }
34
- /**
35
- * Take the raw `rateLimitTokens` value and return what should be exposed
36
- * in the response body. Default: always null. Opt-in: pass through.
37
- */
38
- export function sanitizeRateLimitTokens(input, env = process.env) {
39
- const expose = readExposeTokensFlag(env);
40
- if (expose) {
41
- return {
42
- rateLimitTokens: typeof input.rateLimitTokens === "number" ? input.rateLimitTokens : null,
43
- exposed: true,
44
- };
45
- }
46
- return { rateLimitTokens: null, exposed: false };
47
- }
48
- /**
49
- * Boot-time WARN helper. Caller invokes once on startup if hooks API
50
- * is mounted.
51
- */
52
- export function checkExposeTokensAtBoot(logger = console, env = process.env) {
53
- if (readExposeTokensFlag(env)) {
54
- logger.warn("[security] NOX_HOOK_EXPOSE_TOKENS=1 — /api/hooks/status will leak " +
55
- "rateLimitTokens. Disables G17 mitigation. Use only for ops debugging.");
56
- return true;
57
- }
58
- return false;
59
- }
60
- // ── Drop-in transformer for hooks.ts /status branch ────────────────────────
61
- //
62
- // Replace the current `rateLimitTokens: inspect.rateLimitTokens ?? null`
63
- // with `rateLimitTokens: sanitizeRateLimitTokens({ rateLimitTokens: inspect.rateLimitTokens }).rateLimitTokens`.
64
- //
65
- // Or, use the helper below for a one-liner:
66
- export function statusBodyWithSanitizedTokens(body, env = process.env) {
67
- const sanitized = sanitizeRateLimitTokens({ rateLimitTokens: body.rateLimitTokens }, env);
68
- return { ...body, rateLimitTokens: sanitized.rateLimitTokens };
69
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * G13 — Rate limit for `POST /api/hooks/dryrun` (Wave G)
3
- *
4
- * Background:
5
- * `POST /api/hooks/dryrun` intentionally bypasses the capture rate limit
6
- * (a separate token bucket for actual ingestion). This lets ops/dev test
7
- * classifier output freely.
8
- *
9
- * But: it also lets an attacker probe the classifier filter (privacy
10
- * patterns, PII detection, redaction layers) at unlimited speed — an
11
- * oracle that can be used to fingerprint or evade A1 patterns.
12
- *
13
- * Fix:
14
- * Per-IP token bucket sized via `NOX_HOOK_DRYRUN_RATE_LIMIT` (default
15
- * 10 req/min). Refills at `rate / 60` tokens per second. Buckets are
16
- * process-local (no shared state — single-tenant assumption per
17
- * `THREAT-MODEL.md §12.1`).
18
- *
19
- * Does NOT affect:
20
- * - The capture rate-limit token bucket (separate, configured via
21
- * `HookConfig.rateLimitPerMin`).
22
- * - GET endpoints (status, recent) — those are read-only metadata.
23
- *
24
- * Refs:
25
- * - PR #58 §14 G13.
26
- * - THREAT-MODEL.md §7.7 T-P2-2.
27
- */
28
- export interface DryrunRateLimitConfig {
29
- /** Requests per minute per IP. Default 10. */
30
- perMinute: number;
31
- /** Override: bucket capacity (defaults to perMinute). */
32
- burstCapacity?: number;
33
- }
34
- export declare function readDryrunRateLimitConfig(env?: NodeJS.ProcessEnv): DryrunRateLimitConfig;
35
- export interface DryrunRateLimiter {
36
- /** Attempt to consume 1 token. Returns true if allowed. */
37
- tryConsume(ip: string, nowMs?: number): boolean;
38
- /** Refill all buckets up to `nowMs`. Pure helper for tests. */
39
- refillAll(nowMs?: number): void;
40
- /** Snapshot for telemetry. */
41
- snapshot(): Array<{
42
- ip: string;
43
- tokens: number;
44
- lastRefillMs: number;
45
- }>;
46
- /** Reset (test helper). */
47
- clear(): void;
48
- }
49
- export declare function createDryrunRateLimiter(cfg?: DryrunRateLimitConfig): DryrunRateLimiter;
50
- export interface DryrunGateResult {
51
- allowed: boolean;
52
- /** HTTP response when rejected. */
53
- rejectResponse?: {
54
- status: 429;
55
- headers: Record<string, string>;
56
- body: {
57
- error: "rate_limited";
58
- reason: "dryrun_per_ip";
59
- retry_after_seconds: number;
60
- };
61
- };
62
- }
63
- /**
64
- * Gate helper for `POST /api/hooks/dryrun`. Caller (hooks API handler)
65
- * wraps the existing dryrun branch with:
66
- *
67
- * const gate = checkDryrunGate(limiter, req.ip);
68
- * if (!gate.allowed) return gate.rejectResponse;
69
- * // ... existing dryrun logic ...
70
- */
71
- export declare function checkDryrunGate(limiter: DryrunRateLimiter, ip: string, cfg?: DryrunRateLimitConfig): DryrunGateResult;
@@ -1,110 +0,0 @@
1
- /**
2
- * G13 — Rate limit for `POST /api/hooks/dryrun` (Wave G)
3
- *
4
- * Background:
5
- * `POST /api/hooks/dryrun` intentionally bypasses the capture rate limit
6
- * (a separate token bucket for actual ingestion). This lets ops/dev test
7
- * classifier output freely.
8
- *
9
- * But: it also lets an attacker probe the classifier filter (privacy
10
- * patterns, PII detection, redaction layers) at unlimited speed — an
11
- * oracle that can be used to fingerprint or evade A1 patterns.
12
- *
13
- * Fix:
14
- * Per-IP token bucket sized via `NOX_HOOK_DRYRUN_RATE_LIMIT` (default
15
- * 10 req/min). Refills at `rate / 60` tokens per second. Buckets are
16
- * process-local (no shared state — single-tenant assumption per
17
- * `THREAT-MODEL.md §12.1`).
18
- *
19
- * Does NOT affect:
20
- * - The capture rate-limit token bucket (separate, configured via
21
- * `HookConfig.rateLimitPerMin`).
22
- * - GET endpoints (status, recent) — those are read-only metadata.
23
- *
24
- * Refs:
25
- * - PR #58 §14 G13.
26
- * - THREAT-MODEL.md §7.7 T-P2-2.
27
- */
28
- export function readDryrunRateLimitConfig(env = process.env) {
29
- const raw = env.NOX_HOOK_DRYRUN_RATE_LIMIT;
30
- const n = raw ? Number.parseInt(raw, 10) : NaN;
31
- const perMinute = Number.isFinite(n) && n > 0 ? n : 10;
32
- return { perMinute };
33
- }
34
- export function createDryrunRateLimiter(cfg = readDryrunRateLimitConfig()) {
35
- const buckets = new Map();
36
- const capacity = cfg.burstCapacity ?? cfg.perMinute;
37
- const refillPerMs = cfg.perMinute / 60_000;
38
- const refill = (b, nowMs) => {
39
- const elapsed = Math.max(0, nowMs - b.lastRefillMs);
40
- if (elapsed === 0)
41
- return;
42
- const add = elapsed * refillPerMs;
43
- if (add <= 0)
44
- return;
45
- b.tokens = Math.min(capacity, b.tokens + add);
46
- b.lastRefillMs = nowMs;
47
- };
48
- return {
49
- tryConsume(ip, nowMs = Date.now()) {
50
- let b = buckets.get(ip);
51
- if (!b) {
52
- b = { tokens: capacity, lastRefillMs: nowMs };
53
- buckets.set(ip, b);
54
- }
55
- else {
56
- refill(b, nowMs);
57
- }
58
- if (b.tokens >= 1) {
59
- b.tokens -= 1;
60
- return true;
61
- }
62
- return false;
63
- },
64
- refillAll(nowMs = Date.now()) {
65
- for (const b of buckets.values())
66
- refill(b, nowMs);
67
- },
68
- snapshot() {
69
- return Array.from(buckets.entries()).map(([ip, b]) => ({
70
- ip,
71
- tokens: b.tokens,
72
- lastRefillMs: b.lastRefillMs,
73
- }));
74
- },
75
- clear() {
76
- buckets.clear();
77
- },
78
- };
79
- }
80
- /**
81
- * Gate helper for `POST /api/hooks/dryrun`. Caller (hooks API handler)
82
- * wraps the existing dryrun branch with:
83
- *
84
- * const gate = checkDryrunGate(limiter, req.ip);
85
- * if (!gate.allowed) return gate.rejectResponse;
86
- * // ... existing dryrun logic ...
87
- */
88
- export function checkDryrunGate(limiter, ip, cfg = readDryrunRateLimitConfig()) {
89
- if (limiter.tryConsume(ip)) {
90
- return { allowed: true };
91
- }
92
- // Retry-After: roughly time to next token (60s / perMinute).
93
- const retryAfterSeconds = Math.max(1, Math.ceil(60 / cfg.perMinute));
94
- return {
95
- allowed: false,
96
- rejectResponse: {
97
- status: 429,
98
- headers: {
99
- "Content-Type": "application/json; charset=utf-8",
100
- "Retry-After": String(retryAfterSeconds),
101
- "Cache-Control": "no-store",
102
- },
103
- body: {
104
- error: "rate_limited",
105
- reason: "dryrun_per_ip",
106
- retry_after_seconds: retryAfterSeconds,
107
- },
108
- },
109
- };
110
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * src/lib/hooks/rate-limit.ts — T5: Layer 5 of pipeline.
3
- *
4
- * Two protections combined:
5
- * 1. Token-bucket rate limit (default 30 captures/min, configurable via
6
- * NOX_HOOK_RATE_LIMIT). Refills 1 token every (60/N) seconds.
7
- * 2. Near-duplicate dedup via cosine similarity on a lightweight
8
- * character-shingle vector (no embeddings required — keeps Layer 5
9
- * independent of embedding provider availability).
10
- *
11
- * Dedup keeps a ring buffer of the last 10 redacted texts; if cosine
12
- * (new vs any in ring) > NOX_HOOK_DEDUP_THRESHOLD (default 0.95), reject.
13
- *
14
- * Note on cosine choice: full Gemini embedding cosine would be ideal but
15
- * Layer 5 must NOT depend on network/embedding latency (it's the last
16
- * gate before persistence). Char-shingle cosine is fast + decent for
17
- * near-identical detection (e.g., "rerun the same command" duplicates).
18
- * Upstream callers can swap the similarity fn via DI if a real embedder
19
- * is desired (e.g., from cached chunks).
20
- */
21
- import type { CaptureDecision, HookContext } from "./types.js";
22
- /** Pluggable similarity. Default = char-shingle cosine. */
23
- export type SimilarityFn = (a: string, b: string) => number;
24
- export interface RateLimitState {
25
- /** Tokens available (float). */
26
- tokens: number;
27
- /** Last refill timestamp (ms epoch). */
28
- lastRefillMs: number;
29
- /** Ring buffer of recent redacted texts. */
30
- recent: string[];
31
- }
32
- export interface RateLimitOpts {
33
- /** Captures-per-minute capacity. Default 30. */
34
- capacityPerMin?: number;
35
- /** Cosine threshold for dedup (rejects if >threshold). Default 0.95. */
36
- dedupThreshold?: number;
37
- /** Ring buffer size. Default 10. */
38
- ringSize?: number;
39
- /** Pluggable similarity. Default charShingleCosine. */
40
- similarity?: SimilarityFn;
41
- /** Inject clock for tests. */
42
- now?: () => number;
43
- }
44
- /**
45
- * Build a fresh empty state with full bucket.
46
- */
47
- export declare function createState(capacity: number, now?: () => number): RateLimitState;
48
- /** Default: character 3-shingle cosine. */
49
- export declare function charShingleCosine(a: string, b: string): number;
50
- /**
51
- * Evaluate Layer 5 against a HookContext, updating the passed-in state.
52
- * State must be threaded by the pipeline (singleton per worker).
53
- */
54
- export declare function applyRateLimit(ctx: HookContext, state: RateLimitState, opts?: RateLimitOpts): CaptureDecision;
@@ -1,122 +0,0 @@
1
- /**
2
- * src/lib/hooks/rate-limit.ts — T5: Layer 5 of pipeline.
3
- *
4
- * Two protections combined:
5
- * 1. Token-bucket rate limit (default 30 captures/min, configurable via
6
- * NOX_HOOK_RATE_LIMIT). Refills 1 token every (60/N) seconds.
7
- * 2. Near-duplicate dedup via cosine similarity on a lightweight
8
- * character-shingle vector (no embeddings required — keeps Layer 5
9
- * independent of embedding provider availability).
10
- *
11
- * Dedup keeps a ring buffer of the last 10 redacted texts; if cosine
12
- * (new vs any in ring) > NOX_HOOK_DEDUP_THRESHOLD (default 0.95), reject.
13
- *
14
- * Note on cosine choice: full Gemini embedding cosine would be ideal but
15
- * Layer 5 must NOT depend on network/embedding latency (it's the last
16
- * gate before persistence). Char-shingle cosine is fast + decent for
17
- * near-identical detection (e.g., "rerun the same command" duplicates).
18
- * Upstream callers can swap the similarity fn via DI if a real embedder
19
- * is desired (e.g., from cached chunks).
20
- */
21
- /**
22
- * Build a fresh empty state with full bucket.
23
- */
24
- export function createState(capacity, now = Date.now) {
25
- return {
26
- tokens: capacity,
27
- lastRefillMs: now(),
28
- recent: [],
29
- };
30
- }
31
- /** Default: character 3-shingle cosine. */
32
- export function charShingleCosine(a, b) {
33
- if (a.length === 0 || b.length === 0)
34
- return 0;
35
- if (a === b)
36
- return 1;
37
- const shA = shingle(a, 3);
38
- const shB = shingle(b, 3);
39
- let dot = 0;
40
- let magA = 0;
41
- let magB = 0;
42
- for (const [k, va] of shA) {
43
- magA += va * va;
44
- const vb = shB.get(k) ?? 0;
45
- if (vb !== 0)
46
- dot += va * vb;
47
- }
48
- for (const vb of shB.values())
49
- magB += vb * vb;
50
- if (magA === 0 || magB === 0)
51
- return 0;
52
- return dot / (Math.sqrt(magA) * Math.sqrt(magB));
53
- }
54
- function shingle(s, n) {
55
- const m = new Map();
56
- if (s.length < n) {
57
- m.set(s, 1);
58
- return m;
59
- }
60
- for (let i = 0; i <= s.length - n; i++) {
61
- const k = s.slice(i, i + n);
62
- m.set(k, (m.get(k) ?? 0) + 1);
63
- }
64
- return m;
65
- }
66
- /**
67
- * Refill token bucket based on elapsed wall-clock since last refill.
68
- */
69
- function refill(state, capacityPerMin, now) {
70
- const t = now();
71
- const elapsedMs = t - state.lastRefillMs;
72
- if (elapsedMs <= 0)
73
- return;
74
- const refillRatePerMs = capacityPerMin / 60_000;
75
- const add = elapsedMs * refillRatePerMs;
76
- state.tokens = Math.min(capacityPerMin, state.tokens + add);
77
- state.lastRefillMs = t;
78
- }
79
- /**
80
- * Evaluate Layer 5 against a HookContext, updating the passed-in state.
81
- * State must be threaded by the pipeline (singleton per worker).
82
- */
83
- export function applyRateLimit(ctx, state, opts = {}) {
84
- const capacity = opts.capacityPerMin ?? 30;
85
- const threshold = opts.dedupThreshold ?? 0.95;
86
- const ringSize = opts.ringSize ?? 10;
87
- const sim = opts.similarity ?? charShingleCosine;
88
- const now = opts.now ?? Date.now;
89
- refill(state, capacity, now);
90
- // Dedup check (cosine) before consuming a token — dedup hits should NOT
91
- // count against rate-limit.
92
- const text = ctx.redacted?.text ?? ctx.event.content;
93
- for (const prev of state.recent) {
94
- const c = sim(text, prev);
95
- if (c > threshold) {
96
- return {
97
- capture: false,
98
- reason: `dedup_hit cosine=${c.toFixed(3)} threshold=${threshold}`,
99
- layer: "rate-limit",
100
- score: c,
101
- };
102
- }
103
- }
104
- // Rate-limit
105
- if (state.tokens < 1) {
106
- return {
107
- capture: false,
108
- reason: `rate_limited tokens=${state.tokens.toFixed(2)} capacity=${capacity}/min`,
109
- layer: "rate-limit",
110
- };
111
- }
112
- // Consume + push to ring
113
- state.tokens -= 1;
114
- state.recent.push(text);
115
- if (state.recent.length > ringSize)
116
- state.recent.shift();
117
- return {
118
- capture: true,
119
- reason: `ok tokens_remaining=${state.tokens.toFixed(2)}`,
120
- layer: "rate-limit",
121
- };
122
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * src/lib/hooks/server-deps.ts — Wave O T5: P2 (hooks) runtime adapter.
3
- *
4
- * Wire-up.ts lazy-imports this module:
5
- *
6
- * const depsMod = await tryImport("../lib/hooks/server-deps.js");
7
- * if (!depsMod?.buildHooksDeps) writeJson(res, ..., 503);
8
- * const out = await handleHooksRequest(req, await depsMod.buildHooksDeps());
9
- *
10
- * The staged-P2 `handleHooksRequest` expects `HooksApiDeps`:
11
- *
12
- * interface HooksApiDeps {
13
- * readRecent(limit): Promise<row[]>;
14
- * config?: HookConfig;
15
- * telemetry?: TelemetrySink;
16
- * inspectQueue?(): { queueDepth; rateLimitTokens? };
17
- * }
18
- *
19
- * `readRecent` queries `agent_events` (schema v11) for the most recent N
20
- * captured events. Each row is sanitized to METADATA ONLY — no `payload_json`,
21
- * no raw content (P2 privacy invariant; see staged-P2 source comment).
22
- */
23
- export interface HookRecentRow {
24
- event_uuid: string;
25
- session_id: string;
26
- project_slug: string;
27
- kind: string;
28
- timestamp: string;
29
- redaction_count: number;
30
- }
31
- export interface HookTelemetryRow {
32
- event_uuid: string;
33
- layer: string;
34
- reason: string;
35
- kind: string;
36
- redaction_count: number;
37
- payload_json: string;
38
- ts: string;
39
- }
40
- export interface HooksApiDeps {
41
- readRecent: (limit: number) => Promise<HookRecentRow[]>;
42
- /** Optional. When absent, handler defaults to `loadConfig()` from env. */
43
- config?: unknown;
44
- /** Sink for dryrun telemetry. No-op default. */
45
- telemetry?: (row: HookTelemetryRow) => void;
46
- inspectQueue?: () => {
47
- queueDepth: number;
48
- rateLimitTokens?: number;
49
- };
50
- }
51
- /**
52
- * Build the HooksApiDeps the staged-P2 `handleHooksRequest` expects.
53
- * Idempotent — safe to call once per request.
54
- */
55
- export declare function buildHooksDeps(overrides?: Partial<HooksApiDeps>): Promise<HooksApiDeps>;
56
- /** Swap the queue probe for tests. */
57
- export declare function __setQueueProbeForTests(probe: (() => {
58
- queueDepth: number;
59
- rateLimitTokens?: number;
60
- }) | null): void;
61
- export declare function __resetHooksDepsForTests(): void;
@@ -1,92 +0,0 @@
1
- /**
2
- * src/lib/hooks/server-deps.ts — Wave O T5: P2 (hooks) runtime adapter.
3
- *
4
- * Wire-up.ts lazy-imports this module:
5
- *
6
- * const depsMod = await tryImport("../lib/hooks/server-deps.js");
7
- * if (!depsMod?.buildHooksDeps) writeJson(res, ..., 503);
8
- * const out = await handleHooksRequest(req, await depsMod.buildHooksDeps());
9
- *
10
- * The staged-P2 `handleHooksRequest` expects `HooksApiDeps`:
11
- *
12
- * interface HooksApiDeps {
13
- * readRecent(limit): Promise<row[]>;
14
- * config?: HookConfig;
15
- * telemetry?: TelemetrySink;
16
- * inspectQueue?(): { queueDepth; rateLimitTokens? };
17
- * }
18
- *
19
- * `readRecent` queries `agent_events` (schema v11) for the most recent N
20
- * captured events. Each row is sanitized to METADATA ONLY — no `payload_json`,
21
- * no raw content (P2 privacy invariant; see staged-P2 source comment).
22
- */
23
- import { getDb } from "../deps/deps-registry.js";
24
- // ─── Default implementations ─────────────────────────────────────────────────
25
- async function defaultReadRecent(limit) {
26
- const db = await getDb();
27
- if (!db)
28
- return [];
29
- // Cap limit defensively even though handler already validates.
30
- const safeLimit = Math.max(1, Math.min(500, Math.floor(limit)));
31
- try {
32
- const rows = db
33
- .prepare(`SELECT event_uuid, session_id, project_slug, kind, timestamp, redaction_count
34
- FROM agent_events
35
- WHERE captured = 1
36
- ORDER BY timestamp DESC
37
- LIMIT ?`)
38
- .all(safeLimit);
39
- return rows;
40
- }
41
- catch {
42
- // Table missing (pre-v11) → return empty.
43
- return [];
44
- }
45
- }
46
- function defaultInspectQueue() {
47
- // The actual worker singleton lives in `lib/hooks/worker.ts`. We try to
48
- // probe it dynamically; when unavailable (CLI-only deploy), return zero.
49
- return { queueDepth: 0 };
50
- }
51
- let _queueProbe = null;
52
- async function tryLoadWorkerProbe() {
53
- if (_queueProbe)
54
- return;
55
- try {
56
- // String indirection — `./worker.js` is staged-P2's worker module,
57
- // co-located only after rsync.
58
- const WORKER_SPEC = "./worker.js";
59
- const mod = await import(WORKER_SPEC);
60
- if (typeof mod.inspectQueue === "function") {
61
- _queueProbe = mod.inspectQueue.bind(mod);
62
- }
63
- else if (typeof mod.default?.inspectQueue === "function") {
64
- _queueProbe = mod.default.inspectQueue.bind(mod.default);
65
- }
66
- }
67
- catch {
68
- // Worker module not deployed — silent fallback.
69
- }
70
- }
71
- // ─── Public builder ──────────────────────────────────────────────────────────
72
- /**
73
- * Build the HooksApiDeps the staged-P2 `handleHooksRequest` expects.
74
- * Idempotent — safe to call once per request.
75
- */
76
- export async function buildHooksDeps(overrides) {
77
- await tryLoadWorkerProbe();
78
- return {
79
- readRecent: overrides?.readRecent ?? defaultReadRecent,
80
- config: overrides?.config,
81
- telemetry: overrides?.telemetry,
82
- inspectQueue: overrides?.inspectQueue ?? _queueProbe ?? defaultInspectQueue,
83
- };
84
- }
85
- // ─── Test seam ───────────────────────────────────────────────────────────────
86
- /** Swap the queue probe for tests. */
87
- export function __setQueueProbeForTests(probe) {
88
- _queueProbe = probe;
89
- }
90
- export function __resetHooksDepsForTests() {
91
- _queueProbe = null;
92
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * src/lib/hooks/source-allowlist.ts — T2: Layer 2 of the privacy pipeline.
3
- *
4
- * Filters HookEvent by `source` AND `role`. Only events with:
5
- * - source ∈ NOX_HOOK_SOURCES (default {openclaw})
6
- * - role ∈ {user, assistant} (system/tool/unknown rejected by default)
7
- *
8
- * pass through. "unknown" source is ALWAYS rejected (it indicates the
9
- * event was constructed without explicit channel attribution — risk vector).
10
- *
11
- * No content access. No telemetry write here — pipeline (T6) records the
12
- * decision via the trace mechanism.
13
- */
14
- import type { HookConfig } from "./config.js";
15
- import type { CaptureDecision, HookEvent, HookRole } from "./types.js";
16
- export interface SourceAllowlistOpts {
17
- /** Override allowed roles (tests only). */
18
- allowedRoles?: ReadonlySet<HookRole>;
19
- }
20
- /**
21
- * Evaluate Layer 2 against a HookEvent given the active config.
22
- * Pure function — safe to test in isolation.
23
- */
24
- export declare function evaluateSourceAllowlist(event: HookEvent, config: HookConfig, opts?: SourceAllowlistOpts): CaptureDecision;
25
- /** Returns true if a given source string is recognized at all. */
26
- export declare function isKnownSource(s: string): boolean;