@blackbelt-technology/pi-agent-dashboard 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/README.md +85 -11
- package/docs/architecture.md +3020 -116
- package/package.json +31 -18
- package/packages/extension/package.json +10 -8
- package/packages/extension/src/ask-user-tool.ts +65 -3
- package/packages/extension/src/auto-session-namer.ts +190 -50
- package/packages/extension/src/bridge-handlers/dispatch.ts +504 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +229 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1069 -0
- package/packages/extension/src/bridge-handlers/ui-prompt-patch.ts +198 -0
- package/packages/extension/src/bridge-identity-log.ts +45 -0
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +517 -2534
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +259 -16
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +294 -24
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/empty-actionable-guard.ts +8 -3
- package/packages/extension/src/flow-event-wiring.ts +1 -1
- package/packages/extension/src/followup-buffer.ts +1 -1
- package/packages/extension/src/followup-drain.ts +79 -0
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +232 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +88 -0
- package/packages/extension/src/multiselect-list.ts +6 -2
- package/packages/extension/src/multiselect-polyfill.ts +2 -2
- package/packages/extension/src/openspec-cli-shim.ts +1 -1
- package/packages/extension/src/path-gate/decide.ts +15 -41
- package/packages/extension/src/path-gate/grant-cache.ts +3 -1
- package/packages/extension/src/path-gate/handler.ts +51 -2
- package/packages/extension/src/path-gate/index.ts +12 -1
- package/packages/extension/src/path-gate/resolve.ts +6 -124
- package/packages/extension/src/path-gate/roots.ts +4 -1
- package/packages/extension/src/path-gate/suppression.ts +4 -1
- package/packages/extension/src/path-gate/yolo-link.ts +104 -0
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +258 -25
- package/packages/extension/src/prompt-expander.ts +5 -1
- package/packages/extension/src/prompt-meta.ts +64 -0
- package/packages/extension/src/provider-register.ts +146 -38
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/role-model-tools.ts +47 -6
- package/packages/extension/src/server-auto-start.ts +13 -6
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +73 -50
- package/packages/extension/src/spawn-token.ts +46 -0
- package/packages/extension/src/stream-forward-buffer.ts +161 -0
- package/packages/extension/src/subagent-frame-buffer.ts +6 -2
- package/packages/extension/src/subagent-tick-throttle.ts +3 -1
- package/packages/extension/src/vault-delivery.ts +404 -0
- package/packages/extension/src/vault-forwarder.ts +128 -0
- package/packages/extension/src/vault-masker.ts +165 -0
- package/packages/extension/src/vault-redaction.ts +181 -0
- package/packages/extension/src/vcs-info.ts +5 -2
- package/packages/server/bin/pi-dashboard.mjs +26 -89
- package/packages/server/package.json +29 -15
- package/packages/server/src/access/access-grants.ts +79 -8
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +5 -1
- package/packages/server/src/access/agent-confirm-registry.ts +31 -13
- package/packages/server/src/access/agent-grant.ts +1 -1
- package/packages/server/src/access/agent-yolo.ts +91 -0
- package/packages/server/src/access/containment-gate.ts +82 -17
- package/packages/server/src/access/cwd-admission-log.ts +46 -0
- package/packages/server/src/access/cwd-verdict.ts +144 -0
- package/packages/server/src/access/grant-coordinator.ts +3 -1
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +407 -0
- package/packages/server/src/access/planes.ts +116 -2
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +127 -14
- package/packages/server/src/acp-bridge/acp-connection.ts +225 -0
- package/packages/server/src/acp-bridge/acp-restore.ts +41 -0
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +549 -0
- package/packages/server/src/acp-bridge/child-env.ts +73 -0
- package/packages/server/src/acp-bridge/event-log.ts +194 -0
- package/packages/server/src/acp-bridge/gateway-client.ts +136 -0
- package/packages/server/src/acp-bridge/local-bridge-socket.ts +67 -0
- package/packages/server/src/acp-bridge/local-host.ts +132 -0
- package/packages/server/src/acp-bridge/main.ts +118 -0
- package/packages/server/src/acp-bridge/models.ts +33 -0
- package/packages/server/src/acp-bridge/permission-bridge.ts +106 -0
- package/packages/server/src/acp-bridge/server-requests.ts +136 -0
- package/packages/server/src/acp-bridge/session-state.ts +127 -0
- package/packages/server/src/addons/addon-toggle-restore.ts +110 -0
- package/packages/server/src/addons/addons-catalog.ts +408 -0
- package/packages/server/src/addons/addons-folder-service.ts +347 -0
- package/packages/server/src/addons/addons-folder.ts +310 -0
- package/packages/server/src/addons/addons-service.ts +470 -0
- package/packages/server/src/addons/package-contents.ts +99 -0
- package/packages/server/src/addons/settings-entries.ts +120 -0
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/audit-log.ts +80 -0
- package/packages/server/src/auth/auth-plugin.ts +329 -97
- package/packages/server/src/auth/auth.ts +102 -11
- package/packages/server/src/auth/bearer-auth.ts +74 -12
- package/packages/server/src/auth/cors-origin.ts +86 -29
- package/packages/server/src/auth/csp-report-paths.ts +31 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +111 -9
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/host-admission.ts +26 -0
- package/packages/server/src/auth/host-gate.ts +6 -1
- package/packages/server/src/auth/local-credential.ts +258 -0
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +76 -22
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +298 -17
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/network-trust-telemetry.ts +126 -0
- package/packages/server/src/auth/node-guard.ts +43 -0
- package/packages/server/src/auth/operate-required.ts +126 -0
- package/packages/server/src/auth/passkey/challenge-store.ts +90 -0
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +109 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +232 -0
- package/packages/server/src/auth/passkey/passkey-service.ts +247 -0
- package/packages/server/src/auth/passkey/phone-signin.ts +211 -0
- package/packages/server/src/auth/passkey/requester.ts +83 -0
- package/packages/server/src/auth/passkey/rp-context.ts +98 -0
- package/packages/server/src/auth/passkey/user-directory.ts +348 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +324 -0
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +61 -9
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/radius-override.ts +13 -0
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +27 -11
- package/packages/server/src/auth/runtime-provider-catalogue.ts +107 -0
- package/packages/server/src/auth/scan-legacy-provider-ids.ts +80 -0
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +197 -0
- package/packages/server/src/auth/trust-mode-boot.ts +93 -0
- package/packages/server/src/auth/trust-mode.ts +83 -0
- package/packages/server/src/auth/ws-ticket.ts +39 -1
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/auto-name-outcome-store.ts +4 -1
- package/packages/server/src/browse.ts +114 -2
- package/packages/server/src/browser-handlers/acp-guard.ts +79 -0
- package/packages/server/src/browser-handlers/directory-handler.ts +151 -6
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +138 -63
- package/packages/server/src/browser-handlers/session-meta-handler.ts +16 -6
- package/packages/server/src/browser-handlers/spawn-choice.ts +99 -0
- package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli.ts +1063 -106
- package/packages/server/src/config-api.ts +166 -2
- package/packages/server/src/config-snapshot.ts +53 -1
- package/packages/server/src/directory-service.ts +545 -36
- package/packages/server/src/embed-lifecycle/caps.ts +35 -4
- package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +45 -4
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +195 -20
- package/packages/server/src/embed-lifecycle/lifecycle-metrics.ts +38 -0
- package/packages/server/src/embed-lifecycle/plugin-session-close.ts +123 -0
- package/packages/server/src/embed-lifecycle/quiescence.ts +29 -3
- package/packages/server/src/embed-lifecycle/reclaim-give-up.ts +54 -0
- package/packages/server/src/event-wiring.ts +349 -141
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +60 -15
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +91 -6
- package/packages/server/src/git-worktree/worktree-init.ts +7 -56
- package/packages/server/src/identity/host-resources.ts +3 -0
- package/packages/server/src/identity/http-road-classification.ts +31 -1
- package/packages/server/src/identity/identity-registration-tracker.ts +4 -1
- package/packages/server/src/identity/plugin-identity.ts +19 -0
- package/packages/server/src/identity/policy-registry.ts +4 -1
- package/packages/server/src/identity/resolver-registry.ts +12 -3
- package/packages/server/src/identity/ws-message-scope.ts +10 -0
- package/packages/server/src/identity/ws-road-classification.ts +10 -0
- package/packages/server/src/known-server-moves.ts +196 -0
- package/packages/server/src/lib/browse-roots.ts +137 -0
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/digest-gate.ts +82 -0
- package/packages/server/src/lib/eml.ts +3 -8
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/file-write-lock.ts +24 -0
- package/packages/server/src/lib/folder-project.ts +439 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +93 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/office-preview.ts +2 -3
- package/packages/server/src/lib/path-containment.ts +7 -0
- package/packages/server/src/lib/purify.ts +13 -5
- package/packages/server/src/lib/resolve-file-mention.ts +11 -9
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +16 -1
- package/packages/server/src/lifecycle/classify-dashboard-port.ts +134 -0
- package/packages/server/src/lifecycle/home-lock.ts +344 -130
- package/packages/server/src/lifecycle/home-rendezvous.ts +41 -11
- package/packages/server/src/lifecycle/recovery-server.ts +129 -6
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/capability-redact.ts +15 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +461 -0
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +93 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +21 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +209 -33
- package/packages/server/src/live-server/live-server-proxy.ts +326 -34
- package/packages/server/src/live-server/live-static.ts +228 -0
- package/packages/server/src/metrics/eventloop-spike-metrics.ts +2 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +27 -26
- package/packages/server/src/model-proxy/internal-registry.ts +6 -0
- package/packages/server/src/model-proxy/server-model-runtime.ts +6 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +111 -16
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +189 -11
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +126 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +286 -44
- package/packages/server/src/openspec/proposal-attach-naming.ts +5 -3
- package/packages/server/src/openspec/readiness.ts +9 -0
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +1002 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/package-health-scanner.ts +133 -0
- package/packages/server/src/package/package-manager-wrapper.ts +18 -2
- package/packages/server/src/package/provider-catalogue-cache.ts +17 -3
- package/packages/server/src/package/provider-probe.ts +13 -5
- package/packages/server/src/pairing/browser-gateway.ts +292 -16
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/paired-devices.ts +335 -22
- package/packages/server/src/pairing/pairing.ts +188 -31
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/subagent-resync-routing.ts +4 -1
- package/packages/server/src/pairing/ws-tier-gate.ts +34 -0
- package/packages/server/src/peer-servers.ts +77 -0
- package/packages/server/src/pending/pending-plugin-ref-registry.ts +57 -2
- package/packages/server/src/persistence/boot-state.ts +48 -1
- package/packages/server/src/persistence/memory-event-store.ts +216 -237
- package/packages/server/src/persistence/meta-persistence.ts +12 -1
- package/packages/server/src/persistence/preferences-store.ts +125 -7
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-upgrade-auth.ts +48 -22
- package/packages/server/src/pi/folder-commands.ts +141 -0
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/gateway-socket-bind.ts +9 -3
- package/packages/server/src/pi/gateway-transport-policy.ts +13 -0
- package/packages/server/src/pi/host-project-trust.ts +166 -33
- package/packages/server/src/pi/pi-gateway.ts +283 -29
- package/packages/server/src/pi/pi-resource-scanner.ts +15 -0
- package/packages/server/src/pi/resource-activation-toggle.ts +6 -0
- package/packages/server/src/pi/resource-toggle-trust.ts +34 -2
- package/packages/server/src/pi/session-skill-registry.ts +13 -3
- package/packages/server/src/pi/settings-write-lock.ts +32 -0
- package/packages/server/src/pi/trust-challenges.ts +38 -0
- package/packages/server/src/pi-agent-settings.ts +701 -100
- package/packages/server/src/pi-settings-themes.ts +104 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/questions/brief-generator.ts +138 -0
- package/packages/server/src/questions/brief-model.ts +55 -0
- package/packages/server/src/questions/brief-policy.ts +36 -0
- package/packages/server/src/questions/brief-prompt.ts +92 -0
- package/packages/server/src/questions/brief-runtime.ts +50 -0
- package/packages/server/src/questions/question-answer.ts +55 -0
- package/packages/server/src/questions/question-broadcast.ts +106 -0
- package/packages/server/src/questions/question-files.ts +128 -0
- package/packages/server/src/questions/question-routes.ts +126 -0
- package/packages/server/src/questions/question-snapshot.ts +150 -0
- package/packages/server/src/questions/question-stack.ts +57 -0
- package/packages/server/src/questions/question-store.ts +477 -0
- package/packages/server/src/routes/access-prompt-routes.ts +5 -3
- package/packages/server/src/routes/access-routes.ts +274 -6
- package/packages/server/src/routes/acme-routes.ts +190 -0
- package/packages/server/src/routes/acp-routes.ts +16 -0
- package/packages/server/src/routes/addons-routes.ts +221 -0
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +620 -209
- package/packages/server/src/routes/file-write-binary-routes.ts +530 -0
- package/packages/server/src/routes/folder-project-routes.ts +105 -0
- package/packages/server/src/routes/git-routes.ts +334 -203
- package/packages/server/src/routes/grep-routes.ts +38 -14
- package/packages/server/src/routes/known-servers-routes.ts +433 -55
- package/packages/server/src/routes/live-server-routes.ts +438 -7
- package/packages/server/src/routes/local-proof-routes.ts +26 -7
- package/packages/server/src/routes/mermaid-repair-routes.ts +254 -0
- package/packages/server/src/routes/model-proxy-routes.ts +4 -2
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +636 -55
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +86 -11
- package/packages/server/src/routes/pairing-routes.ts +303 -33
- package/packages/server/src/routes/pi-retry-routes.ts +18 -2
- package/packages/server/src/routes/pi-settings-routes.ts +264 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +146 -27
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/provider-auth-routes.ts +37 -7
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +33 -35
- package/packages/server/src/routes/session-routes.ts +100 -9
- package/packages/server/src/routes/system-routes.ts +286 -33
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +15 -2
- package/packages/server/src/runtime-overlay/runtime-update-checker.ts +11 -2
- package/packages/server/src/server.ts +1537 -246
- package/packages/server/src/services/attached-driver.ts +175 -0
- package/packages/server/src/services/change-notifier.ts +55 -0
- package/packages/server/src/services/cli-service.ts +450 -0
- package/packages/server/src/services/command-runner.ts +92 -0
- package/packages/server/src/services/definitions-store.ts +121 -0
- package/packages/server/src/services/driver.ts +112 -0
- package/packages/server/src/services/health.ts +94 -0
- package/packages/server/src/services/leases.ts +117 -0
- package/packages/server/src/services/log-text.ts +97 -0
- package/packages/server/src/services/native-driver.ts +283 -0
- package/packages/server/src/services/oci-driver.ts +590 -0
- package/packages/server/src/services/output-capture.ts +183 -0
- package/packages/server/src/services/paths.ts +82 -0
- package/packages/server/src/services/ports.ts +26 -0
- package/packages/server/src/services/routes.ts +140 -0
- package/packages/server/src/services/runtime-detect.ts +108 -0
- package/packages/server/src/services/secret-delivery.ts +61 -0
- package/packages/server/src/services/secrets-resolver.ts +145 -0
- package/packages/server/src/services/secrets-store.ts +137 -0
- package/packages/server/src/services/service-manager.ts +1565 -0
- package/packages/server/src/services/start-record.ts +66 -0
- package/packages/server/src/services/state-machine.ts +241 -0
- package/packages/server/src/session/archive-sweeper.ts +92 -3
- package/packages/server/src/session/custom-event-group-matcher.ts +4 -3
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +60 -0
- package/packages/server/src/session/name-provenance.ts +102 -0
- package/packages/server/src/session/open-tool-calls.ts +15 -6
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/session-api.ts +47 -12
- package/packages/server/src/session/session-archive.ts +56 -4
- package/packages/server/src/session/session-diff-cache.ts +11 -4
- package/packages/server/src/session/session-load-worker-pool.ts +4 -3
- package/packages/server/src/session/session-load-worker.ts +11 -2
- package/packages/server/src/session/session-scanner.ts +73 -3
- package/packages/server/src/session/session-to-meta.ts +15 -0
- package/packages/server/src/spawn-process/abort-spawned-run.ts +55 -0
- package/packages/server/src/spawn-process/acp-spawn.ts +131 -0
- package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
- package/packages/server/src/spawn-process/process-manager.ts +164 -30
- package/packages/server/src/spawn-process/restart-helper.ts +9 -8
- package/packages/server/src/spawn-process/server-pid.ts +16 -7
- package/packages/server/src/spawn-process/session-terminator.ts +218 -0
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +159 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +10 -1
- package/packages/server/src/terminal/terminal-manager.ts +75 -1
- package/packages/server/src/tls/cert-files.ts +228 -0
- package/packages/server/src/tls/cert-manager.ts +703 -0
- package/packages/server/src/tls/cert-store.ts +69 -0
- package/packages/server/src/tls/source-registry.ts +71 -0
- package/packages/server/src/tls/sources/acme/accounts.ts +76 -0
- package/packages/server/src/tls/sources/acme/acme-source.ts +508 -0
- package/packages/server/src/tls/sources/acme/config-projection.ts +34 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +185 -0
- package/packages/server/src/tls/sources/acme/dns.ts +303 -0
- package/packages/server/src/tls/sources/acme/e2e-overrides.ts +49 -0
- package/packages/server/src/tls/sources/acme/entry.ts +180 -0
- package/packages/server/src/tls/sources/acme/gc.ts +78 -0
- package/packages/server/src/tls/sources/acme/runtime.ts +51 -0
- package/packages/server/src/tls/sources/acme/solvers/acme-dns.ts +154 -0
- package/packages/server/src/tls/sources/acme/solvers/cloudflare.ts +147 -0
- package/packages/server/src/tls/sources/acme/types.ts +72 -0
- package/packages/server/src/tls/sources/tailscale-cert.ts +172 -0
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +94 -0
- package/packages/server/src/tls/tls-listener.ts +351 -0
- package/packages/server/src/tls/types.ts +80 -0
- package/packages/server/src/tunnel/tunnel-block-events.ts +4 -1
- package/packages/server/src/tunnel/tunnel-core.ts +4 -1
- package/packages/server/src/tunnel/tunnel-endpoints.ts +4 -0
- package/packages/server/src/tunnel-providers/tailscale.ts +27 -6
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +424 -0
- package/packages/server/src/vault/vault-grants.ts +260 -0
- package/packages/server/src/vault/vault-import.ts +161 -0
- package/packages/server/src/vault/vault-permissions.ts +39 -0
- package/packages/server/src/vault/vault-plugin-read.ts +64 -0
- package/packages/server/src/vault/vault-projects.ts +156 -0
- package/packages/server/src/vault/vault-routes.ts +277 -0
- package/packages/server/src/vault/vault-store.ts +371 -0
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/shared/package.json +5 -2
- package/packages/shared/src/acp/acp-config.ts +123 -0
- package/packages/shared/src/acp/normalize-v1.ts +92 -0
- package/packages/shared/src/acp/paths.ts +36 -0
- package/packages/shared/src/acp/to-dashboard-events.ts +533 -0
- package/packages/shared/src/acp/update-model.ts +574 -0
- package/packages/shared/src/anthropic-messages-source.ts +8 -0
- package/packages/shared/src/bind-reachability.ts +21 -2
- package/packages/shared/src/boot-state.ts +6 -0
- package/packages/shared/src/browser-host-identity.ts +49 -0
- package/packages/shared/src/browser-host-ipc.ts +107 -0
- package/packages/shared/src/browser-protocol.ts +533 -73
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +817 -51
- package/packages/shared/src/containment-guard.ts +35 -0
- package/packages/shared/src/custom-event-groups.ts +5 -2
- package/packages/shared/src/cwd-guard.ts +381 -1
- package/packages/shared/src/dashboard-paths.ts +12 -0
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
- package/packages/shared/src/dashboard-plugin/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +73 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +9 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +160 -3
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
- package/packages/shared/src/dashboard-plugin/project-identity.ts +42 -0
- package/packages/shared/src/dashboard-plugin/project-markers.ts +60 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +139 -2
- package/packages/shared/src/dashboard-plugin/slot-types.ts +72 -4
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +50 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +119 -134
- package/packages/shared/src/enabled-models-match.ts +47 -0
- package/packages/shared/src/event-forward-declaration.ts +187 -0
- package/packages/shared/src/file-kind.ts +54 -2
- package/packages/shared/src/git-worktree-helpers.ts +8 -4
- package/packages/shared/src/grammar-types.ts +3 -1
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/host-port.ts +34 -0
- package/packages/shared/src/launcher-origin.ts +26 -0
- package/packages/shared/src/live-server.ts +141 -0
- package/packages/shared/src/local-credential-proof.ts +219 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/markup-repair/asciidoc.ts +130 -0
- package/packages/shared/src/markup-repair/types.ts +13 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
- package/packages/shared/src/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +414 -45
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +213 -11
- package/packages/shared/src/openspec-status-all.ts +393 -0
- package/packages/shared/src/operate-required.ts +29 -0
- package/packages/shared/src/pairing-knock-client.ts +301 -0
- package/packages/shared/src/pairing-knock.ts +71 -0
- package/packages/shared/src/pairing-refusal.ts +32 -0
- package/packages/shared/src/path-containment-guard-name.ts +8 -0
- package/packages/shared/src/pi-settings-keys.ts +9 -0
- package/packages/shared/src/pi-settings-schema.ts +285 -0
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +198 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +90 -0
- package/packages/shared/src/pi-trust-mirror.ts +354 -0
- package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +210 -4
- package/packages/shared/src/platform/native-ts-hooks.mjs +93 -40
- package/packages/shared/src/platform/native-ts-register.mjs +22 -10
- package/packages/shared/src/platform/native-ts-tier.d.mts +1 -0
- package/packages/shared/src/platform/native-ts-tier.mjs +17 -0
- package/packages/shared/src/platform/node-spawn.ts +1 -2
- package/packages/shared/src/platform/openspec.ts +129 -31
- package/packages/shared/src/platform/process-scan.ts +199 -1
- package/packages/shared/src/platform/process.ts +99 -4
- package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-mechanism.ts +14 -2
- package/packages/shared/src/platform/ts-loader-select.d.mts +1 -7
- package/packages/shared/src/platform/ts-loader-select.mjs +14 -43
- package/packages/shared/src/plugin-bridge-register.ts +24 -1
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +138 -0
- package/packages/shared/src/project-name.ts +42 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +172 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +98 -23
- package/packages/shared/src/recovery-timing.ts +39 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/rest-api.ts +533 -3
- package/packages/shared/src/role-config-disk.ts +23 -0
- package/packages/shared/src/role-schema.ts +79 -0
- package/packages/shared/src/route-tiers.ts +181 -0
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +17 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +119 -8
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +21 -34
- package/packages/shared/src/server-pinning.ts +136 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/services/offers.ts +114 -0
- package/packages/shared/src/services/schema.ts +628 -0
- package/packages/shared/src/services/status.ts +169 -0
- package/packages/shared/src/session-meta.ts +59 -2
- package/packages/shared/src/session-name.ts +8 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/skill-block-parser.ts +14 -0
- package/packages/shared/src/source-matching.ts +5 -1
- package/packages/shared/src/state-replay.ts +19 -0
- package/packages/shared/src/terminal-safe.ts +24 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tls-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +31 -9
- package/packages/shared/src/tool-registry/index.ts +2 -2
- package/packages/shared/src/tool-registry/pi-tools.ts +32 -3
- package/packages/shared/src/tool-registry/strategies.ts +12 -11
- package/packages/shared/src/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +170 -9
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +88 -0
- package/packages/shared/src/vault-origin.ts +51 -0
- package/packages/shared/src/vault-project-key.ts +53 -0
- package/packages/shared/src/worktree-init-hook.ts +69 -0
- package/packages/shared/src/ws-message-tiers.ts +136 -0
- package/tsconfig.base.json +1 -0
|
@@ -45,9 +45,45 @@ import * as path from "node:path";
|
|
|
45
45
|
import { getDashboardConfigDir } from "@blackbelt-technology/pi-dashboard-shared/dashboard-paths.js";
|
|
46
46
|
import { isUngrantableSubject } from "./forbidden-subjects.js";
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Notified after a PERSISTED grant is written or revoked. Feeds the pi-trust
|
|
50
|
+
* mirror snapshot; set once by the server. See change: mirror-dashboard-trust-to-pi.
|
|
51
|
+
*/
|
|
52
|
+
let grantsChanged: (() => void) | undefined;
|
|
53
|
+
export function setGrantsChangedListener(fn: (() => void) | undefined): void {
|
|
54
|
+
grantsChanged = fn;
|
|
55
|
+
}
|
|
56
|
+
function notifyGrantsChanged(): void {
|
|
57
|
+
try {
|
|
58
|
+
grantsChanged?.();
|
|
59
|
+
} catch {
|
|
60
|
+
/* a listener never fails a grant */
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Notified SYNCHRONOUSLY when the in-memory session grants change. Separate from
|
|
66
|
+
* {@link setGrantsChangedListener} (persisted writes only). Feeds the pi-trust
|
|
67
|
+
* live count. See change: mirror-dashboard-trust-live-remote.
|
|
68
|
+
*/
|
|
69
|
+
let sessionGrantsChanged: (() => void) | undefined;
|
|
70
|
+
export function setSessionGrantsChangedListener(fn: (() => void) | undefined): void {
|
|
71
|
+
sessionGrantsChanged = fn;
|
|
72
|
+
}
|
|
73
|
+
function notifySessionGrantsChanged(): void {
|
|
74
|
+
try {
|
|
75
|
+
sessionGrantsChanged?.();
|
|
76
|
+
} catch {
|
|
77
|
+
/* a listener never fails a grant */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
48
81
|
/** `session` = in-memory, until server restart. `project` = persisted JSON. */
|
|
49
82
|
export type GrantScope = "session" | "project";
|
|
50
83
|
|
|
84
|
+
/** Which write path produced a grant (absent = the Access page's grant route). */
|
|
85
|
+
type GrantVia = "prompt" | "agent-prompt" | "provision";
|
|
86
|
+
|
|
51
87
|
/** One grant. Session-scoped grants carry the SAME four fields (D17) — not a bare Set. */
|
|
52
88
|
export interface AccessGrant {
|
|
53
89
|
/** Directory, realpath'd at grant time (D2). */
|
|
@@ -63,11 +99,13 @@ export interface AccessGrant {
|
|
|
63
99
|
*/
|
|
64
100
|
widenedFrom?: string;
|
|
65
101
|
/**
|
|
102
|
+
* `"provision"` = an operator approved a line of a project's provisioning request
|
|
103
|
+
* (change: add-access-provisioning); such a grant is never an eviction victim.
|
|
66
104
|
* `"prompt"` when an operator's allow-always answer to an access prompt wrote
|
|
67
105
|
* this grant (change: add-access-grant-dialog, task 8.2). Absent = the Access
|
|
68
106
|
* page's grant route. Optional and additive: older builds spread it through.
|
|
69
107
|
*/
|
|
70
|
-
via?:
|
|
108
|
+
via?: GrantVia;
|
|
71
109
|
}
|
|
72
110
|
|
|
73
111
|
/** D10: fixed cap, per scope. */
|
|
@@ -177,6 +215,8 @@ function loadFromDisk(): AccessGrant[] {
|
|
|
177
215
|
// The cap is a property of the STORE, not of the write path: a hand-edited or
|
|
178
216
|
// hostile file with 100k grants would otherwise be admitted in full, growing
|
|
179
217
|
// the hot path's Set per request and memory without bound.
|
|
218
|
+
// Load does not spare provisioned grants: the bound wins, so a hostile file
|
|
219
|
+
// full of `via: "provision"` entries still cannot grow the Set.
|
|
180
220
|
enforceCap(valid, "project");
|
|
181
221
|
return valid;
|
|
182
222
|
}
|
|
@@ -244,21 +284,36 @@ export function grantedSubjects(): string[] {
|
|
|
244
284
|
* already in the file could make it sort oldest, and evicting it would let
|
|
245
285
|
* `recordGrant` return `ok: true` for a grant that was never persisted: the UI
|
|
246
286
|
* would claim a grant that does not exist, the exact failure D11 forbids.
|
|
287
|
+
*
|
|
288
|
+
* `spareProvisioned` — `via: "provision"` grants are never victims (change:
|
|
289
|
+
* add-access-provisioning, D5). Returns `false` and mutates nothing when the
|
|
290
|
+
* excess cannot be fully evicted (`evict: false`, or every candidate spared).
|
|
291
|
+
* Every eviction is logged.
|
|
247
292
|
*/
|
|
248
|
-
function enforceCap(
|
|
293
|
+
function enforceCap(
|
|
294
|
+
grants: AccessGrant[],
|
|
295
|
+
scope: GrantScope,
|
|
296
|
+
opts: { protect?: AccessGrant; evict?: boolean; spareProvisioned?: boolean } = {},
|
|
297
|
+
): boolean {
|
|
249
298
|
const inScope = grants.filter((g) => g.scope === scope);
|
|
250
|
-
if (inScope.length <= GRANT_CAP_PER_SCOPE) return;
|
|
299
|
+
if (inScope.length <= GRANT_CAP_PER_SCOPE) return true;
|
|
300
|
+
if (opts.evict === false) return false;
|
|
251
301
|
const excess = inScope.length - GRANT_CAP_PER_SCOPE;
|
|
252
302
|
const evictOrder = inScope
|
|
253
|
-
.filter((g) => g !== protect)
|
|
303
|
+
.filter((g) => g !== opts.protect && !(opts.spareProvisioned && g.via === "provision"))
|
|
254
304
|
.map((g, i) => ({ g, i }))
|
|
255
305
|
.sort((a, b) => a.g.grantedAt - b.g.grantedAt || a.i - b.i)
|
|
256
306
|
.slice(0, excess)
|
|
257
307
|
.map((x) => x.g);
|
|
308
|
+
if (evictOrder.length < excess) return false;
|
|
258
309
|
const doomed = new Set(evictOrder);
|
|
259
310
|
for (let i = grants.length - 1; i >= 0; i -= 1) {
|
|
260
311
|
if (doomed.has(grants[i])) grants.splice(i, 1);
|
|
261
312
|
}
|
|
313
|
+
for (const g of evictOrder) {
|
|
314
|
+
console.warn(`[access-grants] evicted subject=${JSON.stringify(g.subject)} via=${g.via ?? "none"}`);
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
262
317
|
}
|
|
263
318
|
|
|
264
319
|
/** Atomic write: temp file in the same directory, then rename (D11). */
|
|
@@ -290,7 +345,12 @@ export interface RecordGrantInput {
|
|
|
290
345
|
origin?: string;
|
|
291
346
|
/** Set when the subject came from the denial's offered-ancestor ladder. */
|
|
292
347
|
widenedFrom?: string;
|
|
293
|
-
via?:
|
|
348
|
+
via?: GrantVia;
|
|
349
|
+
/**
|
|
350
|
+
* `false` = refuse with `{ok:false, error:"capacity"}` at the cap instead of
|
|
351
|
+
* evicting the oldest grant (change: add-access-provisioning). Default `true`.
|
|
352
|
+
*/
|
|
353
|
+
evict?: boolean;
|
|
294
354
|
now?: number;
|
|
295
355
|
}
|
|
296
356
|
|
|
@@ -303,7 +363,7 @@ export interface RecordGrantInput {
|
|
|
303
363
|
* did not stick.
|
|
304
364
|
*/
|
|
305
365
|
/** A grant with its optional provenance fields set only when present. */
|
|
306
|
-
function buildGrant(base: AccessGrant, widenedFrom: string | undefined, via:
|
|
366
|
+
function buildGrant(base: AccessGrant, widenedFrom: string | undefined, via: GrantVia | undefined): AccessGrant {
|
|
307
367
|
const grant: AccessGrant = { ...base };
|
|
308
368
|
if (widenedFrom) grant.widenedFrom = widenedFrom;
|
|
309
369
|
if (via) grant.via = via;
|
|
@@ -338,7 +398,11 @@ export function recordGrant(input: RecordGrantInput): RecordGrantResult {
|
|
|
338
398
|
if (existing) return { ok: true, grant: existing };
|
|
339
399
|
const grant = buildGrant({ subject, scope, grantedAt, origin }, widen, input.via);
|
|
340
400
|
sessionGrants.push(grant);
|
|
341
|
-
enforceCap(sessionGrants, "session", grant)
|
|
401
|
+
if (!enforceCap(sessionGrants, "session", { protect: grant, evict: input.evict, spareProvisioned: true })) {
|
|
402
|
+
sessionGrants.pop();
|
|
403
|
+
return { ok: false, error: "capacity" };
|
|
404
|
+
}
|
|
405
|
+
notifySessionGrantsChanged();
|
|
342
406
|
return { ok: true, grant };
|
|
343
407
|
}
|
|
344
408
|
|
|
@@ -347,7 +411,9 @@ export function recordGrant(input: RecordGrantInput): RecordGrantResult {
|
|
|
347
411
|
if (existing) return { ok: true, grant: existing };
|
|
348
412
|
const grant = buildGrant({ subject, scope, grantedAt, origin }, widen, input.via);
|
|
349
413
|
grants.push(grant);
|
|
350
|
-
enforceCap(grants, "project", grant)
|
|
414
|
+
if (!enforceCap(grants, "project", { protect: grant, evict: input.evict, spareProvisioned: true })) {
|
|
415
|
+
return { ok: false, error: "capacity" };
|
|
416
|
+
}
|
|
351
417
|
|
|
352
418
|
const file: StoreFile = { version: 1, grants };
|
|
353
419
|
try {
|
|
@@ -360,6 +426,7 @@ export function recordGrant(input: RecordGrantInput): RecordGrantResult {
|
|
|
360
426
|
return { ok: false, error: (err as Error)?.message ?? "write failed" };
|
|
361
427
|
}
|
|
362
428
|
cache = grants;
|
|
429
|
+
notifyGrantsChanged();
|
|
363
430
|
return { ok: true, grant };
|
|
364
431
|
}
|
|
365
432
|
|
|
@@ -373,12 +440,15 @@ export function revokeGrant(subject: string, scope?: GrantScope): boolean {
|
|
|
373
440
|
let removed = false;
|
|
374
441
|
|
|
375
442
|
if (scope !== "project") {
|
|
443
|
+
let sessionRemoved = false;
|
|
376
444
|
for (let i = sessionGrants.length - 1; i >= 0; i -= 1) {
|
|
377
445
|
if (sessionGrants[i].subject === target) {
|
|
378
446
|
sessionGrants.splice(i, 1);
|
|
379
447
|
removed = true;
|
|
448
|
+
sessionRemoved = true;
|
|
380
449
|
}
|
|
381
450
|
}
|
|
451
|
+
if (sessionRemoved) notifySessionGrantsChanged();
|
|
382
452
|
}
|
|
383
453
|
if (scope === "session") return removed;
|
|
384
454
|
|
|
@@ -394,5 +464,6 @@ export function revokeGrant(subject: string, scope?: GrantScope): boolean {
|
|
|
394
464
|
return false;
|
|
395
465
|
}
|
|
396
466
|
cache = kept;
|
|
467
|
+
notifyGrantsChanged();
|
|
397
468
|
return true;
|
|
398
469
|
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type { GrantCoordinator } from "./grant-coordinator.js";
|
|
14
14
|
import type { GrantRegistryStats } from "./pending-grant-registry.js";
|
|
15
15
|
import type { HostGateMode } from "./prompt-channel.js";
|
|
16
|
+
import type { ProvisionStats } from "./provisioning.js";
|
|
16
17
|
import type { YoloController } from "./yolo-session.js";
|
|
17
18
|
|
|
18
19
|
export interface AccessGrantHealth {
|
|
@@ -40,6 +41,12 @@ export interface AccessGrantHealth {
|
|
|
40
41
|
};
|
|
41
42
|
/** Remembered explicit refusals (the durable ledger). */
|
|
42
43
|
refusals: number;
|
|
44
|
+
/**
|
|
45
|
+
* Access-provisioning counters (design D14): cumulative except `pending`.
|
|
46
|
+
* Additive and optional: absent when no reader is wired; readers ignore it.
|
|
47
|
+
* See change: add-access-provisioning.
|
|
48
|
+
*/
|
|
49
|
+
provisioning?: ProvisionStats;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
export interface AccessGrantHealthDeps {
|
|
@@ -50,6 +57,8 @@ export interface AccessGrantHealthDeps {
|
|
|
50
57
|
killSwitch(): boolean;
|
|
51
58
|
hostGateMode(): HostGateMode;
|
|
52
59
|
operatorChannels(): number;
|
|
60
|
+
/** Provisioning registry stats; omit to leave `provisioning` out of the snapshot. */
|
|
61
|
+
provisioning?(): ProvisionStats;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
export function snapshotAccessGrantHealth(deps: AccessGrantHealthDeps): AccessGrantHealth {
|
|
@@ -73,5 +82,6 @@ export function snapshotAccessGrantHealth(deps: AccessGrantHealthDeps): AccessGr
|
|
|
73
82
|
refusedByPriorRefusal: totals.refusedByPriorRefusal,
|
|
74
83
|
},
|
|
75
84
|
refusals: deps.refusalCount(),
|
|
85
|
+
...(deps.provisioning ? { provisioning: deps.provisioning() } : {}),
|
|
76
86
|
};
|
|
77
87
|
}
|
|
@@ -35,7 +35,11 @@ interface PlaneGrantRequest {
|
|
|
35
35
|
|
|
36
36
|
type PlaneGrantResult =
|
|
37
37
|
| { ok: true; store: string; widenedFrom?: string }
|
|
38
|
-
| {
|
|
38
|
+
| {
|
|
39
|
+
ok: false;
|
|
40
|
+
reason: "unnamed" | "forbidden" | "invalid-subject" | "write-failed" | "unverifiable";
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
39
43
|
|
|
40
44
|
interface PlaneBase {
|
|
41
45
|
readonly id: AccessPlaneId;
|
|
@@ -13,6 +13,13 @@ const REDEEM_WINDOW_MS = 5_000;
|
|
|
13
13
|
const DEFAULT_TTL_MS = 120_000;
|
|
14
14
|
const CAP_PER_SESSION = 32;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* `confirm` entries are redeemable by a `path_grant_request`; `select` entries
|
|
18
|
+
* (the gate's select prompt) only by a `path_gate_refusal`. Never cross-kind.
|
|
19
|
+
* See change: yolo-covers-agent-path-gate.
|
|
20
|
+
*/
|
|
21
|
+
export type RegistryKind = "select" | "confirm";
|
|
22
|
+
|
|
16
23
|
type State = "pending" | "settled" | "used" | "cancelled";
|
|
17
24
|
|
|
18
25
|
interface Entry {
|
|
@@ -38,16 +45,22 @@ export function createAgentConfirmRegistry(opts: AgentConfirmRegistryOptions = {
|
|
|
38
45
|
const getTtl = opts.getTtlMs ?? (() => DEFAULT_TTL_MS);
|
|
39
46
|
const redeem = opts.redeemWindowMs ?? REDEEM_WINDOW_MS;
|
|
40
47
|
const cap = opts.capPerSession ?? CAP_PER_SESSION;
|
|
41
|
-
const bySession = new Map<string, Map<string, Entry
|
|
48
|
+
const bySession = new Map<string, Record<RegistryKind, Map<string, Entry>>>();
|
|
49
|
+
const find = (sessionId: string, promptId: string, kind?: RegistryKind): Entry | undefined => {
|
|
50
|
+
const m = bySession.get(sessionId);
|
|
51
|
+
if (!m) return undefined;
|
|
52
|
+
return kind ? m[kind].get(promptId) : (m.confirm.get(promptId) ?? m.select.get(promptId));
|
|
53
|
+
};
|
|
42
54
|
|
|
43
55
|
return {
|
|
44
56
|
/** Record a forwarded confirm prompt. A replay of a known promptId is ignored. */
|
|
45
|
-
observe(sessionId: string, promptId: string, info: { path: string; subject: string }): void {
|
|
46
|
-
let
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
bySession.set(sessionId,
|
|
57
|
+
observe(sessionId: string, promptId: string, info: { path: string; subject: string }, kind: RegistryKind = "confirm"): void {
|
|
58
|
+
let all = bySession.get(sessionId);
|
|
59
|
+
if (!all) {
|
|
60
|
+
all = { select: new Map(), confirm: new Map() };
|
|
61
|
+
bySession.set(sessionId, all);
|
|
50
62
|
}
|
|
63
|
+
const m = all[kind];
|
|
51
64
|
if (m.has(promptId)) return; // first sight only — never extends expiresAt
|
|
52
65
|
m.set(promptId, { path: info.path, subject: info.subject, expiresAt: now() + getTtl(), state: "pending" });
|
|
53
66
|
while (m.size > cap) {
|
|
@@ -58,15 +71,19 @@ export function createAgentConfirmRegistry(opts: AgentConfirmRegistryOptions = {
|
|
|
58
71
|
},
|
|
59
72
|
/** `prompt_cancel` (timeout / gate cancel): never redeemable again. */
|
|
60
73
|
cancel(sessionId: string, promptId: string): void {
|
|
61
|
-
const
|
|
62
|
-
|
|
74
|
+
for (const kind of ["select", "confirm"] as const) {
|
|
75
|
+
const e = find(sessionId, promptId, kind);
|
|
76
|
+
if (e) e.state = "cancelled";
|
|
77
|
+
}
|
|
63
78
|
},
|
|
64
79
|
/** `prompt_dismiss` (emitted on every settlement): redeemable for a short window. */
|
|
65
80
|
settle(sessionId: string, promptId: string): void {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
e.state
|
|
69
|
-
|
|
81
|
+
for (const kind of ["select", "confirm"] as const) {
|
|
82
|
+
const e = find(sessionId, promptId, kind);
|
|
83
|
+
if (e && e.state === "pending") {
|
|
84
|
+
e.state = "settled";
|
|
85
|
+
e.settledAt = now();
|
|
86
|
+
}
|
|
70
87
|
}
|
|
71
88
|
},
|
|
72
89
|
clearSession(sessionId: string): void {
|
|
@@ -81,8 +98,9 @@ export function createAgentConfirmRegistry(opts: AgentConfirmRegistryOptions = {
|
|
|
81
98
|
promptId: string,
|
|
82
99
|
req: { path: string; subject: string },
|
|
83
100
|
sameSubject: (a: string, b: string) => boolean,
|
|
101
|
+
kind: RegistryKind = "confirm",
|
|
84
102
|
): ConsumeResult {
|
|
85
|
-
const e =
|
|
103
|
+
const e = find(sessionId, promptId, kind);
|
|
86
104
|
if (!e) return { ok: false, error: "unknown confirmation" };
|
|
87
105
|
if (e.state === "used") return { ok: false, error: "confirmation already used" };
|
|
88
106
|
if (e.state === "cancelled") return { ok: false, error: "confirmation was cancelled" };
|
|
@@ -51,7 +51,7 @@ export function handlePathGrantRequest(
|
|
|
51
51
|
}
|
|
52
52
|
if (msg.sessionId !== connectionSessionId) return refuse("session mismatch");
|
|
53
53
|
|
|
54
|
-
const consumed = deps.registry.consume(connectionSessionId, msg.promptId, { path: msg.path, subject: msg.subject }, isSameSubject);
|
|
54
|
+
const consumed = deps.registry.consume(connectionSessionId, msg.promptId, { path: msg.path, subject: msg.subject }, isSameSubject, "confirm");
|
|
55
55
|
if (!consumed.ok) return refuse(consumed.error);
|
|
56
56
|
|
|
57
57
|
// Re-derive the subject from the confirmed PATH now, by the gate's rule (the path
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server handling of the agent path gate's YOLO frames (design D5):
|
|
3
|
+
* - `path_yolo_request` → `path_yolo_result` (session-bound; verdict from the
|
|
4
|
+
* YOLO controller, never from the body);
|
|
5
|
+
* - `path_gate_refusal` (fire-and-forget) → `recordRefusal("agent-path", subject)`,
|
|
6
|
+
* bound to a select prompt the server actually saw raised (registry `select`
|
|
7
|
+
* kind), with the subject re-derived from the path by the gate rule.
|
|
8
|
+
* See change: yolo-covers-agent-path-gate.
|
|
9
|
+
*/
|
|
10
|
+
import nodePath from "node:path";
|
|
11
|
+
import { isSameSubject } from "@blackbelt-technology/pi-dashboard-shared/canonical-subject.js";
|
|
12
|
+
import type {
|
|
13
|
+
PathGateRefusalMessage,
|
|
14
|
+
PathYoloRequestMessage,
|
|
15
|
+
PathYoloResultMessage,
|
|
16
|
+
} from "@blackbelt-technology/pi-dashboard-shared/protocol.js";
|
|
17
|
+
import type { AgentConfirmRegistry } from "./agent-confirm-registry.js";
|
|
18
|
+
|
|
19
|
+
export type YoloAgentVerdict = "auto-allow" | "refused-by-prior-refusal" | null;
|
|
20
|
+
|
|
21
|
+
export interface AgentYoloDeps {
|
|
22
|
+
/** Lazy: absent (YOLO not constructed yet) → every request declines. */
|
|
23
|
+
decideAgentPath?: (path: string) => YoloAgentVerdict;
|
|
24
|
+
registry: AgentConfirmRegistry;
|
|
25
|
+
recordRefusal: (plane: "agent-path", subject: string) => { ok: true } | { ok: false; error?: string };
|
|
26
|
+
log?: (line: string) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function makeLog(deps: AgentYoloDeps): (line: string) => void {
|
|
30
|
+
const sink = deps.log ?? ((l: string) => console.log(l));
|
|
31
|
+
// Paths / ids are attacker-influenced: strip control characters at the single emission point.
|
|
32
|
+
return (line) => sink(line.replace(/[\u0000-\u001f\u007f\u2028\u2029]/g, "?"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function handlePathYoloRequest(
|
|
36
|
+
/** The gateway's own socket key — never trusted from the body. */
|
|
37
|
+
connectionSessionId: string,
|
|
38
|
+
msg: PathYoloRequestMessage,
|
|
39
|
+
deps: AgentYoloDeps,
|
|
40
|
+
): PathYoloResultMessage {
|
|
41
|
+
const log = makeLog(deps);
|
|
42
|
+
const requestId = typeof msg?.requestId === "string" ? msg.requestId : "";
|
|
43
|
+
const decline = (cause: string): PathYoloResultMessage => {
|
|
44
|
+
log(`[path-gate] yolo declined session=${connectionSessionId} cause=${cause}`);
|
|
45
|
+
return { type: "path_yolo_result", requestId, verdict: "decline" };
|
|
46
|
+
};
|
|
47
|
+
if (typeof msg?.requestId !== "string" || msg.requestId === "" || typeof msg.path !== "string" || !nodePath.isAbsolute(msg.path)) {
|
|
48
|
+
return decline("malformed request");
|
|
49
|
+
}
|
|
50
|
+
if (msg.sessionId !== connectionSessionId) return decline("session mismatch");
|
|
51
|
+
if (!deps.decideAgentPath) return decline("yolo unavailable");
|
|
52
|
+
let verdict: YoloAgentVerdict;
|
|
53
|
+
try {
|
|
54
|
+
verdict = deps.decideAgentPath(msg.path);
|
|
55
|
+
} catch {
|
|
56
|
+
return decline("yolo error");
|
|
57
|
+
}
|
|
58
|
+
const mapped = verdict === "auto-allow" ? "auto-allow" : verdict === "refused-by-prior-refusal" ? "refused" : "decline";
|
|
59
|
+
return { type: "path_yolo_result", requestId: msg.requestId, verdict: mapped };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function handlePathGateRefusal(connectionSessionId: string, msg: PathGateRefusalMessage, deps: AgentYoloDeps): void {
|
|
63
|
+
const log = makeLog(deps);
|
|
64
|
+
const drop = (cause: string): void => log(`[path-gate] refusal not recorded session=${connectionSessionId} cause=${cause}`);
|
|
65
|
+
if (
|
|
66
|
+
typeof msg?.promptId !== "string" ||
|
|
67
|
+
typeof msg.path !== "string" ||
|
|
68
|
+
typeof msg.subject !== "string" ||
|
|
69
|
+
!nodePath.isAbsolute(msg.path)
|
|
70
|
+
) {
|
|
71
|
+
return drop("malformed request");
|
|
72
|
+
}
|
|
73
|
+
if (msg.sessionId !== connectionSessionId) return drop("session mismatch");
|
|
74
|
+
const consumed = deps.registry.consume(
|
|
75
|
+
connectionSessionId,
|
|
76
|
+
msg.promptId,
|
|
77
|
+
{ path: msg.path, subject: msg.subject },
|
|
78
|
+
isSameSubject,
|
|
79
|
+
"select",
|
|
80
|
+
);
|
|
81
|
+
if (!consumed.ok) return drop(consumed.error);
|
|
82
|
+
// The subject the server bound when it saw the prompt — NOT a fresh resolution of
|
|
83
|
+
// `msg.path`, whose symlinks may have moved while the prompt was open (a swap must
|
|
84
|
+
// not drop the refusal). The claimed subject was already validated inside consume.
|
|
85
|
+
const saved = deps.recordRefusal("agent-path", consumed.subject);
|
|
86
|
+
if (saved && saved.ok === false) {
|
|
87
|
+
log(`[path-gate] refusal NOT persisted session=${connectionSessionId} error=${saved.error ?? "unknown"}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
log(`[path-gate] refusal recorded session=${connectionSessionId} subject=${consumed.subject}`);
|
|
91
|
+
}
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { lstat } from "node:fs/promises";
|
|
26
|
+
import type { PathDecision } from "@blackbelt-technology/pi-dashboard-shared/containment-guard.js";
|
|
27
|
+
import { currentCallerUnproven, dashboardStateRefuses } from "../lib/dashboard-state-guard.js";
|
|
26
28
|
import { isAllowed, isGrantAdmitted } from "../lib/path-containment.js";
|
|
27
29
|
import { recordPathDenial } from "./access-denials.js";
|
|
28
30
|
import { grantedSubjects } from "./access-grants.js";
|
|
@@ -63,10 +65,18 @@ async function remedySubject(resolved: string, kind: SubjectKind): Promise<strin
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/**
|
|
69
|
+
* A containment verdict bound to the exact path it decided (`resolved`). Branded in
|
|
70
|
+
* `@blackbelt-technology/pi-dashboard-shared/containment-guard.js`; this module is the ONLY
|
|
71
|
+
* place that builds one (see `decision`), so `containmentAllows(decision, resolved)` can only
|
|
72
|
+
* be true for the path that was actually evaluated.
|
|
73
|
+
* See change: codeql-file-containment-barrier.
|
|
74
|
+
*/
|
|
75
|
+
export type ContainmentDecision = PathDecision;
|
|
76
|
+
|
|
77
|
+
/** The one constructor of a {@link ContainmentDecision}. */
|
|
78
|
+
function decision(resolved: string, allowed: boolean, viaGrant: boolean): ContainmentDecision {
|
|
79
|
+
return { allowed, viaGrant, resolved } as ContainmentDecision;
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
/** The additive remedy fields carried beside an unchanged `error` string. */
|
|
@@ -92,6 +102,12 @@ export interface DenialRemedy {
|
|
|
92
102
|
promptOutcome?: PromptOutcome;
|
|
93
103
|
}
|
|
94
104
|
|
|
105
|
+
/**
|
|
106
|
+
* What `evaluateContainment` returns on a miss. `denialId` is absent only for a
|
|
107
|
+
* `quiet` evaluation, which records nothing and so has nothing to bind a grant to.
|
|
108
|
+
*/
|
|
109
|
+
export type ContainmentRemedy = Omit<DenialRemedy, "denialId"> & Partial<Pick<DenialRemedy, "denialId">>;
|
|
110
|
+
|
|
95
111
|
/**
|
|
96
112
|
* The closed set a denial body names (see change: surface-denial-remedy-in-previews,
|
|
97
113
|
* design D5). The client mirrors it; `unavailable` is the catch-all.
|
|
@@ -214,19 +230,33 @@ export async function evaluateContainment(
|
|
|
214
230
|
* surface-denial-remedy-in-previews.
|
|
215
231
|
*/
|
|
216
232
|
disclosure?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Background / non-user-facing probe (the editor pane's digest). A miss
|
|
235
|
+
* names its remedy fields but records NO denial and never suspends: a
|
|
236
|
+
* background verification must not surface as a pending grant request or
|
|
237
|
+
* a denial-ledger row on the Access surface. The body carries no `denialId`
|
|
238
|
+
* and no `promptOutcome` (nothing was asked, so there is no posture to name).
|
|
239
|
+
* See change: gate-changed-on-disk-by-content (D4).
|
|
240
|
+
*/
|
|
241
|
+
quiet?: boolean;
|
|
217
242
|
},
|
|
218
|
-
): Promise<ContainmentDecision & { remedy?:
|
|
243
|
+
): Promise<ContainmentDecision & { remedy?: ContainmentRemedy }> {
|
|
244
|
+
// Dashboard secrets (token, identity key, config) are refused before anything else, with the
|
|
245
|
+
// plain refusal and NO remedy: nothing is recorded, so there is no `denialId` to turn into a
|
|
246
|
+
// grant, and no operator is asked. See change: close-container-loopback-impersonation (D8).
|
|
247
|
+
if (await dashboardStateRefuses(resolved)) return decision(resolved, false, false);
|
|
248
|
+
|
|
219
249
|
// Layers ①/② first — untouched and still authoritative (design D1) — then the
|
|
220
250
|
// grant layer, and only on a miss does the denial get recorded.
|
|
221
|
-
let
|
|
251
|
+
let verdict: ContainmentDecision;
|
|
222
252
|
if (await isAllowed(resolved, { anchors })) {
|
|
223
|
-
|
|
253
|
+
verdict = decision(resolved, true, false);
|
|
224
254
|
} else if ((opts.allowGrant ?? true) && (await isGrantAdmitted(resolved, grantedSubjects()))) {
|
|
225
|
-
|
|
255
|
+
verdict = decision(resolved, true, true);
|
|
226
256
|
} else {
|
|
227
|
-
|
|
257
|
+
verdict = decision(resolved, false, false);
|
|
228
258
|
}
|
|
229
|
-
if (
|
|
259
|
+
if (verdict.allowed) return verdict;
|
|
230
260
|
|
|
231
261
|
// A site that cannot be ADMITTED by a grant must not ORIGINATE one. Recording a
|
|
232
262
|
// denial here would return a `denialId` the operator could accept, minting a
|
|
@@ -238,7 +268,7 @@ export async function evaluateContainment(
|
|
|
238
268
|
// `denialBody` emits only the fields that are present. (Task 4.5, fresh cycle
|
|
239
269
|
// round 1: `allowGrant: false` previously blocked admission but still minted a
|
|
240
270
|
// remedy at `/api/open-in-system` and `/api/reveal-in-file-manager`.)
|
|
241
|
-
if (opts.allowGrant === false) return
|
|
271
|
+
if (opts.allowGrant === false) return verdict;
|
|
242
272
|
|
|
243
273
|
// `subjectKind` decides what the remedy names — see `remedySubject`. The
|
|
244
274
|
// default ("file") is right for the majority of sites (a refused file read);
|
|
@@ -258,6 +288,18 @@ export async function evaluateContainment(
|
|
|
258
288
|
ancestors = [];
|
|
259
289
|
}
|
|
260
290
|
|
|
291
|
+
if (opts.quiet) {
|
|
292
|
+
return {
|
|
293
|
+
...verdict,
|
|
294
|
+
remedy: {
|
|
295
|
+
reason: "Path is outside every containment anchor for this session.",
|
|
296
|
+
hint: "Grant access to this directory from the denial's remedy, or open the file from a session rooted in it.",
|
|
297
|
+
subject,
|
|
298
|
+
ancestors,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
261
303
|
const entry = recordPathDenial({
|
|
262
304
|
subject,
|
|
263
305
|
site: opts.site,
|
|
@@ -275,14 +317,37 @@ export async function evaluateContainment(
|
|
|
275
317
|
|
|
276
318
|
// Ask the operator, if this denial may be asked about (add-access-grant-dialog).
|
|
277
319
|
// Any outcome other than an allow verdict leaves the denial exactly as above.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
320
|
+
// A bare-loopback caller that only lacks proof is prompt-ineligible: refused at once, nothing
|
|
321
|
+
// queued, nobody asked (MODIFIED file-read-containment). See change: close-container-loopback-impersonation (D8).
|
|
322
|
+
const resolution: Resolution = currentCallerUnproven()
|
|
323
|
+
? { kind: "deny", reason: "ineligible" }
|
|
324
|
+
: await holdDenial(
|
|
325
|
+
{ plane: "filesystem", rawSubject: entry.subject, ancestors, origin: opts.session ?? "unknown" },
|
|
326
|
+
opts.hold,
|
|
327
|
+
);
|
|
282
328
|
const reEvaluated = resolution.kind === "allow" && (await reEvaluate(resolved, anchors, resolution));
|
|
283
|
-
if (reEvaluated) return
|
|
329
|
+
if (reEvaluated) return decision(resolved, true, true);
|
|
284
330
|
if (opts.disclosure) remedy.promptOutcome = outcomeFor(resolution, opts.hold !== undefined);
|
|
285
|
-
return { ...
|
|
331
|
+
return { ...verdict, remedy };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The decision of a PASSIVE site: one that filters or returns nothing instead of refusing with a
|
|
336
|
+
* body, and so never originates a denial (`grep-routes.ts` result filter, `resolve-file-mention.ts`,
|
|
337
|
+
* the raw-image pre-check in `file-routes.ts`). Layers ①/② first, then — only with `allowGrant` —
|
|
338
|
+
* the grant layer. No denial record, no hold, and no refusal of its own beyond what `isAllowed` / `isGrantAdmitted` already enforce (both refuse dashboard-state paths): exactly the
|
|
339
|
+
* `isAllowed` / `isGrantAdmitted` pair these sites called by hand before, now bound to the path.
|
|
340
|
+
* `grantSubjects` lets a loop hoist the store read (design D16: no N × store read per match).
|
|
341
|
+
* See change: codeql-file-containment-barrier.
|
|
342
|
+
*/
|
|
343
|
+
export async function decidePassive(
|
|
344
|
+
resolved: string,
|
|
345
|
+
anchors: string[],
|
|
346
|
+
opts: { allowGrant: boolean; grantSubjects?: string[] },
|
|
347
|
+
): Promise<ContainmentDecision> {
|
|
348
|
+
if (await isAllowed(resolved, { anchors })) return decision(resolved, true, false);
|
|
349
|
+
if (opts.allowGrant && (await isGrantAdmitted(resolved, opts.grantSubjects ?? grantedSubjects()))) return decision(resolved, true, true);
|
|
350
|
+
return decision(resolved, false, false);
|
|
286
351
|
}
|
|
287
352
|
|
|
288
353
|
/**
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate-limited sink for `indeterminate` plugin cwd admissions.
|
|
3
|
+
*
|
|
4
|
+
* Today a probe timeout is invisible (it surfaces as a bare 403). Each
|
|
5
|
+
* `indeterminate` decision is worth one warn line, but a burst of 25 sidebar
|
|
6
|
+
* pills would flood the log, so at most one line is emitted per canonical cwd
|
|
7
|
+
* per `CWD_ADMISSION_LOG_INTERVAL_MS`. The throttle map is LRU-bounded so a
|
|
8
|
+
* stream of distinct attacker-chosen cwds cannot grow it without limit.
|
|
9
|
+
*
|
|
10
|
+
* See change: harden-plugin-cwd-admission (D7).
|
|
11
|
+
*/
|
|
12
|
+
import type { IndeterminateInfo } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
13
|
+
|
|
14
|
+
export const CWD_ADMISSION_LOG_INTERVAL_MS = 60_000;
|
|
15
|
+
export const CWD_ADMISSION_LOG_MAX_ENTRIES = 512;
|
|
16
|
+
|
|
17
|
+
export interface IndeterminateLogger {
|
|
18
|
+
(info: IndeterminateInfo): void;
|
|
19
|
+
/** Current throttle-map size (tests). */
|
|
20
|
+
readonly size: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createIndeterminateLogger(
|
|
24
|
+
logger: { warn(message: string): void },
|
|
25
|
+
now: () => number = Date.now,
|
|
26
|
+
): IndeterminateLogger {
|
|
27
|
+
// Map iteration order = insertion order, so delete+set keeps it LRU.
|
|
28
|
+
const lastLogged = new Map<string, number>();
|
|
29
|
+
const log = (info: IndeterminateInfo): void => {
|
|
30
|
+
const t = now();
|
|
31
|
+
const prev = lastLogged.get(info.cwd);
|
|
32
|
+
if (prev !== undefined && t - prev < CWD_ADMISSION_LOG_INTERVAL_MS) return;
|
|
33
|
+
lastLogged.delete(info.cwd);
|
|
34
|
+
lastLogged.set(info.cwd, t);
|
|
35
|
+
while (lastLogged.size > CWD_ADMISSION_LOG_MAX_ENTRIES) {
|
|
36
|
+
const oldest = lastLogged.keys().next().value;
|
|
37
|
+
if (oldest === undefined) break;
|
|
38
|
+
lastLogged.delete(oldest);
|
|
39
|
+
}
|
|
40
|
+
logger.warn(
|
|
41
|
+
`[cwd-admission] indeterminate cwd=${JSON.stringify(info.cwd)} failedProbes=${JSON.stringify(info.failedProbes)} elapsedMs=${info.elapsedMs}`,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(log, "size", { get: () => lastLogged.size });
|
|
45
|
+
return log as IndeterminateLogger;
|
|
46
|
+
}
|