skillfit 0.10.0 → 0.11.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 (104) hide show
  1. package/README.md +27 -7
  2. package/README.zh-CN.md +27 -7
  3. package/benches/README.md +2 -2
  4. package/dist/cli.js +146 -36
  5. package/dist/cli.test.js +94 -0
  6. package/dist/commands/bench-calibration.js +197 -0
  7. package/dist/commands/bench-calibration.test.js +237 -0
  8. package/dist/commands/bench-check-json.test.js +24 -3
  9. package/dist/commands/bench.js +69 -141
  10. package/dist/commands/calibration-cli.test.js +145 -0
  11. package/dist/commands/eval-agent-preflight.test.js +245 -0
  12. package/dist/commands/eval-cli.js +31 -0
  13. package/dist/commands/eval-component.js +59 -28
  14. package/dist/commands/eval-export-modes.test.js +350 -0
  15. package/dist/commands/eval-export.js +44 -10
  16. package/dist/commands/eval-export.test.js +165 -8
  17. package/dist/commands/eval-interruption.test.js +238 -0
  18. package/dist/commands/eval-plan.js +37 -0
  19. package/dist/commands/eval-preflight.js +61 -0
  20. package/dist/commands/eval-preflight.test.js +382 -0
  21. package/dist/commands/eval-report.js +60 -14
  22. package/dist/commands/eval-report.test.js +2 -2
  23. package/dist/commands/eval-single-arm-replay.js +21 -0
  24. package/dist/commands/eval-single-arm-report.js +223 -0
  25. package/dist/commands/eval.js +184 -112
  26. package/dist/commands/evaluation-report.js +5 -0
  27. package/dist/commands/evaluation-report.test.js +243 -0
  28. package/dist/commands/replay-cancellation.test.js +105 -0
  29. package/dist/commands/workflow-entrypoints.test.js +137 -0
  30. package/dist/harness/agent-preflight.js +180 -0
  31. package/dist/harness/bench.js +2 -1
  32. package/dist/harness/command.js +49 -0
  33. package/dist/harness/eval-audit.js +164 -17
  34. package/dist/harness/eval-budget.js +46 -2
  35. package/dist/harness/eval-budget.test.js +30 -3
  36. package/dist/harness/eval-component.test.js +169 -6
  37. package/dist/harness/eval-contract.js +11 -5
  38. package/dist/harness/executors/api.js +14 -4
  39. package/dist/harness/executors/api.test.js +61 -0
  40. package/dist/harness/executors/cli.js +24 -3
  41. package/dist/harness/experiment-session.js +77 -18
  42. package/dist/harness/experiment-session.test.js +51 -1
  43. package/dist/harness/input-snapshot.js +150 -0
  44. package/dist/harness/interruption.js +48 -0
  45. package/dist/harness/interruption.test.js +31 -0
  46. package/dist/harness/invocation-costs.js +72 -0
  47. package/dist/harness/judge-accounting.test.js +216 -0
  48. package/dist/harness/judge-audit.js +56 -0
  49. package/dist/harness/judge.js +86 -21
  50. package/dist/harness/replay-package.js +71 -5
  51. package/dist/harness/runner.js +92 -44
  52. package/dist/harness/runner.test.js +23 -0
  53. package/dist/harness/single-arm-audit.js +436 -0
  54. package/dist/harness/trigger.js +41 -7
  55. package/dist/harness/trigger.test.js +12 -0
  56. package/dist/harness/verifier-error.js +65 -0
  57. package/dist/harness/verifier.test.js +128 -0
  58. package/docs/bench-authoring.md +34 -9
  59. package/docs/bench-check-json.md +36 -6
  60. package/docs/eval-agent-preflight.md +101 -0
  61. package/docs/eval-case-preflight.md +115 -0
  62. package/docs/eval-component.md +65 -9
  63. package/docs/eval-costs.md +53 -0
  64. package/docs/eval-planning.md +153 -0
  65. package/docs/evaluation-input-snapshots.md +125 -0
  66. package/docs/evaluation-interruption.md +101 -0
  67. package/docs/evaluation-reports.md +143 -0
  68. package/docs/experiment-workflow.md +16 -2
  69. package/docs/first-real-eval.md +55 -5
  70. package/docs/growth-roadmap-2026-10.md +48 -11
  71. package/docs/metrics.md +71 -3
  72. package/docs/plans/2026-10-16-case-workflow-and-release.md +19 -0
  73. package/docs/plans/2026-10-17-workflow-foundations.md +64 -0
  74. package/docs/releases/0.10.0-ci-registry-install.json +140 -0
  75. package/docs/releases/0.10.0-feature-smoke.json +22 -0
  76. package/docs/releases/0.10.0-feature-smoke.mjs +62 -0
  77. package/docs/releases/0.10.0-signatures.txt +7 -0
  78. package/docs/releases/0.10.0-verification.json +76 -0
  79. package/docs/releases/0.10.0.md +44 -8
  80. package/docs/releases/0.10.1-ci-registry-install.json +70 -0
  81. package/docs/releases/0.10.1-feature-smoke.json +28 -0
  82. package/docs/releases/0.10.1-feature-smoke.mjs +95 -0
  83. package/docs/releases/0.10.1-local-registry-install.json +60 -0
  84. package/docs/releases/0.10.1-registry-metadata.json +33 -0
  85. package/docs/releases/0.10.1-signatures.txt +7 -0
  86. package/docs/releases/0.10.1-verification.json +90 -0
  87. package/docs/releases/0.10.1.md +71 -0
  88. package/docs/releases/0.11.0-feature-smoke.mjs +224 -0
  89. package/docs/releases/0.11.0.md +47 -0
  90. package/docs/replay-packages.md +52 -11
  91. package/docs/schemas/agent-preflight.schema.json +31 -0
  92. package/docs/schemas/calibration-plan.schema.json +22 -0
  93. package/docs/schemas/calibration-result.schema.json +17 -0
  94. package/docs/schemas/eval-preflight.schema.json +57 -0
  95. package/docs/schemas/eval-request.schema.json +1 -1
  96. package/docs/schemas/eval-result.schema.json +14 -1
  97. package/docs/schemas/invocation-costs.schema.json +31 -0
  98. package/docs/schemas/judge-call.schema.json +22 -0
  99. package/docs/schemas/single-arm-report.schema.json +20 -0
  100. package/docs/schemas/verifier-error.schema.json +11 -0
  101. package/docs/sharing-results.md +8 -2
  102. package/docs/verifier-contract.md +99 -0
  103. package/package.json +1 -1
  104. package/skills/skillfit/SKILL.md +41 -8
@@ -6,19 +6,24 @@ import { getAgent } from '../agents.js';
6
6
  import { loadBench, selectBenchTasks } from '../harness/bench.js';
7
7
  import { RUN_GROUP_PATTERN } from '../harness/constants.js';
8
8
  import { ExperimentSession, validateCallBudget } from '../harness/experiment-session.js';
9
- import { ApiExecutor } from '../harness/executors/api.js';
10
- import { CliExecutor, DEFAULT_CLI_TIMEOUT_MS } from '../harness/executors/cli.js';
9
+ import { ApiExecutor, DEFAULT_API_TIMEOUT_MS } from '../harness/executors/api.js';
10
+ import { CliExecutor } from '../harness/executors/cli.js';
11
11
  import { listFilesRecursive } from '../harness/hash.js';
12
12
  import { assertNativeDiffFixtures, nativeDiffDescriptor } from '../harness/native-diff.js';
13
13
  import { assertInstalledSkillFixtures, assertSkillRevisionTargets, collectInstalledSkillTarget } from '../harness/installed-skill.js';
14
14
  import { assertInputModeSupported } from '../harness/prompt.js';
15
15
  import { CONCLUSIVE_TASKS, CONCLUSIVE_TRIALS, renderSummary } from '../harness/report.js';
16
- import { runExperiment } from '../harness/runner.js';
16
+ import { runExperiment, withSampling } from '../harness/runner.js';
17
17
  import { collectInstalledSkillFingerprint } from '../harness/bundle.js';
18
18
  import { installedUserSkills } from '../harness/receipts.js';
19
19
  import { collectEvaluationTarget } from '../harness/target.js';
20
20
  import { renderTriggerSummary, runTriggerExperiment, } from '../harness/trigger.js';
21
+ import { parseExecutorTimeoutSeconds, parsePairOrder } from '../harness/eval-contract.js';
21
22
  import { parseSpendingBudget } from '../harness/eval-budget.js';
23
+ import { withEvaluationInterrupts, throwIfEvaluationInterrupted } from '../harness/interruption.js';
24
+ import { CASE_PREFLIGHT_POLICY, checkEvalCases } from './eval-preflight.js';
25
+ import { INPUT_SNAPSHOT_POLICY } from '../harness/input-snapshot.js';
26
+ import { inspectAgentEnvironment, assertAgentEnvironment, assertAgentEnvironmentUnchanged, renderAgentEnvironment } from '../harness/agent-preflight.js';
22
27
  export const DEFAULT_EVAL_TRIALS = 5;
23
28
  function bundledBenchesRoot() {
24
29
  return fileURLToPath(new URL('../../benches', import.meta.url));
@@ -59,7 +64,7 @@ function resolveExecutor(agent, target, installed = false, executorTimeoutSecond
59
64
  ...(installed && definition.headless.streamJson ? { triggerSkillName: target.name } : {}),
60
65
  });
61
66
  }
62
- return ApiExecutor.fromEnv();
67
+ return ApiExecutor.fromEnv(process.env, executorTimeoutSeconds === undefined ? {} : { timeoutMs: executorTimeoutSeconds * 1000 });
63
68
  }
64
69
  /**
65
70
  * An API executor has no filesystem access, so it cannot satisfy a `verifierKind: "command"` task.
@@ -81,23 +86,19 @@ function assertExecutorSupportsBench(executor, bench) {
81
86
  'would be written and both arms would score 0. Use --agent <id> for a CLI executor that works in the run ' +
82
87
  'directory, or re-grade those tasks as verifierKind "output".');
83
88
  }
84
- function resolveJudge(judgeAgent) {
89
+ function resolveJudge(judgeAgent, timeoutSeconds) {
85
90
  const flag = process.env['SKILLFIT_JUDGE'];
86
91
  if (!judgeAgent && (!flag || flag === '0' || flag === 'false'))
87
92
  return null;
88
93
  if (judgeAgent) {
89
- return CliExecutor.forAgent(judgeAgent);
90
- }
91
- try {
92
- return new ApiExecutor({
93
- apiKey: process.env['SKILLFIT_JUDGE_API_KEY'] ?? process.env['SKILLFIT_API_KEY'] ?? process.env['OPENAI_API_KEY'],
94
- model: process.env['SKILLFIT_JUDGE_MODEL'] ?? process.env['SKILLFIT_API_MODEL'],
95
- baseUrl: process.env['SKILLFIT_JUDGE_BASE_URL'] ?? process.env['SKILLFIT_API_BASE_URL'],
96
- });
97
- }
98
- catch {
99
- return null;
94
+ return CliExecutor.forAgent(judgeAgent, timeoutSeconds === undefined ? {} : { timeoutMs: timeoutSeconds * 1000 });
100
95
  }
96
+ return new ApiExecutor({
97
+ apiKey: process.env['SKILLFIT_JUDGE_API_KEY'] ?? process.env['SKILLFIT_API_KEY'] ?? process.env['OPENAI_API_KEY'],
98
+ model: process.env['SKILLFIT_JUDGE_MODEL'] ?? process.env['SKILLFIT_API_MODEL'],
99
+ baseUrl: process.env['SKILLFIT_JUDGE_BASE_URL'] ?? process.env['SKILLFIT_API_BASE_URL'],
100
+ ...(timeoutSeconds === undefined ? {} : { timeoutMs: timeoutSeconds * 1000 }),
101
+ });
101
102
  }
102
103
  function defaultRunGroup(now = new Date()) {
103
104
  const pad2 = (value) => String(value).padStart(2, '0');
@@ -105,6 +106,15 @@ function defaultRunGroup(now = new Date()) {
105
106
  const time = `${pad2(now.getHours())}${pad2(now.getMinutes())}${pad2(now.getSeconds())}`;
106
107
  return `eval-${date}-${time}`;
107
108
  }
109
+ function inspectEvalAgent(options, target, executor, judge, capabilityError, resolutionError, judgeError) {
110
+ const roles = [{ role: 'agent', definition: options.agent ? getAgent(options.agent) : undefined,
111
+ executor: executor?.describe() ?? null, injected: options.executor !== undefined, resolutionError }];
112
+ if (judge || judgeError)
113
+ roles.push({ role: 'judge', definition: options.judgeAgent ? getAgent(options.judgeAgent) : undefined,
114
+ executor: judge?.describe() ?? null, injected: options.judgeExecutor != null, resolutionError: judgeError });
115
+ return inspectAgentEnvironment({ roles, mode: options.mode ?? 'inject', target, capabilityError,
116
+ homeDir: options.sessionOptions?.homeDir, env: options.sessionOptions?.env });
117
+ }
108
118
  function sessionFor(options, bench, target, trials, runsRoot, runGroup, armNames, plannedCalls, details, baselineTarget) {
109
119
  if (!RUN_GROUP_PATTERN.test(runGroup))
110
120
  throw new Error(`Invalid run group: ${runGroup}`);
@@ -141,6 +151,8 @@ function renderPlan(bench, target, executor, judge, trials, runsRoot, runGroup,
141
151
  lines.push(`Baseline : ${baselineTarget.name} (${baselineTarget.files.length} files, bundle sha256 ${baselineTarget.sha256.slice(0, 12)}…)`);
142
152
  lines.push('Compare : previous Skill in baseline vs target Skill in treatment; measures revision effects, not benefit over no Skill');
143
153
  }
154
+ else if (inputMode === 'workspace' && target.kind === 'skill')
155
+ lines.push('Baseline : no Skill installed by the harness (inherited configuration still applies)');
144
156
  if (target.kind !== 'skill') {
145
157
  lines.push(' applied as project files; treatment material is never injected into the prompt');
146
158
  }
@@ -202,17 +214,21 @@ function renderTriggerPlan(bench, skill, executor, trials, runsRoot, runGroup, i
202
214
  return lines.join('\n');
203
215
  }
204
216
  async function runEvalTrigger(options, bench, skill, trials, log) {
217
+ if (options.judgeAgent || options.judgeExecutor)
218
+ throw new Error('Trigger evaluation does not use a judge.');
219
+ const executorTimeoutSeconds = parseExecutorTimeoutSeconds(options.executorTimeoutSeconds);
220
+ const spendingBudget = options.spendingBudget === undefined ? undefined : parseSpendingBudget(options.spendingBudget);
205
221
  let executor = options.executor ?? null;
222
+ let resolutionError;
206
223
  if (!executor) {
207
224
  if (!options.agent) {
208
225
  throw new Error('trigger mode requires --agent (a CLI executor with trigger detection); API executors cannot measure skill triggering.');
209
226
  }
210
227
  try {
211
- executor = CliExecutor.forAgent(options.agent, { triggerSkillName: skill.name });
228
+ executor = CliExecutor.forAgent(options.agent, { triggerSkillName: skill.name, timeoutMs: executorTimeoutSeconds * 1000 });
212
229
  }
213
230
  catch (error) {
214
- if (!options.dryRun)
215
- throw error;
231
+ resolutionError = error.message;
216
232
  log(`Note: ${error.message}`);
217
233
  }
218
234
  }
@@ -222,6 +238,8 @@ async function runEvalTrigger(options, bench, skill, trials, log) {
222
238
  const runGroup = options.runGroup ?? defaultRunGroup();
223
239
  const plannedCalls = bench.tasks.filter(task => task.shouldTrigger !== undefined).length * trials;
224
240
  const maxCalls = validateCallBudget(plannedCalls, options.maxCalls);
241
+ const inspect = () => inspectEvalAgent(options, skill, executor, null, undefined, resolutionError);
242
+ const agentPreflight = inspect();
225
243
  if (!RUN_GROUP_PATTERN.test(runGroup))
226
244
  throw new Error(`Invalid run group: ${runGroup}`);
227
245
  const competitors = options.competeInstalled && options.agent
@@ -233,54 +251,82 @@ async function runEvalTrigger(options, bench, skill, trials, log) {
233
251
  const competeLine = competitors.length === 0
234
252
  ? 'Compete : alone (recall is an upper bound)'
235
253
  : `Compete : ${competitors.map((entry) => entry.name).join(', ')}`;
254
+ const installedFingerprint = collectInstalledSkillFingerprint(skill.sourceDir);
255
+ const competition = { mode: competitors.length ? 'installed' : 'alone', skills: competitors };
256
+ options.onPlan?.({ mode: 'trigger', target: { kind: 'skill', name: skill.name, sourceDir: skill.sourceDir,
257
+ sha256: skill.sha256, files: skill.files }, baseline: null,
258
+ bench: { name: bench.name, dir: bench.dir, sha256: bench.contentSha256, taskIds: bench.tasks.map(task => task.id) },
259
+ executor: executor?.describe() ?? null, judge: null, inputMode: 'workspace', installDir: installDir ?? null,
260
+ trials, plannedCalls, maxCalls, outputDir: join(runsRoot, runGroup),
261
+ agentPreflight, casePreflight: { ...CASE_PREFLIGHT_POLICY, status: 'pending' }, inputSnapshot: { ...INPUT_SNAPSHOT_POLICY },
262
+ executorTimeoutSeconds, ...(spendingBudget ? { spendingBudget } : {}),
263
+ installedFingerprint: { sha256: installedFingerprint.sha256, files: installedFingerprint.files }, competition, detection });
236
264
  if (options.dryRun) {
237
265
  log(renderTriggerPlan(bench, skill, executor, trials, runsRoot, runGroup, installDir));
266
+ log(renderAgentEnvironment(agentPreflight));
267
+ log('Case preflight: pending; required before execution. Dry run does not execute verifiers or oracles.');
238
268
  log(competeLine);
239
269
  log(`Calls : ${plannedCalls} planned; ceiling ${maxCalls} (agent calls only)`);
270
+ log(`Agent deadline: ${executorTimeoutSeconds}s per invocation`);
271
+ if (spendingBudget)
272
+ log(`Spending stop lines: ${JSON.stringify(spendingBudget)}; checked between calls, in-flight overshoot remains possible`);
240
273
  return null;
241
274
  }
275
+ assertAgentEnvironment(agentPreflight);
242
276
  if (!executor) {
243
277
  throw new Error('No executor available for trigger mode; pass --agent.');
244
278
  }
245
279
  if (!installDir) {
246
280
  throw new Error('trigger mode needs a skill install directory: pass --agent (the matrix provides one) or skillInstallDir.');
247
281
  }
248
- log(renderTriggerPlan(bench, skill, executor, trials, runsRoot, runGroup, installDir).replace(' (dry run)', '').replace(' (not created)', '').replace('Dry run — nothing was written.', `Calls : ${plannedCalls} planned; ceiling ${maxCalls}`));
249
- log(competeLine);
250
- const session = sessionFor(options, bench, skill, trials, runsRoot, runGroup, ['installed'], plannedCalls, { mode: 'trigger', trials, executor: executor.describe() });
251
- let manifest;
252
- try {
253
- manifest = await runTriggerExperiment({
254
- bench,
255
- skill,
256
- executor: session.wrap(executor, 'agent'),
257
- session,
258
- trials,
259
- runsRoot,
260
- runGroup,
261
- skillInstallDir: installDir,
262
- competitors,
263
- detection,
264
- log,
265
- });
266
- }
267
- catch (error) {
268
- session.finish(error);
269
- throw error;
270
- }
271
- session.finish(undefined, manifest);
272
- log(renderTriggerSummary(manifest, join(runsRoot, runGroup, 'manifest.json')));
273
- return manifest;
282
+ return withEvaluationInterrupts(async () => {
283
+ if (existsSync(join(runsRoot, runGroup)))
284
+ throw new Error(`Run group directory already exists: ${join(runsRoot, runGroup)}`);
285
+ const eligible = { ...bench, tasks: bench.tasks.filter(t => t.shouldTrigger !== undefined) };
286
+ const casePreflight = await checkEvalCases(eligible, [skill], false, log);
287
+ assertAgentEnvironmentUnchanged(agentPreflight, inspect());
288
+ if (collectInstalledSkillFingerprint(skill.sourceDir).sha256 !== installedFingerprint.sha256 ||
289
+ competitors.some(entry => collectInstalledSkillFingerprint(entry.sourceDir).sha256 !== entry.sha256)) {
290
+ throw new Error('Installed Skill resources changed during case preflight; create a fresh plan. No calls started.');
291
+ }
292
+ throwIfEvaluationInterrupted();
293
+ log(renderTriggerPlan(bench, skill, executor, trials, runsRoot, runGroup, installDir).replace(' (dry run)', '').replace(' (not created)', '').replace('Dry run — nothing was written.', `Calls : ${plannedCalls} planned; ceiling ${maxCalls}`));
294
+ log(competeLine);
295
+ log(renderAgentEnvironment(agentPreflight));
296
+ const session = sessionFor(options, bench, skill, trials, runsRoot, runGroup, ['installed'], plannedCalls, { mode: 'trigger', trials, executor: executor.describe(), casePreflight, agentPreflight,
297
+ skillInstallDir: installDir, executorTimeoutSeconds, competition, detection,
298
+ ...(options.reviewedPlan ? { reviewedPlan: options.reviewedPlan } : {}),
299
+ ...(spendingBudget ? { spendingBudget } : {}) });
300
+ let manifest;
301
+ try {
302
+ manifest = await runTriggerExperiment({
303
+ bench,
304
+ skill,
305
+ executor: session.wrap(executor, 'agent'),
306
+ session,
307
+ trials,
308
+ runsRoot,
309
+ runGroup,
310
+ skillInstallDir: installDir,
311
+ competitors,
312
+ detection,
313
+ ...(spendingBudget ? { spendingBudget } : {}),
314
+ log,
315
+ });
316
+ throwIfEvaluationInterrupted();
317
+ }
318
+ catch (error) {
319
+ session.finish(error);
320
+ throw error;
321
+ }
322
+ session.finish(undefined, manifest);
323
+ log(renderTriggerSummary(manifest, join(runsRoot, runGroup, 'manifest.json')));
324
+ return manifest;
325
+ });
274
326
  }
275
327
  export async function runEval(options) {
276
- if (options.spendingBudget !== undefined && options.mode === 'trigger')
277
- throw new Error('spendingBudget applies only to paired evaluations.');
278
- const executorTimeoutSeconds = options.executorTimeoutSeconds ?? DEFAULT_CLI_TIMEOUT_MS / 1000;
279
- if (!Number.isSafeInteger(executorTimeoutSeconds) || executorTimeoutSeconds < 1 || executorTimeoutSeconds > 3600) {
280
- throw new Error('executorTimeoutSeconds must be an integer between 1 and 3600.');
281
- }
282
- if (options.executorTimeoutSeconds !== undefined && !options.agent && !options.executor)
283
- throw new Error('executorTimeoutSeconds requires a CLI agent.');
328
+ const executorTimeoutSeconds = parseExecutorTimeoutSeconds(options.executorTimeoutSeconds ??
329
+ (!options.agent && !options.executor ? DEFAULT_API_TIMEOUT_MS / 1000 : undefined));
284
330
  const log = options.log ?? ((msg) => console.log(msg));
285
331
  const installed = options.mode === 'installed';
286
332
  if (options.baselineSkillPath !== undefined && !installed) {
@@ -291,9 +337,6 @@ export async function runEval(options) {
291
337
  }
292
338
  const inputMode = options.inputMode ?? (installed ? 'workspace' : 'snapshot');
293
339
  assertInputModeSupported(inputMode, null);
294
- if (inputMode === 'workspace' && !options.agent && !options.executor) {
295
- throw new Error('workspace input requires --agent <id> for a CLI executor; API keys do not provide filesystem access.');
296
- }
297
340
  if (options.mode === 'trigger' && options.inputMode !== undefined) {
298
341
  throw new Error('--input applies only to paired modes; trigger mode already presents files on disk.');
299
342
  }
@@ -329,8 +372,6 @@ export async function runEval(options) {
329
372
  assertNativeDiffFixtures(bench);
330
373
  }
331
374
  if ((options.mode ?? 'inject') === 'trigger') {
332
- if (options.executorTimeoutSeconds !== undefined)
333
- throw new Error('executorTimeoutSeconds is only available for paired experiments.');
334
375
  if (options.pairOrder !== undefined)
335
376
  throw new Error('pairOrder is only available for paired experiments.');
336
377
  if (target.kind !== 'skill') {
@@ -338,9 +379,6 @@ export async function runEval(options) {
338
379
  }
339
380
  return runEvalTrigger(options, bench, target, trials, log);
340
381
  }
341
- if (target.kind !== 'skill' && !options.agent && !options.executor) {
342
- throw new Error(`${target.kind} experiments require --agent because API executors do not load project configuration files.`);
343
- }
344
382
  if (target.kind !== 'skill' && options.agent) {
345
383
  const agent = getAgent(options.agent);
346
384
  const expected = (target.kind === 'mcp' ? agent.mcp.projectFiles : agent.rules.projectFiles)
@@ -360,23 +398,43 @@ export async function runEval(options) {
360
398
  }
361
399
  }
362
400
  let executor = null;
401
+ let resolutionError;
363
402
  try {
364
- executor = options.executor ?? resolveExecutor(options.agent, target, installed, options.executorTimeoutSeconds);
403
+ executor = options.executor ?? resolveExecutor(options.agent, target, installed, executorTimeoutSeconds);
365
404
  }
366
405
  catch (error) {
367
- if (!options.dryRun)
368
- throw error;
406
+ resolutionError = error.message;
369
407
  log(`Note: ${error.message}`);
370
408
  }
371
- assertExecutorSupportsBench(executor, bench);
372
- assertInputModeSupported(inputMode, executor);
373
- if (target.kind !== 'skill' && executor?.describe().kind === 'api') {
374
- throw new Error(`${target.kind} experiments require a CLI executor; API executors cannot load project configuration files.`);
409
+ let capabilityError;
410
+ try {
411
+ if (inputMode === 'workspace' && !options.agent && !options.executor) {
412
+ throw new Error('workspace input requires --agent <id> for a CLI executor; API keys do not provide filesystem access.');
413
+ }
414
+ if (target.kind !== 'skill' && !options.agent && !options.executor) {
415
+ throw new Error(`${target.kind} experiments require --agent because API executors do not load project configuration files.`);
416
+ }
417
+ assertExecutorSupportsBench(executor, bench);
418
+ assertInputModeSupported(inputMode, executor);
419
+ if (target.kind !== 'skill' && executor?.describe().kind === 'api') {
420
+ throw new Error(`${target.kind} experiments require a CLI executor; API executors cannot load project configuration files.`);
421
+ }
422
+ }
423
+ catch (error) {
424
+ capabilityError = error.message;
425
+ }
426
+ let judge = null, judgeError;
427
+ try {
428
+ judge = options.judgeExecutor !== undefined ? options.judgeExecutor : resolveJudge(options.judgeAgent, executorTimeoutSeconds);
375
429
  }
376
- const judge = options.judgeExecutor !== undefined ? options.judgeExecutor : resolveJudge(options.judgeAgent);
430
+ catch (error) {
431
+ judgeError = error.message;
432
+ }
433
+ const inspect = () => inspectEvalAgent(options, target, executor, judge, capabilityError, resolutionError, judgeError);
434
+ const agentPreflight = inspect();
435
+ if (capabilityError)
436
+ assertAgentEnvironment(agentPreflight);
377
437
  const spendingBudget = options.spendingBudget === undefined ? undefined : parseSpendingBudget(options.spendingBudget);
378
- if (spendingBudget && judge)
379
- throw new Error('spendingBudget requires a paired evaluation without a judge; judge usage is not covered.');
380
438
  if (options.judgeAgent && options.judgeAgent === options.agent) {
381
439
  log('Warning: judge and executor are the same agent — self-preference bias risk (docs/metrics.md L4).');
382
440
  }
@@ -384,29 +442,32 @@ export async function runEval(options) {
384
442
  const runGroup = options.runGroup ?? defaultRunGroup();
385
443
  const plannedCalls = bench.tasks.length * trials * (judge ? 4 : 2);
386
444
  const maxCalls = validateCallBudget(plannedCalls, options.maxCalls);
387
- const pairOrder = options.pairOrder ?? 'baseline-first';
388
- if (pairOrder !== 'baseline-first' && pairOrder !== 'balanced')
389
- throw new Error('pairOrder must be baseline-first or balanced.');
445
+ const pairOrder = parsePairOrder(options.pairOrder);
390
446
  if (!RUN_GROUP_PATTERN.test(runGroup))
391
447
  throw new Error(`Invalid run group: ${runGroup}`);
392
448
  options.onPlan?.({
393
- target: { name: target.name, sourceDir: target.sourceDir, sha256: target.sha256, files: target.files },
449
+ mode: installed ? 'installed' : 'inject',
450
+ agentPreflight,
451
+ casePreflight: { ...CASE_PREFLIGHT_POLICY, status: 'pending' },
452
+ inputSnapshot: { ...INPUT_SNAPSHOT_POLICY },
453
+ target: { kind: target.kind, name: target.name, sourceDir: target.sourceDir, sha256: target.sha256, files: target.files },
394
454
  baseline: baselineTarget ? { name: baselineTarget.name, sourceDir: baselineTarget.sourceDir, sha256: baselineTarget.sha256, files: baselineTarget.files } : null,
395
455
  bench: { name: bench.name, dir: bench.dir, sha256: bench.contentSha256, taskIds: bench.tasks.map(t => t.id) },
396
- executor: executor?.describe() ?? null, judge: judge?.describe() ?? null, inputMode,
456
+ executor: executor ? withSampling(executor.describe()) : null, judge: judge ? withSampling(judge.describe()) : null, inputMode,
397
457
  installDir: skillInstallDir ?? null, trials, plannedCalls, maxCalls, pairOrder,
398
458
  ...(spendingBudget ? { spendingBudget } : {}),
399
459
  ...(installed ? { nativeDiffTool: nativeDiffDescriptor() } : {}),
400
- ...(options.agent || options.executorTimeoutSeconds !== undefined ? { executorTimeoutSeconds } : {}), outputDir: join(runsRoot, runGroup),
460
+ executorTimeoutSeconds, outputDir: join(runsRoot, runGroup),
401
461
  });
402
462
  if (options.dryRun) {
403
463
  log(renderPlan(bench, target, executor, judge, trials, runsRoot, runGroup, inputMode, baselineTarget));
464
+ log(renderAgentEnvironment(agentPreflight));
465
+ log('Case preflight: pending; required before execution. Dry run does not execute verifiers or oracles.');
404
466
  log(`Calls : ${plannedCalls} planned; ceiling ${maxCalls} (includes both judge orders when enabled)`);
405
467
  log(`Pair order: ${pairOrder}; arms remain adjacent`);
406
468
  if (spendingBudget)
407
469
  log(`Spending stop lines: ${JSON.stringify(spendingBudget)}; checked between calls, in-flight overshoot remains possible`);
408
- if (options.agent || options.executorTimeoutSeconds !== undefined)
409
- log(`Agent deadline: ${executorTimeoutSeconds}s per invocation in both arms`);
470
+ log(`Agent deadline: ${executorTimeoutSeconds}s per invocation in both arms`);
410
471
  if (skillInstallDir) {
411
472
  log('Tool : native untracked-file diff helper in both arms (version 1; environment correction)');
412
473
  log('Delivery : complete Skill resources installed ' + (baselineTarget ? 'in both conditions' : 'only in treatment') + ' at ' + skillInstallDir + '/' + target.name);
@@ -414,41 +475,52 @@ export async function runEval(options) {
414
475
  }
415
476
  return null;
416
477
  }
478
+ assertAgentEnvironment(agentPreflight);
417
479
  if (!executor) {
418
480
  throw new Error('No executor available; pass --agent or set SKILLFIT_API_KEY.');
419
481
  }
420
- log(renderPlan(bench, target, executor, judge, trials, runsRoot, runGroup, inputMode, baselineTarget).replace(' (dry run)', '').replace(' (not created)', '').replace('Dry run — nothing was written.', `Calls : ${plannedCalls} planned; ceiling ${maxCalls}`));
421
- const session = sessionFor(options, bench, target, trials, runsRoot, runGroup, ['baseline', 'treatment'], plannedCalls, { mode: installed ? 'installed' : 'inject', inputMode, trials, pairOrder,
422
- ...(spendingBudget ? { spendingBudget } : {}),
423
- ...(installed ? { nativeDiffTool: nativeDiffDescriptor() } : {}),
424
- ...(options.agent || options.executorTimeoutSeconds !== undefined ? { executorTimeoutSeconds } : {}), executor: executor.describe(), judge: judge?.describe() ?? null,
425
- ...(options.component ? { component: options.component } : {}),
426
- ...(baselineTarget ? { baselineTarget: { name: baselineTarget.name, sourceDir: baselineTarget.sourceDir, bundleSha256: baselineTarget.sha256, files: baselineTarget.files } } : {}) }, baselineTarget);
427
- let manifest;
428
- try {
429
- manifest = await runExperiment({
430
- bench,
431
- target,
432
- baselineTarget,
433
- component: options.component,
434
- pairOrder,
482
+ return withEvaluationInterrupts(async () => {
483
+ if (existsSync(join(runsRoot, runGroup)))
484
+ throw new Error(`Run group directory already exists: ${join(runsRoot, runGroup)}`);
485
+ const casePreflight = await checkEvalCases(bench, [target, ...(baselineTarget ? [baselineTarget] : [])], installed, log);
486
+ assertAgentEnvironmentUnchanged(agentPreflight, inspect());
487
+ throwIfEvaluationInterrupted();
488
+ log(renderPlan(bench, target, executor, judge, trials, runsRoot, runGroup, inputMode, baselineTarget).replace(' (dry run)', '').replace(' (not created)', '').replace('Dry run — nothing was written.', `Calls : ${plannedCalls} planned; ceiling ${maxCalls}`));
489
+ log(renderAgentEnvironment(agentPreflight));
490
+ const session = sessionFor(options, bench, target, trials, runsRoot, runGroup, ['baseline', 'treatment'], plannedCalls, { mode: installed ? 'installed' : 'inject', inputMode, trials, pairOrder, casePreflight, agentPreflight,
491
+ ...(options.reviewedPlan ? { reviewedPlan: options.reviewedPlan } : {}),
435
492
  ...(spendingBudget ? { spendingBudget } : {}),
436
- inputMode,
437
- ...(skillInstallDir ? { skillInstallDir, skillSearchDirs } : {}),
438
- executor: session.wrap(executor, 'agent'),
439
- judge: judge ? session.wrap(judge, 'judge') : null,
440
- session,
441
- trials,
442
- runsRoot,
443
- runGroup,
444
- log,
445
- });
446
- }
447
- catch (error) {
448
- session.finish(error);
449
- throw error;
450
- }
451
- session.finish(undefined, manifest);
452
- log(renderSummary(manifest, join(runsRoot, runGroup, 'manifest.json')));
453
- return manifest;
493
+ ...(installed ? { nativeDiffTool: nativeDiffDescriptor() } : {}),
494
+ executorTimeoutSeconds, executor: executor.describe(), judge: judge?.describe() ?? null,
495
+ ...(options.component ? { component: options.component } : {}),
496
+ ...(baselineTarget ? { baselineTarget: { name: baselineTarget.name, sourceDir: baselineTarget.sourceDir, bundleSha256: baselineTarget.sha256, files: baselineTarget.files } } : {}) }, baselineTarget);
497
+ let manifest;
498
+ try {
499
+ manifest = await runExperiment({
500
+ bench,
501
+ target,
502
+ baselineTarget,
503
+ component: options.component,
504
+ pairOrder,
505
+ ...(spendingBudget ? { spendingBudget } : {}),
506
+ inputMode,
507
+ ...(skillInstallDir ? { skillInstallDir, skillSearchDirs } : {}),
508
+ executor: session.wrap(executor, 'agent'),
509
+ judge: judge ? session.wrap(judge, 'judge') : null,
510
+ session,
511
+ trials,
512
+ runsRoot,
513
+ runGroup,
514
+ log,
515
+ });
516
+ throwIfEvaluationInterrupted();
517
+ }
518
+ catch (error) {
519
+ session.finish(error);
520
+ throw error;
521
+ }
522
+ session.finish(undefined, manifest);
523
+ log(renderSummary(manifest, join(runsRoot, runGroup, 'manifest.json')));
524
+ return manifest;
525
+ });
454
526
  }
@@ -0,0 +1,5 @@
1
+ import { reportEvalComponent } from './eval-component.js';
2
+ /** One read-only dispatcher for the public Markdown and JSON report entry points. */
3
+ export async function readEvaluationReport(path, options = {}) {
4
+ return reportEvalComponent(path, options);
5
+ }