akm-cli 0.9.0-rc.0 → 0.9.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/CHANGELOG.md +339 -2
  2. package/SECURITY.md +23 -24
  3. package/dist/assets/help/help-improve.md +10 -10
  4. package/dist/assets/hints/cli-hints-full.md +44 -10
  5. package/dist/assets/hints/cli-hints-short.md +6 -2
  6. package/dist/assets/{profiles → improve-strategies}/default.json +1 -0
  7. package/dist/assets/{profiles → improve-strategies}/graph-refresh.json +1 -1
  8. package/dist/assets/{profiles → improve-strategies}/proactive-maintenance.json +2 -3
  9. package/dist/assets/{profiles → improve-strategies}/reflect-distill.json +3 -4
  10. package/dist/assets/prompts/workflow-unit-preamble.md +26 -0
  11. package/dist/assets/stash-skeleton/README.md +28 -0
  12. package/dist/assets/stash-skeleton/facts/conventions/assets/agent.md +6 -0
  13. package/dist/assets/stash-skeleton/facts/conventions/assets/command.md +6 -0
  14. package/dist/assets/stash-skeleton/facts/conventions/assets/fact.md +12 -1
  15. package/dist/assets/stash-skeleton/facts/conventions/assets/knowledge.md +11 -1
  16. package/dist/assets/stash-skeleton/facts/conventions/assets/lesson.md +6 -0
  17. package/dist/assets/stash-skeleton/facts/conventions/assets/memory.md +9 -0
  18. package/dist/assets/stash-skeleton/facts/conventions/assets/script.md +7 -0
  19. package/dist/assets/stash-skeleton/facts/conventions/assets/skill.md +7 -0
  20. package/dist/assets/stash-skeleton/facts/conventions/assets/workflow.md +6 -0
  21. package/dist/assets/stash-skeleton/facts/conventions/backlinks.md +98 -0
  22. package/dist/assets/stash-skeleton/facts/conventions/domains.md +63 -0
  23. package/dist/assets/stash-skeleton/facts/conventions/organization.md +127 -0
  24. package/dist/assets/tasks/core/backup.yml +1 -0
  25. package/dist/assets/tasks/core/extract.yml +1 -0
  26. package/dist/assets/tasks/core/improve.yml +1 -0
  27. package/dist/assets/tasks/core/index-refresh.yml +1 -0
  28. package/dist/assets/tasks/core/sync.yml +1 -0
  29. package/dist/assets/tasks/core/version-check.yml +1 -0
  30. package/dist/assets/tasks/graph-refresh-weekly.yml +4 -4
  31. package/dist/assets/templates/html/health.html +5 -1
  32. package/dist/cli/config-migrate.js +31 -138
  33. package/dist/cli/config-validate.js +10 -8
  34. package/dist/cli.js +48 -14
  35. package/dist/commands/agent/agent-dispatch.js +17 -16
  36. package/dist/commands/agent/agent-support.js +0 -24
  37. package/dist/commands/agent/contribute-cli.js +5 -15
  38. package/dist/commands/backup-cli.js +54 -0
  39. package/dist/commands/config-cli.js +45 -159
  40. package/dist/commands/env/env-binding.js +95 -0
  41. package/dist/commands/env/env-cli.js +8 -65
  42. package/dist/commands/env/secret.js +8 -5
  43. package/dist/commands/health/checks.js +130 -83
  44. package/dist/commands/health/html-report.js +4 -0
  45. package/dist/commands/health/improve-metrics.js +30 -32
  46. package/dist/commands/health/llm-usage.js +19 -19
  47. package/dist/commands/health/md-report.js +4 -0
  48. package/dist/commands/health/metrics.js +2 -1
  49. package/dist/commands/health/surfaces.js +5 -4
  50. package/dist/commands/health.js +1 -1
  51. package/dist/commands/improve/consolidate/chunking.js +2 -2
  52. package/dist/commands/improve/consolidate.js +28 -25
  53. package/dist/commands/improve/distill/promote-memory.js +5 -12
  54. package/dist/commands/improve/distill/quality-gate.js +5 -7
  55. package/dist/commands/improve/distill.js +16 -5
  56. package/dist/commands/improve/eligibility.js +22 -12
  57. package/dist/commands/improve/extract-cli.js +47 -19
  58. package/dist/commands/improve/extract.js +110 -62
  59. package/dist/commands/improve/improve-cli.js +38 -16
  60. package/dist/commands/improve/improve-result-file.js +30 -24
  61. package/dist/commands/improve/improve-strategies.js +137 -0
  62. package/dist/commands/improve/improve.js +60 -30
  63. package/dist/commands/improve/locks.js +66 -45
  64. package/dist/commands/improve/loop-stages.js +75 -33
  65. package/dist/commands/improve/memory/memory-belief.js +79 -7
  66. package/dist/commands/improve/memory/memory-contradiction-detect.js +12 -4
  67. package/dist/commands/improve/preparation.js +71 -73
  68. package/dist/commands/improve/procedural.js +3 -2
  69. package/dist/commands/improve/recombine.js +2 -1
  70. package/dist/commands/improve/reflect.js +119 -214
  71. package/dist/commands/improve/shared.js +11 -5
  72. package/dist/commands/lint/base-linter.js +152 -42
  73. package/dist/commands/mv-cli.js +809 -0
  74. package/dist/commands/proposal/proposal-cli.js +18 -8
  75. package/dist/commands/proposal/propose.js +64 -69
  76. package/dist/commands/read/knowledge.js +436 -4
  77. package/dist/commands/read/remember-cli.js +39 -2
  78. package/dist/commands/read/search-cli.js +6 -1
  79. package/dist/commands/registry-cli.js +29 -14
  80. package/dist/commands/remember.js +2 -0
  81. package/dist/commands/sources/init.js +13 -14
  82. package/dist/commands/sources/migration-help.js +7 -4
  83. package/dist/commands/sources/schema-repair.js +2 -4
  84. package/dist/commands/sources/source-add.js +62 -73
  85. package/dist/commands/sources/source-manage.js +50 -46
  86. package/dist/commands/sources/stash-cli.js +41 -4
  87. package/dist/commands/tasks/default-tasks.js +12 -12
  88. package/dist/commands/tasks/tasks-cli.js +7 -3
  89. package/dist/commands/tasks/tasks.js +113 -18
  90. package/dist/commands/wiki-cli.js +9 -10
  91. package/dist/commands/workflow-cli.js +276 -12
  92. package/dist/core/asset/asset-spec.js +58 -1
  93. package/dist/core/asset/frontmatter.js +12 -2
  94. package/dist/core/common.js +5 -3
  95. package/dist/core/config/config-io.js +28 -17
  96. package/dist/core/config/config-schema.js +379 -66
  97. package/dist/core/config/config-types.js +3 -3
  98. package/dist/core/config/config-version.js +29 -0
  99. package/dist/core/config/config-walker.js +98 -27
  100. package/dist/core/config/config.js +132 -266
  101. package/dist/core/config/deep-merge.js +41 -0
  102. package/dist/core/config/engine-semantics.js +32 -0
  103. package/dist/core/errors.js +2 -2
  104. package/dist/core/extra-params.js +61 -0
  105. package/dist/core/file-lock.js +201 -56
  106. package/dist/core/improve-result.js +178 -0
  107. package/dist/core/json-schema.js +142 -0
  108. package/dist/core/maintenance-barrier.js +119 -0
  109. package/dist/core/migration-backup.js +416 -0
  110. package/dist/core/paths.js +3 -0
  111. package/dist/core/redaction.js +358 -0
  112. package/dist/core/state/migrations.js +17 -2
  113. package/dist/core/state-db.js +44 -1
  114. package/dist/indexer/db/db.js +118 -2
  115. package/dist/indexer/graph/graph-extraction.js +28 -16
  116. package/dist/indexer/index-writer-lock.js +31 -24
  117. package/dist/indexer/index-written-assets.js +15 -6
  118. package/dist/indexer/indexer.js +47 -2
  119. package/dist/indexer/passes/memory-inference.js +10 -6
  120. package/dist/indexer/passes/metadata.js +250 -0
  121. package/dist/indexer/search/db-search.js +111 -44
  122. package/dist/indexer/search/fts-query.js +41 -0
  123. package/dist/indexer/search/ranking-contributors.js +48 -0
  124. package/dist/indexer/search/ranking.js +36 -23
  125. package/dist/indexer/search/search-fields.js +11 -1
  126. package/dist/indexer/walk/matchers.js +39 -0
  127. package/dist/integrations/agent/builder-shared.js +7 -0
  128. package/dist/integrations/agent/builders.js +5 -50
  129. package/dist/integrations/agent/config.js +3 -143
  130. package/dist/integrations/agent/detect.js +17 -2
  131. package/dist/integrations/agent/engine-resolution.js +202 -0
  132. package/dist/integrations/agent/index.js +1 -2
  133. package/dist/integrations/agent/model-aliases.js +16 -2
  134. package/dist/integrations/agent/profiles.js +36 -62
  135. package/dist/integrations/agent/runner-dispatch.js +91 -4
  136. package/dist/integrations/agent/runner.js +76 -207
  137. package/dist/integrations/agent/spawn.js +141 -20
  138. package/dist/integrations/harnesses/aider/agent-builder.js +112 -0
  139. package/dist/integrations/harnesses/aider/index.js +57 -0
  140. package/dist/integrations/harnesses/aider/result-extractor.js +53 -0
  141. package/dist/integrations/harnesses/amazonq/agent-builder.js +152 -0
  142. package/dist/integrations/harnesses/amazonq/index.js +58 -0
  143. package/dist/integrations/harnesses/amazonq/result-extractor.js +48 -0
  144. package/dist/integrations/harnesses/claude/agent-builder.js +46 -8
  145. package/dist/integrations/harnesses/claude/index.js +25 -25
  146. package/dist/integrations/harnesses/claude/result-extractor.js +52 -0
  147. package/dist/integrations/harnesses/codex/agent-builder.js +136 -0
  148. package/dist/integrations/harnesses/codex/index.js +62 -0
  149. package/dist/integrations/harnesses/codex/result-extractor.js +73 -0
  150. package/dist/integrations/harnesses/copilot/agent-builder.js +121 -0
  151. package/dist/integrations/harnesses/copilot/index.js +59 -0
  152. package/dist/integrations/harnesses/copilot/result-extractor.js +151 -0
  153. package/dist/integrations/harnesses/gemini/agent-builder.js +120 -0
  154. package/dist/integrations/harnesses/gemini/index.js +59 -0
  155. package/dist/integrations/harnesses/gemini/result-extractor.js +121 -0
  156. package/dist/integrations/harnesses/index.js +27 -28
  157. package/dist/integrations/harnesses/opencode/agent-builder.js +2 -3
  158. package/dist/integrations/harnesses/opencode/index.js +15 -22
  159. package/dist/integrations/harnesses/opencode-sdk/harness.js +60 -0
  160. package/dist/integrations/harnesses/opencode-sdk/index.js +8 -32
  161. package/dist/integrations/harnesses/opencode-sdk/sdk-runner.js +681 -108
  162. package/dist/integrations/harnesses/openhands/agent-builder.js +125 -0
  163. package/dist/integrations/harnesses/openhands/index.js +57 -0
  164. package/dist/integrations/harnesses/openhands/result-extractor.js +103 -0
  165. package/dist/integrations/harnesses/pi/agent-builder.js +103 -0
  166. package/dist/integrations/harnesses/pi/index.js +57 -0
  167. package/dist/integrations/harnesses/pi/result-extractor.js +135 -0
  168. package/dist/integrations/harnesses/types.js +8 -32
  169. package/dist/integrations/lockfile.js +32 -21
  170. package/dist/integrations/session-logs/index.js +24 -11
  171. package/dist/llm/client.js +48 -14
  172. package/dist/llm/feature-gate.js +15 -47
  173. package/dist/llm/graph-extract.js +1 -1
  174. package/dist/llm/index-passes.js +8 -42
  175. package/dist/llm/memory-infer-impl.js +1 -1
  176. package/dist/llm/usage-persist.js +4 -0
  177. package/dist/llm/usage-telemetry.js +35 -5
  178. package/dist/output/renderers.js +3 -2
  179. package/dist/output/shapes/helpers.js +2 -1
  180. package/dist/output/shapes/passthrough.js +6 -0
  181. package/dist/output/text/helpers.js +215 -2
  182. package/dist/output/text/workflow.js +3 -1
  183. package/dist/schemas/akm-config.json +16638 -0
  184. package/dist/schemas/akm-task.json +87 -0
  185. package/dist/schemas/akm-workflow.json +372 -0
  186. package/dist/scripts/migrate-storage.js +10944 -8801
  187. package/dist/scripts/migrations/import-fs-improve-runs-to-db.js +9247 -350
  188. package/dist/setup/detected-engines.js +142 -0
  189. package/dist/setup/engine-config.js +89 -0
  190. package/dist/setup/setup.js +236 -132
  191. package/dist/setup/steps/connection.js +61 -32
  192. package/dist/setup/steps/platforms.js +4 -4
  193. package/dist/setup/steps.js +3 -2
  194. package/dist/storage/database.js +13 -1
  195. package/dist/storage/engines/sqlite-migrations.js +1 -0
  196. package/dist/storage/repositories/improve-runs-repository.js +5 -5
  197. package/dist/storage/repositories/task-history-repository.js +78 -0
  198. package/dist/storage/repositories/workflow-runs-repository.js +190 -1
  199. package/dist/tasks/parser.js +138 -52
  200. package/dist/tasks/runner.js +71 -75
  201. package/dist/tasks/schema.js +1 -1
  202. package/dist/tasks/validator.js +11 -6
  203. package/dist/text-import-hook.mjs +1 -1
  204. package/dist/wiki/wiki.js +9 -8
  205. package/dist/workflows/authoring/authoring.js +123 -10
  206. package/dist/workflows/authoring/workflow-program-template.yaml +31 -0
  207. package/dist/workflows/cli.js +4 -0
  208. package/dist/workflows/concurrency-policy.js +15 -0
  209. package/dist/workflows/db.js +200 -13
  210. package/dist/workflows/exec/brief.js +478 -0
  211. package/dist/workflows/exec/frozen-judge.js +47 -0
  212. package/dist/workflows/exec/native-executor.js +1034 -0
  213. package/dist/workflows/exec/param-secrets.js +115 -0
  214. package/dist/workflows/exec/report.js +1355 -0
  215. package/dist/workflows/exec/run-workflow.js +609 -0
  216. package/dist/workflows/exec/scheduler.js +71 -0
  217. package/dist/workflows/exec/step-work.js +1212 -0
  218. package/dist/workflows/exec/unit-writer.js +23 -0
  219. package/dist/workflows/exec/watch.js +116 -0
  220. package/dist/workflows/exec/worktree.js +171 -0
  221. package/dist/workflows/ir/compile.js +375 -0
  222. package/dist/workflows/ir/freeze.js +243 -0
  223. package/dist/workflows/ir/params.js +54 -0
  224. package/dist/workflows/ir/plan-hash.js +68 -0
  225. package/dist/workflows/ir/schema.js +545 -0
  226. package/dist/workflows/parser.js +10 -1
  227. package/dist/workflows/program/expressions.js +369 -0
  228. package/dist/workflows/program/parser.js +869 -0
  229. package/dist/workflows/program/project.js +104 -0
  230. package/dist/workflows/program/schema.js +54 -0
  231. package/dist/workflows/renderer.js +82 -5
  232. package/dist/workflows/resource-limits.js +20 -0
  233. package/dist/workflows/runtime/agent-identity.js +59 -14
  234. package/dist/workflows/runtime/plan-classifier.js +187 -0
  235. package/dist/workflows/runtime/runs.js +246 -69
  236. package/dist/workflows/runtime/unit-checkin.js +45 -0
  237. package/dist/workflows/runtime/workflow-asset-loader.js +42 -1
  238. package/dist/workflows/validate-summary.js +24 -3
  239. package/dist/workflows/validator.js +26 -1
  240. package/docs/data-and-telemetry.md +4 -3
  241. package/docs/migration/release-notes/0.6.0.md +1 -1
  242. package/docs/migration/release-notes/0.7.0.md +5 -4
  243. package/docs/migration/release-notes/0.9.0-beta.60.md +19 -0
  244. package/docs/migration/v0.8-to-v0.9.md +401 -0
  245. package/package.json +4 -2
  246. package/schemas/akm-config.json +16638 -0
  247. package/schemas/akm-task.json +87 -0
  248. package/schemas/akm-workflow.json +372 -0
  249. package/dist/commands/improve/improve-profiles.js +0 -168
  250. package/dist/core/config/config-migration.js +0 -602
  251. package/dist/core/deep-merge.js +0 -38
  252. package/dist/llm/call-ai.js +0 -62
  253. package/dist/setup/legacy-config.js +0 -106
  254. package/docs/README.md +0 -104
  255. /package/dist/assets/{profiles → improve-strategies}/catchup.json +0 -0
  256. /package/dist/assets/{profiles → improve-strategies}/consolidate.json +0 -0
  257. /package/dist/assets/{profiles → improve-strategies}/frequent.json +0 -0
  258. /package/dist/assets/{profiles → improve-strategies}/memory-focus.json +0 -0
  259. /package/dist/assets/{profiles → improve-strategies}/quick.json +0 -0
  260. /package/dist/assets/{profiles → improve-strategies}/recombine-only.json +0 -0
  261. /package/dist/assets/{profiles → improve-strategies}/synthesize.json +0 -0
  262. /package/dist/assets/{profiles → improve-strategies}/thorough.json +0 -0
@@ -21,6 +21,7 @@ function makeStampHandler(command) {
21
21
  const PASSTHROUGH_COMMANDS = [
22
22
  "add",
23
23
  "agent-result",
24
+ "backup",
24
25
  "clone",
25
26
  "config",
26
27
  "disable",
@@ -50,6 +51,7 @@ const PASSTHROUGH_COMMANDS = [
50
51
  "init",
51
52
  "lint",
52
53
  "list",
54
+ "mv",
53
55
  "proposal-accept-batch",
54
56
  "proposal-drain",
55
57
  "proposal-reject-batch",
@@ -87,15 +89,19 @@ const PASSTHROUGH_COMMANDS = [
87
89
  "wiki-show",
88
90
  "wiki-stash",
89
91
  "workflow-abandon",
92
+ "workflow-brief",
90
93
  "workflow-complete",
91
94
  "workflow-complete-rejected",
92
95
  "workflow-create",
93
96
  "workflow-list",
94
97
  "workflow-next",
98
+ "workflow-report",
95
99
  "workflow-resume",
100
+ "workflow-run",
96
101
  "workflow-start",
97
102
  "workflow-status",
98
103
  "workflow-validate",
104
+ "workflow-watch",
99
105
  ];
100
106
  export const passthroughShapes = PASSTHROUGH_COMMANDS.map((command) => ({
101
107
  command,
@@ -194,7 +194,18 @@ export function formatWorkflowValidatePlain(r) {
194
194
  return `workflow validate: failed (${pathValue})`;
195
195
  const title = typeof r.title === "string" ? r.title : "";
196
196
  const stepCount = typeof r.stepCount === "number" ? r.stepCount : 0;
197
- return `workflow validate: ok — ${title || pathValue} (${stepCount} step(s))`;
197
+ const lines = [`workflow validate: ok — ${title || pathValue} (${stepCount} step(s))`];
198
+ // Non-fatal advisories: clearly marked, printed after the ok line so `ok`
199
+ // is never in doubt. Absent/empty for markdown and fully-typed programs.
200
+ const warnings = Array.isArray(r.warnings) ? r.warnings : [];
201
+ if (warnings.length > 0) {
202
+ lines.push(` ${warnings.length} warning(s):`);
203
+ for (const w of warnings) {
204
+ const line = typeof w.line === "number" ? w.line : "?";
205
+ lines.push(` warning: ${pathValue}:${line} — ${String(w.message ?? "")}`);
206
+ }
207
+ }
208
+ return lines.join("\n");
198
209
  }
199
210
  /**
200
211
  * Plain-text rendering for a step-completion that was rejected by the
@@ -390,13 +401,15 @@ export function formatProposalDrainPlain(r) {
390
401
  const rejected = Array.isArray(r.rejected) ? r.rejected : [];
391
402
  const deferred = Array.isArray(r.deferred) ? r.deferred : [];
392
403
  const skippedByCap = Array.isArray(r.skippedByCap) ? r.skippedByCap : [];
404
+ const staged = Array.isArray(r.staged) ? r.staged : [];
393
405
  const prefix = r.dryRun === true ? "[dry-run] " : "";
394
406
  const lines = [
395
- `${prefix}Drained proposal queue (policy=${policy}, applyMode=${applyMode})`,
407
+ `${prefix}Drained proposal queue (strategy=${String(r.strategy ?? "?")}, policy=${policy}, applyMode=${applyMode})`,
396
408
  ` promoted: ${promoted.length}`,
397
409
  ` rejected: ${rejected.length}`,
398
410
  ` deferred: ${deferred.length}`,
399
411
  ` skippedByCap: ${skippedByCap.length}`,
412
+ ` staged: ${staged.length}`,
400
413
  ];
401
414
  for (const d of deferred) {
402
415
  lines.push(` - ${String(d.id ?? "?")} (${String(d.reason ?? "?")})`);
@@ -722,8 +735,59 @@ export function formatWorkflowStatusPlain(result) {
722
735
  }
723
736
  }
724
737
  }
738
+ // `workflow status --units` (#22): the honest per-unit diagnostic surface —
739
+ // failure_reason plus any journaled result/error text. Diagnostics only; the
740
+ // deterministic step evidence above is unaffected.
741
+ const units = Array.isArray(result.units) ? result.units : undefined;
742
+ if (units) {
743
+ lines.push("");
744
+ lines.push(units.length > 0 ? "units:" : "units: (none journaled)");
745
+ for (const unit of units) {
746
+ const id = typeof unit.unitId === "string" ? unit.unitId : "unknown";
747
+ const status = typeof unit.status === "string" ? unit.status : "unknown";
748
+ const node = typeof unit.nodeId === "string" ? unit.nodeId : "";
749
+ const attempts = typeof unit.attempts === "number" ? unit.attempts : undefined;
750
+ const suffix = attempts !== undefined && attempts > 1 ? `, attempt ${attempts}` : "";
751
+ lines.push(` - ${id} [${node}] (${status}${suffix})`);
752
+ // Codex round-3 finding B: a `running` claim gone silent past the check-in
753
+ // window — the driver likely died. Surface it (with the claim holder) so a
754
+ // human can reclaim/re-run the unit, matching what `brief` reports.
755
+ if (unit.stale === true) {
756
+ const holder = typeof unit.claimHolder === "string" && unit.claimHolder.trim() ? ` claimed by ${unit.claimHolder}` : "";
757
+ lines.push(` stale: claim went silent past the check-in window${holder} — its driver may have died`);
758
+ }
759
+ if (typeof unit.failureReason === "string" && unit.failureReason.trim()) {
760
+ lines.push(` failure_reason: ${unit.failureReason}`);
761
+ }
762
+ if (typeof unit.diagnostic === "string" && unit.diagnostic.trim()) {
763
+ const diagLines = unit.diagnostic.split("\n");
764
+ lines.push(` diagnostic: ${diagLines[0]}`);
765
+ for (const diagLine of diagLines.slice(1))
766
+ lines.push(` ${diagLine}`);
767
+ }
768
+ }
769
+ }
770
+ // Review C2: the check-in `continue` directive must survive plain-text
771
+ // rendering — JSON consumers saw `checkin` but the text path dropped it.
772
+ const checkinLine = formatWorkflowCheckinLine(result);
773
+ if (checkinLine) {
774
+ lines.push("");
775
+ lines.push(checkinLine);
776
+ }
725
777
  return lines.join("\n");
726
778
  }
779
+ /**
780
+ * Render the stalled-run check-in directive (#506) when present on a
781
+ * workflow-next/status result. Returns null when the run is healthy.
782
+ */
783
+ function formatWorkflowCheckinLine(result) {
784
+ const checkin = typeof result.checkin === "object" && result.checkin !== null
785
+ ? result.checkin
786
+ : undefined;
787
+ if (!checkin || typeof checkin.directive !== "string" || !checkin.directive.trim())
788
+ return null;
789
+ return checkin.directive.trim();
790
+ }
727
791
  export function formatWorkflowNextPlain(result) {
728
792
  const base = formatWorkflowStatusPlain(result);
729
793
  const step = typeof result.step === "object" && result.step !== null ? result.step : undefined;
@@ -765,6 +829,155 @@ export function formatWorkflowNextPlain(result) {
765
829
  }
766
830
  return lines.join("\n");
767
831
  }
832
+ export function formatWorkflowRunPlain(result) {
833
+ const run = typeof result.run === "object" && result.run !== null ? result.run : undefined;
834
+ if (!run)
835
+ return null;
836
+ const lines = [`run: ${String(run.id ?? "unknown")}`, `status: ${String(run.status ?? "unknown")}`];
837
+ const executed = Array.isArray(result.executed) ? result.executed : [];
838
+ if (executed.length === 0) {
839
+ lines.push("executed: (no steps — run was already done or blocked)");
840
+ }
841
+ else {
842
+ lines.push("executed:");
843
+ for (const step of executed) {
844
+ const marker = step.ok === true ? "ok" : "FAILED";
845
+ lines.push(` - ${String(step.stepId ?? "?")} [${marker}] units: ${String(step.unitCount ?? 0)}` +
846
+ (Number(step.failedUnits ?? 0) > 0 ? ` (${String(step.failedUnits)} failed)` : ""));
847
+ if (typeof step.summary === "string" && step.summary.trim()) {
848
+ lines.push(` ${step.summary}`);
849
+ }
850
+ }
851
+ }
852
+ const gate = typeof result.gateRejection === "object" && result.gateRejection !== null
853
+ ? result.gateRejection
854
+ : undefined;
855
+ if (gate) {
856
+ lines.push(`gate rejected step ${String(gate.stepId ?? "?")}: ${String(gate.feedback ?? "")}`);
857
+ const missing = Array.isArray(gate.missing) ? gate.missing : [];
858
+ for (const item of missing)
859
+ lines.push(` missing: ${String(item)}`);
860
+ }
861
+ if (result.done === true)
862
+ lines.push("workflow completed.");
863
+ return lines.join("\n");
864
+ }
865
+ export function formatWorkflowBriefPlain(result) {
866
+ const run = typeof result.run === "object" && result.run !== null ? result.run : undefined;
867
+ if (!run)
868
+ return null;
869
+ const lines = [];
870
+ lines.push(`# Workflow brief: ${String(run.id ?? "unknown")}`);
871
+ lines.push(`workflow: ${String(run.workflowRef ?? "?")} (${String(run.workflowTitle ?? "")})`);
872
+ lines.push(`status: ${String(run.status ?? "?")}`);
873
+ if (typeof result.message === "string")
874
+ lines.push(result.message);
875
+ const lease = typeof result.engineLease === "object" && result.engineLease !== null
876
+ ? result.engineLease
877
+ : undefined;
878
+ if (lease) {
879
+ const live = lease.live === true ? "LIVE" : "expired";
880
+ lines.push(`engine lease: ${String(lease.holder ?? "?")} (until ${String(lease.until ?? "?")}) [${live}]`);
881
+ }
882
+ const warnings = Array.isArray(result.warnings) ? result.warnings : [];
883
+ for (const w of warnings)
884
+ lines.push(`! ${String(w)}`);
885
+ if (result.done === true) {
886
+ lines.push("");
887
+ lines.push("This run is completed — no work remains.");
888
+ return lines.join("\n");
889
+ }
890
+ const step = typeof result.step === "object" && result.step !== null ? result.step : undefined;
891
+ if (!step) {
892
+ return lines.join("\n");
893
+ }
894
+ const gate = typeof step.gate === "object" && step.gate !== null ? step.gate : undefined;
895
+ lines.push("");
896
+ lines.push(`## Active step: ${String(step.stepId ?? "?")} — ${String(step.title ?? "")} [${String(step.kind ?? "execute")}]`);
897
+ if (gate) {
898
+ const criteria = Array.isArray(gate.criteria) ? gate.criteria : [];
899
+ lines.push(`gate: loop ${String(gate.currentLoop ?? 1)} of max ${String(gate.maxLoops ?? 1)}` +
900
+ (criteria.length > 0 ? `; criteria: ${criteria.map(String).join("; ")}` : "; no completion criteria") +
901
+ (gate.judgesArtifact === true ? " (artifact-judged)" : ""));
902
+ }
903
+ if (step.outputSchema !== undefined)
904
+ lines.push("outputSchema: declared (see JSON output)");
905
+ const feedback = typeof result.gateFeedback === "object" && result.gateFeedback !== null
906
+ ? result.gateFeedback
907
+ : undefined;
908
+ if (feedback) {
909
+ lines.push(`gate feedback (previous loop rejected): ${String(feedback.feedback ?? "")}`);
910
+ const missing = Array.isArray(feedback.missing) ? feedback.missing : [];
911
+ for (const m of missing)
912
+ lines.push(` - missing: ${String(m)}`);
913
+ }
914
+ const route = typeof result.route === "object" && result.route !== null ? result.route : undefined;
915
+ if (route) {
916
+ lines.push("");
917
+ lines.push(`## Route contract on ${String(route.input ?? "?")}`);
918
+ const when = typeof route.when === "object" && route.when !== null ? route.when : {};
919
+ for (const [value, target] of Object.entries(when))
920
+ lines.push(` when "${value}" → ${String(target)}`);
921
+ if (route.defaultStepId !== undefined)
922
+ lines.push(` default → ${String(route.defaultStepId)}`);
923
+ const decision = typeof route.decision === "object" && route.decision !== null
924
+ ? route.decision
925
+ : undefined;
926
+ if (decision)
927
+ lines.push(` decision NOW: value "${String(decision.value)}" → ${String(decision.selected)}`);
928
+ else if (typeof route.decisionError === "string")
929
+ lines.push(` decision error: ${route.decisionError}`);
930
+ else
931
+ lines.push(" decision: pending this step's output (evaluated after units complete)");
932
+ }
933
+ const workList = typeof result.workList === "object" && result.workList !== null
934
+ ? result.workList
935
+ : undefined;
936
+ const units = workList && Array.isArray(workList.units) ? workList.units : [];
937
+ if (workList?.error) {
938
+ lines.push("");
939
+ lines.push(`work-list error: ${String(workList.error)}`);
940
+ }
941
+ else if (units.length > 0) {
942
+ lines.push("");
943
+ lines.push(`## Units (${units.length})`);
944
+ for (const u of units) {
945
+ const model = u.model ? ` model=${String(u.model)}` : "";
946
+ const journaled = typeof u.journaled === "object" && u.journaled !== null ? u.journaled : undefined;
947
+ const jstatus = journaled ? ` [journaled: ${String(journaled.status)}]` : "";
948
+ lines.push(`- ${String(u.unitId)} (runner=${String(u.runner)}${model})${jstatus}`);
949
+ const env = Array.isArray(u.env) ? u.env : [];
950
+ if (env.length > 0)
951
+ lines.push(` env (names): ${env.map(String).join(", ")}`);
952
+ if (u.outputSchema !== undefined)
953
+ lines.push(" outputSchema: declared (see JSON output)");
954
+ const resolved = typeof u.resolved === "object" && u.resolved !== null ? u.resolved : undefined;
955
+ if (resolved && resolved.ok === false)
956
+ lines.push(` RESOLUTION ERROR: ${String(resolved.error)}`);
957
+ if (typeof u.report === "string")
958
+ lines.push(` report: ${u.report}`);
959
+ }
960
+ }
961
+ // Finding D: a non-dispatching step (route-only / empty / all-unresolvable)
962
+ // advances via the `--settle` verb, surfaced so a driver can advance the spine.
963
+ if (typeof result.settleCommand === "string") {
964
+ lines.push("");
965
+ lines.push("## Advance (no reportable units)");
966
+ lines.push(`settle: ${result.settleCommand}`);
967
+ }
968
+ const guidance = typeof result.reportGuidance === "object" && result.reportGuidance !== null
969
+ ? result.reportGuidance
970
+ : undefined;
971
+ if (guidance) {
972
+ lines.push("");
973
+ lines.push("## Reporting");
974
+ if (typeof guidance.checkin === "string")
975
+ lines.push(`heartbeat: ${guidance.checkin}`);
976
+ if (typeof guidance.failure === "string")
977
+ lines.push(`on failure: ${guidance.failure}`);
978
+ }
979
+ return lines.join("\n");
980
+ }
768
981
  export function formatSearchPlain(r, detail) {
769
982
  const hits = r.hits ?? [];
770
983
  const registryHits = r.registryHits ?? [];
@@ -2,7 +2,7 @@
2
2
  // License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
  // Output text formatters for all `akm workflow *` commands.
5
- import { formatWorkflowCompleteRejectedPlain, formatWorkflowCreatePlain, formatWorkflowListPlain, formatWorkflowNextPlain, formatWorkflowResumePlain, formatWorkflowStatusPlain, formatWorkflowValidatePlain, } from "./helpers.js";
5
+ import { formatWorkflowBriefPlain, formatWorkflowCompleteRejectedPlain, formatWorkflowCreatePlain, formatWorkflowListPlain, formatWorkflowNextPlain, formatWorkflowResumePlain, formatWorkflowRunPlain, formatWorkflowStatusPlain, formatWorkflowValidatePlain, } from "./helpers.js";
6
6
  export const workflowFormatters = [
7
7
  { command: "workflow-start", handler: (r) => formatWorkflowStatusPlain(r) },
8
8
  { command: "workflow-status", handler: (r) => formatWorkflowStatusPlain(r) },
@@ -14,4 +14,6 @@ export const workflowFormatters = [
14
14
  { command: "workflow-validate", handler: (r) => formatWorkflowValidatePlain(r) },
15
15
  { command: "workflow-resume", handler: (r) => formatWorkflowResumePlain(r) },
16
16
  { command: "workflow-abandon", handler: (r) => formatWorkflowStatusPlain(r) },
17
+ { command: "workflow-run", handler: (r) => formatWorkflowRunPlain(r) },
18
+ { command: "workflow-brief", handler: (r) => formatWorkflowBriefPlain(r) },
17
19
  ];