@mmerterden/multi-agent-pipeline 23.7.0 → 24.1.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 (162) hide show
  1. package/CHANGELOG.md +60 -1
  2. package/README.md +59 -24
  3. package/README.tr.md +43 -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 +67 -15
  9. package/install/_codex-agents.mjs +13 -8
  10. package/install/_common.mjs +24 -0
  11. package/install/_dev-only-files.mjs +5 -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 +2083 -0
  20. package/package.json +8 -2
  21. package/pipeline/commands/multi-agent/SKILL.md +5 -4
  22. package/pipeline/commands/multi-agent/analysis/SKILL.md +5 -1
  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/CHANGELOG.md +15 -0
  29. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  30. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  31. package/pipeline/contract/fixtures/runs-awaiting-question.json +6 -1
  32. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  33. package/pipeline/contract/fixtures/runs-failed.json +21 -1
  34. package/pipeline/contract/fixtures/runs-old-schema.json +18 -3
  35. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +31 -1
  36. package/pipeline/contract/fixtures/runs-pr-opened.json +31 -1
  37. package/pipeline/contract/fixtures/runs-running.json +16 -1
  38. package/pipeline/contract/manifest.json +14 -14
  39. package/pipeline/contract/types/index.d.ts +20 -1
  40. package/pipeline/lib/_jira-auth.sh +50 -78
  41. package/pipeline/lib/_service-account.sh +191 -0
  42. package/pipeline/lib/credential-inventory.sh +49 -37
  43. package/pipeline/lib/credential-store.sh +48 -3
  44. package/pipeline/lib/fetch-confluence.sh +76 -92
  45. package/pipeline/lib/fetch-crashlytics.sh +30 -59
  46. package/pipeline/lib/fetch-figma-annotations.sh +9 -9
  47. package/pipeline/lib/fetch-fortify.sh +77 -81
  48. package/pipeline/lib/fetch-graylog.sh +38 -77
  49. package/pipeline/lib/figma-mcp-refresh.sh +23 -4
  50. package/pipeline/lib/figma-screenshot.sh +7 -8
  51. package/pipeline/lib/figma-token.sh +39 -46
  52. package/pipeline/lib/host.mjs +138 -0
  53. package/pipeline/lib/host.sh +48 -0
  54. package/pipeline/lib/issue-fetcher.sh +25 -41
  55. package/pipeline/lib/jira-publish.sh +23 -21
  56. package/pipeline/lib/local-model.mjs +93 -0
  57. package/pipeline/lib/md2confluence-v3.py +37 -30
  58. package/pipeline/lib/model-dispatch.sh +41 -4
  59. package/pipeline/lib/model-resolve.mjs +58 -0
  60. package/pipeline/lib/post-pr-review.sh +38 -53
  61. package/pipeline/lib/reviewer-families.mjs +70 -0
  62. package/pipeline/lib/service-account.mjs +2131 -0
  63. package/pipeline/lib/service-account.sh +35 -0
  64. package/pipeline/lib/usage-token.mjs +64 -24
  65. package/pipeline/lib/usage-vocab.mjs +1 -1
  66. package/pipeline/lib/user-facing.mjs +11 -3
  67. package/pipeline/lib/vercel-deploy.sh +17 -26
  68. package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
  69. package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
  70. package/pipeline/multi-agent-refs/analysis/render.md +12 -1
  71. package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
  72. package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
  73. package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
  74. package/pipeline/multi-agent-refs/channels/generator.md +10 -2
  75. package/pipeline/multi-agent-refs/channels/menu.md +3 -1
  76. package/pipeline/multi-agent-refs/channels/preview.md +3 -1
  77. package/pipeline/multi-agent-refs/channels/reference.md +16 -2
  78. package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
  79. package/pipeline/multi-agent-refs/cross-cli-contract.md +35 -27
  80. package/pipeline/multi-agent-refs/features/doctor.md +37 -11
  81. package/pipeline/multi-agent-refs/features/free-models.md +3 -3
  82. package/pipeline/multi-agent-refs/features/local-model.md +87 -0
  83. package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
  84. package/pipeline/multi-agent-refs/features/product-context.md +6 -5
  85. package/pipeline/multi-agent-refs/features/service-accounts.md +233 -0
  86. package/pipeline/multi-agent-refs/features/unattended-security.md +10 -1
  87. package/pipeline/multi-agent-refs/help/en.md +36 -1
  88. package/pipeline/multi-agent-refs/help/tr.md +34 -1
  89. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +2 -1
  90. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -1
  91. package/pipeline/multi-agent-refs/phases/modes.md +20 -1
  92. package/pipeline/multi-agent-refs/phases/phase-0-init.md +1 -0
  93. package/pipeline/multi-agent-refs/phases/phase-4-commit.md +1 -0
  94. package/pipeline/multi-agent-refs/phases/phase-5-report.md +13 -11
  95. package/pipeline/multi-agent-refs/phases.md +4 -3
  96. package/pipeline/multi-agent-refs/review/panel.md +30 -18
  97. package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
  98. package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
  99. package/pipeline/multi-agent-refs/sync/overview.md +11 -5
  100. package/pipeline/multi-agent-refs/tracker-contract.md +64 -20
  101. package/pipeline/office/index.html +77 -4
  102. package/pipeline/schemas/activity.schema.json +63 -4
  103. package/pipeline/schemas/autopilot-config.schema.json +29 -4
  104. package/pipeline/schemas/hosts.json +512 -0
  105. package/pipeline/schemas/hosts.schema.json +310 -0
  106. package/pipeline/schemas/launch.json +22 -2
  107. package/pipeline/schemas/launch.schema.json +2 -1
  108. package/pipeline/schemas/now-lines.json +103 -0
  109. package/pipeline/schemas/now-lines.schema.json +42 -0
  110. package/pipeline/schemas/phases.json +19 -1
  111. package/pipeline/schemas/phases.schema.json +8 -0
  112. package/pipeline/schemas/prefs.schema.json +331 -4
  113. package/pipeline/schemas/runs-index.schema.json +22 -1
  114. package/pipeline/scripts/_autopilot-config.mjs +67 -4
  115. package/pipeline/scripts/_autopilot-item.mjs +67 -0
  116. package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
  117. package/pipeline/scripts/_contract-core.mjs +1 -1
  118. package/pipeline/scripts/_cost.mjs +75 -3
  119. package/pipeline/scripts/activity-snapshot.mjs +27 -1
  120. package/pipeline/scripts/analysis-sources.mjs +22 -5
  121. package/pipeline/scripts/analysis-unattended.mjs +360 -0
  122. package/pipeline/scripts/anonymize-findings.mjs +3 -7
  123. package/pipeline/scripts/autopilot-arming.mjs +19 -10
  124. package/pipeline/scripts/autopilot-intake.mjs +124 -27
  125. package/pipeline/scripts/autopilot-menubar.swift +7 -0
  126. package/pipeline/scripts/autopilot-runner.mjs +77 -48
  127. package/pipeline/scripts/autopilot-status.sh +32 -9
  128. package/pipeline/scripts/bulk-read.sh +37 -5
  129. package/pipeline/scripts/confluence-readback.mjs +15 -7
  130. package/pipeline/scripts/cost-table.json +65 -25
  131. package/pipeline/scripts/doctor.mjs +119 -32
  132. package/pipeline/scripts/entry-mode.mjs +101 -0
  133. package/pipeline/scripts/estimate.mjs +30 -16
  134. package/pipeline/scripts/feedback-send.mjs +11 -8
  135. package/pipeline/scripts/gen-facts.mjs +7 -9
  136. package/pipeline/scripts/jira-attach.sh +23 -28
  137. package/pipeline/scripts/jira-search.sh +5 -21
  138. package/pipeline/scripts/launch-request.mjs +15 -9
  139. package/pipeline/scripts/migrate-prefs.mjs +56 -0
  140. package/pipeline/scripts/phase-tracker.sh +226 -50
  141. package/pipeline/scripts/priority-review.mjs +14 -7
  142. package/pipeline/scripts/product-context.mjs +26 -7
  143. package/pipeline/scripts/prune-logs.sh +4 -2
  144. package/pipeline/scripts/render-work-summary.sh +51 -1
  145. package/pipeline/scripts/report-file.mjs +285 -0
  146. package/pipeline/scripts/rework-escalation.mjs +19 -4
  147. package/pipeline/scripts/runs-index.mjs +2 -1
  148. package/pipeline/scripts/service-read.mjs +19 -17
  149. package/pipeline/scripts/skill-siblings.mjs +17 -1
  150. package/pipeline/scripts/status-overview.mjs +20 -10
  151. package/pipeline/scripts/uninstall.mjs +145 -57
  152. package/pipeline/scripts/usage-register.mjs +34 -11
  153. package/pipeline/scripts/usage-report.mjs +31 -26
  154. package/pipeline/scripts/validate-triage.mjs +11 -1
  155. package/pipeline/scripts/work-items.mjs +25 -28
  156. package/pipeline/scripts/write-store-config.mjs +37 -11
  157. package/pipeline/skills/.skill-manifest.json +4 -4
  158. package/pipeline/skills/.skills-index.json +1 -1
  159. package/pipeline/skills/shared/core/multi-agent/SKILL.md +11 -3
  160. package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
  161. package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
  162. package/pipeline/lib/credential-resolve.mjs +0 -75
@@ -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
  }
@@ -58,6 +58,7 @@ import {
58
58
  } from "../lib/xcode-plugin.mjs";
59
59
  import { createInterface } from "readline";
60
60
  import { removeHooks, templateCommands } from "./host-hooks.mjs";
61
+ import { HOST_IDS, host as hostEntry } from "../lib/host.mjs";
61
62
  import { prefsFileIn } from "../lib/prefs-value.mjs";
62
63
  import { legacyWarning, retireOfficeRemote } from "../lib/office-legacy.mjs";
63
64
  import { LEGACY_SERVER_ID, finalMatcher } from "../lib/mcp-rename.mjs";
@@ -118,7 +119,7 @@ export const INSTALL_MANIFEST = ".pipeline-manifest.json";
118
119
 
119
120
  const flags = process.argv.slice(2).filter((a) => a !== "uninstall");
120
121
 
121
- const TOOL_FLAGS = ["--claude", "--copilot", "--codex"];
122
+ const TOOL_FLAGS = HOST_IDS.map((id) => hostEntry(id).install.flag);
122
123
 
123
124
  // Flags of adapters the installer no longer has, and any other flag this
124
125
  // script does not know, are refused rather than ignored: an unrecognised flag
@@ -142,6 +143,9 @@ const explicitlyTargeted = flags.some((f) => TOOL_FLAGS.includes(f)) || flags.in
142
143
  const forClaude = flags.includes("--claude") || flags.includes("--all") || !explicitlyTargeted;
143
144
  const forCopilot = flags.includes("--copilot") || flags.includes("--all") || !explicitlyTargeted;
144
145
  const forCodex = flags.includes("--codex") || flags.includes("--all") || !explicitlyTargeted;
146
+ // The local host is the Codex engine in a tree of its own, so it is removed
147
+ // like Codex but never together with it: a user who keeps one keeps the other.
148
+ const forLocal = flags.includes("--local") || flags.includes("--all") || !explicitlyTargeted;
145
149
 
146
150
  const dryRun = flags.includes("--dry-run");
147
151
  const skipPrompt = flags.includes("--yes") || flags.includes("-y");
@@ -231,23 +235,43 @@ function rmDirExcept(dir, keep) {
231
235
  }
232
236
 
233
237
  /**
234
- * Full cleanup removes the settings file, but not the map that names the tokens.
238
+ * Full cleanup removes the settings file, but not what names the tokens.
235
239
  *
236
- * `global.keychainMapping` is logical-name -> credential-store key. It holds no
237
- * secret, and without it the preserved tokens become unfindable: they sit in the
238
- * OS store under names the user never chose and now has no record of. Deleting
239
- * it while promising "tokens are preserved" makes that promise hollow.
240
+ * These five keys hold no secret, and without them the preserved tokens become
241
+ * unfindable or unusable: the items sit in the OS store under names the user
242
+ * never chose, and nothing records which host each one belongs to. Deleting
243
+ * them while promising "tokens are preserved" makes that promise hollow.
244
+ *
245
+ * `serviceAccounts` is the one that pairs a secret with its host, so dropping
246
+ * it on a machine with two accounts of one service loses the only record of
247
+ * which token is which - the person would reinstall and be asked to tell the
248
+ * difference again. `hosts` and `credentialHosts` are the flat projection of
249
+ * the same thing, and `serviceOptOuts` is the person's answer to a question
250
+ * setup would otherwise ask them a second time.
240
251
  *
241
252
  * Everything else in the file goes. An absent or unparseable file is not an
242
253
  * uninstall failure - it is removed as before.
243
254
  * @param {string} prefsPath
244
255
  */
256
+ const PRESERVED_CREDENTIAL_KEYS = [
257
+ "keychainMapping",
258
+ "serviceAccounts",
259
+ "serviceOptOuts",
260
+ "hosts",
261
+ "credentialHosts",
262
+ ];
263
+
245
264
  function preservePrefsCredentialMapping(prefsPath) {
246
265
  if (!existsSync(prefsPath)) return;
247
266
  let mapping;
267
+ const kept = {};
248
268
  try {
249
269
  const prefs = JSON.parse(readFileSync(prefsPath, "utf-8"));
250
270
  mapping = prefs?.global?.keychainMapping;
271
+ for (const key of PRESERVED_CREDENTIAL_KEYS) {
272
+ const value = prefs?.global?.[key];
273
+ if (value != null) kept[key] = value;
274
+ }
251
275
  } catch {
252
276
  /* unreadable: nothing to rescue, fall through to a plain removal */
253
277
  }
@@ -258,17 +282,15 @@ function preservePrefsCredentialMapping(prefsPath) {
258
282
  if (dryRun) {
259
283
  report(
260
284
  "would reduce",
261
- `${prefsPath} to global.keychainMapping (${Object.keys(mapping).length} keys)`,
285
+ `${prefsPath} to ${Object.keys(kept).join(", ")} (${Object.keys(mapping).length} mapped keys)`,
262
286
  );
263
287
  return;
264
288
  }
265
- writeFileSync(
266
- prefsPath,
267
- JSON.stringify({ global: { keychainMapping: mapping } }, null, 2) + "\n",
268
- );
289
+ writeFileSync(prefsPath, JSON.stringify({ global: kept }, null, 2) + "\n");
269
290
  console.log(
270
- ` kept: ${prefsPath} reduced to global.keychainMapping (${Object.keys(mapping).length} keys) - ` +
271
- "the preserved tokens stay findable",
291
+ ` kept: ${prefsPath} reduced to ${Object.keys(kept).join(", ")} ` +
292
+ `(${Object.keys(mapping).length} mapped keys) - the preserved tokens stay findable, ` +
293
+ "and so does which host each one belongs to",
272
294
  );
273
295
  }
274
296
 
@@ -532,11 +554,16 @@ export function retiredRegistrations(isRegistered) {
532
554
  * @param {string[]} [scopeArgs]
533
555
  * @param {{dry?: boolean}} [opts]
534
556
  */
535
- export function deregisterMcpServer(host, cliPath, scopeArgs = [], { dry = dryRun } = {}) {
557
+ export function deregisterMcpServer(
558
+ host,
559
+ cliPath,
560
+ scopeArgs = [],
561
+ { dry = dryRun, env = process.env } = {},
562
+ ) {
536
563
  const cli = cliPath || host;
537
564
  const isRegistered = (name) => {
538
565
  try {
539
- execFileSync(cli, ["mcp", "get", name], { stdio: "pipe", timeout: 20_000 });
566
+ execFileSync(cli, ["mcp", "get", name], { stdio: "pipe", timeout: 20_000, env });
540
567
  return true;
541
568
  } catch {
542
569
  return false;
@@ -559,6 +586,7 @@ export function deregisterMcpServer(host, cliPath, scopeArgs = [], { dry = dryRu
559
586
  execFileSync(cli, ["mcp", "remove", ...scopeArgs, name], {
560
587
  stdio: "pipe",
561
588
  timeout: 20_000,
589
+ env,
562
590
  });
563
591
  console.log(` removed: ${name} MCP registration (${host})`);
564
592
  } catch {
@@ -568,8 +596,70 @@ export function deregisterMcpServer(host, cliPath, scopeArgs = [], { dry = dryRu
568
596
  report("kept", `${MCP_PRESERVED} MCP registration (${host}) - usable without the pipeline`);
569
597
  }
570
598
 
571
- function deregisterCodexMcpServer() {
572
- deregisterMcpServer("codex");
599
+ /**
600
+ * Remove a Codex-engine host's tree. Both the Codex CLI host and the local-model
601
+ * host install the same shape under a root of their own, so the removal is one
602
+ * body with two roots rather than two copies that drift apart.
603
+ *
604
+ * @param {object} opts
605
+ * @param {string} opts.label - host label for the console lines
606
+ * @param {string} opts.root - that host's directory
607
+ * @param {string[]} opts.hooksCommands - shipped hook commands to match
608
+ * @param {string[]} opts.extraHooksHomes - other homes a hooks.json may sit in
609
+ * @param {boolean} opts.deregister - whether the host had a stamp to read
610
+ * @param {string|null} opts.codexHome - CODEX_HOME the MCP entry was written under
611
+ */
612
+ function removeCodexTree({ label, root, hooksCommands, extraHooksHomes, deregister, codexHome }) {
613
+ const removing = dryRun ? "Would remove" : "Removing";
614
+ console.log("");
615
+ console.log(` [${label}] ${removing} from ${root.replace(homedir(), "~")}...`);
616
+
617
+ // Codex reads hooks from $CODEX_HOME when set, so host-hooks.mjs may have
618
+ // registered outside this root as well. The template was read by the caller,
619
+ // before any block removed one.
620
+ const hooksFiles = new Set([join(root, "hooks.json")]);
621
+ for (const home of extraHooksHomes) hooksFiles.add(join(home, "hooks.json"));
622
+ for (const hooksFile of hooksFiles) cleanCodexHooks(hooksFile, hooksCommands);
623
+
624
+ // Wholly pipeline-owned trees.
625
+ rmIfExists(join(root, "multi-agent-refs"));
626
+ rmIfExists(join(root, "scripts"));
627
+ rmDirExcept(join(root, "lib"), KEEP_IN_LIB);
628
+ rmIfExists(join(root, "schemas"));
629
+ rmIfExists(join(root, "office"));
630
+ rmIfExists(join(root, "rules"));
631
+ rmIfExists(join(root, ".pipeline-version"));
632
+ rmMatchingFiles(join(root, "templates"), (name) => PIPELINE_TEMPLATE_FILES.includes(name));
633
+ rmdirIfEmpty(join(root, "templates"));
634
+
635
+ // Co-owned dirs: remove only what the pipeline wrote. `skills/` holds
636
+ // Codex's own `.system` set plus user skills; `prompts/` and `agents/` hold
637
+ // user-authored files.
638
+ const skills = join(root, "skills");
639
+ let n = rmMatchingDirs(
640
+ skills,
641
+ (name) => name === "multi-agent" || name.startsWith("multi-agent-"),
642
+ );
643
+ n += rmPluginDeliveredSkills(skills);
644
+ if (n > 0) console.log(` removed ${n} skill dir(s) under ${skills}`);
645
+ rmIfExists(join(root, "prompts", "multi-agent.md"));
646
+ removeCodexCommandPrompts(join(root, "prompts"));
647
+ removeGeneratedCodexAgents(join(root, "agents"));
648
+
649
+ stripManagedBlock(join(root, "AGENTS.md"), { hostFile: true });
650
+
651
+ // The MCP entry was written by `codex mcp add`, so hand it back the same
652
+ // way rather than editing config.toml - Codex also stores marketplace and
653
+ // plugin state in that file.
654
+ if (deregister) deregisterCodexMcpServer(codexHome);
655
+ }
656
+
657
+ function deregisterCodexMcpServer(codexHome) {
658
+ // The installer registers the local host's server with CODEX_HOME pointing at
659
+ // that host's own tree, so the removal has to name the same home or it reads
660
+ // the default one and finds nothing.
661
+ const env = codexHome ? { ...process.env, CODEX_HOME: codexHome } : process.env;
662
+ deregisterMcpServer("codex", undefined, [], { env });
573
663
  }
574
664
 
575
665
  /**
@@ -1101,7 +1191,7 @@ export async function main() {
1101
1191
  if (retiredGiven.length > 0) {
1102
1192
  console.error(
1103
1193
  ` ${retiredGiven.join(", ")}: no longer supported; nothing was removed.\n` +
1104
- " Name a host with --claude, --copilot or --codex, or pass none for all of them.",
1194
+ ` Name a host with ${TOOL_FLAGS.join(", ")}, or pass none for all of them.`,
1105
1195
  );
1106
1196
  process.exit(2);
1107
1197
  }
@@ -1131,6 +1221,10 @@ export async function main() {
1131
1221
  console.log(
1132
1222
  " - Codex CLI (~/.codex: skills/multi-agent, multi-agent-refs, agents/*.toml, prompts/multi-agent.md and the user-only command prompts, scripts, lib except the credential reader, schemas, rules, AGENTS.md block, the retired dev-toolkit MCP entry; the multi-agent MCP entry is KEPT)",
1133
1223
  );
1224
+ if (forLocal)
1225
+ console.log(
1226
+ ` - ${hostEntry("local").label} (~/${hostEntry("local").install.root}: the same tree, which the pipeline owns whole)`,
1227
+ );
1134
1228
  console.log("");
1135
1229
  if (allData) {
1136
1230
  console.log(" FULL CLEANUP (--all-data) also removes:");
@@ -1161,7 +1255,17 @@ export async function main() {
1161
1255
  // Read before any stamp is removed: the Codex MCP entry is deregistered last.
1162
1256
  const copilotInstalled = hostInstalled(".copilot");
1163
1257
  const codexInstalled = hostInstalled(".codex");
1258
+ const LOCAL = hostEntry("local");
1259
+ const LOCAL_ROOT = LOCAL.install.root;
1260
+ const localInstalled = hostInstalled(LOCAL_ROOT);
1164
1261
  const removing = dryRun ? "Would remove" : "Removing";
1262
+ // Read before ANY block removes a templates file. The lookup falls back to the
1263
+ // tree this script is running from, so a Copilot-tree uninstall that deletes
1264
+ // its own copy first would leave the Codex hooks unmatched and the entries in
1265
+ // place, pointing at scripts the same run removed.
1266
+ const codexHooks = shippedHookCommands("codex-hooks.json", [
1267
+ join(HOME ?? "", ".codex", "templates"),
1268
+ ]);
1165
1269
 
1166
1270
  console.log("");
1167
1271
  console.log(" [Office]");
@@ -1244,9 +1348,14 @@ export async function main() {
1244
1348
  const COP = join(HOME, ".copilot");
1245
1349
  rmIfExists(join(COP, "scripts"));
1246
1350
  // Pipeline-managed trees the installer lays down alongside scripts/.
1351
+ rmIfExists(join(COP, "multi-agent-refs"));
1247
1352
  rmIfExists(join(COP, "schemas"));
1248
1353
  rmIfExists(join(COP, "office"));
1249
1354
  rmDirExcept(join(COP, "lib"), KEEP_IN_LIB);
1355
+ // templates/ is installed on every host, so it has to be removed on every
1356
+ // host. By shipped name, not wholesale: the directory is the host's.
1357
+ rmMatchingFiles(join(COP, "templates"), (name) => PIPELINE_TEMPLATE_FILES.includes(name));
1358
+ rmdirIfEmpty(join(COP, "templates"));
1250
1359
  rmIfExists(join(COP, ".pipeline-version"));
1251
1360
  const skills = join(COP, "skills");
1252
1361
  let n = rmMatchingDirs(
@@ -1308,46 +1417,25 @@ export async function main() {
1308
1417
  }
1309
1418
 
1310
1419
  if (forCodex && HOME) {
1311
- console.log("");
1312
- console.log(` [Codex CLI] ${removing} from ~/.codex...`);
1313
- const CODEX = join(HOME, ".codex");
1314
-
1315
- // Codex reads hooks from $CODEX_HOME when set, so host-hooks.mjs may have
1316
- // registered there as well as in ~/.codex.
1317
- const codexHooks = shippedHookCommands("codex-hooks.json", [join(CODEX, "templates")]);
1318
- const hooksFiles = new Set([join(CODEX, "hooks.json")]);
1319
- if (process.env.CODEX_HOME) hooksFiles.add(join(process.env.CODEX_HOME, "hooks.json"));
1320
- for (const hooksFile of hooksFiles) cleanCodexHooks(hooksFile, codexHooks);
1321
-
1322
- // Wholly pipeline-owned trees.
1323
- rmIfExists(join(CODEX, "multi-agent-refs"));
1324
- rmIfExists(join(CODEX, "scripts"));
1325
- rmDirExcept(join(CODEX, "lib"), KEEP_IN_LIB);
1326
- rmIfExists(join(CODEX, "schemas"));
1327
- rmIfExists(join(CODEX, "office"));
1328
- rmIfExists(join(CODEX, "rules"));
1329
- rmIfExists(join(CODEX, ".pipeline-version"));
1330
-
1331
- // Co-owned dirs: remove only what the pipeline wrote. `skills/` holds
1332
- // Codex's own `.system` set plus user skills; `prompts/` and `agents/` hold
1333
- // user-authored files.
1334
- const skills = join(CODEX, "skills");
1335
- let n = rmMatchingDirs(
1336
- skills,
1337
- (name) => name === "multi-agent" || name.startsWith("multi-agent-"),
1338
- );
1339
- n += rmPluginDeliveredSkills(skills);
1340
- if (n > 0) console.log(` removed ${n} skill dir(s) under ${skills}`);
1341
- rmIfExists(join(CODEX, "prompts", "multi-agent.md"));
1342
- removeCodexCommandPrompts(join(CODEX, "prompts"));
1343
- removeGeneratedCodexAgents(join(CODEX, "agents"));
1344
-
1345
- stripManagedBlock(join(CODEX, "AGENTS.md"), { hostFile: true });
1420
+ removeCodexTree({
1421
+ label: "Codex CLI",
1422
+ root: join(HOME, ".codex"),
1423
+ hooksCommands: codexHooks,
1424
+ extraHooksHomes: process.env.CODEX_HOME ? [process.env.CODEX_HOME] : [],
1425
+ deregister: codexInstalled,
1426
+ codexHome: null,
1427
+ });
1428
+ }
1346
1429
 
1347
- // The MCP entry was written by `codex mcp add`, so hand it back the same
1348
- // way rather than editing config.toml - Codex also stores marketplace and
1349
- // plugin state in that file.
1350
- if (codexInstalled) deregisterCodexMcpServer();
1430
+ if (forLocal && HOME) {
1431
+ removeCodexTree({
1432
+ label: LOCAL.label,
1433
+ root: join(HOME, LOCAL_ROOT),
1434
+ hooksCommands: codexHooks,
1435
+ extraHooksHomes: [],
1436
+ deregister: localInstalled,
1437
+ codexHome: join(HOME, LOCAL_ROOT),
1438
+ });
1351
1439
  }
1352
1440
 
1353
1441
  console.log("");
@@ -124,7 +124,8 @@ import {
124
124
  transportReason,
125
125
  } from "./usage-register-beacon.mjs";
126
126
  import { PREFS_ENV, prefsFileIn } from "../lib/prefs-value.mjs";
127
- import { credentialStores } from "../lib/usage-token.mjs";
127
+ import { credentialStores, usagePrefs } from "../lib/usage-token.mjs";
128
+ import { itemNames, resolveSecret } from "../lib/service-account.mjs";
128
129
  import { exitOnHelp } from "../lib/cli-help.mjs";
129
130
  import { hostDigest, loadRunKey } from "../lib/usage-run-key.mjs";
130
131
  import { versionOrUnknown } from "../lib/usage-vocab.mjs";
@@ -232,13 +233,35 @@ export function registerUrl(endpoint) {
232
233
  return ep.endsWith("/ingest") ? `${ep.slice(0, -"/ingest".length)}/register` : `${ep}/register`;
233
234
  }
234
235
 
235
- function storedToken(prefs, stores) {
236
- const name = prefs?.global?.keychainMapping?.usage_ingest;
237
- if (!name) return null;
236
+ /**
237
+ * The store item the usage account names, or null.
238
+ *
239
+ * A name, never a value: the resolver reads the accounts the preferences
240
+ * describe, so a file written before accounts existed answers the same as one
241
+ * written after.
242
+ */
243
+ function usageEntryName(prefs) {
244
+ const named = itemNames(prefs).find((x) => x.service === "usage_ingest" && x.slot === "token");
245
+ return named?.item ?? null;
246
+ }
247
+
248
+ /**
249
+ * The token already in the store, for the destination it is about to reach.
250
+ *
251
+ * The account resolver decides which usage account answers and whether it
252
+ * covers `url`; a destination it does not cover produces nothing rather than
253
+ * the token this machine happens to hold. Each installed host's store is asked
254
+ * in turn, as a read of the same account.
255
+ */
256
+ function storedToken(prefs, stores, url) {
257
+ const request = { service: "usage_ingest", url };
258
+ const resolverPrefs = usagePrefs(prefs?.global);
238
259
  for (const store of stores) {
239
- const r = spawnSync("bash", [store, "get", name], { encoding: "utf8", timeout: 8000 });
240
- const out = (r.stdout || "").trim();
241
- if (out) return out;
260
+ const answer = resolveSecret(request, {
261
+ prefs: resolverPrefs,
262
+ env: { ...process.env, CRED_STORE: store },
263
+ });
264
+ if (answer.ok && answer.secret.trim()) return answer.secret.trim();
242
265
  }
243
266
  return null;
244
267
  }
@@ -1046,8 +1069,8 @@ export async function register(argv, { ingestRejected = false } = {}) {
1046
1069
  pre.reason,
1047
1070
  );
1048
1071
  // The stored token stays in memory and is sent only in the check's header.
1049
- const stored = identityMatters ? storedToken(prefs, stores) : null;
1050
1072
  const checkAt = registerUrl(prefs.global?.usageLog?.endpoint);
1073
+ const stored = identityMatters ? storedToken(prefs, stores, checkAt) : null;
1051
1074
  if (
1052
1075
  stored &&
1053
1076
  !opts.dryRun &&
@@ -1110,7 +1133,7 @@ export async function register(argv, { ingestRejected = false } = {}) {
1110
1133
  // machine keeps it off: a feedback run reaches this point for the token
1111
1134
  // alone, and optOut covers passive collection.
1112
1135
  if (current.global?.usageLog?.enabled !== true && !opts.dryRun) {
1113
- const name = current.global?.keychainMapping?.usage_ingest || null;
1136
+ const name = usageEntryName(current);
1114
1137
  if (persistPrefs(prefsPath, name)) {
1115
1138
  say(" -> operational reporting: enabled (a token was already onboarded)");
1116
1139
  sendInstalledVersion(prefsPath);
@@ -1217,9 +1240,9 @@ export async function register(argv, { ingestRejected = false } = {}) {
1217
1240
 
1218
1241
  const optedOut = prefs.global?.usageLog?.optOut === true;
1219
1242
  // A rejected token is overwritten in its own entry rather than left beside a new one.
1220
- const mapped = current.global?.keychainMapping?.usage_ingest;
1243
+ const mapped = usageEntryName(current);
1221
1244
  const entry =
1222
- rejected && typeof mapped === "string" && /^[A-Za-z0-9._-]{1,128}$/.test(mapped)
1245
+ rejected && mapped && /^[A-Za-z0-9._-]{1,128}$/.test(mapped)
1223
1246
  ? mapped
1224
1247
  : `${process.env.USER || user}_Usage_Ingest_Token`;
1225
1248
  const set = stores.length
@@ -51,7 +51,6 @@ import { DEFAULT_ENDPOINT, canonicalEndpoint, registerUrlAllowed } from "../lib/
51
51
  import { homedir, platform } from "os";
52
52
  import { dirname, join } from "path";
53
53
  import { fileURLToPath, pathToFileURL } from "url";
54
- import { execFileSync } from "child_process";
55
54
  import { randomBytes } from "crypto";
56
55
  import { costUsd } from "./_cost.mjs";
57
56
  import { defaultPrefsPath, identityHidden, resolveReportingLogin } from "./usage-identity.mjs";
@@ -59,6 +58,7 @@ import { installedVersion, lifecycleEvent } from "../lib/usage-lifecycle.mjs";
59
58
  import { lockTimeoutFrom, updateJsonFileSync } from "../lib/json-file-lock.mjs";
60
59
  import { ALWAYS_ON, KNOWN_STACKS, STACK_PLUGIN_ALIAS } from "./_stack-routing.mjs";
61
60
  import { exitOnHelp } from "../lib/cli-help.mjs";
61
+ import { resolveSecret } from "../lib/service-account.mjs";
62
62
  import { detachSelf, shouldDetach } from "../lib/detach-self.mjs";
63
63
  import { isPublicMcpServer, publicServerName } from "../lib/public-mcp-servers.mjs";
64
64
  import { MCP_SERVER_ID } from "../lib/mcp-rename.mjs";
@@ -227,32 +227,22 @@ function resolvePrefs() {
227
227
 
228
228
  /**
229
229
  * Resolve the ingest token without ever storing it in a synced file.
230
- * Order: env, then prefs.usageLog.token, then the Keychain entry mapped by
231
- * prefs.global.keychainMapping.usage_ingest (via credential-store.sh). This
232
- * lets update flip usageLog.enabled on while the secret stays in the Keychain.
230
+ *
231
+ * Order: env, then prefs.usageLog.token, then the account resolver, which
232
+ * reads the store only for the endpoint this report is actually being sent
233
+ * to. That last step is the change: before it, the token was read whatever
234
+ * the endpoint was, so an endpoint edited in the preferences file carried the
235
+ * same token to somewhere else entirely.
233
236
  */
234
237
  function resolveToken() {
235
238
  if (process.env.MULTI_AGENT_USAGE_TOKEN) return process.env.MULTI_AGENT_USAGE_TOKEN;
236
239
  const g = resolveGlobalPrefs();
237
240
  const inline = g.usageLog?.token;
238
241
  if (typeof inline === "string" && inline.trim()) return inline.trim();
239
- const name = g.keychainMapping?.usage_ingest;
240
- if (typeof name === "string" && name.trim()) {
241
- const store = hostFile("lib", "credential-store.sh");
242
- if (store) {
243
- try {
244
- const out = execFileSync("bash", [store, "get", name.trim()], {
245
- encoding: "utf-8",
246
- timeout: 4000,
247
- stdio: ["ignore", "pipe", "ignore"],
248
- }).trim();
249
- if (out) return out;
250
- } catch {
251
- /* keychain unavailable - stay silent */
252
- }
253
- }
254
- }
255
- return "";
242
+ const endpoint = g.usageLog?.endpoint;
243
+ if (typeof endpoint !== "string" || !endpoint.trim()) return "";
244
+ const answer = resolveSecret({ service: "usage_ingest", url: endpoint.trim() });
245
+ return answer.ok ? answer.secret.trim() : "";
256
246
  }
257
247
 
258
248
  // A plugin key mapped to `false` is de-selected (e.g. /multi-agent:stack writes
@@ -658,14 +648,25 @@ function commandName(state) {
658
648
  * invoked command when it names a mode, an explicit state.mode, the autopilot
659
649
  * flag (the mode phases.json marks autopilot: true), then "full", which is
660
650
  * what an absent mode means in agent-state.schema.json.
651
+ *
652
+ * A run that carries the autopilot flag resolves to the unattended variant of
653
+ * whatever mode it is in, when the contract declares one: `/multi-agent:analysis
654
+ * <ref> autopilot` is `analysis-autopilot`, not the attended `analysis` it would
655
+ * otherwise read as. The panel's whole question about a mode is what it cost
656
+ * and how it ended, and those differ between the two.
661
657
  */
662
658
  export function modeOf(state, modes = allowedModes()) {
663
659
  const names = Object.keys(modes);
664
660
  const has = (n) => typeof n === "string" && names.includes(n);
661
+ const unattended = (n) => {
662
+ if (!state.autopilot || modes[n]?.autopilot === true) return n;
663
+ const variant = names.find((v) => v === `${n}-autopilot` && modes[v]?.autopilot === true);
664
+ return variant || n;
665
+ };
665
666
  const cmd = commandName(state);
666
- if (has(cmd)) return cmd;
667
+ if (has(cmd)) return unattended(cmd);
667
668
  if (typeof state.mode === "string" && state.mode.trim()) {
668
- return has(state.mode.trim()) ? state.mode.trim() : "unknown";
669
+ return has(state.mode.trim()) ? unattended(state.mode.trim()) : "unknown";
669
670
  }
670
671
  if (state.autopilot === true) {
671
672
  const ap = names.find((n) => modes[n]?.autopilot === true);
@@ -1363,9 +1364,13 @@ async function selfHeal(rejectedToken) {
1363
1364
  * The login to name a run after. A context that cannot see this machine's
1364
1365
  * accounts (usage-identity.mjs `hidden`) falls back to the login an earlier
1365
1366
  * check cached; the server names the record after the token's login anyway.
1367
+ *
1368
+ * `write: false` resolves without caching the answer in preferences. A dry run
1369
+ * passes it: the environment it resolves under is its caller's, not the one a
1370
+ * real send would use, so remembering its verdict would decide the next run.
1366
1371
  */
1367
- function reportingLogin(prefs) {
1368
- const who = registeredLogin(prefs) ?? resolveReportingLogin();
1372
+ function reportingLogin(prefs, { write = true } = {}) {
1373
+ const who = registeredLogin(prefs) ?? resolveReportingLogin({ write });
1369
1374
  if (who.login || !who.hidden) return who;
1370
1375
  const cached = typeof prefs?.login === "string" ? prefs.login.trim() : "";
1371
1376
  return /^[A-Za-z0-9][A-Za-z0-9_-]{0,38}$/.test(cached) ? { ...who, login: cached } : who;
@@ -1449,7 +1454,7 @@ async function main() {
1449
1454
  if (args.status) state.status = args.status;
1450
1455
  const kind = EVENT_KINDS.includes(args.event) ? args.event : null;
1451
1456
 
1452
- const who = reportingLogin(prefs);
1457
+ const who = reportingLogin(prefs, { write: !args.dryRun });
1453
1458
  if (!who.login) {
1454
1459
  process.stderr.write(`usage-report: not sent - ${who.reason}\n`);
1455
1460
  if (!args.dryRun) {
@@ -43,7 +43,17 @@ await import("../lib/cli-help.mjs").then(
43
43
  () => {},
44
44
  );
45
45
 
46
- const ALLOWED_REVIEWERS = new Set(["fable", "opus", "sonnet", "gpt"]);
46
+ // The same families anonymize-findings writes back, derived from the host
47
+ // registry rather than listed twice. This script also runs copied on its own,
48
+ // without lib/ beside it, so the import is optional the way --help is: there
49
+ // the hand-written floor applies and no reviewer value is rejected for being
50
+ // newer than this copy.
51
+ const ALLOWED_REVIEWERS = new Set(
52
+ await import("../lib/reviewer-families.mjs").then(
53
+ (m) => m.FAMILIES,
54
+ () => ["fable", "opus", "sonnet", "gpt", "local"],
55
+ ),
56
+ );
47
57
  const FOUND_BY_RE = /^(Source [A-Z]|security-auditor)$/;
48
58
  const ANONYMIZED = process.argv.includes("--anonymized");
49
59
  const ALLOWED_SEVERITIES = new Set(["blocking", "important", "suggestion"]);