@mmerterden/multi-agent-pipeline 23.4.0 → 23.5.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 +35 -6
- package/README.md +4 -4
- package/README.tr.md +4 -4
- package/SECURITY.md +16 -0
- package/docs/ecosystem.md +5 -5
- package/docs/facts.json +4 -4
- package/docs/features.md +1 -1
- package/install/_platform-filter.mjs +2 -55
- package/install/codex.mjs +1 -3
- package/install/copilot.mjs +4 -8
- package/manifest.json +46 -45
- package/package.json +2 -2
- package/pipeline/commands/multi-agent/design-check/SKILL.md +1 -0
- package/pipeline/contract/CHANGELOG.md +14 -0
- package/pipeline/contract/README.md +1 -0
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/manifest.json +14 -1
- package/pipeline/contract/types/index.d.ts +28 -2
- package/pipeline/lib/stack-detect.sh +1 -1
- package/pipeline/lib/usage-names.generated.mjs +0 -1
- package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
- package/pipeline/multi-agent-refs/features/remote-control.md +2 -1
- package/pipeline/multi-agent-refs/features/usage-reporting.md +4 -4
- package/pipeline/multi-agent-refs/help/en.md +1 -1
- package/pipeline/multi-agent-refs/help/tr.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
- package/pipeline/office/index.html +104 -5
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/mcp-health.schema.json +96 -0
- package/pipeline/schemas/toolkit-path-params.json +1 -7
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +12 -0
- package/pipeline/scripts/build-stack-plugins.mjs +1 -47
- package/pipeline/scripts/contract-server.mjs +2 -0
- package/pipeline/scripts/design-check-config.mjs +205 -0
- package/pipeline/scripts/gen-facts.mjs +1 -2
- package/pipeline/scripts/mcp-health.mjs +309 -0
- package/pipeline/scripts/remote/handler.mjs +19 -6
- package/pipeline/scripts/remote/store.mjs +8 -5
- package/pipeline/scripts/skill-usage.mjs +16 -5
- package/pipeline/skills/.skill-manifest.json +1 -1
- package/pipeline/scripts/_renamed-skills.mjs +0 -164
- package/pipeline/skills/renamed.json +0 -30
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file mcp-health.mjs - how the MCP servers a session uses are doing, per
|
|
4
|
+
* server and tool: calls, failures and when the last failure happened.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here measures anything of its own. Two local files the hooks already
|
|
7
|
+
* write are read and never changed:
|
|
8
|
+
*
|
|
9
|
+
* mcp-failures.jsonl one row per failed call (note-mcp-failure.mjs): server,
|
|
10
|
+
* tool, time and a closed error class. Read with its
|
|
11
|
+
* previous generation.
|
|
12
|
+
* mcp-calls.json successful calls per host session, folded from
|
|
13
|
+
* mcp-calls.log the hook's own log; the lines no report has folded yet
|
|
14
|
+
* are counted as recent
|
|
15
|
+
*
|
|
16
|
+
* Only the last WINDOW_DAYS count. A counter session is counted whole when its
|
|
17
|
+
* last fold falls inside the window, including calls made before the window
|
|
18
|
+
* began; a failure row is counted by its own time. A call that failed is a call, so `calls` is
|
|
19
|
+
* the successful calls plus every failed one; `failures` leaves out the errors
|
|
20
|
+
* that say nothing about the server (invalid input, a refusal by the user or
|
|
21
|
+
* the permission layer, an interrupt), the same split `doctor` uses.
|
|
22
|
+
* `lastFailure` is the time of the last of those failures, to the minute.
|
|
23
|
+
* Successful calls are counted only while usage counting is on (the call
|
|
24
|
+
* counter's switches, note-mcp-failure.mjs callCountEnabled), failures always.
|
|
25
|
+
* With counting off the counter files are not read at all. `callsCounted` says which: false when counting is off or neither counter file
|
|
26
|
+
* exists, and then `calls` holds only the failed calls and is not a call count.
|
|
27
|
+
*
|
|
28
|
+
* Names follow the usage record's rule: a server is named only when it is on
|
|
29
|
+
* the shipped public list (lib/public-mcp-servers.mjs), any other server is the
|
|
30
|
+
* constant `private` with its tools folded into one `private` row, and a tool is
|
|
31
|
+
* named only when it is on the shipped tool list of this product's own server
|
|
32
|
+
* (the generated TOOLKIT_TOOLS), any other is `other`. Names, counts and
|
|
33
|
+
* minutes only: never arguments, results or error text.
|
|
34
|
+
*
|
|
35
|
+
* Files are read through rotated-log.mjs (a generation that is not a regular
|
|
36
|
+
* file is never read; a link or special file where a log or counter belongs is
|
|
37
|
+
* named in `skipped`, like one over the size cap) and the bounded regular-file reader (no link followed,
|
|
38
|
+
* at most READ_MAX bytes each). A file over the cap is left out and named in
|
|
39
|
+
* `skipped`; the rest still answers. Sizes of the answer are bounded too:
|
|
40
|
+
* MAX_SERVERS servers with MAX_TOOLS_PER_SERVER tools each, the rest folded
|
|
41
|
+
* into `other`.
|
|
42
|
+
*
|
|
43
|
+
* Local only: it describes which servers this machine has registered.
|
|
44
|
+
*
|
|
45
|
+
* Usage:
|
|
46
|
+
* mcp-health.mjs [--json]
|
|
47
|
+
*
|
|
48
|
+
* Exit: 0 printed, 2 usage.
|
|
49
|
+
*
|
|
50
|
+
* @module pipeline/scripts/mcp-health
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
import { lstatSync } from "node:fs";
|
|
54
|
+
import { join } from "node:path";
|
|
55
|
+
|
|
56
|
+
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
57
|
+
import { invokedDirectly } from "../lib/invoked-directly.mjs";
|
|
58
|
+
import { MCP_SERVER_ID } from "../lib/mcp-rename.mjs";
|
|
59
|
+
import { isPublicMcpServer } from "../lib/public-mcp-servers.mjs";
|
|
60
|
+
import { readRegularFile } from "../lib/regular-file.mjs";
|
|
61
|
+
import { rotatedPaths } from "../lib/rotated-log.mjs";
|
|
62
|
+
import { TOOLKIT_TOOLS } from "../lib/usage-names.generated.mjs";
|
|
63
|
+
import {
|
|
64
|
+
CALLER_SIDE,
|
|
65
|
+
CALLS_FILE,
|
|
66
|
+
CALLS_LOG,
|
|
67
|
+
ERROR_CLASSES,
|
|
68
|
+
LOG_FILE,
|
|
69
|
+
callKeyOf,
|
|
70
|
+
callCountEnabled,
|
|
71
|
+
} from "./note-mcp-failure.mjs";
|
|
72
|
+
import { logDir } from "./note-skill-use.mjs";
|
|
73
|
+
|
|
74
|
+
exitOnHelp(import.meta.url);
|
|
75
|
+
|
|
76
|
+
export const CONTRACT_VERSION = "1.0.0";
|
|
77
|
+
export const WINDOW_DAYS = 7;
|
|
78
|
+
const MAX_SERVERS = 5;
|
|
79
|
+
export const MAX_TOOLS_PER_SERVER = 20;
|
|
80
|
+
const MAX_COUNT = 1_000_000;
|
|
81
|
+
const READ_MAX = 4 * 1024 * 1024;
|
|
82
|
+
const DAY_MS = 86_400_000;
|
|
83
|
+
const TOOL_PART = /^[A-Za-z0-9_]{1,64}$/;
|
|
84
|
+
const SESSION_ID = /^[A-Za-z0-9_-]{8,64}$/;
|
|
85
|
+
const TOOLKIT_TOOL_SET = new Set(TOOLKIT_TOOLS);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The server and tool as the document names them, or null for a value that is
|
|
89
|
+
* not a string. A server off the public list is private whatever its name looks
|
|
90
|
+
* like, and a tool is named only from the shipped list, so no pattern decides
|
|
91
|
+
* whether a failure is counted.
|
|
92
|
+
*/
|
|
93
|
+
function label(server, tool) {
|
|
94
|
+
if (typeof server !== "string" || typeof tool !== "string") return null;
|
|
95
|
+
if (!isPublicMcpServer(server)) return { server: "private", tool: "private" };
|
|
96
|
+
const named = server === MCP_SERVER_ID && TOOL_PART.test(tool) && TOOLKIT_TOOL_SET.has(tool);
|
|
97
|
+
return { server, tool: named ? tool : "other" };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const minute = (ms) => `${new Date(ms).toISOString().slice(0, 16)}:00Z`;
|
|
101
|
+
|
|
102
|
+
/** The file's text, or null with `skip` set when it exists and cannot be read within the bounds. */
|
|
103
|
+
function readBounded(path, dir, skip) {
|
|
104
|
+
try {
|
|
105
|
+
return readRegularFile(path, { maxBytes: READ_MAX, within: [dir], noFollow: true });
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (/ENOENT/.test(e?.message ?? "")) return null;
|
|
108
|
+
skip();
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function failureRows(dir, skip) {
|
|
114
|
+
const out = [];
|
|
115
|
+
const file = join(dir, LOG_FILE);
|
|
116
|
+
const regular = new Set(rotatedPaths(file));
|
|
117
|
+
for (const path of [`${file}.1`, file]) {
|
|
118
|
+
if (regular.has(path)) continue;
|
|
119
|
+
try {
|
|
120
|
+
lstatSync(path);
|
|
121
|
+
skip();
|
|
122
|
+
} catch {
|
|
123
|
+
/* not there */
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const path of regular) {
|
|
127
|
+
const text = readBounded(path, dir, skip);
|
|
128
|
+
for (const line of (text ?? "").split("\n")) {
|
|
129
|
+
if (!line.startsWith("{")) continue;
|
|
130
|
+
try {
|
|
131
|
+
const r = JSON.parse(line);
|
|
132
|
+
const named = label(r?.server, r?.tool);
|
|
133
|
+
const at = Date.parse(r?.ts);
|
|
134
|
+
if (named && Number.isFinite(at)) {
|
|
135
|
+
const cls = ERROR_CLASSES.includes(r.errorClass) ? r.errorClass : "other";
|
|
136
|
+
out.push({ ...named, at, serverSide: !CALLER_SIDE.has(cls) });
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
/* a torn line */
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function callCounts(dir, since, now, skip) {
|
|
147
|
+
const out = [];
|
|
148
|
+
let seen = false;
|
|
149
|
+
const add = (key, n) => {
|
|
150
|
+
const at = key.indexOf(":");
|
|
151
|
+
const named = at > 0 ? label(key.slice(0, at), key.slice(at + 1)) : null;
|
|
152
|
+
if (named && Number.isInteger(n) && n > 0) out.push({ ...named, n: Math.min(n, MAX_COUNT) });
|
|
153
|
+
};
|
|
154
|
+
const counter = readBounded(join(dir, CALLS_FILE), dir, () => skip("calls"));
|
|
155
|
+
if (counter !== null) {
|
|
156
|
+
seen = true;
|
|
157
|
+
try {
|
|
158
|
+
const sessions = JSON.parse(counter)?.sessions;
|
|
159
|
+
for (const s of Object.values(sessions && typeof sessions === "object" ? sessions : {})) {
|
|
160
|
+
const t = Date.parse(s?.t);
|
|
161
|
+
if (!(t >= since && t <= now) || !s?.calls || typeof s.calls !== "object") continue;
|
|
162
|
+
for (const [key, n] of Object.entries(s.calls)) add(key, n);
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
/* a damaged counter counts nothing */
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const pending = readBounded(join(dir, CALLS_LOG), dir, () => skip("calls"));
|
|
169
|
+
if (pending !== null) seen = true;
|
|
170
|
+
const tally = new Map();
|
|
171
|
+
for (const line of (pending ?? "").split("\n")) {
|
|
172
|
+
const [sid, name, extra] = line.split(" ");
|
|
173
|
+
if (extra !== undefined || !SESSION_ID.test(sid ?? "")) continue;
|
|
174
|
+
const key = callKeyOf(name);
|
|
175
|
+
if (key) tally.set(key, (tally.get(key) ?? 0) + 1);
|
|
176
|
+
}
|
|
177
|
+
for (const [key, n] of tally) add(key, n);
|
|
178
|
+
return { out, seen };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function fold(into, tool, patch) {
|
|
182
|
+
const t = into.get(tool) ?? { tool, calls: 0, failures: 0, last: 0 };
|
|
183
|
+
t.calls = Math.min(t.calls + (patch.calls ?? 0), MAX_COUNT);
|
|
184
|
+
t.failures = Math.min(t.failures + (patch.failures ?? 0), MAX_COUNT);
|
|
185
|
+
t.last = Math.max(t.last, patch.last ?? 0);
|
|
186
|
+
into.set(tool, t);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const shown = (t) => ({
|
|
190
|
+
tool: t.tool,
|
|
191
|
+
calls: t.calls,
|
|
192
|
+
failures: t.failures,
|
|
193
|
+
lastFailure: t.last ? minute(t.last) : null,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
function limitTools(map) {
|
|
197
|
+
const ranked = [...map.values()].sort(
|
|
198
|
+
(a, b) => b.failures - a.failures || b.calls - a.calls || (a.tool < b.tool ? -1 : 1),
|
|
199
|
+
);
|
|
200
|
+
if (ranked.length <= MAX_TOOLS_PER_SERVER) return ranked;
|
|
201
|
+
const keep = ranked.filter((t) => t.tool !== "other").slice(0, MAX_TOOLS_PER_SERVER - 1);
|
|
202
|
+
const rest = new Map();
|
|
203
|
+
for (const t of ranked) {
|
|
204
|
+
if (!keep.includes(t)) fold(rest, "other", t);
|
|
205
|
+
}
|
|
206
|
+
return [...keep, ...rest.values()];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @param {{env?: NodeJS.ProcessEnv, now?: number}} [opts]
|
|
211
|
+
*/
|
|
212
|
+
export function mcpHealth({ env = process.env, now = Date.now() } = {}) {
|
|
213
|
+
const dir = logDir(env);
|
|
214
|
+
const since = now - WINDOW_DAYS * DAY_MS;
|
|
215
|
+
const skipped = new Set();
|
|
216
|
+
const failures = failureRows(dir, () => skipped.add("failures")).filter(
|
|
217
|
+
(r) => r.at >= since && r.at <= now,
|
|
218
|
+
);
|
|
219
|
+
const countingOn = callCountEnabled(env);
|
|
220
|
+
const { out: counted, seen } = countingOn
|
|
221
|
+
? callCounts(dir, since, now, (what) => skipped.add(what))
|
|
222
|
+
: { out: [], seen: false };
|
|
223
|
+
const callsCounted = countingOn && seen;
|
|
224
|
+
|
|
225
|
+
const servers = new Map();
|
|
226
|
+
const slot = (server) => {
|
|
227
|
+
if (!servers.has(server)) servers.set(server, new Map());
|
|
228
|
+
return servers.get(server);
|
|
229
|
+
};
|
|
230
|
+
for (const c of counted) fold(slot(c.server), c.tool, { calls: c.n });
|
|
231
|
+
for (const f of failures) {
|
|
232
|
+
fold(slot(f.server), f.tool, {
|
|
233
|
+
calls: 1,
|
|
234
|
+
failures: f.serverSide ? 1 : 0,
|
|
235
|
+
last: f.serverSide ? f.at : 0,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const rows = [...servers].map(([server, tools]) => {
|
|
240
|
+
const list = limitTools(tools);
|
|
241
|
+
return {
|
|
242
|
+
server,
|
|
243
|
+
calls: list.reduce((n, t) => n + t.calls, 0),
|
|
244
|
+
failures: list.reduce((n, t) => n + t.failures, 0),
|
|
245
|
+
lastFailure: list.reduce((m, t) => Math.max(m, t.last), 0),
|
|
246
|
+
tools: list.map(shown),
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
rows.sort(
|
|
250
|
+
(a, b) => b.failures - a.failures || b.calls - a.calls || (a.server < b.server ? -1 : 1),
|
|
251
|
+
);
|
|
252
|
+
const top = rows.slice(0, MAX_SERVERS).map((s) => ({
|
|
253
|
+
...s,
|
|
254
|
+
lastFailure: s.lastFailure ? minute(s.lastFailure) : null,
|
|
255
|
+
}));
|
|
256
|
+
return {
|
|
257
|
+
contractVersion: CONTRACT_VERSION,
|
|
258
|
+
generatedAt: new Date(now).toISOString(),
|
|
259
|
+
ok: true,
|
|
260
|
+
windowDays: WINDOW_DAYS,
|
|
261
|
+
callsCounted,
|
|
262
|
+
servers: top,
|
|
263
|
+
totals: {
|
|
264
|
+
calls: top.reduce((n, s) => n + s.calls, 0),
|
|
265
|
+
failures: top.reduce((n, s) => n + s.failures, 0),
|
|
266
|
+
},
|
|
267
|
+
skipped: [...skipped].sort(),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* A reader that reuses one answer for ttlMs, so a panel polling every few
|
|
273
|
+
* seconds reads the logs about once a minute.
|
|
274
|
+
* @param {{ttlMs?: number, now?: () => number, compute?: () => object}} [opts]
|
|
275
|
+
*/
|
|
276
|
+
export function createMcpHealthCache({
|
|
277
|
+
ttlMs = 60_000,
|
|
278
|
+
now = Date.now,
|
|
279
|
+
compute = () => mcpHealth(),
|
|
280
|
+
} = {}) {
|
|
281
|
+
let at = -Infinity;
|
|
282
|
+
let doc = null;
|
|
283
|
+
return () => {
|
|
284
|
+
const t = now();
|
|
285
|
+
if (doc === null || t - at >= ttlMs || t < at) {
|
|
286
|
+
doc = compute();
|
|
287
|
+
at = t;
|
|
288
|
+
}
|
|
289
|
+
return doc;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (invokedDirectly(import.meta.url)) {
|
|
294
|
+
const args = process.argv.slice(2);
|
|
295
|
+
if (args.some((a) => a !== "--json")) {
|
|
296
|
+
console.error("usage: mcp-health.mjs [--json]");
|
|
297
|
+
process.exit(2);
|
|
298
|
+
}
|
|
299
|
+
const doc = mcpHealth();
|
|
300
|
+
process.stdout.write(
|
|
301
|
+
args.includes("--json")
|
|
302
|
+
? JSON.stringify(doc) + "\n"
|
|
303
|
+
: doc.servers.length
|
|
304
|
+
? doc.servers
|
|
305
|
+
.map((s) => `${s.server}: ${s.calls} calls, ${s.failures} failures`)
|
|
306
|
+
.join("\n") + "\n"
|
|
307
|
+
: `no MCP calls recorded in the last ${doc.windowDays} days\n`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
@@ -248,6 +248,7 @@ export async function handleRequest(item, ctx) {
|
|
|
248
248
|
audit(env, {
|
|
249
249
|
device: req.deviceId,
|
|
250
250
|
verb: req.verb,
|
|
251
|
+
run: issuedHandle(ctx.executor, req.deviceId, answer.run),
|
|
251
252
|
outcome: answer.payload.ok ? "ok" : "refused",
|
|
252
253
|
reason: answer.payload.ok ? (gap ? "gap" : "") : answer.payload.error,
|
|
253
254
|
});
|
|
@@ -268,6 +269,16 @@ export async function handleRequest(item, ctx) {
|
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
|
|
272
|
+
/**
|
|
273
|
+
* The run value of a verb for the audit line: only a handle this device was
|
|
274
|
+
* given by the executor's table, never a raw run id or anything else the
|
|
275
|
+
* phone sent.
|
|
276
|
+
*/
|
|
277
|
+
function issuedHandle(executor, deviceId, handle) {
|
|
278
|
+
if (typeof handle !== "string" || !executor?.handles) return "";
|
|
279
|
+
return executor.handles.resolve(deviceId, handle) === null ? "" : handle;
|
|
280
|
+
}
|
|
281
|
+
|
|
271
282
|
const dropCode = (reason) =>
|
|
272
283
|
String(reason)
|
|
273
284
|
.toLowerCase()
|
|
@@ -294,24 +305,26 @@ async function decide(req, device, payload, ctx, now) {
|
|
|
294
305
|
return { payload: refusal("iat") };
|
|
295
306
|
}
|
|
296
307
|
|
|
308
|
+
let run = "";
|
|
297
309
|
if (spec.target === "run") {
|
|
298
310
|
const tag = runTag(b64uDecode(device.keys.tag), checked.args.run);
|
|
299
311
|
if (!equalBytes(Buffer.from(tag), Buffer.from(req.runTag)))
|
|
300
312
|
return { payload: refusal("run_tag") };
|
|
313
|
+
run = checked.args.run;
|
|
301
314
|
} else if (req.runTag !== "") {
|
|
302
315
|
return { payload: refusal("run_tag") };
|
|
303
316
|
}
|
|
304
317
|
|
|
305
|
-
if (spec.mutating && ctx.unattended()) return { payload: refusal("unattended") };
|
|
318
|
+
if (spec.mutating && ctx.unattended()) return { payload: refusal("unattended"), run };
|
|
306
319
|
|
|
307
|
-
const
|
|
308
|
-
if (typeof
|
|
320
|
+
const execute = ctx.executor[payload.verb];
|
|
321
|
+
if (typeof execute !== "function") return { payload: refusal("phase"), run };
|
|
309
322
|
try {
|
|
310
|
-
const result = await
|
|
311
|
-
return { payload: { v: WIRE_VERSION, ok: true, result } };
|
|
323
|
+
const result = await execute(checked.args, { deviceId: req.deviceId });
|
|
324
|
+
return { payload: { v: WIRE_VERSION, ok: true, result }, run };
|
|
312
325
|
} catch (err) {
|
|
313
326
|
const code =
|
|
314
327
|
typeof err?.code === "string" && /^[a-z_]{1,32}$/.test(err.code) ? err.code : "internal";
|
|
315
|
-
return { payload: refusal(code) };
|
|
328
|
+
return { payload: refusal(code), run };
|
|
316
329
|
}
|
|
317
330
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* devices.json 0600 the pinned devices and their session keys,
|
|
8
8
|
* counters and reply sequence; every change is a
|
|
9
9
|
* locked read-modify-write, replaced atomically
|
|
10
|
-
* audit.jsonl 0600 one line per request: time, device, verb, outcome;
|
|
10
|
+
* audit.jsonl 0600 one line per request: time, device, verb, run handle, outcome;
|
|
11
11
|
* never content, rotated at a size cap
|
|
12
12
|
* listener.json 0600 the background listener's pid record (lifecycle.mjs)
|
|
13
13
|
*
|
|
@@ -24,6 +24,7 @@ import { updateJsonFileSync } from "../../lib/json-file-lock.mjs";
|
|
|
24
24
|
import { appendFileSafe } from "../../lib/safe-write.mjs";
|
|
25
25
|
import { readRegularJson } from "../../lib/regular-file.mjs";
|
|
26
26
|
import { autopilotRoot } from "../../lib/pr-request-location.mjs";
|
|
27
|
+
import { HANDLE_PATTERN } from "./handles.mjs";
|
|
27
28
|
|
|
28
29
|
export const MAX_DEVICES = 5;
|
|
29
30
|
export const AUDIT_CAP_BYTES = 256 * 1024;
|
|
@@ -158,17 +159,19 @@ const AUDIT_OUTCOMES = new Set([
|
|
|
158
159
|
|
|
159
160
|
/**
|
|
160
161
|
* One audit line. Only the first 8 characters of the device id, the verb
|
|
161
|
-
* name when it is a contract verb, a fixed outcome
|
|
162
|
-
*
|
|
163
|
-
*
|
|
162
|
+
* name when it is a contract verb, a fixed outcome, a short reason code and,
|
|
163
|
+
* for a verb about one run, that run's opaque handle (the value the phone
|
|
164
|
+
* holds, never the run id) are written: no argument, answer, key or token
|
|
165
|
+
* ever reaches this function's output.
|
|
164
166
|
*/
|
|
165
|
-
export function audit(env, { device = "", verb = "", outcome, reason = "" }) {
|
|
167
|
+
export function audit(env, { device = "", verb = "", outcome, reason = "", run = "" }) {
|
|
166
168
|
const line = {
|
|
167
169
|
t: new Date().toISOString(),
|
|
168
170
|
device: String(device).slice(0, 8),
|
|
169
171
|
verb: /^[a-z][a-z0-9_]{0,31}$/.test(verb) ? verb : verb ? "unknown" : "",
|
|
170
172
|
outcome: AUDIT_OUTCOMES.has(outcome) ? outcome : "dropped",
|
|
171
173
|
reason: /^[a-z0-9:_-]{0,40}$/.test(reason) ? reason : "",
|
|
174
|
+
run: HANDLE_PATTERN.test(run) ? run : "",
|
|
172
175
|
};
|
|
173
176
|
try {
|
|
174
177
|
ensureDir(env);
|
|
@@ -32,10 +32,9 @@
|
|
|
32
32
|
*
|
|
33
33
|
* Two kinds of entry are never prune candidates:
|
|
34
34
|
*
|
|
35
|
-
* rename aliases a SKILL.md carrying `renamed-to
|
|
36
|
-
* is left out of the catalog
|
|
37
|
-
*
|
|
38
|
-
* counts as a use of the skill it points at.
|
|
35
|
+
* rename aliases a SKILL.md carrying `renamed-to:`, left on a machine by an
|
|
36
|
+
* earlier release, is left out of the catalog. A call under
|
|
37
|
+
* the old name counts as a use of the skill it points at.
|
|
39
38
|
* commands everything under ~/.claude/commands is listed as not
|
|
40
39
|
* observable. A slash command the user types expands in
|
|
41
40
|
* the prompt without a Skill tool call, so the hook never
|
|
@@ -65,7 +64,6 @@ import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
|
65
64
|
import { invokedDirectly } from "../lib/invoked-directly.mjs";
|
|
66
65
|
import { marketplacePluginNames, pluginSkillRootCandidates } from "../lib/plugin-skill-roots.mjs";
|
|
67
66
|
import { readRegularFile } from "../lib/regular-file.mjs";
|
|
68
|
-
import { aliasTarget } from "./_renamed-skills.mjs";
|
|
69
67
|
import { LOG_FILE, MAX_LOG_BYTES, SKILL_NAME, logDir } from "./note-skill-use.mjs";
|
|
70
68
|
|
|
71
69
|
exitOnHelp(import.meta.url);
|
|
@@ -76,9 +74,22 @@ const DAY_MS = 86_400_000;
|
|
|
76
74
|
const READ_CAP = MAX_LOG_BYTES * 4;
|
|
77
75
|
const OUTCOMES = new Set(["ok", "error"]);
|
|
78
76
|
|
|
77
|
+
const ALIAS_TARGET = /^ {2}renamed-to: ([a-z0-9-]+)$/m;
|
|
78
|
+
|
|
79
79
|
const home = (env) => env.HOME || homedir();
|
|
80
80
|
const hidden = (name) => name.startsWith("_") || name.startsWith(".");
|
|
81
81
|
|
|
82
|
+
function aliasTarget(skillMdPath) {
|
|
83
|
+
try {
|
|
84
|
+
return (
|
|
85
|
+
ALIAS_TARGET.exec(readRegularFile(skillMdPath, { maxBytes: 65_536, noFollow: true }))?.[1] ??
|
|
86
|
+
null
|
|
87
|
+
);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
function entries(dir) {
|
|
83
94
|
try {
|
|
84
95
|
return readdirSync(dir, { withFileTypes: true });
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// _renamed-skills.mjs
|
|
2
|
-
//
|
|
3
|
-
// A shipped knowledge skill that changes its name keeps its old name working
|
|
4
|
-
// for one major cycle. pipeline/skills/renamed.json maps each old name to the
|
|
5
|
-
// new one; the old directory is gone from the authoring tree, and every place
|
|
6
|
-
// that delivers knowledge skills (build-stack-plugins.mjs for the marketplace,
|
|
7
|
-
// the Copilot and Codex installers for their local copies) writes a small alias
|
|
8
|
-
// skill under the old name that sends the reader to the new one.
|
|
9
|
-
//
|
|
10
|
-
// The alias never lives in pipeline/skills, so it is not in the skills index,
|
|
11
|
-
// the routing table or the pipeline's own description budget. Where it is
|
|
12
|
-
// delivered it is a real skill: each alias is declared in the plugin's
|
|
13
|
-
// plugin.json `skills[]` and written into the local skill copies, so hosts list
|
|
14
|
-
// it and its one-line description counts against the host's listing budget
|
|
15
|
-
// until the entry leaves renamed.json at removeIn.
|
|
16
|
-
|
|
17
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
18
|
-
import { join } from "node:path";
|
|
19
|
-
|
|
20
|
-
export const RENAMED_FILE = join("pipeline", "skills", "renamed.json");
|
|
21
|
-
|
|
22
|
-
const NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
23
|
-
const SEMVER_RE = /^\d+\.\d+\.\d+$/;
|
|
24
|
-
const ALIAS_MARKER = "renamed-to:";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Read the rename map of a pipeline checkout. A missing file is an empty map.
|
|
28
|
-
* `skills` holds the renames that still ship an alias; `retired` holds renames
|
|
29
|
-
* whose alias is gone, which upstream-overlap-gate.mjs keeps reading because
|
|
30
|
-
* an upstream checkout still names the skill by its old name.
|
|
31
|
-
* @param {string} pipelineRoot - repo root (the directory holding pipeline/)
|
|
32
|
-
* @returns {{removeIn: string, skills: Record<string, string>, retired: Record<string, string>}}
|
|
33
|
-
*/
|
|
34
|
-
export function loadRenamed(pipelineRoot) {
|
|
35
|
-
const path = join(pipelineRoot, RENAMED_FILE);
|
|
36
|
-
if (!existsSync(path)) return { removeIn: "", skills: {}, retired: {} };
|
|
37
|
-
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
38
|
-
const map = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : {});
|
|
39
|
-
return {
|
|
40
|
-
removeIn: typeof raw?.removeIn === "string" ? raw.removeIn : "",
|
|
41
|
-
skills: map(raw?.skills),
|
|
42
|
-
retired: map(raw?.retired),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* What is wrong with a rename map, given the skill names that exist now.
|
|
48
|
-
* @param {{removeIn: string, skills: Record<string, string>}} renamed
|
|
49
|
-
* @param {Set<string>} existing - every skill directory name in pipeline/skills
|
|
50
|
-
* @param {Set<string>} external - the knowledge skill names in shared/external
|
|
51
|
-
* @returns {string[]}
|
|
52
|
-
*/
|
|
53
|
-
export function renamedProblems(renamed, existing, external) {
|
|
54
|
-
const problems = [];
|
|
55
|
-
if (Object.keys(renamed.skills).length > 0 && !SEMVER_RE.test(renamed.removeIn)) {
|
|
56
|
-
problems.push(`removeIn "${renamed.removeIn}" is not a x.y.z version`);
|
|
57
|
-
}
|
|
58
|
-
const retired = renamed.retired ?? {};
|
|
59
|
-
for (const oldName of Object.keys(retired)) {
|
|
60
|
-
if (Object.hasOwn(renamed.skills, oldName)) {
|
|
61
|
-
problems.push(`${oldName}: listed in both skills and retired`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const entries = [...Object.entries(retired), ...Object.entries(renamed.skills)];
|
|
65
|
-
for (const [oldName, newName] of entries) {
|
|
66
|
-
if (!NAME_RE.test(oldName)) problems.push(`old name "${oldName}" is not kebab-case`);
|
|
67
|
-
if (typeof newName !== "string" || !NAME_RE.test(newName)) {
|
|
68
|
-
problems.push(`${oldName}: new name "${newName}" is not kebab-case`);
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (oldName === newName) problems.push(`${oldName}: renamed to itself`);
|
|
72
|
-
if (existing.has(oldName)) {
|
|
73
|
-
problems.push(`${oldName}: still a skill directory, so its alias would shadow it`);
|
|
74
|
-
}
|
|
75
|
-
if (!external.has(newName)) {
|
|
76
|
-
problems.push(
|
|
77
|
-
`${oldName}: target ${newName} is not a skill in pipeline/skills/shared/external`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
if (Object.hasOwn(renamed.skills, newName) || Object.hasOwn(retired, newName)) {
|
|
81
|
-
problems.push(`${oldName}: target ${newName} is itself renamed; point at the final name`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return problems;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The renamed pairs whose new name is among `delivered`, so an alias is written
|
|
89
|
-
* only next to the skill it points at.
|
|
90
|
-
* @param {{skills: Record<string, string>}} renamed
|
|
91
|
-
* @param {Iterable<string>} delivered
|
|
92
|
-
* @returns {Array<[string, string]>}
|
|
93
|
-
*/
|
|
94
|
-
export function aliasesFor(renamed, delivered) {
|
|
95
|
-
const have = new Set(delivered);
|
|
96
|
-
return Object.entries(renamed.skills)
|
|
97
|
-
.filter(([, newName]) => have.has(newName))
|
|
98
|
-
.sort(([a], [b]) => a.localeCompare(b));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Whether a SKILL.md frontmatter turns off user invocation.
|
|
103
|
-
* @param {string} skillMdPath
|
|
104
|
-
*/
|
|
105
|
-
export function isUserInvocableOff(skillMdPath) {
|
|
106
|
-
try {
|
|
107
|
-
const text = readFileSync(skillMdPath, "utf8");
|
|
108
|
-
const end = text.indexOf("\n---", 4);
|
|
109
|
-
const head = end > 0 ? text.slice(0, end) : "";
|
|
110
|
-
return /^user-invocable:\s*false\s*$/m.test(head);
|
|
111
|
-
} catch {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The alias SKILL.md written under an old name.
|
|
118
|
-
* @param {string} oldName
|
|
119
|
-
* @param {string} newName
|
|
120
|
-
* @param {{removeIn: string, userInvocable?: boolean}} opts
|
|
121
|
-
*/
|
|
122
|
-
export function aliasSkillMarkdown(oldName, newName, { removeIn, userInvocable = true }) {
|
|
123
|
-
return [
|
|
124
|
-
"---",
|
|
125
|
-
`name: ${oldName}`,
|
|
126
|
-
`description: "${oldName} is now ${newName}; load ${newName}."`,
|
|
127
|
-
...(userInvocable ? [] : ["user-invocable: false"]),
|
|
128
|
-
"metadata:",
|
|
129
|
-
` ${ALIAS_MARKER} ${newName}`,
|
|
130
|
-
" source: multi-agent-pipeline",
|
|
131
|
-
"---",
|
|
132
|
-
"",
|
|
133
|
-
`# ${oldName}`,
|
|
134
|
-
"",
|
|
135
|
-
`\`${oldName}\` is now \`${newName}\`. Load the \`${newName}\` skill from the same toolkit and follow it.`,
|
|
136
|
-
removeIn
|
|
137
|
-
? `This alias is removed in ${removeIn}.`
|
|
138
|
-
: "This alias is removed in the next major release.",
|
|
139
|
-
"",
|
|
140
|
-
].join("\n");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Whether a SKILL.md on disk is an alias this module wrote.
|
|
145
|
-
* @param {string} skillMdPath
|
|
146
|
-
*/
|
|
147
|
-
export function isAliasSkill(skillMdPath) {
|
|
148
|
-
return aliasTarget(skillMdPath) !== null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The skill an alias SKILL.md points at, or null when it is not an alias.
|
|
153
|
-
* @param {string} skillMdPath
|
|
154
|
-
*/
|
|
155
|
-
export function aliasTarget(skillMdPath) {
|
|
156
|
-
try {
|
|
157
|
-
const m = new RegExp(`^ ${ALIAS_MARKER} ([a-z0-9-]+)$`, "m").exec(
|
|
158
|
-
readFileSync(skillMdPath, "utf8"),
|
|
159
|
-
);
|
|
160
|
-
return m ? m[1] : null;
|
|
161
|
-
} catch {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"removeIn": "21.0.0",
|
|
4
|
-
"skills": {},
|
|
5
|
-
"retired": {
|
|
6
|
-
"app-store-changelog": "app-store-release-notes",
|
|
7
|
-
"firebase": "firebase-integration",
|
|
8
|
-
"ios-debugger-agent": "ios-simulator-debugging",
|
|
9
|
-
"macos-menubar-tuist-app": "macos-menubar-utility",
|
|
10
|
-
"macos-spm-app-packaging": "macos-app-distribution",
|
|
11
|
-
"nextjs-app-router": "nextjs-routing",
|
|
12
|
-
"spm-build-analysis": "package-build-audit",
|
|
13
|
-
"swift-concurrency-expert": "swift-concurrency-fix",
|
|
14
|
-
"swift-concurrency-pro": "swift-concurrency-review",
|
|
15
|
-
"swift-testing-pro": "swift-testing-review",
|
|
16
|
-
"swiftdata-pro": "swiftdata-review",
|
|
17
|
-
"swiftui-expert-skill": "swiftui-feature-builder",
|
|
18
|
-
"swiftui-liquid-glass": "swiftui-glass-effects",
|
|
19
|
-
"swiftui-performance-audit": "swiftui-performance-triage",
|
|
20
|
-
"swiftui-pro": "swiftui-review",
|
|
21
|
-
"swiftui-ui-patterns": "swiftui-flow-recipes",
|
|
22
|
-
"swiftui-view-refactor": "swiftui-view-splitting",
|
|
23
|
-
"tailwind-css": "tailwind-styling",
|
|
24
|
-
"xcode-build-benchmark": "build-time-benchmark",
|
|
25
|
-
"xcode-build-fixer": "build-time-fixes",
|
|
26
|
-
"xcode-build-orchestrator": "build-time-optimizer",
|
|
27
|
-
"xcode-compilation-analyzer": "swift-compile-hotspots",
|
|
28
|
-
"xcode-project-analyzer": "build-settings-audit"
|
|
29
|
-
}
|
|
30
|
-
}
|