@bridge_gpt/mcp-server 0.2.71 → 0.2.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1638 — the schema version 2 assessment of `install epic-implementer`.
|
|
3
|
+
*
|
|
4
|
+
* Pure. It turns the evidence setup already collects (read-only) into one
|
|
5
|
+
* document: every setup item with its evidence and fix, every open choice with
|
|
6
|
+
* its options and consequences, and the read-only repository facts. It never
|
|
7
|
+
* prompts, writes, or reads anything itself.
|
|
8
|
+
*
|
|
9
|
+
* Every value is projected through an explicit serializer here. Nothing spreads
|
|
10
|
+
* a raw server response, a policy object, a candidate record, or a resolver
|
|
11
|
+
* result into the document, so no credential value can reach it.
|
|
12
|
+
*/
|
|
13
|
+
import { INSTALL_ASSESSMENT_SCHEMA_VERSION, } from "./install-bridge-conductor-contracts.js";
|
|
14
|
+
import { EPIC_SERVER_QUESTION, MCP_GRANT_QUESTION, REINDEX_RETRY_QUESTION, SETUP_ITEM_IDS, setupItemRemedy } from "./install-bridge-conductor-setup.js";
|
|
15
|
+
import { describeDeclinedCiChange, describeEpicBranchCi, finalIntegrationSentence } from "./epic-branch-ci-summary.js";
|
|
16
|
+
import { EPIC_CI_WORKFLOW_PATH } from "./epic-ci-workflow.js";
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Items
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Projected ids that name the same obligation as a catalog id. The assessment
|
|
22
|
+
* path reports local facts as `local.*`, and server records as `<scope>:<id>`.
|
|
23
|
+
* Assessment-only obligations (canonical index, parse progress, setup PR,
|
|
24
|
+
* coverage) have no catalog twin and keep their own ids.
|
|
25
|
+
*/
|
|
26
|
+
const PROJECTED_ID_TO_SETUP_ITEM_ID = Object.freeze({
|
|
27
|
+
"local.claude-login": SETUP_ITEM_IDS.claudeLogin,
|
|
28
|
+
"local.github-login": SETUP_ITEM_IDS.githubSignIn,
|
|
29
|
+
"local.repository-identity": SETUP_ITEM_IDS.repositoryIdentity,
|
|
30
|
+
"local.merge-credential": SETUP_ITEM_IDS.mergeCredential,
|
|
31
|
+
"local.workflow": SETUP_ITEM_IDS.workflows,
|
|
32
|
+
});
|
|
33
|
+
/** Map a projected item id to its catalog id; the original is kept in evidence. */
|
|
34
|
+
export function catalogItemId(projectedId) {
|
|
35
|
+
const mapped = PROJECTED_ID_TO_SETUP_ITEM_ID[projectedId];
|
|
36
|
+
if (mapped !== undefined)
|
|
37
|
+
return { id: mapped, scope: "local" };
|
|
38
|
+
const colon = projectedId.indexOf(":");
|
|
39
|
+
if (colon > 0 && projectedId.slice(colon + 1).includes(".")) {
|
|
40
|
+
return { id: projectedId.slice(colon + 1), scope: projectedId.slice(0, colon) };
|
|
41
|
+
}
|
|
42
|
+
return { id: projectedId, scope: null };
|
|
43
|
+
}
|
|
44
|
+
/** The first back-quoted command in a remedy, when it has one. */
|
|
45
|
+
function remedyCommand(text) {
|
|
46
|
+
const match = /`([^`\n]{1,300})`/.exec(text);
|
|
47
|
+
return match?.[1];
|
|
48
|
+
}
|
|
49
|
+
function projectItem(item) {
|
|
50
|
+
const { id, scope } = catalogItemId(item.id);
|
|
51
|
+
const evidence = { projected_id: item.id };
|
|
52
|
+
if (scope !== null)
|
|
53
|
+
evidence.scope = scope;
|
|
54
|
+
// A remedy-less item resolves its fix by its CATALOG id, so a local fact gets its own repair, not a retry.
|
|
55
|
+
const fixText = item.state === "met" ? null : setupItemRemedy(item.remedy === null ? { ...item, id } : item);
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
label: item.label,
|
|
59
|
+
state: item.state,
|
|
60
|
+
blocking: item.blocking,
|
|
61
|
+
evidence,
|
|
62
|
+
fix: fixText === null || fixText.length === 0
|
|
63
|
+
? null
|
|
64
|
+
: { text: fixText, ...(remedyCommand(fixText) !== undefined ? { command: remedyCommand(fixText) } : {}) },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const KEEP_OPTION = (consequence) => ({ id: "keep", label: "Keep it as it is", consequence });
|
|
68
|
+
function approveDecline(approve, decline) {
|
|
69
|
+
return [
|
|
70
|
+
{ id: "approve", label: "Approve", consequence: approve },
|
|
71
|
+
{ id: "decline", label: "Decline", consequence: decline },
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
function gateEffect(gate) {
|
|
75
|
+
return {
|
|
76
|
+
action: "store_gate_and_defaults",
|
|
77
|
+
target: "repository_gate",
|
|
78
|
+
params: {
|
|
79
|
+
kind: gate.kind,
|
|
80
|
+
provider_checks: [...gate.providerChecks].sort(),
|
|
81
|
+
watched_checks: [...gate.watchedChecks].sort(),
|
|
82
|
+
local_commands: [...gate.localCommands].sort(),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/*
|
|
87
|
+
* A settled choice still carries the effect an approval would name. A replayed
|
|
88
|
+
* answers file then hashes the same after its write is done, and apply reports
|
|
89
|
+
* that write `unchanged` instead of refusing the file.
|
|
90
|
+
*/
|
|
91
|
+
function gateChoice(gate) {
|
|
92
|
+
if (gate === null || !gate.writeNeeded) {
|
|
93
|
+
return {
|
|
94
|
+
id: "gate",
|
|
95
|
+
family: "gate",
|
|
96
|
+
answer_key: "gate",
|
|
97
|
+
current: gate?.currentKind ?? null,
|
|
98
|
+
options: [KEEP_OPTION(gate?.consequence || "The stored gate and supervisor defaults stay as they are.")],
|
|
99
|
+
recommended: "keep",
|
|
100
|
+
why_recommended: "The stored gate already matches what setup would write, so nothing changes.",
|
|
101
|
+
consequential: true,
|
|
102
|
+
applicable: false,
|
|
103
|
+
selection: "single",
|
|
104
|
+
...(gate !== null ? { effects: { approve: gateEffect(gate) } } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
id: "gate",
|
|
109
|
+
family: "gate",
|
|
110
|
+
answer_key: "gate",
|
|
111
|
+
current: gate.currentKind,
|
|
112
|
+
options: approveDecline(gate.consequence || "Stores the proposed gate and the safe supervisor defaults.", "Keeps the gate and defaults unchanged. A run without a stored gate is not ready."),
|
|
113
|
+
recommended: "approve",
|
|
114
|
+
why_recommended: "Runs are admitted only once a confirmed gate and the safe defaults are stored.",
|
|
115
|
+
consequential: true,
|
|
116
|
+
applicable: true,
|
|
117
|
+
selection: "single",
|
|
118
|
+
effects: { approve: gateEffect(gate) },
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const DECLARATION_LABEL = Object.freeze({
|
|
122
|
+
dependency_install: "dependency refresh before each worker step",
|
|
123
|
+
ci_database: "whether CI runs with a database",
|
|
124
|
+
must_order_paths: "paths that must change in order",
|
|
125
|
+
worker_database: "the worker database",
|
|
126
|
+
});
|
|
127
|
+
function declarationEffect(key, value) {
|
|
128
|
+
return { action: "store_declaration", target: `repository_gate.${key}`, params: { value } };
|
|
129
|
+
}
|
|
130
|
+
function declarationChoice(key, found) {
|
|
131
|
+
if (found === undefined || found.applicable === false) {
|
|
132
|
+
return {
|
|
133
|
+
id: key,
|
|
134
|
+
family: "worker_declaration",
|
|
135
|
+
answer_key: key,
|
|
136
|
+
current: null,
|
|
137
|
+
options: [KEEP_OPTION(`The stored ${DECLARATION_LABEL[key]} stays as it is.`)],
|
|
138
|
+
recommended: "keep",
|
|
139
|
+
why_recommended: "Discovery found nothing new to declare, so nothing changes.",
|
|
140
|
+
consequential: true,
|
|
141
|
+
applicable: false,
|
|
142
|
+
selection: "single",
|
|
143
|
+
...(found !== undefined ? { effects: { approve: declarationEffect(key, found.value) } } : {}),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const detail = found.summary.map((line) => line.trim()).join("; ");
|
|
147
|
+
return {
|
|
148
|
+
id: key,
|
|
149
|
+
family: "worker_declaration",
|
|
150
|
+
answer_key: key,
|
|
151
|
+
current: null,
|
|
152
|
+
options: approveDecline(`Stores ${DECLARATION_LABEL[key]} with the gate${detail ? ` (${detail})` : ""}. Workers prepare with it before qualification.`, `Leaves ${DECLARATION_LABEL[key]} as it is stored.`),
|
|
153
|
+
recommended: "approve",
|
|
154
|
+
why_recommended: "Discovery read this from the repository's own files, and workers need it to run the gate's command.",
|
|
155
|
+
consequential: true,
|
|
156
|
+
applicable: true,
|
|
157
|
+
selection: "single",
|
|
158
|
+
effects: { approve: declarationEffect(key, found.value) },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** The bounded discovery-and-promotion trial: the server tries learned candidates and stores one only if it passes. */
|
|
162
|
+
export const LEARN_EFFECT = Object.freeze({
|
|
163
|
+
action: "discover_and_promote_test_command",
|
|
164
|
+
target: "repository_gate.local_commands",
|
|
165
|
+
params: Object.freeze({ bounded: true }),
|
|
166
|
+
condition: "only_if_check_passes",
|
|
167
|
+
});
|
|
168
|
+
function testCommandChoice(t) {
|
|
169
|
+
const options = [];
|
|
170
|
+
if (t.trialEligible) {
|
|
171
|
+
options.push({
|
|
172
|
+
id: "learn",
|
|
173
|
+
label: "Let Bridge learn and prove the test command",
|
|
174
|
+
consequence: "Bridge tries the commands it learned from the repository, one bounded trial, and stores one only if the check passes.",
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
options.push(t.stored
|
|
178
|
+
? KEEP_OPTION("The stored test command stays as it is.")
|
|
179
|
+
: { id: "skip", label: "Do not set a test command now", consequence: "No command is stored; the gate keeps no local check." });
|
|
180
|
+
return {
|
|
181
|
+
id: "test_command",
|
|
182
|
+
family: "test_command",
|
|
183
|
+
answer_key: "test_command",
|
|
184
|
+
current: t.stored ? "stored" : "missing",
|
|
185
|
+
options,
|
|
186
|
+
recommended: t.trialEligible ? "learn" : t.stored ? "keep" : "skip",
|
|
187
|
+
why_recommended: t.trialEligible
|
|
188
|
+
? "A learned command is stored only after the server proves it passes, so it cannot weaken the gate."
|
|
189
|
+
: t.stored
|
|
190
|
+
? "A command is already stored and proven, so nothing changes."
|
|
191
|
+
: "No trial can run for this gate, so there is nothing to prove now.",
|
|
192
|
+
consequential: false,
|
|
193
|
+
applicable: t.trialEligible || t.ownerCommandSupplied,
|
|
194
|
+
selection: "single",
|
|
195
|
+
effects: { learn: LEARN_EFFECT },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const SETUP_PR_EFFECT = Object.freeze({
|
|
199
|
+
action: "open_setup_pull_request",
|
|
200
|
+
target: "github.default_branch",
|
|
201
|
+
condition: "only_if_check_passes",
|
|
202
|
+
});
|
|
203
|
+
function setupPrChoice(pr) {
|
|
204
|
+
if (!pr.applicable) {
|
|
205
|
+
return {
|
|
206
|
+
id: "setup_pr",
|
|
207
|
+
family: "setup_pr",
|
|
208
|
+
answer_key: "setup_pr",
|
|
209
|
+
current: pr.workflowState,
|
|
210
|
+
options: [KEEP_OPTION("No setup pull request opens.")],
|
|
211
|
+
recommended: "keep",
|
|
212
|
+
why_recommended: "Nothing on the default branch needs Bridge's workflow, so no pull request is needed.",
|
|
213
|
+
consequential: true,
|
|
214
|
+
applicable: false,
|
|
215
|
+
selection: "single",
|
|
216
|
+
effects: { approve: SETUP_PR_EFFECT },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const runs = pr.commandSource === "learned" ? "the learned test command" : "the stored test command";
|
|
220
|
+
return {
|
|
221
|
+
id: "setup_pr",
|
|
222
|
+
family: "setup_pr",
|
|
223
|
+
answer_key: "setup_pr",
|
|
224
|
+
current: pr.workflowState,
|
|
225
|
+
options: approveDecline(`Opens a setup pull request running ${runs}, only if the check passes. You review and merge it.`, "Opens no pull request. Bridge's workflow is not added."),
|
|
226
|
+
recommended: "approve",
|
|
227
|
+
why_recommended: `The workflow runs ${runs}, the pull request opens only if that check passes, and you review and merge it, so nothing reaches your default branch without you.`,
|
|
228
|
+
consequential: true,
|
|
229
|
+
applicable: true,
|
|
230
|
+
selection: "single",
|
|
231
|
+
effects: { approve: SETUP_PR_EFFECT },
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function mergeTokenChoice(m) {
|
|
235
|
+
const applicable = m.state === "missing" || m.state === "stored_rejected";
|
|
236
|
+
if (!applicable) {
|
|
237
|
+
return {
|
|
238
|
+
id: "merge_token",
|
|
239
|
+
family: "merge_token",
|
|
240
|
+
answer_key: "merge_token",
|
|
241
|
+
current: m.state,
|
|
242
|
+
options: [KEEP_OPTION("The merge credential stays as it is.")],
|
|
243
|
+
recommended: "keep",
|
|
244
|
+
why_recommended: m.state === "configured" || m.state === "not_applicable"
|
|
245
|
+
? "Merges already have the credential they need, so nothing changes."
|
|
246
|
+
: "Setup cannot store a token for this state; fix the item it reports first.",
|
|
247
|
+
consequential: true,
|
|
248
|
+
applicable: false,
|
|
249
|
+
selection: "reference",
|
|
250
|
+
...(m.storeTarget !== null ? { effects: { reference: { action: "store_merge_token", target: m.storeTarget } } } : {}),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
id: "merge_token",
|
|
255
|
+
family: "merge_token",
|
|
256
|
+
answer_key: "merge_token",
|
|
257
|
+
current: m.state,
|
|
258
|
+
options: [
|
|
259
|
+
{
|
|
260
|
+
id: "reference",
|
|
261
|
+
label: "Store the token named by a reference",
|
|
262
|
+
consequence: "Reads the token from the environment variable or credential-store entry you name, at apply time, and stores it on this computer for this repository only. It is never printed or sent to Bridge.",
|
|
263
|
+
},
|
|
264
|
+
{ id: "decline", label: "Decline", consequence: "Stores nothing. Merges need GITHUB_MERGE_TOKEN set instead." },
|
|
265
|
+
],
|
|
266
|
+
recommended: null,
|
|
267
|
+
why_recommended: "Only you can supply this token, so setup recommends no option and never reads one without your reference.",
|
|
268
|
+
consequential: true,
|
|
269
|
+
applicable: true,
|
|
270
|
+
selection: "reference",
|
|
271
|
+
effects: {
|
|
272
|
+
reference: { action: "store_merge_token", target: m.storeTarget ?? "credential_store.merge_token" },
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The re-index effects, fixed so a replayed answer hashes the same after the
|
|
278
|
+
* recovery evidence moved on. The branch names live in the consequence text and
|
|
279
|
+
* are re-checked against fresh evidence at apply time, never reused blindly.
|
|
280
|
+
*/
|
|
281
|
+
export const REINDEX_EFFECT = Object.freeze({ action: "queue_tracked_parse", target: "repository_index" });
|
|
282
|
+
export const REINDEX_BRANCH_EFFECTS = Object.freeze({
|
|
283
|
+
correct: Object.freeze({ action: "correct_index_branch", target: "repository_config.branch" }),
|
|
284
|
+
keep: Object.freeze({ action: "keep_index_branch", target: "repository_config.branch" }),
|
|
285
|
+
});
|
|
286
|
+
export const REINDEX_RETRY_EFFECTS = Object.freeze({
|
|
287
|
+
retry: Object.freeze({ action: "retry_tracked_parse", target: "repository_index" }),
|
|
288
|
+
});
|
|
289
|
+
const INDEX_ITEM_IDS = new Set(["server.canonical-index", SETUP_ITEM_IDS.indexFreshness]);
|
|
290
|
+
/**
|
|
291
|
+
* Whether the index can honestly be called current. The index items and the
|
|
292
|
+
* setup-revision index state must agree; anything unknown or behind is
|
|
293
|
+
* `unconfirmed`, and indexing under way is `running`.
|
|
294
|
+
*/
|
|
295
|
+
export function indexDisplayStatus(items, index) {
|
|
296
|
+
const states = items.filter((i) => INDEX_ITEM_IDS.has(catalogItemId(i.id).id)).map((i) => i.state);
|
|
297
|
+
if (states.some((s) => s !== "met" && s !== "pending"))
|
|
298
|
+
return "unconfirmed";
|
|
299
|
+
if (["unknown", "behind", "diverged", "recovery_unresolved"].includes(index.state))
|
|
300
|
+
return "unconfirmed";
|
|
301
|
+
if (states.includes("pending") || ["in_progress", "queued_by_setup", "recovery_pending"].includes(index.state))
|
|
302
|
+
return "running";
|
|
303
|
+
return "current";
|
|
304
|
+
}
|
|
305
|
+
/** The `current` value of a not-planned re-index choice, by what the index items say. */
|
|
306
|
+
const REINDEX_NOT_PLANNED_CURRENT = Object.freeze({
|
|
307
|
+
current: "current",
|
|
308
|
+
running: "indexing",
|
|
309
|
+
unconfirmed: "unknown",
|
|
310
|
+
});
|
|
311
|
+
/** The shown text of the not-planned re-index choice, by what the index items say. */
|
|
312
|
+
const REINDEX_NOT_PLANNED_TEXT = Object.freeze({
|
|
313
|
+
current: {
|
|
314
|
+
why: "The index is current, so nothing needs queuing.",
|
|
315
|
+
keep: "The index already covers the setup revision; nothing is queued.",
|
|
316
|
+
},
|
|
317
|
+
running: {
|
|
318
|
+
why: "Indexing is already under way, so nothing more needs queuing.",
|
|
319
|
+
keep: "Nothing more is queued; the indexing already under way continues.",
|
|
320
|
+
},
|
|
321
|
+
unconfirmed: {
|
|
322
|
+
why: "Setup could not confirm the index is up to date and has no re-index to offer here, so follow the fix on the index items instead.",
|
|
323
|
+
keep: "Nothing is queued now. Setup could not confirm the index covers the setup revision.",
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
function reindexChoices(r) {
|
|
327
|
+
const notPlanned = REINDEX_NOT_PLANNED_TEXT[r.indexStatus ?? "current"];
|
|
328
|
+
const choices = [
|
|
329
|
+
{
|
|
330
|
+
id: "reindex",
|
|
331
|
+
family: "reindex",
|
|
332
|
+
answer_key: "reindex",
|
|
333
|
+
// Shown state only (never hashed, never planned on): it agrees with the index items.
|
|
334
|
+
current: r.planned ? "stale" : REINDEX_NOT_PLANNED_CURRENT[r.indexStatus ?? "current"],
|
|
335
|
+
options: r.planned
|
|
336
|
+
? [
|
|
337
|
+
{
|
|
338
|
+
id: "approve",
|
|
339
|
+
label: "Re-index the repository",
|
|
340
|
+
consequence: "Queues one tracked parse of the configured branch so the index reaches the setup revision.",
|
|
341
|
+
},
|
|
342
|
+
{ id: "skip", label: "Not now", consequence: "Queues nothing; the index stays behind." },
|
|
343
|
+
]
|
|
344
|
+
: [KEEP_OPTION(notPlanned.keep)],
|
|
345
|
+
recommended: r.planned ? "approve" : "keep",
|
|
346
|
+
why_recommended: r.planned
|
|
347
|
+
? "Workers read the index, and it is behind the setup revision."
|
|
348
|
+
: notPlanned.why,
|
|
349
|
+
consequential: false,
|
|
350
|
+
applicable: r.planned,
|
|
351
|
+
selection: "single",
|
|
352
|
+
effects: { approve: REINDEX_EFFECT },
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
if (r.branchQuestion !== undefined) {
|
|
356
|
+
const q = r.branchQuestion;
|
|
357
|
+
const configured = JSON.stringify(q.configured);
|
|
358
|
+
choices.push({
|
|
359
|
+
id: "reindex_branch",
|
|
360
|
+
family: "reindex",
|
|
361
|
+
answer_key: "reindex_branch",
|
|
362
|
+
current: q.configured,
|
|
363
|
+
options: [
|
|
364
|
+
{
|
|
365
|
+
id: "correct",
|
|
366
|
+
label: `Use the default branch (${q.destination})`,
|
|
367
|
+
consequence: `Using the default changes the shared branch from ${configured} to ${q.destination}, then queues one tracked first parse once the change reads back and the fresh evidence agrees.`,
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
id: "keep",
|
|
371
|
+
label: `Keep the current branch (${configured})`,
|
|
372
|
+
consequence: "Keeping your branch preserves it. Setup can index it only if fresh evidence shows it contains the setup revision; otherwise merge the setup changes there first.",
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
recommended: "correct",
|
|
376
|
+
why_recommended: "The setup revision is on the default branch, so indexing it there reaches the revision workers need.",
|
|
377
|
+
consequential: true,
|
|
378
|
+
applicable: true,
|
|
379
|
+
selection: "single",
|
|
380
|
+
effects: {
|
|
381
|
+
correct: REINDEX_BRANCH_EFFECTS.correct,
|
|
382
|
+
keep: REINDEX_BRANCH_EFFECTS.keep,
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
if (r.retryQuestion !== undefined) {
|
|
387
|
+
const q = r.retryQuestion;
|
|
388
|
+
choices.push({
|
|
389
|
+
id: "reindex_retry",
|
|
390
|
+
family: "reindex",
|
|
391
|
+
answer_key: "reindex_retry",
|
|
392
|
+
current: "failed_attempt",
|
|
393
|
+
options: [
|
|
394
|
+
{
|
|
395
|
+
id: "retry",
|
|
396
|
+
label: "Retry once",
|
|
397
|
+
consequence: "Retrying queues one new tracked attempt that picks the configured branch when it runs. Asking again for the same retry cannot queue another.",
|
|
398
|
+
},
|
|
399
|
+
{ id: "no_retry", label: "Do not retry", consequence: "Queues nothing; the earlier attempt stays as it ended." },
|
|
400
|
+
],
|
|
401
|
+
recommended: "retry",
|
|
402
|
+
why_recommended: "The earlier attempt did not finish, and one tracked retry is the bounded way to finish it.",
|
|
403
|
+
consequential: true,
|
|
404
|
+
applicable: true,
|
|
405
|
+
selection: "single",
|
|
406
|
+
effects: { retry: REINDEX_RETRY_EFFECTS.retry },
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return choices;
|
|
410
|
+
}
|
|
411
|
+
/** A fixed shape for a listed-but-not-selectable entry: name, origin, and reason only. */
|
|
412
|
+
function excludedEntry(e) {
|
|
413
|
+
return { name: String(e.name), ...(e.origin !== undefined ? { origin: String(e.origin) } : {}), reason: String(e.reason) };
|
|
414
|
+
}
|
|
415
|
+
function mcpGrantChoice(g) {
|
|
416
|
+
if (g === null) {
|
|
417
|
+
return {
|
|
418
|
+
id: "worker_mcp_grant",
|
|
419
|
+
family: "worker_mcp_grant",
|
|
420
|
+
answer_key: "worker_mcp_grant",
|
|
421
|
+
current: null,
|
|
422
|
+
options: [KEEP_OPTION("Workers keep exactly the MCP servers they have today.")],
|
|
423
|
+
recommended: "keep",
|
|
424
|
+
why_recommended: "The MCP servers could not be inspected here, so nothing changes.",
|
|
425
|
+
consequential: true,
|
|
426
|
+
applicable: false,
|
|
427
|
+
selection: "multiple",
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
const options = g.candidates.map((c) => ({
|
|
431
|
+
id: c.id,
|
|
432
|
+
label: `${c.name} (${c.origins.join(", ")})`,
|
|
433
|
+
consequence: `Every Epic Implementer worker in this repository also gets ${c.name}.`,
|
|
434
|
+
}));
|
|
435
|
+
options.push({
|
|
436
|
+
id: "decline",
|
|
437
|
+
label: "Decline",
|
|
438
|
+
consequence: "Changes nothing. Any earlier approval, including an entry listed as no longer valid, stays as it is.",
|
|
439
|
+
});
|
|
440
|
+
// A settled grant is kept when its key is left out; only an open grant recommends the empty selection.
|
|
441
|
+
if (!g.applicable)
|
|
442
|
+
options.unshift(KEEP_OPTION("Workers keep exactly the MCP servers already approved."));
|
|
443
|
+
return {
|
|
444
|
+
id: "worker_mcp_grant",
|
|
445
|
+
family: "worker_mcp_grant",
|
|
446
|
+
answer_key: "worker_mcp_grant",
|
|
447
|
+
current: g.current,
|
|
448
|
+
options,
|
|
449
|
+
recommended: g.applicable ? [] : "keep",
|
|
450
|
+
why_recommended: g.applicable
|
|
451
|
+
? "Workers always get Bridge; each extra server is a deliberate grant, so setup recommends none and you add only what you need."
|
|
452
|
+
: "The approved servers still match what this repository offers, so nothing changes.",
|
|
453
|
+
consequential: true,
|
|
454
|
+
applicable: g.applicable,
|
|
455
|
+
selection: "multiple",
|
|
456
|
+
effects: {
|
|
457
|
+
select: { action: "write_mcp_grant", target: "mcp_grant", params: { fingerprint: g.fingerprint } },
|
|
458
|
+
},
|
|
459
|
+
excluded: g.excluded.map(excludedEntry),
|
|
460
|
+
invalid_existing: g.invalidExisting.map(excludedEntry),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function epicServerChoice(e) {
|
|
464
|
+
const current = e?.current ?? null;
|
|
465
|
+
const options = [
|
|
466
|
+
{
|
|
467
|
+
id: "none",
|
|
468
|
+
label: "No epic server",
|
|
469
|
+
consequence: "Runs start no epic server; UI checks are handed off to a person.",
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
id: "local",
|
|
473
|
+
label: "A local epic server",
|
|
474
|
+
consequence: "The driver starts the epic's code with a throwaway test login, and workers borrow it in turns for UI checks.",
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
id: "sfcc_shared_active",
|
|
478
|
+
label: "One approved SFCC sandbox",
|
|
479
|
+
consequence: "Workers use the approved sandbox. Its account secret stays in the credential store; only its reference is stored.",
|
|
480
|
+
},
|
|
481
|
+
];
|
|
482
|
+
const applicable = e?.applicable ?? false;
|
|
483
|
+
// Keep is always offered: on an open choice it declines, writing nothing, exactly as declining
|
|
484
|
+
// the interactive question does.
|
|
485
|
+
if (current !== null)
|
|
486
|
+
options.unshift(KEEP_OPTION(`The stored choice (${current}) stays as it is.`));
|
|
487
|
+
else
|
|
488
|
+
options.unshift(KEEP_OPTION("Nothing is written; the epic-server record stays as it is."));
|
|
489
|
+
return {
|
|
490
|
+
id: "epic_server",
|
|
491
|
+
family: "epic_server",
|
|
492
|
+
answer_key: "epic_server",
|
|
493
|
+
current,
|
|
494
|
+
options,
|
|
495
|
+
recommended: applicable && current === null ? "none" : "keep",
|
|
496
|
+
why_recommended: applicable && current === null
|
|
497
|
+
? "No epic server is the safe default: a missing server only hands UI checks off."
|
|
498
|
+
: current !== null
|
|
499
|
+
? "A valid choice is already stored, so nothing changes."
|
|
500
|
+
: "The epic-server record could not be read here, so nothing is written.",
|
|
501
|
+
consequential: true,
|
|
502
|
+
applicable,
|
|
503
|
+
selection: "single",
|
|
504
|
+
effects: {
|
|
505
|
+
none: { action: "write_epic_server_record", target: "epic_server_record", params: { mode: "none" } },
|
|
506
|
+
local: { action: "write_epic_server_record", target: "epic_server_record", params: { mode: "local" } },
|
|
507
|
+
sfcc_shared_active: { action: "write_epic_server_record", target: "epic_server_record", params: { mode: "sfcc_shared_active" } },
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/** The summary input for this evidence. */
|
|
512
|
+
function summaryInput(e) {
|
|
513
|
+
const offer = e.ciOffer !== null && e.ciOffer !== undefined && e.ciOffer.applicable
|
|
514
|
+
? { actionClass: e.ciOffer.identity.action_class, path: e.ciOffer.identity.path, ...(e.ciOffer.branchesBefore !== undefined ? { branchesBefore: e.ciOffer.branchesBefore } : {}) }
|
|
515
|
+
: e.managedWorkflowViaSetupPr === true
|
|
516
|
+
// The setup pull request itself offers Bridge's workflow: say so, never "without checks".
|
|
517
|
+
? { actionClass: "managed_workflow", path: EPIC_CI_WORKFLOW_PATH }
|
|
518
|
+
: null;
|
|
519
|
+
return {
|
|
520
|
+
coverage: e.coverage,
|
|
521
|
+
offer,
|
|
522
|
+
excluded: e.excludedWorkflows ?? [],
|
|
523
|
+
ciSystems: e.ciSystems ?? null,
|
|
524
|
+
integrationTarget: e.integrationTarget ?? null,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
/** BAPI-1654 — the plain text for the epic-branch CI state, or null when nothing was collected. */
|
|
528
|
+
export function epicBranchCiStateText(e) {
|
|
529
|
+
return e === null ? null : describeEpicBranchCi(summaryInput(e));
|
|
530
|
+
}
|
|
531
|
+
const CI_CHANGE_ACTION = Object.freeze({
|
|
532
|
+
trigger_edit: "open_ci_trigger_pull_request",
|
|
533
|
+
managed_workflow: "open_managed_epic_workflow_pull_request",
|
|
534
|
+
});
|
|
535
|
+
/** The effect an approval of the CI change has. Its params are the approval's binding. */
|
|
536
|
+
export function ciChangeEffect(identity) {
|
|
537
|
+
return {
|
|
538
|
+
action: CI_CHANGE_ACTION[identity.action_class],
|
|
539
|
+
target: identity.path,
|
|
540
|
+
params: {
|
|
541
|
+
action_class: identity.action_class,
|
|
542
|
+
source_sha256: identity.source_sha256,
|
|
543
|
+
patch_sha256: identity.patch_sha256,
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* BAPI-1654 — the CI change, an ordinary choice. Present only when a change is
|
|
549
|
+
* on offer (or already in place, for a replay), so every proposal without one
|
|
550
|
+
* keeps its exact decisions, actions, and digest.
|
|
551
|
+
*/
|
|
552
|
+
function epicCiChangeChoice(e) {
|
|
553
|
+
const offer = e?.ciOffer ?? null;
|
|
554
|
+
if (e === null || offer === null)
|
|
555
|
+
return null;
|
|
556
|
+
const id = offer.identity;
|
|
557
|
+
const effect = ciChangeEffect(id);
|
|
558
|
+
if (!offer.applicable) {
|
|
559
|
+
return {
|
|
560
|
+
id: "epic_ci_change",
|
|
561
|
+
family: "epic_ci_change",
|
|
562
|
+
answer_key: "epic_ci_change",
|
|
563
|
+
current: "in_place",
|
|
564
|
+
options: [KEEP_OPTION(`The CI change to ${id.path} is already in place, so nothing changes.`)],
|
|
565
|
+
// A replay names no recommendation: it adds no decision to a proposal that never had one.
|
|
566
|
+
recommended: null,
|
|
567
|
+
why_recommended: "The CI change is already in place, so nothing changes.",
|
|
568
|
+
consequential: true,
|
|
569
|
+
applicable: false,
|
|
570
|
+
selection: "single",
|
|
571
|
+
effects: { approve: effect },
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
const input = summaryInput(e);
|
|
575
|
+
const before = offer.branchesBefore !== undefined && offer.branchesBefore.length > 0
|
|
576
|
+
? ` (today it lists ${offer.branchesBefore.map((b) => `'${b}'`).join(", ")})`
|
|
577
|
+
: "";
|
|
578
|
+
const approve = id.action_class === "trigger_edit"
|
|
579
|
+
? `Opens a separate pull request that adds 'epic/**' to the pull_request branch list in ${id.path}${before}. Only that list changes. You review and merge it; until then, child pull requests merge into the epic branch without checks.`
|
|
580
|
+
: `Opens one pull request that adds Bridge's epic workflow as a new file, ${id.path}. It runs your test command on each child pull request once you merge it. No existing workflow changes.${e.managedWorkflowViaSetupPr === true ? " If you also approve the setup pull request, that one pull request serves both." : ""}`;
|
|
581
|
+
return {
|
|
582
|
+
id: "epic_ci_change",
|
|
583
|
+
family: "epic_ci_change",
|
|
584
|
+
answer_key: "epic_ci_change",
|
|
585
|
+
current: id.action_class,
|
|
586
|
+
options: approveDecline(approve, describeDeclinedCiChange(input)),
|
|
587
|
+
recommended: "approve",
|
|
588
|
+
why_recommended: id.action_class === "trigger_edit"
|
|
589
|
+
? `This is a one-line, trigger-only change to ${id.path} that you review and merge, and it lets each child's checks run before it merges.`
|
|
590
|
+
: `No existing workflow can be changed safely, and Bridge's workflow is a new file you review and merge that runs your test command on each child pull request.`,
|
|
591
|
+
consequential: true,
|
|
592
|
+
applicable: true,
|
|
593
|
+
selection: "single",
|
|
594
|
+
effects: { approve: effect },
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function epicBranchCiChoices(e) {
|
|
598
|
+
const covers = e?.coverage === "covers";
|
|
599
|
+
const recorded = e?.recordedDecision ?? null;
|
|
600
|
+
// BAPI-1659: only confirmed coverage recommends `include` here. An offer's existence is not
|
|
601
|
+
// evidence, so a delivery action lifts the recommendation in `resolveEpicBranchCiRecommendation`,
|
|
602
|
+
// from the proposed (or answered) selection set. `offered` below is display only: it picks the
|
|
603
|
+
// sentence the decline option shows.
|
|
604
|
+
const offered = (e?.ciOffer !== null && e?.ciOffer !== undefined && e.ciOffer.applicable) || e?.managedWorkflowViaSetupPr === true;
|
|
605
|
+
const recommendedCi = e === null ? null : covers ? "include" : "decline";
|
|
606
|
+
const stateText = e === null ? null : describeEpicBranchCi(summaryInput(e));
|
|
607
|
+
const decision = {
|
|
608
|
+
id: "epic_branch_ci",
|
|
609
|
+
family: "epic_branch_ci",
|
|
610
|
+
answer_key: "epic_branch_ci",
|
|
611
|
+
current: e?.coverage ?? null,
|
|
612
|
+
options: [
|
|
613
|
+
{
|
|
614
|
+
id: "include",
|
|
615
|
+
label: "Include",
|
|
616
|
+
consequence: "Each child waits for the checks that run on its epic-branch PR before it merges.",
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
id: "decline",
|
|
620
|
+
label: "Decline",
|
|
621
|
+
// The detailed state lives here, not only in `why_recommended`: the recommendation
|
|
622
|
+
// policy replaces that reason when decline is the last resort.
|
|
623
|
+
consequence: e === null || (e.integrationTarget === undefined && e.ciSystems === undefined)
|
|
624
|
+
? "Children merge into the epic branch without waiting for checks that never run there. Problems then surface only at the human-gated integration PR into the base branch."
|
|
625
|
+
: covers || offered
|
|
626
|
+
? `Children merge into the epic branch without waiting for checks. ${finalIntegrationSentence(e.integrationTarget)}`
|
|
627
|
+
: stateText ?? "",
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
recommended: recommendedCi,
|
|
631
|
+
// A recorded decision is shown as the earlier answer. `recommended` stays as the coverage
|
|
632
|
+
// says, so the digest of any answers file is unchanged. The reason explains only the
|
|
633
|
+
// recommendation, never the earlier answer.
|
|
634
|
+
...(recorded !== null ? { earlier_answer: recorded } : {}),
|
|
635
|
+
why_recommended: covers
|
|
636
|
+
? "A workflow runs on epic-branch PRs, so waiting for it catches problems before each merge."
|
|
637
|
+
: stateText ?? "Bridge could not confirm a workflow runs on epic-branch PRs, so it recommends neither option; runs behave as include unless you decline.",
|
|
638
|
+
consequential: false,
|
|
639
|
+
applicable: e !== null,
|
|
640
|
+
selection: "single",
|
|
641
|
+
effects: {
|
|
642
|
+
include: { action: "record_epic_branch_ci_decision", target: "epic_branch_ci", params: { decision: "include" } },
|
|
643
|
+
decline: { action: "record_epic_branch_ci_decision", target: "epic_branch_ci", params: { decision: "decline" } },
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
const approvals = e?.approvalsRequired ?? null;
|
|
647
|
+
const exemptionApplicable = approvals === "yes";
|
|
648
|
+
const exemption = {
|
|
649
|
+
id: "approval_exemption",
|
|
650
|
+
family: "approval_exemption",
|
|
651
|
+
answer_key: "approval_exemption",
|
|
652
|
+
current: approvals,
|
|
653
|
+
options: exemptionApplicable
|
|
654
|
+
? approveDecline("Excludes epic/** from the approval rule with your own gh login. Only the ruleset's excluded branches change, and only for a ruleset that holds nothing but the approval rule.", "Changes nothing. Each child merge waits for a human approval unless the merging account can bypass the rule.")
|
|
655
|
+
: [KEEP_OPTION("No approval rule needs changing for epic-branch PRs.")],
|
|
656
|
+
recommended: exemptionApplicable ? "decline" : "keep",
|
|
657
|
+
why_recommended: exemptionApplicable
|
|
658
|
+
? "Changing a ruleset is consequential, so the safe default is to leave it and decide yourself."
|
|
659
|
+
: "No approval rule applies to epic-branch PRs, or it could not be read, so nothing changes.",
|
|
660
|
+
consequential: true,
|
|
661
|
+
applicable: exemptionApplicable,
|
|
662
|
+
selection: "single",
|
|
663
|
+
effects: e?.ownerRepo !== null && e?.ownerRepo !== undefined
|
|
664
|
+
? { approve: { action: "exclude_epic_from_approval_rule", target: `github.rulesets:${e.ownerRepo}` } }
|
|
665
|
+
: undefined,
|
|
666
|
+
};
|
|
667
|
+
return [decision, exemption];
|
|
668
|
+
}
|
|
669
|
+
function launchProfileChoice(l) {
|
|
670
|
+
const options = [];
|
|
671
|
+
if (l.selected !== null) {
|
|
672
|
+
options.push({
|
|
673
|
+
id: "save",
|
|
674
|
+
label: `Save the launch profile '${l.selected}'`,
|
|
675
|
+
consequence: "Saves a reusable launch profile for this computer with its policy file reference and alert route; never a secret.",
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
options.push({ id: "skip", label: "Do not save a launch profile", consequence: "Nothing is saved; drive-epic asks for its options each time." });
|
|
679
|
+
return {
|
|
680
|
+
id: "launch_profile",
|
|
681
|
+
family: "launch_profile",
|
|
682
|
+
answer_key: "launch_profile",
|
|
683
|
+
current: l.notification,
|
|
684
|
+
options,
|
|
685
|
+
recommended: l.selected !== null ? "save" : "skip",
|
|
686
|
+
why_recommended: l.selected !== null
|
|
687
|
+
? "You named this profile, and saving it lets drive-epic reuse its policy and escalation route."
|
|
688
|
+
: "No profile was named, so there is nothing to save.",
|
|
689
|
+
consequential: false,
|
|
690
|
+
applicable: l.selected !== null,
|
|
691
|
+
selection: "single",
|
|
692
|
+
effects: l.selected !== null
|
|
693
|
+
? { save: { action: "write_launch_profile", target: "launch_profile", params: { name: l.selected } } }
|
|
694
|
+
: undefined,
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
export const RECOMMENDATION_POLICY = Object.freeze({
|
|
698
|
+
gate: Object.freeze({
|
|
699
|
+
never: Object.freeze(["decline"]),
|
|
700
|
+
replacement: Object.freeze({
|
|
701
|
+
option: "approve",
|
|
702
|
+
why: "Runs are admitted only once a confirmed gate and the safe defaults are stored.",
|
|
703
|
+
}),
|
|
704
|
+
}),
|
|
705
|
+
approval_exemption: Object.freeze({
|
|
706
|
+
never: Object.freeze(["decline"]),
|
|
707
|
+
replacement: Object.freeze({
|
|
708
|
+
option: "approve",
|
|
709
|
+
why: "Using your own GitHub CLI sign-in, this changes only the branches the ruleset excludes, only for a ruleset that holds nothing but the approval rule, and it appears in the single proposal you approve, though child merges may still need a human approval if the rule cannot be changed or other approval requirements remain.",
|
|
710
|
+
}),
|
|
711
|
+
}),
|
|
712
|
+
merge_token: Object.freeze({ never: Object.freeze(["decline"]), unresolvedOk: true }),
|
|
713
|
+
test_command: Object.freeze({
|
|
714
|
+
lastResort: Object.freeze({
|
|
715
|
+
option: "skip",
|
|
716
|
+
why: "This is the last resort because no discovery-and-promotion trial can run for this gate, and Bridge recommends learning the command whenever that trial is available.",
|
|
717
|
+
}),
|
|
718
|
+
}),
|
|
719
|
+
epic_branch_ci: Object.freeze({ lastResort: Object.freeze({ option: "decline", why: "This is the last resort because it lets each child merge without waiting for checks, and Bridge recommends it only when no other option can be offered." }), unresolvedOk: true }),
|
|
720
|
+
epic_server: Object.freeze({
|
|
721
|
+
lastResort: Object.freeze({
|
|
722
|
+
option: "none",
|
|
723
|
+
why: "This is the last resort because setup has no evidence the application runs locally, so runs start no epic server and UI checks are handed to a person.",
|
|
724
|
+
}),
|
|
725
|
+
}),
|
|
726
|
+
});
|
|
727
|
+
/**
|
|
728
|
+
* Apply the recommendation policy to one choice. Changes only `recommended` and
|
|
729
|
+
* `why_recommended`; every option, effect, selection and earlier answer is untouched.
|
|
730
|
+
*/
|
|
731
|
+
export function finalizeRecommendation(choice) {
|
|
732
|
+
const rule = RECOMMENDATION_POLICY[choice.answer_key];
|
|
733
|
+
if (rule === undefined)
|
|
734
|
+
return choice;
|
|
735
|
+
const offered = (id) => choice.options.some((o) => o.id === id);
|
|
736
|
+
const rec = choice.recommended;
|
|
737
|
+
if (choice.applicable && typeof rec === "string" && rule.never?.includes(rec)) {
|
|
738
|
+
if (rule.replacement !== undefined && offered(rule.replacement.option)) {
|
|
739
|
+
return { ...choice, recommended: rule.replacement.option, why_recommended: rule.replacement.why };
|
|
740
|
+
}
|
|
741
|
+
if (rule.unresolvedOk === true) {
|
|
742
|
+
return { ...choice, recommended: null, why_recommended: choice.why_recommended };
|
|
743
|
+
}
|
|
744
|
+
return choice;
|
|
745
|
+
}
|
|
746
|
+
if (typeof rec === "string" && rule.lastResort !== undefined && rec === rule.lastResort.option) {
|
|
747
|
+
return { ...choice, why_recommended: rule.lastResort.why };
|
|
748
|
+
}
|
|
749
|
+
if (choice.applicable && rule.replacement !== undefined && rec === rule.replacement.option && offered(rec)) {
|
|
750
|
+
return { ...choice, why_recommended: rule.replacement.why };
|
|
751
|
+
}
|
|
752
|
+
return choice;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* The question each choice asks, in the owner's words. Keyed by answer key so
|
|
756
|
+
* every choice has one. Display only: none of it reaches the digest.
|
|
757
|
+
*/
|
|
758
|
+
const CHOICE_QUESTION = Object.freeze({
|
|
759
|
+
gate: "Should setup save the checks each piece of epic work must pass before it can merge?",
|
|
760
|
+
dependency_install: "Should workers refresh the project's dependencies, using the steps setup found, before each piece of work?",
|
|
761
|
+
ci_database: "Should setup save what it found about whether your tests need a database?",
|
|
762
|
+
must_order_paths: "Should setup save the list of files that must change in a set order, such as database migrations?",
|
|
763
|
+
worker_database: "Should setup save the database settings workers use when they run tests?",
|
|
764
|
+
test_command: "How should setup choose the command that runs your tests?",
|
|
765
|
+
setup_pr: "Should setup open a pull request that adds Bridge's setup workflow to your repository?",
|
|
766
|
+
merge_token: "Where should setup find the GitHub token it uses to merge finished work?",
|
|
767
|
+
reindex: "Should Bridge read your repository again now, so its copy is up to date?",
|
|
768
|
+
reindex_branch: "Which branch should Bridge read your repository from?",
|
|
769
|
+
reindex_retry: REINDEX_RETRY_QUESTION,
|
|
770
|
+
worker_mcp_grant: MCP_GRANT_QUESTION,
|
|
771
|
+
epic_server: EPIC_SERVER_QUESTION,
|
|
772
|
+
epic_branch_ci: "Should each piece of epic work wait for your CI checks before it merges into the epic branch?",
|
|
773
|
+
approval_exemption: "Should setup change your GitHub rule so epic work can merge into the epic branch without a person approving each merge?",
|
|
774
|
+
launch_profile: "Should setup save these launch settings so later runs can reuse them?",
|
|
775
|
+
epic_ci_change: "Should setup open a pull request so your checks also run on pull requests into epic branches?",
|
|
776
|
+
});
|
|
777
|
+
/** Place the choice's question right after its answer key. */
|
|
778
|
+
function withQuestion(c) {
|
|
779
|
+
const { id, family, answer_key, ...rest } = c;
|
|
780
|
+
return { id, family, answer_key, question: CHOICE_QUESTION[answer_key], ...rest };
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* BAPI-1659 — the one answer-aware place where `epic_branch_ci` is recommended.
|
|
784
|
+
*
|
|
785
|
+
* `include` is recommended only when checks are confirmed to run on epic-branch
|
|
786
|
+
* pull requests, an approved CI change will add them, or an approved setup pull
|
|
787
|
+
* request genuinely adds Bridge's workflow. A declined, kept, duplicate-only, or
|
|
788
|
+
* unanswered-and-not-recommended delivery earns no credit. An unanswered
|
|
789
|
+
* delivery choice counts as its own recommendation, so the draft proposal reads
|
|
790
|
+
* as a proposal; a stated answer always wins. Only `recommended` and its reason
|
|
791
|
+
* change, and only when the choice carries a recommendation at all.
|
|
792
|
+
*/
|
|
793
|
+
export function resolveEpicBranchCiRecommendation(choices, settled, context = { setupSuppliesWorkflow: false }) {
|
|
794
|
+
const ci = choiceFor(choices, "epic_branch_ci");
|
|
795
|
+
if (ci === undefined || ci.recommended === null || typeof ci.recommended !== "string")
|
|
796
|
+
return [...choices];
|
|
797
|
+
const picked = (key) => {
|
|
798
|
+
const c = choiceFor(choices, key);
|
|
799
|
+
if (c === undefined || !c.applicable)
|
|
800
|
+
return undefined;
|
|
801
|
+
return settled(key) ?? (typeof c.recommended === "string" ? c.recommended : undefined);
|
|
802
|
+
};
|
|
803
|
+
const covers = ci.current === "covers";
|
|
804
|
+
const ciApproved = picked("epic_ci_change") === "approve";
|
|
805
|
+
const setupApproved = context.setupSuppliesWorkflow && picked("setup_pr") === "approve";
|
|
806
|
+
const delivered = ciApproved || setupApproved;
|
|
807
|
+
const target = covers || delivered ? "include" : "decline";
|
|
808
|
+
if (target === ci.recommended)
|
|
809
|
+
return [...choices];
|
|
810
|
+
const next = target === "include"
|
|
811
|
+
? {
|
|
812
|
+
...ci,
|
|
813
|
+
recommended: "include",
|
|
814
|
+
why_recommended: context.stateText !== undefined && context.stateText !== null && context.stateText.length > 0
|
|
815
|
+
? `${context.stateText} Including lets each child wait for those checks once the change is merged.`
|
|
816
|
+
: "Checks are proposed, not running yet: the pull request you approve adds them, and each child waits for them only once you merge it.",
|
|
817
|
+
}
|
|
818
|
+
: { ...ci, recommended: "decline" };
|
|
819
|
+
return choices.map((c) => (c.answer_key === "epic_branch_ci" ? finalizeRecommendation(next) : c));
|
|
820
|
+
}
|
|
821
|
+
/** Build the full choice catalog. Every family appears, applicable or not. */
|
|
822
|
+
export function buildInstallChoices(d) {
|
|
823
|
+
const declarations = new Map(d.declarations.map((entry) => [entry.key, entry]));
|
|
824
|
+
const choices = [
|
|
825
|
+
gateChoice(d.gate),
|
|
826
|
+
declarationChoice("dependency_install", declarations.get("dependency_install")),
|
|
827
|
+
declarationChoice("ci_database", declarations.get("ci_database")),
|
|
828
|
+
declarationChoice("must_order_paths", declarations.get("must_order_paths")),
|
|
829
|
+
declarationChoice("worker_database", declarations.get("worker_database")),
|
|
830
|
+
testCommandChoice(d.testCommand),
|
|
831
|
+
setupPrChoice(d.setupPr),
|
|
832
|
+
mergeTokenChoice(d.mergeToken),
|
|
833
|
+
...reindexChoices(d.reindex),
|
|
834
|
+
mcpGrantChoice(d.mcpGrant),
|
|
835
|
+
epicServerChoice(d.epicServer),
|
|
836
|
+
...epicBranchCiChoices(d.epicBranchCi),
|
|
837
|
+
launchProfileChoice(d.launchProfile),
|
|
838
|
+
];
|
|
839
|
+
// BAPI-1654: the CI change is conditional, appended last so every other choice keeps its place.
|
|
840
|
+
const ciChange = epicCiChangeChoice(d.epicBranchCi);
|
|
841
|
+
if (ciChange !== null)
|
|
842
|
+
choices.push(ciChange);
|
|
843
|
+
const built = choices.map((c) => finalizeRecommendation(withQuestion(c)));
|
|
844
|
+
// The draft resolves against the complete proposed selection set (recommended approvals as proposals).
|
|
845
|
+
return resolveEpicBranchCiRecommendation(built, () => undefined, {
|
|
846
|
+
setupSuppliesWorkflow: d.epicBranchCi?.managedWorkflowViaSetupPr === true,
|
|
847
|
+
stateText: epicBranchCiStateText(d.epicBranchCi ?? null),
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
export const EMPTY_REPOSITORY_FACTS = Object.freeze({
|
|
851
|
+
ci_workflows: null,
|
|
852
|
+
package_manager: null,
|
|
853
|
+
mcp_configs: null,
|
|
854
|
+
});
|
|
855
|
+
/** Copy repository facts through a fixed shape: names, origins, and filters only. */
|
|
856
|
+
function projectFacts(facts) {
|
|
857
|
+
return {
|
|
858
|
+
ci_workflows: facts.ci_workflows?.map((w) => ({
|
|
859
|
+
path: String(w.path),
|
|
860
|
+
pull_request_branches: w.pull_request_branches === null ? null : w.pull_request_branches.map(String),
|
|
861
|
+
})) ?? null,
|
|
862
|
+
package_manager: facts.package_manager === null
|
|
863
|
+
? null
|
|
864
|
+
: { name: String(facts.package_manager.name), lockfile: facts.package_manager.lockfile === null ? null : String(facts.package_manager.lockfile) },
|
|
865
|
+
mcp_configs: facts.mcp_configs?.map((c) => ({ name: String(c.name), origin: String(c.origin) })) ?? null,
|
|
866
|
+
// BAPI-1654: additive, and only when detection ran, so older inputs keep their exact facts.
|
|
867
|
+
...(facts.ci_systems !== undefined
|
|
868
|
+
? { ci_systems: facts.ci_systems === null ? null : facts.ci_systems.map((c) => ({ name: String(c.name), path: String(c.path) })) }
|
|
869
|
+
: {}),
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
/** The choice for a key, or undefined. */
|
|
873
|
+
export function choiceFor(choices, key) {
|
|
874
|
+
return choices.find((c) => c.answer_key === key);
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Build the schema version 2 document. The version 1 fields are copied as they
|
|
878
|
+
* were, with the same meaning and optionality: `assessment` and
|
|
879
|
+
* `advisoryVerdict` appear only when the run produced them.
|
|
880
|
+
*/
|
|
881
|
+
export function buildInstallAssessment(input) {
|
|
882
|
+
const { legacy } = input;
|
|
883
|
+
return {
|
|
884
|
+
schemaVersion: INSTALL_ASSESSMENT_SCHEMA_VERSION,
|
|
885
|
+
outcome: legacy.outcome,
|
|
886
|
+
exitCode: legacy.exitCode,
|
|
887
|
+
dryRun: legacy.dryRun,
|
|
888
|
+
...(legacy.namedOutcome !== undefined ? { namedOutcome: legacy.namedOutcome } : {}),
|
|
889
|
+
...(legacy.assessment !== undefined ? { assessment: legacy.assessment } : {}),
|
|
890
|
+
...(legacy.advisoryVerdict !== undefined ? { advisoryVerdict: legacy.advisoryVerdict } : {}),
|
|
891
|
+
items: input.items.map(projectItem),
|
|
892
|
+
choices: input.choices !== undefined ? [...input.choices] : input.decisions === null ? [] : buildInstallChoices(input.decisions),
|
|
893
|
+
repository_facts: projectFacts(input.decisions?.repositoryFacts ?? EMPTY_REPOSITORY_FACTS),
|
|
894
|
+
};
|
|
895
|
+
}
|