@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.
Files changed (146) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +3 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-permissions.js +27 -0
  5. package/build/ci-system-detection.js +50 -0
  6. package/build/ci-trigger-adapters.js +631 -0
  7. package/build/ci-trigger-install.js +106 -0
  8. package/build/codex-launcher-pin.js +33 -2
  9. package/build/codex-skill-adapter.js +3 -1
  10. package/build/command-host.js +33 -0
  11. package/build/commands.generated.js +7 -6
  12. package/build/conductor/bridge-api-client.js +842 -35
  13. package/build/conductor/bring-up-facts.js +18 -5
  14. package/build/conductor/command-drift-production.js +42 -17
  15. package/build/conductor/command-drift.js +47 -0
  16. package/build/conductor/declare-blocked.js +554 -0
  17. package/build/conductor/doctor.js +106 -21
  18. package/build/conductor/driver-commands.js +141 -0
  19. package/build/conductor/driver-guard.js +277 -0
  20. package/build/conductor/driver-lapse.js +321 -0
  21. package/build/conductor/driver-register.js +176 -0
  22. package/build/conductor/driver-release.js +174 -0
  23. package/build/conductor/driver-session-state.js +315 -0
  24. package/build/conductor/epic-branch-ci-inspection.js +222 -29
  25. package/build/conductor/epic-implementer-cli.js +166 -15
  26. package/build/conductor/epic-server-database.js +162 -0
  27. package/build/conductor/epic-server-guidance.js +278 -0
  28. package/build/conductor/epic-server-journal.js +239 -0
  29. package/build/conductor/epic-server-processes.js +324 -0
  30. package/build/conductor/epic-server-recipe.js +397 -0
  31. package/build/conductor/epic-server-runtime.js +1207 -0
  32. package/build/conductor/epic-server-sfcc.js +107 -0
  33. package/build/conductor/epic-server-state.js +427 -0
  34. package/build/conductor/epic-server.js +594 -0
  35. package/build/conductor/gate-discovery.js +150 -5
  36. package/build/conductor/gate-settings-review.js +224 -4
  37. package/build/conductor/launch-need-probes.js +6 -53
  38. package/build/conductor/launch-plan.js +313 -156
  39. package/build/conductor/prerequisite-inputs.js +879 -45
  40. package/build/conductor/readiness-assessment.js +16 -1
  41. package/build/conductor/readiness-cli.js +20 -9
  42. package/build/conductor/readiness-prerequisites.js +28 -9
  43. package/build/conductor/readiness-sections.js +133 -126
  44. package/build/conductor/readiness.js +1 -1
  45. package/build/conductor/recovery-cli.js +13 -2
  46. package/build/conductor/tools.js +6 -5
  47. package/build/conductor/wait-run-attention.js +2 -2
  48. package/build/conductor/wait-run-cli.js +208 -22
  49. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  50. package/build/conductor/worker-setup-tally.js +27 -0
  51. package/build/credential-store.js +71 -1
  52. package/build/dependency-install-declarations.js +55 -0
  53. package/build/docs.generated.js +2 -2
  54. package/build/doctor.js +54 -3
  55. package/build/drive-epic-help.js +21 -2
  56. package/build/drive-epic.js +1811 -351
  57. package/build/engine-paths.js +20 -0
  58. package/build/epic-branch-ci-summary.js +140 -0
  59. package/build/epic-capability-statement.js +107 -0
  60. package/build/epic-ci-workflow-drift.js +30 -15
  61. package/build/epic-ci-workflow-install.js +110 -42
  62. package/build/epic-ci-workflow-v2.js +274 -0
  63. package/build/epic-ci-workflow.js +38 -12
  64. package/build/epic-implementer-bin.js +2101 -44
  65. package/build/epic-launch-context.js +607 -0
  66. package/build/epic-server-record.js +273 -0
  67. package/build/epic-shared/bridge-client.js +11 -3
  68. package/build/escalation-reachability.js +43 -0
  69. package/build/executor/ci-fix-test-runs.js +334 -0
  70. package/build/executor/completion-contract.js +8 -1
  71. package/build/executor/env.js +59 -22
  72. package/build/executor/epic-server-context.js +141 -0
  73. package/build/executor/gate-qualification-job.js +127 -26
  74. package/build/executor/http-client.js +52 -5
  75. package/build/executor/job-runner.js +423 -69
  76. package/build/executor/observation.js +8 -0
  77. package/build/executor/pre-pr-checks.js +363 -0
  78. package/build/executor/prompt-spec.js +114 -2
  79. package/build/executor/reconcile-overlap-job.js +5 -3
  80. package/build/executor/required-work-diagnostics.js +4 -2
  81. package/build/executor/required-work-ledger.js +936 -38
  82. package/build/executor/results.js +58 -0
  83. package/build/executor/terminal-mutation.js +8 -0
  84. package/build/executor/worker-command.js +72 -3
  85. package/build/executor/worker-database-config.js +281 -0
  86. package/build/executor/worker-database-target.js +16 -12
  87. package/build/executor/worker-database.js +320 -101
  88. package/build/executor/worker-finalization.js +7 -1
  89. package/build/executor/worker-resources.js +25 -3
  90. package/build/executor/worker-verification-guidance.js +18 -3
  91. package/build/executor/worktree.js +20 -1
  92. package/build/executor-launch.js +54 -2
  93. package/build/generated-assets-catalog.js +2 -2
  94. package/build/index.js +664 -335
  95. package/build/init.js +26 -11
  96. package/build/install-bridge-conductor-answers.js +465 -0
  97. package/build/install-bridge-conductor-apply.js +259 -0
  98. package/build/install-bridge-conductor-assessment.js +895 -0
  99. package/build/install-bridge-conductor-compact.js +161 -0
  100. package/build/install-bridge-conductor-contracts.js +63 -0
  101. package/build/install-bridge-conductor-gate.js +1197 -196
  102. package/build/install-bridge-conductor-setup.js +535 -79
  103. package/build/install-bridge-conductor.js +2885 -560
  104. package/build/install-bridge.js +199 -21
  105. package/build/install-maintenance.js +26 -3
  106. package/build/launcher-config-inspection.js +162 -1
  107. package/build/mcp-grant-candidates.js +767 -0
  108. package/build/mcp-grant-doctor.js +63 -0
  109. package/build/mcp-grant.js +288 -0
  110. package/build/mcp-host-targets.js +8 -0
  111. package/build/mcp-identity.js +23 -0
  112. package/build/mcp-invoke.js +126 -13
  113. package/build/mcp-presets.js +107 -0
  114. package/build/mcp-provisioning.js +134 -2
  115. package/build/mcp-registration-doctor.js +31 -2
  116. package/build/mcp-server-invocation.js +6 -1
  117. package/build/merge-workflow-install.js +234 -109
  118. package/build/pipelines.generated.js +5 -5
  119. package/build/plan-discovery.js +97 -4
  120. package/build/plan-execution-ledger.js +100 -7
  121. package/build/plan-generation-io.js +262 -0
  122. package/build/plan-generation.js +424 -0
  123. package/build/plane/build-freshness.js +6 -1
  124. package/build/plane/cli.js +75 -9
  125. package/build/plane/plane-freshness.js +17 -0
  126. package/build/plane/preflight.js +50 -10
  127. package/build/plane/shutdown.js +19 -0
  128. package/build/plane/terminal-run-cleanup.js +18 -4
  129. package/build/printed-remedy-commands.js +206 -12
  130. package/build/readiness-check.js +77 -0
  131. package/build/readiness-prerequisites.generated.js +122 -14
  132. package/build/readme.generated.js +1 -1
  133. package/build/repository-state-paths.js +38 -0
  134. package/build/run-unit-tests-launcher.js +8 -1
  135. package/build/setup-epic.js +1190 -196
  136. package/build/setup-progress.js +44 -0
  137. package/build/setup-question.js +122 -4
  138. package/build/third-party-mcp-targets.js +30 -0
  139. package/build/ticket-delivery-enrollment.js +9 -0
  140. package/build/upgrade-cli.js +85 -2
  141. package/build/v2-readiness-requirements.js +28 -1
  142. package/build/version.generated.js +3 -3
  143. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  144. package/docs/epic-implementer/getting-started.md +3 -1
  145. package/docs/epic-implementer/self-hosting.md +14 -1
  146. package/package.json +2 -2
@@ -12,7 +12,7 @@
12
12
  * it — including any manifest belonging to a plane that is already running.
13
13
  */
14
14
  import path from "path";
15
- import { PLANE_SERVER_PORT_ENV_VAR, planeCheckFinding, planeCheckPassed, } from "./types.js";
15
+ import { PLANE_SERVER_PORT_ENV_VAR, planeCheckFinding, planeCheckPassed, planeCheckSkipped, } from "./types.js";
16
16
  import { runLegacyEpicImplementerEnvPreflight } from "../epic-implementer-env.js";
17
17
  import { checkPlaneBuildFreshness, checkPlaneRuntimeEntrypoint } from "./build-freshness.js";
18
18
  import { checkAlembicHead } from "./alembic-head.js";
@@ -21,6 +21,36 @@ import { detectClaudeLogin, formatClaudeLoginAdvisory } from "../claude-login.js
21
21
  import { createReadinessCheck, createReadinessCheckSafely, } from "../readiness-check.js";
22
22
  /** Files that must exist for a path to be this repository's root. */
23
23
  const REQUIRED_REPO_FILES = ["main.py", "worker.py", "alembic.ini"];
24
+ /** The four markers that identify a Bridge API engine checkout (BAPI-1595). */
25
+ export const BRIDGE_ENGINE_MARKERS = [
26
+ ...REQUIRED_REPO_FILES,
27
+ "scripts/conductor_health_check.py",
28
+ ];
29
+ /**
30
+ * Tri-state classification of `repoRoot` by its Bridge markers.
31
+ *
32
+ * Absence is proven only by `ENOENT` or `ENOTDIR`. A marker that exists as any
33
+ * kind of entry (including a directory standing where a file should be) counts
34
+ * as present, so it can never be read as "every marker is absent".
35
+ */
36
+ export async function classifyBridgeCheckout(repoRoot, fs) {
37
+ let present = false;
38
+ let unreadable = false;
39
+ for (const marker of BRIDGE_ENGINE_MARKERS) {
40
+ try {
41
+ await fs.stat(path.join(repoRoot, marker));
42
+ present = true;
43
+ }
44
+ catch (error) {
45
+ const code = error?.code;
46
+ if (code !== "ENOENT" && code !== "ENOTDIR")
47
+ unreadable = true;
48
+ }
49
+ }
50
+ if (present)
51
+ return "bridge";
52
+ return unreadable ? "unknown" : "not_bridge";
53
+ }
24
54
  /** Applicability only. Plane startup has additional, independent prerequisites. */
25
55
  export async function isBridgeEngineRepository(repoRoot, fs) {
26
56
  let missing = false;
@@ -183,6 +213,8 @@ const ROOT_DEPENDENT_CHECKS = [
183
213
  ["alembic-head", "alembic-head", "Database migration head"],
184
214
  ["existing-plane", "existing-plane", "Existing plane"],
185
215
  ];
216
+ /** BAPI-1595 — fixed detail for a Bridge-only check skipped on a confirmed non-Bridge checkout. */
217
+ export const PLANE_NOT_BRIDGE_SKIP_DETAIL = "skipped: this checkout is not a Bridge API checkout, so the Bridge-only check does not apply";
186
218
  /** Fixed detail for a prerequisite skipped because the legacy-environment guard refused first. */
187
219
  const PLANE_LEGACY_ENVIRONMENT_SKIP_DETAIL = "not run — the legacy-environment guard refused first";
188
220
  /**
@@ -269,7 +301,10 @@ export async function runPlanePreflight(repoRoot, deps) {
269
301
  }
270
302
  return { ok: false, diagnostics, outcomes };
271
303
  }
272
- const rootCheck = record(await checkRepositoryRoot(repoRoot, deps));
304
+ const notBridge = deps.bridgeApplicability === "not_bridge";
305
+ const rootCheck = record(notBridge
306
+ ? planeCheckSkipped("repository-root", "Repository root", PLANE_NOT_BRIDGE_SKIP_DETAIL)
307
+ : await checkRepositoryRoot(repoRoot, deps));
273
308
  // Every remaining check is relative to the repository root. Without a valid
274
309
  // one there is nothing coherent left to check, so report and stop here rather
275
310
  // than emitting a cascade of derived failures the operator cannot act on.
@@ -307,7 +342,10 @@ export async function runPlanePreflight(repoRoot, deps) {
307
342
  add(advisory);
308
343
  if (!credentials.ok)
309
344
  add(credentials.diagnostic);
310
- record(await checkPlaneBuildFreshness(repoRoot, { fs: deps.fs }));
345
+ record(await checkPlaneBuildFreshness(repoRoot, {
346
+ fs: deps.fs,
347
+ ...(notBridge ? { isBridge: false } : {}),
348
+ }));
311
349
  // Read-only, and evaluated alongside the other independent checks so an
312
350
  // unresolvable re-exec target aggregates with them instead of short-circuiting.
313
351
  const runtimeEntrypoint = deps.resolveRuntimeEntrypoint();
@@ -331,13 +369,15 @@ export async function runPlanePreflight(repoRoot, deps) {
331
369
  remediation: PLANE_SERVER_ENDPOINT_REMEDIATION,
332
370
  }, "Local server port", "the configured local server endpoint could not be resolved"));
333
371
  }
334
- record(await checkAlembicHead(repoRoot, {
335
- execFile: deps.execFile,
336
- fileExists: (filePath) => fileExists(filePath, deps.fs),
337
- platform: deps.platform,
338
- },
339
- // The code this plane will RUN. The executable still comes from `repoRoot`.
340
- deps.codeSnapshot?.path ?? repoRoot));
372
+ record(notBridge
373
+ ? planeCheckSkipped("alembic-head", "Database migration head", PLANE_NOT_BRIDGE_SKIP_DETAIL)
374
+ : await checkAlembicHead(repoRoot, {
375
+ execFile: deps.execFile,
376
+ fileExists: (filePath) => fileExists(filePath, deps.fs),
377
+ platform: deps.platform,
378
+ },
379
+ // The code this plane will RUN. The executable still comes from `repoRoot`.
380
+ deps.codeSnapshot?.path ?? repoRoot));
341
381
  const existing = await checkExistingPlane(repoRoot, deps);
342
382
  record(existing);
343
383
  observations.existingPlane = existing.observation;
@@ -248,6 +248,22 @@ export async function inspectPlaneRunExecutors(runExecutors) {
248
248
  }
249
249
  return { ok: true, targeting, malformed: listed.malformed };
250
250
  }
251
+ /**
252
+ * Does another run still ride on this plane? True only when a run-scoped
253
+ * executor record for a run OTHER than `epicRunId` targets this plane and its
254
+ * process is VERIFIED alive. Read-only.
255
+ *
256
+ * Deliberately narrower than the terminal-run cleanup's dependency check: an
257
+ * unreadable registry, a malformed record, or an unverifiable process answers
258
+ * `false`, so a single-epic wind-down with a stale record behaves exactly as
259
+ * before. Only a positively live second run blocks.
260
+ */
261
+ export async function planeHasLiveOtherRunExecutor(runExecutors, epicRunId) {
262
+ const inspected = await inspectPlaneRunExecutors(runExecutors);
263
+ if (!inspected.ok)
264
+ return false;
265
+ return inspected.targeting.some(({ record, state }) => record.epicRunId !== epicRunId && state === "verified");
266
+ }
251
267
  /** `verify`, with a throw settled as `unknown` — never a signal target. */
252
268
  async function verifyRunExecutorSafely(runExecutors, record) {
253
269
  try {
@@ -406,6 +422,9 @@ function formatRunShutdown(outcome) {
406
422
  case "already-stopped":
407
423
  return [`Run shutdown: run ${outcome.epicRunId} was already stopped; no further action.`];
408
424
  case "terminal":
425
+ if (outcome.status === "done") {
426
+ return [`Run shutdown: run ${outcome.epicRunId} already finished (done); nothing to stop.`];
427
+ }
409
428
  return [
410
429
  `Run shutdown: run ${outcome.epicRunId} is terminal (${outcome.status}) and cannot be ` +
411
430
  "stopped. Signalling local processes does not change this — run " +
@@ -51,7 +51,8 @@ export function createTerminalRunCleanupDeps(env = process.env) {
51
51
  resolveAccess: async (repoRoot) => {
52
52
  try {
53
53
  const { resolveConductorBridgeApiAccess } = await import("../conductor/bridge-api-client.js");
54
- return await resolveConductorBridgeApiAccess({ env, cwd: repoRoot });
54
+ // The plane is the run's own server, so follow the selected launch profile to reach it.
55
+ return await resolveConductorBridgeApiAccess({ env, cwd: repoRoot, followEpicLaunchProfile: true });
55
56
  }
56
57
  catch {
57
58
  return { ok: false, kind: "credentials-unavailable", error: "access could not be resolved" };
@@ -275,16 +276,29 @@ async function otherRunDependency(teardownDeps, epicRunId) {
275
276
  * positively holds no non-terminal run but the bound one.
276
277
  */
277
278
  async function otherServedRun(deps, access, epicRunId) {
279
+ const other = await readOtherLiveRun(deps.listLiveRunIds, access, epicRunId);
280
+ if (other.kind === "unconfirmed")
281
+ return "live-runs-unconfirmed";
282
+ return other.kind === "live" ? "shared-with-live-run" : null;
283
+ }
284
+ /**
285
+ * Read-only: whether the plane's server holds a non-terminal run other than
286
+ * `epicRunId`. `unconfirmed` when the list cannot be read. Never throws. The
287
+ * cleanup above and the launch preview (BAPI-1651) both ask this one question,
288
+ * so the preview cannot promise a cleanup the create will refuse.
289
+ */
290
+ export async function readOtherLiveRun(listLiveRunIds, access, epicRunId) {
278
291
  let ids;
279
292
  try {
280
- ids = await deps.listLiveRunIds(access);
293
+ ids = await listLiveRunIds(access);
281
294
  }
282
295
  catch {
283
296
  ids = null;
284
297
  }
285
298
  if (ids === null)
286
- return "live-runs-unconfirmed";
287
- return ids.some((id) => id !== epicRunId) ? "shared-with-live-run" : null;
299
+ return { kind: "unconfirmed" };
300
+ const other = ids.find((id) => id !== epicRunId);
301
+ return other === undefined ? { kind: "none" } : { kind: "live", epicRunId: other };
288
302
  }
289
303
  function incomplete(epicRunId, planeId, cause) {
290
304
  return {
@@ -11,7 +11,6 @@
11
11
  * mirrored contract (`conductor/merge-execution-contract.ts`).
12
12
  */
13
13
  import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
14
- import { EPIC_IMPLEMENTER_CI_CHECK_NAME } from "./epic-ci-workflow.js";
15
14
  /** The non-interactive launcher every printed command starts with. */
16
15
  const LAUNCHER = `npx -y ${MCP_PACKAGE_NAME}`;
17
16
  /** The top-level subcommand tokens `index.ts` dispatches that remedies name. */
@@ -33,11 +32,11 @@ export const CONSUMER_GUIDE_PATH = "docs/install/epic-implementer-install.md";
33
32
  */
34
33
  export const CONSUMER_GUIDE_POINTER = `${CONSUMER_GUIDE_PATH} (write or refresh it with ${PRINTED_INSTALL_COMMAND})`;
35
34
  /**
36
- * Conductor bootstrap with an explicit provider check. Since BAPI-1391 a
37
- * confirmed gate (provider, local, mixed, or none) replaces the old "at least
38
- * one --required-check" rule; a provider check is still the common scripted form.
35
+ * Conductor setup. The plain command is the whole remedy (BAPI-1603): setup plans
36
+ * the repository gate from what it finds, learns and proves the test command, and
37
+ * adds no required check on its own, so no remedy needs to name one.
39
38
  */
40
- export const PRINTED_CONDUCTOR_INSTALL_COMMAND = `${LAUNCHER} install epic-implementer --required-check "${EPIC_IMPLEMENTER_CI_CHECK_NAME}"`;
39
+ export const PRINTED_CONDUCTOR_INSTALL_COMMAND = `${LAUNCHER} install epic-implementer`;
41
40
  /** Conductor bootstrap that also provisions a repository-wide executor service. */
42
41
  export const PRINTED_CONDUCTOR_EXECUTOR_INSTALL_COMMAND = `${PRINTED_CONDUCTOR_INSTALL_COMMAND} --executor-id <id> --repo-wide`;
43
42
  /** Read-only readiness diagnostics. */
@@ -45,14 +44,15 @@ export const PRINTED_DOCTOR_COMMAND = `${LAUNCHER} doctor`;
45
44
  /** Sessionless GitHub App connection. `--repo` is optional for this command. */
46
45
  export const PRINTED_CONNECT_GITHUB_COMMAND = `${LAUNCHER} connect-github`;
47
46
  /**
48
- * BAPI-1536 — save or replace the repository's stored test command. The flag is
49
- * the consent for that one write; the placeholder is never filled in here.
47
+ * BAPI-1536 — replace the repository's test command. Since BAPI-1603 the flag is
48
+ * the owner's command offered for proof, not a direct write: Bridge runs it once
49
+ * and the server stores it only if it passes. The placeholder is never filled in here.
50
50
  */
51
51
  export const PRINTED_TEST_COMMAND_INSTALL_COMMAND = `${LAUNCHER} install epic-implementer --test-command "<command>"`;
52
52
  /** Explains the `<command>` placeholder; print it beside the test-command remedy. */
53
53
  export const PRINTED_TEST_COMMAND_INSTRUCTION = "Replace <command> with the one command that runs your tests.";
54
- /** Explains the `<check-name>` placeholder; print it beside a conductor command. */
55
- export const PRINTED_CHECK_NAME_INSTRUCTION = "Run setup to create the workflow and store the required check.";
54
+ /** One plain sentence on what setup does; print it beside a conductor command. */
55
+ export const PRINTED_CHECK_NAME_INSTRUCTION = "Run setup to plan the repository gate and store the safe defaults.";
56
56
  /** Explains the `<id>` placeholder of the executor command. */
57
57
  export const PRINTED_EXECUTOR_ID_INSTRUCTION = "Replace <id> with a name for the executor service.";
58
58
  /**
@@ -65,20 +65,213 @@ export const PRINTED_QUALIFY_GATE_COMMAND = `${LAUNCHER} install epic-implemente
65
65
  export const PRINTED_REPO_WIDE_EXECUTOR_COMMAND = `${LAUNCHER} install epic-implementer --executor-id <id> --repo-wide`;
66
66
  /** The lifecycle-free executor service-unit generator. */
67
67
  export const PRINTED_EXECUTOR_INSTALL_SERVICE_COMMAND = `${LAUNCHER} executor install-service`;
68
+ /**
69
+ * BAPI-1602 — workflow remedies name the step that CHANGES the failed state, never
70
+ * the command that just printed them. The old text told the reader to run
71
+ * `install epic-implementer --required-check ...`, and that command printed the
72
+ * same text again. Each piece is a short sentence; the combined remedy is built
73
+ * from the same pieces so wording cannot drift between the three cases.
74
+ */
75
+ const REVIEW_WORKFLOW_STEP = `Add .github/workflows/claude-review.yml, or run ${LAUNCHER} install epic-implementer.`;
76
+ const MANAGED_WORKFLOW_STEP = "Merge the setup pull request.";
77
+ const REINDEX_STEP = "Then re-index the repository.";
68
78
  /** Fixed public actions; generated into Python from this source at build time. */
69
79
  export const READINESS_PREREQUISITE_FIXES = {
70
80
  retry: "Retry the readiness check.",
71
- setup: `Run ${PRINTED_CONDUCTOR_INSTALL_COMMAND}, then retry readiness.`,
81
+ setup: "Merge the setup pull request, then retry readiness.",
72
82
  no_index: "Re-index the repository, then retry readiness.",
73
83
  pending_index: "Wait for indexing to finish, then retry readiness.",
74
- missing_workflow: `Run ${PRINTED_CONDUCTOR_INSTALL_COMMAND}, merge the workflow changes, then re-index the repository.`,
75
- explicit_command: `Run ${PRINTED_TEST_COMMAND_INSTALL_COMMAND}. ${PRINTED_TEST_COMMAND_INSTRUCTION}`,
84
+ missing_workflow: `${MANAGED_WORKFLOW_STEP} ${REINDEX_STEP}`,
85
+ missing_review_workflow: `${REVIEW_WORKFLOW_STEP} ${REINDEX_STEP}`,
86
+ missing_review_and_managed_workflows: `${REVIEW_WORKFLOW_STEP} ${MANAGED_WORKFLOW_STEP} ${REINDEX_STEP}`,
87
+ webhook_failed_email_available: "The webhook did not respond. Escalations will go to the account email.",
76
88
  escalation: "Declare a notify webhook, or verify the account email with live email delivery.",
77
89
  self_host: "Check the self-host installation guide, then retry readiness.",
78
90
  consent: "Turn on Allow unattended Epic Implementer runs on the repository Setup page, or use --attended.",
79
91
  github: `Run ${PRINTED_CONNECT_GITHUB_COMMAND}, then retry readiness.`,
92
+ // BAPI-1635 — client-side remedies for known states. None of these is ever sent
93
+ // on the wire: the server maps them to the empty fix (see
94
+ // PUBLISHED_SERVER_COMPATIBLE_FIXES) and the client resolves them by prerequisite ID.
95
+ supervisor_gate: `Run ${PRINTED_CONDUCTOR_INSTALL_COMMAND} to plan the repository gate and store the safe defaults, then retry readiness.`,
96
+ install_setup: `Run ${PRINTED_CONDUCTOR_INSTALL_COMMAND}, then retry readiness.`,
97
+ install_guided: `Run ${PRINTED_INSTALL_COMMAND}, then retry readiness.`,
98
+ executor: `Run ${PRINTED_REPO_WIDE_EXECUTOR_COMMAND}. ${PRINTED_EXECUTOR_ID_INSTRUCTION} Then retry readiness.`,
99
+ doctor: `Run ${PRINTED_DOCTOR_COMMAND} and follow the remedy it prints for this item, then retry readiness.`,
100
+ local_login: "Sign in to Claude on this machine (run claude, then /login), then retry readiness.",
101
+ gh_cli: "Install the GitHub CLI (gh) and run gh auth login, then retry readiness.",
102
+ node_engine: "Install a Node version that satisfies the engines range in the package, then retry readiness.",
103
+ support: "Service availability failed. Report it to Bridge support with the time of this readiness check.",
104
+ profile_policy: "Declare notify.webhook_url in a run policy, then save a profile that uses it with --launch-profile <name> --policy-file <path>.",
105
+ asset_refresh: "Refresh the committed command and agent files, review the changes, then commit them or mark them as customized.",
106
+ reindex_manual: "Re-index the repository (/parse-repository).",
80
107
  none: "",
81
108
  };
109
+ const PUBLISHED_INSTALL_COMMAND = `${LAUNCHER} install epic-implementer --required-check "epic-implementer-ci / gate"`;
110
+ /**
111
+ * BAPI-1635 — the fix texts the PUBLISHED client (0.2.72) accepts from a server.
112
+ * That client drops the whole server prerequisite list when one row carries any
113
+ * other text, so the Python projector may put only these on the wire and sends
114
+ * the empty fix for every richer remedy. These are the exact published bytes, kept
115
+ * as literals: they are NOT built from {@link READINESS_PREREQUISITE_FIXES}, which
116
+ * has changed since. Nothing is added here without a published client that
117
+ * accepts it.
118
+ */
119
+ export const PUBLISHED_SERVER_COMPATIBLE_FIXES = [
120
+ "Retry the readiness check.",
121
+ `Run ${PUBLISHED_INSTALL_COMMAND}, then retry readiness.`,
122
+ "Re-index the repository, then retry readiness.",
123
+ "Wait for indexing to finish, then retry readiness.",
124
+ `Run ${PUBLISHED_INSTALL_COMMAND}, merge the workflow changes, then re-index the repository.`,
125
+ `Run ${LAUNCHER} install epic-implementer --test-command "<command>". Replace <command> with the one command that runs your tests.`,
126
+ "Declare a notify webhook, or verify the account email with live email delivery.",
127
+ "Check the self-host installation guide, then retry readiness.",
128
+ "Turn on Allow unattended Epic Implementer runs on the repository Setup page, or use --attended.",
129
+ `Run ${LAUNCHER} connect-github, then retry readiness.`,
130
+ "",
131
+ ];
132
+ /**
133
+ * BAPI-1635 — the remedy a KNOWN unmet prerequisite resolves to, by catalog ID.
134
+ * Each value is a key of the flat {@link READINESS_PREREQUISITE_FIXES}; the map is
135
+ * separate so the flat object stays string-valued for `Object.values(...)`
136
+ * validators. No ID defaults to `setup`: that text is reserved for evidence of a
137
+ * real setup pull request that needs merging. `retry` is never a default here —
138
+ * it belongs to unknown observations alone.
139
+ */
140
+ export const READINESS_PREREQUISITE_FIXES_BY_ID = {
141
+ 'server.unattended-posture': 'consent',
142
+ 'server.resolved-merge-mode': 'install_setup',
143
+ 'server.provider-repository': 'github',
144
+ 'server.supervisor-setup': 'supervisor_gate',
145
+ 'server.supervisor-config': 'supervisor_gate',
146
+ 'server.supervisor-required-checks': 'supervisor_gate',
147
+ 'server.review-policy': 'install_setup',
148
+ 'server.github-credentials': 'github',
149
+ 'server.provider-default-branch-readable': 'github',
150
+ 'server.github-actions-permission': 'github',
151
+ 'server.merge-execution-workflow': 'install_setup',
152
+ 'server.merge-execution-branch-policy': 'install_setup',
153
+ 'server.reconciler-liveness': 'self_host',
154
+ 'server.executor-readiness': 'executor',
155
+ 'server.review-workflow': 'missing_review_workflow',
156
+ 'server.conductor-ci-workflow': 'install_setup',
157
+ 'server.unattended-notify-default': 'escalation',
158
+ 'server.escalation-webhook-reachable': 'escalation',
159
+ 'server.repository-workflow-readiness': 'install_setup',
160
+ 'server.database-migration-current': 'self_host',
161
+ 'server.worker-present': 'self_host',
162
+ 'server.single-transition-authority': 'self_host',
163
+ 'server.indexed-workflows': 'reindex_manual',
164
+ 'server.integration-branch-unset': 'install_setup',
165
+ 'server.service-availability': 'support',
166
+ 'install.claude-login': 'local_login',
167
+ 'install.identity': 'install_guided',
168
+ 'install.credential': 'install_guided',
169
+ 'install.connectivity': 'install_guided',
170
+ 'install.bootstrap': 'install_guided',
171
+ 'install.integrations': 'install_guided',
172
+ 'install.github': 'github',
173
+ 'install.indexing': 'reindex_manual',
174
+ 'conductor.ledger': 'install_setup',
175
+ 'conductor.git-hooks': 'install_setup',
176
+ 'conductor.mcp-profile': 'install_setup',
177
+ 'conductor.gh-cli': 'gh_cli',
178
+ 'conductor.merge-credential': 'install_setup',
179
+ 'conductor.native-ledger': 'install_setup',
180
+ 'conductor.mcp-registration-form': 'install_setup',
181
+ 'conductor.node-engine': 'node_engine',
182
+ 'conductor.deny-enforcement': 'install_setup',
183
+ 'conductor.claude-login': 'local_login',
184
+ 'plane.legacy-environment': 'self_host',
185
+ 'plane.repository-root': 'self_host',
186
+ 'plane.worktree-presence': 'self_host',
187
+ 'plane.claude-login': 'self_host',
188
+ 'plane.repo-identity': 'self_host',
189
+ 'plane.bridge-credentials': 'self_host',
190
+ 'plane.credential-permissions': 'self_host',
191
+ 'plane.executor-build': 'self_host',
192
+ 'plane.runtime-entrypoint': 'self_host',
193
+ 'plane.server-port': 'self_host',
194
+ 'plane.alembic-head': 'self_host',
195
+ 'plane.existing-plane': 'self_host',
196
+ 'conductor.merge-credential-capability': 'install_setup',
197
+ 'conductor.worktree-preparation': 'doctor',
198
+ 'conductor.install-section-supervisor-gate-profile': 'supervisor_gate',
199
+ 'conductor.install-section-supervisor-required-checks': 'supervisor_gate',
200
+ 'conductor.install-section-supervisor-review-alignment': 'install_setup',
201
+ 'conductor.install-section-github-actions-permission': 'github',
202
+ 'conductor.install-section-merge-execution-eligibility': 'install_setup',
203
+ 'conductor.install-section-executor-provisioning': 'self_host',
204
+ 'conductor.install-section-executor-service-state': 'self_host',
205
+ 'conductor.install-section-epic-implementer-profile-token': 'install_setup',
206
+ 'conductor.install-section-conductor-hook-targets': 'install_setup',
207
+ 'conductor.install-section-gh-actions-merge-auth': 'github',
208
+ 'conductor.install-section-gh-actions-merge-observable': 'github',
209
+ 'conductor.install-section-epic-implementer-ledger-loadability': 'install_setup',
210
+ 'server.admission-evidence': 'install_setup',
211
+ 'server.admission-unattended-consent': 'consent',
212
+ 'server.admission-notify-webhook': 'escalation',
213
+ 'server.admission-repository-readiness': 'install_setup',
214
+ 'server.admission-required-checks': 'supervisor_gate',
215
+ 'server.admission-index-provenance': 'reindex_manual',
216
+ 'server.admission-durable-actor': 'self_host',
217
+ 'server.admission-migration-head': 'self_host',
218
+ 'server.gate-profile': 'supervisor_gate',
219
+ 'server.gate-profile-warnings': 'supervisor_gate',
220
+ 'server.effective-review-mode': 'install_setup',
221
+ 'server.epic-branch-ci-decision': 'install_setup',
222
+ 'server.epic-branch-ci-coverage-warning': 'install_setup',
223
+ 'server.diagnostics': 'doctor',
224
+ 'conductor.command-drift': 'asset_refresh',
225
+ 'escalation-reachability': 'escalation',
226
+ };
227
+ /**
228
+ * BAPI-1635 — the one remedy for a prerequisite. A met or not-applicable item has
229
+ * none; a genuinely unknown observation retries; a known unmet item gets its
230
+ * per-ID remedy. A self-host-scoped item keeps the self-host text in every
231
+ * unmet state, as it did before. A known unmet ID with no map entry is a
232
+ * defect the generator rejects, so it falls back to retry rather than throwing.
233
+ */
234
+ export function resolveReadinessRemedy(item) {
235
+ if (item.state === 'met' || item.state === 'not_applicable')
236
+ return READINESS_PREREQUISITE_FIXES.none;
237
+ if (item.scope === 'self_host')
238
+ return READINESS_PREREQUISITE_FIXES.self_host;
239
+ if (item.state === 'unknown')
240
+ return READINESS_PREREQUISITE_FIXES.retry;
241
+ // A webhook that failed its probe while live email is confirmed arrives as a warning. Its meaning is that
242
+ // escalations still reach the account email, which the server can no longer say on the wire.
243
+ if (item.id === 'server.escalation-webhook-reachable' && item.impact === 'warning') {
244
+ return READINESS_PREREQUISITE_FIXES.webhook_failed_email_available;
245
+ }
246
+ const key = READINESS_PREREQUISITE_FIXES_BY_ID[item.id];
247
+ return key ? READINESS_PREREQUISITE_FIXES[key] : READINESS_PREREQUISITE_FIXES.retry;
248
+ }
249
+ /**
250
+ * BAPI-1635 — the profile-policy remedy for a known unmet escalation route. It
251
+ * names the declaration and the save command and never carries a webhook value.
252
+ * `launcherCommand` is the already-validated command prefix for the detected
253
+ * launcher; the package launcher is used when none is supplied.
254
+ */
255
+ export function formatProfilePolicyRemedy(launcherCommand) {
256
+ const command = `${launcherCommand ?? PRINTED_CONDUCTOR_INSTALL_COMMAND}`;
257
+ return `Declare notify.webhook_url in a run policy, then save a profile with ${command} --launch-profile <name> --policy-file <path>.`;
258
+ }
259
+ /**
260
+ * The command an older Bridge API printed in its remedies, kept as the literal
261
+ * bytes it sent. It is NOT built from {@link PRINTED_CONDUCTOR_INSTALL_COMMAND}:
262
+ * that command changed in BAPI-1603, and the text an older server sends did not.
263
+ */
264
+ const PREVIOUS_SERVER_INSTALL_COMMAND = `${LAUNCHER} install epic-implementer --required-check "epic-implementer-ci / gate"`;
265
+ /**
266
+ * BAPI-1602 — the remedy texts an older Bridge API sends for rows this build still
267
+ * knows. They are accepted ONLY so an older server's readiness report parses and
268
+ * renders with its own text; they are fixed literals, are
269
+ * never printed by this build, and nothing new may be added here.
270
+ */
271
+ export const PREVIOUS_SERVER_READINESS_FIXES = [
272
+ `Run ${PREVIOUS_SERVER_INSTALL_COMMAND}, then retry readiness.`,
273
+ `Run ${PREVIOUS_SERVER_INSTALL_COMMAND}, merge the workflow changes, then re-index the repository.`,
274
+ ];
82
275
  /** Structured explanations are descriptive and never grant effect consent. */
83
276
  export function assessmentRemedyQuestion(remedy, evidence) {
84
277
  const hosted = !['repository_admin', 'local_user', 'bridge_support', 'self_host_operator'].includes(remedy.audience ?? '') || remedy.audience === 'bridge_support' ||
@@ -87,6 +280,7 @@ export function assessmentRemedyQuestion(remedy, evidence) {
87
280
  none: 'No action required.', retry: READINESS_PREREQUISITE_FIXES.retry,
88
281
  setup: READINESS_PREREQUISITE_FIXES.setup, github: READINESS_PREREQUISITE_FIXES.github,
89
282
  index: READINESS_PREREQUISITE_FIXES.no_index, workflow: READINESS_PREREQUISITE_FIXES.missing_workflow,
283
+ missing_review_workflow: READINESS_PREREQUISITE_FIXES.missing_review_workflow,
90
284
  escalation: READINESS_PREREQUISITE_FIXES.escalation,
91
285
  support: 'Contact Bridge support to investigate service availability.',
92
286
  self_host: READINESS_PREREQUISITE_FIXES.self_host,
@@ -1,3 +1,80 @@
1
+ /**
2
+ * The canonical shared readiness-check contract (BAPI-1055, AC-6).
3
+ *
4
+ * Conductor prerequisite probing is spread across five loci — `bridge doctor`
5
+ * ({@link file:./install-doctor.ts}), `epic-implementer doctor`
6
+ * ({@link file:./conductor/doctor.ts}), `plane` preflight
7
+ * ({@link file:./plane/preflight.ts}), the server `conductor-readiness`
8
+ * collector, and the unified install doctor
9
+ * ({@link file:./conductor/install-doctor.ts}) that already composes four of
10
+ * them. Each speaks its own status vocabulary. This module is the ONE record
11
+ * shape they are all projected into, so a consolidated report can say
12
+ * pass/fail and name exactly one remediation per failure without any locus
13
+ * having to abandon its own verdicts.
14
+ *
15
+ * DEPENDENCY-NEUTRAL LEAF. It imports nothing: no fs, no network, no CLI, no
16
+ * sibling diagnostic. That is what makes it safe to import from every surface,
17
+ * including ones pinned to issue zero probes.
18
+ *
19
+ * ## Exhaustive source-status mapping (the accepted four-state vocabulary)
20
+ *
21
+ * The shared vocabulary has FOUR states, not three, because four is the
22
+ * minimum that lets every source verdict round-trip without a lossy merge.
23
+ * Collapsing `degraded` onto `fail` would make a fallback npm channel read
24
+ * identically to an unusable ledger, which would contradict the rule that each
25
+ * section's own advisory semantics stay unchanged.
26
+ *
27
+ * | Source | Source verdict | Canonical |
28
+ * | ----------------------------------- | ----------------------------- | --------- |
29
+ * | `install-doctor` `InstallCheckStatus` | `PASS` | `pass` |
30
+ * | `install-doctor` `InstallCheckStatus` | `WARN` | `warn` |
31
+ * | `install-doctor` `InstallCheckStatus` | `SKIP` | `skip` |
32
+ * | `install-doctor` `InstallCheckStatus` | `INFO` | see below |
33
+ * | `conductor/install-doctor` section | `ok` | `pass` |
34
+ * | `conductor/install-doctor` section | `degraded` | `warn` |
35
+ * | `conductor/install-doctor` section | `fatal` | `fail` |
36
+ * | `conductor/doctor` inspection | `degraded: true` | `warn` |
37
+ * | `plane` diagnostic | `severity: "warning"` | `warn` |
38
+ * | `plane` diagnostic | `severity: "blocking"` | `fail` |
39
+ * | server readiness | unreadable / `null` / missing | `fail` |
40
+ *
41
+ * `INFO` never becomes a canonical status. It is informational by definition,
42
+ * so its content is preserved in {@link ReadinessCheck.detail} while the check
43
+ * takes `pass`, `warn`, or `skip` according to that check's own established
44
+ * semantics — chosen per check id by the adapter, never guessed here.
45
+ *
46
+ * Three states are deliberately NOT interchangeable:
47
+ *
48
+ * - `fail` means a prerequisite is not satisfied, INCLUDING the case where its
49
+ * state could not be established. An unreadable liveness read, a failed
50
+ * permission probe, `executor.ready === null`, and a field a newer server
51
+ * would have sent are all `fail` with a remediation for restoring the probe.
52
+ * Uncertainty must never appear healthy.
53
+ * - `warn` means the prerequisite is degraded but usable, or a launch-permitting
54
+ * plane warning. It is not a soft failure and is never derived from silence.
55
+ * - `skip` means the check genuinely did not apply or a dependency prevented it
56
+ * from running. It is never used to hide an unknown.
57
+ *
58
+ * ## The failure/remediation invariant
59
+ *
60
+ * AC-6 requires exactly ONE named remediation on every failure, so the union
61
+ * below makes that a property of the type: the `fail` variant REQUIRES one
62
+ * non-empty scalar remediation and the `pass` variant PROHIBITS one. `warn` and
63
+ * `skip` may each carry at most one, because an actionable warning and the
64
+ * actionable deny-probe skip both have a named next step, while a
65
+ * dependency-driven skip has none.
66
+ *
67
+ * ## Secret discipline
68
+ *
69
+ * Every `detail` and `remediation` is fixed prose plus non-secret facts: a
70
+ * label, a closed enum, a count, a boolean, a timestamp, a relative identifier,
71
+ * or an approved base/setup URL. The helpers here cap length, strip control
72
+ * characters, and refuse obvious absolute paths — but they are a last line of
73
+ * defence, NOT permission to pass a raw exception, subprocess output, a request
74
+ * header, a response body, or a credential into the constructor. Projecting
75
+ * source data into safe prose is the adapter's job; this module only refuses
76
+ * the most obvious leaks.
77
+ */
1
78
  /** Every valid status, for exhaustive validation and test enumeration. */
2
79
  export const READINESS_CHECK_STATUSES = [
3
80
  "pass",