skillfit 0.10.1 → 0.12.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.
- package/README.md +43 -8
- package/README.zh-CN.md +43 -8
- package/benches/README.md +6 -2
- package/dist/cli.js +153 -37
- package/dist/cli.test.js +94 -0
- package/dist/commands/bench-calibration.js +201 -0
- package/dist/commands/bench-calibration.test.js +237 -0
- package/dist/commands/bench-check-json.test.js +24 -3
- package/dist/commands/bench-draft.js +167 -0
- package/dist/commands/bench-draft.test.js +168 -0
- package/dist/commands/bench-manage.js +5 -4
- package/dist/commands/bench-source.js +101 -0
- package/dist/commands/bench-source.test.js +84 -0
- package/dist/commands/bench.js +227 -245
- package/dist/commands/bench.test.js +7 -3
- package/dist/commands/calibration-cli.test.js +145 -0
- package/dist/commands/eval-agent-preflight.test.js +269 -0
- package/dist/commands/eval-api-failure.test.js +46 -0
- package/dist/commands/eval-cli-usage.test.js +75 -0
- package/dist/commands/eval-cli.js +31 -0
- package/dist/commands/eval-component.js +52 -28
- package/dist/commands/eval-export-modes.test.js +350 -0
- package/dist/commands/eval-export.js +12 -4
- package/dist/commands/eval-interruption.test.js +26 -1
- package/dist/commands/eval-layout.test.js +126 -0
- package/dist/commands/eval-plan.js +37 -0
- package/dist/commands/eval-preflight.test.js +144 -1
- package/dist/commands/eval-report.js +18 -3
- package/dist/commands/eval-single-arm-replay.js +21 -0
- package/dist/commands/eval-single-arm-report.js +223 -0
- package/dist/commands/eval.js +113 -88
- package/dist/commands/evaluation-report.js +5 -0
- package/dist/commands/evaluation-report.test.js +243 -0
- package/dist/commands/npm-first-run.test.js +74 -0
- package/dist/commands/replay-cancellation.test.js +105 -0
- package/dist/commands/workflow-entrypoints.test.js +137 -0
- package/dist/harness/agent-preflight.js +196 -0
- package/dist/harness/bench-location.js +29 -0
- package/dist/harness/bench-location.test.js +33 -0
- package/dist/harness/bench.js +10 -4
- package/dist/harness/command.js +49 -0
- package/dist/harness/eval-audit.js +162 -17
- package/dist/harness/eval-budget.js +46 -2
- package/dist/harness/eval-budget.test.js +26 -1
- package/dist/harness/eval-component.test.js +163 -0
- package/dist/harness/eval-contract.js +11 -5
- package/dist/harness/evaluation-layout.js +30 -0
- package/dist/harness/executors/api.js +24 -10
- package/dist/harness/executors/api.test.js +57 -0
- package/dist/harness/executors/cli.js +15 -25
- package/dist/harness/executors/cli.test.js +33 -2
- package/dist/harness/experiment-session.js +23 -25
- package/dist/harness/experiment-session.test.js +8 -0
- package/dist/harness/hash.js +3 -1
- package/dist/harness/invocation-costs.js +72 -0
- package/dist/harness/judge-accounting.test.js +216 -0
- package/dist/harness/judge-audit.js +56 -0
- package/dist/harness/judge.js +86 -21
- package/dist/harness/replay-package.js +71 -5
- package/dist/harness/runner.js +44 -33
- package/dist/harness/runner.test.js +23 -0
- package/dist/harness/single-arm-audit.js +436 -0
- package/dist/harness/trigger.js +22 -4
- package/dist/harness/trigger.test.js +12 -0
- package/dist/harness/verifier-error.js +65 -0
- package/dist/harness/verifier-timeout.js +8 -0
- package/dist/harness/verifier-timeout.test.js +76 -0
- package/dist/harness/verifier.test.js +128 -0
- package/docs/bench-authoring.md +57 -12
- package/docs/bench-check-json.md +28 -5
- package/docs/bench-drafting.md +75 -0
- package/docs/case-management.md +12 -1
- package/docs/eval-agent-preflight.md +114 -0
- package/docs/eval-case-preflight.md +5 -0
- package/docs/eval-component.md +38 -10
- package/docs/eval-costs.md +70 -0
- package/docs/eval-planning.md +167 -0
- package/docs/evaluation-input-snapshots.md +22 -5
- package/docs/evaluation-interruption.md +22 -10
- package/docs/evaluation-reports.md +97 -3
- package/docs/experiment-workflow.md +7 -0
- package/docs/first-real-eval.md +75 -3
- package/docs/growth-roadmap-2026-10.md +51 -10
- package/docs/metrics.md +40 -3
- package/docs/plans/2026-10-17-workflow-foundations.md +99 -0
- package/docs/releases/0.10.1-ci-registry-install.json +70 -0
- package/docs/releases/0.10.1-feature-smoke.json +28 -0
- package/docs/releases/0.10.1-local-registry-install.json +60 -0
- package/docs/releases/0.10.1-registry-metadata.json +33 -0
- package/docs/releases/0.10.1-signatures.txt +7 -0
- package/docs/releases/0.10.1-verification.json +90 -0
- package/docs/releases/0.10.1.md +37 -4
- package/docs/releases/0.11.0-ci-registry-install.json +130 -0
- package/docs/releases/0.11.0-feature-smoke.json +1576 -0
- package/docs/releases/0.11.0-feature-smoke.mjs +224 -0
- package/docs/releases/0.11.0-local-attempt-1.json +24 -0
- package/docs/releases/0.11.0-local-attempt-1.log +19 -0
- package/docs/releases/0.11.0-local-registry-install.json +25 -0
- package/docs/releases/0.11.0-registry-metadata.json +33 -0
- package/docs/releases/0.11.0-signatures.txt +12 -0
- package/docs/releases/0.11.0-verification.json +95 -0
- package/docs/releases/0.11.0.md +90 -0
- package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
- package/docs/releases/0.12.0.md +68 -0
- package/docs/replay-packages.md +38 -6
- package/docs/schemas/agent-preflight.schema.json +31 -0
- package/docs/schemas/calibration-plan.schema.json +22 -0
- package/docs/schemas/calibration-result.schema.json +17 -0
- package/docs/schemas/eval-request.schema.json +1 -1
- package/docs/schemas/eval-result.schema.json +3 -1
- package/docs/schemas/invocation-costs.schema.json +31 -0
- package/docs/schemas/judge-call.schema.json +22 -0
- package/docs/schemas/single-arm-report.schema.json +20 -0
- package/docs/schemas/verifier-error.schema.json +11 -0
- package/docs/sharing-results.md +3 -0
- package/docs/verifier-contract.md +108 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +61 -8
package/dist/harness/judge.js
CHANGED
|
@@ -2,6 +2,17 @@ import { createHash, randomBytes } from 'node:crypto';
|
|
|
2
2
|
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { ExecutorFailure } from './types.js';
|
|
6
|
+
import { executionClock } from './execution-timing.js';
|
|
7
|
+
import { throwIfEvaluationInterrupted } from './interruption.js';
|
|
8
|
+
export class JudgePairFailure extends Error {
|
|
9
|
+
calls;
|
|
10
|
+
constructor(message, calls, cause) {
|
|
11
|
+
super(message, { cause });
|
|
12
|
+
this.calls = calls;
|
|
13
|
+
this.name = 'JudgePairFailure';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
5
16
|
export function judgeOrder(seed) {
|
|
6
17
|
const digest = createHash('sha256').update(seed, 'utf8').digest();
|
|
7
18
|
const first = (digest[0] ?? 0) % 2 === 0 ? 'baseline' : 'treatment';
|
|
@@ -63,7 +74,7 @@ function parseChecklist(raw, label) {
|
|
|
63
74
|
}
|
|
64
75
|
return score;
|
|
65
76
|
}
|
|
66
|
-
function
|
|
77
|
+
export function parseJudgeScores(raw) {
|
|
67
78
|
return { a: parseChecklist(raw, 'A'), b: parseChecklist(raw, 'B') };
|
|
68
79
|
}
|
|
69
80
|
export async function judgePair(judge, args) {
|
|
@@ -72,26 +83,79 @@ export async function judgePair(judge, args) {
|
|
|
72
83
|
// the task directory would expose both arms' _output.md and their _result.json — which names the
|
|
73
84
|
// condition and the evaluation-target hash — and the AB/BA swap would be blindfolding a judge that can
|
|
74
85
|
// just look. It gets a fresh directory holding only the two positionally-anonymized answers.
|
|
75
|
-
const
|
|
86
|
+
const calls = [];
|
|
87
|
+
const clock = args.clock ?? executionClock;
|
|
76
88
|
try {
|
|
77
|
-
const call = async (firstCondition) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const call = async (firstCondition, callIndex) => {
|
|
90
|
+
throwIfEvaluationInterrupted();
|
|
91
|
+
args.beforeCall?.(callIndex);
|
|
92
|
+
const judgeDir = mkdtempSync(join(tmpdir(), 'skillfit-judge-'));
|
|
93
|
+
try {
|
|
94
|
+
const answerA = firstCondition === 'baseline' ? args.baselineOutput : args.treatmentOutput;
|
|
95
|
+
const answerB = firstCondition === 'baseline' ? args.treatmentOutput : args.baselineOutput;
|
|
96
|
+
writeFileSync(join(judgeDir, 'answerA.md'), answerA, 'utf8');
|
|
97
|
+
writeFileSync(join(judgeDir, 'answerB.md'), answerB, 'utf8');
|
|
98
|
+
const prompt = buildJudgePrompt(args.taskPromptText, args.rubricText ?? null, answerA, answerB);
|
|
99
|
+
const startedWall = clock.wallNow(), startedMono = clock.monotonicNow();
|
|
100
|
+
let output = '', rawOutput = null, tokens = null;
|
|
101
|
+
let usageStatus = 'unknown', execution = null;
|
|
102
|
+
let executorInvoked = true, error = null, scores = null;
|
|
103
|
+
let usageEvidence;
|
|
104
|
+
try {
|
|
105
|
+
const result = await judge.run(prompt, judgeDir);
|
|
106
|
+
output = result.output;
|
|
107
|
+
rawOutput = result.rawOutput ?? null;
|
|
108
|
+
tokens = result.tokens ?? null;
|
|
109
|
+
usageStatus = result.usageStatus ?? (tokens ? 'final' : 'unknown');
|
|
110
|
+
execution = result.executionTiming ?? null;
|
|
111
|
+
usageEvidence = result.usageEvidence;
|
|
112
|
+
if (result.guardError)
|
|
113
|
+
throw new Error(result.guardError);
|
|
114
|
+
}
|
|
115
|
+
catch (failure) {
|
|
116
|
+
error = failure.message;
|
|
117
|
+
if (failure instanceof ExecutorFailure) {
|
|
118
|
+
executorInvoked = failure.executorInvoked;
|
|
119
|
+
output = failure.result.output;
|
|
120
|
+
rawOutput = failure.result.rawOutput ?? null;
|
|
121
|
+
tokens = failure.result.tokens ?? null;
|
|
122
|
+
usageStatus = failure.result.usageStatus ?? (tokens ? 'partial' : 'unknown');
|
|
123
|
+
execution = failure.result.executionTiming ?? null;
|
|
124
|
+
usageEvidence = failure.result.usageEvidence;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const finishedWall = clock.wallNow(), durationSeconds = Math.round(clock.monotonicNow() - startedMono) / 1000;
|
|
128
|
+
if (!error) {
|
|
129
|
+
try {
|
|
130
|
+
const parsed = parseJudgeScores(output);
|
|
131
|
+
scores = { baseline: firstCondition === 'baseline' ? parsed.a : parsed.b,
|
|
132
|
+
treatment: firstCondition === 'baseline' ? parsed.b : parsed.a };
|
|
133
|
+
}
|
|
134
|
+
catch (failure) {
|
|
135
|
+
error = failure.message;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const receipt = { schemaVersion: 1, kind: 'skillfit.judge-call',
|
|
139
|
+
taskId: args.taskId ?? 'standalone', trial: args.trial ?? 1, callIndex, seed: args.seed, firstCondition,
|
|
140
|
+
prompt, promptSha256: createHash('sha256').update(prompt).digest('hex'), output, rawOutput,
|
|
141
|
+
executor: { ...judge.describe(), sampling: judge.describe().sampling ?? null },
|
|
142
|
+
startedAt: new Date(startedWall).toISOString(), finishedAt: new Date(finishedWall).toISOString(), durationSeconds,
|
|
143
|
+
timing: { clock: 'performance.now', wallDurationSeconds: (finishedWall - startedWall) / 1000, execution },
|
|
144
|
+
executorInvoked, error, passed: error === null, tokens, usageStatus, ...(usageEvidence ? { usageEvidence } : {}), scores };
|
|
145
|
+
calls.push(receipt);
|
|
146
|
+
// Persist before propagating a parse/execution error, cancellation or budget stop.
|
|
147
|
+
args.onCall?.(receipt);
|
|
148
|
+
throwIfEvaluationInterrupted();
|
|
149
|
+
if (error)
|
|
150
|
+
throw new Error(error);
|
|
151
|
+
return { ...scores, raw: output };
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
rmSync(judgeDir, { recursive: true, force: true });
|
|
155
|
+
}
|
|
92
156
|
};
|
|
93
|
-
const forward = await call(first);
|
|
94
|
-
const reverse = await call(second);
|
|
157
|
+
const forward = await call(first, 1);
|
|
158
|
+
const reverse = await call(second, 2);
|
|
95
159
|
const winner = (scores) => Math.sign(scores.baseline - scores.treatment);
|
|
96
160
|
const consistent = winner(forward) === winner(reverse);
|
|
97
161
|
return {
|
|
@@ -100,9 +164,10 @@ export async function judgePair(judge, args) {
|
|
|
100
164
|
consistent,
|
|
101
165
|
firstCondition: first,
|
|
102
166
|
raw: `${forward.raw}\n--- reverse order ---\n${reverse.raw}`,
|
|
167
|
+
calls,
|
|
103
168
|
};
|
|
104
169
|
}
|
|
105
|
-
|
|
106
|
-
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw new JudgePairFailure(error.message, calls, error);
|
|
107
172
|
}
|
|
108
173
|
}
|
|
@@ -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 {
|
|
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=
|
|
78
|
-
if(child.
|
|
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
|
}
|
package/dist/harness/runner.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import {
|
|
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,11 @@ 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 {
|
|
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';
|
|
25
|
+
import { parseVerifierTimeoutSeconds } from './verifier-timeout.js';
|
|
22
26
|
function applyOverlay(overlayDir, runDir) {
|
|
23
27
|
for (const rel of listFilesRecursive(overlayDir)) {
|
|
24
28
|
const destination = join(runDir, rel);
|
|
@@ -26,7 +30,6 @@ function applyOverlay(overlayDir, runDir) {
|
|
|
26
30
|
cpSync(join(overlayDir, rel), destination);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
const VERIFIER_TIMEOUT_MS = 2 * 60 * 1000;
|
|
30
33
|
const MAX_PROCESS_OUTPUT_BYTES = 8 * 1024 * 1024;
|
|
31
34
|
function runProcess(command, args, cwd, timeoutMs) {
|
|
32
35
|
const signal = evaluationSignal();
|
|
@@ -262,10 +265,10 @@ export async function runTrial(plan, taskId, condition, trial) {
|
|
|
262
265
|
let score = null;
|
|
263
266
|
let checks = null;
|
|
264
267
|
if (error === null) {
|
|
265
|
-
const verifier = await runVerifier(bench.dir, task.verifier, runDir);
|
|
268
|
+
const verifier = await runVerifier(bench.dir, task.verifier, runDir, task.verifierTimeoutSeconds);
|
|
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 {
|
|
@@ -321,13 +324,17 @@ export async function runTrial(plan, taskId, condition, trial) {
|
|
|
321
324
|
}, null, 2)}\n`, 'utf8');
|
|
322
325
|
return record;
|
|
323
326
|
}
|
|
324
|
-
export async function runVerifier(benchDir, command, runDir) {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
export async function runVerifier(benchDir, command, runDir, timeoutSeconds) {
|
|
328
|
+
const timeoutMs = parseVerifierTimeoutSeconds(timeoutSeconds) * 1000;
|
|
329
|
+
let tokens;
|
|
330
|
+
try {
|
|
331
|
+
tokens = parseCommand(command);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
return { exitCode: null, output: '', error: `VERIFIER_COMMAND_ERROR: ${error.message}` };
|
|
329
335
|
}
|
|
330
|
-
|
|
336
|
+
const result = await runProcess(tokens[0], [...tokens.slice(1), runDir], benchDir, timeoutMs);
|
|
337
|
+
return { ...result, error: result.error ?? verifierRuntimeError(result.output, result.exitCode, benchDir, runDir) };
|
|
331
338
|
}
|
|
332
339
|
export function verifierLogFor(result) {
|
|
333
340
|
return result.error ? `${result.output}\n[${result.error}]` : result.output;
|
|
@@ -340,6 +347,8 @@ const SPAWN_FAILURE = /ENOENT|EINVAL|EACCES|EPERM/i;
|
|
|
340
347
|
*/
|
|
341
348
|
export function verifierFailure(label, command, reason) {
|
|
342
349
|
const why = reason ?? 'no exit code';
|
|
350
|
+
if (why.startsWith('VERIFIER_'))
|
|
351
|
+
return `${label} failed (${why}): ${command}`;
|
|
343
352
|
if (SPAWN_FAILURE.test(why)) {
|
|
344
353
|
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
354
|
}
|
|
@@ -363,7 +372,7 @@ function sumTokens(records) {
|
|
|
363
372
|
* knob reports `sampling: null`, which is a statement about the surface — not an omission that a
|
|
364
373
|
* reader would have to guess at.
|
|
365
374
|
*/
|
|
366
|
-
function withSampling(descriptor) {
|
|
375
|
+
export function withSampling(descriptor) {
|
|
367
376
|
return { ...descriptor, sampling: descriptor.sampling ?? null };
|
|
368
377
|
}
|
|
369
378
|
function countErrors(records) {
|
|
@@ -430,7 +439,7 @@ function tokenDelta(baseline, treatment) {
|
|
|
430
439
|
return null;
|
|
431
440
|
return { input: treatment.input - baseline.input, output: treatment.output - baseline.output };
|
|
432
441
|
}
|
|
433
|
-
function summarizeJudge(judgeResults) {
|
|
442
|
+
export function summarizeJudge(judgeResults) {
|
|
434
443
|
if (judgeResults.length === 0)
|
|
435
444
|
return null;
|
|
436
445
|
const consistent = judgeResults.filter((r) => r.consistent);
|
|
@@ -447,7 +456,7 @@ function summarizeJudge(judgeResults) {
|
|
|
447
456
|
treatmentMean: mean(consistent.map((r) => r.treatmentScore)),
|
|
448
457
|
};
|
|
449
458
|
}
|
|
450
|
-
async function judgeTaskTrials(plan, taskId, outcomes) {
|
|
459
|
+
async function judgeTaskTrials(plan, taskId, outcomes, allJudgeCalls, budget) {
|
|
451
460
|
const judge = plan.judge;
|
|
452
461
|
if (!judge)
|
|
453
462
|
return [];
|
|
@@ -473,13 +482,27 @@ async function judgeTaskTrials(plan, taskId, outcomes) {
|
|
|
473
482
|
baselineOutput: baseline.output,
|
|
474
483
|
treatmentOutput: treatment.output,
|
|
475
484
|
seed,
|
|
485
|
+
taskId: task.id,
|
|
486
|
+
trial,
|
|
487
|
+
clock: plan.clock,
|
|
488
|
+
beforeCall: callIndex => budget.before({ role: 'judge', taskId: task.id, trial, callIndex }),
|
|
489
|
+
onCall: receipt => {
|
|
490
|
+
const path = join(taskDir, `judge-trial-${trial}`);
|
|
491
|
+
mkdirSync(path, { recursive: true });
|
|
492
|
+
writeFileSync(join(path, `call-${receipt.callIndex}.json`), JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
|
|
493
|
+
allJudgeCalls.push(receipt);
|
|
494
|
+
budget.after({ role: 'judge', taskId: task.id, trial, callIndex: receipt.callIndex }, receipt);
|
|
495
|
+
},
|
|
476
496
|
});
|
|
477
497
|
results.push(result);
|
|
478
498
|
writeFileSync(join(taskDir, `judge-trial-${trial}.json`), `${JSON.stringify({ trial, seed, ...result }, null, 2)}\n`, 'utf8');
|
|
479
499
|
}
|
|
480
500
|
catch (error) {
|
|
501
|
+
writeFileSync(join(taskDir, `judge-trial-${trial}-error.json`), JSON.stringify({ schemaVersion: 1, trial, seed,
|
|
502
|
+
error: error.message, calls: error instanceof JudgePairFailure ? error.calls : [], automaticRetry: false }, null, 2) + '\n', { flag: 'wx' });
|
|
481
503
|
throwIfEvaluationInterrupted();
|
|
482
504
|
plan.log?.(`Judge failed for ${task.id} trial ${trial}: ${error.message}`);
|
|
505
|
+
throw error;
|
|
483
506
|
}
|
|
484
507
|
}
|
|
485
508
|
return results;
|
|
@@ -603,8 +626,6 @@ function summarizeTask(taskId, outcomes, survivors, judgeResults, readObservatio
|
|
|
603
626
|
}
|
|
604
627
|
export async function runExperiment(plan) {
|
|
605
628
|
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
629
|
assertInputModeSupported(plan.inputMode ?? 'snapshot', plan.executor);
|
|
609
630
|
const pairOrder = plan.pairOrder ?? 'baseline-first';
|
|
610
631
|
if (pairOrder !== 'baseline-first' && pairOrder !== 'balanced')
|
|
@@ -639,14 +660,8 @@ export async function runExperiment(plan) {
|
|
|
639
660
|
const taskSummaries = [];
|
|
640
661
|
const allOutcomes = { baseline: [], treatment: [] };
|
|
641
662
|
const allSurvivors = { baseline: [], treatment: [] };
|
|
642
|
-
const
|
|
643
|
-
const
|
|
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
|
-
};
|
|
663
|
+
const budgetRecorder = createSpendingBudgetRecorder({ budget, groupDir });
|
|
664
|
+
const allJudgeCalls = [];
|
|
650
665
|
for (const [taskIndex, task] of plan.bench.tasks.entries()) {
|
|
651
666
|
const outcomes = { baseline: [], treatment: [] };
|
|
652
667
|
// Interleaved: the trial loop is outermost so the two arms of a pair run adjacently. Running
|
|
@@ -655,26 +670,21 @@ export async function runExperiment(plan) {
|
|
|
655
670
|
for (let trial = 1; trial <= plan.trials; trial++) {
|
|
656
671
|
for (const condition of pairConditions(pairOrder, taskIndex, trial)) {
|
|
657
672
|
throwIfEvaluationInterrupted();
|
|
658
|
-
|
|
659
|
-
if (before)
|
|
660
|
-
assertSpendingCanContinue(before);
|
|
673
|
+
budgetRecorder.before({ taskId: task.id, condition, trial });
|
|
661
674
|
plan.log?.(`Running ${task.id} / ${condition} / trial ${trial}…`);
|
|
662
675
|
const outcome = await runTrial(plan, task.id, condition, trial);
|
|
663
676
|
outcomes[condition].push(outcome);
|
|
664
677
|
allOutcomes[condition].push(outcome);
|
|
665
|
-
|
|
666
|
-
const after = budgetEvent('after-call', task.id, condition, trial);
|
|
678
|
+
budgetRecorder.after({ taskId: task.id, condition, trial }, outcome);
|
|
667
679
|
throwIfEvaluationInterrupted();
|
|
668
680
|
// A reached line prevents the next call; incomplete or failed evidence stops even
|
|
669
681
|
// 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
682
|
}
|
|
673
683
|
}
|
|
674
684
|
const survivors = pairedSurvivors(outcomes);
|
|
675
685
|
allSurvivors.baseline.push(...survivors.baseline);
|
|
676
686
|
allSurvivors.treatment.push(...survivors.treatment);
|
|
677
|
-
const judgeResults = await judgeTaskTrials(plan, task.id, outcomes);
|
|
687
|
+
const judgeResults = await judgeTaskTrials(plan, task.id, outcomes, allJudgeCalls, budgetRecorder);
|
|
678
688
|
taskSummaries.push(summarizeTask(task.id, outcomes, survivors, judgeResults, !!plan.skillInstallDir));
|
|
679
689
|
}
|
|
680
690
|
const overallBaseline = statsFor(allSurvivors.baseline, countErrors(allOutcomes.baseline), !!plan.skillInstallDir);
|
|
@@ -692,6 +702,7 @@ export async function runExperiment(plan) {
|
|
|
692
702
|
plan.session?.settle();
|
|
693
703
|
const manifestWithoutWarnings = {
|
|
694
704
|
schemaVersion: 4,
|
|
705
|
+
invocationCosts: summarizeInvocationCosts([...allOutcomes.baseline, ...allOutcomes.treatment], allJudgeCalls, !!plan.judge),
|
|
695
706
|
...(plan.component ? { component: plan.component } : {}),
|
|
696
707
|
...(plan.session ? { experiment: plan.session.summary() } : {}),
|
|
697
708
|
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();
|