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
package/src/worker/access.ts
CHANGED
|
@@ -5,8 +5,19 @@ import { policyAllowsAvailability, type DaemonPolicy } from "./policy.ts";
|
|
|
5
5
|
|
|
6
6
|
export type AccountRole = keyof typeof accessContract.roles;
|
|
7
7
|
|
|
8
|
+
export interface AuthorizedToken {
|
|
9
|
+
tokenKey: string;
|
|
10
|
+
accountId: string;
|
|
11
|
+
accountVersion: number;
|
|
12
|
+
clientId: string;
|
|
13
|
+
familyId: string;
|
|
14
|
+
dpopJkt: string;
|
|
15
|
+
role: AccountRole;
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
const roles = accessContract.roles as Record<string, { profile: string }>;
|
|
9
19
|
const profiles = policyContract.profiles as unknown as Record<string, DaemonPolicy>;
|
|
20
|
+
const ownerOnlyTools = new Set((accessContract.ownerOnlyTools as string[] | undefined)?.map(String) ?? []);
|
|
10
21
|
const toolAvailability = new Map((toolCatalog as Array<{ name: string; availability: string }>).map((tool) => [tool.name, tool.availability]));
|
|
11
22
|
|
|
12
23
|
export const ACCOUNT_ACCESS_REVISION = Number(accessContract.revision);
|
|
@@ -38,6 +49,7 @@ export function accountRolePolicy(role: AccountRole): DaemonPolicy {
|
|
|
38
49
|
|
|
39
50
|
export function accountRoleAllowsTool(role: AccountRole, toolName: string): boolean {
|
|
40
51
|
if (toolName === "server_info") return true;
|
|
52
|
+
if (role !== OWNER_ACCOUNT_ROLE && ownerOnlyTools.has(toolName)) return false;
|
|
41
53
|
const availability = toolAvailability.get(toolName);
|
|
42
54
|
return Boolean(availability && policyAllowsAvailability(accountRolePolicy(role), availability));
|
|
43
55
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ADMIN_AUTH_SCHEME, ADMIN_AUTH_TTL_SECONDS, adminAuthTranscript } from "../shared/admin-auth.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import type { AuthorityRevocation } from "../shared/authority-revocation.mjs";
|
|
3
|
+
import { decodeBase64Url, verifyDeviceSessionCertificate, verifyP256Signature } from "./device-session-verifier.ts";
|
|
4
|
+
import { json, methodNotAllowed, parseRequestBody, readBoundedBytes } from "./http.ts";
|
|
3
5
|
import { consumeBoundedNonce } from "./nonce-store.ts";
|
|
4
6
|
import {
|
|
5
7
|
accountByName, createAccount, publicAccount, replaceAccountPassword, revokeAccountCredentials,
|
|
6
|
-
|
|
8
|
+
updateAccount, type AccountRecord, type OAuthStore,
|
|
7
9
|
} from "./oauth-state.ts";
|
|
8
10
|
|
|
9
11
|
const BODY_LIMIT_BYTES = 64 * 1024;
|
|
@@ -12,22 +14,36 @@ const MAX_ACCOUNTS = 64;
|
|
|
12
14
|
export interface AccountAdminAuthorization {
|
|
13
15
|
nonce: string;
|
|
14
16
|
expiresAt: number;
|
|
17
|
+
request: Request;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export async function accountAdminAuthorized(
|
|
18
21
|
request: Request,
|
|
19
|
-
|
|
22
|
+
rootPublicKeyJson: string,
|
|
23
|
+
workerOrigin: string,
|
|
24
|
+
server: string,
|
|
25
|
+
version: string,
|
|
20
26
|
now = Math.floor(Date.now() / 1000),
|
|
21
27
|
): Promise<AccountAdminAuthorization | null> {
|
|
22
|
-
if (!
|
|
28
|
+
if (!rootPublicKeyJson) return null;
|
|
23
29
|
const scheme = request.headers.get("X-Bridge-Admin-Scheme") || "";
|
|
24
30
|
const issuedAt = Number(request.headers.get("X-Bridge-Admin-Time"));
|
|
25
31
|
const nonce = request.headers.get("X-Bridge-Admin-Nonce") || "";
|
|
26
32
|
const bodyHash = request.headers.get("X-Bridge-Admin-Body-SHA256") || "";
|
|
27
|
-
const
|
|
28
|
-
|
|
33
|
+
const keyId = request.headers.get("X-Bridge-Admin-Key") || "";
|
|
34
|
+
const suppliedSignature = decodeBase64Url(request.headers.get("X-Bridge-Admin-Signature") || "", 64);
|
|
35
|
+
if (scheme !== ADMIN_AUTH_SCHEME || !suppliedSignature) return null;
|
|
29
36
|
if (!Number.isSafeInteger(issuedAt) || Math.abs(now - issuedAt) > ADMIN_AUTH_TTL_SECONDS) return null;
|
|
30
|
-
if (!/^[A-Za-z0-9_-]{32,128}$/.test(nonce) || !/^[a-f0-9]{64}$/.test(bodyHash) || !/^[A-Za-z0-9_-]{
|
|
37
|
+
if (!/^[A-Za-z0-9_-]{32,128}$/.test(nonce) || !/^[a-f0-9]{64}$/.test(bodyHash) || !/^device_[A-Za-z0-9_-]{32}$/.test(keyId)) return null;
|
|
38
|
+
const certificate = await verifyDeviceSessionCertificate({
|
|
39
|
+
encodedCertificate: request.headers.get("X-Bridge-Device-Certificate") || "",
|
|
40
|
+
rootPublicKeyJson,
|
|
41
|
+
workerOrigin,
|
|
42
|
+
server,
|
|
43
|
+
version,
|
|
44
|
+
now,
|
|
45
|
+
});
|
|
46
|
+
if (!certificate || certificate.sessionKeyId !== keyId) return null;
|
|
31
47
|
let transcript: string;
|
|
32
48
|
try {
|
|
33
49
|
transcript = adminAuthTranscript({
|
|
@@ -35,26 +51,32 @@ export async function accountAdminAuthorized(
|
|
|
35
51
|
method: request.method.toUpperCase(),
|
|
36
52
|
pathname: new URL(request.url).pathname,
|
|
37
53
|
bodyHash,
|
|
54
|
+
keyId,
|
|
38
55
|
issuedAt,
|
|
39
56
|
nonce,
|
|
40
57
|
});
|
|
41
58
|
} catch {
|
|
42
59
|
return null;
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
new TextEncoder().encode(expected),
|
|
47
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
48
|
-
false,
|
|
49
|
-
["sign"],
|
|
50
|
-
);
|
|
51
|
-
const expectedSignature = base64Url(new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(transcript))));
|
|
52
|
-
if (!(await safeEqual(suppliedSignature, expectedSignature))) return null;
|
|
53
|
-
const body = new Uint8Array(await request.clone().arrayBuffer());
|
|
54
|
-
if (body.byteLength > BODY_LIMIT_BYTES) return null;
|
|
61
|
+
if (!(await verifyP256Signature(certificate.sessionPublicJwk, transcript, suppliedSignature))) return null;
|
|
62
|
+
const body = await readBoundedBytes(request, BODY_LIMIT_BYTES);
|
|
55
63
|
const actualBodyHash = hex(new Uint8Array(await crypto.subtle.digest("SHA-256", body)));
|
|
56
|
-
if (
|
|
57
|
-
return {
|
|
64
|
+
if (bodyHash !== actualBodyHash) return null;
|
|
65
|
+
return {
|
|
66
|
+
nonce,
|
|
67
|
+
expiresAt: Math.max(now, issuedAt) + ADMIN_AUTH_TTL_SECONDS,
|
|
68
|
+
request: rebuildBoundedAdminRequest(request, body),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function rebuildBoundedAdminRequest(request: Request, body: Uint8Array<ArrayBuffer>): Request {
|
|
73
|
+
const headers = new Headers(request.headers);
|
|
74
|
+
headers.delete("content-length");
|
|
75
|
+
const method = request.method.toUpperCase();
|
|
76
|
+
return new Request(request.url, {
|
|
77
|
+
method, headers,
|
|
78
|
+
body: method === "GET" || method === "HEAD" || body.byteLength === 0 ? undefined : body.buffer,
|
|
79
|
+
});
|
|
58
80
|
}
|
|
59
81
|
|
|
60
82
|
export async function consumeAccountAdminNonce(
|
|
@@ -69,6 +91,7 @@ export async function consumeAccountAdminNonce(
|
|
|
69
91
|
now,
|
|
70
92
|
noncePattern: /^[A-Za-z0-9_-]{32,128}$/,
|
|
71
93
|
maximum: 256,
|
|
94
|
+
maxFutureSeconds: ADMIN_AUTH_TTL_SECONDS * 2,
|
|
72
95
|
});
|
|
73
96
|
}
|
|
74
97
|
|
|
@@ -76,7 +99,7 @@ export async function handleAccountAdminOperation(options: {
|
|
|
76
99
|
request: Request;
|
|
77
100
|
operation: "accounts" | "rotate-password";
|
|
78
101
|
store: OAuthStore;
|
|
79
|
-
save: () => Promise<void>;
|
|
102
|
+
save: (revocation?: AuthorityRevocation) => Promise<void>;
|
|
80
103
|
now: number;
|
|
81
104
|
}): Promise<Response> {
|
|
82
105
|
const { request, operation, store, save, now } = options;
|
|
@@ -115,9 +138,10 @@ async function create(
|
|
|
115
138
|
return json({ account: publicAccount(account) }, 201);
|
|
116
139
|
}
|
|
117
140
|
|
|
118
|
-
async function update(body: Record<string, unknown>, store: OAuthStore, save: () => Promise<void>, now: number): Promise<Response> {
|
|
141
|
+
async function update(body: Record<string, unknown>, store: OAuthStore, save: (revocation?: AuthorityRevocation) => Promise<void>, now: number): Promise<Response> {
|
|
119
142
|
const account = store.accounts[String(body.account_id ?? "")];
|
|
120
143
|
if (!account) return json({ error: "account_not_found" }, 404);
|
|
144
|
+
const previousVersion = account.version;
|
|
121
145
|
const removesLastOwner = account.active && account.role === "owner" && activeOwnerCount(store) === 1
|
|
122
146
|
&& (body.active === false || (body.role !== undefined && body.role !== "owner"));
|
|
123
147
|
if (removesLastOwner) return json({ error: "last_owner_required" }, 409);
|
|
@@ -127,33 +151,37 @@ async function update(body: Record<string, unknown>, store: OAuthStore, save: ()
|
|
|
127
151
|
return json({ error: "invalid_account", message: "account display name, role, or active state is invalid" }, 400);
|
|
128
152
|
}
|
|
129
153
|
revokeAccountCredentials(store, account.account_id);
|
|
130
|
-
await save(
|
|
154
|
+
await save(account.version !== previousVersion ? {
|
|
155
|
+
accountId: account.account_id,
|
|
156
|
+
accountVersion: previousVersion,
|
|
157
|
+
} : undefined);
|
|
131
158
|
return json({ account: publicAccount(account) });
|
|
132
159
|
}
|
|
133
160
|
|
|
134
|
-
async function remove(body: Record<string, unknown>, store: OAuthStore, save: () => Promise<void>): Promise<Response> {
|
|
161
|
+
async function remove(body: Record<string, unknown>, store: OAuthStore, save: (revocation?: AuthorityRevocation) => Promise<void>): Promise<Response> {
|
|
135
162
|
const accountId = String(body.account_id ?? "");
|
|
136
163
|
const account = store.accounts[accountId];
|
|
137
164
|
if (!account) return json({ error: "account_not_found" }, 404);
|
|
138
165
|
if (account.active && account.role === "owner" && activeOwnerCount(store) === 1) return json({ error: "last_owner_required" }, 409);
|
|
139
166
|
revokeAccountCredentials(store, accountId);
|
|
140
167
|
delete store.accounts[accountId];
|
|
141
|
-
await save();
|
|
168
|
+
await save({ accountId, accountVersion: account.version });
|
|
142
169
|
return new Response(null, { status: 204 });
|
|
143
170
|
}
|
|
144
171
|
|
|
145
|
-
async function rotatePassword(request: Request, store: OAuthStore, save: () => Promise<void>, now: number): Promise<Response> {
|
|
172
|
+
async function rotatePassword(request: Request, store: OAuthStore, save: (revocation?: AuthorityRevocation) => Promise<void>, now: number): Promise<Response> {
|
|
146
173
|
if (request.method !== "POST") return methodNotAllowed("POST");
|
|
147
174
|
const body = await parseRequestBody(request, BODY_LIMIT_BYTES);
|
|
148
175
|
const account = store.accounts[String(body.account_id ?? "")];
|
|
149
176
|
if (!account) return json({ error: "account_not_found" }, 404);
|
|
177
|
+
const previousVersion = account.version;
|
|
150
178
|
try {
|
|
151
179
|
await replaceAccountPassword(account, body.password, now);
|
|
152
180
|
} catch {
|
|
153
181
|
return json({ error: "invalid_password", message: "account password must be a generated 256-bit token" }, 400);
|
|
154
182
|
}
|
|
155
183
|
revokeAccountCredentials(store, account.account_id);
|
|
156
|
-
await save();
|
|
184
|
+
await save({ accountId: account.account_id, accountVersion: previousVersion });
|
|
157
185
|
return json({ account: publicAccount(account) });
|
|
158
186
|
}
|
|
159
187
|
|
|
@@ -161,12 +189,6 @@ function activeOwnerCount(store: OAuthStore): number {
|
|
|
161
189
|
return Object.values(store.accounts).filter((account) => account.active && account.role === "owner").length;
|
|
162
190
|
}
|
|
163
191
|
|
|
164
|
-
function base64Url(bytes: Uint8Array): string {
|
|
165
|
-
let binary = "";
|
|
166
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
167
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
192
|
function hex(bytes: Uint8Array): string {
|
|
171
193
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
172
194
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { normalizeAuthorityRevocation, type AuthorityRevocation } from "../shared/authority-revocation.mjs";
|
|
2
|
+
import { randomToken } from "./oauth-state.ts";
|
|
3
|
+
|
|
4
|
+
export const AUTHORITY_REVOCATIONS_KEY = "authority-revocations";
|
|
5
|
+
const AUTHORITY_REVOCATION_SCHEMA = 1;
|
|
6
|
+
const MAX_AUTHORITY_REVOCATIONS = 1024;
|
|
7
|
+
const REVOCATION_ID = /^revoke_[A-Za-z0-9_-]{43}$/;
|
|
8
|
+
const QUEUE_FIELDS = new Set(["schema_version", "records"]);
|
|
9
|
+
const RECORD_FIELDS = new Set(["id", "account_id", "account_version", "client_id", "family_id", "queued_at"]);
|
|
10
|
+
|
|
11
|
+
type AuthorityRevocationRecord = Readonly<{
|
|
12
|
+
id: string;
|
|
13
|
+
account_id: string;
|
|
14
|
+
account_version: number;
|
|
15
|
+
client_id?: string;
|
|
16
|
+
family_id?: string;
|
|
17
|
+
queued_at: number;
|
|
18
|
+
}>;
|
|
19
|
+
type AuthorityRevocationQueue = { schema_version: 1; records: AuthorityRevocationRecord[] };
|
|
20
|
+
type RevocationStorage = Pick<DurableObjectStorage, "get" | "put" | "delete" | "transaction">;
|
|
21
|
+
type RevocationTransaction = Pick<DurableObjectTransaction, "get" | "put" | "delete">;
|
|
22
|
+
|
|
23
|
+
export async function putWithAuthorityRevocation(
|
|
24
|
+
storage: RevocationStorage,
|
|
25
|
+
writes: Readonly<Record<string, unknown>>,
|
|
26
|
+
revocation?: AuthorityRevocation,
|
|
27
|
+
now = Math.floor(Date.now() / 1000),
|
|
28
|
+
): Promise<void> {
|
|
29
|
+
return putWithAuthorityRevocations(storage, writes, revocation ? [revocation] : [], now);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function putWithAuthorityRevocations(
|
|
33
|
+
storage: RevocationStorage,
|
|
34
|
+
writes: Readonly<Record<string, unknown>>,
|
|
35
|
+
revocations: readonly AuthorityRevocation[],
|
|
36
|
+
now = Math.floor(Date.now() / 1000),
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
if (Object.hasOwn(writes, AUTHORITY_REVOCATIONS_KEY)) {
|
|
39
|
+
throw new Error("protected writes cannot replace the authority revocation queue");
|
|
40
|
+
}
|
|
41
|
+
if (revocations.length === 0) {
|
|
42
|
+
await storage.transaction(async (transaction) => {
|
|
43
|
+
await writeEntries(transaction, writes);
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const candidates = revocations.map((revocation) => recordFromRevocation(
|
|
48
|
+
normalizeAuthorityRevocationInput(revocation), randomToken("revoke"), now,
|
|
49
|
+
));
|
|
50
|
+
await storage.transaction(async (transaction) => {
|
|
51
|
+
const queue = await readQueue(transaction);
|
|
52
|
+
for (const candidate of candidates) mergeRevocation(queue, candidate);
|
|
53
|
+
await writeEntries(transaction, writes);
|
|
54
|
+
await transaction.put(AUTHORITY_REVOCATIONS_KEY, queue);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function writeEntries(
|
|
59
|
+
storage: Pick<RevocationTransaction, "put">,
|
|
60
|
+
writes: Readonly<Record<string, unknown>>,
|
|
61
|
+
): Promise<void> {
|
|
62
|
+
for (const [key, value] of Object.entries(writes)) await storage.put(key, value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function authorityRevocations(storage: Pick<DurableObjectStorage, "get">): Promise<AuthorityRevocationRecord[]> {
|
|
66
|
+
return [...(await readQueue(storage)).records];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function acknowledgeAuthorityRevocation(storage: RevocationStorage, revocationId: string): Promise<boolean> {
|
|
70
|
+
if (!REVOCATION_ID.test(revocationId)) return false;
|
|
71
|
+
return storage.transaction(async (transaction) => {
|
|
72
|
+
const queue = await readQueue(transaction);
|
|
73
|
+
const next = queue.records.filter((record) => record.id !== revocationId);
|
|
74
|
+
if (next.length === queue.records.length) return false;
|
|
75
|
+
if (next.length === 0) await transaction.delete(AUTHORITY_REVOCATIONS_KEY);
|
|
76
|
+
else await transaction.put(AUTHORITY_REVOCATIONS_KEY, { schema_version: 1, records: next });
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function authorityRevocationWireMessage(record: AuthorityRevocationRecord): Record<string, unknown> {
|
|
82
|
+
return {
|
|
83
|
+
type: "authority_revoke",
|
|
84
|
+
revocation_id: record.id,
|
|
85
|
+
account_id: record.account_id,
|
|
86
|
+
account_version: record.account_version,
|
|
87
|
+
...(record.client_id ? { client_id: record.client_id } : {}),
|
|
88
|
+
...(record.family_id ? { family_id: record.family_id } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function authorityRevocationAckId(value: unknown): string {
|
|
93
|
+
const id = String(value || "");
|
|
94
|
+
return REVOCATION_ID.test(id) ? id : "";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function normalizeAuthorityRevocationInput(value: AuthorityRevocation): AuthorityRevocation {
|
|
98
|
+
const normalized = normalizeAuthorityRevocation({
|
|
99
|
+
account_id: value.accountId,
|
|
100
|
+
account_version: value.accountVersion,
|
|
101
|
+
client_id: value.clientId,
|
|
102
|
+
family_id: value.familyId,
|
|
103
|
+
});
|
|
104
|
+
if (!normalized) throw new Error("authority revocation is invalid");
|
|
105
|
+
return normalized;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function recordFromRevocation(value: AuthorityRevocation, id: string, now: number): AuthorityRevocationRecord {
|
|
109
|
+
return Object.freeze({
|
|
110
|
+
id,
|
|
111
|
+
account_id: value.accountId,
|
|
112
|
+
account_version: value.accountVersion,
|
|
113
|
+
...(value.clientId ? { client_id: value.clientId } : {}),
|
|
114
|
+
...(value.familyId ? { family_id: value.familyId } : {}),
|
|
115
|
+
queued_at: Math.max(1, Math.floor(now)),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function mergeRevocation(queue: AuthorityRevocationQueue, candidate: AuthorityRevocationRecord): void {
|
|
120
|
+
if (queue.records.some((record) => covers(record, candidate))) return;
|
|
121
|
+
queue.records = queue.records.filter((record) => !covers(candidate, record));
|
|
122
|
+
if (queue.records.length >= MAX_AUTHORITY_REVOCATIONS) {
|
|
123
|
+
const collapsed = recordFromRevocation({
|
|
124
|
+
accountId: candidate.account_id,
|
|
125
|
+
accountVersion: candidate.account_version,
|
|
126
|
+
}, candidate.id, candidate.queued_at);
|
|
127
|
+
queue.records = queue.records.filter((record) => !sameAccountVersion(record, collapsed));
|
|
128
|
+
if (!queue.records.some((record) => covers(record, collapsed))) queue.records.push(collapsed);
|
|
129
|
+
} else {
|
|
130
|
+
queue.records.push(candidate);
|
|
131
|
+
}
|
|
132
|
+
if (queue.records.length > MAX_AUTHORITY_REVOCATIONS) throw new Error("authority revocation queue is full");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function covers(left: AuthorityRevocationRecord, right: AuthorityRevocationRecord): boolean {
|
|
136
|
+
if (!sameAccountVersion(left, right)) return false;
|
|
137
|
+
if (!left.client_id) return true;
|
|
138
|
+
if (left.client_id !== right.client_id) return false;
|
|
139
|
+
return !left.family_id || left.family_id === right.family_id;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function sameAccountVersion(left: AuthorityRevocationRecord, right: AuthorityRevocationRecord): boolean {
|
|
143
|
+
return left.account_id === right.account_id && left.account_version === right.account_version;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function readQueue(storage: Pick<RevocationStorage | RevocationTransaction, "get">): Promise<AuthorityRevocationQueue> {
|
|
147
|
+
const raw = await storage.get<unknown>(AUTHORITY_REVOCATIONS_KEY);
|
|
148
|
+
if (raw === undefined) return { schema_version: AUTHORITY_REVOCATION_SCHEMA, records: [] };
|
|
149
|
+
if (!validQueue(raw)) throw new Error("authority revocation state is invalid");
|
|
150
|
+
return { schema_version: 1, records: raw.records.map((record) => Object.freeze({ ...record })) };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function validQueue(value: unknown): value is AuthorityRevocationQueue {
|
|
154
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
155
|
+
const queue = value as Partial<AuthorityRevocationQueue>;
|
|
156
|
+
return Object.keys(value).every((key) => QUEUE_FIELDS.has(key))
|
|
157
|
+
&& queue.schema_version === AUTHORITY_REVOCATION_SCHEMA
|
|
158
|
+
&& Array.isArray(queue.records)
|
|
159
|
+
&& queue.records.length <= MAX_AUTHORITY_REVOCATIONS
|
|
160
|
+
&& queue.records.every(validRecord);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function validRecord(value: unknown): value is AuthorityRevocationRecord {
|
|
164
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
165
|
+
const record = value as Record<string, unknown>;
|
|
166
|
+
if (!Object.keys(record).every((key) => RECORD_FIELDS.has(key))
|
|
167
|
+
|| !REVOCATION_ID.test(String(record.id || "")) || !Number.isSafeInteger(record.queued_at) || Number(record.queued_at) <= 0) return false;
|
|
168
|
+
return Boolean(normalizeAuthorityRevocation({
|
|
169
|
+
account_id: record.account_id,
|
|
170
|
+
account_version: record.account_version,
|
|
171
|
+
client_id: record.client_id,
|
|
172
|
+
family_id: record.family_id,
|
|
173
|
+
}));
|
|
174
|
+
}
|
package/src/worker/authority.ts
CHANGED
|
@@ -31,6 +31,12 @@ type AccountAuthority = {
|
|
|
31
31
|
daemon_policy: string;
|
|
32
32
|
host_filtering: string;
|
|
33
33
|
};
|
|
34
|
+
execution_model: {
|
|
35
|
+
within_effective_authority: "automatic_without_per_operation_prompt";
|
|
36
|
+
owner_ambient_authority: "daemon_os_user" | "not_owner";
|
|
37
|
+
generic_control_plane_paths: "denied_even_for_owner";
|
|
38
|
+
mutually_untrusted_execution_requires: "external_os_isolation";
|
|
39
|
+
};
|
|
34
40
|
summary: string;
|
|
35
41
|
};
|
|
36
42
|
|
|
@@ -78,22 +84,38 @@ export function accountAuthoritySnapshot(input: AccountIdentity & {
|
|
|
78
84
|
daemon_policy: "daemon.policy is only the local daemon capability ceiling; it is not the authenticated account permission",
|
|
79
85
|
host_filtering: "the MCP host may expose a smaller subset than effective_tools, and Machine Bridge cannot observe that post-relay subset",
|
|
80
86
|
},
|
|
87
|
+
execution_model: {
|
|
88
|
+
within_effective_authority: "automatic_without_per_operation_prompt",
|
|
89
|
+
owner_ambient_authority: input.role === "owner" ? "daemon_os_user" : "not_owner",
|
|
90
|
+
generic_control_plane_paths: "denied_even_for_owner",
|
|
91
|
+
mutually_untrusted_execution_requires: "external_os_isolation",
|
|
92
|
+
},
|
|
81
93
|
summary: input.daemonPolicy
|
|
82
|
-
? `Authenticated account role ${input.role} has effective profile ${effectiveProfile}. daemon.policy.profile=${daemonProfile} is only the daemon capability ceiling, not this account's permission.`
|
|
83
|
-
: `Authenticated account role ${input.role} is configured for profile ${accountPolicy.profile}, but no daemon is connected; only Worker-local tools are currently available.`,
|
|
94
|
+
? `Authenticated account role ${input.role} has effective profile ${effectiveProfile}. daemon.policy.profile=${daemonProfile} is only the daemon capability ceiling, not this account's permission. Operations within effective authority execute automatically without a per-operation prompt${input.role === "owner" ? "; owner shell, browser, and application automation can act with the daemon OS user's ambient authority" : ""}.`
|
|
95
|
+
: `Authenticated account role ${input.role} is configured for profile ${accountPolicy.profile}, but no daemon is connected; only Worker-local tools are currently available. Operations within effective authority execute automatically without a per-operation prompt.`,
|
|
84
96
|
};
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
export function decorateProjectOverview(value: unknown, account: AccountIdentity): unknown {
|
|
88
100
|
if (!isRecord(value)) return value;
|
|
89
|
-
const daemonPolicy = isDaemonPolicy(value.
|
|
90
|
-
|
|
101
|
+
const daemonPolicy = isDaemonPolicy(value.daemonPolicy)
|
|
102
|
+
? value.daemonPolicy
|
|
103
|
+
: isDaemonPolicy(value.policy)
|
|
104
|
+
? value.policy
|
|
105
|
+
: null;
|
|
106
|
+
const daemonToolSource = Array.isArray(value.daemonTools) ? value.daemonTools : value.tools;
|
|
107
|
+
const daemonTools = Array.isArray(daemonToolSource)
|
|
108
|
+
? daemonToolSource.filter((item): item is string => typeof item === "string")
|
|
109
|
+
: [];
|
|
91
110
|
const effectiveTools = ["server_info", ...accountRoleToolNames(account.role, daemonTools)];
|
|
92
111
|
const authority = accountAuthoritySnapshot({ ...account, daemonPolicy, effectiveTools });
|
|
112
|
+
const projected = account.role === "owner" ? value : redactNonOwnerProjectOverview(value);
|
|
93
113
|
return {
|
|
94
|
-
...
|
|
114
|
+
...projected,
|
|
95
115
|
daemonPolicy,
|
|
96
|
-
daemonTools,
|
|
116
|
+
daemonToolCount: daemonTools.length,
|
|
117
|
+
daemonTools: account.role === "owner" ? daemonTools : [],
|
|
118
|
+
...(account.role === "owner" ? {} : { daemonToolsHiddenByAuthority: true }),
|
|
97
119
|
policy: authority.effective_policy,
|
|
98
120
|
tools: authority.effective_tools,
|
|
99
121
|
policyScope: "authenticated_account_effective_authority",
|
|
@@ -102,6 +124,30 @@ export function decorateProjectOverview(value: unknown, account: AccountIdentity
|
|
|
102
124
|
};
|
|
103
125
|
}
|
|
104
126
|
|
|
127
|
+
function redactNonOwnerProjectOverview(value: Record<string, unknown>): Record<string, unknown> {
|
|
128
|
+
const topLevel = Array.isArray(value.topLevel)
|
|
129
|
+
? value.topLevel.map((item) => projectTopLevelEntry(item))
|
|
130
|
+
: [];
|
|
131
|
+
return {
|
|
132
|
+
workspace: ".",
|
|
133
|
+
workspaceName: "workspace",
|
|
134
|
+
gitRoot: typeof value.gitRoot === "string" && value.gitRoot ? "." : "",
|
|
135
|
+
capabilityRouting: { activity_hidden_by_authority: true },
|
|
136
|
+
topLevel,
|
|
137
|
+
topLevelTotal: Number.isFinite(Number(value.topLevelTotal)) ? Number(value.topLevelTotal) : topLevel.length,
|
|
138
|
+
topLevelTruncated: value.topLevelTruncated === true,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function projectTopLevelEntry(value: unknown): Record<string, unknown> {
|
|
143
|
+
if (!isRecord(value)) return { name: "", type: "other" };
|
|
144
|
+
return {
|
|
145
|
+
name: typeof value.name === "string" ? value.name : "",
|
|
146
|
+
type: typeof value.type === "string" ? value.type : "other",
|
|
147
|
+
...(Number.isFinite(Number(value.size)) ? { size: Number(value.size) } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
105
151
|
function intersectPolicies(accountPolicy: DaemonPolicy, daemonPolicy: DaemonPolicy): EffectivePolicy {
|
|
106
152
|
const execMode = execRank[accountPolicy.execMode] <= execRank[daemonPolicy.execMode] ? accountPolicy.execMode : daemonPolicy.execMode;
|
|
107
153
|
const capabilities = {
|