@bridge_gpt/mcp-server 0.2.69 → 0.2.71

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 (164) hide show
  1. package/README.md +140 -292
  2. package/build/agent-launchers/claude-executor-adapter.js +27 -5
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +15 -5
  5. package/build/artifact-diff.js +110 -0
  6. package/build/bin-entrypoint.js +36 -0
  7. package/build/bounded-wait.js +9 -1
  8. package/build/bridge-permissions.js +36 -9
  9. package/build/claude-review-workflow-drift.js +3 -3
  10. package/build/codex-bridge-profile.js +1 -1
  11. package/build/commands.generated.js +6 -6
  12. package/build/conductor/bridge-api-client.js +858 -21
  13. package/build/conductor/bring-up-facts.js +9 -9
  14. package/build/conductor/command-drift-production.js +7 -2
  15. package/build/conductor/doctor.js +472 -18
  16. package/build/conductor/epic-child-continuation.js +54 -3
  17. package/build/conductor/epic-implementer-cli.js +136 -34
  18. package/build/conductor/epic-runtime.js +2 -2
  19. package/build/conductor/epic-state.js +1 -1
  20. package/build/conductor/gate-discovery.js +524 -10
  21. package/build/conductor/gate-settings-review.js +451 -0
  22. package/build/conductor/hook-runtime-qualification.js +1 -1
  23. package/build/conductor/install-doctor.js +4 -2
  24. package/build/conductor/launch-need-probes.js +342 -0
  25. package/build/conductor/launch-plan.js +145 -0
  26. package/build/conductor/local-merge.js +241 -56
  27. package/build/conductor/merge-credential.js +172 -0
  28. package/build/conductor/merge-execution-eligibility.js +1 -1
  29. package/build/conductor/merged-child-check.js +95 -0
  30. package/build/conductor/plan-trim.js +30 -0
  31. package/build/conductor/pr-ci-producer.js +1 -1
  32. package/build/conductor/precheck-timings.js +14 -0
  33. package/build/conductor/preview-observations.js +10 -0
  34. package/build/conductor/readiness-cli.js +11 -6
  35. package/build/conductor/readiness-prerequisites.js +41 -0
  36. package/build/conductor/readiness-sections.js +348 -55
  37. package/build/conductor/readiness.js +99 -87
  38. package/build/conductor/recovery-cli.js +665 -23
  39. package/build/conductor/recovery-operations.js +350 -8
  40. package/build/conductor/repair-contract.js +47 -2
  41. package/build/conductor/repository-workflow-remedy.js +8 -6
  42. package/build/conductor/stored-merge-credential.js +76 -0
  43. package/build/conductor/stored-merge-token-probe.js +28 -0
  44. package/build/conductor/temporary-plan.js +50 -0
  45. package/build/conductor/wait-run-cli.js +759 -0
  46. package/build/conductor/worker-database-doctor-inspector.js +49 -0
  47. package/build/conductor-bin.js +2 -2
  48. package/build/conductor-claude-hook-bin.js +2 -2
  49. package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
  50. package/build/conductor-removed-stub-bin.js +2 -5
  51. package/build/credential-store.js +356 -13
  52. package/build/docs.generated.js +26 -13
  53. package/build/doctor.js +94 -32
  54. package/build/drive-epic-help.js +212 -0
  55. package/build/drive-epic.js +1989 -379
  56. package/build/epic-ci-workflow-drift.js +125 -0
  57. package/build/epic-ci-workflow-install.js +240 -0
  58. package/build/epic-ci-workflow-v1.js +132 -0
  59. package/build/epic-ci-workflow.js +318 -0
  60. package/build/epic-contract-context.js +326 -0
  61. package/build/epic-implementer-bin.js +58 -42
  62. package/build/epic-implementer-claude-hook-bin.js +2 -2
  63. package/build/escalation-reachability.js +134 -0
  64. package/build/executor/ci-rerun-job.js +220 -14
  65. package/build/executor/cleanup-report.js +99 -0
  66. package/build/executor/cli.js +12 -1
  67. package/build/executor/completion-contract.js +66 -11
  68. package/build/executor/completion-supervision.js +99 -0
  69. package/build/executor/delivery-outcome.js +179 -0
  70. package/build/executor/deps.js +3 -0
  71. package/build/executor/env.js +276 -1
  72. package/build/executor/failure-reason-codes.js +126 -0
  73. package/build/executor/gate-qualification-job.js +20 -5
  74. package/build/executor/heartbeat.js +38 -0
  75. package/build/executor/http-client.js +72 -0
  76. package/build/executor/integration-job.js +298 -5
  77. package/build/executor/job-errors.js +36 -6
  78. package/build/executor/job-runner.js +830 -45
  79. package/build/executor/likely-tests.js +42 -3
  80. package/build/executor/merge-job.js +145 -2
  81. package/build/executor/observation.js +73 -4
  82. package/build/executor/permissions.js +193 -97
  83. package/build/executor/preflight.js +19 -3
  84. package/build/executor/process-containment.js +46 -2
  85. package/build/executor/prompt-spec.js +113 -9
  86. package/build/executor/rebase-finalization.js +38 -3
  87. package/build/executor/reconcile-overlap-job.js +41 -8
  88. package/build/executor/required-work-ledger.js +236 -81
  89. package/build/executor/resume-pre-spawn.js +38 -1
  90. package/build/executor/runner.js +91 -3
  91. package/build/executor/test-clock.js +8 -0
  92. package/build/executor/types.js +37 -2
  93. package/build/executor/worker-cli-launcher.js +259 -0
  94. package/build/executor/worker-command.js +177 -5
  95. package/build/executor/worker-database-target.js +91 -0
  96. package/build/executor/worker-database.js +927 -0
  97. package/build/executor/worker-finalization.js +106 -0
  98. package/build/executor/worker-guard-hook.js +203 -0
  99. package/build/executor/worker-resources.js +58 -0
  100. package/build/executor/worker-verification-guidance.js +44 -2
  101. package/build/executor/worktree.js +303 -15
  102. package/build/executor-launch.js +11 -1
  103. package/build/generated-assets-doctor.js +9 -1
  104. package/build/generated-assets-health.js +13 -4
  105. package/build/generated-assets-legacy.js +39 -0
  106. package/build/generated-assets-paths.js +12 -1
  107. package/build/generated-assets-repair.js +4 -1
  108. package/build/generated-assets-test-support.js +12 -0
  109. package/build/github-remote.js +33 -0
  110. package/build/github-sign-in.js +62 -0
  111. package/build/index.js +1133 -546
  112. package/build/init.js +39 -1
  113. package/build/install-bridge-conductor-gate.js +270 -11
  114. package/build/install-bridge-conductor-setup.js +427 -0
  115. package/build/install-bridge-conductor.js +1545 -268
  116. package/build/install-bridge.js +376 -60
  117. package/build/mcp-install-state.js +8 -2
  118. package/build/merge-pull-request.js +6 -0
  119. package/build/merge-workflow-install.js +782 -344
  120. package/build/phase-result-artifacts.js +75 -20
  121. package/build/pipeline-orchestrator.js +247 -4
  122. package/build/pipelines.generated.js +35 -35
  123. package/build/plan-discovery.js +15 -2
  124. package/build/plan-execution-ledger.js +321 -17
  125. package/build/plan-phase-routing.js +48 -13
  126. package/build/plane/cli.js +105 -51
  127. package/build/plane/defaults.js +3 -0
  128. package/build/plane/plane-freshness.js +298 -0
  129. package/build/plane/preflight.js +19 -0
  130. package/build/plane/schema-compatibility.js +137 -0
  131. package/build/plane/shutdown-deps.js +38 -0
  132. package/build/plane/shutdown.js +83 -8
  133. package/build/plane/terminal-run-cleanup.js +303 -0
  134. package/build/printed-remedy-commands.js +33 -4
  135. package/build/readiness-check.js +6 -2
  136. package/build/readiness-prerequisites.generated.js +532 -0
  137. package/build/readme.generated.js +1 -1
  138. package/build/repository-toolchains.js +581 -0
  139. package/build/setup-epic.js +421 -34
  140. package/build/shared-resources.generated.js +5 -0
  141. package/build/start-tickets.js +28 -15
  142. package/build/test-command-detection.js +284 -0
  143. package/build/test-command-validation.js +73 -0
  144. package/build/testing-config-client.js +150 -0
  145. package/build/ticket-delivery-artifacts.js +265 -0
  146. package/build/ticket-delivery-enrollment.js +369 -0
  147. package/build/ticket-delivery.js +205 -0
  148. package/build/ticket-review-summary.js +14 -0
  149. package/build/upgrade-cli.js +13 -0
  150. package/build/v2-readiness-requirements.js +552 -0
  151. package/build/version.generated.js +3 -3
  152. package/build/worker-guard-hook-bin.js +2 -2
  153. package/build/worktree-core.js +22 -7
  154. package/docs/BRIDGE-DIRECTORY-README.md +48 -0
  155. package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
  156. package/docs/EPIC-IMPLEMENTER.md +142 -63
  157. package/docs/epic-implementer/getting-started.md +187 -0
  158. package/docs/epic-implementer/self-hosting.md +133 -0
  159. package/package.json +4 -4
  160. package/pipelines/idea-to-ticket.json +1 -1
  161. package/pipelines/implement-ticket.json +8 -8
  162. package/pipelines/review-ticket.json +2 -2
  163. package/design-assets/favicon/favicon-32x32.png +0 -0
  164. package/design-assets/just-logo-rough-draft.png +0 -0
@@ -1,49 +1,65 @@
1
1
  /**
2
- * `install-bridge conductor --merge-workflow` — the generate-and-PR installer
3
- * (BAPI-1136).
2
+ * The generate-and-PR artifact installer (BAPI-1136, generalized by BAPI-1460).
4
3
  *
5
- * One command generates the Epic Implementer merge workflow plus its two review
6
- * artifacts, commits them on a managed branch, pushes with the CUSTOMER's own
7
- * git identity, and opens a pull request with the customer's own `gh`. It never
4
+ * One engine installs a named ARTIFACT SET: it generates the set's managed
5
+ * files, commits them on a managed branch, pushes with the CUSTOMER's own git
6
+ * identity, and opens a pull request with the customer's own `gh`. It never
8
7
  * merges that pull request, and Bridge never writes to the repository at all.
9
- * The customer's review IS the security control: this workflow is the one file
10
- * that can perform a privileged merge, so a human deciding to merge it is the
11
- * whole point rather than an inconvenience on the way to automation.
8
+ * Two sets exist today: the Epic Implementer merge workflow with its two review
9
+ * artifacts (`install-bridge conductor --merge-workflow`, below), and the
10
+ * Epic Implementer CI workflow (`epic-ci-workflow-install.ts`).
12
11
  *
13
12
  * ## Domain logic lives here, not in the CLI
14
13
  *
15
14
  * `install-bridge.ts` parses arguments and builds seams. Everything below — the
16
- * preflight, the four-way classification, the consent summary, the branch /
17
- * commit / push / PR sequence — is here so it is unit-testable with in-memory
18
- * fakes and so the CLI layer stays thin.
15
+ * preflight, the classification, the consent summary, the worktree / commit /
16
+ * push / PR sequence — is here so it is unit-testable with in-memory fakes and
17
+ * so the CLI layer stays thin.
19
18
  *
20
19
  * ## Read-only until it is not
21
20
  *
22
- * The ENTIRE preflight completes before the first branch, file write,
23
- * install-state write, commit, push, or pull request. That ordering is the
24
- * design: a failure discovered halfway through leaves a branch, or a file, or a
25
- * pushed ref in a customer's repository that they now have to understand and
26
- * clean up. Nothing here can partially install.
21
+ * The ENTIRE preflight — local checks, the remote default-branch head, every
22
+ * managed file's content on that head, the open managed pull request, and the
23
+ * managed remote branch — completes before the first fetch, file write, commit,
24
+ * push, or pull request. Nothing here can partially install.
27
25
  *
28
- * ## Four content states, and why `identical` is not the only no-op
26
+ * ## The person's checkout is never touched
29
27
  *
30
- * A file at the managed path is one of four things: absent, byte-identical to
31
- * what this build renders, a complete older version Bridge itself published, or
32
- * something else. Only the first and third are installable. "Something else"
33
- * includes a hand-edit, a truncation, a newer version from a future build, and a
34
- * file that merely claims a lower version in its marker — all of them get the
35
- * same fail-closed treatment, because this installer cannot tell a benign edit
36
- * from a hostile one and must not guess about a file that can merge code.
28
+ * All branch and file work happens in a temporary, DETACHED `git worktree`
29
+ * created from the verified default-branch head, outside the person's checkout,
30
+ * and removed on every exit path. The person's HEAD, index, and working files
31
+ * are unchanged at the end: no checkout, switch, reset, or stash ever runs
32
+ * against them. Content is classified from the default branch, not from
33
+ * whatever the person has checked out.
34
+ *
35
+ * ## Content states, and why `identical` is not the only no-op
36
+ *
37
+ * A file at a managed path is absent, byte-identical to the proposal, a complete
38
+ * older version Bridge itself published, or something else. Only the first and
39
+ * third are installable. "Something else" — a hand edit, a truncation, a newer
40
+ * version, a file that merely claims a version — is never overwritten: the
41
+ * installer prints a unified diff of what it would have written against what is
42
+ * there and reports a named refusal.
43
+ *
44
+ * ## Re-runs find their own work
45
+ *
46
+ * A re-run that finds an open managed pull request whose contents match the
47
+ * proposal reports it and writes nothing. One whose contents differ is reported
48
+ * for manual reconciliation. A pushed managed branch with no open pull request
49
+ * (left by an earlier `pr_open_failed`) is reported with a fixed next step; it
50
+ * is never reused, overwritten, or deleted automatically.
37
51
  *
38
52
  * ## Secret discipline
39
53
  *
40
- * No path here accepts, prompts for, reads, writes, or prints a credential. The
41
- * Bridge API key is referenced by NAME only. Raw `git` and `gh` output never
42
- * reaches the operator: every failure is a stable named reason plus one
43
- * remediation sentence, because subprocess text is unbounded and can carry a
44
- * remote URL with an embedded token.
54
+ * No path here accepts, prompts for, reads, writes, or prints a credential. Raw
55
+ * `git` and `gh` output never reaches the operator: every failure is a stable
56
+ * named reason plus one remediation sentence, because subprocess text is
57
+ * unbounded and can carry a remote URL with an embedded token.
45
58
  */
46
- import { resolve } from "node:path";
59
+ import { lstat as fsLstat, mkdtemp, rm } from "node:fs/promises";
60
+ import { tmpdir } from "node:os";
61
+ import { join, resolve } from "node:path";
62
+ import { renderUnifiedDiff } from "./artifact-diff.js";
47
63
  import { MERGE_WORKFLOW_EXPECTED_VERSION, MERGE_WORKFLOW_PATH, } from "./conductor/merge-execution-contract.js";
48
64
  import { MERGE_WORKFLOW_API_KEY_SECRET_NAME, } from "./merge-workflow-config.js";
49
65
  import { MERGE_WORKFLOW_CLASSIFICATION_TEXT, classifyMergeWorkflowContent, } from "./merge-workflow-drift.js";
@@ -51,7 +67,7 @@ import { MERGE_WORKFLOW_CODEOWNERS_RELPATH, MERGE_WORKFLOW_GUIDANCE_RELPATH, MER
51
67
  import { renderEpicImplementerMergeWorkflow } from "./merge-workflow.js";
52
68
  import { MCP_INSTALL_STATE_RELPATH } from "./mcp-install-state.js";
53
69
  // ---------------------------------------------------------------------------
54
- // Managed identity
70
+ // Managed identity (merge-workflow set)
55
71
  // ---------------------------------------------------------------------------
56
72
  /** The managed branch this installer creates, for a fresh installation. */
57
73
  export const MERGE_WORKFLOW_INSTALL_BRANCH = "bridge/merge-workflow-v" + String(MERGE_WORKFLOW_EXPECTED_VERSION);
@@ -73,7 +89,8 @@ export const MERGE_WORKFLOW_UPGRADE_PR_TITLE = MERGE_WORKFLOW_UPGRADE_COMMIT_SUB
73
89
  *
74
90
  * Closed on purpose: each value is printed verbatim as the first token of a
75
91
  * stderr line, so the vocabulary is an operator-facing contract, and the set has
76
- * to be greppable rather than assembled from subprocess text.
92
+ * to be greppable rather than assembled from subprocess text. Tokens may be
93
+ * added; none may be removed or renamed.
77
94
  */
78
95
  export const MERGE_WORKFLOW_INSTALL_FAILURE_REASONS = [
79
96
  /** `git` is not on PATH. */
@@ -106,6 +123,26 @@ export const MERGE_WORKFLOW_INSTALL_FAILURE_REASONS = [
106
123
  "pr_open_failed",
107
124
  /** A required write surface was declined, or no prompt was available. */
108
125
  "consent_declined",
126
+ // --- BAPI-1460 -----------------------------------------------------------
127
+ /** A remote read (default-branch head, managed file, PR, or branch) gave no reliable answer. */
128
+ "remote_state_unverifiable",
129
+ /** An open managed pull request carries contents that differ from the current proposal. */
130
+ "existing_pr_differs",
131
+ /** A managed branch is pushed but has no open pull request. */
132
+ "managed_branch_without_pr",
133
+ /** The default branch moved after consent and no plan could be re-approved at the new head. */
134
+ "default_branch_moved",
135
+ /** Another actor created the managed branch or pull request during this run. */
136
+ "managed_state_changed",
137
+ /** The temporary worktree could not be created. */
138
+ "worktree_failed",
139
+ /** The test command for the CI workflow is missing or invalid. */
140
+ "test_command_invalid",
141
+ // --- BAPI-1536 -----------------------------------------------------------
142
+ /** The CI workflow's toolchain set is outside the closed vocabulary. */
143
+ "toolchains_invalid",
144
+ /** A pull request from an earlier published renderer version's managed branch is still open. */
145
+ "historical_managed_pr_open",
109
146
  ];
110
147
  // ---------------------------------------------------------------------------
111
148
  // Path safety
@@ -113,10 +150,10 @@ export const MERGE_WORKFLOW_INSTALL_FAILURE_REASONS = [
113
150
  /**
114
151
  * Reject any managed path that is not a plain, repository-relative POSIX path.
115
152
  *
116
- * The three managed paths are constants, so this can never fire in production —
117
- * which is exactly why it is here. It is the assertion that keeps a future edit
118
- * from introducing an absolute path, a `..` escape, or a Windows separator into
119
- * the one code path that writes files and stages them for commit.
153
+ * The managed paths are constants, so this can never fire in production — which
154
+ * is exactly why it is here. It keeps a future edit from introducing an
155
+ * absolute path, a `..` escape, or a Windows separator into the one code path
156
+ * that writes files and stages them for commit.
120
157
  */
121
158
  export function isSafeManagedRelPath(relPath) {
122
159
  if (typeof relPath !== "string" || relPath.length === 0)
@@ -137,49 +174,19 @@ function joinCwd(cwd, rel) {
137
174
  return `${base}/${rel}`;
138
175
  }
139
176
  function isEnoent(err) {
140
- return typeof err === "object" && err !== null && err.code === "ENOENT";
141
- }
142
- /** Read a file, mapping "absent" to `null` and any other error to a throw. */
143
- async function readOrNull(deps, absPath) {
144
- try {
145
- return await deps.readFile(absPath);
146
- }
147
- catch (err) {
148
- if (isEnoent(err))
149
- return null;
150
- throw err;
151
- }
177
+ const code = typeof err === "object" && err !== null ? err.code : undefined;
178
+ return code === "ENOENT" || code === "ENOTDIR";
152
179
  }
153
180
  // ---------------------------------------------------------------------------
154
181
  // Remote identity
155
182
  // ---------------------------------------------------------------------------
156
- /**
157
- * Parse `owner/name` out of a git remote URL, accepting ONLY canonical
158
- * github.com forms.
159
- *
160
- * GitHub Enterprise and every non-GitHub host return `null`. This feature is
161
- * GitHub.com-only: the workflow it installs uses `${{ github.token }}` and the
162
- * GitHub REST surface, and quietly "succeeding" against a host where the result
163
- * cannot work would open a pull request that can never actuate anything.
164
- */
165
- export function parseGithubRemote(remoteUrl) {
166
- if (typeof remoteUrl !== "string")
167
- return null;
168
- const trimmed = remoteUrl.trim();
169
- if (trimmed.length === 0)
170
- return null;
171
- const patterns = [
172
- /^https:\/\/github\.com\/([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/,
173
- /^ssh:\/\/git@github\.com\/([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/,
174
- /^git@github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/,
175
- ];
176
- for (const pattern of patterns) {
177
- const m = pattern.exec(trimmed);
178
- if (m)
179
- return `${m[1]}/${m[2]}`;
180
- }
181
- return null;
182
- }
183
+ // BAPI-1461: moved to a dependency-free module so credential resolution can use
184
+ // it without loading this installer's graph; re-exported so this surface is unchanged.
185
+ import { parseGithubRemote } from "./github-remote.js";
186
+ export { parseGithubRemote };
187
+ // ---------------------------------------------------------------------------
188
+ // Remediation
189
+ // ---------------------------------------------------------------------------
183
190
  /** One remediation sentence per named failure. Printed after the reason token. */
184
191
  const REMEDIATION = {
185
192
  git_unavailable: "Install git and re-run; this command creates the branch with your own git.",
@@ -192,15 +199,31 @@ const REMEDIATION = {
192
199
  codeowner_invalid: "Pass exactly one real reviewer as `--codeowner @org/team` or `--codeowner @user`.",
193
200
  workflow_modified_or_unrecognized: "Review the existing file by hand; this command never overwrites a workflow Bridge did not write.",
194
201
  companion_artifact_conflict: "Review the differing file by hand and remove or reconcile it, then re-run.",
195
- existing_pr_unverifiable: "Inspect the open Bridge merge-workflow pull request by hand and close it if it is not the one you want.",
202
+ existing_pr_unverifiable: "Inspect the open Bridge pull request by hand and close it if it is not the one you want.",
196
203
  write_failed: "Check directory permissions for the repository and re-run.",
197
- git_failed: "Check the reported branch with git by hand; nothing already created has been removed.",
198
- pr_open_failed: "The branch is pushed; open the pull request by hand, or re-run this command to reuse it.",
204
+ git_failed: "Check the reported branch with git by hand; nothing already pushed has been removed.",
205
+ pr_open_failed: "The branch is pushed; open a pull request from it by hand, or delete that remote branch, then re-run this command.",
199
206
  consent_declined: "Re-run in an interactive terminal and accept the write to continue.",
207
+ remote_state_unverifiable: "Check that `gh` is authenticated and can read this repository, then re-run; nothing was written.",
208
+ existing_pr_differs: "An open Bridge pull request differs from what this build proposes; review it and close it, then re-run.",
209
+ managed_branch_without_pr: "Open a pull request from the managed branch, or delete that remote branch, then re-run this command.",
210
+ default_branch_moved: "The default branch changed while this command ran; re-run it to review the new proposal.",
211
+ managed_state_changed: "Another managed branch or pull request appeared while this command ran; review it, then re-run.",
212
+ worktree_failed: "A temporary git worktree could not be created; check free disk space and `git worktree list`, then re-run.",
213
+ test_command_invalid: "Save a valid test command through Bridge setup, then re-run.",
214
+ toolchains_invalid: "Re-run setup so the repository's dependency files are inspected again; nothing was written.",
215
+ historical_managed_pr_open: "An earlier Bridge setup pull request is still open for this workflow; merge or close it, then re-run. Bridge does not close or rewrite it.",
200
216
  };
201
- function fail(reason) {
202
- return { outcome: "failed", reason, remediation: REMEDIATION[reason] };
217
+ /** The remediation sentence for a reason. */
218
+ export function artifactSetRemediation(reason) {
219
+ return REMEDIATION[reason];
203
220
  }
221
+ function fail(reason, extra = {}) {
222
+ return { outcome: "failed", reason, remediation: REMEDIATION[reason], warnings: [], ...extra };
223
+ }
224
+ // ---------------------------------------------------------------------------
225
+ // Subprocess helpers
226
+ // ---------------------------------------------------------------------------
204
227
  async function commandSucceeds(run, args) {
205
228
  try {
206
229
  const result = await run(args);
@@ -211,31 +234,242 @@ async function commandSucceeds(run, args) {
211
234
  }
212
235
  }
213
236
  async function captureStdout(run, args) {
237
+ const raw = await captureRawStdout(run, args);
238
+ return raw === null ? null : raw.trim();
239
+ }
240
+ /** Successful stdout, UNtrimmed — a leading status column is significant. */
241
+ async function captureRawStdout(run, args) {
214
242
  try {
215
243
  const result = await run(args);
216
244
  if (result.status !== 0)
217
245
  return null;
218
- return result.stdout.trim();
246
+ return result.stdout;
219
247
  }
220
248
  catch {
221
249
  return null;
222
250
  }
223
251
  }
252
+ /** Whether a porcelain-v1 status line names exactly the install manifest. */
253
+ function isInstallStateLine(line) {
254
+ // `XY <path>`: two status columns, a space, then the path.
255
+ return line.length > 3 && line.slice(3) === MCP_INSTALL_STATE_RELPATH;
256
+ }
257
+ /** Split `gh api --include` output into its status code and RAW body. */
258
+ function parseIncludedResponse(stdout) {
259
+ const status = /^HTTP\/[0-9.]+ (\d{3})\b/.exec(stdout);
260
+ if (!status)
261
+ return null;
262
+ const crlf = stdout.indexOf("\r\n\r\n");
263
+ const lf = stdout.indexOf("\n\n");
264
+ let cut;
265
+ if (crlf >= 0 && (lf < 0 || crlf < lf))
266
+ cut = crlf + 4;
267
+ else if (lf >= 0)
268
+ cut = lf + 2;
269
+ else
270
+ return null;
271
+ return { status: Number(status[1]), body: stdout.slice(cut) };
272
+ }
224
273
  /**
225
- * Run the complete read-only preflight.
226
- *
227
- * Every check here is a read. Nothing it calls creates a branch, writes a file,
228
- * touches install state, commits, pushes, or opens a pull request — which is
229
- * what lets the caller treat a failure as "nothing happened".
274
+ * Read one file's RAW bytes from the remote at an immutable commit, through
275
+ * `gh api`. A confirmed 404 is `absent`; anything else that is not a clean 200
276
+ * is `unverifiable` — an uncertain read must never authorize a replacement.
277
+ */
278
+ async function readRemoteFile(deps, repository, sha, relPath) {
279
+ const encodedPath = relPath.split("/").map(encodeURIComponent).join("/");
280
+ let result;
281
+ try {
282
+ result = await deps.runGh([
283
+ "api",
284
+ "--include",
285
+ "-H",
286
+ "Accept: application/vnd.github.raw",
287
+ `repos/${repository}/contents/${encodedPath}?ref=${encodeURIComponent(sha)}`,
288
+ ]);
289
+ }
290
+ catch {
291
+ return { kind: "unverifiable" };
292
+ }
293
+ const parsed = parseIncludedResponse(result.stdout ?? "");
294
+ if (!parsed)
295
+ return { kind: "unverifiable" };
296
+ if (parsed.status === 200 && result.status === 0)
297
+ return { kind: "present", content: parsed.body };
298
+ if (parsed.status === 404)
299
+ return { kind: "absent" };
300
+ return { kind: "unverifiable" };
301
+ }
302
+ /** The SHA a remote branch points at; `null` when absent; `undefined` when unknown. */
303
+ async function readRemoteBranchSha(deps, remoteName, branch) {
304
+ const ref = `refs/heads/${branch}`;
305
+ const raw = await captureRawStdout(deps.runGit, ["ls-remote", remoteName, ref]);
306
+ if (raw === null)
307
+ return undefined;
308
+ const lines = raw.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
309
+ const matches = lines
310
+ .map((line) => line.split(/\s+/))
311
+ .filter((parts) => parts.length === 2 && parts[1] === ref);
312
+ if (matches.length === 0)
313
+ return lines.length === 0 ? null : undefined;
314
+ if (matches.length > 1 || !/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(matches[0][0]))
315
+ return undefined;
316
+ return matches[0][0];
317
+ }
318
+ /**
319
+ * Find an open pull request already carrying this installation, by the
320
+ * deterministic managed BRANCH identity (a title is prose anyone can change).
321
+ * A lookup failure is distinct from a reliable "no open PR".
322
+ */
323
+ async function findExistingManagedPr(deps, repository, branch) {
324
+ const raw = await captureStdout(deps.runGh, [
325
+ "pr",
326
+ "list",
327
+ "--repo",
328
+ repository,
329
+ "--state",
330
+ "open",
331
+ "--head",
332
+ branch,
333
+ "--json",
334
+ "url,headRefName,headRefOid,baseRefName,isCrossRepository,files",
335
+ "--limit",
336
+ "2",
337
+ ]);
338
+ if (raw === null)
339
+ return { kind: "lookup_failed" };
340
+ let parsed;
341
+ try {
342
+ parsed = JSON.parse(raw);
343
+ }
344
+ catch {
345
+ return { kind: "lookup_failed" };
346
+ }
347
+ if (!Array.isArray(parsed))
348
+ return { kind: "lookup_failed" };
349
+ if (parsed.length === 0)
350
+ return { kind: "none" };
351
+ if (parsed.length > 1) {
352
+ // Two open PRs from one managed branch name cannot both be ours.
353
+ return { kind: "found", pr: { url: "", headRefName: "", headRefOid: "", baseRefName: "", isCrossRepository: null, files: [] } };
354
+ }
355
+ const first = parsed[0];
356
+ if (typeof first.url !== "string")
357
+ return { kind: "lookup_failed" };
358
+ const files = Array.isArray(first.files)
359
+ ? first.files
360
+ .map((f) => (f && typeof f === "object" ? f.path : undefined))
361
+ .filter((p) => typeof p === "string")
362
+ : [];
363
+ return {
364
+ kind: "found",
365
+ pr: {
366
+ url: first.url,
367
+ headRefName: typeof first.headRefName === "string" ? first.headRefName : "",
368
+ headRefOid: typeof first.headRefOid === "string" ? first.headRefOid : "",
369
+ baseRefName: typeof first.baseRefName === "string" ? first.baseRefName : "",
370
+ isCrossRepository: typeof first.isCrossRepository === "boolean" ? first.isCrossRepository : null,
371
+ files,
372
+ },
373
+ };
374
+ }
375
+ /**
376
+ * Confirm a detected pull request has the shape of this installation's review
377
+ * surface: the managed head branch in THIS repository, the default branch as
378
+ * base, and only managed paths changed.
379
+ */
380
+ function existingPrIsExpected(pr, branch, defaultBranch, managedPaths) {
381
+ if (pr.headRefName !== branch)
382
+ return false;
383
+ if (pr.baseRefName !== defaultBranch)
384
+ return false;
385
+ if (pr.isCrossRepository !== false)
386
+ return false;
387
+ if (!/^[0-9a-f]{40}([0-9a-f]{24})?$/.test(pr.headRefOid))
388
+ return false;
389
+ if (pr.files.length === 0)
390
+ return false;
391
+ const managed = new Set(managedPaths);
392
+ return pr.files.every((f) => managed.has(f));
393
+ }
394
+ /** Whether every managed file at the PR head equals the proposal. `null` if unreadable. */
395
+ async function prContentMatchesProposal(deps, repository, pr, proposals) {
396
+ for (const [relPath, proposal] of proposals) {
397
+ const file = await readRemoteFile(deps, repository, pr.headRefOid, relPath);
398
+ if (file.kind === "unverifiable")
399
+ return null;
400
+ if (file.kind === "absent" || file.content !== proposal)
401
+ return false;
402
+ }
403
+ return true;
404
+ }
405
+ function compareUrl(repository, defaultBranch, branch) {
406
+ return `https://github.com/${repository}/compare/${encodeURI(defaultBranch)}...${encodeURI(branch)}`;
407
+ }
408
+ /**
409
+ * Classify every managed artifact against the default branch at `sha`.
410
+ * Read-only. Prints each refused artifact's diff.
411
+ */
412
+ async function classifyAtRemote(deps, descriptor, repository, sha, quiet) {
413
+ const proposals = new Map();
414
+ let allIdentical = true;
415
+ let upgrade = false;
416
+ const refusals = [];
417
+ for (const artifact of descriptor.artifacts) {
418
+ const proposal = artifact.render();
419
+ proposals.set(artifact.relPath, proposal);
420
+ const remote = await readRemoteFile(deps, repository, sha, artifact.relPath);
421
+ if (remote.kind === "unverifiable")
422
+ return { ok: false, result: fail("remote_state_unverifiable") };
423
+ const existing = remote.kind === "present" ? remote.content : null;
424
+ const classification = artifact.classify(existing);
425
+ if (artifact.progressLabel && classification.text && !quiet) {
426
+ deps.log(` ${artifact.progressLabel}: ${classification.text}`);
427
+ }
428
+ if (classification.state === "conflict") {
429
+ refusals.push({
430
+ reason: classification.reason,
431
+ diff: { relPath: artifact.relPath, diff: renderUnifiedDiff(artifact.relPath, existing ?? "", proposal) },
432
+ });
433
+ continue;
434
+ }
435
+ if (classification.state !== "identical")
436
+ allIdentical = false;
437
+ if (classification.state === "managed_version_older")
438
+ upgrade = true;
439
+ }
440
+ if (refusals.length > 0) {
441
+ if (!quiet) {
442
+ for (const { diff } of refusals) {
443
+ deps.log("");
444
+ deps.log(`Not overwriting ${diff.relPath}. What this command would have written, against what is there:`);
445
+ for (const line of diff.diff.replace(/\n$/, "").split("\n"))
446
+ deps.log(line);
447
+ }
448
+ }
449
+ return {
450
+ ok: false,
451
+ result: fail(refusals[0].reason, { diffs: refusals.map((r) => r.diff) }),
452
+ };
453
+ }
454
+ return {
455
+ ok: true,
456
+ classification: allIdentical ? "identical" : upgrade ? "managed_version_older" : "not_installed",
457
+ proposals,
458
+ };
459
+ }
460
+ /**
461
+ * Run the complete read-only preflight for an artifact set.
230
462
  *
231
- * The progress lines are emitted in a fixed order — repository/worktree, default
232
- * branch, remote, git, gh, code owner — so two runs on different machines
233
- * produce comparable output.
463
+ * Every check here is a read: executables, repository root, clean worktree,
464
+ * default branch, remote and `gh` identity, set-specific options, the remote
465
+ * default-branch head (via `ls-remote`, no fetch), and each managed file's raw
466
+ * bytes at that head (via `gh api`). Nothing it calls creates a branch, writes a
467
+ * file, touches install state, fetches, commits, pushes, or opens a pull request.
234
468
  */
235
- export async function runMergeWorkflowPreflight(deps, options) {
469
+ export async function runArtifactSetPreflight(descriptor, deps) {
236
470
  // Managed paths are constants; this guards a future edit, not today's input.
237
- for (const relPath of MERGE_WORKFLOW_MANAGED_RELPATHS) {
238
- if (!isSafeManagedRelPath(relPath))
471
+ for (const artifact of descriptor.artifacts) {
472
+ if (!isSafeManagedRelPath(artifact.relPath))
239
473
  return { ok: false, result: fail("write_failed") };
240
474
  }
241
475
  if (!(await commandSucceeds(deps.runGit, ["--version"]))) {
@@ -253,26 +487,21 @@ export async function runMergeWorkflowPreflight(deps, options) {
253
487
  return { ok: false, result: fail("not_repository_root") };
254
488
  }
255
489
  deps.log(` repository root: ${normalizedRoot}`);
256
- // A clean worktree is required BEFORE a branch exists, so an unrelated
257
- // customer change can never be swept into the managed commit below.
490
+ // A clean worktree is still required, so the person is not surprised by a
491
+ // proposal built while their own changes are in flight.
258
492
  //
259
493
  // `--untracked-files=all` rather than the default: git otherwise COLLAPSES an
260
- // untracked directory to a single `?? .bridge/` entry, and the one path that
261
- // must be tolerated below could not then be distinguished from its neighbours.
262
- const status = await captureStdout(deps.runGit, ["status", "--porcelain", "--untracked-files=all"]);
494
+ // untracked directory to a single `?? .bridge/` entry. The output is read RAW
495
+ // (untrimmed) because the first status column is significant, and exactly one
496
+ // path — the install manifest, by full name — is tolerated.
497
+ const status = await captureRawStdout(deps.runGit, ["status", "--porcelain", "--untracked-files=all"]);
263
498
  if (status === null)
264
499
  return { ok: false, result: fail("git_failed") };
265
500
  const dirty = status
266
501
  .split("\n")
267
- .map((line) => line.trim())
268
- .filter((line) => line.length > 0)
269
- // The install manifest is Bridge's OWN record, written by this command and
270
- // deliberately never staged. Counting it as a customer change made a
271
- // successful install poison the very re-run the ticket requires to be a
272
- // clean no-op: the first run left the file behind, and the second refused
273
- // with `worktree_not_clean`. Exactly one path is tolerated, by full name, so
274
- // any other file under `.bridge/` still makes the worktree dirty.
275
- .filter((line) => !line.endsWith(MCP_INSTALL_STATE_RELPATH));
502
+ .map((line) => line.replace(/\r$/, ""))
503
+ .filter((line) => line.trim().length > 0)
504
+ .filter((line) => !isInstallStateLine(line));
276
505
  if (dirty.length > 0)
277
506
  return { ok: false, result: fail("worktree_not_clean") };
278
507
  deps.log(" worktree: clean");
@@ -309,135 +538,75 @@ export async function runMergeWorkflowPreflight(deps, options) {
309
538
  return { ok: false, result: fail("repository_identity_mismatch") };
310
539
  }
311
540
  deps.log(` gh: authenticated for ${ghRepository}`);
312
- let codeOwner;
313
- try {
314
- codeOwner = validateMergeWorkflowCodeOwner(options.codeOwner);
315
- }
316
- catch (err) {
317
- if (err instanceof MergeWorkflowCodeOwnerError) {
318
- return { ok: false, result: fail("codeowner_invalid") };
319
- }
320
- throw err;
541
+ if (descriptor.validateOptions) {
542
+ const checked = descriptor.validateOptions();
543
+ if (!checked.ok)
544
+ return { ok: false, result: fail(checked.reason) };
545
+ for (const line of checked.progress)
546
+ deps.log(line);
321
547
  }
322
- deps.log(` code owner: ${codeOwner}`);
323
- // --- content classification -------------------------------------------
324
- let existingWorkflow;
325
- try {
326
- existingWorkflow = await readOrNull(deps, joinCwd(normalizedRoot, MERGE_WORKFLOW_PATH));
327
- }
328
- catch {
329
- return { ok: false, result: fail("write_failed") };
330
- }
331
- const classification = classifyMergeWorkflowContent(existingWorkflow);
332
- deps.log(` workflow: ${MERGE_WORKFLOW_CLASSIFICATION_TEXT[classification]}`);
333
- if (classification === "modified_or_unrecognized") {
334
- return { ok: false, result: fail("workflow_modified_or_unrecognized") };
335
- }
336
- // Companion artifacts are inspected BEFORE any write. An existing file whose
337
- // bytes differ from what this owner would produce is a conflict, not a target:
338
- // it may be a previous install for a DIFFERENT code owner, or a customer edit.
339
- const companions = [
340
- [MERGE_WORKFLOW_CODEOWNERS_RELPATH, renderMergeWorkflowCodeownersFragment(codeOwner)],
341
- [MERGE_WORKFLOW_GUIDANCE_RELPATH, renderMergeWorkflowGuidance(codeOwner)],
342
- ];
343
- let allCompanionsIdentical = true;
344
- for (const [relPath, expected] of companions) {
345
- let existing;
346
- try {
347
- existing = await readOrNull(deps, joinCwd(normalizedRoot, relPath));
348
- }
349
- catch {
350
- return { ok: false, result: fail("write_failed") };
351
- }
352
- if (existing === null) {
353
- allCompanionsIdentical = false;
354
- continue;
355
- }
356
- if (existing !== expected) {
357
- return { ok: false, result: fail("companion_artifact_conflict") };
358
- }
548
+ // The default branch head, read from the remote. A managed branch is never
549
+ // the default branch; that is enforced again at push time.
550
+ if (descriptor.installBranch === ghDefaultBranch || descriptor.upgradeBranch === ghDefaultBranch) {
551
+ return { ok: false, result: fail("default_branch_unresolved") };
359
552
  }
360
- // The aggregate no-op requires EVERY managed artifact to match. A workflow that
361
- // is already identical while its guidance is missing is still an installation.
362
- const effective = classification === "identical" && !allCompanionsIdentical ? "not_installed" : classification;
553
+ const defaultBranchSha = await readRemoteBranchSha(deps, remoteName, ghDefaultBranch);
554
+ if (defaultBranchSha === undefined)
555
+ return { ok: false, result: fail("remote_state_unverifiable") };
556
+ if (defaultBranchSha === null)
557
+ return { ok: false, result: fail("default_branch_unresolved") };
558
+ const classified = await classifyAtRemote(deps, descriptor, ghRepository, defaultBranchSha, false);
559
+ if (!classified.ok)
560
+ return { ok: false, result: classified.result };
363
561
  return {
364
562
  ok: true,
365
563
  preflight: {
366
564
  repositoryRoot: normalizedRoot,
367
565
  defaultBranch: ghDefaultBranch,
566
+ defaultBranchSha,
368
567
  remoteName,
369
568
  repository: ghRepository,
370
- codeOwner,
371
- classification: effective,
569
+ classification: classified.classification,
570
+ proposals: classified.proposals,
372
571
  },
373
572
  };
374
573
  }
375
574
  /**
376
- * Find an open pull request already carrying this installation.
377
- *
378
- * Looked up by the deterministic managed BRANCH identity rather than by title:
379
- * a title is prose anyone can change, while the branch is the thing this command
380
- * would otherwise try to create.
575
+ * Inspect the managed pull request and branch for `branch`. Read-only.
576
+ * Returns `null` when the way is clear, or the outcome to report.
381
577
  */
382
- async function findExistingManagedPr(deps, branch) {
383
- const raw = await captureStdout(deps.runGh, [
384
- "pr",
385
- "list",
386
- "--state",
387
- "open",
388
- "--head",
389
- branch,
390
- "--json",
391
- "url,headRefName,baseRefName,files",
392
- "--limit",
393
- "1",
394
- ]);
395
- if (!raw)
396
- return null;
397
- try {
398
- const parsed = JSON.parse(raw);
399
- if (!Array.isArray(parsed) || parsed.length === 0)
400
- return null;
401
- const first = parsed[0];
402
- const files = Array.isArray(first.files)
403
- ? first.files
404
- .map((f) => (f && typeof f === "object" ? f.path : undefined))
405
- .filter((p) => typeof p === "string")
406
- : [];
407
- if (typeof first.url !== "string")
408
- return null;
409
- return {
410
- url: first.url,
411
- headRefName: typeof first.headRefName === "string" ? first.headRefName : "",
412
- baseRefName: typeof first.baseRefName === "string" ? first.baseRefName : "",
413
- files,
414
- };
578
+ async function inspectManagedState(deps, descriptor, preflight, branch, upgrade) {
579
+ const managedPaths = descriptor.artifacts.map((a) => a.relPath);
580
+ const lookup = await findExistingManagedPr(deps, preflight.repository, branch);
581
+ if (lookup.kind === "lookup_failed")
582
+ return fail("remote_state_unverifiable", { branch });
583
+ if (lookup.kind === "found") {
584
+ if (!existingPrIsExpected(lookup.pr, branch, preflight.defaultBranch, managedPaths)) {
585
+ return fail("existing_pr_unverifiable", { branch });
586
+ }
587
+ const matches = await prContentMatchesProposal(deps, preflight.repository, lookup.pr, preflight.proposals);
588
+ if (matches === null)
589
+ return fail("existing_pr_unverifiable", { branch, prUrl: lookup.pr.url });
590
+ if (!matches)
591
+ return fail("existing_pr_differs", { branch, prUrl: lookup.pr.url });
592
+ return { outcome: "existing-pr", branch, prUrl: lookup.pr.url, upgrade, warnings: [] };
415
593
  }
416
- catch {
417
- return null;
594
+ // Independently of PR discovery: a pushed managed branch with no open PR.
595
+ const branchSha = await readRemoteBranchSha(deps, preflight.remoteName, branch);
596
+ if (branchSha === undefined)
597
+ return fail("remote_state_unverifiable", { branch });
598
+ if (branchSha !== null) {
599
+ return fail("managed_branch_without_pr", {
600
+ branch,
601
+ compareUrl: compareUrl(preflight.repository, preflight.defaultBranch, branch),
602
+ });
418
603
  }
419
- }
420
- /**
421
- * Confirm a detected pull request really is this installation's review surface.
422
- *
423
- * Reporting an unverified pull request as "already open" would tell an operator
424
- * the review exists when it might touch different files, target a different
425
- * base, or have been opened for something else entirely.
426
- */
427
- function existingPrIsExpected(pr, branch, defaultBranch) {
428
- if (pr.headRefName !== branch)
429
- return false;
430
- if (pr.baseRefName !== defaultBranch)
431
- return false;
432
- if (pr.files.length === 0)
433
- return false;
434
- const managed = new Set(MERGE_WORKFLOW_MANAGED_RELPATHS);
435
- return pr.files.every((f) => managed.has(f));
604
+ return null;
436
605
  }
437
606
  // ---------------------------------------------------------------------------
438
- // Pull request body
607
+ // Merge-workflow descriptor
439
608
  // ---------------------------------------------------------------------------
440
- /** Render the pull request body. Deterministic, and free of any secret value. */
609
+ /** Render the merge-workflow pull request body. Deterministic, and free of any secret value. */
441
610
  export function renderMergeWorkflowPrBody(codeOwner, upgrade) {
442
611
  const owner = validateMergeWorkflowCodeOwner(codeOwner);
443
612
  return [
@@ -479,159 +648,428 @@ export function renderMergeWorkflowPrBody(codeOwner, upgrade) {
479
648
  "",
480
649
  ].join("\n");
481
650
  }
651
+ /** A companion: absent or byte-identical is fine; anything else is a conflict. */
652
+ function companionArtifact(relPath, render) {
653
+ return {
654
+ relPath,
655
+ render,
656
+ classify: (existing) => {
657
+ if (existing === null)
658
+ return { state: "not_installed" };
659
+ if (existing === render())
660
+ return { state: "identical" };
661
+ return { state: "conflict", reason: "companion_artifact_conflict" };
662
+ },
663
+ };
664
+ }
665
+ /** The merge-workflow artifact set for one code owner. */
666
+ export function buildMergeWorkflowArtifactSet(codeOwner) {
667
+ let owner = codeOwner;
668
+ return {
669
+ setName: "merge-workflow",
670
+ installBranch: MERGE_WORKFLOW_INSTALL_BRANCH,
671
+ upgradeBranch: MERGE_WORKFLOW_UPGRADE_BRANCH,
672
+ installCommitSubject: MERGE_WORKFLOW_INSTALL_COMMIT_SUBJECT,
673
+ upgradeCommitSubject: MERGE_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
674
+ installPrTitle: MERGE_WORKFLOW_INSTALL_PR_TITLE,
675
+ upgradePrTitle: MERGE_WORKFLOW_UPGRADE_PR_TITLE,
676
+ renderPrBody: (upgrade) => renderMergeWorkflowPrBody(owner, upgrade),
677
+ validateOptions: () => {
678
+ try {
679
+ owner = validateMergeWorkflowCodeOwner(codeOwner);
680
+ }
681
+ catch (err) {
682
+ if (err instanceof MergeWorkflowCodeOwnerError)
683
+ return { ok: false, reason: "codeowner_invalid" };
684
+ throw err;
685
+ }
686
+ return { ok: true, progress: [` code owner: ${owner}`] };
687
+ },
688
+ consentPrompt: (plan) => `Create branch ${plan.branch}, write ${plan.artifacts.length} files, commit, push, and open a pull request? [y/N] `,
689
+ artifacts: [
690
+ {
691
+ relPath: MERGE_WORKFLOW_PATH,
692
+ render: () => renderEpicImplementerMergeWorkflow(),
693
+ progressLabel: "workflow",
694
+ classify: (existing) => {
695
+ const classification = classifyMergeWorkflowContent(existing);
696
+ const text = MERGE_WORKFLOW_CLASSIFICATION_TEXT[classification];
697
+ if (classification === "modified_or_unrecognized") {
698
+ return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
699
+ }
700
+ return { state: classification, text };
701
+ },
702
+ },
703
+ companionArtifact(MERGE_WORKFLOW_CODEOWNERS_RELPATH, () => renderMergeWorkflowCodeownersFragment(owner)),
704
+ companionArtifact(MERGE_WORKFLOW_GUIDANCE_RELPATH, () => renderMergeWorkflowGuidance(owner)),
705
+ ],
706
+ };
707
+ }
708
+ /**
709
+ * Run the complete read-only merge-workflow preflight. Compatibility entry point
710
+ * around {@link runArtifactSetPreflight}.
711
+ */
712
+ export async function runMergeWorkflowPreflight(deps, options) {
713
+ const pre = await runArtifactSetPreflight(buildMergeWorkflowArtifactSet(options.codeOwner), deps);
714
+ if (!pre.ok)
715
+ return pre;
716
+ return {
717
+ ok: true,
718
+ preflight: { ...pre.preflight, codeOwner: validateMergeWorkflowCodeOwner(options.codeOwner) },
719
+ };
720
+ }
482
721
  // ---------------------------------------------------------------------------
483
722
  // Orchestration
484
723
  // ---------------------------------------------------------------------------
724
+ /** How many times consent is asked before a still-moving default branch stops the run. */
725
+ const MAX_CONSENT_ROUNDS = 3;
726
+ function defaultConsentPrompt(plan) {
727
+ return (`Create branch ${plan.branch} from ${plan.defaultBranch} in a temporary worktree, write ` +
728
+ `${plan.artifacts.join(", ")}, commit "${plan.commitSubject}", push to ` +
729
+ `${plan.remoteName}/${plan.branch}, and open a pull request into ${plan.defaultBranch}? [y/N] `);
730
+ }
485
731
  async function consent(deps, promptText) {
486
732
  if (!deps.confirmWrite)
487
733
  return false;
488
734
  return await deps.confirmWrite(promptText);
489
735
  }
736
+ function samePlan(a, b) {
737
+ if (a.classification !== b.classification)
738
+ return false;
739
+ if (a.proposals.size !== b.proposals.size)
740
+ return false;
741
+ for (const [path, content] of a.proposals)
742
+ if (b.proposals.get(path) !== content)
743
+ return false;
744
+ return true;
745
+ }
746
+ /** Refuse to write through a symlink anywhere on the path inside the worktree. */
747
+ async function pathIsSafeInWorktree(deps, worktree, relPath) {
748
+ const target = resolve(worktree, relPath);
749
+ if (!target.startsWith(resolve(worktree) + "/"))
750
+ return false;
751
+ const lstat = deps.lstat ?? fsLstat;
752
+ const segments = relPath.split("/");
753
+ let current = resolve(worktree);
754
+ for (const segment of segments) {
755
+ current = join(current, segment);
756
+ try {
757
+ if ((await lstat(current)).isSymbolicLink())
758
+ return false;
759
+ }
760
+ catch (err) {
761
+ if (isEnoent(err))
762
+ return true;
763
+ return false;
764
+ }
765
+ }
766
+ return true;
767
+ }
490
768
  /**
491
- * Generate the managed artifacts and open the customer's review pull request.
769
+ * Install one artifact set: read-only preflight, consent, then all writes in a
770
+ * temporary worktree, push to the managed branch, and open the pull request.
492
771
  *
493
- * Returns a process exit code: `0` for every success shape (new pull request,
494
- * upgrade pull request, verified existing pull request, byte-identical no-op,
495
- * dry run) and `1` for every failure. A failure prints the stable reason token
496
- * first and one remediation sentence second, both on stderr.
497
- *
498
- * Nothing already created is undone on a later failure. A branch that exists, a
499
- * file that was written, or a ref that was pushed is left in place with a
500
- * bounded recovery instruction: deleting a customer's branch to tidy up after
501
- * ourselves is a destructive act taken on incomplete information.
772
+ * Progress lines go to `deps.log`; the caller reports the returned outcome and
773
+ * prints any `warnings` (cleanup problems) after it, on stderr.
774
+ * Nothing already pushed is undone on a later failure: deleting a customer's
775
+ * branch to tidy up is a destructive act taken on incomplete information.
502
776
  */
503
- export async function runMergeWorkflowInstall(cwd, options, deps) {
504
- const report = (result) => {
505
- if (result.outcome === "failed") {
506
- deps.errorLog(`${result.reason}`);
507
- deps.errorLog(result.remediation);
508
- return 1;
509
- }
510
- return 0;
511
- };
512
- deps.log("Bridge merge-workflow installer");
513
- deps.log(" preflight:");
514
- const pre = await runMergeWorkflowPreflight({ ...deps, cwd }, options);
777
+ export async function installArtifactSet(descriptor, options, deps) {
778
+ const pre = await runArtifactSetPreflight(descriptor, deps);
515
779
  if (!pre.ok)
516
- return report(pre.result);
517
- const preflight = pre.preflight;
780
+ return pre.result;
781
+ let preflight = pre.preflight;
518
782
  if (preflight.classification === "identical") {
519
- deps.log("");
520
- deps.log("Clean no-op: every managed artifact already matches this build.");
521
- deps.log(` ${MERGE_WORKFLOW_PATH} (contract version ${MERGE_WORKFLOW_EXPECTED_VERSION})`);
522
- deps.log("Nothing was written and no pull request was opened.");
523
- return 0;
783
+ return { outcome: "identical", artifacts: [...preflight.proposals.keys()], warnings: [] };
524
784
  }
525
- const upgrade = preflight.classification === "managed_version_older";
526
- const branch = upgrade ? MERGE_WORKFLOW_UPGRADE_BRANCH : MERGE_WORKFLOW_INSTALL_BRANCH;
527
- // Asked BEFORE a local branch exists, so a verified open pull request is
528
- // reported instead of duplicated rather than after a duplicate branch is made.
529
- const existing = await findExistingManagedPr(deps, branch);
530
- if (existing) {
531
- if (!existingPrIsExpected(existing, branch, preflight.defaultBranch)) {
532
- return report(fail("existing_pr_unverifiable"));
785
+ // An open pull request from an earlier renderer version's branch comes first:
786
+ // it targets the same managed file, so new work would race it.
787
+ for (const historical of descriptor.historicalBranches ?? []) {
788
+ const lookup = await findExistingManagedPr(deps, preflight.repository, historical);
789
+ if (lookup.kind === "lookup_failed")
790
+ return fail("remote_state_unverifiable", { branch: historical });
791
+ if (lookup.kind === "found") {
792
+ return fail("historical_managed_pr_open", {
793
+ branch: historical,
794
+ ...(lookup.pr.url.length > 0 ? { prUrl: lookup.pr.url } : {}),
795
+ });
533
796
  }
797
+ }
798
+ const managedPaths = descriptor.artifacts.map((a) => a.relPath);
799
+ let upgrade = false;
800
+ let branch = "";
801
+ let commitSubject = "";
802
+ // Consent covers one plan at one default-branch head. When the default branch
803
+ // moves after consent and the plan changes, the new plan is shown and consent
804
+ // is asked again; a branch that keeps moving stops with default_branch_moved.
805
+ for (let round = 0;; round += 1) {
806
+ upgrade = preflight.classification === "managed_version_older";
807
+ branch = upgrade ? descriptor.upgradeBranch : descriptor.installBranch;
808
+ commitSubject = upgrade ? descriptor.upgradeCommitSubject : descriptor.installCommitSubject;
809
+ const managed = await inspectManagedState(deps, descriptor, preflight, branch, upgrade);
810
+ if (managed)
811
+ return managed;
812
+ const plan = {
813
+ branch,
814
+ upgrade,
815
+ artifacts: managedPaths,
816
+ commitSubject,
817
+ remoteName: preflight.remoteName,
818
+ defaultBranch: preflight.defaultBranch,
819
+ };
534
820
  deps.log("");
535
- deps.log(`${upgrade ? "Upgrade" : "Installation"} pull request is already open.`);
821
+ if (round > 0)
822
+ deps.log(`${preflight.defaultBranch} moved since you approved, and the plan changed.`);
823
+ deps.log(upgrade ? "Planned upgrade:" : "Planned installation:");
536
824
  deps.log(` branch: ${branch}`);
537
- deps.log(` pull request: ${existing.url}`);
538
- deps.log("Review and merge it; re-running this command opens nothing new.");
539
- return 0;
825
+ for (const relPath of managedPaths)
826
+ deps.log(` file: ${relPath}`);
827
+ deps.log(` commit: ${commitSubject}`);
828
+ deps.log(` push: ${preflight.remoteName}/${branch} (your git identity)`);
829
+ deps.log(` pull request: into ${preflight.defaultBranch} (your gh identity)`);
830
+ if (options.dryRun) {
831
+ deps.log("");
832
+ deps.log("--dry-run: nothing was written, committed, pushed, or opened.");
833
+ return { outcome: "dry-run", branch, artifacts: managedPaths, upgrade, warnings: [] };
834
+ }
835
+ const prompt = (descriptor.consentPrompt ?? defaultConsentPrompt)(plan);
836
+ if (!(await consent(deps, prompt)))
837
+ return fail("consent_declined", { branch });
838
+ // --- first mutation: fetch the default branch into the remote-tracking ref --
839
+ const trackingRef = `refs/remotes/${preflight.remoteName}/${preflight.defaultBranch}`;
840
+ if (!(await commandSucceeds(deps.runGit, [
841
+ "fetch",
842
+ "--no-tags",
843
+ preflight.remoteName,
844
+ `+refs/heads/${preflight.defaultBranch}:${trackingRef}`,
845
+ ]))) {
846
+ return fail("git_failed", { branch });
847
+ }
848
+ const fetchedSha = await captureStdout(deps.runGit, ["rev-parse", "--verify", "--quiet", `${trackingRef}^{commit}`]);
849
+ if (!fetchedSha)
850
+ return fail("git_failed", { branch });
851
+ if (fetchedSha === preflight.defaultBranchSha)
852
+ break;
853
+ // The default branch moved: re-inspect at the fetched head. An unchanged
854
+ // plan proceeds from the new head under the consent already given.
855
+ const again = await classifyAtRemote(deps, descriptor, preflight.repository, fetchedSha, true);
856
+ if (!again.ok && again.result.reason === "remote_state_unverifiable")
857
+ return fail("remote_state_unverifiable", { branch });
858
+ if (!again.ok)
859
+ return fail("default_branch_moved", { branch });
860
+ const unchanged = samePlan(again, preflight);
861
+ preflight = { ...preflight, defaultBranchSha: fetchedSha, classification: again.classification, proposals: again.proposals };
862
+ if (unchanged)
863
+ break;
864
+ if (again.classification === "identical") {
865
+ return { outcome: "identical", artifacts: [...again.proposals.keys()], warnings: [] };
866
+ }
867
+ if (round + 1 >= MAX_CONSENT_ROUNDS)
868
+ return fail("default_branch_moved", { branch });
540
869
  }
541
- deps.log("");
542
- deps.log(upgrade ? "Planned upgrade:" : "Planned installation:");
543
- deps.log(` branch: ${branch}`);
544
- for (const relPath of MERGE_WORKFLOW_MANAGED_RELPATHS)
545
- deps.log(` file: ${relPath}`);
546
- deps.log(` commit: ${upgrade ? MERGE_WORKFLOW_UPGRADE_COMMIT_SUBJECT : MERGE_WORKFLOW_INSTALL_COMMIT_SUBJECT}`);
547
- deps.log(` push: ${preflight.remoteName}/${branch} (your git identity)`);
548
- deps.log(` pull request: into ${preflight.defaultBranch} (your gh identity)`);
549
- if (options.dryRun) {
550
- deps.log("");
551
- deps.log("--dry-run: nothing was written, committed, pushed, or opened.");
552
- return 0;
870
+ const makeTempDir = deps.makeTempDir ?? (() => mkdtemp(join(tmpdir(), `bridge-${descriptor.setName}-`)));
871
+ const removeDir = deps.removeDir ?? ((dir) => rm(dir, { recursive: true, force: true }));
872
+ let tempRoot;
873
+ try {
874
+ tempRoot = await makeTempDir();
553
875
  }
554
- if (!(await consent(deps, `Create branch ${branch}, write ${MERGE_WORKFLOW_MANAGED_RELPATHS.length} files, commit, push, and open a pull request? [y/N] `))) {
555
- return report(fail("consent_declined"));
876
+ catch {
877
+ return fail("worktree_failed", { branch });
556
878
  }
557
- // --- first mutation: the branch ----------------------------------------
558
- if (!(await commandSucceeds(deps.runGit, ["checkout", "-b", branch]))) {
559
- return report(fail("git_failed"));
879
+ const worktree = join(tempRoot, "worktree");
880
+ const warnings = [];
881
+ let worktreeAdded = false;
882
+ const run = async () => {
883
+ if (!(await commandSucceeds(deps.runGit, [
884
+ "worktree",
885
+ "add",
886
+ "--detach",
887
+ worktree,
888
+ preflight.defaultBranchSha,
889
+ ]))) {
890
+ return fail("worktree_failed", { branch });
891
+ }
892
+ worktreeAdded = true;
893
+ for (const artifact of descriptor.artifacts) {
894
+ const content = preflight.proposals.get(artifact.relPath);
895
+ if (!(await pathIsSafeInWorktree(deps, worktree, artifact.relPath)))
896
+ return fail("write_failed", { branch });
897
+ const absPath = joinCwd(worktree, artifact.relPath);
898
+ const parent = absPath.slice(0, absPath.lastIndexOf("/"));
899
+ try {
900
+ // Read-compare-write: an identical target is never rewritten.
901
+ let existing;
902
+ try {
903
+ existing = await deps.readFile(absPath);
904
+ }
905
+ catch (err) {
906
+ if (!isEnoent(err))
907
+ throw err;
908
+ existing = null;
909
+ }
910
+ if (existing !== content) {
911
+ await deps.mkdir(parent, { recursive: true });
912
+ await deps.writeFile(absPath, content, { encoding: "utf-8" });
913
+ }
914
+ }
915
+ catch {
916
+ return fail("write_failed", { branch });
917
+ }
918
+ try {
919
+ // The manifest lands in the temporary worktree and is never staged.
920
+ await deps.recordArtifact(worktree, artifact.relPath);
921
+ }
922
+ catch {
923
+ // Recording is best effort and never blocks the install.
924
+ }
925
+ }
926
+ // Only the explicit managed paths are staged, after `--`.
927
+ if (!(await commandSucceeds(deps.runGit, ["-C", worktree, "add", "--", ...managedPaths]))) {
928
+ return fail("git_failed", { branch });
929
+ }
930
+ if (!(await commandSucceeds(deps.runGit, ["-C", worktree, "commit", "-m", commitSubject]))) {
931
+ return fail("git_failed", { branch });
932
+ }
933
+ // Immediately before push: nobody else created the managed branch or PR.
934
+ const raced = await inspectManagedState(deps, descriptor, preflight, branch, upgrade);
935
+ if (raced) {
936
+ if (raced.outcome === "failed" && raced.reason === "remote_state_unverifiable")
937
+ return raced;
938
+ return fail("managed_state_changed", { branch });
939
+ }
940
+ if (branch === preflight.defaultBranch)
941
+ return fail("git_failed", { branch });
942
+ if (!(await commandSucceeds(deps.runGit, [
943
+ "-C",
944
+ worktree,
945
+ "push",
946
+ preflight.remoteName,
947
+ `HEAD:refs/heads/${branch}`,
948
+ ]))) {
949
+ return fail("git_failed", { branch });
950
+ }
951
+ const prUrl = await captureStdout(deps.runGh, [
952
+ "pr",
953
+ "create",
954
+ "--repo",
955
+ preflight.repository,
956
+ "--base",
957
+ preflight.defaultBranch,
958
+ "--head",
959
+ branch,
960
+ "--title",
961
+ upgrade ? descriptor.upgradePrTitle : descriptor.installPrTitle,
962
+ "--body",
963
+ descriptor.renderPrBody(upgrade),
964
+ ]);
965
+ if (!prUrl) {
966
+ return fail("pr_open_failed", {
967
+ branch,
968
+ compareUrl: compareUrl(preflight.repository, preflight.defaultBranch, branch),
969
+ });
970
+ }
971
+ return {
972
+ outcome: upgrade ? "upgrade-pr-opened" : "installed-pr-opened",
973
+ branch,
974
+ prUrl,
975
+ artifacts: managedPaths,
976
+ warnings: [],
977
+ };
978
+ };
979
+ let result;
980
+ try {
981
+ result = await run();
560
982
  }
561
- const artifacts = [
562
- [MERGE_WORKFLOW_PATH, renderEpicImplementerMergeWorkflow()],
563
- [MERGE_WORKFLOW_CODEOWNERS_RELPATH, renderMergeWorkflowCodeownersFragment(preflight.codeOwner)],
564
- [MERGE_WORKFLOW_GUIDANCE_RELPATH, renderMergeWorkflowGuidance(preflight.codeOwner)],
565
- ];
566
- const written = [];
567
- for (const [relPath, content] of artifacts) {
568
- const absPath = joinCwd(preflight.repositoryRoot, relPath);
569
- const parent = absPath.slice(0, absPath.lastIndexOf("/"));
983
+ finally {
984
+ let cleaned = true;
985
+ if (worktreeAdded && !(await commandSucceeds(deps.runGit, ["worktree", "remove", "--force", worktree]))) {
986
+ cleaned = false;
987
+ }
570
988
  try {
571
- // Read-compare-write: an identical target is never rewritten, so a partial
572
- // re-run does not churn file mtimes or produce an empty diff entry.
573
- const existingContent = await readOrNull(deps, absPath);
574
- if (existingContent !== content) {
575
- await deps.mkdir(parent, { recursive: true });
576
- await deps.writeFile(absPath, content, { encoding: "utf-8" });
577
- }
578
- written.push(relPath);
989
+ await removeDir(tempRoot);
579
990
  }
580
991
  catch {
581
- return report(fail("write_failed"));
992
+ cleaned = false;
993
+ }
994
+ if (!cleaned) {
995
+ const warning = `cleanup_incomplete: the temporary worktree at ${worktree} was not fully removed. ` +
996
+ `Remove it with \`git worktree remove --force ${worktree}\` and delete ${tempRoot}.`;
997
+ // Returned, not printed: the caller prints it AFTER its own outcome, so a
998
+ // failure's stable reason token stays the first stderr line.
999
+ warnings.push(warning);
582
1000
  }
583
- // Recorded per artifact, with the POSIX repository-relative path only.
584
- await deps.recordArtifact(preflight.repositoryRoot, relPath);
585
- }
586
- // Only the explicit managed paths are staged, passed after `--` so a path can
587
- // never be read as a git option.
588
- if (!(await commandSucceeds(deps.runGit, ["add", "--", ...MERGE_WORKFLOW_MANAGED_RELPATHS]))) {
589
- return report(fail("git_failed"));
590
- }
591
- const commitSubject = upgrade
592
- ? MERGE_WORKFLOW_UPGRADE_COMMIT_SUBJECT
593
- : MERGE_WORKFLOW_INSTALL_COMMIT_SUBJECT;
594
- if (!(await commandSucceeds(deps.runGit, ["commit", "-m", commitSubject]))) {
595
- return report(fail("git_failed"));
596
- }
597
- if (!(await commandSucceeds(deps.runGit, [
598
- "push",
599
- "--set-upstream",
600
- preflight.remoteName,
601
- branch,
602
- ]))) {
603
- return report(fail("git_failed"));
604
1001
  }
605
- const prTitle = upgrade ? MERGE_WORKFLOW_UPGRADE_PR_TITLE : MERGE_WORKFLOW_INSTALL_PR_TITLE;
606
- const prUrl = await captureStdout(deps.runGh, [
607
- "pr",
608
- "create",
609
- "--base",
610
- preflight.defaultBranch,
611
- "--head",
612
- branch,
613
- "--title",
614
- prTitle,
615
- "--body",
616
- renderMergeWorkflowPrBody(preflight.codeOwner, upgrade),
617
- ]);
618
- if (!prUrl) {
619
- deps.errorLog("pr_open_failed");
620
- deps.errorLog(`${REMEDIATION.pr_open_failed} The branch ${branch} is pushed to ${preflight.remoteName} and was left in place.`);
621
- return 1;
1002
+ return { ...result, warnings: [...result.warnings, ...warnings] };
1003
+ }
1004
+ /**
1005
+ * Generate the merge-workflow artifacts and open the customer's review PR.
1006
+ *
1007
+ * Compatibility wrapper for `install-bridge conductor --merge-workflow` around
1008
+ * {@link installArtifactSet}. Returns a process exit code: `0` for every
1009
+ * success shape (new pull request, upgrade pull request, verified existing pull
1010
+ * request, byte-identical no-op, dry run) and `1` for every failure. A failure
1011
+ * prints the stable reason token first and one remediation sentence second,
1012
+ * both on stderr.
1013
+ */
1014
+ export async function runMergeWorkflowInstall(cwd, options, deps) {
1015
+ deps.log("Bridge merge-workflow installer");
1016
+ deps.log(" preflight:");
1017
+ const descriptor = buildMergeWorkflowArtifactSet(options.codeOwner);
1018
+ const result = await installArtifactSet(descriptor, { dryRun: options.dryRun }, { ...deps, cwd });
1019
+ const exitCode = reportMergeWorkflowResult(result, deps);
1020
+ for (const warning of result.warnings)
1021
+ deps.errorLog(warning);
1022
+ return exitCode;
1023
+ }
1024
+ function reportMergeWorkflowResult(result, deps) {
1025
+ switch (result.outcome) {
1026
+ case "failed":
1027
+ deps.errorLog(`${result.reason}`);
1028
+ if (result.reason === "pr_open_failed" && result.branch) {
1029
+ deps.errorLog(`${result.remediation} The branch ${result.branch} is pushed to origin and was left in place.`);
1030
+ }
1031
+ else if (result.reason === "managed_branch_without_pr" && result.branch) {
1032
+ deps.errorLog(`${result.remediation} Managed branch: ${result.branch}.`);
1033
+ if (result.compareUrl)
1034
+ deps.errorLog(`Open a pull request from it: ${result.compareUrl}`);
1035
+ }
1036
+ else if (result.reason === "existing_pr_differs" && result.prUrl) {
1037
+ deps.errorLog(`${result.remediation} Pull request: ${result.prUrl}`);
1038
+ }
1039
+ else {
1040
+ deps.errorLog(result.remediation);
1041
+ }
1042
+ return 1;
1043
+ case "identical":
1044
+ deps.log("");
1045
+ deps.log("Clean no-op: every managed artifact already matches this build.");
1046
+ deps.log(` ${MERGE_WORKFLOW_PATH} (contract version ${MERGE_WORKFLOW_EXPECTED_VERSION})`);
1047
+ deps.log("Nothing was written and no pull request was opened.");
1048
+ return 0;
1049
+ case "existing-pr":
1050
+ deps.log("");
1051
+ deps.log(`${result.upgrade ? "Upgrade" : "Installation"} pull request is already open.`);
1052
+ deps.log(` branch: ${result.branch}`);
1053
+ deps.log(` pull request: ${result.prUrl}`);
1054
+ deps.log("Review and merge it; re-running this command opens nothing new.");
1055
+ return 0;
1056
+ case "dry-run":
1057
+ return 0;
1058
+ case "installed-pr-opened":
1059
+ case "upgrade-pr-opened":
1060
+ deps.log("");
1061
+ deps.log(result.outcome === "upgrade-pr-opened" ? "Upgrade pull request opened." : "Installation pull request opened.");
1062
+ deps.log(` branch: ${result.branch}`);
1063
+ for (const relPath of result.artifacts)
1064
+ deps.log(` file: ${relPath}`);
1065
+ deps.log(` pull request: ${result.prUrl}`);
1066
+ deps.log("");
1067
+ deps.log("Next, in this order:");
1068
+ deps.log(" 1. Review the pull request — the workflow is what performs the privileged merge.");
1069
+ deps.log(` 2. Create the repository Actions secret ${MERGE_WORKFLOW_API_KEY_SECRET_NAME} through GitHub. Never pass its value to this command.`);
1070
+ deps.log(` 3. Merge the rule in ${MERGE_WORKFLOW_CODEOWNERS_RELPATH} into your active CODEOWNERS file.`);
1071
+ deps.log(" 4. Add a default-branch rule requiring a pull request and code-owner review.");
1072
+ deps.log(" 5. Merge the pull request yourself; Bridge never merges it.");
1073
+ return 0;
622
1074
  }
623
- deps.log("");
624
- deps.log(upgrade ? "Upgrade pull request opened." : "Installation pull request opened.");
625
- deps.log(` branch: ${branch}`);
626
- for (const relPath of written)
627
- deps.log(` file: ${relPath}`);
628
- deps.log(` pull request: ${prUrl}`);
629
- deps.log("");
630
- deps.log("Next, in this order:");
631
- deps.log(" 1. Review the pull request — the workflow is what performs the privileged merge.");
632
- deps.log(` 2. Create the repository Actions secret ${MERGE_WORKFLOW_API_KEY_SECRET_NAME} through GitHub. Never pass its value to this command.`);
633
- deps.log(` 3. Merge the rule in ${MERGE_WORKFLOW_CODEOWNERS_RELPATH} into your active CODEOWNERS file.`);
634
- deps.log(" 4. Add a default-branch rule requiring a pull request and code-owner review.");
635
- deps.log(" 5. Merge the pull request yourself; Bridge never merges it.");
636
- return 0;
637
1075
  }