@astragenie/astramemory-local 0.7.2

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 (493) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/README.md +419 -0
  3. package/dist/backup/retention.d.ts +15 -0
  4. package/dist/backup/retention.js +62 -0
  5. package/dist/backup/retention.js.map +1 -0
  6. package/dist/backup/snapshot.d.ts +21 -0
  7. package/dist/backup/snapshot.js +55 -0
  8. package/dist/backup/snapshot.js.map +1 -0
  9. package/dist/backup/verify.d.ts +23 -0
  10. package/dist/backup/verify.js +77 -0
  11. package/dist/backup/verify.js.map +1 -0
  12. package/dist/budget/tracker.d.ts +58 -0
  13. package/dist/budget/tracker.js +102 -0
  14. package/dist/budget/tracker.js.map +1 -0
  15. package/dist/capture/codex.d.ts +63 -0
  16. package/dist/capture/codex.js +0 -0
  17. package/dist/capture/codex.js.map +1 -0
  18. package/dist/cli/backup.d.ts +1 -0
  19. package/dist/cli/backup.js +112 -0
  20. package/dist/cli/backup.js.map +1 -0
  21. package/dist/cli/budget.d.ts +7 -0
  22. package/dist/cli/budget.js +44 -0
  23. package/dist/cli/budget.js.map +1 -0
  24. package/dist/cli/capture.d.ts +10 -0
  25. package/dist/cli/capture.js +113 -0
  26. package/dist/cli/capture.js.map +1 -0
  27. package/dist/cli/consolidate.d.ts +16 -0
  28. package/dist/cli/consolidate.js +146 -0
  29. package/dist/cli/consolidate.js.map +1 -0
  30. package/dist/cli/doctor.d.ts +1 -0
  31. package/dist/cli/doctor.js +54 -0
  32. package/dist/cli/doctor.js.map +1 -0
  33. package/dist/cli/entity-backfill.d.ts +10 -0
  34. package/dist/cli/entity-backfill.js +46 -0
  35. package/dist/cli/entity-backfill.js.map +1 -0
  36. package/dist/cli/hook-install.d.ts +45 -0
  37. package/dist/cli/hook-install.js +77 -0
  38. package/dist/cli/hook-install.js.map +1 -0
  39. package/dist/cli/index.d.ts +2 -0
  40. package/dist/cli/index.js +312 -0
  41. package/dist/cli/index.js.map +1 -0
  42. package/dist/cli/init.d.ts +16 -0
  43. package/dist/cli/init.js +431 -0
  44. package/dist/cli/init.js.map +1 -0
  45. package/dist/cli/mcp-stdio.d.ts +18 -0
  46. package/dist/cli/mcp-stdio.js +67 -0
  47. package/dist/cli/mcp-stdio.js.map +1 -0
  48. package/dist/cli/memory.d.ts +15 -0
  49. package/dist/cli/memory.js +52 -0
  50. package/dist/cli/memory.js.map +1 -0
  51. package/dist/cli/open-runtime-db.d.ts +15 -0
  52. package/dist/cli/open-runtime-db.js +37 -0
  53. package/dist/cli/open-runtime-db.js.map +1 -0
  54. package/dist/cli/pair.d.ts +29 -0
  55. package/dist/cli/pair.js +64 -0
  56. package/dist/cli/pair.js.map +1 -0
  57. package/dist/cli/providers.d.ts +10 -0
  58. package/dist/cli/providers.js +97 -0
  59. package/dist/cli/providers.js.map +1 -0
  60. package/dist/cli/queue-purge.d.ts +5 -0
  61. package/dist/cli/queue-purge.js +92 -0
  62. package/dist/cli/queue-purge.js.map +1 -0
  63. package/dist/cli/queue.d.ts +29 -0
  64. package/dist/cli/queue.js +73 -0
  65. package/dist/cli/queue.js.map +1 -0
  66. package/dist/cli/rebuild.d.ts +15 -0
  67. package/dist/cli/rebuild.js +70 -0
  68. package/dist/cli/rebuild.js.map +1 -0
  69. package/dist/cli/reembed-dim.d.ts +21 -0
  70. package/dist/cli/reembed-dim.js +199 -0
  71. package/dist/cli/reembed-dim.js.map +1 -0
  72. package/dist/cli/reinstall.d.ts +1 -0
  73. package/dist/cli/reinstall.js +205 -0
  74. package/dist/cli/reinstall.js.map +1 -0
  75. package/dist/cli/restore.d.ts +1 -0
  76. package/dist/cli/restore.js +167 -0
  77. package/dist/cli/restore.js.map +1 -0
  78. package/dist/cli/retag.d.ts +14 -0
  79. package/dist/cli/retag.js +62 -0
  80. package/dist/cli/retag.js.map +1 -0
  81. package/dist/cli/search.d.ts +66 -0
  82. package/dist/cli/search.js +174 -0
  83. package/dist/cli/search.js.map +1 -0
  84. package/dist/cli/serve.d.ts +9 -0
  85. package/dist/cli/serve.js +364 -0
  86. package/dist/cli/serve.js.map +1 -0
  87. package/dist/cli/service.d.ts +1 -0
  88. package/dist/cli/service.js +121 -0
  89. package/dist/cli/service.js.map +1 -0
  90. package/dist/cli/sync.d.ts +15 -0
  91. package/dist/cli/sync.js +61 -0
  92. package/dist/cli/sync.js.map +1 -0
  93. package/dist/cli/token.d.ts +24 -0
  94. package/dist/cli/token.js +77 -0
  95. package/dist/cli/token.js.map +1 -0
  96. package/dist/cli/wait-health.d.ts +4 -0
  97. package/dist/cli/wait-health.js +23 -0
  98. package/dist/cli/wait-health.js.map +1 -0
  99. package/dist/config/config.d.ts +127 -0
  100. package/dist/config/config.js +38 -0
  101. package/dist/config/config.js.map +1 -0
  102. package/dist/config/datadir.d.ts +30 -0
  103. package/dist/config/datadir.js +65 -0
  104. package/dist/config/datadir.js.map +1 -0
  105. package/dist/config/loader.d.ts +23 -0
  106. package/dist/config/loader.js +102 -0
  107. package/dist/config/loader.js.map +1 -0
  108. package/dist/config/migrate-dirs.d.ts +36 -0
  109. package/dist/config/migrate-dirs.js +132 -0
  110. package/dist/config/migrate-dirs.js.map +1 -0
  111. package/dist/config/persist-envs.d.ts +23 -0
  112. package/dist/config/persist-envs.js +119 -0
  113. package/dist/config/persist-envs.js.map +1 -0
  114. package/dist/config/resolve-runtime.d.ts +19 -0
  115. package/dist/config/resolve-runtime.js +53 -0
  116. package/dist/config/resolve-runtime.js.map +1 -0
  117. package/dist/config/secrets.d.ts +28 -0
  118. package/dist/config/secrets.js +38 -0
  119. package/dist/config/secrets.js.map +1 -0
  120. package/dist/config/sync-settings.d.ts +16 -0
  121. package/dist/config/sync-settings.js +34 -0
  122. package/dist/config/sync-settings.js.map +1 -0
  123. package/dist/config/writer.d.ts +19 -0
  124. package/dist/config/writer.js +121 -0
  125. package/dist/config/writer.js.map +1 -0
  126. package/dist/consolidate/consolidate.d.ts +80 -0
  127. package/dist/consolidate/consolidate.js +0 -0
  128. package/dist/consolidate/consolidate.js.map +1 -0
  129. package/dist/consolidate/proposals.d.ts +35 -0
  130. package/dist/consolidate/proposals.js +66 -0
  131. package/dist/consolidate/proposals.js.map +1 -0
  132. package/dist/contracts/atom-wire.d.ts +48 -0
  133. package/dist/contracts/atom-wire.js +55 -0
  134. package/dist/contracts/atom-wire.js.map +1 -0
  135. package/dist/contracts/embed.d.ts +41 -0
  136. package/dist/contracts/embed.js +20 -0
  137. package/dist/contracts/embed.js.map +1 -0
  138. package/dist/contracts/index.d.ts +5 -0
  139. package/dist/contracts/index.js +6 -0
  140. package/dist/contracts/index.js.map +1 -0
  141. package/dist/contracts/job.d.ts +113 -0
  142. package/dist/contracts/job.js +32 -0
  143. package/dist/contracts/job.js.map +1 -0
  144. package/dist/contracts/llm.d.ts +30 -0
  145. package/dist/contracts/llm.js +2 -0
  146. package/dist/contracts/llm.js.map +1 -0
  147. package/dist/contracts/memory.d.ts +47 -0
  148. package/dist/contracts/memory.js +5 -0
  149. package/dist/contracts/memory.js.map +1 -0
  150. package/dist/contracts/vector.d.ts +29 -0
  151. package/dist/contracts/vector.js +2 -0
  152. package/dist/contracts/vector.js.map +1 -0
  153. package/dist/distill/flatten-turns.d.ts +1 -0
  154. package/dist/distill/flatten-turns.js +50 -0
  155. package/dist/distill/flatten-turns.js.map +1 -0
  156. package/dist/distill/pipeline.d.ts +45 -0
  157. package/dist/distill/pipeline.js +113 -0
  158. package/dist/distill/pipeline.js.map +1 -0
  159. package/dist/distill/prompts/extract.d.ts +122 -0
  160. package/dist/distill/prompts/extract.js +67 -0
  161. package/dist/distill/prompts/extract.js.map +1 -0
  162. package/dist/distill/stages/01-cleanup.d.ts +9 -0
  163. package/dist/distill/stages/01-cleanup.js +67 -0
  164. package/dist/distill/stages/01-cleanup.js.map +1 -0
  165. package/dist/distill/stages/02-normalize.d.ts +9 -0
  166. package/dist/distill/stages/02-normalize.js +76 -0
  167. package/dist/distill/stages/02-normalize.js.map +1 -0
  168. package/dist/distill/stages/03-chunk.d.ts +22 -0
  169. package/dist/distill/stages/03-chunk.js +138 -0
  170. package/dist/distill/stages/03-chunk.js.map +1 -0
  171. package/dist/distill/stages/04-compact.d.ts +28 -0
  172. package/dist/distill/stages/04-compact.js +69 -0
  173. package/dist/distill/stages/04-compact.js.map +1 -0
  174. package/dist/distill/stages/05-extract.d.ts +35 -0
  175. package/dist/distill/stages/05-extract.js +101 -0
  176. package/dist/distill/stages/05-extract.js.map +1 -0
  177. package/dist/distill/stages/06-reduce.d.ts +16 -0
  178. package/dist/distill/stages/06-reduce.js +30 -0
  179. package/dist/distill/stages/06-reduce.js.map +1 -0
  180. package/dist/distill/stages/07-memory-normalize.d.ts +27 -0
  181. package/dist/distill/stages/07-memory-normalize.js +65 -0
  182. package/dist/distill/stages/07-memory-normalize.js.map +1 -0
  183. package/dist/distill/stages/08-embed-index.d.ts +31 -0
  184. package/dist/distill/stages/08-embed-index.js +82 -0
  185. package/dist/distill/stages/08-embed-index.js.map +1 -0
  186. package/dist/doctor/checks.d.ts +77 -0
  187. package/dist/doctor/checks.js +626 -0
  188. package/dist/doctor/checks.js.map +1 -0
  189. package/dist/doctor/hardening-checks.d.ts +9 -0
  190. package/dist/doctor/hardening-checks.js +182 -0
  191. package/dist/doctor/hardening-checks.js.map +1 -0
  192. package/dist/doctor/probes/embed-probe.d.ts +19 -0
  193. package/dist/doctor/probes/embed-probe.js +47 -0
  194. package/dist/doctor/probes/embed-probe.js.map +1 -0
  195. package/dist/doctor/probes/llm-chat-probe.d.ts +11 -0
  196. package/dist/doctor/probes/llm-chat-probe.js +41 -0
  197. package/dist/doctor/probes/llm-chat-probe.js.map +1 -0
  198. package/dist/doctor/probes/plugin-coexistence.d.ts +14 -0
  199. package/dist/doctor/probes/plugin-coexistence.js +60 -0
  200. package/dist/doctor/probes/plugin-coexistence.js.map +1 -0
  201. package/dist/doctor/runner.d.ts +17 -0
  202. package/dist/doctor/runner.js +53 -0
  203. package/dist/doctor/runner.js.map +1 -0
  204. package/dist/doctor/types.d.ts +12 -0
  205. package/dist/doctor/types.js +2 -0
  206. package/dist/doctor/types.js.map +1 -0
  207. package/dist/entity/backfill.d.ts +30 -0
  208. package/dist/entity/backfill.js +55 -0
  209. package/dist/entity/backfill.js.map +1 -0
  210. package/dist/entity/extract-entities.d.ts +27 -0
  211. package/dist/entity/extract-entities.js +86 -0
  212. package/dist/entity/extract-entities.js.map +1 -0
  213. package/dist/entity/normalize.d.ts +17 -0
  214. package/dist/entity/normalize.js +20 -0
  215. package/dist/entity/normalize.js.map +1 -0
  216. package/dist/eval/harness.d.ts +96 -0
  217. package/dist/eval/harness.js +119 -0
  218. package/dist/eval/harness.js.map +1 -0
  219. package/dist/eval/metrics.d.ts +23 -0
  220. package/dist/eval/metrics.js +44 -0
  221. package/dist/eval/metrics.js.map +1 -0
  222. package/dist/log/correlation.d.ts +24 -0
  223. package/dist/log/correlation.js +33 -0
  224. package/dist/log/correlation.js.map +1 -0
  225. package/dist/log/logger.d.ts +38 -0
  226. package/dist/log/logger.js +129 -0
  227. package/dist/log/logger.js.map +1 -0
  228. package/dist/log/scrub.d.ts +33 -0
  229. package/dist/log/scrub.js +91 -0
  230. package/dist/log/scrub.js.map +1 -0
  231. package/dist/mcp/server.d.ts +36 -0
  232. package/dist/mcp/server.js +553 -0
  233. package/dist/mcp/server.js.map +1 -0
  234. package/dist/memory-tool/adapter.d.ts +73 -0
  235. package/dist/memory-tool/adapter.js +269 -0
  236. package/dist/memory-tool/adapter.js.map +1 -0
  237. package/dist/pipeline/errors.d.ts +21 -0
  238. package/dist/pipeline/errors.js +34 -0
  239. package/dist/pipeline/errors.js.map +1 -0
  240. package/dist/pipeline/failure-classifier.d.ts +13 -0
  241. package/dist/pipeline/failure-classifier.js +72 -0
  242. package/dist/pipeline/failure-classifier.js.map +1 -0
  243. package/dist/pipeline/handler-ctx-ext.d.ts +23 -0
  244. package/dist/pipeline/handler-ctx-ext.js +19 -0
  245. package/dist/pipeline/handler-ctx-ext.js.map +1 -0
  246. package/dist/pipeline/handler.d.ts +20 -0
  247. package/dist/pipeline/handler.js +2 -0
  248. package/dist/pipeline/handler.js.map +1 -0
  249. package/dist/pipeline/handlers/cleanup.d.ts +14 -0
  250. package/dist/pipeline/handlers/cleanup.js +47 -0
  251. package/dist/pipeline/handlers/cleanup.js.map +1 -0
  252. package/dist/pipeline/handlers/consolidate.d.ts +8 -0
  253. package/dist/pipeline/handlers/consolidate.js +23 -0
  254. package/dist/pipeline/handlers/consolidate.js.map +1 -0
  255. package/dist/pipeline/handlers/distill-events.d.ts +15 -0
  256. package/dist/pipeline/handlers/distill-events.js +134 -0
  257. package/dist/pipeline/handlers/distill-events.js.map +1 -0
  258. package/dist/pipeline/handlers/distill.d.ts +17 -0
  259. package/dist/pipeline/handlers/distill.js +110 -0
  260. package/dist/pipeline/handlers/distill.js.map +1 -0
  261. package/dist/pipeline/handlers/reembed.d.ts +10 -0
  262. package/dist/pipeline/handlers/reembed.js +34 -0
  263. package/dist/pipeline/handlers/reembed.js.map +1 -0
  264. package/dist/pipeline/job-repo.d.ts +86 -0
  265. package/dist/pipeline/job-repo.js +168 -0
  266. package/dist/pipeline/job-repo.js.map +1 -0
  267. package/dist/pipeline/mock-providers.d.ts +49 -0
  268. package/dist/pipeline/mock-providers.js +175 -0
  269. package/dist/pipeline/mock-providers.js.map +1 -0
  270. package/dist/pipeline/registry.d.ts +15 -0
  271. package/dist/pipeline/registry.js +20 -0
  272. package/dist/pipeline/registry.js.map +1 -0
  273. package/dist/pipeline/worker.d.ts +41 -0
  274. package/dist/pipeline/worker.js +167 -0
  275. package/dist/pipeline/worker.js.map +1 -0
  276. package/dist/providers/embed/azure-openai.d.ts +25 -0
  277. package/dist/providers/embed/azure-openai.js +138 -0
  278. package/dist/providers/embed/azure-openai.js.map +1 -0
  279. package/dist/providers/embed/ollama.d.ts +17 -0
  280. package/dist/providers/embed/ollama.js +106 -0
  281. package/dist/providers/embed/ollama.js.map +1 -0
  282. package/dist/providers/index.d.ts +19 -0
  283. package/dist/providers/index.js +72 -0
  284. package/dist/providers/index.js.map +1 -0
  285. package/dist/providers/llm/azure-openai.d.ts +20 -0
  286. package/dist/providers/llm/azure-openai.js +135 -0
  287. package/dist/providers/llm/azure-openai.js.map +1 -0
  288. package/dist/providers/llm/ollama.d.ts +13 -0
  289. package/dist/providers/llm/ollama.js +113 -0
  290. package/dist/providers/llm/ollama.js.map +1 -0
  291. package/dist/providers/llm/pricing.d.ts +21 -0
  292. package/dist/providers/llm/pricing.js +22 -0
  293. package/dist/providers/llm/pricing.js.map +1 -0
  294. package/dist/recall/pack.d.ts +32 -0
  295. package/dist/recall/pack.js +90 -0
  296. package/dist/recall/pack.js.map +1 -0
  297. package/dist/recall/policy.d.ts +39 -0
  298. package/dist/recall/policy.js +96 -0
  299. package/dist/recall/policy.js.map +1 -0
  300. package/dist/redact/detectors.d.ts +20 -0
  301. package/dist/redact/detectors.js +85 -0
  302. package/dist/redact/detectors.js.map +1 -0
  303. package/dist/redact/entropy.d.ts +24 -0
  304. package/dist/redact/entropy.js +77 -0
  305. package/dist/redact/entropy.js.map +1 -0
  306. package/dist/redact/index.d.ts +47 -0
  307. package/dist/redact/index.js +165 -0
  308. package/dist/redact/index.js.map +1 -0
  309. package/dist/search/fuse.d.ts +108 -0
  310. package/dist/search/fuse.js +135 -0
  311. package/dist/search/fuse.js.map +1 -0
  312. package/dist/search/query.d.ts +28 -0
  313. package/dist/search/query.js +70 -0
  314. package/dist/search/query.js.map +1 -0
  315. package/dist/search/search.d.ts +164 -0
  316. package/dist/search/search.js +310 -0
  317. package/dist/search/search.js.map +1 -0
  318. package/dist/server/app.d.ts +17 -0
  319. package/dist/server/app.js +133 -0
  320. package/dist/server/app.js.map +1 -0
  321. package/dist/server/health-state.d.ts +29 -0
  322. package/dist/server/health-state.js +28 -0
  323. package/dist/server/health-state.js.map +1 -0
  324. package/dist/server/lib/network.d.ts +12 -0
  325. package/dist/server/lib/network.js +16 -0
  326. package/dist/server/lib/network.js.map +1 -0
  327. package/dist/server/lib/score-contract.d.ts +36 -0
  328. package/dist/server/lib/score-contract.js +54 -0
  329. package/dist/server/lib/score-contract.js.map +1 -0
  330. package/dist/server/lib/stable-stringify.d.ts +10 -0
  331. package/dist/server/lib/stable-stringify.js +27 -0
  332. package/dist/server/lib/stable-stringify.js.map +1 -0
  333. package/dist/server/lib/wire-meta.d.ts +7 -0
  334. package/dist/server/lib/wire-meta.js +29 -0
  335. package/dist/server/lib/wire-meta.js.map +1 -0
  336. package/dist/server/queries/dashboard.d.ts +142 -0
  337. package/dist/server/queries/dashboard.js +166 -0
  338. package/dist/server/queries/dashboard.js.map +1 -0
  339. package/dist/server/routes/consolidation.d.ts +14 -0
  340. package/dist/server/routes/consolidation.js +67 -0
  341. package/dist/server/routes/consolidation.js.map +1 -0
  342. package/dist/server/routes/dashboard-api-html.d.ts +15 -0
  343. package/dist/server/routes/dashboard-api-html.js +144 -0
  344. package/dist/server/routes/dashboard-api-html.js.map +1 -0
  345. package/dist/server/routes/dashboard-consolidation-html.d.ts +26 -0
  346. package/dist/server/routes/dashboard-consolidation-html.js +202 -0
  347. package/dist/server/routes/dashboard-consolidation-html.js.map +1 -0
  348. package/dist/server/routes/dashboard-html.d.ts +15 -0
  349. package/dist/server/routes/dashboard-html.js +365 -0
  350. package/dist/server/routes/dashboard-html.js.map +1 -0
  351. package/dist/server/routes/dashboard-jobs-html.d.ts +18 -0
  352. package/dist/server/routes/dashboard-jobs-html.js +186 -0
  353. package/dist/server/routes/dashboard-jobs-html.js.map +1 -0
  354. package/dist/server/routes/dashboard-search-html.d.ts +18 -0
  355. package/dist/server/routes/dashboard-search-html.js +189 -0
  356. package/dist/server/routes/dashboard-search-html.js.map +1 -0
  357. package/dist/server/routes/dashboard.d.ts +19 -0
  358. package/dist/server/routes/dashboard.js +68 -0
  359. package/dist/server/routes/dashboard.js.map +1 -0
  360. package/dist/server/routes/digest.d.ts +9 -0
  361. package/dist/server/routes/digest.js +37 -0
  362. package/dist/server/routes/digest.js.map +1 -0
  363. package/dist/server/routes/entities.d.ts +12 -0
  364. package/dist/server/routes/entities.js +46 -0
  365. package/dist/server/routes/entities.js.map +1 -0
  366. package/dist/server/routes/health.d.ts +14 -0
  367. package/dist/server/routes/health.js +100 -0
  368. package/dist/server/routes/health.js.map +1 -0
  369. package/dist/server/routes/ingest.d.ts +209 -0
  370. package/dist/server/routes/ingest.js +454 -0
  371. package/dist/server/routes/ingest.js.map +1 -0
  372. package/dist/server/routes/lifecycle.d.ts +21 -0
  373. package/dist/server/routes/lifecycle.js +132 -0
  374. package/dist/server/routes/lifecycle.js.map +1 -0
  375. package/dist/server/routes/mcp.d.ts +15 -0
  376. package/dist/server/routes/mcp.js +36 -0
  377. package/dist/server/routes/mcp.js.map +1 -0
  378. package/dist/server/routes/memory-tool.d.ts +14 -0
  379. package/dist/server/routes/memory-tool.js +28 -0
  380. package/dist/server/routes/memory-tool.js.map +1 -0
  381. package/dist/server/routes/memory.d.ts +7 -0
  382. package/dist/server/routes/memory.js +19 -0
  383. package/dist/server/routes/memory.js.map +1 -0
  384. package/dist/server/routes/recall.d.ts +15 -0
  385. package/dist/server/routes/recall.js +74 -0
  386. package/dist/server/routes/recall.js.map +1 -0
  387. package/dist/server/routes/search.d.ts +12 -0
  388. package/dist/server/routes/search.js +203 -0
  389. package/dist/server/routes/search.js.map +1 -0
  390. package/dist/server/routes/version.d.ts +2 -0
  391. package/dist/server/routes/version.js +11 -0
  392. package/dist/server/routes/version.js.map +1 -0
  393. package/dist/server/routes/why.d.ts +9 -0
  394. package/dist/server/routes/why.js +38 -0
  395. package/dist/server/routes/why.js.map +1 -0
  396. package/dist/service/index.d.ts +10 -0
  397. package/dist/service/index.js +25 -0
  398. package/dist/service/index.js.map +1 -0
  399. package/dist/service/install-flow.d.ts +18 -0
  400. package/dist/service/install-flow.js +47 -0
  401. package/dist/service/install-flow.js.map +1 -0
  402. package/dist/service/instance-lock.d.ts +26 -0
  403. package/dist/service/instance-lock.js +150 -0
  404. package/dist/service/instance-lock.js.map +1 -0
  405. package/dist/service/launchd.d.ts +11 -0
  406. package/dist/service/launchd.js +196 -0
  407. package/dist/service/launchd.js.map +1 -0
  408. package/dist/service/schtasks.d.ts +31 -0
  409. package/dist/service/schtasks.js +274 -0
  410. package/dist/service/schtasks.js.map +1 -0
  411. package/dist/service/shim.d.ts +21 -0
  412. package/dist/service/shim.js +80 -0
  413. package/dist/service/shim.js.map +1 -0
  414. package/dist/service/systemd.d.ts +11 -0
  415. package/dist/service/systemd.js +150 -0
  416. package/dist/service/systemd.js.map +1 -0
  417. package/dist/service/task-xml.d.ts +36 -0
  418. package/dist/service/task-xml.js +91 -0
  419. package/dist/service/task-xml.js.map +1 -0
  420. package/dist/service/types.d.ts +47 -0
  421. package/dist/service/types.js +2 -0
  422. package/dist/service/types.js.map +1 -0
  423. package/dist/storage/archival.d.ts +29 -0
  424. package/dist/storage/archival.js +47 -0
  425. package/dist/storage/archival.js.map +1 -0
  426. package/dist/storage/bearer-keystore.d.ts +34 -0
  427. package/dist/storage/bearer-keystore.js +75 -0
  428. package/dist/storage/bearer-keystore.js.map +1 -0
  429. package/dist/storage/db.d.ts +37 -0
  430. package/dist/storage/db.js +92 -0
  431. package/dist/storage/db.js.map +1 -0
  432. package/dist/storage/entities.d.ts +71 -0
  433. package/dist/storage/entities.js +141 -0
  434. package/dist/storage/entities.js.map +1 -0
  435. package/dist/storage/ingest-idempotency.d.ts +26 -0
  436. package/dist/storage/ingest-idempotency.js +29 -0
  437. package/dist/storage/ingest-idempotency.js.map +1 -0
  438. package/dist/storage/keystore.d.ts +64 -0
  439. package/dist/storage/keystore.js +194 -0
  440. package/dist/storage/keystore.js.map +1 -0
  441. package/dist/storage/memories.d.ts +51 -0
  442. package/dist/storage/memories.js +67 -0
  443. package/dist/storage/memories.js.map +1 -0
  444. package/dist/storage/memory-events.d.ts +145 -0
  445. package/dist/storage/memory-events.js +287 -0
  446. package/dist/storage/memory-events.js.map +1 -0
  447. package/dist/storage/migrate-encrypt.d.ts +16 -0
  448. package/dist/storage/migrate-encrypt.js +121 -0
  449. package/dist/storage/migrate-encrypt.js.map +1 -0
  450. package/dist/storage/migrate.d.ts +27 -0
  451. package/dist/storage/migrate.js +105 -0
  452. package/dist/storage/migrate.js.map +1 -0
  453. package/dist/storage/redaction-log.d.ts +18 -0
  454. package/dist/storage/redaction-log.js +27 -0
  455. package/dist/storage/redaction-log.js.map +1 -0
  456. package/dist/storage/usefulness.d.ts +115 -0
  457. package/dist/storage/usefulness.js +203 -0
  458. package/dist/storage/usefulness.js.map +1 -0
  459. package/dist/sync/conflict-resolve.d.ts +26 -0
  460. package/dist/sync/conflict-resolve.js +139 -0
  461. package/dist/sync/conflict-resolve.js.map +1 -0
  462. package/dist/sync/puller.d.ts +115 -0
  463. package/dist/sync/puller.js +173 -0
  464. package/dist/sync/puller.js.map +1 -0
  465. package/dist/sync/shipper.d.ts +112 -0
  466. package/dist/sync/shipper.js +189 -0
  467. package/dist/sync/shipper.js.map +1 -0
  468. package/dist/tag-hygiene/backfill.d.ts +50 -0
  469. package/dist/tag-hygiene/backfill.js +117 -0
  470. package/dist/tag-hygiene/backfill.js.map +1 -0
  471. package/dist/tag-hygiene/derive-repo.d.ts +9 -0
  472. package/dist/tag-hygiene/derive-repo.js +19 -0
  473. package/dist/tag-hygiene/derive-repo.js.map +1 -0
  474. package/dist/tag-hygiene/tier2-infer.d.ts +28 -0
  475. package/dist/tag-hygiene/tier2-infer.js +72 -0
  476. package/dist/tag-hygiene/tier2-infer.js.map +1 -0
  477. package/dist/vector/sqlite-vec.d.ts +16 -0
  478. package/dist/vector/sqlite-vec.js +49 -0
  479. package/dist/vector/sqlite-vec.js.map +1 -0
  480. package/migrations/001-init.sql +117 -0
  481. package/migrations/002-wire-v1.sql +16 -0
  482. package/migrations/003-expand-memory-types.sql +81 -0
  483. package/migrations/004-provenance.sql +4 -0
  484. package/migrations/005-security.sql +12 -0
  485. package/migrations/006-atom-v3.sql +28 -0
  486. package/migrations/007-memory-events.sql +30 -0
  487. package/migrations/008-consolidation.sql +31 -0
  488. package/migrations/009-tag-hygiene.sql +13 -0
  489. package/migrations/010-sync-pull.sql +53 -0
  490. package/migrations/011-embed-dim-migration.sql +28 -0
  491. package/migrations/012-entities.sql +36 -0
  492. package/migrations/013-archival.sql +50 -0
  493. package/package.json +50 -0
@@ -0,0 +1,5 @@
1
+ /** Single runtime source of truth for memory types — CLI validation and any
2
+ * future enum checks must use this array, not a hand-copied list (the CLI
3
+ * once drifted to a stale 5-type copy and silently rejected note/event). */
4
+ export const MEMORY_TYPES = ['decision', 'fact', 'lesson', 'command', 'todo', 'note', 'event'];
5
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/contracts/memory.ts"],"names":[],"mappings":"AAAA;;6EAE6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Filters applied to vector search. Implementations MUST throw if they cannot
3
+ * honor a non-empty filter — silent ignore is a contract violation.
4
+ */
5
+ export interface VecFilter {
6
+ type?: string[];
7
+ repo?: string;
8
+ project?: string;
9
+ since?: number;
10
+ }
11
+ export interface VecHit {
12
+ id: string;
13
+ score: number;
14
+ }
15
+ /**
16
+ * Vector store contract. v1 ships sqlite-vec only. LanceDB lands in a later
17
+ * wave behind the same interface; add 'lancedb' to the union when that
18
+ * implementation exists.
19
+ */
20
+ export interface VectorStore {
21
+ readonly name: 'sqlite-vec';
22
+ upsert(id: string, vec: Float32Array): Promise<void>;
23
+ search(vec: Float32Array, k: number, filter?: VecFilter): Promise<VecHit[]>;
24
+ /**
25
+ * Erase all stored vectors. Used as the wipe primitive ahead of a
26
+ * re-embed pass orchestrated by a Wave 3 worker. Does NOT repopulate.
27
+ */
28
+ clear(): Promise<void>;
29
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector.js","sourceRoot":"","sources":["../../src/contracts/vector.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function flattenTranscriptContent(content: string): string;
@@ -0,0 +1,50 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * D-DEF1 fix — turn-flattening defect.
4
+ *
5
+ * The canonical ingest envelope (server/routes/ingest.ts) stores turns as
6
+ * `JSON.stringify(turns)` in `transcripts.content` — a structured
7
+ * `[{role, text, ts}]` array. The distill pipeline's stages 1-3
8
+ * (cleanup/normalize/chunk) were built for plain text with `role: text`
9
+ * line-prefixed turn boundaries — the same convention the legacy envelope's
10
+ * raw `content` string already uses (see distill/stages/03-chunk.ts
11
+ * `TURN_BOUNDARY_RE`). `JSON.stringify` produces a single-line string (no
12
+ * embedded newlines), so when that raw JSON is fed through unchanged, stage
13
+ * 3's turn-boundary detector never fires: the whole transcript becomes one
14
+ * opaque "turn" that gets sliced blindly by character count, and role
15
+ * attribution is lost before stage 1 even runs (CHANGELOG 0.2.0 "Known
16
+ * issues" — D-DEF1: "fix is scoped to... flatten turns to `role: text\n`
17
+ * pairs before pipeline entry").
18
+ *
19
+ * This converts the canonical JSON-turns shape into `role: text` pairs (one
20
+ * per line) — the format the pipeline stages already parse. Legacy
21
+ * plain-text content (or any JSON that isn't a turns array) passes through
22
+ * unchanged.
23
+ */
24
+ const TurnLikeSchema = z.object({
25
+ role: z.string(),
26
+ text: z.string(),
27
+ });
28
+ export function flattenTranscriptContent(content) {
29
+ let parsed;
30
+ try {
31
+ parsed = JSON.parse(content);
32
+ }
33
+ catch {
34
+ return content; // legacy plain text — not JSON, pass through unchanged
35
+ }
36
+ if (!Array.isArray(parsed) || parsed.length === 0) {
37
+ return content;
38
+ }
39
+ const turns = [];
40
+ for (const item of parsed) {
41
+ const result = TurnLikeSchema.safeParse(item);
42
+ if (!result.success) {
43
+ // Not a turns array (some other JSON payload) — leave untouched.
44
+ return content;
45
+ }
46
+ turns.push(result.data);
47
+ }
48
+ return turns.map(t => `${t.role}: ${t.text}`).join('\n');
49
+ }
50
+ //# sourceMappingURL=flatten-turns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flatten-turns.js","sourceRoot":"","sources":["../../src/distill/flatten-turns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC,CAAC,uDAAuD;IACzE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,KAAK,GAA0C,EAAE,CAAC;IACxD,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,iEAAiE;YACjE,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 8-stage distillation pipeline.
3
+ *
4
+ * Stages:
5
+ * 1. cleanup — deterministic
6
+ * 2. normalize — deterministic
7
+ * 3. chunk — deterministic
8
+ * 4. compact — LLM call (budget-gated)
9
+ * 5. extract — LLM call, JSON-mode (budget-gated, Zod-validated, retry once)
10
+ * 6. reduce — deterministic
11
+ * 7. memory-normalize — deterministic
12
+ * 8. embed + index — provider call + DB writes
13
+ */
14
+ import type { LLMProvider, EmbedProvider } from '../contracts/index.js';
15
+ import type { DB } from '../storage/db.js';
16
+ export { BudgetExceeded } from '../budget/tracker.js';
17
+ export interface PipelineContext {
18
+ db: DB;
19
+ llmCompaction: LLMProvider;
20
+ llmExtraction: LLMProvider;
21
+ embed: EmbedProvider;
22
+ capUsd: number;
23
+ sessionId: string | null;
24
+ repo: string | null;
25
+ project: string | null;
26
+ branch: string | null;
27
+ agent: string | null;
28
+ sourceHash: string | null;
29
+ }
30
+ export interface PipelineResult {
31
+ memoriesCreated: number;
32
+ memoriesDeduped: number;
33
+ atomsExtracted: number;
34
+ chunksProcessed: number;
35
+ /** IDs of every memory this run touched (both newly-created and deduped-existing), in stage-8 order. */
36
+ memoryIds: string[];
37
+ }
38
+ /**
39
+ * Run the full 8-stage distillation pipeline on a raw transcript.
40
+ * Returns count of new memories created.
41
+ *
42
+ * Throws BudgetExceeded if the daily cap is hit during stages 4 or 5.
43
+ * The caller (distill handler) catches this and moves the job to paused.
44
+ */
45
+ export declare function runPipeline(transcript: string, ctx: PipelineContext): Promise<PipelineResult>;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * 8-stage distillation pipeline.
3
+ *
4
+ * Stages:
5
+ * 1. cleanup — deterministic
6
+ * 2. normalize — deterministic
7
+ * 3. chunk — deterministic
8
+ * 4. compact — LLM call (budget-gated)
9
+ * 5. extract — LLM call, JSON-mode (budget-gated, Zod-validated, retry once)
10
+ * 6. reduce — deterministic
11
+ * 7. memory-normalize — deterministic
12
+ * 8. embed + index — provider call + DB writes
13
+ */
14
+ import { cleanup } from './stages/01-cleanup.js';
15
+ import { normalize } from './stages/02-normalize.js';
16
+ import { chunk } from './stages/03-chunk.js';
17
+ import { compact, BudgetExceeded as CompactBudgetExceeded } from './stages/04-compact.js';
18
+ import { extract, BudgetExceeded as ExtractBudgetExceeded } from './stages/05-extract.js';
19
+ import { reduce } from './stages/06-reduce.js';
20
+ import { memoryNormalize } from './stages/07-memory-normalize.js';
21
+ import { embedAndIndex } from './stages/08-embed-index.js';
22
+ import { BudgetTracker } from '../budget/tracker.js';
23
+ import { childLogger } from '../log/logger.js';
24
+ export { BudgetExceeded } from '../budget/tracker.js';
25
+ /**
26
+ * Run the full 8-stage distillation pipeline on a raw transcript.
27
+ * Returns count of new memories created.
28
+ *
29
+ * Throws BudgetExceeded if the daily cap is hit during stages 4 or 5.
30
+ * The caller (distill handler) catches this and moves the job to paused.
31
+ */
32
+ export async function runPipeline(transcript, ctx) {
33
+ // Base logger for the pipeline run — inherits any job_id from caller context
34
+ const pipeLog = childLogger({ session_id: ctx.sessionId ?? undefined });
35
+ // Stage 1: Cleanup
36
+ pipeLog.info({ stage: 'cleanup' }, 'stage start');
37
+ const cleaned = cleanup(transcript);
38
+ pipeLog.info({ stage: 'cleanup' }, 'stage complete');
39
+ // Stage 2: Normalize
40
+ pipeLog.info({ stage: 'normalize' }, 'stage start');
41
+ const normalized = normalize(cleaned);
42
+ pipeLog.info({ stage: 'normalize' }, 'stage complete');
43
+ // Stage 3: Chunk
44
+ pipeLog.info({ stage: 'chunk' }, 'stage start');
45
+ const chunks = chunk(normalized);
46
+ pipeLog.info({ stage: 'chunk', chunk_count: chunks.length }, 'stage complete');
47
+ const budget = new BudgetTracker(ctx.db);
48
+ // Stage 4: Compact (LLM, budget-gated)
49
+ pipeLog.info({ stage: 'compact', chunk_count: chunks.length }, 'stage start');
50
+ let compactedChunks;
51
+ try {
52
+ const compactResults = await compact(chunks, ctx.llmCompaction, budget, ctx.capUsd);
53
+ compactedChunks = compactResults.map(r => ({ index: r.index, text: r.text || chunks[r.index]?.text || '' }));
54
+ pipeLog.info({ stage: 'compact', chunks_compacted: compactedChunks.length }, 'stage complete');
55
+ }
56
+ catch (err) {
57
+ if (err instanceof CompactBudgetExceeded) {
58
+ pipeLog.warn({ stage: 'compact', error_kind: 'BudgetExceeded' }, 'stage aborted — budget exceeded');
59
+ throw err;
60
+ }
61
+ pipeLog.warn({ stage: 'compact', error_message: (err instanceof Error ? err.message : String(err)).slice(0, 200), error_kind: err instanceof Error ? err.name : 'Unknown' }, 'stage failed');
62
+ throw err;
63
+ }
64
+ // Stage 5: Extract (LLM JSON-mode, budget-gated, retry on parse fail)
65
+ pipeLog.info({ stage: 'extract', chunk_count: compactedChunks.length }, 'stage start');
66
+ let extractResults;
67
+ try {
68
+ extractResults = await extract(compactedChunks, ctx.llmExtraction, budget, ctx.capUsd);
69
+ const atomsExtracted = extractResults.reduce((sum, r) => sum + r.atoms.length, 0);
70
+ pipeLog.info({ stage: 'extract', atoms_extracted: atomsExtracted }, 'stage complete');
71
+ }
72
+ catch (err) {
73
+ if (err instanceof ExtractBudgetExceeded) {
74
+ pipeLog.warn({ stage: 'extract', error_kind: 'BudgetExceeded' }, 'stage aborted — budget exceeded');
75
+ throw err;
76
+ }
77
+ pipeLog.warn({ stage: 'extract', error_message: (err instanceof Error ? err.message : String(err)).slice(0, 200), error_kind: err instanceof Error ? err.name : 'Unknown' }, 'stage failed');
78
+ throw err;
79
+ }
80
+ // Flatten all atoms
81
+ const allAtoms = extractResults.flatMap(r => r.atoms);
82
+ // Stage 6: Reduce (merge by content hash)
83
+ pipeLog.info({ stage: 'reduce', atoms_in: allAtoms.length }, 'stage start');
84
+ const reducedAtoms = reduce(allAtoms);
85
+ pipeLog.info({ stage: 'reduce', atoms_out: reducedAtoms.length }, 'stage complete');
86
+ // Stage 7: Memory-normalize
87
+ pipeLog.info({ stage: 'memory-normalize' }, 'stage start');
88
+ const normalizedMemories = memoryNormalize(reducedAtoms);
89
+ pipeLog.info({ stage: 'memory-normalize', memories: normalizedMemories.length }, 'stage complete');
90
+ // Stage 8: Embed + index
91
+ pipeLog.info({ stage: 'embed-index', memories: normalizedMemories.length }, 'stage start');
92
+ const indexResults = await embedAndIndex(normalizedMemories, {
93
+ db: ctx.db,
94
+ embed: ctx.embed,
95
+ sessionId: ctx.sessionId,
96
+ repo: ctx.repo,
97
+ project: ctx.project,
98
+ branch: ctx.branch,
99
+ agent: ctx.agent,
100
+ sourceHash: ctx.sourceHash,
101
+ });
102
+ const created = indexResults.filter(r => r.created).length;
103
+ const deduped = indexResults.filter(r => !r.created).length;
104
+ pipeLog.info({ stage: 'embed-index', memories_created: created, memories_deduped: deduped }, 'stage complete');
105
+ return {
106
+ memoriesCreated: created,
107
+ memoriesDeduped: deduped,
108
+ atomsExtracted: allAtoms.length,
109
+ chunksProcessed: chunks.length,
110
+ memoryIds: indexResults.map(r => r.memoryId),
111
+ };
112
+ }
113
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/distill/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAA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B,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC3D,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAE5D,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,EAAE,gBAAgB,CAAC,CAAC;IAE/G,OAAO;QACL,eAAe,EAAE,OAAO;QACxB,eAAe,EAAE,OAAO;QACxB,cAAc,EAAE,QAAQ,CAAC,MAAM;QAC/B,eAAe,EAAE,MAAM,CAAC,MAAM;QAC9B,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC7C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,122 @@
1
+ import { z } from 'zod';
2
+ export declare const EntityKindSchema: z.ZodEnum<["product", "tech", "person", "org", "repo", "concept"]>;
3
+ export type EntityKind = z.infer<typeof EntityKindSchema>;
4
+ export declare const AtomEntitySchema: z.ZodObject<{
5
+ name: z.ZodString;
6
+ kind: z.ZodEnum<["product", "tech", "person", "org", "repo", "concept"]>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
9
+ name: string;
10
+ }, {
11
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
12
+ name: string;
13
+ }>;
14
+ export type AtomEntity = z.infer<typeof AtomEntitySchema>;
15
+ export declare const AtomSchema: z.ZodObject<{
16
+ type: z.ZodEnum<["decision", "fact", "lesson", "command", "todo", "note", "event"]>;
17
+ text: z.ZodString;
18
+ importance: z.ZodNumber;
19
+ confidence: z.ZodNumber;
20
+ evidence: z.ZodOptional<z.ZodString>;
21
+ /** Named things mentioned in this atom (FEAT-402 AC-1). Optional — atoms
22
+ * with no clearly-named entity omit it entirely rather than guessing. */
23
+ entities: z.ZodOptional<z.ZodArray<z.ZodObject<{
24
+ name: z.ZodString;
25
+ kind: z.ZodEnum<["product", "tech", "person", "org", "repo", "concept"]>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
28
+ name: string;
29
+ }, {
30
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
31
+ name: string;
32
+ }>, "many">>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
35
+ text: string;
36
+ importance: number;
37
+ confidence: number;
38
+ evidence?: string | undefined;
39
+ entities?: {
40
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
41
+ name: string;
42
+ }[] | undefined;
43
+ }, {
44
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
45
+ text: string;
46
+ importance: number;
47
+ confidence: number;
48
+ evidence?: string | undefined;
49
+ entities?: {
50
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
51
+ name: string;
52
+ }[] | undefined;
53
+ }>;
54
+ export declare const ExtractionSchema: z.ZodObject<{
55
+ atoms: z.ZodArray<z.ZodObject<{
56
+ type: z.ZodEnum<["decision", "fact", "lesson", "command", "todo", "note", "event"]>;
57
+ text: z.ZodString;
58
+ importance: z.ZodNumber;
59
+ confidence: z.ZodNumber;
60
+ evidence: z.ZodOptional<z.ZodString>;
61
+ /** Named things mentioned in this atom (FEAT-402 AC-1). Optional — atoms
62
+ * with no clearly-named entity omit it entirely rather than guessing. */
63
+ entities: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
+ name: z.ZodString;
65
+ kind: z.ZodEnum<["product", "tech", "person", "org", "repo", "concept"]>;
66
+ }, "strip", z.ZodTypeAny, {
67
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
68
+ name: string;
69
+ }, {
70
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
71
+ name: string;
72
+ }>, "many">>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
75
+ text: string;
76
+ importance: number;
77
+ confidence: number;
78
+ evidence?: string | undefined;
79
+ entities?: {
80
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
81
+ name: string;
82
+ }[] | undefined;
83
+ }, {
84
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
85
+ text: string;
86
+ importance: number;
87
+ confidence: number;
88
+ evidence?: string | undefined;
89
+ entities?: {
90
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
91
+ name: string;
92
+ }[] | undefined;
93
+ }>, "many">;
94
+ }, "strip", z.ZodTypeAny, {
95
+ atoms: {
96
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
97
+ text: string;
98
+ importance: number;
99
+ confidence: number;
100
+ evidence?: string | undefined;
101
+ entities?: {
102
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
103
+ name: string;
104
+ }[] | undefined;
105
+ }[];
106
+ }, {
107
+ atoms: {
108
+ type: "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event";
109
+ text: string;
110
+ importance: number;
111
+ confidence: number;
112
+ evidence?: string | undefined;
113
+ entities?: {
114
+ kind: "org" | "product" | "tech" | "person" | "repo" | "concept";
115
+ name: string;
116
+ }[] | undefined;
117
+ }[];
118
+ }>;
119
+ export type Atom = z.infer<typeof AtomSchema>;
120
+ export type Extraction = z.infer<typeof ExtractionSchema>;
121
+ export declare const EXTRACTION_SYSTEM_PROMPT = "You extract durable knowledge from AI coding agent transcripts.\n\nOutput STRICT JSON matching:\n{\n \"atoms\": [\n {\n \"type\": \"decision\" | \"fact\" | \"lesson\" | \"command\" | \"todo\" | \"note\" | \"event\",\n \"text\": \"<5-500 chars, canonical phrasing>\",\n \"importance\": 0.0-1.0,\n \"confidence\": 0.0-1.0,\n \"evidence\": \"<optional, short excerpt from source>\",\n \"entities\": [{ \"name\": \"<named thing mentioned>\", \"kind\": \"product\" | \"tech\" | \"person\" | \"org\" | \"repo\" | \"concept\" }]\n }\n ]\n}\n\nTypes:\n- decision: chosen approach/architecture (use SQLite, not Postgres)\n- fact: discovered truth about the codebase/system (port 7777 is the default)\n- lesson: learning from failure or surprise (Bun does not support better-sqlite3 on Windows)\n- command: useful shell incantation (npm test -- --reporter=verbose)\n- todo: pending work item explicitly raised\n- note: freeform observation or annotation not fitting other types\n- event: something that happened at a point in time (deployment, incident, decision meeting)\n\nEntities: list every specific named thing the atom is ABOUT (not every word\nmentioned) \u2014 a technology, product, repo, person, or organization. kind is\none of:\n- product: a named product or app (e.g. \"AstraMemory\", \"GitHub Copilot\")\n- tech: a language/framework/library/tool/protocol (e.g. \"Postgres\", \"TypeScript\", \"sqlite-vec\")\n- person: a named individual\n- org: a company or organization\n- repo: a named git repository or codebase\n- concept: a named pattern, architecture, or idea (e.g. \"bitemporal model\", \"CRDT\")\nOmit \"entities\" entirely (or leave it empty) when the atom names nothing specific.\n\nSkip noise: greetings, repeated thinking, false starts, generic AI fluff.\nSkip secrets: tokens, API keys, passwords.\nConfidence reflects evidence strength: clear conclusion = 0.9; speculation = 0.3.\nImportance reflects long-term value: architecture decision = 0.9; one-off command = 0.4.";
122
+ export declare const EXTRACTION_STRICT_PROMPT = "You extract durable knowledge from AI coding agent transcripts.\n\nOutput STRICT JSON matching:\n{\n \"atoms\": [\n {\n \"type\": \"decision\" | \"fact\" | \"lesson\" | \"command\" | \"todo\" | \"note\" | \"event\",\n \"text\": \"<5-500 chars, canonical phrasing>\",\n \"importance\": 0.0-1.0,\n \"confidence\": 0.0-1.0,\n \"evidence\": \"<optional, short excerpt from source>\",\n \"entities\": [{ \"name\": \"<named thing mentioned>\", \"kind\": \"product\" | \"tech\" | \"person\" | \"org\" | \"repo\" | \"concept\" }]\n }\n ]\n}\n\nTypes:\n- decision: chosen approach/architecture (use SQLite, not Postgres)\n- fact: discovered truth about the codebase/system (port 7777 is the default)\n- lesson: learning from failure or surprise (Bun does not support better-sqlite3 on Windows)\n- command: useful shell incantation (npm test -- --reporter=verbose)\n- todo: pending work item explicitly raised\n- note: freeform observation or annotation not fitting other types\n- event: something that happened at a point in time (deployment, incident, decision meeting)\n\nEntities: list every specific named thing the atom is ABOUT (not every word\nmentioned) \u2014 a technology, product, repo, person, or organization. kind is\none of:\n- product: a named product or app (e.g. \"AstraMemory\", \"GitHub Copilot\")\n- tech: a language/framework/library/tool/protocol (e.g. \"Postgres\", \"TypeScript\", \"sqlite-vec\")\n- person: a named individual\n- org: a company or organization\n- repo: a named git repository or codebase\n- concept: a named pattern, architecture, or idea (e.g. \"bitemporal model\", \"CRDT\")\nOmit \"entities\" entirely (or leave it empty) when the atom names nothing specific.\n\nSkip noise: greetings, repeated thinking, false starts, generic AI fluff.\nSkip secrets: tokens, API keys, passwords.\nConfidence reflects evidence strength: clear conclusion = 0.9; speculation = 0.3.\nImportance reflects long-term value: architecture decision = 0.9; one-off command = 0.4.\n\nCRITICAL: Output ONLY valid JSON. No markdown, no prose, no code fences. The response must start with { and end with }.";
@@ -0,0 +1,67 @@
1
+ import { z } from 'zod';
2
+ // FEAT-402 (W4.2) AC-1/AC-9 — entity kinds emitted alongside each atom, in
3
+ // the SAME extraction LLM call (no extra call/budget spend). Names are
4
+ // normalized at write time via src/entity/normalize.ts, not here — this
5
+ // schema only validates shape.
6
+ export const EntityKindSchema = z.enum(['product', 'tech', 'person', 'org', 'repo', 'concept']);
7
+ export const AtomEntitySchema = z.object({
8
+ name: z.string().min(1).max(100),
9
+ kind: EntityKindSchema,
10
+ });
11
+ export const AtomSchema = z.object({
12
+ type: z.enum(['decision', 'fact', 'lesson', 'command', 'todo', 'note', 'event']),
13
+ text: z.string().min(5).max(500),
14
+ importance: z.number().min(0).max(1),
15
+ confidence: z.number().min(0).max(1),
16
+ evidence: z.string().optional(),
17
+ /** Named things mentioned in this atom (FEAT-402 AC-1). Optional — atoms
18
+ * with no clearly-named entity omit it entirely rather than guessing. */
19
+ entities: z.array(AtomEntitySchema).optional(),
20
+ });
21
+ export const ExtractionSchema = z.object({
22
+ atoms: z.array(AtomSchema)
23
+ });
24
+ export const EXTRACTION_SYSTEM_PROMPT = `You extract durable knowledge from AI coding agent transcripts.
25
+
26
+ Output STRICT JSON matching:
27
+ {
28
+ "atoms": [
29
+ {
30
+ "type": "decision" | "fact" | "lesson" | "command" | "todo" | "note" | "event",
31
+ "text": "<5-500 chars, canonical phrasing>",
32
+ "importance": 0.0-1.0,
33
+ "confidence": 0.0-1.0,
34
+ "evidence": "<optional, short excerpt from source>",
35
+ "entities": [{ "name": "<named thing mentioned>", "kind": "product" | "tech" | "person" | "org" | "repo" | "concept" }]
36
+ }
37
+ ]
38
+ }
39
+
40
+ Types:
41
+ - decision: chosen approach/architecture (use SQLite, not Postgres)
42
+ - fact: discovered truth about the codebase/system (port 7777 is the default)
43
+ - lesson: learning from failure or surprise (Bun does not support better-sqlite3 on Windows)
44
+ - command: useful shell incantation (npm test -- --reporter=verbose)
45
+ - todo: pending work item explicitly raised
46
+ - note: freeform observation or annotation not fitting other types
47
+ - event: something that happened at a point in time (deployment, incident, decision meeting)
48
+
49
+ Entities: list every specific named thing the atom is ABOUT (not every word
50
+ mentioned) — a technology, product, repo, person, or organization. kind is
51
+ one of:
52
+ - product: a named product or app (e.g. "AstraMemory", "GitHub Copilot")
53
+ - tech: a language/framework/library/tool/protocol (e.g. "Postgres", "TypeScript", "sqlite-vec")
54
+ - person: a named individual
55
+ - org: a company or organization
56
+ - repo: a named git repository or codebase
57
+ - concept: a named pattern, architecture, or idea (e.g. "bitemporal model", "CRDT")
58
+ Omit "entities" entirely (or leave it empty) when the atom names nothing specific.
59
+
60
+ Skip noise: greetings, repeated thinking, false starts, generic AI fluff.
61
+ Skip secrets: tokens, API keys, passwords.
62
+ Confidence reflects evidence strength: clear conclusion = 0.9; speculation = 0.3.
63
+ Importance reflects long-term value: architecture decision = 0.9; one-off command = 0.4.`;
64
+ export const EXTRACTION_STRICT_PROMPT = `${EXTRACTION_SYSTEM_PROMPT}
65
+
66
+ CRITICAL: Output ONLY valid JSON. No markdown, no prose, no code fences. The response must start with { and end with }.`;
67
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../src/distill/prompts/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2EAA2E;AAC3E,uEAAuE;AACvE,wEAAwE;AACxE,+BAA+B;AAC/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAGhG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,IAAI,EAAE,gBAAgB;CACvB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B;6EACyE;IACzE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;CAC/C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;CAC3B,CAAC,CAAC;AAKH,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yFAuCiD,CAAC;AAE1F,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,wBAAwB;;wHAEqD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Stage 1 — Cleanup (deterministic)
3
+ *
4
+ * - Normalize line endings to \n
5
+ * - Deduplicate consecutive blank lines (max 2)
6
+ * - Remove repeated tool-output blocks (identical lines appearing 3+ times consecutively)
7
+ * - Strip trailing whitespace per line
8
+ */
9
+ export declare function cleanup(text: string): string;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Stage 1 — Cleanup (deterministic)
3
+ *
4
+ * - Normalize line endings to \n
5
+ * - Deduplicate consecutive blank lines (max 2)
6
+ * - Remove repeated tool-output blocks (identical lines appearing 3+ times consecutively)
7
+ * - Strip trailing whitespace per line
8
+ */
9
+ /** Maximum consecutive blank lines to keep */
10
+ const MAX_BLANK_LINES = 2;
11
+ /** Number of identical consecutive lines that triggers dedup */
12
+ const REPEAT_THRESHOLD = 3;
13
+ export function cleanup(text) {
14
+ // 1. Normalize line endings
15
+ let result = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
16
+ // 2. Strip trailing whitespace per line
17
+ result = result
18
+ .split('\n')
19
+ .map(line => line.trimEnd())
20
+ .join('\n');
21
+ // 3. Deduplicate repeated consecutive identical lines (tool output spam)
22
+ result = deduplicateRepeatedLines(result);
23
+ // 4. Collapse excess blank lines
24
+ result = collapseBlankLines(result);
25
+ // 5. Trim leading/trailing whitespace
26
+ return result.trim();
27
+ }
28
+ /**
29
+ * If the same non-empty line appears REPEAT_THRESHOLD or more times in a row,
30
+ * collapse them to a single instance.
31
+ */
32
+ function deduplicateRepeatedLines(text) {
33
+ const lines = text.split('\n');
34
+ const out = [];
35
+ let i = 0;
36
+ while (i < lines.length) {
37
+ const line = lines[i] ?? '';
38
+ if (line.trim() === '') {
39
+ out.push(line);
40
+ i++;
41
+ continue;
42
+ }
43
+ // Count consecutive identical lines
44
+ let count = 1;
45
+ while (i + count < lines.length && lines[i + count] === line) {
46
+ count++;
47
+ }
48
+ if (count >= REPEAT_THRESHOLD) {
49
+ // Replace run with single occurrence + indicator
50
+ out.push(line);
51
+ }
52
+ else {
53
+ for (let j = 0; j < count; j++)
54
+ out.push(line);
55
+ }
56
+ i += count;
57
+ }
58
+ return out.join('\n');
59
+ }
60
+ /**
61
+ * Collapse runs of more than MAX_BLANK_LINES consecutive blank lines.
62
+ */
63
+ function collapseBlankLines(text) {
64
+ // Replace 3+ consecutive newlines with 2 newlines (= MAX_BLANK_LINES blank line)
65
+ return text.replace(/\n{3,}/g, '\n\n');
66
+ }
67
+ //# sourceMappingURL=01-cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"01-cleanup.js","sourceRoot":"","sources":["../../../src/distill/stages/01-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8CAA8C;AAC9C,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,gEAAgE;AAChE,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,4BAA4B;IAC5B,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,C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,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC;QACD,CAAC,IAAI,KAAK,CAAC;IACb,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,iFAAiF;IACjF,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Stage 2 — Normalize (deterministic)
3
+ *
4
+ * - Windows backslash paths → forward slash
5
+ * - Absolute paths → home-relative (~/)
6
+ * - ISO-8601 timestamp normalization (various formats → canonical)
7
+ * - Agent name casing → lowercase canonical
8
+ */
9
+ export declare function normalize(text: string): string;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Stage 2 — Normalize (deterministic)
3
+ *
4
+ * - Windows backslash paths → forward slash
5
+ * - Absolute paths → home-relative (~/)
6
+ * - ISO-8601 timestamp normalization (various formats → canonical)
7
+ * - Agent name casing → lowercase canonical
8
+ */
9
+ import { homedir } from 'node:os';
10
+ /**
11
+ * Canonical agent name mapping. Keys are lowercase patterns to match,
12
+ * values are canonical forms.
13
+ */
14
+ const AGENT_ALIASES = {
15
+ 'claude-code': 'claude-code',
16
+ 'claude code': 'claude-code',
17
+ 'claudecode': 'claude-code',
18
+ 'cursor': 'cursor',
19
+ 'copilot': 'github-copilot',
20
+ 'github copilot': 'github-copilot',
21
+ 'github-copilot': 'github-copilot',
22
+ };
23
+ /** Regex for Windows-style absolute paths: C:\... or D:\... */
24
+ const WIN_ABS_PATH_RE = /[A-Za-z]:\\(?:[^\s"'<>|?*\r\n]+)/g;
25
+ /** Regex for Unix-style absolute paths starting with / */
26
+ const UNIX_ABS_PATH_RE = /(?<!\w)(\/[^\s"'<>|?*\r\n:]{2,})/g;
27
+ /**
28
+ * Common timestamp patterns to normalize to ISO-8601 UTC:
29
+ * - 2024-01-15T10:30:00.000Z → keep as-is (already ISO)
30
+ * - 2024-01-15 10:30:00 → 2024-01-15T10:30:00Z
31
+ * - Jan 15, 2024 10:30 AM → skip (too ambiguous without timezone)
32
+ */
33
+ const DATETIME_SPACE_RE = /(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})(?:\.\d+)?(?:\s*UTC|\s*Z)?/g;
34
+ const home = homedir();
35
+ export function normalize(text) {
36
+ let result = text;
37
+ // 1. Windows paths → forward slash, then treat as absolute
38
+ result = result.replace(WIN_ABS_PATH_RE, (match) => {
39
+ // C:\Users\foo\bar → ~/bar (replace home dir portion)
40
+ const forwardSlash = match.replace(/\\/g, '/');
41
+ return homeRelative(forwardSlash);
42
+ });
43
+ // 2. Unix absolute paths → home-relative where applicable
44
+ result = result.replace(UNIX_ABS_PATH_RE, (match) => {
45
+ return homeRelative(match);
46
+ });
47
+ // 3. Datetime with space separator → ISO-8601
48
+ result = result.replace(DATETIME_SPACE_RE, (_match, date, time) => {
49
+ return `${date}T${time}Z`;
50
+ });
51
+ // 4. Agent names → lowercase canonical
52
+ result = normalizeAgentNames(result);
53
+ return result;
54
+ }
55
+ function homeRelative(path) {
56
+ // Normalize home dir to forward slashes for comparison
57
+ const homeForward = home.replace(/\\/g, '/');
58
+ const pathForward = path.replace(/\\/g, '/');
59
+ if (pathForward.startsWith(homeForward)) {
60
+ return '~' + pathForward.slice(homeForward.length);
61
+ }
62
+ // Also handle Windows-style home in forward-slash form: /Users/xxx or /home/xxx
63
+ // covered by the homedir() call above already
64
+ return pathForward;
65
+ }
66
+ function normalizeAgentNames(text) {
67
+ // Replace known agent name patterns (word-boundary aware)
68
+ for (const [alias, canonical] of Object.entries(AGENT_ALIASES)) {
69
+ // Escape special regex chars in alias
70
+ const escaped = alias.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
71
+ const re = new RegExp(`\\b${escaped}\\b`, 'gi');
72
+ text = text.replace(re, canonical);
73
+ }
74
+ return text;
75
+ }
76
+ //# sourceMappingURL=02-normalize.js.map