@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
@@ -57,9 +57,39 @@ _MA_CI_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
57
57
  # shellcheck source=/dev/null
58
58
  if [ -f "$_MA_CI_HERE/user-facing.sh" ]; then . "$_MA_CI_HERE/user-facing.sh"; else . "$HOME/.claude/lib/user-facing.sh"; fi
59
59
 
60
+ # The account resolver answers where each service lives. Sourced for sa_host,
61
+ # which reads the account rather than a host key, so this inventory names the
62
+ # same host the fetchers will actually call.
63
+ for _sa in "$_MA_CI_HERE/_service-account.sh" "$HOME/.claude/lib/_service-account.sh" \
64
+ "$HOME/.copilot/lib/_service-account.sh" "$HOME/.codex/lib/_service-account.sh" \
65
+ "$HOME/.codex-local/lib/_service-account.sh"; do
66
+ # shellcheck source=/dev/null
67
+ [ -f "$_sa" ] && { . "$_sa"; break; }
68
+ done
69
+ unset _sa
70
+
71
+ # The host of a service's account, or empty when no account answers for it.
72
+ # Called inside a command substitution, so it never exits.
73
+ account_host() {
74
+ if ! command -v sa_host >/dev/null 2>&1; then
75
+ return 0
76
+ fi
77
+ sa_host "$@" 2>/dev/null || true
78
+ }
79
+
80
+ # One slot of a service's account, for the destination that account was checked
81
+ # against, or empty. Same rule: no exit, and nothing printed on a refusal.
82
+ account_secret() {
83
+ if ! command -v sa_token >/dev/null 2>&1; then
84
+ return 0
85
+ fi
86
+ sa_token "$@" 2>/dev/null || true
87
+ }
88
+
60
89
  STORE=""
61
90
  for c in "$HOME/.claude/lib/credential-store.sh" "$HOME/.copilot/lib/credential-store.sh" \
62
- "$HOME/.codex/lib/credential-store.sh" "$(dirname "$0")/credential-store.sh"; do
91
+ "$HOME/.codex/lib/credential-store.sh" "$HOME/.codex-local/lib/credential-store.sh" \
92
+ "$(dirname "$0")/credential-store.sh"; do
63
93
  [ -f "$c" ] && { STORE="$c"; break; }
64
94
  done
65
95
 
@@ -78,24 +108,6 @@ while [ $# -gt 0 ]; do
78
108
  esac
79
109
  done
80
110
 
81
- pref() { # pref <dotted.path> -> value or empty
82
- [ -f "$PREFS" ] || return 0
83
- python3 - "$PREFS" "$1" <<'PYPREF' 2>/dev/null
84
- import json, sys
85
- try:
86
- d = json.load(open(sys.argv[1]))
87
- except Exception:
88
- sys.exit(0)
89
- for k in sys.argv[2].split("."):
90
- if not isinstance(d, dict):
91
- sys.exit(0)
92
- d = d.get(k)
93
- if d is None:
94
- sys.exit(0)
95
- print(d if not isinstance(d, (dict, list)) else "")
96
- PYPREF
97
- }
98
-
99
111
  # An authenticated request whose credential never appears in argv.
100
112
  #
101
113
  # `curl -H "Authorization: Bearer $TOK"` puts the secret in the process command line,
@@ -231,12 +243,11 @@ MCPCHK
231
243
  # Reachability for one logical key. Never prints a credential; the value is piped
232
244
  # straight into curl's stdin config and discarded.
233
245
  #
234
- # Hosts always come from preferences - a self-hosted Jira / Bitbucket / Confluence /
235
- # Fortify / Graylog address is deployment-specific and must never be baked in. Only
236
- # genuinely global public APIs are named literally. Host keys live at
237
- # `global.hosts.<service>` per prefs.schema.json - an earlier version of this probe
238
- # guessed `global.<service>Host` and reported no-host-configured for every
239
- # self-hosted service the user had actually configured.
246
+ # Hosts always come from the account resolver - a self-hosted Jira / Bitbucket /
247
+ # Confluence / Fortify / Graylog address is deployment-specific and must never be
248
+ # baked in. Only genuinely global public APIs are named literally. A service whose
249
+ # account names no host reads as no-host-configured, which is a setup gap rather
250
+ # than a broken credential.
240
251
  probe_one() {
241
252
  local key="$1" tok host status
242
253
  tok=$(bash "$STORE" get "$key" 2>/dev/null) || { echo "no-credential"; return; }
@@ -244,19 +255,20 @@ probe_one() {
244
255
 
245
256
  case "$key" in
246
257
  jira)
247
- host=$(pref global.hosts.jira)
258
+ host=$(account_host jira)
248
259
  [ -n "$host" ] || { echo "no-host-configured"; return; }
249
260
  status=$(probe_http "https://${host}/rest/api/2/myself" "Authorization" "Bearer $tok") ;;
250
261
  confluence)
251
- host=$(pref global.hosts.confluence)
262
+ host=$(account_host confluence)
252
263
  [ -n "$host" ] || { echo "no-host-configured"; return; }
253
264
  status=$(probe_http "https://${host}/rest/api/user/current" "Authorization" "Bearer $tok") ;;
254
265
  bitbucket_token)
255
- host=$(pref global.hosts.bitbucket)
266
+ host=$(account_host bitbucket)
256
267
  [ -n "$host" ] || { echo "no-host-configured"; return; }
257
- local bbuser bbkey
258
- bbkey=$(pref global.keychainMapping.bitbucket_user)
259
- bbuser=$([ -n "$bbkey" ] && bash "$STORE" get bitbucket_user 2>/dev/null || echo "")
268
+ # The username is the other half of this account's login; the resolver
269
+ # hands it out only for the host the account itself names.
270
+ local bbuser
271
+ bbuser=$(account_secret bitbucket "https://${host}" --slot username)
260
272
  if [ -n "$bbuser" ]; then
261
273
  status=$(probe_basic "https://${host}/rest/api/1.0/repos?limit=1" "$bbuser" "$tok")
262
274
  else
@@ -276,7 +288,7 @@ probe_one() {
276
288
  npm)
277
289
  status=$(probe_http "https://registry.npmjs.org/-/whoami" "Authorization" "Bearer $tok") ;;
278
290
  fortify)
279
- host=$(pref global.hosts.fortify)
291
+ host=$(account_host fortify)
280
292
  [ -n "$host" ] || { echo "no-host-configured"; return; }
281
293
  # Shapes copied from fetch-fortify.sh, which already works against SSC: the API
282
294
  # lives under /ssc/, and SSC accepts either a Bearer token or its own
@@ -288,12 +300,12 @@ probe_one() {
288
300
  "Authorization" "FortifyToken $(printf '%s' "$tok" | base64 | tr -d '\n')")
289
301
  fi ;;
290
302
  graylog|graylog_test)
291
- # The test instance is a separate deployment with its own host key; probing it
292
- # against the prod host would report a healthy token as broken.
303
+ # The test instance is a separate deployment with its own account; probing it
304
+ # against the production host would report a healthy token as broken.
293
305
  if [ "$key" = "graylog_test" ]; then
294
- host=$(pref global.hosts.graylogTest)
306
+ host=$(account_host graylog --environment test)
295
307
  else
296
- host=$(pref global.hosts.graylog)
308
+ host=$(account_host graylog --environment production)
297
309
  fi
298
310
  [ -n "$host" ] || { echo "no-host-configured"; return; }
299
311
  # Graylog PATs authenticate as basic auth with the literal password "token", and
@@ -301,7 +313,7 @@ probe_one() {
301
313
  status=$(probe_basic_hdr "https://${host}/api/system" "$tok" "token" \
302
314
  "X-Requested-By" "multi-agent-pipeline") ;;
303
315
  jenkins)
304
- host=$(pref global.hosts.jenkins)
316
+ host=$(account_host jenkins)
305
317
  [ -n "$host" ] || { echo "no-host-configured"; return; }
306
318
  status=$(probe_http "https://${host}/api/json" "Authorization" "Bearer $tok") ;;
307
319
  firebase)
@@ -12,6 +12,11 @@
12
12
  # keeps the secret off this script's argv (visible to
13
13
  # ps). A literal "-" value cannot be stored this way.
14
14
  # delete <key> Remove secret
15
+ # resolve <key> Print the store item NAME this logical key maps to,
16
+ # and never a value. The mapping is what decides which
17
+ # account a request is made as, so it has to be readable
18
+ # on its own: a check that can only observe it by reading
19
+ # the secret cannot run where secrets must not be printed.
15
20
  # probe <key> Is the secret readable right now, without a prompt?
16
21
  # Prints one word - readable | missing | locked - and
17
22
  # never the value: the backend's stdout goes to
@@ -135,8 +140,30 @@ audit_lookup() {
135
140
  do_get() {
136
141
  local key="${1:-}"
137
142
  [ -z "$key" ] && { echo "usage: $0 get <key>" >&2; exit 3; }
138
- local logical="$key"
139
- key=$(resolve_key "$key")
143
+ read_item "$(resolve_key "$key")" "$key"
144
+ }
145
+
146
+ # Read an item by its exact store name, with no mapping pass.
147
+ #
148
+ # `get` takes a logical key and maps it; a caller that already holds an item
149
+ # name has nothing left to map, and sending it through `resolve_key` a second
150
+ # time would let a name that happens to match a mapping key become a different
151
+ # item. The audit label is passed separately so the trail keeps naming the
152
+ # logical thing that was asked for rather than the item that answered it.
153
+ do_get_item() {
154
+ local item="${1:-}" label="${2:-}"
155
+ [ -z "$item" ] && { echo "usage: $0 get-item <item-name> [audit-label]" >&2; exit 3; }
156
+ read_item "$item" "${label:-$item}"
157
+ }
158
+
159
+ # The body both of the above share: one exact-name read, one audit line.
160
+ #
161
+ # Exit codes are the caller's contract: 1 absent or empty, 2 backend
162
+ # unavailable, 4 backend error, 5 the store is locked. 5 is told apart from 1
163
+ # because "there is no such secret" and "I may not look" ask for different
164
+ # things from the person reading the message.
165
+ read_item() {
166
+ local key="${1:-}" logical="${2:-$1}"
140
167
  if delegate_to_python; then
141
168
  local val rc
142
169
  val=$(python3 "$KEYCHAIN_PY" get "$key" 2>/dev/null) || rc=$?
@@ -167,6 +194,12 @@ do_get() {
167
194
  fi
168
195
  if [ -z "$val" ]; then
169
196
  audit_lookup "$logical" false
197
+ # A locked keychain refuses every read with the same emptiness an absent
198
+ # item gives, so the refusal text is the only thing that tells them apart.
199
+ case "$attrs" in
200
+ *"User interaction is not allowed"*|*"-25308"*)
201
+ echo "ERR: credential store is locked" >&2; return 5 ;;
202
+ esac
170
203
  return 1
171
204
  fi
172
205
  audit_lookup "$logical" true
@@ -281,13 +314,25 @@ do_doctor() {
281
314
  || echo "Backend: security ✗ MISSING (impossible on macOS)"
282
315
  }
283
316
 
317
+ do_resolve() {
318
+ local key="${1:-}"
319
+ if [ -z "$key" ]; then
320
+ echo "usage: $0 resolve <key>" >&2
321
+ return 3
322
+ fi
323
+ resolve_key "$key"
324
+ printf '\n'
325
+ }
326
+
284
327
  case "$CMD" in
285
328
  get) do_get "$@" ;;
329
+ get-item) do_get_item "$@" ;;
330
+ resolve) do_resolve "$@" ;;
286
331
  set) do_set "$@" ;;
287
332
  delete) do_delete "$@" ;;
288
333
  probe) do_probe "$@" ;;
289
334
  list) do_list ;;
290
335
  platform) echo "$PLATFORM" ;;
291
336
  doctor) do_doctor ;;
292
- *) echo "usage: $0 {get|set|delete|probe|list|platform|doctor} [args]" >&2; exit 3 ;;
337
+ *) echo "usage: $0 {get|get-item|set|resolve|delete|probe|list|platform|doctor} [args]" >&2; exit 3 ;;
293
338
  esac
@@ -13,11 +13,12 @@
13
13
  #
14
14
  # Optional env:
15
15
  # CONFLUENCE_TIMEOUT_SECONDS default 20
16
- # CONFLUENCE_AUTH_TOKEN_KEY default prefs.global.keychainMapping.confluence
17
- # fallback "${USER}_Confluence_Access_Token"
18
- # CONFLUENCE_HOST_OVERRIDE forces the host (overrides URL host extraction)
19
- # and is the one host trusted without a match
20
- # against prefs.global.hosts.confluence
16
+ # CONFLUENCE_AUTH_TOKEN_KEY names a store item, when the account is to be
17
+ # chosen by the item it holds
18
+ # CONFLUENCE_HOST_OVERRIDE forces the host (overrides URL host extraction).
19
+ # It still has to be a host a configured account
20
+ # covers: an override names which account, it
21
+ # does not excuse one from being checked.
21
22
  #
22
23
  # Output (stdout, single JSON object):
23
24
  # {
@@ -36,22 +37,24 @@
36
37
  # 2 missing token or auth failure (after Save Flow trigger)
37
38
  # 3 network / HTTP error
38
39
  # 4 bad usage
39
- # 6 host refused: the page is not on prefs.global.hosts.confluence
40
- # (host-not-allowed), or no Confluence host is configured and the page is
41
- # not on Atlassian Cloud (host-not-configured). Checked before the token
42
- # is read, so the token never travels to a host the user did not name.
40
+ # 6 host refused: no Confluence account covers the page's host
41
+ # (host-not-allowed), or none is configured at all (host-not-configured).
42
+ # Decided before any secret is read, so the token never travels to a host
43
+ # no account names.
43
44
  #
44
45
  # Notes on auth:
45
- # The script reads the Confluence token via credential-store.sh. If the
46
- # token is missing, the script prints a structured "blocked" JSON to stderr
47
- # and exits 2 - the orchestrator handles the Save Flow + retry. The script
48
- # itself never prompts.
46
+ # Auth goes through the account resolver: the credential is written into a
47
+ # curl config that also carries the URL it is for, so the two cannot be
48
+ # separated and a redirect is refused rather than followed with the header
49
+ # on. The token never reaches a shell variable, argv or a log. When no
50
+ # account can answer, the script prints a structured "blocked" JSON to
51
+ # stderr and exits 2 - the orchestrator handles the Save Flow + retry. The
52
+ # script itself never prompts.
49
53
 
50
54
  set -euo pipefail
51
55
 
52
56
  URL=""
53
- ENV_HOST_OVERRIDE="${CONFLUENCE_HOST_OVERRIDE:-}"
54
- HOST_OVERRIDE="$ENV_HOST_OVERRIDE"
57
+ HOST_OVERRIDE="${CONFLUENCE_HOST_OVERRIDE:-}"
55
58
  PAGE_ID=""
56
59
  TIMEOUT="${CONFLUENCE_TIMEOUT_SECONDS:-20}"
57
60
 
@@ -129,84 +132,24 @@ if ! [[ "$HOST" =~ ^[A-Za-z0-9.-]+(:[0-9]{1,5})?$ ]] || { [[ "$HOST" == *:* ]] &
129
132
  fi
130
133
 
131
134
  # The link usually comes from ticket text, so its host is attacker-choosable.
132
- # The token goes only to the configured host (or a subdomain of it); without a
133
- # configured host, only to Atlassian Cloud, where the host is the tenant.
134
- PREFS="$HOME/.claude/multi-agent-preferences.json"
135
- if [ -z "$ENV_HOST_OVERRIDE" ]; then
136
- HOST_VERDICT=$(python3 - "$HOST" "$PREFS" <<'PY'
137
- import json, sys
138
- host = sys.argv[1].lower().split(":", 1)[0].rstrip(".")
139
- try:
140
- with open(sys.argv[2]) as f:
141
- allowed = (json.load(f).get("global", {}).get("hosts", {}).get("confluence") or "")
142
- except Exception:
143
- allowed = ""
144
- allowed = allowed.lower().strip().rstrip("/").split("://")[-1].split("/")[0].split(":")[0]
145
- if allowed:
146
- ok = host == allowed or host.endswith("." + allowed)
147
- print("ok" if ok else "host-not-allowed")
148
- else:
149
- print("ok" if host.endswith(".atlassian.net") else "host-not-configured")
150
- PY
151
- )
152
- if [ "$HOST_VERDICT" != "ok" ]; then
153
- printf '%s\n' '{"status":"blocked","reason":"'"$HOST_VERDICT"'","service":"confluence","expected_pref":"global.hosts.confluence"}' >&2
154
- exit 6
155
- fi
156
- fi
157
-
158
- # Resolve token via keychainMapping with sane fallback.
159
- TOKEN_KEY="${CONFLUENCE_AUTH_TOKEN_KEY:-}"
160
- if [ -z "$TOKEN_KEY" ] && [ -f "$PREFS" ]; then
161
- TOKEN_KEY=$(python3 -c "
162
- import json
163
- try:
164
- p = json.load(open('$PREFS'))
165
- print(p.get('global', {}).get('keychainMapping', {}).get('confluence') or '')
166
- except Exception:
167
- print('')
168
- ")
169
- fi
170
- [ -z "$TOKEN_KEY" ] && TOKEN_KEY="${USER}_Confluence_Access_Token"
171
-
172
- # Locate the resolver with an existence check, not a `.`-chain.
173
- #
174
- # Sourcing a file that does not exist aborts the shell under `set -e` - `||` included -
175
- # so `. <candidate> || . <candidate> || { error }` reaches neither its later candidates
176
- # nor its error branch. Every fetcher used that shape starting from `$HOME/.claude/...`,
177
- # so on a Copilot-only or Codex-only install they all died with a bare exit 1 and no
178
- # message. Reordering does not help: whichever candidate is absent aborts at that point.
179
- # Checking for the file before sourcing it is the only safe form.
180
- for _cred_resolver in \
181
- "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/credential-store-resolver.sh" \
182
- "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/../lib" 2>/dev/null && pwd)/credential-store-resolver.sh" \
183
- "$HOME/.claude/lib/credential-store-resolver.sh" \
184
- "$HOME/.copilot/lib/credential-store-resolver.sh" \
185
- "$HOME/.codex/lib/credential-store-resolver.sh"; do
186
- [ -f "$_cred_resolver" ] || continue
187
- # shellcheck source=/dev/null
188
- . "$_cred_resolver" 2>/dev/null || true
189
- # `if`, not `[ ... ] && break`: the latter is the loop body's last command and returns
190
- # 1 when CRED_STORE is still empty, which under `set -e` kills the loop on the first
191
- # candidate that does not resolve - the very case the loop exists to survive.
192
- if [ -n "${CRED_STORE:-}" ]; then break; fi
193
- done
194
- unset _cred_resolver
195
- if [ -z "${CRED_STORE:-}" ]; then
196
- printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"confluence","expected_key":"'"$TOKEN_KEY"'"}' >&2
135
+ # The account resolver decides whether any configured account covers it, and
136
+ # writes the credential only into a config pinned to that one URL.
137
+ _MA_FC_HERE="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
138
+ # shellcheck source=/dev/null
139
+ if [ -f "$_MA_FC_HERE/_service-account.sh" ]; then
140
+ . "$_MA_FC_HERE/_service-account.sh"
141
+ elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
142
+ . "$HOME/.claude/lib/_service-account.sh"
143
+ else
144
+ printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"confluence"}' >&2
197
145
  exit 2
198
146
  fi
199
147
 
200
- TOKEN=$("$CRED_STORE" get "$TOKEN_KEY" 2>/dev/null || true)
201
- if [ -z "$TOKEN" ]; then
202
- printf '%s\n' '{"status":"blocked","reason":"missing-token","service":"confluence","expected_key":"'"$TOKEN_KEY"'"}' >&2
203
- exit 2
148
+ SA_PICK=(--host "$HOST")
149
+ if [ -n "${CONFLUENCE_AUTH_TOKEN_KEY:-}" ]; then
150
+ SA_PICK+=(--item "$CONFLUENCE_AUTH_TOKEN_KEY")
204
151
  fi
205
152
 
206
- # Bearer auth via a curl config fed through process substitution so the token
207
- # never appears in argv (argv is visible to ps).
208
- confluence_auth_cfg() { printf 'header = "Authorization: Bearer %s"\n' "$TOKEN"; }
209
-
210
153
  # Endpoint resolution: Confluence Cloud (<tenant>.atlassian.net/wiki/rest/api)
211
154
  # vs Server/Data Center (<host>/rest/api). The same paths exist on both.
212
155
  case "$HOST" in
@@ -214,6 +157,47 @@ case "$HOST" in
214
157
  *) API_BASE="https://$HOST/rest/api" ;;
215
158
  esac
216
159
 
160
+ # Sets CONFLUENCE_CFG rather than printing it: a caller that read it through a
161
+ # command substitution would run this in a subshell, where the refusal branch's
162
+ # `exit` ends the subshell and the script carries on unauthenticated.
163
+ CONFLUENCE_CFG=""
164
+ confluence_cfg() {
165
+ CONFLUENCE_CFG="$(sa_cfg confluence "$1" bearer "${SA_PICK[@]+"${SA_PICK[@]}"}")"
166
+ }
167
+
168
+ confluence_blocked() {
169
+ local reason code
170
+ case "$(sa_code)" in
171
+ host-mismatch|no-account-for-target|identity-mismatch|insecure-url)
172
+ reason="host-not-allowed"; code=6 ;;
173
+ not-configured|unknown-account)
174
+ # No account exists. Whether that is a credential still to be saved or a
175
+ # link to a host nobody named turns on whether anything says where this
176
+ # service lives: the file for a Server install, the tenant name itself on
177
+ # Cloud. The first is the Save Flow's case, the second is not.
178
+ case "$HOST" in
179
+ *.atlassian.net) reason="missing-token"; code=2 ;;
180
+ *)
181
+ if [ "$(sa_field hostKnown)" = "true" ]; then
182
+ reason="missing-token"; code=2
183
+ else
184
+ reason="host-not-configured"; code=6
185
+ fi ;;
186
+ esac ;;
187
+ prefs-unreadable|invalid-config)
188
+ reason="host-not-configured"; code=6 ;;
189
+ store-unavailable)
190
+ reason="missing-credential-helper"; code=2 ;;
191
+ *)
192
+ reason="missing-token"; code=2 ;;
193
+ esac
194
+ printf '%s\n' '{"status":"blocked","reason":"'"$reason"'","service":"confluence","expected_pref":"global.hosts.confluence"}' >&2
195
+ exit "$code"
196
+ }
197
+
198
+ # Decided once, before any request: a host nothing covers never reaches a curl.
199
+ confluence_cfg "$API_BASE/content" || confluence_blocked
200
+
217
201
  # When we have a page URL but no pageId yet, resolve via title lookup.
218
202
  if [ -z "$PAGE_ID_RESOLVED" ] && [ -n "$SPACE_KEY" ] && [ -n "$URL" ]; then
219
203
  TITLE_RAW=$(python3 -c "
@@ -225,11 +209,11 @@ print(up.unquote(m.group(1)) if m else '')
225
209
  " "$URL")
226
210
  if [ -n "$TITLE_RAW" ]; then
227
211
  LOOKUP=$(curl -sS --fail --max-time "$TIMEOUT" --connect-timeout 5 \
228
- -K <(confluence_auth_cfg) -H "Accept: application/json" \
212
+ --config "$CONFLUENCE_CFG" -H "Accept: application/json" \
229
213
  --data-urlencode "spaceKey=$SPACE_KEY" \
230
214
  --data-urlencode "title=$TITLE_RAW" \
231
215
  --data-urlencode "expand=" \
232
- -G "$API_BASE/content" 2>/dev/null || true)
216
+ -G 2>/dev/null || true)
233
217
  PAGE_ID_RESOLVED=$(printf '%s' "$LOOKUP" | python3 -c "
234
218
  import sys, json
235
219
  try:
@@ -248,9 +232,9 @@ if [ -z "$PAGE_ID_RESOLVED" ]; then
248
232
  fi
249
233
 
250
234
  # Fetch the page body in storage format.
235
+ confluence_cfg "$API_BASE/content/$PAGE_ID_RESOLVED?expand=body.storage,space" || confluence_blocked
251
236
  PAGE_JSON=$(curl -sS --fail --max-time "$TIMEOUT" --connect-timeout 5 \
252
- -K <(confluence_auth_cfg) -H "Accept: application/json" \
253
- "$API_BASE/content/$PAGE_ID_RESOLVED?expand=body.storage,space" 2>/dev/null || true)
237
+ --config "$CONFLUENCE_CFG" -H "Accept: application/json" 2>/dev/null || true)
254
238
 
255
239
  if [ -z "$PAGE_JSON" ]; then
256
240
  echo "ERR: Confluence GET failed for pageId=$PAGE_ID_RESOLVED" >&2
@@ -19,7 +19,7 @@
19
19
  # Credential resolution, in order:
20
20
  # 1. FIREBASE_TOKEN_KEY (env override)
21
21
  # 2. prefs.global.firebase.accounts[] entry whose projectId matches the URL
22
- # 3. prefs.global.keychainMapping.firebase (single-project setups)
22
+ # 3. the sole Firebase account (single-project setups)
23
23
  # 4. "${USER}_Firebase_Access_Json"
24
24
  #
25
25
  # Output (stdout, single JSON object):
@@ -148,71 +148,42 @@ if [ "$PROBE" -eq 0 ] \
148
148
  exit 4
149
149
  fi
150
150
 
151
- # Resolve the Firebase SA JSON via keychain mapping (matches Phase 0 contract).
151
+ # Resolve the Firebase service-account key for this project.
152
152
  #
153
153
  # One team routinely owns several Firebase projects - a legacy app and its
154
- # redesign, or staging next to production - and each has its own service-account
155
- # key. A single `keychainMapping.firebase` slot forced a choice, and a crash URL
156
- # from the other project then failed the project_id check as if it were a
157
- # configuration error. `global.firebase.accounts[]` maps projectId -> keychain
158
- # key, and the URL's projectId picks the key. The single slot stays the fallback,
159
- # so a one-project setup needs no config at all.
160
- PREFS="$HOME/.claude/multi-agent-preferences.json"
161
- TOKEN_KEY="${FIREBASE_TOKEN_KEY:-}"
162
- FIREBASE_ACCOUNT_LABEL=""
163
- if [ -z "$TOKEN_KEY" ] && [ -f "$PREFS" ]; then
164
- ACCOUNT_HIT=$(WANT_PROJECT="$PROJECT_ID" python3 -c "
165
- import json, os
166
- want = os.environ.get('WANT_PROJECT') or ''
167
- try:
168
- g = json.load(open('$PREFS')).get('global', {})
169
- except Exception:
170
- g = {}
171
- for a in (g.get('firebase', {}) or {}).get('accounts') or []:
172
- if isinstance(a, dict) and str(a.get('projectId') or '') == want and a.get('keychainKey'):
173
- print('%s\t%s' % (a['keychainKey'], a.get('label') or a['projectId']))
174
- break
175
- else:
176
- print('%s\t' % ((g.get('keychainMapping', {}) or {}).get('firebase') or ''))
177
- " 2>/dev/null || printf '\t')
178
- TOKEN_KEY=$(printf '%s' "$ACCOUNT_HIT" | cut -f1)
179
- FIREBASE_ACCOUNT_LABEL=$(printf '%s' "$ACCOUNT_HIT" | cut -f2)
180
- fi
181
- [ -z "$TOKEN_KEY" ] && TOKEN_KEY="${USER}_Firebase_Access_Json"
182
-
183
- # Locate the resolver with an existence check, not a `.`-chain.
184
- #
185
- # Sourcing a file that does not exist aborts the shell under `set -e` - `||` included -
186
- # so `. <candidate> || . <candidate> || { error }` reaches neither its later candidates
187
- # nor its error branch. Every fetcher used that shape starting from `$HOME/.claude/...`,
188
- # so on a Copilot-only or Codex-only install they all died with a bare exit 1 and no
189
- # message. Reordering does not help: whichever candidate is absent aborts at that point.
190
- # Checking for the file before sourcing it is the only safe form.
191
- for _cred_resolver in \
192
- "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/credential-store-resolver.sh" \
193
- "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/../lib" 2>/dev/null && pwd)/credential-store-resolver.sh" \
194
- "$HOME/.claude/lib/credential-store-resolver.sh" \
195
- "$HOME/.copilot/lib/credential-store-resolver.sh" \
196
- "$HOME/.codex/lib/credential-store-resolver.sh"; do
197
- [ -f "$_cred_resolver" ] || continue
198
- # shellcheck source=/dev/null
199
- . "$_cred_resolver" 2>/dev/null || true
200
- # `if`, not `[ ... ] && break`: the latter is the loop body's last command and returns
201
- # 1 when CRED_STORE is still empty, which under `set -e` kills the loop on the first
202
- # candidate that does not resolve - the very case the loop exists to survive.
203
- if [ -n "${CRED_STORE:-}" ]; then break; fi
204
- done
205
- unset _cred_resolver
206
- if [ -z "${CRED_STORE:-}" ]; then
154
+ # redesign, or staging next to production - each with its own service-account
155
+ # key. The project id in the crash URL picks the account, so a URL from the
156
+ # other project resolves that project's key instead of failing the project_id
157
+ # check as if it were a configuration error.
158
+ _MA_FC_HERE="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
159
+ # shellcheck source=/dev/null
160
+ if [ -f "$_MA_FC_HERE/_service-account.sh" ]; then
161
+ . "$_MA_FC_HERE/_service-account.sh"
162
+ elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
163
+ . "$HOME/.claude/lib/_service-account.sh"
164
+ else
207
165
  [ "$PROBE" -eq 1 ] && probe_out unreachable no-credential-helper "$PROJECT_ID"
208
- printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"firebase","expected_key":"'"$TOKEN_KEY"'"}' >&2
166
+ printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"firebase"}' >&2
209
167
  exit 2
210
168
  fi
211
169
 
212
- SA_JSON_RAW=$("$CRED_STORE" get "$TOKEN_KEY" 2>/dev/null || true)
170
+ FIREBASE_PICK=()
171
+ if [ -n "${FIREBASE_TOKEN_KEY:-}" ]; then
172
+ FIREBASE_PICK+=(--item "$FIREBASE_TOKEN_KEY")
173
+ elif [ -n "${PROJECT_ID:-}" ]; then
174
+ FIREBASE_PICK+=(--project-id "$PROJECT_ID")
175
+ fi
176
+
177
+ FIREBASE_ACCOUNT_LABEL=$(sa_run select --service firebase "${FIREBASE_PICK[@]+"${FIREBASE_PICK[@]}"}" |
178
+ node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{process.stdout.write(JSON.parse(s).account.label||"")}catch{process.stdout.write("")}})' 2>/dev/null || true)
179
+
180
+ # The key is a service-account JSON handed to a Google client, not a header we
181
+ # write, so the value is produced rather than a curl config.
182
+ SA_JSON_RAW=$(sa_token firebase "https://oauth2.googleapis.com/token" \
183
+ "${FIREBASE_PICK[@]+"${FIREBASE_PICK[@]}"}" 2>/dev/null || true)
213
184
  if [ -z "$SA_JSON_RAW" ]; then
214
185
  [ "$PROBE" -eq 1 ] && probe_out no-credential nothing-stored "$PROJECT_ID"
215
- printf '%s\n' '{"status":"blocked","reason":"missing-token","service":"firebase","expected_key":"'"$TOKEN_KEY"'"}' >&2
186
+ printf '%s\n' '{"status":"blocked","reason":"missing-token","service":"firebase","projectId":"'"$PROJECT_ID"'"}' >&2
216
187
  exit 2
217
188
  fi
218
189
 
@@ -252,7 +223,7 @@ if [ -n "$SA_PROJECT" ] && [ "$SA_PROJECT" != "$PROJECT_ID" ]; then
252
223
  # with several Firebase projects in play, "project mismatch" alone does not
253
224
  # tell you whether the URL is wrong or the mapping is missing an account.
254
225
  echo "ERR: SA project_id ($SA_PROJECT) != URL project ($PROJECT_ID)" >&2
255
- echo " key used: $TOKEN_KEY${FIREBASE_ACCOUNT_LABEL:+ (account: $FIREBASE_ACCOUNT_LABEL)}" >&2
226
+ echo " account used: ${FIREBASE_ACCOUNT_LABEL:-firebase}" >&2
256
227
  echo " map this project: prefs.global.firebase.accounts[] += {\"projectId\":\"$PROJECT_ID\",\"keychainKey\":\"<keychain-key>\"}" >&2
257
228
  exit 5
258
229
  fi
@@ -69,12 +69,12 @@ for _figma_token_lib in \
69
69
  [ -f "$_figma_token_lib" ] || continue
70
70
  # shellcheck source=/dev/null
71
71
  . "$_figma_token_lib" 2>/dev/null || true
72
- if command -v resolve_figma_token >/dev/null 2>&1; then break; fi
72
+ if command -v figma_cfg >/dev/null 2>&1; then break; fi
73
73
  done
74
74
  unset _figma_token_lib
75
- if ! command -v resolve_figma_token >/dev/null 2>&1; then
76
- resolve_figma_token() { [ -n "${FIGMA_PAT:-}" ] && printf '%s' "$FIGMA_PAT"; }
77
- figma_token_remediation() { printf 'figma-token.sh not found - reinstall the pipeline, or export FIGMA_PAT.'; }
75
+ if ! command -v figma_cfg >/dev/null 2>&1; then
76
+ figma_cfg() { return 2; }
77
+ figma_token_remediation() { printf 'figma-token.sh not found - reinstall the pipeline.'; }
78
78
  fi
79
79
 
80
80
  FIGMA_API="https://api.figma.com/v1"
@@ -114,8 +114,7 @@ fi
114
114
  [ -z "$FILE_KEY" ] && die 1 "missing --file-key (or a --url to parse it from)"
115
115
  [ -z "$NODE_IDS" ] && die 1 "missing --node-id (or a --url to parse it from)"
116
116
 
117
- FIGMA_TOKEN=$(resolve_figma_token || true)
118
- if [ -z "$FIGMA_TOKEN" ]; then
117
+ if ! figma_cfg "$FIGMA_API/files/$FILE_KEY"; then
119
118
  printf '{"ok":false,"reason":"missing-token","source":"figma-rest","fileKey":"%s"}\n' "$FILE_KEY"
120
119
  die 2 "$(figma_token_remediation)"
121
120
  fi
@@ -123,9 +122,11 @@ fi
123
122
  TMPDIR_A=$(mktemp -d "${TMPDIR:-/tmp}/figma-annot.XXXXXX")
124
123
  trap 'rm -rf "$TMPDIR_A"' EXIT INT TERM
125
124
 
126
- # curl one /nodes batch (token via -K config so it never lands in argv).
125
+ # curl one /nodes batch. The config carries the URL as well as the credential,
126
+ # so the two cannot be separated and a redirect is refused, not followed.
127
127
  curl_nodes() {
128
128
  local out="$1" ids="$2" code
129
+ figma_cfg "$FIGMA_API/files/$FILE_KEY/nodes?ids=$ids" || { printf '000'; return 0; }
129
130
  # curl already writes "000" via -w on a total connection failure (and
130
131
  # still exits non-zero for it, which the inner `|| echo "000"` used to
131
132
  # catch too - so `code` became the literal string "000000", never
@@ -134,8 +135,7 @@ curl_nodes() {
134
135
  # into $code; `:-000` only fills in when curl fails before -w ever runs.
135
136
  code=$(curl -sS -o "$out" -w '%{http_code}' \
136
137
  --max-time "$HTTP_TIMEOUT" --connect-timeout 5 \
137
- -K <(printf 'header = "X-Figma-Token: %s"\n' "$FIGMA_TOKEN") \
138
- "$FIGMA_API/files/$FILE_KEY/nodes?ids=$ids") || true
138
+ --config "$FIGMA_CFG") || true
139
139
  code="${code:-000}"
140
140
  printf '%s' "$code"
141
141
  }