@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,117 @@
1
+ CREATE TABLE sessions (
2
+ id TEXT PRIMARY KEY,
3
+ repo TEXT,
4
+ project TEXT,
5
+ branch TEXT,
6
+ agent TEXT,
7
+ started_at INTEGER NOT NULL,
8
+ ended_at INTEGER
9
+ );
10
+ CREATE INDEX idx_sessions_repo_started ON sessions(repo, started_at DESC);
11
+
12
+ CREATE TABLE messages (
13
+ id TEXT PRIMARY KEY,
14
+ session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
15
+ role TEXT NOT NULL,
16
+ content TEXT NOT NULL,
17
+ ts INTEGER NOT NULL,
18
+ kind TEXT
19
+ );
20
+ CREATE INDEX idx_messages_session ON messages(session_id, ts);
21
+
22
+ CREATE TABLE transcripts (
23
+ id TEXT PRIMARY KEY,
24
+ session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
25
+ source TEXT NOT NULL,
26
+ content TEXT NOT NULL,
27
+ ingested_at INTEGER NOT NULL
28
+ );
29
+ CREATE INDEX idx_transcripts_session ON transcripts(session_id);
30
+
31
+ CREATE TABLE memories (
32
+ id TEXT PRIMARY KEY,
33
+ type TEXT NOT NULL CHECK(type IN ('decision','fact','lesson','command','todo')),
34
+ text TEXT NOT NULL,
35
+ normalized_text TEXT NOT NULL,
36
+ repo TEXT,
37
+ project TEXT,
38
+ branch TEXT,
39
+ agent TEXT,
40
+ session_id TEXT REFERENCES sessions(id) ON DELETE SET NULL,
41
+ importance REAL NOT NULL DEFAULT 0.5,
42
+ confidence REAL NOT NULL DEFAULT 0.5,
43
+ hash TEXT NOT NULL,
44
+ embedding_provider TEXT,
45
+ embedding_model TEXT,
46
+ embedding_dim INTEGER,
47
+ created_at INTEGER NOT NULL,
48
+ updated_at INTEGER NOT NULL,
49
+ source_hash TEXT
50
+ );
51
+ CREATE UNIQUE INDEX idx_memories_hash ON memories(hash);
52
+ CREATE INDEX idx_memories_repo_type ON memories(repo, type, created_at DESC);
53
+ CREATE INDEX idx_memories_session ON memories(session_id);
54
+
55
+ CREATE VIRTUAL TABLE memories_fts USING fts5(
56
+ text, normalized_text, content='memories', content_rowid='rowid'
57
+ );
58
+
59
+ CREATE TRIGGER memories_ai AFTER INSERT ON memories BEGIN
60
+ INSERT INTO memories_fts(rowid, text, normalized_text) VALUES (new.rowid, new.text, new.normalized_text);
61
+ END;
62
+ CREATE TRIGGER memories_ad AFTER DELETE ON memories BEGIN
63
+ INSERT INTO memories_fts(memories_fts, rowid, text, normalized_text) VALUES('delete', old.rowid, old.text, old.normalized_text);
64
+ END;
65
+ CREATE TRIGGER memories_au AFTER UPDATE ON memories BEGIN
66
+ INSERT INTO memories_fts(memories_fts, rowid, text, normalized_text) VALUES('delete', old.rowid, old.text, old.normalized_text);
67
+ INSERT INTO memories_fts(rowid, text, normalized_text) VALUES (new.rowid, new.text, new.normalized_text);
68
+ END;
69
+
70
+ -- Vector index dim is parameterized (FEAT-409, src/contracts/embed.ts
71
+ -- DEFAULT_EMBED_DIM). __EMBED_DIM__ is substituted by storage/migrate.ts
72
+ -- with config.embedding.dim at migration time — defaults to 1024, matching
73
+ -- both Ollama mxbai-embed-large (native 1024) and Azure text-embedding-3-*
74
+ -- (via `dimensions: 1024`). This substitution only affects a FRESH
75
+ -- database (this file only runs once, the first time schema_version has no
76
+ -- row for version 1); an EXISTING database's dim is immutable short of the
77
+ -- resumable re-embed procedure (migration 011, `astramem-local
78
+ -- reembed-dim`) since sqlite-vec's vec0 table fixes its dim at CREATE
79
+ -- TABLE time. Changing the embedding provider (even at the same dim)
80
+ -- still requires a re-embed pass — different models are different
81
+ -- geometric spaces.
82
+ CREATE VIRTUAL TABLE memories_vec USING vec0(embedding FLOAT[__EMBED_DIM__]);
83
+
84
+ CREATE TABLE jobs (
85
+ id TEXT PRIMARY KEY,
86
+ kind TEXT NOT NULL,
87
+ payload_json TEXT NOT NULL,
88
+ state TEXT NOT NULL CHECK(state IN ('pending','running','completed','failed','poison','paused')),
89
+ attempts INTEGER NOT NULL DEFAULT 0,
90
+ last_error TEXT,
91
+ created_at INTEGER NOT NULL,
92
+ updated_at INTEGER NOT NULL
93
+ );
94
+ CREATE INDEX idx_jobs_state ON jobs(state, created_at);
95
+
96
+ CREATE TABLE artifacts (
97
+ id TEXT PRIMARY KEY,
98
+ job_id TEXT NOT NULL REFERENCES jobs(id) ON DELETE CASCADE,
99
+ kind TEXT NOT NULL,
100
+ content_path TEXT NOT NULL,
101
+ created_at INTEGER NOT NULL
102
+ );
103
+
104
+ CREATE TABLE provider_state (
105
+ provider TEXT NOT NULL,
106
+ model TEXT NOT NULL,
107
+ dim INTEGER,
108
+ last_health_ok INTEGER NOT NULL DEFAULT 0,
109
+ last_check_at INTEGER,
110
+ PRIMARY KEY (provider, model)
111
+ );
112
+
113
+ CREATE TABLE budget_spend (
114
+ day TEXT PRIMARY KEY,
115
+ usd_total REAL NOT NULL DEFAULT 0,
116
+ calls INTEGER NOT NULL DEFAULT 0
117
+ );
@@ -0,0 +1,16 @@
1
+ ALTER TABLE transcripts ADD COLUMN event TEXT;
2
+ ALTER TABLE transcripts ADD COLUMN captured_at INTEGER;
3
+ ALTER TABLE transcripts ADD COLUMN client_scrub_applied INTEGER;
4
+ ALTER TABLE transcripts ADD COLUMN client_scrub_hits INTEGER;
5
+ ALTER TABLE transcripts ADD COLUMN client_scrub_version TEXT;
6
+ ALTER TABLE transcripts ADD COLUMN client_scrub_hits_by_label_json TEXT;
7
+ ALTER TABLE transcripts ADD COLUMN client_version TEXT;
8
+ ALTER TABLE transcripts ADD COLUMN wire_version TEXT NOT NULL DEFAULT 'v0.0';
9
+
10
+ CREATE TABLE ingest_idempotency (
11
+ key TEXT PRIMARY KEY,
12
+ tenant_id TEXT,
13
+ body_hash TEXT NOT NULL,
14
+ summary_memory_id TEXT,
15
+ created_at INTEGER NOT NULL
16
+ );
@@ -0,0 +1,81 @@
1
+ -- 003: Expand memories.type CHECK to include 'note' + 'event'
2
+ -- SQLite table-rewrite pattern (CHECK constraints are immutable).
3
+ -- migrate.ts wraps each migration in db.transaction() — no explicit BEGIN/COMMIT here.
4
+ --
5
+ -- FK safety: PRAGMA foreign_keys = OFF is a session-level, out-of-transaction operation
6
+ -- and cannot be set inside better-sqlite3's transaction wrapper. It is not required here
7
+ -- because:
8
+ -- (a) we INSERT INTO memories_new SELECT * FROM memories — all existing session_id
9
+ -- values are already valid referents in sessions;
10
+ -- (b) the memories_vec virtual table has no FK dependency on memories.
11
+
12
+ -- 1. Create new table with expanded CHECK (all other columns verbatim from 001-init.sql)
13
+ CREATE TABLE memories_new (
14
+ id TEXT PRIMARY KEY,
15
+ type TEXT NOT NULL CHECK(type IN ('decision','fact','lesson','command','todo','note','event')),
16
+ text TEXT NOT NULL,
17
+ normalized_text TEXT NOT NULL,
18
+ repo TEXT,
19
+ project TEXT,
20
+ branch TEXT,
21
+ agent TEXT,
22
+ session_id TEXT REFERENCES sessions(id) ON DELETE SET NULL,
23
+ importance REAL NOT NULL DEFAULT 0.5,
24
+ confidence REAL NOT NULL DEFAULT 0.5,
25
+ hash TEXT NOT NULL,
26
+ embedding_provider TEXT,
27
+ embedding_model TEXT,
28
+ embedding_dim INTEGER,
29
+ created_at INTEGER NOT NULL,
30
+ updated_at INTEGER NOT NULL,
31
+ source_hash TEXT
32
+ );
33
+
34
+ -- 2. Copy all existing rows
35
+ INSERT INTO memories_new SELECT * FROM memories;
36
+
37
+ -- 3. Drop old triggers that reference the old memories table
38
+ DROP TRIGGER IF EXISTS memories_ai;
39
+ DROP TRIGGER IF EXISTS memories_ad;
40
+ DROP TRIGGER IF EXISTS memories_au;
41
+
42
+ -- 4. Drop old indexes attached to memories
43
+ DROP INDEX IF EXISTS idx_memories_hash;
44
+ DROP INDEX IF EXISTS idx_memories_repo_type;
45
+ DROP INDEX IF EXISTS idx_memories_session;
46
+
47
+ -- 5. Drop FTS table (FTS5 content= binding references the table by name;
48
+ -- it does NOT follow a rename — must drop and recreate)
49
+ DROP TABLE IF EXISTS memories_fts;
50
+
51
+ -- 6. Drop old table and rename new table into place
52
+ DROP TABLE memories;
53
+ ALTER TABLE memories_new RENAME TO memories;
54
+
55
+ -- 7. Recreate indexes (verbatim from 001-init.sql)
56
+ CREATE UNIQUE INDEX idx_memories_hash ON memories(hash);
57
+ CREATE INDEX idx_memories_repo_type ON memories(repo, type, created_at DESC);
58
+ CREATE INDEX idx_memories_session ON memories(session_id);
59
+
60
+ -- 8. Recreate FTS5 virtual table (verbatim from 001-init.sql)
61
+ CREATE VIRTUAL TABLE memories_fts USING fts5(
62
+ text, normalized_text, content='memories', content_rowid='rowid'
63
+ );
64
+
65
+ -- 9. Repopulate FTS from existing rows
66
+ INSERT INTO memories_fts(rowid, text, normalized_text)
67
+ SELECT rowid, text, normalized_text FROM memories;
68
+
69
+ -- 10. Recreate triggers (verbatim from 001-init.sql)
70
+ CREATE TRIGGER memories_ai AFTER INSERT ON memories BEGIN
71
+ INSERT INTO memories_fts(rowid, text, normalized_text) VALUES (new.rowid, new.text, new.normalized_text);
72
+ END;
73
+ CREATE TRIGGER memories_ad AFTER DELETE ON memories BEGIN
74
+ INSERT INTO memories_fts(memories_fts, rowid, text, normalized_text) VALUES('delete', old.rowid, old.text, old.normalized_text);
75
+ END;
76
+ CREATE TRIGGER memories_au AFTER UPDATE ON memories BEGIN
77
+ INSERT INTO memories_fts(memories_fts, rowid, text, normalized_text) VALUES('delete', old.rowid, old.text, old.normalized_text);
78
+ INSERT INTO memories_fts(rowid, text, normalized_text) VALUES (new.rowid, new.text, new.normalized_text);
79
+ END;
80
+
81
+ -- memories_vec is a separate virtual table (vec0) — unaffected by memories rewrite, leave alone.
@@ -0,0 +1,4 @@
1
+ -- AM-1: persist stage-5 extraction evidence (provenance receipts).
2
+ -- Nullable: rows created before v0.4.0 have no evidence — why_memory
3
+ -- degrades gracefully. See design doc 2026-07-02 §2/§3.
4
+ ALTER TABLE memories ADD COLUMN evidence TEXT;
@@ -0,0 +1,12 @@
1
+ -- SEC-6: stage-0 secret-redaction counters. Counts + types only per ingest —
2
+ -- raw secret values are NEVER written here (see src/redact/). Surfaced via
3
+ -- `doctor` and GET /health. See docs/specs/2026-07-02-encryption-and-secret-redaction.md §4.2/§4.3.
4
+ CREATE TABLE redaction_log (
5
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6
+ type TEXT NOT NULL,
7
+ count INTEGER NOT NULL,
8
+ session_id TEXT NULL,
9
+ created_at INTEGER NOT NULL
10
+ );
11
+ CREATE INDEX idx_redaction_log_created ON redaction_log(created_at DESC);
12
+ CREATE INDEX idx_redaction_log_type ON redaction_log(type, created_at DESC);
@@ -0,0 +1,28 @@
1
+ -- 006: Atom v3 (ADR-001) — bitemporal validity, scope, lineage on memories.
2
+ -- See docs/adr/ADR-001-canonical-memory-atom.md.
3
+ --
4
+ -- valid_from/valid_to: bitemporal valid-time window. valid_to NULL = currently
5
+ -- valid. New rows set valid_from = created_at at insert time (see
6
+ -- src/storage/memories.ts); existing rows are backfilled below.
7
+ -- superseded_by: id of the memory that replaced this one. Mutated only via
8
+ -- the lifecycle/event-log ops landing in Wave 2b — this migration just adds
9
+ -- the column (NULL for all rows).
10
+ -- derived_from: JSON array of memory ids — consolidation lineage (ADR-004
11
+ -- stage 9). NULL until a consolidation pass sets it.
12
+ -- scope: personal | team | org (ADR-009); personal is the default.
13
+ --
14
+ -- SQLite ALTER TABLE ADD COLUMN cannot add NOT NULL with a non-constant
15
+ -- default on existing rows, but a literal constant default (scope) is fine
16
+ -- directly on the ALTER. valid_from has no literal default available (it
17
+ -- must mirror each row's own created_at), so it is backfilled via a
18
+ -- separate UPDATE statement below.
19
+
20
+ ALTER TABLE memories ADD COLUMN valid_from INTEGER;
21
+ ALTER TABLE memories ADD COLUMN valid_to INTEGER;
22
+ ALTER TABLE memories ADD COLUMN superseded_by TEXT;
23
+ ALTER TABLE memories ADD COLUMN derived_from TEXT;
24
+ ALTER TABLE memories ADD COLUMN scope TEXT NOT NULL DEFAULT 'personal';
25
+
26
+ -- Backfill valid_from for pre-existing rows so bitemporal queries are
27
+ -- correct from day one.
28
+ UPDATE memories SET valid_from = created_at WHERE valid_from IS NULL;
@@ -0,0 +1,30 @@
1
+ -- 007: memory_events append-only log (ADR-002 decision point 1).
2
+ -- See docs/adr/ADR-002-local-storage-engine.md.
3
+ --
4
+ -- Source of truth for state *changes*: create | invalidate | supersede |
5
+ -- promote_scope | erase_request | usefulness. Materialized state (the
6
+ -- memories table) is updated in the same transaction as the event append —
7
+ -- see src/storage/memory-events.ts MemoryEventRepo. This is log + tables in
8
+ -- one file, not full event sourcing: no view rebuilding, no projection
9
+ -- framework. The log exists so ADR-003 sync becomes log-shipping and audit
10
+ -- becomes free.
11
+
12
+ CREATE TABLE memory_events (
13
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
14
+ event_type TEXT NOT NULL CHECK(event_type IN ('create', 'invalidate', 'supersede', 'promote_scope', 'erase_request', 'usefulness')),
15
+ atom_id TEXT NOT NULL,
16
+ payload_json TEXT,
17
+ content_hash TEXT,
18
+ created_at INTEGER NOT NULL,
19
+ synced_at INTEGER
20
+ );
21
+
22
+ CREATE INDEX idx_memory_events_atom_seq ON memory_events (atom_id, seq);
23
+
24
+ -- Backfill: synthetic 'create' events for every pre-existing memory, so the
25
+ -- first sync (ADR-003) ships a complete log rather than one with a gap at
26
+ -- the start. Hash-stable: content_hash mirrors the memory's own hash column;
27
+ -- created_at mirrors the memory's own created_at (not the migration's run
28
+ -- time), so replays are consistent with actual atom creation order.
29
+ INSERT INTO memory_events (event_type, atom_id, payload_json, content_hash, created_at)
30
+ SELECT 'create', id, '{"backfill":true}', hash, created_at FROM memories;
@@ -0,0 +1,31 @@
1
+ -- 008: consolidation proposals (ADR-004 stage 9, Wave 4b).
2
+ --
3
+ -- Propose-only queue for consolidation actions that must NOT auto-apply
4
+ -- (strategy Pass 6 A4: auto-invalidation is trust-destroying). The offline
5
+ -- consolidation job writes 'pending' rows; the user accepts or rejects via
6
+ -- REST/MCP. Auto-merges (similarity above the merge threshold) bypass this
7
+ -- table entirely — they go straight through the supersede event flow, which
8
+ -- is non-destructive by construction (W4 fix: originals kept as superseded,
9
+ -- lineage recorded in memories.derived_from).
10
+ --
11
+ -- kind 'merge' — borderline near-duplicate pair, user confirms merge.
12
+ -- kind 'contradiction' — reserved for the v1.x LLM contradiction detector;
13
+ -- the confirm flow is identical, only the producer differs.
14
+
15
+ CREATE TABLE consolidation_proposals (
16
+ id TEXT PRIMARY KEY,
17
+ kind TEXT NOT NULL CHECK(kind IN ('merge', 'contradiction')),
18
+ -- winner_id: the atom that would survive; loser_id: the atom that would be
19
+ -- superseded. Pair is stored directionally after winner selection.
20
+ winner_id TEXT NOT NULL,
21
+ loser_id TEXT NOT NULL,
22
+ similarity REAL NOT NULL,
23
+ status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'accepted', 'rejected')),
24
+ created_at INTEGER NOT NULL,
25
+ resolved_at INTEGER
26
+ );
27
+
28
+ -- One live proposal per unordered pair — the job dedups on this before insert.
29
+ CREATE UNIQUE INDEX idx_consolidation_pair_pending
30
+ ON consolidation_proposals (MIN(winner_id, loser_id), MAX(winner_id, loser_id))
31
+ WHERE status = 'pending';
@@ -0,0 +1,13 @@
1
+ -- 009: tag hygiene (W4.3, FEAT-403) — persist session cwd.
2
+ --
3
+ -- `cwd` was already accepted on the canonical ingest envelope
4
+ -- (CanonicalIngestSchema.cwd, src/server/routes/ingest.ts) but never
5
+ -- persisted anywhere — the canonical wire path only ever wrote `project`
6
+ -- (from project_id) into `sessions`, leaving `sessions.repo` NULL forever
7
+ -- for every canonical-ingested session. That left no durable signal to
8
+ -- derive a memory's `repo` tag from after the fact.
9
+ --
10
+ -- Storing cwd lets the tag-hygiene backfill (src/tag-hygiene/backfill.ts)
11
+ -- derive `repo` from the last path segment of the session's cwd when
12
+ -- `sessions.repo` itself is unset (tier-1 heuristic, AC-1).
13
+ ALTER TABLE sessions ADD COLUMN cwd TEXT;
@@ -0,0 +1,53 @@
1
+ -- 010: sync pull — event_id (ADR-011 multi-device conflict policy) +
2
+ -- sync_pull_state (FEAT-407 pull watermark).
3
+ -- See docs/adr/ADR-011-multi-device-conflict-policy.md.
4
+ --
5
+ -- Part 1 — event_id on memory_events:
6
+ -- Globally-unique per-event identity assigned once at append time. This is
7
+ -- the pull-side idempotency key (FEAT-407 AC-2): "INSERT ... WHERE NOT
8
+ -- EXISTS (SELECT 1 FROM memory_events WHERE event_id = ?)" per pulled row,
9
+ -- and the deterministic tie-break key (created_at, event_id) ADR-011's
10
+ -- conflict rules use. Additive on the wire (WireSyncEvent gains event_id,
11
+ -- no astramem-sync@1 version bump — ADR-001's additive-field evolution
12
+ -- rule) and additive here: existing single-device append()/invalidate()/
13
+ -- supersede()/erase() code paths are unaffected other than now also writing
14
+ -- event_id.
15
+ --
16
+ -- SQLite ALTER TABLE ADD COLUMN cannot add NOT NULL with a non-constant
17
+ -- default on existing rows (same constraint migration 006 documented), so
18
+ -- the column is added nullable, backfilled per-row with a distinct
19
+ -- UUIDv4-shaped value (mirrors migration 007's synthetic-value backfill
20
+ -- pattern), then uniquely indexed. New rows always supply event_id via
21
+ -- MemoryEventRepo.append() (node:crypto randomUUID()) — enforced at the
22
+ -- application layer since SQLite can't retrofit a NOT NULL constraint onto
23
+ -- an existing column without a full table rebuild.
24
+
25
+ ALTER TABLE memory_events ADD COLUMN event_id TEXT;
26
+
27
+ UPDATE memory_events
28
+ SET event_id = lower(
29
+ hex(randomblob(4)) || '-' ||
30
+ hex(randomblob(2)) || '-4' ||
31
+ substr(hex(randomblob(2)), 2) || '-' ||
32
+ substr('89ab', 1 + (abs(random()) % 4), 1) ||
33
+ substr(hex(randomblob(2)), 2) || '-' ||
34
+ hex(randomblob(6))
35
+ )
36
+ WHERE event_id IS NULL;
37
+
38
+ CREATE UNIQUE INDEX idx_memory_events_event_id ON memory_events (event_id);
39
+
40
+ -- Part 2 — sync_pull_state: persisted pull cursor/watermark (FEAT-407's own
41
+ -- scope, per ADR-011's "Implications for FEAT-407": the merge/dedup
42
+ -- mechanics are ADR-011's, persisting where pull left off is FEAT-407's).
43
+ -- Single-row table (id=1 enforced) — one pull cursor per daemon install.
44
+ -- Persisted, and advanced in the SAME transaction as the dedup-insert +
45
+ -- projection recompute it corresponds to, so a daemon restart mid-sync
46
+ -- resumes from the last-persisted cursor rather than re-pulling from zero
47
+ -- or leaving a gap (AC-4).
48
+
49
+ CREATE TABLE sync_pull_state (
50
+ id INTEGER PRIMARY KEY CHECK (id = 1),
51
+ cursor TEXT,
52
+ updated_at INTEGER NOT NULL
53
+ );
@@ -0,0 +1,28 @@
1
+ -- FEAT-409: resumable checkpoint tracking for the embedding-dimension
2
+ -- re-embed procedure (`astramem-local reembed-dim`, docs/embed-dim-migration.md).
3
+ --
4
+ -- sqlite-vec's vec0 virtual table bakes its dim into CREATE VIRTUAL TABLE
5
+ -- DDL — there is no ALTER for it. Changing config.embedding.dim against an
6
+ -- EXISTING database with live data therefore requires: (1) recreating
7
+ -- memories_vec at the new dim (destructive — the pre-change backup is the
8
+ -- rollback, per AC-4), then (2) re-embedding every memory's text with the
9
+ -- newly-configured provider and upserting into the recreated table.
10
+ --
11
+ -- Step (2) calls out to the embed provider over the network per memory and
12
+ -- can be interrupted (Ctrl+C, crash, transient provider failure). This
13
+ -- table is the resumability mechanism: `reembed-dim` commits one row here
14
+ -- in the SAME transaction as each memory's vec upsert, so a re-run skips
15
+ -- memory ids already checkpointed for the target dim instead of redoing
16
+ -- completed work or leaving a memory half-migrated.
17
+ --
18
+ -- This is intentionally NOT the vector store itself and carries no dim
19
+ -- literal of its own — target_dim is data, supplied at runtime by the CLI,
20
+ -- not baked into schema (unlike memories_vec, whose dim genuinely must be
21
+ -- fixed at CREATE TABLE time for vec0 to work at all).
22
+ CREATE TABLE dim_migration_progress (
23
+ memory_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
24
+ target_dim INTEGER NOT NULL,
25
+ completed_at INTEGER NOT NULL,
26
+ PRIMARY KEY (memory_id, target_dim)
27
+ );
28
+ CREATE INDEX idx_dim_migration_progress_target ON dim_migration_progress(target_dim);
@@ -0,0 +1,36 @@
1
+ -- 012: entity extraction schema (W4.2, FEAT-402 slice 1).
2
+ --
3
+ -- entities: canonical named-thing registry. `name` is normalized (lowercase
4
+ -- + trim; AC-9 seam — src/entity/normalize.ts normalizeEntityName) so
5
+ -- "Postgres"/"postgres"/" Postgres " collapse to one row via the UNIQUE
6
+ -- constraint (EntityRepo.upsert selects-then-inserts on the normalized
7
+ -- name). An alias table ("pg" -> "postgres") is deferred — normalizeEntityName
8
+ -- is the single seam callers go through, so adding aliasing later never
9
+ -- touches call sites.
10
+ --
11
+ -- memory_entities: many-to-many link, memory_id -> entity_id, written by the
12
+ -- distill-time embed-index stage (same LLM call as atom extraction) and by
13
+ -- the one-shot `entity-backfill` CLI command for the pre-existing corpus.
14
+ --
15
+ -- Cascade (AC-3, zero orphan links):
16
+ -- - erase() HARD-deletes the memories row (src/storage/memory-events.ts) —
17
+ -- ON DELETE CASCADE on memory_id follows it automatically because
18
+ -- foreign_keys=ON is set for every connection (src/storage/db.ts).
19
+ -- - supersede() does NOT delete the memories row (bitemporal history is
20
+ -- kept for as_of queries) so it cannot rely on FK cascade; it explicitly
21
+ -- deletes the old memory's memory_entities rows in the same transaction
22
+ -- — a superseded memory's facts should stop counting as "current"
23
+ -- evidence for an entity even though the row itself survives for audit.
24
+ CREATE TABLE entities (
25
+ id TEXT PRIMARY KEY,
26
+ name TEXT NOT NULL UNIQUE,
27
+ kind TEXT NOT NULL
28
+ );
29
+
30
+ CREATE TABLE memory_entities (
31
+ memory_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
32
+ entity_id TEXT NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
33
+ PRIMARY KEY (memory_id, entity_id)
34
+ );
35
+
36
+ CREATE INDEX idx_memory_entities_entity ON memory_entities(entity_id);
@@ -0,0 +1,50 @@
1
+ -- 013: memory TTL / archival tiers (FEAT-404, W4.4).
2
+ --
3
+ -- Additive: `memories.archived` + `memories.archived_at` track archival
4
+ -- state (default off / null on every existing row). Archival reuses the
5
+ -- exact non-destructive bookkeeping supersede()/invalidate() already
6
+ -- established (migration 006/007): valid_to is set, no row is ever
7
+ -- deleted, and the transition is restorable — see
8
+ -- src/storage/memory-events.ts MemoryEventRepo.archive/restore. Because
9
+ -- archived memories get valid_to set, every existing `valid_to IS NULL`
10
+ -- candidate filter (search.ts, recall/pack.ts) already excludes them for
11
+ -- free; restore() clearing valid_to re-admits them for free too.
12
+ --
13
+ -- The memory_events.event_type CHECK constraint (migration 007) enumerates
14
+ -- valid event types; SQLite CHECK constraints are immutable (see migration
15
+ -- 003's create-copy-swap precedent), so widening it to add 'archive' and
16
+ -- 'restore' requires the same table-rewrite pattern. memory_events has no
17
+ -- FK dependents; it has two indexes (atom_seq from 007, the unique
18
+ -- event_id index from 010 ADR-011) and gained `event_id` via ALTER TABLE
19
+ -- ADD COLUMN in migration 010 — both are carried through explicitly below
20
+ -- (an explicit column list on the INSERT, not `SELECT *`, so this doesn't
21
+ -- silently depend on ADD COLUMN's physical append-at-end ordering).
22
+
23
+ ALTER TABLE memories ADD COLUMN archived INTEGER NOT NULL DEFAULT 0;
24
+ ALTER TABLE memories ADD COLUMN archived_at INTEGER;
25
+
26
+ -- Serves the archival pass's candidate-selection query (archived = 0 AND
27
+ -- valid_to IS NULL AND created_at < cutoff).
28
+ CREATE INDEX idx_memories_archival_candidates ON memories(archived, valid_to, created_at);
29
+
30
+ CREATE TABLE memory_events_new (
31
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
32
+ event_type TEXT NOT NULL CHECK(event_type IN ('create', 'invalidate', 'supersede', 'promote_scope', 'erase_request', 'usefulness', 'archive', 'restore')),
33
+ atom_id TEXT NOT NULL,
34
+ payload_json TEXT,
35
+ content_hash TEXT,
36
+ created_at INTEGER NOT NULL,
37
+ synced_at INTEGER,
38
+ event_id TEXT
39
+ );
40
+
41
+ INSERT INTO memory_events_new (seq, event_type, atom_id, payload_json, content_hash, created_at, synced_at, event_id)
42
+ SELECT seq, event_type, atom_id, payload_json, content_hash, created_at, synced_at, event_id FROM memory_events;
43
+
44
+ DROP INDEX IF EXISTS idx_memory_events_atom_seq;
45
+ DROP INDEX IF EXISTS idx_memory_events_event_id;
46
+ DROP TABLE memory_events;
47
+ ALTER TABLE memory_events_new RENAME TO memory_events;
48
+
49
+ CREATE INDEX idx_memory_events_atom_seq ON memory_events (atom_id, seq);
50
+ CREATE UNIQUE INDEX idx_memory_events_event_id ON memory_events (event_id);
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@astragenie/astramemory-local",
3
+ "version": "0.7.2",
4
+ "type": "module",
5
+ "bin": {
6
+ "astramem-local": "./dist/cli/index.js"
7
+ },
8
+ "files": [
9
+ "dist",
10
+ "migrations",
11
+ "README.md",
12
+ "CHANGELOG.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p .",
17
+ "dev": "tsc -w -p .",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest",
20
+ "test:smoke": "vitest run tests/smoke",
21
+ "contracts:validate": "node contracts/validate.mjs",
22
+ "prepublishOnly": "bun run build"
23
+ },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "trustedDependencies": [
28
+ "@napi-rs/keyring",
29
+ "better-sqlite3-multiple-ciphers"
30
+ ],
31
+ "dependencies": {
32
+ "@inquirer/prompts": "^8.5.2",
33
+ "@modelcontextprotocol/sdk": "^1.29.0",
34
+ "@napi-rs/keyring": "^1.3.0",
35
+ "better-sqlite3-multiple-ciphers": "^12.11.1",
36
+ "fastify": "^5.9.0",
37
+ "pino": "^10.3.1",
38
+ "pino-roll": "^4.0.0",
39
+ "sqlite-vec": "^0.1.0",
40
+ "zod": "^3.23.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.0.0",
44
+ "ajv": "^8.17.1",
45
+ "ajv-formats": "^3.0.1",
46
+ "typescript": "^5.5.0",
47
+ "vitest": "^4.1.9"
48
+ },
49
+ "license": "MIT"
50
+ }