@bridge_gpt/mcp-server 0.2.72 → 0.2.73
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.
- package/README.md +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +106 -21
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +166 -15
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +150 -5
- package/build/conductor/gate-settings-review.js +224 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2101 -44
- package/build/epic-launch-context.js +607 -0
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +234 -109
- package/build/pipelines.generated.js +5 -5
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in MCP presets offered at the grant setup item (BAPI-1545).
|
|
3
|
+
*
|
|
4
|
+
* One preset today: Playwright. It is a pinned `@playwright/mcp` run through
|
|
5
|
+
* `npx -y` with `--headless --isolated`. The `mcp-invoke` shim adds exactly one
|
|
6
|
+
* `--allowed-origins <origin>` pair at launch, derived from the
|
|
7
|
+
* `BRIDGE_EPIC_SERVER_URL` the shim itself inherits (child 3 sets it at spawn).
|
|
8
|
+
*
|
|
9
|
+
* WHY A DENY-ALL ORIGIN AND NOT AN EMPTY LIST. In `@playwright/mcp` 0.0.83 the
|
|
10
|
+
* browser context installs its block-all route only when
|
|
11
|
+
* `network.allowedOrigins` is NON-EMPTY (`_setupRequestInterception` checks
|
|
12
|
+
* `allowedOrigins?.length`). An empty list, or no flag at all, allows every
|
|
13
|
+
* origin. So "allow nothing" has to be a non-empty list naming one origin that
|
|
14
|
+
* can never match a real request: a reserved `.invalid` host (RFC 6761).
|
|
15
|
+
* This was verified against the locally cached 0.0.83 package; the pin below is
|
|
16
|
+
* that version. If a future pin cannot limit origins, set
|
|
17
|
+
* `PLAYWRIGHT_PRESET_LIMITS_ORIGINS` to false: the preset is then not offered at
|
|
18
|
+
* all, never shipped allowing everything.
|
|
19
|
+
*
|
|
20
|
+
* CAVEAT, stated plainly: upstream documents that `--allowed-origins` "does not
|
|
21
|
+
* serve as a security boundary and does not affect redirects". It narrows what
|
|
22
|
+
* the browser requests; it is not OS isolation. The replacing environment and
|
|
23
|
+
* fixed port child 3 adds are separate limits this module does not provide.
|
|
24
|
+
*/
|
|
25
|
+
/** The grant name the Playwright preset is registered under. Reserved. */
|
|
26
|
+
export const PLAYWRIGHT_PRESET_NAME = "playwright";
|
|
27
|
+
/** The pinned, locally verified package version. Never a floating tag. */
|
|
28
|
+
export const PLAYWRIGHT_MCP_PINNED_VERSION = "0.0.83";
|
|
29
|
+
/** The pinned package spec `npx -y` launches. */
|
|
30
|
+
export const PLAYWRIGHT_MCP_PACKAGE_SPEC = `@playwright/mcp@${PLAYWRIGHT_MCP_PINNED_VERSION}`;
|
|
31
|
+
/** Baseline arguments, before the shim appends the origin limit. */
|
|
32
|
+
export const PLAYWRIGHT_PRESET_BASE_ARGS = ["-y", PLAYWRIGHT_MCP_PACKAGE_SPEC, "--headless", "--isolated"];
|
|
33
|
+
/** Whether the pinned version honors `--allowed-origins` (verified for 0.0.83). */
|
|
34
|
+
export const PLAYWRIGHT_PRESET_LIMITS_ORIGINS = true;
|
|
35
|
+
/** The non-empty origin list that allows nothing (RFC 6761 reserved TLD). */
|
|
36
|
+
export const PLAYWRIGHT_DENY_ALL_ORIGIN = "http://deny-all.invalid";
|
|
37
|
+
/** The env var the shim reads the one allowed origin from. */
|
|
38
|
+
export const EPIC_SERVER_URL_ENV = "BRIDGE_EPIC_SERVER_URL";
|
|
39
|
+
/** The ambient env vars that could widen the origin list; removed from the child env. */
|
|
40
|
+
export const PLAYWRIGHT_ORIGIN_ENV_KEYS = [
|
|
41
|
+
"PLAYWRIGHT_MCP_ALLOWED_ORIGINS",
|
|
42
|
+
"PLAYWRIGHT_MCP_BLOCKED_ORIGINS",
|
|
43
|
+
];
|
|
44
|
+
/** Shown in the setup item when the preset cannot limit origins. */
|
|
45
|
+
export const PLAYWRIGHT_PRESET_UNAVAILABLE_TEXT = "Playwright preset unavailable: this version cannot limit origins";
|
|
46
|
+
/** The preset's grant entry, or null when it must not be offered. */
|
|
47
|
+
export function playwrightPresetEntry() {
|
|
48
|
+
if (!PLAYWRIGHT_PRESET_LIMITS_ORIGINS)
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
name: PLAYWRIGHT_PRESET_NAME,
|
|
52
|
+
source: "preset",
|
|
53
|
+
transport: "stdio",
|
|
54
|
+
command: "npx",
|
|
55
|
+
args: [...PLAYWRIGHT_PRESET_BASE_ARGS],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** True when a granted entry is the built-in Playwright preset. */
|
|
59
|
+
export function isPlaywrightPresetEntry(entry) {
|
|
60
|
+
return entry.source === "preset" && entry.name === PLAYWRIGHT_PRESET_NAME;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Derive the one allowed origin from the shim's environment. Only an http or
|
|
64
|
+
* https URL counts, reduced to its origin. Absent or invalid → the deny-all
|
|
65
|
+
* origin. `invalidSupplied` lets the caller print one fixed diagnostic; the
|
|
66
|
+
* supplied value is never returned or printed.
|
|
67
|
+
*/
|
|
68
|
+
export function resolvePlaywrightAllowedOrigin(env) {
|
|
69
|
+
const raw = env[EPIC_SERVER_URL_ENV];
|
|
70
|
+
if (raw === undefined || raw.trim().length === 0)
|
|
71
|
+
return { origin: PLAYWRIGHT_DENY_ALL_ORIGIN, invalidSupplied: false };
|
|
72
|
+
try {
|
|
73
|
+
const url = new URL(raw.trim());
|
|
74
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && url.origin !== "null") {
|
|
75
|
+
return { origin: url.origin, invalidSupplied: false };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
/* fall through to deny-all */
|
|
80
|
+
}
|
|
81
|
+
return { origin: PLAYWRIGHT_DENY_ALL_ORIGIN, invalidSupplied: true };
|
|
82
|
+
}
|
|
83
|
+
function isOriginFlag(arg) {
|
|
84
|
+
return (arg === "--allowed-origins" ||
|
|
85
|
+
arg.startsWith("--allowed-origins=") ||
|
|
86
|
+
arg === "--blocked-origins" ||
|
|
87
|
+
arg.startsWith("--blocked-origins="));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Remove every origin flag (split or `=` form) and append exactly one
|
|
91
|
+
* `--allowed-origins <origin>` pair.
|
|
92
|
+
*/
|
|
93
|
+
export function applyPlaywrightOriginLimit(args, origin) {
|
|
94
|
+
const out = [];
|
|
95
|
+
for (let i = 0; i < args.length; i++) {
|
|
96
|
+
const arg = args[i];
|
|
97
|
+
if (isOriginFlag(arg)) {
|
|
98
|
+
// A split form also consumes its value.
|
|
99
|
+
if (!arg.includes("=") && i + 1 < args.length)
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
out.push(arg);
|
|
104
|
+
}
|
|
105
|
+
out.push("--allowed-origins", origin);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
@@ -16,12 +16,22 @@
|
|
|
16
16
|
* provisioned as its own shim entry. Unsupported or incomplete non-`bapi`
|
|
17
17
|
* targets produce a non-fatal, secret-free warning.
|
|
18
18
|
*
|
|
19
|
+
* BAPI-1545 adds the GRANT PATH. When the caller supplies a trusted repository
|
|
20
|
+
* name (the executor passes the claimed job's `repo_name`) and that repository
|
|
21
|
+
* has an MCP grant file outside the worktree, the worktree's `.bridge/config` is
|
|
22
|
+
* never read. The registration is rebuilt from the grant on every spawn — Bridge
|
|
23
|
+
* plus one shim per granted server, nothing else — replacing the whole server
|
|
24
|
+
* map so a worker's edits cannot survive. An unusable grant yields Bridge only.
|
|
25
|
+
* With no trusted name, or no grant file, the legacy path below is unchanged.
|
|
26
|
+
*
|
|
19
27
|
* All filesystem access is dependency-injected so this is unit-testable, and the
|
|
20
28
|
* platform path API is resolved locally (never imported from `start-tickets.ts`)
|
|
21
29
|
* to avoid a runtime import cycle.
|
|
22
30
|
*/
|
|
31
|
+
import os from "os";
|
|
23
32
|
import path from "path";
|
|
24
33
|
import { readBridgeConfig } from "./bridge-config.js";
|
|
34
|
+
import { readMcpGrant } from "./mcp-grant.js";
|
|
25
35
|
import { getThirdPartyTargetDefinition, validateThirdPartyTargetManifestEntry, } from "./third-party-mcp-targets.js";
|
|
26
36
|
import { buildMcpShimCommand, } from "./mcp-server-invocation.js";
|
|
27
37
|
import { getWorktreeHostTargets, hostAdapterForTarget } from "./mcp-host-targets.js";
|
|
@@ -90,8 +100,8 @@ export function serverNameForMcpTarget(target) {
|
|
|
90
100
|
* `command` and `args`; credentials continue to be resolved by the `mcp-invoke`
|
|
91
101
|
* shim at launch and are never written into the worktree.
|
|
92
102
|
*/
|
|
93
|
-
export function buildShimMcpServerEntry(target, absoluteWorktreePath, invocation, bridgeApiBaseUrl) {
|
|
94
|
-
const entry = buildMcpShimCommand(invocation, target, absoluteWorktreePath);
|
|
103
|
+
export function buildShimMcpServerEntry(target, absoluteWorktreePath, invocation, bridgeApiBaseUrl, grantRepo) {
|
|
104
|
+
const entry = buildMcpShimCommand(invocation, target, absoluteWorktreePath, grantRepo);
|
|
95
105
|
// Tier-2 targets are structurally unchanged: `--base-url` is a `bapi`-only flag
|
|
96
106
|
// and `mcp-invoke` rejects it for any other target, so appending it elsewhere
|
|
97
107
|
// would generate a registration that refuses to launch.
|
|
@@ -240,6 +250,25 @@ export function mergeBridgeApiMcpRegistration(existing, topLevelKey, entry) {
|
|
|
240
250
|
// canonical name is sufficient — and keeps ONE place that decides the key.
|
|
241
251
|
return mergeMcpRegistrations(existing, topLevelKey, { [MCP_SERVER_NAME]: entry });
|
|
242
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* BAPI-1545: the authoritative server map for the grant path. Bridge is always
|
|
255
|
+
* present (with `--grant-repo`, so the shim takes its repository identity from
|
|
256
|
+
* the trusted name). A usable grant adds exactly one shim per granted server; an
|
|
257
|
+
* unusable grant adds none.
|
|
258
|
+
*/
|
|
259
|
+
export function buildGrantMcpServerEntries(grant, trustedRepoName, absoluteWorktreePath, invocation, bridgeApiBaseUrl) {
|
|
260
|
+
const entries = {
|
|
261
|
+
[serverNameForMcpTarget("bapi")]: buildShimMcpServerEntry("bapi", absoluteWorktreePath, invocation, bridgeApiBaseUrl, trustedRepoName),
|
|
262
|
+
};
|
|
263
|
+
if (grant.state === "ok") {
|
|
264
|
+
for (const server of grant.grant.servers) {
|
|
265
|
+
entries[serverNameForMcpTarget(server.name)] = buildShimMcpServerEntry(server.name, absoluteWorktreePath, invocation, undefined, trustedRepoName);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return entries;
|
|
269
|
+
}
|
|
270
|
+
/** Fixed, secret-free warning for an unusable grant. */
|
|
271
|
+
export const UNUSABLE_GRANT_WARNING = "the MCP grant for this repository is unusable; this worker gets Bridge only. Re-run `install epic-implementer` to repair it.";
|
|
243
272
|
// ---------------------------------------------------------------------------
|
|
244
273
|
// Filesystem writes
|
|
245
274
|
// ---------------------------------------------------------------------------
|
|
@@ -281,6 +310,55 @@ export async function writeMcpRegistrationFile(target, entries, deps) {
|
|
|
281
310
|
}
|
|
282
311
|
return { ok: true };
|
|
283
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* BAPI-1545: write a registration file AUTHORITATIVELY — the whole server map
|
|
315
|
+
* under `topLevelKey` is replaced by `entries`, removing stale extras and any
|
|
316
|
+
* Bridge alias. Unrelated top-level fields of a valid existing document are
|
|
317
|
+
* kept. A malformed existing document is refused, never overwritten blindly.
|
|
318
|
+
* The file is then read back and its server map compared with `entries`.
|
|
319
|
+
*/
|
|
320
|
+
export async function writeAuthoritativeMcpRegistrationFile(target, entries, deps) {
|
|
321
|
+
const api = pathApiForProvisioningPlatform(deps.platform);
|
|
322
|
+
let existing = {};
|
|
323
|
+
try {
|
|
324
|
+
const raw = await deps.readFile(target.filePath);
|
|
325
|
+
let parsed;
|
|
326
|
+
try {
|
|
327
|
+
parsed = JSON.parse(raw);
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return { ok: false, error: `existing ${target.filePath} contains malformed JSON; not overwriting` };
|
|
331
|
+
}
|
|
332
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
333
|
+
return { ok: false, error: `existing ${target.filePath} is not a JSON object; not overwriting` };
|
|
334
|
+
}
|
|
335
|
+
existing = { ...parsed };
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
const code = err && typeof err === "object" ? err.code : undefined;
|
|
339
|
+
if (code !== "ENOENT")
|
|
340
|
+
return { ok: false, error: `unable to read ${target.filePath}` };
|
|
341
|
+
}
|
|
342
|
+
const document = { ...existing, [target.topLevelKey]: { ...entries } };
|
|
343
|
+
try {
|
|
344
|
+
await deps.mkdir(api.dirname(target.filePath), { recursive: true });
|
|
345
|
+
await deps.writeFile(target.filePath, `${JSON.stringify(document, null, 2)}\n`);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return { ok: false, error: `failed to write ${target.filePath}` };
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
const readBack = JSON.parse(await deps.readFile(target.filePath));
|
|
352
|
+
const servers = readBack?.[target.topLevelKey];
|
|
353
|
+
if (JSON.stringify(servers) !== JSON.stringify(entries)) {
|
|
354
|
+
return { ok: false, error: `${target.filePath} did not read back as written` };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
return { ok: false, error: `${target.filePath} could not be read back` };
|
|
359
|
+
}
|
|
360
|
+
return { ok: true };
|
|
361
|
+
}
|
|
284
362
|
/**
|
|
285
363
|
* Write (or merge) the worktree's `.claude/settings.local.json` so the given
|
|
286
364
|
* `.mcp.json` server names are pre-approved via `enabledMcpjsonServers`. This
|
|
@@ -381,6 +459,25 @@ export async function provisionMcpRegistrationForWorktree(row, deps) {
|
|
|
381
459
|
if (row.status !== "created" || !row.path) {
|
|
382
460
|
return row;
|
|
383
461
|
}
|
|
462
|
+
// BAPI-1545: choose the authority BEFORE reading anything from the worktree.
|
|
463
|
+
if (deps.trustedRepoName !== undefined) {
|
|
464
|
+
const readGrant = deps.readMcpGrant ??
|
|
465
|
+
((repo) => readMcpGrant(repo, {
|
|
466
|
+
env: deps.env ?? process.env,
|
|
467
|
+
homedir: deps.homedir ?? os.homedir,
|
|
468
|
+
readFile: deps.readFile,
|
|
469
|
+
}));
|
|
470
|
+
let grant;
|
|
471
|
+
try {
|
|
472
|
+
grant = await readGrant(deps.trustedRepoName);
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
grant = { state: "unusable", reason: "the grant file could not be read" };
|
|
476
|
+
}
|
|
477
|
+
if (grant.state !== "absent") {
|
|
478
|
+
return provisionGrantMcpRegistration(row, row.path, deps.trustedRepoName, grant, deps);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
384
481
|
const read = await readBridgeConfig(row.path, { readFile: deps.readFile });
|
|
385
482
|
if (!read.ok) {
|
|
386
483
|
if (read.kind === "missing") {
|
|
@@ -422,6 +519,41 @@ export async function provisionMcpRegistrationForWorktree(row, deps) {
|
|
|
422
519
|
}
|
|
423
520
|
return result;
|
|
424
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* BAPI-1545: the grant path. Never reads `.bridge/config`. Writes BOTH
|
|
524
|
+
* registration files authoritatively from the grant, reads them back, and
|
|
525
|
+
* records the outcome on `row.mcpGrantRegistration` so the executor can refuse
|
|
526
|
+
* a spawn whose registration is not authoritative. Trust pre-approval stays
|
|
527
|
+
* best-effort.
|
|
528
|
+
*/
|
|
529
|
+
async function provisionGrantMcpRegistration(row, worktreePath, trustedRepoName, grant, deps) {
|
|
530
|
+
const normalized = normalizeWorktreePathForRegistration(worktreePath, deps);
|
|
531
|
+
if (!normalized.ok) {
|
|
532
|
+
const error = `MCP provisioning failed: ${normalized.error}`;
|
|
533
|
+
return { ...row, status: "spawn-failed", error, mcpGrantRegistration: { ok: false, error } };
|
|
534
|
+
}
|
|
535
|
+
const entries = buildGrantMcpServerEntries(grant, trustedRepoName, normalized.path, deps.mcpServerInvocation, deps.bridgeApiBaseUrl);
|
|
536
|
+
let result = { ...row, mcpRegistrationForm: deps.mcpServerInvocation.form };
|
|
537
|
+
if (grant.state === "unusable")
|
|
538
|
+
result = withWarning(result, UNUSABLE_GRANT_WARNING);
|
|
539
|
+
for (const target of getWorktreeMcpRegistrationTargets(normalized.path, deps.platform)) {
|
|
540
|
+
const written = await writeAuthoritativeMcpRegistrationFile(target, entries, deps);
|
|
541
|
+
if (!written.ok) {
|
|
542
|
+
const error = `MCP provisioning failed: ${written.error}`;
|
|
543
|
+
return { ...result, status: "spawn-failed", error, mcpGrantRegistration: { ok: false, error } };
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const serverNames = Object.keys(entries);
|
|
547
|
+
result = { ...result, mcpGrantRegistration: { ok: true, expectedServerNames: [...serverNames].sort() } };
|
|
548
|
+
if (deps.mcpServerInvocation.form !== "absolute-build-path") {
|
|
549
|
+
result = withWarning(result, "MCP registration used npm-channel fallback because an on-disk build entry was not resolvable.");
|
|
550
|
+
}
|
|
551
|
+
const trust = await writeClaudeServerTrustSettings(normalized.path, serverNames, deps);
|
|
552
|
+
if (!trust.ok) {
|
|
553
|
+
result = withWarning(result, `Claude MCP trust pre-approval skipped: ${trust.error}`);
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
425
557
|
/**
|
|
426
558
|
* Provision MCP registrations for every created worktree row, in order.
|
|
427
559
|
* Per-row failures are isolated — a failed row never aborts later rows.
|
|
@@ -10,6 +10,7 @@ import path from "path";
|
|
|
10
10
|
import { getWorktreeHostTargets, hostAdapterForTarget } from "./mcp-host-targets.js";
|
|
11
11
|
import { MCP_SERVER_NAME, MCP_PACKAGE_NAME, resolveRegistrationKey, } from "./mcp-identity.js";
|
|
12
12
|
import { DUPLICATE_REGISTRATION_GUIDANCE } from "./launcher-config-inspection.js";
|
|
13
|
+
import { validateRepoName } from "./bridge-config.js";
|
|
13
14
|
/**
|
|
14
15
|
* Read and parse a JSON file.
|
|
15
16
|
*
|
|
@@ -63,8 +64,33 @@ function flagValue(args, flag) {
|
|
|
63
64
|
* In both forms `--target` must be `bapi` and `--project-root` must match the
|
|
64
65
|
* given worktree exactly. The server entry path is NOT required to sit under any
|
|
65
66
|
* particular username/path prefix.
|
|
67
|
+
*
|
|
68
|
+
* BAPI-1545: an executor worktree on the MCP-grant path carries a trailing
|
|
69
|
+
* `--grant-repo <repo>` pair. It is tolerated, and when present its value must
|
|
70
|
+
* be a usable repository name. Authority is never re-checked against
|
|
71
|
+
* `.bridge/config` here.
|
|
66
72
|
*/
|
|
67
73
|
export function isBridgeApiShimEntry(entry, worktreeRoot) {
|
|
74
|
+
if (!isMcpInvokeShimEntry(entry, worktreeRoot))
|
|
75
|
+
return false;
|
|
76
|
+
const args = entry.args.filter((a) => typeof a === "string");
|
|
77
|
+
if (flagValue(args, "--target") !== "bapi")
|
|
78
|
+
return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* BAPI-1545: the same shape check for any shim target, so a granted server's
|
|
83
|
+
* registration (`--target <name> --project-root <worktree> --grant-repo <repo>`)
|
|
84
|
+
* can be recognized. A granted entry must carry `--grant-repo`.
|
|
85
|
+
*/
|
|
86
|
+
export function isGrantedShimEntry(entry, worktreeRoot, target) {
|
|
87
|
+
if (!isMcpInvokeShimEntry(entry, worktreeRoot))
|
|
88
|
+
return false;
|
|
89
|
+
const args = entry.args.filter((a) => typeof a === "string");
|
|
90
|
+
return flagValue(args, "--target") === target && flagValue(args, "--grant-repo") !== undefined;
|
|
91
|
+
}
|
|
92
|
+
/** The shared shim shape: launcher form, `mcp-invoke`, project root, and an optional valid `--grant-repo`. */
|
|
93
|
+
function isMcpInvokeShimEntry(entry, worktreeRoot) {
|
|
68
94
|
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
69
95
|
return false;
|
|
70
96
|
const candidate = entry;
|
|
@@ -85,10 +111,13 @@ export function isBridgeApiShimEntry(entry, worktreeRoot) {
|
|
|
85
111
|
}
|
|
86
112
|
if (!args.includes("mcp-invoke"))
|
|
87
113
|
return false;
|
|
88
|
-
if (flagValue(args, "--target") !== "bapi")
|
|
89
|
-
return false;
|
|
90
114
|
if (flagValue(args, "--project-root") !== worktreeRoot)
|
|
91
115
|
return false;
|
|
116
|
+
if (args.includes("--grant-repo")) {
|
|
117
|
+
const repo = flagValue(args, "--grant-repo");
|
|
118
|
+
if (repo === undefined || !validateRepoName(repo).ok)
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
92
121
|
return true;
|
|
93
122
|
}
|
|
94
123
|
/**
|
|
@@ -50,7 +50,10 @@ export function isTransientNpxEntryPath(entryPath) {
|
|
|
50
50
|
* `nodeExecutable` is returned as the standalone `command`, never concatenated
|
|
51
51
|
* with the server entry path, so `EPIC_IMPLEMENTER_NODE_PATH` can substitute it later.
|
|
52
52
|
*/
|
|
53
|
-
export function buildMcpShimCommand(invocation, target, absoluteWorktreePath) {
|
|
53
|
+
export function buildMcpShimCommand(invocation, target, absoluteWorktreePath, grantRepo) {
|
|
54
|
+
// BAPI-1545: `--grant-repo` is appended ONLY on the grant path, after the
|
|
55
|
+
// legacy arguments, so a call without it is byte-identical to before.
|
|
56
|
+
const grantArgs = grantRepo === undefined ? [] : ["--grant-repo", grantRepo];
|
|
54
57
|
if (invocation.form === "absolute-build-path") {
|
|
55
58
|
return {
|
|
56
59
|
command: invocation.nodeExecutable,
|
|
@@ -61,6 +64,7 @@ export function buildMcpShimCommand(invocation, target, absoluteWorktreePath) {
|
|
|
61
64
|
target,
|
|
62
65
|
"--project-root",
|
|
63
66
|
absoluteWorktreePath,
|
|
67
|
+
...grantArgs,
|
|
64
68
|
],
|
|
65
69
|
};
|
|
66
70
|
}
|
|
@@ -74,6 +78,7 @@ export function buildMcpShimCommand(invocation, target, absoluteWorktreePath) {
|
|
|
74
78
|
target,
|
|
75
79
|
"--project-root",
|
|
76
80
|
absoluteWorktreePath,
|
|
81
|
+
...grantArgs,
|
|
77
82
|
],
|
|
78
83
|
};
|
|
79
84
|
}
|