@mmerterden/multi-agent-pipeline 23.7.0 → 24.0.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 (142) hide show
  1. package/CHANGELOG.md +38 -1
  2. package/README.md +57 -24
  3. package/README.tr.md +41 -8
  4. package/SECURITY.md +3 -3
  5. package/docs/architecture.md +41 -4
  6. package/docs/ecosystem.md +15 -13
  7. package/docs/facts.json +5 -4
  8. package/docs/features.md +59 -15
  9. package/install/_codex-agents.mjs +13 -8
  10. package/install/_common.mjs +24 -0
  11. package/install/_dev-only-files.mjs +4 -0
  12. package/install/_mcp-register.mjs +6 -2
  13. package/install/_rewrite-tree.mjs +197 -0
  14. package/install/codex.mjs +96 -180
  15. package/install/copilot.mjs +24 -54
  16. package/install/index.mjs +29 -11
  17. package/install/templates/codex-instructions.md +21 -5
  18. package/install/templates/copilot-instructions.md +21 -14
  19. package/manifest.json +2082 -0
  20. package/package.json +6 -2
  21. package/pipeline/commands/multi-agent/SKILL.md +5 -4
  22. package/pipeline/commands/multi-agent/analysis/SKILL.md +4 -0
  23. package/pipeline/commands/multi-agent/autopilot-on/SKILL.md +31 -3
  24. package/pipeline/commands/multi-agent/autopilot-status/SKILL.md +5 -1
  25. package/pipeline/commands/multi-agent/channels/SKILL.md +16 -8
  26. package/pipeline/commands/multi-agent/log/SKILL.md +2 -0
  27. package/pipeline/commands/multi-agent/stack/SKILL.md +1 -1
  28. package/pipeline/contract/manifest.json +1 -1
  29. package/pipeline/contract/types/index.d.ts +1 -0
  30. package/pipeline/lib/_jira-auth.sh +50 -78
  31. package/pipeline/lib/_service-account.sh +191 -0
  32. package/pipeline/lib/credential-inventory.sh +49 -37
  33. package/pipeline/lib/credential-store.sh +48 -3
  34. package/pipeline/lib/fetch-confluence.sh +76 -92
  35. package/pipeline/lib/fetch-crashlytics.sh +30 -59
  36. package/pipeline/lib/fetch-figma-annotations.sh +9 -9
  37. package/pipeline/lib/fetch-fortify.sh +77 -81
  38. package/pipeline/lib/fetch-graylog.sh +38 -77
  39. package/pipeline/lib/figma-mcp-refresh.sh +23 -4
  40. package/pipeline/lib/figma-screenshot.sh +7 -8
  41. package/pipeline/lib/figma-token.sh +39 -46
  42. package/pipeline/lib/host.mjs +138 -0
  43. package/pipeline/lib/host.sh +48 -0
  44. package/pipeline/lib/issue-fetcher.sh +25 -41
  45. package/pipeline/lib/jira-publish.sh +23 -21
  46. package/pipeline/lib/local-model.mjs +93 -0
  47. package/pipeline/lib/md2confluence-v3.py +37 -30
  48. package/pipeline/lib/model-dispatch.sh +41 -4
  49. package/pipeline/lib/model-resolve.mjs +58 -0
  50. package/pipeline/lib/post-pr-review.sh +38 -53
  51. package/pipeline/lib/reviewer-families.mjs +70 -0
  52. package/pipeline/lib/service-account.mjs +2131 -0
  53. package/pipeline/lib/service-account.sh +35 -0
  54. package/pipeline/lib/usage-token.mjs +64 -24
  55. package/pipeline/lib/usage-vocab.mjs +1 -1
  56. package/pipeline/lib/user-facing.mjs +11 -3
  57. package/pipeline/lib/vercel-deploy.sh +17 -26
  58. package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
  59. package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
  60. package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
  61. package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
  62. package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
  63. package/pipeline/multi-agent-refs/channels/generator.md +10 -2
  64. package/pipeline/multi-agent-refs/channels/menu.md +3 -1
  65. package/pipeline/multi-agent-refs/channels/preview.md +3 -1
  66. package/pipeline/multi-agent-refs/channels/reference.md +16 -2
  67. package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
  68. package/pipeline/multi-agent-refs/cross-cli-contract.md +35 -27
  69. package/pipeline/multi-agent-refs/features/doctor.md +37 -11
  70. package/pipeline/multi-agent-refs/features/free-models.md +3 -3
  71. package/pipeline/multi-agent-refs/features/local-model.md +87 -0
  72. package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
  73. package/pipeline/multi-agent-refs/features/product-context.md +6 -5
  74. package/pipeline/multi-agent-refs/features/service-accounts.md +233 -0
  75. package/pipeline/multi-agent-refs/features/unattended-security.md +10 -1
  76. package/pipeline/multi-agent-refs/help/en.md +28 -1
  77. package/pipeline/multi-agent-refs/help/tr.md +28 -1
  78. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +2 -1
  79. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -1
  80. package/pipeline/multi-agent-refs/phases/modes.md +20 -1
  81. package/pipeline/multi-agent-refs/phases/phase-5-report.md +12 -10
  82. package/pipeline/multi-agent-refs/phases.md +4 -3
  83. package/pipeline/multi-agent-refs/review/panel.md +30 -18
  84. package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
  85. package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
  86. package/pipeline/multi-agent-refs/sync/overview.md +11 -5
  87. package/pipeline/multi-agent-refs/tracker-contract.md +28 -10
  88. package/pipeline/office/index.html +3 -3
  89. package/pipeline/schemas/autopilot-config.schema.json +29 -4
  90. package/pipeline/schemas/hosts.json +512 -0
  91. package/pipeline/schemas/hosts.schema.json +310 -0
  92. package/pipeline/schemas/launch.json +22 -2
  93. package/pipeline/schemas/launch.schema.json +2 -1
  94. package/pipeline/schemas/phases.json +19 -1
  95. package/pipeline/schemas/phases.schema.json +8 -0
  96. package/pipeline/schemas/prefs.schema.json +331 -4
  97. package/pipeline/scripts/.doctor-mut.47076.mjs +2253 -0
  98. package/pipeline/scripts/_autopilot-config.mjs +67 -4
  99. package/pipeline/scripts/_autopilot-item.mjs +67 -0
  100. package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
  101. package/pipeline/scripts/_cost.mjs +75 -3
  102. package/pipeline/scripts/analysis-sources.mjs +22 -5
  103. package/pipeline/scripts/analysis-unattended.mjs +360 -0
  104. package/pipeline/scripts/anonymize-findings.mjs +3 -7
  105. package/pipeline/scripts/autopilot-arming.mjs +19 -10
  106. package/pipeline/scripts/autopilot-intake.mjs +124 -27
  107. package/pipeline/scripts/autopilot-menubar.swift +7 -0
  108. package/pipeline/scripts/autopilot-runner.mjs +77 -48
  109. package/pipeline/scripts/autopilot-status.sh +32 -9
  110. package/pipeline/scripts/bulk-read.sh +37 -5
  111. package/pipeline/scripts/confluence-readback.mjs +15 -7
  112. package/pipeline/scripts/cost-table.json +65 -25
  113. package/pipeline/scripts/doctor.mjs +119 -32
  114. package/pipeline/scripts/entry-mode.mjs +101 -0
  115. package/pipeline/scripts/estimate.mjs +30 -16
  116. package/pipeline/scripts/feedback-send.mjs +11 -8
  117. package/pipeline/scripts/gen-facts.mjs +7 -9
  118. package/pipeline/scripts/jira-attach.sh +23 -28
  119. package/pipeline/scripts/jira-search.sh +5 -21
  120. package/pipeline/scripts/launch-request.mjs +15 -9
  121. package/pipeline/scripts/migrate-prefs.mjs +56 -0
  122. package/pipeline/scripts/phase-tracker.sh +146 -38
  123. package/pipeline/scripts/priority-review.mjs +14 -7
  124. package/pipeline/scripts/product-context.mjs +26 -7
  125. package/pipeline/scripts/prune-logs.sh +4 -2
  126. package/pipeline/scripts/report-file.mjs +285 -0
  127. package/pipeline/scripts/rework-escalation.mjs +19 -4
  128. package/pipeline/scripts/service-read.mjs +19 -17
  129. package/pipeline/scripts/skill-siblings.mjs +17 -1
  130. package/pipeline/scripts/status-overview.mjs +20 -10
  131. package/pipeline/scripts/uninstall.mjs +145 -57
  132. package/pipeline/scripts/usage-register.mjs +34 -11
  133. package/pipeline/scripts/usage-report.mjs +31 -26
  134. package/pipeline/scripts/validate-triage.mjs +11 -1
  135. package/pipeline/scripts/work-items.mjs +25 -28
  136. package/pipeline/scripts/write-store-config.mjs +37 -11
  137. package/pipeline/skills/.skill-manifest.json +4 -4
  138. package/pipeline/skills/.skills-index.json +1 -1
  139. package/pipeline/skills/shared/core/multi-agent/SKILL.md +11 -3
  140. package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
  141. package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
  142. package/pipeline/lib/credential-resolve.mjs +0 -75
@@ -48,7 +48,7 @@ import { basename, dirname, join, resolve } from "node:path";
48
48
  import { pathToFileURL } from "node:url";
49
49
 
50
50
  import { ArgsError, parseArgs } from "../lib/args.mjs";
51
- import { resolveTokenAsync } from "../lib/credential-resolve.mjs";
51
+ import { resolveSecretAsync, selectAccount } from "../lib/service-account.mjs";
52
52
  import { globalPref } from "../lib/prefs-value.mjs";
53
53
  import { hostCommand, messages, outputLanguage } from "../lib/user-facing.mjs";
54
54
 
@@ -383,18 +383,25 @@ export function buildJql(team, presetId, days, extra, t = TEXT.en) {
383
383
  // ---------------------------------------------------------------- Jira
384
384
 
385
385
  function jiraHost(env, t) {
386
- const h = globalPref("hosts.jira", null, env);
387
- if (typeof h !== "string" || !h.trim()) throw new Refusal(t.noHost(hostCommand("setup")));
388
- const host = h.trim().replace(/\/+$/, "");
389
- return /^https?:\/\//.test(host) ? host : `https://${host}`;
386
+ const chosen = selectAccount({ service: "jira" }, { env });
387
+ if (!chosen.ok) throw new Refusal(t.noHost(hostCommand("setup")));
388
+ const base = chosen.account.baseUrl ?? `https://${chosen.account.hosts[0]}`;
389
+ if (!base) throw new Refusal(t.noHost(hostCommand("setup")));
390
+ return base;
390
391
  }
391
392
 
392
393
  function jiraClient(env, t) {
393
394
  const host = jiraHost(env, t);
394
395
  let token = null;
395
396
  return async function request(path, method = "GET", body = undefined) {
396
- if (!token) token = await resolveTokenAsync("jira", "JIRA_TOKEN", { env });
397
- if (!token) throw new Refusal(t.noToken(hostCommand("setup")));
397
+ if (!token) {
398
+ // The host this client was built for is the destination the token is
399
+ // asked for: one account answers both, so a token for another instance
400
+ // is a refusal here rather than a header on the way out.
401
+ const answer = await resolveSecretAsync({ service: "jira", url: host }, { env });
402
+ if (!answer.ok) throw new Refusal(t.noToken(hostCommand("setup")));
403
+ token = answer.secret;
404
+ }
398
405
  const headers = { Authorization: `Bearer ${token}`, Accept: "application/json" };
399
406
  if (body !== undefined) headers["Content-Type"] = "application/json";
400
407
  const res = await fetch(host + path, {
@@ -47,6 +47,7 @@ import { fileURLToPath } from "node:url";
47
47
  import { lockTimeoutFrom, withFileLockSync, writeJsonAtomicSync } from "../lib/json-file-lock.mjs";
48
48
  import { fileSafeName } from "../lib/slug.mjs";
49
49
  import { prefsPath } from "../lib/prefs-value.mjs";
50
+ import { itemNames, selectAccount } from "../lib/service-account.mjs";
50
51
  import { ArgsError, parseArgs as parseArgv } from "../lib/args.mjs";
51
52
  import { exitOnHelp } from "../lib/cli-help.mjs";
52
53
 
@@ -245,19 +246,21 @@ function httpsHost(remote) {
245
246
  }
246
247
 
247
248
  /**
248
- * Write a confirmed product. A repository may name a credential only when that
249
- * key is already bound to the repository's https host in
250
- * `prefs.global.credentialHosts`, which `/multi-agent:setup` writes with the
251
- * person present. The product map never creates a binding: the repo list is
252
- * assembled from picker output and model-written files, and a binding made
253
- * there would let any text that reached the planner send a token anywhere.
249
+ * Write a confirmed product. A repository may name a credential only when the
250
+ * pairing already exists: an account that names it and covers the repository's
251
+ * https host, or that host listed for the key in `prefs.global.credentialHosts`,
252
+ * which `/multi-agent:setup` writes with the person present. The product map
253
+ * never creates a binding: the repo list is assembled from picker output and
254
+ * model-written files, and a binding made there would let any text that reached
255
+ * the planner send a token anywhere.
254
256
  */
255
257
  const MAX_PRODUCT_REPOS = 20;
256
258
  const CREDENTIAL_FIELDS = ["credential", "authScheme", "username"];
257
259
 
258
260
  /**
259
261
  * Why a repo entry may not carry its credential, or null when it may: the
260
- * remote must be https and its host bound to the key in
262
+ * remote must be https and the key already paired with its host - by an
263
+ * account that names the key and covers the host, or by the key's own list in
261
264
  * `prefs.global.credentialHosts`, which only setup writes. Checked on every
262
265
  * entry a merge produces, so a credential kept from an earlier spelling never
263
266
  * lands on a remote it was not bound for.
@@ -265,6 +268,7 @@ const CREDENTIAL_FIELDS = ["credential", "authScheme", "username"];
265
268
  function credentialProblem(prefs, r) {
266
269
  if (!r.credential) return null;
267
270
  const host = httpsHost(r.remote);
271
+ if (host && accountCovers(prefs, r.credential, host)) return null;
268
272
  const hosts = (prefs?.global?.credentialHosts?.[r.credential] || []).map((h) =>
269
273
  String(h).toLowerCase(),
270
274
  );
@@ -272,6 +276,21 @@ function credentialProblem(prefs, r) {
272
276
  return `credential ${JSON.stringify(r.credential)} is not bound to ${host || r.remote}; bind it in prefs.global.credentialHosts with /multi-agent:setup hosts first`;
273
277
  }
274
278
 
279
+ /**
280
+ * Whether an account this credential key names already reaches `host`.
281
+ *
282
+ * The key is the one a store read is made with, so it answers to an account by
283
+ * its id or by the item it holds. The account decides the destination: a key
284
+ * that names an account reaches what that account reaches and nothing else.
285
+ */
286
+ function accountCovers(prefs, credential, host) {
287
+ const named = itemNames(prefs).filter((x) => x.accountId === credential || x.item === credential);
288
+ return named.some(
289
+ (x) =>
290
+ selectAccount({ service: x.service, accountId: x.accountId, host }, { prefs, env: {} }).ok,
291
+ );
292
+ }
293
+
275
294
  export function learnProduct(prefs, projectKey, productName, repos) {
276
295
  if (!productName || !/^[A-Za-z0-9._-]{1,64}$/.test(productName))
277
296
  throw new Error("product name must be 1-64 letters, digits, . _ -");
@@ -3,7 +3,8 @@
3
3
  #
4
4
  # Every run persists a task log dir at
5
5
  # $HOME/.claude/logs/multi-agent/<project>/<task>/
6
- # holding agent-state.json, agent-log.md, tracker-state.json, otel-spans.jsonl.
6
+ # holding agent-state.json, agent-log.md, tracker-state.json, otel-spans.jsonl
7
+ # or task-report.md.
7
8
  # These accumulate forever. This prunes whole task dirs, with optional age /
8
9
  # project / task filters.
9
10
  #
@@ -133,7 +134,8 @@ fi
133
134
  is_task_dir() {
134
135
  local d="$1"
135
136
  [ -f "$d/agent-state.json" ] || [ -f "$d/tracker-state.json" ] ||
136
- [ -f "$d/agent-log.md" ] || [ -f "$d/otel-spans.jsonl" ]
137
+ [ -f "$d/agent-log.md" ] || [ -f "$d/otel-spans.jsonl" ] ||
138
+ [ -f "$d/task-report.md" ]
137
139
  }
138
140
 
139
141
  # Names promised to survive pruning. A directory carrying one of these names
@@ -0,0 +1,285 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * report-file.mjs - the run's report, on disk, whatever the channels did.
4
+ *
5
+ * Phase 5 composes a development summary and test scenarios and hands them to
6
+ * PR, Jira, Confluence and Wiki. Every one of those is an external write, and
7
+ * three ordinary paths end with nothing written at all: a local-only repo
8
+ * short-circuits before the menu, an unattended run defers delivery to the
9
+ * runner, and a cancelled or timed-out menu posts nothing. On a machine with no
10
+ * tracker the work was summarized and then thrown away.
11
+ *
12
+ * So this is not a fifth channel. A channel is selectable, waits for the
13
+ * approval gate, and is skipped unattended and offline - each of which would
14
+ * reintroduce one of the three losses. It is internal capture, like
15
+ * `agent-log.md`: unconditional, local, and with no preference to get wrong.
16
+ *
17
+ * Nothing here composes anything. The bodies are handed in as files and copied
18
+ * byte for byte, so the file says exactly what the preview said and what the
19
+ * adapters posted.
20
+ *
21
+ * Usage:
22
+ * report-file.mjs write --dir <task-dir> --run <id> --meta <meta.json>
23
+ * --body <name>=<file> [--body ...] [--delivery <json>]
24
+ * report-file.mjs path --dir <task-dir>
25
+ *
26
+ * Block names: `report`, `pr:<label>`, `jira`, `confluence`. Order is fixed
27
+ * here, not by the argument order.
28
+ *
29
+ * Exit: 0 written; 2 usage, no body, an empty body, or a path that is not
30
+ * inside the logs root; 7 a body carries credential-shaped text.
31
+ */
32
+
33
+ import {
34
+ existsSync,
35
+ lstatSync,
36
+ mkdirSync,
37
+ readFileSync,
38
+ readdirSync,
39
+ realpathSync,
40
+ renameSync,
41
+ rmSync,
42
+ unlinkSync,
43
+ writeFileSync,
44
+ } from "node:fs";
45
+ import { basename, join, resolve } from "node:path";
46
+ import { ArgsError, parseArgs } from "../lib/args.mjs";
47
+ import { scan } from "../lib/outbound-gate.mjs";
48
+ import { logsRoot } from "./_run-paths.mjs";
49
+
50
+ await import("../lib/cli-help.mjs").then(
51
+ (m) => m.exitOnHelp(import.meta.url),
52
+ () => {},
53
+ );
54
+
55
+ const FILE_NAME = "task-report.md";
56
+ const HISTORY_DIR = "report-history";
57
+ const HISTORY_KEEP = 5;
58
+
59
+ /** Blocks in the order a reader wants them, whatever order they arrived in. */
60
+ const ORDER = ["report", "pr", "jira", "confluence"];
61
+ const rank = (name) => {
62
+ const kind = name.startsWith("pr:") ? "pr" : name;
63
+ const at = ORDER.indexOf(kind);
64
+ return at < 0 ? ORDER.length : at;
65
+ };
66
+
67
+ /** What a block is called in the file. Fixed English, so the file stays parseable. */
68
+ function heading(name) {
69
+ if (name === "report") return "Report";
70
+ if (name === "jira") return "Jira comment";
71
+ if (name === "confluence") return "Confluence page";
72
+ if (name.startsWith("pr:")) return `PR description (${name.slice(3)})`;
73
+ return name;
74
+ }
75
+
76
+ function die(code, message) {
77
+ process.stderr.write(`report-file: ${message}\n`);
78
+ process.exit(code);
79
+ }
80
+
81
+ /**
82
+ * The flags, through the shared parser.
83
+ *
84
+ * `--body` is the only repeatable one, and every flag here takes a value, so
85
+ * a missing one is a usage error rather than a `true` that would later read
86
+ * as a filename.
87
+ */
88
+ function parseArgv(argv) {
89
+ try {
90
+ const { flags } = parseArgs(argv, {
91
+ values: ["dir", "run", "meta", "delivery", "body"],
92
+ multiple: ["body"],
93
+ unknown: "error",
94
+ });
95
+ return { ...flags, body: flags.body ?? [] };
96
+ } catch (error) {
97
+ if (error instanceof ArgsError) die(2, error.message);
98
+ throw error;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The task directory, proven to be inside the logs root.
104
+ *
105
+ * `realpath` on the root and on the directory's parent, then a prefix test: a
106
+ * caller that passes `..`, or a symlink pointing out of the tree, is asking
107
+ * this script to write somewhere it has no business writing. Refused rather
108
+ * than normalized, because a path that needed normalizing was not the path the
109
+ * caller meant.
110
+ */
111
+ function taskDir(given) {
112
+ if (!given) die(2, "--dir is required");
113
+ const dir = resolve(given);
114
+ if (!existsSync(dir)) die(2, `no such directory: ${dir}`);
115
+ let real;
116
+ let root;
117
+ try {
118
+ real = realpathSync(dir);
119
+ root = realpathSync(logsRoot());
120
+ } catch {
121
+ die(2, "the logs root does not resolve");
122
+ }
123
+ if (real !== root && !real.startsWith(root + "/")) {
124
+ die(2, `refusing to write outside the logs root: ${real}`);
125
+ }
126
+ return real;
127
+ }
128
+
129
+ /** A path that exists and is not a link. A link here points the write elsewhere. */
130
+ function refuseLink(path, what) {
131
+ if (!existsSync(path)) return;
132
+ if (lstatSync(path).isSymbolicLink()) die(2, `${what} is a symbolic link: ${path}`);
133
+ }
134
+
135
+ /**
136
+ * The history name for a report already on disk.
137
+ *
138
+ * The stamp leads, so the directory sorts chronologically, and the run id
139
+ * follows, because the stamp is minute-resolution and two runs inside one
140
+ * minute would otherwise share a name - the second quietly replacing the first
141
+ * in the very place that exists to not lose it.
142
+ */
143
+ function historyName(text) {
144
+ const stamp = (
145
+ /^- Written: (\d{4}-\d{2}-\d{2} \d{2}:\d{2})/m.exec(text)?.[1] ?? "unknown"
146
+ ).replace(/[: ]/g, "-");
147
+ const run = (runOf(text) ?? "unknown").replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 40);
148
+ return `task-report-${stamp}-${run}.md`;
149
+ }
150
+
151
+ /** The run id a file on disk was written for. */
152
+ function runOf(text) {
153
+ return /^- Written:.*\(run ([^)]*)\)/m.exec(text)?.[1] ?? null;
154
+ }
155
+
156
+ function localStamp(now = new Date()) {
157
+ const p = (n) => String(n).padStart(2, "0");
158
+ return `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}`;
159
+ }
160
+
161
+ function readJson(path, what) {
162
+ if (!path) return null;
163
+ try {
164
+ return JSON.parse(readFileSync(path, "utf8"));
165
+ } catch {
166
+ die(2, `${what} does not parse: ${path}`);
167
+ }
168
+ }
169
+
170
+ /** The whole file, envelope then blocks. */
171
+ function render(meta, blocks, delivery) {
172
+ const head = [
173
+ `# ${meta.taskKey ?? "(untitled run)"}${meta.title ? ` - ${meta.title}` : ""}`,
174
+ "",
175
+ `- Branch: ${meta.branch ? `\`${meta.branch}\`${meta.base ? ` -> \`${meta.base}\`` : ""}` : "none"}`,
176
+ `- PR: ${meta.prUrl ?? "none"}`,
177
+ `- Tracker: ${meta.tracker ?? "none"}`,
178
+ `- Written: ${localStamp()} by /multi-agent:channels (run ${meta.runId})`,
179
+ `- Delivery: ${delivery ?? "not sent"}`,
180
+ "",
181
+ ];
182
+ const body = [];
183
+ for (const { name, text } of blocks) {
184
+ body.push("---", "", `# ${heading(name)}`, "", text.replace(/\n+$/, ""), "");
185
+ }
186
+ return head.concat(body).join("\n").replace(/\n+$/, "") + "\n";
187
+ }
188
+
189
+ /** One line per channel, from the dispatch result, or null when nothing ran. */
190
+ function deliveryLine(results) {
191
+ if (!results) return null;
192
+ const parts = [];
193
+ for (const [channel, r] of Object.entries(results)) {
194
+ if (!r || typeof r !== "object") continue;
195
+ const status = r.status ?? "unknown";
196
+ parts.push(`${channel} ${status}${r.reason ? `: ${r.reason}` : ""}`);
197
+ }
198
+ return parts.length ? parts.join(" · ") : null;
199
+ }
200
+
201
+ function cmdWrite(a) {
202
+ const dir = taskDir(a.dir);
203
+ if (!a.run) die(2, "--run is required");
204
+ if (!a.body.length) die(2, "at least one --body <name>=<file> is required");
205
+
206
+ const blocks = [];
207
+ for (const pair of a.body) {
208
+ const at = pair.indexOf("=");
209
+ if (at < 1) die(2, `--body wants <name>=<file>, got: ${pair}`);
210
+ const name = pair.slice(0, at);
211
+ const file = pair.slice(at + 1);
212
+ let text;
213
+ try {
214
+ text = readFileSync(file, "utf8");
215
+ } catch {
216
+ die(2, `body file unreadable: ${file}`);
217
+ }
218
+ if (!text.trim()) die(2, `body is empty: ${name}`);
219
+ blocks.push({ name, text });
220
+ }
221
+ blocks.sort((x, y) => rank(x.name) - rank(y.name) || x.name.localeCompare(y.name));
222
+
223
+ // Scanned before anything is written, and the match itself is never printed:
224
+ // a report naming the rule that fired is useful, a report quoting the secret
225
+ // it found has copied the secret somewhere new.
226
+ for (const { name, text } of blocks) {
227
+ const blocking = scan(text).filter((f) => f.certain);
228
+ if (blocking.length) {
229
+ const named = blocking.map((f) => `${f.rule} (line ${f.line})`).join(", ");
230
+ die(7, `credential-shaped text in the ${heading(name)} body: ${named} - nothing written`);
231
+ }
232
+ }
233
+
234
+ const meta = { ...(readJson(a.meta, "--meta") ?? {}), runId: a.run };
235
+ const delivery = deliveryLine(readJson(a.delivery, "--delivery"));
236
+ const target = join(dir, FILE_NAME);
237
+ const history = join(dir, HISTORY_DIR);
238
+ refuseLink(target, FILE_NAME);
239
+ refuseLink(history, HISTORY_DIR);
240
+
241
+ // A new run keeps the previous file rather than overwriting it, and the same
242
+ // run rewrites in place: the Edit loop and the delivery stamp are the same
243
+ // run saying the same thing again, not a second report.
244
+ let rotated = false;
245
+ if (existsSync(target)) {
246
+ const previous = readFileSync(target, "utf8");
247
+ if (runOf(previous) !== a.run) {
248
+ mkdirSync(history, { recursive: true, mode: 0o700 });
249
+ writeFileSync(join(history, historyName(previous)), previous, { mode: 0o600 });
250
+ rotated = true;
251
+ const kept = readdirSync(history)
252
+ .filter((f) => f.startsWith("task-report-") && f.endsWith(".md"))
253
+ .sort()
254
+ .reverse();
255
+ for (const old of kept.slice(HISTORY_KEEP)) rmSync(join(history, old), { force: true });
256
+ }
257
+ }
258
+
259
+ // Temp file in the same directory, then rename: a reader never sees a half
260
+ // written report, and a crash leaves the previous one intact.
261
+ const tmp = join(dir, `.${FILE_NAME}.${process.pid}.tmp`);
262
+ try {
263
+ writeFileSync(tmp, render(meta, blocks, delivery), { mode: 0o600 });
264
+ renameSync(tmp, target);
265
+ } catch (error) {
266
+ try {
267
+ unlinkSync(tmp);
268
+ } catch {
269
+ /* the temp file is already gone */
270
+ }
271
+ die(2, `could not write ${target}: ${error.message}`);
272
+ }
273
+ process.stdout.write(target + "\n");
274
+ if (rotated) process.stderr.write(`report-file: previous report kept in ${HISTORY_DIR}/\n`);
275
+ }
276
+
277
+ function cmdPath(a) {
278
+ process.stdout.write(join(taskDir(a.dir), FILE_NAME) + "\n");
279
+ }
280
+
281
+ const [command, ...rest] = process.argv.slice(2);
282
+ const args = parseArgv(rest);
283
+ if (command === "write") cmdWrite(args);
284
+ else if (command === "path") cmdPath(args);
285
+ else die(2, `usage: ${basename(process.argv[1])} {write|path} --dir <task-dir> [...]`);
@@ -20,7 +20,7 @@
20
20
  * mid-run (model-fallback.md, Non-goals)
21
21
  * budget-* cost-budget-check.mjs is at warn, exceeded, or unreadable,
22
22
  * or was not run while prefs.global.costBudget.enabled is true
23
- * unknown-tier the current rung is not on the ladder (another host's model)
23
+ * unknown-tier the recorded model resolves to no rung on this host
24
24
  * top-of-ladder nothing above the current rung
25
25
  * fable-off the next rung is fable and modelFallback.fableEnabled is not true
26
26
  * at-ceiling the next rung is above prefs.global.reworkEscalation.maxTier
@@ -59,6 +59,7 @@ import { DEFAULT_ROUNDS, resolveForRun } from "./review-rounds.mjs";
59
59
  import { prefsPath } from "../lib/prefs-value.mjs";
60
60
  import { ArgsError, parseArgs } from "../lib/args.mjs";
61
61
  import { exitOnHelp } from "../lib/cli-help.mjs";
62
+ import { modelFor, rungOf } from "../lib/model-resolve.mjs";
62
63
 
63
64
  exitOnHelp(import.meta.url);
64
65
 
@@ -135,14 +136,28 @@ export function decide({
135
136
  );
136
137
  }
137
138
 
138
- const at = ladder.indexOf(currentTier);
139
- if (at < 0 || !LADDER.includes(currentTier)) return stay("unknown-tier", trigger);
139
+ // A tracker records the MODEL a round ran, and only one host names its models
140
+ // after the rungs. Comparing the raw string against the ladder answered
141
+ // "unknown-tier" for every other host, which turned escalation off there
142
+ // without ever saying so.
143
+ const tier = rungOf(currentTier) ?? currentTier;
144
+ const at = ladder.indexOf(tier);
145
+ if (at < 0 || !LADDER.includes(tier)) return stay("unknown-tier", trigger);
140
146
  if (at === 0) return stay("top-of-ladder", trigger);
141
147
  const next = ladder[at - 1];
142
148
  if (next === "fable" && !cfg.fableEnabled) return stay("fable-off", trigger);
149
+ // A host that does not offer the next rung, or whose next rung runs the same
150
+ // model at the same effort, has nothing above this one. Spending a rework
151
+ // round to arrive at the same dispatch is the failure this guard names.
152
+ const here = modelFor(tier);
153
+ const above = modelFor(next);
154
+ if (!above) return stay("top-of-ladder", trigger);
155
+ if (here && above.model === here.model && above.effort === here.effort) {
156
+ return stay("top-of-ladder", trigger);
157
+ }
143
158
  if (LADDER.indexOf(next) < LADDER.indexOf(cfg.maxTier)) return stay("at-ceiling", trigger);
144
159
 
145
- return { escalate: true, fromTier: currentTier, toTier: next, trigger, reason: "escalated" };
160
+ return { escalate: true, fromTier: tier, toTier: next, trigger, reason: "escalated" };
146
161
  }
147
162
 
148
163
  // ---------------------------------------------------------------------------
@@ -5,11 +5,11 @@
5
5
  * shows it next to a run:
6
6
  *
7
7
  * confluence <page> lib/fetch-confluence.sh: a page by id or by https
8
- * URL, both only on the configured
9
- * prefs.global.hosts.confluence; a URL on any other
10
- * host, or any URL when no host is configured, is
11
- * refused before the script runs; title, markdown
12
- * body, API contracts count
8
+ * URL, both only on a host a configured Confluence
9
+ * account covers; a URL on any other host, or any
10
+ * URL when no account is configured, is refused
11
+ * before the script runs; title, markdown body, API
12
+ * contracts count
13
13
  * crashlytics <issue-url> lib/fetch-crashlytics.sh: one Crashlytics issue,
14
14
  * title, occurrences, impacted users, top frames
15
15
  * figma <file-key> <node> lib/figma-screenshot.sh (REST with the Figma
@@ -24,9 +24,9 @@
24
24
  * The scripts run as child processes without blocking the caller's event
25
25
  * loop (contract-server.mjs serves other routes meanwhile).
26
26
  *
27
- * Credentials are read only by those scripts, through credential-store.sh.
28
- * Every text that comes back is scrubbed and redacted; an image comes back as
29
- * base64.
27
+ * Credentials are read only by those scripts, each through the account
28
+ * resolver. Every text that comes back is scrubbed and redacted; an image
29
+ * comes back as base64.
30
30
  *
31
31
  * Usage:
32
32
  * service-read.mjs confluence <page-id|https-url>
@@ -49,7 +49,7 @@ import { createRedactor } from "./transcript-index.mjs";
49
49
  import { spawnAsync } from "./_spawn-async.mjs";
50
50
  import { runMain } from "../lib/fatal.mjs";
51
51
  import { invokedDirectly } from "../lib/invoked-directly.mjs";
52
- import { loadGlobalPrefs, prefsPath } from "../lib/prefs-value.mjs";
52
+ import { selectAccount } from "../lib/service-account.mjs";
53
53
  import { exitOnHelp } from "../lib/cli-help.mjs";
54
54
 
55
55
  exitOnHelp(import.meta.url);
@@ -104,13 +104,15 @@ async function run(env, file, args, failCodes) {
104
104
  }
105
105
  }
106
106
 
107
- function confluenceHost(env) {
108
- try {
109
- const h = loadGlobalPrefs(prefsPath(env))?.hosts?.confluence;
110
- return typeof h === "string" && h ? h.replace(/^https?:\/\//, "").replace(/\/.*$/, "") : null;
111
- } catch {
112
- return null;
113
- }
107
+ /**
108
+ * The Confluence host a page may be read from: the account that covers `url`,
109
+ * or, with no URL, the account the resolver picks on its own. A service with
110
+ * no account answers null, which is how "nothing is configured" and "not this
111
+ * host" stay different answers to the caller.
112
+ */
113
+ function confluenceHost(env, url = undefined) {
114
+ const chosen = selectAccount({ service: "confluence", url }, { env });
115
+ return chosen.ok ? (chosen.account.hosts[0] ?? null) : null;
114
116
  }
115
117
 
116
118
  /** One Confluence page, by id or by a URL on the configured host only. */
@@ -129,7 +131,7 @@ export async function confluencePage(page, env = process.env) {
129
131
  "no Confluence host is configured, so only a page id is accepted",
130
132
  );
131
133
  }
132
- if (new URL(url).hostname !== host) {
134
+ if (!confluenceHost(env, url)) {
133
135
  throw new ServiceError("host-not-allowed", "that host is not the configured Confluence host");
134
136
  }
135
137
  args = [url];
@@ -44,6 +44,7 @@ import { basename, dirname, join, resolve } from "node:path";
44
44
  import { homedir } from "node:os";
45
45
  import { fileURLToPath } from "node:url";
46
46
  import { hostCommand } from "../lib/user-facing.mjs";
47
+ import { REGISTRY, hostRoot, installedHostIds } from "../lib/host.mjs";
47
48
  import { exitOnHelp } from "../lib/cli-help.mjs";
48
49
 
49
50
  exitOnHelp(import.meta.url);
@@ -61,7 +62,20 @@ const REPO_CMD_DIR = join(REPO_ROOT, "pipeline", "commands", "multi-agent");
61
62
  const IN_REPO = existsSync(REPO_CMD_DIR);
62
63
  const ROOT = IN_REPO ? REPO_ROOT : HOME;
63
64
 
64
- const CMD_DIR = IN_REPO ? REPO_CMD_DIR : join(HOME, ".claude", "commands", "multi-agent");
65
+ // Installed, the specs sit wherever THIS machine's hosts keep them, which is a
66
+ // different tree and a different directory naming on each. Reading the Claude
67
+ // layout unconditionally made a machine with a complete Copilot-only install
68
+ // report "no commands found - the tree layout has changed".
69
+ const INSTALLED_SPECS = installedHostIds(HOME)
70
+ .map((id) => ({
71
+ dir: join(hostRoot(HOME, id), REGISTRY.hosts[id].install.commandSpecs),
72
+ prefix: REGISTRY.hosts[id].install.commandSpecPrefix,
73
+ }))
74
+ .find(({ dir }) => existsSync(dir));
75
+ const CMD_DIR = IN_REPO
76
+ ? REPO_CMD_DIR
77
+ : (INSTALLED_SPECS?.dir ?? join(HOME, ".claude", "commands", "multi-agent"));
78
+ const CMD_PREFIX = IN_REPO ? "" : (INSTALLED_SPECS?.prefix ?? "");
65
79
  const CORE_DIR = join(REPO_ROOT, "pipeline", "skills", "shared", "core");
66
80
  const COPILOT_DIR = join(HOME, ".copilot", "skills");
67
81
  const CODEX_DIR = join(HOME, ".codex", "multi-agent-refs", "commands");
@@ -100,9 +114,11 @@ function commandNames() {
100
114
  if (!existsSync(CMD_DIR)) return [];
101
115
  return readdirSync(CMD_DIR)
102
116
  .filter((d) => {
117
+ if (CMD_PREFIX && !d.startsWith(CMD_PREFIX)) return false;
103
118
  const p = join(CMD_DIR, d);
104
119
  return statSync(p).isDirectory() && existsSync(join(p, "SKILL.md"));
105
120
  })
121
+ .map((d) => (CMD_PREFIX ? d.slice(CMD_PREFIX.length) : d))
106
122
  .sort();
107
123
  }
108
124
 
@@ -18,10 +18,10 @@
18
18
  * estimate errs low;
19
19
  * 3. accounts: the github.com logins gh holds (usage-identity.mjs) and the
20
20
  * author git would write in the current directory;
21
- * 4. credentials: each logical name in prefs.global.keychainMapping is
22
- * "registered" when its service name is in `credential-store.sh list`.
23
- * Only service names are read: the store is never asked for a value, and
24
- * nothing about a value (length, prefix) is printed;
21
+ * 4. credentials: every store item this machine's accounts name (the account
22
+ * resolver's itemNames) is "registered" when the store lists it. Only
23
+ * names are read: the store is never asked for a value, and nothing about
24
+ * a value (length, prefix) is printed;
25
25
  * 5. runs: runs-index.mjs, the same records /multi-agent:status always used.
26
26
  *
27
27
  * Usage:
@@ -50,6 +50,7 @@ import { matchRun } from "./activity-snapshot.mjs";
50
50
  import { buildIndex, phaseCell } from "./runs-index.mjs";
51
51
  import { listAccounts } from "./usage-identity.mjs";
52
52
  import { prefsPath as sharedPrefsPath } from "../lib/prefs-value.mjs";
53
+ import { itemNames } from "../lib/service-account.mjs";
53
54
 
54
55
  export const CONTRACT_VERSION = "1.0.0";
55
56
  export const WINDOW_MS = 24 * 3_600_000;
@@ -204,11 +205,18 @@ function recentFiles(root, since) {
204
205
  return out;
205
206
  }
206
207
 
207
- /** Logical credential names and whether each is registered; values are never read. */
208
+ /**
209
+ * The accounts' credential names and whether each is registered; values are
210
+ * never read.
211
+ *
212
+ * The name shown is the account a slot belongs to, which for a single-secret
213
+ * service is the service itself; a service with more than one secret names the
214
+ * slot as well, so two halves of one login read as two rows rather than one.
215
+ */
208
216
  export function credentialStatus({ env = process.env } = {}) {
209
- let mapping;
217
+ let named;
210
218
  try {
211
- mapping = JSON.parse(readFileSync(prefsPath(env), "utf8"))?.global?.keychainMapping ?? {};
219
+ named = itemNames(JSON.parse(readFileSync(prefsPath(env), "utf8")));
212
220
  } catch {
213
221
  return { readable: false, items: [] };
214
222
  }
@@ -219,9 +227,11 @@ export function credentialStatus({ env = process.env } = {}) {
219
227
  });
220
228
  if (listed.status !== 0) return { readable: false, items: [] };
221
229
  const services = new Set(String(listed.stdout).split("\n").filter(Boolean));
222
- const items = Object.entries(mapping)
223
- .filter(([k, v]) => typeof k === "string" && typeof v === "string" && v)
224
- .map(([name, service]) => ({ name, registered: services.has(service) }))
230
+ const items = named
231
+ .map(({ item, accountId, slot }) => ({
232
+ name: slot === "token" ? accountId : `${accountId}/${slot}`,
233
+ registered: services.has(item),
234
+ }))
225
235
  .sort((a, b) => a.name.localeCompare(b.name));
226
236
  return { readable: true, items };
227
237
  }