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
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import { COST_METRICS, summarizeCosts } from './costs.js';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { appendFileSync, existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
/** Only controlled budget diagnostics may be copied into a durable session stop reason. */
|
|
5
|
+
export class SpendingBudgetStop extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, state) {
|
|
8
|
+
super(`${code}: no further agent calls; reached=${state.reached.join(',') || 'none'}, incomplete=${state.incomplete.join(',') || 'none'}. Retained spending is not discarded; no retry or replacement.`);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = 'SpendingBudgetStop';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function spendingStopFrom(error) {
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
let current = error;
|
|
16
|
+
while (current instanceof Error && !seen.has(current) && seen.size < 8) {
|
|
17
|
+
if (current instanceof SpendingBudgetStop)
|
|
18
|
+
return current;
|
|
19
|
+
seen.add(current);
|
|
20
|
+
current = current.cause;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
4
24
|
export function parseSpendingBudget(value) {
|
|
5
25
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
6
26
|
throw new Error('spendingBudget must be an object.');
|
|
@@ -30,7 +50,31 @@ export function spendingBudgetState(limits, observations) {
|
|
|
30
50
|
}
|
|
31
51
|
export function assertSpendingCanContinue(state) {
|
|
32
52
|
if (state.reason)
|
|
33
|
-
throw new
|
|
53
|
+
throw new SpendingBudgetStop(state.reason, state);
|
|
54
|
+
}
|
|
55
|
+
/** One serial stop-line recorder for every executor role and evaluation mode. */
|
|
56
|
+
export function createSpendingBudgetRecorder(options) {
|
|
57
|
+
const observations = [];
|
|
58
|
+
const event = (phase, identity) => {
|
|
59
|
+
if (!options.budget)
|
|
60
|
+
return null;
|
|
61
|
+
const state = spendingBudgetState(options.budget, observations);
|
|
62
|
+
appendFileSync(join(options.groupDir, '_budget.jsonl'), JSON.stringify({ phase, ...identity, state }) + '\n', 'utf8');
|
|
63
|
+
return state;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
before(identity) {
|
|
67
|
+
const state = event('before-call', identity);
|
|
68
|
+
if (state)
|
|
69
|
+
assertSpendingCanContinue(state);
|
|
70
|
+
},
|
|
71
|
+
after(identity, observation) {
|
|
72
|
+
observations.push(observation);
|
|
73
|
+
const state = event('after-call', identity);
|
|
74
|
+
if (state && (state.incomplete.length || state.reason === 'EXECUTION_FAILED'))
|
|
75
|
+
assertSpendingCanContinue(state);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
34
78
|
}
|
|
35
79
|
/** Informational on stopped evidence; a completed native audit verifies every event. */
|
|
36
80
|
export function spendingBudgetReport(runDir) {
|
|
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
|
|
|
5
5
|
import { test } from 'node:test';
|
|
6
6
|
import { runEvalComponent, reportEvalComponent } from '../commands/eval-component.js';
|
|
7
7
|
import { parseEvalRequest } from './eval-contract.js';
|
|
8
|
-
import { assertSpendingCanContinue, parseSpendingBudget, spendingBudgetState } from './eval-budget.js';
|
|
8
|
+
import { assertSpendingCanContinue, parseSpendingBudget, spendingBudgetState, spendingStopFrom, SpendingBudgetStop } from './eval-budget.js';
|
|
9
9
|
import { COST_METRICS } from './costs.js';
|
|
10
10
|
import { sha256File } from './hash.js';
|
|
11
11
|
import { ExecutorFailure } from './types.js';
|
|
@@ -36,6 +36,25 @@ test('all-invocation budgets count functional failures, partial costs and unknow
|
|
|
36
36
|
assert.equal(state.metrics.input.coverage.partial, 1);
|
|
37
37
|
assert.equal(state.reason, 'FINAL_USAGE_MISSING');
|
|
38
38
|
});
|
|
39
|
+
test('budget stop codes survive trusted cause chains without treating arbitrary error text as safe diagnostics', () => {
|
|
40
|
+
const state = spendingBudgetState({ ...limits, input: 10 }, [observation()]);
|
|
41
|
+
let stopped;
|
|
42
|
+
try {
|
|
43
|
+
assertSpendingCanContinue(state);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
stopped = error;
|
|
47
|
+
}
|
|
48
|
+
assert.ok(stopped instanceof SpendingBudgetStop);
|
|
49
|
+
assert.equal(stopped.code, 'SPENDING_BUDGET_REACHED');
|
|
50
|
+
assert.equal(spendingStopFrom(new Error('wrapper', { cause: stopped })), stopped);
|
|
51
|
+
const ordinary = new Error('SPENDING_BUDGET_REACHED: private credential text');
|
|
52
|
+
ordinary.name = 'SpendingBudgetStop';
|
|
53
|
+
assert.equal(spendingStopFrom(ordinary), null);
|
|
54
|
+
const cycle = new Error('cyclic cause');
|
|
55
|
+
cycle.cause = cycle;
|
|
56
|
+
assert.equal(spendingStopFrom(cycle), null);
|
|
57
|
+
});
|
|
39
58
|
function setup(t, change = {}, result, functionalFailure = false) {
|
|
40
59
|
const root = mkdtempSync(join(tmpdir(), 'skillfit-budget-'));
|
|
41
60
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
@@ -83,6 +102,9 @@ for (const metric of COST_METRICS)
|
|
|
83
102
|
const receipt = JSON.parse(readFileSync(join(f.directory, 'first/baseline/trial-1/_result.json'), 'utf8'));
|
|
84
103
|
assert.deepEqual(receipt.tokens, { input: 10, cachedInput: 6, output: 3 });
|
|
85
104
|
assert.equal(existsSync(join(f.directory, 'first/treatment/trial-1')), false);
|
|
105
|
+
const session = JSON.parse(readFileSync(join(f.directory, '_session.json'), 'utf8'));
|
|
106
|
+
assert.equal(session.stopCode, 'SPENDING_BUDGET_REACHED');
|
|
107
|
+
assert.match(session.stopReason, /SPENDING_BUDGET_REACHED/);
|
|
86
108
|
assert.ok('spendingBudget' in result);
|
|
87
109
|
assert.ok(result.spendingBudget);
|
|
88
110
|
assert.ok(result.spendingBudget.latestState.reached.includes(metric));
|
|
@@ -106,6 +128,9 @@ for (const [label, tokens] of [['no counters', undefined], ['missing cache', { i
|
|
|
106
128
|
assert.equal(f.calls(), 1);
|
|
107
129
|
assert.equal(result.status, 'stopped');
|
|
108
130
|
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
131
|
+
const session = JSON.parse(readFileSync(join(f.directory, '_session.json'), 'utf8'));
|
|
132
|
+
assert.equal(session.stopCode, 'FINAL_USAGE_MISSING');
|
|
133
|
+
assert.match(session.stopReason, /FINAL_USAGE_MISSING/);
|
|
109
134
|
assert.ok('spendingBudget' in result);
|
|
110
135
|
assert.ok(result.spendingBudget);
|
|
111
136
|
assert.equal(result.spendingBudget.latestState.reason, 'FINAL_USAGE_MISSING');
|
|
@@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { reportEvalComponent, runEvalComponent } from '../commands/eval-component.js';
|
|
9
9
|
import { exportEvaluation } from '../commands/eval-export.js';
|
|
10
10
|
import { runEval } from '../commands/eval.js';
|
|
11
|
+
import { runEvalCli } from '../commands/eval-cli.js';
|
|
11
12
|
import { assessEvaluation } from './eval-acceptance.js';
|
|
12
13
|
import { parseAcceptancePolicy, parseEvalRequest, policyHash } from './eval-contract.js';
|
|
13
14
|
import { hashFileSet, listFilesRecursive, sha256File } from './hash.js';
|
|
@@ -316,6 +317,7 @@ test('changing the request policy during a call stops further calls and retains
|
|
|
316
317
|
assert.ok('costs' in result);
|
|
317
318
|
assert.equal(result.costs.populations?.attempts.baseline.metrics.input.knownTotal, 10);
|
|
318
319
|
const replay = await reportEvalComponent(f.runDir);
|
|
320
|
+
assert.ok('costs' in replay);
|
|
319
321
|
assert.deepEqual(replay.costs, result.costs);
|
|
320
322
|
});
|
|
321
323
|
test('executor failures preserve partial usage and missing cache counts remain unknown', async (t) => {
|
|
@@ -605,3 +607,164 @@ test('CLI request plans and errors emit one parseable JSON document without agen
|
|
|
605
607
|
assert.match(JSON.parse(mixed.stdout).error.message, /cannot be combined/);
|
|
606
608
|
assert.equal(existsSync(join(f.root, 'runs')), false);
|
|
607
609
|
});
|
|
610
|
+
test('an explicit null baseline installs no Skill in baseline, preserves identical prompts and replays without originals', async (t) => {
|
|
611
|
+
const f = setup(t), seen = [], prompts = [];
|
|
612
|
+
writeFileSync(f.requestPath, JSON.stringify({ ...f.body, baselineSkill: null, taskIds: ['fix'], maxCalls: 2, executorTimeoutSeconds: 17 }));
|
|
613
|
+
const executor = { describe: () => ({ kind: 'mock', model: 'offline-no-skill' }), run: async (prompt, workdir) => {
|
|
614
|
+
prompts.push(prompt);
|
|
615
|
+
const installed = existsSync(join(workdir, 'project-skills/answer-skill/SKILL.md'));
|
|
616
|
+
seen.push(installed);
|
|
617
|
+
writeFileSync(join(workdir, 'answer.txt'), installed ? '2' : '1');
|
|
618
|
+
return { output: 'done', tokens: { input: 10, cachedInput: 6, output: 2 } };
|
|
619
|
+
} };
|
|
620
|
+
const options = { ...f.options, executor }, preview = await runEvalComponent(f.requestPath, { ...options, dryRun: true });
|
|
621
|
+
assert.equal(preview.plan.request.baselineSkill, null);
|
|
622
|
+
assert.equal(preview.plan.evaluation.baseline, null);
|
|
623
|
+
assert.equal(preview.plan.evaluation.executorTimeoutSeconds, 17);
|
|
624
|
+
assert.equal(preview.plan.evaluation.plannedCalls, 2);
|
|
625
|
+
assert.equal(existsSync(f.runDir), false);
|
|
626
|
+
assert.equal(seen.length, 0);
|
|
627
|
+
const result = await runEvalComponent(f.requestPath, { ...options, dryRun: false, expectedPlanSha256: preview.plan.sha256 });
|
|
628
|
+
assert.deepEqual(seen, [false, true]);
|
|
629
|
+
assert.equal(prompts[0], prompts[1]);
|
|
630
|
+
assert.ok('identity' in result);
|
|
631
|
+
assert.equal(result.identity.baseline, null);
|
|
632
|
+
assert.equal(result.evidence.verified, true);
|
|
633
|
+
assert.ok(result.acceptance.reasons.some(r => r.code === 'REVISION_COMPARISON_REQUIRED'));
|
|
634
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
635
|
+
for (const path of [f.requestPath, join(f.root, 'bench'), join(f.root, 'old'), join(f.root, 'new')])
|
|
636
|
+
rmSync(path, { recursive: true });
|
|
637
|
+
const replay = await reportEvalComponent(f.runDir, { replay: true });
|
|
638
|
+
assert.equal(replay.evidence.verified, true);
|
|
639
|
+
const output = join(f.root, 'portable');
|
|
640
|
+
await exportEvaluation(f.runDir, output, { yes: true, log: () => { } });
|
|
641
|
+
assert.equal(existsSync(join(output, 'inputs/baseline-skill')), false);
|
|
642
|
+
assert.equal(JSON.parse(readFileSync(join(output, 'inputs/request.json'), 'utf8')).baselineSkill, null);
|
|
643
|
+
rmSync(f.runDir, { recursive: true });
|
|
644
|
+
const child = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000 });
|
|
645
|
+
assert.equal(child.status, 0, child.stderr);
|
|
646
|
+
const portable = JSON.parse(child.stdout);
|
|
647
|
+
assert.equal(portable.identity.baseline, null);
|
|
648
|
+
assert.equal(portable.acceptance.eligibleForUpgrade, false);
|
|
649
|
+
assert.equal(seen.length, 2);
|
|
650
|
+
});
|
|
651
|
+
test('null is an explicit baseline choice; missing, empty or malformed paths never silently select it', t => {
|
|
652
|
+
const f = setup(t), { baselineSkill: _previous, ...missing } = f.body;
|
|
653
|
+
assert.equal(parseEvalRequest({ ...f.body, baselineSkill: null }, f.root).baselineSkill, null);
|
|
654
|
+
assert.equal(parseEvalRequest(f.body, f.root).baselineSkill, join(f.root, 'old'));
|
|
655
|
+
for (const baselineSkill of [undefined, '', false, 0, {}])
|
|
656
|
+
assert.throws(() => parseEvalRequest({ ...f.body, baselineSkill }, f.root), /baselineSkill/);
|
|
657
|
+
assert.throws(() => parseEvalRequest(missing, f.root), /baselineSkill/);
|
|
658
|
+
assert.equal(f.calls(), 0);
|
|
659
|
+
});
|
|
660
|
+
function ordinaryOptions(f, overrides = {}) {
|
|
661
|
+
return { skillPath: join(f.root, 'new'), baselineSkillPath: join(f.root, 'old'), bench: join(f.root, 'bench'), agent: 'codex',
|
|
662
|
+
mode: 'installed', inputMode: 'workspace', trials: 1, maxCalls: 4, runsRoot: join(f.root, 'runs'), runGroup: 'component',
|
|
663
|
+
dryRun: true, yes: true, ...f.options, log: () => { }, ...overrides };
|
|
664
|
+
}
|
|
665
|
+
test('ordinary eval and request preview share the effective plan, timeout and all spending lines', async (t) => {
|
|
666
|
+
const f = setup(t), spendingBudget = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
|
|
667
|
+
writeFileSync(f.requestPath, JSON.stringify({ ...f.body, pairOrder: 'balanced', executorTimeoutSeconds: 17, spendingBudget }));
|
|
668
|
+
const request = await runEvalComponent(f.requestPath, { ...f.options, dryRun: true });
|
|
669
|
+
const ordinary = await runEvalCli(ordinaryOptions(f, { pairOrder: 'balanced', executorTimeoutSeconds: 17, spendingBudget }));
|
|
670
|
+
assert.ok('plan' in ordinary);
|
|
671
|
+
assert.deepEqual(ordinary.plan.evaluation, request.plan.evaluation);
|
|
672
|
+
assert.equal(ordinary.plan.implementationSha256, request.plan.implementationSha256);
|
|
673
|
+
assert.equal(ordinary.status, 'planned');
|
|
674
|
+
assert.equal(ordinary.acceptance.eligibleForUpgrade, false);
|
|
675
|
+
assert.equal(existsSync(join(f.root, 'runs')), false);
|
|
676
|
+
assert.equal(f.calls(), 0);
|
|
677
|
+
});
|
|
678
|
+
test('ordinary confirmed plans reject changed budget, timeout, ordering, selection and baseline before calls', async (t) => {
|
|
679
|
+
const f = setup(t), spendingBudget = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
|
|
680
|
+
const base = ordinaryOptions(f, { pairOrder: 'balanced', executorTimeoutSeconds: 17, spendingBudget });
|
|
681
|
+
const preview = await runEvalCli(base);
|
|
682
|
+
assert.ok('plan' in preview);
|
|
683
|
+
for (const change of [{ executorTimeoutSeconds: 18 }, { pairOrder: 'baseline-first' }, { spendingBudget: { ...spendingBudget, input: 999 } },
|
|
684
|
+
{ maxCalls: 5 }, { taskIds: ['fix'] }, { baselineSkillPath: undefined }]) {
|
|
685
|
+
await assert.rejects(() => runEvalCli({ ...base, ...change, dryRun: false }, preview.plan.sha256), /--plan-sha matching/);
|
|
686
|
+
}
|
|
687
|
+
assert.equal(f.calls(), 0);
|
|
688
|
+
assert.equal(existsSync(f.runDir), false);
|
|
689
|
+
});
|
|
690
|
+
test('ordinary execution seals the shared reviewed plan and retains replayable costs without component adoption', async (t) => {
|
|
691
|
+
const f = setup(t), spendingBudget = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
|
|
692
|
+
const base = ordinaryOptions(f, { executorTimeoutSeconds: 17, pairOrder: 'balanced', spendingBudget });
|
|
693
|
+
const preview = await runEvalCli(base);
|
|
694
|
+
assert.ok('plan' in preview);
|
|
695
|
+
const result = await runEvalCli({ ...base, dryRun: false }, preview.plan.sha256);
|
|
696
|
+
assert.equal(result.status, 'completed');
|
|
697
|
+
assert.ok('evidence' in result);
|
|
698
|
+
assert.equal(result.evidence.verified, true, result.evidence.reasons.join('; '));
|
|
699
|
+
assert.ok('costs' in result);
|
|
700
|
+
const native = JSON.parse(readFileSync(join(f.runDir, '_plan.json'), 'utf8'));
|
|
701
|
+
assert.deepEqual(native.details.reviewedPlan, preview.plan);
|
|
702
|
+
assert.equal(native.details.executorTimeoutSeconds, 17);
|
|
703
|
+
assert.equal(native.details.component, undefined);
|
|
704
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
705
|
+
for (const path of ['bench', 'old', 'new'])
|
|
706
|
+
rmSync(join(f.root, path), { recursive: true });
|
|
707
|
+
const replay = await reportEvalComponent(f.runDir, { replay: true });
|
|
708
|
+
assert.equal(replay.evidence.verified, true);
|
|
709
|
+
assert.ok('costs' in replay);
|
|
710
|
+
assert.deepEqual(replay.costs, result.costs);
|
|
711
|
+
assert.deepEqual(replay.spendingBudget?.limits, spendingBudget);
|
|
712
|
+
const output = join(f.root, 'portable');
|
|
713
|
+
await exportEvaluation(f.runDir, output, { yes: true, log: () => { } });
|
|
714
|
+
rmSync(f.runDir, { recursive: true });
|
|
715
|
+
const child = spawnSync(process.execPath, [join(output, 'reproduce.mjs')], { encoding: 'utf8', timeout: 30_000 });
|
|
716
|
+
assert.equal(child.status, 0, child.stderr);
|
|
717
|
+
const portable = JSON.parse(child.stdout);
|
|
718
|
+
assert.equal(portable.evidence.verified, true);
|
|
719
|
+
assert.deepEqual(portable.costs, result.costs);
|
|
720
|
+
assert.deepEqual(portable.spendingBudget.limits, spendingBudget);
|
|
721
|
+
assert.equal(portable.acceptance.eligibleForUpgrade, false);
|
|
722
|
+
assert.equal(f.calls(), 4);
|
|
723
|
+
});
|
|
724
|
+
test('ordinary and Agent no-Skill comparisons stop at the same budget line and keep the one invoked receipt', async (t) => {
|
|
725
|
+
const f = setup(t), spendingBudget = { input: 10, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 100 };
|
|
726
|
+
let calls = 0;
|
|
727
|
+
const executor = { describe: () => ({ kind: 'mock', model: 'offline-common-budget' }), run: async (_prompt, workdir) => {
|
|
728
|
+
calls++;
|
|
729
|
+
assert.equal(existsSync(join(workdir, 'project-skills/answer-skill')), false);
|
|
730
|
+
writeFileSync(join(workdir, 'answer.txt'), '1');
|
|
731
|
+
return { output: 'done', tokens: { input: 10, cachedInput: 6, output: 2 } };
|
|
732
|
+
} };
|
|
733
|
+
writeFileSync(f.requestPath, JSON.stringify({ ...f.body, baselineSkill: null, taskIds: ['fix'], maxCalls: 2, spendingBudget }));
|
|
734
|
+
const requestPreview = await runEvalComponent(f.requestPath, { ...f.options, executor, dryRun: true });
|
|
735
|
+
const request = await runEvalComponent(f.requestPath, { ...f.options, executor, dryRun: false, expectedPlanSha256: requestPreview.plan.sha256 });
|
|
736
|
+
const base = ordinaryOptions(f, { baselineSkillPath: undefined, taskIds: ['fix'], maxCalls: 2, spendingBudget, executor, runGroup: 'ordinary' });
|
|
737
|
+
const preview = await runEvalCli(base);
|
|
738
|
+
assert.ok('plan' in preview);
|
|
739
|
+
const ordinary = await runEvalCli({ ...base, dryRun: false }, preview.plan.sha256);
|
|
740
|
+
for (const result of [request, ordinary]) {
|
|
741
|
+
assert.equal(result.status, 'stopped');
|
|
742
|
+
assert.ok('spendingBudget' in result && result.spendingBudget);
|
|
743
|
+
assert.equal(result.spendingBudget.latestState.metrics.input.knownTotal, 10);
|
|
744
|
+
assert.ok(result.spendingBudget.latestState.reached.includes('input'));
|
|
745
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
746
|
+
}
|
|
747
|
+
assert.equal(calls, 2);
|
|
748
|
+
assert.equal(existsSync(join(f.runDir, 'fix/treatment/trial-1')), false);
|
|
749
|
+
assert.equal(existsSync(join(f.root, 'runs/ordinary/fix/treatment/trial-1')), false);
|
|
750
|
+
});
|
|
751
|
+
for (const [label, tokens] of [['missing cache', { input: 10, output: 2 }], ['partial', { input: 10, cachedInput: 6, output: 2 }]]) {
|
|
752
|
+
test(`ordinary ${label} usage cannot authorize a second budgeted invocation`, async (t) => {
|
|
753
|
+
const f = setup(t);
|
|
754
|
+
let calls = 0;
|
|
755
|
+
const executor = { describe: () => ({ kind: 'mock', model: 'offline-incomplete-budget' }), run: async (_prompt, workdir) => {
|
|
756
|
+
calls++;
|
|
757
|
+
writeFileSync(join(workdir, 'answer.txt'), '1');
|
|
758
|
+
return { output: 'done', tokens, ...(label === 'partial' ? { usageStatus: 'partial' } : {}) };
|
|
759
|
+
} };
|
|
760
|
+
const base = ordinaryOptions(f, { executor, spendingBudget: { input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 100 } });
|
|
761
|
+
const preview = await runEvalCli(base);
|
|
762
|
+
assert.ok('plan' in preview);
|
|
763
|
+
const result = await runEvalCli({ ...base, dryRun: false }, preview.plan.sha256);
|
|
764
|
+
assert.equal(result.status, 'stopped');
|
|
765
|
+
assert.equal(calls, 1);
|
|
766
|
+
assert.ok('spendingBudget' in result && result.spendingBudget);
|
|
767
|
+
assert.equal(result.spendingBudget.latestState.reason, 'FINAL_USAGE_MISSING');
|
|
768
|
+
assert.equal(result.acceptance.eligibleForUpgrade, false);
|
|
769
|
+
});
|
|
770
|
+
}
|
|
@@ -28,6 +28,14 @@ function numeric(value, label, min, max = Number.MAX_SAFE_INTEGER, integer = fal
|
|
|
28
28
|
}
|
|
29
29
|
return value;
|
|
30
30
|
}
|
|
31
|
+
export function parseExecutorTimeoutSeconds(value = DEFAULT_CLI_TIMEOUT_MS / 1000, label = 'executorTimeoutSeconds') {
|
|
32
|
+
return numeric(value, label, 1, 3600, true);
|
|
33
|
+
}
|
|
34
|
+
export function parsePairOrder(value = 'baseline-first', label = 'pairOrder') {
|
|
35
|
+
if (value !== 'baseline-first' && value !== 'balanced')
|
|
36
|
+
throw new Error(`${label} must be baseline-first or balanced.`);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
31
39
|
export function parseAcceptancePolicy(value = {}) {
|
|
32
40
|
const p = record(value, 'policy');
|
|
33
41
|
if (p.schemaVersion === 2) {
|
|
@@ -79,18 +87,16 @@ export function parseEvalRequest(value, baseDir) {
|
|
|
79
87
|
getAgent(agent);
|
|
80
88
|
if (r.purpose !== 'development' && r.purpose !== 'validation')
|
|
81
89
|
throw new Error('request.purpose must be development or validation.');
|
|
82
|
-
if (r.pairOrder !== undefined && r.pairOrder !== 'baseline-first' && r.pairOrder !== 'balanced')
|
|
83
|
-
throw new Error('request.pairOrder must be baseline-first or balanced.');
|
|
84
90
|
const runGroup = text(r.runGroup, 'request.runGroup');
|
|
85
91
|
if (!RUN_GROUP_PATTERN.test(runGroup))
|
|
86
92
|
throw new Error('request.runGroup is invalid.');
|
|
87
93
|
return { schemaVersion: 1,
|
|
88
|
-
baselineSkill: resolve(baseDir, text(r.baselineSkill, 'request.baselineSkill')),
|
|
94
|
+
baselineSkill: r.baselineSkill === null ? null : resolve(baseDir, text(r.baselineSkill, 'request.baselineSkill (use null for no installed Skill)')),
|
|
89
95
|
candidateSkill: resolve(baseDir, text(r.candidateSkill, 'request.candidateSkill')),
|
|
90
96
|
bench: resolve(baseDir, text(r.bench, 'request.bench')),
|
|
91
97
|
...(r.taskIds !== undefined ? { taskIds: parseTaskIds(r.taskIds) } : {}),
|
|
92
|
-
agent, purpose: r.purpose, pairOrder: r.pairOrder
|
|
93
|
-
executorTimeoutSeconds:
|
|
98
|
+
agent, purpose: r.purpose, pairOrder: parsePairOrder(r.pairOrder, 'request.pairOrder'),
|
|
99
|
+
executorTimeoutSeconds: parseExecutorTimeoutSeconds(r.executorTimeoutSeconds, 'request.executorTimeoutSeconds'),
|
|
94
100
|
trials: numeric(r.trials, 'request.trials', 1, 20, true),
|
|
95
101
|
maxCalls: numeric(r.maxCalls, 'request.maxCalls', 1, Number.MAX_SAFE_INTEGER, true),
|
|
96
102
|
...(r.spendingBudget !== undefined ? { spendingBudget: parseSpendingBudget(r.spendingBudget) } : {}),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Resolve existing ancestors so an uncreated output cannot hide behind an alias. */
|
|
5
|
+
export function physicalPath(path) {
|
|
6
|
+
let parent = resolve(path);
|
|
7
|
+
const parts = [];
|
|
8
|
+
while (!existsSync(parent)) {
|
|
9
|
+
parts.unshift(basename(parent));
|
|
10
|
+
parent = dirname(parent);
|
|
11
|
+
}
|
|
12
|
+
return join(realpathSync(parent), ...parts);
|
|
13
|
+
}
|
|
14
|
+
function contains(root, path) {
|
|
15
|
+
const rel = relative(root, path);
|
|
16
|
+
return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);
|
|
17
|
+
}
|
|
18
|
+
/** Preview and session setup share this read-only rule. */
|
|
19
|
+
export function assertEvaluationOutputLayout(output, inputs) {
|
|
20
|
+
const actual = physicalPath(output);
|
|
21
|
+
if ([resolve(output), actual].some(path => path.split(/[\\/]/).includes('.git'))) {
|
|
22
|
+
throw new Error('Experiment output must be outside Git metadata; choose a separate --runs-root.');
|
|
23
|
+
}
|
|
24
|
+
const implementation = fileURLToPath(new URL('../', import.meta.url));
|
|
25
|
+
for (const input of [inputs.benchDir, ...(inputs.targetDirs ?? []), implementation]) {
|
|
26
|
+
if (contains(physicalPath(input), actual)) {
|
|
27
|
+
throw new Error('Experiment output must be outside the bench, Skill/overlay and compiled runtime inputs; choose a sibling --runs-root before previewing or running.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExecutorFailure } from '../types.js';
|
|
1
2
|
import { evaluationSignal } from '../interruption.js';
|
|
2
3
|
function tokenCount(value) {
|
|
3
4
|
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
@@ -20,7 +21,7 @@ function tokenUsage(usage) {
|
|
|
20
21
|
...(cachedInput !== undefined ? { cachedInput } : {}),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
|
-
const
|
|
24
|
+
export const DEFAULT_API_TIMEOUT_MS = 2 * 60 * 1000;
|
|
24
25
|
export class ApiExecutor {
|
|
25
26
|
apiKey;
|
|
26
27
|
model;
|
|
@@ -34,11 +35,12 @@ export class ApiExecutor {
|
|
|
34
35
|
this.apiKey = options.apiKey;
|
|
35
36
|
this.model = options.model ?? 'gpt-4o';
|
|
36
37
|
this.baseUrl = (options.baseUrl ?? 'https://api.openai.com/v1').replace(/\/+$/, '');
|
|
37
|
-
this.timeoutMs = options.timeoutMs ??
|
|
38
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_API_TIMEOUT_MS;
|
|
38
39
|
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
39
40
|
}
|
|
40
|
-
static fromEnv(env = process.env) {
|
|
41
|
+
static fromEnv(env = process.env, options = {}) {
|
|
41
42
|
return new ApiExecutor({
|
|
43
|
+
...options,
|
|
42
44
|
apiKey: env['SKILLFIT_API_KEY'] ?? env['OPENAI_API_KEY'],
|
|
43
45
|
model: env['SKILLFIT_API_MODEL'],
|
|
44
46
|
baseUrl: env['SKILLFIT_API_BASE_URL'],
|
|
@@ -62,16 +64,28 @@ export class ApiExecutor {
|
|
|
62
64
|
}),
|
|
63
65
|
signal: interrupted ? AbortSignal.any([interrupted, AbortSignal.timeout(this.timeoutMs)]) : AbortSignal.timeout(this.timeoutMs),
|
|
64
66
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const body = await response.text();
|
|
68
|
+
let data, parsed = false;
|
|
69
|
+
try {
|
|
70
|
+
const value = JSON.parse(body);
|
|
71
|
+
parsed = true;
|
|
72
|
+
if (value && typeof value === 'object' && !Array.isArray(value))
|
|
73
|
+
data = value;
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
const content = data
|
|
75
|
+
catch { /* Retain the public body; malformed JSON cannot establish usage. */ }
|
|
76
|
+
const content = data?.choices?.[0]?.message?.content;
|
|
77
|
+
const tokens = tokenUsage(data?.usage);
|
|
78
|
+
const failure = (message) => new ExecutorFailure(message, {
|
|
79
|
+
output: typeof content === 'string' ? content : '', rawOutput: body,
|
|
80
|
+
...(tokens ? { tokens, usageStatus: 'final' } : {}),
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw failure(`API request failed with status ${response.status}: ${body.slice(0, 300)}`);
|
|
84
|
+
if (!parsed)
|
|
85
|
+
throw failure('API response was not valid JSON');
|
|
71
86
|
if (typeof content !== 'string') {
|
|
72
|
-
throw
|
|
87
|
+
throw failure('API response did not contain choices[0].message.content');
|
|
73
88
|
}
|
|
74
|
-
const tokens = tokenUsage(data.usage);
|
|
75
89
|
return tokens ? { output: content, tokens } : { output: content };
|
|
76
90
|
}
|
|
77
91
|
}
|
|
@@ -3,6 +3,7 @@ import { test } from 'node:test';
|
|
|
3
3
|
import { ApiExecutor } from './api.js';
|
|
4
4
|
import { summarizeCosts } from '../costs.js';
|
|
5
5
|
import { spendingBudgetState } from '../eval-budget.js';
|
|
6
|
+
import { ExecutorFailure } from '../types.js';
|
|
6
7
|
function jsonResponse(body, status = 200) {
|
|
7
8
|
return new Response(JSON.stringify(body), {
|
|
8
9
|
status,
|
|
@@ -100,6 +101,44 @@ test('ApiExecutor throws when the payload has no message content', async () => {
|
|
|
100
101
|
const executor = new ApiExecutor({ apiKey: 'k', fetchImpl });
|
|
101
102
|
await assert.rejects(() => executor.run('hi', '/tmp'), /choices\[0\]/);
|
|
102
103
|
});
|
|
104
|
+
test('API invalid content and HTTP errors retain reported final counters and public response', async () => {
|
|
105
|
+
for (const [content, status] of [[null, 200], [undefined, 200], [{ text: 'unsupported' }, 200], ['retained failed output', 500]]) {
|
|
106
|
+
let calls = 0;
|
|
107
|
+
const payload = { choices: [{ message: { content, refusal: 'synthetic refusal' } }],
|
|
108
|
+
usage: { prompt_tokens: 123, completion_tokens: 17, prompt_tokens_details: { cached_tokens: 23 } } };
|
|
109
|
+
const executor = new ApiExecutor({ apiKey: 'synthetic-key-not-in-evidence', fetchImpl: async () => { calls++; return jsonResponse(payload, status); } });
|
|
110
|
+
await assert.rejects(executor.run('offline'), error => {
|
|
111
|
+
assert.ok(error instanceof ExecutorFailure);
|
|
112
|
+
assert.equal(error.executorInvoked, true);
|
|
113
|
+
assert.deepEqual(error.result.tokens, { input: 123, cachedInput: 23, output: 17 });
|
|
114
|
+
assert.equal(error.result.usageStatus, 'final');
|
|
115
|
+
assert.equal(error.result.rawOutput, JSON.stringify(payload));
|
|
116
|
+
assert.equal(error.result.output, typeof content === 'string' ? content : '');
|
|
117
|
+
assert.equal(JSON.stringify(error.result).includes('synthetic-key-not-in-evidence'), false);
|
|
118
|
+
return true;
|
|
119
|
+
});
|
|
120
|
+
assert.equal(calls, 1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
test('malformed API payloads retain raw evidence without guessing missing usage', async () => {
|
|
124
|
+
for (const body of ['{broken JSON', 'null', '[]', '{"choices":[]}']) {
|
|
125
|
+
const executor = new ApiExecutor({ apiKey: 'offline-only', fetchImpl: async () => new Response(body) });
|
|
126
|
+
await assert.rejects(executor.run('offline'), error => {
|
|
127
|
+
assert.ok(error instanceof ExecutorFailure);
|
|
128
|
+
assert.equal(error.result.rawOutput, body);
|
|
129
|
+
assert.equal(error.result.tokens, undefined);
|
|
130
|
+
assert.equal(error.result.usageStatus, undefined);
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const executor = new ApiExecutor({ apiKey: 'offline-only', fetchImpl: async () => jsonResponse({ choices: [], usage: { prompt_tokens: 12 } }) });
|
|
135
|
+
await assert.rejects(executor.run('offline'), error => {
|
|
136
|
+
assert.ok(error instanceof ExecutorFailure);
|
|
137
|
+
assert.deepEqual(error.result.tokens, { input: 12 });
|
|
138
|
+
assert.equal(error.result.usageStatus, 'final');
|
|
139
|
+
return true;
|
|
140
|
+
});
|
|
141
|
+
});
|
|
103
142
|
test('ApiExecutor requires an API key', () => {
|
|
104
143
|
assert.throws(() => new ApiExecutor(), /API key/);
|
|
105
144
|
});
|
|
@@ -116,3 +155,21 @@ test('ApiExecutor.fromEnv reads SKILLFIT_API_KEY first', () => {
|
|
|
116
155
|
test('ApiExecutor.fromEnv throws without any key', () => {
|
|
117
156
|
assert.throws(() => ApiExecutor.fromEnv({}), /API key/);
|
|
118
157
|
});
|
|
158
|
+
test('API environment construction applies an explicit deadline to fake fetch without any network call', async () => {
|
|
159
|
+
let observed = false;
|
|
160
|
+
const executor = ApiExecutor.fromEnv({ SKILLFIT_API_KEY: 'offline-only' }, { timeoutMs: 10,
|
|
161
|
+
fetchImpl: async (_url, init) => new Promise((_resolve, reject) => {
|
|
162
|
+
observed = true;
|
|
163
|
+
const signal = init.signal;
|
|
164
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
165
|
+
}) });
|
|
166
|
+
// AbortSignal.timeout uses an unreferenced timer; keep only this offline test alive.
|
|
167
|
+
const timer = setTimeout(() => { }, 1000);
|
|
168
|
+
try {
|
|
169
|
+
await assert.rejects(() => executor.run('offline'), error => error instanceof Error && error.name === 'TimeoutError');
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
assert.equal(observed, true);
|
|
175
|
+
});
|
|
@@ -60,6 +60,7 @@ export class CliExecutor {
|
|
|
60
60
|
sessions;
|
|
61
61
|
homeDir;
|
|
62
62
|
triggerSkillName;
|
|
63
|
+
streamJson;
|
|
63
64
|
triggerToolName;
|
|
64
65
|
projectTrustConfigArg;
|
|
65
66
|
clock;
|
|
@@ -82,6 +83,7 @@ export class CliExecutor {
|
|
|
82
83
|
this.sessions = options.sessions;
|
|
83
84
|
this.homeDir = options.homeDir;
|
|
84
85
|
this.triggerSkillName = options.triggerSkillName;
|
|
86
|
+
this.streamJson = options.streamJson ?? (options.triggerSkillName !== undefined);
|
|
85
87
|
this.triggerToolName = options.triggerToolName ?? DEFAULT_TRIGGER_TOOL_NAME;
|
|
86
88
|
this.projectTrustConfigArg = options.projectTrustConfigArg;
|
|
87
89
|
this.clock = options.clock;
|
|
@@ -94,30 +96,16 @@ export class CliExecutor {
|
|
|
94
96
|
if (opts?.trustProjectConfig && !projectTrustConfigArg) {
|
|
95
97
|
throw new Error(`Agent "${agent.id}" has no project trust override in the matrix`);
|
|
96
98
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
throw new Error(`Agent "${agent.id}" has no headless streamJson command template; trigger detection is unavailable for it`);
|
|
101
|
-
}
|
|
102
|
-
return new CliExecutor({
|
|
103
|
-
argv: streamJson.argv,
|
|
104
|
-
label: agent.id,
|
|
105
|
-
timeoutMs: opts.timeoutMs,
|
|
106
|
-
promptVia: headless.promptVia,
|
|
107
|
-
promptFile: headless.promptFile,
|
|
108
|
-
usageFromSessionLog: headless.usageFromSessionLog ?? false,
|
|
109
|
-
partialUsageFromSessionLog: headless.partialUsageFromSessionLog ?? false,
|
|
110
|
-
sessions: agent.sessions,
|
|
111
|
-
triggerSkillName: opts.triggerSkillName,
|
|
112
|
-
triggerToolName: streamJson.triggerToolName,
|
|
113
|
-
projectTrustConfigArg,
|
|
114
|
-
});
|
|
99
|
+
const streamJson = headless.streamJson;
|
|
100
|
+
if (opts?.triggerSkillName !== undefined && !streamJson?.argv.length) {
|
|
101
|
+
throw new Error(`Agent "${agent.id}" has no headless streamJson command template; trigger detection is unavailable for it`);
|
|
115
102
|
}
|
|
116
103
|
if (!headless || headless.argv.length === 0) {
|
|
117
104
|
throw new Error(`No default headless command template for agent "${agent.id}"`);
|
|
118
105
|
}
|
|
119
106
|
return new CliExecutor({
|
|
120
|
-
argv: headless.argv,
|
|
107
|
+
argv: streamJson?.argv ?? headless.argv,
|
|
108
|
+
streamJson: streamJson !== undefined,
|
|
121
109
|
label: agent.id,
|
|
122
110
|
timeoutMs: opts?.timeoutMs,
|
|
123
111
|
promptVia: headless.promptVia,
|
|
@@ -125,6 +113,8 @@ export class CliExecutor {
|
|
|
125
113
|
usageFromSessionLog: headless.usageFromSessionLog ?? false,
|
|
126
114
|
partialUsageFromSessionLog: headless.partialUsageFromSessionLog ?? false,
|
|
127
115
|
sessions: agent.sessions,
|
|
116
|
+
triggerSkillName: opts?.triggerSkillName,
|
|
117
|
+
triggerToolName: streamJson?.triggerToolName,
|
|
128
118
|
projectTrustConfigArg,
|
|
129
119
|
});
|
|
130
120
|
}
|
|
@@ -182,7 +172,7 @@ export class CliExecutor {
|
|
|
182
172
|
let stopping = false;
|
|
183
173
|
let drainTimer;
|
|
184
174
|
const parseResult = () => ({
|
|
185
|
-
...(this.
|
|
175
|
+
...(this.streamJson
|
|
186
176
|
? parseStreamJsonTranscript(stdout, this.triggerToolName, this.triggerSkillName)
|
|
187
177
|
: { output: stdout }), executionTiming: deadline.snapshot(),
|
|
188
178
|
});
|
|
@@ -280,7 +270,7 @@ export class CliExecutor {
|
|
|
280
270
|
return;
|
|
281
271
|
}
|
|
282
272
|
if (code !== 0) {
|
|
283
|
-
const detail = (this.
|
|
273
|
+
const detail = (this.streamJson ? terminalStreamError(stdout) : null)
|
|
284
274
|
?? stderr.trim().slice(0, 500);
|
|
285
275
|
rejectPromise(failure(`"${command}" exited with code ${code ?? 'null'}${detail ? `: ${detail}` : ''}`));
|
|
286
276
|
return;
|
|
@@ -385,7 +375,7 @@ function parseStreamJsonTranscript(stdout, triggerToolName, skillName) {
|
|
|
385
375
|
}
|
|
386
376
|
const args = fnRecord.arguments;
|
|
387
377
|
const argsText = typeof args === 'string' ? args : JSON.stringify(args ?? null);
|
|
388
|
-
if (argsText.includes(skillName)) {
|
|
378
|
+
if (skillName !== undefined && argsText.includes(skillName)) {
|
|
389
379
|
triggered = true;
|
|
390
380
|
}
|
|
391
381
|
}
|
|
@@ -409,7 +399,7 @@ function parseStreamJsonTranscript(stdout, triggerToolName, skillName) {
|
|
|
409
399
|
}
|
|
410
400
|
if (blockRecord.type === 'tool_use' &&
|
|
411
401
|
blockRecord.name === triggerToolName &&
|
|
412
|
-
JSON.stringify(blockRecord.input ?? null).includes(skillName)) {
|
|
402
|
+
skillName !== undefined && JSON.stringify(blockRecord.input ?? null).includes(skillName)) {
|
|
413
403
|
triggered = true;
|
|
414
404
|
}
|
|
415
405
|
}
|
|
@@ -446,7 +436,7 @@ function parseStreamJsonTranscript(stdout, triggerToolName, skillName) {
|
|
|
446
436
|
}
|
|
447
437
|
if (itemRecord.type === 'command_execution' && typeof itemRecord.command === 'string') {
|
|
448
438
|
const normalized = itemRecord.command.replace(/\\+/g, '/');
|
|
449
|
-
if (normalized.includes(`skills/${skillName}/SKILL.md`)) {
|
|
439
|
+
if (skillName !== undefined && normalized.includes(`skills/${skillName}/SKILL.md`)) {
|
|
450
440
|
triggered = true;
|
|
451
441
|
}
|
|
452
442
|
}
|
|
@@ -467,5 +457,5 @@ function parseStreamJsonTranscript(stdout, triggerToolName, skillName) {
|
|
|
467
457
|
tokens = undefined;
|
|
468
458
|
usageStatus = coverage.input === usageTurns && coverage.output === usageTurns ? 'final' : 'partial';
|
|
469
459
|
}
|
|
470
|
-
return { output: textParts.join('\n'), skillTriggered: triggered, rawOutput: stdout, tokens, usageStatus };
|
|
460
|
+
return { output: textParts.join('\n'), ...(skillName === undefined ? {} : { skillTriggered: triggered }), rawOutput: stdout, tokens, usageStatus };
|
|
471
461
|
}
|