@bridge_gpt/mcp-server 0.2.69 → 0.2.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/README.md +140 -292
  2. package/build/agent-launchers/claude-executor-adapter.js +27 -5
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +15 -5
  5. package/build/artifact-diff.js +110 -0
  6. package/build/bin-entrypoint.js +36 -0
  7. package/build/bounded-wait.js +9 -1
  8. package/build/bridge-permissions.js +36 -9
  9. package/build/claude-review-workflow-drift.js +3 -3
  10. package/build/codex-bridge-profile.js +1 -1
  11. package/build/commands.generated.js +6 -6
  12. package/build/conductor/bridge-api-client.js +858 -21
  13. package/build/conductor/bring-up-facts.js +9 -9
  14. package/build/conductor/command-drift-production.js +7 -2
  15. package/build/conductor/doctor.js +472 -18
  16. package/build/conductor/epic-child-continuation.js +54 -3
  17. package/build/conductor/epic-implementer-cli.js +136 -34
  18. package/build/conductor/epic-runtime.js +2 -2
  19. package/build/conductor/epic-state.js +1 -1
  20. package/build/conductor/gate-discovery.js +524 -10
  21. package/build/conductor/gate-settings-review.js +451 -0
  22. package/build/conductor/hook-runtime-qualification.js +1 -1
  23. package/build/conductor/install-doctor.js +4 -2
  24. package/build/conductor/launch-need-probes.js +342 -0
  25. package/build/conductor/launch-plan.js +145 -0
  26. package/build/conductor/local-merge.js +241 -56
  27. package/build/conductor/merge-credential.js +172 -0
  28. package/build/conductor/merge-execution-eligibility.js +1 -1
  29. package/build/conductor/merged-child-check.js +95 -0
  30. package/build/conductor/plan-trim.js +30 -0
  31. package/build/conductor/pr-ci-producer.js +1 -1
  32. package/build/conductor/precheck-timings.js +14 -0
  33. package/build/conductor/preview-observations.js +10 -0
  34. package/build/conductor/readiness-cli.js +11 -6
  35. package/build/conductor/readiness-prerequisites.js +41 -0
  36. package/build/conductor/readiness-sections.js +348 -55
  37. package/build/conductor/readiness.js +99 -87
  38. package/build/conductor/recovery-cli.js +665 -23
  39. package/build/conductor/recovery-operations.js +350 -8
  40. package/build/conductor/repair-contract.js +47 -2
  41. package/build/conductor/repository-workflow-remedy.js +8 -6
  42. package/build/conductor/stored-merge-credential.js +76 -0
  43. package/build/conductor/stored-merge-token-probe.js +28 -0
  44. package/build/conductor/temporary-plan.js +50 -0
  45. package/build/conductor/wait-run-cli.js +759 -0
  46. package/build/conductor/worker-database-doctor-inspector.js +49 -0
  47. package/build/conductor-bin.js +2 -2
  48. package/build/conductor-claude-hook-bin.js +2 -2
  49. package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
  50. package/build/conductor-removed-stub-bin.js +2 -5
  51. package/build/credential-store.js +356 -13
  52. package/build/docs.generated.js +26 -13
  53. package/build/doctor.js +94 -32
  54. package/build/drive-epic-help.js +212 -0
  55. package/build/drive-epic.js +1989 -379
  56. package/build/epic-ci-workflow-drift.js +125 -0
  57. package/build/epic-ci-workflow-install.js +240 -0
  58. package/build/epic-ci-workflow-v1.js +132 -0
  59. package/build/epic-ci-workflow.js +318 -0
  60. package/build/epic-contract-context.js +326 -0
  61. package/build/epic-implementer-bin.js +58 -42
  62. package/build/epic-implementer-claude-hook-bin.js +2 -2
  63. package/build/escalation-reachability.js +134 -0
  64. package/build/executor/ci-rerun-job.js +220 -14
  65. package/build/executor/cleanup-report.js +99 -0
  66. package/build/executor/cli.js +12 -1
  67. package/build/executor/completion-contract.js +66 -11
  68. package/build/executor/completion-supervision.js +99 -0
  69. package/build/executor/delivery-outcome.js +179 -0
  70. package/build/executor/deps.js +3 -0
  71. package/build/executor/env.js +276 -1
  72. package/build/executor/failure-reason-codes.js +126 -0
  73. package/build/executor/gate-qualification-job.js +20 -5
  74. package/build/executor/heartbeat.js +38 -0
  75. package/build/executor/http-client.js +72 -0
  76. package/build/executor/integration-job.js +298 -5
  77. package/build/executor/job-errors.js +36 -6
  78. package/build/executor/job-runner.js +830 -45
  79. package/build/executor/likely-tests.js +42 -3
  80. package/build/executor/merge-job.js +145 -2
  81. package/build/executor/observation.js +73 -4
  82. package/build/executor/permissions.js +193 -97
  83. package/build/executor/preflight.js +19 -3
  84. package/build/executor/process-containment.js +46 -2
  85. package/build/executor/prompt-spec.js +113 -9
  86. package/build/executor/rebase-finalization.js +38 -3
  87. package/build/executor/reconcile-overlap-job.js +41 -8
  88. package/build/executor/required-work-ledger.js +236 -81
  89. package/build/executor/resume-pre-spawn.js +38 -1
  90. package/build/executor/runner.js +91 -3
  91. package/build/executor/test-clock.js +8 -0
  92. package/build/executor/types.js +37 -2
  93. package/build/executor/worker-cli-launcher.js +259 -0
  94. package/build/executor/worker-command.js +177 -5
  95. package/build/executor/worker-database-target.js +91 -0
  96. package/build/executor/worker-database.js +927 -0
  97. package/build/executor/worker-finalization.js +106 -0
  98. package/build/executor/worker-guard-hook.js +203 -0
  99. package/build/executor/worker-resources.js +58 -0
  100. package/build/executor/worker-verification-guidance.js +44 -2
  101. package/build/executor/worktree.js +303 -15
  102. package/build/executor-launch.js +11 -1
  103. package/build/generated-assets-doctor.js +9 -1
  104. package/build/generated-assets-health.js +13 -4
  105. package/build/generated-assets-legacy.js +39 -0
  106. package/build/generated-assets-paths.js +12 -1
  107. package/build/generated-assets-repair.js +4 -1
  108. package/build/generated-assets-test-support.js +12 -0
  109. package/build/github-remote.js +33 -0
  110. package/build/github-sign-in.js +62 -0
  111. package/build/index.js +1133 -546
  112. package/build/init.js +39 -1
  113. package/build/install-bridge-conductor-gate.js +270 -11
  114. package/build/install-bridge-conductor-setup.js +427 -0
  115. package/build/install-bridge-conductor.js +1545 -268
  116. package/build/install-bridge.js +376 -60
  117. package/build/mcp-install-state.js +8 -2
  118. package/build/merge-pull-request.js +6 -0
  119. package/build/merge-workflow-install.js +782 -344
  120. package/build/phase-result-artifacts.js +75 -20
  121. package/build/pipeline-orchestrator.js +247 -4
  122. package/build/pipelines.generated.js +35 -35
  123. package/build/plan-discovery.js +15 -2
  124. package/build/plan-execution-ledger.js +321 -17
  125. package/build/plan-phase-routing.js +48 -13
  126. package/build/plane/cli.js +105 -51
  127. package/build/plane/defaults.js +3 -0
  128. package/build/plane/plane-freshness.js +298 -0
  129. package/build/plane/preflight.js +19 -0
  130. package/build/plane/schema-compatibility.js +137 -0
  131. package/build/plane/shutdown-deps.js +38 -0
  132. package/build/plane/shutdown.js +83 -8
  133. package/build/plane/terminal-run-cleanup.js +303 -0
  134. package/build/printed-remedy-commands.js +33 -4
  135. package/build/readiness-check.js +6 -2
  136. package/build/readiness-prerequisites.generated.js +532 -0
  137. package/build/readme.generated.js +1 -1
  138. package/build/repository-toolchains.js +581 -0
  139. package/build/setup-epic.js +421 -34
  140. package/build/shared-resources.generated.js +5 -0
  141. package/build/start-tickets.js +28 -15
  142. package/build/test-command-detection.js +284 -0
  143. package/build/test-command-validation.js +73 -0
  144. package/build/testing-config-client.js +150 -0
  145. package/build/ticket-delivery-artifacts.js +265 -0
  146. package/build/ticket-delivery-enrollment.js +369 -0
  147. package/build/ticket-delivery.js +205 -0
  148. package/build/ticket-review-summary.js +14 -0
  149. package/build/upgrade-cli.js +13 -0
  150. package/build/v2-readiness-requirements.js +552 -0
  151. package/build/version.generated.js +3 -3
  152. package/build/worker-guard-hook-bin.js +2 -2
  153. package/build/worktree-core.js +22 -7
  154. package/docs/BRIDGE-DIRECTORY-README.md +48 -0
  155. package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
  156. package/docs/EPIC-IMPLEMENTER.md +142 -63
  157. package/docs/epic-implementer/getting-started.md +187 -0
  158. package/docs/epic-implementer/self-hosting.md +133 -0
  159. package/package.json +4 -4
  160. package/pipelines/idea-to-ticket.json +1 -1
  161. package/pipelines/implement-ticket.json +8 -8
  162. package/pipelines/review-ticket.json +2 -2
  163. package/design-assets/favicon/favicon-32x32.png +0 -0
  164. package/design-assets/just-logo-rough-draft.png +0 -0
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Fail-closed byte identity for the managed CI workflow (BAPI-1460).
3
+ *
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.
14
+ *
15
+ * Leaf module: no filesystem, network, or subprocess access, and no YAML parser.
16
+ * Nothing here logs file content.
17
+ */
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";
21
+ import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
22
+ /**
23
+ * Renderers for every OLDER published version, keyed by version.
24
+ *
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.
41
+ */
42
+ export function extractEpicCiWorkflowCommand(content) {
43
+ const lines = content.split("\n");
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)
63
+ return null;
64
+ let decoded;
65
+ try {
66
+ decoded = JSON.parse(scalar);
67
+ }
68
+ catch {
69
+ return null;
70
+ }
71
+ try {
72
+ return validateTestCommand(decoded);
73
+ }
74
+ catch (err) {
75
+ if (err instanceof TestCommandValidationError)
76
+ return null;
77
+ throw err;
78
+ }
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
+ }
93
+ /**
94
+ * Classify `existing` (`null` when absent) against the proposal for
95
+ * `proposedCommand` and `proposedToolchains`. Comparison is on raw bytes;
96
+ * line-ending differences are differences.
97
+ */
98
+ export function classifyEpicCiWorkflowContent(existing, proposedCommand, proposedToolchains) {
99
+ if (existing === null)
100
+ return "not_installed";
101
+ if (existing === renderEpicImplementerCiWorkflow(proposedCommand, proposedToolchains))
102
+ return "identical";
103
+ const extracted = extractEpicCiWorkflowCommand(existing);
104
+ if (extracted === null)
105
+ return "modified_or_unrecognized";
106
+ for (const render of EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS.values()) {
107
+ if (existing === render(extracted))
108
+ return "managed_version_older";
109
+ }
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)) {
114
+ return "managed_command_differs";
115
+ }
116
+ return "modified_or_unrecognized";
117
+ }
118
+ /** Operator-facing gloss for each classification. Path-only; never the command. */
119
+ export const EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT = {
120
+ not_installed: `${EPIC_CI_WORKFLOW_PATH} is not installed`,
121
+ identical: `${EPIC_CI_WORKFLOW_PATH} already matches the stored test command`,
122
+ managed_version_older: `${EPIC_CI_WORKFLOW_PATH} is an older Bridge-managed version and can be upgraded`,
123
+ managed_command_differs: `${EPIC_CI_WORKFLOW_PATH} was rendered by Bridge for a different test command or toolchain set and can be updated`,
124
+ modified_or_unrecognized: `${EPIC_CI_WORKFLOW_PATH} has been modified or is not a file Bridge rendered`,
125
+ };
@@ -0,0 +1,240 @@
1
+ /**
2
+ * The Epic Implementer CI workflow as an installable artifact set (BAPI-1460).
3
+ *
4
+ * One managed file, `.github/workflows/epic-implementer-ci.yml`, rendered from
5
+ * the repository's stored test command and delivered through the shared
6
+ * {@link installArtifactSet} engine: read-only preflight, consent, a temporary
7
+ * worktree, a managed branch, and one pull request into the default branch.
8
+ *
9
+ * ## The setup caller's sequence (BAPI-1461, BAPI-1536)
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.
24
+ *
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.
29
+ *
30
+ * The backend integration point for readiness (BAPI-1459) is
31
+ * `get_test_command(repo_name)` in `api/library/db/postgres_functions.py`. A
32
+ * runnable command is never derived from the worker prose fields.
33
+ */
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";
35
+ import { EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT, classifyEpicCiWorkflowContent, } from "./epic-ci-workflow-drift.js";
36
+ import { describeToolchainSet, RepositoryToolchainError, validateRepositoryToolchains, } from "./repository-toolchains.js";
37
+ import { installArtifactSet, } from "./merge-workflow-install.js";
38
+ import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
39
+ /** Managed branch for a fresh installation. */
40
+ export const EPIC_CI_WORKFLOW_INSTALL_BRANCH = "bridge/epic-implementer-ci-v" + String(EPIC_CI_WORKFLOW_RENDERER_VERSION);
41
+ /**
42
+ * Managed branch for replacing an existing Bridge rendering: an older renderer
43
+ * version, or the current version rendered for a different stored command or
44
+ * toolchain set.
45
+ */
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
+ ];
68
+ export const EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT = "Add the Bridge Epic Implementer CI workflow";
69
+ export const EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT = "Update the Bridge Epic Implementer CI workflow";
70
+ /**
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.
74
+ */
75
+ export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
76
+ const setup = describeToolchainSet(toolchains);
77
+ return [
78
+ upgrade
79
+ ? "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."
81
+ : "This pull request adds the Bridge Epic Implementer CI workflow, renderer version " +
82
+ String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ".",
83
+ "",
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.",
86
+ "",
87
+ "## How it runs",
88
+ "",
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.",
92
+ "- It requests only `contents: read` and uses no secrets.",
93
+ "- A pull request from a fork never checks out or runs repository code. The gate passes for",
94
+ " it immediately and says so. The gate job itself has a " + String(EPIC_CI_GATE_JOB_TIMEOUT_MINUTES) + "-minute limit.",
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
+ "",
108
+ "## Files",
109
+ "",
110
+ "- `" + EPIC_CI_WORKFLOW_PATH + "`",
111
+ "",
112
+ "## What you must do",
113
+ "",
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.",
117
+ "",
118
+ ].join("\n");
119
+ }
120
+ /**
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.
125
+ */
126
+ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
127
+ return {
128
+ setName: "epic-ci-workflow",
129
+ installBranch: EPIC_CI_WORKFLOW_INSTALL_BRANCH,
130
+ upgradeBranch: EPIC_CI_WORKFLOW_UPGRADE_BRANCH,
131
+ installCommitSubject: EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT,
132
+ upgradeCommitSubject: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
133
+ installPrTitle: EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT,
134
+ upgradePrTitle: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
135
+ historicalBranches: EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES,
136
+ renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains),
137
+ validateOptions: () => {
138
+ try {
139
+ validateTestCommand(testCommand);
140
+ }
141
+ catch (err) {
142
+ if (err instanceof TestCommandValidationError)
143
+ return { ok: false, reason: "test_command_invalid" };
144
+ throw err;
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
+ }
154
+ return { ok: true, progress: [] };
155
+ },
156
+ artifacts: [
157
+ {
158
+ relPath: EPIC_CI_WORKFLOW_PATH,
159
+ render: () => renderEpicImplementerCiWorkflow(testCommand, toolchains),
160
+ progressLabel: "workflow",
161
+ classify: (existing) => {
162
+ const classification = classifyEpicCiWorkflowContent(existing, testCommand, toolchains);
163
+ const text = EPIC_CI_WORKFLOW_CLASSIFICATION_TEXT[classification];
164
+ if (classification === "modified_or_unrecognized") {
165
+ return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
166
+ }
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.
172
+ if (classification === "managed_command_differs")
173
+ return { state: "managed_version_older", text };
174
+ return { state: classification, text };
175
+ },
176
+ },
177
+ ],
178
+ };
179
+ }
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);
183
+ }
184
+ const REFUSALS = new Set([
185
+ "workflow_modified_or_unrecognized",
186
+ "consent_declined",
187
+ "worktree_not_clean",
188
+ "test_command_invalid",
189
+ "toolchains_invalid",
190
+ "historical_managed_pr_open",
191
+ ]);
192
+ /** Map an install result to its status. `null` means the install was not attempted. */
193
+ export function epicCiInstallStatus(result) {
194
+ if (result === null)
195
+ return "not_attempted";
196
+ switch (result.outcome) {
197
+ case "installed-pr-opened":
198
+ case "upgrade-pr-opened":
199
+ return "pr_opened";
200
+ case "dry-run":
201
+ return "proposal_ready";
202
+ case "identical":
203
+ return "already_installed";
204
+ case "existing-pr":
205
+ return "setup_pr_already_open";
206
+ case "failed":
207
+ if (result.reason === "existing_pr_differs")
208
+ return "proposal_differs";
209
+ if (result.reason === "managed_branch_without_pr" || result.reason === "pr_open_failed") {
210
+ return "managed_branch_needs_recovery";
211
+ }
212
+ return REFUSALS.has(result.reason) ? "install_refused" : "install_failed";
213
+ }
214
+ }
215
+ /**
216
+ * Combine the command outcome and the install outcome into one status, keeping
217
+ * them separate: the command can be saved while the install is refused.
218
+ */
219
+ export function describeEpicCiSetupStatus(command, provenance, result) {
220
+ const status = {
221
+ command,
222
+ install: epicCiInstallStatus(result),
223
+ provenance,
224
+ branch: null,
225
+ prUrl: null,
226
+ compareUrl: null,
227
+ reason: null,
228
+ };
229
+ if (result === null)
230
+ return status;
231
+ if ("branch" in result && typeof result.branch === "string")
232
+ status.branch = result.branch;
233
+ if ("prUrl" in result && typeof result.prUrl === "string")
234
+ status.prUrl = result.prUrl;
235
+ if (result.outcome === "failed") {
236
+ status.reason = result.reason;
237
+ status.compareUrl = result.compareUrl ?? null;
238
+ }
239
+ return status;
240
+ }
@@ -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
+ }