skillfit 0.10.1 → 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 (87) hide show
  1. package/README.md +18 -6
  2. package/README.zh-CN.md +18 -6
  3. package/benches/README.md +2 -2
  4. package/dist/cli.js +132 -28
  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 +63 -143
  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 +52 -28
  14. package/dist/commands/eval-export-modes.test.js +350 -0
  15. package/dist/commands/eval-export.js +12 -4
  16. package/dist/commands/eval-plan.js +37 -0
  17. package/dist/commands/eval-preflight.test.js +144 -1
  18. package/dist/commands/eval-report.js +18 -3
  19. package/dist/commands/eval-single-arm-replay.js +21 -0
  20. package/dist/commands/eval-single-arm-report.js +223 -0
  21. package/dist/commands/eval.js +106 -56
  22. package/dist/commands/evaluation-report.js +5 -0
  23. package/dist/commands/evaluation-report.test.js +243 -0
  24. package/dist/commands/replay-cancellation.test.js +105 -0
  25. package/dist/commands/workflow-entrypoints.test.js +137 -0
  26. package/dist/harness/agent-preflight.js +180 -0
  27. package/dist/harness/bench.js +2 -1
  28. package/dist/harness/command.js +49 -0
  29. package/dist/harness/eval-audit.js +161 -16
  30. package/dist/harness/eval-budget.js +46 -2
  31. package/dist/harness/eval-budget.test.js +26 -1
  32. package/dist/harness/eval-component.test.js +163 -0
  33. package/dist/harness/eval-contract.js +11 -5
  34. package/dist/harness/executors/api.js +4 -3
  35. package/dist/harness/executors/api.test.js +18 -0
  36. package/dist/harness/experiment-session.js +18 -10
  37. package/dist/harness/experiment-session.test.js +8 -0
  38. package/dist/harness/invocation-costs.js +72 -0
  39. package/dist/harness/judge-accounting.test.js +216 -0
  40. package/dist/harness/judge-audit.js +56 -0
  41. package/dist/harness/judge.js +86 -21
  42. package/dist/harness/replay-package.js +71 -5
  43. package/dist/harness/runner.js +40 -30
  44. package/dist/harness/runner.test.js +23 -0
  45. package/dist/harness/single-arm-audit.js +436 -0
  46. package/dist/harness/trigger.js +21 -3
  47. package/dist/harness/trigger.test.js +12 -0
  48. package/dist/harness/verifier-error.js +65 -0
  49. package/dist/harness/verifier.test.js +128 -0
  50. package/docs/bench-authoring.md +34 -9
  51. package/docs/bench-check-json.md +28 -5
  52. package/docs/eval-agent-preflight.md +101 -0
  53. package/docs/eval-case-preflight.md +5 -0
  54. package/docs/eval-component.md +38 -10
  55. package/docs/eval-costs.md +44 -0
  56. package/docs/eval-planning.md +153 -0
  57. package/docs/evaluation-input-snapshots.md +2 -1
  58. package/docs/evaluation-interruption.md +22 -10
  59. package/docs/evaluation-reports.md +97 -3
  60. package/docs/experiment-workflow.md +7 -0
  61. package/docs/first-real-eval.md +50 -3
  62. package/docs/growth-roadmap-2026-10.md +41 -9
  63. package/docs/metrics.md +40 -3
  64. package/docs/plans/2026-10-17-workflow-foundations.md +64 -0
  65. package/docs/releases/0.10.1-ci-registry-install.json +70 -0
  66. package/docs/releases/0.10.1-feature-smoke.json +28 -0
  67. package/docs/releases/0.10.1-local-registry-install.json +60 -0
  68. package/docs/releases/0.10.1-registry-metadata.json +33 -0
  69. package/docs/releases/0.10.1-signatures.txt +7 -0
  70. package/docs/releases/0.10.1-verification.json +90 -0
  71. package/docs/releases/0.10.1.md +37 -4
  72. package/docs/releases/0.11.0-feature-smoke.mjs +224 -0
  73. package/docs/releases/0.11.0.md +47 -0
  74. package/docs/replay-packages.md +38 -6
  75. package/docs/schemas/agent-preflight.schema.json +31 -0
  76. package/docs/schemas/calibration-plan.schema.json +22 -0
  77. package/docs/schemas/calibration-result.schema.json +17 -0
  78. package/docs/schemas/eval-request.schema.json +1 -1
  79. package/docs/schemas/eval-result.schema.json +3 -1
  80. package/docs/schemas/invocation-costs.schema.json +31 -0
  81. package/docs/schemas/judge-call.schema.json +22 -0
  82. package/docs/schemas/single-arm-report.schema.json +20 -0
  83. package/docs/schemas/verifier-error.schema.json +11 -0
  84. package/docs/sharing-results.md +3 -0
  85. package/docs/verifier-contract.md +99 -0
  86. package/package.json +1 -1
  87. package/skills/skillfit/SKILL.md +41 -8
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import { spawn } from 'node:child_process';
2
3
  import { lstatSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
3
4
  import { isAbsolute, join, relative, resolve, sep } from 'node:path';
4
5
  export function packageFiles(root, prefix = '') {
@@ -56,30 +57,95 @@ export function verifyReplayPackage(root) {
56
57
  }
57
58
  if (metadata.hasManifest !== ('run/manifest.json' in metadata.files))
58
59
  throw new Error('Portable manifest coverage changed.');
60
+ if (metadata.evaluationType !== undefined) {
61
+ if (!['paired', 'calibration', 'trigger'].includes(metadata.evaluationType))
62
+ throw new Error('Invalid portable evaluation type.');
63
+ const plan = JSON.parse(readFileSync(packageMember(root, 'run/_plan.json'), 'utf8'));
64
+ const plannedType = ['calibration', 'trigger'].includes(plan.details?.mode) ? plan.details.mode : 'paired';
65
+ if (metadata.evaluationType !== plannedType)
66
+ throw new Error('Portable evaluation type differs from its native plan.');
67
+ }
59
68
  return metadata;
60
69
  }
70
+ /** Wait for the pinned CLI to clean its verifier tree before returning a signal exit. */
71
+ function runPinnedReplay(root, interrupted) {
72
+ return new Promise((resolveRun, reject) => {
73
+ // The original cancellation context also covers older pinned CLIs whose
74
+ // report dispatcher predates the public replay wrapper. The CLI stays byte-identical.
75
+ const loader = "import{dirname,join}from'node:path';import{pathToFileURL}from'node:url';process.on('message',message=>{if(message?.kind==='skillfit.replay-signal'&&['SIGINT','SIGTERM'].includes(message.signal))process.emit(message.signal);});process.channel?.unref();const cli=process.argv[1];const{withEvaluationInterrupts}=await import(pathToFileURL(join(dirname(cli),'harness/interruption.js')).href);await withEvaluationInterrupts(async()=>{const idle=new Promise(resolve=>process.once('beforeExit',resolve));await import(pathToFileURL(cli).href);await idle;});";
76
+ const child = spawn(process.execPath, ['--input-type=module', '--eval', loader, join(root, 'runtime/dist/cli.js'), 'report', 'eval', join(root, 'run'), '--json', '--replay', '--bench', join(root, 'inputs/bench')], { cwd: root, stdio: ['ignore', 'pipe', 'pipe', 'ipc'], windowsHide: true });
77
+ let stdout = '', stderr = '', bytes = 0, failure = null, signal = null;
78
+ const stopChild = (value) => {
79
+ if (process.platform === 'win32' && child.connected)
80
+ child.send({ kind: 'skillfit.replay-signal', signal: value });
81
+ else
82
+ child.kill(value);
83
+ };
84
+ const forward = (value) => {
85
+ if (signal)
86
+ return;
87
+ signal = value;
88
+ interrupted(value);
89
+ stopChild(value);
90
+ };
91
+ const onInt = () => forward('SIGINT'), onTerm = () => forward('SIGTERM');
92
+ process.on('SIGINT', onInt);
93
+ process.on('SIGTERM', onTerm);
94
+ const cleanup = () => { process.removeListener('SIGINT', onInt); process.removeListener('SIGTERM', onTerm); };
95
+ const append = (value, error) => {
96
+ bytes += Buffer.byteLength(value);
97
+ if (bytes > 32 * 1024 * 1024) {
98
+ if (!failure) {
99
+ failure = new Error('Pinned replay output exceeded 32 MiB.');
100
+ stopChild('SIGTERM');
101
+ }
102
+ return;
103
+ }
104
+ if (error)
105
+ stderr += value;
106
+ else
107
+ stdout += value;
108
+ };
109
+ child.stdout.setEncoding('utf8');
110
+ child.stderr.setEncoding('utf8');
111
+ child.stdout.on('data', value => append(String(value), false));
112
+ child.stderr.on('data', value => append(String(value), true));
113
+ child.once('error', error => { failure = error; });
114
+ child.once('close', status => {
115
+ cleanup();
116
+ if (signal)
117
+ reject(new Error(`Offline replay interrupted by ${signal}; waited for the pinned CLI to stop its verifier processes.`));
118
+ else if (failure)
119
+ reject(failure);
120
+ else
121
+ resolveRun({ stdout, stderr, status });
122
+ });
123
+ });
124
+ }
61
125
  /** Serialize these dependency-free functions so old pinned runtimes need no new export API. */
62
126
  export function portableReproducer() {
63
127
  return `import {createHash} from 'node:crypto';
64
128
  import {lstatSync,readFileSync,readdirSync,realpathSync} from 'node:fs';
65
129
  import {isAbsolute,join,relative,resolve,sep} from 'node:path';
66
130
  import {fileURLToPath} from 'node:url';
67
- import {spawnSync} from 'node:child_process';
131
+ import {spawn} from 'node:child_process';
68
132
  ${packageFiles.toString()}
69
133
  ${packageMember.toString()}
70
134
  ${packageHash.toString()}
71
135
  ${verifyReplayPackage.toString()}
136
+ ${runPinnedReplay.toString()}
137
+ let interruptedSignal=null;
72
138
  try {
73
139
  const root=fileURLToPath(new URL('.',import.meta.url)), metadata=verifyReplayPackage(root);
74
140
  if(process.argv.includes('--verify-only')) {
75
141
  console.log(JSON.stringify({schemaVersion:1,kind:'skillfit.replay-package-verification',verified:true,files:Object.keys(metadata.files).length,nativeStatus:metadata.nativeStatus,modelCalls:0}));
76
142
  } else {
77
- const child=spawnSync(process.execPath,[join(root,'runtime/dist/cli.js'),'report','eval',join(root,'run'),'--json','--replay','--bench',join(root,'inputs/bench')],{cwd:root,encoding:'utf8',maxBuffer:32*1024*1024});
78
- if(child.error||child.status!==0) throw new Error(child.error?.message||child.stderr||'Pinned offline replay failed.');
143
+ const child=await runPinnedReplay(root,signal=>{interruptedSignal=signal;});
144
+ if(child.status!==0) throw new Error(child.stderr||'Pinned offline replay failed.');
79
145
  const result=JSON.parse(child.stdout);
80
- if(metadata.hasManifest&&!result.evidence?.verified) throw new Error('Offline evidence audit failed: '+JSON.stringify(result.evidence));
146
+ if((metadata.hasManifest||metadata.evaluationType==='calibration'||metadata.evaluationType==='trigger')&&!result.evidence?.verified) throw new Error('Offline evidence audit failed: '+JSON.stringify(result.evidence));
81
147
  console.log(JSON.stringify({...result,portableReplay:{verified:true,sourcePlanSha256:metadata.sourcePlanSha256,modelCalls:0,scope:'Offline evidence reproduction; no new observations or upgrade authorization.'}},null,2));
82
148
  }
83
- } catch(error) { console.error(error.message); process.exitCode=2; }
149
+ } catch(error) { console.error(error.message); process.exitCode=interruptedSignal==='SIGINT'?130:interruptedSignal==='SIGTERM'?143:2; }
84
150
  `;
85
151
  }
@@ -1,10 +1,10 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { appendFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { dirname, join, resolve } from 'node:path';
4
4
  import { MOCK_MARKER_FILE, RUN_GROUP_PATTERN } from './constants.js';
5
5
  import { assertInstalledSkillFixtures, assertSkillRevisionTargets, installSkillResources, installedSkillDestination } from './installed-skill.js';
6
6
  import { collectInstalledSkillFingerprint } from './bundle.js';
7
- import { judgePair } from './judge.js';
7
+ import { JudgePairFailure, judgePair } from './judge.js';
8
8
  import { killTree, treeSpawnOptions } from './kill-tree.js';
9
9
  import { evaluationSignal, throwIfEvaluationInterrupted } from './interruption.js';
10
10
  import { assertInputModeSupported, buildTaskPrompt, snapshotRepoFiles } from './prompt.js';
@@ -18,7 +18,10 @@ import { ExecutorFailure } from './types.js';
18
18
  import { summarizeCosts } from './costs.js';
19
19
  import { executionClock } from './execution-timing.js';
20
20
  import { verdictFromOutput } from './verifier-summary.js';
21
- import { assertSpendingCanContinue, parseSpendingBudget, spendingBudgetState } from './eval-budget.js';
21
+ import { createSpendingBudgetRecorder, parseSpendingBudget } from './eval-budget.js';
22
+ import { summarizeInvocationCosts } from './invocation-costs.js';
23
+ import { parseCommand } from './command.js';
24
+ import { verifierRuntimeError } from './verifier-error.js';
22
25
  function applyOverlay(overlayDir, runDir) {
23
26
  for (const rel of listFilesRecursive(overlayDir)) {
24
27
  const destination = join(runDir, rel);
@@ -265,7 +268,7 @@ export async function runTrial(plan, taskId, condition, trial) {
265
268
  const verifier = await runVerifier(bench.dir, task.verifier, runDir);
266
269
  verifierExitCode = verifier.exitCode;
267
270
  writeFileSync(join(runDir, '_verifier.txt'), verifierLogFor(verifier), 'utf8');
268
- if (verifier.exitCode === null) {
271
+ if (verifier.error !== null || verifier.exitCode === null) {
269
272
  error = verifierFailure('verifier', task.verifier, verifier.error);
270
273
  }
271
274
  else {
@@ -322,12 +325,15 @@ export async function runTrial(plan, taskId, condition, trial) {
322
325
  return record;
323
326
  }
324
327
  export async function runVerifier(benchDir, command, runDir) {
325
- const tokens = command.split(/\s+/).filter(Boolean);
326
- const executable = tokens[0];
327
- if (!executable) {
328
- return { exitCode: null, output: '', error: 'empty verifier command' };
328
+ let tokens;
329
+ try {
330
+ tokens = parseCommand(command);
331
+ }
332
+ catch (error) {
333
+ return { exitCode: null, output: '', error: `VERIFIER_COMMAND_ERROR: ${error.message}` };
329
334
  }
330
- return runProcess(executable, [...tokens.slice(1), runDir], benchDir, VERIFIER_TIMEOUT_MS);
335
+ const result = await runProcess(tokens[0], [...tokens.slice(1), runDir], benchDir, VERIFIER_TIMEOUT_MS);
336
+ return { ...result, error: result.error ?? verifierRuntimeError(result.output, result.exitCode, benchDir, runDir) };
331
337
  }
332
338
  export function verifierLogFor(result) {
333
339
  return result.error ? `${result.output}\n[${result.error}]` : result.output;
@@ -340,6 +346,8 @@ const SPAWN_FAILURE = /ENOENT|EINVAL|EACCES|EPERM/i;
340
346
  */
341
347
  export function verifierFailure(label, command, reason) {
342
348
  const why = reason ?? 'no exit code';
349
+ if (why.startsWith('VERIFIER_'))
350
+ return `${label} failed (${why}): ${command}`;
343
351
  if (SPAWN_FAILURE.test(why)) {
344
352
  return `${label} could not be started (${why}): ${command} — it is spawned without a shell, so the first token must be an executable the OS can start directly ("node verifiers/x.mjs"); to grade with a shell command, wrap it via "bench add --freeze --verifier-cmd"`;
345
353
  }
@@ -363,7 +371,7 @@ function sumTokens(records) {
363
371
  * knob reports `sampling: null`, which is a statement about the surface — not an omission that a
364
372
  * reader would have to guess at.
365
373
  */
366
- function withSampling(descriptor) {
374
+ export function withSampling(descriptor) {
367
375
  return { ...descriptor, sampling: descriptor.sampling ?? null };
368
376
  }
369
377
  function countErrors(records) {
@@ -430,7 +438,7 @@ function tokenDelta(baseline, treatment) {
430
438
  return null;
431
439
  return { input: treatment.input - baseline.input, output: treatment.output - baseline.output };
432
440
  }
433
- function summarizeJudge(judgeResults) {
441
+ export function summarizeJudge(judgeResults) {
434
442
  if (judgeResults.length === 0)
435
443
  return null;
436
444
  const consistent = judgeResults.filter((r) => r.consistent);
@@ -447,7 +455,7 @@ function summarizeJudge(judgeResults) {
447
455
  treatmentMean: mean(consistent.map((r) => r.treatmentScore)),
448
456
  };
449
457
  }
450
- async function judgeTaskTrials(plan, taskId, outcomes) {
458
+ async function judgeTaskTrials(plan, taskId, outcomes, allJudgeCalls, budget) {
451
459
  const judge = plan.judge;
452
460
  if (!judge)
453
461
  return [];
@@ -473,13 +481,27 @@ async function judgeTaskTrials(plan, taskId, outcomes) {
473
481
  baselineOutput: baseline.output,
474
482
  treatmentOutput: treatment.output,
475
483
  seed,
484
+ taskId: task.id,
485
+ trial,
486
+ clock: plan.clock,
487
+ beforeCall: callIndex => budget.before({ role: 'judge', taskId: task.id, trial, callIndex }),
488
+ onCall: receipt => {
489
+ const path = join(taskDir, `judge-trial-${trial}`);
490
+ mkdirSync(path, { recursive: true });
491
+ writeFileSync(join(path, `call-${receipt.callIndex}.json`), JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
492
+ allJudgeCalls.push(receipt);
493
+ budget.after({ role: 'judge', taskId: task.id, trial, callIndex: receipt.callIndex }, receipt);
494
+ },
476
495
  });
477
496
  results.push(result);
478
497
  writeFileSync(join(taskDir, `judge-trial-${trial}.json`), `${JSON.stringify({ trial, seed, ...result }, null, 2)}\n`, 'utf8');
479
498
  }
480
499
  catch (error) {
500
+ writeFileSync(join(taskDir, `judge-trial-${trial}-error.json`), JSON.stringify({ schemaVersion: 1, trial, seed,
501
+ error: error.message, calls: error instanceof JudgePairFailure ? error.calls : [], automaticRetry: false }, null, 2) + '\n', { flag: 'wx' });
481
502
  throwIfEvaluationInterrupted();
482
503
  plan.log?.(`Judge failed for ${task.id} trial ${trial}: ${error.message}`);
504
+ throw error;
483
505
  }
484
506
  }
485
507
  return results;
@@ -603,8 +625,6 @@ function summarizeTask(taskId, outcomes, survivors, judgeResults, readObservatio
603
625
  }
604
626
  export async function runExperiment(plan) {
605
627
  const budget = plan.spendingBudget === undefined ? undefined : parseSpendingBudget(plan.spendingBudget);
606
- if (budget && plan.judge)
607
- throw new Error('spendingBudget does not cover judge calls.');
608
628
  assertInputModeSupported(plan.inputMode ?? 'snapshot', plan.executor);
609
629
  const pairOrder = plan.pairOrder ?? 'baseline-first';
610
630
  if (pairOrder !== 'baseline-first' && pairOrder !== 'balanced')
@@ -639,14 +659,8 @@ export async function runExperiment(plan) {
639
659
  const taskSummaries = [];
640
660
  const allOutcomes = { baseline: [], treatment: [] };
641
661
  const allSurvivors = { baseline: [], treatment: [] };
642
- const budgetObservations = [];
643
- const budgetEvent = (phase, taskId, condition, trial) => {
644
- if (!budget)
645
- return null;
646
- const state = spendingBudgetState(budget, budgetObservations);
647
- appendFileSync(join(groupDir, '_budget.jsonl'), JSON.stringify({ phase, taskId, condition, trial, state }) + '\n', 'utf8');
648
- return state;
649
- };
662
+ const budgetRecorder = createSpendingBudgetRecorder({ budget, groupDir });
663
+ const allJudgeCalls = [];
650
664
  for (const [taskIndex, task] of plan.bench.tasks.entries()) {
651
665
  const outcomes = { baseline: [], treatment: [] };
652
666
  // Interleaved: the trial loop is outermost so the two arms of a pair run adjacently. Running
@@ -655,26 +669,21 @@ export async function runExperiment(plan) {
655
669
  for (let trial = 1; trial <= plan.trials; trial++) {
656
670
  for (const condition of pairConditions(pairOrder, taskIndex, trial)) {
657
671
  throwIfEvaluationInterrupted();
658
- const before = budgetEvent('before-call', task.id, condition, trial);
659
- if (before)
660
- assertSpendingCanContinue(before);
672
+ budgetRecorder.before({ taskId: task.id, condition, trial });
661
673
  plan.log?.(`Running ${task.id} / ${condition} / trial ${trial}…`);
662
674
  const outcome = await runTrial(plan, task.id, condition, trial);
663
675
  outcomes[condition].push(outcome);
664
676
  allOutcomes[condition].push(outcome);
665
- budgetObservations.push(outcome);
666
- const after = budgetEvent('after-call', task.id, condition, trial);
677
+ budgetRecorder.after({ taskId: task.id, condition, trial }, outcome);
667
678
  throwIfEvaluationInterrupted();
668
679
  // A reached line prevents the next call; incomplete or failed evidence stops even
669
680
  // after the final scheduled call. One in-flight invocation may cross a stop line.
670
- if (after && (after.incomplete.length || after.reason === 'EXECUTION_FAILED'))
671
- assertSpendingCanContinue(after);
672
681
  }
673
682
  }
674
683
  const survivors = pairedSurvivors(outcomes);
675
684
  allSurvivors.baseline.push(...survivors.baseline);
676
685
  allSurvivors.treatment.push(...survivors.treatment);
677
- const judgeResults = await judgeTaskTrials(plan, task.id, outcomes);
686
+ const judgeResults = await judgeTaskTrials(plan, task.id, outcomes, allJudgeCalls, budgetRecorder);
678
687
  taskSummaries.push(summarizeTask(task.id, outcomes, survivors, judgeResults, !!plan.skillInstallDir));
679
688
  }
680
689
  const overallBaseline = statsFor(allSurvivors.baseline, countErrors(allOutcomes.baseline), !!plan.skillInstallDir);
@@ -692,6 +701,7 @@ export async function runExperiment(plan) {
692
701
  plan.session?.settle();
693
702
  const manifestWithoutWarnings = {
694
703
  schemaVersion: 4,
704
+ invocationCosts: summarizeInvocationCosts([...allOutcomes.baseline, ...allOutcomes.treatment], allJudgeCalls, !!plan.judge),
695
705
  ...(plan.component ? { component: plan.component } : {}),
696
706
  ...(plan.session ? { experiment: plan.session.summary() } : {}),
697
707
  inputMode: plan.inputMode ?? 'snapshot',
@@ -513,6 +513,29 @@ test('runExperiment excludes a trial whose verifier could not be spawned', async
513
513
  assert.match(result.error ?? '', /verifier could not be started/);
514
514
  assert.match(result.error ?? '', /spawned without a shell/);
515
515
  });
516
+ test('a grader exception excludes its pair while normal graded failures and all invocation costs survive', async (t) => {
517
+ const root = tmp(t, 'skillfit-grader-errors-');
518
+ mkdirSync(join(root, 'fixture'));
519
+ writeFileSync(join(root, 'fixture/input.txt'), 'input');
520
+ writeFileSync(join(root, 'prompt.md'), 'Return an answer.');
521
+ writeFileSync(join(root, 'verifier.mjs'), "import{readFileSync}from'node:fs';import{join}from'node:path';const text=readFileSync(join(process.argv[2],'_output.md'),'utf8');if(text==='crash')throw new Error('grader unavailable');console.log(JSON.stringify({passed:false}));process.exit(1);");
522
+ writeFileSync(join(root, 'bench.json'), JSON.stringify({ schemaVersion: 1, tasks: [{ id: 't', fixture: 'fixture', prompt: 'prompt.md', verifier: 'node verifier.mjs' }] }));
523
+ let calls = 0;
524
+ const executor = { describe: () => ({ kind: 'mock', model: 'offline-grader-pairs' }), run: async () => ({ output: ++calls === 1 ? 'crash' : 'normal failure', tokens: { input: 10, cachedInput: 4, output: 2 } }) };
525
+ const manifest = await runExperiment({ bench: loadBench(root), target: collectSkillBundle(makeSkill(t)), executor,
526
+ trials: 2, runsRoot: join(root, 'runs'), runGroup: 'grade' });
527
+ const task = manifest.tasks[0];
528
+ assert.equal(calls, 4);
529
+ assert.equal(task.conditions.baseline.errors, 1);
530
+ assert.equal(task.conditions.treatment.errors, 0);
531
+ assert.deepEqual(task.outcomes, { baseline: [false], treatment: [false] });
532
+ assert.equal(manifest.overall.costs.attempts.baseline.metrics.input.knownTotal, 20);
533
+ assert.equal(manifest.overall.costs.attempts.treatment.metrics.input.knownTotal, 20);
534
+ assert.equal(manifest.overall.costs.paired.baseline.metrics.input.knownTotal, 10);
535
+ const receipt = JSON.parse(readFileSync(join(root, 'runs/grade/t/baseline/trial-1/_result.json'), 'utf8'));
536
+ assert.equal(receipt.verifierExitCode, 1);
537
+ assert.match(receipt.error, /VERIFIER_RUNTIME_ERROR/);
538
+ });
516
539
  test('runExperiment interleaves conditions within each trial and records sampling', async (t) => {
517
540
  const runsRoot = tmp(t, 'skillfit-runs-order-');
518
541
  const inner = new MockExecutor();