@bridge_gpt/mcp-server 0.2.71 → 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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -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/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- 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 +187 -28
- 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 +213 -13
- 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 +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- 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 +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- 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/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- 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 +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- 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-install-state.js +68 -2
- 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 +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- 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 +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -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/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** One run's secret-bearing credential decision. Nothing here is a printable result. */
|
|
2
|
+
import { askSetupQuestion, askPlainSetupQuestion } from "./setup-question.js";
|
|
3
|
+
import { classifySetupAction } from "./setup-change-policy.js";
|
|
4
|
+
import { resolveBapiCredentials, readStoredBindingState } from "./credential-store.js";
|
|
5
|
+
const endpoint = (value) => value.trim().replace(/\/+$/, "");
|
|
6
|
+
/** Every consequential question uses the shared effect classifier and explained-question contract. */
|
|
7
|
+
export async function authorizeMaintenanceEffect(action, terminal, evidence, consequences, presentation) {
|
|
8
|
+
const classification = classifySetupAction(action);
|
|
9
|
+
if (classification === "routine" || classification === "no-op")
|
|
10
|
+
return true;
|
|
11
|
+
if (classification === "missing-information")
|
|
12
|
+
return false;
|
|
13
|
+
if (presentation) {
|
|
14
|
+
const plain = {
|
|
15
|
+
question: presentation.question,
|
|
16
|
+
options: [{ id: "yes", label: "Yes, allow it", aliases: ["y"] },
|
|
17
|
+
{ id: "no", label: "No, keep the existing approval", aliases: ["n"] }],
|
|
18
|
+
recommended: "no",
|
|
19
|
+
recordingFlag: "rerun setup interactively to record this choice",
|
|
20
|
+
evidence: presentation.details,
|
|
21
|
+
summary: [presentation.recommendationReason, presentation.consequence],
|
|
22
|
+
consequences: [],
|
|
23
|
+
recovery: presentation.recovery,
|
|
24
|
+
};
|
|
25
|
+
// A reader exists only on an interactive terminal; the plain asker needs the flag.
|
|
26
|
+
const decision = await askPlainSetupQuestion(plain, { ...terminal, isTTY: !!terminal.read });
|
|
27
|
+
return decision.status === "selected" && decision.id === "yes";
|
|
28
|
+
}
|
|
29
|
+
const decision = await askSetupQuestion({ purpose: action.effect, evidence,
|
|
30
|
+
options: [{ id: "yes", label: "Authorize this change" }, { id: "no", label: "Preserve existing state" }],
|
|
31
|
+
consequences, deferred: "Only this change is deferred. Independent maintenance remains available.",
|
|
32
|
+
recovery: "Rerun interactively after checking the affected project and destination." }, terminal);
|
|
33
|
+
return decision.status === "accept";
|
|
34
|
+
}
|
|
35
|
+
export async function settleMaintenanceCredential(input) {
|
|
36
|
+
const { repoName, baseUrl, terminal, report } = input;
|
|
37
|
+
const store = { ...input.store, env: { ...input.store.env, BAPI_API_KEY: undefined } };
|
|
38
|
+
const stored = await resolveBapiCredentials(repoName, store);
|
|
39
|
+
if (!stored.ok && stored.kind !== "not-found" && stored.kind !== "missing-key") {
|
|
40
|
+
return { ok: false, reason: `Saved credential ${stored.kind}; repair the credential store before reconnecting. Signup was not selected.` };
|
|
41
|
+
}
|
|
42
|
+
const observedKey = stored.ok ? stored.credentials.apiKey : null;
|
|
43
|
+
const binding = await readStoredBindingState(`bapi:${repoName}`, store);
|
|
44
|
+
if (binding.state === "unreadable" || binding.state === "invalid")
|
|
45
|
+
return { ok: false, reason: "Saved endpoint approval is unreadable or invalid; repair it before reconnecting." };
|
|
46
|
+
const storedEndpoint = binding.state === "bound" ? binding.baseUrl : input.productionBaseUrl;
|
|
47
|
+
const hosts = input.hosts.filter(host => host.repo === repoName);
|
|
48
|
+
const existing = [
|
|
49
|
+
...(observedKey ? [{ key: observedKey, source: "store", label: "saved credential", baseUrl: storedEndpoint }] : []),
|
|
50
|
+
...hosts.map(host => ({ key: host.key, source: "host", label: host.source, baseUrl: host.baseUrl ?? input.productionBaseUrl })),
|
|
51
|
+
];
|
|
52
|
+
let retained = existing[0];
|
|
53
|
+
let reconcileHosts = false;
|
|
54
|
+
if (new Set(existing.map(item => item.key)).size > 1) {
|
|
55
|
+
const choices = existing.filter((item, index) => existing.findIndex(other => other.key === item.key) === index);
|
|
56
|
+
const decision = await askSetupQuestion({ purpose: "Reconcile conflicting installed Bridge credentials",
|
|
57
|
+
evidence: choices.map(item => `${item.label}: project ${repoName}; destination ${endpoint(item.baseUrl) === endpoint(baseUrl) ? baseUrl : "a different configured endpoint (details withheld)"}`),
|
|
58
|
+
options: choices.map((item, i) => ({ id: String(i + 1), label: `Use ${item.label}` })),
|
|
59
|
+
consequences: ["Selected host bindings and the saved credential will use the chosen identity after validation. No credential value is displayed."],
|
|
60
|
+
deferred: "All conflicting bindings remain unchanged; independent assets can still be refreshed.",
|
|
61
|
+
recovery: "Inspect the configured projects and rerun interactively." }, terminal);
|
|
62
|
+
if (decision.status !== "selected")
|
|
63
|
+
return { ok: false, reason: "Installed credential conflict remains unresolved; existing bindings preserved." };
|
|
64
|
+
retained = choices[Number(decision.id) - 1];
|
|
65
|
+
reconcileHosts = true;
|
|
66
|
+
}
|
|
67
|
+
let candidate = input.candidate ?? (retained ? { key: retained.key, source: retained.source } : undefined);
|
|
68
|
+
if (reconcileHosts && retained && candidate && existing.some(item => item.key === candidate.key))
|
|
69
|
+
candidate = { key: retained.key, source: retained.source };
|
|
70
|
+
if (!candidate?.key)
|
|
71
|
+
return { ok: false, reason: stored.ok ? "No usable installed credential." : `Saved credential ${stored.kind}; supply a token for this project or use an explicit onboarding route.` };
|
|
72
|
+
const sameEndpoint = (value) => endpoint(value) === endpoint(baseUrl);
|
|
73
|
+
const inheritedPair = typeof input.originalEnvironment.BAPI_BASE_URL === "string" && sameEndpoint(input.originalEnvironment.BAPI_BASE_URL);
|
|
74
|
+
const observedCandidate = existing.find(item => item.key === candidate.key);
|
|
75
|
+
const transferNeeded = observedCandidate ? !sameEndpoint(observedCandidate.baseUrl)
|
|
76
|
+
: candidate.source === "env" && !inheritedPair && !sameEndpoint(input.productionBaseUrl);
|
|
77
|
+
let transferred = false;
|
|
78
|
+
if (transferNeeded) {
|
|
79
|
+
const sourceName = candidate.source === "store" ? "saved store" : candidate.source === "host" ? "host configuration" : candidate.source === "env" ? "environment" : candidate.source;
|
|
80
|
+
transferred = await authorizeMaintenanceEffect({ category: "credential", state: { status: "present", identity: repoName },
|
|
81
|
+
unchanged: false, context: baseUrl, effect: "Authorize the credential for this Bridge destination?", repository: repoName, trusted: true }, terminal, [`Project: ${repoName}`, `Credential source: ${candidate.source}`, `Destination: ${baseUrl}`, "Account and wider credential scope: unknown until validation"], ["Authenticated validation sends the credential to this destination. Saving approval replaces its previous endpoint binding; this does not authorize a different identity."], { question: `Allow setup to use the Bridge key for ${repoName} at ${baseUrl}?`,
|
|
82
|
+
recommendationReason: "Recommended: No. The key should not be sent to a different destination without your approval.",
|
|
83
|
+
consequence: `Yes sends the key to ${baseUrl} to check it, and remembers that this key is approved for ${baseUrl}.`,
|
|
84
|
+
details: [`Project: ${repoName}`, `Key source: ${sourceName}`, `Destination: ${baseUrl}`,
|
|
85
|
+
"The account and what else the key can do are not known until the key is checked.",
|
|
86
|
+
"This does not approve a different key."],
|
|
87
|
+
recovery: "Choosing No keeps the existing approval. Rerun setup to decide again." });
|
|
88
|
+
if (!transferred) {
|
|
89
|
+
if (!retained || !sameEndpoint(retained.baseUrl))
|
|
90
|
+
return { ok: false, reason: "Endpoint transfer deferred; retained credential is unavailable to this destination." };
|
|
91
|
+
candidate = { key: retained.key, source: retained.source };
|
|
92
|
+
if (input.originalEnvironment.BAPI_API_KEY)
|
|
93
|
+
report("Environment candidate declined. Unset BAPI_API_KEY in future shells to use the saved identity.");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let validated = false;
|
|
97
|
+
const different = !!retained && candidate.key !== retained.key;
|
|
98
|
+
if (different || transferred || reconcileHosts) {
|
|
99
|
+
try {
|
|
100
|
+
validated = await input.validate(candidate.key);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
validated = false;
|
|
104
|
+
}
|
|
105
|
+
if (reconcileHosts && !validated)
|
|
106
|
+
return { ok: false, reason: "Chosen installed credential could not be validated; conflicting bindings remain unchanged." };
|
|
107
|
+
let accepted = validated;
|
|
108
|
+
if (different && validated)
|
|
109
|
+
accepted = await authorizeMaintenanceEffect({ category: "credential", state: { status: "present", identity: repoName },
|
|
110
|
+
unchanged: false, context: baseUrl, effect: "Replace the installed Bridge credential?", repository: repoName, trusted: true }, terminal, [`Project: ${repoName}`, `Destination: ${baseUrl}`, "Candidate access validated through /jira/ping. Account and wider scope metadata remain unknown."], ["The saved credential, selected host bindings, future requests and launches will use the replacement. Optional declined capabilities remain unavailable."]);
|
|
111
|
+
if (!accepted) {
|
|
112
|
+
if (!retained || !sameEndpoint(retained.baseUrl))
|
|
113
|
+
return { ok: false, reason: "Candidate validation or replacement deferred; no usable retained identity for this destination." };
|
|
114
|
+
candidate = { key: retained.key, source: retained.source };
|
|
115
|
+
validated = false;
|
|
116
|
+
transferred = false;
|
|
117
|
+
reconcileHosts = false;
|
|
118
|
+
report("Candidate validation failed or replacement was declined; installed identity preserved.");
|
|
119
|
+
if (input.originalEnvironment.BAPI_API_KEY)
|
|
120
|
+
report("Unset BAPI_API_KEY in future shells to use the saved identity.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, identity: { repoName, baseUrl, apiKey: candidate.key, source: candidate.source,
|
|
124
|
+
observedKey, persist: candidate.key !== observedKey, bindEndpoint: transferred || (candidate.key !== observedKey && !sameEndpoint(input.productionBaseUrl)),
|
|
125
|
+
replacementAccepted: (different && candidate.key !== retained?.key) || reconcileHosts,
|
|
126
|
+
validation: validated ? "validated" : "required" } };
|
|
127
|
+
}
|
package/build/install-reexec.js
CHANGED
|
@@ -170,7 +170,7 @@ export function prepareInstallReexecArguments(argv) {
|
|
|
170
170
|
* 1. Strip sentinels (before anything reads argv).
|
|
171
171
|
* 2. If a sentinel was present, or the first remaining token is `conductor`,
|
|
172
172
|
* delegate straight to the local installer — no registry lookup, no spawn.
|
|
173
|
-
* The nested `install
|
|
173
|
+
* The nested `install epic-implementer` surface is intercepted inside
|
|
174
174
|
* `runInstallBridgeCli`, so it must reach it as `["conductor", ...]` rather
|
|
175
175
|
* than being collapsed into bare onboarding.
|
|
176
176
|
* 3. Otherwise look up the latest version, defaulting the comparison target to
|
|
@@ -20,12 +20,20 @@
|
|
|
20
20
|
* Secret safety: an inspection result carries only sanitized launcher facts —
|
|
21
21
|
* relative path, launcher shape, the package spec token, and versions. It never
|
|
22
22
|
* carries config bodies, `env` maps, credential values, or raw error text.
|
|
23
|
+
*
|
|
24
|
+
* BAPI-1636 adds a separate destination section
|
|
25
|
+
* ({@link detectEffectiveBridgeDestination}). It is binding INSPECTION, not
|
|
26
|
+
* credential resolution: it reads only `BAPI_BASE_URL` and the stored binding
|
|
27
|
+
* state a caller already obtained through `readStoredBindingState()`. It never
|
|
28
|
+
* reads `BAPI_API_KEY`, and it takes no launcher fact, so a launcher's shape can
|
|
29
|
+
* never decide where Bridge points.
|
|
23
30
|
*/
|
|
24
31
|
import path from "path";
|
|
25
32
|
import { codexHome, isCodexHomeOverrideHonored } from "./codex-home.js";
|
|
26
33
|
import { inspectCodexLauncher } from "./codex-launcher-pin.js";
|
|
34
|
+
import { normalizeBoundBaseUrl } from "./credential-store.js";
|
|
27
35
|
import { getProjectJsonTargets, hostAdapterForTarget, MCP_HOST_TARGETS, } from "./mcp-host-targets.js";
|
|
28
|
-
import { LEGACY_SERVER_NAMES, MCP_SERVER_NAME, MCP_PACKAGE_NAME, resolveRegistrationKey, WORKTREE_SHIM_TOKEN, } from "./mcp-identity.js";
|
|
36
|
+
import { isLocalBuildLauncher, LEGACY_SERVER_NAMES, MCP_SERVER_NAME, MCP_PACKAGE_NAME, resolveRegistrationKey, WORKTREE_SHIM_TOKEN, } from "./mcp-identity.js";
|
|
29
37
|
/**
|
|
30
38
|
* The npm package every Bridge launcher spec names. Retained as a compatibility
|
|
31
39
|
* alias — `doctor.ts` still imports this name — assigned from the shared
|
|
@@ -340,6 +348,17 @@ async function inspectOne(target, options) {
|
|
|
340
348
|
action: "skip-worktree-shim",
|
|
341
349
|
};
|
|
342
350
|
}
|
|
351
|
+
// BAPI-1636: a local build has no package token either. Detected after the
|
|
352
|
+
// shim and before the token requirement, so it is preserved, not refused.
|
|
353
|
+
if (isLocalBuildLauncher(entry.command, args)) {
|
|
354
|
+
return {
|
|
355
|
+
...keyed,
|
|
356
|
+
filePresent: true,
|
|
357
|
+
bridgeEntryPresent: true,
|
|
358
|
+
shape: "local-build",
|
|
359
|
+
action: "skip-local-build",
|
|
360
|
+
};
|
|
361
|
+
}
|
|
343
362
|
const pin = parseLauncherPin(args);
|
|
344
363
|
if (!pin) {
|
|
345
364
|
return {
|
|
@@ -516,6 +535,16 @@ export async function inspectGlobalLauncherConfigs(options) {
|
|
|
516
535
|
shape: "worktree-shim",
|
|
517
536
|
action: "skip-worktree-shim",
|
|
518
537
|
};
|
|
538
|
+
case "local-build":
|
|
539
|
+
return {
|
|
540
|
+
...base,
|
|
541
|
+
filePresent: true,
|
|
542
|
+
bridgeEntryPresent: true,
|
|
543
|
+
registrationKey: found.registrationName,
|
|
544
|
+
legacyRegistration: found.registrationName !== MCP_SERVER_NAME,
|
|
545
|
+
shape: "local-build",
|
|
546
|
+
action: "skip-local-build",
|
|
547
|
+
};
|
|
519
548
|
case "located": {
|
|
520
549
|
const keyed = {
|
|
521
550
|
...base,
|
|
@@ -541,6 +570,138 @@ export async function inspectGlobalLauncherConfigs(options) {
|
|
|
541
570
|
}
|
|
542
571
|
}
|
|
543
572
|
}
|
|
573
|
+
/** Fixed, value-free reasons. Never an URL, a key, or an error message. */
|
|
574
|
+
export const BRIDGE_DESTINATION_REASON_TEXT = {
|
|
575
|
+
production_default: "no BAPI_BASE_URL and no stored binding, so the production default applies",
|
|
576
|
+
stored_binding: "the stored credential binding names the endpoint",
|
|
577
|
+
environment_only: "BAPI_BASE_URL names the endpoint and no stored credential exists",
|
|
578
|
+
environment_production: "BAPI_BASE_URL names production and the stored key has no binding",
|
|
579
|
+
environment_corroborated: "BAPI_BASE_URL and the stored credential binding name the same endpoint",
|
|
580
|
+
environment_binding_conflict: "BAPI_BASE_URL and the stored credential binding name different endpoints",
|
|
581
|
+
environment_unbound_conflict: "BAPI_BASE_URL names a non-production endpoint, but the stored key has no binding",
|
|
582
|
+
environment_malformed: "BAPI_BASE_URL is not a usable http(s) URL",
|
|
583
|
+
binding_malformed: "the stored credential binding is present but invalid",
|
|
584
|
+
binding_unreadable: "the credential store could not be read",
|
|
585
|
+
production_malformed: "the production URL is not a usable http(s) URL",
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* The Bridge origins named anywhere in the destination evidence, valid ones
|
|
589
|
+
* only, for the grant classifier. It is kept even on a conflict or a malformed
|
|
590
|
+
* result, so a candidate that names any of them fails toward exclusion. It holds
|
|
591
|
+
* no user info, path, query, or fragment, and it refuses to serialize.
|
|
592
|
+
*/
|
|
593
|
+
export class BridgeDestinationEvidence {
|
|
594
|
+
#origins;
|
|
595
|
+
constructor(origins) {
|
|
596
|
+
this.#origins = new Set(origins);
|
|
597
|
+
}
|
|
598
|
+
/** True when `value` is an http(s) URL whose scheme, host, and effective port match a known origin. */
|
|
599
|
+
matchesUrl(value) {
|
|
600
|
+
const origin = bridgeUrlOrigin(value);
|
|
601
|
+
return origin !== null && this.#origins.has(origin);
|
|
602
|
+
}
|
|
603
|
+
/** How many distinct origins the evidence names. */
|
|
604
|
+
get size() {
|
|
605
|
+
return this.#origins.size;
|
|
606
|
+
}
|
|
607
|
+
toJSON() {
|
|
608
|
+
return "[redacted]";
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/** Parse an http(s) URL, or null. Never throws. */
|
|
612
|
+
function parseHttpUrl(value) {
|
|
613
|
+
if (typeof value !== "string")
|
|
614
|
+
return null;
|
|
615
|
+
try {
|
|
616
|
+
const url = new URL(value.trim());
|
|
617
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url : null;
|
|
618
|
+
}
|
|
619
|
+
catch {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* The comparison key for an http(s) URL: scheme, host, and effective port. Path,
|
|
625
|
+
* user info, query, and fragment are ignored. Null for anything else. No DNS.
|
|
626
|
+
*/
|
|
627
|
+
export function bridgeUrlOrigin(value) {
|
|
628
|
+
const url = parseHttpUrl(value);
|
|
629
|
+
if (url === null)
|
|
630
|
+
return null;
|
|
631
|
+
const port = url.port !== "" ? url.port : url.protocol === "https:" ? "443" : "80";
|
|
632
|
+
return `${url.protocol}//${url.hostname}:${port}`;
|
|
633
|
+
}
|
|
634
|
+
/** Scheme, host, port, and path only, with trailing slashes dropped. */
|
|
635
|
+
function projectDestination(url) {
|
|
636
|
+
return `${url.protocol}//${url.host}${url.pathname}`.replace(/\/+$/, "");
|
|
637
|
+
}
|
|
638
|
+
/** True for `localhost`, `127.0.0.0/8`, and `::1`. Decided from the text alone. */
|
|
639
|
+
function isLoopbackHost(hostname) {
|
|
640
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost"))
|
|
641
|
+
return true;
|
|
642
|
+
if (hostname === "[::1]")
|
|
643
|
+
return true;
|
|
644
|
+
return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Report the effective Bridge destination from the same facts
|
|
648
|
+
* `resolveEpicLaunchCredential()` uses: `BAPI_BASE_URL`, the stored binding, and
|
|
649
|
+
* the production URL. Read-only and pure; it chooses no local behavior. On a
|
|
650
|
+
* conflict or a malformed fact, the caller that would act on the destination
|
|
651
|
+
* defers that operation and reports the fixed reason.
|
|
652
|
+
*/
|
|
653
|
+
export function detectEffectiveBridgeDestination(input) {
|
|
654
|
+
const envRaw = normalizeBoundBaseUrl(input.envBaseUrl);
|
|
655
|
+
const envUrl = parseHttpUrl(envRaw);
|
|
656
|
+
const productionRaw = normalizeBoundBaseUrl(input.productionBaseUrl);
|
|
657
|
+
const productionUrl = parseHttpUrl(productionRaw);
|
|
658
|
+
const boundRaw = input.binding.state === "bound" ? normalizeBoundBaseUrl(input.binding.baseUrl) : null;
|
|
659
|
+
const boundUrl = parseHttpUrl(boundRaw);
|
|
660
|
+
const origins = [];
|
|
661
|
+
for (const url of [envUrl, productionUrl, boundUrl]) {
|
|
662
|
+
if (url !== null)
|
|
663
|
+
origins.push(bridgeUrlOrigin(url.href));
|
|
664
|
+
}
|
|
665
|
+
const evidence = new BridgeDestinationEvidence(origins);
|
|
666
|
+
const fail = (state, reason) => ({ state, reason, evidence });
|
|
667
|
+
if (envRaw !== null && envUrl === null)
|
|
668
|
+
return fail("malformed", "environment_malformed");
|
|
669
|
+
if (input.binding.state === "invalid")
|
|
670
|
+
return fail("malformed", "binding_malformed");
|
|
671
|
+
if (input.binding.state === "unreadable")
|
|
672
|
+
return fail("malformed", "binding_unreadable");
|
|
673
|
+
if (boundRaw !== null && boundUrl === null)
|
|
674
|
+
return fail("malformed", "binding_malformed");
|
|
675
|
+
if (productionUrl === null)
|
|
676
|
+
return fail("malformed", "production_malformed");
|
|
677
|
+
const resolved = (url, suppliedBy, reason) => {
|
|
678
|
+
const baseUrl = projectDestination(url);
|
|
679
|
+
const kind = baseUrl === projectDestination(productionUrl)
|
|
680
|
+
? "production"
|
|
681
|
+
: isLoopbackHost(url.hostname)
|
|
682
|
+
? "local"
|
|
683
|
+
: "non_production";
|
|
684
|
+
return { state: "resolved", baseUrl, kind, suppliedBy, reason, evidence };
|
|
685
|
+
};
|
|
686
|
+
if (envUrl === null) {
|
|
687
|
+
if (boundUrl !== null)
|
|
688
|
+
return resolved(boundUrl, "stored-binding", "stored_binding");
|
|
689
|
+
return resolved(productionUrl, "production-default", "production_default");
|
|
690
|
+
}
|
|
691
|
+
switch (input.binding.state) {
|
|
692
|
+
case "no-entry":
|
|
693
|
+
return resolved(envUrl, "environment", "environment_only");
|
|
694
|
+
case "bound":
|
|
695
|
+
return envRaw === boundRaw
|
|
696
|
+
? resolved(envUrl, "environment-and-binding", "environment_corroborated")
|
|
697
|
+
: fail("conflict", "environment_binding_conflict");
|
|
698
|
+
case "absent":
|
|
699
|
+
// Production needs no binding; any other endpoint does (BAPI-1272).
|
|
700
|
+
return envRaw === productionRaw
|
|
701
|
+
? resolved(envUrl, "environment", "environment_production")
|
|
702
|
+
: fail("conflict", "environment_unbound_conflict");
|
|
703
|
+
}
|
|
704
|
+
}
|
|
544
705
|
// ---------------------------------------------------------------------------
|
|
545
706
|
// Effective Claude Code pin (BAPI-1446)
|
|
546
707
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Shared bounded process and default-deny consent boundaries for local cleanup. */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
export async function confirmLocalCleanup(question) {
|
|
5
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
6
|
+
return false;
|
|
7
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
8
|
+
try {
|
|
9
|
+
return /^(y|yes)$/i.test((await rl.question(`${question} (y/N) `)).trim());
|
|
10
|
+
}
|
|
11
|
+
finally {
|
|
12
|
+
rl.close();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function runLocalCommand(executable, args, cwd, timeoutMs = 10_000) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const child = spawn(executable, args, { cwd, shell: false, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"] });
|
|
18
|
+
const stdout = [], stderr = [];
|
|
19
|
+
let bytes = 0, finished = false;
|
|
20
|
+
const finish = (exitCode) => {
|
|
21
|
+
if (finished)
|
|
22
|
+
return;
|
|
23
|
+
finished = true;
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
resolve({ exitCode, stdout: Buffer.concat(stdout).toString("utf8"), stderr: Buffer.concat(stderr).toString("utf8") });
|
|
26
|
+
};
|
|
27
|
+
const terminate = () => {
|
|
28
|
+
// Git can spawn an SSH helper. Kill this invocation's own process group,
|
|
29
|
+
// so a timed-out observation cannot leave that helper behind on POSIX.
|
|
30
|
+
try {
|
|
31
|
+
if (process.platform !== "win32" && child.pid)
|
|
32
|
+
process.kill(-child.pid, "SIGKILL");
|
|
33
|
+
else
|
|
34
|
+
child.kill("SIGKILL");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
child.kill("SIGKILL");
|
|
38
|
+
}
|
|
39
|
+
child.stdout.destroy();
|
|
40
|
+
child.stderr.destroy();
|
|
41
|
+
finish(-1);
|
|
42
|
+
};
|
|
43
|
+
const timer = setTimeout(terminate, Math.max(1, Math.min(timeoutMs, 10_000)));
|
|
44
|
+
const collect = (chunks, chunk) => {
|
|
45
|
+
if (finished)
|
|
46
|
+
return;
|
|
47
|
+
bytes += chunk.length;
|
|
48
|
+
if (bytes > 1024 * 1024) {
|
|
49
|
+
terminate();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
chunks.push(chunk);
|
|
53
|
+
};
|
|
54
|
+
child.stdout.on("data", (chunk) => collect(stdout, chunk));
|
|
55
|
+
child.stderr.on("data", (chunk) => collect(stderr, chunk));
|
|
56
|
+
child.on("error", () => finish(-1));
|
|
57
|
+
child.on("close", (code) => finish(code ?? -1));
|
|
58
|
+
});
|
|
59
|
+
}
|