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,49 +0,0 @@
1
- /**
2
- * src/lib/hooks/config.ts — T7: Env config loader + validator.
3
- *
4
- * Reads the following env vars (all OPT-IN — defaults are most-restrictive):
5
- *
6
- * NOX_HOOKS_ENABLED → "1" | "0" (default "0" — Layer 1 gate is OFF)
7
- * NOX_HOOK_SOURCES → CSV of HookSource (default "openclaw")
8
- * NOX_HOOK_RATE_LIMIT → captures/min (default 30, min 1, max 1000)
9
- * NOX_HOOK_DEDUP_THRESHOLD→ cosine threshold (default 0.95, range 0.5..0.999)
10
- * NOX_HOOK_LLM_CLASSIFY → "1" | "0" (default "0" — heuristics only)
11
- * NOX_HOOK_DRY_RUN → "1" | "0" (default "0")
12
- * NOX_HOOK_QUEUE_SIZE → worker queue max (default 10000)
13
- * NOX_HOOK_MIN_LENGTH → classifier min chars (default 20)
14
- * NOX_HOOK_PII_POLICY → "redact" | "drop" (default "redact")
15
- *
16
- * Defensive: invalid values fall back to defaults + warn() to telemetry.
17
- */
18
- import type { HookSource } from "./types.js";
19
- export interface HookConfig {
20
- enabled: boolean;
21
- allowedSources: ReadonlySet<HookSource>;
22
- rateLimitPerMin: number;
23
- dedupThreshold: number;
24
- llmClassify: boolean;
25
- dryRun: boolean;
26
- queueSize: number;
27
- minLength: number;
28
- piiPolicy: "redact" | "drop";
29
- }
30
- export declare const DEFAULTS: HookConfig;
31
- /** Parse "1"/"true"/"yes" as true; everything else false. */
32
- declare function parseBool(v: string | undefined, fallback: boolean): boolean;
33
- declare function parseInt0(v: string | undefined, fallback: number, lo: number, hi: number): number;
34
- declare function parseFloat0(v: string | undefined, fallback: number, lo: number, hi: number): number;
35
- declare function parseSources(v: string | undefined, fallback: ReadonlySet<HookSource>): ReadonlySet<HookSource>;
36
- declare function parsePolicy(v: string | undefined): "redact" | "drop";
37
- /**
38
- * Build a HookConfig from process.env (or a passed-in env-like object for tests).
39
- */
40
- export declare function loadConfig(env?: NodeJS.ProcessEnv): HookConfig;
41
- /** Internal helper kept exported for tests. */
42
- export declare const __test: {
43
- parseBool: typeof parseBool;
44
- parseInt0: typeof parseInt0;
45
- parseFloat0: typeof parseFloat0;
46
- parseSources: typeof parseSources;
47
- parsePolicy: typeof parsePolicy;
48
- };
49
- export {};
@@ -1,106 +0,0 @@
1
- /**
2
- * src/lib/hooks/config.ts — T7: Env config loader + validator.
3
- *
4
- * Reads the following env vars (all OPT-IN — defaults are most-restrictive):
5
- *
6
- * NOX_HOOKS_ENABLED → "1" | "0" (default "0" — Layer 1 gate is OFF)
7
- * NOX_HOOK_SOURCES → CSV of HookSource (default "openclaw")
8
- * NOX_HOOK_RATE_LIMIT → captures/min (default 30, min 1, max 1000)
9
- * NOX_HOOK_DEDUP_THRESHOLD→ cosine threshold (default 0.95, range 0.5..0.999)
10
- * NOX_HOOK_LLM_CLASSIFY → "1" | "0" (default "0" — heuristics only)
11
- * NOX_HOOK_DRY_RUN → "1" | "0" (default "0")
12
- * NOX_HOOK_QUEUE_SIZE → worker queue max (default 10000)
13
- * NOX_HOOK_MIN_LENGTH → classifier min chars (default 20)
14
- * NOX_HOOK_PII_POLICY → "redact" | "drop" (default "redact")
15
- *
16
- * Defensive: invalid values fall back to defaults + warn() to telemetry.
17
- */
18
- export const DEFAULTS = Object.freeze({
19
- enabled: false,
20
- allowedSources: new Set(["openclaw"]),
21
- rateLimitPerMin: 30,
22
- dedupThreshold: 0.95,
23
- llmClassify: false,
24
- dryRun: false,
25
- queueSize: 10_000,
26
- minLength: 20,
27
- piiPolicy: "redact",
28
- });
29
- const VALID_SOURCES = new Set([
30
- "openclaw",
31
- "cli",
32
- "manual",
33
- "mcp",
34
- "api",
35
- "unknown",
36
- ]);
37
- /** Parse "1"/"true"/"yes" as true; everything else false. */
38
- function parseBool(v, fallback) {
39
- if (v === undefined)
40
- return fallback;
41
- const s = v.trim().toLowerCase();
42
- if (["1", "true", "yes", "on"].includes(s))
43
- return true;
44
- if (["0", "false", "no", "off", ""].includes(s))
45
- return false;
46
- return fallback;
47
- }
48
- function parseInt0(v, fallback, lo, hi) {
49
- if (v === undefined)
50
- return fallback;
51
- const n = Number.parseInt(v.trim(), 10);
52
- if (!Number.isFinite(n) || Number.isNaN(n))
53
- return fallback;
54
- if (n < lo || n > hi)
55
- return fallback;
56
- return n;
57
- }
58
- function parseFloat0(v, fallback, lo, hi) {
59
- if (v === undefined)
60
- return fallback;
61
- const n = Number.parseFloat(v.trim());
62
- if (!Number.isFinite(n) || Number.isNaN(n))
63
- return fallback;
64
- if (n < lo || n > hi)
65
- return fallback;
66
- return n;
67
- }
68
- function parseSources(v, fallback) {
69
- if (v === undefined || v.trim() === "")
70
- return fallback;
71
- const items = v.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
72
- const out = new Set();
73
- for (const it of items) {
74
- if (VALID_SOURCES.has(it))
75
- out.add(it);
76
- }
77
- if (out.size === 0)
78
- return fallback;
79
- return out;
80
- }
81
- function parsePolicy(v) {
82
- if (v === undefined)
83
- return DEFAULTS.piiPolicy;
84
- const s = v.trim().toLowerCase();
85
- if (s === "drop")
86
- return "drop";
87
- return "redact";
88
- }
89
- /**
90
- * Build a HookConfig from process.env (or a passed-in env-like object for tests).
91
- */
92
- export function loadConfig(env = process.env) {
93
- return Object.freeze({
94
- enabled: parseBool(env["NOX_HOOKS_ENABLED"], DEFAULTS.enabled),
95
- allowedSources: parseSources(env["NOX_HOOK_SOURCES"], DEFAULTS.allowedSources),
96
- rateLimitPerMin: parseInt0(env["NOX_HOOK_RATE_LIMIT"], DEFAULTS.rateLimitPerMin, 1, 1000),
97
- dedupThreshold: parseFloat0(env["NOX_HOOK_DEDUP_THRESHOLD"], DEFAULTS.dedupThreshold, 0.5, 0.999),
98
- llmClassify: parseBool(env["NOX_HOOK_LLM_CLASSIFY"], DEFAULTS.llmClassify),
99
- dryRun: parseBool(env["NOX_HOOK_DRY_RUN"], DEFAULTS.dryRun),
100
- queueSize: parseInt0(env["NOX_HOOK_QUEUE_SIZE"], DEFAULTS.queueSize, 100, 1_000_000),
101
- minLength: parseInt0(env["NOX_HOOK_MIN_LENGTH"], DEFAULTS.minLength, 1, 10_000),
102
- piiPolicy: parsePolicy(env["NOX_HOOK_PII_POLICY"]),
103
- });
104
- }
105
- /** Internal helper kept exported for tests. */
106
- export const __test = { parseBool, parseInt0, parseFloat0, parseSources, parsePolicy };
@@ -1,35 +0,0 @@
1
- /**
2
- * src/lib/hooks/decorators.ts — T10: Explicit user override of classifier.
3
- *
4
- * Users (or upstream agents) can mark content with inline annotations:
5
- *
6
- * // @nox:capture → force capture, bypassing classifier (but NOT
7
- * privacy filter or rate-limit/dedup)
8
- * // @nox:skip → force skip, short-circuit pipeline immediately
9
- *
10
- * Supported comment shapes (case-insensitive, leading whitespace allowed):
11
- * "// @nox:capture", "/* @nox:capture *\/", "# @nox:capture",
12
- * "<!-- @nox:capture -->"
13
- *
14
- * The decorator is detected on the FIRST 4 lines of the content body to
15
- * avoid scanning huge transcripts. False positives in code-style text are
16
- * acceptable — the user opt-in is explicit.
17
- */
18
- import type { HookEvent } from "./types.js";
19
- export type Decorator = "capture" | "skip";
20
- /**
21
- * Parse decorators from the first MAX_LINES lines of `content`.
22
- * Returns deduped, ordered list.
23
- */
24
- export declare function parseDecorators(content: string, MAX_LINES?: number): Decorator[];
25
- /**
26
- * Mutates event.decorators with parsed results if not already set.
27
- */
28
- export declare function attachDecorators(event: HookEvent): HookEvent;
29
- /**
30
- * Returns "capture" if force-capture decorator present, "skip" if force-skip,
31
- * else null (no override).
32
- *
33
- * Precedence: skip wins over capture (defensive).
34
- */
35
- export declare function decoratorOverride(event: HookEvent): Decorator | null;
@@ -1,59 +0,0 @@
1
- /**
2
- * src/lib/hooks/decorators.ts — T10: Explicit user override of classifier.
3
- *
4
- * Users (or upstream agents) can mark content with inline annotations:
5
- *
6
- * // @nox:capture → force capture, bypassing classifier (but NOT
7
- * privacy filter or rate-limit/dedup)
8
- * // @nox:skip → force skip, short-circuit pipeline immediately
9
- *
10
- * Supported comment shapes (case-insensitive, leading whitespace allowed):
11
- * "// @nox:capture", "/* @nox:capture *\/", "# @nox:capture",
12
- * "<!-- @nox:capture -->"
13
- *
14
- * The decorator is detected on the FIRST 4 lines of the content body to
15
- * avoid scanning huge transcripts. False positives in code-style text are
16
- * acceptable — the user opt-in is explicit.
17
- */
18
- const PATTERNS = [
19
- { re: /(^|\s)(?:\/\/|#|<!--|\/\*)\s*@nox:capture\b/i, kind: "capture" },
20
- { re: /(^|\s)(?:\/\/|#|<!--|\/\*)\s*@nox:skip\b/i, kind: "skip" },
21
- ];
22
- /**
23
- * Parse decorators from the first MAX_LINES lines of `content`.
24
- * Returns deduped, ordered list.
25
- */
26
- export function parseDecorators(content, MAX_LINES = 4) {
27
- if (!content)
28
- return [];
29
- const head = content.split("\n").slice(0, MAX_LINES).join("\n");
30
- const seen = new Set();
31
- for (const p of PATTERNS) {
32
- if (p.re.test(head))
33
- seen.add(p.kind);
34
- }
35
- return Array.from(seen);
36
- }
37
- /**
38
- * Mutates event.decorators with parsed results if not already set.
39
- */
40
- export function attachDecorators(event) {
41
- if (event.decorators && event.decorators.length > 0)
42
- return event;
43
- const decorators = parseDecorators(event.content);
44
- return decorators.length > 0 ? { ...event, decorators } : event;
45
- }
46
- /**
47
- * Returns "capture" if force-capture decorator present, "skip" if force-skip,
48
- * else null (no override).
49
- *
50
- * Precedence: skip wins over capture (defensive).
51
- */
52
- export function decoratorOverride(event) {
53
- const decorators = event.decorators ?? parseDecorators(event.content);
54
- if (decorators.includes("skip"))
55
- return "skip";
56
- if (decorators.includes("capture"))
57
- return "capture";
58
- return null;
59
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * src/lib/hooks/pipeline.ts — T6: 5-layer orchestrator.
3
- *
4
- * Chains layers in load-bearing order:
5
- *
6
- * Layer 1: env gate (config.enabled)
7
- * Layer 2: source allowlist (source-allowlist.ts)
8
- * Layer 3: privacy filter (privacy-filter-adapter.ts)
9
- * Layer 4: classifier (classifier.ts)
10
- * Layer 5: rate-limit+dedup (rate-limit.ts)
11
- *
12
- * Decorator overrides (T10):
13
- * - "@nox:skip" short-circuits at Layer 1 (before anything else)
14
- * - "@nox:capture" bypasses Layer 4 (classifier) but NOT Layers 1/2/3/5
15
- *
16
- * Telemetry: emits one row per pipeline run via the injected telemetry
17
- * sink — captured OR rejected. NEVER includes raw content.
18
- *
19
- * Dry-run: when config.dryRun is true, the pipeline still runs through
20
- * every layer but does NOT call ingestFn at the end. Outcome reports
21
- * dry_run=true.
22
- */
23
- import { type HookConfig } from "./config.js";
24
- import { type RedactFn } from "./privacy-filter-adapter.js";
25
- import { type SimilarityFn } from "./rate-limit.js";
26
- import type { HookEvent, HookResult, HookTelemetryRow } from "./types.js";
27
- /** ingestText sink — pipeline writes here on capture. */
28
- export type IngestFn = (params: {
29
- text: string;
30
- source: string;
31
- session_id: string;
32
- project_slug: string;
33
- provenance: "hook";
34
- redaction_count: number;
35
- ts: string;
36
- event_id: string;
37
- }) => Promise<{
38
- chunk_id: number;
39
- } | {
40
- chunk_id: null;
41
- error: string;
42
- }>;
43
- /** Telemetry sink — pipeline emits one row per event. */
44
- export type TelemetrySink = (row: HookTelemetryRow) => void | Promise<void>;
45
- export interface PipelineDeps {
46
- config?: HookConfig;
47
- redact?: RedactFn;
48
- similarity?: SimilarityFn;
49
- ingest?: IngestFn;
50
- telemetry?: TelemetrySink;
51
- /** Inject clock (tests). */
52
- now?: () => number;
53
- /** Inject llm classify (T4). */
54
- llmClassify?: (text: string) => {
55
- capture: boolean;
56
- reason: string;
57
- };
58
- }
59
- export interface PipelineHandle {
60
- run(event: HookEvent): Promise<HookResult>;
61
- /** Reset internal rate-limit/dedup state (tests, manual). */
62
- resetState(): void;
63
- /** Exposed for inspection (CLI/HTTP status). */
64
- inspect(): {
65
- config: HookConfig;
66
- rateLimitTokens: number;
67
- recentBufferSize: number;
68
- };
69
- }
70
- /**
71
- * Build a pipeline handle. Stateful: keeps a RateLimitState across calls.
72
- *
73
- * Each invocation runs the 5 layers in order. Every rejection emits ONE
74
- * telemetry row. A capture emits ONE telemetry row plus the ingest call.
75
- */
76
- export declare function createPipeline(deps?: PipelineDeps): PipelineHandle;
@@ -1,213 +0,0 @@
1
- /**
2
- * src/lib/hooks/pipeline.ts — T6: 5-layer orchestrator.
3
- *
4
- * Chains layers in load-bearing order:
5
- *
6
- * Layer 1: env gate (config.enabled)
7
- * Layer 2: source allowlist (source-allowlist.ts)
8
- * Layer 3: privacy filter (privacy-filter-adapter.ts)
9
- * Layer 4: classifier (classifier.ts)
10
- * Layer 5: rate-limit+dedup (rate-limit.ts)
11
- *
12
- * Decorator overrides (T10):
13
- * - "@nox:skip" short-circuits at Layer 1 (before anything else)
14
- * - "@nox:capture" bypasses Layer 4 (classifier) but NOT Layers 1/2/3/5
15
- *
16
- * Telemetry: emits one row per pipeline run via the injected telemetry
17
- * sink — captured OR rejected. NEVER includes raw content.
18
- *
19
- * Dry-run: when config.dryRun is true, the pipeline still runs through
20
- * every layer but does NOT call ingestFn at the end. Outcome reports
21
- * dry_run=true.
22
- */
23
- import { loadConfig } from "./config.js";
24
- import { evaluateSourceAllowlist } from "./source-allowlist.js";
25
- import { applyPrivacyFilter, identityRedact } from "./privacy-filter-adapter.js";
26
- import { applyClassifier } from "./classifier.js";
27
- import { applyRateLimit, createState } from "./rate-limit.js";
28
- import { decoratorOverride, attachDecorators } from "./decorators.js";
29
- const DEFAULT_TELEMETRY = () => {
30
- /* no-op */
31
- };
32
- const DEFAULT_INGEST = async () => ({ chunk_id: null, error: "no_ingest_configured" });
33
- /**
34
- * Build a pipeline handle. Stateful: keeps a RateLimitState across calls.
35
- *
36
- * Each invocation runs the 5 layers in order. Every rejection emits ONE
37
- * telemetry row. A capture emits ONE telemetry row plus the ingest call.
38
- */
39
- export function createPipeline(deps = {}) {
40
- const config = deps.config ?? loadConfig();
41
- const redact = deps.redact ?? identityRedact;
42
- const ingest = deps.ingest ?? DEFAULT_INGEST;
43
- const telemetry = deps.telemetry ?? DEFAULT_TELEMETRY;
44
- const now = deps.now ?? Date.now;
45
- let rlState = createState(config.rateLimitPerMin, now);
46
- async function emit(event, kind, layer, reason, redaction_count) {
47
- const row = {
48
- event_uuid: event.event_id,
49
- session_id: event.session_id ?? "unknown",
50
- project_slug: event.project_slug ?? "unknown",
51
- kind,
52
- timestamp: event.ts,
53
- payload_json: JSON.stringify({ layer, reason }),
54
- redaction_count,
55
- retention_days: 30,
56
- };
57
- try {
58
- await telemetry(row);
59
- }
60
- catch {
61
- /* telemetry errors must NEVER break the pipeline */
62
- }
63
- }
64
- function kindForEvent(_e) {
65
- // P2 spec §6.1 enum. Hook events arrive as user_prompt or tool_use most
66
- // commonly; pipeline doesn't currently distinguish — default tool_use.
67
- return "tool_use";
68
- }
69
- return {
70
- async run(rawEvent) {
71
- const startMs = now();
72
- const event = attachDecorators(rawEvent);
73
- const ctx = { event, trace: [] };
74
- function record(layer, dec) {
75
- const t_ms = now() - startMs;
76
- ctx.trace.push({ layer, decision: { ...dec, layer }, t_ms });
77
- return dec;
78
- }
79
- async function reject(reasonCode, layer, dec, redaction_count = 0) {
80
- await emit(event, kindForEvent(event), layer, dec.reason, redaction_count);
81
- const result = {
82
- captured: false,
83
- reason: reasonCode,
84
- layer,
85
- duration_ms: now() - startMs,
86
- dry_run: config.dryRun,
87
- };
88
- ctx.outcome = result;
89
- return result;
90
- }
91
- // ── Decorator early-skip (T10) ─────────────────────────────────────
92
- const override = decoratorOverride(event);
93
- if (override === "skip") {
94
- const dec = {
95
- capture: false,
96
- reason: "decorator @nox:skip",
97
- layer: "decorator",
98
- };
99
- record("decorator", dec);
100
- return reject("explicit_skip", "decorator", dec, 0);
101
- }
102
- // ── Layer 1: env gate ──────────────────────────────────────────────
103
- if (!config.enabled) {
104
- const dec = {
105
- capture: false,
106
- reason: "NOX_HOOKS_ENABLED!=1",
107
- layer: "env-gate",
108
- };
109
- record("env-gate", dec);
110
- return reject("env_disabled", "env-gate", dec, 0);
111
- }
112
- record("env-gate", { capture: true, reason: "enabled", layer: "env-gate" });
113
- // ── Layer 2: source allowlist ──────────────────────────────────────
114
- const l2 = evaluateSourceAllowlist(event, config);
115
- record("source-allowlist", l2);
116
- if (!l2.capture)
117
- return reject("source_not_allowed", "source-allowlist", l2, 0);
118
- // ── Layer 3: privacy filter ────────────────────────────────────────
119
- const l3 = applyPrivacyFilter(ctx, {
120
- redact,
121
- dropOnDetect: config.piiPolicy === "drop",
122
- });
123
- record("privacy-filter", l3);
124
- if (!l3.capture) {
125
- return reject("pii_detected_skip", "privacy-filter", l3, ctx.redacted?.redaction_count ?? 0);
126
- }
127
- // ── Layer 4: classifier (skippable via @nox:capture) ───────────────
128
- if (override === "capture") {
129
- record("classifier", {
130
- capture: true,
131
- reason: "decorator @nox:capture bypassed classifier",
132
- layer: "classifier",
133
- });
134
- }
135
- else {
136
- const l4 = applyClassifier(ctx, {
137
- minLength: config.minLength,
138
- llmFallback: config.llmClassify,
139
- ...(deps.llmClassify ? { llmClassify: deps.llmClassify } : {}),
140
- });
141
- record("classifier", l4);
142
- if (!l4.capture) {
143
- return reject("classifier_low_signal", "classifier", l4, ctx.redacted?.redaction_count ?? 0);
144
- }
145
- }
146
- // ── Layer 5: rate-limit + dedup ────────────────────────────────────
147
- const l5 = applyRateLimit(ctx, rlState, {
148
- capacityPerMin: config.rateLimitPerMin,
149
- dedupThreshold: config.dedupThreshold,
150
- ...(deps.similarity ? { similarity: deps.similarity } : {}),
151
- now,
152
- });
153
- record("rate-limit", l5);
154
- if (!l5.capture) {
155
- const code = l5.reason.startsWith("dedup_hit") ? "dedup_hit" : "rate_limited";
156
- return reject(code, "rate-limit", l5, ctx.redacted?.redaction_count ?? 0);
157
- }
158
- // ── Persistence (Layer 6 implicit) ────────────────────────────────
159
- const redaction_count = ctx.redacted?.redaction_count ?? 0;
160
- if (config.dryRun) {
161
- await emit(event, kindForEvent(event), "persistence", "dry_run_skip", redaction_count);
162
- return {
163
- captured: false,
164
- reason: "dry_run",
165
- layer: "persistence",
166
- duration_ms: now() - startMs,
167
- dry_run: true,
168
- };
169
- }
170
- const ingestResult = await ingest({
171
- text: ctx.redacted?.text ?? event.content,
172
- source: event.source,
173
- session_id: event.session_id ?? "unknown",
174
- project_slug: event.project_slug ?? "unknown",
175
- provenance: "hook",
176
- redaction_count,
177
- ts: event.ts,
178
- event_id: event.event_id,
179
- });
180
- if (ingestResult.chunk_id === null) {
181
- await emit(event, kindForEvent(event), "persistence", `ingest_failed:${ingestResult.error}`, redaction_count);
182
- return {
183
- captured: false,
184
- reason: "invalid_input",
185
- layer: "persistence",
186
- duration_ms: now() - startMs,
187
- dry_run: false,
188
- };
189
- }
190
- await emit(event, kindForEvent(event), "persistence", "ok", redaction_count);
191
- const ok = {
192
- captured: true,
193
- reason: "ok",
194
- layer: "persisted",
195
- chunk_id: ingestResult.chunk_id,
196
- duration_ms: now() - startMs,
197
- dry_run: false,
198
- };
199
- ctx.outcome = ok;
200
- return ok;
201
- },
202
- resetState() {
203
- rlState = createState(config.rateLimitPerMin, now);
204
- },
205
- inspect() {
206
- return {
207
- config,
208
- rateLimitTokens: rlState.tokens,
209
- recentBufferSize: rlState.recent.length,
210
- };
211
- },
212
- };
213
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * src/lib/hooks/privacy-filter-adapter.ts — T3: Layer 3 of pipeline.
3
- *
4
- * Wraps staged-A1 `redact()` (13 patterns, 68 tests, 1.7% FP) so the
5
- * pipeline (T6) can call a stable local interface even if the upstream
6
- * A1 contract evolves.
7
- *
8
- * Contract (locked, mirrors staged-privacy/edits/privacy/filter.ts):
9
- *
10
- * redact(rawText: string): {
11
- * text: string; // potentially with `<private>` markers replacing PII
12
- * redactionCount: number; // total matches replaced
13
- * kinds: string[]; // deduped pattern names
14
- * }
15
- *
16
- * Layer 3 ALWAYS redacts (default policy). If NOX_HOOK_PII_POLICY=drop,
17
- * the pipeline (T6) will reject when redaction_count > 0 — but THIS module
18
- * never drops; it only transforms.
19
- *
20
- * Telemetry: this module emits ZERO content; it returns metadata so the
21
- * pipeline can log layer name + reason + counts.
22
- */
23
- import type { CaptureDecision, HookContext } from "./types.js";
24
- /** Shape of the upstream A1 redact() result (locked). */
25
- export interface A1RedactResult {
26
- text: string;
27
- redactionCount: number;
28
- kinds: string[];
29
- }
30
- /** Pluggable redact() signature — defaults to staged-A1 import at wire-up. */
31
- export type RedactFn = (rawText: string) => A1RedactResult;
32
- /**
33
- * Default redact() — identity function pre-T11 swap.
34
- * Production wiring imports the real `redact` from staged-A1
35
- * (see staged-privacy/edits/privacy/filter.ts).
36
- *
37
- * The pipeline (T6) accepts a custom RedactFn via DI so tests don't need
38
- * the real regex pack.
39
- */
40
- export declare const identityRedact: RedactFn;
41
- export interface PrivacyAdapterOpts {
42
- /** Redact implementation. Default = identityRedact. */
43
- redact?: RedactFn;
44
- /** When true, treat any redaction_count>0 as a drop signal. Default false. */
45
- dropOnDetect?: boolean;
46
- }
47
- /**
48
- * Apply Layer 3 to a HookContext.
49
- * Mutates ctx.redacted with the result.
50
- *
51
- * Returns:
52
- * capture=true → forward to Layer 4 with redacted text
53
- * capture=false → drop (only when dropOnDetect && redactionCount > 0)
54
- */
55
- export declare function applyPrivacyFilter(ctx: HookContext, opts?: PrivacyAdapterOpts): CaptureDecision;
@@ -1,84 +0,0 @@
1
- /**
2
- * src/lib/hooks/privacy-filter-adapter.ts — T3: Layer 3 of pipeline.
3
- *
4
- * Wraps staged-A1 `redact()` (13 patterns, 68 tests, 1.7% FP) so the
5
- * pipeline (T6) can call a stable local interface even if the upstream
6
- * A1 contract evolves.
7
- *
8
- * Contract (locked, mirrors staged-privacy/edits/privacy/filter.ts):
9
- *
10
- * redact(rawText: string): {
11
- * text: string; // potentially with `<private>` markers replacing PII
12
- * redactionCount: number; // total matches replaced
13
- * kinds: string[]; // deduped pattern names
14
- * }
15
- *
16
- * Layer 3 ALWAYS redacts (default policy). If NOX_HOOK_PII_POLICY=drop,
17
- * the pipeline (T6) will reject when redaction_count > 0 — but THIS module
18
- * never drops; it only transforms.
19
- *
20
- * Telemetry: this module emits ZERO content; it returns metadata so the
21
- * pipeline can log layer name + reason + counts.
22
- */
23
- /**
24
- * Default redact() — identity function pre-T11 swap.
25
- * Production wiring imports the real `redact` from staged-A1
26
- * (see staged-privacy/edits/privacy/filter.ts).
27
- *
28
- * The pipeline (T6) accepts a custom RedactFn via DI so tests don't need
29
- * the real regex pack.
30
- */
31
- export const identityRedact = (rawText) => ({
32
- text: rawText,
33
- redactionCount: 0,
34
- kinds: [],
35
- });
36
- /**
37
- * Apply Layer 3 to a HookContext.
38
- * Mutates ctx.redacted with the result.
39
- *
40
- * Returns:
41
- * capture=true → forward to Layer 4 with redacted text
42
- * capture=false → drop (only when dropOnDetect && redactionCount > 0)
43
- */
44
- export function applyPrivacyFilter(ctx, opts = {}) {
45
- const redact = opts.redact ?? identityRedact;
46
- const dropOnDetect = opts.dropOnDetect ?? false;
47
- let result;
48
- try {
49
- result = redact(ctx.event.content);
50
- }
51
- catch (e) {
52
- // Defensive: if A1 throws, drop the event to fail closed.
53
- return {
54
- capture: false,
55
- reason: `A1 redact threw: ${e.message || "unknown"}`,
56
- layer: "privacy-filter",
57
- };
58
- }
59
- ctx.redacted = {
60
- text: result.text,
61
- redaction_count: result.redactionCount,
62
- kinds: result.kinds.slice(),
63
- };
64
- if (dropOnDetect && result.redactionCount > 0) {
65
- return {
66
- capture: false,
67
- reason: `pii_detected redactions=${result.redactionCount} kinds=[${result.kinds.join("|")}] policy=drop`,
68
- layer: "privacy-filter",
69
- };
70
- }
71
- if (result.redactionCount > 0) {
72
- // Log redaction in trace but continue.
73
- return {
74
- capture: true,
75
- reason: `redacted=${result.redactionCount} kinds=[${result.kinds.join("|")}] policy=redact`,
76
- layer: "privacy-filter",
77
- };
78
- }
79
- return {
80
- capture: true,
81
- reason: "no_pii_detected",
82
- layer: "privacy-filter",
83
- };
84
- }