skillfit 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -7
- package/README.zh-CN.md +27 -7
- package/benches/README.md +2 -2
- package/dist/cli.js +146 -36
- 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 +69 -141
- 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 +59 -28
- package/dist/commands/eval-export-modes.test.js +350 -0
- package/dist/commands/eval-export.js +44 -10
- package/dist/commands/eval-export.test.js +165 -8
- package/dist/commands/eval-interruption.test.js +238 -0
- package/dist/commands/eval-plan.js +37 -0
- package/dist/commands/eval-preflight.js +61 -0
- package/dist/commands/eval-preflight.test.js +382 -0
- package/dist/commands/eval-report.js +60 -14
- package/dist/commands/eval-report.test.js +2 -2
- 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 +184 -112
- 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 +164 -17
- package/dist/harness/eval-budget.js +46 -2
- package/dist/harness/eval-budget.test.js +30 -3
- package/dist/harness/eval-component.test.js +169 -6
- package/dist/harness/eval-contract.js +11 -5
- package/dist/harness/executors/api.js +14 -4
- package/dist/harness/executors/api.test.js +61 -0
- package/dist/harness/executors/cli.js +24 -3
- package/dist/harness/experiment-session.js +77 -18
- package/dist/harness/experiment-session.test.js +51 -1
- package/dist/harness/input-snapshot.js +150 -0
- package/dist/harness/interruption.js +48 -0
- package/dist/harness/interruption.test.js +31 -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 +92 -44
- package/dist/harness/runner.test.js +23 -0
- package/dist/harness/single-arm-audit.js +436 -0
- package/dist/harness/trigger.js +41 -7
- 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 +36 -6
- package/docs/eval-agent-preflight.md +101 -0
- package/docs/eval-case-preflight.md +115 -0
- package/docs/eval-component.md +65 -9
- package/docs/eval-costs.md +53 -0
- package/docs/eval-planning.md +153 -0
- package/docs/evaluation-input-snapshots.md +125 -0
- package/docs/evaluation-interruption.md +101 -0
- package/docs/evaluation-reports.md +143 -0
- package/docs/experiment-workflow.md +16 -2
- package/docs/first-real-eval.md +55 -5
- package/docs/growth-roadmap-2026-10.md +48 -11
- package/docs/metrics.md +71 -3
- package/docs/plans/2026-10-16-case-workflow-and-release.md +19 -0
- package/docs/plans/2026-10-17-workflow-foundations.md +64 -0
- package/docs/releases/0.10.0-ci-registry-install.json +140 -0
- package/docs/releases/0.10.0-feature-smoke.json +22 -0
- package/docs/releases/0.10.0-feature-smoke.mjs +62 -0
- package/docs/releases/0.10.0-signatures.txt +7 -0
- package/docs/releases/0.10.0-verification.json +76 -0
- package/docs/releases/0.10.0.md +44 -8
- 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-feature-smoke.mjs +95 -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 +71 -0
- 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 +52 -11
- 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-preflight.schema.json +57 -0
- package/docs/schemas/eval-request.schema.json +1 -1
- package/docs/schemas/eval-result.schema.json +14 -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 +8 -2
- package/docs/verifier-contract.md +99 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +41 -8
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { getAgent
|
|
6
|
+
import { getAgent } from '../agents.js';
|
|
7
7
|
import { parseFrontmatter } from '../frontmatter.js';
|
|
8
8
|
import { hashFileSet, sha256File, sha256Text } from './hash.js';
|
|
9
9
|
import { assertNativeDiffFile, assertNativeDiffWorkspace, NATIVE_DIFF_SNAPSHOT } from './native-diff.js';
|
|
10
10
|
import { ExecutorFailure } from './types.js';
|
|
11
|
+
import { EvaluationInterrupted, evaluationSignal, throwIfEvaluationInterrupted } from './interruption.js';
|
|
12
|
+
import { freezeInputSnapshot, verifyInputSnapshot } from './input-snapshot.js';
|
|
13
|
+
import { loadBench } from './bench.js';
|
|
14
|
+
import { globalSkillRoots } from './agent-preflight.js';
|
|
15
|
+
import { spendingStopFrom } from './eval-budget.js';
|
|
11
16
|
function skillInventory(root) {
|
|
12
17
|
if (!existsSync(root))
|
|
13
18
|
return { root, entries: ['missing'] };
|
|
@@ -160,9 +165,11 @@ export class ExperimentSession {
|
|
|
160
165
|
callsStarted = 0;
|
|
161
166
|
callsFinished = 0;
|
|
162
167
|
stopReason = null;
|
|
168
|
+
stopCode;
|
|
163
169
|
finished = false;
|
|
164
170
|
guardFiles;
|
|
165
171
|
nativeDiffTool;
|
|
172
|
+
inputSnapshot;
|
|
166
173
|
constructor(options) {
|
|
167
174
|
this.nativeDiffTool = options.details.nativeDiffTool !== undefined;
|
|
168
175
|
this.guardFiles = (options.guardFiles ?? []).map(file => ({ ...file, path: resolve(file.path) }));
|
|
@@ -186,12 +193,13 @@ export class ExperimentSession {
|
|
|
186
193
|
}
|
|
187
194
|
const packageRoot = fileURLToPath(new URL('../../', import.meta.url));
|
|
188
195
|
this.inputs = [pin('bench', options.bench.dir, this.groupDir), pin('target', options.target.sourceDir), pin('implementation', join(packageRoot, 'dist'))];
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
for (const metadata of [options.details['component'], options.details['reviewedPlan']])
|
|
197
|
+
if (metadata !== undefined) {
|
|
198
|
+
const expected = metadata.implementationSha256;
|
|
199
|
+
if (typeof expected !== 'string' || expected !== this.inputs.find(input => input.label === 'implementation').sha256) {
|
|
200
|
+
throw new Error('Evaluation implementation differs from the approved preview; no calls allowed.');
|
|
201
|
+
}
|
|
193
202
|
}
|
|
194
|
-
}
|
|
195
203
|
if (options.baselineTarget)
|
|
196
204
|
this.inputs.push(pin('baseline Skill', options.baselineTarget.sourceDir));
|
|
197
205
|
this.configs = [];
|
|
@@ -222,8 +230,7 @@ export class ExperimentSession {
|
|
|
222
230
|
const trust = match ? { table: match[1], field: match[2], value: match[3] } : undefined;
|
|
223
231
|
for (const path of paths)
|
|
224
232
|
this.configs.push(configState(path, path === settings.path ? trust : undefined, this.trustWorkspaces));
|
|
225
|
-
for (const
|
|
226
|
-
const root = expand(spec, home);
|
|
233
|
+
for (const root of globalSkillRoots(agent, home, env)) {
|
|
227
234
|
this.inventories.push(skillInventory(root));
|
|
228
235
|
if (!existsSync(root))
|
|
229
236
|
continue;
|
|
@@ -256,17 +263,37 @@ export class ExperimentSession {
|
|
|
256
263
|
agent: options.agent ?? null, cliVersion, configuredSettings: configured, servedModel: 'unrecorded',
|
|
257
264
|
plannedCalls: this.plannedCalls, maxCalls: this.maxCalls, workspaces: this.workspaces, workspaceAliases: this.workspaceAliases,
|
|
258
265
|
inputs: this.inputs, guardFiles: this.guardFiles, configurations: this.configs, skillInventories: this.inventories, warnings, details: options.details };
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
mkdirSync(this.groupDir
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
mkdirSync(dirname(this.groupDir), { recursive: true });
|
|
267
|
+
// Claim exclusively; a failed setup removes only the fresh directory we own.
|
|
268
|
+
mkdirSync(this.groupDir);
|
|
269
|
+
try {
|
|
270
|
+
this.inputSnapshot = freezeInputSnapshot(this.groupDir, this.inputs, this.guardFiles);
|
|
271
|
+
if (loadBench(join(this.groupDir, '_inputs/bench')).contentSha256 !== options.bench.contentSha256)
|
|
272
|
+
throw new Error('Sealed bench does not match the planned content hash; keep Git metadata and run outputs outside bench inputs.');
|
|
273
|
+
for (const input of this.inputs)
|
|
274
|
+
if (pin(input.label, input.root, input.exclude).sha256 !== input.sha256)
|
|
275
|
+
throw new Error(`Frozen ${input.label} input changed while sealing snapshots.`);
|
|
276
|
+
for (const file of this.guardFiles)
|
|
277
|
+
if (sha256File(file.path) !== file.sha256)
|
|
278
|
+
throw new Error(`Frozen ${file.label} changed while sealing snapshots.`);
|
|
279
|
+
throwIfEvaluationInterrupted();
|
|
280
|
+
const bytes = JSON.stringify({ ...plan, inputSnapshot: this.inputSnapshot }, null, 2) + '\n';
|
|
281
|
+
this.planSha256 = sha256Text(bytes);
|
|
282
|
+
writeFileSync(join(this.groupDir, '_plan.json'), bytes, { flag: 'wx' });
|
|
283
|
+
if (sha256File(join(this.groupDir, '_plan.json')) !== this.planSha256)
|
|
284
|
+
throw new Error('Frozen plan write verification failed.');
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
rmSync(this.groupDir, { recursive: true, force: true });
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
265
290
|
}
|
|
266
291
|
check() {
|
|
267
292
|
if (this.stopReason)
|
|
268
293
|
throw new Error(this.stopReason);
|
|
269
294
|
try {
|
|
295
|
+
throwIfEvaluationInterrupted();
|
|
296
|
+
verifyInputSnapshot(this.groupDir, { inputs: this.inputs, guardFiles: this.guardFiles, inputSnapshot: this.inputSnapshot });
|
|
270
297
|
if (this.nativeDiffTool) {
|
|
271
298
|
assertNativeDiffFile(join(this.groupDir, NATIVE_DIFF_SNAPSHOT));
|
|
272
299
|
for (const workdir of this.workspaces)
|
|
@@ -299,6 +326,15 @@ export class ExperimentSession {
|
|
|
299
326
|
throw error;
|
|
300
327
|
}
|
|
301
328
|
}
|
|
329
|
+
/** Only this fresh session may hand its prepared directory to an engine. */
|
|
330
|
+
assertPrepared() {
|
|
331
|
+
if (this.finished || this.callsStarted !== 0 ||
|
|
332
|
+
readdirSync(this.groupDir).sort().join() !== '_inputs,_inputs.json,_plan.json' ||
|
|
333
|
+
sha256File(join(this.groupDir, '_plan.json')) !== this.planSha256) {
|
|
334
|
+
throw new Error(`Run group directory already exists or preparation changed: ${this.groupDir}`);
|
|
335
|
+
}
|
|
336
|
+
verifyInputSnapshot(this.groupDir, { inputs: this.inputs, guardFiles: this.guardFiles, inputSnapshot: this.inputSnapshot });
|
|
337
|
+
}
|
|
302
338
|
wrap(executor, role) {
|
|
303
339
|
return { describe: () => executor.describe(), run: async (prompt, workdir) => {
|
|
304
340
|
try {
|
|
@@ -323,14 +359,23 @@ export class ExperimentSession {
|
|
|
323
359
|
}
|
|
324
360
|
catch {
|
|
325
361
|
if (role === 'judge')
|
|
326
|
-
throw new
|
|
362
|
+
throw new ExecutorFailure(this.stopReason, result);
|
|
327
363
|
return { ...result, guardError: this.stopReason };
|
|
328
364
|
}
|
|
329
365
|
return result;
|
|
330
366
|
}
|
|
331
367
|
catch (error) {
|
|
332
368
|
if (!this.stopReason)
|
|
333
|
-
this.stopReason =
|
|
369
|
+
this.stopReason = evaluationSignal()?.aborted
|
|
370
|
+
? evaluationSignal().reason.message
|
|
371
|
+
: `${role} executor failed; inspect the per-trial error receipt. No further calls.`;
|
|
372
|
+
if (role === 'judge' && evaluationSignal()?.aborted) {
|
|
373
|
+
const result = error instanceof ExecutorFailure ? error.result : null;
|
|
374
|
+
writeFileSync(join(this.groupDir, `_interrupted-judge-${call}.json`), JSON.stringify({
|
|
375
|
+
schemaVersion: 1, call, role, error: error.message, result,
|
|
376
|
+
scope: 'Supplementary interrupted judge output and available usage. Independent judge-call receipts retain invocation accounting; primary Agent comparison stays separate.',
|
|
377
|
+
}, null, 2) + '\n', { flag: 'wx' });
|
|
378
|
+
}
|
|
334
379
|
if (this.callsFinished < call) {
|
|
335
380
|
this.callsFinished++;
|
|
336
381
|
appendFileSync(ledger, JSON.stringify({ event: 'failed', call, at: new Date().toISOString() }) + '\n');
|
|
@@ -342,7 +387,7 @@ export class ExperimentSession {
|
|
|
342
387
|
summary() {
|
|
343
388
|
return { schemaVersion: 1, status: this.stopReason ? 'stopped' : this.callsFinished === this.plannedCalls ? 'completed' : 'incomplete',
|
|
344
389
|
plannedCalls: this.plannedCalls, maxCalls: this.maxCalls, callsStarted: this.callsStarted, callsFinished: this.callsFinished,
|
|
345
|
-
stopReason: this.stopReason, planSha256: this.planSha256 };
|
|
390
|
+
stopReason: this.stopReason, ...(this.stopCode ? { stopCode: this.stopCode } : {}), planSha256: this.planSha256 };
|
|
346
391
|
}
|
|
347
392
|
settle() {
|
|
348
393
|
try {
|
|
@@ -354,6 +399,20 @@ export class ExperimentSession {
|
|
|
354
399
|
if (this.finished)
|
|
355
400
|
return;
|
|
356
401
|
this.finished = true;
|
|
402
|
+
const interruption = evaluationSignal()?.reason;
|
|
403
|
+
if (interruption instanceof EvaluationInterrupted) {
|
|
404
|
+
if (!this.stopReason)
|
|
405
|
+
this.stopReason = interruption.message;
|
|
406
|
+
writeFileSync(join(this.groupDir, '_interruption.json'), JSON.stringify({
|
|
407
|
+
schemaVersion: 1, signal: interruption.signalName, receivedAt: interruption.receivedAt,
|
|
408
|
+
exitCode: interruption.exitCode, automaticRetry: false,
|
|
409
|
+
}, null, 2) + '\n', { flag: 'wx' });
|
|
410
|
+
}
|
|
411
|
+
const spendingStop = spendingStopFrom(error);
|
|
412
|
+
if (spendingStop && !(interruption instanceof EvaluationInterrupted)) {
|
|
413
|
+
this.stopCode = spendingStop.code;
|
|
414
|
+
this.stopReason ??= spendingStop.message;
|
|
415
|
+
}
|
|
357
416
|
if (error && !this.stopReason)
|
|
358
417
|
this.stopReason = 'Experiment setup or execution stopped; inspect the command error and retained receipts.';
|
|
359
418
|
this.settle();
|
|
@@ -9,6 +9,7 @@ import { ExperimentSession, normalizeProjectTrust, validateCallBudget } from './
|
|
|
9
9
|
import { sha256File } from './hash.js';
|
|
10
10
|
import { runEval } from '../commands/eval.js';
|
|
11
11
|
import { runBenchCheck } from '../commands/bench.js';
|
|
12
|
+
import { packageFiles } from './replay-package.js';
|
|
12
13
|
function setup(t) {
|
|
13
14
|
const root = mkdtempSync(join(tmpdir(), 'skillfit-session-'));
|
|
14
15
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
@@ -19,7 +20,7 @@ function setup(t) {
|
|
|
19
20
|
writeFileSync(join(skill, 'SKILL.md'), '---\nname: candidate\ndescription: offline fixture\n---\nInspect boundaries.\n');
|
|
20
21
|
writeFileSync(join(benchDir, 'fixture', 'index.js'), 'module.exports = 1;\n');
|
|
21
22
|
writeFileSync(join(benchDir, 'prompt.md'), 'Fix the cache.\n');
|
|
22
|
-
writeFileSync(join(benchDir, 'verify.mjs'), 'process.exit(0);\n
|
|
23
|
+
writeFileSync(join(benchDir, 'verify.mjs'), "import{existsSync,readFileSync}from'node:fs';import{join}from'node:path';const output=join(process.argv[2],'_output.md');process.exit(existsSync(output)&&readFileSync(output,'utf8').trim()?0:1);\n");
|
|
23
24
|
writeFileSync(join(benchDir, 'bench.json'), JSON.stringify({ schemaVersion: 1, name: 'session-test', tasks: [
|
|
24
25
|
{ id: 'one', fixture: 'fixture', prompt: 'prompt.md', verifier: 'node verify.mjs', shouldTrigger: true },
|
|
25
26
|
] }));
|
|
@@ -88,6 +89,45 @@ test('a changed frozen input retains returned output but blocks subsequent calls
|
|
|
88
89
|
assert.equal(calls, 1);
|
|
89
90
|
assert.equal(session.summary().status, 'stopped');
|
|
90
91
|
});
|
|
92
|
+
test('input snapshots exist and are bound before dispatch; modifying one stops further calls with usage retained', async (t) => {
|
|
93
|
+
const s = setup(t), session = new ExperimentSession(s.options);
|
|
94
|
+
const plan = JSON.parse(readFileSync(join(s.groupDir, '_plan.json'), 'utf8'));
|
|
95
|
+
const snapshot = JSON.parse(readFileSync(join(s.groupDir, '_inputs.json'), 'utf8'));
|
|
96
|
+
assert.equal(plan.inputSnapshot.sha256, sha256File(join(s.groupDir, '_inputs.json')));
|
|
97
|
+
assert.deepEqual(snapshot.entries.map((entry) => entry.label).sort(), ['bench', 'implementation', 'target']);
|
|
98
|
+
const files = packageFiles(join(s.groupDir, '_inputs'));
|
|
99
|
+
assert.equal(plan.inputSnapshot.cost.files, files.length + 1);
|
|
100
|
+
assert.equal(plan.inputSnapshot.cost.bytes, files.reduce((sum, file) => sum + readFileSync(join(s.groupDir, '_inputs', file)).length, 0) + readFileSync(join(s.groupDir, '_inputs.json')).length);
|
|
101
|
+
assert.equal(plan.inputSnapshot.cost.modelCalls, 0);
|
|
102
|
+
assert.ok(plan.inputSnapshot.cost.durationMs >= 0);
|
|
103
|
+
let calls = 0;
|
|
104
|
+
const guarded = session.wrap({ ...s.executor, run: async () => {
|
|
105
|
+
calls++;
|
|
106
|
+
assert.equal(readFileSync(join(s.groupDir, '_inputs/target/SKILL.md'), 'utf8'), readFileSync(join(s.skill, 'SKILL.md'), 'utf8'));
|
|
107
|
+
writeFileSync(join(s.groupDir, '_inputs/target/SKILL.md'), 'changed snapshot');
|
|
108
|
+
return { output: 'retained', tokens: { input: 12, output: 3 } };
|
|
109
|
+
} }, 'agent');
|
|
110
|
+
const result = await guarded.run('first', s.root);
|
|
111
|
+
assert.match(result.guardError, /snapshot hash mismatch/);
|
|
112
|
+
assert.deepEqual(result.tokens, { input: 12, output: 3 });
|
|
113
|
+
await assert.rejects(guarded.run('partner', s.root), /snapshot hash mismatch/);
|
|
114
|
+
assert.equal(calls, 1);
|
|
115
|
+
session.finish();
|
|
116
|
+
assert.equal(session.summary().status, 'stopped');
|
|
117
|
+
});
|
|
118
|
+
test('source drift during snapshot setup fails before dispatch and removes only its fresh output', async (t) => {
|
|
119
|
+
const s = setup(t);
|
|
120
|
+
let calls = 0;
|
|
121
|
+
const runsRoot = join(s.root, 'drift'), group = join(runsRoot, 'saved');
|
|
122
|
+
mkdirSync(runsRoot);
|
|
123
|
+
writeFileSync(join(runsRoot, 'kept'), 'existing sibling');
|
|
124
|
+
await assert.rejects(runEval({ skillPath: s.skill, bench: s.benchDir, executor: { ...s.executor, run: async () => { calls++; return { output: 'done' }; } },
|
|
125
|
+
judgeExecutor: null, agent: 'codex', trials: 1, dryRun: false, yes: true, runsRoot, runGroup: 'saved', log: () => { },
|
|
126
|
+
sessionOptions: { homeDir: s.root, env: {}, versionProbe: () => { writeFileSync(join(s.benchDir, 'prompt.md'), 'changed after fingerprinting'); return 'fake 1.0'; } } }), /changed.*snapshot|snapshot.*changed/i);
|
|
127
|
+
assert.equal(calls, 0);
|
|
128
|
+
assert.ok(!existsSync(group));
|
|
129
|
+
assert.equal(readFileSync(join(runsRoot, 'kept'), 'utf8'), 'existing sibling');
|
|
130
|
+
});
|
|
91
131
|
test('executor failure stops further actual calls and keeps a failure receipt without secrets', async (t) => {
|
|
92
132
|
const s = setup(t);
|
|
93
133
|
let calls = 0;
|
|
@@ -100,6 +140,14 @@ test('executor failure stops further actual calls and keeps a failure receipt wi
|
|
|
100
140
|
assert.equal(readFileSync(join(s.groupDir, '_session.json'), 'utf8').includes('PRIVATE_SECRET'), false);
|
|
101
141
|
assert.match(readFileSync(join(s.groupDir, '_calls.jsonl'), 'utf8'), /"event":"failed"/);
|
|
102
142
|
});
|
|
143
|
+
test('finalizing arbitrary errors keeps generic session diagnostics instead of copying secret-bearing messages', t => {
|
|
144
|
+
const s = setup(t), session = new ExperimentSession(s.options);
|
|
145
|
+
session.finish(new Error('secret-bearing untrusted executor error'));
|
|
146
|
+
const saved = readFileSync(join(s.groupDir, '_session.json'), 'utf8');
|
|
147
|
+
assert.doesNotMatch(saved, /secret-bearing/);
|
|
148
|
+
assert.equal(session.summary().stopCode, undefined);
|
|
149
|
+
assert.match(session.summary().stopReason, /Experiment setup or execution stopped/);
|
|
150
|
+
});
|
|
103
151
|
test('trust normalization covers declared pure blocks only and preserves other configuration bytes', () => {
|
|
104
152
|
const trust = { table: 'projects', field: 'trust_level', value: 'trusted' };
|
|
105
153
|
const base = 'model = "m"\n';
|
|
@@ -121,6 +169,8 @@ test('temporary profile config is pinned, planned trust additions are allowed, m
|
|
|
121
169
|
const plan = readFileSync(join(s.groupDir, '_plan.json'), 'utf8');
|
|
122
170
|
assert.equal(plan.includes('PRIVATE_SECRET'), false);
|
|
123
171
|
assert.match(plan, /"model_reasoning_effort": "high"/);
|
|
172
|
+
const snapshot = JSON.parse(readFileSync(join(s.groupDir, '_inputs.json'), 'utf8'));
|
|
173
|
+
assert.deepEqual(snapshot.entries.map((entry) => entry.label).sort(), ['bench', 'implementation', 'target'], 'private agent configuration remains fingerprint-only');
|
|
124
174
|
writeFileSync(config, readFileSync(config, 'utf8') + `\n[projects.${JSON.stringify(s.options.workspaces[0])}]\ntrust_level = "trusted"\n`);
|
|
125
175
|
session.check();
|
|
126
176
|
writeFileSync(config, readFileSync(config, 'utf8').replace('"offline"', '"changed"'));
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { chmodSync, lstatSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
4
|
+
import { hashFileSet, sha256File } from './hash.js';
|
|
5
|
+
import { packageFiles, packageMember } from './replay-package.js';
|
|
6
|
+
const ALIASES = new Map([['bench', 'bench'], ['target', 'target'], ['implementation', 'implementation'], ['baseline Skill', 'baseline-skill']]);
|
|
7
|
+
export const INPUT_SNAPSHOT_POLICY = { schemaVersion: 1, required: true, status: 'pending' };
|
|
8
|
+
/** Includes empty directories; excludes Git metadata and the current native run. */
|
|
9
|
+
export function inputDirectories(root, exclude) {
|
|
10
|
+
const result = [];
|
|
11
|
+
const walk = (prefix) => {
|
|
12
|
+
for (const entry of readdirSync(join(root, prefix), { withFileTypes: true })) {
|
|
13
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
14
|
+
const rel = exclude ? relative(exclude, join(root, path)) : '..';
|
|
15
|
+
if (entry.name === '.git' || (exclude && !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`)))
|
|
16
|
+
continue;
|
|
17
|
+
if (entry.isSymbolicLink())
|
|
18
|
+
throw new Error(`Unpinned symbolic link in input snapshot: ${path}`);
|
|
19
|
+
if (entry.isDirectory()) {
|
|
20
|
+
result.push(path);
|
|
21
|
+
walk(path);
|
|
22
|
+
}
|
|
23
|
+
else if (!entry.isFile())
|
|
24
|
+
throw new Error(`Unsupported input snapshot entry: ${path}`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
walk('');
|
|
28
|
+
return result.sort();
|
|
29
|
+
}
|
|
30
|
+
function selectedInputs(inputs) {
|
|
31
|
+
assert.ok(Array.isArray(inputs), 'Native input fingerprints are missing.');
|
|
32
|
+
const selected = inputs.filter(input => input && ALIASES.has(input.label));
|
|
33
|
+
for (const label of ['bench', 'target', 'implementation'])
|
|
34
|
+
assert.equal(selected.filter(input => input.label === label).length, 1, `Missing or repeated snapshot input: ${label}`);
|
|
35
|
+
assert.equal(new Set(selected.map(input => input.label)).size, selected.length, 'Repeated snapshot input.');
|
|
36
|
+
for (const input of selected) {
|
|
37
|
+
assert.ok(typeof input.root === 'string' && Array.isArray(input.files) && input.files.every(path => typeof path === 'string'));
|
|
38
|
+
assert.deepEqual([...new Set(input.files)].sort(), input.files, 'Snapshot file list must be sorted and unique.');
|
|
39
|
+
assert.match(input.sha256, /^[a-f0-9]{64}$/);
|
|
40
|
+
}
|
|
41
|
+
return selected;
|
|
42
|
+
}
|
|
43
|
+
function requestInput(guards) {
|
|
44
|
+
if (guards === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
assert.ok(Array.isArray(guards), 'Invalid native request guards.');
|
|
47
|
+
const requests = guards.filter(file => file?.label === 'component request');
|
|
48
|
+
assert.ok(requests.length <= 1, 'Repeated component request guard.');
|
|
49
|
+
if (requests[0]) {
|
|
50
|
+
assert.equal(typeof requests[0].path, 'string');
|
|
51
|
+
assert.match(requests[0].sha256, /^[a-f0-9]{64}$/);
|
|
52
|
+
}
|
|
53
|
+
return requests[0];
|
|
54
|
+
}
|
|
55
|
+
/** Called only in an exclusively claimed fresh run, before publishing _plan.json. */
|
|
56
|
+
export function freezeInputSnapshot(run, inputs, guards) {
|
|
57
|
+
const started = performance.now(), entries = [];
|
|
58
|
+
let bytes = 0, files = 0;
|
|
59
|
+
const copy = (source, target) => {
|
|
60
|
+
const content = readFileSync(source);
|
|
61
|
+
writeFileSync(target, content, { flag: 'wx' });
|
|
62
|
+
chmodSync(target, lstatSync(source).mode & 0o777);
|
|
63
|
+
bytes += content.length;
|
|
64
|
+
files++;
|
|
65
|
+
};
|
|
66
|
+
mkdirSync(join(run, '_inputs'));
|
|
67
|
+
for (const input of selectedInputs(inputs)) {
|
|
68
|
+
const label = ALIASES.get(input.label), path = `_inputs/${label}`, root = join(run, path);
|
|
69
|
+
const directories = inputDirectories(input.root, input.exclude);
|
|
70
|
+
mkdirSync(root);
|
|
71
|
+
for (const dir of directories)
|
|
72
|
+
mkdirSync(join(root, dir), { recursive: true });
|
|
73
|
+
for (const file of input.files) {
|
|
74
|
+
const source = packageMember(input.root, file);
|
|
75
|
+
copy(source, join(root, file));
|
|
76
|
+
}
|
|
77
|
+
if (hashFileSet(root, input.files) !== input.sha256)
|
|
78
|
+
throw new Error(`Input changed while sealing snapshot: ${label}`);
|
|
79
|
+
assert.deepEqual(inputDirectories(input.root, input.exclude), directories, `Input directories changed while sealing snapshot: ${label}`);
|
|
80
|
+
const executableFiles = input.files.filter(file => (lstatSync(join(root, file)).mode & 0o111) !== 0);
|
|
81
|
+
entries.push({ label, path, files: [...input.files], directories, executableFiles, sha256: input.sha256 });
|
|
82
|
+
}
|
|
83
|
+
const request = requestInput(guards);
|
|
84
|
+
if (request) {
|
|
85
|
+
const path = '_inputs/request.json';
|
|
86
|
+
if (!lstatSync(request.path).isFile())
|
|
87
|
+
throw new Error('Input request must be a regular file.');
|
|
88
|
+
copy(request.path, join(run, path));
|
|
89
|
+
if (sha256File(join(run, path)) !== request.sha256)
|
|
90
|
+
throw new Error('Request changed while sealing snapshot.');
|
|
91
|
+
entries.push({ label: 'request', path, files: [], directories: [], executableFiles: [], sha256: request.sha256 });
|
|
92
|
+
}
|
|
93
|
+
writeFileSync(join(run, '_inputs.json'), JSON.stringify({ schemaVersion: 1, kind: 'skillfit.eval-inputs', entries }, null, 2) + '\n', { flag: 'wx' });
|
|
94
|
+
bytes += lstatSync(join(run, '_inputs.json')).size;
|
|
95
|
+
files++;
|
|
96
|
+
const snapshot = { schemaVersion: 1, indexPath: '_inputs.json', sha256: sha256File(join(run, '_inputs.json')),
|
|
97
|
+
cost: { modelCalls: 0, durationMs: Math.round(performance.now() - started), bytes, files } };
|
|
98
|
+
verifyInputSnapshot(run, { inputs, guardFiles: guards, inputSnapshot: snapshot });
|
|
99
|
+
snapshot.cost.durationMs = Math.round(performance.now() - started);
|
|
100
|
+
return snapshot;
|
|
101
|
+
}
|
|
102
|
+
/** A declared snapshot never falls back to mutable originals when damaged. */
|
|
103
|
+
export function verifyInputSnapshot(run, plan) {
|
|
104
|
+
if (plan.inputSnapshot === undefined)
|
|
105
|
+
return null; // Historical run: retain the old recovery path.
|
|
106
|
+
const descriptor = plan.inputSnapshot;
|
|
107
|
+
assert.ok(descriptor && descriptor.schemaVersion === 1 && descriptor.indexPath === '_inputs.json', 'Invalid input snapshot descriptor.');
|
|
108
|
+
const indexPath = packageMember(run, '_inputs.json');
|
|
109
|
+
assert.equal(sha256File(indexPath), descriptor.sha256, 'Input snapshot index changed.');
|
|
110
|
+
const index = JSON.parse(readFileSync(indexPath, 'utf8'));
|
|
111
|
+
assert.ok(index.schemaVersion === 1 && index.kind === 'skillfit.eval-inputs' && Array.isArray(index.entries), 'Invalid input snapshot index.');
|
|
112
|
+
const inputs = selectedInputs(plan.inputs), request = requestInput(plan.guardFiles);
|
|
113
|
+
const expectedLabels = [...inputs.map(input => ALIASES.get(input.label)), ...(request ? ['request'] : [])].sort();
|
|
114
|
+
assert.deepEqual(index.entries.map(entry => entry.label).sort(), expectedLabels, 'Input snapshot coverage changed.');
|
|
115
|
+
assert.ok(lstatSync(join(run, '_inputs')).isDirectory(), 'Input snapshot root must be a regular directory.');
|
|
116
|
+
const expectedFiles = [], expectedDirectories = [], roots = new Map();
|
|
117
|
+
for (const entry of index.entries) {
|
|
118
|
+
const path = entry.label === 'request' ? '_inputs/request.json' : `_inputs/${entry.label}`;
|
|
119
|
+
assert.equal(entry.path, path, 'Unsafe input snapshot root.');
|
|
120
|
+
if (entry.label === 'request') {
|
|
121
|
+
assert.equal(entry.sha256, request.sha256);
|
|
122
|
+
assert.equal(sha256File(packageMember(run, path)), request.sha256, 'Input request snapshot changed.');
|
|
123
|
+
assert.deepEqual(entry.files, []);
|
|
124
|
+
assert.deepEqual(entry.directories, []);
|
|
125
|
+
assert.deepEqual(entry.executableFiles, []);
|
|
126
|
+
expectedFiles.push('request.json');
|
|
127
|
+
roots.set(entry.label, join(run, path));
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const input = inputs.find(input => ALIASES.get(input.label) === entry.label);
|
|
131
|
+
assert.deepEqual(entry.files, input.files, 'Input snapshot file coverage changed.');
|
|
132
|
+
assert.equal(entry.sha256, input.sha256);
|
|
133
|
+
const root = join(run, path);
|
|
134
|
+
assert.ok(lstatSync(root).isDirectory(), 'Input snapshot root must be a regular directory.');
|
|
135
|
+
for (const file of entry.files)
|
|
136
|
+
packageMember(root, file);
|
|
137
|
+
assert.deepEqual(packageFiles(root), entry.files, 'Input snapshot inventory changed.');
|
|
138
|
+
assert.deepEqual(inputDirectories(root), entry.directories, 'Input snapshot directories changed.');
|
|
139
|
+
assert.ok(Array.isArray(entry.executableFiles) && entry.executableFiles.every(file => entry.files.includes(file)), 'Invalid snapshot executable file list.');
|
|
140
|
+
if (process.platform !== 'win32')
|
|
141
|
+
assert.deepEqual(entry.files.filter(file => (lstatSync(join(root, file)).mode & 0o111) !== 0), entry.executableFiles, 'Input snapshot executable modes changed.');
|
|
142
|
+
assert.equal(hashFileSet(root, entry.files), input.sha256, `Input snapshot hash mismatch: ${entry.label}`);
|
|
143
|
+
expectedFiles.push(...entry.files.map(file => `${entry.label}/${file}`));
|
|
144
|
+
roots.set(entry.label, root);
|
|
145
|
+
expectedDirectories.push(entry.label, ...entry.directories.map(dir => `${entry.label}/${dir}`));
|
|
146
|
+
}
|
|
147
|
+
assert.deepEqual(packageFiles(join(run, '_inputs')), expectedFiles.sort(), 'Input snapshot inventory changed.');
|
|
148
|
+
assert.deepEqual(inputDirectories(join(run, '_inputs')), expectedDirectories.sort(), 'Input snapshot directories changed.');
|
|
149
|
+
return { entries: index.entries, roots };
|
|
150
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export class EvaluationInterrupted extends Error {
|
|
3
|
+
signalName;
|
|
4
|
+
receivedAt = new Date().toISOString();
|
|
5
|
+
exitCode;
|
|
6
|
+
constructor(signalName) {
|
|
7
|
+
super(`Evaluation interrupted by ${signalName}; no further calls. Retained receipts must not be retried or replaced automatically.`);
|
|
8
|
+
this.signalName = signalName;
|
|
9
|
+
this.name = 'EvaluationInterrupted';
|
|
10
|
+
this.exitCode = signalName === 'SIGINT' ? 130 : 143;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// The cancellation belongs to this asynchronous evaluation, including its git,
|
|
14
|
+
// verifier and judge work. Imports, previews and unrelated commands install no handlers.
|
|
15
|
+
const evaluations = new AsyncLocalStorage();
|
|
16
|
+
export function evaluationSignal() {
|
|
17
|
+
return evaluations.getStore();
|
|
18
|
+
}
|
|
19
|
+
export function throwIfEvaluationInterrupted() {
|
|
20
|
+
evaluationSignal()?.throwIfAborted();
|
|
21
|
+
}
|
|
22
|
+
export async function withEvaluationInterrupts(operation) {
|
|
23
|
+
if (evaluationSignal())
|
|
24
|
+
return operation();
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const interrupt = (signal) => {
|
|
27
|
+
if (controller.signal.aborted)
|
|
28
|
+
return;
|
|
29
|
+
const reason = new EvaluationInterrupted(signal);
|
|
30
|
+
process.exitCode = reason.exitCode;
|
|
31
|
+
process.stderr.write(`${signal}: stopping evaluation processes and sealing retained records…\n`);
|
|
32
|
+
controller.abort(reason);
|
|
33
|
+
};
|
|
34
|
+
const onInt = () => interrupt('SIGINT'), onTerm = () => interrupt('SIGTERM');
|
|
35
|
+
process.on('SIGINT', onInt);
|
|
36
|
+
process.on('SIGTERM', onTerm);
|
|
37
|
+
try {
|
|
38
|
+
return await evaluations.run(controller.signal, async () => {
|
|
39
|
+
const result = await operation();
|
|
40
|
+
throwIfEvaluationInterrupted();
|
|
41
|
+
return result;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
process.removeListener('SIGINT', onInt);
|
|
46
|
+
process.removeListener('SIGTERM', onTerm);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { evaluationSignal, withEvaluationInterrupts } from './interruption.js';
|
|
4
|
+
const counts = () => [process.listenerCount('SIGINT'), process.listenerCount('SIGTERM')];
|
|
5
|
+
test('normal and failed operations restore signal handlers and asynchronous context', async () => {
|
|
6
|
+
const before = counts();
|
|
7
|
+
assert.equal(evaluationSignal(), undefined);
|
|
8
|
+
assert.equal(await withEvaluationInterrupts(async () => {
|
|
9
|
+
assert.ok(evaluationSignal());
|
|
10
|
+
await Promise.resolve();
|
|
11
|
+
assert.ok(evaluationSignal());
|
|
12
|
+
return 'done';
|
|
13
|
+
}), 'done');
|
|
14
|
+
assert.deepEqual(counts(), before);
|
|
15
|
+
assert.equal(evaluationSignal(), undefined);
|
|
16
|
+
await assert.rejects(withEvaluationInterrupts(async () => { throw new Error('offline setup failed'); }), /offline setup failed/);
|
|
17
|
+
assert.deepEqual(counts(), before);
|
|
18
|
+
assert.equal(evaluationSignal(), undefined);
|
|
19
|
+
});
|
|
20
|
+
test('concurrent operations keep distinct cancellation contexts and clean up all handlers', async () => {
|
|
21
|
+
const before = counts();
|
|
22
|
+
const signals = await Promise.all([1, 2].map(() => withEvaluationInterrupts(async () => {
|
|
23
|
+
const signal = evaluationSignal();
|
|
24
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
25
|
+
assert.equal(evaluationSignal(), signal);
|
|
26
|
+
return signal;
|
|
27
|
+
})));
|
|
28
|
+
assert.notEqual(signals[0], signals[1]);
|
|
29
|
+
assert.deepEqual(counts(), before);
|
|
30
|
+
assert.equal(evaluationSignal(), undefined);
|
|
31
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { COST_METRICS, summarizeCosts } from './costs.js';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { record } from './eval-contract.js';
|
|
4
|
+
export function invocationPopulation(rows) {
|
|
5
|
+
return summarizeCosts({ baseline: rows, treatment: [] }, { baseline: [], treatment: [] }).attempts.baseline;
|
|
6
|
+
}
|
|
7
|
+
export function summarizeInvocationCosts(agent, judge, requested) {
|
|
8
|
+
return { schemaVersion: 1, agent: invocationPopulation(agent), judge: invocationPopulation(judge),
|
|
9
|
+
total: invocationPopulation([...agent, ...judge]), judgeUsage: requested ? 'recorded' : 'not-requested' };
|
|
10
|
+
}
|
|
11
|
+
/** Historical absence never establishes a free judge or a complete invocation total. */
|
|
12
|
+
export function historicalInvocationCosts(agent, requested) {
|
|
13
|
+
return { schemaVersion: 1, agent, judge: requested ? null : invocationPopulation([]),
|
|
14
|
+
total: requested ? null : agent, judgeUsage: requested ? 'unknown' : 'not-requested' };
|
|
15
|
+
}
|
|
16
|
+
export function parseInvocationCosts(value) {
|
|
17
|
+
const r = record(value, 'invocationCosts');
|
|
18
|
+
assert.equal(r.schemaVersion, 1, 'Unsupported invocationCosts schema.');
|
|
19
|
+
assert.ok(['recorded', 'unknown', 'not-requested'].includes(String(r.judgeUsage)), 'Invalid judge usage state.');
|
|
20
|
+
const population = (value, label) => {
|
|
21
|
+
const p = record(value, label);
|
|
22
|
+
for (const field of ['runs', 'passes'])
|
|
23
|
+
assert.ok(Number.isSafeInteger(p[field]) && Number(p[field]) >= 0, `${label}.${field} must be a non-negative safe integer.`);
|
|
24
|
+
assert.ok(Number(p.passes) <= Number(p.runs), `${label} successes exceed invocations.`);
|
|
25
|
+
const metrics = record(p.metrics, `${label}.metrics`);
|
|
26
|
+
for (const metric of COST_METRICS) {
|
|
27
|
+
const m = record(metrics[metric], `${label}.${metric}`), c = record(m.coverage, `${label}.${metric}.coverage`);
|
|
28
|
+
assert.ok(typeof m.knownTotal === 'number' && Number.isFinite(m.knownTotal) && m.knownTotal >= 0 &&
|
|
29
|
+
(metric === 'durationSeconds' || Number.isSafeInteger(m.knownTotal)), `${label}.${metric} has invalid known spending.`);
|
|
30
|
+
for (const status of ['final', 'partial', 'unknown'])
|
|
31
|
+
assert.ok(Number.isSafeInteger(c[status]) && Number(c[status]) >= 0, `${label}.${metric} has invalid coverage.`);
|
|
32
|
+
assert.equal(Number(c.final) + Number(c.partial) + Number(c.unknown), p.runs, `${label}.${metric} coverage differs from invocations.`);
|
|
33
|
+
if (Number(c.final) + Number(c.partial) === 0)
|
|
34
|
+
assert.equal(m.knownTotal, 0, `${label}.${metric} unknown spending must not invent a known total.`);
|
|
35
|
+
}
|
|
36
|
+
return p;
|
|
37
|
+
};
|
|
38
|
+
const agent = population(r.agent, 'invocationCosts.agent'), judge = r.judge === null ? null : population(r.judge, 'invocationCosts.judge');
|
|
39
|
+
const total = r.total === null ? null : population(r.total, 'invocationCosts.total');
|
|
40
|
+
assert.equal(judge === null, total === null, 'Unknown judge usage must keep its invocation total unknown too.');
|
|
41
|
+
if (r.judgeUsage !== 'unknown')
|
|
42
|
+
assert.ok(judge && total, 'Recorded judge usage requires cost populations.');
|
|
43
|
+
if (judge && total) {
|
|
44
|
+
for (const field of ['runs', 'passes'])
|
|
45
|
+
assert.equal(total[field], agent[field] + judge[field], `Invocation ${field} total differs from roles.`);
|
|
46
|
+
for (const metric of COST_METRICS) {
|
|
47
|
+
assert.ok(Math.abs(total.metrics[metric].knownTotal - agent.metrics[metric].knownTotal - judge.metrics[metric].knownTotal) < 1e-6, `Invocation ${metric} total differs from roles.`);
|
|
48
|
+
for (const status of ['final', 'partial', 'unknown'])
|
|
49
|
+
assert.equal(total.metrics[metric].coverage[status], agent.metrics[metric].coverage[status] + judge.metrics[metric].coverage[status], `Invocation ${metric} coverage total differs from roles.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (r.judgeUsage === 'not-requested')
|
|
53
|
+
assert.equal(judge.runs, 0, 'Disabled judge cannot have invocations.');
|
|
54
|
+
return { schemaVersion: 1, agent, judge, total, judgeUsage: r.judgeUsage };
|
|
55
|
+
}
|
|
56
|
+
export function renderInvocationCostLines(costs) {
|
|
57
|
+
const lines = ['All executor invocation costs (primary Agent and optional judge):'];
|
|
58
|
+
for (const role of ['agent', 'judge', 'total']) {
|
|
59
|
+
const population = costs[role];
|
|
60
|
+
if (!population) {
|
|
61
|
+
lines.push(`- ${role}: unknown; historical judge receipts were not recorded.`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
lines.push(`- ${role}: ${population.runs} invocations.`);
|
|
65
|
+
for (const metric of COST_METRICS) {
|
|
66
|
+
const m = population.metrics[metric], c = m.coverage;
|
|
67
|
+
lines.push(` ${metric}: known total ${m.knownTotal}; final/partial/unknown ${c.final}/${c.partial}/${c.unknown}.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
lines.push('- Usage and monotonic elapsed intervals only; no exact bill. Judge spending does not alter the primary Agent comparison or adoption policy.');
|
|
71
|
+
return lines;
|
|
72
|
+
}
|