@bridge_gpt/mcp-server 0.2.71 → 0.2.73
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 +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -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-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -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-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- 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 +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- 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 +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -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/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -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/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- 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-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
package/build/drive-epic.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { isTerminalRunCleanupStatus } from "./plane/terminal-run-status.js";
|
|
2
|
+
import { resolveDeclaredRunBaseBranch } from "./conductor/run-branch.js";
|
|
1
3
|
import { monotonicNow, elapsedMs, measurePrecheck } from "./conductor/precheck-timings.js";
|
|
2
|
-
import { buildLaunchPlan } from "./conductor/launch-plan.js";
|
|
4
|
+
import { buildLaunchPlan, LAUNCH_PRE_CREATE_CODES, PARALLEL_LIMIT_CHANGE_ADVISORY, PARALLEL_LIMIT_MEANING_COPY, SERVER_WEBHOOK_ROW_ID, } from "./conductor/launch-plan.js";
|
|
3
5
|
import { ticketReviewSummary } from "./ticket-review-summary.js";
|
|
4
6
|
import { parseConductorReadinessResponse } from "./conductor/bridge-api-client.js";
|
|
7
|
+
import { workerSetupTallyEntries } from "./conductor/worker-setup-tally.js";
|
|
5
8
|
import { READINESS_PRE_CREATE_CODES, READINESS_PREREQUISITE_BY_ID, READINESS_LEGACY_IDS } from "./readiness-prerequisites.generated.js";
|
|
6
9
|
/**
|
|
7
10
|
* `drive-epic` — the one universal conductor entry point (BAPI-887).
|
|
@@ -61,34 +64,39 @@ import { READINESS_PRE_CREATE_CODES, READINESS_PREREQUISITE_BY_ID, READINESS_LEG
|
|
|
61
64
|
import { access as fsAccess, readdir, readFile, realpath, stat as fsStat } from "node:fs/promises";
|
|
62
65
|
import { constants as fsConstants } from "node:fs";
|
|
63
66
|
import path, { dirname, join } from "node:path";
|
|
64
|
-
import { ConductorBridgeApiError, resolveEpicLaunchBridgeApiAccess, fetchConductorReadiness,
|
|
67
|
+
import { ConductorBridgeApiError, createReadinessAcquisition, resolveEpicLaunchBridgeApiAccess, fetchConductorReadiness, isSchemaIncompatibleError, SCHEMA_INCOMPATIBLE_REPAIR_ROUTE, fetchEpicRunState, isProviderRepositoryIdentity, safeDiagnosticMessage, classifyChildMergeStatus as classifyChildMergeStatusClient, recordSkippedChildren as recordSkippedChildrenClient, fetchEpicChildren, fetchStoredTicketDescription, resolveConductorBridgeApiAccess, validateEpicPlan, } from "./conductor/bridge-api-client.js";
|
|
65
68
|
import { CHILD_MERGE_STATUS_BATCH_SIZE, buildAlreadyDoneEntries, classifyPlanChildren, selectSkips, } from "./conductor/merged-child-check.js";
|
|
66
69
|
import { trimDonePlanNodes } from "./conductor/plan-trim.js";
|
|
67
70
|
import { withPlanPath } from "./conductor/temporary-plan.js";
|
|
68
|
-
import { ESCALATION_REACHABILITY_CHECK_ID, buildEscalationReachabilityCheck, } from "./escalation-reachability.js";
|
|
69
|
-
import { EPIC_LAUNCH_PROFILE_NAME_PATTERN, epicLaunchPolicyDigest, pinEpicLaunchPolicy, renderEpicLaunchCommand, resolveEpicLaunchSelection, shellQuote, } from "./epic-launch-profile.js";
|
|
71
|
+
import { ESCALATION_REACHABILITY_CHECK_ID, buildEscalationReachabilityCheck, classifyEscalationReachabilityPresentation, } from "./escalation-reachability.js";
|
|
72
|
+
import { EPIC_LAUNCH_PROFILE_NAME_PATTERN, epicLaunchPolicyDigest, getPinnedEpicLaunchPolicy, pinEpicLaunchPolicy, renderEpicLaunchCommand, resolveEpicLaunchSelection, shellQuote, } from "./epic-launch-profile.js";
|
|
70
73
|
import { validateHttpBaseUrl, describeBaseUrlRejection } from "./base-url.js";
|
|
71
|
-
import { BRING_UP_REFUSAL_MESSAGES, BRING_UP_RUNBOOK, firstBringUpRefusal, } from "./conductor/bring-up-facts.js";
|
|
72
|
-
import { V2_READINESS_REQUIREMENTS, buildLaunchReadinessChecks, firstLaunchEvidenceBlocker,
|
|
74
|
+
import { BRING_UP_REFUSAL_MESSAGES, BRING_UP_RUNBOOK, firstBringUpRefusal, firstProvenBringUpRefusal, } from "./conductor/bring-up-facts.js";
|
|
75
|
+
import { V2_READINESS_REQUIREMENTS, buildLaunchEvidenceChecks, buildLaunchReadinessChecks, firstLaunchEvidenceBlocker, projectReadinessRowBlocking, unattendedPostureCheck, } from "./v2-readiness-requirements.js";
|
|
73
76
|
import { classifyLocalGhPreflight, probeLocalMergeCapability, } from "./conductor/local-merge.js";
|
|
74
77
|
import { nodeGithubMergeCredentialReadDeps, resolveMergeCredentialAtAction, } from "./conductor/stored-merge-credential.js";
|
|
75
78
|
import { resolveWorktreeSettingsExclude, } from "./executor/permissions.js";
|
|
76
79
|
import { collectWorkerDatabaseDoctorSection, WORKER_DATABASE_DOCTOR_TIMEOUT_MS, } from "./conductor/doctor.js";
|
|
77
|
-
import {
|
|
78
|
-
import { createWorkflowSource,
|
|
80
|
+
import { buildHostPowerLaunchRow, buildSelfHostedRunnerLaunchRow, buildWorkerDbRoleLaunchRow, hostPowerFactFromReport, LAUNCH_NEED_ROW_IDS, workerDatabaseReadinessChecks, } from "./conductor/readiness-sections.js";
|
|
81
|
+
import { createWorkflowSource, inspectRequiredSelfHostedRunners, } from "./conductor/launch-need-probes.js";
|
|
79
82
|
import { createWorkerDatabaseDoctorInspector } from "./conductor/worker-database-doctor-inspector.js";
|
|
80
|
-
import {
|
|
83
|
+
import { ENGINE_PATHS } from "./engine-paths.js";
|
|
84
|
+
import { policyDeclaresNotifyWebhook, policyNotifyDestinationsConflict, notifyDestinationsConflictMessage, effectivePolicyFacts, evaluateParallelPolicyPreflight, parseParallelLimit, readSetupEpicPolicyFile, retainedParallelLimitNotice, resolveFeatureBranchSelection, readCanonicalParseTruth as readSetupCanonicalParseTruth, runSetupEpicWorkflow, launchReconnectCommand, READINESS_UNKNOWN_CONTINUING_WARNING, RUN_WAITING_FOR_APPROVAL_PHRASE, formatSetupEpicAutoMergeIntent, resolveSetupEpicAutoMergeIntent, readinessSnapshotFromLaunchContext, } from "./setup-epic.js";
|
|
85
|
+
import { getConfigFieldBaseBranch } from "./epic-shared/bridge-client.js";
|
|
81
86
|
import { EPIC_KEY_PATTERN } from "./drive-epic-key.js";
|
|
87
|
+
import { buildEpicLaunchContext, projectWorkerDatabase, readEpicLaunchContext, writeEpicLaunchContext, } from "./epic-launch-context.js";
|
|
82
88
|
import { flushProcessStdout, writeJsonDocument } from "./conductor/json-output.js";
|
|
83
89
|
import { BRIDGE_LAUNCHER_ENV } from "./bridge-permissions.js";
|
|
84
90
|
import { checkPlaneBuildFreshness, PLANE_BUILD_FIX_REMEDIATION } from "./plane/build-freshness.js";
|
|
85
|
-
import { discoverEpicPlan, } from "./plan-discovery.js";
|
|
86
|
-
import {
|
|
87
|
-
import {
|
|
91
|
+
import { discoverEpicPlan, isPlanGenerationEligible, unrelatedMissingMetaPaths, } from "./plan-discovery.js";
|
|
92
|
+
import { attemptPlanGeneration, createDefaultPlanPublicationFs, generatedPlanFolder, listTrackedFilesWithGit, publishGeneratedPlan, validateGeneratedPlan, } from "./plan-generation-io.js";
|
|
93
|
+
import { PLAN_GENERATION_FAILURE_TEXT, } from "./plan-generation.js";
|
|
94
|
+
import { DEFAULT_RUN_PARALLEL_LIMIT, formatPlaneDiagnostic, isPlaneExecutorLaneMember, launchPlaneControlPlane, parallelLimitToExecutorLanes, requestPlaneScopedLanes, runDefaultPlanePreflight, runPlaneCli, } from "./plane/cli.js";
|
|
95
|
+
import { PLANE_PORT_PROBE_TIMEOUT_MS, describePlanePortOccupant, classifyBridgeCheckout, } from "./plane/preflight.js";
|
|
88
96
|
import { createPlaneExecFile, createPlaneFsDeps, probeAutomationHealth, probeTcpPort, resolveHostname, } from "./plane/defaults.js";
|
|
89
97
|
import { readPlaneManifest } from "./plane/manifest.js";
|
|
90
|
-
import { cleanupTerminalRunPlane, createTerminalRunCleanupDeps, terminalRunCleanupStderrLine, } from "./plane/terminal-run-cleanup.js";
|
|
91
|
-
import { checkPlaneFreshness, inspectHostSleep, PLANE_DATABASE_HEAD_ID, PLANE_DATABASE_HEAD_REMEDY, PLANE_FRESHNESS_UNVERIFIED_REMEDY, PLANE_HOST_SLEEP_ID, PLANE_SLEEP_REMEDY, formatBoundPlaneStaleRemedy, PLANE_SNAPSHOT_FRESHNESS_ID, PLANE_SNAPSHOT_STALE_REMEDY, } from "./plane/plane-freshness.js";
|
|
98
|
+
import { cleanupTerminalRunPlane, createTerminalRunCleanupDeps, readOtherLiveRun, terminalRunCleanupStderrLine, } from "./plane/terminal-run-cleanup.js";
|
|
99
|
+
import { checkPlaneFreshness, inspectHostSleep, PLANE_DATABASE_HEAD_ID, PLANE_DATABASE_HEAD_REMEDY, PLANE_FRESHNESS_UNVERIFIED_REMEDY, PLANE_HOST_SLEEP_ID, PLANE_SLEEP_REMEDY, formatBoundPlaneStaleRemedy, formatSharedPlaneStaleRemedy, PLANE_SNAPSHOT_FRESHNESS_ID, PLANE_SNAPSHOT_STALE_REMEDY, } from "./plane/plane-freshness.js";
|
|
92
100
|
import { baseUrlNamesPlaneEndpoint, planeEndpointForTarget } from "./plane/endpoint.js";
|
|
93
101
|
import { resolvePlaneServerEndpoint, } from "./plane/member-roster.js";
|
|
94
102
|
import { resolveMemberInstanceId } from "./plane/supervisor.js";
|
|
@@ -100,7 +108,7 @@ import { isTerminalEpicRunStatus } from "./epic-run-status.js";
|
|
|
100
108
|
import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
101
109
|
import { getDriveEpicAdvancedUsage, getDriveEpicUsage } from "./drive-epic-help.js";
|
|
102
110
|
export { getDriveEpicUsage };
|
|
103
|
-
import { CONSUMER_GUIDE_POINTER, PRINTED_CHECK_NAME_INSTRUCTION, PRINTED_CONDUCTOR_INSTALL_COMMAND, PRINTED_DOCTOR_COMMAND, } from "./printed-remedy-commands.js";
|
|
111
|
+
import { CONSUMER_GUIDE_POINTER, PRINTED_CHECK_NAME_INSTRUCTION, PRINTED_CONDUCTOR_INSTALL_COMMAND, PRINTED_DOCTOR_COMMAND, READINESS_PREREQUISITE_FIXES, resolveReadinessRemedy, } from "./printed-remedy-commands.js";
|
|
104
112
|
/** The conductor paths. Derived types below come from this constant. */
|
|
105
113
|
export const DRIVE_EPIC_CONDUCTORS = ["v2"];
|
|
106
114
|
/**
|
|
@@ -151,6 +159,21 @@ const MERGE_CREDENTIAL_ROW = "conductor.merge-credential-capability";
|
|
|
151
159
|
* three competing actions has to work out which to do first, and the order here
|
|
152
160
|
* already encodes that (setup, then config, then credentials).
|
|
153
161
|
*/
|
|
162
|
+
/** The reason id of a PROVEN mandatory-diagnostic failure (unchanged by BAPI-1595). */
|
|
163
|
+
const MANDATORY_DIAGNOSTIC_FAILED_ID = "mandatory-diagnostic-unverified";
|
|
164
|
+
const MANDATORY_DIAGNOSTIC_FAILED_REMEDY = "Resolve the mandatory diagnostic at the selected Bridge API target and retry.";
|
|
165
|
+
/**
|
|
166
|
+
* BAPI-1595 — whether any diagnostic is uncertain: missing severity or
|
|
167
|
+
* applicability, or a mandatory applicable one whose verdict was not established.
|
|
168
|
+
* Such a finding warns (it is never a proven failure) and the launch continues.
|
|
169
|
+
*/
|
|
170
|
+
export function mandatoryDiagnosticsUncertain(diagnostics) {
|
|
171
|
+
return (diagnostics ?? []).some((diagnostic) => diagnostic.severity === null ||
|
|
172
|
+
diagnostic.applicability === null ||
|
|
173
|
+
(diagnostic.applicability === "applicable" &&
|
|
174
|
+
diagnostic.severity === "mandatory" &&
|
|
175
|
+
diagnostic.verdict === "unknown"));
|
|
176
|
+
}
|
|
154
177
|
export function classifyV2Readiness(readiness, options = {},
|
|
155
178
|
/**
|
|
156
179
|
* BAPI-1452 — the value-free launch evidence (credential probe verdict and
|
|
@@ -161,21 +184,17 @@ export function classifyV2Readiness(readiness, options = {},
|
|
|
161
184
|
* posture is never read from here — only from the server report.
|
|
162
185
|
*/
|
|
163
186
|
launchEvidence) {
|
|
187
|
+
// BAPI-1595 — only a PROVEN failure refuses: a diagnostic that is explicitly
|
|
188
|
+
// mandatory, explicitly applicable, and `failed`. An unknown verdict, or one whose
|
|
189
|
+
// severity or applicability was not established, is uncertainty (see
|
|
190
|
+
// {@link mandatoryDiagnosticsUncertain}), never a stop.
|
|
164
191
|
for (const diagnostic of readiness.diagnostics ?? []) {
|
|
165
|
-
if (diagnostic.severity ===
|
|
166
|
-
return {
|
|
167
|
-
kind: "operator_blocked",
|
|
168
|
-
id: "diagnostic-metadata-unknown",
|
|
169
|
-
describe: "Additional readiness diagnostics",
|
|
170
|
-
remedy: "Upgrade or repair the readiness producer, then retry the selected target.",
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
if (diagnostic.applicability === "applicable" && diagnostic.severity === "mandatory" && diagnostic.verdict !== "passed") {
|
|
192
|
+
if (diagnostic.applicability === "applicable" && diagnostic.severity === "mandatory" && diagnostic.verdict === "failed") {
|
|
174
193
|
return {
|
|
175
194
|
kind: "operator_blocked",
|
|
176
|
-
id:
|
|
195
|
+
id: MANDATORY_DIAGNOSTIC_FAILED_ID,
|
|
177
196
|
describe: "Additional readiness diagnostics",
|
|
178
|
-
remedy:
|
|
197
|
+
remedy: MANDATORY_DIAGNOSTIC_FAILED_REMEDY,
|
|
179
198
|
};
|
|
180
199
|
}
|
|
181
200
|
}
|
|
@@ -266,16 +285,47 @@ launchEvidence) {
|
|
|
266
285
|
if (blocker) {
|
|
267
286
|
return {
|
|
268
287
|
kind: "operator_blocked",
|
|
269
|
-
id: { "server.indexed-workflows": READINESS_PRE_CREATE_CODES.INDEXED_WORKFLOWS_NOT_MET, "server.unattended-notify-default": READINESS_PRE_CREATE_CODES.ESCALATION_CHANNEL_NOT_MET, "server.
|
|
288
|
+
id: { "server.indexed-workflows": READINESS_PRE_CREATE_CODES.INDEXED_WORKFLOWS_NOT_MET, "server.unattended-notify-default": READINESS_PRE_CREATE_CODES.ESCALATION_CHANNEL_NOT_MET, "server.escalation-webhook-reachable": LAUNCH_PRE_CREATE_CODES.ESCALATION_WEBHOOK_UNREACHABLE, "server.provider-default-branch-readable": LAUNCH_PRE_CREATE_CODES.PROVIDER_DEFAULT_BRANCH_UNREADABLE }[blocker.id] ?? blocker.id,
|
|
270
289
|
describe: blocker.describe,
|
|
271
290
|
...(() => {
|
|
272
|
-
const remedy = blocker.
|
|
291
|
+
const remedy = blocker.id === INDEXED_WORKFLOWS_ROW_ID
|
|
292
|
+
? indexedWorkflowsRemedy(readiness)
|
|
293
|
+
: blocker.remedyFor?.(readiness) ?? blocker.remedy;
|
|
273
294
|
return remedy ? { remedy } : {};
|
|
274
295
|
})(),
|
|
275
296
|
};
|
|
276
297
|
}
|
|
277
298
|
return { kind: "runtime_only", unmetIds: unmet.map((req) => req.id) };
|
|
278
299
|
}
|
|
300
|
+
const INDEXED_WORKFLOWS_ROW_ID = "server.indexed-workflows";
|
|
301
|
+
/**
|
|
302
|
+
* BAPI-1635 — the refusal guidance for an unmet indexed-workflows row, chosen from
|
|
303
|
+
* the row the server already sent. No new read is made.
|
|
304
|
+
*
|
|
305
|
+
* The server sends a wire-compatible EMPTY fix for the richer remedies, so an empty
|
|
306
|
+
* or missing fix resolves by prerequisite ID (the repository is not indexed). An
|
|
307
|
+
* explicit published remedy keeps its meaning: `no_index` re-indexes, `pending_index`
|
|
308
|
+
* waits, and only a fix that actually carries the setup remedy tells the owner to
|
|
309
|
+
* merge the setup pull request. Anything else known-but-unclassified says the
|
|
310
|
+
* determining state could not be established, so no pending pull request is guessed.
|
|
311
|
+
*/
|
|
312
|
+
function indexedWorkflowsRemedy(readiness) {
|
|
313
|
+
const row = readiness.prerequisites?.find((p) => p.id === INDEXED_WORKFLOWS_ROW_ID);
|
|
314
|
+
if (row === undefined)
|
|
315
|
+
return INDEXED_WORKFLOWS_UNCLASSIFIED;
|
|
316
|
+
const fix = row.fix.length > 0
|
|
317
|
+
? row.fix
|
|
318
|
+
: resolveReadinessRemedy({ id: INDEXED_WORKFLOWS_ROW_ID, state: row.check_status === "unknown" ? "unknown" : "not_met" });
|
|
319
|
+
if (fix === READINESS_PREREQUISITE_FIXES.no_index || fix === READINESS_PREREQUISITE_FIXES.reindex_manual) {
|
|
320
|
+
return READINESS_PREREQUISITE_FIXES.reindex_manual;
|
|
321
|
+
}
|
|
322
|
+
if (fix === READINESS_PREREQUISITE_FIXES.pending_index)
|
|
323
|
+
return "Wait for indexing to finish, then run drive-epic again.";
|
|
324
|
+
if (fix.includes("Merge the setup pull request") || fix === READINESS_PREREQUISITE_FIXES.setup || fix.includes("merge the workflow changes"))
|
|
325
|
+
return fix;
|
|
326
|
+
return INDEXED_WORKFLOWS_UNCLASSIFIED;
|
|
327
|
+
}
|
|
328
|
+
const INDEXED_WORKFLOWS_UNCLASSIFIED = "The state blocking the indexed workflows could not be established; run readiness again to read it.";
|
|
279
329
|
/**
|
|
280
330
|
* Parse argv. Rejects malformed input BEFORE any side effect — no readiness
|
|
281
331
|
* read, no credential resolution, no delegation.
|
|
@@ -332,12 +382,25 @@ export function parseDriveEpicArgs(argv) {
|
|
|
332
382
|
const keepChildren = [];
|
|
333
383
|
const skipChildren = [];
|
|
334
384
|
let noMergedCheck = false;
|
|
385
|
+
// BAPI-1581 — validated for shape with setup-epic's own parser; forwarded verbatim.
|
|
386
|
+
let parallel;
|
|
335
387
|
for (let i = 0; i < argv.length; i++) {
|
|
336
388
|
const arg = argv[i];
|
|
337
389
|
if (arg === "--all") {
|
|
338
390
|
all = true;
|
|
339
391
|
continue;
|
|
340
392
|
}
|
|
393
|
+
if (arg === "--parallel" || arg.startsWith("--parallel=")) {
|
|
394
|
+
const inline = arg.startsWith("--parallel=");
|
|
395
|
+
const raw = inline ? arg.slice("--parallel=".length) : argv[i + 1];
|
|
396
|
+
const parsedParallel = parseParallelLimit(!inline && (raw === undefined || raw.startsWith("-")) ? undefined : raw);
|
|
397
|
+
if (!parsedParallel.ok)
|
|
398
|
+
return { status: "error", message: parsedParallel.error };
|
|
399
|
+
parallel = parsedParallel.value;
|
|
400
|
+
if (!inline)
|
|
401
|
+
i++;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
341
404
|
if (arg === "--no-merged-check") {
|
|
342
405
|
noMergedCheck = true;
|
|
343
406
|
continue;
|
|
@@ -488,6 +551,16 @@ export function parseDriveEpicArgs(argv) {
|
|
|
488
551
|
"form of the read-only launch preview, and a real launch has no JSON output.",
|
|
489
552
|
};
|
|
490
553
|
}
|
|
554
|
+
// BAPI-1581 — an unattended-only request against an explicit opt-out, refused by
|
|
555
|
+
// name whatever the argument order, before any request or local service.
|
|
556
|
+
if (parallel !== undefined && (attended || intoBase)) {
|
|
557
|
+
return {
|
|
558
|
+
status: "error",
|
|
559
|
+
message: "drive-epic REFUSED (parallel-requires-unattended): --parallel sets the limit of an " +
|
|
560
|
+
`unattended run, and ${attended ? "--attended opts out of unattended operation" : "--into-base runs children directly into the repository base branch"}. ` +
|
|
561
|
+
"Drop --parallel, or make the run unattended.",
|
|
562
|
+
};
|
|
563
|
+
}
|
|
491
564
|
// BAPI-1510 — contradictory child intent is refused before any file read or launch.
|
|
492
565
|
const overlap = keepChildren.filter((key) => skipChildren.includes(key));
|
|
493
566
|
if (overlap.length > 0) {
|
|
@@ -557,6 +630,7 @@ export function parseDriveEpicArgs(argv) {
|
|
|
557
630
|
// Added only when supplied, so the no-flag options object stays byte-identical.
|
|
558
631
|
...(attended ? { attended: true } : {}),
|
|
559
632
|
...(policyFile ? { policyFile } : {}),
|
|
633
|
+
...(parallel !== undefined ? { parallel } : {}),
|
|
560
634
|
...(reviewPolicy ? { reviewPolicy } : {}),
|
|
561
635
|
...(replacePolicy ? { replacePolicy: true } : {}),
|
|
562
636
|
...(launchProfile ? { launchProfile } : {}),
|
|
@@ -596,7 +670,7 @@ export function parseDriveEpicArgs(argv) {
|
|
|
596
670
|
* about to be created.
|
|
597
671
|
*/
|
|
598
672
|
export function selectConductor(readiness) {
|
|
599
|
-
const missing = V2_READINESS_REQUIREMENTS.filter((req) => req.unattendedOnly !== true && req.advisoryOnly !== true && !req.satisfied(readiness));
|
|
673
|
+
const missing = V2_READINESS_REQUIREMENTS.filter((req) => req.unattendedOnly !== true && req.launchOnly !== true && req.advisoryOnly !== true && !req.satisfied(readiness));
|
|
600
674
|
if (missing.length === 0) {
|
|
601
675
|
return {
|
|
602
676
|
kind: "selected",
|
|
@@ -622,7 +696,7 @@ export function selectConductor(readiness) {
|
|
|
622
696
|
* no quoting to get wrong.
|
|
623
697
|
*/
|
|
624
698
|
export function buildSetupEpicArgv(options) {
|
|
625
|
-
const { epicKey, planFile, repo, featureBranch, intoBase, attended, policyFile, reviewPolicy, replacePolicy, launchProfile, baseUrl, verificationHandoff, verificationHandoffExceptions, } = options;
|
|
699
|
+
const { epicKey, planFile, repo, featureBranch, intoBase, attended, policyFile, reviewPolicy, replacePolicy, launchProfile, baseUrl, verificationHandoff, verificationHandoffExceptions, parallel, } = options;
|
|
626
700
|
return [
|
|
627
701
|
"--epic-key",
|
|
628
702
|
epicKey,
|
|
@@ -647,6 +721,9 @@ export function buildSetupEpicArgv(options) {
|
|
|
647
721
|
// when supplied, so every pre-existing argv stays byte-identical.
|
|
648
722
|
...(verificationHandoff !== undefined ? ["--verification-handoff", verificationHandoff] : []),
|
|
649
723
|
...(verificationHandoffExceptions ?? []).flatMap((entry) => ["--verification-handoff-exception", entry]),
|
|
724
|
+
// BAPI-1581 — the operator's requested limit, appended last and only when
|
|
725
|
+
// supplied, so every pre-existing argv stays byte-identical.
|
|
726
|
+
...(parallel !== undefined ? ["--parallel", String(parallel)] : []),
|
|
650
727
|
];
|
|
651
728
|
}
|
|
652
729
|
/**
|
|
@@ -679,7 +756,9 @@ launch = { profile: null },
|
|
|
679
756
|
* BAPI-1285 — what discovery found. Absent reads as "no metadata named this
|
|
680
757
|
* epic", with the searched directory left as its placeholder.
|
|
681
758
|
*/
|
|
682
|
-
discovery, presentation = "default"
|
|
759
|
+
discovery, presentation = "default",
|
|
760
|
+
/** BAPI-1621 — why automatic plan generation stopped, when it was tried. */
|
|
761
|
+
generationReason) {
|
|
683
762
|
// BAPI-1496 — an owner's explicit verification hand-off choice survives the
|
|
684
763
|
// re-run command verbatim. Nothing is derived: no flag, no flag added.
|
|
685
764
|
const handoffSuffix = [
|
|
@@ -711,6 +790,13 @@ discovery, presentation = "default") {
|
|
|
711
790
|
...discovery.candidates.map((candidate) => ` - ${candidate}`),
|
|
712
791
|
]
|
|
713
792
|
: [`No epic-plan.meta.json under ${plansDir} names ${epicKey}.`];
|
|
793
|
+
const generation = generationReason !== undefined
|
|
794
|
+
? [
|
|
795
|
+
"",
|
|
796
|
+
`Automatic plan generation was tried and stopped (${generationReason}): ` +
|
|
797
|
+
`${PLAN_GENERATION_FAILURE_TEXT[generationReason]}. Nothing was written.`,
|
|
798
|
+
]
|
|
799
|
+
: [];
|
|
714
800
|
const skipped = discovery !== undefined && discovery.skipped.length > 0
|
|
715
801
|
? [
|
|
716
802
|
"",
|
|
@@ -727,6 +813,7 @@ discovery, presentation = "default") {
|
|
|
727
813
|
: `${epicKey}: ${selection.reason}, but no plan was supplied and none could be selected.`,
|
|
728
814
|
"",
|
|
729
815
|
...outcome,
|
|
816
|
+
...generation,
|
|
730
817
|
...skipped,
|
|
731
818
|
"",
|
|
732
819
|
"Discovery reads only epic-plan.meta.json ({\"epic_key\": ...}). It never matches a",
|
|
@@ -769,8 +856,8 @@ const PLANE_DOWN_SELECTION = {
|
|
|
769
856
|
* The one text both the preview and a real launch print for the guarded
|
|
770
857
|
* plane-down no-plan stop, so the preview is a verbatim part of the real output.
|
|
771
858
|
*/
|
|
772
|
-
function planeDownNoPlanStopText(epicKey, launch, discovery) {
|
|
773
|
-
const text = renderConductorHandoff(PLANE_DOWN_SELECTION, epicKey, launch, discovery, "plane_not_running")
|
|
859
|
+
function planeDownNoPlanStopText(epicKey, launch, discovery, generationReason) {
|
|
860
|
+
const text = renderConductorHandoff(PLANE_DOWN_SELECTION, epicKey, launch, discovery, "plane_not_running", generationReason)
|
|
774
861
|
.lines.join("\n");
|
|
775
862
|
assertSingleConductorInvocation(text);
|
|
776
863
|
return text;
|
|
@@ -1042,9 +1129,16 @@ function createDefaultPlanDiscoveryFs() {
|
|
|
1042
1129
|
readFile: (filePath) => readFile(filePath, "utf8"),
|
|
1043
1130
|
};
|
|
1044
1131
|
}
|
|
1132
|
+
/**
|
|
1133
|
+
* The server's terminal code for more than one active run on one epic
|
|
1134
|
+
* (`api/library/db/epic_runs.py:EPIC_RUN_CODE_ACTIVE_RUN_EXISTS`). The only 409
|
|
1135
|
+
* the live-run read counts as a wedged epic (BAPI-1595).
|
|
1136
|
+
*/
|
|
1137
|
+
export const ACTIVE_EPIC_RUN_EXISTS_ERROR_CODE = "ACTIVE_EPIC_RUN_EXISTS";
|
|
1045
1138
|
/**
|
|
1046
1139
|
* BAPI-1285 — map the by-epic-key run read the way `setup-epic`'s Step 0 does:
|
|
1047
|
-
* 404 is no run, 409 is a wedged epic, and
|
|
1140
|
+
* 404 is no run, a 409 carrying `ACTIVE_EPIC_RUN_EXISTS` is a wedged epic, and
|
|
1141
|
+
* every other failure (any other 409 included) is unknown.
|
|
1048
1142
|
* Nothing but a status and an error kind is ever kept from a failure.
|
|
1049
1143
|
*/
|
|
1050
1144
|
export async function readLiveEpicRunByKey(access, epicKey, fetchImpl = globalThis.fetch) {
|
|
@@ -1075,8 +1169,12 @@ export async function readLiveEpicRunByKey(access, epicKey, fetchImpl = globalTh
|
|
|
1075
1169
|
if (err instanceof ConductorBridgeApiError) {
|
|
1076
1170
|
if (err.status === 404)
|
|
1077
1171
|
return { kind: "none" };
|
|
1078
|
-
|
|
1172
|
+
// BAPI-1595 — a 409 is a wedged epic ONLY when its typed `errorCode` says so.
|
|
1173
|
+
// Any other 409, or one with no readable code, proves nothing about whether a
|
|
1174
|
+
// second run exists, so it is unknown (the server's idempotent create decides).
|
|
1175
|
+
if (err.status === 409 && err.errorCode === ACTIVE_EPIC_RUN_EXISTS_ERROR_CODE) {
|
|
1079
1176
|
return { kind: "conflict" };
|
|
1177
|
+
}
|
|
1080
1178
|
return {
|
|
1081
1179
|
kind: "unknown",
|
|
1082
1180
|
reason: `kind=${err.kind}${typeof err.status === "number" ? ` status=${err.status}` : ""}`,
|
|
@@ -1094,7 +1192,19 @@ export function createDefaultDriveEpicDeps() {
|
|
|
1094
1192
|
if (!top.ok || !path.isAbsolute(top.stdout.trim()))
|
|
1095
1193
|
throw new Error("repository_root_unverifiable");
|
|
1096
1194
|
const repoRoot = await realpath(top.stdout.trim());
|
|
1097
|
-
|
|
1195
|
+
// BAPI-1595 — tri-state: only all-markers-absent is non-Bridge. A partial
|
|
1196
|
+
// checkout stays Bridge-applicable, and a marker that cannot be inspected
|
|
1197
|
+
// keeps the existing `repository-identity-unverifiable` refusal.
|
|
1198
|
+
const applicability = await classifyBridgeCheckout(repoRoot, createPlaneFsDeps());
|
|
1199
|
+
if (applicability === "unknown")
|
|
1200
|
+
throw new Error("repository_identity_unverifiable");
|
|
1201
|
+
return { repoRoot, isBridge: applicability === "bridge" };
|
|
1202
|
+
},
|
|
1203
|
+
readScopeBaseBranch: async (access) => {
|
|
1204
|
+
const configured = await getConfigFieldBaseBranch(access, globalThis.fetch);
|
|
1205
|
+
if (!configured.ok)
|
|
1206
|
+
return null;
|
|
1207
|
+
return configured.value.base_branch !== null ? configured.value.base_branch : "main";
|
|
1098
1208
|
},
|
|
1099
1209
|
resolveAccess: async (repo, cwd, launch) => {
|
|
1100
1210
|
// BAPI-1260: the target-first launch contract. BAPI-1272: with no target
|
|
@@ -1115,6 +1225,8 @@ export function createDefaultDriveEpicDeps() {
|
|
|
1115
1225
|
process.env.BAPI_BASE_URL = baseUrl;
|
|
1116
1226
|
},
|
|
1117
1227
|
readReadiness: (access) => fetchConductorReadiness(access, globalThis.fetch),
|
|
1228
|
+
writeLaunchContext: (context) => writeEpicLaunchContext(context),
|
|
1229
|
+
reportLaunch: (report) => console.error(`${LAUNCH_REPORT_PREFIX}${JSON.stringify(report)}`),
|
|
1118
1230
|
runSetupEpic: (argv, handoff) => runSetupEpicWorkflow(argv, {}, handoff),
|
|
1119
1231
|
readEligibilityArtifact: (path) => readFile(path, "utf8"),
|
|
1120
1232
|
runPlanePreflight: (repoRoot) => runDefaultPlanePreflight(repoRoot),
|
|
@@ -1135,7 +1247,10 @@ export function createDefaultDriveEpicDeps() {
|
|
|
1135
1247
|
cwd: () => process.cwd(),
|
|
1136
1248
|
resolvePlaneEndpoint: () => resolvePlaneServerEndpoint(process.env),
|
|
1137
1249
|
probePlanePort: (host, port) => probeTcpPort(host, port, PLANE_PORT_PROBE_TIMEOUT_MS),
|
|
1138
|
-
checkExecutorBuildFreshness: (repoRoot) => checkPlaneBuildFreshness(repoRoot, {
|
|
1250
|
+
checkExecutorBuildFreshness: (repoRoot, applicability) => checkPlaneBuildFreshness(repoRoot, {
|
|
1251
|
+
fs: createPlaneFsDeps(),
|
|
1252
|
+
...(applicability?.isBridge === false ? { isBridge: false } : {}),
|
|
1253
|
+
}),
|
|
1139
1254
|
collectPlaneFreshness: ({ repoRoot, ownsManifest, expectedPlaneId }) => checkPlaneFreshness(repoRoot, {
|
|
1140
1255
|
execFile: createPlaneExecFile(),
|
|
1141
1256
|
fileExists: (filePath) => fsStat(filePath).then((entry) => entry.isFile(), () => false),
|
|
@@ -1150,10 +1265,30 @@ export function createDefaultDriveEpicDeps() {
|
|
|
1150
1265
|
execFile: createPlaneExecFile(),
|
|
1151
1266
|
workflows: createWorkflowSource(),
|
|
1152
1267
|
}),
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1268
|
+
// A launch shows only the role and the boundary (BAPI-1594); `doctor` keeps the full inspection.
|
|
1269
|
+
inspectWorkerDatabase: (repoRoot, config) => createWorkerDatabaseDoctorInspector({ env: process.env, cwd: repoRoot ?? process.cwd(), scope: "launch" })(config),
|
|
1270
|
+
// BAPI-1596 — child 5's validated cache, read-only: no claim, no write, bounded in time.
|
|
1271
|
+
readPrerequisiteCache: async ({ epicKey, children, access }) => {
|
|
1272
|
+
const { readCachedPrerequisites } = await import("./conductor/prerequisite-inputs.js");
|
|
1273
|
+
const { fetchStoredTicket } = await import("./conductor/bridge-api-client.js");
|
|
1274
|
+
let timer;
|
|
1275
|
+
const deadline = new Promise((resolve) => {
|
|
1276
|
+
timer = setTimeout(() => resolve({ kind: "unavailable" }), PREREQUISITE_CACHE_READ_TIMEOUT_MS);
|
|
1277
|
+
});
|
|
1278
|
+
try {
|
|
1279
|
+
return await Promise.race([
|
|
1280
|
+
readCachedPrerequisites({ epicKey, children, fetchTicket: (key) => fetchStoredTicket(access, key) }),
|
|
1281
|
+
deadline,
|
|
1282
|
+
]);
|
|
1283
|
+
}
|
|
1284
|
+
finally {
|
|
1285
|
+
if (timer !== undefined)
|
|
1286
|
+
clearTimeout(timer);
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
execEngineStatus: createPlaneExecFile(),
|
|
1156
1290
|
cleanupTerminalRunPlane: (input) => cleanupTerminalRunPlane(input, createTerminalRunCleanupDeps(process.env)),
|
|
1291
|
+
listLiveRunIds: (access) => createTerminalRunCleanupDeps(process.env).listLiveRunIds(access),
|
|
1157
1292
|
readRunState: async (access, epicRunId) => {
|
|
1158
1293
|
const state = await fetchEpicRunState(access, epicRunId, globalThis.fetch);
|
|
1159
1294
|
const run = state.epic_run;
|
|
@@ -1185,12 +1320,39 @@ export function createDefaultDriveEpicDeps() {
|
|
|
1185
1320
|
}),
|
|
1186
1321
|
discoveryFs: createDefaultPlanDiscoveryFs(),
|
|
1187
1322
|
readPlanDag: (filePath) => readFile(filePath, "utf8"),
|
|
1323
|
+
// BAPI-1621 — the general resolver, never the launch profile: generation runs
|
|
1324
|
+
// before any local plane is up, exactly like `prerequisite-inputs`.
|
|
1325
|
+
attemptPlanGeneration: (epicKey) => attemptPlanGeneration(epicKey, {
|
|
1326
|
+
resolveAccess: () => resolveConductorBridgeApiAccess(),
|
|
1327
|
+
readLiveRun: async (access, key) => (await readLiveEpicRunByKey(access, key)).kind,
|
|
1328
|
+
fetchChildren: (access, key) => fetchEpicChildren(access, key),
|
|
1329
|
+
fetchTicket: async (access, key) => ({ description: await fetchStoredTicketDescription(access, key) }),
|
|
1330
|
+
listTrackedFiles: () => listTrackedFilesWithGit(process.cwd()),
|
|
1331
|
+
validatePlan: (access, request) => validateEpicPlan(access, request),
|
|
1332
|
+
}),
|
|
1333
|
+
publishGeneratedPlan: ({ epicKey, docsDir, dag, summary, access }) => publishGeneratedPlan({
|
|
1334
|
+
epicKey,
|
|
1335
|
+
docsDir,
|
|
1336
|
+
dag,
|
|
1337
|
+
summary,
|
|
1338
|
+
fs: createDefaultPlanPublicationFs(),
|
|
1339
|
+
validate: () => validateGeneratedPlan(access, epicKey, dag, (a, request) => validateEpicPlan(a, request)),
|
|
1340
|
+
rediscover: () => discoverEpicPlan(epicKey, docsDir, createDefaultPlanDiscoveryFs()),
|
|
1341
|
+
}),
|
|
1188
1342
|
readPolicyFile: (filePath) => readFile(filePath, "utf8"),
|
|
1189
1343
|
readLiveEpicRun: (access, epicKey) => readLiveEpicRunByKey(access, epicKey),
|
|
1190
|
-
previewSetupEpic: async ({ argv, baseUrl, handoff, observations }) => {
|
|
1344
|
+
previewSetupEpic: async ({ argv, baseUrl, handoff, observations, planContents }) => {
|
|
1191
1345
|
const stdout = [];
|
|
1192
1346
|
const stderr = [];
|
|
1193
1347
|
const result = await runSetupEpicWorkflow(argv, {
|
|
1348
|
+
...(planContents !== undefined
|
|
1349
|
+
? {
|
|
1350
|
+
readFile: (filePath) => {
|
|
1351
|
+
const inline = planContents.get(filePath);
|
|
1352
|
+
return inline !== undefined ? Promise.resolve(inline) : readFile(filePath, "utf8");
|
|
1353
|
+
},
|
|
1354
|
+
}
|
|
1355
|
+
: {}),
|
|
1194
1356
|
// A COPY carrying the resolved target: the preview never mutates
|
|
1195
1357
|
// `process.env`, so a dry run leaves the process exactly as it found it.
|
|
1196
1358
|
env: { ...process.env, BAPI_BASE_URL: baseUrl },
|
|
@@ -1258,6 +1420,15 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1258
1420
|
}
|
|
1259
1421
|
const { epicKey, planFile, repo, featureBranch, intoBase } = parsed.options;
|
|
1260
1422
|
const launch = launchSelectionOf(parsed.options);
|
|
1423
|
+
// BAPI-1581 — a supplied `--parallel` against an explicit policy file is judged
|
|
1424
|
+
// locally, before any request, readiness probe, setup call, or local service
|
|
1425
|
+
// start. Only the explicit file is read here; a profile or default composition
|
|
1426
|
+
// is judged on the creation routes, where a candidate creation policy exists.
|
|
1427
|
+
const earlyParallelRefusal = await explicitPolicyParallelRefusal(deps, parsed.options);
|
|
1428
|
+
if (earlyParallelRefusal !== null) {
|
|
1429
|
+
deps.errorLog(earlyParallelRefusal);
|
|
1430
|
+
return 1;
|
|
1431
|
+
}
|
|
1261
1432
|
// BAPI-1285 — the read-only preview is its own path from here. It shares the
|
|
1262
1433
|
// classification and refusal builders below and none of the launch code.
|
|
1263
1434
|
if (parsed.options.dryRun === true) {
|
|
@@ -1296,6 +1467,10 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1296
1467
|
targetSource: accessResult.targetSource ?? "default",
|
|
1297
1468
|
freshness: createPlaneFreshnessCache(),
|
|
1298
1469
|
launchCredential: {},
|
|
1470
|
+
launchObservations: [],
|
|
1471
|
+
liveObservation: {},
|
|
1472
|
+
invokedAt: new Date((deps.now ?? Date.now)()).toISOString(),
|
|
1473
|
+
launchReportState: { reported: false },
|
|
1299
1474
|
};
|
|
1300
1475
|
// BAPI-1285 — with no `--plan-file`, look for the plan BEFORE readiness. A
|
|
1301
1476
|
// discovered plan must count as a supplied one for the BAPI-1153 cold-start
|
|
@@ -1310,10 +1485,17 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1310
1485
|
// discovered plan is a convenience, not approved input: it may still be used to
|
|
1311
1486
|
// create a run, but a live run is attached to first and the plan stays unused.
|
|
1312
1487
|
let planWasDiscovered = false;
|
|
1488
|
+
// BAPI-1621 — why automatic generation stopped, for the no-plan stop text.
|
|
1489
|
+
let generationReason;
|
|
1313
1490
|
if (planFile === undefined) {
|
|
1314
1491
|
const docs = await deps.resolveDocsDir();
|
|
1315
1492
|
if (docs.ok) {
|
|
1316
1493
|
discovered = await discoverEpicPlan(epicKey, docs.docsDir, deps.discoveryFs);
|
|
1494
|
+
if (discovered.status === "plan_not_found") {
|
|
1495
|
+
const generated = await generateMissingPlanForLaunch(ctx, docs.docsDir, discovered);
|
|
1496
|
+
discovered = generated.discovery;
|
|
1497
|
+
generationReason = generated.reason;
|
|
1498
|
+
}
|
|
1317
1499
|
if (discovered.status === "found") {
|
|
1318
1500
|
planWasDiscovered = true;
|
|
1319
1501
|
ctx = { ...ctx, options: { ...ctx.options, planFile: discovered.path } };
|
|
@@ -1325,73 +1507,68 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1325
1507
|
}
|
|
1326
1508
|
let foundPlanAnnounced = false;
|
|
1327
1509
|
/** Names the found plan once, BEFORE anything is created, and surfaces its advisory. */
|
|
1328
|
-
const announceFoundPlan = async (
|
|
1510
|
+
const announceFoundPlan = async () => {
|
|
1329
1511
|
if (foundPlanAnnounced || discovered?.status !== "found")
|
|
1330
1512
|
return;
|
|
1331
1513
|
foundPlanAnnounced = true;
|
|
1332
1514
|
deps.log(`${epicKey}: using the plan found by epic key: ${discovered.path}`);
|
|
1333
|
-
if (surfaceAdvisory)
|
|
1334
|
-
await surfaceContainmentAdvisory(deps, discovered.path);
|
|
1335
1515
|
};
|
|
1336
|
-
// ---
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
return escalate(deps, epicKey, `launch profile '${launchProfile.name}' selects durable execution, and its control plane is ` +
|
|
1363
|
-
"not answering; no local replacement was started");
|
|
1364
|
-
}
|
|
1365
|
-
if (endpoint !== null) {
|
|
1366
|
-
const probe = await deps.probePlanePort(endpoint.host, endpoint.port);
|
|
1367
|
-
if (probe.kind === "refused") {
|
|
1368
|
-
// `coldStartPlane` surfaces the containment advisory itself.
|
|
1369
|
-
await announceFoundPlan(false);
|
|
1370
|
-
return await coldStartPlane(ctx);
|
|
1516
|
+
// --- No readiness read at launch (BAPI-1595). -----------------------------
|
|
1517
|
+
// The preview owns readiness acquisition (one attempt plus one retry). A real
|
|
1518
|
+
// launch reads nothing: it reuses the preview's stored snapshot when that
|
|
1519
|
+
// snapshot is bound to THIS launch, and otherwise writes one fixed tally line
|
|
1520
|
+
// and carries on with every evaluator on its unknown (warn) path. The server's
|
|
1521
|
+
// create and approve stay the gate.
|
|
1522
|
+
//
|
|
1523
|
+
// A cold start used to be recognized from a failed readiness read. It is now
|
|
1524
|
+
// recognized from the plane port itself: a refused port IS "no server yet".
|
|
1525
|
+
const planeEndpoint = planeTarget ? planeEndpointForBaseUrl(deps, accessResult.access.baseUrl) : null;
|
|
1526
|
+
const noPlanDiscovery = launchProfile?.executionMode !== "durable" &&
|
|
1527
|
+
discovered !== null &&
|
|
1528
|
+
(discovered.status === "plan_not_found" || discovered.status === "plan_ambiguous")
|
|
1529
|
+
? discovered
|
|
1530
|
+
: null;
|
|
1531
|
+
if (planeEndpoint !== null && (ctx.options.planFile !== undefined || noPlanDiscovery !== null)) {
|
|
1532
|
+
const probe = await deps.probePlanePort(planeEndpoint.host, planeEndpoint.port).catch(() => ({ kind: "error" }));
|
|
1533
|
+
if (probe.kind === "refused") {
|
|
1534
|
+
if (ctx.options.planFile !== undefined) {
|
|
1535
|
+
// BAPI-1260 — only a SELECTED LOCAL plane is ever started here. A
|
|
1536
|
+
// profile approved for durable execution names an authority this
|
|
1537
|
+
// machine does not own, so a refused port is that authority being
|
|
1538
|
+
// down — never permission to launch a local replacement.
|
|
1539
|
+
if (launchProfile !== null && launchProfile.executionMode !== "local") {
|
|
1540
|
+
return escalate(deps, epicKey, `launch profile '${launchProfile.name}' selects durable execution, and its control plane is ` +
|
|
1541
|
+
"not answering; no local replacement was started");
|
|
1371
1542
|
}
|
|
1543
|
+
// `coldStartPlane` surfaces the containment advisory itself.
|
|
1544
|
+
await announceFoundPlan();
|
|
1545
|
+
return await coldStartPlane(ctx);
|
|
1372
1546
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
planeTarget &&
|
|
1380
|
-
err instanceof ConductorBridgeApiError &&
|
|
1381
|
-
err.kind === "network" &&
|
|
1382
|
-
launchProfile?.executionMode !== "durable" &&
|
|
1383
|
-
discovered !== null &&
|
|
1384
|
-
(discovered.status === "plan_not_found" || discovered.status === "plan_ambiguous")) {
|
|
1385
|
-
const endpoint = planeEndpointForBaseUrl(deps, accessResult.access.baseUrl);
|
|
1386
|
-
if (endpoint !== null) {
|
|
1387
|
-
const probe = await deps.probePlanePort(endpoint.host, endpoint.port).catch(() => ({ kind: "error" }));
|
|
1388
|
-
if (probe.kind === "refused") {
|
|
1389
|
-
deps.errorLog(planeDownNoPlanStopText(epicKey, { profile: launchProfile, options: parsed.options }, discovered));
|
|
1390
|
-
return 1;
|
|
1391
|
-
}
|
|
1547
|
+
// The narrow no-plan stop: a local, non-durable plane that refuses
|
|
1548
|
+
// connections, with no usable plan supplied or discovered. This is the
|
|
1549
|
+
// existing stop outcome, not a new refusal. Nothing is started or created.
|
|
1550
|
+
if (noPlanDiscovery !== null) {
|
|
1551
|
+
deps.errorLog(planeDownNoPlanStopText(epicKey, { profile: launchProfile, options: parsed.options }, noPlanDiscovery, generationReason));
|
|
1552
|
+
return 1;
|
|
1392
1553
|
}
|
|
1393
1554
|
}
|
|
1394
|
-
|
|
1555
|
+
}
|
|
1556
|
+
const resolvedSnapshot = await resolveLaunchSnapshot(ctx);
|
|
1557
|
+
ctx = {
|
|
1558
|
+
...ctx,
|
|
1559
|
+
launchSnapshot: resolvedSnapshot.snapshot,
|
|
1560
|
+
...(resolvedSnapshot.previewRepository !== undefined
|
|
1561
|
+
? { previewRepository: resolvedSnapshot.previewRepository }
|
|
1562
|
+
: {}),
|
|
1563
|
+
};
|
|
1564
|
+
const readiness = launchFullReadiness();
|
|
1565
|
+
// BAPI-1595 — a launch from a VERIFIED non-Bridge checkout runs none of the
|
|
1566
|
+
// Bridge-only checks, so no repository-root, build-entrypoint, plane database
|
|
1567
|
+
// head, or worker-database finding exists to render. Each skip is written to the
|
|
1568
|
+
// tally exactly once.
|
|
1569
|
+
if (isConfirmedNonBridge(ctx)) {
|
|
1570
|
+
for (const skip of Object.values(BRIDGE_ONLY_SKIPS))
|
|
1571
|
+
tallyBridgeOnlySkip(ctx, skip);
|
|
1395
1572
|
}
|
|
1396
1573
|
// BAPI-1532 — an EXPLICIT plan selects its setup now. A discovered plan does
|
|
1397
1574
|
// not: plan selection, approval, and the create-time escalation-channel checks
|
|
@@ -1408,15 +1585,9 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1408
1585
|
ctx = { ...ctx, handoff: prepared.handoff };
|
|
1409
1586
|
}
|
|
1410
1587
|
// --- Route. Exactly one path from here on. -------------------------------
|
|
1411
|
-
|
|
1412
|
-
//
|
|
1413
|
-
|
|
1414
|
-
// other resolvable location). Fail-open: any failure here — missing
|
|
1415
|
-
// artifact, bad JSON, malformed/inconsistent shape, an unsafe rendered
|
|
1416
|
-
// value — silently yields no advisory and never affects routing, the
|
|
1417
|
-
// delegated argv, or the exit code.
|
|
1418
|
-
if (planFile)
|
|
1419
|
-
await surfaceContainmentAdvisory(deps, planFile);
|
|
1588
|
+
// BAPI-1593 — an unknown report selects the one engine there is (v2) and
|
|
1589
|
+
// takes the green route below; nothing here is decided from it.
|
|
1590
|
+
const selection = readiness === null ? READINESS_UNKNOWN_SELECTION : selectConductor(readiness);
|
|
1420
1591
|
// BAPI-1285 — no `--plan-file`: find the plan from the epic key, and read the
|
|
1421
1592
|
// epic's live run. Readiness has already been resolved (unknown escalated
|
|
1422
1593
|
// above), so nothing here can be a discovery-driven create on unknown.
|
|
@@ -1428,13 +1599,15 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1428
1599
|
if (docsRootUnresolved || discovered === null) {
|
|
1429
1600
|
return refuse(deps, docsRootRefusal(epicKey).lines);
|
|
1430
1601
|
}
|
|
1431
|
-
|
|
1432
|
-
//
|
|
1433
|
-
|
|
1602
|
+
// BAPI-1595 — the launch's ONE pre-mutation live-run observation (one retry on
|
|
1603
|
+
// unknown), shared by every pre-create consumer below.
|
|
1604
|
+
const live = await acquireObservedLive(ctx);
|
|
1605
|
+
// Wedged (the server's typed `ACTIVE_EPIC_RUN_EXISTS`): never a create and
|
|
1606
|
+
// never an attach, whatever discovery found. An UNKNOWN read is not that: it
|
|
1607
|
+
// warned in the tally, and the server's idempotent create returns the existing
|
|
1608
|
+
// run if there is one, so it continues as "no run seen".
|
|
1434
1609
|
if (live.kind === "conflict")
|
|
1435
1610
|
return refuse(deps, liveRunAmbiguousRefusal(epicKey).lines);
|
|
1436
|
-
if (live.kind === "unknown")
|
|
1437
|
-
return refuse(deps, liveRunUnknownRefusal(epicKey, live.reason).lines);
|
|
1438
1611
|
if (discovered.status === "found") {
|
|
1439
1612
|
if (live.kind === "live") {
|
|
1440
1613
|
// BAPI-1532 — attach FIRST. The discovered plan is dropped from the
|
|
@@ -1478,11 +1651,13 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1478
1651
|
// reads: whatever a `--policy-file` says stays opaque here, exactly as it
|
|
1479
1652
|
// always has. Its mere PRESENCE defers the escalation-channel requirement
|
|
1480
1653
|
// to `setup-epic`, which composes the policy and can actually read it.
|
|
1481
|
-
const classification =
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1654
|
+
const classification = readiness === null
|
|
1655
|
+
? classifySnapshotDiagnostics(ctx)
|
|
1656
|
+
: classifyV2Readiness(readiness, {
|
|
1657
|
+
attended: parsed.options.attended === true,
|
|
1658
|
+
intoBase: parsed.options.intoBase === true,
|
|
1659
|
+
effectivePolicy: ctx.handoff?.selection,
|
|
1660
|
+
});
|
|
1486
1661
|
// Green: create the run, then make sure something will claim its jobs
|
|
1487
1662
|
// (BAPI-1279). Before this, green delegated to setup-epic and nothing
|
|
1488
1663
|
// else, so a production launch — or any second run — created a run no
|
|
@@ -1506,8 +1681,11 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1506
1681
|
const probe = endpoint
|
|
1507
1682
|
? await deps.probePlanePort(endpoint.host, endpoint.port).catch(() => ({ kind: "error" }))
|
|
1508
1683
|
: null;
|
|
1509
|
-
|
|
1684
|
+
// BAPI-1593 — a fresh plane is a fresh server, so the stopped plane's
|
|
1685
|
+
// answer (and any stored snapshot of it) is never reused for it.
|
|
1686
|
+
if (probe?.kind === "refused") {
|
|
1510
1687
|
return await coldStartPlane(ctx);
|
|
1688
|
+
}
|
|
1511
1689
|
}
|
|
1512
1690
|
const attachable = await findAttachablePlane(ctx);
|
|
1513
1691
|
if (attachable !== null) {
|
|
@@ -1534,7 +1712,7 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1534
1712
|
"",
|
|
1535
1713
|
"This is not something starting the runtime can fix, so nothing was started.",
|
|
1536
1714
|
// The requirement's OWN remedy when it has one. Telling an operator to
|
|
1537
|
-
// run `install-
|
|
1715
|
+
// run `install epic-implementer` for a missing consent flag sends them
|
|
1538
1716
|
// to a command that cannot set it.
|
|
1539
1717
|
operatorBlockedRemedy(classification),
|
|
1540
1718
|
].join("\n");
|
|
@@ -1545,12 +1723,14 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1545
1723
|
deps.errorLog(refusal);
|
|
1546
1724
|
return 1;
|
|
1547
1725
|
}
|
|
1726
|
+
// Only a READABLE report reaches here: an unknown one took the green route.
|
|
1727
|
+
const report = readiness;
|
|
1548
1728
|
// BAPI-1279 — runtime-only against a target that is NOT this machine's
|
|
1549
1729
|
// plane: starting anything here could not help, because the missing
|
|
1550
1730
|
// reconciler belongs to that deployment. One named reason, and nothing
|
|
1551
1731
|
// local is touched.
|
|
1552
1732
|
if (!planeTarget) {
|
|
1553
|
-
return refuseRemoteRuntime(ctx,
|
|
1733
|
+
return refuseRemoteRuntime(ctx, report);
|
|
1554
1734
|
}
|
|
1555
1735
|
// Runtime-only: this invocation composes bring-up with run creation.
|
|
1556
1736
|
const repoRoot = deps.cwd();
|
|
@@ -1592,7 +1772,7 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1592
1772
|
return 1;
|
|
1593
1773
|
}
|
|
1594
1774
|
if (attachManifest !== null) {
|
|
1595
|
-
return await attachToPlane(ctx, attachManifest,
|
|
1775
|
+
return await attachToPlane(ctx, attachManifest, report);
|
|
1596
1776
|
}
|
|
1597
1777
|
// ---- PHASE ONE: the control plane, and NOTHING that claims jobs --------
|
|
1598
1778
|
//
|
|
@@ -1610,7 +1790,13 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1610
1790
|
deps.log(`${epicKey}: the Epic Implementer runtime is not live; starting its control plane before creating the run.`);
|
|
1611
1791
|
// The SAME preflight result is handed to the launch, so the port that was
|
|
1612
1792
|
// probed is the port that gets launched and the two cannot disagree.
|
|
1613
|
-
const
|
|
1793
|
+
const parallelCreationRefusal = await parallelCreationCandidateRefusal(ctx);
|
|
1794
|
+
if (parallelCreationRefusal !== null) {
|
|
1795
|
+
deps.errorLog(`${epicKey}: ${parallelCreationRefusal}\nNothing was started.`);
|
|
1796
|
+
return 1;
|
|
1797
|
+
}
|
|
1798
|
+
const startedLanes = parallelLimitToExecutorLanes(ctx.options.parallel ?? DEFAULT_RUN_PARALLEL_LIMIT);
|
|
1799
|
+
const controlPlane = await deps.launchControlPlane({ preflight, executors: startedLanes });
|
|
1614
1800
|
if (!controlPlane.ok) {
|
|
1615
1801
|
// The launch already reported why, in its own words, and it rolls its own
|
|
1616
1802
|
// startup back. No run was created here.
|
|
@@ -1638,7 +1824,8 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1638
1824
|
repoRoot,
|
|
1639
1825
|
planeId: controlPlane.planeId,
|
|
1640
1826
|
awaitPlaneReady: controlPlane.awaitPlaneReady,
|
|
1641
|
-
|
|
1827
|
+
laneCount: startedLanes,
|
|
1828
|
+
}, report);
|
|
1642
1829
|
}
|
|
1643
1830
|
// No plan file, and readiness is not green: v2 is not ready and there is no
|
|
1644
1831
|
// second conductor to offer. Report it as a not-ready refusal on stderr with
|
|
@@ -1648,7 +1835,7 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1648
1835
|
`${epicKey}: ${selection.reason}.`,
|
|
1649
1836
|
"",
|
|
1650
1837
|
"The v2 engine is not ready to drive this epic, and there is no alternative",
|
|
1651
|
-
"engine to fall back to. Resolve Epic Implementer readiness (`install
|
|
1838
|
+
"engine to fall back to. Resolve Epic Implementer readiness (`install epic-implementer`,",
|
|
1652
1839
|
"then `doctor`) and run drive-epic again.",
|
|
1653
1840
|
`See ${CONSUMER_GUIDE_POINTER}.`,
|
|
1654
1841
|
].join("\n");
|
|
@@ -1658,7 +1845,7 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1658
1845
|
}
|
|
1659
1846
|
// BAPI-1285 — reached only after discovery came back empty or ambiguous and no
|
|
1660
1847
|
// live run exists. Nothing was created, so this is a stop, not a success.
|
|
1661
|
-
const handoff = renderConductorHandoff(selection, epicKey, { profile: launchProfile, options: parsed.options }, discoveryStop);
|
|
1848
|
+
const handoff = renderConductorHandoff(selection, epicKey, { profile: launchProfile, options: parsed.options }, discoveryStop, "default", generationReason);
|
|
1662
1849
|
const text = handoff.lines.join("\n");
|
|
1663
1850
|
assertSingleConductorInvocation(text);
|
|
1664
1851
|
deps.errorLog(text);
|
|
@@ -1672,28 +1859,6 @@ export async function runDriveEpicCli(argv, overrides = {}) {
|
|
|
1672
1859
|
return 1;
|
|
1673
1860
|
}
|
|
1674
1861
|
}
|
|
1675
|
-
/**
|
|
1676
|
-
* BAPI-1022: surface any containment-hazard advisory before dispatch or handoff.
|
|
1677
|
-
*
|
|
1678
|
-
* Read only when a plan file was supplied (the sidecar has no other resolvable
|
|
1679
|
-
* location). Fail-open: any failure — missing artifact, bad JSON,
|
|
1680
|
-
* malformed/inconsistent shape, an unsafe rendered value — silently yields no
|
|
1681
|
-
* advisory and never affects routing, the delegated argv, or the exit code.
|
|
1682
|
-
* One helper, so the cold-start path (BAPI-1153) cannot drift from the rest.
|
|
1683
|
-
*/
|
|
1684
|
-
async function surfaceContainmentAdvisory(deps, planFile) {
|
|
1685
|
-
try {
|
|
1686
|
-
const advisory = await readContainmentEligibilityAdvisory(planFile, deps.readEligibilityArtifact);
|
|
1687
|
-
if (advisory) {
|
|
1688
|
-
const rendered = renderContainmentEligibilityAdvisory(advisory);
|
|
1689
|
-
if (rendered)
|
|
1690
|
-
deps.log(rendered);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
catch {
|
|
1694
|
-
// Fail open — a containment advisory is never allowed to block dispatch.
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
1862
|
/**
|
|
1698
1863
|
* BAPI-1285 — the one remedy sentence an unknown-readiness escalation ends with.
|
|
1699
1864
|
* A constant so the preview's `readiness.remedy` is the very line the real
|
|
@@ -1713,34 +1878,421 @@ function operatorBlockedRemedy(classification) {
|
|
|
1713
1878
|
return `${remedy} See ${CONSUMER_GUIDE_POINTER}.`;
|
|
1714
1879
|
}
|
|
1715
1880
|
/**
|
|
1716
|
-
* The
|
|
1717
|
-
*
|
|
1718
|
-
*
|
|
1881
|
+
* The stop for a launch that cannot reach its target: no usable credential, or a
|
|
1882
|
+
* durable profile's control plane that does not answer. Both are needs only a
|
|
1883
|
+
* person can meet. Prints NO conductor invocation.
|
|
1884
|
+
*
|
|
1885
|
+
* BAPI-1593 — an unknown readiness read no longer comes here: it warns and
|
|
1886
|
+
* continues to the server's create and approve. There is one engine
|
|
1887
|
+
* (`DRIVE_EPIC_CONDUCTORS = ["v2"]`), so there is no "wrong engine" to start.
|
|
1719
1888
|
*/
|
|
1720
1889
|
function escalate(deps, epicKey, reason) {
|
|
1721
|
-
const lines = [
|
|
1722
|
-
`Cannot determine which engine owns ${epicKey}: ${reason}`,
|
|
1723
|
-
"",
|
|
1724
|
-
"This is not a not-ready result — it is an unknown one, and starting the wrong",
|
|
1725
|
-
"engine on an epic wedges it permanently.",
|
|
1726
|
-
ESCALATE_REMEDY,
|
|
1727
|
-
];
|
|
1890
|
+
const lines = [`Cannot start ${epicKey}: ${reason}`, "", ESCALATE_REMEDY];
|
|
1728
1891
|
const text = lines.join("\n");
|
|
1729
1892
|
assertSingleConductorInvocation(text);
|
|
1730
1893
|
deps.errorLog(text);
|
|
1731
1894
|
return 1;
|
|
1732
1895
|
}
|
|
1896
|
+
/** The prefix of the default launch-report line. */
|
|
1897
|
+
export const LAUNCH_REPORT_PREFIX = "Launch report: ";
|
|
1898
|
+
/** How long drive-epic watches a planning run for activation after an uncertain approve. */
|
|
1899
|
+
export const ACTIVATION_ATTACH_WINDOW_MS = 10 * 60_000;
|
|
1900
|
+
/** The pause between activation reads, capped to the time left. */
|
|
1901
|
+
export const ACTIVATION_POLL_INTERVAL_MS = 15_000;
|
|
1902
|
+
/** The warning printed when the attach window ends with the run still waiting. */
|
|
1903
|
+
export const APPROVAL_NOT_CONFIRMED_WARNING = "approval not confirmed: the run is still waiting for approval";
|
|
1904
|
+
/** The selection an unknown report takes: the one engine there is. */
|
|
1905
|
+
const READINESS_UNKNOWN_SELECTION = {
|
|
1906
|
+
kind: "selected",
|
|
1907
|
+
conductor: DRIVE_EPIC_PREFERRED_CONDUCTOR,
|
|
1908
|
+
reason: "readiness is unknown",
|
|
1909
|
+
};
|
|
1910
|
+
const defaultLaunchSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1911
|
+
function launchNowIso(ctx) {
|
|
1912
|
+
return new Date((ctx.deps.now ?? Date.now)()).toISOString();
|
|
1913
|
+
}
|
|
1914
|
+
/** BAPI-1621 — the tally reason code for a published generated plan. */
|
|
1915
|
+
export const PLAN_GENERATED_REASON_CODE = "plan_generated";
|
|
1916
|
+
/**
|
|
1917
|
+
* BAPI-1621 — the real launch's generation step, run only after discovery
|
|
1918
|
+
* returned `plan_not_found` with no `--plan-file`.
|
|
1919
|
+
*
|
|
1920
|
+
* It rebuilds from current stored ticket data (never the preview's copy),
|
|
1921
|
+
* publishes by one folder rename, and runs discovery again so the published plan
|
|
1922
|
+
* continues through the ordinary found-plan path. A live run, an ineligible
|
|
1923
|
+
* discovery, or any failure returns the original `plan_not_found` (with a fixed
|
|
1924
|
+
* reason when one applies), so today's attach and stop behavior is unchanged. A
|
|
1925
|
+
* successful rename ends generation's ownership: nothing later removes the folder.
|
|
1926
|
+
*/
|
|
1927
|
+
async function generateMissingPlanForLaunch(ctx, docsDir, discovery) {
|
|
1928
|
+
const { deps, epicKey } = ctx;
|
|
1929
|
+
if (deps.attemptPlanGeneration === undefined || deps.publishGeneratedPlan === undefined)
|
|
1930
|
+
return { discovery };
|
|
1931
|
+
if (!(await planGenerationAllowed(deps.discoveryFs, epicKey, discovery))) {
|
|
1932
|
+
return { discovery, reason: "discovery_blocked" };
|
|
1933
|
+
}
|
|
1934
|
+
deps.log(`${epicKey}: no plan found; checking epic children and building a deterministic plan…`);
|
|
1935
|
+
let attempt;
|
|
1936
|
+
try {
|
|
1937
|
+
attempt = await deps.attemptPlanGeneration(epicKey);
|
|
1938
|
+
}
|
|
1939
|
+
catch {
|
|
1940
|
+
return { discovery, reason: "children_unreadable" };
|
|
1941
|
+
}
|
|
1942
|
+
if (attempt.kind === "not_attempted")
|
|
1943
|
+
return { discovery };
|
|
1944
|
+
if (attempt.kind === "failed")
|
|
1945
|
+
return { discovery, reason: attempt.reason };
|
|
1946
|
+
if (!(await planGenerationAllowed(deps.discoveryFs, epicKey, discovery, attempt))) {
|
|
1947
|
+
return { discovery, reason: "discovery_blocked" };
|
|
1948
|
+
}
|
|
1949
|
+
let published;
|
|
1950
|
+
try {
|
|
1951
|
+
published = await deps.publishGeneratedPlan({
|
|
1952
|
+
epicKey,
|
|
1953
|
+
docsDir,
|
|
1954
|
+
dag: attempt.dag,
|
|
1955
|
+
summary: attempt.summary,
|
|
1956
|
+
access: attempt.access,
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
catch {
|
|
1960
|
+
return { discovery, reason: "publish_failed" };
|
|
1961
|
+
}
|
|
1962
|
+
if (published.kind === "failed")
|
|
1963
|
+
return { discovery, reason: published.reason };
|
|
1964
|
+
if (published.kind === "collision")
|
|
1965
|
+
return { discovery: published.discovery };
|
|
1966
|
+
const relative = path.relative(docsDir, published.dagPath).split(path.sep).join("/");
|
|
1967
|
+
observeLaunch(ctx, PLAN_GENERATED_REASON_CODE, `plan: generated ${relative}`);
|
|
1968
|
+
deps.log(`${epicKey}: plan: generated ${published.dagPath}`);
|
|
1969
|
+
const after = await discoverEpicPlan(epicKey, docsDir, deps.discoveryFs);
|
|
1970
|
+
return after.status === "plan_not_found" ? { discovery: after, reason: "publish_failed" } : { discovery: after };
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Whether discovery's skipped entries allow generation. A DAG with no metadata
|
|
1974
|
+
* blocks only when it names the epic or one of its children, or can't be read.
|
|
1975
|
+
* Before the attempt only the epic key is known; after a generated attempt, every
|
|
1976
|
+
* child it accounts for (its nodes and the spikes it left out) is checked too.
|
|
1977
|
+
*/
|
|
1978
|
+
async function planGenerationAllowed(fs, epicKey, discovery, attempt) {
|
|
1979
|
+
const related = [epicKey];
|
|
1980
|
+
if (attempt !== undefined) {
|
|
1981
|
+
related.push(...attempt.dag.nodes.map((node) => node.ticket_key));
|
|
1982
|
+
related.push(...attempt.summary.excluded.map((entry) => entry.ticket_key));
|
|
1983
|
+
}
|
|
1984
|
+
return isPlanGenerationEligible(discovery, await unrelatedMissingMetaPaths(discovery, related, fs));
|
|
1985
|
+
}
|
|
1986
|
+
/** Record one bookkeeping observation for the launch report. */
|
|
1987
|
+
function observeLaunch(ctx, code, message) {
|
|
1988
|
+
ctx.launchObservations?.push({ code, message, at: launchNowIso(ctx) });
|
|
1989
|
+
}
|
|
1990
|
+
// ---------------------------------------------------------------------------
|
|
1991
|
+
// BAPI-1595 — fixed tally lines and stable reason codes
|
|
1992
|
+
// ---------------------------------------------------------------------------
|
|
1993
|
+
// Each constant sits beside the function that writes it, and a test imports it
|
|
1994
|
+
// rather than retyping the text. None carries a path, a credential, an email
|
|
1995
|
+
// address, a payload, or exception text.
|
|
1996
|
+
/** The launch could not reuse the preview's stored snapshot, so it asked nothing and went on. */
|
|
1997
|
+
export const SNAPSHOT_EXPIRED_WARNING = "readiness snapshot expired; server create and approve decide";
|
|
1998
|
+
export const SNAPSHOT_EXPIRED_REASON_CODE = "readiness_snapshot_expired";
|
|
1999
|
+
/** The pause before the one retry of the pre-mutation live-run read. */
|
|
2000
|
+
export const LIVE_RUN_RETRY_BACKOFF_MS = 1_500;
|
|
2001
|
+
export const LIVE_RUN_RETRY_REASON_CODE = "live_run_read_retried";
|
|
2002
|
+
export const LIVE_RUN_RETRY_MESSAGE = "live run read uncertain; retrying once";
|
|
2003
|
+
/** The live-run read stayed unknown after its retry: the idempotent create decides. */
|
|
2004
|
+
export const LIVE_RUN_UNKNOWN_WARNING = "live run: unknown, continuing; create is idempotent";
|
|
2005
|
+
export const LIVE_RUN_UNKNOWN_REASON_CODE = "live_run_unknown_continued";
|
|
2006
|
+
/** A mandatory diagnostic whose verdict or classification was not established. */
|
|
2007
|
+
export const MANDATORY_DIAGNOSTIC_UNKNOWN_WARNING = "mandatory diagnostic: unknown, continuing; server create and approve decide";
|
|
2008
|
+
export const MANDATORY_DIAGNOSTIC_UNKNOWN_REASON_CODE = "mandatory_diagnostic_unknown_continued";
|
|
2009
|
+
/** The escalation channel evidence was not established, so no "no channel" claim is made. */
|
|
2010
|
+
export const ESCALATION_CHANNEL_UNCERTAIN_WARNING = "escalation channel: unconfirmed, continuing; server create and approve decide";
|
|
2011
|
+
export const ESCALATION_CHANNEL_UNCERTAIN_REASON_CODE = "escalation_channel_unconfirmed_continued";
|
|
2012
|
+
/** Written once whenever the reachability line is left out of the output. */
|
|
2013
|
+
export const ESCALATION_LINE_SUPPRESSED_LINE = "escalation reachability line omitted: a no-channel condition is not established";
|
|
2014
|
+
export const ESCALATION_LINE_SUPPRESSED_REASON_CODE = "escalation_reachability_line_suppressed";
|
|
2015
|
+
/** One Bridge-only check skipped on a verified non-Bridge checkout. */
|
|
2016
|
+
export const BRIDGE_ONLY_SKIPS = {
|
|
2017
|
+
repositoryRoot: {
|
|
2018
|
+
id: "repository-root",
|
|
2019
|
+
reasonCode: "bridge_only_check_skipped_repository_root",
|
|
2020
|
+
line: "repository root check skipped: not a Bridge checkout",
|
|
2021
|
+
},
|
|
2022
|
+
executorBuild: {
|
|
2023
|
+
id: "executor-build",
|
|
2024
|
+
reasonCode: "bridge_only_check_skipped_executor_build",
|
|
2025
|
+
line: "build entrypoint check skipped: not a Bridge checkout",
|
|
2026
|
+
},
|
|
2027
|
+
planeDatabaseHead: {
|
|
2028
|
+
id: "plane-database-head",
|
|
2029
|
+
reasonCode: "bridge_only_check_skipped_plane_database_head",
|
|
2030
|
+
line: "plane database head check skipped: not a Bridge checkout",
|
|
2031
|
+
},
|
|
2032
|
+
workerDatabase: {
|
|
2033
|
+
id: "worker-database",
|
|
2034
|
+
reasonCode: "bridge_only_check_skipped_worker_database",
|
|
2035
|
+
line: "worker database check skipped: not a Bridge checkout",
|
|
2036
|
+
},
|
|
2037
|
+
};
|
|
2038
|
+
/** Write one tally observation and its warning line, once per (code, message) per launch. */
|
|
2039
|
+
function tallyOnce(ctx, code, message, printed = true) {
|
|
2040
|
+
const seen = ctx.launchObservations?.some((entry) => entry.code === code && entry.message === message);
|
|
2041
|
+
if (seen === true)
|
|
2042
|
+
return;
|
|
2043
|
+
if (printed)
|
|
2044
|
+
ctx.deps.errorLog(`${ctx.epicKey}: [warn] ${message}`);
|
|
2045
|
+
observeLaunch(ctx, code, message);
|
|
2046
|
+
}
|
|
2047
|
+
/** Record that a Bridge-only check was skipped, exactly once per launch. */
|
|
2048
|
+
function tallyBridgeOnlySkip(ctx, skip) {
|
|
2049
|
+
// Informational, not a warning: it goes to the launch report's observations, not the terminal.
|
|
2050
|
+
tallyOnce(ctx, skip.reasonCode, skip.line, false);
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Whether the launch may skip Bridge-only checks: only a verified, carried
|
|
2054
|
+
* `isBridge === false`. An absent identity, a Bridge, and a partial checkout all
|
|
2055
|
+
* keep the checks.
|
|
2056
|
+
*/
|
|
2057
|
+
function isConfirmedNonBridge(ctx) {
|
|
2058
|
+
return ctx.previewRepository?.isBridge === false;
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* The full readiness report a real launch holds: none. The preview acquires it and
|
|
2062
|
+
* the launch reads only the narrow, validated snapshot. A function rather than a
|
|
2063
|
+
* literal so the paths that still accept a report keep their signature and TypeScript
|
|
2064
|
+
* does not narrow the null away.
|
|
2065
|
+
*/
|
|
2066
|
+
function launchFullReadiness() {
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* BAPI-1595 — the mandatory-diagnostic decision for a launch that holds only the
|
|
2071
|
+
* preview's snapshot. A diagnostic recorded as `failed` was explicitly mandatory and
|
|
2072
|
+
* applicable when it was projected, so it keeps today's refusal. One recorded as
|
|
2073
|
+
* `unknown` (an unknown verdict, or severity / applicability not established)
|
|
2074
|
+
* warns under a stable reason code and the launch continues. No readiness read is
|
|
2075
|
+
* ever made here.
|
|
2076
|
+
*/
|
|
2077
|
+
function classifySnapshotDiagnostics(ctx) {
|
|
2078
|
+
const readiness = ctx.launchSnapshot?.context.readiness;
|
|
2079
|
+
if (readiness === undefined || readiness.state !== "known")
|
|
2080
|
+
return { kind: "green" };
|
|
2081
|
+
const diagnostics = readiness.value.mandatory_diagnostics;
|
|
2082
|
+
if (diagnostics.some((entry) => entry.verdict === "failed")) {
|
|
2083
|
+
return {
|
|
2084
|
+
kind: "operator_blocked",
|
|
2085
|
+
id: MANDATORY_DIAGNOSTIC_FAILED_ID,
|
|
2086
|
+
describe: "Additional readiness diagnostics",
|
|
2087
|
+
remedy: MANDATORY_DIAGNOSTIC_FAILED_REMEDY,
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
if (diagnostics.some((entry) => entry.verdict === "unknown")) {
|
|
2091
|
+
tallyOnce(ctx, MANDATORY_DIAGNOSTIC_UNKNOWN_REASON_CODE, MANDATORY_DIAGNOSTIC_UNKNOWN_WARNING);
|
|
2092
|
+
}
|
|
2093
|
+
return { kind: "green" };
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Resolve the preview's stored snapshot for THIS launch (BAPI-1595). Never throws,
|
|
2097
|
+
* never reads the readiness report, and never refuses.
|
|
2098
|
+
*
|
|
2099
|
+
* The identity is recomputed locally here only to BIND the snapshot; the preview's
|
|
2100
|
+
* verified classification (carried in the snapshot) stays the applicability
|
|
2101
|
+
* authority. An unavailable or mismatched local identity makes the snapshot
|
|
2102
|
+
* unusable, and an unusable snapshot is never read as "not a Bridge checkout".
|
|
2103
|
+
*/
|
|
2104
|
+
async function resolveLaunchSnapshot(ctx) {
|
|
2105
|
+
const { deps } = ctx;
|
|
2106
|
+
let local = null;
|
|
2107
|
+
try {
|
|
2108
|
+
local = await deps.inspectRepositoryIdentity();
|
|
2109
|
+
}
|
|
2110
|
+
catch {
|
|
2111
|
+
local = null;
|
|
2112
|
+
}
|
|
2113
|
+
let baseBranch = null;
|
|
2114
|
+
try {
|
|
2115
|
+
baseBranch = (await deps.readScopeBaseBranch?.(ctx.access)) ?? null;
|
|
2116
|
+
}
|
|
2117
|
+
catch {
|
|
2118
|
+
baseBranch = null;
|
|
2119
|
+
}
|
|
2120
|
+
const binding = {
|
|
2121
|
+
epicKey: ctx.epicKey,
|
|
2122
|
+
baseBranch,
|
|
2123
|
+
targetBaseUrl: ctx.access.baseUrl,
|
|
2124
|
+
repository: local !== null ? { repoName: ctx.access.repoName, isBridge: local.isBridge } : null,
|
|
2125
|
+
now: new Date((deps.now ?? Date.now)()),
|
|
2126
|
+
};
|
|
2127
|
+
let result;
|
|
2128
|
+
try {
|
|
2129
|
+
result = await (deps.readLaunchContext ?? ((b) => readEpicLaunchContext(b)))(binding);
|
|
2130
|
+
}
|
|
2131
|
+
catch {
|
|
2132
|
+
result = { kind: "unusable", reason: "unreadable" };
|
|
2133
|
+
}
|
|
2134
|
+
if (result.kind === "usable" && local !== null) {
|
|
2135
|
+
return { snapshot: result.value, previewRepository: local };
|
|
2136
|
+
}
|
|
2137
|
+
tallyOnce(ctx, SNAPSHOT_EXPIRED_REASON_CODE, SNAPSHOT_EXPIRED_WARNING);
|
|
2138
|
+
return { snapshot: null };
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* The launch's ONE pre-mutation live-run observation (BAPI-1595).
|
|
2142
|
+
*
|
|
2143
|
+
* Read once; an `unknown` answer spends ONE retry (its own budget, separate from
|
|
2144
|
+
* readiness), and a second `unknown` warns and continues — a create is idempotent
|
|
2145
|
+
* (`POST /runs` returns the existing run) and the unique index allows one active
|
|
2146
|
+
* run per epic. The result is memoized on the launch's shared holder, so every
|
|
2147
|
+
* pre-create consumer reads the same value instead of asking again. This is
|
|
2148
|
+
* never evidence of what a later create or approve committed; post-mutation
|
|
2149
|
+
* reconciliation reads for itself.
|
|
2150
|
+
*/
|
|
2151
|
+
async function acquireObservedLive(ctx) {
|
|
2152
|
+
const holder = ctx.liveObservation;
|
|
2153
|
+
if (holder?.pending !== undefined)
|
|
2154
|
+
return holder.pending;
|
|
2155
|
+
const acquire = async () => {
|
|
2156
|
+
let live = await ctx.deps.readLiveEpicRun(ctx.access, ctx.epicKey);
|
|
2157
|
+
if (live.kind !== "unknown")
|
|
2158
|
+
return live;
|
|
2159
|
+
observeLaunch(ctx, LIVE_RUN_RETRY_REASON_CODE, LIVE_RUN_RETRY_MESSAGE);
|
|
2160
|
+
await (ctx.deps.launchSleep ?? defaultLaunchSleep)(LIVE_RUN_RETRY_BACKOFF_MS);
|
|
2161
|
+
live = await ctx.deps.readLiveEpicRun(ctx.access, ctx.epicKey);
|
|
2162
|
+
if (live.kind === "unknown")
|
|
2163
|
+
tallyOnce(ctx, LIVE_RUN_UNKNOWN_REASON_CODE, LIVE_RUN_UNKNOWN_WARNING);
|
|
2164
|
+
return live;
|
|
2165
|
+
};
|
|
2166
|
+
const pending = acquire();
|
|
2167
|
+
if (holder !== undefined)
|
|
2168
|
+
holder.pending = pending;
|
|
2169
|
+
return pending;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Print the launch report once per invocation. Setup's observations follow
|
|
2173
|
+
* drive's own, in order, with exact duplicates dropped.
|
|
2174
|
+
*/
|
|
2175
|
+
function reportLaunchOutcome(ctx, outcome, facts) {
|
|
2176
|
+
const state = ctx.launchReportState;
|
|
2177
|
+
if (state === undefined || state.reported)
|
|
2178
|
+
return;
|
|
2179
|
+
state.reported = true;
|
|
2180
|
+
const at = launchNowIso(ctx);
|
|
2181
|
+
const observations = [];
|
|
2182
|
+
const seen = new Set();
|
|
2183
|
+
for (const entry of [...(ctx.launchObservations ?? []), ...(facts.observations ?? []).map((o) => ({ ...o, at }))]) {
|
|
2184
|
+
const key = `${entry.code}\u0000${entry.message}`;
|
|
2185
|
+
if (seen.has(key))
|
|
2186
|
+
continue;
|
|
2187
|
+
seen.add(key);
|
|
2188
|
+
observations.push(entry);
|
|
2189
|
+
}
|
|
2190
|
+
const report = {
|
|
2191
|
+
launch_outcome: outcome,
|
|
2192
|
+
epic_key: ctx.epicKey,
|
|
2193
|
+
epic_run_id: facts.epicRunId ?? null,
|
|
2194
|
+
run_status: facts.runStatus ?? null,
|
|
2195
|
+
invoked_at: ctx.invokedAt ?? at,
|
|
2196
|
+
first_claimed_job_at: "pending",
|
|
2197
|
+
observations,
|
|
2198
|
+
};
|
|
2199
|
+
ctx.deps.reportLaunch?.(report);
|
|
2200
|
+
}
|
|
2201
|
+
/** A refusal that also settles the launch outcome. */
|
|
2202
|
+
function refuseLaunch(ctx, lines) {
|
|
2203
|
+
reportLaunchOutcome(ctx, "refused", {});
|
|
2204
|
+
return refuse(ctx.deps, lines);
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Watch a planning run for activation after an uncertain approve. Reads only —
|
|
2208
|
+
* it never approves. A failed read keeps the known id and tries again. Bounded
|
|
2209
|
+
* by {@link ACTIVATION_ATTACH_WINDOW_MS}; every pause is capped to the time left.
|
|
2210
|
+
*/
|
|
2211
|
+
async function awaitRunActivation(ctx, epicRunId) {
|
|
2212
|
+
const now = ctx.deps.launchClock ?? (() => performance.now());
|
|
2213
|
+
const sleep = ctx.deps.launchSleep ?? defaultLaunchSleep;
|
|
2214
|
+
const deadline = now() + ACTIVATION_ATTACH_WINDOW_MS;
|
|
2215
|
+
for (;;) {
|
|
2216
|
+
const remaining = deadline - now();
|
|
2217
|
+
if (remaining <= 0)
|
|
2218
|
+
return { kind: "exhausted" };
|
|
2219
|
+
await sleep(Math.min(ACTIVATION_POLL_INTERVAL_MS, remaining));
|
|
2220
|
+
let status;
|
|
2221
|
+
try {
|
|
2222
|
+
status = (await ctx.deps.readRunState(ctx.access, epicRunId)).status;
|
|
2223
|
+
}
|
|
2224
|
+
catch {
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
if (status === "active")
|
|
2228
|
+
return { kind: "active" };
|
|
2229
|
+
if (status !== "planning")
|
|
2230
|
+
return { kind: "changed", status };
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Settle what setup established. `active` continues to the caller's ordinary
|
|
2235
|
+
* lane or executor dispatch. A planning run after an uncertain approve is watched
|
|
2236
|
+
* until it activates (then dispatched the same way) or the window ends. Every
|
|
2237
|
+
* other outcome is reported here and handled: nothing claims jobs for it.
|
|
2238
|
+
*/
|
|
2239
|
+
async function settleSetupLaunch(ctx, setup) {
|
|
2240
|
+
const { deps, epicKey } = ctx;
|
|
2241
|
+
const facts = {
|
|
2242
|
+
...(setup.epicRunId !== undefined ? { epicRunId: setup.epicRunId } : {}),
|
|
2243
|
+
...(setup.runStatus !== undefined ? { runStatus: setup.runStatus } : {}),
|
|
2244
|
+
...(setup.observations !== undefined ? { observations: setup.observations } : {}),
|
|
2245
|
+
};
|
|
2246
|
+
if (setup.exitCode !== 0) {
|
|
2247
|
+
reportLaunchOutcome(ctx, setup.launchOutcome === "terminal" ? "terminal" : "refused", facts);
|
|
2248
|
+
return setup;
|
|
2249
|
+
}
|
|
2250
|
+
if (setup.launchOutcome === "not_confirmed") {
|
|
2251
|
+
reportLaunchOutcome(ctx, "not_confirmed", facts);
|
|
2252
|
+
return { ...setup, launchHandled: true };
|
|
2253
|
+
}
|
|
2254
|
+
if (setup.launchOutcome === "pending_activation" && setup.epicRunId !== undefined) {
|
|
2255
|
+
if (setup.runStatus !== "planning") {
|
|
2256
|
+
deps.log(`${epicKey}: run ${setup.epicRunId} is ${setup.runStatus ?? "not active"}; attached without changing it.`);
|
|
2257
|
+
reportLaunchOutcome(ctx, "pending_activation", facts);
|
|
2258
|
+
return { ...setup, launchHandled: true };
|
|
2259
|
+
}
|
|
2260
|
+
deps.errorLog(`${epicKey}: run ${setup.epicRunId}: ${RUN_WAITING_FOR_APPROVAL_PHRASE}. Watching for activation ` +
|
|
2261
|
+
"for up to 10 minutes; nothing is approved from here.");
|
|
2262
|
+
const activation = await awaitRunActivation(ctx, setup.epicRunId);
|
|
2263
|
+
if (activation.kind === "active") {
|
|
2264
|
+
observeLaunch(ctx, "launch_outcome_reread", "approve re-read: run activated while attached");
|
|
2265
|
+
reportLaunchOutcome(ctx, "active", { ...facts, runStatus: "active" });
|
|
2266
|
+
return { ...setup, launchOutcome: "active", runStatus: "active" };
|
|
2267
|
+
}
|
|
2268
|
+
if (activation.kind === "changed") {
|
|
2269
|
+
const terminal = isTerminalEpicRunStatus(activation.status);
|
|
2270
|
+
deps.log(`${epicKey}: run ${setup.epicRunId} is ${activation.status}; attached without changing it.`);
|
|
2271
|
+
reportLaunchOutcome(ctx, terminal ? "terminal" : "pending_activation", { ...facts, runStatus: activation.status });
|
|
2272
|
+
return { ...setup, exitCode: terminal ? 1 : 0, launchHandled: true };
|
|
2273
|
+
}
|
|
2274
|
+
deps.errorLog(`${epicKey}: [warn] ${APPROVAL_NOT_CONFIRMED_WARNING}. Re-run setup with: ` +
|
|
2275
|
+
launchReconnectCommand(epicKey, ctx.access));
|
|
2276
|
+
reportLaunchOutcome(ctx, "pending_activation", facts);
|
|
2277
|
+
return { ...setup, launchHandled: true };
|
|
2278
|
+
}
|
|
2279
|
+
// Never inferred from exit 0: only a reported `active` status counts.
|
|
2280
|
+
reportLaunchOutcome(ctx, setup.launchOutcome === "active" || setup.runStatus === "active" ? "active" : "pending_activation", facts);
|
|
2281
|
+
return setup;
|
|
2282
|
+
}
|
|
1733
2283
|
/** Resolve policy intent once for the setup delegation, after a fresh run read. */
|
|
1734
2284
|
/** Narrow an effective-policy channel label to the closed identity set. */
|
|
1735
2285
|
function channelIdentityOf(label) {
|
|
1736
2286
|
return label === "configured webhook" || label === "account email" ? label : "unavailable";
|
|
1737
2287
|
}
|
|
1738
2288
|
async function prepareSetupSelection(ctx, coldStart = false, observedLive) {
|
|
1739
|
-
|
|
1740
|
-
|
|
2289
|
+
// BAPI-1595 — one observation per launch, reused here instead of a fresh read. An
|
|
2290
|
+
// unknown one (already retried and warned about) is treated as "no run seen":
|
|
2291
|
+
// `POST /runs` is idempotent, so it returns the existing run if there is one.
|
|
2292
|
+
const observed = coldStart ? { kind: "none" } : observedLive ?? await acquireObservedLive(ctx);
|
|
2293
|
+
if (observed.kind === "conflict")
|
|
1741
2294
|
return { ok: false, reasonId: "live-run-ambiguous" };
|
|
1742
|
-
|
|
1743
|
-
return { ok: false, reasonId: "live-run-unknown" };
|
|
2295
|
+
const live = observed.kind === "unknown" ? { kind: "none" } : observed;
|
|
1744
2296
|
const explicit = ctx.options.policyFile;
|
|
1745
2297
|
const selectedPath = explicit ?? (live.kind === "none" ? ctx.profile?.policyRef?.path : undefined);
|
|
1746
2298
|
let pinnedPolicy;
|
|
@@ -1923,14 +2475,118 @@ async function recordSkippedChildrenBestEffort(ctx, epicRunId, skipped) {
|
|
|
1923
2475
|
deps.errorLog("The run was created, but the skipped-child record could not be saved.");
|
|
1924
2476
|
}
|
|
1925
2477
|
}
|
|
2478
|
+
// ---------------------------------------------------------------------------
|
|
2479
|
+
// BAPI-1581 — parallel limit: local preflight and capacity reporting
|
|
2480
|
+
// ---------------------------------------------------------------------------
|
|
2481
|
+
/**
|
|
2482
|
+
* The refusal for a supplied `--parallel` judged against an EXPLICIT policy
|
|
2483
|
+
* file, or `null`. Read-only and local: it reads the one file the operator named,
|
|
2484
|
+
* and an unreadable file is left to the existing policy-read handling.
|
|
2485
|
+
*/
|
|
2486
|
+
async function explicitPolicyParallelRefusal(deps, options) {
|
|
2487
|
+
if (options.parallel === undefined || options.policyFile === undefined)
|
|
2488
|
+
return null;
|
|
2489
|
+
const read = await readSetupEpicPolicyFile(options.policyFile, (filePath) => deps.readPolicyFile(filePath));
|
|
2490
|
+
if (!read.ok)
|
|
2491
|
+
return null;
|
|
2492
|
+
const verdict = evaluateParallelPolicyPreflight({
|
|
2493
|
+
parallel: options.parallel,
|
|
2494
|
+
attended: options.attended === true,
|
|
2495
|
+
intoBase: options.intoBase === true,
|
|
2496
|
+
filePolicy: read.policy,
|
|
2497
|
+
// BAPI-1595 — the plan is not read yet, so whether create would select an epic
|
|
2498
|
+
// branch (and fill a posture-silent file as unattended) is not known. The
|
|
2499
|
+
// creation routes judge that case with the branch selection in hand.
|
|
2500
|
+
postureFillDeferred: true,
|
|
2501
|
+
});
|
|
2502
|
+
return verdict.ok ? null : verdict.message.replace(/^setup-epic REFUSED/, `${options.epicKey}: REFUSED`);
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* The refusal for a supplied `--parallel` judged against the CANDIDATE creation
|
|
2506
|
+
* policy (pinned file/profile policy, or the default composition for this plan),
|
|
2507
|
+
* or `null`. Called only on routes that are about to start a plane and create a
|
|
2508
|
+
* run, so it never judges an existing run's stored policy.
|
|
2509
|
+
*/
|
|
2510
|
+
async function parallelCreationCandidateRefusal(ctx) {
|
|
2511
|
+
const parallel = ctx.options.parallel;
|
|
2512
|
+
if (parallel === undefined)
|
|
2513
|
+
return null;
|
|
2514
|
+
const planPath = ctx.options.planFile;
|
|
2515
|
+
if (planPath === undefined)
|
|
2516
|
+
return null;
|
|
2517
|
+
const children = await readPlanChildren(ctx.deps, planPath);
|
|
2518
|
+
if (children === null)
|
|
2519
|
+
return null;
|
|
2520
|
+
const pinned = ctx.handoff ? getPinnedEpicLaunchPolicy(ctx.handoff.selection) : undefined;
|
|
2521
|
+
const declaresBranch = pinned !== undefined && resolveDeclaredRunBaseBranch(pinned) !== undefined;
|
|
2522
|
+
const verdict = evaluateParallelPolicyPreflight({
|
|
2523
|
+
parallel,
|
|
2524
|
+
attended: ctx.options.attended === true,
|
|
2525
|
+
intoBase: ctx.options.intoBase === true,
|
|
2526
|
+
...(pinned !== undefined ? { filePolicy: pinned } : {}),
|
|
2527
|
+
featureBranch: resolveFeatureBranchSelection({
|
|
2528
|
+
epicKey: ctx.epicKey,
|
|
2529
|
+
featureBranch: ctx.options.featureBranch,
|
|
2530
|
+
intoBase: ctx.options.intoBase === true,
|
|
2531
|
+
}, children.keys.length, declaresBranch),
|
|
2532
|
+
});
|
|
2533
|
+
return verdict.ok ? null : verdict.message.replace(/^setup-epic REFUSED/, "REFUSED");
|
|
2534
|
+
}
|
|
2535
|
+
/** The durable-profile capacity line: the stored limit, and where concurrency is configured. */
|
|
2536
|
+
function durableCapacityLine(storedLimit) {
|
|
2537
|
+
return (`The run's parallel limit is ${storedLimit}. Concurrency of the durable executor is configured on its ` +
|
|
2538
|
+
"host; this command starts no executor and cannot change it.");
|
|
2539
|
+
}
|
|
2540
|
+
/** Executor lanes an attached plane's manifest records: `executor-N` members only, no liveness filter. */
|
|
2541
|
+
function attachedPlaneLaneCount(manifest) {
|
|
2542
|
+
return manifest.members.filter((member) => isPlaneExecutorLaneMember(member.name)).length;
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Warn, once, when the plane's known lane count is below the run's stored
|
|
2546
|
+
* parallel limit. Never an action: nothing is stopped, parked, refused, or resized.
|
|
2547
|
+
*/
|
|
2548
|
+
function reportPlaneCapacity(ctx, lanes, storedLimit, posture) {
|
|
2549
|
+
if (lanes === undefined || storedLimit === undefined || posture !== "unattended")
|
|
2550
|
+
return;
|
|
2551
|
+
if (lanes >= storedLimit)
|
|
2552
|
+
return;
|
|
2553
|
+
ctx.deps.errorLog(`${ctx.epicKey}: [warn] this plane has ${lanes} executor lane${lanes === 1 ? "" : "s"}, but the run's ` +
|
|
2554
|
+
`parallel limit is ${storedLimit}. Each lane serves one job at a time, so capacity is reduced to ` +
|
|
2555
|
+
`${lanes} job${lanes === 1 ? "" : "s"} at once. Nothing was stopped. To use the full limit, wind the ` +
|
|
2556
|
+
`plane down after the run or between runs, then relaunch with \`--parallel ${storedLimit}\`.`);
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* BAPI-1593 — delegate to setup-epic, then settle what it established before
|
|
2560
|
+
* anything claims jobs. A `launchHandled` result was fully reported here, and
|
|
2561
|
+
* its caller returns its exit code without requesting lanes or an executor.
|
|
2562
|
+
*/
|
|
1926
2563
|
async function runSelectedSetupEpic(ctx) {
|
|
1927
|
-
|
|
2564
|
+
return settleSetupLaunch(ctx, await runSelectedSetupEpicWorkflow(ctx));
|
|
2565
|
+
}
|
|
2566
|
+
async function runSelectedSetupEpicWorkflow(ctx) {
|
|
2567
|
+
const selected = ctx.handoff
|
|
1928
2568
|
? { ok: true, handoff: ctx.handoff }
|
|
1929
2569
|
: await prepareSetupSelection(ctx);
|
|
1930
|
-
if (!
|
|
1931
|
-
ctx.deps.errorLog(`${ctx.epicKey}: REFUSED (${
|
|
2570
|
+
if (!selected.ok) {
|
|
2571
|
+
ctx.deps.errorLog(`${ctx.epicKey}: REFUSED (${selected.reasonId}) — the selected run or policy could not be verified.`);
|
|
1932
2572
|
return { exitCode: 1 };
|
|
1933
2573
|
}
|
|
2574
|
+
// BAPI-1595 — readiness is acquired by the PREVIEW and never by a launch. The
|
|
2575
|
+
// hand-off says so explicitly (an in-process contract, not an argv flag), and
|
|
2576
|
+
// carries the narrow evidence the stored snapshot held, or `null` when none was
|
|
2577
|
+
// usable: setup-epic then reads nothing, every evaluator takes its warn path, and
|
|
2578
|
+
// the server's create and approve decide.
|
|
2579
|
+
const snapshotEvidence = ctx.launchSnapshot !== undefined && ctx.launchSnapshot !== null
|
|
2580
|
+
? readinessSnapshotFromLaunchContext(ctx.launchSnapshot.context)
|
|
2581
|
+
: null;
|
|
2582
|
+
const prepared = {
|
|
2583
|
+
ok: true,
|
|
2584
|
+
handoff: {
|
|
2585
|
+
...selected.handoff,
|
|
2586
|
+
readinessDisposition: "preview_handoff",
|
|
2587
|
+
launchEvidence: snapshotEvidence,
|
|
2588
|
+
},
|
|
2589
|
+
};
|
|
1934
2590
|
const { deps, options, epicKey } = ctx;
|
|
1935
2591
|
// BAPI-1510 — fresh classification immediately before setup. Preview verdicts are
|
|
1936
2592
|
// never consumed: each create starts from the ORIGINAL plan and re-checks.
|
|
@@ -1965,6 +2621,15 @@ async function runSelectedSetupEpic(ctx) {
|
|
|
1965
2621
|
const pr = skippedChildPr(evaluation.state, key);
|
|
1966
2622
|
deps.log(`${epicKey}: ${confirmed ? "skipping (confirmed by you)" : "skipping already-merged child"} ${key}` +
|
|
1967
2623
|
`${pr !== null ? ` (#${pr})` : ""}`);
|
|
2624
|
+
if (!confirmed) {
|
|
2625
|
+
deps.log(`already merged, will skip: ${key}${pr !== null ? ` (#${pr})` : ""}`);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
for (const child of evaluation.state.children) {
|
|
2629
|
+
if (child.classification === "probably_done" && !evaluation.skipKeys.has(child.ticket_key)) {
|
|
2630
|
+
const pr = skippedChildPr(evaluation.state, child.ticket_key);
|
|
2631
|
+
deps.log(`may already be merged; kept: ${child.ticket_key}${pr !== null ? ` (#${pr})` : ""}`);
|
|
2632
|
+
}
|
|
1968
2633
|
}
|
|
1969
2634
|
const trimmed = trimDonePlanNodes(evaluation.plan, evaluation.skipKeys);
|
|
1970
2635
|
const withPath = deps.withPlanPath ?? withPlanPath;
|
|
@@ -2000,7 +2665,14 @@ function isUnattendedLaunch(options) {
|
|
|
2000
2665
|
return options.attended !== true && options.intoBase !== true;
|
|
2001
2666
|
}
|
|
2002
2667
|
/** The launch row ids a launch can be refused on, without their namespace. */
|
|
2003
|
-
|
|
2668
|
+
/**
|
|
2669
|
+
* BAPI-1585 — the two pre-create refusal codes the server added after the
|
|
2670
|
+
* generator's regex was written. The generator is read-only for this ticket, so
|
|
2671
|
+
* they are spelled once in `conductor/launch-plan.ts` (which also renders them)
|
|
2672
|
+
* and pinned against `pre_create_refusal.py` in
|
|
2673
|
+
* `readiness-prerequisites-contract.test.ts`.
|
|
2674
|
+
*/
|
|
2675
|
+
const LAUNCH_REFUSAL_IDS = ["merge-credential-capability", "worktree-preparation", ...Object.values(READINESS_PRE_CREATE_CODES), ...Object.values(LAUNCH_PRE_CREATE_CODES)];
|
|
2004
2676
|
/**
|
|
2005
2677
|
* The credential evidence. Probes ONLY a locally owned executor's credential in
|
|
2006
2678
|
* `local` / `machine_token` mode, against the server's explicit `owner/name`;
|
|
@@ -2099,9 +2771,12 @@ async function launchCredentialForExecutor(ctx, readiness) {
|
|
|
2099
2771
|
if (box !== undefined && box.resolved !== undefined) {
|
|
2100
2772
|
return box.resolved?.kind === "local" ? box.resolved : null;
|
|
2101
2773
|
}
|
|
2102
|
-
|
|
2774
|
+
// BAPI-1595 — the mode and repository come from the full report when one is held,
|
|
2775
|
+
// otherwise from the preview's validated snapshot. No usable source: no credential.
|
|
2776
|
+
const source = readiness ?? credentialFactsOfSnapshot(ctx);
|
|
2777
|
+
if (source === null || source.resolved_merge_execution_mode !== "local")
|
|
2103
2778
|
return null;
|
|
2104
|
-
const repository =
|
|
2779
|
+
const repository = source.provider_repository;
|
|
2105
2780
|
if (typeof repository !== "string" || !isProviderRepositoryIdentity(repository))
|
|
2106
2781
|
return null;
|
|
2107
2782
|
const resolved = await resolveLaunchCredentialOnce(ctx.deps, "local", repository, box);
|
|
@@ -2141,6 +2816,50 @@ async function collectLaunchEvidence(deps, readiness, topology, box) {
|
|
|
2141
2816
|
worktree: await collectWorktreeEvidence(deps, topology),
|
|
2142
2817
|
};
|
|
2143
2818
|
}
|
|
2819
|
+
/**
|
|
2820
|
+
* BAPI-1595 — the two facts the merge-credential probe reads, taken from the
|
|
2821
|
+
* preview's validated snapshot. `null` when no usable snapshot (or no known facts)
|
|
2822
|
+
* is held. Never a rebuilt readiness report: only these two members exist.
|
|
2823
|
+
*/
|
|
2824
|
+
function credentialFactsOfSnapshot(ctx) {
|
|
2825
|
+
const readiness = ctx.launchSnapshot?.context.readiness;
|
|
2826
|
+
if (readiness === undefined || readiness.state !== "known")
|
|
2827
|
+
return null;
|
|
2828
|
+
const mode = readiness.value.resolved_merge_execution_mode;
|
|
2829
|
+
return {
|
|
2830
|
+
resolved_merge_execution_mode: mode === "local" || mode === "machine_token" || mode === "github_actions" ? mode : null,
|
|
2831
|
+
provider_repository: readiness.value.provider_repository,
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* BAPI-1595 — the local launch-evidence gate for a launch that holds the preview's
|
|
2836
|
+
* snapshot but no full readiness report. It keeps the AC-3 local refusals — a merge
|
|
2837
|
+
* credential that is PROVEN missing, invalid, or without access, and a worktree
|
|
2838
|
+
* exclude proven unwritable — and nothing else. With no usable snapshot there is
|
|
2839
|
+
* nothing to probe against, and the server's create and approve decide.
|
|
2840
|
+
*/
|
|
2841
|
+
async function snapshotLaunchEvidenceGate(ctx, topology, outcome) {
|
|
2842
|
+
const facts = credentialFactsOfSnapshot(ctx);
|
|
2843
|
+
if (facts === null)
|
|
2844
|
+
return null;
|
|
2845
|
+
const { deps, epicKey } = ctx;
|
|
2846
|
+
const evidence = {
|
|
2847
|
+
credential: await collectCredentialEvidence(deps, facts, topology, ctx.launchCredential),
|
|
2848
|
+
worktree: await collectWorktreeEvidence(deps, topology),
|
|
2849
|
+
};
|
|
2850
|
+
const blocker = firstLaunchEvidenceBlocker(buildLaunchEvidenceChecks({ attended: false, intoBase: false }, evidence));
|
|
2851
|
+
if (blocker === null)
|
|
2852
|
+
return null;
|
|
2853
|
+
const describe = blocker.id === MERGE_CREDENTIAL_ROW
|
|
2854
|
+
? "a merge credential that has push and can read pull requests"
|
|
2855
|
+
: "an executor clone whose shared git exclude can be prepared";
|
|
2856
|
+
const remedy = `${blocker.detail ?? blocker.label}. ${blocker.remediation} See ${CONSUMER_GUIDE_POINTER}.`;
|
|
2857
|
+
return refuse(deps, [
|
|
2858
|
+
`${epicKey}: REFUSED (${blocker.id.slice(blocker.id.indexOf(".") + 1)}) — the launch still needs ${describe}.`,
|
|
2859
|
+
remedy,
|
|
2860
|
+
outcome,
|
|
2861
|
+
]);
|
|
2862
|
+
}
|
|
2144
2863
|
/**
|
|
2145
2864
|
* The launch capability gate (BAPI-1452). Runs after readiness and executor
|
|
2146
2865
|
* topology are resolved and BEFORE the run is created, dispatched, or given an
|
|
@@ -2154,8 +2873,12 @@ async function launchCapabilityGate(ctx, readiness, topology, outcome = "Nothing
|
|
|
2154
2873
|
const { deps, epicKey, options } = ctx;
|
|
2155
2874
|
if (!isUnattendedLaunch(options))
|
|
2156
2875
|
return null;
|
|
2876
|
+
// BAPI-1593 — no report, no rows: the server's create and approve enforce what
|
|
2877
|
+
// these rows mirror. BAPI-1595 — the local PROVEN refusals (merge credential,
|
|
2878
|
+
// worktree) still run from the preview's snapshot when the launch holds one.
|
|
2879
|
+
if (readiness === null)
|
|
2880
|
+
return await snapshotLaunchEvidenceGate(ctx, topology, outcome);
|
|
2157
2881
|
const evidence = await collectLaunchEvidence(deps, readiness, topology, ctx.launchCredential);
|
|
2158
|
-
(deps.launchReadinessLog ?? deps.errorLog)(formatLaunchReadinessSummary(buildLaunchReadinessChecks(readiness, { launchEvidence: evidence }), { all: ctx.options.all, isProduction: readiness.is_production, prerequisites: readiness.prerequisites }).join("\n"));
|
|
2159
2882
|
const classification = classifyV2Readiness(readiness, { attended: false, intoBase: false, effectivePolicy: ctx.handoff?.selection }, evidence);
|
|
2160
2883
|
if (classification.kind !== "operator_blocked" || !LAUNCH_REFUSAL_IDS.includes(classification.id)) {
|
|
2161
2884
|
return null;
|
|
@@ -2195,6 +2918,8 @@ async function previewLaunchCapability(ctx, readiness, topology) {
|
|
|
2195
2918
|
return { checks, refusal: null };
|
|
2196
2919
|
}
|
|
2197
2920
|
function durableActorAdmissionDenied(readiness) {
|
|
2921
|
+
if (readiness === null)
|
|
2922
|
+
return false;
|
|
2198
2923
|
const evidence = readiness.admission_evidence;
|
|
2199
2924
|
return evidence?.schema_version === 1 &&
|
|
2200
2925
|
evidence.records.some((record) => record.predicate === "durable_actor" && record.verdict === "denied");
|
|
@@ -2232,7 +2957,18 @@ const LAUNCHED_PLANE_LEFT_RUNNING = [
|
|
|
2232
2957
|
* rebuilt from the manifest, sent as a query parameter, and never rendered.
|
|
2233
2958
|
*/
|
|
2234
2959
|
async function checkPlaneAdmission(ctx, readiness, manifest) {
|
|
2235
|
-
|
|
2960
|
+
// BAPI-1593 — an unknown report proves no bring-up fact; the plane's own
|
|
2961
|
+
// reconciler is still confirmed below, from its own read. BAPI-1595 — only a
|
|
2962
|
+
// PROVEN-bad fact refuses (a second reconciler, a database behind head, a missing
|
|
2963
|
+
// worker). The facts come from the full report when one is held, otherwise from
|
|
2964
|
+
// the preview's validated snapshot; unreadable or unreported ones are unknown.
|
|
2965
|
+
const snapshotReadiness = ctx.launchSnapshot?.context.readiness;
|
|
2966
|
+
const bringUpFacts = readiness !== null
|
|
2967
|
+
? (readiness.bring_up ?? null)
|
|
2968
|
+
: snapshotReadiness !== undefined && snapshotReadiness.state === "known"
|
|
2969
|
+
? snapshotReadiness.value.bring_up
|
|
2970
|
+
: null;
|
|
2971
|
+
const bringUpRefusal = firstProvenBringUpRefusal(bringUpFacts);
|
|
2236
2972
|
if (bringUpRefusal !== null) {
|
|
2237
2973
|
return [
|
|
2238
2974
|
`${ctx.epicKey}: REFUSED (${bringUpRefusal}) — ${BRING_UP_REFUSAL_MESSAGES[bringUpRefusal]}`,
|
|
@@ -2360,7 +3096,12 @@ function assessPlaneFreshness(reports, sleep, mode, allowStalePlane,
|
|
|
2360
3096
|
* remedy, which never advises `plane down` for a run that is not finished.
|
|
2361
3097
|
* Absent keeps `PLANE_SNAPSHOT_STALE_REMEDY` byte for byte.
|
|
2362
3098
|
*/
|
|
2363
|
-
boundRun
|
|
3099
|
+
boundRun,
|
|
3100
|
+
/**
|
|
3101
|
+
* A create preview only: the plane server's other live runs (BAPI-1651).
|
|
3102
|
+
* The stale refusal becomes a cleanup warning only when this is `none`.
|
|
3103
|
+
*/
|
|
3104
|
+
cleanupPreview = null) {
|
|
2364
3105
|
const rows = [];
|
|
2365
3106
|
const blockers = [];
|
|
2366
3107
|
let overridden = false;
|
|
@@ -2394,6 +3135,14 @@ boundRun) {
|
|
|
2394
3135
|
remedy: refusal.remedy,
|
|
2395
3136
|
});
|
|
2396
3137
|
}
|
|
3138
|
+
else if (verdict === "refuse" && mode === "create" && !allowStalePlane && cleanupPreview?.kind === "none" &&
|
|
3139
|
+
id === PLANE_SNAPSHOT_FRESHNESS_ID && isTerminalRunCleanupStatus(boundRun?.status)) {
|
|
3140
|
+
rows.push({
|
|
3141
|
+
duration_ms, id, label, status: "warn", blocking: false,
|
|
3142
|
+
detail: `This create will attempt guarded cleanup — ${detail}. Create rechecks ownership and run status before teardown.`,
|
|
3143
|
+
remedy: refusal.remedy,
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
2397
3146
|
else if (verdict === "refuse" && allowStalePlane) {
|
|
2398
3147
|
overridden = true;
|
|
2399
3148
|
rows.push({
|
|
@@ -2422,7 +3171,11 @@ boundRun) {
|
|
|
2422
3171
|
if (reports !== null) {
|
|
2423
3172
|
project(PLANE_SNAPSHOT_FRESHNESS_ID, "Plane snapshot freshness", reports.snapshot, {
|
|
2424
3173
|
reasonId: "plane-snapshot-stale",
|
|
2425
|
-
remedy: boundRun
|
|
3174
|
+
remedy: boundRun === undefined
|
|
3175
|
+
? PLANE_SNAPSHOT_STALE_REMEDY
|
|
3176
|
+
: cleanupPreview !== null && cleanupPreview.kind !== "none" && isTerminalRunCleanupStatus(boundRun.status)
|
|
3177
|
+
? formatSharedPlaneStaleRemedy(boundRun, cleanupPreview.kind === "live" ? cleanupPreview.epicRunId : null)
|
|
3178
|
+
: formatBoundPlaneStaleRemedy(boundRun),
|
|
2426
3179
|
});
|
|
2427
3180
|
project(PLANE_DATABASE_HEAD_ID, "Plane database head", reports.database, {
|
|
2428
3181
|
reasonId: "plane-database-head-mismatch",
|
|
@@ -2492,6 +3245,13 @@ function renderFreshnessRows(rows, heading = 'Plane freshness:') {
|
|
|
2492
3245
|
* it is never proof of staleness and never permission to skip another safeguard.
|
|
2493
3246
|
*/
|
|
2494
3247
|
async function planeFreshnessCreateGuard(ctx, own, trailer = []) {
|
|
3248
|
+
// BAPI-1595 — plane freshness and the plane database head are Bridge-only. A
|
|
3249
|
+
// verified non-Bridge checkout skips both, with its fixed tally line; a Bridge,
|
|
3250
|
+
// a partial checkout, and an unestablished identity keep them.
|
|
3251
|
+
if (isConfirmedNonBridge(ctx)) {
|
|
3252
|
+
tallyBridgeOnlySkip(ctx, BRIDGE_ONLY_SKIPS.planeDatabaseHead);
|
|
3253
|
+
return null;
|
|
3254
|
+
}
|
|
2495
3255
|
try {
|
|
2496
3256
|
const reports = await collectFreshnessObservations(ctx, own);
|
|
2497
3257
|
if (reports === null)
|
|
@@ -2502,9 +3262,7 @@ async function planeFreshnessCreateGuard(ctx, own, trailer = []) {
|
|
|
2502
3262
|
// setup-epic REUSES the epic's live run instead of creating one, and a reuse
|
|
2503
3263
|
// is an attachment: it is warned about, never refused. Asked only when a
|
|
2504
3264
|
// confirmed finding would otherwise block, so the common path reads nothing.
|
|
2505
|
-
const live = await ctx.
|
|
2506
|
-
.readLiveEpicRun(ctx.access, ctx.epicKey)
|
|
2507
|
-
.catch(() => ({ kind: "unknown" }));
|
|
3265
|
+
const live = await acquireObservedLive(ctx).catch(() => ({ kind: "unknown" }));
|
|
2508
3266
|
if (live.kind === "live") {
|
|
2509
3267
|
assessment = assessPlaneFreshness(reports, null, "attach", ctx.options.allowStalePlane === true, boundRun);
|
|
2510
3268
|
}
|
|
@@ -2539,6 +3297,10 @@ async function planeFreshnessCreateGuard(ctx, own, trailer = []) {
|
|
|
2539
3297
|
}
|
|
2540
3298
|
/** The warning-only counterpart for an existing run. Never refuses, never throws. */
|
|
2541
3299
|
async function surfacePlaneFreshnessForExistingRun(ctx, own) {
|
|
3300
|
+
if (isConfirmedNonBridge(ctx)) {
|
|
3301
|
+
tallyBridgeOnlySkip(ctx, BRIDGE_ONLY_SKIPS.planeDatabaseHead);
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
2542
3304
|
try {
|
|
2543
3305
|
const reports = await collectFreshnessObservations(ctx, own);
|
|
2544
3306
|
if (reports === null)
|
|
@@ -2558,19 +3320,60 @@ async function surfacePlaneFreshnessForExistingRun(ctx, own) {
|
|
|
2558
3320
|
// Advisory only.
|
|
2559
3321
|
}
|
|
2560
3322
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
3323
|
+
export const WORKER_DATABASE_UNPROVEN_REASON_CODE = "worker_database_configuration_unproven";
|
|
3324
|
+
export const WORKER_DATABASE_UNPROVEN_LINE = "worker database boundary: not checked (the project's database configuration was not reported)";
|
|
3325
|
+
export const WORKER_DATABASE_FALLBACK_REASON_CODE = "worker_database_configuration_defaulted";
|
|
3326
|
+
export const WORKER_DATABASE_FALLBACK_LINE = "worker database boundary: configuration not reported; checked with Bridge's own database names";
|
|
3327
|
+
export function resolveWorkerDatabaseApplicability(input) {
|
|
3328
|
+
const declared = input.declaration;
|
|
3329
|
+
if (declared !== null && declared !== undefined) {
|
|
3330
|
+
if (declared.mode === "none")
|
|
3331
|
+
return { kind: "skip", reason: "mode_none" };
|
|
3332
|
+
return {
|
|
3333
|
+
kind: "inspect",
|
|
3334
|
+
fallback: false,
|
|
3335
|
+
config: {
|
|
3336
|
+
status: "configured",
|
|
3337
|
+
mode: "disposable_postgres",
|
|
3338
|
+
...(declared.worker_role !== null ? { workerRole: declared.worker_role } : {}),
|
|
3339
|
+
protectedDatabases: [...declared.protected_databases],
|
|
3340
|
+
envNames: [],
|
|
3341
|
+
},
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
if (input.validContext && input.isBridge === true)
|
|
3345
|
+
return { kind: "inspect", config: undefined, fallback: true };
|
|
3346
|
+
return { kind: "unproven" };
|
|
3347
|
+
}
|
|
3348
|
+
/** The applicability for a real launch, from its validated snapshot and verified identity. */
|
|
3349
|
+
function launchWorkerDatabaseApplicability(ctx) {
|
|
3350
|
+
const readiness = ctx.launchSnapshot?.context.readiness;
|
|
3351
|
+
return resolveWorkerDatabaseApplicability({
|
|
3352
|
+
declaration: readiness?.state === "known" ? readiness.value.worker_database : null,
|
|
3353
|
+
validContext: ctx.launchSnapshot !== undefined && ctx.launchSnapshot !== null,
|
|
3354
|
+
isBridge: ctx.previewRepository?.isBridge,
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
/** Copy the typed worker state onto its row so a consumer never reads `detail` prose. */
|
|
3358
|
+
function stampWorkerState(rows, section) {
|
|
3359
|
+
return rows.map((row) => {
|
|
3360
|
+
const source = section.rows.find((entry) => entry.id === row.id);
|
|
3361
|
+
return source !== undefined && (source.state === "unsafe" || source.state === "unknown")
|
|
3362
|
+
? { ...row, worker_state: source.state }
|
|
3363
|
+
: row;
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
2564
3366
|
/**
|
|
2565
3367
|
* Run the worker-database inspection for a local-plane target, once.
|
|
2566
3368
|
*
|
|
2567
3369
|
* `null` when nothing applies: a target that is not this machine's plane never
|
|
2568
3370
|
* runs the inspector, so a remote launch's requests and output are unchanged.
|
|
2569
3371
|
* An inspector that throws or times out prints one fixed line naming only the
|
|
2570
|
-
* closed classification, then yields
|
|
2571
|
-
*
|
|
3372
|
+
* closed classification, then yields a section with NO rows: a launch shows no
|
|
3373
|
+
* advisory row for an inspection it could not make (BAPI-1594), and the
|
|
3374
|
+
* missing role row still resolves the role need to `unverifiable`.
|
|
2572
3375
|
*/
|
|
2573
|
-
async function collectWorkerDatabaseAdvisory(deps, baseUrl, cache) {
|
|
3376
|
+
async function collectWorkerDatabaseAdvisory(deps, baseUrl, cache, config) {
|
|
2574
3377
|
if (baseUrl === null || planeEndpointForBaseUrl(deps, baseUrl) === null)
|
|
2575
3378
|
return null;
|
|
2576
3379
|
const inspect = deps.inspectWorkerDatabase;
|
|
@@ -2578,16 +3381,12 @@ async function collectWorkerDatabaseAdvisory(deps, baseUrl, cache) {
|
|
|
2578
3381
|
return null;
|
|
2579
3382
|
const run = async () => {
|
|
2580
3383
|
let failed = false;
|
|
2581
|
-
const section = await collectWorkerDatabaseDoctorSection(() => inspect(deps.cwd()), WORKER_DATABASE_DOCTOR_TIMEOUT_MS, (failure) => {
|
|
3384
|
+
const section = await collectWorkerDatabaseDoctorSection(() => inspect(deps.cwd(), config), WORKER_DATABASE_DOCTOR_TIMEOUT_MS, (failure) => {
|
|
2582
3385
|
failed = true;
|
|
2583
3386
|
deps.errorLog(`worker-db inspection failed: ${failure}`);
|
|
2584
3387
|
}).catch(() => null);
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
// rows. The doctor's own all-unknown section is left as it is.
|
|
2588
|
-
if (section !== null && failed) {
|
|
2589
|
-
return { ...section, rows: section.rows.filter((row) => row.id === "worker-db-unverifiable") };
|
|
2590
|
-
}
|
|
3388
|
+
if (section !== null && failed)
|
|
3389
|
+
return { ...section, rows: [] };
|
|
2591
3390
|
return section;
|
|
2592
3391
|
};
|
|
2593
3392
|
if (cache === undefined)
|
|
@@ -2595,9 +3394,9 @@ async function collectWorkerDatabaseAdvisory(deps, baseUrl, cache) {
|
|
|
2595
3394
|
cache.workerDatabase ??= run();
|
|
2596
3395
|
return cache.workerDatabase;
|
|
2597
3396
|
}
|
|
2598
|
-
/** The advisory rows for a local launch: non-healthy `worker-db
|
|
2599
|
-
async function workerDatabaseAdvisoryRows(deps, baseUrl, cache) {
|
|
2600
|
-
const section = await collectWorkerDatabaseAdvisory(deps, baseUrl, cache);
|
|
3397
|
+
/** The advisory rows for a local launch: non-healthy `worker-db-role` and `worker-db-boundary` warnings only. */
|
|
3398
|
+
async function workerDatabaseAdvisoryRows(deps, baseUrl, cache, config) {
|
|
3399
|
+
const section = await collectWorkerDatabaseAdvisory(deps, baseUrl, cache, config);
|
|
2601
3400
|
return section === null ? [] : previewLaunchRows(workerDatabaseReadinessChecks(section));
|
|
2602
3401
|
}
|
|
2603
3402
|
/**
|
|
@@ -2608,8 +3407,24 @@ async function workerDatabaseAdvisoryRows(deps, baseUrl, cache) {
|
|
|
2608
3407
|
* an unexpected failure prints nothing.
|
|
2609
3408
|
*/
|
|
2610
3409
|
async function surfaceWorkerDatabaseAdvisory(ctx) {
|
|
3410
|
+
// BAPI-1596 — the configured mode decides, not the checkout's identity. A verified
|
|
3411
|
+
// non-Bridge checkout that declares no database skips with its one fixed tally line;
|
|
3412
|
+
// a configuration that was not reported is tallied and never inspected.
|
|
3413
|
+
const applicability = launchWorkerDatabaseApplicability(ctx);
|
|
3414
|
+
if (applicability.kind === "skip") {
|
|
3415
|
+
if (isConfirmedNonBridge(ctx))
|
|
3416
|
+
tallyBridgeOnlySkip(ctx, BRIDGE_ONLY_SKIPS.workerDatabase);
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
if (applicability.kind === "unproven") {
|
|
3420
|
+
tallyOnce(ctx, WORKER_DATABASE_UNPROVEN_REASON_CODE, WORKER_DATABASE_UNPROVEN_LINE, false);
|
|
3421
|
+
return;
|
|
3422
|
+
}
|
|
3423
|
+
if (applicability.fallback) {
|
|
3424
|
+
tallyOnce(ctx, WORKER_DATABASE_FALLBACK_REASON_CODE, WORKER_DATABASE_FALLBACK_LINE, false);
|
|
3425
|
+
}
|
|
2611
3426
|
try {
|
|
2612
|
-
const rows = await workerDatabaseAdvisoryRows(ctx.deps, ctx.access.baseUrl, ctx.freshness);
|
|
3427
|
+
const rows = await workerDatabaseAdvisoryRows(ctx.deps, ctx.access.baseUrl, ctx.freshness, applicability.config);
|
|
2613
3428
|
if (rows.length === 0)
|
|
2614
3429
|
return;
|
|
2615
3430
|
const log = ctx.deps.launchReadinessLog ?? ctx.deps.errorLog;
|
|
@@ -2629,11 +3444,21 @@ async function surfaceWorkerDatabaseAdvisory(ctx) {
|
|
|
2629
3444
|
* inspector and its JSON is unchanged. Never changes the decision, a refusal,
|
|
2630
3445
|
* readiness, or the exit code.
|
|
2631
3446
|
*/
|
|
2632
|
-
async function appendWorkerDatabaseAdvisoryRows(deps, preview, repository) {
|
|
2633
|
-
|
|
2634
|
-
|
|
3447
|
+
async function appendWorkerDatabaseAdvisoryRows(deps, preview, repository, applicability) {
|
|
3448
|
+
// BAPI-1596 — gated on the configured mode, not on checkout identity. A verified
|
|
3449
|
+
// non-Bridge checkout keeps its two fixed `not_bridge_repository` skip rows.
|
|
3450
|
+
if (applicability.kind !== "inspect") {
|
|
3451
|
+
if (repository?.isBridge === false) {
|
|
3452
|
+
preview.launch_checks = [...(preview.launch_checks ?? []), ...nonBridgeRows(WORKER_DATABASE_PREVIEW_IDS)];
|
|
3453
|
+
}
|
|
3454
|
+
if (applicability.kind === "unproven") {
|
|
3455
|
+
(preview.tally_lines ??= []).push({ code: WORKER_DATABASE_UNPROVEN_REASON_CODE, line: WORKER_DATABASE_UNPROVEN_LINE });
|
|
3456
|
+
}
|
|
2635
3457
|
return null;
|
|
2636
3458
|
}
|
|
3459
|
+
if (applicability.fallback) {
|
|
3460
|
+
(preview.tally_lines ??= []).push({ code: WORKER_DATABASE_FALLBACK_REASON_CODE, line: WORKER_DATABASE_FALLBACK_LINE });
|
|
3461
|
+
}
|
|
2637
3462
|
if (repository === undefined)
|
|
2638
3463
|
return null;
|
|
2639
3464
|
if (preview.target.kind !== "local_plane")
|
|
@@ -2641,8 +3466,8 @@ async function appendWorkerDatabaseAdvisoryRows(deps, preview, repository) {
|
|
|
2641
3466
|
try {
|
|
2642
3467
|
// BAPI-1506: the section is returned so the launch-need step reuses this one
|
|
2643
3468
|
// inspection instead of running a second.
|
|
2644
|
-
const section = await collectWorkerDatabaseAdvisory(deps, preview.target.base_url);
|
|
2645
|
-
const rows = section === null ? [] : previewLaunchRows(workerDatabaseReadinessChecks(section));
|
|
3469
|
+
const section = await collectWorkerDatabaseAdvisory(deps, preview.target.base_url, undefined, applicability.config);
|
|
3470
|
+
const rows = section === null ? [] : stampWorkerState(previewLaunchRows(workerDatabaseReadinessChecks(section)), section);
|
|
2646
3471
|
if (rows.length > 0)
|
|
2647
3472
|
preview.launch_checks = [...(preview.launch_checks ?? []), ...rows];
|
|
2648
3473
|
return section;
|
|
@@ -2718,11 +3543,6 @@ async function coldStartPlane(ctx) {
|
|
|
2718
3543
|
]);
|
|
2719
3544
|
}
|
|
2720
3545
|
}
|
|
2721
|
-
// The cold start leaves the readiness `catch` before the ordinary advisory
|
|
2722
|
-
// read is reached, so it surfaces the BAPI-1022 containment advisory itself —
|
|
2723
|
-
// before anything is started, exactly as every other plan-file route does.
|
|
2724
|
-
if (ctx.options.planFile)
|
|
2725
|
-
await surfaceContainmentAdvisory(deps, ctx.options.planFile);
|
|
2726
3546
|
deps.log(`${epicKey}: nothing is listening on the plane endpoint; cold-starting the local plane.`);
|
|
2727
3547
|
const repoRoot = deps.cwd();
|
|
2728
3548
|
// BAPI-1496: a plane bound to a finished run is torn down before preflight.
|
|
@@ -2737,28 +3557,23 @@ async function coldStartPlane(ctx) {
|
|
|
2737
3557
|
"Nothing was started. Fix the item above and run drive-epic again.",
|
|
2738
3558
|
]);
|
|
2739
3559
|
}
|
|
2740
|
-
const
|
|
3560
|
+
const parallelColdRefusal = await parallelCreationCandidateRefusal(ctx);
|
|
3561
|
+
if (parallelColdRefusal !== null) {
|
|
3562
|
+
deps.errorLog(`${epicKey}: ${parallelColdRefusal}\nNothing was started.`);
|
|
3563
|
+
return 1;
|
|
3564
|
+
}
|
|
3565
|
+
const coldLanes = parallelLimitToExecutorLanes(ctx.options.parallel ?? DEFAULT_RUN_PARALLEL_LIMIT);
|
|
3566
|
+
const controlPlane = await deps.launchControlPlane({ preflight, executors: coldLanes });
|
|
2741
3567
|
if (!controlPlane.ok) {
|
|
2742
3568
|
return reportControlPlaneLaunchFailure(ctx, controlPlane);
|
|
2743
3569
|
}
|
|
2744
3570
|
void controlPlane.lifetime.catch(() => undefined);
|
|
2745
|
-
//
|
|
2746
|
-
//
|
|
2747
|
-
//
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
}
|
|
2752
|
-
catch (err) {
|
|
2753
|
-
if (isSchemaIncompatibleError(err)) {
|
|
2754
|
-
return refuse(deps, [...formatSchemaIncompatibleRefusal(epicKey, err), ...LAUNCHED_PLANE_LEFT_RUNNING]);
|
|
2755
|
-
}
|
|
2756
|
-
return refuse(deps, [
|
|
2757
|
-
`${epicKey}: the plane came up, but its Epic Implementer readiness could not be read: ` +
|
|
2758
|
-
safeDiagnosticMessage(err, "readiness request failed"),
|
|
2759
|
-
...LAUNCHED_PLANE_LEFT_RUNNING,
|
|
2760
|
-
]);
|
|
2761
|
-
}
|
|
3571
|
+
// BAPI-1595 — a launch reads no readiness report, a cold start included. This
|
|
3572
|
+
// plane is a fresh server, so no stored snapshot describes it: say so once and
|
|
3573
|
+
// carry on with every evaluator on its unknown (warn) path. The server's create
|
|
3574
|
+
// and approve decide; the plane's own reconciler is still confirmed below.
|
|
3575
|
+
tallyOnce(ctx, SNAPSHOT_EXPIRED_REASON_CODE, SNAPSHOT_EXPIRED_WARNING);
|
|
3576
|
+
const readiness = launchFullReadiness();
|
|
2762
3577
|
const prepared = await prepareSetupSelection(ctx);
|
|
2763
3578
|
if (!prepared.ok) {
|
|
2764
3579
|
return refuse(deps, [
|
|
@@ -2767,11 +3582,13 @@ async function coldStartPlane(ctx) {
|
|
|
2767
3582
|
]);
|
|
2768
3583
|
}
|
|
2769
3584
|
ctx = { ...ctx, handoff: prepared.handoff };
|
|
2770
|
-
const classification =
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
3585
|
+
const classification = readiness === null
|
|
3586
|
+
? classifySnapshotDiagnostics(ctx)
|
|
3587
|
+
: classifyV2Readiness(readiness, {
|
|
3588
|
+
attended: ctx.options.attended === true,
|
|
3589
|
+
intoBase: ctx.options.intoBase === true,
|
|
3590
|
+
effectivePolicy: ctx.handoff?.selection,
|
|
3591
|
+
});
|
|
2775
3592
|
if (classification.kind === "operator_blocked") {
|
|
2776
3593
|
return refuse(deps, [
|
|
2777
3594
|
`${epicKey}: the engine path still needs ${classification.describe}.`,
|
|
@@ -2801,6 +3618,7 @@ async function coldStartPlane(ctx) {
|
|
|
2801
3618
|
repoRoot,
|
|
2802
3619
|
planeId: controlPlane.planeId,
|
|
2803
3620
|
awaitPlaneReady: controlPlane.awaitPlaneReady,
|
|
3621
|
+
laneCount: coldLanes,
|
|
2804
3622
|
}, readiness);
|
|
2805
3623
|
}
|
|
2806
3624
|
/**
|
|
@@ -2883,6 +3701,7 @@ async function attachToPlane(ctx, manifest, readiness) {
|
|
|
2883
3701
|
repoRoot: manifest.repoRoot,
|
|
2884
3702
|
planeId: manifest.planeId,
|
|
2885
3703
|
...(manifest.epicRunId !== undefined ? { boundRunId: manifest.epicRunId } : {}),
|
|
3704
|
+
laneCount: attachedPlaneLaneCount(manifest),
|
|
2886
3705
|
}, readiness);
|
|
2887
3706
|
}
|
|
2888
3707
|
/**
|
|
@@ -2899,13 +3718,15 @@ async function createRunAndRequestLanes(ctx, plane, readiness) {
|
|
|
2899
3718
|
const launched = plane.origin === "launched";
|
|
2900
3719
|
// BAPI-1452: a plane lane owns this run's executor, so the launch evidence
|
|
2901
3720
|
// can only warn here; printed before the run exists.
|
|
2902
|
-
if (readiness !== undefined) {
|
|
3721
|
+
if (readiness !== undefined && readiness !== null) {
|
|
2903
3722
|
const gate = await launchCapabilityGate(ctx, readiness, { kind: "plane_lane" });
|
|
2904
3723
|
if (gate !== null)
|
|
2905
3724
|
return gate;
|
|
2906
3725
|
}
|
|
2907
3726
|
// ---- PHASE TWO, part one: create the run ------------------------------
|
|
2908
3727
|
const setup = await runSelectedSetupEpic(ctx);
|
|
3728
|
+
if (setup.launchHandled === true)
|
|
3729
|
+
return setup.exitCode;
|
|
2909
3730
|
if (setup.exitCode !== 0) {
|
|
2910
3731
|
// The control plane is deliberately LEFT RUNNING, and NO EXECUTOR LANE
|
|
2911
3732
|
// was spawned — there is nothing to claim a job that may not exist.
|
|
@@ -2974,6 +3795,7 @@ async function createRunAndRequestLanes(ctx, plane, readiness) {
|
|
|
2974
3795
|
].join("\n"));
|
|
2975
3796
|
return 1;
|
|
2976
3797
|
}
|
|
3798
|
+
reportPlaneCapacity(ctx, plane.laneCount, setup.parallelLimit, setup.runPosture);
|
|
2977
3799
|
if (plane.awaitPlaneReady === undefined) {
|
|
2978
3800
|
// Attached: the plane's own detached runtime performs the spawn and the
|
|
2979
3801
|
// per-lane readiness gating, and this process may exit first. Its progress
|
|
@@ -3105,7 +3927,7 @@ function remoteRuntimeRefusal(epicKey, access, readiness) {
|
|
|
3105
3927
|
function durableCoverageRefusal(epicKey, access, profile, coverage, outcome) {
|
|
3106
3928
|
const remedy = [
|
|
3107
3929
|
"Start the durable host's executor with --repo-wide",
|
|
3108
|
-
" (`install
|
|
3930
|
+
" (`install epic-implementer --execution-mode durable --executor-id <id> --repo-wide`; see `drive-epic --help-advanced`),",
|
|
3109
3931
|
"or launch without the durable profile.",
|
|
3110
3932
|
].join("\n");
|
|
3111
3933
|
return {
|
|
@@ -3124,6 +3946,22 @@ function durableCoverageRefusal(epicKey, access, profile, coverage, outcome) {
|
|
|
3124
3946
|
],
|
|
3125
3947
|
};
|
|
3126
3948
|
}
|
|
3949
|
+
/**
|
|
3950
|
+
* BAPI-1595 — the durable-host coverage a launch may refuse on. The launch holds the
|
|
3951
|
+
* preview's snapshot rather than a report, so coverage refuses only when the snapshot
|
|
3952
|
+
* PROVES it absent (`false`); an unreported or unreadable value is unknown and the
|
|
3953
|
+
* server's create decides. A full report, when one is held, keeps its strict reading.
|
|
3954
|
+
*/
|
|
3955
|
+
function durableCoverageOf(ctx, readiness) {
|
|
3956
|
+
if (readiness !== null)
|
|
3957
|
+
return readiness.executor.repo_wide_executor_live;
|
|
3958
|
+
const snapshotReadiness = ctx.launchSnapshot?.context.readiness;
|
|
3959
|
+
return snapshotReadiness !== undefined &&
|
|
3960
|
+
snapshotReadiness.state === "known" &&
|
|
3961
|
+
snapshotReadiness.value.repo_wide_executor_live === false
|
|
3962
|
+
? false
|
|
3963
|
+
: true;
|
|
3964
|
+
}
|
|
3127
3965
|
/** The pre-create refusal when no executor could ever be started from this checkout. */
|
|
3128
3966
|
function executorPreconditionRefusal(epicKey, message, outcome) {
|
|
3129
3967
|
return {
|
|
@@ -3165,21 +4003,6 @@ function liveRunAmbiguousRefusal(epicKey) {
|
|
|
3165
4003
|
],
|
|
3166
4004
|
};
|
|
3167
4005
|
}
|
|
3168
|
-
/** BAPI-1285 — the epic's run state could not be read, so nothing may be assumed. */
|
|
3169
|
-
function liveRunUnknownRefusal(epicKey, reason) {
|
|
3170
|
-
const remedy = "Restore Bridge API access, then run drive-epic again. Creating a run without knowing " +
|
|
3171
|
-
"whether one exists could mint a duplicate, which wedges the epic permanently.";
|
|
3172
|
-
return {
|
|
3173
|
-
reasonId: "live-run-unknown",
|
|
3174
|
-
remedy,
|
|
3175
|
-
lines: [
|
|
3176
|
-
`${epicKey}: REFUSED (live-run-unknown) — the epic's run state could not be read (${reason}).`,
|
|
3177
|
-
remedy,
|
|
3178
|
-
"",
|
|
3179
|
-
"Nothing was created and nothing was started.",
|
|
3180
|
-
],
|
|
3181
|
-
};
|
|
3182
|
-
}
|
|
3183
4006
|
/**
|
|
3184
4007
|
* Create the run, then make sure an executor will claim its jobs — the path for
|
|
3185
4008
|
* every launch that does not request a plane lane.
|
|
@@ -3202,7 +4025,8 @@ async function createRunWithRunExecutor(ctx, readiness) {
|
|
|
3202
4025
|
"No run was created and no local executor was started.",
|
|
3203
4026
|
]);
|
|
3204
4027
|
}
|
|
3205
|
-
|
|
4028
|
+
// BAPI-1593 — unknown readiness: the server's create and approve decide.
|
|
4029
|
+
const coverage = durableCoverageOf(ctx, readiness);
|
|
3206
4030
|
if (coverage !== true) {
|
|
3207
4031
|
return refuse(deps, durableCoverageRefusal(epicKey, access, profile, coverage, "No run was created").lines);
|
|
3208
4032
|
}
|
|
@@ -3212,11 +4036,16 @@ async function createRunWithRunExecutor(ctx, readiness) {
|
|
|
3212
4036
|
if (gate !== null)
|
|
3213
4037
|
return gate;
|
|
3214
4038
|
const setup = await runSelectedSetupEpic(ctx);
|
|
4039
|
+
if (setup.launchHandled === true)
|
|
4040
|
+
return setup.exitCode;
|
|
3215
4041
|
if (setup.exitCode === 0) {
|
|
3216
4042
|
deps.log([
|
|
3217
4043
|
"",
|
|
3218
4044
|
`${epicKey}: run ${setup.epicRunId ?? "(id not reported)"} created on ${access.baseUrl}.`,
|
|
3219
4045
|
"The durable host's repo-wide executor claims its jobs; no local executor was started.",
|
|
4046
|
+
...(setup.parallelLimit !== undefined && setup.runPosture === "unattended"
|
|
4047
|
+
? [durableCapacityLine(setup.parallelLimit)]
|
|
4048
|
+
: []),
|
|
3220
4049
|
].join("\n"));
|
|
3221
4050
|
}
|
|
3222
4051
|
return setup.exitCode;
|
|
@@ -3232,6 +4061,8 @@ async function createRunWithRunExecutor(ctx, readiness) {
|
|
|
3232
4061
|
if (gate !== null)
|
|
3233
4062
|
return gate;
|
|
3234
4063
|
const setup = await runSelectedSetupEpic(ctx);
|
|
4064
|
+
if (setup.launchHandled === true)
|
|
4065
|
+
return setup.exitCode;
|
|
3235
4066
|
if (setup.exitCode !== 0) {
|
|
3236
4067
|
// setup-epic already said why. Nothing was started for a run that may not exist.
|
|
3237
4068
|
deps.errorLog(`\n${epicKey}: no executor was started.`);
|
|
@@ -3257,6 +4088,10 @@ async function createRunWithRunExecutor(ctx, readiness) {
|
|
|
3257
4088
|
access,
|
|
3258
4089
|
profile,
|
|
3259
4090
|
mergeCredential: await launchCredentialForExecutor(ctx, readiness),
|
|
4091
|
+
// BAPI-1581 — the SERVER-stored limit, and only for a stored unattended run.
|
|
4092
|
+
...(setup.runPosture === "unattended" && setup.parallelLimit !== undefined
|
|
4093
|
+
? { maxConcurrent: setup.parallelLimit }
|
|
4094
|
+
: {}),
|
|
3260
4095
|
});
|
|
3261
4096
|
return reportExecutorOutcome(ctx, ensured, setup.epicRunId, "created");
|
|
3262
4097
|
}
|
|
@@ -3305,6 +4140,10 @@ function reportExecutorOutcome(ctx, ensured, epicRunId, framing) {
|
|
|
3305
4140
|
? `${epicKey}: run ${epicRunId} is created on ${access.baseUrl}.`
|
|
3306
4141
|
: `${epicKey}: run ${epicRunId} is already live on ${access.baseUrl}; nothing was created.`,
|
|
3307
4142
|
started,
|
|
4143
|
+
...(ensured.maxConcurrent !== undefined && ensured.maxConcurrent > 1
|
|
4144
|
+
? [`It serves ${ensured.maxConcurrent} jobs at a time.`]
|
|
4145
|
+
: []),
|
|
4146
|
+
...(ensured.capacityNotice !== undefined ? [ensured.capacityNotice] : []),
|
|
3308
4147
|
"It claims only this run's jobs, and exits on its own once the run is done or abandoned.",
|
|
3309
4148
|
` Log: ${ensured.logPath}`,
|
|
3310
4149
|
` Record: ${ensured.recordPath}`,
|
|
@@ -3349,11 +4188,14 @@ async function planeServesLiveRun(ctx, live) {
|
|
|
3349
4188
|
*/
|
|
3350
4189
|
async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
3351
4190
|
const { deps, epicKey, access, profile } = ctx;
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
4191
|
+
// BAPI-1593 — an unknown report proves nothing to refuse on: attach.
|
|
4192
|
+
const classification = readiness === null
|
|
4193
|
+
? { kind: "green" }
|
|
4194
|
+
: classifyV2Readiness(readiness, {
|
|
4195
|
+
attended: ctx.options.attended === true,
|
|
4196
|
+
intoBase: ctx.options.intoBase === true,
|
|
4197
|
+
approvedStoredPolicy: true,
|
|
4198
|
+
});
|
|
3357
4199
|
if (classification.kind === "operator_blocked") {
|
|
3358
4200
|
return refuse(deps, [
|
|
3359
4201
|
`${epicKey}: the engine path still needs ${classification.describe}.`,
|
|
@@ -3363,11 +4205,15 @@ async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
|
3363
4205
|
]);
|
|
3364
4206
|
}
|
|
3365
4207
|
const planeTarget = planeEndpointForBaseUrl(deps, access.baseUrl) !== null;
|
|
3366
|
-
if (classification.kind === "runtime_only") {
|
|
4208
|
+
if (classification.kind === "runtime_only" && readiness !== null) {
|
|
3367
4209
|
if (!planeTarget)
|
|
3368
4210
|
return refuseRemoteRuntime(ctx, readiness);
|
|
3369
4211
|
return refuse(deps, localReconcilerRefusal(epicKey, readiness).lines);
|
|
3370
4212
|
}
|
|
4213
|
+
reportLaunchOutcome(ctx, live.status === "active" ? "active" : "pending_activation", {
|
|
4214
|
+
epicRunId: live.epicRunId,
|
|
4215
|
+
runStatus: live.status,
|
|
4216
|
+
});
|
|
3371
4217
|
if (planeTarget) {
|
|
3372
4218
|
const manifest = await findAttachablePlane(ctx).catch(() => null);
|
|
3373
4219
|
if (manifest?.epicRunId === live.epicRunId) {
|
|
@@ -3391,8 +4237,15 @@ async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
|
3391
4237
|
"found, so nothing will be created; making sure it has an executor."
|
|
3392
4238
|
: `${epicKey}: run ${live.epicRunId} is already live (${live.status}); the plan found by epic key ` +
|
|
3393
4239
|
`(${unusedDiscoveredPlan}) is not used, so nothing will be created; making sure it has an executor.`);
|
|
4240
|
+
// BAPI-1581 — the limit and posture that GOVERN this run come from its stored
|
|
4241
|
+
// policy; launch flags never decide them. A missing stored policy reads as no
|
|
4242
|
+
// known limit and adds no executor concurrency.
|
|
4243
|
+
const storedParallel = live.effectivePolicy !== undefined && typeof live.effectivePolicy.parallel_limit === "number"
|
|
4244
|
+
? live.effectivePolicy.parallel_limit
|
|
4245
|
+
: undefined;
|
|
4246
|
+
const storedUnattended = live.effectivePolicy?.posture === "unattended";
|
|
3394
4247
|
if (live.effectivePolicy) {
|
|
3395
|
-
deps.log(`Effective policy: stored;
|
|
4248
|
+
deps.log(`Effective policy: stored; parallel limit ${live.effectivePolicy.parallel_limit}; caps ${live.effectivePolicy.caps ? JSON.stringify(live.effectivePolicy.caps) : "unavailable"}; ` +
|
|
3396
4249
|
`timeouts ${live.effectivePolicy.job_timeouts ? JSON.stringify(live.effectivePolicy.job_timeouts) : "unavailable"}; ` +
|
|
3397
4250
|
`channel ${live.effectivePolicy.escalation_channel}.`);
|
|
3398
4251
|
}
|
|
@@ -3403,7 +4256,9 @@ async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
|
3403
4256
|
"No run was changed and no local executor was started.",
|
|
3404
4257
|
]);
|
|
3405
4258
|
}
|
|
3406
|
-
|
|
4259
|
+
// BAPI-1593 — unknown readiness says nothing about coverage; the warning
|
|
4260
|
+
// already printed, and the run is left as it is.
|
|
4261
|
+
const coverage = durableCoverageOf(ctx, readiness);
|
|
3407
4262
|
if (coverage !== true) {
|
|
3408
4263
|
return refuse(deps, durableCoverageRefusal(epicKey, access, profile, coverage, "No run was changed").lines);
|
|
3409
4264
|
}
|
|
@@ -3411,15 +4266,32 @@ async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
|
3411
4266
|
"",
|
|
3412
4267
|
`${epicKey}: run ${live.epicRunId} is served by the durable host's confirmed repo-wide executor.`,
|
|
3413
4268
|
"No local executor was started.",
|
|
4269
|
+
...(storedParallel !== undefined && storedUnattended ? [durableCapacityLine(storedParallel)] : []),
|
|
3414
4270
|
].join("\n"));
|
|
3415
4271
|
return 0;
|
|
3416
4272
|
}
|
|
4273
|
+
// BAPI-1581 — one informational notice, never a refusal or a policy change.
|
|
4274
|
+
if (ctx.options.parallel !== undefined) {
|
|
4275
|
+
if (!storedUnattended) {
|
|
4276
|
+
deps.log(`${epicKey}: --parallel ${ctx.options.parallel} was not applied: run ${live.epicRunId} is not ` +
|
|
4277
|
+
"unattended, and the limit applies only to unattended runs. Nothing was changed.");
|
|
4278
|
+
}
|
|
4279
|
+
else if (storedParallel !== undefined) {
|
|
4280
|
+
const retained = retainedParallelLimitNotice(ctx.options.parallel, storedParallel);
|
|
4281
|
+
if (retained !== null)
|
|
4282
|
+
deps.log(retained);
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
3417
4285
|
if (planeTarget && (await planeServesLiveRun(ctx, live))) {
|
|
3418
4286
|
deps.log([
|
|
3419
4287
|
"",
|
|
3420
4288
|
`${epicKey}: this checkout's plane is bound to run ${live.epicRunId}; its executor lanes serve it.`,
|
|
3421
4289
|
"No run-scoped executor was started beside them.",
|
|
3422
4290
|
].join("\n"));
|
|
4291
|
+
const servingManifest = await findAttachablePlane(ctx).catch(() => null);
|
|
4292
|
+
if (servingManifest !== null) {
|
|
4293
|
+
reportPlaneCapacity(ctx, attachedPlaneLaneCount(servingManifest), storedParallel, storedUnattended ? "unattended" : "attended");
|
|
4294
|
+
}
|
|
3423
4295
|
return 0;
|
|
3424
4296
|
}
|
|
3425
4297
|
const prepared = await deps.prepareRunExecutor(deps.cwd());
|
|
@@ -3433,6 +4305,7 @@ async function attachToLiveRun(ctx, readiness, live, unusedDiscoveredPlan) {
|
|
|
3433
4305
|
access,
|
|
3434
4306
|
profile,
|
|
3435
4307
|
mergeCredential: await launchCredentialForExecutor(ctx, readiness),
|
|
4308
|
+
...(storedUnattended && storedParallel !== undefined ? { maxConcurrent: storedParallel } : {}),
|
|
3436
4309
|
});
|
|
3437
4310
|
return reportExecutorOutcome(ctx, ensured, live.epicRunId, "attached");
|
|
3438
4311
|
}
|
|
@@ -3488,6 +4361,100 @@ function reportControlPlaneLaunchFailure(ctx, controlPlane) {
|
|
|
3488
4361
|
"No run was created.",
|
|
3489
4362
|
]);
|
|
3490
4363
|
}
|
|
4364
|
+
// ---------------------------------------------------------------------------
|
|
4365
|
+
// BAPI-1285 — the read-only launch preview (`--dry-run [--json]`)
|
|
4366
|
+
// ---------------------------------------------------------------------------
|
|
4367
|
+
//
|
|
4368
|
+
// The preview answers "what would a real invocation do?" and changes nothing. It
|
|
4369
|
+
// resolves the target, reads readiness and the epic's live run, discovers the
|
|
4370
|
+
// plan, and — when a plan is available — runs setup-epic's OWN dry run so the
|
|
4371
|
+
// server's real plan validator speaks. It never calls `adoptLaunchTarget`, a
|
|
4372
|
+
// non-dry `runSetupEpic`, `prepareRunExecutor`, `ensureRunExecutor`,
|
|
4373
|
+
// `launchControlPlane`, `runPlane`, or `requestScopedLanes`, and it never mutates
|
|
4374
|
+
// `process.env`.
|
|
4375
|
+
//
|
|
4376
|
+
// Output discipline: with `--json` stdout carries exactly ONE single-line JSON
|
|
4377
|
+
// document and nothing else, even on refusal. Nothing captured from setup-epic is
|
|
4378
|
+
// replayed, and no error text, credential, webhook URL, or policy content is ever
|
|
4379
|
+
// put into the document. The narrow exception is the production epic-launch
|
|
4380
|
+
// resolver's fixed sentences: they may name a store target key, store/profile
|
|
4381
|
+
// path, profile name, or validated safe binding target URL, never a credential
|
|
4382
|
+
// value or entry contents. Readiness, live-run, setup, and thrown errors remain
|
|
4383
|
+
// excluded.
|
|
4384
|
+
//
|
|
4385
|
+
// Known limits, stated plainly: the preview probes a port in exactly two narrow
|
|
4386
|
+
// cases, both after a local readiness read failed at the transport — a supplied
|
|
4387
|
+
// or discovered plan (to preview the guarded cold start), and no usable plan (the
|
|
4388
|
+
// plane-down stop, whose text is a verbatim part of the real launch's output).
|
|
4389
|
+
// Any other local plane that is not listening reads as unknown readiness; and a
|
|
4390
|
+
// local-plane target with only the reconciler missing previews as if the runtime
|
|
4391
|
+
// could be brought up, as a real launch with a plan composes.
|
|
4392
|
+
// BAPI-1594 — the engine's own paths live in their own module (they are Bridge repository
|
|
4393
|
+
// paths, not owner-facing text); re-exported here beside the preview definitions.
|
|
4394
|
+
export { ENGINE_PATHS };
|
|
4395
|
+
/** Bound for the one engine-path `git status`. */
|
|
4396
|
+
const ENGINE_STATUS_TIMEOUT_MS = 10_000;
|
|
4397
|
+
/** One porcelain-v1 `-z` record: two status columns, a space, then a path. */
|
|
4398
|
+
const PORCELAIN_RECORD = /^[ MTADRCU?!][ MTADRCU?!] [^\0]+$/;
|
|
4399
|
+
/**
|
|
4400
|
+
* Classify the NUL-delimited porcelain-v1 output of the engine-path status.
|
|
4401
|
+
* `clean` only for explicitly empty output. A rename or copy record is followed
|
|
4402
|
+
* by its origin path as a separate NUL-terminated field; a path-filtered rename
|
|
4403
|
+
* into or out of an engine path can legally appear as just the engine-side
|
|
4404
|
+
* addition or deletion. Anything that does not parse is `unreadable`, never clean.
|
|
4405
|
+
*/
|
|
4406
|
+
function classifyEngineStatus(stdout) {
|
|
4407
|
+
if (typeof stdout !== "string")
|
|
4408
|
+
return "unreadable";
|
|
4409
|
+
if (stdout === "")
|
|
4410
|
+
return "clean";
|
|
4411
|
+
if (!stdout.endsWith("\0"))
|
|
4412
|
+
return "unreadable";
|
|
4413
|
+
const fields = stdout.slice(0, -1).split("\0");
|
|
4414
|
+
let records = 0;
|
|
4415
|
+
for (let i = 0; i < fields.length; i += 1) {
|
|
4416
|
+
const field = fields[i];
|
|
4417
|
+
if (!PORCELAIN_RECORD.test(field))
|
|
4418
|
+
return "unreadable";
|
|
4419
|
+
records += 1;
|
|
4420
|
+
if (/^[RC]/.test(field) || /^.[RC]/.test(field)) {
|
|
4421
|
+
// The rename/copy origin path follows as its own field.
|
|
4422
|
+
i += 1;
|
|
4423
|
+
if (i >= fields.length || fields[i] === "")
|
|
4424
|
+
return "unreadable";
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
return records > 0 ? "dirty" : "unreadable";
|
|
4428
|
+
}
|
|
4429
|
+
/**
|
|
4430
|
+
* Collect the health-check fact for a verified Bridge LOCAL-plane create preview
|
|
4431
|
+
* (BAPI-1594). Advisory by construction: it never changes the decision, a
|
|
4432
|
+
* refusal, or the exit code, and nothing it saw (a filename, raw porcelain, an
|
|
4433
|
+
* error) reaches the document. Any uncertainty asks for the check.
|
|
4434
|
+
*/
|
|
4435
|
+
async function appendHealthCheckFact(deps, preview, repository) {
|
|
4436
|
+
if (repository?.isBridge !== true || preview.target.kind !== "local_plane" || preview.decision !== "create")
|
|
4437
|
+
return;
|
|
4438
|
+
const exec = deps.execEngineStatus;
|
|
4439
|
+
if (exec === undefined)
|
|
4440
|
+
return;
|
|
4441
|
+
let outcome = "unreadable";
|
|
4442
|
+
try {
|
|
4443
|
+
const result = await exec("git", ["status", "--porcelain=v1", "-z", "--untracked-files=all", "--", ...ENGINE_PATHS], { cwd: repository.repoRoot, timeoutMs: ENGINE_STATUS_TIMEOUT_MS });
|
|
4444
|
+
if (result !== null && typeof result === "object" && result.ok === true)
|
|
4445
|
+
outcome = classifyEngineStatus(result.stdout);
|
|
4446
|
+
}
|
|
4447
|
+
catch {
|
|
4448
|
+
outcome = "unreadable";
|
|
4449
|
+
}
|
|
4450
|
+
if (outcome === "clean") {
|
|
4451
|
+
preview.health_check_needed = false;
|
|
4452
|
+
}
|
|
4453
|
+
else {
|
|
4454
|
+
preview.health_check_needed = true;
|
|
4455
|
+
preview.health_check_reason = outcome === "dirty" ? "engine_paths_changed" : "git_status_unreadable";
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
3491
4458
|
export const DRIVE_EPIC_ACCESS_REFUSAL_REASON_IDS = {
|
|
3492
4459
|
"profile-unusable": "access-profile-unusable",
|
|
3493
4460
|
"target-missing": "access-target-missing",
|
|
@@ -3498,7 +4465,7 @@ export const DRIVE_EPIC_ACCESS_REFUSAL_REASON_IDS = {
|
|
|
3498
4465
|
"credentials-unavailable": "access-credentials-unavailable",
|
|
3499
4466
|
"credential-unbound": "access-credential-unbound",
|
|
3500
4467
|
};
|
|
3501
|
-
const WORKER_DATABASE_PREVIEW_IDS = ["worker-db-role", "worker-db-boundary"
|
|
4468
|
+
const WORKER_DATABASE_PREVIEW_IDS = ["worker-db-role", "worker-db-boundary"];
|
|
3502
4469
|
function nonBridgeRows(ids) {
|
|
3503
4470
|
return ids.map((id) => {
|
|
3504
4471
|
const started = monotonicNow();
|
|
@@ -3507,7 +4474,7 @@ function nonBridgeRows(ids) {
|
|
|
3507
4474
|
});
|
|
3508
4475
|
}
|
|
3509
4476
|
/** BAPI-1452 — project launch rows into the stable preview shape. */
|
|
3510
|
-
function previewLaunchRows(checks) {
|
|
4477
|
+
export function previewLaunchRows(checks) {
|
|
3511
4478
|
return checks.map((check) => {
|
|
3512
4479
|
const started = monotonicNow();
|
|
3513
4480
|
return {
|
|
@@ -3524,6 +4491,26 @@ function previewLaunchRows(checks) {
|
|
|
3524
4491
|
/** The readiness reason a preview reports for a generic not-ready engine. */
|
|
3525
4492
|
const ENGINE_NOT_READY_REASON_ID = "engine-not-ready";
|
|
3526
4493
|
const ENGINE_NOT_READY_REMEDY = `Resolve Epic Implementer readiness (\`${PRINTED_CONDUCTOR_INSTALL_COMMAND}\`, then \`${PRINTED_DOCTOR_COMMAND}\`) and run drive-epic again. ${PRINTED_CHECK_NAME_INSTRUCTION} See ${CONSUMER_GUIDE_POINTER}.`;
|
|
4494
|
+
const CREATE_POLICY_PROJECTION_KEYS = [
|
|
4495
|
+
"posture",
|
|
4496
|
+
"v2_auto_merge_enabled",
|
|
4497
|
+
"merge_execution_mode",
|
|
4498
|
+
"integration_preparation",
|
|
4499
|
+
];
|
|
4500
|
+
/** Structural check only: an object carrying exactly the four projection keys. */
|
|
4501
|
+
function readCreatePolicyEnvelope(value) {
|
|
4502
|
+
if (value === undefined)
|
|
4503
|
+
return { kind: "absent" };
|
|
4504
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
4505
|
+
return { kind: "malformed" };
|
|
4506
|
+
const record = value;
|
|
4507
|
+
const keys = Object.keys(record);
|
|
4508
|
+
if (keys.length !== CREATE_POLICY_PROJECTION_KEYS.length ||
|
|
4509
|
+
!CREATE_POLICY_PROJECTION_KEYS.every((key) => Object.prototype.hasOwnProperty.call(record, key))) {
|
|
4510
|
+
return { kind: "malformed" };
|
|
4511
|
+
}
|
|
4512
|
+
return { kind: "present", policy: record };
|
|
4513
|
+
}
|
|
3527
4514
|
/**
|
|
3528
4515
|
* Read exactly one well-shaped setup-epic dry-run JSON document out of captured
|
|
3529
4516
|
* `log` output. Anything else — none, several, or one with the wrong shape — is
|
|
@@ -3580,7 +4567,15 @@ function readSetupPreviewPayload(stdout) {
|
|
|
3580
4567
|
const jobTimeouts = numericMap(facts.job_timeouts);
|
|
3581
4568
|
if (caps === undefined || jobTimeouts === undefined)
|
|
3582
4569
|
return null;
|
|
4570
|
+
// BAPI-1581 — strict when present (an integer 1-4 or "server_default"); an
|
|
4571
|
+
// absent field is older setup output and stays absent.
|
|
4572
|
+
const rawParallel = facts.parallel_limit;
|
|
4573
|
+
if (rawParallel !== undefined &&
|
|
4574
|
+
rawParallel !== "server_default" &&
|
|
4575
|
+
!(typeof rawParallel === "number" && Number.isInteger(rawParallel) && rawParallel >= 1 && rawParallel <= 4))
|
|
4576
|
+
return null;
|
|
3583
4577
|
effectivePolicy = {
|
|
4578
|
+
...(rawParallel !== undefined ? { parallel_limit: rawParallel } : {}),
|
|
3584
4579
|
source: facts.source,
|
|
3585
4580
|
serial_execution: "serial",
|
|
3586
4581
|
posture: facts.posture,
|
|
@@ -3605,16 +4600,95 @@ function readSetupPreviewPayload(stdout) {
|
|
|
3605
4600
|
catch {
|
|
3606
4601
|
return null;
|
|
3607
4602
|
} })(),
|
|
4603
|
+
serverPlanHash: typeof doc.server_plan_hash === "string" && /^[A-Za-z0-9:_-]{8,128}$/.test(doc.server_plan_hash)
|
|
4604
|
+
? doc.server_plan_hash
|
|
4605
|
+
: null,
|
|
4606
|
+
createPolicy: readCreatePolicyEnvelope(doc.create_policy),
|
|
3608
4607
|
};
|
|
3609
4608
|
}
|
|
3610
|
-
/** The
|
|
3611
|
-
async function
|
|
4609
|
+
/** The node count and the valid ticket keys in file order, or `null` unless the DAG has `{ nodes: [...] }`. */
|
|
4610
|
+
async function readPlanDagChildren(deps, planPath) {
|
|
3612
4611
|
try {
|
|
3613
4612
|
const parsed = JSON.parse(await deps.readPlanDag(planPath));
|
|
3614
4613
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
3615
4614
|
return null;
|
|
3616
4615
|
const nodes = parsed.nodes;
|
|
3617
|
-
|
|
4616
|
+
if (!Array.isArray(nodes))
|
|
4617
|
+
return null;
|
|
4618
|
+
const keys = [];
|
|
4619
|
+
for (const node of nodes) {
|
|
4620
|
+
const key = node !== null && typeof node === "object" ? node.ticket_key : undefined;
|
|
4621
|
+
if (typeof key === "string" && EPIC_KEY_PATTERN.test(key))
|
|
4622
|
+
keys.push(key);
|
|
4623
|
+
}
|
|
4624
|
+
return { count: nodes.length, keys };
|
|
4625
|
+
}
|
|
4626
|
+
catch {
|
|
4627
|
+
return null;
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
/**
|
|
4631
|
+
* BAPI-1621 — serve a generated preview's plan from memory.
|
|
4632
|
+
*
|
|
4633
|
+
* Every preview read of the plan goes through `readPlanDag`, setup-epic's dry
|
|
4634
|
+
* run, or `withPlanPath` (the trimmed copy when merged children are skipped).
|
|
4635
|
+
* This overlay answers all three for `planPath` without touching the disk, so a
|
|
4636
|
+
* generated preview stays completely read-only. Every other path reads as before.
|
|
4637
|
+
*/
|
|
4638
|
+
function withInlinePlan(deps, planPath, json) {
|
|
4639
|
+
const files = new Map([[planPath, json]]);
|
|
4640
|
+
const inner = deps.withPlanPath ?? withPlanPath;
|
|
4641
|
+
const inMemoryWithPlanPath = async (options, callback) => {
|
|
4642
|
+
if (!options.skipped || options.originalPath !== planPath)
|
|
4643
|
+
return inner(options, callback);
|
|
4644
|
+
const trimmedPath = planPath.replace(/\.json$/, ".trimmed.json");
|
|
4645
|
+
files.set(trimmedPath, options.trimmedJson);
|
|
4646
|
+
try {
|
|
4647
|
+
return await callback(trimmedPath);
|
|
4648
|
+
}
|
|
4649
|
+
finally {
|
|
4650
|
+
files.delete(trimmedPath);
|
|
4651
|
+
}
|
|
4652
|
+
};
|
|
4653
|
+
return {
|
|
4654
|
+
...deps,
|
|
4655
|
+
readPlanDag: (filePath) => {
|
|
4656
|
+
const inline = files.get(filePath);
|
|
4657
|
+
return inline !== undefined ? Promise.resolve(inline) : deps.readPlanDag(filePath);
|
|
4658
|
+
},
|
|
4659
|
+
previewSetupEpic: (args) => deps.previewSetupEpic({ ...args, planContents: files }),
|
|
4660
|
+
withPlanPath: inMemoryWithPlanPath,
|
|
4661
|
+
};
|
|
4662
|
+
}
|
|
4663
|
+
/**
|
|
4664
|
+
* BAPI-1621 — a found generated plan's nodes for the launch screen, read from the
|
|
4665
|
+
* DAG on disk. Null when the file cannot be read or is not a node list; the
|
|
4666
|
+
* preview's own validation stays the authority on the plan.
|
|
4667
|
+
*/
|
|
4668
|
+
async function readGeneratedPlanNodes(deps, planPath) {
|
|
4669
|
+
try {
|
|
4670
|
+
const parsed = JSON.parse(await deps.readPlanDag(planPath));
|
|
4671
|
+
const nodes = parsed?.nodes;
|
|
4672
|
+
if (!Array.isArray(nodes))
|
|
4673
|
+
return null;
|
|
4674
|
+
const result = [];
|
|
4675
|
+
for (const raw of nodes) {
|
|
4676
|
+
const node = raw;
|
|
4677
|
+
if (typeof node?.ticket_key !== "string" || !EPIC_KEY_PATTERN.test(node.ticket_key))
|
|
4678
|
+
return null;
|
|
4679
|
+
if (node.status !== "planned" && node.status !== "done")
|
|
4680
|
+
return null;
|
|
4681
|
+
const dependsOn = Array.isArray(node.depends_on) ? node.depends_on : [];
|
|
4682
|
+
if (!dependsOn.every((dep) => typeof dep === "string" && EPIC_KEY_PATTERN.test(dep)))
|
|
4683
|
+
return null;
|
|
4684
|
+
result.push({
|
|
4685
|
+
ticket_key: node.ticket_key,
|
|
4686
|
+
status: node.status,
|
|
4687
|
+
depends_on: dependsOn,
|
|
4688
|
+
...(Array.isArray(node.touched_files) ? { touched_files: node.touched_files.filter((f) => typeof f === "string") } : {}),
|
|
4689
|
+
});
|
|
4690
|
+
}
|
|
4691
|
+
return result;
|
|
3618
4692
|
}
|
|
3619
4693
|
catch {
|
|
3620
4694
|
return null;
|
|
@@ -3669,12 +4743,21 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3669
4743
|
*/
|
|
3670
4744
|
const refuseWithReadiness = (kind, named, _alsoTopLevel = false) => {
|
|
3671
4745
|
preview.readiness = { kind, reason_id: named.reasonId, remedy: named.remedy };
|
|
3672
|
-
|
|
4746
|
+
// BAPI-1596: `operator_blocked` is the classification that rests on proven evidence.
|
|
4747
|
+
preview.refusal = {
|
|
4748
|
+
reason_id: named.reasonId,
|
|
4749
|
+
remedy: named.remedy,
|
|
4750
|
+
...(kind === "operator_blocked" ? { authoritative: true } : {}),
|
|
4751
|
+
};
|
|
3673
4752
|
preview.decision = "refuse";
|
|
3674
4753
|
};
|
|
3675
4754
|
/** A refusal that is not about readiness: only the top-level block carries it. */
|
|
3676
4755
|
const refuseTopLevel = (named) => {
|
|
3677
|
-
preview.refusal = {
|
|
4756
|
+
preview.refusal = {
|
|
4757
|
+
reason_id: named.reasonId,
|
|
4758
|
+
remedy: named.remedy,
|
|
4759
|
+
...(named.authoritative === true ? { authoritative: true } : {}),
|
|
4760
|
+
};
|
|
3678
4761
|
preview.decision = "refuse";
|
|
3679
4762
|
};
|
|
3680
4763
|
// The readiness read previewDecision observed, for the reachability row. It stays
|
|
@@ -3693,10 +4776,13 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3693
4776
|
});
|
|
3694
4777
|
}
|
|
3695
4778
|
ensureRefusalExplained(preview);
|
|
4779
|
+
await writePreviewLaunchContext(deps, options, preview, observed);
|
|
3696
4780
|
if (observed.repository?.isBridge === false && !preview.launch_checks?.some((row) => row.id === "plane-snapshot-freshness")) {
|
|
3697
4781
|
preview.launch_checks = [...(preview.launch_checks ?? []), ...nonBridgeRows(["plane-snapshot-freshness", "plane-database-head"])];
|
|
3698
4782
|
}
|
|
3699
|
-
|
|
4783
|
+
// Each probe writes to a private copy. `tally_lines` and `warnings` start empty on a copy
|
|
4784
|
+
// (a shared array would double-count; an absent one would be lost) and are merged back below.
|
|
4785
|
+
const isolated = () => ({ ...preview, launch_checks: [], tally_lines: undefined, warnings: undefined });
|
|
3700
4786
|
const worker = isolated();
|
|
3701
4787
|
const escalation = isolated();
|
|
3702
4788
|
const executor = isolated();
|
|
@@ -3705,15 +4791,23 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3705
4791
|
if (scopeBase)
|
|
3706
4792
|
previewScopeBaseBranch.set(needs, scopeBase);
|
|
3707
4793
|
// Collect into private arrays; only launch-needs waits for the worker result.
|
|
3708
|
-
|
|
4794
|
+
// BAPI-1596 — the boundary follows the configured mode, from the readiness this preview
|
|
4795
|
+
// already holds (the same projection the launch-context file stores). No extra read.
|
|
4796
|
+
const applicability = resolveWorkerDatabaseApplicability({
|
|
4797
|
+
declaration: projectWorkerDatabase(observed.readiness?.gate_profile?.worker_database),
|
|
4798
|
+
validContext: observed.readiness !== null,
|
|
4799
|
+
isBridge: observed.repository?.isBridge,
|
|
4800
|
+
});
|
|
4801
|
+
const workerTask = timed("worker_database_ms", () => appendWorkerDatabaseAdvisoryRows(deps, worker, observed.repository, applicability));
|
|
3709
4802
|
const needsTask = workerTask.then((section) => {
|
|
3710
4803
|
needs.launch_checks = [...(worker.launch_checks ?? [])];
|
|
3711
|
-
return timed("launch_needs_ms", () => appendLaunchNeedRows(deps, needs, observed, section));
|
|
4804
|
+
return timed("launch_needs_ms", () => appendLaunchNeedRows(deps, needs, observed, section, applicability));
|
|
3712
4805
|
});
|
|
3713
4806
|
await Promise.all([
|
|
3714
4807
|
needsTask,
|
|
4808
|
+
timed("health_status_ms", () => appendHealthCheckFact(deps, preview, observed.repository)),
|
|
3715
4809
|
timed("escalation_ms", async () => { appendEscalationReachabilityRow(escalation, observed.readiness); }),
|
|
3716
|
-
timed("executor_build_ms", () => appendExecutorBuildFreshnessWarning(deps, executor)),
|
|
4810
|
+
timed("executor_build_ms", () => appendExecutorBuildFreshnessWarning(deps, executor, observed.repository)),
|
|
3717
4811
|
]);
|
|
3718
4812
|
const workerIds = new Set(worker.launch_checks?.map((row) => row.id));
|
|
3719
4813
|
const needRows = needs.launch_checks ?? [];
|
|
@@ -3722,14 +4816,21 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3722
4816
|
...(escalation.launch_checks ?? []), ...(executor.launch_checks ?? []),
|
|
3723
4817
|
...needRows.filter((row) => !workerIds.has(row.id)),
|
|
3724
4818
|
];
|
|
3725
|
-
|
|
4819
|
+
mergeIsolatedObservations(preview, escalation, [worker, escalation, executor, needs]);
|
|
4820
|
+
// BAPI-1596 — the plan is built once, from the finished preview, and only for a create
|
|
4821
|
+
// or a refusal the preview selected as authoritative. A failure leaves no plan; the
|
|
4822
|
+
// session then shows the plain older-CLI screen and computes nothing.
|
|
4823
|
+
if (preview.decision === "create" || (preview.decision === "refuse" && preview.refusal?.authoritative === true)) {
|
|
3726
4824
|
try {
|
|
3727
|
-
const
|
|
4825
|
+
const collected = await collectLaunchPlanFacts(deps, options, preview, observed);
|
|
4826
|
+
// The tally lines do not depend on the builder succeeding.
|
|
4827
|
+
recordLaunchPlanObservations(preview, collected.tally);
|
|
4828
|
+
const result = (deps.buildLaunchPlan ?? buildLaunchPlan)(preview, collected.facts);
|
|
3728
4829
|
if (result)
|
|
3729
4830
|
preview.launch_plan = result.launch_plan;
|
|
3730
4831
|
}
|
|
3731
4832
|
catch {
|
|
3732
|
-
deps.errorLog("Launch plan unavailable; the
|
|
4833
|
+
deps.errorLog("Launch plan unavailable; the preview carries no plan.");
|
|
3733
4834
|
}
|
|
3734
4835
|
}
|
|
3735
4836
|
timings.total_ms = elapsedMs(started);
|
|
@@ -3740,6 +4841,160 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3740
4841
|
return 1;
|
|
3741
4842
|
return preview.decision === "create" || preview.decision === "attach" ? 0 : 1;
|
|
3742
4843
|
}
|
|
4844
|
+
/** The plan's child keys per preview, in file order. Kept off the document. */
|
|
4845
|
+
const previewPlanChildKeys = new WeakMap();
|
|
4846
|
+
/** The most time a launch preview spends reading the prerequisite cache before it carries on without it. */
|
|
4847
|
+
const PREREQUISITE_CACHE_READ_TIMEOUT_MS = 10_000;
|
|
4848
|
+
const PREREQUISITE_ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
4849
|
+
function handoffValueText(value) {
|
|
4850
|
+
return value === "unknown" ? "unknown (today's default: proceed)" : value;
|
|
4851
|
+
}
|
|
4852
|
+
/**
|
|
4853
|
+
* BAPI-1596 — collect the launch plan's facts ONCE, from evidence the preview already
|
|
4854
|
+
* holds. The only new reads are the injected cache read and a boolean-only presence
|
|
4855
|
+
* check per distinct core variable name. Nothing here reads an environment value,
|
|
4856
|
+
* refuses, or changes a decision; unavailable evidence is tallied and the launch goes on.
|
|
4857
|
+
*/
|
|
4858
|
+
async function collectLaunchPlanFacts(deps, options, preview, observed) {
|
|
4859
|
+
const tally = [];
|
|
4860
|
+
// The hand-off policy this launch will stamp, and the project default beside it.
|
|
4861
|
+
const reported = observed.readiness?.gate_profile?.verification_handoff_default;
|
|
4862
|
+
const projectDefault = reported === "proceed" || reported === "block" ? reported : "unknown";
|
|
4863
|
+
const explicit = options.verificationHandoff === "proceed" || options.verificationHandoff === "block"
|
|
4864
|
+
? options.verificationHandoff
|
|
4865
|
+
: null;
|
|
4866
|
+
const handoff = { explicit, projectDefault };
|
|
4867
|
+
const effective = explicit ?? projectDefault;
|
|
4868
|
+
const source = explicit !== null ? "explicit choice"
|
|
4869
|
+
: projectDefault !== "unknown" ? "project default"
|
|
4870
|
+
: observed.readiness === null ? "readiness not read" : "older server, no default reported";
|
|
4871
|
+
tally.push({
|
|
4872
|
+
code: "verification_handoff_policy",
|
|
4873
|
+
line: `verification hand-off: ${handoffValueText(effective)} (${source}); project default ${handoffValueText(projectDefault)}`,
|
|
4874
|
+
});
|
|
4875
|
+
// Child 5's cache, for the children this launch will actually run.
|
|
4876
|
+
let prerequisites = { status: "not_collected" };
|
|
4877
|
+
const keys = previewPlanChildKeys.get(preview);
|
|
4878
|
+
if (deps.readPrerequisiteCache !== undefined && keys !== undefined) {
|
|
4879
|
+
const skipped = new Set();
|
|
4880
|
+
const merged = preview.already_done_children;
|
|
4881
|
+
if (merged !== undefined && merged.status === "checked") {
|
|
4882
|
+
for (const child of merged.children)
|
|
4883
|
+
if (child.will_skip === true)
|
|
4884
|
+
skipped.add(child.ticket_key);
|
|
4885
|
+
}
|
|
4886
|
+
const members = new Set(keys.filter((key) => !skipped.has(key)));
|
|
4887
|
+
let read;
|
|
4888
|
+
try {
|
|
4889
|
+
read = observed.contextAccess === undefined
|
|
4890
|
+
? { kind: "unavailable" }
|
|
4891
|
+
: await deps.readPrerequisiteCache({ epicKey: options.epicKey, children: keys, access: observed.contextAccess });
|
|
4892
|
+
}
|
|
4893
|
+
catch {
|
|
4894
|
+
read = { kind: "unavailable" };
|
|
4895
|
+
}
|
|
4896
|
+
if (read.kind === "unavailable") {
|
|
4897
|
+
tally.push({ code: "prerequisite_cache_unavailable", line: "prerequisite scan: cache not read at preview" });
|
|
4898
|
+
}
|
|
4899
|
+
else {
|
|
4900
|
+
const hasEnv = deps.hasEnvName ?? ((name) => Object.hasOwn(process.env, name));
|
|
4901
|
+
const presence = new Map();
|
|
4902
|
+
const missing = new Map();
|
|
4903
|
+
const runtimeChildren = new Set();
|
|
4904
|
+
const kept = { minor: 0, "observed present": 0, "worker runtime": 0, "not measurable": 0, skipped: 0 };
|
|
4905
|
+
for (const entry of read.entries) {
|
|
4906
|
+
if (!members.has(entry.child)) {
|
|
4907
|
+
kept.skipped += entry.items.length;
|
|
4908
|
+
continue;
|
|
4909
|
+
}
|
|
4910
|
+
for (const item of entry.items) {
|
|
4911
|
+
if ("category" in item) {
|
|
4912
|
+
kept["worker runtime"] += 1;
|
|
4913
|
+
runtimeChildren.add(entry.child);
|
|
4914
|
+
continue;
|
|
4915
|
+
}
|
|
4916
|
+
if ("measurable" in item) {
|
|
4917
|
+
kept["not measurable"] += 1;
|
|
4918
|
+
continue;
|
|
4919
|
+
}
|
|
4920
|
+
if (item.class !== "core") {
|
|
4921
|
+
kept.minor += 1;
|
|
4922
|
+
continue;
|
|
4923
|
+
}
|
|
4924
|
+
if (!PREREQUISITE_ENV_NAME.test(item.env)) {
|
|
4925
|
+
kept["not measurable"] += 1;
|
|
4926
|
+
continue;
|
|
4927
|
+
}
|
|
4928
|
+
if (!presence.has(item.env))
|
|
4929
|
+
presence.set(item.env, hasEnv(item.env));
|
|
4930
|
+
if (presence.get(item.env) === true) {
|
|
4931
|
+
kept["observed present"] += 1;
|
|
4932
|
+
continue;
|
|
4933
|
+
}
|
|
4934
|
+
const mapKey = `${item.env}:${item.uncertain}`;
|
|
4935
|
+
const prior = missing.get(mapKey);
|
|
4936
|
+
missing.set(mapKey, prior === undefined
|
|
4937
|
+
? { name: item.env, requirement: item.requirement, dependents: item.dependents, uncertain: item.uncertain === "yes" }
|
|
4938
|
+
: { ...prior, dependents: prior.dependents.split(", ").includes(item.dependents) ? prior.dependents : `${prior.dependents}, ${item.dependents}` });
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
for (const [category, count] of Object.entries(kept)) {
|
|
4942
|
+
if (count > 0)
|
|
4943
|
+
tally.push({ code: "prerequisite_kept_off_screen", line: `prerequisite scan: kept off the screen: ${category} ${count}` });
|
|
4944
|
+
}
|
|
4945
|
+
prerequisites = {
|
|
4946
|
+
status: "collected",
|
|
4947
|
+
missingCore: [...missing.values()],
|
|
4948
|
+
workerRuntimeChildren: [...runtimeChildren],
|
|
4949
|
+
};
|
|
4950
|
+
}
|
|
4951
|
+
}
|
|
4952
|
+
// Launch rows the screen leaves out, so nothing is silent.
|
|
4953
|
+
const suppressed = [];
|
|
4954
|
+
// Server rows that only warn (for example an unset integration branch) never reach the screen;
|
|
4955
|
+
// the webhook row is the one warning the plan presents.
|
|
4956
|
+
for (const row of preview.prerequisites ?? []) {
|
|
4957
|
+
if (row.impact === "warning" && row.check_status === "not_met" && row.id !== SERVER_WEBHOOK_ROW_ID) {
|
|
4958
|
+
suppressed.push(row.id.replace(/^server\./, ""));
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
// Rows the plan presents are the three launch needs and the proven boundary; any other
|
|
4962
|
+
// warning or failing launch row stays in the preview's rows and is named here.
|
|
4963
|
+
const PRESENTED_ROWS = new Set([...Object.values(LAUNCH_NEED_ROW_IDS), "worker-db-boundary"]);
|
|
4964
|
+
for (const row of preview.launch_checks ?? []) {
|
|
4965
|
+
if ((row.status === "warn" || row.status === "fail") && !PRESENTED_ROWS.has(row.id) &&
|
|
4966
|
+
row.id !== ESCALATION_REACHABILITY_CHECK_ID) {
|
|
4967
|
+
suppressed.push(row.id);
|
|
4968
|
+
}
|
|
4969
|
+
}
|
|
4970
|
+
if (suppressed.length > 0) {
|
|
4971
|
+
tally.push({ code: "launch_rows_kept_off_screen", line: `launch rows kept off the screen: ${[...new Set(suppressed)].join(", ")}` });
|
|
4972
|
+
}
|
|
4973
|
+
return { facts: { prerequisites, handoff }, tally };
|
|
4974
|
+
}
|
|
4975
|
+
/** Append the collected fixed lines to the preview's tally lines, once each. */
|
|
4976
|
+
function recordLaunchPlanObservations(preview, lines) {
|
|
4977
|
+
if (lines.length === 0)
|
|
4978
|
+
return;
|
|
4979
|
+
const seen = new Set((preview.tally_lines ?? []).map((entry) => `${entry.code}\u0000${entry.line}`));
|
|
4980
|
+
const fresh = lines.filter((entry) => !seen.has(`${entry.code}\u0000${entry.line}`));
|
|
4981
|
+
if (fresh.length > 0)
|
|
4982
|
+
preview.tally_lines = [...(preview.tally_lines ?? []), ...fresh];
|
|
4983
|
+
}
|
|
4984
|
+
/** Fold the private copies' tally lines, warnings, and escalation presentation back into the preview. */
|
|
4985
|
+
function mergeIsolatedObservations(preview, escalation, parts) {
|
|
4986
|
+
for (const part of parts) {
|
|
4987
|
+
if (part.tally_lines !== undefined && part.tally_lines.length > 0) {
|
|
4988
|
+
preview.tally_lines = [...(preview.tally_lines ?? []), ...part.tally_lines];
|
|
4989
|
+
}
|
|
4990
|
+
if (part.warnings !== undefined && part.warnings.length > 0) {
|
|
4991
|
+
preview.warnings = [...(preview.warnings ?? []), ...part.warnings];
|
|
4992
|
+
}
|
|
4993
|
+
}
|
|
4994
|
+
const presentation = previewEscalationPresentation.get(escalation);
|
|
4995
|
+
if (presentation !== undefined)
|
|
4996
|
+
previewEscalationPresentation.set(preview, presentation);
|
|
4997
|
+
}
|
|
3743
4998
|
/**
|
|
3744
4999
|
* Give every `create` or `attach` preview exactly one non-blocking
|
|
3745
5000
|
* `escalation-reachability` row (BAPI-1490).
|
|
@@ -3750,13 +5005,40 @@ async function runDriveEpicPreview(deps, options) {
|
|
|
3750
5005
|
* read failure) is passed as unavailable, so the row warns rather than vanishing.
|
|
3751
5006
|
* A refused or stopped preview describes no launch, so it gets none.
|
|
3752
5007
|
*/
|
|
5008
|
+
/** BAPI-1595 — what each preview's reachability output may claim. Kept off the JSON document. */
|
|
5009
|
+
const previewEscalationPresentation = new WeakMap();
|
|
3753
5010
|
function appendEscalationReachabilityRow(preview, readiness) {
|
|
3754
5011
|
const started = monotonicNow();
|
|
3755
5012
|
if (preview.decision !== "create" && preview.decision !== "attach")
|
|
3756
5013
|
return;
|
|
5014
|
+
// BAPI-1598 — fixed tally lines for the worker-database and hand-off settings the
|
|
5015
|
+
// readiness already reported. An older server reports neither, so nothing is added.
|
|
5016
|
+
for (const entry of workerSetupTallyEntries(readiness?.gate_profile)) {
|
|
5017
|
+
(preview.tally_lines ??= []).push({ code: entry.code, line: entry.message });
|
|
5018
|
+
}
|
|
3757
5019
|
const [row] = previewLaunchRows([
|
|
3758
5020
|
buildEscalationReachabilityCheck(readiness, preview.summary.escalation_channel),
|
|
3759
5021
|
]);
|
|
5022
|
+
// BAPI-1595 — decide what the output may SAY. The JSON row stays (an older reader
|
|
5023
|
+
// and the launch plan treat an absent row as "unconfirmed"); the human line is
|
|
5024
|
+
// shown only when it is true, and a left-out line is written to the tally once.
|
|
5025
|
+
const presentation = classifyEscalationReachabilityPresentation(readiness, preview.summary.escalation_channel);
|
|
5026
|
+
previewEscalationPresentation.set(preview, presentation);
|
|
5027
|
+
if (presentation === "uncertain") {
|
|
5028
|
+
(preview.warnings ??= []).push(ESCALATION_CHANNEL_UNCERTAIN_WARNING);
|
|
5029
|
+
}
|
|
5030
|
+
if (presentation === "uncertain" || presentation === "omitted") {
|
|
5031
|
+
(preview.tally_lines ??= []).push({
|
|
5032
|
+
code: ESCALATION_LINE_SUPPRESSED_REASON_CODE,
|
|
5033
|
+
line: ESCALATION_LINE_SUPPRESSED_LINE,
|
|
5034
|
+
});
|
|
5035
|
+
}
|
|
5036
|
+
if (presentation === "uncertain") {
|
|
5037
|
+
(preview.tally_lines ??= []).push({
|
|
5038
|
+
code: ESCALATION_CHANNEL_UNCERTAIN_REASON_CODE,
|
|
5039
|
+
line: ESCALATION_CHANNEL_UNCERTAIN_WARNING,
|
|
5040
|
+
});
|
|
5041
|
+
}
|
|
3760
5042
|
preview.launch_checks = [
|
|
3761
5043
|
...(preview.launch_checks ?? []).filter((existing) => existing.id !== ESCALATION_REACHABILITY_CHECK_ID),
|
|
3762
5044
|
{ ...row, duration_ms: elapsedMs(started) },
|
|
@@ -3770,7 +5052,7 @@ function appendEscalationReachabilityRow(preview, readiness) {
|
|
|
3770
5052
|
* missing dependency leaves `launch_checks` untouched. A thrown check prints one
|
|
3771
5053
|
* fixed line and nothing from the exception.
|
|
3772
5054
|
*/
|
|
3773
|
-
async function appendExecutorBuildFreshnessWarning(deps, preview) {
|
|
5055
|
+
async function appendExecutorBuildFreshnessWarning(deps, preview, repository) {
|
|
3774
5056
|
const started = monotonicNow();
|
|
3775
5057
|
const override = process.env[BRIDGE_LAUNCHER_ENV];
|
|
3776
5058
|
if (override === undefined || override.trim() === "")
|
|
@@ -3778,7 +5060,7 @@ async function appendExecutorBuildFreshnessWarning(deps, preview) {
|
|
|
3778
5060
|
if (deps.checkExecutorBuildFreshness === undefined)
|
|
3779
5061
|
return;
|
|
3780
5062
|
try {
|
|
3781
|
-
const report = await deps.checkExecutorBuildFreshness(deps.cwd());
|
|
5063
|
+
const report = await deps.checkExecutorBuildFreshness(deps.cwd(), repository?.isBridge === false ? { isBridge: false } : undefined);
|
|
3782
5064
|
if (report.diagnostic === null)
|
|
3783
5065
|
return;
|
|
3784
5066
|
const outcome = report.outcomes.find((entry) => entry.status === "warn" || entry.status === "fail") ?? report.outcomes[0];
|
|
@@ -3802,6 +5084,70 @@ async function appendExecutorBuildFreshnessWarning(deps, preview) {
|
|
|
3802
5084
|
* preview document so its JSON shape is unchanged.
|
|
3803
5085
|
*/
|
|
3804
5086
|
const previewScopeBaseBranch = new WeakMap();
|
|
5087
|
+
/** BAPI-1601 — why an `unavailable` auto-merge intent has nothing to show. Print-only. */
|
|
5088
|
+
const previewAutoMergeUnavailableReason = new WeakMap();
|
|
5089
|
+
/** The one human auto-merge line, worded exactly as setup-epic words it. */
|
|
5090
|
+
function autoMergeLine(preview) {
|
|
5091
|
+
const merge = preview.summary.auto_merge;
|
|
5092
|
+
if (merge === undefined)
|
|
5093
|
+
return " Auto-merge: n/a";
|
|
5094
|
+
if (merge.state === "unavailable") {
|
|
5095
|
+
return previewAutoMergeUnavailableReason.get(preview) === "invalid"
|
|
5096
|
+
? " Auto-merge: unavailable (the policy does not declare a valid auto-merge setting)"
|
|
5097
|
+
: " Auto-merge: unavailable (older setup-epic output)";
|
|
5098
|
+
}
|
|
5099
|
+
const intent = merge.state === "on" ? { state: "on" } : { state: "off", reason: merge.reason ?? "" };
|
|
5100
|
+
return ` ${formatSetupEpicAutoMergeIntent(intent, preview.summary.branch ?? undefined)}`;
|
|
5101
|
+
}
|
|
5102
|
+
/** BAPI-1593 — the plan digest setup-epic's dry run says the SERVER validated, per preview. */
|
|
5103
|
+
const previewServerPlanDigest = new WeakMap();
|
|
5104
|
+
/**
|
|
5105
|
+
* BAPI-1593 — write the launch-context file from what the preview already
|
|
5106
|
+
* established. It issues no request: the readiness result is the acquisition's
|
|
5107
|
+
* latest completed attempt, read without spending a retry. A failure is one
|
|
5108
|
+
* warning and a `launch_context_write_failed` observation, never a refusal.
|
|
5109
|
+
*/
|
|
5110
|
+
async function writePreviewLaunchContext(deps, options, preview, observed) {
|
|
5111
|
+
if (deps.writeLaunchContext === undefined || observed.acquisition === undefined)
|
|
5112
|
+
return;
|
|
5113
|
+
const readiness = observed.acquisition.peek();
|
|
5114
|
+
// BAPI-1595 — the base branch the launch will bind to. Setup's dry run reports it for
|
|
5115
|
+
// a branch-bearing run; for any other run (for example `--into-base`) it reports
|
|
5116
|
+
// none, so the same resolution the launch uses fills it in. Without a base on the
|
|
5117
|
+
// stored file the launch could never match it.
|
|
5118
|
+
let baseBranch = previewScopeBaseBranch.get(preview) ?? null;
|
|
5119
|
+
if (baseBranch === null && observed.contextAccess !== undefined && deps.readScopeBaseBranch !== undefined) {
|
|
5120
|
+
try {
|
|
5121
|
+
baseBranch = (await deps.readScopeBaseBranch(observed.contextAccess)) ?? null;
|
|
5122
|
+
}
|
|
5123
|
+
catch {
|
|
5124
|
+
baseBranch = null;
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
const context = buildEpicLaunchContext({
|
|
5128
|
+
epicKey: options.epicKey,
|
|
5129
|
+
baseBranch,
|
|
5130
|
+
targetBaseUrl: preview.target.base_url,
|
|
5131
|
+
writtenAt: new Date((deps.now ?? Date.now)()),
|
|
5132
|
+
readiness,
|
|
5133
|
+
// BAPI-1595 — the VERIFIED local identity only. A report's own repo_name is never
|
|
5134
|
+
// substituted when the local identity is unavailable.
|
|
5135
|
+
repoName: observed.repoName ?? null,
|
|
5136
|
+
isBridge: observed.repository?.isBridge ?? null,
|
|
5137
|
+
serverPlanDigest: previewServerPlanDigest.get(preview) ?? null,
|
|
5138
|
+
});
|
|
5139
|
+
let written;
|
|
5140
|
+
try {
|
|
5141
|
+
written = await deps.writeLaunchContext(context);
|
|
5142
|
+
}
|
|
5143
|
+
catch {
|
|
5144
|
+
written = { ok: false, reason: "write_failed" };
|
|
5145
|
+
}
|
|
5146
|
+
if (!written.ok) {
|
|
5147
|
+
deps.errorLog(`${options.epicKey}: [warn] launch_context_write_failed — the launch-context file could not be ` +
|
|
5148
|
+
`written (${written.reason}); the preview is unaffected and no current context was claimed.`);
|
|
5149
|
+
}
|
|
5150
|
+
}
|
|
3805
5151
|
/** Run one probe; a missing boundary or any rejection becomes the fallback fact. */
|
|
3806
5152
|
async function guardedProbe(run, fallback) {
|
|
3807
5153
|
if (run === undefined)
|
|
@@ -3829,29 +5175,29 @@ async function collectHostPowerFact(deps, topology) {
|
|
|
3829
5175
|
return hostPowerFactFromReport(report);
|
|
3830
5176
|
}
|
|
3831
5177
|
/**
|
|
3832
|
-
* Append the
|
|
3833
|
-
* role, self-hosted runner, host power (`host-sleep`)
|
|
3834
|
-
*
|
|
5178
|
+
* Append the three launch-need rows to a `create` preview (BAPI-1506, narrowed by
|
|
5179
|
+
* BAPI-1596): worker DB role, self-hosted runner, and host power (`host-sleep`).
|
|
5180
|
+
* The usage-reset and epic-branch-behind-base needs are gone: a launch neither
|
|
5181
|
+
* probes nor shows them.
|
|
3835
5182
|
*
|
|
3836
|
-
*
|
|
3837
|
-
*
|
|
3838
|
-
*
|
|
3839
|
-
*
|
|
3840
|
-
*
|
|
3841
|
-
*
|
|
5183
|
+
* Each probe runs concurrently and is guarded on its own, so a missing boundary, a
|
|
5184
|
+
* rejection or a timeout is an `unverifiable` warning row. Rows are
|
|
5185
|
+
* `blocking: false` and NEVER change the decision, a refusal, readiness or the
|
|
5186
|
+
* exit code. An `attach`, refused or stopped preview gets none of them. The merged
|
|
5187
|
+
* `worker-db-role` warning row is decorated in place rather than duplicated. When
|
|
5188
|
+
* the project's configuration says the database does not apply (or was not
|
|
5189
|
+
* reported), the role row is `not_applicable`: the same rule as the boundary row.
|
|
3842
5190
|
*/
|
|
3843
|
-
async function appendLaunchNeedRows(deps, preview, observed, workerDatabase) {
|
|
5191
|
+
async function appendLaunchNeedRows(deps, preview, observed, workerDatabase, applicability) {
|
|
3844
5192
|
if (preview.decision !== "create")
|
|
3845
5193
|
return;
|
|
3846
5194
|
try {
|
|
3847
5195
|
const repoRoot = observed.repository?.repoRoot ?? deps.cwd();
|
|
3848
5196
|
const local = preview.target.kind === "local_plane";
|
|
3849
5197
|
const readiness = observed.readiness;
|
|
3850
|
-
const access = observed.access;
|
|
3851
|
-
const nowMs = (deps.now ?? Date.now)();
|
|
3852
5198
|
const durations = [];
|
|
3853
5199
|
const measured = (index, work) => measurePrecheck(work, (duration) => { durations[index] = duration; });
|
|
3854
|
-
const [runner, power
|
|
5200
|
+
const [runner, power] = await Promise.all([
|
|
3855
5201
|
measured(0, () => guardedProbe(deps.inspectRequiredRunners === undefined
|
|
3856
5202
|
? undefined
|
|
3857
5203
|
: () => deps.inspectRequiredRunners({
|
|
@@ -3860,32 +5206,18 @@ async function appendLaunchNeedRows(deps, preview, observed, workerDatabase) {
|
|
|
3860
5206
|
gateProfile: readiness?.gate_profile,
|
|
3861
5207
|
}), { state: "unverifiable", reason: "probe_failed" })),
|
|
3862
5208
|
measured(1, () => guardedProbe(() => collectHostPowerFact(deps, observed.launchTopology), { state: "unverifiable", reason: "probe_failed" })),
|
|
3863
|
-
measured(2, () => guardedProbe(deps.fetchUsageAdvisory === undefined || access === undefined
|
|
3864
|
-
? undefined
|
|
3865
|
-
: () => deps.fetchUsageAdvisory(access), null)),
|
|
3866
|
-
measured(3, () => guardedProbe(deps.inspectEpicBranchBehind === undefined
|
|
3867
|
-
? undefined
|
|
3868
|
-
: () => deps.inspectEpicBranchBehind({
|
|
3869
|
-
repoRoot,
|
|
3870
|
-
branch: preview.summary.branch,
|
|
3871
|
-
baseBranch: previewScopeBaseBranch.get(preview) ?? null,
|
|
3872
|
-
}), preview.summary.branch === null
|
|
3873
|
-
? { state: "not_applicable", reason: "no_epic_branch" }
|
|
3874
|
-
: { state: "unverifiable", reason: "git_failed" })),
|
|
3875
5209
|
]);
|
|
3876
|
-
|
|
3877
|
-
|
|
5210
|
+
// BAPI-1613 R6: a cold start has no readiness yet; that is not a non-Bridge checkout.
|
|
5211
|
+
const skipRow = applicability.kind === "unproven" && observed.repository?.isBridge !== false
|
|
5212
|
+
? { ...nonBridgeRows(["worker-db-role"])[0], reason: "readiness_unknown", detail: "readiness_unknown" }
|
|
5213
|
+
: nonBridgeRows(["worker-db-role"])[0];
|
|
5214
|
+
const workerRow = applicability.kind !== "inspect"
|
|
5215
|
+
? { ...skipRow, launch_need: { need: "worker_db_role", state: "not_applicable", asked: false } }
|
|
3878
5216
|
: { ...buildWorkerDbRoleLaunchRow(workerDatabase, local),
|
|
3879
5217
|
duration_ms: workerDatabase?.rows.find((row) => row.id === "worker-db-role")?.duration_ms ?? elapsedMs(monotonicNow()) };
|
|
3880
5218
|
const rows = [
|
|
3881
5219
|
buildSelfHostedRunnerLaunchRow(runner),
|
|
3882
5220
|
buildHostPowerLaunchRow(power),
|
|
3883
|
-
buildUsageResetAfterRunLaunchRow({
|
|
3884
|
-
advisory: usage ?? REPOSITORY_USAGE_ADVISORY_UNAVAILABLE,
|
|
3885
|
-
childCount: preview.summary.child_count,
|
|
3886
|
-
nowMs,
|
|
3887
|
-
}),
|
|
3888
|
-
buildEpicBranchBehindBaseLaunchRow(branch),
|
|
3889
5221
|
].map((row, index) => ({ ...row, duration_ms: durations[index] }));
|
|
3890
5222
|
const existing = preview.launch_checks ?? [];
|
|
3891
5223
|
const roleIndex = existing.findIndex((row) => row.id === workerRow.id);
|
|
@@ -3966,6 +5298,8 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
3966
5298
|
return;
|
|
3967
5299
|
}
|
|
3968
5300
|
const access = accessResult.access;
|
|
5301
|
+
observed.repoName = access.repoName;
|
|
5302
|
+
observed.contextAccess = access;
|
|
3969
5303
|
const profile = accessResult.profile ?? null;
|
|
3970
5304
|
const endpoint = planeEndpointForBaseUrl(deps, access.baseUrl);
|
|
3971
5305
|
const planeTarget = endpoint !== null;
|
|
@@ -3976,7 +5310,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
3976
5310
|
? { source: accessResult.targetSource }
|
|
3977
5311
|
: {}),
|
|
3978
5312
|
};
|
|
3979
|
-
|
|
5313
|
+
let ctx = {
|
|
3980
5314
|
deps,
|
|
3981
5315
|
epicKey,
|
|
3982
5316
|
options,
|
|
@@ -3986,6 +5320,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
3986
5320
|
targetSource: accessResult.targetSource ?? "default",
|
|
3987
5321
|
freshness: createPlaneFreshnessCache(),
|
|
3988
5322
|
launchCredential: {},
|
|
5323
|
+
liveObservation: {},
|
|
3989
5324
|
};
|
|
3990
5325
|
// Discover before readiness so a selected local plane can preview its guarded
|
|
3991
5326
|
// cold start. Keep the candidate out of ordinary failure documents.
|
|
@@ -3993,6 +5328,9 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
3993
5328
|
let plan = { status: "not_found" };
|
|
3994
5329
|
// The full discovery result, kept for the guarded plane-down stop below.
|
|
3995
5330
|
let discovery = null;
|
|
5331
|
+
// BAPI-1621 — why automatic generation stopped, and whether it read "no live run".
|
|
5332
|
+
let generationReason;
|
|
5333
|
+
let generatedLiveRunChecked = false;
|
|
3996
5334
|
let docsRootUnresolved = false;
|
|
3997
5335
|
if (planPath !== undefined) {
|
|
3998
5336
|
plan = { status: "supplied", path: planPath };
|
|
@@ -4014,16 +5352,69 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
4014
5352
|
: {}),
|
|
4015
5353
|
epic_plans_dir: discovered.epic_plans_dir,
|
|
4016
5354
|
};
|
|
4017
|
-
if (discovered.status === "found")
|
|
5355
|
+
if (discovered.status === "found") {
|
|
4018
5356
|
planPath = discovered.path;
|
|
5357
|
+
// BAPI-1621 — a found GENERATED plan shows its provenance from the files
|
|
5358
|
+
// already on disk; an authored plan's preview is unchanged.
|
|
5359
|
+
if (discovered.generated !== undefined) {
|
|
5360
|
+
plan.generated = true;
|
|
5361
|
+
const nodes = await readGeneratedPlanNodes(deps, discovered.path);
|
|
5362
|
+
if (nodes !== null)
|
|
5363
|
+
plan.generation = { nodes, summary: discovered.generated.summary };
|
|
5364
|
+
}
|
|
5365
|
+
}
|
|
5366
|
+
else if (discovered.status === "plan_not_found" && deps.attemptPlanGeneration !== undefined) {
|
|
5367
|
+
// BAPI-1621 — build in memory only. The preview writes no folder, staging
|
|
5368
|
+
// directory, temporary file, metadata, or DAG.
|
|
5369
|
+
if (!(await planGenerationAllowed(deps.discoveryFs, epicKey, discovered))) {
|
|
5370
|
+
generationReason = "discovery_blocked";
|
|
5371
|
+
}
|
|
5372
|
+
else {
|
|
5373
|
+
const attempt = await deps.attemptPlanGeneration(epicKey).catch(() => ({ kind: "failed", reason: "children_unreadable" }));
|
|
5374
|
+
if (attempt.kind === "failed") {
|
|
5375
|
+
generationReason = attempt.reason;
|
|
5376
|
+
}
|
|
5377
|
+
else if (attempt.kind === "generated" &&
|
|
5378
|
+
!(await planGenerationAllowed(deps.discoveryFs, epicKey, discovered, attempt))) {
|
|
5379
|
+
generationReason = "discovery_blocked";
|
|
5380
|
+
}
|
|
5381
|
+
else if (attempt.kind === "generated") {
|
|
5382
|
+
const folder = generatedPlanFolder(docs.docsDir, epicKey);
|
|
5383
|
+
planPath = path.join(folder, "epic-plan.dag.json");
|
|
5384
|
+
plan = {
|
|
5385
|
+
status: "generated",
|
|
5386
|
+
generated: true,
|
|
5387
|
+
inline: { nodes: attempt.dag.nodes, summary: attempt.summary },
|
|
5388
|
+
would_write: folder,
|
|
5389
|
+
...(plan.skipped !== undefined ? { skipped: plan.skipped } : {}),
|
|
5390
|
+
epic_plans_dir: discovered.epic_plans_dir,
|
|
5391
|
+
};
|
|
5392
|
+
generatedLiveRunChecked = true;
|
|
5393
|
+
ctx = { ...ctx, deps: withInlinePlan(ctx.deps, planPath, JSON.stringify(attempt.dag, null, 2) + "\n") };
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
if (generationReason !== undefined)
|
|
5397
|
+
plan.generation_failure = generationReason;
|
|
5398
|
+
}
|
|
4019
5399
|
}
|
|
4020
5400
|
}
|
|
4021
5401
|
// Every later exit, refusal or not, reports the plan state as discovered.
|
|
4022
5402
|
preview.plan = plan;
|
|
4023
5403
|
// --- Readiness. -----------------------------------------------------------
|
|
4024
|
-
|
|
5404
|
+
// BAPI-1593 — ONE acquisition for this preview: at most two full reads. The
|
|
5405
|
+
// first failure is inspected on its own (a refused plane port is a cold start);
|
|
5406
|
+
// anything else spends the one retry, and a second uncertain read warns and
|
|
5407
|
+
// continues rather than refusing.
|
|
5408
|
+
const previewAcquisition = createReadinessAcquisition(() => deps.readReadiness(access), {
|
|
5409
|
+
...(deps.launchSleep !== undefined ? { sleep: deps.launchSleep } : {}),
|
|
5410
|
+
});
|
|
5411
|
+
observed.acquisition = previewAcquisition;
|
|
5412
|
+
let readiness = null;
|
|
4025
5413
|
try {
|
|
4026
|
-
|
|
5414
|
+
const first = await previewAcquisition.firstAttempt();
|
|
5415
|
+
if (first.kind !== "ready")
|
|
5416
|
+
throw first.error;
|
|
5417
|
+
readiness = first.readiness;
|
|
4027
5418
|
}
|
|
4028
5419
|
catch (err) {
|
|
4029
5420
|
if (isSchemaIncompatibleError(err)) {
|
|
@@ -4062,7 +5453,11 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
4062
5453
|
preview.readiness = { kind: "cold_start" };
|
|
4063
5454
|
await finalizeCreatePreview(ctx, preview, planPath, true, refuseTopLevel);
|
|
4064
5455
|
if (preview.decision === "create") {
|
|
4065
|
-
preview.cold_start = {
|
|
5456
|
+
preview.cold_start = {
|
|
5457
|
+
plane_endpoint: access.baseUrl,
|
|
5458
|
+
will_start_plane: true,
|
|
5459
|
+
live_run_checked: generatedLiveRunChecked,
|
|
5460
|
+
};
|
|
4066
5461
|
}
|
|
4067
5462
|
// No plane exists yet, so there is no snapshot or database to compare;
|
|
4068
5463
|
// the host-sleep advisory still applies to the plane about to start.
|
|
@@ -4087,27 +5482,62 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
4087
5482
|
if (probe.kind === "refused") {
|
|
4088
5483
|
preview.readiness = {
|
|
4089
5484
|
kind: "unknown",
|
|
4090
|
-
remedy: planeDownNoPlanStopText(epicKey, { profile, options }, discovery),
|
|
5485
|
+
remedy: planeDownNoPlanStopText(epicKey, { profile, options }, discovery, generationReason),
|
|
4091
5486
|
};
|
|
4092
5487
|
preview.refusal = null;
|
|
4093
5488
|
preview.decision = "stop";
|
|
4094
5489
|
return;
|
|
4095
5490
|
}
|
|
4096
5491
|
}
|
|
4097
|
-
|
|
5492
|
+
const settled = await previewAcquisition.result();
|
|
5493
|
+
if (settled.kind === "refused") {
|
|
5494
|
+
return refuseTopLevel({
|
|
5495
|
+
reasonId: "schema-incompatible",
|
|
5496
|
+
remedy: "Local schema incompatible: launch-critical schema objects are missing. " +
|
|
5497
|
+
`${SCHEMA_INCOMPATIBLE_REPAIR_ROUTE} Nothing was created or started.`,
|
|
5498
|
+
});
|
|
5499
|
+
}
|
|
5500
|
+
if (settled.kind === "ready")
|
|
5501
|
+
readiness = settled.readiness;
|
|
5502
|
+
}
|
|
5503
|
+
if (readiness === null) {
|
|
5504
|
+
// BAPI-1593 — unknown readiness is a warning, not a refusal: the launch would
|
|
5505
|
+
// continue to the server's create and approve. Only the decisions that need
|
|
5506
|
+
// no readiness report are previewed: the live-run read, and setup's own dry run.
|
|
5507
|
+
preview.readiness = { kind: "unknown", warning: READINESS_UNKNOWN_CONTINUING_WARNING };
|
|
5508
|
+
if (docsRootUnresolved)
|
|
5509
|
+
return refuseTopLevel(docsRootRefusal(epicKey));
|
|
5510
|
+
const unknownLive = await acquireObservedLive(ctx);
|
|
5511
|
+
if (unknownLive.kind === "conflict")
|
|
5512
|
+
return refuseTopLevel(liveRunAmbiguousRefusal(epicKey));
|
|
5513
|
+
if (unknownLive.kind === "unknown")
|
|
5514
|
+
(preview.warnings ??= []).push(LIVE_RUN_UNKNOWN_WARNING);
|
|
5515
|
+
if (unknownLive.kind === "live") {
|
|
5516
|
+
preview.live_run = { epic_run_id: unknownLive.epicRunId, status: unknownLive.status };
|
|
5517
|
+
if (options.planFile === undefined) {
|
|
5518
|
+
preview.decision = "attach";
|
|
5519
|
+
return;
|
|
5520
|
+
}
|
|
5521
|
+
}
|
|
5522
|
+
if (planPath === undefined) {
|
|
5523
|
+
preview.decision = "stop";
|
|
5524
|
+
return;
|
|
5525
|
+
}
|
|
5526
|
+
await finalizeCreatePreview(ctx, preview, planPath, false, refuseTopLevel, true);
|
|
5527
|
+
return;
|
|
4098
5528
|
}
|
|
4099
5529
|
observed.readiness = readiness;
|
|
4100
5530
|
if (docsRootUnresolved)
|
|
4101
5531
|
return refuseTopLevel(docsRootRefusal(epicKey));
|
|
4102
|
-
const live = await
|
|
5532
|
+
const live = await acquireObservedLive(ctx);
|
|
4103
5533
|
if (live.kind === "conflict")
|
|
4104
5534
|
return refuseTopLevel(liveRunAmbiguousRefusal(epicKey));
|
|
4105
5535
|
if (live.kind === "unknown")
|
|
4106
|
-
|
|
5536
|
+
(preview.warnings ??= []).push(LIVE_RUN_UNKNOWN_WARNING);
|
|
4107
5537
|
// BAPI-1532 — a DISCOVERED plan beside a live run is unused: the launch attaches,
|
|
4108
5538
|
// so the effective plan path is cleared while the preview still reports the plan
|
|
4109
5539
|
// as found. An explicit --plan-file keeps its create-path behavior unchanged.
|
|
4110
|
-
const attachingDiscoveredPlan = options.planFile === undefined && plan.status === "found" && live.kind === "live";
|
|
5540
|
+
const attachingDiscoveredPlan = options.planFile === undefined && (plan.status === "found" || plan.status === "generated") && live.kind === "live";
|
|
4111
5541
|
const effectivePlanPath = attachingDiscoveredPlan ? undefined : planPath;
|
|
4112
5542
|
const previewCtx = { ...ctx, options: { ...options, ...(effectivePlanPath ? { planFile: effectivePlanPath } : {}) } };
|
|
4113
5543
|
const observations = {
|
|
@@ -4130,6 +5560,9 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
4130
5560
|
approvedStoredPolicy: live.kind === "live" && !effectivePlanPath,
|
|
4131
5561
|
});
|
|
4132
5562
|
preview.readiness = { kind: classification.kind };
|
|
5563
|
+
if (mandatoryDiagnosticsUncertain(readiness.diagnostics)) {
|
|
5564
|
+
(preview.warnings ??= []).push(MANDATORY_DIAGNOSTIC_UNKNOWN_WARNING);
|
|
5565
|
+
}
|
|
4133
5566
|
if (classification.kind === 'operator_blocked') {
|
|
4134
5567
|
const requirement = V2_READINESS_REQUIREMENTS.find(req => req.id === classification.id);
|
|
4135
5568
|
if (requirement)
|
|
@@ -4143,6 +5576,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
|
|
|
4143
5576
|
if (live.effectivePolicy) {
|
|
4144
5577
|
preview.summary.policy_source = live.effectivePolicy.source;
|
|
4145
5578
|
preview.summary.serial_execution = live.effectivePolicy.serial_execution;
|
|
5579
|
+
preview.summary.parallel_limit = live.effectivePolicy.parallel_limit;
|
|
4146
5580
|
preview.summary.caps = live.effectivePolicy.caps;
|
|
4147
5581
|
preview.summary.job_timeouts = live.effectivePolicy.job_timeouts;
|
|
4148
5582
|
preview.summary.escalation_channel_label = live.effectivePolicy.escalation_channel;
|
|
@@ -4231,12 +5665,13 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
|
|
|
4231
5665
|
? "webhook"
|
|
4232
5666
|
: prepared.handoff.selection.escalationChannel === "account email" ? "email" : null;
|
|
4233
5667
|
}
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
// declared paths nor target topology can establish repository identity.
|
|
4237
|
-
preview.plan_database_relevance = "unknown";
|
|
4238
|
-
preview.summary.child_count = await readPlanChildCount(deps, planPath);
|
|
5668
|
+
const planChildren = await readPlanDagChildren(deps, planPath);
|
|
5669
|
+
preview.summary.child_count = planChildren?.count ?? null;
|
|
4239
5670
|
preview.summary.children_to_run = preview.summary.child_count;
|
|
5671
|
+
// A key list is trusted only when it names every node; a partial list would shrink membership.
|
|
5672
|
+
if (planChildren !== null && planChildren.keys.length === planChildren.count) {
|
|
5673
|
+
previewPlanChildKeys.set(preview, planChildren.keys);
|
|
5674
|
+
}
|
|
4240
5675
|
// BAPI-1510 — the already-merged check, after plan discovery and BEFORE the
|
|
4241
5676
|
// setup dry run, so the dry run validates the plan a real create would submit.
|
|
4242
5677
|
// An attach, a disabled check, and a cold start (no plane to ask yet) classify
|
|
@@ -4311,18 +5746,22 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
|
|
|
4311
5746
|
preview.summary.branch = payload.featureBranch;
|
|
4312
5747
|
if (payload.scopeBaseBranch !== null)
|
|
4313
5748
|
previewScopeBaseBranch.set(preview, payload.scopeBaseBranch);
|
|
5749
|
+
if (payload.serverPlanHash !== null)
|
|
5750
|
+
previewServerPlanDigest.set(preview, payload.serverPlanHash);
|
|
4314
5751
|
preview.summary.ticket_review = payload.ticketReview;
|
|
4315
5752
|
if (payload.launchReadiness) {
|
|
4316
5753
|
preview.prerequisites = payload.launchReadiness.prerequisites;
|
|
4317
5754
|
preview.is_production = payload.launchReadiness.is_production;
|
|
4318
5755
|
const launch = classifyV2Readiness(payload.launchReadiness, { attended: options.attended, intoBase: options.intoBase });
|
|
4319
5756
|
if (launch.kind === 'operator_blocked')
|
|
4320
|
-
return refuseTopLevel({ reasonId: launch.id, remedy: launch.remedy ?? 'Retry readiness.' });
|
|
5757
|
+
return refuseTopLevel({ reasonId: launch.id, remedy: launch.remedy ?? 'Retry readiness.', authoritative: true });
|
|
4321
5758
|
}
|
|
4322
5759
|
if (payload.effectivePolicy) {
|
|
4323
5760
|
const facts = payload.effectivePolicy;
|
|
4324
5761
|
preview.summary.policy_source = facts.source;
|
|
4325
5762
|
preview.summary.serial_execution = facts.serial_execution;
|
|
5763
|
+
if (facts.parallel_limit !== undefined)
|
|
5764
|
+
preview.summary.parallel_limit = facts.parallel_limit;
|
|
4326
5765
|
preview.summary.caps = facts.caps;
|
|
4327
5766
|
preview.summary.job_timeouts = facts.job_timeouts;
|
|
4328
5767
|
preview.summary.escalation_channel_label = facts.escalation_channel;
|
|
@@ -4331,8 +5770,27 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
|
|
|
4331
5770
|
preview.summary.escalation_channel = facts.escalation_channel === "configured webhook"
|
|
4332
5771
|
? "webhook" : facts.escalation_channel === "account email" ? "email" : null;
|
|
4333
5772
|
}
|
|
4334
|
-
|
|
4335
|
-
|
|
5773
|
+
// BAPI-1601 — one intent result drives the summary, the printed line, and the
|
|
5774
|
+
// compatibility scope, so they cannot disagree. An absent or unusable
|
|
5775
|
+
// `create_policy` is `unavailable` — never `off`, and never an invented scope.
|
|
5776
|
+
const epicBranch = payload.featureBranch ?? undefined;
|
|
5777
|
+
let intent;
|
|
5778
|
+
if (payload.createPolicy.kind === "present") {
|
|
5779
|
+
intent = resolveSetupEpicAutoMergeIntent(payload.createPolicy.policy, {
|
|
5780
|
+
epicBranch,
|
|
5781
|
+
attended: options.attended === true,
|
|
5782
|
+
});
|
|
5783
|
+
// A present envelope with no usable boolean is not "older output".
|
|
5784
|
+
if (intent.state === "unavailable")
|
|
5785
|
+
previewAutoMergeUnavailableReason.set(preview, "invalid");
|
|
5786
|
+
}
|
|
5787
|
+
else {
|
|
5788
|
+
intent = { state: "unavailable" };
|
|
5789
|
+
previewAutoMergeUnavailableReason.set(preview, payload.createPolicy.kind === "absent" ? "older" : "invalid");
|
|
5790
|
+
}
|
|
5791
|
+
preview.summary.auto_merge =
|
|
5792
|
+
intent.state === "off" ? { state: "off", reason: intent.reason } : { state: intent.state };
|
|
5793
|
+
preview.summary.auto_merge_scope = intent.state === "on" ? payload.featureBranch : null;
|
|
4336
5794
|
// The bootstrap reusing a run IS an attach: it reports the run's id.
|
|
4337
5795
|
if (payload.existingRunId !== null) {
|
|
4338
5796
|
// Existing runs are never trimmed: report the check as not applied.
|
|
@@ -4400,14 +5858,20 @@ async function applyPreviewFreshness(ctx, preview, topology, coldStart) {
|
|
|
4400
5858
|
const sleep = preview.decision === "attach" ? await collectHostSleep(ctx, own.repoRoot) : null;
|
|
4401
5859
|
// Read-only: one run-state read, local plane only, and only for a bound plane.
|
|
4402
5860
|
const boundRun = await boundRunForStaleRemedy(ctx, own, reports);
|
|
4403
|
-
|
|
5861
|
+
// BAPI-1651: create's cleanup also refuses while another run is live on the
|
|
5862
|
+
// plane, so ask the same read-only question before promising it.
|
|
5863
|
+
const otherLive = preview.decision === "create" && boundRun !== undefined && isTerminalRunCleanupStatus(boundRun.status)
|
|
5864
|
+
? await readOtherLiveRun(deps.listLiveRunIds ?? (async () => null), ctx.access, boundRun.epicRunId)
|
|
5865
|
+
: null;
|
|
5866
|
+
const assessment = assessPlaneFreshness(reports, sleep, preview.decision === "create" ? "create" : "attach", ctx.options.allowStalePlane === true, boundRun, otherLive);
|
|
4404
5867
|
if (assessment.rows.length > 0) {
|
|
4405
5868
|
preview.launch_checks = [...(preview.launch_checks ?? []), ...assessment.rows];
|
|
4406
5869
|
}
|
|
4407
5870
|
const refusal = freshnessRefusalOf(assessment.blockers);
|
|
4408
5871
|
if (refusal !== null) {
|
|
4409
5872
|
preview.decision = "refuse";
|
|
4410
|
-
|
|
5873
|
+
// BAPI-1596: a freshness blocker is proven (a stale plane or a database behind head).
|
|
5874
|
+
preview.refusal = { reason_id: refusal.reasonId, remedy: refusal.remedy, authoritative: true };
|
|
4411
5875
|
}
|
|
4412
5876
|
}
|
|
4413
5877
|
catch {
|
|
@@ -4498,6 +5962,15 @@ function reachabilityLines(preview) {
|
|
|
4498
5962
|
const row = preview.launch_checks?.find((entry) => entry.id === ESCALATION_REACHABILITY_CHECK_ID);
|
|
4499
5963
|
if (row === undefined)
|
|
4500
5964
|
return [];
|
|
5965
|
+
// BAPI-1595 — the confirmed "no reachable channel" line appears only when both
|
|
5966
|
+
// facts are established. An unestablished one shows the fixed uncertainty warning
|
|
5967
|
+
// instead, and an unremarkable one shows nothing.
|
|
5968
|
+
const presentation = previewEscalationPresentation.get(preview);
|
|
5969
|
+
if (presentation === "uncertain") {
|
|
5970
|
+
return [` WARN ${ESCALATION_REACHABILITY_CHECK_ID}`, ` ${ESCALATION_CHANNEL_UNCERTAIN_WARNING}`];
|
|
5971
|
+
}
|
|
5972
|
+
if (presentation === "omitted")
|
|
5973
|
+
return [];
|
|
4501
5974
|
return [
|
|
4502
5975
|
` ${row.status === "pass" ? "PASS" : "WARN"} ${ESCALATION_REACHABILITY_CHECK_ID}`,
|
|
4503
5976
|
...(row.detail ? [` ${row.detail}`] : []),
|
|
@@ -4516,7 +5989,7 @@ const UNKNOWN_REASON_TEXT = {
|
|
|
4516
5989
|
const NOT_CHECKED_TEXT = {
|
|
4517
5990
|
disabled: "Merged check: turned off (--no-merged-check). Every child will run.",
|
|
4518
5991
|
attach: "Merged check: not applied; existing runs are unchanged.",
|
|
4519
|
-
cold_start: "Merged check: will be checked at create.",
|
|
5992
|
+
cold_start: "Merged check: will be checked at create. Already-merged children will be skipped; pass --keep-child <KEY> to keep one.",
|
|
4520
5993
|
cut_commit_unavailable: "Merged check: the indexed commit could not be read. Every child will run.",
|
|
4521
5994
|
check_failed: "Merged check: could not complete. Every child will run.",
|
|
4522
5995
|
no_plan: null,
|
|
@@ -4526,7 +5999,7 @@ const NOT_CHECKED_TEXT = {
|
|
|
4526
5999
|
* children to run and skipped, then the groups in a fixed order. Meaning is carried
|
|
4527
6000
|
* by words, never colour; only customer ticket keys and validated PR numbers appear.
|
|
4528
6001
|
*/
|
|
4529
|
-
function alreadyDoneLines(preview) {
|
|
6002
|
+
export function alreadyDoneLines(preview) {
|
|
4530
6003
|
const s = preview.summary;
|
|
4531
6004
|
const state = preview.already_done_children ?? { status: "not_checked", reason: "no_plan", children: [] };
|
|
4532
6005
|
const lines = [];
|
|
@@ -4552,8 +6025,14 @@ function alreadyDoneLines(preview) {
|
|
|
4552
6025
|
: "";
|
|
4553
6026
|
if (skipped.length > 0) {
|
|
4554
6027
|
lines.push(" Skipped (already merged):");
|
|
4555
|
-
|
|
4556
|
-
|
|
6028
|
+
const confirmedMerged = skipped.filter((child) => child.classification === "done");
|
|
6029
|
+
for (const child of confirmedMerged) {
|
|
6030
|
+
lines.push(` already merged, will skip: ${child.ticket_key}${pr(child)}`);
|
|
6031
|
+
}
|
|
6032
|
+
if (confirmedMerged.length > 0)
|
|
6033
|
+
lines.push(" To keep one, pass --keep-child <KEY>.");
|
|
6034
|
+
for (const child of skipped.filter((entry) => entry.classification !== "done")) {
|
|
6035
|
+
lines.push(` ${child.ticket_key}${pr(child)} — confirmed skip`);
|
|
4557
6036
|
}
|
|
4558
6037
|
}
|
|
4559
6038
|
const probably = state.children.filter((child) => child.classification === "probably_done" && !child.will_skip);
|
|
@@ -4590,6 +6069,32 @@ function alreadyDoneLines(preview) {
|
|
|
4590
6069
|
}
|
|
4591
6070
|
return lines;
|
|
4592
6071
|
}
|
|
6072
|
+
/** The v2 plan as plain lines: the same document the session renders, never recomputed here. */
|
|
6073
|
+
function launchPlanLines(plan) {
|
|
6074
|
+
const lines = [" Launch plan:", ` ${plan.summary}`, ` Recommended: ${plan.recommendation}`, ` Why: ${plan.reason}`];
|
|
6075
|
+
const groups = [
|
|
6076
|
+
["Blocks the launch", plan.items.blocks_launch],
|
|
6077
|
+
["Needs your choice", plan.items.needs_choice],
|
|
6078
|
+
["Worth knowing", plan.items.worth_knowing],
|
|
6079
|
+
];
|
|
6080
|
+
for (const [title, entries] of groups) {
|
|
6081
|
+
if (entries.length === 0)
|
|
6082
|
+
continue;
|
|
6083
|
+
lines.push(` ${title}:`);
|
|
6084
|
+
for (const entry of entries) {
|
|
6085
|
+
lines.push(` - ${entry.summary}`, ` ${entry.reason}`);
|
|
6086
|
+
if (entry.remedy)
|
|
6087
|
+
lines.push(` Fix: ${entry.remedy}`);
|
|
6088
|
+
}
|
|
6089
|
+
}
|
|
6090
|
+
lines.push(" Your options:");
|
|
6091
|
+
for (const option of plan.options) {
|
|
6092
|
+
lines.push(` ${option.number}. ${option.label}${option.recommended ? " (as recommended)" : ""}. ${option.description} ${option.duration}`);
|
|
6093
|
+
}
|
|
6094
|
+
if (plan.local_handoff)
|
|
6095
|
+
lines.push(` ${plan.local_handoff}`);
|
|
6096
|
+
return lines;
|
|
6097
|
+
}
|
|
4593
6098
|
/**
|
|
4594
6099
|
* Print the preview: one JSON line with `--json`, short readable lines otherwise.
|
|
4595
6100
|
*
|
|
@@ -4619,22 +6124,22 @@ async function emitPreview(deps, options, preview) {
|
|
|
4619
6124
|
? "Found, unused"
|
|
4620
6125
|
: preview.plan.status}${preview.plan.path ? ` — ${preview.plan.path}` : ""}`,
|
|
4621
6126
|
];
|
|
6127
|
+
// BAPI-1621 — generated provenance and a stopped generation, in plain words.
|
|
6128
|
+
if (preview.plan.generated === true) {
|
|
6129
|
+
lines.push(preview.plan.status === "generated"
|
|
6130
|
+
? ` GENERATED — built from current epic children; not written by this preview. A launch saves it to ${preview.plan.would_write ?? "the generated plan folder"}.`
|
|
6131
|
+
: " GENERATED — built from epic children by drive-epic.");
|
|
6132
|
+
}
|
|
6133
|
+
if (preview.plan.generation_failure !== undefined) {
|
|
6134
|
+
lines.push(` generation: stopped (${preview.plan.generation_failure}) — ${PLAN_GENERATION_FAILURE_TEXT[preview.plan.generation_failure]}`);
|
|
6135
|
+
}
|
|
4622
6136
|
for (const candidate of preview.plan.candidates ?? [])
|
|
4623
6137
|
lines.push(` candidate: ${candidate}`);
|
|
4624
6138
|
for (const skipped of preview.plan.skipped ?? []) {
|
|
4625
6139
|
lines.push(` skipped: ${skipped.path} (${skipped.reason})`);
|
|
4626
6140
|
}
|
|
4627
6141
|
const s = preview.summary;
|
|
4628
|
-
lines.push(` Ticket review: ${s.ticket_review ?? "on"}`, ` Posture: ${s.posture ?? "n/a"}`, ` Children: ${s.child_count ?? "n/a"}`, ...alreadyDoneLines(preview), ` Branch: ${s.branch ?? "n/a"}`, `
|
|
4629
|
-
" Launch plan (advisory):",
|
|
4630
|
-
...(preview.launch_plan.items.length === 0 ? [" There are no pending decisions"] :
|
|
4631
|
-
preview.launch_plan.items.flatMap((item) => [
|
|
4632
|
-
` ${item.summary} (${item.id}): ${item.recommendation}`,
|
|
4633
|
-
` ${item.reason}`,
|
|
4634
|
-
...(item.remedy ? [` Remedy: ${item.remedy}`] : []),
|
|
4635
|
-
...(item.recommendation === "fix first" ? [" Launch anyway accepts the unresolved risk; no remediation is performed."] : []),
|
|
4636
|
-
])),
|
|
4637
|
-
] : []), ` Validation: ${preview.cold_start ? "Partial — plane is not yet running" : s.server_validation ?? "n/a"}`, ` Decision: ${preview.decision}`);
|
|
6142
|
+
lines.push(` Ticket review: ${s.ticket_review ?? "on"}`, ` Posture: ${s.posture ?? "n/a"}`, ` Parallel limit: ${s.parallel_limit === undefined ? "unavailable" : s.parallel_limit === "server_default" ? "server default" : s.parallel_limit}`, ` ${PARALLEL_LIMIT_MEANING_COPY}`, ` ${PARALLEL_LIMIT_CHANGE_ADVISORY}`, ` Children: ${s.child_count ?? "n/a"}`, ...alreadyDoneLines(preview), ` Branch: ${s.branch ?? "n/a"}`, autoMergeLine(preview), ` Escalation: ${s.escalation_channel ?? "n/a"}`, ...reachabilityLines(preview), ...(preview.launch_plan ? launchPlanLines(preview.launch_plan) : []), ` Validation: ${preview.cold_start ? "Partial — plane is not yet running" : s.server_validation ?? "n/a"}`, ` Decision: ${preview.decision}`);
|
|
4638
6143
|
if (isPlaneDownStop(preview)) {
|
|
4639
6144
|
// The shared stop text, verbatim and unindented, so it reads exactly as the
|
|
4640
6145
|
// real launch prints it. It is a stop, not a refusal.
|
|
@@ -4648,13 +6153,9 @@ async function emitPreview(deps, options, preview) {
|
|
|
4648
6153
|
if (preview.refusal && preview.refusal.reason_id !== EPIC_ALREADY_COMPLETE_REASON_ID) {
|
|
4649
6154
|
lines.push(` Refusal: ${preview.refusal.reason_id} — ${preview.refusal.remedy}`);
|
|
4650
6155
|
}
|
|
6156
|
+
// BAPI-1596 — no "Not ready: N blocking" summary on the launch preview: the plan above
|
|
6157
|
+
// carries the verdict. The readiness command keeps its own text report.
|
|
4651
6158
|
const summaryRows = (preview.launch_checks ?? []).filter(row => row.id !== ESCALATION_REACHABILITY_CHECK_ID);
|
|
4652
|
-
lines.unshift(...formatLaunchReadinessSummary(summaryRows.map(row => ({
|
|
4653
|
-
id: row.id, source: row.id.startsWith('server.') ? 'server' : 'conductor',
|
|
4654
|
-
label: row.label, status: row.status, blocking: row.blocking,
|
|
4655
|
-
...(row.detail ? { detail: row.detail } : {}),
|
|
4656
|
-
...(row.remedy ? { remediation: row.remedy } : {}),
|
|
4657
|
-
})), { all: options.all, isProduction: preview.is_production, prerequisites: preview.prerequisites }));
|
|
4658
6159
|
const localRows = summaryRows.filter(row => !READINESS_PREREQUISITE_BY_ID.has(READINESS_LEGACY_IDS[row.id] ?? row.id));
|
|
4659
6160
|
// BAPI-1506: launch-need rows get their own heading; they are not plane freshness.
|
|
4660
6161
|
const freshnessRows = localRows.filter(row => row.launch_need === undefined);
|