akm-cli 0.7.0-rc1 → 0.7.1

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 (314) hide show
  1. package/dist/{src/cli.js → cli.js} +100 -16
  2. package/dist/{src/commands → commands}/config-cli.js +42 -0
  3. package/dist/{src/commands → commands}/history.js +78 -7
  4. package/dist/{src/commands → commands}/registry-search.js +69 -6
  5. package/dist/{src/commands → commands}/search.js +30 -3
  6. package/dist/{src/commands → commands}/show.js +29 -0
  7. package/dist/{src/commands → commands}/source-add.js +5 -1
  8. package/dist/{src/commands → commands}/source-manage.js +7 -1
  9. package/dist/{src/core → core}/config.js +28 -0
  10. package/dist/{src/indexer → indexer}/db-search.js +1 -0
  11. package/dist/{src/indexer → indexer}/indexer.js +16 -2
  12. package/dist/{src/indexer → indexer}/matchers.js +1 -1
  13. package/dist/{src/indexer → indexer}/search-source.js +4 -2
  14. package/dist/{src/integrations → integrations}/agent/profiles.js +1 -1
  15. package/dist/{src/integrations → integrations}/agent/spawn.js +67 -16
  16. package/dist/{src/integrations → integrations}/github.js +9 -3
  17. package/dist/{src/llm → llm}/embedders/remote.js +37 -3
  18. package/dist/{src/output → output}/cli-hints.js +15 -2
  19. package/dist/{src/output → output}/renderers.js +3 -1
  20. package/dist/{src/output → output}/shapes.js +8 -1
  21. package/dist/{src/output → output}/text.js +156 -3
  22. package/dist/{src/registry → registry}/build-index.js +5 -4
  23. package/dist/{src/registry → registry}/providers/static-index.js +3 -1
  24. package/dist/{src/setup → setup}/setup.js +9 -0
  25. package/dist/{src/wiki → wiki}/wiki.js +54 -6
  26. package/dist/{src/workflows → workflows}/runs.js +37 -3
  27. package/package.json +8 -8
  28. package/dist/tests/add-website-source.test.js +0 -119
  29. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  30. package/dist/tests/agent/agent-config.test.js +0 -221
  31. package/dist/tests/agent/agent-detect.test.js +0 -100
  32. package/dist/tests/agent/agent-spawn.test.js +0 -234
  33. package/dist/tests/agent-output.test.js +0 -186
  34. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  35. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  36. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  37. package/dist/tests/asset-ref.test.js +0 -192
  38. package/dist/tests/asset-registry.test.js +0 -103
  39. package/dist/tests/asset-spec.test.js +0 -241
  40. package/dist/tests/bench/attribution.test.js +0 -995
  41. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  42. package/dist/tests/bench/cleanup.js +0 -203
  43. package/dist/tests/bench/cleanup.test.js +0 -166
  44. package/dist/tests/bench/cli.js +0 -683
  45. package/dist/tests/bench/cli.test.js +0 -177
  46. package/dist/tests/bench/compare.test.js +0 -556
  47. package/dist/tests/bench/corpus.js +0 -314
  48. package/dist/tests/bench/corpus.test.js +0 -258
  49. package/dist/tests/bench/driver.js +0 -346
  50. package/dist/tests/bench/driver.test.js +0 -443
  51. package/dist/tests/bench/evolve-metrics.js +0 -179
  52. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  53. package/dist/tests/bench/evolve.js +0 -580
  54. package/dist/tests/bench/evolve.test.js +0 -616
  55. package/dist/tests/bench/failure-modes.test.js +0 -300
  56. package/dist/tests/bench/feedback-integrity.test.js +0 -456
  57. package/dist/tests/bench/leakage.test.js +0 -125
  58. package/dist/tests/bench/learning-curve.test.js +0 -133
  59. package/dist/tests/bench/metrics.js +0 -2319
  60. package/dist/tests/bench/metrics.test.js +0 -1144
  61. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  62. package/dist/tests/bench/report.js +0 -1821
  63. package/dist/tests/bench/report.test.js +0 -989
  64. package/dist/tests/bench/runner.js +0 -536
  65. package/dist/tests/bench/runner.test.js +0 -958
  66. package/dist/tests/bench/search-bridge.test.js +0 -331
  67. package/dist/tests/bench/tmp.js +0 -41
  68. package/dist/tests/bench/trajectory.js +0 -116
  69. package/dist/tests/bench/trajectory.test.js +0 -127
  70. package/dist/tests/bench/verifier.js +0 -109
  71. package/dist/tests/bench/verifier.test.js +0 -118
  72. package/dist/tests/bench/workflow-evaluator.js +0 -557
  73. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  74. package/dist/tests/bench/workflow-spec.js +0 -358
  75. package/dist/tests/bench/workflow-spec.test.js +0 -363
  76. package/dist/tests/bench/workflow-trace.js +0 -438
  77. package/dist/tests/bench/workflow-trace.test.js +0 -254
  78. package/dist/tests/benchmark-search-quality.js +0 -536
  79. package/dist/tests/benchmark-suite.js +0 -1441
  80. package/dist/tests/capture-cli.test.js +0 -112
  81. package/dist/tests/cli-errors.test.js +0 -203
  82. package/dist/tests/commands/events.test.js +0 -370
  83. package/dist/tests/commands/history.test.js +0 -223
  84. package/dist/tests/commands/import.test.js +0 -103
  85. package/dist/tests/commands/proposal-cli.test.js +0 -209
  86. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  87. package/dist/tests/commands/remember.test.js +0 -97
  88. package/dist/tests/commands/scope-flags.test.js +0 -300
  89. package/dist/tests/commands/search.test.js +0 -537
  90. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  91. package/dist/tests/commands/show.test.js +0 -294
  92. package/dist/tests/common.test.js +0 -266
  93. package/dist/tests/completions.test.js +0 -142
  94. package/dist/tests/config-cli.test.js +0 -193
  95. package/dist/tests/config-llm-features.test.js +0 -139
  96. package/dist/tests/config.test.js +0 -544
  97. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  98. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  99. package/dist/tests/contracts/spec-helpers.js +0 -46
  100. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  101. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  102. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  103. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  104. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  105. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  106. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  107. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  108. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  109. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  110. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  111. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  112. package/dist/tests/core/write-source.test.js +0 -366
  113. package/dist/tests/curate-command.test.js +0 -87
  114. package/dist/tests/db-scoring.test.js +0 -201
  115. package/dist/tests/db.test.js +0 -654
  116. package/dist/tests/distill-cli-flag.test.js +0 -208
  117. package/dist/tests/distill.test.js +0 -515
  118. package/dist/tests/docker-install.test.js +0 -120
  119. package/dist/tests/e2e.test.js +0 -1398
  120. package/dist/tests/embedder.test.js +0 -340
  121. package/dist/tests/embedding-model-config.test.js +0 -379
  122. package/dist/tests/feedback-command.test.js +0 -172
  123. package/dist/tests/file-context.test.js +0 -552
  124. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  125. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  126. package/dist/tests/fixtures/stashes/load.js +0 -166
  127. package/dist/tests/fixtures/stashes/load.test.js +0 -88
  128. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  129. package/dist/tests/frontmatter.test.js +0 -190
  130. package/dist/tests/fts-field-weighting.test.js +0 -254
  131. package/dist/tests/fuzzy-search.test.js +0 -230
  132. package/dist/tests/git-provider-clone.test.js +0 -45
  133. package/dist/tests/github.test.js +0 -161
  134. package/dist/tests/graph-boost-ranking.test.js +0 -305
  135. package/dist/tests/graph-extraction.test.js +0 -282
  136. package/dist/tests/helpers/usage-events.js +0 -8
  137. package/dist/tests/index-pass-llm.test.js +0 -161
  138. package/dist/tests/indexer.test.js +0 -559
  139. package/dist/tests/info-command.test.js +0 -166
  140. package/dist/tests/init.test.js +0 -69
  141. package/dist/tests/install-script.test.js +0 -246
  142. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  143. package/dist/tests/issue-36-repro.test.js +0 -304
  144. package/dist/tests/issues-191-194.test.js +0 -160
  145. package/dist/tests/lesson-lint.test.js +0 -111
  146. package/dist/tests/llm-client.test.js +0 -115
  147. package/dist/tests/llm-feature-gate.test.js +0 -151
  148. package/dist/tests/llm.test.js +0 -139
  149. package/dist/tests/lockfile.test.js +0 -216
  150. package/dist/tests/manifest.test.js +0 -205
  151. package/dist/tests/markdown.test.js +0 -126
  152. package/dist/tests/matchers-unit.test.js +0 -189
  153. package/dist/tests/memory-inference.test.js +0 -299
  154. package/dist/tests/merge-scoring.test.js +0 -136
  155. package/dist/tests/metadata.test.js +0 -313
  156. package/dist/tests/migration-help.test.js +0 -89
  157. package/dist/tests/origin-resolve.test.js +0 -124
  158. package/dist/tests/output-baseline.test.js +0 -217
  159. package/dist/tests/output-shapes-unit.test.js +0 -476
  160. package/dist/tests/parallel-search.test.js +0 -272
  161. package/dist/tests/parameter-metadata.test.js +0 -365
  162. package/dist/tests/paths.test.js +0 -177
  163. package/dist/tests/progressive-disclosure.test.js +0 -280
  164. package/dist/tests/proposals.test.js +0 -279
  165. package/dist/tests/proposed-quality.test.js +0 -271
  166. package/dist/tests/provider-registry.test.js +0 -32
  167. package/dist/tests/ranking-regression.test.js +0 -548
  168. package/dist/tests/reflect-propose.test.js +0 -455
  169. package/dist/tests/registry-build-index.test.js +0 -378
  170. package/dist/tests/registry-cli.test.js +0 -290
  171. package/dist/tests/registry-index-v2.test.js +0 -430
  172. package/dist/tests/registry-install.test.js +0 -728
  173. package/dist/tests/registry-providers/parity.test.js +0 -189
  174. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  175. package/dist/tests/registry-providers/static-index.test.js +0 -204
  176. package/dist/tests/registry-resolve.test.js +0 -126
  177. package/dist/tests/registry-search.test.js +0 -723
  178. package/dist/tests/remember-frontmatter.test.js +0 -380
  179. package/dist/tests/remember-unit.test.js +0 -123
  180. package/dist/tests/ripgrep-install.test.js +0 -251
  181. package/dist/tests/ripgrep-resolve.test.js +0 -108
  182. package/dist/tests/ripgrep.test.js +0 -163
  183. package/dist/tests/save-command.test.js +0 -94
  184. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  185. package/dist/tests/scoring-pipeline.test.js +0 -648
  186. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  187. package/dist/tests/self-update.test.js +0 -442
  188. package/dist/tests/semantic-search-e2e.test.js +0 -512
  189. package/dist/tests/semantic-status.test.js +0 -471
  190. package/dist/tests/setup-run.integration.js +0 -877
  191. package/dist/tests/setup-wizard.test.js +0 -198
  192. package/dist/tests/setup.test.js +0 -131
  193. package/dist/tests/source-add.test.js +0 -11
  194. package/dist/tests/source-clone.test.js +0 -254
  195. package/dist/tests/source-manage.test.js +0 -366
  196. package/dist/tests/source-providers/filesystem.test.js +0 -82
  197. package/dist/tests/source-providers/git.test.js +0 -252
  198. package/dist/tests/source-providers/website.test.js +0 -128
  199. package/dist/tests/source-qa-fixes.test.js +0 -268
  200. package/dist/tests/source-registry.test.js +0 -350
  201. package/dist/tests/source-resolve.test.js +0 -100
  202. package/dist/tests/source-source.test.js +0 -221
  203. package/dist/tests/source.test.js +0 -533
  204. package/dist/tests/tar-utils-scan.test.js +0 -73
  205. package/dist/tests/toggle-components.test.js +0 -73
  206. package/dist/tests/usage-telemetry.test.js +0 -265
  207. package/dist/tests/utility-scoring.test.js +0 -558
  208. package/dist/tests/vault-load-error.test.js +0 -78
  209. package/dist/tests/vault-qa-fixes.test.js +0 -194
  210. package/dist/tests/vault.test.js +0 -429
  211. package/dist/tests/vector-search.test.js +0 -608
  212. package/dist/tests/walker.test.js +0 -252
  213. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  214. package/dist/tests/wave2-cluster-d.test.js +0 -180
  215. package/dist/tests/wave2-cluster-e.test.js +0 -179
  216. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  217. package/dist/tests/wiki.test.js +0 -529
  218. package/dist/tests/workflow-cli.test.js +0 -271
  219. package/dist/tests/workflow-markdown.test.js +0 -171
  220. package/dist/tests/workflow-path-escape.test.js +0 -132
  221. package/dist/tests/workflow-qa-fixes.test.js +0 -377
  222. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  223. /package/dist/{src/commands → commands}/completions.js +0 -0
  224. /package/dist/{src/commands → commands}/curate.js +0 -0
  225. /package/dist/{src/commands → commands}/distill.js +0 -0
  226. /package/dist/{src/commands → commands}/events.js +0 -0
  227. /package/dist/{src/commands → commands}/info.js +0 -0
  228. /package/dist/{src/commands → commands}/init.js +0 -0
  229. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  230. /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
  231. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  232. /package/dist/{src/commands → commands}/proposal.js +0 -0
  233. /package/dist/{src/commands → commands}/propose.js +0 -0
  234. /package/dist/{src/commands → commands}/reflect.js +0 -0
  235. /package/dist/{src/commands → commands}/remember.js +0 -0
  236. /package/dist/{src/commands → commands}/self-update.js +0 -0
  237. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  238. /package/dist/{src/commands → commands}/vault.js +0 -0
  239. /package/dist/{src/core → core}/asset-ref.js +0 -0
  240. /package/dist/{src/core → core}/asset-registry.js +0 -0
  241. /package/dist/{src/core → core}/asset-spec.js +0 -0
  242. /package/dist/{src/core → core}/common.js +0 -0
  243. /package/dist/{src/core → core}/errors.js +0 -0
  244. /package/dist/{src/core → core}/events.js +0 -0
  245. /package/dist/{src/core → core}/frontmatter.js +0 -0
  246. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  247. /package/dist/{src/core → core}/markdown.js +0 -0
  248. /package/dist/{src/core → core}/paths.js +0 -0
  249. /package/dist/{src/core → core}/proposals.js +0 -0
  250. /package/dist/{src/core → core}/warn.js +0 -0
  251. /package/dist/{src/core → core}/write-source.js +0 -0
  252. /package/dist/{src/indexer → indexer}/db.js +0 -0
  253. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  254. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  255. /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
  256. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  257. /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
  258. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  259. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  260. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  261. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  262. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  263. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  264. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  265. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  266. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  267. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  268. /package/dist/{src/llm → llm}/client.js +0 -0
  269. /package/dist/{src/llm → llm}/embedder.js +0 -0
  270. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  271. /package/dist/{src/llm → llm}/embedders/local.js +0 -0
  272. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  273. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  274. /package/dist/{src/llm → llm}/graph-extract.js +0 -0
  275. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  276. /package/dist/{src/llm → llm}/memory-infer.js +0 -0
  277. /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
  278. /package/dist/{src/output → output}/context.js +0 -0
  279. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  280. /package/dist/{src/registry → registry}/factory.js +0 -0
  281. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  282. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  283. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  284. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  285. /package/dist/{src/registry → registry}/resolve.js +0 -0
  286. /package/dist/{src/registry → registry}/types.js +0 -0
  287. /package/dist/{src/setup → setup}/detect.js +0 -0
  288. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  289. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  290. /package/dist/{src/setup → setup}/steps.js +0 -0
  291. /package/dist/{src/sources → sources}/include.js +0 -0
  292. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  293. /package/dist/{src/sources → sources}/provider.js +0 -0
  294. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  295. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  296. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  297. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  298. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  299. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  300. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  301. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  302. /package/dist/{src/sources → sources}/providers/website.js +0 -0
  303. /package/dist/{src/sources → sources}/resolve.js +0 -0
  304. /package/dist/{src/sources → sources}/types.js +0 -0
  305. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  306. /package/dist/{src/version.js → version.js} +0 -0
  307. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  308. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  309. /package/dist/{src/workflows → workflows}/db.js +0 -0
  310. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  311. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  312. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  313. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  314. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,683 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * akm-bench CLI dispatcher.
4
- *
5
- * Subcommands:
6
- * • `utility` — paired noakm vs akm utility benchmark (Track A).
7
- * • `compare` — diff two report JSON files; refuses on hash/model mismatch.
8
- * • `attribute` — per-asset marginal contribution via leave-one-out masking.
9
- * • `evolve` — longitudinal evolution loop (Track B). Stub.
10
- *
11
- * Implementation status and validity rules live in `tests/bench/BENCH.md`.
12
- *
13
- * NOTE: The bench binary is intentionally argv-light. citty is the project's
14
- * CLI framework but the bench is not part of the public CLI surface, so a
15
- * hand-rolled parser keeps the dependency graph tight.
16
- */
17
- import fs from "node:fs";
18
- import process from "node:process";
19
- import { listTasks } from "./corpus";
20
- import { runEvolve } from "./evolve";
21
- import { compareReports, rehydrateRunFromSerialized, runMaskedCorpus, } from "./metrics";
22
- import { renderAttributionTable, renderCompareMarkdown, renderEvolveReport, renderUtilityReport, } from "./report";
23
- import { runUtility } from "./runner";
24
- const HELP = `akm-bench — agent-plus-akm evaluation framework
25
-
26
- Usage:
27
- bun run tests/bench/cli.ts <subcommand> [...flags]
28
-
29
- Subcommands:
30
- utility Track A: paired noakm vs akm utility benchmark.
31
- evolve Track B: longitudinal feedback → distill → propose loop.
32
- compare Diff two report JSON files (refuses cross-model diffs).
33
- attribute Per-asset marginal pass-rate contribution.
34
-
35
- utility flags:
36
- --tasks <slice> train | eval | all (default: all)
37
- --seeds <N> seeds per arm (default: 5)
38
- --budget-tokens <N> per-run token cap (default: 30000)
39
- --budget-wall-ms <N> per-run wallclock cap in ms (default: 120000)
40
- --include-synthetic add a third 'synthetic' arm where the model writes/uses its own
41
- scratch notes (no AKM stash). Reports akm_over_synthetic_lift so
42
- operators can see whether AKM beats a self-notes baseline.
43
- --json suppress the markdown summary on stderr (machine-readable only).
44
- Without --json, JSON still goes to stdout and the markdown
45
- summary is also written to stderr for human-friendly reads.
46
- -h, --help show this message.
47
-
48
- evolve flags:
49
- --tasks <domain> domain id (e.g., docker-homelab) or 'all'. REQUIRED.
50
- --seeds <N> seeds per arm (default: 5)
51
- --budget-tokens <N> per-run token cap (default: 30000)
52
- --budget-wall-ms <N> per-run wallclock cap in ms (default: 120000)
53
- --negative-threshold-count <N> absolute negative-feedback count to evolve (default: 2)
54
- --negative-threshold-ratio <R> ratio of negatives to total feedback (default: 0.5)
55
- --json suppress the markdown summary on stderr.
56
-
57
- compare flags:
58
- --base <path> path to baseline UtilityRunReport JSON file. REQUIRED.
59
- --current <path> path to current UtilityRunReport JSON file. REQUIRED.
60
- --json emit the structured CompareResult JSON to stdout instead
61
- of a markdown diff.
62
- --allow-corpus-mismatch proceed even when the two reports disagree on the
63
- selected task IDs / taskCorpusHash. The diff is
64
- rendered with a warning instead of being refused.
65
- --allow-fixture-mismatch proceed even when the two reports disagree on the
66
- fixtureContentHash. Renders a warning instead of
67
- refusing.
68
- Exit codes: 0 on successful diff, 1 on refusal (model/corpus/fixture-hash/schema/track mismatch),
69
- 2 on input errors (missing files, malformed JSON, unknown flags).
70
-
71
- attribute flags:
72
- --base <path> path to a §13.3 utility run JSON (required).
73
- --top <N> number of top-loaded assets to mask (default: 5; clamped).
74
- --json suppress the markdown summary on stderr.
75
-
76
- Environment:
77
- BENCH_OPENCODE_MODEL model id stamped into every RunResult. REQUIRED for utility.
78
-
79
- See tests/bench/BENCH.md for the operator guide.
80
- `;
81
- function parseArgs(argv) {
82
- const flags = new Map();
83
- const bool = new Set();
84
- const positional = [];
85
- const subcommand = argv[0] ?? "";
86
- for (let i = 1; i < argv.length; i++) {
87
- const arg = argv[i];
88
- if (arg === "--help" || arg === "-h") {
89
- bool.add("help");
90
- continue;
91
- }
92
- if (arg === "--json") {
93
- bool.add("json");
94
- continue;
95
- }
96
- if (arg.startsWith("--")) {
97
- const eq = arg.indexOf("=");
98
- if (eq !== -1) {
99
- flags.set(arg.slice(2, eq), arg.slice(eq + 1));
100
- }
101
- else {
102
- const next = argv[i + 1];
103
- if (next === undefined || next.startsWith("--")) {
104
- bool.add(arg.slice(2));
105
- }
106
- else {
107
- flags.set(arg.slice(2), next);
108
- i += 1;
109
- }
110
- }
111
- continue;
112
- }
113
- positional.push(arg);
114
- }
115
- return { subcommand, flags, bool, positional };
116
- }
117
- /**
118
- * `utility` subcommand. Walks the corpus, runs K seeds per arm per task,
119
- * and produces the §13.3 report.
120
- *
121
- * Returns rather than mutates process to keep this unit-testable. The
122
- * `main()` driver below maps the result onto the actual stdout/stderr/exit.
123
- */
124
- export async function runUtilityCli(options) {
125
- const sliceFilter = options.slice === "all" ? undefined : options.slice;
126
- const tasks = listTasks(sliceFilter ? { slice: sliceFilter } : {});
127
- const report = await runUtility({
128
- tasks,
129
- arms: ["noakm", "akm"],
130
- model: options.model,
131
- seedsPerArm: options.seedsPerArm,
132
- budgetTokens: options.budgetTokens,
133
- budgetWallMs: options.budgetWallMs,
134
- slice: options.slice,
135
- // #261: thread the synthetic-arm gate. Default off — the envelope shape
136
- // is byte-identical to the pre-#261 output unless the operator opts in.
137
- ...(options.includeSynthetic ? { includeSynthetic: true } : {}),
138
- ...(options.branch !== undefined ? { branch: options.branch } : {}),
139
- ...(options.commit !== undefined ? { commit: options.commit } : {}),
140
- ...(options.timestamp !== undefined ? { timestamp: options.timestamp } : {}),
141
- });
142
- const { json, markdown } = renderUtilityReport(report);
143
- const jsonText = `${JSON.stringify(json, null, 2)}\n`;
144
- const markdownText = `${markdown}\n`;
145
- // JSON ALWAYS goes to stdout. This is the bench's machine-readable
146
- // contract (matches `tests/benchmark-suite.ts` and the future `bench
147
- // compare`/`attribute` subcommands). The `--json` flag means
148
- // "suppress the human-friendly markdown summary on stderr"; without it,
149
- // both the JSON envelope (stdout) and the markdown summary (stderr) are
150
- // emitted so an operator running it interactively gets both views.
151
- const stdout = jsonText;
152
- let stderr = options.json ? "" : markdownText;
153
- stderr += `tasks discovered: ${tasks.length} (slice=${options.slice})\n`;
154
- if (tasks.length === 0) {
155
- stderr += "no tasks found — corpus is empty or the slice filter excluded all tasks\n";
156
- }
157
- return { exitCode: 0, stdout, stderr };
158
- }
159
- /**
160
- * `compare` subcommand. Reads two UtilityRunReport JSON files from disk,
161
- * dispatches to `compareReports`, and renders either markdown (default) or
162
- * the structured JSON envelope to stdout.
163
- *
164
- * Exit-code shape:
165
- * • 0 on a successful diff (regardless of whether the diff shows wins).
166
- * • 1 on a refusal (model/hash/schema/track mismatch).
167
- * • 2 on input errors (file missing, malformed JSON).
168
- *
169
- * Returned `UtilityCliResult` keeps this unit-testable; the `main()` driver
170
- * splices the result onto the actual process.
171
- */
172
- export function runCompareCli(options) {
173
- let baseRaw;
174
- let currentRaw;
175
- try {
176
- baseRaw = fs.readFileSync(options.basePath, "utf8");
177
- }
178
- catch (err) {
179
- return {
180
- exitCode: 2,
181
- stdout: "",
182
- stderr: `bench compare: cannot read --base ${options.basePath}: ${err.message}\n`,
183
- };
184
- }
185
- try {
186
- currentRaw = fs.readFileSync(options.currentPath, "utf8");
187
- }
188
- catch (err) {
189
- return {
190
- exitCode: 2,
191
- stdout: "",
192
- stderr: `bench compare: cannot read --current ${options.currentPath}: ${err.message}\n`,
193
- };
194
- }
195
- let base;
196
- let current;
197
- try {
198
- base = JSON.parse(baseRaw);
199
- }
200
- catch (err) {
201
- return { exitCode: 2, stdout: "", stderr: `bench compare: malformed JSON in --base: ${err.message}\n` };
202
- }
203
- try {
204
- current = JSON.parse(currentRaw);
205
- }
206
- catch (err) {
207
- return {
208
- exitCode: 2,
209
- stdout: "",
210
- stderr: `bench compare: malformed JSON in --current: ${err.message}\n`,
211
- };
212
- }
213
- const result = compareReports(base, current, {
214
- ...(options.allowCorpusMismatch ? { allowCorpusMismatch: true } : {}),
215
- ...(options.allowFixtureMismatch ? { allowFixtureMismatch: true } : {}),
216
- });
217
- const stdout = options.json ? `${JSON.stringify(result, null, 2)}\n` : `${renderCompareMarkdown(result)}\n`;
218
- let stderr = "";
219
- if (!result.ok) {
220
- stderr = `bench compare: ${result.message}\n`;
221
- return { exitCode: 1, stdout, stderr };
222
- }
223
- // One-line summary on stderr so an interactive operator sees it without
224
- // having to scan the markdown body.
225
- const agg = result.aggregate;
226
- stderr = `bench compare: pass_rate Δ=${agg.passRateDelta.toFixed(2)} (${agg.passRateSign}); ${result.perTask.length} tasks compared.\n`;
227
- for (const w of result.warnings)
228
- stderr += `warning: ${w}\n`;
229
- return { exitCode: 0, stdout, stderr };
230
- }
231
- /**
232
- * `attribute` subcommand. Loads a base utility report, picks the top-N
233
- * most-loaded assets, masks each in turn, re-runs the corpus, and emits a
234
- * marginal-contribution report.
235
- *
236
- * Cost: N × (tasks × arms × seedsPerArm) re-runs. Reported to stderr up
237
- * front so the operator can abort if the projection is too expensive.
238
- */
239
- export async function runAttributeCli(options) {
240
- if (!fs.existsSync(options.basePath)) {
241
- return {
242
- exitCode: 2,
243
- stdout: "",
244
- stderr: `bench attribute: base report not found: ${options.basePath}\n`,
245
- };
246
- }
247
- let baseEnvelope;
248
- try {
249
- baseEnvelope = JSON.parse(fs.readFileSync(options.basePath, "utf8"));
250
- }
251
- catch (err) {
252
- return {
253
- exitCode: 2,
254
- stdout: "",
255
- stderr: `bench attribute: failed to parse ${options.basePath}: ${err instanceof Error ? err.message : String(err)}\n`,
256
- };
257
- }
258
- const corpus = (baseEnvelope.corpus ?? {});
259
- const sliceRaw = (corpus.slice ?? "all");
260
- const slice = sliceRaw === "train" || sliceRaw === "eval" ? sliceRaw : "all";
261
- const sliceFilter = slice === "all" ? undefined : slice;
262
- const tasks = listTasks(sliceFilter ? { slice: sliceFilter } : {});
263
- const seedsPerArm = typeof corpus.seedsPerArm === "number" ? corpus.seedsPerArm : 5;
264
- const agent = (baseEnvelope.agent ?? {});
265
- const model = options.modelOverride ?? (typeof agent.model === "string" ? agent.model : "unknown");
266
- // The stored envelope's perAsset is in snake_case. Convert it back to the
267
- // PerAssetAttribution shape the metrics module expects so we can pass it
268
- // through to runMaskedCorpus.
269
- const perAssetSerialised = baseEnvelope.perAsset;
270
- const perAsset = {
271
- totalAkmRuns: perAssetSerialised?.total_akm_runs ?? 0,
272
- rows: (perAssetSerialised?.rows ?? []).map((r) => ({
273
- assetRef: String(r.asset_ref ?? ""),
274
- loadCount: Number(r.load_count ?? 0),
275
- loadCountPassing: Number(r.load_count_passing ?? 0),
276
- loadCountFailing: Number(r.load_count_failing ?? 0),
277
- loadPassRate: r.load_pass_rate === null ? null : Number(r.load_pass_rate),
278
- })),
279
- };
280
- if (perAsset.rows.length === 0) {
281
- return {
282
- exitCode: 2,
283
- stdout: "",
284
- stderr: "bench attribute: base report has no per-asset attribution rows (no assets loaded). Re-run `bench utility` first.\n",
285
- };
286
- }
287
- const desired = Math.max(1, options.topN);
288
- const clamped = Math.min(desired, perAsset.rows.length);
289
- // Prefer the persisted `runs[]` array (#249). When the report carries
290
- // serialised raw runs we hydrate them back into RunResult shape and feed
291
- // them to `runMaskedCorpus` directly — that keeps attribution faithful to
292
- // the original (task, arm, seed) bag instead of synthesising stubs from
293
- // the per-asset aggregate. Falls back to the legacy aggregate path when
294
- // the report pre-dates the `runs[]` field.
295
- const persistedRuns = readPersistedRuns(baseEnvelope);
296
- const akmRuns = persistedRuns !== null ? persistedRuns.filter((r) => r.arm === "akm") : synthesiseAkmRunsFromAttribution(perAsset);
297
- const baseReport = {
298
- timestamp: String(baseEnvelope.timestamp ?? ""),
299
- branch: String(baseEnvelope.branch ?? ""),
300
- commit: String(baseEnvelope.commit ?? ""),
301
- model,
302
- corpus: {
303
- domains: typeof corpus.domains === "number" ? corpus.domains : 0,
304
- tasks: typeof corpus.tasks === "number" ? corpus.tasks : tasks.length,
305
- slice,
306
- seedsPerArm,
307
- },
308
- aggregateNoakm: extractCorpusMetrics(baseEnvelope, "noakm"),
309
- aggregateAkm: extractCorpusMetrics(baseEnvelope, "akm"),
310
- aggregateDelta: extractCorpusMetrics(baseEnvelope, "delta"),
311
- trajectoryAkm: { correctAssetLoaded: null, feedbackRecorded: 0 },
312
- failureModes: { byLabel: {}, byTask: {} },
313
- tasks: [],
314
- warnings: [],
315
- perAsset,
316
- akmRuns,
317
- taskMetadata: tasks,
318
- };
319
- const projection = clamped * tasks.length * 2 * seedsPerArm;
320
- let stderr = `bench attribute: masking top ${clamped} of ${perAsset.rows.length} assets; ${clamped} × ${tasks.length} tasks × 2 arms × ${seedsPerArm} seeds = ${projection} re-runs.\n`;
321
- const baseOptions = {
322
- arms: ["noakm", "akm"],
323
- model,
324
- seedsPerArm,
325
- };
326
- const maskedRunner = options.runUtility ?? defaultMaskedRunner;
327
- let maskedResult;
328
- try {
329
- maskedResult = await runMaskedCorpus({
330
- baseReport,
331
- topN: clamped,
332
- runUtility: maskedRunner,
333
- baseOptions,
334
- ...(options.fixturesRoot ? { fixturesRoot: options.fixturesRoot } : {}),
335
- });
336
- }
337
- catch (err) {
338
- return {
339
- exitCode: 1,
340
- stdout: "",
341
- stderr: `${stderr}bench attribute: masked-corpus run failed: ${err instanceof Error ? err.message : String(err)}\n`,
342
- };
343
- }
344
- const json = {
345
- schemaVersion: 1,
346
- track: "attribute",
347
- base: { path: options.basePath, model },
348
- // Issue #251: surface the masking strategy + the exact masked refs in
349
- // the JSON envelope so operators can audit the marginal-contribution
350
- // numbers without re-running the masker. The `maskedRefs` order matches
351
- // `attributions[]`. Strategy is currently always `"leave-one-out"`;
352
- // future strategies extend the union in `MaskedCorpusResult`.
353
- attribution: {
354
- maskingStrategy: maskedResult.maskingStrategy,
355
- maskedRefs: maskedResult.maskedRefs,
356
- },
357
- maskingStrategy: maskedResult.maskingStrategy,
358
- runsPerformed: maskedResult.runsPerformed,
359
- perAsset: {
360
- total_akm_runs: perAsset.totalAkmRuns,
361
- rows: perAsset.rows.map((r) => ({
362
- asset_ref: r.assetRef,
363
- load_count: r.loadCount,
364
- load_count_passing: r.loadCountPassing,
365
- load_count_failing: r.loadCountFailing,
366
- load_pass_rate: r.loadPassRate,
367
- })),
368
- },
369
- attributions: maskedResult.attributions.map((a) => ({
370
- asset_ref: a.assetRef,
371
- base_pass_rate: a.basePassRate,
372
- masked_pass_rate: a.maskedPassRate,
373
- marginal_contribution: a.marginalContribution,
374
- })),
375
- };
376
- const stdout = `${JSON.stringify(json, null, 2)}\n`;
377
- if (!options.json) {
378
- stderr += `${renderAttributionTable(perAsset)}\n`;
379
- stderr += `\n## Marginal contributions (leave-one-out)\n\n`;
380
- stderr += `| asset_ref | base_pass_rate | masked_pass_rate | marginal_contribution |\n`;
381
- stderr += `|-----------|----------------|------------------|-----------------------|\n`;
382
- for (const a of maskedResult.attributions) {
383
- stderr += `| \`${a.assetRef}\` | ${a.basePassRate.toFixed(2)} | ${a.maskedPassRate.toFixed(2)} | ${signed(a.marginalContribution.toFixed(2))} |\n`;
384
- }
385
- }
386
- return { exitCode: 0, stdout, stderr };
387
- }
388
- /** Default real-runner wrapper for masked re-runs. */
389
- async function defaultMaskedRunner(options) {
390
- const arms = options.arms;
391
- return runUtility({
392
- tasks: options.tasks,
393
- arms,
394
- model: options.model,
395
- ...(options.seedsPerArm !== undefined ? { seedsPerArm: options.seedsPerArm } : {}),
396
- ...(options.budgetTokens !== undefined ? { budgetTokens: options.budgetTokens } : {}),
397
- ...(options.budgetWallMs !== undefined ? { budgetWallMs: options.budgetWallMs } : {}),
398
- ...(options.slice !== undefined ? { slice: options.slice } : {}),
399
- ...(options.timestamp !== undefined ? { timestamp: options.timestamp } : {}),
400
- ...(options.branch !== undefined ? { branch: options.branch } : {}),
401
- ...(options.commit !== undefined ? { commit: options.commit } : {}),
402
- ...(options.spawn ? { spawn: options.spawn } : {}),
403
- ...(options.materialiseStash !== undefined ? { materialiseStash: options.materialiseStash } : {}),
404
- });
405
- }
406
- /**
407
- * Best-effort extractor for `aggregate.<arm>` corpus metrics from the
408
- * persisted §13.3 envelope. The envelope keys are snake-cased.
409
- */
410
- function extractCorpusMetrics(envelope, key) {
411
- const aggregate = (envelope.aggregate ?? {});
412
- const node = (aggregate[key] ?? {});
413
- return {
414
- passRate: typeof node.pass_rate === "number" ? node.pass_rate : 0,
415
- tokensPerPass: node.tokens_per_pass === null ? null : typeof node.tokens_per_pass === "number" ? node.tokens_per_pass : null,
416
- wallclockMs: typeof node.wallclock_ms === "number" ? node.wallclock_ms : 0,
417
- };
418
- }
419
- /**
420
- * Read the persisted `runs[]` array (#249) from a §13.3 envelope and hydrate
421
- * each row back into the in-memory `RunResult` shape. Returns `null` when the
422
- * envelope pre-dates the field (legacy reports) so callers can fall back to
423
- * the aggregate-only path.
424
- *
425
- * Structurally validates each row: rows that don't carry the required keys
426
- * are skipped silently. We intentionally avoid throwing — older envelopes
427
- * with partial shapes still want to flow through the legacy path.
428
- */
429
- function readPersistedRuns(envelope) {
430
- const raw = envelope.runs;
431
- if (!Array.isArray(raw))
432
- return null;
433
- const out = [];
434
- for (const r of raw) {
435
- if (!r || typeof r !== "object")
436
- continue;
437
- const row = r;
438
- if (typeof row.task_id !== "string")
439
- continue;
440
- if (typeof row.arm !== "string")
441
- continue;
442
- if (typeof row.seed !== "number")
443
- continue;
444
- if (typeof row.outcome !== "string")
445
- continue;
446
- // Trajectory shape: tolerate missing/partial sub-object so we don't
447
- // reject otherwise-valid rows.
448
- const traj = (row.trajectory ?? {});
449
- const normalised = {
450
- task_id: row.task_id,
451
- arm: row.arm,
452
- seed: row.seed,
453
- model: typeof row.model === "string" ? row.model : "unknown",
454
- outcome: row.outcome,
455
- tokens: row.tokens ?? { input: 0, output: 0 },
456
- wallclock_ms: typeof row.wallclock_ms === "number" ? row.wallclock_ms : 0,
457
- verifier_exit_code: typeof row.verifier_exit_code === "number" ? row.verifier_exit_code : 0,
458
- trajectory: {
459
- correct_asset_loaded: traj.correct_asset_loaded ?? null,
460
- feedback_recorded: traj.feedback_recorded ?? null,
461
- },
462
- assets_loaded: Array.isArray(row.assets_loaded) ? row.assets_loaded : [],
463
- failure_mode: typeof row.failure_mode === "string" ? row.failure_mode : null,
464
- };
465
- out.push(rehydrateRunFromSerialized(normalised));
466
- }
467
- return out;
468
- }
469
- /**
470
- * Build a synthetic akm-arm RunResult bag from a previously-computed
471
- * attribution table. Used when we load a §13.3 envelope from disk: the
472
- * envelope doesn't carry raw RunResults, but the attribution table is
473
- * lossless w.r.t. (asset, pass/fail) counts — which is all
474
- * `computePerAssetAttribution` needs to reproduce the top-N ranking.
475
- *
476
- * Each synthetic run loads exactly one asset. This over-counts the run
477
- * total but keeps the per-asset counts faithful to the original table. The
478
- * synthesised runs are NOT consumed by `runMaskedCorpus` for the masked
479
- * runs themselves — those go through the injected runner — they only seed
480
- * `report.akmRuns` so that recomputing the attribution gives back the
481
- * same top-N ordering.
482
- */
483
- function synthesiseAkmRunsFromAttribution(perAsset) {
484
- const out = [];
485
- for (const row of perAsset.rows) {
486
- for (let i = 0; i < row.loadCountPassing; i++) {
487
- out.push(makeSyntheticRun("pass", row.assetRef));
488
- }
489
- for (let i = 0; i < row.loadCountFailing; i++) {
490
- out.push(makeSyntheticRun("fail", row.assetRef));
491
- }
492
- }
493
- return out;
494
- }
495
- function makeSyntheticRun(outcome, ref) {
496
- return {
497
- schemaVersion: 1,
498
- taskId: "synthetic",
499
- arm: "akm",
500
- seed: 0,
501
- model: "synthetic",
502
- outcome,
503
- tokens: { input: 0, output: 0 },
504
- wallclockMs: 0,
505
- trajectory: { correctAssetLoaded: null, feedbackRecorded: null },
506
- events: [],
507
- verifierStdout: "",
508
- verifierExitCode: outcome === "pass" ? 0 : 1,
509
- assetsLoaded: [ref],
510
- };
511
- }
512
- function signed(text) {
513
- if (text.startsWith("-"))
514
- return text;
515
- if (text === "0" || text === "0.00" || text === "0.0")
516
- return text;
517
- return `+${text}`;
518
- }
519
- function getEnv(name) {
520
- const value = process.env[name];
521
- return value && value.length > 0 ? value : undefined;
522
- }
523
- function parseInt32(text, fallback) {
524
- if (text === undefined)
525
- return fallback;
526
- const n = Number.parseInt(text, 10);
527
- if (!Number.isFinite(n) || n <= 0)
528
- return fallback;
529
- return n;
530
- }
531
- function parseFloatArg(text, fallback) {
532
- if (text === undefined)
533
- return fallback;
534
- const n = Number.parseFloat(text);
535
- if (!Number.isFinite(n) || n < 0)
536
- return fallback;
537
- return n;
538
- }
539
- /**
540
- * `evolve` subcommand. Filters the corpus to one domain (or `all`), then
541
- * dispatches `runEvolve` and renders the §6.3+§6.4 envelope.
542
- */
543
- export async function runEvolveCli(options) {
544
- // Discover all tasks then filter on domain.
545
- const allTasks = listTasks();
546
- const tasks = options.domain === "all" ? allTasks : allTasks.filter((t) => t.domain === options.domain);
547
- if (tasks.length === 0) {
548
- return {
549
- exitCode: 2,
550
- stdout: "",
551
- stderr: `bench evolve: no tasks matched domain "${options.domain}".\n`,
552
- };
553
- }
554
- const report = await runEvolve({
555
- tasks,
556
- model: options.model,
557
- seedsPerArm: options.seedsPerArm,
558
- budgetTokens: options.budgetTokens,
559
- budgetWallMs: options.budgetWallMs,
560
- negativeThreshold: options.negativeThreshold,
561
- ...(options.branch !== undefined ? { branch: options.branch } : {}),
562
- ...(options.commit !== undefined ? { commit: options.commit } : {}),
563
- ...(options.timestamp !== undefined ? { timestamp: options.timestamp } : {}),
564
- });
565
- const { json, markdown } = renderEvolveReport(report);
566
- const stdout = `${JSON.stringify(json, null, 2)}\n`;
567
- let stderr = options.json ? "" : `${markdown}\n`;
568
- stderr += `tasks discovered: ${tasks.length} (domain=${options.domain})\n`;
569
- return { exitCode: 0, stdout, stderr };
570
- }
571
- async function main(argv) {
572
- const parsed = parseArgs(argv);
573
- if (parsed.bool.has("help") || parsed.subcommand === "" || parsed.subcommand === "help") {
574
- process.stdout.write(HELP);
575
- return parsed.subcommand === "" ? 2 : 0;
576
- }
577
- switch (parsed.subcommand) {
578
- case "utility": {
579
- const sliceRaw = parsed.flags.get("tasks") ?? "all";
580
- if (sliceRaw !== "train" && sliceRaw !== "eval" && sliceRaw !== "all") {
581
- process.stderr.write(`bench utility: invalid --tasks value "${sliceRaw}"; expected one of: all, train, eval.\n`);
582
- return 2;
583
- }
584
- const slice = sliceRaw;
585
- const model = getEnv("BENCH_OPENCODE_MODEL");
586
- if (!model) {
587
- process.stderr.write("bench utility: BENCH_OPENCODE_MODEL environment variable is required.\n");
588
- return 2;
589
- }
590
- const result = await runUtilityCli({
591
- slice,
592
- json: parsed.bool.has("json"),
593
- seedsPerArm: parseInt32(parsed.flags.get("seeds"), 5),
594
- budgetTokens: parseInt32(parsed.flags.get("budget-tokens"), 30000),
595
- budgetWallMs: parseInt32(parsed.flags.get("budget-wall-ms"), 120000),
596
- model,
597
- ...(parsed.bool.has("include-synthetic") ? { includeSynthetic: true } : {}),
598
- });
599
- if (result.stdout)
600
- process.stdout.write(result.stdout);
601
- if (result.stderr)
602
- process.stderr.write(result.stderr);
603
- return result.exitCode;
604
- }
605
- case "evolve": {
606
- const domain = parsed.flags.get("tasks");
607
- if (!domain) {
608
- process.stderr.write("bench evolve: --tasks <domain> is required (use --tasks all to run the full corpus).\n");
609
- return 2;
610
- }
611
- const model = getEnv("BENCH_OPENCODE_MODEL");
612
- if (!model) {
613
- process.stderr.write("bench evolve: BENCH_OPENCODE_MODEL environment variable is required.\n");
614
- return 2;
615
- }
616
- const result = await runEvolveCli({
617
- domain,
618
- json: parsed.bool.has("json"),
619
- seedsPerArm: parseInt32(parsed.flags.get("seeds"), 5),
620
- budgetTokens: parseInt32(parsed.flags.get("budget-tokens"), 30000),
621
- budgetWallMs: parseInt32(parsed.flags.get("budget-wall-ms"), 120000),
622
- model,
623
- negativeThreshold: {
624
- absoluteCount: parseInt32(parsed.flags.get("negative-threshold-count"), 2),
625
- ratio: parseFloatArg(parsed.flags.get("negative-threshold-ratio"), 0.5),
626
- },
627
- });
628
- if (result.stdout)
629
- process.stdout.write(result.stdout);
630
- if (result.stderr)
631
- process.stderr.write(result.stderr);
632
- return result.exitCode;
633
- }
634
- case "compare": {
635
- const basePath = parsed.flags.get("base");
636
- const currentPath = parsed.flags.get("current");
637
- if (!basePath || !currentPath) {
638
- process.stderr.write("bench compare: --base and --current are both required.\n");
639
- return 2;
640
- }
641
- const result = runCompareCli({
642
- basePath,
643
- currentPath,
644
- json: parsed.bool.has("json"),
645
- allowCorpusMismatch: parsed.bool.has("allow-corpus-mismatch"),
646
- allowFixtureMismatch: parsed.bool.has("allow-fixture-mismatch"),
647
- });
648
- if (result.stdout)
649
- process.stdout.write(result.stdout);
650
- if (result.stderr)
651
- process.stderr.write(result.stderr);
652
- return result.exitCode;
653
- }
654
- case "attribute": {
655
- const basePath = parsed.flags.get("base");
656
- if (!basePath) {
657
- process.stderr.write("bench attribute: --base <path> is required.\n");
658
- return 2;
659
- }
660
- const topN = parseInt32(parsed.flags.get("top"), 5);
661
- const result = await runAttributeCli({
662
- basePath,
663
- topN,
664
- json: parsed.bool.has("json"),
665
- });
666
- if (result.stdout)
667
- process.stdout.write(result.stdout);
668
- if (result.stderr)
669
- process.stderr.write(result.stderr);
670
- return result.exitCode;
671
- }
672
- default:
673
- process.stderr.write(`unknown subcommand: ${parsed.subcommand}\n`);
674
- process.stderr.write(HELP);
675
- return 2;
676
- }
677
- }
678
- // Only execute when invoked directly. The exported `runUtilityCli` is callable
679
- // from tests without triggering process.exit.
680
- if (import.meta.main) {
681
- const code = await main(process.argv.slice(2));
682
- process.exit(code);
683
- }