@bridge_gpt/mcp-server 0.2.69 → 0.2.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
package/build/setup-epic.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ticketReviewSummary } from "./ticket-review-summary.js";
|
|
2
|
+
import { previewLaunchReadiness } from "./conductor/bridge-api-client.js";
|
|
3
|
+
import { previewObservationScopeMatches } from "./conductor/preview-observations.js";
|
|
1
4
|
/**
|
|
2
5
|
* `setup-epic` — one-command bootstrap for an Epic Implementer run.
|
|
3
6
|
*
|
|
@@ -82,7 +85,7 @@
|
|
|
82
85
|
import { readFile as fsReadFile, stat as fsStat } from "node:fs/promises";
|
|
83
86
|
import os from "node:os";
|
|
84
87
|
import { createProductionEpicIntegrationGhRunner, ensureEpicIntegrationPullRequest, formatEpicIntegrationPullRequestOutcome, } from "./epic-integration-pr.js";
|
|
85
|
-
import { approveEpicPlan, buildConductorJiraUrl, conductorGetHeaders, createEpicRunWithDisposition, decodeCanonicalProvenance, fetchConductorReadiness, fetchEpicRunState, replaceEpicRunPolicy, resolveConductorBridgeApiAccess, resolveEpicLaunchBridgeApiAccess, safeDiagnosticMessage, storeEpicPlan, validateEpicPlan, ConductorBridgeApiError, } from "./conductor/bridge-api-client.js";
|
|
88
|
+
import { approveEpicPlan, buildConductorJiraUrl, conductorGetHeaders, createEpicRunWithDisposition, decodeCanonicalProvenance, fetchConductorReadiness, formatSchemaIncompatibleRefusal, isSchemaIncompatibleError, fetchEpicRunState, replaceEpicRunPolicy, resolveConductorBridgeApiAccess, resolveEpicLaunchBridgeApiAccess, safeDiagnosticMessage, storeEpicPlan, validateEpicPlan, ConductorBridgeApiError, } from "./conductor/bridge-api-client.js";
|
|
86
89
|
import { formatEpicLaunchChannelIdentity, getPinnedEpicLaunchPolicy, readEpicLaunchProfile, } from "./epic-launch-profile.js";
|
|
87
90
|
// BAPI-1133 (A2) — the single legacy-to-typed merge-execution-mode mapping and
|
|
88
91
|
// its total legacy resolver live in `merge-pull-request.ts` (no import cycle:
|
|
@@ -94,6 +97,7 @@ import { classifyMergeExecutionEligibility } from "./conductor/merge-execution-e
|
|
|
94
97
|
import { repositoryWorkflowRemedy } from "./conductor/repository-workflow-remedy.js";
|
|
95
98
|
import { resolveTrackedPaths } from "./git-reachability.js";
|
|
96
99
|
import { validateBranchName } from "./base-ref.js";
|
|
100
|
+
import { TICKET_KEY_PATTERN } from "./ticket-key-utils.js";
|
|
97
101
|
// Reused from the implement-epic client on purpose: adding a second wrapper under
|
|
98
102
|
// `conductor/` would give the v2 path its own copy to drift from.
|
|
99
103
|
//
|
|
@@ -113,6 +117,138 @@ import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
|
113
117
|
// state. See `planeBinding` on `SetupEpicDeps` below.
|
|
114
118
|
import { createPlaneFsDeps, createPlaneProcessDeps } from "./plane/defaults.js";
|
|
115
119
|
import { bindPlaneManifestEpicRun, manifestHasLiveProcess, readPlaneManifest, } from "./plane/manifest.js";
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Verification hand-off choice (BAPI-1496)
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
/** The policy keys child 1 (BAPI-1492) declares on the server's `RunPolicy`. */
|
|
124
|
+
export const SETUP_EPIC_VERIFICATION_HANDOFF_ENABLED_KEY = "verification_handoff_enabled";
|
|
125
|
+
export const SETUP_EPIC_VERIFICATION_HANDOFF_EXCEPTIONS_KEY = "verification_handoff_exceptions";
|
|
126
|
+
/**
|
|
127
|
+
* The closed step-class vocabulary. Mirrors the server's
|
|
128
|
+
* `VERIFICATION_HANDOFF_STEP_CLASSES` in `api/models/epic_run.py`; a client
|
|
129
|
+
* cannot import a Python constant, so a test pins the two together.
|
|
130
|
+
*/
|
|
131
|
+
export const SETUP_EPIC_VERIFICATION_HANDOFF_STEP_CLASSES = [
|
|
132
|
+
"unit_tests",
|
|
133
|
+
"e2e_tests",
|
|
134
|
+
"rendered_ui_review",
|
|
135
|
+
];
|
|
136
|
+
/** Mirrors the server's `MAX_VERIFICATION_HANDOFF_EXCEPTIONS`. */
|
|
137
|
+
export const SETUP_EPIC_MAX_VERIFICATION_HANDOFF_EXCEPTIONS = 200;
|
|
138
|
+
/**
|
|
139
|
+
* Deduplicate and order exception pairs deterministically, by ticket key and
|
|
140
|
+
* then class, so the same set always composes the same bytes.
|
|
141
|
+
*/
|
|
142
|
+
export function normalizeVerificationHandoffExceptions(entries) {
|
|
143
|
+
const seen = new Map();
|
|
144
|
+
for (const entry of entries) {
|
|
145
|
+
seen.set(`${entry.ticket_key}\u0000${entry.step_class}`, {
|
|
146
|
+
ticket_key: entry.ticket_key,
|
|
147
|
+
step_class: entry.step_class,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return [...seen.values()].sort((a, b) => a.ticket_key === b.ticket_key
|
|
151
|
+
? a.step_class.localeCompare(b.step_class)
|
|
152
|
+
: a.ticket_key.localeCompare(b.ticket_key));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Validate the raw flag values. Every refusal names the offending flag and
|
|
156
|
+
* repeats only CLI-supplied text, before any file read or request.
|
|
157
|
+
*/
|
|
158
|
+
export function parseVerificationHandoffFlags(args) {
|
|
159
|
+
if (args.choice === undefined && args.exceptions.length === 0)
|
|
160
|
+
return { ok: true, value: undefined };
|
|
161
|
+
if (args.choice === undefined) {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
error: "--verification-handoff-exception requires --verification-handoff block. An exception " +
|
|
165
|
+
"only narrows a hand-off choice, so without one there is nothing to narrow.",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (args.choice !== "proceed" && args.choice !== "block") {
|
|
169
|
+
return {
|
|
170
|
+
ok: false,
|
|
171
|
+
error: `--verification-handoff must be one of: proceed, block. Got '${args.choice}'.`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (args.attended || args.intoBase) {
|
|
175
|
+
const flag = args.attended ? "--attended" : "--into-base";
|
|
176
|
+
return {
|
|
177
|
+
ok: false,
|
|
178
|
+
error: `--verification-handoff cannot be combined with ${flag}: a verification hand-off ` +
|
|
179
|
+
"needs an unattended epic-branch run, and this launch has no such authority. " +
|
|
180
|
+
"Drop --verification-handoff; verification stays a blocker.",
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const parsed = [];
|
|
184
|
+
for (const raw of args.exceptions) {
|
|
185
|
+
const separator = raw.lastIndexOf(":");
|
|
186
|
+
const ticketKey = separator > 0 ? raw.slice(0, separator) : "";
|
|
187
|
+
const stepClass = separator > 0 ? raw.slice(separator + 1) : "";
|
|
188
|
+
if (!TICKET_KEY_PATTERN.test(ticketKey)) {
|
|
189
|
+
return {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: `--verification-handoff-exception '${raw}' must be <TICKET>:<class> with a ticket key such as PROJ-12.`,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (!SETUP_EPIC_VERIFICATION_HANDOFF_STEP_CLASSES.includes(stepClass)) {
|
|
195
|
+
return {
|
|
196
|
+
ok: false,
|
|
197
|
+
error: `--verification-handoff-exception '${raw}' names an unsupported class. Use one of: ` +
|
|
198
|
+
`${SETUP_EPIC_VERIFICATION_HANDOFF_STEP_CLASSES.join(", ")}.`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
parsed.push({ ticket_key: ticketKey, step_class: stepClass });
|
|
202
|
+
}
|
|
203
|
+
if (args.choice === "proceed" && parsed.length > 0) {
|
|
204
|
+
return {
|
|
205
|
+
ok: false,
|
|
206
|
+
error: "--verification-handoff-exception cannot be combined with --verification-handoff proceed. " +
|
|
207
|
+
"Use --verification-handoff block to keep verification a blocker for named work.",
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
if (args.choice === "block" && parsed.length === 0) {
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
error: "--verification-handoff block needs at least one --verification-handoff-exception " +
|
|
214
|
+
"<TICKET>:<class> naming the work whose verification stays a blocker.",
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const exceptions = normalizeVerificationHandoffExceptions(parsed);
|
|
218
|
+
if (exceptions.length > SETUP_EPIC_MAX_VERIFICATION_HANDOFF_EXCEPTIONS) {
|
|
219
|
+
return {
|
|
220
|
+
ok: false,
|
|
221
|
+
error: `--verification-handoff-exception names ${exceptions.length} distinct entries; the run ` +
|
|
222
|
+
`policy holds at most ${SETUP_EPIC_MAX_VERIFICATION_HANDOFF_EXCEPTIONS}. Nothing was created.`,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return { ok: true, value: { choice: args.choice, exceptions } };
|
|
226
|
+
}
|
|
227
|
+
/** The two policy keys a validated choice composes. */
|
|
228
|
+
export function verificationHandoffPolicyKeys(choice) {
|
|
229
|
+
return {
|
|
230
|
+
[SETUP_EPIC_VERIFICATION_HANDOFF_ENABLED_KEY]: true,
|
|
231
|
+
[SETUP_EPIC_VERIFICATION_HANDOFF_EXCEPTIONS_KEY]: choice.exceptions.map((entry) => ({ ...entry })),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Read a policy file's declared exception list as a normalized pair set, or
|
|
236
|
+
* `null` when it is not a well-shaped list. Never returns or echoes a value.
|
|
237
|
+
*/
|
|
238
|
+
function readDeclaredHandoffExceptions(value) {
|
|
239
|
+
if (!Array.isArray(value))
|
|
240
|
+
return null;
|
|
241
|
+
const entries = [];
|
|
242
|
+
for (const entry of value) {
|
|
243
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
244
|
+
return null;
|
|
245
|
+
const { ticket_key: ticketKey, step_class: stepClass } = entry;
|
|
246
|
+
if (typeof ticketKey !== "string" || typeof stepClass !== "string")
|
|
247
|
+
return null;
|
|
248
|
+
entries.push({ ticket_key: ticketKey, step_class: stepClass });
|
|
249
|
+
}
|
|
250
|
+
return normalizeVerificationHandoffExceptions(entries);
|
|
251
|
+
}
|
|
116
252
|
/**
|
|
117
253
|
* The one `policy_json.posture` value that means "unattended" (BAPI-1102).
|
|
118
254
|
*
|
|
@@ -225,7 +361,7 @@ export function getSetupEpicUsage() {
|
|
|
225
361
|
"default branch. `drive-epic` readiness lists all three with their current state.",
|
|
226
362
|
"",
|
|
227
363
|
"Required:",
|
|
228
|
-
" --epic-key <KEY>
|
|
364
|
+
" --epic-key <KEY> Epic key (e.g. PROJ-123)",
|
|
229
365
|
" --plan-file <path> Path to epic-plan.dag.json (from decompose-epic)",
|
|
230
366
|
"",
|
|
231
367
|
"Options:",
|
|
@@ -248,14 +384,13 @@ export function getSetupEpicUsage() {
|
|
|
248
384
|
" the default would leave on base.",
|
|
249
385
|
" --into-base OPT OUT of the epic-branch default: cut no branch and",
|
|
250
386
|
" target every child PR at the repository base branch",
|
|
251
|
-
" (the
|
|
387
|
+
" (children target the base branch). Use this if automation",
|
|
252
388
|
" depended on \"no flag = direct to base\". Contradictory",
|
|
253
389
|
" with --feature-branch; passing both is a parse error.",
|
|
254
390
|
" --attended OPT OUT of the unattended default: compose only",
|
|
255
391
|
" base_branch (plus --review-policy when supplied), with",
|
|
256
392
|
" no posture and no auto-merge authorization, and skip the",
|
|
257
|
-
" unattended repository prerequisites entirely.
|
|
258
|
-
" request is byte-for-byte the pre-BAPI-1102 one.",
|
|
393
|
+
" unattended repository prerequisites entirely.",
|
|
259
394
|
" Contradictory with a --policy-file that declares",
|
|
260
395
|
" posture: unattended; that pair is refused by name.",
|
|
261
396
|
" --review-policy <src> PER-RUN review policy source, one of:",
|
|
@@ -272,12 +407,22 @@ export function getSetupEpicUsage() {
|
|
|
272
407
|
" default is stamped into a new run only when the run",
|
|
273
408
|
" sets no review policy of its own, so a value supplied",
|
|
274
409
|
" here always wins.",
|
|
410
|
+
" --verification-handoff proceed|block",
|
|
411
|
+
" The owner's answer to the setup gap question,",
|
|
412
|
+
" for a NEW unattended epic-branch run. proceed composes",
|
|
413
|
+
" verification_handoff_enabled: true with no exceptions;",
|
|
414
|
+
" block composes it with the named exceptions. Refused with",
|
|
415
|
+
" --attended, --into-base, a launch with no epic branch, or",
|
|
416
|
+
" a live run (use patch-policy). Omitted, no key is sent.",
|
|
417
|
+
" --verification-handoff-exception <TICKET>:<class>",
|
|
418
|
+
` Repeatable; class is one of ${SETUP_EPIC_VERIFICATION_HANDOFF_STEP_CLASSES.join(", ")}.`,
|
|
419
|
+
" Required with block, refused with proceed. At most",
|
|
420
|
+
` ${SETUP_EPIC_MAX_VERIFICATION_HANDOFF_EXCEPTIONS} distinct entries.`,
|
|
275
421
|
" --json Emit a single JSON result object on stdout",
|
|
276
|
-
" --launch-profile <name>
|
|
277
|
-
" credential from
|
|
278
|
-
"
|
|
279
|
-
"
|
|
280
|
-
" --base-url <url> (BAPI-1260) Explicit target; must agree with the profile.",
|
|
422
|
+
" --launch-profile <name> Passed by drive-epic: resolve the target, repository, and",
|
|
423
|
+
" credential from a host-local launch profile (see",
|
|
424
|
+
" `drive-epic --help-advanced`).",
|
|
425
|
+
" --base-url <url> Explicit target; must agree with the profile.",
|
|
281
426
|
" -h, --help Show this help",
|
|
282
427
|
"",
|
|
283
428
|
"Policy controls:",
|
|
@@ -290,8 +435,7 @@ export function getSetupEpicUsage() {
|
|
|
290
435
|
" type's gate ceiling (implement / spec_review / resume",
|
|
291
436
|
" 10799; remediate / ci_fix 3599; rebase / smoke 2699;",
|
|
292
437
|
" merge 1799); the server rejects a higher value with a",
|
|
293
|
-
" 422 naming the offending field.
|
|
294
|
-
" docs/epic-implementer/operator-runbook.md §4.",
|
|
438
|
+
" 422 naming the offending field.",
|
|
295
439
|
" --replace-policy Authorize replacing a LIVE run's stored policy with the",
|
|
296
440
|
" policy file, as a complete replacement. Without it, a",
|
|
297
441
|
" divergent policy on a reused run is refused with a",
|
|
@@ -380,8 +524,26 @@ export function parseSetupEpicArgs(argv) {
|
|
|
380
524
|
let json = false;
|
|
381
525
|
let launchProfile;
|
|
382
526
|
let baseUrl;
|
|
527
|
+
// BAPI-1496 — raw hand-off values; validated together after the loop.
|
|
528
|
+
let verificationHandoffChoice;
|
|
529
|
+
const verificationHandoffExceptions = [];
|
|
383
530
|
for (let i = 0; i < argv.length; i++) {
|
|
384
531
|
const arg = argv[i];
|
|
532
|
+
// BAPI-1496 — inline forms of the hand-off flags.
|
|
533
|
+
if (arg.startsWith("--verification-handoff=")) {
|
|
534
|
+
verificationHandoffChoice = arg.slice("--verification-handoff=".length).trim();
|
|
535
|
+
if (verificationHandoffChoice === "") {
|
|
536
|
+
return { status: "error", message: "--verification-handoff requires a value." };
|
|
537
|
+
}
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
if (arg.startsWith("--verification-handoff-exception=")) {
|
|
541
|
+
const raw = arg.slice("--verification-handoff-exception=".length).trim();
|
|
542
|
+
if (raw === "")
|
|
543
|
+
return { status: "error", message: "--verification-handoff-exception requires a value." };
|
|
544
|
+
verificationHandoffExceptions.push(raw);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
385
547
|
// `--policy-file=<path>` inline form (BAPI-754).
|
|
386
548
|
if (arg.startsWith("--policy-file=")) {
|
|
387
549
|
const raw = arg.slice("--policy-file=".length).trim();
|
|
@@ -494,6 +656,18 @@ export function parseSetupEpicArgs(argv) {
|
|
|
494
656
|
i++;
|
|
495
657
|
break;
|
|
496
658
|
}
|
|
659
|
+
case "--verification-handoff":
|
|
660
|
+
case "--verification-handoff-exception": {
|
|
661
|
+
const v = takeValue(argv, i, arg);
|
|
662
|
+
if (v === null || v.trim() === "")
|
|
663
|
+
return { status: "error", message: `${arg} requires a value.` };
|
|
664
|
+
if (arg === "--verification-handoff")
|
|
665
|
+
verificationHandoffChoice = v.trim();
|
|
666
|
+
else
|
|
667
|
+
verificationHandoffExceptions.push(v.trim());
|
|
668
|
+
i++;
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
497
671
|
case "--into-base":
|
|
498
672
|
intoBase = true;
|
|
499
673
|
break;
|
|
@@ -551,6 +725,16 @@ export function parseSetupEpicArgs(argv) {
|
|
|
551
725
|
"may be selected — remove whichever one you did not mean.",
|
|
552
726
|
};
|
|
553
727
|
}
|
|
728
|
+
// BAPI-1496 — the hand-off choice, its pairing rules, and its topology rule,
|
|
729
|
+
// refused here before any file read, credential resolution, or request.
|
|
730
|
+
const handoff = parseVerificationHandoffFlags({
|
|
731
|
+
choice: verificationHandoffChoice,
|
|
732
|
+
exceptions: verificationHandoffExceptions,
|
|
733
|
+
attended,
|
|
734
|
+
intoBase,
|
|
735
|
+
});
|
|
736
|
+
if (!handoff.ok)
|
|
737
|
+
return { status: "error", message: handoff.error };
|
|
554
738
|
if (replacePolicy && policyFile === undefined) {
|
|
555
739
|
return {
|
|
556
740
|
status: "error",
|
|
@@ -578,6 +762,8 @@ export function parseSetupEpicArgs(argv) {
|
|
|
578
762
|
// BAPI-1260 — only when supplied, so a legacy options object is unchanged.
|
|
579
763
|
...(launchProfile ? { launchProfile } : {}),
|
|
580
764
|
...(baseUrl ? { baseUrl } : {}),
|
|
765
|
+
// BAPI-1496 — only when supplied, so a legacy options object is unchanged.
|
|
766
|
+
...(handoff.value !== undefined ? { verificationHandoff: handoff.value } : {}),
|
|
581
767
|
},
|
|
582
768
|
};
|
|
583
769
|
}
|
|
@@ -715,6 +901,39 @@ export function composeSetupEpicPolicy(filePolicy, selections) {
|
|
|
715
901
|
: { source: selections.reviewPolicy };
|
|
716
902
|
}
|
|
717
903
|
}
|
|
904
|
+
// BAPI-1496 — the hand-off keys under the same "no silent winner" rule. No
|
|
905
|
+
// choice leaves the file's values exactly as written; a choice fills only an
|
|
906
|
+
// absent key and refuses any declared disagreement. Exception lists compare as
|
|
907
|
+
// (ticket_key, step_class) sets. Neither value is echoed.
|
|
908
|
+
if (selections.verificationHandoff !== undefined) {
|
|
909
|
+
const wanted = verificationHandoffPolicyKeys(selections.verificationHandoff);
|
|
910
|
+
const enabledKey = SETUP_EPIC_VERIFICATION_HANDOFF_ENABLED_KEY;
|
|
911
|
+
const exceptionsKey = SETUP_EPIC_VERIFICATION_HANDOFF_EXCEPTIONS_KEY;
|
|
912
|
+
const flag = `--verification-handoff ${selections.verificationHandoff.choice}`;
|
|
913
|
+
if (enabledKey in composed && composed[enabledKey] !== wanted[enabledKey]) {
|
|
914
|
+
return {
|
|
915
|
+
ok: false,
|
|
916
|
+
error: `${flag} turns the verification hand-off on, but --policy-file declares a different ` +
|
|
917
|
+
`${enabledKey}. setup-epic will not pick a winner between them: drop the flag, or fix ` +
|
|
918
|
+
`the policy file so both agree.`,
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
if (exceptionsKey in composed) {
|
|
922
|
+
const declared = readDeclaredHandoffExceptions(composed[exceptionsKey]);
|
|
923
|
+
if (declared === null || JSON.stringify(declared) !== JSON.stringify(wanted[exceptionsKey])) {
|
|
924
|
+
return {
|
|
925
|
+
ok: false,
|
|
926
|
+
error: `${flag} selects a set of verification exceptions, but --policy-file declares a ` +
|
|
927
|
+
`different ${exceptionsKey}. setup-epic will not pick a winner between them: drop ` +
|
|
928
|
+
`the flag, or fix the policy file so both agree.`,
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
for (const key of [enabledKey, exceptionsKey]) {
|
|
933
|
+
if (!(key in composed))
|
|
934
|
+
composed[key] = wanted[key];
|
|
935
|
+
}
|
|
936
|
+
}
|
|
718
937
|
return { ok: true, policy: composed };
|
|
719
938
|
}
|
|
720
939
|
/**
|
|
@@ -773,7 +992,27 @@ export function preflightSetupEpicPolicy(args) {
|
|
|
773
992
|
`declaration from the policy file.`,
|
|
774
993
|
};
|
|
775
994
|
}
|
|
776
|
-
// 3.
|
|
995
|
+
// 3. BAPI-1496 — a hand-off choice needs an unattended epic-branch launch.
|
|
996
|
+
// `--attended` and `--into-base` are already parse errors; this covers the
|
|
997
|
+
// topology resolved from the plan and the file: no epic branch at all, or a
|
|
998
|
+
// file whose declared posture is not the unattended one.
|
|
999
|
+
if (args.verificationHandoff !== undefined) {
|
|
1000
|
+
const declaresOtherPosture = args.filePolicy !== undefined &&
|
|
1001
|
+
"posture" in args.filePolicy &&
|
|
1002
|
+
args.filePolicy.posture !== SETUP_EPIC_UNATTENDED_POSTURE;
|
|
1003
|
+
if ((args.featureBranch === undefined && !args.policyDeclaresBranch) || declaresOtherPosture) {
|
|
1004
|
+
return {
|
|
1005
|
+
ok: false,
|
|
1006
|
+
reason: "verification_handoff_without_authority",
|
|
1007
|
+
message: "--verification-handoff needs an unattended run on an epic branch, and this launch " +
|
|
1008
|
+
(declaresOtherPosture
|
|
1009
|
+
? `is not unattended: --policy-file '${args.policyFile}' declares another posture. `
|
|
1010
|
+
: "selects no epic branch. ") +
|
|
1011
|
+
"Drop --verification-handoff; verification stays a blocker.",
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
// 4. Policy-source contradictions between the file and the CLI selections.
|
|
777
1016
|
// Delegated to the composer, which owns the "no silent winner" rule; the
|
|
778
1017
|
// gate only gives the outcome a stable name.
|
|
779
1018
|
if (args.filePolicy === undefined)
|
|
@@ -781,6 +1020,7 @@ export function preflightSetupEpicPolicy(args) {
|
|
|
781
1020
|
const composed = composeSetupEpicPolicy(args.filePolicy, {
|
|
782
1021
|
featureBranch: args.featureBranch,
|
|
783
1022
|
reviewPolicy: args.reviewPolicy,
|
|
1023
|
+
...(args.verificationHandoff !== undefined ? { verificationHandoff: args.verificationHandoff } : {}),
|
|
784
1024
|
});
|
|
785
1025
|
if (!composed.ok) {
|
|
786
1026
|
return { ok: false, reason: "policy_source_contradiction", message: composed.error };
|
|
@@ -1144,7 +1384,48 @@ function findCycle(keys, adjacency) {
|
|
|
1144
1384
|
}
|
|
1145
1385
|
return null;
|
|
1146
1386
|
}
|
|
1147
|
-
|
|
1387
|
+
/**
|
|
1388
|
+
* Count the distinct ordering relationships a validated plan declares, through
|
|
1389
|
+
* either supported representation: top-level `edges` and per-node `depends_on`.
|
|
1390
|
+
* One pair is counted once however many places declare it. Empty IDs and
|
|
1391
|
+
* self-loops are ignored; node existence is validated elsewhere, not here.
|
|
1392
|
+
*/
|
|
1393
|
+
function countDeclaredOrderingPairs(plan) {
|
|
1394
|
+
const pairs = new Set();
|
|
1395
|
+
const add = (from, to) => {
|
|
1396
|
+
if (typeof from !== "string" || typeof to !== "string")
|
|
1397
|
+
return;
|
|
1398
|
+
if (from === "" || to === "" || from === to)
|
|
1399
|
+
return;
|
|
1400
|
+
pairs.add(`${from}->${to}`);
|
|
1401
|
+
};
|
|
1402
|
+
for (const edge of Array.isArray(plan.edges) ? plan.edges : [])
|
|
1403
|
+
add(edge?.from, edge?.to);
|
|
1404
|
+
for (const node of Array.isArray(plan.nodes) ? plan.nodes : []) {
|
|
1405
|
+
for (const dependency of Array.isArray(node?.depends_on) ? node.depends_on : []) {
|
|
1406
|
+
add(dependency, node.ticket_key);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return pairs.size;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* The channel a STORED policy resolves to, from the engine's own
|
|
1413
|
+
* `notification_sink` facts. The stored policy is server-redacted, so its
|
|
1414
|
+
* `notify` block cannot answer this. Strict `=== true` comparisons: a truthy
|
|
1415
|
+
* non-boolean is unavailable, never a guess.
|
|
1416
|
+
*/
|
|
1417
|
+
function storedEscalationChannel(notificationSink) {
|
|
1418
|
+
if (!notificationSink || typeof notificationSink !== "object" || Array.isArray(notificationSink)) {
|
|
1419
|
+
return "unavailable";
|
|
1420
|
+
}
|
|
1421
|
+
const sink = notificationSink;
|
|
1422
|
+
if (sink.webhook_configured === true)
|
|
1423
|
+
return "configured webhook";
|
|
1424
|
+
if (sink.email_channel_selected === true)
|
|
1425
|
+
return "account email";
|
|
1426
|
+
return "unavailable";
|
|
1427
|
+
}
|
|
1428
|
+
export function effectivePolicyFacts(policy, source, notificationSink) {
|
|
1148
1429
|
const object = policy && typeof policy === "object" && !Array.isArray(policy)
|
|
1149
1430
|
? policy : {};
|
|
1150
1431
|
const numbers = (value) => {
|
|
@@ -1159,7 +1440,9 @@ export function effectivePolicyFacts(policy, source) {
|
|
|
1159
1440
|
posture: object.posture === "unattended" ? "unattended" : "attended",
|
|
1160
1441
|
caps: numbers(object.caps),
|
|
1161
1442
|
job_timeouts: numbers(object.job_timeouts),
|
|
1162
|
-
escalation_channel: formatEpicLaunchChannelIdentity(source === "stored"
|
|
1443
|
+
escalation_channel: formatEpicLaunchChannelIdentity(source === "stored"
|
|
1444
|
+
? storedEscalationChannel(notificationSink)
|
|
1445
|
+
: policyDeclaresNotifyWebhook(object) ? "configured webhook" : "account email"),
|
|
1163
1446
|
};
|
|
1164
1447
|
}
|
|
1165
1448
|
/** Propose a conductor epic feature branch name for an epic key (BAPI-655). */
|
|
@@ -1351,7 +1634,7 @@ export function evaluateSetupEpicUnattendedPrerequisites(readiness, requestedPol
|
|
|
1351
1634
|
message: "unattended runs are off for this repository. Turn on 'Allow unattended " +
|
|
1352
1635
|
"Epic Implementer runs' on the repository's Setup page in the Bridge admin " +
|
|
1353
1636
|
"panel, or pass --attended to create an attended run. If it is already on, " +
|
|
1354
|
-
"
|
|
1637
|
+
"email info@bridgegpt.ai. No run was created.",
|
|
1355
1638
|
};
|
|
1356
1639
|
}
|
|
1357
1640
|
// Two independent sources satisfy the escalation channel, and the check has to
|
|
@@ -1411,7 +1694,7 @@ export function evaluateSetupEpicBringUpPrerequisites(readiness) {
|
|
|
1411
1694
|
if (readiness === null) {
|
|
1412
1695
|
return {
|
|
1413
1696
|
reason: "readiness_unreadable",
|
|
1414
|
-
message: "the
|
|
1697
|
+
message: "the Epic Implementer readiness report could not be read, so the database " +
|
|
1415
1698
|
"migration, worker presence, and single-reconciler facts could not be confirmed. " +
|
|
1416
1699
|
`Retry once the server is reachable. ${NO_RUN_WAS_CREATED}`,
|
|
1417
1700
|
};
|
|
@@ -1462,8 +1745,8 @@ export function evaluateSetupEpicMergeExecutionPrerequisites(readiness, requeste
|
|
|
1462
1745
|
if (readiness === null) {
|
|
1463
1746
|
return {
|
|
1464
1747
|
reason: MERGE_EXECUTION_INELIGIBLE,
|
|
1465
|
-
message: "this run declares merge_execution_mode: github_actions, and the
|
|
1466
|
-
"
|
|
1748
|
+
message: "this run declares merge_execution_mode: github_actions, and the Epic " +
|
|
1749
|
+
"Implementer readiness report could not be read, so the repository's merge " +
|
|
1467
1750
|
"capability could not be confirmed. Retry once the server is reachable. If " +
|
|
1468
1751
|
"readiness then reports the merge workflow missing or out of date, resolve it " +
|
|
1469
1752
|
`with \`${MERGE_WORKFLOW_REMEDY_COMMAND}\`. ${MERGE_WORKFLOW_CODEOWNER_INSTRUCTION} ` +
|
|
@@ -1555,6 +1838,9 @@ export function composeDefaultSetupEpicPolicy(args) {
|
|
|
1555
1838
|
policy[SETUP_EPIC_INTEGRATION_PREPARATION_POLICY_KEY] = {
|
|
1556
1839
|
...SETUP_EPIC_INTEGRATION_PREPARATION_DEFAULT,
|
|
1557
1840
|
};
|
|
1841
|
+
if (args.verificationHandoff !== undefined) {
|
|
1842
|
+
Object.assign(policy, verificationHandoffPolicyKeys(args.verificationHandoff));
|
|
1843
|
+
}
|
|
1558
1844
|
}
|
|
1559
1845
|
}
|
|
1560
1846
|
if (args.reviewPolicy !== undefined) {
|
|
@@ -1698,13 +1984,13 @@ async function applyReusedRunPolicy(args) {
|
|
|
1698
1984
|
});
|
|
1699
1985
|
if (outcome.kind === "noop") {
|
|
1700
1986
|
args.result.policy_applied = "noop";
|
|
1701
|
-
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored");
|
|
1987
|
+
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored", args.notificationSink);
|
|
1702
1988
|
args.say("Policy: policy unchanged");
|
|
1703
1989
|
return true;
|
|
1704
1990
|
}
|
|
1705
1991
|
if (outcome.kind === "refused_divergent") {
|
|
1706
1992
|
args.result.policy_applied = "refused_divergent";
|
|
1707
|
-
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored");
|
|
1993
|
+
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored", args.notificationSink);
|
|
1708
1994
|
args.deps.errorLog(`Epic run ${args.epicRunId} is live and its stored policy differs from the ` +
|
|
1709
1995
|
`policy file. setup-epic will not silently change a running epic's policy.\n` +
|
|
1710
1996
|
`${outcome.diffLines.join("\n")}\n` +
|
|
@@ -1717,7 +2003,7 @@ async function applyReusedRunPolicy(args) {
|
|
|
1717
2003
|
}
|
|
1718
2004
|
catch (err) {
|
|
1719
2005
|
args.result.policy_applied = "refused_divergent";
|
|
1720
|
-
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored");
|
|
2006
|
+
args.result.effective_policy = effectivePolicyFacts(args.storedPolicy, "stored", args.notificationSink);
|
|
1721
2007
|
args.deps.errorLog(`Failed to replace the run policy: ${errorDetail(err)}`);
|
|
1722
2008
|
return false;
|
|
1723
2009
|
}
|
|
@@ -1981,6 +2267,9 @@ export async function runSetupEpicWorkflow(argv, overrides = {}, handoff) {
|
|
|
1981
2267
|
exitCode,
|
|
1982
2268
|
...(sink.epicRunId !== undefined ? { epicRunId: sink.epicRunId } : {}),
|
|
1983
2269
|
...(sink.epicRunId !== undefined ? { runExists: true } : {}),
|
|
2270
|
+
...(sink.runCreated !== undefined ? { runCreated: sink.runCreated } : {}),
|
|
2271
|
+
...(sink.planStored !== undefined ? { planStored: sink.planStored } : {}),
|
|
2272
|
+
...(sink.reusedExistingRun !== undefined ? { reusedExistingRun: sink.reusedExistingRun } : {}),
|
|
1984
2273
|
};
|
|
1985
2274
|
}
|
|
1986
2275
|
/**
|
|
@@ -2080,13 +2369,18 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2080
2369
|
selectedProfilePolicyPath = profileRead.profile.policyRef?.path;
|
|
2081
2370
|
}
|
|
2082
2371
|
}
|
|
2372
|
+
let observations;
|
|
2083
2373
|
let existingRunId = null;
|
|
2374
|
+
let existingTicketReview;
|
|
2084
2375
|
let existingStatus = null;
|
|
2085
2376
|
let existingBaseBranch = null;
|
|
2086
2377
|
let existingReviewPolicy = null;
|
|
2087
2378
|
// BAPI-754: the live run's SERVER-REDACTED stored policy, kept for the reuse
|
|
2088
2379
|
// comparison. Redacted is the only form a client can ever see.
|
|
2089
2380
|
let existingPolicyJson = null;
|
|
2381
|
+
// The same response's engine-reported notification facts (never the redacted
|
|
2382
|
+
// policy's `notify`), for the stored-policy channel label.
|
|
2383
|
+
let existingNotificationSink = null;
|
|
2090
2384
|
if (!opts.localOnly) {
|
|
2091
2385
|
// --- Resolve access ------------------------------------------------------
|
|
2092
2386
|
// BAPI-1260: a caller that selected the epic-launch contract (drive-epic
|
|
@@ -2114,9 +2408,15 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2114
2408
|
return 1;
|
|
2115
2409
|
}
|
|
2116
2410
|
access = accessResult.access;
|
|
2411
|
+
observations = opts.dryRun ? deps.previewObservations : undefined;
|
|
2412
|
+
if (observations !== undefined && (!previewObservationScopeMatches(observations, access, opts.epicKey) ||
|
|
2413
|
+
observations.liveRun.state === "error" || observations.readiness.state !== "supplied")) {
|
|
2414
|
+
deps.errorLog("Preview observations are unavailable or have a mismatched scope. Nothing was created.");
|
|
2415
|
+
return 1;
|
|
2416
|
+
}
|
|
2117
2417
|
say(`Epic: ${opts.epicKey}`);
|
|
2118
2418
|
say(`Repo: ${access.repoName}`);
|
|
2119
|
-
say(`Plan: v${plan.plan_version}, ${plan.nodes.length} node(s), ${plan
|
|
2419
|
+
say(`Plan: v${plan.plan_version}, ${plan.nodes.length} node(s), ${countDeclaredOrderingPairs(plan)} edge(s)`);
|
|
2120
2420
|
say(`Local hash: ${localHash}`);
|
|
2121
2421
|
for (const w of warnings)
|
|
2122
2422
|
say(` [warn] ${w}`);
|
|
@@ -2126,11 +2426,15 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2126
2426
|
// --- Step 0: pre-check ---------------------------------------------------
|
|
2127
2427
|
// Never create on an ambiguous read. A wrong answer here mints a duplicate run.
|
|
2128
2428
|
try {
|
|
2129
|
-
const state =
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2429
|
+
const state = observations === undefined
|
|
2430
|
+
? await fetchEpicRunState(access, opts.epicKey, deps.fetch)
|
|
2431
|
+
: observations.liveRun.state === "supplied" ? observations.liveRun.value : null;
|
|
2432
|
+
existingRunId = state?.epic_run?.epic_run_id ?? null;
|
|
2433
|
+
existingTicketReview = state?.epic_run?.ticket_review;
|
|
2434
|
+
existingStatus = state?.epic_run?.status ?? null;
|
|
2435
|
+
const existingPolicy = state?.epic_run?.policy_json;
|
|
2133
2436
|
existingPolicyJson = existingPolicy ?? null;
|
|
2437
|
+
existingNotificationSink = state?.notification_sink ?? null;
|
|
2134
2438
|
const existingBase = existingPolicy && typeof existingPolicy === "object"
|
|
2135
2439
|
? existingPolicy.base_branch
|
|
2136
2440
|
: undefined;
|
|
@@ -2170,6 +2474,22 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2170
2474
|
}
|
|
2171
2475
|
}
|
|
2172
2476
|
}
|
|
2477
|
+
// BAPI-1510 — attach-only reuse. A caller that trimmed the plan must never apply
|
|
2478
|
+
// it to a run that already exists, so a pre-check that found a live run returns
|
|
2479
|
+
// here, before the policy file, any cut, plan store, approval, or other mutation.
|
|
2480
|
+
// A dry run keeps its ordinary reporting. Direct setup-epic never sets the option.
|
|
2481
|
+
//
|
|
2482
|
+
// Only an ACTIVATED run is attach-only. A run still in `planning` or
|
|
2483
|
+
// `pending_approval` was created by an earlier setup that failed a later step
|
|
2484
|
+
// (cut, plan store, approval); re-running setup is how it gets finished, so it
|
|
2485
|
+
// takes the ordinary reuse path with the trimmed plan, guarded by the pinned cut.
|
|
2486
|
+
const reusedRunIsActivated = existingStatus !== null && existingStatus !== "planning" && existingStatus !== "pending_approval";
|
|
2487
|
+
if (existingRunId && reusedRunIsActivated && handoff?.attachOnlyOnReuse === true && !opts.dryRun) {
|
|
2488
|
+
runIdSink.epicRunId = existingRunId;
|
|
2489
|
+
runIdSink.reusedExistingRun = true;
|
|
2490
|
+
say(`Run: reusing ${existingRunId} (status: ${existingStatus}); existing runs are unchanged`);
|
|
2491
|
+
return 0;
|
|
2492
|
+
}
|
|
2173
2493
|
// --- Read the policy file (still no network) ------------------------------
|
|
2174
2494
|
// BAPI-754: parsed here so a malformed file, or a contradiction between the
|
|
2175
2495
|
// file and the CLI flags, fails before credentials are resolved or any request
|
|
@@ -2240,6 +2560,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2240
2560
|
policyDeclaresBranch,
|
|
2241
2561
|
featureBranch,
|
|
2242
2562
|
reviewPolicy: opts.reviewPolicy,
|
|
2563
|
+
...(opts.verificationHandoff !== undefined ? { verificationHandoff: opts.verificationHandoff } : {}),
|
|
2243
2564
|
});
|
|
2244
2565
|
if (!policyGate.ok) {
|
|
2245
2566
|
deps.errorLog(policyGate.message);
|
|
@@ -2252,7 +2573,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2252
2573
|
// The policy gate above already composed and validated; nothing is repeated
|
|
2253
2574
|
// here, so the offline path and the real path refuse the same set.
|
|
2254
2575
|
say(`Epic: ${opts.epicKey}`);
|
|
2255
|
-
say(`Plan: v${plan.plan_version}, ${plan.nodes.length} node(s), ${plan
|
|
2576
|
+
say(`Plan: v${plan.plan_version}, ${plan.nodes.length} node(s), ${countDeclaredOrderingPairs(plan)} edge(s)`);
|
|
2256
2577
|
// BAPI-1009: the same node-count-derived strategy an ordinary run would take,
|
|
2257
2578
|
// stated without cutting a branch, reading the network, or touching git.
|
|
2258
2579
|
say(`Branch: ${branchStrategyLine}`);
|
|
@@ -2336,8 +2657,24 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2336
2657
|
attended: opts.attended,
|
|
2337
2658
|
reviewPolicy: opts.reviewPolicy,
|
|
2338
2659
|
mergeExecutionMode: declaredMergeExecutionMode,
|
|
2660
|
+
...(opts.verificationHandoff !== undefined ? { verificationHandoff: opts.verificationHandoff } : {}),
|
|
2339
2661
|
});
|
|
2340
|
-
|
|
2662
|
+
// Reuse the actual composition result; drive-epic never interprets policy files.
|
|
2663
|
+
let launchReadiness = null;
|
|
2664
|
+
if (!opts.localOnly) {
|
|
2665
|
+
try {
|
|
2666
|
+
// Repository GET readiness uses the server's default policy. This POST
|
|
2667
|
+
// evaluates the actual run policy (including webhook/review settings), so
|
|
2668
|
+
// it is a different check and cannot consume that repository observation.
|
|
2669
|
+
launchReadiness = await previewLaunchReadiness(access, existingRunId !== null ? existingPolicyJson ?? {} : composedForCreate, deps.fetch);
|
|
2670
|
+
}
|
|
2671
|
+
catch {
|
|
2672
|
+
// An unavailable preview is not a proven launch deficiency. Create is authoritative.
|
|
2673
|
+
launchReadiness = null;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
const selectedTicketReview = ticketReviewSummary(existingTicketReview, existingRunId !== null ? existingPolicyJson ?? {} : composedForCreate);
|
|
2677
|
+
const selectedEffectivePolicyFacts = effectivePolicyFacts(existingRunId !== null ? existingPolicyJson : composedForCreate, selectedPolicySource, existingRunId !== null ? existingNotificationSink : undefined);
|
|
2341
2678
|
say(`Policy: effective ${selectedEffectivePolicyFacts.source}; serial execution; ` +
|
|
2342
2679
|
`caps ${selectedEffectivePolicyFacts.caps ? JSON.stringify(selectedEffectivePolicyFacts.caps) : "unavailable"}; ` +
|
|
2343
2680
|
`timeouts ${selectedEffectivePolicyFacts.job_timeouts ? JSON.stringify(selectedEffectivePolicyFacts.job_timeouts) : "unavailable"}; ` +
|
|
@@ -2393,6 +2730,15 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2393
2730
|
// dropping `--feature-branch` reuses the run only when the flag is what asked
|
|
2394
2731
|
// for the branch; when the DEFAULT asked, `--into-base` is the way to say
|
|
2395
2732
|
// "keep this run on base".
|
|
2733
|
+
// BAPI-1496 — the hand-off flags compose a NEW run's policy only. A live run's
|
|
2734
|
+
// policy changes through `patch-policy`; reusing it here would either drop the
|
|
2735
|
+
// owner's answer silently or patch a live run behind the operator's back.
|
|
2736
|
+
if (existingRunId && opts.verificationHandoff !== undefined) {
|
|
2737
|
+
deps.errorLog(`Epic ${opts.epicKey} already has a live run (${existingRunId}). --verification-handoff ` +
|
|
2738
|
+
"sets the policy of a NEW run only. Change a live run's verification hand-off with " +
|
|
2739
|
+
"`epic-implementer patch-policy`, or re-run without --verification-handoff to reuse it.");
|
|
2740
|
+
return 1;
|
|
2741
|
+
}
|
|
2396
2742
|
if (existingRunId && featureBranch !== undefined && existingBaseBranch !== featureBranch) {
|
|
2397
2743
|
const reuseAdvice = opts.featureBranch !== undefined
|
|
2398
2744
|
? "Re-run without --feature-branch to reuse it unchanged"
|
|
@@ -2449,7 +2795,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2449
2795
|
return 1;
|
|
2450
2796
|
}
|
|
2451
2797
|
if (opts.reviewPolicy !== undefined) {
|
|
2452
|
-
say(`Review: ${opts.reviewPolicy} (per-run; repository
|
|
2798
|
+
say(`Review: ${opts.reviewPolicy} (per-run only; no repository default is stored)`);
|
|
2453
2799
|
}
|
|
2454
2800
|
// --- Authoritative server validation (BAPI-754) --------------------------
|
|
2455
2801
|
// Runs BEFORE any create. A plan the server would refuse must not cost a run
|
|
@@ -2607,7 +2953,9 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2607
2953
|
say(" serialization disabled — no ordering was derived from file overlap");
|
|
2608
2954
|
}
|
|
2609
2955
|
else if (validated.insertedEdges === 0) {
|
|
2610
|
-
say(
|
|
2956
|
+
say(validated.overlappingPairsFound > 0
|
|
2957
|
+
? ` serialization enabled — ${validated.overlappingPairsFound} overlapping pair(s) already ordered by declared dependencies`
|
|
2958
|
+
: " serialization enabled — no declared file overlaps produced edges");
|
|
2611
2959
|
}
|
|
2612
2960
|
else {
|
|
2613
2961
|
say(` serialization enabled — ${validated.insertedEdges} edge(s) inserted from ` +
|
|
@@ -2658,6 +3006,23 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2658
3006
|
cutCommitSha = truth.cutCommitSha;
|
|
2659
3007
|
say(`Cut: ${cutCommitSha} (canonical indexed commit; origin/${effectiveFeatureBranch} will be cut here)`);
|
|
2660
3008
|
}
|
|
3009
|
+
// BAPI-1510 — pinned cut. A trimmed launch classified children against ONE
|
|
3010
|
+
// indexed commit; refuse unless setup's own canonical read names that same commit.
|
|
3011
|
+
// This runs even when trimming left a base-branch or single-node launch that
|
|
3012
|
+
// would not otherwise read canonical parse truth, and before any create-side
|
|
3013
|
+
// effect (including on a dry run).
|
|
3014
|
+
if (handoff?.expectedCutCommitSha !== undefined) {
|
|
3015
|
+
let observedCut = cutCommitSha;
|
|
3016
|
+
if (observedCut === null) {
|
|
3017
|
+
const pinTruth = await readCanonicalParseTruth(access, deps.fetch);
|
|
3018
|
+
observedCut = pinTruth.ok ? pinTruth.cutCommitSha : null;
|
|
3019
|
+
}
|
|
3020
|
+
if (observedCut === null || observedCut !== handoff.expectedCutCommitSha) {
|
|
3021
|
+
deps.errorLog("The indexed commit could not be confirmed or changed since the already-merged check. " +
|
|
3022
|
+
"Re-run drive-epic. No run was created and no branch was changed.");
|
|
3023
|
+
return 1;
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
2661
3026
|
if (opts.dryRun) {
|
|
2662
3027
|
say("");
|
|
2663
3028
|
say(validated
|
|
@@ -2675,7 +3040,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2675
3040
|
: ` - feature branch: ${effectiveFeatureBranch} (validated server-side at approval; no request made in dry-run)`);
|
|
2676
3041
|
if (needsCut && cutCommitSha !== null && scopeBaseBranch !== null) {
|
|
2677
3042
|
say(` - would open a draft pull request ${effectiveFeatureBranch} → ${scopeBaseBranch} ` +
|
|
2678
|
-
"for epic-implementer-ci / gate (
|
|
3043
|
+
"for epic-implementer-ci / gate (nothing opened in dry-run)");
|
|
2679
3044
|
}
|
|
2680
3045
|
}
|
|
2681
3046
|
if (opts.reviewPolicy !== undefined) {
|
|
@@ -2698,6 +3063,11 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2698
3063
|
// BAPI-850: the exact commit the cut WOULD use, reported without
|
|
2699
3064
|
// cutting. Present only when the dry run validated canonical parse truth.
|
|
2700
3065
|
...(cutCommitSha !== null ? { cut_commit_sha: cutCommitSha } : {}),
|
|
3066
|
+
// BAPI-1506: the repository base branch the epic branch is cut from
|
|
3067
|
+
// (the configured base, else "main"). Only present for a
|
|
3068
|
+
// feature-branch run; the launch preview compares the epic branch
|
|
3069
|
+
// against it, information only.
|
|
3070
|
+
...(scopeBaseBranch !== null ? { scope_base_branch: scopeBaseBranch } : {}),
|
|
2701
3071
|
// Only present when a policy was explicitly selected — the
|
|
2702
3072
|
// no-policy JSON shape is unchanged.
|
|
2703
3073
|
...(opts.reviewPolicy !== undefined
|
|
@@ -2708,6 +3078,8 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2708
3078
|
server_validated: validated !== null,
|
|
2709
3079
|
policy_applied: "absent",
|
|
2710
3080
|
effective_policy: selectedEffectivePolicyFacts,
|
|
3081
|
+
launch_readiness: launchReadiness,
|
|
3082
|
+
ticket_review: selectedTicketReview,
|
|
2711
3083
|
...(validated
|
|
2712
3084
|
? {
|
|
2713
3085
|
server_plan_hash: validated.planHash,
|
|
@@ -2791,6 +3163,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2791
3163
|
// BAPI-1102 — the reuse path's authoritative id, taken from the pre-check's
|
|
2792
3164
|
// server response rather than from anything local.
|
|
2793
3165
|
runIdSink.epicRunId = existingRunId;
|
|
3166
|
+
runIdSink.reusedExistingRun = true;
|
|
2794
3167
|
say(`Run: reusing ${existingRunId} (status: ${existingStatus})`);
|
|
2795
3168
|
// A pre-check that already found a live run means create would answer 200
|
|
2796
3169
|
// anyway; reconcile the file against that run's stored policy directly.
|
|
@@ -2802,6 +3175,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2802
3175
|
result,
|
|
2803
3176
|
epicRunId: existingRunId,
|
|
2804
3177
|
storedPolicy: existingPolicyJson,
|
|
3178
|
+
notificationSink: existingNotificationSink,
|
|
2805
3179
|
requestedPolicy,
|
|
2806
3180
|
replacePolicy: opts.replacePolicy,
|
|
2807
3181
|
});
|
|
@@ -2837,7 +3211,13 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2837
3211
|
try {
|
|
2838
3212
|
readiness = await fetchConductorReadiness(access, deps.fetch);
|
|
2839
3213
|
}
|
|
2840
|
-
catch {
|
|
3214
|
+
catch (err) {
|
|
3215
|
+
// BAPI-1455 — the one readable refusal: a proven-incompatible local
|
|
3216
|
+
// schema. Its explanation is server-authored from a maintained list.
|
|
3217
|
+
if (isSchemaIncompatibleError(err)) {
|
|
3218
|
+
deps.errorLog(formatSchemaIncompatibleRefusal("setup-epic", err).join("\n"));
|
|
3219
|
+
return 1;
|
|
3220
|
+
}
|
|
2841
3221
|
// Fail CLOSED, and silently as to WHY: the thrown value can carry a URL
|
|
2842
3222
|
// or a response excerpt, and this refusal is rendered to a terminal. The
|
|
2843
3223
|
// generic `readiness_unreadable` message says what to do about it.
|
|
@@ -2908,6 +3288,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2908
3288
|
// returns the server's run for a fresh creation AND for a create-race
|
|
2909
3289
|
// adoption (`created: false`), so both are captured by this one assignment.
|
|
2910
3290
|
runIdSink.epicRunId = run.epic_run_id;
|
|
3291
|
+
runIdSink.runCreated = created;
|
|
2911
3292
|
result.status = run.status;
|
|
2912
3293
|
result.run_created = created;
|
|
2913
3294
|
if (created) {
|
|
@@ -2927,10 +3308,15 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
2927
3308
|
// index is the race backstop that keeps it so. Naming the adopted run and
|
|
2928
3309
|
// its status, rather than reporting a bare reuse, is what lets an operator
|
|
2929
3310
|
// decide between continuing on it and closing it.
|
|
3311
|
+
runIdSink.reusedExistingRun = true;
|
|
2930
3312
|
say(`Run: adopting existing active run ${run.epic_run_id} (status: ${run.status})`);
|
|
2931
3313
|
say(` No second run was created — one epic has at most one active ` +
|
|
2932
3314
|
`run. Continue on this one, or abandon it first with ` +
|
|
2933
3315
|
`\`epic-implementer abandon-run --epic-run-id ${run.epic_run_id}\` to start over.`);
|
|
3316
|
+
// BAPI-1510 — attach-only: a race-adopted run is never touched by a
|
|
3317
|
+
// trimmed launch (no policy replacement, cut, plan store, or approval).
|
|
3318
|
+
if (handoff?.attachOnlyOnReuse === true)
|
|
3319
|
+
return 0;
|
|
2934
3320
|
if (requestedPolicy !== undefined) {
|
|
2935
3321
|
const outcome = await applyReusedRunPolicy({
|
|
2936
3322
|
access,
|
|
@@ -3108,6 +3494,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
3108
3494
|
...(trackedPathEvidence !== undefined ? { trackedPaths: trackedPathEvidence } : {}),
|
|
3109
3495
|
}, deps.fetch);
|
|
3110
3496
|
result.plan_stored = true;
|
|
3497
|
+
runIdSink.planStored = true;
|
|
3111
3498
|
const serverHash = stored?.plan_hash;
|
|
3112
3499
|
if (typeof serverHash === "string")
|
|
3113
3500
|
result.plan_hash = serverHash;
|
|
@@ -3161,7 +3548,7 @@ async function executeSetupEpic(argv, overrides, runIdSink, handoff) {
|
|
|
3161
3548
|
`Turn 'Allow unattended Epic Implementer runs' back on in the repository's ` +
|
|
3162
3549
|
`Setup page in the Bridge admin panel and re-run setup-epic, or ` +
|
|
3163
3550
|
`deliberately convert this run to an attended posture through the ` +
|
|
3164
|
-
`supported operator flow. If it is already on,
|
|
3551
|
+
`supported operator flow. If it is already on, email info@bridgegpt.ai.` +
|
|
3165
3552
|
`\nDetail: ${errorDetail(err)}`);
|
|
3166
3553
|
}
|
|
3167
3554
|
else {
|