@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -2
- package/README.md +64 -18
- package/docs/architecture.md +2325 -270
- package/package.json +36 -20
- package/packages/extension/package.json +18 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +109 -70
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +31 -13
- package/packages/extension/src/bridge-handlers/lifecycle.ts +149 -66
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +309 -284
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +106 -37
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +153 -38
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +77 -6
- package/packages/extension/src/model-refresh.ts +69 -0
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +178 -30
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +487 -46
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +68 -10
- package/packages/extension/src/server-auto-start.ts +69 -3
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-sync.ts +53 -24
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-delivery.ts +11 -1
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +303 -64
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +12 -1
- package/packages/server/src/access/containment-gate.ts +113 -30
- package/packages/server/src/access/cwd-verdict.ts +3 -3
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +50 -11
- package/packages/server/src/access/planes.ts +107 -1
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/access/yolo-session.ts +54 -2
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +18 -5
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/auth/audit-log.ts +108 -0
- package/packages/server/src/auth/auth-plugin.ts +230 -38
- package/packages/server/src/auth/auth.ts +104 -4
- package/packages/server/src/auth/bearer-auth.ts +52 -12
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +90 -30
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +26 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +145 -11
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +69 -18
- package/packages/server/src/auth/localhost-guard.ts +98 -33
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
- package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-storage.ts +214 -12
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +111 -11
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +40 -2
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +34 -24
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +167 -63
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +146 -3
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +229 -53
- package/packages/server/src/config-api.ts +53 -35
- package/packages/server/src/config-snapshot.ts +197 -1
- package/packages/server/src/directory-service.ts +193 -68
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +322 -207
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +45 -11
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +18 -2
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +11 -3
- package/packages/server/src/identity/ws-road-classification.ts +3 -1
- package/packages/server/src/known-server-moves.ts +36 -15
- package/packages/server/src/lib/browse-roots.ts +129 -17
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +513 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/eml.ts +5 -10
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +96 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +49 -13
- package/packages/server/src/lib/path-containment.ts +50 -10
- package/packages/server/src/lib/resolve-file-mention.ts +234 -40
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +26 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/lifecycle/recovery-server.ts +65 -18
- package/packages/server/src/live-server/capability-redact.ts +31 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +615 -44
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +141 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +25 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +220 -33
- package/packages/server/src/live-server/live-server-proxy.ts +411 -50
- package/packages/server/src/live-server/live-static.ts +231 -0
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
- package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +141 -267
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/provider-probe.ts +202 -7
- package/packages/server/src/pairing/browser-gateway.ts +325 -51
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/paired-devices.ts +702 -27
- package/packages/server/src/pairing/pairing.ts +103 -11
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +61 -2
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/host-project-trust.ts +29 -15
- package/packages/server/src/pi/pi-gateway.ts +398 -41
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +18 -7
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +182 -15
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +640 -279
- package/packages/server/src/routes/file-write-binary-routes.ts +97 -24
- package/packages/server/src/routes/folder-project-routes.ts +18 -12
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +340 -273
- package/packages/server/src/routes/grep-routes.ts +64 -14
- package/packages/server/src/routes/known-servers-routes.ts +189 -91
- package/packages/server/src/routes/live-server-routes.ts +572 -15
- package/packages/server/src/routes/local-proof-routes.ts +14 -0
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +396 -31
- package/packages/server/src/routes/package-routes.ts +58 -10
- package/packages/server/src/routes/pairing-routes.ts +342 -17
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +181 -10
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/resource-activation-routes.ts +18 -4
- package/packages/server/src/routes/session-routes.ts +75 -25
- package/packages/server/src/routes/system-routes.ts +169 -52
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +1139 -291
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/memory-session-manager.ts +31 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +32 -4
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +393 -77
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/terminal/terminal-manager.ts +54 -46
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +2 -0
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +172 -26
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +285 -59
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +443 -187
- package/packages/shared/src/containment-guard.ts +45 -0
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +2 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +100 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +58 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +47 -3
- package/packages/shared/src/dashboard-plugin/slot-types.ts +9 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +39 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +94 -27
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +161 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +176 -0
- package/packages/shared/src/mdns-discovery.ts +25 -6
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-poller.ts +3 -2
- package/packages/shared/src/pairing-knock-client.ts +135 -11
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +21 -11
- package/packages/shared/src/pi-trust-mirror-types.ts +38 -3
- package/packages/shared/src/pi-trust-mirror.ts +47 -11
- package/packages/shared/src/pi-trust-resource-digest.ts +261 -0
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +14 -8
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +452 -5
- package/packages/shared/src/platform/resolve-pi-shell.ts +105 -0
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +192 -0
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +187 -86
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +97 -26
- package/packages/shared/src/recovery-timing.ts +27 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +148 -11
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +149 -4
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/server-launcher.ts +9 -1
- package/packages/shared/src/server-pinning.ts +55 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/definitions.ts +5 -5
- package/packages/shared/src/tool-registry/strategies.ts +13 -12
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +134 -109
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +15 -0
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +11 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content proof for REMOTE live trust answers: a salted digest of exactly what
|
|
3
|
+
* pi's project-trust gate protects for a cwd.
|
|
4
|
+
*
|
|
5
|
+
* pi decides "does this folder need trust" from `<cwd>/.pi/{settings.json,
|
|
6
|
+
* mcp.json, extensions, skills, prompts, themes, SYSTEM.md, APPEND_SYSTEM.md}`
|
|
7
|
+
* plus `<d>/.agents/skills` for the cwd and every ancestor (except the user's own
|
|
8
|
+
* `~/.agents/skills`). `trustResourceManifest` lists every entry under that set
|
|
9
|
+
* (files by content hash, directories by name) and the answer binds it to the
|
|
10
|
+
* cwd key with an HMAC over a fresh salt. Two sides trust only on equality of two
|
|
11
|
+
* computed digests, so a different folder at the same path (or a copy that
|
|
12
|
+
* differs in `.pi/mcp.json`) never inherits trust.
|
|
13
|
+
*
|
|
14
|
+
* Fail-closed → `null`: empty set, any symlink / non-regular entry, a read
|
|
15
|
+
* failure, a cap (1,000 entries / 16 MiB), unparseable or unrecognised
|
|
16
|
+
* `.pi/settings.json` references, or references to code outside the set.
|
|
17
|
+
* Async (`fs/promises`) with an AbortSignal checked after every awaited read, so
|
|
18
|
+
* the bridge's single deadline can stop the walk.
|
|
19
|
+
*
|
|
20
|
+
* Node-only. See change: mirror-dashboard-trust-live-remote (D5).
|
|
21
|
+
*/
|
|
22
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
23
|
+
import * as fsp from "node:fs/promises";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { nativePathApi, type PathApi, piPathsEqual } from "./pi-path-compare.js";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* pi does not export its own list (`TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES`),
|
|
29
|
+
* so ours is a literal, pinned to pi's by a golden test.
|
|
30
|
+
*/
|
|
31
|
+
export const TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES: readonly string[] = [
|
|
32
|
+
"settings.json",
|
|
33
|
+
"mcp.json",
|
|
34
|
+
"extensions",
|
|
35
|
+
"skills",
|
|
36
|
+
"prompts",
|
|
37
|
+
"themes",
|
|
38
|
+
"SYSTEM.md",
|
|
39
|
+
"APPEND_SYSTEM.md",
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/** `.pi` subtrees a settings reference may legitimately point into (all hashed recursively). */
|
|
43
|
+
const CODE_SUBTREES = ["extensions", "skills", "prompts", "themes"] as const;
|
|
44
|
+
|
|
45
|
+
export const TRUST_RESOURCE_MAX_ENTRIES = 1000;
|
|
46
|
+
export const TRUST_RESOURCE_MAX_BYTES = 16 * 1024 * 1024;
|
|
47
|
+
|
|
48
|
+
const DIGEST_DOMAIN = "pi-trust-live/v1";
|
|
49
|
+
|
|
50
|
+
class FailClosed extends Error {}
|
|
51
|
+
|
|
52
|
+
interface Walk {
|
|
53
|
+
entries: Array<{ label: string; line: string }>;
|
|
54
|
+
bytes: number;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function checkAbort(w: Walk): void {
|
|
59
|
+
if (w.signal?.aborted) throw new FailClosed("aborted");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function addEntry(w: Walk, label: string, line: string): void {
|
|
63
|
+
if (w.entries.length >= TRUST_RESOURCE_MAX_ENTRIES) throw new FailClosed("too many entries");
|
|
64
|
+
w.entries.push({ label, line });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function lstatOrNull(p: string, w: Walk): Promise<import("node:fs").Stats | null> {
|
|
68
|
+
try {
|
|
69
|
+
const st = await fsp.lstat(p);
|
|
70
|
+
checkAbort(w);
|
|
71
|
+
return st;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
checkAbort(w);
|
|
74
|
+
if ((err as NodeJS.ErrnoException)?.code === "ENOENT" || (err as NodeJS.ErrnoException)?.code === "ENOTDIR") return null;
|
|
75
|
+
throw new FailClosed("stat failed");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function addDirectory(w: Walk, abs: string, label: string): Promise<void> {
|
|
80
|
+
addEntry(w, label, `${label}\0d`);
|
|
81
|
+
// Iterate (not `readdir`): a directory of millions of names stops at the entry cap
|
|
82
|
+
// instead of being listed into memory first.
|
|
83
|
+
let handle: import("node:fs").Dir;
|
|
84
|
+
try {
|
|
85
|
+
handle = await fsp.opendir(abs);
|
|
86
|
+
} catch {
|
|
87
|
+
throw new FailClosed("readdir failed");
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
for await (const ent of handle) {
|
|
91
|
+
checkAbort(w);
|
|
92
|
+
await addTree(w, path.join(abs, ent.name), `${label}/${ent.name}`);
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof FailClosed) throw err;
|
|
96
|
+
throw new FailClosed("readdir failed");
|
|
97
|
+
} finally {
|
|
98
|
+
await handle.close().catch(() => undefined);
|
|
99
|
+
}
|
|
100
|
+
checkAbort(w);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function addFile(w: Walk, abs: string, label: string, size: number): Promise<void> {
|
|
104
|
+
if (w.bytes + size > TRUST_RESOURCE_MAX_BYTES) throw new FailClosed("too large");
|
|
105
|
+
w.bytes += size;
|
|
106
|
+
let buf: Buffer;
|
|
107
|
+
try {
|
|
108
|
+
buf = await fsp.readFile(abs, w.signal ? { signal: w.signal } : undefined);
|
|
109
|
+
} catch {
|
|
110
|
+
throw new FailClosed("read failed");
|
|
111
|
+
}
|
|
112
|
+
checkAbort(w);
|
|
113
|
+
addEntry(w, label, `${label}\0f\0${createHash("sha256").update(buf).digest("hex")}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Add `abs` (labelled `label`) and, for a directory, everything below it. */
|
|
117
|
+
async function addTree(w: Walk, abs: string, label: string): Promise<boolean> {
|
|
118
|
+
const st = await lstatOrNull(abs, w);
|
|
119
|
+
if (!st) return false;
|
|
120
|
+
if (st.isSymbolicLink()) throw new FailClosed("symlink");
|
|
121
|
+
if (st.isDirectory()) await addDirectory(w, abs, label);
|
|
122
|
+
else if (st.isFile()) await addFile(w, abs, label, st.size);
|
|
123
|
+
else throw new FailClosed("special file");
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function withinOrEqual(child: string, parent: string): boolean {
|
|
128
|
+
const rel = path.relative(parent, child);
|
|
129
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** One settings reference: optional include/exclude marker, optional glob tail; must resolve inside `roots`. */
|
|
133
|
+
function referenceInside(item: unknown, piDir: string, roots: readonly string[]): boolean {
|
|
134
|
+
if (typeof item !== "string") return false;
|
|
135
|
+
let ref = item;
|
|
136
|
+
if (ref.startsWith("!") || ref.startsWith("+") || ref.startsWith("-")) ref = ref.slice(1);
|
|
137
|
+
const glob = ref.search(/[*?[{]/);
|
|
138
|
+
if (glob >= 0) ref = ref.slice(0, ref.lastIndexOf("/", glob) + 1) || ".";
|
|
139
|
+
const resolved = path.resolve(piDir, ref);
|
|
140
|
+
return roots.some((r) => withinOrEqual(resolved, r));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function readSettings(w: Walk, file: string): Promise<Record<string, unknown>> {
|
|
144
|
+
let parsed: unknown;
|
|
145
|
+
try {
|
|
146
|
+
parsed = JSON.parse(await fsp.readFile(file, "utf8"));
|
|
147
|
+
} catch {
|
|
148
|
+
throw new FailClosed("settings unparseable");
|
|
149
|
+
}
|
|
150
|
+
checkAbort(w);
|
|
151
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new FailClosed("settings shape");
|
|
152
|
+
return parsed as Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* `.pi/settings.json` may point pi at code. Every reference must stay inside the
|
|
157
|
+
* hashed subtrees; `packages` (fetched by pi) and any shape we do not recognise
|
|
158
|
+
* fail closed.
|
|
159
|
+
*/
|
|
160
|
+
async function checkSettingsRefs(w: Walk, piDir: string): Promise<void> {
|
|
161
|
+
const file = path.join(piDir, "settings.json");
|
|
162
|
+
if (!(await lstatOrNull(file, w))) return;
|
|
163
|
+
const obj = await readSettings(w, file);
|
|
164
|
+
if ("packages" in obj && (!Array.isArray(obj.packages) || obj.packages.length > 0)) {
|
|
165
|
+
throw new FailClosed("packages referenced");
|
|
166
|
+
}
|
|
167
|
+
const roots = CODE_SUBTREES.map((n) => path.join(piDir, n));
|
|
168
|
+
for (const key of CODE_SUBTREES) {
|
|
169
|
+
if (!(key in obj)) continue;
|
|
170
|
+
const list = obj[key];
|
|
171
|
+
if (!Array.isArray(list)) throw new FailClosed("reference shape");
|
|
172
|
+
if (!list.every((item) => referenceInside(item, piDir, roots))) throw new FailClosed("reference outside set");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function compareCodePoints(a: string, b: string): number {
|
|
177
|
+
const ai = Array.from(a);
|
|
178
|
+
const bi = Array.from(b);
|
|
179
|
+
const n = Math.min(ai.length, bi.length);
|
|
180
|
+
for (let i = 0; i < n; i += 1) {
|
|
181
|
+
const x = ai[i].codePointAt(0) as number;
|
|
182
|
+
const y = bi[i].codePointAt(0) as number;
|
|
183
|
+
if (x !== y) return x - y;
|
|
184
|
+
}
|
|
185
|
+
return ai.length - bi.length;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function realOrSelf(p: string, pathApi: PathApi): Promise<string> {
|
|
189
|
+
try {
|
|
190
|
+
return await fsp.realpath(p);
|
|
191
|
+
} catch {
|
|
192
|
+
return pathApi.resolve(p);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** `<cwd>/.pi/<resource>` for every name pi's gate protects (a symlinked `.pi` fails closed). */
|
|
197
|
+
async function collectPiResources(w: Walk, cwd: string): Promise<void> {
|
|
198
|
+
const piDir = path.join(cwd, ".pi");
|
|
199
|
+
const piStat = await lstatOrNull(piDir, w);
|
|
200
|
+
if (!piStat) return;
|
|
201
|
+
if (piStat.isSymbolicLink()) throw new FailClosed("symlink");
|
|
202
|
+
if (!piStat.isDirectory()) return;
|
|
203
|
+
await checkSettingsRefs(w, piDir);
|
|
204
|
+
for (const name of TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES) {
|
|
205
|
+
await addTree(w, path.join(piDir, name), `c/${name}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* `<d>/.agents/skills` for the cwd and every ancestor, except the user's own —
|
|
211
|
+
* excluded with pi's `pathsEqual` (1.5.0 `trust-manager.js:167`).
|
|
212
|
+
*/
|
|
213
|
+
async function collectAgentSkills(w: Walk, cwd: string, userSkills: string, pathApi: PathApi): Promise<void> {
|
|
214
|
+
for (let dir = cwd, k = 0; ; k += 1) {
|
|
215
|
+
const agents = pathApi.join(dir, ".agents");
|
|
216
|
+
const agentsStat = await lstatOrNull(agents, w);
|
|
217
|
+
if (agentsStat?.isSymbolicLink()) throw new FailClosed("symlink");
|
|
218
|
+
const skills = pathApi.join(agents, "skills");
|
|
219
|
+
if (!piPathsEqual(skills, userSkills, pathApi) && agentsStat) await addTree(w, skills, `a${k}`);
|
|
220
|
+
const parent = pathApi.dirname(dir);
|
|
221
|
+
if (parent === dir) return;
|
|
222
|
+
dir = parent;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The manifest of pi's trust-requiring resources for `cwd` (a canonical key), or
|
|
228
|
+
* `null` when the set is empty or cannot be bound. `home` is this side's own home
|
|
229
|
+
* (its `.agents/skills` is the user's, excluded). `pathApi` (default native) is
|
|
230
|
+
* the path module for the skills walk and that exclusion (win32 testable anywhere).
|
|
231
|
+
*/
|
|
232
|
+
export async function trustResourceManifest(
|
|
233
|
+
cwd: string,
|
|
234
|
+
opts: { home: string; signal?: AbortSignal; pathApi?: PathApi },
|
|
235
|
+
): Promise<string | null> {
|
|
236
|
+
const w: Walk = { entries: [], bytes: 0, signal: opts.signal };
|
|
237
|
+
try {
|
|
238
|
+
checkAbort(w);
|
|
239
|
+
const pathApi = opts.pathApi ?? nativePathApi();
|
|
240
|
+
const userSkills = pathApi.join(await realOrSelf(opts.home, pathApi), ".agents", "skills");
|
|
241
|
+
checkAbort(w);
|
|
242
|
+
await collectPiResources(w, cwd);
|
|
243
|
+
await collectAgentSkills(w, cwd, userSkills, pathApi);
|
|
244
|
+
if (w.entries.length === 0) return null;
|
|
245
|
+
w.entries.sort((a, b) => compareCodePoints(a.label, b.label));
|
|
246
|
+
return w.entries.map((e) => e.line).join("\n");
|
|
247
|
+
} catch {
|
|
248
|
+
// FailClosed or anything unexpected: no binding, no trust.
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** 16 random bytes, hex. Fresh per answer. */
|
|
254
|
+
export function newTrustSalt(): string {
|
|
255
|
+
return randomBytes(16).toString("hex");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** `HMAC-SHA256(salt, "pi-trust-live/v1\n" + cwdKey + "\n" + manifest)`, hex. */
|
|
259
|
+
export function trustResourceDigest(salt: string, cwdKey: string, manifest: string): string {
|
|
260
|
+
return createHmac("sha256", salt).update(`${DIGEST_DOMAIN}\n${cwdKey}\n${manifest}`).digest("hex");
|
|
261
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE builder for a pi process's pid-namespace report. Used at every bridge
|
|
3
|
+
* `session_register` site, in-process by the ACP bridge, and by the server for
|
|
4
|
+
* its own `ServerPidContext` — so both sides compare like with like.
|
|
5
|
+
*
|
|
6
|
+
* - `kind`/`distro`: `"wsl"` + `WSL_DISTRO_NAME` when that env var is non-empty.
|
|
7
|
+
* - `nsId`: Linux only, the `/proc/self/ns/pid` link.
|
|
8
|
+
* - `hostId`: Linux `/proc/sys/kernel/random/boot_id` (no hostname fallback);
|
|
9
|
+
* elsewhere `os.hostname()` (a weak discriminator, documented in design Risks).
|
|
10
|
+
* - Unreadable fields are omitted, never `null`; the builder never throws.
|
|
11
|
+
*
|
|
12
|
+
* Node-only (fs/os): never import from the client bundle.
|
|
13
|
+
* See change: scope-pids-to-namespace.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, readlinkSync } from "node:fs";
|
|
16
|
+
import { hostname as osHostname } from "node:os";
|
|
17
|
+
import type { PidNamespace } from "./types.js";
|
|
18
|
+
|
|
19
|
+
export type { PidNamespace } from "./types.js";
|
|
20
|
+
|
|
21
|
+
/** Injectable seams (tests); every field defaults to the real process/OS. */
|
|
22
|
+
export interface PidNamespaceOpts {
|
|
23
|
+
platform?: NodeJS.Platform | string;
|
|
24
|
+
env?: Record<string, string | undefined>;
|
|
25
|
+
readlink?: (path: string) => string;
|
|
26
|
+
readFile?: (path: string) => string;
|
|
27
|
+
hostname?: () => string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The server's own namespace, computed once at startup. */
|
|
31
|
+
export interface ServerPidContext {
|
|
32
|
+
platform: string;
|
|
33
|
+
hostId?: string;
|
|
34
|
+
nsId?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const NS_LINK = "/proc/self/ns/pid";
|
|
38
|
+
const BOOT_ID = "/proc/sys/kernel/random/boot_id";
|
|
39
|
+
|
|
40
|
+
function attempt(read: () => string): string | undefined {
|
|
41
|
+
try {
|
|
42
|
+
const v = read().trim();
|
|
43
|
+
return v === "" ? undefined : v;
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function buildPidNamespace(opts: PidNamespaceOpts = {}): PidNamespace {
|
|
50
|
+
const platform = opts.platform ?? process.platform;
|
|
51
|
+
const env = opts.env ?? process.env;
|
|
52
|
+
const readlink = opts.readlink ?? ((p: string) => readlinkSync(p));
|
|
53
|
+
const readFile = opts.readFile ?? ((p: string) => readFileSync(p, "utf8"));
|
|
54
|
+
const hostname = opts.hostname ?? osHostname;
|
|
55
|
+
|
|
56
|
+
const distro = env.WSL_DISTRO_NAME;
|
|
57
|
+
const ns: PidNamespace = distro ? { platform, kind: "wsl", distro } : { platform, kind: "host" };
|
|
58
|
+
|
|
59
|
+
if (platform === "linux") {
|
|
60
|
+
const nsId = attempt(() => readlink(NS_LINK));
|
|
61
|
+
if (nsId !== undefined) ns.nsId = nsId;
|
|
62
|
+
const hostId = attempt(() => readFile(BOOT_ID));
|
|
63
|
+
if (hostId !== undefined) ns.hostId = hostId;
|
|
64
|
+
} else {
|
|
65
|
+
const hostId = attempt(hostname);
|
|
66
|
+
if (hostId !== undefined) ns.hostId = hostId;
|
|
67
|
+
}
|
|
68
|
+
return ns;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let processNs: PidNamespace | undefined;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* THIS process's namespace, built once and reused: every register a bridge
|
|
75
|
+
* sends (first, reattach, provisional) therefore carries the identical value.
|
|
76
|
+
*/
|
|
77
|
+
export function processPidNamespace(): PidNamespace {
|
|
78
|
+
processNs ??= buildPidNamespace();
|
|
79
|
+
return processNs;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The server's context: the same builder, reduced to the compared fields. */
|
|
83
|
+
export function buildServerPidContext(opts: PidNamespaceOpts = {}): ServerPidContext {
|
|
84
|
+
const { platform, hostId, nsId } = buildPidNamespace(opts);
|
|
85
|
+
return { platform, ...(hostId !== undefined ? { hostId } : {}), ...(nsId !== undefined ? { nsId } : {}) };
|
|
86
|
+
}
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* Layout verified by the R1 CI spike (dugite-native v2.53.0-3):
|
|
7
7
|
* cmd/git.exe git launcher
|
|
8
8
|
* usr/bin/sh.exe POSIX shell (GNU bash under the name `sh`;
|
|
9
|
-
* dugite-native ships NO bash.exe).
|
|
10
|
-
*
|
|
9
|
+
* dugite-native ships NO bash.exe).
|
|
10
|
+
* usr/bin/bash.exe byte copy of sh.exe added by the build step
|
|
11
|
+
* (download-git-windows.mjs). pi's getShellConfig()
|
|
12
|
+
* (bash tool, `!`, `!cmd`) resolves only a file named
|
|
13
|
+
* bash.exe — never sh.exe — so this is the file pi
|
|
14
|
+
* picks when usr/bin precedes System32 on PATH.
|
|
11
15
|
* <libdir>/bin git core libs + DLLs. <libdir> is
|
|
12
16
|
* arch-specific: `mingw64` on win32-x64,
|
|
13
17
|
* `clangarm64` on win32-arm64.
|
|
@@ -19,11 +23,11 @@
|
|
|
19
23
|
* This module is the ONLY place allowed to reference bundled-git paths
|
|
20
24
|
* (enforced by no-hardcoded-bundled-git-paths.test.ts).
|
|
21
25
|
*
|
|
22
|
-
* See change: embed-git-bash-on-windows.
|
|
26
|
+
* See change: embed-git-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
23
27
|
*/
|
|
24
28
|
import { existsSync } from "node:fs";
|
|
25
29
|
import path from "node:path";
|
|
26
|
-
import type { GitSource } from "./select-git-source.js";
|
|
30
|
+
import type { GitSource, WindowsBashSourceSetting } from "./select-git-source.js";
|
|
27
31
|
|
|
28
32
|
/** Arch-specific MinGW/Clang library dir names, in probe order. */
|
|
29
33
|
const GIT_LIBDIRS = ["mingw64", "clangarm64"] as const;
|
|
@@ -90,6 +94,52 @@ export interface EnsureBundledGitOpts {
|
|
|
90
94
|
candidates?: string[];
|
|
91
95
|
/** Override `fs.existsSync` for tests. */
|
|
92
96
|
exists?: (p: string) => boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Where `usr/bin` (the bundled bash) sits on PATH. "bundled" (default) →
|
|
99
|
+
* prepended ahead of System32; "host" → appended last so pi resolves the
|
|
100
|
+
* host's first `bash.exe`. See change: fix-windows-bundled-bash-exe.
|
|
101
|
+
*/
|
|
102
|
+
bashSource?: WindowsBashSourceSetting;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Slash-normalised, trailing-separator-trimmed, case-folded PATH entry key. */
|
|
106
|
+
const entryKey = (e: string): string => e.trim().replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase();
|
|
107
|
+
|
|
108
|
+
/** Existing, de-duplicated (case/slash-insensitive) subset of `dirs`, order kept. */
|
|
109
|
+
function existingUnique(dirs: string[], exists: (p: string) => boolean): string[] {
|
|
110
|
+
const seen = new Set<string>();
|
|
111
|
+
return dirs.filter((dir) => {
|
|
112
|
+
const k = entryKey(dir);
|
|
113
|
+
if (!exists(dir) || seen.has(k)) return false;
|
|
114
|
+
seen.add(k);
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Placement. `cmd` + `<libdir>/bin` always precede the inherited PATH. `usr/bin`
|
|
121
|
+
* (bash.exe + MSYS coreutils) precedes it in "bundled" mode and follows it in
|
|
122
|
+
* "host" mode. Existing entries for the dirs being placed are stripped first
|
|
123
|
+
* (case/trailing-slash-insensitive) so switching mode MOVES usr/bin and
|
|
124
|
+
* re-applying is idempotent. Operates on the already-normalised `PATH` key
|
|
125
|
+
* (callers run normalizeEnvPathKey first).
|
|
126
|
+
*/
|
|
127
|
+
function placeBundledDirs(
|
|
128
|
+
currentPath: string,
|
|
129
|
+
gitDir: string,
|
|
130
|
+
libDir: string | null,
|
|
131
|
+
bashSource: WindowsBashSourceSetting,
|
|
132
|
+
exists: (p: string) => boolean,
|
|
133
|
+
): string {
|
|
134
|
+
const join = path.win32.join;
|
|
135
|
+
const usrBin = join(gitDir, "usr", "bin");
|
|
136
|
+
const front = [join(gitDir, "cmd"), ...(bashSource === "bundled" ? [usrBin] : []), ...(libDir ? [join(gitDir, libDir, "bin")] : [])];
|
|
137
|
+
const frontOk = existingUnique(front, exists);
|
|
138
|
+
const backOk = existingUnique(bashSource === "host" ? [usrBin] : [], exists);
|
|
139
|
+
|
|
140
|
+
const ours = new Set([...frontOk, ...backOk].map(entryKey));
|
|
141
|
+
const rest = currentPath.split(";").filter((e) => e.trim() !== "" && !ours.has(entryKey(e)));
|
|
142
|
+
return [...frontOk, ...rest, ...backOk].join(";");
|
|
93
143
|
}
|
|
94
144
|
|
|
95
145
|
/**
|
|
@@ -126,37 +176,10 @@ export function ensureBundledGitOnPath(
|
|
|
126
176
|
const join = path.win32.join;
|
|
127
177
|
const libDir = resolveLibDir(gitDir, exists);
|
|
128
178
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const dirs = [join(gitDir, "cmd"), join(gitDir, "usr", "bin")];
|
|
132
|
-
if (libDir) dirs.push(join(gitDir, libDir, "bin"));
|
|
133
|
-
|
|
134
|
-
const currentPath = env.PATH ?? "";
|
|
135
|
-
// Exact per-entry equality (case-insensitive), NOT substring containment:
|
|
136
|
-
// substring matching would let `C:\x\usr\bin-old` block the required
|
|
137
|
-
// `C:\x\usr\bin` prepend. Trailing separators trimmed.
|
|
138
|
-
const present = new Set(
|
|
139
|
-
currentPath
|
|
140
|
-
.split(";")
|
|
141
|
-
.map((e) => e.trim().replace(/[\\/]+$/, "").toLowerCase())
|
|
142
|
-
.filter(Boolean),
|
|
143
|
-
);
|
|
144
|
-
const seen = new Set<string>();
|
|
145
|
-
const toAdd: string[] = [];
|
|
146
|
-
for (const dir of dirs) {
|
|
147
|
-
if (!exists(dir)) continue;
|
|
148
|
-
const lower = dir.replace(/[\\/]+$/, "").toLowerCase();
|
|
149
|
-
if (present.has(lower) || seen.has(lower)) continue;
|
|
150
|
-
seen.add(lower);
|
|
151
|
-
toAdd.push(dir);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const DELIM = ";";
|
|
179
|
+
const bashSource = opts.bashSource === "host" ? "host" : "bundled";
|
|
180
|
+
const newPath = placeBundledDirs(env.PATH ?? "", gitDir, libDir, bashSource, exists);
|
|
155
181
|
let out = env;
|
|
156
|
-
if (
|
|
157
|
-
const newPath = currentPath
|
|
158
|
-
? `${toAdd.join(DELIM)}${DELIM}${currentPath}`
|
|
159
|
-
: toAdd.join(DELIM);
|
|
182
|
+
if (newPath !== (env.PATH ?? "")) {
|
|
160
183
|
out = { ...out, PATH: newPath };
|
|
161
184
|
}
|
|
162
185
|
|
|
@@ -12,19 +12,24 @@
|
|
|
12
12
|
* injected by the caller to avoid a binary-lookup ↔ git-source import
|
|
13
13
|
* cycle.
|
|
14
14
|
*
|
|
15
|
-
* See change: embed-git-bash-on-windows.
|
|
15
|
+
* See change: embed-git-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type GitSource,
|
|
20
|
-
type WindowsGitSourceSetting,
|
|
21
|
-
} from "./select-git-source.js";
|
|
17
|
+
|
|
18
|
+
import path from "node:path";
|
|
22
19
|
import {
|
|
23
20
|
ensureBundledGitOnPath,
|
|
24
21
|
resolveBundledGitDir,
|
|
25
22
|
} from "./ensure-bundled-git.js";
|
|
23
|
+
import { ensureWindowsSystemPath } from "./ensure-windows-path.js";
|
|
24
|
+
import { normalizeEnvPathKey } from "./env-path-key.js";
|
|
26
25
|
import { spawnSync } from "./exec.js";
|
|
27
|
-
import
|
|
26
|
+
import { resolvePiShell } from "./resolve-pi-shell.js";
|
|
27
|
+
import {
|
|
28
|
+
type GitSource,
|
|
29
|
+
selectGitSource,
|
|
30
|
+
type WindowsBashSourceSetting,
|
|
31
|
+
type WindowsGitSourceSetting,
|
|
32
|
+
} from "./select-git-source.js";
|
|
28
33
|
|
|
29
34
|
export type WhichFn = (cmd: string) => string | null;
|
|
30
35
|
|
|
@@ -33,11 +38,26 @@ export interface ActiveGitSource {
|
|
|
33
38
|
setting: WindowsGitSourceSetting;
|
|
34
39
|
/** Bundled git root when source is "bundled" and present, else null. */
|
|
35
40
|
gitDir: string | null;
|
|
41
|
+
/** Where bundled `usr/bin` sits on PATH (only matters when source is "bundled"). */
|
|
42
|
+
bashSetting: WindowsBashSourceSetting;
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
let configuredSetting: WindowsGitSourceSetting = "auto";
|
|
46
|
+
let bashSetting: WindowsBashSourceSetting = "bundled";
|
|
39
47
|
let cached: ActiveGitSource | null = null;
|
|
40
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Seed the configured bash placement (server reads `windowsBashSource` from
|
|
51
|
+
* DashboardConfig). Invalidates both caches. See change: fix-windows-bundled-bash-exe.
|
|
52
|
+
*/
|
|
53
|
+
export function setWindowsBashSourceSetting(setting: WindowsBashSourceSetting): void {
|
|
54
|
+
const next: WindowsBashSourceSetting = setting === "host" ? "host" : "bundled";
|
|
55
|
+
if (next !== bashSetting) {
|
|
56
|
+
bashSetting = next;
|
|
57
|
+
invalidateGitSourceCache();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
41
61
|
/** Seed the configured setting (server reads it from DashboardConfig). */
|
|
42
62
|
export function setWindowsGitSourceSetting(setting: WindowsGitSourceSetting): void {
|
|
43
63
|
if (setting !== configuredSetting) {
|
|
@@ -56,6 +76,10 @@ export interface GitSourceResolveOpts {
|
|
|
56
76
|
/** Override `process.resourcesPath` for tests / standalone bundles. */
|
|
57
77
|
resourcesPath?: string;
|
|
58
78
|
candidates?: string[];
|
|
79
|
+
/** Override `process.platform` (test seam). */
|
|
80
|
+
platform?: NodeJS.Platform;
|
|
81
|
+
/** Override `fs.existsSync` (test seam). */
|
|
82
|
+
exists?: (p: string) => boolean;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
/**
|
|
@@ -64,15 +88,17 @@ export interface GitSourceResolveOpts {
|
|
|
64
88
|
*/
|
|
65
89
|
export function getActiveGitSource(which: WhichFn, opts: GitSourceResolveOpts = {}): ActiveGitSource {
|
|
66
90
|
if (cached) return cached;
|
|
67
|
-
const source = selectGitSource({ setting: configuredSetting, which });
|
|
91
|
+
const source = selectGitSource({ setting: configuredSetting, which, platform: opts.platform });
|
|
68
92
|
const gitDir =
|
|
69
93
|
source === "bundled"
|
|
70
94
|
? resolveBundledGitDir({
|
|
95
|
+
platform: opts.platform,
|
|
71
96
|
resourcesPath: opts.resourcesPath ?? (process as { resourcesPath?: string }).resourcesPath,
|
|
72
97
|
candidates: opts.candidates,
|
|
98
|
+
exists: opts.exists,
|
|
73
99
|
})
|
|
74
100
|
: null;
|
|
75
|
-
cached = { source, setting: configuredSetting, gitDir };
|
|
101
|
+
cached = { source, setting: configuredSetting, gitDir, bashSetting };
|
|
76
102
|
return cached;
|
|
77
103
|
}
|
|
78
104
|
|
|
@@ -87,8 +113,14 @@ export function augmentEnvWithGitSource(
|
|
|
87
113
|
opts: GitSourceResolveOpts = {},
|
|
88
114
|
): NodeJS.ProcessEnv {
|
|
89
115
|
try {
|
|
90
|
-
const { source, gitDir } = getActiveGitSource(which, opts);
|
|
91
|
-
return ensureBundledGitOnPath(env, {
|
|
116
|
+
const { source, gitDir, bashSetting: bashSource } = getActiveGitSource(which, opts);
|
|
117
|
+
return ensureBundledGitOnPath(env, {
|
|
118
|
+
source,
|
|
119
|
+
gitDir,
|
|
120
|
+
bashSource,
|
|
121
|
+
platform: opts.platform,
|
|
122
|
+
exists: opts.exists,
|
|
123
|
+
});
|
|
92
124
|
} catch {
|
|
93
125
|
return env;
|
|
94
126
|
}
|
|
@@ -101,8 +133,26 @@ export interface GitSourceReadout {
|
|
|
101
133
|
gitPath: string | null;
|
|
102
134
|
/** `git --version` output, or null when unresolved. */
|
|
103
135
|
gitVersion: string | null;
|
|
104
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* The `bash.exe` pi-coding-agent would resolve for a fresh spawn (pi's
|
|
138
|
+
* getShellConfig order over the augmented spawn env), or null. Never `sh.exe`.
|
|
139
|
+
*/
|
|
105
140
|
shellPath: string | null;
|
|
141
|
+
/** Effective `windowsBashSource` placement. */
|
|
142
|
+
bashSetting: WindowsBashSourceSetting;
|
|
143
|
+
/** `shellPath` is the System32/Sysnative WSL launcher (pi stdin-transport shell). */
|
|
144
|
+
shellIsWslLauncher: boolean;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface GitSourceReadoutOpts extends GitSourceResolveOpts {
|
|
148
|
+
/**
|
|
149
|
+
* The env a real spawn would receive (`ToolResolver.buildSpawnEnv(process.env)`),
|
|
150
|
+
* or a thunk for it — evaluated only on a readout-cache miss on win32, so
|
|
151
|
+
* health polls on other platforms / cache hits pay nothing. When omitted, a
|
|
152
|
+
* minimal equivalent is derived from `process.env` (normalised PATH key +
|
|
153
|
+
* System32 + bundled git).
|
|
154
|
+
*/
|
|
155
|
+
spawnEnv?: NodeJS.ProcessEnv | (() => NodeJS.ProcessEnv);
|
|
106
156
|
}
|
|
107
157
|
|
|
108
158
|
let readoutCache: GitSourceReadout | null = null;
|
|
@@ -119,27 +169,39 @@ function probeVersion(gitPath: string): string | null {
|
|
|
119
169
|
/**
|
|
120
170
|
* Windows-only diagnostic readout for /api/health + Diagnostics. Returns
|
|
121
171
|
* null on macOS/Linux (the setting is a no-op there). Cached for the life
|
|
122
|
-
* of the process; reset by invalidateGitSourceCache()
|
|
172
|
+
* of the process; reset by invalidateGitSourceCache() (config write) — NOT
|
|
173
|
+
* re-probed when Git for Windows is installed/removed at runtime.
|
|
174
|
+
*
|
|
175
|
+
* Documented residuals: the session cwd (`where.exe` searches it first) and a
|
|
176
|
+
* user-set pi `shellPath` (applies to the bash tool and `!` only).
|
|
123
177
|
*/
|
|
124
|
-
export function getGitSourceReadout(which: WhichFn, opts:
|
|
125
|
-
|
|
178
|
+
export function getGitSourceReadout(which: WhichFn, opts: GitSourceReadoutOpts = {}): GitSourceReadout | null {
|
|
179
|
+
const platform = opts.platform ?? process.platform;
|
|
180
|
+
if (platform !== "win32") return null;
|
|
126
181
|
if (readoutCache) return readoutCache;
|
|
127
|
-
const { source, setting, gitDir } = getActiveGitSource(which, opts);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
182
|
+
const { source, setting, gitDir, bashSetting: bashSource } = getActiveGitSource(which, opts);
|
|
183
|
+
const exists = opts.exists;
|
|
184
|
+
const join = path.win32.join;
|
|
185
|
+
|
|
186
|
+
const gitPath = source === "bundled" && gitDir ? join(gitDir, "cmd", "git.exe") : which("git");
|
|
187
|
+
|
|
188
|
+
const spawnEnv =
|
|
189
|
+
(typeof opts.spawnEnv === "function" ? opts.spawnEnv() : opts.spawnEnv) ??
|
|
190
|
+
augmentEnvWithGitSource(
|
|
191
|
+
ensureWindowsSystemPath(normalizeEnvPathKey({ ...process.env }, platform), { platform, exists }),
|
|
192
|
+
which,
|
|
193
|
+
opts,
|
|
194
|
+
);
|
|
195
|
+
const shell = resolvePiShell({ env: spawnEnv, exists });
|
|
196
|
+
|
|
137
197
|
readoutCache = {
|
|
138
198
|
setting,
|
|
139
199
|
source,
|
|
140
200
|
gitPath,
|
|
141
201
|
gitVersion: gitPath ? probeVersion(gitPath) : null,
|
|
142
|
-
shellPath,
|
|
202
|
+
shellPath: shell?.path ?? null,
|
|
203
|
+
bashSetting: bashSource,
|
|
204
|
+
shellIsWslLauncher: shell?.isWslLauncher ?? false,
|
|
143
205
|
};
|
|
144
206
|
return readoutCache;
|
|
145
207
|
}
|