skillfit 0.15.2 → 0.16.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/CHANGELOG.md +39 -0
- package/README.md +33 -25
- package/README.zh-CN.md +33 -25
- package/benches/code-review/ground-truth/r1.md +3 -3
- package/benches/code-review/verifiers/seeded-bugs.mjs +25 -10
- package/dist/agents/mcp-probe.js +138 -13
- package/dist/bench/authoring.js +10 -2
- package/dist/cli/definition.js +28 -10
- package/dist/cli/doctor.js +33 -14
- package/dist/cli/eval-report.js +1 -1
- package/dist/cli/main.js +53 -6
- package/dist/cli/mcp.js +23 -7
- package/dist/cli/report.js +4 -1
- package/dist/composition.js +16 -0
- package/dist/configuration/bundle.js +150 -47
- package/dist/configuration/install.js +109 -23
- package/dist/configuration/lock.js +28 -0
- package/dist/configuration/mcp-write.js +311 -0
- package/dist/configuration/uninstall.js +241 -0
- package/dist/configuration/upstream.js +3 -0
- package/dist/evaluation/records/session.js +16 -8
- package/docs/README.md +7 -7
- package/docs/guides/experiment-workflow.md +25 -0
- package/docs/guides/selectable-codex.md +35 -4
- package/docs/maintainers/architecture.md +1 -1
- package/docs/reference/eval-component.md +2 -2
- package/docs/schemas/doctor-report.schema.json +92 -0
- package/package.json +1 -1
- package/skills/skillfit/SKILL.md +18 -15
- package/tools/verify/recipes/0.11.0-feature-smoke.mjs +140 -491
- package/tools/verify/recipes/release-feature-smoke.mjs +8 -4
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { getAgent } from "../agents/matrix.js";
|
|
6
|
+
import { resolveAgentPath } from "../agents/environment.js";
|
|
7
|
+
import { loadMcpProbeSpec, parseMcpProbeSpec } from "../agents/mcp-probe.js";
|
|
8
|
+
import { LOCKFILE_NAME, readLockfile } from "./lock.js";
|
|
9
|
+
import { executeTransaction } from "./transaction.js";
|
|
10
|
+
function stable(value) {
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.map(stable);
|
|
13
|
+
if (typeof value === "object" && value !== null)
|
|
14
|
+
return Object.fromEntries(Object.entries(value)
|
|
15
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
16
|
+
.map(([key, item]) => [key, stable(item)]));
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function entryHash(value) {
|
|
20
|
+
return createHash("sha256")
|
|
21
|
+
.update(JSON.stringify(stable(value)), "utf8")
|
|
22
|
+
.digest("hex");
|
|
23
|
+
}
|
|
24
|
+
function nativeEntry(spec) {
|
|
25
|
+
if (spec.transport === "http")
|
|
26
|
+
return {
|
|
27
|
+
type: "http",
|
|
28
|
+
url: spec.url,
|
|
29
|
+
headers: spec.headers ?? {},
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
type: "stdio",
|
|
33
|
+
command: spec.command,
|
|
34
|
+
args: spec.args,
|
|
35
|
+
env: spec.env ?? {},
|
|
36
|
+
cwd: spec.cwd,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function portableMcpSpec(spec, source) {
|
|
40
|
+
if (source["timeoutMs"] !== undefined)
|
|
41
|
+
throw new Error(`MCP server "${spec.name}" has an explicit timeout; portable export is unsupported`);
|
|
42
|
+
if (spec.transport === "stdio") {
|
|
43
|
+
if (spec.args.length > 0 ||
|
|
44
|
+
Object.keys(spec.env ?? {}).length > 0 ||
|
|
45
|
+
source["cwd"] !== undefined)
|
|
46
|
+
throw new Error(`MCP server "${spec.name}" has args, env or cwd; portable export requires these to be absent or empty`);
|
|
47
|
+
return {
|
|
48
|
+
schemaVersion: 1,
|
|
49
|
+
name: spec.name,
|
|
50
|
+
transport: "stdio",
|
|
51
|
+
command: spec.command,
|
|
52
|
+
args: [],
|
|
53
|
+
env: {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const url = new URL(spec.url);
|
|
57
|
+
if (Object.keys(spec.headers ?? {}).length > 0 ||
|
|
58
|
+
url.username ||
|
|
59
|
+
url.password ||
|
|
60
|
+
url.search ||
|
|
61
|
+
url.hash)
|
|
62
|
+
throw new Error(`MCP server "${spec.name}" has headers or URL credentials/query/fragment; portable export is refused`);
|
|
63
|
+
return {
|
|
64
|
+
schemaVersion: 1,
|
|
65
|
+
name: spec.name,
|
|
66
|
+
transport: "http",
|
|
67
|
+
url: spec.url,
|
|
68
|
+
headers: {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export async function loadPortableMcpSpec(file) {
|
|
72
|
+
const source = JSON.parse(await fs.readFile(file, "utf8"));
|
|
73
|
+
return portableMcpSpec(parseMcpProbeSpec(source, path.dirname(file)), source);
|
|
74
|
+
}
|
|
75
|
+
async function textIfExists(pathValue) {
|
|
76
|
+
try {
|
|
77
|
+
return await fs.readFile(pathValue, "utf8");
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.code === "ENOENT")
|
|
81
|
+
return null;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function printPlan(plan, log) {
|
|
86
|
+
log(`${plan.action}: mcp "${plan.server}" ${plan.path} (${plan.scope}) — ${plan.detail}`);
|
|
87
|
+
}
|
|
88
|
+
export async function planMcpApply(options) {
|
|
89
|
+
if (!options.agent || !options.server.trim())
|
|
90
|
+
throw new Error("MCP apply requires a non-empty --agent and --server.");
|
|
91
|
+
if (options.remove && options.from !== undefined)
|
|
92
|
+
throw new Error("MCP apply --remove cannot be combined with --from.");
|
|
93
|
+
if (!options.remove && options.from === undefined)
|
|
94
|
+
throw new Error("MCP apply needs --from <probe.json> or --remove.");
|
|
95
|
+
const agent = getAgent(options.agent);
|
|
96
|
+
const scope = options.project ? "project" : "user";
|
|
97
|
+
const homeDir = options.homeDir ?? os.homedir();
|
|
98
|
+
const projectDir = options.projectDir ?? process.cwd();
|
|
99
|
+
const env = options.env ?? process.env;
|
|
100
|
+
if (agent.mcp.format !== "json-mcpServers")
|
|
101
|
+
throw new Error(`Native ${agent.displayName} MCP format "${agent.mcp.format}" is not supported by mcp apply; no configuration was written and no server was contacted.`);
|
|
102
|
+
const context = { homeDir, cwd: projectDir, env };
|
|
103
|
+
const candidates = [
|
|
104
|
+
...new Set((options.project ? agent.mcp.projectFiles : agent.mcp.userFiles).map((file) => resolveAgentPath(file, context))),
|
|
105
|
+
];
|
|
106
|
+
const existingPaths = [];
|
|
107
|
+
for (const candidate of candidates)
|
|
108
|
+
if ((await textIfExists(candidate)) !== null)
|
|
109
|
+
existingPaths.push(candidate);
|
|
110
|
+
if (existingPaths.length > 1)
|
|
111
|
+
throw new Error(`Multiple ${scope} MCP configuration files exist for ${agent.displayName}; refusing to choose implicitly: ${existingPaths.join(", ")}`);
|
|
112
|
+
const target = existingPaths[0] ?? (candidates[0] ? resolveAgentPath(candidates[0], context) : null);
|
|
113
|
+
if (!target)
|
|
114
|
+
throw new Error(`${agent.displayName} has no ${scope} MCP configuration path.`);
|
|
115
|
+
try {
|
|
116
|
+
if ((await fs.lstat(target)).isSymbolicLink())
|
|
117
|
+
throw new Error(`Refusing to write through a symlinked MCP configuration: ${target}`);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error.code !== "ENOENT")
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
const spec = options.from === undefined
|
|
124
|
+
? null
|
|
125
|
+
: options.portable
|
|
126
|
+
? await loadPortableMcpSpec(options.from)
|
|
127
|
+
: loadMcpProbeSpec(options.from);
|
|
128
|
+
if (spec && spec.name !== options.server)
|
|
129
|
+
throw new Error(`Probe name "${spec.name}" does not match --server "${options.server}".`);
|
|
130
|
+
let document = {};
|
|
131
|
+
const currentText = await textIfExists(target);
|
|
132
|
+
if (currentText !== null) {
|
|
133
|
+
let parsed;
|
|
134
|
+
try {
|
|
135
|
+
parsed = JSON.parse(currentText);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new Error(`Invalid JSON MCP configuration at ${target}; no configuration was written and no server was contacted.`);
|
|
139
|
+
}
|
|
140
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
141
|
+
throw new Error(`MCP configuration at ${target} must contain a JSON object.`);
|
|
142
|
+
document = parsed;
|
|
143
|
+
}
|
|
144
|
+
const currentServers = document["mcpServers"] ?? {};
|
|
145
|
+
if (typeof currentServers !== "object" ||
|
|
146
|
+
currentServers === null ||
|
|
147
|
+
Array.isArray(currentServers))
|
|
148
|
+
throw new Error(`MCP configuration at ${target} requires an mcpServers object.`);
|
|
149
|
+
const servers = currentServers;
|
|
150
|
+
const existing = Object.hasOwn(servers, options.server) ? servers[options.server] : undefined;
|
|
151
|
+
const lockKey = `${agent.id}:mcp:${options.server}`;
|
|
152
|
+
const desired = options.remove ? null : nativeEntry(spec);
|
|
153
|
+
const desiredHash = entryHash(desired);
|
|
154
|
+
const currentHash = existing === undefined ? null : entryHash(existing);
|
|
155
|
+
const nextDocument = { ...document, mcpServers: { ...servers } };
|
|
156
|
+
if (options.remove)
|
|
157
|
+
delete nextDocument.mcpServers[options.server];
|
|
158
|
+
else
|
|
159
|
+
nextDocument.mcpServers[options.server] = desired;
|
|
160
|
+
const nextContent = `${JSON.stringify(nextDocument, null, 2)}\n`;
|
|
161
|
+
const lock = await readLockfile(path.join(scope === "user" ? homeDir : projectDir, LOCKFILE_NAME));
|
|
162
|
+
const lockEntry = lock.entries[lockKey];
|
|
163
|
+
if (lockEntry !== undefined &&
|
|
164
|
+
(lockEntry.agent !== agent.id ||
|
|
165
|
+
lockEntry.kind !== "mcp" ||
|
|
166
|
+
path.resolve(lockEntry.path) !== path.resolve(target)))
|
|
167
|
+
return {
|
|
168
|
+
agent: agent.id,
|
|
169
|
+
server: options.server,
|
|
170
|
+
scope,
|
|
171
|
+
path: target,
|
|
172
|
+
action: "conflict",
|
|
173
|
+
detail: "The lock record has a different agent, kind or target; no configuration or lock change is allowed",
|
|
174
|
+
lockKey,
|
|
175
|
+
entryHash: desiredHash,
|
|
176
|
+
lockOnly: false,
|
|
177
|
+
};
|
|
178
|
+
if (options.remove && existing === undefined)
|
|
179
|
+
return {
|
|
180
|
+
agent: agent.id,
|
|
181
|
+
server: options.server,
|
|
182
|
+
scope,
|
|
183
|
+
path: target,
|
|
184
|
+
action: "skip",
|
|
185
|
+
detail: lockEntry
|
|
186
|
+
? "Entry is already absent; remove only its lock record"
|
|
187
|
+
: "Entry is already absent; no change is needed",
|
|
188
|
+
lockKey,
|
|
189
|
+
entryHash: desiredHash,
|
|
190
|
+
lockOnly: lockEntry !== undefined,
|
|
191
|
+
};
|
|
192
|
+
if (existing === undefined)
|
|
193
|
+
return {
|
|
194
|
+
agent: agent.id,
|
|
195
|
+
server: options.server,
|
|
196
|
+
scope,
|
|
197
|
+
path: target,
|
|
198
|
+
action: options.remove ? "skip" : "create",
|
|
199
|
+
detail: options.remove
|
|
200
|
+
? "Entry is already absent"
|
|
201
|
+
: "Create only the selected JSON MCP entry",
|
|
202
|
+
lockKey,
|
|
203
|
+
entryHash: desiredHash,
|
|
204
|
+
nextContent,
|
|
205
|
+
lockOnly: false,
|
|
206
|
+
};
|
|
207
|
+
if (currentHash === desiredHash && !options.remove)
|
|
208
|
+
return {
|
|
209
|
+
agent: agent.id,
|
|
210
|
+
server: options.server,
|
|
211
|
+
scope,
|
|
212
|
+
path: target,
|
|
213
|
+
action: "skip",
|
|
214
|
+
detail: "The selected MCP entry already matches; no configuration change",
|
|
215
|
+
lockKey,
|
|
216
|
+
entryHash: desiredHash,
|
|
217
|
+
lockOnly: false,
|
|
218
|
+
};
|
|
219
|
+
if (lockEntry === undefined ||
|
|
220
|
+
lockEntry.kind !== "mcp" ||
|
|
221
|
+
path.resolve(lockEntry.path) !== path.resolve(target) ||
|
|
222
|
+
currentHash !== lockEntry.sha256)
|
|
223
|
+
return {
|
|
224
|
+
agent: agent.id,
|
|
225
|
+
server: options.server,
|
|
226
|
+
scope,
|
|
227
|
+
path: target,
|
|
228
|
+
action: "conflict",
|
|
229
|
+
detail: "The existing MCP entry is unmanaged, locally changed or has a different target; no overwrite or removal is allowed",
|
|
230
|
+
lockKey,
|
|
231
|
+
entryHash: desiredHash,
|
|
232
|
+
lockOnly: false,
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
agent: agent.id,
|
|
236
|
+
server: options.server,
|
|
237
|
+
scope,
|
|
238
|
+
path: target,
|
|
239
|
+
action: options.remove ? "remove" : "update",
|
|
240
|
+
detail: options.remove
|
|
241
|
+
? "Remove only the matching managed MCP entry"
|
|
242
|
+
: "Update the matching managed MCP entry",
|
|
243
|
+
lockKey,
|
|
244
|
+
entryHash: desiredHash,
|
|
245
|
+
nextContent,
|
|
246
|
+
lockOnly: false,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export async function runMcpApply(options) {
|
|
250
|
+
const plan = await planMcpApply(options);
|
|
251
|
+
const log = options.log ?? (() => { });
|
|
252
|
+
printPlan(plan, log);
|
|
253
|
+
if (plan.action === "conflict") {
|
|
254
|
+
if (options.dryRun)
|
|
255
|
+
return { status: "planned", plan };
|
|
256
|
+
throw new Error("MCP apply has a conflict; no configuration was changed and no server was contacted.");
|
|
257
|
+
}
|
|
258
|
+
if (options.dryRun)
|
|
259
|
+
return { status: "planned", plan };
|
|
260
|
+
if (plan.action === "skip" && !plan.lockOnly)
|
|
261
|
+
return { status: "unchanged", plan };
|
|
262
|
+
if (!options.yes) {
|
|
263
|
+
const ok = await (options.confirm ?? (async () => false))(`Apply MCP ${plan.action} for "${plan.server}" (${plan.scope})? [y/N] `);
|
|
264
|
+
if (!ok)
|
|
265
|
+
return { status: "cancelled", plan };
|
|
266
|
+
}
|
|
267
|
+
const homeDir = options.homeDir ?? os.homedir();
|
|
268
|
+
const projectDir = options.projectDir ?? process.cwd();
|
|
269
|
+
const scopeDir = plan.scope === "user" ? homeDir : projectDir;
|
|
270
|
+
const lockPath = path.join(scopeDir, LOCKFILE_NAME);
|
|
271
|
+
const lock = await readLockfile(lockPath);
|
|
272
|
+
const nextLock = { ...lock, entries: { ...lock.entries } };
|
|
273
|
+
if (plan.action === "remove" || plan.lockOnly) {
|
|
274
|
+
delete nextLock.entries[plan.lockKey];
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const previous = nextLock.entries[plan.lockKey];
|
|
278
|
+
nextLock.entries[plan.lockKey] = {
|
|
279
|
+
agent: plan.agent,
|
|
280
|
+
kind: "mcp",
|
|
281
|
+
path: plan.path,
|
|
282
|
+
sha256: plan.entryHash,
|
|
283
|
+
profile: "mcp-apply",
|
|
284
|
+
profileVersion: "1",
|
|
285
|
+
installedAt: (options.now?.() ?? new Date()).toISOString(),
|
|
286
|
+
};
|
|
287
|
+
if (previous && previous.kind !== "mcp")
|
|
288
|
+
throw new Error(`Existing lock entry ${plan.lockKey} is not an MCP entry.`);
|
|
289
|
+
}
|
|
290
|
+
const lockContent = `${JSON.stringify(nextLock, null, 2)}\n`;
|
|
291
|
+
const files = [];
|
|
292
|
+
if (!plan.lockOnly)
|
|
293
|
+
files.push({
|
|
294
|
+
path: plan.path,
|
|
295
|
+
content: plan.nextContent,
|
|
296
|
+
backup: (await textIfExists(plan.path)) === null ? "none" : "first",
|
|
297
|
+
});
|
|
298
|
+
files.push({
|
|
299
|
+
path: lockPath,
|
|
300
|
+
content: lockContent,
|
|
301
|
+
backup: (await textIfExists(lockPath)) === null ? "none" : "previous",
|
|
302
|
+
});
|
|
303
|
+
await executeTransaction(files, async () => {
|
|
304
|
+
if (!plan.lockOnly && (await textIfExists(plan.path)) !== plan.nextContent)
|
|
305
|
+
throw new Error(`MCP target content differs after apply: ${plan.path}`);
|
|
306
|
+
if ((await textIfExists(lockPath)) !== lockContent)
|
|
307
|
+
throw new Error(`Lockfile content differs after MCP apply: ${lockPath}`);
|
|
308
|
+
});
|
|
309
|
+
log(`MCP ${plan.action} applied for "${plan.server}"; configuration and lockfile verified. No server was started or contacted.`);
|
|
310
|
+
return { status: "applied", plan };
|
|
311
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { getAgent } from "../agents/matrix.js";
|
|
6
|
+
import { BACKUP_SUFFIX } from "./constants.js";
|
|
7
|
+
import { LOCKFILE_NAME, MARKER_END, MARKER_START, hashFiles, readLockfile, removeManagedBlock, rulesTarget, skillsTargetDir, } from "./install.js";
|
|
8
|
+
import { executeTransaction } from "./transaction.js";
|
|
9
|
+
function conflict(key, entry, pathValue, detail) {
|
|
10
|
+
return { key, kind: entry.kind, path: pathValue, action: "conflict", detail };
|
|
11
|
+
}
|
|
12
|
+
async function textIfExists(pathValue) {
|
|
13
|
+
try {
|
|
14
|
+
return await fs.readFile(pathValue, "utf8");
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code === "ENOENT")
|
|
18
|
+
return null;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function pathExists(pathValue) {
|
|
23
|
+
try {
|
|
24
|
+
await fs.lstat(pathValue);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error.code === "ENOENT")
|
|
29
|
+
return false;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function managedSkillHash(root) {
|
|
34
|
+
const files = new Map();
|
|
35
|
+
const walk = async (dir, prefix) => {
|
|
36
|
+
for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
|
|
37
|
+
if (entry.name.endsWith(BACKUP_SUFFIX))
|
|
38
|
+
continue;
|
|
39
|
+
const absolute = path.join(dir, entry.name);
|
|
40
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
41
|
+
if (entry.isSymbolicLink())
|
|
42
|
+
throw new Error(`Managed Skill contains a symlink: ${absolute}`);
|
|
43
|
+
if (entry.isDirectory())
|
|
44
|
+
await walk(absolute, relative);
|
|
45
|
+
else if (entry.isFile())
|
|
46
|
+
files.set(relative, await fs.readFile(absolute));
|
|
47
|
+
else
|
|
48
|
+
throw new Error(`Managed Skill contains a non-regular entry: ${absolute}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
await walk(root, "");
|
|
52
|
+
return hashFiles(files);
|
|
53
|
+
}
|
|
54
|
+
async function planSkill(key, entry, name, agent, scope, homeDir, projectDir) {
|
|
55
|
+
const target = path.join(skillsTargetDir(agent, scope, homeDir, projectDir), name);
|
|
56
|
+
if (!entry || entry.kind !== "skill" || entry.agent !== agent.id)
|
|
57
|
+
return {
|
|
58
|
+
key,
|
|
59
|
+
kind: "skill",
|
|
60
|
+
path: target,
|
|
61
|
+
action: "conflict",
|
|
62
|
+
detail: "No managed installation record exists for this Skill",
|
|
63
|
+
};
|
|
64
|
+
if (path.resolve(entry.path) !== path.resolve(target))
|
|
65
|
+
return conflict(key, entry, target, "The lock target differs from the current matrix path");
|
|
66
|
+
if (!(await pathExists(target)))
|
|
67
|
+
return {
|
|
68
|
+
key,
|
|
69
|
+
kind: "skill",
|
|
70
|
+
path: target,
|
|
71
|
+
action: "skip",
|
|
72
|
+
detail: "Target is already absent; remove only its lock entry",
|
|
73
|
+
};
|
|
74
|
+
const stat = await fs.lstat(target);
|
|
75
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
76
|
+
return conflict(key, entry, target, "The managed Skill target is not a regular directory");
|
|
77
|
+
const currentHash = await managedSkillHash(target);
|
|
78
|
+
if (currentHash !== entry.sha256)
|
|
79
|
+
return conflict(key, entry, target, "Local content or unexpected files differ from the managed installation");
|
|
80
|
+
return {
|
|
81
|
+
key,
|
|
82
|
+
kind: "skill",
|
|
83
|
+
path: target,
|
|
84
|
+
action: "remove",
|
|
85
|
+
detail: "Move the unchanged managed Skill to a fresh hidden recovery directory",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function planRules(entries, agent, scope, homeDir, projectDir, env) {
|
|
89
|
+
const targets = rulesTarget(agent, scope, homeDir, projectDir, env);
|
|
90
|
+
const selected = entries.filter(([, entry]) => entry.agent === agent.id && (entry.kind === "rules" || entry.kind === "bridge"));
|
|
91
|
+
if (selected.length === 0)
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
key: `${agent.id}:rules`,
|
|
95
|
+
kind: "rules",
|
|
96
|
+
path: targets.rulesFile,
|
|
97
|
+
action: "conflict",
|
|
98
|
+
detail: "No managed rules record exists for this Agent and scope",
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
const items = [];
|
|
102
|
+
for (const [key, entry] of selected) {
|
|
103
|
+
const expected = entry.kind === "rules" ? targets.rulesFile : targets.bridgeFile;
|
|
104
|
+
if (expected === null || path.resolve(entry.path) !== path.resolve(expected)) {
|
|
105
|
+
items.push(conflict(key, entry, entry.path, "The lock target differs from the current matrix path"));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const current = await textIfExists(entry.path);
|
|
109
|
+
if (current === null) {
|
|
110
|
+
items.push({
|
|
111
|
+
key,
|
|
112
|
+
kind: entry.kind,
|
|
113
|
+
path: entry.path,
|
|
114
|
+
action: "skip",
|
|
115
|
+
detail: "Target is already absent; remove only its lock entry",
|
|
116
|
+
});
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
let next;
|
|
120
|
+
try {
|
|
121
|
+
next = removeManagedBlock(current);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
items.push(conflict(key, entry, entry.path, error.message));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const start = current.indexOf(MARKER_START);
|
|
128
|
+
const block = current.slice(start, current.indexOf(MARKER_END) + MARKER_END.length);
|
|
129
|
+
const hash = createHash("sha256").update(block, "utf8").digest("hex");
|
|
130
|
+
if (hash !== entry.sha256) {
|
|
131
|
+
items.push(conflict(key, entry, entry.path, "The managed block differs from its lock fingerprint"));
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
items.push({
|
|
135
|
+
key,
|
|
136
|
+
kind: entry.kind,
|
|
137
|
+
path: entry.path,
|
|
138
|
+
action: next.trim().length === 0 ? "remove" : "update",
|
|
139
|
+
detail: next.trim().length === 0
|
|
140
|
+
? "Move the managed-only rules file to a fresh hidden recovery file"
|
|
141
|
+
: "Remove only the matching managed block and preserve all other content",
|
|
142
|
+
...(next.trim().length === 0 ? {} : { nextContent: next }),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return items;
|
|
146
|
+
}
|
|
147
|
+
function printPlan(items, log) {
|
|
148
|
+
for (const item of items)
|
|
149
|
+
log(`${item.action}: ${item.kind} ${item.path} — ${item.detail}`);
|
|
150
|
+
}
|
|
151
|
+
export async function runUninstall(options) {
|
|
152
|
+
const agent = getAgent(options.agent);
|
|
153
|
+
const names = [...new Set(options.skills ?? [])];
|
|
154
|
+
if (names.length === 0 && !options.rules)
|
|
155
|
+
throw new Error("Select at least one --skill or --rules for managed uninstall.");
|
|
156
|
+
if (names.some((name) => name.trim().length === 0))
|
|
157
|
+
throw new Error("Managed Skill names must be non-empty.");
|
|
158
|
+
const homeDir = options.homeDir ?? os.homedir();
|
|
159
|
+
const projectDir = options.projectDir ?? process.cwd();
|
|
160
|
+
const env = options.env ?? process.env;
|
|
161
|
+
const scope = options.project ? "project" : "user";
|
|
162
|
+
const scopeDir = options.project ? projectDir : homeDir;
|
|
163
|
+
const lockPath = path.join(scopeDir, LOCKFILE_NAME);
|
|
164
|
+
const lock = await readLockfile(lockPath);
|
|
165
|
+
const items = [];
|
|
166
|
+
for (const name of names) {
|
|
167
|
+
const key = `${agent.id}:skill:${name}`;
|
|
168
|
+
items.push(await planSkill(key, lock.entries[key], name, agent, scope, homeDir, projectDir));
|
|
169
|
+
}
|
|
170
|
+
if (options.rules)
|
|
171
|
+
items.push(...(await planRules(Object.entries(lock.entries), agent, scope, homeDir, projectDir, env)));
|
|
172
|
+
printPlan(items, options.log ?? (() => { }));
|
|
173
|
+
if (items.some((item) => item.action === "conflict")) {
|
|
174
|
+
if (options.dryRun)
|
|
175
|
+
return { status: "planned", items, recovery: [] };
|
|
176
|
+
throw new Error("Managed uninstall has conflicts; nothing was changed.");
|
|
177
|
+
}
|
|
178
|
+
if (options.dryRun)
|
|
179
|
+
return { status: "planned", items, recovery: [] };
|
|
180
|
+
if (!options.yes) {
|
|
181
|
+
const ok = await (options.confirm ?? (async () => false))(`Apply managed removal of ${items.length} item(s), including the lockfile? [y/N] `);
|
|
182
|
+
if (!ok)
|
|
183
|
+
return { status: "cancelled", items, recovery: [] };
|
|
184
|
+
}
|
|
185
|
+
const nextLock = { ...lock, entries: { ...lock.entries } };
|
|
186
|
+
for (const item of items)
|
|
187
|
+
delete nextLock.entries[item.key];
|
|
188
|
+
const lockContent = `${JSON.stringify(nextLock, null, 2)}\n`;
|
|
189
|
+
const files = items
|
|
190
|
+
.filter((item) => item.action === "update")
|
|
191
|
+
.map((item) => ({
|
|
192
|
+
path: item.path,
|
|
193
|
+
content: item.nextContent,
|
|
194
|
+
backup: "first",
|
|
195
|
+
}));
|
|
196
|
+
files.push({ path: lockPath, content: lockContent, backup: "previous" });
|
|
197
|
+
const moved = [];
|
|
198
|
+
try {
|
|
199
|
+
for (const item of items.filter((item) => item.action === "remove")) {
|
|
200
|
+
const recovery = path.join(path.dirname(item.path), `.${path.basename(item.path)}.${process.pid}.${randomUUID()}.skillfit-removed`);
|
|
201
|
+
if (await pathExists(recovery))
|
|
202
|
+
throw new Error(`Recovery path already exists: ${recovery}`);
|
|
203
|
+
await fs.rename(item.path, recovery);
|
|
204
|
+
moved.push({ target: item.path, recovery });
|
|
205
|
+
}
|
|
206
|
+
await executeTransaction(files, async () => {
|
|
207
|
+
for (const item of items) {
|
|
208
|
+
if (item.action === "remove" && (await pathExists(item.path)))
|
|
209
|
+
throw new Error(`Managed target still exists after recovery move: ${item.path}`);
|
|
210
|
+
if (item.action === "update" && (await textIfExists(item.path)) !== item.nextContent)
|
|
211
|
+
throw new Error(`Managed rules content differs after removal: ${item.path}`);
|
|
212
|
+
}
|
|
213
|
+
if ((await textIfExists(lockPath)) !== lockContent)
|
|
214
|
+
throw new Error(`Lockfile content differs after managed uninstall: ${lockPath}`);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
const lockCommitted = (await textIfExists(lockPath)) === lockContent;
|
|
219
|
+
if (lockCommitted)
|
|
220
|
+
throw new Error(`Managed uninstall was applied, but the writer reported an error: ${error.message}; recovery copies were retained at ${moved.map((item) => item.recovery).join(", ") || "none"}.`, { cause: error });
|
|
221
|
+
const failures = [];
|
|
222
|
+
for (const move of [...moved].reverse()) {
|
|
223
|
+
try {
|
|
224
|
+
if (await pathExists(move.target))
|
|
225
|
+
throw new Error("target already exists; refusing to overwrite it");
|
|
226
|
+
await fs.rename(move.recovery, move.target);
|
|
227
|
+
}
|
|
228
|
+
catch (restoreError) {
|
|
229
|
+
failures.push(`${move.target}: ${restoreError.message}; recovery retained at ${move.recovery}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (failures.length > 0)
|
|
233
|
+
throw new Error(`Managed uninstall failed (${error.message}); recovery restoration failed for ${failures.join("; ")}`, { cause: error });
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
const log = options.log ?? (() => { });
|
|
237
|
+
for (const move of moved)
|
|
238
|
+
log(`recovery: ${move.target} -> ${move.recovery}`);
|
|
239
|
+
log("Managed uninstall complete; recovery copies were retained. No unrelated resources were changed.");
|
|
240
|
+
return { status: "completed", items, recovery: moved };
|
|
241
|
+
}
|
|
@@ -192,6 +192,9 @@ export async function prepareUpstreamProfile(bundleDir, options = {}) {
|
|
|
192
192
|
await fs.writeFile(path.join(destination, "rules", "global.md"), options.rulesContent);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
if (selectedManifest.mcp && selectedManifest.mcp.length > 0) {
|
|
196
|
+
await copyRegularTree(path.join(source, "mcp"), path.join(destination, "mcp"));
|
|
197
|
+
}
|
|
195
198
|
for (const skill of selectedManifest.skills ?? []) {
|
|
196
199
|
if (skill.source !== `skills/${skill.name}` || !NAME.test(skill.name))
|
|
197
200
|
throw new Error(`Invalid portable source for ${skill.name}`);
|
|
@@ -4,7 +4,7 @@ export { probeVersion, validateCallBudget } from "../../agents/call-limits.js";
|
|
|
4
4
|
import { measurementScope, requestedClaimFor, assertScopeMatches, assertBenchClaimSupported, } from "../measurement/scope.js";
|
|
5
5
|
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, readdirSync, realpathSync, rmSync, writeFileSync, } from "node:fs";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
|
-
import { readAgentEnvironment, normalizeProjectTrust, } from "../../agents/environment.js";
|
|
7
|
+
import { readAgentEnvironment, resolveAgentPath, normalizeProjectTrust, } from "../../agents/environment.js";
|
|
8
8
|
export { normalizeProjectTrust } from "../../agents/environment.js";
|
|
9
9
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { getAgent } from "../../agents/matrix.js";
|
|
@@ -20,14 +20,13 @@ import { loadBench } from "../../bench/read.js";
|
|
|
20
20
|
import { spendingStopFrom } from "../execution/budget.js";
|
|
21
21
|
import { assertEvaluationOutputLayout, physicalPath } from "../targets/output-layout.js";
|
|
22
22
|
import { assertSessionDetails } from "./contracts.js";
|
|
23
|
-
function skillInventory(root) {
|
|
24
|
-
if (!existsSync(root))
|
|
25
|
-
return { root, entries: ["missing"] };
|
|
23
|
+
function skillInventory(root, managedSystem = false) {
|
|
26
24
|
return {
|
|
27
25
|
root,
|
|
28
26
|
entries: [
|
|
29
|
-
|
|
30
|
-
...readdirSync(root)
|
|
27
|
+
physicalPath(root),
|
|
28
|
+
...(existsSync(root) ? readdirSync(root) : [])
|
|
29
|
+
.filter((entry) => !managedSystem || entry !== ".system")
|
|
31
30
|
.sort()
|
|
32
31
|
.map((entry) => {
|
|
33
32
|
const path = join(root, entry);
|
|
@@ -97,6 +96,7 @@ export class ExperimentSession {
|
|
|
97
96
|
workspaceAliases;
|
|
98
97
|
trustWorkspaces;
|
|
99
98
|
inventories = [];
|
|
99
|
+
managedSkillRoot = null;
|
|
100
100
|
callsStarted = 0;
|
|
101
101
|
callsFinished = 0;
|
|
102
102
|
stopReason = null;
|
|
@@ -172,11 +172,19 @@ export class ExperimentSession {
|
|
|
172
172
|
const agent = getAgent(options.agent);
|
|
173
173
|
const home = options.homeDir ?? homedir();
|
|
174
174
|
const environment = readAgentEnvironment(agent, { homeDir: home, cwd: process.cwd(), env });
|
|
175
|
+
const override = agent.skills.userHomeOverride;
|
|
176
|
+
if (agent.id === "codex" && override) {
|
|
177
|
+
const spec = env[override.env]
|
|
178
|
+
? join(env[override.env], override.relativePath)
|
|
179
|
+
: override.fallback;
|
|
180
|
+
this.managedSkillRoot = resolveAgentPath(spec, { homeDir: home, cwd: process.cwd(), env });
|
|
181
|
+
}
|
|
175
182
|
configured = environment.settings.fields;
|
|
176
183
|
for (const file of environment.configFiles)
|
|
177
184
|
this.configs.push(configState(file.path, file.trust, this.trustWorkspaces));
|
|
178
185
|
for (const root of environment.skillRoots) {
|
|
179
|
-
|
|
186
|
+
// Codex synchronizes .system itself, including on first use of a fresh profile.
|
|
187
|
+
this.inventories.push(skillInventory(root, root === this.managedSkillRoot));
|
|
180
188
|
if (!existsSync(root))
|
|
181
189
|
continue;
|
|
182
190
|
for (const entry of readdirSync(root)) {
|
|
@@ -304,7 +312,7 @@ export class ExperimentSession {
|
|
|
304
312
|
throw new Error(`Agent configuration changed: ${config.path}; no further calls.`);
|
|
305
313
|
}
|
|
306
314
|
for (const inventory of this.inventories)
|
|
307
|
-
if (JSON.stringify(skillInventory(inventory.root)) !== JSON.stringify(inventory)) {
|
|
315
|
+
if (JSON.stringify(skillInventory(inventory.root, inventory.root === this.managedSkillRoot)) !== JSON.stringify(inventory)) {
|
|
308
316
|
throw new Error(`Global Skill inventory changed: ${inventory.root}; no further calls.`);
|
|
309
317
|
}
|
|
310
318
|
}
|
package/docs/README.md
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Choose your build
|
|
4
4
|
|
|
5
|
-
These pages describe the **0.
|
|
5
|
+
These pages describe the **0.16.0 package and current source**; source guides use
|
|
6
6
|
Node >=22, `npm run build` and `node dist/cli.js`. The pinned
|
|
7
|
-
`npx skillfit@0.
|
|
7
|
+
`npx skillfit@0.16.0` commands name the version these pages describe; the registry
|
|
8
8
|
is the source of truth for what is currently published. Superseded releases keep
|
|
9
9
|
their own documentation: see the
|
|
10
10
|
[0.13.1 documentation](https://github.com/remote-controlled-man/skillfit/tree/4eaefde80f7e8a6b1e01939d3bd8a8b6418b75d6/docs)
|
|
11
11
|
and its [publication record](https://github.com/remote-controlled-man/skillfit/blob/3a3ff415ccef1a3a45d1e2d2cc00d903ab7db850/docs/releases/0.13.1.md).
|
|
12
12
|
Standalone driver links and unshipped source references use the
|
|
13
|
-
[reviewed source snapshot](https://github.com/remote-controlled-man/skillfit/tree/
|
|
14
|
-
|
|
13
|
+
[reviewed source snapshot](https://github.com/remote-controlled-man/skillfit/tree/3656a8975fa29af822a7359d18d0578b415c755b),
|
|
14
|
+
which contains personal configuration maintenance before the version bump. Building that commit prints 0.15.4.
|
|
15
15
|
|
|
16
16
|
## Find your task
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ the commit tag v0.15.0 names. Building that commit prints 0.15.0.
|
|
|
20
20
|
| Learn the complete workflow without model spending | [First evaluation](guides/first-real-eval.md) |
|
|
21
21
|
| Prepare and validate your own cases | [Bench authoring](guides/bench-authoring.md) |
|
|
22
22
|
| Plan/run an experiment, handle stops and retain/clean outputs | [Evaluation workflow](guides/experiment-workflow.md) |
|
|
23
|
-
| Select Skills or move a Codex configuration | [
|
|
23
|
+
| Select Skills or move a Codex/Kimi configuration | [Agent configuration](guides/selectable-codex.md) |
|
|
24
24
|
| Integrate JSON requests/results | [Component contract](reference/eval-component.md) |
|
|
25
25
|
| Look up result fields, costs or replay formats | [Report reference](reference/evaluation-reports.md) |
|
|
26
26
|
| Understand statistical verdicts and adoption limits | [Metrics protocol](reference/metrics.md) |
|
|
@@ -29,8 +29,8 @@ the commit tag v0.15.0 names. Building that commit prints 0.15.0.
|
|
|
29
29
|
|
|
30
30
|
CLI `--help` owns flags; [Bench format](../benches/README.md) owns task files and
|
|
31
31
|
claims. JSON schemas, executable examples and SVG assets remain under `schemas/`,
|
|
32
|
-
`examples/` and `assets/`.
|
|
33
|
-
|
|
32
|
+
`examples/` and `assets/`. See [GitHub Issues](https://github.com/remote-controlled-man/skillfit/issues)
|
|
33
|
+
for public work.
|
|
34
34
|
|
|
35
35
|
Retired pages, research files and earlier layouts stay in Git history:
|
|
36
36
|
[documentation snapshot](https://github.com/remote-controlled-man/skillfit/tree/5696bfa32cf28a5fc11d8d5da237f5d070a3cf17/docs),
|