@bridge_gpt/mcp-server 0.2.72 → 0.2.74

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 (181) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +15 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +30 -0
  6. package/build/ci-system-detection.js +50 -0
  7. package/build/ci-trigger-adapters.js +631 -0
  8. package/build/ci-trigger-install.js +106 -0
  9. package/build/codex-launcher-pin.js +33 -2
  10. package/build/codex-skill-adapter.js +3 -1
  11. package/build/command-host.js +33 -0
  12. package/build/command-provisioning.js +4 -3
  13. package/build/commands.generated.js +7 -6
  14. package/build/conductor/bridge-api-client.js +867 -35
  15. package/build/conductor/bring-up-facts.js +18 -5
  16. package/build/conductor/command-drift-production.js +42 -17
  17. package/build/conductor/command-drift.js +48 -1
  18. package/build/conductor/declare-blocked.js +554 -0
  19. package/build/conductor/declared-extras.js +335 -0
  20. package/build/conductor/doctor.js +108 -21
  21. package/build/conductor/driver-commands.js +141 -0
  22. package/build/conductor/driver-guard.js +277 -0
  23. package/build/conductor/driver-lapse.js +321 -0
  24. package/build/conductor/driver-pass-output.js +104 -0
  25. package/build/conductor/driver-pass.js +571 -0
  26. package/build/conductor/driver-register.js +176 -0
  27. package/build/conductor/driver-release.js +174 -0
  28. package/build/conductor/driver-session-state.js +315 -0
  29. package/build/conductor/epic-branch-ci-inspection.js +281 -43
  30. package/build/conductor/epic-implementer-cli.js +199 -15
  31. package/build/conductor/epic-server-database.js +162 -0
  32. package/build/conductor/epic-server-guidance.js +278 -0
  33. package/build/conductor/epic-server-journal.js +239 -0
  34. package/build/conductor/epic-server-processes.js +324 -0
  35. package/build/conductor/epic-server-recipe.js +397 -0
  36. package/build/conductor/epic-server-runtime.js +1207 -0
  37. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  38. package/build/conductor/epic-server-sfcc.js +85 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +647 -0
  41. package/build/conductor/gate-discovery.js +196 -11
  42. package/build/conductor/gate-settings-review.js +261 -4
  43. package/build/conductor/launch-need-probes.js +6 -53
  44. package/build/conductor/launch-plan.js +313 -156
  45. package/build/conductor/prerequisite-inputs.js +879 -45
  46. package/build/conductor/readiness-assessment.js +16 -1
  47. package/build/conductor/readiness-cli.js +20 -9
  48. package/build/conductor/readiness-prerequisites.js +28 -9
  49. package/build/conductor/readiness-sections.js +133 -126
  50. package/build/conductor/readiness.js +1 -1
  51. package/build/conductor/recovery-cli.js +13 -2
  52. package/build/conductor/tools.js +6 -5
  53. package/build/conductor/wait-run-attention.js +2 -2
  54. package/build/conductor/wait-run-cli.js +208 -22
  55. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  56. package/build/conductor/worker-setup-tally.js +27 -0
  57. package/build/credential-delivery.js +280 -0
  58. package/build/credential-launch-safety.js +142 -0
  59. package/build/credential-materialization.js +91 -16
  60. package/build/credential-references-node-deps.js +29 -0
  61. package/build/credential-references.js +1394 -0
  62. package/build/credential-references.test-fixtures.js +211 -0
  63. package/build/credential-scan-conventions.js +145 -0
  64. package/build/credential-scan.js +517 -0
  65. package/build/credential-store.js +121 -1
  66. package/build/credentials-cli.js +252 -3
  67. package/build/dependency-install-declarations.js +102 -1
  68. package/build/docs.generated.js +10 -3
  69. package/build/doctor.js +95 -3
  70. package/build/drive-epic-help.js +21 -2
  71. package/build/drive-epic.js +2095 -375
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +157 -0
  74. package/build/epic-capability-statement.js +175 -0
  75. package/build/epic-ci-workflow-drift.js +77 -23
  76. package/build/epic-ci-workflow-install.js +137 -44
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow-v3.js +273 -0
  79. package/build/epic-ci-workflow.js +165 -18
  80. package/build/epic-implementer-bin.js +2204 -56
  81. package/build/epic-launch-context.js +702 -0
  82. package/build/epic-server-record.js +288 -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/completion-contract.js +8 -1
  87. package/build/executor/credential-delivery-step.js +168 -0
  88. package/build/executor/deps.js +3 -1
  89. package/build/executor/env.js +98 -23
  90. package/build/executor/epic-server-context.js +157 -0
  91. package/build/executor/gate-qualification-job.js +127 -26
  92. package/build/executor/guarded-fast-forward-push.js +13 -8
  93. package/build/executor/http-client.js +52 -5
  94. package/build/executor/job-runner.js +577 -81
  95. package/build/executor/observation.js +8 -0
  96. package/build/executor/permissions.js +85 -3
  97. package/build/executor/pre-pr-checks.js +363 -0
  98. package/build/executor/prompt-spec.js +149 -3
  99. package/build/executor/reconcile-overlap-job.js +5 -3
  100. package/build/executor/required-work-diagnostics.js +4 -2
  101. package/build/executor/required-work-ledger.js +936 -38
  102. package/build/executor/results.js +58 -0
  103. package/build/executor/terminal-mutation.js +8 -0
  104. package/build/executor/worker-command.js +72 -3
  105. package/build/executor/worker-database-config.js +281 -0
  106. package/build/executor/worker-database-target.js +16 -12
  107. package/build/executor/worker-database.js +320 -101
  108. package/build/executor/worker-finalization.js +7 -1
  109. package/build/executor/worker-resources.js +25 -3
  110. package/build/executor/worker-verification-guidance.js +18 -3
  111. package/build/executor/worktree.js +20 -1
  112. package/build/executor-launch.js +58 -4
  113. package/build/generated-assets-catalog.js +2 -2
  114. package/build/git-exclude-lock.js +187 -0
  115. package/build/index.js +824 -366
  116. package/build/init.js +26 -11
  117. package/build/install-bridge-conductor-answers.js +528 -0
  118. package/build/install-bridge-conductor-apply.js +288 -0
  119. package/build/install-bridge-conductor-assessment.js +1222 -0
  120. package/build/install-bridge-conductor-compact.js +186 -0
  121. package/build/install-bridge-conductor-contracts.js +72 -0
  122. package/build/install-bridge-conductor-gate.js +1312 -198
  123. package/build/install-bridge-conductor-setup.js +577 -83
  124. package/build/install-bridge-conductor.js +3381 -544
  125. package/build/install-bridge.js +280 -25
  126. package/build/install-doctor.js +38 -8
  127. package/build/install-maintenance.js +26 -3
  128. package/build/install-sfcc-detection.js +120 -0
  129. package/build/install-sfcc-setup.js +185 -0
  130. package/build/launcher-config-inspection.js +162 -1
  131. package/build/mcp-grant-candidates.js +779 -0
  132. package/build/mcp-grant-doctor.js +63 -0
  133. package/build/mcp-grant.js +288 -0
  134. package/build/mcp-host-targets.js +8 -0
  135. package/build/mcp-identity.js +23 -0
  136. package/build/mcp-invoke.js +292 -15
  137. package/build/mcp-presets.js +107 -0
  138. package/build/mcp-provisioning.js +155 -6
  139. package/build/mcp-registration-doctor.js +31 -2
  140. package/build/mcp-server-invocation.js +19 -1
  141. package/build/merge-workflow-install.js +243 -110
  142. package/build/pipelines.generated.js +7 -6
  143. package/build/plan-discovery.js +97 -4
  144. package/build/plan-execution-ledger.js +100 -7
  145. package/build/plan-generation-io.js +262 -0
  146. package/build/plan-generation.js +424 -0
  147. package/build/plane/build-freshness.js +6 -1
  148. package/build/plane/cli.js +75 -9
  149. package/build/plane/plane-freshness.js +17 -0
  150. package/build/plane/preflight.js +50 -10
  151. package/build/plane/shutdown.js +19 -0
  152. package/build/plane/status.js +8 -2
  153. package/build/plane/terminal-run-cleanup.js +18 -4
  154. package/build/printed-remedy-commands.js +211 -12
  155. package/build/project-root.js +40 -0
  156. package/build/readiness-check.js +77 -0
  157. package/build/readiness-prerequisites.generated.js +122 -14
  158. package/build/readme.generated.js +1 -1
  159. package/build/repository-state-paths.js +41 -0
  160. package/build/repository-toolchains.js +6 -3
  161. package/build/run-unit-tests-launcher.js +8 -1
  162. package/build/setup-epic.js +1305 -210
  163. package/build/setup-progress.js +44 -0
  164. package/build/setup-question.js +122 -4
  165. package/build/sfcc/credentials.js +3 -2
  166. package/build/sfcc/hostname.js +98 -2
  167. package/build/sfcc/tool-wrapper.js +6 -95
  168. package/build/start-tickets.js +193 -29
  169. package/build/test-support/executor-source-files.js +200 -0
  170. package/build/testing-config-client.js +25 -2
  171. package/build/third-party-mcp-targets.js +63 -2
  172. package/build/ticket-delivery-enrollment.js +9 -0
  173. package/build/upgrade-cli.js +85 -2
  174. package/build/v2-readiness-requirements.js +28 -1
  175. package/build/version.generated.js +3 -3
  176. package/build/with-credentials.js +208 -0
  177. package/build/worktree-credential-delivery.js +340 -0
  178. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  179. package/docs/epic-implementer/getting-started.md +3 -1
  180. package/docs/epic-implementer/self-hosting.md +14 -1
  181. package/package.json +2 -2
@@ -6,26 +6,27 @@
6
6
  * {@link installArtifactSet} engine: read-only preflight, consent, a temporary
7
7
  * worktree, a managed branch, and one pull request into the default branch.
8
8
  *
9
- * ## The setup caller's sequence (BAPI-1461, BAPI-1536)
9
+ * ## The setup caller's sequence (BAPI-1603)
10
10
  *
11
- * 1. Detect or select a command (`detectTestCommand`), asking at most once. An
12
- * explicit `--test-command` value is its own write consent and skips this
13
- * question; it is still validated, saved, and read back.
14
- * 2. Get consent to save the command (interactive selection only), then save it
15
- * with `PUT /setup/testing-config` (`writeStoredTestCommand`).
16
- * 3. Read the authoritative command back with `GET /setup/testing-config`
17
- * (`readStoredTestCommand`) and build the descriptor from THAT value, plus the
18
- * toolchain set resolved from the local working tree
19
- * (`resolveRepositoryToolchains`), with {@link buildEpicCiWorkflowArtifactSet}
20
- * — never from the typed answer.
21
- * 4. Get separate consent for the pull request and call {@link installEpicCiWorkflow}.
22
- * Saving a command and opening the workflow pull request are two consents:
23
- * the flag or the prompt covers the command, never the pull request.
11
+ * The workflow is an OPTION on a proven local plan, never a barrier.
24
12
  *
25
- * A failed command read or write stops before any installation. Saving the
26
- * command and installing the workflow are reported separately
27
- * ({@link describeEpicCiSetupStatus}): a refused or failed install never undoes
28
- * a stored command.
13
+ * 1. Setup asks the server for the repository's learned test command, proves it
14
+ * by running it once (gate qualification), and the server stores it as the
15
+ * gate's local member. Nobody is asked for a command. An explicit
16
+ * `--test-command` goes through the same trial as the owner's command.
17
+ * 2. When the repository has no reporting CI and a proven command, setup offers
18
+ * this workflow as one default-No yes/no.
19
+ * 3. On yes, the toolchains are resolved from the remote default branch at the
20
+ * installer's captured snapshot (`captureDefaultBranchSnapshot`), and the
21
+ * descriptor is built from the server-validated command plus that set with
22
+ * {@link buildEpicCiWorkflowArtifactSet}. The same snapshot is passed to
23
+ * {@link installEpicCiWorkflow}, so the rendered proposal and the detached
24
+ * worktree share one head. Uncommitted or unpushed local files never reach it.
25
+ * 4. Only after the installer opens or reuses the setup pull request does setup
26
+ * add `epic-implementer-ci / gate` to the gate.
27
+ *
28
+ * Installing the workflow never undoes a stored command, and a refused or failed
29
+ * install leaves the proven local plan in place ({@link describeEpicCiSetupStatus}).
29
30
  *
30
31
  * The backend integration point for readiness (BAPI-1459) is
31
32
  * `get_test_command(repo_name)` in `api/library/db/postgres_functions.py`. A
@@ -35,6 +36,7 @@ import { EPIC_CI_GATE_JOB_TIMEOUT_MINUTES, EPIC_CI_TEST_JOB_TIMEOUT_MINUTES, EPI
35
36
  import { EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT, classifyEpicCiWorkflowContent, } from "./epic-ci-workflow-drift.js";
36
37
  import { describeToolchainSet, RepositoryToolchainError, validateRepositoryToolchains, } from "./repository-toolchains.js";
37
38
  import { installArtifactSet, } from "./merge-workflow-install.js";
39
+ import { parseDependencyInstallStrict } from "./dependency-install-declarations.js";
38
40
  import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
39
41
  /** Managed branch for a fresh installation. */
40
42
  export const EPIC_CI_WORKFLOW_INSTALL_BRANCH = "bridge/epic-implementer-ci-v" + String(EPIC_CI_WORKFLOW_RENDERER_VERSION);
@@ -51,9 +53,15 @@ export const EPIC_CI_WORKFLOW_UPGRADE_BRANCH = "bridge/epic-implementer-ci-upgra
51
53
  * force-pushes it). Never edit or remove an entry: it names a branch customers
52
54
  * may already have.
53
55
  */
54
- export const EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES = ["bridge/epic-implementer-ci-v1"];
56
+ export const EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES = [
57
+ "bridge/epic-implementer-ci-v1",
58
+ "bridge/epic-implementer-ci-v2",
59
+ "bridge/epic-implementer-ci-v3",
60
+ ];
55
61
  export const EPIC_CI_WORKFLOW_HISTORICAL_UPGRADE_BRANCHES = [
56
62
  "bridge/epic-implementer-ci-upgrade-v1",
63
+ "bridge/epic-implementer-ci-upgrade-v2",
64
+ "bridge/epic-implementer-ci-upgrade-v3",
57
65
  ];
58
66
  export const EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES = [
59
67
  ...EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES,
@@ -68,39 +76,91 @@ export const EPIC_CI_WORKFLOW_ALL_MANAGED_BRANCHES = [
68
76
  export const EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT = "Add the Bridge Epic Implementer CI workflow";
69
77
  export const EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT = "Update the Bridge Epic Implementer CI workflow";
70
78
  /**
71
- * Render the CI pull request body. Deterministic and secret-free. It describes
72
- * the command contract and the dependency setup, but never accepts or embeds the
73
- * command; the diff shows it.
79
+ * The stop-and-exit table the setup change carries (BAPI-1603): what setup stops
80
+ * on, what it no longer stops on, and what it leaves alone. Fixed text.
81
+ */
82
+ export const EPIC_CI_SETUP_STOP_AND_EXIT_TABLE = [
83
+ "| Stop or exit | Before | After |",
84
+ "|---|---|---|",
85
+ "| Repository not learned | Not checked | **Added:** setup stops before any write (owner-approved exception) |",
86
+ "| Test-command question and blocking item, every repository | Asked and blocking | Removed. The command is learned and proven, or there is none |",
87
+ "| Setup PR, repository with reporting CI | Always opened | Not opened |",
88
+ "| Setup PR, repository with no CI | Always opened | Opened only if the person says yes to Bridge's workflow |",
89
+ "| Found CI checks as gate members | Required (would block until green, could stall) | Watched: red blocks, missing warns |",
90
+ "| Unqualified local gate at admission (`local_command_unqualified`) | Possible | Never stored: removed before setup ends |",
91
+ "| `worktree_not_clean` refusal of the setup PR | Blocks setup when the folder is dirty | Removed |",
92
+ "| Quiet `precondition` workflow state | Hides a local precondition | Removed; `not_repository_root` prints its remedy as the blocker |",
93
+ "| Push target, default-branch push refusal, credential checks | Unchanged | Unchanged |",
94
+ ];
95
+ /** A fenced block whose fence is longer than any backtick run inside `text`. */
96
+ function markdownFence(text) {
97
+ const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
98
+ const fence = "`".repeat(Math.max(3, longest + 1));
99
+ return [fence, text, fence];
100
+ }
101
+ /**
102
+ * Render the CI pull request body. Deterministic and secret-free: the same inputs
103
+ * always give the same text. It names the server-validated command and how to
104
+ * change it, and carries the stop-and-exit table. It accepts nothing but the
105
+ * validated command and the resolved toolchains, so a raw server response,
106
+ * executor output, or a qualification log has no way in.
74
107
  */
75
- export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
108
+ export function renderEpicCiWorkflowPrBody(upgrade, toolchains, testCommand, dependencyInstall = []) {
109
+ const command = validateTestCommand(testCommand);
76
110
  const setup = describeToolchainSet(toolchains);
77
111
  return [
78
112
  upgrade
79
113
  ? "This pull request updates the Bridge Epic Implementer CI workflow to renderer version " +
80
- String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ", the repository's current stored test command, and its dependency setup."
114
+ String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ", the repository's current test command, and its dependency setup."
81
115
  : "This pull request adds the Bridge Epic Implementer CI workflow, renderer version " +
82
116
  String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ".",
83
117
  "",
84
- "The workflow publishes one required check, `" + EPIC_IMPLEMENTER_CI_CHECK_NAME + "`. The Bridge",
85
- "Epic Implementer reads it before it merges a child pull request.",
118
+ "The workflow publishes one check, `" + EPIC_IMPLEMENTER_CI_CHECK_NAME + "`. The Bridge",
119
+ "Epic Implementer reads it before it merges a child pull request into an epic branch.",
120
+ "",
121
+ "## The test command",
122
+ "",
123
+ "Bridge learned this command from your repository and proved it by running it once on",
124
+ "your executor before it was stored:",
125
+ "",
126
+ ...markdownFence(command),
127
+ "",
128
+ "To change it, run Bridge setup again with `--test-command \"<your command>\"`. Bridge proves",
129
+ "the new command the same way before it replaces this one. Do not edit the workflow file by hand.",
86
130
  "",
87
131
  "## How it runs",
88
132
  "",
89
- "- On every pull request, it installs dependencies (below), then runs the repository's stored",
90
- " test command with bash from the repository root, on `ubuntu-latest`, with a",
91
- " " + String(EPIC_CI_TEST_JOB_TIMEOUT_MINUTES) + "-minute limit.",
133
+ "- Only on pull requests that target an `epic/**` branch: the child pull requests the Epic",
134
+ " Implementer merges. It installs dependencies (below), then runs the test command with bash",
135
+ " from the repository root, on `ubuntu-latest`, with a " + String(EPIC_CI_TEST_JOB_TIMEOUT_MINUTES) + "-minute limit.",
136
+ "- It does not run for other pull requests. The final pull request into your default branch is",
137
+ " one of them, so do not require `" + EPIC_IMPLEMENTER_CI_CHECK_NAME + "` in a default-branch rule.",
92
138
  "- It requests only `contents: read` and uses no secrets.",
93
139
  "- A pull request from a fork never checks out or runs repository code. The gate passes for",
94
140
  " it immediately and says so. The gate job itself has a " + String(EPIC_CI_GATE_JOB_TIMEOUT_MINUTES) + "-minute limit.",
95
141
  "",
96
142
  "## Dependency setup",
97
143
  "",
98
- "Chosen from the lockfiles in the repository root when this file was generated:",
144
+ "Chosen from the lockfiles in the root of your default branch when this file was generated:",
99
145
  "",
100
146
  ...(setup.length > 0
101
147
  ? setup.map((line) => "- " + line)
102
148
  : ["- None. No supported dependency file was found, so nothing is installed."]),
103
149
  "",
150
+ ...(dependencyInstall.length > 0
151
+ ? [
152
+ "These approved commands run in this order. One that runs a toolchain's manager at the",
153
+ "repository root replaces that manager's fixed install line above. Every other fixed",
154
+ "install line still runs. The test trial and every worker use the same commands:",
155
+ "",
156
+ ...dependencyInstall.flatMap((entry) => [
157
+ "- In `" + entry.cwd + "`:",
158
+ "",
159
+ ...markdownFence(entry.argv.join(" ")),
160
+ "",
161
+ ]),
162
+ ]
163
+ : ["No install commands are approved, so the fixed install lines above run.", ""]),
104
164
  "Where no setup is listed for an ecosystem, nothing is installed for it. A test command that",
105
165
  "needs more than the steps above must install it itself. Rust uses the toolchain the runner",
106
166
  "provides. The version fallbacks are fixed in the generated file, not read from the network.",
@@ -109,21 +169,38 @@ export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
109
169
  "",
110
170
  "- `" + EPIC_CI_WORKFLOW_PATH + "`",
111
171
  "",
172
+ "## What setup stops on, and what it no longer does",
173
+ "",
174
+ ...EPIC_CI_SETUP_STOP_AND_EXIT_TABLE,
175
+ "",
176
+ "Stops added: one, \"repository not learned\", the owner-approved exception.",
177
+ "",
112
178
  "## What you must do",
113
179
  "",
114
- "Review the command in the diff, then merge this pull request yourself. Bridge never merges",
115
- "it. The branch, the commit, and this pull request were created locally with your own git",
116
- "and `gh`; Bridge performed no write to this repository.",
180
+ "Review the command above and the workflow in the diff, then merge this pull request yourself.",
181
+ "Bridge never merges it. The branch, the commit, and this pull request were created locally",
182
+ "with your own git and `gh`, from a temporary copy of your default branch; Bridge performed no",
183
+ "write to this repository and your own folder was not touched.",
117
184
  "",
118
185
  ].join("\n");
119
186
  }
120
187
  /**
121
- * The CI artifact set for one stored command and one resolved toolchain set.
122
- * Build it from the command read back through `GET /setup/testing-config`,
123
- * never from unsaved input, and from the set resolved against the same working
124
- * tree the installer will read.
188
+ * The CI artifact set for one server-validated command and one resolved toolchain
189
+ * set. Build it from the command the server's qualification trial promoted, never
190
+ * from unproven input, and from the set resolved against the same remote
191
+ * default-branch snapshot the installer will build from.
192
+ */
193
+ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains,
194
+ /**
195
+ * BAPI-1654 — the setup CI fallback adds the workflow as a NEW file only. A
196
+ * matching file is still `identical` and an open matching pull request is
197
+ * still reused, but any other existing file is a conflict left untouched: it
198
+ * never takes the upgrade path. Absent keeps every existing caller's upgrade
199
+ * behavior.
125
200
  */
126
- export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
201
+ build = {}) {
202
+ // BAPI-1677: the sealed entries the owner approved. Never derived here.
203
+ const dependencyInstall = build.dependencyInstall ?? [];
127
204
  return {
128
205
  setName: "epic-ci-workflow",
129
206
  installBranch: EPIC_CI_WORKFLOW_INSTALL_BRANCH,
@@ -133,7 +210,7 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
133
210
  installPrTitle: EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT,
134
211
  upgradePrTitle: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
135
212
  historicalBranches: EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES,
136
- renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains),
213
+ renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains, testCommand, dependencyInstall),
137
214
  validateOptions: () => {
138
215
  try {
139
216
  validateTestCommand(testCommand);
@@ -151,15 +228,17 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
151
228
  return { ok: false, reason: "toolchains_invalid" };
152
229
  throw err;
153
230
  }
231
+ if (parseDependencyInstallStrict([...dependencyInstall]) === null)
232
+ return { ok: false, reason: "dependency_install_invalid" };
154
233
  return { ok: true, progress: [] };
155
234
  },
156
235
  artifacts: [
157
236
  {
158
237
  relPath: EPIC_CI_WORKFLOW_PATH,
159
- render: () => renderEpicImplementerCiWorkflow(testCommand, toolchains),
238
+ render: () => renderEpicImplementerCiWorkflow(testCommand, toolchains, dependencyInstall),
160
239
  progressLabel: "workflow",
161
240
  classify: (existing) => {
162
- const classification = classifyEpicCiWorkflowContent(existing, testCommand, toolchains);
241
+ const classification = classifyEpicCiWorkflowContent(existing, testCommand, toolchains, dependencyInstall);
163
242
  const text = EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT[classification];
164
243
  if (classification === "modified_or_unrecognized") {
165
244
  return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
@@ -169,6 +248,9 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
169
248
  // changed. Replace it through the same reviewed update PR as an older
170
249
  // renderer version, so the workflow header's "save a new command and
171
250
  // re-run the installer" holds.
251
+ if (build.createOnly === true && classification !== "not_installed" && classification !== "identical") {
252
+ return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
253
+ }
172
254
  if (classification === "managed_command_differs")
173
255
  return { state: "managed_version_older", text };
174
256
  return { state: classification, text };
@@ -177,16 +259,27 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
177
259
  ],
178
260
  };
179
261
  }
180
- /** Install the CI workflow for `testCommand` and `toolchains`. Returns the typed result; prints progress only. */
262
+ /**
263
+ * Install the CI workflow for `testCommand` and `toolchains`. Returns the typed result; prints progress only.
264
+ *
265
+ * BAPI-1654: `options.createOnly` is the setup CI fallback's mode (see
266
+ * {@link buildEpicCiWorkflowArtifactSet}). The pull request it opens is a
267
+ * proposed workflow, not coverage: checks start only after the owner merges it,
268
+ * and opening it changes no gate.
269
+ */
181
270
  export async function installEpicCiWorkflow(testCommand, toolchains, options, deps) {
182
- return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand, toolchains), options, deps);
271
+ const { createOnly, dependencyInstall, ...engineOptions } = options;
272
+ return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand, toolchains, {
273
+ ...(createOnly === true ? { createOnly: true } : {}),
274
+ ...(dependencyInstall !== undefined ? { dependencyInstall } : {}),
275
+ }), engineOptions, deps);
183
276
  }
184
277
  const REFUSALS = new Set([
185
278
  "workflow_modified_or_unrecognized",
186
279
  "consent_declined",
187
- "worktree_not_clean",
188
280
  "test_command_invalid",
189
281
  "toolchains_invalid",
282
+ "dependency_install_invalid",
190
283
  "historical_managed_pr_open",
191
284
  ]);
192
285
  /** Map an install result to its status. `null` means the install was not attempted. */
@@ -0,0 +1,274 @@
1
+ /**
2
+ * The FROZEN version-2 Epic Implementer CI workflow renderer (BAPI-1603).
3
+ *
4
+ * Version 2 (BAPI-1536) added toolchain provisioning and triggered on every
5
+ * `pull_request`. Version 3 restricts the trigger to epic-targeted pull requests
6
+ * (`branches: ['epic/**']`). Customers hold files this renderer wrote, and the
7
+ * drift classifier recognizes such a file only by reproducing its ENTIRE bytes,
8
+ * so this module is a published contract: its output for a given command and
9
+ * toolchain set must never change, whatever happens to the current renderer
10
+ * (`epic-ci-workflow.ts`). It therefore owns every literal it emits — the action
11
+ * pins, the fallback versions, the timeouts, and the header text — and imports
12
+ * nothing from the current renderer. Only the validators and the canonical
13
+ * toolchain serializer are shared, and a change to either of those is a
14
+ * compatibility break for every renderer version, not only this one.
15
+ *
16
+ * Do not edit this file to change what the workflow does. A behavior change is a
17
+ * new renderer version in `epic-ci-workflow.ts`, with this function left as is.
18
+ *
19
+ * Leaf module: no filesystem, network, or subprocess access.
20
+ */
21
+ import { serializeRepositoryToolchains, validateRepositoryToolchains, } from "./repository-toolchains.js";
22
+ import { validateTestCommand } from "./test-command-validation.js";
23
+ /** Repository-relative path of the managed workflow, as version 2 wrote it. */
24
+ const V2_WORKFLOW_PATH = ".github/workflows/epic-implementer-ci.yml";
25
+ /** The renderer version version 2 wrote into its header. */
26
+ const V2_RENDERER_VERSION = 2;
27
+ /** The header marker keys version 2 used. */
28
+ const V2_VERSION_MARKER_KEY = "x-bridge-ci-renderer-version";
29
+ const V2_TOOLCHAINS_MARKER_KEY = "x-bridge-ci-toolchains";
30
+ /** The `name:` of the one step that runs the stored command. */
31
+ const V2_COMMAND_STEP_NAME = "Run the stored test command";
32
+ /** The pinned action majors version 2 wrote. */
33
+ const V2_ACTION_CHECKOUT = "actions/checkout@v7";
34
+ const V2_ACTION_SETUP_NODE = "actions/setup-node@v7";
35
+ const V2_ACTION_SETUP_PYTHON = "actions/setup-python@v7";
36
+ const V2_ACTION_SETUP_GO = "actions/setup-go@v6";
37
+ const V2_ACTION_SETUP_PNPM = "pnpm/action-setup@v4";
38
+ const V2_ACTION_SETUP_BUN = "oven-sh/setup-bun@v2";
39
+ const V2_ACTION_SETUP_UV = "astral-sh/setup-uv@v6";
40
+ /** The fixed fallbacks version 2 wrote when a repository declared nothing. */
41
+ const V2_NODE_FALLBACK_MAJOR = "24";
42
+ const V2_PYTHON_FALLBACK_MINOR = "3.12";
43
+ const V2_PNPM_FALLBACK_MAJOR = "10";
44
+ const V2_YARN_BERRY_FALLBACK_MAJOR = "4";
45
+ const V2_BUN_VERSION_RANGE = "1.x";
46
+ const V2_POETRY_VERSION = "2.1.3";
47
+ /** The workflow `name:`. */
48
+ const V2_WORKFLOW_NAME = "epic-implementer-ci";
49
+ /** The required check context, and the aggregator job's display `name:`. */
50
+ const V2_CHECK_NAME = "epic-implementer-ci / gate";
51
+ /** Bounds on the execution and aggregator jobs, in minutes. */
52
+ const V2_TEST_JOB_TIMEOUT_MINUTES = 30;
53
+ const V2_GATE_JOB_TIMEOUT_MINUTES = 5;
54
+ /** The fixed indentation and key that precede the command scalar. */
55
+ const V2_COMMAND_LINE_PREFIX = " run: ";
56
+ /**
57
+ * Characters `JSON.stringify` leaves raw that a YAML parser may read as a line
58
+ * break or a byte-order mark (YAML 1.1 treats U+0085, U+2028 and U+2029 as
59
+ * breaks), plus DEL and the C1 controls. They are escaped as `\uXXXX`, which is
60
+ * still valid JSON and a valid YAML double-quoted escape.
61
+ */
62
+ const V2_YAML_UNSAFE_RAW = /[\u007f-\u009f\u2028\u2029\ufeff]/g;
63
+ /** Encode the command as one JSON string that is also a safe YAML scalar. */
64
+ function encodeV2CommandScalar(testCommand) {
65
+ return JSON.stringify(testCommand).replace(V2_YAML_UNSAFE_RAW, (ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0"));
66
+ }
67
+ function v2NodeSetupLines(node) {
68
+ return [
69
+ " - name: Set up Node.js",
70
+ " uses: " + V2_ACTION_SETUP_NODE,
71
+ " with:",
72
+ node === "fixed"
73
+ ? ' node-version: "' + V2_NODE_FALLBACK_MAJOR + '"'
74
+ : " node-version-file: " + node,
75
+ ];
76
+ }
77
+ function v2PythonSetupLines(python) {
78
+ return [
79
+ " - name: Set up Python",
80
+ " uses: " + V2_ACTION_SETUP_PYTHON,
81
+ " with:",
82
+ python === "fixed"
83
+ ? ' python-version: "' + V2_PYTHON_FALLBACK_MINOR + '"'
84
+ : " python-version-file: " + python,
85
+ ];
86
+ }
87
+ function v2JavaScriptSetupLines(js) {
88
+ switch (js.manager) {
89
+ case "npm":
90
+ return [...v2NodeSetupLines(js.node), " - name: Install dependencies", " run: npm ci"];
91
+ case "pnpm":
92
+ return [
93
+ " - name: Set up pnpm",
94
+ " uses: " + V2_ACTION_SETUP_PNPM,
95
+ // A declared `packageManager` is read by the action itself at CI runtime.
96
+ // Passing `version:` as well makes it fail with "Multiple versions of pnpm
97
+ // specified" whenever the two strings differ (a Corepack `+sha` suffix is
98
+ // enough), so the input is given only for the fixed fallback.
99
+ ...(js.pnpm.source === "default" ? [" with:", ' version: "' + V2_PNPM_FALLBACK_MAJOR + '"'] : []),
100
+ ...v2NodeSetupLines(js.node),
101
+ " - name: Install dependencies",
102
+ " run: pnpm install --frozen-lockfile",
103
+ ];
104
+ case "yarn":
105
+ if (js.generation === "classic") {
106
+ return [...v2NodeSetupLines(js.node), " - name: Install dependencies", " run: yarn install --frozen-lockfile"];
107
+ }
108
+ // Corepack reads a declared Yarn version from package.json at CI runtime;
109
+ // the activation below is only the fallback major when none is declared.
110
+ return [
111
+ ...v2NodeSetupLines(js.node),
112
+ " - name: Enable Corepack",
113
+ " run: corepack enable",
114
+ " - name: Activate Yarn",
115
+ " run: corepack prepare yarn@" + V2_YARN_BERRY_FALLBACK_MAJOR + " --activate",
116
+ " - name: Install dependencies",
117
+ " run: yarn install --immutable",
118
+ ];
119
+ case "bun":
120
+ return [
121
+ " - name: Set up Bun",
122
+ " uses: " + V2_ACTION_SETUP_BUN,
123
+ " with:",
124
+ ' bun-version: "' + V2_BUN_VERSION_RANGE + '"',
125
+ " - name: Install dependencies",
126
+ " run: bun install --frozen-lockfile",
127
+ ];
128
+ }
129
+ }
130
+ const V2_PROJECT_ENVIRONMENT_PATH_LINES = [
131
+ " - name: Add the project environment to PATH",
132
+ ' run: echo "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH"',
133
+ ];
134
+ function v2PythonSetupLinesFor(py) {
135
+ const setup = v2PythonSetupLines(py.python);
136
+ switch (py.manager) {
137
+ case "uv":
138
+ return [
139
+ ...setup,
140
+ " - name: Set up uv",
141
+ " uses: " + V2_ACTION_SETUP_UV,
142
+ " - name: Install dependencies",
143
+ " run: uv sync --frozen",
144
+ ...V2_PROJECT_ENVIRONMENT_PATH_LINES,
145
+ ];
146
+ case "poetry":
147
+ return [
148
+ ...setup,
149
+ " - name: Install Poetry",
150
+ " run: python -m pip install poetry==" + V2_POETRY_VERSION,
151
+ " - name: Configure Poetry",
152
+ " run: poetry config virtualenvs.in-project true",
153
+ " - name: Install dependencies",
154
+ " run: poetry install",
155
+ ...V2_PROJECT_ENVIRONMENT_PATH_LINES,
156
+ ];
157
+ case "pip":
158
+ return [...setup, " - name: Install dependencies", " run: pip install -r requirements.txt"];
159
+ }
160
+ }
161
+ /** The setup steps for a validated set, in the fixed JavaScript, Python, Go order. */
162
+ function v2ToolchainSetupLines(toolchains) {
163
+ const lines = [];
164
+ if (toolchains.javascript !== null)
165
+ lines.push(...v2JavaScriptSetupLines(toolchains.javascript));
166
+ if (toolchains.python !== null)
167
+ lines.push(...v2PythonSetupLinesFor(toolchains.python));
168
+ if (toolchains.go !== null) {
169
+ lines.push(" - name: Set up Go", " uses: " + V2_ACTION_SETUP_GO, " with:", " go-version-file: " + toolchains.go.dependencyFile);
170
+ }
171
+ return lines;
172
+ }
173
+ /**
174
+ * Render the workflow for `testCommand` and the resolved `toolchains`.
175
+ * Deterministic: the same inputs always give the same bytes. Throws
176
+ * `TestCommandValidationError` for a bad command and `RepositoryToolchainError`
177
+ * for a toolchain set outside the closed vocabulary.
178
+ */
179
+ export function renderEpicCiWorkflowV2(testCommand, toolchains) {
180
+ const command = validateTestCommand(testCommand);
181
+ const validated = validateRepositoryToolchains(toolchains);
182
+ const lines = [
183
+ "# ===========================================================================",
184
+ "# Epic Implementer CI gate — MANAGED FILE",
185
+ "#",
186
+ "# Generated by Bridge (`" + V2_WORKFLOW_PATH + "`). Do not hand-edit: the",
187
+ "# installer compares this file byte for byte against what it renders and",
188
+ "# refuses to overwrite a modified or unrecognized copy.",
189
+ "#",
190
+ "# " + V2_VERSION_MARKER_KEY + ": " + String(V2_RENDERER_VERSION),
191
+ "# " + V2_TOOLCHAINS_MARKER_KEY + ": " + serializeRepositoryToolchains(validated),
192
+ "#",
193
+ "# WHAT THIS WORKFLOW IS",
194
+ "#",
195
+ "# It publishes one required check, `" + V2_CHECK_NAME + "`, that the",
196
+ "# Bridge Epic Implementer reads before it merges a child pull request. The",
197
+ "# check is green only when the repository's stored test command passes.",
198
+ "#",
199
+ "# SCOPE: SAME-REPOSITORY PULL REQUESTS ONLY",
200
+ "#",
201
+ "# The `tests` job runs only when the pull request head is this repository.",
202
+ "# A fork pull request never checks out or runs repository code; the gate",
203
+ "# passes for it immediately and says so. Nothing here uses a secret, and the",
204
+ "# token is read-only.",
205
+ "#",
206
+ "# DEPENDENCIES",
207
+ "#",
208
+ "# The setup steps before the test command were chosen from the lockfiles in",
209
+ "# the repository root when this file was generated; the toolchains line above",
210
+ "# records the choice. They install dependencies and nothing else. When no",
211
+ "# supported dependency file was found, nothing is installed for that",
212
+ "# ecosystem and the command must install what it needs itself.",
213
+ "#",
214
+ "# THE TEST COMMAND",
215
+ "#",
216
+ "# The command below is the repository's stored test command, run with bash",
217
+ "# from the repository root after the setup steps. To change it, save a new",
218
+ "# command through Bridge setup and re-run the installer; do not edit it here.",
219
+ "# ===========================================================================",
220
+ "name: " + V2_WORKFLOW_NAME,
221
+ "",
222
+ "on:",
223
+ " pull_request:",
224
+ "",
225
+ "permissions:",
226
+ " contents: read",
227
+ "",
228
+ "jobs:",
229
+ " tests:",
230
+ " name: tests",
231
+ " if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}",
232
+ " runs-on: ubuntu-latest",
233
+ " timeout-minutes: " + String(V2_TEST_JOB_TIMEOUT_MINUTES),
234
+ " steps:",
235
+ " - name: Check out the pull request",
236
+ " uses: " + V2_ACTION_CHECKOUT,
237
+ " with:",
238
+ " persist-credentials: false",
239
+ ...v2ToolchainSetupLines(validated),
240
+ " - name: " + V2_COMMAND_STEP_NAME,
241
+ " shell: bash",
242
+ V2_COMMAND_LINE_PREFIX + encodeV2CommandScalar(command),
243
+ "",
244
+ " gate:",
245
+ " name: " + V2_CHECK_NAME,
246
+ " needs: [tests]",
247
+ " if: ${{ always() }}",
248
+ " runs-on: ubuntu-latest",
249
+ " timeout-minutes: " + String(V2_GATE_JOB_TIMEOUT_MINUTES),
250
+ " steps:",
251
+ " - name: Aggregate the Epic Implementer CI result",
252
+ " env:",
253
+ " HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}",
254
+ " THIS_REPOSITORY: ${{ github.repository }}",
255
+ " TESTS_RESULT: ${{ needs.tests.result }}",
256
+ " run: |",
257
+ " if [ -z \"$HEAD_REPOSITORY\" ] || [ -z \"$THIS_REPOSITORY\" ]; then",
258
+ " echo \"The pull request head repository could not be identified; the gate fails.\"",
259
+ " exit 1",
260
+ " fi",
261
+ " if [ \"$HEAD_REPOSITORY\" != \"$THIS_REPOSITORY\" ]; then",
262
+ " echo \"Fork pull request: repository code is never run for a fork, so the gate passes without running tests.\"",
263
+ " exit 0",
264
+ " fi",
265
+ " echo \"Tests: $TESTS_RESULT\"",
266
+ " if [ \"$TESTS_RESULT\" = \"success\" ]; then",
267
+ " exit 0",
268
+ " fi",
269
+ " echo \"The stored test command did not conclude 'success'; the gate fails.\"",
270
+ " exit 1",
271
+ "",
272
+ ];
273
+ return lines.join("\n");
274
+ }