@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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP spawn routing: one entry point for WS `spawn_session`, REST
|
|
3
|
+
* `POST /api/session/spawn` and the plugin spawn hook when an `agent` is given.
|
|
4
|
+
*
|
|
5
|
+
* - non-durable agent (default) → host A, in-process (`startLocalAcpSession`)
|
|
6
|
+
* - durable agent → headless keeper whose child is the acp-bridge adapter,
|
|
7
|
+
* regardless of the configured spawn strategy, without resolving pi.
|
|
8
|
+
*
|
|
9
|
+
* Returns an ordinary `SpawnResult` so callers keep using the same headless PID
|
|
10
|
+
* registry, spawn token, register watchdog and spawn-error surfacing. A spawn
|
|
11
|
+
* with no `agent` never reaches this module.
|
|
12
|
+
*
|
|
13
|
+
* See change: add-acp-session-driver (D2).
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import type { AcpAgentConfig } from "@blackbelt-technology/pi-dashboard-shared/acp/acp-config.js";
|
|
19
|
+
import { loadConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
20
|
+
import type { ToolResolver } from "@blackbelt-technology/pi-dashboard-shared/platform/binary-lookup.js";
|
|
21
|
+
import { type LocalHostDeps, startLocalAcpSession } from "../acp-bridge/local-host.js";
|
|
22
|
+
import { mintSpawnToken } from "../auth/spawn-token.js";
|
|
23
|
+
import { type SpawnResult, spawnPiSession } from "./process-manager.js";
|
|
24
|
+
import { type PreflightReason, type PreflightResult, preflightSpawn } from "./spawn-preflight.js";
|
|
25
|
+
|
|
26
|
+
const ADAPTER_BIN = fileURLToPath(new URL("../../bin/acp-bridge.mjs", import.meta.url));
|
|
27
|
+
|
|
28
|
+
let localHost: LocalHostDeps | null = null;
|
|
29
|
+
|
|
30
|
+
/** Server wiring: how host A attaches to the gateway. */
|
|
31
|
+
export function setLocalAcpHost(host: LocalHostDeps | null): void {
|
|
32
|
+
localHost = host;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolveAcpAgent(id: string): AcpAgentConfig | undefined {
|
|
36
|
+
return loadConfig().acpAgents.find((a) => a.id === id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The ONLY agent data the browser sees: `{ id, name }` — never command/args/env. */
|
|
40
|
+
export function acpAgentsForClient(): Array<{ id: string; name: string }> {
|
|
41
|
+
return loadConfig().acpAgents.map((a) => ({ id: a.id, name: a.name }));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveOnPath(command: string, env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
45
|
+
if (command.includes("/") || command.includes("\\") || path.isAbsolute(command)) {
|
|
46
|
+
return existsSync(command) ? command : undefined;
|
|
47
|
+
}
|
|
48
|
+
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";")] : [""]; // platform-branch-ok: PATHEXT lookup for the preflight
|
|
49
|
+
for (const dir of (env.PATH ?? "").split(path.delimiter).filter(Boolean)) {
|
|
50
|
+
for (const ext of exts) {
|
|
51
|
+
const candidate = path.join(dir, command + ext);
|
|
52
|
+
if (existsSync(candidate)) return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Validation shared by WS + REST + plugin spawns: unknown agent, none configured. */
|
|
59
|
+
export function validateAcpAgent(id: unknown): { ok: true; agent: AcpAgentConfig } | { ok: false; message: string } {
|
|
60
|
+
const agents = loadConfig().acpAgents;
|
|
61
|
+
if (agents.length === 0) return { ok: false, message: "No ACP agents are configured" };
|
|
62
|
+
if (typeof id !== "string") return { ok: false, message: "agent must be a string" };
|
|
63
|
+
const agent = agents.find((a) => a.id === id);
|
|
64
|
+
return agent ? { ok: true, agent } : { ok: false, message: `Unknown ACP agent "${id}"` };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The cwd half of the shared pi preflight (exists / is a directory / writable).
|
|
69
|
+
* Reused instead of re-implementing the fs probes so a spawn cwd is validated by
|
|
70
|
+
* one code path. pi/node resolution is stubbed out: an ACP agent needs neither pi
|
|
71
|
+
* nor a pi-resolved node.
|
|
72
|
+
*/
|
|
73
|
+
function cwdReasons(cwd: string): PreflightReason[] {
|
|
74
|
+
const stub = { resolvePi: () => "-", resolveNode: () => "-" } as unknown as ToolResolver;
|
|
75
|
+
return preflightSpawn(cwd, { resolver: stub }).reasons;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** ACP preflight (replaces the pi/tmux preflight): cwd valid, node + agent command resolvable. */
|
|
79
|
+
export function preflightAcpSpawn(cwd: string, agent: AcpAgentConfig): PreflightResult {
|
|
80
|
+
const reasons: PreflightReason[] = [];
|
|
81
|
+
for (const r of cwdReasons(cwd)) {
|
|
82
|
+
if (r.code === "cwd_missing") reasons.push(r);
|
|
83
|
+
else if (r.code === "DIR_NOT_DIRECTORY") reasons.push({ code: "cwd_not_directory", message: r.message });
|
|
84
|
+
}
|
|
85
|
+
if (agent.durable && !existsSync(process.execPath)) {
|
|
86
|
+
reasons.push({ code: "node_missing", message: `Node binary not found: ${process.execPath}` });
|
|
87
|
+
}
|
|
88
|
+
if (!resolveOnPath(agent.command)) {
|
|
89
|
+
reasons.push({ code: "acp_command_missing", message: `ACP agent command not found: ${agent.command}` });
|
|
90
|
+
}
|
|
91
|
+
return { ok: reasons.length === 0, reasons };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function spawnAcpSession(
|
|
95
|
+
cwd: string,
|
|
96
|
+
opts: { agent: string; spawnToken?: string },
|
|
97
|
+
): Promise<SpawnResult> {
|
|
98
|
+
const agent = resolveAcpAgent(opts.agent);
|
|
99
|
+
if (!agent) return { success: false, code: "SPAWN_ERRNO", message: `Unknown ACP agent "${opts.agent}"` };
|
|
100
|
+
const missing = cwdReasons(cwd).find((r) => r.code === "cwd_missing");
|
|
101
|
+
if (missing) return { success: false, code: "DIR_MISSING", message: missing.message };
|
|
102
|
+
const spawnToken = opts.spawnToken ?? mintSpawnToken();
|
|
103
|
+
|
|
104
|
+
if (!agent.durable) {
|
|
105
|
+
if (!localHost) return { success: false, code: "SPAWN_ERRNO", message: "In-process ACP host is not available", spawnToken };
|
|
106
|
+
const r = startLocalAcpSession(localHost, { agent, settings: loadConfig().acp, cwd, spawnToken });
|
|
107
|
+
return r.success
|
|
108
|
+
? { success: true, dashboardSpawned: true, message: r.message, pid: r.pid, process: r.process, spawnToken }
|
|
109
|
+
: { success: false, code: "SPAWN_ERRNO", message: r.message, spawnToken };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const result = await spawnPiSession(cwd, {
|
|
113
|
+
strategy: "headless",
|
|
114
|
+
spawnToken,
|
|
115
|
+
childCmd: [process.execPath, ADAPTER_BIN, "--agent", agent.id],
|
|
116
|
+
});
|
|
117
|
+
return { ...result, spawnToken };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Plugin spawn hook validation: with `agent` set, pi-only options are rejected
|
|
122
|
+
* (never silently dropped) and an unknown id is rejected. Returns the error
|
|
123
|
+
* message, or `undefined` when the spawn may proceed.
|
|
124
|
+
*/
|
|
125
|
+
export function validatePluginAcpSpawn(opts: { agent?: unknown; scope?: unknown; resume?: unknown; model?: unknown }): string | undefined {
|
|
126
|
+
if (opts.agent === undefined) return undefined;
|
|
127
|
+
const v = validateAcpAgent(opts.agent);
|
|
128
|
+
if (!v.ok) return v.message;
|
|
129
|
+
const piOnly = (["scope", "resume", "model"] as const).filter((k) => opts[k] !== undefined);
|
|
130
|
+
return piOnly.length > 0 ? `option(s) ${piOnly.join(", ")} are pi-only and cannot be combined with agent "${v.agent.id}"` : undefined;
|
|
131
|
+
}
|
|
@@ -8,7 +8,12 @@ import { EventEmitter } from "node:events";
|
|
|
8
8
|
import os from "node:os";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import type { ChildProcess } from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
isProcessAlive,
|
|
13
|
+
killPidWithGroup,
|
|
14
|
+
killProcess,
|
|
15
|
+
killProcessGroup,
|
|
16
|
+
} from "@blackbelt-technology/pi-dashboard-shared/platform/process.js";
|
|
12
17
|
import { isUnsafeTestHomeScan } from "../auth/test-env-guard.js";
|
|
13
18
|
import { readJsonFile, writeJsonFile } from "../persistence/json-store.js";
|
|
14
19
|
|
|
@@ -315,15 +320,15 @@ export function createHeadlessPidRegistry(options?: HeadlessPidRegistryOptions):
|
|
|
315
320
|
killedSomething = true;
|
|
316
321
|
} catch { /* pi may already be dead */ }
|
|
317
322
|
}
|
|
318
|
-
// Fallback
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
//
|
|
323
|
+
// Fallback after a 200 ms grace: terminate the keeper's whole process
|
|
324
|
+
// GROUP (keeper + pi + pi's children — pi is spawned non-detached by the
|
|
325
|
+
// keeper, so it shares the keeper's group). Gated on the GROUP still
|
|
326
|
+
// existing, not on keeper liveness: the keeper auto-exits with pi, but
|
|
327
|
+
// pi's orphaned children (long bash calls, MCP servers) stay in the
|
|
328
|
+
// group. killProcessGroup is a no-op once the group is gone and
|
|
329
|
+
// escalates SIGTERM → SIGKILL. See issue #912.
|
|
323
330
|
setTimeout(() => {
|
|
324
|
-
|
|
325
|
-
try { killPidWithGroup(keeperPid, "SIGTERM"); } catch { /* ignore */ }
|
|
326
|
-
}
|
|
331
|
+
void killProcessGroup(keeperPid, { timeoutMs: 2000 }).catch(() => undefined);
|
|
327
332
|
}, 200).unref?.();
|
|
328
333
|
// If pi was unknown (bridge never connected), fall through to
|
|
329
334
|
// killing the keeper directly with SIGKILL escalation so the
|
|
@@ -28,7 +28,14 @@ import {
|
|
|
28
28
|
mergeHeapIntoNodeOptions,
|
|
29
29
|
stripDashboardHeapFlag,
|
|
30
30
|
} from "@blackbelt-technology/pi-dashboard-shared/heap-flags.js";
|
|
31
|
+
import {
|
|
32
|
+
isLoopbackLiteral,
|
|
33
|
+
localDialHost,
|
|
34
|
+
REQUIRE_SERVER_PROOF_ENV,
|
|
35
|
+
} from "@blackbelt-technology/pi-dashboard-shared/local-credential-proof.js";
|
|
31
36
|
import { MANAGED_BIN } from "@blackbelt-technology/pi-dashboard-shared/managed-paths.js";
|
|
37
|
+
import { prependSelectedNodeToPath } from "@blackbelt-technology/pi-dashboard-shared/node-installs/index.js";
|
|
38
|
+
import { PATH_CONTAINMENT_GUARD_EXT_NAME } from "@blackbelt-technology/pi-dashboard-shared/path-containment-guard-name.js";
|
|
32
39
|
import { ToolResolver } from "@blackbelt-technology/pi-dashboard-shared/platform/binary-lookup.js";
|
|
33
40
|
import {
|
|
34
41
|
spawnDetached,
|
|
@@ -41,7 +48,6 @@ import {
|
|
|
41
48
|
execSync,
|
|
42
49
|
spawnSync,
|
|
43
50
|
} from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
|
|
44
|
-
import { prependSelectedNodeToPath } from "@blackbelt-technology/pi-dashboard-shared/node-installs/index.js";
|
|
45
51
|
import { electronAsNodeRequired } from "@blackbelt-technology/pi-dashboard-shared/platform/runner.js";
|
|
46
52
|
import {
|
|
47
53
|
buildWtArgs,
|
|
@@ -51,8 +57,8 @@ import {
|
|
|
51
57
|
type UserSpawnStrategy,
|
|
52
58
|
} from "@blackbelt-technology/pi-dashboard-shared/platform/spawn-mechanism.js";
|
|
53
59
|
import {
|
|
54
|
-
type ResolvedRuntime,
|
|
55
60
|
piEntryFromArgv,
|
|
61
|
+
type ResolvedRuntime,
|
|
56
62
|
validateResolvedRuntime,
|
|
57
63
|
} from "@blackbelt-technology/pi-dashboard-shared/platform/spawn-runtime.js";
|
|
58
64
|
import { mintSpawnToken } from "../auth/spawn-token.js";
|
|
@@ -66,6 +72,7 @@ import {
|
|
|
66
72
|
} from "../runtime-resolution.js";
|
|
67
73
|
import { type CwdPolicyRegistry, mergeCwdPolicy } from "./cwd-policy.js";
|
|
68
74
|
import { applyHeapArgsToPiArgv, recordHeapArgvFallback } from "./heap-args.js";
|
|
75
|
+
import { applySpawnEnvContributors, type ContributorMechanism } from "./spawn-env-contributors.js";
|
|
69
76
|
|
|
70
77
|
// ── Resolver seam (injectable for tests) ────────────────────────────────────
|
|
71
78
|
|
|
@@ -92,10 +99,19 @@ export function resetResolver(): void {
|
|
|
92
99
|
// spawns (spawn-token watchdog, session tracking), so this overrides any
|
|
93
100
|
// inherited `PI_DASHBOARD_URL`.
|
|
94
101
|
let spawnDashboardPiPort: number | null = null;
|
|
102
|
+
// The host the TCP gateway binds (`config.host`), supplied through the same
|
|
103
|
+
// setter. It does NOT introspect the gateway: a socket-only gateway has no TCP
|
|
104
|
+
// address. Unset ⇒ the legacy `ws://localhost:<piPort>` URL and no marker.
|
|
105
|
+
let spawnBindHost: string | null = null;
|
|
95
106
|
|
|
96
|
-
/**
|
|
97
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Set the owning server's piPort so spawned sessions connect back here, and the
|
|
109
|
+
* host its TCP gateway binds so a loopback spawn can be dialled as a literal and
|
|
110
|
+
* marked for server-proof enforcement (change: loopback-credential-proof, D7).
|
|
111
|
+
*/
|
|
112
|
+
export function setSpawnDashboardPiPort(piPort: number | null, bindHost?: string | null): void {
|
|
98
113
|
spawnDashboardPiPort = piPort;
|
|
114
|
+
spawnBindHost = bindHost ?? null;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
117
|
/** The bridge transport this server actually serves, for spawn pinning (D6). */
|
|
@@ -177,6 +193,11 @@ export interface SessionOptions {
|
|
|
177
193
|
* add-automation-plugin.
|
|
178
194
|
*/
|
|
179
195
|
model?: string;
|
|
196
|
+
/**
|
|
197
|
+
* Optional thinking level appended as `--thinking <level>` on the fresh and
|
|
198
|
+
* continue argv. See change: redesign-directory-home-split.
|
|
199
|
+
*/
|
|
200
|
+
thinking?: string;
|
|
180
201
|
/**
|
|
181
202
|
* Optional session name appended as `--name <name>` (pi 0.78.0+) so a
|
|
182
203
|
* worktree / flow spawn lands with an intended title at creation instead of
|
|
@@ -199,6 +220,8 @@ export interface SessionOptions {
|
|
|
199
220
|
appendSystemPrompt?: string[];
|
|
200
221
|
noContextFiles?: boolean;
|
|
201
222
|
noProjectTrust?: boolean;
|
|
223
|
+
/** `--no-mcp`: see `SessionFlags`. See change: spawn-scope-no-mcp. */
|
|
224
|
+
noMcp?: boolean;
|
|
202
225
|
sessionDir?: string;
|
|
203
226
|
/**
|
|
204
227
|
* Per-extension config projected to namespaced env (`PI_EXT_<NAME>_<KEY>`)
|
|
@@ -208,6 +231,14 @@ export interface SessionOptions {
|
|
|
208
231
|
* add-plugin-spawn-scope.
|
|
209
232
|
*/
|
|
210
233
|
extensionConfig?: Record<string, Record<string, string | string[]>>;
|
|
234
|
+
/**
|
|
235
|
+
* Replace the pi child with an arbitrary command (ACP adapter, host B):
|
|
236
|
+
* the FULL argv `[node, script, ...args]`. Forces the headless keeper
|
|
237
|
+
* mechanism and skips pi resolution, `buildHeadlessArgs`, heap and pi runtime
|
|
238
|
+
* argv shaping. Absent → every path byte-identical to before.
|
|
239
|
+
* See change: add-acp-session-driver (D2).
|
|
240
|
+
*/
|
|
241
|
+
childCmd?: string[];
|
|
211
242
|
}
|
|
212
243
|
|
|
213
244
|
export interface SpawnResult {
|
|
@@ -298,6 +329,15 @@ export function buildSpawnEnv(
|
|
|
298
329
|
* See change: unify-pi-runtime-identity (task 3.1).
|
|
299
330
|
*/
|
|
300
331
|
spawnRuntime?: ResolvedRuntime | null;
|
|
332
|
+
/**
|
|
333
|
+
* Spawn mechanism this env is built for. When present, trusted plugins'
|
|
334
|
+
* spawn-env contributors are applied (additions only, never overriding an
|
|
335
|
+
* inherited variable). Absent ⇒ no contributors (legacy callers).
|
|
336
|
+
* See change: add-context-mode-settings-plugin.
|
|
337
|
+
*/
|
|
338
|
+
mechanism?: ContributorMechanism;
|
|
339
|
+
/** Out-param: receives the contributor entries actually applied (tmux emits them as `-e`). */
|
|
340
|
+
contributedOut?: Record<string, string>;
|
|
301
341
|
},
|
|
302
342
|
): NodeJS.ProcessEnv {
|
|
303
343
|
// Defensive copy: never mutate the caller's env (often `process.env`).
|
|
@@ -321,6 +361,13 @@ export function buildSpawnEnv(
|
|
|
321
361
|
// non-blocking finding — grandchild marker leak).
|
|
322
362
|
delete env.PI_DASHBOARD_ELECTRON;
|
|
323
363
|
delete env.PI_DASHBOARD_RESOURCES_PATH;
|
|
364
|
+
// context-mode's bridge-internal recursion guard / idle reaper vars. A server
|
|
365
|
+
// started from inside a context-mode sandbox would otherwise hand them to
|
|
366
|
+
// every session, where context-mode silently disables its `ctx_*` tools.
|
|
367
|
+
// True delete, never empty (an empty value reads as 0 = disabled).
|
|
368
|
+
// See change: add-context-mode-settings-plugin (D6).
|
|
369
|
+
delete env.CONTEXT_MODE_BRIDGE_DEPTH;
|
|
370
|
+
delete env.CONTEXT_MODE_BRIDGE_IDLE_MS;
|
|
324
371
|
// Dashboard spawns ALWAYS activate the bridge: overrides a host-global
|
|
325
372
|
// `bridge.enabled:false` and any opt-out inherited from the server's shell.
|
|
326
373
|
// Descendants inherit it. tmux panes get it via `-e` (buildTmuxCommand).
|
|
@@ -343,11 +390,32 @@ export function buildSpawnEnv(
|
|
|
343
390
|
// Point spawned bridges at THIS server's gateway so they register with the
|
|
344
391
|
// server that spawned them, not the config-default piPort. Overrides any
|
|
345
392
|
// inherited PI_DASHBOARD_URL. See setSpawnDashboardPiPort above.
|
|
393
|
+
// An inherited enforcement marker is ALWAYS dropped first: it names another
|
|
394
|
+
// endpoint's identity demand and must never reach a descendant that this spawn
|
|
395
|
+
// did not mark. (On the null-port path only the marker is removed here; the
|
|
396
|
+
// URL is left as today.) See change: loopback-credential-proof (D7).
|
|
397
|
+
delete env[REQUIRE_SERVER_PROOF_ENV];
|
|
346
398
|
if (spawnDashboardPiPort != null) {
|
|
347
399
|
const served = spawnGatewayTransport?.() ?? null;
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
|
|
400
|
+
// A loopback bind is dialled as an address LITERAL and marked: the bridge
|
|
401
|
+
// then demands the server counter-proof at exactly this endpoint. The
|
|
402
|
+
// fallback listener always binds 127.0.0.1. `wsl-tmux` is NEVER marked — its
|
|
403
|
+
// pane runs in another kernel and HOME, so it holds another token and would
|
|
404
|
+
// quarantine forever.
|
|
405
|
+
const literal =
|
|
406
|
+
spawnBindHost != null && opts?.mechanism !== "wsl-tmux"
|
|
407
|
+
? served?.transport === "loopback-fallback"
|
|
408
|
+
? "127.0.0.1"
|
|
409
|
+
: localDialHost(spawnBindHost)
|
|
410
|
+
: undefined;
|
|
411
|
+
if (literal !== undefined && isLoopbackLiteral(literal)) {
|
|
412
|
+
env.PI_DASHBOARD_URL = `ws://${literal}:${spawnDashboardPiPort}`;
|
|
413
|
+
env[REQUIRE_SERVER_PROOF_ENV] = env.PI_DASHBOARD_URL;
|
|
414
|
+
} else {
|
|
415
|
+
// After a fallback the URL is a literal so a bridge never lands on a
|
|
416
|
+
// `[::1]` squatter. See change: fix-gateway-socket-stale-owner (D6).
|
|
417
|
+
env.PI_DASHBOARD_URL = `ws://${served?.transport === "loopback-fallback" ? "127.0.0.1" : "localhost"}:${spawnDashboardPiPort}`;
|
|
418
|
+
}
|
|
351
419
|
// Pin over the socket too when this instance is serving one. The URL pin
|
|
352
420
|
// alone stops working the moment the default TCP listener goes away (task
|
|
353
421
|
// 8.1), and an inherited `PI_DASHBOARD_SOCKET` from another instance would
|
|
@@ -363,27 +431,49 @@ export function buildSpawnEnv(
|
|
|
363
431
|
// See change: spawn-correlation-token.
|
|
364
432
|
env.PI_DASHBOARD_SPAWN_TOKEN = opts.spawnToken;
|
|
365
433
|
}
|
|
366
|
-
if (opts?.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
// (`allowedRoots`) gets an underscore inserted, then the token is
|
|
370
|
-
// uppercased and every non-`[A-Z0-9_]` char replaced by `_` (so
|
|
371
|
-
// `allowedRoots`→`ALLOWED_ROOTS`, `api.key`→`API_KEY`, design D4).
|
|
372
|
-
// See change: add-plugin-spawn-scope.
|
|
373
|
-
for (const [name, config] of Object.entries(opts.extensionConfig)) {
|
|
374
|
-
const normName = normalizeEnvSegment(name);
|
|
375
|
-
for (const [key, value] of Object.entries(config)) {
|
|
376
|
-
const normKey = normalizeEnvSegment(key);
|
|
377
|
-
// Scalar string projects verbatim; array projects as JSON so the
|
|
378
|
-
// value is lossless for filesystem paths (design D8).
|
|
379
|
-
env[`PI_EXT_${normName}_${normKey}`] =
|
|
380
|
-
typeof value === "string" ? value : JSON.stringify(value);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
434
|
+
if (opts?.mechanism) {
|
|
435
|
+
const applied = applySpawnEnvContributors(env, opts.mechanism);
|
|
436
|
+
if (opts.contributedOut) Object.assign(opts.contributedOut, applied);
|
|
383
437
|
}
|
|
438
|
+
// AFTER the contributors: they fill only absent names, so projecting/stripping any
|
|
439
|
+
// earlier would let one re-fill a stripped key. See change: add-path-containment-guard-extension (D7).
|
|
440
|
+
applyExtensionConfigNamespaces(env, opts?.extensionConfig, opts?.contributedOut);
|
|
384
441
|
return env;
|
|
385
442
|
}
|
|
386
443
|
|
|
444
|
+
/**
|
|
445
|
+
* A spawn owns the env namespace of every extension it configures: strip each inherited
|
|
446
|
+
* `PI_EXT_<NAME>_*` (also whatever a contributor added) for those names, plus the
|
|
447
|
+
* path-containment guard's namespace unconditionally, and only THEN project the spawn's
|
|
448
|
+
* own `extensionConfig`. Stripping before any projection keeps nested prefixes
|
|
449
|
+
* (`path-containment` vs `path-containment-guard`) from eating each other's output.
|
|
450
|
+
* Without it a stale inherited var would silently stand in for dropped/omitted config.
|
|
451
|
+
* Removed names are also pruned from `contributedOut` so the tmux `-e` emission never re-adds them.
|
|
452
|
+
*
|
|
453
|
+
* Projection: name+key are normalized to a valid env identifier (camelCase boundary gets an
|
|
454
|
+
* underscore, uppercased, non-`[A-Z0-9_]` → `_`: `allowedRoots`→`ALLOWED_ROOTS`). A scalar string
|
|
455
|
+
* projects verbatim; an array projects as JSON (lossless for filesystem paths, design D8).
|
|
456
|
+
* See change: add-plugin-spawn-scope; add-path-containment-guard-extension (D7).
|
|
457
|
+
*/
|
|
458
|
+
function applyExtensionConfigNamespaces(
|
|
459
|
+
env: NodeJS.ProcessEnv,
|
|
460
|
+
extensionConfig: Record<string, Record<string, string | string[]>> | undefined,
|
|
461
|
+
contributedOut: Record<string, string> | undefined,
|
|
462
|
+
): void {
|
|
463
|
+
const namespace = (name: string): string => `PI_EXT_${normalizeEnvSegment(name)}_`;
|
|
464
|
+
const owned = [namespace(PATH_CONTAINMENT_GUARD_EXT_NAME), ...Object.keys(extensionConfig ?? {}).map(namespace)];
|
|
465
|
+
for (const key of Object.keys(env)) {
|
|
466
|
+
if (!owned.some((prefix) => key.startsWith(prefix))) continue;
|
|
467
|
+
delete env[key];
|
|
468
|
+
if (contributedOut) delete contributedOut[key];
|
|
469
|
+
}
|
|
470
|
+
for (const [name, config] of Object.entries(extensionConfig ?? {})) {
|
|
471
|
+
for (const [key, value] of Object.entries(config)) {
|
|
472
|
+
env[`${namespace(name)}${normalizeEnvSegment(key)}`] = typeof value === "string" ? value : JSON.stringify(value);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
387
477
|
/**
|
|
388
478
|
* Normalize an `extensionConfig` name/key segment into a valid uppercase env
|
|
389
479
|
* identifier: split camelCase boundaries with `_` (`allowedRoots` →
|
|
@@ -509,9 +599,19 @@ export function buildTmuxCommand(
|
|
|
509
599
|
options?: SessionOptions,
|
|
510
600
|
piInvocation: string[] = ["pi"],
|
|
511
601
|
heapNodeOptions = "",
|
|
512
|
-
endpoint?: { url?: string; socket?: string },
|
|
602
|
+
endpoint?: { url?: string; socket?: string; marker?: string },
|
|
603
|
+
contributedEnv: Record<string, string> = {},
|
|
513
604
|
): string[] {
|
|
605
|
+
// `env -u` truly unsets context-mode's bridge-internal vars that the pane
|
|
606
|
+
// would otherwise inherit from the long-lived tmux SERVER (an empty `-e`
|
|
607
|
+
// value would disable the idle reaper instead). See change:
|
|
608
|
+
// add-context-mode-settings-plugin (D6).
|
|
514
609
|
const paneCommand = [
|
|
610
|
+
"env",
|
|
611
|
+
"-u",
|
|
612
|
+
"CONTEXT_MODE_BRIDGE_DEPTH",
|
|
613
|
+
"-u",
|
|
614
|
+
"CONTEXT_MODE_BRIDGE_IDLE_MS",
|
|
515
615
|
...piInvocation.map(shellEscape),
|
|
516
616
|
...sessionFlagsToArgv(options ?? {}).map(shellEscape),
|
|
517
617
|
].join(" ");
|
|
@@ -543,10 +643,19 @@ export function buildTmuxCommand(
|
|
|
543
643
|
`PI_DASHBOARD_SOCKET=${endpoint.socket ?? ""}`,
|
|
544
644
|
]
|
|
545
645
|
: [];
|
|
646
|
+
// The server-proof enforcement marker rides `-e` too, ALWAYS: an empty value
|
|
647
|
+
// cancels one inherited from the tmux server's global env (the same
|
|
648
|
+
// convention as `PI_DASHBOARD_SOCKET=` above), and a `wsl-tmux` pane — which
|
|
649
|
+
// is never marked — gets the empty cancel.
|
|
650
|
+
// See change: loopback-credential-proof (D7).
|
|
651
|
+
const markerEnv = ["-e", `${REQUIRE_SERVER_PROOF_ENV}=${endpoint?.marker ?? ""}`];
|
|
546
652
|
// Bridge activation stamp rides `-e` for the same reason: the spawn env
|
|
547
653
|
// never reaches the pane. See change: add-bridge-env-opt-out (D5).
|
|
548
654
|
const bridgeEnv = ["-e", "PI_DASHBOARD_BRIDGE=on"];
|
|
549
|
-
|
|
655
|
+
// Trusted-plugin contributions ride per-window `-e` too (the pane env comes
|
|
656
|
+
// from the tmux server). Already validated by `applySpawnEnvContributors`.
|
|
657
|
+
const contribEnv: string[] = Object.entries(contributedEnv).flatMap(([k, v]) => ["-e", `${k}=${v}`]);
|
|
658
|
+
const envArgs = [...tokenEnv, ...endpointEnv, ...markerEnv, ...heapEnv, ...bridgeEnv, ...contribEnv];
|
|
550
659
|
if (sessionExists) {
|
|
551
660
|
return ["tmux", "new-window", "-t", "pi-dashboard", ...envArgs, "-c", cwd, paneCommand];
|
|
552
661
|
}
|
|
@@ -554,9 +663,9 @@ export function buildTmuxCommand(
|
|
|
554
663
|
}
|
|
555
664
|
|
|
556
665
|
/** The endpoint pin `buildSpawnEnv` set, for the tmux `-e` path (D6). */
|
|
557
|
-
function tmuxEndpoint(env: NodeJS.ProcessEnv): { url?: string; socket?: string } | undefined {
|
|
666
|
+
function tmuxEndpoint(env: NodeJS.ProcessEnv): { url?: string; socket?: string; marker?: string } | undefined {
|
|
558
667
|
if (spawnDashboardPiPort == null) return undefined;
|
|
559
|
-
return { url: env.PI_DASHBOARD_URL, socket: env.PI_DASHBOARD_SOCKET };
|
|
668
|
+
return { url: env.PI_DASHBOARD_URL, socket: env.PI_DASHBOARD_SOCKET, marker: env[REQUIRE_SERVER_PROOF_ENV] };
|
|
560
669
|
}
|
|
561
670
|
|
|
562
671
|
// ── Availability probes (isolated, one place) ───────────────────────────────
|
|
@@ -712,6 +821,8 @@ function applySessionHeap(
|
|
|
712
821
|
* 3. Windows → probe wt first; probe wsl-tmux only if wt is absent
|
|
713
822
|
*/
|
|
714
823
|
function chooseMechanism(options?: SessionOptions, electronMode = false): SpawnMechanism {
|
|
824
|
+
// A non-pi child (ACP adapter) only ever runs under the headless keeper.
|
|
825
|
+
if (options?.childCmd?.length) return "headless";
|
|
715
826
|
const userStrategy: UserSpawnStrategy = options?.strategy === "headless" ? "headless" : "tmux";
|
|
716
827
|
const platform = process.platform;
|
|
717
828
|
|
|
@@ -810,15 +921,18 @@ export function spawnTmux(cwd: string, options?: SessionOptions): SpawnResult {
|
|
|
810
921
|
// pi process (tmux inherits the caller's env into new windows/sessions).
|
|
811
922
|
// argv0 re-adds the Electron-as-node flag when piCmd[0] is the Electron binary.
|
|
812
923
|
// See change: spawn-correlation-token.
|
|
924
|
+
const contributed: Record<string, string> = {};
|
|
813
925
|
const env = buildSpawnEnv(process.env, {
|
|
814
926
|
spawnToken: options?.spawnToken,
|
|
815
927
|
argv0: piCmd[0],
|
|
816
928
|
spawnRuntime: rt,
|
|
929
|
+
mechanism: "tmux",
|
|
930
|
+
contributedOut: contributed,
|
|
817
931
|
});
|
|
818
932
|
// Built AFTER `env` so the per-window value merges over the ALREADY-STRIPPED
|
|
819
933
|
// child environment — unrelated operator options survive into the pane, and
|
|
820
934
|
// the dashboard's own flag is already gone.
|
|
821
|
-
const cmd = buildTmuxCommand(cwd, exists, options, piCmd, tmuxHeapNodeOptions(env), tmuxEndpoint(env));
|
|
935
|
+
const cmd = buildTmuxCommand(cwd, exists, options, piCmd, tmuxHeapNodeOptions(env), tmuxEndpoint(env), contributed);
|
|
822
936
|
try {
|
|
823
937
|
const { argv, spawnOptions } = buildSafeArgv(cmd[0], cmd.slice(1));
|
|
824
938
|
execFileSync(argv[0], argv.slice(1), { stdio: "ignore", env, ...spawnOptions });
|
|
@@ -837,11 +951,14 @@ export function spawnWslTmux(cwd: string, options?: SessionOptions): SpawnResult
|
|
|
837
951
|
// `wsl.exe --exec <tmux argv>`: `.exe` bypasses the cmd.exe branch in
|
|
838
952
|
// buildSafeArgv; `--exec` runs tmux directly instead of through WSL's
|
|
839
953
|
// default shell. `pi` stays literal so it resolves inside the WSL namespace.
|
|
954
|
+
const contributed: Record<string, string> = {};
|
|
840
955
|
const env = buildSpawnEnv(process.env, {
|
|
841
956
|
spawnToken: options?.spawnToken,
|
|
842
957
|
spawnRuntime: spawnRuntimeForSession(),
|
|
958
|
+
mechanism: "wsl-tmux",
|
|
959
|
+
contributedOut: contributed,
|
|
843
960
|
});
|
|
844
|
-
const tmuxArgv = buildTmuxCommand(cwd, false, options, ["pi"], tmuxHeapNodeOptions(env));
|
|
961
|
+
const tmuxArgv = buildTmuxCommand(cwd, false, options, ["pi"], tmuxHeapNodeOptions(env), undefined, contributed);
|
|
845
962
|
const { argv, spawnOptions } = buildSafeArgv("wsl.exe", ["--exec", ...tmuxArgv]);
|
|
846
963
|
execFileSync(argv[0], argv.slice(1), { stdio: "ignore", env, ...spawnOptions });
|
|
847
964
|
return { success: true, dashboardSpawned: true, message: "Pi session started via WSL tmux" };
|
|
@@ -870,6 +987,7 @@ async function spawnWt(cwd: string, options?: SessionOptions): Promise<SpawnResu
|
|
|
870
987
|
spawnToken: options?.spawnToken,
|
|
871
988
|
argv0: piCmd[0],
|
|
872
989
|
spawnRuntime: rt,
|
|
990
|
+
mechanism: "wt",
|
|
873
991
|
});
|
|
874
992
|
if (heaped.fallback) {
|
|
875
993
|
// Last resort (D3a): only the subset `NODE_OPTIONS` accepts, and only
|
|
@@ -908,6 +1026,7 @@ async function spawnWt(cwd: string, options?: SessionOptions): Promise<SpawnResu
|
|
|
908
1026
|
}
|
|
909
1027
|
|
|
910
1028
|
async function spawnHeadless(cwd: string, options?: SessionOptions): Promise<SpawnResult> {
|
|
1029
|
+
if (options?.childCmd?.length) return spawnChildCmdViaKeeper(cwd, options.childCmd, options.spawnToken);
|
|
911
1030
|
// Headless `--mode rpc` sessions are spawned through the RPC keeper sidecar
|
|
912
1031
|
// on every platform. The keeper owns pi's stdin pipe (so pi survives
|
|
913
1032
|
// dashboard server restarts) and exposes a per-session UDS / named pipe
|
|
@@ -929,6 +1048,7 @@ async function spawnHeadless(cwd: string, options?: SessionOptions): Promise<Spa
|
|
|
929
1048
|
argv0: piCmd[0],
|
|
930
1049
|
extensionConfig: options?.extensionConfig,
|
|
931
1050
|
spawnRuntime: rt,
|
|
1051
|
+
mechanism: "headless",
|
|
932
1052
|
});
|
|
933
1053
|
// The ceiling rides the invocation handed to the keeper, so it binds pi and
|
|
934
1054
|
// NOT the keeper. There is deliberately no env fallback on this strategy:
|
|
@@ -939,6 +1059,20 @@ async function spawnHeadless(cwd: string, options?: SessionOptions): Promise<Spa
|
|
|
939
1059
|
return spawnHeadlessViaKeeper(cwd, env, args, heaped.argv);
|
|
940
1060
|
}
|
|
941
1061
|
|
|
1062
|
+
/**
|
|
1063
|
+
* Keeper spawn for a non-pi child (`SessionOptions.childCmd`, the ACP adapter).
|
|
1064
|
+
* `piCmd = [argv0]`, `piArgs = argv.slice(1)` — never empty, so the keeper does
|
|
1065
|
+
* not append its default `--mode rpc`. `argv0` rides `buildSpawnEnv` so an
|
|
1066
|
+
* Electron binary gets `ELECTRON_RUN_AS_NODE`. No pi resolution (`PI_NOT_FOUND`
|
|
1067
|
+
* cannot occur), no heap/runtime argv shaping.
|
|
1068
|
+
* See change: add-acp-session-driver (D2).
|
|
1069
|
+
*/
|
|
1070
|
+
function spawnChildCmdViaKeeper(cwd: string, childCmd: string[], spawnToken?: string): Promise<SpawnResult> {
|
|
1071
|
+
const [argv0, ...rest] = childCmd as [string, ...string[]];
|
|
1072
|
+
const env = buildSpawnEnv(process.env, { spawnToken, argv0, mechanism: "headless" });
|
|
1073
|
+
return spawnHeadlessViaKeeper(cwd, env, rest, [argv0]);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
942
1076
|
/**
|
|
943
1077
|
* RPC keeper sidecar headless spawn. Uniform across Unix + Windows.
|
|
944
1078
|
*
|
|
@@ -22,11 +22,12 @@ export interface RestartParams {
|
|
|
22
22
|
/** Absolute path to the server CLI (typically process.argv[1]) */
|
|
23
23
|
cliPath: string;
|
|
24
24
|
/**
|
|
25
|
-
* Loader value
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* See change: fix-appimage-cold-boot-latency (design D4)
|
|
25
|
+
* Loader value for `--import` (a `file://` URL). `/api/restart` always passes
|
|
26
|
+
* the native register module, never the running process's own `--import`
|
|
27
|
+
* (which may be a foreign jiti inherited across an upgrade). Empty string =
|
|
28
|
+
* none (bare entry).
|
|
29
|
+
* See change: fix-appimage-cold-boot-latency (design D4);
|
|
30
|
+
* strip-only-native-ts-loader (design D5).
|
|
30
31
|
*/
|
|
31
32
|
loader: string;
|
|
32
33
|
/** Port the server listens on */
|
|
@@ -45,10 +46,10 @@ export interface RestartParams {
|
|
|
45
46
|
/** Override Node binary (defaults to process.execPath) */
|
|
46
47
|
execPath?: string;
|
|
47
48
|
/**
|
|
48
|
-
* Whether the new server will boot in dev mode
|
|
49
|
+
* Whether the new server will boot in dev mode.
|
|
49
50
|
* Controls the health-poll deadline embedded in the orchestrator script:
|
|
50
|
-
* - prod: 15s (
|
|
51
|
-
* - dev: 60s (cold
|
|
51
|
+
* - prod: 15s (the server is up well under that)
|
|
52
|
+
* - dev: 60s (a cold dev boot loading ~400 TS files can reach 25–60s)
|
|
52
53
|
* Mismatching this against the actual mode is harmless but defeats the
|
|
53
54
|
* point — a too-short deadline writes a spurious failure line to
|
|
54
55
|
* ~/.pi/dashboard/restart.log even though the new server is fine.
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
* Writes/reads/removes ~/.pi/dashboard/server.pid to track the running server.
|
|
4
4
|
*/
|
|
5
5
|
import fs from "node:fs";
|
|
6
|
-
import path from "node:path";
|
|
7
6
|
import os from "node:os";
|
|
8
|
-
import
|
|
7
|
+
import path from "node:path";
|
|
9
8
|
import { isProcessAlive } from "@blackbelt-technology/pi-dashboard-shared/platform/process.js";
|
|
9
|
+
import { isDashboardRunning } from "@blackbelt-technology/pi-dashboard-shared/server-identity.js";
|
|
10
10
|
|
|
11
11
|
const DEFAULT_PID_PATH = path.join(os.homedir(), ".pi", "dashboard", "server.pid");
|
|
12
12
|
|
|
13
13
|
export interface ServerPidOptions {
|
|
14
14
|
pidPath?: string;
|
|
15
|
+
/** Test seam: replaces the health probe used by `isServerRunning`. */
|
|
16
|
+
probe?: typeof isDashboardRunning;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -60,21 +62,28 @@ export function removePid(options?: ServerPidOptions): void {
|
|
|
60
62
|
/**
|
|
61
63
|
* Check if the dashboard server is currently running.
|
|
62
64
|
* Returns the PID if running, null otherwise.
|
|
63
|
-
* Cleans up
|
|
65
|
+
* Cleans up PID files of DEAD processes only: a live process whose health
|
|
66
|
+
* probe stays silent (overloaded or frozen server) keeps its pid file, so the
|
|
67
|
+
* next `stop` / `status` can still find it.
|
|
68
|
+
* See change: harden-dashboard-start-detection (D3).
|
|
64
69
|
*/
|
|
65
70
|
export async function isServerRunning(port: number, options?: ServerPidOptions): Promise<number | null> {
|
|
66
71
|
const pid = readPid(options);
|
|
67
72
|
|
|
68
73
|
if (pid === null) return null;
|
|
69
74
|
|
|
70
|
-
// Process alive — verify it's actually our server via health check
|
|
75
|
+
// Process alive — verify it's actually our server via health check, with
|
|
76
|
+
// bounded retries so one slow answer is not "not running".
|
|
71
77
|
if (isProcessAlive(pid)) {
|
|
72
|
-
const
|
|
78
|
+
const probe = options?.probe ?? isDashboardRunning;
|
|
79
|
+
const status = await probe(port, undefined, { timeoutMs: 2000, retries: 2 });
|
|
73
80
|
if (status.running) return pid;
|
|
74
|
-
//
|
|
81
|
+
// Alive but not answering: a recycled pid or a hung server. Not ours to
|
|
82
|
+
// delete — the file stays; the caller just doesn't count it as running.
|
|
83
|
+
return null;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
|
-
//
|
|
86
|
+
// Dead process — the pid file is stale, clean it up.
|
|
78
87
|
removePid(options);
|
|
79
88
|
return null;
|
|
80
89
|
}
|