@bridge_gpt/mcp-server 0.2.70 → 0.2.71

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 (61) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +10 -1
  3. package/build/agent-registry.js +5 -5
  4. package/build/agents.generated.js +11 -1
  5. package/build/bounded-wait.js +9 -1
  6. package/build/bridge-permissions.js +13 -5
  7. package/build/commands.generated.js +3 -3
  8. package/build/conductor/bridge-api-client.js +260 -2
  9. package/build/conductor/command-drift-production.js +7 -2
  10. package/build/conductor/doctor.js +9 -3
  11. package/build/conductor/epic-implementer-cli.js +4 -0
  12. package/build/conductor/gate-discovery.js +524 -10
  13. package/build/conductor/gate-settings-review.js +451 -0
  14. package/build/conductor/launch-need-probes.js +16 -11
  15. package/build/conductor/launch-plan.js +145 -0
  16. package/build/conductor/precheck-timings.js +14 -0
  17. package/build/conductor/preview-observations.js +10 -0
  18. package/build/conductor/readiness-sections.js +4 -1
  19. package/build/conductor/recovery-cli.js +59 -2
  20. package/build/conductor/recovery-operations.js +45 -2
  21. package/build/docs.generated.js +1 -1
  22. package/build/drive-epic.js +188 -45
  23. package/build/epic-ci-workflow-drift.js +71 -23
  24. package/build/epic-ci-workflow-install.js +83 -26
  25. package/build/epic-ci-workflow-v1.js +132 -0
  26. package/build/epic-ci-workflow.js +174 -13
  27. package/build/epic-implementer-bin.js +18 -18
  28. package/build/executor/ci-rerun-job.js +220 -14
  29. package/build/executor/env.js +207 -3
  30. package/build/executor/gate-qualification-job.js +20 -5
  31. package/build/executor/job-runner.js +112 -11
  32. package/build/executor/likely-tests.js +6 -1
  33. package/build/executor/preflight.js +5 -0
  34. package/build/executor/process-containment.js +18 -0
  35. package/build/executor/prompt-spec.js +72 -13
  36. package/build/executor/reconcile-overlap-job.js +6 -1
  37. package/build/executor/worker-command.js +136 -1
  38. package/build/executor/worker-database.js +30 -11
  39. package/build/executor/worker-resources.js +12 -1
  40. package/build/executor/worker-verification-guidance.js +29 -0
  41. package/build/index.js +221 -165
  42. package/build/install-bridge-conductor-gate.js +195 -14
  43. package/build/install-bridge-conductor-setup.js +20 -6
  44. package/build/install-bridge-conductor.js +355 -37
  45. package/build/install-bridge.js +1 -1
  46. package/build/merge-workflow-install.js +20 -0
  47. package/build/pipelines.generated.js +2 -2
  48. package/build/plan-execution-ledger.js +23 -8
  49. package/build/plane/plane-freshness.js +6 -2
  50. package/build/plane/preflight.js +19 -0
  51. package/build/printed-remedy-commands.js +8 -1
  52. package/build/readme.generated.js +1 -1
  53. package/build/repository-toolchains.js +581 -0
  54. package/build/setup-epic.js +24 -7
  55. package/build/test-command-detection.js +58 -21
  56. package/build/ticket-delivery-artifacts.js +7 -0
  57. package/build/ticket-delivery-enrollment.js +67 -4
  58. package/build/version.generated.js +3 -3
  59. package/docs/EPIC-IMPLEMENTER.md +38 -0
  60. package/docs/epic-implementer/getting-started.md +58 -2
  61. package/package.json +2 -2
@@ -124,10 +124,11 @@ import { describeNativeLedgerAvailability, } from "./conductor/doctor.js";
124
124
  import { resolveGithubMergeRepositoryIdentity, } from "./credential-store.js";
125
125
  import { isUsableMergeCredentialValue, resolveLocalMergeCredentialDetailed, } from "./conductor/merge-credential.js";
126
126
  import { readStoredTestCommand, writeStoredTestCommand, } from "./testing-config-client.js";
127
+ import { describeToolchainResolution, resolveRepositoryToolchains, } from "./repository-toolchains.js";
127
128
  import { detectTestCommand } from "./test-command-detection.js";
128
- import { TestCommandValidationError, validateTestCommand } from "./test-command-validation.js";
129
+ import { TestCommandValidationError, validateTestCommand, } from "./test-command-validation.js";
129
130
  import { EPIC_IMPLEMENTER_CI_CHECK_NAME } from "./epic-ci-workflow.js";
130
- import { assessSetupIndex, catalogLabel, compareIndexedToMerge, planSetupFixes, projectSetupItems, readSetupPullRequest, renderSetupAssessment, setupVerdictLine, unmetBlockingItems, } from "./install-bridge-conductor-setup.js";
131
+ import { assessSetupIndex, catalogLabel, compareIndexedToMerge, isTestCommandFix, planSetupFixes, projectSetupItems, readSetupPullRequest, renderSetupAssessment, setupVerdictLine, unmetBlockingItems, } from "./install-bridge-conductor-setup.js";
131
132
  import { CONDUCTOR_BIN_UNRESOLVED_ERROR, MANAGED_HOOK_NAMES, } from "./conductor/git-hooks.js";
132
133
  import os from "node:os";
133
134
  import path from "node:path";
@@ -178,7 +179,8 @@ export function getInstallBridgeConductorUsage() {
178
179
  "confirmation, runs `gh auth status`. A ready repository gets no questions and no",
179
180
  "writes. Otherwise it asks only what a missing item needs, each with a default of no:",
180
181
  " - which repository, only when it cannot tell;",
181
- " - saving the test command, only when none is stored;",
182
+ " - saving the test command, only when none is stored (or replacing it, when you",
183
+ " pass --test-command);",
182
184
  " - opening the setup pull request with the CI workflow;",
183
185
  " - storing the repository gate and safe defaults, when they would change;",
184
186
  " - storing a GitHub merge token on this computer (read with no echo).",
@@ -195,7 +197,21 @@ export function getInstallBridgeConductorUsage() {
195
197
  "local copy only; it does not revoke the token at GitHub, and a running executor",
196
198
  "keeps the token it started with until it restarts.",
197
199
  "",
200
+ "Test command: setup prints the stored command (and what CI installs for it) on",
201
+ "every run. To save or replace it, pass --test-command \"<command>\": the flag is",
202
+ "your consent for that one write, so there is no command question. The command is",
203
+ "checked first (one line, no GitHub Actions expression, at most 500 characters),",
204
+ "saved once, and read back; setup reports success only when the stored value",
205
+ "matches. The same value again is \"unchanged\" and writes nothing. The flag does",
206
+ "NOT replace the base-URL confirmation (still asked, so it needs a terminal) and",
207
+ "does NOT consent to the workflow pull request, which asks for itself. With",
208
+ "--dry-run nothing is saved. Do not put a credential in a command: setup prints",
209
+ "it and the workflow file contains it.",
210
+ "",
198
211
  "Options:",
212
+ " --test-command <command> Save or replace the repository's test command.",
213
+ " Not combinable with --remove-merge-token or",
214
+ " --clear-gate; may be given once.",
199
215
  " --remove-merge-token Remove the merge token stored on this computer for",
200
216
  " this repository (its own consent), then exit.",
201
217
  " --repo <name> Repository name (default: BAPI_REPO_NAME / .bridge/config)",
@@ -336,6 +352,8 @@ export function parseInstallBridgeConductorArgs(argv) {
336
352
  let policyFile;
337
353
  let epicBranchCiDecision;
338
354
  let removeMergeToken = false;
355
+ let testCommand;
356
+ let testCommandSeen = false;
339
357
  const takeValue = (arg, inline, next) => {
340
358
  if (inline !== undefined) {
341
359
  if (inline.trim().length === 0)
@@ -379,6 +397,36 @@ export function parseInstallBridgeConductorArgs(argv) {
379
397
  }
380
398
  removeMergeToken = true;
381
399
  break;
400
+ case "--test-command": {
401
+ if (testCommandSeen)
402
+ return { status: "error", message: "--test-command may be given once" };
403
+ testCommandSeen = true;
404
+ // The raw value is validated BEFORE any trimming: `takeValue` trims, which
405
+ // would turn a command ending in a newline into a valid one-line command.
406
+ let rawCommand;
407
+ if (inline !== undefined) {
408
+ rawCommand = inline;
409
+ }
410
+ else {
411
+ const next = argv[i + 1];
412
+ if (next === undefined || next.startsWith("-")) {
413
+ return { status: "error", message: "--test-command requires a value" };
414
+ }
415
+ rawCommand = next;
416
+ i++;
417
+ }
418
+ try {
419
+ testCommand = validateTestCommand(rawCommand);
420
+ }
421
+ catch (err) {
422
+ // The message is fixed text and never echoes the command.
423
+ if (err instanceof TestCommandValidationError) {
424
+ return { status: "error", message: `Invalid --test-command: ${err.message}` };
425
+ }
426
+ throw err;
427
+ }
428
+ break;
429
+ }
382
430
  case "--gate-none":
383
431
  case "--confirm-gate":
384
432
  case "--clear-gate":
@@ -569,6 +617,14 @@ export function parseInstallBridgeConductorArgs(argv) {
569
617
  "--executor-id.",
570
618
  };
571
619
  }
620
+ // BAPI-1536 — `--clear-gate` is a standalone action that stops before setup, so a
621
+ // command request beside it would be silently dropped. Refuse the pair.
622
+ if (testCommand !== undefined && gate.clearGate) {
623
+ return {
624
+ status: "error",
625
+ message: "--test-command cannot be combined with --clear-gate: clearing the gate is a standalone action.",
626
+ };
627
+ }
572
628
  // BAPI-1461 — token removal is its own action: only --repo and --dry-run may
573
629
  // accompany it, so it can never be mistaken for, or followed by, setup writes.
574
630
  if (removeMergeToken) {
@@ -591,6 +647,7 @@ export function parseInstallBridgeConductorArgs(argv) {
591
647
  skipWorkflow ||
592
648
  allowedBot !== undefined ||
593
649
  secretName !== undefined ||
650
+ testCommand !== undefined ||
594
651
  branches !== undefined;
595
652
  if (conflicting) {
596
653
  return {
@@ -640,6 +697,7 @@ export function parseInstallBridgeConductorArgs(argv) {
640
697
  ...(policyFile ? { policyFile } : {}),
641
698
  ...(epicBranchCiDecision ? { epicBranchCiDecision } : {}),
642
699
  ...(removeMergeToken ? { removeMergeToken: true } : {}),
700
+ ...(testCommand !== undefined ? { testCommand } : {}),
643
701
  },
644
702
  };
645
703
  }
@@ -1696,7 +1754,9 @@ function gateIoFor(deps) {
1696
1754
  * neither was requested.
1697
1755
  */
1698
1756
  async function runStandaloneGateAction(options, deps, gateIo, access, accessError, baseUrl) {
1699
- const qualifyOnly = options.gate.qualifyGate && !hasExplicitGateInput(options.gate);
1757
+ // BAPI-1536: a command request means setup has work to do, so `--qualify-gate`
1758
+ // is no longer standalone and its accompanying command is never discarded.
1759
+ const qualifyOnly = options.gate.qualifyGate && !hasExplicitGateInput(options.gate) && options.testCommand === undefined;
1700
1760
  if (!options.gate.clearGate && !qualifyOnly)
1701
1761
  return null;
1702
1762
  if (!access) {
@@ -1793,6 +1853,12 @@ export async function runInstallBridgeConductorCli(argv, deps) {
1793
1853
  deps.errorLog("Error: --remove-merge-token is unavailable here: this caller supplied no credential-store seams.");
1794
1854
  return 1;
1795
1855
  }
1856
+ if (options.testCommand !== undefined) {
1857
+ // Accepting the flag and running an implementation that ignores it would
1858
+ // report success for a command that was never saved.
1859
+ deps.errorLog("Error: --test-command is unavailable here: this caller supplied no test-command seams.");
1860
+ return 1;
1861
+ }
1796
1862
  const confirmed = await resolveAndConfirmBaseUrl(options, deps, "Bootstrap against this URL? [y/N]: ");
1797
1863
  if (!confirmed.ok)
1798
1864
  return confirmed.code;
@@ -2317,13 +2383,23 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
2317
2383
  catch {
2318
2384
  testCommand = { state: "unknown" };
2319
2385
  }
2386
+ // The toolchains, read once from the working tree. Kept apart from the
2387
+ // non-sensitive readiness evidence below: they are an input to the workflow
2388
+ // assessment and to operator-only output, never a readiness row.
2389
+ const toolchains = await resolveRepositoryToolchains((relPath) => setup.readRepositoryFile(relPath));
2320
2390
  // The managed workflow, through the installer's own read-only preflight.
2321
2391
  let workflow = { state: "unknown" };
2322
2392
  if (storedCommand === null) {
2323
2393
  workflow = testCommand.state === "missing" ? { state: "needs_command" } : { state: "unknown" };
2324
2394
  }
2395
+ else if (inputs.commandBlocked === true) {
2396
+ // A failed command verification blocks every later workflow step, including
2397
+ // this closing read: the workflow would be judged against a command nobody
2398
+ // confirmed.
2399
+ workflow = { state: "blocked", remedy: COMMAND_UNVERIFIED_WORKFLOW_REMEDY };
2400
+ }
2325
2401
  else if (inputs.githubSignIn === "signed_in") {
2326
- workflow = await assessWorkflow(setup, storedCommand);
2402
+ workflow = await assessWorkflow(setup, storedCommand, toolchains, inputs.commandChanged === true);
2327
2403
  }
2328
2404
  // The setup pull request and, once it merged, the index.
2329
2405
  let setupPullRequest = { state: "unknown" };
@@ -2353,13 +2429,32 @@ async function collectSetupEvidence(deps, setup, access, readiness, inputs) {
2353
2429
  identity,
2354
2430
  repository,
2355
2431
  storedCommand,
2432
+ toolchains,
2356
2433
  };
2357
2434
  }
2358
- /** Classify the managed workflow with the installer's read-only dry run. */
2359
- async function assessWorkflow(setup, testCommand) {
2435
+ /** The remedy shown for the workflow once a command write could not be verified. */
2436
+ const COMMAND_UNVERIFIED_WORKFLOW_REMEDY = "the test command could not be verified, so the CI workflow is not built from it; fix that first, then re-run setup";
2437
+ /** The remedy when the repository's dependency files could not be inspected. Names files, never content. */
2438
+ function toolchainInspectionRemedy(resolution) {
2439
+ const files = resolution.failures.map((f) => f.file).join(", ");
2440
+ return (`Bridge could not inspect ${files} to choose what CI installs, and it will not guess. ` +
2441
+ "Fix the file or its permissions, then re-run setup");
2442
+ }
2443
+ /**
2444
+ * Classify the managed workflow with the installer's read-only dry run.
2445
+ *
2446
+ * `commandChanged` marks a command written during this run: the workflow must
2447
+ * then change too, so a local precondition that stops the preflight (a dirty
2448
+ * worktree) is a known outstanding change and must not be hidden by an older
2449
+ * server-ready workflow fact.
2450
+ */
2451
+ async function assessWorkflow(setup, testCommand, toolchains, commandChanged = false) {
2452
+ if (toolchains.status === "unknown") {
2453
+ return { state: "blocked", remedy: toolchainInspectionRemedy(toolchains) };
2454
+ }
2360
2455
  let result;
2361
2456
  try {
2362
- result = await setup.installCiWorkflow(testCommand, { dryRun: true, quiet: true });
2457
+ result = await setup.installCiWorkflow(testCommand, toolchains.toolchains, { dryRun: true, quiet: true });
2363
2458
  }
2364
2459
  catch {
2365
2460
  return { state: "unknown" };
@@ -2377,9 +2472,12 @@ async function assessWorkflow(setup, testCommand) {
2377
2472
  return { state: "unknown" };
2378
2473
  case "failed":
2379
2474
  if (result.reason === "worktree_not_clean" || result.reason === "not_repository_root") {
2380
- return { state: "precondition", remedy: result.remediation };
2475
+ return commandChanged
2476
+ ? { state: "blocked", remedy: result.remediation }
2477
+ : { state: "precondition", remedy: result.remediation };
2381
2478
  }
2382
- return result.prUrl !== undefined && result.reason === "existing_pr_differs"
2479
+ return result.prUrl !== undefined &&
2480
+ (result.reason === "existing_pr_differs" || result.reason === "historical_managed_pr_open")
2383
2481
  ? { state: "blocked", remedy: `${result.remediation} (${result.prUrl})` }
2384
2482
  : { state: "blocked", remedy: result.remediation };
2385
2483
  }
@@ -2538,6 +2636,140 @@ async function fixGateAndDefaults(deps, options, access, gatePlan) {
2538
2636
  }
2539
2637
  return true;
2540
2638
  }
2639
+ /**
2640
+ * Write failures that are a definite refusal: the server answered and said no.
2641
+ * Every other failure is UNCERTAIN (the write may have landed), so it is read
2642
+ * back and never retried.
2643
+ */
2644
+ const DEFINITE_WRITE_REFUSALS = new Set([
2645
+ "unauthenticated",
2646
+ "forbidden",
2647
+ "not_found",
2648
+ "invalid_command",
2649
+ ]);
2650
+ /**
2651
+ * Validate `requested`, attempt ONE write, then read the stored value back.
2652
+ *
2653
+ * - Invalid input is never sent.
2654
+ * - A definite refusal (unauthenticated, forbidden, not found, invalid) stops
2655
+ * there: nothing changed, so there is nothing to verify.
2656
+ * - An accepted write and an uncertain one are both read back. The write is
2657
+ * never retried.
2658
+ * - Success needs BOTH an accepted write and a read-back equal to the validated
2659
+ * requested value.
2660
+ */
2661
+ export async function saveAndReadBackTestCommand(config, requested) {
2662
+ let command;
2663
+ try {
2664
+ command = validateTestCommand(requested);
2665
+ }
2666
+ catch (err) {
2667
+ return { kind: "invalid_input", reason: err instanceof TestCommandValidationError ? err.reason : "invalid" };
2668
+ }
2669
+ let written;
2670
+ try {
2671
+ written = await writeStoredTestCommand(config, command);
2672
+ }
2673
+ catch {
2674
+ written = { ok: false, reason: "transport_failure", status: 0 };
2675
+ }
2676
+ if (!written.ok && DEFINITE_WRITE_REFUSALS.has(written.reason)) {
2677
+ return { kind: "write_failed", reason: written.reason, stored: undefined };
2678
+ }
2679
+ let readBack;
2680
+ try {
2681
+ readBack = await readStoredTestCommand(config);
2682
+ }
2683
+ catch {
2684
+ readBack = { ok: false, reason: "transport_failure", status: 0 };
2685
+ }
2686
+ if (!written.ok) {
2687
+ return { kind: "write_failed", reason: written.reason, stored: readBack.ok ? readBack.testCommand : undefined };
2688
+ }
2689
+ if (!readBack.ok)
2690
+ return { kind: "unreadable_verification" };
2691
+ if (readBack.testCommand !== command)
2692
+ return { kind: "read_back_mismatch", stored: readBack.testCommand };
2693
+ return { kind: "confirmed", testCommand: readBack.testCommand };
2694
+ }
2695
+ const COMMAND_NOT_ATTEMPTED = { confirmed: null, failure: null, serverValue: undefined };
2696
+ /** The blocking operation result for a failed command write. Fixed text, no command. */
2697
+ function testCommandOperationFailure(remedy) {
2698
+ return {
2699
+ id: "test-command-save",
2700
+ label: "Test command",
2701
+ state: "needs_action",
2702
+ blocking: true,
2703
+ remedy,
2704
+ };
2705
+ }
2706
+ /**
2707
+ * Report a non-confirmed outcome in fixed, sanitized words and build its blocking
2708
+ * operation result. Never prints the requested command, an upstream error body,
2709
+ * or exception text.
2710
+ */
2711
+ function reportTestCommandSaveFailure(deps, outcome, verb) {
2712
+ const head = `Test command not ${verb}`;
2713
+ switch (outcome.kind) {
2714
+ case "invalid_input":
2715
+ deps.log(` ${head} — that command cannot be stored (${outcome.reason}).`);
2716
+ return {
2717
+ confirmed: null,
2718
+ failure: testCommandOperationFailure("give a valid one-line command with --test-command, then re-run setup"),
2719
+ serverValue: undefined,
2720
+ };
2721
+ case "write_failed":
2722
+ deps.log(` ${head} — the save did not complete (${outcome.reason}).`);
2723
+ return {
2724
+ confirmed: null,
2725
+ failure: testCommandOperationFailure(outcome.reason === "forbidden" || outcome.reason === "unauthenticated"
2726
+ ? "this key cannot change the stored test command; use an administrator key, then re-run setup"
2727
+ : "the save did not complete; check the connection and re-run setup"),
2728
+ serverValue: outcome.stored,
2729
+ };
2730
+ case "unreadable_verification":
2731
+ deps.log(` ${head} — save may have succeeded; verification failed.`);
2732
+ return {
2733
+ confirmed: null,
2734
+ failure: testCommandOperationFailure("the save may have succeeded but could not be verified; re-run setup to read the stored command"),
2735
+ serverValue: undefined,
2736
+ };
2737
+ case "read_back_mismatch":
2738
+ deps.log(` ${head}. The stored value is not the one requested.`);
2739
+ return {
2740
+ confirmed: null,
2741
+ failure: testCommandOperationFailure("the stored value differs from the requested one; check the stored command and re-run setup"),
2742
+ serverValue: outcome.stored,
2743
+ };
2744
+ }
2745
+ }
2746
+ /** Run one save/replace and turn it into a fix result, logging the outcome. */
2747
+ async function persistTestCommand(deps, config, command, verb) {
2748
+ const outcome = await saveAndReadBackTestCommand(config, command);
2749
+ if (outcome.kind !== "confirmed")
2750
+ return reportTestCommandSaveFailure(deps, outcome, verb);
2751
+ deps.log(` ${verb} — the stored test command is now in place.`);
2752
+ return { confirmed: outcome.testCommand, failure: null, serverValue: outcome.testCommand };
2753
+ }
2754
+ /**
2755
+ * The single accept-or-replace question for a detected proposal. Enter skips,
2756
+ * `y` or `yes` accepts the proposal, and anything else is a typed replacement.
2757
+ * No terminal means no prompt: the proposal and the unresolved step are shown
2758
+ * and nothing is saved.
2759
+ */
2760
+ async function askAcceptOrReplace(deps, proposed) {
2761
+ if (!deps.promptLine) {
2762
+ deps.log(" skipped saving the test command: there is no interactive terminal, so this counts as declined.");
2763
+ return null;
2764
+ }
2765
+ const answer = (await deps.promptLine(`Save \`${proposed}\` as the test command? Press y to save it, type a different command to save that ` +
2766
+ "instead, or press Enter to skip [y/N]: ")).trim();
2767
+ if (answer.length === 0)
2768
+ return null;
2769
+ if (/^y(es)?$/i.test(answer))
2770
+ return proposed;
2771
+ return answer;
2772
+ }
2541
2773
  /**
2542
2774
  * Fix: save the repository's test command through the setup route, after one
2543
2775
  * contextual agreement. The command is never run here. Only the value read back
@@ -2557,12 +2789,17 @@ async function fixTestCommand(deps, setup, access) {
2557
2789
  let command = null;
2558
2790
  if (detection.status === "detected") {
2559
2791
  deps.log(` Proposed: \`${detection.selected}\` (found in ${detection.provenance}). It is not run now.`);
2560
- const save = await askConsent(deps, "Save this as the repository's test command? [y/N]: ", "saving the test command");
2561
- if (save)
2562
- command = detection.selected;
2792
+ command = await askAcceptOrReplace(deps, detection.selected);
2563
2793
  }
2564
2794
  else {
2565
- deps.log(" No test command could be found in this repository.");
2795
+ if (detection.status === "failed") {
2796
+ // An uninspectable repository is reported as such, never as "nothing found".
2797
+ deps.log(` The repository files could not be inspected (${detection.reason}` +
2798
+ `${detection.file !== undefined ? `: ${detection.file}` : ""}), so no command was proposed.`);
2799
+ }
2800
+ else {
2801
+ deps.log(" No test command could be found in this repository.");
2802
+ }
2566
2803
  if (!deps.promptLine) {
2567
2804
  deps.log(" skipped saving a test command: there is no interactive terminal, so this counts as declined.");
2568
2805
  }
@@ -2574,36 +2811,55 @@ async function fixTestCommand(deps, setup, access) {
2574
2811
  }
2575
2812
  if (command === null) {
2576
2813
  deps.log(" not saved — the test command stays a step left.");
2577
- return null;
2814
+ return COMMAND_NOT_ATTEMPTED;
2578
2815
  }
2579
2816
  try {
2580
2817
  command = validateTestCommand(command);
2581
2818
  }
2582
2819
  catch (err) {
2820
+ // A typed answer is validated once; the reason is shown and there is no retry loop.
2583
2821
  const reason = err instanceof TestCommandValidationError ? err.reason : "invalid";
2584
2822
  deps.log(` not saved — that command cannot be stored (${reason}).`);
2585
- return null;
2823
+ return COMMAND_NOT_ATTEMPTED;
2586
2824
  }
2587
- const written = await writeStoredTestCommand(config, command);
2588
- if (!written.ok) {
2589
- deps.log(` the save did not complete (${written.reason}); reading the stored value back…`);
2590
- }
2591
- // Read back after a save AND after an uncertain one; never retry the write.
2592
- const readBack = await readStoredTestCommand(config);
2593
- if (!readBack.ok || readBack.testCommand === null) {
2594
- deps.log(" the stored test command could not be confirmed; it stays a step left.");
2595
- return null;
2825
+ return persistTestCommand(deps, config, command, "saved");
2826
+ }
2827
+ /**
2828
+ * Fix: save or replace the test command the operator passed with
2829
+ * `--test-command`. The validated flag IS the consent for this one write, so the
2830
+ * command write never goes through {@link askConsent}. The same validation,
2831
+ * single write, and server read-back apply.
2832
+ */
2833
+ async function fixExplicitTestCommand(deps, setup, access, command, hadStoredCommand) {
2834
+ deps.log("");
2835
+ deps.log("Test command");
2836
+ deps.log(" saving the command you passed with --test-command; that flag is the consent for this write.");
2837
+ return persistTestCommand(deps, setup.testingConfig(access), command, hadStoredCommand ? "replaced" : "saved");
2838
+ }
2839
+ /** The one operator-only line for a readable stored command, then what CI installs for it. */
2840
+ function logStoredCommandAndToolchains(deps, storedCommand, toolchains) {
2841
+ deps.log("");
2842
+ if (storedCommand !== null) {
2843
+ deps.log(`Test command: \`${storedCommand}\` (stored). Change it with --test-command "...".`);
2596
2844
  }
2597
- deps.log(" saved — the stored test command is now in place.");
2598
- return readBack.testCommand;
2845
+ deps.log("What CI installs for it:");
2846
+ for (const line of describeToolchainResolution(toolchains))
2847
+ deps.log(` ${line}`);
2599
2848
  }
2600
2849
  /** Fix: open the one setup pull request through the artifact-set installer. */
2601
- async function fixSetupPullRequest(deps, setup, testCommand, repository) {
2850
+ async function fixSetupPullRequest(deps, setup, testCommand, toolchains, repository) {
2602
2851
  deps.log("");
2603
2852
  deps.log("CI workflow");
2853
+ if (toolchains.status === "unknown") {
2854
+ // Uninspectable dependency files are a blocking inspection failure, never "no lockfile".
2855
+ const remedy = toolchainInspectionRemedy(toolchains);
2856
+ deps.log(` skipped — ${remedy}.`);
2857
+ return { workflow: { state: "blocked", remedy }, pr: null };
2858
+ }
2604
2859
  let result;
2605
2860
  try {
2606
- result = await setup.installCiWorkflow(testCommand, { dryRun: false }, (promptText) => askConsent(deps, promptText, "opening the setup pull request"));
2861
+ // The setup pull request has its OWN consent, separate from the command write.
2862
+ result = await setup.installCiWorkflow(testCommand, toolchains.toolchains, { dryRun: false }, (promptText) => askConsent(deps, promptText, "opening the setup pull request"));
2607
2863
  }
2608
2864
  catch {
2609
2865
  deps.log(" the setup pull request could not be prepared; re-run setup.");
@@ -2883,17 +3139,34 @@ async function runConvergingSetup(options, deps, setup) {
2883
3139
  identity: first.identity,
2884
3140
  repository: first.repository,
2885
3141
  storedCommand: first.storedCommand,
3142
+ toolchains: first.toolchains,
3143
+ commandChanged: false,
3144
+ commandBlocked: false,
2886
3145
  failedOperations: [],
2887
3146
  };
2888
3147
  const firstItems = projectSetupItems(state.evidence);
2889
3148
  for (const line of renderSetupAssessment(firstItems, "What setup found"))
2890
3149
  deps.log(line);
2891
- const fixes = planSetupFixes(state.evidence, {
3150
+ // An explicit --test-command asks for a write unless the stored value already
3151
+ // equals it. A stored value that could not be read is eligible for the write.
3152
+ // Only this non-sensitive boolean reaches the planner; the text never does.
3153
+ const explicitCommand = options.testCommand;
3154
+ const commandAlreadyStored = explicitCommand !== undefined &&
3155
+ state.evidence.testCommand.state === "stored" &&
3156
+ state.storedCommand === explicitCommand;
3157
+ const replaceTestCommandRequested = explicitCommand !== undefined && !commandAlreadyStored;
3158
+ const planContext = {
2892
3159
  gateOrDefaultsNeedWrite: gateOrDefaultsNeedWrite(gatePlan, firstReport.readiness),
2893
3160
  dryRun: options.dryRun,
2894
- });
3161
+ };
3162
+ let fixes = planSetupFixes(state.evidence, { ...planContext, replaceTestCommandRequested });
3163
+ if (commandAlreadyStored) {
3164
+ deps.log("");
3165
+ deps.log("Test command unchanged — it already matches --test-command, so nothing was written.");
3166
+ }
2895
3167
  // ---- Dry run: preview only, before every write and write prompt ---------
2896
3168
  if (options.dryRun) {
3169
+ logStoredCommandAndToolchains(deps, state.storedCommand, state.toolchains);
2897
3170
  deps.log("");
2898
3171
  deps.log("Dry run — nothing was written and nothing was asked.");
2899
3172
  if (fixes.length === 0)
@@ -2914,22 +3187,60 @@ async function runConvergingSetup(options, deps, setup) {
2914
3187
  deps.log("");
2915
3188
  deps.log("Fixing what is missing…");
2916
3189
  }
2917
- for (const fix of fixes) {
2918
- if (fix === "save_test_command") {
2919
- const saved = await fixTestCommand(deps, setup, access);
2920
- if (saved !== null) {
2921
- state.storedCommand = saved;
3190
+ // Each fix runs at most once per invocation: re-planning after a command write
3191
+ // can add the workflow fix, but never repeats a write, a declined prompt, or
3192
+ // an independent setup operation.
3193
+ const attempted = new Set();
3194
+ while (fixes.length > 0) {
3195
+ const fix = fixes.shift();
3196
+ if (attempted.has(fix))
3197
+ continue;
3198
+ attempted.add(fix);
3199
+ if (isTestCommandFix(fix)) {
3200
+ const result = fix === "replace_test_command" && explicitCommand !== undefined
3201
+ ? await fixExplicitTestCommand(deps, setup, access, explicitCommand, state.evidence.testCommand.state === "stored")
3202
+ : await fixTestCommand(deps, setup, access);
3203
+ if (result.failure !== null) {
3204
+ // A write that was not confirmed: report it as a blocking operation, keep
3205
+ // only the server's returned value, and block every later workflow step.
3206
+ state.failedOperations.push(result.failure);
3207
+ state.commandBlocked = true;
3208
+ if (result.serverValue !== undefined) {
3209
+ state.storedCommand = result.serverValue;
3210
+ state.evidence = {
3211
+ ...state.evidence,
3212
+ testCommand: { state: result.serverValue === null ? "missing" : "stored" },
3213
+ };
3214
+ }
3215
+ state.evidence = { ...state.evidence, workflow: { state: "blocked", remedy: COMMAND_UNVERIFIED_WORKFLOW_REMEDY } };
3216
+ }
3217
+ else if (result.confirmed !== null) {
3218
+ state.storedCommand = result.confirmed;
3219
+ state.commandChanged = true;
2922
3220
  state.evidence = { ...state.evidence, testCommand: { state: "stored" } };
3221
+ // Reassess the workflow against the CONFIRMED value and the same
3222
+ // toolchain snapshot, then derive what is left from the updated evidence.
3223
+ const reassessed = state.evidence.githubSignIn === "signed_in"
3224
+ ? await assessWorkflow(setup, result.confirmed, state.toolchains, true)
3225
+ : { state: "unknown" };
3226
+ state.evidence = { ...state.evidence, workflow: reassessed };
3227
+ fixes = planSetupFixes(state.evidence, { ...planContext, replaceTestCommandRequested: false }).filter((kind) => !attempted.has(kind) && !isTestCommandFix(kind));
2923
3228
  }
2924
3229
  }
2925
3230
  else if (fix === "setup_pr") {
3231
+ if (state.commandBlocked) {
3232
+ deps.log("");
3233
+ deps.log("CI workflow");
3234
+ deps.log(" skipped — the test command could not be verified, so the workflow is not built from it.");
3235
+ continue;
3236
+ }
2926
3237
  if (state.storedCommand === null) {
2927
3238
  deps.log("");
2928
3239
  deps.log("CI workflow");
2929
3240
  deps.log(" skipped — it is built from the stored test command, which is not saved yet.");
2930
3241
  continue;
2931
3242
  }
2932
- const opened = await fixSetupPullRequest(deps, setup, state.storedCommand, state.repository);
3243
+ const opened = await fixSetupPullRequest(deps, setup, state.storedCommand, state.toolchains, state.repository);
2933
3244
  state.evidence = { ...state.evidence, workflow: opened.workflow };
2934
3245
  }
2935
3246
  else if (fix === "gate_and_defaults" && gatePlan !== null) {
@@ -3004,6 +3315,8 @@ async function runConvergingSetup(options, deps, setup) {
3004
3315
  const closing = await collectSetupEvidence(deps, setup, access, finalReadiness, {
3005
3316
  ...collectInputs,
3006
3317
  advisories: state.evidence.advisories,
3318
+ commandChanged: state.commandChanged,
3319
+ commandBlocked: state.commandBlocked,
3007
3320
  });
3008
3321
  // A parse this run queued is pending, whatever the first read-back says.
3009
3322
  if (state.evidence.index.state === "queued_by_setup" && closing.evidence.index.state !== "reached") {
@@ -3038,6 +3351,9 @@ async function runConvergingSetup(options, deps, setup) {
3038
3351
  });
3039
3352
  }
3040
3353
  }
3354
+ // The latest authoritative command (after any replacement) and what CI installs
3355
+ // for it. Operator-only: written through deps.log and nowhere else.
3356
+ logStoredCommandAndToolchains(deps, closing.evidence.testCommand.state === "stored" ? closing.storedCommand : null, closing.toolchains);
3041
3357
  for (const line of renderSetupAssessment(items, "Where things stand"))
3042
3358
  deps.log(line);
3043
3359
  for (const advisory of closing.evidence.advisories)
@@ -3056,6 +3372,8 @@ function deniesEnforcementUnknown(report) {
3056
3372
  /** Short previews of each fix for --dry-run. */
3057
3373
  const DRY_RUN_FIX_TEXT = Object.freeze({
3058
3374
  save_test_command: "save the repository's test command (one question, then PUT /setup/testing-config)",
3375
+ replace_test_command: "save the command you passed with --test-command (that flag is the consent; one write, then a read-back), " +
3376
+ "then re-check the CI workflow against the stored value and offer the setup pull request",
3059
3377
  setup_pr: "open the setup pull request with the CI workflow (its own consent)",
3060
3378
  gate_and_defaults: "store the repository gate and the safe supervisor defaults (its own consent)",
3061
3379
  merge_token: "store a GitHub merge token on this computer (its own consent, read with no echo)",
@@ -1691,7 +1691,7 @@ export function buildConductorSetupDeps(deps, log, errorLog) {
1691
1691
  getPostHeaders: async () => ({ "X-API-Key": access.apiKey, "Content-Type": "application/json" }),
1692
1692
  }),
1693
1693
  readRepositoryFile: (relPath) => deps.readFile(path.join(deps.cwd, relPath)),
1694
- installCiWorkflow: (testCommand, options, confirmWrite) => installEpicCiWorkflow(testCommand, { dryRun: options.dryRun }, {
1694
+ installCiWorkflow: (testCommand, toolchains, options, confirmWrite) => installEpicCiWorkflow(testCommand, toolchains, { dryRun: options.dryRun }, {
1695
1695
  ...installerDeps,
1696
1696
  ...(options.quiet === true ? { log: () => { }, errorLog: () => { } } : {}),
1697
1697
  confirmWrite,
@@ -138,6 +138,11 @@ export const MERGE_WORKFLOW_INSTALL_FAILURE_REASONS = [
138
138
  "worktree_failed",
139
139
  /** The test command for the CI workflow is missing or invalid. */
140
140
  "test_command_invalid",
141
+ // --- BAPI-1536 -----------------------------------------------------------
142
+ /** The CI workflow's toolchain set is outside the closed vocabulary. */
143
+ "toolchains_invalid",
144
+ /** A pull request from an earlier published renderer version's managed branch is still open. */
145
+ "historical_managed_pr_open",
141
146
  ];
142
147
  // ---------------------------------------------------------------------------
143
148
  // Path safety
@@ -206,6 +211,8 @@ const REMEDIATION = {
206
211
  managed_state_changed: "Another managed branch or pull request appeared while this command ran; review it, then re-run.",
207
212
  worktree_failed: "A temporary git worktree could not be created; check free disk space and `git worktree list`, then re-run.",
208
213
  test_command_invalid: "Save a valid test command through Bridge setup, then re-run.",
214
+ toolchains_invalid: "Re-run setup so the repository's dependency files are inspected again; nothing was written.",
215
+ historical_managed_pr_open: "An earlier Bridge setup pull request is still open for this workflow; merge or close it, then re-run. Bridge does not close or rewrite it.",
209
216
  };
210
217
  /** The remediation sentence for a reason. */
211
218
  export function artifactSetRemediation(reason) {
@@ -775,6 +782,19 @@ export async function installArtifactSet(descriptor, options, deps) {
775
782
  if (preflight.classification === "identical") {
776
783
  return { outcome: "identical", artifacts: [...preflight.proposals.keys()], warnings: [] };
777
784
  }
785
+ // An open pull request from an earlier renderer version's branch comes first:
786
+ // it targets the same managed file, so new work would race it.
787
+ for (const historical of descriptor.historicalBranches ?? []) {
788
+ const lookup = await findExistingManagedPr(deps, preflight.repository, historical);
789
+ if (lookup.kind === "lookup_failed")
790
+ return fail("remote_state_unverifiable", { branch: historical });
791
+ if (lookup.kind === "found") {
792
+ return fail("historical_managed_pr_open", {
793
+ branch: historical,
794
+ ...(lookup.pr.url.length > 0 ? { prUrl: lookup.pr.url } : {}),
795
+ });
796
+ }
797
+ }
778
798
  const managedPaths = descriptor.artifacts.map((a) => a.relPath);
779
799
  let upgrade = false;
780
800
  let branch = "";