@bridge_gpt/mcp-server 0.2.70 → 0.2.72

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 (134) hide show
  1. package/README.md +55 -17
  2. package/build/agent-launchers/claude-executor-adapter.js +29 -4
  3. package/build/agent-notes.js +171 -95
  4. package/build/agent-registry.js +5 -5
  5. package/build/agents.generated.js +12 -2
  6. package/build/bounded-wait.js +9 -1
  7. package/build/bridge-permissions.js +17 -5
  8. package/build/bridge-worktree-inspection.js +237 -0
  9. package/build/check-evidence.js +6 -0
  10. package/build/claude-review-workflow.js +1 -1
  11. package/build/cli-help.js +6 -0
  12. package/build/codex-auto-recovery.js +126 -0
  13. package/build/codex-skill-adapter.js +2 -0
  14. package/build/commands.generated.js +5 -5
  15. package/build/conductor/bridge-api-client.js +776 -23
  16. package/build/conductor/command-drift-production.js +7 -2
  17. package/build/conductor/doctor.js +93 -13
  18. package/build/conductor/epic-implementer-cli.js +55 -2
  19. package/build/conductor/gate-discovery.js +659 -19
  20. package/build/conductor/gate-settings-review.js +751 -0
  21. package/build/conductor/git-hooks-uninstall.js +112 -0
  22. package/build/conductor/git-hooks.js +81 -15
  23. package/build/conductor/guided-repair.js +10 -1
  24. package/build/conductor/install-doctor.js +2 -4
  25. package/build/conductor/launch-need-probes.js +16 -11
  26. package/build/conductor/launch-plan.js +185 -0
  27. package/build/conductor/local-merge.js +12 -1
  28. package/build/conductor/merge-execution-contract.js +1 -1
  29. package/build/conductor/merged-child-check.js +2 -1
  30. package/build/conductor/precheck-timings.js +14 -0
  31. package/build/conductor/prerequisite-inputs.js +379 -0
  32. package/build/conductor/preview-observations.js +10 -0
  33. package/build/conductor/readiness-assessment.js +78 -0
  34. package/build/conductor/readiness-cli.js +10 -0
  35. package/build/conductor/readiness-prerequisites.js +53 -0
  36. package/build/conductor/readiness-sections.js +25 -9
  37. package/build/conductor/readiness.js +20 -2
  38. package/build/conductor/recovery-cli.js +281 -14
  39. package/build/conductor/recovery-operations.js +78 -5
  40. package/build/conductor/repair-contract.js +33 -0
  41. package/build/conductor/tools.js +34 -3
  42. package/build/conductor/wait-run-attention.js +115 -0
  43. package/build/conductor/wait-run-cli.js +96 -3
  44. package/build/conductor/worker-database-doctor-inspector.js +1 -0
  45. package/build/credential-store.js +25 -20
  46. package/build/dependency-install-declarations.js +157 -0
  47. package/build/docs.generated.js +4 -4
  48. package/build/doctor.js +37 -5
  49. package/build/drive-epic-help.js +2 -2
  50. package/build/drive-epic.js +240 -56
  51. package/build/epic-ci-workflow-drift.js +71 -23
  52. package/build/epic-ci-workflow-install.js +83 -26
  53. package/build/epic-ci-workflow-v1.js +132 -0
  54. package/build/epic-ci-workflow.js +174 -13
  55. package/build/epic-implementer-bin.js +119 -44
  56. package/build/epic-launch-profile.js +1 -1
  57. package/build/executor/ci-rerun-job.js +220 -14
  58. package/build/executor/cli.js +2 -0
  59. package/build/executor/completion-contract.js +16 -0
  60. package/build/executor/credentials.js +1 -1
  61. package/build/executor/delivery-observations.js +113 -0
  62. package/build/executor/delivery-outcome.js +30 -0
  63. package/build/executor/dependency-refresh-runner.js +132 -0
  64. package/build/executor/dependency-refresh.js +530 -0
  65. package/build/executor/deps.js +4 -0
  66. package/build/executor/env.js +274 -5
  67. package/build/executor/gate-qualification-job.js +20 -5
  68. package/build/executor/harness-coverage.js +19 -0
  69. package/build/executor/http-client.js +35 -1
  70. package/build/executor/index.js +2 -1
  71. package/build/executor/install-preflight.js +1 -1
  72. package/build/executor/job-runner.js +355 -36
  73. package/build/executor/likely-tests.js +100 -98
  74. package/build/executor/preflight.js +5 -0
  75. package/build/executor/process-containment.js +18 -0
  76. package/build/executor/prompt-spec.js +84 -15
  77. package/build/executor/reconcile-overlap-job.js +6 -1
  78. package/build/executor/required-verification.js +28 -0
  79. package/build/executor/required-work-diagnostics.js +30 -0
  80. package/build/executor/required-work-ledger.js +19 -1
  81. package/build/executor/results.js +42 -0
  82. package/build/executor/service-discovery.js +42 -0
  83. package/build/executor/service-lifecycle.js +109 -2
  84. package/build/executor/service-uninstall.js +205 -0
  85. package/build/executor/service-unit.js +5 -3
  86. package/build/executor/test-clock.js +3 -0
  87. package/build/executor/verification-hints.js +179 -0
  88. package/build/executor/worker-command.js +188 -1
  89. package/build/executor/worker-database.js +299 -40
  90. package/build/executor/worker-finalization.js +65 -10
  91. package/build/executor/worker-guard-hook.js +10 -2
  92. package/build/executor/worker-resources.js +12 -1
  93. package/build/executor/worker-verification-guidance.js +64 -0
  94. package/build/executor/worktree-inspection.js +42 -0
  95. package/build/github-sign-in.js +1 -1
  96. package/build/index.js +767 -310
  97. package/build/init.js +3 -3
  98. package/build/install-bridge-conductor-gate.js +416 -41
  99. package/build/install-bridge-conductor-setup.js +135 -32
  100. package/build/install-bridge-conductor.js +769 -353
  101. package/build/install-bridge.js +419 -124
  102. package/build/install-maintenance.js +104 -0
  103. package/build/install-reexec.js +1 -1
  104. package/build/local-cleanup.js +59 -0
  105. package/build/mcp-install-state.js +68 -2
  106. package/build/merge-workflow-install.js +22 -2
  107. package/build/package-script-semantics.js +10 -0
  108. package/build/pipeline-utils.js +1 -1
  109. package/build/pipelines.generated.js +6 -6
  110. package/build/plan-execution-ledger.js +171 -10
  111. package/build/plane/plane-freshness.js +12 -9
  112. package/build/plane/preflight.js +19 -0
  113. package/build/plane/terminal-run-cleanup.js +5 -1
  114. package/build/plane/terminal-run-status.js +4 -0
  115. package/build/printed-remedy-commands.js +31 -4
  116. package/build/readiness-check.js +1 -78
  117. package/build/readiness-prerequisites.generated.js +199 -0
  118. package/build/readme.generated.js +1 -1
  119. package/build/repository-toolchains.js +623 -0
  120. package/build/setup-change-policy.js +32 -0
  121. package/build/setup-epic.js +26 -9
  122. package/build/setup-question.js +62 -0
  123. package/build/start-tickets.js +4 -0
  124. package/build/test-command-detection.js +61 -80
  125. package/build/test-support/notes-fs.js +40 -0
  126. package/build/ticket-delivery-artifacts.js +7 -0
  127. package/build/ticket-delivery-enrollment.js +80 -4
  128. package/build/ticket-delivery-run-scope.js +128 -0
  129. package/build/version.generated.js +3 -3
  130. package/build/worker-guard-hook-bin.js +2 -2
  131. package/build/worktrees.js +105 -0
  132. package/docs/EPIC-IMPLEMENTER.md +43 -0
  133. package/docs/epic-implementer/getting-started.md +95 -14
  134. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
+ import { askSetupQuestion, setupConsentQuestion } from "./setup-question.js";
1
2
  /**
2
- * `install-bridge conductor` — the owner-confirmed repository gate (BAPI-1391).
3
+ * `install epic-implementer` — the owner-confirmed repository gate (BAPI-1391).
3
4
  *
4
5
  * Before this module, the conductor installer refused to run without at least
5
6
  * one `--required-check`, so a repository whose CI used other names, ran outside
@@ -41,7 +42,8 @@
41
42
  */
42
43
  import { ConductorBridgeApiError, GATE_PROFILE_CAPABILITY_TOKEN, enqueueConductorGateQualification, fetchConductorGateCheckHistory, fetchConductorGateProfile, fetchConductorGateQualificationJob, probeConductorGateProfileCapability, putConductorGateProfile, putEpicBranchCiDecision, } from "./conductor/bridge-api-client.js";
43
44
  import { applyApprovalExemption, assessApprovalExemptionScope, buildEpicBranchCiEvidence, exemptionManualSteps, inspectEpicBranchWorkflowCoverage, readEpicBranchRulesViaGh, } from "./conductor/epic-branch-ci-inspection.js";
44
- import { describeEvidence, discoverGate, LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./conductor/gate-discovery.js";
45
+ import { describeEvidence, discoverDeclarations, discoverGate, LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./conductor/gate-discovery.js";
46
+ import { dependencyInstallEqual, describeSettingsEdit, hasSettingsToReview, hasUnstoredDeclarationProposal, hintEqual, renderDeclarationsOnly, renderSettingsReview, reviewDeclarations, reviewDiscoveredSettings, settingsMatchStored, storedCiDatabase, terminalSafe, workerEnvEqual, } from "./conductor/gate-settings-review.js";
45
47
  import { PRINTED_EXECUTOR_INSTALL_SERVICE_COMMAND, PRINTED_EXECUTOR_ID_INSTRUCTION, PRINTED_QUALIFY_GATE_COMMAND, PRINTED_REPO_WIDE_EXECUTOR_COMMAND, } from "./printed-remedy-commands.js";
46
48
  export function emptyConductorGateFlags() {
47
49
  return {
@@ -199,10 +201,8 @@ export function createQualificationExecutorRunner(seams) {
199
201
  }
200
202
  const YES = new Set(["y", "yes"]);
201
203
  async function ask(io, promptText) {
202
- if (!io.promptLine)
203
- return false;
204
- const answer = await io.promptLine(promptText);
205
- return YES.has((answer ?? "").trim().toLowerCase());
204
+ const decision = await askSetupQuestion(setupConsentQuestion(promptText), { read: io.promptLine, write: io.log });
205
+ return decision.status === "accept";
206
206
  }
207
207
  /** The fixed update-required refusal (property 2). */
208
208
  export const GATE_UPDATE_REQUIRED_MESSAGE = `Bridge API update required: this server does not advertise ${GATE_PROFILE_CAPABILITY_TOKEN}, so ` +
@@ -261,7 +261,7 @@ function sameCommand(a, b) {
261
261
  a.argv.every((w, i) => w === b.argv[i]));
262
262
  }
263
263
  /** Whether `desired` is exactly what `stored` already holds (no write needed). */
264
- export function gateMatchesStored(desired, stored) {
264
+ export function gateMatchesStored(desired, stored, storedProfile) {
265
265
  const sameGuard = desired.migrationGuard === null
266
266
  ? stored.migrationGuard === null
267
267
  : stored.migrationGuard !== null &&
@@ -277,7 +277,18 @@ export function gateMatchesStored(desired, stored) {
277
277
  desired.localCommands.length === stored.localCommands.length &&
278
278
  desired.localCommands.every((c, i) => sameCommand(c, stored.localCommands[i])) &&
279
279
  sameGuard &&
280
- sameCustomized);
280
+ sameCustomized &&
281
+ // BAPI-1520: omitted settings and per-check hints resolve against what is stored.
282
+ settingsMatchStored(settingsOf(desired), storedProfile ?? null));
283
+ }
284
+ /** The settings edit a desired gate carries; empty when it carries none. */
285
+ function settingsOf(desired) {
286
+ return {
287
+ ...(desired.workerEnv !== undefined ? { workerEnv: desired.workerEnv } : {}),
288
+ ...(desired.reproduce !== undefined ? { reproduce: desired.reproduce } : {}),
289
+ ...(desired.dependencyInstall !== undefined ? { dependencyInstall: desired.dependencyInstall } : {}),
290
+ ...(desired.ciDatabase !== undefined ? { ciDatabase: desired.ciDatabase } : {}),
291
+ };
281
292
  }
282
293
  /** Human descriptions of every member `next` removes from `prior`. */
283
294
  export function gateRemovals(prior, next) {
@@ -299,14 +310,33 @@ export function gateRemovals(prior, next) {
299
310
  return removed;
300
311
  }
301
312
  /** The PUT body for a confirm of `desired` against the revision the server reported. */
302
- export function confirmRequestFor(desired, expectedRevision) {
313
+ export function confirmRequestFor(desired, expectedRevision, stored) {
303
314
  const guard = desired.migrationGuard === null ? null : { kind: desired.migrationGuard.kind, id: desired.migrationGuard.name };
315
+ // BAPI-1520: a setting is sent only when it effectively changes what is stored.
316
+ // An unchanged hint is omitted (the server keeps it); `reproduce: null` is sent
317
+ // only to remove a hint that is actually stored.
318
+ const providerChecks = desired.providerChecks.map((name) => {
319
+ const edit = desired.reproduce?.get(name);
320
+ if (edit === undefined)
321
+ return { name };
322
+ const current = stored?.reproduction_hints?.get(name) ?? null;
323
+ if (edit === null)
324
+ return current !== null ? { name, reproduce: null } : { name };
325
+ if (current !== null && hintEqual(edit, current))
326
+ return { name };
327
+ return { name, reproduce: { argv: [...edit.argv], timeout_seconds: edit.timeout_seconds } };
328
+ });
329
+ const sendWorkerEnv = desired.workerEnv !== undefined && !workerEnvEqual(desired.workerEnv, stored?.worker_env);
330
+ // BAPI-1551: each declaration is sent only when it differs from what is stored;
331
+ // a clear sends `[]`, and a reset of the CI-database value sends `null`.
332
+ const sendDependencyInstall = desired.dependencyInstall !== undefined && !dependencyInstallEqual(desired.dependencyInstall, stored?.dependency_install);
333
+ const sendCiDatabase = desired.ciDatabase !== undefined && desired.ciDatabase !== storedCiDatabase(stored);
304
334
  return {
305
335
  action: "confirm",
306
336
  confirm: true,
307
337
  expected_revision: expectedRevision,
308
338
  kind: desired.kind,
309
- provider_checks: desired.providerChecks.map((name) => ({ name })),
339
+ provider_checks: providerChecks,
310
340
  local_commands: desired.localCommands.map((c) => ({
311
341
  name: c.name,
312
342
  argv: [...c.argv],
@@ -314,6 +344,21 @@ export function confirmRequestFor(desired, expectedRevision) {
314
344
  })),
315
345
  migration_guard: guard,
316
346
  ...(desired.customizedCommands !== undefined ? { customized_commands: desired.customizedCommands } : {}),
347
+ ...(sendWorkerEnv && desired.workerEnv !== undefined
348
+ ? { worker_env: desired.workerEnv.map((e) => ({ ...e })) }
349
+ : {}),
350
+ ...(sendDependencyInstall && desired.dependencyInstall !== undefined
351
+ ? {
352
+ dependency_install: desired.dependencyInstall.map((e) => ({
353
+ cwd: e.cwd,
354
+ argv: [...e.argv],
355
+ lockfiles: [...e.lockfiles],
356
+ })),
357
+ }
358
+ : {}),
359
+ ...(sendCiDatabase && desired.ciDatabase !== undefined
360
+ ? { ci_database: desired.ciDatabase === "unknown" ? null : desired.ciDatabase }
361
+ : {}),
317
362
  };
318
363
  }
319
364
  function resolveLocalCommand(flag, proposal) {
@@ -470,6 +515,8 @@ export function renderGateProposal(io, proposal) {
470
515
  numbered.push({ kind: "provider", name: candidate.name });
471
516
  io.log(` [${numbered.length}] provider check "${candidate.name}" — reported on this repository ` +
472
517
  `(confidence ${candidate.confidence})`);
518
+ if (candidate.checkEvidence)
519
+ io.log(` purpose: ${candidate.checkEvidence.purpose} (${candidate.checkEvidence.purposeProvenance}); source: ${candidate.checkEvidence.discoverySource}; outcome: ${candidate.checkEvidence.executionOutcome}`);
473
520
  for (const e of candidate.evidence)
474
521
  io.log(` evidence: ${describeEvidence(e)}`);
475
522
  }
@@ -548,6 +595,13 @@ export function renderGateComparison(io, current, desired, removals) {
548
595
  io.log(" Proposed gate:");
549
596
  for (const line of describeGate(desired))
550
597
  io.log(line);
598
+ // BAPI-1520: names only here; values were shown once, in the interactive review.
599
+ const settingsLines = describeSettingsEdit(settingsOf(desired), current.profile);
600
+ if (settingsLines.length > 0) {
601
+ io.log(" CI settings to store with this gate (names only; hint-only settings never gate a merge):");
602
+ for (const line of settingsLines)
603
+ io.log(line);
604
+ }
551
605
  if (removals.length > 0) {
552
606
  io.log(` ⚠ This REMOVES ${removals.length} member(s) from the confirmed gate: ${removals.join("; ")}.`);
553
607
  io.log(" Unattended runs then merge with fewer checks.");
@@ -576,19 +630,28 @@ function historyLookupFor(io, access) {
576
630
  /** Run discovery, or an explicit empty proposal when no discovery seam exists. */
577
631
  export async function runGateDiscovery(io, access, gateDeps) {
578
632
  const fs = gateDeps?.discoveryFs;
579
- if (!fs) {
580
- return {
581
- providerCandidates: [],
582
- unreportedProviderNames: [],
583
- localCandidates: [],
584
- evidence: [],
585
- history: { status: "not_queried" },
586
- proposed: { kind: "none", providerChecks: [], localCommandIds: [] },
587
- noCandidates: true,
588
- };
589
- }
633
+ if (!fs)
634
+ return emptyProposal();
590
635
  return discoverGate({ fs, lookupHistory: historyLookupFor(io, access) });
591
636
  }
637
+ /** A fresh explicit empty proposal: nothing discovered, nothing proposed. */
638
+ function emptyProposal() {
639
+ return {
640
+ providerCandidates: [],
641
+ unreportedProviderNames: [],
642
+ localCandidates: [],
643
+ evidence: [],
644
+ history: { status: "not_queried" },
645
+ proposed: { kind: "none", providerChecks: [], localCommandIds: [] },
646
+ noCandidates: true,
647
+ workerEnvCandidates: [],
648
+ workerEnvConflicts: [],
649
+ workerEnvSkipped: [],
650
+ workerEnvOverflow: 0,
651
+ reproductionHints: [],
652
+ reproductionHintsSkipped: [],
653
+ };
654
+ }
592
655
  const MAX_SELECTION_ATTEMPTS = 3;
593
656
  const MAX_TYPED_CHECKS = 32;
594
657
  /**
@@ -668,6 +731,133 @@ async function editProposalInteractively(io, proposal, numbered, gateDeps) {
668
731
  }
669
732
  return desired;
670
733
  }
734
+ /**
735
+ * BAPI-1520 — the interactive review of discovered CI settings, folded into a
736
+ * desired gate. Runs only in a terminal and never under `--dry-run`, so a run
737
+ * without explicit, interactive confirmation sends neither new setting. Nothing
738
+ * is shown or asked when there is nothing stored and nothing proposed.
739
+ *
740
+ * Returns the desired gate carrying the owner's decisions (settings the owner
741
+ * left alone stay `undefined`, so they are omitted from the write) and whether
742
+ * any setting changed.
743
+ */
744
+ async function reviewSettingsInto(io, proposal, current, desired) {
745
+ const prompt = io.promptLine;
746
+ if (!prompt || !hasSettingsToReview(proposal, current.profile, desired.providerChecks)) {
747
+ return { desired, changed: false };
748
+ }
749
+ const edit = await reviewDiscoveredSettings({ log: io.log, promptLine: prompt }, proposal, current.profile, desired.providerChecks);
750
+ const merged = {
751
+ ...desired,
752
+ ...(edit.workerEnv !== undefined ? { workerEnv: edit.workerEnv } : {}),
753
+ ...(edit.reproduce !== undefined ? { reproduce: edit.reproduce } : {}),
754
+ ...(edit.dependencyInstall !== undefined ? { dependencyInstall: edit.dependencyInstall } : {}),
755
+ ...(edit.ciDatabase !== undefined ? { ciDatabase: edit.ciDatabase } : {}),
756
+ };
757
+ return { desired: merged, changed: !settingsMatchStored(edit, current.profile) };
758
+ }
759
+ /**
760
+ * BAPI-1551 — keep the confirmed gate, and offer any unstored declaration
761
+ * proposal as an optional gate change. Declining it (or having none) keeps the
762
+ * no-write plan exactly as before; it never becomes a blocking item.
763
+ */
764
+ async function keptGateWithDeclarations(io, current, currentDesired, gateDeps, options) {
765
+ const unchanged = {
766
+ kind: "plan",
767
+ plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" },
768
+ };
769
+ const offered = await offerDeclarationChanges(io, current, currentDesired, gateDeps, options);
770
+ if (!offered.changed)
771
+ return unchanged;
772
+ renderGateComparison(io, current, offered.desired, []);
773
+ if (!options.planningOnly && !(await ask(io, "Store these worker setup declarations with the gate? [y/N]: "))) {
774
+ io.log(" Declarations not stored; the stored gate and its settings are unchanged.");
775
+ for (const key of offered.offeredKeys)
776
+ options.declinedDeclarations?.add(key);
777
+ return unchanged;
778
+ }
779
+ return {
780
+ kind: "plan",
781
+ plan: {
782
+ current,
783
+ desired: offered.desired,
784
+ write: confirmRequestFor(offered.desired, current.revision, current.profile),
785
+ removals: [],
786
+ origin: "stored",
787
+ },
788
+ };
789
+ }
790
+ /**
791
+ * BAPI-1551 — with a confirmed gate kept as it is, offer the dependency-refresh
792
+ * and CI-database proposals the stored profile does not hold yet. Advisory: the
793
+ * offer only ever adds a gate change the owner accepts. It runs only in a
794
+ * terminal, never under `--dry-run`, never without a discovery seam, and asks
795
+ * nothing when there is no unstored proposal. Declining keeps the stored values.
796
+ */
797
+ async function offerDeclarationChanges(io, current, desired, gateDeps, options) {
798
+ const none = { desired, changed: false, offeredKeys: [] };
799
+ const prompt = io.promptLine;
800
+ const fs = gateDeps?.discoveryFs;
801
+ if (!prompt || !fs || options.dryRun || current.profile === null)
802
+ return none;
803
+ let declarations;
804
+ try {
805
+ declarations = await discoverDeclarations({ fs, providerChecks: desired.providerChecks });
806
+ }
807
+ catch {
808
+ return none;
809
+ }
810
+ // Never re-offer what the owner already ignored or declined in this invocation.
811
+ const declined = options.declinedDeclarations;
812
+ const candidates = (declarations.dependencyInstallCandidates ?? []).filter((c) => !declined?.has(dependencyProposalKey(c)));
813
+ const ci = declarations.ciDatabaseProposal;
814
+ const proposal = {
815
+ ...emptyProposal(),
816
+ ...(candidates.length > 0 ? { dependencyInstallCandidates: candidates } : {}),
817
+ ...(declarations.dependencyInstallNotes ? { dependencyInstallNotes: declarations.dependencyInstallNotes } : {}),
818
+ ...(ci !== undefined && !declined?.has(ciDatabaseProposalKey(ci.value)) ? { ciDatabaseProposal: ci } : {}),
819
+ };
820
+ if (!hasUnstoredDeclarationProposal(proposal, current.profile))
821
+ return none;
822
+ const offeredKeys = [
823
+ ...(proposal.dependencyInstallCandidates ?? [])
824
+ .filter((c) => !(current.profile?.dependency_install ?? []).some((e) => dependencyInstallEqual([e], [c])))
825
+ .map(dependencyProposalKey),
826
+ ...(proposal.ciDatabaseProposal !== undefined &&
827
+ proposal.ciDatabaseProposal.value !== storedCiDatabase(current.profile)
828
+ ? [ciDatabaseProposalKey(proposal.ciDatabaseProposal.value)]
829
+ : []),
830
+ ];
831
+ io.log("");
832
+ io.log(" Discovery proposes worker setup declarations this gate does not store yet (optional):");
833
+ renderDeclarationsOnly(io, proposal, current.profile, true);
834
+ const edit = await reviewDeclarations({ log: io.log, promptLine: prompt }, proposal, current.profile);
835
+ const merged = {
836
+ ...desired,
837
+ ...(edit.dependencyInstall !== undefined ? { dependencyInstall: edit.dependencyInstall } : {}),
838
+ ...(edit.ciDatabase !== undefined ? { ciDatabase: edit.ciDatabase } : {}),
839
+ };
840
+ // A proposal the owner did not take is remembered as declined for this invocation.
841
+ const resultingList = edit.dependencyInstall ?? current.profile.dependency_install ?? [];
842
+ const resultingCi = edit.ciDatabase ?? storedCiDatabase(current.profile);
843
+ for (const candidate of proposal.dependencyInstallCandidates ?? []) {
844
+ if (!resultingList.some((e) => dependencyInstallEqual([e], [candidate]))) {
845
+ declined?.add(dependencyProposalKey(candidate));
846
+ }
847
+ }
848
+ if (proposal.ciDatabaseProposal !== undefined && proposal.ciDatabaseProposal.value !== resultingCi) {
849
+ declined?.add(ciDatabaseProposalKey(proposal.ciDatabaseProposal.value));
850
+ }
851
+ return { desired: merged, changed: !settingsMatchStored(edit, current.profile), offeredKeys };
852
+ }
853
+ /** BAPI-1551 — a proposal's identity for the per-invocation declined set: the whole entry. */
854
+ export function dependencyProposalKey(entry) {
855
+ return `dependency_install:${JSON.stringify([entry.cwd, entry.argv, entry.lockfiles])}`;
856
+ }
857
+ /** BAPI-1551 — the declined-set key of a CI-database proposal. */
858
+ export function ciDatabaseProposalKey(value) {
859
+ return `ci_database:${value}`;
860
+ }
671
861
  /**
672
862
  * Decide the repository gate for this run (BEFORE any write).
673
863
  *
@@ -705,16 +895,34 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
705
895
  io.errorLog("Nothing was written.");
706
896
  return { kind: "exit", code: 1 };
707
897
  }
708
- const desired = built.desired;
898
+ let desired = built.desired;
899
+ // BAPI-1520: in a terminal, review the discovered CI settings before the
900
+ // comparison. A non-interactive run, and a dry run, send neither new setting.
901
+ let settingsChanged = false;
902
+ if (io.promptLine && !options.dryRun) {
903
+ const reviewProposal = proposal ?? (await runGateDiscovery(io, access, gateDeps));
904
+ const reviewed = await reviewSettingsInto(io, reviewProposal, current, desired);
905
+ desired = reviewed.desired;
906
+ settingsChanged = reviewed.changed;
907
+ }
709
908
  const removals = gateRemovals(currentDesired, desired);
710
- const unchanged = current.source === "stored" && currentDesired !== null && gateMatchesStored(desired, currentDesired);
909
+ const unchanged = current.source === "stored" &&
910
+ currentDesired !== null &&
911
+ gateMatchesStored(desired, currentDesired, current.profile);
711
912
  io.log(" Gate flags supplied: they are your explicit gate input.");
712
913
  renderGateComparison(io, current, desired, removals);
713
914
  if (unchanged) {
714
915
  io.log(" The confirmed gate already matches — no gate write is needed.");
715
916
  return { kind: "plan", plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" } };
716
917
  }
717
- if (removals.length > 0 && !flags.confirmGate && !options.dryRun) {
918
+ if (settingsChanged && !options.dryRun && !options.planningOnly) {
919
+ const ok = await ask(io, "Store these CI settings with the gate? [y/N]: ");
920
+ if (!ok) {
921
+ io.errorLog("CI settings not confirmed — nothing was written, and the stored gate is unchanged.");
922
+ return { kind: "exit", code: 1 };
923
+ }
924
+ }
925
+ if (removals.length > 0 && !flags.confirmGate && !options.dryRun && !options.planningOnly) {
718
926
  const ok = await ask(io, "Confirm this gate, including the removals above? [y/N]: ");
719
927
  if (!ok) {
720
928
  io.errorLog("Gate change not confirmed — nothing was written, and the stored gate is unchanged.");
@@ -724,7 +932,13 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
724
932
  }
725
933
  return {
726
934
  kind: "plan",
727
- plan: { current, desired, write: confirmRequestFor(desired, current.revision), removals, origin: "flags" },
935
+ plan: {
936
+ current,
937
+ desired,
938
+ write: confirmRequestFor(desired, current.revision, current.profile),
939
+ removals,
940
+ origin: "flags",
941
+ },
728
942
  };
729
943
  }
730
944
  if (options.ensureProviderCheck !== undefined) {
@@ -736,11 +950,15 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
736
950
  : ` Using the confirmed gate (revision ${current.revision}).`);
737
951
  for (const line of describeGate(currentDesired))
738
952
  io.log(line);
739
- return { kind: "plan", plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" } };
953
+ return keptGateWithDeclarations(io, current, currentDesired, gateDeps, options);
740
954
  }
741
955
  const proposal = await runGateDiscovery(io, access, gateDeps);
742
956
  const numbered = renderGateProposal(io, proposal);
743
957
  if (options.dryRun) {
958
+ // BAPI-1520: a read-only preview. Values are shown only in a terminal.
959
+ if (hasSettingsToReview(proposal, current.profile, proposal.proposed.providerChecks)) {
960
+ renderSettingsReview(io, proposal, current.profile, proposal.proposed.providerChecks, io.promptLine !== undefined);
961
+ }
744
962
  io.log(" Dry run — a real run asks you to confirm or edit this proposal. Nothing was stored.");
745
963
  return { kind: "unconfirmed-preview", current };
746
964
  }
@@ -751,20 +969,28 @@ export async function resolveConductorGate(io, access, flags, gateDeps, options)
751
969
  "or --gate-none). Nothing was written.");
752
970
  return { kind: "exit", code: 1 };
753
971
  }
754
- const desired = await editProposalInteractively(io, proposal, numbered, gateDeps);
755
- if (desired === null) {
972
+ const chosen = await editProposalInteractively(io, proposal, numbered, gateDeps);
973
+ if (chosen === null) {
756
974
  io.errorLog("No gate was chosen. Nothing was written.");
757
975
  return { kind: "exit", code: 1 };
758
976
  }
977
+ // BAPI-1520: worker variables and reproduction hints, decided one at a time.
978
+ const { desired } = await reviewSettingsInto(io, proposal, current, chosen);
759
979
  renderGateComparison(io, current, desired, []);
760
- const confirmed = await ask(io, "Store this repository gate? [y/N]: ");
980
+ const confirmed = options.planningOnly || await ask(io, "Store this repository gate? [y/N]: ");
761
981
  if (!confirmed) {
762
982
  io.errorLog("Gate not confirmed — nothing was written. A confirmed gate is required to continue.");
763
983
  return { kind: "exit", code: 1 };
764
984
  }
765
985
  return {
766
986
  kind: "plan",
767
- plan: { current, desired, write: confirmRequestFor(desired, current.revision), removals: [], origin: "interactive" },
987
+ plan: {
988
+ current,
989
+ desired,
990
+ write: confirmRequestFor(desired, current.revision, current.profile),
991
+ removals: [],
992
+ origin: "interactive",
993
+ },
768
994
  };
769
995
  }
770
996
  /** BAPI-1461 — `desired` with `check` added as a provider member (kept when present). */
@@ -800,21 +1026,35 @@ async function ensureProviderCheckPlan(io, access, current, currentDesired, chec
800
1026
  : ` Using the confirmed gate (revision ${current.revision}).`);
801
1027
  for (const line of describeGate(currentDesired))
802
1028
  io.log(line);
803
- return { kind: "plan", plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" } };
1029
+ return keptGateWithDeclarations(io, current, currentDesired, gateDeps, options);
804
1030
  }
805
- const desired = withProviderCheck(currentDesired, check);
1031
+ // BAPI-1551: unstored declaration proposals ride along with this gate change.
1032
+ const offered = await offerDeclarationChanges(io, current, withProviderCheck(currentDesired, check), gateDeps, options);
1033
+ const desired = offered.desired;
806
1034
  renderGateComparison(io, current, desired, []);
807
1035
  if (currentDesired.kind === "local" || currentDesired.kind === "none") {
808
1036
  if (options.dryRun) {
809
1037
  io.log(" Dry run — a real run asks before adding the CI check to this gate.");
810
1038
  }
811
- else {
1039
+ else if (!options.planningOnly) {
812
1040
  const ok = await ask(io, "Add the CI workflow check to this repository gate? [y/N]: ");
813
1041
  if (!ok) {
814
1042
  io.log(" Kept the stored gate unchanged; the CI check is listed as a step left.");
1043
+ // Declining the check never discards declarations the owner accepted.
1044
+ const kept = {
1045
+ ...currentDesired,
1046
+ ...(desired.dependencyInstall !== undefined ? { dependencyInstall: desired.dependencyInstall } : {}),
1047
+ ...(desired.ciDatabase !== undefined ? { ciDatabase: desired.ciDatabase } : {}),
1048
+ };
815
1049
  return {
816
1050
  kind: "plan",
817
- plan: { current, desired: currentDesired, write: null, removals: [], origin: "stored" },
1051
+ plan: {
1052
+ current,
1053
+ desired: kept,
1054
+ write: offered.changed ? confirmRequestFor(kept, current.revision, current.profile) : null,
1055
+ removals: [],
1056
+ origin: "stored",
1057
+ },
818
1058
  ensureDeclined: true,
819
1059
  };
820
1060
  }
@@ -822,16 +1062,30 @@ async function ensureProviderCheckPlan(io, access, current, currentDesired, chec
822
1062
  }
823
1063
  return {
824
1064
  kind: "plan",
825
- plan: { current, desired, write: confirmRequestFor(desired, current.revision), removals: [], origin: "stored" },
1065
+ plan: {
1066
+ current,
1067
+ desired,
1068
+ write: confirmRequestFor(desired, current.revision, current.profile),
1069
+ removals: [],
1070
+ origin: "stored",
1071
+ },
826
1072
  };
827
1073
  }
828
- const proposal = await runGateDiscovery(io, access, gateDeps);
1074
+ const discovered = await runGateDiscovery(io, access, gateDeps);
1075
+ const proposal = { ...discovered, proposed: { ...discovered.proposed,
1076
+ providerChecks: [...new Set([...discovered.proposed.providerChecks, check])] } };
829
1077
  renderGateProposal(io, proposal);
830
- const desired = withProviderCheck(desiredFromProposalSelection(proposal, proposal.proposed.providerChecks, proposal.proposed.localCommandIds), check);
1078
+ const desired = desiredFromProposalSelection(proposal, proposal.proposed.providerChecks, proposal.proposed.localCommandIds);
831
1079
  renderGateComparison(io, current, desired, []);
832
1080
  return {
833
1081
  kind: "plan",
834
- plan: { current, desired, write: confirmRequestFor(desired, current.revision), removals: [], origin: "interactive" },
1082
+ plan: {
1083
+ current,
1084
+ desired,
1085
+ write: confirmRequestFor(desired, current.revision, current.profile),
1086
+ removals: [],
1087
+ origin: "interactive",
1088
+ },
835
1089
  };
836
1090
  }
837
1091
  const GATE_WRITE_REFUSAL_TEXT = Object.freeze({
@@ -845,7 +1099,37 @@ const GATE_WRITE_REFUSAL_TEXT = Object.freeze({
845
1099
  timeout: "the Bridge API did not answer in time.",
846
1100
  server: "the Bridge API reported an internal error.",
847
1101
  rejected: "the Bridge API rejected the request.",
1102
+ "extension-unsupported": "this server is older than the installer and cannot store worker variables, reproduction hints, " +
1103
+ "dependency refresh declarations, or CI database behavior.",
848
1104
  });
1105
+ /** Plain-language text for each closed `worker_env` refusal reason (BAPI-1520). */
1106
+ const WORKER_ENV_REASON_TEXT = Object.freeze({
1107
+ worker_env_reserved_name: "is reserved by Bridge and cannot be a worker variable. Remove it, then confirm again; " +
1108
+ "nothing was removed or retried automatically.",
1109
+ worker_env_secret_name: "looks secret. Drop it, or confirm its committed-literal assertion individually, then confirm again.",
1110
+ worker_env_duplicate: "appears more than once. Keep one entry, then confirm again.",
1111
+ });
1112
+ /** The request without the BAPI-1520 and BAPI-1551 extension fields, and what it dropped. */
1113
+ function withoutExtensions(request) {
1114
+ const workerEnvNames = (request.worker_env ?? []).map((e) => e.name);
1115
+ const hintChecks = (request.provider_checks ?? [])
1116
+ .filter((c) => c.reproduce !== undefined)
1117
+ .map((c) => c.name);
1118
+ const { worker_env: _dropped, dependency_install: _install, ci_database: _database, ...rest } = request;
1119
+ void _dropped;
1120
+ void _install;
1121
+ void _database;
1122
+ return {
1123
+ ...(request.dependency_install !== undefined ? { dependencyInstall: request.dependency_install } : {}),
1124
+ ...(request.ci_database !== undefined ? { ciDatabase: request.ci_database } : {}),
1125
+ request: {
1126
+ ...rest,
1127
+ ...(request.provider_checks ? { provider_checks: request.provider_checks.map((c) => ({ name: c.name })) } : {}),
1128
+ },
1129
+ workerEnvNames,
1130
+ hintChecks,
1131
+ };
1132
+ }
849
1133
  /**
850
1134
  * Send the plan's PUT. On a refusal, print the reason and the PRIOR gate as
851
1135
  * what is in force (property 4) and return null.
@@ -858,13 +1142,51 @@ export async function storeConductorGate(io, access, plan) {
858
1142
  if (plan.current.source === "stored" &&
859
1143
  plan.current.confirmed &&
860
1144
  plan.current.profile !== null &&
861
- gateMatchesStored(plan.desired, desiredFromStored(plan.current.profile))) {
1145
+ gateMatchesStored(plan.desired, desiredFromStored(plan.current.profile), plan.current.profile)) {
862
1146
  return plan.current;
863
1147
  }
864
- const outcome = await putConductorGateProfile(access, plan.write, io.postJson);
1148
+ let outcome = await putConductorGateProfile(access, plan.write, io.postJson);
1149
+ // BAPI-1520: an older server rejects exactly the extension fields it does not
1150
+ // know. Retry ONCE without them, keep everything else the owner approved, and
1151
+ // report what was not stored by name.
1152
+ let unsaved = null;
1153
+ if (!outcome.ok && outcome.refusal === "extension-unsupported") {
1154
+ const stripped = withoutExtensions(plan.write);
1155
+ unsaved = {
1156
+ workerEnvNames: stripped.workerEnvNames,
1157
+ hintChecks: stripped.hintChecks,
1158
+ ...(stripped.dependencyInstall !== undefined ? { dependencyInstall: stripped.dependencyInstall } : {}),
1159
+ ...(stripped.ciDatabase !== undefined ? { ciDatabase: stripped.ciDatabase } : {}),
1160
+ };
1161
+ const storedDesired = plan.current.profile !== null ? desiredFromStored(plan.current.profile) : null;
1162
+ const membersUnchanged = plan.current.source === "stored" &&
1163
+ storedDesired !== null &&
1164
+ gateMatchesStored({ ...plan.desired, workerEnv: undefined, reproduce: undefined, dependencyInstall: undefined, ciDatabase: undefined }, storedDesired);
1165
+ if (membersUnchanged) {
1166
+ reportUnsavedSettings(io, unsaved);
1167
+ io.log(" The gate itself already matched, so nothing was written.");
1168
+ return plan.current;
1169
+ }
1170
+ outcome = await putConductorGateProfile(access, stripped.request, io.postJson);
1171
+ }
865
1172
  if (!outcome.ok) {
866
1173
  io.errorLog(`Repository gate not stored (${outcome.refusal}): ${GATE_WRITE_REFUSAL_TEXT[outcome.refusal]}`);
1174
+ const reason = outcome.detail?.reason;
1175
+ if (outcome.refusal === "validation" && reason !== undefined) {
1176
+ const name = outcome.detail?.name !== undefined ? ` ${terminalSafe(outcome.detail.name)}` : "";
1177
+ io.errorLog(` Worker variable${name} ${WORKER_ENV_REASON_TEXT[reason] ?? "was refused."} (${reason})`);
1178
+ }
1179
+ else if (outcome.refusal === "validation" && outcome.detail?.field === "provider_checks") {
1180
+ io.errorLog(" A reproduction hint was refused. Correct or remove it, then confirm again.");
1181
+ }
1182
+ else if (outcome.refusal === "validation" && outcome.detail?.field === "worker_env") {
1183
+ io.errorLog(" A worker variable was refused. Correct it, then confirm again; nothing was truncated or written.");
1184
+ }
867
1185
  io.errorLog(` Nothing was written. ${describeStoredHeading(plan.current)}`);
1186
+ // BAPI-1551: what the owner typed for the declarations stays visible, so a
1187
+ // refused or failed write never silently loses it.
1188
+ for (const line of describeUnsentDeclarations(plan.write))
1189
+ io.errorLog(line);
868
1190
  if (plan.current.confirmed && plan.current.profile !== null) {
869
1191
  for (const line of describeGate(desiredFromStored(plan.current.profile)))
870
1192
  io.errorLog(line);
@@ -872,8 +1194,61 @@ export async function storeConductorGate(io, access, plan) {
872
1194
  return null;
873
1195
  }
874
1196
  io.log(` stored repository gate: ${outcome.profile.profile?.kind ?? "none"} (revision ${outcome.profile.revision})`);
1197
+ if (unsaved !== null)
1198
+ reportUnsavedSettings(io, unsaved);
875
1199
  return outcome.profile;
876
1200
  }
1201
+ /**
1202
+ * BAPI-1551 — the declaration edits a write carried, as the owner typed them, so
1203
+ * they can be re-entered after a refused or failed write. Printed only to the
1204
+ * owner's own installer output; the argv is the owner's own declaration.
1205
+ */
1206
+ function describeUnsentDeclarations(write) {
1207
+ const lines = [];
1208
+ if (write.dependency_install !== undefined) {
1209
+ const entries = write.dependency_install ?? [];
1210
+ if (entries.length === 0) {
1211
+ lines.push(" Not stored — dependency refresh: clear every stored entry");
1212
+ }
1213
+ else {
1214
+ lines.push(" Not stored — dependency refresh entries (re-enter them to keep them):");
1215
+ for (const e of entries) {
1216
+ lines.push(` ${terminalSafe(e.cwd)}, lockfiles ${e.lockfiles.map(terminalSafe).join(", ")}: ` +
1217
+ e.argv.map(terminalSafe).join(" "));
1218
+ }
1219
+ }
1220
+ }
1221
+ if (write.ci_database !== undefined) {
1222
+ lines.push(` Not stored — CI database behavior: ${write.ci_database ?? "unknown (reset)"}`);
1223
+ }
1224
+ return lines;
1225
+ }
1226
+ /**
1227
+ * BAPI-1520 — name the settings an older server could not store. Worker-variable
1228
+ * values are never printed; BAPI-1551 declaration edits are, so they can be re-entered.
1229
+ */
1230
+ function reportUnsavedSettings(io, unsaved) {
1231
+ if (unsaved.workerEnvNames.length === 0 &&
1232
+ unsaved.hintChecks.length === 0 &&
1233
+ unsaved.dependencyInstall === undefined &&
1234
+ unsaved.ciDatabase === undefined) {
1235
+ return;
1236
+ }
1237
+ io.log(" ⚠ Partly stored: this server is older than the installer and cannot store these settings.");
1238
+ if (unsaved.workerEnvNames.length > 0) {
1239
+ io.log(` Not stored — worker variables: ${unsaved.workerEnvNames.map(terminalSafe).join(", ")}`);
1240
+ }
1241
+ if (unsaved.hintChecks.length > 0) {
1242
+ io.log(` Not stored — reproduction hints for: ${unsaved.hintChecks.map(terminalSafe).join(", ")}`);
1243
+ }
1244
+ for (const line of describeUnsentDeclarations({
1245
+ ...(unsaved.dependencyInstall !== undefined ? { dependency_install: unsaved.dependencyInstall } : {}),
1246
+ ...(unsaved.ciDatabase !== undefined ? { ci_database: unsaved.ciDatabase } : {}),
1247
+ })) {
1248
+ io.log(line);
1249
+ }
1250
+ io.log(" Upgrade the Bridge API deployment, then re-run to store them.");
1251
+ }
877
1252
  // ---------------------------------------------------------------------------
878
1253
  // Qualification (property 5)
879
1254
  // ---------------------------------------------------------------------------
@@ -1068,7 +1443,7 @@ export async function runQualifyConductorGate(io, access, gateDeps, options) {
1068
1443
  }
1069
1444
  if (!current.confirmed || current.profile === null) {
1070
1445
  io.errorLog("No confirmed repository gate is stored, so there is nothing to qualify. Confirm one first " +
1071
- "with install-bridge conductor. Nothing was queued.");
1446
+ "with install epic-implementer. Nothing was queued.");
1072
1447
  return 1;
1073
1448
  }
1074
1449
  const profile = current.profile;