@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
|
@@ -3,20 +3,36 @@
|
|
|
3
3
|
* binding handed to `createServerPluginContext`. The mount itself (validation,
|
|
4
4
|
* registry, request handling) lives in the runtime package (`mountApp`).
|
|
5
5
|
*
|
|
6
|
-
* A plugin is TRUSTED when its
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* A plugin is TRUSTED when it is BUNDLED, or its manifest id is in config `auth.trustedPlugins` (the
|
|
7
|
+
* single operator trust list, any entry for the id) or in the legacy `auth.capabilityRoutePlugins`
|
|
8
|
+
* (read, never written by the dashboard). BUNDLED = discovery `source` ∈ {workspace, bundled, installed},
|
|
9
|
+
* `realpath(packageDir)` a direct child of `realpath(<repo>/packages)`, `realpath(resources/plugins)`
|
|
10
|
+
* or `realpath(~/.pi/dashboard/plugins)`, and its (real) DIRECTORY name in
|
|
11
|
+
* `packages/server/package.json#piDashboard.bundledPlugins`. A `pi-package` / `local-detected`
|
|
12
|
+
* copy never counts, so a spoofed basename under `~/.pi/agent/npm/node_modules` is refused
|
|
13
|
+
* (design D12, R17). `manifest.priority` is a render-order
|
|
9
14
|
* knob and never trust. An untrusted call mounts nothing and warns once, so an
|
|
10
15
|
* untrusted plugin cannot squat a trusted app's id.
|
|
11
16
|
*
|
|
12
17
|
* API guardrail against accidents, not a boundary against a malicious in-process plugin.
|
|
13
18
|
*
|
|
14
|
-
* See change: add-plugin-capability-routes (D2, D5).
|
|
19
|
+
* See change: add-plugin-capability-routes (D2, D5); decouple-plugins-from-core (task 6.6, D12).
|
|
15
20
|
*/
|
|
21
|
+
import fs from "node:fs";
|
|
16
22
|
import { createRequire } from "node:module";
|
|
17
23
|
import path from "node:path";
|
|
18
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
findBundledPluginsDir,
|
|
26
|
+
findInstalledPluginsDir,
|
|
27
|
+
findMonorepoRoot,
|
|
28
|
+
getPluginStatusStore,
|
|
29
|
+
mountApp,
|
|
30
|
+
type ServeAppOptions,
|
|
31
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
32
|
+
import { loadConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
33
|
+
import type { PluginDiscoverySource } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/plugin-status.js";
|
|
19
34
|
import type { FastifyInstance } from "fastify";
|
|
35
|
+
import { readTrustedPlugins } from "./plugin-trust-store.js";
|
|
20
36
|
|
|
21
37
|
const nodeRequire = createRequire(import.meta.url);
|
|
22
38
|
|
|
@@ -38,43 +54,96 @@ export function readBundledPluginDirs(): ReadonlySet<string> {
|
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
export interface ServeAppTrustInput {
|
|
41
|
-
/** Absolute path of the plugin package directory (its basename is the bundled-list key). */
|
|
57
|
+
/** Absolute path of the plugin package directory (its real basename is the bundled-list key). */
|
|
42
58
|
packageDir: string;
|
|
43
59
|
/** Manifest id (the `auth.capabilityRoutePlugins` key). */
|
|
44
60
|
manifestId: string;
|
|
61
|
+
/** Discovery source of the winning copy. Absent → never bundled (fail closed). */
|
|
62
|
+
source?: PluginDiscoverySource;
|
|
45
63
|
}
|
|
46
64
|
|
|
47
|
-
|
|
65
|
+
const BUNDLED_SOURCES: ReadonlySet<PluginDiscoverySource> = new Set(["workspace", "bundled", "installed"]);
|
|
66
|
+
|
|
67
|
+
function realpathOrNull(p: string): string | null {
|
|
68
|
+
try {
|
|
69
|
+
return fs.realpathSync(p);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Real roots a bundled plugin may live directly under: `<repo>/packages`, `resources/plugins`, `~/.pi/dashboard/plugins`. */
|
|
76
|
+
function readBundledPluginRoots(): string[] {
|
|
77
|
+
const monorepo = findMonorepoRoot();
|
|
78
|
+
const candidates = [monorepo ? path.join(monorepo, "packages") : null, findBundledPluginsDir(), findInstalledPluginsDir()];
|
|
79
|
+
return candidates.flatMap((c) => {
|
|
80
|
+
const real = c ? realpathOrNull(c) : null;
|
|
81
|
+
return real ? [real] : [];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Pure trust decision: bundled (path-contained), OR listed in `auth.trustedPlugins` (`trustedIds`),
|
|
87
|
+
* OR named in the legacy `auth.capabilityRoutePlugins` (`configuredIds`).
|
|
88
|
+
*/
|
|
48
89
|
export function isServeAppTrusted(
|
|
49
90
|
plugin: ServeAppTrustInput,
|
|
50
|
-
lists: {
|
|
91
|
+
lists: {
|
|
92
|
+
bundledDirs: ReadonlySet<string>;
|
|
93
|
+
configuredIds: readonly string[];
|
|
94
|
+
/** Ids with an `auth.trustedPlugins` entry (any entry: the list is the one operator trust list). */
|
|
95
|
+
trustedIds?: readonly string[];
|
|
96
|
+
bundledRoots?: readonly string[];
|
|
97
|
+
},
|
|
51
98
|
): boolean {
|
|
52
|
-
|
|
99
|
+
if (lists.configuredIds.includes(plugin.manifestId)) return true;
|
|
100
|
+
if (lists.trustedIds?.includes(plugin.manifestId)) return true;
|
|
101
|
+
if (!plugin.source || !BUNDLED_SOURCES.has(plugin.source)) return false;
|
|
102
|
+
const real = realpathOrNull(plugin.packageDir);
|
|
103
|
+
if (!real || !lists.bundledDirs.has(path.basename(real))) return false;
|
|
104
|
+
const roots = lists.bundledRoots ?? readBundledPluginRoots();
|
|
105
|
+
const parent = path.dirname(real);
|
|
106
|
+
return roots.some((root) => parent === root);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Live ids of `auth.trustedPlugins`. */
|
|
110
|
+
function readTrustedIds(): readonly string[] {
|
|
111
|
+
return readTrustedPlugins().map((e) => e.id);
|
|
53
112
|
}
|
|
54
113
|
|
|
55
114
|
export interface HostServeAppDeps {
|
|
56
115
|
fastify: FastifyInstance;
|
|
57
116
|
plugin: ServeAppTrustInput;
|
|
58
|
-
/** Live read of `auth.capabilityRoutePlugins` (read when the plugin activates). */
|
|
117
|
+
/** Live read of the legacy `auth.capabilityRoutePlugins` (read when the plugin activates). */
|
|
59
118
|
readConfiguredIds: () => readonly string[];
|
|
119
|
+
/** Live read of `auth.trustedPlugins` ids; defaults to the config. */
|
|
120
|
+
readTrustedIds?: () => readonly string[];
|
|
121
|
+
/** Records the mount outcome; defaults to `PluginStatus.serveApp` in the status store. */
|
|
122
|
+
recordOutcome?: (pluginId: string, state: "mounted" | "refused") => void;
|
|
60
123
|
/** Overridable for tests; defaults to the server package's bundled list. */
|
|
61
124
|
bundledDirs?: ReadonlySet<string>;
|
|
125
|
+
/** Overridable for tests; real roots a bundled plugin must sit directly under. */
|
|
126
|
+
bundledRoots?: readonly string[];
|
|
62
127
|
}
|
|
63
128
|
|
|
64
129
|
/** The `deps.serveApp` binding for one plugin: trust-gate, then mount. */
|
|
65
130
|
export function createHostServeApp(deps: HostServeAppDeps): (opts: ServeAppOptions, env: { dataDir: string }) => void {
|
|
66
131
|
const { plugin } = deps;
|
|
132
|
+
const record = deps.recordOutcome ?? ((id, state) => getPluginStatusStore().recordServeApp(id, state));
|
|
67
133
|
let warned = false;
|
|
68
134
|
return (opts, env) => {
|
|
69
135
|
const trusted = isServeAppTrusted(plugin, {
|
|
70
136
|
bundledDirs: deps.bundledDirs ?? readBundledPluginDirs(),
|
|
71
137
|
configuredIds: deps.readConfiguredIds(),
|
|
138
|
+
trustedIds: (deps.readTrustedIds ?? readTrustedIds)(),
|
|
139
|
+
bundledRoots: deps.bundledRoots,
|
|
72
140
|
});
|
|
73
141
|
if (!trusted) {
|
|
142
|
+
record(plugin.manifestId, "refused");
|
|
74
143
|
if (!warned) {
|
|
75
144
|
warned = true;
|
|
76
145
|
console.warn(
|
|
77
|
-
`[serveApp] plugin '${plugin.manifestId}' is not trusted to mount an app (bundled plugin or auth.capabilityRoutePlugins); ignoring`,
|
|
146
|
+
`[serveApp] plugin '${plugin.manifestId}' is not trusted to mount an app (bundled plugin, auth.trustedPlugins or auth.capabilityRoutePlugins); ignoring`,
|
|
78
147
|
);
|
|
79
148
|
}
|
|
80
149
|
return;
|
|
@@ -93,5 +162,36 @@ export function createHostServeApp(deps: HostServeAppDeps): (opts: ServeAppOptio
|
|
|
93
162
|
},
|
|
94
163
|
opts,
|
|
95
164
|
);
|
|
165
|
+
record(plugin.manifestId, "mounted");
|
|
96
166
|
};
|
|
97
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether a trust change flips a plugin's `serveApp` outcome: the mount is decided at activation, so a
|
|
171
|
+
* refused app that is trusted now (grant), or a mounted one that is no longer trusted (revoke), needs a
|
|
172
|
+
* restart. Pure.
|
|
173
|
+
*/
|
|
174
|
+
export function serveAppRestartNeeded(recorded: "mounted" | "refused" | undefined, trustedNow: boolean): boolean {
|
|
175
|
+
return (recorded === "refused" && trustedNow) || (recorded === "mounted" && !trustedNow);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* After a trust grant/revoke: compare the plugin's CURRENT `serveApp` trust with the outcome recorded at
|
|
180
|
+
* activation and set `restartRequired` on its status row when they differ (spec "Trust freshness differs
|
|
181
|
+
* per surface"). Returns whether the row was flagged; the caller broadcasts `plugins_changed`. A plugin
|
|
182
|
+
* that never called `serveApp` (no recorded outcome) is untouched.
|
|
183
|
+
*/
|
|
184
|
+
export function noteServeAppTrustChange(plugin: ServeAppTrustInput): boolean {
|
|
185
|
+
const store = getPluginStatusStore();
|
|
186
|
+
const stored = store.getStoredStatus(plugin.manifestId);
|
|
187
|
+
const recorded = store.getStatus(plugin.manifestId)?.serveApp;
|
|
188
|
+
if (!stored || stored.restartRequired) return false;
|
|
189
|
+
const trustedNow = isServeAppTrusted(plugin, {
|
|
190
|
+
bundledDirs: readBundledPluginDirs(),
|
|
191
|
+
configuredIds: loadConfig().auth?.capabilityRoutePlugins ?? [],
|
|
192
|
+
trustedIds: readTrustedIds(),
|
|
193
|
+
});
|
|
194
|
+
if (!serveAppRestartNeeded(recorded, trustedNow)) return false;
|
|
195
|
+
store.setStatus({ ...stored, restartRequired: true });
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background check of a Google Vertex AI API key after a save: one countTokens
|
|
3
|
+
* request (generates nothing) under the effective `baseUrl` (empty = the global
|
|
4
|
+
* endpoint; a non-Vertex host is never contacted → `not_checked`), 10 s timeout, no
|
|
5
|
+
* redirects. 401/403/404/timeout/network error → failed; anything else → ok (Google
|
|
6
|
+
* accepted the key). Never blocks the save, never undoes it.
|
|
7
|
+
*
|
|
8
|
+
* Results live in memory only (lost on restart), keyed by auth.json key with a
|
|
9
|
+
* write sequence number: a later save or a removal drops the entry, and an
|
|
10
|
+
* older result never overwrites a newer one. The key is sent in the query only
|
|
11
|
+
* and never logged or stored in the result.
|
|
12
|
+
* See change: add-provider-env-config (D8).
|
|
13
|
+
*/
|
|
14
|
+
import type { ProviderKeyCheck } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
15
|
+
|
|
16
|
+
const KEY_CHECK_TIMEOUT_MS = 10_000;
|
|
17
|
+
const VERTEX_HOST = "https://aiplatform.googleapis.com";
|
|
18
|
+
|
|
19
|
+
interface Entry {
|
|
20
|
+
seq: number;
|
|
21
|
+
result: ProviderKeyCheck;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const checks = new Map<string, Entry>();
|
|
25
|
+
let seqCounter = 0;
|
|
26
|
+
|
|
27
|
+
export interface KeyCheckDeps {
|
|
28
|
+
/** Effective provider `baseUrl` (models.json block). Empty/absent = the global host. */
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
fetch?: typeof fetch;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
/** Outcome log (provider, state, status) — never the key. */
|
|
33
|
+
log?: (line: { provider: string; state: ProviderKeyCheck["state"]; status?: number }) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Current results, keyed by auth.json key. */
|
|
37
|
+
export function keyCheckSnapshot(): Map<string, ProviderKeyCheck> {
|
|
38
|
+
return new Map([...checks].map(([id, e]) => [id, e.result]));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Drop the result for a provider (key changed without a check, or credential removed). */
|
|
42
|
+
export function clearKeyCheck(provider: string): void {
|
|
43
|
+
seqCounter++;
|
|
44
|
+
checks.delete(provider);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Test seam. */
|
|
48
|
+
export function _resetKeyChecksForTests(): void {
|
|
49
|
+
checks.clear();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** True for `aiplatform.googleapis.com` and `<region>-aiplatform.googleapis.com` over https. */
|
|
53
|
+
function isVertexBaseUrl(baseUrl: string): boolean {
|
|
54
|
+
try {
|
|
55
|
+
const u = new URL(baseUrl);
|
|
56
|
+
return u.protocol === "https:" && /^([a-z0-9]+(-[a-z0-9]+)*-)?aiplatform\.googleapis\.com$/.test(u.hostname.toLowerCase()) && !u.username && !u.password;
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function googleMessage(body: string): string | undefined {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(body) as { error?: { message?: unknown } } | Array<{ error?: { message?: unknown } }>;
|
|
65
|
+
const err = Array.isArray(parsed) ? parsed[0]?.error : parsed?.error;
|
|
66
|
+
return typeof err?.message === "string" ? err.message.slice(0, 500) : undefined;
|
|
67
|
+
} catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Mark `provider` pending and start the check. Returns the check's promise
|
|
74
|
+
* (tests await it; the route does not).
|
|
75
|
+
*/
|
|
76
|
+
export function startVertexKeyCheck(provider: string, key: string, model: string, deps: KeyCheckDeps = {}): Promise<void> {
|
|
77
|
+
const seq = ++seqCounter;
|
|
78
|
+
checks.set(provider, { seq, result: { state: "pending" } });
|
|
79
|
+
const doFetch = deps.fetch ?? fetch;
|
|
80
|
+
const timeoutMs = deps.timeoutMs ?? KEY_CHECK_TIMEOUT_MS;
|
|
81
|
+
const settle = (result: ProviderKeyCheck) => {
|
|
82
|
+
const current = checks.get(provider);
|
|
83
|
+
if (!current || current.seq !== seq) return; // superseded or removed
|
|
84
|
+
checks.set(provider, { seq, result });
|
|
85
|
+
deps.log?.({ provider, state: result.state, ...(result.status !== undefined ? { status: result.status } : {}) });
|
|
86
|
+
};
|
|
87
|
+
const baseUrl = deps.baseUrl?.trim() ? deps.baseUrl.trim().replace(/\/+$/, "") : "";
|
|
88
|
+
// The key goes only to a Vertex host: any other `baseUrl` is never contacted.
|
|
89
|
+
if (baseUrl && !isVertexBaseUrl(baseUrl)) {
|
|
90
|
+
settle({ state: "not_checked" });
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
}
|
|
93
|
+
const url = `${baseUrl || `${VERTEX_HOST}/v1`}/publishers/google/models/${encodeURIComponent(model)}:countTokens?key=${encodeURIComponent(key)}`;
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
let timedOut = false;
|
|
96
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
97
|
+
// Raced, not only aborted: a fetch that ignores its signal still settles.
|
|
98
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
99
|
+
timer = setTimeout(() => {
|
|
100
|
+
timedOut = true;
|
|
101
|
+
controller.abort();
|
|
102
|
+
reject(new Error("timeout"));
|
|
103
|
+
}, timeoutMs);
|
|
104
|
+
timer.unref?.();
|
|
105
|
+
});
|
|
106
|
+
return (async () => {
|
|
107
|
+
try {
|
|
108
|
+
const res = await Promise.race([
|
|
109
|
+
doFetch(url, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
redirect: "manual",
|
|
112
|
+
signal: controller.signal,
|
|
113
|
+
headers: { "content-type": "application/json" },
|
|
114
|
+
body: JSON.stringify({ contents: [{ role: "user", parts: [{ text: "ping" }] }] }),
|
|
115
|
+
}),
|
|
116
|
+
timeout,
|
|
117
|
+
]);
|
|
118
|
+
if (res.status === 401 || res.status === 403) {
|
|
119
|
+
const text = await res.text().catch(() => "");
|
|
120
|
+
settle({ state: "failed", status: res.status, message: googleMessage(text) ?? `HTTP ${res.status}` });
|
|
121
|
+
} else if (res.status === 404) {
|
|
122
|
+
// The original 404 (project-less route) used to pass: surface Google's message.
|
|
123
|
+
const text = await res.text().catch(() => "");
|
|
124
|
+
const google = googleMessage(text);
|
|
125
|
+
settle({ state: "failed", status: 404, message: `Model or region not available${google ? `: ${google}` : ""}` });
|
|
126
|
+
} else {
|
|
127
|
+
await res.body?.cancel().catch(() => {});
|
|
128
|
+
settle({ state: "ok" });
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
settle(
|
|
132
|
+
timedOut
|
|
133
|
+
? { state: "failed", message: `Google did not answer within ${Math.round(timeoutMs / 1000)} s` }
|
|
134
|
+
: { state: "failed", message: "Could not reach Google" },
|
|
135
|
+
);
|
|
136
|
+
} finally {
|
|
137
|
+
if (timer) clearTimeout(timer);
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import crypto from "node:crypto";
|
|
20
20
|
import type { Principal } from "@blackbelt-technology/pi-dashboard-shared/identity.js";
|
|
21
|
+
import { isProvenTls } from "./proven-tls.js";
|
|
21
22
|
|
|
22
23
|
/** Core WS route scopes — the only scopes a ticket may ever be bound to. */
|
|
23
24
|
const CORE_WS_ROUTE_SCOPES = ["browser", "terminal", "live", "bridge"] as const;
|
|
@@ -74,11 +75,28 @@ interface TicketEntry {
|
|
|
74
75
|
*/
|
|
75
76
|
principalExpiresAt?: number;
|
|
76
77
|
expiresAt: number;
|
|
78
|
+
/** The minting request was on the hub's own TLS socket with no forwarding header (`bridge` scope). */
|
|
79
|
+
provenTls?: boolean;
|
|
80
|
+
/** How a `bridge` ticket was minted: with a device bearer, or by a genuinely-local bearer-less caller. */
|
|
81
|
+
mintedBy?: "device" | "local";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Facts the minting request proves, recorded on the ticket. See change: prove-vault-bridge-tls (D3). */
|
|
85
|
+
export interface TicketMintMeta {
|
|
86
|
+
provenTls: boolean;
|
|
87
|
+
mintedBy: "device" | "local";
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
/** Outcome of a single-use consumption attempt, with the cause named. */
|
|
80
91
|
export type TicketConsumption =
|
|
81
|
-
| {
|
|
92
|
+
| {
|
|
93
|
+
ok: true;
|
|
94
|
+
deviceId?: string;
|
|
95
|
+
principal?: Principal;
|
|
96
|
+
principalExpiresAt?: number;
|
|
97
|
+
provenTls?: boolean;
|
|
98
|
+
mintedBy?: "device" | "local";
|
|
99
|
+
}
|
|
82
100
|
| { ok: false; reason: "missing" | "unknown" | "expired" | "wrong-scope" };
|
|
83
101
|
|
|
84
102
|
/**
|
|
@@ -104,7 +122,7 @@ export function routeScopeForUrl(url: string | undefined): WsRouteScope | null {
|
|
|
104
122
|
const pathOnly = url.split("?")[0];
|
|
105
123
|
if (pathOnly === "/ws") return "browser";
|
|
106
124
|
if (pathOnly.startsWith("/ws/terminal/")) return "terminal";
|
|
107
|
-
if (pathOnly.startsWith("/live/")) return "live";
|
|
125
|
+
if (pathOnly.startsWith("/live/") || pathOnly.startsWith("/preview/")) return "live";
|
|
108
126
|
if (pathOnly === "/ws/bridge") return "bridge";
|
|
109
127
|
// Plugin-registered scopes resolve LAST, so the core prefixes above always
|
|
110
128
|
// win (plugin prefixes are validated to never overlap them).
|
|
@@ -158,6 +176,7 @@ export class WsTicketStore {
|
|
|
158
176
|
scope: CoreWsRouteScope,
|
|
159
177
|
deviceId?: string,
|
|
160
178
|
identity?: { principal: Principal; principalExpiresAt?: number },
|
|
179
|
+
meta?: TicketMintMeta,
|
|
161
180
|
): string {
|
|
162
181
|
// Lazy sweep on each mint clears abandoned (minted-but-unconsumed) tickets
|
|
163
182
|
// so the map can't grow unbounded without a background timer.
|
|
@@ -169,6 +188,7 @@ export class WsTicketStore {
|
|
|
169
188
|
principal: identity?.principal,
|
|
170
189
|
principalExpiresAt: identity?.principalExpiresAt,
|
|
171
190
|
expiresAt: this.now() + TICKET_TTL_MS,
|
|
191
|
+
...(meta ? { provenTls: meta.provenTls, mintedBy: meta.mintedBy } : {}),
|
|
172
192
|
});
|
|
173
193
|
return ticket;
|
|
174
194
|
}
|
|
@@ -204,6 +224,8 @@ export class WsTicketStore {
|
|
|
204
224
|
deviceId: entry.deviceId,
|
|
205
225
|
principal: entry.principal,
|
|
206
226
|
principalExpiresAt: entry.principalExpiresAt,
|
|
227
|
+
provenTls: entry.provenTls,
|
|
228
|
+
mintedBy: entry.mintedBy,
|
|
207
229
|
};
|
|
208
230
|
}
|
|
209
231
|
|
|
@@ -215,3 +237,19 @@ export class WsTicketStore {
|
|
|
215
237
|
}
|
|
216
238
|
}
|
|
217
239
|
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Mint a `bridge` ticket recording what the MINTING request proves: whether it arrived on the hub's own
|
|
243
|
+
* TLS socket with no forwarding header, and whether a device bearer or a genuinely-local caller minted it.
|
|
244
|
+
* See change: prove-vault-bridge-tls (D3).
|
|
245
|
+
*/
|
|
246
|
+
export function mintBridgeTicket(
|
|
247
|
+
store: WsTicketStore,
|
|
248
|
+
deviceId: string | undefined,
|
|
249
|
+
req: Parameters<typeof isProvenTls>[0],
|
|
250
|
+
): string {
|
|
251
|
+
return store.mint("bridge", deviceId, undefined, {
|
|
252
|
+
provenTls: isProvenTls(req),
|
|
253
|
+
mintedBy: deviceId ? "device" : "local",
|
|
254
|
+
});
|
|
255
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* other gate logs (bridge-scope 400, auth 401, no-auth 403).
|
|
4
4
|
*
|
|
5
5
|
* Line: `[ws-upgrade] rejected status=<n> scope=<s> peer=<addr>
|
|
6
|
-
* fwd=<comma-names|none> ticket=<present|absent>[ suppressed=<n>]`.
|
|
6
|
+
* fwd=<comma-names|none> ticket=<present|absent>[ reason=<token>][ suppressed=<n>]`.
|
|
7
7
|
* Header VALUES, cookies and ticket strings are never read into the line.
|
|
8
8
|
*
|
|
9
9
|
* At most one line per `status|scope|peer` key per window; the first line
|
|
@@ -21,6 +21,8 @@ export interface WsUpgradeRejection {
|
|
|
21
21
|
remoteAddress: string | undefined;
|
|
22
22
|
headers: Record<string, unknown> | undefined;
|
|
23
23
|
ticketPresent: boolean;
|
|
24
|
+
/** Machine reason when the rejection has one (e.g. `local_proof_required`); a fixed token, never caller input. */
|
|
25
|
+
reason?: string;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface WsUpgradeRejectLoggerOptions {
|
|
@@ -73,6 +75,7 @@ export function createWsUpgradeRejectLogger(opts: WsUpgradeRejectLoggerOptions =
|
|
|
73
75
|
emit(
|
|
74
76
|
`[ws-upgrade] rejected status=${r.status} scope=${r.scope} peer=${peer}` +
|
|
75
77
|
` fwd=${fwd.length > 0 ? fwd.join(",") : "none"} ticket=${r.ticketPresent ? "present" : "absent"}` +
|
|
78
|
+
(r.reason ? ` reason=${r.reason}` : "") +
|
|
76
79
|
(suppressed > 0 ? ` suppressed=${suppressed}` : ""),
|
|
77
80
|
);
|
|
78
81
|
},
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import fs from "node:fs/promises";
|
|
16
16
|
import os from "node:os";
|
|
17
17
|
import path from "node:path";
|
|
18
|
+
import { forbiddenGrantSubjects, isForbiddenGrantSubject } from "@blackbelt-technology/pi-dashboard-shared/forbidden-subjects.js";
|
|
18
19
|
import { isFilesystemRoot } from "@blackbelt-technology/pi-dashboard-shared/platform/paths.js";
|
|
19
20
|
import { isPortableProjectName, projectNameProblem } from "@blackbelt-technology/pi-dashboard-shared/project-name.js";
|
|
20
21
|
import type { BrowseEntry, BrowseFlagEntry, BrowseResult, CreateProjectErrorReason } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
@@ -64,6 +65,25 @@ function rankTier(name: string, qLower: string): number {
|
|
|
64
65
|
return 3;
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
export interface ListDirectoriesOptions {
|
|
69
|
+
detect?: boolean;
|
|
70
|
+
/** List files after directories (stat-based; symlinks to files included). */
|
|
71
|
+
files?: boolean;
|
|
72
|
+
/** Include dot entries. */
|
|
73
|
+
hidden?: boolean;
|
|
74
|
+
/** Extension filter (case-insensitive, leading dot optional, comma-separated). Needs `files`. */
|
|
75
|
+
ext?: string;
|
|
76
|
+
/** Drop entries inside forbidden-subjects locations (non-local callers); applies with `files` / `hidden`. */
|
|
77
|
+
excludeForbidden?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** `"json,.PEM"` -> `{".json", ".pem"}`; empty -> null (no filter). */
|
|
81
|
+
function parseExtFilter(raw: string | undefined): Set<string> | null {
|
|
82
|
+
const parts = (raw ?? "").split(",").map((x) => x.trim().toLowerCase()).filter(Boolean);
|
|
83
|
+
if (parts.length === 0) return null;
|
|
84
|
+
return new Set(parts.map((x) => (x.startsWith(".") ? x : `.${x}`)));
|
|
85
|
+
}
|
|
86
|
+
|
|
67
87
|
/**
|
|
68
88
|
* List subdirectories of a given path.
|
|
69
89
|
* Excludes hidden directories (starting with ".").
|
|
@@ -75,9 +95,11 @@ function rankTier(name: string, qLower: string): number {
|
|
|
75
95
|
export async function listDirectories(
|
|
76
96
|
dirPath?: string,
|
|
77
97
|
q?: string,
|
|
78
|
-
opts?:
|
|
98
|
+
opts?: ListDirectoriesOptions,
|
|
79
99
|
): Promise<BrowseResult> {
|
|
80
100
|
const detect = opts?.detect === true;
|
|
101
|
+
const withFiles = opts?.files === true;
|
|
102
|
+
const hidden = opts?.hidden === true;
|
|
81
103
|
const resolved = dirPath ?? os.homedir();
|
|
82
104
|
|
|
83
105
|
// Verify the directory exists and is a directory
|
|
@@ -87,36 +109,63 @@ export async function listDirectories(
|
|
|
87
109
|
}
|
|
88
110
|
|
|
89
111
|
const rawEntries = await fs.readdir(resolved, { withFileTypes: true });
|
|
112
|
+
const visible = (name: string) => hidden || !name.startsWith(".");
|
|
113
|
+
const qLower = (q ?? "").trim().toLowerCase();
|
|
90
114
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const qTrim = (q ?? "").trim();
|
|
98
|
-
if (qTrim) {
|
|
99
|
-
const qLower = qTrim.toLowerCase();
|
|
100
|
-
const ranked = dirs
|
|
115
|
+
// Optional substring filter + tiered ranking; alphabetical otherwise.
|
|
116
|
+
const rankGroup = <T extends { name: string }>(items: T[]): T[] => {
|
|
117
|
+
if (!qLower) {
|
|
118
|
+
return items.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
119
|
+
}
|
|
120
|
+
const ranked = items
|
|
101
121
|
.map((d) => ({ d, tier: rankTier(d.name, qLower) }))
|
|
102
122
|
.filter((x) => x.tier < 4);
|
|
103
123
|
ranked.sort((a, b) => {
|
|
104
124
|
if (a.tier !== b.tier) return a.tier - b.tier;
|
|
105
125
|
return a.d.name.toLowerCase().localeCompare(b.d.name.toLowerCase());
|
|
106
126
|
});
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
return ranked.map((x) => x.d);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
let dirs = rawEntries.filter((e) => e.isDirectory() && visible(e.name));
|
|
131
|
+
|
|
132
|
+
// Files (opt-in): stat-based so a symlink to a file counts.
|
|
133
|
+
let files: { name: string }[] = [];
|
|
134
|
+
if (withFiles) {
|
|
135
|
+
const exts = parseExtFilter(opts?.ext);
|
|
136
|
+
const candidates = rawEntries.filter(
|
|
137
|
+
(e) => !e.isDirectory() && visible(e.name) && (!exts || exts.has(path.extname(e.name).toLowerCase())),
|
|
138
|
+
);
|
|
139
|
+
const kept = await Promise.all(
|
|
140
|
+
candidates.map(async (e) => {
|
|
141
|
+
if (e.isFile()) return e;
|
|
142
|
+
if (!e.isSymbolicLink()) return null;
|
|
143
|
+
try {
|
|
144
|
+
return (await fs.stat(path.join(resolved, e.name))).isFile() ? e : null;
|
|
145
|
+
} catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
files = kept.filter((e): e is NonNullable<typeof e> => e !== null);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Non-local listings that widen the view never reveal credential locations.
|
|
154
|
+
if (opts?.excludeForbidden && (withFiles || hidden)) {
|
|
155
|
+
const sets = forbiddenGrantSubjects();
|
|
156
|
+
const allowed = (name: string) => !isForbiddenGrantSubject(path.join(resolved, name), undefined, sets);
|
|
157
|
+
dirs = dirs.filter((d) => allowed(d.name));
|
|
158
|
+
files = files.filter((f) => allowed(f.name));
|
|
111
159
|
}
|
|
112
160
|
|
|
113
|
-
// Cap at MAX_ENTRIES (AFTER filtering/ranking)
|
|
114
|
-
const capped = dirs.slice(0, MAX_ENTRIES);
|
|
161
|
+
// Cap each group at MAX_ENTRIES (AFTER filtering/ranking)
|
|
162
|
+
const capped = rankGroup(dirs).slice(0, MAX_ENTRIES);
|
|
163
|
+
const cappedFiles = rankGroup(files).slice(0, MAX_ENTRIES);
|
|
115
164
|
|
|
116
165
|
// Build entries. When `detect` is opt-in, probe `.git` / `.pi` for each
|
|
117
|
-
// surviving
|
|
118
|
-
// single-syscall fast path stays a single syscall.
|
|
119
|
-
const
|
|
166
|
+
// surviving directory (never a file); otherwise omit the flag fields entirely
|
|
167
|
+
// so the single-syscall fast path stays a single syscall.
|
|
168
|
+
const dirEntries: BrowseEntry[] = detect
|
|
120
169
|
? await Promise.all(
|
|
121
170
|
capped.map(async (d) => {
|
|
122
171
|
const fullPath = path.join(resolved, d.name);
|
|
@@ -125,6 +174,10 @@ export async function listDirectories(
|
|
|
125
174
|
}),
|
|
126
175
|
)
|
|
127
176
|
: capped.map((d) => ({ name: d.name, path: path.join(resolved, d.name) }));
|
|
177
|
+
const entries: BrowseEntry[] = [
|
|
178
|
+
...dirEntries,
|
|
179
|
+
...cappedFiles.map((f) => ({ name: f.name, path: path.join(resolved, f.name), isFile: true })),
|
|
180
|
+
];
|
|
128
181
|
|
|
129
182
|
// Parent: null for any filesystem root (`/`, `C:\`, `\\server\share\`).
|
|
130
183
|
// Previously this was `resolved === "/"`, which only recognized the Unix
|
|
@@ -18,8 +18,6 @@ export const UNSUPPORTED_FOR_ACP = "unsupported_for_acp";
|
|
|
18
18
|
const PI_ONLY_BROWSER_OPS: ReadonlySet<string> = new Set([
|
|
19
19
|
"retry_session",
|
|
20
20
|
"stop_after_turn",
|
|
21
|
-
"flow_control",
|
|
22
|
-
"flow_management",
|
|
23
21
|
"architect_prompt_response",
|
|
24
22
|
"role_set",
|
|
25
23
|
"role_preset_load",
|
|
@@ -31,7 +29,6 @@ const PI_ONLY_BROWSER_OPS: ReadonlySet<string> = new Set([
|
|
|
31
29
|
"open_inline_terminal",
|
|
32
30
|
"list_files",
|
|
33
31
|
"kill_process",
|
|
34
|
-
"subagent_resync_request",
|
|
35
32
|
]);
|
|
36
33
|
|
|
37
34
|
/**
|
|
@@ -39,7 +36,7 @@ const PI_ONLY_BROWSER_OPS: ReadonlySet<string> = new Set([
|
|
|
39
36
|
* silently — a chat error the user never caused would be noise. The
|
|
40
37
|
* request_roles refresh is sent through whichever session is live first.
|
|
41
38
|
*/
|
|
42
|
-
const SILENT_PI_ONLY_OPS: ReadonlySet<string> = new Set(["request_roles"
|
|
39
|
+
const SILENT_PI_ONLY_OPS: ReadonlySet<string> = new Set(["request_roles"]);
|
|
43
40
|
|
|
44
41
|
export const isAcp = (session: Pick<DashboardSession, "driver"> | undefined): boolean => session?.driver === "acp";
|
|
45
42
|
|