@bridge_gpt/mcp-server 0.2.72 → 0.2.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +15 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +30 -0
  6. package/build/ci-system-detection.js +50 -0
  7. package/build/ci-trigger-adapters.js +631 -0
  8. package/build/ci-trigger-install.js +106 -0
  9. package/build/codex-launcher-pin.js +33 -2
  10. package/build/codex-skill-adapter.js +3 -1
  11. package/build/command-host.js +33 -0
  12. package/build/command-provisioning.js +4 -3
  13. package/build/commands.generated.js +7 -6
  14. package/build/conductor/bridge-api-client.js +867 -35
  15. package/build/conductor/bring-up-facts.js +18 -5
  16. package/build/conductor/command-drift-production.js +42 -17
  17. package/build/conductor/command-drift.js +48 -1
  18. package/build/conductor/declare-blocked.js +554 -0
  19. package/build/conductor/declared-extras.js +335 -0
  20. package/build/conductor/doctor.js +108 -21
  21. package/build/conductor/driver-commands.js +141 -0
  22. package/build/conductor/driver-guard.js +277 -0
  23. package/build/conductor/driver-lapse.js +321 -0
  24. package/build/conductor/driver-pass-output.js +104 -0
  25. package/build/conductor/driver-pass.js +571 -0
  26. package/build/conductor/driver-register.js +176 -0
  27. package/build/conductor/driver-release.js +174 -0
  28. package/build/conductor/driver-session-state.js +315 -0
  29. package/build/conductor/epic-branch-ci-inspection.js +281 -43
  30. package/build/conductor/epic-implementer-cli.js +199 -15
  31. package/build/conductor/epic-server-database.js +162 -0
  32. package/build/conductor/epic-server-guidance.js +278 -0
  33. package/build/conductor/epic-server-journal.js +239 -0
  34. package/build/conductor/epic-server-processes.js +324 -0
  35. package/build/conductor/epic-server-recipe.js +397 -0
  36. package/build/conductor/epic-server-runtime.js +1207 -0
  37. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  38. package/build/conductor/epic-server-sfcc.js +85 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +647 -0
  41. package/build/conductor/gate-discovery.js +196 -11
  42. package/build/conductor/gate-settings-review.js +261 -4
  43. package/build/conductor/launch-need-probes.js +6 -53
  44. package/build/conductor/launch-plan.js +313 -156
  45. package/build/conductor/prerequisite-inputs.js +879 -45
  46. package/build/conductor/readiness-assessment.js +16 -1
  47. package/build/conductor/readiness-cli.js +20 -9
  48. package/build/conductor/readiness-prerequisites.js +28 -9
  49. package/build/conductor/readiness-sections.js +133 -126
  50. package/build/conductor/readiness.js +1 -1
  51. package/build/conductor/recovery-cli.js +13 -2
  52. package/build/conductor/tools.js +6 -5
  53. package/build/conductor/wait-run-attention.js +2 -2
  54. package/build/conductor/wait-run-cli.js +208 -22
  55. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  56. package/build/conductor/worker-setup-tally.js +27 -0
  57. package/build/credential-delivery.js +280 -0
  58. package/build/credential-launch-safety.js +142 -0
  59. package/build/credential-materialization.js +91 -16
  60. package/build/credential-references-node-deps.js +29 -0
  61. package/build/credential-references.js +1394 -0
  62. package/build/credential-references.test-fixtures.js +211 -0
  63. package/build/credential-scan-conventions.js +145 -0
  64. package/build/credential-scan.js +517 -0
  65. package/build/credential-store.js +121 -1
  66. package/build/credentials-cli.js +252 -3
  67. package/build/dependency-install-declarations.js +102 -1
  68. package/build/docs.generated.js +10 -3
  69. package/build/doctor.js +95 -3
  70. package/build/drive-epic-help.js +21 -2
  71. package/build/drive-epic.js +2095 -375
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +157 -0
  74. package/build/epic-capability-statement.js +175 -0
  75. package/build/epic-ci-workflow-drift.js +77 -23
  76. package/build/epic-ci-workflow-install.js +137 -44
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow-v3.js +273 -0
  79. package/build/epic-ci-workflow.js +165 -18
  80. package/build/epic-implementer-bin.js +2204 -56
  81. package/build/epic-launch-context.js +702 -0
  82. package/build/epic-server-record.js +288 -0
  83. package/build/epic-shared/bridge-client.js +11 -3
  84. package/build/escalation-reachability.js +43 -0
  85. package/build/executor/ci-fix-test-runs.js +334 -0
  86. package/build/executor/completion-contract.js +8 -1
  87. package/build/executor/credential-delivery-step.js +168 -0
  88. package/build/executor/deps.js +3 -1
  89. package/build/executor/env.js +98 -23
  90. package/build/executor/epic-server-context.js +157 -0
  91. package/build/executor/gate-qualification-job.js +127 -26
  92. package/build/executor/guarded-fast-forward-push.js +13 -8
  93. package/build/executor/http-client.js +52 -5
  94. package/build/executor/job-runner.js +577 -81
  95. package/build/executor/observation.js +8 -0
  96. package/build/executor/permissions.js +85 -3
  97. package/build/executor/pre-pr-checks.js +363 -0
  98. package/build/executor/prompt-spec.js +149 -3
  99. package/build/executor/reconcile-overlap-job.js +5 -3
  100. package/build/executor/required-work-diagnostics.js +4 -2
  101. package/build/executor/required-work-ledger.js +936 -38
  102. package/build/executor/results.js +58 -0
  103. package/build/executor/terminal-mutation.js +8 -0
  104. package/build/executor/worker-command.js +72 -3
  105. package/build/executor/worker-database-config.js +281 -0
  106. package/build/executor/worker-database-target.js +16 -12
  107. package/build/executor/worker-database.js +320 -101
  108. package/build/executor/worker-finalization.js +7 -1
  109. package/build/executor/worker-resources.js +25 -3
  110. package/build/executor/worker-verification-guidance.js +18 -3
  111. package/build/executor/worktree.js +20 -1
  112. package/build/executor-launch.js +58 -4
  113. package/build/generated-assets-catalog.js +2 -2
  114. package/build/git-exclude-lock.js +187 -0
  115. package/build/index.js +824 -366
  116. package/build/init.js +26 -11
  117. package/build/install-bridge-conductor-answers.js +528 -0
  118. package/build/install-bridge-conductor-apply.js +288 -0
  119. package/build/install-bridge-conductor-assessment.js +1222 -0
  120. package/build/install-bridge-conductor-compact.js +186 -0
  121. package/build/install-bridge-conductor-contracts.js +72 -0
  122. package/build/install-bridge-conductor-gate.js +1312 -198
  123. package/build/install-bridge-conductor-setup.js +577 -83
  124. package/build/install-bridge-conductor.js +3381 -544
  125. package/build/install-bridge.js +280 -25
  126. package/build/install-doctor.js +38 -8
  127. package/build/install-maintenance.js +26 -3
  128. package/build/install-sfcc-detection.js +120 -0
  129. package/build/install-sfcc-setup.js +185 -0
  130. package/build/launcher-config-inspection.js +162 -1
  131. package/build/mcp-grant-candidates.js +779 -0
  132. package/build/mcp-grant-doctor.js +63 -0
  133. package/build/mcp-grant.js +288 -0
  134. package/build/mcp-host-targets.js +8 -0
  135. package/build/mcp-identity.js +23 -0
  136. package/build/mcp-invoke.js +292 -15
  137. package/build/mcp-presets.js +107 -0
  138. package/build/mcp-provisioning.js +155 -6
  139. package/build/mcp-registration-doctor.js +31 -2
  140. package/build/mcp-server-invocation.js +19 -1
  141. package/build/merge-workflow-install.js +243 -110
  142. package/build/pipelines.generated.js +7 -6
  143. package/build/plan-discovery.js +97 -4
  144. package/build/plan-execution-ledger.js +100 -7
  145. package/build/plan-generation-io.js +262 -0
  146. package/build/plan-generation.js +424 -0
  147. package/build/plane/build-freshness.js +6 -1
  148. package/build/plane/cli.js +75 -9
  149. package/build/plane/plane-freshness.js +17 -0
  150. package/build/plane/preflight.js +50 -10
  151. package/build/plane/shutdown.js +19 -0
  152. package/build/plane/status.js +8 -2
  153. package/build/plane/terminal-run-cleanup.js +18 -4
  154. package/build/printed-remedy-commands.js +211 -12
  155. package/build/project-root.js +40 -0
  156. package/build/readiness-check.js +77 -0
  157. package/build/readiness-prerequisites.generated.js +122 -14
  158. package/build/readme.generated.js +1 -1
  159. package/build/repository-state-paths.js +41 -0
  160. package/build/repository-toolchains.js +6 -3
  161. package/build/run-unit-tests-launcher.js +8 -1
  162. package/build/setup-epic.js +1305 -210
  163. package/build/setup-progress.js +44 -0
  164. package/build/setup-question.js +122 -4
  165. package/build/sfcc/credentials.js +3 -2
  166. package/build/sfcc/hostname.js +98 -2
  167. package/build/sfcc/tool-wrapper.js +6 -95
  168. package/build/start-tickets.js +193 -29
  169. package/build/test-support/executor-source-files.js +200 -0
  170. package/build/testing-config-client.js +25 -2
  171. package/build/third-party-mcp-targets.js +63 -2
  172. package/build/ticket-delivery-enrollment.js +9 -0
  173. package/build/upgrade-cli.js +85 -2
  174. package/build/v2-readiness-requirements.js +28 -1
  175. package/build/version.generated.js +3 -3
  176. package/build/with-credentials.js +208 -0
  177. package/build/worktree-credential-delivery.js +340 -0
  178. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  179. package/docs/epic-implementer/getting-started.md +3 -1
  180. package/docs/epic-implementer/self-hosting.md +14 -1
  181. package/package.json +2 -2
@@ -802,7 +802,11 @@ export async function validateWorkerFinalization(input) {
802
802
  }
803
803
  }
804
804
  const hold = job.job_type === "ci_fix" ? null : confirmedDeliveryHold(deliveryOutcome, trimmedHeadSha, remoteSha);
805
- if (hold) {
805
+ // BAPI-1590: a hold with an attached PR at exactly the proven origin tip is not a
806
+ // dead end. Fall through to the unchanged PR contract and let the server judge the
807
+ // report; a missing PR or a different PR head keeps the hold failure.
808
+ const heldAtMatchingPr = hold !== null && observedPr !== undefined && observedPr.head_sha.toLowerCase() === remoteSha.toLowerCase();
809
+ if (hold && !heldAtMatchingPr) {
806
810
  return { ok: false, failure: deliveryHoldFailure(job, trimmedBranch, hold, observedPr) };
807
811
  }
808
812
  let contract = evaluatePrContract(pr, trimmedHeadSha, covered);
@@ -839,6 +843,8 @@ export async function validateWorkerFinalization(input) {
839
843
  prNumber: pr.prNumber,
840
844
  // Only when a fresh assessment was requested, so the legacy success shape is unchanged.
841
845
  ...(input.refreshDeliveryOutcome !== undefined && deliveryOutcome !== undefined ? { deliveryOutcome } : {}),
846
+ // BAPI-1590: only after the PR contract above succeeded for the hold let through.
847
+ ...(heldAtMatchingPr && hold ? { heldAtOpenPr: hold } : {}),
842
848
  // BAPI-1311: the verified origin tip — proven equal to the worker's HEAD above
843
849
  // whenever that HEAD was known. Only for a caller that asked for it.
844
850
  ...(input.exposePushedHead === true ? { pushedHeadSha: remoteSha } : {}),
@@ -19,6 +19,10 @@ import { resolveExecutorStateDir } from "./job-log-registry.js";
19
19
  import { hostIdentityDigest } from "./process-containment.js";
20
20
  import { createDefaultWorkerCliLauncherDeps, createWorkerCliLauncher, } from "./worker-cli-launcher.js";
21
21
  import { createDefaultWorkerDatabaseDeps, dropWorkerDatabase, provisionWorkerDatabase, sweepOrphanedWorkerDatabases, } from "./worker-database.js";
22
+ /** Retain reasons that mean an executor-owned database may still exist. */
23
+ const OWNED_RETAIN_REASONS = new Set([
24
+ "owner_alive", "owner_unknown", "ownership_changed", "drop_failed",
25
+ ]);
22
26
  /**
23
27
  * The production worker resources, bound to this executor process: its pid, its
24
28
  * host identity, its state directory, and the operator checkout it runs from
@@ -35,12 +39,13 @@ export function createProductionWorkerResources(input) {
35
39
  // Built lazily, once: constructing the deps touches nothing, but there is no
36
40
  // reason to do even that for an executor that never claims a worker job.
37
41
  let databaseDeps;
38
- const dbDeps = () => (databaseDeps ??= createDefaultWorkerDatabaseDeps({ stateDir, env: input.env }));
42
+ const dbDeps = () => (databaseDeps ??= input.databaseDeps ?? createDefaultWorkerDatabaseDeps({ stateDir, env: input.env }));
39
43
  let launcherDeps;
40
44
  const cliDeps = () => (launcherDeps ??= createDefaultWorkerCliLauncherDeps({ stateDir }));
41
45
  return {
42
46
  provisionDatabase: (request) => provisionWorkerDatabase({
43
47
  jobId: request.jobId,
48
+ config: request.config,
44
49
  operatorRepositoryRoot: input.cwd,
45
50
  worktreePath: request.worktreePath,
46
51
  executorPid,
@@ -51,8 +56,25 @@ export function createProductionWorkerResources(input) {
51
56
  ? { workerEnv: request.workerEnv }
52
57
  : {}),
53
58
  }, dbDeps()),
54
- dropDatabase: (target) => dropWorkerDatabase(target, dbDeps()),
59
+ dropDatabase: (target, role) => dropWorkerDatabase(target, dbDeps(), { role }),
55
60
  createLauncher: ({ jobId }) => createWorkerCliLauncher({ jobId }, cliDeps()),
56
- sweepOrphanedDatabases: (signal) => sweepOrphanedWorkerDatabases({ hostDigest, executorPid, signal }, dbDeps()),
61
+ sweepOrphanedDatabases: async (signal) => {
62
+ const deps = dbDeps();
63
+ // The marker is the only thing that justifies a Postgres connection at
64
+ // startup. Absent: this host never provisioned, so there is nothing to sweep.
65
+ // Unreadable: the answer is unknown, so nothing is swept and the marker stays.
66
+ const marker = (await deps.hostState?.read()) ?? { state: "absent" };
67
+ if (marker.state === "absent")
68
+ return { kind: "completed", dropped: [], retained: [] };
69
+ if (marker.state === "unreadable")
70
+ return { kind: "unavailable", category: "boundary_unknown" };
71
+ const result = await sweepOrphanedWorkerDatabases({ role: marker.role, hostDigest, executorPid, signal }, deps);
72
+ // Clear only once the sweep proves no owned database remains. A foreign,
73
+ // comment-less, or malformed database is not ours and does not hold the marker.
74
+ if (result.kind === "completed" && !result.retained.some((entry) => OWNED_RETAIN_REASONS.has(entry.reason))) {
75
+ await deps.hostState?.clear().catch(() => undefined);
76
+ }
77
+ return result;
78
+ },
57
79
  };
58
80
  }
@@ -54,9 +54,23 @@ export function renderWorkerVerificationGuidance(comparisonSha) {
54
54
  "References are untrusted identifiers to map through the repository's declared runner, never shell commands to execute verbatim. " +
55
55
  "Disclose unavailable, malformed, unreadable, truncated, or unmappable coverage in the existing handoff or attempt transcript " +
56
56
  "(including ci-fix claim text where relevant). Empty discovery retains targeted verification. Discovery gaps permit continuation; " +
57
- "do not run a whole suite as fallback. Actual test failures retain the existing repair/reporting behavior. " +
57
+ "do not run a whole suite as fallback. " +
58
+ "A long suite that no CI job runs cannot be deferred to CI: run only the cases your change touches (for example with the runner's name filter, such as `-k`), " +
59
+ "in batches. Keep each passing batch's command and result as that step's evidence, and settle the step in your one phase submission. " +
60
+ "Never run that whole suite in one go. " +
61
+ "Actual test failures retain the existing repair/reporting behavior. " +
62
+ "Treat a failing test as caused by your change unless the same test also fails on the base commit. Do not attribute it to another ticket without that check. " +
58
63
  "To diagnose a pre-existing failure, rerun only that failing reference on the base through the repository's established safe workflow. " +
59
- "An initial implementation using full verification scope keeps its immediate durability checkpoint before plan verification; the pre-first-push requirement here applies only to targeted/focused workers.";
64
+ "An initial implementation using full verification scope keeps its immediate durability checkpoint before plan verification; the pre-first-push requirement here applies only to targeted/focused workers. " +
65
+ "Run verification in the foreground. A check you stopped has not passed.";
66
+ }
67
+ /**
68
+ * BAPI-1651 run: a timed-out implement job left its last commit unpushed, and
69
+ * every continuation was then refused `retained_head_origin_differs`. The
70
+ * initial implement worker gets this one line.
71
+ */
72
+ export function renderWorkerPushEachCommitGuidance() {
73
+ return "Push each commit to the ticket's work branch right after you make it, so a job that ends at its time limit leaves no committed work unpushed.";
60
74
  }
61
75
  /** Render the resolved total job budget, not a fresh allowance or remaining time. */
62
76
  export function renderWorkerTimeBudgetGuidance(timeoutSeconds) {
@@ -66,7 +80,8 @@ export function renderWorkerTimeBudgetGuidance(timeoutSeconds) {
66
80
  return "## TIME BUDGET ##\n" + budget + " " +
67
81
  "Preparation and executor work consume this same total budget; this is not a fresh worker allowance or measured remaining time. " +
68
82
  "Local verification must leave room for commit, push, the single renewal pass, and `.conductor/result.json`. " +
69
- "Do not start a verification command that cannot finish within the remaining budget.";
83
+ "Do not start a verification command that cannot finish within the remaining budget. " +
84
+ "Prefer foreground verification. Stopping a task does not make its check pass.";
70
85
  }
71
86
  /**
72
87
  * BAPI-1533: the compact test-invocation rule a PUSHING continuation worker gets
@@ -62,7 +62,7 @@ export async function configureExecutorBranch(worktreePath, branch, deps) {
62
62
  (pushUrls.length === 1 && pushUrls[0] !== urls[0]))
63
63
  return failure;
64
64
  for (const [key, value] of [[`branch.${branch}.remote`, "origin"], [`branch.${branch}.merge`, `refs/heads/${branch}`]]) {
65
- if ((await deps.runCommand("git", ["config", "--local", key, value], { cwd: worktreePath })).exitCode !== 0)
65
+ if (!await writeLocalConfigWithLockRetry(worktreePath, key, value, deps))
66
66
  return failure;
67
67
  }
68
68
  return null;
@@ -71,6 +71,25 @@ export async function configureExecutorBranch(worktreePath, branch, deps) {
71
71
  return failure;
72
72
  }
73
73
  }
74
+ /** Total attempts for one `git config --local` write that hits git's config lock. */
75
+ export const CONFIG_LOCK_WRITE_ATTEMPTS = 4;
76
+ /**
77
+ * Write one local config value. Executors that claim jobs in the same second
78
+ * share one `.git/config`, so git can refuse a write with "could not lock config
79
+ * file". Only that failure is retried, a bounded number of times, after a short
80
+ * random delay. Any other failure returns false at once.
81
+ */
82
+ async function writeLocalConfigWithLockRetry(worktreePath, key, value, deps) {
83
+ for (let attempt = 1;; attempt += 1) {
84
+ const result = await deps.runCommand("git", ["config", "--local", key, value], { cwd: worktreePath });
85
+ if (result.exitCode === 0)
86
+ return true;
87
+ const lockFailure = /could not lock config file/i.test(result.stderr ?? "");
88
+ if (!lockFailure || attempt >= CONFIG_LOCK_WRITE_ATTEMPTS)
89
+ return false;
90
+ await deps.sleep(50 + Math.floor(Math.random() * 200));
91
+ }
92
+ }
74
93
  /**
75
94
  * BAPI-941: emit the per-spawn `claude-review` workflow-drift advisory for an
76
95
  * executor worker. Returns `void` and swallows everything — a diagnostic that
@@ -43,6 +43,7 @@
43
43
  * that executor instance's own heartbeat is fresh. Anything short of that and
44
44
  * uncertain is refused rather than signalled or duplicated.
45
45
  */
46
+ import { PARALLEL_LIMIT_CHANGE_ADVISORY } from "./conductor/launch-plan.js";
46
47
  import { spawn as nodeSpawn } from "node:child_process";
47
48
  import { mkdir, open, readFile, stat, unlink } from "node:fs/promises";
48
49
  import os from "node:os";
@@ -50,7 +51,7 @@ import path from "node:path";
50
51
  import { LOCAL_MERGE_CREDENTIAL_ENV_KEYS, } from "./conductor/merge-credential.js";
51
52
  import { shellQuote } from "./epic-launch-profile.js";
52
53
  import { isValidExecutorEpicRunId } from "./executor/claim-scope.js";
53
- import { ensureGitInfoExcluded } from "./git-ignore-utils.js";
54
+ import { ensureGitInfoExcludedSerialized } from "./git-exclude-lock.js";
54
55
  import { createPlaneExecFile, createPlaneProcessDeps, probeAutomationHealth, resolvePackageEntrypoint, } from "./plane/defaults.js";
55
56
  import { buildPlaneRedactor } from "./plane/supervisor.js";
56
57
  /** Directory, relative to the Git top level, holding every launcher file. */
@@ -150,7 +151,9 @@ export function createDefaultRunExecutorLaunchDeps() {
150
151
  return null;
151
152
  }
152
153
  },
153
- ensureIgnored: (repoRoot) => ensureGitInfoExcluded(repoRoot, RUN_EXECUTOR_IGNORE_ENTRY, {
154
+ ensureIgnored: (repoRoot) =>
155
+ // BAPI-1647: serialized with every other Bridge exclude writer.
156
+ ensureGitInfoExcludedSerialized(repoRoot, RUN_EXECUTOR_IGNORE_ENTRY, {
154
157
  readFile: (filePath) => readFile(filePath, "utf-8"),
155
158
  writeFile: async (filePath, data) => {
156
159
  const handle = await open(filePath, "w");
@@ -228,6 +231,9 @@ export function runExecutorArgs(args) {
228
231
  "--executor-id",
229
232
  args.executorId,
230
233
  "--exit-when-run-terminal",
234
+ ...(args.maxConcurrent !== undefined && args.maxConcurrent > 1
235
+ ? ["--max-concurrent", String(args.maxConcurrent)]
236
+ : []),
231
237
  ];
232
238
  }
233
239
  /**
@@ -289,6 +295,15 @@ export function parseRunExecutorRecord(raw) {
289
295
  }
290
296
  if (!isValidExecutorEpicRunId(r.epicRunId))
291
297
  return null;
298
+ // BAPI-1581 — absent reads as 1; a present value must be the positive integer
299
+ // the executor's own `--max-concurrent` accepts, else the record is untrusted.
300
+ let maxConcurrent = 1;
301
+ if (r.maxConcurrent !== undefined) {
302
+ if (typeof r.maxConcurrent !== "number" || !Number.isInteger(r.maxConcurrent) || r.maxConcurrent < 1) {
303
+ return null;
304
+ }
305
+ maxConcurrent = r.maxConcurrent;
306
+ }
292
307
  return {
293
308
  version: RUN_EXECUTOR_RECORD_VERSION,
294
309
  pid: r.pid,
@@ -297,8 +312,25 @@ export function parseRunExecutorRecord(raw) {
297
312
  baseUrl: r.baseUrl,
298
313
  startedAt: r.startedAt,
299
314
  logPath: r.logPath,
315
+ maxConcurrent,
300
316
  };
301
317
  }
318
+ /**
319
+ * BAPI-1581 — explain a reused executor whose capacity differs from the run's
320
+ * stored limit. Returns `undefined` when they match or no limit was requested.
321
+ * Never an action: a running executor is not stopped, resized, or restarted.
322
+ */
323
+ export function describeReusedExecutorCapacity(actual, requested) {
324
+ if (requested === undefined || requested === actual)
325
+ return undefined;
326
+ if (actual < requested) {
327
+ return (`The reused executor serves ${actual} job${actual === 1 ? "" : "s"} at a time while the run limit is ` +
328
+ `${requested}. ${PARALLEL_LIMIT_CHANGE_ADVISORY} To get higher local capacity, stop this executor ` +
329
+ "and run drive-epic again.");
330
+ }
331
+ return (`The reused executor can serve ${actual} jobs at a time while the run limit is ${requested}; ` +
332
+ "the queue admits only the run limit, so the extra slots stay idle.");
333
+ }
302
334
  /**
303
335
  * Is the recorded pid still THIS executor?
304
336
  *
@@ -497,6 +529,7 @@ export async function ensureRunExecutor(args, deps) {
497
529
  epicRunId,
498
530
  baseUrl: access.baseUrl,
499
531
  executorId,
532
+ ...(args.maxConcurrent !== undefined ? { maxConcurrent: args.maxConcurrent } : {}),
500
533
  });
501
534
  const fail = (reason, message, executorMayBeRunning = false) => ({
502
535
  ok: false,
@@ -563,6 +596,10 @@ export async function ensureRunExecutor(args, deps) {
563
596
  pid: existing.pid,
564
597
  logPath: existing.logPath,
565
598
  recordPath: paths.record,
599
+ ...((existing.maxConcurrent ?? 1) > 1 ? { maxConcurrent: existing.maxConcurrent } : {}),
600
+ ...(describeReusedExecutorCapacity(existing.maxConcurrent ?? 1, args.maxConcurrent) !== undefined
601
+ ? { capacityNotice: describeReusedExecutorCapacity(existing.maxConcurrent ?? 1, args.maxConcurrent) }
602
+ : {}),
566
603
  };
567
604
  }
568
605
  return fail("existing-executor-unconfirmed", `an executor for run ${epicRunId} is already running (pid ${existing.pid}), but its ` +
@@ -606,7 +643,13 @@ export async function ensureRunExecutor(args, deps) {
606
643
  paths.log,
607
644
  deps.nodeExecutable,
608
645
  prepared.entrypoint,
609
- ...runExecutorArgs({ repoName, epicRunId, baseUrl: access.baseUrl, executorId }),
646
+ ...runExecutorArgs({
647
+ repoName,
648
+ epicRunId,
649
+ baseUrl: access.baseUrl,
650
+ executorId,
651
+ ...(args.maxConcurrent !== undefined ? { maxConcurrent: args.maxConcurrent } : {}),
652
+ }),
610
653
  ], { cwd: prepared.repoRoot, env: childEnv, detached: true });
611
654
  }
612
655
  catch {
@@ -627,6 +670,9 @@ export async function ensureRunExecutor(args, deps) {
627
670
  baseUrl: access.baseUrl,
628
671
  startedAt: new Date(spawnedAtMs).toISOString(),
629
672
  logPath: paths.log,
673
+ // BAPI-1581 — the actual capacity of the process just spawned; omitted at 1,
674
+ // which an absent key already means, so a legacy record stays byte-identical.
675
+ ...(args.maxConcurrent !== undefined && args.maxConcurrent > 1 ? { maxConcurrent: args.maxConcurrent } : {}),
630
676
  };
631
677
  try {
632
678
  await deps.writeFile(paths.record, `${JSON.stringify(record, null, 2)}\n`);
@@ -651,7 +697,15 @@ export async function ensureRunExecutor(args, deps) {
651
697
  ? `the executor (pid ${pid}) exited before it sent a heartbeat`
652
698
  : `no heartbeat from the executor (pid ${pid}) arrived within ${timeoutSeconds}s`, !exited);
653
699
  }
654
- return { ok: true, outcome: "started", executorId, pid, logPath: paths.log, recordPath: paths.record };
700
+ return {
701
+ ok: true,
702
+ outcome: "started",
703
+ executorId,
704
+ pid,
705
+ logPath: paths.log,
706
+ recordPath: paths.record,
707
+ ...((record.maxConcurrent ?? 1) > 1 ? { maxConcurrent: record.maxConcurrent } : {}),
708
+ };
655
709
  }
656
710
  finally {
657
711
  try {
@@ -1,7 +1,7 @@
1
1
  import { COMMANDS } from "./commands.generated.js";
2
2
  import { AGENTS } from "./agents.generated.js";
3
3
  import { DOCS, DOC_METADATA } from "./docs.generated.js";
4
- import { renderCommandForHost } from "./command-host.js";
4
+ import { renderCommandForHost, stripClaudeOnlyFrontmatter } from "./command-host.js";
5
5
  import { codexSkillAssets } from "./codex-skill-adapter.js";
6
6
  import { reconstructAgentMarkdown, translateAgentToCopilot, translateCommandToCopilot } from "./agent-utils.js";
7
7
  export const WORKFLOW_HOSTS = ["claude", "cursor", "codex", "copilot"];
@@ -23,7 +23,7 @@ export function buildPackagedAssetCatalog() {
23
23
  try {
24
24
  add(`.claude/commands/${filename}`, renderCommandForHost(filename, content, "claude-code"), "command", ["claude"], [workflow]);
25
25
  add(`.cursor/commands/${filename}`, renderCommandForHost(filename, content, "cursor"), "command", ["cursor"], [workflow]);
26
- const copilot = translateCommandToCopilot(filename, content);
26
+ const copilot = translateCommandToCopilot(filename, stripClaudeOnlyFrontmatter(content));
27
27
  add(`.github/prompts/${workflow}.prompt.md`, copilot.prompt, "prompt", ["copilot"], [workflow]);
28
28
  add(`.github/skills/${workflow}/SKILL.md`, copilot.skill, "skill", ["copilot"], [workflow]);
29
29
  }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * BAPI-1647: a bounded cross-process lock for Bridge's writes to a checkout's
3
+ * `info/exclude`.
4
+ *
5
+ * `ensureGitInfoExcluded()` (`git-ignore-utils.ts`) and the executor's
6
+ * `provisionWorktreeSettingsExclude()` (`executor/permissions.ts`) are both
7
+ * read-then-write. Linked worktrees of one repository share ONE common
8
+ * `info/exclude`, so two launches preparing two worktrees at the same moment
9
+ * could each read the file, each append their own line, and the second rename or
10
+ * write would drop the first line. Every Bridge writer therefore takes this lock
11
+ * around its whole read-modify-write and re-reads inside it.
12
+ *
13
+ * The lock is keyed on the CANONICAL exclude pathname (its directory resolved
14
+ * through `realpath`), never the worktree path: two worktrees resolve to the
15
+ * same key exactly when they share an exclude file. The lock file sits beside
16
+ * the exclude file (`exclude.bridge-lock`), created with `open(..., "wx")`, and
17
+ * only its owner removes it. A lock older than {@link STALE_LOCK_MS} is treated
18
+ * as abandoned (a crashed writer) and removed once; the critical section is a
19
+ * few milliseconds, so a live owner never gets near that age.
20
+ *
21
+ * Failure outcomes are fixed text: no path, no errno, no exception message.
22
+ */
23
+ import { mkdir as fsMkdir, open as fsOpen, realpath as fsRealpath, stat as fsStat, unlink as fsUnlink } from "fs/promises";
24
+ import path from "path";
25
+ import { ensureGitInfoExcluded } from "./git-ignore-utils.js";
26
+ /** How long a contended writer waits before giving up. */
27
+ export const EXCLUDE_LOCK_TIMEOUT_MS = 10_000;
28
+ /** Poll interval while waiting. */
29
+ export const EXCLUDE_LOCK_POLL_MS = 25;
30
+ /** A lock file older than this is an abandoned lock from a crashed writer. */
31
+ export const STALE_LOCK_MS = 60_000;
32
+ /** Lock file name beside the exclude file. */
33
+ export const EXCLUDE_LOCK_FILE_NAME = "exclude.bridge-lock";
34
+ export function defaultExcludeLockDeps() {
35
+ return {
36
+ open: (p, flags, mode) => fsOpen(p, flags, mode),
37
+ unlink: (p) => fsUnlink(p),
38
+ mkdir: (p, o) => fsMkdir(p, o),
39
+ realpath: (p) => fsRealpath(p),
40
+ mtimeMs: async (p) => (await fsStat(p)).mtimeMs,
41
+ now: () => Date.now(),
42
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
43
+ };
44
+ }
45
+ function errnoCode(err) {
46
+ return err && typeof err === "object" ? err.code : undefined;
47
+ }
48
+ /**
49
+ * The lock key: the exclude file's directory resolved through `realpath`, joined
50
+ * with the file name. The directory is created first so it can be resolved.
51
+ */
52
+ export async function canonicalExcludePath(excludePath, deps) {
53
+ const dir = path.dirname(excludePath);
54
+ await deps.mkdir(dir, { recursive: true });
55
+ const realDir = await deps.realpath(dir);
56
+ return path.join(realDir, path.basename(excludePath));
57
+ }
58
+ /** Acquire the lock for one resolved exclude path. */
59
+ export async function acquireExcludeLock(excludePath, deps = defaultExcludeLockDeps()) {
60
+ let lockPath;
61
+ try {
62
+ const canonical = await canonicalExcludePath(excludePath, deps);
63
+ lockPath = path.join(path.dirname(canonical), EXCLUDE_LOCK_FILE_NAME);
64
+ }
65
+ catch {
66
+ return { ok: false, reason: "lock_unavailable" };
67
+ }
68
+ let released = false;
69
+ const release = async () => {
70
+ if (released)
71
+ return;
72
+ released = true;
73
+ try {
74
+ await deps.unlink(lockPath);
75
+ }
76
+ catch {
77
+ /* a lock that is already gone never fails the caller */
78
+ }
79
+ };
80
+ const deadline = deps.now() + (deps.timeoutMs ?? EXCLUDE_LOCK_TIMEOUT_MS);
81
+ let staleChecked = false;
82
+ for (;;) {
83
+ try {
84
+ const handle = await deps.open(lockPath, "wx", 0o600);
85
+ await handle.close();
86
+ return { ok: true, release };
87
+ }
88
+ catch (err) {
89
+ if (errnoCode(err) !== "EEXIST")
90
+ return { ok: false, reason: "lock_unavailable" };
91
+ }
92
+ if (!staleChecked) {
93
+ staleChecked = true;
94
+ try {
95
+ const age = deps.now() - (await deps.mtimeMs(lockPath));
96
+ if (age > STALE_LOCK_MS) {
97
+ await deps.unlink(lockPath);
98
+ continue;
99
+ }
100
+ }
101
+ catch {
102
+ /* vanished or unreadable: retry normally */
103
+ }
104
+ }
105
+ if (deps.now() >= deadline)
106
+ return { ok: false, reason: "lock_timeout" };
107
+ await deps.sleep(EXCLUDE_LOCK_POLL_MS);
108
+ }
109
+ }
110
+ /** Run `fn` while holding the lock for `excludePath`. */
111
+ export async function withExcludeLock(excludePath, fn, deps = defaultExcludeLockDeps()) {
112
+ const lock = await acquireExcludeLock(excludePath, deps);
113
+ if (!lock.ok)
114
+ return lock;
115
+ try {
116
+ return { ok: true, value: await fn() };
117
+ }
118
+ finally {
119
+ await lock.release();
120
+ }
121
+ }
122
+ /**
123
+ * Resolve the exclude path the same way `ensureGitInfoExcluded()` does: through
124
+ * `git rev-parse --git-path info/exclude` when `runCommand` and `platform` are
125
+ * supplied (linked worktrees resolve to the common directory), else the legacy
126
+ * `<root>/.git/info/exclude` join. `git-ignore-utils.ts` keeps its resolver
127
+ * private, so this mirrors it rather than editing that file.
128
+ */
129
+ export async function resolveExcludePathForLock(worktreeRoot, deps) {
130
+ if (deps.runCommand && deps.platform) {
131
+ const api = deps.platform === "win32" ? path.win32 : path.posix;
132
+ const result = await deps.runCommand("git", ["rev-parse", "--git-path", "info/exclude"], { cwd: worktreeRoot });
133
+ if (result.exitCode !== 0 || result.stdout.trim().length === 0) {
134
+ throw new Error("Failed to resolve the worktree info/exclude path.");
135
+ }
136
+ const raw = result.stdout.trim();
137
+ return api.isAbsolute(raw) ? api.normalize(raw) : api.resolve(worktreeRoot, raw);
138
+ }
139
+ return path.join(worktreeRoot, ".git", "info", "exclude");
140
+ }
141
+ /**
142
+ * `ensureGitInfoExcluded()` inside the exclude lock, re-reading the file inside
143
+ * the critical section (the wrapped call reads first). Never throws.
144
+ */
145
+ export async function ensureGitInfoExcludedLocked(worktreeRoot, relativePath, deps, lockDeps = defaultExcludeLockDeps()) {
146
+ let excludePath;
147
+ try {
148
+ excludePath = await resolveExcludePathForLock(worktreeRoot, deps);
149
+ }
150
+ catch {
151
+ return { ok: false, reason: "exclude_failed" };
152
+ }
153
+ try {
154
+ const locked = await withExcludeLock(excludePath, () => ensureGitInfoExcluded(worktreeRoot, relativePath, deps), lockDeps);
155
+ return locked.ok ? { ok: true } : locked;
156
+ }
157
+ catch {
158
+ return { ok: false, reason: "exclude_failed" };
159
+ }
160
+ }
161
+ /**
162
+ * For the pre-existing writers whose contract predates the lock: hold the lock
163
+ * when it can be had, and otherwise fall back to the unlocked write they always
164
+ * did, so a lock problem never changes their established outcome. Errors from
165
+ * the write itself propagate exactly as before.
166
+ */
167
+ export async function ensureGitInfoExcludedSerialized(worktreeRoot, relativePath, deps, lockDeps = defaultExcludeLockDeps()) {
168
+ let excludePath;
169
+ try {
170
+ excludePath = await resolveExcludePathForLock(worktreeRoot, deps);
171
+ }
172
+ catch {
173
+ excludePath = undefined;
174
+ }
175
+ if (excludePath === undefined) {
176
+ await ensureGitInfoExcluded(worktreeRoot, relativePath, deps);
177
+ return;
178
+ }
179
+ const lock = await acquireExcludeLock(excludePath, lockDeps);
180
+ try {
181
+ await ensureGitInfoExcluded(worktreeRoot, relativePath, deps);
182
+ }
183
+ finally {
184
+ if (lock.ok)
185
+ await lock.release();
186
+ }
187
+ }