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/commands/bench.js
CHANGED
|
@@ -2,20 +2,24 @@ import { spawnSync } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { assertInputModeSupported } from '../harness/prompt.js';
|
|
11
|
-
import { runTrial, runVerifier, verifierFailure } from '../harness/runner.js';
|
|
12
|
-
import { MOCK_MARKER_FILE, RUN_GROUP_PATTERN } from '../harness/constants.js';
|
|
5
|
+
import { BENCH_SCHEMA_VERSION, loadBench, selectBenchTasks, validateBenchTask } from '../harness/bench.js';
|
|
6
|
+
import { resolveBenchDir } from '../harness/bench-location.js';
|
|
7
|
+
import { listFilesRecursive, sha256File, sha256Text } from '../harness/hash.js';
|
|
8
|
+
import { runVerifier, verifierFailure } from '../harness/runner.js';
|
|
9
|
+
import { MOCK_MARKER_FILE } from '../harness/constants.js';
|
|
13
10
|
import { verdictFromOutput } from '../harness/verifier-summary.js';
|
|
14
11
|
import { confirm as confirmPrompt } from './confirm.js';
|
|
15
12
|
import { commandTemplateFiles } from './bench-command-template.js';
|
|
16
13
|
import { benchDiagnostic, benchCheckEvidence } from './bench-check-report.js';
|
|
17
14
|
import { BACKUP_SUFFIX } from './install.js';
|
|
18
15
|
import { withEvaluationInterrupts, throwIfEvaluationInterrupted } from '../harness/interruption.js';
|
|
16
|
+
import { assertAgentEnvironment, renderAgentEnvironment } from '../harness/agent-preflight.js';
|
|
17
|
+
import { calibrationCasePreflight, executeCalibration, prepareCalibration } from './bench-calibration.js';
|
|
18
|
+
import { freezeSourceFiles } from './bench-source.js';
|
|
19
|
+
import { BenchDraftSession } from './bench-draft.js';
|
|
20
|
+
import { parseVerifierTimeoutSeconds } from '../harness/verifier-timeout.js';
|
|
21
|
+
export { captureSourceFiles } from './bench-source.js';
|
|
22
|
+
export { prepareBenchCalibration } from './bench-calibration.js';
|
|
19
23
|
const FIXTURE_SIZE_WARN_BYTES = 64 * 1024;
|
|
20
24
|
// benches/README.md: a verifier decomposes its acceptance criteria into 2–8 named checks.
|
|
21
25
|
const MIN_FACET_CHECKS = 2;
|
|
@@ -142,13 +146,13 @@ export async function runBenchInit(options) {
|
|
|
142
146
|
log('This is a teaching case. Replace it with your own task before measuring Skill benefit.');
|
|
143
147
|
return { dir, created };
|
|
144
148
|
}
|
|
145
|
-
async function probeVerifier(benchDir, verifier, output) {
|
|
149
|
+
async function probeVerifier(benchDir, verifier, output, timeoutSeconds) {
|
|
146
150
|
const dir = mkdtempSync(join(tmpdir(), 'skillfit-check-'));
|
|
147
151
|
try {
|
|
148
152
|
if (output !== null) {
|
|
149
153
|
writeFileSync(join(dir, '_output.md'), output, 'utf8');
|
|
150
154
|
}
|
|
151
|
-
const result = await runVerifier(benchDir, verifier, dir);
|
|
155
|
+
const result = await runVerifier(benchDir, verifier, dir, timeoutSeconds);
|
|
152
156
|
return {
|
|
153
157
|
exitCode: result.exitCode,
|
|
154
158
|
error: result.error,
|
|
@@ -185,27 +189,29 @@ function copyFixture(fixtureDir, dest) {
|
|
|
185
189
|
writeFileSync(target, readFileSync(join(fixtureDir, rel)));
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
|
-
async function runOracleGate(benchDir, fixtureDir, oracle, verifier) {
|
|
192
|
+
async function runOracleGate(benchDir, fixtureDir, oracle, verifier, timeoutSeconds, record) {
|
|
189
193
|
const dir = mkdtempSync(join(tmpdir(), 'skillfit-check-'));
|
|
190
194
|
try {
|
|
191
195
|
copyFixture(fixtureDir, dir);
|
|
192
|
-
const oracleRun = await runVerifier(benchDir, oracle, dir);
|
|
193
|
-
|
|
196
|
+
const oracleRun = await runVerifier(benchDir, oracle, dir, timeoutSeconds);
|
|
197
|
+
record?.('oracle', oracleRun);
|
|
198
|
+
if (oracleRun.error !== null || oracleRun.exitCode !== 0) {
|
|
194
199
|
return {
|
|
195
200
|
kind: 'oracle-failed',
|
|
196
201
|
result: oracleRun,
|
|
197
202
|
command: oracle,
|
|
198
203
|
exitCode: oracleRun.exitCode,
|
|
199
|
-
reason: oracleRun.exitCode === null ? verifierFailure('oracle', oracle, oracleRun.error) : null,
|
|
204
|
+
reason: oracleRun.error !== null || oracleRun.exitCode === null ? verifierFailure('oracle', oracle, oracleRun.error) : null,
|
|
200
205
|
};
|
|
201
206
|
}
|
|
202
|
-
const graded = await runVerifier(benchDir, verifier, dir);
|
|
203
|
-
|
|
207
|
+
const graded = await runVerifier(benchDir, verifier, dir, timeoutSeconds);
|
|
208
|
+
record?.('oracle-verifier', graded);
|
|
209
|
+
if (graded.error !== null || graded.exitCode !== 0) {
|
|
204
210
|
return {
|
|
205
211
|
kind: 'verifier-failed',
|
|
206
212
|
result: graded,
|
|
207
213
|
command: verifier,
|
|
208
|
-
reason: graded.exitCode === null ? verifierFailure('verifier', verifier, graded.error) : null,
|
|
214
|
+
reason: graded.error !== null || graded.exitCode === null ? verifierFailure('verifier', verifier, graded.error) : null,
|
|
209
215
|
};
|
|
210
216
|
}
|
|
211
217
|
const score = verdictFromOutput(graded.output)?.score ?? null;
|
|
@@ -218,8 +224,8 @@ async function runOracleGate(benchDir, fixtureDir, oracle, verifier) {
|
|
|
218
224
|
rmSync(dir, { recursive: true, force: true });
|
|
219
225
|
}
|
|
220
226
|
}
|
|
221
|
-
async function probeOracle(benchDir, fixture, oracle, verifier) {
|
|
222
|
-
const gate = await runOracleGate(benchDir, join(benchDir, fixture), oracle, verifier);
|
|
227
|
+
async function probeOracle(benchDir, fixture, oracle, verifier, timeoutSeconds) {
|
|
228
|
+
const gate = await runOracleGate(benchDir, join(benchDir, fixture), oracle, verifier, timeoutSeconds);
|
|
223
229
|
switch (gate.kind) {
|
|
224
230
|
case 'oracle-failed':
|
|
225
231
|
return {
|
|
@@ -252,8 +258,14 @@ function renderCheck({ status, message }) {
|
|
|
252
258
|
return `[${status}] ${message}`;
|
|
253
259
|
}
|
|
254
260
|
export async function runBenchCheck(options) {
|
|
261
|
+
return withEvaluationInterrupts(() => runBenchCheckWithinInterrupts(options));
|
|
262
|
+
}
|
|
263
|
+
export async function runBenchCalibration(options) {
|
|
264
|
+
return withEvaluationInterrupts(() => runBenchCheckWithinInterrupts(options, true));
|
|
265
|
+
}
|
|
266
|
+
async function runBenchCheckWithinInterrupts(options, strictCalibration = false) {
|
|
255
267
|
const log = options.log ?? ((msg) => console.log(msg));
|
|
256
|
-
|
|
268
|
+
let dir = resolve(options.dir ?? '.');
|
|
257
269
|
const checks = [];
|
|
258
270
|
let identity = null;
|
|
259
271
|
const push = (code, status, message, task, evidence) => {
|
|
@@ -263,7 +275,8 @@ export async function runBenchCheck(options) {
|
|
|
263
275
|
};
|
|
264
276
|
let bench;
|
|
265
277
|
try {
|
|
266
|
-
|
|
278
|
+
dir = resolveBenchDir(options.dir ?? '.');
|
|
279
|
+
bench = selectBenchTasks(loadBench(dir), options.taskIds ?? (options.calibrate ? options.calibrate.taskIds : undefined));
|
|
267
280
|
}
|
|
268
281
|
catch (error) {
|
|
269
282
|
push('BENCH_LOAD', 'FAIL', `bench does not load: ${error.message}`);
|
|
@@ -271,12 +284,26 @@ export async function runBenchCheck(options) {
|
|
|
271
284
|
}
|
|
272
285
|
identity = { name: bench.name, sha256: bench.contentSha256, taskCount: bench.tasks.length };
|
|
273
286
|
push('BENCH_LOAD', 'PASS', `bench.json valid (${bench.tasks.length} task(s), content sha256 ${bench.contentSha256.slice(0, 12)}…)`);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
287
|
+
const calibration = options.calibrate ? prepareCalibration({ dir, taskIds: options.taskIds, calibrate: options.calibrate }) : null;
|
|
288
|
+
if (calibration) {
|
|
289
|
+
log(renderAgentEnvironment(calibration.plan.agentPreflight));
|
|
290
|
+
if (options.calibrate && options.calibrate.dryRun) {
|
|
291
|
+
push('CALIBRATION', 'INFO', `calibration executor: ${calibration.plan.executor?.detail ?? calibration.plan.executor?.model ?? 'unavailable'}`);
|
|
292
|
+
push('CALIBRATION', 'INFO', `calibration plan: ${bench.tasks.length} task(s) × ${calibration.plan.trials} baseline run(s), input ${calibration.plan.inputMode}; ${calibration.plan.plannedCalls} calls, ceiling ${calibration.plan.maxCalls}; deadline ${calibration.plan.executorTimeoutSeconds}s; no verifier, oracle or agent started and no run directory created`);
|
|
293
|
+
push('CALIBRATION', 'INFO', `Plan SHA-256: ${calibration.plan.planSha256}; fresh output ${calibration.plan.outputDir}`);
|
|
294
|
+
return finish(dir, checks, log, true, identity);
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
assertAgentEnvironment(calibration.plan.agentPreflight);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (strictCalibration)
|
|
301
|
+
throw error;
|
|
302
|
+
push('CALIBRATION', 'FAIL', error.message);
|
|
303
|
+
return finish(dir, checks, log, true, identity);
|
|
304
|
+
}
|
|
279
305
|
}
|
|
306
|
+
const offlineStarted = performance.now();
|
|
280
307
|
let labeledTasks = 0;
|
|
281
308
|
let negativeTasks = 0;
|
|
282
309
|
for (const task of bench.tasks) {
|
|
@@ -286,9 +313,9 @@ export async function runBenchCheck(options) {
|
|
|
286
313
|
const fixtureCopy = mkdtempSync(join(tmpdir(), 'skillfit-check-'));
|
|
287
314
|
try {
|
|
288
315
|
copyFixture(join(bench.dir, task.fixture), fixtureCopy);
|
|
289
|
-
const pristine = await runVerifier(bench.dir, task.verifier, fixtureCopy);
|
|
316
|
+
const pristine = await runVerifier(bench.dir, task.verifier, fixtureCopy, task.verifierTimeoutSeconds);
|
|
290
317
|
facetChecks = verdictFromOutput(pristine.output)?.checks ?? null;
|
|
291
|
-
if (pristine.exitCode === null) {
|
|
318
|
+
if (pristine.error !== null || pristine.exitCode === null) {
|
|
292
319
|
// Without this branch a verifier that cannot even be spawned reads as a clean NOP gate:
|
|
293
320
|
// "fails on the untouched fixture" is exactly what `exitCode !== 0` looks like.
|
|
294
321
|
taskPush('UNTOUCHED_FIXTURE', 'FAIL', `${task.id}: ${verifierFailure('verifier', task.verifier, pristine.error)}`, benchCheckEvidence(pristine, task.verifier));
|
|
@@ -305,8 +332,8 @@ export async function runBenchCheck(options) {
|
|
|
305
332
|
}
|
|
306
333
|
}
|
|
307
334
|
else {
|
|
308
|
-
const missing = await probeVerifier(bench.dir, task.verifier, null);
|
|
309
|
-
if (missing.exitCode === null) {
|
|
335
|
+
const missing = await probeVerifier(bench.dir, task.verifier, null, task.verifierTimeoutSeconds);
|
|
336
|
+
if (missing.error !== null || missing.exitCode === null) {
|
|
310
337
|
taskPush('MISSING_OUTPUT', 'FAIL', `${task.id}: ${verifierFailure('verifier', task.verifier, missing.error)}`, benchCheckEvidence(missing, task.verifier));
|
|
311
338
|
}
|
|
312
339
|
else if (missing.exitCode === 0) {
|
|
@@ -315,9 +342,9 @@ export async function runBenchCheck(options) {
|
|
|
315
342
|
else {
|
|
316
343
|
taskPush('MISSING_OUTPUT', 'PASS', `${task.id}: verifier rejects missing output`, benchCheckEvidence(missing, task.verifier));
|
|
317
344
|
}
|
|
318
|
-
const empty = await probeVerifier(bench.dir, task.verifier, '');
|
|
345
|
+
const empty = await probeVerifier(bench.dir, task.verifier, '', task.verifierTimeoutSeconds);
|
|
319
346
|
facetChecks = empty.checks;
|
|
320
|
-
if (empty.exitCode === null) {
|
|
347
|
+
if (empty.error !== null || empty.exitCode === null) {
|
|
321
348
|
taskPush('EMPTY_OUTPUT', 'FAIL', `${task.id}: ${verifierFailure('verifier', task.verifier, empty.error)}`, benchCheckEvidence(empty, task.verifier));
|
|
322
349
|
}
|
|
323
350
|
else if (empty.exitCode === 0) {
|
|
@@ -331,7 +358,7 @@ export async function runBenchCheck(options) {
|
|
|
331
358
|
if (facetGate)
|
|
332
359
|
taskPush('FACET_COUNT', facetGate.status, facetGate.message);
|
|
333
360
|
if (task.oracle) {
|
|
334
|
-
const oracleResult = await probeOracle(bench.dir, task.fixture, task.oracle, task.verifier);
|
|
361
|
+
const oracleResult = await probeOracle(bench.dir, task.fixture, task.oracle, task.verifier, task.verifierTimeoutSeconds);
|
|
335
362
|
taskPush('ORACLE', oracleResult.status, `${task.id}: ${oracleResult.message}`, oracleResult.evidence);
|
|
336
363
|
}
|
|
337
364
|
else {
|
|
@@ -352,8 +379,8 @@ export async function runBenchCheck(options) {
|
|
|
352
379
|
taskPush(arm === 'baseline' ? 'MOCK_BASELINE' : 'MOCK_TREATMENT', 'INFO', `${task.id}: no mock ${arm} output — this arm was not probed`);
|
|
353
380
|
continue;
|
|
354
381
|
}
|
|
355
|
-
const probe = await probeVerifier(bench.dir, task.verifier, behavior.output);
|
|
356
|
-
taskPush(arm === 'baseline' ? 'MOCK_BASELINE' : 'MOCK_TREATMENT', probe.exitCode === null ? 'FAIL' : 'INFO', `${task.id}: mock ${arm} output → ${probe.exitCode === null ? verifierFailure('verifier', task.verifier, probe.error) : `verifier ${probe.exitCode === 0 ? 'pass' : 'fail'}`}`, benchCheckEvidence(probe, task.verifier));
|
|
382
|
+
const probe = await probeVerifier(bench.dir, task.verifier, behavior.output, task.verifierTimeoutSeconds);
|
|
383
|
+
taskPush(arm === 'baseline' ? 'MOCK_BASELINE' : 'MOCK_TREATMENT', probe.error !== null || probe.exitCode === null ? 'FAIL' : 'INFO', `${task.id}: mock ${arm} output → ${probe.error !== null || probe.exitCode === null ? verifierFailure('verifier', task.verifier, probe.error) : `verifier ${probe.exitCode === 0 ? 'pass' : 'fail'}`}`, benchCheckEvidence(probe, task.verifier));
|
|
357
384
|
}
|
|
358
385
|
}
|
|
359
386
|
catch (error) {
|
|
@@ -396,128 +423,27 @@ export async function runBenchCheck(options) {
|
|
|
396
423
|
push('NEGATIVE_CONTROLS', 'PASS', `${negativeTasks}/${labeledTasks} labeled task(s) are negative controls (${percent}%) — at or above the ${NEGATIVE_CONTROL_PERCENT}% target`);
|
|
397
424
|
}
|
|
398
425
|
}
|
|
399
|
-
if (
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const trials = options.trials ?? CALIBRATE_DEFAULT_TRIALS;
|
|
411
|
-
const inputMode = options.inputMode ?? 'snapshot';
|
|
412
|
-
const capture = options.agent && getAgent(options.agent).headless.streamJson;
|
|
413
|
-
const executor = options.executor ?? CliExecutor.forAgent(options.agent ?? '', capture ? { triggerSkillName: 'calibration-none' } : undefined);
|
|
414
|
-
assertInputModeSupported(inputMode, executor);
|
|
415
|
-
if (!Number.isInteger(trials) || trials < 1 || trials > 20) {
|
|
416
|
-
throw new Error(`calibration trials must be an integer between 1 and 20, got ${trials}`);
|
|
417
|
-
}
|
|
418
|
-
const plannedCalls = bench.tasks.length * trials;
|
|
419
|
-
const maxCalls = validateCallBudget(plannedCalls, options.maxCalls);
|
|
420
|
-
if (options.dryRun) {
|
|
421
|
-
push('INFO', `calibration executor: ${executor.describe().detail ?? executor.describe().model}`);
|
|
422
|
-
push('INFO', `calibration plan: ${bench.tasks.length} task(s) × ${trials} baseline run(s), input ${inputMode}; ${plannedCalls} calls, ceiling ${maxCalls}; no agent started and no run directory created`);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
return withEvaluationInterrupts(async () => {
|
|
426
|
-
const emptySkillDir = mkdtempSync(join(tmpdir(), 'skillfit-calibrate-'));
|
|
427
|
-
let session;
|
|
428
|
-
let failure;
|
|
429
|
-
try {
|
|
430
|
-
const skill = {
|
|
431
|
-
kind: 'skill',
|
|
432
|
-
name: 'calibration-none',
|
|
433
|
-
sourceDir: emptySkillDir,
|
|
434
|
-
files: [],
|
|
435
|
-
sha256: '0'.repeat(64),
|
|
436
|
-
payload: '',
|
|
437
|
-
overlays: {},
|
|
438
|
-
};
|
|
439
|
-
const runGroup = options.runGroup ??
|
|
440
|
-
`calibrate-${new Date().toISOString().slice(0, 10).replaceAll('-', '')}-${String(Date.now() % 100000).padStart(5, '0')}`;
|
|
441
|
-
if (!RUN_GROUP_PATTERN.test(runGroup))
|
|
442
|
-
throw new Error(`Invalid run group: ${runGroup}`);
|
|
443
|
-
const runsRoot = options.runsRoot ?? resolve('runs');
|
|
444
|
-
push('INFO', `calibration plan: ${plannedCalls} baseline calls, ceiling ${maxCalls}; fresh output ${join(runsRoot, runGroup)}`);
|
|
445
|
-
session = new ExperimentSession({ bench, target: skill, groupDir: join(runsRoot, runGroup), plannedCalls,
|
|
446
|
-
maxCalls, agent: options.agent, injected: options.executor !== undefined, ...options.sessionOptions,
|
|
447
|
-
workspaces: bench.tasks.flatMap(task => Array.from({ length: trials }, (_, i) => join(runsRoot, runGroup, task.id, 'baseline', `trial-${i + 1}`))),
|
|
448
|
-
details: { mode: 'calibration', inputMode, trials, executor: executor.describe() } });
|
|
449
|
-
// Calibration measures inject-mode baseline difficulty, so it drives the inject path with an
|
|
450
|
-
// empty skill payload (prompt.ts drops a falsy payload, so no skill block is injected) and runs
|
|
451
|
-
// one arm per task. This used to route through trigger mode, whose `shouldTrigger` filter
|
|
452
|
-
// silently calibrated zero tasks on an unlabelled bench and then reported PASS 0/0.
|
|
453
|
-
const plan = {
|
|
454
|
-
bench,
|
|
455
|
-
target: skill,
|
|
456
|
-
inputMode,
|
|
457
|
-
executor: session.wrap(executor, 'agent'),
|
|
458
|
-
trials,
|
|
459
|
-
runsRoot,
|
|
460
|
-
runGroup,
|
|
461
|
-
log,
|
|
462
|
-
};
|
|
463
|
-
push('INFO', `calibration: ${trials} run(s) per task with no skill installed (baseline difficulty; input ${inputMode})`);
|
|
464
|
-
let discriminative = 0;
|
|
465
|
-
let tasksRun = 0;
|
|
466
|
-
const taskResults = [];
|
|
467
|
-
for (const task of bench.tasks) {
|
|
468
|
-
let passes = 0;
|
|
469
|
-
let completed = 0;
|
|
470
|
-
let errors = 0;
|
|
471
|
-
for (let trial = 1; trial <= trials; trial++) {
|
|
472
|
-
const outcome = await runTrial(plan, task.id, 'baseline', trial);
|
|
473
|
-
throwIfEvaluationInterrupted();
|
|
474
|
-
if (outcome.error !== null) {
|
|
475
|
-
errors++;
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
completed++;
|
|
479
|
-
if (outcome.passed)
|
|
480
|
-
passes++;
|
|
481
|
-
}
|
|
482
|
-
taskResults.push({ id: task.id, passes, completed, errors });
|
|
483
|
-
if (completed === 0) {
|
|
484
|
-
push('WARN', `${task.id}: no completed runs${errors > 0 ? ` (${errors} ungraded run(s))` : ''} — cannot assess difficulty`);
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
tasksRun++;
|
|
488
|
-
const rate = passes / completed;
|
|
489
|
-
if (rate >= 0.9) {
|
|
490
|
-
push('WARN', `${task.id}: baseline ${passes}/${completed} — too easy (saturated; cannot discriminate skill effects)`);
|
|
491
|
-
}
|
|
492
|
-
else if (rate <= 0.1) {
|
|
493
|
-
push('WARN', `${task.id}: baseline ${passes}/${completed} — too hard or broken (floor)`);
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
discriminative++;
|
|
497
|
-
push('PASS', `${task.id}: baseline ${passes}/${completed} — discriminative band`);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
session.settle();
|
|
501
|
-
const result = { schemaVersion: 1, runGroup, inputMode, trials, tasks: taskResults, experiment: session.summary() };
|
|
502
|
-
writeFileSync(join(session.groupDir, '_calibration.json'), JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
|
|
503
|
-
session.finish(undefined, result, '_calibration.json');
|
|
504
|
-
if (session.summary().status !== 'completed')
|
|
505
|
-
push('FAIL', 'Calibration stopped or incomplete; inspect _session.json and _calls.jsonl before a fresh plan.');
|
|
506
|
-
if (tasksRun === 0) {
|
|
507
|
-
push('FAIL', `calibration ran 0 task(s): difficulty unmeasured (runs under ${runGroup})`);
|
|
508
|
-
return;
|
|
426
|
+
if (calibration) {
|
|
427
|
+
const offlineReport = { dir, bench: identity, checks, failures: checks.filter(check => check.status === 'FAIL').length,
|
|
428
|
+
warnings: checks.filter(check => check.status === 'WARN').length };
|
|
429
|
+
const casePreflight = calibrationCasePreflight(bench, offlineReport, Math.round(performance.now() - offlineStarted));
|
|
430
|
+
log(`Case preflight: ${casePreflight.status}; ${casePreflight.summary.failures} failure(s), ${casePreflight.summary.warnings} warning(s), ${casePreflight.summary.unknown} unknown(s); 0 model calls`);
|
|
431
|
+
for (const check of casePreflight.checks.filter(check => check.status === 'UNKNOWN'))
|
|
432
|
+
log(`[UNKNOWN] ${check.code}: ${check.message}`);
|
|
433
|
+
if (casePreflight.status === 'blocked') {
|
|
434
|
+
if (strictCalibration) {
|
|
435
|
+
const { CasePreflightFailed } = await import('./eval-preflight.js');
|
|
436
|
+
throw new CasePreflightFailed(casePreflight);
|
|
509
437
|
}
|
|
510
|
-
push(
|
|
438
|
+
push('CALIBRATION', 'FAIL', 'Offline case preflight blocked calibration; no agent calls or run directory were created. Fix every hard failure before a fresh plan.');
|
|
439
|
+
for (const check of casePreflight.checks.filter(check => check.code === 'INPUT_CHANGED'))
|
|
440
|
+
push('CALIBRATION', 'FAIL', check.message);
|
|
511
441
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
throw error;
|
|
515
|
-
}
|
|
516
|
-
finally {
|
|
517
|
-
session?.finish(failure);
|
|
518
|
-
rmSync(emptySkillDir, { recursive: true, force: true });
|
|
442
|
+
else {
|
|
443
|
+
await executeCalibration(calibration, casePreflight, (status, message) => push('CALIBRATION', status, message), log);
|
|
519
444
|
}
|
|
520
|
-
}
|
|
445
|
+
}
|
|
446
|
+
return finish(dir, checks, log, options.calibrate !== false && options.calibrate !== undefined, identity);
|
|
521
447
|
}
|
|
522
448
|
function finish(dir, checks, log, calibrated = false, bench = null) {
|
|
523
449
|
const failures = checks.filter((c) => c.status === 'FAIL').length;
|
|
@@ -533,13 +459,6 @@ function finish(dir, checks, log, calibrated = false, bench = null) {
|
|
|
533
459
|
return { dir, bench, checks, failures, warnings };
|
|
534
460
|
}
|
|
535
461
|
const TASK_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
536
|
-
export function captureSourceFiles(sourceDir) {
|
|
537
|
-
const git = spawnSync('git', ['ls-files', '-z'], { cwd: sourceDir, encoding: 'utf8' });
|
|
538
|
-
if (git.status === 0 && git.stdout.trim() !== '') {
|
|
539
|
-
return git.stdout.split('\0').filter(Boolean);
|
|
540
|
-
}
|
|
541
|
-
return listFilesRecursive(sourceDir).filter((rel) => !rel.split(/[\\/]/).some((part) => part === '.git' || part === 'node_modules'));
|
|
542
|
-
}
|
|
543
462
|
function verifierForCmd(cmd) {
|
|
544
463
|
return `import { spawnSync } from 'node:child_process';
|
|
545
464
|
|
|
@@ -557,11 +476,12 @@ function scrubbedEnv() {
|
|
|
557
476
|
const result = spawnSync(${JSON.stringify(cmd)}, { cwd: runDir, shell: true, encoding: 'utf8', env: scrubbedEnv() });
|
|
558
477
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
559
478
|
if (result.stderr) process.stderr.write(result.stderr);
|
|
560
|
-
if (result.error) {
|
|
561
|
-
console.
|
|
562
|
-
|
|
479
|
+
if (result.error || result.signal || result.status === null) {
|
|
480
|
+
console.log(JSON.stringify({ schemaVersion: 1, kind: 'skillfit.verifier-error',
|
|
481
|
+
message: result.error ? String(result.error) : 'Verifier command ended without a verdict: ' + (result.signal ?? 'no exit code') }));
|
|
482
|
+
process.exit(2);
|
|
563
483
|
}
|
|
564
|
-
process.exit(result.status
|
|
484
|
+
process.exit(result.status);
|
|
565
485
|
`;
|
|
566
486
|
}
|
|
567
487
|
function verifierForExpect(needle) {
|
|
@@ -629,58 +549,45 @@ Node built-ins. Your draft is validated automatically: the verifier must fail th
|
|
|
629
549
|
fixture and pass the oracle-solved one, so test both directions before you finish.
|
|
630
550
|
`;
|
|
631
551
|
}
|
|
632
|
-
async function draftVerifierWithOracle(
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
552
|
+
async function draftVerifierWithOracle(session, log) {
|
|
553
|
+
const staging = session.workspace;
|
|
554
|
+
const fixtureDir = join(staging, 'fixture');
|
|
555
|
+
log(`Drafting verifier + oracle; at most 1 call. Records: ${session.dir}`);
|
|
556
|
+
await session.run();
|
|
557
|
+
const verifierPath = join(staging, 'verifier.mjs');
|
|
558
|
+
const oraclePath = join(staging, 'oracle.mjs');
|
|
559
|
+
if (!existsSync(verifierPath) || !existsSync(oraclePath)) {
|
|
560
|
+
throw new Error('the drafting agent did not write verifier.mjs and oracle.mjs into its working directory — nothing was added');
|
|
636
561
|
}
|
|
637
|
-
const
|
|
562
|
+
const nopDir = mkdtempSync(join(tmpdir(), 'skillfit-decompose-nop-'));
|
|
638
563
|
try {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
log(`Drafting verifier + oracle with ${executor.describe().kind} (${executor.describe().model})…`);
|
|
646
|
-
await executor.run(buildDecomposePrompt(prepared.promptText, prepared.fixtureFiles.map((f) => f.rel), prepared.verifierKind), staging);
|
|
647
|
-
const verifierPath = join(staging, 'verifier.mjs');
|
|
648
|
-
const oraclePath = join(staging, 'oracle.mjs');
|
|
649
|
-
if (!existsSync(verifierPath) || !existsSync(oraclePath)) {
|
|
650
|
-
throw new Error('the drafting agent did not write verifier.mjs and oracle.mjs into its working directory — nothing was added');
|
|
651
|
-
}
|
|
652
|
-
const nopDir = mkdtempSync(join(tmpdir(), 'skillfit-decompose-nop-'));
|
|
653
|
-
try {
|
|
654
|
-
copyFixture(fixtureDir, nopDir);
|
|
655
|
-
const nop = await runVerifier(staging, 'node verifier.mjs', nopDir);
|
|
656
|
-
if (nop.exitCode === null) {
|
|
657
|
-
throw new Error(`draft rejected: ${verifierFailure('verifier', 'node verifier.mjs', nop.error)}`);
|
|
658
|
-
}
|
|
659
|
-
if (nop.exitCode === 0) {
|
|
660
|
-
throw new Error('draft rejected: the verifier passes the untouched fixture — the task would start solved (NOP gate)');
|
|
661
|
-
}
|
|
564
|
+
copyFixture(fixtureDir, nopDir);
|
|
565
|
+
const nop = await runVerifier(staging, 'node verifier.mjs', nopDir, session.plan.verifierTimeoutSeconds);
|
|
566
|
+
session.gate('untouched-fixture', nop);
|
|
567
|
+
if (nop.error !== null || nop.exitCode === null) {
|
|
568
|
+
throw new Error(`draft rejected: ${verifierFailure('verifier', 'node verifier.mjs', nop.error)}`);
|
|
662
569
|
}
|
|
663
|
-
|
|
664
|
-
|
|
570
|
+
if (nop.exitCode === 0) {
|
|
571
|
+
throw new Error('draft rejected: the verifier passes the untouched fixture — the task would start solved (NOP gate)');
|
|
665
572
|
}
|
|
666
|
-
const solvedGate = await runOracleGate(staging, fixtureDir, 'node oracle.mjs', 'node verifier.mjs');
|
|
667
|
-
if (solvedGate.kind === 'oracle-failed') {
|
|
668
|
-
throw new Error(`draft rejected: ${solvedGate.reason ?? 'the oracle command failed on a fresh fixture copy'}`);
|
|
669
|
-
}
|
|
670
|
-
if (solvedGate.kind === 'verifier-failed') {
|
|
671
|
-
throw new Error(`draft rejected: ${solvedGate.reason ?? 'the verifier fails even after the oracle solved the task (oracle gate)'}`);
|
|
672
|
-
}
|
|
673
|
-
if (solvedGate.kind === 'low-score') {
|
|
674
|
-
throw new Error(`draft rejected: the oracle scores ${solvedGate.score.toFixed(2)} on the drafted checks — checks are stricter than the oracle`);
|
|
675
|
-
}
|
|
676
|
-
return {
|
|
677
|
-
verifierSource: readFileSync(verifierPath, 'utf8'),
|
|
678
|
-
oracleSource: readFileSync(oraclePath, 'utf8'),
|
|
679
|
-
};
|
|
680
573
|
}
|
|
681
574
|
finally {
|
|
682
|
-
rmSync(
|
|
575
|
+
rmSync(nopDir, { recursive: true, force: true });
|
|
576
|
+
}
|
|
577
|
+
const solvedGate = await runOracleGate(staging, fixtureDir, 'node oracle.mjs', 'node verifier.mjs', session.plan.verifierTimeoutSeconds, (name, result) => session.gate(name, result));
|
|
578
|
+
if (solvedGate.kind === 'oracle-failed') {
|
|
579
|
+
throw new Error(`draft rejected: ${solvedGate.reason ?? 'the oracle command failed on a fresh fixture copy'}`);
|
|
683
580
|
}
|
|
581
|
+
if (solvedGate.kind === 'verifier-failed') {
|
|
582
|
+
throw new Error(`draft rejected: ${solvedGate.reason ?? 'the verifier fails even after the oracle solved the task (oracle gate)'}`);
|
|
583
|
+
}
|
|
584
|
+
if (solvedGate.kind === 'low-score') {
|
|
585
|
+
throw new Error(`draft rejected: the oracle scores ${solvedGate.score.toFixed(2)} on the drafted checks — checks are stricter than the oracle`);
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
verifierSource: readFileSync(verifierPath, 'utf8'),
|
|
589
|
+
oracleSource: readFileSync(oraclePath, 'utf8'),
|
|
590
|
+
};
|
|
684
591
|
}
|
|
685
592
|
function assertInsideBench(benchDir, target) {
|
|
686
593
|
const rel = relative(benchDir, target);
|
|
@@ -688,7 +595,38 @@ function assertInsideBench(benchDir, target) {
|
|
|
688
595
|
throw new Error(`Refusing to write outside the bench directory: ${target}`);
|
|
689
596
|
}
|
|
690
597
|
}
|
|
598
|
+
function assertBenchWrites(benchDir, targets) {
|
|
599
|
+
for (const target of targets) {
|
|
600
|
+
assertInsideBench(benchDir, target);
|
|
601
|
+
const parts = relative(benchDir, target).split(/[\\/]/);
|
|
602
|
+
let path = benchDir;
|
|
603
|
+
for (let index = 0; index < parts.length; index++) {
|
|
604
|
+
path = join(path, parts[index]);
|
|
605
|
+
try {
|
|
606
|
+
const stat = lstatSync(path);
|
|
607
|
+
if (stat.isSymbolicLink())
|
|
608
|
+
throw new Error(`Refusing a symlink in bench output: ${path}`);
|
|
609
|
+
if (index < parts.length - 1 ? !stat.isDirectory() : !stat.isFile())
|
|
610
|
+
throw new Error(`Refusing to overwrite a non-file or traverse a non-directory: ${path}`);
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
if (error.code !== 'ENOENT')
|
|
614
|
+
throw error;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
const stat = lstatSync(target + BACKUP_SUFFIX);
|
|
619
|
+
if (stat.isSymbolicLink() || !stat.isFile())
|
|
620
|
+
throw new Error(`Refusing an unsafe backup target: ${target + BACKUP_SUFFIX}`);
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
if (error.code !== 'ENOENT')
|
|
624
|
+
throw error;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
691
628
|
export function applyBenchWrites(benchDir, writes) {
|
|
629
|
+
assertBenchWrites(benchDir, writes.map(write => write.target));
|
|
692
630
|
const applied = [];
|
|
693
631
|
try {
|
|
694
632
|
for (const write of writes) {
|
|
@@ -737,7 +675,11 @@ export function applyBenchWrites(benchDir, writes) {
|
|
|
737
675
|
}
|
|
738
676
|
}
|
|
739
677
|
export async function runBenchAdd(options) {
|
|
678
|
+
return options.dryRun ? runBenchAddWithinInterrupts(options) : withEvaluationInterrupts(() => runBenchAddWithinInterrupts(options));
|
|
679
|
+
}
|
|
680
|
+
async function runBenchAddWithinInterrupts(options) {
|
|
740
681
|
const log = options.log ?? ((msg) => console.log(msg));
|
|
682
|
+
const timeout = options.verifierTimeoutSeconds === undefined ? {} : { verifierTimeoutSeconds: parseVerifierTimeoutSeconds(options.verifierTimeoutSeconds) };
|
|
741
683
|
if (!options.freeze && !options.fromCommit) {
|
|
742
684
|
throw new Error('bench add needs an importer: --freeze (current directory) or --from-commit <sha> (git history).');
|
|
743
685
|
}
|
|
@@ -759,8 +701,15 @@ export async function runBenchAdd(options) {
|
|
|
759
701
|
if (!existsSync(benchJsonPath)) {
|
|
760
702
|
throw new Error(`Not a bench directory (missing bench.json): ${benchDir} — run \`skillfit bench init\` first.`);
|
|
761
703
|
}
|
|
762
|
-
const
|
|
704
|
+
const originalManifest = readFileSync(benchJsonPath, 'utf8');
|
|
705
|
+
const benchJson = JSON.parse(originalManifest);
|
|
763
706
|
const tasks = Array.isArray(benchJson.tasks) ? benchJson.tasks : [];
|
|
707
|
+
if (benchJson.schemaVersion !== BENCH_SCHEMA_VERSION || !Array.isArray(benchJson.tasks))
|
|
708
|
+
throw new Error('Invalid bench.json schema or task list; fix the bench before adding a task.');
|
|
709
|
+
for (const [index, task] of tasks.entries())
|
|
710
|
+
validateBenchTask(benchDir, task, index);
|
|
711
|
+
if (new Set(tasks.map(task => task.id)).size !== tasks.length)
|
|
712
|
+
throw new Error('Duplicate task IDs in bench.json; fix the bench before adding a task.');
|
|
764
713
|
const prepared = options.fromCommit
|
|
765
714
|
? prepareFromCommit(options, cwd)
|
|
766
715
|
: prepareFreeze(options, cwd);
|
|
@@ -771,19 +720,15 @@ export async function runBenchAdd(options) {
|
|
|
771
720
|
if (tasks.some((task) => task?.id === taskId)) {
|
|
772
721
|
throw new Error(`Task "${taskId}" already exists in ${benchJsonPath}.`);
|
|
773
722
|
}
|
|
774
|
-
|
|
775
|
-
const drafted = await draftVerifierWithOracle(options, prepared, log);
|
|
776
|
-
prepared.verifierSource = drafted.verifierSource;
|
|
777
|
-
prepared.oracleSource = drafted.oracleSource;
|
|
778
|
-
}
|
|
723
|
+
const draft = options.decompose ? new BenchDraftSession(options, taskId, benchDir, cwd, prepared.fixtureFiles, buildDecomposePrompt(prepared.promptText, prepared.fixtureFiles.map(file => file.rel), prepared.verifierKind)) : undefined;
|
|
779
724
|
const generated = {
|
|
780
725
|
[`prompts/${taskId}.md`]: `${prepared.promptText.trimEnd()}\n`,
|
|
781
726
|
[`prompts/${taskId}.trigger.md`]: `${prepared.promptText.trimEnd()}\n\nThe repository is in your current working directory.\n`,
|
|
782
727
|
[`verifiers/${taskId}.mjs`]: prepared.verifierSource,
|
|
783
728
|
[`ground-truth/${taskId}.md`]: prepared.groundTruth,
|
|
784
729
|
};
|
|
785
|
-
if (prepared.oracleSource) {
|
|
786
|
-
generated[`ground-truth/oracle-${taskId}.mjs`] = prepared.oracleSource;
|
|
730
|
+
if (prepared.oracleSource || options.decompose) {
|
|
731
|
+
generated[`ground-truth/oracle-${taskId}.mjs`] = prepared.oracleSource ?? '';
|
|
787
732
|
}
|
|
788
733
|
const taskEntry = {
|
|
789
734
|
id: taskId,
|
|
@@ -792,11 +737,29 @@ export async function runBenchAdd(options) {
|
|
|
792
737
|
promptTrigger: `prompts/${taskId}.trigger.md`,
|
|
793
738
|
verifier: `node verifiers/${taskId}.mjs`,
|
|
794
739
|
verifierKind: prepared.verifierKind,
|
|
740
|
+
...timeout,
|
|
795
741
|
rubric: `ground-truth/${taskId}.md`,
|
|
796
|
-
...(prepared.oracleSource ? { oracle: `node ground-truth/oracle-${taskId}.mjs` } : {}),
|
|
742
|
+
...(prepared.oracleSource || options.decompose ? { oracle: `node ground-truth/oracle-${taskId}.mjs` } : {}),
|
|
797
743
|
...(options.oracle ? { oracle: options.oracle } : {}),
|
|
798
744
|
...(options.shouldTrigger !== undefined ? { shouldTrigger: options.shouldTrigger } : {}),
|
|
799
745
|
};
|
|
746
|
+
const targets = [...prepared.fixtureFiles.map(file => join(benchDir, 'fixtures', taskId, file.rel)),
|
|
747
|
+
...Object.keys(generated).map(rel => join(benchDir, rel)), benchJsonPath];
|
|
748
|
+
assertBenchWrites(benchDir, targets);
|
|
749
|
+
if (sha256File(benchJsonPath) !== sha256Text(originalManifest))
|
|
750
|
+
throw new Error('Bench manifest changed while preparing the task; nothing was written.');
|
|
751
|
+
const writeState = () => targets.flatMap(target => [target, target + BACKUP_SUFFIX]).map(path => existsSync(path) ? sha256File(path) : null);
|
|
752
|
+
const expectedWrites = JSON.stringify(writeState());
|
|
753
|
+
const assertOutputsUnchanged = () => {
|
|
754
|
+
assertBenchWrites(benchDir, targets);
|
|
755
|
+
if (JSON.stringify(writeState()) !== expectedWrites)
|
|
756
|
+
throw new Error('Bench outputs changed while preparing the task; nothing was written. Review a fresh plan.');
|
|
757
|
+
};
|
|
758
|
+
if (draft) {
|
|
759
|
+
log(`Draft plan: 1 call; ceiling ${draft.plan.maxCalls}; executor deadline ${draft.plan.executorTimeoutSeconds}s; no automatic retry.`);
|
|
760
|
+
log(`Draft records: ${draft.dir}`);
|
|
761
|
+
log(`Spending limits: ${draft.plan.spendingBudget ? JSON.stringify(draft.plan.spendingBudget) : 'not set; token/cache usage may remain unknown'}. Authentication: unknown offline.`);
|
|
762
|
+
}
|
|
800
763
|
if (options.verifierCmd) {
|
|
801
764
|
// The string is not used once and discarded: it is written into a generated .mjs and re-executed
|
|
802
765
|
// with a shell on every later `bench check` and `eval`. Disclose it before writing, in both the
|
|
@@ -818,38 +781,57 @@ export async function runBenchAdd(options) {
|
|
|
818
781
|
}
|
|
819
782
|
if (!options.yes) {
|
|
820
783
|
const confirm = options.confirm ?? confirmPrompt;
|
|
821
|
-
const ok = await confirm(
|
|
784
|
+
const ok = await confirm(`${draft ? 'Authorize 1 drafting call, retain its costs, then ' : ''}Add ${prepared.fixtureFiles.length} fixture file(s) + ${Object.keys(generated).length} generated file(s) into ${benchDir}? [y/N] `);
|
|
822
785
|
if (!ok) {
|
|
823
786
|
log('Aborted — nothing was written.');
|
|
824
787
|
return null;
|
|
825
788
|
}
|
|
826
789
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
790
|
+
let failure;
|
|
791
|
+
try {
|
|
792
|
+
throwIfEvaluationInterrupted();
|
|
793
|
+
assertOutputsUnchanged();
|
|
794
|
+
if (draft) {
|
|
795
|
+
const drafted = await draftVerifierWithOracle(draft, log);
|
|
796
|
+
generated[`verifiers/${taskId}.mjs`] = drafted.verifierSource;
|
|
797
|
+
generated[`ground-truth/oracle-${taskId}.mjs`] = drafted.oracleSource;
|
|
798
|
+
}
|
|
799
|
+
const writes = [];
|
|
800
|
+
for (const file of prepared.fixtureFiles) {
|
|
801
|
+
if (file.rel.split(/[\\/]/).includes('..') || isAbsolute(file.rel)) {
|
|
802
|
+
throw new Error(`Fixture path escapes the task directory: ${file.rel}`);
|
|
803
|
+
}
|
|
804
|
+
writes.push({ target: join(benchDir, 'fixtures', taskId, file.rel), content: file.content });
|
|
805
|
+
}
|
|
806
|
+
for (const [rel, content] of Object.entries(generated)) {
|
|
807
|
+
writes.push({ target: join(benchDir, rel), content });
|
|
831
808
|
}
|
|
832
|
-
|
|
809
|
+
benchJson.tasks = [...tasks, taskEntry];
|
|
810
|
+
writes.push({ target: benchJsonPath, content: `${JSON.stringify(benchJson, null, 2)}\n` });
|
|
811
|
+
throwIfEvaluationInterrupted();
|
|
812
|
+
assertOutputsUnchanged();
|
|
813
|
+
applyBenchWrites(benchDir, writes);
|
|
814
|
+
log(`Task "${taskId}" added to ${benchDir} (${prepared.fixtureFiles.length} fixture file(s), verifier: ${prepared.verifierKind}).`);
|
|
815
|
+
log('Next:');
|
|
816
|
+
log(` skillfit bench check ${benchDir}`);
|
|
817
|
+
log(` skillfit eval <skill-path> --bench ${benchDir} --agent <id> --trials 5`);
|
|
818
|
+
return {
|
|
819
|
+
dir: benchDir,
|
|
820
|
+
taskId,
|
|
821
|
+
files: [
|
|
822
|
+
...prepared.fixtureFiles.map((file) => `fixtures/${taskId}/${file.rel}`),
|
|
823
|
+
...Object.keys(generated),
|
|
824
|
+
'bench.json',
|
|
825
|
+
],
|
|
826
|
+
};
|
|
833
827
|
}
|
|
834
|
-
|
|
835
|
-
|
|
828
|
+
catch (error) {
|
|
829
|
+
failure = error;
|
|
830
|
+
throw error;
|
|
831
|
+
}
|
|
832
|
+
finally {
|
|
833
|
+
draft?.finish(failure);
|
|
836
834
|
}
|
|
837
|
-
benchJson.tasks = [...tasks, taskEntry];
|
|
838
|
-
writes.push({ target: benchJsonPath, content: `${JSON.stringify(benchJson, null, 2)}\n` });
|
|
839
|
-
applyBenchWrites(benchDir, writes);
|
|
840
|
-
log(`Task "${taskId}" added to ${benchDir} (${prepared.fixtureFiles.length} fixture file(s), verifier: ${prepared.verifierKind}).`);
|
|
841
|
-
log('Next:');
|
|
842
|
-
log(` skillfit bench check ${benchDir}`);
|
|
843
|
-
log(` skillfit eval <skill-path> --bench ${benchDir} --agent <id> --trials 5`);
|
|
844
|
-
return {
|
|
845
|
-
dir: benchDir,
|
|
846
|
-
taskId,
|
|
847
|
-
files: [
|
|
848
|
-
...prepared.fixtureFiles.map((file) => `fixtures/${taskId}/${file.rel}`),
|
|
849
|
-
...Object.keys(generated),
|
|
850
|
-
'bench.json',
|
|
851
|
-
],
|
|
852
|
-
};
|
|
853
835
|
}
|
|
854
836
|
function prepareFreeze(options, cwd) {
|
|
855
837
|
const promptText = options.prompt ??
|
|
@@ -874,7 +856,7 @@ function prepareFreeze(options, cwd) {
|
|
|
874
856
|
if (!existsSync(sourceDir)) {
|
|
875
857
|
throw new Error(`--source-dir does not exist: ${sourceDir}`);
|
|
876
858
|
}
|
|
877
|
-
const captured =
|
|
859
|
+
const captured = freezeSourceFiles(sourceDir, resolve(cwd, options.benchDir ?? '.'), options.include);
|
|
878
860
|
if (captured.length === 0) {
|
|
879
861
|
throw new Error(`No capturable files in ${sourceDir} (empty git index or directory).`);
|
|
880
862
|
}
|
|
@@ -891,7 +873,7 @@ function prepareFreeze(options, cwd) {
|
|
|
891
873
|
: options.verifierCmd
|
|
892
874
|
? 'command'
|
|
893
875
|
: 'output',
|
|
894
|
-
fixtureFiles: captured
|
|
876
|
+
fixtureFiles: captured,
|
|
895
877
|
groundTruth: `# Ground truth — frozen task
|
|
896
878
|
|
|
897
879
|
Frozen from a real failure on ${new Date().toISOString().slice(0, 10)}.
|