@bridge_gpt/mcp-server 0.2.69 → 0.2.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The converging setup model for `install conductor` (BAPI-1461).
|
|
3
|
+
*
|
|
4
|
+
* Setup is no longer a fixed list of phases. It is:
|
|
5
|
+
*
|
|
6
|
+
* check everything (read-only) → fix only what is missing, in order →
|
|
7
|
+
* check again → print one verdict.
|
|
8
|
+
*
|
|
9
|
+
* This module holds the parts of that loop that do not touch the terminal: the
|
|
10
|
+
* readiness items, the projection of evidence onto them, the dependency-aware
|
|
11
|
+
* fix planner, the managed setup pull request and index reads, and the final
|
|
12
|
+
* rendering. Every effect is an injected seam; nothing here prompts or writes.
|
|
13
|
+
*
|
|
14
|
+
* Items reuse the shared readiness catalog's ids and labels, so each item has
|
|
15
|
+
* one name everywhere it appears. The server's own readiness prerequisites are
|
|
16
|
+
* the base list; local evidence (sign-ins, the merge token, the setup pull
|
|
17
|
+
* request, indexing) refines the item it belongs to instead of adding a second
|
|
18
|
+
* row for the same fact. An unmet blocking item is counted once.
|
|
19
|
+
*/
|
|
20
|
+
import { READINESS_PREREQUISITE_BY_ID, READINESS_PREREQUISITE_CATALOG, } from "./readiness-prerequisites.generated.js";
|
|
21
|
+
import { READINESS_PREREQUISITE_FIXES } from "./printed-remedy-commands.js";
|
|
22
|
+
import { githubSignInRemedy } from "./github-sign-in.js";
|
|
23
|
+
import { EPIC_CI_WORKFLOW_ALL_MANAGED_BRANCHES } from "./epic-ci-workflow-install.js";
|
|
24
|
+
import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
25
|
+
/** The catalog ids setup reports, named once. */
|
|
26
|
+
export const SETUP_ITEM_IDS = Object.freeze({
|
|
27
|
+
claudeLogin: "conductor.claude-login",
|
|
28
|
+
githubSignIn: "conductor.gh-cli",
|
|
29
|
+
mergeCredential: "conductor.merge-credential-capability",
|
|
30
|
+
testCommand: "server.test-command",
|
|
31
|
+
workflows: "server.indexed-workflows",
|
|
32
|
+
escalation: "server.unattended-notify-default",
|
|
33
|
+
supervisorSetup: "server.supervisor-setup",
|
|
34
|
+
supervisorConfig: "server.supervisor-config",
|
|
35
|
+
requiredChecks: "server.supervisor-required-checks",
|
|
36
|
+
repositoryIdentity: "install.identity",
|
|
37
|
+
serverConnectivity: "install.connectivity",
|
|
38
|
+
});
|
|
39
|
+
/** The catalog label for an id, falling back to the id itself. */
|
|
40
|
+
export function catalogLabel(id) {
|
|
41
|
+
return READINESS_PREREQUISITE_BY_ID.get(id)?.label ?? id;
|
|
42
|
+
}
|
|
43
|
+
/** The catalog's position for an id; unknown ids sort last, in arrival order. */
|
|
44
|
+
function catalogIndex(id) {
|
|
45
|
+
const index = READINESS_PREREQUISITE_CATALOG.findIndex((d) => d.id === id);
|
|
46
|
+
return index === -1 ? Number.MAX_SAFE_INTEGER : index;
|
|
47
|
+
}
|
|
48
|
+
/** The printed setup command, used in fixes that point back at setup. */
|
|
49
|
+
export const PRINTED_SETUP_COMMAND = `npx -y ${MCP_PACKAGE_NAME} install conductor`;
|
|
50
|
+
/**
|
|
51
|
+
* The fix for the escalation channel. There is no verification route on the
|
|
52
|
+
* server, so this is a step the person carries out — setup never asks for or
|
|
53
|
+
* sends an email address.
|
|
54
|
+
*/
|
|
55
|
+
export const ESCALATION_EMAIL_REMEDY = "verify the escalation email: declare notify.webhook_url in your run policy, or ask your Bridge " +
|
|
56
|
+
"account administrator to confirm that the account email address receives mail, then re-run setup";
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Projection
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
function fromServerPrerequisite(p, isProduction) {
|
|
61
|
+
if (p.check_status === "met" || p.check_status === "not_applicable") {
|
|
62
|
+
return { id: p.id, label: p.label, state: "met", blocking: p.impact === "blocking", remedy: null };
|
|
63
|
+
}
|
|
64
|
+
const blocking = p.impact === "blocking";
|
|
65
|
+
// On production, a Bridge-hosted (self_host) fact is never the customer's to
|
|
66
|
+
// fix, so it reads as "could not verify — retry", never as server repair advice.
|
|
67
|
+
if (p.scope === "self_host" && isProduction) {
|
|
68
|
+
return {
|
|
69
|
+
id: p.id,
|
|
70
|
+
label: p.label,
|
|
71
|
+
state: "unknown",
|
|
72
|
+
blocking,
|
|
73
|
+
remedy: READINESS_PREREQUISITE_FIXES.retry,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
id: p.id,
|
|
78
|
+
label: p.label,
|
|
79
|
+
state: p.check_status === "unknown" ? "unknown" : "needs_action",
|
|
80
|
+
blocking,
|
|
81
|
+
remedy: p.fix.length > 0 ? p.fix : READINESS_PREREQUISITE_FIXES.retry,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function upsert(items, item) {
|
|
85
|
+
const at = items.findIndex((i) => i.id === item.id);
|
|
86
|
+
if (at === -1)
|
|
87
|
+
items.push(item);
|
|
88
|
+
else
|
|
89
|
+
items[at] = item;
|
|
90
|
+
}
|
|
91
|
+
function local(id, state, blocking, remedy) {
|
|
92
|
+
return { id, label: catalogLabel(id), state, blocking, remedy: state === "met" ? null : remedy };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Project one assessment pass onto the readiness items, in catalog order.
|
|
96
|
+
*
|
|
97
|
+
* Pure. It never derives readiness from a local write or an exit code: a
|
|
98
|
+
* stored command is met only when the read-back saw it, a workflow only when
|
|
99
|
+
* the installer found it identical, and indexing only when the index reached
|
|
100
|
+
* the merge commit.
|
|
101
|
+
*/
|
|
102
|
+
export function projectSetupItems(evidence) {
|
|
103
|
+
const items = [];
|
|
104
|
+
const readiness = evidence.readiness;
|
|
105
|
+
const isProduction = readiness?.is_production === true;
|
|
106
|
+
if (readiness === null) {
|
|
107
|
+
items.push(local(SETUP_ITEM_IDS.serverConnectivity, "unknown", true, "the Bridge API readiness report could not be read; check the URL and your network, then re-run setup"));
|
|
108
|
+
}
|
|
109
|
+
else if (readiness.prerequisites !== undefined) {
|
|
110
|
+
for (const p of readiness.prerequisites) {
|
|
111
|
+
const item = fromServerPrerequisite(p, isProduction);
|
|
112
|
+
if (item !== null)
|
|
113
|
+
items.push(item);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// An older server without the shared prerequisites: the supervisor facts it
|
|
118
|
+
// has always reported stand in for those rows.
|
|
119
|
+
items.push(local(SETUP_ITEM_IDS.supervisorSetup, readiness.supervisor.setup_present ? "met" : "needs_action", true, `re-run setup and accept storing the repository gate and the safe defaults`), local(SETUP_ITEM_IDS.supervisorConfig, readiness.supervisor.config_present ? "met" : "needs_action", true, `re-run setup and accept storing the repository gate and the safe defaults`));
|
|
120
|
+
}
|
|
121
|
+
// --- Sign-ins (read-only, checked first) --------------------------------
|
|
122
|
+
if (evidence.claudeLoggedIn !== null) {
|
|
123
|
+
upsert(items, local(SETUP_ITEM_IDS.claudeLogin, evidence.claudeLoggedIn ? "met" : "needs_action", false, "run `claude login`"));
|
|
124
|
+
}
|
|
125
|
+
upsert(items, local(SETUP_ITEM_IDS.githubSignIn, evidence.githubSignIn === "signed_in" ? "met" : evidence.githubSignIn === "unavailable" ? "unknown" : "needs_action", true, githubSignInRemedy(evidence.githubSignIn)));
|
|
126
|
+
// --- Repository identity ------------------------------------------------
|
|
127
|
+
if (evidence.repositoryIdentity !== "resolved") {
|
|
128
|
+
upsert(items, local(SETUP_ITEM_IDS.repositoryIdentity, "needs_action", true, evidence.repositoryIdentity === "conflict"
|
|
129
|
+
? "this checkout's github.com remote names a different repository than Bridge does; run setup from the matching checkout"
|
|
130
|
+
: "run setup from a checkout whose `origin` remote is the github.com repository"));
|
|
131
|
+
}
|
|
132
|
+
// --- Test command (the stored value, read back) --------------------------
|
|
133
|
+
if (evidence.testCommand.state !== "stored") {
|
|
134
|
+
const existing = items.find((i) => i.id === SETUP_ITEM_IDS.testCommand);
|
|
135
|
+
upsert(items, local(SETUP_ITEM_IDS.testCommand, evidence.testCommand.state === "missing" ? "needs_action" : "unknown", true, evidence.testCommand.state === "missing"
|
|
136
|
+
? "save a test command: re-run setup and give the command that runs your tests"
|
|
137
|
+
: existing?.remedy ?? READINESS_PREREQUISITE_FIXES.retry));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const existing = items.find((i) => i.id === SETUP_ITEM_IDS.testCommand);
|
|
141
|
+
if (existing === undefined)
|
|
142
|
+
upsert(items, local(SETUP_ITEM_IDS.testCommand, "met", true, null));
|
|
143
|
+
}
|
|
144
|
+
// --- Workflow, setup pull request, and indexing --------------------------
|
|
145
|
+
const workflowItem = projectWorkflowItem(evidence, items.find((i) => i.id === SETUP_ITEM_IDS.workflows));
|
|
146
|
+
if (workflowItem !== null)
|
|
147
|
+
upsert(items, workflowItem);
|
|
148
|
+
// --- The gate change the owner declined ---------------------------------
|
|
149
|
+
if (evidence.gateChangeDeclined) {
|
|
150
|
+
upsert(items, local(SETUP_ITEM_IDS.requiredChecks, "needs_action", true, "add the CI workflow check to the repository gate: re-run setup and accept the gate change"));
|
|
151
|
+
}
|
|
152
|
+
// --- Merge credential ----------------------------------------------------
|
|
153
|
+
const merge = projectMergeCredential(evidence.mergeCredential);
|
|
154
|
+
if (merge !== null)
|
|
155
|
+
upsert(items, merge);
|
|
156
|
+
// --- Escalation channel: a fix the person carries out --------------------
|
|
157
|
+
const escalation = items.find((i) => i.id === SETUP_ITEM_IDS.escalation);
|
|
158
|
+
if (escalation !== undefined && escalation.state === "needs_action") {
|
|
159
|
+
upsert(items, { ...escalation, remedy: ESCALATION_EMAIL_REMEDY });
|
|
160
|
+
}
|
|
161
|
+
return items
|
|
162
|
+
.map((item, arrival) => ({ item, arrival }))
|
|
163
|
+
.sort((a, b) => catalogIndex(a.item.id) - catalogIndex(b.item.id) || a.arrival - b.arrival)
|
|
164
|
+
.map(({ item }) => item);
|
|
165
|
+
}
|
|
166
|
+
function projectWorkflowItem(evidence, server) {
|
|
167
|
+
const id = SETUP_ITEM_IDS.workflows;
|
|
168
|
+
const pr = evidence.setupPullRequest;
|
|
169
|
+
switch (evidence.workflow.state) {
|
|
170
|
+
case "pr_open":
|
|
171
|
+
return local(id, "pending", true, `merge the setup PR: ${evidence.workflow.url}`);
|
|
172
|
+
case "needs_pr":
|
|
173
|
+
return local(id, "needs_action", true, "open the setup PR: re-run setup and accept the setup pull request");
|
|
174
|
+
case "blocked":
|
|
175
|
+
return local(id, "needs_action", true, evidence.workflow.remedy);
|
|
176
|
+
case "needs_command":
|
|
177
|
+
return local(id, "needs_action", true, "save a test command first; setup builds the CI workflow from it");
|
|
178
|
+
case "unknown":
|
|
179
|
+
return server ?? local(id, "unknown", true, "the CI workflow could not be checked; re-run setup");
|
|
180
|
+
case "precondition":
|
|
181
|
+
// The local preflight could not run, but a merged setup PR still proves the
|
|
182
|
+
// workflow reached the default branch; then only indexing remains.
|
|
183
|
+
if (server?.state === "met")
|
|
184
|
+
return server;
|
|
185
|
+
if (pr.state !== "merged")
|
|
186
|
+
return local(id, "needs_action", true, evidence.workflow.remedy);
|
|
187
|
+
break;
|
|
188
|
+
case "installed":
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
// The workflow is on the default branch. What remains is indexing.
|
|
192
|
+
if (pr.state === "closed_unmerged") {
|
|
193
|
+
return local(id, "needs_action", true, `the setup PR was closed without merging (${pr.url}); reopen and merge it, or delete the branch ${pr.branch} and re-run setup`);
|
|
194
|
+
}
|
|
195
|
+
switch (evidence.index.state) {
|
|
196
|
+
case "reached":
|
|
197
|
+
// The server's fact can need more than this workflow (for example the
|
|
198
|
+
// review workflow a policy requires), so a local "met" never hides it.
|
|
199
|
+
return server !== undefined && server.state !== "met" ? server : local(id, "met", true, null);
|
|
200
|
+
case "behind":
|
|
201
|
+
return local(id, "needs_action", true, "re-index the repository: re-run setup to queue indexing");
|
|
202
|
+
case "in_progress":
|
|
203
|
+
return local(id, "pending", true, "indexing is running; re-run setup when it finishes");
|
|
204
|
+
case "queued_by_setup":
|
|
205
|
+
return local(id, "pending", true, "indexing was queued; re-run setup when it finishes");
|
|
206
|
+
case "unknown":
|
|
207
|
+
return local(id, "pending", true, "could not confirm the index reached the setup PR; re-run setup later");
|
|
208
|
+
case "not_applicable":
|
|
209
|
+
return server ?? local(id, "met", true, null);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function projectMergeCredential(state) {
|
|
213
|
+
const id = SETUP_ITEM_IDS.mergeCredential;
|
|
214
|
+
switch (state.state) {
|
|
215
|
+
case "not_applicable":
|
|
216
|
+
return null;
|
|
217
|
+
case "configured":
|
|
218
|
+
return local(id, "met", true, null);
|
|
219
|
+
case "missing":
|
|
220
|
+
return local(id, "needs_action", true, "store a GitHub merge token: re-run setup and accept storing it, or set GITHUB_MERGE_TOKEN");
|
|
221
|
+
case "env_invalid":
|
|
222
|
+
return local(id, "needs_action", true, `${state.sourceKey} is set but is not a usable token; fix it or unset it`);
|
|
223
|
+
case "stored_rejected":
|
|
224
|
+
return local(id, "needs_action", true, "the stored merge token was rejected by GitHub; re-run setup to replace it");
|
|
225
|
+
case "machine_missing":
|
|
226
|
+
return local(id, "needs_action", true, "set BAPI_MACHINE_MERGE_TOKEN in the environment the executor starts from");
|
|
227
|
+
case "unknown":
|
|
228
|
+
return local(id, "unknown", true, "the merge token could not be checked right now; re-run setup later");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/** The two fixes that write the stored test command. */
|
|
232
|
+
export function isTestCommandFix(fix) {
|
|
233
|
+
return fix === "save_test_command" || fix === "replace_test_command";
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Pick the permitted fixes for the unmet items, in the order they must run.
|
|
237
|
+
*
|
|
238
|
+
* Pure. Dependencies are explicit:
|
|
239
|
+
* - a missing stored command blocks the workflow PR (it is built from it);
|
|
240
|
+
* - an explicit replacement is planned first and, like a save, can make the
|
|
241
|
+
* workflow PR possible or necessary once its read-back is confirmed;
|
|
242
|
+
* - a GitHub sign-in that is not ready blocks GitHub-dependent fixes (the
|
|
243
|
+
* setup PR), never the Bridge or local ones;
|
|
244
|
+
* - an unresolved repository identity blocks the stored merge token.
|
|
245
|
+
* A fix that is skipped or declined leaves its item outstanding; it never
|
|
246
|
+
* undoes an independent fix that already succeeded.
|
|
247
|
+
*/
|
|
248
|
+
export function planSetupFixes(evidence, context) {
|
|
249
|
+
const fixes = [];
|
|
250
|
+
const githubReady = evidence.githubSignIn === "signed_in";
|
|
251
|
+
// An explicit request outranks the interactive one; the interactive save is
|
|
252
|
+
// kept only for a command that is KNOWN to be missing.
|
|
253
|
+
if (context.replaceTestCommandRequested === true)
|
|
254
|
+
fixes.push("replace_test_command");
|
|
255
|
+
else if (evidence.testCommand.state === "missing")
|
|
256
|
+
fixes.push("save_test_command");
|
|
257
|
+
// Either command fix is a potential dependency of the workflow fix; whether
|
|
258
|
+
// the workflow is then installed depends on the read-back being confirmed.
|
|
259
|
+
const commandAvailable = evidence.testCommand.state === "stored" || fixes.some(isTestCommandFix);
|
|
260
|
+
if (githubReady &&
|
|
261
|
+
commandAvailable &&
|
|
262
|
+
(evidence.workflow.state === "needs_pr" || evidence.workflow.state === "needs_command")) {
|
|
263
|
+
fixes.push("setup_pr");
|
|
264
|
+
}
|
|
265
|
+
if (context.gateOrDefaultsNeedWrite)
|
|
266
|
+
fixes.push("gate_and_defaults");
|
|
267
|
+
if (evidence.repositoryIdentity === "resolved" &&
|
|
268
|
+
(evidence.mergeCredential.state === "missing" || evidence.mergeCredential.state === "stored_rejected")) {
|
|
269
|
+
fixes.push("merge_token");
|
|
270
|
+
}
|
|
271
|
+
if (evidence.index.state === "behind")
|
|
272
|
+
fixes.push("reindex");
|
|
273
|
+
return fixes;
|
|
274
|
+
}
|
|
275
|
+
const SHA_RE = /^[0-9a-f]{40}$/;
|
|
276
|
+
/**
|
|
277
|
+
* Read the managed setup pull request's state through `gh`. Read-only; any
|
|
278
|
+
* unreadable answer is `unknown`, never `none`. It looks at the current managed
|
|
279
|
+
* branches AND the branches earlier published renderer versions used (BAPI-1536),
|
|
280
|
+
* so a version-1 pull request that is still open is seen, not missed. An open PR
|
|
281
|
+
* wins; otherwise the most recently merged one; otherwise a closed, unmerged one.
|
|
282
|
+
*/
|
|
283
|
+
export async function readSetupPullRequest(runGh, repository) {
|
|
284
|
+
const rows = [];
|
|
285
|
+
for (const branch of EPIC_CI_WORKFLOW_ALL_MANAGED_BRANCHES) {
|
|
286
|
+
let result;
|
|
287
|
+
try {
|
|
288
|
+
result = await runGh([
|
|
289
|
+
"pr", "list", "--repo", repository, "--state", "all", "--head", branch,
|
|
290
|
+
"--json", "url,state,mergedAt,mergeCommit,headRefName", "--limit", "10",
|
|
291
|
+
]);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return { state: "unknown" };
|
|
295
|
+
}
|
|
296
|
+
if (result.status !== 0)
|
|
297
|
+
return { state: "unknown" };
|
|
298
|
+
let parsed;
|
|
299
|
+
try {
|
|
300
|
+
parsed = JSON.parse(result.stdout);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return { state: "unknown" };
|
|
304
|
+
}
|
|
305
|
+
if (!Array.isArray(parsed))
|
|
306
|
+
return { state: "unknown" };
|
|
307
|
+
rows.push(...parsed);
|
|
308
|
+
}
|
|
309
|
+
const str = (v) => (typeof v === "string" && v.length > 0 ? v : null);
|
|
310
|
+
const open = rows.find((r) => r.state === "OPEN" && str(r.url) && str(r.headRefName));
|
|
311
|
+
if (open)
|
|
312
|
+
return { state: "open", url: str(open.url), branch: str(open.headRefName) };
|
|
313
|
+
const merged = rows
|
|
314
|
+
.filter((r) => r.state === "MERGED" && str(r.url) && typeof r.mergeCommit?.oid === "string")
|
|
315
|
+
.sort((a, b) => String(b.mergedAt ?? "").localeCompare(String(a.mergedAt ?? "")));
|
|
316
|
+
if (merged.length > 0) {
|
|
317
|
+
const sha = String(merged[0].mergeCommit.oid).toLowerCase();
|
|
318
|
+
if (!SHA_RE.test(sha))
|
|
319
|
+
return { state: "unknown" };
|
|
320
|
+
return { state: "merged", url: str(merged[0].url), mergeCommitSha: sha };
|
|
321
|
+
}
|
|
322
|
+
const closed = rows.find((r) => r.state === "CLOSED" && str(r.url) && str(r.headRefName));
|
|
323
|
+
if (closed)
|
|
324
|
+
return { state: "closed_unmerged", url: str(closed.url), branch: str(closed.headRefName) };
|
|
325
|
+
return { state: "none" };
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Whether `indexed` contains `merge`: equal SHAs, or GitHub's compare reports
|
|
329
|
+
* the indexed commit `identical` to or `ahead` of the merge commit. Any other
|
|
330
|
+
* answer, or no answer, is `unknown` (never `behind` by guess) except an
|
|
331
|
+
* explicit `behind`/`diverged`.
|
|
332
|
+
*/
|
|
333
|
+
export async function compareIndexedToMerge(runGh, repository, mergeSha, indexedSha) {
|
|
334
|
+
if (mergeSha === indexedSha)
|
|
335
|
+
return "reached";
|
|
336
|
+
if (!SHA_RE.test(mergeSha) || !SHA_RE.test(indexedSha))
|
|
337
|
+
return "unknown";
|
|
338
|
+
let result;
|
|
339
|
+
try {
|
|
340
|
+
result = await runGh(["api", `repos/${repository}/compare/${mergeSha}...${indexedSha}`, "--jq", ".status"]);
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return "unknown";
|
|
344
|
+
}
|
|
345
|
+
if (result.status !== 0)
|
|
346
|
+
return "unknown";
|
|
347
|
+
const status = result.stdout.trim();
|
|
348
|
+
if (status === "identical" || status === "ahead")
|
|
349
|
+
return "reached";
|
|
350
|
+
if (status === "behind" || status === "diverged")
|
|
351
|
+
return "behind";
|
|
352
|
+
return "unknown";
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Decide the index state for a merged setup PR from one parse-status read.
|
|
356
|
+
* Never queues anything.
|
|
357
|
+
*/
|
|
358
|
+
export async function assessSetupIndex(pr, readParseStatus, compare) {
|
|
359
|
+
if (pr.state !== "merged")
|
|
360
|
+
return { state: "not_applicable" };
|
|
361
|
+
let status;
|
|
362
|
+
try {
|
|
363
|
+
status = await readParseStatus();
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return { state: "unknown" };
|
|
367
|
+
}
|
|
368
|
+
if (status.status === "queued" || status.status === "in_progress")
|
|
369
|
+
return { state: "in_progress" };
|
|
370
|
+
if (status.status === "idle")
|
|
371
|
+
return { state: "behind" };
|
|
372
|
+
const indexed = typeof status.indexed_commit_sha === "string" ? status.indexed_commit_sha.toLowerCase() : null;
|
|
373
|
+
if (indexed === null) {
|
|
374
|
+
// A failed run left no indexed commit; a succeeded run with an unknown
|
|
375
|
+
// commit cannot be compared, so it stays pending rather than re-queued.
|
|
376
|
+
return status.status === "failed" ? { state: "behind" } : { state: "unknown" };
|
|
377
|
+
}
|
|
378
|
+
const verdict = await compare(pr.mergeCommitSha, indexed);
|
|
379
|
+
return verdict === "reached" ? { state: "reached" } : verdict === "behind" ? { state: "behind" } : { state: "unknown" };
|
|
380
|
+
}
|
|
381
|
+
// ---------------------------------------------------------------------------
|
|
382
|
+
// Rendering
|
|
383
|
+
// ---------------------------------------------------------------------------
|
|
384
|
+
const STATE_WORD = Object.freeze({
|
|
385
|
+
met: "ready",
|
|
386
|
+
needs_action: "needs action",
|
|
387
|
+
pending: "pending",
|
|
388
|
+
unknown: "could not verify",
|
|
389
|
+
});
|
|
390
|
+
/** Blocking items that are not met, each counted once. */
|
|
391
|
+
export function unmetBlockingItems(items) {
|
|
392
|
+
const seen = new Set();
|
|
393
|
+
return items.filter((item) => {
|
|
394
|
+
if (!item.blocking || item.state === "met" || seen.has(item.id))
|
|
395
|
+
return false;
|
|
396
|
+
seen.add(item.id);
|
|
397
|
+
return true;
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/** The verdict line. Ready only when every blocking item is positively met. */
|
|
401
|
+
export function setupVerdictLine(items) {
|
|
402
|
+
const left = unmetBlockingItems(items).length;
|
|
403
|
+
return left === 0 ? "Ready for your first epic" : `Not ready: ${left} step${left === 1 ? "" : "s"} left`;
|
|
404
|
+
}
|
|
405
|
+
/** Render the assessment: a status list, then one fix per unmet blocking item. */
|
|
406
|
+
export function renderSetupAssessment(items, heading) {
|
|
407
|
+
const lines = ["", heading];
|
|
408
|
+
const width = Math.max(...Object.values(STATE_WORD).map((w) => w.length));
|
|
409
|
+
for (const item of items) {
|
|
410
|
+
if (!item.blocking && item.state === "met")
|
|
411
|
+
continue;
|
|
412
|
+
const word = STATE_WORD[item.state].padEnd(width);
|
|
413
|
+
lines.push(` ${word} ${item.label}${item.blocking ? "" : " (advisory)"}`);
|
|
414
|
+
}
|
|
415
|
+
const unmet = unmetBlockingItems(items);
|
|
416
|
+
if (unmet.length > 0) {
|
|
417
|
+
lines.push("", "Steps left");
|
|
418
|
+
unmet.forEach((item, index) => lines.push(` ${index + 1}. ${item.label}: ${item.remedy ?? READINESS_PREREQUISITE_FIXES.retry}`));
|
|
419
|
+
}
|
|
420
|
+
const advisories = items.filter((i) => !i.blocking && i.state !== "met" && i.remedy !== null);
|
|
421
|
+
if (advisories.length > 0) {
|
|
422
|
+
lines.push("", "Also worth doing (advisory)");
|
|
423
|
+
for (const item of advisories)
|
|
424
|
+
lines.push(` - ${item.label}: ${item.remedy}`);
|
|
425
|
+
}
|
|
426
|
+
return lines;
|
|
427
|
+
}
|