akm-cli 0.6.1 → 0.7.0-rc1

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 (319) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{cli.js → src/cli.js} +620 -26
  3. package/dist/{commands → src/commands}/config-cli.js +5 -4
  4. package/dist/src/commands/distill.js +283 -0
  5. package/dist/src/commands/events.js +108 -0
  6. package/dist/src/commands/history.js +120 -0
  7. package/dist/{commands → src/commands}/installed-stashes.js +1 -1
  8. package/dist/src/commands/proposal.js +119 -0
  9. package/dist/src/commands/propose.js +171 -0
  10. package/dist/src/commands/reflect.js +193 -0
  11. package/dist/{commands → src/commands}/registry-search.js +2 -1
  12. package/dist/{commands → src/commands}/remember.js +12 -0
  13. package/dist/{commands → src/commands}/search.js +74 -1
  14. package/dist/{commands → src/commands}/self-update.js +4 -3
  15. package/dist/{commands → src/commands}/show.js +44 -0
  16. package/dist/{core → src/core}/asset-ref.js +5 -5
  17. package/dist/{core → src/core}/asset-spec.js +12 -0
  18. package/dist/{core → src/core}/common.js +1 -1
  19. package/dist/{core → src/core}/config.js +175 -121
  20. package/dist/{core → src/core}/errors.js +4 -0
  21. package/dist/src/core/events.js +239 -0
  22. package/dist/src/core/lesson-lint.js +86 -0
  23. package/dist/src/core/proposals.js +406 -0
  24. package/dist/src/core/warn.js +72 -0
  25. package/dist/{core → src/core}/write-source.js +80 -5
  26. package/dist/{indexer → src/indexer}/db-search.js +113 -24
  27. package/dist/{indexer → src/indexer}/db.js +76 -23
  28. package/dist/{indexer → src/indexer}/file-context.js +0 -3
  29. package/dist/src/indexer/graph-boost.js +179 -0
  30. package/dist/src/indexer/graph-extraction.js +212 -0
  31. package/dist/{indexer → src/indexer}/indexer.js +73 -6
  32. package/dist/src/indexer/memory-inference.js +263 -0
  33. package/dist/{indexer → src/indexer}/metadata.js +111 -3
  34. package/dist/src/integrations/agent/config.js +292 -0
  35. package/dist/src/integrations/agent/detect.js +94 -0
  36. package/dist/src/integrations/agent/index.js +17 -0
  37. package/dist/src/integrations/agent/profiles.js +65 -0
  38. package/dist/src/integrations/agent/prompts.js +167 -0
  39. package/dist/src/integrations/agent/spawn.js +221 -0
  40. package/dist/{integrations → src/integrations}/lockfile.js +0 -26
  41. package/dist/{llm → src/llm}/client.js +33 -2
  42. package/dist/src/llm/feature-gate.js +108 -0
  43. package/dist/src/llm/graph-extract.js +107 -0
  44. package/dist/src/llm/index-passes.js +35 -0
  45. package/dist/src/llm/memory-infer.js +86 -0
  46. package/dist/{output → src/output}/renderers.js +60 -1
  47. package/dist/src/output/shapes.js +516 -0
  48. package/dist/{output → src/output}/text.js +447 -4
  49. package/dist/{registry → src/registry}/build-index.js +14 -4
  50. package/dist/{registry → src/registry}/factory.js +0 -8
  51. package/dist/{registry → src/registry}/providers/static-index.js +3 -2
  52. package/dist/{registry → src/registry}/resolve.js +68 -2
  53. package/dist/{setup → src/setup}/setup.js +43 -5
  54. package/dist/{sources → src/sources}/providers/git.js +7 -15
  55. package/dist/tests/add-website-source.test.js +119 -0
  56. package/dist/tests/agent/agent-config-loader.test.js +70 -0
  57. package/dist/tests/agent/agent-config.test.js +221 -0
  58. package/dist/tests/agent/agent-detect.test.js +100 -0
  59. package/dist/tests/agent/agent-spawn.test.js +234 -0
  60. package/dist/tests/agent-output.test.js +186 -0
  61. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
  62. package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
  63. package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
  64. package/dist/tests/asset-ref.test.js +192 -0
  65. package/dist/tests/asset-registry.test.js +103 -0
  66. package/dist/tests/asset-spec.test.js +241 -0
  67. package/dist/tests/bench/attribution.test.js +995 -0
  68. package/dist/tests/bench/cleanup-sigint.test.js +83 -0
  69. package/dist/tests/bench/cleanup.js +203 -0
  70. package/dist/tests/bench/cleanup.test.js +166 -0
  71. package/dist/tests/bench/cli.js +683 -0
  72. package/dist/tests/bench/cli.test.js +177 -0
  73. package/dist/tests/bench/compare.test.js +556 -0
  74. package/dist/tests/bench/corpus.js +314 -0
  75. package/dist/tests/bench/corpus.test.js +258 -0
  76. package/dist/tests/bench/driver.js +346 -0
  77. package/dist/tests/bench/driver.test.js +443 -0
  78. package/dist/tests/bench/evolve-metrics.js +179 -0
  79. package/dist/tests/bench/evolve-metrics.test.js +187 -0
  80. package/dist/tests/bench/evolve.js +580 -0
  81. package/dist/tests/bench/evolve.test.js +616 -0
  82. package/dist/tests/bench/failure-modes.test.js +300 -0
  83. package/dist/tests/bench/feedback-integrity.test.js +456 -0
  84. package/dist/tests/bench/leakage.test.js +125 -0
  85. package/dist/tests/bench/learning-curve.test.js +133 -0
  86. package/dist/tests/bench/metrics.js +2319 -0
  87. package/dist/tests/bench/metrics.test.js +1144 -0
  88. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
  89. package/dist/tests/bench/report.js +1821 -0
  90. package/dist/tests/bench/report.test.js +989 -0
  91. package/dist/tests/bench/runner.js +536 -0
  92. package/dist/tests/bench/runner.test.js +958 -0
  93. package/dist/tests/bench/search-bridge.test.js +331 -0
  94. package/dist/tests/bench/tmp.js +41 -0
  95. package/dist/tests/bench/trajectory.js +116 -0
  96. package/dist/tests/bench/trajectory.test.js +127 -0
  97. package/dist/tests/bench/verifier.js +109 -0
  98. package/dist/tests/bench/verifier.test.js +118 -0
  99. package/dist/tests/bench/workflow-evaluator.js +557 -0
  100. package/dist/tests/bench/workflow-evaluator.test.js +421 -0
  101. package/dist/tests/bench/workflow-spec.js +358 -0
  102. package/dist/tests/bench/workflow-spec.test.js +363 -0
  103. package/dist/tests/bench/workflow-trace.js +438 -0
  104. package/dist/tests/bench/workflow-trace.test.js +254 -0
  105. package/dist/tests/benchmark-search-quality.js +536 -0
  106. package/dist/tests/benchmark-suite.js +1441 -0
  107. package/dist/tests/capture-cli.test.js +112 -0
  108. package/dist/tests/cli-errors.test.js +203 -0
  109. package/dist/tests/commands/events.test.js +370 -0
  110. package/dist/tests/commands/history.test.js +223 -0
  111. package/dist/tests/commands/import.test.js +103 -0
  112. package/dist/tests/commands/proposal-cli.test.js +209 -0
  113. package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
  114. package/dist/tests/commands/remember.test.js +97 -0
  115. package/dist/tests/commands/scope-flags.test.js +300 -0
  116. package/dist/tests/commands/search.test.js +537 -0
  117. package/dist/tests/commands/show-indexer-parity.test.js +117 -0
  118. package/dist/tests/commands/show.test.js +294 -0
  119. package/dist/tests/common.test.js +266 -0
  120. package/dist/tests/completions.test.js +142 -0
  121. package/dist/tests/config-cli.test.js +193 -0
  122. package/dist/tests/config-llm-features.test.js +139 -0
  123. package/dist/tests/config.test.js +544 -0
  124. package/dist/tests/contracts/migration-baseline.test.js +43 -0
  125. package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
  126. package/dist/tests/contracts/spec-helpers.js +46 -0
  127. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
  128. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
  129. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
  130. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
  131. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
  132. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
  133. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
  134. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
  135. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
  136. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
  137. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
  138. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
  139. package/dist/tests/core/write-source.test.js +366 -0
  140. package/dist/tests/curate-command.test.js +87 -0
  141. package/dist/tests/db-scoring.test.js +201 -0
  142. package/dist/tests/db.test.js +654 -0
  143. package/dist/tests/distill-cli-flag.test.js +208 -0
  144. package/dist/tests/distill.test.js +515 -0
  145. package/dist/tests/docker-install.test.js +120 -0
  146. package/dist/tests/e2e.test.js +1398 -0
  147. package/dist/tests/embedder.test.js +340 -0
  148. package/dist/tests/embedding-model-config.test.js +379 -0
  149. package/dist/tests/feedback-command.test.js +172 -0
  150. package/dist/tests/file-context.test.js +552 -0
  151. package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
  152. package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
  153. package/dist/tests/fixtures/stashes/load.js +166 -0
  154. package/dist/tests/fixtures/stashes/load.test.js +88 -0
  155. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
  156. package/dist/tests/frontmatter.test.js +190 -0
  157. package/dist/tests/fts-field-weighting.test.js +254 -0
  158. package/dist/tests/fuzzy-search.test.js +230 -0
  159. package/dist/tests/git-provider-clone.test.js +45 -0
  160. package/dist/tests/github.test.js +161 -0
  161. package/dist/tests/graph-boost-ranking.test.js +305 -0
  162. package/dist/tests/graph-extraction.test.js +282 -0
  163. package/dist/tests/helpers/usage-events.js +8 -0
  164. package/dist/tests/index-pass-llm.test.js +161 -0
  165. package/dist/tests/indexer.test.js +559 -0
  166. package/dist/tests/info-command.test.js +166 -0
  167. package/dist/tests/init.test.js +69 -0
  168. package/dist/tests/install-script.test.js +246 -0
  169. package/dist/tests/integration/agent-real-profile.test.js +94 -0
  170. package/dist/tests/issue-36-repro.test.js +304 -0
  171. package/dist/tests/issues-191-194.test.js +160 -0
  172. package/dist/tests/lesson-lint.test.js +111 -0
  173. package/dist/tests/llm-client.test.js +115 -0
  174. package/dist/tests/llm-feature-gate.test.js +151 -0
  175. package/dist/tests/llm.test.js +139 -0
  176. package/dist/tests/lockfile.test.js +216 -0
  177. package/dist/tests/manifest.test.js +205 -0
  178. package/dist/tests/markdown.test.js +126 -0
  179. package/dist/tests/matchers-unit.test.js +189 -0
  180. package/dist/tests/memory-inference.test.js +299 -0
  181. package/dist/tests/merge-scoring.test.js +136 -0
  182. package/dist/tests/metadata.test.js +313 -0
  183. package/dist/tests/migration-help.test.js +89 -0
  184. package/dist/tests/origin-resolve.test.js +124 -0
  185. package/dist/tests/output-baseline.test.js +217 -0
  186. package/dist/tests/output-shapes-unit.test.js +476 -0
  187. package/dist/tests/parallel-search.test.js +272 -0
  188. package/dist/tests/parameter-metadata.test.js +365 -0
  189. package/dist/tests/paths.test.js +177 -0
  190. package/dist/tests/progressive-disclosure.test.js +280 -0
  191. package/dist/tests/proposals.test.js +279 -0
  192. package/dist/tests/proposed-quality.test.js +271 -0
  193. package/dist/tests/provider-registry.test.js +32 -0
  194. package/dist/tests/ranking-regression.test.js +548 -0
  195. package/dist/tests/reflect-propose.test.js +455 -0
  196. package/dist/tests/registry-build-index.test.js +378 -0
  197. package/dist/tests/registry-cli.test.js +290 -0
  198. package/dist/tests/registry-index-v2.test.js +430 -0
  199. package/dist/tests/registry-install.test.js +728 -0
  200. package/dist/tests/registry-providers/parity.test.js +189 -0
  201. package/dist/tests/registry-providers/skills-sh.test.js +309 -0
  202. package/dist/tests/registry-providers/static-index.test.js +204 -0
  203. package/dist/tests/registry-resolve.test.js +126 -0
  204. package/dist/tests/registry-search.test.js +723 -0
  205. package/dist/tests/remember-frontmatter.test.js +380 -0
  206. package/dist/tests/remember-unit.test.js +123 -0
  207. package/dist/tests/ripgrep-install.test.js +251 -0
  208. package/dist/tests/ripgrep-resolve.test.js +108 -0
  209. package/dist/tests/ripgrep.test.js +163 -0
  210. package/dist/tests/save-command.test.js +94 -0
  211. package/dist/tests/save-trust-qa-fixes.test.js +270 -0
  212. package/dist/tests/scoring-pipeline.test.js +648 -0
  213. package/dist/tests/search-include-proposed-cli.test.js +118 -0
  214. package/dist/tests/self-update.test.js +442 -0
  215. package/dist/tests/semantic-search-e2e.test.js +512 -0
  216. package/dist/tests/semantic-status.test.js +471 -0
  217. package/dist/tests/setup-run.integration.js +877 -0
  218. package/dist/tests/setup-wizard.test.js +198 -0
  219. package/dist/tests/setup.test.js +131 -0
  220. package/dist/tests/source-add.test.js +11 -0
  221. package/dist/tests/source-clone.test.js +254 -0
  222. package/dist/tests/source-manage.test.js +366 -0
  223. package/dist/tests/source-providers/filesystem.test.js +82 -0
  224. package/dist/tests/source-providers/git.test.js +252 -0
  225. package/dist/tests/source-providers/website.test.js +128 -0
  226. package/dist/tests/source-qa-fixes.test.js +268 -0
  227. package/dist/tests/source-registry.test.js +350 -0
  228. package/dist/tests/source-resolve.test.js +100 -0
  229. package/dist/tests/source-source.test.js +221 -0
  230. package/dist/tests/source.test.js +533 -0
  231. package/dist/tests/tar-utils-scan.test.js +73 -0
  232. package/dist/tests/toggle-components.test.js +73 -0
  233. package/dist/tests/usage-telemetry.test.js +265 -0
  234. package/dist/tests/utility-scoring.test.js +558 -0
  235. package/dist/tests/vault-load-error.test.js +78 -0
  236. package/dist/tests/vault-qa-fixes.test.js +194 -0
  237. package/dist/tests/vault.test.js +429 -0
  238. package/dist/tests/vector-search.test.js +608 -0
  239. package/dist/tests/walker.test.js +252 -0
  240. package/dist/tests/wave2-cluster-bc.test.js +228 -0
  241. package/dist/tests/wave2-cluster-d.test.js +180 -0
  242. package/dist/tests/wave2-cluster-e.test.js +179 -0
  243. package/dist/tests/wiki-qa-fixes.test.js +270 -0
  244. package/dist/tests/wiki.test.js +529 -0
  245. package/dist/tests/workflow-cli.test.js +271 -0
  246. package/dist/tests/workflow-markdown.test.js +171 -0
  247. package/dist/tests/workflow-path-escape.test.js +132 -0
  248. package/dist/tests/workflow-qa-fixes.test.js +377 -0
  249. package/dist/tests/workflows/indexer-rejection.test.js +213 -0
  250. package/docs/README.md +8 -0
  251. package/docs/migration/release-notes/0.7.0.md +244 -0
  252. package/package.json +2 -2
  253. package/dist/core/warn.js +0 -27
  254. package/dist/output/shapes.js +0 -212
  255. /package/dist/{commands → src/commands}/completions.js +0 -0
  256. /package/dist/{commands → src/commands}/curate.js +0 -0
  257. /package/dist/{commands → src/commands}/info.js +0 -0
  258. /package/dist/{commands → src/commands}/init.js +0 -0
  259. /package/dist/{commands → src/commands}/install-audit.js +0 -0
  260. /package/dist/{commands → src/commands}/migration-help.js +0 -0
  261. /package/dist/{commands → src/commands}/source-add.js +0 -0
  262. /package/dist/{commands → src/commands}/source-clone.js +0 -0
  263. /package/dist/{commands → src/commands}/source-manage.js +0 -0
  264. /package/dist/{commands → src/commands}/vault.js +0 -0
  265. /package/dist/{core → src/core}/asset-registry.js +0 -0
  266. /package/dist/{core → src/core}/frontmatter.js +0 -0
  267. /package/dist/{core → src/core}/markdown.js +0 -0
  268. /package/dist/{core → src/core}/paths.js +0 -0
  269. /package/dist/{indexer → src/indexer}/manifest.js +0 -0
  270. /package/dist/{indexer → src/indexer}/matchers.js +0 -0
  271. /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
  272. /package/dist/{indexer → src/indexer}/search-source.js +0 -0
  273. /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
  274. /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
  275. /package/dist/{indexer → src/indexer}/walker.js +0 -0
  276. /package/dist/{integrations → src/integrations}/github.js +0 -0
  277. /package/dist/{llm → src/llm}/embedder.js +0 -0
  278. /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
  279. /package/dist/{llm → src/llm}/embedders/local.js +0 -0
  280. /package/dist/{llm → src/llm}/embedders/remote.js +0 -0
  281. /package/dist/{llm → src/llm}/embedders/types.js +0 -0
  282. /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
  283. /package/dist/{output → src/output}/cli-hints.js +0 -0
  284. /package/dist/{output → src/output}/context.js +0 -0
  285. /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
  286. /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
  287. /package/dist/{registry → src/registry}/providers/index.js +0 -0
  288. /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
  289. /package/dist/{registry → src/registry}/providers/types.js +0 -0
  290. /package/dist/{registry → src/registry}/types.js +0 -0
  291. /package/dist/{setup → src/setup}/detect.js +0 -0
  292. /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
  293. /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
  294. /package/dist/{setup → src/setup}/steps.js +0 -0
  295. /package/dist/{sources → src/sources}/include.js +0 -0
  296. /package/dist/{sources → src/sources}/provider-factory.js +0 -0
  297. /package/dist/{sources → src/sources}/provider.js +0 -0
  298. /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
  299. /package/dist/{sources → src/sources}/providers/index.js +0 -0
  300. /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
  301. /package/dist/{sources → src/sources}/providers/npm.js +0 -0
  302. /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
  303. /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
  304. /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
  305. /package/dist/{sources → src/sources}/providers/website.js +0 -0
  306. /package/dist/{sources → src/sources}/resolve.js +0 -0
  307. /package/dist/{sources → src/sources}/types.js +0 -0
  308. /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
  309. /package/dist/{version.js → src/version.js} +0 -0
  310. /package/dist/{wiki → src/wiki}/wiki.js +0 -0
  311. /package/dist/{workflows → src/workflows}/authoring.js +0 -0
  312. /package/dist/{workflows → src/workflows}/cli.js +0 -0
  313. /package/dist/{workflows → src/workflows}/db.js +0 -0
  314. /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
  315. /package/dist/{workflows → src/workflows}/parser.js +0 -0
  316. /package/dist/{workflows → src/workflows}/renderer.js +0 -0
  317. /package/dist/{workflows → src/workflows}/runs.js +0 -0
  318. /package/dist/{workflows → src/workflows}/schema.js +0 -0
  319. /package/dist/{workflows → src/workflows}/validator.js +0 -0
@@ -0,0 +1,958 @@
1
+ /**
2
+ * Unit tests for the K-seed runner.
3
+ *
4
+ * The runner is exercised end-to-end with an injected fake spawn so no real
5
+ * opencode binary is required. We assert:
6
+ * • Cardinality: tasks × arms × seeds RunResults are produced.
7
+ * • Workspace isolation: each (arm, seed) sees a fresh cwd.
8
+ * • Cleanup: tmp dirs are torn down on success and failure.
9
+ * • Trajectory splice: goldRef + tool-call output produces the right boolean.
10
+ */
11
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+ import { runUtility } from "./runner";
15
+ import { benchMkdtemp } from "./tmp";
16
+ function asReadableStream(text) {
17
+ const bytes = new TextEncoder().encode(text);
18
+ return new ReadableStream({
19
+ start(controller) {
20
+ controller.enqueue(bytes);
21
+ controller.close();
22
+ },
23
+ });
24
+ }
25
+ function fakeSpawnFactory(agentStdoutByArm = {}, options = {}) {
26
+ const observed = { cmd: [], cwd: undefined, armSeen: [] };
27
+ let lastArmCacheHome;
28
+ const spawn = (cmd, opts) => {
29
+ observed.cmd = cmd;
30
+ observed.cwd = opts.cwd;
31
+ const isAgent = cmd[0] === "opencode";
32
+ let arm = "noakm";
33
+ if (isAgent) {
34
+ arm = opts.env?.AKM_STASH_DIR ? "akm" : "noakm";
35
+ observed.armSeen.push(arm);
36
+ lastArmCacheHome = opts.env?.XDG_CACHE_HOME;
37
+ }
38
+ const stdout = isAgent
39
+ ? ((arm === "akm" ? agentStdoutByArm.akm : agentStdoutByArm.noakm) ?? "")
40
+ : (options.verifierStdout ?? "");
41
+ const exitCode = isAgent ? (options.agentExitCode ?? 0) : (options.verifierExitCode ?? 0);
42
+ const proc = {
43
+ exitCode,
44
+ exited: Promise.resolve(exitCode),
45
+ stdout: asReadableStream(stdout),
46
+ stderr: asReadableStream(""),
47
+ stdin: null,
48
+ kill() { },
49
+ };
50
+ // For akm-arm runs, drop a synthetic events.jsonl into the cache home so
51
+ // the trajectory parser sees a feedback event when the test wants one.
52
+ if (isAgent && arm === "akm" && lastArmCacheHome && agentStdoutByArm.akm?.includes("FEEDBACK")) {
53
+ const akmDir = path.join(lastArmCacheHome, "akm");
54
+ fs.mkdirSync(akmDir, { recursive: true });
55
+ fs.writeFileSync(path.join(akmDir, "events.jsonl"), `${JSON.stringify({ schemaVersion: 1, ts: "2026-04-27T00:00:00Z", eventType: "feedback", ref: "skill:foo" })}\n`);
56
+ }
57
+ return proc;
58
+ };
59
+ return { spawn, observed };
60
+ }
61
+ function fakeTask(taskDir, overrides = {}) {
62
+ return {
63
+ id: "fake/task-a",
64
+ title: "Fake task",
65
+ domain: "fake",
66
+ difficulty: "easy",
67
+ stash: "minimal",
68
+ verifier: "regex",
69
+ expectedMatch: "ok",
70
+ budget: { tokens: 1000, wallMs: 5000 },
71
+ taskDir,
72
+ ...overrides,
73
+ };
74
+ }
75
+ describe("runUtility", () => {
76
+ let workspaceRoot;
77
+ let taskDir;
78
+ beforeAll(() => {
79
+ workspaceRoot = benchMkdtemp("bench-runner-test-");
80
+ taskDir = path.join(workspaceRoot, "task-a");
81
+ fs.mkdirSync(taskDir, { recursive: true });
82
+ // No workspace template — runs start with empty cwd, which is valid.
83
+ });
84
+ afterAll(() => {
85
+ fs.rmSync(workspaceRoot, { recursive: true, force: true });
86
+ });
87
+ test("stamps corpus identity (selectedTaskIds, taskCorpusHash, fixtures, fixtureContentHash) (#250)", async () => {
88
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
89
+ const report = await runUtility({
90
+ tasks: [fakeTask(taskDir, { id: "domain-a/task-z" }), fakeTask(taskDir, { id: "domain-a/task-a" })],
91
+ arms: ["noakm"],
92
+ model: "test-model",
93
+ seedsPerArm: 1,
94
+ spawn,
95
+ materialiseStash: false,
96
+ branch: "test-branch",
97
+ commit: "abc123",
98
+ timestamp: "2026-04-27T00:00:00Z",
99
+ });
100
+ // selectedTaskIds is sorted alphabetically.
101
+ expect(report.corpus.selectedTaskIds).toEqual(["domain-a/task-a", "domain-a/task-z"]);
102
+ expect(report.corpus.taskCorpusHash).toMatch(/^[0-9a-f]{64}$/);
103
+ expect(report.corpus.fixtureContentHash).toMatch(/^[0-9a-f]{64}$/);
104
+ // The "minimal" fixture is referenced by both fakeTasks; one entry expected.
105
+ expect(report.corpus.fixtures).toBeDefined();
106
+ expect(Object.keys(report.corpus.fixtures ?? {})).toEqual(["minimal"]);
107
+ expect(report.corpus.fixtures?.minimal).toMatch(/^[0-9a-f]{64}$/);
108
+ // Re-running with the same inputs yields the same hashes (determinism).
109
+ const report2 = await runUtility({
110
+ tasks: [fakeTask(taskDir, { id: "domain-a/task-z" }), fakeTask(taskDir, { id: "domain-a/task-a" })],
111
+ arms: ["noakm"],
112
+ model: "test-model",
113
+ seedsPerArm: 1,
114
+ spawn: fakeSpawnFactory({ noakm: "ok", akm: "ok" }).spawn,
115
+ materialiseStash: false,
116
+ branch: "test-branch",
117
+ commit: "abc123",
118
+ timestamp: "2026-04-27T00:00:00Z",
119
+ });
120
+ expect(report2.corpus.taskCorpusHash).toBe(report.corpus.taskCorpusHash);
121
+ expect(report2.corpus.fixtureContentHash).toBe(report.corpus.fixtureContentHash);
122
+ });
123
+ test("produces tasks × arms × seeds run records (cardinality)", async () => {
124
+ const { spawn, observed } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
125
+ const report = await runUtility({
126
+ tasks: [fakeTask(taskDir)],
127
+ arms: ["noakm", "akm"],
128
+ model: "test-model",
129
+ seedsPerArm: 3,
130
+ spawn,
131
+ materialiseStash: false,
132
+ branch: "test-branch",
133
+ commit: "abc123",
134
+ timestamp: "2026-04-27T00:00:00Z",
135
+ });
136
+ expect(report.tasks.length).toBe(1);
137
+ // 3 seeds × 2 arms = 6 agent invocations.
138
+ expect(observed.armSeen.length).toBe(6);
139
+ expect(observed.armSeen.filter((a) => a === "akm").length).toBe(3);
140
+ expect(observed.armSeen.filter((a) => a === "noakm").length).toBe(3);
141
+ // Per-task aggregates were filled.
142
+ const t = report.tasks[0];
143
+ expect(t).toBeDefined();
144
+ expect(t?.noakm.count).toBe(3);
145
+ expect(t?.akm.count).toBe(3);
146
+ expect(t?.noakm.passRate).toBe(1); // verifier exitCode 0 → pass
147
+ expect(t?.akm.passRate).toBe(1);
148
+ });
149
+ test("workspace isolation: each run gets a fresh cwd", async () => {
150
+ const cwds = new Set();
151
+ const spawn = (cmd, opts) => {
152
+ if (cmd[0] === "opencode" && opts.cwd)
153
+ cwds.add(opts.cwd);
154
+ return {
155
+ exitCode: 0,
156
+ exited: Promise.resolve(0),
157
+ stdout: asReadableStream("ok"),
158
+ stderr: asReadableStream(""),
159
+ stdin: null,
160
+ kill() { },
161
+ };
162
+ };
163
+ const report = await runUtility({
164
+ tasks: [fakeTask(taskDir)],
165
+ arms: ["noakm", "akm"],
166
+ model: "test",
167
+ seedsPerArm: 2,
168
+ spawn,
169
+ materialiseStash: false,
170
+ });
171
+ expect(report.tasks.length).toBe(1);
172
+ // 2 seeds × 2 arms = 4 unique cwds.
173
+ expect(cwds.size).toBe(4);
174
+ });
175
+ test("cleanup: workspace tmp dirs are removed after each run", async () => {
176
+ const cwdsObserved = new Set();
177
+ const spawn = (cmd, opts) => {
178
+ if (cmd[0] === "opencode" && opts.cwd)
179
+ cwdsObserved.add(opts.cwd);
180
+ return {
181
+ exitCode: 0,
182
+ exited: Promise.resolve(0),
183
+ stdout: asReadableStream("ok"),
184
+ stderr: asReadableStream(""),
185
+ stdin: null,
186
+ kill() { },
187
+ };
188
+ };
189
+ await runUtility({
190
+ tasks: [fakeTask(taskDir)],
191
+ arms: ["noakm"],
192
+ model: "test",
193
+ seedsPerArm: 2,
194
+ spawn,
195
+ materialiseStash: false,
196
+ });
197
+ expect(cwdsObserved.size).toBe(2);
198
+ for (const cwd of cwdsObserved) {
199
+ expect(fs.existsSync(cwd)).toBe(false);
200
+ }
201
+ });
202
+ test("cleanup happens even when verifier reports failure (workspace still removed)", async () => {
203
+ const cwdsObserved = new Set();
204
+ const spawn = (cmd, opts) => {
205
+ if (cmd[0] === "opencode" && opts.cwd)
206
+ cwdsObserved.add(opts.cwd);
207
+ const isAgent = cmd[0] === "opencode";
208
+ const exitCode = isAgent ? 0 : 1;
209
+ return {
210
+ exitCode,
211
+ exited: Promise.resolve(exitCode),
212
+ stdout: asReadableStream(isAgent ? "nope" : ""),
213
+ stderr: asReadableStream(""),
214
+ stdin: null,
215
+ kill() { },
216
+ };
217
+ };
218
+ const report = await runUtility({
219
+ tasks: [fakeTask(taskDir)],
220
+ arms: ["noakm"],
221
+ model: "test",
222
+ seedsPerArm: 2,
223
+ spawn,
224
+ materialiseStash: false,
225
+ });
226
+ expect(report.tasks[0]?.noakm.passRate).toBe(0);
227
+ for (const cwd of cwdsObserved) {
228
+ expect(fs.existsSync(cwd)).toBe(false);
229
+ }
230
+ });
231
+ test("trajectory splice: correctAssetLoaded + feedbackRecorded fill from akm-arm runs", async () => {
232
+ const akmStdout = "tool: akm show skill:foo\nFEEDBACK emitted\n";
233
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: akmStdout });
234
+ const report = await runUtility({
235
+ tasks: [fakeTask(taskDir, { goldRef: "skill:foo" })],
236
+ arms: ["noakm", "akm"],
237
+ model: "test",
238
+ seedsPerArm: 2,
239
+ spawn,
240
+ materialiseStash: false,
241
+ });
242
+ expect(report.trajectoryAkm.correctAssetLoaded).toBe(1);
243
+ expect(report.trajectoryAkm.feedbackRecorded).toBe(1);
244
+ });
245
+ test("workspace template files are copied into per-run cwd", async () => {
246
+ // Drop a sentinel file into the task's workspace/ template.
247
+ const wsTemplate = path.join(taskDir, "workspace");
248
+ fs.mkdirSync(wsTemplate, { recursive: true });
249
+ fs.writeFileSync(path.join(wsTemplate, "marker.txt"), "hello");
250
+ const seenContents = [];
251
+ const spawn = (cmd, opts) => {
252
+ if (cmd[0] === "opencode" && opts.cwd) {
253
+ const p = path.join(opts.cwd, "marker.txt");
254
+ if (fs.existsSync(p))
255
+ seenContents.push(fs.readFileSync(p, "utf8"));
256
+ }
257
+ return {
258
+ exitCode: 0,
259
+ exited: Promise.resolve(0),
260
+ stdout: asReadableStream("ok"),
261
+ stderr: asReadableStream(""),
262
+ stdin: null,
263
+ kill() { },
264
+ };
265
+ };
266
+ try {
267
+ await runUtility({
268
+ tasks: [fakeTask(taskDir)],
269
+ arms: ["noakm"],
270
+ model: "test",
271
+ seedsPerArm: 1,
272
+ spawn,
273
+ materialiseStash: false,
274
+ });
275
+ expect(seenContents).toEqual(["hello"]);
276
+ }
277
+ finally {
278
+ fs.rmSync(wsTemplate, { recursive: true, force: true });
279
+ }
280
+ });
281
+ test("default seedsPerArm is 5", async () => {
282
+ const { spawn, observed } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
283
+ await runUtility({
284
+ tasks: [fakeTask(taskDir)],
285
+ arms: ["noakm"],
286
+ model: "test",
287
+ spawn,
288
+ materialiseStash: false,
289
+ });
290
+ expect(observed.armSeen.length).toBe(5);
291
+ });
292
+ test("multi-task: each task lands in tasks[] in input order", async () => {
293
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
294
+ const taskA = fakeTask(taskDir, { id: "alpha/x", domain: "alpha" });
295
+ const taskB = fakeTask(taskDir, { id: "beta/y", domain: "beta" });
296
+ const report = await runUtility({
297
+ tasks: [taskA, taskB],
298
+ arms: ["noakm"],
299
+ model: "test",
300
+ seedsPerArm: 1,
301
+ spawn,
302
+ materialiseStash: false,
303
+ });
304
+ expect(report.tasks.map((t) => t.id)).toEqual(["alpha/x", "beta/y"]);
305
+ expect(report.corpus.domains).toBe(2);
306
+ expect(report.corpus.tasks).toBe(2);
307
+ });
308
+ // ── #267: per-arm prompt override ──────────────────────────────────────────
309
+ test("buildPrompt override forwards prompt to runOne when defined", async () => {
310
+ // Capture the agent command to assert the prompt forms its trailing arg
311
+ // (runAgent appends `prompt` as the last cmd token).
312
+ const capturedAgentCmds = [];
313
+ const spawn = (cmd, _opts) => {
314
+ const isAgent = cmd[0] === "opencode";
315
+ if (isAgent)
316
+ capturedAgentCmds.push([...cmd]);
317
+ return {
318
+ exitCode: 0,
319
+ exited: Promise.resolve(0),
320
+ stdout: asReadableStream("ok"),
321
+ stderr: asReadableStream(""),
322
+ stdin: null,
323
+ kill() { },
324
+ };
325
+ };
326
+ await runUtility({
327
+ tasks: [fakeTask(taskDir)],
328
+ arms: ["noakm", "akm"],
329
+ model: "test",
330
+ seedsPerArm: 1,
331
+ spawn,
332
+ materialiseStash: false,
333
+ buildPrompt: (task, arm) => (arm === "akm" ? `BYOS scratchpad for ${task.id}` : undefined),
334
+ });
335
+ // 1 noakm + 1 akm = 2 agent invocations.
336
+ expect(capturedAgentCmds.length).toBe(2);
337
+ const akmInvocation = capturedAgentCmds.find((c) => c.some((t) => t.startsWith("BYOS scratchpad")));
338
+ expect(akmInvocation).toBeDefined();
339
+ const noakmInvocation = capturedAgentCmds.find((c) => !c.some((t) => t.startsWith("BYOS scratchpad")));
340
+ expect(noakmInvocation).toBeDefined();
341
+ // The noakm arm received the default prompt — assert the override didn't
342
+ // leak across arms.
343
+ expect(noakmInvocation?.some((t) => t.startsWith("BYOS"))).toBe(false);
344
+ });
345
+ // ── #251: TaskMetadata.stashDirOverride ───────────────────────────────────
346
+ test("stashDirOverride: AKM_STASH_DIR points at the override, never at __no-stash__", async () => {
347
+ // Issue #251 regression. Before the fix, `runMaskedCorpus` mutated
348
+ // `task.stash` and called the runner with `materialiseStash: false`,
349
+ // which ended up wiring `AKM_STASH_DIR` to `<taskDir>/__no-stash__` —
350
+ // so masked re-runs never saw the masked content. The fix is a
351
+ // dedicated `stashDirOverride` field that the runner consults FIRST.
352
+ const observedAkmStashDirs = [];
353
+ const spawn = (cmd, opts) => {
354
+ const isAgent = cmd[0] === "opencode";
355
+ if (isAgent && opts.env?.AKM_STASH_DIR) {
356
+ observedAkmStashDirs.push(opts.env.AKM_STASH_DIR);
357
+ }
358
+ return {
359
+ exitCode: 0,
360
+ exited: Promise.resolve(0),
361
+ stdout: asReadableStream("ok"),
362
+ stderr: asReadableStream(""),
363
+ stdin: null,
364
+ kill() { },
365
+ };
366
+ };
367
+ const overrideDir = benchMkdtemp("akm-bench-251-override-");
368
+ try {
369
+ await runUtility({
370
+ tasks: [fakeTask(taskDir, { stashDirOverride: overrideDir })],
371
+ arms: ["akm"],
372
+ model: "test",
373
+ seedsPerArm: 1,
374
+ spawn,
375
+ materialiseStash: false,
376
+ });
377
+ expect(observedAkmStashDirs.length).toBe(1);
378
+ expect(observedAkmStashDirs[0]).toBe(overrideDir);
379
+ // Critical: the runner MUST NOT have fallen back to the __no-stash__
380
+ // placeholder. This is the regression guard.
381
+ expect(observedAkmStashDirs[0]?.endsWith("__no-stash__")).toBe(false);
382
+ }
383
+ finally {
384
+ fs.rmSync(overrideDir, { recursive: true, force: true });
385
+ }
386
+ });
387
+ test("stashDirOverride: takes precedence over stashDirByFixture and materialised stash", async () => {
388
+ // Resolution order acceptance criterion: per-task override beats both
389
+ // the per-fixture map and the runner's own loadFixtureStash.
390
+ const observedAkmStashDirs = [];
391
+ const spawn = (cmd, opts) => {
392
+ const isAgent = cmd[0] === "opencode";
393
+ if (isAgent && opts.env?.AKM_STASH_DIR) {
394
+ observedAkmStashDirs.push(opts.env.AKM_STASH_DIR);
395
+ }
396
+ return {
397
+ exitCode: 0,
398
+ exited: Promise.resolve(0),
399
+ stdout: asReadableStream("ok"),
400
+ stderr: asReadableStream(""),
401
+ stdin: null,
402
+ kill() { },
403
+ };
404
+ };
405
+ const overrideDir = benchMkdtemp("akm-bench-251-prec-");
406
+ const fixtureMapDir = benchMkdtemp("akm-bench-251-mapdir-");
407
+ try {
408
+ await runUtility({
409
+ tasks: [fakeTask(taskDir, { stashDirOverride: overrideDir, stash: "ignored-fixture" })],
410
+ arms: ["akm"],
411
+ model: "test",
412
+ seedsPerArm: 1,
413
+ spawn,
414
+ materialiseStash: false,
415
+ stashDirByFixture: new Map([["ignored-fixture", fixtureMapDir]]),
416
+ });
417
+ expect(observedAkmStashDirs).toEqual([overrideDir]);
418
+ }
419
+ finally {
420
+ fs.rmSync(overrideDir, { recursive: true, force: true });
421
+ fs.rmSync(fixtureMapDir, { recursive: true, force: true });
422
+ }
423
+ });
424
+ test("buildPrompt returning undefined keeps the default prompt path", async () => {
425
+ const capturedAgentCmds = [];
426
+ const spawn = (cmd, _opts) => {
427
+ if (cmd[0] === "opencode")
428
+ capturedAgentCmds.push([...cmd]);
429
+ return {
430
+ exitCode: 0,
431
+ exited: Promise.resolve(0),
432
+ stdout: asReadableStream("ok"),
433
+ stderr: asReadableStream(""),
434
+ stdin: null,
435
+ kill() { },
436
+ };
437
+ };
438
+ await runUtility({
439
+ tasks: [fakeTask(taskDir)],
440
+ arms: ["noakm"],
441
+ model: "test",
442
+ seedsPerArm: 1,
443
+ spawn,
444
+ materialiseStash: false,
445
+ buildPrompt: () => undefined,
446
+ });
447
+ // The driver's defaultPrompt() embeds the task id; assert that's what we
448
+ // got, not a custom prompt.
449
+ expect(capturedAgentCmds.length).toBe(1);
450
+ const trailing = capturedAgentCmds[0]?.[capturedAgentCmds[0].length - 1] ?? "";
451
+ expect(trailing).toContain("Task: fake/task-a");
452
+ });
453
+ // ── #261: optional synthetic arm ───────────────────────────────────────────
454
+ test("includeSynthetic: runs noakm + akm + synthetic over the same tasks/seeds", async () => {
455
+ // Spy on every agent invocation so we can assert which arm fired and
456
+ // that AKM_STASH_DIR is absent for the synthetic arm only.
457
+ const observedArms = [];
458
+ const spawn = (cmd, opts) => {
459
+ const isAgent = cmd[0] === "opencode";
460
+ if (isAgent) {
461
+ const promptArg = cmd[cmd.length - 1] ?? "";
462
+ let arm;
463
+ if (promptArg.includes("Arm: synthetic"))
464
+ arm = "synthetic";
465
+ else if (opts.env?.AKM_STASH_DIR)
466
+ arm = "akm";
467
+ else
468
+ arm = "noakm";
469
+ observedArms.push({ arm, akmStashDir: opts.env?.AKM_STASH_DIR });
470
+ }
471
+ return {
472
+ exitCode: 0,
473
+ exited: Promise.resolve(0),
474
+ stdout: asReadableStream("ok"),
475
+ stderr: asReadableStream(""),
476
+ stdin: null,
477
+ kill() { },
478
+ };
479
+ };
480
+ const report = await runUtility({
481
+ tasks: [fakeTask(taskDir)],
482
+ arms: ["noakm", "akm"],
483
+ model: "test",
484
+ seedsPerArm: 2,
485
+ spawn,
486
+ materialiseStash: false,
487
+ includeSynthetic: true,
488
+ });
489
+ // 2 seeds × 3 arms = 6 invocations.
490
+ expect(observedArms.length).toBe(6);
491
+ expect(observedArms.filter((o) => o.arm === "noakm").length).toBe(2);
492
+ expect(observedArms.filter((o) => o.arm === "akm").length).toBe(2);
493
+ expect(observedArms.filter((o) => o.arm === "synthetic").length).toBe(2);
494
+ // Synthetic-arm child env MUST NOT carry AKM_STASH_DIR.
495
+ for (const o of observedArms.filter((o) => o.arm === "synthetic")) {
496
+ expect(o.akmStashDir).toBeUndefined();
497
+ }
498
+ // Per-task synthetic metrics are spliced in; aggregateSynth populated.
499
+ expect(report.aggregateSynth).toBeDefined();
500
+ expect(report.aggregateSynth?.passRate).toBe(1);
501
+ expect(report.tasks[0]?.synthetic).toBeDefined();
502
+ expect(report.tasks[0]?.synthetic?.count).toBe(2);
503
+ });
504
+ test("default behaviour (no includeSynthetic) is byte-identical to two-arm output (no synthetic keys)", async () => {
505
+ // SNAPSHOT-STYLE TEST: run runUtility WITHOUT includeSynthetic, capture
506
+ // the JSON envelope keys, and assert no key contains 'synthetic'.
507
+ // Without this gate the byte-identical contract is unverifiable.
508
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
509
+ const report = await runUtility({
510
+ tasks: [fakeTask(taskDir)],
511
+ arms: ["noakm", "akm"],
512
+ model: "test",
513
+ seedsPerArm: 1,
514
+ spawn,
515
+ materialiseStash: false,
516
+ branch: "test-branch",
517
+ commit: "abc123",
518
+ timestamp: "2026-04-27T00:00:00Z",
519
+ });
520
+ // In-memory report shape: aggregateSynth absent.
521
+ expect(report.aggregateSynth).toBeUndefined();
522
+ expect(report.tasks[0]?.synthetic).toBeUndefined();
523
+ // Render the JSON envelope and walk every key recursively. None should
524
+ // contain 'synthetic'. We exercise the byte-identical envelope contract.
525
+ const { renderUtilityReport } = await import("./report");
526
+ const { json } = renderUtilityReport(report);
527
+ const allKeys = [];
528
+ const walk = (node) => {
529
+ if (Array.isArray(node)) {
530
+ for (const item of node)
531
+ walk(item);
532
+ }
533
+ else if (node && typeof node === "object") {
534
+ for (const [k, v] of Object.entries(node)) {
535
+ allKeys.push(k);
536
+ walk(v);
537
+ }
538
+ }
539
+ };
540
+ walk(json);
541
+ const synthMentions = allKeys.filter((k) => k.toLowerCase().includes("synth"));
542
+ expect(synthMentions).toEqual([]);
543
+ // Markdown body must not mention 'synthetic' (case-insensitive).
544
+ const { markdown } = renderUtilityReport(report);
545
+ expect(markdown.toLowerCase().includes("synthetic")).toBe(false);
546
+ });
547
+ test("includeSynthetic: arm-keyed map defaults synthetic to 'arm-not-run' when arm is absent on a task", async () => {
548
+ // Edge case: build a grouped map manually that lacks the synthetic arm
549
+ // for a given task. The runner ALWAYS dispatches the arm when the flag
550
+ // is set, so this guard is enforced through the buildReport branch:
551
+ // when includeSynth is true but no synth runs landed, the per-task
552
+ // PerTaskMetrics carries `count: 0` (zero-result aggregate) — distinct
553
+ // from "arm not run at all" which omits the field. Verify the
554
+ // distinction: report tasks WITHOUT the flag have synthetic absent.
555
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
556
+ const reportNoFlag = await runUtility({
557
+ tasks: [fakeTask(taskDir)],
558
+ arms: ["noakm", "akm"],
559
+ model: "test",
560
+ seedsPerArm: 1,
561
+ spawn,
562
+ materialiseStash: false,
563
+ });
564
+ expect(reportNoFlag.tasks[0]?.synthetic).toBeUndefined();
565
+ });
566
+ test("includeSynthetic: forwards a clear scratch-notes prompt to the synthetic arm", async () => {
567
+ // Acceptance criterion: synthetic arm has a clear scratch-notes prompt
568
+ // contract. We assert the default built-in prompt is forwarded when
569
+ // the caller does not supply a buildPrompt override.
570
+ const capturedAgentCmds = [];
571
+ const spawn = (cmd, _opts) => {
572
+ if (cmd[0] === "opencode")
573
+ capturedAgentCmds.push([...cmd]);
574
+ return {
575
+ exitCode: 0,
576
+ exited: Promise.resolve(0),
577
+ stdout: asReadableStream("ok"),
578
+ stderr: asReadableStream(""),
579
+ stdin: null,
580
+ kill() { },
581
+ };
582
+ };
583
+ await runUtility({
584
+ tasks: [fakeTask(taskDir)],
585
+ arms: ["noakm", "akm"],
586
+ model: "test",
587
+ seedsPerArm: 1,
588
+ spawn,
589
+ materialiseStash: false,
590
+ includeSynthetic: true,
591
+ });
592
+ const synthCmd = capturedAgentCmds.find((c) => c[c.length - 1]?.includes("Arm: synthetic"));
593
+ expect(synthCmd).toBeDefined();
594
+ const synthPrompt = synthCmd?.[synthCmd.length - 1] ?? "";
595
+ expect(synthPrompt).toContain("Bring Your Own Skills");
596
+ expect(synthPrompt).toContain("scratchpad");
597
+ expect(synthPrompt).toContain("AKM_STASH_DIR is intentionally absent");
598
+ });
599
+ test("includeSynthetic: caller buildPrompt override wins for synthetic arm", async () => {
600
+ // When the caller threads a buildPrompt override that returns a string
601
+ // for the synthetic arm, the runner forwards that override verbatim
602
+ // instead of the built-in scratch-notes prompt. This preserves the
603
+ // Track B `runEvolve` integration where synthetic arm prompts are
604
+ // built by `buildSyntheticPrompt(task.id)`.
605
+ const capturedAgentCmds = [];
606
+ const spawn = (cmd, _opts) => {
607
+ if (cmd[0] === "opencode")
608
+ capturedAgentCmds.push([...cmd]);
609
+ return {
610
+ exitCode: 0,
611
+ exited: Promise.resolve(0),
612
+ stdout: asReadableStream("ok"),
613
+ stderr: asReadableStream(""),
614
+ stdin: null,
615
+ kill() { },
616
+ };
617
+ };
618
+ await runUtility({
619
+ tasks: [fakeTask(taskDir)],
620
+ arms: ["noakm", "akm"],
621
+ model: "test",
622
+ seedsPerArm: 1,
623
+ spawn,
624
+ materialiseStash: false,
625
+ includeSynthetic: true,
626
+ buildPrompt: (task, arm) => (arm === "synthetic" ? `OVERRIDE for ${task.id}` : undefined),
627
+ });
628
+ const synthCmd = capturedAgentCmds.find((c) => c[c.length - 1]?.startsWith("OVERRIDE for"));
629
+ expect(synthCmd).toBeDefined();
630
+ // The built-in scratch-notes contract MUST NOT have leaked through.
631
+ expect(synthCmd?.[synthCmd.length - 1]).not.toContain("Bring Your Own Skills");
632
+ });
633
+ test("includeSynthetic: report carries akm_over_synthetic_lift in aggregate", async () => {
634
+ // akm + noakm pass (regex verifier matches "ok"); synthetic fails (we
635
+ // emit "nope" on the synthetic agent stdout so the regex verifier
636
+ // rejects). The fake task uses regex/expectedMatch="ok" — see fakeTask().
637
+ const spawn = (cmd, _opts) => {
638
+ const isAgent = cmd[0] === "opencode";
639
+ if (!isAgent) {
640
+ return {
641
+ exitCode: 0,
642
+ exited: Promise.resolve(0),
643
+ stdout: asReadableStream(""),
644
+ stderr: asReadableStream(""),
645
+ stdin: null,
646
+ kill() { },
647
+ };
648
+ }
649
+ const promptArg = cmd[cmd.length - 1] ?? "";
650
+ const isSynth = promptArg.includes("Arm: synthetic");
651
+ const stdout = isSynth ? "nope" : "ok";
652
+ return {
653
+ exitCode: 0,
654
+ exited: Promise.resolve(0),
655
+ stdout: asReadableStream(stdout),
656
+ stderr: asReadableStream(""),
657
+ stdin: null,
658
+ kill() { },
659
+ };
660
+ };
661
+ const report = await runUtility({
662
+ tasks: [fakeTask(taskDir)],
663
+ arms: ["noakm", "akm"],
664
+ model: "test",
665
+ seedsPerArm: 2,
666
+ spawn,
667
+ materialiseStash: false,
668
+ includeSynthetic: true,
669
+ });
670
+ expect(report.aggregateAkm.passRate).toBe(1);
671
+ expect(report.aggregateSynth?.passRate).toBe(0);
672
+ const { renderUtilityReport } = await import("./report");
673
+ const { json, markdown } = renderUtilityReport(report);
674
+ const aggregate = json.aggregate;
675
+ expect(aggregate.synthetic).toBeDefined();
676
+ expect(aggregate.akm_over_synthetic_lift).toBe(1);
677
+ // Markdown should mention the lift.
678
+ expect(markdown).toContain("akm_over_synthetic_lift");
679
+ });
680
+ test("includeSynthetic: markdown surfaces a warning when AKM fails to beat synthetic", async () => {
681
+ // Acceptance criterion: utility markdown summarizes when AKM fails to
682
+ // beat synthetic notes. Construct a scenario where akm_pass_rate <=
683
+ // synth_pass_rate — regex verifier expects "ok"; AKM agent emits "nope"
684
+ // (fail), synthetic + noakm emit "ok" (pass).
685
+ const spawn = (cmd, opts) => {
686
+ const isAgent = cmd[0] === "opencode";
687
+ if (!isAgent) {
688
+ return {
689
+ exitCode: 0,
690
+ exited: Promise.resolve(0),
691
+ stdout: asReadableStream(""),
692
+ stderr: asReadableStream(""),
693
+ stdin: null,
694
+ kill() { },
695
+ };
696
+ }
697
+ const promptArg = cmd[cmd.length - 1] ?? "";
698
+ const isSynth = promptArg.includes("Arm: synthetic");
699
+ const isAkm = !isSynth && opts.env?.AKM_STASH_DIR !== undefined;
700
+ const stdout = isAkm ? "nope" : "ok";
701
+ return {
702
+ exitCode: 0,
703
+ exited: Promise.resolve(0),
704
+ stdout: asReadableStream(stdout),
705
+ stderr: asReadableStream(""),
706
+ stdin: null,
707
+ kill() { },
708
+ };
709
+ };
710
+ const report = await runUtility({
711
+ tasks: [fakeTask(taskDir)],
712
+ arms: ["noakm", "akm"],
713
+ model: "test",
714
+ seedsPerArm: 2,
715
+ spawn,
716
+ materialiseStash: false,
717
+ includeSynthetic: true,
718
+ });
719
+ expect(report.aggregateAkm.passRate).toBe(0);
720
+ expect(report.aggregateSynth?.passRate).toBe(1);
721
+ const { renderUtilityReport } = await import("./report");
722
+ const { markdown } = renderUtilityReport(report);
723
+ expect(markdown).toContain(":warning:");
724
+ expect(markdown).toContain("AKM did not beat the synthetic-notes baseline");
725
+ });
726
+ });
727
+ // ── Workflow compliance plumbing (#257) ────────────────────────────────────
728
+ describe("runUtility workflow compliance (#257)", () => {
729
+ let workspaceRoot;
730
+ let taskDir;
731
+ beforeAll(() => {
732
+ workspaceRoot = benchMkdtemp("bench-runner-wf-");
733
+ taskDir = path.join(workspaceRoot, "task");
734
+ fs.mkdirSync(taskDir, { recursive: true });
735
+ });
736
+ afterAll(() => {
737
+ fs.rmSync(workspaceRoot, { recursive: true, force: true });
738
+ });
739
+ test("loads workflow specs from the default directory and stamps workflowChecks on the report", async () => {
740
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
741
+ const report = await runUtility({
742
+ tasks: [
743
+ // domain-name needs to match a task_domain in at least one shipping spec
744
+ // so the evaluator emits applicable checks (not_applicable rows are
745
+ // expected for the rest).
746
+ fakeTask(taskDir, { id: "docker-homelab/redis", domain: "docker-homelab" }),
747
+ ],
748
+ arms: ["akm"],
749
+ model: "test",
750
+ seedsPerArm: 1,
751
+ spawn,
752
+ materialiseStash: false,
753
+ });
754
+ expect(Array.isArray(report.workflowChecks)).toBe(true);
755
+ // At least one shipping spec applies to docker-homelab → some checks emitted.
756
+ expect((report.workflowChecks ?? []).length).toBeGreaterThan(0);
757
+ });
758
+ test("workflowsDir: '' disables workflow evaluation and yields no workflowChecks", async () => {
759
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
760
+ const report = await runUtility({
761
+ tasks: [fakeTask(taskDir)],
762
+ arms: ["akm"],
763
+ model: "test",
764
+ seedsPerArm: 1,
765
+ spawn,
766
+ materialiseStash: false,
767
+ workflowsDir: "",
768
+ });
769
+ expect(report.workflowChecks).toEqual([]);
770
+ });
771
+ test("missing workflowsDir is recorded as a warning, not a crash", async () => {
772
+ const { setQuiet, resetQuiet } = await import("../../src/core/warn");
773
+ setQuiet(true);
774
+ try {
775
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
776
+ const report = await runUtility({
777
+ tasks: [fakeTask(taskDir)],
778
+ arms: ["akm"],
779
+ model: "test",
780
+ seedsPerArm: 1,
781
+ spawn,
782
+ materialiseStash: false,
783
+ workflowsDir: "/path/that/does/not/exist",
784
+ });
785
+ expect(report.workflowChecks).toEqual([]);
786
+ const hasWarn = report.warnings.some((w) => w.includes("workflow specs"));
787
+ expect(hasWarn).toBe(true);
788
+ }
789
+ finally {
790
+ resetQuiet();
791
+ }
792
+ });
793
+ test("runner attaches taskOutcome to each workflowCheck so the cross-tab can attribute it", async () => {
794
+ const { spawn } = fakeSpawnFactory({ noakm: "ok", akm: "ok" });
795
+ const report = await runUtility({
796
+ tasks: [fakeTask(taskDir, { id: "docker-homelab/redis", domain: "docker-homelab" })],
797
+ arms: ["akm"],
798
+ model: "test",
799
+ seedsPerArm: 1,
800
+ spawn,
801
+ materialiseStash: false,
802
+ });
803
+ const c = (report.workflowChecks ?? [])[0];
804
+ expect(c).toBeDefined();
805
+ expect(typeof c?.taskOutcome).toBe("string");
806
+ });
807
+ test("passes search/result and test-presence flags into workflow evaluation", async () => {
808
+ const workflowsDir = benchMkdtemp("akm-bench-workflow-flags-");
809
+ const spawn = (cmd, opts) => {
810
+ const isAgent = cmd[0] === "opencode";
811
+ if (isAgent && opts.env?.XDG_CACHE_HOME) {
812
+ const akmDir = path.join(opts.env.XDG_CACHE_HOME, "akm");
813
+ fs.mkdirSync(akmDir, { recursive: true });
814
+ fs.writeFileSync(path.join(akmDir, "events.jsonl"), [
815
+ JSON.stringify({
816
+ schemaVersion: 1,
817
+ ts: "2026-04-27T00:00:00Z",
818
+ eventType: "search",
819
+ metadata: { query: "deploy", resultRefs: ["skill:foo"] },
820
+ }),
821
+ JSON.stringify({
822
+ schemaVersion: 1,
823
+ ts: "2026-04-27T00:00:01Z",
824
+ eventType: "propose_invoked",
825
+ }),
826
+ JSON.stringify({
827
+ schemaVersion: 1,
828
+ ts: "2026-04-27T00:00:02Z",
829
+ eventType: "promoted",
830
+ }),
831
+ ].join("\n"));
832
+ }
833
+ return {
834
+ exitCode: 0,
835
+ exited: Promise.resolve(0),
836
+ stdout: asReadableStream("ok"),
837
+ stderr: asReadableStream(""),
838
+ stdin: null,
839
+ kill() { },
840
+ };
841
+ };
842
+ try {
843
+ fs.writeFileSync(path.join(workflowsDir, "search.yaml"), `id: search-guard
844
+ title: search guard
845
+ applies_to:
846
+ arms: ["akm"]
847
+ required_sequence:
848
+ - event: akm_search
849
+ - event: akm_show
850
+ required_if: search_has_relevant_result
851
+ scoring:
852
+ required_steps_weight: 0.7
853
+ forbidden_steps_weight: 0.2
854
+ evidence_quality_weight: 0.1
855
+ `, "utf8");
856
+ fs.writeFileSync(path.join(workflowsDir, "tests.yaml"), `id: tests-guard
857
+ title: tests guard
858
+ applies_to:
859
+ arms: ["akm"]
860
+ required_sequence:
861
+ - event: akm_propose
862
+ - event: test_run
863
+ required_if: task_has_tests
864
+ - event: akm_proposal_accept
865
+ scoring:
866
+ required_steps_weight: 0.7
867
+ forbidden_steps_weight: 0.2
868
+ evidence_quality_weight: 0.1
869
+ `, "utf8");
870
+ const testsDir = path.join(taskDir, "tests");
871
+ fs.mkdirSync(testsDir, { recursive: true });
872
+ fs.writeFileSync(path.join(testsDir, "test_sample.py"), "def test_ok():\n assert True\n");
873
+ const report = await runUtility({
874
+ tasks: [fakeTask(taskDir, { verifier: "pytest", goldRef: "skill:foo" })],
875
+ arms: ["akm"],
876
+ model: "test",
877
+ seedsPerArm: 1,
878
+ spawn,
879
+ materialiseStash: false,
880
+ workflowsDir,
881
+ });
882
+ const byId = new Map((report.workflowChecks ?? []).map((check) => [check.workflowId, check]));
883
+ expect(byId.get("search-guard")?.violations.some((v) => v.code === "missing_required_event")).toBe(true);
884
+ expect(byId.get("tests-guard")?.violations.some((v) => v.code === "missing_required_event")).toBe(true);
885
+ }
886
+ finally {
887
+ fs.rmSync(workflowsDir, { recursive: true, force: true });
888
+ fs.rmSync(path.join(taskDir, "tests"), { recursive: true, force: true });
889
+ }
890
+ });
891
+ test("skips required_if workflow steps when runner-derived flags are false", async () => {
892
+ const workflowsDir = benchMkdtemp("akm-bench-workflow-flags-off-");
893
+ const spawn = (cmd, opts) => {
894
+ const isAgent = cmd[0] === "opencode";
895
+ if (isAgent && opts.env?.XDG_CACHE_HOME) {
896
+ const akmDir = path.join(opts.env.XDG_CACHE_HOME, "akm");
897
+ fs.mkdirSync(akmDir, { recursive: true });
898
+ fs.writeFileSync(path.join(akmDir, "events.jsonl"), `${JSON.stringify({
899
+ schemaVersion: 1,
900
+ ts: "2026-04-27T00:00:00Z",
901
+ eventType: "search",
902
+ metadata: { query: "deploy", resultRefs: ["skill:other"] },
903
+ })}\n`);
904
+ }
905
+ return {
906
+ exitCode: 0,
907
+ exited: Promise.resolve(0),
908
+ stdout: asReadableStream("ok"),
909
+ stderr: asReadableStream(""),
910
+ stdin: null,
911
+ kill() { },
912
+ };
913
+ };
914
+ try {
915
+ fs.writeFileSync(path.join(workflowsDir, "search.yaml"), `id: search-guard
916
+ title: search guard
917
+ applies_to:
918
+ arms: ["akm"]
919
+ required_sequence:
920
+ - event: akm_search
921
+ - event: akm_show
922
+ required_if: search_has_relevant_result
923
+ scoring:
924
+ required_steps_weight: 0.7
925
+ forbidden_steps_weight: 0.2
926
+ evidence_quality_weight: 0.1
927
+ `, "utf8");
928
+ fs.writeFileSync(path.join(workflowsDir, "tests.yaml"), `id: tests-guard
929
+ title: tests guard
930
+ applies_to:
931
+ arms: ["akm"]
932
+ required_sequence:
933
+ - event: akm_search
934
+ - event: test_run
935
+ required_if: task_has_tests
936
+ scoring:
937
+ required_steps_weight: 0.7
938
+ forbidden_steps_weight: 0.2
939
+ evidence_quality_weight: 0.1
940
+ `, "utf8");
941
+ const report = await runUtility({
942
+ tasks: [fakeTask(taskDir, { verifier: "regex", goldRef: "skill:foo" })],
943
+ arms: ["akm"],
944
+ model: "test",
945
+ seedsPerArm: 1,
946
+ spawn,
947
+ materialiseStash: false,
948
+ workflowsDir,
949
+ });
950
+ const byId = new Map((report.workflowChecks ?? []).map((check) => [check.workflowId, check]));
951
+ expect(byId.get("search-guard")?.status).toBe("pass");
952
+ expect(byId.get("tests-guard")?.status).toBe("pass");
953
+ }
954
+ finally {
955
+ fs.rmSync(workflowsDir, { recursive: true, force: true });
956
+ }
957
+ });
958
+ });