@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,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolvePiShell — which `bash.exe` pi-coding-agent would pick on Windows, so
|
|
3
|
+
* diagnostics report what the agent will actually run (not what the dashboard
|
|
4
|
+
* would like it to run).
|
|
5
|
+
*
|
|
6
|
+
* Replica of pi-coding-agent 1.5.0 `getShellConfig()` with no `shellPath`
|
|
7
|
+
* (dist/utils/shell.js — re-check on every pi bump; the build gate
|
|
8
|
+
* assert-bundled-bash-resolvable.mjs compares this replica to the shipped pi):
|
|
9
|
+
* 1. `%ProgramFiles%\Git\bin\bash.exe`, then `%ProgramFiles(x86)%\Git\bin\bash.exe`
|
|
10
|
+
* — first that exists;
|
|
11
|
+
* 2. else the first `where bash.exe` hit that exists — modelled as the first
|
|
12
|
+
* PATH directory holding `bash.exe` (`where` lists only existing files, in
|
|
13
|
+
* PATH order; it also searches the process cwd first, a documented residual);
|
|
14
|
+
* 3. else none (pi throws "No bash shell found").
|
|
15
|
+
* pi never looks for `sh.exe`.
|
|
16
|
+
*
|
|
17
|
+
* Pure: env + fs are injected. Contains NO bundled-git path literals (it only
|
|
18
|
+
* scans PATH), so it stays outside no-hardcoded-bundled-git-paths.test.ts.
|
|
19
|
+
*
|
|
20
|
+
* Existence mirrors pi's `shellPathExists` (`accessSync(F_OK)`, which on Windows
|
|
21
|
+
* also accepts runnable Store aliases that `existsSync` rejects). The WSL-launcher
|
|
22
|
+
* check is pi's `isLegacyWslBashPath` (1.4.0+), `SystemRoot`-aware, classified
|
|
23
|
+
* against the spawn env.
|
|
24
|
+
*
|
|
25
|
+
* See change: fix-windows-bundled-bash-exe, update-pi-core-1-5-adopt-apis.
|
|
26
|
+
*/
|
|
27
|
+
import { accessSync, constants } from "node:fs";
|
|
28
|
+
import path from "node:path";
|
|
29
|
+
|
|
30
|
+
export interface ResolvedPiShell {
|
|
31
|
+
path: string;
|
|
32
|
+
/** pi treats System32/Sysnative bash.exe as the WSL launcher (stdin transport). */
|
|
33
|
+
isWslLauncher: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ResolvePiShellOpts {
|
|
37
|
+
/** Spawn env the agent process would receive. */
|
|
38
|
+
env: NodeJS.ProcessEnv;
|
|
39
|
+
/** Override the existence check (default: pi's `accessSync(F_OK)`) for tests. */
|
|
40
|
+
exists?: (p: string) => boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** pi's shell existence check (`shellPathExists`): `accessSync(p, F_OK)`, false on any error. */
|
|
44
|
+
function piPathExists(p: string): boolean {
|
|
45
|
+
try {
|
|
46
|
+
accessSync(p, constants.F_OK);
|
|
47
|
+
return true;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* pi's `isLegacyWslBashPath` (1.4.0+): with `SystemRoot` set (case-insensitive
|
|
55
|
+
* key), only `<SystemRoot>\System32\bash.exe` and `<SystemRoot>\Sysnative\bash.exe`
|
|
56
|
+
* are the launcher, and a `SystemRoot` that is not drive-absolute means "not the
|
|
57
|
+
* launcher". The fixed `<drive>:\windows\(system32|sysnative)\bash.exe` pattern is
|
|
58
|
+
* only the fallback when `SystemRoot` is unset.
|
|
59
|
+
*/
|
|
60
|
+
export function isWslLauncherBash(p: string, env: NodeJS.ProcessEnv): boolean {
|
|
61
|
+
const win32 = path.win32;
|
|
62
|
+
const normalized = win32.normalize(p).toLowerCase();
|
|
63
|
+
const systemRoot = envGet(env, "SystemRoot");
|
|
64
|
+
if (systemRoot) {
|
|
65
|
+
if (!/^[a-z]:[\\/]/i.test(systemRoot)) return false;
|
|
66
|
+
return ["System32", "Sysnative"].some(
|
|
67
|
+
(dir) => normalized === win32.join(systemRoot, dir, "bash.exe").toLowerCase(),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return /^[a-z]:\\windows\\(?:system32|sysnative)\\bash\.exe$/.test(normalized);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Case-insensitive env lookup (Windows env keys are case-insensitive). */
|
|
74
|
+
function envGet(env: NodeJS.ProcessEnv, name: string): string | undefined {
|
|
75
|
+
const lower = name.toLowerCase();
|
|
76
|
+
for (const key of Object.keys(env)) {
|
|
77
|
+
if (key.toLowerCase() === lower) {
|
|
78
|
+
const v = env[key];
|
|
79
|
+
if (typeof v === "string" && v !== "") return v;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resolvePiShell(opts: ResolvePiShellOpts): ResolvedPiShell | null {
|
|
86
|
+
const exists = opts.exists ?? piPathExists;
|
|
87
|
+
const join = path.win32.join;
|
|
88
|
+
const found = (p: string): ResolvedPiShell => ({ path: p, isWslLauncher: isWslLauncherBash(p, opts.env) });
|
|
89
|
+
|
|
90
|
+
for (const key of ["ProgramFiles", "ProgramFiles(x86)"]) {
|
|
91
|
+
const root = envGet(opts.env, key);
|
|
92
|
+
if (!root) continue;
|
|
93
|
+
const candidate = `${root}\\Git\\bin\\bash.exe`;
|
|
94
|
+
if (exists(candidate)) return found(candidate);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const pathValue = envGet(opts.env, "PATH") ?? "";
|
|
98
|
+
for (const raw of pathValue.split(";")) {
|
|
99
|
+
const dir = raw.trim().replace(/^"(.*)"$/, "$1");
|
|
100
|
+
if (!dir) continue;
|
|
101
|
+
const candidate = join(dir, "bash.exe");
|
|
102
|
+
if (exists(candidate)) return found(candidate);
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
export type GitSource = "host" | "bundled";
|
|
20
20
|
export type WindowsGitSourceSetting = "auto" | "host" | "bundled";
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Windows-only: where `usr/bin` of the bundled git tree sits on the spawn PATH
|
|
24
|
+
* (decides which `bash.exe` pi resolves). No effect unless the git source is
|
|
25
|
+
* "bundled". See change: fix-windows-bundled-bash-exe.
|
|
26
|
+
*/
|
|
27
|
+
export type WindowsBashSourceSetting = "bundled" | "host";
|
|
28
|
+
|
|
22
29
|
export interface SelectGitSourceOpts {
|
|
23
30
|
/** Config value. Default "auto". */
|
|
24
31
|
setting?: WindowsGitSourceSetting;
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* `process.execPath` everywhere else. Total by construction.
|
|
25
25
|
*
|
|
26
26
|
* The gate: satisfies the spawned pi copy's `engines.node` floor (read from
|
|
27
|
-
* the resolved pi entry, falling back to the canonical `
|
|
27
|
+
* the resolved pi entry, falling back to the canonical `MIN_PI_SPAWN_NODE`)
|
|
28
28
|
* AND is not in the nodejs/node#58515 affected range. The `<27` cap is the
|
|
29
29
|
* SERVER's tested range, not a spawn constraint — a cap-excess candidate is
|
|
30
30
|
* ACCEPTED and flagged so Doctor can note it informationally.
|
|
@@ -49,12 +49,14 @@ import { getManagedDir } from "../managed-paths.js";
|
|
|
49
49
|
import {
|
|
50
50
|
isAffectedNode,
|
|
51
51
|
isAtOrAboveEnginesCap,
|
|
52
|
-
|
|
52
|
+
isUsableNodeVersion,
|
|
53
|
+
MIN_PI_SPAWN_NODE,
|
|
53
54
|
meetsFloor,
|
|
55
|
+
SERVER_ENGINES_RANGE,
|
|
54
56
|
} from "../node-version.js";
|
|
55
57
|
import { isPiCodingAgentName } from "../pi-installs/candidates.js";
|
|
56
58
|
import { whichSync, whichViaLoginShell } from "./binary-lookup.js";
|
|
57
|
-
import { spawnSync } from "./exec.js";
|
|
59
|
+
import { execFileAsync, spawnSync } from "./exec.js";
|
|
58
60
|
|
|
59
61
|
// ── Classification (design D4 — vendored from manage-node-runtime-updates) ──
|
|
60
62
|
|
|
@@ -135,7 +137,7 @@ export interface VersionGateResult {
|
|
|
135
137
|
* The step-2 spawn gate: passes the pi floor AND not in the nodejs/node#58515
|
|
136
138
|
* affected range. Cap excess is accepted (with `capExceeded`) — see the module
|
|
137
139
|
* doc comment. Zero version literals here: the floor comes from the caller
|
|
138
|
-
* (the spawned pi copy's engines, or `
|
|
140
|
+
* (the spawned pi copy's engines, or `MIN_PI_SPAWN_NODE`), the affected
|
|
139
141
|
* range and the cap from `node-version.ts`.
|
|
140
142
|
*/
|
|
141
143
|
export function evaluateVersionGate(version: string, floor: string): VersionGateResult {
|
|
@@ -163,7 +165,7 @@ export interface PiEnginesFloor {
|
|
|
163
165
|
* Extract the floor term from an `engines.node` range. Supports the shapes
|
|
164
166
|
* that occur in practice: `>=X.Y.Z` (optionally with a `<cap` term), `^X`,
|
|
165
167
|
* `~X.Y`. Anything else (OR ranges, `*`, garbage, empty) is unreadable →
|
|
166
|
-
* null → the caller falls back to `
|
|
168
|
+
* null → the caller falls back to `MIN_PI_SPAWN_NODE`. Strictness is the
|
|
167
169
|
* point: a mis-parsed floor silently changes which Nodes the ladder accepts.
|
|
168
170
|
*/
|
|
169
171
|
export function parseEnginesFloor(range: string): string | null {
|
|
@@ -189,13 +191,13 @@ export function parseEnginesFloor(range: string): string | null {
|
|
|
189
191
|
* Read pi's declared Node floor from the pi copy that will actually be
|
|
190
192
|
* spawned: walk UP from the resolved pi entry to the nearest `package.json`
|
|
191
193
|
* whose `name` is a pi-coding-agent package, parse `engines.node`, and fall
|
|
192
|
-
* back to the canonical `
|
|
194
|
+
* back to the canonical `MIN_PI_SPAWN_NODE` on anything unreadable. The
|
|
193
195
|
* walk only ever climbs the GIVEN entry's ancestor chain — a global pi
|
|
194
196
|
* elsewhere on the machine is never consulted (which copy spawns is the tool
|
|
195
197
|
* registry's orthogonal axis).
|
|
196
198
|
*/
|
|
197
199
|
export function readPiEnginesFloor(piEntry?: string | null): PiEnginesFloor {
|
|
198
|
-
const fallback: PiEnginesFloor = { floor:
|
|
200
|
+
const fallback: PiEnginesFloor = { floor: MIN_PI_SPAWN_NODE, source: "fallback" };
|
|
199
201
|
if (!piEntry) return fallback;
|
|
200
202
|
|
|
201
203
|
const start = realpathOrNull(piEntry);
|
|
@@ -742,6 +744,190 @@ export function resolveSpawnRuntime(opts: ResolveSpawnRuntimeOpts = {}): Resolve
|
|
|
742
744
|
);
|
|
743
745
|
}
|
|
744
746
|
|
|
747
|
+
// ── Server-spawn runtime resolution (change raise-node-floor-to-26, D4/D5) ──
|
|
748
|
+
|
|
749
|
+
/** Which candidate source a server-mode resolution step came from. */
|
|
750
|
+
export type ServerRuntimeStep = "override" | "path" | "version-manager" | "managed" | "own-runtime";
|
|
751
|
+
|
|
752
|
+
export interface ServerRuntimeCandidate {
|
|
753
|
+
step: ServerRuntimeStep;
|
|
754
|
+
/** Version-manager name (`nvm`, `volta`, …) for `step === "version-manager"`. */
|
|
755
|
+
manager?: string;
|
|
756
|
+
/** Candidate binary path; absent when the source had no hit. */
|
|
757
|
+
candidate?: string;
|
|
758
|
+
/** Version reported by the candidate (raw `--version` output when unparseable). */
|
|
759
|
+
version?: string;
|
|
760
|
+
outcome: "selected" | "skipped" | "not-found";
|
|
761
|
+
reason?: string;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export type ServerRuntimeResolution =
|
|
765
|
+
| {
|
|
766
|
+
resolved: true;
|
|
767
|
+
nodeBinary: string;
|
|
768
|
+
version: string;
|
|
769
|
+
step: ServerRuntimeStep;
|
|
770
|
+
manager?: string;
|
|
771
|
+
/** The required range the gate enforced (`>=26.0.0 <27`). */
|
|
772
|
+
range: string;
|
|
773
|
+
trail: ServerRuntimeCandidate[];
|
|
774
|
+
}
|
|
775
|
+
| { resolved: false; range: string; trail: ServerRuntimeCandidate[] };
|
|
776
|
+
|
|
777
|
+
export interface ResolveServerRuntimeOpts {
|
|
778
|
+
/** Step 1: `runtime.override` (default: read from `~/.pi/dashboard/config.json`). */
|
|
779
|
+
overrideBinary?: string | null;
|
|
780
|
+
configPath?: string;
|
|
781
|
+
/**
|
|
782
|
+
* Step 5: the starter's own runtime — pi's `process.execPath` +
|
|
783
|
+
* `process.version` for the bridge, Electron's executable + its embedded
|
|
784
|
+
* `process.versions.node` for the Electron app. Its version is read from
|
|
785
|
+
* the running process and NEVER probed. Default: this process.
|
|
786
|
+
*/
|
|
787
|
+
ownRuntime?: { binary: string; version: string } | null;
|
|
788
|
+
managedDir?: string;
|
|
789
|
+
homedir?: string;
|
|
790
|
+
platform?: NodeJS.Platform;
|
|
791
|
+
env?: NodeJS.ProcessEnv;
|
|
792
|
+
pathWhich?: (name: string, env?: NodeJS.ProcessEnv) => string | null;
|
|
793
|
+
/** Raw `node --version` output for a binary, or null on failure/timeout. */
|
|
794
|
+
versionProbe?: (binary: string) => Promise<string | null>;
|
|
795
|
+
exists?: (p: string) => boolean;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Default server-mode probe: `<binary> --version` with a fixed argv and NO
|
|
800
|
+
* shell (execFile). `ELECTRON_RUN_AS_NODE=1` keeps an Electron binary from
|
|
801
|
+
* opening a GUI. Raw trimmed stdout, or null on non-zero exit / timeout.
|
|
802
|
+
*/
|
|
803
|
+
export async function defaultServerVersionProbe(binary: string): Promise<string | null> {
|
|
804
|
+
try {
|
|
805
|
+
const { stdout } = await execFileAsync(binary, ["--version"], {
|
|
806
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
807
|
+
windowsHide: true,
|
|
808
|
+
env: { ...(process.env ?? {}), ELECTRON_RUN_AS_NODE: "1" },
|
|
809
|
+
});
|
|
810
|
+
return String(stdout).trim() || null;
|
|
811
|
+
} catch {
|
|
812
|
+
return null;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/** Every existing version-manager default, in probe order (nvm, volta, asdf, mise, fnm). */
|
|
817
|
+
function vmDefaultNodes(home: string, exists: (p: string) => boolean): VmDefaultHit[] {
|
|
818
|
+
const hits: VmDefaultHit[] = [];
|
|
819
|
+
const nvm = nvmDefaultNode(home);
|
|
820
|
+
if (nvm && exists(nvm.binary)) hits.push(nvm);
|
|
821
|
+
for (const probe of VM_SHIM_PROBES) {
|
|
822
|
+
const binary = path.join(home, ...probe.rel);
|
|
823
|
+
if (exists(binary)) hits.push({ binary, manager: probe.manager });
|
|
824
|
+
}
|
|
825
|
+
return hits;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Resolve the Node binary that will run the dashboard SERVER for a starter
|
|
830
|
+
* that cannot rely on a known-good runtime (bridge auto-start, Electron with
|
|
831
|
+
* no bundled Node). Same probes as the pi-session ladder, gated on the server
|
|
832
|
+
* engines range (`isUsableNodeVersion`) instead of pi's floor. Order:
|
|
833
|
+
* override → first `node` on PATH → every version-manager default →
|
|
834
|
+
* managed → the starter's own runtime (version from the running process).
|
|
835
|
+
*
|
|
836
|
+
* NOT total: when nothing qualifies it returns `{ resolved: false }` with
|
|
837
|
+
* every candidate and its skip reason. NEVER invokes a shell (no login-shell
|
|
838
|
+
* rung) and probes each distinct candidate path at most once.
|
|
839
|
+
*/
|
|
840
|
+
export async function resolveServerRuntime(
|
|
841
|
+
opts: ResolveServerRuntimeOpts = {},
|
|
842
|
+
): Promise<ServerRuntimeResolution> {
|
|
843
|
+
const platform = opts.platform ?? process.platform;
|
|
844
|
+
const homedir = opts.homedir ?? os.homedir();
|
|
845
|
+
const managedDir = opts.managedDir ?? getManagedDir();
|
|
846
|
+
const exists = opts.exists ?? existsSync;
|
|
847
|
+
const pathWhich = opts.pathWhich ?? ((name: string) => whichSync(name));
|
|
848
|
+
const probe = opts.versionProbe ?? defaultServerVersionProbe;
|
|
849
|
+
const own =
|
|
850
|
+
opts.ownRuntime === undefined ? { binary: process.execPath, version: process.version } : opts.ownRuntime;
|
|
851
|
+
const range = SERVER_ENGINES_RANGE;
|
|
852
|
+
|
|
853
|
+
const trail: ServerRuntimeCandidate[] = [];
|
|
854
|
+
const probed = new Map<string, Promise<string | null>>();
|
|
855
|
+
|
|
856
|
+
const gate = (version: string): string | null => {
|
|
857
|
+
if (!/^v?\d+\.\d+\.\d+(?:[-+]\S*)?$/.test(version)) return `unparseable version output "${version}"`;
|
|
858
|
+
return isUsableNodeVersion(version) ? null : `outside server engines range ${range} (found ${version})`;
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
type Cand = { step: ServerRuntimeStep; manager?: string; binary: string | null; ownVersion?: string };
|
|
862
|
+
const attempt = async (c: Cand): Promise<ServerRuntimeResolution | null> => {
|
|
863
|
+
const base = { step: c.step, ...(c.manager ? { manager: c.manager } : {}) };
|
|
864
|
+
if (!c.binary) {
|
|
865
|
+
trail.push({ ...base, outcome: "not-found" });
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
if (!exists(c.binary)) {
|
|
869
|
+
trail.push({ ...base, candidate: c.binary, outcome: "not-found", reason: "binary does not exist" });
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
let version: string | null;
|
|
873
|
+
if (c.ownVersion !== undefined) {
|
|
874
|
+
version = c.ownVersion;
|
|
875
|
+
} else {
|
|
876
|
+
let pending = probed.get(c.binary);
|
|
877
|
+
if (!pending) {
|
|
878
|
+
pending = probe(c.binary);
|
|
879
|
+
probed.set(c.binary, pending);
|
|
880
|
+
}
|
|
881
|
+
version = await pending;
|
|
882
|
+
}
|
|
883
|
+
if (!version) {
|
|
884
|
+
trail.push({ ...base, candidate: c.binary, outcome: "skipped", reason: "version probe failed or timed out" });
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
const reason = gate(version);
|
|
888
|
+
if (reason) {
|
|
889
|
+
trail.push({ ...base, candidate: c.binary, version, outcome: "skipped", reason });
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
trail.push({ ...base, candidate: c.binary, version, outcome: "selected" });
|
|
893
|
+
return { resolved: true, nodeBinary: c.binary, version, ...base, range, trail };
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
const overrideBinary =
|
|
897
|
+
opts.overrideBinary !== undefined ? opts.overrideBinary : readRuntimeOverride(opts.configPath);
|
|
898
|
+
const candidates: Array<() => Cand[]> = [
|
|
899
|
+
() => [{ step: "override", binary: overrideBinary ?? null }],
|
|
900
|
+
() => [{ step: "path", binary: pathWhich("node", opts.env) }],
|
|
901
|
+
() => {
|
|
902
|
+
const hits = vmDefaultNodes(homedir, exists);
|
|
903
|
+
return hits.length
|
|
904
|
+
? hits.map((h) => ({ step: "version-manager" as const, manager: h.manager, binary: h.binary }))
|
|
905
|
+
: [{ step: "version-manager" as const, binary: null }];
|
|
906
|
+
},
|
|
907
|
+
() => [{ step: "managed", binary: managedNodePath(managedDir, platform) }],
|
|
908
|
+
() => [{ step: "own-runtime", binary: own?.binary ?? null, ownVersion: own?.version }],
|
|
909
|
+
];
|
|
910
|
+
for (const source of candidates) {
|
|
911
|
+
for (const c of source()) {
|
|
912
|
+
const hit = await attempt(c);
|
|
913
|
+
if (hit) return hit;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return { resolved: false, range, trail };
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/** One-line human summary of a server-mode resolution trail (logs / notices). */
|
|
920
|
+
export function describeServerRuntimeTrail(trail: readonly ServerRuntimeCandidate[]): string {
|
|
921
|
+
return trail
|
|
922
|
+
.map((t) => {
|
|
923
|
+
const name = t.manager ? `${t.step}:${t.manager}` : t.step;
|
|
924
|
+
const where = t.candidate ? ` ${t.candidate}` : "";
|
|
925
|
+
const ver = t.version ? ` (${t.version})` : "";
|
|
926
|
+
return `${name}${where}${ver} ${t.outcome}${t.reason ? `: ${t.reason}` : ""}`;
|
|
927
|
+
})
|
|
928
|
+
.join("; ");
|
|
929
|
+
}
|
|
930
|
+
|
|
745
931
|
// ── Pi entry derivation (design D2 — the gate reads THE spawned pi copy) ────
|
|
746
932
|
|
|
747
933
|
/**
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request-`cwd` parsing + admission for plugin REST routes (automation, flows).
|
|
3
|
+
*
|
|
4
|
+
* One boundary for the three questions a route asks of a caller-supplied `cwd`,
|
|
5
|
+
* in a fixed order, all BEFORE any filesystem / git access under it:
|
|
6
|
+
* 1. shape — a present value that is not a single string → 400 `invalid_cwd`
|
|
7
|
+
* (array from `?cwd=a&cwd=b`, JSON object / number / boolean);
|
|
8
|
+
* 2. presence — absent or `""` on a route that needs a folder → 400 `cwd_required`
|
|
9
|
+
* (never defaulted to the server process cwd);
|
|
10
|
+
* 3. admission — a supplied cwd is decided by the tri-state {@link admitCwd}:
|
|
11
|
+
* refuse → 403 (existing plugin refusal body), indeterminate →
|
|
12
|
+
* 503 `cwd-admission-unavailable` + `Retry-After: 1`.
|
|
13
|
+
* `admitCwd` is never called for outcomes 1 and 2.
|
|
14
|
+
*
|
|
15
|
+
* The caller releases the admission token in its handler `finally` (`release()`).
|
|
16
|
+
* See change: harden-git-terminal-plugin-boundaries (S1r).
|
|
17
|
+
*/
|
|
18
|
+
import { type AdmitCwdOptions, admissionAllows, admitCwd, releaseAdmission } from "./cwd-guard.js";
|
|
19
|
+
|
|
20
|
+
export interface RouteCwdOptions {
|
|
21
|
+
/** `true` → an absent or empty cwd is `cwd_required`; `false` → it resolves to `cwd: undefined`. */
|
|
22
|
+
required: boolean;
|
|
23
|
+
/** Live admit set, read on every request (never cached here). Fail-closed default: nothing known. */
|
|
24
|
+
knownCwds?: () => string[];
|
|
25
|
+
/** `admitCwd` options (the host's throttled `onIndeterminate` logger; test seams). */
|
|
26
|
+
admitOptions?: AdmitCwdOptions;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RouteCwdRefusal {
|
|
30
|
+
ok: false;
|
|
31
|
+
status: number;
|
|
32
|
+
body: Record<string, unknown>;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type RouteCwdResult = { ok: true; cwd: string | undefined; release: () => void } | RouteCwdRefusal;
|
|
37
|
+
|
|
38
|
+
const NO_KNOWN = (): string[] => [];
|
|
39
|
+
const NOOP = (): void => {};
|
|
40
|
+
|
|
41
|
+
const DENIED_REASON = "cwd is not a known session or pinned directory.";
|
|
42
|
+
const DENIED_HINT = "Pin this directory to allow it, or open a session rooted in it.";
|
|
43
|
+
|
|
44
|
+
/** Parse (shape → presence) then admit a request `cwd` for a plugin route. */
|
|
45
|
+
export async function admitRouteCwdParam(raw: unknown, opts: RouteCwdOptions): Promise<RouteCwdResult> {
|
|
46
|
+
// JSON `null` carries no value: same as absent.
|
|
47
|
+
if (raw !== undefined && raw !== null && typeof raw !== "string") {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
status: 400,
|
|
51
|
+
body: { error: "invalid_cwd", message: "cwd must be a single string" },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (raw === undefined || raw === null || raw === "") {
|
|
55
|
+
if (opts.required) {
|
|
56
|
+
return { ok: false, status: 400, body: { error: "cwd_required", message: "cwd is required" } };
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, cwd: undefined, release: NOOP };
|
|
59
|
+
}
|
|
60
|
+
const admission = await admitCwd(raw, opts.knownCwds ?? NO_KNOWN, opts.admitOptions);
|
|
61
|
+
if (admission.kind === "admit" && admissionAllows(admission, raw)) {
|
|
62
|
+
const { token } = admission;
|
|
63
|
+
return { ok: true, cwd: raw, release: () => releaseAdmission(token) };
|
|
64
|
+
}
|
|
65
|
+
if (admission.kind === "indeterminate") {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
status: 503,
|
|
69
|
+
body: {
|
|
70
|
+
error: "cwd-admission-unavailable",
|
|
71
|
+
message: "cwd admission could not be decided right now",
|
|
72
|
+
retryAfterMs: 1000,
|
|
73
|
+
},
|
|
74
|
+
headers: { "Retry-After": "1" },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
status: 403,
|
|
80
|
+
body: { error: "not-allowed", message: `cwd not allowed: ${raw}`, reason: DENIED_REASON, hint: DENIED_HINT },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The minimal reply surface {@link sendRouteCwdRefusal} needs (a Fastify reply satisfies it). */
|
|
85
|
+
interface ReplyLike {
|
|
86
|
+
code(status: number): unknown;
|
|
87
|
+
header(name: string, value: string): unknown;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Write a refusal onto `reply` and return its body (handlers `return` it). */
|
|
91
|
+
export function sendRouteCwdRefusal(reply: ReplyLike, refusal: RouteCwdRefusal): Record<string, unknown> {
|
|
92
|
+
for (const [k, v] of Object.entries(refusal.headers ?? {})) reply.header(k, v);
|
|
93
|
+
reply.code(refusal.status);
|
|
94
|
+
return refusal.body;
|
|
95
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview-egress origin helpers — pure, browser-safe.
|
|
3
|
+
*
|
|
4
|
+
* `canonicalHttpsOrigin` is the single canonical subject form of the
|
|
5
|
+
* `preview-egress` access plane; `isUngrantableEgressOrigin` decides which
|
|
6
|
+
* origins can NEVER be granted (loopback / private / LAN / wildcard-DNS names
|
|
7
|
+
* and the dashboard's own origins). Origin semantics — deliberately separate
|
|
8
|
+
* from the path-oriented `forbidden-subjects`.
|
|
9
|
+
*
|
|
10
|
+
* See change: improve-canvas-html-and-url-ux (design D7).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* WHATWG-canonical `https` origin: lowercase, punycode, trailing-dot stripped,
|
|
15
|
+
* default port elided. `null` for a non-https scheme, userinfo, or a
|
|
16
|
+
* non-parseable input.
|
|
17
|
+
*/
|
|
18
|
+
export function canonicalHttpsOrigin(input: string): string | null {
|
|
19
|
+
let u: URL;
|
|
20
|
+
try {
|
|
21
|
+
u = new URL(input);
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (u.protocol !== "https:") return null;
|
|
26
|
+
if (u.username || u.password) return null;
|
|
27
|
+
const host = u.hostname.replace(/\.+$/, "");
|
|
28
|
+
if (!host) return null;
|
|
29
|
+
return `https://${host}${u.port ? `:${u.port}` : ""}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Parse an IPv6 literal (no brackets) into 8 16-bit groups; null when malformed. */
|
|
33
|
+
function parseIpv6(addr: string): number[] | null {
|
|
34
|
+
let a = addr.toLowerCase();
|
|
35
|
+
const zone = a.indexOf("%");
|
|
36
|
+
if (zone >= 0) a = a.slice(0, zone);
|
|
37
|
+
// Trailing dotted-quad (IPv4-mapped / compatible forms).
|
|
38
|
+
const quad = a.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
39
|
+
if (quad) {
|
|
40
|
+
const o = quad.slice(1, 5).map(Number);
|
|
41
|
+
if (o.some((n) => n > 255)) return null;
|
|
42
|
+
a = `${a.slice(0, quad.index)}${((o[0] << 8) | o[1]).toString(16)}:${((o[2] << 8) | o[3]).toString(16)}`;
|
|
43
|
+
}
|
|
44
|
+
const halves = a.split("::");
|
|
45
|
+
if (halves.length > 2) return null;
|
|
46
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
47
|
+
const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
48
|
+
const fill = 8 - head.length - tail.length;
|
|
49
|
+
if (halves.length === 1 ? head.length !== 8 : fill < 1) return null;
|
|
50
|
+
const groups = [...head, ...Array(halves.length === 2 ? fill : 0).fill("0"), ...tail];
|
|
51
|
+
if (groups.length !== 8) return null;
|
|
52
|
+
const out: number[] = [];
|
|
53
|
+
for (const g of groups) {
|
|
54
|
+
if (!/^[0-9a-f]{1,4}$/.test(g)) return null;
|
|
55
|
+
out.push(Number.parseInt(g, 16));
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** True for loopback / unspecified / private / link-local / CGNAT IPv4. */
|
|
61
|
+
export function isPrivateIpv4(o: readonly number[]): boolean {
|
|
62
|
+
const [a, b] = o;
|
|
63
|
+
return (
|
|
64
|
+
a === 0 ||
|
|
65
|
+
a === 10 ||
|
|
66
|
+
a === 127 ||
|
|
67
|
+
(a === 100 && b >= 64 && b <= 127) ||
|
|
68
|
+
(a === 169 && b === 254) ||
|
|
69
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
70
|
+
(a === 192 && b === 168) ||
|
|
71
|
+
(a === 192 && b === 0) ||
|
|
72
|
+
a >= 224 // multicast / reserved / broadcast
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** True for unspecified / loopback / ULA / link-local / IPv4-mapped-or-compatible private IPv6. */
|
|
77
|
+
export function isPrivateIpv6(g: readonly number[]): boolean {
|
|
78
|
+
if (g.every((x) => x === 0)) return true; // ::
|
|
79
|
+
if (g.slice(0, 7).every((x) => x === 0) && g[7] === 1) return true; // ::1
|
|
80
|
+
if ((g[0] & 0xfe00) === 0xfc00) return true; // fc00::/7 ULA
|
|
81
|
+
if ((g[0] & 0xffc0) === 0xfe80) return true; // fe80::/10 link-local
|
|
82
|
+
// IPv4-mapped (::ffff:a.b.c.d) / IPv4-compatible (::a.b.c.d)
|
|
83
|
+
if (g.slice(0, 5).every((x) => x === 0) && (g[5] === 0xffff || g[5] === 0)) {
|
|
84
|
+
return isPrivateIpv4([g[6] >> 8, g[6] & 0xff, g[7] >> 8, g[7] & 0xff]);
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const INTERNAL_SUFFIXES = [".local", ".internal", ".lan", ".home.arpa", ".localhost"];
|
|
90
|
+
|
|
91
|
+
/** Hostname embeds an IPv4 pattern (`10.0.0.5.example.io`, `127-0-0-1.example.io`). */
|
|
92
|
+
function embedsIpv4(host: string): boolean {
|
|
93
|
+
return (
|
|
94
|
+
/(^|\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\.|$)/.test(host) ||
|
|
95
|
+
/(^|[.-])\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}($|[.-])/.test(host)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* True when `origin` must never be granted as a preview egress origin: not a
|
|
101
|
+
* canonical https origin; `localhost` / `*.localhost`; a loopback / private /
|
|
102
|
+
* link-local / CGNAT / ULA IP literal in any parsed form; a single-label host;
|
|
103
|
+
* an internal suffix; a host embedding an IPv4 pattern (structurally covers
|
|
104
|
+
* wildcard-DNS services); or one of the dashboard's own origins.
|
|
105
|
+
*/
|
|
106
|
+
export function isUngrantableEgressOrigin(
|
|
107
|
+
origin: string,
|
|
108
|
+
ownOrigins: Iterable<string> = [],
|
|
109
|
+
): boolean {
|
|
110
|
+
const canon = canonicalHttpsOrigin(origin);
|
|
111
|
+
if (!canon) return true;
|
|
112
|
+
const u = new URL(canon);
|
|
113
|
+
const host = u.hostname;
|
|
114
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
115
|
+
|
|
116
|
+
if (host.startsWith("[")) {
|
|
117
|
+
const g = parseIpv6(host.slice(1, -1));
|
|
118
|
+
if (!g || isPrivateIpv6(g)) return true;
|
|
119
|
+
} else if (/^\d+(\.\d+){0,3}$/.test(host) || /^0x/i.test(host)) {
|
|
120
|
+
// WHATWG already normalised any numeric form to dotted-quad.
|
|
121
|
+
const o = host.split(".").map(Number);
|
|
122
|
+
if (o.length !== 4 || o.some((n) => !Number.isInteger(n) || n > 255) || isPrivateIpv4(o)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
if (!host.includes(".")) return true; // single-label
|
|
127
|
+
if (INTERNAL_SUFFIXES.some((s) => host.endsWith(s))) return true;
|
|
128
|
+
if (embedsIpv4(host)) return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const own of ownOrigins) {
|
|
132
|
+
try {
|
|
133
|
+
if (new URL(own).origin === u.origin) return true;
|
|
134
|
+
} catch {
|
|
135
|
+
/* ignore malformed own origin */
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Extra IPv4 ranges that are never a public unicast peer (docs, benchmarking, 6to4 relay). */
|
|
142
|
+
function isReservedIpv4(o: readonly number[]): boolean {
|
|
143
|
+
const [a, b, c] = o;
|
|
144
|
+
return (
|
|
145
|
+
(a === 192 && b === 88 && c === 99) || // 192.88.99.0/24 6to4 relay
|
|
146
|
+
(a === 198 && (b === 18 || b === 19)) || // 198.18.0.0/15 benchmarking
|
|
147
|
+
(a === 198 && b === 51 && c === 100) || // 198.51.100.0/24 TEST-NET-2
|
|
148
|
+
(a === 203 && b === 0 && c === 113) // 203.0.113.0/24 TEST-NET-3
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Extra IPv6 ranges that are never a public unicast peer (design D12 3c). */
|
|
153
|
+
function isReservedIpv6(g: readonly number[]): boolean {
|
|
154
|
+
const zero = (from: number, to: number) => g.slice(from, to).every((x) => x === 0);
|
|
155
|
+
return (
|
|
156
|
+
(g[0] === 0x0100 && zero(1, 4)) || // 100::/64 discard-only
|
|
157
|
+
(g[0] === 0x2001 && g[1] === 0) || // 2001::/32 Teredo
|
|
158
|
+
(g[0] === 0x2001 && (g[1] & 0xfff0) === 0x0010) || // 2001:10::/28 ORCHID
|
|
159
|
+
(g[0] === 0x2001 && g[1] === 0x0db8) || // 2001:db8::/32 documentation
|
|
160
|
+
g[0] === 0x2002 || // 2002::/16 6to4
|
|
161
|
+
(g[0] === 0x0064 && g[1] === 0xff9b && (zero(2, 6) || g[2] === 1)) || // 64:ff9b::/96, 64:ff9b:1::/48
|
|
162
|
+
(zero(0, 4) && g[4] === 0xffff) || // ::ffff:0:0:0/96 SIIT-translated
|
|
163
|
+
(zero(0, 4) && g[4] === 0 && g[5] === 0xffff) || // ::ffff:0:0/96 IPv4-mapped (never a resolver answer)
|
|
164
|
+
zero(0, 6) || // ::/96 IPv4-compatible (deprecated)
|
|
165
|
+
(g[0] & 0xffc0) === 0xfec0 || // fec0::/10 site-local
|
|
166
|
+
(g[0] & 0xff00) === 0xff00 // ff00::/8 multicast
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* True only for a globally routable unicast IP literal (`dns.lookup` result).
|
|
172
|
+
* Built on {@link isPrivateIpv4}/{@link isPrivateIpv6} plus the documentation,
|
|
173
|
+
* benchmarking, transition and multicast ranges. Strips an IPv6 zone id and
|
|
174
|
+
* FAILS CLOSED on anything it cannot parse (empty, bracketed, hostnames,
|
|
175
|
+
* leading-zero octets).
|
|
176
|
+
*
|
|
177
|
+
* See change: rich-chat-links (design D12).
|
|
178
|
+
*/
|
|
179
|
+
export function isPublicUnicastAddress(ip: string): boolean {
|
|
180
|
+
if (typeof ip !== "string") return false;
|
|
181
|
+
const addr = ip.split("%")[0];
|
|
182
|
+
const v4 = addr.match(/^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})$/);
|
|
183
|
+
if (v4) {
|
|
184
|
+
const o = v4.slice(1, 5).map(Number);
|
|
185
|
+
if (o.some((n) => n > 255)) return false;
|
|
186
|
+
return !isPrivateIpv4(o) && !isReservedIpv4(o);
|
|
187
|
+
}
|
|
188
|
+
if (!addr.includes(":")) return false;
|
|
189
|
+
const g = parseIpv6(addr);
|
|
190
|
+
if (!g) return false;
|
|
191
|
+
return !isPrivateIpv6(g) && !isReservedIpv6(g);
|
|
192
|
+
}
|