@bridge_gpt/mcp-server 0.2.71 → 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 +19 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +4 -4
- package/build/bridge-permissions.js +4 -0
- 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 +518 -23
- package/build/conductor/doctor.js +84 -10
- package/build/conductor/epic-implementer-cli.js +51 -2
- package/build/conductor/gate-discovery.js +136 -10
- package/build/conductor/gate-settings-review.js +305 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-plan.js +42 -2
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +379 -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 +21 -8
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +223 -13
- package/build/conductor/recovery-operations.js +34 -4
- 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 +52 -11
- package/build/epic-implementer-bin.js +118 -43
- package/build/epic-launch-profile.js +1 -1
- 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 +67 -2
- 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 +246 -28
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/prompt-spec.js +13 -3
- 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 +54 -2
- package/build/executor/worker-database.js +271 -31
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-verification-guidance.js +37 -2
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +679 -278
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +236 -42
- package/build/install-bridge-conductor-setup.js +115 -26
- package/build/install-bridge-conductor.js +448 -350
- package/build/install-bridge.js +418 -123
- 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 +2 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +5 -5
- package/build/plan-execution-ledger.js +148 -2
- package/build/plane/plane-freshness.js +6 -7
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +24 -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 +50 -8
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +2 -2
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-enrollment.js +21 -8
- 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 +5 -0
- package/docs/epic-implementer/getting-started.md +40 -15
- package/package.json +1 -1
|
@@ -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,8 +107,8 @@
|
|
|
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";
|
|
@@ -163,20 +153,21 @@ export const CONDUCTOR_REVIEW_POLICY_SOURCES = [
|
|
|
163
153
|
* at first approval. AI review is an explicit `--review-policy verdict_protocol`.
|
|
164
154
|
*/
|
|
165
155
|
export const DEFAULT_CONDUCTOR_REVIEW_POLICY = "repository_policy";
|
|
166
|
-
/** Usage text for `install-
|
|
156
|
+
/** Usage text for `install epic-implementer`. */
|
|
167
157
|
export function getInstallBridgeConductorUsage() {
|
|
168
158
|
return [
|
|
169
|
-
"Usage: install
|
|
159
|
+
"Usage: install epic-implementer [options]",
|
|
170
160
|
"",
|
|
171
161
|
"Set up this repository for the Epic Implementer. It checks everything first",
|
|
172
162
|
"(read-only), fixes only what is missing, checks again, and ends with one",
|
|
173
163
|
"verdict: \"Ready for your first epic\" or \"Not ready: N steps left\" with the fix",
|
|
174
|
-
"for each step.
|
|
175
|
-
"
|
|
176
|
-
"
|
|
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).",
|
|
177
168
|
"",
|
|
178
|
-
"It
|
|
179
|
-
"
|
|
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",
|
|
180
171
|
"writes. Otherwise it asks only what a missing item needs, each with a default of no:",
|
|
181
172
|
" - which repository, only when it cannot tell;",
|
|
182
173
|
" - saving the test command, only when none is stored (or replacing it, when you",
|
|
@@ -184,11 +175,14 @@ export function getInstallBridgeConductorUsage() {
|
|
|
184
175
|
" - opening the setup pull request with the CI workflow;",
|
|
185
176
|
" - storing the repository gate and safe defaults, when they would change;",
|
|
186
177
|
" - storing a GitHub merge token on this computer (read with no echo).",
|
|
187
|
-
"The
|
|
178
|
+
"The destination is displayed without a redundant URL question. Without an",
|
|
188
179
|
"interactive terminal every question is a decline: no token is stored and no",
|
|
189
180
|
"pull request is opened. When setup reports that its setup pull request is",
|
|
190
|
-
"waiting, merge it and run setup again
|
|
191
|
-
"
|
|
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.",
|
|
192
186
|
"",
|
|
193
187
|
"Merge token: setup can store a GitHub token for this repository in your user",
|
|
194
188
|
"credential store (~/.config/bridge/credentials.json). GITHUB_MERGE_TOKEN, then",
|
|
@@ -203,7 +197,7 @@ export function getInstallBridgeConductorUsage() {
|
|
|
203
197
|
"checked first (one line, no GitHub Actions expression, at most 500 characters),",
|
|
204
198
|
"saved once, and read back; setup reports success only when the stored value",
|
|
205
199
|
"matches. The same value again is \"unchanged\" and writes nothing. The flag does",
|
|
206
|
-
"NOT
|
|
200
|
+
"NOT authorize credential endpoint transfer and",
|
|
207
201
|
"does NOT consent to the workflow pull request, which asks for itself. With",
|
|
208
202
|
"--dry-run nothing is saved. Do not put a credential in a command: setup prints",
|
|
209
203
|
"it and the workflow file contains it.",
|
|
@@ -332,6 +326,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
332
326
|
}
|
|
333
327
|
let repo;
|
|
334
328
|
let dryRun = false;
|
|
329
|
+
let json = false;
|
|
335
330
|
let skipWorkflow = false;
|
|
336
331
|
let replaceDoneGate = false;
|
|
337
332
|
let reviewPolicy = DEFAULT_CONDUCTOR_REVIEW_POLICY;
|
|
@@ -340,6 +335,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
340
335
|
let planFile;
|
|
341
336
|
let executorId;
|
|
342
337
|
const epicRunIds = [];
|
|
338
|
+
let assessmentEpicRunId;
|
|
343
339
|
let repoWide = false;
|
|
344
340
|
let allowedBot;
|
|
345
341
|
let secretName;
|
|
@@ -371,6 +367,11 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
371
367
|
const flag = eq === -1 ? raw : raw.slice(0, eq);
|
|
372
368
|
const inline = eq === -1 ? undefined : raw.slice(eq + 1);
|
|
373
369
|
switch (flag) {
|
|
370
|
+
case "--json":
|
|
371
|
+
if (inline !== undefined)
|
|
372
|
+
return { status: "error", message: "--json takes no value" };
|
|
373
|
+
json = true;
|
|
374
|
+
break;
|
|
374
375
|
case "--dry-run":
|
|
375
376
|
if (inline !== undefined)
|
|
376
377
|
return { status: "error", message: "--dry-run takes no value" };
|
|
@@ -450,6 +451,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
450
451
|
case "--plan-file":
|
|
451
452
|
case "--executor-id":
|
|
452
453
|
case "--epic-run-id":
|
|
454
|
+
case "--assessment-epic-run-id":
|
|
453
455
|
case "--allowed-bot":
|
|
454
456
|
case "--secret-name":
|
|
455
457
|
case "--branches":
|
|
@@ -509,6 +511,12 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
509
511
|
executorId = value;
|
|
510
512
|
else if (flag === "--epic-run-id")
|
|
511
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
|
+
}
|
|
512
520
|
else if (flag === "--allowed-bot")
|
|
513
521
|
allowedBot = value;
|
|
514
522
|
else if (flag === "--secret-name")
|
|
@@ -675,6 +683,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
675
683
|
options: {
|
|
676
684
|
repo,
|
|
677
685
|
dryRun,
|
|
686
|
+
json,
|
|
678
687
|
requiredChecks: normalizedChecks,
|
|
679
688
|
gate,
|
|
680
689
|
reviewPolicy,
|
|
@@ -688,6 +697,7 @@ export function parseInstallBridgeConductorArgs(argv) {
|
|
|
688
697
|
...(replaceDoneGate ? { replaceDoneGate: true } : {}),
|
|
689
698
|
executorId,
|
|
690
699
|
...(epicRunIds.length > 0 ? { epicRunIds } : {}),
|
|
700
|
+
...(assessmentEpicRunId !== undefined ? { assessmentEpicRunId } : {}),
|
|
691
701
|
...(repoWide ? { repoWide: true } : {}),
|
|
692
702
|
...(launchProfile ? { launchProfile } : {}),
|
|
693
703
|
...(baseUrl ? { baseUrl } : {}),
|
|
@@ -716,7 +726,7 @@ export function createDefaultLaunchProfileDeps(env) {
|
|
|
716
726
|
readFile: store.readFile,
|
|
717
727
|
stat: (p) => statAsync(p),
|
|
718
728
|
}),
|
|
719
|
-
bindCredential: (repoName, baseUrl) => bindEpicLaunchCredential(repoName, baseUrl, store),
|
|
729
|
+
bindCredential: (repoName, baseUrl, observedKey) => bindEpicLaunchCredential(repoName, baseUrl, store, { observedKey: observedKey ?? null }),
|
|
720
730
|
readPolicyFile: (absolutePath) => readFileAsync(absolutePath, "utf-8"),
|
|
721
731
|
};
|
|
722
732
|
}
|
|
@@ -873,11 +883,8 @@ function renderBootstrapOutcome(deps, response) {
|
|
|
873
883
|
}
|
|
874
884
|
}
|
|
875
885
|
async function confirm(deps, promptText) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
return false;
|
|
879
|
-
const answer = await deps.promptLine(promptText);
|
|
880
|
-
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";
|
|
881
888
|
}
|
|
882
889
|
/**
|
|
883
890
|
* BAPI-1452 — the merge-credential next step. Value-free configuration guidance
|
|
@@ -1160,16 +1167,16 @@ export function formatConductorRestartAdvisory(mergedProfile) {
|
|
|
1160
1167
|
}
|
|
1161
1168
|
/** Remediation printed when no supported host config carries a Bridge entry. */
|
|
1162
1169
|
export const CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION = `run \`${PRINTED_INSTALL_COMMAND}\` to create and register the host MCP entry, ` +
|
|
1163
|
-
"then re-run `install
|
|
1170
|
+
"then re-run `install epic-implementer`.";
|
|
1164
1171
|
/** Remediation printed whenever the managed git hooks were not installed. */
|
|
1165
|
-
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 " +
|
|
1166
1173
|
"`epic-implementer install-git-hooks` directly.";
|
|
1167
1174
|
/**
|
|
1168
1175
|
* Remediation for a non-fatal hook refusal (BAPI-1290): the hooks need a
|
|
1169
1176
|
* persistent install to embed, and the repair is to create one and reinstall.
|
|
1170
1177
|
*/
|
|
1171
1178
|
export const CONDUCTOR_HOOKS_DURABLE_REMEDIATION = `install the CLI persistently (\`npm i -g ${MCP_PACKAGE_NAME}\`), then run ` +
|
|
1172
|
-
"`epic-implementer install-git-hooks` (or re-run `install
|
|
1179
|
+
"`epic-implementer install-git-hooks` (or re-run `install epic-implementer` and accept the " +
|
|
1173
1180
|
"local-observability consent).";
|
|
1174
1181
|
/**
|
|
1175
1182
|
* Phase: tool visibility.
|
|
@@ -1186,7 +1193,7 @@ async function runConductorToolVisibilityPhase(deps, local) {
|
|
|
1186
1193
|
deps.log(" declined — no host MCP configuration and no install state were written.");
|
|
1187
1194
|
return {
|
|
1188
1195
|
manualActions: [
|
|
1189
|
-
"tool visibility: re-run `install
|
|
1196
|
+
"tool visibility: re-run `install epic-implementer` and accept the profile consent to " +
|
|
1190
1197
|
"make the Epic Implementer MCP tools visible.",
|
|
1191
1198
|
],
|
|
1192
1199
|
};
|
|
@@ -1282,7 +1289,7 @@ async function runConductorLocalObservabilityPhase(deps, local) {
|
|
|
1282
1289
|
"(engine admission is unaffected).");
|
|
1283
1290
|
// Only BAPI-772's broken-package case stays fatal: the executing artifact
|
|
1284
1291
|
// ships no hook binary at all. Every other refusal — an npx-cache runtime
|
|
1285
|
-
// (the documented `npx … install
|
|
1292
|
+
// (the documented `npx … install epic-implementer` path), an unqualified or
|
|
1286
1293
|
// unloadable runtime, an unsafe existing hook — is a manual action, and
|
|
1287
1294
|
// the installer continues to setup-epic verification and executor
|
|
1288
1295
|
// provisioning. Optional hooks must never stop the phases that do gate
|
|
@@ -1302,7 +1309,7 @@ async function runConductorLocalObservabilityPhase(deps, local) {
|
|
|
1302
1309
|
else if (result !== null && result.ok) {
|
|
1303
1310
|
if (!result.is_worktree) {
|
|
1304
1311
|
deps.log(" not a git worktree, so no managed hook was installed (degraded optional capability).");
|
|
1305
|
-
manualActions.push("local observability: run `install
|
|
1312
|
+
manualActions.push("local observability: run `install epic-implementer` from a git worktree to install the " +
|
|
1306
1313
|
"managed git hooks.");
|
|
1307
1314
|
}
|
|
1308
1315
|
else {
|
|
@@ -1623,7 +1630,7 @@ async function runLaunchProfilePhase(deps, options, inputs) {
|
|
|
1623
1630
|
gaps.push("the credential binding was not approved, so a launch could not use the stored key.");
|
|
1624
1631
|
}
|
|
1625
1632
|
else {
|
|
1626
|
-
const result = await lp.bindCredential(repoName, inputs.baseUrl);
|
|
1633
|
+
const result = await lp.bindCredential(repoName, inputs.baseUrl, inputs.access.apiKey);
|
|
1627
1634
|
if (!result.ok)
|
|
1628
1635
|
gaps.push(`the credential binding could not be written: ${result.error}`);
|
|
1629
1636
|
else
|
|
@@ -1636,7 +1643,7 @@ async function runLaunchProfilePhase(deps, options, inputs) {
|
|
|
1636
1643
|
deps.log(` incomplete — profile '${name}' was NOT written:`);
|
|
1637
1644
|
for (const gap of gaps)
|
|
1638
1645
|
deps.log(` → ${gap}`);
|
|
1639
|
-
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} ` +
|
|
1640
1647
|
`--base-url ${inputs.baseUrl} --required-check <name> ...`);
|
|
1641
1648
|
return { complete: false };
|
|
1642
1649
|
}
|
|
@@ -1731,11 +1738,6 @@ async function resolveAndConfirmBaseUrl(options, deps, promptText) {
|
|
|
1731
1738
|
deps.log(` explicit target for epic launch profile '${options.launchProfile}'` +
|
|
1732
1739
|
(baseUrl === DEFAULT_BAPI_BASE_URL ? " — this is the PRODUCTION Bridge API, selected deliberately." : "."));
|
|
1733
1740
|
}
|
|
1734
|
-
const baseUrlOk = await confirm(deps, promptText);
|
|
1735
|
-
if (!baseUrlOk) {
|
|
1736
|
-
deps.log("Aborted — no network call (readiness GET or bootstrap POST) was attempted.");
|
|
1737
|
-
return { ok: false, code: 0 };
|
|
1738
|
-
}
|
|
1739
1741
|
return { ok: true, baseUrl };
|
|
1740
1742
|
}
|
|
1741
1743
|
function gateIoFor(deps) {
|
|
@@ -1830,7 +1832,55 @@ async function runExecutorPreflightPhase(options, deps, baseUrl, access) {
|
|
|
1830
1832
|
}
|
|
1831
1833
|
return { kind: "ok", plans: null };
|
|
1832
1834
|
}
|
|
1835
|
+
/** One output finalizer for success, deferment, dry run, and contained failures. */
|
|
1833
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) {
|
|
1834
1884
|
const parsed = parseInstallBridgeConductorArgs(argv);
|
|
1835
1885
|
if (parsed.status === "help") {
|
|
1836
1886
|
deps.log(parsed.usage);
|
|
@@ -1863,9 +1913,14 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1863
1913
|
if (!confirmed.ok)
|
|
1864
1914
|
return confirmed.code;
|
|
1865
1915
|
const baseUrl = confirmed.baseUrl;
|
|
1916
|
+
if (!options.dryRun && !(await assessEpicInstallerPrerequisites(deps, Boolean(options.executorId))).available)
|
|
1917
|
+
return 1;
|
|
1866
1918
|
const accessResult = await deps.resolveAccess(options.repo, baseUrl);
|
|
1867
1919
|
const access = accessResult.ok ? accessResult.access : null;
|
|
1868
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;
|
|
1869
1924
|
const gateIo = gateIoFor(deps);
|
|
1870
1925
|
const standalone = await runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl);
|
|
1871
1926
|
if (standalone !== null)
|
|
@@ -1876,6 +1931,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1876
1931
|
access,
|
|
1877
1932
|
accessError,
|
|
1878
1933
|
reviewPolicySource: options.reviewPolicy,
|
|
1934
|
+
assessmentVersion: 1,
|
|
1935
|
+
epicRunId: options.assessmentEpicRunId,
|
|
1879
1936
|
});
|
|
1880
1937
|
deps.log(formatConductorInstallDoctorReport(firstReport));
|
|
1881
1938
|
if (conductorInstallDoctorHasFatal(firstReport)) {
|
|
@@ -1893,10 +1950,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1893
1950
|
// and before the dry-run return, so `--dry-run` reports the same refusal.
|
|
1894
1951
|
const executor = deps.executorProvisioning;
|
|
1895
1952
|
const local = deps.localProvisioning;
|
|
1896
|
-
const
|
|
1897
|
-
if (preflight.kind === "refused")
|
|
1898
|
-
return 1;
|
|
1899
|
-
const executorPlans = preflight.plans;
|
|
1953
|
+
const executorPlans = earlyPreflight.plans;
|
|
1900
1954
|
// ---- BAPI-1391: the repository gate, decided BEFORE any write ----------
|
|
1901
1955
|
// Capability probe first (a read, after the base-URL consent), then the stored
|
|
1902
1956
|
// gate, explicit gate flags, or a discovery proposal the owner confirms. Under
|
|
@@ -1906,7 +1960,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1906
1960
|
return 1;
|
|
1907
1961
|
}
|
|
1908
1962
|
const gatePhase = await resolveConductorGate(gateIo, access, options.gate, deps.gate, {
|
|
1909
|
-
dryRun: options.dryRun,
|
|
1963
|
+
dryRun: options.dryRun, planningOnly: true,
|
|
1910
1964
|
});
|
|
1911
1965
|
if (gatePhase.kind === "exit")
|
|
1912
1966
|
return gatePhase.code;
|
|
@@ -1919,6 +1973,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
1919
1973
|
if (options.dryRun) {
|
|
1920
1974
|
deps.log("");
|
|
1921
1975
|
deps.log("Dry run — no writes will be performed.");
|
|
1976
|
+
if (gatePlan !== null)
|
|
1977
|
+
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
1922
1978
|
if (gatePlan === null) {
|
|
1923
1979
|
deps.log(" Repository gate: none confirmed — a real run asks you to confirm one before any write.");
|
|
1924
1980
|
}
|
|
@@ -2006,104 +2062,12 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2006
2062
|
// replacing bootstrap when the server cannot preview.
|
|
2007
2063
|
deps.log("");
|
|
2008
2064
|
deps.log("Phase 2/8 — bootstrapping supervisor project defaults…");
|
|
2009
|
-
const
|
|
2010
|
-
|
|
2011
|
-
// BAPI-694 — the narrow ReviewPolicy object, sent ONLY on an explicit
|
|
2012
|
-
// selection. `review_source` is deliberately NOT sent: on an existing
|
|
2013
|
-
// repository an omitted field keeps its stored value, and a new repository
|
|
2014
|
-
// receives the server's `verdict_protocol` default either way.
|
|
2015
|
-
...(options.reviewPolicyExplicit
|
|
2016
|
-
? { review_policy: { source: options.reviewPolicy } }
|
|
2017
|
-
: {}),
|
|
2018
|
-
merge_approval_required: "true",
|
|
2019
|
-
...(options.replaceDoneGate ? { replace_done_gate: true } : {}),
|
|
2020
|
-
};
|
|
2021
|
-
// BAPI-1391 — the gate is stored FIRST, under its own combined consent, in
|
|
2022
|
-
// two cases:
|
|
2023
|
-
// * a gate with no provider checks (local-only or `none`): the server
|
|
2024
|
-
// accepts an empty CI list only for a stored gate of that kind;
|
|
2025
|
-
// * any change to an already STORED gate: the bootstrap apply would
|
|
2026
|
-
// otherwise run BAPI-1390's profile sync first, which merges the additive
|
|
2027
|
-
// CI list into the stored profile under a new revision — so a later PUT
|
|
2028
|
-
// would be refused as stale while the gate had silently been widened.
|
|
2029
|
-
// Stored first, the CI checks already equal the gate, the bootstrap adds
|
|
2030
|
-
// nothing, and the sync has nothing to change.
|
|
2031
|
-
// A legacy or unconfirmed repository keeps the original order (preview,
|
|
2032
|
-
// consent, apply) and is stored after the apply; the sync never touches it.
|
|
2033
|
-
const gateFirst = gatePlan.write !== null &&
|
|
2034
|
-
(bootstrapChecks.length === 0 || gatePlan.current.source === "stored");
|
|
2035
|
-
let storedGate = gatePlan.write === null ? gatePlan.current : null;
|
|
2036
|
-
if (gateFirst) {
|
|
2037
|
-
deps.log("");
|
|
2038
|
-
const gateOk = await confirm(deps, "Store this repository gate and write the safe project-default supervisor posture now? [y/N]: ");
|
|
2039
|
-
if (!gateOk) {
|
|
2040
|
-
deps.log("Aborted — no server write was attempted.");
|
|
2041
|
-
return 0;
|
|
2042
|
-
}
|
|
2043
|
-
storedGate = await storeConductorGate(gateIo, access, gatePlan);
|
|
2044
|
-
if (storedGate === null)
|
|
2045
|
-
return 1;
|
|
2046
|
-
}
|
|
2047
|
-
let preview;
|
|
2048
|
-
try {
|
|
2049
|
-
preview = await previewConductorSupervisorBootstrap(access, bootstrapRequest, deps.postJson);
|
|
2050
|
-
}
|
|
2051
|
-
catch (err) {
|
|
2052
|
-
reportBootstrapFailure(deps, "preview", classifySupervisorBootstrapFailure(err));
|
|
2065
|
+
const combined = await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
2066
|
+
if (combined.status === "deferred" || combined.status === "unknown")
|
|
2053
2067
|
return 1;
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
// Deliberately separate from the base-URL consent above (which was given
|
|
2058
|
-
// before any network call). Confirming WHERE to write is not consent TO write.
|
|
2059
|
-
// A gate stored first above was stored under its own combined consent.
|
|
2060
|
-
if (!gateFirst) {
|
|
2061
|
-
deps.log("");
|
|
2062
|
-
const bootstrapOk = await confirm(deps, "Write the safe project-default supervisor posture now? [y/N]: ");
|
|
2063
|
-
if (!bootstrapOk) {
|
|
2064
|
-
deps.log("Aborted — no server write was attempted.");
|
|
2065
|
-
return 0;
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
// ---- Consent #3: the EXACT gate change, only when the preview needs it ---
|
|
2069
|
-
// Never inferred from consent #2: agreeing to install is not agreeing to
|
|
2070
|
-
// remove a configured requirement. A missing prompt seam is a refusal.
|
|
2071
|
-
let applyRequest = bootstrapRequest;
|
|
2072
|
-
if (preview.approval_required) {
|
|
2073
|
-
deps.log("");
|
|
2074
|
-
const gateChangeOk = await confirm(deps, "Approve EXACTLY the gate changes listed above? [y/N]: ");
|
|
2075
|
-
if (!gateChangeOk || !preview.approval_token) {
|
|
2076
|
-
deps.errorLog("Gate change not approved — no server write was attempted, and every configured " +
|
|
2077
|
-
"requirement is unchanged.");
|
|
2078
|
-
return 1;
|
|
2079
|
-
}
|
|
2080
|
-
applyRequest = {
|
|
2081
|
-
...bootstrapRequest,
|
|
2082
|
-
approval: { approve: true, approval_token: preview.approval_token },
|
|
2083
|
-
};
|
|
2084
|
-
}
|
|
2085
|
-
let bootstrapResponse;
|
|
2086
|
-
try {
|
|
2087
|
-
bootstrapResponse = await bootstrapConductorSupervisorDefaults(access, applyRequest, deps.postJson);
|
|
2088
|
-
}
|
|
2089
|
-
catch (err) {
|
|
2090
|
-
reportBootstrapFailure(deps, "apply", classifySupervisorBootstrapFailure(err));
|
|
2091
|
-
return 1;
|
|
2092
|
-
}
|
|
2093
|
-
if (bootstrapResponse.setup_outcome === null || bootstrapResponse.config_outcome === null) {
|
|
2094
|
-
reportBootstrapFailure(deps, "apply", "unsupported-protocol");
|
|
2095
|
-
return 1;
|
|
2096
|
-
}
|
|
2097
|
-
renderBootstrapOutcome(deps, bootstrapResponse);
|
|
2098
|
-
// ---- BAPI-1391: store the confirmed gate, then offer its qualification --
|
|
2099
|
-
// Stored after the apply so the bootstrap's additive CI write cannot widen
|
|
2100
|
-
// the gate's exact provider checks: the gate PUT rewrites that projection to
|
|
2101
|
-
// exactly the confirmed checks, under the server's revision compare-and-swap.
|
|
2102
|
-
if (storedGate === null) {
|
|
2103
|
-
storedGate = await storeConductorGate(gateIo, access, gatePlan);
|
|
2104
|
-
if (storedGate === null)
|
|
2105
|
-
return 1;
|
|
2106
|
-
}
|
|
2068
|
+
const storedGate = combined.current
|
|
2069
|
+
? { revision: combined.current.state.revision, qualification_state: combined.current.policy.qualification }
|
|
2070
|
+
: gatePlan.current;
|
|
2107
2071
|
const manualActions = [];
|
|
2108
2072
|
if (gatePlan.desired.localCommands.length > 0) {
|
|
2109
2073
|
const qualified = storedGate.qualification_state === "qualified";
|
|
@@ -2213,7 +2177,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2213
2177
|
}
|
|
2214
2178
|
else {
|
|
2215
2179
|
deps.log(" skipped — this caller supplied no local-provisioning seams.");
|
|
2216
|
-
manualActions.push("tool visibility: run the packaged `install
|
|
2180
|
+
manualActions.push("tool visibility: run the packaged `install epic-implementer` command to add the " +
|
|
2217
2181
|
"`epic_implementer` profile to your host MCP configuration.");
|
|
2218
2182
|
}
|
|
2219
2183
|
deps.log("");
|
|
@@ -2226,7 +2190,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2226
2190
|
}
|
|
2227
2191
|
else {
|
|
2228
2192
|
deps.log(" skipped — this caller supplied no local-provisioning seams.");
|
|
2229
|
-
manualActions.push("local observability: run the packaged `install
|
|
2193
|
+
manualActions.push("local observability: run the packaged `install epic-implementer` command, or " +
|
|
2230
2194
|
"`epic-implementer install-git-hooks`, to install the managed Git hooks.");
|
|
2231
2195
|
}
|
|
2232
2196
|
// The fail-loud hook-binary refusal (a package that ships no hook binary)
|
|
@@ -2290,7 +2254,7 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2290
2254
|
let postReadiness = observedReadiness;
|
|
2291
2255
|
if (postReadiness === null) {
|
|
2292
2256
|
try {
|
|
2293
|
-
postReadiness = await fetchConductorReadiness(access, deps.fetchJson);
|
|
2257
|
+
postReadiness = await fetchConductorReadiness(access, deps.fetchJson, { assessmentVersion: 1, epicRunId: options.assessmentEpicRunId });
|
|
2294
2258
|
}
|
|
2295
2259
|
catch {
|
|
2296
2260
|
// Degraded, not fatal: the write already succeeded, and the matrix simply
|
|
@@ -2304,6 +2268,8 @@ export async function runInstallBridgeConductorCli(argv, deps) {
|
|
|
2304
2268
|
const finalReport = await deps.runDoctor({
|
|
2305
2269
|
access,
|
|
2306
2270
|
reviewPolicySource: options.reviewPolicy,
|
|
2271
|
+
assessmentVersion: 1,
|
|
2272
|
+
epicRunId: options.assessmentEpicRunId,
|
|
2307
2273
|
});
|
|
2308
2274
|
deps.log(formatConductorInstallDoctorReport(finalReport));
|
|
2309
2275
|
// Manual actions (BAPI-775): every declined, unavailable, empty, or incomplete
|
|
@@ -2404,12 +2370,27 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
|
|
|
2404
2370
|
// The setup pull request and, once it merged, the index.
|
|
2405
2371
|
let setupPullRequest = { state: "unknown" };
|
|
2406
2372
|
let index = { state: "not_applicable" };
|
|
2373
|
+
let recovery;
|
|
2407
2374
|
if (repository !== null && inputs.githubSignIn === "signed_in") {
|
|
2408
2375
|
setupPullRequest = await readSetupPullRequest(setup.runGh, repository);
|
|
2409
2376
|
index = await assessSetupIndex(setupPullRequest, () => setup.fetchParseStatus(access), (mergeSha, indexedSha) => compareIndexedToMerge(setup.runGh, repository, mergeSha, indexedSha));
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
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
|
+
}
|
|
2413
2394
|
}
|
|
2414
2395
|
const mergeCredential = await assessMergeCredential(deps, setup, readiness, identity);
|
|
2415
2396
|
return {
|
|
@@ -2422,6 +2403,7 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
|
|
|
2422
2403
|
workflow,
|
|
2423
2404
|
setupPullRequest,
|
|
2424
2405
|
index,
|
|
2406
|
+
...(recovery ? { recovery } : {}),
|
|
2425
2407
|
mergeCredential,
|
|
2426
2408
|
gateChangeDeclined: inputs.gateChangeDeclined,
|
|
2427
2409
|
advisories: inputs.advisories,
|
|
@@ -2561,80 +2543,94 @@ function gateOrDefaultsNeedWrite(gatePlan, readiness) {
|
|
|
2561
2543
|
return false;
|
|
2562
2544
|
return !readiness.supervisor.setup_present || !readiness.supervisor.config_present;
|
|
2563
2545
|
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
return (
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
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 };
|
|
2570
2551
|
}
|
|
2571
|
-
function
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
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);
|
|
2577
2559
|
};
|
|
2560
|
+
return canonical(expected) === canonical(actual);
|
|
2578
2561
|
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Fix: store the repository gate and the safe supervisor defaults, under ONE
|
|
2581
|
-
* consent for this surface (plus the separate exact approval a weakening change
|
|
2582
|
-
* needs). Never inferred from the setup-PR or any other consent.
|
|
2583
|
-
*/
|
|
2584
2562
|
async function fixGateAndDefaults(deps, options, access, gatePlan) {
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
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" };
|
|
2614
2614
|
}
|
|
2615
|
-
applyRequest = { ...request, approval: { approve: true, approval_token: preview.approval_token } };
|
|
2616
2615
|
}
|
|
2617
|
-
let response;
|
|
2618
2616
|
try {
|
|
2619
|
-
|
|
2617
|
+
current = await fetchConductorSetupPolicy(access, deps.fetchJson);
|
|
2620
2618
|
}
|
|
2621
|
-
catch
|
|
2622
|
-
|
|
2623
|
-
return
|
|
2619
|
+
catch {
|
|
2620
|
+
deps.log("Unknown—verify before retrying: policy apply could not be confirmed. Ask the bootstrap administrator.");
|
|
2621
|
+
return { status: "unknown" };
|
|
2624
2622
|
}
|
|
2625
|
-
if (
|
|
2626
|
-
|
|
2627
|
-
|
|
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" };
|
|
2628
2629
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
else {
|
|
2632
|
-
deps.log(" the safe supervisor defaults are already in place — nothing to write.");
|
|
2630
|
+
deps.log("Completed: coherent server state matches the intended policy.");
|
|
2631
|
+
return { status: "completed", current };
|
|
2633
2632
|
}
|
|
2634
|
-
|
|
2635
|
-
return false;
|
|
2636
|
-
}
|
|
2637
|
-
return true;
|
|
2633
|
+
return { status: "deferred" };
|
|
2638
2634
|
}
|
|
2639
2635
|
/**
|
|
2640
2636
|
* Write failures that are a definite refusal: the server answered and said no.
|
|
@@ -2751,75 +2747,59 @@ async function persistTestCommand(deps, config, command, verb) {
|
|
|
2751
2747
|
deps.log(` ${verb} — the stored test command is now in place.`);
|
|
2752
2748
|
return { confirmed: outcome.testCommand, failure: null, serverValue: outcome.testCommand };
|
|
2753
2749
|
}
|
|
2754
|
-
/**
|
|
2755
|
-
* The single accept-or-replace question for a detected proposal. Enter skips,
|
|
2756
|
-
* `y` or `yes` accepts the proposal, and anything else is a typed replacement.
|
|
2757
|
-
* No terminal means no prompt: the proposal and the unresolved step are shown
|
|
2758
|
-
* and nothing is saved.
|
|
2759
|
-
*/
|
|
2760
|
-
async function askAcceptOrReplace(deps, proposed) {
|
|
2761
|
-
if (!deps.promptLine) {
|
|
2762
|
-
deps.log(" skipped saving the test command: there is no interactive terminal, so this counts as declined.");
|
|
2763
|
-
return null;
|
|
2764
|
-
}
|
|
2765
|
-
const answer = (await deps.promptLine(`Save \`${proposed}\` as the test command? Press y to save it, type a different command to save that ` +
|
|
2766
|
-
"instead, or press Enter to skip [y/N]: ")).trim();
|
|
2767
|
-
if (answer.length === 0)
|
|
2768
|
-
return null;
|
|
2769
|
-
if (/^y(es)?$/i.test(answer))
|
|
2770
|
-
return proposed;
|
|
2771
|
-
return answer;
|
|
2772
|
-
}
|
|
2773
|
-
/**
|
|
2774
|
-
* Fix: save the repository's test command through the setup route, after one
|
|
2775
|
-
* contextual agreement. The command is never run here. Only the value read back
|
|
2776
|
-
* from the server is used afterwards.
|
|
2777
|
-
*/
|
|
2750
|
+
/** Resolve named alternatives separately from custom command input. */
|
|
2778
2751
|
async function fixTestCommand(deps, setup, access) {
|
|
2779
2752
|
const config = setup.testingConfig(access);
|
|
2780
|
-
deps.log("");
|
|
2781
|
-
deps.log("Test command");
|
|
2782
2753
|
let detection;
|
|
2783
2754
|
try {
|
|
2784
|
-
detection = await detectTestCommand({ skipStoredRead: true }, { config, readFile:
|
|
2755
|
+
detection = await detectTestCommand({ skipStoredRead: true }, { config, readFile: relPath => setup.readRepositoryFile(relPath) });
|
|
2785
2756
|
}
|
|
2786
2757
|
catch {
|
|
2787
2758
|
detection = { status: "failed", reason: "repository_read_failed" };
|
|
2788
2759
|
}
|
|
2789
2760
|
let command = null;
|
|
2790
|
-
if (detection.status === "
|
|
2791
|
-
|
|
2792
|
-
|
|
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;
|
|
2793
2769
|
}
|
|
2794
2770
|
else {
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
if (
|
|
2809
|
-
|
|
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
|
+
}
|
|
2810
2792
|
}
|
|
2811
2793
|
}
|
|
2812
2794
|
if (command === null) {
|
|
2813
|
-
deps.log("
|
|
2795
|
+
deps.log("Deferred: test command was not saved.");
|
|
2814
2796
|
return COMMAND_NOT_ATTEMPTED;
|
|
2815
2797
|
}
|
|
2816
2798
|
try {
|
|
2817
2799
|
command = validateTestCommand(command);
|
|
2818
2800
|
}
|
|
2819
|
-
catch
|
|
2820
|
-
|
|
2821
|
-
const reason = err instanceof TestCommandValidationError ? err.reason : "invalid";
|
|
2822
|
-
deps.log(` not saved — that command cannot be stored (${reason}).`);
|
|
2801
|
+
catch {
|
|
2802
|
+
deps.log("Deferred: invalid test command.");
|
|
2823
2803
|
return COMMAND_NOT_ATTEMPTED;
|
|
2824
2804
|
}
|
|
2825
2805
|
return persistTestCommand(deps, config, command, "saved");
|
|
@@ -2958,34 +2938,124 @@ async function fixMergeToken(deps, setup, identity, replacing) {
|
|
|
2958
2938
|
return true;
|
|
2959
2939
|
}
|
|
2960
2940
|
/**
|
|
2961
|
-
*
|
|
2962
|
-
*
|
|
2963
|
-
* 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.
|
|
2964
2943
|
*/
|
|
2965
|
-
async function fixReindex(deps, setup, access) {
|
|
2944
|
+
export async function fixReindex(deps, setup, access, initial) {
|
|
2966
2945
|
deps.log("");
|
|
2967
2946
|
deps.log("Repository indexing");
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
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.`);
|
|
2986
3057
|
}
|
|
2987
|
-
|
|
2988
|
-
return { state: "queued_by_setup" };
|
|
3058
|
+
return unresolved("Configuration changed; re-run setup for a new review. Nothing was queued.");
|
|
2989
3059
|
}
|
|
2990
3060
|
/**
|
|
2991
3061
|
* `--remove-merge-token`: remove this repository's stored merge token under the
|
|
@@ -3039,46 +3109,57 @@ function localAdvisories(report) {
|
|
|
3039
3109
|
}
|
|
3040
3110
|
return out;
|
|
3041
3111
|
}
|
|
3042
|
-
/**
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
* The four pinned properties hold: base-URL consent comes before any network
|
|
3047
|
-
* call (every run, never persisted); --dry-run writes nothing; each write
|
|
3048
|
-
* surface asks for itself; and executor readiness is only ever the server's
|
|
3049
|
-
* observation.
|
|
3050
|
-
*/
|
|
3051
|
-
async function runConvergingSetup(options, deps, setup) {
|
|
3052
|
-
if (options.removeMergeToken === true)
|
|
3053
|
-
return runRemoveMergeToken(options, deps, setup);
|
|
3054
|
-
// ---- First operational check: the Claude login marker (a file read only) --
|
|
3055
|
-
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 };
|
|
3056
3116
|
try {
|
|
3057
|
-
|
|
3117
|
+
if (deps.prerequisites)
|
|
3118
|
+
observed = await deps.prerequisites(executorRequested);
|
|
3058
3119
|
}
|
|
3059
|
-
catch {
|
|
3060
|
-
|
|
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.`);
|
|
3061
3149
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
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, "");
|
|
3064
3156
|
if (!confirmed.ok)
|
|
3065
3157
|
return confirmed.code;
|
|
3066
3158
|
const baseUrl = confirmed.baseUrl;
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
}
|
|
3072
|
-
catch {
|
|
3073
|
-
githubSignIn = "unavailable";
|
|
3074
|
-
}
|
|
3075
|
-
let localRemote = null;
|
|
3076
|
-
try {
|
|
3077
|
-
localRemote = await setup.readLocalGithubRemote();
|
|
3078
|
-
}
|
|
3079
|
-
catch {
|
|
3080
|
-
localRemote = null;
|
|
3081
|
-
}
|
|
3159
|
+
const prerequisites = await assessEpicInstallerPrerequisites(deps, Boolean(options.executorId));
|
|
3160
|
+
if (!prerequisites.available && !options.dryRun)
|
|
3161
|
+
return 1;
|
|
3162
|
+
const { claudeLoggedIn, githubSignIn, localRemote } = prerequisites;
|
|
3082
3163
|
// ---- Repository: ask only when it is genuinely ambiguous ----------------
|
|
3083
3164
|
let accessResult = await deps.resolveAccess(options.repo, baseUrl);
|
|
3084
3165
|
if (!accessResult.ok && options.repo === undefined && deps.promptLine) {
|
|
@@ -3088,12 +3169,15 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3088
3169
|
const answer = (await deps.promptLine(suggestion !== null
|
|
3089
3170
|
? `Bridge repository name [${suggestion}]: `
|
|
3090
3171
|
: "Bridge repository name (press Enter to skip): ")).trim();
|
|
3091
|
-
const chosen = answer.length > 0 ? answer :
|
|
3172
|
+
const chosen = answer.length > 0 && !/^(y|yes|n|no)$/i.test(answer) ? answer : null;
|
|
3092
3173
|
if (chosen !== null)
|
|
3093
3174
|
accessResult = await deps.resolveAccess(chosen, baseUrl);
|
|
3094
3175
|
}
|
|
3095
3176
|
const access = accessResult.ok ? accessResult.access : null;
|
|
3096
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;
|
|
3097
3181
|
const gateIo = gateIoFor(deps);
|
|
3098
3182
|
const standalone = await runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl);
|
|
3099
3183
|
if (standalone !== null)
|
|
@@ -3106,6 +3190,8 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3106
3190
|
access,
|
|
3107
3191
|
accessError,
|
|
3108
3192
|
reviewPolicySource: options.reviewPolicy,
|
|
3193
|
+
assessmentVersion: 1,
|
|
3194
|
+
epicRunId: options.assessmentEpicRunId,
|
|
3109
3195
|
skipDenyProbe: true,
|
|
3110
3196
|
storedMergeCredential: storedContext,
|
|
3111
3197
|
});
|
|
@@ -3118,13 +3204,11 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3118
3204
|
deps.log("complete-with-manual-steps");
|
|
3119
3205
|
return 1;
|
|
3120
3206
|
}
|
|
3121
|
-
const
|
|
3122
|
-
if (preflight.kind === "refused")
|
|
3123
|
-
return 1;
|
|
3124
|
-
const executorPlans = preflight.plans;
|
|
3207
|
+
const executorPlans = earlyPreflight.plans;
|
|
3125
3208
|
// ---- The gate: explicit flags win; otherwise the CI check is added ------
|
|
3126
3209
|
const gatePhase = await resolveConductorGate(gateIo, access, options.gate, deps.gate, {
|
|
3127
3210
|
dryRun: options.dryRun,
|
|
3211
|
+
planningOnly: true,
|
|
3128
3212
|
...(hasExplicitGateInput(options.gate) ? {} : { ensureProviderCheck: EPIC_IMPLEMENTER_CI_CHECK_NAME }),
|
|
3129
3213
|
});
|
|
3130
3214
|
if (gatePhase.kind === "exit")
|
|
@@ -3145,7 +3229,8 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3145
3229
|
failedOperations: [],
|
|
3146
3230
|
};
|
|
3147
3231
|
const firstItems = projectSetupItems(state.evidence);
|
|
3148
|
-
|
|
3232
|
+
deps.assessmentSink?.(firstItems.find(i => i.assessment)?.assessment);
|
|
3233
|
+
for (const line of renderSetupAssessment(firstItems, "What setup found", "initial"))
|
|
3149
3234
|
deps.log(line);
|
|
3150
3235
|
// An explicit --test-command asks for a write unless the stored value already
|
|
3151
3236
|
// equals it. A stored value that could not be read is eligible for the write.
|
|
@@ -3155,8 +3240,10 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3155
3240
|
state.evidence.testCommand.state === "stored" &&
|
|
3156
3241
|
state.storedCommand === explicitCommand;
|
|
3157
3242
|
const replaceTestCommandRequested = explicitCommand !== undefined && !commandAlreadyStored;
|
|
3243
|
+
const policyRequired = gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness);
|
|
3158
3244
|
const planContext = {
|
|
3159
3245
|
gateOrDefaultsNeedWrite: gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness),
|
|
3246
|
+
suppliedPolicyInput: options.reviewPolicyExplicit || options.replaceDoneGate || hasExplicitGateInput(options.gate),
|
|
3160
3247
|
dryRun: options.dryRun,
|
|
3161
3248
|
};
|
|
3162
3249
|
let fixes = planSetupFixes(state.evidence, { ...planContext, replaceTestCommandRequested });
|
|
@@ -3166,6 +3253,8 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3166
3253
|
}
|
|
3167
3254
|
// ---- Dry run: preview only, before every write and write prompt ---------
|
|
3168
3255
|
if (options.dryRun) {
|
|
3256
|
+
if (gatePlan !== null)
|
|
3257
|
+
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
3169
3258
|
logStoredCommandAndToolchains(deps, state.storedCommand, state.toolchains);
|
|
3170
3259
|
deps.log("");
|
|
3171
3260
|
deps.log("Dry run — nothing was written and nothing was asked.");
|
|
@@ -3190,6 +3279,7 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3190
3279
|
// Each fix runs at most once per invocation: re-planning after a command write
|
|
3191
3280
|
// can add the workflow fix, but never repeats a write, a declined prompt, or
|
|
3192
3281
|
// an independent setup operation.
|
|
3282
|
+
let policyResult = null;
|
|
3193
3283
|
const attempted = new Set();
|
|
3194
3284
|
while (fixes.length > 0) {
|
|
3195
3285
|
const fix = fixes.shift();
|
|
@@ -3244,19 +3334,20 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3244
3334
|
state.evidence = { ...state.evidence, workflow: opened.workflow };
|
|
3245
3335
|
}
|
|
3246
3336
|
else if (fix === "gate_and_defaults" && gatePlan !== null) {
|
|
3247
|
-
await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
3337
|
+
policyResult = await fixGateAndDefaults(deps, options, access, gatePlan);
|
|
3248
3338
|
}
|
|
3249
3339
|
else if (fix === "merge_token" && state.identity !== null) {
|
|
3250
3340
|
await fixMergeToken(deps, setup, state.identity, state.evidence.mergeCredential.state === "stored_rejected");
|
|
3251
3341
|
}
|
|
3252
3342
|
else if (fix === "reindex") {
|
|
3253
|
-
state.evidence = { ...state.evidence, index: await fixReindex(deps, setup, access) };
|
|
3343
|
+
state.evidence = { ...state.evidence, index: await fixReindex(deps, setup, access, state.evidence.recovery) };
|
|
3254
3344
|
}
|
|
3255
3345
|
}
|
|
3256
3346
|
// ---- Explicit operations, each behind its own consent (unchanged) -------
|
|
3257
|
-
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") {
|
|
3258
3349
|
await runConductorGateQualification(gateIo, access, deps.gate, {
|
|
3259
|
-
revision: gatePlan.current.revision,
|
|
3350
|
+
revision: policyResult?.current?.state.revision ?? gatePlan.current.revision,
|
|
3260
3351
|
baseUrl,
|
|
3261
3352
|
});
|
|
3262
3353
|
}
|
|
@@ -3309,19 +3400,21 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3309
3400
|
const finalReport = await deps.runDoctor({
|
|
3310
3401
|
access,
|
|
3311
3402
|
reviewPolicySource: options.reviewPolicy,
|
|
3403
|
+
assessmentVersion: 1,
|
|
3404
|
+
epicRunId: options.assessmentEpicRunId,
|
|
3312
3405
|
storedMergeCredential: storedMergeContextFor(setup, firstReport.readiness?.provider_repository ?? null, localRemote),
|
|
3313
3406
|
});
|
|
3314
|
-
const finalReadiness =
|
|
3407
|
+
const finalReadiness = options.assessmentEpicRunId !== undefined
|
|
3408
|
+
? finalReport.readiness
|
|
3409
|
+
: observedReadiness ?? finalReport.readiness;
|
|
3315
3410
|
const closing = await collectSetupEvidence(deps, setup, access, finalReadiness, {
|
|
3316
3411
|
...collectInputs,
|
|
3317
3412
|
advisories: state.evidence.advisories,
|
|
3318
3413
|
commandChanged: state.commandChanged,
|
|
3319
3414
|
commandBlocked: state.commandBlocked,
|
|
3320
3415
|
});
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
closing.evidence.index = { state: "queued_by_setup" };
|
|
3324
|
-
}
|
|
3416
|
+
if (state.evidence.index.state === "recovery_unresolved" && closing.evidence.index.state !== "reached")
|
|
3417
|
+
closing.evidence.index = state.evidence.index;
|
|
3325
3418
|
const items = [...projectSetupItems(closing.evidence), ...state.failedOperations];
|
|
3326
3419
|
if (deniesEnforcementUnknown(finalReport)) {
|
|
3327
3420
|
items.push({
|
|
@@ -3354,7 +3447,12 @@ async function runConvergingSetup(options, deps, setup) {
|
|
|
3354
3447
|
// The latest authoritative command (after any replacement) and what CI installs
|
|
3355
3448
|
// for it. Operator-only: written through deps.log and nowhere else.
|
|
3356
3449
|
logStoredCommandAndToolchains(deps, closing.evidence.testCommand.state === "stored" ? closing.storedCommand : null, closing.toolchains);
|
|
3357
|
-
|
|
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"))
|
|
3358
3456
|
deps.log(line);
|
|
3359
3457
|
for (const advisory of closing.evidence.advisories)
|
|
3360
3458
|
deps.log(` - ${advisory}`);
|
|
@@ -3377,7 +3475,7 @@ const DRY_RUN_FIX_TEXT = Object.freeze({
|
|
|
3377
3475
|
setup_pr: "open the setup pull request with the CI workflow (its own consent)",
|
|
3378
3476
|
gate_and_defaults: "store the repository gate and the safe supervisor defaults (its own consent)",
|
|
3379
3477
|
merge_token: "store a GitHub merge token on this computer (its own consent, read with no echo)",
|
|
3380
|
-
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",
|
|
3381
3479
|
});
|
|
3382
3480
|
/**
|
|
3383
3481
|
* The claude-review workflow, only for an explicit `--review-policy
|