@bridge_gpt/mcp-server 0.2.72 → 0.2.74
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 +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -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/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -21
- 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-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -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 +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -15
- 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-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -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/completion-contract.js +8 -1
- package/build/executor/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -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-invoke.js +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- 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 +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +63 -2
- package/build/ticket-delivery-enrollment.js +9 -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/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -150,16 +150,56 @@ export function getConductorUsage() {
|
|
|
150
150
|
" current digest (from the PR report or explain-run). Never run by the",
|
|
151
151
|
" driver or a worker; it verifies, readies and merges nothing.",
|
|
152
152
|
" wait-run --epic-run-id <id> [--ticket-key <key>] [--since <token>] [--timeout <seconds>]",
|
|
153
|
-
" [--until change|attention] [--json]",
|
|
153
|
+
" [--until change|attention] [--json] [--watch [--max-minutes <minutes>]]",
|
|
154
154
|
" Read-only: wait until the run's observable state changes, the run finishes,",
|
|
155
155
|
" or the window closes (default 110 s; values above 240 are clamped to 240).",
|
|
156
156
|
" --until attention wakes only when a new incident appears (a park, a",
|
|
157
157
|
" needs-human reason, a failed job, a paused/stopped or non-active run).",
|
|
158
|
+
" --watch repeats attention windows under one deadline (--max-minutes,",
|
|
159
|
+
" default 20, at most 60) and prints one result.",
|
|
158
160
|
" Pass the previous result's token as --since. Changes nothing.",
|
|
161
|
+
" epic-server prove|start --epic <KEY> --epic-run-id <id> --head <SHA>",
|
|
162
|
+
" epic-server status [--epic-run-id <id> [--since <seq>]]",
|
|
163
|
+
" epic-server stop --expect-epic-run-id <id>",
|
|
164
|
+
" The run's one epic server for UI checks (opt-in per repository at setup).",
|
|
165
|
+
" The driver proves the run recipe, starts the detached helper, reads its",
|
|
166
|
+
" journal, and stops ONLY this run's own helper (ownership-verified).",
|
|
167
|
+
" epic-server turn acquire --ticket <KEY> --head <SHA> --wait <seconds>",
|
|
168
|
+
" epic-server turn release --lease <handle>",
|
|
169
|
+
" A worker borrows the epic server at its own head for a bounded turn, then",
|
|
170
|
+
" releases it with the lease handle acquire printed. A timeout or a missing",
|
|
171
|
+
" server prints a no_live_server observation for the hand-off; nothing parks.",
|
|
172
|
+
" epic-server sfcc-upload --ticket <KEY> --head <SHA>",
|
|
173
|
+
" epic-server sfcc-upload --full --epic <KEY> --epic-run-id <id> --head <SHA>",
|
|
174
|
+
" epic-server sfcc-upload --check",
|
|
175
|
+
" Uploads committed cartridge files to the run's one shared SFCC code version,",
|
|
176
|
+
" in any epic-server mode (worker: changed files; --full: the driver's whole",
|
|
177
|
+
" tree plus a baseline; --check: read-only readiness). A failure prints a",
|
|
178
|
+
" no_live_server observation for the hand-off; nothing parks.",
|
|
159
179
|
" prerequisite-inputs --epic-key <KEY> --child <KEY> [--child <KEY> ...] [--json]",
|
|
160
|
-
" Reads stored ticket descriptions and
|
|
161
|
-
"
|
|
162
|
-
"
|
|
180
|
+
" Reads stored ticket descriptions and reports, per child, cached, in_flight,",
|
|
181
|
+
" scan_needed (with a private scanner input file under",
|
|
182
|
+
" ~/.local/state/bapi-conductor-runs/<EPIC>/), or a closed failure.",
|
|
183
|
+
" Changes nothing on the server.",
|
|
184
|
+
" prerequisite-inputs --record --epic-key <KEY> --child <KEY> --input-hash <SHA256> --claim-id <ID> [--json]",
|
|
185
|
+
" Fully local: records a scanner result read from stdin (never argv).",
|
|
186
|
+
" driver-register --epic-run-id <id> [--json]",
|
|
187
|
+
" Arm the /drive-epic-run Stop-hook guard for this Claude Code session and",
|
|
188
|
+
" print the exact background waiter. Outside Claude Code it arms nothing.",
|
|
189
|
+
" driver-release --reason owner|done|handoff --epic-run-id <id>",
|
|
190
|
+
" Release this session from supervision: done (run terminal) and handoff",
|
|
191
|
+
" (report published) are checked on the server; owner only on the owner's",
|
|
192
|
+
" explicit instruction. Changes nothing on the run.",
|
|
193
|
+
" driver-pass --epic-run-id <id> [--ticket-key <key>] [--json]",
|
|
194
|
+
" Read-only: report the driver's clock facts (no-progress time, job pause,",
|
|
195
|
+
" attach window, reconciler liveness) from the server's own clock. Decides",
|
|
196
|
+
" and changes nothing; unreadable facts print as unknown.",
|
|
197
|
+
" driver-guard The /drive-epic-run Stop hook. Reads hook JSON on stdin, decides locally",
|
|
198
|
+
" with no network call, always exits 0. Off switch: BRIDGE_EI_DRIVER_GUARD=off.",
|
|
199
|
+
" declare-blocked --epic-run-id <id> --ticket-key <K>... --entry 1|2|3|4|5|wedge --requirement <text>",
|
|
200
|
+
" [--evidence <text>] [--tried <verbs>] [--alternatives <text>] [--fixer-outcome <text>]",
|
|
201
|
+
" Advisory blocker check: not a blocker yet (run <command>), accepted and",
|
|
202
|
+
" escalated, run-wide blocked, or scope unknown. Never releases supervision.",
|
|
163
203
|
"",
|
|
164
204
|
"supervise options:",
|
|
165
205
|
" --run-id <id> Run/session identifier to supervise (required)",
|
|
@@ -261,7 +301,9 @@ export function getConductorUsage() {
|
|
|
261
301
|
" --help Print this usage message",
|
|
262
302
|
"",
|
|
263
303
|
"epic-status options:",
|
|
264
|
-
" --epic-key <KEY> Epic key to fetch the snapshot for
|
|
304
|
+
" --epic-key <KEY> Epic key to fetch the snapshot for",
|
|
305
|
+
" --epic-run-id <id> Epic run identifier, as the other run commands take it",
|
|
306
|
+
" (pass exactly one of --epic-key or --epic-run-id)",
|
|
265
307
|
" --json Print compact JSON result",
|
|
266
308
|
" --help Print this usage message",
|
|
267
309
|
"",
|
|
@@ -270,6 +312,7 @@ export function getConductorUsage() {
|
|
|
270
312
|
" epic-implementer approve-plan EPIC-405 --plan-version 2 --json",
|
|
271
313
|
" epic-implementer epic-status --epic-key EPIC-405",
|
|
272
314
|
" epic-implementer epic-status --epic-key EPIC-405 --json",
|
|
315
|
+
" epic-implementer epic-status --epic-run-id <id>",
|
|
273
316
|
"",
|
|
274
317
|
"stop-run / abandon-run options:",
|
|
275
318
|
" --epic-run-id <id> Epic run identifier (required)",
|
|
@@ -390,6 +433,15 @@ const VALID_COMMANDS = new Set([
|
|
|
390
433
|
"wait-run",
|
|
391
434
|
// BAPI-1557: CLI-only stored-ticket reader and private local-state writer — never an MCP tool.
|
|
392
435
|
"prerequisite-inputs",
|
|
436
|
+
// BAPI-1546: CLI-only epic-server helper (driver verbs and worker turns) — never an MCP tool.
|
|
437
|
+
"epic-server",
|
|
438
|
+
// BAPI-1642: CLI-only driver supervision guard and blocker check — never MCP tools.
|
|
439
|
+
"driver-register",
|
|
440
|
+
"driver-release",
|
|
441
|
+
"driver-guard",
|
|
442
|
+
"declare-blocked",
|
|
443
|
+
// BAPI-1682: CLI-only read-only driver clock report — never an MCP tool.
|
|
444
|
+
"driver-pass",
|
|
393
445
|
// Private, and deliberately ABSENT from the usage text: `__hook-bin` exists as
|
|
394
446
|
// the bundled-artifact regression guard for BAPI-772 (mirroring `plane
|
|
395
447
|
// __entrypoint`), not as a supported operator workflow.
|
|
@@ -800,6 +852,41 @@ export async function runDoctorCommand(argv, deps = {}) {
|
|
|
800
852
|
// BAPI-1479: advisory, read-only worker-database rows; runs under
|
|
801
853
|
// --no-deny-probe too. A caller's injected inspector wins.
|
|
802
854
|
inspectWorkerDatabase: createWorkerDatabaseDoctorInspector({ env: deps.env ?? process.env, cwd: process.cwd() }),
|
|
855
|
+
// BAPI-1598: the inspection follows the project's declaration. A read that fails
|
|
856
|
+
// for any reason is `unreadable` (shown as "Couldn't check"), never "unset".
|
|
857
|
+
readWorkerDatabaseConfig: async () => {
|
|
858
|
+
try {
|
|
859
|
+
const { resolveConductorBridgeApiAccess, fetchConductorGateProfile } = await import("./bridge-api-client.js");
|
|
860
|
+
const access = await resolveConductorBridgeApiAccess({ env: deps.env ?? process.env });
|
|
861
|
+
if (!access.ok)
|
|
862
|
+
return { status: "unreadable" };
|
|
863
|
+
const read = await fetchConductorGateProfile(access.access, (url, init) => fetch(url, init));
|
|
864
|
+
if (read.stored_malformed)
|
|
865
|
+
return { status: "unreadable" };
|
|
866
|
+
const declared = read.profile?.worker_database;
|
|
867
|
+
if (!declared)
|
|
868
|
+
return { status: "unset" };
|
|
869
|
+
return {
|
|
870
|
+
status: "configured",
|
|
871
|
+
mode: declared.mode,
|
|
872
|
+
...(declared.worker_role ? { workerRole: declared.worker_role } : {}),
|
|
873
|
+
protectedDatabases: declared.protected_databases ?? [],
|
|
874
|
+
envNames: declared.env_names ?? [],
|
|
875
|
+
...(declared.migrate_command
|
|
876
|
+
? {
|
|
877
|
+
migrateCommand: {
|
|
878
|
+
argv: declared.migrate_command.argv,
|
|
879
|
+
timeoutSeconds: declared.migrate_command.timeout_seconds,
|
|
880
|
+
headCheck: declared.migrate_command.head_check ?? "none",
|
|
881
|
+
},
|
|
882
|
+
}
|
|
883
|
+
: {}),
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
return { status: "unreadable" };
|
|
888
|
+
}
|
|
889
|
+
},
|
|
803
890
|
// BAPI-1461: a merge token stored once for this repository counts as
|
|
804
891
|
// configured — after the bounded capability probe confirms GitHub accepts
|
|
805
892
|
// it. Doctor runs in the person's own session, so the stored rung applies.
|
|
@@ -1187,7 +1274,7 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1187
1274
|
// Lazy import keeps the credential/HTTP graph out of commands that never
|
|
1188
1275
|
// need Bridge API access (doctor, emit-event, etc.).
|
|
1189
1276
|
const { resolveConductorBridgeApiAccess, approveEpicPlan } = await import("./bridge-api-client.js");
|
|
1190
|
-
const accessResult = await resolveConductorBridgeApiAccess();
|
|
1277
|
+
const accessResult = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
|
|
1191
1278
|
if (!accessResult.ok) {
|
|
1192
1279
|
const envelope = { error: "CREDENTIALS_UNAVAILABLE", status: 401, message: accessResult.error };
|
|
1193
1280
|
if (parsed.json) {
|
|
@@ -1203,6 +1290,10 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1203
1290
|
epicKey: parsed.epicKey,
|
|
1204
1291
|
planVersion: parsed.planVersion,
|
|
1205
1292
|
});
|
|
1293
|
+
if (!result.ok && result.kind === "refused") {
|
|
1294
|
+
throw new ConductorValidationError(`approve-plan refused by the server (${result.error_code}, ` +
|
|
1295
|
+
`predicate ${result.predicate}, reason ${result.reason_code}).`);
|
|
1296
|
+
}
|
|
1206
1297
|
if (!result.ok) {
|
|
1207
1298
|
throw new ConductorValidationError(`approve-plan rejected: version drift or monotonic constraint violation ` +
|
|
1208
1299
|
`(kind: ${result.kind}). Ensure --plan-version is strictly greater than ` +
|
|
@@ -1236,22 +1327,35 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1236
1327
|
// ---------------------------------------------------------------------------
|
|
1237
1328
|
// epic-status
|
|
1238
1329
|
// ---------------------------------------------------------------------------
|
|
1239
|
-
const EPIC_STATUS_VALUE_FLAGS = new Set(["--epic-key"]);
|
|
1330
|
+
const EPIC_STATUS_VALUE_FLAGS = new Set(["--epic-key", "--epic-run-id"]);
|
|
1240
1331
|
const EPIC_STATUS_BOOL_FLAGS = new Set(["--json", "--help"]);
|
|
1241
1332
|
/**
|
|
1242
|
-
* Parse `epic-status` flags. `--epic-key`
|
|
1243
|
-
*
|
|
1333
|
+
* Parse `epic-status` flags. Exactly one of `--epic-key` or `--epic-run-id` is
|
|
1334
|
+
* required and must be non-empty. The other run-control commands take
|
|
1335
|
+
* `--epic-run-id`, and the state endpoint resolves either a run id or an epic
|
|
1336
|
+
* key, so both name the same run. Malformed input raises a sanitized
|
|
1337
|
+
* {@link ConductorValidationError}.
|
|
1244
1338
|
*/
|
|
1245
1339
|
export function parseEpicStatusArgs(argv) {
|
|
1246
1340
|
const { values, bools } = tokenizeFlags(argv, EPIC_STATUS_VALUE_FLAGS, EPIC_STATUS_BOOL_FLAGS);
|
|
1247
1341
|
if (bools.has("--help")) {
|
|
1248
|
-
return { epicKey: "", json: false, help: true };
|
|
1342
|
+
return { epicKey: "", epicRunId: null, json: false, help: true };
|
|
1249
1343
|
}
|
|
1250
1344
|
const epicKeyRaw = values.get("--epic-key");
|
|
1345
|
+
const epicRunIdRaw = values.get("--epic-run-id");
|
|
1346
|
+
if (epicKeyRaw !== undefined && epicRunIdRaw !== undefined) {
|
|
1347
|
+
throw new ConductorValidationError('Pass only one of "--epic-key" or "--epic-run-id" to epic-status.');
|
|
1348
|
+
}
|
|
1349
|
+
if (epicRunIdRaw !== undefined) {
|
|
1350
|
+
if (epicRunIdRaw.trim().length === 0) {
|
|
1351
|
+
throw new ConductorValidationError('Flag "--epic-run-id" must be non-empty.');
|
|
1352
|
+
}
|
|
1353
|
+
return { epicKey: "", epicRunId: epicRunIdRaw.trim(), json: bools.has("--json"), help: false };
|
|
1354
|
+
}
|
|
1251
1355
|
if (epicKeyRaw === undefined || epicKeyRaw.trim().length === 0) {
|
|
1252
|
-
throw new ConductorValidationError('Flag "--epic-key" is required for epic-status and must be non-empty.');
|
|
1356
|
+
throw new ConductorValidationError('Flag "--epic-key" (or "--epic-run-id") is required for epic-status and must be non-empty.');
|
|
1253
1357
|
}
|
|
1254
|
-
return { epicKey: epicKeyRaw.trim(), json: bools.has("--json"), help: false };
|
|
1358
|
+
return { epicKey: epicKeyRaw.trim(), epicRunId: null, json: bools.has("--json"), help: false };
|
|
1255
1359
|
}
|
|
1256
1360
|
/**
|
|
1257
1361
|
* Run the `epic-status` command. Resolves Bridge API credentials, calls
|
|
@@ -1276,7 +1380,7 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1276
1380
|
// Lazy import keeps the credential/HTTP graph out of commands that never
|
|
1277
1381
|
// need Bridge API access (doctor, emit-event, etc.).
|
|
1278
1382
|
const { resolveConductorBridgeApiAccess, fetchEpicRunState, ConductorBridgeApiError: BridgeApiError } = await import("./bridge-api-client.js");
|
|
1279
|
-
const accessResult = await resolveConductorBridgeApiAccess();
|
|
1383
|
+
const accessResult = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
|
|
1280
1384
|
if (!accessResult.ok) {
|
|
1281
1385
|
if (parsed.json) {
|
|
1282
1386
|
await writeJsonDocument(JSON.stringify({ ok: false, kind: "unauthorized", error: accessResult.error }));
|
|
@@ -1287,7 +1391,7 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1287
1391
|
return 1;
|
|
1288
1392
|
}
|
|
1289
1393
|
try {
|
|
1290
|
-
const state = await fetchEpicRunState(accessResult.access, parsed.epicKey);
|
|
1394
|
+
const state = await fetchEpicRunState(accessResult.access, parsed.epicRunId ?? parsed.epicKey);
|
|
1291
1395
|
if (parsed.json) {
|
|
1292
1396
|
return (await writeJsonDocument(JSON.stringify(state))) ? 0 : 1;
|
|
1293
1397
|
}
|
|
@@ -1324,7 +1428,9 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1324
1428
|
catch (error) {
|
|
1325
1429
|
if (error instanceof BridgeApiError && error.status === 404) {
|
|
1326
1430
|
if (parsed.json) {
|
|
1327
|
-
const written = await writeJsonDocument(JSON.stringify(
|
|
1431
|
+
const written = await writeJsonDocument(JSON.stringify(parsed.epicRunId !== null
|
|
1432
|
+
? { epic_run_id: parsed.epicRunId, status: "unknown", state: null }
|
|
1433
|
+
: { epic_key: parsed.epicKey, status: "unknown", state: null }));
|
|
1328
1434
|
if (!written)
|
|
1329
1435
|
return 1;
|
|
1330
1436
|
}
|
|
@@ -1672,6 +1778,84 @@ export async function runEpicImplementerCli(argv, likelyTestsDeps) {
|
|
|
1672
1778
|
}
|
|
1673
1779
|
return await runPrerequisiteInputsCommand(parsed.argv);
|
|
1674
1780
|
}
|
|
1781
|
+
case "epic-server": {
|
|
1782
|
+
// BAPI-1546: dispatched before any MCP server is built or connected. A
|
|
1783
|
+
// module-load failure gets fixed wording, never exception text.
|
|
1784
|
+
let runEpicServerCommand;
|
|
1785
|
+
try {
|
|
1786
|
+
({ runEpicServerCommand } = await import("./epic-server.js"));
|
|
1787
|
+
}
|
|
1788
|
+
catch {
|
|
1789
|
+
console.error("Error: epic-server could not be loaded; nothing was started or stopped.");
|
|
1790
|
+
return 1;
|
|
1791
|
+
}
|
|
1792
|
+
return await runEpicServerCommand(parsed.argv);
|
|
1793
|
+
}
|
|
1794
|
+
case "driver-guard": {
|
|
1795
|
+
// BAPI-1642: the Stop hook. Its own boundary: a load failure or any
|
|
1796
|
+
// exception allows the stop silently with exit 0, never the general
|
|
1797
|
+
// exit-1 error path below.
|
|
1798
|
+
try {
|
|
1799
|
+
const { runDriverGuardCommand } = await import("./driver-guard.js");
|
|
1800
|
+
return await runDriverGuardCommand(parsed.argv);
|
|
1801
|
+
}
|
|
1802
|
+
catch {
|
|
1803
|
+
return 0;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
case "driver-register": {
|
|
1807
|
+
let runDriverRegisterCommand;
|
|
1808
|
+
try {
|
|
1809
|
+
({ runDriverRegisterCommand } = await import("./driver-register.js"));
|
|
1810
|
+
}
|
|
1811
|
+
catch {
|
|
1812
|
+
console.error("Error: driver-register could not be loaded; the driver guard is not armed.");
|
|
1813
|
+
return 1;
|
|
1814
|
+
}
|
|
1815
|
+
return await runDriverRegisterCommand(parsed.argv);
|
|
1816
|
+
}
|
|
1817
|
+
case "driver-release": {
|
|
1818
|
+
let runDriverReleaseCommand;
|
|
1819
|
+
try {
|
|
1820
|
+
({ runDriverReleaseCommand } = await import("./driver-release.js"));
|
|
1821
|
+
}
|
|
1822
|
+
catch {
|
|
1823
|
+
console.error("Error: driver-release could not be loaded; nothing was released.");
|
|
1824
|
+
return 1;
|
|
1825
|
+
}
|
|
1826
|
+
return await runDriverReleaseCommand(parsed.argv);
|
|
1827
|
+
}
|
|
1828
|
+
case "driver-pass": {
|
|
1829
|
+
// BAPI-1682: CLI-only, read-only, advisory. A module-load failure is
|
|
1830
|
+
// fail-open like the command itself: one fixed line, a full unavailable
|
|
1831
|
+
// result from the dependency-light output module, exit 0.
|
|
1832
|
+
let runDriverPassCommand;
|
|
1833
|
+
try {
|
|
1834
|
+
({ runDriverPassCommand } = await import("./driver-pass.js"));
|
|
1835
|
+
}
|
|
1836
|
+
catch {
|
|
1837
|
+
console.error("driver-pass could not be loaded; no run state was read.");
|
|
1838
|
+
const { buildUnavailableDriverPassResult, formatDriverPassResult } = await import("./driver-pass-output.js");
|
|
1839
|
+
const runFlag = parsed.argv.indexOf("--epic-run-id");
|
|
1840
|
+
const ref = runFlag >= 0 ? parsed.argv[runFlag + 1] : undefined;
|
|
1841
|
+
const safeRef = typeof ref === "string" && /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(ref) ? ref : "unknown";
|
|
1842
|
+
const result = buildUnavailableDriverPassResult(safeRef, "computation_failed");
|
|
1843
|
+
console.log(parsed.argv.includes("--json") ? JSON.stringify(result) : formatDriverPassResult(result));
|
|
1844
|
+
return 0;
|
|
1845
|
+
}
|
|
1846
|
+
return await runDriverPassCommand(parsed.argv);
|
|
1847
|
+
}
|
|
1848
|
+
case "declare-blocked": {
|
|
1849
|
+
let runDeclareBlockedCommand;
|
|
1850
|
+
try {
|
|
1851
|
+
({ runDeclareBlockedCommand } = await import("./declare-blocked.js"));
|
|
1852
|
+
}
|
|
1853
|
+
catch {
|
|
1854
|
+
console.error("Error: declare-blocked could not be loaded; nothing was escalated. Supervision continues.");
|
|
1855
|
+
return 1;
|
|
1856
|
+
}
|
|
1857
|
+
return await runDeclareBlockedCommand(parsed.argv);
|
|
1858
|
+
}
|
|
1675
1859
|
default:
|
|
1676
1860
|
console.error('Error: Unknown command. Run "epic-implementer --help" for usage.');
|
|
1677
1861
|
return 1;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The epic-server helper's OPTIONAL per-turn database (BAPI-1546).
|
|
3
|
+
*
|
|
4
|
+
* Created only when the validated recipe asks for one (`database.kind:
|
|
5
|
+
* disposable_postgres`). It uses its own name prefix (`bridge_epic_server_`) and
|
|
6
|
+
* its own ownership comment, so the executor's orphan sweep, which lists only
|
|
7
|
+
* the exact `bridge_worker_job_` prefix, never lists or drops it mid-turn.
|
|
8
|
+
*
|
|
9
|
+
* Migration is never run here: it is the recipe's own `migrate` step, so the
|
|
10
|
+
* packaged helper carries no migration tool assumption. This adapter only
|
|
11
|
+
* creates, comments, drops, and sweeps.
|
|
12
|
+
*
|
|
13
|
+
* The ownership comment names the run, the helper pid, a DIGEST of the helper's
|
|
14
|
+
* instance nonce (never the nonce itself), and the turn generation. On start the
|
|
15
|
+
* helper sweeps only its own run's leftovers whose recorded helper pid is
|
|
16
|
+
* definitively dead (or is itself, from an earlier turn). Anything ambiguous,
|
|
17
|
+
* malformed, or another run's is left alone.
|
|
18
|
+
*/
|
|
19
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
20
|
+
import { EPIC_SERVER_DATABASE_PREFIX, createEpicServerDatabase, dropEpicServerDatabase, isValidEpicServerDatabaseName, listEpicServerDatabases, } from "../executor/worker-database.js";
|
|
21
|
+
import { WORKER_DATABASE_HOST, WORKER_DATABASE_PORT } from "../executor/worker-database-target.js";
|
|
22
|
+
export const EPIC_SERVER_DATABASE_METADATA_VERSION = 1;
|
|
23
|
+
const KEYS = ["v", "kind", "runId", "helperPid", "nonceDigest", "generation", "createdAt"];
|
|
24
|
+
const RUN_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{7,63}$/;
|
|
25
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
26
|
+
/** The digest recorded instead of the nonce. */
|
|
27
|
+
export function instanceNonceDigest(nonce) {
|
|
28
|
+
return createHash("sha256").update(`epic-server:${nonce}`).digest("hex");
|
|
29
|
+
}
|
|
30
|
+
export function encodeEpicServerDatabaseMetadata(metadata) {
|
|
31
|
+
return JSON.stringify({
|
|
32
|
+
v: metadata.v,
|
|
33
|
+
kind: metadata.kind,
|
|
34
|
+
runId: metadata.runId,
|
|
35
|
+
helperPid: metadata.helperPid,
|
|
36
|
+
nonceDigest: metadata.nonceDigest,
|
|
37
|
+
generation: metadata.generation,
|
|
38
|
+
createdAt: metadata.createdAt,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Strict parser: exactly the known keys, each well-formed. Anything else is null. */
|
|
42
|
+
export function parseEpicServerDatabaseMetadata(comment) {
|
|
43
|
+
if (typeof comment !== "string" || comment.length > 512)
|
|
44
|
+
return null;
|
|
45
|
+
let raw;
|
|
46
|
+
try {
|
|
47
|
+
raw = JSON.parse(comment);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw))
|
|
53
|
+
return null;
|
|
54
|
+
const doc = raw;
|
|
55
|
+
const keys = Object.keys(doc);
|
|
56
|
+
if (keys.length !== KEYS.length || !KEYS.every((k) => keys.includes(k)))
|
|
57
|
+
return null;
|
|
58
|
+
if (doc.v !== EPIC_SERVER_DATABASE_METADATA_VERSION || doc.kind !== "epic_server")
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof doc.runId !== "string" || !RUN_ID_RE.test(doc.runId))
|
|
61
|
+
return null;
|
|
62
|
+
if (typeof doc.helperPid !== "number" || !Number.isSafeInteger(doc.helperPid) || doc.helperPid <= 1)
|
|
63
|
+
return null;
|
|
64
|
+
if (typeof doc.nonceDigest !== "string" || !DIGEST_RE.test(doc.nonceDigest))
|
|
65
|
+
return null;
|
|
66
|
+
if (typeof doc.generation !== "number" || !Number.isSafeInteger(doc.generation) || doc.generation < 0)
|
|
67
|
+
return null;
|
|
68
|
+
if (typeof doc.createdAt !== "string" || Number.isNaN(Date.parse(doc.createdAt)))
|
|
69
|
+
return null;
|
|
70
|
+
return {
|
|
71
|
+
v: EPIC_SERVER_DATABASE_METADATA_VERSION,
|
|
72
|
+
kind: "epic_server",
|
|
73
|
+
runId: doc.runId,
|
|
74
|
+
helperPid: doc.helperPid,
|
|
75
|
+
nonceDigest: doc.nonceDigest,
|
|
76
|
+
generation: doc.generation,
|
|
77
|
+
createdAt: doc.createdAt,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** `bridge_epic_server_<run12>_g<gen>_<hex8>`, within the identifier limit. */
|
|
81
|
+
export function buildEpicServerDatabaseName(runId, generation, suffix) {
|
|
82
|
+
const run = runId.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 12);
|
|
83
|
+
if (run.length === 0 || !/^[0-9a-f]{4,16}$/.test(suffix) || !Number.isSafeInteger(generation) || generation < 0)
|
|
84
|
+
return null;
|
|
85
|
+
const name = `${EPIC_SERVER_DATABASE_PREFIX}${run}_g${generation}_${suffix}`;
|
|
86
|
+
return isValidEpicServerDatabaseName(name) ? name : null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create the turn's database and record ownership BEFORE exposing its settings.
|
|
90
|
+
* The settings name only this database, on loopback, as the recipe's role.
|
|
91
|
+
*/
|
|
92
|
+
export async function provisionTurnDatabase(owner, role, budgetMs, deps) {
|
|
93
|
+
const suffix = (deps.randomSuffix ?? (() => randomBytes(4).toString("hex")))();
|
|
94
|
+
const name = buildEpicServerDatabaseName(owner.runId, owner.generation, suffix);
|
|
95
|
+
if (name === null)
|
|
96
|
+
return { kind: "unavailable" };
|
|
97
|
+
const comment = encodeEpicServerDatabaseMetadata({
|
|
98
|
+
v: EPIC_SERVER_DATABASE_METADATA_VERSION,
|
|
99
|
+
kind: "epic_server",
|
|
100
|
+
runId: owner.runId,
|
|
101
|
+
helperPid: owner.helperPid,
|
|
102
|
+
nonceDigest: instanceNonceDigest(owner.nonce),
|
|
103
|
+
generation: owner.generation,
|
|
104
|
+
createdAt: deps.now().toISOString(),
|
|
105
|
+
});
|
|
106
|
+
const created = await createEpicServerDatabase(name, role, comment, deps.database, budgetMs);
|
|
107
|
+
if (created.kind !== "ok")
|
|
108
|
+
return created.retained ? { kind: "unavailable", retainedName: name } : { kind: "unavailable" };
|
|
109
|
+
return {
|
|
110
|
+
kind: "ready",
|
|
111
|
+
name,
|
|
112
|
+
settings: { host: WORKER_DATABASE_HOST, port: WORKER_DATABASE_PORT, role, name },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Drop the turn's database. Returns false when the drop could not be confirmed. */
|
|
116
|
+
export async function dropTurnDatabase(name, role, budgetMs, deps) {
|
|
117
|
+
const dropped = await dropEpicServerDatabase(name, role, deps.database, budgetMs);
|
|
118
|
+
return dropped.kind === "ok";
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* True only when `settings` names the helper's CURRENT per-turn database. The
|
|
122
|
+
* runtime checks this before building any migrate or seed command.
|
|
123
|
+
*/
|
|
124
|
+
export function isCurrentTurnDatabase(settings, current) {
|
|
125
|
+
if (settings === null || current === null)
|
|
126
|
+
return false;
|
|
127
|
+
return (isValidEpicServerDatabaseName(settings.name) &&
|
|
128
|
+
settings.name === current.name &&
|
|
129
|
+
settings.role === current.role &&
|
|
130
|
+
settings.host === WORKER_DATABASE_HOST &&
|
|
131
|
+
settings.port === WORKER_DATABASE_PORT);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Drop this run's leftover helper databases whose recorded helper is definitively
|
|
135
|
+
* dead, or is the current helper itself (an earlier turn whose drop failed).
|
|
136
|
+
* Live, unknown, malformed, and other runs' databases are retained untouched.
|
|
137
|
+
*/
|
|
138
|
+
export async function sweepOwnLeftoverDatabases(current, role, budgetMs, deps) {
|
|
139
|
+
const result = { dropped: [], retained: [] };
|
|
140
|
+
const listing = await listEpicServerDatabases(role, deps.database, budgetMs);
|
|
141
|
+
if (listing.kind !== "ok")
|
|
142
|
+
return result;
|
|
143
|
+
const currentDigest = instanceNonceDigest(current.nonce);
|
|
144
|
+
for (const row of listing.rows) {
|
|
145
|
+
if (deps.keep?.has(row.name))
|
|
146
|
+
continue;
|
|
147
|
+
const metadata = parseEpicServerDatabaseMetadata(row.comment);
|
|
148
|
+
if (metadata === null || metadata.runId !== current.runId)
|
|
149
|
+
continue;
|
|
150
|
+
const ownEarlierTurn = metadata.helperPid === current.helperPid && metadata.nonceDigest === currentDigest;
|
|
151
|
+
const deadOwner = metadata.helperPid !== current.helperPid && deps.isPidAlive(metadata.helperPid) === false;
|
|
152
|
+
if (!ownEarlierTurn && !deadOwner) {
|
|
153
|
+
result.retained.push(row.name);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (await dropTurnDatabase(row.name, role, budgetMs, deps))
|
|
157
|
+
result.dropped.push(row.name);
|
|
158
|
+
else
|
|
159
|
+
result.retained.push(row.name);
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|