@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
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard secrets out of reach of the path-taking routes.
|
|
3
|
+
*
|
|
4
|
+
* `~/.pi/dashboard/` holds the local IPC token (`local/token`), the server
|
|
5
|
+
* identity key and `config.json` (which carries the auth HMAC secret). The file
|
|
6
|
+
* routes anchor on `[cwd, ~/.pi]`, and a session cwd of `$HOME` contains them
|
|
7
|
+
* too, so any running session used to let a bare-loopback caller read them.
|
|
8
|
+
*
|
|
9
|
+
* Two tiers, decided on REAL paths (symlinks resolved on both sides):
|
|
10
|
+
* - **always** — `<dir>/local/**` and `<dir>/identity.key`: refused for every
|
|
11
|
+
* caller in every mode. This tier is the recorded exception to
|
|
12
|
+
* rollback-by-flag (`requireLocalProof: false` does not reopen it).
|
|
13
|
+
* - **gated** — the rest of `<dir>`: refused unless the caller is locally
|
|
14
|
+
* trusted NOW (proof, or the strict default is off) or holds a login
|
|
15
|
+
* session. A caller that passes then falls through to the ordinary anchors.
|
|
16
|
+
*
|
|
17
|
+
* The caller is supplied per request through an `AsyncLocalStorage` set by one
|
|
18
|
+
* `onRequest` hook, so every containment decision made while serving that
|
|
19
|
+
* request sees it without each site threading a request through. With no caller
|
|
20
|
+
* in scope (internal, non-HTTP code) only the always-refused tier applies.
|
|
21
|
+
*
|
|
22
|
+
* `handleIsAlwaysRefused` closes the check-then-open race: after opening, the
|
|
23
|
+
* handle's (dev, ino) is compared with each always-refused file, so a symlink
|
|
24
|
+
* swapped in between the path check and the open is still caught. The
|
|
25
|
+
* trust-gated tier keeps only the pre-open check (its residual race is
|
|
26
|
+
* documented in the design).
|
|
27
|
+
*
|
|
28
|
+
* Deliberately NOT built on `access/verified-read.ts`: that is grant-only and
|
|
29
|
+
* `lstat`-based, and would regress in-scope symlink reads.
|
|
30
|
+
*
|
|
31
|
+
* **pi-agent credential files** (`AGENT_CREDENTIAL_NAMES`) are a second always-refused
|
|
32
|
+
* class: `<agentDir>/<name>` and any same-directory `<name>.*` sibling (quarantine /
|
|
33
|
+
* backup copies). The agent dirs are `resolvePiAgentDir()` (server env only) ∪
|
|
34
|
+
* `<home>/.pi/agent`, de-duplicated on real path and recomputed per call (so a HOME /
|
|
35
|
+
* `PI_CODING_AGENT_DIR` change is followed). Only the entry whose OWN basename matches
|
|
36
|
+
* is refused (`models.json.d/frag.json` is admitted); hard links and swapped symlinks
|
|
37
|
+
* are caught by the post-open (dev, ino) recheck. Case: exact compare on a
|
|
38
|
+
* case-sensitive volume, folded only where a cached per-dir probe says the volume folds
|
|
39
|
+
* (a failed probe counts as folding: over-refuse, never under-refuse).
|
|
40
|
+
* To protect a new pi credential file: add its name to `AGENT_CREDENTIAL_NAMES` (fixed
|
|
41
|
+
* list, no glob) and to `docs/security/residual-risks.md`.
|
|
42
|
+
*
|
|
43
|
+
* Residuals (accepted): a session's own `PI_CODING_AGENT_DIR` override is invisible to
|
|
44
|
+
* the server (only the server env is read); the JS grep walker reads a hard-linked
|
|
45
|
+
* credential file before the route's identity filter drops its matches; the
|
|
46
|
+
* `rendered-pdf` converter takes a path, so a swap after its last checked open is
|
|
47
|
+
* not caught (its output is a PDF rendering, never the bytes).
|
|
48
|
+
*
|
|
49
|
+
* See change: close-container-loopback-impersonation (D8), close-security-map-high-findings (D1).
|
|
50
|
+
*/
|
|
51
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
52
|
+
import { realpathSync } from "node:fs";
|
|
53
|
+
import fs from "node:fs/promises";
|
|
54
|
+
import os from "node:os";
|
|
55
|
+
import path from "node:path";
|
|
56
|
+
import {
|
|
57
|
+
PI_AGENT_ASK_READ_FILES,
|
|
58
|
+
PI_AGENT_SECRET_FILES,
|
|
59
|
+
} from "@blackbelt-technology/pi-dashboard-shared/agent-credential-files.js";
|
|
60
|
+
import { getDashboardConfigDir, resolvePiAgentDir } from "@blackbelt-technology/pi-dashboard-shared/dashboard-paths.js";
|
|
61
|
+
|
|
62
|
+
type DashboardStateTier = "always" | "gated";
|
|
63
|
+
|
|
64
|
+
/** What the guard needs to know about the caller of the current request. */
|
|
65
|
+
export interface StateCaller {
|
|
66
|
+
/** May the trust-gated tier be read? (locally trusted now, or a login session) */
|
|
67
|
+
gatedAdmitted(): boolean;
|
|
68
|
+
/** Is this a bare-loopback caller that only lacks local proof? (never raises an operator prompt) */
|
|
69
|
+
unproven(): boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const callers = new AsyncLocalStorage<StateCaller>();
|
|
73
|
+
|
|
74
|
+
/** Run `fn` with `caller` in scope for every containment decision it (transitively) makes. */
|
|
75
|
+
export function runWithStateCaller<T>(caller: StateCaller, fn: () => T): T {
|
|
76
|
+
return callers.run(caller, fn);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The caller of the request being served, if any. */
|
|
80
|
+
export function currentStateCaller(): StateCaller | undefined {
|
|
81
|
+
return callers.getStore();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Resolve symlinks; for a path that does not exist, resolve the nearest existing ancestor and re-append the tail. */
|
|
85
|
+
async function realpathLoose(p: string): Promise<string> {
|
|
86
|
+
try {
|
|
87
|
+
return await fs.realpath(p);
|
|
88
|
+
} catch {
|
|
89
|
+
const parent = path.dirname(p);
|
|
90
|
+
if (parent === p) return p;
|
|
91
|
+
return path.join(await realpathLoose(parent), path.basename(p));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Compared case-insensitively everywhere: macOS/Windows volumes are case-insensitive (`Local/Token` IS the token),
|
|
96
|
+
// and on a case-sensitive volume the only cost is refusing a differently-cased name inside the dashboard dir.
|
|
97
|
+
const norm = (s: string): string => s.toLowerCase();
|
|
98
|
+
|
|
99
|
+
let cachedFor = "";
|
|
100
|
+
let cachedReal = "";
|
|
101
|
+
async function realDashboardDir(): Promise<string> {
|
|
102
|
+
// Recomputed when HOME changes (tests reassign it; `os.homedir()` follows it).
|
|
103
|
+
const key = `${os.homedir()}`;
|
|
104
|
+
if (cachedFor !== key) {
|
|
105
|
+
cachedReal = await realpathLoose(getDashboardConfigDir());
|
|
106
|
+
cachedFor = key;
|
|
107
|
+
}
|
|
108
|
+
return cachedReal;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Fixed, auditable set of pi-agent credential files (relative to an agent dir; `/` separates
|
|
113
|
+
* path segments). No glob: `settings.json`, `trust.json` etc. stay readable. Built from the
|
|
114
|
+
* shared `agent-credential-files.ts` constants (agent-side credential guard + path gate use
|
|
115
|
+
* the same names); this server list adds `plugin-credentials.json` and always refuses
|
|
116
|
+
* `models.json`/`mcp.json`. See change: harden-agent-tool-guards (task 1.9).
|
|
117
|
+
*/
|
|
118
|
+
const AGENT_CREDENTIAL_NAMES: readonly string[] = [
|
|
119
|
+
...PI_AGENT_SECRET_FILES,
|
|
120
|
+
"plugin-credentials.json",
|
|
121
|
+
...PI_AGENT_ASK_READ_FILES,
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
/** Real, de-duplicated agent dirs (server env ∪ `<home>/.pi/agent`); recomputed per call, never cached. */
|
|
125
|
+
async function agentCredentialDirs(): Promise<string[]> {
|
|
126
|
+
const dirs = [resolvePiAgentDir(), path.join(os.homedir(), ".pi", "agent")];
|
|
127
|
+
const real = await Promise.all(dirs.map((d) => realpathLoose(path.resolve(d))));
|
|
128
|
+
return [...new Set(real)];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function agentCredentialDirsSync(): string[] {
|
|
132
|
+
const dirs = [resolvePiAgentDir(), path.join(os.homedir(), ".pi", "agent")];
|
|
133
|
+
return [...new Set(dirs.map((d) => realpathLooseSync(path.resolve(d))))];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function realpathLooseSync(p: string): string {
|
|
137
|
+
try {
|
|
138
|
+
return realpathSync(p);
|
|
139
|
+
} catch {
|
|
140
|
+
const parent = path.dirname(p);
|
|
141
|
+
if (parent === p) return p;
|
|
142
|
+
return path.join(realpathLooseSync(parent), path.basename(p));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const swapCase = (s: string): string =>
|
|
147
|
+
[...s].map((c) => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase())).join("");
|
|
148
|
+
|
|
149
|
+
/** One probe per directory per process: does its volume fold case? (failure ⇒ true: over-refuse.) */
|
|
150
|
+
const foldProbes = new Map<string, Promise<boolean>>();
|
|
151
|
+
function volumeFolds(dir: string): Promise<boolean> {
|
|
152
|
+
let probe = foldProbes.get(dir);
|
|
153
|
+
if (!probe) {
|
|
154
|
+
probe = (async () => {
|
|
155
|
+
const base = path.basename(dir);
|
|
156
|
+
const swapped = swapCase(base);
|
|
157
|
+
if (swapped === base) return true; // no letters to swap: cannot tell
|
|
158
|
+
const alt = path.join(path.dirname(dir), swapped);
|
|
159
|
+
try {
|
|
160
|
+
const a = await fs.stat(alt);
|
|
161
|
+
const o = await fs.stat(dir);
|
|
162
|
+
return a.dev === o.dev && a.ino === o.ino;
|
|
163
|
+
} catch (err) {
|
|
164
|
+
if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
|
|
165
|
+
try {
|
|
166
|
+
await fs.stat(dir);
|
|
167
|
+
return false; // the real dir exists, the swapped name does not: case-sensitive
|
|
168
|
+
} catch {
|
|
169
|
+
return true; // ENOENT on both: cannot tell
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
})();
|
|
175
|
+
foldProbes.set(dir, probe);
|
|
176
|
+
}
|
|
177
|
+
return probe;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Test seam: drop the cached volume probes. */
|
|
181
|
+
export function __resetCredentialVolumeProbes(): void {
|
|
182
|
+
foldProbes.clear();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Segments of a credential name joined onto an agent dir. */
|
|
186
|
+
const credFile = (dir: string, name: string): string => path.join(dir, ...name.split("/"));
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Does REAL `realTarget` name a credential file of agent dir `dir` (exact entry or a same-dir `<name>.*` sibling)?
|
|
190
|
+
* Exact compare first; the volume probe runs ONLY when a case-folded compare matches but the exact one does
|
|
191
|
+
* not (so an unrelated path costs no probe), and then decides whether the fold counts.
|
|
192
|
+
*/
|
|
193
|
+
async function isCredentialIn(dir: string, realTarget: string): Promise<boolean> {
|
|
194
|
+
const matches = (fold: boolean, t: string, c: string): boolean => (fold ? norm(t) === norm(c) : t === c);
|
|
195
|
+
const nameMatch = (fold: boolean, cred: string): boolean => {
|
|
196
|
+
const base = path.basename(cred);
|
|
197
|
+
const tb = path.basename(realTarget);
|
|
198
|
+
if (!matches(fold, path.dirname(realTarget), path.dirname(cred))) return false;
|
|
199
|
+
return matches(fold, tb, base) || (tb.length > base.length && matches(fold, tb.slice(0, base.length + 1), `${base}.`));
|
|
200
|
+
};
|
|
201
|
+
let foldOnly = false;
|
|
202
|
+
for (const name of AGENT_CREDENTIAL_NAMES) {
|
|
203
|
+
const cred = credFile(dir, name);
|
|
204
|
+
if (nameMatch(false, cred)) return true;
|
|
205
|
+
if (nameMatch(true, cred)) foldOnly = true;
|
|
206
|
+
}
|
|
207
|
+
if (foldOnly && (await volumeFolds(dir))) return true;
|
|
208
|
+
// A credential file that is itself a symlink: its destination is the credential too.
|
|
209
|
+
for (const name of AGENT_CREDENTIAL_NAMES) {
|
|
210
|
+
const cred = credFile(dir, name);
|
|
211
|
+
let real: string;
|
|
212
|
+
try {
|
|
213
|
+
real = await fs.realpath(cred);
|
|
214
|
+
} catch {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (real !== cred && real === realTarget) return true;
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Is REAL path `realTarget` a pi-agent credential file (or same-dir `<name>.*` sibling)? */
|
|
223
|
+
async function isAgentCredentialReal(realTarget: string): Promise<boolean> {
|
|
224
|
+
for (const dir of await agentCredentialDirs()) {
|
|
225
|
+
if (await isCredentialIn(dir, realTarget)) return true;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Synchronous "is this file a pi-agent credential file?" for the JS grep walker, so it never reads one.
|
|
232
|
+
* Basename pre-filter first (cheap), then a `realpathSync` compare. Folds case unconditionally (a
|
|
233
|
+
* differently-cased name is merely skipped by the search fallback).
|
|
234
|
+
*/
|
|
235
|
+
export function isAgentCredentialFileSync(full: string): boolean {
|
|
236
|
+
const base = norm(path.basename(full));
|
|
237
|
+
const candidate = AGENT_CREDENTIAL_NAMES.some((n) => {
|
|
238
|
+
const b = norm(path.basename(n));
|
|
239
|
+
return base === b || base.startsWith(`${b}.`);
|
|
240
|
+
});
|
|
241
|
+
if (!candidate) return false;
|
|
242
|
+
let real: string;
|
|
243
|
+
try {
|
|
244
|
+
real = realpathSync(full);
|
|
245
|
+
} catch {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const targetDir = norm(path.dirname(real));
|
|
249
|
+
const targetBase = norm(path.basename(real));
|
|
250
|
+
for (const dir of agentCredentialDirsSync()) {
|
|
251
|
+
for (const name of AGENT_CREDENTIAL_NAMES) {
|
|
252
|
+
const cred = credFile(dir, name);
|
|
253
|
+
const b = norm(path.basename(cred));
|
|
254
|
+
if (norm(path.dirname(cred)) === targetDir && (targetBase === b || targetBase.startsWith(`${b}.`))) return true;
|
|
255
|
+
try {
|
|
256
|
+
if (norm(realpathSync(cred)) === norm(real)) return true;
|
|
257
|
+
} catch {
|
|
258
|
+
/* absent */
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The tier of a path that is ALREADY a real path, relative to the real dashboard dir; `null` outside it. */
|
|
266
|
+
function tierWithin(realDir: string, realTarget: string): DashboardStateTier | null {
|
|
267
|
+
const rel = path.relative(norm(realDir), norm(realTarget));
|
|
268
|
+
if (rel === "") return "gated";
|
|
269
|
+
if (rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) return null;
|
|
270
|
+
const first = rel.split(path.sep)[0];
|
|
271
|
+
if (first === "local" || rel === "identity.key") return "always";
|
|
272
|
+
return "gated";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Is `target` (any spelling: relative symlinks, `~` already expanded) inside the
|
|
277
|
+
* dashboard state dir (and which tier), or a pi-agent credential file (`"always"`)? Realpath-based, so
|
|
278
|
+
* a symlink INTO the dir and a `$HOME` symlink are both seen through.
|
|
279
|
+
*/
|
|
280
|
+
export async function isDashboardStatePath(target: string): Promise<DashboardStateTier | null> {
|
|
281
|
+
const [realDir, realTarget] = await Promise.all([realDashboardDir(), realpathLoose(path.resolve(target))]);
|
|
282
|
+
const tier = tierWithin(realDir, realTarget);
|
|
283
|
+
if (tier === "always") return tier;
|
|
284
|
+
if (await isAgentCredentialReal(realTarget)) return "always";
|
|
285
|
+
return tier;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Must the current caller be refused this path? Always-refused tier: every caller.
|
|
290
|
+
* Trust-gated tier: unless the request's caller is admitted (no caller in scope ⇒ internal ⇒ admitted).
|
|
291
|
+
*/
|
|
292
|
+
export async function dashboardStateRefuses(target: string): Promise<boolean> {
|
|
293
|
+
const tier = await isDashboardStatePath(target);
|
|
294
|
+
if (tier === null) return false;
|
|
295
|
+
if (tier === "always") return true;
|
|
296
|
+
const caller = currentStateCaller();
|
|
297
|
+
return caller ? !caller.gatedAdmitted() : false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Is the current request's caller a bare-loopback one that merely lacks proof? */
|
|
301
|
+
export function currentCallerUnproven(): boolean {
|
|
302
|
+
return currentStateCaller()?.unproven() === true;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function alwaysRefusedFiles(realDir: string): Promise<string[]> {
|
|
306
|
+
const out: string[] = [path.join(realDir, "identity.key")];
|
|
307
|
+
const walk = async (dir: string, depth: number): Promise<void> => {
|
|
308
|
+
let entries: import("node:fs").Dirent[];
|
|
309
|
+
try {
|
|
310
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
311
|
+
} catch {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
for (const e of entries) {
|
|
315
|
+
const full = path.join(dir, e.name);
|
|
316
|
+
if (e.isDirectory()) {
|
|
317
|
+
if (depth < 3) await walk(full, depth + 1);
|
|
318
|
+
} else {
|
|
319
|
+
out.push(full);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
await walk(path.join(realDir, "local"), 0);
|
|
324
|
+
// pi-agent credential files + their same-dir `<name>.*` siblings (one readdir per credential dir).
|
|
325
|
+
for (const dir of await agentCredentialDirs()) {
|
|
326
|
+
let folds: boolean | undefined; // probed lazily: only when a case-only sibling match needs it
|
|
327
|
+
const byDir = new Map<string, string[]>();
|
|
328
|
+
for (const name of AGENT_CREDENTIAL_NAMES) {
|
|
329
|
+
const cred = credFile(dir, name);
|
|
330
|
+
out.push(cred);
|
|
331
|
+
const d = path.dirname(cred);
|
|
332
|
+
byDir.set(d, [...(byDir.get(d) ?? []), path.basename(cred)]);
|
|
333
|
+
}
|
|
334
|
+
for (const [d, bases] of byDir) {
|
|
335
|
+
let names: string[];
|
|
336
|
+
try {
|
|
337
|
+
names = await fs.readdir(d);
|
|
338
|
+
} catch {
|
|
339
|
+
continue; // best effort: the named files above are still rechecked
|
|
340
|
+
}
|
|
341
|
+
for (const n of names) {
|
|
342
|
+
if (bases.some((b) => n.startsWith(`${b}.`))) {
|
|
343
|
+
out.push(path.join(d, n));
|
|
344
|
+
} else if (bases.some((b) => norm(n).startsWith(`${norm(b)}.`))) {
|
|
345
|
+
folds ??= await volumeFolds(dir);
|
|
346
|
+
if (folds) out.push(path.join(d, n));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** (dev, ino) of every always-refused file that exists right now. Build once per request, reuse across checks. */
|
|
355
|
+
export type AlwaysRefusedIdentities = ReadonlyArray<{ dev: number | bigint; ino: number | bigint }>;
|
|
356
|
+
export async function alwaysRefusedIdentities(): Promise<AlwaysRefusedIdentities> {
|
|
357
|
+
const out: Array<{ dev: number | bigint; ino: number | bigint }> = [];
|
|
358
|
+
for (const file of await alwaysRefusedFiles(await realDashboardDir())) {
|
|
359
|
+
try {
|
|
360
|
+
const st = await fs.stat(file);
|
|
361
|
+
out.push({ dev: st.dev, ino: st.ino });
|
|
362
|
+
} catch {
|
|
363
|
+
/* absent: cannot be the opened file */
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Is `(dev, ino)` an always-refused file? Pass a prebuilt `identities` list to amortize across many checks. */
|
|
370
|
+
export async function identityIsAlwaysRefused(
|
|
371
|
+
id: { dev: number | bigint; ino: number | bigint },
|
|
372
|
+
identities?: AlwaysRefusedIdentities,
|
|
373
|
+
): Promise<boolean> {
|
|
374
|
+
const list = identities ?? (await alwaysRefusedIdentities());
|
|
375
|
+
return list.some((f) => f.ino === id.ino && f.dev === id.dev);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* After OPENING a path, is the handle one of the always-refused files? Compares
|
|
380
|
+
* (dev, ino) of the handle with each always-refused file, so a symlink or hard
|
|
381
|
+
* link swapped in after the path check is caught. Fails closed on a stat error
|
|
382
|
+
* of the HANDLE; a vanished always-refused file simply cannot match.
|
|
383
|
+
*/
|
|
384
|
+
export async function handleIsAlwaysRefused(handle: { stat(): Promise<{ dev: number | bigint; ino: number | bigint }> }): Promise<boolean> {
|
|
385
|
+
return identityIsAlwaysRefused(await handle.stat());
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let cachedSyncFor = "";
|
|
389
|
+
let cachedSyncReal = "";
|
|
390
|
+
/**
|
|
391
|
+
* Synchronous "is this directory the dashboard state dir itself?" for the one sync walker (the JS grep
|
|
392
|
+
* fallback), so it never enters the dir. Cheap: only a directory whose BASE NAME matches the state dir's
|
|
393
|
+
* is resolved. Compared on real paths, like {@link isDashboardStatePath}.
|
|
394
|
+
*/
|
|
395
|
+
export function isDashboardStateDirSync(dir: string): boolean {
|
|
396
|
+
const configured = getDashboardConfigDir();
|
|
397
|
+
if (norm(path.basename(dir)) !== norm(path.basename(configured))) return false;
|
|
398
|
+
const key = `${os.homedir()}`;
|
|
399
|
+
if (cachedSyncFor !== key) {
|
|
400
|
+
try {
|
|
401
|
+
cachedSyncReal = realpathSync(configured);
|
|
402
|
+
} catch {
|
|
403
|
+
cachedSyncReal = path.resolve(configured);
|
|
404
|
+
}
|
|
405
|
+
cachedSyncFor = key;
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
return norm(realpathSync(dir)) === norm(cachedSyncReal);
|
|
409
|
+
} catch {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Thrown when an OPENED handle turned out to be one of the always-refused files. */
|
|
415
|
+
export class DashboardStateRefused extends Error {
|
|
416
|
+
constructor() {
|
|
417
|
+
super("refused: dashboard state file");
|
|
418
|
+
this.name = "DashboardStateRefused";
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Thrown when an OPENED handle is not the file the containment decision was made on: the path now
|
|
424
|
+
* resolves elsewhere (a link swapped in after the decision) or the handle's identity differs, or the
|
|
425
|
+
* post-open check itself failed. Subclasses {@link DashboardStateRefused} so every site that already maps
|
|
426
|
+
* that to its containment refusal (403, never 2xx/500) maps this too.
|
|
427
|
+
* See change: close-local-listener-and-egress-gaps (D2).
|
|
428
|
+
*/
|
|
429
|
+
export class ContainmentBindingRefused extends DashboardStateRefused {
|
|
430
|
+
constructor() {
|
|
431
|
+
super();
|
|
432
|
+
this.message = "refused: opened file is not the path the containment decision bound";
|
|
433
|
+
this.name = "ContainmentBindingRefused";
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Options binding an open to the real path a containment decision was made on. */
|
|
438
|
+
export interface DecidedRealOpts {
|
|
439
|
+
decidedReal?: string;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Post-open binding: the path still resolves to `decidedReal` and the handle is that file
|
|
444
|
+
* (same dev+ino). Any failure of the check is the same refusal. Caller closes the handle.
|
|
445
|
+
*/
|
|
446
|
+
export async function assertHandleBoundToDecided(
|
|
447
|
+
fh: import("node:fs/promises").FileHandle,
|
|
448
|
+
p: string,
|
|
449
|
+
decidedReal: string,
|
|
450
|
+
): Promise<void> {
|
|
451
|
+
try {
|
|
452
|
+
if ((await fs.realpath(p)) !== decidedReal) throw new ContainmentBindingRefused();
|
|
453
|
+
// lstat, not stat: if the path flipped to a link after the realpath above, `stat` would follow it to the
|
|
454
|
+
// very file the handle already holds and the check would pass; `lstat` sees the link's own identity.
|
|
455
|
+
const [handleStat, realStat] = await Promise.all([fh.stat(), fs.lstat(decidedReal)]);
|
|
456
|
+
if (handleStat.dev !== realStat.dev || handleStat.ino !== realStat.ino) throw new ContainmentBindingRefused();
|
|
457
|
+
} catch (err) {
|
|
458
|
+
throw err instanceof ContainmentBindingRefused ? err : new ContainmentBindingRefused();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* `fs.open` + the post-open handle check. A refused handle is closed at once and
|
|
464
|
+
* nothing is read from it. With `opts.decidedReal` the handle must also be bound to
|
|
465
|
+
* that decided real path (see {@link assertHandleBoundToDecided}).
|
|
466
|
+
*/
|
|
467
|
+
export async function openStateChecked(
|
|
468
|
+
p: string,
|
|
469
|
+
flags: string | number = "r",
|
|
470
|
+
opts: DecidedRealOpts = {},
|
|
471
|
+
): Promise<import("node:fs/promises").FileHandle> {
|
|
472
|
+
const fh = await fs.open(p, flags);
|
|
473
|
+
try {
|
|
474
|
+
if (await handleIsAlwaysRefused(fh)) throw new DashboardStateRefused();
|
|
475
|
+
if (opts.decidedReal !== undefined) await assertHandleBoundToDecided(fh, p, opts.decidedReal);
|
|
476
|
+
} catch (err) {
|
|
477
|
+
await fh.close().catch(() => undefined);
|
|
478
|
+
throw err;
|
|
479
|
+
}
|
|
480
|
+
return fh;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** `fs.readFile` through {@link openStateChecked}: the bytes come from the checked handle. */
|
|
484
|
+
export async function readFileStateChecked(p: string, encoding?: undefined, opts?: DecidedRealOpts): Promise<Buffer>;
|
|
485
|
+
export async function readFileStateChecked(p: string, encoding: BufferEncoding, opts?: DecidedRealOpts): Promise<string>;
|
|
486
|
+
export async function readFileStateChecked(
|
|
487
|
+
p: string,
|
|
488
|
+
encoding?: BufferEncoding,
|
|
489
|
+
opts: DecidedRealOpts = {},
|
|
490
|
+
): Promise<Buffer | string> {
|
|
491
|
+
const fh = await openStateChecked(p, "r", opts);
|
|
492
|
+
try {
|
|
493
|
+
return encoding ? await fh.readFile(encoding) : await fh.readFile();
|
|
494
|
+
} finally {
|
|
495
|
+
await fh.close().catch(() => undefined);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Plugin seam (`ServerPluginContext.readFileGuarded`): UTF-8 read of `absPath` that resolves `null` when
|
|
501
|
+
* the guard refuses it — decided on the REAL path (both tiers, caller from the request scope) and again
|
|
502
|
+
* on the opened handle's (dev, ino). Other failures (ENOENT, EISDIR, EACCES) reject unchanged.
|
|
503
|
+
* See change: close-security-map-high-findings (D1, H1).
|
|
504
|
+
*/
|
|
505
|
+
export async function readFileGuarded(absPath: string): Promise<string | null> {
|
|
506
|
+
if (await dashboardStateRefuses(absPath)) return null;
|
|
507
|
+
try {
|
|
508
|
+
return await readFileStateChecked(absPath, "utf-8");
|
|
509
|
+
} catch (err) {
|
|
510
|
+
if (err instanceof DashboardStateRefused) return null;
|
|
511
|
+
throw err;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
* See OpenSpec change: diagram-rendering (design D3, D4, D5).
|
|
6
6
|
*/
|
|
7
|
+
|
|
7
8
|
import { createHash } from "node:crypto";
|
|
8
9
|
import zlib from "node:zlib";
|
|
9
|
-
import {
|
|
10
|
+
import { type KrokiConfig, resolveKrokiEndpoint } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
11
|
+
import { DIAGRAM_SVG_PROFILE } from "@blackbelt-technology/pi-dashboard-shared/sanitize-profiles.js";
|
|
10
12
|
import { createSemaphore } from "@blackbelt-technology/pi-dashboard-shared/semaphore.js";
|
|
11
13
|
import { loadPurify } from "./purify.js";
|
|
12
14
|
|
|
@@ -31,11 +33,7 @@ const MAX_DIAGRAM_RESPONSE_BYTES = 5 * 1024 * 1024; // 5 MB response cap
|
|
|
31
33
|
|
|
32
34
|
async function sanitizeSvg(svg: string): Promise<string> {
|
|
33
35
|
const purify = await loadPurify();
|
|
34
|
-
return purify.sanitize(svg,
|
|
35
|
-
USE_PROFILES: { svg: true, svgFilters: true },
|
|
36
|
-
FORBID_TAGS: ["foreignObject", "script", "style"],
|
|
37
|
-
FORBID_ATTR: ["onclick", "onload", "onerror", "onmouseover", "onmouseout"],
|
|
38
|
-
});
|
|
36
|
+
return purify.sanitize(svg, DIAGRAM_SVG_PROFILE);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
// ── In-memory LRU cache ─────────────────────────────────────────────────────
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
* NEVER fetches remote URLs — the browser does, inside the opaque-origin iframe.
|
|
10
10
|
* See change: add-eml-preview.
|
|
11
11
|
*/
|
|
12
|
+
|
|
12
13
|
import type { Stats } from "node:fs";
|
|
13
|
-
import
|
|
14
|
+
import { EML_PROFILE } from "@blackbelt-technology/pi-dashboard-shared/sanitize-profiles.js";
|
|
14
15
|
import { type ParsedMail, simpleParser } from "mailparser";
|
|
16
|
+
import { readFileStateChecked } from "./dashboard-state-guard.js";
|
|
15
17
|
import { loadPurify } from "./purify.js";
|
|
16
18
|
|
|
17
19
|
// Lazy DOMPurify via shared `loadPurify()` (./purify.ts): a broken jsdom fails a
|
|
@@ -96,7 +98,7 @@ export async function loadParsedEml(
|
|
|
96
98
|
parseCache.unshift(hit);
|
|
97
99
|
return hit.parsed;
|
|
98
100
|
}
|
|
99
|
-
const parsed = await parseEmlBuffer(await
|
|
101
|
+
const parsed = await parseEmlBuffer(await readFileStateChecked(absPath));
|
|
100
102
|
rememberParsed(key, parsed);
|
|
101
103
|
return parsed;
|
|
102
104
|
}
|
|
@@ -184,14 +186,7 @@ export async function sanitizeBody(
|
|
|
184
186
|
): Promise<{ html: string; hasRemote: boolean }> {
|
|
185
187
|
if (!rawHtml) return { html: "", hasRemote: false };
|
|
186
188
|
const DOMPurify = await loadPurify();
|
|
187
|
-
const bodyEl = DOMPurify.sanitize(rawHtml, {
|
|
188
|
-
RETURN_DOM: true,
|
|
189
|
-
WHOLE_DOCUMENT: false,
|
|
190
|
-
// FORCE_BODY keeps a leading `<style>` from being hoisted to <head> + dropped.
|
|
191
|
-
FORCE_BODY: true,
|
|
192
|
-
ADD_TAGS: ["style"],
|
|
193
|
-
ADD_ATTR: ["target"],
|
|
194
|
-
}) as unknown as DomEl;
|
|
189
|
+
const bodyEl = DOMPurify.sanitize(rawHtml, { ...EML_PROFILE, RETURN_DOM: true }) as unknown as DomEl;
|
|
195
190
|
|
|
196
191
|
let hasRemote = false;
|
|
197
192
|
const elements: DomEl[] = [bodyEl, ...Array.from(bodyEl.querySelectorAll("*"))];
|