akm-cli 0.8.7 → 0.8.14

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 (324) hide show
  1. package/CHANGELOG.md +428 -0
  2. package/dist/assets/help/help-proposals.md +1 -2
  3. package/dist/assets/hints/cli-hints-full.md +34 -19
  4. package/dist/assets/hints/cli-hints-short.md +1 -1
  5. package/dist/assets/profiles/catchup.json +13 -0
  6. package/dist/assets/profiles/consolidate.json +13 -0
  7. package/dist/assets/profiles/frequent.json +13 -0
  8. package/dist/assets/tasks/core/backup.yml +4 -0
  9. package/dist/assets/tasks/core/extract.yml +4 -0
  10. package/dist/assets/tasks/core/improve.yml +4 -0
  11. package/dist/assets/tasks/core/index-refresh.yml +4 -0
  12. package/dist/assets/tasks/core/sync.yml +4 -0
  13. package/dist/assets/tasks/core/update-stashes.yml +4 -0
  14. package/dist/assets/tasks/core/version-check.yml +4 -0
  15. package/dist/assets/templates/html/default.html +78 -0
  16. package/dist/assets/templates/html/health.html +560 -0
  17. package/dist/assets/templates/html/vendor/echarts.min.js +45 -0
  18. package/dist/cli/config-migrate.js +6 -6
  19. package/dist/cli/config-validate.js +4 -4
  20. package/dist/cli/confirm.js +3 -3
  21. package/dist/cli/parse-args.js +1 -1
  22. package/dist/cli/shared.js +72 -19
  23. package/dist/cli-node.mjs +26 -0
  24. package/dist/cli.js +206 -3866
  25. package/dist/commands/{agent-dispatch.js → agent/agent-dispatch.js} +6 -6
  26. package/dist/commands/{agent-support.js → agent/agent-support.js} +2 -2
  27. package/dist/commands/agent/contribute-cli.js +200 -0
  28. package/dist/commands/completions.js +1 -1
  29. package/dist/commands/config-cli.js +230 -3
  30. package/dist/commands/db-cli.js +2 -2
  31. package/dist/commands/env/env-cli.js +529 -0
  32. package/dist/commands/env/env.js +410 -0
  33. package/dist/commands/env/secret-cli.js +259 -0
  34. package/dist/commands/{secret.js → env/secret.js} +6 -47
  35. package/dist/commands/events.js +4 -4
  36. package/dist/commands/feedback-cli.js +18 -34
  37. package/dist/commands/graph/graph-cli.js +132 -0
  38. package/dist/commands/{graph.js → graph/graph.js} +22 -16
  39. package/dist/commands/health/checks.js +279 -0
  40. package/dist/commands/health/html-report.js +448 -0
  41. package/dist/commands/health.js +189 -266
  42. package/dist/commands/{consolidate.js → improve/consolidate.js} +48 -36
  43. package/dist/commands/{distill-promotion-policy.js → improve/distill-promotion-policy.js} +3 -3
  44. package/dist/commands/{distill.js → improve/distill.js} +39 -18
  45. package/dist/commands/{eval-cases.js → improve/eval-cases.js} +1 -1
  46. package/dist/commands/{extract-cli.js → improve/extract-cli.js} +4 -4
  47. package/dist/commands/{extract-prompt.js → improve/extract-prompt.js} +2 -2
  48. package/dist/commands/{extract.js → improve/extract.js} +221 -26
  49. package/dist/commands/{improve-auto-accept.js → improve/improve-auto-accept.js} +30 -4
  50. package/dist/commands/{improve-cli.js → improve/improve-cli.js} +44 -22
  51. package/dist/commands/{improve-profiles.js → improve/improve-profiles.js} +13 -7
  52. package/dist/commands/{improve-result-file.js → improve/improve-result-file.js} +1 -1
  53. package/dist/commands/{improve.js → improve/improve.js} +672 -292
  54. package/dist/{core → commands/improve/memory}/memory-belief.js +2 -2
  55. package/dist/{core → commands/improve/memory}/memory-contradiction-detect.js +5 -5
  56. package/dist/{core → commands/improve/memory}/memory-improve.js +4 -4
  57. package/dist/commands/improve/reflect-noise.js +0 -0
  58. package/dist/commands/{reflect.js → improve/reflect.js} +58 -28
  59. package/dist/commands/improve/session-asset.js +248 -0
  60. package/dist/commands/lint/agent-linter.js +1 -1
  61. package/dist/commands/lint/base-linter.js +55 -37
  62. package/dist/commands/lint/command-linter.js +1 -1
  63. package/dist/commands/lint/default-linter.js +1 -1
  64. package/dist/commands/lint/env-key-rules.js +1 -1
  65. package/dist/commands/lint/index.js +19 -25
  66. package/dist/commands/lint/knowledge-linter.js +1 -1
  67. package/dist/commands/lint/memory-linter.js +1 -1
  68. package/dist/commands/lint/registry.js +8 -8
  69. package/dist/commands/lint/skill-linter.js +1 -1
  70. package/dist/commands/lint/task-linter.js +1 -1
  71. package/dist/commands/lint/workflow-linter.js +1 -1
  72. package/dist/commands/lint.js +1 -1
  73. package/dist/commands/observability-cli.js +244 -0
  74. package/dist/commands/proposal/drain-policies.js +3 -3
  75. package/dist/commands/proposal/drain.js +87 -15
  76. package/dist/commands/proposal/proposal-cli.js +490 -0
  77. package/dist/commands/{proposal.js → proposal/proposal.js} +17 -6
  78. package/dist/commands/{propose.js → proposal/propose.js} +11 -11
  79. package/dist/{core → commands/proposal/validators}/proposal-quality-validators.js +8 -3
  80. package/dist/{core → commands/proposal/validators}/proposal-validators.js +5 -5
  81. package/dist/{core → commands/proposal/validators}/proposals.js +374 -345
  82. package/dist/commands/{curate.js → read/curate.js} +7 -7
  83. package/dist/commands/{knowledge.js → read/knowledge.js} +22 -9
  84. package/dist/commands/{registry-search.js → read/registry-search.js} +5 -5
  85. package/dist/commands/{remember-cli.js → read/remember-cli.js} +15 -7
  86. package/dist/commands/read/search-cli.js +207 -0
  87. package/dist/commands/{search.js → read/search.js} +22 -27
  88. package/dist/commands/{show.js → read/show.js} +31 -45
  89. package/dist/commands/registry-cli.js +8 -8
  90. package/dist/commands/remember.js +14 -10
  91. package/dist/commands/sources/add-cli.js +293 -0
  92. package/dist/commands/{history.js → sources/history.js} +27 -25
  93. package/dist/commands/{info.js → sources/info.js} +6 -6
  94. package/dist/commands/{init.js → sources/init.js} +6 -6
  95. package/dist/commands/{installed-stashes.js → sources/installed-stashes.js} +12 -12
  96. package/dist/commands/{migration-help.js → sources/migration-help.js} +3 -2
  97. package/dist/commands/{schema-repair.js → sources/schema-repair.js} +8 -8
  98. package/dist/commands/{self-update.js → sources/self-update.js} +10 -9
  99. package/dist/commands/{source-add.js → sources/source-add.js} +10 -10
  100. package/dist/commands/{source-clone.js → sources/source-clone.js} +7 -7
  101. package/dist/commands/{source-manage.js → sources/source-manage.js} +4 -4
  102. package/dist/commands/sources/sources-cli.js +305 -0
  103. package/dist/commands/sources/stash-cli.js +219 -0
  104. package/dist/commands/{stash-skeleton.js → sources/stash-skeleton.js} +2 -1
  105. package/dist/commands/tasks/default-tasks.js +173 -0
  106. package/dist/commands/tasks/tasks-cli.js +210 -0
  107. package/dist/commands/{tasks.js → tasks/tasks.js} +14 -14
  108. package/dist/commands/wiki-cli.js +307 -0
  109. package/dist/commands/workflow-cli.js +329 -0
  110. package/dist/core/action-contributors.js +1 -1
  111. package/dist/core/assert.js +40 -0
  112. package/dist/core/asset/asset-create.js +54 -0
  113. package/dist/core/{asset-ref.js → asset/asset-ref.js} +21 -4
  114. package/dist/core/{asset-registry.js → asset/asset-registry.js} +3 -3
  115. package/dist/core/{asset-spec.js → asset/asset-spec.js} +17 -31
  116. package/dist/core/{markdown.js → asset/markdown.js} +1 -1
  117. package/dist/core/{stash-meta.js → asset/stash-meta.js} +1 -1
  118. package/dist/core/best-effort.js +64 -0
  119. package/dist/core/common.js +32 -18
  120. package/dist/core/{config-io.js → config/config-io.js} +29 -19
  121. package/dist/core/{config-migration.js → config/config-migration.js} +11 -9
  122. package/dist/core/{config-schema.js → config/config-schema.js} +50 -7
  123. package/dist/core/config/config-types.js +16 -0
  124. package/dist/core/{config-walker.js → config/config-walker.js} +2 -2
  125. package/dist/core/{config.js → config/config.js} +10 -8
  126. package/dist/core/env-secret-ref.js +90 -0
  127. package/dist/core/errors.js +13 -3
  128. package/dist/core/events.js +27 -4
  129. package/dist/core/file-lock.js +1 -1
  130. package/dist/core/improve-types.js +48 -0
  131. package/dist/core/lesson-lint.js +2 -2
  132. package/dist/core/logs-db.js +304 -0
  133. package/dist/core/paths.js +2 -2
  134. package/dist/core/ripgrep/install.js +2 -2
  135. package/dist/core/ripgrep/resolve.js +2 -2
  136. package/dist/core/state-db.js +195 -60
  137. package/dist/core/text-truncation.js +148 -0
  138. package/dist/core/time.js +1 -1
  139. package/dist/core/write-source.js +98 -85
  140. package/dist/indexer/{db-backup.js → db/db-backup.js} +9 -24
  141. package/dist/indexer/{db.js → db/db.js} +128 -118
  142. package/dist/indexer/{graph-db.js → db/graph-db.js} +9 -4
  143. package/dist/indexer/{llm-cache.js → db/llm-cache.js} +15 -12
  144. package/dist/indexer/ensure-index.js +4 -4
  145. package/dist/indexer/{graph-boost.js → graph/graph-boost.js} +1 -1
  146. package/dist/indexer/{graph-extraction.js → graph/graph-extraction.js} +55 -13
  147. package/dist/indexer/indexer.js +37 -30
  148. package/dist/indexer/init.js +54 -0
  149. package/dist/indexer/manifest.js +10 -10
  150. package/dist/indexer/{memory-inference.js → passes/memory-inference.js} +141 -33
  151. package/dist/indexer/{metadata-contributors.js → passes/metadata-contributors.js} +10 -8
  152. package/dist/indexer/{metadata.js → passes/metadata.js} +15 -19
  153. package/dist/indexer/{staleness-detect.js → passes/staleness-detect.js} +53 -12
  154. package/dist/indexer/{db-search.js → search/db-search.js} +28 -16
  155. package/dist/indexer/{ranking-contributors.js → search/ranking-contributors.js} +1 -1
  156. package/dist/indexer/{ranking.js → search/ranking.js} +2 -2
  157. package/dist/indexer/{search-hit-enrichers.js → search/search-hit-enrichers.js} +3 -3
  158. package/dist/indexer/{search-source.js → search/search-source.js} +8 -8
  159. package/dist/indexer/{semantic-status.js → search/semantic-status.js} +3 -3
  160. package/dist/indexer/usage/unmigrated-vaults-guard.js +94 -0
  161. package/dist/indexer/{usage-events.js → usage/usage-events.js} +32 -0
  162. package/dist/indexer/{file-context.js → walk/file-context.js} +10 -15
  163. package/dist/indexer/{matchers.js → walk/matchers.js} +13 -9
  164. package/dist/indexer/{path-resolver.js → walk/path-resolver.js} +6 -6
  165. package/dist/indexer/{project-context.js → walk/project-context.js} +1 -1
  166. package/dist/indexer/{walker.js → walk/walker.js} +4 -3
  167. package/dist/integrations/agent/builder-shared.js +39 -0
  168. package/dist/integrations/agent/builders.js +14 -81
  169. package/dist/integrations/agent/config.js +6 -4
  170. package/dist/integrations/agent/detect.js +1 -1
  171. package/dist/integrations/agent/index.js +23 -8
  172. package/dist/integrations/agent/prompts.js +2 -3
  173. package/dist/integrations/agent/runner.js +22 -3
  174. package/dist/integrations/agent/spawn.js +9 -10
  175. package/dist/integrations/harnesses/claude/agent-builder.js +48 -0
  176. package/dist/integrations/harnesses/claude/config-import.js +70 -0
  177. package/dist/integrations/harnesses/claude/index.js +64 -0
  178. package/dist/integrations/{session-logs/providers/claude-code.js → harnesses/claude/session-log.js} +32 -5
  179. package/dist/integrations/harnesses/index.js +144 -0
  180. package/dist/integrations/harnesses/opencode/agent-builder.js +43 -0
  181. package/dist/integrations/harnesses/opencode/config-import.js +82 -0
  182. package/dist/integrations/harnesses/opencode/index.js +59 -0
  183. package/dist/integrations/{session-logs/providers/opencode.js → harnesses/opencode/session-log.js} +1 -1
  184. package/dist/integrations/harnesses/opencode-sdk/index.js +49 -0
  185. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +234 -0
  186. package/dist/integrations/harnesses/types.js +43 -0
  187. package/dist/integrations/lockfile.js +7 -16
  188. package/dist/integrations/session-logs/index.js +82 -9
  189. package/dist/llm/call-ai.js +4 -4
  190. package/dist/llm/client.js +146 -6
  191. package/dist/llm/embedder.js +6 -6
  192. package/dist/llm/embedders/local.js +9 -22
  193. package/dist/llm/embedders/remote.js +2 -2
  194. package/dist/llm/embedders/types.js +1 -1
  195. package/dist/llm/graph-extract.js +31 -12
  196. package/dist/llm/index-passes.js +1 -1
  197. package/dist/llm/memory-infer.js +12 -5
  198. package/dist/llm/metadata-enhance.js +2 -2
  199. package/dist/llm/usage-persist.js +77 -0
  200. package/dist/llm/usage-telemetry.js +103 -0
  201. package/dist/output/context.js +9 -46
  202. package/dist/output/html-render.js +73 -0
  203. package/dist/output/renderers.js +88 -58
  204. package/dist/output/shapes/curate.js +7 -3
  205. package/dist/output/shapes/distill.js +7 -3
  206. package/dist/output/shapes/env-list.js +18 -16
  207. package/dist/output/shapes/events.js +5 -4
  208. package/dist/output/shapes/helpers.js +19 -5
  209. package/dist/output/shapes/history.js +7 -3
  210. package/dist/output/shapes/passthrough.js +8 -11
  211. package/dist/output/shapes/{proposal-accept.js → proposal/accept.js} +7 -3
  212. package/dist/output/shapes/{proposal-diff.js → proposal/diff.js} +7 -3
  213. package/dist/output/shapes/{proposal-list.js → proposal/list.js} +7 -3
  214. package/dist/output/shapes/{proposal-producer.js → proposal/producer.js} +5 -4
  215. package/dist/output/shapes/{proposal-reject.js → proposal/reject.js} +7 -3
  216. package/dist/output/shapes/{proposal-show.js → proposal/show.js} +7 -3
  217. package/dist/output/shapes/registry-search.js +7 -3
  218. package/dist/output/shapes/registry.js +12 -0
  219. package/dist/output/shapes/search.js +7 -3
  220. package/dist/output/shapes/secret-list.js +18 -16
  221. package/dist/output/shapes/show.js +7 -3
  222. package/dist/output/shapes.js +55 -30
  223. package/dist/output/text/add.js +2 -3
  224. package/dist/output/text/clone.js +2 -3
  225. package/dist/output/text/config.js +2 -3
  226. package/dist/output/text/curate.js +4 -3
  227. package/dist/output/text/distill.js +2 -3
  228. package/dist/output/text/enable-disable.js +5 -4
  229. package/dist/output/text/env.js +13 -0
  230. package/dist/output/text/events.js +5 -4
  231. package/dist/output/text/feedback.js +4 -3
  232. package/dist/output/text/helpers.js +123 -40
  233. package/dist/output/text/history.js +2 -3
  234. package/dist/output/text/import.js +2 -3
  235. package/dist/output/text/index.js +2 -3
  236. package/dist/output/text/info.js +2 -3
  237. package/dist/output/text/init.js +2 -3
  238. package/dist/output/text/list.js +2 -3
  239. package/dist/output/text/proposal/producer.js +9 -0
  240. package/dist/output/text/proposal/proposal.js +13 -0
  241. package/dist/output/text/registry-commands.js +8 -7
  242. package/dist/output/text/registry.js +12 -0
  243. package/dist/output/text/remember.js +4 -3
  244. package/dist/output/text/remove.js +2 -3
  245. package/dist/output/text/save.js +2 -3
  246. package/dist/output/text/search.js +4 -3
  247. package/dist/output/text/show.js +4 -3
  248. package/dist/output/text/update.js +2 -3
  249. package/dist/output/text/upgrade.js +2 -3
  250. package/dist/output/text/wiki.js +12 -11
  251. package/dist/output/text/workflow.js +12 -10
  252. package/dist/output/text.js +66 -32
  253. package/dist/registry/build-index.js +11 -10
  254. package/dist/registry/factory.js +1 -1
  255. package/dist/registry/origin-resolve.js +1 -1
  256. package/dist/registry/providers/index.js +2 -2
  257. package/dist/registry/providers/skills-sh.js +91 -72
  258. package/dist/registry/providers/static-index.js +75 -52
  259. package/dist/registry/resolve.js +3 -3
  260. package/dist/runtime.js +242 -0
  261. package/dist/scripts/migrate-storage.js +1654 -683
  262. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +254 -168
  263. package/dist/setup/detect.js +311 -9
  264. package/dist/setup/harness-config-import.js +6 -120
  265. package/dist/setup/setup.js +454 -43
  266. package/dist/sources/include.js +1 -1
  267. package/dist/sources/provider-factory.js +2 -2
  268. package/dist/sources/providers/filesystem.js +3 -3
  269. package/dist/sources/providers/git.js +9 -9
  270. package/dist/sources/providers/index.js +4 -4
  271. package/dist/sources/providers/npm.js +6 -6
  272. package/dist/sources/providers/provider-utils.js +13 -20
  273. package/dist/sources/providers/sync-from-ref.js +5 -5
  274. package/dist/sources/providers/tar-utils.js +2 -2
  275. package/dist/sources/providers/website.js +2 -2
  276. package/dist/sources/resolve.js +5 -5
  277. package/dist/sources/website-ingest.js +5 -5
  278. package/dist/storage/database.js +102 -0
  279. package/dist/storage/engines/sqlite-migrations.js +42 -0
  280. package/dist/storage/locations.js +25 -0
  281. package/dist/storage/repositories/index-db.js +43 -0
  282. package/dist/storage/repositories/workflow-runs-repository.js +141 -0
  283. package/dist/tasks/backends/cron.js +4 -4
  284. package/dist/tasks/backends/exec-utils.js +32 -0
  285. package/dist/tasks/backends/index.js +3 -3
  286. package/dist/tasks/backends/launchd.js +7 -14
  287. package/dist/tasks/backends/schtasks.js +7 -16
  288. package/dist/tasks/embedded.js +71 -0
  289. package/dist/tasks/parser.js +2 -2
  290. package/dist/tasks/resolveAkmBin.js +1 -1
  291. package/dist/tasks/runner.js +127 -31
  292. package/dist/tasks/schedule.js +1 -1
  293. package/dist/tasks/validator.js +7 -7
  294. package/dist/text-import-hook.mjs +51 -0
  295. package/dist/version.js +2 -1
  296. package/dist/wiki/wiki.js +7 -7
  297. package/dist/workflows/{authoring.js → authoring/authoring.js} +6 -6
  298. package/dist/workflows/{scope-key.js → authoring/scope-key.js} +1 -1
  299. package/dist/workflows/cli.js +1 -1
  300. package/dist/workflows/db.js +54 -32
  301. package/dist/workflows/parser.js +4 -4
  302. package/dist/workflows/renderer.js +5 -5
  303. package/dist/workflows/runtime/agent-identity.js +56 -0
  304. package/dist/workflows/runtime/checkin.js +57 -0
  305. package/dist/workflows/{runs.js → runtime/runs.js} +197 -101
  306. package/dist/workflows/validate-summary.js +82 -0
  307. package/docs/README.md +1 -1
  308. package/docs/data-and-telemetry.md +6 -6
  309. package/package.json +17 -8
  310. package/dist/commands/add-cli.js +0 -279
  311. package/dist/commands/env.js +0 -213
  312. package/dist/integrations/agent/sdk-runner.js +0 -126
  313. package/dist/output/shapes/vault-list.js +0 -19
  314. package/dist/output/text/proposal-producer.js +0 -8
  315. package/dist/output/text/proposal.js +0 -12
  316. package/dist/output/text/vault.js +0 -16
  317. /package/dist/core/{asset-serialize.js → asset/asset-serialize.js} +0 -0
  318. /package/dist/core/{frontmatter.js → asset/frontmatter.js} +0 -0
  319. /package/dist/core/{config-sources.js → config/config-sources.js} +0 -0
  320. /package/dist/indexer/{graph-dedup.js → graph/graph-dedup.js} +0 -0
  321. /package/dist/{core/config-types.js → indexer/passes/pass-context.js} +0 -0
  322. /package/dist/indexer/{search-fields.js → search/search-fields.js} +0 -0
  323. /package/dist/indexer/{index-context.js → walk/index-context.js} +0 -0
  324. /package/dist/workflows/{document-cache.js → runtime/document-cache.js} +0 -0
@@ -353,7 +353,65 @@ var require_main = __commonJS((exports, module) => {
353
353
  module.exports = DotenvModule;
354
354
  });
355
355
 
356
- // src/commands/env.ts
356
+ // src/core/errors.ts
357
+ var CONFIG_HINTS, USAGE_HINTS, AkmError, ConfigError, UsageError;
358
+ var init_errors = __esm(() => {
359
+ CONFIG_HINTS = {
360
+ STASH_DIR_NOT_FOUND: "Run `akm setup` to create and configure your stash, or set stashDir in your config.",
361
+ STASH_DIR_NOT_A_DIRECTORY: "The configured stashDir exists but isn't a directory. Update stashDir to point at a folder.",
362
+ STASH_DIR_UNREADABLE: "Check the path exists and your user has read permission, or update stashDir.",
363
+ EMBEDDING_NOT_CONFIGURED: 'Run `akm config set embedding \'{"endpoint":"...","model":"..."}\'` to enable embeddings.',
364
+ LLM_NOT_CONFIGURED: 'Run `akm setup` or `akm config set profiles.llm.default \'{"endpoint":"...","model":"..."}\' to configure an LLM profile.',
365
+ TEST_ISOLATION_MISSING: "Under bun test, when AKM_STASH_DIR is set you MUST also set XDG_DATA_HOME (or AKM_DATA_DIR) and XDG_STATE_HOME (or AKM_STATE_DIR) to temp directories so the test does not touch the developer's real ~/.local/share/akm or ~/.local/state/akm.",
366
+ SETUP_TMP_STASH_REFUSED: "Use a persistent directory, or set AKM_FORCE_SETUP_TMP_STASH=1 to opt in to a sandboxed setup (setup also pre-sets AKM_STASH_DIR so config and cache writes auto-isolate into $stashDir/.akm/ \u2014 host config is preserved).",
367
+ UNSAFE_STASH_DIR: "Choose a path inside your home directory (e.g. ~/akm) or another empty workspace. The stash directory cannot be the filesystem root, your home directory itself, or a sensitive system path like /etc, /var, ~/.config, or ~/.ssh."
368
+ };
369
+ USAGE_HINTS = {
370
+ INVALID_FLAG_VALUE: "Run `akm <command> --help` to see accepted values.",
371
+ INVALID_SOURCE_VALUE: "Pick one of: stash, registry, both.",
372
+ INVALID_FORMAT_VALUE: "Pick one of: json, jsonl, text, yaml.",
373
+ INVALID_DETAIL_VALUE: "Pick one of: brief, normal, full. For agent/summary projections use --shape.",
374
+ INVALID_SHAPE_VALUE: "Pick one of: human, agent, summary (summary is only valid on `akm show`).",
375
+ INVALID_JSON_CONFIG_VALUE: `Quote JSON values in your shell, for example: akm config set embedding '{"endpoint":"http://localhost:11434/v1/embeddings","model":"nomic-embed-text"}'.`,
376
+ MISSING_OR_AMBIGUOUS_TARGET: "Use `akm update --all` or pass a target like `akm update npm:@scope/pkg` (not both).",
377
+ TARGET_NOT_UPDATABLE: "Run `akm list` to view your sources, then retry with one of those values.",
378
+ MISSING_REQUIRED_ARGUMENT: "Refs use the form type:name, e.g. `akm show skill:deploy` or `akm show knowledge:guide.md`."
379
+ };
380
+ AkmError = class AkmError extends Error {
381
+ };
382
+ ConfigError = class ConfigError extends AkmError {
383
+ kind = "config";
384
+ code;
385
+ _hint;
386
+ constructor(msg, code = "INVALID_CONFIG_FILE", hint) {
387
+ super(msg);
388
+ this.name = "ConfigError";
389
+ this.code = code;
390
+ this._hint = hint;
391
+ Object.setPrototypeOf(this, new.target.prototype);
392
+ }
393
+ hint() {
394
+ return this._hint ?? CONFIG_HINTS[this.code];
395
+ }
396
+ };
397
+ UsageError = class UsageError extends AkmError {
398
+ kind = "usage";
399
+ code;
400
+ _hint;
401
+ constructor(msg, code = "INVALID_FLAG_VALUE", hint) {
402
+ super(msg);
403
+ this.name = "UsageError";
404
+ this.code = code;
405
+ this._hint = hint;
406
+ Object.setPrototypeOf(this, new.target.prototype);
407
+ }
408
+ hint() {
409
+ return this._hint ?? USAGE_HINTS[this.code];
410
+ }
411
+ };
412
+ });
413
+
414
+ // src/commands/env/env.ts
357
415
  import fs from "fs";
358
416
  function scanKeys(text) {
359
417
  const keys = [];
@@ -389,11 +447,12 @@ function listKeys(envPath) {
389
447
  var import_dotenv, ASSIGN_RE;
390
448
  var init_env = __esm(() => {
391
449
  init_common();
450
+ init_errors();
392
451
  import_dotenv = __toESM(require_main(), 1);
393
452
  ASSIGN_RE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/;
394
453
  });
395
454
 
396
- // src/core/frontmatter.ts
455
+ // src/core/asset/frontmatter.ts
397
456
  function parseFrontmatter(raw) {
398
457
  const parsedBlock = parseFrontmatterBlock(raw);
399
458
  if (!parsedBlock) {
@@ -541,7 +600,7 @@ function parseYamlScalar(value) {
541
600
  return value;
542
601
  }
543
602
 
544
- // src/core/markdown.ts
603
+ // src/core/asset/markdown.ts
545
604
  function parseMarkdownToc(content) {
546
605
  const lines = content.split(/\r?\n/);
547
606
  const headings = [];
@@ -561,17 +620,17 @@ function parseMarkdownToc(content) {
561
620
  }
562
621
  var init_markdown = () => {};
563
622
 
564
- // src/indexer/file-context.ts
623
+ // src/core/warn.ts
624
+ var init_warn = () => {};
625
+
626
+ // src/indexer/walk/file-context.ts
565
627
  var renderers;
566
628
  var init_file_context = __esm(() => {
567
629
  init_common();
568
630
  renderers = new Map;
569
631
  });
570
632
 
571
- // src/core/warn.ts
572
- var init_warn = () => {};
573
-
574
- // src/indexer/metadata-contributors.ts
633
+ // src/indexer/passes/metadata-contributors.ts
575
634
  function registerMetadataContributor(contributor) {
576
635
  contributors.push(contributor);
577
636
  }
@@ -580,7 +639,7 @@ var init_metadata_contributors = __esm(() => {
580
639
  contributors = [];
581
640
  });
582
641
 
583
- // src/indexer/metadata.ts
642
+ // src/indexer/passes/metadata.ts
584
643
  import fs2 from "fs";
585
644
  function extractDescriptionFromComments(filePath) {
586
645
  let content;
@@ -632,75 +691,12 @@ var init_metadata = __esm(() => {
632
691
  WIKI_INFRA_FILES = new Set(["schema.md", "index.md", "log.md"]);
633
692
  });
634
693
 
635
- // src/core/errors.ts
636
- var CONFIG_HINTS, USAGE_HINTS, ConfigError, UsageError;
637
- var init_errors = __esm(() => {
638
- CONFIG_HINTS = {
639
- STASH_DIR_NOT_FOUND: "Run `akm setup` to create and configure your stash, or set stashDir in your config.",
640
- STASH_DIR_NOT_A_DIRECTORY: "The configured stashDir exists but isn't a directory. Update stashDir to point at a folder.",
641
- STASH_DIR_UNREADABLE: "Check the path exists and your user has read permission, or update stashDir.",
642
- EMBEDDING_NOT_CONFIGURED: 'Run `akm config set embedding \'{"endpoint":"...","model":"..."}\'` to enable embeddings.',
643
- LLM_NOT_CONFIGURED: 'Run `akm setup` or `akm config set profiles.llm.default \'{"endpoint":"...","model":"..."}\' to configure an LLM profile.',
644
- TEST_ISOLATION_MISSING: "Under bun test, when AKM_STASH_DIR is set you MUST also set XDG_DATA_HOME (or AKM_DATA_DIR) and XDG_STATE_HOME (or AKM_STATE_DIR) to temp directories so the test does not touch the developer's real ~/.local/share/akm or ~/.local/state/akm.",
645
- SETUP_TMP_STASH_REFUSED: "Use a persistent directory, or set AKM_FORCE_SETUP_TMP_STASH=1 to opt in to a sandboxed setup (setup also pre-sets AKM_STASH_DIR so config and cache writes auto-isolate into $stashDir/.akm/ \u2014 host config is preserved).",
646
- UNSAFE_STASH_DIR: "Choose a path inside your home directory (e.g. ~/akm) or another empty workspace. The stash directory cannot be the filesystem root, your home directory itself, or a sensitive system path like /etc, /var, ~/.config, or ~/.ssh."
647
- };
648
- USAGE_HINTS = {
649
- INVALID_FLAG_VALUE: "Run `akm <command> --help` to see accepted values.",
650
- INVALID_SOURCE_VALUE: "Pick one of: stash, registry, both.",
651
- INVALID_FORMAT_VALUE: "Pick one of: json, jsonl, text, yaml.",
652
- INVALID_DETAIL_VALUE: "Pick one of: brief, normal, full. For agent/summary projections use --shape.",
653
- INVALID_SHAPE_VALUE: "Pick one of: human, agent, summary (summary is only valid on `akm show`).",
654
- INVALID_JSON_CONFIG_VALUE: `Quote JSON values in your shell, for example: akm config set embedding '{"endpoint":"http://localhost:11434/v1/embeddings","model":"nomic-embed-text"}'.`,
655
- MISSING_OR_AMBIGUOUS_TARGET: "Use `akm update --all` or pass a target like `akm update npm:@scope/pkg` (not both).",
656
- TARGET_NOT_UPDATABLE: "Run `akm list` to view your sources, then retry with one of those values.",
657
- MISSING_REQUIRED_ARGUMENT: "Refs use the form type:name, e.g. `akm show skill:deploy` or `akm show knowledge:guide.md`."
658
- };
659
- ConfigError = class ConfigError extends Error {
660
- code;
661
- _hint;
662
- constructor(msg, code = "INVALID_CONFIG_FILE", hint) {
663
- super(msg);
664
- this.name = "ConfigError";
665
- this.code = code;
666
- this._hint = hint;
667
- Object.setPrototypeOf(this, new.target.prototype);
668
- }
669
- hint() {
670
- return this._hint ?? CONFIG_HINTS[this.code];
671
- }
672
- };
673
- UsageError = class UsageError extends Error {
674
- code;
675
- _hint;
676
- constructor(msg, code = "INVALID_FLAG_VALUE", hint) {
677
- super(msg);
678
- this.name = "UsageError";
679
- this.code = code;
680
- this._hint = hint;
681
- Object.setPrototypeOf(this, new.target.prototype);
682
- }
683
- hint() {
684
- return this._hint ?? USAGE_HINTS[this.code];
685
- }
686
- };
687
- });
688
-
689
- // src/core/asset-ref.ts
694
+ // src/core/asset/asset-ref.ts
690
695
  var init_asset_ref = __esm(() => {
691
696
  init_common();
692
697
  init_errors();
693
698
  });
694
699
 
695
- // src/workflows/document-cache.ts
696
- function cacheWorkflowDocument(entry, doc) {
697
- cache.set(entry, doc);
698
- }
699
- var cache;
700
- var init_document_cache = __esm(() => {
701
- cache = new WeakMap;
702
- });
703
-
704
700
  // node_modules/yaml/dist/nodes/identity.js
705
701
  var require_identity = __commonJS((exports) => {
706
702
  var ALIAS = Symbol.for("yaml.alias");
@@ -8071,6 +8067,15 @@ var init_parser = __esm(() => {
8071
8067
  BULLET_LINE = /^[-*]\s+(.+)$/;
8072
8068
  });
8073
8069
 
8070
+ // src/workflows/runtime/document-cache.ts
8071
+ function cacheWorkflowDocument(entry, doc) {
8072
+ cache.set(entry, doc);
8073
+ }
8074
+ var cache;
8075
+ var init_document_cache = __esm(() => {
8076
+ cache = new WeakMap;
8077
+ });
8078
+
8074
8079
  // src/workflows/renderer.ts
8075
8080
  function shellQuote(value) {
8076
8081
  return `'${value.replace(/'/g, `'\\''`)}'`;
@@ -8091,8 +8096,8 @@ var init_renderer = __esm(() => {
8091
8096
  init_asset_ref();
8092
8097
  init_errors();
8093
8098
  init_metadata_contributors();
8094
- init_document_cache();
8095
8099
  init_parser();
8100
+ init_document_cache();
8096
8101
  registerMetadataContributor({
8097
8102
  name: "workflow-document-metadata",
8098
8103
  appliesTo: ({ rendererName }) => rendererName === "workflow-md",
@@ -8121,6 +8126,24 @@ var init_renderer = __esm(() => {
8121
8126
  });
8122
8127
 
8123
8128
  // src/output/renderers.ts
8129
+ function applySessionMetadata(entry, ctx) {
8130
+ try {
8131
+ const fm = applyFrontmatterDescriptionAndTags(entry, ctx);
8132
+ entry.tags = Array.from(new Set([...entry.tags ?? [], "session"]));
8133
+ const hints = new Set(entry.searchHints ?? []);
8134
+ const harness = asNonEmptyString(fm.harness);
8135
+ if (harness)
8136
+ hints.add(`harness:${harness}`);
8137
+ const project = asNonEmptyString(fm.project);
8138
+ if (project)
8139
+ hints.add(`project:${project}`);
8140
+ const logPath = asNonEmptyString(fm.log_path);
8141
+ if (logPath)
8142
+ hints.add(`log_path:${logPath}`);
8143
+ if (hints.size > 0)
8144
+ entry.searchHints = Array.from(hints).filter(Boolean);
8145
+ } catch {}
8146
+ }
8124
8147
  function applyTocMetadata(entry, ctx) {
8125
8148
  try {
8126
8149
  const toc = parseMarkdownToc(ctx.content());
@@ -8192,18 +8215,6 @@ function applyScriptMetadata(entry, ctx) {
8192
8215
  entry.confidence = 0.7;
8193
8216
  }
8194
8217
  }
8195
- function applyVaultMetadata(entry, ctx) {
8196
- const { keys, comments } = listKeys(ctx.absPath);
8197
- if (comments.length > 0 && !entry.description) {
8198
- entry.description = comments.join(" ").slice(0, 500);
8199
- entry.source = "comments";
8200
- entry.confidence = 0.7;
8201
- }
8202
- if (keys.length > 0) {
8203
- entry.searchHints = keys;
8204
- }
8205
- entry.tags = Array.from(new Set([...entry.tags ?? [], "vault", "secrets"]));
8206
- }
8207
8218
  function applyEnvMetadata(entry, ctx) {
8208
8219
  const { keys, comments } = listKeys(ctx.absPath);
8209
8220
  if (comments.length > 0 && !entry.description) {
@@ -8239,11 +8250,11 @@ function applyTaskMetadata(entry, ctx) {
8239
8250
  }
8240
8251
  var init_renderers = __esm(() => {
8241
8252
  init_env();
8242
- init_common();
8243
8253
  init_markdown();
8244
- init_file_context();
8254
+ init_common();
8245
8255
  init_metadata();
8246
8256
  init_metadata_contributors();
8257
+ init_file_context();
8247
8258
  init_renderer();
8248
8259
  registerMetadataContributor({
8249
8260
  name: "toc-metadata",
@@ -8265,11 +8276,6 @@ var init_renderers = __esm(() => {
8265
8276
  appliesTo: ({ rendererName }) => rendererName === "script-source",
8266
8277
  contribute: (entry, ctx) => applyScriptMetadata(entry, ctx.renderContext)
8267
8278
  });
8268
- registerMetadataContributor({
8269
- name: "vault-secret-metadata",
8270
- appliesTo: ({ rendererName }) => rendererName === "vault-env",
8271
- contribute: (entry, ctx) => applyVaultMetadata(entry, ctx.renderContext)
8272
- });
8273
8279
  registerMetadataContributor({
8274
8280
  name: "env-file-metadata",
8275
8281
  appliesTo: ({ rendererName }) => rendererName === "env-file",
@@ -8285,20 +8291,28 @@ var init_renderers = __esm(() => {
8285
8291
  appliesTo: ({ rendererName }) => rendererName === "task-yaml",
8286
8292
  contribute: (entry, ctx) => applyTaskMetadata(entry, ctx.renderContext)
8287
8293
  });
8294
+ registerMetadataContributor({
8295
+ name: "session-md-metadata",
8296
+ appliesTo: ({ rendererName }) => rendererName === "session-md",
8297
+ contribute: (entry, ctx) => applySessionMetadata(entry, ctx.renderContext)
8298
+ });
8288
8299
  });
8289
8300
 
8290
- // src/core/asset-registry.ts
8301
+ // src/core/asset/asset-registry.ts
8291
8302
  var init_asset_registry = __esm(() => {
8292
8303
  init_renderers();
8293
8304
  });
8294
8305
 
8295
- // src/core/asset-spec.ts
8306
+ // src/core/asset/asset-spec.ts
8296
8307
  import path from "path";
8308
+ function getAssetTypes() {
8309
+ return Object.keys(ASSET_SPECS_INTERNAL);
8310
+ }
8297
8311
  var buildTaskAction = (ref) => `akm tasks show ${ref.replace(/^task:/, "")} -> inspect; akm tasks run <id> -> run now; akm tasks remove <id> -> unschedule`, markdownSpec, SCRIPT_EXTENSIONS, scriptSpec, ASSET_SPECS_INTERNAL, TYPE_DIRS;
8298
8312
  var init_asset_spec = __esm(() => {
8299
8313
  init_renderers();
8300
- init_asset_registry();
8301
8314
  init_common();
8315
+ init_asset_registry();
8302
8316
  markdownSpec = {
8303
8317
  isRelevantFile: (fileName) => path.extname(fileName).toLowerCase() === ".md",
8304
8318
  toCanonicalName: (typeRoot, filePath) => {
@@ -8377,27 +8391,6 @@ var init_asset_spec = __esm(() => {
8377
8391
  rendererName: "env-file",
8378
8392
  actionBuilder: (ref) => `akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with the whole .env injected (values never reach stdout); akm env export ${ref} --out <file> -> write a sourceable script to a file`
8379
8393
  },
8380
- vault: {
8381
- stashDir: "vaults",
8382
- isRelevantFile: (fileName) => fileName === ".env" || fileName.endsWith(".env"),
8383
- toCanonicalName: (typeRoot, filePath) => {
8384
- const rel = toPosix(path.relative(typeRoot, filePath));
8385
- const fileName = path.basename(rel);
8386
- if (fileName === ".env") {
8387
- const dir = path.dirname(rel);
8388
- return dir === "." || dir === "" ? "default" : `${dir}/default`;
8389
- }
8390
- const stripped = rel.endsWith(".env") ? rel.slice(0, -4) : rel;
8391
- return stripped;
8392
- },
8393
- toAssetPath: (typeRoot, name) => {
8394
- if (name === "default")
8395
- return path.join(typeRoot, ".env");
8396
- return path.join(typeRoot, name.endsWith(".env") ? name : `${name}.env`);
8397
- },
8398
- rendererName: "vault-env",
8399
- actionBuilder: (ref) => `DEPRECATED (use env): akm show ${ref} -> inspect key names; akm env run ${ref} -- <command> -> run with injected env`
8400
- },
8401
8394
  secret: {
8402
8395
  stashDir: "secrets",
8403
8396
  isRelevantFile: (fileName) => !fileName.endsWith(".lock") && !fileName.endsWith(".sensitive"),
@@ -8431,6 +8424,12 @@ var init_asset_spec = __esm(() => {
8431
8424
  },
8432
8425
  rendererName: "task-yaml",
8433
8426
  actionBuilder: buildTaskAction
8427
+ },
8428
+ session: {
8429
+ stashDir: "sessions",
8430
+ ...markdownSpec,
8431
+ rendererName: "session-md",
8432
+ actionBuilder: (ref) => `akm show ${ref} -> read the session summary; follow the \`access\` frontmatter to open the raw log at \`log_path\``
8434
8433
  }
8435
8434
  };
8436
8435
  TYPE_DIRS = Object.fromEntries(Object.entries(ASSET_SPECS_INTERNAL).map(([type, spec]) => [type, spec.stashDir]));
@@ -8451,20 +8450,7 @@ var init_common = __esm(() => {
8451
8450
  init_asset_spec();
8452
8451
  init_errors();
8453
8452
  init_paths();
8454
- ASSET_TYPES = [
8455
- "skill",
8456
- "command",
8457
- "agent",
8458
- "knowledge",
8459
- "workflow",
8460
- "script",
8461
- "memory",
8462
- "env",
8463
- "vault",
8464
- "secret",
8465
- "wiki",
8466
- "lesson"
8467
- ];
8453
+ ASSET_TYPES = Object.freeze([...getAssetTypes()]);
8468
8454
  ASSET_TYPE_SET = new Set(ASSET_TYPES);
8469
8455
  IS_WINDOWS = process.platform === "win32";
8470
8456
  DEFAULT_RESPONSE_BYTE_CAP = 10 * 1024 * 1024;
@@ -8516,11 +8502,123 @@ import fs4 from "fs";
8516
8502
  import path4 from "path";
8517
8503
 
8518
8504
  // src/core/state-db.ts
8519
- init_paths();
8520
- init_warn();
8521
- import { Database } from "bun:sqlite";
8522
8505
  import fs3 from "fs";
8523
8506
  import path3 from "path";
8507
+
8508
+ // src/storage/database.ts
8509
+ import { createRequire } from "module";
8510
+ var isBun = !!process.versions?.bun;
8511
+ var nodeRequire = createRequire(import.meta.url);
8512
+ function openDatabase(path, opts) {
8513
+ if (isBun) {
8514
+ return openBunDatabase(path, opts);
8515
+ }
8516
+ return openNodeDatabase(path, opts);
8517
+ }
8518
+ function openBunDatabase(path, opts) {
8519
+ const { Database: BunDatabase } = loadBunSqlite();
8520
+ const db = opts ? new BunDatabase(path, bunOptions(opts)) : new BunDatabase(path);
8521
+ return db;
8522
+ }
8523
+ function bunOptions(opts) {
8524
+ const out = {};
8525
+ if (opts.readonly !== undefined)
8526
+ out.readonly = opts.readonly;
8527
+ if (opts.create !== undefined)
8528
+ out.create = opts.create;
8529
+ return out;
8530
+ }
8531
+ var bunSqliteModule;
8532
+ function loadBunSqlite() {
8533
+ if (!bunSqliteModule) {
8534
+ bunSqliteModule = nodeRequire("bun:sqlite");
8535
+ }
8536
+ return bunSqliteModule;
8537
+ }
8538
+ var betterSqlite3Ctor;
8539
+ function loadBetterSqlite3() {
8540
+ if (!betterSqlite3Ctor) {
8541
+ const mod = nodeRequire("better-sqlite3");
8542
+ betterSqlite3Ctor = mod.default ?? mod;
8543
+ }
8544
+ return betterSqlite3Ctor;
8545
+ }
8546
+ function openNodeDatabase(path, opts) {
8547
+ const BetterSqlite3 = loadBetterSqlite3();
8548
+ const options = {};
8549
+ if (opts?.readonly !== undefined)
8550
+ options.readonly = opts.readonly;
8551
+ if (opts?.create === false)
8552
+ options.fileMustExist = true;
8553
+ const db = opts ? new BetterSqlite3(path, options) : new BetterSqlite3(path);
8554
+ return db;
8555
+ }
8556
+
8557
+ // src/storage/engines/sqlite-migrations.ts
8558
+ function ensureMigrationsTable(db) {
8559
+ db.exec(`
8560
+ CREATE TABLE IF NOT EXISTS schema_migrations (
8561
+ id TEXT PRIMARY KEY,
8562
+ applied_at TEXT NOT NULL DEFAULT (datetime('now'))
8563
+ );
8564
+ `);
8565
+ }
8566
+ function runMigrations(db, migrations, opts) {
8567
+ ensureMigrationsTable(db);
8568
+ opts?.bootstrap?.(db);
8569
+ const appliedRows = db.prepare("SELECT id FROM schema_migrations").all();
8570
+ const applied = new Set(appliedRows.map((r) => r.id));
8571
+ for (const migration of migrations) {
8572
+ if (applied.has(migration.id))
8573
+ continue;
8574
+ db.transaction(() => {
8575
+ db.exec(migration.up);
8576
+ db.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(migration.id);
8577
+ })();
8578
+ }
8579
+ }
8580
+
8581
+ // src/core/assert.ts
8582
+ function assertNever(x, context) {
8583
+ let serialized;
8584
+ try {
8585
+ serialized = JSON.stringify(x);
8586
+ } catch {
8587
+ serialized = String(x);
8588
+ }
8589
+ if (serialized === undefined) {
8590
+ serialized = String(x);
8591
+ }
8592
+ const where = context ? ` (${context})` : "";
8593
+ throw new Error(`Unexpected value reached assertNever${where}: ${serialized}`);
8594
+ }
8595
+
8596
+ // src/core/improve-types.ts
8597
+ function classifyImproveAction(mode) {
8598
+ switch (mode) {
8599
+ case "reflect":
8600
+ case "distill":
8601
+ case "memory-inference":
8602
+ case "graph-extraction":
8603
+ return "accepted";
8604
+ case "reflect-cooldown":
8605
+ case "reflect-skipped":
8606
+ case "distill-skipped":
8607
+ case "reflect-guard-rejected":
8608
+ return "rejected";
8609
+ case "reflect-failed":
8610
+ case "error":
8611
+ return "error";
8612
+ case "memory-prune":
8613
+ return "noop";
8614
+ default:
8615
+ return assertNever(mode);
8616
+ }
8617
+ }
8618
+
8619
+ // src/core/state-db.ts
8620
+ init_paths();
8621
+ init_warn();
8524
8622
  function getStateDbPath() {
8525
8623
  return path3.join(getDataDir(), "state.db");
8526
8624
  }
@@ -8530,11 +8628,11 @@ function openStateDatabase(dbPath) {
8530
8628
  if (!fs3.existsSync(dir)) {
8531
8629
  fs3.mkdirSync(dir, { recursive: true });
8532
8630
  }
8533
- const db = new Database(resolvedPath);
8631
+ const db = openDatabase(resolvedPath);
8534
8632
  db.exec("PRAGMA journal_mode = WAL");
8535
8633
  db.exec("PRAGMA foreign_keys = ON");
8536
- db.exec("PRAGMA busy_timeout = 5000");
8537
- runMigrations(db);
8634
+ db.exec("PRAGMA busy_timeout = 30000");
8635
+ runMigrations2(db);
8538
8636
  return db;
8539
8637
  }
8540
8638
  var MIGRATIONS = [
@@ -8608,7 +8706,9 @@ var MIGRATIONS = [
8608
8706
  --
8609
8707
  -- Extensible (metadata_json) columns:
8610
8708
  -- metadata_json TEXT \u2014 JSON object for future proposal fields.
8611
- -- Current fields stored here: sourceRun, review.
8709
+ -- Current fields stored here: sourceRun,
8710
+ -- review, confidence, gateDecision (#577),
8711
+ -- backupContent.
8612
8712
  --
8613
8713
  -- ADD COLUMN extension points (future migrations):
8614
8714
  -- ALTER TABLE proposals ADD COLUMN source_run TEXT DEFAULT NULL;
@@ -8795,28 +8895,20 @@ var MIGRATIONS = [
8795
8895
  CREATE INDEX IF NOT EXISTS idx_extract_sessions_processed
8796
8896
  ON extract_sessions_seen(processed_at);
8797
8897
  `
8898
+ },
8899
+ {
8900
+ id: "005-proposal-fs-imports",
8901
+ up: `
8902
+ CREATE TABLE IF NOT EXISTS proposal_fs_imports (
8903
+ stash_dir TEXT PRIMARY KEY,
8904
+ imported_at TEXT NOT NULL,
8905
+ imported_count INTEGER NOT NULL DEFAULT 0
8906
+ );
8907
+ `
8798
8908
  }
8799
8909
  ];
8800
- function ensureMigrationsTable(db) {
8801
- db.exec(`
8802
- CREATE TABLE IF NOT EXISTS schema_migrations (
8803
- id TEXT PRIMARY KEY,
8804
- applied_at TEXT NOT NULL DEFAULT (datetime('now'))
8805
- );
8806
- `);
8807
- }
8808
- function runMigrations(db) {
8809
- ensureMigrationsTable(db);
8810
- const appliedRows = db.prepare("SELECT id FROM schema_migrations").all();
8811
- const applied = new Set(appliedRows.map((r) => r.id));
8812
- for (const migration of MIGRATIONS) {
8813
- if (applied.has(migration.id))
8814
- continue;
8815
- db.transaction(() => {
8816
- db.exec(migration.up);
8817
- db.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(migration.id);
8818
- })();
8819
- }
8910
+ function runMigrations2(db) {
8911
+ runMigrations(db, MIGRATIONS);
8820
8912
  }
8821
8913
  function computeImproveRunMetrics(result) {
8822
8914
  const plannedCount = Array.isArray(result.plannedRefs) ? result.plannedRefs.length : 0;
@@ -8827,23 +8919,17 @@ function computeImproveRunMetrics(result) {
8827
8919
  let autoAcceptedCount = 0;
8828
8920
  let errorCount = 0;
8829
8921
  for (const action of actions) {
8830
- switch (action.mode) {
8831
- case "reflect":
8832
- case "distill":
8833
- case "memory-inference":
8834
- case "graph-extraction":
8922
+ switch (classifyImproveAction(action.mode)) {
8923
+ case "accepted":
8835
8924
  acceptedCount++;
8836
8925
  break;
8837
- case "reflect-cooldown":
8838
- case "reflect-skipped":
8839
- case "distill-skipped":
8926
+ case "rejected":
8840
8927
  rejectedCount++;
8841
8928
  break;
8842
- case "reflect-failed":
8843
8929
  case "error":
8844
8930
  errorCount++;
8845
8931
  break;
8846
- case "memory-prune":
8932
+ case "noop":
8847
8933
  break;
8848
8934
  }
8849
8935
  const r = action.result;