@bridge_gpt/mcp-server 0.2.72 → 0.2.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +3 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-permissions.js +27 -0
  5. package/build/ci-system-detection.js +50 -0
  6. package/build/ci-trigger-adapters.js +631 -0
  7. package/build/ci-trigger-install.js +106 -0
  8. package/build/codex-launcher-pin.js +33 -2
  9. package/build/codex-skill-adapter.js +3 -1
  10. package/build/command-host.js +33 -0
  11. package/build/commands.generated.js +7 -6
  12. package/build/conductor/bridge-api-client.js +842 -35
  13. package/build/conductor/bring-up-facts.js +18 -5
  14. package/build/conductor/command-drift-production.js +42 -17
  15. package/build/conductor/command-drift.js +47 -0
  16. package/build/conductor/declare-blocked.js +554 -0
  17. package/build/conductor/doctor.js +106 -21
  18. package/build/conductor/driver-commands.js +141 -0
  19. package/build/conductor/driver-guard.js +277 -0
  20. package/build/conductor/driver-lapse.js +321 -0
  21. package/build/conductor/driver-register.js +176 -0
  22. package/build/conductor/driver-release.js +174 -0
  23. package/build/conductor/driver-session-state.js +315 -0
  24. package/build/conductor/epic-branch-ci-inspection.js +222 -29
  25. package/build/conductor/epic-implementer-cli.js +166 -15
  26. package/build/conductor/epic-server-database.js +162 -0
  27. package/build/conductor/epic-server-guidance.js +278 -0
  28. package/build/conductor/epic-server-journal.js +239 -0
  29. package/build/conductor/epic-server-processes.js +324 -0
  30. package/build/conductor/epic-server-recipe.js +397 -0
  31. package/build/conductor/epic-server-runtime.js +1207 -0
  32. package/build/conductor/epic-server-sfcc.js +107 -0
  33. package/build/conductor/epic-server-state.js +427 -0
  34. package/build/conductor/epic-server.js +594 -0
  35. package/build/conductor/gate-discovery.js +150 -5
  36. package/build/conductor/gate-settings-review.js +224 -4
  37. package/build/conductor/launch-need-probes.js +6 -53
  38. package/build/conductor/launch-plan.js +313 -156
  39. package/build/conductor/prerequisite-inputs.js +879 -45
  40. package/build/conductor/readiness-assessment.js +16 -1
  41. package/build/conductor/readiness-cli.js +20 -9
  42. package/build/conductor/readiness-prerequisites.js +28 -9
  43. package/build/conductor/readiness-sections.js +133 -126
  44. package/build/conductor/readiness.js +1 -1
  45. package/build/conductor/recovery-cli.js +13 -2
  46. package/build/conductor/tools.js +6 -5
  47. package/build/conductor/wait-run-attention.js +2 -2
  48. package/build/conductor/wait-run-cli.js +208 -22
  49. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  50. package/build/conductor/worker-setup-tally.js +27 -0
  51. package/build/credential-store.js +71 -1
  52. package/build/dependency-install-declarations.js +55 -0
  53. package/build/docs.generated.js +2 -2
  54. package/build/doctor.js +54 -3
  55. package/build/drive-epic-help.js +21 -2
  56. package/build/drive-epic.js +1811 -351
  57. package/build/engine-paths.js +20 -0
  58. package/build/epic-branch-ci-summary.js +140 -0
  59. package/build/epic-capability-statement.js +107 -0
  60. package/build/epic-ci-workflow-drift.js +30 -15
  61. package/build/epic-ci-workflow-install.js +110 -42
  62. package/build/epic-ci-workflow-v2.js +274 -0
  63. package/build/epic-ci-workflow.js +38 -12
  64. package/build/epic-implementer-bin.js +2101 -44
  65. package/build/epic-launch-context.js +607 -0
  66. package/build/epic-server-record.js +273 -0
  67. package/build/epic-shared/bridge-client.js +11 -3
  68. package/build/escalation-reachability.js +43 -0
  69. package/build/executor/ci-fix-test-runs.js +334 -0
  70. package/build/executor/completion-contract.js +8 -1
  71. package/build/executor/env.js +59 -22
  72. package/build/executor/epic-server-context.js +141 -0
  73. package/build/executor/gate-qualification-job.js +127 -26
  74. package/build/executor/http-client.js +52 -5
  75. package/build/executor/job-runner.js +423 -69
  76. package/build/executor/observation.js +8 -0
  77. package/build/executor/pre-pr-checks.js +363 -0
  78. package/build/executor/prompt-spec.js +114 -2
  79. package/build/executor/reconcile-overlap-job.js +5 -3
  80. package/build/executor/required-work-diagnostics.js +4 -2
  81. package/build/executor/required-work-ledger.js +936 -38
  82. package/build/executor/results.js +58 -0
  83. package/build/executor/terminal-mutation.js +8 -0
  84. package/build/executor/worker-command.js +72 -3
  85. package/build/executor/worker-database-config.js +281 -0
  86. package/build/executor/worker-database-target.js +16 -12
  87. package/build/executor/worker-database.js +320 -101
  88. package/build/executor/worker-finalization.js +7 -1
  89. package/build/executor/worker-resources.js +25 -3
  90. package/build/executor/worker-verification-guidance.js +18 -3
  91. package/build/executor/worktree.js +20 -1
  92. package/build/executor-launch.js +54 -2
  93. package/build/generated-assets-catalog.js +2 -2
  94. package/build/index.js +664 -335
  95. package/build/init.js +26 -11
  96. package/build/install-bridge-conductor-answers.js +465 -0
  97. package/build/install-bridge-conductor-apply.js +259 -0
  98. package/build/install-bridge-conductor-assessment.js +895 -0
  99. package/build/install-bridge-conductor-compact.js +161 -0
  100. package/build/install-bridge-conductor-contracts.js +63 -0
  101. package/build/install-bridge-conductor-gate.js +1197 -196
  102. package/build/install-bridge-conductor-setup.js +535 -79
  103. package/build/install-bridge-conductor.js +2885 -560
  104. package/build/install-bridge.js +199 -21
  105. package/build/install-maintenance.js +26 -3
  106. package/build/launcher-config-inspection.js +162 -1
  107. package/build/mcp-grant-candidates.js +767 -0
  108. package/build/mcp-grant-doctor.js +63 -0
  109. package/build/mcp-grant.js +288 -0
  110. package/build/mcp-host-targets.js +8 -0
  111. package/build/mcp-identity.js +23 -0
  112. package/build/mcp-invoke.js +126 -13
  113. package/build/mcp-presets.js +107 -0
  114. package/build/mcp-provisioning.js +134 -2
  115. package/build/mcp-registration-doctor.js +31 -2
  116. package/build/mcp-server-invocation.js +6 -1
  117. package/build/merge-workflow-install.js +234 -109
  118. package/build/pipelines.generated.js +5 -5
  119. package/build/plan-discovery.js +97 -4
  120. package/build/plan-execution-ledger.js +100 -7
  121. package/build/plan-generation-io.js +262 -0
  122. package/build/plan-generation.js +424 -0
  123. package/build/plane/build-freshness.js +6 -1
  124. package/build/plane/cli.js +75 -9
  125. package/build/plane/plane-freshness.js +17 -0
  126. package/build/plane/preflight.js +50 -10
  127. package/build/plane/shutdown.js +19 -0
  128. package/build/plane/terminal-run-cleanup.js +18 -4
  129. package/build/printed-remedy-commands.js +206 -12
  130. package/build/readiness-check.js +77 -0
  131. package/build/readiness-prerequisites.generated.js +122 -14
  132. package/build/readme.generated.js +1 -1
  133. package/build/repository-state-paths.js +38 -0
  134. package/build/run-unit-tests-launcher.js +8 -1
  135. package/build/setup-epic.js +1190 -196
  136. package/build/setup-progress.js +44 -0
  137. package/build/setup-question.js +122 -4
  138. package/build/third-party-mcp-targets.js +30 -0
  139. package/build/ticket-delivery-enrollment.js +9 -0
  140. package/build/upgrade-cli.js +85 -2
  141. package/build/v2-readiness-requirements.js +28 -1
  142. package/build/version.generated.js +3 -3
  143. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  144. package/docs/epic-implementer/getting-started.md +3 -1
  145. package/docs/epic-implementer/self-hosting.md +14 -1
  146. package/package.json +2 -2
@@ -0,0 +1,20 @@
1
+ /**
2
+ * BAPI-1594 — the engine's own paths. A local launch runs engine code from this
3
+ * checkout, so an uncommitted change under any of them is code CI has not seen;
4
+ * a clean status here means the checkout is what CI verified.
5
+ */
6
+ export const ENGINE_PATHS = [
7
+ "mcp_server/src/",
8
+ "mcp_server/tsconfig.json",
9
+ "mcp_server/package.json",
10
+ "mcp_server/package-lock.json",
11
+ "api/library/epic_implementer/",
12
+ "api/library/db/epic_runs.py",
13
+ "api/library/github/merge_execution_eligibility.py",
14
+ "api/routes/epic_runs.py",
15
+ "db/alembic/",
16
+ "requirements.txt",
17
+ "scripts/conductor_health_check.py",
18
+ "tests/integration/conductor_harness/",
19
+ "tests/pytest/db/test_executor_protocol_contract_fidelity.py",
20
+ ];
@@ -0,0 +1,140 @@
1
+ /**
2
+ * BAPI-1654 — the owner-facing words about checks on epic branches.
3
+ *
4
+ * Pure. It turns the collected evidence (coverage, the CI change on offer, the
5
+ * detected CI systems, and whether CI runs on the final integration pull
6
+ * request) into plain sentences, one distinct text per state:
7
+ *
8
+ * - confirmed coverage;
9
+ * - confirmed exclusion, naming the workflow and its filter;
10
+ * - unknown;
11
+ * - a CI change on offer (a trigger edit, or Bridge's managed workflow);
12
+ * - a proposed but unmerged change: proposed, not coverage;
13
+ * - no offer, or a declined one: child pull requests merge without checks;
14
+ * - a CI system Bridge has no adapter for, named.
15
+ *
16
+ * Two rules hold everywhere:
17
+ * - "child pull requests merge into the epic branch without checks" is said
18
+ * only when no check is confirmed to run there and no managed workflow is on
19
+ * offer; for unreadable coverage the words are "could not be confirmed".
20
+ * - "CI runs on the final integration pull request" is said only when the
21
+ * workflows were confirmed to run on pull requests into that base branch.
22
+ *
23
+ * No internal key, id, reason token, or stage name appears in the text.
24
+ */
25
+ const GITHUB_ACTIONS = "GitHub Actions";
26
+ /** At most this many excluded workflows are named one by one. */
27
+ const MAX_NAMED_WORKFLOWS = 5;
28
+ function quoteList(branches) {
29
+ return branches.map((b) => `'${b}'`).join(", ");
30
+ }
31
+ /** "A", "A and B", "A, B, and C". */
32
+ export function joinNames(names) {
33
+ if (names.length <= 1)
34
+ return names[0] ?? "";
35
+ if (names.length === 2)
36
+ return `${names[0]} and ${names[1]}`;
37
+ return `${names.slice(0, -1).join(", ")}, and ${names[names.length - 1]}`;
38
+ }
39
+ /** The sentence about the final integration pull request, by what was confirmed. */
40
+ export function finalIntegrationSentence(target) {
41
+ if (target !== null && target !== undefined && target.coverage === "covers") {
42
+ return `CI runs on the final integration pull request into ${target.branch}.`;
43
+ }
44
+ return "Bridge could not confirm that CI runs on the final integration pull request either.";
45
+ }
46
+ /** The sentence naming detected CI systems Bridge cannot change, or "". */
47
+ export function unsupportedSystemsSentence(systems) {
48
+ const names = (systems ?? []).map((s) => s.name).filter((n) => n !== GITHUB_ACTIONS);
49
+ const unique = [...new Set(names)];
50
+ if (unique.length === 0)
51
+ return "";
52
+ return `This repository also uses ${joinNames(unique)}. Bridge can't safely change ${unique.length === 1 ? "its" : "their"} config yet.`;
53
+ }
54
+ function onlyUnsupportedSystems(systems) {
55
+ const all = systems ?? [];
56
+ if (all.some((s) => s.name === GITHUB_ACTIONS))
57
+ return [];
58
+ return [...new Set(all.map((s) => s.name))];
59
+ }
60
+ function exclusionSentence(excluded) {
61
+ const named = (excluded ?? []).filter((w) => w.branches !== null && w.branches.length > 0);
62
+ if (named.length === 0)
63
+ return "No workflow runs on pull requests into epic branches.";
64
+ if (named.length === 1) {
65
+ return `${named[0].path} runs only on pull requests into ${quoteList(named[0].branches)}, not into epic branches.`;
66
+ }
67
+ // Each workflow with its own filter, bounded so a large repository stays readable.
68
+ const shown = named.slice(0, MAX_NAMED_WORKFLOWS).map((w) => `${w.path} runs only on pull requests into ${quoteList(w.branches)}`);
69
+ const more = named.length - shown.length;
70
+ return `${shown.join("; ")}${more > 0 ? `; and ${more} more workflow${more === 1 ? "" : "s"} like them` : ""}. None of them runs on pull requests into epic branches.`;
71
+ }
72
+ /** The plain text for the current state, before any apply. */
73
+ export function describeEpicBranchCi(input) {
74
+ const parts = [];
75
+ const unsupported = unsupportedSystemsSentence(input.ciSystems);
76
+ if (input.coverage === "covers") {
77
+ parts.push("A workflow already runs on pull requests into epic branches, so each child can wait for its checks before it merges.");
78
+ if (unsupported)
79
+ parts.push(unsupported);
80
+ return parts.join(" ");
81
+ }
82
+ const offer = input.offer ?? null;
83
+ if (offer !== null && offer.actionClass === "trigger_edit") {
84
+ const filter = offer.branchesBefore !== undefined && offer.branchesBefore.length > 0 ? ` (today: ${quoteList(offer.branchesBefore)})` : "";
85
+ parts.push(`${offer.path} does not run on pull requests into epic branches${filter}. Adding 'epic/**' to its pull_request branch list would fix that, and only that list would change.`);
86
+ parts.push("Until that change is merged, child pull requests merge into the epic branch without checks.");
87
+ parts.push(finalIntegrationSentence(input.integrationTarget));
88
+ if (unsupported)
89
+ parts.push(unsupported);
90
+ return parts.join(" ");
91
+ }
92
+ if (offer !== null && offer.actionClass === "managed_workflow") {
93
+ parts.push(`No workflow can be changed safely to run on pull requests into epic branches. Bridge's epic workflow (${offer.path}) would run your test command on each child pull request once it is merged.`);
94
+ if (unsupported)
95
+ parts.push(unsupported);
96
+ return parts.join(" ");
97
+ }
98
+ const only = onlyUnsupportedSystems(input.ciSystems);
99
+ if (input.coverage === null && only.length > 0) {
100
+ parts.push(`This repository uses ${joinNames(only)}. Bridge can't safely change ${only.length === 1 ? "its" : "their"} config yet, so child pull requests merge into the epic branch without checks.`);
101
+ parts.push(finalIntegrationSentence(input.integrationTarget));
102
+ return parts.join(" ");
103
+ }
104
+ if (input.coverage === "does_not_cover") {
105
+ parts.push(exclusionSentence(input.excluded));
106
+ parts.push("Child pull requests merge into the epic branch without checks.");
107
+ parts.push(finalIntegrationSentence(input.integrationTarget));
108
+ }
109
+ else {
110
+ parts.push("Bridge could not confirm that checks run on pull requests into epic branches, so child pull requests may merge into the epic branch without checks.");
111
+ parts.push(finalIntegrationSentence(input.integrationTarget));
112
+ }
113
+ if (unsupported)
114
+ parts.push(unsupported);
115
+ return parts.join(" ");
116
+ }
117
+ /** The text for a declined CI change: honest about what stays without checks. */
118
+ export function describeDeclinedCiChange(input) {
119
+ if (input.coverageViaApprovedSetup === true) {
120
+ // The setup pull request you approved adds the same workflow, so declining this one loses nothing.
121
+ return [
122
+ "You declined this CI pull request, but the setup pull request you approved also adds Bridge's epic workflow.",
123
+ "Its checks start on child pull requests once you merge it. Until then, child pull requests merge into the epic branch without checks.",
124
+ finalIntegrationSentence(input.integrationTarget),
125
+ ].join(" ");
126
+ }
127
+ return [
128
+ "You declined the CI change, so child pull requests merge into the epic branch without checks.",
129
+ finalIntegrationSentence(input.integrationTarget),
130
+ ].join(" ");
131
+ }
132
+ /** The text for an opened or reused CI pull request: proposed, not coverage. */
133
+ export function describeProposedCiChange(actionClass, path, url) {
134
+ const where = url !== null ? ` in ${url}` : "";
135
+ return actionClass === "trigger_edit"
136
+ ? `The CI change to ${path} is proposed${where} and not merged yet. Until you merge it, child pull requests ` +
137
+ "merge into the epic branch without checks. Nothing waits for it."
138
+ : `Bridge's epic workflow (${path}) is proposed${where} and not merged yet. Its checks start on child pull ` +
139
+ "requests once you merge it. Nothing waits for it.";
140
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The advisory capability statement (BAPI-1545).
3
+ *
4
+ * Every non-dry-run `install epic-implementer` builds this short, non-secret
5
+ * summary from the current MCP grant and the epic-server record and writes it to
6
+ * the server (`PUT /jira/epic-runs/capability-statement`). Plan generation and
7
+ * the implement-worker prompt include it, so the planner stops writing tests
8
+ * nobody can run.
9
+ *
10
+ * It is ADVISORY and NEVER an authorization source: nothing may read it to
11
+ * decide what a worker can load. It says what the owner configured, not that
12
+ * any of it works at runtime.
13
+ *
14
+ * Version 1 holds names and closed-vocabulary values only — no commands,
15
+ * arguments, paths, environment values, or credential references. The Python
16
+ * twin (`src/python/llms/agents/epic_capability_statement.py`) applies the same
17
+ * rules; keep the two in step.
18
+ *
19
+ * BAPI-1546: `recipe` says whether repository epic-server GUIDANCE was found at
20
+ * setup. It never means a run recipe was proven or that an epic server is live:
21
+ * the driver proves its recipe per run, and a missing server is a hand-off.
22
+ */
23
+ import { isGrantableServerName, MCP_GRANT_MAX_SERVERS } from "./mcp-grant.js";
24
+ export const EPIC_CAPABILITY_STATEMENT_VERSION = 1;
25
+ const MODES = ["none", "local", "sfcc_shared_active", "unknown"];
26
+ const RECIPES = ["present", "absent", "unknown"];
27
+ const GRANT_STATES = ["present", "absent", "unusable"];
28
+ const KEYS = ["version", "approved_servers", "epic_server_mode", "recipe", "grant_state", "written_at"];
29
+ /**
30
+ * Build the statement from what was read. A usable grant is `present` even when
31
+ * it approves no extra server; an absent or unusable grant lists no servers.
32
+ */
33
+ export function buildEpicCapabilityStatement(grant, epicServer, now) {
34
+ const approved = grant.state === "ok"
35
+ ? [...new Set(grant.grant.servers.map((s) => s.name).filter((n) => isGrantableServerName(n)))]
36
+ .sort()
37
+ .slice(0, MCP_GRANT_MAX_SERVERS)
38
+ : [];
39
+ const grantState = grant.state === "ok" ? "present" : grant.state === "absent" ? "absent" : "unusable";
40
+ let mode;
41
+ let recipe;
42
+ if (epicServer.state === "absent") {
43
+ mode = "none";
44
+ recipe = "unknown";
45
+ }
46
+ else if (epicServer.state === "unusable") {
47
+ mode = "unknown";
48
+ recipe = "unknown";
49
+ }
50
+ else {
51
+ mode = epicServer.record.mode;
52
+ recipe = epicServer.record.recipe ?? "unknown";
53
+ }
54
+ return {
55
+ version: EPIC_CAPABILITY_STATEMENT_VERSION,
56
+ approved_servers: approved,
57
+ epic_server_mode: mode,
58
+ recipe,
59
+ grant_state: grantState,
60
+ written_at: now.toISOString(),
61
+ };
62
+ }
63
+ /**
64
+ * Strictly validate a statement (unknown keys, an unsupported version, a bad
65
+ * timestamp, an unknown vocabulary value, an unsafe or Bridge name, or an
66
+ * unsorted or duplicated list are all rejected). Returns null when invalid.
67
+ */
68
+ export function validateEpicCapabilityStatement(raw) {
69
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
70
+ return null;
71
+ const doc = raw;
72
+ for (const key of Object.keys(doc))
73
+ if (!KEYS.includes(key))
74
+ return null;
75
+ if (doc.version !== EPIC_CAPABILITY_STATEMENT_VERSION)
76
+ return null;
77
+ const servers = doc.approved_servers;
78
+ if (!Array.isArray(servers) || servers.length > MCP_GRANT_MAX_SERVERS)
79
+ return null;
80
+ for (let i = 0; i < servers.length; i++) {
81
+ if (!isGrantableServerName(servers[i]))
82
+ return null;
83
+ if (i > 0 && !(servers[i - 1] < servers[i]))
84
+ return null;
85
+ }
86
+ if (typeof doc.epic_server_mode !== "string" || !MODES.includes(doc.epic_server_mode))
87
+ return null;
88
+ if (typeof doc.recipe !== "string" || !RECIPES.includes(doc.recipe))
89
+ return null;
90
+ if (typeof doc.grant_state !== "string" || !GRANT_STATES.includes(doc.grant_state))
91
+ return null;
92
+ const writtenAt = doc.written_at;
93
+ if (typeof writtenAt !== "string" ||
94
+ writtenAt.length > 64 ||
95
+ !/^\d{4}-\d{2}-\d{2}T.*(Z|[+-]\d{2}:\d{2})$/.test(writtenAt) ||
96
+ Number.isNaN(Date.parse(writtenAt))) {
97
+ return null;
98
+ }
99
+ return {
100
+ version: EPIC_CAPABILITY_STATEMENT_VERSION,
101
+ approved_servers: [...servers],
102
+ epic_server_mode: doc.epic_server_mode,
103
+ recipe: doc.recipe,
104
+ grant_state: doc.grant_state,
105
+ written_at: writtenAt,
106
+ };
107
+ }
@@ -6,9 +6,10 @@
6
6
  * recognition cannot be a fixed SHA list. Instead a file is recognized as
7
7
  * Bridge-rendered only when its ENTIRE bytes equal a re-render: of the current
8
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
9
+ * step by a renderer version Bridge actually published (with the toolchain set
10
+ * from the file's own header, for the versions that wrote one), or of the command
11
+ * AND the toolchain set extracted from a current-version file's own header. A
12
+ * version marker alone proves nothing; a hand-edited or hostile file can claim any
12
13
  * version it likes, and a marker that does not reproduce the whole file is
13
14
  * refused.
14
15
  *
@@ -17,20 +18,26 @@
17
18
  */
18
19
  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
20
  import { renderEpicCiWorkflowV1 } from "./epic-ci-workflow-v1.js";
21
+ import { renderEpicCiWorkflowV2 } from "./epic-ci-workflow-v2.js";
20
22
  import { parseRepositoryToolchains, } from "./repository-toolchains.js";
21
23
  import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
22
24
  /**
23
25
  * Renderers for every OLDER published version, keyed by version.
24
26
  *
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".
27
+ * Version 1 is frozen in `epic-ci-workflow-v1.ts` and version 2 in
28
+ * `epic-ci-workflow-v2.ts`, each unchanged, so their exact bytes stay
29
+ * recognizable. Version 1 uses only a command, because it provisioned no
30
+ * toolchain; version 2 also needs the toolchain set its header records. This map
31
+ * is the published-version preservation contract: a version is added here only
32
+ * by freezing the renderer that shipped, and an entry is never edited or removed,
33
+ * or customers' installed files would stop being recognized as upgradeable.
34
+ * Inventing an entry for a version that never shipped would let a file Bridge
35
+ * never wrote be "upgraded".
32
36
  */
33
- export const EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS = new Map([[1, renderEpicCiWorkflowV1]]);
37
+ export const EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS = new Map([
38
+ [1, (command) => renderEpicCiWorkflowV1(command)],
39
+ [2, (command, toolchains) => (toolchains === null ? null : renderEpicCiWorkflowV2(command, toolchains))],
40
+ ]);
34
41
  /**
35
42
  * Extract and validate the command from the fixed stored-command step; `null`
36
43
  * if the step is absent, duplicated, malformed, or its command is invalid.
@@ -103,13 +110,21 @@ export function classifyEpicCiWorkflowContent(existing, proposedCommand, propose
103
110
  const extracted = extractEpicCiWorkflowCommand(existing);
104
111
  if (extracted === null)
105
112
  return "modified_or_unrecognized";
113
+ // Both inputs of a rendering come from the file itself, and the whole file must
114
+ // reproduce from them. The header marker is untrusted until that is true.
115
+ const toolchains = extractEpicCiWorkflowToolchains(existing);
106
116
  for (const render of EPIC_CI_WORKFLOW_HISTORICAL_RENDERERS.values()) {
107
- if (existing === render(extracted))
117
+ let rendered;
118
+ try {
119
+ rendered = render(extracted, toolchains);
120
+ }
121
+ catch {
122
+ continue;
123
+ }
124
+ if (rendered !== null && existing === rendered)
108
125
  return "managed_version_older";
109
126
  }
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);
127
+ // Another current-version rendering of a different command or toolchain set.
113
128
  if (toolchains !== null && existing === renderEpicImplementerCiWorkflow(extracted, toolchains)) {
114
129
  return "managed_command_differs";
115
130
  }
@@ -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
@@ -51,9 +52,13 @@ export const EPIC_CI_WORKFLOW_UPGRADE_BRANCH = "bridge/epic-implementer-ci-upgra
51
52
  * force-pushes it). Never edit or remove an entry: it names a branch customers
52
53
  * may already have.
53
54
  */
54
- export const EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES = ["bridge/epic-implementer-ci-v1"];
55
+ export const EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES = [
56
+ "bridge/epic-implementer-ci-v1",
57
+ "bridge/epic-implementer-ci-v2",
58
+ ];
55
59
  export const EPIC_CI_WORKFLOW_HISTORICAL_UPGRADE_BRANCHES = [
56
60
  "bridge/epic-implementer-ci-upgrade-v1",
61
+ "bridge/epic-implementer-ci-upgrade-v2",
57
62
  ];
58
63
  export const EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES = [
59
64
  ...EPIC_CI_WORKFLOW_HISTORICAL_INSTALL_BRANCHES,
@@ -68,34 +73,72 @@ export const EPIC_CI_WORKFLOW_ALL_MANAGED_BRANCHES = [
68
73
  export const EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT = "Add the Bridge Epic Implementer CI workflow";
69
74
  export const EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT = "Update the Bridge Epic Implementer CI workflow";
70
75
  /**
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.
76
+ * The stop-and-exit table the setup change carries (BAPI-1603): what setup stops
77
+ * on, what it no longer stops on, and what it leaves alone. Fixed text.
78
+ */
79
+ export const EPIC_CI_SETUP_STOP_AND_EXIT_TABLE = [
80
+ "| Stop or exit | Before | After |",
81
+ "|---|---|---|",
82
+ "| Repository not learned | Not checked | **Added:** setup stops before any write (owner-approved exception) |",
83
+ "| Test-command question and blocking item, every repository | Asked and blocking | Removed. The command is learned and proven, or there is none |",
84
+ "| Setup PR, repository with reporting CI | Always opened | Not opened |",
85
+ "| Setup PR, repository with no CI | Always opened | Opened only if the person says yes to Bridge's workflow |",
86
+ "| Found CI checks as gate members | Required (would block until green, could stall) | Watched: red blocks, missing warns |",
87
+ "| Unqualified local gate at admission (`local_command_unqualified`) | Possible | Never stored: removed before setup ends |",
88
+ "| `worktree_not_clean` refusal of the setup PR | Blocks setup when the folder is dirty | Removed |",
89
+ "| Quiet `precondition` workflow state | Hides a local precondition | Removed; `not_repository_root` prints its remedy as the blocker |",
90
+ "| Push target, default-branch push refusal, credential checks | Unchanged | Unchanged |",
91
+ ];
92
+ /** A fenced block whose fence is longer than any backtick run inside `text`. */
93
+ function markdownFence(text) {
94
+ const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
95
+ const fence = "`".repeat(Math.max(3, longest + 1));
96
+ return [fence, text, fence];
97
+ }
98
+ /**
99
+ * Render the CI pull request body. Deterministic and secret-free: the same inputs
100
+ * always give the same text. It names the server-validated command and how to
101
+ * change it, and carries the stop-and-exit table. It accepts nothing but the
102
+ * validated command and the resolved toolchains, so a raw server response,
103
+ * executor output, or a qualification log has no way in.
74
104
  */
75
- export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
105
+ export function renderEpicCiWorkflowPrBody(upgrade, toolchains, testCommand) {
106
+ const command = validateTestCommand(testCommand);
76
107
  const setup = describeToolchainSet(toolchains);
77
108
  return [
78
109
  upgrade
79
110
  ? "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."
111
+ String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ", the repository's current test command, and its dependency setup."
81
112
  : "This pull request adds the Bridge Epic Implementer CI workflow, renderer version " +
82
113
  String(EPIC_CI_WORKFLOW_RENDERER_VERSION) + ".",
83
114
  "",
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.",
115
+ "The workflow publishes one check, `" + EPIC_IMPLEMENTER_CI_CHECK_NAME + "`. The Bridge",
116
+ "Epic Implementer reads it before it merges a child pull request into an epic branch.",
117
+ "",
118
+ "## The test command",
119
+ "",
120
+ "Bridge learned this command from your repository and proved it by running it once on",
121
+ "your executor before it was stored:",
122
+ "",
123
+ ...markdownFence(command),
124
+ "",
125
+ "To change it, run Bridge setup again with `--test-command \"<your command>\"`. Bridge proves",
126
+ "the new command the same way before it replaces this one. Do not edit the workflow file by hand.",
86
127
  "",
87
128
  "## How it runs",
88
129
  "",
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.",
130
+ "- Only on pull requests that target an `epic/**` branch: the child pull requests the Epic",
131
+ " Implementer merges. It installs dependencies (below), then runs the test command with bash",
132
+ " from the repository root, on `ubuntu-latest`, with a " + String(EPIC_CI_TEST_JOB_TIMEOUT_MINUTES) + "-minute limit.",
133
+ "- It does not run for other pull requests. The final pull request into your default branch is",
134
+ " one of them, so do not require `" + EPIC_IMPLEMENTER_CI_CHECK_NAME + "` in a default-branch rule.",
92
135
  "- It requests only `contents: read` and uses no secrets.",
93
136
  "- A pull request from a fork never checks out or runs repository code. The gate passes for",
94
137
  " it immediately and says so. The gate job itself has a " + String(EPIC_CI_GATE_JOB_TIMEOUT_MINUTES) + "-minute limit.",
95
138
  "",
96
139
  "## Dependency setup",
97
140
  "",
98
- "Chosen from the lockfiles in the repository root when this file was generated:",
141
+ "Chosen from the lockfiles in the root of your default branch when this file was generated:",
99
142
  "",
100
143
  ...(setup.length > 0
101
144
  ? setup.map((line) => "- " + line)
@@ -109,21 +152,36 @@ export function renderEpicCiWorkflowPrBody(upgrade, toolchains) {
109
152
  "",
110
153
  "- `" + EPIC_CI_WORKFLOW_PATH + "`",
111
154
  "",
155
+ "## What setup stops on, and what it no longer does",
156
+ "",
157
+ ...EPIC_CI_SETUP_STOP_AND_EXIT_TABLE,
158
+ "",
159
+ "Stops added: one, \"repository not learned\", the owner-approved exception.",
160
+ "",
112
161
  "## What you must do",
113
162
  "",
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.",
163
+ "Review the command above and the workflow in the diff, then merge this pull request yourself.",
164
+ "Bridge never merges it. The branch, the commit, and this pull request were created locally",
165
+ "with your own git and `gh`, from a temporary copy of your default branch; Bridge performed no",
166
+ "write to this repository and your own folder was not touched.",
117
167
  "",
118
168
  ].join("\n");
119
169
  }
120
170
  /**
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.
171
+ * The CI artifact set for one server-validated command and one resolved toolchain
172
+ * set. Build it from the command the server's qualification trial promoted, never
173
+ * from unproven input, and from the set resolved against the same remote
174
+ * default-branch snapshot the installer will build from.
175
+ */
176
+ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains,
177
+ /**
178
+ * BAPI-1654 — the setup CI fallback adds the workflow as a NEW file only. A
179
+ * matching file is still `identical` and an open matching pull request is
180
+ * still reused, but any other existing file is a conflict left untouched: it
181
+ * never takes the upgrade path. Absent keeps every existing caller's upgrade
182
+ * behavior.
125
183
  */
126
- export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
184
+ build = {}) {
127
185
  return {
128
186
  setName: "epic-ci-workflow",
129
187
  installBranch: EPIC_CI_WORKFLOW_INSTALL_BRANCH,
@@ -133,7 +191,7 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
133
191
  installPrTitle: EPIC_CI_WORKFLOW_INSTALL_COMMIT_SUBJECT,
134
192
  upgradePrTitle: EPIC_CI_WORKFLOW_UPGRADE_COMMIT_SUBJECT,
135
193
  historicalBranches: EPIC_CI_WORKFLOW_HISTORICAL_BRANCHES,
136
- renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains),
194
+ renderPrBody: (upgrade) => renderEpicCiWorkflowPrBody(upgrade, toolchains, testCommand),
137
195
  validateOptions: () => {
138
196
  try {
139
197
  validateTestCommand(testCommand);
@@ -169,6 +227,9 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
169
227
  // changed. Replace it through the same reviewed update PR as an older
170
228
  // renderer version, so the workflow header's "save a new command and
171
229
  // re-run the installer" holds.
230
+ if (build.createOnly === true && classification !== "not_installed" && classification !== "identical") {
231
+ return { state: "conflict", reason: "workflow_modified_or_unrecognized", text };
232
+ }
172
233
  if (classification === "managed_command_differs")
173
234
  return { state: "managed_version_older", text };
174
235
  return { state: classification, text };
@@ -177,14 +238,21 @@ export function buildEpicCiWorkflowArtifactSet(testCommand, toolchains) {
177
238
  ],
178
239
  };
179
240
  }
180
- /** Install the CI workflow for `testCommand` and `toolchains`. Returns the typed result; prints progress only. */
241
+ /**
242
+ * Install the CI workflow for `testCommand` and `toolchains`. Returns the typed result; prints progress only.
243
+ *
244
+ * BAPI-1654: `options.createOnly` is the setup CI fallback's mode (see
245
+ * {@link buildEpicCiWorkflowArtifactSet}). The pull request it opens is a
246
+ * proposed workflow, not coverage: checks start only after the owner merges it,
247
+ * and opening it changes no gate.
248
+ */
181
249
  export async function installEpicCiWorkflow(testCommand, toolchains, options, deps) {
182
- return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand, toolchains), options, deps);
250
+ const { createOnly, ...engineOptions } = options;
251
+ return await installArtifactSet(buildEpicCiWorkflowArtifactSet(testCommand, toolchains, createOnly === true ? { createOnly: true } : {}), engineOptions, deps);
183
252
  }
184
253
  const REFUSALS = new Set([
185
254
  "workflow_modified_or_unrecognized",
186
255
  "consent_declined",
187
- "worktree_not_clean",
188
256
  "test_command_invalid",
189
257
  "toolchains_invalid",
190
258
  "historical_managed_pr_open",