akm-cli 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{src/cli.js → cli.js} +22 -8
  3. package/dist/{src/commands → commands}/installed-stashes.js +1 -1
  4. package/dist/{src/commands → commands}/source-add.js +1 -1
  5. package/dist/{src/core → core}/common.js +16 -1
  6. package/dist/{src/core → core}/config.js +5 -2
  7. package/dist/{src/indexer → indexer}/db-search.js +16 -1
  8. package/dist/{src/indexer → indexer}/graph-extraction.js +5 -3
  9. package/dist/{src/indexer → indexer}/indexer.js +27 -11
  10. package/dist/{src/indexer → indexer}/memory-inference.js +47 -58
  11. package/dist/{src/indexer → indexer}/search-source.js +1 -1
  12. package/dist/{src/llm → llm}/client.js +61 -1
  13. package/dist/{src/llm → llm}/embedder.js +8 -5
  14. package/dist/{src/llm → llm}/embedders/local.js +8 -2
  15. package/dist/{src/llm → llm}/embedders/remote.js +4 -2
  16. package/dist/{src/llm → llm}/graph-extract.js +4 -4
  17. package/dist/llm/memory-infer.js +114 -0
  18. package/dist/{src/llm → llm}/metadata-enhance.js +2 -2
  19. package/dist/{src/output → output}/cli-hints.js +2 -0
  20. package/dist/{src/setup → setup}/setup.js +30 -20
  21. package/dist/sources/providers/website.js +27 -0
  22. package/dist/{src/sources/providers/website.js → sources/website-ingest.js} +38 -51
  23. package/docs/README.md +7 -0
  24. package/docs/migration/release-notes/0.7.0.md +14 -0
  25. package/package.json +11 -8
  26. package/dist/src/llm/memory-infer.js +0 -86
  27. package/dist/tests/add-website-source.test.js +0 -119
  28. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  29. package/dist/tests/agent/agent-config.test.js +0 -221
  30. package/dist/tests/agent/agent-detect.test.js +0 -100
  31. package/dist/tests/agent/agent-spawn.test.js +0 -234
  32. package/dist/tests/agent-output.test.js +0 -186
  33. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  34. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  35. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  36. package/dist/tests/asset-ref.test.js +0 -192
  37. package/dist/tests/asset-registry.test.js +0 -103
  38. package/dist/tests/asset-spec.test.js +0 -241
  39. package/dist/tests/bench/attribution.test.js +0 -996
  40. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  41. package/dist/tests/bench/cleanup.js +0 -234
  42. package/dist/tests/bench/cleanup.test.js +0 -166
  43. package/dist/tests/bench/cli.js +0 -1018
  44. package/dist/tests/bench/cli.test.js +0 -445
  45. package/dist/tests/bench/compare.test.js +0 -556
  46. package/dist/tests/bench/corpus.js +0 -317
  47. package/dist/tests/bench/corpus.test.js +0 -258
  48. package/dist/tests/bench/doctor.js +0 -525
  49. package/dist/tests/bench/driver.js +0 -401
  50. package/dist/tests/bench/driver.test.js +0 -584
  51. package/dist/tests/bench/environment.js +0 -233
  52. package/dist/tests/bench/environment.test.js +0 -199
  53. package/dist/tests/bench/evolve-metrics.js +0 -179
  54. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  55. package/dist/tests/bench/evolve.js +0 -647
  56. package/dist/tests/bench/evolve.test.js +0 -624
  57. package/dist/tests/bench/failure-modes.test.js +0 -349
  58. package/dist/tests/bench/feedback-integrity.test.js +0 -457
  59. package/dist/tests/bench/leakage.test.js +0 -228
  60. package/dist/tests/bench/learning-curve.test.js +0 -134
  61. package/dist/tests/bench/metrics.js +0 -2395
  62. package/dist/tests/bench/metrics.test.js +0 -1150
  63. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  64. package/dist/tests/bench/opencode-config.js +0 -194
  65. package/dist/tests/bench/opencode-config.test.js +0 -370
  66. package/dist/tests/bench/report.js +0 -1885
  67. package/dist/tests/bench/report.test.js +0 -1038
  68. package/dist/tests/bench/run-config.js +0 -355
  69. package/dist/tests/bench/run-config.test.js +0 -298
  70. package/dist/tests/bench/run-curate-test.js +0 -32
  71. package/dist/tests/bench/run-failing-tasks.js +0 -56
  72. package/dist/tests/bench/run-full-bench.js +0 -51
  73. package/dist/tests/bench/run-items36-targeted.js +0 -69
  74. package/dist/tests/bench/run-nano-quick.js +0 -42
  75. package/dist/tests/bench/run-waveg-targeted.js +0 -62
  76. package/dist/tests/bench/runner.js +0 -699
  77. package/dist/tests/bench/runner.test.js +0 -958
  78. package/dist/tests/bench/search-bridge.test.js +0 -331
  79. package/dist/tests/bench/tmp.js +0 -131
  80. package/dist/tests/bench/trajectory.js +0 -116
  81. package/dist/tests/bench/trajectory.test.js +0 -127
  82. package/dist/tests/bench/verifier.js +0 -114
  83. package/dist/tests/bench/verifier.test.js +0 -118
  84. package/dist/tests/bench/workflow-evaluator.js +0 -557
  85. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  86. package/dist/tests/bench/workflow-spec.js +0 -345
  87. package/dist/tests/bench/workflow-spec.test.js +0 -363
  88. package/dist/tests/bench/workflow-trace.js +0 -472
  89. package/dist/tests/bench/workflow-trace.test.js +0 -254
  90. package/dist/tests/benchmark-search-quality.js +0 -536
  91. package/dist/tests/benchmark-suite.js +0 -1441
  92. package/dist/tests/capture-cli.test.js +0 -112
  93. package/dist/tests/cli-errors.test.js +0 -204
  94. package/dist/tests/commands/events.test.js +0 -370
  95. package/dist/tests/commands/history.test.js +0 -418
  96. package/dist/tests/commands/import.test.js +0 -103
  97. package/dist/tests/commands/proposal-cli.test.js +0 -209
  98. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  99. package/dist/tests/commands/remember.test.js +0 -97
  100. package/dist/tests/commands/scope-flags.test.js +0 -300
  101. package/dist/tests/commands/search.test.js +0 -537
  102. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  103. package/dist/tests/commands/show.test.js +0 -294
  104. package/dist/tests/common.test.js +0 -266
  105. package/dist/tests/completions.test.js +0 -142
  106. package/dist/tests/config-cli.test.js +0 -193
  107. package/dist/tests/config-llm-features.test.js +0 -139
  108. package/dist/tests/config.test.js +0 -569
  109. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  110. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  111. package/dist/tests/contracts/spec-helpers.js +0 -46
  112. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  113. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  114. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  115. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  116. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  117. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  118. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  119. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  120. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  121. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  122. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  123. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  124. package/dist/tests/core/write-source.test.js +0 -366
  125. package/dist/tests/curate-command.test.js +0 -87
  126. package/dist/tests/db-scoring.test.js +0 -201
  127. package/dist/tests/db.test.js +0 -654
  128. package/dist/tests/distill-cli-flag.test.js +0 -208
  129. package/dist/tests/distill.test.js +0 -515
  130. package/dist/tests/docker-install.test.js +0 -120
  131. package/dist/tests/e2e.test.js +0 -1419
  132. package/dist/tests/embedder.test.js +0 -340
  133. package/dist/tests/embedding-model-config.test.js +0 -379
  134. package/dist/tests/feedback-command.test.js +0 -172
  135. package/dist/tests/file-context.test.js +0 -552
  136. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  137. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  138. package/dist/tests/fixtures/stashes/load.js +0 -166
  139. package/dist/tests/fixtures/stashes/load.test.js +0 -97
  140. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  141. package/dist/tests/frontmatter.test.js +0 -190
  142. package/dist/tests/fts-field-weighting.test.js +0 -254
  143. package/dist/tests/fuzzy-search.test.js +0 -230
  144. package/dist/tests/git-provider-clone.test.js +0 -45
  145. package/dist/tests/github.test.js +0 -161
  146. package/dist/tests/graph-boost-ranking.test.js +0 -305
  147. package/dist/tests/graph-extraction.test.js +0 -282
  148. package/dist/tests/helpers/usage-events.js +0 -8
  149. package/dist/tests/index-pass-llm.test.js +0 -161
  150. package/dist/tests/indexer.test.js +0 -570
  151. package/dist/tests/info-command.test.js +0 -166
  152. package/dist/tests/init.test.js +0 -69
  153. package/dist/tests/install-script.test.js +0 -246
  154. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  155. package/dist/tests/issue-36-repro.test.js +0 -304
  156. package/dist/tests/issues-191-194.test.js +0 -160
  157. package/dist/tests/lesson-lint.test.js +0 -111
  158. package/dist/tests/llm-client.test.js +0 -115
  159. package/dist/tests/llm-feature-gate.test.js +0 -151
  160. package/dist/tests/llm.test.js +0 -139
  161. package/dist/tests/lockfile.test.js +0 -216
  162. package/dist/tests/manifest.test.js +0 -205
  163. package/dist/tests/markdown.test.js +0 -126
  164. package/dist/tests/matchers-unit.test.js +0 -189
  165. package/dist/tests/memory-inference.test.js +0 -299
  166. package/dist/tests/merge-scoring.test.js +0 -136
  167. package/dist/tests/metadata.test.js +0 -313
  168. package/dist/tests/migration-help.test.js +0 -89
  169. package/dist/tests/origin-resolve.test.js +0 -124
  170. package/dist/tests/output-baseline.test.js +0 -218
  171. package/dist/tests/output-shapes-unit.test.js +0 -478
  172. package/dist/tests/parallel-search.test.js +0 -272
  173. package/dist/tests/parameter-metadata.test.js +0 -365
  174. package/dist/tests/paths.test.js +0 -177
  175. package/dist/tests/progressive-disclosure.test.js +0 -280
  176. package/dist/tests/proposals.test.js +0 -279
  177. package/dist/tests/proposed-quality.test.js +0 -271
  178. package/dist/tests/provider-registry.test.js +0 -32
  179. package/dist/tests/ranking-regression.test.js +0 -548
  180. package/dist/tests/reflect-propose.test.js +0 -455
  181. package/dist/tests/registry-build-index.test.js +0 -394
  182. package/dist/tests/registry-cli.test.js +0 -290
  183. package/dist/tests/registry-index-v2.test.js +0 -430
  184. package/dist/tests/registry-install.test.js +0 -728
  185. package/dist/tests/registry-providers/parity.test.js +0 -189
  186. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  187. package/dist/tests/registry-providers/static-index.test.js +0 -238
  188. package/dist/tests/registry-resolve.test.js +0 -126
  189. package/dist/tests/registry-search.test.js +0 -923
  190. package/dist/tests/remember-frontmatter.test.js +0 -378
  191. package/dist/tests/remember-unit.test.js +0 -123
  192. package/dist/tests/ripgrep-install.test.js +0 -251
  193. package/dist/tests/ripgrep-resolve.test.js +0 -108
  194. package/dist/tests/ripgrep.test.js +0 -163
  195. package/dist/tests/save-command.test.js +0 -94
  196. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  197. package/dist/tests/scoring-pipeline.test.js +0 -648
  198. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  199. package/dist/tests/self-update.test.js +0 -442
  200. package/dist/tests/semantic-search-e2e.test.js +0 -512
  201. package/dist/tests/semantic-status.test.js +0 -471
  202. package/dist/tests/setup-run.integration.js +0 -877
  203. package/dist/tests/setup-wizard.test.js +0 -198
  204. package/dist/tests/setup.test.js +0 -131
  205. package/dist/tests/source-add.test.js +0 -11
  206. package/dist/tests/source-clone.test.js +0 -254
  207. package/dist/tests/source-manage.test.js +0 -366
  208. package/dist/tests/source-providers/filesystem.test.js +0 -82
  209. package/dist/tests/source-providers/git.test.js +0 -252
  210. package/dist/tests/source-providers/website.test.js +0 -128
  211. package/dist/tests/source-qa-fixes.test.js +0 -286
  212. package/dist/tests/source-registry.test.js +0 -350
  213. package/dist/tests/source-resolve.test.js +0 -100
  214. package/dist/tests/source-source.test.js +0 -281
  215. package/dist/tests/source.test.js +0 -533
  216. package/dist/tests/tar-utils-scan.test.js +0 -73
  217. package/dist/tests/toggle-components.test.js +0 -73
  218. package/dist/tests/usage-telemetry.test.js +0 -265
  219. package/dist/tests/utility-scoring.test.js +0 -558
  220. package/dist/tests/vault-load-error.test.js +0 -78
  221. package/dist/tests/vault-qa-fixes.test.js +0 -194
  222. package/dist/tests/vault.test.js +0 -429
  223. package/dist/tests/vector-search.test.js +0 -608
  224. package/dist/tests/walker.test.js +0 -252
  225. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  226. package/dist/tests/wave2-cluster-d.test.js +0 -180
  227. package/dist/tests/wave2-cluster-e.test.js +0 -179
  228. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  229. package/dist/tests/wiki.test.js +0 -529
  230. package/dist/tests/workflow-cli.test.js +0 -271
  231. package/dist/tests/workflow-markdown.test.js +0 -171
  232. package/dist/tests/workflow-path-escape.test.js +0 -132
  233. package/dist/tests/workflow-qa-fixes.test.js +0 -395
  234. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  235. /package/dist/{src/commands → commands}/completions.js +0 -0
  236. /package/dist/{src/commands → commands}/config-cli.js +0 -0
  237. /package/dist/{src/commands → commands}/curate.js +0 -0
  238. /package/dist/{src/commands → commands}/distill.js +0 -0
  239. /package/dist/{src/commands → commands}/events.js +0 -0
  240. /package/dist/{src/commands → commands}/history.js +0 -0
  241. /package/dist/{src/commands → commands}/info.js +0 -0
  242. /package/dist/{src/commands → commands}/init.js +0 -0
  243. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  244. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  245. /package/dist/{src/commands → commands}/proposal.js +0 -0
  246. /package/dist/{src/commands → commands}/propose.js +0 -0
  247. /package/dist/{src/commands → commands}/reflect.js +0 -0
  248. /package/dist/{src/commands → commands}/registry-search.js +0 -0
  249. /package/dist/{src/commands → commands}/remember.js +0 -0
  250. /package/dist/{src/commands → commands}/search.js +0 -0
  251. /package/dist/{src/commands → commands}/self-update.js +0 -0
  252. /package/dist/{src/commands → commands}/show.js +0 -0
  253. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  254. /package/dist/{src/commands → commands}/source-manage.js +0 -0
  255. /package/dist/{src/commands → commands}/vault.js +0 -0
  256. /package/dist/{src/core → core}/asset-ref.js +0 -0
  257. /package/dist/{src/core → core}/asset-registry.js +0 -0
  258. /package/dist/{src/core → core}/asset-spec.js +0 -0
  259. /package/dist/{src/core → core}/errors.js +0 -0
  260. /package/dist/{src/core → core}/events.js +0 -0
  261. /package/dist/{src/core → core}/frontmatter.js +0 -0
  262. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  263. /package/dist/{src/core → core}/markdown.js +0 -0
  264. /package/dist/{src/core → core}/paths.js +0 -0
  265. /package/dist/{src/core → core}/proposals.js +0 -0
  266. /package/dist/{src/core → core}/warn.js +0 -0
  267. /package/dist/{src/core → core}/write-source.js +0 -0
  268. /package/dist/{src/indexer → indexer}/db.js +0 -0
  269. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  270. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  271. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  272. /package/dist/{src/indexer → indexer}/matchers.js +0 -0
  273. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  274. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  275. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  276. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  277. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  278. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  279. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  280. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  281. /package/dist/{src/integrations → integrations}/agent/profiles.js +0 -0
  282. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  283. /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
  284. /package/dist/{src/integrations → integrations}/github.js +0 -0
  285. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  286. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  287. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  288. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  289. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  290. /package/dist/{src/output → output}/context.js +0 -0
  291. /package/dist/{src/output → output}/renderers.js +0 -0
  292. /package/dist/{src/output → output}/shapes.js +0 -0
  293. /package/dist/{src/output → output}/text.js +0 -0
  294. /package/dist/{src/registry → registry}/build-index.js +0 -0
  295. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  296. /package/dist/{src/registry → registry}/factory.js +0 -0
  297. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  298. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  299. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  300. /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
  301. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  302. /package/dist/{src/registry → registry}/resolve.js +0 -0
  303. /package/dist/{src/registry → registry}/types.js +0 -0
  304. /package/dist/{src/setup → setup}/detect.js +0 -0
  305. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  306. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  307. /package/dist/{src/setup → setup}/steps.js +0 -0
  308. /package/dist/{src/sources → sources}/include.js +0 -0
  309. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  310. /package/dist/{src/sources → sources}/provider.js +0 -0
  311. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  312. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  313. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  314. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  315. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  316. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  317. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  318. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  319. /package/dist/{src/sources → sources}/resolve.js +0 -0
  320. /package/dist/{src/sources → sources}/types.js +0 -0
  321. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  322. /package/dist/{src/version.js → version.js} +0 -0
  323. /package/dist/{src/wiki → wiki}/wiki.js +0 -0
  324. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  325. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  326. /package/dist/{src/workflows → workflows}/db.js +0 -0
  327. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  328. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  329. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  330. /package/dist/{src/workflows → workflows}/runs.js +0 -0
  331. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  332. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,958 +0,0 @@
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
- });