akm-cli 0.9.30 → 0.10.261001-beta

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 (384) hide show
  1. package/CHANGELOG.md +438 -0
  2. package/README.md +10 -10
  3. package/ROADMAP.md +112 -0
  4. package/STABILITY.md +99 -57
  5. package/dist/api-node.mjs +20 -0
  6. package/dist/api.d.ts +23 -0
  7. package/dist/api.js +45 -0
  8. package/dist/assets/hints/cli-hints-full.md +15 -29
  9. package/dist/assets/hints/cli-hints-short.md +2 -2
  10. package/dist/assets/improve-strategies/default.json +3 -3
  11. package/dist/assets/prompts/consolidate-pair.md +9 -7
  12. package/dist/assets/stash-skeleton/README.md +1 -1
  13. package/dist/assets/tasks/improve/akm-improve-consolidate.yml +1 -1
  14. package/dist/cli/shared.js +31 -48
  15. package/dist/cli/unknown-flags.js +6 -43
  16. package/dist/cli.js +8 -34
  17. package/dist/commands/agent/contribute-cli.js +1 -1
  18. package/dist/commands/completions.js +1 -2
  19. package/dist/commands/config-cli.js +5 -28
  20. package/dist/commands/env/env-cli.js +5 -5
  21. package/dist/commands/env/secret-cli.js +2 -2
  22. package/dist/commands/feedback-cli.js +75 -49
  23. package/dist/commands/health/checks.js +41 -16
  24. package/dist/commands/health/plugin-staleness.js +52 -22
  25. package/dist/commands/improve/autonomy-gate.js +5 -3
  26. package/dist/commands/improve/consolidate/chunking.js +3 -10
  27. package/dist/commands/improve/consolidate/continuity-check.js +4 -4
  28. package/dist/commands/improve/consolidate/pair-pass.js +29 -10
  29. package/dist/commands/improve/consolidate.js +10 -65
  30. package/dist/commands/improve/distill/lesson-update.js +91 -0
  31. package/dist/commands/improve/distill-guards.js +1 -43
  32. package/dist/commands/improve/distill.js +148 -21
  33. package/dist/commands/improve/eligibility.js +14 -1
  34. package/dist/commands/improve/extract-cli.js +1 -1
  35. package/dist/commands/improve/extract-prompt.js +17 -7
  36. package/dist/commands/improve/extract.js +5 -7
  37. package/dist/commands/improve/improve-cli.js +125 -118
  38. package/dist/commands/improve/improve-strategies.js +8 -12
  39. package/dist/commands/improve/improve.js +134 -52
  40. package/dist/commands/improve/loop-stages.js +18 -5
  41. package/dist/commands/improve/planner.js +0 -1
  42. package/dist/commands/improve/preparation.js +40 -99
  43. package/dist/commands/improve/proactive-maintenance.js +2 -2
  44. package/dist/commands/improve/reflect-noise.js +3 -55
  45. package/dist/commands/improve/reflect.js +29 -34
  46. package/dist/commands/improve/retrieval-queries.js +37 -0
  47. package/dist/commands/improve/retrieval-scope.js +2 -2
  48. package/dist/commands/improve/salience.js +2 -9
  49. package/dist/commands/improve/session-asset.js +4 -1
  50. package/dist/commands/improve/stage.js +23 -12
  51. package/dist/commands/lint/index.js +5 -20
  52. package/dist/commands/observability-cli.js +3 -9
  53. package/dist/commands/proposal/drain.js +43 -6
  54. package/dist/commands/proposal/proposal-cli.js +11 -31
  55. package/dist/commands/proposal/repository.js +20 -14
  56. package/dist/commands/proposal/validators/proposal-quality-validators.js +0 -3
  57. package/dist/commands/read/knowledge.js +3 -3
  58. package/dist/commands/read/remember-cli.js +0 -13
  59. package/dist/commands/read/search-cli.js +29 -97
  60. package/dist/commands/read/search.js +0 -11
  61. package/dist/commands/read/show.js +0 -19
  62. package/dist/commands/sources/plugin-upgrade.js +164 -101
  63. package/dist/commands/sources/sources-cli.js +1 -15
  64. package/dist/commands/sources/stash-cli.js +6 -14
  65. package/dist/commands/tasks/tasks-cli.js +4 -115
  66. package/dist/commands/workflow/plan.js +11 -33
  67. package/dist/commands/workflow-cli.js +2 -7
  68. package/dist/core/adapter/adapter-ids.js +1 -2
  69. package/dist/core/adapter/adapters/agent-skills-adapter.js +0 -4
  70. package/dist/core/adapter/adapters/akm-adapter.js +9 -48
  71. package/dist/core/adapter/adapters/akm-lint.js +10 -26
  72. package/dist/core/adapter/adapters/akm-metadata.js +2 -72
  73. package/dist/core/adapter/adapters/akm-task-adapter.js +0 -5
  74. package/dist/core/adapter/adapters/akm-workflow-adapter.js +9 -28
  75. package/dist/core/adapter/adapters/dotenv-adapter.js +1 -20
  76. package/dist/core/adapter/adapters/generic-files-adapter.js +0 -10
  77. package/dist/core/adapter/adapters/llm-wiki-adapter.js +0 -4
  78. package/dist/core/adapter/adapters/tool-dir-shared.js +0 -24
  79. package/dist/core/adapter/adapters/website-snapshot-adapter.js +4 -4
  80. package/dist/core/adapter/recognize-match.js +3 -4
  81. package/dist/core/common.js +18 -2
  82. package/dist/core/config/config-schema.js +12 -15
  83. package/dist/core/config/config-types.js +6 -15
  84. package/dist/core/config/config-walker.js +6 -23
  85. package/dist/core/config/config.js +17 -80
  86. package/dist/core/config/engine-semantics.js +7 -3
  87. package/dist/core/config/schema/engines.js +7 -7
  88. package/dist/core/config/schema/improve-processes.js +10 -63
  89. package/dist/core/config/schema/improve.js +2 -21
  90. package/dist/core/config/schema/index-config.js +6 -39
  91. package/dist/core/env-secret-ref.js +2 -45
  92. package/dist/core/errors.js +1 -2
  93. package/dist/core/extra-params.js +2 -86
  94. package/dist/core/file-lock.js +12 -7
  95. package/dist/core/improve-result.js +13 -1
  96. package/dist/core/mutation-target.js +2 -2
  97. package/dist/core/paths.js +4 -0
  98. package/dist/core/recognition-util.js +4 -5
  99. package/dist/core/run-lock.js +1 -1
  100. package/dist/core/subprocess.js +49 -0
  101. package/dist/core/warn.js +21 -4
  102. package/dist/core/write-source.js +3 -3
  103. package/dist/execution/target-ref.js +1 -2
  104. package/dist/indexer/indexer.js +15 -6
  105. package/dist/indexer/passes/memory-inference.js +15 -6
  106. package/dist/indexer/search/db-search.js +49 -36
  107. package/dist/indexer/search/fts-query.js +0 -19
  108. package/dist/indexer/search/ranking.js +29 -1
  109. package/dist/indexer/usage/usage-events.js +21 -16
  110. package/dist/integrations/agent/engine-resolution.js +5 -2
  111. package/dist/integrations/agent/index.js +1 -1
  112. package/dist/integrations/agent/profiles.js +41 -98
  113. package/dist/integrations/agent/request-lowering.js +3 -3
  114. package/dist/integrations/harnesses/aider/index.js +5 -0
  115. package/dist/integrations/harnesses/amazonq/index.js +1 -0
  116. package/dist/integrations/harnesses/claude/config-import.js +2 -3
  117. package/dist/integrations/harnesses/claude/index.js +5 -0
  118. package/dist/integrations/harnesses/codex/index.js +1 -0
  119. package/dist/integrations/harnesses/copilot/index.js +1 -0
  120. package/dist/integrations/harnesses/gemini/index.js +1 -0
  121. package/dist/integrations/harnesses/index.js +18 -39
  122. package/dist/integrations/harnesses/opencode/agent-builder.js +60 -35
  123. package/dist/integrations/harnesses/opencode/config-import.js +121 -52
  124. package/dist/integrations/harnesses/opencode/index.js +22 -0
  125. package/dist/integrations/harnesses/opencode/plugin-layout.js +68 -0
  126. package/dist/integrations/harnesses/opencode/session-log-types.js +12 -0
  127. package/dist/integrations/harnesses/opencode/session-log-v1.js +72 -0
  128. package/dist/integrations/harnesses/opencode/session-log-v2.js +140 -0
  129. package/dist/integrations/harnesses/opencode/session-log.js +104 -115
  130. package/dist/integrations/harnesses/opencode/version.js +98 -0
  131. package/dist/integrations/harnesses/opencode-sdk/{harness.js → index.js} +5 -17
  132. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +105 -206
  133. package/dist/integrations/harnesses/opencode-sdk/v1-adapter.js +199 -0
  134. package/dist/integrations/harnesses/opencode-sdk/v2-adapter.js +254 -0
  135. package/dist/integrations/harnesses/opencode-sdk/wire.js +66 -0
  136. package/dist/integrations/harnesses/openhands/index.js +1 -0
  137. package/dist/integrations/harnesses/pi/index.js +1 -0
  138. package/dist/integrations/harnesses/shared.js +2 -0
  139. package/dist/integrations/harnesses/types.js +2 -0
  140. package/dist/llm/client.js +74 -14
  141. package/dist/output/cli-hints.js +1 -1
  142. package/dist/output/context.js +10 -19
  143. package/dist/output/format-exempt.js +5 -8
  144. package/dist/output/shapes/helpers.js +1 -22
  145. package/dist/output/shapes/passthrough.js +0 -1
  146. package/dist/output/shapes.js +3 -31
  147. package/dist/output/stdout.js +5 -1
  148. package/dist/output/text/command-format.js +6 -1
  149. package/dist/output/text/workflow-format.js +4 -22
  150. package/dist/scripts/akm-migrate-node.js +15769 -16731
  151. package/dist/scripts/akm-migrate.js +16339 -17297
  152. package/dist/setup/detect.js +10 -4
  153. package/dist/setup/harness-config-import.js +5 -14
  154. package/dist/setup/setup.js +1 -1
  155. package/dist/setup/steps/tasks.js +12 -13
  156. package/dist/sources/providers/git-stash.js +94 -13
  157. package/dist/storage/repositories/index-utility-repository.js +2 -32
  158. package/dist/storage/repositories/index-vec-repository.js +4 -0
  159. package/dist/storage/repositories/task-history-repository.js +0 -5
  160. package/dist/storage/repositories/workflow-runs-repository.js +5 -15
  161. package/dist/tasks/embedded.js +2 -1
  162. package/dist/tasks/run/run-command-task.js +9 -1
  163. package/dist/tasks/run/run-workflow-task.js +4 -3
  164. package/dist/tasks/run/task-history.js +0 -2
  165. package/dist/tasks/run/task-log.js +38 -1
  166. package/dist/tasks/schedule-gates.js +39 -0
  167. package/dist/tasks/scheduler-binding.js +0 -16
  168. package/dist/tasks/scheduler-sync.js +3 -97
  169. package/dist/tasks/source/bounded-document.js +1 -1
  170. package/dist/tasks/source/task-source-v4.js +2 -12
  171. package/dist/tasks/task-run-reserved-flags.js +2 -31
  172. package/dist/workflows/authoring/authoring.js +6 -6
  173. package/dist/workflows/compile.js +8 -65
  174. package/dist/workflows/exec/child-workflow.js +22 -3
  175. package/dist/workflows/exec/native-executor.js +12 -147
  176. package/dist/workflows/exec/run-workflow.js +31 -103
  177. package/dist/workflows/exec/step-work.js +9 -178
  178. package/dist/workflows/exec/unit-dispatch.js +0 -10
  179. package/dist/workflows/freeze/environment.js +3 -44
  180. package/dist/workflows/freeze/freeze.js +8 -41
  181. package/dist/workflows/freeze/targets/child-workflow.js +27 -63
  182. package/dist/workflows/freeze/targets/command.js +2 -16
  183. package/dist/workflows/freeze/targets/shell.js +0 -2
  184. package/dist/workflows/freeze/task-bindings.js +2 -28
  185. package/dist/workflows/ir/params.js +12 -2
  186. package/dist/workflows/parser.js +82 -232
  187. package/dist/workflows/plan.js +1 -1
  188. package/dist/workflows/renderer.js +10 -19
  189. package/dist/workflows/runtime/run-plan.js +11 -53
  190. package/dist/workflows/runtime/runs.js +4 -27
  191. package/dist/workflows/source-files.js +12 -16
  192. package/dist/workflows/source-semantics.js +1 -93
  193. package/docs/README.md +43 -42
  194. package/docs/agents/README.md +15 -0
  195. package/docs/agents/agent-install.md +14 -0
  196. package/docs/architecture/0.10-process-rules.md +827 -0
  197. package/docs/architecture/README.md +67 -0
  198. package/docs/architecture/adapters.md +258 -0
  199. package/docs/architecture/akm-architecture-decision-history.md +2055 -0
  200. package/docs/architecture/akm-core-principles.md +126 -0
  201. package/docs/architecture/architecture.md +578 -0
  202. package/docs/architecture/comparisons/claude-code-vs-akm-workflows-full.md +550 -0
  203. package/docs/architecture/decisions/0001-no-interpolation-attached-structured-context.md +72 -0
  204. package/docs/architecture/decisions/0002-unit-reuse-and-input-hash-scope.md +142 -0
  205. package/docs/architecture/decisions/0003-child-env-allowlist-and-provenance.md +189 -0
  206. package/docs/architecture/decisions/0004-task-input-contract-and-flag-coercion.md +97 -0
  207. package/docs/architecture/decisions/0005-task-result-vocabulary-and-legacy-read-mapping.md +108 -0
  208. package/docs/architecture/decisions/0006-task-source-version-routing.md +124 -0
  209. package/docs/architecture/decisions/0007-workflow-composition-bounds.md +83 -0
  210. package/docs/architecture/decisions/0008-task-binding-normalization.md +88 -0
  211. package/docs/architecture/decisions/0009-child-run-publication-column-parity.md +80 -0
  212. package/docs/architecture/decisions/0010-driver-protocol-cut.md +36 -0
  213. package/docs/architecture/decisions/0011-engine-run-loop-invariants.md +125 -0
  214. package/docs/architecture/decisions/README.md +62 -0
  215. package/docs/architecture/improvement.md +479 -0
  216. package/docs/architecture/internals/classification.md +154 -0
  217. package/docs/architecture/internals/fresh-host-rebuild-runbook.md +40 -0
  218. package/docs/architecture/internals/functional-contract-patterns.md +340 -0
  219. package/docs/architecture/internals/health-advisories.md +110 -0
  220. package/docs/architecture/internals/improve-workflow.md +719 -0
  221. package/docs/architecture/internals/indexing.md +498 -0
  222. package/docs/architecture/internals/registry-network-boundary.md +57 -0
  223. package/docs/architecture/internals/search.md +248 -0
  224. package/docs/architecture/internals/storage-locations.md +943 -0
  225. package/docs/architecture/persisted-data-compat.md +68 -0
  226. package/docs/architecture/reviews/env-secret-access.md +319 -0
  227. package/docs/architecture/runtime-boundary-design.md +153 -0
  228. package/docs/architecture/specs/0.9.0-close-out-plan.md +361 -0
  229. package/docs/architecture/specs/0.9.0-decisions.md +532 -0
  230. package/docs/architecture/specs/0.9.0-docs-code-drift-register.md +745 -0
  231. package/docs/architecture/specs/0.9.0-open-items-register.md +135 -0
  232. package/docs/architecture/specs/0.9.0-public-api-issue-backlog.md +740 -0
  233. package/docs/architecture/specs/0.9.0-release-surface-review.md +636 -0
  234. package/docs/architecture/specs/agent-command-engine-model-design.md +513 -0
  235. package/docs/architecture/specs/akm-0.9.0-bundle-adapter-spec.md +501 -0
  236. package/docs/architecture/specs/akm-0.9.0-ref-grammar-decision.md +291 -0
  237. package/docs/architecture/specs/akm-format-neutral-bundle-workspace-spec.md +2059 -0
  238. package/docs/architecture/specs/di-seams-plan.md +539 -0
  239. package/docs/architecture/specs/driver-protocol-keep-or-cut.md +275 -0
  240. package/docs/architecture/specs/fact-asset-type.md +142 -0
  241. package/docs/architecture/specs/improve-collapse-churn-detector-design.md +634 -0
  242. package/docs/architecture/specs/okf-support.md +148 -0
  243. package/docs/architecture/specs/ref.md +329 -0
  244. package/docs/architecture/specs/reviews/task-workflow-unification/README.md +72 -0
  245. package/docs/architecture/specs/reviews/task-workflow-unification/findings-consolidated.md +152 -0
  246. package/docs/architecture/specs/reviews/task-workflow-unification/library-eval-alternatives.md +352 -0
  247. package/docs/architecture/specs/reviews/task-workflow-unification/library-eval-bunqueue.md +300 -0
  248. package/docs/architecture/specs/reviews/task-workflow-unification/library-eval-openworkflow.md +402 -0
  249. package/docs/architecture/specs/reviews/task-workflow-unification/opus-review-1.md +758 -0
  250. package/docs/architecture/specs/reviews/task-workflow-unification/opus-review-2.md +645 -0
  251. package/docs/architecture/specs/reviews/task-workflow-unification/opus-review-3.md +602 -0
  252. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r1-adversarial.md +27 -0
  253. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r1-architecture.md +27 -0
  254. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r1-coverage.md +74 -0
  255. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r1-security.md +15 -0
  256. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r2-adversarial.md +132 -0
  257. package/docs/architecture/specs/reviews/task-workflow-unification/panel-r2-verification.md +147 -0
  258. package/docs/architecture/specs/stash-conventions-code-spec.md +275 -0
  259. package/docs/architecture/specs/stash-organization-conventions.md +377 -0
  260. package/docs/architecture/specs/task-workflow-format-unification.md +721 -0
  261. package/docs/architecture/specs/workflow-engine-buy-vs-build.md +231 -0
  262. package/docs/architecture/specs/workflow-format-unification.md +432 -0
  263. package/docs/architecture/testing/manual-testing-checklist.md +3411 -0
  264. package/docs/architecture/testing/okf-v0.2-conformance-runbook.md +924 -0
  265. package/docs/architecture/testing/task-workflow-manual-tests.md +1720 -0
  266. package/docs/architecture/testing/testing-workflow.md +446 -0
  267. package/docs/architecture/workflow-engine.md +223 -0
  268. package/docs/guides/README.md +33 -0
  269. package/docs/guides/author-bundles.md +310 -0
  270. package/docs/guides/author-workflows.md +490 -0
  271. package/docs/guides/bundles.md +323 -0
  272. package/docs/guides/capture-knowledge.md +136 -0
  273. package/docs/guides/claude-code-vs-akm-workflows.md +29 -0
  274. package/docs/guides/concepts.md +93 -0
  275. package/docs/guides/discover-and-load.md +158 -0
  276. package/docs/guides/getting-started.md +240 -0
  277. package/docs/guides/improve-the-library.md +247 -0
  278. package/docs/guides/knowledge-management.md +18 -0
  279. package/docs/guides/recipes/headless-install.md +97 -0
  280. package/docs/guides/recipes/website-source.md +28 -0
  281. package/docs/guides/run-workflows.md +279 -0
  282. package/docs/guides/scheduling.md +131 -0
  283. package/docs/guides/use-with-any-agent.md +174 -0
  284. package/docs/guides/wikis.md +81 -0
  285. package/docs/integration/bundling-akm.md +7 -6
  286. package/docs/maintainers/README.md +19 -0
  287. package/docs/maintainers/curate-workmap.md +335 -0
  288. package/docs/maintainers/eval.md +3 -0
  289. package/docs/maintainers/local-development.md +108 -0
  290. package/docs/maintainers/release-checklist.md +135 -0
  291. package/docs/migration/README.md +4 -2
  292. package/docs/migration/release-notes/0.0.13.md +1 -1
  293. package/docs/migration/release-notes/0.1.0.md +1 -1
  294. package/docs/migration/release-notes/0.10.0.md +201 -0
  295. package/docs/migration/release-notes/0.2.0.md +1 -1
  296. package/docs/migration/release-notes/0.3.0.md +1 -1
  297. package/docs/migration/release-notes/0.5.0.md +1 -1
  298. package/docs/migration/release-notes/0.6.0.md +1 -1
  299. package/docs/migration/release-notes/0.7.0.md +1 -1
  300. package/docs/migration/release-notes/0.7.3.md +2 -2
  301. package/docs/migration/release-notes/0.7.4.md +1 -1
  302. package/docs/migration/release-notes/0.7.5.md +1 -1
  303. package/docs/migration/release-notes/0.8.0.md +1 -1
  304. package/docs/migration/release-notes/0.9.0.md +1 -1
  305. package/docs/migration/release-notes/0.9.14.md +1 -1
  306. package/docs/migration/release-notes/0.9.15.md +1 -1
  307. package/docs/migration/release-notes/0.9.16.md +1 -1
  308. package/docs/migration/release-notes/0.9.17.md +1 -1
  309. package/docs/migration/release-notes/0.9.19.md +1 -1
  310. package/docs/migration/release-notes/0.9.2.md +1 -1
  311. package/docs/migration/release-notes/README.md +28 -31
  312. package/docs/migration/v0.5-to-v0.6.md +759 -0
  313. package/docs/migration/v0.8-to-v0.9.md +1 -1
  314. package/docs/migration/v0.9-to-v0.10.md +507 -0
  315. package/docs/plans/0.9.2-agent-command-workflow-plan.md +423 -0
  316. package/docs/posts/README.md +30 -0
  317. package/docs/posts/akm-command-tour.md +495 -0
  318. package/docs/posts/akm-logo-sized.webp +0 -0
  319. package/docs/posts/belief-aware-memory-12.md +139 -0
  320. package/docs/posts/config-v2-lessons-16.md +191 -0
  321. package/docs/posts/improve-loop-autonomous-10.md +225 -0
  322. package/docs/posts/improve-pipeline-debugging-0803.md +179 -0
  323. package/docs/posts/intro-part-01.md +76 -0
  324. package/docs/posts/intro-part-02.md +221 -0
  325. package/docs/posts/intro-part-03.md +190 -0
  326. package/docs/posts/intro-part-04.md +221 -0
  327. package/docs/posts/llm-mode-reflect-13.md +166 -0
  328. package/docs/posts/openpalm-built-on-akm.md +86 -0
  329. package/docs/posts/progressive-disclosure-06.md +129 -0
  330. package/docs/posts/proposal-safety-net-15.md +112 -0
  331. package/docs/posts/release-0.5.0.md +247 -0
  332. package/docs/posts/release-0.6.0.md +117 -0
  333. package/docs/posts/release-0.7.0.md +159 -0
  334. package/docs/posts/release-0.8.0.md +332 -0
  335. package/docs/posts/scattered-skills-05.md +100 -0
  336. package/docs/posts/task-assets-persistent-workflows-11.md +222 -0
  337. package/docs/posts/team-skills-07.md +198 -0
  338. package/docs/posts/wiki-agent-knowledge-08.md +223 -0
  339. package/docs/posts/workflows-vaults-09.md +321 -0
  340. package/docs/product-surface.md +54 -0
  341. package/docs/reference/README.md +2 -2
  342. package/docs/reference/api.md +65 -0
  343. package/docs/reference/asset-types.md +166 -0
  344. package/docs/reference/bundle-types.md +2 -4
  345. package/docs/reference/cli.md +163 -192
  346. package/docs/reference/configuration.md +101 -20
  347. package/docs/reference/data-and-telemetry.md +2 -2
  348. package/docs/reference/env-and-secrets.md +126 -0
  349. package/docs/reference/memory.md +124 -0
  350. package/docs/reference/refs.md +156 -0
  351. package/docs/reference/registry.md +489 -0
  352. package/docs/reference/supported-formats.md +3 -4
  353. package/docs/reference/tasks.md +12 -19
  354. package/docs/reference/website-sources.md +141 -0
  355. package/docs/reference/workflow-schema.md +89 -317
  356. package/docs/reference/workflows.md +20 -48
  357. package/package.json +23 -16
  358. package/schemas/akm-config.json +2 -243
  359. package/schemas/akm-task.json +2 -3
  360. package/schemas/akm-workflow.json +47 -84
  361. package/dist/assets/improve-strategies/catchup.json +0 -41
  362. package/dist/assets/improve-strategies/proactive-maintenance.json +0 -24
  363. package/dist/assets/improve-strategies/quick.json +0 -17
  364. package/dist/assets/improve-strategies/reflect-distill.json +0 -29
  365. package/dist/assets/improve-strategies/thorough.json +0 -49
  366. package/dist/assets/prompts/retrieval-relevance-judge.md +0 -6
  367. package/dist/assets/tasks/improve/akm-improve-catchup.yml +0 -6
  368. package/dist/assets/tasks/improve/akm-improve-frequent.yml +0 -4
  369. package/dist/assets/tasks/improve/akm-improve-nightly.yml +0 -4
  370. package/dist/cli/retired-commands.js +0 -118
  371. package/dist/commands/improve/retrieval-gate.js +0 -132
  372. package/dist/commands/tasks/validate.js +0 -176
  373. package/dist/core/config/legacy-source-shape-shim.js +0 -117
  374. package/dist/indexer/feedback/utility-policy.js +0 -75
  375. package/dist/integrations/harnesses/ids.js +0 -28
  376. package/dist/tasks/source/task-source-v3-frozen.js +0 -424
  377. package/dist/tasks/source/task-to-v4.js +0 -863
  378. package/dist/workflows/exec/worktree.js +0 -372
  379. package/dist/workflows/freeze/child-output-references.js +0 -83
  380. package/dist/workflows/freeze/identity.js +0 -22
  381. package/dist/workflows/freeze/targets/script.js +0 -50
  382. package/dist/workflows/freeze/targets/task.js +0 -124
  383. package/dist/workflows/github-yaml.js +0 -506
  384. package/dist/workflows/runtime/run-outputs.js +0 -80
@@ -0,0 +1,479 @@
1
+ # Architecture: The Improvement Loop
2
+
3
+ ## Purpose and boundary
4
+
5
+ The improvement loop turns outcomes into ranking changes and reviewable proposals. This page is the
6
+ architecture-level reference for that loop — how a feedback signal becomes a
7
+ ranking change, how ranking and usage evidence become a proposal, and the
8
+ boundary around what AKM is allowed to write without a human or policy
9
+ reviewing the diff first.
10
+
11
+ The loop itself:
12
+
13
+ ```text
14
+ agent selects capability -> agent records outcome -> AKM updates utility and analyzes evidence ->
15
+ AKM creates a proposal -> human or policy reviews the diff -> accept / reject / revert
16
+ ```
17
+
18
+ The user-facing command surface for this loop (`akm feedback`, `akm log`,
19
+ `akm improve`, `akm proposal ...`) is documented in
20
+ [Improve the Library](../guides/improve-the-library.md) and
21
+ [CLI Reference](../reference/cli.md). This page covers the implementation
22
+ detail behind those commands: how utility moves, how strategies configure
23
+ what runs, what the autonomy gate does and does not allow, how sync happens
24
+ at the end of a run, and how session extraction fits in.
25
+
26
+ **Boundary:** `akm improve` (and its subprocesses — reflect, distill,
27
+ consolidate) never write asset files directly. The only durable artifact they
28
+ produce is a proposal row in `state.db`. The narrow set of writes that *are*
29
+ allowed to happen without review is enumerated below, under
30
+ [The autonomy gate](#the-autonomy-gate);
31
+ everything else routes through `akm proposal accept`.
32
+
33
+ ## Components
34
+
35
+ - **Utility recompute** (`recomputeUtilityScores`, `src/indexer/indexer.ts`) —
36
+ the one place utility is computed from `usage_events`; `akm index` runs it
37
+ for every entry and `akm feedback` for the entry it touched.
38
+ - **Strategies** (`src/commands/improve/improve-strategies.ts`,
39
+ `src/assets/improve-strategies/*.json`) — named presets that decide which
40
+ improve processes run and with what engine/model/limits.
41
+ - **Autonomy gate** (`src/commands/improve/autonomy-gate.ts`) — downgrades
42
+ the handful of processes that would otherwise mutate assets without review
43
+ (memory inference, memory cleanup, and a judged triage promote), unless
44
+ `experimental.improveAutonomy` is explicitly set.
45
+ - **Reflect / distill / consolidate subprocesses** — the improve pipeline's
46
+ proposal generators, invoked per asset (reflect, distill) or across the
47
+ whole memory corpus (consolidate). See
48
+ [Improve Workflow](internals/improve-workflow.md) for the full per-step
49
+ reference and flow diagram.
50
+ - **Proposal queue** (`state.db`) — written by `createProposal` (reflect,
51
+ distill, consolidate's promote operations, and the other proposal producers)
52
+ and by `createRetireProposal` (the pair pass's retire proposals).
53
+ - **Auto-sync** — the pre-run sync and the end-of-run commit/push step for git-backed bundles.
54
+ - **Session extraction** (`akm proposal extract`) — a separate entry point
55
+ that mines coding-agent session transcripts for durable insights and queues
56
+ them the same way.
57
+
58
+ ## Data flow
59
+
60
+ 1. An agent uses a capability and calls `akm feedback <ref> --positive|--negative`.
61
+ `--negative` is for content that is wrong or stale; a note that simply did
62
+ not fit the agent's task gets no feedback.
63
+ `--negative --reason "<what is wrong and what should change>"` flags the
64
+ asset: the next improve run may repair its frontmatter from the reason.
65
+ `--replace`/`--with`/`--source` attach an exact fix of its text once the
66
+ agent has verified the correct fact, which akm checks and applies at once
67
+ through a `feedback` proposal it accepts on the spot (no review).
68
+ `--positive` records that the asset helped (it raises its ranking) and does
69
+ not trigger a rewrite.
70
+ 2. The feedback event is appended to `state.db`. `akm search` and `akm curate`
71
+ count a user's recorded positives and negatives per asset and scale the
72
+ fused score by them (logarithmic in each count, the same for every asset),
73
+ so ranking moves at once with no reindex. The asset's utility score, which
74
+ improve and metrics read, is recomputed immediately by the same formula
75
+ `akm index` uses (below).
76
+ 3. `akm improve` selects assets from the one bundle it writes to. A rewrite
77
+ (reflect) is planned only for an asset with negative feedback in the last
78
+ 30 days that is newer than the stage's last attempt, or for an explicit ref;
79
+ a positive or note-only signal never plans one, and neither does a negative whose exact fix has since been accepted as a `feedback` proposal. Distill reads any feedback
80
+ on a memory in that window, but skips a memory flagged wrong and not edited
81
+ since: a negative feedback in the window judged the body it still has (or,
82
+ recorded without that body's hash, is newer than its file's last write). It
83
+ also skips a memory whose only feedback in the window is positive with no
84
+ reason or note, which gives the writer nothing to distil (10 of the 11
85
+ lessons made from such memories were rejected). Unless
86
+ `--require-feedback-signal` is set, the
87
+ proactive-maintenance lane (where the strategy enables it, as `default`
88
+ does) adds the stable assets due for a revisit that the retrieval scope below
89
+ admits, and plans them with the feedback-bearing ones. At most `maxPerRun`
90
+ (15) assets are picked per run, an asset is due only if not reflected or
91
+ distilled for `dueDays` (30), and reflect's `limit` (25) bounds the run. It ranks the selected assets by salience, applies the limit, then
92
+ runs whichever processes the selected strategy enables against each one (see
93
+ [Improve Workflow](internals/improve-workflow.md#ledger-pre-filter-signal-delta)).
94
+ 4. Reflect and distill each emit at most one proposal per asset per run;
95
+ consolidate runs two passes alongside each other — the promote pass emits
96
+ a proposal turning a memory into knowledge (and, once accepted, retires
97
+ the source memory) unless a neighbouring `knowledge/` doc already covers
98
+ the memory, and it offers a memory whose promotion was accepted or
99
+ rejected, or that the model judged and left alone, again only after the
100
+ memory's body changes; the pair pass judges
101
+ near-duplicate and superseding pairs in the memory tier and emits a
102
+ `retire` proposal for the `duplicate`/`subsumed`/`supersedes` classes;
103
+ `overlap`, `unrelated` and `contradicts` are recorded as
104
+ `judged_no_action` with no proposal. The judge first lists the durable
105
+ claims each side alone holds, and a side with any listed claim is never
106
+ retired. Knowledge is never retired in favour of a memory: when the judge would
107
+ do that, the memory is retired in favour of the note if the memory lists no claim of its own,
108
+ and the pair is left alone otherwise. A retirement whose retired side lists nothing (a duplicate: neither
109
+ side), confirmed by a second look, is staged for the triage drain to accept; every other
110
+ retirement waits for a person.
111
+ 5. Every emitted proposal lands in the `proposals` table in `state.db`,
112
+ status `pending`.
113
+ 6. A human (via `akm proposal diff` / `accept` / `reject`) or a configured
114
+ drain policy (`akm proposal drain`) reviews and resolves each proposal. A
115
+ rejection is not final: `akm proposal reopen` puts a rejected proposal back
116
+ to `pending`.
117
+ 7. `akm proposal accept` promotes the proposal into the bundle; `akm proposal
118
+ revert` restores the prior content from the backup captured at promotion
119
+ time, if the proposal overwrote an existing asset. When the bundle is a git
120
+ repository (a `.git` directory, whatever its source kind), each accept is
121
+ committed as it happens, locally and with exactly the paths it wrote or
122
+ removed: `akm accept: <generator> <proposal-id-8> <ref>`. A retirement's
123
+ archived copy and tombstone, and the source memory a consolidate promotion
124
+ retires, go in the same commit. A commit that fails warns and the accept
125
+ stands.
126
+ 8. For a git-backed bundle, `akm improve`'s end-of-run auto-sync commits the
127
+ rest of the run's changes as a single batch and pushes (see below). The run
128
+ began with the same sync, so it started from what other hosts had pushed.
129
+
130
+
131
+ ## Current decisions
132
+
133
+ ### Utility scoring
134
+
135
+ Utility has one formula and one implementation, `recomputeUtilityScores`
136
+ (`src/indexer/indexer.ts`), counting only user-attributed (`source='user'`)
137
+ events:
138
+
139
+ ```text
140
+ rate = max(selectRate, max(0, positives - negatives) / (positives + negatives))
141
+ nextUtil = prevUtil * 0.7^days + rate * (1 - 0.7^days)
142
+ ```
143
+
144
+ `akm index` runs it for every entry. `akm feedback` runs the same function for
145
+ the one entry it touched, so the value it stores is the one the next index
146
+ would compute at that moment (a one-entry call skips the usage-event purge
147
+ and leaves the recompute watermark alone). `days` is the time since the last
148
+ full recompute, at least 1, so decay is time-proportional rather than tied to
149
+ index frequency. When a previously high-utility asset (utility >= 0.5) falls
150
+ below 0.5 after feedback, an `improve_review_needed` event is emitted. Usage
151
+ history (and the utility it drives) is preserved across schema resets and full
152
+ index rebuilds - see [Architecture: Utility Scoring](architecture.md#utility-scoring)
153
+ for the storage-level summary.
154
+
155
+ ### Strategy inheritance
156
+
157
+ Improve presets live under `improve.strategies` (config) and the built-in
158
+ set: `default` and `consolidate` (`src/assets/improve-strategies/*.json`). The removed `quick`, `thorough`,
159
+ `catchup`, `reflect-distill` and `proactive-maintenance` still work as user-defined strategies. Selection
160
+ order is `--strategy`, then `defaults.improveStrategy`, then `default`.
161
+
162
+ Resolution is a two-step deep merge (`resolveImproveStrategy`): a named
163
+ built-in strategy is first merged onto the built-in `default` strategy, then
164
+ any user-defined override for that same name (under `improve.strategies` in
165
+ config) is merged on top. So a strategy — built-in or user-defined — that
166
+ omits a field, or an entire process block, inherits it from `default`; an
167
+ explicit `enabled: true`/`false` in the more specific layer always wins. This
168
+ is why, for example, `proactiveMaintenance` is on in `default` and off in
169
+ `consolidate`, and a preset that doesn't mention it at all inherits the
170
+ `default` value. A user-defined strategy named `proactive-maintenance` (the name
171
+ of the retired built-in) resolves the same way, merged onto `default`.
172
+
173
+ ### Retrieval scope
174
+
175
+ Improve reworks only what gets read (#986). Fresh feedback and an explicit ref
176
+ scope (`akm improve skills/x`) are usage evidence of their own. Every other
177
+ pick — the proactive-maintenance lane, and the memories consolidation judges — must be in the retrieval
178
+ scope (`src/commands/improve/retrieval-scope.ts`):
179
+
180
+ - **Retrieved:** a user-attributed `search`, `curate` or `show` returned the
181
+ asset, or user `feedback` named it, inside the window. A hit on a
182
+ `.derived` memory counts for its parent. Machine traffic (`improve`, `task`,
183
+ `audit`) does not count.
184
+ - **New material:** the file was written inside the window and no improve
185
+ stage has processed the asset — no `improve_ledger` row and no proposal from
186
+ any source but a capture (`extract`, `propose`, `remember`, `import`).
187
+
188
+ The window is the usage log's retention (`USAGE_EVENT_RETENTION_DAYS`, 90
189
+ days): the log keeps nothing older, and a shorter window would drop assets
190
+ read less often than it. There is no config key. Refs left out are counted by
191
+ the plan's `retrieval` gate and reported as the `not_retrieved` skip reason;
192
+ consolidation reports them in its warnings. A bulk rewrite of old files
193
+ (a rename, a lint fix, a fresh clone) makes them look new until improve has
194
+ processed each once.
195
+
196
+ ### Quality judge
197
+
198
+ Every reflect revision and every distilled lesson is scored by a judge before it
199
+ is queued (`runQualityJudge`, `src/commands/improve/stage.ts`): one call at
200
+ temperature 0, each criterion scored 1 to 5, failing closed (no runner, a
201
+ timeout, or an unparseable or incomplete reply never passes content and goes to
202
+ review). A reflect revision is scored on three criteria:
203
+
204
+ - **need**: does it fix a concrete problem in the source: something the
205
+ feedback reports as wrong or missing, a factual error, or broken, garbled,
206
+ truncated or missing text (frontmatter fields included)? A rewrite that only
207
+ rewords, restates or reformats a correct source, or adds headings, an
208
+ introduction or a table of contents, scores 1 or 2.
209
+ - **preservation**: does it keep every concrete fact, identifier, command, path,
210
+ number and example, without truncation?
211
+ - **quality**: is it coherent and accurate, with nothing the source or the
212
+ feedback does not support?
213
+
214
+ Content passes only when **every** criterion scores 4 or more (a lesson's
215
+ grounding is judged apart, see
216
+ [distill](internals/improve-workflow.md#distill-akmdistill)); a mean of 3.5
217
+ passed it before. A verdict that does not pass is a review when its mean is 2.5
218
+ or more and a rejection below that. Reflect narrows that band: a revision whose
219
+ mean is 3.5 or more is queued for a person (reason `judge-uncertain`, with the
220
+ `scores` and `judgeReason`) and records no rejection window, and a lower mean is
221
+ refused. On 113 reviewed frontmatter-only proposals (lab 27B Q2, the shipped
222
+ judge) the non-passing ones at 3.5 or more were 17 good and 9 bad, the rest 1
223
+ good and 2 bad; on 396 labelled body rewrites a mean below 3.5 was good 6 times
224
+ in 291 (the constant and its sources are in `src/commands/improve/reflect.ts`). The rubric and the rule were chosen on 90
225
+ labelled real rewrites, where judging on the mean let rewrites that only
226
+ reworded a correct asset through.
227
+
228
+ A reflect pass is stamped on the proposal as a `staged` decision from the
229
+ `quality-gate` with the per-criterion `scores` and the judge's `judgeReason`;
230
+ both stay on the proposal when the drain accepts it, so a later audit can read
231
+ why it passed (`akm proposal show --format json`). A distill pass is not staged:
232
+ the lesson or promotion is minted `deferred` for a person (reason
233
+ `distill-review`, same gate) with the same `scores` and `judgeReason`, and the
234
+ triage drain and its judgment tier leave it alone. A lesson that repeats an existing
235
+ lesson may instead be proposed as an update of that lesson (reason
236
+ `distill-update`, same gate), with only what the memory adds; the drain leaves
237
+ it for a person too. On 2026-10-05 the gate had
238
+ staged 12 lessons and 10 were bad (they restated the memory, claimed what it
239
+ does not say, or filed a dated status as a lesson), and no score separated them
240
+ from the two good ones. Reflect revises only an asset's
241
+ `description`, `when_to_use` and title, never its body. On 396 labelled edits,
242
+ those that fixed a frontmatter defect and left the body alone were good 24
243
+ times in 26, and those that also rewrote the body were bad 175 times in 224.
244
+
245
+ ### Judgment tier: promotions only
246
+
247
+ The triage drain's judgment tier (`processes.triage.judgment`, off in every
248
+ built-in strategy) may accept only a consolidate promotion, a memory proposed as
249
+ a new knowledge note. A retirement or a reflect revision it would
250
+ accept is left for a person (`judgment-not-promotion`); it may still reject.
251
+ Measured on the nightly eval with `experimental.improveAutonomy` (#1132, #1094),
252
+ judging every kind solved 0.49 (gpt-5.6-terra) and 0.53 (qwen3.8-27b) of the
253
+ items, harmed 14 and 11, and changed 18 and 21 notes outside the planted set.
254
+ Judging promotions alone: precision 0.87, recall 0.78 and 4.8% of bad promotions
255
+ accepted on qwen3.8-27b; precision 1.0, recall 0.17 on gpt-5.6-terra.
256
+
257
+ ### Proactive-lane proposals wait for a person
258
+
259
+ A proposal planned by the proactive-maintenance lane (`eligibilitySource:
260
+ "proactive"`, an asset with no feedback behind it) is never accepted by the
261
+ drain, whether a deterministic gate (a staged quality-judge pass), the judgment
262
+ tier or an accept staged by an earlier drain would take it. It is left for a
263
+ person with reason `proactive-needs-review`, and the judgment tier does not see
264
+ it. An empty diff is still rejected. Proposals driven by feedback (`signal-delta`,
265
+ `scope`) follow the one rule unchanged (#1147).
266
+
267
+ ### Retirement continuity
268
+
269
+ Before the consolidate pair pass mints a `retire` proposal (rule R3,
270
+ `src/commands/improve/consolidate/continuity-check.ts`), it replays up to five
271
+ of the retired asset's own past `search`/`curate` queries
272
+ (`loadRetrievalQueries`, `../retrieval-queries.ts` — boilerplate, harness/tool envelopes,
273
+ pastes and near-duplicates dropped before replay, S3a) through akm's own
274
+ search, in-process — the ranking a user actually gets, no LLM. For every
275
+ query where the retired asset ranked in the top 10, the successor must too
276
+ (N2: compared directly — search itself returns at most the top 10 hits, so
277
+ "ranked" and "absent from those hits" are the only two states there are, no
278
+ generic rank-change-report abstraction needed). An asset with no recorded
279
+ queries is not checked at all, and neither is a pair whose two bodies are
280
+ content-identical once whitespace is collapsed (S3b) — search's own
281
+ content-dedupe already hides the successor behind the retired asset for
282
+ every such query, so a "successor missing" finding there would not be a
283
+ real risk.
284
+
285
+ A failing pair still mints — the check flags, it never blocks — but the
286
+ proposal carries `continuityRisk` in its retirement metadata: the failing
287
+ query count and the rank pairs, visible in `akm proposal show`/`list`/`diff`. A
288
+ flagged proposal is excluded from every bulk accept path (`accept
289
+ --generator …`, with or without `--yes`); a person can still accept it by id.
290
+ Bulk *reject* is unaffected, since declining a flagged proposal is always the
291
+ safe direction.
292
+
293
+ A query that never ran (the search call threw) or that fell back to
294
+ keyword-only ranking instead of the real one (`mode: "fts-fallback"` — most
295
+ often a down or unreachable embedding endpoint) is "unverified": it is never
296
+ compared for rank at all, and on its own it is enough to set
297
+ `continuityRisk` (`unverifiedQueries` alongside the usual `ranks`), so an
298
+ endpoint outage reads as "risk unknown," never as the silent "no risk
299
+ found" a search that quietly used a degraded ranking would otherwise
300
+ produce. Once any query in a pair-pass run falls back, every later query in
301
+ that same run skips the semantic attempt entirely and goes straight to
302
+ keyword-only — a dead endpoint costs one failed attempt for the whole run,
303
+ not one per remaining query.
304
+
305
+ This check replaces the old per-run forgetting-safety lane (a one-time WS-1
306
+ cutover guard that compared improve's own salience ranking before and after
307
+ each run). The 30-day event window showed it made no pick the signal-delta
308
+ lane or the retrieval scope would not also have made, and it protected
309
+ `asset_salience.rank_score`, which only improve itself ever read — a rank drop
310
+ could not hide anything from search. `forgetting-safety` stays a valid
311
+ `eligibilitySource`/event-type value so old proposals and events still decode,
312
+ but nothing assigns or emits it any more.
313
+
314
+ ### Dry-run planning boundary
315
+
316
+ Dry and live improve runs call the same selectors for signal-delta eligibility,
317
+ the proactive-maintenance lane, the retrieval scope, salience ranking, disk presence, and the
318
+ final cap, and resolve the bundle they plan the same way: `--bundle`, else
319
+ `defaultWriteTarget`, else the working bundle (`AKM_BUNDLE_DIR`, else
320
+ `defaultBundle`). Each invocation reports a best-effort observation assembled
321
+ while it runs; it is not an atomic cross-store snapshot, a reservation, or a
322
+ durable frozen plan. A later live invocation re-inspects mutable index, state,
323
+ filesystem, and session-log inputs and can therefore differ from an earlier
324
+ dry preview. Given equivalent observed inputs, both paths produce the same
325
+ selection. The public schema-v2 result projects the observation as `plan`: raw
326
+ in-scope count, each gate's removals, configured and effective limits, final
327
+ ranked refs with lane attribution, proactive due statistics, consolidation
328
+ pool/delta/minimum gates and chunk estimate, maintenance-stage decisions,
329
+ triage mode/caps, and the read-side index snapshot status. `plannedRefs` means
330
+ the effective post-limit work set in both modes.
331
+
332
+ The dry path stops at that projection boundary. It may read indexed assets,
333
+ the filesystem, and an existing `state.db`, but opens state read-only and does
334
+ not create it when absent. It does not acquire the improve lock or write the
335
+ index, state, events, proposals, assets, cache, sync journal, or persisted run
336
+ result, and it never dispatches an LLM. SQLite inputs are inspected through
337
+ disposable main/WAL copies so even a held source SHM file is not touched.
338
+ Consolidation pool inspection and the extract `minNewSessions` gate use shared
339
+ zero-LLM selectors, while live execution re-inspects mutable inputs immediately
340
+ before dispatch. A missing index or one without the current `entries` table
341
+ yields an explicit empty `plan.snapshot` (`missing` or `incompatible`) rather
342
+ than creating or migrating the database.
343
+
344
+ `plan.limits.effective` is the cap on the refs a run dispatches, resolved from
345
+ `--limit`, then the reflect process's `limit`, then the strategy's `limit`. The
346
+ replay lane is retired, so `additiveReplayAllowance` is always `0` (the field
347
+ stays so the schema-v2 plan shape keeps validating) and a finite `totalCeiling`
348
+ equals `effective`. When the run is unbounded, `totalCeiling` is omitted.
349
+
350
+ ### The autonomy gate
351
+
352
+ `akm improve` runs by default and is review-first: reflect, distill, extract
353
+ candidates, validation, and proactive-maintenance selection are proposal-only
354
+ and never write assets directly regardless of this gate.
355
+ Three specific lanes *would* mutate assets without review and are downgraded
356
+ unless `experimental.improveAutonomy` is explicitly set to `true` (the triage
357
+ lane only when its judgment tier is on; see below):
358
+
359
+ | Lane | What it does when enabled | With autonomy off |
360
+ | --- | --- | --- |
361
+ | `memoryInference` | Writes `.derived.md` children and rewrites parent frontmatter | disabled |
362
+ | memory cleanup | Belief-state frontmatter rewrites, archive moves | analyzed but not applied |
363
+ | `triage` `applyMode: "promote"` **with judgment on** | The judgment tier auto-accepts consolidate promotions into the bundle | downgraded to `queue` — triage still runs, it just does not auto-accept |
364
+
365
+ A deterministic-only `promote` (triage with judgment off) is not gated (#1143):
366
+ the `default` strategy drains the queue through the deterministic gates, up to
367
+ `maxAcceptsPerRun` (200) per run, with no opt-in. The nightly eval's baseline is
368
+ exactly this path (`proposal drain --promote` without judgment): 0.91 (terra) and
369
+ 0.89 (qwen) of items solved, 0 to 1 harmed.
370
+
371
+ Every downgrade is reported, not silent: it warns on stderr, appends an
372
+ `improve_skipped` event with `reason: "autonomy_gated"`, and is counted in
373
+ `akm health`'s improve skip-reason summary. Consolidation stays enabled with
374
+ autonomy off: both its passes only ever emit a reviewable proposal. The one
375
+ pair-pass `retire` proposal `triage` `applyMode: "promote"` accepts is a
376
+ retirement the pair pass staged (nothing unique to the retired side, confirmed
377
+ by a second look, no continuity risk); every other one waits for `akm proposal accept`. An absent `experimental`
378
+ section, an absent key, and an explicit `false` all read identically as off —
379
+ autonomy is never inferred. `akm proposal drain --promote` is a second,
380
+ explicit promote surface independent of this gate.
381
+
382
+ ### Auto-sync
383
+
384
+ For git-backed bundles (detected by a `.git` directory), `akm improve` syncs
385
+ twice: once **before** the run and once at the end. Both are the same operation
386
+ as `akm sync` — fetch and merge the upstream, commit, and push if the bundle is
387
+ writable, per the active strategy's `sync` setting. A user-defined strategy can
388
+ turn sync off, so an interrupted run does not leave an uncommitted backlog.
389
+ `--no-sync` disables both for a single run; `--no-push` commits without pushing.
390
+ Strategy sync behavior is configured via the `sync` block under
391
+ `improve.strategies.<name>`.
392
+
393
+ The pre-run sync runs right after the run takes its lock and before the index
394
+ and plan stages, so they see what another host pushed. It stages what `akm sync`
395
+ stages (the managed paths, or the content subdirectory of a repo whose content
396
+ lives in one), which means pending hand edits there are committed (and pushed)
397
+ before the run starts, not mistaken for the run's own writes. It never aborts
398
+ the run: a merge that conflicts (aborted, local commit kept), a failed fetch, or
399
+ any other error is a warning, and the run continues on the local state. The
400
+ outcome is `preRunSync` on the result (same shape as `sync`) and a `stash_synced`
401
+ event with `phase: "pre-run"`. A dry run does not sync. Scheduled `core/improve`
402
+ and `akm-improve-consolidate` runs go through the same `akm improve` entry, so
403
+ they get it too.
404
+
405
+ The sync always commits the paths it is given. It then fetches the remote and
406
+ brings the upstream in (a fast-forward when it can, otherwise git's default
407
+ merge) before it pushes, so a second host that pushed first does not stop the
408
+ push. A branch it cannot push (no upstream branch, a failed fetch, or a merge
409
+ that conflicts, which is aborted with the local commit kept) only skips the push,
410
+ and the result says why: `sync.reason` reads `not pushed: ...`. A push the remote
411
+ refuses after the commit landed still reports `sync.committed: true`. A branch that is
412
+ ahead of its upstream, as it is after the accept commits above, is pushed with
413
+ the sync commit. A clean tree that is ahead is not pushed: the sync pushes what
414
+ it commits.
415
+
416
+ The commit is scoped by **write provenance**, not by directory: every akm write
417
+ path records the file it mutated into a run-scoped journal
418
+ (`src/core/write-provenance.ts`), and the end-of-run sync stages exactly the
419
+ journaled paths that Git still reports as changed. A file someone else edits
420
+ under a managed directory while the run is in flight is therefore left dirty for
421
+ its author, while a file that was already dirty when the run started and was
422
+ then rewritten by the run IS committed. Deletions are journaled like writes, so
423
+ the final on-disk state is what lands — a path written and then reverted or
424
+ purged produces no commit at all. The run reports its journal as
425
+ `writtenPaths` on the improve result. Callers that supply no explicit path list
426
+ (`akm sync`, `akm push`) keep the managed-pathspec fallback in `saveGitStash`.
427
+
428
+ ### Archive purge
429
+
430
+ A retirement's archived bytes (`.akm/memory-cleanup/archive/<stamp>-<ref>/`)
431
+ are not deleted at accept time — only the tombstone (`cleanup.md`) resolves
432
+ the ref going forward. `purgeGracedArchive`
433
+ (`src/commands/improve/memory/memory-improve.ts`) sweeps them later: run once
434
+ at the very start of every `akm improve` invocation, deterministic, no LLM,
435
+ before index bootstrap or triage. For a git-backed bundle, it deletes the
436
+ archived asset file(s) — never `cleanup.md` — of every retirement whose
437
+ tombstone `retiredAt` is more than 30 days old (`RETIRE_GRACE_DAYS`) AND
438
+ whose archive directory is entirely git-tracked and clean (`git ls-files`
439
+ plus `git status --porcelain -uall`, both checked once per sweep, not once
440
+ per directory). `.git` presence alone does not guarantee a retirement was
441
+ ever committed: an accept commits its own paths (`commitAcceptedPaths` in
442
+ `src/core/write-source.ts`), on a `kind: "filesystem"` source with a `.git`
443
+ directory too, but a commit that failed only warned, and a retirement accepted
444
+ by an older akm left archived bytes sitting on disk with no commit behind them
445
+ at all. A directory with even one untracked or modified file (the tombstone
446
+ included) is left whole for a later sweep, so the purge only ever removes
447
+ bytes git can already recover. Every deleted path is journaled individually,
448
+ so the end-of-run auto-sync commits the removal the same way it commits the
449
+ archive move itself. A bundle with no `.git` of its own has no history to
450
+ fall back on, so its archive is left untouched — `akm health` reports its
451
+ size and file count instead (`memory-cleanup-archive` advisory,
452
+ `src/commands/health/archive-usage.ts`).
453
+
454
+ ### Session extraction
455
+
456
+ `akm proposal extract` is the standalone entry point for mining coding-agent
457
+ session transcripts (`--type claude`, `--type codex`, `--type opencode`, or
458
+ `--auto` to iterate every harness with a detectable session-log location) into
459
+ proposals.
460
+ It replaced the legacy session-checkpoint hook and runs independently of
461
+ whether a strategy's own `processes.extract` stage is enabled — no shipped
462
+ strategy turns that improve-stage extraction on, and a direct
463
+ `akm proposal extract --type <harness>` or `--auto` invocation is never gated
464
+ by that toggle. Session indexing writes are additive
465
+ (`sessions/**`), which is why they are one of the writes left deliberately
466
+ ungated by the autonomy gate above.
467
+
468
+ ## See also
469
+
470
+ - [Improve the Library](../guides/improve-the-library.md) — the user-facing
471
+ command guide for this loop
472
+ - [Improve Workflow](internals/improve-workflow.md) — full per-step reference
473
+ and flow diagram for reflect/distill/consolidate
474
+ - [Architecture](architecture.md) — system-wide architecture summary,
475
+ including the Utility Scoring and Writing to Sources sections
476
+ - [Configuration Reference — Strategies](../reference/configuration.md#strategies)
477
+ and [Experimental opt-ins](../reference/configuration.md#experimental-opt-ins)
478
+ - [STABILITY.md](../../STABILITY.md#akm-improve-autonomy--opt-in-in-090) — the
479
+ normative autonomy-gate contract
@@ -0,0 +1,154 @@
1
+ # Classification System
2
+
3
+ akm recognizes files through **bundle adapters**. Each adapter owns a bundle
4
+ format and exposes a `recognize()` primitive that inspects a single file (path +
5
+ frontmatter + content) and returns an `IndexDocument` — the item's
6
+ subdir-qualified `conceptId`, type, renderer, and metadata — or `null` if the
7
+ adapter does not claim the file. There is no longer a global matcher registry;
8
+ the per-format adapter is the unit of recognition.
9
+
10
+ ## Built-in adapters
11
+
12
+ The registry is a **static frozen list** (`BUILTIN_ADAPTERS` in
13
+ `src/core/adapter/adapters/index.ts`, exposed through
14
+ `src/core/adapter/registry.ts`) — always populated at module load, no
15
+ registration call required. Eleven built-ins, in probe order:
16
+
17
+ | Adapter id | Format | Recognizes |
18
+ | --- | --- | --- |
19
+ | `website-snapshot` | Crawled website snapshot bundle (read-only) | snapshot pages |
20
+ | `agent-skills` | Agent-skills package (root `SKILL.md`) | skills |
21
+ | `claude` | A `.claude/` tool directory | commands, agents, skills, settings-adjacent files |
22
+ | `opencode` | An `.opencode/` tool directory | commands, agents, skills |
23
+ | `dotenv` | Env-file bundle | env/secret whole-file assets (values never indexed) |
24
+ | `akm-workflow` | Workflow-dir component | workflow programs |
25
+ | `akm-task` | Task-dir component | scheduled task definitions |
26
+ | `llm-wiki` | LLM Wiki bundle | a wiki root (`schema.md` + `pages/`) and its pages, raw, xrefs, citations |
27
+ | `akm` | The classic AKM bundle layout | scripts, skills, commands, agents, knowledge, instructions, workflows, memories, lessons, env, secrets, facts, tasks, sessions |
28
+ | `okf` | Open Knowledge Format bundle | OKF concept documents of any open type |
29
+ | `generic-files` | Catch-all file mount | explicit configuration only — never auto-probed |
30
+
31
+ `looksLikeRoot` probes run most-specific-first in the list order above; the
32
+ first match wins and the winner is recorded per component. A root matching no
33
+ probe falls back to `akm` (see `FALLBACK_ADAPTER_ID` in
34
+ `src/indexer/installations.ts`).
35
+ `generic-files` never participates in probing.
36
+
37
+ Configured adapter ownership wins over probing. `akm add` records the detected
38
+ adapter so later indexing does not reinterpret a bundle. The broad OKF probe
39
+ also recognizes index-less typed Markdown, but strong AKM layout evidence runs
40
+ first because AKM Markdown is an OKF-compatible superset.
41
+
42
+ See [Bundle Types](../../reference/bundle-types.md) for the user-facing detail
43
+ per adapter — conceptId/ref shape, what's indexed, `validate()` checks, and
44
+ read/write status in 0.9.0.
45
+
46
+ ## Item types
47
+
48
+ `type` is an open descriptive string. The core accepts every non-empty value;
49
+ the owning adapter decides whether a value receives specialized behavior. The
50
+ `akm` adapter emits its fourteen defined native types (`script`, `skill`,
51
+ `command`, `agent`, `knowledge`, `instruction`, `workflow`, `memory`,
52
+ `lesson`, `env`, `secret`, `fact`, `task`, `session`) — see
53
+ [Bundle Types](../../reference/bundle-types.md) for the full
54
+ purpose / agent-output table per type.
55
+
56
+ `wiki` is **no longer an item type**. Multi-page wikis are a bundle *format* owned
57
+ by the `llm-wiki` adapter, not a per-file type stamped by the classifier.
58
+
59
+ ## Reserved structural files
60
+
61
+ `index.md` and `log.md` are reserved structural files for the `akm`, `okf`, and
62
+ `llm-wiki` adapters. OKF defines their meaning in OKF bundles; AKM and LLM Wiki
63
+ reserve the same names under their own format contracts. Other adapters own
64
+ their reserved-name rules.
65
+
66
+ ## Adapter-owned filtering (AKM sensitive/infra abstention)
67
+
68
+ Each adapter decides which walked files it claims and which it abstains on — the
69
+ core always excludes VCS internals and symlink escapes. An OKF walk includes
70
+ ordinary dot directories and `bin/` because those paths can identify conformant
71
+ concepts; AKM keeps its existing cache/dot-directory hygiene. The `akm`
72
+ adapter's `recognize` abstains (returns `null`) on its own bundle's
73
+ non-content files, using **path/stat checks only** so the bytes of sensitive files
74
+ are never read to make the decision:
75
+
76
+ - an `env/…` `.env` file that has a sibling `.sensitive` marker;
77
+ - anything under the frozen legacy `vaults/` directory (the `vault` type was
78
+ removed in 0.9.0);
79
+ - a `secrets/` `.sensitive`/`.lock` marker, or a secret with a sibling
80
+ `<name>.sensitive` marker;
81
+ - a `wikis/<name>/` root-level infrastructure file (`schema.md`/`index.md`/`log.md`).
82
+
83
+ This policy previously lived in the indexer's `shouldIndexStashFile` pre-filter; it
84
+ now lives in the adapter (`akmStashAbstains` in
85
+ `src/core/adapter/adapters/akm-adapter.ts`), so each adapter owns its own bundle's
86
+ filtering (owner ruling 2026-07-21).
87
+
88
+ ## The akm adapter's recognition signals
89
+
90
+ Inside the `akm` adapter, recognition picks a winner by **specificity descending**,
91
+ ties broken by registration order (later wins). The signals:
92
+
93
+ | Specificity | Signal | Result |
94
+ | --- | --- | --- |
95
+ | 25 | `SKILL.md` (skill directory) | `skill` |
96
+ | 20 | `tools` frontmatter | `agent` |
97
+ | 19 | workflow markdown structure | `workflow` |
98
+ | 18 | command frontmatter / `$ARGUMENTS` body placeholders | `command` |
99
+ | 15 | immediate parent dir hint | directory-specific type |
100
+ | 10 | ancestor dir hint | directory-specific type |
101
+ | 8 | `model` frontmatter only | weak `agent` signal |
102
+ | 5 | fallback markdown | `knowledge` |
103
+ | 3 | known script extension | `script` |
104
+
105
+ ### Directory signals
106
+
107
+ - `scripts/` → `script`
108
+ - `skills/` → `skill`
109
+ - `commands/` → `command`
110
+ - `agents/` → `agent`
111
+ - `knowledge/` → `knowledge`
112
+ - `workflows/` → `workflow`
113
+ - `memories/` → `memory`
114
+ - `lessons/` → `lesson`
115
+ - `env/` → `env`
116
+ - `secrets/` → `secret`
117
+ - `tasks/` → `task`
118
+
119
+ ### Markdown signals
120
+
121
+ | Signal | Type | Specificity |
122
+ | --- | --- | --- |
123
+ | `tools` in frontmatter | `agent` | 20 |
124
+ | workflow heading/step structure | `workflow` | 19 |
125
+ | `agent` in frontmatter | `command` | 18 |
126
+ | `$ARGUMENTS` or `$1`-`$3` in body | `command` | 18 |
127
+ | `model` in frontmatter only | `agent` | 8 |
128
+ | any other `.md` | `knowledge` | 5 |
129
+
130
+ ## Asset quality values
131
+
132
+ The `quality` field marks how an item was produced. Four values are well-known:
133
+
134
+ | Value | Meaning |
135
+ | --- | --- |
136
+ | `"generated"` | Heuristically indexed; included in default search |
137
+ | `"curated"` | Human-authored; included in default search |
138
+ | `"enriched"` | Retired LLM enrichment pass (0.9.17-alpha.9) ran for this item; included in default search |
139
+ | `"proposed"` | Pending review; excluded from default search, opt-in via `--include-proposed` |
140
+
141
+ Unknown string values warn once at runtime and remain searchable.
142
+
143
+ ## Examples
144
+
145
+ | File | Winning signal | conceptId |
146
+ | --- | --- | --- |
147
+ | `scripts/deploy.sh` | parent dir (15) → `script` | `scripts/deploy.sh` |
148
+ | `skills/review/SKILL.md` | `SKILL.md` (25) → `skill` | `skills/review` |
149
+ | `commands/release.md` with `agent: coder` | command frontmatter (18) | `commands/release` |
150
+ | `agents/reviewer.md` with `tools:` | frontmatter (20) → `agent` | `agents/reviewer` |
151
+ | `workflows/release.md` with workflow structure | structure (19) → `workflow` | `workflows/release` |
152
+ | `env/prod.env` | parent dir (15) → `env` | `env/prod` |
153
+ | `secrets/deploy-token` | parent dir (15) → `secret` | `secrets/deploy-token` |
154
+ | `docs/guide.md` | fallback (5) → `knowledge` | `knowledge/guide` |