@mmerterden/multi-agent-pipeline 23.6.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 (167) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/README.md +61 -27
  3. package/README.tr.md +46 -12
  4. package/SECURITY.md +3 -3
  5. package/docs/architecture.md +47 -8
  6. package/docs/ecosystem.md +20 -18
  7. package/docs/engineering.md +1 -1
  8. package/docs/facts.json +8 -6
  9. package/docs/features.md +59 -15
  10. package/install/_codex-agents.mjs +13 -8
  11. package/install/_common.mjs +24 -0
  12. package/install/_dev-only-files.mjs +4 -0
  13. package/install/_mcp-register.mjs +6 -2
  14. package/install/_rewrite-tree.mjs +197 -0
  15. package/install/codex.mjs +96 -180
  16. package/install/copilot.mjs +24 -54
  17. package/install/index.mjs +29 -11
  18. package/install/templates/codex-instructions.md +21 -5
  19. package/install/templates/copilot-instructions.md +21 -14
  20. package/manifest.json +2082 -0
  21. package/package.json +6 -2
  22. package/pipeline/commands/multi-agent/SKILL.md +7 -5
  23. package/pipeline/commands/multi-agent/analysis/SKILL.md +4 -0
  24. package/pipeline/commands/multi-agent/autopilot-on/SKILL.md +31 -3
  25. package/pipeline/commands/multi-agent/autopilot-status/SKILL.md +5 -1
  26. package/pipeline/commands/multi-agent/channels/SKILL.md +16 -8
  27. package/pipeline/commands/multi-agent/log/SKILL.md +2 -0
  28. package/pipeline/commands/multi-agent/resume/SKILL.md +2 -0
  29. package/pipeline/commands/multi-agent/review-rounds/SKILL.md +94 -0
  30. package/pipeline/commands/multi-agent/stack/SKILL.md +1 -1
  31. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  32. package/pipeline/contract/manifest.json +1 -1
  33. package/pipeline/contract/types/index.d.ts +1 -0
  34. package/pipeline/lib/_jira-auth.sh +50 -78
  35. package/pipeline/lib/_service-account.sh +191 -0
  36. package/pipeline/lib/credential-inventory.sh +49 -37
  37. package/pipeline/lib/credential-store.sh +48 -3
  38. package/pipeline/lib/fetch-confluence.sh +76 -92
  39. package/pipeline/lib/fetch-crashlytics.sh +30 -59
  40. package/pipeline/lib/fetch-figma-annotations.sh +9 -9
  41. package/pipeline/lib/fetch-fortify.sh +77 -81
  42. package/pipeline/lib/fetch-graylog.sh +38 -77
  43. package/pipeline/lib/figma-mcp-refresh.sh +23 -4
  44. package/pipeline/lib/figma-screenshot.sh +7 -8
  45. package/pipeline/lib/figma-token.sh +39 -46
  46. package/pipeline/lib/host.mjs +138 -0
  47. package/pipeline/lib/host.sh +48 -0
  48. package/pipeline/lib/issue-fetcher.sh +25 -41
  49. package/pipeline/lib/jira-publish.sh +23 -21
  50. package/pipeline/lib/local-model.mjs +93 -0
  51. package/pipeline/lib/md2confluence-v3.py +37 -30
  52. package/pipeline/lib/model-dispatch.sh +41 -4
  53. package/pipeline/lib/model-resolve.mjs +58 -0
  54. package/pipeline/lib/post-pr-review.sh +38 -53
  55. package/pipeline/lib/reviewer-families.mjs +70 -0
  56. package/pipeline/lib/service-account.mjs +2131 -0
  57. package/pipeline/lib/service-account.sh +35 -0
  58. package/pipeline/lib/usage-names.generated.mjs +3 -0
  59. package/pipeline/lib/usage-token.mjs +64 -24
  60. package/pipeline/lib/usage-vocab.mjs +1 -1
  61. package/pipeline/lib/user-facing.mjs +11 -3
  62. package/pipeline/lib/vercel-deploy.sh +17 -26
  63. package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
  64. package/pipeline/multi-agent-refs/_input-parser.md +1 -1
  65. package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
  66. package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
  67. package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
  68. package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
  69. package/pipeline/multi-agent-refs/channels/generator.md +10 -2
  70. package/pipeline/multi-agent-refs/channels/menu.md +3 -1
  71. package/pipeline/multi-agent-refs/channels/preview.md +3 -1
  72. package/pipeline/multi-agent-refs/channels/reference.md +16 -2
  73. package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
  74. package/pipeline/multi-agent-refs/component-dispatch.md +2 -2
  75. package/pipeline/multi-agent-refs/cross-cli-contract.md +38 -30
  76. package/pipeline/multi-agent-refs/features/autopilot-circuit-breaker.md +4 -4
  77. package/pipeline/multi-agent-refs/features/doctor.md +37 -11
  78. package/pipeline/multi-agent-refs/features/free-models.md +3 -3
  79. package/pipeline/multi-agent-refs/features/local-model.md +87 -0
  80. package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
  81. package/pipeline/multi-agent-refs/features/product-context.md +6 -5
  82. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  83. package/pipeline/multi-agent-refs/features/review-rounds.md +40 -0
  84. package/pipeline/multi-agent-refs/features/rework-escalation.md +5 -4
  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 +31 -2
  88. package/pipeline/multi-agent-refs/help/tr.md +31 -2
  89. package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +3 -2
  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/operations.md +1 -1
  93. package/pipeline/multi-agent-refs/phases/phase-0-init.md +1 -1
  94. package/pipeline/multi-agent-refs/phases/phase-2-dev.md +4 -4
  95. package/pipeline/multi-agent-refs/phases/phase-3-review.md +7 -3
  96. package/pipeline/multi-agent-refs/phases/phase-5-report.md +12 -10
  97. package/pipeline/multi-agent-refs/phases.md +4 -3
  98. package/pipeline/multi-agent-refs/resume/details.md +2 -0
  99. package/pipeline/multi-agent-refs/review/panel.md +30 -18
  100. package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
  101. package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
  102. package/pipeline/multi-agent-refs/sync/overview.md +11 -5
  103. package/pipeline/multi-agent-refs/tracker-contract.md +28 -10
  104. package/pipeline/office/index.html +4 -4
  105. package/pipeline/schemas/agent-state.schema.json +19 -1
  106. package/pipeline/schemas/autopilot-config.schema.json +29 -4
  107. package/pipeline/schemas/hosts.json +512 -0
  108. package/pipeline/schemas/hosts.schema.json +310 -0
  109. package/pipeline/schemas/launch.json +22 -2
  110. package/pipeline/schemas/launch.schema.json +2 -1
  111. package/pipeline/schemas/phases.json +21 -3
  112. package/pipeline/schemas/phases.schema.json +8 -0
  113. package/pipeline/schemas/prefs.schema.json +346 -7
  114. package/pipeline/schemas/token-budget.json +2 -2
  115. package/pipeline/scripts/.doctor-mut.47076.mjs +2253 -0
  116. package/pipeline/scripts/_autopilot-config.mjs +67 -4
  117. package/pipeline/scripts/_autopilot-item.mjs +67 -0
  118. package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
  119. package/pipeline/scripts/_cost.mjs +75 -3
  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 +16 -13
  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 +146 -38
  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/report-file.mjs +285 -0
  145. package/pipeline/scripts/review-rounds.mjs +592 -0
  146. package/pipeline/scripts/rework-escalation.mjs +26 -7
  147. package/pipeline/scripts/service-read.mjs +19 -17
  148. package/pipeline/scripts/skill-siblings.mjs +17 -1
  149. package/pipeline/scripts/status-overview.mjs +20 -10
  150. package/pipeline/scripts/uninstall.mjs +145 -57
  151. package/pipeline/scripts/usage-register.mjs +34 -11
  152. package/pipeline/scripts/usage-report.mjs +31 -26
  153. package/pipeline/scripts/validate-state.mjs +19 -11
  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 +11 -7
  158. package/pipeline/skills/.skills-index.json +13 -2
  159. package/pipeline/skills/shared/README.md +4 -3
  160. package/pipeline/skills/shared/core/multi-agent/SKILL.md +14 -6
  161. package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
  162. package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
  163. package/pipeline/skills/shared/core/multi-agent-resume/SKILL.md +1 -1
  164. package/pipeline/skills/shared/core/multi-agent-review-rounds/SKILL.md +92 -0
  165. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  166. package/pipeline/skills/skills-index.md +2 -1
  167. package/pipeline/lib/credential-resolve.mjs +0 -75
@@ -1,71 +1,64 @@
1
1
  #!/bin/bash
2
2
  #
3
3
  # figma-token.sh
4
- # Single resolution point for the Tier 2 Figma Personal Access Token.
4
+ # The one place a Tier 2 Figma request gets its credential.
5
5
  #
6
6
  # Sourced by every Tier 2 fetcher (fetch-figma-annotations.sh,
7
7
  # figma-screenshot.sh). It exists because those two each carried their own copy
8
- # of this lookup: when `migrate-prefs.mjs` consolidated
9
- # `keychainMapping.figma_pat` into `keychainMapping.figma` and deleted the old
10
- # key, only the migration was updated. Both fetchers kept reading the deleted
11
- # key, so every migrated install reported `missing-token` while a valid PAT sat
12
- # under the new name - and the error text told the user to map the key the
13
- # migration had just removed. One copy of the lookup cannot drift from itself.
8
+ # of the lookup, and a copy drifts: when the key a fetcher read was renamed,
9
+ # only one of the three places learned about it, and a valid PAT read as
10
+ # `missing-token` while the error text named a key that no longer existed. One
11
+ # copy of the lookup cannot drift from itself.
14
12
  #
15
13
  # Tier 2 is only reached when Tier 1 (Figma MCP) is unreachable; see the Figma
16
14
  # Access Tier rule in multi-agent-refs/rules.md for the chain and the
17
15
  # expired-token decision that gates the move to Tier 3.
18
16
  #
19
- # Resolution order, first non-empty wins:
20
- # 1. credential-store.sh get figma - the canonical logical key
21
- # 2. credential-store.sh get figma_pat - pre-v13.6 installs that never migrated
22
- # 3. $FIGMA_PAT - env fallback for CI and one-shot runs
17
+ # Resolution goes through the account resolver, which owns the whole question:
18
+ # which account answers for Figma, which store item holds its PAT, whether the
19
+ # environment carries one instead, and whether the URL being called is one that
20
+ # account may be sent to. No logical key, no store path and no Keychain service
21
+ # name appears here, which is what keeps the Synced Command Hygiene rule
22
+ # satisfied by construction rather than by review.
23
23
  #
24
- # Logical keys are passed through verbatim. credential-store.sh owns the
25
- # `prefs.global.keychainMapping` indirection, so resolving the mapping here as
26
- # well would reintroduce the duplication this file exists to remove. No literal
27
- # Keychain service name appears here, which keeps the Synced Command Hygiene
28
- # rule satisfied.
24
+ # Usage:
25
+ # figma_cfg "https://api.figma.com/v1/..." # sets FIGMA_CFG, or returns non-zero
26
+ # curl --config "$FIGMA_CFG" ...
29
27
  #
30
- # Requires `$CRED_STORE` to already be resolved (via credential-store-resolver.sh).
31
- # An unset or non-executable CRED_STORE is tolerated: resolution falls through to
32
- # the env fallback so a keychain-less CI box still works.
28
+ # The credential never reaches a shell variable: it is written into a curl
29
+ # config that also carries the URL it is for, so the two cannot be separated
30
+ # and a redirect is refused rather than followed with the header on.
33
31
 
34
32
  _MA_FT_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35
33
  # shellcheck source=/dev/null
36
34
  if [ -f "$_MA_FT_HERE/user-facing.sh" ]; then . "$_MA_FT_HERE/user-facing.sh"; else . "$HOME/.claude/lib/user-facing.sh"; fi
35
+ # shellcheck source=/dev/null
36
+ if [ -f "$_MA_FT_HERE/_service-account.sh" ]; then
37
+ . "$_MA_FT_HERE/_service-account.sh"
38
+ elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
39
+ . "$HOME/.claude/lib/_service-account.sh"
40
+ fi
37
41
 
38
- # The canonical key first, the legacy key second. Space-separated; the loop
39
- # below splits explicitly because zsh (the pipeline's Bash tool) does not
40
- # word-split an unquoted parameter, so `for key in $KEYS` saw one key there.
41
- FIGMA_TOKEN_LOGICAL_KEYS="${FIGMA_TOKEN_LOGICAL_KEYS:-figma figma_pat}"
42
-
43
- # resolve_figma_token
44
- # Prints the token on stdout and returns 0, or prints nothing and returns 1.
45
- resolve_figma_token() {
46
- local key tok
47
- if [ -n "${CRED_STORE:-}" ] && [ -x "${CRED_STORE:-}" ]; then
48
- while IFS= read -r key; do
49
- [ -n "$key" ] || continue
50
- tok=$("$CRED_STORE" get "$key" 2>/dev/null || true)
51
- if [ -n "$tok" ]; then
52
- printf '%s' "$tok"
53
- return 0
54
- fi
55
- done <<EOF_KEYS
56
- $(printf '%s\n' "$FIGMA_TOKEN_LOGICAL_KEYS" | tr ' ' '\n')
57
- EOF_KEYS
58
- fi
59
- if [ -n "${FIGMA_PAT:-}" ]; then
60
- printf '%s' "$FIGMA_PAT"
61
- return 0
42
+ # figma_cfg <url>
43
+ # Sets FIGMA_CFG to a curl config carrying the PAT to that URL, or returns
44
+ # non-zero with the refusal available from sa_reason / sa_explain.
45
+ #
46
+ # It sets a variable rather than printing one because a caller reading it
47
+ # through a command substitution runs in a subshell, where a refusal branch's
48
+ # `exit` ends the subshell and the caller carries on unauthenticated.
49
+ # shellcheck disable=SC2034 # read by the fetchers that source this file
50
+ FIGMA_CFG=""
51
+ figma_cfg() {
52
+ if ! command -v sa_cfg >/dev/null 2>&1; then
53
+ return 2
62
54
  fi
63
- return 1
55
+ # shellcheck disable=SC2034 # read by the fetchers that source this file
56
+ FIGMA_CFG="$(sa_cfg figma "$1" figma-pat)"
64
57
  }
65
58
 
66
59
  # figma_token_remediation
67
60
  # The one place the "how do I fix this" sentence is written, so a fetcher can
68
- # never name a key the migration deleted.
61
+ # never name a key that does not exist.
69
62
  figma_token_remediation() {
70
- printf 'no Figma PAT for Tier 2. Map prefs.global.keychainMapping.figma (run %s), or export FIGMA_PAT.' "$(ma_command setup)"
63
+ printf 'no Figma PAT for Tier 2. Add a Figma account with %s, or export FIGMA_PAT.' "$(ma_command setup)"
71
64
  }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * host.mjs - which host this code is installed under, and what that host is
3
+ * called.
4
+ *
5
+ * `pipeline/schemas/hosts.json` is the single source. Everything here reads a
6
+ * field off it; nothing here compares a host name to a literal. A new host is a
7
+ * record in that file plus an installer module, not a branch added in each
8
+ * consumer.
9
+ *
10
+ * The registry is packaged data, never user input: it names install roots and
11
+ * argv, so opening it to extension would be a path-traversal and
12
+ * command-injection surface.
13
+ *
14
+ * @module pipeline/lib/host
15
+ */
16
+
17
+ import { existsSync, readFileSync } from "fs";
18
+ import { basename, dirname, join } from "path";
19
+ import { fileURLToPath } from "url";
20
+
21
+ // `fileURLToPath`, not `new URL(...).pathname`: the pathname keeps its
22
+ // percent-encoding, so an install under a home directory with a space in it
23
+ // would look for a file whose name contains `%20`. This module is imported by
24
+ // `user-facing.mjs`, which most of the pipeline imports, so that failure is not
25
+ // one script refusing to run - it is all of them.
26
+ const HERE = dirname(fileURLToPath(import.meta.url));
27
+
28
+ // What answers when the registry is not on disk. An install missing its schemas
29
+ // tree is broken, and the check that SAYS so lives in a script that imports this
30
+ // module, so throwing here would silence the only thing able to report the
31
+ // cause. The fallback describes the state root and the host the paths are
32
+ // authored against; `install-present` then names the missing tree.
33
+ const FALLBACK = Object.freeze({
34
+ version: "0",
35
+ order: ["claude"],
36
+ stateRoot: ".claude",
37
+ hosts: {
38
+ claude: {
39
+ label: "Claude Code",
40
+ install: { root: ".claude", subtrees: ["scripts", "lib", "schemas"] },
41
+ detect: { rootSegment: ".claude" },
42
+ command: { template: "/multi-agent:{sub}" },
43
+ models: { rungs: {} },
44
+ },
45
+ },
46
+ });
47
+
48
+ function loadRegistry() {
49
+ try {
50
+ return JSON.parse(readFileSync(join(HERE, "..", "schemas", "hosts.json"), "utf8"));
51
+ } catch {
52
+ return FALLBACK;
53
+ }
54
+ }
55
+
56
+ /** @type {{version: string, order: string[], stateRoot: string, hosts: Record<string, any>}} */
57
+ export const REGISTRY = loadRegistry();
58
+
59
+ /** Host ids in the order the installer and every user-facing listing uses them. */
60
+ export const HOST_IDS = Object.freeze([...REGISTRY.order]);
61
+
62
+ /** The tree shared state lives in, whichever hosts are installed. `.claude`. */
63
+ export const STATE_ROOT = REGISTRY.stateRoot;
64
+
65
+ /**
66
+ * The host record, or null for an unknown id.
67
+ *
68
+ * @param {string} id
69
+ * @returns {object|null}
70
+ */
71
+ export function host(id) {
72
+ return REGISTRY.hosts[id] ?? null;
73
+ }
74
+
75
+ /**
76
+ * The directory a host installs into, e.g. `/Users/x/.copilot`.
77
+ *
78
+ * @param {string} home
79
+ * @param {string} id
80
+ * @returns {string|null} null for an unknown id
81
+ */
82
+ export function hostRoot(home, id) {
83
+ const h = host(id);
84
+ return h ? join(home, h.install.root) : null;
85
+ }
86
+
87
+ /**
88
+ * Which host a file belongs to, read from the path it sits at.
89
+ *
90
+ * Takes the directory a tree lives in - `~/.copilot/scripts`, `~/.codex/lib` -
91
+ * and answers with the host id, or null when the path is outside every install
92
+ * (a repo checkout, most often).
93
+ *
94
+ * @param {string} dir
95
+ * @returns {string|null}
96
+ */
97
+ function hostIdFromDir(dir) {
98
+ const segment = basename(dirname(dir));
99
+ for (const id of HOST_IDS) {
100
+ if (REGISTRY.hosts[id].detect.rootSegment === segment) return id;
101
+ }
102
+ return null;
103
+ }
104
+
105
+ /**
106
+ * Which host this module is running from, or null in a repo checkout.
107
+ *
108
+ * @param {string} [dir] - defaults to this file's own directory
109
+ * @returns {string|null}
110
+ */
111
+ export function currentHostId(dir = HERE) {
112
+ return hostIdFromDir(dir);
113
+ }
114
+
115
+ /**
116
+ * How the user types a pipeline sub-command on a host.
117
+ *
118
+ * @param {string} id
119
+ * @param {string} sub
120
+ * @returns {string}
121
+ */
122
+ export function hostCommandFor(id, sub) {
123
+ const h = host(id) ?? host(HOST_IDS[0]);
124
+ return h.command.template.replace("{sub}", sub);
125
+ }
126
+
127
+ /**
128
+ * The hosts that actually have an install under `home`.
129
+ *
130
+ * Presence is the version stamp, not the directory: `~/.codex` exists on any
131
+ * machine with Codex CLI, installed pipeline or not.
132
+ *
133
+ * @param {string} home
134
+ * @returns {string[]} ids, in registry order
135
+ */
136
+ export function installedHostIds(home) {
137
+ return HOST_IDS.filter((id) => existsSync(join(hostRoot(home, id), ".pipeline-version")));
138
+ }
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+ # host.sh - which host a shell script is running under, and what the registry
3
+ # says about it.
4
+ #
5
+ # The mjs side is pipeline/lib/host.mjs and reads the same file. Source this
6
+ # rather than matching a host name: `pipeline/schemas/hosts.json` is the single
7
+ # source, and a script that compares `$HOST` to a literal is a script that has
8
+ # to be edited again when a host is added.
9
+ #
10
+ # Usage:
11
+ # . "$(dirname "${BASH_SOURCE[0]}")/host.sh"
12
+ # id=$(ma_host_id) # a host id, or empty off an install
13
+ # ma_host_has_provider anthropic && ...
14
+ #
15
+ # Every function answers from the registry that shipped with THIS install, so a
16
+ # script copied into another host's tree answers for that host. Without jq there
17
+ # is no answer at all rather than a wrong one: callers treat an empty answer the
18
+ # way they treat a missing preference.
19
+
20
+ # The registry, resolved from this file's own location so it works in the repo
21
+ # (pipeline/lib -> pipeline/schemas) and in an install (<root>/lib -> <root>/schemas).
22
+ ma_host_registry() {
23
+ printf '%s\n' "$(cd "$(dirname "${BASH_SOURCE[0]}")/../schemas" 2>/dev/null && pwd)/hosts.json"
24
+ }
25
+
26
+ # The host whose tree this file sits in, or empty from a repo checkout.
27
+ ma_host_id() {
28
+ local reg seg
29
+ reg=$(ma_host_registry)
30
+ [ -f "$reg" ] || return 0
31
+ command -v jq >/dev/null 2>&1 || return 0
32
+ seg=$(basename "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd)")
33
+ jq -r --arg seg "$seg" \
34
+ '[.hosts | to_entries[] | select(.value.detect.rootSegment == $seg) | .key][0] // ""' \
35
+ "$reg" 2>/dev/null || true
36
+ }
37
+
38
+ # True when this host dispatches to the named provider.
39
+ ma_host_has_provider() {
40
+ local reg id
41
+ reg=$(ma_host_registry)
42
+ id=$(ma_host_id)
43
+ [ -f "$reg" ] || return 1
44
+ command -v jq >/dev/null 2>&1 || return 1
45
+ [ -n "$id" ] || id=$(jq -r '.order[0]' "$reg" 2>/dev/null)
46
+ jq -e --arg id "$id" --arg p "$1" \
47
+ '(.hosts[$id].models.providers // []) | index($p) != null' "$reg" >/dev/null 2>&1
48
+ }
@@ -200,51 +200,35 @@ def bound_comments(rows):
200
200
  return kept
201
201
  '
202
202
 
203
- # Bearer-auth via a curl config fed through process substitution so the
204
- # token never appears in argv (argv is visible to `ps` / process audit).
205
- jira_auth_cfg() { printf 'header = "Authorization: Bearer %s"\n' "$1"; }
203
+ # shellcheck source=_service-account.sh
204
+ if [ -f "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/_service-account.sh" ]; then
205
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/_service-account.sh"
206
+ elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
207
+ # shellcheck source=/dev/null
208
+ . "$HOME/.claude/lib/_service-account.sh"
209
+ fi
206
210
 
207
- # Resolve the credential helper once and issue one authenticated GET. Split
208
- # out of fetch_jira so the sibling search reuses the same resolution instead
209
- # of duplicating thirty lines of it.
211
+ # One authenticated GET. Split out of fetch_jira so the sibling search reuses
212
+ # the same resolution instead of duplicating it. The credential is written into
213
+ # a config that carries the URL too, so a redirect cannot carry the header and
214
+ # the token never reaches argv or a shell variable.
210
215
  jira_curl() {
211
- local path="$1"
212
- if [ -z "$JIRA_HOST" ] || [ -z "$JIRA_TOKEN_KEY" ]; then
213
- echo "ERR: ACCOUNT_JIRA_HOST and ACCOUNT_JIRA_TOKEN_KEY must be set" >&2
216
+ local path="$1" cfg host
217
+ # The account answers both halves of the question: which instance this run
218
+ # talks to, and the credential for it. ACCOUNT_JIRA_HOST and
219
+ # ACCOUNT_JIRA_TOKEN_KEY still name one when a caller sets them.
220
+ local -a sel=()
221
+ [ -n "${JIRA_HOST:-}" ] && sel+=(--host "$JIRA_HOST")
222
+ [ -n "${JIRA_TOKEN_KEY:-}" ] && sel+=(--item "$JIRA_TOKEN_KEY")
223
+ host="$(sa_host jira "${sel[@]+"${sel[@]}"}")" || {
224
+ echo "ERR: no Jira account for this run: $(sa_explain)" >&2
214
225
  return 1
215
- fi
216
- # Resolve the credential helper via the shared resolver (works from the
217
- # repo checkout and from both install trees) - never hardcode the path.
218
- # A pre-set CRED_STORE (tests, custom installs) is honored as-is.
219
- if [ -z "${CRED_STORE:-}" ]; then
220
- # shellcheck disable=SC1090,SC1091
221
- # Existence check before sourcing: `. <missing>` aborts the shell under `set -e`,
222
- # `||` included, so a `.`-chain reaches neither its later candidates nor its error
223
- # branch. The loop also covers all three hosts - the chain it replaced knew only
224
- # .claude and .copilot, so a Codex-only install could not resolve at all.
225
- for _cred_resolver in \
226
- "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/credential-store-resolver.sh" \
227
- "$HOME/.claude/lib/credential-store-resolver.sh" \
228
- "$HOME/.copilot/lib/credential-store-resolver.sh" \
229
- "$HOME/.codex/lib/credential-store-resolver.sh"; do
230
- [ -f "$_cred_resolver" ] || continue
231
- # shellcheck source=/dev/null
232
- . "$_cred_resolver" 2>/dev/null || true
233
- if [ -n "${CRED_STORE:-}" ]; then break; fi
234
- done
235
- unset _cred_resolver
236
- if [ -z "${CRED_STORE:-}" ]; then
237
- echo "ERR: credential helper not found" >&2
238
- return 1
239
- fi
240
- fi
241
- local token
242
- token=$("$CRED_STORE" get "$JIRA_TOKEN_KEY" 2>/dev/null || true)
243
- if [ -z "$token" ]; then
244
- echo "ERR: Jira token not found in credential store ($JIRA_TOKEN_KEY)" >&2
226
+ }
227
+ cfg="$(sa_cfg jira "https://$host$path" bearer "${sel[@]+"${sel[@]}"}")" || {
228
+ echo "ERR: $(sa_explain)" >&2
245
229
  return 1
246
- fi
247
- curl -sf -m 30 -K <(jira_auth_cfg "$token") "https://$JIRA_HOST$path"
230
+ }
231
+ curl -sf -m 30 --config "$cfg"
248
232
  }
249
233
 
250
234
  # The field list is a parameter because the related-issue lookup wants a
@@ -89,7 +89,6 @@ ma_outbound_gate() {
89
89
  }
90
90
 
91
91
  SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
92
- PREFS="${MULTI_AGENT_PREFS:-$HOME/.claude/multi-agent-preferences.json}"
93
92
  CURL="${JIRA_PUBLISH_CURL:-curl}"
94
93
 
95
94
  ISSUE=""
@@ -135,26 +134,29 @@ for cand in "$SELF_DIR/../scripts/jira-wiki-escape.mjs" "$HOME/.claude/scripts/j
135
134
  done
136
135
  [ -n "$ESCAPER" ] || die "jira-wiki-escape.mjs not found next to lib/ or in ~/.claude/scripts" 4
137
136
 
138
- HOST="${JIRA_HOST:-}"
139
- if [ -z "$HOST" ] && [ -f "$PREFS" ]; then
140
- HOST=$(jq -r '.global.hosts.jira // empty' "$PREFS" 2>/dev/null || echo "")
141
- fi
142
- [ -n "$HOST" ] || die "no Jira host: set JIRA_HOST or prefs .global.hosts.jira" 4
143
- HOST="${HOST#https://}"; HOST="${HOST#http://}"; HOST="${HOST%/}"
144
-
145
- TOKEN="${JIRA_TOKEN:-}"
146
- if [ -z "$TOKEN" ]; then
147
- key="${JIRA_TOKEN_KEY:-}"
148
- if [ -z "$key" ] && [ -f "$PREFS" ]; then
149
- key=$(jq -r '.global.keychainMapping.jira // empty' "$PREFS" 2>/dev/null || echo "")
150
- fi
151
- [ -n "$key" ] || die "no Jira token: set JIRA_TOKEN or map prefs .global.keychainMapping.jira" 4
152
- TOKEN=$("$SELF_DIR/credential-store.sh" get "$key" 2>/dev/null || echo "")
153
- [ -n "$TOKEN" ] || die "Jira token not in the credential store under: $key" 4
154
- fi
155
-
156
- auth_cfg() { printf 'header = "Authorization: Bearer %s"\n' "$1"; }
157
- api() { "$CURL" -sS -m 30 -K <(auth_cfg "$TOKEN") -H "Content-Type: application/json" "$@"; }
137
+ # shellcheck source=_jira-auth.sh
138
+ . "$SELF_DIR/_jira-auth.sh"
139
+ jira_auth_resolve || exit 4
140
+ HOST="$JIRA_API_HOST"
141
+
142
+ # The URL is the last argument, as every call site already writes it, and it is
143
+ # the one thing that decides which credential may go out. It is handed to the
144
+ # resolver rather than to curl: the config that comes back carries the URL, the
145
+ # scheme lock and the header together, so nothing can point curl elsewhere
146
+ # between the check and the request. The token never reaches a variable here.
147
+ api() {
148
+ local -a args=("$@")
149
+ local last=$((${#args[@]} - 1))
150
+ local url="${args[$last]}"
151
+ unset "args[$last]"
152
+ local cfg
153
+ cfg="$(sa_cfg jira "$url" bearer "${JIRA_AUTH_SELECTORS[@]+"${JIRA_AUTH_SELECTORS[@]}"}")" || {
154
+ echo "ERR: $(sa_explain)" >&2
155
+ return 4
156
+ }
157
+ "$CURL" -sS -m 30 --config "$cfg" -H "Content-Type: application/json" \
158
+ "${args[@]+"${args[@]}"}"
159
+ }
158
160
 
159
161
  WORK="$(mktemp -d)"
160
162
  trap 'rm -rf "$WORK"' EXIT
@@ -0,0 +1,93 @@
1
+ /**
2
+ * local-model.mjs - the one place a user-chosen local model and server
3
+ * address are read and checked.
4
+ *
5
+ * The host registry is packaged data and names install roots and argv, so it is
6
+ * not extensible. The two things that ARE the user's - which model answers, and
7
+ * where it is served - live in preferences, and everything they reach is
8
+ * validated here before it is written into a config file or an agent TOML.
9
+ *
10
+ * The address is loopback by default and an address off this machine takes an
11
+ * explicit opt-in: a base URL is where every prompt in a run is sent, so a typo
12
+ * that resolves is a silent exfiltration path rather than an error.
13
+ *
14
+ * @module pipeline/lib/local-model
15
+ */
16
+
17
+ import { existsSync, readFileSync } from "fs";
18
+
19
+ /** Model ids this writes: a narrow set, because the value reaches a TOML file. */
20
+ const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
21
+
22
+ /** Hosts that are this machine. Anything else needs `allowRemote`. */
23
+ const LOOPBACK = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
24
+
25
+ /**
26
+ * `prefs.global.localModel`, or null when the file does not read.
27
+ *
28
+ * @param {string} prefsPath
29
+ * @returns {{baseUrl?: string, model?: string, contextWindow?: number, allowRemote?: boolean}|null}
30
+ */
31
+ function readLocalModel(prefsPath) {
32
+ if (!prefsPath || !existsSync(prefsPath)) return null;
33
+ try {
34
+ const parsed = JSON.parse(readFileSync(prefsPath, "utf8"));
35
+ const cfg = parsed?.global?.localModel;
36
+ return cfg && typeof cfg === "object" ? cfg : null;
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Why this configuration cannot be used, or null when it can.
44
+ *
45
+ * Every answer names the field and what it has to be, because the person
46
+ * reading it is editing a JSON file by hand.
47
+ *
48
+ * @param {object|null} cfg
49
+ * @returns {string|null}
50
+ */
51
+ export function localModelProblem(cfg) {
52
+ if (!cfg) return "global.localModel is not set in preferences";
53
+ if (typeof cfg.model !== "string" || !MODEL_NAME.test(cfg.model)) {
54
+ return "global.localModel.model must be a model id of letters, digits and . _ : / -";
55
+ }
56
+ if (typeof cfg.baseUrl !== "string" || !cfg.baseUrl) {
57
+ return "global.localModel.baseUrl must be the server's base URL";
58
+ }
59
+ let url;
60
+ try {
61
+ url = new URL(cfg.baseUrl);
62
+ } catch {
63
+ return `global.localModel.baseUrl is not a URL: ${cfg.baseUrl}`;
64
+ }
65
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
66
+ return `global.localModel.baseUrl must be http or https, not ${url.protocol}`;
67
+ }
68
+ if (!LOOPBACK.has(url.hostname) && cfg.allowRemote !== true) {
69
+ return `global.localModel.baseUrl points at ${url.hostname}, which is not this machine; set global.localModel.allowRemote to true to send prompts there on purpose`;
70
+ }
71
+ if (!Number.isInteger(cfg.contextWindow) || cfg.contextWindow < 8192) {
72
+ // Measured, not guessed: a trivial one-turn request already carries about
73
+ // 45 KB of instructions before the task itself, and a phase spec is larger
74
+ // again. Below this the diff is truncated and the run reports on a file it
75
+ // never saw.
76
+ return "global.localModel.contextWindow must be an integer of at least 8192 tokens";
77
+ }
78
+ return null;
79
+ }
80
+
81
+ /**
82
+ * The model id to bind agents to, or null when the configuration is unusable.
83
+ *
84
+ * Null is a working answer: agents are written without a model and the children
85
+ * inherit the session's.
86
+ *
87
+ * @param {string} prefsPath
88
+ * @returns {string|null}
89
+ */
90
+ export function localModelName(prefsPath) {
91
+ const cfg = readLocalModel(prefsPath);
92
+ return localModelProblem(cfg) === null ? cfg.model : null;
93
+ }
@@ -21,8 +21,8 @@ Authentication:
21
21
  CONFLUENCE_BASE_URL - base URL, e.g. https://confluence.example.com
22
22
  CONFLUENCE_USER - user (informational; bearer token auth is used)
23
23
  Token is resolved from ~/.claude/lib/credential-store.sh using the logical key
24
- found in ~/.claude/multi-agent-preferences.json .global.keychainMapping.confluence
25
- If that path fails, env CONFLUENCE_TOKEN is used as a fallback.
24
+ resolved by the account resolver for the host CONFLUENCE_BASE_URL names.
25
+ An account that does not cover that host is refused, not used.
26
26
 
27
27
  Output:
28
28
  JSON envelope on stdout describing what happened (page id, url, attachments,
@@ -578,31 +578,38 @@ class ConfluenceAuth:
578
578
  user: str | None = None
579
579
 
580
580
 
581
- def resolve_token() -> str | None:
582
- prefs_path = Path.home() / ".claude" / "multi-agent-preferences.json"
583
- cred_script = Path.home() / ".claude" / "lib" / "credential-store.sh"
584
- if prefs_path.exists() and cred_script.exists():
585
- try:
586
- with prefs_path.open(encoding="utf-8") as fh:
587
- prefs = json.load(fh)
588
- logical = (
589
- prefs.get("global", {})
590
- .get("keychainMapping", {})
591
- .get("confluence")
592
- )
593
- if logical:
594
- proc = subprocess.run(
595
- [str(cred_script), "get", str(logical)],
596
- capture_output=True,
597
- text=True,
598
- timeout=10,
599
- )
600
- token = (proc.stdout or "").strip()
601
- if proc.returncode == 0 and token:
602
- return token
603
- except (OSError, json.JSONDecodeError, subprocess.SubprocessError):
604
- pass
605
- return os.environ.get("CONFLUENCE_TOKEN") or None
581
+ def _resolver() -> Path | None:
582
+ for candidate in (
583
+ Path(__file__).resolve().parent / "service-account.sh",
584
+ Path.home() / ".claude" / "lib" / "service-account.sh",
585
+ ):
586
+ if candidate.is_file():
587
+ return candidate
588
+ return None
589
+
590
+
591
+ def resolve_token(base_url: str) -> str | None:
592
+ """The credential for this base URL, or None when no account covers it.
593
+
594
+ The destination is part of the question, not something checked afterwards:
595
+ CONFLUENCE_BASE_URL comes from the caller, and an account that does not
596
+ name that host is refused rather than used.
597
+ """
598
+ script = _resolver()
599
+ if script is None:
600
+ return None
601
+ try:
602
+ proc = subprocess.run(
603
+ [str(script), "token", "--service", "confluence", "--url", base_url],
604
+ capture_output=True,
605
+ text=True,
606
+ timeout=15,
607
+ )
608
+ except (OSError, subprocess.SubprocessError):
609
+ return None
610
+ if proc.returncode != 0:
611
+ return None
612
+ return proc.stdout or None
606
613
 
607
614
 
608
615
  def resolve_auth() -> ConfluenceAuth:
@@ -610,11 +617,11 @@ def resolve_auth() -> ConfluenceAuth:
610
617
  if not base:
611
618
  sys.stderr.write("error: CONFLUENCE_BASE_URL is not set\n")
612
619
  sys.exit(2)
613
- token = resolve_token()
620
+ token = resolve_token(base)
614
621
  if not token:
615
622
  sys.stderr.write(
616
- "error: no Confluence token available (credential-store + "
617
- "CONFLUENCE_TOKEN both empty)\n"
623
+ "error: no Confluence account answers for "
624
+ f"{base} - add one with /multi-agent:setup\n"
618
625
  )
619
626
  sys.exit(2)
620
627
  return ConfluenceAuth(base_url=base, token=token, user=os.environ.get("CONFLUENCE_USER"))