@bridge_gpt/mcp-server 0.2.70 → 0.2.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +10 -1
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +11 -1
  5. package/build/bounded-wait.js +9 -1
  6. package/build/bridge-permissions.js +13 -5
  7. package/build/commands.generated.js +3 -3
  8. package/build/conductor/bridge-api-client.js +260 -2
  9. package/build/conductor/command-drift-production.js +7 -2
  10. package/build/conductor/doctor.js +9 -3
  11. package/build/conductor/epic-implementer-cli.js +4 -0
  12. package/build/conductor/gate-discovery.js +524 -10
  13. package/build/conductor/gate-settings-review.js +451 -0
  14. package/build/conductor/launch-need-probes.js +16 -11
  15. package/build/conductor/launch-plan.js +145 -0
  16. package/build/conductor/precheck-timings.js +14 -0
  17. package/build/conductor/preview-observations.js +10 -0
  18. package/build/conductor/readiness-sections.js +4 -1
  19. package/build/conductor/recovery-cli.js +59 -2
  20. package/build/conductor/recovery-operations.js +45 -2
  21. package/build/docs.generated.js +1 -1
  22. package/build/drive-epic.js +188 -45
  23. package/build/epic-ci-workflow-drift.js +71 -23
  24. package/build/epic-ci-workflow-install.js +83 -26
  25. package/build/epic-ci-workflow-v1.js +132 -0
  26. package/build/epic-ci-workflow.js +174 -13
  27. package/build/epic-implementer-bin.js +18 -18
  28. package/build/executor/ci-rerun-job.js +220 -14
  29. package/build/executor/env.js +207 -3
  30. package/build/executor/gate-qualification-job.js +20 -5
  31. package/build/executor/job-runner.js +112 -11
  32. package/build/executor/likely-tests.js +6 -1
  33. package/build/executor/preflight.js +5 -0
  34. package/build/executor/process-containment.js +18 -0
  35. package/build/executor/prompt-spec.js +72 -13
  36. package/build/executor/reconcile-overlap-job.js +6 -1
  37. package/build/executor/worker-command.js +136 -1
  38. package/build/executor/worker-database.js +30 -11
  39. package/build/executor/worker-resources.js +12 -1
  40. package/build/executor/worker-verification-guidance.js +29 -0
  41. package/build/index.js +221 -165
  42. package/build/install-bridge-conductor-gate.js +195 -14
  43. package/build/install-bridge-conductor-setup.js +20 -6
  44. package/build/install-bridge-conductor.js +355 -37
  45. package/build/install-bridge.js +1 -1
  46. package/build/merge-workflow-install.js +20 -0
  47. package/build/pipelines.generated.js +2 -2
  48. package/build/plan-execution-ledger.js +23 -8
  49. package/build/plane/plane-freshness.js +6 -2
  50. package/build/plane/preflight.js +19 -0
  51. package/build/printed-remedy-commands.js +8 -1
  52. package/build/readme.generated.js +1 -1
  53. package/build/repository-toolchains.js +581 -0
  54. package/build/setup-epic.js +24 -7
  55. package/build/test-command-detection.js +58 -21
  56. package/build/ticket-delivery-artifacts.js +7 -0
  57. package/build/ticket-delivery-enrollment.js +67 -4
  58. package/build/version.generated.js +3 -3
  59. package/docs/EPIC-IMPLEMENTER.md +38 -0
  60. package/docs/epic-implementer/getting-started.md +58 -2
  61. package/package.json +2 -2
@@ -1,3 +1,5 @@
1
+ import { monotonicNow, elapsedMs, measurePrecheck } from "./conductor/precheck-timings.js";
2
+ import { buildLaunchPlan } from "./conductor/launch-plan.js";
1
3
  import { ticketReviewSummary } from "./ticket-review-summary.js";
2
4
  import { parseConductorReadinessResponse } from "./conductor/bridge-api-client.js";
3
5
  import { READINESS_PRE_CREATE_CODES, READINESS_PREREQUISITE_BY_ID, READINESS_LEGACY_IDS } from "./readiness-prerequisites.generated.js";
@@ -56,7 +58,7 @@ import { READINESS_PRE_CREATE_CODES, READINESS_PREREQUISITE_BY_ID, READINESS_LEG
56
58
  * ratcheted down, and a tool would be useless in a bare-chat session anyway,
57
59
  * where the model has no tool call to make.
58
60
  */
59
- import { access as fsAccess, readdir, readFile, stat as fsStat } from "node:fs/promises";
61
+ import { access as fsAccess, readdir, readFile, realpath, stat as fsStat } from "node:fs/promises";
60
62
  import { constants as fsConstants } from "node:fs";
61
63
  import path, { dirname, join } from "node:path";
62
64
  import { ConductorBridgeApiError, resolveEpicLaunchBridgeApiAccess, fetchConductorReadiness, fetchRepositoryUsageAdvisory, REPOSITORY_USAGE_ADVISORY_UNAVAILABLE, formatSchemaIncompatibleRefusal, isSchemaIncompatibleError, SCHEMA_INCOMPATIBLE_REPAIR_ROUTE, fetchEpicRunState, isProviderRepositoryIdentity, safeDiagnosticMessage, classifyChildMergeStatus as classifyChildMergeStatusClient, recordSkippedChildren as recordSkippedChildrenClient, } from "./conductor/bridge-api-client.js";
@@ -82,7 +84,7 @@ import { BRIDGE_LAUNCHER_ENV } from "./bridge-permissions.js";
82
84
  import { checkPlaneBuildFreshness, PLANE_BUILD_FIX_REMEDIATION } from "./plane/build-freshness.js";
83
85
  import { discoverEpicPlan, } from "./plan-discovery.js";
84
86
  import { formatPlaneDiagnostic, launchPlaneControlPlane, requestPlaneScopedLanes, runDefaultPlanePreflight, runPlaneCli, } from "./plane/cli.js";
85
- import { PLANE_PORT_PROBE_TIMEOUT_MS, describePlanePortOccupant, } from "./plane/preflight.js";
87
+ import { PLANE_PORT_PROBE_TIMEOUT_MS, describePlanePortOccupant, isBridgeEngineRepository, } from "./plane/preflight.js";
86
88
  import { createPlaneExecFile, createPlaneFsDeps, probeAutomationHealth, probeTcpPort, resolveHostname, } from "./plane/defaults.js";
87
89
  import { readPlaneManifest } from "./plane/manifest.js";
88
90
  import { cleanupTerminalRunPlane, createTerminalRunCleanupDeps, terminalRunCleanupStderrLine, } from "./plane/terminal-run-cleanup.js";
@@ -1060,6 +1062,7 @@ export async function readLiveEpicRunByKey(access, epicKey, fetchImpl = globalTh
1060
1062
  }
1061
1063
  return {
1062
1064
  kind: "live",
1065
+ state,
1063
1066
  epicRunId: run.epic_run_id,
1064
1067
  status: run.status,
1065
1068
  ticketReview: ticketReviewSummary(run.ticket_review),
@@ -1084,6 +1087,15 @@ export async function readLiveEpicRunByKey(access, epicKey, fetchImpl = globalTh
1084
1087
  }
1085
1088
  export function createDefaultDriveEpicDeps() {
1086
1089
  return {
1090
+ inspectRepositoryIdentity: async () => {
1091
+ const top = await createPlaneExecFile()("git", ["rev-parse", "--show-toplevel"], {
1092
+ cwd: process.cwd(), timeoutMs: 5000,
1093
+ });
1094
+ if (!top.ok || !path.isAbsolute(top.stdout.trim()))
1095
+ throw new Error("repository_root_unverifiable");
1096
+ const repoRoot = await realpath(top.stdout.trim());
1097
+ return { repoRoot, isBridge: await isBridgeEngineRepository(repoRoot, createPlaneFsDeps()) };
1098
+ },
1087
1099
  resolveAccess: async (repo, cwd, launch) => {
1088
1100
  // BAPI-1260: the target-first launch contract. BAPI-1272: with no target
1089
1101
  // selected it defaults to production, and a stored key is sent there only
@@ -1140,7 +1152,7 @@ export function createDefaultDriveEpicDeps() {
1140
1152
  }),
1141
1153
  inspectEpicBranchBehind: ({ repoRoot, branch, baseBranch }) => inspectEpicBranchBehindBase({ repoRoot, branch, baseBranch, execFile: createPlaneExecFile() }),
1142
1154
  fetchUsageAdvisory: (access) => fetchRepositoryUsageAdvisory(access),
1143
- inspectWorkerDatabase: createWorkerDatabaseDoctorInspector({ env: process.env, cwd: process.cwd() }),
1155
+ inspectWorkerDatabase: (repoRoot) => createWorkerDatabaseDoctorInspector({ env: process.env, cwd: repoRoot ?? process.cwd() })(),
1144
1156
  cleanupTerminalRunPlane: (input) => cleanupTerminalRunPlane(input, createTerminalRunCleanupDeps(process.env)),
1145
1157
  readRunState: async (access, epicRunId) => {
1146
1158
  const state = await fetchEpicRunState(access, epicRunId, globalThis.fetch);
@@ -1175,13 +1187,14 @@ export function createDefaultDriveEpicDeps() {
1175
1187
  readPlanDag: (filePath) => readFile(filePath, "utf8"),
1176
1188
  readPolicyFile: (filePath) => readFile(filePath, "utf8"),
1177
1189
  readLiveEpicRun: (access, epicKey) => readLiveEpicRunByKey(access, epicKey),
1178
- previewSetupEpic: async ({ argv, baseUrl, handoff }) => {
1190
+ previewSetupEpic: async ({ argv, baseUrl, handoff, observations }) => {
1179
1191
  const stdout = [];
1180
1192
  const stderr = [];
1181
1193
  const result = await runSetupEpicWorkflow(argv, {
1182
1194
  // A COPY carrying the resolved target: the preview never mutates
1183
1195
  // `process.env`, so a dry run leaves the process exactly as it found it.
1184
1196
  env: { ...process.env, BAPI_BASE_URL: baseUrl },
1197
+ previewObservations: observations,
1185
1198
  log: (message) => stdout.push(message),
1186
1199
  errorLog: (message) => stderr.push(message),
1187
1200
  }, handoff);
@@ -1722,8 +1735,8 @@ function escalate(deps, epicKey, reason) {
1722
1735
  function channelIdentityOf(label) {
1723
1736
  return label === "configured webhook" || label === "account email" ? label : "unavailable";
1724
1737
  }
1725
- async function prepareSetupSelection(ctx, coldStart = false) {
1726
- const live = coldStart ? { kind: "none" } : await ctx.deps.readLiveEpicRun(ctx.access, ctx.epicKey);
1738
+ async function prepareSetupSelection(ctx, coldStart = false, observedLive) {
1739
+ const live = coldStart ? { kind: "none" } : observedLive ?? await ctx.deps.readLiveEpicRun(ctx.access, ctx.epicKey);
1727
1740
  if (live.kind === "conflict")
1728
1741
  return { ok: false, reasonId: "live-run-ambiguous" };
1729
1742
  if (live.kind === "unknown")
@@ -2165,8 +2178,13 @@ async function previewLaunchCapability(ctx, readiness, topology) {
2165
2178
  if (!isUnattendedLaunch(options)) {
2166
2179
  return { checks: buildLaunchReadinessChecks(readiness, context), refusal: null };
2167
2180
  }
2168
- const evidence = await collectLaunchEvidence(deps, readiness, topology);
2169
- const checks = buildLaunchReadinessChecks(readiness, { ...context, launchEvidence: evidence });
2181
+ const durations = {};
2182
+ const [credential, worktree] = await Promise.all([
2183
+ measurePrecheck(() => collectCredentialEvidence(deps, readiness, topology), (ms) => { durations["conductor.merge-credential-capability"] = ms; }),
2184
+ measurePrecheck(() => collectWorktreeEvidence(deps, topology), (ms) => { durations["conductor.worktree-preparation"] = ms; }),
2185
+ ]);
2186
+ const evidence = { credential, worktree };
2187
+ const checks = buildLaunchReadinessChecks(readiness, { ...context, launchEvidence: evidence }).map((row) => ({ ...row, duration_ms: durations[row.id] ?? elapsedMs(monotonicNow()) }));
2170
2188
  const classification = classifyV2Readiness(readiness, { ...context, effectivePolicy: ctx.handoff?.selection }, evidence);
2171
2189
  if (classification.kind === "operator_blocked" && LAUNCH_REFUSAL_IDS.includes(classification.id)) {
2172
2190
  return {
@@ -2289,7 +2307,11 @@ async function collectHostSleep(ctx, repoRoot) {
2289
2307
  if (inspect === undefined)
2290
2308
  return null;
2291
2309
  const cache = ctx.freshness ?? createPlaneFreshnessCache();
2292
- cache.sleep ??= inspect(repoRoot).catch(() => null);
2310
+ cache.sleep ??= (async () => {
2311
+ const started = monotonicNow();
2312
+ const report = await inspect(repoRoot).catch(() => null);
2313
+ return report === null ? null : { ...report, duration_ms: elapsedMs(started) };
2314
+ })();
2293
2315
  return cache.sleep;
2294
2316
  }
2295
2317
  /**
@@ -2344,12 +2366,14 @@ boundRun) {
2344
2366
  let overridden = false;
2345
2367
  const flagNote = allowStalePlane ? "; overridden for this invocation by --allow-stale-plane" : "";
2346
2368
  const project = (id, label, report, refusal) => {
2369
+ const duration_ms = report.duration_ms ?? elapsedMs(monotonicNow());
2347
2370
  const { verdict, detail } = freshnessVerdictOf(report);
2348
2371
  if (verdict === "pass") {
2349
- rows.push({ id, label, status: "pass", blocking: false, detail: `pass — ${detail}` });
2372
+ rows.push({ duration_ms, id, label, status: "pass", blocking: false, detail: `pass — ${detail}` });
2350
2373
  }
2351
2374
  else if (verdict === "unverified") {
2352
2375
  rows.push({
2376
+ duration_ms,
2353
2377
  id,
2354
2378
  label,
2355
2379
  status: "warn",
@@ -2361,6 +2385,7 @@ boundRun) {
2361
2385
  else if (verdict === "refuse" && mode === "attach") {
2362
2386
  // Warning-only: an existing run is never stopped for freshness.
2363
2387
  rows.push({
2388
+ duration_ms,
2364
2389
  id,
2365
2390
  label,
2366
2391
  status: "warn",
@@ -2372,6 +2397,7 @@ boundRun) {
2372
2397
  else if (verdict === "refuse" && allowStalePlane) {
2373
2398
  overridden = true;
2374
2399
  rows.push({
2400
+ duration_ms,
2375
2401
  id,
2376
2402
  label,
2377
2403
  status: "fail",
@@ -2383,6 +2409,7 @@ boundRun) {
2383
2409
  else if (verdict === "refuse") {
2384
2410
  blockers.push(refusal);
2385
2411
  rows.push({
2412
+ duration_ms,
2386
2413
  id,
2387
2414
  label,
2388
2415
  status: "fail",
@@ -2403,12 +2430,14 @@ boundRun) {
2403
2430
  });
2404
2431
  }
2405
2432
  if (sleep !== null) {
2433
+ const duration_ms = sleep.duration_ms ?? elapsedMs(monotonicNow());
2406
2434
  const { verdict, detail } = freshnessVerdictOf(sleep);
2407
2435
  if (verdict === "skip") {
2408
- rows.push({ id: PLANE_HOST_SLEEP_ID, label: "Host sleep", status: "skip", blocking: false, detail: `not applicable — ${detail}` });
2436
+ rows.push({ duration_ms, id: PLANE_HOST_SLEEP_ID, label: "Host sleep", status: "skip", blocking: false, detail: `not applicable — ${detail}` });
2409
2437
  }
2410
2438
  else if (verdict === "unverified") {
2411
2439
  rows.push({
2440
+ duration_ms,
2412
2441
  id: PLANE_HOST_SLEEP_ID,
2413
2442
  label: "Host sleep",
2414
2443
  status: "warn",
@@ -2421,6 +2450,7 @@ boundRun) {
2421
2450
  // BAPI-1506: a battery or lid advisory is a warning with its remedy, not
2422
2451
  // a pass. It still never blocks.
2423
2452
  rows.push({
2453
+ duration_ms,
2424
2454
  id: PLANE_HOST_SLEEP_ID,
2425
2455
  label: "Host sleep",
2426
2456
  status: "warn",
@@ -2431,7 +2461,7 @@ boundRun) {
2431
2461
  }
2432
2462
  else {
2433
2463
  // Readable evidence never blocks setup. "pass" means exactly that.
2434
- rows.push({ id: PLANE_HOST_SLEEP_ID, label: "Host sleep", status: "pass", blocking: false, detail: `pass — ${detail}` });
2464
+ rows.push({ duration_ms, id: PLANE_HOST_SLEEP_ID, label: "Host sleep", status: "pass", blocking: false, detail: `pass — ${detail}` });
2435
2465
  }
2436
2466
  }
2437
2467
  return { rows, blockers, overridden };
@@ -2548,7 +2578,7 @@ async function collectWorkerDatabaseAdvisory(deps, baseUrl, cache) {
2548
2578
  return null;
2549
2579
  const run = async () => {
2550
2580
  let failed = false;
2551
- const section = await collectWorkerDatabaseDoctorSection(inspect, WORKER_DATABASE_DOCTOR_TIMEOUT_MS, (failure) => {
2581
+ const section = await collectWorkerDatabaseDoctorSection(() => inspect(deps.cwd()), WORKER_DATABASE_DOCTOR_TIMEOUT_MS, (failure) => {
2552
2582
  failed = true;
2553
2583
  deps.errorLog(`worker-db inspection failed: ${failure}`);
2554
2584
  }).catch(() => null);
@@ -2599,7 +2629,13 @@ async function surfaceWorkerDatabaseAdvisory(ctx) {
2599
2629
  * inspector and its JSON is unchanged. Never changes the decision, a refusal,
2600
2630
  * readiness, or the exit code.
2601
2631
  */
2602
- async function appendWorkerDatabaseAdvisoryRows(deps, preview) {
2632
+ async function appendWorkerDatabaseAdvisoryRows(deps, preview, repository) {
2633
+ if (repository?.isBridge === false) {
2634
+ preview.launch_checks = [...(preview.launch_checks ?? []), ...nonBridgeRows(WORKER_DATABASE_PREVIEW_IDS)];
2635
+ return null;
2636
+ }
2637
+ if (repository === undefined)
2638
+ return null;
2603
2639
  if (preview.target.kind !== "local_plane")
2604
2640
  return null;
2605
2641
  try {
@@ -3462,16 +3498,28 @@ export const DRIVE_EPIC_ACCESS_REFUSAL_REASON_IDS = {
3462
3498
  "credentials-unavailable": "access-credentials-unavailable",
3463
3499
  "credential-unbound": "access-credential-unbound",
3464
3500
  };
3501
+ const WORKER_DATABASE_PREVIEW_IDS = ["worker-db-role", "worker-db-boundary", "worker-db-alembic", "worker-db-leftovers", "worker-db-unverifiable", "worker-db-harness"];
3502
+ function nonBridgeRows(ids) {
3503
+ return ids.map((id) => {
3504
+ const started = monotonicNow();
3505
+ return { id, label: id, status: "skip", blocking: false,
3506
+ reason: "not_bridge_repository", detail: "not_bridge_repository", duration_ms: elapsedMs(started) };
3507
+ });
3508
+ }
3465
3509
  /** BAPI-1452 — project launch rows into the stable preview shape. */
3466
3510
  function previewLaunchRows(checks) {
3467
- return checks.map((check) => ({
3468
- id: check.id,
3469
- label: check.label,
3470
- status: check.status,
3471
- blocking: check.blocking,
3472
- ...(check.detail ? { detail: check.detail } : {}),
3473
- ...(check.remediation ? { remedy: check.remediation } : {}),
3474
- }));
3511
+ return checks.map((check) => {
3512
+ const started = monotonicNow();
3513
+ return {
3514
+ duration_ms: check.duration_ms ?? elapsedMs(started),
3515
+ id: check.id,
3516
+ label: check.label,
3517
+ status: check.status,
3518
+ blocking: check.blocking,
3519
+ ...(check.detail ? { detail: check.detail } : {}),
3520
+ ...(check.remediation ? { remedy: check.remediation } : {}),
3521
+ };
3522
+ });
3475
3523
  }
3476
3524
  /** The readiness reason a preview reports for a generic not-ready engine. */
3477
3525
  const ENGINE_NOT_READY_REASON_ID = "engine-not-ready";
@@ -3578,9 +3626,21 @@ async function readPlanChildCount(deps, planPath) {
3578
3626
  * named refusal in the same document.
3579
3627
  */
3580
3628
  async function runDriveEpicPreview(deps, options) {
3629
+ const started = monotonicNow();
3630
+ const timings = {};
3631
+ const original = deps;
3632
+ const timed = (phase, run) => measurePrecheck(run, (duration) => { timings[phase] = duration; });
3633
+ deps = {
3634
+ ...original,
3635
+ inspectRepositoryIdentity: () => timed("repository_identity_ms", () => original.inspectRepositoryIdentity()),
3636
+ readReadiness: (access) => timed("readiness_ms", () => original.readReadiness(access)),
3637
+ readLiveEpicRun: (access, epic) => timed("live_run_ms", () => original.readLiveEpicRun(access, epic)),
3638
+ previewSetupEpic: (args) => timed("setup_preview_ms", () => original.previewSetupEpic(args)),
3639
+ };
3581
3640
  const { epicKey } = options;
3582
3641
  const posture = options.attended === true || options.intoBase === true ? "attended" : "unattended";
3583
3642
  const preview = {
3643
+ timings,
3584
3644
  epic_key: epicKey,
3585
3645
  target: { base_url: null, kind: null },
3586
3646
  readiness: { kind: "unknown" },
@@ -3621,7 +3681,7 @@ async function runDriveEpicPreview(deps, options) {
3621
3681
  // `null` when no read succeeded, which the row reports as unconfirmed.
3622
3682
  const observed = { readiness: null };
3623
3683
  try {
3624
- await previewDecision(deps, options, preview, refuseWithReadiness, refuseTopLevel, observed);
3684
+ await timed("decision_ms", () => previewDecision(deps, options, preview, refuseWithReadiness, refuseTopLevel, observed));
3625
3685
  }
3626
3686
  catch {
3627
3687
  // Sanitized on purpose: nothing from the thrown value reaches the document.
@@ -3633,10 +3693,46 @@ async function runDriveEpicPreview(deps, options) {
3633
3693
  });
3634
3694
  }
3635
3695
  ensureRefusalExplained(preview);
3636
- const workerDatabase = await appendWorkerDatabaseAdvisoryRows(deps, preview);
3637
- appendEscalationReachabilityRow(preview, observed.readiness);
3638
- await appendExecutorBuildFreshnessWarning(deps, preview);
3639
- await appendLaunchNeedRows(deps, preview, observed, workerDatabase);
3696
+ if (observed.repository?.isBridge === false && !preview.launch_checks?.some((row) => row.id === "plane-snapshot-freshness")) {
3697
+ preview.launch_checks = [...(preview.launch_checks ?? []), ...nonBridgeRows(["plane-snapshot-freshness", "plane-database-head"])];
3698
+ }
3699
+ const isolated = () => ({ ...preview, launch_checks: [] });
3700
+ const worker = isolated();
3701
+ const escalation = isolated();
3702
+ const executor = isolated();
3703
+ const needs = isolated();
3704
+ const scopeBase = previewScopeBaseBranch.get(preview);
3705
+ if (scopeBase)
3706
+ previewScopeBaseBranch.set(needs, scopeBase);
3707
+ // Collect into private arrays; only launch-needs waits for the worker result.
3708
+ const workerTask = timed("worker_database_ms", () => appendWorkerDatabaseAdvisoryRows(deps, worker, observed.repository));
3709
+ const needsTask = workerTask.then((section) => {
3710
+ needs.launch_checks = [...(worker.launch_checks ?? [])];
3711
+ return timed("launch_needs_ms", () => appendLaunchNeedRows(deps, needs, observed, section));
3712
+ });
3713
+ await Promise.all([
3714
+ needsTask,
3715
+ timed("escalation_ms", async () => { appendEscalationReachabilityRow(escalation, observed.readiness); }),
3716
+ timed("executor_build_ms", () => appendExecutorBuildFreshnessWarning(deps, executor)),
3717
+ ]);
3718
+ const workerIds = new Set(worker.launch_checks?.map((row) => row.id));
3719
+ const needRows = needs.launch_checks ?? [];
3720
+ preview.launch_checks = [
3721
+ ...(preview.launch_checks ?? []), ...needRows.filter((row) => workerIds.has(row.id)),
3722
+ ...(escalation.launch_checks ?? []), ...(executor.launch_checks ?? []),
3723
+ ...needRows.filter((row) => !workerIds.has(row.id)),
3724
+ ];
3725
+ if (preview.decision === "create") {
3726
+ try {
3727
+ const result = (deps.buildLaunchPlan ?? buildLaunchPlan)(preview);
3728
+ if (result)
3729
+ preview.launch_plan = result.launch_plan;
3730
+ }
3731
+ catch {
3732
+ deps.errorLog("Launch plan unavailable; the driving session will compute it.");
3733
+ }
3734
+ }
3735
+ timings.total_ms = elapsedMs(started);
3640
3736
  const emitted = await emitPreview(deps, options, preview);
3641
3737
  // BAPI-1397 (F3): a `--json` document that could not reach stdout whole is a
3642
3738
  // failed preview, never a silently truncated one.
@@ -3655,6 +3751,7 @@ async function runDriveEpicPreview(deps, options) {
3655
3751
  * A refused or stopped preview describes no launch, so it gets none.
3656
3752
  */
3657
3753
  function appendEscalationReachabilityRow(preview, readiness) {
3754
+ const started = monotonicNow();
3658
3755
  if (preview.decision !== "create" && preview.decision !== "attach")
3659
3756
  return;
3660
3757
  const [row] = previewLaunchRows([
@@ -3662,7 +3759,7 @@ function appendEscalationReachabilityRow(preview, readiness) {
3662
3759
  ]);
3663
3760
  preview.launch_checks = [
3664
3761
  ...(preview.launch_checks ?? []).filter((existing) => existing.id !== ESCALATION_REACHABILITY_CHECK_ID),
3665
- row,
3762
+ { ...row, duration_ms: elapsedMs(started) },
3666
3763
  ];
3667
3764
  }
3668
3765
  /**
@@ -3674,6 +3771,7 @@ function appendEscalationReachabilityRow(preview, readiness) {
3674
3771
  * fixed line and nothing from the exception.
3675
3772
  */
3676
3773
  async function appendExecutorBuildFreshnessWarning(deps, preview) {
3774
+ const started = monotonicNow();
3677
3775
  const override = process.env[BRIDGE_LAUNCHER_ENV];
3678
3776
  if (override === undefined || override.trim() === "")
3679
3777
  return;
@@ -3686,6 +3784,7 @@ async function appendExecutorBuildFreshnessWarning(deps, preview) {
3686
3784
  const outcome = report.outcomes.find((entry) => entry.status === "warn" || entry.status === "fail") ?? report.outcomes[0];
3687
3785
  const row = {
3688
3786
  id: "executor-build-freshness",
3787
+ duration_ms: elapsedMs(started),
3689
3788
  label: outcome?.label ?? "Executor build freshness",
3690
3789
  status: "warn",
3691
3790
  blocking: false,
@@ -3745,24 +3844,26 @@ async function appendLaunchNeedRows(deps, preview, observed, workerDatabase) {
3745
3844
  if (preview.decision !== "create")
3746
3845
  return;
3747
3846
  try {
3748
- const repoRoot = deps.cwd();
3847
+ const repoRoot = observed.repository?.repoRoot ?? deps.cwd();
3749
3848
  const local = preview.target.kind === "local_plane";
3750
3849
  const readiness = observed.readiness;
3751
3850
  const access = observed.access;
3752
3851
  const nowMs = (deps.now ?? Date.now)();
3852
+ const durations = [];
3853
+ const measured = (index, work) => measurePrecheck(work, (duration) => { durations[index] = duration; });
3753
3854
  const [runner, power, usage, branch] = await Promise.all([
3754
- guardedProbe(deps.inspectRequiredRunners === undefined
3855
+ measured(0, () => guardedProbe(deps.inspectRequiredRunners === undefined
3755
3856
  ? undefined
3756
3857
  : () => deps.inspectRequiredRunners({
3757
3858
  repoRoot,
3758
3859
  providerRepository: readiness?.provider_repository,
3759
3860
  gateProfile: readiness?.gate_profile,
3760
- }), { state: "unverifiable", reason: "probe_failed" }),
3761
- guardedProbe(() => collectHostPowerFact(deps, observed.launchTopology), { state: "unverifiable", reason: "probe_failed" }),
3762
- guardedProbe(deps.fetchUsageAdvisory === undefined || access === undefined
3861
+ }), { state: "unverifiable", reason: "probe_failed" })),
3862
+ measured(1, () => guardedProbe(() => collectHostPowerFact(deps, observed.launchTopology), { state: "unverifiable", reason: "probe_failed" })),
3863
+ measured(2, () => guardedProbe(deps.fetchUsageAdvisory === undefined || access === undefined
3763
3864
  ? undefined
3764
- : () => deps.fetchUsageAdvisory(access), null),
3765
- guardedProbe(deps.inspectEpicBranchBehind === undefined
3865
+ : () => deps.fetchUsageAdvisory(access), null)),
3866
+ measured(3, () => guardedProbe(deps.inspectEpicBranchBehind === undefined
3766
3867
  ? undefined
3767
3868
  : () => deps.inspectEpicBranchBehind({
3768
3869
  repoRoot,
@@ -3770,9 +3871,12 @@ async function appendLaunchNeedRows(deps, preview, observed, workerDatabase) {
3770
3871
  baseBranch: previewScopeBaseBranch.get(preview) ?? null,
3771
3872
  }), preview.summary.branch === null
3772
3873
  ? { state: "not_applicable", reason: "no_epic_branch" }
3773
- : { state: "unverifiable", reason: "git_failed" }),
3874
+ : { state: "unverifiable", reason: "git_failed" })),
3774
3875
  ]);
3775
- const workerRow = buildWorkerDbRoleLaunchRow(workerDatabase, local);
3876
+ const workerRow = observed.repository?.isBridge === false
3877
+ ? { ...nonBridgeRows(["worker-db-role"])[0], launch_need: { need: "worker_db_role", state: "not_applicable", asked: false } }
3878
+ : { ...buildWorkerDbRoleLaunchRow(workerDatabase, local),
3879
+ duration_ms: workerDatabase?.rows.find((row) => row.id === "worker-db-role")?.duration_ms ?? elapsedMs(monotonicNow()) };
3776
3880
  const rows = [
3777
3881
  buildSelfHostedRunnerLaunchRow(runner),
3778
3882
  buildHostPowerLaunchRow(power),
@@ -3782,7 +3886,7 @@ async function appendLaunchNeedRows(deps, preview, observed, workerDatabase) {
3782
3886
  nowMs,
3783
3887
  }),
3784
3888
  buildEpicBranchBehindBaseLaunchRow(branch),
3785
- ];
3889
+ ].map((row, index) => ({ ...row, duration_ms: durations[index] }));
3786
3890
  const existing = preview.launch_checks ?? [];
3787
3891
  const roleIndex = existing.findIndex((row) => row.id === workerRow.id);
3788
3892
  const merged = roleIndex >= 0
@@ -3830,6 +3934,18 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
3830
3934
  reasonId: READINESS_UNKNOWN_REASON_ID,
3831
3935
  remedy: ESCALATE_REMEDY,
3832
3936
  });
3937
+ try {
3938
+ observed.repository = await deps.inspectRepositoryIdentity();
3939
+ // This deps object is invocation-owned; subsequent relative probes use the
3940
+ // verified Git toplevel even when the command started in a subdirectory.
3941
+ deps.cwd = () => observed.repository.repoRoot;
3942
+ }
3943
+ catch {
3944
+ return refuseTopLevel({
3945
+ reasonId: "repository-identity-unverifiable",
3946
+ remedy: "Resolve the invocation Git worktree and its marker-file permissions, then preview again.",
3947
+ });
3948
+ }
3833
3949
  // --- Target: resolved, never adopted. -------------------------------------
3834
3950
  const accessResult = await deps.resolveAccess(options.repo, undefined, launchSelectionOf(options));
3835
3951
  if (!accessResult.ok) {
@@ -3866,6 +3982,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
3866
3982
  options,
3867
3983
  access,
3868
3984
  profile,
3985
+ previewRepository: observed.repository,
3869
3986
  targetSource: accessResult.targetSource ?? "default",
3870
3987
  freshness: createPlaneFreshnessCache(),
3871
3988
  launchCredential: {},
@@ -3916,7 +4033,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
3916
4033
  `${SCHEMA_INCOMPATIBLE_REPAIR_ROUTE} Nothing was created or started.`,
3917
4034
  });
3918
4035
  }
3919
- if (planPath !== undefined && endpoint !== null && profile?.executionMode !== "durable" &&
4036
+ if (observed.repository.isBridge && planPath !== undefined && endpoint !== null && profile?.executionMode !== "durable" &&
3920
4037
  err instanceof ConductorBridgeApiError && err.kind === "network") {
3921
4038
  const probe = await deps.probePlanePort(endpoint.host, endpoint.port).catch(() => ({ kind: "error" }));
3922
4039
  if (probe.kind === "refused") {
@@ -3993,7 +4110,13 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
3993
4110
  const attachingDiscoveredPlan = options.planFile === undefined && plan.status === "found" && live.kind === "live";
3994
4111
  const effectivePlanPath = attachingDiscoveredPlan ? undefined : planPath;
3995
4112
  const previewCtx = { ...ctx, options: { ...options, ...(effectivePlanPath ? { planFile: effectivePlanPath } : {}) } };
3996
- const prepared = effectivePlanPath ? await prepareSetupSelection(previewCtx) : null;
4113
+ const observations = {
4114
+ endpoint: access.baseUrl, repository: access.repoName, epic: epicKey,
4115
+ readiness: { state: "supplied", value: readiness },
4116
+ liveRun: live.kind === "none" ? { state: "absent" }
4117
+ : live.kind === "live" && live.state ? { state: "supplied", value: live.state } : { state: "error" },
4118
+ };
4119
+ const prepared = effectivePlanPath ? await prepareSetupSelection(previewCtx, false, live) : null;
3997
4120
  if (prepared !== null && !prepared.ok) {
3998
4121
  return refuseTopLevel({
3999
4122
  reasonId: prepared.reasonId,
@@ -4010,7 +4133,7 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
4010
4133
  if (classification.kind === 'operator_blocked') {
4011
4134
  const requirement = V2_READINESS_REQUIREMENTS.find(req => req.id === classification.id);
4012
4135
  if (requirement)
4013
- preview.launch_checks = [{ id: requirement.id, label: requirement.describe, status: 'fail', blocking: true, remedy: classification.remedy }];
4136
+ preview.launch_checks = [{ id: requirement.id, label: requirement.describe, status: 'fail', blocking: true, remedy: classification.remedy, duration_ms: elapsedMs(monotonicNow()) }];
4014
4137
  }
4015
4138
  const selection = selectConductor(readiness);
4016
4139
  // --- The live run. Conflict and unknown refuse whatever the plan says. ------
@@ -4078,13 +4201,15 @@ async function previewDecision(deps, options, preview, refuseWithReadiness, refu
4078
4201
  const launchTopology = planeTarget && classification.kind === "runtime_only"
4079
4202
  ? { kind: "plane_lane" }
4080
4203
  : topology.value ?? { kind: "local", repoRoot: null };
4204
+ const mergedEvaluation = live.kind !== "live" && options.noMergedCheck !== true
4205
+ ? evaluateMergedChildren(ctx, planPathForCreate).catch(() => notChecked("check_failed")) : undefined;
4081
4206
  const launch = await previewLaunchCapability(prepared?.ok ? { ...previewCtx, handoff: prepared.handoff } : previewCtx, readiness, launchTopology);
4082
4207
  preview.launch_checks = previewLaunchRows(launch.checks);
4083
4208
  if (launch.refusal !== null)
4084
4209
  return refuseWithReadiness("operator_blocked", launch.refusal);
4085
4210
  observed.access = access;
4086
4211
  observed.launchTopology = launchTopology;
4087
- await finalizeCreatePreview(prepared?.ok ? { ...previewCtx, handoff: prepared.handoff } : previewCtx, preview, planPathForCreate, false, refuseTopLevel, live.kind === "live");
4212
+ await finalizeCreatePreview(prepared?.ok ? { ...previewCtx, handoff: prepared.handoff, previewObservations: observations, previewMergedEvaluation: mergedEvaluation } : { ...previewCtx, previewObservations: observations, previewMergedEvaluation: mergedEvaluation }, preview, planPathForCreate, false, refuseTopLevel, live.kind === "live");
4088
4213
  await applyPreviewFreshness(ctx, preview, topology, false);
4089
4214
  }
4090
4215
  async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTopLevel, liveRunKnown = false) {
@@ -4106,6 +4231,10 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
4106
4231
  ? "webhook"
4107
4232
  : prepared.handoff.selection.escalationChannel === "account email" ? "email" : null;
4108
4233
  }
4234
+ // Compatibility path when no trusted repository-applicability fact is supplied.
4235
+ // Unknown is advisory, not a prerequisite on the sibling identity gate. Neither
4236
+ // declared paths nor target topology can establish repository identity.
4237
+ preview.plan_database_relevance = "unknown";
4109
4238
  preview.summary.child_count = await readPlanChildCount(deps, planPath);
4110
4239
  preview.summary.children_to_run = preview.summary.child_count;
4111
4240
  // BAPI-1510 — the already-merged check, after plan discovery and BEFORE the
@@ -4123,7 +4252,7 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
4123
4252
  preview.already_done_children = { status: "not_checked", reason: "cold_start", children: [] };
4124
4253
  }
4125
4254
  else {
4126
- evaluation = await evaluateMergedChildren(ctx, planPath);
4255
+ evaluation = await (ctx.previewMergedEvaluation ?? evaluateMergedChildren(ctx, planPath));
4127
4256
  preview.already_done_children = evaluation.state;
4128
4257
  if (evaluation.refusals.length > 0) {
4129
4258
  return refuseTopLevel({
@@ -4150,6 +4279,7 @@ async function finalizeCreatePreview(ctx, preview, planPath, coldStart, refuseTo
4150
4279
  const runPreviewSetup = (effectivePlanPath) => deps.previewSetupEpic({
4151
4280
  argv: [...buildSetupEpicArgv({ ...options, planFile: effectivePlanPath }), ...(coldStart ? ["--local-only"] : []), "--dry-run", "--json"],
4152
4281
  baseUrl: access.baseUrl,
4282
+ observations: ctx.previewObservations,
4153
4283
  handoff: trim !== null ? { ...prepared.handoff, expectedCutCommitSha: trim.cut } : prepared.handoff,
4154
4284
  });
4155
4285
  const setup = trim !== null
@@ -4247,6 +4377,10 @@ function previewReadinessRefusal(ctx, classification, readiness, planeTarget, pa
4247
4377
  async function applyPreviewFreshness(ctx, preview, topology, coldStart) {
4248
4378
  if (preview.decision !== "create" && preview.decision !== "attach")
4249
4379
  return;
4380
+ if (ctx.previewRepository?.isBridge === false) {
4381
+ preview.launch_checks = [...(preview.launch_checks ?? []), ...nonBridgeRows(["plane-snapshot-freshness", "plane-database-head"])];
4382
+ return;
4383
+ }
4250
4384
  const { deps } = ctx;
4251
4385
  if (planeEndpointForBaseUrl(deps, ctx.access.baseUrl) === null)
4252
4386
  return;
@@ -4308,7 +4442,7 @@ topologyOut) {
4308
4442
  ? null
4309
4443
  : durableCoverageRefusal(epicKey, access, profile, coverage, outcome);
4310
4444
  }
4311
- if (planeTarget) {
4445
+ if (planeTarget && ctx.previewRepository?.isBridge !== false) {
4312
4446
  if (live !== null) {
4313
4447
  const manifest = await findAttachablePlane(ctx).catch(() => null);
4314
4448
  if (topologyOut)
@@ -4491,7 +4625,16 @@ async function emitPreview(deps, options, preview) {
4491
4625
  lines.push(` skipped: ${skipped.path} (${skipped.reason})`);
4492
4626
  }
4493
4627
  const s = preview.summary;
4494
- 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"}`, ` Auto-merge: ${s.auto_merge_scope ?? "n/a"}`, ` Escalation: ${s.escalation_channel ?? "n/a"}`, ...reachabilityLines(preview), ` Validation: ${preview.cold_start ? "Partial — plane is not yet running" : s.server_validation ?? "n/a"}`, ` Decision: ${preview.decision}`);
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"}`, ` Auto-merge: ${s.auto_merge_scope ?? "n/a"}`, ` Escalation: ${s.escalation_channel ?? "n/a"}`, ...reachabilityLines(preview), ...(preview.launch_plan ? [
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}`);
4495
4638
  if (isPlaneDownStop(preview)) {
4496
4639
  // The shared stop text, verbatim and unindented, so it reads exactly as the
4497
4640
  // real launch prints it. It is a stop, not a refusal.