akm-cli 0.7.0-rc1 → 0.7.0

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 (83) hide show
  1. package/dist/src/cli.js +100 -16
  2. package/dist/src/commands/config-cli.js +42 -0
  3. package/dist/src/commands/history.js +78 -7
  4. package/dist/src/commands/registry-search.js +69 -6
  5. package/dist/src/commands/search.js +30 -3
  6. package/dist/src/commands/show.js +29 -0
  7. package/dist/src/commands/source-add.js +5 -1
  8. package/dist/src/commands/source-manage.js +7 -1
  9. package/dist/src/core/config.js +28 -0
  10. package/dist/src/indexer/db-search.js +1 -0
  11. package/dist/src/indexer/indexer.js +16 -2
  12. package/dist/src/indexer/matchers.js +1 -1
  13. package/dist/src/indexer/search-source.js +4 -2
  14. package/dist/src/integrations/agent/profiles.js +1 -1
  15. package/dist/src/integrations/agent/spawn.js +67 -16
  16. package/dist/src/integrations/github.js +9 -3
  17. package/dist/src/llm/embedders/remote.js +37 -3
  18. package/dist/src/output/cli-hints.js +15 -2
  19. package/dist/src/output/renderers.js +3 -1
  20. package/dist/src/output/shapes.js +8 -1
  21. package/dist/src/output/text.js +156 -3
  22. package/dist/src/registry/build-index.js +5 -4
  23. package/dist/src/registry/providers/static-index.js +3 -1
  24. package/dist/src/setup/setup.js +9 -0
  25. package/dist/src/wiki/wiki.js +54 -6
  26. package/dist/src/workflows/runs.js +37 -3
  27. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +1 -1
  28. package/dist/tests/bench/attribution.test.js +24 -23
  29. package/dist/tests/bench/cleanup.js +31 -0
  30. package/dist/tests/bench/cli.js +366 -31
  31. package/dist/tests/bench/cli.test.js +282 -14
  32. package/dist/tests/bench/corpus.js +3 -0
  33. package/dist/tests/bench/corpus.test.js +10 -10
  34. package/dist/tests/bench/doctor.js +525 -0
  35. package/dist/tests/bench/driver.js +77 -22
  36. package/dist/tests/bench/driver.test.js +142 -1
  37. package/dist/tests/bench/environment.js +233 -0
  38. package/dist/tests/bench/environment.test.js +199 -0
  39. package/dist/tests/bench/evolve.js +67 -0
  40. package/dist/tests/bench/evolve.test.js +12 -4
  41. package/dist/tests/bench/failure-modes.test.js +52 -3
  42. package/dist/tests/bench/feedback-integrity.test.js +3 -2
  43. package/dist/tests/bench/leakage.test.js +105 -2
  44. package/dist/tests/bench/learning-curve.test.js +3 -2
  45. package/dist/tests/bench/metrics.js +102 -26
  46. package/dist/tests/bench/metrics.test.js +10 -4
  47. package/dist/tests/bench/opencode-config.js +194 -0
  48. package/dist/tests/bench/opencode-config.test.js +370 -0
  49. package/dist/tests/bench/report.js +73 -9
  50. package/dist/tests/bench/report.test.js +59 -10
  51. package/dist/tests/bench/run-config.js +355 -0
  52. package/dist/tests/bench/run-config.test.js +298 -0
  53. package/dist/tests/bench/run-curate-test.js +32 -0
  54. package/dist/tests/bench/run-failing-tasks.js +56 -0
  55. package/dist/tests/bench/run-full-bench.js +51 -0
  56. package/dist/tests/bench/run-items36-targeted.js +69 -0
  57. package/dist/tests/bench/run-nano-quick.js +42 -0
  58. package/dist/tests/bench/run-waveg-targeted.js +62 -0
  59. package/dist/tests/bench/runner.js +257 -94
  60. package/dist/tests/bench/tmp.js +90 -0
  61. package/dist/tests/bench/trajectory.js +2 -2
  62. package/dist/tests/bench/verifier.js +6 -1
  63. package/dist/tests/bench/workflow-spec.js +11 -24
  64. package/dist/tests/bench/workflow-spec.test.js +1 -1
  65. package/dist/tests/bench/workflow-trace.js +34 -0
  66. package/dist/tests/cli-errors.test.js +1 -0
  67. package/dist/tests/commands/history.test.js +195 -0
  68. package/dist/tests/config.test.js +25 -0
  69. package/dist/tests/e2e.test.js +23 -2
  70. package/dist/tests/fixtures/stashes/load.js +1 -1
  71. package/dist/tests/fixtures/stashes/load.test.js +11 -2
  72. package/dist/tests/indexer.test.js +12 -1
  73. package/dist/tests/output-baseline.test.js +2 -1
  74. package/dist/tests/output-shapes-unit.test.js +3 -1
  75. package/dist/tests/registry-build-index.test.js +17 -1
  76. package/dist/tests/registry-providers/static-index.test.js +34 -0
  77. package/dist/tests/registry-search.test.js +200 -0
  78. package/dist/tests/remember-frontmatter.test.js +11 -13
  79. package/dist/tests/source-qa-fixes.test.js +18 -0
  80. package/dist/tests/source-registry.test.js +3 -3
  81. package/dist/tests/source-source.test.js +61 -1
  82. package/dist/tests/workflow-qa-fixes.test.js +18 -0
  83. package/package.json +1 -1
@@ -31,6 +31,37 @@ import * as fs from "node:fs";
31
31
  import * as path from "node:path";
32
32
  import { warn } from "../../src/core/warn";
33
33
  import { benchTmpRoot } from "./tmp";
34
+ /**
35
+ * Register a process-group kill for a spawned opencode PID.
36
+ *
37
+ * On SIGINT/SIGTERM the bench driver must kill the entire opencode process
38
+ * group (not just the node wrapper) so .opencode children don't become orphans
39
+ * that keep pipes open and block subsequent runs.
40
+ *
41
+ * Call this immediately after spawning opencode. Returns a deregister thunk
42
+ * that should be called once the process has exited (in the run's finally
43
+ * block).
44
+ *
45
+ * The SIGKILL is sent to the process group (`-pid`) if available, falling back
46
+ * to the individual PID for environments where group-kill is unavailable.
47
+ */
48
+ export function registerProcessGroupCleanup(pid) {
49
+ const fn = () => {
50
+ try {
51
+ process.kill(-pid, "SIGKILL");
52
+ }
53
+ catch {
54
+ // Process group may not exist (process already exited or pid unavailable).
55
+ try {
56
+ process.kill(pid, "SIGKILL");
57
+ }
58
+ catch {
59
+ /* already gone */
60
+ }
61
+ }
62
+ };
63
+ return registerCleanup(fn);
64
+ }
34
65
  const registry = {
35
66
  fns: new Set(),
36
67
  installed: false,
@@ -7,6 +7,7 @@
7
7
  * • `compare` — diff two report JSON files; refuses on hash/model mismatch.
8
8
  * • `attribute` — per-asset marginal contribution via leave-one-out masking.
9
9
  * • `evolve` — longitudinal evolution loop (Track B). Stub.
10
+ * • `kill` — send SIGTERM to a running bench process (reads bench.pid).
10
11
  *
11
12
  * Implementation status and validity rules live in `tests/bench/BENCH.md`.
12
13
  *
@@ -15,31 +16,56 @@
15
16
  * hand-rolled parser keeps the dependency graph tight.
16
17
  */
17
18
  import fs from "node:fs";
19
+ import path from "node:path";
18
20
  import process from "node:process";
21
+ import { getCacheDir } from "../../src/core/paths";
19
22
  import { listTasks } from "./corpus";
20
23
  import { runEvolve } from "./evolve";
21
24
  import { compareReports, rehydrateRunFromSerialized, runMaskedCorpus, } from "./metrics";
25
+ import { BenchConfigError, loadOpencodeProviders } from "./opencode-config";
22
26
  import { renderAttributionTable, renderCompareMarkdown, renderEvolveReport, renderUtilityReport, } from "./report";
27
+ import { loadBenchRunConfig } from "./run-config";
23
28
  import { runUtility } from "./runner";
29
+ import { isPidRunning, readBenchPid, writeBenchPid } from "./tmp";
24
30
  const HELP = `akm-bench — agent-plus-akm evaluation framework
25
31
 
26
32
  Usage:
33
+ bun run tests/bench/cli.ts <config.json> [--json] [--seeds N] [--parallel N] [--tasks <list>]
27
34
  bun run tests/bench/cli.ts <subcommand> [...flags]
28
35
 
29
- Subcommands:
36
+ Config-file mode (recommended):
37
+ Pass a path to a tests/bench/configs/*.json file as the first argument.
38
+ See tests/bench/BENCH.md for the run-config schema and provider
39
+ discovery chain (BENCH_OPENCODE_CONFIG → providers/providersRef →
40
+ ~/.config/akm/bench-providers.json).
41
+
42
+ Subcommands (legacy; still supported):
30
43
  utility Track A: paired noakm vs akm utility benchmark.
31
44
  evolve Track B: longitudinal feedback → distill → propose loop.
32
45
  compare Diff two report JSON files (refuses cross-model diffs).
33
46
  attribute Per-asset marginal pass-rate contribution.
47
+ kill Send SIGTERM to a running bench process (reads bench.pid).
48
+ clean Remove all bench tmp dirs under \${AKM_CACHE_DIR}/bench/.
34
49
 
35
50
  utility flags:
36
51
  --tasks <slice> train | eval | all (default: all)
37
52
  --seeds <N> seeds per arm (default: 5)
38
53
  --budget-tokens <N> per-run token cap (default: 30000)
39
54
  --budget-wall-ms <N> per-run wallclock cap in ms (default: 120000)
55
+ --parallel <N> number of (task, arm, seed) triples to run concurrently
56
+ (default: 1 — sequential). Clamped to [1, 8]. Values > 4
57
+ print a warning unless --force-parallel is also set.
58
+ --force-parallel suppress the high-parallelism warning when --parallel > 4.
59
+ --no-noakm exclude the noakm baseline arm (default: included). The noakm arm is
60
+ the control condition — pass_rate(akm) − pass_rate(noakm) is the
61
+ primary utility metric. Omit only when you are measuring workflow
62
+ compliance rather than marginal utility.
40
63
  --include-synthetic add a third 'synthetic' arm where the model writes/uses its own
41
64
  scratch notes (no AKM stash). Reports akm_over_synthetic_lift so
42
65
  operators can see whether AKM beats a self-notes baseline.
66
+ --opencode-config <path> path to a bench opencode providers JSON file. Auto-discovered
67
+ from BENCH_OPENCODE_CONFIG env var or the fixture defaults when
68
+ omitted. See BENCH.md for the discovery order.
43
69
  --json suppress the markdown summary on stderr (machine-readable only).
44
70
  Without --json, JSON still goes to stdout and the markdown
45
71
  summary is also written to stderr for human-friendly reads.
@@ -50,8 +76,11 @@ evolve flags:
50
76
  --seeds <N> seeds per arm (default: 5)
51
77
  --budget-tokens <N> per-run token cap (default: 30000)
52
78
  --budget-wall-ms <N> per-run wallclock cap in ms (default: 120000)
79
+ --parallel <N> same as utility --parallel (default: 1).
80
+ --force-parallel suppress the high-parallelism warning when --parallel > 4.
53
81
  --negative-threshold-count <N> absolute negative-feedback count to evolve (default: 2)
54
82
  --negative-threshold-ratio <R> ratio of negatives to total feedback (default: 0.5)
83
+ --opencode-config <path> path to a bench opencode providers JSON file (same as utility).
55
84
  --json suppress the markdown summary on stderr.
56
85
 
57
86
  compare flags:
@@ -71,10 +100,26 @@ compare flags:
71
100
  attribute flags:
72
101
  --base <path> path to a §13.3 utility run JSON (required).
73
102
  --top <N> number of top-loaded assets to mask (default: 5; clamped).
103
+ --opencode-config <path> path to a bench opencode providers JSON file (same as utility).
74
104
  --json suppress the markdown summary on stderr.
75
105
 
106
+ kill flags:
107
+ (none) Reads \${AKM_CACHE_DIR}/bench/bench.pid and sends SIGTERM.
108
+ Prints "no bench running" and exits 0 when the PID file is absent.
109
+ Run again (or press Ctrl-C) to escalate to SIGKILL.
110
+
76
111
  Environment:
77
- BENCH_OPENCODE_MODEL model id stamped into every RunResult. REQUIRED for utility.
112
+ BENCH_OPENCODE_MODEL model id stamped into every RunResult. REQUIRED for utility/evolve
113
+ unless the loaded providers file supplies a defaultModel.
114
+ BENCH_OPENCODE_CONFIG path to the bench opencode providers JSON file. Overrides the
115
+ default fixture; overridden by --opencode-config flag.
116
+
117
+ Auto-discovery order for --opencode-config (first existing file wins):
118
+ 1. --opencode-config <path> flag value
119
+ 2. BENCH_OPENCODE_CONFIG env var
120
+ 3. tests/fixtures/bench/opencode-providers.local.json (gitignored operator overlay)
121
+ 4. tests/fixtures/bench/opencode-providers.json (committed fixture)
122
+ 5. None found → empty isolated dir, opencode uses cloud-provider defaults.
78
123
 
79
124
  See tests/bench/BENCH.md for the operator guide.
80
125
  `;
@@ -114,6 +159,58 @@ function parseArgs(argv) {
114
159
  }
115
160
  return { subcommand, flags, bool, positional };
116
161
  }
162
+ /**
163
+ * Absolute path to the committed default bench opencode providers fixture.
164
+ * Used as the final fallback in the auto-discovery chain.
165
+ */
166
+ const DEFAULT_PROVIDERS_PATH = path.resolve(__dirname, "..", "fixtures", "bench", "opencode-providers.json");
167
+ /**
168
+ * Absolute path to the gitignored operator overlay. Takes precedence over
169
+ * the committed fixture when it exists.
170
+ */
171
+ const LOCAL_PROVIDERS_PATH = path.resolve(__dirname, "..", "fixtures", "bench", "opencode-providers.local.json");
172
+ /**
173
+ * Auto-discover and load the bench opencode providers file.
174
+ *
175
+ * Discovery order (first existing file wins):
176
+ * 1. `flagPath` — `--opencode-config` flag value (already resolved by caller).
177
+ * 2. `BENCH_OPENCODE_CONFIG` env var.
178
+ * 3. `tests/fixtures/bench/opencode-providers.local.json` (gitignored overlay).
179
+ * 4. `tests/fixtures/bench/opencode-providers.json` (committed fixture).
180
+ * 5. None found → returns `undefined` (empty isolated dir, cloud-provider fallback).
181
+ *
182
+ * When a file is found but fails to load, the BenchConfigError is re-thrown
183
+ * so the caller can map it to the correct exit code.
184
+ */
185
+ export function discoverOpencodeProviders(flagPath) {
186
+ const candidates = [
187
+ flagPath,
188
+ getEnv("BENCH_OPENCODE_CONFIG"),
189
+ LOCAL_PROVIDERS_PATH,
190
+ DEFAULT_PROVIDERS_PATH,
191
+ ];
192
+ for (const candidate of candidates) {
193
+ if (!candidate)
194
+ continue;
195
+ const absPath = path.isAbsolute(candidate) ? candidate : path.resolve(candidate);
196
+ if (fs.existsSync(absPath)) {
197
+ // Throws BenchConfigError on validation failure; callers propagate it.
198
+ return loadOpencodeProviders(absPath);
199
+ }
200
+ // When a flag or env-var path was given explicitly but doesn't exist,
201
+ // treat it as a usage error rather than silently skipping to the next
202
+ // candidate. Only the auto-discovered defaults (local + committed) are
203
+ // silently skipped when absent.
204
+ if (candidate === flagPath && flagPath) {
205
+ // This throws with isUsageError: true (file not found).
206
+ return loadOpencodeProviders(absPath);
207
+ }
208
+ if (candidate === getEnv("BENCH_OPENCODE_CONFIG") && candidate) {
209
+ return loadOpencodeProviders(absPath);
210
+ }
211
+ }
212
+ return undefined;
213
+ }
117
214
  /**
118
215
  * `utility` subcommand. Walks the corpus, runs K seeds per arm per task,
119
216
  * and produces the §13.3 report.
@@ -124,9 +221,13 @@ function parseArgs(argv) {
124
221
  export async function runUtilityCli(options) {
125
222
  const sliceFilter = options.slice === "all" ? undefined : options.slice;
126
223
  const tasks = listTasks(sliceFilter ? { slice: sliceFilter } : {});
224
+ // noakm arm is included by default: it is the control condition for the
225
+ // primary utility metric (pass_rate(akm) − pass_rate(noakm), spec §4).
226
+ // Pass --no-noakm (options.includeNoakm === false) to exclude it.
227
+ const arms = options.includeNoakm === false ? ["akm"] : ["noakm", "akm"];
127
228
  const report = await runUtility({
128
229
  tasks,
129
- arms: ["noakm", "akm"],
230
+ arms,
130
231
  model: options.model,
131
232
  seedsPerArm: options.seedsPerArm,
132
233
  budgetTokens: options.budgetTokens,
@@ -135,9 +236,12 @@ export async function runUtilityCli(options) {
135
236
  // #261: thread the synthetic-arm gate. Default off — the envelope shape
136
237
  // is byte-identical to the pre-#261 output unless the operator opts in.
137
238
  ...(options.includeSynthetic ? { includeSynthetic: true } : {}),
239
+ ...(options.parallel !== undefined ? { parallel: options.parallel } : {}),
240
+ ...(options.forceParallel ? { forceParallel: true } : {}),
138
241
  ...(options.branch !== undefined ? { branch: options.branch } : {}),
139
242
  ...(options.commit !== undefined ? { commit: options.commit } : {}),
140
243
  ...(options.timestamp !== undefined ? { timestamp: options.timestamp } : {}),
244
+ ...(options.opencodeProviders ? { opencodeProviders: options.opencodeProviders } : {}),
141
245
  });
142
246
  const { json, markdown } = renderUtilityReport(report);
143
247
  const jsonText = `${JSON.stringify(json, null, 2)}\n`;
@@ -413,6 +517,7 @@ function extractCorpusMetrics(envelope, key) {
413
517
  return {
414
518
  passRate: typeof node.pass_rate === "number" ? node.pass_rate : 0,
415
519
  tokensPerPass: node.tokens_per_pass === null ? null : typeof node.tokens_per_pass === "number" ? node.tokens_per_pass : null,
520
+ tokensPerRun: node.tokens_per_run === null ? null : typeof node.tokens_per_run === "number" ? node.tokens_per_run : null,
416
521
  wallclockMs: typeof node.wallclock_ms === "number" ? node.wallclock_ms : 0,
417
522
  };
418
523
  }
@@ -536,6 +641,101 @@ function parseFloatArg(text, fallback) {
536
641
  return fallback;
537
642
  return n;
538
643
  }
644
+ /**
645
+ * Set of obsolete-flag names that have already emitted their stderr
646
+ * warning during this process. Used by `warnObsolete` to dedupe.
647
+ *
648
+ * Exported as a test seam so unit tests can clear the cache between
649
+ * cases without restarting the process.
650
+ */
651
+ export const obsoleteFlagWarned = new Set();
652
+ /**
653
+ * Emit a one-line `[obsolete] ...` warning on stderr the FIRST time the
654
+ * named flag is used in this process. Subsequent calls with the same
655
+ * `name` are silent so a single invocation never emits the same warning
656
+ * twice. Internal: wired into the existing utility/evolve dispatch
657
+ * branches; the new config-file path never triggers these.
658
+ */
659
+ function warnObsolete(name, replacement) {
660
+ if (obsoleteFlagWarned.has(name))
661
+ return;
662
+ obsoleteFlagWarned.add(name);
663
+ process.stderr.write(`[obsolete] ${name} → ${replacement}\n`);
664
+ }
665
+ /**
666
+ * Detect whether the user supplied any of the flags marked obsolete in
667
+ * BENCH.md §G and emit one warning per used flag. The flags continue to
668
+ * function — the warning is the only behavior change.
669
+ */
670
+ function warnIfObsoleteFlagsUsed(parsed) {
671
+ if (parsed.bool.has("no-noakm")) {
672
+ warnObsolete("--no-noakm", 'use `arms: ["akm"]` in a run config');
673
+ }
674
+ if (parsed.bool.has("include-synthetic")) {
675
+ warnObsolete("--include-synthetic", 'use `arms: [..., "synthetic"]` in a run config');
676
+ }
677
+ if (parsed.flags.has("opencode-config")) {
678
+ warnObsolete("--opencode-config", "use `providersRef` in a run config, BENCH_OPENCODE_CONFIG, or ~/.config/akm/bench-providers.json");
679
+ }
680
+ if (parsed.flags.has("budget-tokens")) {
681
+ warnObsolete("--budget-tokens", "use `budgetTokens` in a run config");
682
+ }
683
+ if (parsed.flags.has("budget-wall-ms")) {
684
+ warnObsolete("--budget-wall-ms", "use `budgetWallMs` in a run config");
685
+ }
686
+ }
687
+ /**
688
+ * `<config.json>` dispatch — load a bench run config, resolve providers
689
+ * and tasks, invoke `runUtility`, and emit the §13.3 envelope on stdout.
690
+ *
691
+ * Behaves identically to `runUtilityCli` from a stdout/stderr/exit-code
692
+ * standpoint: JSON on stdout, optional markdown summary on stderr,
693
+ * returns 0/2/78 mirroring the existing semantics.
694
+ */
695
+ export async function runConfigCli(options) {
696
+ let resolved;
697
+ try {
698
+ const overrides = {};
699
+ if (options.tasksList)
700
+ overrides.tasksList = options.tasksList;
701
+ if (options.seedsPerArm !== undefined)
702
+ overrides.seedsPerArm = options.seedsPerArm;
703
+ if (options.parallel !== undefined)
704
+ overrides.parallel = options.parallel;
705
+ resolved = loadBenchRunConfig(options.configPath, overrides);
706
+ }
707
+ catch (err) {
708
+ const exitCode = err instanceof BenchConfigError && err.isUsageError ? 2 : 78;
709
+ return {
710
+ exitCode,
711
+ stdout: "",
712
+ stderr: `bench: ${err instanceof Error ? err.message : String(err)}\n`,
713
+ };
714
+ }
715
+ const report = await runUtility({
716
+ tasks: resolved.tasks,
717
+ arms: resolved.arms,
718
+ model: resolved.model,
719
+ slice: resolved.slice,
720
+ ...(resolved.seedsPerArm !== undefined ? { seedsPerArm: resolved.seedsPerArm } : {}),
721
+ ...(resolved.budgetTokens !== undefined ? { budgetTokens: resolved.budgetTokens } : {}),
722
+ ...(resolved.budgetWallMs !== undefined ? { budgetWallMs: resolved.budgetWallMs } : {}),
723
+ ...(resolved.parallel !== undefined ? { parallel: resolved.parallel } : {}),
724
+ ...(resolved.forceParallel ? { forceParallel: true } : {}),
725
+ ...(resolved.baselineByTaskId ? { baselineByTaskId: resolved.baselineByTaskId } : {}),
726
+ ...(options.timestamp !== undefined ? { timestamp: options.timestamp } : {}),
727
+ ...(options.branch !== undefined ? { branch: options.branch } : {}),
728
+ ...(options.commit !== undefined ? { commit: options.commit } : {}),
729
+ opencodeProviders: resolved.providers,
730
+ // Synthetic arm follows from `arms` containing "synthetic".
731
+ ...(resolved.arms.includes("synthetic") ? { includeSynthetic: true } : {}),
732
+ });
733
+ const { json, markdown } = renderUtilityReport(report);
734
+ const stdout = `${JSON.stringify(json, null, 2)}\n`;
735
+ let stderr = options.json ? "" : `${markdown}\n`;
736
+ stderr += `bench: config=${resolved.name} tasks=${resolved.tasks.length} arms=${resolved.arms.join(",")} model=${resolved.model}\n`;
737
+ return { exitCode: 0, stdout, stderr };
738
+ }
539
739
  /**
540
740
  * `evolve` subcommand. Filters the corpus to one domain (or `all`), then
541
741
  * dispatches `runEvolve` and renders the §6.3+§6.4 envelope.
@@ -574,6 +774,43 @@ async function main(argv) {
574
774
  process.stdout.write(HELP);
575
775
  return parsed.subcommand === "" ? 2 : 0;
576
776
  }
777
+ // Config-file dispatch: when argv[0] looks like a JSON path that exists,
778
+ // route to `runConfigCli`. This is the new common-case entry point —
779
+ // existing subcommand-style invocations are untouched.
780
+ if (parsed.subcommand.endsWith(".json") && fs.existsSync(parsed.subcommand)) {
781
+ const tasksRaw = parsed.flags.get("tasks");
782
+ const tasksList = tasksRaw
783
+ ? tasksRaw
784
+ .split(",")
785
+ .map((s) => s.trim())
786
+ .filter((s) => s.length > 0)
787
+ : undefined;
788
+ const seedsRaw = parsed.flags.get("seeds");
789
+ const parallelRaw = parsed.flags.get("parallel");
790
+ const removePid = writeBenchPid();
791
+ let result;
792
+ try {
793
+ result = await runConfigCli({
794
+ configPath: parsed.subcommand,
795
+ json: parsed.bool.has("json"),
796
+ ...(tasksList ? { tasksList } : {}),
797
+ ...(seedsRaw !== undefined ? { seedsPerArm: parseInt32(seedsRaw, 5) } : {}),
798
+ ...(parallelRaw !== undefined ? { parallel: parseInt32(parallelRaw, 1) } : {}),
799
+ });
800
+ }
801
+ finally {
802
+ removePid();
803
+ }
804
+ if (result.stdout)
805
+ process.stdout.write(result.stdout);
806
+ if (result.stderr)
807
+ process.stderr.write(result.stderr);
808
+ return result.exitCode;
809
+ }
810
+ // Emit obsolete-flag warnings for the legacy subcommand path. The new
811
+ // config-file path above never reaches this code so config-mode runs
812
+ // never spuriously warn.
813
+ warnIfObsoleteFlagsUsed(parsed);
577
814
  switch (parsed.subcommand) {
578
815
  case "utility": {
579
816
  const sliceRaw = parsed.flags.get("tasks") ?? "all";
@@ -582,20 +819,43 @@ async function main(argv) {
582
819
  return 2;
583
820
  }
584
821
  const slice = sliceRaw;
585
- const model = getEnv("BENCH_OPENCODE_MODEL");
822
+ // Load provider config at CLI startup (before any runs).
823
+ let opencodeProviders;
824
+ try {
825
+ opencodeProviders = discoverOpencodeProviders(parsed.flags.get("opencode-config"));
826
+ }
827
+ catch (err) {
828
+ const exitCode = err instanceof BenchConfigError && err.isUsageError ? 2 : 78;
829
+ process.stderr.write(`bench utility: ${err instanceof Error ? err.message : String(err)}\n`);
830
+ return exitCode;
831
+ }
832
+ // BENCH_OPENCODE_MODEL: flag → env var → loaded.defaultModel → error exit 2.
833
+ const model = getEnv("BENCH_OPENCODE_MODEL") ?? opencodeProviders?.defaultModel;
586
834
  if (!model) {
587
835
  process.stderr.write("bench utility: BENCH_OPENCODE_MODEL environment variable is required.\n");
588
836
  return 2;
589
837
  }
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
- });
838
+ // Write PID file so `bench kill` can terminate this run.
839
+ const removePid = writeBenchPid();
840
+ let result;
841
+ try {
842
+ result = await runUtilityCli({
843
+ slice,
844
+ json: parsed.bool.has("json"),
845
+ seedsPerArm: parseInt32(parsed.flags.get("seeds"), 5),
846
+ budgetTokens: parseInt32(parsed.flags.get("budget-tokens"), 30000),
847
+ budgetWallMs: parseInt32(parsed.flags.get("budget-wall-ms"), 120000),
848
+ model,
849
+ parallel: parseInt32(parsed.flags.get("parallel"), 1),
850
+ ...(parsed.bool.has("force-parallel") ? { forceParallel: true } : {}),
851
+ ...(parsed.bool.has("include-synthetic") ? { includeSynthetic: true } : {}),
852
+ ...(parsed.bool.has("no-noakm") ? { includeNoakm: false } : {}),
853
+ ...(opencodeProviders ? { opencodeProviders } : {}),
854
+ });
855
+ }
856
+ finally {
857
+ removePid();
858
+ }
599
859
  if (result.stdout)
600
860
  process.stdout.write(result.stdout);
601
861
  if (result.stderr)
@@ -608,28 +868,49 @@ async function main(argv) {
608
868
  process.stderr.write("bench evolve: --tasks <domain> is required (use --tasks all to run the full corpus).\n");
609
869
  return 2;
610
870
  }
611
- const model = getEnv("BENCH_OPENCODE_MODEL");
871
+ // Load provider config at CLI startup (before any runs).
872
+ let opencodeProvidersEvolve;
873
+ try {
874
+ opencodeProvidersEvolve = discoverOpencodeProviders(parsed.flags.get("opencode-config"));
875
+ }
876
+ catch (err) {
877
+ const exitCode = err instanceof BenchConfigError && err.isUsageError ? 2 : 78;
878
+ process.stderr.write(`bench evolve: ${err instanceof Error ? err.message : String(err)}\n`);
879
+ return exitCode;
880
+ }
881
+ const model = getEnv("BENCH_OPENCODE_MODEL") ?? opencodeProvidersEvolve?.defaultModel;
612
882
  if (!model) {
613
883
  process.stderr.write("bench evolve: BENCH_OPENCODE_MODEL environment variable is required.\n");
614
884
  return 2;
615
885
  }
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;
886
+ // Write PID file so `bench kill` can terminate this run.
887
+ const removePidEvolve = writeBenchPid();
888
+ let resultEvolve;
889
+ try {
890
+ resultEvolve = await runEvolveCli({
891
+ domain,
892
+ json: parsed.bool.has("json"),
893
+ seedsPerArm: parseInt32(parsed.flags.get("seeds"), 5),
894
+ budgetTokens: parseInt32(parsed.flags.get("budget-tokens"), 30000),
895
+ budgetWallMs: parseInt32(parsed.flags.get("budget-wall-ms"), 120000),
896
+ model,
897
+ parallel: parseInt32(parsed.flags.get("parallel"), 1),
898
+ ...(parsed.bool.has("force-parallel") ? { forceParallel: true } : {}),
899
+ negativeThreshold: {
900
+ absoluteCount: parseInt32(parsed.flags.get("negative-threshold-count"), 2),
901
+ ratio: parseFloatArg(parsed.flags.get("negative-threshold-ratio"), 0.5),
902
+ },
903
+ ...(opencodeProvidersEvolve ? { opencodeProviders: opencodeProvidersEvolve } : {}),
904
+ });
905
+ }
906
+ finally {
907
+ removePidEvolve();
908
+ }
909
+ if (resultEvolve.stdout)
910
+ process.stdout.write(resultEvolve.stdout);
911
+ if (resultEvolve.stderr)
912
+ process.stderr.write(resultEvolve.stderr);
913
+ return resultEvolve.exitCode;
633
914
  }
634
915
  case "compare": {
635
916
  const basePath = parsed.flags.get("base");
@@ -657,6 +938,19 @@ async function main(argv) {
657
938
  process.stderr.write("bench attribute: --base <path> is required.\n");
658
939
  return 2;
659
940
  }
941
+ // Load provider config for parity (attribute re-runs use the same model + provider).
942
+ let opencodeProvidersAttr;
943
+ try {
944
+ opencodeProvidersAttr = discoverOpencodeProviders(parsed.flags.get("opencode-config"));
945
+ }
946
+ catch (err) {
947
+ const exitCode = err instanceof BenchConfigError && err.isUsageError ? 2 : 78;
948
+ process.stderr.write(`bench attribute: ${err instanceof Error ? err.message : String(err)}\n`);
949
+ return exitCode;
950
+ }
951
+ // Suppress unused variable warning — opencodeProvidersAttr is exposed for
952
+ // future wiring when runMaskedCorpus accepts it. For now it only validates.
953
+ void opencodeProvidersAttr;
660
954
  const topN = parseInt32(parsed.flags.get("top"), 5);
661
955
  const result = await runAttributeCli({
662
956
  basePath,
@@ -669,6 +963,47 @@ async function main(argv) {
669
963
  process.stderr.write(result.stderr);
670
964
  return result.exitCode;
671
965
  }
966
+ case "kill": {
967
+ const pid = readBenchPid();
968
+ if (pid === undefined) {
969
+ process.stdout.write("no bench running\n");
970
+ return 0;
971
+ }
972
+ if (!isPidRunning(pid)) {
973
+ process.stdout.write(`no bench running (stale PID file for PID ${pid} — cleaning up)\n`);
974
+ try {
975
+ const { benchPidPath } = await import("./tmp");
976
+ const { default: nodeFs } = await import("node:fs");
977
+ nodeFs.rmSync(benchPidPath(), { force: true });
978
+ }
979
+ catch {
980
+ /* best-effort */
981
+ }
982
+ return 0;
983
+ }
984
+ try {
985
+ process.kill(pid, "SIGTERM");
986
+ process.stdout.write(`sent SIGTERM to bench process ${pid}\n`);
987
+ process.stdout.write("run `bench kill` again to escalate to SIGKILL if the process does not exit.\n");
988
+ }
989
+ catch (err) {
990
+ process.stderr.write(`bench kill: failed to signal PID ${pid}: ${err instanceof Error ? err.message : String(err)}\n`);
991
+ return 1;
992
+ }
993
+ return 0;
994
+ }
995
+ case "clean": {
996
+ const benchRoot = path.join(getCacheDir(), "bench");
997
+ try {
998
+ fs.rmSync(benchRoot, { recursive: true, force: true });
999
+ process.stderr.write(`bench clean: removed ${benchRoot}\n`);
1000
+ }
1001
+ catch (err) {
1002
+ process.stderr.write(`bench clean: failed to remove ${benchRoot}: ${err.message}\n`);
1003
+ return 1;
1004
+ }
1005
+ return 0;
1006
+ }
672
1007
  default:
673
1008
  process.stderr.write(`unknown subcommand: ${parsed.subcommand}\n`);
674
1009
  process.stderr.write(HELP);