@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
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session-related REST API routes.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { isAbsolute, resolve } from "node:path";
|
|
5
|
+
import { containmentAllows } from "@blackbelt-technology/pi-dashboard-shared/containment-guard.js";
|
|
6
|
+
import type { SessionListItem } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
7
|
+
import { sessionUiPath } from "@blackbelt-technology/pi-dashboard-shared/session-ui-path.js";
|
|
6
8
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
7
9
|
import type { FastifyInstance } from "fastify";
|
|
8
10
|
import { evaluateContainment } from "../access/containment-gate.js";
|
|
9
|
-
import { canDiscloseAccessPosture } from "../auth/localhost-guard.js";
|
|
10
11
|
import { readFileVerifiedUtf8, VerifiedReadRefused } from "../access/verified-read.js";
|
|
12
|
+
import { canDiscloseAccessPosture } from "../auth/localhost-guard.js";
|
|
11
13
|
import { canAccessSession, gateHttpSession, sessionPrincipalOf } from "../identity/session-access.js";
|
|
14
|
+
import { DashboardStateRefused, dashboardStateRefuses, readFileStateChecked } from "../lib/dashboard-state-guard.js";
|
|
12
15
|
import type { EventStore } from "../persistence/memory-event-store.js";
|
|
13
16
|
import type { SessionManager } from "../session/memory-session-manager.js";
|
|
14
17
|
import type { RemoteTranscriptStore } from "../session/remote-transcript-store.js";
|
|
@@ -21,6 +24,7 @@ import { findSessionCustomEntry, findSessionToolCallPayload } from "../session/s
|
|
|
21
24
|
import type { SessionLoadWorkerPool } from "../session/session-load-worker-pool.js";
|
|
22
25
|
import { originOf } from "../session/session-origin.js";
|
|
23
26
|
import type { NetworkGuard } from "./route-deps.js";
|
|
27
|
+
import { resolveRequestUiBase } from "./ui-link-base.js";
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Cumulative answers of the tool-result route that distinguished a still-running
|
|
@@ -32,6 +36,9 @@ export interface ToolResultStats {
|
|
|
32
36
|
gone: number;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
const headerString = (v: string | string[] | undefined): string | undefined =>
|
|
40
|
+
Array.isArray(v) ? v[0] : v;
|
|
41
|
+
|
|
35
42
|
export function registerSessionRoutes(
|
|
36
43
|
fastify: FastifyInstance,
|
|
37
44
|
deps: {
|
|
@@ -63,6 +70,14 @@ export function registerSessionRoutes(
|
|
|
63
70
|
* SAME value so transcript- and store-sourced payloads match.
|
|
64
71
|
* See change: fix-session-diff-durable-source. */
|
|
65
72
|
maxStringSize?: number;
|
|
73
|
+
/** Inputs for `uiUrl` / `diffUrl` (D1). Read per request so tunnel / config
|
|
74
|
+
* changes are seen live. Absent (unit tests) → localhost fallback on `port` 8000.
|
|
75
|
+
* See change: add-session-ui-deep-links-for-agents. */
|
|
76
|
+
uiLinks?: {
|
|
77
|
+
configuredOrigins: () => string[];
|
|
78
|
+
isAdmitted: (hostHeader: string | undefined) => boolean;
|
|
79
|
+
port: () => number;
|
|
80
|
+
};
|
|
66
81
|
},
|
|
67
82
|
) {
|
|
68
83
|
const {
|
|
@@ -104,9 +119,41 @@ export function registerSessionRoutes(
|
|
|
104
119
|
sizeOf: sessionDiffResultSize,
|
|
105
120
|
});
|
|
106
121
|
|
|
107
|
-
|
|
122
|
+
// `?id=` (single string): case-insensitive exact id, or a prefix of >= 8
|
|
123
|
+
// characters — the same floor as the client's `resolveSessionRouteId`.
|
|
124
|
+
// Applied after `filterOwned`. See change: add-session-ui-deep-links-for-agents.
|
|
125
|
+
fastify.get<{ Querystring: { id?: string | string[] } }>("/api/sessions", async (request, reply) => {
|
|
126
|
+
const rawId = request.query.id;
|
|
127
|
+
if (rawId !== undefined && typeof rawId !== "string") {
|
|
128
|
+
reply.code(400);
|
|
129
|
+
return { success: false, error: "id must be a single string" } satisfies ApiResponse;
|
|
130
|
+
}
|
|
131
|
+
const idQuery = rawId?.toLowerCase();
|
|
108
132
|
// §8.1/§8.2: per-item owner filter — never disclose the full registry.
|
|
109
|
-
|
|
133
|
+
let owned = filterOwned(request, sessionManager.listAll());
|
|
134
|
+
if (idQuery !== undefined) {
|
|
135
|
+
owned = owned.filter((s) => {
|
|
136
|
+
const id = s.id.toLowerCase();
|
|
137
|
+
return id === idQuery || (idQuery.length >= 8 && id.startsWith(idQuery));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// The links depend on the request's Host / X-Forwarded-Host: never cacheable.
|
|
141
|
+
reply.header("Cache-Control", "no-store");
|
|
142
|
+
const links = deps.uiLinks;
|
|
143
|
+
const base = resolveRequestUiBase({
|
|
144
|
+
host: headerString(request.headers.host),
|
|
145
|
+
forwardedHost: headerString(request.headers["x-forwarded-host"]),
|
|
146
|
+
protocol: request.protocol,
|
|
147
|
+
configuredOrigins: links?.configuredOrigins() ?? [],
|
|
148
|
+
isAdmitted: links?.isAdmitted ?? (() => false),
|
|
149
|
+
port: links?.port() ?? 8000,
|
|
150
|
+
});
|
|
151
|
+
const data: SessionListItem[] = owned.map((s) => ({
|
|
152
|
+
...s,
|
|
153
|
+
uiUrl: base + sessionUiPath(s.id),
|
|
154
|
+
diffUrl: base + sessionUiPath(s.id, "diff"),
|
|
155
|
+
}));
|
|
156
|
+
return { success: true, data } satisfies ApiResponse;
|
|
110
157
|
});
|
|
111
158
|
|
|
112
159
|
// On-demand listing of archived sessions, served from the in-memory index
|
|
@@ -489,34 +536,37 @@ export function registerSessionRoutes(
|
|
|
489
536
|
}
|
|
490
537
|
// Resolve and ensure path is within cwd
|
|
491
538
|
const absPath = isAbsolute(filePath) ? filePath : resolve(session.cwd, filePath);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
539
|
+
// Dashboard-state + pi-agent credential refusal (real path, both tiers) BEFORE the in-cwd shortcut:
|
|
540
|
+
// a session cwd of `$HOME` contains `.pi/agent/auth.json` and `.pi/dashboard/local/token`.
|
|
541
|
+
// See change: close-security-map-high-findings (D1, F1).
|
|
542
|
+
if (await dashboardStateRefuses(absPath)) {
|
|
543
|
+
reply.code(403);
|
|
544
|
+
return { success: false, error: "path outside session directory" } satisfies ApiResponse;
|
|
545
|
+
}
|
|
546
|
+
// Always decided by the gate (no lexical in-cwd shortcut: an in-cwd link to an outside file must not
|
|
547
|
+
// be served). A path grant admits here exactly as at the file-routes sites; the refusal string is
|
|
548
|
+
// unchanged when no grant covers it. See change: close-local-listener-and-egress-gaps (D1).
|
|
549
|
+
const sessionDecision = await evaluateContainment(absPath, [session.cwd], {
|
|
550
|
+
site: "session-routes:session-file",
|
|
551
|
+
hold: { request, reply },
|
|
552
|
+
disclosure: canDiscloseAccessPosture(request),
|
|
553
|
+
session: sessionId,
|
|
554
|
+
});
|
|
555
|
+
if (!containmentAllows(sessionDecision, absPath)) {
|
|
556
|
+
reply.code(403);
|
|
557
|
+
return { success: false, error: "path outside session directory", ...sessionDecision.remedy } as ApiResponse;
|
|
509
558
|
}
|
|
559
|
+
const viaGrant = sessionDecision.viaGrant;
|
|
510
560
|
try {
|
|
511
561
|
// A grant-admitted read is verified against the open handle (design D14,
|
|
512
562
|
// task 2.8): without it a granted FIFO would block this read, and a path
|
|
513
563
|
// swapped after the containment check would be served.
|
|
514
564
|
const content = viaGrant
|
|
515
|
-
? await readFileVerifiedUtf8(
|
|
516
|
-
: await
|
|
565
|
+
? await readFileVerifiedUtf8(sessionDecision.real, { decidedReal: sessionDecision.real })
|
|
566
|
+
: await readFileStateChecked(sessionDecision.real, "utf-8", { decidedReal: sessionDecision.real });
|
|
517
567
|
return { success: true, data: { content } } satisfies ApiResponse;
|
|
518
568
|
} catch (err) {
|
|
519
|
-
if (err instanceof VerifiedReadRefused) {
|
|
569
|
+
if (err instanceof VerifiedReadRefused || err instanceof DashboardStateRefused) {
|
|
520
570
|
reply.code(403);
|
|
521
571
|
return { success: false, error: "path outside session directory" } as ApiResponse;
|
|
522
572
|
}
|
|
@@ -14,14 +14,16 @@ import type { ServerToBrowserMessage } from "@blackbelt-technology/pi-dashboard-
|
|
|
14
14
|
import type { BridgeLoadSource, PluginStatus } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/plugin-status.js";
|
|
15
15
|
import { parseLaunchSource } from "@blackbelt-technology/pi-dashboard-shared/dashboard-starter.js";
|
|
16
16
|
import { ELECTRON_RESTART_EXIT_CODE, restartsViaElectron } from "@blackbelt-technology/pi-dashboard-shared/electron-restart.js";
|
|
17
|
-
import {
|
|
17
|
+
import { GENERIC_NETWORK_DENIED_HINT, type HealthNetworkAccessField, NETWORK_NOT_ALLOWED } from "@blackbelt-technology/pi-dashboard-shared/network-denial-signal.js";
|
|
18
|
+
import { LOCAL_PROOF_REQUIRED } from "@blackbelt-technology/pi-dashboard-shared/local-proof-signal.js";
|
|
19
|
+
import { ToolResolver, whichSync } from "@blackbelt-technology/pi-dashboard-shared/platform/binary-lookup.js";
|
|
18
20
|
import { getGitSourceReadout } from "@blackbelt-technology/pi-dashboard-shared/platform/git-source.js";
|
|
19
21
|
import { resolveNativeTsLoader } from "@blackbelt-technology/pi-dashboard-shared/platform/ts-loader-select.mjs";
|
|
20
22
|
import { classifyBridgeSource } from "@blackbelt-technology/pi-dashboard-shared/plugin-bridge-register.js";
|
|
21
|
-
import { RESTART_QUIESCE_MS } from "@blackbelt-technology/pi-dashboard-shared/recovery-timing.js";
|
|
23
|
+
import { RESTART_QUIESCE_MS, SHUTDOWN_QUIESCE_MS } from "@blackbelt-technology/pi-dashboard-shared/recovery-timing.js";
|
|
22
24
|
import type { NetworkInterface, PiMirrorResult, ReservedNameResult } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
23
25
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
24
|
-
import type { FastifyInstance } from "fastify";
|
|
26
|
+
import type { FastifyInstance, FastifyRequest } from "fastify";
|
|
25
27
|
import type { AccessGrantHealth } from "../access/access-health.js";
|
|
26
28
|
import {
|
|
27
29
|
computeBindReachability,
|
|
@@ -29,7 +31,9 @@ import {
|
|
|
29
31
|
safeComputeBindReachability,
|
|
30
32
|
sameReachability,
|
|
31
33
|
} from "../auth/bind-reachability-service.js";
|
|
32
|
-
import {
|
|
34
|
+
import type { CspReportsSnapshot } from "../auth/csp-report-store.js";
|
|
35
|
+
import type { LocalTrustContext } from "../auth/local-proof.js";
|
|
36
|
+
import { canDiscloseAccessPosture, localhostGuard, loopbackCoveringEntries, needsLocalProof } from "../auth/localhost-guard.js";
|
|
33
37
|
import { networkOnlySnapshot } from "../auth/network-trust-telemetry.js";
|
|
34
38
|
import { getRegistryError } from "../auth/provider-auth-registry.js";
|
|
35
39
|
import { effectiveTrustMode } from "../auth/trust-mode.js";
|
|
@@ -38,6 +42,7 @@ import type { DirectoryService } from "../directory-service.js";
|
|
|
38
42
|
import {
|
|
39
43
|
type ClientBuildSnapshot,
|
|
40
44
|
readClientBuildSnapshot,
|
|
45
|
+
readServedDeclaration,
|
|
41
46
|
runtimePluginRegistryHash,
|
|
42
47
|
} from "../lib/client-dist.js";
|
|
43
48
|
import { bootParentPid, computeBootParentAlive, readLivePpid } from "../lifecycle/boot-parent-liveness.js";
|
|
@@ -47,6 +52,7 @@ import type { EventLoopSpikeMetrics } from "../metrics/eventloop-spike-metrics.j
|
|
|
47
52
|
import type { HydrationMetrics } from "../metrics/hydration-metrics.js";
|
|
48
53
|
import { getModelProxyStatus } from "../model-proxy/registry-singleton.js";
|
|
49
54
|
import { type DroppedFrameStats, EMPTY_DROPPED_FRAME_STATS, EMPTY_SOCKET_BUFFER_OCCUPANCY, type SocketBufferOccupancy } from "../pairing/browser-gateway.js";
|
|
55
|
+
import { exitBarrier, scheduleExit } from "../lifecycle/credential-exit-barrier.js";
|
|
50
56
|
import { recordExitIntent } from "../persistence/boot-state.js";
|
|
51
57
|
import { EMPTY_STORE_RETENTION, EMPTY_TRIM_STATS, type StoreRetention, type TrimStats } from "../persistence/memory-event-store.js";
|
|
52
58
|
import type { MetaPersistence } from "../persistence/meta-persistence.js";
|
|
@@ -63,17 +69,18 @@ import {
|
|
|
63
69
|
readPiCompatibility,
|
|
64
70
|
} from "../pi/pi-version-skew.js";
|
|
65
71
|
import { mirrorDefaultsToPi } from "../pi-agent-settings.js";
|
|
72
|
+
import { notePiMirrorWrite } from "../pi-default-remirror.js";
|
|
66
73
|
import { EMPTY_KEEPER_LOG_STATS, type KeeperLogStats } from "../rpc-keeper/keeper-manager.js";
|
|
67
74
|
import type { ServerConfig } from "../server.js";
|
|
68
75
|
import { serverHeapTelemetry } from "../server-heap-telemetry.js";
|
|
69
|
-
import { projectAcmeConfigured } from "../tls/sources/acme/config-projection.js";
|
|
70
|
-
import { touchesTlsOrPorts, validateTlsConfigWrite } from "../tls/tls-config-validation.js";
|
|
71
|
-
import type { TlsListener } from "../tls/tls-listener.js";
|
|
72
76
|
import type { SessionManager } from "../session/memory-session-manager.js";
|
|
73
77
|
import { heapFallbackStatus } from "../spawn-process/heap-args.js";
|
|
74
78
|
import { spawnRestart } from "../spawn-process/restart-helper.js";
|
|
75
79
|
import { readSpawnFailures } from "../spawn-process/spawn-failure-log.js";
|
|
76
80
|
import { systemOpenCapability } from "../system-open-capability.js";
|
|
81
|
+
import { projectAcmeConfigured } from "../tls/sources/acme/config-projection.js";
|
|
82
|
+
import { touchesTlsOrPorts, validateTlsConfigWrite } from "../tls/tls-config-validation.js";
|
|
83
|
+
import type { TlsListener } from "../tls/tls-listener.js";
|
|
77
84
|
import { connectedProviderIds, connectGateway, createTunnel, deleteTunnel, disconnectResolvedProviders, ensureReservedName, gatewayProviderStatus, getProviderReadiness, getTunnelStatus, getTunnelUrl, getZrokLastError, releaseShare } from "../tunnel/tunnel.js";
|
|
78
85
|
import { acceptTargetFor, blockEvents } from "../tunnel/tunnel-block-events.js";
|
|
79
86
|
import { collectEndpoints, liveReadinessEndpoints } from "../tunnel/tunnel-endpoints.js";
|
|
@@ -81,6 +88,7 @@ import { runEnrollStep } from "../tunnel/tunnel-enroll.js";
|
|
|
81
88
|
import { startTunnelWatchdog, stopTunnelWatchdog } from "../tunnel/tunnel-watchdog.js";
|
|
82
89
|
import { reserveNameAsync } from "../tunnel-providers/zrok.js";
|
|
83
90
|
import { buildNetworkInterfaceList } from "./network-interfaces.js";
|
|
91
|
+
import type { PiTrustLiveCounters } from "./pi-trust-query-routes.js";
|
|
84
92
|
|
|
85
93
|
/** Heartbeat poll-cost counters summed on /api/health. See change: optimize-polling-hot-paths. */
|
|
86
94
|
const POLL_COST_KEYS = [
|
|
@@ -96,7 +104,10 @@ import {
|
|
|
96
104
|
readRuntimeRequest,
|
|
97
105
|
readRuntimeState,
|
|
98
106
|
} from "@blackbelt-technology/pi-dashboard-shared/runtime-overlay/state.js";
|
|
107
|
+
import { recognizeTrustedTypesMode } from "@blackbelt-technology/pi-dashboard-shared/trusted-types-mode.js";
|
|
99
108
|
import { createRuntimeHealthProvider, redactRuntimeHealth } from "../runtime-overlay/runtime-health.js";
|
|
109
|
+
import { getPluginEntryStats } from "../plugin-entry-stats.js";
|
|
110
|
+
import { getPluginPolicyRegistry } from "../plugin-policy-registry.js";
|
|
100
111
|
import type { NetworkGuard } from "./route-deps.js";
|
|
101
112
|
|
|
102
113
|
/**
|
|
@@ -160,12 +171,30 @@ function saveConfigAndMirror(partial: Record<string, any>) {
|
|
|
160
171
|
console.warn("[pi-settings] default-model mirror threw:", err instanceof Error ? err.message : err);
|
|
161
172
|
}
|
|
162
173
|
if (!piMirror.ok) console.warn(`[pi-settings] default-model mirror failed: ${piMirror.error}`);
|
|
174
|
+
else notePiMirrorWrite();
|
|
163
175
|
}
|
|
164
176
|
return { ok: true as const, result, reloaded, piMirror };
|
|
165
177
|
};
|
|
166
178
|
return runOnConfigSaveChain(run);
|
|
167
179
|
}
|
|
168
180
|
|
|
181
|
+
/**
|
|
182
|
+
* `/api/health` is unauthenticated and tunnel-reachable, so its `plugins[]` stays path- and
|
|
183
|
+
* hash-free: local-detected rows (they name a session cwd's packages), `shadowed` (carries
|
|
184
|
+
* `packageDir`) and `client.sha256` are dropped; `source`, `restartRequired`, `hostApi`,
|
|
185
|
+
* `client.delivery` / `client.refusedReason` and `serveApp` pass through. The guarded
|
|
186
|
+
* `GET /api/plugins` and `plugins_changed` (authenticated WS) carry the full rows.
|
|
187
|
+
* See change: decouple-plugins-from-core (task 5.10, design D15).
|
|
188
|
+
*/
|
|
189
|
+
export function toHealthPlugins(statuses: readonly PluginStatus[]): PluginStatus[] {
|
|
190
|
+
return statuses
|
|
191
|
+
.filter((s) => s.source !== "local-detected")
|
|
192
|
+
.map((s) => {
|
|
193
|
+
const { shadowed: _shadowed, client, ...rest } = s;
|
|
194
|
+
return client ? { ...rest, client: { delivery: client.delivery, ...(client.refusedReason ? { refusedReason: client.refusedReason } : {}) } } : rest;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
169
198
|
/**
|
|
170
199
|
* Enrich each plugin status with `bridgeLoadedFrom` by classifying the
|
|
171
200
|
* plugin's resolved bridge path against the live pi settings.json.
|
|
@@ -211,10 +240,21 @@ export function registerSystemRoutes(
|
|
|
211
240
|
metaPersistence: MetaPersistence;
|
|
212
241
|
config: ServerConfig;
|
|
213
242
|
networkGuard: NetworkGuard;
|
|
243
|
+
/** Strict-proof context: `/api/health` adds `localProof: "required"` for a bare-loopback caller that lacks proof. See change: close-container-loopback-impersonation (D3). */
|
|
244
|
+
localTrust?: LocalTrustContext;
|
|
245
|
+
/** True when the caller's request would be refused by the REST network guard (pure, no side effects). Absent → no `networkAccess` field. See change: surface-network-denial-on-health (D2). */
|
|
246
|
+
readNetworkVerdict?: (request: FastifyRequest) => boolean;
|
|
214
247
|
version?: string;
|
|
215
248
|
directoryService?: DirectoryService;
|
|
216
249
|
/** Called after a `PUT /api/config` that touched `vault`, so delivery switches apply live. See change: add-credential-vault. */
|
|
217
250
|
onVaultConfigChanged?: () => void;
|
|
251
|
+
/**
|
|
252
|
+
* Called after a `PUT /api/config` that touched `tls`, BEFORE the listener reconcile: withdraw values from, and
|
|
253
|
+
* close, TLS-admitted bridges when Accept bridges or the listener turned off. See change: prove-vault-bridge-tls (D2).
|
|
254
|
+
*/
|
|
255
|
+
onTlsBridgeSwitchChanged?: () => void;
|
|
256
|
+
/** True while a first-plaintext-exposure registry write has not persisted; reported on `/api/health`. */
|
|
257
|
+
exposureWritePending?: () => boolean;
|
|
218
258
|
/** Optional TLS listener: status in `/api/health.tls`, endpoints, reconcile after a `tls` config write. See change: add-tailscale-cert-tls. */
|
|
219
259
|
tls?: Pick<TlsListener, "status" | "tlsListenerUrls" | "reconcile">;
|
|
220
260
|
piGateway?: PiGateway;
|
|
@@ -249,6 +289,12 @@ export function registerSystemRoutes(
|
|
|
249
289
|
// `accessGrants`, failure-isolated like every other telemetry read.
|
|
250
290
|
// See change: add-access-grant-dialog (task 9.3).
|
|
251
291
|
readAccessGrants?: () => AccessGrantHealth;
|
|
292
|
+
// Live pi-trust query counters (`piTrustMirror.live`), same disclosure gate as
|
|
293
|
+
// `accessGrants`. See change: mirror-dashboard-trust-live-remote (D6).
|
|
294
|
+
readPiTrustLive?: () => PiTrustLiveCounters;
|
|
295
|
+
// Persisted baseline CSP report counters (`cspReports`), same disclosure gate as `accessGrants`;
|
|
296
|
+
// counts only. See change: harden-cors-and-csp-reporting (D8).
|
|
297
|
+
readCspReports?: () => CspReportsSnapshot;
|
|
252
298
|
// Live trusted-network list (top-level ∪ auth.bypassHosts) for the additive
|
|
253
299
|
// `trustPosture` health field. Falls back to the boot list when unwired.
|
|
254
300
|
// See change: fix-trusted-network-tunnel-bypass (D3).
|
|
@@ -292,14 +338,16 @@ export function registerSystemRoutes(
|
|
|
292
338
|
clientBuild?: ClientBuildSnapshot;
|
|
293
339
|
},
|
|
294
340
|
) {
|
|
295
|
-
const { sessionManager, preferencesStore, metaPersistence, config, networkGuard, version, directoryService, piGateway, browserGateway, hydrationMetrics, readEventLoopDelay, eventLoopSpikes, eventStore, toolResultStats, embedLifecycle, keeperLogStats, clientDir, readAccessGrants, readTrustedNetworks, readPushErrors } = deps;
|
|
341
|
+
const { sessionManager, preferencesStore, metaPersistence, config, networkGuard, version, directoryService, piGateway, browserGateway, hydrationMetrics, readEventLoopDelay, eventLoopSpikes, eventStore, toolResultStats, embedLifecycle, keeperLogStats, clientDir, readAccessGrants, readPiTrustLive, readCspReports, readTrustedNetworks, readPushErrors, readNetworkVerdict } = deps;
|
|
296
342
|
|
|
297
343
|
// Served-artifact coherence snapshot (design D4): a startup snapshot, never a
|
|
298
344
|
// per-request filesystem read (P1).
|
|
345
|
+
// The served declaration decides which plugins the server hashes (design D11): read once with the snapshot.
|
|
346
|
+
const servedDeclaration = readServedDeclaration(clientDir ?? null);
|
|
299
347
|
const clientBuild =
|
|
300
348
|
deps.clientBuild ??
|
|
301
349
|
readClientBuildSnapshot(clientDir ?? null, (policy) =>
|
|
302
|
-
runtimePluginRegistryHash(policy === "excluded"),
|
|
350
|
+
runtimePluginRegistryHash(policy === "excluded", servedDeclaration),
|
|
303
351
|
);
|
|
304
352
|
|
|
305
353
|
// Hoisted for the same reason as `clientBuild`: `runtimePluginRegistryHash`
|
|
@@ -312,13 +360,12 @@ export function registerSystemRoutes(
|
|
|
312
360
|
// Fixture clients are part of a production build only under the opt-in
|
|
313
361
|
// PI_DASHBOARD_FIXTURE_PLUGINS gate (docker test harness) — the same rule
|
|
314
362
|
// the vite plugin applied. See change: expose-plugin-credential-and-oauth-seams (D8).
|
|
315
|
-
const bundleHash = runtimePluginRegistryHash(!config.dev && !fixturePluginsEnabled());
|
|
363
|
+
const bundleHash = runtimePluginRegistryHash(!config.dev && !fixturePluginsEnabled(), servedDeclaration);
|
|
316
364
|
|
|
317
365
|
// Quiesce windows for the bridge `server_restarting` broadcast. See change
|
|
318
366
|
// `fix-restart-bridge-auto-start-race`. Bridges that receive this message
|
|
319
367
|
// suppress only the spawn step in `server-auto-start.ts` for `quiesceMs`;
|
|
320
368
|
// discovery + reconnection still run.
|
|
321
|
-
const SHUTDOWN_QUIESCE_MS = 60000;
|
|
322
369
|
const announceRestart = (
|
|
323
370
|
reason: "restart" | "shutdown",
|
|
324
371
|
quiesceMs: number,
|
|
@@ -438,10 +485,13 @@ export function registerSystemRoutes(
|
|
|
438
485
|
// render the toggle inert with the reason. See change: ask-agent-file-access-in-chat.
|
|
439
486
|
const gateEnv = process.env.PI_DASHBOARD_AGENT_PATH_GATE?.trim().toLowerCase();
|
|
440
487
|
const agentPathGateEnvOverride = gateEnv === "off" || gateEnv === "on" ? gateEnv : null;
|
|
488
|
+
// `trustedTypesEnvOverride`: the recognized `PI_DASHBOARD_TRUSTED_TYPES` value (env beats config), else null.
|
|
489
|
+
// COMPUTED, never persisted. See change: enforce-trusted-types-default (D5).
|
|
490
|
+
const trustedTypesEnvOverride = recognizeTrustedTypesMode(process.env.PI_DASHBOARD_TRUSTED_TYPES);
|
|
441
491
|
// `tls.sources[].solver.configured` (ACME): projected from the vault listing, never a secret.
|
|
442
492
|
// See change: add-acme-dns01-certs.
|
|
443
493
|
const redacted = await projectAcmeConfigured(readConfigRedacted());
|
|
444
|
-
return { success: true, data: { ...redacted, reachability, agentPathGateEnvOverride } };
|
|
494
|
+
return { success: true, data: { ...redacted, reachability, agentPathGateEnvOverride, trustedTypesEnvOverride } };
|
|
445
495
|
},
|
|
446
496
|
);
|
|
447
497
|
|
|
@@ -467,13 +517,17 @@ export function registerSystemRoutes(
|
|
|
467
517
|
}
|
|
468
518
|
const configModule = await import("@blackbelt-technology/pi-dashboard-shared/config.js");
|
|
469
519
|
const cfg = configModule.loadConfig();
|
|
520
|
+
const tlsEndpoints = deps.tls?.tlsListenerUrls() ?? [];
|
|
470
521
|
const endpoints = collectEndpoints({
|
|
471
522
|
providerEndpoints,
|
|
472
523
|
publicBaseUrls: configModule.resolvePublicBaseUrls(cfg),
|
|
473
524
|
port: config.port,
|
|
474
|
-
tlsEndpoints
|
|
525
|
+
tlsEndpoints,
|
|
475
526
|
});
|
|
476
|
-
|
|
527
|
+
// `tlsEndpoints` names the certificate-backed listener URLs on their own, so the token dialog can point at
|
|
528
|
+
// the native HTTPS address (a tunnel endpoint of the same shape is not a bridge target).
|
|
529
|
+
// See change: prove-vault-bridge-tls (D8).
|
|
530
|
+
return { success: true, data: { endpoints, tlsEndpoints } } satisfies ApiResponse;
|
|
477
531
|
},
|
|
478
532
|
);
|
|
479
533
|
|
|
@@ -639,6 +693,9 @@ export function registerSystemRoutes(
|
|
|
639
693
|
// work is scheduled, never awaited here. A reconcile failure is reported in TLS
|
|
640
694
|
// status; the config stays as written. See change: add-tailscale-cert-tls (D7).
|
|
641
695
|
if (partial.tls !== undefined) {
|
|
696
|
+
// BEFORE the reconcile: closing the listener waits for upgraded (bridge) sockets, which `closeAllConnections`
|
|
697
|
+
// does not reach, so withdraw values and close TLS-admitted bridges first. See change: prove-vault-bridge-tls (D2).
|
|
698
|
+
deps.onTlsBridgeSwitchChanged?.();
|
|
642
699
|
try {
|
|
643
700
|
await deps.tls?.reconcile();
|
|
644
701
|
} catch (err) {
|
|
@@ -764,6 +821,10 @@ export function registerSystemRoutes(
|
|
|
764
821
|
source,
|
|
765
822
|
authActive: Boolean((fastify as any)._reloadAuth),
|
|
766
823
|
providerCount: Object.keys(cfg.auth?.providers ?? {}).length,
|
|
824
|
+
// Live (from the auth plugin's authState, not config.json): providers with no
|
|
825
|
+
// allowlist/group map; `refused` = public IdP (login refused), `open` = allow-all.
|
|
826
|
+
// See change: close-security-map-high-findings (D3).
|
|
827
|
+
openEnrolment: (fastify as any)._authOpenEnrolment?.() ?? [],
|
|
767
828
|
},
|
|
768
829
|
} satisfies ApiResponse;
|
|
769
830
|
},
|
|
@@ -1138,6 +1199,17 @@ export function registerSystemRoutes(
|
|
|
1138
1199
|
if (canDiscloseAccessPosture(request)) {
|
|
1139
1200
|
try { accessGrants = readAccessGrants?.() ?? null; } catch { /* keep null */ }
|
|
1140
1201
|
}
|
|
1202
|
+
// Live pi-trust query counters: same disclosure gate as `accessGrants`.
|
|
1203
|
+
let piTrustMirror: { live: PiTrustLiveCounters } | null = null;
|
|
1204
|
+
if (readPiTrustLive && canDiscloseAccessPosture(request)) {
|
|
1205
|
+
try { piTrustMirror = { live: readPiTrustLive() }; } catch { /* keep null */ }
|
|
1206
|
+
}
|
|
1207
|
+
// Baseline CSP report counters: counts only, same disclosure gate as `accessGrants`. Omitted
|
|
1208
|
+
// (absent, not null) for any other caller or when the read throws. See change: harden-cors-and-csp-reporting (D8).
|
|
1209
|
+
let cspReports: CspReportsSnapshot | null = null;
|
|
1210
|
+
if (readCspReports && canDiscloseAccessPosture(request)) {
|
|
1211
|
+
try { cspReports = readCspReports(); } catch { /* omit */ }
|
|
1212
|
+
}
|
|
1141
1213
|
// Inert-entry flag: a loopback entry in trustedNetworks/bypassHosts never
|
|
1142
1214
|
// admits tunnel traffic. Same disclosure gate as `accessGrants`.
|
|
1143
1215
|
// See change: fix-trusted-network-tunnel-bypass (D3).
|
|
@@ -1163,6 +1235,14 @@ export function registerSystemRoutes(
|
|
|
1163
1235
|
};
|
|
1164
1236
|
} catch { /* keep null */ }
|
|
1165
1237
|
}
|
|
1238
|
+
// Caller's own network-guard verdict (omitted on throw / absent dep).
|
|
1239
|
+
// See change: surface-network-denial-on-health (D3).
|
|
1240
|
+
const networkAccessField = (req: FastifyRequest): HealthNetworkAccessField => {
|
|
1241
|
+
try {
|
|
1242
|
+
if (readNetworkVerdict?.(req)) return { networkAccess: { error: NETWORK_NOT_ALLOWED, hint: GENERIC_NETWORK_DENIED_HINT } };
|
|
1243
|
+
} catch { /* omit */ }
|
|
1244
|
+
return {};
|
|
1245
|
+
};
|
|
1166
1246
|
// Push errors name local config (file paths, missing keys): same
|
|
1167
1247
|
// disclosure gate. Absent key when undisclosable or push is disabled.
|
|
1168
1248
|
// See change: add-server-push-notifications.
|
|
@@ -1191,6 +1271,12 @@ export function registerSystemRoutes(
|
|
|
1191
1271
|
// Access-grant prompting counters (additive; null when unwired or on a
|
|
1192
1272
|
// throwing read). See change: add-access-grant-dialog (task 9.3).
|
|
1193
1273
|
accessGrants,
|
|
1274
|
+
piTrustMirror,
|
|
1275
|
+
...(cspReports ? { cspReports } : {}),
|
|
1276
|
+
// A bare-loopback caller the strict default refuses for want of proof is told so (the
|
|
1277
|
+
// remedy is `pi-dashboard open`). Absent for every other caller. See change:
|
|
1278
|
+
// close-container-loopback-impersonation (D3).
|
|
1279
|
+
...(needsLocalProof(request, deps.localTrust) ? { localProof: LOCAL_PROOF_REQUIRED } : networkAccessField(request)),
|
|
1194
1280
|
...(tlsStatus ? { tls: tlsStatus } : {}),
|
|
1195
1281
|
// Loopback-trusted-entry posture (additive; null unless disclosable).
|
|
1196
1282
|
// See change: fix-trusted-network-tunnel-bypass (D3).
|
|
@@ -1299,7 +1385,7 @@ export function registerSystemRoutes(
|
|
|
1299
1385
|
// server log so it is discoverable live, not only post-mortem.
|
|
1300
1386
|
// See change: bound-session-heap-and-gc-telemetry (D3a).
|
|
1301
1387
|
sessionHeapFallback: heapFallbackStatus(),
|
|
1302
|
-
plugins: enrichWithBridgeSource(getPluginStatusStore().listAll()),
|
|
1388
|
+
plugins: toHealthPlugins(enrichWithBridgeSource(getPluginStatusStore().listAll())),
|
|
1303
1389
|
bundleHash,
|
|
1304
1390
|
// Served-artifact coherence (design D4). Additive; `bundleHash` above
|
|
1305
1391
|
// keeps its shape and meaning. No filesystem path is exposed.
|
|
@@ -1307,8 +1393,12 @@ export function registerSystemRoutes(
|
|
|
1307
1393
|
clientBuild,
|
|
1308
1394
|
proxy: getModelProxyStatus(),
|
|
1309
1395
|
// Windows-only: active git/sh source readout for Settings + Diagnostics.
|
|
1310
|
-
// null on macOS/Linux.
|
|
1311
|
-
|
|
1396
|
+
// null on macOS/Linux. `shellPath` is the bash.exe pi would resolve over the
|
|
1397
|
+
// same env a real spawn gets (buildSpawnEnv). See change:
|
|
1398
|
+
// embed-git-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
1399
|
+
gitSource: getGitSourceReadout(whichSync, {
|
|
1400
|
+
spawnEnv: () => new ToolResolver({ processExecPath: process.execPath }).buildSpawnEnv(process.env),
|
|
1401
|
+
}),
|
|
1312
1402
|
// Event-loop delay (ms) over the window since the last /api/health read.
|
|
1313
1403
|
// Correlates hydration spikes with real main-loop lag. Additive field.
|
|
1314
1404
|
// See change: instrument-session-hydration-timing.
|
|
@@ -1327,6 +1417,9 @@ export function registerSystemRoutes(
|
|
|
1327
1417
|
// Pi runtime divergence, under two distinct labels (see readPiDivergence).
|
|
1328
1418
|
// See change: select-pi-runtime-install (design D5).
|
|
1329
1419
|
piRuntime: readPiDivergence(),
|
|
1420
|
+
// A first plaintext-exposure write has not persisted: the hub refuses all remote vault delivery while true.
|
|
1421
|
+
// See change: prove-vault-bridge-tls (D4).
|
|
1422
|
+
pairing: { exposureWritePending: deps.exposureWritePending?.() === true },
|
|
1330
1423
|
// Per-hop dropped-frame counters (observability for silently-dropped
|
|
1331
1424
|
// WS frames). `serverToBrowser` = frames the fanout skipped under
|
|
1332
1425
|
// back-pressure, split transcript vs blocking; `bridgeToServer` = the max
|
|
@@ -1355,6 +1448,9 @@ export function registerSystemRoutes(
|
|
|
1355
1448
|
// See change: fix-backpressure-status-and-subagent-frames.
|
|
1356
1449
|
statusReconcileQueued: serverToBrowser.statusReconcileQueued,
|
|
1357
1450
|
statusReconcileSent: serverToBrowser.statusReconcileSent,
|
|
1451
|
+
// Subagent end / liveness frames deferred instead of shed. Not a
|
|
1452
|
+
// drop. See change: fix-background-subagent-ghost-rows (D6).
|
|
1453
|
+
deferredSubagentFrames: serverToBrowser.deferredSubagentFrames,
|
|
1358
1454
|
};
|
|
1359
1455
|
})(),
|
|
1360
1456
|
// Browser-socket `bufferedAmount` occupancy. The drop counters are
|
|
@@ -1368,24 +1464,6 @@ export function registerSystemRoutes(
|
|
|
1368
1464
|
// not typecheck `b`, so an inline literal could silently drift.
|
|
1369
1465
|
// See change: fix-backpressure-status-and-subagent-frames.
|
|
1370
1466
|
socketBufferOccupancy: browserGateway?.getSocketBufferOccupancy?.() ?? EMPTY_SOCKET_BUFFER_OCCUPANCY,
|
|
1371
|
-
// Subagent-tick throttle counters, summed across active bridges. Rides
|
|
1372
|
-
// the heartbeat `processMetrics` transport, so the per-session breakdown
|
|
1373
|
-
// is already in `agents[]` above and this block is the session-agnostic
|
|
1374
|
-
// roll-up. `tickDiscardedAtTerminal` + `tickDroppedNotReady` are the
|
|
1375
|
-
// throttle's only two information-loss modes; they sit here beside the
|
|
1376
|
-
// other silent-loss counters for exactly that reason.
|
|
1377
|
-
// See change: reduce-bridge-tick-bandwidth (D6).
|
|
1378
|
-
subagentTickThrottle: activeSessions.reduce(
|
|
1379
|
-
(acc, s) => {
|
|
1380
|
-
const m = s.processMetrics as Record<string, number | undefined> | undefined;
|
|
1381
|
-
acc.tickForwarded += m?.tickForwarded ?? 0;
|
|
1382
|
-
acc.tickCoalesced += m?.tickCoalesced ?? 0;
|
|
1383
|
-
acc.tickDiscardedAtTerminal += m?.tickDiscardedAtTerminal ?? 0;
|
|
1384
|
-
acc.tickDroppedNotReady += m?.tickDroppedNotReady ?? 0;
|
|
1385
|
-
return acc;
|
|
1386
|
-
},
|
|
1387
|
-
{ tickForwarded: 0, tickCoalesced: 0, tickDiscardedAtTerminal: 0, tickDroppedNotReady: 0 },
|
|
1388
|
-
),
|
|
1389
1467
|
// Plugin event-forward registry counters summed across active bridges
|
|
1390
1468
|
// (declared channels, rejected declaration entries, conflicts, retained +
|
|
1391
1469
|
// dropped stream/latest messages). See change: add-plugin-bridge-contributions.
|
|
@@ -1401,6 +1479,22 @@ export function registerSystemRoutes(
|
|
|
1401
1479
|
},
|
|
1402
1480
|
{ declared: 0, rejected: 0, conflicts: 0, retained: 0, dropped: 0 },
|
|
1403
1481
|
),
|
|
1482
|
+
// Plugin tool-update filters summed across active bridges (declared filters,
|
|
1483
|
+
// refused declarations, applied drops). See change: move-subagents-to-plugin (D5).
|
|
1484
|
+
pluginToolUpdateFilter: activeSessions.reduce(
|
|
1485
|
+
(acc, s) => {
|
|
1486
|
+
const m = s.processMetrics as Record<string, number | undefined> | undefined;
|
|
1487
|
+
acc.declared += m?.toolUpdateFilterDeclared ?? 0;
|
|
1488
|
+
acc.refused += m?.toolUpdateFilterRefused ?? 0;
|
|
1489
|
+
acc.applied += m?.toolUpdateFilterApplied ?? 0;
|
|
1490
|
+
return acc;
|
|
1491
|
+
},
|
|
1492
|
+
{ declared: 0, refused: 0, applied: 0 },
|
|
1493
|
+
),
|
|
1494
|
+
// Plugin entry replay + rejected plugin actions: declared replay entry
|
|
1495
|
+
// types (gauge), replayed plugin entries and rejected plugin_action /
|
|
1496
|
+
// plugin-route commands (cumulative). See change: update-flows-plugin (task 1.7).
|
|
1497
|
+
pluginEntries: getPluginEntryStats(),
|
|
1404
1498
|
// Poll-cost counters (SUM across live sessions, not max).
|
|
1405
1499
|
// See change: optimize-polling-hot-paths.
|
|
1406
1500
|
pollCost: activeSessions.reduce(
|
|
@@ -1429,6 +1523,8 @@ export function registerSystemRoutes(
|
|
|
1429
1523
|
// Cumulative tool-result route answers: `202` still running, `410`
|
|
1430
1524
|
// recorded eviction. See change: distinguish-tool-result-pending-vs-gone (D6).
|
|
1431
1525
|
toolResult: { pending: toolResultStats?.pending ?? 0, gone: toolResultStats?.gone ?? 0 },
|
|
1526
|
+
// Plugin windowed-replay carry counters. See change: move-subagents-to-plugin (D2).
|
|
1527
|
+
pluginReplayCarry: getPluginPolicyRegistry().stats().replayCarry,
|
|
1432
1528
|
// Store-derived retention signals (D4), DELIBERATELY separate from the
|
|
1433
1529
|
// cumulative `storeTrim` counters: a gauge, a set of configuration
|
|
1434
1530
|
// constants and a boolean latch all break the "never reset on read"
|
|
@@ -1490,7 +1586,13 @@ export function registerSystemRoutes(
|
|
|
1490
1586
|
// Tear down the zrok tunnel (and sweep orphans on our port) so restarts
|
|
1491
1587
|
// don't leak reservations that leave stale URLs backed by nothing.
|
|
1492
1588
|
try { await deleteTunnel(config.port); } catch { /* best-effort */ }
|
|
1493
|
-
|
|
1589
|
+
// Point of no return: refuse new credential work, then exit only after
|
|
1590
|
+
// in-flight writes (a rotated single-use refresh token) settle. The reply
|
|
1591
|
+
// goes out first, so the caller's fetch timeout is not spent on the wait.
|
|
1592
|
+
// See change: settle-server-credential-writes-on-exit.
|
|
1593
|
+
exitBarrier.closeGate();
|
|
1594
|
+
exitBarrier.commitExit(0);
|
|
1595
|
+
scheduleExit(0, 100);
|
|
1494
1596
|
return { ok: true };
|
|
1495
1597
|
},
|
|
1496
1598
|
);
|
|
@@ -1562,7 +1664,12 @@ export function registerSystemRoutes(
|
|
|
1562
1664
|
// runtime identity and its watchdog). `cli start` would come back Standalone.
|
|
1563
1665
|
// See change: electron-runtime-overlay-updates.
|
|
1564
1666
|
if (restartsViaElectron(process.env)) {
|
|
1565
|
-
|
|
1667
|
+
// Latch the code now: the orchestrator's SIGTERM may land inside the
|
|
1668
|
+
// settle window and must not turn this restart into a plain exit 0.
|
|
1669
|
+
// See change: settle-server-credential-writes-on-exit.
|
|
1670
|
+
exitBarrier.closeGate();
|
|
1671
|
+
exitBarrier.commitExit(ELECTRON_RESTART_EXIT_CODE);
|
|
1672
|
+
scheduleExit(ELECTRON_RESTART_EXIT_CODE, 200);
|
|
1566
1673
|
return { ok: true };
|
|
1567
1674
|
}
|
|
1568
1675
|
|
|
@@ -1589,21 +1696,31 @@ export function registerSystemRoutes(
|
|
|
1589
1696
|
// polls the port via net, spawns the new server, polls /api/health
|
|
1590
1697
|
// via http. No dependency on sh/lsof/curl — works on Windows too.
|
|
1591
1698
|
// See change: fix-windows-server-parity.
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1699
|
+
// Point of no return (every refusal above left the gate open): refuse
|
|
1700
|
+
// new credential work before the orchestrator can SIGTERM us.
|
|
1701
|
+
// See change: settle-server-credential-writes-on-exit.
|
|
1702
|
+
exitBarrier.closeGate();
|
|
1703
|
+
exitBarrier.commitExit(0);
|
|
1704
|
+
try {
|
|
1705
|
+
spawnRestart({
|
|
1706
|
+
cliPath,
|
|
1707
|
+
loader,
|
|
1708
|
+
port: config.port,
|
|
1709
|
+
// Carry the bound gateway port across the restart. Without it the new
|
|
1710
|
+
// process re-resolves it from the file config (which usually has no
|
|
1711
|
+
// `piPort`), lands on the 9999 default, and every live pi bridge — still
|
|
1712
|
+
// dialling the old port — fails to re-register.
|
|
1713
|
+
// See change: restore-ask-user-tool-state-on-reconnect.
|
|
1714
|
+
piPort: config.piPort,
|
|
1715
|
+
extraArgs,
|
|
1716
|
+
dev: useDev,
|
|
1717
|
+
});
|
|
1718
|
+
} catch (err) {
|
|
1719
|
+
// A refused spawn must not strand a running server with a closed gate.
|
|
1720
|
+
exitBarrier.reopen();
|
|
1721
|
+
throw err;
|
|
1722
|
+
}
|
|
1723
|
+
scheduleExit(0, 200);
|
|
1607
1724
|
return { ok: true };
|
|
1608
1725
|
},
|
|
1609
1726
|
);
|