skillfit 0.11.0 → 0.13.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 +68 -104
- package/README.zh-CN.md +68 -101
- package/benches/README.md +6 -2
- package/dist/cli.js +28 -16
- package/dist/commands/bench-calibration.js +5 -1
- package/dist/commands/bench-check-report.js +1 -34
- 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 +157 -328
- package/dist/commands/eval-api-failure.test.js +46 -0
- package/dist/commands/eval-layout.test.js +126 -0
- package/dist/commands/eval-preflight-error.js +9 -0
- package/dist/commands/eval-preflight.js +4 -11
- package/dist/commands/eval-report.js +6 -459
- package/dist/commands/eval.js +7 -32
- package/dist/commands/install.js +14 -98
- package/dist/harness/agent-preflight.js +18 -2
- package/dist/harness/bench-check.js +277 -0
- package/dist/harness/bench-diagnostics.js +34 -0
- package/dist/harness/bench-location.js +29 -0
- package/dist/harness/bench-location.test.js +33 -0
- package/dist/harness/bench.js +8 -3
- package/dist/harness/eval-acceptance.js +1 -1
- package/dist/harness/eval-audit.js +2 -2
- package/dist/harness/eval-manifest.js +456 -0
- package/dist/harness/evaluation-layout.js +30 -0
- package/dist/harness/executors/api.js +20 -7
- package/dist/harness/executors/cli.js +15 -25
- package/dist/harness/experiment-session.js +5 -15
- package/dist/harness/hash.js +3 -1
- package/dist/harness/runner.js +5 -4
- package/dist/harness/single-arm-audit.js +1 -1
- package/dist/harness/trigger.js +1 -1
- package/dist/harness/verifier-timeout.js +8 -0
- package/dist/harness/verifier-timeout.test.js +76 -0
- package/dist/install/constants.js +1 -0
- package/dist/install/transaction.js +112 -0
- package/docs/README.md +65 -0
- package/docs/architecture.md +86 -0
- package/docs/archive-delivery.md +83 -0
- package/docs/archive-inventory.md +91 -0
- package/docs/bench-authoring.md +23 -3
- package/docs/bench-drafting.md +75 -0
- package/docs/case-management.md +12 -1
- package/docs/eval-agent-preflight.md +15 -2
- package/docs/eval-costs.md +28 -2
- package/docs/eval-planning.md +14 -0
- package/docs/evaluation-input-snapshots.md +20 -4
- package/docs/evaluation-reports.md +1 -1
- package/docs/first-real-eval.md +28 -3
- package/docs/growth-roadmap-2026-10.md +23 -18
- package/docs/package-contents.md +73 -0
- package/docs/plans/2026-10-17-workflow-foundations.md +37 -2
- package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
- package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
- package/docs/plans/2026-10-20-delivery-verification.json +146 -0
- package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
- package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
- package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
- 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-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 +54 -11
- package/docs/releases/0.12.0-attestation-check.json +22 -0
- package/docs/releases/0.12.0-attestations.json +155 -0
- package/docs/releases/0.12.0-ci-registry-install.json +90 -0
- package/docs/releases/0.12.0-feature-smoke.json +34 -0
- package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
- package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
- package/docs/releases/0.12.0-local-registry-install.json +75 -0
- package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
- package/docs/releases/0.12.0-registry-metadata.json +96 -0
- package/docs/releases/0.12.0-signatures.txt +6 -0
- package/docs/releases/0.12.0-verification.json +99 -0
- package/docs/releases/0.12.0.md +82 -0
- package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
- package/docs/releases/0.13.0-preparation.json +102 -0
- package/docs/releases/0.13.0.md +61 -0
- package/docs/releases/archive-delivery-smoke.mjs +37 -0
- package/docs/reproducible-offline-example.md +1 -1
- package/docs/schemas/agent-preflight.schema.json +1 -1
- package/docs/verifier-contract.md +9 -0
- package/evidence/README.md +24 -1
- package/evidence/archive-catalog.v1.json +8044 -0
- package/evidence/fetch-archives.mjs +211 -0
- package/package.json +9 -2
- package/skills/skillfit/SKILL.md +25 -5
- package/dist/cli.test.js +0 -193
- package/dist/commands/bench-calibration.test.js +0 -237
- package/dist/commands/bench-check-json.test.js +0 -242
- package/dist/commands/bench-manage.test.js +0 -87
- package/dist/commands/bench.test.js +0 -1162
- package/dist/commands/bundle.test.js +0 -142
- package/dist/commands/calibration-cli.test.js +0 -145
- package/dist/commands/doctor.test.js +0 -280
- package/dist/commands/eval-agent-preflight.test.js +0 -245
- package/dist/commands/eval-export-modes.test.js +0 -350
- package/dist/commands/eval-export.test.js +0 -279
- package/dist/commands/eval-interruption.test.js +0 -238
- package/dist/commands/eval-preflight.test.js +0 -382
- package/dist/commands/eval-report.test.js +0 -367
- package/dist/commands/eval.test.js +0 -503
- package/dist/commands/evaluation-report.test.js +0 -243
- package/dist/commands/install.test.js +0 -555
- package/dist/commands/replay-cancellation.test.js +0 -105
- package/dist/commands/report.test.js +0 -110
- package/dist/commands/setup.test.js +0 -150
- package/dist/commands/upstream.test.js +0 -139
- package/dist/commands/workflow-entrypoints.test.js +0 -137
- package/dist/docs.test.js +0 -154
- package/dist/frontmatter.test.js +0 -49
- package/dist/harness/bench.test.js +0 -109
- package/dist/harness/bundle.test.js +0 -71
- package/dist/harness/codex-usage.test.js +0 -87
- package/dist/harness/costs.test.js +0 -92
- package/dist/harness/eval-budget.test.js +0 -237
- package/dist/harness/eval-component.test.js +0 -770
- package/dist/harness/eval-efficiency.test.js +0 -56
- package/dist/harness/execution-timing.test.js +0 -61
- package/dist/harness/executors/api.test.js +0 -136
- package/dist/harness/executors/cli.test.js +0 -510
- package/dist/harness/executors/mock.test.js +0 -43
- package/dist/harness/experiment-session.test.js +0 -317
- package/dist/harness/installed-skill.test.js +0 -162
- package/dist/harness/interruption.test.js +0 -31
- package/dist/harness/judge-accounting.test.js +0 -216
- package/dist/harness/judge.test.js +0 -181
- package/dist/harness/kimi-usage.test.js +0 -62
- package/dist/harness/native-diff.test.js +0 -53
- package/dist/harness/oss-lru-cache.test.js +0 -79
- package/dist/harness/oss-normalize-url.test.js +0 -64
- package/dist/harness/oss-regression-witness.test.js +0 -89
- package/dist/harness/oss-skill-followup.test.js +0 -59
- package/dist/harness/prompt.test.js +0 -48
- package/dist/harness/receipts.test.js +0 -148
- package/dist/harness/report.test.js +0 -297
- package/dist/harness/runner.test.js +0 -635
- package/dist/harness/skill-revision.test.js +0 -148
- package/dist/harness/stats.test.js +0 -124
- package/dist/harness/target.test.js +0 -60
- package/dist/harness/trigger.test.js +0 -261
- package/dist/harness/verifier-summary.test.js +0 -99
- package/dist/harness/verifier.test.js +0 -128
- package/dist/harness/waza-behavior.test.js +0 -139
- package/dist/mcp/probe.test.js +0 -139
- package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
- package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { verdictFor } from './report.js';
|
|
2
|
+
import { mcnemarExactP } from './stats.js';
|
|
3
|
+
import { validateSkillInstallDir } from './installed-skill.js';
|
|
4
|
+
import { assertCostTotals, COST_METRICS } from './costs.js';
|
|
5
|
+
import { parseInvocationCosts } from './invocation-costs.js';
|
|
6
|
+
function object(value, label) {
|
|
7
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
8
|
+
throw new Error(`${label} must be an object`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function string(value, label) {
|
|
13
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
14
|
+
throw new Error(`${label} must be a non-empty string`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function number(value, label, min = -Infinity, max = Infinity) {
|
|
18
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max) {
|
|
19
|
+
throw new Error(`${label} must be a finite number between ${min} and ${max}`);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function integer(value, label, min = 0) {
|
|
24
|
+
const result = number(value, label, min);
|
|
25
|
+
if (!Number.isInteger(result))
|
|
26
|
+
throw new Error(`${label} must be an integer`);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function hash(value, label) {
|
|
30
|
+
const result = string(value, label);
|
|
31
|
+
if (!/^[0-9a-f]{64}$/i.test(result))
|
|
32
|
+
throw new Error(`${label} must be a SHA-256 hex digest`);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function verdict(value, label) {
|
|
36
|
+
if (value !== 'effective' && value !== 'ineffective' && value !== 'inconclusive') {
|
|
37
|
+
throw new Error(`${label} must be effective, ineffective, or inconclusive`);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function experiment(value) {
|
|
42
|
+
if (value === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const item = object(value, 'experiment');
|
|
45
|
+
if (item['schemaVersion'] !== 1)
|
|
46
|
+
throw new Error('experiment.schemaVersion must be 1');
|
|
47
|
+
const status = item['status'];
|
|
48
|
+
if (status !== 'completed' && status !== 'stopped' && status !== 'incomplete')
|
|
49
|
+
throw new Error('experiment.status must be completed, stopped, or incomplete');
|
|
50
|
+
const plannedCalls = integer(item['plannedCalls'], 'experiment.plannedCalls', 1);
|
|
51
|
+
const maxCalls = integer(item['maxCalls'], 'experiment.maxCalls', 1);
|
|
52
|
+
const callsStarted = integer(item['callsStarted'], 'experiment.callsStarted');
|
|
53
|
+
const callsFinished = integer(item['callsFinished'], 'experiment.callsFinished');
|
|
54
|
+
const stopReason = item['stopReason'] === null ? null : string(item['stopReason'], 'experiment.stopReason');
|
|
55
|
+
if (item['stopCode'] !== undefined && !['EXECUTION_FAILED', 'FINAL_USAGE_MISSING', 'SPENDING_BUDGET_REACHED'].includes(String(item['stopCode'])))
|
|
56
|
+
throw new Error('Invalid experiment.stopCode');
|
|
57
|
+
if (![plannedCalls, maxCalls, callsStarted, callsFinished].every(Number.isSafeInteger) ||
|
|
58
|
+
maxCalls < plannedCalls || callsStarted > plannedCalls || callsFinished > callsStarted ||
|
|
59
|
+
(status === 'completed' && (stopReason !== null || callsFinished !== plannedCalls)) ||
|
|
60
|
+
(status === 'stopped' && stopReason === null) ||
|
|
61
|
+
(status === 'incomplete' && (stopReason !== null || callsFinished === plannedCalls))) {
|
|
62
|
+
throw new Error('experiment status, call counts, ceiling, and stop reason contradict each other');
|
|
63
|
+
}
|
|
64
|
+
return { schemaVersion: 1, status, plannedCalls, maxCalls, callsStarted, callsFinished, stopReason,
|
|
65
|
+
planSha256: hash(item['planSha256'], 'experiment.planSha256'),
|
|
66
|
+
...(item['stopCode'] === undefined ? {} : { stopCode: item['stopCode'] }) };
|
|
67
|
+
}
|
|
68
|
+
function counts(value, label) {
|
|
69
|
+
const item = object(value, label);
|
|
70
|
+
const passes = integer(item['passes'], `${label}.passes`);
|
|
71
|
+
const trials = integer(item['trials'], `${label}.trials`);
|
|
72
|
+
const errors = integer(item['errors'], `${label}.errors`);
|
|
73
|
+
if (passes > trials)
|
|
74
|
+
throw new Error(`${label}.passes cannot exceed trials`);
|
|
75
|
+
const meanScore = item['meanScore'] === undefined || item['meanScore'] === null
|
|
76
|
+
? null : number(item['meanScore'], `${label}.meanScore`, 0, 1);
|
|
77
|
+
const rawTokens = item['tokens'] === undefined || item['tokens'] === null
|
|
78
|
+
? null : object(item['tokens'], `${label}.tokens`);
|
|
79
|
+
const tokens = rawTokens === null ? null : {
|
|
80
|
+
input: number(rawTokens['input'], `${label}.tokens.input`, 0),
|
|
81
|
+
output: number(rawTokens['output'], `${label}.tokens.output`, 0),
|
|
82
|
+
};
|
|
83
|
+
const rawCoverage = item['tokenCoverage'] === undefined
|
|
84
|
+
? null : object(item['tokenCoverage'], `${label}.tokenCoverage`);
|
|
85
|
+
const tokenCoverage = rawCoverage === null ? null : {
|
|
86
|
+
input: integer(rawCoverage['input'], `${label}.tokenCoverage.input`),
|
|
87
|
+
output: integer(rawCoverage['output'], `${label}.tokenCoverage.output`),
|
|
88
|
+
};
|
|
89
|
+
if (tokenCoverage && (tokenCoverage.input > trials || tokenCoverage.output > trials)) {
|
|
90
|
+
throw new Error(`${label}.tokenCoverage cannot exceed graded trials`);
|
|
91
|
+
}
|
|
92
|
+
if (tokenCoverage) {
|
|
93
|
+
for (const field of ['input', 'output']) {
|
|
94
|
+
if ((tokenCoverage[field] > 0 && tokens === null) ||
|
|
95
|
+
(tokenCoverage[field] === 0 && tokens !== null && tokens[field] !== 0)) {
|
|
96
|
+
throw new Error(`${label}.tokenCoverage contradicts its recorded tokens`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (meanScore !== null && trials === 0)
|
|
101
|
+
throw new Error(`${label}.meanScore requires graded trials`);
|
|
102
|
+
const rawReads = item['skillReads'] === undefined ? null : object(item['skillReads'], `${label}.skillReads`);
|
|
103
|
+
const skillReads = rawReads === null ? null : {
|
|
104
|
+
observed: integer(rawReads['observed'], `${label}.skillReads.observed`),
|
|
105
|
+
unobserved: integer(rawReads['unobserved'], `${label}.skillReads.unobserved`),
|
|
106
|
+
unknown: integer(rawReads['unknown'], `${label}.skillReads.unknown`),
|
|
107
|
+
};
|
|
108
|
+
if (skillReads && skillReads.observed + skillReads.unobserved + skillReads.unknown !== trials) {
|
|
109
|
+
throw new Error(`${label}.skillReads must total the surviving graded trials`);
|
|
110
|
+
}
|
|
111
|
+
return { passes, trials, errors, meanScore, tokens, tokenCoverage, skillReads };
|
|
112
|
+
}
|
|
113
|
+
function facets(value, label) {
|
|
114
|
+
if (value === undefined)
|
|
115
|
+
return [];
|
|
116
|
+
if (!Array.isArray(value))
|
|
117
|
+
throw new Error(`${label} must be an array`);
|
|
118
|
+
return value.map((raw, index) => {
|
|
119
|
+
const item = object(raw, `${label}[${index}]`);
|
|
120
|
+
return {
|
|
121
|
+
name: string(item['name'], `${label}[${index}].name`),
|
|
122
|
+
baselinePassRate: number(item['baselinePassRate'], `${label}[${index}].baselinePassRate`, 0, 1),
|
|
123
|
+
treatmentPassRate: number(item['treatmentPassRate'], `${label}[${index}].treatmentPassRate`, 0, 1),
|
|
124
|
+
baselineTrials: integer(item['baselineTrials'], `${label}[${index}].baselineTrials`),
|
|
125
|
+
treatmentTrials: integer(item['treatmentTrials'], `${label}[${index}].treatmentTrials`),
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function row(value, label, id) {
|
|
130
|
+
const item = object(value, label);
|
|
131
|
+
const conditions = object(item['conditions'], `${label}.conditions`);
|
|
132
|
+
return {
|
|
133
|
+
costs: item['costs'] === undefined ? null : parseCosts(item['costs'], `${label}.costs`),
|
|
134
|
+
id,
|
|
135
|
+
baseline: counts(conditions['baseline'], `${label}.conditions.baseline`),
|
|
136
|
+
treatment: counts(conditions['treatment'], `${label}.conditions.treatment`),
|
|
137
|
+
deltaPassRate: number(item['deltaPassRate'], `${label}.deltaPassRate`, -1, 1),
|
|
138
|
+
verdict: verdict(item['verdict'], `${label}.verdict`),
|
|
139
|
+
scoreDelta: item['scoreDelta'] === undefined || item['scoreDelta'] === null
|
|
140
|
+
? null : number(item['scoreDelta'], `${label}.scoreDelta`, -1, 1),
|
|
141
|
+
facets: facets(item['facets'], `${label}.facets`),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function parseCosts(value, label) {
|
|
145
|
+
const item = object(value, label);
|
|
146
|
+
if (item['schemaVersion'] !== 1)
|
|
147
|
+
throw new Error(`${label}.schemaVersion must be 1`);
|
|
148
|
+
const scope = (name) => {
|
|
149
|
+
const arms = object(item[name], `${label}.${name}`);
|
|
150
|
+
const population = (arm) => {
|
|
151
|
+
const path = `${label}.${name}.${arm}`;
|
|
152
|
+
const raw = object(arms[arm], path);
|
|
153
|
+
const runs = integer(raw['runs'], `${path}.runs`);
|
|
154
|
+
const passes = integer(raw['passes'], `${path}.passes`);
|
|
155
|
+
if (passes > runs)
|
|
156
|
+
throw new Error(`${path}.passes cannot exceed runs`);
|
|
157
|
+
const rawMetrics = object(raw['metrics'], `${path}.metrics`);
|
|
158
|
+
const metrics = Object.fromEntries(COST_METRICS.map(metric => {
|
|
159
|
+
const measure = object(rawMetrics[metric], `${path}.metrics.${metric}`);
|
|
160
|
+
const coverage = object(measure['coverage'], `${path}.metrics.${metric}.coverage`);
|
|
161
|
+
const parsed = {
|
|
162
|
+
knownTotal: number(measure['knownTotal'], `${path}.metrics.${metric}.knownTotal`, 0),
|
|
163
|
+
coverage: {
|
|
164
|
+
final: integer(coverage['final'], `${path}.metrics.${metric}.coverage.final`),
|
|
165
|
+
partial: integer(coverage['partial'], `${path}.metrics.${metric}.coverage.partial`),
|
|
166
|
+
unknown: integer(coverage['unknown'], `${path}.metrics.${metric}.coverage.unknown`),
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
const c = parsed.coverage;
|
|
170
|
+
if (c.final + c.partial + c.unknown !== runs ||
|
|
171
|
+
(c.final + c.partial === 0 && parsed.knownTotal !== 0))
|
|
172
|
+
throw new Error(`${path}.metrics.${metric} contradicts coverage`);
|
|
173
|
+
if (metric === 'durationSeconds' && (c.partial !== 0 || c.unknown !== 0))
|
|
174
|
+
throw new Error(`${path} elapsed time must cover every invocation`);
|
|
175
|
+
return [metric, parsed];
|
|
176
|
+
}));
|
|
177
|
+
const cache = metrics.cachedInput;
|
|
178
|
+
const uncached = metrics.uncachedInput;
|
|
179
|
+
if (JSON.stringify(cache.coverage) !== JSON.stringify(uncached.coverage))
|
|
180
|
+
throw new Error(`${path} cache partition coverage must match`);
|
|
181
|
+
if (cache.coverage.final + cache.coverage.partial > metrics.input.coverage.final + metrics.input.coverage.partial ||
|
|
182
|
+
cache.coverage.final > metrics.input.coverage.final ||
|
|
183
|
+
cache.knownTotal + uncached.knownTotal > metrics.input.knownTotal + 1e-6)
|
|
184
|
+
throw new Error(`${path} cache partition contradicts input`);
|
|
185
|
+
if (cache.coverage.final + cache.coverage.partial === metrics.input.coverage.final + metrics.input.coverage.partial &&
|
|
186
|
+
Math.abs(cache.knownTotal + uncached.knownTotal - metrics.input.knownTotal) > 1e-6)
|
|
187
|
+
throw new Error(`${path} cache partition disagrees with input`);
|
|
188
|
+
return { runs, passes, metrics };
|
|
189
|
+
};
|
|
190
|
+
return { baseline: population('baseline'), treatment: population('treatment') };
|
|
191
|
+
};
|
|
192
|
+
const notInvoked = object(item['notInvoked'], `${label}.notInvoked`);
|
|
193
|
+
return { schemaVersion: 1, paired: scope('paired'), attempts: scope('attempts'), notInvoked: {
|
|
194
|
+
baseline: integer(notInvoked['baseline'], `${label}.notInvoked.baseline`),
|
|
195
|
+
treatment: integer(notInvoked['treatment'], `${label}.notInvoked.treatment`),
|
|
196
|
+
} };
|
|
197
|
+
}
|
|
198
|
+
function checkCostCounts(row, declaredRuns, label) {
|
|
199
|
+
const costs = row.costs;
|
|
200
|
+
if (!costs)
|
|
201
|
+
return;
|
|
202
|
+
for (const arm of ['baseline', 'treatment']) {
|
|
203
|
+
const paired = costs.paired[arm];
|
|
204
|
+
const attempts = costs.attempts[arm];
|
|
205
|
+
if (paired.runs !== row[arm].trials || paired.passes !== row[arm].passes ||
|
|
206
|
+
attempts.runs + costs.notInvoked[arm] !== declaredRuns ||
|
|
207
|
+
paired.runs > attempts.runs || paired.passes > attempts.passes ||
|
|
208
|
+
attempts.passes - paired.passes > attempts.runs - paired.runs)
|
|
209
|
+
throw new Error(`${label}.costs disagree with declared/graded counts`);
|
|
210
|
+
for (const metric of COST_METRICS) {
|
|
211
|
+
if (paired.metrics[metric].knownTotal > attempts.metrics[metric].knownTotal + 1e-6)
|
|
212
|
+
throw new Error(`${label}.costs paired spending exceeds all invocations`);
|
|
213
|
+
for (const status of ['final', 'partial', 'unknown']) {
|
|
214
|
+
if (paired.metrics[metric].coverage[status] > attempts.metrics[metric].coverage[status])
|
|
215
|
+
throw new Error(`${label}.costs paired coverage exceeds all invocations`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function checkDelta(value, label) {
|
|
221
|
+
if (value.baseline.trials !== value.treatment.trials) {
|
|
222
|
+
throw new Error(`${label} must contain equal numbers of graded paired trials`);
|
|
223
|
+
}
|
|
224
|
+
const seen = new Set();
|
|
225
|
+
for (const facet of value.facets) {
|
|
226
|
+
if (seen.has(facet.name))
|
|
227
|
+
throw new Error(`${label}.facets contains a duplicate check name`);
|
|
228
|
+
seen.add(facet.name);
|
|
229
|
+
for (const condition of ['baseline', 'treatment']) {
|
|
230
|
+
const trials = condition === 'baseline' ? facet.baselineTrials : facet.treatmentTrials;
|
|
231
|
+
const rate = condition === 'baseline' ? facet.baselinePassRate : facet.treatmentPassRate;
|
|
232
|
+
if (trials > value[condition].trials || (trials === 0 && rate !== 0) ||
|
|
233
|
+
Math.abs(rate * trials - Math.round(rate * trials)) > 1e-9) {
|
|
234
|
+
throw new Error(`${label}.facets has an invalid ${condition} check denominator or rate`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const rate = (counts) => counts.trials === 0 ? 0 : counts.passes / counts.trials;
|
|
239
|
+
const expected = rate(value.treatment) - rate(value.baseline);
|
|
240
|
+
if (Math.abs(value.deltaPassRate - expected) > 1e-9) {
|
|
241
|
+
throw new Error(`${label}.deltaPassRate disagrees with its pass counts`);
|
|
242
|
+
}
|
|
243
|
+
if (value.baseline.meanScore !== null && value.treatment.meanScore !== null &&
|
|
244
|
+
value.scoreDelta !== null && Math.abs(value.scoreDelta -
|
|
245
|
+
(value.treatment.meanScore - value.baseline.meanScore)) > 1e-9 && label !== 'overall') {
|
|
246
|
+
throw new Error(`${label}.scoreDelta disagrees with its mean scores`);
|
|
247
|
+
}
|
|
248
|
+
if (value.scoreDelta !== null && (value.baseline.meanScore === null || value.treatment.meanScore === null)) {
|
|
249
|
+
throw new Error(`${label}.scoreDelta requires graded scores in both conditions`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** Read only the v4 fields the Markdown report actually uses. Never reinterpret older metrics. */
|
|
253
|
+
export function parseEvalReport(value) {
|
|
254
|
+
const manifest = object(value, 'Manifest');
|
|
255
|
+
if (manifest['schemaVersion'] !== 4) {
|
|
256
|
+
throw new Error(`Only evaluation manifest schemaVersion 4 can be rendered (found ${JSON.stringify(manifest['schemaVersion'])})`);
|
|
257
|
+
}
|
|
258
|
+
const target = object(manifest['target'], 'target');
|
|
259
|
+
const kind = string(target['kind'], 'target.kind');
|
|
260
|
+
if (!['skill', 'rules', 'mcp'].includes(kind))
|
|
261
|
+
throw new Error('target.kind must be skill, rules, or mcp');
|
|
262
|
+
const bench = object(manifest['bench'], 'bench');
|
|
263
|
+
const executor = object(manifest['executor'], 'executor');
|
|
264
|
+
const inputMode = manifest['inputMode'];
|
|
265
|
+
if (inputMode !== undefined && inputMode !== 'snapshot' && inputMode !== 'workspace') {
|
|
266
|
+
throw new Error('inputMode must be snapshot or workspace');
|
|
267
|
+
}
|
|
268
|
+
let skillDelivery = null;
|
|
269
|
+
if (manifest['skillDelivery'] !== undefined) {
|
|
270
|
+
const delivery = object(manifest['skillDelivery'], 'skillDelivery');
|
|
271
|
+
if (delivery['mode'] !== 'installed' || kind !== 'skill' || inputMode !== 'workspace') {
|
|
272
|
+
throw new Error('skillDelivery requires installed mode, a Skill target and workspace input');
|
|
273
|
+
}
|
|
274
|
+
const installDir = string(delivery['installDir'], 'skillDelivery.installDir');
|
|
275
|
+
validateSkillInstallDir(installDir);
|
|
276
|
+
if (!Array.isArray(target['files']) || !target['files'].includes('SKILL.md') ||
|
|
277
|
+
target['files'].some((file) => typeof file !== 'string' || !file)) {
|
|
278
|
+
throw new Error('Installed Skill target.files must list the complete resources including SKILL.md');
|
|
279
|
+
}
|
|
280
|
+
skillDelivery = { mode: 'installed', installDir };
|
|
281
|
+
}
|
|
282
|
+
let baselineTarget = null;
|
|
283
|
+
if (manifest['baselineTarget'] !== undefined) {
|
|
284
|
+
const previous = object(manifest['baselineTarget'], 'baselineTarget');
|
|
285
|
+
if (!skillDelivery || previous['kind'] !== 'skill') {
|
|
286
|
+
throw new Error('baselineTarget requires two installed Skill versions.');
|
|
287
|
+
}
|
|
288
|
+
const name = string(previous['name'], 'baselineTarget.name');
|
|
289
|
+
if (name !== target['name'])
|
|
290
|
+
throw new Error('baselineTarget.name must match the target Skill name.');
|
|
291
|
+
const sha256 = hash(previous['bundleSha256'], 'baselineTarget.bundleSha256');
|
|
292
|
+
if (sha256.toLowerCase() === hash(target['bundleSha256'], 'target.bundleSha256').toLowerCase()) {
|
|
293
|
+
throw new Error('baselineTarget and target must have different complete-resource fingerprints.');
|
|
294
|
+
}
|
|
295
|
+
string(previous['sourceDir'], 'baselineTarget.sourceDir');
|
|
296
|
+
if (!Array.isArray(previous['files']) || !previous['files'].includes('SKILL.md') ||
|
|
297
|
+
previous['files'].some(file => typeof file !== 'string' || !file)) {
|
|
298
|
+
throw new Error('baselineTarget.files must list the complete resources including SKILL.md.');
|
|
299
|
+
}
|
|
300
|
+
baselineTarget = { name, sha256 };
|
|
301
|
+
}
|
|
302
|
+
const rawTasks = manifest['tasks'];
|
|
303
|
+
if (!Array.isArray(rawTasks))
|
|
304
|
+
throw new Error('tasks must be an array');
|
|
305
|
+
const tasks = rawTasks.map((task, index) => {
|
|
306
|
+
const item = object(task, `tasks[${index}]`);
|
|
307
|
+
return row(item, `tasks[${index}]`, string(item['id'], `tasks[${index}].id`));
|
|
308
|
+
});
|
|
309
|
+
const overall = object(manifest['overall'], 'overall');
|
|
310
|
+
const stats = object(overall['stats'], 'overall.stats');
|
|
311
|
+
const discordant = object(stats['discordant'], 'overall.stats.discordant');
|
|
312
|
+
const rawCi = stats['deltaCi'];
|
|
313
|
+
const ci = rawCi === null ? null : object(rawCi, 'overall.stats.deltaCi');
|
|
314
|
+
const warnings = manifest['warnings'];
|
|
315
|
+
if (!Array.isArray(warnings) || warnings.some((item) => typeof item !== 'string')) {
|
|
316
|
+
throw new Error('warnings must be an array of strings');
|
|
317
|
+
}
|
|
318
|
+
const createdAt = string(manifest['createdAt'], 'createdAt');
|
|
319
|
+
if (!Number.isFinite(Date.parse(createdAt)))
|
|
320
|
+
throw new Error('createdAt must be a date-time');
|
|
321
|
+
const taskCount = integer(bench['taskCount'], 'bench.taskCount');
|
|
322
|
+
if (tasks.length !== taskCount)
|
|
323
|
+
throw new Error('bench.taskCount must match tasks.length');
|
|
324
|
+
const ciValue = ci === null ? null : {
|
|
325
|
+
lo: number(ci['lo'], 'overall.stats.deltaCi.lo', -1, 1),
|
|
326
|
+
hi: number(ci['hi'], 'overall.stats.deltaCi.hi', -1, 1),
|
|
327
|
+
resamples: integer(ci['resamples'], 'overall.stats.deltaCi.resamples', 1),
|
|
328
|
+
};
|
|
329
|
+
if (ciValue && ciValue.lo > ciValue.hi)
|
|
330
|
+
throw new Error('overall.stats.deltaCi.lo cannot exceed hi');
|
|
331
|
+
const rawScoreCi = stats['scoreDeltaCi'];
|
|
332
|
+
const scoreCi = rawScoreCi === undefined || rawScoreCi === null ? null
|
|
333
|
+
: object(rawScoreCi, 'overall.stats.scoreDeltaCi');
|
|
334
|
+
const scoreDeltaCi = scoreCi === null ? null : {
|
|
335
|
+
lo: number(scoreCi['lo'], 'overall.stats.scoreDeltaCi.lo', -1, 1),
|
|
336
|
+
hi: number(scoreCi['hi'], 'overall.stats.scoreDeltaCi.hi', -1, 1),
|
|
337
|
+
resamples: integer(scoreCi['resamples'], 'overall.stats.scoreDeltaCi.resamples', 1),
|
|
338
|
+
};
|
|
339
|
+
if (scoreDeltaCi && scoreDeltaCi.lo > scoreDeltaCi.hi)
|
|
340
|
+
throw new Error('overall.stats.scoreDeltaCi.lo cannot exceed hi');
|
|
341
|
+
const overallRow = row(overall, 'overall', 'Overall');
|
|
342
|
+
const declaredTrials = integer(manifest['trials'], 'trials', 1);
|
|
343
|
+
for (const [index, task] of tasks.entries())
|
|
344
|
+
checkCostCounts(task, declaredTrials, `tasks[${index}]`);
|
|
345
|
+
checkCostCounts(overallRow, declaredTrials * tasks.length, 'overall');
|
|
346
|
+
if (overallRow.costs) {
|
|
347
|
+
if (tasks.some(t => !t.costs))
|
|
348
|
+
throw new Error('overall.costs requires costs for every task');
|
|
349
|
+
assertCostTotals(overallRow.costs, tasks.map(t => t.costs));
|
|
350
|
+
}
|
|
351
|
+
else if (tasks.some(t => t.costs))
|
|
352
|
+
throw new Error('Task costs require corresponding overall costs');
|
|
353
|
+
for (const [index, task] of tasks.entries())
|
|
354
|
+
checkDelta(task, `tasks[${index}]`);
|
|
355
|
+
checkDelta(overallRow, 'overall');
|
|
356
|
+
if (scoreDeltaCi) {
|
|
357
|
+
if (overallRow.scoreDelta === null || overallRow.baseline.meanScore === null ||
|
|
358
|
+
overallRow.treatment.meanScore === null || !tasks.some(t => t.baseline.trials > 0 && t.baseline.meanScore !== null &&
|
|
359
|
+
t.treatment.meanScore !== null && t.scoreDelta !== null)) {
|
|
360
|
+
throw new Error('overall.stats.scoreDeltaCi requires paired graded score observations and overall scoreDelta');
|
|
361
|
+
}
|
|
362
|
+
if (scoreCi['point'] !== undefined && Math.abs(number(scoreCi['point'], 'overall.stats.scoreDeltaCi.point', -1, 1) - overallRow.scoreDelta) > 1e-9) {
|
|
363
|
+
throw new Error('overall.stats.scoreDeltaCi.point disagrees with overall.scoreDelta');
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
for (const condition of ['baseline', 'treatment']) {
|
|
367
|
+
for (const field of ['passes', 'trials', 'errors']) {
|
|
368
|
+
const total = tasks.reduce((sum, task) => sum + task[condition][field], 0);
|
|
369
|
+
if (total !== overallRow[condition][field]) {
|
|
370
|
+
throw new Error(`overall.conditions.${condition}.${field} disagrees with task totals`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const aggregate = overallRow[condition];
|
|
374
|
+
if (aggregate.skillReads) {
|
|
375
|
+
if (!skillDelivery || tasks.some(t => t[condition].skillReads === null))
|
|
376
|
+
throw new Error('skillReads requires installed delivery and recorded observations for every task');
|
|
377
|
+
for (const field of ['observed', 'unobserved', 'unknown']) {
|
|
378
|
+
if (aggregate.skillReads[field] !== tasks.reduce((sum, t) => sum + t[condition].skillReads[field], 0)) {
|
|
379
|
+
throw new Error(`overall.conditions.${condition}.skillReads.${field} disagrees with task totals`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else if (tasks.some(t => t[condition].skillReads !== null))
|
|
384
|
+
throw new Error('Task skillReads requires corresponding overall observations');
|
|
385
|
+
if (aggregate.tokenCoverage) {
|
|
386
|
+
if (tasks.some(t => t[condition].tokenCoverage === null)) {
|
|
387
|
+
throw new Error(`overall.conditions.${condition}.tokenCoverage requires recorded coverage for every task`);
|
|
388
|
+
}
|
|
389
|
+
for (const field of ['input', 'output']) {
|
|
390
|
+
const coverage = tasks.reduce((sum, t) => sum + t[condition].tokenCoverage[field], 0);
|
|
391
|
+
if (coverage !== aggregate.tokenCoverage[field]) {
|
|
392
|
+
throw new Error(`overall.conditions.${condition}.tokenCoverage.${field} disagrees with task totals`);
|
|
393
|
+
}
|
|
394
|
+
const total = tasks.reduce((sum, t) => sum + (t[condition].tokens?.[field] ?? 0), 0);
|
|
395
|
+
if (total !== (aggregate.tokens?.[field] ?? 0)) {
|
|
396
|
+
throw new Error(`overall.conditions.${condition}.tokens.${field} disagrees with task totals`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const improved = integer(discordant['improved'], 'overall.stats.discordant.improved');
|
|
402
|
+
const regressed = integer(discordant['regressed'], 'overall.stats.discordant.regressed');
|
|
403
|
+
if (improved + regressed > overallRow.baseline.trials) {
|
|
404
|
+
throw new Error('overall.stats.discordant exceeds the number of paired trials');
|
|
405
|
+
}
|
|
406
|
+
if (improved - regressed !== overallRow.treatment.passes - overallRow.baseline.passes) {
|
|
407
|
+
throw new Error('overall.stats.discordant.improved - regressed disagrees with treatment.passes - baseline.passes');
|
|
408
|
+
}
|
|
409
|
+
const sharedSuccess = overallRow.baseline.passes - regressed;
|
|
410
|
+
if (sharedSuccess < 0) {
|
|
411
|
+
throw new Error('overall.stats.discordant implies a negative shared success count');
|
|
412
|
+
}
|
|
413
|
+
const sharedFailure = overallRow.baseline.trials - improved - regressed - sharedSuccess;
|
|
414
|
+
if (sharedFailure < 0) {
|
|
415
|
+
throw new Error('overall.stats.discordant implies a negative shared failure count');
|
|
416
|
+
}
|
|
417
|
+
const mcnemarP = number(stats['mcnemarP'], 'overall.stats.mcnemarP', 0, 1);
|
|
418
|
+
if (Math.abs(mcnemarP - mcnemarExactP(improved, regressed)) > 1e-9) {
|
|
419
|
+
throw new Error('overall.stats.mcnemarP disagrees with discordant counts');
|
|
420
|
+
}
|
|
421
|
+
const expectedVerdict = verdictFor({ improved, regressed, deltaPassRate: overallRow.deltaPassRate }).verdict;
|
|
422
|
+
if (overallRow.verdict !== expectedVerdict)
|
|
423
|
+
throw new Error('overall.verdict disagrees with the metrics protocol');
|
|
424
|
+
const managed = experiment(manifest['experiment']);
|
|
425
|
+
if (managed && managed.plannedCalls !== taskCount * integer(manifest['trials'], 'trials', 1) * (manifest['judge'] == null ? 2 : 4)) {
|
|
426
|
+
throw new Error('experiment.plannedCalls contradicts the declared tasks, trials, conditions, and judge');
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
runGroup: string(manifest['runGroup'], 'runGroup'),
|
|
430
|
+
...(manifest['invocationCosts'] === undefined ? {} : { invocationCosts: parseInvocationCosts(manifest['invocationCosts']) }),
|
|
431
|
+
createdAt,
|
|
432
|
+
target: { kind, name: string(target['name'], 'target.name'), sha256: hash(target['bundleSha256'], 'target.bundleSha256') },
|
|
433
|
+
baselineTarget,
|
|
434
|
+
bench: {
|
|
435
|
+
name: string(bench['name'], 'bench.name'),
|
|
436
|
+
sha256: hash(bench['contentSha256'], 'bench.contentSha256'),
|
|
437
|
+
taskCount,
|
|
438
|
+
},
|
|
439
|
+
executor: { kind: string(executor['kind'], 'executor.kind'), model: string(executor['model'], 'executor.model') },
|
|
440
|
+
trials: integer(manifest['trials'], 'trials', 1),
|
|
441
|
+
inputMode: inputMode ?? null,
|
|
442
|
+
skillDelivery,
|
|
443
|
+
experiment: managed,
|
|
444
|
+
tasks,
|
|
445
|
+
overall: {
|
|
446
|
+
...overallRow,
|
|
447
|
+
verdictReason: string(overall['verdictReason'], 'overall.verdictReason'),
|
|
448
|
+
improved,
|
|
449
|
+
regressed,
|
|
450
|
+
mcnemarP,
|
|
451
|
+
deltaCi: ciValue,
|
|
452
|
+
scoreDeltaCi,
|
|
453
|
+
},
|
|
454
|
+
warnings: warnings,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
@@ -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;
|
|
@@ -63,16 +64,28 @@ export class ApiExecutor {
|
|
|
63
64
|
}),
|
|
64
65
|
signal: interrupted ? AbortSignal.any([interrupted, AbortSignal.timeout(this.timeoutMs)]) : AbortSignal.timeout(this.timeoutMs),
|
|
65
66
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
69
74
|
}
|
|
70
|
-
|
|
71
|
-
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');
|
|
72
86
|
if (typeof content !== 'string') {
|
|
73
|
-
throw
|
|
87
|
+
throw failure('API response did not contain choices[0].message.content');
|
|
74
88
|
}
|
|
75
|
-
const tokens = tokenUsage(data.usage);
|
|
76
89
|
return tokens ? { output: content, tokens } : { output: content };
|
|
77
90
|
}
|
|
78
91
|
}
|
|
@@ -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
|
}
|