@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.
- package/README.md +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -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/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -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 +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -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-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -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 +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -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-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -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-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -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/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- 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 +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -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 +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- 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/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- 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 +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +63 -2
- 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/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- 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
package/build/mcp-invoke.js
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
* manifest entry, resolves the target's required env overlay atomically from
|
|
16
16
|
* the secret store, and spawns the manifest `command`/`args`.
|
|
17
17
|
*
|
|
18
|
+
* BAPI-1545 adds the GRANT PATH, selected by `--grant-repo <repo>`. On it the
|
|
19
|
+
* shim never reads `<project-root>/.bridge/config`: `--target bapi` takes its
|
|
20
|
+
* repository identity from the flag, and every other target is resolved from
|
|
21
|
+
* the owner's grant file outside the worktree (`mcp-grant.ts`). Without the
|
|
22
|
+
* flag, both legacy paths above are unchanged.
|
|
23
|
+
*
|
|
18
24
|
* This file is the highest-risk surface of the worktree-credentials work: the
|
|
19
25
|
* stdio passthrough plus the signal/exit-code contract is covered exhaustively
|
|
20
26
|
* by its unit tests.
|
|
@@ -23,11 +29,16 @@ import { spawn, execFile } from "child_process";
|
|
|
23
29
|
import { stat, readFile } from "fs/promises";
|
|
24
30
|
import path from "path";
|
|
25
31
|
import os from "os";
|
|
26
|
-
import { resolveRepoNameForProjectRoot, readBridgeConfig, validateMcpTarget, } from "./bridge-config.js";
|
|
27
|
-
import { resolveBapiCredentials } from "./credential-store.js";
|
|
32
|
+
import { resolveRepoNameForProjectRoot, readBridgeConfig, validateMcpTarget, validateRepoName, } from "./bridge-config.js";
|
|
33
|
+
import { resolveBapiCredentials, resolveCredentialBundle, } from "./credential-store.js";
|
|
34
|
+
import { readMcpGrant } from "./mcp-grant.js";
|
|
35
|
+
import { forMcpServer } from "./credential-references.js";
|
|
36
|
+
import { createLaunchCredentialReferenceDeps, formatCredentialNotice, formatRecordUnusableNotice, launchResolveOptions, mcpReferenceEligibility, readApprovalMetadata, } from "./credential-delivery.js";
|
|
37
|
+
import { checkRestrictedLauncher } from "./credential-launch-safety.js";
|
|
38
|
+
import { applyPlaywrightOriginLimit, isPlaywrightPresetEntry, PLAYWRIGHT_ORIGIN_ENV_KEYS, resolvePlaywrightAllowedOrigin, } from "./mcp-presets.js";
|
|
28
39
|
import { describeBaseUrlRejection, validateHttpBaseUrl } from "./base-url.js";
|
|
29
40
|
import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
30
|
-
import { getThirdPartyTargetDefinition, resolveThirdPartyTargetEnv, validateThirdPartyTargetManifestEntry, } from "./third-party-mcp-targets.js";
|
|
41
|
+
import { getThirdPartyTargetDefinition, grantedEntryRequiredKeys, resolveThirdPartyTargetEnv, validateGrantedTargetEntry, validateThirdPartyTargetManifestEntry, } from "./third-party-mcp-targets.js";
|
|
31
42
|
// ---------------------------------------------------------------------------
|
|
32
43
|
// Usage / argument parsing
|
|
33
44
|
// ---------------------------------------------------------------------------
|
|
@@ -54,10 +65,14 @@ export function getMcpInvokeUsage() {
|
|
|
54
65
|
" omitted, the child inherits BAPI_BASE_URL",
|
|
55
66
|
" unchanged. Must be an absolute http/https URL",
|
|
56
67
|
" with no embedded username or password.",
|
|
68
|
+
" --grant-repo <REPO> Optional. Resolve the target from the owner's",
|
|
69
|
+
" MCP grant for this repository (outside the",
|
|
70
|
+
" worktree) and never from .bridge/config. With",
|
|
71
|
+
" --target bapi, use this repository name.",
|
|
57
72
|
" -h, --help Show this help",
|
|
58
73
|
].join("\n");
|
|
59
74
|
}
|
|
60
|
-
const KNOWN_FLAGS = new Set(["--target", "--project-root", "--base-url"]);
|
|
75
|
+
const KNOWN_FLAGS = new Set(["--target", "--project-root", "--base-url", "--grant-repo"]);
|
|
61
76
|
/**
|
|
62
77
|
* Parse `--target`, `--project-root`, and the optional `--base-url` (split or `=`
|
|
63
78
|
* form). Rejects unknown flags, positional arguments, missing values, and
|
|
@@ -73,6 +88,7 @@ export function parseMcpInvokeArgs(argv) {
|
|
|
73
88
|
let target;
|
|
74
89
|
let projectRoot;
|
|
75
90
|
let baseUrl;
|
|
91
|
+
let grantRepo;
|
|
76
92
|
for (let i = 0; i < argv.length; i++) {
|
|
77
93
|
const token = argv[i];
|
|
78
94
|
if (token === "-h" || token === "--help") {
|
|
@@ -115,6 +131,17 @@ export function parseMcpInvokeArgs(argv) {
|
|
|
115
131
|
}
|
|
116
132
|
baseUrl = validation.baseUrl;
|
|
117
133
|
}
|
|
134
|
+
else if (flag === "--grant-repo") {
|
|
135
|
+
if (grantRepo !== undefined) {
|
|
136
|
+
return { status: "error", message: "Duplicate --grant-repo flag" };
|
|
137
|
+
}
|
|
138
|
+
const repo = validateRepoName(value);
|
|
139
|
+
// The rejected value is never echoed.
|
|
140
|
+
if (!repo.ok || repo.value !== value) {
|
|
141
|
+
return { status: "error", message: "Invalid --grant-repo: not a usable repository name" };
|
|
142
|
+
}
|
|
143
|
+
grantRepo = repo.value;
|
|
144
|
+
}
|
|
118
145
|
else {
|
|
119
146
|
if (projectRoot !== undefined) {
|
|
120
147
|
return { status: "error", message: "Duplicate --project-root flag" };
|
|
@@ -141,9 +168,13 @@ export function parseMcpInvokeArgs(argv) {
|
|
|
141
168
|
message: "--base-url is only valid with --target bapi",
|
|
142
169
|
};
|
|
143
170
|
}
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
171
|
+
return {
|
|
172
|
+
status: "ok",
|
|
173
|
+
target: targetValidation.value,
|
|
174
|
+
projectRoot,
|
|
175
|
+
...(baseUrl !== undefined ? { baseUrl } : {}),
|
|
176
|
+
...(grantRepo !== undefined ? { grantRepo } : {}),
|
|
177
|
+
};
|
|
147
178
|
}
|
|
148
179
|
// ---------------------------------------------------------------------------
|
|
149
180
|
// Validation, env construction, signals
|
|
@@ -325,12 +356,95 @@ export async function resolveBapiInvocation(projectRoot, deps) {
|
|
|
325
356
|
if (typeof deps.baseUrl === "string" && deps.baseUrl.length > 0) {
|
|
326
357
|
overlay.BAPI_BASE_URL = deps.baseUrl;
|
|
327
358
|
}
|
|
328
|
-
const env = buildChildEnv(deps.env, overlay);
|
|
359
|
+
const env = buildChildEnv(deps.env, { ...(deps.referenceOverlay ?? {}), ...overlay });
|
|
329
360
|
return {
|
|
330
361
|
ok: true,
|
|
331
362
|
invocation: { command: deps.execPath, args: [deps.scriptPath], env },
|
|
332
363
|
};
|
|
333
364
|
}
|
|
365
|
+
/** Production seams for one shim invocation rooted at `projectRoot`. */
|
|
366
|
+
export function createMcpReferenceSeams(env, projectRoot) {
|
|
367
|
+
const deps = createLaunchCredentialReferenceDeps(env, projectRoot);
|
|
368
|
+
const options = launchResolveOptions(projectRoot);
|
|
369
|
+
return {
|
|
370
|
+
readMetadata: (repoName) => readApprovalMetadata(repoName, deps),
|
|
371
|
+
resolve: (target, launch, repoName) => forMcpServer(target, launch, repoName, deps, options),
|
|
372
|
+
checkLauncher: (launch, childEnv) => checkRestrictedLauncher({ command: launch.command, args: launch.args, cwd: projectRoot, env: childEnv, worktreeRoot: projectRoot }),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/** Fixed warning prefix for every reference notice on the shim's stderr. */
|
|
376
|
+
function emitReferenceNotices(lines, stderr) {
|
|
377
|
+
for (const line of lines)
|
|
378
|
+
stderr(`Warning: ${line}`);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Resolve the overlay for one target and launch. Never throws, never returns a
|
|
382
|
+
* value outside the overlay, and reports problems only as fixed, names-only
|
|
383
|
+
* notices: a record that cannot be used gives zero values and one notice; a
|
|
384
|
+
* missing, unreadable, unparsable, or mismatched source omits that credential
|
|
385
|
+
* with a notice; restricted values are removed for a launch the worktree
|
|
386
|
+
* controls.
|
|
387
|
+
*/
|
|
388
|
+
export async function resolveReferenceOverlay(target, launch, repoName, seams, stderr, options, metadataRead) {
|
|
389
|
+
try {
|
|
390
|
+
const read = metadataRead ?? (await seams.readMetadata(repoName));
|
|
391
|
+
if (read.state === "record_unusable") {
|
|
392
|
+
emitReferenceNotices([formatRecordUnusableNotice(read.reason)], stderr);
|
|
393
|
+
return {};
|
|
394
|
+
}
|
|
395
|
+
if (read.state !== "ok")
|
|
396
|
+
return {};
|
|
397
|
+
const eligibility = mcpReferenceEligibility(read.metadata, target, launch, { requireFingerprint: options.requireFingerprint });
|
|
398
|
+
const notices = [];
|
|
399
|
+
if (options.requireFingerprint) {
|
|
400
|
+
// Fingerprinted declarations that did not match this launch.
|
|
401
|
+
const declared = mcpReferenceEligibility(read.metadata, target, launch, { requireFingerprint: true, ignoreFingerprintMatch: true });
|
|
402
|
+
const matchedNames = new Set(eligibility.matched.map((d) => d.entry));
|
|
403
|
+
for (const d of declared.matched) {
|
|
404
|
+
if (!matchedNames.has(d.entry))
|
|
405
|
+
notices.push({ name: d.entry, reason: "launch_mismatch" });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (eligibility.matched.length === 0) {
|
|
409
|
+
emitReferenceNotices(notices.map(formatCredentialNotice), stderr);
|
|
410
|
+
return {};
|
|
411
|
+
}
|
|
412
|
+
const resolution = await seams.resolve(target, launch, repoName);
|
|
413
|
+
if (resolution.state === "record_unusable") {
|
|
414
|
+
emitReferenceNotices([formatRecordUnusableNotice()], stderr);
|
|
415
|
+
return {};
|
|
416
|
+
}
|
|
417
|
+
const matchedNames = new Set(eligibility.matched.map((d) => d.entry));
|
|
418
|
+
for (const u of resolution.unavailable) {
|
|
419
|
+
// Unfingerprinted declarations are not this path's to report when filtered out.
|
|
420
|
+
if (matchedNames.has(u.name))
|
|
421
|
+
notices.push({ name: u.name, reason: u.reason });
|
|
422
|
+
}
|
|
423
|
+
const allowedKeys = new Set(eligibility.keys);
|
|
424
|
+
const overlay = {};
|
|
425
|
+
for (const [key, value] of Object.entries(resolution.env)) {
|
|
426
|
+
if (allowedKeys.has(key))
|
|
427
|
+
overlay[key] = value;
|
|
428
|
+
}
|
|
429
|
+
const restricted = eligibility.matched.filter((d) => d.level === "restricted");
|
|
430
|
+
const restrictedKeys = new Set(restricted.flatMap((d) => d.keys));
|
|
431
|
+
if ([...restrictedKeys].some((k) => k in overlay)) {
|
|
432
|
+
const verdict = await seams.checkLauncher(launch, options.childEnv);
|
|
433
|
+
if (verdict !== "safe") {
|
|
434
|
+
for (const key of restrictedKeys)
|
|
435
|
+
delete overlay[key];
|
|
436
|
+
for (const d of restricted)
|
|
437
|
+
notices.push({ name: d.entry, reason: "restricted_launcher" });
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
emitReferenceNotices([...new Set(notices.map(formatCredentialNotice))], stderr);
|
|
441
|
+
return overlay;
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
emitReferenceNotices([formatRecordUnusableNotice()], stderr);
|
|
445
|
+
return {};
|
|
446
|
+
}
|
|
447
|
+
}
|
|
334
448
|
/**
|
|
335
449
|
* Resolve a Tier-2 third-party invocation: read `.bridge/config`, locate the
|
|
336
450
|
* requested target entry, resolve the target's required env overlay atomically
|
|
@@ -359,13 +473,43 @@ export async function resolveThirdPartyInvocation(target, projectRoot, deps) {
|
|
|
359
473
|
error: `target '${target}' is not declared in .bridge/config`,
|
|
360
474
|
};
|
|
361
475
|
}
|
|
362
|
-
|
|
476
|
+
// BAPI-1647: a bundle-less registry entry is reference-BACKED when approved
|
|
477
|
+
// fingerprinted declarations cover its required keys. Whether the overlay is
|
|
478
|
+
// applied is decided separately below, against the CURRENT command and args,
|
|
479
|
+
// so an edited launch starts without credentials instead of being refused.
|
|
480
|
+
const hasBundle = entry.secretBundle !== undefined && entry.secretBundle.trim().length > 0;
|
|
481
|
+
let repoName;
|
|
482
|
+
let metadata;
|
|
483
|
+
let referenceBacked = false;
|
|
484
|
+
if (!hasBundle && deps.references && deps.resolveRepoName && entry.command !== undefined && entry.args !== undefined) {
|
|
485
|
+
try {
|
|
486
|
+
const repo = await deps.resolveRepoName(projectRoot);
|
|
487
|
+
if (repo.ok) {
|
|
488
|
+
repoName = repo.value;
|
|
489
|
+
metadata = await deps.references.readMetadata(repoName);
|
|
490
|
+
if (metadata.state === "ok") {
|
|
491
|
+
referenceBacked = mcpReferenceEligibility(metadata.metadata, target, { command: entry.command, args: entry.args }, {
|
|
492
|
+
requireFingerprint: true,
|
|
493
|
+
ignoreFingerprintMatch: true,
|
|
494
|
+
}).eligible;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
metadata = undefined;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const entryValidation = validateThirdPartyTargetManifestEntry(entry, { referenceBacked });
|
|
363
503
|
if (!entryValidation.ok) {
|
|
364
504
|
return { ok: false, error: entryValidation.error };
|
|
365
505
|
}
|
|
366
506
|
// After validation these are guaranteed present.
|
|
367
507
|
const command = entry.command;
|
|
368
508
|
const args = entry.args;
|
|
509
|
+
if (entryValidation.referenceBacked && deps.references && repoName !== undefined) {
|
|
510
|
+
const overlay = await resolveReferenceOverlay(target, { command, args }, repoName, deps.references, deps.stderr ?? (() => undefined), { requireFingerprint: true, childEnv: deps.env }, metadata);
|
|
511
|
+
return { ok: true, invocation: { command, args, env: buildChildEnv(deps.env, overlay) } };
|
|
512
|
+
}
|
|
369
513
|
const secretBundle = entry.secretBundle;
|
|
370
514
|
const envResult = await deps.resolveTargetEnv(definition, secretBundle);
|
|
371
515
|
if (!envResult.ok) {
|
|
@@ -374,6 +518,90 @@ export async function resolveThirdPartyInvocation(target, projectRoot, deps) {
|
|
|
374
518
|
const env = buildChildEnv(deps.env, envResult.env);
|
|
375
519
|
return { ok: true, invocation: { command, args, env } };
|
|
376
520
|
}
|
|
521
|
+
/** One fixed line when `BRIDGE_EPIC_SERVER_URL` is set but unusable. Never the value. */
|
|
522
|
+
export const PLAYWRIGHT_INVALID_EPIC_SERVER_URL_MESSAGE = "Warning: BRIDGE_EPIC_SERVER_URL is not an http or https URL; the browser is limited to an origin that allows nothing.";
|
|
523
|
+
/**
|
|
524
|
+
* BAPI-1545: resolve a non-Bridge target from the owner's grant ONLY. Never
|
|
525
|
+
* reads `.bridge/config`. A missing entry, an unusable or absent grant, or a
|
|
526
|
+
* failed credential resolution is a fixed, secret-free error (the shim exits
|
|
527
|
+
* non-zero, the host shows the server as failed, and the job continues).
|
|
528
|
+
*
|
|
529
|
+
* The child env is the inherited env, then the entry's non-secret `env`, then
|
|
530
|
+
* the resolved secrets. For the Playwright preset, exactly one
|
|
531
|
+
* `--allowed-origins <origin>` pair is appended (deny-all when
|
|
532
|
+
* `BRIDGE_EPIC_SERVER_URL` is absent or invalid), and the ambient
|
|
533
|
+
* `PLAYWRIGHT_MCP_ALLOWED_ORIGINS` / `PLAYWRIGHT_MCP_BLOCKED_ORIGINS` are removed
|
|
534
|
+
* last, so nothing ambient can widen the list.
|
|
535
|
+
*/
|
|
536
|
+
export async function resolveGrantedInvocation(target, grantRepo, deps) {
|
|
537
|
+
const read = await deps.readGrant(grantRepo);
|
|
538
|
+
if (read.state === "absent") {
|
|
539
|
+
return { ok: false, error: `no MCP grant exists for this repository; target '${target}' is not granted` };
|
|
540
|
+
}
|
|
541
|
+
if (read.state === "unusable") {
|
|
542
|
+
return { ok: false, error: `the MCP grant for this repository is unusable (${read.reason}); target '${target}' is withheld` };
|
|
543
|
+
}
|
|
544
|
+
const entry = read.grant.servers.find((s) => s.name === target);
|
|
545
|
+
if (!entry) {
|
|
546
|
+
return { ok: false, error: `target '${target}' is not in the MCP grant for this repository` };
|
|
547
|
+
}
|
|
548
|
+
// BAPI-1647: an entry WITH a `secret_bundle` resolves exactly as before and
|
|
549
|
+
// gets no reference overlay. A bundle-less entry may be reference-backed: its
|
|
550
|
+
// eligibility comes from the trusted grant's own command and args (outside
|
|
551
|
+
// the worktree), never from the record inside the validator.
|
|
552
|
+
const hasBundle = entry.secret_bundle !== undefined && entry.secret_bundle.trim().length > 0;
|
|
553
|
+
let metadata;
|
|
554
|
+
let referenceBacked = false;
|
|
555
|
+
if (!hasBundle && deps.references) {
|
|
556
|
+
try {
|
|
557
|
+
metadata = await deps.references.readMetadata(grantRepo);
|
|
558
|
+
}
|
|
559
|
+
catch {
|
|
560
|
+
metadata = undefined;
|
|
561
|
+
}
|
|
562
|
+
if (metadata?.state === "ok") {
|
|
563
|
+
referenceBacked = mcpReferenceEligibility(metadata.metadata, target, { command: entry.command, args: entry.args }, {
|
|
564
|
+
requireFingerprint: false,
|
|
565
|
+
}).eligible;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const validation = validateGrantedTargetEntry(entry, { referenceBacked });
|
|
569
|
+
if (!validation.ok)
|
|
570
|
+
return { ok: false, error: validation.error };
|
|
571
|
+
const overlay = { ...(entry.env ?? {}) };
|
|
572
|
+
const keys = validation.referenceBacked ? [] : grantedEntryRequiredKeys(entry);
|
|
573
|
+
if (keys.length > 0) {
|
|
574
|
+
if (entry.secret_bundle === undefined) {
|
|
575
|
+
return { ok: false, error: `granted server '${target}' requires a secret_bundle` };
|
|
576
|
+
}
|
|
577
|
+
const resolved = await deps.resolveBundle(entry.secret_bundle, keys);
|
|
578
|
+
if (!resolved.ok) {
|
|
579
|
+
return { ok: false, error: `failed to resolve credentials for '${target}': ${resolved.error}` };
|
|
580
|
+
}
|
|
581
|
+
for (const key of keys) {
|
|
582
|
+
const value = resolved.values[key];
|
|
583
|
+
if (typeof value !== "string") {
|
|
584
|
+
return { ok: false, error: `failed to resolve credentials for '${target}': a required key is missing` };
|
|
585
|
+
}
|
|
586
|
+
overlay[key] = value;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (!hasBundle && deps.references && metadata !== undefined) {
|
|
590
|
+
const reference = await resolveReferenceOverlay(target, { command: entry.command, args: entry.args }, grantRepo, deps.references, deps.stderr, { requireFingerprint: false, childEnv: buildChildEnv(deps.env, overlay) }, metadata);
|
|
591
|
+
Object.assign(overlay, reference);
|
|
592
|
+
}
|
|
593
|
+
let args = [...entry.args];
|
|
594
|
+
const env = buildChildEnv(deps.env, overlay);
|
|
595
|
+
if (isPlaywrightPresetEntry(entry)) {
|
|
596
|
+
const origin = resolvePlaywrightAllowedOrigin(deps.env);
|
|
597
|
+
if (origin.invalidSupplied)
|
|
598
|
+
deps.stderr(PLAYWRIGHT_INVALID_EPIC_SERVER_URL_MESSAGE);
|
|
599
|
+
args = applyPlaywrightOriginLimit(args, origin.origin);
|
|
600
|
+
for (const key of PLAYWRIGHT_ORIGIN_ENV_KEYS)
|
|
601
|
+
delete env[key];
|
|
602
|
+
}
|
|
603
|
+
return { ok: true, invocation: { command: entry.command, args, env } };
|
|
604
|
+
}
|
|
377
605
|
/**
|
|
378
606
|
* Run the `mcp-invoke` subcommand. Returns a process exit code (never calls
|
|
379
607
|
* `process.exit`). Parses args BEFORE any validation/resolution; validates the
|
|
@@ -397,13 +625,17 @@ export async function runMcpInvokeCli(argv, overrides = {}) {
|
|
|
397
625
|
stderr(getMcpInvokeUsage());
|
|
398
626
|
return 1;
|
|
399
627
|
}
|
|
400
|
-
const { target, projectRoot, baseUrl } = parsed;
|
|
628
|
+
const { target, projectRoot, baseUrl, grantRepo } = parsed;
|
|
401
629
|
const statFn = overrides.stat ?? ((p) => stat(p));
|
|
402
630
|
const dirCheck = await validateProjectRootDirectory(projectRoot, statFn);
|
|
403
631
|
if (!dirCheck.ok) {
|
|
404
632
|
stderr(`Error: ${dirCheck.error}`);
|
|
405
633
|
return 1;
|
|
406
634
|
}
|
|
635
|
+
// BAPI-1647: resolved here, in the shim's own process, never by the worker.
|
|
636
|
+
const references = overrides.credentialReferences === null
|
|
637
|
+
? undefined
|
|
638
|
+
: (overrides.credentialReferences ?? createMcpReferenceSeams(env, projectRoot));
|
|
407
639
|
const credentialDeps = {
|
|
408
640
|
env,
|
|
409
641
|
homedir: os.homedir,
|
|
@@ -412,14 +644,47 @@ export async function runMcpInvokeCli(argv, overrides = {}) {
|
|
|
412
644
|
stat: (p) => stat(p),
|
|
413
645
|
stderr,
|
|
414
646
|
};
|
|
647
|
+
// BAPI-1545: on the grant path a non-Bridge target is resolved from the grant
|
|
648
|
+
// file only, before any worktree-config reader is even constructed.
|
|
649
|
+
if (grantRepo !== undefined && target !== "bapi") {
|
|
650
|
+
const readGrant = overrides.readMcpGrant ??
|
|
651
|
+
((repo) => readMcpGrant(repo, { env, homedir: os.homedir, readFile: (p) => readFile(p, "utf-8") }));
|
|
652
|
+
const resolveBundle = overrides.resolveCredentialBundle ??
|
|
653
|
+
((bundle, keys) => resolveCredentialBundle(bundle, keys, credentialDeps));
|
|
654
|
+
const resolved = await resolveGrantedInvocation(target, grantRepo, {
|
|
655
|
+
env,
|
|
656
|
+
readGrant,
|
|
657
|
+
resolveBundle,
|
|
658
|
+
stderr,
|
|
659
|
+
...(references ? { references } : {}),
|
|
660
|
+
});
|
|
661
|
+
if (!resolved.ok) {
|
|
662
|
+
stderr(`Error: ${resolved.error}`);
|
|
663
|
+
return 1;
|
|
664
|
+
}
|
|
665
|
+
return spawnInvocation(resolved.invocation, overrides);
|
|
666
|
+
}
|
|
415
667
|
if (target === "bapi") {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
668
|
+
// BAPI-1545: with `--grant-repo`, the trusted repository name is used as is
|
|
669
|
+
// and the worktree's `.bridge/config` is never consulted, so a worker that
|
|
670
|
+
// rewrites `repoName` there cannot pick another repository's credential.
|
|
671
|
+
// The grant itself is not read: Bridge works even when the grant is unusable.
|
|
672
|
+
const resolveRepoName = grantRepo !== undefined
|
|
673
|
+
? async () => ({ ok: true, value: grantRepo })
|
|
674
|
+
: overrides.resolveRepoName ??
|
|
675
|
+
((pr) => resolveRepoNameForProjectRoot(pr, {
|
|
676
|
+
readFile: (p) => readFile(p, "utf-8"),
|
|
677
|
+
runCommand: defaultRunCommand,
|
|
678
|
+
}));
|
|
421
679
|
const resolveCredentials = overrides.resolveCredentials ??
|
|
422
680
|
((rn) => resolveBapiCredentials(rn, credentialDeps));
|
|
681
|
+
// BAPI-1647: record credentials for the `bridge` consumer only under a
|
|
682
|
+
// TRUSTED identity (`--grant-repo`, which `start-tickets` and the executor
|
|
683
|
+
// write from their own resolved repository). The worktree's `.bridge/config`
|
|
684
|
+
// never selects them, and the grant's own state does not matter here.
|
|
685
|
+
const referenceOverlay = grantRepo !== undefined && references
|
|
686
|
+
? await resolveReferenceOverlay("bapi", { command: process.execPath, args: [process.argv[1]] }, grantRepo, references, stderr, { requireFingerprint: false, childEnv: env })
|
|
687
|
+
: undefined;
|
|
423
688
|
// The parsed URL reaches ONLY this branch; the parser already rejected
|
|
424
689
|
// `--base-url` for every other target, so the Tier-2 path below cannot see it.
|
|
425
690
|
const resolved = await resolveBapiInvocation(projectRoot, {
|
|
@@ -429,6 +694,7 @@ export async function runMcpInvokeCli(argv, overrides = {}) {
|
|
|
429
694
|
resolveRepoName,
|
|
430
695
|
resolveCredentials,
|
|
431
696
|
baseUrl,
|
|
697
|
+
...(referenceOverlay && Object.keys(referenceOverlay).length > 0 ? { referenceOverlay } : {}),
|
|
432
698
|
});
|
|
433
699
|
if (!resolved.ok) {
|
|
434
700
|
stderr(`Error: ${resolved.error}`);
|
|
@@ -447,6 +713,17 @@ export async function runMcpInvokeCli(argv, overrides = {}) {
|
|
|
447
713
|
readBridgeConfig: readConfig,
|
|
448
714
|
getTargetDefinition,
|
|
449
715
|
resolveTargetEnv,
|
|
716
|
+
...(references
|
|
717
|
+
? {
|
|
718
|
+
references,
|
|
719
|
+
stderr,
|
|
720
|
+
resolveRepoName: overrides.resolveRepoName ??
|
|
721
|
+
((pr) => resolveRepoNameForProjectRoot(pr, {
|
|
722
|
+
readFile: (p) => readFile(p, "utf-8"),
|
|
723
|
+
runCommand: defaultRunCommand,
|
|
724
|
+
})),
|
|
725
|
+
}
|
|
726
|
+
: {}),
|
|
450
727
|
});
|
|
451
728
|
if (!resolved.ok) {
|
|
452
729
|
stderr(`Error: ${resolved.error}`);
|
|
@@ -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
|
+
}
|