@bridge_gpt/mcp-server 0.2.75 → 0.2.76

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 (64) hide show
  1. package/README.md +5 -5
  2. package/build/agents.generated.js +4 -4
  3. package/build/codex-auto-recovery.js +25 -7
  4. package/build/commands.generated.js +6 -6
  5. package/build/conductor/bridge-api-client.js +141 -6
  6. package/build/conductor/declare-blocked.js +4 -0
  7. package/build/conductor/driver-pass.js +8 -0
  8. package/build/conductor/epic-implementer-cli.js +4 -3
  9. package/build/conductor/epic-server-journal.js +13 -0
  10. package/build/conductor/epic-server-recipe.js +15 -5
  11. package/build/conductor/epic-server-runtime.js +163 -45
  12. package/build/conductor/epic-server.js +13 -6
  13. package/build/conductor/install-doctor.js +30 -2
  14. package/build/conductor/local-merge.js +54 -12
  15. package/build/conductor/pr-ci-producer.js +12 -3
  16. package/build/conductor/readiness-sections.js +46 -13
  17. package/build/conductor/readiness.js +3 -40
  18. package/build/conductor/recovery-cli.js +12 -12
  19. package/build/conductor/repository-workflow-remedy.js +147 -7
  20. package/build/conductor/ui-readiness.js +224 -0
  21. package/build/conductor/wait-run-attention.js +9 -4
  22. package/build/conductor/wait-run-cli.js +9 -2
  23. package/build/docs.generated.js +2 -2
  24. package/build/drive-epic.js +402 -27
  25. package/build/epic-implementer-bin.js +62 -42
  26. package/build/epic-launch-context.js +8 -1
  27. package/build/epic-shared/cut-protocol.js +55 -3
  28. package/build/executor/failure-reason-codes.js +2 -0
  29. package/build/executor/integration-job.js +56 -2
  30. package/build/executor/job-runner.js +4 -1
  31. package/build/executor/merge-job.js +45 -1
  32. package/build/executor/permissions.js +187 -2
  33. package/build/executor/provider-checks.js +28 -5
  34. package/build/executor/reconcile-overlap-job.js +70 -17
  35. package/build/executor/required-work-ledger.js +7 -2
  36. package/build/executor/resume-pre-spawn.js +32 -8
  37. package/build/executor/runner.js +26 -4
  38. package/build/executor/worktree.js +12 -1
  39. package/build/index.js +376 -434
  40. package/build/init.js +16 -0
  41. package/build/install-bridge-conductor-answers.js +4 -0
  42. package/build/install-bridge-conductor-apply.js +10 -0
  43. package/build/install-bridge-conductor-assessment.js +71 -0
  44. package/build/install-bridge-conductor-contracts.js +9 -1
  45. package/build/install-bridge-conductor-setup.js +103 -3
  46. package/build/install-bridge-conductor.js +437 -93
  47. package/build/mcp-host-config.js +54 -37
  48. package/build/phase-context-git-probe.js +16 -0
  49. package/build/pipelines.generated.js +9 -9
  50. package/build/plan-execution-ledger.js +27 -0
  51. package/build/plane/plane-freshness.js +43 -26
  52. package/build/printed-remedy-commands.js +8 -0
  53. package/build/readme.generated.js +1 -1
  54. package/build/secret-redaction.js +3 -0
  55. package/build/setup-epic.js +41 -8
  56. package/build/test-support/create-preview-world.js +232 -0
  57. package/build/ticket-delivery.js +65 -0
  58. package/build/v2-readiness-requirements.js +8 -3
  59. package/build/version.generated.js +3 -3
  60. package/build/worktree-core.js +51 -7
  61. package/docs/EPIC-IMPLEMENTER.md +79 -0
  62. package/docs/epic-implementer/getting-started.md +1 -1
  63. package/package.json +1 -1
  64. package/pipelines/implement-ticket.json +2 -2
@@ -132,7 +132,7 @@ import { withSetupProgress } from "./setup-progress.js";
132
132
  * default branch, not the person's folder. The one stop this adds is the learned
133
133
  * stop; everything else it adds only warns.
134
134
  */
135
- import { PRINTED_INSTALL_COMMAND, PRINTED_QUALIFY_GATE_COMMAND } from "./printed-remedy-commands.js";
135
+ import { PRINTED_QUALIFY_GATE_COMMAND, CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION } from "./printed-remedy-commands.js";
136
136
  import { collectEpicBranchCi, confirmRequestFor, planDeclarations, resolveEffectiveDependencyInstall, describeGateRestoration, desiredFromStored, emptyConductorGateFlags, hasExplicitGateInput, parseLocalCommandFlag, parseEpicBranchCiDecisionFlag, parseMigrationGuardFlag, planManagedProviderGate, reportLearnedCommandTrial, isInformationalNoCommandReason, NO_COMMAND_INFORMATION_TEXT, CANDIDATE_REJECTION_FIX, formatSetupPolicyRefusal, describePolicyChanges, resolveConductorGate, runEpicBranchCiInspection, runGateConsequenceSummary, runClearConductorGate, mapExemptionOutcomeToWriteResult, runConductorGateQualification, runLearnedTestCommandTrial, runQualifyConductorGate, validateConductorGateFlags, } from "./install-bridge-conductor-gate.js";
137
137
  import { classifyEpicPullRequestTrigger, readDefaultBranchRequiredChecksViaGh, readPullRequestBranchFilters, } from "./conductor/epic-branch-ci-inspection.js";
138
138
  import { describeGateConsequence } from "./conductor/readiness-sections.js";
@@ -158,6 +158,9 @@ import { buildEpicCapabilityStatement } from "./epic-capability-statement.js";
158
158
  import { MCP_GRANT_MAX_SERVERS } from "./mcp-grant.js";
159
159
  import { advisoryFindingLines, assessIndexFreshness, assessSetupIndex, catalogLabel, NPM_SETUP_LAUNCHER, closedSetupPullRequestNotice, compareIndexedToMerge, planSetupFixes, projectSetupItems, readSetupPullRequest, renderSetupAssessment, deriveCompactReadiness, setupItemRemedy, setupVerdictLine, unmetBlockingItems, } from "./install-bridge-conductor-setup.js";
160
160
  import { CONDUCTOR_BIN_UNRESOLVED_ERROR, MANAGED_HOOK_NAMES, } from "./conductor/git-hooks.js";
161
+ import { profileMergeNeededFrom } from "./mcp-host-config.js";
162
+ import { DuplicateRegistrationError } from "./init.js";
163
+ import { DUPLICATE_REGISTRATION_GUIDANCE } from "./launcher-config-inspection.js";
161
164
  import os from "node:os";
162
165
  import path from "node:path";
163
166
  import { readFile as readFileAsync, stat as statAsync } from "node:fs/promises";
@@ -328,10 +331,11 @@ export function getInstallBridgeConductorUsage() {
328
331
  "",
329
332
  ` --review-policy <source> One of: ${CONDUCTOR_REVIEW_POLICY_SOURCES.join(", ")}`,
330
333
  " Omitted, setup keeps a project default that is already",
331
- " stored. With none stored it stores verdict_protocol when",
332
- " .github/workflows/claude-review.yml exists on your default",
333
- " branch, and repository_policy when it does not or cannot",
334
- " be read. It scaffolds no Claude review workflow unless you",
334
+ " stored. With none stored it stores verdict_protocol only",
335
+ " when Bridge read .github/workflows/claude-review.yml on",
336
+ " your default branch, the file exists, and it emits both the",
337
+ " run-id: and Reviewed-SHA: markers. Otherwise it stores",
338
+ " repository_policy. It scaffolds no Claude review workflow unless you",
335
339
  " pass --review-policy verdict_protocol. Supplying any value",
336
340
  " persists it as the project default, stamped into a new",
337
341
  " run that carries no review policy of its own.",
@@ -1353,9 +1357,11 @@ export function formatConductorRestartAdvisory(mergedProfile) {
1353
1357
  "at startup, so this activates on the next MCP server launch — restart your MCP " +
1354
1358
  "client to gain access to the Epic Implementer tools.");
1355
1359
  }
1356
- /** Remediation printed when no supported host config carries a Bridge entry. */
1357
- export const CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION = `run \`${PRINTED_INSTALL_COMMAND}\` to create and register the host MCP entry, ` +
1358
- "then re-run `install epic-implementer`.";
1360
+ /**
1361
+ * Remediation printed when no supported host config carries a Bridge entry.
1362
+ * Owned by `printed-remedy-commands.ts` since BAPI-1719; re-exported for compatibility.
1363
+ */
1364
+ export { CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION };
1359
1365
  /** Remediation printed whenever the managed git hooks were not installed. */
1360
1366
  export const CONDUCTOR_HOOKS_MANUAL_REMEDIATION = "re-run `install epic-implementer` and accept the local-observability consent, or run " +
1361
1367
  "`epic-implementer install-git-hooks` directly.";
@@ -1366,6 +1372,101 @@ export const CONDUCTOR_HOOKS_MANUAL_REMEDIATION = "re-run `install epic-implemen
1366
1372
  export const CONDUCTOR_HOOKS_DURABLE_REMEDIATION = `install the CLI persistently (\`npm i -g ${MCP_PACKAGE_NAME}\`), then run ` +
1367
1373
  "`epic-implementer install-git-hooks` (or re-run `install epic-implementer` and accept the " +
1368
1374
  "local-observability consent).";
1375
+ /**
1376
+ * The plain restart line the converging setup prints once after a confirmed write
1377
+ * (BAPI-1719), and the advisory its structured result carries.
1378
+ */
1379
+ export const TOOL_VISIBILITY_RESTART_LINE = "Restart your MCP client so this session can see the Epic Implementer tools.";
1380
+ /** Fixed, secret-free wording for the closed failure cases. Never an exception message. */
1381
+ const TOOL_VISIBILITY_FAILURE_TEXT = Object.freeze({
1382
+ inspection: "the MCP configuration could not be inspected",
1383
+ write: "the host MCP profile could not be updated",
1384
+ duplicate: "a config registers Bridge under two names, so nothing was changed",
1385
+ });
1386
+ /**
1387
+ * Add the `epic_implementer` group to the EXISTING project-local Bridge MCP entries.
1388
+ *
1389
+ * CONSENT BELONGS TO THE CALLER: this function never asks. It modifies only entries
1390
+ * that already exist (the writer never creates a file, directory, or registration),
1391
+ * and it writes only through `local.mergeProfileToken()`.
1392
+ *
1393
+ * Mutation success is decoupled from what follows it: once the writer returns a
1394
+ * non-empty profile the outcome is `written`, whatever the read-back or the
1395
+ * capability record later report. `deps` is accepted for signature symmetry with the
1396
+ * other setup operations; the helper itself prints nothing.
1397
+ */
1398
+ export async function applyToolVisibility(deps, local, options = {}) {
1399
+ void deps;
1400
+ const base = {
1401
+ outcome: "failed", changedPaths: [], mergedProfile: "", carryingPaths: [],
1402
+ verification: "not_run", guidance: [], advisories: [], notes: [], failurePaths: [],
1403
+ };
1404
+ let changedPaths = [];
1405
+ if (options.freshInspection !== false) {
1406
+ // Fresh evidence only: nothing from the earlier assessment is reused.
1407
+ let pre;
1408
+ try {
1409
+ pre = await local.inspectProfileToken();
1410
+ }
1411
+ catch {
1412
+ return { ...base, failure: TOOL_VISIBILITY_FAILURE_TEXT.inspection, guidance: ["re-run setup once the MCP configuration is readable"] };
1413
+ }
1414
+ if (!profileMergeNeededFrom(pre)) {
1415
+ if (pre.bridgeEntryPresent)
1416
+ return { ...base, outcome: "unchanged" };
1417
+ if (pre.configs.some((c) => c.state === "unreadable")) {
1418
+ return { ...base, failure: TOOL_VISIBILITY_FAILURE_TEXT.inspection, guidance: ["re-run setup once the MCP configuration is readable"] };
1419
+ }
1420
+ return { ...base, outcome: "no_entry", guidance: [CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION] };
1421
+ }
1422
+ changedPaths = pre.configs.filter((c) => c.state === "token-absent").map((c) => c.path);
1423
+ }
1424
+ let merged;
1425
+ try {
1426
+ merged = await local.mergeProfileToken();
1427
+ }
1428
+ catch (error) {
1429
+ // The thrown value is discarded except for a duplicate's fixed config paths:
1430
+ // any other message can carry an absolute path or an environment value.
1431
+ if (error instanceof DuplicateRegistrationError) {
1432
+ return {
1433
+ ...base,
1434
+ failure: TOOL_VISIBILITY_FAILURE_TEXT.duplicate,
1435
+ failurePaths: [...error.relPaths],
1436
+ guidance: [DUPLICATE_REGISTRATION_GUIDANCE],
1437
+ };
1438
+ }
1439
+ return { ...base, failure: TOOL_VISIBILITY_FAILURE_TEXT.write };
1440
+ }
1441
+ if (merged === "") {
1442
+ return { ...base, outcome: "no_entry", guidance: [CONDUCTOR_PROFILE_EMPTY_MERGE_REMEDIATION] };
1443
+ }
1444
+ // The write is confirmed. Nothing below can turn it into a failure.
1445
+ const result = { ...base, outcome: "written", changedPaths, mergedProfile: merged, advisories: [TOOL_VISIBILITY_RESTART_LINE] };
1446
+ try {
1447
+ // Which configs carry the group now: the READ-ONLY inspector, not a guess from the merged string.
1448
+ const post = await local.inspectProfileToken();
1449
+ result.carryingPaths = post.configs.filter((c) => c.state === "token-present").map((c) => c.path);
1450
+ result.verification = profileMergeNeededFrom(post) ? "unknown" : "confirmed";
1451
+ }
1452
+ catch {
1453
+ result.verification = "unknown";
1454
+ }
1455
+ if (result.verification === "unknown") {
1456
+ result.guidance.push("the write could not be confirmed by reading the configuration back; run `epic-implementer doctor` after restarting your MCP client");
1457
+ }
1458
+ try {
1459
+ const recorded = await local.recordCapability("conductor_tool_visibility");
1460
+ // Advisory: install state is a diagnostic aid. A recording failure does not
1461
+ // invalidate the host-config change that just landed.
1462
+ if (!recorded.ok)
1463
+ result.notes.push(`install-state not updated (${recorded.error ?? "unknown"})`);
1464
+ }
1465
+ catch {
1466
+ result.notes.push("install-state not updated (unknown)");
1467
+ }
1468
+ return result;
1469
+ }
1369
1470
  /**
1370
1471
  * Phase: tool visibility.
1371
1472
  *
@@ -1373,6 +1474,8 @@ export const CONDUCTOR_HOOKS_DURABLE_REMEDIATION = `install the CLI persistently
1373
1474
  * own consent, then prints the restart advisory. It never creates a host config
1374
1475
  * — the merge helper's never-create rule is what keeps a declined or
1375
1476
  * unconfigured repository from acquiring files it did not ask for.
1477
+ *
1478
+ * Production has not reached this phase since BAPI-1461; the converging setup applies the same operation.
1376
1479
  */
1377
1480
  async function runConductorToolVisibilityPhase(deps, local) {
1378
1481
  const consented = await confirm(deps, "Update existing supported host MCP configurations (.mcp.json, .vscode/mcp.json, " +
@@ -1386,16 +1489,13 @@ async function runConductorToolVisibilityPhase(deps, local) {
1386
1489
  ],
1387
1490
  };
1388
1491
  }
1389
- let mergedProfile;
1390
- try {
1391
- mergedProfile = await local.mergeProfileToken();
1392
- }
1393
- catch {
1394
- // The thrown value is discarded: it can carry an absolute config path.
1492
+ // The legacy phase merges unconditionally and reports every non-empty merge, so it skips the fresh pre-write inspection.
1493
+ const result = await applyToolVisibility(deps, local, { freshInspection: false });
1494
+ if (result.outcome === "failed") {
1395
1495
  deps.errorLog(" the host MCP profile could not be updated.");
1396
1496
  return { manualActions: [], fatal: true };
1397
1497
  }
1398
- if (mergedProfile === "") {
1498
+ if (result.outcome === "no_entry") {
1399
1499
  deps.log(" no supported host MCP configuration carries a Bridge entry, so nothing " +
1400
1500
  "was written (this command never creates one).");
1401
1501
  return {
@@ -1404,31 +1504,14 @@ async function runConductorToolVisibilityPhase(deps, local) {
1404
1504
  ],
1405
1505
  };
1406
1506
  }
1407
- // Which configs actually carry the token now. Derived from the READ-ONLY
1408
- // inspector rather than guessed from the merged profile string, which says
1409
- // nothing about which files it came from.
1410
- let carrying = [];
1411
- try {
1412
- const inspection = await local.inspectProfileToken();
1413
- carrying = inspection.configs
1414
- .filter((c) => c.state === "token-present")
1415
- .map((c) => c.path);
1416
- }
1417
- catch {
1418
- // A failed read-back is not a failed merge. The advisory below still prints.
1419
- }
1420
- deps.log(carrying.length > 0
1421
- ? ` updated: ${carrying.join(", ")}`
1507
+ deps.log(result.carryingPaths.length > 0
1508
+ ? ` updated: ${result.carryingPaths.join(", ")}`
1422
1509
  : " the Epic Implementer profile was merged into your supported host MCP config(s).");
1423
1510
  // Coverage honesty: the merge path writes these three files and no others.
1424
1511
  deps.log(" Codex and Copilot host configuration was NOT inspected or changed.");
1425
- deps.log(` ${formatConductorRestartAdvisory(mergedProfile)}`);
1426
- const recorded = await local.recordCapability("conductor_tool_visibility");
1427
- if (!recorded.ok) {
1428
- // Advisory: install state is a diagnostic aid. A recording failure does not
1429
- // invalidate the host-config change that just landed.
1430
- deps.errorLog(` note: install-state not updated (${recorded.error ?? "unknown"})`);
1431
- }
1512
+ deps.log(` ${formatConductorRestartAdvisory(result.mergedProfile)}`);
1513
+ for (const note of result.notes)
1514
+ deps.errorLog(` note: ${note}`);
1432
1515
  return { manualActions: [] };
1433
1516
  }
1434
1517
  /**
@@ -2030,11 +2113,16 @@ function renderReviewPolicy(deps, options, decision) {
2030
2113
  "default and stamped into a new run that sets no review policy of its own. An explicit per-run " +
2031
2114
  "policy always wins, and changing this later never alters an already-approved run."
2032
2115
  : decision.basis === "workflow_present"
2033
- ? ` Inferred: ${CLAUDE_REVIEW_WORKFLOW_RELPATH} exists on your default branch. It is stored as the ` +
2034
- "project default, and a stored default is never overwritten by a later run. Pass --review-policy to choose another."
2035
- : ` Inferred: no ${CLAUDE_REVIEW_WORKFLOW_RELPATH} was found on your default branch, so no Claude review ` +
2036
- "workflow is needed. It is stored as the project default, and a stored default is never overwritten by a " +
2037
- "later run. Pass --review-policy verdict_protocol to opt in to AI review.");
2116
+ ? ` Inferred: ${CLAUDE_REVIEW_WORKFLOW_RELPATH} exists on your default branch and emits both the run-id: and ` +
2117
+ "Reviewed-SHA: markers. It is stored as the project default, and a stored default is never overwritten by a later run. " +
2118
+ "Pass --review-policy to choose another."
2119
+ : decision.basis === "workflow_without_markers"
2120
+ ? ` Inferred: ${CLAUDE_REVIEW_WORKFLOW_RELPATH} exists on your default branch but does not emit both the run-id: ` +
2121
+ "and Reviewed-SHA: markers that verdict_protocol needs, so repository_policy was stored as the project default. " +
2122
+ "Pass --review-policy verdict_protocol to opt in; setup then offers to write the workflow."
2123
+ : ` Inferred: no ${CLAUDE_REVIEW_WORKFLOW_RELPATH} was found on your default branch, so no Claude review ` +
2124
+ "workflow is needed. It is stored as the project default, and a stored default is never overwritten by a " +
2125
+ "later run. Pass --review-policy verdict_protocol to opt in to AI review.");
2038
2126
  return;
2039
2127
  }
2040
2128
  deps.log(`Review policy: ${options.reviewPolicy}`);
@@ -2954,27 +3042,21 @@ function storedReviewSource(policy) {
2954
3042
  // A stored value this client cannot interpret is still a stored choice.
2955
3043
  return "unrecognized";
2956
3044
  }
2957
- /** Whether `.github/workflows/claude-review.yml` exists on the remote default branch snapshot. */
2958
- async function remoteReviewWorkflowExists(setup, snapshot) {
2959
- if (snapshot === null || setup.readSnapshotFile === undefined)
2960
- return false;
2961
- try {
2962
- await setup.readSnapshotFile(snapshot, CLAUDE_REVIEW_WORKFLOW_RELPATH);
2963
- return true;
2964
- }
2965
- catch {
2966
- // Absent and unreadable both fall back to repository_policy, which needs no workflow.
2967
- return false;
2968
- }
2969
- }
2970
3045
  /**
2971
3046
  * Decide the review default: explicit `--review-policy` first; otherwise none when
2972
- * a project default is already stored (or cannot be read); otherwise
2973
- * `verdict_protocol` when the claude-review workflow exists on the remote default
2974
- * branch and `repository_policy` when it is absent or cannot be read. The remote
2975
- * snapshot decides, never the person's checkout. Reads only.
3047
+ * a project default is already stored (or cannot be read); otherwise infer from the
3048
+ * server's own read of the review workflow (BAPI-1714).
3049
+ *
3050
+ * `verdict_protocol` is inferred ONLY when the server's probe succeeded, the file
3051
+ * is present, and it emits BOTH the `run-id:` and `Reviewed-SHA:` markers (each
3052
+ * literally `true`). A workflow that is present but known to lack a marker cannot
3053
+ * produce the evidence `verdict_protocol` needs, so `repository_policy` is stored
3054
+ * with the `workflow_without_markers` basis. An absent workflow, a failed probe, or
3055
+ * any unknown fact keeps the `repository_policy` fallback. Workflow parsing stays
3056
+ * server-owned: this reads the typed observation and adds no YAML parser, marker
3057
+ * scanner, or provider probe. Reads only.
2976
3058
  */
2977
- async function resolveReviewDefault(deps, options, setup, access, snapshot) {
3059
+ async function resolveReviewDefault(deps, options, access, reviewWorkflow) {
2978
3060
  let stored;
2979
3061
  try {
2980
3062
  stored = storedReviewSource(await fetchConductorSetupPolicy(access, deps.fetchJson));
@@ -2989,11 +3071,16 @@ async function resolveReviewDefault(deps, options, setup, access, snapshot) {
2989
3071
  return { kind: "preserve", basis: "unreadable", stored: null };
2990
3072
  if (stored !== null)
2991
3073
  return { kind: "preserve", basis: "stored", stored };
2992
- const exists = await remoteReviewWorkflowExists(setup, snapshot);
3074
+ const probed = reviewWorkflow?.probe_succeeded === true;
3075
+ const present = probed && reviewWorkflow?.workflow_present === true;
3076
+ if (present && reviewWorkflow?.emits_run_id === true && reviewWorkflow?.emits_reviewed_sha === true) {
3077
+ return { kind: "send", source: "verdict_protocol", basis: "workflow_present", stored: null };
3078
+ }
3079
+ const knownMissingMarker = present && (reviewWorkflow?.emits_run_id === false || reviewWorkflow?.emits_reviewed_sha === false);
2993
3080
  return {
2994
3081
  kind: "send",
2995
- source: exists ? "verdict_protocol" : "repository_policy",
2996
- basis: exists ? "workflow_present" : "workflow_absent",
3082
+ source: "repository_policy",
3083
+ basis: knownMissingMarker ? "workflow_without_markers" : "workflow_absent",
2997
3084
  stored: null,
2998
3085
  };
2999
3086
  }
@@ -3566,11 +3653,8 @@ async function runRemoveMergeToken(options, deps, setup) {
3566
3653
  function localAdvisories(report) {
3567
3654
  const out = [];
3568
3655
  const section = (id) => report.sections.find((s) => s.id === id);
3569
- const profile = section("epic-implementer-profile-token");
3570
- if (profile !== undefined && profile.status !== "ok") {
3571
- out.push("to see the Epic Implementer tools in your editor, add `epic_implementer` to BRIDGE_MCP_PROFILE " +
3572
- "in your MCP configuration, then restart the editor");
3573
- }
3656
+ // BAPI-1719: the profile-token advisory moved to the `local.tool-visibility` setup item,
3657
+ // the single representation of that gap. Only the hook advisory stays here.
3574
3658
  const hooks = section("conductor-hook-targets");
3575
3659
  if (hooks !== undefined && hooks.status !== "ok") {
3576
3660
  out.push("for local event history, run `epic-implementer install-git-hooks`");
@@ -4671,6 +4755,13 @@ async function collectDecisionEvidence(input) {
4671
4755
  ...(setupPrOffersWorkflow(input) && workflowState !== "installed" ? { managedWorkflowViaSetupPr: true } : {}),
4672
4756
  },
4673
4757
  launchProfile: { selected: options.launchProfile ?? null, notification: state.evidence.notification?.state ?? null },
4758
+ // BAPI-1719: from the same collected evidence and planned-fix list setup uses. Present only
4759
+ // when the fix is planned, so every proposal without it keeps its exact evidence and digest.
4760
+ ...(fixes.includes("tool_visibility")
4761
+ ? { toolVisibility: { planned: true, configPaths: state.evidence.toolVisibility?.state === "needs_merge" ? [...state.evidence.toolVisibility.configPaths] : [] } }
4762
+ : {}),
4763
+ // BAPI-1526: present only when the fix is planned, so every other proposal keeps its digest.
4764
+ ...(fixes.includes("qualify_gate") ? { qualifyGate: { planned: true } } : {}),
4674
4765
  repositoryFacts: {
4675
4766
  ...(await collectRepositoryFacts(deps, grantInventory, input.readToolchains)),
4676
4767
  ...(state.ciSystems !== undefined
@@ -5018,13 +5109,44 @@ export function workflowWriteResult(outcome, asked, decision) {
5018
5109
  return { key: "setup_pr", status: outcome.status, target, reason: outcome.reason, fix: "Rerun setup once the cause above is fixed." };
5019
5110
  }
5020
5111
  }
5112
+ /** BAPI-1526 — why a declined gate qualification leaves the item outstanding. */
5113
+ const QUALIFY_GATE_DECLINED_REASON = "the gate was not qualified, so unattended runs that rely on it stay refused";
5114
+ /**
5115
+ * BAPI-1526 — one `qualify_gate` write result per qualification report. The text is
5116
+ * fixed; the qualification phase already printed its own explanation above.
5117
+ */
5118
+ export function qualifyGateWriteResult(report, target) {
5119
+ const rerun = `Fix the cause above, then rerun setup or run ${PRINTED_QUALIFY_GATE_COMMAND}.`;
5120
+ switch (report) {
5121
+ case "qualified":
5122
+ return { key: "qualify_gate", status: "written", target };
5123
+ case "not_applicable":
5124
+ return { key: "qualify_gate", status: "unchanged", target, reason: "the stored gate has no local commands to qualify" };
5125
+ case "queued":
5126
+ case "running":
5127
+ case "unverified":
5128
+ return { key: "qualify_gate", status: "uncertain", target, reason: "the qualification has not finished, or its result could not be read", fix: `Check readiness, or run ${PRINTED_QUALIFY_GATE_COMMAND}.` };
5129
+ case "failed":
5130
+ case "could_not_run":
5131
+ case "stale":
5132
+ case "refused":
5133
+ return { key: "qualify_gate", status: "failed", target, reason: `the gate qualification ${report === "failed" ? "failed" : report === "could_not_run" ? "could not run" : report === "stale" ? "was for an older gate revision" : "was refused"}`, fix: rerun };
5134
+ }
5135
+ }
5136
+ /** BAPI-1718 — why a reference answer did nothing when a merge token is already stored. Fixed text. */
5137
+ const MERGE_TOKEN_REFERENCE_UNUSED_REASON = "a merge token is already stored for this repository, so the reference was not used. " +
5138
+ "To replace it, run install epic-implementer --remove-merge-token, then rerun setup";
5021
5139
  function fixOutcomeResult(key, target, outcome) {
5022
5140
  if (outcome.status === "failed") {
5023
- return { key, status: "failed", target, reason: outcome.reason, fix: "Fix the cause above, then rerun setup with the same answers." };
5141
+ return { key, status: "failed", target, reason: outcome.reason, fix: outcome.fix ?? "Fix the cause above, then rerun setup with the same answers." };
5142
+ }
5143
+ if (outcome.status === "unattempted") {
5144
+ return { key, status: "unattempted", target, reason: outcome.reason, fix: outcome.fix };
5024
5145
  }
5025
5146
  // BAPI-1667: fixed advisory text only. It reports; it never changes the status.
5026
5147
  const advisories = [...new Set(outcome.advisories ?? [])];
5027
- return { key, status: outcome.status, target, ...(advisories.length > 0 ? { reason: advisories.join(" ") } : {}) };
5148
+ const reason = outcome.reason ?? (advisories.length > 0 ? advisories.join(" ") : undefined);
5149
+ return { key, status: outcome.status, target, ...(reason !== undefined ? { reason } : {}) };
5028
5150
  }
5029
5151
  function indexProgress(index) {
5030
5152
  if (index.state === "reached")
@@ -5280,7 +5402,7 @@ async function runConvergingSetup(options, deps, setup) {
5280
5402
  }
5281
5403
  const readToolchains = snapshotToolchainReader(setup, snapshot);
5282
5404
  // ---- The review default: explicit flag, then what is stored, then the remote workflow ----
5283
- const reviewDefault = await resolveReviewDefault(deps, options, setup, access, snapshot);
5405
+ const reviewDefault = await resolveReviewDefault(deps, options, access, firstReport.readiness?.review_workflow);
5284
5406
  renderReviewPolicy(deps, options, reviewDefault);
5285
5407
  // ---- The gate: explicit flags win, a stored gate is kept, otherwise facts decide ----
5286
5408
  // BAPI-1638: the answers path plans the gate without a terminal, so no discovered
@@ -5348,6 +5470,8 @@ async function runConvergingSetup(options, deps, setup) {
5348
5470
  if (setup.epicServer !== undefined) {
5349
5471
  state.evidence = { ...state.evidence, epicServer: await assessEpicServer(setup.epicServer, access.repoName) };
5350
5472
  }
5473
+ // BAPI-1719: whether the Bridge MCP entries load the Epic Implementer group, read-only. Its item is advisory.
5474
+ state.evidence = { ...state.evidence, toolVisibility: await collectToolVisibilityEvidence(deps.localProvisioning) };
5351
5475
  // BAPI-1635: the selected profile's escalation declaration, read-only.
5352
5476
  {
5353
5477
  const notification = await collectNotificationEvidence(deps, options, baseUrl);
@@ -5371,6 +5495,14 @@ async function runConvergingSetup(options, deps, setup) {
5371
5495
  gateOrDefaultsNeedWrite: gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness, reviewDefault),
5372
5496
  suppliedPolicyInput: options.reviewPolicyExplicit || options.replaceDoneGate || hasExplicitGateInput(options.gate),
5373
5497
  ...(options.epicServerChange === true ? { epicServerChangeRequested: true } : {}),
5498
+ // BAPI-1526: the two gate-qualification facts. A gate revision with local commands this
5499
+ // pass writes (from explicit gate input, or setup's own policy write), with no test-command
5500
+ // trial in this pass that would qualify it, is offered qualification.
5501
+ ...(options.gate.qualifyGate ? { qualifyGateRequested: true } : {}),
5502
+ ...(gatePlan !== null && gatePlan.write !== null && gatePlan.desired.localCommands.length > 0
5503
+ && options.testCommand === undefined && gatePlan.testCommandTrial?.eligible !== true
5504
+ ? { explicitLocalGateUnproven: true }
5505
+ : {}),
5374
5506
  };
5375
5507
  const fixes = planSetupFixes(state.evidence, planContext);
5376
5508
  // BAPI-1667: one read-only snapshot for both setup paths. An ordinary interactive run
@@ -5554,6 +5686,8 @@ async function runConvergingSetup(options, deps, setup) {
5554
5686
  }
5555
5687
  let policyResult = null;
5556
5688
  let epicServerChanged = false;
5689
+ // BAPI-1719: what the profile merge did, for the closing assessment and the closing line.
5690
+ let toolVisibilityApplied = null;
5557
5691
  const answerOf = (key) => decisionFor(proposal, key);
5558
5692
  const optionOf = (key) => {
5559
5693
  const d = answerOf(key);
@@ -5666,22 +5800,72 @@ async function runConvergingSetup(options, deps, setup) {
5666
5800
  key: "test_command",
5667
5801
  run: async () => {
5668
5802
  // ---- Explicit operations, each behind its own consent (unchanged) -------
5669
- if (options.gate.qualifyGate && gatePlan !== null && gatePlan.desired.localCommands.length > 0
5670
- && policyResult?.status !== "deferred" && policyResult?.status !== "unknown") {
5803
+ const qualifiable = gatePlan !== null && gatePlan.desired.localCommands.length > 0
5804
+ && policyResult?.status !== "deferred" && policyResult?.status !== "unknown";
5805
+ if (options.gate.qualifyGate && qualifiable) {
5671
5806
  await runConductorGateQualification(gateIo, access, deps.gate, {
5672
5807
  revision: policyResult?.current?.state.revision ?? gatePlan.current.revision,
5673
5808
  baseUrl,
5674
5809
  });
5810
+ return null;
5811
+ }
5812
+ // BAPI-1526: the `qualify_gate` fix, behind its own consent. Same step, same revision.
5813
+ if (!fixes.includes("qualify_gate"))
5814
+ return null;
5815
+ const target = "repository_gate.qualification";
5816
+ // A test-command trial in this pass already qualifies the gate (promoted), or is still finishing
5817
+ // the same job (uncertain). Asking again would be redundant, so nothing is asked or queued.
5818
+ if (state.trial?.status === "promoted" || state.trial?.status === "uncertain") {
5819
+ return { key: "qualify_gate", status: "unchanged", target, reason: "the test-command check in this pass qualifies the gate" };
5820
+ }
5821
+ if (proposal !== null) {
5822
+ const d = answerOf("qualify_gate");
5823
+ if (d === undefined)
5824
+ return null;
5825
+ if (d.kind === "decline")
5826
+ return { key: "qualify_gate", status: "declined", target, reason: QUALIFY_GATE_DECLINED_REASON };
5827
+ }
5828
+ else {
5829
+ if (deps.promptLine === undefined) {
5830
+ return { key: "qualify_gate", status: "declined", target, reason: "there is no interactive terminal, so the gate was not qualified" };
5831
+ }
5832
+ deps.log("");
5833
+ deps.log("Gate qualification");
5834
+ deps.log(" The local gate must pass once under the executor before an unattended run is admitted. Setup will run it now if you approve.");
5835
+ if (!(await confirm(deps, "Run the local gate once now to qualify it? [y/N]: "))) {
5836
+ deps.log(` declined — ${QUALIFY_GATE_DECLINED_REASON}.`);
5837
+ return { key: "qualify_gate", status: "declined", target, reason: QUALIFY_GATE_DECLINED_REASON };
5838
+ }
5839
+ }
5840
+ if (!qualifiable) {
5841
+ return { key: "qualify_gate", status: "unattempted", target, reason: "the gate this pass would qualify was not stored", fix: "Rerun setup once the gate is stored." };
5842
+ }
5843
+ let report;
5844
+ try {
5845
+ report = await runConductorGateQualification(gateIo, access, deps.gate, {
5846
+ revision: policyResult?.current?.state.revision ?? gatePlan.current.revision,
5847
+ baseUrl,
5848
+ });
5675
5849
  }
5676
- return null;
5850
+ catch {
5851
+ return { key: "qualify_gate", status: "uncertain", target, reason: "the qualification's result is unknown", fix: `Check readiness, or run ${PRINTED_QUALIFY_GATE_COMMAND}.` };
5852
+ }
5853
+ // A local result is reported only. The closing verdict still comes from the server's refreshed report.
5854
+ return qualifyGateWriteResult(report, target);
5677
5855
  },
5678
5856
  },
5679
5857
  {
5680
5858
  key: "merge_token",
5681
5859
  run: async () => {
5682
5860
  if (!fixes.includes("merge_token") || state.identity === null) {
5683
- return proposal === null || answerOf("merge_token")?.kind !== "reference" ? null
5684
- : { key: "merge_token", status: "unchanged", target: "merge_token" };
5861
+ if (proposal === null || answerOf("merge_token")?.kind !== "reference")
5862
+ return null;
5863
+ // BAPI-1718: a reference answered against an already configured token is a deliberate
5864
+ // no-op. Say so, without resolving the reference or touching the credential store.
5865
+ // The reason lives here only; the setup record's stable "in place" row is unchanged.
5866
+ return fixes.includes("merge_token")
5867
+ ? { key: "merge_token", status: "unchanged", target: "merge_token" }
5868
+ : { key: "merge_token", status: "unchanged", target: "merge_token", reason: MERGE_TOKEN_REFERENCE_UNUSED_REASON };
5685
5869
  }
5686
5870
  const d = answerOf("merge_token");
5687
5871
  const answer = proposal === null || d === undefined ? undefined
@@ -5711,14 +5895,33 @@ async function runConvergingSetup(options, deps, setup) {
5711
5895
  {
5712
5896
  key: "worker_mcp_grant",
5713
5897
  run: async () => {
5714
- if (!fixes.includes("mcp_grant") || setup.mcpGrant === undefined || grantInventory === null) {
5715
- return proposal === null || answerOf("worker_mcp_grant")?.kind !== "selection" ? null
5716
- : { key: "worker_mcp_grant", status: "unchanged", target: "mcp_grant" };
5717
- }
5898
+ if (setup.mcpGrant === undefined)
5899
+ return null;
5718
5900
  const d = answerOf("worker_mcp_grant");
5901
+ const planned = fixes.includes("mcp_grant");
5902
+ // BAPI-1718: a stated selection reaches the writer whether or not the grant was planned
5903
+ // as a fix. Before, a settled grant answered "unchanged" and silently wrote nothing.
5904
+ const stated = proposal !== null && d?.kind === "selection";
5905
+ // Not planned, and no selection to apply: absent, keep, and decline all change nothing.
5906
+ if (!planned && !stated)
5907
+ return null;
5908
+ if (grantInventory === null) {
5909
+ // A planned grant with no stated selection keeps its earlier behavior: nothing to do.
5910
+ if (!stated)
5911
+ return null;
5912
+ return {
5913
+ key: "worker_mcp_grant",
5914
+ status: "unattempted",
5915
+ target: "mcp_grant",
5916
+ reason: "the MCP servers could not be inspected, so the approved selection was not written",
5917
+ fix: "Rerun setup with the same answers.",
5918
+ };
5919
+ }
5719
5920
  const answer = proposal === null || d === undefined ? undefined
5720
5921
  : d.kind === "selection" ? { decision: "select", ids: d.ids } : { decision: "decline" };
5721
- const outcome = await fixMcpGrant(deps, setup.mcpGrant, access.repoName, grantInventory, answer, sfccGrantIds(epicServerSnapshot, grantInventory));
5922
+ const outcome = await fixMcpGrant(deps, setup.mcpGrant, access.repoName, grantInventory, answer, sfccGrantIds(epicServerSnapshot, grantInventory),
5923
+ // Only the newly enabled path (a settled grant) is protected from losing servers.
5924
+ stated && !planned ? { keepStored: true } : {});
5722
5925
  return fixOutcomeResult("worker_mcp_grant", "mcp_grant", outcome);
5723
5926
  },
5724
5927
  },
@@ -5845,13 +6048,69 @@ async function runConvergingSetup(options, deps, setup) {
5845
6048
  return written;
5846
6049
  },
5847
6050
  },
6051
+ {
6052
+ // BAPI-1719: the local MCP profile merge, last, behind terminal or answers approval.
6053
+ // It never gates readiness: a decline, a failure, or an unknown read stays advisory.
6054
+ key: "tool_visibility",
6055
+ run: async () => {
6056
+ const local = deps.localProvisioning;
6057
+ // No planned fix (including a stated conditional answer whose choice is gone) means no apply.
6058
+ if (!fixes.includes("tool_visibility") || local === undefined)
6059
+ return null;
6060
+ const target = "host_mcp_profile";
6061
+ const paths = state.evidence.toolVisibility?.state === "needs_merge" ? state.evidence.toolVisibility.configPaths : [];
6062
+ if (proposal !== null) {
6063
+ const d = answerOf("tool_visibility");
6064
+ if (d === undefined || (d.kind === "option" && d.option === "keep"))
6065
+ return null;
6066
+ if (d.kind === "decline") {
6067
+ return { key: "tool_visibility", status: "declined", target, reason: "no MCP configuration was changed" };
6068
+ }
6069
+ }
6070
+ else {
6071
+ // The terminal path: the phased y/N wording. Without a terminal this is "no", and nothing is asked.
6072
+ if (deps.promptLine === undefined)
6073
+ return { key: "tool_visibility", status: "declined", target, reason: "there is no interactive terminal, so no MCP configuration was changed" };
6074
+ deps.log("");
6075
+ deps.log("Epic Implementer tools in your editor");
6076
+ deps.log(` ${paths.length > 0 ? paths.join(", ") : "Your MCP configuration"} does not load the epic_implementer group yet. Approving adds it to the existing Bridge entry and keeps your other groups; you then restart your MCP client.`);
6077
+ const consented = await confirm(deps, "Update existing supported host MCP configurations (.mcp.json, .vscode/mcp.json, " +
6078
+ ".cursor/mcp.json) to add the `epic_implementer` profile? [y/N]: ");
6079
+ if (!consented) {
6080
+ deps.log(" declined — no host MCP configuration was changed.");
6081
+ return { key: "tool_visibility", status: "declined", target, reason: "no MCP configuration was changed" };
6082
+ }
6083
+ }
6084
+ const result = await applyToolVisibility(deps, local);
6085
+ toolVisibilityApplied = result;
6086
+ for (const note of result.notes)
6087
+ deps.errorLog(` note: ${note}`);
6088
+ // A failure is advisory, but never silent: fixed wording and fixed paths only.
6089
+ if (result.outcome === "failed") {
6090
+ deps.errorLog(` ${result.failure ?? TOOL_VISIBILITY_FAILURE_TEXT.write}${result.failurePaths.length > 0 ? ` (${result.failurePaths.join(", ")})` : ""}; the MCP profile was not changed by setup.`);
6091
+ }
6092
+ if (result.outcome === "written") {
6093
+ deps.log(` updated: ${(result.changedPaths.length > 0 ? result.changedPaths : result.carryingPaths).join(", ")}`);
6094
+ // Coverage honesty: the merge path writes these three files and no others.
6095
+ deps.log(" Codex and Copilot host configuration was NOT inspected or changed.");
6096
+ }
6097
+ const guidance = result.guidance.join(" ");
6098
+ const outcome = result.outcome === "failed"
6099
+ ? { status: "failed", reason: `${result.failure ?? TOOL_VISIBILITY_FAILURE_TEXT.write}${result.failurePaths.length > 0 ? ` (${result.failurePaths.join(", ")})` : ""}`, ...(guidance.length > 0 ? { fix: guidance } : {}) }
6100
+ : result.outcome === "written"
6101
+ ? { status: "written", advisories: [...result.advisories, ...result.guidance] }
6102
+ : { status: "unchanged", ...(result.outcome === "no_entry" ? { advisories: ["no supported Bridge entry exists, so nothing was written (setup never creates one)"] } : {}) };
6103
+ const written = fixOutcomeResult("tool_visibility", target, outcome);
6104
+ return result.outcome === "written" ? { ...written, read_back: { config_paths: result.changedPaths.length > 0 ? result.changedPaths : result.carryingPaths } } : written;
6105
+ },
6106
+ },
5848
6107
  ];
5849
6108
  // The interactive path keeps its original question order: the missing-item fixes
5850
6109
  // (merge token, re-index, grant, epic server) come right after the gate and before
5851
6110
  // the learned check, the setup PR, and qualification. The answers path runs the
5852
6111
  // array as written so the learned check and setup PR chain on the gate.
5853
6112
  const ordered = proposal !== null ? operations
5854
- : [operations[0], ...operations.slice(4, 8), ...operations.slice(1, 4), operations[8], operations[9]];
6113
+ : [operations[0], ...operations.slice(4, 8), ...operations.slice(1, 4), operations[8], operations[9], operations[10]];
5855
6114
  const firstApply = await applyInstallProposal({ proposal, digest: proposalDigest, refusal: null }, { operations: ordered });
5856
6115
  const applied = firstApply.kind === "applied" ? firstApply.result : { complete: false, results: [] };
5857
6116
  if (options.reviewPolicy === "verdict_protocol" && !options.skipWorkflow) {
@@ -5942,6 +6201,16 @@ async function runConvergingSetup(options, deps, setup) {
5942
6201
  ? { ...closingEpicServer, statementError }
5943
6202
  : closingEpicServer;
5944
6203
  }
6204
+ // BAPI-1719: the same read-only collection, run again after the apply. A confirmed write whose
6205
+ // read-back does not show the group stays visible as `unknown` verification, never as satisfied.
6206
+ {
6207
+ const closingVisibility = await collectToolVisibilityEvidence(deps.localProvisioning);
6208
+ const applied = toolVisibilityApplied;
6209
+ closing.evidence.toolVisibility =
6210
+ applied?.outcome === "written" && closingVisibility.state !== "met"
6211
+ ? { state: "unknown", reason: "verification" }
6212
+ : closingVisibility;
6213
+ }
5945
6214
  // ---- BAPI-1260: the reusable launch profile (explicit) ------------------
5946
6215
  // BAPI-1635: this runs BEFORE the final items are projected, so a profile saved by
5947
6216
  // this invocation is read back and judged for escalation, not left as pre-save evidence.
@@ -6049,6 +6318,12 @@ async function runConvergingSetup(options, deps, setup) {
6049
6318
  if (r.fix !== undefined)
6050
6319
  deps.log(` ${r.key}: ${r.fix}`);
6051
6320
  }
6321
+ // BAPI-1719: once, after a confirmed profile write, even when its verification is unknown.
6322
+ // The same instruction rides in the structured write result's reason.
6323
+ if (toolVisibilityApplied?.outcome === "written") {
6324
+ deps.log("");
6325
+ deps.log(TOOL_VISIBILITY_RESTART_LINE);
6326
+ }
6052
6327
  deps.installDocumentSink?.({
6053
6328
  items,
6054
6329
  decisions: decisionEvidence,
@@ -6201,7 +6476,7 @@ async function closingMcpGrantState(grantDeps, repoName, inventory) {
6201
6476
  ? { state: "met" }
6202
6477
  : { state: "needs_action", reason: "changed" };
6203
6478
  }
6204
- export async function fixMcpGrant(deps, grantDeps, repoName, inventory, answer, sfccRecommendedIds = []) {
6479
+ export async function fixMcpGrant(deps, grantDeps, repoName, inventory, answer, sfccRecommendedIds = [], options = {}) {
6205
6480
  deps.log("");
6206
6481
  deps.log("Worker MCP servers");
6207
6482
  deps.log(` Epic Implementer workers in ${repoName} always get Bridge. You can approve extra MCP servers for them, ` +
@@ -6234,7 +6509,7 @@ export async function fixMcpGrant(deps, grantDeps, repoName, inventory, answer,
6234
6509
  return { status: "declined" };
6235
6510
  }
6236
6511
  if (answer?.decision === "select")
6237
- return publishApprovedGrant(deps, grantDeps, repoName, inventory, answer.ids);
6512
+ return publishApprovedGrant(deps, grantDeps, repoName, inventory, answer.ids, options);
6238
6513
  if (!deps.promptLine) {
6239
6514
  deps.log(" skipped approving MCP servers: there is no interactive terminal, so this counts as declined. Nothing changed.");
6240
6515
  return { status: "declined" };
@@ -6314,25 +6589,55 @@ async function publishGrant(deps, grantDeps, repoName, inventory, selectedIds) {
6314
6589
  * BAPI-1638 — the answers path: the selection is the approved option ids.
6315
6590
  * A grant that already holds exactly these servers, for the same inventory, is
6316
6591
  * `unchanged` and is not rewritten.
6592
+ *
6593
+ * BAPI-1718 — the stored names are compared whole, with no name filtered out, so a
6594
+ * selection that differs from what is stored is never reported `unchanged`.
6317
6595
  */
6318
- async function publishApprovedGrant(deps, grantDeps, repoName, inventory, ids) {
6596
+ async function publishApprovedGrant(deps, grantDeps, repoName, inventory, ids, options = {}) {
6319
6597
  const names = inventory.candidates
6320
6598
  .filter((c) => c.definitions.some((d) => ids.includes(d.id)))
6321
6599
  .map((c) => c.name)
6322
6600
  .sort();
6601
+ let current;
6602
+ let readFailed = false;
6323
6603
  try {
6324
- const current = await grantDeps.readGrant(repoName);
6325
- if (current.state === "ok" && current.grant.candidate_fingerprint === inventory.fingerprint) {
6326
- const stored = current.grant.servers.map((server) => server.name).filter((name) => name !== "playwright" || names.includes(name)).sort();
6327
- if (stored.length === names.length && stored.every((name, i) => name === names[i])) {
6328
- deps.log(" unchanged — the stored approval already says this.");
6329
- return { status: "unchanged" };
6604
+ current = await grantDeps.readGrant(repoName);
6605
+ }
6606
+ catch {
6607
+ readFailed = true;
6608
+ }
6609
+ // The keep-stored guard protects a settled grant's selections within this one setup run: it
6610
+ // reads the grant fresh, just before any publish, and refuses to drop an approved server. It
6611
+ // takes no lock (a concurrent edit between the read and the write is not prevented) and it
6612
+ // does not change how a planned replacement behaves, which never sets the flag.
6613
+ if (options.keepStored === true) {
6614
+ if (readFailed || current === undefined || current.state === "unusable") {
6615
+ deps.log(" The approved MCP servers could not be read. Nothing changed.");
6616
+ return {
6617
+ status: "unattempted",
6618
+ reason: "the approved MCP servers could not be read, so the selection was not written",
6619
+ fix: "Rerun setup with the same answers.",
6620
+ };
6621
+ }
6622
+ if (current.state === "ok") {
6623
+ const omitted = current.grant.servers.map((server) => server.name).filter((name) => !names.includes(name)).sort();
6624
+ if (omitted.length > 0) {
6625
+ const reason = `the selection leaves out ${omitted.join(", ")}, which are already approved for workers. ` +
6626
+ "Setup never removes an approved server from a settled grant, so nothing changed. " +
6627
+ "To add a server, list every approved server plus the new one.";
6628
+ deps.log(` declined — ${reason}`);
6629
+ return { status: "declined", reason };
6330
6630
  }
6331
6631
  }
6332
6632
  }
6333
- catch {
6334
- // An unreadable grant is replaced through the same revalidated publication below.
6633
+ if (current !== undefined && current.state === "ok" && current.grant.candidate_fingerprint === inventory.fingerprint) {
6634
+ const stored = current.grant.servers.map((server) => server.name).sort();
6635
+ if (stored.length === names.length && stored.every((name, i) => name === names[i])) {
6636
+ deps.log(" unchanged — the stored approval already says this.");
6637
+ return { status: "unchanged" };
6638
+ }
6335
6639
  }
6640
+ // An unreadable grant (without the flag) is replaced through the same revalidated publication.
6336
6641
  deps.log(` Workers in ${repoName} would get: Bridge${names.length > 0 ? ` + ${names.join(", ")}` : " only"}.`);
6337
6642
  return publishGrant(deps, grantDeps, repoName, inventory, ids);
6338
6643
  }
@@ -6361,6 +6666,43 @@ async function publishCapabilityStatement(deps, grantDeps, access, verbose) {
6361
6666
  // BAPI-1546: the epic-server item
6362
6667
  // ---------------------------------------------------------------------------
6363
6668
  /** Read the record and map it to setup evidence. Read-only; never throws. */
6669
+ /**
6670
+ * BAPI-1719: project one read-only profile inspection onto the setup evidence.
6671
+ * `met` only when every supported Bridge entry loads the group AND the inspection
6672
+ * was conclusive (no unreadable config); a needed merge, a missing entry, and an
6673
+ * inconclusive read stay distinct. Carries fixed config paths only.
6674
+ *
6675
+ * A config that registers Bridge under both names comes first: the writer refuses
6676
+ * it all-or-nothing, so planning a merge would only produce a failed write and a
6677
+ * setup that exits 1 on every run. Setup skips the merge and shows a notice instead,
6678
+ * the way the SFCC profile merge (`index.ts`) and vendor-first host provisioning
6679
+ * (`skipped-duplicate-registration`) leave such a config untouched.
6680
+ */
6681
+ export function toolVisibilityStateFrom(inspection) {
6682
+ const duplicates = inspection.configs.filter((c) => c.duplicateRegistration === true).map((c) => c.path);
6683
+ if (duplicates.length > 0)
6684
+ return { state: "duplicate_registration", configPaths: duplicates };
6685
+ if (profileMergeNeededFrom(inspection)) {
6686
+ return {
6687
+ state: "needs_merge",
6688
+ configPaths: inspection.configs.filter((c) => c.state === "token-absent").map((c) => c.path),
6689
+ };
6690
+ }
6691
+ if (inspection.configs.some((c) => c.state === "unreadable"))
6692
+ return { state: "unknown", reason: "inspection" };
6693
+ return inspection.bridgeEntryPresent ? { state: "met" } : { state: "no_entry" };
6694
+ }
6695
+ /** Read-only. Unwired dependencies or a throwing inspector are `unknown`, never satisfied. */
6696
+ async function collectToolVisibilityEvidence(local) {
6697
+ if (local === undefined)
6698
+ return { state: "unknown", reason: "inspection" };
6699
+ try {
6700
+ return toolVisibilityStateFrom(await local.inspectProfileToken());
6701
+ }
6702
+ catch {
6703
+ return { state: "unknown", reason: "inspection" };
6704
+ }
6705
+ }
6364
6706
  async function assessEpicServer(epicDeps, repoName) {
6365
6707
  let read;
6366
6708
  try {
@@ -6584,6 +6926,8 @@ const DRY_RUN_FIX_TEXT = Object.freeze({
6584
6926
  merge_token: "store a GitHub merge token on this computer (its own consent, read with no echo)",
6585
6927
  mcp_grant: "approve which extra MCP servers Epic Implementer workers get in this repository (one consent; the grant is stored outside every worktree)",
6586
6928
  epic_server: "choose the epic server for Epic Implementer runs: none, local, or sfcc_shared_active (its own consent; the record is stored outside every worktree)",
6929
+ tool_visibility: "add the epic_implementer group to your existing Bridge MCP entries, keeping the groups already listed, then restart your MCP client (its own consent; no file is created)",
6930
+ qualify_gate: "run the stored local gate once under a short-lived executor to qualify it for its current revision (its own consent; dry run runs nothing)",
6587
6931
  reindex: "use the default branch for indexing when it is the only candidate, or ask which branch to use when a different branch exists; then queue one tracked first parse, or one retry you approve. Dry run writes no configuration, queue, retry, authorization record, or file",
6588
6932
  });
6589
6933
  /**