skillfit 0.12.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 +60 -119
- package/README.zh-CN.md +60 -116
- package/dist/commands/bench-check-report.js +1 -34
- package/dist/commands/bench.js +6 -239
- 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/install.js +14 -98
- package/dist/harness/bench-check.js +277 -0
- package/dist/harness/bench-diagnostics.js +34 -0
- package/dist/harness/eval-acceptance.js +1 -1
- package/dist/harness/eval-audit.js +1 -1
- package/dist/harness/eval-manifest.js +456 -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/evaluation-reports.md +1 -1
- package/docs/growth-roadmap-2026-10.md +14 -18
- package/docs/package-contents.md +73 -0
- 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.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-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 +14 -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/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/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 -1166
- 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 -269
- package/dist/commands/eval-cli-usage.test.js +0 -75
- 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 -263
- 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/npm-first-run.test.js +0 -74
- 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 -175
- package/dist/harness/executors/cli.test.js +0 -541
- 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
|
@@ -1,463 +1,13 @@
|
|
|
1
1
|
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { readEvaluationReport } from './evaluation-report.js';
|
|
2
3
|
import { agentEnvironmentReportLines } from '../harness/agent-preflight.js';
|
|
3
4
|
import { renderSingleArmReport } from './eval-single-arm-report.js';
|
|
4
|
-
import { CONCLUSIVE_TASKS, CONCLUSIVE_TRIALS, formatP, formatPp1
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { CONCLUSIVE_TASKS, CONCLUSIVE_TRIALS, formatP, formatPp1 } from '../harness/report.js';
|
|
6
|
+
import { renderCostLines } from '../harness/costs.js';
|
|
7
|
+
import { renderInvocationCostLines } from '../harness/invocation-costs.js';
|
|
8
|
+
import { parseEvalReport } from '../harness/eval-manifest.js';
|
|
9
|
+
export { parseEvalReport } from '../harness/eval-manifest.js';
|
|
9
10
|
const MAX_MANIFEST_BYTES = 16 * 1024 * 1024;
|
|
10
|
-
function object(value, label) {
|
|
11
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
12
|
-
throw new Error(`${label} must be an object`);
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
function string(value, label) {
|
|
17
|
-
if (typeof value !== 'string' || value.trim() === '')
|
|
18
|
-
throw new Error(`${label} must be a non-empty string`);
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
function number(value, label, min = -Infinity, max = Infinity) {
|
|
22
|
-
if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max) {
|
|
23
|
-
throw new Error(`${label} must be a finite number between ${min} and ${max}`);
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
function integer(value, label, min = 0) {
|
|
28
|
-
const result = number(value, label, min);
|
|
29
|
-
if (!Number.isInteger(result))
|
|
30
|
-
throw new Error(`${label} must be an integer`);
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
function hash(value, label) {
|
|
34
|
-
const result = string(value, label);
|
|
35
|
-
if (!/^[0-9a-f]{64}$/i.test(result))
|
|
36
|
-
throw new Error(`${label} must be a SHA-256 hex digest`);
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
function verdict(value, label) {
|
|
40
|
-
if (value !== 'effective' && value !== 'ineffective' && value !== 'inconclusive') {
|
|
41
|
-
throw new Error(`${label} must be effective, ineffective, or inconclusive`);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
function experiment(value) {
|
|
46
|
-
if (value === undefined)
|
|
47
|
-
return null;
|
|
48
|
-
const item = object(value, 'experiment');
|
|
49
|
-
if (item['schemaVersion'] !== 1)
|
|
50
|
-
throw new Error('experiment.schemaVersion must be 1');
|
|
51
|
-
const status = item['status'];
|
|
52
|
-
if (status !== 'completed' && status !== 'stopped' && status !== 'incomplete')
|
|
53
|
-
throw new Error('experiment.status must be completed, stopped, or incomplete');
|
|
54
|
-
const plannedCalls = integer(item['plannedCalls'], 'experiment.plannedCalls', 1);
|
|
55
|
-
const maxCalls = integer(item['maxCalls'], 'experiment.maxCalls', 1);
|
|
56
|
-
const callsStarted = integer(item['callsStarted'], 'experiment.callsStarted');
|
|
57
|
-
const callsFinished = integer(item['callsFinished'], 'experiment.callsFinished');
|
|
58
|
-
const stopReason = item['stopReason'] === null ? null : string(item['stopReason'], 'experiment.stopReason');
|
|
59
|
-
if (item['stopCode'] !== undefined && !['EXECUTION_FAILED', 'FINAL_USAGE_MISSING', 'SPENDING_BUDGET_REACHED'].includes(String(item['stopCode'])))
|
|
60
|
-
throw new Error('Invalid experiment.stopCode');
|
|
61
|
-
if (![plannedCalls, maxCalls, callsStarted, callsFinished].every(Number.isSafeInteger) ||
|
|
62
|
-
maxCalls < plannedCalls || callsStarted > plannedCalls || callsFinished > callsStarted ||
|
|
63
|
-
(status === 'completed' && (stopReason !== null || callsFinished !== plannedCalls)) ||
|
|
64
|
-
(status === 'stopped' && stopReason === null) ||
|
|
65
|
-
(status === 'incomplete' && (stopReason !== null || callsFinished === plannedCalls))) {
|
|
66
|
-
throw new Error('experiment status, call counts, ceiling, and stop reason contradict each other');
|
|
67
|
-
}
|
|
68
|
-
return { schemaVersion: 1, status, plannedCalls, maxCalls, callsStarted, callsFinished, stopReason,
|
|
69
|
-
planSha256: hash(item['planSha256'], 'experiment.planSha256'),
|
|
70
|
-
...(item['stopCode'] === undefined ? {} : { stopCode: item['stopCode'] }) };
|
|
71
|
-
}
|
|
72
|
-
function counts(value, label) {
|
|
73
|
-
const item = object(value, label);
|
|
74
|
-
const passes = integer(item['passes'], `${label}.passes`);
|
|
75
|
-
const trials = integer(item['trials'], `${label}.trials`);
|
|
76
|
-
const errors = integer(item['errors'], `${label}.errors`);
|
|
77
|
-
if (passes > trials)
|
|
78
|
-
throw new Error(`${label}.passes cannot exceed trials`);
|
|
79
|
-
const meanScore = item['meanScore'] === undefined || item['meanScore'] === null
|
|
80
|
-
? null : number(item['meanScore'], `${label}.meanScore`, 0, 1);
|
|
81
|
-
const rawTokens = item['tokens'] === undefined || item['tokens'] === null
|
|
82
|
-
? null : object(item['tokens'], `${label}.tokens`);
|
|
83
|
-
const tokens = rawTokens === null ? null : {
|
|
84
|
-
input: number(rawTokens['input'], `${label}.tokens.input`, 0),
|
|
85
|
-
output: number(rawTokens['output'], `${label}.tokens.output`, 0),
|
|
86
|
-
};
|
|
87
|
-
const rawCoverage = item['tokenCoverage'] === undefined
|
|
88
|
-
? null : object(item['tokenCoverage'], `${label}.tokenCoverage`);
|
|
89
|
-
const tokenCoverage = rawCoverage === null ? null : {
|
|
90
|
-
input: integer(rawCoverage['input'], `${label}.tokenCoverage.input`),
|
|
91
|
-
output: integer(rawCoverage['output'], `${label}.tokenCoverage.output`),
|
|
92
|
-
};
|
|
93
|
-
if (tokenCoverage && (tokenCoverage.input > trials || tokenCoverage.output > trials)) {
|
|
94
|
-
throw new Error(`${label}.tokenCoverage cannot exceed graded trials`);
|
|
95
|
-
}
|
|
96
|
-
if (tokenCoverage) {
|
|
97
|
-
for (const field of ['input', 'output']) {
|
|
98
|
-
if ((tokenCoverage[field] > 0 && tokens === null) ||
|
|
99
|
-
(tokenCoverage[field] === 0 && tokens !== null && tokens[field] !== 0)) {
|
|
100
|
-
throw new Error(`${label}.tokenCoverage contradicts its recorded tokens`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (meanScore !== null && trials === 0)
|
|
105
|
-
throw new Error(`${label}.meanScore requires graded trials`);
|
|
106
|
-
const rawReads = item['skillReads'] === undefined ? null : object(item['skillReads'], `${label}.skillReads`);
|
|
107
|
-
const skillReads = rawReads === null ? null : {
|
|
108
|
-
observed: integer(rawReads['observed'], `${label}.skillReads.observed`),
|
|
109
|
-
unobserved: integer(rawReads['unobserved'], `${label}.skillReads.unobserved`),
|
|
110
|
-
unknown: integer(rawReads['unknown'], `${label}.skillReads.unknown`),
|
|
111
|
-
};
|
|
112
|
-
if (skillReads && skillReads.observed + skillReads.unobserved + skillReads.unknown !== trials) {
|
|
113
|
-
throw new Error(`${label}.skillReads must total the surviving graded trials`);
|
|
114
|
-
}
|
|
115
|
-
return { passes, trials, errors, meanScore, tokens, tokenCoverage, skillReads };
|
|
116
|
-
}
|
|
117
|
-
function facets(value, label) {
|
|
118
|
-
if (value === undefined)
|
|
119
|
-
return [];
|
|
120
|
-
if (!Array.isArray(value))
|
|
121
|
-
throw new Error(`${label} must be an array`);
|
|
122
|
-
return value.map((raw, index) => {
|
|
123
|
-
const item = object(raw, `${label}[${index}]`);
|
|
124
|
-
return {
|
|
125
|
-
name: string(item['name'], `${label}[${index}].name`),
|
|
126
|
-
baselinePassRate: number(item['baselinePassRate'], `${label}[${index}].baselinePassRate`, 0, 1),
|
|
127
|
-
treatmentPassRate: number(item['treatmentPassRate'], `${label}[${index}].treatmentPassRate`, 0, 1),
|
|
128
|
-
baselineTrials: integer(item['baselineTrials'], `${label}[${index}].baselineTrials`),
|
|
129
|
-
treatmentTrials: integer(item['treatmentTrials'], `${label}[${index}].treatmentTrials`),
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function row(value, label, id) {
|
|
134
|
-
const item = object(value, label);
|
|
135
|
-
const conditions = object(item['conditions'], `${label}.conditions`);
|
|
136
|
-
return {
|
|
137
|
-
costs: item['costs'] === undefined ? null : parseCosts(item['costs'], `${label}.costs`),
|
|
138
|
-
id,
|
|
139
|
-
baseline: counts(conditions['baseline'], `${label}.conditions.baseline`),
|
|
140
|
-
treatment: counts(conditions['treatment'], `${label}.conditions.treatment`),
|
|
141
|
-
deltaPassRate: number(item['deltaPassRate'], `${label}.deltaPassRate`, -1, 1),
|
|
142
|
-
verdict: verdict(item['verdict'], `${label}.verdict`),
|
|
143
|
-
scoreDelta: item['scoreDelta'] === undefined || item['scoreDelta'] === null
|
|
144
|
-
? null : number(item['scoreDelta'], `${label}.scoreDelta`, -1, 1),
|
|
145
|
-
facets: facets(item['facets'], `${label}.facets`),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function parseCosts(value, label) {
|
|
149
|
-
const item = object(value, label);
|
|
150
|
-
if (item['schemaVersion'] !== 1)
|
|
151
|
-
throw new Error(`${label}.schemaVersion must be 1`);
|
|
152
|
-
const scope = (name) => {
|
|
153
|
-
const arms = object(item[name], `${label}.${name}`);
|
|
154
|
-
const population = (arm) => {
|
|
155
|
-
const path = `${label}.${name}.${arm}`;
|
|
156
|
-
const raw = object(arms[arm], path);
|
|
157
|
-
const runs = integer(raw['runs'], `${path}.runs`);
|
|
158
|
-
const passes = integer(raw['passes'], `${path}.passes`);
|
|
159
|
-
if (passes > runs)
|
|
160
|
-
throw new Error(`${path}.passes cannot exceed runs`);
|
|
161
|
-
const rawMetrics = object(raw['metrics'], `${path}.metrics`);
|
|
162
|
-
const metrics = Object.fromEntries(COST_METRICS.map(metric => {
|
|
163
|
-
const measure = object(rawMetrics[metric], `${path}.metrics.${metric}`);
|
|
164
|
-
const coverage = object(measure['coverage'], `${path}.metrics.${metric}.coverage`);
|
|
165
|
-
const parsed = {
|
|
166
|
-
knownTotal: number(measure['knownTotal'], `${path}.metrics.${metric}.knownTotal`, 0),
|
|
167
|
-
coverage: {
|
|
168
|
-
final: integer(coverage['final'], `${path}.metrics.${metric}.coverage.final`),
|
|
169
|
-
partial: integer(coverage['partial'], `${path}.metrics.${metric}.coverage.partial`),
|
|
170
|
-
unknown: integer(coverage['unknown'], `${path}.metrics.${metric}.coverage.unknown`),
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
const c = parsed.coverage;
|
|
174
|
-
if (c.final + c.partial + c.unknown !== runs ||
|
|
175
|
-
(c.final + c.partial === 0 && parsed.knownTotal !== 0))
|
|
176
|
-
throw new Error(`${path}.metrics.${metric} contradicts coverage`);
|
|
177
|
-
if (metric === 'durationSeconds' && (c.partial !== 0 || c.unknown !== 0))
|
|
178
|
-
throw new Error(`${path} elapsed time must cover every invocation`);
|
|
179
|
-
return [metric, parsed];
|
|
180
|
-
}));
|
|
181
|
-
const cache = metrics.cachedInput;
|
|
182
|
-
const uncached = metrics.uncachedInput;
|
|
183
|
-
if (JSON.stringify(cache.coverage) !== JSON.stringify(uncached.coverage))
|
|
184
|
-
throw new Error(`${path} cache partition coverage must match`);
|
|
185
|
-
if (cache.coverage.final + cache.coverage.partial > metrics.input.coverage.final + metrics.input.coverage.partial ||
|
|
186
|
-
cache.coverage.final > metrics.input.coverage.final ||
|
|
187
|
-
cache.knownTotal + uncached.knownTotal > metrics.input.knownTotal + 1e-6)
|
|
188
|
-
throw new Error(`${path} cache partition contradicts input`);
|
|
189
|
-
if (cache.coverage.final + cache.coverage.partial === metrics.input.coverage.final + metrics.input.coverage.partial &&
|
|
190
|
-
Math.abs(cache.knownTotal + uncached.knownTotal - metrics.input.knownTotal) > 1e-6)
|
|
191
|
-
throw new Error(`${path} cache partition disagrees with input`);
|
|
192
|
-
return { runs, passes, metrics };
|
|
193
|
-
};
|
|
194
|
-
return { baseline: population('baseline'), treatment: population('treatment') };
|
|
195
|
-
};
|
|
196
|
-
const notInvoked = object(item['notInvoked'], `${label}.notInvoked`);
|
|
197
|
-
return { schemaVersion: 1, paired: scope('paired'), attempts: scope('attempts'), notInvoked: {
|
|
198
|
-
baseline: integer(notInvoked['baseline'], `${label}.notInvoked.baseline`),
|
|
199
|
-
treatment: integer(notInvoked['treatment'], `${label}.notInvoked.treatment`),
|
|
200
|
-
} };
|
|
201
|
-
}
|
|
202
|
-
function checkCostCounts(row, declaredRuns, label) {
|
|
203
|
-
const costs = row.costs;
|
|
204
|
-
if (!costs)
|
|
205
|
-
return;
|
|
206
|
-
for (const arm of ['baseline', 'treatment']) {
|
|
207
|
-
const paired = costs.paired[arm];
|
|
208
|
-
const attempts = costs.attempts[arm];
|
|
209
|
-
if (paired.runs !== row[arm].trials || paired.passes !== row[arm].passes ||
|
|
210
|
-
attempts.runs + costs.notInvoked[arm] !== declaredRuns ||
|
|
211
|
-
paired.runs > attempts.runs || paired.passes > attempts.passes ||
|
|
212
|
-
attempts.passes - paired.passes > attempts.runs - paired.runs)
|
|
213
|
-
throw new Error(`${label}.costs disagree with declared/graded counts`);
|
|
214
|
-
for (const metric of COST_METRICS) {
|
|
215
|
-
if (paired.metrics[metric].knownTotal > attempts.metrics[metric].knownTotal + 1e-6)
|
|
216
|
-
throw new Error(`${label}.costs paired spending exceeds all invocations`);
|
|
217
|
-
for (const status of ['final', 'partial', 'unknown']) {
|
|
218
|
-
if (paired.metrics[metric].coverage[status] > attempts.metrics[metric].coverage[status])
|
|
219
|
-
throw new Error(`${label}.costs paired coverage exceeds all invocations`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function checkDelta(value, label) {
|
|
225
|
-
if (value.baseline.trials !== value.treatment.trials) {
|
|
226
|
-
throw new Error(`${label} must contain equal numbers of graded paired trials`);
|
|
227
|
-
}
|
|
228
|
-
const seen = new Set();
|
|
229
|
-
for (const facet of value.facets) {
|
|
230
|
-
if (seen.has(facet.name))
|
|
231
|
-
throw new Error(`${label}.facets contains a duplicate check name`);
|
|
232
|
-
seen.add(facet.name);
|
|
233
|
-
for (const condition of ['baseline', 'treatment']) {
|
|
234
|
-
const trials = condition === 'baseline' ? facet.baselineTrials : facet.treatmentTrials;
|
|
235
|
-
const rate = condition === 'baseline' ? facet.baselinePassRate : facet.treatmentPassRate;
|
|
236
|
-
if (trials > value[condition].trials || (trials === 0 && rate !== 0) ||
|
|
237
|
-
Math.abs(rate * trials - Math.round(rate * trials)) > 1e-9) {
|
|
238
|
-
throw new Error(`${label}.facets has an invalid ${condition} check denominator or rate`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const rate = (counts) => counts.trials === 0 ? 0 : counts.passes / counts.trials;
|
|
243
|
-
const expected = rate(value.treatment) - rate(value.baseline);
|
|
244
|
-
if (Math.abs(value.deltaPassRate - expected) > 1e-9) {
|
|
245
|
-
throw new Error(`${label}.deltaPassRate disagrees with its pass counts`);
|
|
246
|
-
}
|
|
247
|
-
if (value.baseline.meanScore !== null && value.treatment.meanScore !== null &&
|
|
248
|
-
value.scoreDelta !== null && Math.abs(value.scoreDelta -
|
|
249
|
-
(value.treatment.meanScore - value.baseline.meanScore)) > 1e-9 && label !== 'overall') {
|
|
250
|
-
throw new Error(`${label}.scoreDelta disagrees with its mean scores`);
|
|
251
|
-
}
|
|
252
|
-
if (value.scoreDelta !== null && (value.baseline.meanScore === null || value.treatment.meanScore === null)) {
|
|
253
|
-
throw new Error(`${label}.scoreDelta requires graded scores in both conditions`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
/** Read only the v4 fields the Markdown report actually uses. Never reinterpret older metrics. */
|
|
257
|
-
export function parseEvalReport(value) {
|
|
258
|
-
const manifest = object(value, 'Manifest');
|
|
259
|
-
if (manifest['schemaVersion'] !== 4) {
|
|
260
|
-
throw new Error(`Only evaluation manifest schemaVersion 4 can be rendered (found ${JSON.stringify(manifest['schemaVersion'])})`);
|
|
261
|
-
}
|
|
262
|
-
const target = object(manifest['target'], 'target');
|
|
263
|
-
const kind = string(target['kind'], 'target.kind');
|
|
264
|
-
if (!['skill', 'rules', 'mcp'].includes(kind))
|
|
265
|
-
throw new Error('target.kind must be skill, rules, or mcp');
|
|
266
|
-
const bench = object(manifest['bench'], 'bench');
|
|
267
|
-
const executor = object(manifest['executor'], 'executor');
|
|
268
|
-
const inputMode = manifest['inputMode'];
|
|
269
|
-
if (inputMode !== undefined && inputMode !== 'snapshot' && inputMode !== 'workspace') {
|
|
270
|
-
throw new Error('inputMode must be snapshot or workspace');
|
|
271
|
-
}
|
|
272
|
-
let skillDelivery = null;
|
|
273
|
-
if (manifest['skillDelivery'] !== undefined) {
|
|
274
|
-
const delivery = object(manifest['skillDelivery'], 'skillDelivery');
|
|
275
|
-
if (delivery['mode'] !== 'installed' || kind !== 'skill' || inputMode !== 'workspace') {
|
|
276
|
-
throw new Error('skillDelivery requires installed mode, a Skill target and workspace input');
|
|
277
|
-
}
|
|
278
|
-
const installDir = string(delivery['installDir'], 'skillDelivery.installDir');
|
|
279
|
-
validateSkillInstallDir(installDir);
|
|
280
|
-
if (!Array.isArray(target['files']) || !target['files'].includes('SKILL.md') ||
|
|
281
|
-
target['files'].some((file) => typeof file !== 'string' || !file)) {
|
|
282
|
-
throw new Error('Installed Skill target.files must list the complete resources including SKILL.md');
|
|
283
|
-
}
|
|
284
|
-
skillDelivery = { mode: 'installed', installDir };
|
|
285
|
-
}
|
|
286
|
-
let baselineTarget = null;
|
|
287
|
-
if (manifest['baselineTarget'] !== undefined) {
|
|
288
|
-
const previous = object(manifest['baselineTarget'], 'baselineTarget');
|
|
289
|
-
if (!skillDelivery || previous['kind'] !== 'skill') {
|
|
290
|
-
throw new Error('baselineTarget requires two installed Skill versions.');
|
|
291
|
-
}
|
|
292
|
-
const name = string(previous['name'], 'baselineTarget.name');
|
|
293
|
-
if (name !== target['name'])
|
|
294
|
-
throw new Error('baselineTarget.name must match the target Skill name.');
|
|
295
|
-
const sha256 = hash(previous['bundleSha256'], 'baselineTarget.bundleSha256');
|
|
296
|
-
if (sha256.toLowerCase() === hash(target['bundleSha256'], 'target.bundleSha256').toLowerCase()) {
|
|
297
|
-
throw new Error('baselineTarget and target must have different complete-resource fingerprints.');
|
|
298
|
-
}
|
|
299
|
-
string(previous['sourceDir'], 'baselineTarget.sourceDir');
|
|
300
|
-
if (!Array.isArray(previous['files']) || !previous['files'].includes('SKILL.md') ||
|
|
301
|
-
previous['files'].some(file => typeof file !== 'string' || !file)) {
|
|
302
|
-
throw new Error('baselineTarget.files must list the complete resources including SKILL.md.');
|
|
303
|
-
}
|
|
304
|
-
baselineTarget = { name, sha256 };
|
|
305
|
-
}
|
|
306
|
-
const rawTasks = manifest['tasks'];
|
|
307
|
-
if (!Array.isArray(rawTasks))
|
|
308
|
-
throw new Error('tasks must be an array');
|
|
309
|
-
const tasks = rawTasks.map((task, index) => {
|
|
310
|
-
const item = object(task, `tasks[${index}]`);
|
|
311
|
-
return row(item, `tasks[${index}]`, string(item['id'], `tasks[${index}].id`));
|
|
312
|
-
});
|
|
313
|
-
const overall = object(manifest['overall'], 'overall');
|
|
314
|
-
const stats = object(overall['stats'], 'overall.stats');
|
|
315
|
-
const discordant = object(stats['discordant'], 'overall.stats.discordant');
|
|
316
|
-
const rawCi = stats['deltaCi'];
|
|
317
|
-
const ci = rawCi === null ? null : object(rawCi, 'overall.stats.deltaCi');
|
|
318
|
-
const warnings = manifest['warnings'];
|
|
319
|
-
if (!Array.isArray(warnings) || warnings.some((item) => typeof item !== 'string')) {
|
|
320
|
-
throw new Error('warnings must be an array of strings');
|
|
321
|
-
}
|
|
322
|
-
const createdAt = string(manifest['createdAt'], 'createdAt');
|
|
323
|
-
if (!Number.isFinite(Date.parse(createdAt)))
|
|
324
|
-
throw new Error('createdAt must be a date-time');
|
|
325
|
-
const taskCount = integer(bench['taskCount'], 'bench.taskCount');
|
|
326
|
-
if (tasks.length !== taskCount)
|
|
327
|
-
throw new Error('bench.taskCount must match tasks.length');
|
|
328
|
-
const ciValue = ci === null ? null : {
|
|
329
|
-
lo: number(ci['lo'], 'overall.stats.deltaCi.lo', -1, 1),
|
|
330
|
-
hi: number(ci['hi'], 'overall.stats.deltaCi.hi', -1, 1),
|
|
331
|
-
resamples: integer(ci['resamples'], 'overall.stats.deltaCi.resamples', 1),
|
|
332
|
-
};
|
|
333
|
-
if (ciValue && ciValue.lo > ciValue.hi)
|
|
334
|
-
throw new Error('overall.stats.deltaCi.lo cannot exceed hi');
|
|
335
|
-
const rawScoreCi = stats['scoreDeltaCi'];
|
|
336
|
-
const scoreCi = rawScoreCi === undefined || rawScoreCi === null ? null
|
|
337
|
-
: object(rawScoreCi, 'overall.stats.scoreDeltaCi');
|
|
338
|
-
const scoreDeltaCi = scoreCi === null ? null : {
|
|
339
|
-
lo: number(scoreCi['lo'], 'overall.stats.scoreDeltaCi.lo', -1, 1),
|
|
340
|
-
hi: number(scoreCi['hi'], 'overall.stats.scoreDeltaCi.hi', -1, 1),
|
|
341
|
-
resamples: integer(scoreCi['resamples'], 'overall.stats.scoreDeltaCi.resamples', 1),
|
|
342
|
-
};
|
|
343
|
-
if (scoreDeltaCi && scoreDeltaCi.lo > scoreDeltaCi.hi)
|
|
344
|
-
throw new Error('overall.stats.scoreDeltaCi.lo cannot exceed hi');
|
|
345
|
-
const overallRow = row(overall, 'overall', 'Overall');
|
|
346
|
-
const declaredTrials = integer(manifest['trials'], 'trials', 1);
|
|
347
|
-
for (const [index, task] of tasks.entries())
|
|
348
|
-
checkCostCounts(task, declaredTrials, `tasks[${index}]`);
|
|
349
|
-
checkCostCounts(overallRow, declaredTrials * tasks.length, 'overall');
|
|
350
|
-
if (overallRow.costs) {
|
|
351
|
-
if (tasks.some(t => !t.costs))
|
|
352
|
-
throw new Error('overall.costs requires costs for every task');
|
|
353
|
-
assertCostTotals(overallRow.costs, tasks.map(t => t.costs));
|
|
354
|
-
}
|
|
355
|
-
else if (tasks.some(t => t.costs))
|
|
356
|
-
throw new Error('Task costs require corresponding overall costs');
|
|
357
|
-
for (const [index, task] of tasks.entries())
|
|
358
|
-
checkDelta(task, `tasks[${index}]`);
|
|
359
|
-
checkDelta(overallRow, 'overall');
|
|
360
|
-
if (scoreDeltaCi) {
|
|
361
|
-
if (overallRow.scoreDelta === null || overallRow.baseline.meanScore === null ||
|
|
362
|
-
overallRow.treatment.meanScore === null || !tasks.some(t => t.baseline.trials > 0 && t.baseline.meanScore !== null &&
|
|
363
|
-
t.treatment.meanScore !== null && t.scoreDelta !== null)) {
|
|
364
|
-
throw new Error('overall.stats.scoreDeltaCi requires paired graded score observations and overall scoreDelta');
|
|
365
|
-
}
|
|
366
|
-
if (scoreCi['point'] !== undefined && Math.abs(number(scoreCi['point'], 'overall.stats.scoreDeltaCi.point', -1, 1) - overallRow.scoreDelta) > 1e-9) {
|
|
367
|
-
throw new Error('overall.stats.scoreDeltaCi.point disagrees with overall.scoreDelta');
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
for (const condition of ['baseline', 'treatment']) {
|
|
371
|
-
for (const field of ['passes', 'trials', 'errors']) {
|
|
372
|
-
const total = tasks.reduce((sum, task) => sum + task[condition][field], 0);
|
|
373
|
-
if (total !== overallRow[condition][field]) {
|
|
374
|
-
throw new Error(`overall.conditions.${condition}.${field} disagrees with task totals`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
const aggregate = overallRow[condition];
|
|
378
|
-
if (aggregate.skillReads) {
|
|
379
|
-
if (!skillDelivery || tasks.some(t => t[condition].skillReads === null))
|
|
380
|
-
throw new Error('skillReads requires installed delivery and recorded observations for every task');
|
|
381
|
-
for (const field of ['observed', 'unobserved', 'unknown']) {
|
|
382
|
-
if (aggregate.skillReads[field] !== tasks.reduce((sum, t) => sum + t[condition].skillReads[field], 0)) {
|
|
383
|
-
throw new Error(`overall.conditions.${condition}.skillReads.${field} disagrees with task totals`);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else if (tasks.some(t => t[condition].skillReads !== null))
|
|
388
|
-
throw new Error('Task skillReads requires corresponding overall observations');
|
|
389
|
-
if (aggregate.tokenCoverage) {
|
|
390
|
-
if (tasks.some(t => t[condition].tokenCoverage === null)) {
|
|
391
|
-
throw new Error(`overall.conditions.${condition}.tokenCoverage requires recorded coverage for every task`);
|
|
392
|
-
}
|
|
393
|
-
for (const field of ['input', 'output']) {
|
|
394
|
-
const coverage = tasks.reduce((sum, t) => sum + t[condition].tokenCoverage[field], 0);
|
|
395
|
-
if (coverage !== aggregate.tokenCoverage[field]) {
|
|
396
|
-
throw new Error(`overall.conditions.${condition}.tokenCoverage.${field} disagrees with task totals`);
|
|
397
|
-
}
|
|
398
|
-
const total = tasks.reduce((sum, t) => sum + (t[condition].tokens?.[field] ?? 0), 0);
|
|
399
|
-
if (total !== (aggregate.tokens?.[field] ?? 0)) {
|
|
400
|
-
throw new Error(`overall.conditions.${condition}.tokens.${field} disagrees with task totals`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
const improved = integer(discordant['improved'], 'overall.stats.discordant.improved');
|
|
406
|
-
const regressed = integer(discordant['regressed'], 'overall.stats.discordant.regressed');
|
|
407
|
-
if (improved + regressed > overallRow.baseline.trials) {
|
|
408
|
-
throw new Error('overall.stats.discordant exceeds the number of paired trials');
|
|
409
|
-
}
|
|
410
|
-
if (improved - regressed !== overallRow.treatment.passes - overallRow.baseline.passes) {
|
|
411
|
-
throw new Error('overall.stats.discordant.improved - regressed disagrees with treatment.passes - baseline.passes');
|
|
412
|
-
}
|
|
413
|
-
const sharedSuccess = overallRow.baseline.passes - regressed;
|
|
414
|
-
if (sharedSuccess < 0) {
|
|
415
|
-
throw new Error('overall.stats.discordant implies a negative shared success count');
|
|
416
|
-
}
|
|
417
|
-
const sharedFailure = overallRow.baseline.trials - improved - regressed - sharedSuccess;
|
|
418
|
-
if (sharedFailure < 0) {
|
|
419
|
-
throw new Error('overall.stats.discordant implies a negative shared failure count');
|
|
420
|
-
}
|
|
421
|
-
const mcnemarP = number(stats['mcnemarP'], 'overall.stats.mcnemarP', 0, 1);
|
|
422
|
-
if (Math.abs(mcnemarP - mcnemarExactP(improved, regressed)) > 1e-9) {
|
|
423
|
-
throw new Error('overall.stats.mcnemarP disagrees with discordant counts');
|
|
424
|
-
}
|
|
425
|
-
const expectedVerdict = verdictFor({ improved, regressed, deltaPassRate: overallRow.deltaPassRate }).verdict;
|
|
426
|
-
if (overallRow.verdict !== expectedVerdict)
|
|
427
|
-
throw new Error('overall.verdict disagrees with the metrics protocol');
|
|
428
|
-
const managed = experiment(manifest['experiment']);
|
|
429
|
-
if (managed && managed.plannedCalls !== taskCount * integer(manifest['trials'], 'trials', 1) * (manifest['judge'] == null ? 2 : 4)) {
|
|
430
|
-
throw new Error('experiment.plannedCalls contradicts the declared tasks, trials, conditions, and judge');
|
|
431
|
-
}
|
|
432
|
-
return {
|
|
433
|
-
runGroup: string(manifest['runGroup'], 'runGroup'),
|
|
434
|
-
...(manifest['invocationCosts'] === undefined ? {} : { invocationCosts: parseInvocationCosts(manifest['invocationCosts']) }),
|
|
435
|
-
createdAt,
|
|
436
|
-
target: { kind, name: string(target['name'], 'target.name'), sha256: hash(target['bundleSha256'], 'target.bundleSha256') },
|
|
437
|
-
baselineTarget,
|
|
438
|
-
bench: {
|
|
439
|
-
name: string(bench['name'], 'bench.name'),
|
|
440
|
-
sha256: hash(bench['contentSha256'], 'bench.contentSha256'),
|
|
441
|
-
taskCount,
|
|
442
|
-
},
|
|
443
|
-
executor: { kind: string(executor['kind'], 'executor.kind'), model: string(executor['model'], 'executor.model') },
|
|
444
|
-
trials: integer(manifest['trials'], 'trials', 1),
|
|
445
|
-
inputMode: inputMode ?? null,
|
|
446
|
-
skillDelivery,
|
|
447
|
-
experiment: managed,
|
|
448
|
-
tasks,
|
|
449
|
-
overall: {
|
|
450
|
-
...overallRow,
|
|
451
|
-
verdictReason: string(overall['verdictReason'], 'overall.verdictReason'),
|
|
452
|
-
improved,
|
|
453
|
-
regressed,
|
|
454
|
-
mcnemarP,
|
|
455
|
-
deltaCi: ciValue,
|
|
456
|
-
scoreDeltaCi,
|
|
457
|
-
},
|
|
458
|
-
warnings: warnings,
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
11
|
function escapeMarkdown(value) {
|
|
462
12
|
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
463
13
|
.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('*', '\\*')
|
|
@@ -602,9 +152,6 @@ export function renderEvalMarkdown(report) {
|
|
|
602
152
|
return lines.join('\n');
|
|
603
153
|
}
|
|
604
154
|
export async function runEvalReport(inputPath, log = console.log, options = {}) {
|
|
605
|
-
// Import after module initialization: component assessment itself uses this
|
|
606
|
-
// module's manifest parser. Both CLI formats must share the same assessment.
|
|
607
|
-
const { readEvaluationReport } = await import('./evaluation-report.js');
|
|
608
155
|
const result = await readEvaluationReport(inputPath, options);
|
|
609
156
|
if ('evaluationType' in result) {
|
|
610
157
|
log(renderSingleArmReport(result));
|
package/dist/commands/install.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { promises as fs } from 'node:fs';
|
|
4
4
|
import * as os from 'node:os';
|
|
@@ -6,10 +6,12 @@ import * as path from 'node:path';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { getAgent } from '../agents.js';
|
|
8
8
|
import { parseFrontmatter } from '../frontmatter.js';
|
|
9
|
+
import { BACKUP_SUFFIX } from '../install/constants.js';
|
|
10
|
+
import { executeTransaction } from '../install/transaction.js';
|
|
9
11
|
import { confirm as confirmPrompt } from './confirm.js';
|
|
10
12
|
export const MARKER_START = '<!-- SKILLFIT_START -->';
|
|
11
13
|
export const MARKER_END = '<!-- SKILLFIT_END -->';
|
|
12
|
-
export
|
|
14
|
+
export { BACKUP_SUFFIX } from '../install/constants.js';
|
|
13
15
|
export const LOCKFILE_NAME = 'skillfit.lock.json';
|
|
14
16
|
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
15
17
|
export async function runInstall(opts) {
|
|
@@ -71,7 +73,12 @@ export async function runInstall(opts) {
|
|
|
71
73
|
}
|
|
72
74
|
recordEntries(lock, items, manifest, now().toISOString());
|
|
73
75
|
const lockContent = `${JSON.stringify(lock, null, 2)}\n`;
|
|
74
|
-
|
|
76
|
+
const files = writes.flatMap(item => item.files.map(file => ({
|
|
77
|
+
path: file.path, content: file.content, backup: file.backup ? 'first' : 'none',
|
|
78
|
+
})));
|
|
79
|
+
// Metadata is committed last and backs up its immediately previous version.
|
|
80
|
+
files.push({ path: lockPath, content: lockContent, backup: existsSync(lockPath) ? 'previous' : 'none' });
|
|
81
|
+
const written = await executeTransaction(files, async () => {
|
|
75
82
|
const problems = await validateWrites(writes);
|
|
76
83
|
if (problems.length > 0) {
|
|
77
84
|
throw new Error(`Post-install validation failed:\n ${problems.join('\n ')}`);
|
|
@@ -79,7 +86,10 @@ export async function runInstall(opts) {
|
|
|
79
86
|
if (await fs.readFile(lockPath, 'utf8') !== lockContent) {
|
|
80
87
|
throw new Error(`Post-install validation failed: lockfile content differs from the plan at ${lockPath}`);
|
|
81
88
|
}
|
|
82
|
-
}
|
|
89
|
+
});
|
|
90
|
+
for (const entry of written.slice(0, -1)) {
|
|
91
|
+
log(` wrote ${entry.target}${entry.backedUp ? ` (backup: ${entry.backedUp})` : ''}`);
|
|
92
|
+
}
|
|
83
93
|
log(`Post-install validation passed (${writes.length} item(s) checked).`);
|
|
84
94
|
log(`Lockfile updated: ${lockPath}`);
|
|
85
95
|
log('Install complete.');
|
|
@@ -506,100 +516,6 @@ function printPlan(log, manifest, scope, scopeDir, items) {
|
|
|
506
516
|
log('');
|
|
507
517
|
log(`Summary: ${counts.create} create, ${counts.update} update, ${counts.skip} skipped (unchanged), ${counts.conflict} conflict`);
|
|
508
518
|
}
|
|
509
|
-
async function executeWrites(writes, lockPath, lockContent, validate, log) {
|
|
510
|
-
// Every target gets a temporary copy of its immediately previous state for rollback. The
|
|
511
|
-
// user-facing .skillfit-bak has a different purpose: it preserves the earliest original.
|
|
512
|
-
// Include the lockfile in this batch so its write and post-write validation can also roll back.
|
|
513
|
-
const files = writes.flatMap((item) => item.files.map((file) => ({ ...file, isLockfile: false })));
|
|
514
|
-
files.push({ path: lockPath, content: lockContent, backup: existsSync(lockPath), isLockfile: true });
|
|
515
|
-
const staged = [];
|
|
516
|
-
try {
|
|
517
|
-
for (const file of files) {
|
|
518
|
-
await fs.mkdir(path.dirname(file.path), { recursive: true });
|
|
519
|
-
const suffix = `${process.pid}.${randomUUID()}`;
|
|
520
|
-
const tmp = `${file.path}.${suffix}.skillfit-staged`;
|
|
521
|
-
const restore = existsSync(file.path) ? `${file.path}.${suffix}.skillfit-restore` : null;
|
|
522
|
-
const entry = { target: file.path, tmp, restore, backedUp: null, isLockfile: file.isLockfile };
|
|
523
|
-
staged.push(entry);
|
|
524
|
-
if (restore)
|
|
525
|
-
await fs.copyFile(file.path, restore);
|
|
526
|
-
if (file.backup) {
|
|
527
|
-
// The lockfile backup tracks the previous version; user-content backups keep the first.
|
|
528
|
-
if (file.isLockfile) {
|
|
529
|
-
await fs.copyFile(file.path, file.path + BACKUP_SUFFIX);
|
|
530
|
-
entry.backedUp = file.path + BACKUP_SUFFIX;
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
entry.backedUp = await backupOnce(file.path);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
await fs.writeFile(tmp, file.content);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
catch (error) {
|
|
540
|
-
await cleanupStaged(staged);
|
|
541
|
-
throw error;
|
|
542
|
-
}
|
|
543
|
-
const applied = [];
|
|
544
|
-
try {
|
|
545
|
-
for (const entry of staged) {
|
|
546
|
-
await fs.rename(entry.tmp, entry.target);
|
|
547
|
-
applied.push(entry);
|
|
548
|
-
}
|
|
549
|
-
await validate();
|
|
550
|
-
}
|
|
551
|
-
catch (error) {
|
|
552
|
-
const rollbackFailures = [];
|
|
553
|
-
const preserveRestores = new Set();
|
|
554
|
-
for (const entry of applied.reverse()) {
|
|
555
|
-
try {
|
|
556
|
-
if (entry.restore)
|
|
557
|
-
await fs.copyFile(entry.restore, entry.target);
|
|
558
|
-
else
|
|
559
|
-
await fs.rm(entry.target, { force: true });
|
|
560
|
-
}
|
|
561
|
-
catch (rollbackError) {
|
|
562
|
-
rollbackFailures.push(`${entry.target}: ${rollbackError.message}`);
|
|
563
|
-
preserveRestores.add(entry.target);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
await cleanupStaged(staged, preserveRestores);
|
|
567
|
-
if (rollbackFailures.length > 0) {
|
|
568
|
-
throw new Error(`Install failed (${error.message}) and rollback failed for ${rollbackFailures.join('; ')}. ` +
|
|
569
|
-
`Recovery copies with the .skillfit-restore suffix were kept beside those targets.`, { cause: error });
|
|
570
|
-
}
|
|
571
|
-
throw error;
|
|
572
|
-
}
|
|
573
|
-
await cleanupStaged(staged);
|
|
574
|
-
for (const entry of staged) {
|
|
575
|
-
if (!entry.isLockfile)
|
|
576
|
-
log(` wrote ${entry.target}${entry.backedUp ? ` (backup: ${entry.backedUp})` : ''}`);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
async function cleanupStaged(staged, preserveRestores = new Set()) {
|
|
580
|
-
for (const entry of staged) {
|
|
581
|
-
await fs.rm(entry.tmp, { force: true });
|
|
582
|
-
if (entry.restore && !preserveRestores.has(entry.target))
|
|
583
|
-
await fs.rm(entry.restore, { force: true });
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Back up a file at most once. `.skillfit-bak` is a single slot, and the copy worth keeping is the
|
|
588
|
-
* user's pre-skillfit original: overwriting it on a later update would destroy the only copy of the
|
|
589
|
-
* content the suffix exists to protect. Returns the backup path when one was created, else null.
|
|
590
|
-
*/
|
|
591
|
-
async function backupOnce(target) {
|
|
592
|
-
const backup = target + BACKUP_SUFFIX;
|
|
593
|
-
try {
|
|
594
|
-
await fs.access(backup);
|
|
595
|
-
return null;
|
|
596
|
-
}
|
|
597
|
-
catch {
|
|
598
|
-
// absent — take the backup
|
|
599
|
-
}
|
|
600
|
-
await fs.copyFile(target, backup);
|
|
601
|
-
return backup;
|
|
602
|
-
}
|
|
603
519
|
async function validateWrites(writes) {
|
|
604
520
|
const problems = [];
|
|
605
521
|
for (const item of writes) {
|