@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
@@ -0,0 +1,197 @@
1
+ /**
2
+ * _rewrite-tree.mjs - copy a tree, retargeting the paths inside it, and lay
3
+ * down the reference tree a host reads on demand.
4
+ *
5
+ * Every ref and sub-command spec is written against `$HOME/.claude/...`. A host
6
+ * that keeps its own tree has to retarget those strings as the files land, so
7
+ * the copy is a rewrite, not `copyDir` from `_common.mjs` (which copies bytes).
8
+ *
9
+ * The rewrite itself is the host's: each installer passes its own path map in.
10
+ * Everything else - which trees are copied, in what order, and which file the
11
+ * router already shipped and must not be copied twice - is the same wherever
12
+ * the refs land, so it lives here once.
13
+ *
14
+ * @module install/_rewrite-tree
15
+ */
16
+
17
+ import { existsSync, readFileSync, readdirSync } from "fs";
18
+ import { join } from "path";
19
+
20
+ import { ensureDir, ensureRealDir, wipeDir, writeFile } from "./_common.mjs";
21
+ import { REGISTRY, STATE_ROOT } from "../pipeline/lib/host.mjs";
22
+
23
+ /** Regex-escape a path fragment, including `/`, which the ordering tests read. */
24
+ const esc = (p) => p.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
25
+
26
+ /** Matches either spelling of the home directory, captured so it survives. */
27
+ const HOME_RE = "(\\$HOME|~)";
28
+
29
+ /**
30
+ * One path segment as the authored text actually spells it.
31
+ *
32
+ * Not a bare word class. A reference is as often a placeholder as a literal:
33
+ * the dispatch contract names a persona by variable, the help pages name
34
+ * `commands/multi-agent/<name>`, the sync tables name `{cmd}`, and a glob
35
+ * stands in for the whole set. Each of those is a line a reader follows, so a
36
+ * class matching only literals leaves exactly those lines pointing into a tree
37
+ * the host does not write.
38
+ */
39
+ const NAME = "[A-Za-z0-9_\\$\\{\\}<>*-]+";
40
+
41
+ /**
42
+ * The host's path map, built from its registry record.
43
+ *
44
+ * Every ref, spec and skill is authored against the state root. A host that
45
+ * keeps its own trees has to retarget those strings as the files land, and the
46
+ * ORDER of the rules is load-bearing: a rule matching a shorter prefix placed
47
+ * first swallows the longer one and produces a path that does not exist. The
48
+ * registry stores them in order and this builder preserves it.
49
+ *
50
+ * Three shapes, because three things can happen to a path:
51
+ * - `exact` the whole path becomes another whole path (the dispatcher)
52
+ * - `segment` `<from>/<name>` becomes `<to><name>` (a directory per
53
+ * sub-command becomes a flat, prefixed skill name)
54
+ * - `prefix` the leading directory moves, the rest of the path rides along
55
+ * - `root` one whole install root becomes another, for a second install of
56
+ * the same engine
57
+ * plus `extension`, which runs last and rewrites a file suffix inside a tree
58
+ * the host already owns - a persona is Markdown on one host and TOML on another,
59
+ * so moving its directory is not enough.
60
+ *
61
+ * @param {string} hostId
62
+ * @returns {ReadonlyArray<{from: RegExp, to: string}>}
63
+ */
64
+ export function buildPathRewrites(hostId) {
65
+ const root = REGISTRY.hosts[hostId].install.root;
66
+ const home = `${esc("/" + STATE_ROOT)}`;
67
+ const rules = [];
68
+ for (const rule of REGISTRY.hosts[hostId].install.pathRewrites) {
69
+ if (rule.match === "root") {
70
+ // A second install of the same engine: the authored text names the
71
+ // engine's default tree, and this one keeps its own. The lookahead is
72
+ // what makes the rule safe to run beside the others - without it the
73
+ // replacement matches its own output and grows a suffix each pass.
74
+ rules.push({
75
+ from: new RegExp(`${HOME_RE}${esc("/" + rule.from)}(?![-A-Za-z0-9])`, "g"),
76
+ to: `$1/${rule.to}`,
77
+ });
78
+ continue;
79
+ }
80
+ if (rule.match === "extension") {
81
+ rules.push({
82
+ from: new RegExp(
83
+ `${HOME_RE}${esc("/" + root + "/" + rule.from + "/")}(${NAME})${esc("." + rule.fromExt)}\\b`,
84
+ "g",
85
+ ),
86
+ to: `$1/${root}/${rule.from}/$2.${rule.toExt}`,
87
+ });
88
+ continue;
89
+ }
90
+ // Only a prefix rule needs a boundary: a segment is already delimited by
91
+ // the `/` before it, and the class cannot cross the one after it. Asking
92
+ // for a word boundary there dropped a segment that is a single glob, whose
93
+ // neighbours on both sides are non-word characters.
94
+ const tail = rule.match === "prefix" ? "\\b" : "";
95
+ const body =
96
+ rule.match === "segment" ? `${esc("/" + rule.from + "/")}(${NAME})` : esc("/" + rule.from);
97
+ rules.push({
98
+ from: new RegExp(`${HOME_RE}${home}${body}${tail}`, "g"),
99
+ to: rule.match === "segment" ? `$1/${root}/${rule.to}$2` : `$1/${root}/${rule.to}`,
100
+ });
101
+ }
102
+ return Object.freeze(rules);
103
+ }
104
+
105
+ /**
106
+ * Apply a host's path map to a file's text.
107
+ *
108
+ * @param {ReadonlyArray<{from: RegExp, to: string}>} rules
109
+ * @param {string} text
110
+ * @returns {string}
111
+ */
112
+ export function applyPathRewrites(rules, text) {
113
+ let out = text;
114
+ for (const { from, to } of rules) out = out.replace(from, to);
115
+ return out;
116
+ }
117
+
118
+ /** Extensions whose bytes are text and therefore carry retargetable paths. */
119
+ const TEXT = /\.(md|json|sh|mjs|js|txt|ya?ml|toml)$/i;
120
+
121
+ /**
122
+ * Build a tree copier bound to one host's path map.
123
+ *
124
+ * @param {(text: string) => string} rewrite - the host's path map, applied to
125
+ * text files only; binary files are copied through untouched.
126
+ * @returns {(src: string, dest: string, filter?: (relPath: string) => boolean) => number}
127
+ * a copier returning the number of files written. The filter receives the
128
+ * path relative to the copy root (POSIX-separated), not the basename.
129
+ */
130
+ export function makeCopyTreeRewritten(rewrite) {
131
+ return function copyTreeRewritten(src, dest, filter, relBase = "") {
132
+ let n = 0;
133
+ for (const entry of readdirSync(src, { withFileTypes: true })) {
134
+ const from = join(src, entry.name);
135
+ const to = join(dest, entry.name);
136
+ const rel = relBase ? `${relBase}/${entry.name}` : entry.name;
137
+ if (entry.isDirectory()) {
138
+ n += copyTreeRewritten(from, to, filter, rel);
139
+ continue;
140
+ }
141
+ if (!entry.isFile()) continue;
142
+ if (filter && !filter(rel)) continue;
143
+ ensureDir(dest);
144
+ const isText = TEXT.test(entry.name);
145
+ const raw = readFileSync(from, isText ? "utf-8" : null);
146
+ writeFile(to, isText ? rewrite(raw) : raw);
147
+ n++;
148
+ }
149
+ return n;
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Install the reference tree: the shared `multi-agent-refs/` docs, every
155
+ * sub-command spec, and the standalone command specs. Read on demand, never
156
+ * part of the skills block.
157
+ *
158
+ * @param {string} pipelineSrc - the `pipeline/` directory being installed from
159
+ * @param {string} dest - the host's `multi-agent-refs` directory
160
+ * @param {(src: string, dest: string, filter?: (rel: string) => boolean) => number} copyTree
161
+ * @param {{subCommandSpecs?: boolean}} [options] - `subCommandSpecs: false` skips
162
+ * the per-sub-command specs. A host that fans the pipeline out as one skill per
163
+ * sub-command already carries them in its skills tree; copying them here too
164
+ * would ship every spec twice and give its path rewrites two valid answers.
165
+ * @returns {number} files written, or 0 when the destination is not usable
166
+ */
167
+ export function installRefs(pipelineSrc, dest, copyTree, { subCommandSpecs = true } = {}) {
168
+ const refsSrc = join(pipelineSrc, "multi-agent-refs");
169
+ const commandsSrc = join(pipelineSrc, "commands", "multi-agent");
170
+ const standaloneSrc = join(pipelineSrc, "commands");
171
+
172
+ if (ensureRealDir(dest) === null) return 0;
173
+ ensureDir(dest);
174
+ wipeDir(dest);
175
+
176
+ let count = 0;
177
+ if (existsSync(refsSrc)) count += copyTree(refsSrc, dest);
178
+
179
+ // The sub-command specs. Skip ONLY the top-level dispatcher SKILL.md - it
180
+ // already shipped as the router skill. The filter is on the path relative to
181
+ // the copy root, not the basename: every sub-command spec is itself named
182
+ // SKILL.md, so a basename filter would copy N empty directories and leave the
183
+ // orchestrator with nothing to read.
184
+ if (subCommandSpecs && existsSync(commandsSrc)) {
185
+ count += copyTree(commandsSrc, join(dest, "commands"), (rel) => rel !== "SKILL.md");
186
+ }
187
+
188
+ // Standalone command specs (sim-test, deploy, archive-guard, ...). The router
189
+ // delegates to these by path, so an install that omits them leaves those
190
+ // routes dangling.
191
+ if (existsSync(standaloneSrc)) {
192
+ count += copyTree(standaloneSrc, join(dest, "commands"), (rel) => /^[^/]+\.md$/.test(rel));
193
+ }
194
+
195
+ console.log(` -> ${count} reference file(s) copied to ${dest}`);
196
+ return count;
197
+ }
package/install/codex.mjs CHANGED
@@ -22,11 +22,11 @@ import { dirname, join } from "path";
22
22
 
23
23
  import {
24
24
  copyDir,
25
- copyFile,
26
25
  copySkillsIndex,
27
26
  countFiles,
28
27
  ensureDir,
29
28
  ensureRealDir,
29
+ ensureSharedPreferences,
30
30
  isCopyJunk,
31
31
  isDryRun,
32
32
  wipeDir,
@@ -36,6 +36,15 @@ import { DEV_ONLY_SCRIPTS, countDevOnlyFiles } from "./_dev-only-files.mjs";
36
36
  import { registerMcpServer } from "./_mcp-register.mjs";
37
37
  import { deliverXcodeSkills } from "./_xcode-skills.mjs";
38
38
  import { installCodexAgents } from "./_codex-agents.mjs";
39
+ import {
40
+ applyPathRewrites,
41
+ buildPathRewrites,
42
+ installRefs,
43
+ makeCopyTreeRewritten,
44
+ } from "./_rewrite-tree.mjs";
45
+ import { REGISTRY } from "../pipeline/lib/host.mjs";
46
+ import { localModelName } from "../pipeline/lib/local-model.mjs";
47
+ import { prefsFileIn } from "../pipeline/lib/prefs-value.mjs";
39
48
  import {
40
49
  installAuthoredPluginSkills,
41
50
  pipelineOwnedSkillNames,
@@ -47,7 +56,6 @@ import {
47
56
  } from "./_platform-filter.mjs";
48
57
  import { generateCodexInstructions } from "./_codex-instructions.mjs";
49
58
  import { mergeManagedBlock } from "./_managed-block.mjs";
50
- import { prefsFileIn } from "../pipeline/lib/prefs-value.mjs";
51
59
 
52
60
  /** Start of the pipeline-managed span in `~/.codex/AGENTS.md`. */
53
61
  export const AGENTS_MD_START_MARKER = "# Multi-Agent Development Pipeline";
@@ -74,66 +82,7 @@ export const AGENTS_MD_END_MARKER = "<!-- multi-agent-pipeline:codex-instruction
74
82
  *
75
83
  * @type {ReadonlyArray<{from: RegExp, to: string}>}
76
84
  */
77
- export const CODEX_PATH_REWRITES = Object.freeze([
78
- // The dispatcher itself. MUST come first: the rules below match the bare
79
- // `commands/multi-agent` prefix, and `\b` treats the `.` in `multi-agent.md`
80
- // as a boundary - so a later-ordered rule rewrites this filename into
81
- // `multi-agent-refs/commands.md`, a path that does not exist. On Codex the
82
- // dispatcher is the router skill.
83
- {
84
- from: /\$HOME\/\.claude\/commands\/multi-agent\.md/g,
85
- to: "$HOME/.codex/skills/multi-agent/SKILL.md",
86
- },
87
- { from: /~\/\.claude\/commands\/multi-agent\.md/g, to: "~/.codex/skills/multi-agent/SKILL.md" },
88
- // Current dispatcher spelling (directory layout). MUST also precede the
89
- // sub-command rule: `commands/multi-agent/SKILL.md` would otherwise become
90
- // `multi-agent-refs/commands/SKILL.md`, which installRefs deliberately never
91
- // writes (the top-level SKILL.md ships as the router skill instead).
92
- {
93
- from: /\$HOME\/\.claude\/commands\/multi-agent\/SKILL\.md/g,
94
- to: "$HOME/.codex/skills/multi-agent/SKILL.md",
95
- },
96
- {
97
- from: /~\/\.claude\/commands\/multi-agent\/SKILL\.md/g,
98
- to: "~/.codex/skills/multi-agent/SKILL.md",
99
- },
100
- // Sub-command specs become reference files under the Codex refs tree.
101
- {
102
- from: /\$HOME\/\.claude\/commands\/multi-agent\b/g,
103
- to: "$HOME/.codex/multi-agent-refs/commands",
104
- },
105
- { from: /~\/\.claude\/commands\/multi-agent\b/g, to: "~/.codex/multi-agent-refs/commands" },
106
- // Standalone command specs (sim-test.md, deploy.md, ...) land in the same
107
- // refs/commands dir, so these generic rules follow the multi-agent ones.
108
- { from: /\$HOME\/\.claude\/commands\b/g, to: "$HOME/.codex/multi-agent-refs/commands" },
109
- { from: /~\/\.claude\/commands\b/g, to: "~/.codex/multi-agent-refs/commands" },
110
- // Skills live under the refs tree on this host, so a skill referenced by path
111
- // (the compliance pair, humanizer, the xcode-build family) has to point there.
112
- // MUST precede the bare `multi-agent-refs` rule below, which would otherwise
113
- // leave the `/skills` segment pointing at the Claude tree.
114
- { from: /\$HOME\/\.claude\/skills\b/g, to: "$HOME/.codex/multi-agent-refs/skills" },
115
- { from: /~\/\.claude\/skills\b/g, to: "~/.codex/multi-agent-refs/skills" },
116
- { from: /\$HOME\/\.claude\/multi-agent-refs\b/g, to: "$HOME/.codex/multi-agent-refs" },
117
- { from: /~\/\.claude\/multi-agent-refs\b/g, to: "~/.codex/multi-agent-refs" },
118
- { from: /\$HOME\/\.claude\/agents\b/g, to: "$HOME/.codex/agents" },
119
- { from: /~\/\.claude\/agents\b/g, to: "~/.codex/agents" },
120
- { from: /\$HOME\/\.claude\/scripts\b/g, to: "$HOME/.codex/scripts" },
121
- { from: /~\/\.claude\/scripts\b/g, to: "~/.codex/scripts" },
122
- { from: /\$HOME\/\.claude\/lib\b/g, to: "$HOME/.codex/lib" },
123
- { from: /~\/\.claude\/lib\b/g, to: "~/.codex/lib" },
124
- { from: /\$HOME\/\.claude\/schemas\b/g, to: "$HOME/.codex/schemas" },
125
- { from: /~\/\.claude\/schemas\b/g, to: "~/.codex/schemas" },
126
- // The convention rules the analysis phase falls back to when a project ships
127
- // no standards file. Dangling here means that fallback silently yields
128
- // nothing, so the tree is installed on Codex too.
129
- { from: /\$HOME\/\.claude\/rules\b/g, to: "$HOME/.codex/rules" },
130
- { from: /~\/\.claude\/rules\b/g, to: "~/.codex/rules" },
131
- // Personas are Markdown on Claude Code and generated TOML on Codex, so the
132
- // directory rewrite above is not enough: `agents/code-reviewer.md` has to
133
- // become `agents/code-reviewer.toml` or every persona reference in the refs
134
- // resolves to nothing. Runs last, after the directory rules.
135
- { from: /(\$HOME|~)\/\.codex\/agents\/([a-z0-9-]+)\.md\b/g, to: "$1/.codex/agents/$2.toml" },
136
- ]);
85
+ export const CODEX_PATH_REWRITES = buildPathRewrites("codex");
137
86
 
138
87
  /**
139
88
  * Apply the Codex path map to a file's text.
@@ -142,9 +91,7 @@ export const CODEX_PATH_REWRITES = Object.freeze([
142
91
  * @returns {string}
143
92
  */
144
93
  export function rewriteCodexPaths(text) {
145
- let out = text;
146
- for (const { from, to } of CODEX_PATH_REWRITES) out = out.replace(from, to);
147
- return out;
94
+ return applyPathRewrites(CODEX_PATH_REWRITES, text);
148
95
  }
149
96
 
150
97
  /**
@@ -201,7 +148,18 @@ export function installCodex(ctx) {
201
148
  // it selects which stack plugin's authored skills are delivered.
202
149
  const { home, pipelineSrc, useSymlinks, platformFlag } = ctx;
203
150
 
204
- const CODEX_DIR = join(home, ".codex");
151
+ // Two hosts share this installer: Codex CLI itself, and the local-model host,
152
+ // which is the same engine pointed at a model served from this machine and
153
+ // given a tree of its own. Everything that differs between them is a field on
154
+ // the registry record, so nothing below names either one.
155
+ const hostId = ctx.hostId ?? "codex";
156
+ const host = REGISTRY.hosts[hostId];
157
+ const label = host.label;
158
+ const copyTree = makeCopyTreeRewritten((text) =>
159
+ applyPathRewrites(buildPathRewrites(hostId), text),
160
+ );
161
+
162
+ const CODEX_DIR = join(home, host.install.root);
205
163
  const CODEX_SKILLS = join(CODEX_DIR, "skills");
206
164
  const CODEX_MA_REFS = join(CODEX_DIR, "multi-agent-refs");
207
165
  const CODEX_AGENTS = join(CODEX_DIR, "agents");
@@ -214,24 +172,24 @@ export function installCodex(ctx) {
214
172
  const CODEX_RULES = join(CODEX_DIR, "rules");
215
173
  const CODEX_SKILL_REFS = join(CODEX_MA_REFS, "skills");
216
174
 
217
- console.log(" [Codex CLI] Installing pipeline orchestrator...");
175
+ console.log(` [${label}] Installing pipeline orchestrator...`);
218
176
  ensureDir(CODEX_DIR);
219
177
 
220
- installRouterSkill(pipelineSrc, CODEX_SKILLS);
221
- installRefs(pipelineSrc, CODEX_MA_REFS);
222
- installPersonas(pipelineSrc, CODEX_AGENTS);
223
- installPrompt(CODEX_PROMPTS);
224
- installUserOnlyPrompts(pipelineSrc, CODEX_PROMPTS);
225
- installSkillRefs(pipelineSrc, CODEX_SKILL_REFS, home, platformFlag);
178
+ installRouterSkill(pipelineSrc, CODEX_SKILLS, copyTree, hostId);
179
+ installRefs(pipelineSrc, CODEX_MA_REFS, copyTree);
180
+ installPersonas(pipelineSrc, CODEX_AGENTS, hostId, home);
181
+ installPrompt(CODEX_PROMPTS, hostId);
182
+ installUserOnlyPrompts(pipelineSrc, CODEX_PROMPTS, hostId);
183
+ installSkillRefs(pipelineSrc, CODEX_SKILL_REFS, home, platformFlag, copyTree);
226
184
  installScripts(pipelineSrc, CODEX_SCRIPTS, useSymlinks);
227
- installTree("lib", pipelineSrc, CODEX_LIB, useSymlinks);
228
- installTree("schemas", pipelineSrc, CODEX_SCHEMAS, useSymlinks);
229
- installTree("office", pipelineSrc, CODEX_OFFICE, useSymlinks);
230
- installTree("rules", pipelineSrc, CODEX_RULES, useSymlinks);
185
+ installTree("lib", pipelineSrc, CODEX_LIB, useSymlinks, copyTree);
186
+ installTree("schemas", pipelineSrc, CODEX_SCHEMAS, useSymlinks, copyTree);
187
+ installTree("office", pipelineSrc, CODEX_OFFICE, useSymlinks, copyTree);
188
+ installTree("rules", pipelineSrc, CODEX_RULES, useSymlinks, copyTree);
231
189
  installTemplates(pipelineSrc, CODEX_TEMPLATES, useSymlinks);
232
- writeAgentsMd(join(CODEX_DIR, "AGENTS.md"));
190
+ writeAgentsMd(join(CODEX_DIR, "AGENTS.md"), hostId);
233
191
  ensureSharedPreferences(home, pipelineSrc);
234
- registerMcpServer("codex", "Codex CLI");
192
+ registerMcpServer("codex", label, { codexHome: hostId === "codex" ? null : CODEX_DIR });
235
193
 
236
194
  console.log("");
237
195
  }
@@ -240,7 +198,7 @@ export function installCodex(ctx) {
240
198
  * Write the single router skill, and prune per-command skill dirs left by any
241
199
  * install that predates the one-skill layout.
242
200
  */
243
- function installRouterSkill(pipelineSrc, skillsDir) {
201
+ function installRouterSkill(pipelineSrc, skillsDir, copyTree, hostId = "codex") {
244
202
  const dispatcherSrc = join(pipelineSrc, "commands", "multi-agent", "SKILL.md");
245
203
  if (!existsSync(dispatcherSrc)) return;
246
204
 
@@ -251,7 +209,8 @@ function installRouterSkill(pipelineSrc, skillsDir) {
251
209
  pruneLegacyCommandSkills(skillsDir);
252
210
 
253
211
  const raw = readFileSync(dispatcherSrc, "utf-8");
254
- const skill = rewriteCodexPaths(toCodexSkill(raw, "multi-agent"));
212
+ const rewrite = (text) => applyPathRewrites(buildPathRewrites(hostId), text);
213
+ const skill = rewrite(toCodexSkill(raw, "multi-agent"));
255
214
  const dest = join(skillsDir, "multi-agent");
256
215
  ensureDir(dest);
257
216
  writeFile(join(dest, "SKILL.md"), skill);
@@ -294,82 +253,50 @@ function pruneLegacyCommandSkills(skillsDir) {
294
253
  }
295
254
 
296
255
  /**
297
- * Install the reference tree: the shared `multi-agent-refs/` docs plus every
298
- * sub-command specs, all path-rewritten. These are read on demand and never
299
- * enter the skills block.
256
+ * Copy a tree into the Codex install, retargeting every `$HOME/.claude/...`
257
+ * path it carries. The machinery is shared with the other hosts; only the path
258
+ * map is this host's.
259
+ *
260
+ * @type {(src: string, dest: string, filter?: (rel: string) => boolean) => number}
300
261
  */
301
- function installRefs(pipelineSrc, dest) {
302
- const refsSrc = join(pipelineSrc, "multi-agent-refs");
303
- const commandsSrc = join(pipelineSrc, "commands", "multi-agent");
304
-
305
- if (ensureRealDir(dest) === null) return;
306
- ensureDir(dest);
307
- wipeDir(dest);
262
+ const copyTreeRewritten = makeCopyTreeRewritten(rewriteCodexPaths);
308
263
 
309
- let count = 0;
310
- if (existsSync(refsSrc)) count += copyTreeRewritten(refsSrc, dest);
311
-
312
- // The sub-command specs. Skip ONLY the top-level dispatcher SKILL.md -
313
- // it already shipped as the router skill. The filter is on the path relative
314
- // to the copy root, not the basename: every sub-command spec is itself named
315
- // SKILL.md, so a basename filter would copy N empty directories and leave
316
- // the orchestrator with nothing to read.
317
- if (existsSync(commandsSrc)) {
318
- count += copyTreeRewritten(commandsSrc, join(dest, "commands"), (rel) => rel !== "SKILL.md");
319
- }
320
-
321
- // Standalone Claude Code command specs (sim-test, deploy, archive-guard, ...).
322
- // The router delegates to these by path, so a Codex install that omits them
323
- // leaves those routes dangling.
324
- const standaloneSrc = join(pipelineSrc, "commands");
325
- if (existsSync(standaloneSrc)) {
326
- count += copyTreeRewritten(standaloneSrc, join(dest, "commands"), (rel) =>
327
- /^[^/]+\.md$/.test(rel),
328
- );
329
- }
330
-
331
- console.log(` -> ${count} reference file(s) copied to ${dest}`);
332
- }
264
+ /** The copier a helper uses when its caller passed none (the Codex host). */
265
+ const orDefault = (copyTree) => copyTree ?? copyTreeRewritten;
333
266
 
334
267
  /**
335
- * Recursively copy a tree, applying the Codex path map to text files.
268
+ * Persona rung -> the model and effort this host writes into an agent TOML.
336
269
  *
337
- * Not `copyDir` from `_common.mjs`: that copies bytes, and every ref file here
338
- * carries `$HOME/.claude/...` references that must be retargeted.
270
+ * Codex CLI's rungs are fixed model ids and come straight off the registry.
271
+ * The local host's are a placeholder: which model answers is the user's choice,
272
+ * so it is read from preferences at install time and validated there. Without a
273
+ * choice recorded, no agent is bound to a model at all and the children inherit
274
+ * whatever the session was started on, which is the one answer that cannot be
275
+ * wrong.
339
276
  *
340
- * @param {string} src
341
- * @param {string} dest
342
- * @param {(relPath: string) => boolean} [filter] - receives the path relative to
343
- * the copy root (POSIX-separated), not the basename. Return false to skip.
344
- * @param {string} [relBase] - internal: accumulated relative path
345
- * @returns {number} files written
277
+ * @param {string} hostId
278
+ * @param {string|null} home
346
279
  */
347
- function copyTreeRewritten(src, dest, filter, relBase = "") {
348
- const TEXT = /\.(md|json|sh|mjs|js|txt|ya?ml|toml)$/i;
349
- let n = 0;
350
- for (const entry of readdirSync(src, { withFileTypes: true })) {
351
- const from = join(src, entry.name);
352
- const to = join(dest, entry.name);
353
- const rel = relBase ? `${relBase}/${entry.name}` : entry.name;
354
- if (entry.isDirectory()) {
355
- n += copyTreeRewritten(from, to, filter, rel);
356
- continue;
357
- }
358
- if (!entry.isFile()) continue;
359
- if (filter && !filter(rel)) continue;
360
- ensureDir(dest);
361
- const raw = readFileSync(from, TEXT.test(entry.name) ? "utf-8" : null);
362
- writeFile(to, TEXT.test(entry.name) ? rewriteCodexPaths(raw) : raw);
363
- n++;
280
+ function tierMapFor(hostId, home) {
281
+ const rungs = REGISTRY.hosts[hostId].models.rungs;
282
+ const placeholder = REGISTRY.hosts[hostId].pricing.ceilingKey === "local";
283
+ if (!placeholder) {
284
+ return Object.fromEntries(
285
+ Object.entries(rungs).map(([rung, slot]) => [
286
+ rung,
287
+ { model: slot.model, reasoning_effort: slot.effort },
288
+ ]),
289
+ );
364
290
  }
365
- return n;
291
+ const chosen = home ? localModelName(prefsFileIn(home)) : null;
292
+ return Object.fromEntries(Object.keys(rungs).map((rung) => [rung, { model: chosen }]));
366
293
  }
367
294
 
368
- function installPersonas(pipelineSrc, dest) {
295
+ function installPersonas(pipelineSrc, dest, hostId = "codex", home = null) {
369
296
  const agentsSrc = join(pipelineSrc, "agents");
370
297
  if (!existsSync(agentsSrc)) return;
371
- const written = installCodexAgents(agentsSrc, dest);
372
- console.log(` -> ${written} persona(s) generated as Codex agent TOML in ${dest}`);
298
+ const written = installCodexAgents(agentsSrc, dest, { tierMap: tierMapFor(hostId, home) });
299
+ console.log(` -> ${written} persona(s) generated as agent TOML in ${dest}`);
373
300
  }
374
301
 
375
302
  /**
@@ -377,16 +304,17 @@ function installPersonas(pipelineSrc, dest) {
377
304
  * command. It is a two-line router into the skill, not a second copy of the
378
305
  * orchestrator - one spec, two entry points.
379
306
  */
380
- function installPrompt(promptsDir) {
307
+ function installPrompt(promptsDir, hostId = "codex") {
308
+ const root = REGISTRY.hosts[hostId].install.root;
381
309
  promptsDir = ensureRealDir(promptsDir, { userOwned: true });
382
310
  ensureDir(promptsDir);
383
311
  const body = [
384
312
  "Run the multi-agent development pipeline.",
385
313
  "",
386
- "Load the orchestrator spec at `$HOME/.codex/skills/multi-agent/SKILL.md` and follow it",
314
+ `Load the orchestrator spec at \`$HOME/${root}/skills/multi-agent/SKILL.md\` and follow it`,
387
315
  "for the input below. Sub-command specs are at",
388
- "`$HOME/.codex/multi-agent-refs/commands/<cmd>/SKILL.md`; phase specs are at",
389
- "`$HOME/.codex/multi-agent-refs/phases/`. Read them on demand as the spec directs.",
316
+ `\`$HOME/${root}/multi-agent-refs/commands/<cmd>/SKILL.md\`; phase specs are at`,
317
+ `\`$HOME/${root}/multi-agent-refs/phases/\`. Read them on demand as the spec directs.`,
390
318
  "",
391
319
  "Input: $ARGUMENTS",
392
320
  "",
@@ -426,7 +354,8 @@ export function userOnlyCommandIds(pipelineSrc) {
426
354
  * @param {string} pipelineSrc
427
355
  * @param {string} promptsDir
428
356
  */
429
- export function installUserOnlyPrompts(pipelineSrc, promptsDir) {
357
+ export function installUserOnlyPrompts(pipelineSrc, promptsDir, hostId = "codex") {
358
+ const root = REGISTRY.hosts[hostId].install.root;
430
359
  promptsDir = ensureRealDir(promptsDir, { userOwned: true });
431
360
  ensureDir(promptsDir);
432
361
  const ids = userOnlyCommandIds(pipelineSrc);
@@ -442,7 +371,7 @@ export function installUserOnlyPrompts(pipelineSrc, promptsDir) {
442
371
  const body = [
443
372
  `Run the multi-agent pipeline's \`${id}\` command. The user typed it, so it may run.`,
444
373
  "",
445
- `Read \`$HOME/.codex/multi-agent-refs/commands/${id}/SKILL.md\` and follow it for the input below.`,
374
+ `Read \`$HOME/${root}/multi-agent-refs/commands/${id}/SKILL.md\` and follow it for the input below.`,
446
375
  "",
447
376
  "Input: $ARGUMENTS",
448
377
  "",
@@ -469,7 +398,8 @@ export function installUserOnlyPrompts(pipelineSrc, promptsDir) {
469
398
  * - the pipeline's own `skills/shared/external` (what `~/.claude/skills` receives)
470
399
  * - the enabled stack plugin's authored skills (what the marketplace provides)
471
400
  */
472
- function installSkillRefs(pipelineSrc, dest, home, platformFlag) {
401
+ function installSkillRefs(pipelineSrc, dest, home, platformFlag, copyTree) {
402
+ copyTree = orDefault(copyTree);
473
403
  const externalSrc = join(pipelineSrc, "skills", "shared", "external");
474
404
  const coreSrc = join(pipelineSrc, "skills", "shared", "core");
475
405
 
@@ -487,7 +417,7 @@ function installSkillRefs(pipelineSrc, dest, home, platformFlag) {
487
417
  const { names: enabled, source: selectionSource } = pluginsToDeliver(home, platformFlag);
488
418
  const { keep, skipped } = partitionExternalSkillsByPlugins(externalSrc, enabled);
489
419
  for (const name of keep) {
490
- count += copyTreeRewritten(join(externalSrc, name), join(dest, name));
420
+ count += copyTree(join(externalSrc, name), join(dest, name));
491
421
  }
492
422
  writeExternalSkillsManifest(dest, keep);
493
423
  console.log(
@@ -501,7 +431,7 @@ function installSkillRefs(pipelineSrc, dest, home, platformFlag) {
501
431
  // them. The `multi-agent*` dirs stay out: those are sub-command specs, and they ship as
502
432
  // refs under `commands/` precisely so they never enter the skills block.
503
433
  if (existsSync(coreSrc)) {
504
- count += copyTreeRewritten(
434
+ count += copyTree(
505
435
  coreSrc,
506
436
  dest,
507
437
  (rel) => !rel.startsWith("multi-agent/") && !rel.startsWith("multi-agent-"),
@@ -518,7 +448,7 @@ function installSkillRefs(pipelineSrc, dest, home, platformFlag) {
518
448
  label: "Codex CLI",
519
449
  skipNames: pipelineOwnedSkillNames(pipelineSrc),
520
450
  copy: (from, to) => {
521
- if (!isDryRun()) copyTreeRewritten(from, to, (rel) => !isCopyJunk(rel));
451
+ if (!isDryRun()) copyTree(from, to, (rel) => !isCopyJunk(rel));
522
452
  },
523
453
  });
524
454
 
@@ -529,7 +459,7 @@ function installSkillRefs(pipelineSrc, dest, home, platformFlag) {
529
459
  format: "codex",
530
460
  enabled: pluginsToDeliver(home, platformFlag).names.includes("ai-ios-toolkit"),
531
461
  taken: new Set([...pipelineOwnedSkillNames(pipelineSrc), ...res.deliveredNames]),
532
- copy: (from, to) => copyTreeRewritten(from, to, (rel) => !isCopyJunk(rel)),
462
+ copy: (from, to) => copyTree(from, to, (rel) => !isCopyJunk(rel)),
533
463
  });
534
464
 
535
465
  // The index lands beside the refs it indexes. Codex has no skills block to feed,
@@ -593,7 +523,8 @@ function installTemplates(pipelineSrc, dest, useSymlinks) {
593
523
  console.log(` -> ${countFiles(src)} template file(s) copied to ${dest}`);
594
524
  }
595
525
 
596
- function installTree(name, pipelineSrc, dest, useSymlinks) {
526
+ function installTree(name, pipelineSrc, dest, useSymlinks, copyTree) {
527
+ copyTree = orDefault(copyTree);
597
528
  const src = join(pipelineSrc, name);
598
529
  if (!existsSync(src)) return;
599
530
  if (!useSymlinks) {
@@ -602,7 +533,7 @@ function installTree(name, pipelineSrc, dest, useSymlinks) {
602
533
  }
603
534
  wipeDir(dest);
604
535
  if (!useSymlinks && REWRITTEN_TREES.has(name)) {
605
- const n = copyTreeRewritten(src, dest);
536
+ const n = copyTree(src, dest);
606
537
  console.log(` -> ${n} ${name} file(s) copied to ${dest} (paths retargeted)`);
607
538
  return;
608
539
  }
@@ -610,10 +541,15 @@ function installTree(name, pipelineSrc, dest, useSymlinks) {
610
541
  console.log(` -> ${countFiles(src)} ${name} file(s) copied to ${dest}`);
611
542
  }
612
543
 
613
- function writeAgentsMd(path) {
544
+ function writeAgentsMd(path, hostId = "codex") {
545
+ // The instructions block is authored against the engine's default tree. A
546
+ // second install of the same engine keeps its own, so the same rewrite the
547
+ // refs go through applies here: an instruction naming the other install's
548
+ // tree would send every run to the wrong files.
549
+ const rewrite = (text) => applyPathRewrites(buildPathRewrites(hostId), text);
614
550
  const result = mergeManagedBlock({
615
551
  path,
616
- body: generateCodexInstructions(),
552
+ body: rewrite(generateCodexInstructions()),
617
553
  startMarker: AGENTS_MD_START_MARKER,
618
554
  endMarker: AGENTS_MD_END_MARKER,
619
555
  });
@@ -626,26 +562,6 @@ function writeAgentsMd(path) {
626
562
  console.log(` -> ${verb} ${path}`);
627
563
  }
628
564
 
629
- /**
630
- * Seed `~/.claude/multi-agent-preferences.json` when it is absent.
631
- *
632
- * Preferences are cross-host state, not a Claude Code artifact: every phase
633
- * reads them and the orchestrator is specified to warn and stop when they are
634
- * missing. A Codex-only install would otherwise produce a complete tree that
635
- * halts on the first run, because only the Claude Code target creates the file.
636
- *
637
- * Existing files are never overwritten.
638
- */
639
- function ensureSharedPreferences(home, pipelineSrc) {
640
- const prefsPath = prefsFileIn(home);
641
- if (existsSync(prefsPath)) return;
642
- const template = join(pipelineSrc, "preferences-template.json");
643
- if (!existsSync(template)) return;
644
- ensureDir(join(home, ".claude"));
645
- copyFile(template, prefsPath);
646
- console.log(` -> seeded shared preferences at ${prefsPath}`);
647
- }
648
-
649
565
  /**
650
566
  * Register the multi-agent MCP server via the `codex` CLI.
651
567
  *