@bridge_gpt/mcp-server 0.2.72 → 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 +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -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/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -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 +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +106 -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-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 +166 -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.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 +150 -5
- package/build/conductor/gate-settings-review.js +224 -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-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- 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 +2101 -44
- package/build/epic-launch-context.js +607 -0
- 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/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- 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 +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- 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 +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- 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-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 +234 -109
- package/build/pipelines.generated.js +5 -5
- 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/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- 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 +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- 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/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,45 @@ 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.",
|
|
159
172
|
" prerequisite-inputs --epic-key <KEY> --child <KEY> [--child <KEY> ...] [--json]",
|
|
160
|
-
" Reads stored ticket descriptions and
|
|
161
|
-
"
|
|
162
|
-
"
|
|
173
|
+
" Reads stored ticket descriptions and reports, per child, cached, in_flight,",
|
|
174
|
+
" scan_needed (with a private scanner input file under",
|
|
175
|
+
" ~/.local/state/bapi-conductor-runs/<EPIC>/), or a closed failure.",
|
|
176
|
+
" Changes nothing on the server.",
|
|
177
|
+
" prerequisite-inputs --record --epic-key <KEY> --child <KEY> --input-hash <SHA256> --claim-id <ID> [--json]",
|
|
178
|
+
" Fully local: records a scanner result read from stdin (never argv).",
|
|
179
|
+
" driver-register --epic-run-id <id> [--json]",
|
|
180
|
+
" Arm the /drive-epic-run Stop-hook guard for this Claude Code session and",
|
|
181
|
+
" print the exact background waiter. Outside Claude Code it arms nothing.",
|
|
182
|
+
" driver-release --reason owner|done|handoff --epic-run-id <id>",
|
|
183
|
+
" Release this session from supervision: done (run terminal) and handoff",
|
|
184
|
+
" (report published) are checked on the server; owner only on the owner's",
|
|
185
|
+
" explicit instruction. Changes nothing on the run.",
|
|
186
|
+
" driver-guard The /drive-epic-run Stop hook. Reads hook JSON on stdin, decides locally",
|
|
187
|
+
" with no network call, always exits 0. Off switch: BRIDGE_EI_DRIVER_GUARD=off.",
|
|
188
|
+
" declare-blocked --epic-run-id <id> --ticket-key <K>... --entry 1|2|3|4|5|wedge --requirement <text>",
|
|
189
|
+
" [--evidence <text>] [--tried <verbs>] [--alternatives <text>] [--fixer-outcome <text>]",
|
|
190
|
+
" Advisory blocker check: not a blocker yet (run <command>), accepted and",
|
|
191
|
+
" escalated, run-wide blocked, or scope unknown. Never releases supervision.",
|
|
163
192
|
"",
|
|
164
193
|
"supervise options:",
|
|
165
194
|
" --run-id <id> Run/session identifier to supervise (required)",
|
|
@@ -261,7 +290,9 @@ export function getConductorUsage() {
|
|
|
261
290
|
" --help Print this usage message",
|
|
262
291
|
"",
|
|
263
292
|
"epic-status options:",
|
|
264
|
-
" --epic-key <KEY> Epic key to fetch the snapshot for
|
|
293
|
+
" --epic-key <KEY> Epic key to fetch the snapshot for",
|
|
294
|
+
" --epic-run-id <id> Epic run identifier, as the other run commands take it",
|
|
295
|
+
" (pass exactly one of --epic-key or --epic-run-id)",
|
|
265
296
|
" --json Print compact JSON result",
|
|
266
297
|
" --help Print this usage message",
|
|
267
298
|
"",
|
|
@@ -270,6 +301,7 @@ export function getConductorUsage() {
|
|
|
270
301
|
" epic-implementer approve-plan EPIC-405 --plan-version 2 --json",
|
|
271
302
|
" epic-implementer epic-status --epic-key EPIC-405",
|
|
272
303
|
" epic-implementer epic-status --epic-key EPIC-405 --json",
|
|
304
|
+
" epic-implementer epic-status --epic-run-id <id>",
|
|
273
305
|
"",
|
|
274
306
|
"stop-run / abandon-run options:",
|
|
275
307
|
" --epic-run-id <id> Epic run identifier (required)",
|
|
@@ -390,6 +422,13 @@ const VALID_COMMANDS = new Set([
|
|
|
390
422
|
"wait-run",
|
|
391
423
|
// BAPI-1557: CLI-only stored-ticket reader and private local-state writer — never an MCP tool.
|
|
392
424
|
"prerequisite-inputs",
|
|
425
|
+
// BAPI-1546: CLI-only epic-server helper (driver verbs and worker turns) — never an MCP tool.
|
|
426
|
+
"epic-server",
|
|
427
|
+
// BAPI-1642: CLI-only driver supervision guard and blocker check — never MCP tools.
|
|
428
|
+
"driver-register",
|
|
429
|
+
"driver-release",
|
|
430
|
+
"driver-guard",
|
|
431
|
+
"declare-blocked",
|
|
393
432
|
// Private, and deliberately ABSENT from the usage text: `__hook-bin` exists as
|
|
394
433
|
// the bundled-artifact regression guard for BAPI-772 (mirroring `plane
|
|
395
434
|
// __entrypoint`), not as a supported operator workflow.
|
|
@@ -800,6 +839,41 @@ export async function runDoctorCommand(argv, deps = {}) {
|
|
|
800
839
|
// BAPI-1479: advisory, read-only worker-database rows; runs under
|
|
801
840
|
// --no-deny-probe too. A caller's injected inspector wins.
|
|
802
841
|
inspectWorkerDatabase: createWorkerDatabaseDoctorInspector({ env: deps.env ?? process.env, cwd: process.cwd() }),
|
|
842
|
+
// BAPI-1598: the inspection follows the project's declaration. A read that fails
|
|
843
|
+
// for any reason is `unreadable` (shown as "Couldn't check"), never "unset".
|
|
844
|
+
readWorkerDatabaseConfig: async () => {
|
|
845
|
+
try {
|
|
846
|
+
const { resolveConductorBridgeApiAccess, fetchConductorGateProfile } = await import("./bridge-api-client.js");
|
|
847
|
+
const access = await resolveConductorBridgeApiAccess({ env: deps.env ?? process.env });
|
|
848
|
+
if (!access.ok)
|
|
849
|
+
return { status: "unreadable" };
|
|
850
|
+
const read = await fetchConductorGateProfile(access.access, (url, init) => fetch(url, init));
|
|
851
|
+
if (read.stored_malformed)
|
|
852
|
+
return { status: "unreadable" };
|
|
853
|
+
const declared = read.profile?.worker_database;
|
|
854
|
+
if (!declared)
|
|
855
|
+
return { status: "unset" };
|
|
856
|
+
return {
|
|
857
|
+
status: "configured",
|
|
858
|
+
mode: declared.mode,
|
|
859
|
+
...(declared.worker_role ? { workerRole: declared.worker_role } : {}),
|
|
860
|
+
protectedDatabases: declared.protected_databases ?? [],
|
|
861
|
+
envNames: declared.env_names ?? [],
|
|
862
|
+
...(declared.migrate_command
|
|
863
|
+
? {
|
|
864
|
+
migrateCommand: {
|
|
865
|
+
argv: declared.migrate_command.argv,
|
|
866
|
+
timeoutSeconds: declared.migrate_command.timeout_seconds,
|
|
867
|
+
headCheck: declared.migrate_command.head_check ?? "none",
|
|
868
|
+
},
|
|
869
|
+
}
|
|
870
|
+
: {}),
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
catch {
|
|
874
|
+
return { status: "unreadable" };
|
|
875
|
+
}
|
|
876
|
+
},
|
|
803
877
|
// BAPI-1461: a merge token stored once for this repository counts as
|
|
804
878
|
// configured — after the bounded capability probe confirms GitHub accepts
|
|
805
879
|
// it. Doctor runs in the person's own session, so the stored rung applies.
|
|
@@ -1187,7 +1261,7 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1187
1261
|
// Lazy import keeps the credential/HTTP graph out of commands that never
|
|
1188
1262
|
// need Bridge API access (doctor, emit-event, etc.).
|
|
1189
1263
|
const { resolveConductorBridgeApiAccess, approveEpicPlan } = await import("./bridge-api-client.js");
|
|
1190
|
-
const accessResult = await resolveConductorBridgeApiAccess();
|
|
1264
|
+
const accessResult = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
|
|
1191
1265
|
if (!accessResult.ok) {
|
|
1192
1266
|
const envelope = { error: "CREDENTIALS_UNAVAILABLE", status: 401, message: accessResult.error };
|
|
1193
1267
|
if (parsed.json) {
|
|
@@ -1203,6 +1277,10 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1203
1277
|
epicKey: parsed.epicKey,
|
|
1204
1278
|
planVersion: parsed.planVersion,
|
|
1205
1279
|
});
|
|
1280
|
+
if (!result.ok && result.kind === "refused") {
|
|
1281
|
+
throw new ConductorValidationError(`approve-plan refused by the server (${result.error_code}, ` +
|
|
1282
|
+
`predicate ${result.predicate}, reason ${result.reason_code}).`);
|
|
1283
|
+
}
|
|
1206
1284
|
if (!result.ok) {
|
|
1207
1285
|
throw new ConductorValidationError(`approve-plan rejected: version drift or monotonic constraint violation ` +
|
|
1208
1286
|
`(kind: ${result.kind}). Ensure --plan-version is strictly greater than ` +
|
|
@@ -1236,22 +1314,35 @@ export async function runApprovePlanCommand(argv) {
|
|
|
1236
1314
|
// ---------------------------------------------------------------------------
|
|
1237
1315
|
// epic-status
|
|
1238
1316
|
// ---------------------------------------------------------------------------
|
|
1239
|
-
const EPIC_STATUS_VALUE_FLAGS = new Set(["--epic-key"]);
|
|
1317
|
+
const EPIC_STATUS_VALUE_FLAGS = new Set(["--epic-key", "--epic-run-id"]);
|
|
1240
1318
|
const EPIC_STATUS_BOOL_FLAGS = new Set(["--json", "--help"]);
|
|
1241
1319
|
/**
|
|
1242
|
-
* Parse `epic-status` flags. `--epic-key`
|
|
1243
|
-
*
|
|
1320
|
+
* Parse `epic-status` flags. Exactly one of `--epic-key` or `--epic-run-id` is
|
|
1321
|
+
* required and must be non-empty. The other run-control commands take
|
|
1322
|
+
* `--epic-run-id`, and the state endpoint resolves either a run id or an epic
|
|
1323
|
+
* key, so both name the same run. Malformed input raises a sanitized
|
|
1324
|
+
* {@link ConductorValidationError}.
|
|
1244
1325
|
*/
|
|
1245
1326
|
export function parseEpicStatusArgs(argv) {
|
|
1246
1327
|
const { values, bools } = tokenizeFlags(argv, EPIC_STATUS_VALUE_FLAGS, EPIC_STATUS_BOOL_FLAGS);
|
|
1247
1328
|
if (bools.has("--help")) {
|
|
1248
|
-
return { epicKey: "", json: false, help: true };
|
|
1329
|
+
return { epicKey: "", epicRunId: null, json: false, help: true };
|
|
1249
1330
|
}
|
|
1250
1331
|
const epicKeyRaw = values.get("--epic-key");
|
|
1332
|
+
const epicRunIdRaw = values.get("--epic-run-id");
|
|
1333
|
+
if (epicKeyRaw !== undefined && epicRunIdRaw !== undefined) {
|
|
1334
|
+
throw new ConductorValidationError('Pass only one of "--epic-key" or "--epic-run-id" to epic-status.');
|
|
1335
|
+
}
|
|
1336
|
+
if (epicRunIdRaw !== undefined) {
|
|
1337
|
+
if (epicRunIdRaw.trim().length === 0) {
|
|
1338
|
+
throw new ConductorValidationError('Flag "--epic-run-id" must be non-empty.');
|
|
1339
|
+
}
|
|
1340
|
+
return { epicKey: "", epicRunId: epicRunIdRaw.trim(), json: bools.has("--json"), help: false };
|
|
1341
|
+
}
|
|
1251
1342
|
if (epicKeyRaw === undefined || epicKeyRaw.trim().length === 0) {
|
|
1252
|
-
throw new ConductorValidationError('Flag "--epic-key" is required for epic-status and must be non-empty.');
|
|
1343
|
+
throw new ConductorValidationError('Flag "--epic-key" (or "--epic-run-id") is required for epic-status and must be non-empty.');
|
|
1253
1344
|
}
|
|
1254
|
-
return { epicKey: epicKeyRaw.trim(), json: bools.has("--json"), help: false };
|
|
1345
|
+
return { epicKey: epicKeyRaw.trim(), epicRunId: null, json: bools.has("--json"), help: false };
|
|
1255
1346
|
}
|
|
1256
1347
|
/**
|
|
1257
1348
|
* Run the `epic-status` command. Resolves Bridge API credentials, calls
|
|
@@ -1276,7 +1367,7 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1276
1367
|
// Lazy import keeps the credential/HTTP graph out of commands that never
|
|
1277
1368
|
// need Bridge API access (doctor, emit-event, etc.).
|
|
1278
1369
|
const { resolveConductorBridgeApiAccess, fetchEpicRunState, ConductorBridgeApiError: BridgeApiError } = await import("./bridge-api-client.js");
|
|
1279
|
-
const accessResult = await resolveConductorBridgeApiAccess();
|
|
1370
|
+
const accessResult = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
|
|
1280
1371
|
if (!accessResult.ok) {
|
|
1281
1372
|
if (parsed.json) {
|
|
1282
1373
|
await writeJsonDocument(JSON.stringify({ ok: false, kind: "unauthorized", error: accessResult.error }));
|
|
@@ -1287,7 +1378,7 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1287
1378
|
return 1;
|
|
1288
1379
|
}
|
|
1289
1380
|
try {
|
|
1290
|
-
const state = await fetchEpicRunState(accessResult.access, parsed.epicKey);
|
|
1381
|
+
const state = await fetchEpicRunState(accessResult.access, parsed.epicRunId ?? parsed.epicKey);
|
|
1291
1382
|
if (parsed.json) {
|
|
1292
1383
|
return (await writeJsonDocument(JSON.stringify(state))) ? 0 : 1;
|
|
1293
1384
|
}
|
|
@@ -1324,7 +1415,9 @@ export async function runEpicStatusCommand(argv) {
|
|
|
1324
1415
|
catch (error) {
|
|
1325
1416
|
if (error instanceof BridgeApiError && error.status === 404) {
|
|
1326
1417
|
if (parsed.json) {
|
|
1327
|
-
const written = await writeJsonDocument(JSON.stringify(
|
|
1418
|
+
const written = await writeJsonDocument(JSON.stringify(parsed.epicRunId !== null
|
|
1419
|
+
? { epic_run_id: parsed.epicRunId, status: "unknown", state: null }
|
|
1420
|
+
: { epic_key: parsed.epicKey, status: "unknown", state: null }));
|
|
1328
1421
|
if (!written)
|
|
1329
1422
|
return 1;
|
|
1330
1423
|
}
|
|
@@ -1672,6 +1765,64 @@ export async function runEpicImplementerCli(argv, likelyTestsDeps) {
|
|
|
1672
1765
|
}
|
|
1673
1766
|
return await runPrerequisiteInputsCommand(parsed.argv);
|
|
1674
1767
|
}
|
|
1768
|
+
case "epic-server": {
|
|
1769
|
+
// BAPI-1546: dispatched before any MCP server is built or connected. A
|
|
1770
|
+
// module-load failure gets fixed wording, never exception text.
|
|
1771
|
+
let runEpicServerCommand;
|
|
1772
|
+
try {
|
|
1773
|
+
({ runEpicServerCommand } = await import("./epic-server.js"));
|
|
1774
|
+
}
|
|
1775
|
+
catch {
|
|
1776
|
+
console.error("Error: epic-server could not be loaded; nothing was started or stopped.");
|
|
1777
|
+
return 1;
|
|
1778
|
+
}
|
|
1779
|
+
return await runEpicServerCommand(parsed.argv);
|
|
1780
|
+
}
|
|
1781
|
+
case "driver-guard": {
|
|
1782
|
+
// BAPI-1642: the Stop hook. Its own boundary: a load failure or any
|
|
1783
|
+
// exception allows the stop silently with exit 0, never the general
|
|
1784
|
+
// exit-1 error path below.
|
|
1785
|
+
try {
|
|
1786
|
+
const { runDriverGuardCommand } = await import("./driver-guard.js");
|
|
1787
|
+
return await runDriverGuardCommand(parsed.argv);
|
|
1788
|
+
}
|
|
1789
|
+
catch {
|
|
1790
|
+
return 0;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
case "driver-register": {
|
|
1794
|
+
let runDriverRegisterCommand;
|
|
1795
|
+
try {
|
|
1796
|
+
({ runDriverRegisterCommand } = await import("./driver-register.js"));
|
|
1797
|
+
}
|
|
1798
|
+
catch {
|
|
1799
|
+
console.error("Error: driver-register could not be loaded; the driver guard is not armed.");
|
|
1800
|
+
return 1;
|
|
1801
|
+
}
|
|
1802
|
+
return await runDriverRegisterCommand(parsed.argv);
|
|
1803
|
+
}
|
|
1804
|
+
case "driver-release": {
|
|
1805
|
+
let runDriverReleaseCommand;
|
|
1806
|
+
try {
|
|
1807
|
+
({ runDriverReleaseCommand } = await import("./driver-release.js"));
|
|
1808
|
+
}
|
|
1809
|
+
catch {
|
|
1810
|
+
console.error("Error: driver-release could not be loaded; nothing was released.");
|
|
1811
|
+
return 1;
|
|
1812
|
+
}
|
|
1813
|
+
return await runDriverReleaseCommand(parsed.argv);
|
|
1814
|
+
}
|
|
1815
|
+
case "declare-blocked": {
|
|
1816
|
+
let runDeclareBlockedCommand;
|
|
1817
|
+
try {
|
|
1818
|
+
({ runDeclareBlockedCommand } = await import("./declare-blocked.js"));
|
|
1819
|
+
}
|
|
1820
|
+
catch {
|
|
1821
|
+
console.error("Error: declare-blocked could not be loaded; nothing was escalated. Supervision continues.");
|
|
1822
|
+
return 1;
|
|
1823
|
+
}
|
|
1824
|
+
return await runDeclareBlockedCommand(parsed.argv);
|
|
1825
|
+
}
|
|
1675
1826
|
default:
|
|
1676
1827
|
console.error('Error: Unknown command. Run "epic-implementer --help" for usage.');
|
|
1677
1828
|
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
|
+
}
|