@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.12.0
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/AGENTS.md +4 -2
- package/README.md +64 -18
- package/docs/architecture.md +2325 -270
- package/package.json +36 -20
- package/packages/extension/package.json +18 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +109 -70
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +31 -13
- package/packages/extension/src/bridge-handlers/lifecycle.ts +149 -66
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +309 -284
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +106 -37
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +153 -38
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +77 -6
- package/packages/extension/src/model-refresh.ts +69 -0
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +178 -30
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +487 -46
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +68 -10
- package/packages/extension/src/server-auto-start.ts +69 -3
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-sync.ts +53 -24
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-delivery.ts +11 -1
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +303 -64
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +12 -1
- package/packages/server/src/access/containment-gate.ts +113 -30
- package/packages/server/src/access/cwd-verdict.ts +3 -3
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +50 -11
- package/packages/server/src/access/planes.ts +107 -1
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/access/yolo-session.ts +54 -2
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +18 -5
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/auth/audit-log.ts +108 -0
- package/packages/server/src/auth/auth-plugin.ts +230 -38
- package/packages/server/src/auth/auth.ts +104 -4
- package/packages/server/src/auth/bearer-auth.ts +52 -12
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +90 -30
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +26 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +145 -11
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +69 -18
- package/packages/server/src/auth/localhost-guard.ts +98 -33
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
- package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-storage.ts +214 -12
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +111 -11
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +40 -2
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +34 -24
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +167 -63
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +146 -3
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +229 -53
- package/packages/server/src/config-api.ts +53 -35
- package/packages/server/src/config-snapshot.ts +197 -1
- package/packages/server/src/directory-service.ts +193 -68
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +322 -207
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +45 -11
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +18 -2
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +11 -3
- package/packages/server/src/identity/ws-road-classification.ts +3 -1
- package/packages/server/src/known-server-moves.ts +36 -15
- package/packages/server/src/lib/browse-roots.ts +129 -17
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +513 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/eml.ts +5 -10
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +96 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +49 -13
- package/packages/server/src/lib/path-containment.ts +50 -10
- package/packages/server/src/lib/resolve-file-mention.ts +234 -40
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +26 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/lifecycle/recovery-server.ts +65 -18
- package/packages/server/src/live-server/capability-redact.ts +31 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +615 -44
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +141 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +25 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +220 -33
- package/packages/server/src/live-server/live-server-proxy.ts +411 -50
- package/packages/server/src/live-server/live-static.ts +231 -0
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
- package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +141 -267
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/provider-probe.ts +202 -7
- package/packages/server/src/pairing/browser-gateway.ts +325 -51
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/paired-devices.ts +702 -27
- package/packages/server/src/pairing/pairing.ts +103 -11
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +61 -2
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/host-project-trust.ts +29 -15
- package/packages/server/src/pi/pi-gateway.ts +398 -41
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +18 -7
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +182 -15
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +640 -279
- package/packages/server/src/routes/file-write-binary-routes.ts +97 -24
- package/packages/server/src/routes/folder-project-routes.ts +18 -12
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +340 -273
- package/packages/server/src/routes/grep-routes.ts +64 -14
- package/packages/server/src/routes/known-servers-routes.ts +189 -91
- package/packages/server/src/routes/live-server-routes.ts +572 -15
- package/packages/server/src/routes/local-proof-routes.ts +14 -0
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +396 -31
- package/packages/server/src/routes/package-routes.ts +58 -10
- package/packages/server/src/routes/pairing-routes.ts +342 -17
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +181 -10
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/resource-activation-routes.ts +18 -4
- package/packages/server/src/routes/session-routes.ts +75 -25
- package/packages/server/src/routes/system-routes.ts +169 -52
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +1139 -291
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/memory-session-manager.ts +31 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +32 -4
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +393 -77
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/terminal/terminal-manager.ts +54 -46
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +2 -0
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +172 -26
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +285 -59
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +443 -187
- package/packages/shared/src/containment-guard.ts +45 -0
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +2 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +100 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +58 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +47 -3
- package/packages/shared/src/dashboard-plugin/slot-types.ts +9 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +39 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +94 -27
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +161 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +176 -0
- package/packages/shared/src/mdns-discovery.ts +25 -6
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-poller.ts +3 -2
- package/packages/shared/src/pairing-knock-client.ts +135 -11
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +21 -11
- package/packages/shared/src/pi-trust-mirror-types.ts +38 -3
- package/packages/shared/src/pi-trust-mirror.ts +47 -11
- package/packages/shared/src/pi-trust-resource-digest.ts +261 -0
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +14 -8
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +452 -5
- package/packages/shared/src/platform/resolve-pi-shell.ts +105 -0
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +192 -0
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +187 -86
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +97 -26
- package/packages/shared/src/recovery-timing.ts +27 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +148 -11
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +149 -4
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/server-launcher.ts +9 -1
- package/packages/shared/src/server-pinning.ts +55 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/definitions.ts +5 -5
- package/packages/shared/src/tool-registry/strategies.ts +13 -12
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +134 -109
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +15 -0
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +11 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
|
@@ -15,14 +15,25 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import type { TLSSocket } from "node:tls";
|
|
18
|
+
import {
|
|
19
|
+
devbindMessage,
|
|
20
|
+
devcheckMessage,
|
|
21
|
+
isDevicePub,
|
|
22
|
+
} from "@blackbelt-technology/pi-dashboard-shared/device-key-proof.js";
|
|
23
|
+
import type { PairPollData } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
18
24
|
import { isTier, TIERS } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
|
|
25
|
+
import { TLS_ONLY_TOKEN_UNTRUSTED_CHANNEL } from "@blackbelt-technology/pi-dashboard-shared/tls-only-token.js";
|
|
19
26
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
20
27
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
21
28
|
import { describeApprovalRefusal } from "../auth/approval-refusal.js";
|
|
29
|
+
import { auditDeviceEvent, auditKeyEvent, auditLine, auditPrefix, auditRequestFields } from "../auth/audit-log.js";
|
|
30
|
+
import { parseBearerHeader, ROTATE_ROUTE } from "../auth/bearer-auth.js";
|
|
31
|
+
import { DeviceNonceStore, DeviceStatusLimiter, RevokedAnswerLog, verifyNonceProof } from "../auth/device-proof.js";
|
|
22
32
|
import { type HostAdmissionOptions, isHostAdmitted } from "../auth/host-admission.js";
|
|
23
33
|
import type { ServerIdentity } from "../auth/identity.js";
|
|
24
34
|
import { signNonce } from "../auth/identity.js";
|
|
25
35
|
import { hasLocalCredential } from "../auth/local-credential.js";
|
|
36
|
+
import { bearerChannelOf, isProvenChannel } from "../auth/proven-tls.js";
|
|
26
37
|
import { createLocalTrustContext, hasLocalProof, type LocalTrustContext } from "../auth/local-proof.js";
|
|
27
38
|
import { isLocallyTrusted, type LanInterface } from "../auth/localhost-guard.js";
|
|
28
39
|
import {
|
|
@@ -33,12 +44,37 @@ import {
|
|
|
33
44
|
knockPeerInput,
|
|
34
45
|
knockPeerState,
|
|
35
46
|
} from "../pairing/knock-admission.js";
|
|
36
|
-
import
|
|
37
|
-
import
|
|
47
|
+
import { createDeviceKeyIntake } from "../pairing/device-key-intake.js";
|
|
48
|
+
import {
|
|
49
|
+
BRIDGE_TOKEN_REQUIRES_HTTPS,
|
|
50
|
+
keyIdOf,
|
|
51
|
+
type PairedDeviceRegistry,
|
|
52
|
+
type PairedDeviceView,
|
|
53
|
+
} from "../pairing/paired-devices.js";
|
|
54
|
+
import type { ApprovedKeys, ApproveResult, PairingManager, PendingDeviceView } from "../pairing/pairing.js";
|
|
38
55
|
import { SUPPORTED_PAIRING_VERSIONS } from "../pairing/pairing.js";
|
|
39
56
|
import { localEndpoints } from "../tunnel/tunnel-endpoints.js";
|
|
40
57
|
import type { NetworkGuard } from "./route-deps.js";
|
|
41
58
|
|
|
59
|
+
/**
|
|
60
|
+
* The `https:` origins of the reachable list, de-duplicated, in order. `wss://`
|
|
61
|
+
* and the `PI_E2E_SEED` loopback `http` origin that `reachableUrls()` admits for
|
|
62
|
+
* the QR payload are NOT routes. See change: group-servers-by-identity (D7).
|
|
63
|
+
*/
|
|
64
|
+
function httpsOrigins(urls: readonly string[]): string[] {
|
|
65
|
+
const out: string[] = [];
|
|
66
|
+
for (const raw of urls) {
|
|
67
|
+
let url: URL;
|
|
68
|
+
try {
|
|
69
|
+
url = new URL(raw);
|
|
70
|
+
} catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (url.protocol === "https:" && !out.includes(url.origin)) out.push(url.origin);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
/** Strip trailing slashes without a regex (avoids a polynomial-ReDoS shape). */
|
|
43
79
|
function stripTrailingSlashes(u: string): string {
|
|
44
80
|
let end = u.length;
|
|
@@ -49,6 +85,9 @@ function stripTrailingSlashes(u: string): string {
|
|
|
49
85
|
/** URL prefixes of the PUBLIC device-facing pairing routes (auth-exempt). */
|
|
50
86
|
export const PUBLIC_PAIRING_PREFIXES = [
|
|
51
87
|
"/api/pair/challenge",
|
|
88
|
+
// device-key-mutual-check (D1): answers only a signed proof of the asked-about key. NOT a string prefix of
|
|
89
|
+
// `/api/pair/device-key` (the credentialed bind route) — the auth hook matches by `startsWith`.
|
|
90
|
+
"/api/pair/device-status",
|
|
52
91
|
"/api/pair/redeem",
|
|
53
92
|
"/api/pair/poll",
|
|
54
93
|
// Device-initiated knock: public like `redeem`; the admission gates in
|
|
@@ -81,6 +120,19 @@ function approveFailure(
|
|
|
81
120
|
: { success: false, error: result.error };
|
|
82
121
|
}
|
|
83
122
|
|
|
123
|
+
/** One audit line per key / companion outcome of an approval, caused by the operator's request. */
|
|
124
|
+
function auditApprovedKeys(request: FastifyRequest, deviceId: string, keys: ApprovedKeys | undefined): void {
|
|
125
|
+
if (!keys) return;
|
|
126
|
+
if (keys.key) auditKeyEvent(keys.key.bound ? "key_bound" : "key_ignored", deviceId, keys.key.id, request);
|
|
127
|
+
if (keys.companion) auditKeyEvent(keys.companion.allowed ? "companion_allowed" : "key_ignored", deviceId, keys.companion.id, request);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Optional `allowCompanion`: absent → false; a supplied non-boolean is invalid (null). */
|
|
131
|
+
function parseAllowCompanion(v: unknown): boolean | null {
|
|
132
|
+
if (v === undefined) return false;
|
|
133
|
+
return typeof v === "boolean" ? v : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
84
136
|
/**
|
|
85
137
|
* Operator guard for the credential-bearing pairing routes (D5): mint,
|
|
86
138
|
* approve, pending list, deny, revoke.
|
|
@@ -192,6 +244,66 @@ function createApprovalGuard(deps: {
|
|
|
192
244
|
};
|
|
193
245
|
}
|
|
194
246
|
|
|
247
|
+
/**
|
|
248
|
+
* `POST /api/paired-devices/rotate` — a browser-held device bearer rotates ITSELF.
|
|
249
|
+
*
|
|
250
|
+
* Authenticated ONLY by `Authorization: Bearer`: a cookie, local proof, operator
|
|
251
|
+
* session or nothing is 401 `bearer_required`, and any device id in the body is
|
|
252
|
+
* ignored (the bearer identifies the row). Deliberately no `networkGuard`: the
|
|
253
|
+
* bearer is the sole credential, so no network position can stand in for it.
|
|
254
|
+
* The registry does the work synchronously (no await between verify and write),
|
|
255
|
+
* so two same-tick rotations with one bearer serialise (second → 409
|
|
256
|
+
* `bearer_superseded`). Success returns `{token, expiresAt}` with `no-store`.
|
|
257
|
+
* An EXPIRED bearer is refused earlier by the bearer hook (401 `bearer_expired`).
|
|
258
|
+
* See change: harden-auth-credentials (D5).
|
|
259
|
+
*/
|
|
260
|
+
export function registerBearerRotateRoute(fastify: FastifyInstance, deps: { registry: PairedDeviceRegistry }): void {
|
|
261
|
+
const { registry } = deps;
|
|
262
|
+
fastify.post<{ Body: unknown }>(ROTATE_ROUTE, async (request, reply) => {
|
|
263
|
+
reply.header("Cache-Control", "no-store");
|
|
264
|
+
const presented = parseBearerHeader(request.headers.authorization);
|
|
265
|
+
if (!presented) {
|
|
266
|
+
reply.code(401);
|
|
267
|
+
return { success: false, error: "bearer_required", code: "bearer_required" };
|
|
268
|
+
}
|
|
269
|
+
const body = request.body;
|
|
270
|
+
// Only the exact string "browser" is a declaration; anything else is none (A-G11).
|
|
271
|
+
const declared =
|
|
272
|
+
body !== null && typeof body === "object" && (body as Record<string, unknown>).holder === "browser";
|
|
273
|
+
const result = registry.rotate(presented, declared, { channel: bearerChannelOf(request.raw) });
|
|
274
|
+
if (result.ok) {
|
|
275
|
+
auditLine("pairing", "rotated", { id: auditPrefix(result.id), ip: request.ip });
|
|
276
|
+
return { token: result.token, expiresAt: result.expiresAt };
|
|
277
|
+
}
|
|
278
|
+
const refuse = (status: number, code: string) => {
|
|
279
|
+
if (result.id !== undefined) {
|
|
280
|
+
auditLine("pairing", "rotate_refused", { id: auditPrefix(result.id), reason: code, ip: request.ip });
|
|
281
|
+
}
|
|
282
|
+
reply.code(status);
|
|
283
|
+
return { success: false, error: code, code };
|
|
284
|
+
};
|
|
285
|
+
switch (result.reason) {
|
|
286
|
+
case "expired":
|
|
287
|
+
return refuse(401, "bearer_expired");
|
|
288
|
+
case "superseded":
|
|
289
|
+
return refuse(409, "bearer_superseded");
|
|
290
|
+
case "holder_declaration_required":
|
|
291
|
+
return refuse(409, "holder_declaration_required");
|
|
292
|
+
case "persist_failed":
|
|
293
|
+
return refuse(500, "rotation_failed");
|
|
294
|
+
case "tls_only_untrusted_channel":
|
|
295
|
+
return refuse(401, TLS_ONLY_TOKEN_UNTRUSTED_CHANNEL);
|
|
296
|
+
case "rate_limited":
|
|
297
|
+
reply.header("Retry-After", String(result.retryAfterS ?? 60));
|
|
298
|
+
return refuse(429, "rate_limited");
|
|
299
|
+
default:
|
|
300
|
+
// Unknown / revoked / superseded-after-grace: a plain 401, byte-equal to every other route's.
|
|
301
|
+
reply.code(401);
|
|
302
|
+
return { success: false, error: "unauthorized" };
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
195
307
|
export function registerPairingRoutes(
|
|
196
308
|
fastify: FastifyInstance,
|
|
197
309
|
deps: {
|
|
@@ -212,6 +324,8 @@ export function registerPairingRoutes(
|
|
|
212
324
|
* list so the browser Settings flow and the CLI share one source (D8).
|
|
213
325
|
*/
|
|
214
326
|
getReachableUrls?: () => string[];
|
|
327
|
+
/** Certificate-backed `https://` URLs of the native TLS listener (named in a refused bridge-token issue). */
|
|
328
|
+
getTlsListenerUrls?: () => string[];
|
|
215
329
|
/** Bound HTTP port, used to enumerate loopback/LAN endpoints. A thunk so
|
|
216
330
|
* a `port: 0` server reports the real bound port per request. */
|
|
217
331
|
getPort?: () => number;
|
|
@@ -230,6 +344,12 @@ export function registerPairingRoutes(
|
|
|
230
344
|
/** Injectable limiter / refusal logger (tests). */
|
|
231
345
|
knockLimiter?: KnockLimiter;
|
|
232
346
|
logKnockRefusal?: ReturnType<typeof createRefusalLogger>;
|
|
347
|
+
/** Injectable device-check state (tests, injected clocks). See change: device-key-mutual-check. */
|
|
348
|
+
deviceNonces?: DeviceNonceStore;
|
|
349
|
+
deviceStatusLimiter?: DeviceStatusLimiter;
|
|
350
|
+
revokedAnswerLog?: RevokedAnswerLog;
|
|
351
|
+
/** Clock for the companion `ts` window (tests). */
|
|
352
|
+
now?: () => number;
|
|
233
353
|
},
|
|
234
354
|
) {
|
|
235
355
|
const { networkGuard, identity, pairing, registry, localToken, hostAdmission } = deps;
|
|
@@ -241,6 +361,15 @@ export function registerPairingRoutes(
|
|
|
241
361
|
loginAvailable: deps.loginAvailable,
|
|
242
362
|
getConfigPort: deps.getPort,
|
|
243
363
|
});
|
|
364
|
+
const deviceNonces = deps.deviceNonces ?? new DeviceNonceStore();
|
|
365
|
+
const deviceStatusLimiter = deps.deviceStatusLimiter ?? new DeviceStatusLimiter();
|
|
366
|
+
const revokedAnswerLog = deps.revokedAnswerLog ?? new RevokedAnswerLog();
|
|
367
|
+
const keyIntake = createDeviceKeyIntake({
|
|
368
|
+
nonces: deviceNonces,
|
|
369
|
+
registry,
|
|
370
|
+
fingerprint: () => identity.fingerprint,
|
|
371
|
+
now: deps.now,
|
|
372
|
+
});
|
|
244
373
|
const knockLimiter = deps.knockLimiter ?? new KnockLimiter();
|
|
245
374
|
const logKnockRefusal = deps.logKnockRefusal ?? createRefusalLogger();
|
|
246
375
|
// Denial / lockout start the source's cooldown; approve + expiry do not (D12).
|
|
@@ -255,7 +384,10 @@ export function registerPairingRoutes(
|
|
|
255
384
|
// pinned public key and detect an impostor on a reused URL.
|
|
256
385
|
fastify.post<{ Body: { nonce?: string } }>(
|
|
257
386
|
"/api/pair/challenge",
|
|
258
|
-
async (
|
|
387
|
+
async (
|
|
388
|
+
request,
|
|
389
|
+
reply,
|
|
390
|
+
): Promise<ApiResponse<{ fingerprint: string; publicKey: string; signature: string; v: number; deviceNonce: string }>> => {
|
|
259
391
|
const nonce = request.body?.nonce;
|
|
260
392
|
if (typeof nonce !== "string" || nonce.length < 8 || nonce.length > 512) {
|
|
261
393
|
reply.code(400);
|
|
@@ -268,11 +400,70 @@ export function registerPairingRoutes(
|
|
|
268
400
|
publicKey: identity.publicKeyB64,
|
|
269
401
|
signature: signNonce(identity, nonce),
|
|
270
402
|
v: Math.max(...SUPPORTED_PAIRING_VERSIONS),
|
|
403
|
+
// Step 2 of the device check: single-use, 60 s. Never rate-limited by the status limiter.
|
|
404
|
+
deviceNonce: deviceNonces.issue(),
|
|
271
405
|
},
|
|
272
406
|
};
|
|
273
407
|
},
|
|
274
408
|
);
|
|
275
409
|
|
|
410
|
+
// ── Device check, step 2 (public): the status of the caller's OWN key ──
|
|
411
|
+
// Verify-before-lookup. Every failure — bad shape, bad signature, unknown / expired / used nonce,
|
|
412
|
+
// rate limit, even an unparseable body — is the same `{"status":"unverified"}` at HTTP 200, so the
|
|
413
|
+
// reply never says whether a key exists. See change: device-key-mutual-check (D1, D2).
|
|
414
|
+
const UNVERIFIED = { status: "unverified" } as const;
|
|
415
|
+
fastify.post<{ Body: unknown }>(
|
|
416
|
+
"/api/pair/device-status",
|
|
417
|
+
{
|
|
418
|
+
errorHandler: (_err, _request, reply) => {
|
|
419
|
+
reply.header("Cache-Control", "no-store").code(200).send(UNVERIFIED);
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
async (request, reply) => {
|
|
423
|
+
reply.header("Cache-Control", "no-store");
|
|
424
|
+
// Socket peer, like the knock admission — never `request.ip`.
|
|
425
|
+
if (!deviceStatusLimiter.allow(request.socket.remoteAddress ?? "unknown")) return UNVERIFIED;
|
|
426
|
+
const body = request.body;
|
|
427
|
+
const fields = body !== null && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
428
|
+
if (!verifyNonceProof(deviceNonces, fields, (n) => devcheckMessage(identity.fingerprint, n))) return UNVERIFIED;
|
|
429
|
+
const answer = registry.deviceKeyStatus(fields.pub as string);
|
|
430
|
+
revokedAnswerLog.note(keyIdOf(fields.pub as string), answer.status);
|
|
431
|
+
return answer;
|
|
432
|
+
},
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
// ── Credentialed device: bind / replace its own key (D3) ───────────────
|
|
436
|
+
// Only the device's OWN credential (bearer or cookie → `authVia === "device"`), at any tier. No
|
|
437
|
+
// `networkGuard`: the device credential itself is the stricter condition and anonymous is 401 here.
|
|
438
|
+
fastify.post<{ Body: unknown }>(
|
|
439
|
+
"/api/pair/device-key",
|
|
440
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
441
|
+
const authed = request as { authVia?: string; principalDeviceId?: string };
|
|
442
|
+
if (authed.authVia !== "device" || typeof authed.principalDeviceId !== "string") {
|
|
443
|
+
reply.code(401);
|
|
444
|
+
return { success: false, error: "device credential required" };
|
|
445
|
+
}
|
|
446
|
+
const body = request.body;
|
|
447
|
+
const fields = body !== null && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
448
|
+
if (!verifyNonceProof(deviceNonces, fields, (n) => devbindMessage(identity.fingerprint, n))) {
|
|
449
|
+
reply.code(400);
|
|
450
|
+
return { success: false, error: "invalid_device_key_proof" };
|
|
451
|
+
}
|
|
452
|
+
const pub = fields.pub as string;
|
|
453
|
+
const result = registry.bindKey(authed.principalDeviceId, pub);
|
|
454
|
+
if (result === "held") {
|
|
455
|
+
reply.code(409);
|
|
456
|
+
return { success: false, error: "key_held" };
|
|
457
|
+
}
|
|
458
|
+
if (result === "no-device") {
|
|
459
|
+
reply.code(401);
|
|
460
|
+
return { success: false, error: "device credential required" };
|
|
461
|
+
}
|
|
462
|
+
auditKeyEvent(result === "replaced" ? "key_replaced" : "key_bound", authed.principalDeviceId, keyIdOf(pub), request);
|
|
463
|
+
return { success: true };
|
|
464
|
+
},
|
|
465
|
+
);
|
|
466
|
+
|
|
276
467
|
// ── Dashboard: mint a pairing payload (authenticated) — Task 2.3 ───────
|
|
277
468
|
fastify.get(
|
|
278
469
|
"/api/pair/payload",
|
|
@@ -290,7 +481,7 @@ export function registerPairingRoutes(
|
|
|
290
481
|
);
|
|
291
482
|
|
|
292
483
|
// ── Device: redeem a code → pending device + confirm code (public) ─────
|
|
293
|
-
fastify.post<{ Body: { code?: string } }>(
|
|
484
|
+
fastify.post<{ Body: { code?: string; holder?: unknown; deviceKey?: unknown } }>(
|
|
294
485
|
"/api/pair/redeem",
|
|
295
486
|
async (request, reply): Promise<ApiResponse<{ pendingId: string; confirmCode: string }>> => {
|
|
296
487
|
const code = request.body?.code;
|
|
@@ -298,13 +489,19 @@ export function registerPairingRoutes(
|
|
|
298
489
|
reply.code(400);
|
|
299
490
|
return { success: false, error: "code required" };
|
|
300
491
|
}
|
|
492
|
+
// The device key (if any) is verified and its nonce consumed on ARRIVAL; an invalid / held key is
|
|
493
|
+
// dropped silently and the response is unchanged. See change: device-key-mutual-check (D3).
|
|
494
|
+
const { deviceKey } = keyIntake.accept({ deviceKey: request.body?.deviceKey });
|
|
301
495
|
// Redeemer metadata is untrusted display text for the operator dialog;
|
|
302
496
|
// the manager bounds it and never uses it for a decision (D4).
|
|
303
497
|
const result = pairing.redeem(code, {
|
|
498
|
+
...(deviceKey ? { deviceKey } : {}),
|
|
304
499
|
userAgent: headerString(request.headers["user-agent"]),
|
|
305
500
|
host: headerString(request.headers.host),
|
|
306
501
|
remoteAddress: request.ip,
|
|
307
502
|
forwardedFor: headerString(request.headers["x-forwarded-for"]),
|
|
503
|
+
// Only the exact string "browser" is a holder declaration (the manager enforces it).
|
|
504
|
+
holder: request.body?.holder,
|
|
308
505
|
});
|
|
309
506
|
if (!result.ok) {
|
|
310
507
|
reply.code(result.error === "rate_limited" ? 429 : 400);
|
|
@@ -321,7 +518,7 @@ export function registerPairingRoutes(
|
|
|
321
518
|
// semantics), the LAN gates, the switch and the limits. Admission uses the
|
|
322
519
|
// SOCKET peer address — never `request.ip` — and that same address is recorded
|
|
323
520
|
// as the pending device's remote address.
|
|
324
|
-
fastify.post<{ Body: { name?: unknown } | null }>(
|
|
521
|
+
fastify.post<{ Body: { name?: unknown; holder?: unknown; deviceKey?: unknown; companion?: unknown } | null }>(
|
|
325
522
|
"/api/pair/request",
|
|
326
523
|
async (
|
|
327
524
|
request,
|
|
@@ -359,6 +556,8 @@ export function registerPairingRoutes(
|
|
|
359
556
|
? { success: false, error: decision.error }
|
|
360
557
|
: { success: false, error: decision.error, retryAfter: decision.retryAfter };
|
|
361
558
|
}
|
|
559
|
+
// Verified only for an ADMITTED knock, on arrival; invalid / replayed / held → dropped silently.
|
|
560
|
+
const keys = keyIntake.accept(request.body);
|
|
362
561
|
const result = pairing.knock({
|
|
363
562
|
sourceKey: decision.sourceKey,
|
|
364
563
|
name: request.body?.name,
|
|
@@ -367,6 +566,8 @@ export function registerPairingRoutes(
|
|
|
367
566
|
userAgent: headerString(request.headers["user-agent"]),
|
|
368
567
|
host: headerString(request.headers.host),
|
|
369
568
|
remoteAddress: decision.sourceKey,
|
|
569
|
+
holder: request.body?.holder,
|
|
570
|
+
...keys,
|
|
370
571
|
},
|
|
371
572
|
});
|
|
372
573
|
return {
|
|
@@ -387,7 +588,7 @@ export function registerPairingRoutes(
|
|
|
387
588
|
// could mint a second durable token that survives its own revocation
|
|
388
589
|
// (CodeRabbit CWE-862). `operatorGuard` admits only a dashboard login session,
|
|
389
590
|
// the local token, or a genuinely-local caller.
|
|
390
|
-
fastify.post<{ Body: { code?: string; confirmCode?: string; label?: string; tier?: unknown } }>(
|
|
591
|
+
fastify.post<{ Body: { code?: string; confirmCode?: string; label?: string; tier?: unknown; allowCompanion?: unknown } }>(
|
|
391
592
|
"/api/pair/approve",
|
|
392
593
|
{ preHandler: approvalGuard },
|
|
393
594
|
async (request, reply): Promise<ApiResponse<PairedDeviceView>> => {
|
|
@@ -419,7 +620,12 @@ export function registerPairingRoutes(
|
|
|
419
620
|
}
|
|
420
621
|
label = trimmed;
|
|
421
622
|
}
|
|
422
|
-
const
|
|
623
|
+
const allowCompanion = parseAllowCompanion(request.body?.allowCompanion);
|
|
624
|
+
if (allowCompanion === null) {
|
|
625
|
+
reply.code(400);
|
|
626
|
+
return { success: false, error: "allowCompanion must be a boolean" };
|
|
627
|
+
}
|
|
628
|
+
const result = pairing.approve(code, confirmCode, label, isTier(tier) ? tier : undefined, { allowCompanion });
|
|
423
629
|
if (!result.ok) {
|
|
424
630
|
// Status codes unchanged for this route (no_pending stays 400); a
|
|
425
631
|
// mismatch additionally carries `attemptsLeft` (additive, D2).
|
|
@@ -428,6 +634,7 @@ export function registerPairingRoutes(
|
|
|
428
634
|
? ({ success: false, error: result.error, attemptsLeft: result.attemptsLeft } as ApiResponse<PairedDeviceView>)
|
|
429
635
|
: { success: false, error: result.error };
|
|
430
636
|
}
|
|
637
|
+
auditApprovedKeys(request, result.device.id, result.keys);
|
|
431
638
|
return { success: true, data: result.device };
|
|
432
639
|
},
|
|
433
640
|
);
|
|
@@ -442,7 +649,9 @@ export function registerPairingRoutes(
|
|
|
442
649
|
);
|
|
443
650
|
|
|
444
651
|
// ── Dashboard: approve by pendingId (typed confirm code, operator-only) ─
|
|
445
|
-
fastify.post<{
|
|
652
|
+
fastify.post<{
|
|
653
|
+
Body: { pendingId?: unknown; confirmCode?: unknown; label?: unknown; tier?: unknown; allowCompanion?: unknown };
|
|
654
|
+
}>(
|
|
446
655
|
"/api/pair/approve-pending",
|
|
447
656
|
{ preHandler: approvalGuard },
|
|
448
657
|
async (request, reply): Promise<ApiResponse<PairedDeviceView> & { attemptsLeft?: number }> => {
|
|
@@ -464,8 +673,15 @@ export function registerPairingRoutes(
|
|
|
464
673
|
reply.code(400);
|
|
465
674
|
return { success: false, error: `label must be 1..${MAX_DEVICE_LABEL_BYTES} UTF-8 bytes` };
|
|
466
675
|
}
|
|
467
|
-
|
|
676
|
+
// Opt-in, default off: the companion is stored only when the operator ticked the box.
|
|
677
|
+
const allowCompanion = parseAllowCompanion(request.body?.allowCompanion);
|
|
678
|
+
if (allowCompanion === null) {
|
|
679
|
+
reply.code(400);
|
|
680
|
+
return { success: false, error: "allowCompanion must be a boolean" };
|
|
681
|
+
}
|
|
682
|
+
const result = pairing.approvePending(pendingId, confirmCode, name, isTier(tier) ? tier : undefined, { allowCompanion });
|
|
468
683
|
if (!result.ok) return approveFailure(result, reply);
|
|
684
|
+
auditApprovedKeys(request, result.device.id, result.keys);
|
|
469
685
|
return { success: true, data: result.device };
|
|
470
686
|
},
|
|
471
687
|
);
|
|
@@ -492,15 +708,30 @@ export function registerPairingRoutes(
|
|
|
492
708
|
);
|
|
493
709
|
|
|
494
710
|
// ── Device: poll for approval + collect the bearer token (public) ──────
|
|
495
|
-
fastify.post<{ Body: { pendingId?: string } }>(
|
|
711
|
+
fastify.post<{ Body: { pendingId?: string; holder?: unknown } }>(
|
|
496
712
|
"/api/pair/poll",
|
|
497
|
-
async (request, reply): Promise<ApiResponse<
|
|
713
|
+
async (request, reply): Promise<ApiResponse<PairPollData>> => {
|
|
498
714
|
const pendingId = request.body?.pendingId;
|
|
499
715
|
if (typeof pendingId !== "string") {
|
|
500
716
|
reply.code(400);
|
|
501
717
|
return { success: false, error: "pendingId required" };
|
|
502
718
|
}
|
|
503
|
-
const result = pairing.poll(pendingId);
|
|
719
|
+
const result = pairing.poll(pendingId, request.body?.holder, bearerChannelOf(request.raw));
|
|
720
|
+
// Route delegation (D7): the one approved answer that carries the token also
|
|
721
|
+
// names the server's https origins. Filtered here, not in PairingManager.poll,
|
|
722
|
+
// so knock and QR redemption both get it and the QR payload `urls` stay as minted.
|
|
723
|
+
if (result.status === "approved") {
|
|
724
|
+
return {
|
|
725
|
+
success: true,
|
|
726
|
+
data: {
|
|
727
|
+
status: "approved",
|
|
728
|
+
token: result.token,
|
|
729
|
+
// Present only for a browser-held (expiring) row; epoch ms.
|
|
730
|
+
...(result.expiresAt !== undefined ? { expiresAt: result.expiresAt } : {}),
|
|
731
|
+
routes: httpsOrigins(pairing.reachableUrls()),
|
|
732
|
+
},
|
|
733
|
+
};
|
|
734
|
+
}
|
|
504
735
|
return { success: true, data: result };
|
|
505
736
|
},
|
|
506
737
|
);
|
|
@@ -520,24 +751,92 @@ export function registerPairingRoutes(
|
|
|
520
751
|
"/api/paired-devices/:id",
|
|
521
752
|
{ preHandler: operatorGuard },
|
|
522
753
|
async (request, reply): Promise<ApiResponse> => {
|
|
523
|
-
const removed = registry.revoke(request.params.id);
|
|
754
|
+
const removed = registry.revoke(request.params.id, auditRequestFields(request).actor);
|
|
524
755
|
if (!removed) {
|
|
525
756
|
reply.code(404);
|
|
526
757
|
return { success: false, error: "device not found" };
|
|
527
758
|
}
|
|
759
|
+
// Audit: id prefix + actor + socket peer only — never a bearer or hash (D2).
|
|
760
|
+
auditLine("pairing", "revoked", { id: auditPrefix(request.params.id), ...auditRequestFields(request) });
|
|
528
761
|
return { success: true };
|
|
529
762
|
},
|
|
530
763
|
);
|
|
531
764
|
|
|
765
|
+
// ── Held (revoked) devices: operator-only list / restore / delete-now (D6) ─
|
|
766
|
+
// Static `revoked` segments win over `:id` in Fastify's router. A device bearer is refused 401 by
|
|
767
|
+
// `operatorGuard`. Audit lines only after a successful change (never on 404 / 409).
|
|
768
|
+
fastify.get(
|
|
769
|
+
"/api/paired-devices/revoked",
|
|
770
|
+
{ preHandler: operatorGuard },
|
|
771
|
+
async (): Promise<ApiResponse<ReturnType<PairedDeviceRegistry["listRevoked"]>["devices"]> & { warning?: "unreadable" }> => {
|
|
772
|
+
const { devices, warning } = registry.listRevoked();
|
|
773
|
+
return { success: true, data: devices, ...(warning ? { warning } : {}) };
|
|
774
|
+
},
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
fastify.post<{ Params: { id: string } }>(
|
|
778
|
+
"/api/paired-devices/:id/restore",
|
|
779
|
+
{ preHandler: operatorGuard },
|
|
780
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
781
|
+
const result = registry.restore(request.params.id);
|
|
782
|
+
if (result === "not-found") {
|
|
783
|
+
reply.code(404);
|
|
784
|
+
return { success: false, error: "device not found" };
|
|
785
|
+
}
|
|
786
|
+
if (result === "active") {
|
|
787
|
+
reply.code(409);
|
|
788
|
+
return { success: false, error: "device_active" };
|
|
789
|
+
}
|
|
790
|
+
auditDeviceEvent("restored", request.params.id, request);
|
|
791
|
+
return { success: true };
|
|
792
|
+
},
|
|
793
|
+
);
|
|
794
|
+
|
|
795
|
+
fastify.delete<{ Params: { id: string } }>(
|
|
796
|
+
"/api/paired-devices/revoked/:id",
|
|
797
|
+
{ preHandler: operatorGuard },
|
|
798
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
799
|
+
const result = registry.deleteRevoked(request.params.id);
|
|
800
|
+
if (result === "not-found") {
|
|
801
|
+
reply.code(404);
|
|
802
|
+
return { success: false, error: "device not found" };
|
|
803
|
+
}
|
|
804
|
+
if (result === "active") {
|
|
805
|
+
reply.code(409);
|
|
806
|
+
return { success: false, error: "device_active" };
|
|
807
|
+
}
|
|
808
|
+
auditDeviceEvent("deleted", request.params.id, request);
|
|
809
|
+
return { success: true };
|
|
810
|
+
},
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
// Remove ONE companion key of an active device (the operator's "Remove"). Keyed by the short key id.
|
|
814
|
+
fastify.delete<{ Params: { id: string; companionId: string } }>(
|
|
815
|
+
"/api/paired-devices/:id/companions/:companionId",
|
|
816
|
+
{ preHandler: operatorGuard },
|
|
817
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
818
|
+
if (!registry.removeCompanion(request.params.id, request.params.companionId)) {
|
|
819
|
+
reply.code(404);
|
|
820
|
+
return { success: false, error: "companion not found" };
|
|
821
|
+
}
|
|
822
|
+
auditKeyEvent("companion_removed", request.params.id, request.params.companionId, request);
|
|
823
|
+
return { success: true };
|
|
824
|
+
},
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
// ── Browser device: rotate its own bearer (bearer-only credential) ────
|
|
828
|
+
registerBearerRotateRoute(fastify, { registry });
|
|
829
|
+
|
|
532
830
|
// ── Dashboard: mint a device token for an MCP client (operator-only) ──
|
|
533
831
|
// Deliberately NOT in PUBLIC_PAIRING_PREFIXES: this route issues durable
|
|
534
832
|
// credentials and requires an operator credential, not a pairing code (D5).
|
|
535
|
-
fastify.post<{ Body: { label?: unknown; tier?: unknown } }>(
|
|
833
|
+
fastify.post<{ Body: { label?: unknown; tier?: unknown; purpose?: unknown } }>(
|
|
536
834
|
"/api/paired-devices",
|
|
537
835
|
{ preHandler: operatorGuard },
|
|
538
|
-
async (request, reply): Promise<ApiResponse<{ device: PairedDeviceView; token: string }
|
|
836
|
+
async (request, reply): Promise<ApiResponse<{ device: PairedDeviceView; token: string }> & { httpsUrl?: string }> => {
|
|
539
837
|
const label = request.body?.label;
|
|
540
838
|
const tier = request.body?.tier;
|
|
839
|
+
const purpose = request.body?.purpose;
|
|
541
840
|
if (typeof label !== "string") {
|
|
542
841
|
reply.code(400);
|
|
543
842
|
return { success: false, error: "label must be a string" };
|
|
@@ -556,10 +855,36 @@ export function registerPairingRoutes(
|
|
|
556
855
|
error: `label must be 1..${MAX_DEVICE_LABEL_BYTES} UTF-8 bytes`,
|
|
557
856
|
};
|
|
558
857
|
}
|
|
858
|
+
// `purpose` is absent or "bridge" (D9); `bridge` forces tier `operate`, which bridge-ticket
|
|
859
|
+
// minting needs. Both are validated BEFORE the registry is touched, so a refusal leaves no row.
|
|
860
|
+
if (purpose !== undefined && purpose !== "bridge") {
|
|
861
|
+
reply.code(400);
|
|
862
|
+
return { success: false, error: 'purpose must be "bridge" when present' };
|
|
863
|
+
}
|
|
864
|
+
if (purpose === "bridge" && tier !== undefined && tier !== "operate") {
|
|
865
|
+
reply.code(400);
|
|
866
|
+
return { success: false, error: "a bridge token is always tier operate" };
|
|
867
|
+
}
|
|
868
|
+
const channel = bearerChannelOf(request.raw);
|
|
869
|
+
if (purpose === "bridge" && !isProvenChannel(channel)) {
|
|
870
|
+
// A bridge token is never handed out plain-and-exposed by accident.
|
|
871
|
+
const httpsUrl = deps.getTlsListenerUrls?.()[0];
|
|
872
|
+
reply.code(403);
|
|
873
|
+
return { success: false, error: BRIDGE_TOKEN_REQUIRES_HTTPS, ...(httpsUrl ? { httpsUrl } : {}) };
|
|
874
|
+
}
|
|
559
875
|
// The plaintext token rides this ONE response and is never retrievable
|
|
560
876
|
// again (D4) — same plaintext-once semantics as the pairing ceremony.
|
|
561
|
-
// No tier → the manual source default (`observe`, D1).
|
|
562
|
-
|
|
877
|
+
// No tier → the manual source default (`observe`, D1). The delivering channel decides exposure.
|
|
878
|
+
const minted = registry.add(trimmed, "manual", isTier(tier) ? tier : undefined, undefined, {
|
|
879
|
+
channel,
|
|
880
|
+
...(purpose === "bridge" ? { purpose: "bridge" as const } : {}),
|
|
881
|
+
});
|
|
882
|
+
auditLine("pairing", "minted", {
|
|
883
|
+
id: auditPrefix(minted.device.id),
|
|
884
|
+
tier: minted.device.tier,
|
|
885
|
+
...auditRequestFields(request),
|
|
886
|
+
});
|
|
887
|
+
return { success: true, data: minted };
|
|
563
888
|
},
|
|
564
889
|
);
|
|
565
890
|
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
readPiSettings,
|
|
51
51
|
writePiSettingsRaw,
|
|
52
52
|
} from "../pi-agent-settings.js";
|
|
53
|
+
import { notePiMirrorWrite } from "../pi-default-remirror.js";
|
|
53
54
|
import { createThemeLister, type ScanThemes } from "../pi-settings-themes.js";
|
|
54
55
|
import type { NetworkGuard } from "./route-deps.js";
|
|
55
56
|
|
|
@@ -223,6 +224,7 @@ export function registerPiSettingsRoutes(
|
|
|
223
224
|
return { success: false, error: mirror.error ?? "io" };
|
|
224
225
|
}
|
|
225
226
|
logWrite("sync-defaults", "ok");
|
|
227
|
+
notePiMirrorWrite(); // See change: default-model-follows-role (D4).
|
|
226
228
|
const s = readPiSettings(fsDeps);
|
|
227
229
|
return {
|
|
228
230
|
success: true,
|