@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
@@ -199,6 +199,13 @@ async function confirmExecutorJob(deps, store, ticketKey, registrationKey, bindi
199
199
  return { binding, replaced: false };
200
200
  }
201
201
  }
202
+ /** Non-empty string warnings from an optional server field; anything else is ignored. */
203
+ function readWarnings(value) {
204
+ if (!Array.isArray(value))
205
+ return undefined;
206
+ const warnings = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
207
+ return warnings.length > 0 ? warnings : undefined;
208
+ }
202
209
  /**
203
210
  * Send every pending batch, oldest first. Never throws.
204
211
  *
@@ -242,6 +249,7 @@ export async function syncPendingSubmissions(deps, ticketKey, binding) {
242
249
  const body = response.body;
243
250
  if (body.readiness)
244
251
  readiness = body.readiness;
252
+ const warnings = readWarnings(body.warnings);
245
253
  const report = {
246
254
  submission_id: entry.submission_id,
247
255
  phase: entry.phase,
@@ -249,6 +257,7 @@ export async function syncPendingSubmissions(deps, ticketKey, binding) {
249
257
  retryable: body.retryable === true,
250
258
  refusals: Array.isArray(body.refusals) ? body.refusals : [],
251
259
  ...(body.recovery_guidance ? { recovery_guidance: body.recovery_guidance } : {}),
260
+ ...(warnings ? { warnings } : {}),
252
261
  };
253
262
  reports.push(report);
254
263
  if (report.retryable)
@@ -324,6 +324,8 @@ export function formatDryRunLine(found) {
324
324
  return ` ${relPath}: would create with ${MCP_PACKAGE_NAME}@${targetVersion}`;
325
325
  case "skip-worktree-shim":
326
326
  return ` ${relPath}: skipped — worktree mcp-invoke shim (no published-package pin applies)`;
327
+ case "skip-local-build":
328
+ return ` ${relPath}: skipped — local build preserved (no published-package pin applies)`;
327
329
  case "skip-inactive":
328
330
  return null; // Absent config for an inactive IDE — not worth a line.
329
331
  default:
@@ -346,6 +348,8 @@ export function formatResultLine(action) {
346
348
  return ` ${relPath}: created with ${MCP_PACKAGE_NAME}@${action.toVersion}`;
347
349
  case "skipped-worktree-shim":
348
350
  return ` ${relPath}: skipped — worktree mcp-invoke shim preserved`;
351
+ case "skipped-local-build":
352
+ return ` ${relPath}: skipped — local build preserved`;
349
353
  case "skipped-ahead":
350
354
  // Defensive: upgrade blocks on an ahead pin during preflight, so this is
351
355
  // only reachable if a config changed underneath the run.
@@ -363,6 +367,7 @@ export function formatResultLine(action) {
363
367
  */
364
368
  export function isEveryLauncherAlreadyCurrent(actions) {
365
369
  const applicable = actions.filter((a) => a.kind !== "skipped-worktree-shim" &&
370
+ a.kind !== "skipped-local-build" &&
366
371
  a.kind !== "skipped-inactive" &&
367
372
  a.kind !== "skipped-ahead");
368
373
  if (applicable.length === 0)
@@ -419,6 +424,8 @@ function globalResultAction(initial, targetVersion) {
419
424
  return { relPath, kind: "already-current", registrationKey, toVersion: targetVersion };
420
425
  case "skip-worktree-shim":
421
426
  return { relPath, kind: "skipped-worktree-shim", registrationKey };
427
+ case "skip-local-build":
428
+ return { relPath, kind: "skipped-local-build", registrationKey };
422
429
  default:
423
430
  return null;
424
431
  }
@@ -518,6 +525,12 @@ async function verifyCodexConfig(deps, env, snapshot, targetVersion, expected) {
518
525
  ? { inspection: found, failures: [] }
519
526
  : fail("a worktree shim was expected to be preserved but no longer looks like one");
520
527
  }
528
+ if (initial.action === "skip-local-build") {
529
+ // BAPI-1636: never spliced, so the file must read back byte-identical.
530
+ return found.action === "skip-local-build" && after.source === snapshot.source
531
+ ? { inspection: found, failures: [] }
532
+ : fail("a local build was expected to be preserved but no longer looks the same");
533
+ }
521
534
  if (found.action !== "already-current" || found.currentVersion !== targetVersion) {
522
535
  return fail(`expected ${MCP_PACKAGE_NAME}@${targetVersion} after the write`);
523
536
  }
@@ -572,11 +585,19 @@ export async function runUpgradeCli(argv, injected) {
572
585
  // ---- Phase 2: read-only launcher preflight, before ANY side effect ----
573
586
  const isCreatable = deps.isCreatable ?? ((relPath) => relPath === ".mcp.json");
574
587
  let inspections;
588
+ // BAPI-1636: the exact text each project config held, kept privately so a
589
+ // preserved local build can be proven byte-identical after the writes and its
590
+ // backing install found. Never reported.
591
+ const projectSources = new Map();
575
592
  try {
576
593
  inspections = await inspectLauncherConfigs({
577
594
  cwd: deps.cwd,
578
595
  targetVersion: target.version,
579
- readFile: deps.readFile,
596
+ readFile: async (filePath) => {
597
+ const text = await deps.readFile(filePath);
598
+ projectSources.set(filePath, text);
599
+ return text;
600
+ },
580
601
  isCreatable,
581
602
  targets: LAUNCHER_CONFIG_TARGETS,
582
603
  });
@@ -654,7 +675,14 @@ export async function runUpgradeCli(argv, injected) {
654
675
  return 0;
655
676
  }
656
677
  // ---- Phase 4: competing local install — a reconciliation, not a transition ----
657
- if (await deps.hasCompetingLocalInstall(deps.cwd)) {
678
+ // BAPI-1636: an install that a preserved local-build launcher runs from is
679
+ // never removed; removing it would break the registration this run keeps.
680
+ const localBuildEntries = localBuildEntryPoints(deps.cwd, inspections, projectSources, codexSnapshot);
681
+ const localInstallDir = path.join(deps.cwd, "node_modules", MCP_PACKAGE_NAME);
682
+ if (localBuildEntries.some((entry) => isPathInside(localInstallDir, entry))) {
683
+ stdout(`Kept node_modules/${MCP_PACKAGE_NAME}: a preserved local-build launcher runs from it.`);
684
+ }
685
+ else if (await deps.hasCompetingLocalInstall(deps.cwd)) {
658
686
  stdout("Found a competing local installation in node_modules. Removing so npx resolves the pinned version...");
659
687
  const removed = await deps.removeCompetingLocalInstall(deps.cwd);
660
688
  if (!removed) {
@@ -724,6 +752,7 @@ export async function runUpgradeCli(argv, injected) {
724
752
  const verificationFailures = [];
725
753
  for (const action of initResult.configActions) {
726
754
  if (action.kind === "skipped-worktree-shim" ||
755
+ action.kind === "skipped-local-build" ||
727
756
  action.kind === "skipped-inactive" ||
728
757
  action.kind === "skipped-ahead") {
729
758
  // Assert the shim really was left alone rather than quietly rewritten.
@@ -731,6 +760,20 @@ export async function runUpgradeCli(argv, injected) {
731
760
  if (action.kind === "skipped-worktree-shim" && after?.action !== "skip-worktree-shim") {
732
761
  verificationFailures.push(`${action.relPath}: a worktree shim was expected to be preserved but no longer looks like one`);
733
762
  }
763
+ // BAPI-1636: a local build is proven by its bytes, re-read after every write.
764
+ if (action.kind === "skipped-local-build") {
765
+ const fullPath = path.join(deps.cwd, action.relPath);
766
+ let current = null;
767
+ try {
768
+ current = await deps.readFile(fullPath);
769
+ }
770
+ catch {
771
+ current = null;
772
+ }
773
+ if (after?.action !== "skip-local-build" || current === null || current !== projectSources.get(fullPath)) {
774
+ verificationFailures.push(`${action.relPath}: a local build was expected to be preserved but no longer looks the same`);
775
+ }
776
+ }
734
777
  continue;
735
778
  }
736
779
  const after = verifiedByPath.get(action.relPath);
@@ -862,6 +905,43 @@ export async function runUpgradeCli(argv, injected) {
862
905
  }
863
906
  return 0;
864
907
  }
908
+ /**
909
+ * BAPI-1636: the entry-point paths of every preserved local-build launcher,
910
+ * project and Codex, read from the text Phase 2 already captured. Private: the
911
+ * paths decide Phase 4 cleanup and are never printed.
912
+ */
913
+ function localBuildEntryPoints(cwd, inspections, projectSources, codex) {
914
+ const entries = [];
915
+ for (const found of inspections) {
916
+ if (found.action !== "skip-local-build" || found.registrationKey === null)
917
+ continue;
918
+ try {
919
+ const parsed = JSON.parse(projectSources.get(path.join(cwd, found.relPath)) ?? "");
920
+ const first = parsed?.[found.topLevelKey]?.[found.registrationKey]?.args?.[0];
921
+ if (typeof first === "string")
922
+ entries.push(first);
923
+ }
924
+ catch {
925
+ // Unreadable now means unknown: nothing is added, so cleanup is unchanged.
926
+ }
927
+ }
928
+ if (codex.inspection.action === "skip-local-build" && codex.source !== null) {
929
+ const found = inspectCodexLauncher(codex.source);
930
+ if (found.kind === "local-build" && typeof found.args[0] === "string")
931
+ entries.push(found.args[0]);
932
+ }
933
+ return entries;
934
+ }
935
+ /**
936
+ * True when `candidate` lies inside `dir`, by path containment rather than a
937
+ * string prefix (`.../mcp-server-old` is not inside `.../mcp-server`). The POSIX
938
+ * or Windows rules follow the candidate's own form.
939
+ */
940
+ function isPathInside(dir, candidate) {
941
+ const paths = candidate.startsWith("/") ? path.posix : path.win32;
942
+ const relative = paths.relative(dir, candidate);
943
+ return relative.length > 0 && !relative.startsWith("..") && !paths.isAbsolute(relative);
944
+ }
865
945
  /** Planned actions that change a configuration and so warrant reload guidance. */
866
946
  const PLANNED_CHANGE_ACTIONS = new Set([
867
947
  "repin",
@@ -935,6 +1015,9 @@ function toPlannedActions(inspections) {
935
1015
  case "skip-worktree-shim":
936
1016
  actions.push({ relPath: found.relPath, kind: "skipped-worktree-shim" });
937
1017
  break;
1018
+ case "skip-local-build":
1019
+ actions.push({ relPath: found.relPath, kind: "skipped-local-build" });
1020
+ break;
938
1021
  case "skip-inactive":
939
1022
  actions.push({ relPath: found.relPath, kind: "skipped-inactive" });
940
1023
  break;
@@ -164,7 +164,11 @@ const LEGACY_V2_READINESS_REQUIREMENTS = [
164
164
  // with child 4, once a repository can actually satisfy it.
165
165
  ];
166
166
  /** The three additive outcomes are authoritative; absent or unknown never denies. */
167
- const NEW_IDS = ['server.indexed-workflows', 'server.unattended-notify-default', 'server.test-command'];
167
+ const LAUNCH_ONLY_BLOCKING_IDS = [
168
+ { id: 'server.escalation-webhook-reachable', unattendedOnly: true },
169
+ { id: 'server.provider-default-branch-readable', unattendedOnly: false },
170
+ ];
171
+ const NEW_IDS = ['server.indexed-workflows', 'server.unattended-notify-default'];
168
172
  export const V2_READINESS_REQUIREMENTS = [
169
173
  ...LEGACY_V2_READINESS_REQUIREMENTS.map(req => {
170
174
  const id = READINESS_LEGACY_IDS[req.id] ?? req.id;
@@ -183,6 +187,17 @@ export const V2_READINESS_REQUIREMENTS = [
183
187
  satisfied: (r) => !r.prerequisites?.some(p => p.id === id && p.check_status === 'not_met' && p.impact === 'blocking'),
184
188
  remedyFor: (r) => r.prerequisites?.find(p => p.id === id)?.fix ?? 'Retry readiness.',
185
189
  })),
190
+ // BAPI-1585 — two launch checks the server evaluates only on a launch path. The
191
+ // webhook row is unattended-only (it is not_applicable otherwise). The provider
192
+ // read applies to every launch, attended included, so it carries no marker. The
193
+ // integration-branch note is deliberately absent: it is a warning, rendered from
194
+ // the generic prerequisite list, and never gates.
195
+ ...LAUNCH_ONLY_BLOCKING_IDS.map(({ id, unattendedOnly }) => ({
196
+ id, describe: READINESS_PREREQUISITE_BY_ID.get(id).label, governedRowIds: [id], launchOnly: true,
197
+ ...(unattendedOnly ? { unattendedOnly: true } : {}),
198
+ satisfied: (r) => !r.prerequisites?.some(p => p.id === id && p.check_status === 'not_met' && p.impact === 'blocking'),
199
+ remedyFor: (r) => r.prerequisites?.find(p => p.id === id)?.fix ?? 'Retry readiness.',
200
+ })),
186
201
  ];
187
202
  // ---------------------------------------------------------------------------
188
203
  // BAPI-1452: launch capability evidence
@@ -509,6 +524,18 @@ export function buildLaunchReadinessChecks(readiness, context) {
509
524
  providerRepositoryCheck(readiness),
510
525
  ], context);
511
526
  }
527
+ /**
528
+ * BAPI-1595 — only the two launch-evidence rows (merge credential, worktree), for a
529
+ * launch that holds the local evidence but no full readiness report. The rows are
530
+ * built by the same functions {@link buildLaunchReadinessChecks} uses, so their
531
+ * wording and blocking projection cannot drift from it.
532
+ */
533
+ export function buildLaunchEvidenceChecks(context, evidence) {
534
+ const used = optedOut(context) ? undefined : evidence;
535
+ return projectReadinessRowBlocking([credentialCheck(used?.credential ?? null), worktreeCheck(used?.worktree ?? null)],
536
+ // The launch-evidence requirements apply by the evidence itself, as in {@link buildLaunchReadinessChecks}.
537
+ { ...context, launchEvidence: evidence });
538
+ }
512
539
  /** The two launch-evidence rows a launch can be refused on. */
513
540
  export const LAUNCH_EVIDENCE_ROW_IDS = [
514
541
  MERGE_CREDENTIAL_CAPABILITY_ROW_ID,
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED — do not edit manually. Regenerate with: npm run build
2
- export const VERSION = "0.2.72";
3
- export const BUILD_COMMIT = "bfa72f4a97cf";
4
- export const LAUNCHER_ARGS = ["-y", "--prefer-offline", "@bridge_gpt/mcp-server@0.2.72", "serve"];
2
+ export const VERSION = "0.2.74";
3
+ export const BUILD_COMMIT = "0d017bd07c69";
4
+ export const LAUNCHER_ARGS = ["-y", "--prefer-offline", "@bridge_gpt/mcp-server@0.2.74", "serve"];
@@ -0,0 +1,208 @@
1
+ /**
2
+ * BAPI-1647: `with-credentials --repo <repo> -- <agent argv>` — an internal
3
+ * subcommand that `start-tickets` puts in front of the agent in each tab.
4
+ *
5
+ * It resolves the repository's approved SANDBOX shell variables through child
6
+ * 1's `forWorkerLaunch()` in its OWN process, at the moment the agent starts,
7
+ * and then runs the agent with those variables in its environment. So a value
8
+ * never appears in the tab command, in any argv, in a prompt file, or in a
9
+ * `start-tickets` summary, and a rotated value is picked up at the next start
10
+ * with no Bridge step.
11
+ *
12
+ * - The repository identity comes from `--repo`, which `start-tickets` writes
13
+ * from the repository it resolved itself — never from the worktree.
14
+ * - Only the variable channel is applied here. File credentials were already
15
+ * linked into the worktree before the tab opened; MCP credentials are
16
+ * resolved by the `mcp-invoke` shim.
17
+ * - Missing credentials are a notice on stderr, never a failure: the agent
18
+ * starts either way and its exit status is returned unchanged. stdout belongs
19
+ * to the agent alone.
20
+ * - A reserved worker-environment name (child 1 already refuses it in the
21
+ * record) is rechecked and dropped with a notice naming only the variable.
22
+ */
23
+ import { spawn } from "child_process";
24
+ import { existsSync } from "fs";
25
+ import path from "path";
26
+ import { validateRepoName } from "./bridge-config.js";
27
+ import { forWorkerLaunch } from "./credential-references.js";
28
+ import { createLaunchCredentialReferenceDeps, formatNoticeLines, launchResolveOptions, } from "./credential-delivery.js";
29
+ import { isWorkerEnvNameReserved } from "./executor/env.js";
30
+ import { spawnMcpCommand } from "./mcp-invoke.js";
31
+ export const WITH_CREDENTIALS_SUBCOMMAND = "with-credentials";
32
+ // ---------------------------------------------------------------------------
33
+ // Windows `.cmd` / `.bat` agents
34
+ // ---------------------------------------------------------------------------
35
+ /**
36
+ * Node cannot spawn a `.cmd`/`.bat` shim (how npm installs `claude` on
37
+ * Windows) without a shell. Rather than `shell: true`, which joins argv
38
+ * unquoted, the shim is run through `cmd.exe /d /s /c "<line>"` with every part
39
+ * escaped for both the C runtime and cmd's metacharacters (the scheme
40
+ * `cross-spawn` uses), and `windowsVerbatimArguments` so Node adds nothing.
41
+ */
42
+ const CMD_META = /([()\][%!^"`<>&|;, *?])/g;
43
+ function escapeWindowsArgument(arg) {
44
+ let escaped = arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1");
45
+ escaped = `"${escaped}"`;
46
+ // Twice: once for cmd parsing the line, once for the .cmd shim re-parsing `%*`.
47
+ return escaped.replace(CMD_META, "^$1").replace(CMD_META, "^$1");
48
+ }
49
+ function escapeWindowsCommand(command) {
50
+ return command.replace(CMD_META, "^$1");
51
+ }
52
+ /**
53
+ * Resolve the agent on Windows through `PATH`/`PATHEXT`. A `.cmd`/`.bat`
54
+ * resolves to a `cmd.exe` invocation; anything else is spawned directly.
55
+ */
56
+ export function resolveWindowsAgentInvocation(command, args, env, fileExists) {
57
+ const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((e) => e.length > 0);
58
+ const hasSep = /[\\/]/.test(command);
59
+ const dirs = hasSep ? [""] : (env.PATH ?? env.Path ?? "").split(";").filter((d) => d.length > 0);
60
+ let resolved = null;
61
+ for (const dir of dirs) {
62
+ const base = dir.length === 0 ? command : path.win32.join(dir, command);
63
+ const hasExt = exts.some((e) => base.toLowerCase().endsWith(e.toLowerCase()));
64
+ for (const candidate of hasExt ? [base] : exts.map((e) => `${base}${e}`)) {
65
+ if (fileExists(candidate)) {
66
+ resolved = candidate;
67
+ break;
68
+ }
69
+ }
70
+ if (resolved)
71
+ break;
72
+ }
73
+ if (resolved && /\.(cmd|bat)$/i.test(resolved)) {
74
+ const line = [escapeWindowsCommand(path.win32.normalize(resolved)), ...args.map(escapeWindowsArgument)].join(" ");
75
+ return { command: env.ComSpec ?? env.COMSPEC ?? "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], verbatim: true };
76
+ }
77
+ return { command: resolved ?? command, args: [...args], verbatim: false };
78
+ }
79
+ export function getWithCredentialsUsage() {
80
+ return [
81
+ "Usage: with-credentials --repo <repo> -- <agent> [args...]",
82
+ "",
83
+ "Internal: run an agent with the repository's approved sandbox credential",
84
+ "variables in its environment. Used by start-tickets tabs.",
85
+ ].join("\n");
86
+ }
87
+ /** Parse argv (after the subcommand). Never echoes an agent argument. */
88
+ export function parseWithCredentialsArgs(argv) {
89
+ const separator = argv.indexOf("--");
90
+ const head = separator === -1 ? [...argv] : argv.slice(0, separator);
91
+ if (head.includes("--help") || head.includes("-h"))
92
+ return { status: "help" };
93
+ if (separator === -1)
94
+ return { status: "error", message: "missing '--' before the agent command" };
95
+ let repo;
96
+ for (let i = 0; i < head.length; i++) {
97
+ if (head[i] === "--repo") {
98
+ if (repo !== undefined)
99
+ return { status: "error", message: "--repo was given more than once" };
100
+ const value = head[i + 1];
101
+ if (value === undefined)
102
+ return { status: "error", message: "--repo needs a value" };
103
+ repo = value;
104
+ i++;
105
+ continue;
106
+ }
107
+ return { status: "error", message: "unknown option before '--'" };
108
+ }
109
+ if (repo === undefined)
110
+ return { status: "error", message: "--repo is required" };
111
+ const validated = validateRepoName(repo);
112
+ if (!validated.ok)
113
+ return { status: "error", message: `invalid --repo: ${validated.error}` };
114
+ const agent = argv.slice(separator + 1);
115
+ if (agent.length === 0 || agent[0].length === 0) {
116
+ return { status: "error", message: "the agent command after '--' is empty" };
117
+ }
118
+ return { status: "ok", repo: validated.value, command: agent[0], args: agent.slice(1) };
119
+ }
120
+ /**
121
+ * Build the agent environment: the inherited environment plus admitted
122
+ * variables. A reserved name is dropped. Returns names-only notices.
123
+ */
124
+ export function buildAgentEnv(parentEnv, values) {
125
+ const env = { ...parentEnv };
126
+ const notices = [];
127
+ const admitted = [];
128
+ for (const [name, value] of Object.entries(values)) {
129
+ if (isWorkerEnvNameReserved(name)) {
130
+ notices.push({ name, reason: "reserved_name" });
131
+ continue;
132
+ }
133
+ // Same rule as the executor's admitDeclaredCredentialEnv: an approved
134
+ // credential never overrides a variable the agent's environment already
135
+ // sets. The collision is named (never its value) and the inherited value wins.
136
+ if (env[name] !== undefined) {
137
+ notices.push({ name, reason: "name_collision" });
138
+ continue;
139
+ }
140
+ env[name] = value;
141
+ admitted.push(name);
142
+ }
143
+ return { env, notices, admitted };
144
+ }
145
+ /** Run the subcommand. Returns the agent's exit status (never calls `process.exit`). */
146
+ export async function runWithCredentialsCli(argv, overrides = {}) {
147
+ const stderr = overrides.stderr ?? ((m) => process.stderr.write(`${m}\n`));
148
+ const env = overrides.env ?? process.env;
149
+ const cwd = overrides.cwd ?? process.cwd();
150
+ const parsed = parseWithCredentialsArgs(argv);
151
+ if (parsed.status === "help") {
152
+ // Usage goes to stderr so stdout stays the agent's.
153
+ stderr(getWithCredentialsUsage());
154
+ return 0;
155
+ }
156
+ if (parsed.status === "error") {
157
+ stderr(`Error: ${parsed.message}`);
158
+ stderr(getWithCredentialsUsage());
159
+ return 2;
160
+ }
161
+ let resolution;
162
+ try {
163
+ resolution = overrides.resolve
164
+ ? await overrides.resolve(parsed.repo, cwd)
165
+ : await forWorkerLaunch(parsed.repo, createLaunchCredentialReferenceDeps(env, cwd), launchResolveOptions(cwd));
166
+ }
167
+ catch {
168
+ resolution = { state: "record_unusable", files: [], env: {}, unavailable: [] };
169
+ }
170
+ // Only the variable channel applies here; file specs were linked before the tab opened.
171
+ const values = resolution.state === "ok" ? resolution.env : {};
172
+ const built = buildAgentEnv(env, values);
173
+ const notices = [
174
+ ...resolution.unavailable.map((u) => ({ name: u.name, reason: u.reason })),
175
+ ...built.notices,
176
+ ];
177
+ for (const line of formatNoticeLines(resolution.state, notices))
178
+ stderr(`Warning: ${line}`);
179
+ const invocation = { command: parsed.command, args: parsed.args, env: built.env };
180
+ try {
181
+ if (overrides.spawnAgent)
182
+ return await overrides.spawnAgent(invocation);
183
+ const platform = overrides.platform ?? process.platform;
184
+ const win = platform === "win32"
185
+ ? resolveWindowsAgentInvocation(invocation.command, invocation.args, invocation.env, existsSync)
186
+ : null;
187
+ const spawnFn = win?.verbatim
188
+ ? ((command, args, options) => spawn(command, args, { ...options, windowsVerbatimArguments: true }))
189
+ : spawn;
190
+ return await spawnMcpCommand({
191
+ spawn: spawnFn,
192
+ command: win ? win.command : invocation.command,
193
+ args: win ? win.args : invocation.args,
194
+ env: invocation.env,
195
+ onSignal: (s, h) => {
196
+ process.on(s, h);
197
+ },
198
+ offSignal: (s, h) => {
199
+ process.off(s, h);
200
+ },
201
+ });
202
+ }
203
+ catch {
204
+ // Fixed text: never the command, its arguments, or the error.
205
+ stderr("Error: the agent could not be started");
206
+ return 127;
207
+ }
208
+ }