@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,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge half of the sudo credential prompt.
|
|
3
|
+
*
|
|
4
|
+
* Observes `dashboard_identity` (modelled on `vault-delivery.ts` `handleIdentity`)
|
|
5
|
+
* and, while the server advertises `sudo-credential`, the setting is on, the
|
|
6
|
+
* platform is not win32 and the operator set no `SUDO_ASKPASS` of their own,
|
|
7
|
+
* installs the askpass wrapper and points `process.env.SUDO_ASKPASS` at it. The
|
|
8
|
+
* helper asks over a unix socket; the bridge applies the anti-accident gate (a
|
|
9
|
+
* bash / `user_bash` call in flight, one pending prompt, not Cancel-blocked,
|
|
10
|
+
* server connected), consults the per-session cache, otherwise asks the operator
|
|
11
|
+
* through the server relay and delivers the answer to the helper.
|
|
12
|
+
*
|
|
13
|
+
* Never logged or thrown: the password. Log lines carry type + callId only.
|
|
14
|
+
*
|
|
15
|
+
* See change: add-sudo-credential-prompt (D3, D4, D7, D9, D10).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { randomBytes } from "node:crypto";
|
|
19
|
+
import type net from "node:net";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import type {
|
|
22
|
+
SudoCredentialCacheMessage,
|
|
23
|
+
SudoCredentialDismissMessage,
|
|
24
|
+
SudoCredentialRequestMessage,
|
|
25
|
+
} from "@blackbelt-technology/pi-dashboard-shared/protocol.js";
|
|
26
|
+
import {
|
|
27
|
+
parseSudoCredentialPrompt,
|
|
28
|
+
SUDO_CREDENTIAL_FEATURE,
|
|
29
|
+
SUDO_CREDENTIAL_MAX_PASSWORD_LENGTH,
|
|
30
|
+
type SudoCredentialPromptConfig,
|
|
31
|
+
} from "@blackbelt-technology/pi-dashboard-shared/sudo-credential.js";
|
|
32
|
+
import type { BashOperationsLike } from "../vault-redaction.js";
|
|
33
|
+
import { createInFlightTracker } from "./in-flight.js";
|
|
34
|
+
import { installAskpass, type InstalledAskpass } from "./install.js";
|
|
35
|
+
import { createInvocationCounters, createPasswordCache } from "./password-cache.js";
|
|
36
|
+
import { buildPromptDisplay } from "./prompt-text.js";
|
|
37
|
+
import { SUDO_HELPER_MAX_REQUEST_BYTES, SUDO_HELPER_OK_MAGIC, SUDO_HELPER_REFUSE } from "./protocol.js";
|
|
38
|
+
import { registerSudoPassword } from "./sudo-mask-registry.js";
|
|
39
|
+
|
|
40
|
+
type SudoOutbound = SudoCredentialRequestMessage | SudoCredentialDismissMessage | SudoCredentialCacheMessage;
|
|
41
|
+
|
|
42
|
+
/** sudo's default `passwd_tries`: the invocation at this ordinal is the last one sudo will make. */
|
|
43
|
+
const SUDO_FINAL_INVOCATION = 3;
|
|
44
|
+
const HELPER_REQUEST_READ_TIMEOUT_MS = 5_000;
|
|
45
|
+
const COUNTER_WINDOW_FALLBACK_MINUTES = 5;
|
|
46
|
+
|
|
47
|
+
export interface SudoAskpassDeps {
|
|
48
|
+
/** Send on the OPEN server socket; false = not sent. */
|
|
49
|
+
send: (msg: SudoOutbound) => boolean;
|
|
50
|
+
sessionId: () => string;
|
|
51
|
+
isConnected: () => boolean;
|
|
52
|
+
/** Re-read on every decision, so a Settings change applies live (G6). Clamped here. */
|
|
53
|
+
readConfig: () => SudoCredentialPromptConfig;
|
|
54
|
+
/** Seam for the vault-masker registry (D7 C); defaults to the real one. */
|
|
55
|
+
registerPassword?: (value: string) => void;
|
|
56
|
+
env?: NodeJS.ProcessEnv;
|
|
57
|
+
platform?: NodeJS.Platform;
|
|
58
|
+
tmpdir?: string;
|
|
59
|
+
execPath?: string;
|
|
60
|
+
mkdtemp?: (prefix: string) => Promise<string>;
|
|
61
|
+
log?: (line: string) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface SudoAskpass {
|
|
65
|
+
/** Observes `dashboard_identity` (returns false) and consumes `sudo_credential_response|cancel|forget`. */
|
|
66
|
+
onServerMessage(msg: unknown): boolean;
|
|
67
|
+
onOpen(): void;
|
|
68
|
+
/** Server connection lost: withdraw, zero the cache, dismiss any pending prompt. */
|
|
69
|
+
onClose(): void;
|
|
70
|
+
/** Re-evaluate the install predicate against the live setting (also runs on identity and each helper request). */
|
|
71
|
+
reconcile(): void;
|
|
72
|
+
toolExecutionStart(event: { toolCallId?: unknown; toolName?: unknown; args?: unknown }): void;
|
|
73
|
+
toolExecutionEnd(event: { toolCallId?: unknown; toolName?: unknown }): void;
|
|
74
|
+
/** Wrap `user_bash` operations with the in-flight tracker. */
|
|
75
|
+
trackUserBash(ops: BashOperationsLike): BashOperationsLike;
|
|
76
|
+
/** True while our wrapper is installed (D9); drives `userBash({ always })`. */
|
|
77
|
+
featureInstalled(): boolean;
|
|
78
|
+
/** `session_shutdown`: withdraw everything we installed. */
|
|
79
|
+
shutdown(): void;
|
|
80
|
+
/** Resolves when no install is in flight (tests, orderly teardown). */
|
|
81
|
+
whenIdle(): Promise<void>;
|
|
82
|
+
wrapperPath(): string | undefined;
|
|
83
|
+
socketPath(): string | undefined;
|
|
84
|
+
/** Test seams: state sizes, never values the production path would not hold anyway. */
|
|
85
|
+
debug: {
|
|
86
|
+
cacheBuffer(): Buffer | undefined;
|
|
87
|
+
cacheExpiresAt(): number | null;
|
|
88
|
+
counterSize(): number;
|
|
89
|
+
pendingCallId(): string | undefined;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface Pending {
|
|
94
|
+
callId: string;
|
|
95
|
+
sock: net.Socket;
|
|
96
|
+
/** Helper invocation ordinal for its (self-reported) sudo pid. */
|
|
97
|
+
invocation: number;
|
|
98
|
+
timer: ReturnType<typeof setTimeout>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const sockAlive = (s: net.Socket): boolean => !s.destroyed && s.writable;
|
|
102
|
+
|
|
103
|
+
export function createSudoAskpass(deps: SudoAskpassDeps): SudoAskpass {
|
|
104
|
+
const env = deps.env ?? process.env;
|
|
105
|
+
const platform = deps.platform ?? process.platform;
|
|
106
|
+
const register = deps.registerPassword ?? registerSudoPassword;
|
|
107
|
+
const log = (line: string): void => deps.log?.(line);
|
|
108
|
+
|
|
109
|
+
let featureSupported = false;
|
|
110
|
+
let installed: InstalledAskpass | undefined;
|
|
111
|
+
let installing: Promise<void> | undefined;
|
|
112
|
+
let pending: Pending | undefined;
|
|
113
|
+
/** Tool-call ids a sticky Cancel covers; pruned as they end. */
|
|
114
|
+
const covered = new Set<string>();
|
|
115
|
+
const counters = createInvocationCounters();
|
|
116
|
+
const tracker = createInFlightTracker((id, remaining) => {
|
|
117
|
+
covered.delete(id);
|
|
118
|
+
if (remaining === 0 && pending) dismissPending("call-ended");
|
|
119
|
+
});
|
|
120
|
+
const cache = createPasswordCache({
|
|
121
|
+
onChange: (expiresAt) => {
|
|
122
|
+
deps.send({ type: "sudo_credential_cache", sessionId: deps.sessionId(), expiresAt });
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const config = (): SudoCredentialPromptConfig => {
|
|
127
|
+
try {
|
|
128
|
+
return parseSudoCredentialPrompt(deps.readConfig());
|
|
129
|
+
} catch {
|
|
130
|
+
return parseSudoCredentialPrompt(undefined);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const refuse = (sock: net.Socket): void => {
|
|
135
|
+
if (!sockAlive(sock)) return;
|
|
136
|
+
sock.end(SUDO_HELPER_REFUSE);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const deliver = (sock: net.Socket, password: Buffer): void => {
|
|
140
|
+
if (!sockAlive(sock)) return;
|
|
141
|
+
const framed = Buffer.concat([SUDO_HELPER_OK_MAGIC, password, Buffer.from("\n")]);
|
|
142
|
+
sock.write(framed, () => {
|
|
143
|
+
framed.fill(0);
|
|
144
|
+
sock.end();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const clearPendingState = (): Pending | undefined => {
|
|
149
|
+
const p = pending;
|
|
150
|
+
if (!p) return undefined;
|
|
151
|
+
clearTimeout(p.timer);
|
|
152
|
+
pending = undefined;
|
|
153
|
+
return p;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Bridge-initiated end of the pending prompt: browsers are dismissed, the helper exits 1. */
|
|
157
|
+
function dismissPending(why: string): void {
|
|
158
|
+
const p = clearPendingState();
|
|
159
|
+
if (!p) return;
|
|
160
|
+
log(`[sudo-askpass] dismiss callId=${p.callId} (${why})`);
|
|
161
|
+
deps.send({ type: "sudo_credential_dismiss", sessionId: deps.sessionId(), callId: p.callId });
|
|
162
|
+
refuse(p.sock);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const withdraw = (): void => {
|
|
166
|
+
dismissPending("withdrawn");
|
|
167
|
+
cache.clear();
|
|
168
|
+
counters.clear();
|
|
169
|
+
covered.clear();
|
|
170
|
+
const inst = installed;
|
|
171
|
+
if (!inst) return;
|
|
172
|
+
installed = undefined;
|
|
173
|
+
if (env.SUDO_ASKPASS === inst.wrapperPath) delete env.SUDO_ASKPASS; // only if still ours
|
|
174
|
+
inst.close();
|
|
175
|
+
process.off("exit", exitCleanup);
|
|
176
|
+
log("[sudo-askpass] withdrawn");
|
|
177
|
+
};
|
|
178
|
+
/** Best-effort directory removal when the process exits without a shutdown. */
|
|
179
|
+
const exitCleanup = (): void => {
|
|
180
|
+
installed?.close();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const want = (): boolean => platform !== "win32" && featureSupported && config().enabled;
|
|
184
|
+
|
|
185
|
+
const operatorPreset = (): boolean => {
|
|
186
|
+
const v = env.SUDO_ASKPASS;
|
|
187
|
+
return typeof v === "string" && v.length > 0;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const runInstall = async (): Promise<void> => {
|
|
191
|
+
const result = await installAskpass({
|
|
192
|
+
platform,
|
|
193
|
+
tmpdir: deps.tmpdir ?? os.tmpdir(),
|
|
194
|
+
execPath: deps.execPath ?? process.execPath,
|
|
195
|
+
mkdtemp: deps.mkdtemp,
|
|
196
|
+
onConnection: onHelperConnection,
|
|
197
|
+
});
|
|
198
|
+
if (!result.ok) {
|
|
199
|
+
log(`[sudo-askpass] install aborted: ${result.reason}`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// The identity may have flapped, or the setting flipped, while we were installing.
|
|
203
|
+
if (!want() || operatorPreset()) {
|
|
204
|
+
result.value.close();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
installed = result.value;
|
|
208
|
+
env.SUDO_ASKPASS = installed.wrapperPath;
|
|
209
|
+
process.once("exit", exitCleanup);
|
|
210
|
+
log("[sudo-askpass] installed");
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const reconcile = (): void => {
|
|
214
|
+
const wanted = want();
|
|
215
|
+
if (!wanted) {
|
|
216
|
+
if (installed) withdraw();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (installed || installing !== undefined) return;
|
|
220
|
+
if (operatorPreset()) return; // a local override (or a parent pi's wrapper) is never touched
|
|
221
|
+
installing = runInstall()
|
|
222
|
+
.catch(() => log("[sudo-askpass] install aborted: error"))
|
|
223
|
+
.finally(() => {
|
|
224
|
+
installing = undefined; // a failed install is retried by the next identity, never in a loop
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// ---- helper requests -------------------------------------------------
|
|
229
|
+
|
|
230
|
+
/** Anti-accident gate (D7): not security, it stops stray or mistaken requests. */
|
|
231
|
+
const gateOpen = (): boolean => {
|
|
232
|
+
if (!installed || !deps.isConnected()) return false;
|
|
233
|
+
const inFlight = tracker.list();
|
|
234
|
+
if (inFlight.length === 0) return false;
|
|
235
|
+
if (pending) return false;
|
|
236
|
+
return !inFlight.every((e) => covered.has(e.id)); // every in-flight call covered by a sticky Cancel
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
function onHelperConnection(sock: net.Socket): void {
|
|
240
|
+
sock.on("error", () => {});
|
|
241
|
+
sock.setTimeout(HELPER_REQUEST_READ_TIMEOUT_MS, () => sock.destroy());
|
|
242
|
+
let buf: Buffer = Buffer.alloc(0);
|
|
243
|
+
let handled = false;
|
|
244
|
+
sock.on("data", (chunk: Buffer) => {
|
|
245
|
+
if (handled) return;
|
|
246
|
+
buf = Buffer.concat([buf, chunk]);
|
|
247
|
+
const nl = buf.indexOf(10);
|
|
248
|
+
if (nl < 0) {
|
|
249
|
+
if (buf.length > SUDO_HELPER_MAX_REQUEST_BYTES) {
|
|
250
|
+
handled = true;
|
|
251
|
+
refuse(sock);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
handled = true;
|
|
256
|
+
sock.setTimeout(0);
|
|
257
|
+
let req: { promptText?: unknown; ppid?: unknown } | undefined;
|
|
258
|
+
try {
|
|
259
|
+
req = JSON.parse(buf.subarray(0, nl).toString("utf8"));
|
|
260
|
+
} catch {
|
|
261
|
+
req = undefined;
|
|
262
|
+
}
|
|
263
|
+
if (!req || typeof req !== "object") return refuse(sock);
|
|
264
|
+
handleHelperRequest(sock, typeof req.promptText === "string" ? req.promptText : "", req.ppid);
|
|
265
|
+
});
|
|
266
|
+
sock.on("close", () => {
|
|
267
|
+
if (pending?.sock === sock) dismissPending("helper-closed");
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Caching turned off live: nothing cached may be served. */
|
|
272
|
+
const clearCacheIfDisabled = (cfg: SudoCredentialPromptConfig): void => {
|
|
273
|
+
if (cfg.cacheMinutes === 0) cache.clear();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
function handleHelperRequest(sock: net.Socket, promptText: string, ppid: unknown): void {
|
|
277
|
+
reconcile(); // a live disable must beat a request that raced it
|
|
278
|
+
if (!gateOpen()) return refuse(sock);
|
|
279
|
+
const cfg = config();
|
|
280
|
+
clearCacheIfDisabled(cfg);
|
|
281
|
+
const windowMs = (cfg.cacheMinutes > 0 ? cfg.cacheMinutes : COUNTER_WINDOW_FALLBACK_MINUTES) * 60_000;
|
|
282
|
+
const invocation = counters.bump(ppid, windowMs);
|
|
283
|
+
// A repeat helper call for the same sudo pid means sudo rejected the previous password.
|
|
284
|
+
if (invocation >= 2) cache.clear();
|
|
285
|
+
const cached = invocation === 1 ? cache.get() : undefined;
|
|
286
|
+
if (cached) return deliver(sock, cached);
|
|
287
|
+
|
|
288
|
+
const callId = randomBytes(16).toString("hex");
|
|
289
|
+
const { prompt, promptTruncated } = buildPromptDisplay(promptText);
|
|
290
|
+
pending = {
|
|
291
|
+
callId,
|
|
292
|
+
sock,
|
|
293
|
+
invocation,
|
|
294
|
+
timer: setTimeout(() => {
|
|
295
|
+
// Not sticky (G4): sudo's three-attempt budget bounds repeats.
|
|
296
|
+
if (pending?.callId === callId) dismissPending("timeout");
|
|
297
|
+
}, cfg.timeoutMs),
|
|
298
|
+
};
|
|
299
|
+
pending.timer.unref?.();
|
|
300
|
+
const sent = deps.send({
|
|
301
|
+
type: "sudo_credential_request",
|
|
302
|
+
sessionId: deps.sessionId(),
|
|
303
|
+
callId,
|
|
304
|
+
commands: tracker.list().map((e) => e.command),
|
|
305
|
+
prompt,
|
|
306
|
+
...(promptTruncated ? { promptTruncated } : {}),
|
|
307
|
+
});
|
|
308
|
+
if (!sent) {
|
|
309
|
+
clearPendingState();
|
|
310
|
+
refuse(sock);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ---- operator answers ------------------------------------------------
|
|
315
|
+
|
|
316
|
+
const onResponse = (m: { sessionId?: unknown; callId?: unknown; password?: unknown }): void => {
|
|
317
|
+
reconcile(); // a live disable must beat an answer that raced it: withdraws (dismissing the pending prompt) before anything is accepted
|
|
318
|
+
const p = pending;
|
|
319
|
+
if (!p || m.callId !== p.callId || m.sessionId !== deps.sessionId()) return; // late / stray / replayed: dropped
|
|
320
|
+
if (!sockAlive(p.sock)) {
|
|
321
|
+
dismissPending("helper-closed");
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const pw = m.password;
|
|
325
|
+
// Defensive (G5): empty / over-long is never registered, cached or delivered; the prompt stays pending.
|
|
326
|
+
if (typeof pw !== "string" || pw.length < 1 || pw.length > SUDO_CREDENTIAL_MAX_PASSWORD_LENGTH) return;
|
|
327
|
+
|
|
328
|
+
register(pw); // D7 C: before delivery and before caching, also when caching is off
|
|
329
|
+
clearPendingState();
|
|
330
|
+
const bytes = Buffer.from(pw, "utf8");
|
|
331
|
+
const cfg = config();
|
|
332
|
+
// The last sudo invocation's entry could not be cleared if wrong, so it is not cached (D3).
|
|
333
|
+
if (cfg.cacheMinutes > 0 && p.invocation < SUDO_FINAL_INVOCATION) {
|
|
334
|
+
cache.set(Buffer.from(bytes), cfg.cacheMinutes * 60_000);
|
|
335
|
+
}
|
|
336
|
+
deliver(p.sock, bytes);
|
|
337
|
+
// `deliver` frames its own copy; ours is no longer needed.
|
|
338
|
+
bytes.fill(0);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const onCancel = (m: { sessionId?: unknown; callId?: unknown; reason?: unknown }): void => {
|
|
342
|
+
const p = pending;
|
|
343
|
+
if (!p || m.callId !== p.callId || m.sessionId !== deps.sessionId()) return;
|
|
344
|
+
// Operator Cancel (no reason) is sticky for the calls in flight now; a relay refusal is not.
|
|
345
|
+
if (m.reason === undefined) for (const e of tracker.list()) covered.add(e.id);
|
|
346
|
+
clearPendingState();
|
|
347
|
+
log(`[sudo-askpass] ${m.reason === undefined ? "cancel" : "refused"} callId=${p.callId}`);
|
|
348
|
+
refuse(p.sock);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
onServerMessage(raw) {
|
|
353
|
+
const msg = raw as { type?: unknown; features?: unknown; sessionId?: unknown } | null | undefined;
|
|
354
|
+
switch (msg?.type) {
|
|
355
|
+
case "dashboard_identity":
|
|
356
|
+
featureSupported = Array.isArray(msg.features) && msg.features.includes(SUDO_CREDENTIAL_FEATURE);
|
|
357
|
+
reconcile();
|
|
358
|
+
return false; // observed, never consumed: other handlers still need it
|
|
359
|
+
case "sudo_credential_response":
|
|
360
|
+
onResponse(msg as Parameters<typeof onResponse>[0]);
|
|
361
|
+
return true;
|
|
362
|
+
case "sudo_credential_cancel":
|
|
363
|
+
onCancel(msg as Parameters<typeof onCancel>[0]);
|
|
364
|
+
return true;
|
|
365
|
+
case "sudo_credential_forget":
|
|
366
|
+
if (msg.sessionId === deps.sessionId()) cache.clear();
|
|
367
|
+
return true;
|
|
368
|
+
default:
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
onOpen() {},
|
|
373
|
+
onClose() {
|
|
374
|
+
featureSupported = false;
|
|
375
|
+
withdraw();
|
|
376
|
+
},
|
|
377
|
+
reconcile,
|
|
378
|
+
toolExecutionStart(e) {
|
|
379
|
+
const command = (e.args as { command?: unknown } | null | undefined)?.command;
|
|
380
|
+
if (e.toolName === "bash" && typeof e.toolCallId === "string" && typeof command === "string") {
|
|
381
|
+
tracker.beginTool(e.toolCallId, command);
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
toolExecutionEnd(e) {
|
|
385
|
+
if (e.toolName === "bash" && typeof e.toolCallId === "string") tracker.endTool(e.toolCallId);
|
|
386
|
+
},
|
|
387
|
+
trackUserBash: (ops) => tracker.wrapOperations(ops),
|
|
388
|
+
featureInstalled: () => installed !== undefined,
|
|
389
|
+
shutdown() {
|
|
390
|
+
featureSupported = false;
|
|
391
|
+
withdraw();
|
|
392
|
+
},
|
|
393
|
+
whenIdle: async () => {
|
|
394
|
+
while (installing !== undefined) await installing;
|
|
395
|
+
},
|
|
396
|
+
wrapperPath: () => installed?.wrapperPath,
|
|
397
|
+
socketPath: () => installed?.socketPath,
|
|
398
|
+
debug: {
|
|
399
|
+
cacheBuffer: () => cache.peek(),
|
|
400
|
+
cacheExpiresAt: () => cache.expiresAt(),
|
|
401
|
+
counterSize: () => counters.size(),
|
|
402
|
+
pendingCallId: () => pending?.callId,
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source of the askpass helper and its shell wrapper (D10).
|
|
3
|
+
*
|
|
4
|
+
* The wrapper is a `/bin/sh` script that clears `NODE_OPTIONS`/`NODE_PATH` and
|
|
5
|
+
* execs the ABSOLUTE interpreter (`process.execPath`), never `env node`, since the
|
|
6
|
+
* agent controls `PATH` and `NODE_OPTIONS` in the bash call. The helper has the
|
|
7
|
+
* socket path baked in (no env), writes the answer only to stdout, never to argv,
|
|
8
|
+
* env or stderr, and prints one fixed message on any failure.
|
|
9
|
+
*
|
|
10
|
+
* See change: add-sudo-credential-prompt (D10).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { SUDO_HELPER_OK_MAGIC } from "./protocol.js";
|
|
14
|
+
|
|
15
|
+
/** The only text the helper ever writes to stderr (sudo's stderr is tool output). */
|
|
16
|
+
export const SUDO_HELPER_FAILURE_MESSAGE = "pi-dashboard askpass: no credential provided\n";
|
|
17
|
+
|
|
18
|
+
/** Longest bridge answer the helper will buffer (max password is 1 024 chars). */
|
|
19
|
+
const MAX_ANSWER_BYTES = 16 * 1024;
|
|
20
|
+
|
|
21
|
+
export function buildHelperSource(socketPath: string): string {
|
|
22
|
+
return `"use strict";
|
|
23
|
+
const net = require("net");
|
|
24
|
+
const fs = require("fs");
|
|
25
|
+
const MAGIC = Buffer.from(${JSON.stringify(SUDO_HELPER_OK_MAGIC.toString("latin1"))}, "latin1");
|
|
26
|
+
let done = false;
|
|
27
|
+
function fail() {
|
|
28
|
+
if (done) return;
|
|
29
|
+
done = true;
|
|
30
|
+
try { fs.writeSync(2, ${JSON.stringify(SUDO_HELPER_FAILURE_MESSAGE)}); } catch (e) {}
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
function finish(chunks) {
|
|
34
|
+
if (done) return;
|
|
35
|
+
const buf = Buffer.concat(chunks);
|
|
36
|
+
if (buf.length <= MAGIC.length || !buf.subarray(0, MAGIC.length).equals(MAGIC)) return fail();
|
|
37
|
+
done = true;
|
|
38
|
+
process.stdout.write(buf.subarray(MAGIC.length), function () { process.exit(0); });
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let size = 0;
|
|
43
|
+
const conn = net.createConnection(${JSON.stringify(socketPath)});
|
|
44
|
+
conn.on("connect", function () {
|
|
45
|
+
conn.write(JSON.stringify({ promptText: process.argv[2] === undefined ? "" : String(process.argv[2]), ppid: process.ppid }) + "\\n");
|
|
46
|
+
});
|
|
47
|
+
conn.on("data", function (d) {
|
|
48
|
+
size += d.length;
|
|
49
|
+
if (size > ${MAX_ANSWER_BYTES}) return fail();
|
|
50
|
+
chunks.push(d);
|
|
51
|
+
});
|
|
52
|
+
conn.on("end", function () { finish(chunks); });
|
|
53
|
+
conn.on("error", fail);
|
|
54
|
+
conn.on("close", function () { finish(chunks); });
|
|
55
|
+
} catch (e) {
|
|
56
|
+
fail();
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const shQuote = (s: string): string => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
62
|
+
|
|
63
|
+
/** `/bin/sh` wrapper: scrub node env, exec the absolute interpreter on the helper file. */
|
|
64
|
+
export function buildWrapperSource(execPath: string, helperPath: string): string {
|
|
65
|
+
return `#!/bin/sh
|
|
66
|
+
unset NODE_OPTIONS NODE_PATH
|
|
67
|
+
exec ${shQuote(execPath)} ${shQuote(helperPath)} "$@"
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-accident gate input (D7): which bash / `user_bash` commands are running
|
|
3
|
+
* right now. Entries start at `tool_execution_start` (bash) or when a wrapped
|
|
4
|
+
* `user_bash` operation begins to exec, and end at `tool_execution_end` or in the
|
|
5
|
+
* operation's `finally`. The bridge never maps a sudo pid to one call (pi runs
|
|
6
|
+
* tool calls in parallel), so the modal lists every command in flight.
|
|
7
|
+
*
|
|
8
|
+
* See change: add-sudo-credential-prompt (D4, D7).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { BashOperationsLike } from "../vault-redaction.js";
|
|
12
|
+
|
|
13
|
+
export interface InFlightEntry {
|
|
14
|
+
id: string;
|
|
15
|
+
command: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface InFlightTracker {
|
|
19
|
+
/** Start an entry for a bash tool call; idempotent per `toolCallId`. */
|
|
20
|
+
beginTool(toolCallId: string, command: string): void;
|
|
21
|
+
endTool(toolCallId: string): void;
|
|
22
|
+
/** Start an anonymous entry (a `!` command); returns the id for `end`. */
|
|
23
|
+
begin(command: string): string;
|
|
24
|
+
end(id: string): void;
|
|
25
|
+
/** Entries in start order. */
|
|
26
|
+
list(): InFlightEntry[];
|
|
27
|
+
size(): number;
|
|
28
|
+
/** Wrap `user_bash` operations: increment with the command at exec start, decrement in `finally`. */
|
|
29
|
+
wrapOperations(ops: BashOperationsLike): BashOperationsLike;
|
|
30
|
+
clear(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `onEnd` runs after an entry ended, with the remaining size and the ended id. */
|
|
34
|
+
export function createInFlightTracker(onEnd?: (endedId: string, remaining: number) => void): InFlightTracker {
|
|
35
|
+
const entries = new Map<string, string>();
|
|
36
|
+
let seq = 0;
|
|
37
|
+
|
|
38
|
+
const remove = (id: string): void => {
|
|
39
|
+
if (!entries.delete(id)) return;
|
|
40
|
+
onEnd?.(id, entries.size);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const begin = (command: string): string => {
|
|
44
|
+
const id = `user:${++seq}`;
|
|
45
|
+
entries.set(id, command);
|
|
46
|
+
return id;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
beginTool(toolCallId, command) {
|
|
51
|
+
const id = `tool:${toolCallId}`;
|
|
52
|
+
if (!entries.has(id)) entries.set(id, command);
|
|
53
|
+
},
|
|
54
|
+
endTool(toolCallId) {
|
|
55
|
+
remove(`tool:${toolCallId}`);
|
|
56
|
+
},
|
|
57
|
+
begin,
|
|
58
|
+
end: remove,
|
|
59
|
+
list() {
|
|
60
|
+
return [...entries].map(([id, command]) => ({ id, command }));
|
|
61
|
+
},
|
|
62
|
+
size: () => entries.size,
|
|
63
|
+
wrapOperations(ops) {
|
|
64
|
+
return {
|
|
65
|
+
exec: async (command, cwd, options) => {
|
|
66
|
+
const id = begin(command);
|
|
67
|
+
try {
|
|
68
|
+
return await ops.exec(command, cwd, options);
|
|
69
|
+
} finally {
|
|
70
|
+
remove(id);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
clear() {
|
|
76
|
+
entries.clear();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single entry the bridge imports for the sudo credential prompt.
|
|
3
|
+
* See change: add-sudo-credential-prompt.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { createSudoAskpass } from "./controller.js";
|
|
7
|
+
export type { SudoAskpass, SudoAskpassDeps } from "./controller.js";
|
|
8
|
+
export { createInFlightTracker } from "./in-flight.js";
|
|
9
|
+
export type { InFlightTracker } from "./in-flight.js";
|
|
10
|
+
export { buildPromptDisplay, escapePromptText } from "./prompt-text.js";
|
|
11
|
+
export { createSudoConfigReader } from "./config-reader.js";
|