@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
@@ -14,11 +14,12 @@
14
14
  // anyone can install off npm. A person can paste the one line they think
15
15
  // matters; a script cannot know which line that is.
16
16
  //
17
- // Auth reuses the usage ingest token (`prefs.global.keychainMapping.usage_ingest`)
18
- // so nothing new has to be onboarded. Unlike usage telemetry, `optOut` does NOT
19
- // silence this: telemetry is passive collection, feedback is a deliberate act by
20
- // the person running the command, and silently dropping something a user chose
21
- // to send is worse than not offering the command.
17
+ // Auth reuses the usage ingest token this machine already registered, resolved
18
+ // through lib/usage-token.mjs for this endpoint and no other, so nothing new
19
+ // has to be onboarded. Unlike usage telemetry, `optOut` does NOT silence this:
20
+ // telemetry is passive collection, feedback is a deliberate act by the person
21
+ // running the command, and silently dropping something a user chose to send is
22
+ // worse than not offering the command.
22
23
  //
23
24
  // Usage:
24
25
  // node feedback-send.mjs --text "<message>" [--kind bug|idea|question]
@@ -78,8 +79,10 @@ function host() {
78
79
  return "unknown";
79
80
  }
80
81
 
81
- function resolveToken() {
82
- return resolveUsageToken(readPrefs());
82
+ // The endpoint is passed in because it is the destination the token is about to
83
+ // reach: a usage account that does not cover it hands nothing out.
84
+ function resolveToken(endpoint) {
85
+ return resolveUsageToken(readPrefs(), { endpoint });
83
86
  }
84
87
 
85
88
  async function main() {
@@ -121,7 +124,7 @@ async function main() {
121
124
  process.exit(1);
122
125
  }
123
126
 
124
- const token = resolveToken();
127
+ const token = resolveToken(endpoint);
125
128
  if (!token) {
126
129
  process.stderr.write(
127
130
  `ERROR: no ingest token. Run ${hostCommand("update", import.meta.dirname)} once (it registers one) or ${hostCommand("setup", import.meta.dirname)}.\n`,
@@ -13,7 +13,7 @@
13
13
  * skillCount a count of pipeline/skills/shared/external/<name>/SKILL.md
14
14
  * skillCountAll every SKILL.md under pipeline/skills, at any depth
15
15
  * agentCount a count of pipeline/agents/*.md
16
- * hosts the CLIs install/ has an adapter for
16
+ * hosts every host the registry declares, by label
17
17
  * toolCount the toolkit's own tools/list response, when reachable
18
18
  * toolCategories that same response, grouped by the prefix in each tool name
19
19
  * pluginSkillCount every SKILL.md in the plugin marketplace, when checked out,
@@ -43,6 +43,7 @@ import { fileURLToPath } from "node:url";
43
43
  import { spawnSync } from "node:child_process";
44
44
  import { siblingsParent } from "./_sibling-root.mjs";
45
45
  import { exitOnHelp } from "../lib/cli-help.mjs";
46
+ import { HOST_IDS, host } from "../lib/host.mjs";
46
47
  import { SERVER_CHECKOUT_DIRS } from "../lib/mcp-rename.mjs";
47
48
 
48
49
  exitOnHelp(import.meta.url);
@@ -233,14 +234,11 @@ const facts = {
233
234
  // Both are headline figures on the site; generated from pipeline/agents and
234
235
  // install/, so the sub-agent count and the host list follow what ships.
235
236
  agentCount: readdirSync(join(ROOT, "pipeline", "agents")).filter((f) => f.endsWith(".md")).length,
236
- hosts: readdirSync(join(ROOT, "install"))
237
- .filter((f) => f.endsWith(".mjs") && !f.startsWith("_") && f !== "index.mjs")
238
- .map(
239
- (f) =>
240
- ({ claude: "Claude Code", copilot: "Copilot CLI", codex: "Codex CLI" })[
241
- f.replace(".mjs", "")
242
- ],
243
- )
237
+ // From the host registry, not from the files in install/: a host whose
238
+ // installer is another host's (the local one runs the Codex installer) has
239
+ // no file of its own, and a list built from filenames leaves it out of every
240
+ // sentence that counts hosts.
241
+ hosts: HOST_IDS.map((id) => host(id).label)
244
242
  .filter(Boolean)
245
243
  .sort(),
246
244
  toolCount,
@@ -13,8 +13,10 @@
13
13
  # jira-attach.sh <issue-key> <file> [file...]
14
14
  #
15
15
  # Env:
16
- # JIRA_BASE https://host - else resolved from prefs hosts.jira
17
- # JIRA_TOKEN else resolved from prefs keychainMapping.jira
16
+ # JIRA_BASE https://host - names which account to use, when more than
17
+ # one is configured. Otherwise the account resolver picks.
18
+ # JIRA_TOKEN_KEY a store item name, when the account is to be named by item.
19
+ # JIRA_TOKEN a token for a run with no configured account.
18
20
  #
19
21
  # Output (stdout), one line per uploaded file:
20
22
  # <filename>\t<content-url>
@@ -30,32 +32,21 @@ shift 2>/dev/null || true
30
32
  exit 2
31
33
  }
32
34
 
33
- PREFS="$HOME/.claude/multi-agent-preferences.json"
34
-
35
35
  _MA_JA_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
36
36
  # shellcheck source=/dev/null
37
37
  if [ -f "$_MA_JA_HERE/../lib/user-facing.sh" ]; then . "$_MA_JA_HERE/../lib/user-facing.sh"; else . "$HOME/.claude/lib/user-facing.sh"; fi
38
+ # shellcheck source=/dev/null
39
+ if [ -f "$_MA_JA_HERE/../lib/_service-account.sh" ]; then . "$_MA_JA_HERE/../lib/_service-account.sh"; else . "$HOME/.claude/lib/_service-account.sh"; fi
38
40
 
39
- if [ -z "${JIRA_BASE:-}" ]; then
40
- JIRA_BASE=$(node -e '
41
- const fs=require("fs");
42
- try{const g=(JSON.parse(fs.readFileSync(process.argv[1],"utf8")).global||{});
43
- process.stdout.write((g.hosts||{}).jira||"")}catch{process.stdout.write("")}
44
- ' "$PREFS" 2>/dev/null)
45
- fi
46
- [ -n "$JIRA_BASE" ] || { echo "jira-attach: no Jira host (set JIRA_BASE or prefs hosts.jira)" >&2; exit 2; }
47
- case "$JIRA_BASE" in http*) ;; *) JIRA_BASE="https://$JIRA_BASE" ;; esac
41
+ SA_PICK=()
42
+ if [ -n "${JIRA_BASE:-}" ]; then SA_PICK+=(--host "$JIRA_BASE"); fi
43
+ if [ -n "${JIRA_TOKEN_KEY:-}" ]; then SA_PICK+=(--item "$JIRA_TOKEN_KEY"); fi
48
44
 
49
- if [ -z "${JIRA_TOKEN:-}" ]; then
50
- KEY=$(node -e '
51
- const fs=require("fs");
52
- try{const g=(JSON.parse(fs.readFileSync(process.argv[1],"utf8")).global||{});
53
- process.stdout.write((g.keychainMapping||{}).jira||"")}catch{process.stdout.write("")}
54
- ' "$PREFS" 2>/dev/null)
55
- [ -n "$KEY" ] || { echo "jira-attach: keychainMapping.jira is not set - onboard it via $(ma_command setup)" >&2; exit 2; }
56
- JIRA_TOKEN=$(bash "$HOME/.claude/lib/credential-store.sh" get "$KEY" 2>/dev/null)
57
- fi
58
- [ -n "${JIRA_TOKEN:-}" ] || { echo "jira-attach: no Jira token - onboard it via $(ma_command setup)" >&2; exit 2; }
45
+ JIRA_BASE="$(sa_base jira "${SA_PICK[@]+"${SA_PICK[@]}"}")" || {
46
+ echo "jira-attach: $(sa_explain)" >&2
47
+ exit 2
48
+ }
49
+ [ -n "$JIRA_BASE" ] || { echo "jira-attach: no Jira account - add one with $(ma_command setup)" >&2; exit 2; }
59
50
 
60
51
  RC=0
61
52
  for f in "$@"; do
@@ -64,12 +55,16 @@ for f in "$@"; do
64
55
  RC=3
65
56
  continue
66
57
  fi
67
- # The token never reaches argv: curl reads the header from a file descriptor.
68
- resp=$(curl -sS -X POST \
69
- -H @<(printf 'Authorization: Bearer %s\n' "$JIRA_TOKEN") \
58
+ # The config carries the URL as well as the credential, so the two cannot be
59
+ # separated: a redirect is refused rather than followed with the header on.
60
+ cfg=$(sa_cfg jira "$JIRA_BASE/rest/api/2/issue/$ISSUE/attachments" bearer \
61
+ "${SA_PICK[@]+"${SA_PICK[@]}"}") || {
62
+ echo "jira-attach: $(sa_explain)" >&2
63
+ exit 2
64
+ }
65
+ resp=$(curl -sS -X POST --config "$cfg" \
70
66
  -H "X-Atlassian-Token: no-check" \
71
- -F "file=@$f" \
72
- "$JIRA_BASE/rest/api/2/issue/$ISSUE/attachments" 2>/dev/null)
67
+ -F "file=@$f" 2>/dev/null)
73
68
  line=$(printf '%s' "$resp" | node -e '
74
69
  let b="";process.stdin.on("data",d=>b+=d).on("end",()=>{
75
70
  try{
@@ -34,32 +34,16 @@ while [ $# -gt 0 ]; do
34
34
  done
35
35
  [ -n "$JQL" ] || { echo "jira-search: --jql is required" >&2; exit 2; }
36
36
 
37
- PREFS="${MA_PREFS_FILE:-$HOME/.claude/multi-agent-preferences.json}"
38
- [ -f "$PREFS" ] || { echo "jira-search: no preferences file" >&2; exit 1; }
39
37
 
40
- # Host and the LOGICAL key name, never the literal Keychain service name: the
41
- # mapping is per-user and resolving it here is what keeps the service name out
42
- # of every synced file.
43
- eval "$(python3 - "$PREFS" <<'PY'
44
- import json, sys, shlex
45
- try:
46
- g = json.load(open(sys.argv[1]))["global"]
47
- except Exception:
48
- g = {}
49
- host = (g.get("hosts") or {}).get("jira", "")
50
- key = (g.get("keychainMapping") or {}).get("jira", "")
51
- print(f"ACCOUNT_JIRA_HOST={shlex.quote(host)}")
52
- print(f"ACCOUNT_JIRA_TOKEN_KEY={shlex.quote(key)}")
53
- PY
54
- )"
38
+ # Which Jira account answers, and where its credential lives, is the account
39
+ # resolver's question. ACCOUNT_JIRA_HOST and ACCOUNT_JIRA_TOKEN_KEY are still
40
+ # honoured when a caller sets them: they name an account rather than replacing
41
+ # the check that it may be sent to.
55
42
  export ACCOUNT_JIRA_HOST ACCOUNT_JIRA_TOKEN_KEY
56
- [ -n "$ACCOUNT_JIRA_HOST" ] && [ -n "$ACCOUNT_JIRA_TOKEN_KEY" ] || {
57
- echo "jira-search: jira is not onboarded (host or keychainMapping.jira missing)" >&2
58
- exit 1
59
- }
60
43
 
61
44
  HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
62
45
  for cand in "$HERE/../lib/issue-fetcher.sh" "$HOME/.claude/lib/issue-fetcher.sh"; do
46
+ # shellcheck source=/dev/null
63
47
  [ -f "$cand" ] && { . "$cand"; break; }
64
48
  done
65
49
  command -v jira_search >/dev/null 2>&1 || {
@@ -36,8 +36,8 @@
36
36
  *
37
37
  * - a structured reference: a Jira key, a GitHub issue URL
38
38
  * (https://github.com/<owner>/<repo>/issues/<n>), repo#N, #N, or a Jira
39
- * URL on the configured Jira host (prefs global.hosts.jira). It reaches
40
- * the prompt as it is;
39
+ * URL on the host this machine's Jira account names. It reaches the
40
+ * prompt as it is;
41
41
  * - free text (the bearer route, the CLI, and a request file Phase 0
42
42
  * reads): one line of at most FREE_TEXT_MAX printable
43
43
  * characters, no quote, backslash or backtick, reaching the prompt as one
@@ -109,7 +109,8 @@ import { lockTimeoutFrom, updateJsonFileSync } from "../lib/json-file-lock.mjs";
109
109
  import { unattendedSettingsPath } from "../lib/unattended-settings-location.mjs";
110
110
  import { isUnattended } from "../lib/unattended.mjs";
111
111
  import { listRuns, logsRoot } from "./_run-paths.mjs";
112
- import { loadGlobalPrefs, prefsPath } from "../lib/prefs-value.mjs";
112
+ import { prefsPath, readPrefsFile } from "../lib/prefs-value.mjs";
113
+ import { selectAccount } from "../lib/service-account.mjs";
113
114
  import { exitOnHelp } from "../lib/cli-help.mjs";
114
115
 
115
116
  exitOnHelp(import.meta.url);
@@ -173,14 +174,19 @@ const normalizeHost = (h) =>
173
174
  .replace(/:.*$/, "")
174
175
  .replace(/\.$/, "");
175
176
 
176
- /** The configured Jira host from prefs, normalized, or "" when there is none. */
177
+ /**
178
+ * The host of this machine's Jira account, or "" when no account answers.
179
+ *
180
+ * A Jira URL is a structured reference only on that host; anything else is
181
+ * free text. The account resolver decides, so a machine with two Jira
182
+ * instances is asked rather than guessed at, and a file that names no account
183
+ * makes every Jira URL free text instead of a reference to a host nobody
184
+ * configured.
185
+ */
177
186
  export function configuredJiraHost(env = process.env) {
178
187
  const file = prefsPath(env, { envVar: "MA_PREFS_FILE" });
179
- try {
180
- return normalizeHost(loadGlobalPrefs(file)?.hosts?.jira);
181
- } catch {
182
- return "";
183
- }
188
+ const chosen = selectAccount({ service: "jira" }, { env, prefs: readPrefsFile(file).prefs });
189
+ return chosen.ok ? (chosen.account.hosts[0] ?? "") : "";
184
190
  }
185
191
 
186
192
  /** The words the dispatcher's routing table routes on: the first word of each row's pattern. */
@@ -19,6 +19,7 @@ import { canonicalEndpoint } from "../lib/usage-endpoint.mjs";
19
19
  import { lockTimeoutFrom, withFileLockSync, writeJsonAtomicSync } from "../lib/json-file-lock.mjs";
20
20
  import { prefsFileIn } from "../lib/prefs-value.mjs";
21
21
  import { migrateServerPrefs } from "../lib/mcp-rename.mjs";
22
+ import { effectiveAccounts, projectLegacy, reconcileAccounts } from "../lib/service-account.mjs";
22
23
  import { ArgsError, parseArgs as parseArgv } from "../lib/args.mjs";
23
24
 
24
25
  const DEFAULT_FILE = prefsFileIn(os.homedir());
@@ -227,6 +228,55 @@ function defaultTriageCrossCheck() {
227
228
  return { enabled: false, samplePct: 10, model: "sonnet", blockOnDisagreement: false };
228
229
  }
229
230
 
231
+ /**
232
+ * Derive `serviceAccounts[]` from the flat credential keys.
233
+ *
234
+ * What it will not do is guess. Where the file holds one token and one host for
235
+ * a service, that pair is the only one the data allows and it is written. Where
236
+ * it holds more of either and nothing says which goes with which, the entry is
237
+ * written with `unresolved` instead of a host, which the resolver refuses and
238
+ * setup asks a person about. A token sent to a host nobody paired it with is
239
+ * the failure this whole change exists to prevent, so the migration may not
240
+ * introduce one.
241
+ *
242
+ * Idempotent: a second run reconciles its own output and finds nothing to say.
243
+ */
244
+ function buildServiceAccounts(out, changes) {
245
+ const g = out.global;
246
+ const before = JSON.stringify(g.serviceAccounts ?? null);
247
+ const { accounts, notes } = reconcileAccounts(out);
248
+ if (JSON.stringify(accounts) !== before) {
249
+ g.serviceAccounts = accounts;
250
+ const unpaired = accounts.filter((a) => a.unresolved).length;
251
+ changes.push(
252
+ `serviceAccounts: ${accounts.length} account(s) derived from keychainMapping and hosts` +
253
+ (unpaired ? `, ${unpaired} waiting for a host` : ""),
254
+ );
255
+ for (const note of notes) changes.push(`serviceAccounts: ${note}`);
256
+ }
257
+ if (!Array.isArray(g.serviceOptOuts)) {
258
+ g.serviceOptOuts = [];
259
+ changes.push("added empty serviceOptOuts");
260
+ }
261
+ // identities[] is deliberately left byte-identical. An identity id is derived
262
+ // from the name on every read, so an account can point at one without the
263
+ // file carrying it; it is persisted the first time a person adds an account
264
+ // through setup, which is a write they asked for. Renaming an identity before
265
+ // that happens orphans the link, and the resolver says so and refuses rather
266
+ // than quietly binding the account to whoever now answers to that name.
267
+ // The flat keys stay the projection of the accounts, so everything still
268
+ // reading them keeps reading the same answer. Only absent keys are filled;
269
+ // a value already there is left alone, because this step has no business
270
+ // overruling something a person set.
271
+ const legacy = projectLegacy(effectiveAccounts(out).accounts);
272
+ for (const [key, value] of Object.entries(legacy.hosts)) {
273
+ if (!g.hosts?.[key]) {
274
+ g.hosts = { ...g.hosts, [key]: value };
275
+ changes.push(`hosts.${key}: filled from the account that holds it`);
276
+ }
277
+ }
278
+ }
279
+
230
280
  function migrate(prefs) {
231
281
  const changes = [];
232
282
  const out = JSON.parse(JSON.stringify(prefs)); // deep clone
@@ -470,6 +520,12 @@ function migrate(prefs) {
470
520
  // 15. The MCP server renamed: guard rules and devToolkit fields that name it.
471
521
  migrateServerPrefs(out, changes);
472
522
 
523
+ // 16. serviceAccounts[]: the host, the secret and the identity of one
524
+ // credential on one entry. Runs last, because it reads the flat keys every
525
+ // step above may still have been fixing. Idempotent, and it rewrites no
526
+ // legacy value: the flat keys stay exactly where everything else reads them.
527
+ buildServiceAccounts(out, changes);
528
+
473
529
  return { out, changes, alreadyMigrated: changes.length === 0 };
474
530
  }
475
531
 
@@ -18,7 +18,7 @@
18
18
  #
19
19
  # Commands:
20
20
  # init <task_id> Reset tracker for this task
21
- # add <phase_id> "<name>" Register a phase (status=pending); idempotent - existing id is a no-op
21
+ # add <phase_id> "<name>" Register a phase and its contract sub-steps (status=pending); idempotent - existing id is a no-op
22
22
  # update <phase_id> <status> Change status + re-render
23
23
  # sub <phase_id> <sub_id> "<name>" [status] Add or update a sub-phase
24
24
  # tokens <phase_id> <in> <out> [cached] Add to phase's token totals (in = fresh input, cache-exclusive)
@@ -129,6 +129,24 @@ waiting_word() {
129
129
  esac
130
130
  }
131
131
 
132
+ # The sub-steps each phase declares before it starts, keyed `<id>:<name>` so a
133
+ # mode that renames a slot only inherits the set when the slot is the same one.
134
+ # Held to pipeline/schemas/phases.json `steps` by smoke-phase-tracker.sh, which
135
+ # compares the two sets; it stays a case statement here for the same reason
136
+ # phase-banner.sh keeps its label table (ADR-0004, no runtime schema read).
137
+ #
138
+ # Dev is absent on purpose: its sub-steps are Phase 1's plan tasks, which `plan`
139
+ # attaches once they exist. Declaring a second set would put two lists of work
140
+ # under one phase.
141
+ phase_steps() {
142
+ case "$1" in
143
+ 0:Init) printf 'Intake\nWorkspace\nTask contract\n' ;;
144
+ 1:Plan) printf 'Context\nExploration\nTask breakdown\n' ;;
145
+ 3:Review) printf 'Gates\nReview panel\nTriage\n' ;;
146
+ 4:Commit) printf 'Commit\nPush\nPull request\n' ;;
147
+ 5:Report) printf 'Channels dispatch\nLog + telemetry\nKnowledge + memory\n' ;;
148
+ esac
149
+ }
132
150
 
133
151
  if [ "$#" -lt 1 ]; then
134
152
  cat >&2 <<USAGE
@@ -779,12 +797,12 @@ tracker_next_hint() {
779
797
  # default only up to Opus 4.7 / Sonnet 4.6, a default that landed in
780
798
  # v2.1.268. Naming the fallback on the same line is what keeps a newer model
781
799
  # from advancing six phases in silence.
782
- # `subjects` now carries Phase 1's plan steps as indented rows, and
783
- # update_plan takes the whole list anyway, so re-reading it is what puts
784
- # those steps on the Codex plan without a second mechanism. Codex has no
800
+ # `tiles` prints the whole payload with each row's current status, and
801
+ # update_plan takes the whole list anyway, so re-reading it is what puts the
802
+ # sub-steps on the Codex plan without a second mechanism. Codex has no
785
803
  # dependency concept; the "(waiting on: ...)" suffix inside the step text is
786
804
  # where that information survives on this host.
787
- codex) mirror="update_plan: set step \"Phase $pid $name\" to $status, re-reading the FULL list from \`phase-tracker.sh subjects\` (it is not a delta, and the indented rows are plan steps that belong in it)" ;;
805
+ codex) mirror="update_plan: set step \"Phase $pid $name\" to $status, re-reading the FULL payload from \`phase-tracker.sh tiles\` (it is not a delta, and the indented rows are plan steps that belong in it)" ;;
788
806
  *) mirror="no task widget on this host - reprint the card above inside your reply text" ;;
789
807
  esac
790
808
  printf '\n-- NEXT (required) --\n %s\n' "$mirror"
@@ -795,6 +813,23 @@ tracker_next_hint() {
795
813
  esac
796
814
  }
797
815
 
816
+ # Printed after every sub-step change, for the same reason the phase hint is:
817
+ # the card goes to stdout and the host collapses it, so a sub-step that moves
818
+ # only in the state file moves nowhere the user can see. The row text is the
819
+ # one `subjects` prints, so the tile it names is the tile that exists.
820
+ sub_next_hint() {
821
+ local pid="$1" sid="$2" status="$3" row mirror
822
+ [ "${TRACKER_QUIET:-0}" = "1" ] && return 0
823
+ row=$(sub_rows "$(load_state)" "$pid" "$sid")
824
+ [ -n "$row" ] || return 0
825
+ case "$(host_kind)" in
826
+ claude) mirror="TaskUpdate(<tile \"$row\">, status=\"$status\") - the sub-step is a tile of its own, created from \`phase-tracker.sh tiles\`; if it has no tile yet, re-run \`tiles\` and rebuild the list first" ;;
827
+ codex) mirror="update_plan: set step \"$row\" to $status, re-reading the FULL list from \`phase-tracker.sh tiles\` (it is not a delta)" ;;
828
+ *) mirror="no task widget on this host - reprint the card above inside your reply text" ;;
829
+ esac
830
+ printf '\n-- NEXT (required) --\n %s\n' "$mirror"
831
+ }
832
+
798
833
  # Elapsed with an hours bucket. format_elapsed stops at minutes because the card
799
834
  # shows one phase at a time; a whole-run total reads as "102m" without this.
800
835
  format_span() {
@@ -950,18 +985,34 @@ subjects() {
950
985
  # Indentation is two spaces INSIDE the subject because the widget takes
951
986
  # exactly one string per row and has no parent field - there is no nesting
952
987
  # to ask for, so the only place a hierarchy can be expressed is the string.
953
- if [ -z "$want" ] || [ "$want" = "$pid" ]; then
954
- echo "$state" | jq -r --arg pid "$pid" --arg waiting "$(waiting_word)" '
955
- ([.phases[] | select(.id == $pid)][0].subs) // []
956
- | .[]
957
- | " " + (.id // "") + " " + (.name // "")
958
- + (if ((.deps // []) | length) > 0
959
- then " (" + $waiting + ": " + ((.deps // []) | join(", ")) + ")"
960
- else "" end)'
988
+ #
989
+ # The row carries `<phase>.<step>` and not the bare step id because the
990
+ # number has to survive in the string: the widget renders one string per row
991
+ # and no field beside it, so a `1` on its own row says nothing about which
992
+ # phase it belongs to.
993
+ #
994
+ # A single-phase read (`subjects <id>`) is the subject of ONE tile and stays
995
+ # one line; the sub rows are tiles of their own and belong to the full list.
996
+ if [ -z "$want" ]; then
997
+ sub_rows "$state" "$pid"
961
998
  fi
962
999
  done <<< "$rows"
963
1000
  }
964
1001
 
1002
+ # The sub rows of one phase, in the shape every host puts on its widget.
1003
+ # `sid` narrows to a single step, which is what a per-step mirror call needs.
1004
+ sub_rows() {
1005
+ local state="$1" pid="$2" sid="${3:-}"
1006
+ echo "$state" | jq -r --arg pid "$pid" --arg sid "$sid" --arg waiting "$(waiting_word)" '
1007
+ ([.phases[] | select(.id == $pid)][0].subs) // []
1008
+ | .[]
1009
+ | select($sid == "" or (.id // "") == $sid)
1010
+ | " " + $pid + "." + (.id // "") + " " + (.name // "")
1011
+ + (if ((.deps // []) | length) > 0
1012
+ then " (" + $waiting + ": " + ((.deps // []) | join(", ")) + ")"
1013
+ else "" end)'
1014
+ }
1015
+
965
1016
  # The TaskCreate/TaskUpdate script for this host, in creation order.
966
1017
  #
967
1018
  # Creation order is the ONLY ordering the native widget has - it renders by the
@@ -971,14 +1022,20 @@ subjects() {
971
1022
  # already does for a different reason.
972
1023
  tiles_script() {
973
1024
  need_jq
974
- local new_only="${1:-}"
1025
+ local new_only="${1:-}" rebuild="${2:-}"
975
1026
  local state; state=$(load_state)
976
- local has_subs
977
- has_subs=$(echo "$state" | jq '[.phases[]?.subs[]?] | length')
978
-
979
- # A list carrying sub-steps has to be rebuilt whole, so the rebuild wins over a
980
- # narrowed batch: appending to it would land the new rows after Phase 5.
981
- [ "${has_subs:-0}" -gt 0 ] && new_only=""
1027
+ # A phase whose tasklist_id was never recorded has, as far as anything can
1028
+ # tell, no tile. With none recorded at all there is no list yet, so the whole
1029
+ # list is a first batch and nothing is rebuilt.
1030
+ local has_tiles
1031
+ has_tiles=$(echo "$state" | jq \
1032
+ '[.phases[]? | select(((.meta.tasklist_id // "") | tostring) != "")] | length')
1033
+ [ "${has_tiles:-0}" -gt 0 ] || rebuild=""
1034
+
1035
+ # Rows that arrive after the list exists have to be inserted, which the widget
1036
+ # cannot do, so the whole list is rebuilt. The rebuild wins over a narrowed
1037
+ # batch: appending to it would land the new rows after the last phase.
1038
+ [ -n "$rebuild" ] && new_only=""
982
1039
 
983
1040
  if [ -n "$new_only" ]; then
984
1041
  local pending_new
@@ -987,19 +1044,21 @@ tiles_script() {
987
1044
  printf 'Every registered phase already has a tile - nothing to create.\n'
988
1045
  return 0
989
1046
  fi
990
- printf 'REQUIRED - create one native tile per phase below, in this exact order.
1047
+ printf 'REQUIRED - create one native tile per ROW below, in this exact order.
991
1048
  '
992
1049
  printf 'Tiles already created keep their place; every phase here is numbered
993
1050
  '
994
- printf 'above them, so the widget stays in phase order.
1051
+ printf 'above them, so the widget stays in phase order. The indented rows are
1052
+ '
1053
+ printf 'the sub-steps of the phase above them and are tiles of their own.
995
1054
 
996
1055
  '
997
1056
  printf '%s\n' "$pending_new" | sed 's/^/ TaskCreate(subject: "/; s/$/")/'
998
1057
  return 0
999
1058
  fi
1000
1059
 
1001
- if [ "${has_subs:-0}" -gt 0 ]; then
1002
- printf 'The tile list has sub-steps now, and the widget orders by CREATION.
1060
+ if [ -n "$rebuild" ]; then
1061
+ printf 'The tile list has gained rows, and the widget orders by CREATION.
1003
1062
  '
1004
1063
  printf 'Delete every existing tile (TaskUpdate status="deleted"), then create
1005
1064
  '
@@ -1009,11 +1068,15 @@ tiles_script() {
1009
1068
 
1010
1069
  '
1011
1070
  else
1012
- printf 'REQUIRED - create one native tile per phase, in this exact order,
1071
+ printf 'REQUIRED - create one native tile per ROW below, in this exact
1072
+ '
1073
+ printf 'order, BEFORE any TaskUpdate. The indented rows are the sub-steps of
1013
1074
  '
1014
- printf 'BEFORE any TaskUpdate. The widget renders by creation order, not by
1075
+ printf 'the phase above them and are tiles of their own; the widget renders by
1015
1076
  '
1016
- printf 'phase number, so an out-of-order call scrambles the stack.
1077
+ printf 'creation order, not by phase number, so an out-of-order call scrambles
1078
+ '
1079
+ printf 'the stack.
1017
1080
 
1018
1081
  '
1019
1082
  fi
@@ -1029,12 +1092,13 @@ tiles_script() {
1029
1092
  # executable and is not, which is worse than a line that admits what it needs.
1030
1093
  local deps
1031
1094
  deps=$(echo "$state" | jq -r '
1032
- [.phases[]? | .subs[]?] as $all
1033
- | $all[] | select(((.deps // []) | length) > 0)
1095
+ [.phases[]? | . as $p | (.subs[]? | . + {phase: $p.id})] as $all
1096
+ | def row($s): "<tile \" " + ($s.phase // "") + "." + ($s.id // "") + " " + ($s.name // "") + "\">";
1097
+ $all[] | select(((.deps // []) | length) > 0)
1034
1098
  | . as $s
1035
- | " TaskUpdate(<tile \" " + ($s.name // "") + "\">, addBlockedBy: [" +
1099
+ | " TaskUpdate(" + row($s) + ", addBlockedBy: [" +
1036
1100
  (($s.deps // [])
1037
- | map(. as $d | (($all[] | select(.id == $d) | "<tile \" " + (.name // "") + "\">") // $d))
1101
+ | map(. as $d | (($all[] | select(.id == $d and .phase == $s.phase) | row(.)) // $d))
1038
1102
  | join(", ")) + "])"')
1039
1103
  if [ -n "$deps" ]; then
1040
1104
  printf '\nThen the dependencies, so the widget says WHY a step has not started.\n'
@@ -1044,6 +1108,29 @@ tiles_script() {
1044
1108
  fi
1045
1109
  }
1046
1110
 
1111
+ # The Codex plan payload: every row `subjects` prints, carrying the status the
1112
+ # tracker holds for it. The indented rows are plan steps like any other - the
1113
+ # plan tool has no nesting, so the phase number inside the text is the only
1114
+ # thing that says which phase a step belongs to. Codex knows three statuses, so
1115
+ # a failed or skipped row goes out as `completed` and the agent log carries why.
1116
+ codex_plan() {
1117
+ local state="$1" statuses
1118
+ statuses=$(echo "$state" | jq -r '
1119
+ .phases // []
1120
+ | sort_by(.id | (tonumber? // 9999))
1121
+ | .[]
1122
+ | select((.id // "") != "")
1123
+ | (.status // "pending"), ((.subs // [])[] | (.status // "pending"))')
1124
+ paste -d"$(printf '\037')" <(subjects) <(printf '%s\n' "$statuses") \
1125
+ | jq -Rn -c '[inputs | select(length > 0) | split("\u001f") | . as $r
1126
+ | {step: $r[0],
1127
+ status: (if $r[1] == "in_progress" then "in_progress"
1128
+ elif ($r[1] == "completed" or $r[1] == "failed" or $r[1] == "skipped")
1129
+ then "completed"
1130
+ else "pending" end)}]
1131
+ | {plan: .}'
1132
+ }
1133
+
1047
1134
  render() {
1048
1135
  need_jq
1049
1136
  local state
@@ -1302,15 +1389,23 @@ case "$ACTION" in
1302
1389
  need_jq
1303
1390
  [ "$#" -ge 2 ] || { echo "add needs <phase_id> <name>" >&2; exit 64; }
1304
1391
  PID="$1"; PNAME="$(decode_entities "$2")"
1392
+ # The phase arrives with its sub-steps already on it. A step registered from
1393
+ # the contract is a property of the phase set, and so reaches the widget
1394
+ # whether or not the phase later announces it; one a phase has to announce
1395
+ # before it exists reaches the widget only when that call is made.
1396
+ PSUBS=$(phase_steps "$PID:$PNAME" | jq -Rn \
1397
+ '[inputs | select(length > 0)]
1398
+ | to_entries
1399
+ | map({id: ((.key + 1) | tostring), name: .value, status: "pending", deps: []})')
1305
1400
  acquire_state_lock
1306
1401
  state=$(load_state)
1307
1402
  # Idempotent: a phase id that already exists is a no-op (name, status, and
1308
1403
  # token history are preserved). This is what lets continuation commands
1309
1404
  # (/multi-agent:resume, /multi-agent:manual-test) re-declare their phase set against a
1310
1405
  # pre-existing tracker without duplicating or resetting tiles.
1311
- new=$(echo "$state" | jq --arg id "$PID" --arg name "$PNAME" '
1406
+ new=$(echo "$state" | jq --arg id "$PID" --arg name "$PNAME" --argjson subs "$PSUBS" '
1312
1407
  if any(.phases[]?; .id == $id) then .
1313
- else .phases += [{"id":$id,"name":$name,"status":"pending","subs":[]}]
1408
+ else .phases += [{"id":$id,"name":$name,"status":"pending","subs":$subs}]
1314
1409
  end')
1315
1410
  save_state "$new"
1316
1411
  release_state_lock
@@ -1422,7 +1517,10 @@ $(printf '%s' "$PLAN_IN" | jq -r '
1422
1517
  EOF
1423
1518
  [ "$N" -gt 0 ] || { echo "phase-tracker: plan carried no tasks[]" >&2; exit 65; }
1424
1519
  printf 'phase-tracker: %s plan step(s) attached to phase %s\n' "$N" "$PID"
1425
- tiles_script
1520
+ # The steps arrive after the list exists, so the list is rebuilt - and
1521
+ # through the `tiles` action, so each host is told in its own calls rather
1522
+ # than handed Claude Code's.
1523
+ "$SELF_PATH" tiles --rebuild
1426
1524
  ;;
1427
1525
  sub)
1428
1526
  need_jq
@@ -1456,6 +1554,7 @@ EOF
1456
1554
  emit_otel_span "phase.sub" "$PID" "$SNAME" \
1457
1555
  "$(jq -nc --arg s "$SID" --arg st "$SSTATUS" '{sub_id:$s,status:$st}')"
1458
1556
  render
1557
+ sub_next_hint "$PID" "$SID" "$SSTATUS"
1459
1558
  ;;
1460
1559
 
1461
1560
  tokens)
@@ -1661,7 +1760,15 @@ EOF
1661
1760
  tiles)
1662
1761
  need_jq
1663
1762
  tiles_new=""
1664
- [ "${1:-}" = "--new" ] && tiles_new=1
1763
+ tiles_rebuild=""
1764
+ while [ "$#" -gt 0 ]; do
1765
+ case "$1" in
1766
+ --new) tiles_new=1 ;;
1767
+ --rebuild) tiles_rebuild=1 ;;
1768
+ *) echo "tiles: unknown option $1" >&2; exit 64 ;;
1769
+ esac
1770
+ shift
1771
+ done
1665
1772
  tiles_state=$(load_state)
1666
1773
  tiles_count=$(echo "$tiles_state" | jq '[.phases[]?] | length')
1667
1774
  [ "${tiles_count:-0}" -gt 0 ] || {
@@ -1684,7 +1791,7 @@ EOF
1684
1791
  # tools it has. And the fallback is not enough on its own: a user looking
1685
1792
  # at a missing widget needs the one command that brings it back, which is
1686
1793
  # why the opt-in is printed next to it.
1687
- tiles_script "$tiles_new"
1794
+ tiles_script "$tiles_new" "$tiles_rebuild"
1688
1795
  echo
1689
1796
  echo "At every phase boundary re-run \`phase-tracker.sh subjects <id>\` and"
1690
1797
  echo "pass that line as the subject of the TaskUpdate. The subject is the only"
@@ -1709,8 +1816,9 @@ EOF
1709
1816
  codex)
1710
1817
  echo "REQUIRED - register the plan in ONE update_plan call with this step"
1711
1818
  echo "list. update_plan takes the full list, not a delta, so every later"
1712
- echo "boundary resends it with one step's status changed."
1713
- echo "$tiles_state" | jq -c '{plan: [.phases[] | {step: "Phase \(.id) \(.name)", status: "pending"}]}'
1819
+ echo "boundary resends it with one step's status changed. The indented"
1820
+ echo "steps are the sub-steps of the phase above them and belong in it."
1821
+ codex_plan "$tiles_state"
1714
1822
  ;;
1715
1823
  *)
1716
1824
  echo "Copilot CLI has no native task widget: the bordered card IS the widget."