@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,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route model for server identities: one pure, I/O-free module shared by the
|
|
3
|
+
* dashboard server, the browser client and Electron.
|
|
4
|
+
*
|
|
5
|
+
* A server is its identity (fingerprint); an address at which it answers is a
|
|
6
|
+
* {@link Route}. This module owns the rules that turn addresses into rows:
|
|
7
|
+
* host normalisation, derived route kind (never stored), grouping (D1), best
|
|
8
|
+
* route (D3), validation of routes delivered at pairing (D7) and the pair
|
|
9
|
+
* action per client (D8).
|
|
10
|
+
*
|
|
11
|
+
* See change: group-servers-by-identity (design D1–D4, D7, D8, D11).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type RouteScheme = "http" | "https";
|
|
15
|
+
/** How a route was learned. `config` is not a source: legacy entries are `saved`. */
|
|
16
|
+
export type RouteSource = "saved" | "mdns" | "pairing";
|
|
17
|
+
export type RouteKind = "loopback" | "lan" | "mdns" | "tunnel" | "public";
|
|
18
|
+
|
|
19
|
+
/** The persisted shape of a route: host, port, scheme and source only (kind is derived). */
|
|
20
|
+
export interface Route {
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
scheme: RouteScheme;
|
|
24
|
+
source: RouteSource;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A route is "similar" in latency to another within this many ms (inclusive, D11). */
|
|
28
|
+
export const SIMILAR_LATENCY_MS = 50;
|
|
29
|
+
/** At most this many delivered routes are kept (D7). */
|
|
30
|
+
export const MAX_DELIVERED_ROUTES = 8;
|
|
31
|
+
const MAX_HOST_CHARS = 253;
|
|
32
|
+
|
|
33
|
+
export const ROUTE_SCHEMES: readonly RouteScheme[] = ["http", "https"];
|
|
34
|
+
export const ROUTE_SOURCES: readonly RouteSource[] = ["saved", "mdns", "pairing"];
|
|
35
|
+
|
|
36
|
+
/** Scheme a legacy `host`/`port` pair is read as: `https` on 443, else `http`. */
|
|
37
|
+
export function defaultSchemeForPort(port: number): RouteScheme {
|
|
38
|
+
return port === 443 ? "https" : "http";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Valid TCP port: integer in 1..65535. */
|
|
42
|
+
export function isValidPort(port: unknown): port is number {
|
|
43
|
+
return typeof port === "number" && Number.isInteger(port) && port >= 1 && port <= 65535;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── Host normalisation (D4, D11) ──────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
const IPV4_RE = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
49
|
+
|
|
50
|
+
function parseIpv4(text: string): Uint8Array | null {
|
|
51
|
+
const m = IPV4_RE.exec(text);
|
|
52
|
+
if (!m) return null;
|
|
53
|
+
const bytes = new Uint8Array(4);
|
|
54
|
+
for (let i = 0; i < 4; i++) {
|
|
55
|
+
const n = Number(m[i + 1]);
|
|
56
|
+
if (n > 255) return null;
|
|
57
|
+
bytes[i] = n;
|
|
58
|
+
}
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Hex groups of one `::`-free side of an IPv6 literal; null when any group is malformed. */
|
|
63
|
+
function ipv6Groups(side: string): number[] | null {
|
|
64
|
+
if (side === "") return [];
|
|
65
|
+
const out: number[] = [];
|
|
66
|
+
for (const g of side.split(":")) {
|
|
67
|
+
if (!/^[0-9a-f]{1,4}$/i.test(g)) return null;
|
|
68
|
+
out.push(Number.parseInt(g, 16));
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Parse an IPv6 literal (no brackets, no zone) into 16 bytes; embedded IPv4 tail supported. */
|
|
74
|
+
function parseIpv6(text: string): Uint8Array | null {
|
|
75
|
+
if (!/^[0-9a-f:.]+$/i.test(text) || !text.includes(":")) return null;
|
|
76
|
+
let head = text;
|
|
77
|
+
let tail: number[] = [];
|
|
78
|
+
if (head.includes(".")) {
|
|
79
|
+
const cut = head.lastIndexOf(":");
|
|
80
|
+
const v4 = parseIpv4(head.slice(cut + 1));
|
|
81
|
+
if (!v4) return null;
|
|
82
|
+
tail = [(v4[0] << 8) | v4[1], (v4[2] << 8) | v4[3]];
|
|
83
|
+
// `::1.2.3.4` keeps its `::`; `a:b:1.2.3.4` loses the dangling `:`.
|
|
84
|
+
head = head.slice(0, cut + 1);
|
|
85
|
+
if (!head.endsWith("::")) head = head.slice(0, -1);
|
|
86
|
+
}
|
|
87
|
+
const halves = head.split("::");
|
|
88
|
+
if (halves.length > 2) return null;
|
|
89
|
+
const left = ipv6Groups(halves[0]);
|
|
90
|
+
const right = halves.length === 2 ? ipv6Groups(halves[1]) : [];
|
|
91
|
+
if (!left || !right) return null;
|
|
92
|
+
const zeros = halves.length === 2 ? 8 - left.length - right.length - tail.length : 0;
|
|
93
|
+
const all = [...left, ...new Array<number>(Math.max(zeros, 0)).fill(0), ...right, ...tail];
|
|
94
|
+
if (all.length !== 8 || (halves.length === 2 && zeros < 1)) return null;
|
|
95
|
+
const bytes = new Uint8Array(16);
|
|
96
|
+
all.forEach((g, i) => {
|
|
97
|
+
bytes[i * 2] = g >> 8;
|
|
98
|
+
bytes[i * 2 + 1] = g & 0xff;
|
|
99
|
+
});
|
|
100
|
+
return bytes;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isIpv4Mapped(b: Uint8Array): boolean {
|
|
104
|
+
for (let i = 0; i < 10; i++) if (b[i] !== 0) return false;
|
|
105
|
+
return b[10] === 0xff && b[11] === 0xff;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One spelling per host: trimmed, lower-cased, brackets and an IPv6 zone id
|
|
110
|
+
* removed, one trailing dot removed, an IPv4-mapped IPv6 literal rewritten as
|
|
111
|
+
* its IPv4 address. Used before classifying and before comparing hosts.
|
|
112
|
+
*/
|
|
113
|
+
export function normalizeHost(host: string): string {
|
|
114
|
+
let h = host.trim().toLowerCase();
|
|
115
|
+
if (h.startsWith("[") && h.endsWith("]")) h = h.slice(1, -1);
|
|
116
|
+
const zone = h.indexOf("%");
|
|
117
|
+
if (zone !== -1) h = h.slice(0, zone);
|
|
118
|
+
if (h.endsWith(".")) h = h.slice(0, -1);
|
|
119
|
+
if (h.includes(":")) {
|
|
120
|
+
const bytes = parseIpv6(h);
|
|
121
|
+
if (bytes && isIpv4Mapped(bytes)) return `${bytes[12]}.${bytes[13]}.${bytes[14]}.${bytes[15]}`;
|
|
122
|
+
}
|
|
123
|
+
return h;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Stable identity of a route for de-duplication: scheme, normalised host, port. */
|
|
127
|
+
export function routeKey(route: Pick<Route, "host" | "port" | "scheme">): string {
|
|
128
|
+
return `${route.scheme}://${normalizeHost(route.host)}:${route.port}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── Route kind (D4) ───────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
function ipv4Kind(b: Uint8Array): RouteKind {
|
|
134
|
+
if (b[0] === 127) return "loopback";
|
|
135
|
+
if (
|
|
136
|
+
b[0] === 10 ||
|
|
137
|
+
(b[0] === 172 && b[1] >= 16 && b[1] <= 31) ||
|
|
138
|
+
(b[0] === 192 && b[1] === 168) ||
|
|
139
|
+
(b[0] === 100 && b[1] >= 64 && b[1] <= 127) ||
|
|
140
|
+
(b[0] === 169 && b[1] === 254)
|
|
141
|
+
) {
|
|
142
|
+
return "lan";
|
|
143
|
+
}
|
|
144
|
+
return "public";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function ipv6Kind(b: Uint8Array): RouteKind {
|
|
148
|
+
if (b.slice(0, 15).every((x) => x === 0) && b[15] === 1) return "loopback";
|
|
149
|
+
if ((b[0] & 0xfe) === 0xfc || (b[0] === 0xfe && (b[1] & 0xc0) === 0x80)) return "lan";
|
|
150
|
+
return "public";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Derived, never persisted. `lan` mirrors the knock gate's private ranges
|
|
155
|
+
* (a boundary-table test pins them together); `tunnel` is `zrok.io` over https
|
|
156
|
+
* only, the one tunnel host the code names; everything unlisted is `public`.
|
|
157
|
+
*/
|
|
158
|
+
export function classifyRoute(route: { host: string; scheme: RouteScheme }): RouteKind {
|
|
159
|
+
const h = normalizeHost(route.host);
|
|
160
|
+
if (!h) return "public";
|
|
161
|
+
const v4 = parseIpv4(h);
|
|
162
|
+
if (v4) return ipv4Kind(v4);
|
|
163
|
+
if (h.includes(":")) {
|
|
164
|
+
const v6 = parseIpv6(h);
|
|
165
|
+
return v6 ? ipv6Kind(v6) : "public";
|
|
166
|
+
}
|
|
167
|
+
if (h === "localhost") return "loopback";
|
|
168
|
+
if (h.endsWith(".local")) return "mdns";
|
|
169
|
+
if (route.scheme === "https" && (h === "zrok.io" || h.endsWith(".zrok.io"))) return "tunnel";
|
|
170
|
+
if (!h.includes(".") || h.endsWith(".lan") || h.endsWith(".home.arpa") || h.endsWith(".internal")) return "lan";
|
|
171
|
+
return "public";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** On-link = a knock may be possible: kind `lan` or `mdns`, over plain http. */
|
|
175
|
+
export function isOnLinkRoute(route: { host: string; scheme: RouteScheme }): boolean {
|
|
176
|
+
if (route.scheme !== "http") return false;
|
|
177
|
+
const kind = classifyRoute(route);
|
|
178
|
+
return kind === "lan" || kind === "mdns";
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Primary route: the first `http` route, else the first route. */
|
|
182
|
+
export function primaryRoute<R extends Pick<Route, "scheme">>(routes: readonly R[]): R | undefined {
|
|
183
|
+
return routes.find((r) => r.scheme === "http") ?? routes[0];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── Grouping (D1) ─────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
export interface RouteEntry {
|
|
189
|
+
fingerprint?: string;
|
|
190
|
+
routes: readonly Route[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A route plus the fingerprint it proved (or advertised); none ⇒ identity not known. */
|
|
194
|
+
export interface ProvenRoute {
|
|
195
|
+
route: Route;
|
|
196
|
+
fingerprint?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface GroupedEntry {
|
|
200
|
+
fingerprint?: string;
|
|
201
|
+
routes: Route[];
|
|
202
|
+
/** Indices (in the result) of other entries holding the same fingerprint on another instance port. */
|
|
203
|
+
sameIdentityAs: number[];
|
|
204
|
+
/** False for an entry with no known fingerprint ("identity not advertised"). */
|
|
205
|
+
identityAdvertised: boolean;
|
|
206
|
+
/** Index of the input entry this one grew from; absent for entries created here. */
|
|
207
|
+
sourceIndex?: number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Does `routes` already hold `route` (same scheme, normalised host, port)? */
|
|
211
|
+
function holdsRoute(routes: readonly Route[], route: Route): boolean {
|
|
212
|
+
const key = routeKey(route);
|
|
213
|
+
return routes.some((r) => routeKey(r) === key);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Index of the entry a route proving `fingerprint` joins, or -1 for "start a
|
|
218
|
+
* new entry". An `https` route joins the FIRST entry holding the fingerprint
|
|
219
|
+
* (stored order decides, not port); an `http` route joins the first holder that
|
|
220
|
+
* has no `http` route yet or already has one on the same port.
|
|
221
|
+
*/
|
|
222
|
+
export function findAttachTarget(entries: readonly RouteEntry[], route: Route, fingerprint: string | undefined): number {
|
|
223
|
+
if (fingerprint === undefined) return -1;
|
|
224
|
+
for (let i = 0; i < entries.length; i++) {
|
|
225
|
+
const entry = entries[i];
|
|
226
|
+
if (entry.fingerprint !== fingerprint) continue;
|
|
227
|
+
if (route.scheme === "https") return i;
|
|
228
|
+
const httpRoutes = entry.routes.filter((r) => r.scheme === "http");
|
|
229
|
+
if (httpRoutes.length === 0 || httpRoutes.some((r) => r.port === route.port)) return i;
|
|
230
|
+
}
|
|
231
|
+
return -1;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Group `incoming` routes into `entries` (copied, never mutated). A route with
|
|
236
|
+
* no fingerprint joins the entry that already holds the same route, else is a
|
|
237
|
+
* single-route entry. A route already held is not duplicated; the first
|
|
238
|
+
* spelling and source win.
|
|
239
|
+
*/
|
|
240
|
+
export function groupRoutes(entries: readonly RouteEntry[], incoming: readonly ProvenRoute[]): GroupedEntry[] {
|
|
241
|
+
const out: GroupedEntry[] = entries.map((e, i) => ({
|
|
242
|
+
...(e.fingerprint !== undefined ? { fingerprint: e.fingerprint } : {}),
|
|
243
|
+
routes: [...e.routes],
|
|
244
|
+
sameIdentityAs: [],
|
|
245
|
+
identityAdvertised: e.fingerprint !== undefined,
|
|
246
|
+
sourceIndex: i,
|
|
247
|
+
}));
|
|
248
|
+
for (const { route, fingerprint } of incoming) {
|
|
249
|
+
let target = findAttachTarget(out, route, fingerprint);
|
|
250
|
+
if (target === -1 && fingerprint === undefined) {
|
|
251
|
+
target = out.findIndex((e) => holdsRoute(e.routes, route));
|
|
252
|
+
}
|
|
253
|
+
if (target === -1) {
|
|
254
|
+
out.push({
|
|
255
|
+
...(fingerprint !== undefined ? { fingerprint } : {}),
|
|
256
|
+
routes: [route],
|
|
257
|
+
sameIdentityAs: [],
|
|
258
|
+
identityAdvertised: fingerprint !== undefined,
|
|
259
|
+
});
|
|
260
|
+
} else if (!holdsRoute(out[target].routes, route)) {
|
|
261
|
+
out[target].routes.push(route);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
out.forEach((entry, i) => {
|
|
265
|
+
if (entry.fingerprint === undefined) return;
|
|
266
|
+
out.forEach((other, j) => {
|
|
267
|
+
if (j !== i && other.fingerprint === entry.fingerprint) entry.sameIdentityAs.push(j);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ── Best route (D3) ───────────────────────────────────────────────────
|
|
274
|
+
|
|
275
|
+
/** A route with its check result; `latencyMs` is the identity-challenge round trip. */
|
|
276
|
+
export type RankableRoute<R extends Route = Route> = R & {
|
|
277
|
+
/** The challenge proved the group's fingerprint. Anything else is never a candidate. */
|
|
278
|
+
proven: boolean;
|
|
279
|
+
latencyMs?: number;
|
|
280
|
+
/** Seen by discovery this session rather than stored (credentialed order only). */
|
|
281
|
+
discovered?: boolean;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function fastest<T extends { latencyMs?: number }>(routes: readonly T[]): T | undefined {
|
|
285
|
+
let best: T | undefined;
|
|
286
|
+
for (const r of routes) {
|
|
287
|
+
if (!best || (r.latencyMs ?? Number.POSITIVE_INFINITY) < (best.latencyMs ?? Number.POSITIVE_INFINITY)) best = r;
|
|
288
|
+
}
|
|
289
|
+
return best;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Pick the route in use among the PROVEN ones; `null` when none is.
|
|
294
|
+
*
|
|
295
|
+
* `credentialed: false` (list marker, in-page switch): `https` wins when its
|
|
296
|
+
* latency is within {@link SIMILAR_LATENCY_MS} of the fastest `http` (inclusive),
|
|
297
|
+
* otherwise the lowest latency wins.
|
|
298
|
+
*
|
|
299
|
+
* `credentialed: true` (the app sends a stored bearer, Electron): stored https,
|
|
300
|
+
* then stored http (input order), then discovered; the first proven route wins
|
|
301
|
+
* and latency is never compared, so a faster http route cannot downgrade a
|
|
302
|
+
* bearer-carrying open to cleartext.
|
|
303
|
+
*/
|
|
304
|
+
export function rankRoutes<R extends RankableRoute>(routes: readonly R[], opts: { credentialed: boolean }): R | null {
|
|
305
|
+
const candidates = routes.filter((r) => r.proven);
|
|
306
|
+
if (candidates.length === 0) return null;
|
|
307
|
+
if (opts.credentialed) {
|
|
308
|
+
const stored = candidates.filter((r) => !r.discovered);
|
|
309
|
+
const discovered = candidates.filter((r) => r.discovered);
|
|
310
|
+
return (
|
|
311
|
+
stored.find((r) => r.scheme === "https") ??
|
|
312
|
+
stored.find((r) => r.scheme === "http") ??
|
|
313
|
+
discovered.find((r) => r.scheme === "https") ??
|
|
314
|
+
discovered[0] ??
|
|
315
|
+
null
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const bestHttp = fastest(candidates.filter((r) => r.scheme === "http"));
|
|
319
|
+
const bestHttps = fastest(candidates.filter((r) => r.scheme === "https"));
|
|
320
|
+
if (!bestHttp) return bestHttps ?? null;
|
|
321
|
+
if (!bestHttps) return bestHttp;
|
|
322
|
+
const gap = (bestHttps.latencyMs ?? Number.POSITIVE_INFINITY) - (bestHttp.latencyMs ?? Number.POSITIVE_INFINITY);
|
|
323
|
+
return gap <= SIMILAR_LATENCY_MS ? bestHttps : bestHttp;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// ── Delivered routes (D7) ─────────────────────────────────────────────
|
|
327
|
+
|
|
328
|
+
const DNS_NAME_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Validate ONE delivered route origin; returns its normalised origin or null.
|
|
332
|
+
* `https` only; origin only (the bare trailing slash is accepted); a DNS name
|
|
333
|
+
* that is not an IP literal, `localhost` or `*.local`; host at most 253 chars.
|
|
334
|
+
*/
|
|
335
|
+
export function validateDeliveredOrigin(input: unknown): string | null {
|
|
336
|
+
if (typeof input !== "string") return null;
|
|
337
|
+
const m = /^https:\/\/([^/?#@\s\\]+)\/?$/i.exec(input);
|
|
338
|
+
if (!m) return null;
|
|
339
|
+
let url: URL;
|
|
340
|
+
try {
|
|
341
|
+
url = new URL(`https://${m[1]}`);
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
const host = url.hostname;
|
|
346
|
+
if (host.length === 0 || host.length > MAX_HOST_CHARS) return null;
|
|
347
|
+
if (url.username || url.password) return null;
|
|
348
|
+
const name = host.endsWith(".") ? host.slice(0, -1) : host;
|
|
349
|
+
if (!DNS_NAME_RE.test(name)) return null; // also rejects IPv6 (brackets) and anything URL parsing normalised oddly
|
|
350
|
+
if (parseIpv4(name)) return null;
|
|
351
|
+
if (name === "localhost" || name.endsWith(".local")) return null;
|
|
352
|
+
return url.origin;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Validate the `routes` of an approved poll or the urls of a pairing payload:
|
|
357
|
+
* keep the valid origins, normalised, de-duplicated, in delivery order, at most
|
|
358
|
+
* {@link MAX_DELIVERED_ROUTES}. Anything not an array yields nothing.
|
|
359
|
+
*/
|
|
360
|
+
export function validateDeliveredRoutes(input: unknown): string[] {
|
|
361
|
+
if (!Array.isArray(input)) return [];
|
|
362
|
+
const out: string[] = [];
|
|
363
|
+
for (const item of input) {
|
|
364
|
+
const origin = validateDeliveredOrigin(item);
|
|
365
|
+
if (origin === null || out.includes(origin)) continue;
|
|
366
|
+
out.push(origin);
|
|
367
|
+
if (out.length >= MAX_DELIVERED_ROUTES) break;
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** A validated delivered origin as a persistable route (source `pairing`). */
|
|
373
|
+
export function originToRoute(origin: string): Route {
|
|
374
|
+
const url = new URL(origin);
|
|
375
|
+
return { host: url.hostname, port: url.port ? Number(url.port) : 443, scheme: "https", source: "pairing" };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ── Request page URL ──────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* `http://<host>:<port>/pair?request`, built only from a route's host and port
|
|
382
|
+
* and refused (null) unless the result round-trips to exactly them: no userinfo,
|
|
383
|
+
* path, query or fragment smuggled in the host, port 1..65535, IPv6 bracketed.
|
|
384
|
+
*/
|
|
385
|
+
export function buildRequestPageUrl(host: string, port: number): string | null {
|
|
386
|
+
if (!isValidPort(port)) return null;
|
|
387
|
+
const bare = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
388
|
+
if (!bare || /[\s/\\?#@%]/.test(bare)) return null;
|
|
389
|
+
const authority = bare.includes(":") ? `[${bare}]` : bare;
|
|
390
|
+
const built = `http://${authority}:${port}/pair?request`;
|
|
391
|
+
let url: URL;
|
|
392
|
+
try {
|
|
393
|
+
url = new URL(built);
|
|
394
|
+
} catch {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
const portOk = url.port === String(port) || (port === 80 && url.port === "");
|
|
398
|
+
const roundTrips =
|
|
399
|
+
url.protocol === "http:" &&
|
|
400
|
+
!url.username &&
|
|
401
|
+
!url.password &&
|
|
402
|
+
url.hostname === authority.toLowerCase() &&
|
|
403
|
+
portOk &&
|
|
404
|
+
url.pathname === "/pair" &&
|
|
405
|
+
url.search === "?request" &&
|
|
406
|
+
url.hash === "";
|
|
407
|
+
return roundTrips ? built : null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ── Pair action (D8) ──────────────────────────────────────────────────
|
|
411
|
+
|
|
412
|
+
export type PairClient = "browser" | "electron";
|
|
413
|
+
|
|
414
|
+
export interface PairActionInput {
|
|
415
|
+
client: PairClient;
|
|
416
|
+
routes: ReadonlyArray<Route & { discovered?: boolean; inKeyring?: boolean }>;
|
|
417
|
+
/** Advertised or pinned fingerprint of the entry, if any. */
|
|
418
|
+
fingerprint?: string;
|
|
419
|
+
/** This device already holds a credential for the entry. */
|
|
420
|
+
credentialHeld: boolean;
|
|
421
|
+
/** The entry is the dashboard the page is loaded from. */
|
|
422
|
+
isCurrent: boolean;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export type PairAction =
|
|
426
|
+
/** Browser: navigate a new context (noopener) to `url`. Electron: `openServerWindow({host, port})`. */
|
|
427
|
+
| { kind: "request-access"; route: Route; url?: string }
|
|
428
|
+
/** Electron only, no fingerprint known: prove, show it in full, request after the user confirms. */
|
|
429
|
+
| { kind: "verify-and-request"; route: Route }
|
|
430
|
+
/** Paste a pairing code; needs a fingerprint to compare against. */
|
|
431
|
+
| { kind: "pair-with-code" };
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The one pair action for an entry this device has no credential for, or null
|
|
435
|
+
* (no action: state text only). A browser sends and proves nothing from the
|
|
436
|
+
* current page — it only navigates to the peer's own request page — so it never
|
|
437
|
+
* verifies a fingerprint. Electron proves identity before anything is sent.
|
|
438
|
+
*/
|
|
439
|
+
export function pairAction(input: PairActionInput): PairAction | null {
|
|
440
|
+
if (input.credentialHeld || input.isCurrent) return null;
|
|
441
|
+
const onLink = input.routes.filter(isOnLinkRoute);
|
|
442
|
+
const code: PairAction | null = input.fingerprint ? { kind: "pair-with-code" } : null;
|
|
443
|
+
|
|
444
|
+
if (input.client === "browser") {
|
|
445
|
+
const ordered = [...onLink.filter((r) => r.discovered), ...onLink.filter((r) => !r.discovered)];
|
|
446
|
+
for (const r of ordered) {
|
|
447
|
+
const url = buildRequestPageUrl(r.host, r.port);
|
|
448
|
+
if (url) return { kind: "request-access", route: toRoute(r), url };
|
|
449
|
+
}
|
|
450
|
+
return code;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const discovered = onLink.find((r) => r.discovered);
|
|
454
|
+
if (!input.fingerprint && discovered) return { kind: "verify-and-request", route: toRoute(discovered) };
|
|
455
|
+
const reachable = discovered ?? onLink.find((r) => r.inKeyring);
|
|
456
|
+
if (reachable) return { kind: "request-access", route: toRoute(reachable) };
|
|
457
|
+
return code;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function toRoute(r: Route): Route {
|
|
461
|
+
return { host: r.host, port: r.port, scheme: r.scheme, source: r.source };
|
|
462
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser route for a session: `/session/<id>[/diff|/editor]`. Pure and
|
|
3
|
+
* base-free; callers prepend their own origin (server `uiUrl` / `diffUrl`).
|
|
4
|
+
* See change: add-session-ui-deep-links-for-agents (D2).
|
|
5
|
+
*/
|
|
6
|
+
export type SessionUiView = "diff" | "editor";
|
|
7
|
+
|
|
8
|
+
export function sessionUiPath(id: string, view?: SessionUiView): string {
|
|
9
|
+
const base = `/session/${encodeURIComponent(id)}`;
|
|
10
|
+
return view ? `${base}/${view}` : base;
|
|
11
|
+
}
|
|
@@ -129,7 +129,7 @@ export function sourcesMatch(a: string, b: string): boolean {
|
|
|
129
129
|
// Cross-kind: git ↔ npm. Match the git repo name against the npm
|
|
130
130
|
// package's unscoped name (strip @scope/). Handles packages migrated from
|
|
131
131
|
// a git source to a published npm scope without updating every
|
|
132
|
-
// registration
|
|
132
|
+
// registration.
|
|
133
133
|
const npmKey = ka.kind === "npm" ? ka : kb.kind === "npm" ? kb : null;
|
|
134
134
|
if (gitKey && npmKey) {
|
|
135
135
|
const unscoped = npmKey.name.replace(/^@[^/]+\//, "").toLowerCase();
|
|
@@ -139,7 +139,7 @@ export function sourcesMatch(a: string, b: string): boolean {
|
|
|
139
139
|
// Cross-kind: npm ↔ raw (local path). Match the local path basename
|
|
140
140
|
// against the npm package's unscoped name. Handles a local checkout
|
|
141
141
|
// (`pi install -l <path>`) of a package whose manifest source is the
|
|
142
|
-
// npm scope (e.g.
|
|
142
|
+
// npm scope (e.g. after an npm rescope).
|
|
143
143
|
if (npmKey && rawKey) {
|
|
144
144
|
const basename = localPathBasename(rawKey.source);
|
|
145
145
|
const unscoped = npmKey.name.replace(/^@[^/]+\//, "").toLowerCase();
|
|
@@ -38,21 +38,37 @@ import { drainableEntryUsage, usageToTotals, type EntryUsage } from "./usage-tot
|
|
|
38
38
|
* `session_ended` end). Earlier-message orphans are dead and still close.
|
|
39
39
|
* Default off — cold replays (disk, archive, retained) are unchanged.
|
|
40
40
|
* See change: fix-replay-fabricates-orphan-end-for-live-calls (D1, D2).
|
|
41
|
+
* @param opts.replayEntryTypes Plugin-declared custom-entry types (enabled
|
|
42
|
+
* plugins' manifest `replayEntryTypes`) replayed as their recorded
|
|
43
|
+
* `{ seq, eventType, data }` protocol events, seq-sorted.
|
|
44
|
+
* @param opts.hiddenEntryTypes Further declared types (disabled plugins) kept
|
|
45
|
+
* out of the generic custom paths but NOT replayed. Core names no plugin
|
|
46
|
+
* entry type. See change: update-flows-plugin (D3, G5).
|
|
47
|
+
* @param opts.stats Optional out-param: `pluginEntriesReplayed` += emitted
|
|
48
|
+
* declared-entry events (health counter).
|
|
41
49
|
*/
|
|
42
50
|
export function replayEntriesAsEvents(
|
|
43
51
|
sessionId: string,
|
|
44
52
|
entries: any[],
|
|
45
53
|
knownContextWindow?: number,
|
|
46
|
-
opts?: {
|
|
54
|
+
opts?: {
|
|
55
|
+
liveTailOpen?: boolean;
|
|
56
|
+
replayEntryTypes?: Iterable<string>;
|
|
57
|
+
hiddenEntryTypes?: Iterable<string>;
|
|
58
|
+
stats?: { pluginEntriesReplayed: number };
|
|
59
|
+
},
|
|
47
60
|
): EventForwardMessage[] {
|
|
48
61
|
const messages: EventForwardMessage[] = [];
|
|
49
62
|
const openToolCalls = new Set<string>(); // track tool calls without results
|
|
50
63
|
// toolCall ids of the most recent assistant message (the live tail).
|
|
51
64
|
let lastAssistantToolCallIds = new Set<string>();
|
|
52
|
-
//
|
|
53
|
-
// during the loop, then emitted sorted by seq so
|
|
54
|
-
//
|
|
55
|
-
|
|
65
|
+
// Plugin-declared entry records (e.g. the flows plugin's persisted runs).
|
|
66
|
+
// Collected during the loop, then emitted sorted by seq so a plugin's
|
|
67
|
+
// idempotent reducer rebuilds identically to the live path.
|
|
68
|
+
// See change: replay-persisted-flow-runs; update-flows-plugin (D3).
|
|
69
|
+
const replayTypes = new Set<string>(opts?.replayEntryTypes ?? []);
|
|
70
|
+
const hiddenTypes = new Set<string>([...replayTypes, ...(opts?.hiddenEntryTypes ?? [])]);
|
|
71
|
+
const pluginEntryRecords: Array<{ seq: number; eventType: string; data: unknown; ts: number }> = [];
|
|
56
72
|
|
|
57
73
|
let currentModel = "";
|
|
58
74
|
|
|
@@ -64,15 +80,14 @@ export function replayEntriesAsEvents(
|
|
|
64
80
|
currentModel = entry.modelId ?? "";
|
|
65
81
|
}
|
|
66
82
|
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
if (entry.type === "custom" && entry.customType === "flow-event") {
|
|
83
|
+
// Declared plugin entry: { seq, eventType, data, ...extra }. eventType is
|
|
84
|
+
// already the dashboard protocol name — re-forward verbatim, no re-map;
|
|
85
|
+
// extra fields (e.g. a run id) are ignored. Malformed records skipped.
|
|
86
|
+
// The generic custom-entry arms below never claim a hidden type.
|
|
87
|
+
if (entry.type === "custom" && replayTypes.has(entry.customType)) {
|
|
73
88
|
const rec = entry.data as { seq?: unknown; eventType?: unknown; data?: unknown } | undefined;
|
|
74
89
|
if (rec && typeof rec.eventType === "string") {
|
|
75
|
-
|
|
90
|
+
pluginEntryRecords.push({
|
|
76
91
|
seq: typeof rec.seq === "number" ? rec.seq : 0,
|
|
77
92
|
eventType: rec.eventType,
|
|
78
93
|
data: rec.data,
|
|
@@ -87,12 +102,12 @@ export function replayEntriesAsEvents(
|
|
|
87
102
|
// arm builds the identical row. EXACT `display === false` exclusion (D5):
|
|
88
103
|
// pi normalizes content but NOT display, so an untyped extension omitting
|
|
89
104
|
// the flag yields undefined — which RENDERS (absent flag = meant to be
|
|
90
|
-
// seen). Skipping on falsy would silently hide those.
|
|
91
|
-
// excluded for parity with the entry arm (label-spoofing guard).
|
|
105
|
+
// seen). Skipping on falsy would silently hide those. Plugin-declared
|
|
106
|
+
// types are excluded for parity with the entry arm (label-spoofing guard).
|
|
92
107
|
if (
|
|
93
108
|
entry.type === "custom_message" &&
|
|
94
109
|
entry.display !== false &&
|
|
95
|
-
entry.customType
|
|
110
|
+
!hiddenTypes.has(entry.customType)
|
|
96
111
|
) {
|
|
97
112
|
messages.push(makeEvent(sessionId, "message_end", ts, {
|
|
98
113
|
message: {
|
|
@@ -108,8 +123,8 @@ export function replayEntriesAsEvents(
|
|
|
108
123
|
|
|
109
124
|
// Generic custom ENTRY (pi.appendEntry) — same change. Synthesizes the
|
|
110
125
|
// `custom_entry` protocol event the bridge forwards live, so replay and
|
|
111
|
-
// live reduce into the same row shape.
|
|
112
|
-
// seq-sorted path above and never
|
|
126
|
+
// live reduce into the same row shape. Plugin-declared types take their
|
|
127
|
+
// seq-sorted path above (or stay hidden) and never reach this arm.
|
|
113
128
|
|
|
114
129
|
if (entry.type === "message" && entry.message) {
|
|
115
130
|
const msg = entry.message;
|
|
@@ -248,7 +263,7 @@ export function replayEntriesAsEvents(
|
|
|
248
263
|
}));
|
|
249
264
|
}
|
|
250
265
|
|
|
251
|
-
if (entry.type === "custom" && entry.customType
|
|
266
|
+
if (entry.type === "custom" && !hiddenTypes.has(entry.customType)) {
|
|
252
267
|
messages.push(makeEvent(sessionId, "custom_entry", ts, {
|
|
253
268
|
customType: entry.customType,
|
|
254
269
|
data: entry.data,
|
|
@@ -294,14 +309,15 @@ export function replayEntriesAsEvents(
|
|
|
294
309
|
}));
|
|
295
310
|
}
|
|
296
311
|
|
|
297
|
-
// Emit
|
|
298
|
-
// matches seq, but parallel
|
|
299
|
-
// replay —
|
|
300
|
-
// not matter; only seq order WITHIN
|
|
301
|
-
|
|
302
|
-
for (const rec of
|
|
312
|
+
// Emit declared plugin records sorted by seq (defensive: file order already
|
|
313
|
+
// matches seq, but parallel producers emit concurrently). Appended after
|
|
314
|
+
// message replay — plugin and message reducers are independent, so relative
|
|
315
|
+
// order does not matter; only seq order WITHIN plugin records does.
|
|
316
|
+
pluginEntryRecords.sort((a, b) => a.seq - b.seq);
|
|
317
|
+
for (const rec of pluginEntryRecords) {
|
|
303
318
|
messages.push(makeEvent(sessionId, rec.eventType, rec.ts, (rec.data ?? {}) as Record<string, unknown>));
|
|
304
319
|
}
|
|
320
|
+
if (opts?.stats) opts.stats.pluginEntriesReplayed += pluginEntryRecords.length;
|
|
305
321
|
|
|
306
322
|
return messages;
|
|
307
323
|
}
|