@bridge_gpt/mcp-server 0.2.71 → 0.2.73

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 (198) hide show
  1. package/README.md +55 -17
  2. package/build/agent-launchers/claude-executor-adapter.js +22 -3
  3. package/build/agent-notes.js +171 -95
  4. package/build/agents.generated.js +7 -7
  5. package/build/bridge-permissions.js +31 -0
  6. package/build/bridge-worktree-inspection.js +237 -0
  7. package/build/check-evidence.js +6 -0
  8. package/build/ci-system-detection.js +50 -0
  9. package/build/ci-trigger-adapters.js +631 -0
  10. package/build/ci-trigger-install.js +106 -0
  11. package/build/claude-review-workflow.js +1 -1
  12. package/build/cli-help.js +6 -0
  13. package/build/codex-auto-recovery.js +126 -0
  14. package/build/codex-launcher-pin.js +33 -2
  15. package/build/codex-skill-adapter.js +5 -1
  16. package/build/command-host.js +33 -0
  17. package/build/commands.generated.js +7 -6
  18. package/build/conductor/bridge-api-client.js +1352 -50
  19. package/build/conductor/bring-up-facts.js +18 -5
  20. package/build/conductor/command-drift-production.js +42 -17
  21. package/build/conductor/command-drift.js +47 -0
  22. package/build/conductor/declare-blocked.js +554 -0
  23. package/build/conductor/doctor.js +187 -28
  24. package/build/conductor/driver-commands.js +141 -0
  25. package/build/conductor/driver-guard.js +277 -0
  26. package/build/conductor/driver-lapse.js +321 -0
  27. package/build/conductor/driver-register.js +176 -0
  28. package/build/conductor/driver-release.js +174 -0
  29. package/build/conductor/driver-session-state.js +315 -0
  30. package/build/conductor/epic-branch-ci-inspection.js +222 -29
  31. package/build/conductor/epic-implementer-cli.js +213 -13
  32. package/build/conductor/epic-server-database.js +162 -0
  33. package/build/conductor/epic-server-guidance.js +278 -0
  34. package/build/conductor/epic-server-journal.js +239 -0
  35. package/build/conductor/epic-server-processes.js +324 -0
  36. package/build/conductor/epic-server-recipe.js +397 -0
  37. package/build/conductor/epic-server-runtime.js +1207 -0
  38. package/build/conductor/epic-server-sfcc.js +107 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +594 -0
  41. package/build/conductor/gate-discovery.js +281 -10
  42. package/build/conductor/gate-settings-review.js +525 -5
  43. package/build/conductor/git-hooks-uninstall.js +112 -0
  44. package/build/conductor/git-hooks.js +81 -15
  45. package/build/conductor/guided-repair.js +10 -1
  46. package/build/conductor/install-doctor.js +2 -4
  47. package/build/conductor/launch-need-probes.js +6 -53
  48. package/build/conductor/launch-plan.js +318 -121
  49. package/build/conductor/local-merge.js +12 -1
  50. package/build/conductor/merge-execution-contract.js +1 -1
  51. package/build/conductor/merged-child-check.js +2 -1
  52. package/build/conductor/prerequisite-inputs.js +1213 -0
  53. package/build/conductor/readiness-assessment.js +93 -0
  54. package/build/conductor/readiness-cli.js +30 -9
  55. package/build/conductor/readiness-prerequisites.js +77 -5
  56. package/build/conductor/readiness-sections.js +146 -126
  57. package/build/conductor/readiness.js +21 -3
  58. package/build/conductor/recovery-cli.js +236 -15
  59. package/build/conductor/recovery-operations.js +34 -4
  60. package/build/conductor/repair-contract.js +33 -0
  61. package/build/conductor/tools.js +36 -4
  62. package/build/conductor/wait-run-attention.js +115 -0
  63. package/build/conductor/wait-run-cli.js +300 -21
  64. package/build/conductor/worker-database-doctor-inspector.js +34 -2
  65. package/build/conductor/worker-setup-tally.js +27 -0
  66. package/build/credential-store.js +96 -21
  67. package/build/dependency-install-declarations.js +212 -0
  68. package/build/docs.generated.js +4 -4
  69. package/build/doctor.js +91 -8
  70. package/build/drive-epic-help.js +23 -4
  71. package/build/drive-epic.js +1841 -340
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +140 -0
  74. package/build/epic-capability-statement.js +107 -0
  75. package/build/epic-ci-workflow-drift.js +30 -15
  76. package/build/epic-ci-workflow-install.js +110 -42
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow.js +38 -12
  79. package/build/epic-implementer-bin.js +2184 -52
  80. package/build/epic-launch-context.js +607 -0
  81. package/build/epic-launch-profile.js +1 -1
  82. package/build/epic-server-record.js +273 -0
  83. package/build/epic-shared/bridge-client.js +11 -3
  84. package/build/escalation-reachability.js +43 -0
  85. package/build/executor/ci-fix-test-runs.js +334 -0
  86. package/build/executor/cli.js +2 -0
  87. package/build/executor/completion-contract.js +24 -1
  88. package/build/executor/credentials.js +1 -1
  89. package/build/executor/delivery-observations.js +113 -0
  90. package/build/executor/delivery-outcome.js +30 -0
  91. package/build/executor/dependency-refresh-runner.js +132 -0
  92. package/build/executor/dependency-refresh.js +530 -0
  93. package/build/executor/deps.js +4 -0
  94. package/build/executor/env.js +119 -17
  95. package/build/executor/epic-server-context.js +141 -0
  96. package/build/executor/gate-qualification-job.js +127 -26
  97. package/build/executor/harness-coverage.js +19 -0
  98. package/build/executor/http-client.js +87 -6
  99. package/build/executor/index.js +2 -1
  100. package/build/executor/install-preflight.js +1 -1
  101. package/build/executor/job-runner.js +659 -87
  102. package/build/executor/likely-tests.js +94 -97
  103. package/build/executor/observation.js +8 -0
  104. package/build/executor/pre-pr-checks.js +363 -0
  105. package/build/executor/prompt-spec.js +127 -5
  106. package/build/executor/reconcile-overlap-job.js +5 -3
  107. package/build/executor/required-verification.js +28 -0
  108. package/build/executor/required-work-diagnostics.js +32 -0
  109. package/build/executor/required-work-ledger.js +955 -39
  110. package/build/executor/results.js +100 -0
  111. package/build/executor/service-discovery.js +42 -0
  112. package/build/executor/service-lifecycle.js +109 -2
  113. package/build/executor/service-uninstall.js +205 -0
  114. package/build/executor/service-unit.js +5 -3
  115. package/build/executor/terminal-mutation.js +8 -0
  116. package/build/executor/test-clock.js +3 -0
  117. package/build/executor/verification-hints.js +179 -0
  118. package/build/executor/worker-command.js +126 -5
  119. package/build/executor/worker-database-config.js +281 -0
  120. package/build/executor/worker-database-target.js +16 -12
  121. package/build/executor/worker-database.js +575 -116
  122. package/build/executor/worker-finalization.js +71 -10
  123. package/build/executor/worker-guard-hook.js +10 -2
  124. package/build/executor/worker-resources.js +25 -3
  125. package/build/executor/worker-verification-guidance.js +55 -5
  126. package/build/executor/worktree-inspection.js +42 -0
  127. package/build/executor/worktree.js +20 -1
  128. package/build/executor-launch.js +54 -2
  129. package/build/generated-assets-catalog.js +2 -2
  130. package/build/github-sign-in.js +1 -1
  131. package/build/index.js +1111 -381
  132. package/build/init.js +29 -14
  133. package/build/install-bridge-conductor-answers.js +465 -0
  134. package/build/install-bridge-conductor-apply.js +259 -0
  135. package/build/install-bridge-conductor-assessment.js +895 -0
  136. package/build/install-bridge-conductor-compact.js +161 -0
  137. package/build/install-bridge-conductor-contracts.js +63 -0
  138. package/build/install-bridge-conductor-gate.js +1383 -188
  139. package/build/install-bridge-conductor-setup.js +637 -92
  140. package/build/install-bridge-conductor.js +3163 -740
  141. package/build/install-bridge.js +601 -128
  142. package/build/install-maintenance.js +127 -0
  143. package/build/install-reexec.js +1 -1
  144. package/build/launcher-config-inspection.js +162 -1
  145. package/build/local-cleanup.js +59 -0
  146. package/build/mcp-grant-candidates.js +767 -0
  147. package/build/mcp-grant-doctor.js +63 -0
  148. package/build/mcp-grant.js +288 -0
  149. package/build/mcp-host-targets.js +8 -0
  150. package/build/mcp-identity.js +23 -0
  151. package/build/mcp-install-state.js +68 -2
  152. package/build/mcp-invoke.js +126 -13
  153. package/build/mcp-presets.js +107 -0
  154. package/build/mcp-provisioning.js +134 -2
  155. package/build/mcp-registration-doctor.js +31 -2
  156. package/build/mcp-server-invocation.js +6 -1
  157. package/build/merge-workflow-install.js +236 -111
  158. package/build/package-script-semantics.js +10 -0
  159. package/build/pipeline-utils.js +1 -1
  160. package/build/pipelines.generated.js +6 -6
  161. package/build/plan-discovery.js +97 -4
  162. package/build/plan-execution-ledger.js +248 -9
  163. package/build/plan-generation-io.js +262 -0
  164. package/build/plan-generation.js +424 -0
  165. package/build/plane/build-freshness.js +6 -1
  166. package/build/plane/cli.js +75 -9
  167. package/build/plane/plane-freshness.js +23 -7
  168. package/build/plane/preflight.js +50 -10
  169. package/build/plane/shutdown.js +19 -0
  170. package/build/plane/terminal-run-cleanup.js +23 -5
  171. package/build/plane/terminal-run-status.js +4 -0
  172. package/build/printed-remedy-commands.js +229 -15
  173. package/build/readiness-check.js +1 -1
  174. package/build/readiness-prerequisites.generated.js +311 -4
  175. package/build/readme.generated.js +1 -1
  176. package/build/repository-state-paths.js +38 -0
  177. package/build/repository-toolchains.js +50 -8
  178. package/build/run-unit-tests-launcher.js +8 -1
  179. package/build/setup-change-policy.js +32 -0
  180. package/build/setup-epic.js +1192 -198
  181. package/build/setup-progress.js +44 -0
  182. package/build/setup-question.js +180 -0
  183. package/build/start-tickets.js +4 -0
  184. package/build/test-command-detection.js +32 -88
  185. package/build/test-support/notes-fs.js +40 -0
  186. package/build/third-party-mcp-targets.js +30 -0
  187. package/build/ticket-delivery-enrollment.js +30 -8
  188. package/build/ticket-delivery-run-scope.js +128 -0
  189. package/build/upgrade-cli.js +85 -2
  190. package/build/v2-readiness-requirements.js +28 -1
  191. package/build/version.generated.js +3 -3
  192. package/build/worker-guard-hook-bin.js +2 -2
  193. package/build/worktrees.js +105 -0
  194. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  195. package/docs/EPIC-IMPLEMENTER.md +5 -0
  196. package/docs/epic-implementer/getting-started.md +42 -15
  197. package/docs/epic-implementer/self-hosting.md +14 -1
  198. package/package.json +2 -2
@@ -6,7 +6,7 @@
6
6
  * identity, and opens a pull request with the customer's own `gh`. It never
7
7
  * merges that pull request, and Bridge never writes to the repository at all.
8
8
  * Two sets exist today: the Epic Implementer merge workflow with its two review
9
- * artifacts (`install-bridge conductor --merge-workflow`, below), and the
9
+ * artifacts (`install epic-implementer --merge-workflow`, below), and the
10
10
  * Epic Implementer CI workflow (`epic-ci-workflow-install.ts`).
11
11
  *
12
12
  * ## Domain logic lives here, not in the CLI
@@ -18,19 +18,23 @@
18
18
  *
19
19
  * ## Read-only until it is not
20
20
  *
21
- * The ENTIRE preflight — local checks, the remote default-branch head, every
21
+ * The ENTIRE preflight — executable checks, the remote default-branch head, every
22
22
  * managed file's content on that head, the open managed pull request, and the
23
23
  * managed remote branch — completes before the first fetch, file write, commit,
24
24
  * push, or pull request. Nothing here can partially install.
25
25
  *
26
- * ## The person's checkout is never touched
26
+ * ## The person's checkout is never touched, and never in the way
27
27
  *
28
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.
29
+ * created from the verified remote default-branch head, outside the person's
30
+ * checkout, and removed on every exit path. The person's HEAD, index, and
31
+ * working files are unchanged at the end: no checkout, switch, reset, or stash
32
+ * ever runs against them. Content is classified from the default branch, not
33
+ * from whatever the person has checked out, so uncommitted or unpushed local
34
+ * changes can neither block the install nor leak into it. A caller that needs
35
+ * facts about that same head (the toolchains the CI workflow installs) captures
36
+ * the default-branch snapshot first ({@link captureDefaultBranchSnapshot}) and
37
+ * passes it back, so the proposal and the worktree share one SHA.
34
38
  *
35
39
  * ## Content states, and why `identical` is not the only no-op
36
40
  *
@@ -46,8 +50,10 @@
46
50
  * A re-run that finds an open managed pull request whose contents match the
47
51
  * proposal reports it and writes nothing. One whose contents differ is reported
48
52
  * 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.
53
+ * (left by an earlier `pr_open_failed`) whose managed files match the proposal
54
+ * needs only its pull request: the branch is not pushed again. One whose files
55
+ * differ is reported with a fixed next step; it is never overwritten or deleted
56
+ * automatically.
51
57
  *
52
58
  * ## Secret discipline
53
59
  *
@@ -65,7 +71,6 @@ import { MERGE_WORKFLOW_API_KEY_SECRET_NAME, } from "./merge-workflow-config.js"
65
71
  import { MERGE_WORKFLOW_CLASSIFICATION_TEXT, classifyMergeWorkflowContent, } from "./merge-workflow-drift.js";
66
72
  import { MERGE_WORKFLOW_CODEOWNERS_RELPATH, MERGE_WORKFLOW_GUIDANCE_RELPATH, MERGE_WORKFLOW_MANAGED_RELPATHS, MergeWorkflowCodeOwnerError, renderMergeWorkflowCodeownersFragment, renderMergeWorkflowGuidance, validateMergeWorkflowCodeOwner, } from "./merge-workflow-codeowners.js";
67
73
  import { renderEpicImplementerMergeWorkflow } from "./merge-workflow.js";
68
- import { MCP_INSTALL_STATE_RELPATH } from "./mcp-install-state.js";
69
74
  // ---------------------------------------------------------------------------
70
75
  // Managed identity (merge-workflow set)
71
76
  // ---------------------------------------------------------------------------
@@ -99,8 +104,6 @@ export const MERGE_WORKFLOW_INSTALL_FAILURE_REASONS = [
99
104
  "gh_unavailable",
100
105
  /** The requested directory is not the root of the active git worktree. */
101
106
  "not_repository_root",
102
- /** The worktree or index carries uncommitted changes. */
103
- "worktree_not_clean",
104
107
  /** The repository default branch could not be resolved, or the two sources disagreed. */
105
108
  "default_branch_unresolved",
106
109
  /** The push remote is missing, or is not a canonical github.com repository. */
@@ -192,7 +195,6 @@ const REMEDIATION = {
192
195
  git_unavailable: "Install git and re-run; this command creates the branch with your own git.",
193
196
  gh_unavailable: "Install the GitHub CLI (`gh`) and authenticate it; this command opens the pull request as you.",
194
197
  not_repository_root: "Run this command from the root of the repository that should receive the workflow.",
195
- worktree_not_clean: "Commit or set aside your local changes first; this command refuses to stage anything it did not generate.",
196
198
  default_branch_unresolved: "Check that the repository has a default branch and that `gh` can read it, then re-run.",
197
199
  remote_not_github: "Point the push remote at a github.com repository; this feature is GitHub.com-only.",
198
200
  repository_identity_mismatch: "Make the local remote and the `gh` default repository agree, then re-run.",
@@ -210,7 +212,7 @@ const REMEDIATION = {
210
212
  default_branch_moved: "The default branch changed while this command ran; re-run it to review the new proposal.",
211
213
  managed_state_changed: "Another managed branch or pull request appeared while this command ran; review it, then re-run.",
212
214
  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.",
215
+ test_command_invalid: "Give a valid one-line test command with --test-command, then re-run setup; Bridge proves it before it is used.",
214
216
  toolchains_invalid: "Re-run setup so the repository's dependency files are inspected again; nothing was written.",
215
217
  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.",
216
218
  };
@@ -249,11 +251,6 @@ async function captureRawStdout(run, args) {
249
251
  return null;
250
252
  }
251
253
  }
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
254
  /** Split `gh api --include` output into its status code and RAW body. */
258
255
  function parseIncludedResponse(stdout) {
259
256
  const status = /^HTTP\/[0-9.]+ (\d{3})\b/.exec(stdout);
@@ -402,6 +399,41 @@ async function prContentMatchesProposal(deps, repository, pr, proposals) {
402
399
  }
403
400
  return true;
404
401
  }
402
+ /** GitHub's compare endpoint lists at most this many files; a full page may be truncated. */
403
+ const COMPARE_FILE_LIMIT = 300;
404
+ /**
405
+ * The files a pushed branch changes against the default-branch head the install
406
+ * was classified at, through `gh api` compare. `null` when the answer is not a
407
+ * clean, complete list: an uncertain read never authorizes opening a pull request.
408
+ */
409
+ async function readBranchChangedFiles(deps, repository, baseSha, headSha) {
410
+ let result;
411
+ try {
412
+ result = await deps.runGh([
413
+ "api",
414
+ `repos/${repository}/compare/${baseSha}...${headSha}`,
415
+ "--jq",
416
+ "[.files[].filename]",
417
+ ]);
418
+ }
419
+ catch {
420
+ return null;
421
+ }
422
+ if (result.status !== 0)
423
+ return null;
424
+ let parsed;
425
+ try {
426
+ parsed = JSON.parse((result.stdout ?? "").trim());
427
+ }
428
+ catch {
429
+ return null;
430
+ }
431
+ if (!Array.isArray(parsed) || !parsed.every((f) => typeof f === "string"))
432
+ return null;
433
+ if (parsed.length >= COMPARE_FILE_LIMIT)
434
+ return null;
435
+ return parsed;
436
+ }
405
437
  function compareUrl(repository, defaultBranch, branch) {
406
438
  return `https://github.com/${repository}/compare/${encodeURI(defaultBranch)}...${encodeURI(branch)}`;
407
439
  }
@@ -457,21 +489,7 @@ async function classifyAtRemote(deps, descriptor, repository, sha, quiet) {
457
489
  proposals,
458
490
  };
459
491
  }
460
- /**
461
- * Run the complete read-only preflight for an artifact set.
462
- *
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.
468
- */
469
- export async function runArtifactSetPreflight(descriptor, deps) {
470
- // Managed paths are constants; this guards a future edit, not today's input.
471
- for (const artifact of descriptor.artifacts) {
472
- if (!isSafeManagedRelPath(artifact.relPath))
473
- return { ok: false, result: fail("write_failed") };
474
- }
492
+ async function readLocalIdentity(deps) {
475
493
  if (!(await commandSucceeds(deps.runGit, ["--version"]))) {
476
494
  return { ok: false, result: fail("git_unavailable") };
477
495
  }
@@ -487,24 +505,6 @@ export async function runArtifactSetPreflight(descriptor, deps) {
487
505
  return { ok: false, result: fail("not_repository_root") };
488
506
  }
489
507
  deps.log(` repository root: ${normalizedRoot}`);
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.
492
- //
493
- // `--untracked-files=all` rather than the default: git otherwise COLLAPSES an
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"]);
498
- if (status === null)
499
- return { ok: false, result: fail("git_failed") };
500
- const dirty = status
501
- .split("\n")
502
- .map((line) => line.replace(/\r$/, ""))
503
- .filter((line) => line.trim().length > 0)
504
- .filter((line) => !isInstallStateLine(line));
505
- if (dirty.length > 0)
506
- return { ok: false, result: fail("worktree_not_clean") };
507
- deps.log(" worktree: clean");
508
508
  const ghDefaultBranch = await captureStdout(deps.runGh, [
509
509
  "repo",
510
510
  "view",
@@ -538,6 +538,85 @@ export async function runArtifactSetPreflight(descriptor, deps) {
538
538
  return { ok: false, result: fail("repository_identity_mismatch") };
539
539
  }
540
540
  deps.log(` gh: authenticated for ${ghRepository}`);
541
+ return {
542
+ ok: true,
543
+ identity: {
544
+ repositoryRoot: normalizedRoot,
545
+ defaultBranch: ghDefaultBranch,
546
+ remoteName,
547
+ repository: ghRepository,
548
+ },
549
+ };
550
+ }
551
+ /** The default branch head from the remote (`ls-remote`, no fetch), or the refusal. */
552
+ async function readDefaultBranchHead(deps, identity) {
553
+ const sha = await readRemoteBranchSha(deps, identity.remoteName, identity.defaultBranch);
554
+ if (sha === undefined)
555
+ return { ok: false, result: fail("remote_state_unverifiable") };
556
+ if (sha === null)
557
+ return { ok: false, result: fail("default_branch_unresolved") };
558
+ return { ok: true, sha };
559
+ }
560
+ /**
561
+ * Capture the remote default branch as one immutable snapshot. Read-only, and the
562
+ * one owner of how that head is resolved: the preflight below reads it through
563
+ * the same functions rather than a second resolver.
564
+ */
565
+ export async function captureDefaultBranchSnapshot(deps) {
566
+ const local = await readLocalIdentity(deps);
567
+ if (!local.ok)
568
+ return local;
569
+ const head = await readDefaultBranchHead(deps, local.identity);
570
+ if (!head.ok)
571
+ return head;
572
+ return { ok: true, snapshot: { ...local.identity, defaultBranchSha: head.sha } };
573
+ }
574
+ /**
575
+ * Read one file's RAW bytes at the snapshot's immutable commit.
576
+ *
577
+ * Shaped for {@link resolveRepositoryToolchains}'s reader: a confirmed 404 throws
578
+ * an `ENOENT` error (the file is absent), and anything else that is not a clean
579
+ * 200 throws a different error (the file could not be read), so an unreadable
580
+ * file is never mistaken for an absent one.
581
+ */
582
+ export async function readSnapshotFile(deps, snapshot, relPath) {
583
+ if (!isSafeManagedRelPath(relPath))
584
+ throw new Error("snapshot_path_refused");
585
+ const file = await readRemoteFile(deps, snapshot.repository, snapshot.defaultBranchSha, relPath);
586
+ if (file.kind === "present")
587
+ return file.content;
588
+ if (file.kind === "absent")
589
+ throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
590
+ throw new Error("snapshot_read_failed");
591
+ }
592
+ /**
593
+ * Run the complete read-only preflight for an artifact set.
594
+ *
595
+ * Every check here is a read: executables, repository root, default branch,
596
+ * remote and `gh` identity, set-specific options, the remote default-branch head
597
+ * (via `ls-remote`, no fetch), and each managed file's raw bytes at that head
598
+ * (via `gh api`). Nothing it calls creates a branch, writes a file, touches
599
+ * install state, fetches, commits, pushes, or opens a pull request. The person's
600
+ * working tree is not consulted: uncommitted or unpushed changes there neither
601
+ * block this preflight nor reach what it classifies.
602
+ *
603
+ * With a `snapshot`, the head is the snapshot's rather than a fresh read, and the
604
+ * repository and default branch must still be the ones it observed.
605
+ */
606
+ export async function runArtifactSetPreflight(descriptor, deps, snapshot) {
607
+ // Managed paths are constants; this guards a future edit, not today's input.
608
+ for (const artifact of descriptor.artifacts) {
609
+ if (!isSafeManagedRelPath(artifact.relPath))
610
+ return { ok: false, result: fail("write_failed") };
611
+ }
612
+ const local = await readLocalIdentity(deps);
613
+ if (!local.ok)
614
+ return { ok: false, result: local.result };
615
+ const { identity } = local;
616
+ if (snapshot !== undefined &&
617
+ (snapshot.repository !== identity.repository || snapshot.defaultBranch !== identity.defaultBranch)) {
618
+ return { ok: false, result: fail("default_branch_moved") };
619
+ }
541
620
  if (descriptor.validateOptions) {
542
621
  const checked = descriptor.validateOptions();
543
622
  if (!checked.ok)
@@ -547,25 +626,30 @@ export async function runArtifactSetPreflight(descriptor, deps) {
547
626
  }
548
627
  // The default branch head, read from the remote. A managed branch is never
549
628
  // the default branch; that is enforced again at push time.
550
- if (descriptor.installBranch === ghDefaultBranch || descriptor.upgradeBranch === ghDefaultBranch) {
629
+ if (descriptor.installBranch === identity.defaultBranch || descriptor.upgradeBranch === identity.defaultBranch) {
551
630
  return { ok: false, result: fail("default_branch_unresolved") };
552
631
  }
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);
632
+ let defaultBranchSha;
633
+ if (snapshot !== undefined) {
634
+ defaultBranchSha = snapshot.defaultBranchSha;
635
+ }
636
+ else {
637
+ const head = await readDefaultBranchHead(deps, identity);
638
+ if (!head.ok)
639
+ return { ok: false, result: head.result };
640
+ defaultBranchSha = head.sha;
641
+ }
642
+ const classified = await classifyAtRemote(deps, descriptor, identity.repository, defaultBranchSha, false);
559
643
  if (!classified.ok)
560
644
  return { ok: false, result: classified.result };
561
645
  return {
562
646
  ok: true,
563
647
  preflight: {
564
- repositoryRoot: normalizedRoot,
565
- defaultBranch: ghDefaultBranch,
648
+ repositoryRoot: identity.repositoryRoot,
649
+ defaultBranch: identity.defaultBranch,
566
650
  defaultBranchSha,
567
- remoteName,
568
- repository: ghRepository,
651
+ remoteName: identity.remoteName,
652
+ repository: identity.repository,
569
653
  classification: classified.classification,
570
654
  proposals: classified.proposals,
571
655
  },
@@ -573,35 +657,80 @@ export async function runArtifactSetPreflight(descriptor, deps) {
573
657
  }
574
658
  /**
575
659
  * Inspect the managed pull request and branch for `branch`. Read-only.
576
- * Returns `null` when the way is clear, or the outcome to report.
577
660
  */
578
661
  async function inspectManagedState(deps, descriptor, preflight, branch, upgrade) {
579
662
  const managedPaths = descriptor.artifacts.map((a) => a.relPath);
663
+ const report = (result) => ({ state: "report", result });
580
664
  const lookup = await findExistingManagedPr(deps, preflight.repository, branch);
581
665
  if (lookup.kind === "lookup_failed")
582
- return fail("remote_state_unverifiable", { branch });
666
+ return report(fail("remote_state_unverifiable", { branch }));
583
667
  if (lookup.kind === "found") {
584
668
  if (!existingPrIsExpected(lookup.pr, branch, preflight.defaultBranch, managedPaths)) {
585
- return fail("existing_pr_unverifiable", { branch });
669
+ return report(fail("existing_pr_unverifiable", { branch }));
586
670
  }
587
671
  const matches = await prContentMatchesProposal(deps, preflight.repository, lookup.pr, preflight.proposals);
588
672
  if (matches === null)
589
- return fail("existing_pr_unverifiable", { branch, prUrl: lookup.pr.url });
673
+ return report(fail("existing_pr_unverifiable", { branch, prUrl: lookup.pr.url }));
590
674
  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: [] };
675
+ return report(fail("existing_pr_differs", { branch, prUrl: lookup.pr.url }));
676
+ return report({ outcome: "existing-pr", branch, prUrl: lookup.pr.url, upgrade, warnings: [] });
593
677
  }
594
678
  // Independently of PR discovery: a pushed managed branch with no open PR.
595
679
  const branchSha = await readRemoteBranchSha(deps, preflight.remoteName, branch);
596
680
  if (branchSha === undefined)
597
- return fail("remote_state_unverifiable", { branch });
681
+ return report(fail("remote_state_unverifiable", { branch }));
598
682
  if (branchSha !== null) {
599
- return fail("managed_branch_without_pr", {
683
+ // Matching content needs only its pull request; differing content is never
684
+ // reused, overwritten, or deleted.
685
+ const matches = await prContentMatchesProposal(deps, preflight.repository, { url: "", headRefName: branch, headRefOid: branchSha, baseRefName: "", isCrossRepository: null, files: [] }, preflight.proposals);
686
+ if (matches === null)
687
+ return report(fail("remote_state_unverifiable", { branch }));
688
+ if (matches) {
689
+ // The same rule the open-PR path enforces: ONLY managed files may differ from
690
+ // the default branch, or the consent shown would not describe the pull request.
691
+ const changed = await readBranchChangedFiles(deps, preflight.repository, preflight.defaultBranchSha, branchSha);
692
+ if (changed === null)
693
+ return report(fail("remote_state_unverifiable", { branch }));
694
+ const managed = new Set(managedPaths);
695
+ if (changed.length > 0 && changed.every((f) => managed.has(f)))
696
+ return { state: "branch_ready", sha: branchSha };
697
+ }
698
+ return report(fail("managed_branch_without_pr", {
699
+ branch,
700
+ compareUrl: compareUrl(preflight.repository, preflight.defaultBranch, branch),
701
+ }));
702
+ }
703
+ return { state: "clear" };
704
+ }
705
+ /** Open the setup pull request from `branch` into the default branch with the customer's own `gh`. */
706
+ async function openArtifactSetPullRequest(deps, descriptor, preflight, branch, upgrade, managedPaths) {
707
+ const prUrl = await captureStdout(deps.runGh, [
708
+ "pr",
709
+ "create",
710
+ "--repo",
711
+ preflight.repository,
712
+ "--base",
713
+ preflight.defaultBranch,
714
+ "--head",
715
+ branch,
716
+ "--title",
717
+ upgrade ? descriptor.upgradePrTitle : descriptor.installPrTitle,
718
+ "--body",
719
+ descriptor.renderPrBody(upgrade),
720
+ ]);
721
+ if (!prUrl) {
722
+ return fail("pr_open_failed", {
600
723
  branch,
601
724
  compareUrl: compareUrl(preflight.repository, preflight.defaultBranch, branch),
602
725
  });
603
726
  }
604
- return null;
727
+ return {
728
+ outcome: upgrade ? "upgrade-pr-opened" : "installed-pr-opened",
729
+ branch,
730
+ prUrl,
731
+ artifacts: managedPaths,
732
+ warnings: [],
733
+ };
605
734
  }
606
735
  // ---------------------------------------------------------------------------
607
736
  // Merge-workflow descriptor
@@ -685,7 +814,9 @@ export function buildMergeWorkflowArtifactSet(codeOwner) {
685
814
  }
686
815
  return { ok: true, progress: [` code owner: ${owner}`] };
687
816
  },
688
- consentPrompt: (plan) => `Create branch ${plan.branch}, write ${plan.artifacts.length} files, commit, push, and open a pull request? [y/N] `,
817
+ consentPrompt: (plan) => plan.branchReuse === true
818
+ ? `Open a pull request from the existing branch ${plan.branch}? [y/N] `
819
+ : `Create branch ${plan.branch}, write ${plan.artifacts.length} files, commit, push, and open a pull request? [y/N] `,
689
820
  artifacts: [
690
821
  {
691
822
  relPath: MERGE_WORKFLOW_PATH,
@@ -724,6 +855,10 @@ export async function runMergeWorkflowPreflight(deps, options) {
724
855
  /** How many times consent is asked before a still-moving default branch stops the run. */
725
856
  const MAX_CONSENT_ROUNDS = 3;
726
857
  function defaultConsentPrompt(plan) {
858
+ if (plan.branchReuse === true) {
859
+ return (`Open a pull request from the existing branch ${plan.branch} into ${plan.defaultBranch} ` +
860
+ `(${plan.artifacts.join(", ")}; nothing is pushed)? [y/N] `);
861
+ }
727
862
  return (`Create branch ${plan.branch} from ${plan.defaultBranch} in a temporary worktree, write ` +
728
863
  `${plan.artifacts.join(", ")}, commit "${plan.commitSubject}", push to ` +
729
864
  `${plan.remoteName}/${plan.branch}, and open a pull request into ${plan.defaultBranch}? [y/N] `);
@@ -775,7 +910,7 @@ async function pathIsSafeInWorktree(deps, worktree, relPath) {
775
910
  * branch to tidy up is a destructive act taken on incomplete information.
776
911
  */
777
912
  export async function installArtifactSet(descriptor, options, deps) {
778
- const pre = await runArtifactSetPreflight(descriptor, deps);
913
+ const pre = await runArtifactSetPreflight(descriptor, deps, options.snapshot);
779
914
  if (!pre.ok)
780
915
  return pre.result;
781
916
  let preflight = pre.preflight;
@@ -799,6 +934,7 @@ export async function installArtifactSet(descriptor, options, deps) {
799
934
  let upgrade = false;
800
935
  let branch = "";
801
936
  let commitSubject = "";
937
+ let reusableBranch = false;
802
938
  // Consent covers one plan at one default-branch head. When the default branch
803
939
  // moves after consent and the plan changes, the new plan is shown and consent
804
940
  // is asked again; a branch that keeps moving stops with default_branch_moved.
@@ -807,8 +943,9 @@ export async function installArtifactSet(descriptor, options, deps) {
807
943
  branch = upgrade ? descriptor.upgradeBranch : descriptor.installBranch;
808
944
  commitSubject = upgrade ? descriptor.upgradeCommitSubject : descriptor.installCommitSubject;
809
945
  const managed = await inspectManagedState(deps, descriptor, preflight, branch, upgrade);
810
- if (managed)
811
- return managed;
946
+ if (managed.state === "report")
947
+ return managed.result;
948
+ reusableBranch = managed.state === "branch_ready";
812
949
  const plan = {
813
950
  branch,
814
951
  upgrade,
@@ -816,16 +953,19 @@ export async function installArtifactSet(descriptor, options, deps) {
816
953
  commitSubject,
817
954
  remoteName: preflight.remoteName,
818
955
  defaultBranch: preflight.defaultBranch,
956
+ ...(reusableBranch ? { branchReuse: true } : {}),
819
957
  };
820
958
  deps.log("");
821
959
  if (round > 0)
822
960
  deps.log(`${preflight.defaultBranch} moved since you approved, and the plan changed.`);
823
961
  deps.log(upgrade ? "Planned upgrade:" : "Planned installation:");
824
- deps.log(` branch: ${branch}`);
962
+ deps.log(` branch: ${branch}${reusableBranch ? " (already pushed with these files; it is not pushed again)" : ""}`);
825
963
  for (const relPath of managedPaths)
826
964
  deps.log(` file: ${relPath}`);
827
- deps.log(` commit: ${commitSubject}`);
828
- deps.log(` push: ${preflight.remoteName}/${branch} (your git identity)`);
965
+ if (!reusableBranch) {
966
+ deps.log(` commit: ${commitSubject}`);
967
+ deps.log(` push: ${preflight.remoteName}/${branch} (your git identity)`);
968
+ }
829
969
  deps.log(` pull request: into ${preflight.defaultBranch} (your gh identity)`);
830
970
  if (options.dryRun) {
831
971
  deps.log("");
@@ -850,6 +990,10 @@ export async function installArtifactSet(descriptor, options, deps) {
850
990
  return fail("git_failed", { branch });
851
991
  if (fetchedSha === preflight.defaultBranchSha)
852
992
  break;
993
+ // The caller derived its inputs from one snapshot head: a different head is
994
+ // a different build, so the run stops and is re-run from a fresh snapshot.
995
+ if (options.snapshot !== undefined)
996
+ return fail("default_branch_moved", { branch });
853
997
  // The default branch moved: re-inspect at the fetched head. An unchanged
854
998
  // plan proceeds from the new head under the consent already given.
855
999
  const again = await classifyAtRemote(deps, descriptor, preflight.repository, fetchedSha, true);
@@ -867,6 +1011,10 @@ export async function installArtifactSet(descriptor, options, deps) {
867
1011
  if (round + 1 >= MAX_CONSENT_ROUNDS)
868
1012
  return fail("default_branch_moved", { branch });
869
1013
  }
1014
+ // A pushed managed branch whose files already match needs only its pull request.
1015
+ if (reusableBranch) {
1016
+ return await openArtifactSetPullRequest(deps, descriptor, preflight, branch, upgrade, managedPaths);
1017
+ }
870
1018
  const makeTempDir = deps.makeTempDir ?? (() => mkdtemp(join(tmpdir(), `bridge-${descriptor.setName}-`)));
871
1019
  const removeDir = deps.removeDir ?? ((dir) => rm(dir, { recursive: true, force: true }));
872
1020
  let tempRoot;
@@ -932,9 +1080,12 @@ export async function installArtifactSet(descriptor, options, deps) {
932
1080
  }
933
1081
  // Immediately before push: nobody else created the managed branch or PR.
934
1082
  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;
1083
+ if (raced.state !== "clear") {
1084
+ if (raced.state === "report" &&
1085
+ raced.result.outcome === "failed" &&
1086
+ raced.result.reason === "remote_state_unverifiable") {
1087
+ return raced.result;
1088
+ }
938
1089
  return fail("managed_state_changed", { branch });
939
1090
  }
940
1091
  if (branch === preflight.defaultBranch)
@@ -948,33 +1099,7 @@ export async function installArtifactSet(descriptor, options, deps) {
948
1099
  ]))) {
949
1100
  return fail("git_failed", { branch });
950
1101
  }
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
- };
1102
+ return await openArtifactSetPullRequest(deps, descriptor, preflight, branch, upgrade, managedPaths);
978
1103
  };
979
1104
  let result;
980
1105
  try {
@@ -1004,7 +1129,7 @@ export async function installArtifactSet(descriptor, options, deps) {
1004
1129
  /**
1005
1130
  * Generate the merge-workflow artifacts and open the customer's review PR.
1006
1131
  *
1007
- * Compatibility wrapper for `install-bridge conductor --merge-workflow` around
1132
+ * Compatibility wrapper for `install epic-implementer --merge-workflow` around
1008
1133
  * {@link installArtifactSet}. Returns a process exit code: `0` for every
1009
1134
  * success shape (new pull request, upgrade pull request, verified existing pull
1010
1135
  * request, byte-identical no-op, dry run) and `1` for every failure. A failure
@@ -0,0 +1,10 @@
1
+ /** Shared, conservative npm script evidence. Bodies are never executed. */
2
+ export const NPM_PLACEHOLDER_TEST_SCRIPT = 'echo "Error: no test specified" && exit 1';
3
+ export function isUsablePackageScript(value) {
4
+ return typeof value === "string" && value.trim() !== ""
5
+ && !/^echo\s+['"]?Error:\s*no test specified['"]?\s*&&\s*exit\s+1\s*;?$/i.test(value.trim());
6
+ }
7
+ export function isTestScript(name, body) {
8
+ return /^(test([:_-].+)?|unit|integration|e2e)$/.test(name)
9
+ && isUsablePackageScript(body) && !/(?:&&|\|\||[;|])/.test(body);
10
+ }
@@ -256,7 +256,7 @@ export function resolveRecipe(pipeline, instructions, variables, skipSteps, auto
256
256
  "If requires_approval is true, pause before executing. For agent_task steps, the instruction file's own approval format is authoritative — follow it verbatim and do not substitute your own short confirmation prompt. For mcp_call steps with no instruction file, present the resolved params as bullet points and ask for approval. " +
257
257
  'For on_error "halt", stop the pipeline immediately on failure. ' +
258
258
  'For on_error "warn_and_continue", log a warning and proceed. ' +
259
- "Recipes are re-entrant: a recovery run may begin again at step 1, and a step whose tool reports a server-side reuse (e.g. reused: true) has completed successfully — treat that as the expected fast path, not a failure, and continue. " +
259
+ "An interrupted initial workflow may re-enter only as permitted by its recipe and checkpoint rules. Separately dispatched remaining-work corrections follow their focused intent and must not restart a full implementation or planning recipe. A step whose tool reports server-side reuse (e.g. reused: true) has completed successfully — treat that as the expected fast path, not a failure, and continue. " +
260
260
  'A step can succeed (no on_error handling applies) while its own returned content is a JSON envelope shaped like error: "GATEWAY_TIMEOUT", status: 504, and a recovery_get field — recognize that shape and read it as "server-side processing may still be running", not as a failure or an invitation to retry. Poll the named retrieval tool (or the recovery_get URL) with the same artifact identifier until a terminal response is reached, and never reissue the original request tool. Only fall back to on_error handling if that retrieval itself terminally fails. ' +
261
261
  "Do not skip steps, reorder them, or substitute your own tool calls.";
262
262
  // Default-on: include the upgrade-advice surfacing convention unless the