@bridge_gpt/mcp-server 0.2.70 → 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 (61) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +10 -1
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +11 -1
  5. package/build/bounded-wait.js +9 -1
  6. package/build/bridge-permissions.js +13 -5
  7. package/build/commands.generated.js +3 -3
  8. package/build/conductor/bridge-api-client.js +260 -2
  9. package/build/conductor/command-drift-production.js +7 -2
  10. package/build/conductor/doctor.js +9 -3
  11. package/build/conductor/epic-implementer-cli.js +4 -0
  12. package/build/conductor/gate-discovery.js +524 -10
  13. package/build/conductor/gate-settings-review.js +451 -0
  14. package/build/conductor/launch-need-probes.js +16 -11
  15. package/build/conductor/launch-plan.js +145 -0
  16. package/build/conductor/precheck-timings.js +14 -0
  17. package/build/conductor/preview-observations.js +10 -0
  18. package/build/conductor/readiness-sections.js +4 -1
  19. package/build/conductor/recovery-cli.js +59 -2
  20. package/build/conductor/recovery-operations.js +45 -2
  21. package/build/docs.generated.js +1 -1
  22. package/build/drive-epic.js +188 -45
  23. package/build/epic-ci-workflow-drift.js +71 -23
  24. package/build/epic-ci-workflow-install.js +83 -26
  25. package/build/epic-ci-workflow-v1.js +132 -0
  26. package/build/epic-ci-workflow.js +174 -13
  27. package/build/epic-implementer-bin.js +18 -18
  28. package/build/executor/ci-rerun-job.js +220 -14
  29. package/build/executor/env.js +207 -3
  30. package/build/executor/gate-qualification-job.js +20 -5
  31. package/build/executor/job-runner.js +112 -11
  32. package/build/executor/likely-tests.js +6 -1
  33. package/build/executor/preflight.js +5 -0
  34. package/build/executor/process-containment.js +18 -0
  35. package/build/executor/prompt-spec.js +72 -13
  36. package/build/executor/reconcile-overlap-job.js +6 -1
  37. package/build/executor/worker-command.js +136 -1
  38. package/build/executor/worker-database.js +30 -11
  39. package/build/executor/worker-resources.js +12 -1
  40. package/build/executor/worker-verification-guidance.js +29 -0
  41. package/build/index.js +221 -165
  42. package/build/install-bridge-conductor-gate.js +195 -14
  43. package/build/install-bridge-conductor-setup.js +20 -6
  44. package/build/install-bridge-conductor.js +355 -37
  45. package/build/install-bridge.js +1 -1
  46. package/build/merge-workflow-install.js +20 -0
  47. package/build/pipelines.generated.js +2 -2
  48. package/build/plan-execution-ledger.js +23 -8
  49. package/build/plane/plane-freshness.js +6 -2
  50. package/build/plane/preflight.js +19 -0
  51. package/build/printed-remedy-commands.js +8 -1
  52. package/build/readme.generated.js +1 -1
  53. package/build/repository-toolchains.js +581 -0
  54. package/build/setup-epic.js +24 -7
  55. package/build/test-command-detection.js +58 -21
  56. package/build/ticket-delivery-artifacts.js +7 -0
  57. package/build/ticket-delivery-enrollment.js +67 -4
  58. package/build/version.generated.js +3 -3
  59. package/docs/EPIC-IMPLEMENTER.md +38 -0
  60. package/docs/epic-implementer/getting-started.md +58 -2
  61. package/package.json +2 -2
@@ -1,35 +1,66 @@
1
1
  /**
2
2
  * Fail-closed byte identity for the managed CI workflow (BAPI-1460).
3
3
  *
4
- * Unlike the merge workflow, the CI workflow's bytes depend on one input — the
5
- * stored test command — so recognition cannot be a fixed SHA list. Instead a
6
- * file is recognized as Bridge-rendered only when its ENTIRE bytes equal a
7
- * re-render: of the current proposal, or of the command extracted from the
8
- * file's own fixed `run:` line by a renderer version Bridge actually published.
9
- * A version marker alone proves nothing; a hand-edited or hostile file can claim
10
- * any version it likes.
4
+ * Unlike the merge workflow, the CI workflow's bytes depend on two inputs — the
5
+ * stored test command and the resolved toolchain set (BAPI-1536) — so
6
+ * recognition cannot be a fixed SHA list. Instead a file is recognized as
7
+ * Bridge-rendered only when its ENTIRE bytes equal a re-render: of the current
8
+ * proposal, of the command extracted from the file's own fixed stored-command
9
+ * step by a renderer version Bridge actually published, or of the command AND
10
+ * the toolchain set extracted from a version-2 file's own header. A version
11
+ * marker alone proves nothing; a hand-edited or hostile file can claim any
12
+ * version it likes, and a marker that does not reproduce the whole file is
13
+ * refused.
11
14
  *
12
15
  * Leaf module: no filesystem, network, or subprocess access, and no YAML parser.
13
16
  * Nothing here logs file content.
14
17
  */
15
- import { EPIC_CI_COMMAND_LINE_PREFIX, EPIC_CI_WORKFLOW_PATH, renderEpicImplementerCiWorkflow, } from "./epic-ci-workflow.js";
18
+ import { EPIC_CI_COMMAND_LINE_PREFIX, EPIC_CI_COMMAND_STEP_NAME, EPIC_CI_WORKFLOW_PATH, EPIC_CI_WORKFLOW_TOOLCHAINS_MARKER_KEY, renderEpicImplementerCiWorkflow, } from "./epic-ci-workflow.js";
19
+ import { renderEpicCiWorkflowV1 } from "./epic-ci-workflow-v1.js";
20
+ import { parseRepositoryToolchains, } from "./repository-toolchains.js";
16
21
  import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
17
22
  /**
18
23
  * Renderers for every OLDER published version, keyed by version.
19
24
  *
20
- * Empty on purpose: version 1 is the first release, and inventing a historical
21
- * version would let a file that never shipped be "upgraded". When version 2
22
- * ships, freeze version 1's renderer as a function here, unchanged, so its exact
23
- * bytes stay recognizable.
25
+ * Version 1 is frozen in `epic-ci-workflow-v1.ts`, unchanged, so its exact bytes
26
+ * stay recognizable. It takes only a command, because version 1 provisioned no
27
+ * toolchain. This map is the published-version preservation contract: a version
28
+ * is added here only by freezing the renderer that shipped, and an entry is
29
+ * never edited or removed, or customers' installed files would stop being
30
+ * recognized as upgradeable. Inventing an entry for a version that never
31
+ * shipped would let a file Bridge never wrote be "upgraded".
32
+ */
33
+ export const EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS = new Map([[1, renderEpicCiWorkflowV1]]);
34
+ /**
35
+ * Extract and validate the command from the fixed stored-command step; `null`
36
+ * if the step is absent, duplicated, malformed, or its command is invalid.
37
+ *
38
+ * The step is identified by its three fixed lines — the step name, `shell: bash`,
39
+ * and the command line — rather than by "the only quoted `run:` line", because
40
+ * version 2 adds setup steps with their own `run:` lines.
24
41
  */
25
- export const EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS = new Map();
26
- /** Extract and validate the command from the fixed `run:` line; `null` if absent or bad. */
27
42
  export function extractEpicCiWorkflowCommand(content) {
28
43
  const lines = content.split("\n");
29
- const commandLines = lines.filter((line) => line.startsWith(EPIC_CI_COMMAND_LINE_PREFIX + "\""));
30
- if (commandLines.length !== 1)
44
+ const stepLine = " - name: " + EPIC_CI_COMMAND_STEP_NAME;
45
+ let scalar = null;
46
+ for (let i = 0; i < lines.length; i += 1) {
47
+ if (lines[i] !== stepLine)
48
+ continue;
49
+ if (scalar !== null)
50
+ return null; // Two stored-command steps cannot both be ours.
51
+ if (lines[i + 1] !== " shell: bash")
52
+ return null;
53
+ const commandLine = lines[i + 2];
54
+ if (commandLine === undefined || !commandLine.startsWith(EPIC_CI_COMMAND_LINE_PREFIX + "\""))
55
+ return null;
56
+ scalar = commandLine.slice(EPIC_CI_COMMAND_LINE_PREFIX.length);
57
+ }
58
+ if (scalar === null)
59
+ return null;
60
+ // Any other quoted command line is outside the one fixed step.
61
+ const quoted = lines.filter((line) => line.startsWith(EPIC_CI_COMMAND_LINE_PREFIX + "\""));
62
+ if (quoted.length !== 1)
31
63
  return null;
32
- const scalar = commandLines[0].slice(EPIC_CI_COMMAND_LINE_PREFIX.length);
33
64
  let decoded;
34
65
  try {
35
66
  decoded = JSON.parse(scalar);
@@ -46,15 +77,28 @@ export function extractEpicCiWorkflowCommand(content) {
46
77
  throw err;
47
78
  }
48
79
  }
80
+ /**
81
+ * Extract the canonical toolchain set from a version-2 header; `null` if the
82
+ * marker is absent, duplicated, malformed, or outside the closed vocabulary.
83
+ * A marker-only claim is not enough: the caller must still reproduce the whole
84
+ * file from it.
85
+ */
86
+ export function extractEpicCiWorkflowToolchains(content) {
87
+ const prefix = "# " + EPIC_CI_WORKFLOW_TOOLCHAINS_MARKER_KEY + ": ";
88
+ const markers = content.split("\n").filter((line) => line.startsWith(prefix));
89
+ if (markers.length !== 1)
90
+ return null;
91
+ return parseRepositoryToolchains(markers[0].slice(prefix.length));
92
+ }
49
93
  /**
50
94
  * Classify `existing` (`null` when absent) against the proposal for
51
- * `proposedCommand`. Comparison is on raw bytes; line-ending differences are
52
- * differences.
95
+ * `proposedCommand` and `proposedToolchains`. Comparison is on raw bytes;
96
+ * line-ending differences are differences.
53
97
  */
54
- export function classifyEpicCiWorkflowContent(existing, proposedCommand) {
98
+ export function classifyEpicCiWorkflowContent(existing, proposedCommand, proposedToolchains) {
55
99
  if (existing === null)
56
100
  return "not_installed";
57
- if (existing === renderEpicImplementerCiWorkflow(proposedCommand))
101
+ if (existing === renderEpicImplementerCiWorkflow(proposedCommand, proposedToolchains))
58
102
  return "identical";
59
103
  const extracted = extractEpicCiWorkflowCommand(existing);
60
104
  if (extracted === null)
@@ -63,8 +107,12 @@ export function classifyEpicCiWorkflowContent(existing, proposedCommand) {
63
107
  if (existing === render(extracted))
64
108
  return "managed_version_older";
65
109
  }
66
- if (existing === renderEpicImplementerCiWorkflow(extracted))
110
+ // Another version-2 rendering: both inputs come from the file itself, and the
111
+ // whole file must reproduce from them.
112
+ const toolchains = extractEpicCiWorkflowToolchains(existing);
113
+ if (toolchains !== null && existing === renderEpicImplementerCiWorkflow(extracted, toolchains)) {
67
114
  return "managed_command_differs";
115
+ }
68
116
  return "modified_or_unrecognized";
69
117
  }
70
118
  /** Operator-facing gloss for each classification. Path-only; never the command. */
@@ -72,6 +120,6 @@ export const EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT = {
72
120
  not_installed: `${EPIC_CI_WORKFLOW_PATH} is not installed`,
73
121
  identical: `${EPIC_CI_WORKFLOW_PATH} already matches the stored test command`,
74
122
  managed_version_older: `${EPIC_CI_WORKFLOW_PATH} is an older Bridge-managed version and can be upgraded`,
75
- managed_command_differs: `${EPIC_CI_WORKFLOW_PATH} was rendered by Bridge for a different test command and can be updated`,
123
+ managed_command_differs: `${EPIC_CI_WORKFLOW_PATH} was rendered by Bridge for a different test command or toolchain set and can be updated`,
76
124
  modified_or_unrecognized: `${EPIC_CI_WORKFLOW_PATH} has been modified or is not a file Bridge rendered`,
77
125
  };
@@ -6,15 +6,21 @@
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)
9
+ * ## The setup caller's sequence (BAPI-1461, BAPI-1536)
10
10
  *
11
- * 1. Detect or select a command (`detectTestCommand`), asking at most once.
12
- * 2. Get consent to save the command, then save it with `PUT /setup/testing-config`
13
- * (`writeStoredTestCommand`).
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`).
14
16
  * 3. Read the authoritative command back with `GET /setup/testing-config`
15
- * (`readStoredTestCommand`) and build the descriptor from THAT value with
16
- * {@link buildEpicCiWorkflowArtifactSet} — never from the typed answer.
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.
17
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.
18
24
  *
19
25
  * A failed command read or write stops before any installation. Saving the
20
26
  * command and installing the workflow are reported separately
@@ -27,26 +33,51 @@
27
33
  */
28
34
  import { EPIC_CI_GATE_JOB_TIMEOUT_MINUTES, EPIC_CI_TEST_JOB_TIMEOUT_MINUTES, EPIC_CI_WORKFLOW_PATH, EPIC_CI_WORKFLOW_RENDERER_VERSION, EPIC_IMPLEMENTER_CI_CHECK_NAME, renderEpicImplementerCiWorkflow, } from "./epic-ci-workflow.js";
29
35
  import { EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT, classifyEpicCiWorkflowContent, } from "./epic-ci-workflow-drift.js";
36
+ import { describeToolchainSet, RepositoryToolchainError, validateRepositoryToolchains, } from "./repository-toolchains.js";
30
37
  import { installArtifactSet, } from "./merge-workflow-install.js";
31
38
  import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
32
39
  /** Managed branch for a fresh installation. */
33
40
  export const EPIC_CI_WORKFLOW_INSTALL_BRANCH = "bridge/epic-implementer-ci-v" + String(EPIC_CI_WORKFLOW_RENDERER_VERSION);
34
41
  /**
35
42
  * Managed branch for replacing an existing Bridge rendering: an older renderer
36
- * version, or the current version rendered for a different stored command.
43
+ * version, or the current version rendered for a different stored command or
44
+ * toolchain set.
37
45
  */
38
46
  export const EPIC_CI_WORKFLOW_UPGRADE_BRANCH = "bridge/epic-implementer-ci-upgrade-v" + String(EPIC_CI_WORKFLOW_RENDERER_VERSION);
47
+ /**
48
+ * The managed branches earlier published renderer versions used. A pull request
49
+ * still open from one of them is a Bridge pull request for the same file, so new
50
+ * work is refused while it stays open (the installer never closes, rewrites, or
51
+ * force-pushes it). Never edit or remove an entry: it names a branch customers
52
+ * may already have.
53
+ */
54
+ export const EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES = ["bridge/epic-implementer-ci-v1"];
55
+ export const EPIC_CI_WORKFLOW_HISTORICAL_UPGRADE_BRANCHES = [
56
+ "bridge/epic-implementer-ci-upgrade-v1",
57
+ ];
58
+ export const EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES = [
59
+ ...EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES,
60
+ ...EPIC_CI_WORKFLOW_HISTORICAL_UPGRADE_BRANCHES,
61
+ ];
62
+ /** Every managed branch, current first, for callers that look a pull request up by branch. */
63
+ export const EPIC_CI_WORKFLOW_ALL_MANAGED_BRANCHES = [
64
+ EPIC_CI_WORKFLOW_INSTALL_BRANCH,
65
+ EPIC_CI_WORKFLOW_UPGRADE_BRANCH,
66
+ ...EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES,
67
+ ];
39
68
  export const EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT = "Add the Bridge Epic Implementer CI workflow";
40
69
  export const EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT = "Update the Bridge Epic Implementer CI workflow";
41
70
  /**
42
71
  * Render the CI pull request body. Deterministic and secret-free. It describes
43
- * the command contract but never embeds the command; the diff shows it.
72
+ * the command contract and the dependency setup, but never accepts or embeds the
73
+ * command; the diff shows it.
44
74
  */
45
- export function renderEpicCiWorkflowPrBody(upgrade) {
75
+ export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
76
+ const setup = describeToolchainSet(toolchains);
46
77
  return [
47
78
  upgrade
48
79
  ? "This pull request updates the Bridge Epic Implementer CI workflow to renderer version " +
49
- String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + " and the repository's current stored test command."
80
+ String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ", the repository's current stored test command, and its dependency setup."
50
81
  : "This pull request adds the Bridge Epic Implementer CI workflow, renderer version " +
51
82
  String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ".",
52
83
  "",
@@ -55,13 +86,25 @@ export function renderEpicCiWorkflowPrBody(upgrade) {
55
86
  "",
56
87
  "## How it runs",
57
88
  "",
58
- "- On every pull request, it runs the repository's stored test command with bash from the",
59
- " repository root, on `ubuntu-latest`, with a " + String(EPIC_CI_TEST_JOB_TIMEOUT_MINUTES) + "-minute limit.",
60
- "- The command must be self-contained: the workflow installs no runtime or dependencies.",
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.",
61
92
  "- It requests only `contents: read` and uses no secrets.",
62
93
  "- A pull request from a fork never checks out or runs repository code. The gate passes for",
63
94
  " it immediately and says so. The gate job itself has a " + String(EPIC_CI_GATE_JOB_TIMEOUT_MINUTES) + "-minute limit.",
64
95
  "",
96
+ "## Dependency setup",
97
+ "",
98
+ "Chosen from the lockfiles in the repository root when this file was generated:",
99
+ "",
100
+ ...(setup.length > 0
101
+ ? setup.map((line) => "- " + line)
102
+ : ["- None. No supported dependency file was found, so nothing is installed."]),
103
+ "",
104
+ "Where no setup is listed for an ecosystem, nothing is installed for it. A test command that",
105
+ "needs more than the steps above must install it itself. Rust uses the toolchain the runner",
106
+ "provides. The version fallbacks are fixed in the generated file, not read from the network.",
107
+ "",
65
108
  "## Files",
66
109
  "",
67
110
  "- `" + EPIC_CI_WORKFLOW_PATH + "`",
@@ -75,10 +118,12 @@ export function renderEpicCiWorkflowPrBody(upgrade) {
75
118
  ].join("\n");
76
119
  }
77
120
  /**
78
- * The CI artifact set for one stored command. Build it from the command read
79
- * back through `GET /setup/testing-config`, never from unsaved input.
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.
80
125
  */
81
- export function buildEpicCiWorkflowArtifactSet(testCommand) {
126
+ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
82
127
  return {
83
128
  setName: "epic-ci-workflow",
84
129
  installBranch: EPIC_CI_WORKFLOW_INSTALL_BRANCH,
@@ -87,7 +132,8 @@ export function buildEpicCiWorkflowArtifactSet(testCommand) {
87
132
  upgradeCommitSubject: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
88
133
  installPrTitle: EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT,
89
134
  upgradePrTitle: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
90
- renderPrBody: renderEpicCiWorkflowPrBody,
135
+ historicalBranches: EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES,
136
+ renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains),
91
137
  validateOptions: () => {
92
138
  try {
93
139
  validateTestCommand(testCommand);
@@ -97,23 +143,32 @@ export function buildEpicCiWorkflowArtifactSet(testCommand) {
97
143
  return { ok: false, reason: "test_command_invalid" };
98
144
  throw err;
99
145
  }
146
+ try {
147
+ validateRepositoryToolchains(toolchains);
148
+ }
149
+ catch (err) {
150
+ if (err instanceof RepositoryToolchainError)
151
+ return { ok: false, reason: "toolchains_invalid" };
152
+ throw err;
153
+ }
100
154
  return { ok: true, progress: [] };
101
155
  },
102
156
  artifacts: [
103
157
  {
104
158
  relPath: EPIC_CI_WORKFLOW_PATH,
105
- render: () => renderEpicImplementerCiWorkflow(testCommand),
159
+ render: () => renderEpicImplementerCiWorkflow(testCommand, toolchains),
106
160
  progressLabel: "workflow",
107
161
  classify: (existing) => {
108
- const classification = classifyEpicCiWorkflowContent(existing, testCommand);
162
+ const classification = classifyEpicCiWorkflowContent(existing, testCommand, toolchains);
109
163
  const text = EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT[classification];
110
164
  if (classification === "modified_or_unrecognized") {
111
165
  return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
112
166
  }
113
- // A complete Bridge rendering of a different command is not a hand
114
- // edit: the stored command changed. Replace it through the same
115
- // reviewed update PR as an older renderer version, so the workflow
116
- // header's "save a new command and re-run the installer" holds.
167
+ // A complete Bridge rendering of a different command or toolchain set
168
+ // is not a hand edit: the stored command or the dependency files
169
+ // changed. Replace it through the same reviewed update PR as an older
170
+ // renderer version, so the workflow header's "save a new command and
171
+ // re-run the installer" holds.
117
172
  if (classification === "managed_command_differs")
118
173
  return { state: "managed_version_older", text };
119
174
  return { state: classification, text };
@@ -122,15 +177,17 @@ export function buildEpicCiWorkflowArtifactSet(testCommand) {
122
177
  ],
123
178
  };
124
179
  }
125
- /** Install the CI workflow for `testCommand`. Returns the typed result; prints progress only. */
126
- export async function installEpicCiWorkflow(testCommand, options, deps) {
127
- return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand), options, deps);
180
+ /** Install the CI workflow for `testCommand` and `toolchains`. Returns the typed result; prints progress only. */
181
+ export async function installEpicCiWorkflow(testCommand, toolchains, options, deps) {
182
+ return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand, toolchains), options, deps);
128
183
  }
129
184
  const REFUSALS = new Set([
130
185
  "workflow_modified_or_unrecognized",
131
186
  "consent_declined",
132
187
  "worktree_not_clean",
133
188
  "test_command_invalid",
189
+ "toolchains_invalid",
190
+ "historical_managed_pr_open",
134
191
  ]);
135
192
  /** Map an install result to its status. `null` means the install was not attempted. */
136
193
  export function epicCiInstallStatus(result) {
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The FROZEN version-1 Epic Implementer CI workflow renderer (BAPI-1536).
3
+ *
4
+ * Version 1 was published before toolchain provisioning existed. Customers hold
5
+ * files this renderer wrote, and the drift classifier recognizes such a file only
6
+ * by reproducing its ENTIRE bytes. That makes this module a published contract:
7
+ * its output for a given command must never change, whatever happens to the
8
+ * current renderer (`epic-ci-workflow.ts`). It therefore owns every literal it
9
+ * emits and imports nothing from the current renderer, so no later edit there
10
+ * can alter these bytes by accident.
11
+ *
12
+ * Do not edit this file to change what the workflow does. A behavior change is a
13
+ * new renderer version in `epic-ci-workflow.ts`, with this function left as is.
14
+ *
15
+ * Leaf module: no filesystem, network, or subprocess access.
16
+ */
17
+ import { validateTestCommand } from "./test-command-validation.js";
18
+ /** Repository-relative path of the managed workflow, as version 1 wrote it. */
19
+ const V1_WORKFLOW_PATH = ".github/workflows/epic-implementer-ci.yml";
20
+ /** The renderer version version 1 wrote into its header. */
21
+ const V1_RENDERER_VERSION = 1;
22
+ /** The header marker key version 1 used. */
23
+ const V1_VERSION_MARKER_KEY = "x-bridge-ci-renderer-version";
24
+ /** The workflow `name:` version 1 used. */
25
+ const V1_WORKFLOW_NAME = "epic-implementer-ci";
26
+ /** The required check context, and the aggregator job's display `name:`. */
27
+ const V1_CHECK_NAME = "epic-implementer-ci / gate";
28
+ /** Bound on the execution job, in minutes. */
29
+ const V1_TEST_JOB_TIMEOUT_MINUTES = 30;
30
+ /** Bound on the aggregator job, in minutes. */
31
+ const V1_GATE_JOB_TIMEOUT_MINUTES = 5;
32
+ /** The fixed indentation and key that precede the command scalar. */
33
+ const V1_COMMAND_LINE_PREFIX = " run: ";
34
+ /**
35
+ * Characters `JSON.stringify` leaves raw that a YAML parser may read as a line
36
+ * break or a byte-order mark, plus DEL and the C1 controls, escaped as `\uXXXX`.
37
+ */
38
+ const V1_YAML_UNSAFE_RAW = /[\u007f-\u009f\u2028\u2029\ufeff]/g;
39
+ function encodeV1CommandScalar(testCommand) {
40
+ return JSON.stringify(testCommand).replace(V1_YAML_UNSAFE_RAW, (ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0"));
41
+ }
42
+ /**
43
+ * Render the version-1 workflow for `testCommand`. Deterministic. Throws
44
+ * `TestCommandValidationError` for a bad command.
45
+ */
46
+ export function renderEpicCiWorkflowV1(testCommand) {
47
+ const command = validateTestCommand(testCommand);
48
+ const lines = [
49
+ "# ===========================================================================",
50
+ "# Epic Implementer CI gate — MANAGED FILE",
51
+ "#",
52
+ "# Generated by Bridge (`" + V1_WORKFLOW_PATH + "`). Do not hand-edit: the",
53
+ "# installer compares this file byte for byte against what it renders and",
54
+ "# refuses to overwrite a modified or unrecognized copy.",
55
+ "#",
56
+ "# " + V1_VERSION_MARKER_KEY + ": " + String(V1_RENDERER_VERSION),
57
+ "#",
58
+ "# WHAT THIS WORKFLOW IS",
59
+ "#",
60
+ "# It publishes one required check, `" + V1_CHECK_NAME + "`, that the",
61
+ "# Bridge Epic Implementer reads before it merges a child pull request. The",
62
+ "# check is green only when the repository's stored test command passes.",
63
+ "#",
64
+ "# SCOPE: SAME-REPOSITORY PULL REQUESTS ONLY",
65
+ "#",
66
+ "# The `tests` job runs only when the pull request head is this repository.",
67
+ "# A fork pull request never checks out or runs repository code; the gate",
68
+ "# passes for it immediately and says so. Nothing here uses a secret, and the",
69
+ "# token is read-only.",
70
+ "#",
71
+ "# THE TEST COMMAND",
72
+ "#",
73
+ "# The command below is the repository's stored test command, run with bash",
74
+ "# from the repository root. It must be self-contained: this workflow installs",
75
+ "# no language runtime or dependencies, so the command must install what it",
76
+ "# needs. To change it, save a new command through Bridge setup and re-run the",
77
+ "# installer; do not edit it here.",
78
+ "# ===========================================================================",
79
+ "name: " + V1_WORKFLOW_NAME,
80
+ "",
81
+ "on:",
82
+ " pull_request:",
83
+ "",
84
+ "permissions:",
85
+ " contents: read",
86
+ "",
87
+ "jobs:",
88
+ " tests:",
89
+ " name: tests",
90
+ " if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}",
91
+ " runs-on: ubuntu-latest",
92
+ " timeout-minutes: " + String(V1_TEST_JOB_TIMEOUT_MINUTES),
93
+ " steps:",
94
+ " - name: Check out the pull request",
95
+ " uses: actions/checkout@v7",
96
+ " with:",
97
+ " persist-credentials: false",
98
+ " - name: Run the stored test command",
99
+ " shell: bash",
100
+ V1_COMMAND_LINE_PREFIX + encodeV1CommandScalar(command),
101
+ "",
102
+ " gate:",
103
+ " name: " + V1_CHECK_NAME,
104
+ " needs: [tests]",
105
+ " if: ${{ always() }}",
106
+ " runs-on: ubuntu-latest",
107
+ " timeout-minutes: " + String(V1_GATE_JOB_TIMEOUT_MINUTES),
108
+ " steps:",
109
+ " - name: Aggregate the Epic Implementer CI result",
110
+ " env:",
111
+ " HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}",
112
+ " THIS_REPOSITORY: ${{ github.repository }}",
113
+ " TESTS_RESULT: ${{ needs.tests.result }}",
114
+ " run: |",
115
+ " if [ -z \"$HEAD_REPOSITORY\" ] || [ -z \"$THIS_REPOSITORY\" ]; then",
116
+ " echo \"The pull request head repository could not be identified; the gate fails.\"",
117
+ " exit 1",
118
+ " fi",
119
+ " if [ \"$HEAD_REPOSITORY\" != \"$THIS_REPOSITORY\" ]; then",
120
+ " echo \"Fork pull request: repository code is never run for a fork, so the gate passes without running tests.\"",
121
+ " exit 0",
122
+ " fi",
123
+ " echo \"Tests: $TESTS_RESULT\"",
124
+ " if [ \"$TESTS_RESULT\" = \"success\" ]; then",
125
+ " exit 0",
126
+ " fi",
127
+ " echo \"The stored test command did not conclude 'success'; the gate fails.\"",
128
+ " exit 1",
129
+ "",
130
+ ];
131
+ return lines.join("\n");
132
+ }