nox-mem 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (397) hide show
  1. package/README.md +24 -16
  2. package/dist/__tests__/brief-diversity.test.js +266 -0
  3. package/dist/__tests__/brief.test.js +287 -0
  4. package/dist/__tests__/churn.test.js +66 -0
  5. package/dist/__tests__/edge-typing.test.js +99 -0
  6. package/dist/__tests__/ingest-event.test.js +151 -0
  7. package/dist/__tests__/op-audit-e2e.test.js +130 -0
  8. package/dist/__tests__/pragma-alignment.test.js +123 -0
  9. package/dist/__tests__/reranker.test.js +326 -0
  10. package/dist/__tests__/retention.test.js +99 -0
  11. package/dist/__tests__/search-track-access.test.js +49 -0
  12. package/dist/__tests__/spo-injection.test.js +172 -0
  13. package/dist/__tests__/temporal-detector.test.js +103 -0
  14. package/dist/api/wire-up.js +12 -381
  15. package/dist/api-server.js +6 -102
  16. package/dist/db.js +61 -2
  17. package/dist/embed.js +23 -2
  18. package/dist/index.js +1 -22
  19. package/dist/knowledge-graph.js +20 -0
  20. package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
  21. package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
  22. package/dist/lib/answer/__tests__/integration.test.js +347 -0
  23. package/dist/lib/answer/__tests__/prompt.test.js +117 -0
  24. package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
  25. package/dist/lib/answer/provider.js +29 -4
  26. package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
  27. package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
  28. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
  29. package/dist/lib/events/__tests__/bus.test.js +208 -0
  30. package/dist/lib/ingest-router.js +0 -43
  31. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
  32. package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
  33. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
  34. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
  35. package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
  36. package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
  37. package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
  38. package/dist/privacy/__tests__/filter.test.js +352 -0
  39. package/dist/providers/__tests__/conformance-extended.test.js +249 -0
  40. package/dist/providers/__tests__/conformance.test.js +98 -0
  41. package/dist/providers/__tests__/cost-cap.test.js +151 -0
  42. package/dist/providers/__tests__/e2e-real.test.js +79 -0
  43. package/dist/providers/__tests__/factory.test.js +80 -0
  44. package/dist/providers/__tests__/fallback.test.js +223 -0
  45. package/dist/providers/__tests__/gemini.test.js +191 -0
  46. package/dist/providers/__tests__/health.test.js +128 -0
  47. package/dist/providers/__tests__/telemetry.test.js +219 -0
  48. package/dist/reindex.js +2 -2
  49. package/package.json +3 -4
  50. package/dist/api/answer.d.ts +0 -116
  51. package/dist/api/answer.validate-patch.d.ts +0 -72
  52. package/dist/api/brief-diversity.d.ts +0 -64
  53. package/dist/api/brief.d.ts +0 -114
  54. package/dist/api/conflict.d.ts +0 -33
  55. package/dist/api/conflict.js +0 -143
  56. package/dist/api/cors.d.ts +0 -73
  57. package/dist/api/events-stream-limited.d.ts +0 -133
  58. package/dist/api/events-stream-limited.js +0 -217
  59. package/dist/api/events-stream.d.ts +0 -53
  60. package/dist/api/events-stream.js +0 -125
  61. package/dist/api/export.d.ts +0 -42
  62. package/dist/api/export.js +0 -85
  63. package/dist/api/health-confidence-adapter.d.ts +0 -29
  64. package/dist/api/health-confidence-adapter.js +0 -73
  65. package/dist/api/health-confidence.d.ts +0 -36
  66. package/dist/api/health-confidence.js +0 -141
  67. package/dist/api/hooks.d.ts +0 -50
  68. package/dist/api/hooks.js +0 -115
  69. package/dist/api/import.d.ts +0 -38
  70. package/dist/api/import.js +0 -87
  71. package/dist/api/ingest-event.d.ts +0 -65
  72. package/dist/api/mark.d.ts +0 -42
  73. package/dist/api/mark.js +0 -127
  74. package/dist/api/server-deps-a2.d.ts +0 -55
  75. package/dist/api/server-deps-a2.js +0 -138
  76. package/dist/api/server-deps-l2-l3.d.ts +0 -68
  77. package/dist/api/server-deps-l2-l3.js +0 -123
  78. package/dist/api/server-deps-p1.d.ts +0 -84
  79. package/dist/api/server-deps-p2.d.ts +0 -32
  80. package/dist/api/server-deps-p2.js +0 -84
  81. package/dist/api/server-deps-p5.d.ts +0 -66
  82. package/dist/api/server-deps-p5.js +0 -139
  83. package/dist/api/viewer-static.d.ts +0 -30
  84. package/dist/api/viewer-static.js +0 -102
  85. package/dist/api/wire-up.d.ts +0 -54
  86. package/dist/api-impact.d.ts +0 -30
  87. package/dist/api-server.d.ts +0 -2
  88. package/dist/backfill-fts-anchor.d.ts +0 -15
  89. package/dist/backfill-source-type.d.ts +0 -20
  90. package/dist/churn.d.ts +0 -31
  91. package/dist/cli/answer.d.ts +0 -66
  92. package/dist/cli/conflict.d.ts +0 -38
  93. package/dist/cli/conflict.js +0 -282
  94. package/dist/cli/export.d.ts +0 -51
  95. package/dist/cli/export.js +0 -280
  96. package/dist/cli/hooks.d.ts +0 -54
  97. package/dist/cli/hooks.js +0 -133
  98. package/dist/cli/import.d.ts +0 -52
  99. package/dist/cli/import.js +0 -274
  100. package/dist/cli/mark.d.ts +0 -33
  101. package/dist/cli/mark.js +0 -130
  102. package/dist/cli/ocr-batch.d.ts +0 -12
  103. package/dist/cli/ocr-batch.js +0 -411
  104. package/dist/cli/snapshot-main.d.ts +0 -30
  105. package/dist/cli/snapshot-main.js +0 -47
  106. package/dist/cli/viewer.d.ts +0 -35
  107. package/dist/cli/viewer.js +0 -71
  108. package/dist/cli-telemetry.d.ts +0 -36
  109. package/dist/cli-telemetry.js +0 -150
  110. package/dist/compact.d.ts +0 -7
  111. package/dist/consolidate.d.ts +0 -18
  112. package/dist/consolidation.d.ts +0 -32
  113. package/dist/cross-agent-v2.d.ts +0 -45
  114. package/dist/cross-search.d.ts +0 -11
  115. package/dist/crystallize.d.ts +0 -43
  116. package/dist/db.d.ts +0 -11
  117. package/dist/dedup.d.ts +0 -1
  118. package/dist/detect-changes.d.ts +0 -29
  119. package/dist/digest.d.ts +0 -1
  120. package/dist/doctor.d.ts +0 -1
  121. package/dist/embed.d.ts +0 -57
  122. package/dist/evals.d.ts +0 -176
  123. package/dist/evals.js +0 -351
  124. package/dist/generate-user-profile.d.ts +0 -18
  125. package/dist/graphify-ingest.d.ts +0 -18
  126. package/dist/impact.d.ts +0 -39
  127. package/dist/index.d.ts +0 -2
  128. package/dist/ingest-entity.d.ts +0 -44
  129. package/dist/ingest.d.ts +0 -13
  130. package/dist/kg-llm.d.ts +0 -39
  131. package/dist/knowledge-graph.d.ts +0 -72
  132. package/dist/lib/answer/config.d.ts +0 -41
  133. package/dist/lib/answer/index.d.ts +0 -47
  134. package/dist/lib/answer/prompt.d.ts +0 -37
  135. package/dist/lib/answer/provider.d.ts +0 -47
  136. package/dist/lib/answer/retrieval.d.ts +0 -36
  137. package/dist/lib/answer/telemetry.d.ts +0 -99
  138. package/dist/lib/answer/types.d.ts +0 -108
  139. package/dist/lib/api/error-leak-fix.d.ts +0 -54
  140. package/dist/lib/api/safe-error-message.d.ts +0 -70
  141. package/dist/lib/archive/common-passwords.d.ts +0 -37
  142. package/dist/lib/archive/common-passwords.js +0 -753
  143. package/dist/lib/archive/encryption.d.ts +0 -81
  144. package/dist/lib/archive/encryption.js +0 -236
  145. package/dist/lib/archive/enforce-strength.d.ts +0 -54
  146. package/dist/lib/archive/enforce-strength.js +0 -70
  147. package/dist/lib/archive/entropy.d.ts +0 -34
  148. package/dist/lib/archive/entropy.js +0 -180
  149. package/dist/lib/archive/export-locking.d.ts +0 -102
  150. package/dist/lib/archive/export-locking.js +0 -202
  151. package/dist/lib/archive/format.d.ts +0 -20
  152. package/dist/lib/archive/format.js +0 -174
  153. package/dist/lib/archive/index.d.ts +0 -23
  154. package/dist/lib/archive/index.js +0 -17
  155. package/dist/lib/archive/manifest.d.ts +0 -53
  156. package/dist/lib/archive/manifest.js +0 -183
  157. package/dist/lib/archive/migration.d.ts +0 -36
  158. package/dist/lib/archive/migration.js +0 -100
  159. package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
  160. package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
  161. package/dist/lib/archive/orchestrator.d.ts +0 -166
  162. package/dist/lib/archive/orchestrator.js +0 -428
  163. package/dist/lib/archive/serializers/chunks.d.ts +0 -30
  164. package/dist/lib/archive/serializers/chunks.js +0 -113
  165. package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
  166. package/dist/lib/archive/serializers/embeddings.js +0 -115
  167. package/dist/lib/archive/serializers/kg.d.ts +0 -28
  168. package/dist/lib/archive/serializers/kg.js +0 -184
  169. package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
  170. package/dist/lib/archive/serializers/ops_audit.js +0 -97
  171. package/dist/lib/archive/server-deps.d.ts +0 -131
  172. package/dist/lib/archive/server-deps.js +0 -232
  173. package/dist/lib/archive/strength.d.ts +0 -50
  174. package/dist/lib/archive/strength.js +0 -77
  175. package/dist/lib/archive/types.d.ts +0 -159
  176. package/dist/lib/archive/types.js +0 -45
  177. package/dist/lib/archive/unpack-streaming.d.ts +0 -70
  178. package/dist/lib/archive/unpack-streaming.js +0 -255
  179. package/dist/lib/auth/localhost-guard.d.ts +0 -106
  180. package/dist/lib/confidence/config.d.ts +0 -37
  181. package/dist/lib/confidence/config.js +0 -107
  182. package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
  183. package/dist/lib/confidence/db-shim-singleton.js +0 -41
  184. package/dist/lib/confidence/db-shim.d.ts +0 -47
  185. package/dist/lib/confidence/db-shim.js +0 -141
  186. package/dist/lib/confidence/mark.d.ts +0 -58
  187. package/dist/lib/confidence/mark.js +0 -168
  188. package/dist/lib/confidence/ranking.d.ts +0 -69
  189. package/dist/lib/confidence/ranking.js +0 -101
  190. package/dist/lib/confidence/search-filter.d.ts +0 -44
  191. package/dist/lib/confidence/search-filter.js +0 -103
  192. package/dist/lib/confidence/types.d.ts +0 -146
  193. package/dist/lib/confidence/types.js +0 -20
  194. package/dist/lib/confidence/write-hooks.d.ts +0 -50
  195. package/dist/lib/confidence/write-hooks.js +0 -159
  196. package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
  197. package/dist/lib/conflict/audit-fk-check.js +0 -131
  198. package/dist/lib/conflict/audit-writer.d.ts +0 -39
  199. package/dist/lib/conflict/audit-writer.js +0 -133
  200. package/dist/lib/conflict/db-singleton.d.ts +0 -28
  201. package/dist/lib/conflict/db-singleton.js +0 -61
  202. package/dist/lib/conflict/db.d.ts +0 -27
  203. package/dist/lib/conflict/db.js +0 -20
  204. package/dist/lib/conflict/detector-direct.d.ts +0 -21
  205. package/dist/lib/conflict/detector-direct.js +0 -105
  206. package/dist/lib/conflict/evidence.d.ts +0 -24
  207. package/dist/lib/conflict/evidence.js +0 -76
  208. package/dist/lib/conflict/index.d.ts +0 -14
  209. package/dist/lib/conflict/index.js +0 -12
  210. package/dist/lib/conflict/scheduler.d.ts +0 -78
  211. package/dist/lib/conflict/scheduler.js +0 -111
  212. package/dist/lib/conflict/shadow.d.ts +0 -75
  213. package/dist/lib/conflict/shadow.js +0 -161
  214. package/dist/lib/conflict/types.d.ts +0 -133
  215. package/dist/lib/conflict/types.js +0 -19
  216. package/dist/lib/cost-cap.d.ts +0 -94
  217. package/dist/lib/deps/deps-registry.d.ts +0 -111
  218. package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
  219. package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
  220. package/dist/lib/eval-batch.d.ts +0 -34
  221. package/dist/lib/eval-batch.js +0 -103
  222. package/dist/lib/eval-metrics.d.ts +0 -36
  223. package/dist/lib/eval-metrics.js +0 -95
  224. package/dist/lib/eval.d.ts +0 -106
  225. package/dist/lib/eval.js +0 -343
  226. package/dist/lib/events/bus.d.ts +0 -135
  227. package/dist/lib/fts-anchor.d.ts +0 -1
  228. package/dist/lib/hooks/classifier.d.ts +0 -47
  229. package/dist/lib/hooks/classifier.js +0 -129
  230. package/dist/lib/hooks/config.d.ts +0 -49
  231. package/dist/lib/hooks/config.js +0 -106
  232. package/dist/lib/hooks/decorators.d.ts +0 -35
  233. package/dist/lib/hooks/decorators.js +0 -59
  234. package/dist/lib/hooks/pipeline.d.ts +0 -76
  235. package/dist/lib/hooks/pipeline.js +0 -213
  236. package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
  237. package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
  238. package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
  239. package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
  240. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
  241. package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
  242. package/dist/lib/hooks/rate-limit.d.ts +0 -54
  243. package/dist/lib/hooks/rate-limit.js +0 -122
  244. package/dist/lib/hooks/server-deps.d.ts +0 -61
  245. package/dist/lib/hooks/server-deps.js +0 -92
  246. package/dist/lib/hooks/source-allowlist.d.ts +0 -26
  247. package/dist/lib/hooks/source-allowlist.js +0 -53
  248. package/dist/lib/hooks/types.d.ts +0 -129
  249. package/dist/lib/hooks/types.js +0 -24
  250. package/dist/lib/hooks/worker.d.ts +0 -56
  251. package/dist/lib/hooks/worker.js +0 -150
  252. package/dist/lib/ingest-router.d.ts +0 -25
  253. package/dist/lib/ocr-detector.d.ts +0 -61
  254. package/dist/lib/ocr-detector.js +0 -138
  255. package/dist/lib/ocr-engine-stub.d.ts +0 -48
  256. package/dist/lib/ocr-engine-stub.js +0 -190
  257. package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
  258. package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
  259. package/dist/lib/ocr-jobs.d.ts +0 -67
  260. package/dist/lib/ocr-jobs.js +0 -129
  261. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
  262. package/dist/lib/op-audit.d.ts +0 -71
  263. package/dist/lib/privacy-br/detector.d.ts +0 -42
  264. package/dist/lib/privacy-br/detector.js +0 -130
  265. package/dist/lib/privacy-br/index.d.ts +0 -20
  266. package/dist/lib/privacy-br/index.js +0 -20
  267. package/dist/lib/privacy-br/integration.d.ts +0 -71
  268. package/dist/lib/privacy-br/integration.js +0 -74
  269. package/dist/lib/privacy-br/patterns.d.ts +0 -117
  270. package/dist/lib/privacy-br/patterns.js +0 -434
  271. package/dist/lib/privacy-br/redact.d.ts +0 -42
  272. package/dist/lib/privacy-br/redact.js +0 -103
  273. package/dist/lib/privacy-br/types.d.ts +0 -55
  274. package/dist/lib/privacy-br/types.js +0 -25
  275. package/dist/lib/regex-extract/extractor.d.ts +0 -30
  276. package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
  277. package/dist/lib/regex-extract/index.d.ts +0 -14
  278. package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
  279. package/dist/lib/regex-extract/patterns.d.ts +0 -61
  280. package/dist/lib/regex-extract/production-wire.d.ts +0 -128
  281. package/dist/lib/regex-extract/reconcile.d.ts +0 -162
  282. package/dist/lib/regex-extract/strip-code.d.ts +0 -24
  283. package/dist/lib/regex-extract/types.d.ts +0 -48
  284. package/dist/lib/reranker.d.ts +0 -80
  285. package/dist/lib/shadow-tracker.d.ts +0 -191
  286. package/dist/lib/shadow-tracker.js +0 -384
  287. package/dist/lib/spo-injection.d.ts +0 -52
  288. package/dist/lib/telemetry-collector.d.ts +0 -158
  289. package/dist/lib/telemetry-collector.js +0 -249
  290. package/dist/lib/temporal-detector.d.ts +0 -27
  291. package/dist/lib/viewer/auth.d.ts +0 -37
  292. package/dist/lib/viewer/auth.js +0 -70
  293. package/dist/lib/viewer/backpressure.d.ts +0 -59
  294. package/dist/lib/viewer/backpressure.js +0 -100
  295. package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
  296. package/dist/lib/viewer/broadcast-singleton.js +0 -49
  297. package/dist/lib/viewer/broadcast.d.ts +0 -66
  298. package/dist/lib/viewer/broadcast.js +0 -96
  299. package/dist/lib/viewer/event-types.d.ts +0 -132
  300. package/dist/lib/viewer/event-types.js +0 -74
  301. package/dist/lib/viewer/instrumentation.d.ts +0 -106
  302. package/dist/lib/viewer/instrumentation.js +0 -224
  303. package/dist/lib/viewer/migration.d.ts +0 -23
  304. package/dist/lib/viewer/migration.js +0 -56
  305. package/dist/lib/viewer/redaction.d.ts +0 -44
  306. package/dist/lib/viewer/redaction.js +0 -139
  307. package/dist/lib/viewer/session.d.ts +0 -51
  308. package/dist/lib/viewer/session.js +0 -87
  309. package/dist/mcp/tools/answer.d.ts +0 -94
  310. package/dist/mcp/tools/archive.d.ts +0 -152
  311. package/dist/mcp/tools/archive.js +0 -170
  312. package/dist/mcp/tools/conflict.d.ts +0 -44
  313. package/dist/mcp/tools/conflict.js +0 -130
  314. package/dist/mcp/tools/hooks.d.ts +0 -29
  315. package/dist/mcp/tools/hooks.js +0 -78
  316. package/dist/mcp/tools/mark.d.ts +0 -38
  317. package/dist/mcp/tools/mark.js +0 -82
  318. package/dist/mcp/tools/viewer.d.ts +0 -58
  319. package/dist/mcp/tools/viewer.js +0 -64
  320. package/dist/mcp-server.d.ts +0 -2
  321. package/dist/metrics.d.ts +0 -3
  322. package/dist/noise-filter.d.ts +0 -18
  323. package/dist/notion-sync.d.ts +0 -7
  324. package/dist/notion-sync.js +0 -97
  325. package/dist/observability/adapters/a3-adapter.d.ts +0 -63
  326. package/dist/observability/adapters/a3-adapter.js +0 -83
  327. package/dist/observability/adapters/p1-adapter.d.ts +0 -49
  328. package/dist/observability/adapters/p1-adapter.js +0 -63
  329. package/dist/observability/adapters/p5-adapter.d.ts +0 -36
  330. package/dist/observability/adapters/p5-adapter.js +0 -71
  331. package/dist/observability/cardinality.d.ts +0 -61
  332. package/dist/observability/cardinality.js +0 -300
  333. package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
  334. package/dist/observability/collectors/db-stats.collector.js +0 -88
  335. package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
  336. package/dist/observability/collectors/eventbus.collector.js +0 -50
  337. package/dist/observability/collectors/process.collector.d.ts +0 -7
  338. package/dist/observability/collectors/process.collector.js +0 -93
  339. package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
  340. package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
  341. package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
  342. package/dist/observability/collectors/search-telemetry.collector.js +0 -76
  343. package/dist/observability/exporter.d.ts +0 -30
  344. package/dist/observability/exporter.js +0 -182
  345. package/dist/observability/index.d.ts +0 -22
  346. package/dist/observability/index.js +0 -21
  347. package/dist/observability/metrics.d.ts +0 -53
  348. package/dist/observability/metrics.js +0 -213
  349. package/dist/observability/privacy-guard.d.ts +0 -32
  350. package/dist/observability/privacy-guard.js +0 -116
  351. package/dist/observability/record.d.ts +0 -83
  352. package/dist/observability/record.js +0 -217
  353. package/dist/observability/registry.d.ts +0 -60
  354. package/dist/observability/registry.js +0 -93
  355. package/dist/observability/types.d.ts +0 -115
  356. package/dist/observability/types.js +0 -235
  357. package/dist/observability.d.ts +0 -131
  358. package/dist/plugins/nox-hooks/index.d.ts +0 -61
  359. package/dist/plugins/nox-hooks/index.js +0 -99
  360. package/dist/primer.d.ts +0 -1
  361. package/dist/privacy/filter.d.ts +0 -27
  362. package/dist/privacy/patterns.d.ts +0 -29
  363. package/dist/privacy/tag-parser.d.ts +0 -24
  364. package/dist/project-context-gen.d.ts +0 -10
  365. package/dist/providers/embedding/gemini.d.ts +0 -73
  366. package/dist/providers/embedding/openai.d.ts +0 -76
  367. package/dist/providers/embedding/types.d.ts +0 -39
  368. package/dist/providers/embedding/voyage.d.ts +0 -36
  369. package/dist/providers/index.d.ts +0 -116
  370. package/dist/providers/llm/anthropic.d.ts +0 -29
  371. package/dist/providers/llm/chain.d.ts +0 -99
  372. package/dist/providers/llm/gemini.d.ts +0 -48
  373. package/dist/providers/llm/openai.d.ts +0 -64
  374. package/dist/providers/llm/types.d.ts +0 -47
  375. package/dist/providers/telemetry.d.ts +0 -87
  376. package/dist/providers/types.d.ts +0 -42
  377. package/dist/query-entity-count.d.ts +0 -54
  378. package/dist/reflect.d.ts +0 -26
  379. package/dist/reindex-errors.d.ts +0 -7
  380. package/dist/reindex.d.ts +0 -16
  381. package/dist/retention.d.ts +0 -40
  382. package/dist/salience.d.ts +0 -85
  383. package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
  384. package/dist/search-dedup.d.ts +0 -44
  385. package/dist/search-expansion.d.ts +0 -20
  386. package/dist/search.d.ts +0 -62
  387. package/dist/seh-detector.d.ts +0 -31
  388. package/dist/self-improve.d.ts +0 -1
  389. package/dist/session-distill.d.ts +0 -29
  390. package/dist/session-update.d.ts +0 -1
  391. package/dist/shared-memory.d.ts +0 -24
  392. package/dist/stats.d.ts +0 -1
  393. package/dist/temporal-retrieval.d.ts +0 -132
  394. package/dist/tier-manager.d.ts +0 -69
  395. package/dist/vectorize.d.ts +0 -16
  396. package/dist/version.d.ts +0 -1
  397. package/dist/watch.d.ts +0 -8
@@ -1,81 +0,0 @@
1
- /**
2
- * T7+T8 — Encryption wrapper.
3
- *
4
- * Algorithm stack (D41 #2, locked):
5
- * - Cipher: AES-256-GCM (Node native crypto)
6
- * - KDF: scrypt N=2^17 (131072), r=8, p=1 → 32-byte key
7
- * - Nonce: random 12 bytes per file (GCM standard, NEVER reused with same key)
8
- * - AAD: sha256(manifest_pre_encryption_bytes) — manifest tampering breaks tag
9
- * - Salt: random 16 bytes per archive (shared across files; SAME key)
10
- *
11
- * Passphrase input:
12
- * 1. NOX_EXPORT_PASSPHRASE env var (preferred for automation)
13
- * 2. Interactive stdin prompt with echo OFF (TTY only)
14
- *
15
- * NEVER from argv. CLI layer rejects `--passphrase=` at parse time. This module
16
- * defensively errors out if the caller tries to pass a non-string passphrase.
17
- *
18
- * CRITICAL design decisions:
19
- * - Per-file nonces — same archive can have 6+ encrypted files, each needs
20
- * unique nonce to be safe with the shared key.
21
- * - AAD = sha256 of canonical manifest WITHOUT per-file encryption metadata
22
- * (see manifest.ts `manifestAADSource`) — chicken-and-egg avoided.
23
- * - We distinguish "bad passphrase" vs "tampered" by re-deriving the key
24
- * from passphrase + salt; if the very first file decrypts ok and a later
25
- * one fails GCM, it's tamper. If the FIRST fails, we assume bad passphrase
26
- * (more user-friendly), then expose explicit `decryptStrict` for callers
27
- * that want certainty.
28
- */
29
- import { EncryptionMetadata } from "./types.js";
30
- export declare const SCRYPT_N = 131072;
31
- export declare const SCRYPT_R = 8;
32
- export declare const SCRYPT_P = 1;
33
- export declare const KEY_LEN = 32;
34
- export declare const SALT_LEN = 16;
35
- export declare const NONCE_LEN = 12;
36
- export declare const TAG_LEN = 16;
37
- /** Memory-hard scrypt key derivation. ~0.5-1s on a modern laptop. */
38
- export declare function deriveKey(passphrase: string, salt: Buffer): Buffer;
39
- export interface EncryptResult {
40
- ciphertext: Buffer;
41
- nonce: Buffer;
42
- tag: Buffer;
43
- ciphertextSha256: string;
44
- }
45
- /** Encrypt one file blob with the derived key and per-file random nonce. */
46
- export declare function encryptBuffer(plaintext: Buffer, key: Buffer, aad: Buffer): EncryptResult;
47
- /** Decrypt one file blob. Throws TamperedArchiveError on tag mismatch. */
48
- export declare function decryptBuffer(ciphertext: Buffer, key: Buffer, nonce: Buffer, tag: Buffer, aad: Buffer): Buffer;
49
- /**
50
- * Verify a ciphertext sha256 matches the manifest-declared one before decrypt.
51
- * Returns true on match, false on mismatch (constant-time compare).
52
- */
53
- export declare function verifyCiphertextSha256(ciphertext: Buffer, expectedHex: string): boolean;
54
- /**
55
- * Top-level decrypt for a file given the manifest encryption metadata entry.
56
- * Encapsulates: salt parsing, key derivation, sha256 verification, GCM decrypt.
57
- *
58
- * Distinguishes "bad passphrase" vs "tamper" heuristically: if sha256 of
59
- * ciphertext matches manifest but GCM fails → likely bad passphrase. If sha256
60
- * already differs → tampered ciphertext.
61
- */
62
- export declare function decryptArchiveFile(opts: {
63
- ciphertext: Buffer;
64
- fileName: string;
65
- encryptionMetadata: EncryptionMetadata;
66
- passphrase: string;
67
- aad: Buffer;
68
- }): Buffer;
69
- /**
70
- * Get passphrase from env or interactive prompt. NEVER from argv.
71
- *
72
- * @param opts.interactivePrompt - injected for testability; defaults to readline echo-off
73
- * @param opts.envOverride - injected for testability; defaults to process.env
74
- */
75
- export declare function getPassphrase(opts?: {
76
- interactivePrompt?: () => Promise<string>;
77
- envOverride?: Record<string, string | undefined>;
78
- isTTY?: boolean;
79
- }): Promise<string>;
80
- /** Build the file-key portion of EncryptionMetadata given fresh salt + per-file results. */
81
- export declare function buildEncryptionMetadata(saltB64: string, files: Record<string, EncryptResult>): EncryptionMetadata;
@@ -1,236 +0,0 @@
1
- /**
2
- * T7+T8 — Encryption wrapper.
3
- *
4
- * Algorithm stack (D41 #2, locked):
5
- * - Cipher: AES-256-GCM (Node native crypto)
6
- * - KDF: scrypt N=2^17 (131072), r=8, p=1 → 32-byte key
7
- * - Nonce: random 12 bytes per file (GCM standard, NEVER reused with same key)
8
- * - AAD: sha256(manifest_pre_encryption_bytes) — manifest tampering breaks tag
9
- * - Salt: random 16 bytes per archive (shared across files; SAME key)
10
- *
11
- * Passphrase input:
12
- * 1. NOX_EXPORT_PASSPHRASE env var (preferred for automation)
13
- * 2. Interactive stdin prompt with echo OFF (TTY only)
14
- *
15
- * NEVER from argv. CLI layer rejects `--passphrase=` at parse time. This module
16
- * defensively errors out if the caller tries to pass a non-string passphrase.
17
- *
18
- * CRITICAL design decisions:
19
- * - Per-file nonces — same archive can have 6+ encrypted files, each needs
20
- * unique nonce to be safe with the shared key.
21
- * - AAD = sha256 of canonical manifest WITHOUT per-file encryption metadata
22
- * (see manifest.ts `manifestAADSource`) — chicken-and-egg avoided.
23
- * - We distinguish "bad passphrase" vs "tampered" by re-deriving the key
24
- * from passphrase + salt; if the very first file decrypts ok and a later
25
- * one fails GCM, it's tamper. If the FIRST fails, we assume bad passphrase
26
- * (more user-friendly), then expose explicit `decryptStrict` for callers
27
- * that want certainty.
28
- */
29
- import { createCipheriv, createDecipheriv, createHash, randomBytes, scryptSync, timingSafeEqual, } from "node:crypto";
30
- import { BadPassphraseError, ENCRYPTION_FORMAT_VERSION, MissingAADError, TamperedArchiveError, } from "./types.js";
31
- export const SCRYPT_N = 131072; // 2^17
32
- export const SCRYPT_R = 8;
33
- export const SCRYPT_P = 1;
34
- export const KEY_LEN = 32;
35
- export const SALT_LEN = 16;
36
- export const NONCE_LEN = 12;
37
- export const TAG_LEN = 16;
38
- /** Memory-hard scrypt key derivation. ~0.5-1s on a modern laptop. */
39
- export function deriveKey(passphrase, salt) {
40
- if (typeof passphrase !== "string") {
41
- throw new Error("deriveKey: passphrase must be a string");
42
- }
43
- if (passphrase.length === 0) {
44
- throw new Error("deriveKey: empty passphrase rejected");
45
- }
46
- if (salt.length !== SALT_LEN) {
47
- throw new Error(`deriveKey: salt must be ${SALT_LEN} bytes, got ${salt.length}`);
48
- }
49
- return scryptSync(Buffer.from(passphrase, "utf8"), salt, KEY_LEN, {
50
- N: SCRYPT_N,
51
- r: SCRYPT_R,
52
- p: SCRYPT_P,
53
- // Node defaults maxmem too low for N=2^17; bump.
54
- maxmem: 256 * 1024 * 1024,
55
- });
56
- }
57
- /** Encrypt one file blob with the derived key and per-file random nonce. */
58
- export function encryptBuffer(plaintext, key, aad) {
59
- if (key.length !== KEY_LEN) {
60
- throw new Error(`encryptBuffer: key must be ${KEY_LEN} bytes`);
61
- }
62
- if (aad.length === 0) {
63
- throw new MissingAADError();
64
- }
65
- const nonce = randomBytes(NONCE_LEN);
66
- const cipher = createCipheriv("aes-256-gcm", key, nonce);
67
- cipher.setAAD(aad);
68
- const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
69
- const tag = cipher.getAuthTag();
70
- const ciphertextSha256 = createHash("sha256").update(ciphertext).digest("hex");
71
- return { ciphertext, nonce, tag, ciphertextSha256 };
72
- }
73
- /** Decrypt one file blob. Throws TamperedArchiveError on tag mismatch. */
74
- export function decryptBuffer(ciphertext, key, nonce, tag, aad) {
75
- if (key.length !== KEY_LEN) {
76
- throw new Error(`decryptBuffer: key must be ${KEY_LEN} bytes`);
77
- }
78
- if (nonce.length !== NONCE_LEN) {
79
- throw new Error(`decryptBuffer: nonce must be ${NONCE_LEN} bytes`);
80
- }
81
- if (tag.length !== TAG_LEN) {
82
- throw new Error(`decryptBuffer: tag must be ${TAG_LEN} bytes`);
83
- }
84
- if (aad.length === 0) {
85
- throw new MissingAADError();
86
- }
87
- const decipher = createDecipheriv("aes-256-gcm", key, nonce);
88
- decipher.setAAD(aad);
89
- decipher.setAuthTag(tag);
90
- try {
91
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
92
- }
93
- catch (err) {
94
- // GCM auth failure manifests as a generic error; we map to TamperedArchiveError
95
- // and let the caller decide whether it's actually a bad passphrase.
96
- throw new TamperedArchiveError(`GCM auth failure: ${err.message}`);
97
- }
98
- }
99
- /**
100
- * Verify a ciphertext sha256 matches the manifest-declared one before decrypt.
101
- * Returns true on match, false on mismatch (constant-time compare).
102
- */
103
- export function verifyCiphertextSha256(ciphertext, expectedHex) {
104
- const got = createHash("sha256").update(ciphertext).digest();
105
- const want = Buffer.from(expectedHex, "hex");
106
- if (want.length !== got.length)
107
- return false;
108
- return timingSafeEqual(got, want);
109
- }
110
- /**
111
- * Top-level decrypt for a file given the manifest encryption metadata entry.
112
- * Encapsulates: salt parsing, key derivation, sha256 verification, GCM decrypt.
113
- *
114
- * Distinguishes "bad passphrase" vs "tamper" heuristically: if sha256 of
115
- * ciphertext matches manifest but GCM fails → likely bad passphrase. If sha256
116
- * already differs → tampered ciphertext.
117
- */
118
- export function decryptArchiveFile(opts) {
119
- const meta = opts.encryptionMetadata;
120
- if (!meta.enabled || meta.kdf_salt_b64 === null) {
121
- throw new Error(`decryptArchiveFile: encryption metadata disabled for ${opts.fileName}`);
122
- }
123
- const fileMeta = meta.files[opts.fileName];
124
- if (!fileMeta) {
125
- throw new Error(`decryptArchiveFile: no encryption metadata for ${opts.fileName}`);
126
- }
127
- // 1. Verify ciphertext checksum first — distinguishes tamper from bad pw.
128
- if (!verifyCiphertextSha256(opts.ciphertext, fileMeta.ciphertext_sha256)) {
129
- throw new TamperedArchiveError(`Ciphertext sha256 mismatch for ${opts.fileName}`);
130
- }
131
- const salt = Buffer.from(meta.kdf_salt_b64, "base64");
132
- const key = deriveKey(opts.passphrase, salt);
133
- const nonce = Buffer.from(fileMeta.nonce_b64, "base64");
134
- const tag = Buffer.from(fileMeta.tag_b64, "base64");
135
- try {
136
- return decryptBuffer(opts.ciphertext, key, nonce, tag, opts.aad);
137
- }
138
- catch (err) {
139
- // sha256 matched (no tamper) but GCM failed → bad passphrase OR bad AAD.
140
- if (err instanceof TamperedArchiveError) {
141
- throw new BadPassphraseError(`Decrypt failed for ${opts.fileName}; ciphertext integrity ok but GCM auth failed — likely wrong passphrase or manifest tampered.`);
142
- }
143
- throw err;
144
- }
145
- }
146
- /**
147
- * Get passphrase from env or interactive prompt. NEVER from argv.
148
- *
149
- * @param opts.interactivePrompt - injected for testability; defaults to readline echo-off
150
- * @param opts.envOverride - injected for testability; defaults to process.env
151
- */
152
- export async function getPassphrase(opts) {
153
- const env = opts?.envOverride ?? process.env;
154
- const fromEnv = env.NOX_EXPORT_PASSPHRASE;
155
- if (typeof fromEnv === "string" && fromEnv.length > 0) {
156
- return fromEnv;
157
- }
158
- const isTTY = opts?.isTTY ?? Boolean(process.stdin.isTTY);
159
- if (!isTTY) {
160
- throw new Error("getPassphrase: stdin is not a TTY and NOX_EXPORT_PASSPHRASE is unset. " +
161
- "Set NOX_EXPORT_PASSPHRASE or run interactively. " +
162
- "(Refuses to read passphrase from argv to prevent `ps` leaks.)");
163
- }
164
- const prompt = opts?.interactivePrompt ?? defaultInteractivePrompt;
165
- const pw = await prompt();
166
- if (pw.length === 0) {
167
- throw new Error("getPassphrase: empty passphrase rejected");
168
- }
169
- return pw;
170
- }
171
- /** Default interactive prompt — readline with echo OFF. */
172
- async function defaultInteractivePrompt() {
173
- const readline = await import("node:readline");
174
- const rl = readline.createInterface({
175
- input: process.stdin,
176
- output: process.stdout,
177
- terminal: true,
178
- });
179
- // Disable echo
180
- const stdin = process.stdin;
181
- const wasRaw = stdin.isRaw;
182
- stdin.setRawMode?.(true);
183
- return new Promise((resolve, reject) => {
184
- process.stdout.write("Passphrase: ");
185
- const chunks = [];
186
- const onData = (chunk) => {
187
- const s = chunk.toString("utf8");
188
- for (const ch of s) {
189
- if (ch === "\n" || ch === "\r") {
190
- stdin.setRawMode?.(wasRaw ?? false);
191
- stdin.off("data", onData);
192
- rl.close();
193
- process.stdout.write("\n");
194
- resolve(chunks.join(""));
195
- return;
196
- }
197
- if (ch === "") {
198
- // Ctrl-C
199
- stdin.setRawMode?.(wasRaw ?? false);
200
- stdin.off("data", onData);
201
- rl.close();
202
- reject(new Error("Passphrase prompt cancelled"));
203
- return;
204
- }
205
- if (ch === "" || ch === "\b") {
206
- if (chunks.length > 0)
207
- chunks.pop();
208
- continue;
209
- }
210
- chunks.push(ch);
211
- }
212
- };
213
- stdin.on("data", onData);
214
- });
215
- }
216
- /** Build the file-key portion of EncryptionMetadata given fresh salt + per-file results. */
217
- export function buildEncryptionMetadata(saltB64, files) {
218
- const filesMeta = {};
219
- for (const [name, res] of Object.entries(files)) {
220
- filesMeta[name] = {
221
- nonce_b64: res.nonce.toString("base64"),
222
- tag_b64: res.tag.toString("base64"),
223
- ciphertext_sha256: res.ciphertextSha256,
224
- };
225
- }
226
- return {
227
- enabled: true,
228
- algorithm: "AES-256-GCM",
229
- kdf: "scrypt",
230
- kdf_params: { N: SCRYPT_N, r: SCRYPT_R, p: SCRYPT_P },
231
- kdf_salt_b64: saltB64,
232
- files: filesMeta,
233
- aad_source: "sha256(manifest_pre_encryption_bytes)",
234
- format_version: ENCRYPTION_FORMAT_VERSION,
235
- };
236
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * A2.1 T3 — Enforce passphrase entropy.
3
- *
4
- * Default: throws `WeakPassphraseError` if entropy tier < `good` (≥50 bits).
5
- *
6
- * Override paths (require EXPLICIT consent):
7
- * - `opts.allow_weak: true` (caller-provided, programmatic)
8
- * - `NOX_A2_ALLOW_WEAK_PASSPHRASE=1` env var
9
- * - CLI `--allow-weak` flag (wired into export.ts)
10
- *
11
- * When the override is active we emit a single-line WARN to stderr (via the
12
- * injectable `log` sink) so operators in CI logs notice. Silent override is
13
- * never offered.
14
- *
15
- * Threat-model ref: docs/security/THREAT-MODEL.md §5.2 T-A2-1 / Gap G1.
16
- */
17
- import { PassphraseStrength, StrengthThresholds } from "./strength.js";
18
- export declare class WeakPassphraseError extends Error {
19
- readonly bits: number;
20
- readonly tier: PassphraseStrength;
21
- readonly required: PassphraseStrength;
22
- constructor(opts: {
23
- bits: number;
24
- tier: PassphraseStrength;
25
- required: PassphraseStrength;
26
- message?: string;
27
- });
28
- }
29
- export interface EnforcePassphraseOpts {
30
- /** Minimum strength tier required. Default: `good` (≥50 bits). */
31
- minStrength?: PassphraseStrength;
32
- /** Programmatic opt-out — caller has already shown the warning. */
33
- allow_weak?: boolean;
34
- /** Env source (defaults to process.env). */
35
- env?: Record<string, string | undefined>;
36
- /** Log sink for the WARN line. Defaults to console.error. */
37
- log?: (msg: string) => void;
38
- /** Custom thresholds (only for tests / advanced calibration). */
39
- thresholds?: StrengthThresholds;
40
- }
41
- export interface EnforceResult {
42
- bits: number;
43
- tier: PassphraseStrength;
44
- required: PassphraseStrength;
45
- bypassed: boolean;
46
- bypass_reason: "cli_flag" | "env_var" | null;
47
- }
48
- /**
49
- * Throws `WeakPassphraseError` if `passphrase` strength tier is below `minStrength`
50
- * AND no override is active. Returns the assessed strength on success or bypass.
51
- *
52
- * NEVER logs the passphrase — only the tier + bit count.
53
- */
54
- export declare function enforcePassphraseStrength(passphrase: string, opts?: EnforcePassphraseOpts): EnforceResult;
@@ -1,70 +0,0 @@
1
- /**
2
- * A2.1 T3 — Enforce passphrase entropy.
3
- *
4
- * Default: throws `WeakPassphraseError` if entropy tier < `good` (≥50 bits).
5
- *
6
- * Override paths (require EXPLICIT consent):
7
- * - `opts.allow_weak: true` (caller-provided, programmatic)
8
- * - `NOX_A2_ALLOW_WEAK_PASSPHRASE=1` env var
9
- * - CLI `--allow-weak` flag (wired into export.ts)
10
- *
11
- * When the override is active we emit a single-line WARN to stderr (via the
12
- * injectable `log` sink) so operators in CI logs notice. Silent override is
13
- * never offered.
14
- *
15
- * Threat-model ref: docs/security/THREAT-MODEL.md §5.2 T-A2-1 / Gap G1.
16
- */
17
- import { DEFAULT_MIN_STRENGTH, DEFAULT_THRESHOLDS, meetsMinimumStrength, strengthOfPassphrase, } from "./strength.js";
18
- export class WeakPassphraseError extends Error {
19
- bits;
20
- tier;
21
- required;
22
- constructor(opts) {
23
- const base = opts.message ??
24
- `Passphrase too weak: ${opts.tier} (~${opts.bits.toFixed(0)} bits). Minimum required: ${opts.required}. ` +
25
- `Pass --allow-weak or NOX_A2_ALLOW_WEAK_PASSPHRASE=1 to override (NOT recommended).`;
26
- super(base);
27
- this.name = "WeakPassphraseError";
28
- this.bits = opts.bits;
29
- this.tier = opts.tier;
30
- this.required = opts.required;
31
- }
32
- }
33
- /**
34
- * Throws `WeakPassphraseError` if `passphrase` strength tier is below `minStrength`
35
- * AND no override is active. Returns the assessed strength on success or bypass.
36
- *
37
- * NEVER logs the passphrase — only the tier + bit count.
38
- */
39
- export function enforcePassphraseStrength(passphrase, opts = {}) {
40
- if (typeof passphrase !== "string" || passphrase.length === 0) {
41
- throw new WeakPassphraseError({
42
- bits: 0,
43
- tier: "weak",
44
- required: opts.minStrength ?? DEFAULT_MIN_STRENGTH,
45
- message: "Passphrase is empty.",
46
- });
47
- }
48
- const required = opts.minStrength ?? DEFAULT_MIN_STRENGTH;
49
- const thresholds = opts.thresholds ?? DEFAULT_THRESHOLDS;
50
- const { bits, tier } = strengthOfPassphrase(passphrase, thresholds);
51
- if (meetsMinimumStrength(tier, required)) {
52
- return { bits, tier, required, bypassed: false, bypass_reason: null };
53
- }
54
- const env = opts.env ?? process.env;
55
- const envOverride = env.NOX_A2_ALLOW_WEAK_PASSPHRASE === "1";
56
- const log = opts.log ?? ((m) => process.stderr.write(m + "\n"));
57
- if (opts.allow_weak === true) {
58
- log(`WARN: weak passphrase accepted via --allow-weak (tier=${tier}, ` +
59
- `~${bits.toFixed(0)} bits). Required=${required}. ` +
60
- `THIS IS NOT RECOMMENDED FOR PRODUCTION ARCHIVES.`);
61
- return { bits, tier, required, bypassed: true, bypass_reason: "cli_flag" };
62
- }
63
- if (envOverride) {
64
- log(`WARN: weak passphrase accepted via NOX_A2_ALLOW_WEAK_PASSPHRASE=1 ` +
65
- `(tier=${tier}, ~${bits.toFixed(0)} bits). Required=${required}. ` +
66
- `THIS IS NOT RECOMMENDED FOR PRODUCTION ARCHIVES.`);
67
- return { bits, tier, required, bypassed: true, bypass_reason: "env_var" };
68
- }
69
- throw new WeakPassphraseError({ bits, tier, required });
70
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * A2.1 T1 — Lightweight entropy estimator (zxcvbn-inspired, zero-dep).
3
- *
4
- * Real zxcvbn(-ts) is the gold standard but adds ~700 KB and a transitive dep.
5
- * For A2.1 we use a deterministic, fully-local heuristic:
6
- *
7
- * 1) Build the effective character set: pools enabled if at least one char
8
- * present (lowercase 26, uppercase 26, digits 10, symbols 32, unicode
9
- * "other" 256 per non-ASCII char observed up to a cap).
10
- * 2) Raw entropy = length × log2(poolSize).
11
- * 3) Penalties:
12
- * - exact match in COMMON_PASSWORDS → cap to 10 bits regardless.
13
- * - substring match in COMMON_PASSWORDS (length ≥4) → −25 bits.
14
- * - >60% repeated chars → −15 bits.
15
- * - sequential runs of ≥4 ("1234", "abcd", "qwer") → −10 bits per run.
16
- * - keyboard rows ("qwerty", "asdf", "zxcv") of length ≥4 → −10 bits.
17
- * - only digits, length ≤8 → cap to log2(10) × length (no bonus).
18
- * 4) Bonus:
19
- * - length ≥20 → +5 bits (proxy for diceware-style passphrases).
20
- * - length ≥30 → +10 bits.
21
- *
22
- * NOT a security oracle. It's a conservative estimator: when uncertain it
23
- * UNDER-estimates so that enforcement defaults to safer rejections.
24
- *
25
- * Threat-model ref: docs/security/THREAT-MODEL.md §5.2 T-A2-1 / Gap G1.
26
- */
27
- /**
28
- * Estimate entropy bits for `passphrase`. Returns a non-negative number;
29
- * 0 indicates "essentially predictable".
30
- *
31
- * For tests + UX you usually want `strengthFromBits()` (see strength.ts)
32
- * rather than the raw number.
33
- */
34
- export declare function estimateEntropyBits(passphrase: string): number;
@@ -1,180 +0,0 @@
1
- /**
2
- * A2.1 T1 — Lightweight entropy estimator (zxcvbn-inspired, zero-dep).
3
- *
4
- * Real zxcvbn(-ts) is the gold standard but adds ~700 KB and a transitive dep.
5
- * For A2.1 we use a deterministic, fully-local heuristic:
6
- *
7
- * 1) Build the effective character set: pools enabled if at least one char
8
- * present (lowercase 26, uppercase 26, digits 10, symbols 32, unicode
9
- * "other" 256 per non-ASCII char observed up to a cap).
10
- * 2) Raw entropy = length × log2(poolSize).
11
- * 3) Penalties:
12
- * - exact match in COMMON_PASSWORDS → cap to 10 bits regardless.
13
- * - substring match in COMMON_PASSWORDS (length ≥4) → −25 bits.
14
- * - >60% repeated chars → −15 bits.
15
- * - sequential runs of ≥4 ("1234", "abcd", "qwer") → −10 bits per run.
16
- * - keyboard rows ("qwerty", "asdf", "zxcv") of length ≥4 → −10 bits.
17
- * - only digits, length ≤8 → cap to log2(10) × length (no bonus).
18
- * 4) Bonus:
19
- * - length ≥20 → +5 bits (proxy for diceware-style passphrases).
20
- * - length ≥30 → +10 bits.
21
- *
22
- * NOT a security oracle. It's a conservative estimator: when uncertain it
23
- * UNDER-estimates so that enforcement defaults to safer rejections.
24
- *
25
- * Threat-model ref: docs/security/THREAT-MODEL.md §5.2 T-A2-1 / Gap G1.
26
- */
27
- import { containsCommonSubstring, isCommonPassword, } from "./common-passwords.js";
28
- // — Pool sizes (rough char-class counts) —
29
- const POOL_LOWER = 26;
30
- const POOL_UPPER = 26;
31
- const POOL_DIGIT = 10;
32
- // Printable ASCII symbols excluding space (~32 printable special chars).
33
- const POOL_SYMBOL = 32;
34
- // For each unique non-ASCII char we add 256 — this caps at 4096 (16 chars).
35
- const POOL_NON_ASCII_PER_CHAR = 256;
36
- const NON_ASCII_CAP = 16;
37
- const HAS_LOWER = /[a-z]/;
38
- const HAS_UPPER = /[A-Z]/;
39
- const HAS_DIGIT = /[0-9]/;
40
- const HAS_SYMBOL = /[!-/:-@[-`{-~]/; // printable ASCII non-alphanumerics
41
- const NON_ASCII = /[^\x00-\x7f]/;
42
- /** Common keyboard "row" sequences that should not contribute to entropy. */
43
- const KEYBOARD_ROWS = [
44
- "qwertyuiop",
45
- "asdfghjkl",
46
- "zxcvbnm",
47
- "1234567890",
48
- "0987654321",
49
- "qwerty",
50
- "asdfgh",
51
- "zxcvbn",
52
- "azerty",
53
- "qazwsx",
54
- ];
55
- /** Alphabet/sequence runs used to detect ascending/descending tracks. */
56
- const SEQUENCE_RUNS = [
57
- "abcdefghijklmnopqrstuvwxyz",
58
- "zyxwvutsrqponmlkjihgfedcba",
59
- "0123456789",
60
- "9876543210",
61
- ];
62
- /**
63
- * Estimate entropy bits for `passphrase`. Returns a non-negative number;
64
- * 0 indicates "essentially predictable".
65
- *
66
- * For tests + UX you usually want `strengthFromBits()` (see strength.ts)
67
- * rather than the raw number.
68
- */
69
- export function estimateEntropyBits(passphrase) {
70
- if (typeof passphrase !== "string")
71
- return 0;
72
- if (passphrase.length === 0)
73
- return 0;
74
- // Exact-match shortcut.
75
- const lower = passphrase.toLowerCase();
76
- if (isCommonPassword(lower)) {
77
- // Cap at 10 bits regardless. A long well-known password is still well-known.
78
- return Math.min(10, passphrase.length);
79
- }
80
- // — Build pool —
81
- let pool = 0;
82
- if (HAS_LOWER.test(passphrase))
83
- pool += POOL_LOWER;
84
- if (HAS_UPPER.test(passphrase))
85
- pool += POOL_UPPER;
86
- if (HAS_DIGIT.test(passphrase))
87
- pool += POOL_DIGIT;
88
- if (HAS_SYMBOL.test(passphrase))
89
- pool += POOL_SYMBOL;
90
- if (NON_ASCII.test(passphrase)) {
91
- const uniqNonAscii = new Set(Array.from(passphrase).filter((c) => NON_ASCII.test(c)));
92
- const n = Math.min(NON_ASCII_CAP, uniqNonAscii.size);
93
- pool += n * POOL_NON_ASCII_PER_CHAR;
94
- }
95
- if (pool === 0)
96
- return 0;
97
- // Code-point length (correct handling of surrogate pairs, emoji, etc).
98
- const cpLength = Array.from(passphrase).length;
99
- let bits = cpLength * Math.log2(pool);
100
- // — Penalties —
101
- if (containsCommonSubstring(lower)) {
102
- bits -= 25;
103
- }
104
- const repeatPenalty = repeatedCharPenalty(passphrase);
105
- bits -= repeatPenalty;
106
- const seqPenalty = sequenceRunPenalty(lower);
107
- bits -= seqPenalty;
108
- const kbPenalty = keyboardRowPenalty(lower);
109
- bits -= kbPenalty;
110
- // Digit-only cap: short PINs should never be considered strong.
111
- if (/^[0-9]+$/.test(passphrase) && passphrase.length <= 8) {
112
- bits = Math.min(bits, Math.log2(POOL_DIGIT) * passphrase.length);
113
- }
114
- // — Length bonus —
115
- if (cpLength >= 20)
116
- bits += 5;
117
- if (cpLength >= 30)
118
- bits += 10;
119
- return Math.max(0, bits);
120
- }
121
- /**
122
- * Penalty for repeated characters. Returns bits to subtract.
123
- * Highest single-char fraction; if >60% of the string is one char, penalise.
124
- */
125
- function repeatedCharPenalty(s) {
126
- if (s.length === 0)
127
- return 0;
128
- const counts = new Map();
129
- for (const ch of s) {
130
- counts.set(ch, (counts.get(ch) ?? 0) + 1);
131
- }
132
- let maxCount = 0;
133
- for (const c of counts.values()) {
134
- if (c > maxCount)
135
- maxCount = c;
136
- }
137
- const frac = maxCount / s.length;
138
- if (frac > 0.6)
139
- return 15;
140
- if (frac > 0.4)
141
- return 5;
142
- return 0;
143
- }
144
- /**
145
- * Penalty for ascending/descending sequence runs of length ≥4.
146
- * Each such run subtracts 10 bits.
147
- */
148
- function sequenceRunPenalty(lower) {
149
- let bits = 0;
150
- for (const run of SEQUENCE_RUNS) {
151
- for (let i = 0; i + 4 <= lower.length; i++) {
152
- const window = lower.slice(i, i + 4);
153
- if (run.includes(window)) {
154
- bits += 10;
155
- break; // count this run once
156
- }
157
- }
158
- }
159
- return bits;
160
- }
161
- /**
162
- * Penalty for keyboard-row substrings (≥4 chars).
163
- * Each distinct keyboard run subtracts 10 bits.
164
- */
165
- function keyboardRowPenalty(lower) {
166
- let bits = 0;
167
- for (const row of KEYBOARD_ROWS) {
168
- if (row.length < 4)
169
- continue;
170
- // Check any 4-char window of `row` appearing in `lower`.
171
- for (let i = 0; i + 4 <= row.length; i++) {
172
- if (lower.includes(row.slice(i, i + 4))) {
173
- bits += 10;
174
- break;
175
- }
176
- }
177
- }
178
- // Cap penalty so we don't go absurdly negative for "qwerty1234".
179
- return Math.min(30, bits);
180
- }