@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
package/build/install-bridge.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readMcpInstallState } from "./mcp-install-state.js";
|
|
2
2
|
import { askSetupQuestion } from "./setup-question.js";
|
|
3
|
-
import { bindEpicLaunchCredential, resolveEpicLaunchCredential } from "./credential-store.js";
|
|
3
|
+
import { bindEpicLaunchCredential, normalizeBoundBaseUrl, readStoredBindingState, resolveEpicLaunchCredential } from "./credential-store.js";
|
|
4
4
|
import { settleMaintenanceCredential, authorizeMaintenanceEffect } from "./install-maintenance.js";
|
|
5
5
|
import { validateBootstrapDisplayName, validateBootstrapServerIdentity } from "./bootstrap-project-identity.js";
|
|
6
6
|
import { BRIDGE_SUPPORT_EMAIL, archiveAndReplaceModernBootstrapSignup, archiveExpiredLegacySignupAndInstallModern, lookupModernBootstrapRecord, mutateModernBootstrapRecord, prepareModernBootstrapInvite, prepareModernBootstrapSignup, transitionModernBootstrapSignup, lookupLegacyBootstrapInvite, checkpointModernBootstrapIdentity, promoteModernBootstrapCredential } from "./credential-store.js";
|
|
@@ -149,17 +149,25 @@ import { spawn } from "child_process";
|
|
|
149
149
|
import { randomBytes as cryptoRandomBytes, createHash } from "crypto";
|
|
150
150
|
import os from "os";
|
|
151
151
|
import path from "path";
|
|
152
|
+
import { discoverMcpGrantCandidates, publishMcpGrant } from "./mcp-grant-candidates.js";
|
|
153
|
+
import { readMcpGrant } from "./mcp-grant.js";
|
|
154
|
+
import { readEpicServerRecord, writeEpicServerRecord } from "./epic-server-record.js";
|
|
155
|
+
import { readEpicServerGuidance } from "./conductor/epic-server-guidance.js";
|
|
156
|
+
import { writeEpicCapabilityStatement } from "./conductor/bridge-api-client.js";
|
|
152
157
|
import { detectClaudeLogin } from "./claude-login.js";
|
|
153
158
|
import { checkGithubSignIn } from "./github-sign-in.js";
|
|
154
159
|
import { readLocalGithubRemote } from "./conductor/stored-merge-credential.js";
|
|
155
160
|
import { probeStoredMergeToken } from "./conductor/stored-merge-token-probe.js";
|
|
156
161
|
import { readGithubMergeCredential, removeGithubMergeCredential, upsertGithubMergeCredential, } from "./credential-store.js";
|
|
157
162
|
import { createBridgeApiUrls } from "./bridge-api-urls.js";
|
|
163
|
+
import { installCiTriggerEdit } from "./ci-trigger-install.js";
|
|
158
164
|
import { installEpicCiWorkflow } from "./epic-ci-workflow-install.js";
|
|
159
|
-
import { fetchParseStatus,
|
|
165
|
+
import { fetchParseStatus, fetchSetupRecoveryEvidence, correctSetupBranch, admitSetupRecovery, } from "./conductor/bridge-api-client.js";
|
|
160
166
|
import readline from "readline";
|
|
161
167
|
import { runInit, InitPreflightError, buildBridgeApiEntry, buildBridgeConfigManifest, mergeBridgeApiProfileToken, resolveInitScaffoldAssets, refreshBridgeApiPackageSpec, currentBridgePackageSpec, classifyTrackedProbeExitCode, decideExistingProjectRoot, formatUndeterminedRootReplacedWarning, } from "./init.js";
|
|
162
168
|
import { hasProjectRootMarker as sharedHasProjectRootMarker } from "./project-root.js";
|
|
169
|
+
import { resolveDocsDirForRoot } from "./project-root.js";
|
|
170
|
+
import { createSetupRecordWriter } from "./install-bridge-conductor-apply.js";
|
|
163
171
|
import { VERSION } from "./version.generated.js";
|
|
164
172
|
import { bridgeConfigPath, parseBridgeConfigToml, rewriteBridgeConfigRepoName, validateBridgeConfigRepoNameRepresentability, validateRepoName, } from "./bridge-config.js";
|
|
165
173
|
import { renderDiagnosticValue } from "./diagnostic-text.js";
|
|
@@ -167,7 +175,9 @@ import { MCP_HOST_TARGETS, HOST_PLATFORM_ORDER, allHostTargets, agentForPlatform
|
|
|
167
175
|
import { provisionHostTarget, createDefaultVendorProcessDeps, inspectBridgeApiProfileToken, } from "./mcp-host-config.js";
|
|
168
176
|
import { adaptBridgeEntryForHostTarget, } from "./mcp-host-entry-adapter.js";
|
|
169
177
|
import { MCP_SERVER_NAME, MCP_PACKAGE_NAME, resolveRegistrationKey, } from "./mcp-identity.js";
|
|
170
|
-
import { DUPLICATE_REGISTRATION_GUIDANCE, discoverClaudeCodeEffectivePin } from "./launcher-config-inspection.js";
|
|
178
|
+
import { detectEffectiveBridgeDestination, DUPLICATE_REGISTRATION_GUIDANCE, discoverClaudeCodeEffectivePin } from "./launcher-config-inspection.js";
|
|
179
|
+
import { createCommandDriftInspector } from "./conductor/command-drift-production.js";
|
|
180
|
+
import { localBuildSetupLauncher } from "./install-bridge-conductor-setup.js";
|
|
171
181
|
import { codexHome, configureBridgeCodexProfile, inspectBridgeCodexProfile } from "./codex-bridge-profile.js";
|
|
172
182
|
import { recordInstalledConductorCapability, recordInstalledExecutorServiceUnit, recordInstalledProjectArtifact, writeMcpInstallState, } from "./mcp-install-state.js";
|
|
173
183
|
// BAPI-1207: opt-in cross-platform agent notes (AGENTS.md / CLAUDE.md).
|
|
@@ -189,7 +199,7 @@ import { runExecutorCli } from "./executor/cli.js";
|
|
|
189
199
|
import { runExecutor } from "./executor/runner.js";
|
|
190
200
|
// BAPI-1136: the merge-workflow generate-and-PR installer. Domain logic lives in
|
|
191
201
|
// its own module; this file supplies the parser and the process seams.
|
|
192
|
-
import { parseGithubRemote, runMergeWorkflowInstall, } from "./merge-workflow-install.js";
|
|
202
|
+
import { captureDefaultBranchSnapshot, parseGithubRemote, readSnapshotFile, runMergeWorkflowInstall, } from "./merge-workflow-install.js";
|
|
193
203
|
import { MERGE_WORKFLOW_CODEOWNER_INSTRUCTION, MERGE_WORKFLOW_REMEDY_COMMAND, } from "./conductor/merge-execution-contract.js";
|
|
194
204
|
import { MERGE_WORKFLOW_API_KEY_SECRET_NAME, } from "./merge-workflow-config.js";
|
|
195
205
|
import { runConductorInstallDoctor, EPIC_IMPLEMENTER_PROFILE_TOKEN, } from "./conductor/install-doctor.js";
|
|
@@ -1674,6 +1684,29 @@ export function getMergeWorkflowInstallUsage() {
|
|
|
1674
1684
|
export function buildConductorSetupDeps(deps, log, errorLog) {
|
|
1675
1685
|
const installerDeps = buildMergeWorkflowInstallDeps(deps, log, errorLog);
|
|
1676
1686
|
const storeDeps = modernWriteDeps(deps);
|
|
1687
|
+
// BAPI-1636: one read-only discovery, used at assessment AND again at
|
|
1688
|
+
// publication, so the binding, every source config, the existing grant, and
|
|
1689
|
+
// local package identity are re-read just before anything is staged. A
|
|
1690
|
+
// conflicting or malformed destination is not a setup failure: its evidence
|
|
1691
|
+
// only makes the classifier exclude more.
|
|
1692
|
+
const discoverGrantCandidates = async (repoName) => {
|
|
1693
|
+
const binding = await readStoredBindingState(`bapi:${repoName}`, installerCredentialReadDeps(deps));
|
|
1694
|
+
const destination = detectEffectiveBridgeDestination({
|
|
1695
|
+
envBaseUrl: deps.env.BAPI_BASE_URL,
|
|
1696
|
+
binding,
|
|
1697
|
+
productionBaseUrl: DEFAULT_BAPI_BASE_URL,
|
|
1698
|
+
});
|
|
1699
|
+
return discoverMcpGrantCandidates({
|
|
1700
|
+
homedir: deps.homedir,
|
|
1701
|
+
platform: deps.platform,
|
|
1702
|
+
readFile: deps.readFile,
|
|
1703
|
+
cwd: deps.cwd,
|
|
1704
|
+
repoName,
|
|
1705
|
+
productionBaseUrl: DEFAULT_BAPI_BASE_URL,
|
|
1706
|
+
destination: destination.evidence,
|
|
1707
|
+
readGrant: () => readMcpGrant(repoName, { env: deps.env, homedir: deps.homedir, readFile: deps.readFile }),
|
|
1708
|
+
});
|
|
1709
|
+
};
|
|
1677
1710
|
return {
|
|
1678
1711
|
detectClaudeLogin: () => detectClaudeLogin({ homedir: deps.homedir, readFile: deps.readFile }),
|
|
1679
1712
|
// An injected installer runner (tests) is used for these reads too, so a
|
|
@@ -1699,18 +1732,85 @@ export function buildConductorSetupDeps(deps, log, errorLog) {
|
|
|
1699
1732
|
getGetHeaders: async () => ({ "X-API-Key": access.apiKey }),
|
|
1700
1733
|
getPostHeaders: async () => ({ "X-API-Key": access.apiKey, "Content-Type": "application/json" }),
|
|
1701
1734
|
}),
|
|
1735
|
+
// The person's working tree: optional test-command hints for the server only.
|
|
1702
1736
|
readRepositoryFile: (relPath) => deps.readFile(path.join(deps.cwd, relPath)),
|
|
1703
|
-
|
|
1737
|
+
// BAPI-1603: everything the workflow is built from comes from the remote
|
|
1738
|
+
// default branch. One quiet capture, one immutable head, bounded read-only reads at it.
|
|
1739
|
+
captureDefaultBranch: async () => {
|
|
1740
|
+
const captured = await captureDefaultBranchSnapshot({ ...installerDeps, log: () => { }, errorLog: () => { } });
|
|
1741
|
+
return captured.ok ? captured.snapshot : null;
|
|
1742
|
+
},
|
|
1743
|
+
readSnapshotFile: (snapshot, relPath) => readSnapshotFile(installerDeps, snapshot, relPath),
|
|
1744
|
+
installCiWorkflow: (testCommand, toolchains, options, confirmWrite) => installEpicCiWorkflow(testCommand, toolchains, {
|
|
1745
|
+
dryRun: options.dryRun,
|
|
1746
|
+
...(options.snapshot !== undefined ? { snapshot: options.snapshot } : {}),
|
|
1747
|
+
...(options.createOnly === true ? { createOnly: true } : {}),
|
|
1748
|
+
}, {
|
|
1704
1749
|
...installerDeps,
|
|
1705
1750
|
...(options.quiet === true ? { log: () => { }, errorLog: () => { } } : {}),
|
|
1706
1751
|
confirmWrite,
|
|
1707
1752
|
}),
|
|
1753
|
+
// BAPI-1654: the CI-only pull request for an approved trigger edit, through the same engine.
|
|
1754
|
+
installCiTriggerEdit: (edit, options, confirmWrite) => installCiTriggerEdit(edit, { dryRun: options.dryRun, ...(options.snapshot !== undefined ? { snapshot: options.snapshot } : {}) }, { ...installerDeps, confirmWrite }),
|
|
1708
1755
|
runGh: installerDeps.runGh,
|
|
1756
|
+
// BAPI-1635: committed command, agent, and host-mirror drift, read-only (the probe
|
|
1757
|
+
// `doctor` and `readiness` already use, now over the installer's rendered asset catalog).
|
|
1758
|
+
inspectCommandDrift: createCommandDriftInspector({ env: deps.env, cwd: deps.cwd, fetch: deps.fetch }),
|
|
1759
|
+
// BAPI-1635: the local-build command form is chosen only from the same effective
|
|
1760
|
+
// destination detection the MCP grant uses (kind `local`) AND a validated local-build
|
|
1761
|
+
// entry. Anything else, including a conflict or malformed destination, prints the npm form.
|
|
1762
|
+
detectLauncher: async (repoName) => {
|
|
1763
|
+
const entry = process.argv[1];
|
|
1764
|
+
if (typeof entry !== "string")
|
|
1765
|
+
return null;
|
|
1766
|
+
const binding = await readStoredBindingState(`bapi:${repoName}`, installerCredentialReadDeps(deps));
|
|
1767
|
+
const destination = detectEffectiveBridgeDestination({
|
|
1768
|
+
envBaseUrl: deps.env.BAPI_BASE_URL,
|
|
1769
|
+
binding,
|
|
1770
|
+
productionBaseUrl: DEFAULT_BAPI_BASE_URL,
|
|
1771
|
+
});
|
|
1772
|
+
return destination.state === "resolved" && destination.kind === "local" ? localBuildSetupLauncher(entry) : null;
|
|
1773
|
+
},
|
|
1709
1774
|
fetchParseStatus: (access) => fetchParseStatus(access, deps.fetch),
|
|
1710
|
-
triggerParse: (access) => triggerRepositoryParse(access, deps.fetch),
|
|
1711
1775
|
fetchRecoveryEvidence: (access, pr) => fetchSetupRecoveryEvidence(access, pr, deps.fetch),
|
|
1712
1776
|
correctBranch: (access, expected, destination) => correctSetupBranch(access, expected, destination, deps.fetch),
|
|
1713
1777
|
admitRecovery: (access, evidence, retry) => admitSetupRecovery(access, evidence, retry, deps.fetch),
|
|
1778
|
+
// BAPI-1545: the worker MCP grant and the advisory capability statement.
|
|
1779
|
+
mcpGrant: {
|
|
1780
|
+
discover: (repoName) => discoverGrantCandidates(repoName),
|
|
1781
|
+
readGrant: (repoName) => readMcpGrant(repoName, { env: deps.env, homedir: deps.homedir, readFile: deps.readFile }),
|
|
1782
|
+
readEpicServerRecord: (repoName) => readEpicServerRecord(repoName, { env: deps.env, homedir: deps.homedir, readFile: deps.readFile }),
|
|
1783
|
+
publish: (repoName, inventory, selectedIds, now) => publishMcpGrant(repoName, inventory, selectedIds, now, {
|
|
1784
|
+
rediscover: () => discoverGrantCandidates(repoName),
|
|
1785
|
+
credentialStore: storeDeps,
|
|
1786
|
+
grant: {
|
|
1787
|
+
env: deps.env,
|
|
1788
|
+
homedir: deps.homedir,
|
|
1789
|
+
platform: deps.platform,
|
|
1790
|
+
mkdir: deps.mkdir,
|
|
1791
|
+
chmod: deps.chmod,
|
|
1792
|
+
rename: deps.rename,
|
|
1793
|
+
open: deps.open,
|
|
1794
|
+
unlink: deps.unlink,
|
|
1795
|
+
},
|
|
1796
|
+
}),
|
|
1797
|
+
writeStatement: (access, statement) => writeEpicCapabilityStatement(access, statement, deps.fetch),
|
|
1798
|
+
},
|
|
1799
|
+
// BAPI-1546: the epic-server opt-in, its own record outside every worktree.
|
|
1800
|
+
epicServer: {
|
|
1801
|
+
readRecord: (repoName) => readEpicServerRecord(repoName, { env: deps.env, homedir: deps.homedir, readFile: deps.readFile }),
|
|
1802
|
+
writeRecord: (repoName, record) => writeEpicServerRecord(repoName, record, {
|
|
1803
|
+
env: deps.env,
|
|
1804
|
+
homedir: deps.homedir,
|
|
1805
|
+
platform: deps.platform,
|
|
1806
|
+
mkdir: deps.mkdir,
|
|
1807
|
+
chmod: deps.chmod,
|
|
1808
|
+
rename: deps.rename,
|
|
1809
|
+
open: deps.open,
|
|
1810
|
+
unlink: deps.unlink,
|
|
1811
|
+
}),
|
|
1812
|
+
guidancePresent: async () => (await readEpicServerGuidance((rel) => deps.readFile(path.join(deps.cwd, rel)))).state === "ok",
|
|
1813
|
+
},
|
|
1714
1814
|
};
|
|
1715
1815
|
}
|
|
1716
1816
|
export function buildMergeWorkflowInstallDeps(deps, log, errorLog) {
|
|
@@ -2067,6 +2167,39 @@ function installerCredentialReadDeps(deps) {
|
|
|
2067
2167
|
return { env: deps.env, homedir: deps.homedir, platform: deps.platform,
|
|
2068
2168
|
readFile: deps.readFile, stat: async (p) => await deps.stat(p), stderr: deps.errorLog };
|
|
2069
2169
|
}
|
|
2170
|
+
/**
|
|
2171
|
+
* BAPI-1650: for a dry run only, decide whether the credential resolver's result
|
|
2172
|
+
* means the owner has not yet approved a saved key for a non-production address.
|
|
2173
|
+
*
|
|
2174
|
+
* It runs after the one existing resolver call and reads only the stored binding
|
|
2175
|
+
* state, which holds an endpoint and no key. It never resolves a credential again,
|
|
2176
|
+
* compares key values, makes a network call, asks for consent, or writes. Only a
|
|
2177
|
+
* proven `absent` binding, or one bound to a different endpoint, counts; `invalid`,
|
|
2178
|
+
* `unreadable`, `no-entry`, and a binding that matches the target keep their
|
|
2179
|
+
* existing behavior. The metadata is built field by field, never spread.
|
|
2180
|
+
*/
|
|
2181
|
+
async function classifyEndpointApproval(repoName, target, credential, readDeps) {
|
|
2182
|
+
const normalized = normalizeBoundBaseUrl(target);
|
|
2183
|
+
if (normalized === null || normalized === normalizeBoundBaseUrl(DEFAULT_BAPI_BASE_URL))
|
|
2184
|
+
return undefined;
|
|
2185
|
+
let kind;
|
|
2186
|
+
if (credential.ok) {
|
|
2187
|
+
if (credential.binding !== "env-paired")
|
|
2188
|
+
return undefined;
|
|
2189
|
+
kind = "env-paired";
|
|
2190
|
+
}
|
|
2191
|
+
else if (credential.kind === "binding-unbound" || credential.kind === "binding-mismatch") {
|
|
2192
|
+
kind = credential.kind;
|
|
2193
|
+
}
|
|
2194
|
+
else {
|
|
2195
|
+
return undefined;
|
|
2196
|
+
}
|
|
2197
|
+
const state = await readStoredBindingState(`bapi:${repoName}`, readDeps);
|
|
2198
|
+
if (state.state === "absent" || (state.state === "bound" && state.baseUrl !== normalized)) {
|
|
2199
|
+
return { needed: true, repoName, target: normalized, kind };
|
|
2200
|
+
}
|
|
2201
|
+
return undefined;
|
|
2202
|
+
}
|
|
2070
2203
|
/** Project identity evidence is read before onboarding; folder names are never identity. */
|
|
2071
2204
|
export async function observeInstalledIdentity(deps) {
|
|
2072
2205
|
const candidates = [];
|
|
@@ -5516,13 +5649,16 @@ export function isMinttyNonInteractiveInstall(platform, env, isTTY) {
|
|
|
5516
5649
|
const msystem = env.MSYSTEM;
|
|
5517
5650
|
return (typeof msystem === "string" && msystem.trim().length > 0) || env.TERM_PROGRAM === "mintty";
|
|
5518
5651
|
}
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5652
|
+
async function refreshIndependentInstallAssets(deps, reason, presentation) {
|
|
5653
|
+
const compact = presentation?.mode === "compact";
|
|
5654
|
+
if (!compact)
|
|
5655
|
+
deps.errorLog(reason);
|
|
5522
5656
|
try {
|
|
5523
5657
|
await deps.runInit(deps.cwd, { assetsOnly: true, env: { ...deps.env, BAPI_API_KEY: undefined },
|
|
5524
|
-
stdout: deps.log, stderr: deps.errorLog });
|
|
5525
|
-
deps.log(
|
|
5658
|
+
stdout: compact && !presentation.verbose ? () => { } : deps.log, stderr: deps.errorLog });
|
|
5659
|
+
deps.log(compact
|
|
5660
|
+
? "Bridge assets refreshed; your identity, host bindings and preferences were kept."
|
|
5661
|
+
: "Independent Bridge assets refreshed. Existing identity, host bindings and preferences preserved; requested identity-dependent capabilities remain unavailable.");
|
|
5526
5662
|
}
|
|
5527
5663
|
catch {
|
|
5528
5664
|
deps.errorLog("Independent asset refresh failed; completed work was retained.");
|
|
@@ -5667,6 +5803,9 @@ export async function runInstallBridgeCli(argv, overrides = {}) {
|
|
|
5667
5803
|
return 1;
|
|
5668
5804
|
}
|
|
5669
5805
|
const conductorBaseUrl = baseUrlResult.value;
|
|
5806
|
+
// In `--json` mode stdout is reserved for the single JSON document the
|
|
5807
|
+
// conductor writes through `conductorDeps.log`; human narration goes to stderr.
|
|
5808
|
+
const humanOutputSink = argv.includes("--json") ? errorLog : log;
|
|
5670
5809
|
const conductorDeps = {
|
|
5671
5810
|
prerequisites: async (executorRequested) => {
|
|
5672
5811
|
const lookup = deps.lookupExecutable ?? defaultExecutablePresenceProbe;
|
|
@@ -5696,14 +5835,18 @@ export async function runInstallBridgeCli(argv, overrides = {}) {
|
|
|
5696
5835
|
const project = repoName ?? originalEnvironment.BAPI_REPO_NAME ?? (installed.status === "resolved" ? installed.repo : undefined);
|
|
5697
5836
|
if (!project || installed.status === "unavailable" || installed.status === "conflicting")
|
|
5698
5837
|
return { ok: false, error: "Project identity deferred during preview." };
|
|
5699
|
-
const
|
|
5700
|
-
|
|
5701
|
-
|
|
5838
|
+
const resolveDeps = { ...installerCredentialReadDeps(deps), env: originalEnvironment };
|
|
5839
|
+
const credential = await resolveEpicLaunchCredential(project, resolvedBaseUrl, resolveDeps, { productionBaseUrl: DEFAULT_BAPI_BASE_URL });
|
|
5840
|
+
// BAPI-1650: read-only approval evidence, attached only when proven.
|
|
5841
|
+
const endpointApproval = await classifyEndpointApproval(project, resolvedBaseUrl, credential, resolveDeps);
|
|
5842
|
+
const approval = endpointApproval !== undefined ? { endpointApproval } : {};
|
|
5843
|
+
return credential.ok ? { ok: true, access: { repoName: project, baseUrl: resolvedBaseUrl, apiKey: credential.apiKey }, ...approval }
|
|
5844
|
+
: { ok: false, error: "Credential validation and endpoint authorization deferred during dry run.", ...approval };
|
|
5702
5845
|
}
|
|
5703
5846
|
const parsedIdentity = parseInstallBridgeArgs(repoName ? ["--repo", repoName] : []);
|
|
5704
5847
|
if (parsedIdentity.status !== "ok")
|
|
5705
5848
|
return { ok: false, error: "Project selector unavailable." };
|
|
5706
|
-
if (!await selectInstalledProject(parsedIdentity.options, deps)) {
|
|
5849
|
+
if (!await selectInstalledProject(parsedIdentity.options, { ...deps, log: humanOutputSink })) {
|
|
5707
5850
|
return { ok: false, error: "Project identity remains unresolved." };
|
|
5708
5851
|
}
|
|
5709
5852
|
const access = await (deps.conductorResolveAccess ?? (async () => ({ ok: false, error: "access seam unavailable" })))(parsedIdentity.options.repo ?? repoName, resolvedBaseUrl, deps);
|
|
@@ -5713,8 +5856,8 @@ export async function runInstallBridgeCli(argv, overrides = {}) {
|
|
|
5713
5856
|
productionBaseUrl: DEFAULT_BAPI_BASE_URL,
|
|
5714
5857
|
hosts: await detectExistingRealKey(deps, hostConfigTargetsForPlatforms(["claude-code", "cursor", "copilot-vscode"])),
|
|
5715
5858
|
candidate: { key: access.access.apiKey, source: originalEnvironment.BAPI_API_KEY ? "env" : "store" },
|
|
5716
|
-
originalEnvironment, store: installerCredentialReadDeps(deps), report:
|
|
5717
|
-
terminal: { write:
|
|
5859
|
+
originalEnvironment, store: installerCredentialReadDeps(deps), report: humanOutputSink,
|
|
5860
|
+
terminal: { write: humanOutputSink, read: deps.isTTY ? deps.promptLine : undefined },
|
|
5718
5861
|
validate: async (key) => (await verifyConnectivity(deps, resolvedBaseUrl, access.access.repoName, key)).ok });
|
|
5719
5862
|
if (!settled.ok) {
|
|
5720
5863
|
return { ok: false, error: settled.reason };
|
|
@@ -5777,7 +5920,20 @@ export async function runInstallBridgeCli(argv, overrides = {}) {
|
|
|
5777
5920
|
localProvisioning: buildConductorLocalDeps(deps),
|
|
5778
5921
|
// BAPI-1461: the converging setup's seams (sign-ins, the stored merge token,
|
|
5779
5922
|
// the stored test command, the CI workflow installer, and indexing).
|
|
5780
|
-
setup: deps.conductorSetup ?? buildConductorSetupDeps(deps,
|
|
5923
|
+
setup: deps.conductorSetup ?? buildConductorSetupDeps(deps, humanOutputSink, errorLog),
|
|
5924
|
+
// BAPI-1638: `--answers <file>` (relative to this checkout) or `-` for stdin.
|
|
5925
|
+
answersSource: {
|
|
5926
|
+
readFile: (answersPath) => readFile(path.resolve(deps.cwd, answersPath), "utf-8"),
|
|
5927
|
+
readStdin: readProcessStdin,
|
|
5928
|
+
},
|
|
5929
|
+
// BAPI-1638: the setup record lives under docs_dir, the same root `ping` reports.
|
|
5930
|
+
setupRecordWriter: createSetupRecordWriter(resolveDocsDirForRoot(deps.cwd, deps.env), {
|
|
5931
|
+
lstat: (p) => lstat(p),
|
|
5932
|
+
mkdir: (p, o) => mkdir(p, o),
|
|
5933
|
+
readFile: (p, e) => readFile(p, e),
|
|
5934
|
+
writeFile: (p, t, o) => writeFile(p, t, o),
|
|
5935
|
+
rename: (a, b) => rename(a, b),
|
|
5936
|
+
}, { join: path.join, dirname: path.dirname }),
|
|
5781
5937
|
// BAPI-1391: the read-only discovery filesystem over THIS working tree, and
|
|
5782
5938
|
// the short-lived qualifying executor (the existing executor CLI with a
|
|
5783
5939
|
// `runExecutor` override limiting it to `gate_qualification` jobs).
|
|
@@ -5793,12 +5949,21 @@ export async function runInstallBridgeCli(argv, overrides = {}) {
|
|
|
5793
5949
|
}),
|
|
5794
5950
|
},
|
|
5795
5951
|
};
|
|
5796
|
-
|
|
5952
|
+
// Hold the verdict and next step so they print last, after the refresh output.
|
|
5953
|
+
let held;
|
|
5954
|
+
const result = await runInstallBridgeConductorCli(argv.slice(1), { ...conductorDeps, holdClosingResult: closing => { held = closing; } });
|
|
5797
5955
|
const nested = parseInstallBridgeConductorArgs(argv.slice(1));
|
|
5956
|
+
let exitCode = result;
|
|
5798
5957
|
if (result === 1 && nested.status === "ok" && !nested.options.dryRun) {
|
|
5799
|
-
|
|
5958
|
+
exitCode = await refreshIndependentInstallAssets(nested.options.json ? { ...deps, log: errorLog } : deps, "Epic Implementer setup remains incomplete; refreshing independent Bridge assets.", { mode: "compact", verbose: nested.options.verbose === true });
|
|
5800
5959
|
}
|
|
5801
|
-
|
|
5960
|
+
const closing = held;
|
|
5961
|
+
if (closing !== undefined) {
|
|
5962
|
+
log(closing.verdict);
|
|
5963
|
+
if (closing.nextStep !== undefined)
|
|
5964
|
+
log(closing.nextStep);
|
|
5965
|
+
}
|
|
5966
|
+
return exitCode;
|
|
5802
5967
|
}
|
|
5803
5968
|
const parsed = parseInstallBridgeArgs(argv);
|
|
5804
5969
|
if (parsed.status === "help") {
|
|
@@ -7989,3 +8154,16 @@ async function redeemModernInstallAttempt(deps, options, baseUrl, token, signupE
|
|
|
7989
8154
|
throw new ModernInstallRecoveryError("Canonical connectivity failed. Preserve proof and resume the same attempt.");
|
|
7990
8155
|
return { scope, record: checkpoint.record, repoName: exchange.repoName, displayName: exchange.displayName };
|
|
7991
8156
|
}
|
|
8157
|
+
/** BAPI-1638 — read all of stdin once, for `--answers -`. Bounded by the answers reader. */
|
|
8158
|
+
async function readProcessStdin() {
|
|
8159
|
+
const chunks = [];
|
|
8160
|
+
let total = 0;
|
|
8161
|
+
for await (const chunk of process.stdin) {
|
|
8162
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
8163
|
+
total += buffer.length;
|
|
8164
|
+
if (total > 512 * 1024)
|
|
8165
|
+
throw new Error("stdin answers exceed the size limit");
|
|
8166
|
+
chunks.push(buffer);
|
|
8167
|
+
}
|
|
8168
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
8169
|
+
}
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
/** One run's secret-bearing credential decision. Nothing here is a printable result. */
|
|
2
|
-
import { askSetupQuestion } from "./setup-question.js";
|
|
2
|
+
import { askSetupQuestion, askPlainSetupQuestion } from "./setup-question.js";
|
|
3
3
|
import { classifySetupAction } from "./setup-change-policy.js";
|
|
4
4
|
import { resolveBapiCredentials, readStoredBindingState } from "./credential-store.js";
|
|
5
5
|
const endpoint = (value) => value.trim().replace(/\/+$/, "");
|
|
6
6
|
/** Every consequential question uses the shared effect classifier and explained-question contract. */
|
|
7
|
-
export async function authorizeMaintenanceEffect(action, terminal, evidence, consequences) {
|
|
7
|
+
export async function authorizeMaintenanceEffect(action, terminal, evidence, consequences, presentation) {
|
|
8
8
|
const classification = classifySetupAction(action);
|
|
9
9
|
if (classification === "routine" || classification === "no-op")
|
|
10
10
|
return true;
|
|
11
11
|
if (classification === "missing-information")
|
|
12
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
|
+
}
|
|
13
29
|
const decision = await askSetupQuestion({ purpose: action.effect, evidence,
|
|
14
30
|
options: [{ id: "yes", label: "Authorize this change" }, { id: "no", label: "Preserve existing state" }],
|
|
15
31
|
consequences, deferred: "Only this change is deferred. Independent maintenance remains available.",
|
|
@@ -60,8 +76,15 @@ export async function settleMaintenanceCredential(input) {
|
|
|
60
76
|
: candidate.source === "env" && !inheritedPair && !sameEndpoint(input.productionBaseUrl);
|
|
61
77
|
let transferred = false;
|
|
62
78
|
if (transferNeeded) {
|
|
79
|
+
const sourceName = candidate.source === "store" ? "saved store" : candidate.source === "host" ? "host configuration" : candidate.source === "env" ? "environment" : candidate.source;
|
|
63
80
|
transferred = await authorizeMaintenanceEffect({ category: "credential", state: { status: "present", identity: repoName },
|
|
64
|
-
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."]
|
|
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." });
|
|
65
88
|
if (!transferred) {
|
|
66
89
|
if (!retained || !sameEndpoint(retained.baseUrl))
|
|
67
90
|
return { ok: false, reason: "Endpoint transfer deferred; retained credential is unavailable to this destination." };
|
|
@@ -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
|
// ---------------------------------------------------------------------------
|