@bridge_gpt/mcp-server 0.2.73 → 0.2.75

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 (123) hide show
  1. package/README.md +14 -7
  2. package/build/agent-launchers/claude-executor-adapter.js +12 -0
  3. package/build/agent-launchers/prompt.js +9 -21
  4. package/build/agents.generated.js +4 -4
  5. package/build/authored-plan.js +542 -0
  6. package/build/bridge-config.js +7 -1
  7. package/build/bridge-permissions.js +11 -0
  8. package/build/command-provisioning.js +4 -3
  9. package/build/commands.generated.js +6 -6
  10. package/build/conductor/bridge-api-client.js +692 -47
  11. package/build/conductor/command-drift.js +1 -1
  12. package/build/conductor/declared-extras.js +335 -0
  13. package/build/conductor/doctor.js +2 -0
  14. package/build/conductor/driver-pass-output.js +104 -0
  15. package/build/conductor/driver-pass.js +571 -0
  16. package/build/conductor/epic-branch-ci-inspection.js +61 -16
  17. package/build/conductor/epic-implementer-cli.js +370 -93
  18. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  19. package/build/conductor/epic-server-sfcc.js +58 -80
  20. package/build/conductor/epic-server.js +57 -4
  21. package/build/conductor/gate-discovery.js +253 -13
  22. package/build/conductor/gate-settings-review.js +58 -25
  23. package/build/conductor/launch-plan.js +58 -12
  24. package/build/conductor/open-decision-phrases.js +50 -0
  25. package/build/conductor/prerequisite-inputs.js +181 -14
  26. package/build/connect-github-api.js +18 -0
  27. package/build/connect-github.js +35 -18
  28. package/build/credential-delivery.js +280 -0
  29. package/build/credential-launch-safety.js +142 -0
  30. package/build/credential-materialization.js +91 -16
  31. package/build/credential-references-node-deps.js +29 -0
  32. package/build/credential-references.js +1394 -0
  33. package/build/credential-references.test-fixtures.js +211 -0
  34. package/build/credential-scan-conventions.js +145 -0
  35. package/build/credential-scan.js +517 -0
  36. package/build/credential-store.js +50 -0
  37. package/build/credentials-cli.js +252 -3
  38. package/build/dependency-install-declarations.js +47 -1
  39. package/build/docs.generated.js +8 -1
  40. package/build/doctor.js +41 -0
  41. package/build/drive-epic.js +684 -49
  42. package/build/epic-branch-ci-summary.js +18 -1
  43. package/build/epic-capability-statement.js +71 -3
  44. package/build/epic-ci-workflow-drift.js +52 -13
  45. package/build/epic-ci-workflow-install.js +31 -6
  46. package/build/epic-ci-workflow-v3.js +273 -0
  47. package/build/epic-ci-workflow.js +129 -7
  48. package/build/epic-implementer-bin.js +288 -83
  49. package/build/epic-implementer-bundle-cli.js +61 -0
  50. package/build/epic-implementer-claude-hook-bin.js +1 -1
  51. package/build/epic-implementer-env.js +3 -4
  52. package/build/epic-integration-pr.js +5 -2
  53. package/build/epic-launch-context.js +102 -7
  54. package/build/epic-server-record.js +30 -15
  55. package/build/executor/completion-contract.js +24 -1
  56. package/build/executor/credential-delivery-step.js +168 -0
  57. package/build/executor/deps.js +3 -1
  58. package/build/executor/env.js +39 -1
  59. package/build/executor/epic-server-context.js +23 -7
  60. package/build/executor/gate-qualification-job.js +193 -23
  61. package/build/executor/gate-qualification-tests-ran.js +232 -0
  62. package/build/executor/guarded-fast-forward-push.js +13 -8
  63. package/build/executor/job-runner.js +167 -738
  64. package/build/executor/job-type-wrappers.js +734 -0
  65. package/build/executor/permissions.js +85 -3
  66. package/build/executor/preflight.js +6 -2
  67. package/build/executor/process-containment.js +8 -1
  68. package/build/executor/prompt-spec.js +37 -3
  69. package/build/executor/required-verification.js +28 -2
  70. package/build/executor/runner.js +4 -1
  71. package/build/executor/types.js +9 -0
  72. package/build/executor/worker-database.js +6 -1
  73. package/build/executor/worker-guard-hook.js +24 -2
  74. package/build/executor-launch.js +4 -2
  75. package/build/generated/ticket-status.js +20 -0
  76. package/build/git-exclude-lock.js +187 -0
  77. package/build/index.js +589 -326
  78. package/build/install-bridge-conductor-answers.js +112 -22
  79. package/build/install-bridge-conductor-apply.js +38 -1
  80. package/build/install-bridge-conductor-assessment.js +482 -53
  81. package/build/install-bridge-conductor-compact.js +29 -2
  82. package/build/install-bridge-conductor-contracts.js +10 -1
  83. package/build/install-bridge-conductor-gate.js +379 -89
  84. package/build/install-bridge-conductor-setup.js +46 -8
  85. package/build/install-bridge-conductor-trial-report.js +170 -0
  86. package/build/install-bridge-conductor.js +925 -141
  87. package/build/install-bridge.js +88 -11
  88. package/build/install-doctor.js +38 -8
  89. package/build/install-sfcc-detection.js +120 -0
  90. package/build/install-sfcc-setup.js +185 -0
  91. package/build/mcp-grant-candidates.js +108 -96
  92. package/build/mcp-invoke.js +168 -4
  93. package/build/mcp-provisioning.js +21 -4
  94. package/build/mcp-server-invocation.js +13 -0
  95. package/build/merge-workflow-install.js +9 -1
  96. package/build/pipelines.generated.js +8 -7
  97. package/build/plan-generation.js +17 -0
  98. package/build/plane/status.js +8 -2
  99. package/build/printed-remedy-commands.js +59 -0
  100. package/build/project-root.js +40 -0
  101. package/build/readme.generated.js +1 -1
  102. package/build/repository-state-paths.js +5 -2
  103. package/build/repository-toolchains.js +16 -7
  104. package/build/scripts/saved-commands-config-field-driver.js +65 -0
  105. package/build/setup-epic.js +126 -16
  106. package/build/sfcc/credentials.js +3 -2
  107. package/build/sfcc/hostname.js +98 -2
  108. package/build/sfcc/tool-wrapper.js +6 -95
  109. package/build/start-tickets.js +193 -29
  110. package/build/test-support/executor-source-files.js +200 -0
  111. package/build/testing-config-client.js +25 -2
  112. package/build/third-party-mcp-targets.js +35 -4
  113. package/build/v2-readiness-requirements.js +5 -1
  114. package/build/version.generated.js +3 -3
  115. package/build/with-credentials.js +208 -0
  116. package/build/worker-guard-hook-bin.js +2 -2
  117. package/build/worktree-credential-delivery.js +340 -0
  118. package/docs/EPIC-IMPLEMENTER.md +4 -4
  119. package/docs/install/github-app.md +79 -92
  120. package/package.json +1 -1
  121. package/build/conductor/epic-reconcile.js +0 -603
  122. package/build/conductor/epic-runtime.js +0 -2020
  123. package/build/conductor/epic-state.js +0 -774
@@ -49,9 +49,10 @@ import { askSetupQuestion, setupConsentQuestion } from "./setup-question.js";
49
49
  */
50
50
  import { ConductorBridgeApiError, GATE_PROFILE_CAPABILITY_TOKEN, enqueueConductorGateQualification, fetchConductorGateCheckHistory, fetchConductorGateProfile, fetchConductorGateQualificationJob, fetchConductorReadiness, probeConductorGateProfileCapability, probeConductorGateProfileWatchedCapability, probeConductorGateProfileWorkerSetupCapability, putConductorGateProfile, requestConductorLearnedTestCommand, putEpicBranchCiDecision, } from "./conductor/bridge-api-client.js";
51
51
  import { describeGateConsequence } from "./conductor/readiness-sections.js";
52
+ import { CHANGE_TEST_COMMAND_TEXT, PASSED_TRIAL_RUN_TEXT, presentTrialResult, renderTrialReport, sanitizeCommandText, trialCommandLines, } from "./install-bridge-conductor-trial-report.js";
52
53
  import { applyApprovalExemption, assessApprovalExemptionScope, buildEpicBranchCiEvidence, exemptionManualSteps, inspectEpicBranchWorkflowCoverage, readEpicBranchRulesViaGh, } from "./conductor/epic-branch-ci-inspection.js";
53
- import { describeEvidence, discoverDeclarations, discoverGate, LOCAL_COMMAND_TIMEOUT_SECONDS, reportedProviderChecks, } from "./conductor/gate-discovery.js";
54
- import { dependencyInstallEqual, describeSettingsEdit, hasSettingsToReview, hasUnstoredDeclarationProposal, hintEqual, mustOrderOffer, mustOrderShortfallWarning, recommendedSettingsSelection, renderDeclarationsOnly, renderSettingsReview, reviewDeclarations, reviewDiscoveredSettings, settingsMatchStored, storedCiDatabase, terminalSafe, workerDatabaseEqual, workerEnvEqual, } from "./conductor/gate-settings-review.js";
54
+ import { dependencyInstallNoteSentences, describeEvidence, discoverDeclarations, discoverGate, discoverLocalTestCandidates, LOCAL_COMMAND_TIMEOUT_SECONDS, reportedProviderChecks, } from "./conductor/gate-discovery.js";
55
+ import { dependencyInstallEqual, mergeDependencyProposal, describeSettingsEdit, hasSettingsToReview, hasUnstoredDeclarationProposal, hintEqual, mustOrderOffer, mustOrderShortfallWarning, recommendedSettingsSelection, renderDeclarationsOnly, renderSettingsReview, reviewDeclarations, reviewDiscoveredSettings, settingsMatchStored, storedCiDatabase, terminalSafe, workerDatabaseEqual, workerEnvEqual, } from "./conductor/gate-settings-review.js";
55
56
  import { canonicalMustOrderPaths, sameMustOrderPaths, } from "./dependency-install-declarations.js";
56
57
  import { PRINTED_EXECUTOR_INSTALL_SERVICE_COMMAND, PRINTED_EXECUTOR_ID_INSTRUCTION, PRINTED_QUALIFY_GATE_COMMAND, PRINTED_REPO_WIDE_EXECUTOR_COMMAND, } from "./printed-remedy-commands.js";
57
58
  export function emptyConductorGateFlags() {
@@ -986,7 +987,24 @@ export async function runGateDiscovery(io, access, gateDeps) {
986
987
  const fs = gateDeps?.discoveryFs;
987
988
  if (!fs)
988
989
  return emptyProposal();
989
- return discoverGate({ fs, lookupHistory: historyLookupFor(io, access) });
990
+ const learned = await learnedInstructionsFor(gateDeps);
991
+ return discoverGate({
992
+ fs,
993
+ lookupHistory: historyLookupFor(io, access),
994
+ ...(learned !== undefined ? { learned } : {}),
995
+ ...(gateDeps?.platform !== undefined ? { platform: gateDeps.platform } : {}),
996
+ });
997
+ }
998
+ /** The learned snapshot, `undefined` when no reader was given. A failing reader is a limitation, never a throw. */
999
+ async function learnedInstructionsFor(gateDeps) {
1000
+ if (gateDeps?.learnedInstructions === undefined)
1001
+ return undefined;
1002
+ try {
1003
+ return await gateDeps.learnedInstructions();
1004
+ }
1005
+ catch {
1006
+ return null;
1007
+ }
990
1008
  }
991
1009
  /** A fresh explicit empty proposal: nothing discovered, nothing proposed. */
992
1010
  function emptyProposal() {
@@ -1259,13 +1277,24 @@ allowUnstored = false) {
1259
1277
  return null;
1260
1278
  let declarations;
1261
1279
  try {
1262
- declarations = await discoverDeclarations({ fs, providerChecks: desired.providerChecks });
1280
+ const learned = await learnedInstructionsFor(gateDeps);
1281
+ declarations = await discoverDeclarations({
1282
+ fs,
1283
+ providerChecks: desired.providerChecks,
1284
+ ...(learned !== undefined ? { learned } : {}),
1285
+ ...(gateDeps?.platform !== undefined ? { platform: gateDeps.platform } : {}),
1286
+ });
1263
1287
  }
1264
1288
  catch {
1265
1289
  return null;
1266
1290
  }
1291
+ // BAPI-1677: when extras could not be worked out, what is stored stands. An unknown
1292
+ // read never proposes a change to a stored list, so it cannot strip a stored extra.
1293
+ const unknownAgainstStored = declarations.dependencyInstallUnknown === true && (current.profile?.dependency_install?.length ?? 0) > 0;
1267
1294
  // Never re-offer what the owner already ignored or declined in this invocation.
1268
- const candidates = (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
1295
+ const candidates = unknownAgainstStored
1296
+ ? []
1297
+ : (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
1269
1298
  const ci = declarations.ciDatabaseProposal;
1270
1299
  const mustOrder = (declarations.mustOrderPathCandidates ?? []).filter((p) => !declined?.has(mustOrderProposalKey(p)));
1271
1300
  const workerDatabase = declarations.workerDatabaseProposal;
@@ -1276,6 +1305,14 @@ allowUnstored = false) {
1276
1305
  : {}),
1277
1306
  ...(candidates.length > 0 ? { dependencyInstallCandidates: candidates } : {}),
1278
1307
  ...(declarations.dependencyInstallNotes ? { dependencyInstallNotes: declarations.dependencyInstallNotes } : {}),
1308
+ ...(declarations.dependencyInstallLimitations ? { dependencyInstallLimitations: declarations.dependencyInstallLimitations } : {}),
1309
+ ...(declarations.dependencyInstallPipReason !== undefined
1310
+ ? { dependencyInstallPipReason: declarations.dependencyInstallPipReason }
1311
+ : {}),
1312
+ ...(declarations.dependencyInstallUncoveredManifests !== undefined
1313
+ ? { dependencyInstallUncoveredManifests: declarations.dependencyInstallUncoveredManifests }
1314
+ : {}),
1315
+ ...(declarations.dependencyInstallUnknown === true ? { dependencyInstallUnknown: true } : {}),
1279
1316
  ...(ci !== undefined && !declined?.has(ciDatabaseProposalKey(ci.value)) ? { ciDatabaseProposal: ci } : {}),
1280
1317
  ...(mustOrder.length > 0 ? { mustOrderPathCandidates: mustOrder } : {}),
1281
1318
  ...(declarations.mustOrderPathOverflow !== undefined
@@ -1292,14 +1329,43 @@ allowUnstored = false) {
1292
1329
  * or declines by its key; discovery alone authorizes nothing.
1293
1330
  */
1294
1331
  export async function planDeclarationSelections(current, desired, gateDeps) {
1332
+ return (await planDeclarations(current, desired, gateDeps)).entries;
1333
+ }
1334
+ export async function planDeclarations(current, desired, gateDeps) {
1295
1335
  // A first install has no stored profile: its declarations are proposed with the
1296
1336
  // gate, so the first apply stores them before the learned check starts.
1297
1337
  const proposal = await discoverDeclarationProposal(current, desired, gateDeps, undefined, true);
1298
1338
  if (proposal === null)
1299
- return [];
1339
+ return { entries: [], dependencyInstall: null };
1340
+ const storedDeps = current.profile?.dependency_install ?? [];
1341
+ const candidates = proposal.dependencyInstallCandidates ?? [];
1342
+ const limitations = [...(proposal.dependencyInstallLimitations ?? [])];
1343
+ // BAPI-1698: the discovery notes and every uncovered root manifest, as the same
1344
+ // plain sentences the terminal review prints. Advisory: never a stop or consent.
1345
+ for (const sentence of dependencyInstallNoteSentences(proposal)) {
1346
+ if (!limitations.includes(sentence))
1347
+ limitations.push(sentence);
1348
+ }
1349
+ const merge = mergeDependencyProposal(storedDeps, candidates);
1350
+ if (!merge.withinBounds) {
1351
+ limitations.push("Adding what setup found would make too many install commands, so the stored ones stay. You can replace the whole list by correcting it.");
1352
+ }
1353
+ const facts = {
1354
+ planned: merge.withinBounds ? merge.merged : storedDeps.map((e) => ({ ...e })),
1355
+ stored: storedDeps,
1356
+ drift: merge.withinBounds ? merge.drift : "same",
1357
+ evidence: candidates.flatMap((c) => c.extraEvidence ?? []),
1358
+ limitations,
1359
+ };
1300
1360
  if (!hasUnstoredDeclarationProposal(proposal, current.profile))
1301
- return [];
1361
+ return { entries: [], dependencyInstall: facts };
1302
1362
  const { edit } = recommendedSettingsSelection(proposal, current.profile, desired.providerChecks);
1363
+ // Dependency drift is planned here, not by the safe selection: a replacing change is
1364
+ // still shown and offered, recommended decline, and only the owner can take it.
1365
+ if (facts.drift === "same")
1366
+ delete edit.dependencyInstall;
1367
+ else
1368
+ edit.dependencyInstall = facts.planned;
1303
1369
  const entries = [];
1304
1370
  const stored = current.profile;
1305
1371
  if (edit.dependencyInstall !== undefined) {
@@ -1334,7 +1400,26 @@ export async function planDeclarationSelections(current, desired, gateDeps) {
1334
1400
  summary: describeSettingsEdit({ workerDatabase: edit.workerDatabase }, stored),
1335
1401
  });
1336
1402
  }
1337
- return entries;
1403
+ return { entries, dependencyInstall: facts };
1404
+ }
1405
+ /**
1406
+ * BAPI-1677 — the one list an answer leaves in force. A correction replaces the whole
1407
+ * list, approve takes the plan, keep and decline leave what is stored (nothing, on a
1408
+ * first install). Without an answer this is the recommendation: additive drift takes
1409
+ * the plan, and a replacing change does not.
1410
+ */
1411
+ export function resolveEffectiveDependencyInstall(facts, stored, answer) {
1412
+ const copy = (list) => list.map((e) => ({ cwd: e.cwd, argv: [...e.argv], lockfiles: [...e.lockfiles] }));
1413
+ if (typeof answer === "object" && answer !== null && Array.isArray(answer.entries)) {
1414
+ return copy(answer.entries);
1415
+ }
1416
+ if (answer === "keep" || answer === "decline")
1417
+ return copy(stored);
1418
+ if (facts === null)
1419
+ return copy(stored);
1420
+ if (answer === "approve")
1421
+ return copy(facts.planned);
1422
+ return copy(facts.drift === "replacing" ? stored : facts.planned);
1338
1423
  }
1339
1424
  /** BAPI-1551 — a proposal's identity for the per-invocation declined set: the whole entry. */
1340
1425
  export function dependencyProposalKey(entry) {
@@ -1550,7 +1635,8 @@ async function inferredCiPlan(io, access, current, currentDesired, gateDeps, opt
1550
1635
  plan: { current, desired, write, removals: [], origin: "inferred", inferred },
1551
1636
  });
1552
1637
  if (current.stored_malformed) {
1553
- io.log(" The stored repository gate could not be read, so setup leaves it alone and plans nothing.");
1638
+ io.log(" The stored repository gate could not be read, so setup leaves it alone and plans nothing. " +
1639
+ "Running setup again will not change that; ask Bridge support or follow the operator runbook's `stored_malformed: true` recovery.");
1554
1640
  return plan(emptyDesiredGate(), null, {
1555
1641
  ciPlan: "none",
1556
1642
  reportedChecks: [],
@@ -1567,13 +1653,14 @@ async function inferredCiPlan(io, access, current, currentDesired, gateDeps, opt
1567
1653
  // Unknown is not absent: a stored `none` would be kept on every rerun and
1568
1654
  // hide the repository's real CI for good. Store nothing and say why.
1569
1655
  io.log(" Bridge could not read this repository's CI history, so it cannot tell whether there is CI to watch. " +
1570
- "It stores no gate now; run setup again when the history can be read.");
1656
+ "It stores no gate now. Check GitHub access, sign-in, or the app installation for this repository, then run setup again.");
1571
1657
  return plan(emptyDesiredGate(), null, {
1572
1658
  ciPlan: "none",
1573
1659
  reportedChecks: [],
1574
1660
  watchedWritable: false,
1575
1661
  watchedUnsupported: false,
1576
1662
  storedUnreadable: false,
1663
+ historyUnavailable: true,
1577
1664
  trialEligible: false,
1578
1665
  reasons: [],
1579
1666
  });
@@ -1623,6 +1710,52 @@ async function inferredCiPlan(io, access, current, currentDesired, gateDeps, opt
1623
1710
  ],
1624
1711
  });
1625
1712
  }
1713
+ /** The fix for a write whose effect could not be read back. It never recommends writing again first. */
1714
+ const UNCERTAIN_POLICY_FIX = "Read the gate with `epic-implementer doctor` first. Retry only after it shows what was stored; setup did not retry blindly.";
1715
+ /**
1716
+ * BAPI-1701 — sanitized reason and fix for an unsuccessful combined-policy write.
1717
+ * Input is the closed category and whether the outcome is uncertain, so no response
1718
+ * body, header, submitted value, or exception text can reach the output.
1719
+ * A write that could not be confirmed always leads with `doctor`, whatever its category.
1720
+ */
1721
+ export function formatSetupPolicyRefusal(category, uncertain = false) {
1722
+ if (uncertain || category === "uncertain") {
1723
+ return { reason: "the policy write could not be confirmed by reading it back", fix: UNCERTAIN_POLICY_FIX };
1724
+ }
1725
+ switch (category) {
1726
+ case "unavailable":
1727
+ return {
1728
+ reason: "unavailable: the server could not take the policy write right now",
1729
+ fix: "Nothing was written. Try setup once more shortly; if it fails again, check that the Bridge API is reachable.",
1730
+ };
1731
+ case "stale":
1732
+ return {
1733
+ reason: "stale: the policy changed after the preview",
1734
+ fix: "Nothing was written. Rerun setup to review and approve a fresh proposal.",
1735
+ };
1736
+ case "refused":
1737
+ return {
1738
+ reason: "refused: the server did not accept the policy",
1739
+ fix: "Nothing was written. Check that your key is an administrator key for this repository, then rerun setup for a fresh proposal.",
1740
+ };
1741
+ case "unsupported":
1742
+ return {
1743
+ reason: "unsupported: this server cannot take the combined policy",
1744
+ fix: "Nothing was written. Update the Bridge API, then rerun setup; a rerun on this server fails the same way.",
1745
+ };
1746
+ case "malformed":
1747
+ return {
1748
+ reason: "malformed: the server answered in a form this installer cannot verify",
1749
+ fix: "Nothing was confirmed. Read the gate with `epic-implementer doctor`; if it shows the same, ask Bridge support. A plain rerun will not repair it.",
1750
+ };
1751
+ default:
1752
+ // No validated category: the bounded fallback.
1753
+ return {
1754
+ reason: "the policy was refused or changed after the preview",
1755
+ fix: "Rerun setup for a fresh proposal; nothing in the gate was written.",
1756
+ };
1757
+ }
1758
+ }
1626
1759
  const GATE_WRITE_REFUSAL_TEXT = Object.freeze({
1627
1760
  "stale-revision": "the stored gate changed since it was read. Re-run to see the current gate.",
1628
1761
  unauthorized: "the API key was rejected, or it is not an admin key for this repository.",
@@ -1924,40 +2057,29 @@ function reportJob(io, job) {
1924
2057
  io.log(` Qualified — the local gate passed under the executor at revision ${job.revision}.`);
1925
2058
  return "qualified";
1926
2059
  }
1927
- if (job.job_status === "succeeded") {
1928
- // BAPI-1637: the phase is the server's reading of the stored result. The gate
1929
- // stays unqualified in every branch, and each says so.
1930
- if (job.phase === "dependency_preparation_failed") {
1931
- io.errorLog(` Failed — ${DEPENDENCY_INSTALL_FAILED_TEXT} The local gate stays unqualified, so unattended ` +
1932
- "auto-merge stays closed.");
1933
- io.errorLog(` ${DEPENDENCY_INSTALL_REPAIR_TEXT}`);
1934
- io.errorLog(` Qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
1935
- return "failed";
1936
- }
1937
- if (job.phase === "could_not_start") {
1938
- io.errorLog(` Failed — ${COULD_NOT_START_TEXT} The local gate stays unqualified, so unattended auto-merge ` +
1939
- "stays closed.");
1940
- io.errorLog(` ${CHANGE_TEST_COMMAND_HINT} Then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
1941
- return "failed";
1942
- }
1943
- if (job.phase === null && job.dependency_install_declared === true) {
1944
- io.errorLog(` Failed — ${PREPARATION_UNCERTAIN_TEXT} The local gate stays unqualified, so unattended ` +
1945
- "auto-merge stays closed.");
1946
- io.errorLog(` ${PREPARATION_UNCERTAIN_REPAIR_TEXT} Then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
1947
- return "failed";
1948
- }
1949
- io.errorLog(" Failed — a confirmed command did not pass under the executor. The installation itself " +
1950
- "succeeded, but the local gate stays unqualified, so unattended auto-merge stays closed.");
1951
- io.errorLog(` Fix the command, then qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
1952
- if (job.phase === "ran_and_failed" && job.dependency_install_declared === false) {
1953
- io.errorLog(` ${MISSING_INSTALL_TEXT}`);
1954
- }
1955
- return "failed";
2060
+ // BAPI-1698: one shared presentation for every finished, non-qualified job. The
2061
+ // phase is the server's reading of the stored result; per-command statuses are
2062
+ // shown by position only (this path has no command text), and only when the
2063
+ // server's validated list is available.
2064
+ const interrupted = job.job_status !== "succeeded";
2065
+ const presentation = presentTrialResult({
2066
+ phase: job.phase,
2067
+ dependencyInstallDeclared: job.dependency_install_declared,
2068
+ interrupted,
2069
+ commandResults: job.command_results,
2070
+ });
2071
+ const ordinals = (job.command_results ?? []).map((_, index) => `command ${index + 1}`);
2072
+ for (const line of renderTrialReport({
2073
+ presentation,
2074
+ consequence: interrupted
2075
+ ? `Job ${job.job_id} recorded nothing. The local gate stays unqualified.`
2076
+ : "The local gate stays unqualified, so unattended auto-merge stays closed.",
2077
+ commands: trialCommandLines({ commands: ordinals, commandResults: job.command_results, interrupted }),
2078
+ })) {
2079
+ io.errorLog(line);
1956
2080
  }
1957
- io.errorLog(` Failed — the executor could not run job ${job.job_id} (no clean default-branch checkout, ` +
1958
- "or it was interrupted). The local gate stays unqualified.");
1959
- io.errorLog(` Qualify again: ${PRINTED_QUALIFY_GATE_COMMAND}`);
1960
- return "could_not_run";
2081
+ io.errorLog(` Qualify again when ready: ${PRINTED_QUALIFY_GATE_COMMAND}`);
2082
+ return interrupted ? "could_not_run" : "failed";
1961
2083
  }
1962
2084
  /**
1963
2085
  * Enqueue the qualification for `revision` and drain it with the short-lived
@@ -2055,6 +2177,10 @@ export async function runConductorGateQualification(io, access, gateDeps, input)
2055
2177
  // before anything else happens, and the request is never repeated automatically.
2056
2178
  /** How often a running trial prints one plain progress line. */
2057
2179
  export const LEARNED_TRIAL_PROGRESS_INTERVAL_MS = 10_000;
2180
+ /** The display rows for saved commands, named the way the server names a sealed set. */
2181
+ function savedCommandDisplay(commands) {
2182
+ return (commands ?? []).map((command, index) => ({ name: index === 0 ? "tests" : `tests-${index + 1}`, command }));
2183
+ }
2058
2184
  /** The commands a profile's local members run, by digest, in order. */
2059
2185
  function localDigests(profile) {
2060
2186
  return (profile?.local_commands ?? []).map((c) => c.digest).join(",");
@@ -2073,6 +2199,9 @@ function promotionObserved(read, input) {
2073
2199
  return false;
2074
2200
  if (read.revision <= input.current.revision)
2075
2201
  return false;
2202
+ // A saved-command trial may re-qualify the same commands; the new qualified revision is the proof.
2203
+ if (input.expectedGeneration !== undefined)
2204
+ return true;
2076
2205
  return localDigests(read.profile) !== localDigests(input.current.profile);
2077
2206
  }
2078
2207
  async function readGateProfileOrNull(io, access) {
@@ -2095,6 +2224,7 @@ export async function runLearnedTestCommandTrial(io, access, gateDeps, input) {
2095
2224
  expectedRevision: input.current.revision,
2096
2225
  ...(input.candidates !== undefined ? { candidates: input.candidates } : {}),
2097
2226
  ...(input.ownerCommand !== undefined ? { ownerCommand: input.ownerCommand } : {}),
2227
+ ...(input.expectedGeneration !== undefined ? { expectedGeneration: input.expectedGeneration } : {}),
2098
2228
  }, io.postJson);
2099
2229
  switch (posted.kind) {
2100
2230
  case "not_needed":
@@ -2113,9 +2243,14 @@ export async function runLearnedTestCommandTrial(io, access, gateDeps, input) {
2113
2243
  // authoritative profile before anything else.
2114
2244
  const read = await readGateProfileOrNull(io, access);
2115
2245
  if (promotionObserved(read, input)) {
2116
- return { status: "promoted", source: requestedSource, commands: [], profile: read };
2246
+ return { status: "promoted", source: requestedSource, commands: savedCommandDisplay(input.savedCommands), profile: read };
2117
2247
  }
2118
- return { status: "uncertain", reason: "request_unclear", profile: read };
2248
+ return {
2249
+ status: "uncertain",
2250
+ reason: "request_unclear",
2251
+ profile: read,
2252
+ ...(input.savedCommands !== undefined ? { commands: savedCommandDisplay(input.savedCommands) } : {}),
2253
+ };
2119
2254
  }
2120
2255
  case "qualification_queued":
2121
2256
  break;
@@ -2125,7 +2260,7 @@ export async function runLearnedTestCommandTrial(io, access, gateDeps, input) {
2125
2260
  const read = await readGateProfileOrNull(io, access);
2126
2261
  if (promotionObserved(read, input))
2127
2262
  return { status: "promoted", source, commands, profile: read };
2128
- return { status: "uncertain", reason, profile: read };
2263
+ return { status: "uncertain", reason, profile: read, commands };
2129
2264
  };
2130
2265
  let job = await readJob(io, access, jobId);
2131
2266
  if (job === null)
@@ -2184,35 +2319,96 @@ export async function runLearnedTestCommandTrial(io, access, gateDeps, input) {
2184
2319
  const evidence = {
2185
2320
  phase: job.phase,
2186
2321
  dependencyInstallDeclared: job.dependency_install_declared,
2322
+ commandResults: job.command_results,
2323
+ };
2324
+ const promoted = async (profile) => {
2325
+ const omittedSuites = await omittedTestSuites(gateDeps, commands);
2326
+ return {
2327
+ status: "promoted",
2328
+ source,
2329
+ commands,
2330
+ profile,
2331
+ evidence,
2332
+ ...(omittedSuites.length > 0 ? { omittedSuites } : {}),
2333
+ };
2187
2334
  };
2188
2335
  if (job.qualification_state === "stale" || job.failure === "stale") {
2189
- return { status: "stale", source, profile: read, evidence };
2336
+ return { status: "stale", source, profile: read, evidence, commands };
2190
2337
  }
2191
2338
  if (job.job_status === "succeeded" && job.qualification_state === "qualified") {
2192
2339
  if (promotionObserved(read, input))
2193
- return { status: "promoted", source, commands, profile: read, evidence };
2194
- return { status: "uncertain", reason: "result_unreadable", profile: read, evidence };
2340
+ return promoted(read);
2341
+ return { status: "uncertain", reason: "result_unreadable", profile: read, evidence, commands };
2195
2342
  }
2196
2343
  if (job.job_status === "succeeded" && job.qualification_state === "unqualified") {
2197
- return { status: "unqualified", source, profile: read, evidence };
2344
+ return { status: "unqualified", source, profile: read, evidence, commands };
2198
2345
  }
2199
2346
  if (job.job_status === "succeeded") {
2200
2347
  // Finished without a verdict: only a promotion the profile shows can settle it.
2201
2348
  if (promotionObserved(read, input))
2202
- return { status: "promoted", source, commands, profile: read, evidence };
2203
- return { status: "uncertain", reason: "result_unreadable", profile: read, evidence };
2204
- }
2205
- return { status: "could_not_run", source, profile: read, evidence };
2206
- }
2207
- // BAPI-1637 — fixed wording for each completed phase. None of it names a command,
2208
- // an install step, a path, or any output: the server's phase token selects the text.
2209
- const DEPENDENCY_INSTALL_FAILED_TEXT = "The dependency install failed, so the tests did not run.";
2210
- const DEPENDENCY_INSTALL_REPAIR_TEXT = "Correct the install step (for example, a lockfile that no longer matches the manifest), then run setup again.";
2211
- const COULD_NOT_START_TEXT = "The test command could not be started (the program could not launch).";
2212
- const MISSING_INSTALL_TEXT = "No install step was declared, so the dependencies may be missing. Run setup again and accept the proposed install step.";
2213
- const PREPARATION_UNCERTAIN_TEXT = "Bridge cannot tell whether the dependency install ran before the tests, so it cannot say why the check did not pass.";
2214
- const PREPARATION_UNCERTAIN_REPAIR_TEXT = "Update the Bridge executor to the latest version, then run setup again.";
2215
- /** The instruction every successful and failed trial line ends with. */
2349
+ return promoted(read);
2350
+ return { status: "uncertain", reason: "result_unreadable", profile: read, evidence, commands };
2351
+ }
2352
+ return { status: "could_not_run", source, profile: read, evidence, commands };
2353
+ }
2354
+ /**
2355
+ * BAPI-1698 — one comparable key per test suite, so `pytest -q`, `python -m
2356
+ * pytest`, and `.venv/bin/pytest` read as the same suite. Informational only.
2357
+ */
2358
+ export function testSuiteKey(argv) {
2359
+ let tokens = argv.filter((token) => token.length > 0);
2360
+ const base = (token) => token.split("/").pop() ?? token;
2361
+ if (tokens.length === 0)
2362
+ return null;
2363
+ if (base(tokens[0]) === "npx")
2364
+ tokens = tokens.slice(1);
2365
+ else if (["uv", "poetry", "pipenv"].includes(base(tokens[0])) && tokens[1] === "run")
2366
+ tokens = tokens.slice(2);
2367
+ if (tokens.length === 0)
2368
+ return null;
2369
+ const program = base(tokens[0]);
2370
+ if (program === "pytest" || program === "py.test")
2371
+ return "pytest";
2372
+ if (/^python(?:3(?:\.\d+)?)?$/.test(program) && tokens[1] === "-m" && tokens[2] === "pytest")
2373
+ return "pytest";
2374
+ if (["npm", "yarn", "pnpm"].includes(program)) {
2375
+ const script = tokens[1] === "run" || tokens[1] === "run-script" ? tokens[2] : tokens[1];
2376
+ return script === undefined ? null : `package script ${script === "t" ? "test" : script}`;
2377
+ }
2378
+ return tokens.slice(0, 2).map(base).join(" ");
2379
+ }
2380
+ /**
2381
+ * BAPI-1698 — the test suites the repository's own files name (the high-
2382
+ * confidence local candidates) that none of the passing commands appears to run.
2383
+ * Never throws; an unreadable tree means nothing to say. Informational only.
2384
+ */
2385
+ async function omittedTestSuites(gateDeps, commands) {
2386
+ const fs = gateDeps?.discoveryFs;
2387
+ if (!fs || commands.length === 0)
2388
+ return [];
2389
+ try {
2390
+ const tried = new Set(commands.map((c) => testSuiteKey(c.command.trim().split(/\s+/))).filter((key) => key !== null));
2391
+ const omitted = [];
2392
+ for (const candidate of await discoverLocalTestCandidates(fs)) {
2393
+ if (candidate.confidence !== "high")
2394
+ continue;
2395
+ const key = testSuiteKey(candidate.argv);
2396
+ if (key === null || tried.has(key))
2397
+ continue;
2398
+ const line = sanitizeCommandText(candidate.argv.join(" "));
2399
+ if (!omitted.includes(line))
2400
+ omitted.push(line);
2401
+ }
2402
+ return omitted;
2403
+ }
2404
+ catch {
2405
+ return [];
2406
+ }
2407
+ }
2408
+ // BAPI-1698 — the wording for every completed phase lives in one place,
2409
+ // `install-bridge-conductor-trial-report.ts`. None of it names an install step,
2410
+ // a path, or any output: the server's phase token selects the text.
2411
+ /** The instruction every successful trial line ends with. */
2216
2412
  const CHANGE_TEST_COMMAND_HINT = 'Change it with --test-command "<your command>".';
2217
2413
  /**
2218
2414
  * Print one trial outcome in plain words. The validated command is named ONLY on
@@ -2223,47 +2419,72 @@ export function reportLearnedCommandTrial(io, result) {
2223
2419
  const learned = (source) => source === "owner" ? "you gave it with --test-command" : "it learned from your repository";
2224
2420
  switch (result.status) {
2225
2421
  case "promoted": {
2226
- const named = result.commands.map((c) => `\`${c.command.replace(/[\u0000-\u001F\u007F]/g, "?")}\``).join(", ");
2422
+ const named = result.commands.map((c) => `\`${sanitizeCommandText(c.command)}\``).join(", ");
2227
2423
  io.log(named.length > 0
2228
- ? ` Bridge will run ${named} before each merge. It is the command ${learned(result.source)}, and Bridge ` +
2229
- `checked it by running it once. ${CHANGE_TEST_COMMAND_HINT}`
2230
- : ` Bridge stored a test command ${learned(result.source)} and checked it by running it once. ` +
2424
+ ? ` Bridge will run ${named} before each merge. It is the command ${learned(result.source)}, and it ` +
2425
+ `${PASSED_TRIAL_RUN_TEXT}. ${CHANGE_TEST_COMMAND_HINT}`
2426
+ : ` Bridge stored a test command ${learned(result.source)}; it ${PASSED_TRIAL_RUN_TEXT}. ` +
2231
2427
  CHANGE_TEST_COMMAND_HINT);
2428
+ // BAPI-1698: informational only. The pass stands; nothing is retried.
2429
+ for (const suite of result.omittedSuites ?? []) {
2430
+ io.log(` Note: your repository also names \`${suite}\`, which the stored command does not appear to run. ` +
2431
+ `If it is part of your test suite, ${CHANGE_TEST_COMMAND_TEXT}.`);
2432
+ }
2232
2433
  return;
2233
2434
  }
2234
2435
  case "not_needed":
2235
2436
  io.log(" Bridge already has a test command for this repository, so it did not look for another.");
2236
2437
  return;
2237
2438
  case "no_command":
2238
- io.log(` Bridge found no test command to try (${NO_COMMAND_TEXT[result.reason]}). It stored none. ` +
2239
- "Give one with --test-command \"<your command>\" and Bridge will check it by running it once.");
2240
- return;
2241
- case "unqualified": {
2242
- const { phase, dependencyInstallDeclared } = result.evidence ?? { phase: null, dependencyInstallDeclared: null };
2243
- if (phase === "dependency_preparation_failed") {
2244
- io.log(` ${DEPENDENCY_INSTALL_FAILED_TEXT} Bridge stored no learned command. ${DEPENDENCY_INSTALL_REPAIR_TEXT}`);
2439
+ // BAPI-1701: a genuine absence is information. It names no command to enter.
2440
+ if (isInformationalNoCommandReason(result.reason)) {
2441
+ io.log(` ${NO_COMMAND_INFORMATION_TEXT}`);
2245
2442
  return;
2246
2443
  }
2247
- if (phase === "could_not_start") {
2248
- io.log(` ${COULD_NOT_START_TEXT} Bridge stored none. ${CHANGE_TEST_COMMAND_HINT}`);
2444
+ if (result.reason === "generation_superseded") {
2445
+ io.log(` Bridge found no test command to try (${NO_COMMAND_TEXT[result.reason]}). It stored none. ` +
2446
+ "Run setup again to review and approve a fresh proposal.");
2249
2447
  return;
2250
2448
  }
2251
- if (phase === null && dependencyInstallDeclared === true) {
2252
- io.log(` ${PREPARATION_UNCERTAIN_TEXT} Bridge stored none. ${PREPARATION_UNCERTAIN_REPAIR_TEXT}`);
2449
+ if (result.reason !== "llm_unavailable" && result.reason !== "llm_output_invalid") {
2450
+ io.log(` Bridge found a test command but could not use it (${NO_COMMAND_TEXT[result.reason]}). It stored none. ` +
2451
+ `${CANDIDATE_REJECTION_FIX[result.reason]}`);
2253
2452
  return;
2254
2453
  }
2255
- io.log(" The test command did not pass when Bridge ran it once, so Bridge stored none. " +
2256
- "Fix the failing tests, or give another command with --test-command \"<your command>\".");
2257
- if (phase === "ran_and_failed" && dependencyInstallDeclared === false)
2258
- io.log(` ${MISSING_INSTALL_TEXT}`);
2454
+ io.log(` Bridge found no test command to try (${NO_COMMAND_TEXT[result.reason]}). It stored none. ` +
2455
+ "Give one with --test-command \"<your command>\" and Bridge will check it by running it once.");
2456
+ return;
2457
+ case "unqualified": {
2458
+ // BAPI-1698: headline, consequence, the commands (with their own statuses
2459
+ // only when the server's facts line up one for one), then ONE remedy.
2460
+ const evidence = result.evidence ?? { phase: null, dependencyInstallDeclared: null, commandResults: null };
2461
+ for (const line of renderTrialReport({
2462
+ presentation: presentTrialResult({
2463
+ phase: evidence.phase,
2464
+ dependencyInstallDeclared: evidence.dependencyInstallDeclared,
2465
+ commandResults: evidence.commandResults ?? null,
2466
+ }),
2467
+ consequence: "Bridge stored no test command.",
2468
+ commands: trialCommandLines({
2469
+ commands: (result.commands ?? []).map((c) => c.command),
2470
+ commandResults: evidence.commandResults ?? null,
2471
+ }),
2472
+ })) {
2473
+ io.log(line);
2474
+ }
2259
2475
  return;
2260
2476
  }
2261
2477
  case "stale":
2262
2478
  io.log(" The gate changed while the test command was being checked, so Bridge stored none. Run setup again.");
2263
2479
  return;
2264
2480
  case "could_not_run":
2265
- io.log(" Bridge could not run the test command (no clean checkout of your default branch, or the run was " +
2266
- "interrupted), so it stored none. Run setup again.");
2481
+ for (const line of renderTrialReport({
2482
+ presentation: presentTrialResult({ phase: null, dependencyInstallDeclared: null, interrupted: true }),
2483
+ consequence: "Bridge stored no test command.",
2484
+ commands: trialCommandLines({ commands: (result.commands ?? []).map((c) => c.command), interrupted: true }),
2485
+ })) {
2486
+ io.log(line);
2487
+ }
2267
2488
  return;
2268
2489
  case "stale_revision":
2269
2490
  io.log(" The gate changed before the test command could be checked, so nothing was started. Run setup again.");
@@ -2285,6 +2506,23 @@ export function reportLearnedCommandTrial(io, result) {
2285
2506
  return;
2286
2507
  }
2287
2508
  }
2509
+ /**
2510
+ * BAPI-1701 — the only two no-command reasons that are information, not a failure:
2511
+ * the repository names no command, or has no learned testing instructions. Every other
2512
+ * reason is a failed extraction, a rejected candidate, or a superseded generation.
2513
+ */
2514
+ export function isInformationalNoCommandReason(reason) {
2515
+ return reason === "no_candidates" || reason === "no_testing_instructions";
2516
+ }
2517
+ /** BAPI-1701 — what an informational no-command result tells the owner. It says "local", never "all protection". */
2518
+ export const NO_COMMAND_INFORMATION_TEXT = "Bridge found no test command. Epics will run without a local test gate; no command is needed from you.";
2519
+ /** BAPI-1701 — the constraint to correct for each rejected candidate. Closed over the rejection reasons. */
2520
+ export const CANDIDATE_REJECTION_FIX = Object.freeze({
2521
+ working_directory_unsupported: "Give a command that runs from the repository root; a gate cannot run from a subdirectory.",
2522
+ not_plain_argv: "Replace the shell syntax with a plain program and its arguments.",
2523
+ command_not_allowed: "Give a command Bridge allows; the one it found is not on the allowed list.",
2524
+ invalid_command: "Give a valid command: a plain program and its arguments.",
2525
+ });
2288
2526
  const NO_COMMAND_TEXT = Object.freeze({
2289
2527
  no_testing_instructions: "the repository has no learned testing instructions",
2290
2528
  llm_unavailable: "the server could not read them just now",
@@ -2294,6 +2532,7 @@ const NO_COMMAND_TEXT = Object.freeze({
2294
2532
  not_plain_argv: "the command is not a plain program and arguments",
2295
2533
  command_not_allowed: "the command is not allowed",
2296
2534
  invalid_command: "the command is not valid",
2535
+ generation_superseded: "the saved commands changed after you approved them",
2297
2536
  });
2298
2537
  const UNCERTAIN_TEXT = Object.freeze({
2299
2538
  request_unclear: "the request did not answer clearly",
@@ -2579,10 +2818,12 @@ export async function resolveEpicBranchCiDecision(io, flag,
2579
2818
  * asked: only a confirmed `covers` becomes an inferred `include`. Anything else records
2580
2819
  * nothing, asks nothing, and says how to record a choice. An explicit flag still wins.
2581
2820
  */
2582
- inferFrom) {
2821
+ inferFrom,
2822
+ /** BAPI-1679 — says where a decision came from when no owner passed it as a flag. */
2823
+ decisionNote) {
2583
2824
  if (inferFrom !== undefined) {
2584
2825
  if (flag !== null) {
2585
- io.log(` Using --epic-branch-ci-decision=${flag}.`);
2826
+ io.log(` ${decisionNote ?? `Using --epic-branch-ci-decision=${flag}.`}`);
2586
2827
  return flag;
2587
2828
  }
2588
2829
  if (inferFrom === "covers") {
@@ -2625,6 +2866,47 @@ function printExemptionManualSteps(io, ownerRepo, branch) {
2625
2866
  for (const line of steps)
2626
2867
  io.log(` ${line}`);
2627
2868
  }
2869
+ /**
2870
+ * Map the exemption outcome to its setup write result. Exhaustive on purpose: a new
2871
+ * {@link ExemptionInstallOutcome} fails compilation here rather than defaulting.
2872
+ */
2873
+ export function mapExemptionOutcomeToWriteResult(outcome) {
2874
+ switch (outcome) {
2875
+ case "applied":
2876
+ return { key: "approval_exemption", status: "written", target: "github.rulesets" };
2877
+ case "declined":
2878
+ return { key: "approval_exemption", status: "declined", target: "github.rulesets" };
2879
+ case "not_needed":
2880
+ return { key: "approval_exemption", status: "unchanged", target: "github.rulesets" };
2881
+ case "unreadable":
2882
+ return {
2883
+ key: "approval_exemption",
2884
+ status: "unchanged",
2885
+ target: "github.rulesets",
2886
+ reason: "Bridge could not read the approval-rule settings. No approval-rule change was attempted.",
2887
+ };
2888
+ case "could_not_tell":
2889
+ return {
2890
+ key: "approval_exemption",
2891
+ status: "uncertain",
2892
+ target: "github.rulesets",
2893
+ reason: "the ruleset change could not be confirmed",
2894
+ fix: "Check the ruleset yourself; setup will not retry it blindly.",
2895
+ };
2896
+ case "printed_steps":
2897
+ return {
2898
+ key: "approval_exemption",
2899
+ status: "refused",
2900
+ target: "github.rulesets",
2901
+ reason: "the approval rule is not safe to change automatically",
2902
+ fix: "Follow the manual steps printed above.",
2903
+ };
2904
+ default: {
2905
+ const unreachable = outcome;
2906
+ return unreachable;
2907
+ }
2908
+ }
2909
+ }
2628
2910
  /**
2629
2911
  * The approval-rule exemption offer (requirement 6). Separate from the
2630
2912
  * include/decline choice and warning-toned. A ruleset is changed only after an
@@ -2645,7 +2927,8 @@ decision) {
2645
2927
  io.log(" Could not tell whether an approval rule applies to epic-branch PRs, so no exemption was offered " +
2646
2928
  "and nothing was changed.");
2647
2929
  printExemptionManualSteps(io, ownerRepo, branch);
2648
- return "could_not_tell";
2930
+ // Nothing was read, so nothing was attempted: not an uncertain write.
2931
+ return "unreadable";
2649
2932
  }
2650
2933
  io.log("");
2651
2934
  io.log(" Warning: an approval rule applies to epic-branch PRs.");
@@ -2691,6 +2974,13 @@ decision) {
2691
2974
  io.log(" Excluded epic/** from the approval rule. A re-read confirmed no approval rule remains and required checks are unchanged.");
2692
2975
  return "applied";
2693
2976
  }
2977
+ // Only an explicit "nothing was written" signal with a recognized pre-write reason is
2978
+ // safe to report as unchanged. A missing signal, failed or partial PUT, or throw stays uncertain.
2979
+ if (applied.attempted === false && (applied.reason === "scope_not_eligible" || applied.reason === "ruleset_changed")) {
2980
+ io.log(` Not changed: the approval rule was not changed (${applied.reason}).`);
2981
+ printExemptionManualSteps(io, ownerRepo, branch);
2982
+ return "printed_steps";
2983
+ }
2694
2984
  io.log(` Could not confirm the change (${applied.reason}). Check the ruleset yourself; nothing else will be attempted.`);
2695
2985
  printExemptionManualSteps(io, ownerRepo, branch);
2696
2986
  return "could_not_tell";
@@ -2795,7 +3085,7 @@ export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
2795
3085
  result.coverage = coverage.coverage;
2796
3086
  result.rules = rules;
2797
3087
  renderEpicBranchCiFindings(io, coverage, rules);
2798
- const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag, options.inferFromCoverage === true ? coverage.coverage : undefined);
3088
+ const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag, options.inferFromCoverage === true ? coverage.coverage : undefined, options.decisionNote);
2799
3089
  const exemptionOutcome = await offerApprovalExemption(io, seams, run, ownerRepo, branch, rules, options.exemptionDecision);
2800
3090
  const evidence = buildEpicBranchCiEvidence(coverage.coverage, rules, exemptionOutcome);
2801
3091
  result.decision = decision;