@blackbelt-technology/pi-agent-dashboard 0.9.0 → 0.11.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 +2 -2
- package/README.md +85 -11
- package/docs/architecture.md +3020 -116
- package/package.json +31 -18
- package/packages/extension/package.json +10 -8
- package/packages/extension/src/ask-user-tool.ts +65 -3
- package/packages/extension/src/auto-session-namer.ts +190 -50
- package/packages/extension/src/bridge-handlers/dispatch.ts +504 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +229 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1069 -0
- package/packages/extension/src/bridge-handlers/ui-prompt-patch.ts +198 -0
- package/packages/extension/src/bridge-identity-log.ts +45 -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 +517 -2534
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +259 -16
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +294 -24
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/empty-actionable-guard.ts +8 -3
- package/packages/extension/src/flow-event-wiring.ts +1 -1
- package/packages/extension/src/followup-buffer.ts +1 -1
- package/packages/extension/src/followup-drain.ts +79 -0
- 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 +232 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +88 -0
- package/packages/extension/src/multiselect-list.ts +6 -2
- package/packages/extension/src/multiselect-polyfill.ts +2 -2
- package/packages/extension/src/openspec-cli-shim.ts +1 -1
- package/packages/extension/src/path-gate/decide.ts +15 -41
- package/packages/extension/src/path-gate/grant-cache.ts +3 -1
- package/packages/extension/src/path-gate/handler.ts +51 -2
- package/packages/extension/src/path-gate/index.ts +12 -1
- package/packages/extension/src/path-gate/resolve.ts +6 -124
- package/packages/extension/src/path-gate/roots.ts +4 -1
- package/packages/extension/src/path-gate/suppression.ts +4 -1
- package/packages/extension/src/path-gate/yolo-link.ts +104 -0
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +258 -25
- package/packages/extension/src/prompt-expander.ts +5 -1
- package/packages/extension/src/prompt-meta.ts +64 -0
- package/packages/extension/src/provider-register.ts +146 -38
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/role-model-tools.ts +47 -6
- package/packages/extension/src/server-auto-start.ts +13 -6
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +73 -50
- package/packages/extension/src/spawn-token.ts +46 -0
- package/packages/extension/src/stream-forward-buffer.ts +161 -0
- package/packages/extension/src/subagent-frame-buffer.ts +6 -2
- package/packages/extension/src/subagent-tick-throttle.ts +3 -1
- package/packages/extension/src/vault-delivery.ts +404 -0
- package/packages/extension/src/vault-forwarder.ts +128 -0
- package/packages/extension/src/vault-masker.ts +165 -0
- package/packages/extension/src/vault-redaction.ts +181 -0
- package/packages/extension/src/vcs-info.ts +5 -2
- package/packages/server/bin/pi-dashboard.mjs +26 -89
- package/packages/server/package.json +29 -15
- package/packages/server/src/access/access-grants.ts +79 -8
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +5 -1
- package/packages/server/src/access/agent-confirm-registry.ts +31 -13
- package/packages/server/src/access/agent-grant.ts +1 -1
- package/packages/server/src/access/agent-yolo.ts +91 -0
- package/packages/server/src/access/containment-gate.ts +82 -17
- package/packages/server/src/access/cwd-admission-log.ts +46 -0
- package/packages/server/src/access/cwd-verdict.ts +144 -0
- package/packages/server/src/access/grant-coordinator.ts +3 -1
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +407 -0
- package/packages/server/src/access/planes.ts +116 -2
- 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/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +127 -14
- package/packages/server/src/acp-bridge/acp-connection.ts +225 -0
- package/packages/server/src/acp-bridge/acp-restore.ts +41 -0
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +549 -0
- package/packages/server/src/acp-bridge/child-env.ts +73 -0
- package/packages/server/src/acp-bridge/event-log.ts +194 -0
- package/packages/server/src/acp-bridge/gateway-client.ts +136 -0
- package/packages/server/src/acp-bridge/local-bridge-socket.ts +67 -0
- package/packages/server/src/acp-bridge/local-host.ts +132 -0
- package/packages/server/src/acp-bridge/main.ts +118 -0
- package/packages/server/src/acp-bridge/models.ts +33 -0
- package/packages/server/src/acp-bridge/permission-bridge.ts +106 -0
- package/packages/server/src/acp-bridge/server-requests.ts +136 -0
- package/packages/server/src/acp-bridge/session-state.ts +127 -0
- package/packages/server/src/addons/addon-toggle-restore.ts +110 -0
- package/packages/server/src/addons/addons-catalog.ts +408 -0
- package/packages/server/src/addons/addons-folder-service.ts +347 -0
- package/packages/server/src/addons/addons-folder.ts +310 -0
- package/packages/server/src/addons/addons-service.ts +470 -0
- package/packages/server/src/addons/package-contents.ts +99 -0
- package/packages/server/src/addons/settings-entries.ts +120 -0
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/audit-log.ts +80 -0
- package/packages/server/src/auth/auth-plugin.ts +329 -97
- package/packages/server/src/auth/auth.ts +102 -11
- package/packages/server/src/auth/bearer-auth.ts +74 -12
- package/packages/server/src/auth/cors-origin.ts +86 -29
- package/packages/server/src/auth/csp-report-paths.ts +31 -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 +111 -9
- 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/host-admission.ts +26 -0
- package/packages/server/src/auth/host-gate.ts +6 -1
- package/packages/server/src/auth/local-credential.ts +258 -0
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +76 -22
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +298 -17
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/network-trust-telemetry.ts +126 -0
- package/packages/server/src/auth/node-guard.ts +43 -0
- package/packages/server/src/auth/operate-required.ts +126 -0
- package/packages/server/src/auth/passkey/challenge-store.ts +90 -0
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +109 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +232 -0
- package/packages/server/src/auth/passkey/passkey-service.ts +247 -0
- package/packages/server/src/auth/passkey/phone-signin.ts +211 -0
- package/packages/server/src/auth/passkey/requester.ts +83 -0
- package/packages/server/src/auth/passkey/rp-context.ts +98 -0
- package/packages/server/src/auth/passkey/user-directory.ts +348 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +324 -0
- 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-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +61 -9
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/radius-override.ts +13 -0
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +27 -11
- package/packages/server/src/auth/runtime-provider-catalogue.ts +107 -0
- package/packages/server/src/auth/scan-legacy-provider-ids.ts +80 -0
- 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 +197 -0
- package/packages/server/src/auth/trust-mode-boot.ts +93 -0
- package/packages/server/src/auth/trust-mode.ts +83 -0
- package/packages/server/src/auth/ws-ticket.ts +39 -1
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/auto-name-outcome-store.ts +4 -1
- package/packages/server/src/browse.ts +114 -2
- package/packages/server/src/browser-handlers/acp-guard.ts +79 -0
- package/packages/server/src/browser-handlers/directory-handler.ts +151 -6
- 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 +138 -63
- package/packages/server/src/browser-handlers/session-meta-handler.ts +16 -6
- package/packages/server/src/browser-handlers/spawn-choice.ts +99 -0
- package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli.ts +1063 -106
- package/packages/server/src/config-api.ts +166 -2
- package/packages/server/src/config-snapshot.ts +53 -1
- package/packages/server/src/directory-service.ts +545 -36
- package/packages/server/src/embed-lifecycle/caps.ts +35 -4
- package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +45 -4
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +195 -20
- package/packages/server/src/embed-lifecycle/lifecycle-metrics.ts +38 -0
- package/packages/server/src/embed-lifecycle/plugin-session-close.ts +123 -0
- package/packages/server/src/embed-lifecycle/quiescence.ts +29 -3
- package/packages/server/src/embed-lifecycle/reclaim-give-up.ts +54 -0
- package/packages/server/src/event-wiring.ts +349 -141
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +60 -15
- 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/worktree-init-trust.ts +91 -6
- package/packages/server/src/git-worktree/worktree-init.ts +7 -56
- package/packages/server/src/identity/host-resources.ts +3 -0
- package/packages/server/src/identity/http-road-classification.ts +31 -1
- package/packages/server/src/identity/identity-registration-tracker.ts +4 -1
- package/packages/server/src/identity/plugin-identity.ts +19 -0
- package/packages/server/src/identity/policy-registry.ts +4 -1
- package/packages/server/src/identity/resolver-registry.ts +12 -3
- package/packages/server/src/identity/ws-message-scope.ts +10 -0
- package/packages/server/src/identity/ws-road-classification.ts +10 -0
- package/packages/server/src/known-server-moves.ts +196 -0
- package/packages/server/src/lib/browse-roots.ts +137 -0
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/digest-gate.ts +82 -0
- package/packages/server/src/lib/eml.ts +3 -8
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/file-write-lock.ts +24 -0
- package/packages/server/src/lib/folder-project.ts +439 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +93 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/office-preview.ts +2 -3
- package/packages/server/src/lib/path-containment.ts +7 -0
- package/packages/server/src/lib/purify.ts +13 -5
- package/packages/server/src/lib/resolve-file-mention.ts +11 -9
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +16 -1
- package/packages/server/src/lifecycle/classify-dashboard-port.ts +134 -0
- package/packages/server/src/lifecycle/home-lock.ts +344 -130
- package/packages/server/src/lifecycle/home-rendezvous.ts +41 -11
- package/packages/server/src/lifecycle/recovery-server.ts +129 -6
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/capability-redact.ts +15 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +461 -0
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +93 -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 +21 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +209 -33
- package/packages/server/src/live-server/live-server-proxy.ts +326 -34
- package/packages/server/src/live-server/live-static.ts +228 -0
- package/packages/server/src/metrics/eventloop-spike-metrics.ts +2 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +27 -26
- package/packages/server/src/model-proxy/internal-registry.ts +6 -0
- package/packages/server/src/model-proxy/server-model-runtime.ts +6 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +111 -16
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +189 -11
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +126 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +286 -44
- package/packages/server/src/openspec/proposal-attach-naming.ts +5 -3
- package/packages/server/src/openspec/readiness.ts +9 -0
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +1002 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/package-health-scanner.ts +133 -0
- package/packages/server/src/package/package-manager-wrapper.ts +18 -2
- package/packages/server/src/package/provider-catalogue-cache.ts +17 -3
- package/packages/server/src/package/provider-probe.ts +13 -5
- package/packages/server/src/pairing/browser-gateway.ts +292 -16
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/paired-devices.ts +335 -22
- package/packages/server/src/pairing/pairing.ts +188 -31
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/subagent-resync-routing.ts +4 -1
- package/packages/server/src/pairing/ws-tier-gate.ts +34 -0
- package/packages/server/src/peer-servers.ts +77 -0
- package/packages/server/src/pending/pending-plugin-ref-registry.ts +57 -2
- package/packages/server/src/persistence/boot-state.ts +48 -1
- package/packages/server/src/persistence/memory-event-store.ts +216 -237
- package/packages/server/src/persistence/meta-persistence.ts +12 -1
- package/packages/server/src/persistence/preferences-store.ts +125 -7
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-upgrade-auth.ts +48 -22
- package/packages/server/src/pi/folder-commands.ts +141 -0
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/gateway-socket-bind.ts +9 -3
- package/packages/server/src/pi/gateway-transport-policy.ts +13 -0
- package/packages/server/src/pi/host-project-trust.ts +166 -33
- package/packages/server/src/pi/pi-gateway.ts +283 -29
- package/packages/server/src/pi/pi-resource-scanner.ts +15 -0
- package/packages/server/src/pi/resource-activation-toggle.ts +6 -0
- package/packages/server/src/pi/resource-toggle-trust.ts +34 -2
- package/packages/server/src/pi/session-skill-registry.ts +13 -3
- package/packages/server/src/pi/settings-write-lock.ts +32 -0
- package/packages/server/src/pi/trust-challenges.ts +38 -0
- package/packages/server/src/pi-agent-settings.ts +701 -100
- package/packages/server/src/pi-settings-themes.ts +104 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/questions/brief-generator.ts +138 -0
- package/packages/server/src/questions/brief-model.ts +55 -0
- package/packages/server/src/questions/brief-policy.ts +36 -0
- package/packages/server/src/questions/brief-prompt.ts +92 -0
- package/packages/server/src/questions/brief-runtime.ts +50 -0
- package/packages/server/src/questions/question-answer.ts +55 -0
- package/packages/server/src/questions/question-broadcast.ts +106 -0
- package/packages/server/src/questions/question-files.ts +128 -0
- package/packages/server/src/questions/question-routes.ts +126 -0
- package/packages/server/src/questions/question-snapshot.ts +150 -0
- package/packages/server/src/questions/question-stack.ts +57 -0
- package/packages/server/src/questions/question-store.ts +477 -0
- package/packages/server/src/routes/access-prompt-routes.ts +5 -3
- package/packages/server/src/routes/access-routes.ts +274 -6
- package/packages/server/src/routes/acme-routes.ts +190 -0
- package/packages/server/src/routes/acp-routes.ts +16 -0
- package/packages/server/src/routes/addons-routes.ts +221 -0
- 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 +620 -209
- package/packages/server/src/routes/file-write-binary-routes.ts +530 -0
- package/packages/server/src/routes/folder-project-routes.ts +105 -0
- package/packages/server/src/routes/git-routes.ts +334 -203
- package/packages/server/src/routes/grep-routes.ts +38 -14
- package/packages/server/src/routes/known-servers-routes.ts +433 -55
- package/packages/server/src/routes/live-server-routes.ts +438 -7
- package/packages/server/src/routes/local-proof-routes.ts +26 -7
- package/packages/server/src/routes/mermaid-repair-routes.ts +254 -0
- package/packages/server/src/routes/model-proxy-routes.ts +4 -2
- 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 +636 -55
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +86 -11
- package/packages/server/src/routes/pairing-routes.ts +303 -33
- package/packages/server/src/routes/pi-retry-routes.ts +18 -2
- package/packages/server/src/routes/pi-settings-routes.ts +264 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +146 -27
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/provider-auth-routes.ts +37 -7
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +33 -35
- package/packages/server/src/routes/session-routes.ts +100 -9
- package/packages/server/src/routes/system-routes.ts +286 -33
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +15 -2
- package/packages/server/src/runtime-overlay/runtime-update-checker.ts +11 -2
- package/packages/server/src/server.ts +1537 -246
- package/packages/server/src/services/attached-driver.ts +175 -0
- package/packages/server/src/services/change-notifier.ts +55 -0
- package/packages/server/src/services/cli-service.ts +450 -0
- package/packages/server/src/services/command-runner.ts +92 -0
- package/packages/server/src/services/definitions-store.ts +121 -0
- package/packages/server/src/services/driver.ts +112 -0
- package/packages/server/src/services/health.ts +94 -0
- package/packages/server/src/services/leases.ts +117 -0
- package/packages/server/src/services/log-text.ts +97 -0
- package/packages/server/src/services/native-driver.ts +283 -0
- package/packages/server/src/services/oci-driver.ts +590 -0
- package/packages/server/src/services/output-capture.ts +183 -0
- package/packages/server/src/services/paths.ts +82 -0
- package/packages/server/src/services/ports.ts +26 -0
- package/packages/server/src/services/routes.ts +140 -0
- package/packages/server/src/services/runtime-detect.ts +108 -0
- package/packages/server/src/services/secret-delivery.ts +61 -0
- package/packages/server/src/services/secrets-resolver.ts +145 -0
- package/packages/server/src/services/secrets-store.ts +137 -0
- package/packages/server/src/services/service-manager.ts +1565 -0
- package/packages/server/src/services/start-record.ts +66 -0
- package/packages/server/src/services/state-machine.ts +241 -0
- package/packages/server/src/session/archive-sweeper.ts +92 -3
- package/packages/server/src/session/custom-event-group-matcher.ts +4 -3
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +60 -0
- package/packages/server/src/session/name-provenance.ts +102 -0
- package/packages/server/src/session/open-tool-calls.ts +15 -6
- 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/session-api.ts +47 -12
- package/packages/server/src/session/session-archive.ts +56 -4
- package/packages/server/src/session/session-diff-cache.ts +11 -4
- package/packages/server/src/session/session-load-worker-pool.ts +4 -3
- package/packages/server/src/session/session-load-worker.ts +11 -2
- package/packages/server/src/session/session-scanner.ts +73 -3
- package/packages/server/src/session/session-to-meta.ts +15 -0
- package/packages/server/src/spawn-process/abort-spawned-run.ts +55 -0
- package/packages/server/src/spawn-process/acp-spawn.ts +131 -0
- package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
- package/packages/server/src/spawn-process/process-manager.ts +164 -30
- package/packages/server/src/spawn-process/restart-helper.ts +9 -8
- package/packages/server/src/spawn-process/server-pid.ts +16 -7
- package/packages/server/src/spawn-process/session-terminator.ts +218 -0
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +159 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +10 -1
- package/packages/server/src/terminal/terminal-manager.ts +75 -1
- package/packages/server/src/tls/cert-files.ts +228 -0
- package/packages/server/src/tls/cert-manager.ts +703 -0
- package/packages/server/src/tls/cert-store.ts +69 -0
- package/packages/server/src/tls/source-registry.ts +71 -0
- package/packages/server/src/tls/sources/acme/accounts.ts +76 -0
- package/packages/server/src/tls/sources/acme/acme-source.ts +508 -0
- package/packages/server/src/tls/sources/acme/config-projection.ts +34 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +185 -0
- package/packages/server/src/tls/sources/acme/dns.ts +303 -0
- package/packages/server/src/tls/sources/acme/e2e-overrides.ts +49 -0
- package/packages/server/src/tls/sources/acme/entry.ts +180 -0
- package/packages/server/src/tls/sources/acme/gc.ts +78 -0
- package/packages/server/src/tls/sources/acme/runtime.ts +51 -0
- package/packages/server/src/tls/sources/acme/solvers/acme-dns.ts +154 -0
- package/packages/server/src/tls/sources/acme/solvers/cloudflare.ts +147 -0
- package/packages/server/src/tls/sources/acme/types.ts +72 -0
- package/packages/server/src/tls/sources/tailscale-cert.ts +172 -0
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +94 -0
- package/packages/server/src/tls/tls-listener.ts +351 -0
- package/packages/server/src/tls/types.ts +80 -0
- package/packages/server/src/tunnel/tunnel-block-events.ts +4 -1
- package/packages/server/src/tunnel/tunnel-core.ts +4 -1
- package/packages/server/src/tunnel/tunnel-endpoints.ts +4 -0
- package/packages/server/src/tunnel-providers/tailscale.ts +27 -6
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +424 -0
- package/packages/server/src/vault/vault-grants.ts +260 -0
- package/packages/server/src/vault/vault-import.ts +161 -0
- package/packages/server/src/vault/vault-permissions.ts +39 -0
- package/packages/server/src/vault/vault-plugin-read.ts +64 -0
- package/packages/server/src/vault/vault-projects.ts +156 -0
- package/packages/server/src/vault/vault-routes.ts +277 -0
- package/packages/server/src/vault/vault-store.ts +371 -0
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/shared/package.json +5 -2
- package/packages/shared/src/acp/acp-config.ts +123 -0
- package/packages/shared/src/acp/normalize-v1.ts +92 -0
- package/packages/shared/src/acp/paths.ts +36 -0
- package/packages/shared/src/acp/to-dashboard-events.ts +533 -0
- package/packages/shared/src/acp/update-model.ts +574 -0
- package/packages/shared/src/anthropic-messages-source.ts +8 -0
- package/packages/shared/src/bind-reachability.ts +21 -2
- package/packages/shared/src/boot-state.ts +6 -0
- package/packages/shared/src/browser-host-identity.ts +49 -0
- package/packages/shared/src/browser-host-ipc.ts +107 -0
- package/packages/shared/src/browser-protocol.ts +533 -73
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +817 -51
- package/packages/shared/src/containment-guard.ts +35 -0
- package/packages/shared/src/custom-event-groups.ts +5 -2
- package/packages/shared/src/cwd-guard.ts +381 -1
- package/packages/shared/src/dashboard-paths.ts +12 -0
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
- package/packages/shared/src/dashboard-plugin/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +73 -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 +9 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +160 -3
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
- package/packages/shared/src/dashboard-plugin/project-identity.ts +42 -0
- package/packages/shared/src/dashboard-plugin/project-markers.ts +60 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +139 -2
- package/packages/shared/src/dashboard-plugin/slot-types.ts +72 -4
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +50 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +119 -134
- package/packages/shared/src/enabled-models-match.ts +47 -0
- package/packages/shared/src/event-forward-declaration.ts +187 -0
- package/packages/shared/src/file-kind.ts +54 -2
- package/packages/shared/src/git-worktree-helpers.ts +8 -4
- package/packages/shared/src/grammar-types.ts +3 -1
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/host-port.ts +34 -0
- package/packages/shared/src/launcher-origin.ts +26 -0
- package/packages/shared/src/live-server.ts +141 -0
- package/packages/shared/src/local-credential-proof.ts +219 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/markup-repair/asciidoc.ts +130 -0
- package/packages/shared/src/markup-repair/types.ts +13 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
- package/packages/shared/src/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +414 -45
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +213 -11
- package/packages/shared/src/openspec-status-all.ts +393 -0
- package/packages/shared/src/operate-required.ts +29 -0
- package/packages/shared/src/pairing-knock-client.ts +301 -0
- package/packages/shared/src/pairing-knock.ts +71 -0
- package/packages/shared/src/pairing-refusal.ts +32 -0
- package/packages/shared/src/path-containment-guard-name.ts +8 -0
- package/packages/shared/src/pi-settings-keys.ts +9 -0
- package/packages/shared/src/pi-settings-schema.ts +285 -0
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +198 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +90 -0
- package/packages/shared/src/pi-trust-mirror.ts +354 -0
- package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- 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 +210 -4
- package/packages/shared/src/platform/native-ts-hooks.mjs +93 -40
- package/packages/shared/src/platform/native-ts-register.mjs +22 -10
- package/packages/shared/src/platform/native-ts-tier.d.mts +1 -0
- package/packages/shared/src/platform/native-ts-tier.mjs +17 -0
- package/packages/shared/src/platform/node-spawn.ts +1 -2
- package/packages/shared/src/platform/openspec.ts +129 -31
- package/packages/shared/src/platform/process-scan.ts +199 -1
- package/packages/shared/src/platform/process.ts +99 -4
- package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-mechanism.ts +14 -2
- package/packages/shared/src/platform/ts-loader-select.d.mts +1 -7
- package/packages/shared/src/platform/ts-loader-select.mjs +14 -43
- package/packages/shared/src/plugin-bridge-register.ts +24 -1
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +138 -0
- package/packages/shared/src/project-name.ts +42 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +172 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +98 -23
- package/packages/shared/src/recovery-timing.ts +39 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/rest-api.ts +533 -3
- package/packages/shared/src/role-config-disk.ts +23 -0
- package/packages/shared/src/role-schema.ts +79 -0
- package/packages/shared/src/route-tiers.ts +181 -0
- 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/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +17 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +119 -8
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +21 -34
- package/packages/shared/src/server-pinning.ts +136 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/services/offers.ts +114 -0
- package/packages/shared/src/services/schema.ts +628 -0
- package/packages/shared/src/services/status.ts +169 -0
- package/packages/shared/src/session-meta.ts +59 -2
- package/packages/shared/src/session-name.ts +8 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/skill-block-parser.ts +14 -0
- package/packages/shared/src/source-matching.ts +5 -1
- package/packages/shared/src/state-replay.ts +19 -0
- package/packages/shared/src/terminal-safe.ts +24 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tls-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +31 -9
- package/packages/shared/src/tool-registry/index.ts +2 -2
- package/packages/shared/src/tool-registry/pi-tools.ts +32 -3
- package/packages/shared/src/tool-registry/strategies.ts +12 -11
- package/packages/shared/src/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +170 -9
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +88 -0
- package/packages/shared/src/vault-origin.ts +51 -0
- package/packages/shared/src/vault-project-key.ts +53 -0
- package/packages/shared/src/worktree-init-hook.ts +69 -0
- package/packages/shared/src/ws-message-tiers.ts +136 -0
- package/tsconfig.base.json +1 -0
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import {
|
|
26
26
|
type AcquireHooks,
|
|
27
27
|
acquireOrAttach,
|
|
28
|
+
isInstanceUnresponsiveError,
|
|
28
29
|
isLockDisabled,
|
|
29
30
|
type LockMetadata,
|
|
30
31
|
} from "./home-lock.js";
|
|
@@ -39,6 +40,8 @@ export interface EstablishRendezvousConfig {
|
|
|
39
40
|
version: string;
|
|
40
41
|
/** This instance's rendezvous id (see `instance-id.ts`). */
|
|
41
42
|
identity: string;
|
|
43
|
+
/** Host the server binds; recorded in the record when specific and non-loopback. */
|
|
44
|
+
bindHost?: string | null;
|
|
42
45
|
hooks?: AcquireHooks;
|
|
43
46
|
/** Test seam: skip signal-handler installation. Default `true`. */
|
|
44
47
|
installHandlers?: boolean;
|
|
@@ -84,21 +87,45 @@ export async function establishHomeRendezvous(
|
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
let mode: "acquired" | "attach" = "attach";
|
|
91
|
+
let meta: LockMetadata | null = null;
|
|
92
|
+
let release: (() => Promise<void>) | undefined;
|
|
93
|
+
let uninstall: (() => void) | undefined;
|
|
94
|
+
let timer: NodeJS.Timeout | undefined;
|
|
95
|
+
let checking = false;
|
|
96
|
+
|
|
97
|
+
const startPromotionTimer = () => {
|
|
98
|
+
if (intervalMs <= 0 || timer) return;
|
|
99
|
+
timer = setInterval(() => void checkNow(), intervalMs);
|
|
100
|
+
timer.unref?.();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A successor took our lock over (this process was frozen or starved, and
|
|
105
|
+
* noticed late). The lock and the record are the successor's now: stop acting
|
|
106
|
+
* as the HOME default and fall back to attach semantics. The handle already
|
|
107
|
+
* made its own release a no-op.
|
|
108
|
+
*/
|
|
109
|
+
const dropRole = () => {
|
|
110
|
+
if (mode !== "acquired") return;
|
|
111
|
+
log(`[home-lock] lost the rendezvous for this HOME to a successor (${config.identity}); continuing in attach mode.`);
|
|
112
|
+
mode = "attach";
|
|
113
|
+
release = undefined;
|
|
114
|
+
uninstall?.();
|
|
115
|
+
uninstall = undefined;
|
|
116
|
+
startPromotionTimer();
|
|
117
|
+
};
|
|
118
|
+
|
|
87
119
|
const acquireConfig = {
|
|
88
120
|
httpPort: config.httpPort,
|
|
89
121
|
piPort: config.piPort,
|
|
90
122
|
version: config.version,
|
|
91
123
|
identity: config.identity,
|
|
124
|
+
bindHost: config.bindHost,
|
|
92
125
|
hooks: config.hooks,
|
|
126
|
+
onCompromised: dropRole,
|
|
93
127
|
};
|
|
94
128
|
|
|
95
|
-
let mode: "acquired" | "attach" = "attach";
|
|
96
|
-
let meta: LockMetadata | null = null;
|
|
97
|
-
let release: (() => Promise<void>) | undefined;
|
|
98
|
-
let uninstall: (() => void) | undefined;
|
|
99
|
-
let timer: NodeJS.Timeout | undefined;
|
|
100
|
-
let checking = false;
|
|
101
|
-
|
|
102
129
|
const adopt = (result: Awaited<ReturnType<typeof acquireOrAttach>>) => {
|
|
103
130
|
mode = result.mode;
|
|
104
131
|
meta = result.meta;
|
|
@@ -130,6 +157,12 @@ export async function establishHomeRendezvous(
|
|
|
130
157
|
log(`[home-lock] promoted to rendezvous owner for this HOME (${config.identity}).`);
|
|
131
158
|
}
|
|
132
159
|
} catch (err) {
|
|
160
|
+
// An alive-but-silent (or still starting) owner is never taken over; stay
|
|
161
|
+
// attached and look again on the next tick.
|
|
162
|
+
if (isInstanceUnresponsiveError(err)) {
|
|
163
|
+
log(`[home-lock] owner is ${err.reason === "starting" ? "still starting" : "not responding"}; staying attached, retrying next tick.`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
133
166
|
// A mismatch means somebody else holds the HOME on our port; staying in
|
|
134
167
|
// attach mode is the conservative answer, not crashing a running server.
|
|
135
168
|
log(`[home-lock] promotion re-check failed: ${(err as Error).message ?? err}`);
|
|
@@ -138,10 +171,7 @@ export async function establishHomeRendezvous(
|
|
|
138
171
|
}
|
|
139
172
|
};
|
|
140
173
|
|
|
141
|
-
if (mode === "attach"
|
|
142
|
-
timer = setInterval(() => void checkNow(), intervalMs);
|
|
143
|
-
timer.unref?.();
|
|
144
|
-
}
|
|
174
|
+
if (mode === "attach") startPromotionTimer();
|
|
145
175
|
|
|
146
176
|
return {
|
|
147
177
|
get mode() {
|
|
@@ -12,16 +12,32 @@
|
|
|
12
12
|
* missing — and the recovery server itself would fail to load. Keep it
|
|
13
13
|
* dependency-free.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
import { spawn } from "node:child_process";
|
|
17
|
-
import
|
|
18
|
-
import path from "node:path";
|
|
19
|
-
import os from "node:os";
|
|
17
|
+
import crypto from "node:crypto";
|
|
20
18
|
import fs from "node:fs";
|
|
19
|
+
import http from "node:http";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
21
23
|
|
|
22
24
|
export interface RecoveryInfo {
|
|
23
25
|
/** Port to bind. */
|
|
24
26
|
port: number;
|
|
27
|
+
/**
|
|
28
|
+
* Address to bind. Defaults to loopback (`127.0.0.1`): the recovery server is
|
|
29
|
+
* unauthenticated and runs `npm install`, so it must never listen on all
|
|
30
|
+
* interfaces unless the operator explicitly configured the host.
|
|
31
|
+
* See change: harden-server-capability-bounds (B9).
|
|
32
|
+
*/
|
|
33
|
+
host?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The local IPC token (`~/.pi/dashboard/local/token`), when one exists. A caller
|
|
36
|
+
* presenting it in `X-Pi-Local-Token` may run the mutating actions from a
|
|
37
|
+
* non-loopback address. Passed in (not read here) to keep this module
|
|
38
|
+
* node-built-in only.
|
|
39
|
+
*/
|
|
40
|
+
localToken?: string | null;
|
|
25
41
|
/** The original error that prevented startup. */
|
|
26
42
|
error: Error;
|
|
27
43
|
/** Optional: extracted missing module identifier. */
|
|
@@ -30,6 +46,86 @@ export interface RecoveryInfo {
|
|
|
30
46
|
suggestedFix?: string;
|
|
31
47
|
}
|
|
32
48
|
|
|
49
|
+
/** Header carrying the local IPC token (mirrors `LOCAL_TOKEN_HEADER` in `auth/local-token.ts`). */
|
|
50
|
+
const LOCAL_TOKEN_HEADER = "x-pi-local-token";
|
|
51
|
+
|
|
52
|
+
const isLoopbackAddress = (addr: string | undefined): boolean =>
|
|
53
|
+
!!addr && (addr === "::1" || LOOPBACK_IPV4.test(addr) || LOOPBACK_IPV4.test(addr.replace(/^::ffff:/, "")));
|
|
54
|
+
|
|
55
|
+
/** Hostname part of a `Host` header / Origin URL (no port, no IPv6 brackets). */
|
|
56
|
+
const hostnameOf = (hostPort: string): string => {
|
|
57
|
+
const h = hostPort.trim().toLowerCase();
|
|
58
|
+
if (h.startsWith("[")) return h.slice(1, h.indexOf("]"));
|
|
59
|
+
return h.split(":")[0] ?? "";
|
|
60
|
+
};
|
|
61
|
+
// A literal IPv4 in 127.0.0.0/8 only: a DNS NAME such as `127.attacker.example` merely STARTS with
|
|
62
|
+
// "127." and is exactly what DNS rebinding presents (CodeRabbit r1).
|
|
63
|
+
const LOOPBACK_IPV4 = /^127(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/;
|
|
64
|
+
const isLoopbackName = (name: string): boolean => name === "localhost" || name === "::1" || LOOPBACK_IPV4.test(name);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Proxy / tunnel forwarding headers. An INLINE copy of the guard's extended
|
|
68
|
+
* list (`PLUGIN_PROXY_FORWARDING_HEADERS` in `auth/localhost-guard.ts`): this
|
|
69
|
+
* module may import only node built-ins, and a unit test pins the two equal.
|
|
70
|
+
*/
|
|
71
|
+
export const RECOVERY_FORWARDING_HEADERS = [
|
|
72
|
+
"x-forwarded-for",
|
|
73
|
+
"x-forwarded-host",
|
|
74
|
+
"x-forwarded-proto",
|
|
75
|
+
"x-real-ip",
|
|
76
|
+
"forwarded",
|
|
77
|
+
"via",
|
|
78
|
+
"x-forwarded-server",
|
|
79
|
+
"x-forwarded-port",
|
|
80
|
+
] as const;
|
|
81
|
+
|
|
82
|
+
/** `Host` header with the scheme's default port stripped, lower-cased (compare to `URL.host`). */
|
|
83
|
+
function normalisedHost(hostHeader: string, scheme: string): string {
|
|
84
|
+
const h = hostHeader.trim().toLowerCase();
|
|
85
|
+
const defaultPort = scheme === "https:" ? ":443" : scheme === "http:" ? ":80" : "";
|
|
86
|
+
return defaultPort && h.endsWith(defaultPort) ? h.slice(0, -defaultPort.length) : h;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Gate for the mutating recovery actions (`retry`, `reinstall`). The recovery
|
|
91
|
+
* server has no auth of its own, so a mutating request is accepted only when it
|
|
92
|
+
* (a) presents the local IPC token, or (b) comes from a loopback peer carrying
|
|
93
|
+
* NO proxy-forwarding header, a loopback `Host`, and either no `Origin` or an
|
|
94
|
+
* `Origin` that is the SAME origin as `Host`. Forwarding headers stop a tunnel
|
|
95
|
+
* relaying from loopback; the loopback `Host` stops DNS rebinding; same-origin
|
|
96
|
+
* (not "any loopback origin") stops a page served from another local port.
|
|
97
|
+
* See change: harden-server-capability-bounds (B9, D4).
|
|
98
|
+
*/
|
|
99
|
+
export function isRecoveryActionAllowed(
|
|
100
|
+
req: { remoteAddress: string | undefined; headers: Record<string, string | string[] | undefined> },
|
|
101
|
+
expectedToken: string | null | undefined,
|
|
102
|
+
): boolean {
|
|
103
|
+
const first = (v: string | string[] | undefined): string | undefined => (Array.isArray(v) ? v[0] : v);
|
|
104
|
+
|
|
105
|
+
const presented = first(req.headers[LOCAL_TOKEN_HEADER]);
|
|
106
|
+
if (expectedToken && presented) {
|
|
107
|
+
const a = Buffer.from(presented);
|
|
108
|
+
const b = Buffer.from(expectedToken);
|
|
109
|
+
if (a.length === b.length && crypto.timingSafeEqual(a, b)) return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!isLoopbackAddress(req.remoteAddress)) return false;
|
|
113
|
+
if (RECOVERY_FORWARDING_HEADERS.some((h) => req.headers[h] != null)) return false;
|
|
114
|
+
const host = first(req.headers.host);
|
|
115
|
+
if (!host || !isLoopbackName(hostnameOf(host))) return false;
|
|
116
|
+
const origin = first(req.headers.origin);
|
|
117
|
+
if (origin !== undefined) {
|
|
118
|
+
let parsed: URL;
|
|
119
|
+
try {
|
|
120
|
+
parsed = new URL(origin);
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (parsed.host === "" || parsed.host !== normalisedHost(host, parsed.protocol)) return false; // includes `Origin: null`
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
33
129
|
/**
|
|
34
130
|
* Extract the missing-module identifier from an `ERR_MODULE_NOT_FOUND` or
|
|
35
131
|
* legacy `MODULE_NOT_FOUND` error. Returns null if the error isn't of that
|
|
@@ -184,6 +280,9 @@ export function buildRecoveryHtml(info: RecoveryInfo): string {
|
|
|
184
280
|
button.secondary:hover { background: #4b5563; }
|
|
185
281
|
button:disabled { background: #9ca3af; cursor: not-allowed; }
|
|
186
282
|
#status { margin-top: 1rem; font-size: .9em; color: #4b5563; }
|
|
283
|
+
#refusal { margin-top: 1rem; padding: .6rem .75rem; border-radius: 6px; font-size: .9em;
|
|
284
|
+
background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
|
|
285
|
+
#refusal[hidden] { display: none; }
|
|
187
286
|
</style>
|
|
188
287
|
</head>
|
|
189
288
|
<body>
|
|
@@ -198,31 +297,41 @@ export function buildRecoveryHtml(info: RecoveryInfo): string {
|
|
|
198
297
|
<button id="reinstall" class="secondary">Reinstall dependencies</button>
|
|
199
298
|
</div>
|
|
200
299
|
<div id="status"></div>
|
|
300
|
+
<div id="refusal" role="alert" hidden></div>
|
|
201
301
|
<h3 style="margin-top: 1.5rem;">Error details</h3>
|
|
202
302
|
<pre>${stack}</pre>
|
|
203
303
|
</main>
|
|
204
304
|
<script>
|
|
205
305
|
const $ = (id) => document.getElementById(id);
|
|
206
306
|
const status = $("status");
|
|
307
|
+
const refusal = $("refusal");
|
|
207
308
|
function setBusy(b, msg) {
|
|
208
309
|
$("retry").disabled = b; $("reinstall").disabled = b;
|
|
209
310
|
status.textContent = msg;
|
|
210
311
|
}
|
|
312
|
+
// A 403 means the request was refused (not same-origin loopback): show the
|
|
313
|
+
// server's remedy as an alert and leave both buttons enabled.
|
|
314
|
+
function showRefusal(text) { refusal.textContent = text; refusal.hidden = false; }
|
|
315
|
+
function clearRefusal() { refusal.textContent = ""; refusal.hidden = true; }
|
|
211
316
|
async function post(path) {
|
|
212
317
|
const res = await fetch(path, { method: "POST" });
|
|
213
318
|
const text = await res.text();
|
|
214
|
-
return { ok: res.ok, text };
|
|
319
|
+
return { ok: res.ok, status: res.status, text };
|
|
215
320
|
}
|
|
216
321
|
$("retry").addEventListener("click", async () => {
|
|
322
|
+
clearRefusal();
|
|
217
323
|
setBusy(true, "Retrying…");
|
|
218
324
|
const r = await post("/api/recovery/retry");
|
|
325
|
+
if (r.status === 403) { setBusy(false, ""); showRefusal(r.text); return; }
|
|
219
326
|
status.textContent = r.text;
|
|
220
327
|
if (r.ok) setTimeout(() => location.reload(), 1500);
|
|
221
328
|
else setBusy(false, "Retry failed: " + r.text);
|
|
222
329
|
});
|
|
223
330
|
$("reinstall").addEventListener("click", async () => {
|
|
331
|
+
clearRefusal();
|
|
224
332
|
setBusy(true, "Reinstalling… this may take a minute.");
|
|
225
333
|
const r = await post("/api/recovery/reinstall");
|
|
334
|
+
if (r.status === 403) { setBusy(false, ""); showRefusal(r.text); return; }
|
|
226
335
|
status.textContent = r.text;
|
|
227
336
|
setBusy(false, r.text);
|
|
228
337
|
});
|
|
@@ -343,6 +452,20 @@ export async function startRecoveryServer(info: RecoveryInfo): Promise<number> {
|
|
|
343
452
|
);
|
|
344
453
|
return;
|
|
345
454
|
}
|
|
455
|
+
if (
|
|
456
|
+
req.method === "POST" &&
|
|
457
|
+
(url === "/api/recovery/retry" || url === "/api/recovery/reinstall") &&
|
|
458
|
+
!isRecoveryActionAllowed({ remoteAddress: req.socket.remoteAddress, headers: req.headers }, info.localToken)
|
|
459
|
+
) {
|
|
460
|
+
// Route only: never log a header or token value.
|
|
461
|
+
console.error(`[recovery] refused ${req.method} ${url}: not a same-origin loopback request`);
|
|
462
|
+
res.writeHead(403, { "content-type": "text/plain" });
|
|
463
|
+
res.end(
|
|
464
|
+
"Recovery actions only work on the machine running the dashboard. Open this page at http://localhost:" +
|
|
465
|
+
`${info.port || "<port>"} on that machine, or run \`pi-dashboard stop\` then \`pi-dashboard start\` there.`,
|
|
466
|
+
);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
346
469
|
if (req.method === "POST" && url === "/api/recovery/retry") {
|
|
347
470
|
// Respawn ourselves detached, then exit.
|
|
348
471
|
try {
|
|
@@ -412,7 +535,7 @@ export async function startRecoveryServer(info: RecoveryInfo): Promise<number> {
|
|
|
412
535
|
}
|
|
413
536
|
reject(err);
|
|
414
537
|
});
|
|
415
|
-
server.listen(info.port, () => {
|
|
538
|
+
server.listen(info.port, info.host ?? "127.0.0.1", () => {
|
|
416
539
|
const addr = server.address();
|
|
417
540
|
const bound = typeof addr === "object" && addr ? addr.port : info.port;
|
|
418
541
|
console.error(`[recovery] listening on http://localhost:${bound}`);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* or PID state. Every failure means "not owned".
|
|
5
5
|
* See change: fix-cli-stop-foreign-home-kill.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { getLockPath, getMetaPath, type LockMetadata, readMetadata } from "./home-lock.js";
|
|
8
8
|
import { peekInstanceId } from "./instance-id.js";
|
|
9
9
|
|
|
10
10
|
const HEALTH_PROBE_TIMEOUT_MS = 2000;
|
|
@@ -47,10 +47,26 @@ const defaultDeps: OwnershipDeps = {
|
|
|
47
47
|
fetchHealth: (url) => fetch(url, { signal: AbortSignal.timeout(HEALTH_PROBE_TIMEOUT_MS) }),
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
/** Raw `/api/health` fields the stop path reads. */
|
|
51
|
+
type HealthBody = {
|
|
52
|
+
pid?: unknown;
|
|
53
|
+
instanceId?: unknown;
|
|
54
|
+
launchSource?: unknown;
|
|
55
|
+
bootParentAlive?: unknown;
|
|
56
|
+
bootParentPid?: unknown;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Owner facts copied from a health reply (typed, optional). */
|
|
60
|
+
export interface OwnerFacts {
|
|
61
|
+
launchSource?: string;
|
|
62
|
+
bootParentAlive?: boolean;
|
|
63
|
+
bootParentPid?: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
50
66
|
async function probeHealth(
|
|
51
67
|
url: string,
|
|
52
68
|
fetchHealth: OwnershipDeps["fetchHealth"],
|
|
53
|
-
): Promise<
|
|
69
|
+
): Promise<HealthBody | null> {
|
|
54
70
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
55
71
|
try {
|
|
56
72
|
const timeout = new Promise<null>((resolve) => {
|
|
@@ -60,7 +76,7 @@ async function probeHealth(
|
|
|
60
76
|
const res = await fetchHealth(url);
|
|
61
77
|
if (!res.ok) return null;
|
|
62
78
|
const body = await res.json();
|
|
63
|
-
return body && typeof body === "object" ? (body as
|
|
79
|
+
return body && typeof body === "object" ? (body as HealthBody) : null;
|
|
64
80
|
})();
|
|
65
81
|
attempt.catch(() => {}); // a late rejection after the timeout must not be unhandled
|
|
66
82
|
return await Promise.race([attempt, timeout]);
|
|
@@ -71,18 +87,79 @@ async function probeHealth(
|
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The lock-metadata half of ownership proof: the recorded pid, when the record
|
|
92
|
+
* is for `port`. Shared by `stop` (port sweep) and the `start` / `status` port
|
|
93
|
+
* classifier, so the three can never disagree about the same process.
|
|
94
|
+
* See change: harden-dashboard-start-detection (D2).
|
|
95
|
+
*/
|
|
96
|
+
export function lockOwnedPid(meta: LockMetadata | null, port: number): number | null {
|
|
97
|
+
return meta && Number.isInteger(meta.pid) && meta.httpPort === port ? meta.pid : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The instance-id half of ownership proof: the health reply carries this HOME's id. */
|
|
101
|
+
export function healthMatchesInstance(
|
|
102
|
+
health: { pid?: unknown; instanceId?: unknown } | null,
|
|
103
|
+
localInstanceId: string | null,
|
|
104
|
+
): health is { pid: number; instanceId: string } {
|
|
105
|
+
return (
|
|
106
|
+
!!localInstanceId &&
|
|
107
|
+
!!health &&
|
|
108
|
+
health.instanceId === localInstanceId &&
|
|
109
|
+
typeof health.pid === "number" &&
|
|
110
|
+
Number.isInteger(health.pid)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Does the current HOME provably own the dashboard that just answered with
|
|
116
|
+
* `health`? Owned iff the health reply carries this HOME's instance id, OR the
|
|
117
|
+
* lock metadata records the replying pid for this port. `server.pid` is never
|
|
118
|
+
* proof (PIDs are reused across HOMEs). Pure.
|
|
119
|
+
*/
|
|
120
|
+
export function isOwnedHealth(
|
|
121
|
+
health: { pid?: unknown; instanceId?: unknown },
|
|
122
|
+
evidence: { meta: LockMetadata | null; localInstanceId: string | null; port: number },
|
|
123
|
+
): boolean {
|
|
124
|
+
if (healthMatchesInstance(health, evidence.localInstanceId)) return true;
|
|
125
|
+
const lockPid = lockOwnedPid(evidence.meta, evidence.port);
|
|
126
|
+
return lockPid !== null && health.pid === lockPid;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* What the current HOME can prove it owns, plus the one pid whose ownership
|
|
131
|
+
* rests on a health reply (instance-id match) with that reply's owner facts.
|
|
132
|
+
* `healthProven` is null whenever no health proof exists (no local instance
|
|
133
|
+
* id, unreachable, or lock-metadata-only ownership). The probe runs only when a
|
|
134
|
+
* local instance id exists, so there is no added latency otherwise.
|
|
135
|
+
* See change: fix-cli-control-electron-server (design D3).
|
|
136
|
+
*/
|
|
137
|
+
export interface Ownership {
|
|
138
|
+
owned: Set<number>;
|
|
139
|
+
healthProven: { pid: number; health: OwnerFacts } | null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function ownerFacts(body: HealthBody): OwnerFacts {
|
|
143
|
+
return {
|
|
144
|
+
...(typeof body.launchSource === "string" ? { launchSource: body.launchSource } : {}),
|
|
145
|
+
...(typeof body.bootParentAlive === "boolean" ? { bootParentAlive: body.bootParentAlive } : {}),
|
|
146
|
+
...(typeof body.bootParentPid === "number" ? { bootParentPid: body.bootParentPid } : {}),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Owned pids (lock metadata + instance-id match) and the health-proven pid. Empty when `config.port <= 0`. */
|
|
151
|
+
export async function collectOwnership(
|
|
76
152
|
config: OwnershipConfig,
|
|
77
153
|
deps: Partial<OwnershipDeps> = {},
|
|
78
|
-
): Promise<
|
|
154
|
+
): Promise<Ownership> {
|
|
79
155
|
const d = { ...defaultDeps, ...deps };
|
|
80
156
|
const owned = new Set<number>();
|
|
81
|
-
|
|
157
|
+
let healthProven: Ownership["healthProven"] = null;
|
|
158
|
+
if (!(config.port > 0)) return { owned, healthProven };
|
|
82
159
|
|
|
83
160
|
try {
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
161
|
+
const lockPid = lockOwnedPid(d.readLockMeta(), config.port);
|
|
162
|
+
if (lockPid !== null) owned.add(lockPid);
|
|
86
163
|
} catch {
|
|
87
164
|
/* unreadable sidecar → no proof */
|
|
88
165
|
}
|
|
@@ -94,14 +171,23 @@ export async function collectOwnedPids(
|
|
|
94
171
|
`http://${healthHost(config.host)}:${config.port}/api/health`,
|
|
95
172
|
d.fetchHealth,
|
|
96
173
|
);
|
|
97
|
-
if (health
|
|
174
|
+
if (healthMatchesInstance(health, localId)) {
|
|
98
175
|
owned.add(health.pid);
|
|
176
|
+
healthProven = { pid: health.pid, health: ownerFacts(health) };
|
|
99
177
|
}
|
|
100
178
|
}
|
|
101
179
|
} catch {
|
|
102
180
|
/* no proof */
|
|
103
181
|
}
|
|
104
|
-
return owned;
|
|
182
|
+
return { owned, healthProven };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Pids the current HOME can prove it owns. Empty when `config.port <= 0`. */
|
|
186
|
+
export async function collectOwnedPids(
|
|
187
|
+
config: OwnershipConfig,
|
|
188
|
+
deps: Partial<OwnershipDeps> = {},
|
|
189
|
+
): Promise<Set<number>> {
|
|
190
|
+
return (await collectOwnership(config, deps)).owned;
|
|
105
191
|
}
|
|
106
192
|
|
|
107
193
|
/** Split holders (pid → ports) into owned vs foreign. Pure. */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction of a live-preview capability token (`/~c/<token>`) from a log field / path.
|
|
3
|
+
* Its own module so the guard (which logs refused paths) and the capability store (which
|
|
4
|
+
* needs the guard's locality predicate) do not import each other.
|
|
5
|
+
*
|
|
6
|
+
* See change: retire-trusted-networks-bypass (D5).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** `/~c/<token>` anywhere in a path or `Referer`. Tokens are base64url. */
|
|
10
|
+
export const CAPABILITY_SEGMENT = /\/~c\/[A-Za-z0-9_-]+/g;
|
|
11
|
+
|
|
12
|
+
/** Replace any `/~c/<token>` in a log field / path with a redaction marker. */
|
|
13
|
+
export function redactCapability(text: string): string {
|
|
14
|
+
return text.replace(CAPABILITY_SEGMENT, "/~c/<redacted>");
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-originated `/live/` requests need a capability.
|
|
3
|
+
*
|
|
4
|
+
* A sandboxed preview frame has an opaque origin: its requests carry
|
|
5
|
+
* `Origin: null` and `Sec-Fetch-*` metadata. Without this rule a genuinely
|
|
6
|
+
* local operator's opaque frame would reach any registered port target with no
|
|
7
|
+
* capability at all (loopback peer, no forwarding header ⇒ "genuinely local").
|
|
8
|
+
* A request (HTTP or WS upgrade) carrying either marker must therefore present
|
|
9
|
+
* a valid capability; non-browser local callers (`curl`, `fastify.inject`) keep
|
|
10
|
+
* today's admission for port targets.
|
|
11
|
+
*
|
|
12
|
+
* See change: improve-canvas-html-and-url-ux (design D10).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** True when the headers mark the request as browser-originated (opaque origin or fetch metadata). */
|
|
16
|
+
export function isBrowserOriginated(headers: Record<string, unknown>): boolean {
|
|
17
|
+
if (headers.origin === "null") return true;
|
|
18
|
+
for (const name of Object.keys(headers)) {
|
|
19
|
+
if (name.toLowerCase().startsWith("sec-fetch-")) return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|