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.
- package/README.md +18 -6
- package/README.zh-CN.md +18 -6
- package/benches/README.md +2 -2
- package/dist/cli.js +132 -28
- package/dist/cli.test.js +94 -0
- package/dist/commands/bench-calibration.js +197 -0
- package/dist/commands/bench-calibration.test.js +237 -0
- package/dist/commands/bench-check-json.test.js +24 -3
- package/dist/commands/bench.js +63 -143
- package/dist/commands/calibration-cli.test.js +145 -0
- package/dist/commands/eval-agent-preflight.test.js +245 -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-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 +106 -56
- package/dist/commands/evaluation-report.js +5 -0
- package/dist/commands/evaluation-report.test.js +243 -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 +180 -0
- package/dist/harness/bench.js +2 -1
- package/dist/harness/command.js +49 -0
- package/dist/harness/eval-audit.js +161 -16
- 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/executors/api.js +4 -3
- package/dist/harness/executors/api.test.js +18 -0
- package/dist/harness/experiment-session.js +18 -10
- package/dist/harness/experiment-session.test.js +8 -0
- 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 +40 -30
- package/dist/harness/runner.test.js +23 -0
- package/dist/harness/single-arm-audit.js +436 -0
- package/dist/harness/trigger.js +21 -3
- package/dist/harness/trigger.test.js +12 -0
- package/dist/harness/verifier-error.js +65 -0
- package/dist/harness/verifier.test.js +128 -0
- package/docs/bench-authoring.md +34 -9
- package/docs/bench-check-json.md +28 -5
- package/docs/eval-agent-preflight.md +101 -0
- package/docs/eval-case-preflight.md +5 -0
- package/docs/eval-component.md +38 -10
- package/docs/eval-costs.md +44 -0
- package/docs/eval-planning.md +153 -0
- package/docs/evaluation-input-snapshots.md +2 -1
- 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 +50 -3
- package/docs/growth-roadmap-2026-10.md +41 -9
- package/docs/metrics.md +40 -3
- package/docs/plans/2026-10-17-workflow-foundations.md +64 -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-feature-smoke.mjs +224 -0
- package/docs/releases/0.11.0.md +47 -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 +99 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +41 -8
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { runBenchInit } from './bench.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { killTree } from '../harness/kill-tree.js';
|
|
11
|
+
import { packageFiles } from '../harness/replay-package.js';
|
|
12
|
+
import { sha256File } from '../harness/hash.js';
|
|
13
|
+
const cli = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
14
|
+
const pause = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
|
|
16
|
+
function running(pid) {
|
|
17
|
+
try {
|
|
18
|
+
process.kill(pid, 0);
|
|
19
|
+
if (process.platform === 'linux' && readFileSync(`/proc/${pid}/stat`, 'utf8').split(')').at(-1).trim().startsWith('Z'))
|
|
20
|
+
return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function scenario(t, signal, repeat = false) {
|
|
28
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-replay-cancel-'));
|
|
29
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), run = join(root, 'runs/saved');
|
|
30
|
+
const ready = join(root, 'ready.json'), heartbeat = join(root, 'heartbeat');
|
|
31
|
+
let child;
|
|
32
|
+
t.after(async () => {
|
|
33
|
+
if (child?.exitCode === null && child.signalCode === null)
|
|
34
|
+
killTree(child);
|
|
35
|
+
if (existsSync(ready))
|
|
36
|
+
for (const pid of json(ready).pids)
|
|
37
|
+
if (running(pid)) {
|
|
38
|
+
try {
|
|
39
|
+
process.kill(pid, 'SIGKILL');
|
|
40
|
+
}
|
|
41
|
+
catch { /* Already stopped. */ }
|
|
42
|
+
}
|
|
43
|
+
await pause(100);
|
|
44
|
+
rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
45
|
+
});
|
|
46
|
+
await runBenchInit({ dir: bench, yes: true, log: () => { } });
|
|
47
|
+
mkdirSync(skill);
|
|
48
|
+
writeFileSync(join(skill, 'SKILL.md'), '# Offline cancellation fixture\n');
|
|
49
|
+
const leaf = join(root, 'leaf.mjs');
|
|
50
|
+
writeFileSync(leaf, `import{appendFileSync}from'node:fs';process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});setInterval(()=>appendFileSync(${JSON.stringify(heartbeat)},'x'),30);setTimeout(()=>process.exit(),30000);`);
|
|
51
|
+
writeFileSync(join(bench, 'verifiers/example-task.mjs'), `import{spawn}from'node:child_process';import{existsSync,readFileSync,writeFileSync}from'node:fs';import{join}from'node:path';
|
|
52
|
+
if(process.env.SKILLFIT_OFFLINE_REPLAY_BLOCK==='yes'){
|
|
53
|
+
process.on('SIGINT',()=>{});process.on('SIGTERM',()=>{});
|
|
54
|
+
const leaf=spawn(process.execPath,[${JSON.stringify(leaf)}],{stdio:'ignore'});
|
|
55
|
+
const timer=setInterval(()=>{if(existsSync(${JSON.stringify(heartbeat)})){clearInterval(timer);writeFileSync(${JSON.stringify(ready)},JSON.stringify({pids:[process.pid,leaf.pid]}));}},20);
|
|
56
|
+
setTimeout(()=>process.exit(),30000);
|
|
57
|
+
}else{const out=join(process.argv[2],'_output.md');process.exit(existsSync(out)&&readFileSync(out,'utf8').trim()==='skillfit-ok'?0:1);}`);
|
|
58
|
+
let fakeCalls = 0;
|
|
59
|
+
await runEval({ skillPath: skill, bench, trials: 1, maxCalls: 2, runsRoot: join(root, 'runs'), runGroup: 'saved',
|
|
60
|
+
dryRun: false, yes: true, judgeExecutor: null, log: () => { }, executor: {
|
|
61
|
+
describe: () => ({ kind: 'stub', model: 'offline-only' }), run: async () => { fakeCalls++; return { output: 'skillfit-ok', tokens: { input: 10, cachedInput: 2, output: 3 } }; },
|
|
62
|
+
} });
|
|
63
|
+
assert.equal(fakeCalls, 2);
|
|
64
|
+
const evidence = packageFiles(run).map(path => [path, sha256File(join(run, path))]);
|
|
65
|
+
const harness = join(root, 'replay-harness.mjs');
|
|
66
|
+
writeFileSync(harness, `process.on('message',message=>{process.emit(message.signal);if(message.repeat){process.emit(message.signal);process.emit('SIGTERM');}});
|
|
67
|
+
process.argv=[process.execPath,${JSON.stringify(cli)},'report','eval',${JSON.stringify(run)},'--json','--replay'];
|
|
68
|
+
await import(${JSON.stringify(pathToFileURL(cli).href)});
|
|
69
|
+
const timer=setInterval(()=>{if(process.exitCode!==undefined&&process.listenerCount('SIGINT')===0){clearInterval(timer);process.disconnect();}},20);`);
|
|
70
|
+
child = spawn(process.execPath, [harness], { env: { ...process.env, SKILLFIT_OFFLINE_REPLAY_BLOCK: 'yes' }, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
|
|
71
|
+
let stdout = '', stderr = '';
|
|
72
|
+
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
73
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
74
|
+
const closed = new Promise(resolve => child.once('close', (code, signal) => resolve({ code, signal })));
|
|
75
|
+
for (let i = 0; i < 200 && !existsSync(ready) && child.exitCode === null; i++)
|
|
76
|
+
await pause(50);
|
|
77
|
+
assert.ok(existsSync(ready), `Offline replay verifier did not start: ${stderr}`);
|
|
78
|
+
// Windows kill('SIGINT') terminates forcibly; IPC emits the same JS console event
|
|
79
|
+
// while taskkill /T remains the real process-tree cancellation implementation.
|
|
80
|
+
if (process.platform === 'win32' || repeat)
|
|
81
|
+
child.send({ signal, repeat });
|
|
82
|
+
else
|
|
83
|
+
child.kill(signal);
|
|
84
|
+
let timeout;
|
|
85
|
+
const exit = await Promise.race([closed, new Promise((_, reject) => { timeout = setTimeout(() => reject(new Error(`Replay did not stop: ${stderr}`)), 10_000); })]).finally(() => clearTimeout(timeout));
|
|
86
|
+
assert.deepEqual(exit, { code: signal === 'SIGINT' ? 130 : 143, signal: null }, stderr);
|
|
87
|
+
const result = JSON.parse(stdout);
|
|
88
|
+
assert.equal(result.kind, 'skillfit.eval-error');
|
|
89
|
+
assert.match(result.error.message, new RegExp(signal));
|
|
90
|
+
for (let i = 0; i < 100 && json(ready).pids.some(running); i++)
|
|
91
|
+
await pause(50);
|
|
92
|
+
assert.ok(json(ready).pids.every((pid) => !running(pid)), 'Replay verifier and its grandchild must stop.');
|
|
93
|
+
const finalHeartbeat = readFileSync(heartbeat, 'utf8');
|
|
94
|
+
await pause(100);
|
|
95
|
+
assert.equal(readFileSync(heartbeat, 'utf8'), finalHeartbeat);
|
|
96
|
+
assert.deepEqual(packageFiles(run).map(path => [path, sha256File(join(run, path))]), evidence, 'Read-only replay cancellation must leave native evidence unchanged.');
|
|
97
|
+
assert.equal(fakeCalls, 2, 'Replay adds no executor observations.');
|
|
98
|
+
}
|
|
99
|
+
for (const signal of ['SIGINT', 'SIGTERM'])
|
|
100
|
+
test(`${signal} cancels saved delivery replay, kills verifier descendants and emits one JSON document`, { timeout: 30_000 }, async (t) => {
|
|
101
|
+
await scenario(t, signal);
|
|
102
|
+
});
|
|
103
|
+
test('repeated replay interrupts preserve the first exit code and clean up without changing receipts', { timeout: 30_000 }, async (t) => {
|
|
104
|
+
await scenario(t, 'SIGINT', true);
|
|
105
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import { AgentPreflightFailed } from '../harness/agent-preflight.js';
|
|
9
|
+
import { runEval } from './eval.js';
|
|
10
|
+
import { runEvalCli } from './eval-cli.js';
|
|
11
|
+
const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
12
|
+
function fixture(t) {
|
|
13
|
+
const root = mkdtempSync(join(tmpdir(), 'skillfit-workflow-'));
|
|
14
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
const bench = join(root, 'bench'), skill = join(root, 'skill'), home = join(root, 'home');
|
|
16
|
+
for (const dir of [join(bench, 'fixture'), join(skill, 'resources'), home])
|
|
17
|
+
mkdirSync(dir, { recursive: true });
|
|
18
|
+
writeFileSync(join(skill, 'SKILL.md'), '---\nname: workflow-skill\ndescription: Return the correct answer.\n---\nReturn OK.\n');
|
|
19
|
+
writeFileSync(join(skill, 'resources', 'image.bin'), Buffer.from([0, 1, 2, 3]));
|
|
20
|
+
writeFileSync(join(bench, 'fixture', 'input.txt'), 'input\n');
|
|
21
|
+
writeFileSync(join(bench, 'prompt.md'), 'Return OK.');
|
|
22
|
+
writeFileSync(join(bench, 'verify.mjs'), "import{readFileSync,existsSync}from'node:fs';import{join}from'node:path';const p=join(process.argv[2],'_output.md');const passed=existsSync(p)&&readFileSync(p,'utf8').trim()==='OK';console.log(JSON.stringify({passed,checks:[{name:'correct',pass:passed},{name:'complete',pass:passed}]}));process.exit(passed?0:1);");
|
|
23
|
+
writeFileSync(join(bench, 'oracle.mjs'), "import{writeFileSync}from'node:fs';import{join}from'node:path';writeFileSync(join(process.argv[2],'_output.md'),'OK');");
|
|
24
|
+
writeFileSync(join(bench, 'bench.json'), JSON.stringify({ schemaVersion: 1, name: 'workflow', tasks: [true, false].map((shouldTrigger, i) => ({
|
|
25
|
+
id: `task-${i + 1}`, fixture: 'fixture', prompt: 'prompt.md', verifier: 'node verify.mjs', oracle: 'node oracle.mjs', shouldTrigger,
|
|
26
|
+
})) }));
|
|
27
|
+
let calls = 0;
|
|
28
|
+
const base = { skillPath: skill, bench, mode: 'trigger', agent: 'codex', trials: 1, maxCalls: 2,
|
|
29
|
+
dryRun: false, yes: true, runsRoot: join(root, 'runs'), runGroup: 'trigger', log: () => { },
|
|
30
|
+
sessionOptions: { homeDir: home, env: { ...process.env, CODEX_HOME: join(home, 'profile') }, versionProbe: () => null },
|
|
31
|
+
executor: { describe: () => ({ kind: 'cli', model: 'offline-injected', sampling: null }), run: async () => {
|
|
32
|
+
calls++;
|
|
33
|
+
return { output: 'OK', skillTriggered: true, tokens: { input: 10, cachedInput: 4, output: 2 } };
|
|
34
|
+
} } };
|
|
35
|
+
const limits = { input: 10000, cachedInput: 10000, uncachedInput: 10000, output: 10000, durationSeconds: 10000 };
|
|
36
|
+
return { root, skill, bench, home, base, limits, calls: () => calls };
|
|
37
|
+
}
|
|
38
|
+
test('trigger shares reviewed JSON plans, configurable stop lines and sealed reports without paired adoption', async (t) => {
|
|
39
|
+
const f = fixture(t), base = { ...f.base, executorTimeoutSeconds: 19, spendingBudget: f.limits };
|
|
40
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
41
|
+
assert.equal(preview.plan.evaluation.mode, 'trigger');
|
|
42
|
+
assert.equal(preview.plan.evaluation.plannedCalls, 2);
|
|
43
|
+
assert.equal(preview.plan.evaluation.executorTimeoutSeconds, 19);
|
|
44
|
+
assert.deepEqual(preview.plan.evaluation.spendingBudget, f.limits);
|
|
45
|
+
assert.equal(f.calls(), 0);
|
|
46
|
+
assert.equal(existsSync(base.runsRoot), false);
|
|
47
|
+
const result = await runEvalCli(base, preview.plan.sha256);
|
|
48
|
+
assert.ok('evaluationType' in result && result.evaluationType === 'trigger');
|
|
49
|
+
assert.equal(result.status, 'completed');
|
|
50
|
+
assert.equal(result.evidence.verified, true, result.evidence.reasons.join('; '));
|
|
51
|
+
assert.equal(result.usage?.runs, 2);
|
|
52
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 20);
|
|
53
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
54
|
+
assert.equal(result.acceptance.automaticUpgrade, false);
|
|
55
|
+
const plan = JSON.parse(readFileSync(join(base.runsRoot, base.runGroup, '_plan.json'), 'utf8'));
|
|
56
|
+
assert.deepEqual(plan.details.reviewedPlan, preview.plan);
|
|
57
|
+
assert.equal(plan.details.executorTimeoutSeconds, 19);
|
|
58
|
+
assert.equal(f.calls(), 2);
|
|
59
|
+
});
|
|
60
|
+
test('trigger token stop lines retain the paid prefix and never dispatch the next task', async (t) => {
|
|
61
|
+
const f = fixture(t), base = { ...f.base, spendingBudget: { ...f.limits, input: 5 } };
|
|
62
|
+
const preview = await runEvalCli({ ...base, dryRun: true }), result = await runEvalCli(base, preview.plan.sha256);
|
|
63
|
+
assert.ok('evaluationType' in result && result.evaluationType === 'trigger');
|
|
64
|
+
assert.equal(result.status, 'stopped');
|
|
65
|
+
assert.equal(f.calls(), 1);
|
|
66
|
+
assert.equal(result.usage?.runs, 1);
|
|
67
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 10);
|
|
68
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
69
|
+
assert.match(result.session?.stopReason ?? '', /SPENDING_BUDGET_REACHED/);
|
|
70
|
+
assert.equal(existsSync(join(base.runsRoot, base.runGroup, 'task-2', 'installed', 'trial-1')), false);
|
|
71
|
+
});
|
|
72
|
+
test('trigger missing final cache coverage stops rather than assuming a zero cache bill', async (t) => {
|
|
73
|
+
const f = fixture(t);
|
|
74
|
+
let calls = 0;
|
|
75
|
+
const base = { ...f.base, spendingBudget: f.limits, executor: { describe: () => ({ kind: 'cli', model: 'offline-missing-cache' }), run: async () => {
|
|
76
|
+
calls++;
|
|
77
|
+
return { output: 'OK', skillTriggered: true, tokens: { input: 10, output: 2 } };
|
|
78
|
+
} } };
|
|
79
|
+
const preview = await runEvalCli({ ...base, dryRun: true }), result = await runEvalCli(base, preview.plan.sha256);
|
|
80
|
+
assert.ok('evaluationType' in result);
|
|
81
|
+
assert.equal(result.status, 'stopped');
|
|
82
|
+
assert.equal(calls, 1);
|
|
83
|
+
assert.equal(result.usage?.metrics.cachedInput.coverage.unknown, 1);
|
|
84
|
+
assert.equal(result.usage?.metrics.input.knownTotal, 10);
|
|
85
|
+
assert.match(result.session?.stopReason ?? '', /FINAL_USAGE_MISSING/);
|
|
86
|
+
});
|
|
87
|
+
test('trigger plan confirmation pins binary Skill resources and spending settings before any dispatch', async (t) => {
|
|
88
|
+
const f = fixture(t), preview = await runEvalCli({ ...f.base, dryRun: true });
|
|
89
|
+
assert.ok(preview.plan.evaluation.installedFingerprint?.files.includes('resources/image.bin'));
|
|
90
|
+
writeFileSync(join(f.skill, 'resources', 'image.bin'), Buffer.from([8, 9]));
|
|
91
|
+
await assert.rejects(runEvalCli(f.base, preview.plan.sha256), /--plan-sha/);
|
|
92
|
+
assert.equal(f.calls(), 0);
|
|
93
|
+
assert.equal(existsSync(f.base.runsRoot), false);
|
|
94
|
+
const updated = await runEvalCli({ ...f.base, dryRun: true });
|
|
95
|
+
await assert.rejects(runEvalCli({ ...f.base, spendingBudget: f.limits }, updated.plan.sha256), /--plan-sha/);
|
|
96
|
+
assert.equal(f.calls(), 0);
|
|
97
|
+
});
|
|
98
|
+
test('public trigger JSON previews work without an installed agent and live missing-CLI failures remain structured', t => {
|
|
99
|
+
const f = fixture(t), env = { ...process.env, HOME: f.home, USERPROFILE: f.home, CODEX_HOME: join(f.home, 'profile'), SKILLFIT_JUDGE: '0' };
|
|
100
|
+
for (const key of Object.keys(env))
|
|
101
|
+
if (key.toLowerCase() === 'path')
|
|
102
|
+
delete env[key];
|
|
103
|
+
const isolated = { ...env, PATH: '' };
|
|
104
|
+
const args = ['eval', f.skill, '--bench', f.bench, '--mode', 'trigger', '--agent', 'codex', '--trials', '1', '--max-calls', '2', '--run-group', 'public-trigger', '--runs-root', join(f.root, 'runs'), '--json'];
|
|
105
|
+
const preview = spawnSync(process.execPath, [CLI, ...args, '--dry-run'], { encoding: 'utf8', env: isolated });
|
|
106
|
+
assert.equal(preview.status, 0, preview.stderr);
|
|
107
|
+
const planned = JSON.parse(preview.stdout);
|
|
108
|
+
assert.equal(planned.plan.evaluation.mode, 'trigger');
|
|
109
|
+
assert.equal(planned.plan.evaluation.agentPreflight.status, 'blocked');
|
|
110
|
+
const live = spawnSync(process.execPath, [CLI, ...args, '--plan-sha', planned.plan.sha256], { encoding: 'utf8', env: isolated });
|
|
111
|
+
assert.equal(live.status, 2, live.stderr);
|
|
112
|
+
const error = JSON.parse(live.stdout);
|
|
113
|
+
assert.equal(error.error.code, 'AGENT_PREFLIGHT_FAILED');
|
|
114
|
+
assert.equal(existsSync(join(f.root, 'runs')), false);
|
|
115
|
+
});
|
|
116
|
+
test('an explicitly enabled API judge without credentials blocks rather than silently running without judging', async (t) => {
|
|
117
|
+
const f = fixture(t), names = ['SKILLFIT_JUDGE', 'SKILLFIT_JUDGE_API_KEY', 'SKILLFIT_API_KEY', 'OPENAI_API_KEY'];
|
|
118
|
+
const previous = names.map(name => process.env[name]);
|
|
119
|
+
try {
|
|
120
|
+
for (const name of names)
|
|
121
|
+
delete process.env[name];
|
|
122
|
+
process.env['SKILLFIT_JUDGE'] = '1';
|
|
123
|
+
const base = { ...f.base, mode: 'inject', maxCalls: 4 };
|
|
124
|
+
const preview = await runEvalCli({ ...base, dryRun: true });
|
|
125
|
+
assert.equal(preview.plan.evaluation.agentPreflight.status, 'blocked');
|
|
126
|
+
assert.ok(preview.plan.evaluation.agentPreflight.checks.some(check => check.role === 'judge' && check.status === 'FAIL'));
|
|
127
|
+
await assert.rejects(runEval(base), AgentPreflightFailed);
|
|
128
|
+
assert.equal(f.calls(), 0);
|
|
129
|
+
assert.equal(existsSync(base.runsRoot), false);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
names.forEach((name, i) => { if (previous[i] === undefined)
|
|
133
|
+
delete process.env[name];
|
|
134
|
+
else
|
|
135
|
+
process.env[name] = previous[i]; });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { accessSync, constants, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { isAbsolute, join, resolve, win32 } from 'node:path';
|
|
4
|
+
import { loadMatrix, skillUserDirSpecs } from '../agents.js';
|
|
5
|
+
import { parseFrontmatter } from '../frontmatter.js';
|
|
6
|
+
/** Read PATH only; never run which/where, an agent, a login command or an API. */
|
|
7
|
+
export function findExecutable(binary, env = process.env, platform = process.platform) {
|
|
8
|
+
const windows = platform === 'win32';
|
|
9
|
+
// Match Node's first lexicographically sorted key when Windows env keys repeat by case.
|
|
10
|
+
const entries = Object.entries(env).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
11
|
+
const value = (key) => entries.find(([name]) => windows ? name.toLowerCase() === key.toLowerCase() : name === key)?.[1];
|
|
12
|
+
const path = value('PATH') ?? '';
|
|
13
|
+
const hasPath = /[\\/]/.test(binary) || isAbsolute(binary) || (windows && win32.isAbsolute(binary));
|
|
14
|
+
const directories = hasPath ? [''] : path.split(windows ? ';' : ':').map(dir => dir.replace(/^"(.*)"$/, '$1'))
|
|
15
|
+
.filter(dir => isAbsolute(dir) || (windows && win32.isAbsolute(dir)));
|
|
16
|
+
const extensions = windows ? (value('PATHEXT') ?? '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean) : [];
|
|
17
|
+
const names = windows && !extensions.some(ext => binary.toLowerCase().endsWith(ext.toLowerCase()))
|
|
18
|
+
? extensions.map(ext => binary + ext) : [binary];
|
|
19
|
+
for (const dir of directories)
|
|
20
|
+
for (const name of names) {
|
|
21
|
+
const file = resolve(dir.replace(/^"(.*)"$/, '$1'), name);
|
|
22
|
+
try {
|
|
23
|
+
if (!statSync(file).isFile())
|
|
24
|
+
continue;
|
|
25
|
+
accessSync(file, windows ? constants.F_OK : constants.X_OK);
|
|
26
|
+
return realpathSync(file);
|
|
27
|
+
}
|
|
28
|
+
catch { /* Continue searching; config directories are not executable evidence. */ }
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export function globalSkillRoots(agent, home, env) {
|
|
33
|
+
return [...new Set([...skillUserDirSpecs(agent, env), ...agent.skills.sharedDirs.filter(path => path.startsWith('~/'))]
|
|
34
|
+
.map(path => path.startsWith('~/') ? join(home, path.slice(2)) : resolve(path)))];
|
|
35
|
+
}
|
|
36
|
+
function report(checks) {
|
|
37
|
+
const matrix = loadMatrix(), count = (status) => checks.filter(check => check.status === status).length;
|
|
38
|
+
return { schemaVersion: 1, kind: 'skillfit.agent-preflight', scope: 'offline-agent-environment',
|
|
39
|
+
status: count('FAIL') ? 'blocked' : 'ready', matrix: { schemaVersion: matrix.schemaVersion, verifiedAt: matrix.verifiedAt }, checks,
|
|
40
|
+
summary: { failures: count('FAIL'), passed: count('PASS'), unknown: count('UNKNOWN'), info: count('INFO') },
|
|
41
|
+
cost: { modelCalls: 0, cliInvocations: 0 } };
|
|
42
|
+
}
|
|
43
|
+
export function inspectAgentEnvironment(options) {
|
|
44
|
+
const checks = [], env = options.env ?? process.env;
|
|
45
|
+
const home = options.homeDir ?? homedir();
|
|
46
|
+
const names = new Set([options.target.name]);
|
|
47
|
+
if (options.target.kind === 'skill') {
|
|
48
|
+
try {
|
|
49
|
+
const name = parseFrontmatter(readFileSync(join(options.target.sourceDir, 'SKILL.md'), 'utf8'))?.name?.trim();
|
|
50
|
+
if (name)
|
|
51
|
+
names.add(name);
|
|
52
|
+
}
|
|
53
|
+
catch { /* Some legacy injectable bundles have no root SKILL.md. */ }
|
|
54
|
+
}
|
|
55
|
+
for (const role of options.roles) {
|
|
56
|
+
const agent = role.definition;
|
|
57
|
+
const add = (code, status, message, remediation = null, paths = []) => checks.push({ code, status, message, remediation, paths, role: role.role, agent: agent?.id ?? null });
|
|
58
|
+
const streamed = role.role === 'agent' && (options.mode === 'trigger' || (options.mode === 'installed' && agent?.headless.streamJson));
|
|
59
|
+
const argv = streamed ? agent?.headless.streamJson?.argv : agent?.headless.argv;
|
|
60
|
+
const binary = argv?.[0] ?? agent?.headless.argv[0] ?? agent?.detect.binaries[0];
|
|
61
|
+
if (role.injected)
|
|
62
|
+
add('EXECUTOR_INJECTED', 'UNKNOWN', 'Injected executor: installed CLI availability and runtime capabilities are not attested.');
|
|
63
|
+
else if (agent && binary) {
|
|
64
|
+
const path = findExecutable(binary, env);
|
|
65
|
+
add('CLI_AVAILABLE', path ? 'PASS' : 'FAIL', path ? `CLI executable is available: ${binary}.` : `CLI executable is missing or not executable on PATH: ${binary}.`, path ? null : 'Install the selected agent CLI or fix PATH, then create a fresh preview.', path ? [path] : []);
|
|
66
|
+
}
|
|
67
|
+
else if (!agent && role.executor?.kind === 'api')
|
|
68
|
+
add('CLI_AVAILABLE', 'INFO', 'API executor: no local agent CLI is required.');
|
|
69
|
+
let error = (role.role === 'agent' ? options.capabilityError : undefined) ?? role.resolutionError;
|
|
70
|
+
if (agent && !argv?.[0])
|
|
71
|
+
error ??= options.mode === 'trigger' && role.role === 'agent'
|
|
72
|
+
? `Agent "${agent.id}" has no headless streamJson command template; trigger detection is unavailable for it.`
|
|
73
|
+
: `Agent "${agent.id}" has no usable headless command template.`;
|
|
74
|
+
if (agent && role.role === 'agent' && ['installed', 'trigger'].includes(options.mode) && !agent.skills.projectDirs.length) {
|
|
75
|
+
error ??= `Agent "${agent.id}" has no matrix-defined project Skill directory for ${options.mode} mode.`;
|
|
76
|
+
}
|
|
77
|
+
if (!role.injected && !role.executor && !error)
|
|
78
|
+
error = 'No executor available; pass --agent or set SKILLFIT_API_KEY.';
|
|
79
|
+
add('MATRIX_CAPABILITY', error ? 'FAIL' : role.injected && !agent ? 'UNKNOWN' : 'PASS', error ??
|
|
80
|
+
(agent ? 'Declared matrix capabilities match this evaluation; installed CLI flag compatibility was not probed.' : 'Executor supports the declared evaluation surface.'), error ? 'Select a compatible agent/input/mode or correct its configuration, then create a fresh preview.' : null);
|
|
81
|
+
add('AUTHENTICATION', 'UNKNOWN', 'Login and credential validity cannot be confirmed offline; no authentication command, credential file or network probe was used.', 'Confirm authentication separately before authorizing a live run.');
|
|
82
|
+
if (role.role !== 'agent' || options.target.kind !== 'skill')
|
|
83
|
+
continue;
|
|
84
|
+
if (!agent || (role.injected && options.homeDir === undefined)) {
|
|
85
|
+
add('GLOBAL_SKILL_SCAN', 'UNKNOWN', 'Global Skill availability was not inspected for this injected/unconfigured executor.');
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const roots = globalSkillRoots(agent, home, env), conflicts = [], unreadable = [];
|
|
89
|
+
for (const root of roots) {
|
|
90
|
+
try {
|
|
91
|
+
for (const entry of readdirSync(root).sort()) {
|
|
92
|
+
const dir = join(root, entry), manifest = join(dir, 'SKILL.md');
|
|
93
|
+
try {
|
|
94
|
+
if (!statSync(manifest).isFile())
|
|
95
|
+
continue;
|
|
96
|
+
if (names.has(entry) || names.has(parseFrontmatter(readFileSync(manifest, 'utf8'))?.name?.trim() ?? ''))
|
|
97
|
+
conflicts.push(dir);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (!['ENOENT', 'ENOTDIR'].includes(String(error.code)))
|
|
101
|
+
unreadable.push(dir);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.code !== 'ENOENT')
|
|
107
|
+
unreadable.push(root);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
add('GLOBAL_SKILL_CONFLICT', conflicts.length ? 'FAIL' : 'PASS', conflicts.length
|
|
111
|
+
? 'Baseline contamination risk: a globally available Skill has the evaluated directory/frontmatter name; it may be loaded in baseline too.'
|
|
112
|
+
: 'No matching Skill was found among readable direct entries of matrix-listed user/global Skill roots.', conflicts.length ? 'Use a controlled agent profile without the conflicting Skill, then create a fresh preview. No global Skill was changed.' : null, conflicts);
|
|
113
|
+
add('GLOBAL_SKILL_SCAN', unreadable.length ? 'UNKNOWN' : 'INFO', unreadable.length
|
|
114
|
+
? 'Some global Skill entries could not be inspected; absence of contamination is not established.'
|
|
115
|
+
: 'Only matrix-listed user/global roots were inspected. Inherited project, plugin and unlisted Skill scopes remain uncontrolled.', null, unreadable.length ? unreadable : roots);
|
|
116
|
+
}
|
|
117
|
+
return report(checks);
|
|
118
|
+
}
|
|
119
|
+
export class AgentPreflightFailed extends Error {
|
|
120
|
+
agentPreflight;
|
|
121
|
+
constructor(agentPreflight) {
|
|
122
|
+
super('Agent environment preflight blocked evaluation; no agent or judge calls were made.\n' +
|
|
123
|
+
agentPreflight.checks.filter(check => check.status === 'FAIL').map(check => `[FAIL] ${check.role}/${check.code}: ${check.message}${check.paths.length ? ` Paths: ${check.paths.join(', ')}` : ''} ${check.remediation ?? ''}`).join('\n'));
|
|
124
|
+
this.agentPreflight = agentPreflight;
|
|
125
|
+
this.name = 'AgentPreflightFailed';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function assertAgentEnvironment(preflight) {
|
|
129
|
+
if (preflight.status === 'blocked')
|
|
130
|
+
throw new AgentPreflightFailed(preflight);
|
|
131
|
+
}
|
|
132
|
+
export function assertAgentEnvironmentUnchanged(before, after) {
|
|
133
|
+
assertAgentEnvironment(after);
|
|
134
|
+
if (JSON.stringify(before) !== JSON.stringify(after))
|
|
135
|
+
throw new AgentPreflightFailed(report([...after.checks, {
|
|
136
|
+
code: 'ENVIRONMENT_CHANGED', status: 'FAIL', role: 'agent', agent: null,
|
|
137
|
+
message: 'Agent environment changed during offline case preflight.', remediation: 'Create a fresh preview before execution.', paths: [],
|
|
138
|
+
}]));
|
|
139
|
+
}
|
|
140
|
+
export function renderAgentEnvironment(preflight) {
|
|
141
|
+
return [`Agent preflight: ${preflight.status} (offline; login remains unknown)`, ...preflight.checks.map(check => `[${check.status}] ${check.role}/${check.code}: ${check.message}${check.paths.length ? ` Paths: ${check.paths.join(', ')}` : ''}${check.remediation ? ` Remedy: ${check.remediation}` : ''}`)].join('\n');
|
|
142
|
+
}
|
|
143
|
+
/** Validate saved metadata without consulting today's machine or implying login. */
|
|
144
|
+
export function assertRecordedAgentEnvironment(value) {
|
|
145
|
+
const p = value;
|
|
146
|
+
if (!p || p.schemaVersion !== 1 || p.kind !== 'skillfit.agent-preflight' || p.scope !== 'offline-agent-environment' ||
|
|
147
|
+
p.status !== 'ready' || p.cost?.modelCalls !== 0 || p.cost?.cliInvocations !== 0 || !Array.isArray(p.checks) || !p.checks.length ||
|
|
148
|
+
!p.matrix || !Number.isSafeInteger(p.matrix.schemaVersion) || typeof p.matrix.verifiedAt !== 'string')
|
|
149
|
+
throw new Error('Invalid recorded Agent environment preflight.');
|
|
150
|
+
for (const check of p.checks) {
|
|
151
|
+
if (!check || !['PASS', 'UNKNOWN', 'INFO'].includes(check.status) || !['agent', 'judge'].includes(check.role) ||
|
|
152
|
+
typeof check.code !== 'string' || typeof check.message !== 'string' || !Array.isArray(check.paths) || check.paths.some(path => typeof path !== 'string') ||
|
|
153
|
+
(check.agent !== null && typeof check.agent !== 'string') || (check.remediation !== null && typeof check.remediation !== 'string') ||
|
|
154
|
+
(check.code === 'AUTHENTICATION' && (check.status !== 'UNKNOWN' || check.paths.length)))
|
|
155
|
+
throw new Error('Invalid recorded Agent environment check.');
|
|
156
|
+
}
|
|
157
|
+
if (!p.checks.some(check => check.role === 'agent' && check.code === 'AUTHENTICATION'))
|
|
158
|
+
throw new Error('Recorded Agent preflight has no primary agent.');
|
|
159
|
+
for (const role of new Set(p.checks.map(check => check.role)))
|
|
160
|
+
if (!p.checks.some(check => check.role === role && check.code === 'AUTHENTICATION' && check.status === 'UNKNOWN')) {
|
|
161
|
+
throw new Error('Recorded Agent preflight must retain unknown offline authentication.');
|
|
162
|
+
}
|
|
163
|
+
if (!p.summary || p.summary.failures !== 0 || p.summary.passed !== p.checks.filter(check => check.status === 'PASS').length ||
|
|
164
|
+
p.summary.unknown !== p.checks.filter(check => check.status === 'UNKNOWN').length || p.summary.info !== p.checks.filter(check => check.status === 'INFO').length) {
|
|
165
|
+
throw new Error('Recorded Agent preflight summary is inconsistent.');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Human reports omit local paths; JSON retains the original saved checks. */
|
|
169
|
+
export function agentEnvironmentReportLines(value) {
|
|
170
|
+
if (value == null)
|
|
171
|
+
return [];
|
|
172
|
+
try {
|
|
173
|
+
assertRecordedAgentEnvironment(value);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return ['Agent preflight: invalid/unverified saved metadata; inspect the JSON record.'];
|
|
177
|
+
}
|
|
178
|
+
return [`Agent preflight: ${value.status}; ${value.summary.unknown} unknown check(s); authentication remains unknown offline.`,
|
|
179
|
+
...value.checks.map(check => `[${check.status}] ${check.role}/${check.code}: ${check.message}`)];
|
|
180
|
+
}
|
package/dist/harness/bench.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { basename, isAbsolute, join, resolve, sep } from 'node:path';
|
|
3
3
|
import { hashFileSet, listFilesRecursive } from './hash.js';
|
|
4
|
+
import { parseCommand } from './command.js';
|
|
4
5
|
export const BENCH_SCHEMA_VERSION = 1;
|
|
5
6
|
const TASK_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
6
7
|
function assertRelativeInside(benchDir, rel, label) {
|
|
@@ -14,7 +15,7 @@ function assertRelativeInside(benchDir, rel, label) {
|
|
|
14
15
|
return abs;
|
|
15
16
|
}
|
|
16
17
|
function assertCommandTokensExist(benchDir, command, label) {
|
|
17
|
-
for (const token of command
|
|
18
|
+
for (const token of parseCommand(command)) {
|
|
18
19
|
if (!token.includes('/') && !token.includes('\\'))
|
|
19
20
|
continue;
|
|
20
21
|
const tokenAbs = assertRelativeInside(benchDir, token, label);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Tokenize a shell-free command. Quotes group arguments; no expansions run. */
|
|
2
|
+
export function parseCommand(command) {
|
|
3
|
+
const args = [];
|
|
4
|
+
let word = '', started = false, quote = null;
|
|
5
|
+
for (let i = 0; i < command.length; i++) {
|
|
6
|
+
const char = command[i];
|
|
7
|
+
if (char === '\0')
|
|
8
|
+
throw new Error('Command contains a NUL character.');
|
|
9
|
+
if (quote === "'") {
|
|
10
|
+
if (char === quote)
|
|
11
|
+
quote = null;
|
|
12
|
+
else
|
|
13
|
+
word += char;
|
|
14
|
+
}
|
|
15
|
+
else if (char === '\\' && i + 1 < command.length &&
|
|
16
|
+
(command[i + 1] === quote || (!quote && /[\s'"]/.test(command[i + 1])))) {
|
|
17
|
+
word += command[++i];
|
|
18
|
+
started = true;
|
|
19
|
+
}
|
|
20
|
+
else if (quote === '"') {
|
|
21
|
+
if (char === quote)
|
|
22
|
+
quote = null;
|
|
23
|
+
else
|
|
24
|
+
word += char;
|
|
25
|
+
}
|
|
26
|
+
else if (char === "'" || char === '"') {
|
|
27
|
+
quote = char;
|
|
28
|
+
started = true;
|
|
29
|
+
}
|
|
30
|
+
else if (/\s/.test(char)) {
|
|
31
|
+
if (started) {
|
|
32
|
+
args.push(word);
|
|
33
|
+
word = '';
|
|
34
|
+
started = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
word += char;
|
|
39
|
+
started = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (quote)
|
|
43
|
+
throw new Error('Command has an unterminated quote.');
|
|
44
|
+
if (started)
|
|
45
|
+
args.push(word);
|
|
46
|
+
if (!args[0])
|
|
47
|
+
throw new Error('Command requires a non-empty executable.');
|
|
48
|
+
return args;
|
|
49
|
+
}
|