@bridge_gpt/mcp-server 0.2.70 → 0.2.72
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 +29 -4
- package/build/agent-notes.js +171 -95
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +12 -2
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +17 -5
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -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-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +776 -23
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +93 -13
- package/build/conductor/epic-implementer-cli.js +55 -2
- package/build/conductor/gate-discovery.js +659 -19
- package/build/conductor/gate-settings-review.js +751 -0
- 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 +16 -11
- package/build/conductor/launch-plan.js +185 -0
- 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/precheck-timings.js +14 -0
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +25 -9
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +281 -14
- package/build/conductor/recovery-operations.js +78 -5
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +240 -56
- package/build/epic-ci-workflow-drift.js +71 -23
- package/build/epic-ci-workflow-install.js +83 -26
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +174 -13
- package/build/epic-implementer-bin.js +119 -44
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- 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 +274 -5
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +355 -36
- package/build/executor/likely-tests.js +100 -98
- package/build/executor/preflight.js +5 -0
- package/build/executor/process-containment.js +18 -0
- package/build/executor/prompt-spec.js +84 -15
- package/build/executor/reconcile-overlap-job.js +6 -1
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -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/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +188 -1
- package/build/executor/worker-database.js +299 -40
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +12 -1
- package/build/executor/worker-verification-guidance.js +64 -0
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +767 -310
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +416 -41
- package/build/install-bridge-conductor-setup.js +135 -32
- package/build/install-bridge-conductor.js +769 -353
- package/build/install-bridge.js +419 -124
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +22 -2
- 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-execution-ledger.js +171 -10
- package/build/plane/plane-freshness.js +12 -9
- package/build/plane/preflight.js +19 -0
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +31 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +623 -0
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +26 -9
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +61 -80
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-artifacts.js +7 -0
- package/build/ticket-delivery-enrollment.js +80 -4
- package/build/ticket-delivery-run-scope.js +128 -0
- 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.md +43 -0
- package/docs/epic-implementer/getting-started.md +95 -14
- package/package.json +2 -2
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { writeJsonDocument, flushProcessStdout } from './conductor/json-output.js';
|
|
2
|
+
import { previewConductorSetupPolicy, applyConductorSetupPolicy, fetchConductorSetupPolicy, ConductorSetupPolicyError, SETUP_POLICY_PROTOCOL } from "./conductor/bridge-api-client.js";
|
|
3
|
+
import { askSetupQuestion, readCustomSetupCommand, setupConsentQuestion } from "./setup-question.js";
|
|
1
4
|
/**
|
|
2
|
-
* `install-
|
|
5
|
+
* `install epic-implementer` — the nested conductor bootstrap phase (BAPI-679).
|
|
3
6
|
*
|
|
4
7
|
* BAPI-1461 — CONVERGING SETUP. With the production setup seams (always
|
|
5
8
|
* supplied by `install-bridge.ts`), this command is a loop, not a script: it
|
|
@@ -20,26 +23,13 @@
|
|
|
20
23
|
*
|
|
21
24
|
* Four properties are load-bearing and are pinned by tests:
|
|
22
25
|
*
|
|
23
|
-
* 1. **
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* (missing supervisor rows — exactly what bootstrap fixes) are `degraded`
|
|
31
|
-
* and do not block.
|
|
32
|
-
* 2. **`--dry-run` writes nothing, anywhere.** It returns before every POST,
|
|
33
|
-
* filesystem write, install-state write, and write-consent prompt. (It still
|
|
34
|
-
* asks the base-URL confirmation above, because its doctor GET is a network
|
|
35
|
-
* call that reveals the key to the resolved host.)
|
|
36
|
-
* 3. **One consent per write surface.** Confirming the resolved base URL is NOT
|
|
37
|
-
* consent to write; consent to overwrite a workflow file is not consent to
|
|
38
|
-
* edit host MCP configuration; and neither is consent to install Git hooks.
|
|
39
|
-
* The rule is per-SURFACE, not a fixed count — BAPI-775 added two more write
|
|
40
|
-
* surfaces (host MCP configs, managed Git hooks) and each asks for itself, so
|
|
41
|
-
* counting consents was never the invariant. A missing prompt seam (no TTY)
|
|
42
|
-
* is a decline everywhere, never a default-yes.
|
|
26
|
+
* 1. **Destination before requests.** Parent installation settles credential
|
|
27
|
+
* identity and endpoint approval before authenticated requests. The nested
|
|
28
|
+
* command displays the resolved destination before access resolution.
|
|
29
|
+
* 2. **`--dry-run` writes nothing, anywhere.** Read-only diagnostics remain
|
|
30
|
+
* available without redundant URL confirmation or write-consent questions.
|
|
31
|
+
* 3. **One consent per consequential effect.** Destination selection does not
|
|
32
|
+
* authorize policy, credential, service, workflow, or hook changes.
|
|
43
33
|
* 4. **The executor leg is never claimed as provisioned by local success.**
|
|
44
34
|
* AMENDED BY BAPI-779 (R-1): this command can now write the service unit
|
|
45
35
|
* *and* start it. What did not change — and must not — is where readiness
|
|
@@ -67,7 +57,7 @@
|
|
|
67
57
|
* DURABLE-HOST MODE (BAPI-1137). The executor phase below is the supported
|
|
68
58
|
* bring-up for a *durable host*: an execution home that is not an interactive
|
|
69
59
|
* shell session, so a sleeping or closed operator laptop no longer stalls a run.
|
|
70
|
-
* The client command spelling is unchanged — it is still `install
|
|
60
|
+
* The client command spelling is unchanged — it is still `install epic-implementer` —
|
|
71
61
|
* and so is every primitive it drives; what this slice does is name the
|
|
72
62
|
* composition and make its boundaries explicit. Durable-host mode IS that
|
|
73
63
|
* composition, and nothing more:
|
|
@@ -117,17 +107,18 @@
|
|
|
117
107
|
* BAPI-694's. The policy selected here is per-run and is reported as such.
|
|
118
108
|
*/
|
|
119
109
|
import { PRINTED_INSTALL_COMMAND, PRINTED_QUALIFY_GATE_COMMAND } from "./printed-remedy-commands.js";
|
|
120
|
-
import { emptyConductorGateFlags, hasExplicitGateInput, parseLocalCommandFlag, parseEpicBranchCiDecisionFlag, parseMigrationGuardFlag, resolveConductorGate, runEpicBranchCiInspection, runClearConductorGate, runConductorGateQualification, runQualifyConductorGate,
|
|
121
|
-
import {
|
|
110
|
+
import { confirmRequestFor, emptyConductorGateFlags, hasExplicitGateInput, parseLocalCommandFlag, parseEpicBranchCiDecisionFlag, parseMigrationGuardFlag, resolveConductorGate, runEpicBranchCiInspection, runClearConductorGate, runConductorGateQualification, runQualifyConductorGate, validateConductorGateFlags, } from "./install-bridge-conductor-gate.js";
|
|
111
|
+
import { fetchConductorReadiness, } from "./conductor/bridge-api-client.js";
|
|
122
112
|
import { CONDUCTOR_OPERATOR_RUNBOOK_POINTER, EXECUTOR_PROVISIONING_GUIDANCE, conductorInstallDoctorExitCode, conductorInstallDoctorHasFatal, formatConductorInstallDoctorReport, } from "./conductor/install-doctor.js";
|
|
123
113
|
import { describeNativeLedgerAvailability, } from "./conductor/doctor.js";
|
|
124
114
|
import { resolveGithubMergeRepositoryIdentity, } from "./credential-store.js";
|
|
125
115
|
import { isUsableMergeCredentialValue, resolveLocalMergeCredentialDetailed, } from "./conductor/merge-credential.js";
|
|
126
116
|
import { readStoredTestCommand, writeStoredTestCommand, } from "./testing-config-client.js";
|
|
117
|
+
import { describeToolchainResolution, resolveRepositoryToolchains, } from "./repository-toolchains.js";
|
|
127
118
|
import { detectTestCommand } from "./test-command-detection.js";
|
|
128
|
-
import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
|
|
119
|
+
import { TestCommandValidationError, validateTestCommand, } from "./test-command-validation.js";
|
|
129
120
|
import { EPIC_IMPLEMENTER_CI_CHECK_NAME } from "./epic-ci-workflow.js";
|
|
130
|
-
import { assessSetupIndex, catalogLabel, compareIndexedToMerge, planSetupFixes, projectSetupItems, readSetupPullRequest, renderSetupAssessment, setupVerdictLine, unmetBlockingItems, } from "./install-bridge-conductor-setup.js";
|
|
121
|
+
import { assessSetupIndex, catalogLabel, compareIndexedToMerge, isTestCommandFix, planSetupFixes, projectSetupItems, readSetupPullRequest, renderSetupAssessment, setupVerdictLine, unmetBlockingItems, } from "./install-bridge-conductor-setup.js";
|
|
131
122
|
import { CONDUCTOR_BIN_UNRESOLVED_ERROR, MANAGED_HOOK_NAMES, } from "./conductor/git-hooks.js";
|
|
132
123
|
import os from "node:os";
|
|
133
124
|
import path from "node:path";
|
|
@@ -162,31 +153,36 @@ export const CONDUCTOR_REVIEW_POLICY_SOURCES = [
|
|
|
162
153
|
* at first approval. AI review is an explicit `--review-policy verdict_protocol`.
|
|
163
154
|
*/
|
|
164
155
|
export const DEFAULT_CONDUCTOR_REVIEW_POLICY = "repository_policy";
|
|
165
|
-
/** Usage text for `install-
|
|
156
|
+
/** Usage text for `install epic-implementer`. */
|
|
166
157
|
export function getInstallBridgeConductorUsage() {
|
|
167
158
|
return [
|
|
168
|
-
"Usage: install
|
|
159
|
+
"Usage: install epic-implementer [options]",
|
|
169
160
|
"",
|
|
170
161
|
"Set up this repository for the Epic Implementer. It checks everything first",
|
|
171
162
|
"(read-only), fixes only what is missing, checks again, and ends with one",
|
|
172
163
|
"verdict: \"Ready for your first epic\" or \"Not ready: N steps left\" with the fix",
|
|
173
|
-
"for each step.
|
|
174
|
-
"
|
|
175
|
-
"
|
|
164
|
+
"for each step. Interactive output ends with an advisory readiness verdict.",
|
|
165
|
+
" --json Emit one installation result; unanswered interactive choices defer.",
|
|
166
|
+
" --assessment-epic-run-id <id> Observe this run's readiness (default: repository preview).",
|
|
167
|
+
"It exits 0 when ready and 1 for unresolved requested capabilities (0 for --dry-run).",
|
|
176
168
|
"",
|
|
177
|
-
"It
|
|
178
|
-
"
|
|
169
|
+
"It displays the destination and reads your Claude sign-in (~/.claude.json only)",
|
|
170
|
+
"and `gh auth status`. A ready repository gets no questions and no",
|
|
179
171
|
"writes. Otherwise it asks only what a missing item needs, each with a default of no:",
|
|
180
172
|
" - which repository, only when it cannot tell;",
|
|
181
|
-
" - saving the test command, only when none is stored
|
|
173
|
+
" - saving the test command, only when none is stored (or replacing it, when you",
|
|
174
|
+
" pass --test-command);",
|
|
182
175
|
" - opening the setup pull request with the CI workflow;",
|
|
183
176
|
" - storing the repository gate and safe defaults, when they would change;",
|
|
184
177
|
" - storing a GitHub merge token on this computer (read with no echo).",
|
|
185
|
-
"The
|
|
178
|
+
"The destination is displayed without a redundant URL question. Without an",
|
|
186
179
|
"interactive terminal every question is a decline: no token is stored and no",
|
|
187
180
|
"pull request is opened. When setup reports that its setup pull request is",
|
|
188
|
-
"waiting, merge it and run setup again
|
|
189
|
-
"
|
|
181
|
+
"waiting, merge it and run setup again. Recovery diagnoses the demonstrated",
|
|
182
|
+
"target, offers keep/correct/defer when needed, and tracks one durable initial",
|
|
183
|
+
"request. Failed or ineffective work needs an explicit retry; pending work is",
|
|
184
|
+
"observed without cancellation. Unsupported backends require an upgrade;",
|
|
185
|
+
"noninteractive runs cannot authorize branch corrections or retries.",
|
|
190
186
|
"",
|
|
191
187
|
"Merge token: setup can store a GitHub token for this repository in your user",
|
|
192
188
|
"credential store (~/.config/bridge/credentials.json). GITHUB_MERGE_TOKEN, then",
|
|
@@ -195,7 +191,21 @@ export function getInstallBridgeConductorUsage() {
|
|
|
195
191
|
"local copy only; it does not revoke the token at GitHub, and a running executor",
|
|
196
192
|
"keeps the token it started with until it restarts.",
|
|
197
193
|
"",
|
|
194
|
+
"Test command: setup prints the stored command (and what CI installs for it) on",
|
|
195
|
+
"every run. To save or replace it, pass --test-command \"<command>\": the flag is",
|
|
196
|
+
"your consent for that one write, so there is no command question. The command is",
|
|
197
|
+
"checked first (one line, no GitHub Actions expression, at most 500 characters),",
|
|
198
|
+
"saved once, and read back; setup reports success only when the stored value",
|
|
199
|
+
"matches. The same value again is \"unchanged\" and writes nothing. The flag does",
|
|
200
|
+
"NOT authorize credential endpoint transfer and",
|
|
201
|
+
"does NOT consent to the workflow pull request, which asks for itself. With",
|
|
202
|
+
"--dry-run nothing is saved. Do not put a credential in a command: setup prints",
|
|
203
|
+
"it and the workflow file contains it.",
|
|
204
|
+
"",
|
|
198
205
|
"Options:",
|
|
206
|
+
" --test-command <command> Save or replace the repository's test command.",
|
|
207
|
+
" Not combinable with --remove-merge-token or",
|
|
208
|
+
" --clear-gate; may be given once.",
|
|
199
209
|
" --remove-merge-token Remove the merge token stored on this computer for",
|
|
200
210
|
" this repository (its own consent), then exit.",
|
|
201
211
|
" --repo <name> Repository name (default: BAPI_REPO_NAME / .bridge/config)",
|
|
@@ -316,6 +326,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
316
326
|
}
|
|
317
327
|
let repo;
|
|
318
328
|
let dryRun = false;
|
|
329
|
+
let json = false;
|
|
319
330
|
let skipWorkflow = false;
|
|
320
331
|
let replaceDoneGate = false;
|
|
321
332
|
let reviewPolicy = DEFAULT_CONDUCTOR_REVIEW_POLICY;
|
|
@@ -324,6 +335,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
324
335
|
let planFile;
|
|
325
336
|
let executorId;
|
|
326
337
|
const epicRunIds = [];
|
|
338
|
+
let assessmentEpicRunId;
|
|
327
339
|
let repoWide = false;
|
|
328
340
|
let allowedBot;
|
|
329
341
|
let secretName;
|
|
@@ -336,6 +348,8 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
336
348
|
let policyFile;
|
|
337
349
|
let epicBranchCiDecision;
|
|
338
350
|
let removeMergeToken = false;
|
|
351
|
+
let testCommand;
|
|
352
|
+
let testCommandSeen = false;
|
|
339
353
|
const takeValue = (arg, inline, next) => {
|
|
340
354
|
if (inline !== undefined) {
|
|
341
355
|
if (inline.trim().length === 0)
|
|
@@ -353,6 +367,11 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
353
367
|
const flag = eq === -1 ? raw : raw.slice(0, eq);
|
|
354
368
|
const inline = eq === -1 ? undefined : raw.slice(eq + 1);
|
|
355
369
|
switch (flag) {
|
|
370
|
+
case "--json":
|
|
371
|
+
if (inline !== undefined)
|
|
372
|
+
return { status: "error", message: "--json takes no value" };
|
|
373
|
+
json = true;
|
|
374
|
+
break;
|
|
356
375
|
case "--dry-run":
|
|
357
376
|
if (inline !== undefined)
|
|
358
377
|
return { status: "error", message: "--dry-run takes no value" };
|
|
@@ -379,6 +398,36 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
379
398
|
}
|
|
380
399
|
removeMergeToken = true;
|
|
381
400
|
break;
|
|
401
|
+
case "--test-command": {
|
|
402
|
+
if (testCommandSeen)
|
|
403
|
+
return { status: "error", message: "--test-command may be given once" };
|
|
404
|
+
testCommandSeen = true;
|
|
405
|
+
// The raw value is validated BEFORE any trimming: `takeValue` trims, which
|
|
406
|
+
// would turn a command ending in a newline into a valid one-line command.
|
|
407
|
+
let rawCommand;
|
|
408
|
+
if (inline !== undefined) {
|
|
409
|
+
rawCommand = inline;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
const next = argv[i + 1];
|
|
413
|
+
if (next === undefined || next.startsWith("-")) {
|
|
414
|
+
return { status: "error", message: "--test-command requires a value" };
|
|
415
|
+
}
|
|
416
|
+
rawCommand = next;
|
|
417
|
+
i++;
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
testCommand = validateTestCommand(rawCommand);
|
|
421
|
+
}
|
|
422
|
+
catch (err) {
|
|
423
|
+
// The message is fixed text and never echoes the command.
|
|
424
|
+
if (err instanceof TestCommandValidationError) {
|
|
425
|
+
return { status: "error", message: `Invalid --test-command: ${err.message}` };
|
|
426
|
+
}
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
382
431
|
case "--gate-none":
|
|
383
432
|
case "--confirm-gate":
|
|
384
433
|
case "--clear-gate":
|
|
@@ -402,6 +451,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
402
451
|
case "--plan-file":
|
|
403
452
|
case "--executor-id":
|
|
404
453
|
case "--epic-run-id":
|
|
454
|
+
case "--assessment-epic-run-id":
|
|
405
455
|
case "--allowed-bot":
|
|
406
456
|
case "--secret-name":
|
|
407
457
|
case "--branches":
|
|
@@ -461,6 +511,12 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
461
511
|
executorId = value;
|
|
462
512
|
else if (flag === "--epic-run-id")
|
|
463
513
|
epicRunIds.push(value);
|
|
514
|
+
else if (flag === "--assessment-epic-run-id") {
|
|
515
|
+
if (assessmentEpicRunId !== undefined || !isValidExecutorEpicRunId(value)) {
|
|
516
|
+
return { status: "error", message: "--assessment-epic-run-id requires one valid run ID and may be given once." };
|
|
517
|
+
}
|
|
518
|
+
assessmentEpicRunId = value;
|
|
519
|
+
}
|
|
464
520
|
else if (flag === "--allowed-bot")
|
|
465
521
|
allowedBot = value;
|
|
466
522
|
else if (flag === "--secret-name")
|
|
@@ -569,6 +625,14 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
569
625
|
"--executor-id.",
|
|
570
626
|
};
|
|
571
627
|
}
|
|
628
|
+
// BAPI-1536 — `--clear-gate` is a standalone action that stops before setup, so a
|
|
629
|
+
// command request beside it would be silently dropped. Refuse the pair.
|
|
630
|
+
if (testCommand !== undefined && gate.clearGate) {
|
|
631
|
+
return {
|
|
632
|
+
status: "error",
|
|
633
|
+
message: "--test-command cannot be combined with --clear-gate: clearing the gate is a standalone action.",
|
|
634
|
+
};
|
|
635
|
+
}
|
|
572
636
|
// BAPI-1461 — token removal is its own action: only --repo and --dry-run may
|
|
573
637
|
// accompany it, so it can never be mistaken for, or followed by, setup writes.
|
|
574
638
|
if (removeMergeToken) {
|
|
@@ -591,6 +655,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
591
655
|
skipWorkflow ||
|
|
592
656
|
allowedBot !== undefined ||
|
|
593
657
|
secretName !== undefined ||
|
|
658
|
+
testCommand !== undefined ||
|
|
594
659
|
branches !== undefined;
|
|
595
660
|
if (conflicting) {
|
|
596
661
|
return {
|
|
@@ -618,6 +683,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
618
683
|
options: {
|
|
619
684
|
repo,
|
|
620
685
|
dryRun,
|
|
686
|
+
json,
|
|
621
687
|
requiredChecks: normalizedChecks,
|
|
622
688
|
gate,
|
|
623
689
|
reviewPolicy,
|
|
@@ -631,6 +697,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
631
697
|
...(replaceDoneGate ? { replaceDoneGate: true } : {}),
|
|
632
698
|
executorId,
|
|
633
699
|
...(epicRunIds.length > 0 ? { epicRunIds } : {}),
|
|
700
|
+
...(assessmentEpicRunId !== undefined ? { assessmentEpicRunId } : {}),
|
|
634
701
|
...(repoWide ? { repoWide: true } : {}),
|
|
635
702
|
...(launchProfile ? { launchProfile } : {}),
|
|
636
703
|
...(baseUrl ? { baseUrl } : {}),
|
|
@@ -640,6 +707,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
640
707
|
...(policyFile ? { policyFile } : {}),
|
|
641
708
|
...(epicBranchCiDecision ? { epicBranchCiDecision } : {}),
|
|
642
709
|
...(removeMergeToken ? { removeMergeToken: true } : {}),
|
|
710
|
+
...(testCommand !== undefined ? { testCommand } : {}),
|
|
643
711
|
},
|
|
644
712
|
};
|
|
645
713
|
}
|
|
@@ -658,7 +726,7 @@ export function createDefaultLaunchProfileDeps(env) {
|
|
|
658
726
|
readFile: store.readFile,
|
|
659
727
|
stat: (p) => statAsync(p),
|
|
660
728
|
}),
|
|
661
|
-
bindCredential: (repoName, baseUrl) => bindEpicLaunchCredential(repoName, baseUrl, store),
|
|
729
|
+
bindCredential: (repoName, baseUrl, observedKey) => bindEpicLaunchCredential(repoName, baseUrl, store, { observedKey: observedKey ?? null }),
|
|
662
730
|
readPolicyFile: (absolutePath) => readFileAsync(absolutePath, "utf-8"),
|
|
663
731
|
};
|
|
664
732
|
}
|
|
@@ -815,11 +883,8 @@ function renderBootstrapOutcome(deps, response) {
|
|
|
815
883
|
}
|
|
816
884
|
}
|
|
817
885
|
async function confirm(deps, promptText) {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
return false;
|
|
821
|
-
const answer = await deps.promptLine(promptText);
|
|
822
|
-
return CONSENT_YES.has((answer ?? "").trim().toLowerCase());
|
|
886
|
+
const decision = await askSetupQuestion(setupConsentQuestion(promptText), { read: deps.promptLine, write: deps.log });
|
|
887
|
+
return decision.status === "accept";
|
|
823
888
|
}
|
|
824
889
|
/**
|
|
825
890
|
* BAPI-1452 — the merge-credential next step. Value-free configuration guidance
|
|
@@ -1102,16 +1167,16 @@ export function formatConductorRestartAdvisory(mergedProfile) {
|
|
|
1102
1167
|
}
|
|
1103
1168
|
/** Remediation printed when no supported host config carries a Bridge entry. */
|
|
1104
1169
|
export const CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION = `run \`${PRINTED_INSTALL_COMMAND}\` to create and register the host MCP entry, ` +
|
|
1105
|
-
"then re-run `install
|
|
1170
|
+
"then re-run `install epic-implementer`.";
|
|
1106
1171
|
/** Remediation printed whenever the managed git hooks were not installed. */
|
|
1107
|
-
export const CONDUCTOR_HOOKS_MANUAL_REMEDIATION = "re-run `install
|
|
1172
|
+
export const CONDUCTOR_HOOKS_MANUAL_REMEDIATION = "re-run `install epic-implementer` and accept the local-observability consent, or run " +
|
|
1108
1173
|
"`epic-implementer install-git-hooks` directly.";
|
|
1109
1174
|
/**
|
|
1110
1175
|
* Remediation for a non-fatal hook refusal (BAPI-1290): the hooks need a
|
|
1111
1176
|
* persistent install to embed, and the repair is to create one and reinstall.
|
|
1112
1177
|
*/
|
|
1113
1178
|
export const CONDUCTOR_HOOKS_DURABLE_REMEDIATION = `install the CLI persistently (\`npm i -g ${MCP_PACKAGE_NAME}\`), then run ` +
|
|
1114
|
-
"`epic-implementer install-git-hooks` (or re-run `install
|
|
1179
|
+
"`epic-implementer install-git-hooks` (or re-run `install epic-implementer` and accept the " +
|
|
1115
1180
|
"local-observability consent).";
|
|
1116
1181
|
/**
|
|
1117
1182
|
* Phase: tool visibility.
|
|
@@ -1128,7 +1193,7 @@ async function runConductorToolVisibilityPhase(deps, local) {
|
|
|
1128
1193
|
deps.log(" declined — no host MCP configuration and no install state were written.");
|
|
1129
1194
|
return {
|
|
1130
1195
|
manualActions: [
|
|
1131
|
-
"tool visibility: re-run `install
|
|
1196
|
+
"tool visibility: re-run `install epic-implementer` and accept the profile consent to " +
|
|
1132
1197
|
"make the Epic Implementer MCP tools visible.",
|
|
1133
1198
|
],
|
|
1134
1199
|
};
|
|
@@ -1224,7 +1289,7 @@ async function runConductorLocalObservabilityPhase(deps, local) {
|
|
|
1224
1289
|
"(engine admission is unaffected).");
|
|
1225
1290
|
// Only BAPI-772's broken-package case stays fatal: the executing artifact
|
|
1226
1291
|
// ships no hook binary at all. Every other refusal — an npx-cache runtime
|
|
1227
|
-
// (the documented `npx … install
|
|
1292
|
+
// (the documented `npx … install epic-implementer` path), an unqualified or
|
|
1228
1293
|
// unloadable runtime, an unsafe existing hook — is a manual action, and
|
|
1229
1294
|
// the installer continues to setup-epic verification and executor
|
|
1230
1295
|
// provisioning. Optional hooks must never stop the phases that do gate
|
|
@@ -1244,7 +1309,7 @@ async function runConductorLocalObservabilityPhase(deps, local) {
|
|
|
1244
1309
|
else if (result !== null && result.ok) {
|
|
1245
1310
|
if (!result.is_worktree) {
|
|
1246
1311
|
deps.log(" not a git worktree, so no managed hook was installed (degraded optional capability).");
|
|
1247
|
-
manualActions.push("local observability: run `install
|
|
1312
|
+
manualActions.push("local observability: run `install epic-implementer` from a git worktree to install the " +
|
|
1248
1313
|
"managed git hooks.");
|
|
1249
1314
|
}
|
|
1250
1315
|
else {
|
|
@@ -1565,7 +1630,7 @@ async function runLaunchProfilePhase(deps, options, inputs) {
|
|
|
1565
1630
|
gaps.push("the credential binding was not approved, so a launch could not use the stored key.");
|
|
1566
1631
|
}
|
|
1567
1632
|
else {
|
|
1568
|
-
const result = await lp.bindCredential(repoName, inputs.baseUrl);
|
|
1633
|
+
const result = await lp.bindCredential(repoName, inputs.baseUrl, inputs.access.apiKey);
|
|
1569
1634
|
if (!result.ok)
|
|
1570
1635
|
gaps.push(`the credential binding could not be written: ${result.error}`);
|
|
1571
1636
|
else
|
|
@@ -1578,7 +1643,7 @@ async function runLaunchProfilePhase(deps, options, inputs) {
|
|
|
1578
1643
|
deps.log(` incomplete — profile '${name}' was NOT written:`);
|
|
1579
1644
|
for (const gap of gaps)
|
|
1580
1645
|
deps.log(` → ${gap}`);
|
|
1581
|
-
deps.log(` re-run: npx -y ${MCP_PACKAGE_NAME} install
|
|
1646
|
+
deps.log(` re-run: npx -y ${MCP_PACKAGE_NAME} install epic-implementer --launch-profile ${name} ` +
|
|
1582
1647
|
`--base-url ${inputs.baseUrl} --required-check <name> ...`);
|
|
1583
1648
|
return { complete: false };
|
|
1584
1649
|
}
|
|
@@ -1673,11 +1738,6 @@ async function resolveAndConfirmBaseUrl(options, deps, promptText) {
|
|
|
1673
1738
|
deps.log(` explicit target for epic launch profile '${options.launchProfile}'` +
|
|
1674
1739
|
(baseUrl === DEFAULT_BAPI_BASE_URL ? " — this is the PRODUCTION Bridge API, selected deliberately." : "."));
|
|
1675
1740
|
}
|
|
1676
|
-
const baseUrlOk = await confirm(deps, promptText);
|
|
1677
|
-
if (!baseUrlOk) {
|
|
1678
|
-
deps.log("Aborted — no network call (readiness GET or bootstrap POST) was attempted.");
|
|
1679
|
-
return { ok: false, code: 0 };
|
|
1680
|
-
}
|
|
1681
1741
|
return { ok: true, baseUrl };
|
|
1682
1742
|
}
|
|
1683
1743
|
function gateIoFor(deps) {
|
|
@@ -1696,7 +1756,9 @@ function gateIoFor(deps) {
|
|
|
1696
1756
|
* neither was requested.
|
|
1697
1757
|
*/
|
|
1698
1758
|
async function runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl) {
|
|
1699
|
-
|
|
1759
|
+
// BAPI-1536: a command request means setup has work to do, so `--qualify-gate`
|
|
1760
|
+
// is no longer standalone and its accompanying command is never discarded.
|
|
1761
|
+
const qualifyOnly = options.gate.qualifyGate && !hasExplicitGateInput(options.gate) && options.testCommand === undefined;
|
|
1700
1762
|
if (!options.gate.clearGate && !qualifyOnly)
|
|
1701
1763
|
return null;
|
|
1702
1764
|
if (!access) {
|
|
@@ -1770,7 +1832,55 @@ async function runExecutorPreflightPhase(options, deps, baseUrl, access) {
|
|
|
1770
1832
|
}
|
|
1771
1833
|
return { kind: "ok", plans: null };
|
|
1772
1834
|
}
|
|
1835
|
+
/** One output finalizer for success, deferment, dry run, and contained failures. */
|
|
1773
1836
|
export async function runInstallBridgeConductorCli(argv, deps) {
|
|
1837
|
+
const parsed = parseInstallBridgeConductorArgs(argv);
|
|
1838
|
+
const machine = argv.includes('--json');
|
|
1839
|
+
const human = !machine && deps.isTTY === true;
|
|
1840
|
+
let verdict;
|
|
1841
|
+
let outcome = 'complete-with-manual-steps';
|
|
1842
|
+
let assessment;
|
|
1843
|
+
const inner = { ...deps,
|
|
1844
|
+
get promptLine() { return deps.promptLine; },
|
|
1845
|
+
assessmentSink: (value) => { assessment = value; deps.assessmentSink?.(value); },
|
|
1846
|
+
log: (line) => {
|
|
1847
|
+
if (/^complete(?:-with-manual-steps)?(?: \(dry run\))?$/.test(line)) {
|
|
1848
|
+
outcome = line === 'complete' ? 'complete' : 'complete-with-manual-steps';
|
|
1849
|
+
if (!machine && !human)
|
|
1850
|
+
deps.log(line);
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
if (/^(Ready(?: for your first epic)?|Not ready|Readiness not confirmed)(?:$|:| —)/.test(line)) {
|
|
1854
|
+
verdict = line;
|
|
1855
|
+
if (!machine && !human)
|
|
1856
|
+
deps.log(line);
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
if (machine)
|
|
1860
|
+
deps.errorLog(line);
|
|
1861
|
+
else
|
|
1862
|
+
deps.log(line);
|
|
1863
|
+
},
|
|
1864
|
+
errorLog: (line) => { deps.errorLog(line); },
|
|
1865
|
+
};
|
|
1866
|
+
let exitCode;
|
|
1867
|
+
try {
|
|
1868
|
+
exitCode = await runInstallBridgeConductorCore(argv, inner);
|
|
1869
|
+
}
|
|
1870
|
+
catch {
|
|
1871
|
+
exitCode = 1;
|
|
1872
|
+
outcome = 'complete-with-manual-steps';
|
|
1873
|
+
deps.errorLog('Setup stopped unexpectedly. Completed independent work is retained; rerun setup to inspect it.');
|
|
1874
|
+
}
|
|
1875
|
+
if (machine)
|
|
1876
|
+
await writeJsonDocument(JSON.stringify({ schemaVersion: 1, outcome, exitCode,
|
|
1877
|
+
dryRun: parsed.status === 'ok' && parsed.options.dryRun,
|
|
1878
|
+
...(assessment ? { assessment, advisoryVerdict: verdict ?? 'Readiness not confirmed' } : {}) }), { log: deps.log, flush: deps.isTTY === undefined ? async () => true : flushProcessStdout });
|
|
1879
|
+
else if (human && parsed.status === 'ok')
|
|
1880
|
+
deps.log(verdict ?? 'Readiness not confirmed — setup did not establish all required evidence; advisory only.');
|
|
1881
|
+
return exitCode;
|
|
1882
|
+
}
|
|
1883
|
+
async function runInstallBridgeConductorCore(argv, deps) {
|
|
1774
1884
|
const parsed = parseInstallBridgeConductorArgs(argv);
|
|
1775
1885
|
if (parsed.status === "help") {
|
|
1776
1886
|
deps.log(parsed.usage);
|
|
@@ -1793,13 +1903,24 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1793
1903
|
deps.errorLog("Error: --remove-merge-token is unavailable here: this caller supplied no credential-store seams.");
|
|
1794
1904
|
return 1;
|
|
1795
1905
|
}
|
|
1906
|
+
if (options.testCommand !== undefined) {
|
|
1907
|
+
// Accepting the flag and running an implementation that ignores it would
|
|
1908
|
+
// report success for a command that was never saved.
|
|
1909
|
+
deps.errorLog("Error: --test-command is unavailable here: this caller supplied no test-command seams.");
|
|
1910
|
+
return 1;
|
|
1911
|
+
}
|
|
1796
1912
|
const confirmed = await resolveAndConfirmBaseUrl(options, deps, "Bootstrap against this URL? [y/N]: ");
|
|
1797
1913
|
if (!confirmed.ok)
|
|
1798
1914
|
return confirmed.code;
|
|
1799
1915
|
const baseUrl = confirmed.baseUrl;
|
|
1916
|
+
if (!options.dryRun && !(await assessEpicInstallerPrerequisites(deps, Boolean(options.executorId))).available)
|
|
1917
|
+
return 1;
|
|
1800
1918
|
const accessResult = await deps.resolveAccess(options.repo, baseUrl);
|
|
1801
1919
|
const access = accessResult.ok ? accessResult.access : null;
|
|
1802
1920
|
const accessError = accessResult.ok ? undefined : accessResult.error;
|
|
1921
|
+
const earlyPreflight = await runExecutorPreflightPhase(options, deps, baseUrl, access);
|
|
1922
|
+
if (earlyPreflight.kind === "refused")
|
|
1923
|
+
return 1;
|
|
1803
1924
|
const gateIo = gateIoFor(deps);
|
|
1804
1925
|
const standalone = await runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl);
|
|
1805
1926
|
if (standalone !== null)
|
|
@@ -1810,6 +1931,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1810
1931
|
access,
|
|
1811
1932
|
accessError,
|
|
1812
1933
|
reviewPolicySource: options.reviewPolicy,
|
|
1934
|
+
assessmentVersion: 1,
|
|
1935
|
+
epicRunId: options.assessmentEpicRunId,
|
|
1813
1936
|
});
|
|
1814
1937
|
deps.log(formatConductorInstallDoctorReport(firstReport));
|
|
1815
1938
|
if (conductorInstallDoctorHasFatal(firstReport)) {
|
|
@@ -1827,10 +1950,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1827
1950
|
// and before the dry-run return, so `--dry-run` reports the same refusal.
|
|
1828
1951
|
const executor = deps.executorProvisioning;
|
|
1829
1952
|
const local = deps.localProvisioning;
|
|
1830
|
-
const
|
|
1831
|
-
if (preflight.kind === "refused")
|
|
1832
|
-
return 1;
|
|
1833
|
-
const executorPlans = preflight.plans;
|
|
1953
|
+
const executorPlans = earlyPreflight.plans;
|
|
1834
1954
|
// ---- BAPI-1391: the repository gate, decided BEFORE any write ----------
|
|
1835
1955
|
// Capability probe first (a read, after the base-URL consent), then the stored
|
|
1836
1956
|
// gate, explicit gate flags, or a discovery proposal the owner confirms. Under
|
|
@@ -1840,7 +1960,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1840
1960
|
return 1;
|
|
1841
1961
|
}
|
|
1842
1962
|
const gatePhase = await resolveConductorGate(gateIo, access, options.gate, deps.gate, {
|
|
1843
|
-
dryRun: options.dryRun,
|
|
1963
|
+
dryRun: options.dryRun, planningOnly: true,
|
|
1844
1964
|
});
|
|
1845
1965
|
if (gatePhase.kind === "exit")
|
|
1846
1966
|
return gatePhase.code;
|
|
@@ -1853,6 +1973,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1853
1973
|
if (options.dryRun) {
|
|
1854
1974
|
deps.log("");
|
|
1855
1975
|
deps.log("Dry run — no writes will be performed.");
|
|
1976
|
+
if (gatePlan !== null)
|
|
1977
|
+
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
1856
1978
|
if (gatePlan === null) {
|
|
1857
1979
|
deps.log(" Repository gate: none confirmed — a real run asks you to confirm one before any write.");
|
|
1858
1980
|
}
|
|
@@ -1940,104 +2062,12 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1940
2062
|
// replacing bootstrap when the server cannot preview.
|
|
1941
2063
|
deps.log("");
|
|
1942
2064
|
deps.log("Phase 2/8 — bootstrapping supervisor project defaults…");
|
|
1943
|
-
const
|
|
1944
|
-
|
|
1945
|
-
// BAPI-694 — the narrow ReviewPolicy object, sent ONLY on an explicit
|
|
1946
|
-
// selection. `review_source` is deliberately NOT sent: on an existing
|
|
1947
|
-
// repository an omitted field keeps its stored value, and a new repository
|
|
1948
|
-
// receives the server's `verdict_protocol` default either way.
|
|
1949
|
-
...(options.reviewPolicyExplicit
|
|
1950
|
-
? { review_policy: { source: options.reviewPolicy } }
|
|
1951
|
-
: {}),
|
|
1952
|
-
merge_approval_required: "true",
|
|
1953
|
-
...(options.replaceDoneGate ? { replace_done_gate: true } : {}),
|
|
1954
|
-
};
|
|
1955
|
-
// BAPI-1391 — the gate is stored FIRST, under its own combined consent, in
|
|
1956
|
-
// two cases:
|
|
1957
|
-
// * a gate with no provider checks (local-only or `none`): the server
|
|
1958
|
-
// accepts an empty CI list only for a stored gate of that kind;
|
|
1959
|
-
// * any change to an already STORED gate: the bootstrap apply would
|
|
1960
|
-
// otherwise run BAPI-1390's profile sync first, which merges the additive
|
|
1961
|
-
// CI list into the stored profile under a new revision — so a later PUT
|
|
1962
|
-
// would be refused as stale while the gate had silently been widened.
|
|
1963
|
-
// Stored first, the CI checks already equal the gate, the bootstrap adds
|
|
1964
|
-
// nothing, and the sync has nothing to change.
|
|
1965
|
-
// A legacy or unconfirmed repository keeps the original order (preview,
|
|
1966
|
-
// consent, apply) and is stored after the apply; the sync never touches it.
|
|
1967
|
-
const gateFirst = gatePlan.write !== null &&
|
|
1968
|
-
(bootstrapChecks.length === 0 || gatePlan.current.source === "stored");
|
|
1969
|
-
let storedGate = gatePlan.write === null ? gatePlan.current : null;
|
|
1970
|
-
if (gateFirst) {
|
|
1971
|
-
deps.log("");
|
|
1972
|
-
const gateOk = await confirm(deps, "Store this repository gate and write the safe project-default supervisor posture now? [y/N]: ");
|
|
1973
|
-
if (!gateOk) {
|
|
1974
|
-
deps.log("Aborted — no server write was attempted.");
|
|
1975
|
-
return 0;
|
|
1976
|
-
}
|
|
1977
|
-
storedGate = await storeConductorGate(gateIo, access, gatePlan);
|
|
1978
|
-
if (storedGate === null)
|
|
1979
|
-
return 1;
|
|
1980
|
-
}
|
|
1981
|
-
let preview;
|
|
1982
|
-
try {
|
|
1983
|
-
preview = await previewConductorSupervisorBootstrap(access, bootstrapRequest, deps.postJson);
|
|
1984
|
-
}
|
|
1985
|
-
catch (err) {
|
|
1986
|
-
reportBootstrapFailure(deps, "preview", classifySupervisorBootstrapFailure(err));
|
|
2065
|
+
const combined = await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
2066
|
+
if (combined.status === "deferred" || combined.status === "unknown")
|
|
1987
2067
|
return 1;
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
// Deliberately separate from the base-URL consent above (which was given
|
|
1992
|
-
// before any network call). Confirming WHERE to write is not consent TO write.
|
|
1993
|
-
// A gate stored first above was stored under its own combined consent.
|
|
1994
|
-
if (!gateFirst) {
|
|
1995
|
-
deps.log("");
|
|
1996
|
-
const bootstrapOk = await confirm(deps, "Write the safe project-default supervisor posture now? [y/N]: ");
|
|
1997
|
-
if (!bootstrapOk) {
|
|
1998
|
-
deps.log("Aborted — no server write was attempted.");
|
|
1999
|
-
return 0;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
// ---- Consent #3: the EXACT gate change, only when the preview needs it ---
|
|
2003
|
-
// Never inferred from consent #2: agreeing to install is not agreeing to
|
|
2004
|
-
// remove a configured requirement. A missing prompt seam is a refusal.
|
|
2005
|
-
let applyRequest = bootstrapRequest;
|
|
2006
|
-
if (preview.approval_required) {
|
|
2007
|
-
deps.log("");
|
|
2008
|
-
const gateChangeOk = await confirm(deps, "Approve EXACTLY the gate changes listed above? [y/N]: ");
|
|
2009
|
-
if (!gateChangeOk || !preview.approval_token) {
|
|
2010
|
-
deps.errorLog("Gate change not approved — no server write was attempted, and every configured " +
|
|
2011
|
-
"requirement is unchanged.");
|
|
2012
|
-
return 1;
|
|
2013
|
-
}
|
|
2014
|
-
applyRequest = {
|
|
2015
|
-
...bootstrapRequest,
|
|
2016
|
-
approval: { approve: true, approval_token: preview.approval_token },
|
|
2017
|
-
};
|
|
2018
|
-
}
|
|
2019
|
-
let bootstrapResponse;
|
|
2020
|
-
try {
|
|
2021
|
-
bootstrapResponse = await bootstrapConductorSupervisorDefaults(access, applyRequest, deps.postJson);
|
|
2022
|
-
}
|
|
2023
|
-
catch (err) {
|
|
2024
|
-
reportBootstrapFailure(deps, "apply", classifySupervisorBootstrapFailure(err));
|
|
2025
|
-
return 1;
|
|
2026
|
-
}
|
|
2027
|
-
if (bootstrapResponse.setup_outcome === null || bootstrapResponse.config_outcome === null) {
|
|
2028
|
-
reportBootstrapFailure(deps, "apply", "unsupported-protocol");
|
|
2029
|
-
return 1;
|
|
2030
|
-
}
|
|
2031
|
-
renderBootstrapOutcome(deps, bootstrapResponse);
|
|
2032
|
-
// ---- BAPI-1391: store the confirmed gate, then offer its qualification --
|
|
2033
|
-
// Stored after the apply so the bootstrap's additive CI write cannot widen
|
|
2034
|
-
// the gate's exact provider checks: the gate PUT rewrites that projection to
|
|
2035
|
-
// exactly the confirmed checks, under the server's revision compare-and-swap.
|
|
2036
|
-
if (storedGate === null) {
|
|
2037
|
-
storedGate = await storeConductorGate(gateIo, access, gatePlan);
|
|
2038
|
-
if (storedGate === null)
|
|
2039
|
-
return 1;
|
|
2040
|
-
}
|
|
2068
|
+
const storedGate = combined.current
|
|
2069
|
+
? { revision: combined.current.state.revision, qualification_state: combined.current.policy.qualification }
|
|
2070
|
+
: gatePlan.current;
|
|
2041
2071
|
const manualActions = [];
|
|
2042
2072
|
if (gatePlan.desired.localCommands.length > 0) {
|
|
2043
2073
|
const qualified = storedGate.qualification_state === "qualified";
|
|
@@ -2147,7 +2177,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2147
2177
|
}
|
|
2148
2178
|
else {
|
|
2149
2179
|
deps.log(" skipped — this caller supplied no local-provisioning seams.");
|
|
2150
|
-
manualActions.push("tool visibility: run the packaged `install
|
|
2180
|
+
manualActions.push("tool visibility: run the packaged `install epic-implementer` command to add the " +
|
|
2151
2181
|
"`epic_implementer` profile to your host MCP configuration.");
|
|
2152
2182
|
}
|
|
2153
2183
|
deps.log("");
|
|
@@ -2160,7 +2190,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2160
2190
|
}
|
|
2161
2191
|
else {
|
|
2162
2192
|
deps.log(" skipped — this caller supplied no local-provisioning seams.");
|
|
2163
|
-
manualActions.push("local observability: run the packaged `install
|
|
2193
|
+
manualActions.push("local observability: run the packaged `install epic-implementer` command, or " +
|
|
2164
2194
|
"`epic-implementer install-git-hooks`, to install the managed Git hooks.");
|
|
2165
2195
|
}
|
|
2166
2196
|
// The fail-loud hook-binary refusal (a package that ships no hook binary)
|
|
@@ -2224,7 +2254,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2224
2254
|
let postReadiness = observedReadiness;
|
|
2225
2255
|
if (postReadiness === null) {
|
|
2226
2256
|
try {
|
|
2227
|
-
postReadiness = await fetchConductorReadiness(access, deps.fetchJson);
|
|
2257
|
+
postReadiness = await fetchConductorReadiness(access, deps.fetchJson, { assessmentVersion: 1, epicRunId: options.assessmentEpicRunId });
|
|
2228
2258
|
}
|
|
2229
2259
|
catch {
|
|
2230
2260
|
// Degraded, not fatal: the write already succeeded, and the matrix simply
|
|
@@ -2238,6 +2268,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2238
2268
|
const finalReport = await deps.runDoctor({
|
|
2239
2269
|
access,
|
|
2240
2270
|
reviewPolicySource: options.reviewPolicy,
|
|
2271
|
+
assessmentVersion: 1,
|
|
2272
|
+
epicRunId: options.assessmentEpicRunId,
|
|
2241
2273
|
});
|
|
2242
2274
|
deps.log(formatConductorInstallDoctorReport(finalReport));
|
|
2243
2275
|
// Manual actions (BAPI-775): every declined, unavailable, empty, or incomplete
|
|
@@ -2317,23 +2349,48 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
|
|
|
2317
2349
|
catch {
|
|
2318
2350
|
testCommand = { state: "unknown" };
|
|
2319
2351
|
}
|
|
2352
|
+
// The toolchains, read once from the working tree. Kept apart from the
|
|
2353
|
+
// non-sensitive readiness evidence below: they are an input to the workflow
|
|
2354
|
+
// assessment and to operator-only output, never a readiness row.
|
|
2355
|
+
const toolchains = await resolveRepositoryToolchains((relPath) => setup.readRepositoryFile(relPath));
|
|
2320
2356
|
// The managed workflow, through the installer's own read-only preflight.
|
|
2321
2357
|
let workflow = { state: "unknown" };
|
|
2322
2358
|
if (storedCommand === null) {
|
|
2323
2359
|
workflow = testCommand.state === "missing" ? { state: "needs_command" } : { state: "unknown" };
|
|
2324
2360
|
}
|
|
2361
|
+
else if (inputs.commandBlocked === true) {
|
|
2362
|
+
// A failed command verification blocks every later workflow step, including
|
|
2363
|
+
// this closing read: the workflow would be judged against a command nobody
|
|
2364
|
+
// confirmed.
|
|
2365
|
+
workflow = { state: "blocked", remedy: COMMAND_UNVERIFIED_WORKFLOW_REMEDY };
|
|
2366
|
+
}
|
|
2325
2367
|
else if (inputs.githubSignIn === "signed_in") {
|
|
2326
|
-
workflow = await assessWorkflow(setup, storedCommand);
|
|
2368
|
+
workflow = await assessWorkflow(setup, storedCommand, toolchains, inputs.commandChanged === true);
|
|
2327
2369
|
}
|
|
2328
2370
|
// The setup pull request and, once it merged, the index.
|
|
2329
2371
|
let setupPullRequest = { state: "unknown" };
|
|
2330
2372
|
let index = { state: "not_applicable" };
|
|
2373
|
+
let recovery;
|
|
2331
2374
|
if (repository !== null && inputs.githubSignIn === "signed_in") {
|
|
2332
2375
|
setupPullRequest = await readSetupPullRequest(setup.runGh, repository);
|
|
2333
2376
|
index = await assessSetupIndex(setupPullRequest, () => setup.fetchParseStatus(access), (mergeSha, indexedSha) => compareIndexedToMerge(setup.runGh, repository, mergeSha, indexedSha));
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2377
|
+
if (setupPullRequest.state === "merged" && setup.fetchRecoveryEvidence) {
|
|
2378
|
+
const prefix = `https://github.com/${repository}/pull/`;
|
|
2379
|
+
const numberText = setupPullRequest.url.startsWith(prefix) ? setupPullRequest.url.slice(prefix.length) : "";
|
|
2380
|
+
const prNumber = /^[1-9][0-9]*$/.test(numberText) ? Number(numberText) : NaN;
|
|
2381
|
+
recovery = Number.isSafeInteger(prNumber) ? await setup.fetchRecoveryEvidence(access, prNumber) : { supported: false, reason: "evidence_unavailable" };
|
|
2382
|
+
if (recovery.supported) {
|
|
2383
|
+
const r = recovery.evidence;
|
|
2384
|
+
if (r.canonical.verified && ["equal", "contains_target"].includes(r.canonical_relation))
|
|
2385
|
+
index = { state: "reached" };
|
|
2386
|
+
else if (r.reason)
|
|
2387
|
+
index = { state: "unknown" };
|
|
2388
|
+
else if (r.request && ["queued", "in_progress"].includes(r.request.status ?? ""))
|
|
2389
|
+
index = { state: "recovery_pending", requestId: r.request.id, runId: r.request.parse_run_id };
|
|
2390
|
+
else if (r.canonical_relation === "behind" || r.canonical_relation === "diverged")
|
|
2391
|
+
index = { state: r.canonical_relation };
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2337
2394
|
}
|
|
2338
2395
|
const mergeCredential = await assessMergeCredential(deps, setup, readiness, identity);
|
|
2339
2396
|
return {
|
|
@@ -2346,6 +2403,7 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
|
|
|
2346
2403
|
workflow,
|
|
2347
2404
|
setupPullRequest,
|
|
2348
2405
|
index,
|
|
2406
|
+
...(recovery ? { recovery } : {}),
|
|
2349
2407
|
mergeCredential,
|
|
2350
2408
|
gateChangeDeclined: inputs.gateChangeDeclined,
|
|
2351
2409
|
advisories: inputs.advisories,
|
|
@@ -2353,13 +2411,32 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
|
|
|
2353
2411
|
identity,
|
|
2354
2412
|
repository,
|
|
2355
2413
|
storedCommand,
|
|
2414
|
+
toolchains,
|
|
2356
2415
|
};
|
|
2357
2416
|
}
|
|
2358
|
-
/**
|
|
2359
|
-
|
|
2417
|
+
/** The remedy shown for the workflow once a command write could not be verified. */
|
|
2418
|
+
const COMMAND_UNVERIFIED_WORKFLOW_REMEDY = "the test command could not be verified, so the CI workflow is not built from it; fix that first, then re-run setup";
|
|
2419
|
+
/** The remedy when the repository's dependency files could not be inspected. Names files, never content. */
|
|
2420
|
+
function toolchainInspectionRemedy(resolution) {
|
|
2421
|
+
const files = resolution.failures.map((f) => f.file).join(", ");
|
|
2422
|
+
return (`Bridge could not inspect ${files} to choose what CI installs, and it will not guess. ` +
|
|
2423
|
+
"Fix the file or its permissions, then re-run setup");
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Classify the managed workflow with the installer's read-only dry run.
|
|
2427
|
+
*
|
|
2428
|
+
* `commandChanged` marks a command written during this run: the workflow must
|
|
2429
|
+
* then change too, so a local precondition that stops the preflight (a dirty
|
|
2430
|
+
* worktree) is a known outstanding change and must not be hidden by an older
|
|
2431
|
+
* server-ready workflow fact.
|
|
2432
|
+
*/
|
|
2433
|
+
async function assessWorkflow(setup, testCommand, toolchains, commandChanged = false) {
|
|
2434
|
+
if (toolchains.status === "unknown") {
|
|
2435
|
+
return { state: "blocked", remedy: toolchainInspectionRemedy(toolchains) };
|
|
2436
|
+
}
|
|
2360
2437
|
let result;
|
|
2361
2438
|
try {
|
|
2362
|
-
result = await setup.installCiWorkflow(testCommand, { dryRun: true, quiet: true });
|
|
2439
|
+
result = await setup.installCiWorkflow(testCommand, toolchains.toolchains, { dryRun: true, quiet: true });
|
|
2363
2440
|
}
|
|
2364
2441
|
catch {
|
|
2365
2442
|
return { state: "unknown" };
|
|
@@ -2377,9 +2454,12 @@ async function assessWorkflow(setup, testCommand) {
|
|
|
2377
2454
|
return { state: "unknown" };
|
|
2378
2455
|
case "failed":
|
|
2379
2456
|
if (result.reason === "worktree_not_clean" || result.reason === "not_repository_root") {
|
|
2380
|
-
return
|
|
2457
|
+
return commandChanged
|
|
2458
|
+
? { state: "blocked", remedy: result.remediation }
|
|
2459
|
+
: { state: "precondition", remedy: result.remediation };
|
|
2381
2460
|
}
|
|
2382
|
-
return result.prUrl !== undefined &&
|
|
2461
|
+
return result.prUrl !== undefined &&
|
|
2462
|
+
(result.reason === "existing_pr_differs" || result.reason === "historical_managed_pr_open")
|
|
2383
2463
|
? { state: "blocked", remedy: `${result.remediation} (${result.prUrl})` }
|
|
2384
2464
|
: { state: "blocked", remedy: result.remediation };
|
|
2385
2465
|
}
|
|
@@ -2463,147 +2543,303 @@ function gateOrDefaultsNeedWrite(gatePlan, readiness) {
|
|
|
2463
2543
|
return false;
|
|
2464
2544
|
return !readiness.supervisor.setup_present || !readiness.supervisor.config_present;
|
|
2465
2545
|
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
return (
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
preview.config_outcome !== "preserved");
|
|
2546
|
+
function bootstrapRequestFor(options, plan) {
|
|
2547
|
+
const { action, confirm, expected_revision, ...gate } = plan.write ?? confirmRequestFor(plan.desired, plan.current.revision, plan.current.profile);
|
|
2548
|
+
return { protocol: SETUP_POLICY_PROTOCOL, ...(plan.write !== null ? { gate } : {}),
|
|
2549
|
+
defaults: { ...(options.reviewPolicyExplicit ? { review_policy: { source: options.reviewPolicy } } : {}),
|
|
2550
|
+
merge_approval_required: "true" }, replace_done_gate: options.replaceDoneGate === true };
|
|
2472
2551
|
}
|
|
2473
|
-
function
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2552
|
+
function policyMatches(expected, actual) {
|
|
2553
|
+
const canonical = (value) => {
|
|
2554
|
+
if (Array.isArray(value))
|
|
2555
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
2556
|
+
if (value && typeof value === "object")
|
|
2557
|
+
return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
2558
|
+
return JSON.stringify(value);
|
|
2479
2559
|
};
|
|
2560
|
+
return canonical(expected) === canonical(actual);
|
|
2480
2561
|
}
|
|
2481
|
-
/**
|
|
2482
|
-
* Fix: store the repository gate and the safe supervisor defaults, under ONE
|
|
2483
|
-
* consent for this surface (plus the separate exact approval a weakening change
|
|
2484
|
-
* needs). Never inferred from the setup-PR or any other consent.
|
|
2485
|
-
*/
|
|
2486
2562
|
async function fixGateAndDefaults(deps, options, access, gatePlan) {
|
|
2487
|
-
const
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2563
|
+
const request = bootstrapRequestFor(options, gatePlan);
|
|
2564
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
2565
|
+
let preview;
|
|
2566
|
+
try {
|
|
2567
|
+
preview = await previewConductorSetupPolicy(access, request, deps.postJson);
|
|
2568
|
+
}
|
|
2569
|
+
catch {
|
|
2570
|
+
deps.log("Deferred: combined setup policy is unavailable or unsupported. Rerun with a compatible server; ask a bootstrap administrator if this persists.");
|
|
2571
|
+
return { status: "deferred" };
|
|
2572
|
+
}
|
|
2573
|
+
deps.log(`Proposed required checks: ${gatePlan.desired.providerChecks.join(", ") || "none"}`);
|
|
2574
|
+
for (const effect of preview.effects)
|
|
2575
|
+
deps.log(`${effect.category}: ${JSON.stringify(effect.before)} → ${JSON.stringify(effect.after)}`);
|
|
2576
|
+
if (options.dryRun) {
|
|
2577
|
+
deps.log("Dry run: combined preview only; no policy was applied.");
|
|
2578
|
+
return { status: "deferred" };
|
|
2579
|
+
}
|
|
2580
|
+
if (!preview.approval_required) {
|
|
2581
|
+
deps.log("No change: combined policy already matches.");
|
|
2582
|
+
return { status: "unchanged" };
|
|
2583
|
+
}
|
|
2584
|
+
const decision = await askSetupQuestion({
|
|
2585
|
+
purpose: "Authorize exactly the combined repository policy changes shown above.",
|
|
2586
|
+
prompt: "Apply these consequential policy changes? [y/N]: ",
|
|
2587
|
+
evidence: ["The server computed these effects from one locked policy snapshot.",
|
|
2588
|
+
"Existing epic overrides keep precedence. Failed or unknown CI evidence does not relax admission."],
|
|
2589
|
+
options: [{ id: "yes", label: "Apply this exact policy" }, { id: "no", label: "Keep policy unchanged" }],
|
|
2590
|
+
consequences: ["Required checks can prevent merges. Local commands require qualification; changed commands can invalidate it.",
|
|
2591
|
+
"Gate and supervisor defaults commit together, preserving omitted settings."],
|
|
2592
|
+
deferred: "Coupled policy remains unchanged; independent setup work can continue.",
|
|
2593
|
+
recovery: "Rerun setup for a fresh preview; contact the bootstrap administrator if unavailable.",
|
|
2594
|
+
}, { read: deps.promptLine, write: deps.log });
|
|
2595
|
+
if (decision.status !== "accept") {
|
|
2596
|
+
deps.log("Deferred: combined policy was not approved.");
|
|
2597
|
+
return { status: "deferred" };
|
|
2598
|
+
}
|
|
2599
|
+
let current;
|
|
2600
|
+
let appliedState;
|
|
2601
|
+
let uncertain = false;
|
|
2602
|
+
try {
|
|
2603
|
+
appliedState = (await applyConductorSetupPolicy(access, request, preview, true, deps.postJson)).state;
|
|
2604
|
+
}
|
|
2605
|
+
catch (error) {
|
|
2606
|
+
uncertain = true;
|
|
2607
|
+
if (error instanceof ConductorSetupPolicyError && error.reason === "stale" && attempt === 0 && deps.promptLine) {
|
|
2608
|
+
deps.log("Policy changed: refreshing the preview once. The new effects require a new answer.");
|
|
2609
|
+
continue;
|
|
2610
|
+
}
|
|
2611
|
+
if (error instanceof ConductorSetupPolicyError && ["refused", "stale", "unsupported"].includes(error.reason)) {
|
|
2612
|
+
deps.log("Deferred: policy was refused or changed. Rerun for a fresh preview.");
|
|
2613
|
+
return { status: "deferred" };
|
|
2516
2614
|
}
|
|
2517
|
-
applyRequest = { ...request, approval: { approve: true, approval_token: preview.approval_token } };
|
|
2518
2615
|
}
|
|
2519
|
-
let response;
|
|
2520
2616
|
try {
|
|
2521
|
-
|
|
2617
|
+
current = await fetchConductorSetupPolicy(access, deps.fetchJson);
|
|
2522
2618
|
}
|
|
2523
|
-
catch
|
|
2524
|
-
|
|
2525
|
-
return
|
|
2619
|
+
catch {
|
|
2620
|
+
deps.log("Unknown—verify before retrying: policy apply could not be confirmed. Ask the bootstrap administrator.");
|
|
2621
|
+
return { status: "unknown" };
|
|
2526
2622
|
}
|
|
2527
|
-
if (
|
|
2528
|
-
|
|
2529
|
-
|
|
2623
|
+
if (uncertain
|
|
2624
|
+
|| (appliedState !== undefined && !policyMatches(appliedState, current.state))
|
|
2625
|
+
|| !policyMatches(preview.after, current.policy) || current.state.generation <= preview.state.generation
|
|
2626
|
+
|| current.state.revision < preview.state.revision) {
|
|
2627
|
+
deps.log("Unknown—verify before retrying: coherent read-back does not confirm the intended complete policy.");
|
|
2628
|
+
return { status: "unknown" };
|
|
2530
2629
|
}
|
|
2531
|
-
|
|
2630
|
+
deps.log("Completed: coherent server state matches the intended policy.");
|
|
2631
|
+
return { status: "completed", current };
|
|
2532
2632
|
}
|
|
2533
|
-
|
|
2534
|
-
|
|
2633
|
+
return { status: "deferred" };
|
|
2634
|
+
}
|
|
2635
|
+
/**
|
|
2636
|
+
* Write failures that are a definite refusal: the server answered and said no.
|
|
2637
|
+
* Every other failure is UNCERTAIN (the write may have landed), so it is read
|
|
2638
|
+
* back and never retried.
|
|
2639
|
+
*/
|
|
2640
|
+
const DEFINITE_WRITE_REFUSALS = new Set([
|
|
2641
|
+
"unauthenticated",
|
|
2642
|
+
"forbidden",
|
|
2643
|
+
"not_found",
|
|
2644
|
+
"invalid_command",
|
|
2645
|
+
]);
|
|
2646
|
+
/**
|
|
2647
|
+
* Validate `requested`, attempt ONE write, then read the stored value back.
|
|
2648
|
+
*
|
|
2649
|
+
* - Invalid input is never sent.
|
|
2650
|
+
* - A definite refusal (unauthenticated, forbidden, not found, invalid) stops
|
|
2651
|
+
* there: nothing changed, so there is nothing to verify.
|
|
2652
|
+
* - An accepted write and an uncertain one are both read back. The write is
|
|
2653
|
+
* never retried.
|
|
2654
|
+
* - Success needs BOTH an accepted write and a read-back equal to the validated
|
|
2655
|
+
* requested value.
|
|
2656
|
+
*/
|
|
2657
|
+
export async function saveAndReadBackTestCommand(config, requested) {
|
|
2658
|
+
let command;
|
|
2659
|
+
try {
|
|
2660
|
+
command = validateTestCommand(requested);
|
|
2535
2661
|
}
|
|
2536
|
-
|
|
2537
|
-
return
|
|
2662
|
+
catch (err) {
|
|
2663
|
+
return { kind: "invalid_input", reason: err instanceof TestCommandValidationError ? err.reason : "invalid" };
|
|
2538
2664
|
}
|
|
2539
|
-
|
|
2665
|
+
let written;
|
|
2666
|
+
try {
|
|
2667
|
+
written = await writeStoredTestCommand(config, command);
|
|
2668
|
+
}
|
|
2669
|
+
catch {
|
|
2670
|
+
written = { ok: false, reason: "transport_failure", status: 0 };
|
|
2671
|
+
}
|
|
2672
|
+
if (!written.ok && DEFINITE_WRITE_REFUSALS.has(written.reason)) {
|
|
2673
|
+
return { kind: "write_failed", reason: written.reason, stored: undefined };
|
|
2674
|
+
}
|
|
2675
|
+
let readBack;
|
|
2676
|
+
try {
|
|
2677
|
+
readBack = await readStoredTestCommand(config);
|
|
2678
|
+
}
|
|
2679
|
+
catch {
|
|
2680
|
+
readBack = { ok: false, reason: "transport_failure", status: 0 };
|
|
2681
|
+
}
|
|
2682
|
+
if (!written.ok) {
|
|
2683
|
+
return { kind: "write_failed", reason: written.reason, stored: readBack.ok ? readBack.testCommand : undefined };
|
|
2684
|
+
}
|
|
2685
|
+
if (!readBack.ok)
|
|
2686
|
+
return { kind: "unreadable_verification" };
|
|
2687
|
+
if (readBack.testCommand !== command)
|
|
2688
|
+
return { kind: "read_back_mismatch", stored: readBack.testCommand };
|
|
2689
|
+
return { kind: "confirmed", testCommand: readBack.testCommand };
|
|
2690
|
+
}
|
|
2691
|
+
const COMMAND_NOT_ATTEMPTED = { confirmed: null, failure: null, serverValue: undefined };
|
|
2692
|
+
/** The blocking operation result for a failed command write. Fixed text, no command. */
|
|
2693
|
+
function testCommandOperationFailure(remedy) {
|
|
2694
|
+
return {
|
|
2695
|
+
id: "test-command-save",
|
|
2696
|
+
label: "Test command",
|
|
2697
|
+
state: "needs_action",
|
|
2698
|
+
blocking: true,
|
|
2699
|
+
remedy,
|
|
2700
|
+
};
|
|
2540
2701
|
}
|
|
2541
2702
|
/**
|
|
2542
|
-
*
|
|
2543
|
-
*
|
|
2544
|
-
*
|
|
2703
|
+
* Report a non-confirmed outcome in fixed, sanitized words and build its blocking
|
|
2704
|
+
* operation result. Never prints the requested command, an upstream error body,
|
|
2705
|
+
* or exception text.
|
|
2545
2706
|
*/
|
|
2707
|
+
function reportTestCommandSaveFailure(deps, outcome, verb) {
|
|
2708
|
+
const head = `Test command not ${verb}`;
|
|
2709
|
+
switch (outcome.kind) {
|
|
2710
|
+
case "invalid_input":
|
|
2711
|
+
deps.log(` ${head} — that command cannot be stored (${outcome.reason}).`);
|
|
2712
|
+
return {
|
|
2713
|
+
confirmed: null,
|
|
2714
|
+
failure: testCommandOperationFailure("give a valid one-line command with --test-command, then re-run setup"),
|
|
2715
|
+
serverValue: undefined,
|
|
2716
|
+
};
|
|
2717
|
+
case "write_failed":
|
|
2718
|
+
deps.log(` ${head} — the save did not complete (${outcome.reason}).`);
|
|
2719
|
+
return {
|
|
2720
|
+
confirmed: null,
|
|
2721
|
+
failure: testCommandOperationFailure(outcome.reason === "forbidden" || outcome.reason === "unauthenticated"
|
|
2722
|
+
? "this key cannot change the stored test command; use an administrator key, then re-run setup"
|
|
2723
|
+
: "the save did not complete; check the connection and re-run setup"),
|
|
2724
|
+
serverValue: outcome.stored,
|
|
2725
|
+
};
|
|
2726
|
+
case "unreadable_verification":
|
|
2727
|
+
deps.log(` ${head} — save may have succeeded; verification failed.`);
|
|
2728
|
+
return {
|
|
2729
|
+
confirmed: null,
|
|
2730
|
+
failure: testCommandOperationFailure("the save may have succeeded but could not be verified; re-run setup to read the stored command"),
|
|
2731
|
+
serverValue: undefined,
|
|
2732
|
+
};
|
|
2733
|
+
case "read_back_mismatch":
|
|
2734
|
+
deps.log(` ${head}. The stored value is not the one requested.`);
|
|
2735
|
+
return {
|
|
2736
|
+
confirmed: null,
|
|
2737
|
+
failure: testCommandOperationFailure("the stored value differs from the requested one; check the stored command and re-run setup"),
|
|
2738
|
+
serverValue: outcome.stored,
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
/** Run one save/replace and turn it into a fix result, logging the outcome. */
|
|
2743
|
+
async function persistTestCommand(deps, config, command, verb) {
|
|
2744
|
+
const outcome = await saveAndReadBackTestCommand(config, command);
|
|
2745
|
+
if (outcome.kind !== "confirmed")
|
|
2746
|
+
return reportTestCommandSaveFailure(deps, outcome, verb);
|
|
2747
|
+
deps.log(` ${verb} — the stored test command is now in place.`);
|
|
2748
|
+
return { confirmed: outcome.testCommand, failure: null, serverValue: outcome.testCommand };
|
|
2749
|
+
}
|
|
2750
|
+
/** Resolve named alternatives separately from custom command input. */
|
|
2546
2751
|
async function fixTestCommand(deps, setup, access) {
|
|
2547
2752
|
const config = setup.testingConfig(access);
|
|
2548
|
-
deps.log("");
|
|
2549
|
-
deps.log("Test command");
|
|
2550
2753
|
let detection;
|
|
2551
2754
|
try {
|
|
2552
|
-
detection = await detectTestCommand({ skipStoredRead: true }, { config, readFile:
|
|
2755
|
+
detection = await detectTestCommand({ skipStoredRead: true }, { config, readFile: relPath => setup.readRepositoryFile(relPath) });
|
|
2553
2756
|
}
|
|
2554
2757
|
catch {
|
|
2555
2758
|
detection = { status: "failed", reason: "repository_read_failed" };
|
|
2556
2759
|
}
|
|
2557
2760
|
let command = null;
|
|
2558
|
-
if (detection.status === "
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2761
|
+
if (detection.status === "stored")
|
|
2762
|
+
return { confirmed: detection.selected, failure: null, serverValue: detection.selected };
|
|
2763
|
+
if (detection.status === "detected" && detection.question === "none"
|
|
2764
|
+
&& detection.candidates[0]?.autoSaveEligible) {
|
|
2765
|
+
const candidate = detection.candidates[0];
|
|
2766
|
+
deps.log(`Test command: ${candidate.command}; source: ${candidate.provenance}; runner: ${candidate.runner}; directory: ${candidate.workingDirectory}.`);
|
|
2767
|
+
deps.log("Saving this one eligible test command for future CI and verification. Saving does not execute it; execution and coverage are unverified.");
|
|
2768
|
+
command = candidate.command;
|
|
2563
2769
|
}
|
|
2564
2770
|
else {
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
command
|
|
2771
|
+
const candidates = detection.status === "failed" ? [] : detection.candidates;
|
|
2772
|
+
const terminal = { read: deps.promptLine, write: deps.log };
|
|
2773
|
+
const decision = await askSetupQuestion({
|
|
2774
|
+
purpose: "Select the test command future CI and verification will use.",
|
|
2775
|
+
evidence: detection.status === "failed" ? ["Repository inspection failed; test availability is unknown."]
|
|
2776
|
+
: candidates.map((c, i) => `${i + 1}: ${c.command} (${c.provenance}); execution unverified`),
|
|
2777
|
+
options: [...candidates.map((c, i) => ({ id: String(i + 1), label: c.command })),
|
|
2778
|
+
{ id: "custom", label: "Enter a custom command separately" }, { id: "defer", label: "Keep this step unresolved" }],
|
|
2779
|
+
consequences: ["The chosen command will be saved once and read back. This does not execute it."],
|
|
2780
|
+
deferred: "Workflow preparation remains blocked until a command is verified as saved.",
|
|
2781
|
+
recovery: 'Rerun install epic-implementer --test-command "...".',
|
|
2782
|
+
}, terminal);
|
|
2783
|
+
if (decision.status === "selected") {
|
|
2784
|
+
if (decision.id === "custom") {
|
|
2785
|
+
const custom = await readCustomSetupCommand(terminal);
|
|
2786
|
+
if (custom.status === "custom")
|
|
2787
|
+
command = custom.value;
|
|
2788
|
+
}
|
|
2789
|
+
else {
|
|
2790
|
+
command = candidates[Number(decision.id) - 1]?.command ?? null;
|
|
2791
|
+
}
|
|
2573
2792
|
}
|
|
2574
2793
|
}
|
|
2575
2794
|
if (command === null) {
|
|
2576
|
-
deps.log("
|
|
2577
|
-
return
|
|
2795
|
+
deps.log("Deferred: test command was not saved.");
|
|
2796
|
+
return COMMAND_NOT_ATTEMPTED;
|
|
2578
2797
|
}
|
|
2579
2798
|
try {
|
|
2580
2799
|
command = validateTestCommand(command);
|
|
2581
2800
|
}
|
|
2582
|
-
catch
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
return null;
|
|
2586
|
-
}
|
|
2587
|
-
const written = await writeStoredTestCommand(config, command);
|
|
2588
|
-
if (!written.ok) {
|
|
2589
|
-
deps.log(` the save did not complete (${written.reason}); reading the stored value back…`);
|
|
2801
|
+
catch {
|
|
2802
|
+
deps.log("Deferred: invalid test command.");
|
|
2803
|
+
return COMMAND_NOT_ATTEMPTED;
|
|
2590
2804
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2805
|
+
return persistTestCommand(deps, config, command, "saved");
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Fix: save or replace the test command the operator passed with
|
|
2809
|
+
* `--test-command`. The validated flag IS the consent for this one write, so the
|
|
2810
|
+
* command write never goes through {@link askConsent}. The same validation,
|
|
2811
|
+
* single write, and server read-back apply.
|
|
2812
|
+
*/
|
|
2813
|
+
async function fixExplicitTestCommand(deps, setup, access, command, hadStoredCommand) {
|
|
2814
|
+
deps.log("");
|
|
2815
|
+
deps.log("Test command");
|
|
2816
|
+
deps.log(" saving the command you passed with --test-command; that flag is the consent for this write.");
|
|
2817
|
+
return persistTestCommand(deps, setup.testingConfig(access), command, hadStoredCommand ? "replaced" : "saved");
|
|
2818
|
+
}
|
|
2819
|
+
/** The one operator-only line for a readable stored command, then what CI installs for it. */
|
|
2820
|
+
function logStoredCommandAndToolchains(deps, storedCommand, toolchains) {
|
|
2821
|
+
deps.log("");
|
|
2822
|
+
if (storedCommand !== null) {
|
|
2823
|
+
deps.log(`Test command: \`${storedCommand}\` (stored). Change it with --test-command "...".`);
|
|
2596
2824
|
}
|
|
2597
|
-
deps.log("
|
|
2598
|
-
|
|
2825
|
+
deps.log("What CI installs for it:");
|
|
2826
|
+
for (const line of describeToolchainResolution(toolchains))
|
|
2827
|
+
deps.log(` ${line}`);
|
|
2599
2828
|
}
|
|
2600
2829
|
/** Fix: open the one setup pull request through the artifact-set installer. */
|
|
2601
|
-
async function fixSetupPullRequest(deps, setup, testCommand, repository) {
|
|
2830
|
+
async function fixSetupPullRequest(deps, setup, testCommand, toolchains, repository) {
|
|
2602
2831
|
deps.log("");
|
|
2603
2832
|
deps.log("CI workflow");
|
|
2833
|
+
if (toolchains.status === "unknown") {
|
|
2834
|
+
// Uninspectable dependency files are a blocking inspection failure, never "no lockfile".
|
|
2835
|
+
const remedy = toolchainInspectionRemedy(toolchains);
|
|
2836
|
+
deps.log(` skipped — ${remedy}.`);
|
|
2837
|
+
return { workflow: { state: "blocked", remedy }, pr: null };
|
|
2838
|
+
}
|
|
2604
2839
|
let result;
|
|
2605
2840
|
try {
|
|
2606
|
-
|
|
2841
|
+
// The setup pull request has its OWN consent, separate from the command write.
|
|
2842
|
+
result = await setup.installCiWorkflow(testCommand, toolchains.toolchains, { dryRun: false }, (promptText) => askConsent(deps, promptText, "opening the setup pull request"));
|
|
2607
2843
|
}
|
|
2608
2844
|
catch {
|
|
2609
2845
|
deps.log(" the setup pull request could not be prepared; re-run setup.");
|
|
@@ -2702,34 +2938,124 @@ async function fixMergeToken(deps, setup, identity, replacing) {
|
|
|
2702
2938
|
return true;
|
|
2703
2939
|
}
|
|
2704
2940
|
/**
|
|
2705
|
-
*
|
|
2706
|
-
*
|
|
2707
|
-
* running. Concurrent runs rely on the server's coalescing.
|
|
2941
|
+
* Recovery stays unavailable until target-aware backend admission is wired.
|
|
2942
|
+
* Never fall back to a repository-only parse from content relation evidence.
|
|
2708
2943
|
*/
|
|
2709
|
-
async function fixReindex(deps, setup, access) {
|
|
2944
|
+
export async function fixReindex(deps, setup, access, initial) {
|
|
2710
2945
|
deps.log("");
|
|
2711
2946
|
deps.log("Repository indexing");
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
}
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2947
|
+
const unresolved = (remedy, choice) => {
|
|
2948
|
+
deps.log(` ${remedy}`);
|
|
2949
|
+
return { state: "recovery_unresolved", remedy, ...(choice ? { choice } : {}) };
|
|
2950
|
+
};
|
|
2951
|
+
if (!initial?.supported || !setup.fetchRecoveryEvidence || !setup.correctBranch || !setup.admitRecovery)
|
|
2952
|
+
return unresolved("Upgrade the Bridge backend/client for target-aware recovery; nothing was queued.");
|
|
2953
|
+
if (!deps.promptLine)
|
|
2954
|
+
return unresolved("Branch recovery is deferred: there is no interactive terminal. Re-run setup interactively to review the exact effect; nothing was queued.", "deferred");
|
|
2955
|
+
let current = initial.evidence;
|
|
2956
|
+
const knownUnverified = (e) => !e.canonical.verified
|
|
2957
|
+
&& ["absent", "unverified"].includes(e.canonical_observation ?? "unknown");
|
|
2958
|
+
// A definite stale refusal gets at most one new evidence review. No prior
|
|
2959
|
+
// consent survives that transition, and uncertain writes are never retried.
|
|
2960
|
+
for (let review = 0; review < 2; review++) {
|
|
2961
|
+
let corrected = false;
|
|
2962
|
+
if ((!current.canonical.verified && !knownUnverified(current)) || current.reason || !current.required_commit_sha || !current.destination_branch)
|
|
2963
|
+
return unresolved("Recovery evidence is unknown; ask your Bridge administrator to inspect the target and canonical index. Nothing was queued.");
|
|
2964
|
+
if (current.canonical.verified && ["equal", "contains_target"].includes(current.canonical_relation))
|
|
2965
|
+
return { state: "reached" };
|
|
2966
|
+
if (current.configured_relation === "unknown")
|
|
2967
|
+
return unresolved("Configured branch ancestry is unknown; inspect it before retrying. Nothing was queued.");
|
|
2968
|
+
deps.log(` setup target ${current.destination_branch}@${current.required_commit_sha}; stored branch ${JSON.stringify(current.configured_branch)}; resolved ${current.resolved_branch}@${current.resolved_head_sha}; provider default ${current.provider_default}; canonical ${current.canonical_relation}`);
|
|
2969
|
+
if (!["equal", "contains_target"].includes(current.configured_relation) || current.canonical_relation === "diverged") {
|
|
2970
|
+
const decision = await askSetupQuestion({
|
|
2971
|
+
purpose: "Choose how setup should recover the indexing branch.",
|
|
2972
|
+
evidence: [`Stored branch: ${JSON.stringify(current.configured_branch)}. Proposed destination: ${current.destination_branch}.`,
|
|
2973
|
+
`Required setup revision: ${current.required_commit_sha}; configured head: ${current.resolved_head_sha}; canonical content: ${current.canonical_relation}.`],
|
|
2974
|
+
options: [{ id: "keep", label: "Keep current configuration" }, { id: "correct", label: "Correct to the demonstrated setup destination" }, { id: "defer", label: "Defer this choice" }],
|
|
2975
|
+
consequences: [
|
|
2976
|
+
`Correct changes the shared base from ${JSON.stringify(current.configured_branch)} to ${current.destination_branch}, then admits one tracked initial parse if its read-back and fresh target evidence agree.`,
|
|
2977
|
+
"Parsing resolves the configured branch again at execution time; fetched evidence may drift from this preview.",
|
|
2978
|
+
"The shared base affects future applicable deliveries. Existing PR bases and delivery policy are unchanged; already-bound/in-flight work may still use earlier state.",
|
|
2979
|
+
"Keep preserves your branch. Setup can index it only if fresh evidence shows it contains the setup revision; otherwise integrate the setup changes there first.",
|
|
2980
|
+
], deferred: "Index recovery remains unresolved; independent completed setup work is retained.",
|
|
2981
|
+
recovery: "Inspect the branch with the repository maintainer, then re-run setup interactively.",
|
|
2982
|
+
}, { read: deps.promptLine, write: deps.log });
|
|
2983
|
+
if (decision.status !== "selected" || decision.id === "defer")
|
|
2984
|
+
return decision.status === "decline"
|
|
2985
|
+
? unresolved("Branch correction declined; the configured branch is retained and nothing was queued. Integrate the setup changes there before rerunning setup.", "declined")
|
|
2986
|
+
: unresolved("Branch choice deferred; no correction or parse was submitted. Re-run setup interactively when ready.", "deferred");
|
|
2987
|
+
if (decision.id === "keep" && !["equal", "contains_target"].includes(current.configured_relation))
|
|
2988
|
+
return unresolved(`Kept ${JSON.stringify(current.configured_branch)}. Integrate setup revision ${current.required_commit_sha} into that branch, then re-run setup; nothing was queued.`, "kept");
|
|
2989
|
+
if (decision.id === "correct") {
|
|
2990
|
+
const outcome = await setup.correctBranch(access, current.configured_branch, current.destination_branch);
|
|
2991
|
+
if (outcome === "conflict") {
|
|
2992
|
+
if (review === 1)
|
|
2993
|
+
return unresolved("Configuration changed again; the reviewed effect was discarded. Re-run setup for a fresh decision.");
|
|
2994
|
+
const refreshed = await setup.fetchRecoveryEvidence(access, current.setup_pr_number);
|
|
2995
|
+
if (!refreshed.supported)
|
|
2996
|
+
return unresolved("Configuration changed and fresh evidence is unavailable. Re-run setup; nothing was queued.");
|
|
2997
|
+
current = refreshed.evidence;
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
if (outcome !== "verified")
|
|
3001
|
+
return unresolved(`Branch correction ${outcome}; no parse was admitted. Verify the stored branch with your Bridge administrator before retrying.`);
|
|
3002
|
+
corrected = true;
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
const refreshed = await setup.fetchRecoveryEvidence(access, current.setup_pr_number);
|
|
3006
|
+
if (!refreshed.supported)
|
|
3007
|
+
return unresolved("Fresh branch evidence is unavailable; nothing was queued.");
|
|
3008
|
+
if (refreshed.evidence.required_commit_sha !== current.required_commit_sha
|
|
3009
|
+
|| refreshed.evidence.configured_branch !== (corrected ? current.destination_branch : current.configured_branch)
|
|
3010
|
+
|| (!corrected && refreshed.evidence.configuration_fingerprint !== current.configuration_fingerprint))
|
|
3011
|
+
return unresolved("Configuration or target changed after review; the effect was discarded. Re-run setup for a fresh decision; nothing was queued.");
|
|
3012
|
+
current = refreshed.evidence;
|
|
3013
|
+
if (current.canonical.verified && ["equal", "contains_target"].includes(current.canonical_relation))
|
|
3014
|
+
return { state: "reached" };
|
|
3015
|
+
if (current.reason || (!current.canonical.verified && !knownUnverified(current)) || !["equal", "contains_target"].includes(current.configured_relation))
|
|
3016
|
+
return unresolved("The reviewed branch cannot be verified to contain the setup revision; no parse was admitted.");
|
|
3017
|
+
let retry;
|
|
3018
|
+
if (current.request && ["queued", "in_progress"].includes(current.request.status ?? ""))
|
|
3019
|
+
return { state: "recovery_pending", requestId: current.request.id, runId: current.request.parse_run_id };
|
|
3020
|
+
if (current.request) {
|
|
3021
|
+
if (current.retry_generation === null)
|
|
3022
|
+
return unresolved("The retained request has no verified retry generation; inspect its history with your Bridge administrator.");
|
|
3023
|
+
const decision = await askSetupQuestion({
|
|
3024
|
+
purpose: "Authorize one explicit setup retry.", evidence: [
|
|
3025
|
+
`Prior request ${current.request.id}, run ${current.request.parse_run_id ?? "retained"}, status ${current.request.status}.`,
|
|
3026
|
+
`Canonical content relation is ${current.canonical_relation} for ${current.required_commit_sha}; configured head ${current.resolved_head_sha} contains it. Failed attempts may leave canonical content unverified; lifecycle success never proves coverage.`,
|
|
3027
|
+
`Retry generation ${current.retry_generation} for branch ${JSON.stringify(current.configured_branch)} and configuration ${current.configuration_fingerprint}.`,
|
|
3028
|
+
], options: [{ id: "retry", label: "Authorize this retry generation" }, { id: "defer", label: "Defer retry" }],
|
|
3029
|
+
consequences: ["One durable successor will resolve the configured branch at execution time. Replaying this same generation cannot create another request.", "This retry is separate from internal subprocess/worker recovery. Healthy active work is never cancelled."],
|
|
3030
|
+
deferred: "The failed or ineffective attempt remains unresolved; independent setup work is retained.", recovery: "Inspect the prior attempt, then re-run interactive setup.",
|
|
3031
|
+
}, { read: deps.promptLine, write: deps.log });
|
|
3032
|
+
if (!(decision.status === "accept" || (decision.status === "selected" && decision.id === "retry")))
|
|
3033
|
+
return decision.status === "decline"
|
|
3034
|
+
? unresolved("Retry declined; no request was submitted. Re-run setup after reviewing the prior attempt.", "declined")
|
|
3035
|
+
: unresolved("Retry deferred; no request was submitted. Re-run setup after reviewing the prior attempt.", "deferred");
|
|
3036
|
+
retry = current.retry_generation;
|
|
3037
|
+
}
|
|
3038
|
+
deps.log(` admitting one tracked ${retry === undefined ? "initial parse" : `retry generation ${retry}`} for ${current.resolved_branch}@${current.resolved_head_sha}; execution resolves the branch again.`);
|
|
3039
|
+
const admission = await setup.admitRecovery(access, current, retry);
|
|
3040
|
+
if (admission.reason === "configuration_changed")
|
|
3041
|
+
return unresolved("Configuration changed before admission; the reviewed effect was discarded. Re-run setup for a fresh review.");
|
|
3042
|
+
// One bounded read also recovers an uncertain response without another
|
|
3043
|
+
// mutation. Never mint a replacement retry identity or cancel healthy work.
|
|
3044
|
+
const observed = await setup.fetchRecoveryEvidence(access, current.setup_pr_number);
|
|
3045
|
+
if (observed.supported) {
|
|
3046
|
+
const e = observed.evidence;
|
|
3047
|
+
if (e.canonical.verified && ["equal", "contains_target"].includes(e.canonical_relation))
|
|
3048
|
+
return { state: "reached" };
|
|
3049
|
+
if (e.request && ["queued", "in_progress"].includes(e.request.status ?? "")) {
|
|
3050
|
+
deps.log(` pending request ${e.request.id}, run ${e.request.parse_run_id ?? "retained"}; re-run setup to inspect it. Observation never cancels parsing.`);
|
|
3051
|
+
return { state: "recovery_pending", requestId: e.request.id, runId: e.request.parse_run_id };
|
|
3052
|
+
}
|
|
3053
|
+
if (e.request && ["failed", "succeeded"].includes(e.request.status ?? ""))
|
|
3054
|
+
return unresolved(`Request ${e.request.id} ${e.request.status}; target coverage is still unresolved. Re-run setup to review an explicit retry.`);
|
|
3055
|
+
}
|
|
3056
|
+
return unresolved(`Admission ${admission.outcome}; inspection is incomplete. Re-run setup to inspect durable history before retrying; no cancellation was requested.`);
|
|
2730
3057
|
}
|
|
2731
|
-
|
|
2732
|
-
return { state: "queued_by_setup" };
|
|
3058
|
+
return unresolved("Configuration changed; re-run setup for a new review. Nothing was queued.");
|
|
2733
3059
|
}
|
|
2734
3060
|
/**
|
|
2735
3061
|
* `--remove-merge-token`: remove this repository's stored merge token under the
|
|
@@ -2783,46 +3109,57 @@ function localAdvisories(report) {
|
|
|
2783
3109
|
}
|
|
2784
3110
|
return out;
|
|
2785
3111
|
}
|
|
2786
|
-
/**
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
* The four pinned properties hold: base-URL consent comes before any network
|
|
2791
|
-
* call (every run, never persisted); --dry-run writes nothing; each write
|
|
2792
|
-
* surface asks for itself; and executor readiness is only ever the server's
|
|
2793
|
-
* observation.
|
|
2794
|
-
*/
|
|
2795
|
-
async function runConvergingSetup(options, deps, setup) {
|
|
2796
|
-
if (options.removeMergeToken === true)
|
|
2797
|
-
return runRemoveMergeToken(options, deps, setup);
|
|
2798
|
-
// ---- First operational check: the Claude login marker (a file read only) --
|
|
2799
|
-
let claudeLoggedIn = null;
|
|
3112
|
+
/** Non-mutating boundary shared by explicit and converging setup actions. */
|
|
3113
|
+
export async function assessEpicInstallerPrerequisites(deps, executorRequested = false) {
|
|
3114
|
+
deps.log("Epic Implementer requires a supported github.com repository, GitHub CLI and Claude Code tooling and sign-in before dependent changes. General Bridge maintenance remains available.");
|
|
3115
|
+
let observed = { claudeLoggedIn: null, githubSignIn: "unavailable", localRemote: null, toolsAvailable: false, platformSupported: false };
|
|
2800
3116
|
try {
|
|
2801
|
-
|
|
3117
|
+
if (deps.prerequisites)
|
|
3118
|
+
observed = await deps.prerequisites(executorRequested);
|
|
2802
3119
|
}
|
|
2803
|
-
catch {
|
|
2804
|
-
|
|
3120
|
+
catch { /* unknown remains blocked */ }
|
|
3121
|
+
if (deps.setup) {
|
|
3122
|
+
try {
|
|
3123
|
+
observed.claudeLoggedIn = (await deps.setup.detectClaudeLogin()).detected;
|
|
3124
|
+
}
|
|
3125
|
+
catch {
|
|
3126
|
+
observed.claudeLoggedIn = null;
|
|
3127
|
+
}
|
|
3128
|
+
try {
|
|
3129
|
+
observed.githubSignIn = await deps.setup.checkGithubSignIn();
|
|
3130
|
+
}
|
|
3131
|
+
catch {
|
|
3132
|
+
observed.githubSignIn = "unavailable";
|
|
3133
|
+
}
|
|
3134
|
+
try {
|
|
3135
|
+
observed.localRemote = await deps.setup.readLocalGithubRemote();
|
|
3136
|
+
}
|
|
3137
|
+
catch {
|
|
3138
|
+
observed.localRemote = null;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
const available = observed.claudeLoggedIn === true && observed.githubSignIn === "signed_in" && observed.localRemote !== null && observed.toolsAvailable && observed.platformSupported;
|
|
3142
|
+
if (!available) {
|
|
3143
|
+
const missing = [observed.claudeLoggedIn !== true ? "Claude Code sign-in missing or unknown" : null,
|
|
3144
|
+
observed.githubSignIn !== "signed_in" ? `GitHub sign-in ${observed.githubSignIn}` : null,
|
|
3145
|
+
!observed.localRemote ? "supported github.com origin missing or unknown" : null,
|
|
3146
|
+
!observed.toolsAvailable ? "required tools missing or unknown" : null,
|
|
3147
|
+
!observed.platformSupported ? "host/platform unsupported or unknown" : null].filter(Boolean);
|
|
3148
|
+
deps.errorLog(`Epic Implementer setup blocked: ${missing.join("; ")}. Check the github.com origin and required tools; run gh auth login and claude auth login, then rerun install epic-implementer. Dependent changes remain unavailable; general Bridge assets can be maintained separately.`);
|
|
2805
3149
|
}
|
|
2806
|
-
|
|
2807
|
-
|
|
3150
|
+
return { ...observed, available };
|
|
3151
|
+
}
|
|
3152
|
+
async function runConvergingSetup(options, deps, setup) {
|
|
3153
|
+
if (options.removeMergeToken === true)
|
|
3154
|
+
return runRemoveMergeToken(options, deps, setup);
|
|
3155
|
+
const confirmed = await resolveAndConfirmBaseUrl(options, deps, "");
|
|
2808
3156
|
if (!confirmed.ok)
|
|
2809
3157
|
return confirmed.code;
|
|
2810
3158
|
const baseUrl = confirmed.baseUrl;
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
}
|
|
2816
|
-
catch {
|
|
2817
|
-
githubSignIn = "unavailable";
|
|
2818
|
-
}
|
|
2819
|
-
let localRemote = null;
|
|
2820
|
-
try {
|
|
2821
|
-
localRemote = await setup.readLocalGithubRemote();
|
|
2822
|
-
}
|
|
2823
|
-
catch {
|
|
2824
|
-
localRemote = null;
|
|
2825
|
-
}
|
|
3159
|
+
const prerequisites = await assessEpicInstallerPrerequisites(deps, Boolean(options.executorId));
|
|
3160
|
+
if (!prerequisites.available && !options.dryRun)
|
|
3161
|
+
return 1;
|
|
3162
|
+
const { claudeLoggedIn, githubSignIn, localRemote } = prerequisites;
|
|
2826
3163
|
// ---- Repository: ask only when it is genuinely ambiguous ----------------
|
|
2827
3164
|
let accessResult = await deps.resolveAccess(options.repo, baseUrl);
|
|
2828
3165
|
if (!accessResult.ok && options.repo === undefined && deps.promptLine) {
|
|
@@ -2832,12 +3169,15 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2832
3169
|
const answer = (await deps.promptLine(suggestion !== null
|
|
2833
3170
|
? `Bridge repository name [${suggestion}]: `
|
|
2834
3171
|
: "Bridge repository name (press Enter to skip): ")).trim();
|
|
2835
|
-
const chosen = answer.length > 0 ? answer :
|
|
3172
|
+
const chosen = answer.length > 0 && !/^(y|yes|n|no)$/i.test(answer) ? answer : null;
|
|
2836
3173
|
if (chosen !== null)
|
|
2837
3174
|
accessResult = await deps.resolveAccess(chosen, baseUrl);
|
|
2838
3175
|
}
|
|
2839
3176
|
const access = accessResult.ok ? accessResult.access : null;
|
|
2840
3177
|
const accessError = accessResult.ok ? undefined : accessResult.error;
|
|
3178
|
+
const earlyPreflight = await runExecutorPreflightPhase(options, deps, baseUrl, access);
|
|
3179
|
+
if (earlyPreflight.kind === "refused")
|
|
3180
|
+
return 1;
|
|
2841
3181
|
const gateIo = gateIoFor(deps);
|
|
2842
3182
|
const standalone = await runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl);
|
|
2843
3183
|
if (standalone !== null)
|
|
@@ -2850,6 +3190,8 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2850
3190
|
access,
|
|
2851
3191
|
accessError,
|
|
2852
3192
|
reviewPolicySource: options.reviewPolicy,
|
|
3193
|
+
assessmentVersion: 1,
|
|
3194
|
+
epicRunId: options.assessmentEpicRunId,
|
|
2853
3195
|
skipDenyProbe: true,
|
|
2854
3196
|
storedMergeCredential: storedContext,
|
|
2855
3197
|
});
|
|
@@ -2862,13 +3204,11 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2862
3204
|
deps.log("complete-with-manual-steps");
|
|
2863
3205
|
return 1;
|
|
2864
3206
|
}
|
|
2865
|
-
const
|
|
2866
|
-
if (preflight.kind === "refused")
|
|
2867
|
-
return 1;
|
|
2868
|
-
const executorPlans = preflight.plans;
|
|
3207
|
+
const executorPlans = earlyPreflight.plans;
|
|
2869
3208
|
// ---- The gate: explicit flags win; otherwise the CI check is added ------
|
|
2870
3209
|
const gatePhase = await resolveConductorGate(gateIo, access, options.gate, deps.gate, {
|
|
2871
3210
|
dryRun: options.dryRun,
|
|
3211
|
+
planningOnly: true,
|
|
2872
3212
|
...(hasExplicitGateInput(options.gate) ? {} : { ensureProviderCheck: EPIC_IMPLEMENTER_CI_CHECK_NAME }),
|
|
2873
3213
|
});
|
|
2874
3214
|
if (gatePhase.kind === "exit")
|
|
@@ -2883,17 +3223,39 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2883
3223
|
identity: first.identity,
|
|
2884
3224
|
repository: first.repository,
|
|
2885
3225
|
storedCommand: first.storedCommand,
|
|
3226
|
+
toolchains: first.toolchains,
|
|
3227
|
+
commandChanged: false,
|
|
3228
|
+
commandBlocked: false,
|
|
2886
3229
|
failedOperations: [],
|
|
2887
3230
|
};
|
|
2888
3231
|
const firstItems = projectSetupItems(state.evidence);
|
|
2889
|
-
|
|
3232
|
+
deps.assessmentSink?.(firstItems.find(i => i.assessment)?.assessment);
|
|
3233
|
+
for (const line of renderSetupAssessment(firstItems, "What setup found", "initial"))
|
|
2890
3234
|
deps.log(line);
|
|
2891
|
-
|
|
3235
|
+
// An explicit --test-command asks for a write unless the stored value already
|
|
3236
|
+
// equals it. A stored value that could not be read is eligible for the write.
|
|
3237
|
+
// Only this non-sensitive boolean reaches the planner; the text never does.
|
|
3238
|
+
const explicitCommand = options.testCommand;
|
|
3239
|
+
const commandAlreadyStored = explicitCommand !== undefined &&
|
|
3240
|
+
state.evidence.testCommand.state === "stored" &&
|
|
3241
|
+
state.storedCommand === explicitCommand;
|
|
3242
|
+
const replaceTestCommandRequested = explicitCommand !== undefined && !commandAlreadyStored;
|
|
3243
|
+
const policyRequired = gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness);
|
|
3244
|
+
const planContext = {
|
|
2892
3245
|
gateOrDefaultsNeedWrite: gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness),
|
|
3246
|
+
suppliedPolicyInput: options.reviewPolicyExplicit || options.replaceDoneGate || hasExplicitGateInput(options.gate),
|
|
2893
3247
|
dryRun: options.dryRun,
|
|
2894
|
-
}
|
|
3248
|
+
};
|
|
3249
|
+
let fixes = planSetupFixes(state.evidence, { ...planContext, replaceTestCommandRequested });
|
|
3250
|
+
if (commandAlreadyStored) {
|
|
3251
|
+
deps.log("");
|
|
3252
|
+
deps.log("Test command unchanged — it already matches --test-command, so nothing was written.");
|
|
3253
|
+
}
|
|
2895
3254
|
// ---- Dry run: preview only, before every write and write prompt ---------
|
|
2896
3255
|
if (options.dryRun) {
|
|
3256
|
+
if (gatePlan !== null)
|
|
3257
|
+
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
3258
|
+
logStoredCommandAndToolchains(deps, state.storedCommand, state.toolchains);
|
|
2897
3259
|
deps.log("");
|
|
2898
3260
|
deps.log("Dry run — nothing was written and nothing was asked.");
|
|
2899
3261
|
if (fixes.length === 0)
|
|
@@ -2914,38 +3276,78 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2914
3276
|
deps.log("");
|
|
2915
3277
|
deps.log("Fixing what is missing…");
|
|
2916
3278
|
}
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
3279
|
+
// Each fix runs at most once per invocation: re-planning after a command write
|
|
3280
|
+
// can add the workflow fix, but never repeats a write, a declined prompt, or
|
|
3281
|
+
// an independent setup operation.
|
|
3282
|
+
let policyResult = null;
|
|
3283
|
+
const attempted = new Set();
|
|
3284
|
+
while (fixes.length > 0) {
|
|
3285
|
+
const fix = fixes.shift();
|
|
3286
|
+
if (attempted.has(fix))
|
|
3287
|
+
continue;
|
|
3288
|
+
attempted.add(fix);
|
|
3289
|
+
if (isTestCommandFix(fix)) {
|
|
3290
|
+
const result = fix === "replace_test_command" && explicitCommand !== undefined
|
|
3291
|
+
? await fixExplicitTestCommand(deps, setup, access, explicitCommand, state.evidence.testCommand.state === "stored")
|
|
3292
|
+
: await fixTestCommand(deps, setup, access);
|
|
3293
|
+
if (result.failure !== null) {
|
|
3294
|
+
// A write that was not confirmed: report it as a blocking operation, keep
|
|
3295
|
+
// only the server's returned value, and block every later workflow step.
|
|
3296
|
+
state.failedOperations.push(result.failure);
|
|
3297
|
+
state.commandBlocked = true;
|
|
3298
|
+
if (result.serverValue !== undefined) {
|
|
3299
|
+
state.storedCommand = result.serverValue;
|
|
3300
|
+
state.evidence = {
|
|
3301
|
+
...state.evidence,
|
|
3302
|
+
testCommand: { state: result.serverValue === null ? "missing" : "stored" },
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
state.evidence = { ...state.evidence, workflow: { state: "blocked", remedy: COMMAND_UNVERIFIED_WORKFLOW_REMEDY } };
|
|
3306
|
+
}
|
|
3307
|
+
else if (result.confirmed !== null) {
|
|
3308
|
+
state.storedCommand = result.confirmed;
|
|
3309
|
+
state.commandChanged = true;
|
|
2922
3310
|
state.evidence = { ...state.evidence, testCommand: { state: "stored" } };
|
|
3311
|
+
// Reassess the workflow against the CONFIRMED value and the same
|
|
3312
|
+
// toolchain snapshot, then derive what is left from the updated evidence.
|
|
3313
|
+
const reassessed = state.evidence.githubSignIn === "signed_in"
|
|
3314
|
+
? await assessWorkflow(setup, result.confirmed, state.toolchains, true)
|
|
3315
|
+
: { state: "unknown" };
|
|
3316
|
+
state.evidence = { ...state.evidence, workflow: reassessed };
|
|
3317
|
+
fixes = planSetupFixes(state.evidence, { ...planContext, replaceTestCommandRequested: false }).filter((kind) => !attempted.has(kind) && !isTestCommandFix(kind));
|
|
2923
3318
|
}
|
|
2924
3319
|
}
|
|
2925
3320
|
else if (fix === "setup_pr") {
|
|
3321
|
+
if (state.commandBlocked) {
|
|
3322
|
+
deps.log("");
|
|
3323
|
+
deps.log("CI workflow");
|
|
3324
|
+
deps.log(" skipped — the test command could not be verified, so the workflow is not built from it.");
|
|
3325
|
+
continue;
|
|
3326
|
+
}
|
|
2926
3327
|
if (state.storedCommand === null) {
|
|
2927
3328
|
deps.log("");
|
|
2928
3329
|
deps.log("CI workflow");
|
|
2929
3330
|
deps.log(" skipped — it is built from the stored test command, which is not saved yet.");
|
|
2930
3331
|
continue;
|
|
2931
3332
|
}
|
|
2932
|
-
const opened = await fixSetupPullRequest(deps, setup, state.storedCommand, state.repository);
|
|
3333
|
+
const opened = await fixSetupPullRequest(deps, setup, state.storedCommand, state.toolchains, state.repository);
|
|
2933
3334
|
state.evidence = { ...state.evidence, workflow: opened.workflow };
|
|
2934
3335
|
}
|
|
2935
3336
|
else if (fix === "gate_and_defaults" && gatePlan !== null) {
|
|
2936
|
-
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
3337
|
+
policyResult = await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
2937
3338
|
}
|
|
2938
3339
|
else if (fix === "merge_token" && state.identity !== null) {
|
|
2939
3340
|
await fixMergeToken(deps, setup, state.identity, state.evidence.mergeCredential.state === "stored_rejected");
|
|
2940
3341
|
}
|
|
2941
3342
|
else if (fix === "reindex") {
|
|
2942
|
-
state.evidence = { ...state.evidence, index: await fixReindex(deps, setup, access) };
|
|
3343
|
+
state.evidence = { ...state.evidence, index: await fixReindex(deps, setup, access, state.evidence.recovery) };
|
|
2943
3344
|
}
|
|
2944
3345
|
}
|
|
2945
3346
|
// ---- Explicit operations, each behind its own consent (unchanged) -------
|
|
2946
|
-
if (options.gate.qualifyGate && gatePlan !== null && gatePlan.desired.localCommands.length > 0
|
|
3347
|
+
if (options.gate.qualifyGate && gatePlan !== null && gatePlan.desired.localCommands.length > 0
|
|
3348
|
+
&& policyResult?.status !== "deferred" && policyResult?.status !== "unknown") {
|
|
2947
3349
|
await runConductorGateQualification(gateIo, access, deps.gate, {
|
|
2948
|
-
revision: gatePlan.current.revision,
|
|
3350
|
+
revision: policyResult?.current?.state.revision ?? gatePlan.current.revision,
|
|
2949
3351
|
baseUrl,
|
|
2950
3352
|
});
|
|
2951
3353
|
}
|
|
@@ -2998,17 +3400,21 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
2998
3400
|
const finalReport = await deps.runDoctor({
|
|
2999
3401
|
access,
|
|
3000
3402
|
reviewPolicySource: options.reviewPolicy,
|
|
3403
|
+
assessmentVersion: 1,
|
|
3404
|
+
epicRunId: options.assessmentEpicRunId,
|
|
3001
3405
|
storedMergeCredential: storedMergeContextFor(setup, firstReport.readiness?.provider_repository ?? null, localRemote),
|
|
3002
3406
|
});
|
|
3003
|
-
const finalReadiness =
|
|
3407
|
+
const finalReadiness = options.assessmentEpicRunId !== undefined
|
|
3408
|
+
? finalReport.readiness
|
|
3409
|
+
: observedReadiness ?? finalReport.readiness;
|
|
3004
3410
|
const closing = await collectSetupEvidence(deps, setup, access, finalReadiness, {
|
|
3005
3411
|
...collectInputs,
|
|
3006
3412
|
advisories: state.evidence.advisories,
|
|
3413
|
+
commandChanged: state.commandChanged,
|
|
3414
|
+
commandBlocked: state.commandBlocked,
|
|
3007
3415
|
});
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
closing.evidence.index = { state: "queued_by_setup" };
|
|
3011
|
-
}
|
|
3416
|
+
if (state.evidence.index.state === "recovery_unresolved" && closing.evidence.index.state !== "reached")
|
|
3417
|
+
closing.evidence.index = state.evidence.index;
|
|
3012
3418
|
const items = [...projectSetupItems(closing.evidence), ...state.failedOperations];
|
|
3013
3419
|
if (deniesEnforcementUnknown(finalReport)) {
|
|
3014
3420
|
items.push({
|
|
@@ -3038,7 +3444,15 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3038
3444
|
});
|
|
3039
3445
|
}
|
|
3040
3446
|
}
|
|
3041
|
-
|
|
3447
|
+
// The latest authoritative command (after any replacement) and what CI installs
|
|
3448
|
+
// for it. Operator-only: written through deps.log and nowhere else.
|
|
3449
|
+
logStoredCommandAndToolchains(deps, closing.evidence.testCommand.state === "stored" ? closing.storedCommand : null, closing.toolchains);
|
|
3450
|
+
if (policyResult?.status === "deferred" || policyResult?.status === "unknown") {
|
|
3451
|
+
items.push({ id: "setup-policy", label: "Combined repository policy", state: "needs_action", blocking: policyRequired || policyResult.status === "unknown",
|
|
3452
|
+
remedy: "rerun setup for a fresh preview; ask a bootstrap administrator if uncertainty persists" });
|
|
3453
|
+
}
|
|
3454
|
+
deps.assessmentSink?.(items.find(i => i.assessment)?.assessment);
|
|
3455
|
+
for (const line of renderSetupAssessment(items, "Where things stand", "final"))
|
|
3042
3456
|
deps.log(line);
|
|
3043
3457
|
for (const advisory of closing.evidence.advisories)
|
|
3044
3458
|
deps.log(` - ${advisory}`);
|
|
@@ -3056,10 +3470,12 @@ function deniesEnforcementUnknown(report) {
|
|
|
3056
3470
|
/** Short previews of each fix for --dry-run. */
|
|
3057
3471
|
const DRY_RUN_FIX_TEXT = Object.freeze({
|
|
3058
3472
|
save_test_command: "save the repository's test command (one question, then PUT /setup/testing-config)",
|
|
3473
|
+
replace_test_command: "save the command you passed with --test-command (that flag is the consent; one write, then a read-back), " +
|
|
3474
|
+
"then re-check the CI workflow against the stored value and offer the setup pull request",
|
|
3059
3475
|
setup_pr: "open the setup pull request with the CI workflow (its own consent)",
|
|
3060
3476
|
gate_and_defaults: "store the repository gate and the safe supervisor defaults (its own consent)",
|
|
3061
3477
|
merge_token: "store a GitHub merge token on this computer (its own consent, read with no echo)",
|
|
3062
|
-
reindex: "
|
|
3478
|
+
reindex: "review keep/correct/defer for the displayed branch and setup revision; conditionally correct and read back only with consent, then admit one durable initial request or an explicitly authorized retry. Dry run writes no configuration, queue, retry, authorization record, or file",
|
|
3063
3479
|
});
|
|
3064
3480
|
/**
|
|
3065
3481
|
* The claude-review workflow, only for an explicit `--review-policy
|