@bridge_gpt/mcp-server 0.2.74 → 0.2.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +14 -7
  2. package/build/agent-launchers/prompt.js +9 -21
  3. package/build/agents.generated.js +2 -2
  4. package/build/authored-plan.js +542 -0
  5. package/build/bridge-permissions.js +8 -0
  6. package/build/commands.generated.js +5 -5
  7. package/build/conductor/bridge-api-client.js +666 -46
  8. package/build/conductor/epic-implementer-cli.js +337 -93
  9. package/build/conductor/gate-discovery.js +209 -9
  10. package/build/conductor/gate-settings-review.js +7 -11
  11. package/build/conductor/launch-plan.js +58 -12
  12. package/build/conductor/open-decision-phrases.js +50 -0
  13. package/build/conductor/prerequisite-inputs.js +181 -14
  14. package/build/connect-github-api.js +18 -0
  15. package/build/connect-github.js +35 -18
  16. package/build/docs.generated.js +2 -2
  17. package/build/drive-epic.js +387 -12
  18. package/build/epic-ci-workflow.js +3 -2
  19. package/build/epic-implementer-bin.js +152 -38
  20. package/build/epic-implementer-bundle-cli.js +61 -0
  21. package/build/epic-implementer-claude-hook-bin.js +1 -1
  22. package/build/epic-implementer-env.js +3 -4
  23. package/build/epic-integration-pr.js +5 -2
  24. package/build/executor/completion-contract.js +24 -1
  25. package/build/executor/gate-qualification-job.js +193 -23
  26. package/build/executor/gate-qualification-tests-ran.js +232 -0
  27. package/build/executor/job-runner.js +9 -722
  28. package/build/executor/job-type-wrappers.js +734 -0
  29. package/build/executor/preflight.js +6 -2
  30. package/build/executor/process-containment.js +8 -1
  31. package/build/executor/required-verification.js +28 -2
  32. package/build/executor/runner.js +4 -1
  33. package/build/executor/types.js +9 -0
  34. package/build/executor/worker-database.js +6 -1
  35. package/build/executor/worker-guard-hook.js +24 -2
  36. package/build/generated/ticket-status.js +20 -0
  37. package/build/index.js +391 -257
  38. package/build/install-bridge-conductor-answers.js +28 -1
  39. package/build/install-bridge-conductor-apply.js +11 -3
  40. package/build/install-bridge-conductor-assessment.js +114 -12
  41. package/build/install-bridge-conductor-compact.js +2 -0
  42. package/build/install-bridge-conductor-gate.js +257 -80
  43. package/build/install-bridge-conductor-setup.js +4 -4
  44. package/build/install-bridge-conductor-trial-report.js +170 -0
  45. package/build/install-bridge-conductor.js +303 -31
  46. package/build/pipelines.generated.js +7 -7
  47. package/build/plan-generation.js +17 -0
  48. package/build/printed-remedy-commands.js +54 -0
  49. package/build/readme.generated.js +1 -1
  50. package/build/repository-toolchains.js +11 -5
  51. package/build/scripts/saved-commands-config-field-driver.js +65 -0
  52. package/build/setup-epic.js +10 -1
  53. package/build/test-support/executor-source-files.js +1 -1
  54. package/build/v2-readiness-requirements.js +5 -1
  55. package/build/version.generated.js +3 -3
  56. package/build/worker-guard-hook-bin.js +2 -2
  57. package/docs/EPIC-IMPLEMENTER.md +4 -4
  58. package/docs/install/github-app.md +79 -92
  59. package/package.json +1 -1
  60. package/build/conductor/epic-reconcile.js +0 -603
  61. package/build/conductor/epic-runtime.js +0 -2020
  62. package/build/conductor/epic-state.js +0 -774
@@ -84,6 +84,9 @@ const OPTION_VOCABULARY = Object.freeze({
84
84
  launch_profile: ["save", "skip"],
85
85
  epic_ci_change: ["approve", "decline", "keep"],
86
86
  });
87
+ /** BAPI-1699 — the most commands one `commands` answer may carry, and the longest line. */
88
+ const TEST_COMMANDS_MAX = 4;
89
+ const TEST_COMMAND_MAX_CHARS = 500;
87
90
  function isPlainObject(value) {
88
91
  return value !== null && typeof value === "object" && !Array.isArray(value);
89
92
  }
@@ -122,11 +125,29 @@ export function parseAnswerValue(key, raw) {
122
125
  }
123
126
  return bad("invalid_value", 'Use "decline", "keep", or a list of offered option ids ([] approves none).');
124
127
  }
128
+ if (key === "test_command" && isPlainObject(raw) && Object.hasOwn(raw, "commands")) {
129
+ // BAPI-1699: the whole list or a refusal. The detail is position-based and never
130
+ // echoes a submitted value, and accepted strings are kept exactly as given.
131
+ const shape = 'Use {"commands": ["<one line>", ...]} with one to four commands.';
132
+ if (Object.keys(raw).length !== 1 || !Array.isArray(raw.commands))
133
+ return bad("invalid_value", shape);
134
+ const list = raw.commands;
135
+ if (list.length < 1 || list.length > TEST_COMMANDS_MAX) {
136
+ return bad("invalid_value", `Give between 1 and ${TEST_COMMANDS_MAX} commands.`);
137
+ }
138
+ for (let i = 0; i < list.length; i += 1) {
139
+ const entry = list[i];
140
+ if (typeof entry !== "string" || entry.trim().length === 0 || entry.length > TEST_COMMAND_MAX_CHARS || /[\r\n]/.test(entry)) {
141
+ return bad("invalid_value", `Command ${i + 1} must be one non-blank line of at most ${TEST_COMMAND_MAX_CHARS} characters.`);
142
+ }
143
+ }
144
+ return { ok: true, decision: { kind: "commands", commands: [...list] } };
145
+ }
125
146
  if (key === "test_command" && isPlainObject(raw)) {
126
147
  if (onlyKeys(raw, ["command"]) && typeof raw.command === "string" && raw.command.trim().length > 0 && raw.command.length <= 500 && !/[\r\n]/.test(raw.command)) {
127
148
  return { ok: true, decision: { kind: "command", command: raw.command.trim() } };
128
149
  }
129
- return bad("invalid_value", 'Use "learn", "skip", "keep", or {"command": "<one line>"}.');
150
+ return bad("invalid_value", 'Use "learn", "skip", "keep", {"command": "<one line>"}, or {"commands": ["<one line>", ...]}.');
130
151
  }
131
152
  if (key === "dependency_install" && isPlainObject(raw)) {
132
153
  const shape = 'Use "approve", "decline", "keep", or {"entries": [{"cwd": ".", "argv": ["..."], "lockfiles": ["..."]}]}.';
@@ -239,6 +260,8 @@ function effectFor(key, choice, decision) {
239
260
  return effects.reference !== undefined ? { ...effects.reference, params: { reference: decision.reference } } : null;
240
261
  case "command":
241
262
  return { action: "qualify_owner_test_command", target: "repository_gate.local_commands", params: { command: decision.command }, condition: "only_if_check_passes" };
263
+ case "commands":
264
+ return { action: "qualify_saved_test_commands", target: "repository_gate.local_commands", params: { commands: decision.commands }, condition: "only_if_check_passes" };
242
265
  case "epic_server_sfcc":
243
266
  return effects[decision.value.mode] !== undefined
244
267
  ? { ...effects[decision.value.mode], params: { ...decision.value } }
@@ -271,6 +294,10 @@ function consequenceOf(choice, decision) {
271
294
  }
272
295
  if (decision.kind === "command")
273
296
  return "Bridge proves your command with one bounded check and stores it only if it passes.";
297
+ if (decision.kind === "commands") {
298
+ const lines = decision.commands.map((command) => `\`${command}\``).join(", ");
299
+ return `Saves your ${decision.commands.length} test command${decision.commands.length === 1 ? "" : "s"} right away, in the order you gave: ${lines}. They are not relied on for the guard until they passed the trial run in a clean checkout.`;
300
+ }
274
301
  if (decision.kind === "dependency_install_entries") {
275
302
  return decision.entries.length === 0
276
303
  ? "Stores an empty list: workers and the test trial run no declared install, and managed CI uses its normal toolchain install."
@@ -14,6 +14,7 @@
14
14
  * `unattempted`; independent ones still run. Nothing is rolled back.
15
15
  * - The setup record is written here and nowhere else, only after approval.
16
16
  */
17
+ import { isTrialPhase, presentTrialResult } from "./install-bridge-conductor-trial-report.js";
17
18
  import { SETUP_RECORD_RELATIVE_PATH, } from "./install-bridge-conductor-contracts.js";
18
19
  const NOT_COMPLETED = new Set(["failed", "refused", "uncertain", "unattempted"]);
19
20
  const COMPLETE = new Set(["written", "unchanged", "declined"]);
@@ -148,7 +149,7 @@ export function renderSetupRecord(proposal, digest, results) {
148
149
  lines.push("");
149
150
  // BAPI-1677: the approved install commands, once they are confirmed in place. The text comes
150
151
  // from the approved proposal, so a replay that finds them unchanged leaves the record alone.
151
- // An install that worked is not a proven test command, and a failed trial is not a failed install.
152
+ // An install that worked is not a test command that passed the trial run, and a failed trial is not a failed install.
152
153
  const installResult = results.find((r) => r.key === "dependency_install");
153
154
  const installValue = proposal?.actions.find((a) => a.key === "dependency_install")?.effect?.params?.value;
154
155
  if (Array.isArray(installValue) && (installResult?.status === "written" || installResult?.status === "unchanged")) {
@@ -164,10 +165,16 @@ export function renderSetupRecord(proposal, digest, results) {
164
165
  const ran = trial?.read_back?.ran;
165
166
  if (Array.isArray(ran) && (trial?.status === "written" || trial?.status === "unchanged")) {
166
167
  // The command the server reports, never the one Bridge expected to try.
167
- lines.push("## Test trial", "", `Passed. The proven test command is ${ran.map((c) => `\`${c.replace(/`/g, "'")}\``).join(", ")}.`, "");
168
+ lines.push("## Test trial", "", `Passed the trial run. The test command is ${ran.map((c) => `\`${c.replace(/`/g, "'")}\``).join(", ")}.`, "");
168
169
  }
169
170
  else if (trial?.status === "failed" && trial.phase != null) {
170
- lines.push("## Test trial", "", "Did not pass, so no test command was stored. The install commands are unaffected. Run setup again to try once more.", "");
171
+ // BAPI-1698: the same phase-specific presentation every setup path uses.
172
+ const presentation = presentTrialResult({
173
+ phase: isTrialPhase(trial.phase) ? trial.phase : null,
174
+ dependencyInstallDeclared: null,
175
+ });
176
+ lines.push("## Test trial", "", `${presentation.headline}. ${presentation.explanation} No test command was stored. The install commands are unaffected.` +
177
+ (presentation.remedy !== null ? ` Next: ${presentation.remedy}` : ""), "");
171
178
  }
172
179
  return lines.join("\n");
173
180
  }
@@ -198,6 +205,7 @@ function describeDecision(decision) {
198
205
  case "selection": return decision.ids.length === 0 ? "none selected" : `${decision.ids.length} selected`;
199
206
  case "reference": return decision.reference.kind === "env" ? `reference env:${decision.reference.name}` : `reference credential_store:${decision.reference.target}`;
200
207
  case "command": return "owner command";
208
+ case "commands": return `${decision.commands.length} test command${decision.commands.length === 1 ? "" : "s"} given`;
201
209
  case "epic_server_sfcc": return decision.value.mode;
202
210
  case "profile": return `profile ${decision.name}`;
203
211
  case "dependency_install_entries": return decision.entries.length === 0 ? "empty install list" : `${decision.entries.length} install command${decision.entries.length === 1 ? "" : "s"} given`;
@@ -238,6 +238,8 @@ export function dependencyInstallDetails(input) {
238
238
  argv: e.argv.map(displayArg),
239
239
  lockfiles: e.lockfiles.map(displayArg),
240
240
  });
241
+ // BAPI-1698: proposed installs come first; named coverage gaps (from the plan's
242
+ // limitations) follow them. Gaps are advisory and never a prerequisite.
241
243
  return {
242
244
  commands: input.commands.map(row),
243
245
  ...(input.differs ? { stored: input.stored.map(row) } : {}),
@@ -254,15 +256,88 @@ export const LEARN_EFFECT = Object.freeze({
254
256
  params: Object.freeze({ bounded: true }),
255
257
  condition: "only_if_check_passes",
256
258
  });
259
+ /** BAPI-1699 — qualify the owner's saved commands; the model is not consulted. */
260
+ export function qualifySavedEffect(saved) {
261
+ return {
262
+ action: "qualify_saved_test_commands",
263
+ target: "repository_gate.local_commands",
264
+ params: { commands: [...saved.commands], generation: saved.generation },
265
+ condition: "only_if_check_passes",
266
+ };
267
+ }
268
+ const SAVED_STATUS_LABEL = Object.freeze({
269
+ not_tried: "Saved; trial not yet run",
270
+ queued: "Trial queued",
271
+ failed: "Trial failed",
272
+ passed: "Passed the trial run",
273
+ });
274
+ /** The factual label for a saved selection's trial state; `null` means the server could not say. */
275
+ export function savedStatusLabel(trialState) {
276
+ return trialState === null ? "Trial could not be read" : SAVED_STATUS_LABEL[trialState] ?? "Trial could not be read";
277
+ }
278
+ function savedDetails(saved) {
279
+ return {
280
+ pending: saved.commands.map(displayArg),
281
+ in_force: (saved.commandsInForce ?? []).map(displayArg),
282
+ status_label: savedStatusLabel(saved.trialState),
283
+ ...(saved.setBy !== null ? { set_by: displayArg(saved.setBy) } : {}),
284
+ };
285
+ }
286
+ function savedCommandsChoice(t, saved) {
287
+ const details = savedDetails(saved);
288
+ const lines = details.pending.map((command) => `\`${command}\``).join(", ");
289
+ if (saved.trialState === "passed") {
290
+ return {
291
+ id: "test_command",
292
+ family: "test_command",
293
+ answer_key: "test_command",
294
+ current: "stored",
295
+ options: [KEEP_OPTION(`The saved test commands (${lines}) passed the trial run and stay in force.`)],
296
+ recommended: "keep",
297
+ why_recommended: "These commands passed the trial run, so nothing changes.",
298
+ consequential: false,
299
+ applicable: t.ownerCommandSupplied,
300
+ selection: "single",
301
+ test_commands: details,
302
+ };
303
+ }
304
+ const replacing = details.in_force.length > 0;
305
+ return {
306
+ id: "test_command",
307
+ family: "test_command",
308
+ answer_key: "test_command",
309
+ current: "saved_pending",
310
+ options: [
311
+ {
312
+ id: "learn",
313
+ label: `Give the saved test commands a trial run: ${lines}`,
314
+ consequence: `Bridge tries exactly these commands, in this order, in a clean checkout. The model is not consulted. ` +
315
+ (replacing
316
+ ? "The guard you have now stays in force until they pass the trial run."
317
+ : "They are relied on for the guard only after they pass the trial run."),
318
+ },
319
+ { id: "skip", label: "Leave the saved commands untried for now", consequence: "Nothing runs; the commands stay saved and are not in force." },
320
+ ],
321
+ recommended: "learn",
322
+ why_recommended: "You or your agent already chose these commands; a trial run proves they work in a clean checkout before anything relies on them.",
323
+ consequential: false,
324
+ applicable: true,
325
+ selection: "single",
326
+ effects: { learn: qualifySavedEffect(saved) },
327
+ test_commands: details,
328
+ };
329
+ }
257
330
  function testCommandChoice(t) {
331
+ if (t.saved !== undefined)
332
+ return savedCommandsChoice(t, t.saved);
258
333
  const options = [];
259
334
  const candidate = t.candidate !== undefined && t.candidate !== null ? displayArg(t.candidate) : null;
260
335
  if (t.trialEligible) {
261
336
  options.push({
262
337
  id: "learn",
263
- label: candidate !== null ? `Let Bridge learn and prove the test command (it expects to try ${candidate})` : "Let Bridge learn and prove the test command",
338
+ label: candidate !== null ? `Let Bridge learn the test command and give it a trial run (it expects to try ${candidate})` : "Let Bridge learn the test command and give it a trial run",
264
339
  consequence: (candidate !== null ? `Bridge expects to try ${candidate} first. ` : "") +
265
- "Learning stores instructions, not a proven command, so they guide the attempt and the server may choose another command. " +
340
+ "Learning stores instructions, not a command that has passed the trial run, so they guide the attempt and the server may choose another command. " +
266
341
  "It runs one bounded trial and stores a command only if the check passes.",
267
342
  });
268
343
  }
@@ -277,9 +352,9 @@ function testCommandChoice(t) {
277
352
  options,
278
353
  recommended: t.trialEligible ? "learn" : t.stored ? "keep" : "skip",
279
354
  why_recommended: t.trialEligible
280
- ? "A learned command is stored only after the server proves it passes, so it cannot weaken the gate."
355
+ ? "A learned command is stored only after it passes the trial run, so it cannot weaken the gate."
281
356
  : t.stored
282
- ? "A command is already stored and proven, so nothing changes."
357
+ ? "A command is already stored and passed the trial run, so nothing changes."
283
358
  : "There is no test command Bridge can try right now, and setup can still finish without one.",
284
359
  consequential: false,
285
360
  applicable: t.trialEligible || t.ownerCommandSupplied,
@@ -314,9 +389,12 @@ function setupPrChoice(pr) {
314
389
  family: "setup_pr",
315
390
  answer_key: "setup_pr",
316
391
  current: pr.workflowState,
317
- options: approveDecline(`Opens a setup pull request running ${runs}, only if the check passes. You review and merge it.`, "Opens no pull request. Bridge's workflow is not added."),
318
- recommended: "approve",
319
- why_recommended: `The workflow runs ${runs}, the pull request opens only if that check passes, and you review and merge it, so nothing reaches your default branch without you.`,
392
+ options: approveDecline(`Adds a GitHub check (${EPIC_IMPLEMENTER_CI_CHECK_NAME}) to each epic pull request, running ${runs}. ` +
393
+ "The setup pull request opens only if the check passes, and you must merge it before the first epic. " +
394
+ "Approving also adds that check as a required check.", "Opens no pull request. Bridge's workflow is not added, and the managed check is not made required."),
395
+ // BAPI-1701: the managed workflow is an opt-in. Approving it also adds a required check, so it is offered, not recommended.
396
+ recommended: "decline",
397
+ why_recommended: `Declining avoids the setup pull request and does not add ${EPIC_IMPLEMENTER_CI_CHECK_NAME} as a required check, and you can still approve it for a GitHub check on each epic pull request running ${runs}.`,
320
398
  consequential: true,
321
399
  applicable: true,
322
400
  selection: "single",
@@ -881,6 +959,12 @@ export const NO_TESTS_SENTENCE = "Bridge will not require a passing test run bef
881
959
  export const TEST_TRIAL_CONDITION = "If the test-command trial does not pass:";
882
960
  /** The next step when nothing is left to do. */
883
961
  export const READY_NEXT_STEP = "Next step: Run /drive-epic-run for an epic.";
962
+ /**
963
+ * BAPI-1698 — the next step when everything a run needs is in place and only the
964
+ * test trial failed. The owner may start now; the warning names the consequence.
965
+ */
966
+ export const GUARDLESS_NEXT_STEP = "Next step: You can start an epic now (run /drive-epic-run for an epic). Until a test command has passed the " +
967
+ "trial run, epics run without a local test guard.";
884
968
  /**
885
969
  * The one rule for merge-test protection, used for both the proposal's planned value
886
970
  * and the verdict's confirmed value. Returns `undefined` when the evidence does not
@@ -1024,10 +1108,23 @@ export function buildInstallVerdict(input) {
1024
1108
  }
1025
1109
  if (protection === "none" || protection === "watched_only")
1026
1110
  parts.push(NO_TESTS_SENTENCE);
1027
- const firstFix = settings[0]?.fix ?? blockers[0]?.fix;
1028
- const nextStep = firstFix !== undefined
1029
- ? asNextStep(firstFix)
1030
- : ready === true ? READY_NEXT_STEP : asNextStep(READINESS_PREREQUISITE_FIXES.doctor);
1111
+ // BAPI-1701: the gate's own fix leads, so an optional setting's generic rerun cannot hide why no gate was stored.
1112
+ const firstFix = (settings.find((s) => s.key === "gate") ?? settings[0])?.fix ?? blockers[0]?.fix;
1113
+ // BAPI-1698: when the ONLY setting that did not take is a completed test trial that
1114
+ // failed, and nothing blocks a run, the owner can start an epic now. Say so, with
1115
+ // the consequence, instead of sending them back to setup.
1116
+ const trialResult = results.find((r) => r.key === "test_command");
1117
+ const onlyFailedTrial = ready === true &&
1118
+ blockers.length === 0 &&
1119
+ settings.length === 1 &&
1120
+ settings[0].key === "test_command" &&
1121
+ trialResult?.status === "failed" &&
1122
+ typeof trialResult.phase === "string";
1123
+ const nextStep = onlyFailedTrial
1124
+ ? GUARDLESS_NEXT_STEP
1125
+ : firstFix !== undefined
1126
+ ? asNextStep(firstFix)
1127
+ : ready === true ? READY_NEXT_STEP : asNextStep(READINESS_PREREQUISITE_FIXES.doctor);
1031
1128
  return {
1032
1129
  line: parts.join(" "),
1033
1130
  settings_not_applied: settings,
@@ -1129,9 +1226,14 @@ export function resolveEpicBranchCiRecommendation(choices, settled, context = {
1129
1226
  // Decline: the draft's reason described a delivery the final answers no longer approve. Finalize
1130
1227
  // first, then set the reason, so the generic last-resort sentence cannot replace it.
1131
1228
  const declined = finalizeRecommendation({ ...withOptions, recommended: "decline" });
1229
+ // BAPI-1701: when the setup pull request is the only way Bridge's workflow arrives and it is not approved,
1230
+ // say what declining leaves out. Anything another approved action supplies is never described as absent.
1231
+ const setupIsSolePath = context.setupSuppliesWorkflow && !setupApproved && !ciApproved && !covers;
1132
1232
  return replaceCi({
1133
1233
  ...declined,
1134
- why_recommended: "No workflow is confirmed to run on pull requests into epic branches and no CI change is approved, so child pull requests merge into the epic branch without checks.",
1234
+ why_recommended: setupIsSolePath
1235
+ ? `Declining the setup pull request does not add ${EPIC_IMPLEMENTER_CI_CHECK_NAME} as a required check, and no CI change is approved, so child pull requests merge into the epic branch without that check.`
1236
+ : "No workflow is confirmed to run on pull requests into epic branches and no CI change is approved, so child pull requests merge into the epic branch without checks.",
1135
1237
  });
1136
1238
  }
1137
1239
  /** Build the full choice catalog. Every family appears, applicable or not. */
@@ -27,6 +27,7 @@ function compactChoice(choice) {
27
27
  ...(choice.excluded !== undefined ? { excluded: choice.excluded } : {}),
28
28
  ...(choice.invalid_existing !== undefined ? { invalid_existing: choice.invalid_existing } : {}),
29
29
  ...(choice.dependency_install !== undefined ? { dependency_install: choice.dependency_install } : {}),
30
+ ...(choice.test_commands !== undefined ? { test_commands: choice.test_commands } : {}),
30
31
  ...(choice.credential_references !== undefined ? { credential_references: choice.credential_references } : {}),
31
32
  };
32
33
  }
@@ -81,6 +82,7 @@ function selectedValue(decision) {
81
82
  case "profile":
82
83
  return "save";
83
84
  case "command":
85
+ case "commands":
84
86
  case "dependency_install_entries":
85
87
  return null;
86
88
  }