@bridge_gpt/mcp-server 0.2.73 → 0.2.74

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 (90) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +12 -0
  3. package/build/agents.generated.js +3 -3
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +3 -0
  6. package/build/command-provisioning.js +4 -3
  7. package/build/commands.generated.js +5 -5
  8. package/build/conductor/bridge-api-client.js +26 -1
  9. package/build/conductor/command-drift.js +1 -1
  10. package/build/conductor/declared-extras.js +335 -0
  11. package/build/conductor/doctor.js +2 -0
  12. package/build/conductor/driver-pass-output.js +104 -0
  13. package/build/conductor/driver-pass.js +571 -0
  14. package/build/conductor/epic-branch-ci-inspection.js +61 -16
  15. package/build/conductor/epic-implementer-cli.js +33 -0
  16. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  17. package/build/conductor/epic-server-sfcc.js +58 -80
  18. package/build/conductor/epic-server.js +57 -4
  19. package/build/conductor/gate-discovery.js +46 -6
  20. package/build/conductor/gate-settings-review.js +51 -14
  21. package/build/credential-delivery.js +280 -0
  22. package/build/credential-launch-safety.js +142 -0
  23. package/build/credential-materialization.js +91 -16
  24. package/build/credential-references-node-deps.js +29 -0
  25. package/build/credential-references.js +1394 -0
  26. package/build/credential-references.test-fixtures.js +211 -0
  27. package/build/credential-scan-conventions.js +145 -0
  28. package/build/credential-scan.js +517 -0
  29. package/build/credential-store.js +50 -0
  30. package/build/credentials-cli.js +252 -3
  31. package/build/dependency-install-declarations.js +47 -1
  32. package/build/docs.generated.js +8 -1
  33. package/build/doctor.js +41 -0
  34. package/build/drive-epic.js +297 -37
  35. package/build/epic-branch-ci-summary.js +18 -1
  36. package/build/epic-capability-statement.js +71 -3
  37. package/build/epic-ci-workflow-drift.js +52 -13
  38. package/build/epic-ci-workflow-install.js +31 -6
  39. package/build/epic-ci-workflow-v3.js +273 -0
  40. package/build/epic-ci-workflow.js +128 -7
  41. package/build/epic-implementer-bin.js +161 -70
  42. package/build/epic-launch-context.js +102 -7
  43. package/build/epic-server-record.js +30 -15
  44. package/build/executor/credential-delivery-step.js +168 -0
  45. package/build/executor/deps.js +3 -1
  46. package/build/executor/env.js +39 -1
  47. package/build/executor/epic-server-context.js +23 -7
  48. package/build/executor/guarded-fast-forward-push.js +13 -8
  49. package/build/executor/job-runner.js +159 -17
  50. package/build/executor/permissions.js +85 -3
  51. package/build/executor/prompt-spec.js +37 -3
  52. package/build/executor-launch.js +4 -2
  53. package/build/git-exclude-lock.js +187 -0
  54. package/build/index.js +398 -269
  55. package/build/install-bridge-conductor-answers.js +84 -21
  56. package/build/install-bridge-conductor-apply.js +30 -1
  57. package/build/install-bridge-conductor-assessment.js +375 -48
  58. package/build/install-bridge-conductor-compact.js +27 -2
  59. package/build/install-bridge-conductor-contracts.js +10 -1
  60. package/build/install-bridge-conductor-gate.js +124 -11
  61. package/build/install-bridge-conductor-setup.js +46 -8
  62. package/build/install-bridge-conductor.js +625 -113
  63. package/build/install-bridge.js +88 -11
  64. package/build/install-doctor.js +38 -8
  65. package/build/install-sfcc-detection.js +120 -0
  66. package/build/install-sfcc-setup.js +185 -0
  67. package/build/mcp-grant-candidates.js +108 -96
  68. package/build/mcp-invoke.js +168 -4
  69. package/build/mcp-provisioning.js +21 -4
  70. package/build/mcp-server-invocation.js +13 -0
  71. package/build/merge-workflow-install.js +9 -1
  72. package/build/pipelines.generated.js +2 -1
  73. package/build/plane/status.js +8 -2
  74. package/build/printed-remedy-commands.js +5 -0
  75. package/build/project-root.js +40 -0
  76. package/build/readme.generated.js +1 -1
  77. package/build/repository-state-paths.js +5 -2
  78. package/build/repository-toolchains.js +6 -3
  79. package/build/setup-epic.js +116 -15
  80. package/build/sfcc/credentials.js +3 -2
  81. package/build/sfcc/hostname.js +98 -2
  82. package/build/sfcc/tool-wrapper.js +6 -95
  83. package/build/start-tickets.js +193 -29
  84. package/build/test-support/executor-source-files.js +200 -0
  85. package/build/testing-config-client.js +25 -2
  86. package/build/third-party-mcp-targets.js +35 -4
  87. package/build/version.generated.js +3 -3
  88. package/build/with-credentials.js +208 -0
  89. package/build/worktree-credential-delivery.js +340 -0
  90. package/package.json +1 -1
@@ -5,6 +5,12 @@
5
5
  * fields to show and write plain reasons from data already in the document. They
6
6
  * read no files, resolve no credentials, decide no policy, and never recompute
7
7
  * the digest.
8
+ *
9
+ * Schema note. These compact fields were added without changing any earlier field:
10
+ * `verdict`, `ready`, and `merge_test_protection` (BAPI-1678), and
11
+ * `missing_learned_fields` (BAPI-1680). The compact proposal also gained
12
+ * `merge_test_protection`, `disclosure`, and `gate_effect_lines` (BAPI-1678).
13
+ * `INSTALL_ASSESSMENT_SCHEMA_VERSION` stays 2, because every change is additive.
8
14
  */
9
15
  function compactChoice(choice) {
10
16
  return {
@@ -20,6 +26,8 @@ function compactChoice(choice) {
20
26
  ...(choice.earlier_answer !== undefined ? { earlier_answer: choice.earlier_answer } : {}),
21
27
  ...(choice.excluded !== undefined ? { excluded: choice.excluded } : {}),
22
28
  ...(choice.invalid_existing !== undefined ? { invalid_existing: choice.invalid_existing } : {}),
29
+ ...(choice.dependency_install !== undefined ? { dependency_install: choice.dependency_install } : {}),
30
+ ...(choice.credential_references !== undefined ? { credential_references: choice.credential_references } : {}),
23
31
  };
24
32
  }
25
33
  function compactItems(document) {
@@ -49,6 +57,9 @@ export function buildCompactAssessment(document) {
49
57
  dryRun: document.dryRun,
50
58
  ...(document.namedOutcome !== undefined ? { namedOutcome: document.namedOutcome } : {}),
51
59
  ...(document.advisoryVerdict !== undefined ? { advisoryVerdict: document.advisoryVerdict } : {}),
60
+ ...(document.missing_learned_fields !== undefined
61
+ ? { missing_learned_fields: document.missing_learned_fields }
62
+ : {}),
52
63
  items,
53
64
  choices: document.choices.map(compactChoice),
54
65
  repository_facts: document.repository_facts,
@@ -66,10 +77,11 @@ function selectedValue(decision) {
66
77
  case "reference":
67
78
  return "reference";
68
79
  case "epic_server_sfcc":
69
- return "sfcc_shared_active";
80
+ return decision.value.mode;
70
81
  case "profile":
71
82
  return "save";
72
83
  case "command":
84
+ case "dependency_install_entries":
73
85
  return null;
74
86
  }
75
87
  }
@@ -127,11 +139,20 @@ export function buildCompactProposal(document) {
127
139
  reason: decisionReason(entry, byKey.get(entry.key)),
128
140
  consequential: entry.consequential,
129
141
  }));
142
+ const presentation = document.proposal_presentation;
130
143
  return {
131
144
  ...(document.proposal_digest !== undefined ? { proposal_digest: document.proposal_digest } : {}),
132
145
  view: "compact",
133
146
  ...(document.proposal !== undefined
134
- ? { proposal: { decisions, actions: document.proposal.actions.map(compactAction) } }
147
+ ? {
148
+ proposal: {
149
+ decisions,
150
+ actions: document.proposal.actions.map(compactAction),
151
+ ...(presentation?.merge_test_protection !== undefined ? { merge_test_protection: presentation.merge_test_protection } : {}),
152
+ ...(presentation?.disclosure !== undefined ? { disclosure: presentation.disclosure } : {}),
153
+ ...(presentation !== undefined ? { gate_effect_lines: presentation.gate_effect_lines } : {}),
154
+ },
155
+ }
135
156
  : {}),
136
157
  ...(document.refusal !== undefined ? { refusal: document.refusal } : {}),
137
158
  ...(document.proposal === undefined && document.refusal === undefined ? { stopped: compactStop(document) } : {}),
@@ -151,11 +172,15 @@ function compactWrite(result) {
151
172
  }
152
173
  export function buildCompactApply(document) {
153
174
  const apply = document.apply;
175
+ const presentation = document.apply_presentation;
154
176
  return {
155
177
  view: "compact",
156
178
  complete: apply?.complete ?? false,
157
179
  writes: (apply?.results ?? []).map(compactWrite),
158
180
  ...(document.refusal !== undefined ? { refusal: document.refusal } : {}),
159
181
  ...(apply === undefined && document.refusal === undefined ? { stopped: compactStop(document) } : {}),
182
+ ...(presentation !== undefined ? { verdict: presentation.verdict } : {}),
183
+ ...(presentation?.ready !== undefined ? { ready: presentation.ready } : {}),
184
+ ...(presentation?.merge_test_protection !== undefined ? { merge_test_protection: presentation.merge_test_protection } : {}),
160
185
  };
161
186
  }
@@ -14,7 +14,16 @@
14
14
  */
15
15
  /** The schema version `--json` emits. Version 1 fields are all kept. */
16
16
  export const INSTALL_ASSESSMENT_SCHEMA_VERSION = 2;
17
- /** The digest structure's own version, so a later change cannot collide with this one. */
17
+ /**
18
+ * The digest structure's own version, so a later change cannot collide with this one.
19
+ *
20
+ * Schema note (BAPI-1677): `dependency_install` also accepts
21
+ * `{"entries":[{"cwd","argv","lockfiles"}]}`. The list replaces every declared install,
22
+ * in the submitted order. `{"entries":[]}` is a write, not a keep or a decline: workers
23
+ * and the test trial then run no declared install, and managed CI uses its normal
24
+ * toolchain install. This stays version 1 because the shape adds a decision kind that
25
+ * appears only when used, so no canonical input of an existing answer changes.
26
+ */
18
27
  export const INSTALL_PROPOSAL_DIGEST_VERSION = 1;
19
28
  /** The fixed setup-record path, relative to `docs_dir` (from `ping`). */
20
29
  export const SETUP_RECORD_RELATIVE_PATH = "bridge-setup/epic-implementer-setup-record.md";
@@ -51,7 +51,7 @@ import { ConductorBridgeApiError, GATE_PROFILE_CAPABILITY_TOKEN, enqueueConducto
51
51
  import { describeGateConsequence } from "./conductor/readiness-sections.js";
52
52
  import { applyApprovalExemption, assessApprovalExemptionScope, buildEpicBranchCiEvidence, exemptionManualSteps, inspectEpicBranchWorkflowCoverage, readEpicBranchRulesViaGh, } from "./conductor/epic-branch-ci-inspection.js";
53
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 { 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
55
  import { canonicalMustOrderPaths, sameMustOrderPaths, } from "./dependency-install-declarations.js";
56
56
  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
57
  export function emptyConductorGateFlags() {
@@ -986,7 +986,19 @@ export async function runGateDiscovery(io, access, gateDeps) {
986
986
  const fs = gateDeps?.discoveryFs;
987
987
  if (!fs)
988
988
  return emptyProposal();
989
- return discoverGate({ fs, lookupHistory: historyLookupFor(io, access) });
989
+ const learned = await learnedInstructionsFor(gateDeps);
990
+ return discoverGate({ fs, lookupHistory: historyLookupFor(io, access), ...(learned !== undefined ? { learned } : {}) });
991
+ }
992
+ /** The learned snapshot, `undefined` when no reader was given. A failing reader is a limitation, never a throw. */
993
+ async function learnedInstructionsFor(gateDeps) {
994
+ if (gateDeps?.learnedInstructions === undefined)
995
+ return undefined;
996
+ try {
997
+ return await gateDeps.learnedInstructions();
998
+ }
999
+ catch {
1000
+ return null;
1001
+ }
990
1002
  }
991
1003
  /** A fresh explicit empty proposal: nothing discovered, nothing proposed. */
992
1004
  function emptyProposal() {
@@ -1259,13 +1271,19 @@ allowUnstored = false) {
1259
1271
  return null;
1260
1272
  let declarations;
1261
1273
  try {
1262
- declarations = await discoverDeclarations({ fs, providerChecks: desired.providerChecks });
1274
+ const learned = await learnedInstructionsFor(gateDeps);
1275
+ declarations = await discoverDeclarations({ fs, providerChecks: desired.providerChecks, ...(learned !== undefined ? { learned } : {}) });
1263
1276
  }
1264
1277
  catch {
1265
1278
  return null;
1266
1279
  }
1280
+ // BAPI-1677: when extras could not be worked out, what is stored stands. An unknown
1281
+ // read never proposes a change to a stored list, so it cannot strip a stored extra.
1282
+ const unknownAgainstStored = declarations.dependencyInstallUnknown === true && (current.profile?.dependency_install?.length ?? 0) > 0;
1267
1283
  // Never re-offer what the owner already ignored or declined in this invocation.
1268
- const candidates = (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
1284
+ const candidates = unknownAgainstStored
1285
+ ? []
1286
+ : (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
1269
1287
  const ci = declarations.ciDatabaseProposal;
1270
1288
  const mustOrder = (declarations.mustOrderPathCandidates ?? []).filter((p) => !declined?.has(mustOrderProposalKey(p)));
1271
1289
  const workerDatabase = declarations.workerDatabaseProposal;
@@ -1276,6 +1294,8 @@ allowUnstored = false) {
1276
1294
  : {}),
1277
1295
  ...(candidates.length > 0 ? { dependencyInstallCandidates: candidates } : {}),
1278
1296
  ...(declarations.dependencyInstallNotes ? { dependencyInstallNotes: declarations.dependencyInstallNotes } : {}),
1297
+ ...(declarations.dependencyInstallLimitations ? { dependencyInstallLimitations: declarations.dependencyInstallLimitations } : {}),
1298
+ ...(declarations.dependencyInstallUnknown === true ? { dependencyInstallUnknown: true } : {}),
1279
1299
  ...(ci !== undefined && !declined?.has(ciDatabaseProposalKey(ci.value)) ? { ciDatabaseProposal: ci } : {}),
1280
1300
  ...(mustOrder.length > 0 ? { mustOrderPathCandidates: mustOrder } : {}),
1281
1301
  ...(declarations.mustOrderPathOverflow !== undefined
@@ -1292,14 +1312,37 @@ allowUnstored = false) {
1292
1312
  * or declines by its key; discovery alone authorizes nothing.
1293
1313
  */
1294
1314
  export async function planDeclarationSelections(current, desired, gateDeps) {
1315
+ return (await planDeclarations(current, desired, gateDeps)).entries;
1316
+ }
1317
+ export async function planDeclarations(current, desired, gateDeps) {
1295
1318
  // A first install has no stored profile: its declarations are proposed with the
1296
1319
  // gate, so the first apply stores them before the learned check starts.
1297
1320
  const proposal = await discoverDeclarationProposal(current, desired, gateDeps, undefined, true);
1298
1321
  if (proposal === null)
1299
- return [];
1322
+ return { entries: [], dependencyInstall: null };
1323
+ const storedDeps = current.profile?.dependency_install ?? [];
1324
+ const candidates = proposal.dependencyInstallCandidates ?? [];
1325
+ const limitations = [...(proposal.dependencyInstallLimitations ?? [])];
1326
+ const merge = mergeDependencyProposal(storedDeps, candidates);
1327
+ if (!merge.withinBounds) {
1328
+ 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.");
1329
+ }
1330
+ const facts = {
1331
+ planned: merge.withinBounds ? merge.merged : storedDeps.map((e) => ({ ...e })),
1332
+ stored: storedDeps,
1333
+ drift: merge.withinBounds ? merge.drift : "same",
1334
+ evidence: candidates.flatMap((c) => c.extraEvidence ?? []),
1335
+ limitations,
1336
+ };
1300
1337
  if (!hasUnstoredDeclarationProposal(proposal, current.profile))
1301
- return [];
1338
+ return { entries: [], dependencyInstall: facts };
1302
1339
  const { edit } = recommendedSettingsSelection(proposal, current.profile, desired.providerChecks);
1340
+ // Dependency drift is planned here, not by the safe selection: a replacing change is
1341
+ // still shown and offered, recommended decline, and only the owner can take it.
1342
+ if (facts.drift === "same")
1343
+ delete edit.dependencyInstall;
1344
+ else
1345
+ edit.dependencyInstall = facts.planned;
1303
1346
  const entries = [];
1304
1347
  const stored = current.profile;
1305
1348
  if (edit.dependencyInstall !== undefined) {
@@ -1334,7 +1377,26 @@ export async function planDeclarationSelections(current, desired, gateDeps) {
1334
1377
  summary: describeSettingsEdit({ workerDatabase: edit.workerDatabase }, stored),
1335
1378
  });
1336
1379
  }
1337
- return entries;
1380
+ return { entries, dependencyInstall: facts };
1381
+ }
1382
+ /**
1383
+ * BAPI-1677 — the one list an answer leaves in force. A correction replaces the whole
1384
+ * list, approve takes the plan, keep and decline leave what is stored (nothing, on a
1385
+ * first install). Without an answer this is the recommendation: additive drift takes
1386
+ * the plan, and a replacing change does not.
1387
+ */
1388
+ export function resolveEffectiveDependencyInstall(facts, stored, answer) {
1389
+ const copy = (list) => list.map((e) => ({ cwd: e.cwd, argv: [...e.argv], lockfiles: [...e.lockfiles] }));
1390
+ if (typeof answer === "object" && answer !== null && Array.isArray(answer.entries)) {
1391
+ return copy(answer.entries);
1392
+ }
1393
+ if (answer === "keep" || answer === "decline")
1394
+ return copy(stored);
1395
+ if (facts === null)
1396
+ return copy(stored);
1397
+ if (answer === "approve")
1398
+ return copy(facts.planned);
1399
+ return copy(facts.drift === "replacing" ? stored : facts.planned);
1338
1400
  }
1339
1401
  /** BAPI-1551 — a proposal's identity for the per-invocation declined set: the whole entry. */
1340
1402
  export function dependencyProposalKey(entry) {
@@ -2579,10 +2641,12 @@ export async function resolveEpicBranchCiDecision(io, flag,
2579
2641
  * asked: only a confirmed `covers` becomes an inferred `include`. Anything else records
2580
2642
  * nothing, asks nothing, and says how to record a choice. An explicit flag still wins.
2581
2643
  */
2582
- inferFrom) {
2644
+ inferFrom,
2645
+ /** BAPI-1679 — says where a decision came from when no owner passed it as a flag. */
2646
+ decisionNote) {
2583
2647
  if (inferFrom !== undefined) {
2584
2648
  if (flag !== null) {
2585
- io.log(` Using --epic-branch-ci-decision=${flag}.`);
2649
+ io.log(` ${decisionNote ?? `Using --epic-branch-ci-decision=${flag}.`}`);
2586
2650
  return flag;
2587
2651
  }
2588
2652
  if (inferFrom === "covers") {
@@ -2625,6 +2689,47 @@ function printExemptionManualSteps(io, ownerRepo, branch) {
2625
2689
  for (const line of steps)
2626
2690
  io.log(` ${line}`);
2627
2691
  }
2692
+ /**
2693
+ * Map the exemption outcome to its setup write result. Exhaustive on purpose: a new
2694
+ * {@link ExemptionInstallOutcome} fails compilation here rather than defaulting.
2695
+ */
2696
+ export function mapExemptionOutcomeToWriteResult(outcome) {
2697
+ switch (outcome) {
2698
+ case "applied":
2699
+ return { key: "approval_exemption", status: "written", target: "github.rulesets" };
2700
+ case "declined":
2701
+ return { key: "approval_exemption", status: "declined", target: "github.rulesets" };
2702
+ case "not_needed":
2703
+ return { key: "approval_exemption", status: "unchanged", target: "github.rulesets" };
2704
+ case "unreadable":
2705
+ return {
2706
+ key: "approval_exemption",
2707
+ status: "unchanged",
2708
+ target: "github.rulesets",
2709
+ reason: "Bridge could not read the approval-rule settings. No approval-rule change was attempted.",
2710
+ };
2711
+ case "could_not_tell":
2712
+ return {
2713
+ key: "approval_exemption",
2714
+ status: "uncertain",
2715
+ target: "github.rulesets",
2716
+ reason: "the ruleset change could not be confirmed",
2717
+ fix: "Check the ruleset yourself; setup will not retry it blindly.",
2718
+ };
2719
+ case "printed_steps":
2720
+ return {
2721
+ key: "approval_exemption",
2722
+ status: "refused",
2723
+ target: "github.rulesets",
2724
+ reason: "the approval rule is not safe to change automatically",
2725
+ fix: "Follow the manual steps printed above.",
2726
+ };
2727
+ default: {
2728
+ const unreachable = outcome;
2729
+ return unreachable;
2730
+ }
2731
+ }
2732
+ }
2628
2733
  /**
2629
2734
  * The approval-rule exemption offer (requirement 6). Separate from the
2630
2735
  * include/decline choice and warning-toned. A ruleset is changed only after an
@@ -2645,7 +2750,8 @@ decision) {
2645
2750
  io.log(" Could not tell whether an approval rule applies to epic-branch PRs, so no exemption was offered " +
2646
2751
  "and nothing was changed.");
2647
2752
  printExemptionManualSteps(io, ownerRepo, branch);
2648
- return "could_not_tell";
2753
+ // Nothing was read, so nothing was attempted: not an uncertain write.
2754
+ return "unreadable";
2649
2755
  }
2650
2756
  io.log("");
2651
2757
  io.log(" Warning: an approval rule applies to epic-branch PRs.");
@@ -2691,6 +2797,13 @@ decision) {
2691
2797
  io.log(" Excluded epic/** from the approval rule. A re-read confirmed no approval rule remains and required checks are unchanged.");
2692
2798
  return "applied";
2693
2799
  }
2800
+ // Only an explicit "nothing was written" signal with a recognized pre-write reason is
2801
+ // safe to report as unchanged. A missing signal, failed or partial PUT, or throw stays uncertain.
2802
+ if (applied.attempted === false && (applied.reason === "scope_not_eligible" || applied.reason === "ruleset_changed")) {
2803
+ io.log(` Not changed: the approval rule was not changed (${applied.reason}).`);
2804
+ printExemptionManualSteps(io, ownerRepo, branch);
2805
+ return "printed_steps";
2806
+ }
2694
2807
  io.log(` Could not confirm the change (${applied.reason}). Check the ruleset yourself; nothing else will be attempted.`);
2695
2808
  printExemptionManualSteps(io, ownerRepo, branch);
2696
2809
  return "could_not_tell";
@@ -2795,7 +2908,7 @@ export async function runEpicBranchCiInspection(io, access, gateDeps, options) {
2795
2908
  result.coverage = coverage.coverage;
2796
2909
  result.rules = rules;
2797
2910
  renderEpicBranchCiFindings(io, coverage, rules);
2798
- const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag, options.inferFromCoverage === true ? coverage.coverage : undefined);
2911
+ const decision = await resolveEpicBranchCiDecision(io, options.decisionFlag, options.inferFromCoverage === true ? coverage.coverage : undefined, options.decisionNote);
2799
2912
  const exemptionOutcome = await offerApprovalExemption(io, seams, run, ownerRepo, branch, rules, options.exemptionDecision);
2800
2913
  const evidence = buildEpicBranchCiEvidence(coverage.coverage, rules, exemptionOutcome);
2801
2914
  result.decision = decision;
@@ -21,8 +21,8 @@ import { formatReadinessAssessment } from './conductor/readiness-prerequisites.j
21
21
  * row for the same fact. An unmet blocking item is counted once.
22
22
  */
23
23
  import { READINESS_PREREQUISITE_BY_ID, READINESS_PREREQUISITE_CATALOG, } from "./readiness-prerequisites.generated.js";
24
- import { READINESS_PREREQUISITE_FIXES, assessmentRemedyQuestion, formatProfilePolicyRemedy, resolveReadinessRemedy, } from "./printed-remedy-commands.js";
25
- import { COMMAND_DRIFT_UNASSESSABLE_REMEDIATION } from "./conductor/command-drift.js";
24
+ import { READINESS_PREREQUISITE_FIXES, assessmentRemedyQuestion, formatProfilePolicyRemedy, resolveReadinessRemedy, PRE_SETUP_READINESS_REMEDY, } from "./printed-remedy-commands.js";
25
+ import { COMMAND_DRIFT_DIVERGENT_REMEDIATION, COMMAND_DRIFT_UNASSESSABLE_REMEDIATION } from "./conductor/command-drift.js";
26
26
  import { shellQuote } from "./epic-launch-profile.js";
27
27
  import { decodeCanonicalProvenance } from "./conductor/bridge-api-client.js";
28
28
  import { githubSignInRemedy } from "./github-sign-in.js";
@@ -129,11 +129,19 @@ const ACTIVE_INDEX_STATES = ["in_progress", "queued_by_setup", "recovery_pending
129
129
  // ---------------------------------------------------------------------------
130
130
  // Projection
131
131
  // ---------------------------------------------------------------------------
132
- function fromServerPrerequisite(p, isProduction) {
132
+ /**
133
+ * BAPI-1678: an item that only reflects that supervisor setup has not been saved yet.
134
+ * Strictly `false`: a true, missing, or unreadable setup presence keeps today's remedy.
135
+ */
136
+ function needsSetupFirst(setupPresent, id, scope) {
137
+ return setupPresent === false && (scope === "self_host" || id === "server.service-availability");
138
+ }
139
+ export function fromServerPrerequisite(p, isProduction, setupPresent) {
133
140
  if (p.check_status === "met" || p.check_status === "not_applicable") {
134
141
  return { id: p.id, label: p.label, state: "met", blocking: p.impact === "blocking", remedy: null };
135
142
  }
136
143
  const blocking = p.impact === "blocking";
144
+ const preSetup = needsSetupFirst(setupPresent, p.id, p.scope);
137
145
  // On production, a Bridge-hosted (self_host) fact is never the customer's to
138
146
  // fix, so it reads as "could not verify — retry", never as server repair advice.
139
147
  if (p.scope === "self_host" && isProduction) {
@@ -142,7 +150,7 @@ function fromServerPrerequisite(p, isProduction) {
142
150
  label: p.label,
143
151
  state: "unknown",
144
152
  blocking,
145
- remedy: READINESS_PREREQUISITE_FIXES.retry,
153
+ remedy: preSetup ? PRE_SETUP_READINESS_REMEDY : READINESS_PREREQUISITE_FIXES.retry,
146
154
  };
147
155
  }
148
156
  return {
@@ -150,7 +158,7 @@ function fromServerPrerequisite(p, isProduction) {
150
158
  label: p.label,
151
159
  state: p.check_status === "unknown" ? "unknown" : "needs_action",
152
160
  blocking,
153
- remedy: p.fix.length > 0 ? p.fix : READINESS_PREREQUISITE_FIXES.retry,
161
+ remedy: preSetup ? PRE_SETUP_READINESS_REMEDY : p.fix.length > 0 ? p.fix : READINESS_PREREQUISITE_FIXES.retry,
154
162
  };
155
163
  }
156
164
  function upsert(items, item) {
@@ -185,7 +193,7 @@ export function projectSetupItems(evidence) {
185
193
  }
186
194
  else if (readiness.prerequisites !== undefined) {
187
195
  for (const p of readiness.prerequisites) {
188
- const item = fromServerPrerequisite(p, isProduction);
196
+ const item = fromServerPrerequisite(p, isProduction, readiness.supervisor?.setup_present);
189
197
  if (item !== null)
190
198
  items.push(item);
191
199
  }
@@ -333,7 +341,7 @@ export function projectCommandDriftItem(evidence) {
333
341
  return item("met", null);
334
342
  if (drift.kind === "unassessable")
335
343
  return item("unknown", COMMAND_DRIFT_UNASSESSABLE_REMEDIATION);
336
- return item("needs_action", `Run ${assetRefreshCommandFor(evidence)}, review the changed files, then commit them, or mark the commands customized in the gate profile.`);
344
+ return item("needs_action", COMMAND_DRIFT_DIVERGENT_REMEDIATION);
337
345
  }
338
346
  function projectWorkflowItem(evidence, server) {
339
347
  const id = SETUP_ITEM_IDS.workflows;
@@ -741,6 +749,32 @@ export function setupVerdictLine(items) {
741
749
  const left = unmetBlockingItems(items).length;
742
750
  return left === 0 ? "Ready for your first epic" : `Not ready: ${left} step${left === 1 ? "" : "s"} left`;
743
751
  }
752
+ /**
753
+ * BAPI-1678: whether a run can start, from the post-apply readiness evidence only.
754
+ * `undefined` means the evidence gave no answer. It follows the same precedence as
755
+ * `setupVerdictLine`, which stays as it is for human output. Write results are not an
756
+ * input, so a successful write cannot make this true and a failed one cannot make it false.
757
+ */
758
+ export function deriveCompactReadiness(input) {
759
+ if (!input.readinessObserved)
760
+ return undefined;
761
+ const { items } = input;
762
+ const assessment = items.find(i => i.assessment)?.assessment;
763
+ if (assessment) {
764
+ const effective = items.find(i => i.effectiveAssessment)?.effectiveAssessment ?? assessment;
765
+ const extras = additionalRequiredItems(items, assessment);
766
+ if (extras.some(i => i.state === 'needs_action'))
767
+ return false;
768
+ const verdict = deriveAdvisoryVerdict(effective);
769
+ if (verdict === 'Not ready')
770
+ return false;
771
+ return verdict === 'Ready' && extras.length === 0 ? true : undefined;
772
+ }
773
+ const unmet = unmetBlockingItems(items);
774
+ if (unmet.some(i => i.state === 'needs_action'))
775
+ return false;
776
+ return unmet.length === 0 ? true : undefined;
777
+ }
744
778
  /** Render the assessment: a status list, then one fix per unmet blocking item. */
745
779
  export function renderSetupAssessment(items, heading, phase = 'final') {
746
780
  const assessment = items.find(i => i.assessment)?.assessment;
@@ -752,7 +786,7 @@ export function renderSetupAssessment(items, heading, phase = 'final') {
752
786
  const projected = new Map(items.filter(i => i.remedy !== null).map(i => [i.id, i.remedy]));
753
787
  const remedyTextForRecord = (r) => {
754
788
  const text = projected.get(`${r.scope}:${r.id}`);
755
- return text !== undefined && (r.reason === 'revision_unbound' || text.includes(AGENT_ANSWERS_MARKER)) ? text : undefined;
789
+ return text !== undefined && (r.reason === 'revision_unbound' || text.includes(AGENT_ANSWERS_MARKER) || text === PRE_SETUP_READINESS_REMEDY) ? text : undefined;
756
790
  };
757
791
  const lines = formatReadinessAssessment(phase === 'final' && effective ? effective : assessment, { initial: phase === 'initial', remedyTextForRecord });
758
792
  if (phase === 'final') {
@@ -856,6 +890,10 @@ function projectAssessmentSetupItems(evidence) {
856
890
  && r.basis !== 'policy_unreadable' && evidence.plannedGateWrite === true) {
857
891
  return GATE_STORED_ON_APPROVAL_REMEDY;
858
892
  }
893
+ // BAPI-1678: before setup is saved, this item only means setup has not run. Chosen before the
894
+ // retry handling below; the record's state and blocking effect do not change.
895
+ if (needsSetupFirst(evidence.readiness?.supervisor?.setup_present, r.id, READINESS_PREREQUISITE_BY_ID.get(r.id)?.scope))
896
+ return PRE_SETUP_READINESS_REMEDY;
859
897
  if (r.blocking_effect === 'unresolved') {
860
898
  // An unbound revision is not cured by a retry: name the action that supplies it.
861
899
  // Any scope other than these two keeps the generic handling below.