@mmerterden/multi-agent-pipeline 24.1.1 → 24.3.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 (45) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +6 -5
  3. package/README.tr.md +6 -5
  4. package/docs/architecture.md +3 -3
  5. package/docs/ecosystem.md +5 -5
  6. package/docs/facts.json +4 -4
  7. package/install/_common.mjs +65 -0
  8. package/install/_plugin-skills.mjs +76 -18
  9. package/install/claude.mjs +7 -0
  10. package/install/codex.mjs +15 -1
  11. package/install/copilot.mjs +7 -0
  12. package/manifest.json +48 -43
  13. package/package.json +1 -1
  14. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  15. package/pipeline/commands/multi-agent/version/SKILL.md +67 -0
  16. package/pipeline/contract/CHANGELOG.md +10 -0
  17. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  18. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  19. package/pipeline/contract/manifest.json +4 -3
  20. package/pipeline/contract/types/index.d.ts +7 -5
  21. package/pipeline/lib/toolkit-install.mjs +147 -0
  22. package/pipeline/lib/usage-names.generated.mjs +2 -0
  23. package/pipeline/multi-agent-refs/cross-cli-contract.md +4 -4
  24. package/pipeline/multi-agent-refs/help/en.md +2 -1
  25. package/pipeline/multi-agent-refs/help/tr.md +2 -1
  26. package/pipeline/office/index.html +2 -2
  27. package/pipeline/schemas/disk-clean-request.schema.json +8 -2
  28. package/pipeline/schemas/disk-clean.schema.json +3 -2
  29. package/pipeline/schemas/hosts.json +7 -0
  30. package/pipeline/schemas/hosts.schema.json +17 -0
  31. package/pipeline/schemas/office-jobs.json +8 -0
  32. package/pipeline/schemas/version-report.schema.json +256 -0
  33. package/pipeline/scripts/_contract-core.mjs +1 -1
  34. package/pipeline/scripts/disk-cleaner.mjs +232 -5
  35. package/pipeline/scripts/feedback-send.mjs +7 -11
  36. package/pipeline/scripts/health-report.mjs +30 -53
  37. package/pipeline/scripts/version-report.mjs +868 -0
  38. package/pipeline/skills/.skill-manifest.json +8 -4
  39. package/pipeline/skills/.skills-index.json +12 -1
  40. package/pipeline/skills/shared/README.md +4 -3
  41. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  42. package/pipeline/skills/shared/core/multi-agent-version/SKILL.md +27 -0
  43. package/pipeline/skills/shared/external/disk-cleaner/SKILL.md +2 -1
  44. package/pipeline/skills/shared/external/disk-cleaner/scripts/disk-cleaner.mjs +232 -5
  45. package/pipeline/skills/skills-index.md +2 -1
@@ -0,0 +1,868 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * version-report.mjs - which version of the ecosystem this machine runs, in
4
+ * all three of its parts, and how fresh each one is.
5
+ *
6
+ * The three parts are published separately: the pipeline and the companion MCP
7
+ * server as npm packages, the plugins as a marketplace repository. So "am I up
8
+ * to date" has three answers, and the one a user is behind on is rarely the one
9
+ * they ask about. This report puts them side by side.
10
+ *
11
+ * Two dates are kept apart on purpose, because they answer different questions
12
+ * and mixing them makes both useless:
13
+ *
14
+ * releasedAt when upstream published the thing in use. Comparable across
15
+ * parts, so the headline is computed from these alone.
16
+ * installedAt when it landed on this machine.
17
+ *
18
+ * `current` is never printed from local state: it requires a successful upstream
19
+ * read in the same run. Offline, every npm part is `unknown` with a reason, which
20
+ * is the honest answer and the one a stale cache would hide.
21
+ *
22
+ * Reads, never writes: no cache file, no fetch into the repository, no npm
23
+ * invocation (a scope mapping in the user's .npmrc can reroute npm to another
24
+ * registry; an HTTPS read of the registry cannot be rerouted), and no upgrade.
25
+ * The registry read is best-effort and bounded; `git ls-remote` runs with the
26
+ * terminal prompt and ssh batch mode off so a missing credential fails fast
27
+ * instead of waiting for input.
28
+ *
29
+ * Usage:
30
+ * node version-report.mjs # report in the output language
31
+ * node version-report.mjs --json # the machine-side document
32
+ * node version-report.mjs --offline # skip every network read
33
+ * node version-report.mjs --timeout-ms N # per-read budget (default 3000)
34
+ * node version-report.mjs --repo PATH # which repo's enabled plugins to read
35
+ * node version-report.mjs --lang tr # override the output language
36
+ *
37
+ * Exit: 0 for a report, 2 for a usage error.
38
+ *
39
+ * @module pipeline/scripts/version-report
40
+ */
41
+
42
+ import { execFile } from "node:child_process";
43
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
44
+ import { homedir } from "node:os";
45
+ import { join, resolve } from "node:path";
46
+
47
+ import { parseArgs, ArgsError } from "../lib/args.mjs";
48
+ import { exitOnHelp } from "../lib/cli-help.mjs";
49
+ import { HOST_IDS, host as hostEntry, hostRoot, currentHostId } from "../lib/host.mjs";
50
+ import { invokedDirectly } from "../lib/invoked-directly.mjs";
51
+ import {
52
+ mcpRegistration,
53
+ npxCopies,
54
+ registrationSpec,
55
+ specIsPinned,
56
+ registrationDir,
57
+ toolkitVersionAt,
58
+ TOOLKIT_PACKAGE,
59
+ } from "../lib/toolkit-install.mjs";
60
+ import { hostCommand, messages, outputLanguage } from "../lib/user-facing.mjs";
61
+
62
+ exitOnHelp(import.meta.url);
63
+
64
+ export const CONTRACT_VERSION = "1.0.0";
65
+
66
+ const PIPELINE_PACKAGE = "@mmerterden/multi-agent-pipeline";
67
+ const REGISTRY = "https://registry.npmjs.org";
68
+ /** The ecosystem's own marketplace. Other marketplaces on the machine are not ours. */
69
+ const MARKETPLACE = "multi-agent-plugins";
70
+ const DEFAULT_TIMEOUT_MS = 3000;
71
+ const VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]{1,40})?$/;
72
+ /** Worst first: the verdict a reader has to act on wins the overall line. */
73
+ const SEVERITY = ["below-floor", "behind", "unknown", "ahead", "current", "absent"];
74
+
75
+ // ---------------------------------------------------------------------------
76
+ // reading
77
+
78
+ function readJson(path) {
79
+ try {
80
+ return JSON.parse(readFileSync(path, "utf8"));
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+
86
+ function mtimeIso(path) {
87
+ try {
88
+ return new Date(statSync(path).mtimeMs).toISOString();
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+
94
+ const iso = (ms) => (Number.isFinite(ms) ? new Date(ms).toISOString() : null);
95
+
96
+ const asString = (v) => (typeof v === "string" && v ? v : null);
97
+
98
+ /** A timestamp this document may carry: a string a Date can read, or null. */
99
+ const isoOrNull = (v) =>
100
+ typeof v === "string" && Number.isFinite(Date.parse(v)) ? new Date(v).toISOString() : null;
101
+
102
+ /** A commit this document may carry: exactly seven hex characters, or null. */
103
+ const shortCommit = (v) =>
104
+ typeof v === "string" && /^[0-9a-f]{7,40}$/.test(v) ? v.slice(0, 7) : null;
105
+
106
+ /** A path compared with another path: resolved, so a symlinked repo still matches. */
107
+ const realPath = (p) => {
108
+ if (typeof p !== "string" || !p) return null;
109
+ try {
110
+ return realpathSync(resolve(p));
111
+ } catch {
112
+ return resolve(p);
113
+ }
114
+ };
115
+
116
+ /**
117
+ * Order two versions, 0 when either is unreadable so an unparseable string can
118
+ * never decide a verdict. On an equal core a prerelease sorts below the release
119
+ * it leads to, which is what keeps a release candidate from being called
120
+ * current, and from slipping under a support floor unnoticed.
121
+ */
122
+ export function compareVersions(a, b) {
123
+ if (!VERSION.test(a ?? "") || !VERSION.test(b ?? "")) return 0;
124
+ const core = (v) => v.split(/[-+]/)[0].split(".").map(Number);
125
+ const pre = (v) => /^[^-+]+-/.test(v);
126
+ const [x, y] = [core(a), core(b)];
127
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
128
+ if (pre(a) === pre(b)) return 0;
129
+ return pre(a) ? -1 : 1;
130
+ }
131
+
132
+ /**
133
+ * What a registry document says, or why it says nothing usable.
134
+ *
135
+ * A 200 is not an answer: a proxy, a mirror or a stub can serve a document whose
136
+ * `latest` is not a version, and comparing against an unreadable version yields
137
+ * "equal", which prints as `current`. Such a document is malformed, not a match.
138
+ *
139
+ * @param {unknown} json
140
+ */
141
+ export function readPackument(json) {
142
+ const tags = json?.["dist-tags"] ?? {};
143
+ if (!VERSION.test(tags.latest ?? "")) return { reason: "malformed" };
144
+ return {
145
+ latest: tags.latest,
146
+ required: VERSION.test(tags.required ?? "") ? tags.required : null,
147
+ time: json?.time && typeof json.time === "object" ? json.time : {},
148
+ };
149
+ }
150
+
151
+ /**
152
+ * A package's dist-tags and publish times, or a reason it could not be read.
153
+ *
154
+ * The full document is read rather than npm's abbreviated metadata, because
155
+ * only the full one carries `time` - and a release date is half of what this
156
+ * report is for. It compresses to about a tenth of its size over the wire.
157
+ */
158
+ async function packument(pkg, timeoutMs) {
159
+ const url = `${REGISTRY}/${pkg.replace("/", "%2F")}`;
160
+ const ctl = new AbortController();
161
+ const timer = setTimeout(() => ctl.abort(), timeoutMs);
162
+ try {
163
+ const res = await fetch(url, { signal: ctl.signal, headers: { accept: "application/json" } });
164
+ if (!res.ok) return { reason: "http-error" };
165
+ return readPackument(await res.json());
166
+ } catch (e) {
167
+ return { reason: e?.name === "AbortError" ? "timeout" : "dns" };
168
+ } finally {
169
+ clearTimeout(timer);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Run git in the clone and hand back stdout, null on any failure.
175
+ *
176
+ * Nothing may ask the user for anything: a prompt in a report that was meant to
177
+ * print a table and exit is a hang. The terminal prompt, ssh's own prompt and
178
+ * any configured credential helper are all switched off, and the call is
179
+ * bounded by the same budget as the registry reads.
180
+ */
181
+ function git(dir, args, timeoutMs) {
182
+ return new Promise((done) => {
183
+ execFile(
184
+ "git",
185
+ ["-c", "credential.helper=", "-C", dir, ...args],
186
+ {
187
+ timeout: timeoutMs,
188
+ env: {
189
+ ...process.env,
190
+ GIT_TERMINAL_PROMPT: "0",
191
+ GIT_SSH_COMMAND: "ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new",
192
+ },
193
+ },
194
+ (err, stdout) => done(err ? null : String(stdout)),
195
+ );
196
+ });
197
+ }
198
+
199
+ /** The commit `origin` serves as HEAD, null when the remote could not be read. */
200
+ async function remoteHead(dir, timeoutMs) {
201
+ const out = await git(dir, ["ls-remote", "origin", "HEAD"], timeoutMs);
202
+ return out ? (/^([0-9a-f]{7,40})\s/.exec(out)?.[1] ?? null) : null;
203
+ }
204
+
205
+ async function gitHead(dir, timeoutMs) {
206
+ const out = await git(dir, ["log", "-1", "--format=%H%x09%cI"], timeoutMs);
207
+ const [commit, when] = String(out ?? "")
208
+ .trim()
209
+ .split("\t");
210
+ return { commit: commit || null, releasedAt: when || null };
211
+ }
212
+
213
+ /**
214
+ * Is the remote commit already in this clone's history? Holding the object is
215
+ * not enough: a fetch that was never merged leaves the commit on disk while the
216
+ * working clone is still behind it, and answering from the object store would
217
+ * report that clone as ahead.
218
+ */
219
+ async function isAncestor(dir, commit, timeoutMs) {
220
+ if (!commit) return null;
221
+ return (await git(dir, ["merge-base", "--is-ancestor", commit, "HEAD"], timeoutMs)) !== null;
222
+ }
223
+
224
+ // ---------------------------------------------------------------------------
225
+ // parts
226
+
227
+ /** Every host tree, whether the pipeline is installed in it, and at what version. */
228
+ export function pipelineHosts(home) {
229
+ return HOST_IDS.map((id) => {
230
+ const root = hostRoot(home, id);
231
+ const marker = join(root, ".pipeline-version");
232
+ // The stamp is the install, not the directory: `~/.codex` exists on any
233
+ // machine with Codex CLI, pipeline installed or not, so a host without one
234
+ // is absent rather than broken. A stamp that exists and does not read is a
235
+ // different thing and is reported as one.
236
+ const stamped = existsSync(marker);
237
+ const raw = stamped ? readFileSync(marker, "utf8").trim() : null;
238
+ const version = raw && VERSION.test(raw) ? raw : null;
239
+ return {
240
+ id,
241
+ name: hostEntry(id)?.label ?? id,
242
+ state: version ? "installed" : stamped ? "no-marker" : "absent",
243
+ version,
244
+ installedAt: version ? mtimeIso(marker) : null,
245
+ builtAgainstToolkit: asString(readJson(join(root, "office", "toolkit.json"))?.toolkitVersion),
246
+ };
247
+ });
248
+ }
249
+
250
+ /**
251
+ * The verdict for a part whose upstream is npm: how local compares with the
252
+ * registry, and why when it does not compare at all.
253
+ */
254
+ export function npmVerdict(local, reg) {
255
+ if (!local) return { verdict: "absent", reason: "not-installed" };
256
+ if (!reg || reg.reason) return { verdict: "unknown", reason: reg?.reason ?? "offline-flag" };
257
+ const c = compareVersions(local, reg.latest);
258
+ if (c > 0) return { verdict: "ahead", reason: null };
259
+ if (c < 0) {
260
+ const below = reg.required && compareVersions(local, reg.required) < 0;
261
+ return { verdict: below ? "below-floor" : "behind", reason: null };
262
+ }
263
+ return { verdict: "current", reason: null };
264
+ }
265
+
266
+ function pipelinePart({ hosts, reg, findings }) {
267
+ const invoking = currentHostId();
268
+ const installed = hosts.filter((h) => h.version);
269
+ const mine = hosts.find((h) => h.id === invoking && h.version) ?? installed[0] ?? null;
270
+ const version = mine?.version ?? null;
271
+
272
+ for (const h of hosts) {
273
+ if (h.state === "no-marker") findings.push({ code: "host-marker-unreadable", subject: h.name });
274
+ else if (h.version && version && h.version !== version)
275
+ findings.push({ code: "host-version-mismatch", subject: h.name });
276
+ }
277
+ const { verdict, reason } = npmVerdict(version, reg);
278
+ const releasedAt = reg?.time?.[version] ?? null;
279
+ // Only a document that carried dates can say a version was never published.
280
+ if (version && reg?.time && Object.keys(reg.time).length && !releasedAt)
281
+ findings.push({ code: "version-not-in-registry", subject: version });
282
+ return {
283
+ hostId: mine?.id ?? null,
284
+ version,
285
+ releasedAt,
286
+ installedAt: mine?.installedAt ?? null,
287
+ latest: reg?.latest ?? null,
288
+ latestReleasedAt: reg?.latest ? (reg.time?.[reg.latest] ?? null) : null,
289
+ required: reg?.required ?? null,
290
+ verdict,
291
+ reason,
292
+ hosts,
293
+ };
294
+ }
295
+
296
+ /**
297
+ * A spec is printed only when its tail is a version or a plain dist-tag. npm
298
+ * also accepts `<package>@<git or tarball url>`, and such a URL routinely
299
+ * carries a token in its userinfo, so anything that is not a plain tail is
300
+ * reported as absent rather than echoed into a report.
301
+ */
302
+ export function safeSpec(spec) {
303
+ if (!spec) return null;
304
+ const tail = spec.slice(TOOLKIT_PACKAGE.length + 1);
305
+ return spec === TOOLKIT_PACKAGE || /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(tail) ? spec : null;
306
+ }
307
+
308
+ function toolkitPart({ home, reg, builtAgainst, findings }) {
309
+ const registration = mcpRegistration(home);
310
+ const spec = registrationSpec(registration);
311
+ const direct = registrationDir(registration, home);
312
+ const copies = npxCopies(home);
313
+ // A registration naming a script decides the copy; otherwise the copies npm
314
+ // cached for that very spec do, newest first. A cache entry asked for a
315
+ // different spec is another server's copy and never answers for this one, and
316
+ // an entry of unknown provenance answers only when nothing matched the spec -
317
+ // otherwise a newer stray copy outranks the one the host would actually run.
318
+ const sameSpec = spec ? copies.filter((c) => c.spec === spec) : [];
319
+ const matching = sameSpec.length ? sameSpec : copies.filter((c) => !c.spec);
320
+ const chosen = direct
321
+ ? { version: toolkitVersionAt(direct), installedAt: mtimeIso(join(direct, "package.json")) }
322
+ : matching[0]
323
+ ? { version: matching[0].version, installedAt: iso(matching[0].installedAt) }
324
+ : null;
325
+
326
+ if (matching.length > 1) findings.push({ code: "toolkit-multiple-copies", subject: null });
327
+ if (spec && specIsPinned(spec))
328
+ findings.push({ code: "toolkit-spec-pinned", subject: safeSpec(spec) });
329
+ if (chosen?.version && builtAgainst && compareVersions(chosen.version, builtAgainst) < 0)
330
+ findings.push({ code: "toolkit-older-than-built-against", subject: builtAgainst });
331
+
332
+ // Absent has three different causes and a user acts on each differently: no
333
+ // registration at all, a registration whose copy npm has not fetched yet (the
334
+ // host fetches it on first use), and a copy on disk that cannot be read.
335
+ const absentReason = !registration
336
+ ? "not-registered"
337
+ : direct || matching.length
338
+ ? "unreadable"
339
+ : "not-installed";
340
+ const { verdict, reason } = chosen?.version
341
+ ? npmVerdict(chosen.version, reg)
342
+ : { verdict: "absent", reason: absentReason };
343
+ return {
344
+ registered: Boolean(registration),
345
+ spec: safeSpec(spec),
346
+ resolvedVersion: chosen?.version ?? null,
347
+ releasedAt: chosen?.version ? (reg?.time?.[chosen.version] ?? null) : null,
348
+ installedAt: chosen?.installedAt ?? null,
349
+ builtAgainst,
350
+ latest: reg?.latest ?? null,
351
+ latestReleasedAt: reg?.latest ? (reg.time?.[reg.latest] ?? null) : null,
352
+ required: reg?.required ?? null,
353
+ otherCopies: matching
354
+ .slice(1)
355
+ .map((c) => ({ version: c.version, installedAt: iso(c.installedAt) })),
356
+ verdict,
357
+ reason,
358
+ };
359
+ }
360
+
361
+ /**
362
+ * Which of this marketplace's plugins are on where the report runs: the user's
363
+ * own settings first, then the repository's, so a repository that turns one off
364
+ * is read as the answer for that repository.
365
+ */
366
+ export function enabledPlugins(home, repo) {
367
+ const state = new Map();
368
+ const files = [
369
+ join(home, ".claude", "settings.json"),
370
+ join(home, ".claude", "settings.local.json"),
371
+ join(repo, ".claude", "settings.json"),
372
+ join(repo, ".claude", "settings.local.json"),
373
+ ];
374
+ for (const file of files) {
375
+ // Keys are `<plugin>@<marketplace>`; only this marketplace's are ours.
376
+ for (const [key, on] of Object.entries(readJson(file)?.enabledPlugins ?? {})) {
377
+ const at = key.lastIndexOf("@");
378
+ if (at < 1 || key.slice(at + 1) !== MARKETPLACE) continue;
379
+ state.set(key.slice(0, at), Boolean(on));
380
+ }
381
+ }
382
+ return new Set([...state].filter(([, on]) => on).map(([name]) => name));
383
+ }
384
+
385
+ /**
386
+ * The install row that answers for this repository: a project-scope row bound to
387
+ * it, otherwise a row that is not bound to any project. A row belonging to a
388
+ * different project is not a fallback - taking it reports a plugin as installed
389
+ * here at a version this repository never loads. Paths are compared resolved,
390
+ * because a project reached through a symlink is the same project.
391
+ *
392
+ * The rows also carry install paths, which are absolute home paths, and those
393
+ * are never read.
394
+ */
395
+ export function installRow(rows, repo) {
396
+ const list = Array.isArray(rows) ? rows.filter((r) => r && typeof r === "object") : [];
397
+ const here = realPath(repo);
398
+ const pick =
399
+ list.find((r) => r.scope === "project" && realPath(r.projectPath) === here) ??
400
+ list.find((r) => !r.projectPath);
401
+ return pick
402
+ ? {
403
+ version: typeof pick.version === "string" ? pick.version : null,
404
+ installedAt: isoOrNull(pick.lastUpdated),
405
+ commit: shortCommit(pick.gitCommitSha),
406
+ }
407
+ : null;
408
+ }
409
+
410
+ async function pluginsPart({ home, repo, offline, timeoutMs, findings }) {
411
+ const dir = join(home, ".claude", "plugins", "marketplaces", MARKETPLACE);
412
+ const catalog = readJson(join(dir, ".claude-plugin", "marketplace.json"));
413
+ const present = Boolean(catalog);
414
+ const head = present ? await gitHead(dir, timeoutMs) : { commit: null, releasedAt: null };
415
+ const installedAll = readJson(
416
+ join(home, ".claude", "plugins", "installed_plugins.json"),
417
+ )?.plugins;
418
+ const known = readJson(join(home, ".claude", "plugins", "known_marketplaces.json"));
419
+ const enabled = enabledPlugins(home, repo);
420
+
421
+ const items = [];
422
+ for (const entry of Array.isArray(catalog?.plugins) ? catalog.plugins : []) {
423
+ const name = typeof entry?.name === "string" ? entry.name : null;
424
+ if (!name) continue;
425
+ const source = typeof entry.source === "string" ? entry.source.replace(/^\.\//, "") : name;
426
+ const row = installRow(installedAll?.[`${name}@${MARKETPLACE}`], repo);
427
+ items.push({
428
+ name,
429
+ catalogVersion:
430
+ asString(readJson(join(dir, source, ".claude-plugin", "plugin.json"))?.version) ??
431
+ asString(entry.version),
432
+ installedVersion: row?.version ?? null,
433
+ installedCommit: row?.commit ?? null,
434
+ installedAt: row?.installedAt ?? null,
435
+ enabledHere: enabled.has(name),
436
+ state: row ? "installed" : "not-installed",
437
+ });
438
+ }
439
+ for (const name of enabled) {
440
+ const item = items.find((i) => i.name === name);
441
+ if (!item) {
442
+ items.push({
443
+ name,
444
+ catalogVersion: null,
445
+ installedVersion: null,
446
+ installedCommit: null,
447
+ installedAt: null,
448
+ enabledHere: true,
449
+ state: "not-in-catalog",
450
+ });
451
+ findings.push({ code: "plugin-enabled-not-in-catalog", subject: name });
452
+ } else if (item.state === "not-installed") {
453
+ findings.push({ code: "plugin-enabled-not-installed", subject: name });
454
+ } else if (
455
+ item.installedVersion &&
456
+ item.catalogVersion &&
457
+ item.installedVersion !== item.catalogVersion
458
+ ) {
459
+ findings.push({ code: "plugin-install-differs-from-catalog", subject: name });
460
+ }
461
+ }
462
+
463
+ let remote = null;
464
+ if (present && !offline) remote = await remoteHead(dir, timeoutMs);
465
+ let verdict = present ? "unknown" : "absent";
466
+ let reason = present
467
+ ? offline
468
+ ? "offline-flag"
469
+ : remote
470
+ ? null
471
+ : "remote-unreachable"
472
+ : "not-installed";
473
+ if (present && remote) {
474
+ if (remote === head.commit) [verdict, reason] = ["current", null];
475
+ else
476
+ [verdict, reason] = (await isAncestor(dir, remote, timeoutMs))
477
+ ? ["ahead", null]
478
+ : ["behind", null];
479
+ }
480
+ return {
481
+ marketplace: {
482
+ present,
483
+ commit: shortCommit(head.commit),
484
+ releasedAt: isoOrNull(head.releasedAt),
485
+ installedAt: isoOrNull(known?.[MARKETPLACE]?.lastUpdated),
486
+ remoteCommit: shortCommit(remote),
487
+ },
488
+ verdict,
489
+ reason,
490
+ items,
491
+ };
492
+ }
493
+
494
+ // ---------------------------------------------------------------------------
495
+ // the document
496
+
497
+ /**
498
+ * The verdict a reader has to act on. An absent part is skipped rather than
499
+ * ranked - not installing the plugins is a choice, not a problem - but an
500
+ * absent pipeline is the whole answer, because there is nothing else to be
501
+ * current about.
502
+ */
503
+ export function worst(verdicts, { pipeline } = {}) {
504
+ if (pipeline === "absent") return "absent";
505
+ const live = verdicts.filter((v) => v !== "absent");
506
+ if (!live.length) return "absent";
507
+ return SEVERITY.find((s) => live.includes(s)) ?? "current";
508
+ }
509
+
510
+ /** The newest upstream release among the parts in use, over known dates only. */
511
+ export function newestRelease(parts) {
512
+ const dated = parts.filter((p) => p.releasedAt && p.version);
513
+ const missing = parts.filter((p) => !p.releasedAt || !p.version).map((p) => p.part);
514
+ const top = dated.sort((a, b) => (a.releasedAt < b.releasedAt ? 1 : -1))[0] ?? null;
515
+ return {
516
+ part: top?.part ?? null,
517
+ version: top?.version ?? null,
518
+ releasedAt: top?.releasedAt ?? null,
519
+ complete: missing.length === 0,
520
+ missing,
521
+ };
522
+ }
523
+
524
+ /**
525
+ * @param {{home?: string, repo?: string, offline?: boolean, timeoutMs?: number}} [opts]
526
+ */
527
+ export async function versionReport({
528
+ home = homedir(),
529
+ repo = process.cwd(),
530
+ offline = false,
531
+ timeoutMs = DEFAULT_TIMEOUT_MS,
532
+ } = {}) {
533
+ const findings = [];
534
+ const hosts = pipelineHosts(home);
535
+
536
+ const [pipeReg, toolReg] = offline
537
+ ? [{ reason: "offline-flag" }, { reason: "offline-flag" }]
538
+ : await Promise.all([
539
+ packument(PIPELINE_PACKAGE, timeoutMs),
540
+ packument(TOOLKIT_PACKAGE, timeoutMs),
541
+ ]);
542
+
543
+ const pipeline = pipelinePart({ hosts, reg: pipeReg, findings });
544
+ // The toolkit version to compare against is the one the reported install was
545
+ // built with, not whichever host happens to carry a stamp.
546
+ const builtAgainst =
547
+ asString(hosts.find((h) => h.id === pipeline.hostId)?.builtAgainstToolkit) ??
548
+ asString(hosts.find((h) => h.builtAgainstToolkit)?.builtAgainstToolkit);
549
+ const toolkit = toolkitPart({ home, reg: toolReg, builtAgainst, findings });
550
+ const plugins = await pluginsPart({ home, repo, offline, timeoutMs, findings });
551
+
552
+ const reached = [pipeReg, toolReg].some((r) => r && !r.reason);
553
+ return {
554
+ contractVersion: CONTRACT_VERSION,
555
+ generatedAt: new Date().toISOString(),
556
+ network: {
557
+ attempted: !offline,
558
+ reached,
559
+ reason: offline ? "offline-flag" : reached ? null : (pipeReg?.reason ?? "dns"),
560
+ },
561
+ overall: worst([pipeline.verdict, toolkit.verdict, plugins.verdict], {
562
+ pipeline: pipeline.verdict,
563
+ }),
564
+ newestRelease: newestRelease([
565
+ { part: "pipeline", version: pipeline.version, releasedAt: pipeline.releasedAt },
566
+ { part: "toolkit", version: toolkit.resolvedVersion, releasedAt: toolkit.releasedAt },
567
+ {
568
+ part: "plugins",
569
+ version: plugins.marketplace.commit,
570
+ // The clone's own commit date is readable offline, unlike the two npm
571
+ // dates. Letting it answer alone would turn a local git fact into a
572
+ // claim about what upstream published, so it counts only once the
573
+ // remote confirmed what the clone holds.
574
+ releasedAt: plugins.verdict === "unknown" ? null : plugins.marketplace.releasedAt,
575
+ },
576
+ ]),
577
+ pipeline,
578
+ toolkit,
579
+ plugins,
580
+ findings: findings.map((f) => ({ code: f.code, subject: f.subject ?? null })),
581
+ };
582
+ }
583
+
584
+ // ---------------------------------------------------------------------------
585
+ // rendering
586
+
587
+ const TEXT = {
588
+ en: {
589
+ head: (v, verdict, when) => `multi-agent ${v ?? "not installed"}: ${verdict} (checked ${when})`,
590
+ verdicts: {
591
+ current: "every part current",
592
+ behind: "a newer release exists",
593
+ "below-floor": "below the supported floor - update before the next run",
594
+ ahead: "running ahead of the registry",
595
+ unknown: "nothing compared",
596
+ unknownPartial: "not every part could be compared",
597
+ absent: "nothing installed",
598
+ },
599
+ newest: (p, v, d) => `Newest release in use: ${p} ${v}, released ${d}`,
600
+ newestUnknown: "Newest release in use: not known without the registry",
601
+ newestPartial: (names) => ` (no date for ${names})`,
602
+ columns: ["Repo", "In use", "Latest", "Released", "Installed here", "State"],
603
+ states: {
604
+ current: "current",
605
+ behind: "behind",
606
+ "below-floor": "below floor",
607
+ ahead: "ahead",
608
+ unknown: "unknown",
609
+ absent: "absent",
610
+ },
611
+ parts: {
612
+ pipeline: "multi-agent-pipeline",
613
+ toolkit: "multi-agent-mcp",
614
+ plugins: "multi-agent-plugins",
615
+ },
616
+ hostsAll: (v, names) => `Hosts: ${names}: all ${v}`,
617
+ hostsEach: (rows) => `Hosts: ${rows}`,
618
+ repo: (n, total, list) => `Plugins in this repo: ${n} of ${total} enabled${list}`,
619
+ repoNone: (total) => `Plugins in this repo: none of ${total} enabled`,
620
+ notes: "Notes:",
621
+ more: (n) => `and ${n} more`,
622
+ update: (cmd) => `Update: ${cmd}`,
623
+ findings: {
624
+ "host-version-mismatch": (s) => `${s} is on a different pipeline version`,
625
+ "host-marker-unreadable": (s) => `${s}: version marker present but unreadable`,
626
+ "toolkit-older-than-built-against": (s) =>
627
+ `the toolkit is older than the ${s} this pipeline was built against`,
628
+ "toolkit-multiple-copies": () => "npm cached more than one toolkit copy",
629
+ "toolkit-spec-pinned": (s) => `the server is registered pinned (${s}), so it will not move`,
630
+ "plugin-enabled-not-installed": (s) => `${s} is enabled here but not installed`,
631
+ "plugin-enabled-not-in-catalog": (s) => `${s} is enabled here but not in the marketplace`,
632
+ "plugin-install-differs-from-catalog": (s) => `${s} is installed at another version`,
633
+ "version-not-in-registry": (s) => `${s} is not a published release`,
634
+ },
635
+ reasons: {
636
+ "offline-flag": "offline",
637
+ timeout: "registry timed out",
638
+ dns: "registry not reached",
639
+ "http-error": "registry refused the read",
640
+ malformed: "registry answer unreadable",
641
+ "not-installed": "not installed",
642
+ "not-registered": "not registered",
643
+ unreadable: "copy unreadable",
644
+ "remote-unreachable": "remote not reached",
645
+ },
646
+ },
647
+ tr: {
648
+ head: (v, verdict, when) => `multi-agent ${v ?? "kurulu değil"}: ${verdict} (${when})`,
649
+ verdicts: {
650
+ current: "her parça güncel",
651
+ behind: "daha yeni bir sürüm var",
652
+ "below-floor": "desteklenen tabanın altında, koşudan önce güncelle",
653
+ ahead: "registry'nin önünde",
654
+ unknown: "karşılaştırma yapılmadı",
655
+ unknownPartial: "her parça karşılaştırılamadı",
656
+ absent: "hiçbir parça kurulu değil",
657
+ },
658
+ newest: (p, v, d) => `Kullanımdaki en yeni sürüm: ${p} ${v}, ${d} tarihinde yayınlandı`,
659
+ newestUnknown: "Kullanımdaki en yeni sürüm: registry olmadan bilinmiyor",
660
+ newestPartial: (names) => ` (${names} için tarih yok)`,
661
+ columns: ["Depo", "Kullanımda", "Son", "Yayın", "Kurulum", "Durum"],
662
+ states: {
663
+ current: "güncel",
664
+ behind: "geride",
665
+ "below-floor": "taban altı",
666
+ ahead: "önde",
667
+ unknown: "bilinmiyor",
668
+ absent: "yok",
669
+ },
670
+ parts: {
671
+ pipeline: "multi-agent-pipeline",
672
+ toolkit: "multi-agent-mcp",
673
+ plugins: "multi-agent-plugins",
674
+ },
675
+ hostsAll: (v, names) => `Host'lar: ${names}: hepsi ${v}`,
676
+ hostsEach: (rows) => `Host'lar: ${rows}`,
677
+ repo: (n, total, list) => `Bu repoda açık plugin: ${total} içinden ${n}${list}`,
678
+ repoNone: (total) => `Bu repoda açık plugin yok (${total} tanesinden hiçbiri)`,
679
+ notes: "Notlar:",
680
+ more: (n) => `ve ${n} tane daha`,
681
+ update: (cmd) => `Güncelleme: ${cmd}`,
682
+ findings: {
683
+ "host-version-mismatch": (s) => `${s} farklı bir pipeline sürümünde`,
684
+ "host-marker-unreadable": (s) => `${s}: sürüm işareti var ama okunamıyor`,
685
+ "toolkit-older-than-built-against": (s) =>
686
+ `toolkit, bu pipeline'ın derlendiği ${s} sürümünden eski`,
687
+ "toolkit-multiple-copies": () => "npm birden fazla toolkit kopyası önbelleklemiş",
688
+ "toolkit-spec-pinned": (s) => `sunucu sabit sürümle kayıtlı (${s}), kendiliğinden ilerlemez`,
689
+ "plugin-enabled-not-installed": (s) => `${s} burada açık ama kurulu değil`,
690
+ "plugin-enabled-not-in-catalog": (s) => `${s} burada açık ama marketplace'te yok`,
691
+ "plugin-install-differs-from-catalog": (s) => `${s} başka bir sürümde kurulu`,
692
+ "version-not-in-registry": (s) => `${s} yayınlanmış bir sürüm değil`,
693
+ },
694
+ reasons: {
695
+ "offline-flag": "çevrimdışı",
696
+ timeout: "registry zaman aşımına uğradı",
697
+ dns: "registry'ye ulaşılamadı",
698
+ "http-error": "registry okumayı reddetti",
699
+ malformed: "registry yanıtı okunamadı",
700
+ "not-installed": "kurulu değil",
701
+ "not-registered": "kayıtlı değil",
702
+ unreadable: "kopya okunamadı",
703
+ "remote-unreachable": "uzak depoya ulaşılamadı",
704
+ },
705
+ },
706
+ };
707
+
708
+ const dateOf = (s, lang) =>
709
+ s ? new Date(s).toLocaleDateString(lang === "tr" ? "tr-TR" : "en-GB") : "-";
710
+ const stampOf = (s, lang) =>
711
+ s
712
+ ? new Date(s).toLocaleString(lang === "tr" ? "tr-TR" : "en-GB", {
713
+ dateStyle: "short",
714
+ timeStyle: "short",
715
+ })
716
+ : "-";
717
+
718
+ function table(rows) {
719
+ const w = rows[0].map((_, i) => Math.max(...rows.map((r) => String(r[i]).length)));
720
+ return rows
721
+ .map((r) => r.map((c, i) => String(c).padEnd(i === r.length - 1 ? 0 : w[i])).join(" "))
722
+ .join("\n")
723
+ .replace(/[ \t]+$/gm, "");
724
+ }
725
+
726
+ /**
727
+ * @param {Awaited<ReturnType<typeof versionReport>>} doc
728
+ * @param {{lang?: string, hostCommand?: string}} [opts]
729
+ */
730
+ export function renderText(doc, { lang = "en", hostCommand = "/multi-agent:update" } = {}) {
731
+ const t = messages(TEXT, lang);
732
+ const state = (verdict, reason) => {
733
+ const word = t.states[verdict] ?? verdict;
734
+ return reason ? `${word} (${t.reasons[reason] ?? reason})` : word;
735
+ };
736
+ const compared = [doc.pipeline, doc.toolkit, doc.plugins].some(
737
+ (p) => p.verdict !== "unknown" && p.verdict !== "absent",
738
+ );
739
+ const headline =
740
+ doc.overall === "unknown" && compared
741
+ ? t.verdicts.unknownPartial
742
+ : (t.verdicts[doc.overall] ?? doc.overall);
743
+ const out = [t.head(doc.pipeline.version, headline, stampOf(doc.generatedAt, lang))];
744
+
745
+ const n = doc.newestRelease;
746
+ if (n.releasedAt) {
747
+ out.push(
748
+ t.newest(t.parts[n.part] ?? n.part, n.version, dateOf(n.releasedAt, lang)) +
749
+ (n.complete ? "" : t.newestPartial(n.missing.map((m) => t.parts[m] ?? m).join(", "))),
750
+ );
751
+ } else {
752
+ out.push(t.newestUnknown);
753
+ }
754
+
755
+ out.push(
756
+ "",
757
+ table([
758
+ t.columns,
759
+ [
760
+ t.parts.pipeline,
761
+ doc.pipeline.version ?? "-",
762
+ doc.pipeline.latest ?? "-",
763
+ dateOf(doc.pipeline.releasedAt, lang),
764
+ stampOf(doc.pipeline.installedAt, lang),
765
+ state(doc.pipeline.verdict, doc.pipeline.reason),
766
+ ],
767
+ [
768
+ t.parts.toolkit,
769
+ doc.toolkit.resolvedVersion ?? "-",
770
+ doc.toolkit.latest ?? "-",
771
+ dateOf(doc.toolkit.releasedAt, lang),
772
+ stampOf(doc.toolkit.installedAt, lang),
773
+ state(doc.toolkit.verdict, doc.toolkit.reason),
774
+ ],
775
+ [
776
+ t.parts.plugins,
777
+ doc.plugins.marketplace.commit ?? "-",
778
+ doc.plugins.marketplace.remoteCommit ?? "-",
779
+ dateOf(doc.plugins.marketplace.releasedAt, lang),
780
+ stampOf(doc.plugins.marketplace.installedAt, lang),
781
+ state(doc.plugins.verdict, doc.plugins.reason),
782
+ ],
783
+ ]),
784
+ "",
785
+ );
786
+
787
+ const installed = doc.pipeline.hosts.filter((h) => h.version);
788
+ if (installed.length) {
789
+ const same = installed.every((h) => h.version === installed[0].version);
790
+ out.push(
791
+ same
792
+ ? t.hostsAll(installed[0].version, installed.map((h) => h.name).join(", "))
793
+ : t.hostsEach(installed.map((h) => `${h.name} ${h.version}`).join(", ")),
794
+ );
795
+ }
796
+
797
+ const on = doc.plugins.items.filter((i) => i.enabledHere);
798
+ // A plugin enabled here that the marketplace does not carry is in the list but
799
+ // is not one of the plugins the marketplace offers, so it cannot inflate the
800
+ // denominator.
801
+ const total = doc.plugins.items.filter((i) => i.state !== "not-in-catalog").length;
802
+ out.push(
803
+ on.length
804
+ ? t.repo(
805
+ on.length,
806
+ total,
807
+ `: ${on.map((i) => `${i.name} ${i.installedVersion ?? i.catalogVersion ?? "?"}`).join(", ")}`,
808
+ )
809
+ : t.repoNone(total),
810
+ );
811
+
812
+ if (doc.findings.length) {
813
+ out.push("", t.notes);
814
+ for (const f of doc.findings.slice(0, 5)) {
815
+ const line = t.findings[f.code];
816
+ out.push(`- ${line ? line(f.subject) : f.code}`);
817
+ }
818
+ if (doc.findings.length > 5) out.push(`- ${t.more(doc.findings.length - 5)}`);
819
+ }
820
+
821
+ if (["behind", "below-floor"].includes(doc.overall)) out.push("", t.update(hostCommand));
822
+ return out.join("\n");
823
+ }
824
+
825
+ // ---------------------------------------------------------------------------
826
+ // CLI
827
+
828
+ export function parseArgv(argv) {
829
+ return parseArgs(argv, {
830
+ booleans: ["json", "offline"],
831
+ values: ["timeout-ms", "repo", "lang"],
832
+ unknown: "error",
833
+ positionals: false,
834
+ });
835
+ }
836
+
837
+ async function main(argv) {
838
+ let flags;
839
+ try {
840
+ ({ flags } = parseArgv(argv));
841
+ } catch (e) {
842
+ if (e instanceof ArgsError) {
843
+ process.stderr.write(`${e.message}\n`);
844
+ process.exitCode = 2;
845
+ return;
846
+ }
847
+ throw e;
848
+ }
849
+ const timeoutMs = Number(flags["timeout-ms"] ?? DEFAULT_TIMEOUT_MS);
850
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
851
+ process.stderr.write("--timeout-ms takes a positive number of milliseconds\n");
852
+ process.exitCode = 2;
853
+ return;
854
+ }
855
+ const doc = await versionReport({
856
+ offline: Boolean(flags.offline),
857
+ timeoutMs,
858
+ repo: resolve(typeof flags.repo === "string" ? flags.repo : process.cwd()),
859
+ });
860
+ if (flags.json) {
861
+ process.stdout.write(`${JSON.stringify(doc, null, 2)}\n`);
862
+ return;
863
+ }
864
+ const lang = typeof flags.lang === "string" ? flags.lang : outputLanguage();
865
+ process.stdout.write(`${renderText(doc, { lang, hostCommand: hostCommand("update") })}\n`);
866
+ }
867
+
868
+ if (invokedDirectly(import.meta.url)) await main(process.argv.slice(2));