@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,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1506 — read-only launch-need probes for the `drive-epic` create preview.
|
|
3
|
+
*
|
|
4
|
+
* Two probes live here: whether every self-hosted label set behind the
|
|
5
|
+
* repository's required checks has an online runner, and how far the epic
|
|
6
|
+
* branch is behind its base. Both are bookkeeping reads (design principle 5):
|
|
7
|
+
* every subprocess has a bounded timeout, and every failure, timeout, missing
|
|
8
|
+
* tool, or unreadable output becomes `unverifiable`. Nothing here can refuse a
|
|
9
|
+
* launch, and nothing from a subprocess, a workflow file, or a path reaches the
|
|
10
|
+
* returned facts — only closed classifications and bounded counts.
|
|
11
|
+
*/
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
14
|
+
import { validateBranchName } from "../base-ref.js";
|
|
15
|
+
import { PLANE_FRESHNESS_TIMEOUT_MS } from "../plane/plane-freshness.js";
|
|
16
|
+
/** One deadline for the whole runner probe, however many pages it reads. */
|
|
17
|
+
export const LAUNCH_RUNNER_PROBE_DEADLINE_MS = PLANE_FRESHNESS_TIMEOUT_MS;
|
|
18
|
+
/** Bound on each git read the behind-base probe runs. */
|
|
19
|
+
export const LAUNCH_BRANCH_PROBE_TIMEOUT_MS = PLANE_FRESHNESS_TIMEOUT_MS;
|
|
20
|
+
const RUNNER_PAGE_SIZE = 100;
|
|
21
|
+
const RUNNER_MAX_PAGES = 10;
|
|
22
|
+
const WORKFLOW_MAX_FILES = 200;
|
|
23
|
+
const WORKFLOW_MAX_BYTES = 512 * 1024;
|
|
24
|
+
export function createWorkflowSource() {
|
|
25
|
+
return {
|
|
26
|
+
list: (dir) => readdir(dir),
|
|
27
|
+
read: async (file) => {
|
|
28
|
+
const entry = await stat(file);
|
|
29
|
+
if (!entry.isFile() || entry.size > WORKFLOW_MAX_BYTES)
|
|
30
|
+
throw new Error("workflow unreadable");
|
|
31
|
+
return readFile(file, "utf8");
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function stripComment(value) {
|
|
36
|
+
// A `#` starts a comment only at the start or after whitespace, outside quotes.
|
|
37
|
+
let quote = null;
|
|
38
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
39
|
+
const ch = value[i];
|
|
40
|
+
if (quote !== null) {
|
|
41
|
+
if (ch === quote)
|
|
42
|
+
quote = null;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (ch === "'" || ch === '"')
|
|
46
|
+
quote = ch;
|
|
47
|
+
else if (ch === "#" && (i === 0 || /\s/.test(value[i - 1] ?? "")))
|
|
48
|
+
return value.slice(0, i);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function unquote(value) {
|
|
53
|
+
const v = value.trim();
|
|
54
|
+
if (v.length >= 2 && ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")))) {
|
|
55
|
+
return v.slice(1, -1);
|
|
56
|
+
}
|
|
57
|
+
if (/^["']/.test(v) || /["']$/.test(v))
|
|
58
|
+
return null;
|
|
59
|
+
return v;
|
|
60
|
+
}
|
|
61
|
+
function plainScalar(raw) {
|
|
62
|
+
const value = stripComment(raw).trim();
|
|
63
|
+
if (value === "" || value.includes("${{") || /^[|>&*!{[]/.test(value))
|
|
64
|
+
return null;
|
|
65
|
+
const text = unquote(value);
|
|
66
|
+
return text === null || text === "" ? null : text;
|
|
67
|
+
}
|
|
68
|
+
function runsOnLabels(raw) {
|
|
69
|
+
const value = stripComment(raw).trim();
|
|
70
|
+
if (value === "" || value.includes("${{"))
|
|
71
|
+
return null;
|
|
72
|
+
if (value.startsWith("[")) {
|
|
73
|
+
if (!value.endsWith("]"))
|
|
74
|
+
return null;
|
|
75
|
+
const inner = value.slice(1, -1).trim();
|
|
76
|
+
if (inner === "")
|
|
77
|
+
return null;
|
|
78
|
+
const labels = [];
|
|
79
|
+
for (const part of inner.split(",")) {
|
|
80
|
+
const label = unquote(part);
|
|
81
|
+
if (label === null || label === "" || /[[\]{}:]/.test(label))
|
|
82
|
+
return null;
|
|
83
|
+
labels.push(label);
|
|
84
|
+
}
|
|
85
|
+
return labels;
|
|
86
|
+
}
|
|
87
|
+
const label = plainScalar(value);
|
|
88
|
+
return label === null ? null : [label];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Read the jobs out of one workflow file. A deliberately small reader: it
|
|
92
|
+
* understands only the top-level `jobs:` mapping and, inside each job, the
|
|
93
|
+
* `name:` and `runs-on:` keys at the job's own indent. Anything it cannot read
|
|
94
|
+
* plainly is reported as unreadable rather than guessed.
|
|
95
|
+
*/
|
|
96
|
+
export function parseWorkflowJobs(text) {
|
|
97
|
+
const lines = text.split(/\r?\n/);
|
|
98
|
+
const jobs = [];
|
|
99
|
+
let inJobs = false;
|
|
100
|
+
let jobIndent = null;
|
|
101
|
+
let current = null;
|
|
102
|
+
const flush = () => {
|
|
103
|
+
if (current !== null) {
|
|
104
|
+
jobs.push({ id: current.id, name: current.name, nameUnreadable: current.nameUnreadable, runsOn: current.runsOn });
|
|
105
|
+
}
|
|
106
|
+
current = null;
|
|
107
|
+
};
|
|
108
|
+
for (const line of lines) {
|
|
109
|
+
if (line.trim() === "" || line.trimStart().startsWith("#"))
|
|
110
|
+
continue;
|
|
111
|
+
const indent = line.length - line.trimStart().length;
|
|
112
|
+
if (indent === 0) {
|
|
113
|
+
flush();
|
|
114
|
+
inJobs = /^jobs:\s*(#.*)?$/.test(line);
|
|
115
|
+
jobIndent = null;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!inJobs)
|
|
119
|
+
continue;
|
|
120
|
+
if (jobIndent === null)
|
|
121
|
+
jobIndent = indent;
|
|
122
|
+
if (indent < jobIndent)
|
|
123
|
+
continue;
|
|
124
|
+
if (indent === jobIndent) {
|
|
125
|
+
flush();
|
|
126
|
+
const match = /^\s*(["']?)([A-Za-z_][A-Za-z0-9_-]*)\1:\s*(#.*)?$/.exec(line);
|
|
127
|
+
if (match !== null) {
|
|
128
|
+
current = { id: match[2], name: null, nameUnreadable: false, runsOn: null, propIndent: null };
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (current === null)
|
|
133
|
+
continue;
|
|
134
|
+
const job = current;
|
|
135
|
+
if (job.propIndent === null)
|
|
136
|
+
job.propIndent = indent;
|
|
137
|
+
if (indent !== job.propIndent)
|
|
138
|
+
continue;
|
|
139
|
+
const key = /^\s*([A-Za-z_-]+):(.*)$/.exec(line);
|
|
140
|
+
if (key === null)
|
|
141
|
+
continue;
|
|
142
|
+
if (key[1] === "name") {
|
|
143
|
+
const name = plainScalar(key[2] ?? "");
|
|
144
|
+
if (name === null)
|
|
145
|
+
job.nameUnreadable = true;
|
|
146
|
+
else
|
|
147
|
+
job.name = name;
|
|
148
|
+
}
|
|
149
|
+
else if (key[1] === "runs-on") {
|
|
150
|
+
job.runsOn = runsOnLabels(key[2] ?? "");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
flush();
|
|
154
|
+
return jobs;
|
|
155
|
+
}
|
|
156
|
+
function parseRunnerPage(stdout) {
|
|
157
|
+
let body;
|
|
158
|
+
try {
|
|
159
|
+
body = JSON.parse(stdout);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
165
|
+
return null;
|
|
166
|
+
const { total_count: total, runners } = body;
|
|
167
|
+
if (typeof total !== "number" || !Number.isSafeInteger(total) || total < 0 || !Array.isArray(runners))
|
|
168
|
+
return null;
|
|
169
|
+
const out = [];
|
|
170
|
+
for (const runner of runners) {
|
|
171
|
+
if (runner === null || typeof runner !== "object")
|
|
172
|
+
return null;
|
|
173
|
+
const { status, labels } = runner;
|
|
174
|
+
if (typeof status !== "string" || !Array.isArray(labels))
|
|
175
|
+
return null;
|
|
176
|
+
const names = new Set();
|
|
177
|
+
for (const label of labels) {
|
|
178
|
+
const name = label?.name;
|
|
179
|
+
if (typeof name !== "string" || name === "")
|
|
180
|
+
return null;
|
|
181
|
+
names.add(name.toLowerCase());
|
|
182
|
+
}
|
|
183
|
+
out.push({ online: status === "online", labels: names });
|
|
184
|
+
}
|
|
185
|
+
return { total, runners: out };
|
|
186
|
+
}
|
|
187
|
+
const PROVIDER_REPOSITORY = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]{1,100}$/;
|
|
188
|
+
/**
|
|
189
|
+
* Whether every self-hosted label set behind the required checks has an
|
|
190
|
+
* online runner. Reads only the jobs behind `gate_profile.provider_checks`.
|
|
191
|
+
* NEVER throws.
|
|
192
|
+
*/
|
|
193
|
+
export async function inspectRequiredSelfHostedRunners(input) {
|
|
194
|
+
try {
|
|
195
|
+
return await probeRunners(input);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return { state: "unverifiable", reason: "probe_failed" };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function probeRunners(input) {
|
|
202
|
+
const now = input.now ?? Date.now;
|
|
203
|
+
const deadline = now() + LAUNCH_RUNNER_PROBE_DEADLINE_MS;
|
|
204
|
+
// Every workflow job, from both `.yml` and `.yaml` files.
|
|
205
|
+
const dir = path.join(input.repoRoot, ".github", "workflows");
|
|
206
|
+
let files;
|
|
207
|
+
try {
|
|
208
|
+
files = (await input.workflows.list(dir)).filter((file) => /\.ya?ml$/.test(file)).sort();
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
const code = error.code;
|
|
212
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
213
|
+
return { state: "not_applicable", reason: "no_github_actions_workflows" };
|
|
214
|
+
return { state: "unverifiable", reason: "workflows_unreadable" };
|
|
215
|
+
}
|
|
216
|
+
if (files.length > WORKFLOW_MAX_FILES)
|
|
217
|
+
return { state: "unverifiable", reason: "workflows_unreadable" };
|
|
218
|
+
if (files.length === 0)
|
|
219
|
+
return { state: "not_applicable", reason: "no_github_actions_workflows" };
|
|
220
|
+
const profile = input.gateProfile;
|
|
221
|
+
if (profile === null || profile === undefined || profile.read_failed || !Array.isArray(profile.provider_checks)) {
|
|
222
|
+
return { state: "unverifiable", reason: "no_gate_profile" };
|
|
223
|
+
}
|
|
224
|
+
const required = profile.provider_checks
|
|
225
|
+
.map((check) => check.name)
|
|
226
|
+
.filter((name) => typeof name === "string" && name !== "");
|
|
227
|
+
if (required.length !== profile.provider_checks.length) {
|
|
228
|
+
return { state: "unverifiable", reason: "no_gate_profile" };
|
|
229
|
+
}
|
|
230
|
+
if (required.length === 0)
|
|
231
|
+
return { state: "not_applicable" };
|
|
232
|
+
const jobs = [];
|
|
233
|
+
for (const file of files) {
|
|
234
|
+
try {
|
|
235
|
+
jobs.push(...parseWorkflowJobs(await input.workflows.read(path.join(dir, file))));
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return { state: "unverifiable", reason: "workflows_unreadable" };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Map each required check to exactly one job: its literal name, else its id.
|
|
242
|
+
const labelSets = new Map();
|
|
243
|
+
for (const check of new Set(required)) {
|
|
244
|
+
const matches = jobs.filter((job) => (job.name ?? (job.nameUnreadable ? null : job.id)) === check);
|
|
245
|
+
if (matches.length !== 1) {
|
|
246
|
+
return { state: "unverifiable", reason: "check_not_mapped" };
|
|
247
|
+
}
|
|
248
|
+
const runsOn = matches[0]?.runsOn ?? null;
|
|
249
|
+
if (runsOn === null)
|
|
250
|
+
return { state: "unverifiable", reason: "runs_on_unreadable" };
|
|
251
|
+
const lowered = runsOn.map((label) => label.toLowerCase());
|
|
252
|
+
if (!lowered.includes("self-hosted"))
|
|
253
|
+
continue;
|
|
254
|
+
const key = [...new Set(lowered)].sort().join("\u0000");
|
|
255
|
+
labelSets.set(key, [...new Set(lowered)]);
|
|
256
|
+
}
|
|
257
|
+
if (labelSets.size === 0)
|
|
258
|
+
return { state: "not_applicable" };
|
|
259
|
+
const repository = input.providerRepository;
|
|
260
|
+
if (typeof repository !== "string" || !PROVIDER_REPOSITORY.test(repository)) {
|
|
261
|
+
return { state: "unverifiable", reason: "no_provider_repository" };
|
|
262
|
+
}
|
|
263
|
+
// A complete runner listing, page by page, inside the one deadline.
|
|
264
|
+
const runners = [];
|
|
265
|
+
let total = null;
|
|
266
|
+
for (let page = 1; page <= RUNNER_MAX_PAGES; page += 1) {
|
|
267
|
+
const remaining = deadline - now();
|
|
268
|
+
if (remaining <= 0)
|
|
269
|
+
return { state: "unverifiable", reason: "runner_list_unavailable" };
|
|
270
|
+
const result = await input.execFile("gh", ["api", `repos/${repository}/actions/runners?per_page=${RUNNER_PAGE_SIZE}&page=${page}`], { cwd: input.repoRoot, timeoutMs: remaining, env: { GH_PROMPT_DISABLED: "1" } });
|
|
271
|
+
if (!result.ok)
|
|
272
|
+
return { state: "unverifiable", reason: "runner_list_unavailable" };
|
|
273
|
+
const parsed = parseRunnerPage(result.stdout);
|
|
274
|
+
if (parsed === null)
|
|
275
|
+
return { state: "unverifiable", reason: "runner_list_malformed" };
|
|
276
|
+
if (total === null)
|
|
277
|
+
total = parsed.total;
|
|
278
|
+
else if (total !== parsed.total)
|
|
279
|
+
return { state: "unverifiable", reason: "runner_list_malformed" };
|
|
280
|
+
runners.push(...parsed.runners);
|
|
281
|
+
if (runners.length >= total)
|
|
282
|
+
break;
|
|
283
|
+
if (parsed.runners.length === 0)
|
|
284
|
+
return { state: "unverifiable", reason: "runner_list_malformed" };
|
|
285
|
+
}
|
|
286
|
+
if (total === null || runners.length !== total)
|
|
287
|
+
return { state: "unverifiable", reason: "runner_list_malformed" };
|
|
288
|
+
let unsatisfied = 0;
|
|
289
|
+
for (const labels of labelSets.values()) {
|
|
290
|
+
const served = runners.some((runner) => runner.online && labels.every((label) => runner.labels.has(label)));
|
|
291
|
+
if (!served)
|
|
292
|
+
unsatisfied += 1;
|
|
293
|
+
}
|
|
294
|
+
return unsatisfied > 0
|
|
295
|
+
? { state: "present", unsatisfied_label_sets: unsatisfied, label_sets: labelSets.size }
|
|
296
|
+
: { state: "absent", label_sets: labelSets.size };
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* How many commits `origin/<branch>` is behind `origin/<base>`. Information
|
|
300
|
+
* only: integration's `sync_base` merges the base into the epic branch. Uses
|
|
301
|
+
* the remote-tracking refs the preview already has; it fetches nothing.
|
|
302
|
+
* NEVER throws.
|
|
303
|
+
*/
|
|
304
|
+
export async function inspectEpicBranchBehindBase(input) {
|
|
305
|
+
try {
|
|
306
|
+
const { branch, baseBranch } = input;
|
|
307
|
+
if (branch === null || branch === "")
|
|
308
|
+
return { state: "not_applicable", reason: "no_epic_branch" };
|
|
309
|
+
if (baseBranch === null || baseBranch === "")
|
|
310
|
+
return { state: "unverifiable", reason: "no_base_branch" };
|
|
311
|
+
if (validateBranchName(branch) !== null || validateBranchName(baseBranch) !== null) {
|
|
312
|
+
return { state: "unverifiable", reason: "invalid_branch_name" };
|
|
313
|
+
}
|
|
314
|
+
if (branch === baseBranch)
|
|
315
|
+
return { state: "not_applicable", reason: "no_epic_branch" };
|
|
316
|
+
const git = (args) => input.execFile("git", args, {
|
|
317
|
+
cwd: input.repoRoot,
|
|
318
|
+
timeoutMs: LAUNCH_BRANCH_PROBE_TIMEOUT_MS,
|
|
319
|
+
env: { GIT_TERMINAL_PROMPT: "0" },
|
|
320
|
+
});
|
|
321
|
+
// `for-each-ref` exits 0 with no output for a ref that does not exist, so a
|
|
322
|
+
// missing branch is told apart from a git failure.
|
|
323
|
+
const ref = `refs/remotes/origin/${branch}`;
|
|
324
|
+
const listed = await git(["for-each-ref", "--format=%(refname)", ref]);
|
|
325
|
+
if (!listed.ok)
|
|
326
|
+
return { state: "unverifiable", reason: "git_failed" };
|
|
327
|
+
if (!listed.stdout.split(/\r?\n/).some((line) => line.trim() === ref)) {
|
|
328
|
+
return { state: "not_applicable", reason: "branch_not_on_origin" };
|
|
329
|
+
}
|
|
330
|
+
const counted = await git(["rev-list", "--count", `refs/remotes/origin/${branch}..refs/remotes/origin/${baseBranch}`]);
|
|
331
|
+
if (!counted.ok)
|
|
332
|
+
return { state: "unverifiable", reason: "git_failed" };
|
|
333
|
+
const text = counted.stdout.trim();
|
|
334
|
+
if (!/^\d{1,9}$/.test(text))
|
|
335
|
+
return { state: "unverifiable", reason: "git_failed" };
|
|
336
|
+
const behind = Number.parseInt(text, 10);
|
|
337
|
+
return behind === 0 ? { state: "absent" } : { state: "present", behind };
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return { state: "unverifiable", reason: "git_failed" };
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { EPIC_KEY_PATTERN } from "../drive-epic-key.js";
|
|
2
|
+
import { ESCALATION_REACHABILITY_CHECK_ID } from "../escalation-reachability.js";
|
|
3
|
+
import { LAUNCH_NEEDS, LAUNCH_NEED_ROW_IDS, LAUNCH_NEED_REMEDIES } from "./readiness-sections.js";
|
|
4
|
+
import { WORKER_DATABASE_DOCTOR_OWNER, WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION } from "./doctor.js";
|
|
5
|
+
import { normalizeRepoRelativePath } from "./file-scope-guard.js";
|
|
6
|
+
/**
|
|
7
|
+
* Advisory decision table (source order within each group):
|
|
8
|
+
* reachability unconfirmed | proceed | [] | fix the channel before retrying
|
|
9
|
+
* probably_done child | run it | [] | skip: [--skip-child, KEY]
|
|
10
|
+
* applicable relevant role / other unhealthy DB | fix first | [] | launch anyway: []
|
|
11
|
+
* asked/present runner | fix first | [] | launch anyway: []
|
|
12
|
+
* asked/present power | proceed, keep the lid open | [] | fix first: []
|
|
13
|
+
* asked/present usage | proceed | [] | fix first: []
|
|
14
|
+
* Fix-first acceptance accepts unresolved risk; it never performs remediation.
|
|
15
|
+
* verification_gap belongs exclusively to the command session, not this union.
|
|
16
|
+
*/
|
|
17
|
+
/** Bridge-specific hints are consulted only after positive repository applicability. */
|
|
18
|
+
export const DB_OR_HARNESS_PATH_HINTS = ["db/alembic/", "tests/integration/conductor_harness/", "migrations/"];
|
|
19
|
+
export function planDatabaseRelevance(nodes, applicable) {
|
|
20
|
+
if (!applicable || !Array.isArray(nodes))
|
|
21
|
+
return "unknown";
|
|
22
|
+
let declared = false;
|
|
23
|
+
let malformed = false;
|
|
24
|
+
let relevant = false;
|
|
25
|
+
for (const node of nodes) {
|
|
26
|
+
if (!isObject(node)) {
|
|
27
|
+
malformed = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!("touched_files" in node))
|
|
31
|
+
continue;
|
|
32
|
+
if (!Array.isArray(node.touched_files)) {
|
|
33
|
+
malformed = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
declared = true;
|
|
37
|
+
for (const raw of node.touched_files) {
|
|
38
|
+
const path = normalizeRepoRelativePath(raw);
|
|
39
|
+
if (path === null) {
|
|
40
|
+
malformed = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (DB_OR_HARNESS_PATH_HINTS.some((hint) => path.startsWith(hint)) || path.includes("/migrations/"))
|
|
44
|
+
relevant = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return relevant ? true : malformed || !declared ? "unknown" : false;
|
|
48
|
+
}
|
|
49
|
+
export const LAUNCH_PLAN_REACHABILITY_COPY = {
|
|
50
|
+
summary: "Escalation reachability",
|
|
51
|
+
reason: "Live delivery is not confirmed; escalations are also shown in the driving session.",
|
|
52
|
+
remedy: "Declare notify.webhook_url in the run policy, or configure live email.",
|
|
53
|
+
};
|
|
54
|
+
export const LAUNCH_PLAN_CHILD_COPY = {
|
|
55
|
+
summary: "Probably done child",
|
|
56
|
+
reason: "The child is on the indexed commit but has no confirmed delivery record; run it to be sure.",
|
|
57
|
+
remedy: "Run the child, or explicitly skip it in this plan.",
|
|
58
|
+
};
|
|
59
|
+
export const LAUNCH_PLAN_NEED_COPY = {
|
|
60
|
+
worker_db_role: { summary: "Worker DB role", reason: "This database-relevant plan needs a safe worker database role.", recommendation: "fix first" },
|
|
61
|
+
self_hosted_runner: { summary: "Self-hosted runner", reason: "Child CI cannot become green while the required runner is offline.", recommendation: "fix first" },
|
|
62
|
+
host_power: { summary: "Host sleep", reason: "The executor needs the host to remain awake during the run.", recommendation: "proceed, keep the lid open" },
|
|
63
|
+
usage_reset_after_run: { summary: "Usage reset after the run", reason: "Capacity waits resume automatically when usage resets.", recommendation: "proceed" },
|
|
64
|
+
};
|
|
65
|
+
export const LAUNCH_PLAN_DB_COPY = {
|
|
66
|
+
"worker-db-boundary": { summary: "Worker database boundary", reason: "The worker database boundary is not confirmed healthy." },
|
|
67
|
+
"worker-db-alembic": { summary: "Worker database migrations", reason: "The operator migration state is not confirmed healthy." },
|
|
68
|
+
"worker-db-leftovers": { summary: "Worker database leftovers", reason: "Worker database cleanup needs attention." },
|
|
69
|
+
"worker-db-unverifiable": { summary: "Worker database inspection", reason: "Worker database safety could not be verified." },
|
|
70
|
+
"worker-db-harness": { summary: "Worker database harness", reason: "Harness database cleanup is not confirmed healthy." },
|
|
71
|
+
};
|
|
72
|
+
function isObject(value) {
|
|
73
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
74
|
+
}
|
|
75
|
+
/** Only complete, asked/present typed rows participate. Untrusted prose is never copied. */
|
|
76
|
+
function eligibleNeed(row) {
|
|
77
|
+
const meta = row.launch_need;
|
|
78
|
+
if (!isObject(meta) || !LAUNCH_NEEDS.includes(meta.need))
|
|
79
|
+
return undefined;
|
|
80
|
+
const need = meta.need;
|
|
81
|
+
if (need === "epic_branch_behind_base" || row.id !== LAUNCH_NEED_ROW_IDS[need] ||
|
|
82
|
+
meta.asked !== true || meta.state !== "present" || row.status !== "warn" ||
|
|
83
|
+
row.blocking !== false || typeof row.remedy !== "string" || row.remedy.trim() === "")
|
|
84
|
+
return undefined;
|
|
85
|
+
return { need, state: "present", asked: true };
|
|
86
|
+
}
|
|
87
|
+
function item(id, kind, copy, recommendation, alternatives) {
|
|
88
|
+
return { id, kind, ...copy, recommendation, alternatives, flags_if_accepted: [] };
|
|
89
|
+
}
|
|
90
|
+
/** Pure projection of a finished preview; no admission decision or input is changed. */
|
|
91
|
+
export function buildLaunchPlan(preview) {
|
|
92
|
+
if (preview.decision !== "create")
|
|
93
|
+
return undefined;
|
|
94
|
+
const rows = Array.isArray(preview.launch_checks) ? preview.launch_checks.filter(isObject) : [];
|
|
95
|
+
const items = [];
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
const add = (entry) => {
|
|
98
|
+
if (!seen.has(entry.id)) {
|
|
99
|
+
seen.add(entry.id);
|
|
100
|
+
items.push(entry);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
if (preview.summary?.escalation_channel !== "webhook" &&
|
|
104
|
+
!rows.some((row) => row.id === ESCALATION_REACHABILITY_CHECK_ID && row.status === "pass")) {
|
|
105
|
+
add(item(ESCALATION_REACHABILITY_CHECK_ID, "reachability", LAUNCH_PLAN_REACHABILITY_COPY, "proceed", [{ choice: "fix first", flags: [] }]));
|
|
106
|
+
}
|
|
107
|
+
const children = preview.already_done_children;
|
|
108
|
+
if (isObject(children) && children.status === "checked" && Array.isArray(children.children)) {
|
|
109
|
+
for (const child of children.children) {
|
|
110
|
+
if (!isObject(child) || child.classification !== "probably_done" || child.will_skip !== false ||
|
|
111
|
+
typeof child.ticket_key !== "string" || !EPIC_KEY_PATTERN.test(child.ticket_key))
|
|
112
|
+
continue;
|
|
113
|
+
add(item(`probably-done-${child.ticket_key}`, "probably_done", {
|
|
114
|
+
...LAUNCH_PLAN_CHILD_COPY, summary: `${LAUNCH_PLAN_CHILD_COPY.summary} ${child.ticket_key}`,
|
|
115
|
+
}, "run it", [{ choice: "skip", flags: ["--skip-child", child.ticket_key] }]));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const addNeed = (row, need) => {
|
|
119
|
+
const copy = LAUNCH_PLAN_NEED_COPY[need];
|
|
120
|
+
add(item(LAUNCH_NEED_ROW_IDS[need], need === "worker_db_role" ? "worker_db" : "launch_need", {
|
|
121
|
+
summary: copy.summary, reason: copy.reason, remedy: LAUNCH_NEED_REMEDIES[need],
|
|
122
|
+
}, copy.recommendation, [{ choice: copy.recommendation === "fix first" ? "launch anyway" : "fix first", flags: [] }]));
|
|
123
|
+
};
|
|
124
|
+
for (const row of rows) {
|
|
125
|
+
// The role never falls through into generic database handling, even if malformed.
|
|
126
|
+
if (row.id === LAUNCH_NEED_ROW_IDS.worker_db_role) {
|
|
127
|
+
if (eligibleNeed(row)?.need === "worker_db_role" && preview.plan_database_relevance === true)
|
|
128
|
+
addNeed(row, "worker_db_role");
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (typeof row.id !== "string" || !Object.hasOwn(LAUNCH_PLAN_DB_COPY, row.id) ||
|
|
132
|
+
!["warn", "fail", "unverified"].includes(row.status) || row.blocking !== false)
|
|
133
|
+
continue;
|
|
134
|
+
const id = row.id;
|
|
135
|
+
add(item(id, "worker_db", { ...LAUNCH_PLAN_DB_COPY[id], remedy: `${WORKER_DATABASE_DOCTOR_OWNER}: see ${WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION}` }, "fix first", [{ choice: "launch anyway", flags: [] }]));
|
|
136
|
+
}
|
|
137
|
+
for (const need of LAUNCH_NEEDS) {
|
|
138
|
+
if (need === "worker_db_role" || need === "epic_branch_behind_base")
|
|
139
|
+
continue;
|
|
140
|
+
const row = rows.find((row) => eligibleNeed(row)?.need === need);
|
|
141
|
+
if (row)
|
|
142
|
+
addNeed(row, need);
|
|
143
|
+
}
|
|
144
|
+
return { launch_plan: { version: 1, items, fix_first: items.some((entry) => entry.recommendation === "fix first") } };
|
|
145
|
+
}
|