machine-bridge-mcp 2.0.0 → 3.0.0-beta.102
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/CHANGELOG.md +1142 -0
- package/CONTRIBUTING.md +23 -25
- package/GOVERNANCE.md +2 -2
- package/README.md +58 -20
- package/SECURITY.md +161 -120
- package/SUPPORT.md +1 -1
- package/browser-extension/broker-auth.js +83 -0
- package/browser-extension/broker-liveness.js +35 -0
- package/browser-extension/browser-error-boundary.js +96 -0
- package/browser-extension/browser-operations.js +1456 -101
- package/browser-extension/devtools-input.js +195 -34
- package/browser-extension/devtools-observation.js +429 -0
- package/browser-extension/devtools-session.js +48 -0
- package/browser-extension/manifest.json +4 -3
- package/browser-extension/page-automation.js +578 -118
- package/browser-extension/pairing-bootstrap.js +42 -0
- package/browser-extension/pairing.js +28 -12
- package/browser-extension/service-worker.js +126 -106
- package/docs/AGENT_CONTEXT.md +13 -10
- package/docs/ARCHITECTURE.md +159 -67
- package/docs/AUDIT.md +1302 -4
- package/docs/CLIENTS.md +19 -6
- package/docs/COMPUTER_USE.md +297 -0
- package/docs/ENGINEERING.md +72 -13
- package/docs/GETTING_STARTED.md +18 -20
- package/docs/LOCAL_AUTHORIZATION.md +115 -72
- package/docs/LOCAL_AUTOMATION.md +27 -21
- package/docs/LOGGING.md +40 -19
- package/docs/MANAGED_JOBS.md +37 -34
- package/docs/MULTI_ACCOUNT.md +98 -37
- package/docs/OPERATIONS.md +145 -51
- package/docs/OVERVIEW.md +14 -11
- package/docs/POLICY_REFERENCE.md +71 -3
- package/docs/PRIVACY.md +41 -2
- package/docs/PROJECT_STANDARDS.md +29 -6
- package/docs/RELEASING.md +238 -64
- package/docs/TESTING.md +150 -39
- package/docs/THREAT_MODEL.md +164 -67
- package/docs/TOOL_REFERENCE.md +653 -60
- package/docs/UPGRADING.md +78 -18
- package/native/macos/MachineBridgeBackgroundInput.swift +1051 -0
- package/native/macos/MachineBridgeBackgroundInputSmokeFixture.swift +295 -0
- package/native/macos/MachineBridgeTrustBroker.swift +233 -0
- package/package.json +94 -16
- package/scripts/accepted-candidate-tarball.mjs +77 -0
- package/scripts/candidate-runtime-store.mjs +93 -0
- package/scripts/check-plan.mjs +73 -3
- package/scripts/check-runner.mjs +129 -17
- package/scripts/commit-message-check.mjs +5 -2
- package/scripts/consumer-package-security.mjs +293 -0
- package/scripts/coverage-check.mjs +251 -15
- package/scripts/coverage-generation.mjs +41 -0
- package/scripts/coverage-range-merge.mjs +41 -0
- package/scripts/foreground-daemon-recovery.mjs +88 -0
- package/scripts/generate-policy-reference.mjs +28 -5
- package/scripts/generate-tool-reference.mjs +1 -1
- package/scripts/generate-worker-types.mjs +21 -11
- package/scripts/github-backlog.mjs +11 -10
- package/scripts/github-push.mjs +62 -16
- package/scripts/github-release-asset.mjs +58 -0
- package/scripts/github-release.mjs +241 -132
- package/scripts/global-package-installation.mjs +68 -0
- package/scripts/hardened-npm-session.mjs +42 -0
- package/scripts/install-published-prerelease.mjs +198 -0
- package/scripts/local-release-acceptance.mjs +103 -45
- package/scripts/macos-background-input-smoke.mjs +515 -0
- package/scripts/network-retry.mjs +8 -1
- package/scripts/npm-global-prefix.mjs +27 -0
- package/scripts/npm-publication-policy.mjs +17 -0
- package/scripts/official-mcp-conformance.mjs +267 -0
- package/scripts/persistent-activation-process.mjs +101 -0
- package/scripts/prepare-pinned-npm.mjs +12 -69
- package/scripts/prerelease-activation.mjs +160 -0
- package/scripts/privacy-check.mjs +14 -6
- package/scripts/promotion-digest.mjs +128 -0
- package/scripts/publish-npm.mjs +260 -0
- package/scripts/published-release.mjs +132 -0
- package/scripts/release-acceptance.mjs +62 -54
- package/scripts/release-browser-extension-store.mjs +172 -0
- package/scripts/release-candidate-manifest.mjs +52 -0
- package/scripts/release-channel.mjs +106 -0
- package/scripts/release-diagnostic.mjs +41 -0
- package/scripts/release-impact-check.mjs +12 -22
- package/scripts/release-oauth-canary-core.mjs +325 -0
- package/scripts/release-oauth-canary-evidence.mjs +100 -0
- package/scripts/release-oauth-canary.mjs +127 -0
- package/scripts/release-publication-guard.mjs +67 -0
- package/scripts/release-soak.mjs +284 -0
- package/scripts/release-state.mjs +1 -1
- package/scripts/run-checks.mjs +44 -7
- package/scripts/run-worker-dry-run.mjs +21 -0
- package/scripts/sarif-security-gate.mjs +2 -1
- package/scripts/sbom-check.mjs +106 -0
- package/scripts/start-release-candidate.mjs +267 -44
- package/scripts/syntax-check.mjs +36 -14
- package/scripts/verification-generation-guard.mjs +15 -0
- package/scripts/verification-idle-sleep-guard.mjs +37 -0
- package/scripts/verification-state.mjs +108 -0
- package/scripts/wrangler-command-lifecycle.mjs +115 -0
- package/src/local/account-access.mjs +13 -1
- package/src/local/account-admin-response.mjs +92 -0
- package/src/local/account-admin.mjs +52 -19
- package/src/local/agent-context-projection.mjs +26 -7
- package/src/local/agent-context.mjs +88 -49
- package/src/local/agent-skill-discovery.mjs +16 -5
- package/src/local/app-automation-macos-jxa.mjs +350 -0
- package/src/local/app-automation.mjs +873 -163
- package/src/local/application-capability-projection.mjs +24 -0
- package/src/local/authority-context.mjs +106 -0
- package/src/local/autostart-log-maintenance.mjs +36 -0
- package/src/local/browser-bridge-http.mjs +5 -3
- package/src/local/browser-bridge.mjs +109 -31
- package/src/local/browser-broker-auth-http.mjs +67 -0
- package/src/local/browser-broker-auth.mjs +98 -0
- package/src/local/browser-broker-routes.mjs +63 -20
- package/src/local/browser-broker-server.mjs +17 -7
- package/src/local/browser-command.mjs +79 -30
- package/src/local/browser-computer-observation-service.mjs +266 -0
- package/src/local/browser-extension-identity.mjs +50 -0
- package/src/local/browser-extension-path.mjs +22 -0
- package/src/local/browser-extension-protocol.mjs +50 -11
- package/src/local/browser-operation-service.mjs +147 -117
- package/src/local/browser-pairing-grant.mjs +109 -0
- package/src/local/browser-pairing-http.mjs +36 -0
- package/src/local/browser-pairing-launch.mjs +58 -0
- package/src/local/browser-pairing-store.mjs +85 -48
- package/src/local/browser-request-registry.mjs +40 -14
- package/src/local/browser-request-settlement.mjs +78 -0
- package/src/local/browser-resource-input.mjs +74 -0
- package/src/local/browser-trusted-input-health.mjs +63 -0
- package/src/local/call-authority.mjs +21 -0
- package/src/local/call-capacity.mjs +45 -0
- package/src/local/call-registry-drain.mjs +54 -0
- package/src/local/call-registry.mjs +30 -15
- package/src/local/capability-observer.mjs +5 -0
- package/src/local/capability-ranking.mjs +3 -2
- package/src/local/child-process-settlement.mjs +132 -0
- package/src/local/cli-account-admin.mjs +40 -6
- package/src/local/cli-activate.mjs +162 -0
- package/src/local/cli-local-admin.mjs +20 -45
- package/src/local/cli-options.mjs +12 -13
- package/src/local/cli-ready-output.mjs +52 -0
- package/src/local/cli-service.mjs +91 -11
- package/src/local/cli.mjs +232 -150
- package/src/local/computer-use-application-observation.mjs +224 -0
- package/src/local/computer-use-arguments.mjs +270 -0
- package/src/local/computer-use-deadline.mjs +50 -0
- package/src/local/computer-use-dispatch-settlement.mjs +40 -0
- package/src/local/computer-use-expectation.mjs +171 -0
- package/src/local/computer-use-observation.mjs +769 -0
- package/src/local/computer-use-recovery.mjs +82 -0
- package/src/local/computer-use-result-budget.mjs +145 -0
- package/src/local/computer-use-snapshot-store.mjs +67 -0
- package/src/local/computer-use.mjs +2255 -0
- package/src/local/daemon-http-relay-auth.mjs +26 -0
- package/src/local/daemon-http-relay-connection.mjs +298 -0
- package/src/local/daemon-http-relay-request.mjs +64 -0
- package/src/local/daemon-http-relay-sequence.mjs +49 -0
- package/src/local/daemon-process.mjs +40 -7
- package/src/local/delegated-process-sandbox.mjs +148 -0
- package/src/local/device-identity.mjs +156 -49
- package/src/local/device-root-provider.mjs +81 -0
- package/src/local/directory-metadata.mjs +47 -0
- package/src/local/doctor-reporting.mjs +23 -0
- package/src/local/durable-process-spec.mjs +80 -0
- package/src/local/errors.mjs +25 -15
- package/src/local/exclusive-file.mjs +74 -26
- package/src/local/execution-limits.mjs +9 -0
- package/src/local/execution-routing.mjs +276 -0
- package/src/local/execution-surface.mjs +23 -0
- package/src/local/file-mutation-coordinator.mjs +47 -0
- package/src/local/file-snapshot-preservation.mjs +24 -0
- package/src/local/filesystem-identity.mjs +54 -0
- package/src/local/fixed-process-environment.mjs +21 -0
- package/src/local/full-access-test.mjs +31 -13
- package/src/local/git-commit.mjs +69 -0
- package/src/local/git-config-safety.mjs +55 -0
- package/src/local/git-log-parser.mjs +41 -0
- package/src/local/git-metadata-boundary.mjs +77 -0
- package/src/local/git-metadata-tree-safety.mjs +59 -0
- package/src/local/git-operation-state.mjs +19 -0
- package/src/local/git-service.mjs +165 -30
- package/src/local/hardened-npm-download-timeout.mjs +46 -0
- package/src/local/hardened-npm-download.mjs +109 -0
- package/src/local/hardened-npm-extract.mjs +20 -0
- package/src/local/hardened-npm-verification.mjs +104 -0
- package/src/local/hardened-npm.mjs +199 -0
- package/src/local/job-runner.mjs +244 -89
- package/src/local/lifecycle.mjs +6 -0
- package/src/local/log.mjs +19 -45
- package/src/local/macos-background-input.mjs +398 -0
- package/src/local/macos-idle-sleep-assertion.mjs +65 -0
- package/src/local/macos-trust-broker.mjs +404 -0
- package/src/local/managed-job-cancellation.mjs +42 -0
- package/src/local/managed-job-capacity.mjs +16 -0
- package/src/local/managed-job-directory-generation.mjs +60 -0
- package/src/local/managed-job-directory.mjs +75 -0
- package/src/local/managed-job-durable-process.mjs +49 -0
- package/src/local/managed-job-lock.mjs +46 -14
- package/src/local/managed-job-plan.mjs +38 -14
- package/src/local/managed-job-projection.mjs +23 -15
- package/src/local/managed-job-retention.mjs +128 -0
- package/src/local/managed-job-runner-claim.mjs +70 -0
- package/src/local/managed-job-runner.mjs +35 -10
- package/src/local/managed-job-storage.mjs +22 -6
- package/src/local/managed-job-terminal-maintenance.mjs +40 -0
- package/src/local/managed-job-terminal.mjs +150 -0
- package/src/local/managed-jobs.mjs +424 -287
- package/src/local/npm-cli.mjs +42 -0
- package/src/local/npm-environment.mjs +37 -0
- package/src/local/operation-authorization.mjs +68 -324
- package/src/local/operation-risk.mjs +51 -4
- package/src/local/owner-state-lock.mjs +118 -0
- package/src/local/package-identity.mjs +9 -0
- package/src/local/patch.mjs +20 -18
- package/src/local/path-inspection.mjs +23 -0
- package/src/local/policy.mjs +19 -0
- package/src/local/private-toolchain-integrity.mjs +54 -0
- package/src/local/process-execution.mjs +87 -75
- package/src/local/process-foreground-timeout.mjs +50 -0
- package/src/local/process-identity.mjs +41 -7
- package/src/local/process-nonreplayable-settlement.mjs +50 -0
- package/src/local/process-result-projection.mjs +22 -0
- package/src/local/process-session-events.mjs +47 -0
- package/src/local/process-session-remote-activity.mjs +10 -0
- package/src/local/process-session-termination.mjs +73 -0
- package/src/local/process-sessions.mjs +144 -112
- package/src/local/process-tracker.mjs +140 -13
- package/src/local/process-tree-ownership-types.d.ts +37 -0
- package/src/local/process-tree-ownership.mjs +57 -0
- package/src/local/process-tree-signal.mjs +34 -0
- package/src/local/process-tree-snapshot.mjs +77 -0
- package/src/local/process-tree-supervisor.mjs +69 -0
- package/src/local/process-tree.mjs +11 -53
- package/src/local/project-metadata.mjs +19 -6
- package/src/local/relay-call-recovery.mjs +58 -38
- package/src/local/relay-connection-classification.mjs +131 -0
- package/src/local/relay-connection-support.mjs +91 -0
- package/src/local/relay-connection.mjs +179 -272
- package/src/local/relay-diagnostics.mjs +91 -0
- package/src/local/relay-heartbeat.mjs +119 -0
- package/src/local/relay-liveness.mjs +109 -0
- package/src/local/relay-peer-diagnostics.mjs +29 -0
- package/src/local/release-runtime-lock.mjs +18 -0
- package/src/local/remote-activity-idle-sleep-guard.mjs +77 -0
- package/src/local/remote-configuration.mjs +48 -0
- package/src/local/resilient-relay-connection.mjs +178 -0
- package/src/local/resource-admission-diagnostics.mjs +52 -0
- package/src/local/resource-admission-policy.mjs +115 -0
- package/src/local/resource-admission.mjs +339 -0
- package/src/local/resource-build-root.mjs +83 -0
- package/src/local/resource-cargo-concurrency.mjs +38 -0
- package/src/local/resource-cmake-concurrency.mjs +42 -0
- package/src/local/resource-command-concurrency.mjs +37 -0
- package/src/local/resource-command-profile.mjs +176 -0
- package/src/local/resource-coordinator-accounting.mjs +21 -0
- package/src/local/resource-cpu-window.mjs +20 -0
- package/src/local/resource-disk-headroom.mjs +13 -0
- package/src/local/resource-elastic-memory.mjs +19 -0
- package/src/local/resource-elastic-request.mjs +36 -0
- package/src/local/resource-foreground-wait.mjs +29 -0
- package/src/local/resource-go-concurrency.mjs +43 -0
- package/src/local/resource-gradle-concurrency.mjs +57 -0
- package/src/local/resource-host-cache.mjs +39 -0
- package/src/local/resource-host-darwin.mjs +54 -0
- package/src/local/resource-host-linux.mjs +35 -0
- package/src/local/resource-host-sample-file.mjs +23 -0
- package/src/local/resource-host-snapshot.mjs +99 -0
- package/src/local/resource-lease-accounting.mjs +119 -0
- package/src/local/resource-light-command.mjs +6 -0
- package/src/local/resource-make-concurrency.mjs +42 -0
- package/src/local/resource-maven-concurrency.mjs +38 -0
- package/src/local/resource-ninja-command-concurrency.mjs +20 -0
- package/src/local/resource-ninja-concurrency.mjs +28 -0
- package/src/local/resource-operations.mjs +26 -10
- package/src/local/resource-pressure.mjs +67 -0
- package/src/local/resource-probe-command.mjs +35 -0
- package/src/local/resource-process-admission.mjs +59 -0
- package/src/local/resource-process-ancestry-cache.mjs +43 -0
- package/src/local/resource-process-ancestry.mjs +32 -0
- package/src/local/resource-process-priority.mjs +15 -0
- package/src/local/resource-project-key.mjs +53 -0
- package/src/local/resource-pytest-concurrency.mjs +33 -0
- package/src/local/resource-release-control-classification.mjs +14 -0
- package/src/local/resource-release-control-executable.mjs +70 -0
- package/src/local/resource-release-control-workspace.mjs +41 -0
- package/src/local/resource-request-contract.mjs +30 -0
- package/src/local/resource-script-classification.mjs +44 -0
- package/src/local/resource-shell-analysis.mjs +58 -0
- package/src/local/resource-staging-recovery.mjs +97 -0
- package/src/local/resource-swift-concurrency.mjs +31 -0
- package/src/local/resource-transaction-lock.mjs +189 -0
- package/src/local/resource-wait.mjs +48 -0
- package/src/local/resource-waiters.mjs +139 -0
- package/src/local/resource-xcode-command.mjs +7 -0
- package/src/local/resource-xcode-concurrency.mjs +34 -0
- package/src/local/resource-xcode-non-build.mjs +19 -0
- package/src/local/runtime-activation.mjs +700 -0
- package/src/local/runtime-activity-projection.mjs +48 -0
- package/src/local/runtime-capabilities.mjs +48 -15
- package/src/local/runtime-diagnostic-state.mjs +14 -0
- package/src/local/runtime-diagnostics.mjs +40 -13
- package/src/local/runtime-info-projection.mjs +60 -0
- package/src/local/runtime-info-relay-projection.mjs +21 -0
- package/src/local/runtime-paths.mjs +2 -1
- package/src/local/runtime-process-routing.mjs +33 -0
- package/src/local/runtime-relay-connection-options.mjs +44 -0
- package/src/local/runtime-relay-control.mjs +98 -0
- package/src/local/runtime-relay.mjs +26 -50
- package/src/local/runtime-reporting.mjs +37 -21
- package/src/local/runtime-resource-service.mjs +77 -0
- package/src/local/runtime-tool-handlers.mjs +13 -10
- package/src/local/runtime.mjs +244 -208
- package/src/local/secure-file.mjs +73 -20
- package/src/local/security-audit-dispatch.mjs +35 -0
- package/src/local/security-audit-log.mjs +215 -0
- package/src/local/security-audit-state.mjs +139 -0
- package/src/local/security-audit-storage.mjs +135 -0
- package/src/local/security-audit-warning.mjs +31 -0
- package/src/local/security-audit-worker.mjs +87 -0
- package/src/local/service-convergence.mjs +42 -1
- package/src/local/service-definition.mjs +24 -0
- package/src/local/service-environment.mjs +18 -10
- package/src/local/service-owner.mjs +146 -0
- package/src/local/service-ownership.mjs +17 -0
- package/src/local/service-restart-handoff.mjs +64 -0
- package/src/local/service-restart-scheduler.mjs +49 -0
- package/src/local/service-runtime-convergence.mjs +52 -0
- package/src/local/service-runtime.mjs +105 -0
- package/src/local/service-status.mjs +60 -0
- package/src/local/service.mjs +385 -92
- package/src/local/shell.mjs +39 -19
- package/src/local/ssh-key.mjs +158 -42
- package/src/local/state-inventory.mjs +50 -24
- package/src/local/state-owner-lock-inventory.mjs +23 -0
- package/src/local/state-root-owned-namespaces.mjs +83 -0
- package/src/local/state-root-retirement.mjs +89 -0
- package/src/local/state.mjs +386 -96
- package/src/local/stdio.mjs +96 -66
- package/src/local/support-state-projection.mjs +30 -0
- package/src/local/system-network-route.mjs +76 -0
- package/src/local/systemd-removal.mjs +20 -0
- package/src/local/tool-executor.mjs +85 -20
- package/src/local/tool-result-boundary.mjs +51 -0
- package/src/local/toolchain-operation-lock.mjs +41 -0
- package/src/local/tools.mjs +7 -5
- package/src/local/trusted-executable.mjs +53 -0
- package/src/local/trusted-git-executable.mjs +34 -0
- package/src/local/trusted-github-cli.mjs +24 -0
- package/src/local/windows-service-convergence.mjs +49 -0
- package/src/local/windows-service.mjs +52 -45
- package/src/local/worker-deployment-fingerprint.mjs +102 -0
- package/src/local/worker-deployment.mjs +48 -60
- package/src/local/worker-health.mjs +12 -4
- package/src/local/worker-secret-file.mjs +37 -17
- package/src/local/workspace-file-service.mjs +156 -239
- package/src/local/workspace-file-transaction.mjs +189 -0
- package/src/local/workspace-search.mjs +55 -0
- package/src/local/wrangler-toolchain/package-lock.json +1505 -0
- package/src/local/wrangler-toolchain/package.json +23 -0
- package/src/local/wrangler-toolchain-verification.mjs +135 -0
- package/src/local/wrangler-toolchain.mjs +188 -0
- package/src/shared/access-contract.json +7 -1
- package/src/shared/activation-recovery.mjs +49 -0
- package/src/shared/admin-auth.d.mts +2 -1
- package/src/shared/admin-auth.mjs +3 -3
- package/src/shared/authority-revocation.d.mts +9 -0
- package/src/shared/authority-revocation.mjs +28 -0
- package/src/shared/daemon-auth.d.mts +11 -0
- package/src/shared/daemon-auth.mjs +17 -0
- package/src/shared/device-session-auth.d.mts +20 -0
- package/src/shared/device-session-auth.mjs +51 -0
- package/src/shared/foreground-timeout.d.mts +15 -0
- package/src/shared/foreground-timeout.mjs +70 -0
- package/src/shared/log-redaction.d.mts +9 -0
- package/src/shared/log-redaction.mjs +51 -0
- package/src/shared/mcp-protocol.d.mts +27 -0
- package/src/shared/mcp-protocol.mjs +275 -0
- package/src/shared/project-overview-projection.d.mts +4 -0
- package/src/shared/project-overview-projection.mjs +96 -0
- package/src/shared/relay-contract.json +28 -0
- package/src/shared/result-projection.d.mts +2 -1
- package/src/shared/result-projection.mjs +13 -2
- package/src/shared/server-metadata.json +15 -9
- package/src/shared/tool-argument-validation.d.mts +17 -0
- package/src/shared/tool-argument-validation.mjs +325 -0
- package/src/shared/tool-call-capacity.d.mts +41 -0
- package/src/shared/tool-call-capacity.mjs +59 -0
- package/src/shared/tool-catalog.json +626 -57
- package/src/worker/access.ts +12 -0
- package/src/worker/account-admin.ts +55 -33
- package/src/worker/authority-revocations.ts +174 -0
- package/src/worker/authority.ts +52 -6
- package/src/worker/daemon-auth.ts +49 -68
- package/src/worker/daemon-channel.ts +36 -0
- package/src/worker/daemon-http-auth.ts +63 -0
- package/src/worker/daemon-http-channel.ts +120 -0
- package/src/worker/daemon-http-controller.ts +163 -0
- package/src/worker/daemon-http-protocol.ts +62 -0
- package/src/worker/daemon-http-registry.ts +82 -0
- package/src/worker/daemon-last-observation.ts +30 -0
- package/src/worker/daemon-liveness.ts +8 -6
- package/src/worker/daemon-ready-dispatch.ts +17 -0
- package/src/worker/daemon-ready-messages.ts +73 -0
- package/src/worker/daemon-ready-waiters.ts +79 -0
- package/src/worker/daemon-recovery-budget.ts +13 -0
- package/src/worker/daemon-registry.ts +58 -0
- package/src/worker/daemon-relay-diagnostics.ts +127 -0
- package/src/worker/daemon-socket-attachment.ts +55 -0
- package/src/worker/daemon-sockets.ts +72 -62
- package/src/worker/daemon-status.ts +38 -0
- package/src/worker/device-session-verifier.ts +129 -0
- package/src/worker/dpop.ts +157 -0
- package/src/worker/durable-process-timeout.ts +29 -0
- package/src/worker/errors.ts +57 -0
- package/src/worker/http.ts +112 -26
- package/src/worker/index.ts +446 -440
- package/src/worker/mcp-access.ts +57 -0
- package/src/worker/mcp-controller.ts +188 -0
- package/src/worker/mcp-http-accept.ts +11 -0
- package/src/worker/mcp-http-contract.ts +322 -0
- package/src/worker/mcp-initialization-compat.ts +141 -0
- package/src/worker/mcp-jsonrpc.ts +11 -29
- package/src/worker/mcp-removed-protocol.ts +17 -0
- package/src/worker/mcp-response-proxy.ts +135 -0
- package/src/worker/mcp-response-stream.ts +65 -0
- package/src/worker/mcp-stale-schema-compat.ts +57 -0
- package/src/worker/mcp-stream-proxy-contract.ts +48 -0
- package/src/worker/mcp-tool-call-input.ts +23 -0
- package/src/worker/nonce-store.ts +33 -35
- package/src/worker/oauth-authorization-page.ts +21 -1
- package/src/worker/oauth-client-admin.ts +52 -0
- package/src/worker/oauth-client-contract.ts +38 -0
- package/src/worker/oauth-controller.ts +107 -47
- package/src/worker/oauth-field-contract.ts +31 -0
- package/src/worker/oauth-record-contract.ts +7 -0
- package/src/worker/oauth-refresh-authority.ts +27 -0
- package/src/worker/oauth-refresh-exchange.ts +162 -0
- package/src/worker/oauth-refresh-families.ts +130 -27
- package/src/worker/oauth-refresh-persistence.ts +116 -0
- package/src/worker/oauth-state.ts +33 -18
- package/src/worker/oauth-store-validation.ts +131 -0
- package/src/worker/oauth-token-derivation.ts +33 -0
- package/src/worker/oauth-token-issuance.ts +119 -0
- package/src/worker/oauth-tokens.ts +56 -190
- package/src/worker/observability.ts +38 -5
- package/src/worker/pending-admission.ts +15 -0
- package/src/worker/pending-call-capacity.ts +108 -0
- package/src/worker/pending-call-contract.ts +42 -5
- package/src/worker/pending-call-deadlines.ts +75 -0
- package/src/worker/pending-calls.ts +131 -125
- package/src/worker/runtime-alarm-storage.ts +37 -0
- package/src/worker/runtime-alarm.ts +136 -0
- package/src/worker/server-info-activity.ts +36 -0
- package/src/worker/server-info-tool-delivery.ts +15 -0
- package/src/worker/server-info.ts +168 -0
- package/src/worker/tool-catalog.ts +47 -1
- package/src/worker/tool-timeout.ts +75 -14
- package/src/worker/websocket-protocol.ts +26 -2
- package/src/worker/worker-edge-guard.ts +90 -0
- package/src/worker/worker-edge-log.ts +65 -0
- package/src/worker/worker-entry.ts +52 -0
- package/src/worker/worker-mcp-config.ts +23 -0
- package/src/worker/worker-metadata.ts +48 -0
- package/src/worker/worker-rate-limit-key.ts +30 -0
- package/src/worker/worker-runtime-config.ts +20 -0
- package/src/worker/worker-static-routes.ts +54 -0
- package/src/worker/worker-task-lifetime.ts +18 -0
- package/tsconfig.local.json +17 -1
- package/wrangler.jsonc +13 -0
- package/src/local/cli-approval.mjs +0 -117
- package/src/local/operation-state-lock.mjs +0 -92
- package/src/worker/mcp-session.ts +0 -72
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Project raw application backend capabilities through the effective tool set.
|
|
5
|
+
* Discovery is independent from launch/UI authority, so callers can expose the
|
|
6
|
+
* inventory without accidentally advertising unavailable mutations.
|
|
7
|
+
* @param {Record<string, any>} capabilities
|
|
8
|
+
* @param {(tool: string) => boolean} allows
|
|
9
|
+
*/
|
|
10
|
+
export function projectApplicationCapabilities(capabilities, allows) {
|
|
11
|
+
const result = { ...capabilities };
|
|
12
|
+
result.discovery = allows("list_local_applications");
|
|
13
|
+
result.open = capabilities.open === true && allows("open_local_application");
|
|
14
|
+
result.accessibility_inspection = capabilities.accessibility_inspection === true && allows("inspect_local_application");
|
|
15
|
+
result.structured_accessibility_actions = capabilities.structured_accessibility_actions === true && allows("operate_local_application");
|
|
16
|
+
result.window_screenshot = capabilities.window_screenshot === true && allows("computer_observe");
|
|
17
|
+
if (capabilities.background_visual_point && typeof capabilities.background_visual_point === "object") {
|
|
18
|
+
result.background_visual_point = {
|
|
19
|
+
...capabilities.background_visual_point,
|
|
20
|
+
available: capabilities.background_visual_point.available === true && allows("computer_act"),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BridgeError } from "./errors.mjs";
|
|
2
|
+
import { intersectPolicies, normalizePolicy, policyProfile } from "./policy.mjs";
|
|
3
|
+
|
|
4
|
+
const ACCOUNT_ID = /^acct_[A-Za-z0-9_-]{20,96}$/;
|
|
5
|
+
const CLIENT_ID = /^mcp_client_[A-Za-z0-9_-]{43}$/;
|
|
6
|
+
const FAMILY_ID = /^mcp_family_[A-Za-z0-9_-]{43}$/;
|
|
7
|
+
|
|
8
|
+
export function buildAuthorityContext({ authorization = {}, daemonPolicy, origin = "local" } = {}) {
|
|
9
|
+
if (origin !== "relay") {
|
|
10
|
+
const policy = normalizePolicy(daemonPolicy || {});
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
origin: "local",
|
|
13
|
+
principal: Object.freeze({ kind: "local", role: "owner" }),
|
|
14
|
+
daemonPolicy: policy,
|
|
15
|
+
accountPolicy: policy,
|
|
16
|
+
effectivePolicy: policy,
|
|
17
|
+
owner: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const accountId = String(authorization.account_id || "");
|
|
22
|
+
const clientId = String(authorization.client_id || "");
|
|
23
|
+
const familyId = String(authorization.family_id || "");
|
|
24
|
+
const role = String(authorization.role || "").trim().toLowerCase();
|
|
25
|
+
const accountVersion = Number(authorization.account_version);
|
|
26
|
+
if (!ACCOUNT_ID.test(accountId) || !CLIENT_ID.test(clientId) || !FAMILY_ID.test(familyId) || !Number.isSafeInteger(accountVersion) || accountVersion <= 0) {
|
|
27
|
+
throw new BridgeError("authorization_denied", "relay operation is missing authenticated principal identity");
|
|
28
|
+
}
|
|
29
|
+
const accountPolicy = policyProfile(roleProfile(role), "explicit");
|
|
30
|
+
const normalizedDaemonPolicy = normalizePolicy(daemonPolicy || {});
|
|
31
|
+
const effectivePolicy = intersectPolicies(normalizedDaemonPolicy, accountPolicy, { origin: "effective" });
|
|
32
|
+
const principal = Object.freeze({
|
|
33
|
+
kind: "account",
|
|
34
|
+
accountId,
|
|
35
|
+
accountVersion,
|
|
36
|
+
clientId,
|
|
37
|
+
familyId,
|
|
38
|
+
role,
|
|
39
|
+
});
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
origin: "relay",
|
|
42
|
+
principal,
|
|
43
|
+
daemonPolicy: normalizedDaemonPolicy,
|
|
44
|
+
accountPolicy,
|
|
45
|
+
effectivePolicy,
|
|
46
|
+
owner: role === "owner",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function policyForContext(context, fallbackPolicy) {
|
|
51
|
+
return normalizePolicy(context?.authority?.effectivePolicy || fallbackPolicy || {});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function principalForContext(context) {
|
|
55
|
+
const principal = context?.authority?.principal;
|
|
56
|
+
if (principal?.kind === "account") return principal;
|
|
57
|
+
return Object.freeze({ kind: "local", role: "owner" });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function principalBinding(context) {
|
|
61
|
+
const principal = principalForContext(context);
|
|
62
|
+
if (principal.kind !== "account") return { owner_kind: "local" };
|
|
63
|
+
return {
|
|
64
|
+
owner_kind: "account",
|
|
65
|
+
owner_account_id: principal.accountId,
|
|
66
|
+
owner_account_version: principal.accountVersion,
|
|
67
|
+
owner_client_id: principal.clientId,
|
|
68
|
+
owner_family_id: principal.familyId,
|
|
69
|
+
owner_role: principal.role,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function assertOwnedByContext(record, context, label = "object") {
|
|
74
|
+
const principal = principalForContext(context);
|
|
75
|
+
if (principal.kind !== "account" || principal.role === "owner") return;
|
|
76
|
+
if (
|
|
77
|
+
record?.owner_kind !== "account"
|
|
78
|
+
|| record.owner_account_id !== principal.accountId
|
|
79
|
+
|| record.owner_account_version !== principal.accountVersion
|
|
80
|
+
|| record.owner_client_id !== principal.clientId
|
|
81
|
+
|| record.owner_family_id !== principal.familyId
|
|
82
|
+
) {
|
|
83
|
+
throw new BridgeError("authorization_denied", `${label} belongs to another account or an obsolete account session`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function visibleToContext(record, context) {
|
|
88
|
+
try {
|
|
89
|
+
assertOwnedByContext(record, context);
|
|
90
|
+
return true;
|
|
91
|
+
} catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function roleProfile(role) {
|
|
97
|
+
const mapping = {
|
|
98
|
+
reviewer: "review",
|
|
99
|
+
editor: "edit",
|
|
100
|
+
operator: "agent",
|
|
101
|
+
owner: "full",
|
|
102
|
+
};
|
|
103
|
+
const profile = mapping[role];
|
|
104
|
+
if (!profile) throw new BridgeError("authorization_denied", `unknown account role: ${role}`);
|
|
105
|
+
return profile;
|
|
106
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { trimAutostartLogs } from "./service.mjs";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_MAINTENANCE_INTERVAL_MS = 15 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Keep long-lived background-service logs within the same bounds enforced at
|
|
9
|
+
* startup. The injected scheduler/trim hooks keep the lifecycle deterministic
|
|
10
|
+
* in tests without weakening the production file-safety checks.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} stateRoot
|
|
13
|
+
* @param {{
|
|
14
|
+
* intervalMs?: number,
|
|
15
|
+
* trim?: (stateRoot: string) => void,
|
|
16
|
+
* onError?: (error: unknown) => void,
|
|
17
|
+
* scheduler?: {setInterval: (callback: () => void, delay: number) => any},
|
|
18
|
+
* }} [options]
|
|
19
|
+
*/
|
|
20
|
+
export function startAutostartLogMaintenance(stateRoot, options = {}) {
|
|
21
|
+
const intervalMs = positiveInteger(options.intervalMs, DEFAULT_MAINTENANCE_INTERVAL_MS);
|
|
22
|
+
const trim = typeof options.trim === "function" ? options.trim : trimAutostartLogs;
|
|
23
|
+
const onError = typeof options.onError === "function" ? options.onError : () => {};
|
|
24
|
+
const scheduler = options.scheduler || { setInterval };
|
|
25
|
+
const maintain = () => {
|
|
26
|
+
try { trim(stateRoot); } catch (error) { onError(error); }
|
|
27
|
+
};
|
|
28
|
+
const timer = scheduler.setInterval(maintain, intervalMs);
|
|
29
|
+
timer?.unref?.();
|
|
30
|
+
return { intervalMs, maintain };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function positiveInteger(value, fallback) {
|
|
34
|
+
const number = Number(value);
|
|
35
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : fallback;
|
|
36
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EXPECTED_EXTENSION_VERSION } from "./browser-extension-protocol.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { EXPECTED_EXTENSION_ID } from "./browser-extension-identity.mjs";
|
|
3
|
+
import { isAllowedLoopbackHost, pairingHtml, securityHeaders, sendJson } from "./browser-pairing-http.mjs";
|
|
3
4
|
|
|
4
5
|
export function handleBrowserBridgeHttp(request, response, {
|
|
5
6
|
port,
|
|
6
|
-
token,
|
|
7
7
|
extensionConnected,
|
|
8
8
|
extensionStatusInfo,
|
|
9
9
|
extensionReloadRequired,
|
|
@@ -26,6 +26,8 @@ export function handleBrowserBridgeHttp(request, response, {
|
|
|
26
26
|
connected: extensionConnected(),
|
|
27
27
|
broker: "machine-bridge-browser",
|
|
28
28
|
expected_extension_version: EXPECTED_EXTENSION_VERSION,
|
|
29
|
+
expected_extension_id: EXPECTED_EXTENSION_ID,
|
|
30
|
+
extension_id: extension?.extension_id || "",
|
|
29
31
|
extension_protocol: extension?.protocol || null,
|
|
30
32
|
extension_version: extension?.version || "",
|
|
31
33
|
extension_capabilities: extension?.capabilities || [],
|
|
@@ -38,7 +40,7 @@ export function handleBrowserBridgeHttp(request, response, {
|
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
42
|
if (url.pathname === "/pair") {
|
|
41
|
-
const html = pairingHtml(port
|
|
43
|
+
const html = pairingHtml(port);
|
|
42
44
|
response.writeHead(200, securityHeaders("text/html; charset=utf-8"));
|
|
43
45
|
response.end(html);
|
|
44
46
|
return;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { WebSocket } from "ws";
|
|
3
3
|
import { createToolAuthorizer } from "./policy.mjs";
|
|
4
|
-
import { assertStateMaintenanceAvailable
|
|
4
|
+
import { assertStateMaintenanceAvailable } from "./state.mjs";
|
|
5
|
+
import { packageRoot } from "./package-identity.mjs";
|
|
5
6
|
import {
|
|
6
7
|
BROWSER_EXTENSION_PROTOCOL, EXPECTED_EXTENSION_VERSION, MAX_BROWSER_MESSAGE_BYTES,
|
|
7
8
|
closeProtocolSocket, normalizeCompatibleExtensionInfo, parseBrowserSocketMessage, parseExtensionHello, safeSocketSend,
|
|
@@ -13,6 +14,10 @@ import { BrowserRequestRegistry } from "./browser-request-registry.mjs";
|
|
|
13
14
|
import { handleBrowserBridgeHttp } from "./browser-bridge-http.mjs";
|
|
14
15
|
import { BrowserBrokerRoutes } from "./browser-broker-routes.mjs";
|
|
15
16
|
import { startBrowserBrokerServer } from "./browser-broker-server.mjs";
|
|
17
|
+
import { EXPECTED_EXTENSION_ID } from "./browser-extension-identity.mjs";
|
|
18
|
+
import { BROKER_AUTH_REQUEST_HEADER, BROKER_AUTH_REQUEST_VALUE, createBrokerAuthChallenge, createBrokerClientProtocol, createBrokerInitProof, parseBrokerAuthResponse, verifyBrokerServerProof } from "./browser-broker-auth.mjs";
|
|
19
|
+
import { startBrowserPairingLaunch } from "./browser-pairing-launch.mjs";
|
|
20
|
+
import { browserExtensionPathForRuntime } from "./browser-extension-path.mjs";
|
|
16
21
|
|
|
17
22
|
const MAX_PORT_ATTEMPTS = 10;
|
|
18
23
|
const MAX_PENDING = 32;
|
|
@@ -37,6 +42,8 @@ export class BrowserBridgeManager {
|
|
|
37
42
|
this.extensionInfo = null;
|
|
38
43
|
this.proxyExtensionInfo = null;
|
|
39
44
|
this.proxyExtensionReloadRequired = false;
|
|
45
|
+
this.extensionConnectionGeneration = 0;
|
|
46
|
+
this.proxyExtensionConnectionGeneration = 0;
|
|
40
47
|
this.extensionReloadRequiredFlag = false;
|
|
41
48
|
this.recoveryTimer = null;
|
|
42
49
|
this.stopping = false;
|
|
@@ -48,15 +55,14 @@ export class BrowserBridgeManager {
|
|
|
48
55
|
extensionConnected: () => this.extensionConnected(),
|
|
49
56
|
extensionStatusInfo: () => this.extensionStatusInfo(),
|
|
50
57
|
extensionReloadRequired: () => this.extensionReloadRequired(),
|
|
58
|
+
extensionGeneration: () => this.extensionConnectionGeneration,
|
|
51
59
|
});
|
|
52
|
-
// Public aliases remain for diagnostics and compatibility with existing behavioral tests.
|
|
53
|
-
this.runtimeClients = this.brokerRoutes.clients;
|
|
54
|
-
this.proxyRoutes = this.brokerRoutes.routes;
|
|
55
60
|
this.startPromise = null;
|
|
56
61
|
this.startGeneration = 0;
|
|
57
62
|
this.port = 0;
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
63
|
+
this.extensionToken = "";
|
|
64
|
+
this.runtimeToken = "";
|
|
65
|
+
this.extensionPath = browserExtensionPathForRuntime({ stateRoot: this.stateRoot, packageDirectory: packageRoot });
|
|
60
66
|
this.operationService = new BrowserOperationService({
|
|
61
67
|
authorizeTool: (tool) => this.authorizeTool(tool),
|
|
62
68
|
ensureStarted: (context) => this.ensureStarted(context),
|
|
@@ -67,15 +73,23 @@ export class BrowserBridgeManager {
|
|
|
67
73
|
extensionConnected: this.extensionConnected(),
|
|
68
74
|
extensionInfo: this.extensionStatusInfo(),
|
|
69
75
|
extensionReloadRequired: this.extensionReloadRequired(),
|
|
76
|
+
extensionGeneration: this.server ? this.extensionConnectionGeneration : this.proxyExtensionConnectionGeneration,
|
|
77
|
+
...this.brokerRoutes.snapshot(),
|
|
70
78
|
}),
|
|
79
|
+
createPairingLaunch: (port) => startBrowserPairingLaunch({ brokerPort: port, extensionToken: this.extensionToken }),
|
|
71
80
|
extensionPath: this.extensionPath,
|
|
72
81
|
expectedExtensionVersion: EXPECTED_EXTENSION_VERSION,
|
|
82
|
+
expectedExtensionId: EXPECTED_EXTENSION_ID,
|
|
73
83
|
runProcess: (...args) => this.runProcess(...args),
|
|
74
84
|
readResourceText: (name) => this.readResourceText(name),
|
|
75
85
|
readResourceBinary: (name) => this.readResourceBinary(name),
|
|
86
|
+
throwIfCancelled: (context) => this.throwIfCancelled(context),
|
|
87
|
+
logger: this.logger,
|
|
76
88
|
});
|
|
77
89
|
}
|
|
78
90
|
|
|
91
|
+
brokerDiagnostics() { return this.brokerRoutes.snapshot(); }
|
|
92
|
+
|
|
79
93
|
status(context = {}) { return this.operationService.status(context); }
|
|
80
94
|
|
|
81
95
|
pair(args = {}, context = {}) { return this.operationService.pair(args, context); }
|
|
@@ -90,6 +104,14 @@ export class BrowserBridgeManager {
|
|
|
90
104
|
|
|
91
105
|
inspectPage(args = {}, context = {}) { return this.operationService.inspectPage(args, context); }
|
|
92
106
|
|
|
107
|
+
observeComputer(args = {}, context = {}) { return this.operationService.observeComputer(args, context); }
|
|
108
|
+
|
|
109
|
+
documentState(args = {}, context = {}) { return this.operationService.documentState(args, context); }
|
|
110
|
+
|
|
111
|
+
pointAction(args = {}, context = {}) { return this.operationService.pointAction(args, context); }
|
|
112
|
+
|
|
113
|
+
backendNodeAction(args = {}, context = {}) { return this.operationService.backendNodeAction(args, context); }
|
|
114
|
+
|
|
93
115
|
act(args = {}, context = {}) { return this.operationService.act(args, context); }
|
|
94
116
|
|
|
95
117
|
fillForm(args = {}, context = {}) { return this.operationService.fillForm(args, context); }
|
|
@@ -127,32 +149,45 @@ export class BrowserBridgeManager {
|
|
|
127
149
|
try { await pending; } finally {
|
|
128
150
|
if (this.startPromise === pending) this.startPromise = null;
|
|
129
151
|
}
|
|
152
|
+
this.throwIfCancelled(context);
|
|
130
153
|
}
|
|
131
154
|
|
|
132
155
|
async start(generation = this.startGeneration) {
|
|
133
156
|
try {
|
|
134
157
|
const pairing = await loadOrCreatePairing(this.stateRoot);
|
|
135
158
|
this.assertStartCurrent(generation);
|
|
136
|
-
this.
|
|
159
|
+
this.extensionToken = pairing.extensionToken;
|
|
160
|
+
this.runtimeToken = pairing.runtimeToken;
|
|
137
161
|
for (let offset = 0; offset < MAX_PORT_ATTEMPTS; offset += 1) {
|
|
138
162
|
const port = pairing.port + offset;
|
|
139
163
|
try {
|
|
140
164
|
await this.listen(port);
|
|
141
165
|
this.assertStartCurrent(generation);
|
|
142
|
-
if (port !== pairing.port
|
|
143
|
-
await savePairing(this.stateRoot, {
|
|
166
|
+
if (this.stateRoot && (port !== pairing.port || pairing.migrationPending)) {
|
|
167
|
+
await savePairing(this.stateRoot, { schemaVersion: pairing.schemaVersion, pairingAuthVersion: pairing.pairingAuthVersion, extensionToken: this.extensionToken, runtimeToken: this.runtimeToken, port, migrationPending: false });
|
|
144
168
|
this.assertStartCurrent(generation);
|
|
145
169
|
}
|
|
146
170
|
return;
|
|
147
171
|
} catch (error) {
|
|
148
172
|
this.assertStartCurrent(generation);
|
|
149
173
|
if (error?.code !== "EADDRINUSE") throw error;
|
|
150
|
-
|
|
174
|
+
const proxy = await this.connectProxy(port, generation);
|
|
175
|
+
if (proxy.connected) {
|
|
151
176
|
this.assertStartCurrent(generation);
|
|
152
177
|
this.port = port;
|
|
178
|
+
if (this.stateRoot && pairing.migrationPending) {
|
|
179
|
+
await savePairing(this.stateRoot, { schemaVersion: pairing.schemaVersion, pairingAuthVersion: pairing.pairingAuthVersion, extensionToken: this.extensionToken, runtimeToken: this.runtimeToken, port, migrationPending: false });
|
|
180
|
+
this.assertStartCurrent(generation);
|
|
181
|
+
}
|
|
153
182
|
return;
|
|
154
183
|
}
|
|
155
184
|
this.assertStartCurrent(generation);
|
|
185
|
+
if (proxy.authenticated) {
|
|
186
|
+
throw new Error("browser broker accepted runtime authentication but did not complete its handshake; refusing a second broker owner");
|
|
187
|
+
}
|
|
188
|
+
if (pairing.migrationPending && offset === 0) {
|
|
189
|
+
throw new Error("previous browser broker occupies the migrated pairing port; restart the prior Machine Bridge runtime before browser broker migration can complete");
|
|
190
|
+
}
|
|
156
191
|
if (offset === MAX_PORT_ATTEMPTS - 1) throw error;
|
|
157
192
|
}
|
|
158
193
|
}
|
|
@@ -176,7 +211,8 @@ export class BrowserBridgeManager {
|
|
|
176
211
|
this.port = port;
|
|
177
212
|
const { server, wss } = await startBrowserBrokerServer({
|
|
178
213
|
port,
|
|
179
|
-
|
|
214
|
+
extensionToken: this.extensionToken,
|
|
215
|
+
runtimeToken: this.runtimeToken,
|
|
180
216
|
maxPayload: MAX_BROWSER_MESSAGE_BYTES,
|
|
181
217
|
onHttp: (request, response) => this.handleHttp(request, response),
|
|
182
218
|
onSocket: (socket, role) => this.acceptSocket(socket, role),
|
|
@@ -186,27 +222,43 @@ export class BrowserBridgeManager {
|
|
|
186
222
|
}
|
|
187
223
|
|
|
188
224
|
async connectProxy(port, generation = this.startGeneration) {
|
|
225
|
+
const clientChallenge = createBrokerAuthChallenge();
|
|
226
|
+
const initProof = createBrokerInitProof(this.runtimeToken, "runtime", clientChallenge);
|
|
227
|
+
const authUrl = `http://127.0.0.1:${port}/runtime-auth?challenge=${encodeURIComponent(clientChallenge)}&init=${encodeURIComponent(initProof)}`;
|
|
228
|
+
let authResponse;
|
|
229
|
+
try {
|
|
230
|
+
authResponse = await fetch(authUrl, { method: "GET", redirect: "error", cache: "no-store", headers: { [BROKER_AUTH_REQUEST_HEADER]: BROKER_AUTH_REQUEST_VALUE }, signal: AbortSignal.timeout(750) });
|
|
231
|
+
} catch { return { connected: false, authenticated: false }; }
|
|
232
|
+
if (authResponse.status !== 204) return { connected: false, authenticated: false };
|
|
233
|
+
const challenge = parseBrokerAuthResponse(authResponse.headers);
|
|
234
|
+
if (!challenge || !verifyBrokerServerProof(this.runtimeToken, "runtime", clientChallenge, challenge.serverNonce, challenge.serverProof)) {
|
|
235
|
+
return { connected: false, authenticated: false };
|
|
236
|
+
}
|
|
237
|
+
this.assertStartCurrent(generation);
|
|
238
|
+
const protocol = createBrokerClientProtocol(this.runtimeToken, "runtime", clientChallenge, challenge.serverNonce);
|
|
189
239
|
const url = `ws://127.0.0.1:${port}/runtime`;
|
|
190
240
|
return new Promise((resolvePromise) => {
|
|
191
241
|
let settled = false;
|
|
192
|
-
const
|
|
242
|
+
const authenticated = true;
|
|
243
|
+
const ws = new WebSocket(url, [protocol], { maxPayload: MAX_BROWSER_MESSAGE_BYTES });
|
|
193
244
|
const timer = setTimeout(() => finish(false), 1500);
|
|
194
245
|
timer.unref?.();
|
|
195
|
-
const finish = (
|
|
246
|
+
const finish = (connected) => {
|
|
196
247
|
if (settled) return;
|
|
197
248
|
settled = true;
|
|
198
249
|
clearTimeout(timer);
|
|
199
|
-
if (!
|
|
200
|
-
try { ws.terminate(); }
|
|
250
|
+
if (!connected) {
|
|
251
|
+
try { ws.terminate(); }
|
|
252
|
+
catch {
|
|
253
|
+
try { ws.close(); }
|
|
254
|
+
catch { /* Rejected bridge ownership is already settled even if the peer closed concurrently. */ }
|
|
255
|
+
}
|
|
201
256
|
}
|
|
202
|
-
resolvePromise(
|
|
257
|
+
resolvePromise({ connected, authenticated });
|
|
203
258
|
};
|
|
204
259
|
ws.on("message", (data) => {
|
|
205
260
|
const parsed = parseBrowserSocketMessage(data);
|
|
206
|
-
if (!parsed.ok) {
|
|
207
|
-
closeProtocolSocket(ws, parsed.code, parsed.reason);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
261
|
+
if (!parsed.ok) { closeProtocolSocket(ws, parsed.code, parsed.reason); return; }
|
|
210
262
|
const message = parsed.message;
|
|
211
263
|
if (!settled) {
|
|
212
264
|
if (message.type !== "hello" || message.role !== "runtime" || message.protocol !== 1) {
|
|
@@ -214,7 +266,8 @@ export class BrowserBridgeManager {
|
|
|
214
266
|
return;
|
|
215
267
|
}
|
|
216
268
|
if (!this.isStartCurrent(generation)) {
|
|
217
|
-
try { ws.close(1001, "runtime stopped"); }
|
|
269
|
+
try { ws.close(1001, "runtime stopped"); }
|
|
270
|
+
catch { /* Runtime shutdown may race an already-closed extension socket. */ }
|
|
218
271
|
finish(false);
|
|
219
272
|
return;
|
|
220
273
|
}
|
|
@@ -223,6 +276,7 @@ export class BrowserBridgeManager {
|
|
|
223
276
|
this.proxyExtensionInfo = claimedExtension ? normalizeCompatibleExtensionInfo(message.extension_info) : null;
|
|
224
277
|
this.proxyExtensionConnected = claimedExtension && Boolean(this.proxyExtensionInfo);
|
|
225
278
|
this.proxyExtensionReloadRequired = message.extension_reload_required === true || (claimedExtension && !this.proxyExtensionInfo);
|
|
279
|
+
this.proxyExtensionConnectionGeneration = this.proxyExtensionConnected ? runtimeExtensionGeneration(message.extension_generation) : 0;
|
|
226
280
|
finish(true);
|
|
227
281
|
return;
|
|
228
282
|
}
|
|
@@ -235,6 +289,7 @@ export class BrowserBridgeManager {
|
|
|
235
289
|
this.proxyExtensionConnected = false;
|
|
236
290
|
this.proxyExtensionInfo = null;
|
|
237
291
|
this.proxyExtensionReloadRequired = false;
|
|
292
|
+
this.proxyExtensionConnectionGeneration = 0;
|
|
238
293
|
this.rejectPending("browser broker disconnected");
|
|
239
294
|
if (settled) this.scheduleBrokerRecovery();
|
|
240
295
|
}
|
|
@@ -301,7 +356,9 @@ export class BrowserBridgeManager {
|
|
|
301
356
|
return;
|
|
302
357
|
}
|
|
303
358
|
clearTimeout(socket.handshakeTimer);
|
|
304
|
-
if (!safeSocketSend(socket, {
|
|
359
|
+
if (!safeSocketSend(socket, {
|
|
360
|
+
type: "hello_ack", role: "extension", protocol: BROWSER_EXTENSION_PROTOCOL, pong_watchdog: true,
|
|
361
|
+
})) {
|
|
305
362
|
closeProtocolSocket(socket, 1011, "extension acknowledgement failed");
|
|
306
363
|
return;
|
|
307
364
|
}
|
|
@@ -311,6 +368,7 @@ export class BrowserBridgeManager {
|
|
|
311
368
|
const previous = this.socket;
|
|
312
369
|
this.socket = socket;
|
|
313
370
|
this.extensionInfo = info;
|
|
371
|
+
this.extensionConnectionGeneration = nextExtensionGeneration(this.extensionConnectionGeneration);
|
|
314
372
|
if (previous && previous !== socket) {
|
|
315
373
|
this.rejectPending("browser extension was replaced; retry the browser request");
|
|
316
374
|
this.rejectProxyRoutes("browser extension was replaced; retry the browser request");
|
|
@@ -324,7 +382,13 @@ export class BrowserBridgeManager {
|
|
|
324
382
|
closeProtocolSocket(socket, 1002, "extension hello required; reload the extension");
|
|
325
383
|
return;
|
|
326
384
|
}
|
|
327
|
-
if (message.type === "ping")
|
|
385
|
+
if (message.type === "ping") {
|
|
386
|
+
const seq = Number.isSafeInteger(message.seq) && message.seq > 0 ? message.seq : undefined;
|
|
387
|
+
if (!safeSocketSend(socket, { type: "pong", ...(seq ? { seq } : {}) })) {
|
|
388
|
+
closeProtocolSocket(socket, 1011, "extension pong delivery failed");
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
328
392
|
if (message.type !== "response" || typeof message.id !== "string") {
|
|
329
393
|
this.markExtensionReloadRequired();
|
|
330
394
|
closeProtocolSocket(socket, 1002, "invalid extension protocol message");
|
|
@@ -344,6 +408,7 @@ export class BrowserBridgeManager {
|
|
|
344
408
|
this.proxyExtensionInfo = claimedExtension ? normalizeCompatibleExtensionInfo(message.extension_info) : null;
|
|
345
409
|
this.proxyExtensionConnected = claimedExtension && Boolean(this.proxyExtensionInfo);
|
|
346
410
|
this.proxyExtensionReloadRequired = message.extension_reload_required === true || (claimedExtension && !this.proxyExtensionInfo);
|
|
411
|
+
this.proxyExtensionConnectionGeneration = this.proxyExtensionConnected ? runtimeExtensionGeneration(message.extension_generation) : 0;
|
|
347
412
|
if (!this.proxyExtensionConnected) this.rejectPending("browser extension disconnected");
|
|
348
413
|
return true;
|
|
349
414
|
}
|
|
@@ -372,16 +437,15 @@ export class BrowserBridgeManager {
|
|
|
372
437
|
handleHttp(request, response) {
|
|
373
438
|
return handleBrowserBridgeHttp(request, response, {
|
|
374
439
|
port: this.port,
|
|
375
|
-
token: this.token,
|
|
376
440
|
extensionConnected: () => this.extensionConnected(),
|
|
377
441
|
extensionStatusInfo: () => this.extensionStatusInfo(),
|
|
378
442
|
extensionReloadRequired: () => this.extensionReloadRequired(),
|
|
379
443
|
});
|
|
380
444
|
}
|
|
381
445
|
|
|
382
|
-
cancelCall(callId) {
|
|
446
|
+
cancelCall(callId, reason = null) {
|
|
383
447
|
const transport = this.server ? this.socket : this.upstream;
|
|
384
|
-
this.requestRegistry.cancelCall(callId, transport);
|
|
448
|
+
this.requestRegistry.cancelCall(callId, transport, reason);
|
|
385
449
|
}
|
|
386
450
|
|
|
387
451
|
rejectPending(message) {
|
|
@@ -402,9 +466,12 @@ export class BrowserBridgeManager {
|
|
|
402
466
|
|
|
403
467
|
closeBrokerTransports(message) {
|
|
404
468
|
this.rejectPending(message);
|
|
405
|
-
try { this.upstream?.close(1001, "runtime stopped"); }
|
|
406
|
-
|
|
407
|
-
try { this.
|
|
469
|
+
try { this.upstream?.close(1001, "runtime stopped"); }
|
|
470
|
+
catch { /* Runtime shutdown is idempotent and the upstream may already be closed. */ }
|
|
471
|
+
try { this.socket?.close(1001, "runtime stopped"); }
|
|
472
|
+
catch { /* Runtime shutdown is idempotent and the client socket may already be closed. */ }
|
|
473
|
+
try { this.pendingExtensionSocket?.close(1001, "runtime stopped"); }
|
|
474
|
+
catch { /* Runtime shutdown is idempotent and the pending extension socket may already be closed. */ }
|
|
408
475
|
this.brokerRoutes.close(message);
|
|
409
476
|
this.upstream = null;
|
|
410
477
|
this.socket = null;
|
|
@@ -413,9 +480,12 @@ export class BrowserBridgeManager {
|
|
|
413
480
|
this.proxyExtensionConnected = false;
|
|
414
481
|
this.proxyExtensionInfo = null;
|
|
415
482
|
this.proxyExtensionReloadRequired = false;
|
|
483
|
+
this.proxyExtensionConnectionGeneration = 0;
|
|
416
484
|
this.extensionReloadRequiredFlag = false;
|
|
417
|
-
try { this.wss?.close(); }
|
|
418
|
-
|
|
485
|
+
try { this.wss?.close(); }
|
|
486
|
+
catch { /* Listener shutdown may race a prior close; ownership state is already terminal. */ }
|
|
487
|
+
try { this.server?.close(); }
|
|
488
|
+
catch { /* Listener shutdown may race a prior close; ownership state is already terminal. */ }
|
|
419
489
|
this.wss = null;
|
|
420
490
|
this.server = null;
|
|
421
491
|
}
|
|
@@ -442,3 +512,11 @@ export class BrowserBridgeManager {
|
|
|
442
512
|
}
|
|
443
513
|
|
|
444
514
|
}
|
|
515
|
+
|
|
516
|
+
function nextExtensionGeneration(value) {
|
|
517
|
+
return Number.isSafeInteger(value) && value > 0 && value < Number.MAX_SAFE_INTEGER ? value + 1 : 1;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function runtimeExtensionGeneration(value) {
|
|
521
|
+
return Number.isSafeInteger(value) && value > 0 ? value : 1;
|
|
522
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BROKER_AUTH_REQUEST_HEADER, BROKER_AUTH_REQUEST_VALUE } from "./browser-broker-auth.mjs";
|
|
2
|
+
import { isAllowedLoopbackHost } from "./browser-pairing-http.mjs";
|
|
3
|
+
import { createPairingBootstrapRegistry } from "./browser-pairing-grant.mjs";
|
|
4
|
+
|
|
5
|
+
export function createBrowserBrokerAuthHttpHandler({ port, extensionToken, runtimeAuth, extensionAuth }) {
|
|
6
|
+
const pairingAuth = createPairingBootstrapRegistry(extensionToken, port);
|
|
7
|
+
return (request, response) => {
|
|
8
|
+
const host = String(request.headers.host || "");
|
|
9
|
+
if (!isAllowedLoopbackHost(host, port)) return false;
|
|
10
|
+
const url = new URL(request.url || "/", `http://${host}`);
|
|
11
|
+
if (url.pathname === "/pair-auth") {
|
|
12
|
+
handlePairingAuth(request, response, url, pairingAuth, extensionToken);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const auth = url.pathname === "/runtime-auth" ? runtimeAuth : url.pathname === "/extension-auth" ? extensionAuth : null;
|
|
16
|
+
if (!auth) return false;
|
|
17
|
+
if (request.method !== "GET") {
|
|
18
|
+
response.writeHead(405, { allow: "GET", "cache-control": "no-store" }).end();
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (!hasAuthMarker(request)) {
|
|
22
|
+
response.writeHead(403, { "cache-control": "no-store" }).end();
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const issued = auth.issue(url.searchParams.get("challenge"), url.searchParams.get("init"));
|
|
26
|
+
if (!issued) {
|
|
27
|
+
response.writeHead(400, { "cache-control": "no-store" }).end();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
response.writeHead(204, proofHeaders(issued)).end();
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handlePairingAuth(request, response, url, pairingAuth, extensionToken) {
|
|
36
|
+
if (!hasAuthMarker(request)) {
|
|
37
|
+
response.writeHead(403, { "cache-control": "no-store" }).end();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const grantId = url.searchParams.get("grant");
|
|
41
|
+
const clientChallenge = url.searchParams.get("challenge");
|
|
42
|
+
if (request.method === "GET") {
|
|
43
|
+
const issued = pairingAuth.issue(grantId, clientChallenge, url.searchParams.get("init"));
|
|
44
|
+
if (!issued) { response.writeHead(401, { "cache-control": "no-store" }).end(); return; }
|
|
45
|
+
response.writeHead(204, proofHeaders(issued)).end();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (request.method === "POST") {
|
|
49
|
+
const ok = pairingAuth.consume(grantId, clientChallenge, url.searchParams.get("nonce"), url.searchParams.get("proof"));
|
|
50
|
+
if (!ok) { response.writeHead(401, { "cache-control": "no-store" }).end(); return; }
|
|
51
|
+
response.writeHead(204, { "cache-control": "no-store", "x-machine-bridge-extension-token": extensionToken }).end();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
response.writeHead(405, { allow: "GET, POST", "cache-control": "no-store" }).end();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hasAuthMarker(request) {
|
|
58
|
+
return request.headers[BROKER_AUTH_REQUEST_HEADER] === BROKER_AUTH_REQUEST_VALUE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function proofHeaders(issued) {
|
|
62
|
+
return {
|
|
63
|
+
"cache-control": "no-store",
|
|
64
|
+
"x-machine-bridge-broker-nonce": issued.serverNonce,
|
|
65
|
+
"x-machine-bridge-broker-proof": issued.serverProof,
|
|
66
|
+
};
|
|
67
|
+
}
|