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.
Files changed (127) hide show
  1. package/README.md +60 -119
  2. package/README.zh-CN.md +60 -116
  3. package/dist/commands/bench-check-report.js +1 -34
  4. package/dist/commands/bench.js +6 -239
  5. package/dist/commands/eval-preflight-error.js +9 -0
  6. package/dist/commands/eval-preflight.js +4 -11
  7. package/dist/commands/eval-report.js +6 -459
  8. package/dist/commands/install.js +14 -98
  9. package/dist/harness/bench-check.js +277 -0
  10. package/dist/harness/bench-diagnostics.js +34 -0
  11. package/dist/harness/eval-acceptance.js +1 -1
  12. package/dist/harness/eval-audit.js +1 -1
  13. package/dist/harness/eval-manifest.js +456 -0
  14. package/dist/install/constants.js +1 -0
  15. package/dist/install/transaction.js +112 -0
  16. package/docs/README.md +65 -0
  17. package/docs/architecture.md +86 -0
  18. package/docs/archive-delivery.md +83 -0
  19. package/docs/archive-inventory.md +91 -0
  20. package/docs/evaluation-reports.md +1 -1
  21. package/docs/growth-roadmap-2026-10.md +14 -18
  22. package/docs/package-contents.md +73 -0
  23. package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
  24. package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
  25. package/docs/plans/2026-10-20-delivery-verification.json +146 -0
  26. package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
  27. package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
  28. package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
  29. package/docs/releases/0.12.0-attestation-check.json +22 -0
  30. package/docs/releases/0.12.0-attestations.json +155 -0
  31. package/docs/releases/0.12.0-ci-registry-install.json +90 -0
  32. package/docs/releases/0.12.0-feature-smoke.json +34 -0
  33. package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
  34. package/docs/releases/0.12.0-local-registry-install.json +75 -0
  35. package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
  36. package/docs/releases/0.12.0-registry-metadata.json +96 -0
  37. package/docs/releases/0.12.0-signatures.txt +6 -0
  38. package/docs/releases/0.12.0-verification.json +99 -0
  39. package/docs/releases/0.12.0.md +14 -0
  40. package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
  41. package/docs/releases/0.13.0-preparation.json +102 -0
  42. package/docs/releases/0.13.0.md +61 -0
  43. package/docs/releases/archive-delivery-smoke.mjs +37 -0
  44. package/docs/reproducible-offline-example.md +1 -1
  45. package/evidence/README.md +24 -1
  46. package/evidence/archive-catalog.v1.json +8044 -0
  47. package/evidence/fetch-archives.mjs +211 -0
  48. package/package.json +9 -2
  49. package/dist/cli.test.js +0 -193
  50. package/dist/commands/bench-calibration.test.js +0 -237
  51. package/dist/commands/bench-check-json.test.js +0 -242
  52. package/dist/commands/bench-manage.test.js +0 -87
  53. package/dist/commands/bench.test.js +0 -1166
  54. package/dist/commands/bundle.test.js +0 -142
  55. package/dist/commands/calibration-cli.test.js +0 -145
  56. package/dist/commands/doctor.test.js +0 -280
  57. package/dist/commands/eval-agent-preflight.test.js +0 -269
  58. package/dist/commands/eval-cli-usage.test.js +0 -75
  59. package/dist/commands/eval-export-modes.test.js +0 -350
  60. package/dist/commands/eval-export.test.js +0 -279
  61. package/dist/commands/eval-interruption.test.js +0 -263
  62. package/dist/commands/eval-preflight.test.js +0 -382
  63. package/dist/commands/eval-report.test.js +0 -367
  64. package/dist/commands/eval.test.js +0 -503
  65. package/dist/commands/evaluation-report.test.js +0 -243
  66. package/dist/commands/install.test.js +0 -555
  67. package/dist/commands/npm-first-run.test.js +0 -74
  68. package/dist/commands/replay-cancellation.test.js +0 -105
  69. package/dist/commands/report.test.js +0 -110
  70. package/dist/commands/setup.test.js +0 -150
  71. package/dist/commands/upstream.test.js +0 -139
  72. package/dist/commands/workflow-entrypoints.test.js +0 -137
  73. package/dist/docs.test.js +0 -154
  74. package/dist/frontmatter.test.js +0 -49
  75. package/dist/harness/bench.test.js +0 -109
  76. package/dist/harness/bundle.test.js +0 -71
  77. package/dist/harness/codex-usage.test.js +0 -87
  78. package/dist/harness/costs.test.js +0 -92
  79. package/dist/harness/eval-budget.test.js +0 -237
  80. package/dist/harness/eval-component.test.js +0 -770
  81. package/dist/harness/eval-efficiency.test.js +0 -56
  82. package/dist/harness/execution-timing.test.js +0 -61
  83. package/dist/harness/executors/api.test.js +0 -175
  84. package/dist/harness/executors/cli.test.js +0 -541
  85. package/dist/harness/executors/mock.test.js +0 -43
  86. package/dist/harness/experiment-session.test.js +0 -317
  87. package/dist/harness/installed-skill.test.js +0 -162
  88. package/dist/harness/interruption.test.js +0 -31
  89. package/dist/harness/judge-accounting.test.js +0 -216
  90. package/dist/harness/judge.test.js +0 -181
  91. package/dist/harness/kimi-usage.test.js +0 -62
  92. package/dist/harness/native-diff.test.js +0 -53
  93. package/dist/harness/oss-lru-cache.test.js +0 -79
  94. package/dist/harness/oss-normalize-url.test.js +0 -64
  95. package/dist/harness/oss-regression-witness.test.js +0 -89
  96. package/dist/harness/oss-skill-followup.test.js +0 -59
  97. package/dist/harness/prompt.test.js +0 -48
  98. package/dist/harness/receipts.test.js +0 -148
  99. package/dist/harness/report.test.js +0 -297
  100. package/dist/harness/runner.test.js +0 -635
  101. package/dist/harness/skill-revision.test.js +0 -148
  102. package/dist/harness/stats.test.js +0 -124
  103. package/dist/harness/target.test.js +0 -60
  104. package/dist/harness/trigger.test.js +0 -261
  105. package/dist/harness/verifier-summary.test.js +0 -99
  106. package/dist/harness/verifier.test.js +0 -128
  107. package/dist/harness/waza-behavior.test.js +0 -139
  108. package/dist/mcp/probe.test.js +0 -139
  109. package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
  110. package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
  111. package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
  112. package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
  113. package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
  114. package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
  115. package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
  116. package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
  117. package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
  118. package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
  119. package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
  120. package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
  121. package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
  122. package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
  123. package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
  124. package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
  125. package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
  126. package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
  127. package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { constants, promises as fs } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const PACKAGE_ROOT = fileURLToPath(new URL('..', import.meta.url));
8
+ export const CATALOG_PATH = 'evidence/archive-catalog.v1.json';
9
+ const digest = bytes => createHash('sha256').update(bytes).digest('hex');
10
+ const inside = (root, target) => target === root || target.startsWith(root + path.sep);
11
+ const message = error => error instanceof Error ? error.message : String(error);
12
+
13
+ function safePath(value) {
14
+ return typeof value === 'string' && value.startsWith('evidence/') && !value.includes('\\') &&
15
+ value.split('/').every(part => part && part !== '.' && part !== '..');
16
+ }
17
+
18
+ export function validateCatalog(catalog) {
19
+ if (catalog?.version !== 1 || catalog.source?.repository !== 'remote-controlled-man/skillfit' ||
20
+ !/^[a-f0-9]{40}$/.test(catalog.source?.commit ?? '')) throw new Error('Unsupported archive catalog/source');
21
+ if (!Array.isArray(catalog.archives) || !catalog.archives.length || !Array.isArray(catalog.supportFiles)) {
22
+ throw new Error('Invalid archive catalog inventory');
23
+ }
24
+ const paths = new Set(), ids = new Set();
25
+ for (const [archive, rows] of [[true, catalog.archives], [false, catalog.supportFiles]]) {
26
+ for (const row of rows) {
27
+ if (!safePath(row.path) || paths.has(row.path) || !Number.isSafeInteger(row.bytes) || row.bytes < 0 ||
28
+ row.bytes > 16 * 1024 * 1024 || !/^[a-f0-9]{64}$/.test(row.sha256 ?? '')) {
29
+ throw new Error(`Invalid catalog file: ${row.path}`);
30
+ }
31
+ if (archive && (!row.path.startsWith('evidence/artifacts/') || !row.path.endsWith('.tar.gz') ||
32
+ !/^[a-z0-9][a-z0-9-]*$/.test(row.id ?? '') || ids.has(row.id))) throw new Error(`Invalid archive ID/path: ${row.id}`);
33
+ if (!archive && /\.(?:tar\.gz|tgz|zip)$/.test(row.path)) throw new Error(`Archive in support inventory: ${row.path}`);
34
+ if (row.inlineBase64 !== undefined) {
35
+ if (archive || typeof row.inlineBase64 !== 'string' || row.inlineBase64.length > Math.ceil(row.bytes / 3) * 4 ||
36
+ Buffer.from(row.inlineBase64, 'base64').toString('base64') !== row.inlineBase64) throw new Error(`Invalid inline support: ${row.path}`);
37
+ verify(row, Buffer.from(row.inlineBase64, 'base64'));
38
+ }
39
+ paths.add(row.path);
40
+ if (archive) ids.add(row.id);
41
+ }
42
+ }
43
+ return catalog;
44
+ }
45
+
46
+ export async function readCatalog(packageRoot = PACKAGE_ROOT) {
47
+ return validateCatalog(JSON.parse(await fs.readFile(path.join(packageRoot, CATALOG_PATH), 'utf8')));
48
+ }
49
+
50
+ function verify(row, bytes) {
51
+ if (bytes.length !== row.bytes || digest(bytes) !== row.sha256) throw new Error(`Integrity mismatch: ${row.path}`);
52
+ return bytes;
53
+ }
54
+
55
+ async function localBytes(root, row) {
56
+ const target = path.join(root, row.path), real = await fs.realpath(target);
57
+ if (!inside(root, real) || !(await fs.lstat(target)).isFile()) throw new Error(`Unsafe source file: ${row.path}`);
58
+ const stat = await fs.stat(target);
59
+ if (stat.size !== row.bytes) throw new Error(`Integrity mismatch: ${row.path}`);
60
+ return verify(row, await fs.readFile(target));
61
+ }
62
+
63
+ export function archiveUrl(catalog, row) {
64
+ return `https://raw.githubusercontent.com/${catalog.source.repository}/${catalog.source.commit}/${row.path}`;
65
+ }
66
+
67
+ async function remoteBytes(catalog, row, fetchImpl, timeoutMs) {
68
+ const response = await fetchImpl(archiveUrl(catalog, row), { redirect: 'error', signal: AbortSignal.timeout(timeoutMs) });
69
+ if (!response.ok) throw new Error(`Archive download failed: ${row.id} (HTTP ${response.status})`);
70
+ if (response.headers.has('content-length') && Number(response.headers.get('content-length')) !== row.bytes) {
71
+ await response.body?.cancel();
72
+ throw new Error(`Integrity mismatch: ${row.path} (download size)`);
73
+ }
74
+ if (!response.body) throw new Error(`Empty archive response: ${row.id}`);
75
+ const reader = response.body.getReader(), chunks = [];
76
+ let size = 0;
77
+ try {
78
+ while (true) {
79
+ const { done, value } = await reader.read();
80
+ if (done) break;
81
+ size += value.length;
82
+ if (size > row.bytes) throw new Error(`Archive exceeds catalog size: ${row.id}`);
83
+ chunks.push(value);
84
+ }
85
+ } catch (error) {
86
+ await reader.cancel().catch(() => {});
87
+ throw error;
88
+ } finally {
89
+ reader.releaseLock();
90
+ }
91
+ return verify(row, Buffer.concat(chunks, size));
92
+ }
93
+
94
+ async function requireAbsent(target) {
95
+ try { await fs.lstat(target); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
96
+ throw new Error(`Output already exists: ${target}`);
97
+ }
98
+
99
+ // Claim a fresh directory exclusively. Copy files exclusively too: portable directory rename
100
+ // can replace an empty competing directory on POSIX, and cannot replace it on Windows.
101
+ // Rollback removes only our files/directories; it never recursively removes the destination.
102
+ async function publish(staging, output, rows) {
103
+ await fs.mkdir(output);
104
+ const files = [], directories = [output];
105
+ try {
106
+ for (const row of rows) {
107
+ let dir = output;
108
+ for (const part of row.path.split('/').slice(0, -1)) {
109
+ dir = path.join(dir, part);
110
+ try { await fs.mkdir(dir); directories.push(dir); } catch (error) {
111
+ if (error.code !== 'EEXIST' || !(await fs.lstat(dir)).isDirectory()) throw error;
112
+ }
113
+ }
114
+ const target = path.join(output, row.path);
115
+ await fs.copyFile(path.join(staging, row.path), target, constants.COPYFILE_EXCL);
116
+ files.push({ path: target, stat: await fs.lstat(target) });
117
+ }
118
+ } catch (error) {
119
+ const failures = [];
120
+ for (const file of files.reverse()) {
121
+ try {
122
+ const stat = await fs.lstat(file.path);
123
+ if (stat.ino !== file.stat.ino || stat.dev !== file.stat.dev) throw new Error('file changed during publication');
124
+ await fs.unlink(file.path);
125
+ } catch (cleanupError) { failures.push(`${file.path}: ${message(cleanupError)}`); }
126
+ }
127
+ for (const dir of directories.reverse()) {
128
+ try { await fs.rmdir(dir); } catch (cleanupError) { failures.push(`${dir}: ${message(cleanupError)}`); }
129
+ }
130
+ if (failures.length) throw new Error(`${message(error)}; output cleanup incomplete: ${failures.join('; ')}`, { cause: error });
131
+ throw error;
132
+ }
133
+ }
134
+
135
+ /** Only explicit yes applies. Injected roots/transport keep tests offline and detached. */
136
+ export async function restoreArchives({ all = false, ids = [], output, yes = false, from, offline = false,
137
+ list = false, packageRoot = PACKAGE_ROOT, catalog, fetchImpl = globalThis.fetch, timeoutMs = 30_000, log = console.log } = {}) {
138
+ catalog = validateCatalog(catalog ?? await readCatalog(packageRoot));
139
+ if (list) {
140
+ if (all || ids.length || output || yes || from || offline) throw new Error('--list cannot be combined with restore options');
141
+ for (const row of catalog.archives) log(`${row.id}\t${row.bytes}\t${row.path}`);
142
+ return { status: 'listed', archives: catalog.archives.length };
143
+ }
144
+ if (all === (ids.length > 0) || new Set(ids).size !== ids.length) throw new Error('Choose --all or one or more unique --id values');
145
+ const selected = all ? catalog.archives : ids.map(id => {
146
+ const row = catalog.archives.find(row => row.id === id);
147
+ if (!row) throw new Error(`Unknown archive ID: ${id}`);
148
+ return row;
149
+ });
150
+ if (!output) throw new Error('A fresh --output directory is required');
151
+ if (offline && !from) throw new Error('--offline requires --from <archive-root>');
152
+ const packagePath = await fs.realpath(packageRoot), sourcePath = from ? await fs.realpath(from) : null;
153
+ const requested = path.resolve(output), parent = await fs.realpath(path.dirname(requested));
154
+ output = path.join(parent, path.basename(requested));
155
+ if (inside(packagePath, output) || (sourcePath && inside(sourcePath, output))) throw new Error('Output must be outside package and archive source directories');
156
+ await requireAbsent(output);
157
+ log(`Archive restore plan: ${selected.length} archive(s), ${catalog.supportFiles.length} shared support file(s)`);
158
+ log(`Source: ${sourcePath ?? `${catalog.source.repository}@${catalog.source.commit} (HTTPS)`}`);
159
+ log(`Output: ${output}`);
160
+ if (!yes) { log('Preview only. Add --yes to restore; no files were written or downloaded.'); return { status: 'planned', archives: selected.length }; }
161
+ const staging = await fs.mkdtemp(path.join(parent, '.skillfit-archives-'));
162
+ let failure;
163
+ try {
164
+ for (const row of catalog.supportFiles) {
165
+ const bytes = row.inlineBase64 === undefined ? await localBytes(packagePath, row) : verify(row, Buffer.from(row.inlineBase64, 'base64'));
166
+ const target = path.join(staging, row.path);
167
+ await fs.mkdir(path.dirname(target), { recursive: true });
168
+ await fs.writeFile(target, bytes, { flag: 'wx' });
169
+ }
170
+ for (const row of selected) {
171
+ const bytes = sourcePath ? await localBytes(sourcePath, row) : await remoteBytes(catalog, row, fetchImpl, timeoutMs);
172
+ const target = path.join(staging, row.path);
173
+ await fs.mkdir(path.dirname(target), { recursive: true });
174
+ await fs.writeFile(target, bytes, { flag: 'wx' });
175
+ }
176
+ // A competing output created during download is rejected by the exclusive mkdir.
177
+ await publish(staging, output, [...catalog.supportFiles, ...selected]);
178
+ } catch (error) { failure = error; }
179
+ try { await fs.rm(staging, { recursive: true, force: true }); } catch (error) {
180
+ failure = new Error(`${failure ? message(failure) + '; ' : ''}Staging cleanup failed: ${staging}: ${message(error)}`, { cause: failure ?? error });
181
+ }
182
+ if (failure) throw failure;
183
+ log(`Restored and verified ${selected.length} archive(s). Follow the historical README for manual offline replay.`);
184
+ return { status: 'restored', archives: selected.length, output };
185
+ }
186
+
187
+ export async function main(args = process.argv.slice(2)) {
188
+ const opts = { ids: [] };
189
+ for (let i = 0; i < args.length; i++) {
190
+ const arg = args[i];
191
+ if (arg === '--help') {
192
+ console.log('Usage: node evidence/fetch-archives.mjs --list | (--all | --id <id>...) --output <new-directory> [--yes] [--from <archive-root>] [--offline]');
193
+ return;
194
+ }
195
+ if (['--all', '--yes', '--offline', '--list'].includes(arg)) {
196
+ const key = arg.slice(2);
197
+ if (opts[key]) throw new Error(`Duplicate option: ${arg}`);
198
+ opts[key] = true;
199
+ } else if (['--id', '--output', '--from'].includes(arg)) {
200
+ const value = args[++i];
201
+ if (!value || value.startsWith('--')) throw new Error(`Missing value for ${arg}`);
202
+ if (arg === '--id') opts.ids.push(value);
203
+ else { const key = arg.slice(2); if (opts[key]) throw new Error(`Duplicate option: ${arg}`); opts[key] = value; }
204
+ } else throw new Error(`Unknown option: ${arg}`);
205
+ }
206
+ return restoreArchives(opts);
207
+ }
208
+
209
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
210
+ main().catch(error => { console.error(`Archive restore failed: ${message(error)}`); process.exitCode = 1; });
211
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillfit",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Evidence-driven configuration for AI coding agents: measure which skills, rules and MCP servers actually help — then install only those.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,7 +10,14 @@
10
10
  "node": ">=22"
11
11
  },
12
12
  "files": [
13
- "dist",
13
+ "dist/**/!(*.test).js",
14
+ "dist/**/*.json",
15
+ "dist/commands/bench-source.test.js",
16
+ "dist/commands/bench-draft.test.js",
17
+ "dist/commands/eval-layout.test.js",
18
+ "dist/commands/eval-api-failure.test.js",
19
+ "dist/harness/verifier-timeout.test.js",
20
+ "dist/harness/bench-location.test.js",
14
21
  "benches",
15
22
  "docs",
16
23
  "evidence",
package/dist/cli.test.js DELETED
@@ -1,193 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { test } from 'node:test';
7
- import { fileURLToPath } from 'node:url';
8
- const PACKAGE_ROOT = fileURLToPath(new URL('..', import.meta.url));
9
- const CLI = fileURLToPath(new URL('./cli.js', import.meta.url));
10
- const COMMANDS = [
11
- ['eval', join(PACKAGE_ROOT, 'skills', 'skillfit'), '--bench', join(PACKAGE_ROOT, 'benches', 'code-review')],
12
- ['bench', 'check', join(PACKAGE_ROOT, 'benches', 'code-review'), '--calibrate'],
13
- ];
14
- test('CLI rejects fractional, malformed and out-of-range trials in eval and calibration dry-runs', (t) => {
15
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-trials-'));
16
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
17
- for (const command of COMMANDS) {
18
- for (const value of ['2.9', '2junk', '', '0', '21', 'NaN']) {
19
- // Dry-run is mandatory even when exercising the broken parser: no agent CLI may run in tests.
20
- const result = spawnSync(process.execPath, [CLI, ...command, '--agent', 'codex', '--input', 'workspace', '--trials', value, '--dry-run'], { cwd, encoding: 'utf8', timeout: 30_000 });
21
- assert.ifError(result.error);
22
- assert.equal(result.status, 1, `${command[0]} --trials ${JSON.stringify(value)}`);
23
- assert.match(result.stderr, /--trials must be an integer between 1 and 20/);
24
- assert.equal(result.stdout, '', 'reject before a bench verifier or experiment plan starts');
25
- }
26
- }
27
- assert.ok(!existsSync(join(cwd, 'runs')));
28
- });
29
- test('CLI keeps valid and default repetition counts in offline eval and calibration plans', (t) => {
30
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-trials-'));
31
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
32
- for (const command of COMMANDS) {
33
- for (const trialArgs of [[], ['--trials', '3']]) {
34
- const result = spawnSync(process.execPath, [CLI, ...command, '--agent', 'codex', '--input', 'workspace', ...trialArgs, '--dry-run'], { cwd, encoding: 'utf8', timeout: 30_000 });
35
- assert.ifError(result.error);
36
- assert.equal(result.status, 0, result.stderr);
37
- const repetitions = trialArgs.length ? 3 : command[0] === 'eval' ? 5 : 2;
38
- if (command[0] === 'eval')
39
- assert.match(result.stdout, new RegExp(`Trials\\s+: ${repetitions} per condition`));
40
- else
41
- assert.ok(result.stdout.includes(`× ${repetitions} baseline run(s)`));
42
- }
43
- }
44
- assert.ok(!existsSync(join(cwd, 'runs')));
45
- });
46
- test('CLI rejects malformed call ceilings and unrelated commands without writes', t => {
47
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-budget-'));
48
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
49
- for (const value of ['0', '-1', '1.5', '2junk', 'NaN', '9007199254740992']) {
50
- const result = spawnSync(process.execPath, [CLI, 'eval', `--max-calls=${value}`, '--dry-run'], { cwd, encoding: 'utf8' });
51
- assert.equal(result.status, 1);
52
- assert.match(result.stderr, /positive safe integer/);
53
- assert.equal(result.stdout, '');
54
- }
55
- const unrelated = spawnSync(process.execPath, [CLI, 'doctor', '--max-calls', '2'], { cwd, encoding: 'utf8' });
56
- assert.equal(unrelated.status, 1);
57
- assert.match(unrelated.stderr, /applies only to eval/);
58
- assert.equal(existsSync(join(cwd, 'runs')), false);
59
- });
60
- test('CLI version comes from package.json and the matrix schema file exists', () => {
61
- const version = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8')).version;
62
- const result = spawnSync(process.execPath, [CLI, '--version'], { encoding: 'utf8' });
63
- assert.equal(result.status, 0);
64
- assert.equal(result.stdout.trim(), version);
65
- const matrix = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'src/matrix/agents.json'), 'utf8'));
66
- assert.equal(matrix.$schema, './agents.schema.json');
67
- assert.equal(existsSync(join(PACKAGE_ROOT, 'src/matrix/agents.schema.json')), true);
68
- });
69
- test('baseline calibration plans use the matrix transcript CLI without starting it', t => {
70
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-calibrate-wire-'));
71
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
72
- const result = spawnSync(process.execPath, [CLI, ...COMMANDS[1], '--agent', 'codex', '--input', 'workspace', '--trials', '2', '--max-calls', '10', '--dry-run'], { cwd, encoding: 'utf8', timeout: 30_000 });
73
- assert.equal(result.status, 0, result.stderr);
74
- assert.match(result.stdout, /calibration executor: codex: codex exec --json/);
75
- assert.equal(existsSync(join(cwd, 'runs')), false);
76
- });
77
- test('CLI wires the previous Skill into an installed dry-run and rejects single-arm comparison', t => {
78
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-revision-'));
79
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
80
- const current = join(cwd, 'new');
81
- const previous = join(cwd, 'old');
82
- for (const dir of [current, previous])
83
- cpSync(join(PACKAGE_ROOT, 'skills', 'skillfit'), dir, { recursive: true });
84
- writeFileSync(join(previous, 'SKILL.md'), readFileSync(join(previous, 'SKILL.md'), 'utf8') + '\nPrevious-version fixture.\n');
85
- const args = ['eval', current, '--baseline-skill', previous, '--bench', join(PACKAGE_ROOT, 'benches', 'code-review'), '--agent', 'codex', '--trials', '1', '--dry-run'];
86
- const result = spawnSync(process.execPath, [CLI, ...args, '--mode', 'installed'], { cwd, encoding: 'utf8', timeout: 30_000 });
87
- assert.equal(result.status, 0, result.stderr);
88
- assert.match(result.stdout, /Baseline\s+: skillfit/);
89
- assert.match(result.stdout, /previous Skill in baseline vs target Skill in treatment/);
90
- assert.match(result.stdout, /installed in both conditions/);
91
- const invalid = spawnSync(process.execPath, [CLI, ...args, '--mode', 'trigger'], { cwd, encoding: 'utf8', timeout: 30_000 });
92
- assert.equal(invalid.status, 1);
93
- assert.match(invalid.stderr, /requires --mode installed/);
94
- const unrelated = spawnSync(process.execPath, [CLI, 'doctor', '--baseline-skill', previous], { cwd, encoding: 'utf8' });
95
- assert.equal(unrelated.status, 1);
96
- assert.match(unrelated.stderr, /applies only to eval/);
97
- assert.equal(unrelated.stdout, '');
98
- assert.equal(existsSync(join(cwd, 'runs')), false);
99
- });
100
- test('ordinary JSON/human and Agent request previews expose the same effective installed no-Skill plan', t => {
101
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-shared-plan-'));
102
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
103
- const skill = join(cwd, 'candidate');
104
- cpSync(join(PACKAGE_ROOT, 'skills/skillfit'), skill, { recursive: true });
105
- const bench = join(PACKAGE_ROOT, 'benches/code-review'), task = JSON.parse(readFileSync(join(bench, 'bench.json'), 'utf8')).tasks[0].id;
106
- const limits = { input: 1000, cachedInput: 1000, uncachedInput: 1000, output: 1000, durationSeconds: 1000 };
107
- const budget = join(cwd, 'budget.json'), request = join(cwd, 'request.json');
108
- writeFileSync(budget, JSON.stringify(limits));
109
- writeFileSync(request, JSON.stringify({ schemaVersion: 1, baselineSkill: null, candidateSkill: skill, bench, taskIds: [task], agent: 'codex',
110
- purpose: 'development', trials: 1, maxCalls: 2, pairOrder: 'balanced', executorTimeoutSeconds: 17, spendingBudget: limits,
111
- runsRoot: join(cwd, 'runs'), runGroup: 'shared' }));
112
- const args = ['eval', skill, '--mode', 'installed', '--bench', bench, '--task', task, '--agent', 'codex', '--trials', '1', '--max-calls', '2',
113
- '--pair-order', 'balanced', '--executor-timeout-seconds', '17', '--spending-budget', budget, '--runs-root', join(cwd, 'runs'), '--run-group', 'shared', '--dry-run'];
114
- const env = { ...process.env, SKILLFIT_JUDGE: '0' };
115
- const ordinary = spawnSync(process.execPath, [CLI, ...args, '--json'], { cwd, env, encoding: 'utf8', timeout: 30_000 });
116
- const agent = spawnSync(process.execPath, [CLI, 'eval', '--request', request, '--dry-run'], { cwd, env, encoding: 'utf8', timeout: 30_000 });
117
- const human = spawnSync(process.execPath, [CLI, ...args], { cwd, env, encoding: 'utf8', timeout: 30_000 });
118
- for (const result of [ordinary, agent, human])
119
- assert.equal(result.status, 0, result.stderr);
120
- const plan = JSON.parse(ordinary.stdout).plan, agentPlan = JSON.parse(agent.stdout).plan;
121
- assert.deepEqual(plan.evaluation, agentPlan.evaluation);
122
- assert.equal(plan.evaluation.baseline, null);
123
- assert.deepEqual(plan.evaluation.spendingBudget, limits);
124
- assert.equal(plan.evaluation.executorTimeoutSeconds, 17);
125
- assert.equal(agentPlan.request.baselineSkill, null);
126
- assert.match(human.stdout, /no Skill installed by the harness/);
127
- assert.ok(human.stdout.includes(plan.sha256));
128
- assert.match(human.stdout, /Agent deadline: 17s/);
129
- assert.equal(existsSync(join(cwd, 'runs')), false);
130
- for (const override of [['--executor-timeout-seconds', '18'], ['--spending-budget', budget], ['--run-group', 'other']]) {
131
- const bad = spawnSync(process.execPath, [CLI, 'eval', '--request', request, '--dry-run', ...override], { cwd, env, encoding: 'utf8' });
132
- assert.equal(bad.status, 2);
133
- assert.match(JSON.parse(bad.stdout).error.message, /cannot be combined/);
134
- }
135
- });
136
- test('positional JSON eval rejects unconfirmed execution and invalid new controls without writes or calls', t => {
137
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-new-controls-'));
138
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
139
- // No target or executor is supplied: even a broken guard cannot dispatch a real model.
140
- for (const args of [['eval', '--json'], ['eval', '--json', '--plan-sha', 'a'.repeat(64)]]) {
141
- const result = spawnSync(process.execPath, [CLI, ...args], { cwd, encoding: 'utf8' });
142
- assert.equal(result.status, 2);
143
- const error = JSON.parse(result.stdout);
144
- assert.equal(error.kind, 'skillfit.eval-error');
145
- assert.match(error.error.message, /plan-sha|run-group/);
146
- assert.equal(error.acceptance.eligibleForUpgrade, false);
147
- }
148
- for (const value of ['0', '3601', '1.5', 'NaN', '2junk']) {
149
- const result = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--agent', 'codex', '--dry-run', '--json', '--executor-timeout-seconds', value], { cwd, encoding: 'utf8' });
150
- assert.equal(result.status, 2);
151
- assert.match(JSON.parse(result.stdout).error.message, /executorTimeoutSeconds/);
152
- }
153
- const file = join(cwd, 'budget.json');
154
- writeFileSync(file, JSON.stringify({ input: 10 }));
155
- const invalid = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--dry-run', '--json', '--spending-budget', file], { cwd, encoding: 'utf8' });
156
- assert.equal(invalid.status, 2);
157
- assert.match(JSON.parse(invalid.stdout).error.message, /spendingBudget/);
158
- const unrelated = spawnSync(process.execPath, [CLI, 'doctor', '--executor-timeout-seconds', '17'], { cwd, encoding: 'utf8' });
159
- assert.equal(unrelated.status, 1);
160
- assert.match(unrelated.stderr, /apply only to eval/);
161
- for (const args of [['eval'], [...COMMANDS[0], '--mode', 'invalid'], [...COMMANDS[0], '--runs-root', '']]) {
162
- const invalid = spawnSync(process.execPath, [CLI, ...args, '--json', '--dry-run'], { cwd, encoding: 'utf8' });
163
- assert.equal(invalid.status, 2);
164
- assert.equal(JSON.parse(invalid.stdout).kind, 'skillfit.eval-error');
165
- }
166
- assert.equal(existsSync(join(cwd, 'runs')), false);
167
- });
168
- test('API, trigger and judged paired previews bind deadlines and budgets without starting executors', t => {
169
- const cwd = mkdtempSync(join(tmpdir(), 'skillfit-cli-api-plan-'));
170
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
171
- const env = { ...process.env, SKILLFIT_API_KEY: 'synthetic-dry-run-only', SKILLFIT_API_BASE_URL: 'https://offline.invalid/v1', SKILLFIT_JUDGE: '0' };
172
- const api = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--dry-run', '--json', '--executor-timeout-seconds', '9'], { cwd, env, encoding: 'utf8' });
173
- assert.equal(api.status, 0, api.stderr);
174
- const plan = JSON.parse(api.stdout).plan.evaluation;
175
- assert.equal(plan.executor.kind, 'api');
176
- assert.equal(plan.executorTimeoutSeconds, 9);
177
- const defaults = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--dry-run', '--json'], { cwd, env, encoding: 'utf8' });
178
- assert.equal(defaults.status, 0, defaults.stderr);
179
- assert.equal(JSON.parse(defaults.stdout).plan.evaluation.executorTimeoutSeconds, 120);
180
- const trigger = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--agent', 'codex', '--mode', 'trigger', '--dry-run', '--json'], { cwd, env, encoding: 'utf8' });
181
- assert.equal(trigger.status, 0, trigger.stderr);
182
- assert.equal(JSON.parse(trigger.stdout).plan.evaluation.mode, 'trigger');
183
- const file = join(cwd, 'budget.json');
184
- writeFileSync(file, JSON.stringify({ input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 100 }));
185
- for (const flags of [['--mode', 'trigger', '--agent', 'codex'], ['--judge-agent', 'codex', '--agent', 'codex']]) {
186
- const result = spawnSync(process.execPath, [CLI, ...COMMANDS[0], '--dry-run', '--json', '--spending-budget', file, ...flags], { cwd, env, encoding: 'utf8' });
187
- assert.equal(result.status, 0, result.stderr);
188
- const preview = JSON.parse(result.stdout).plan.evaluation;
189
- assert.deepEqual(preview.spendingBudget, JSON.parse(readFileSync(file, 'utf8')));
190
- assert.equal(preview.plannedCalls, flags[0] === '--mode' ? 25 : 100);
191
- }
192
- assert.equal(existsSync(join(cwd, 'runs')), false);
193
- });