@blackbelt-technology/pi-agent-dashboard 0.9.0 → 0.10.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/README.md +38 -5
- package/docs/architecture.md +1673 -75
- package/package.json +23 -15
- package/packages/extension/package.json +8 -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 +450 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +220 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1030 -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.ts +480 -2510
- package/packages/extension/src/command-handler.ts +180 -11
- package/packages/extension/src/connection.ts +265 -18
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- 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/local-token-header.ts +161 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +19 -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/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust.ts +119 -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 +87 -20
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/server-auto-start.ts +12 -5
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +31 -38
- 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 +394 -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 +18 -0
- 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 +28 -1
- 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-mirror-service.ts +374 -0
- package/packages/server/src/access/planes.ts +10 -1
- package/packages/server/src/access/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +73 -12
- 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 +544 -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/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/auth-plugin.ts +292 -79
- package/packages/server/src/auth/auth.ts +78 -7
- package/packages/server/src/auth/bearer-auth.ts +23 -1
- package/packages/server/src/auth/cors-origin.ts +10 -0
- package/packages/server/src/auth/csp.ts +6 -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.ts +7 -4
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +251 -8
- 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-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +173 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +224 -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 +321 -0
- package/packages/server/src/auth/provider-auth-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +55 -8
- package/packages/server/src/auth/radius-override.ts +13 -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/serve-app-host.ts +97 -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/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 +128 -6
- package/packages/server/src/browser-handlers/session-action-handler.ts +129 -62
- 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/cli.ts +883 -97
- package/packages/server/src/config-api.ts +143 -1
- package/packages/server/src/config-snapshot.ts +5 -0
- package/packages/server/src/directory-service.ts +435 -32
- 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 +208 -35
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +16 -5
- package/packages/server/src/git-worktree/worktree-init-trust.ts +48 -5
- 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 +18 -0
- 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 +9 -0
- package/packages/server/src/identity/ws-road-classification.ts +9 -0
- package/packages/server/src/known-server-moves.ts +175 -0
- package/packages/server/src/lib/browse-roots.ts +36 -0
- package/packages/server/src/lib/digest-gate.ts +82 -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/purify.ts +13 -5
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +12 -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 +77 -1
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/live-capability.ts +254 -0
- package/packages/server/src/live-server/live-server-proxy.ts +173 -26
- 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/openspec-change-watcher.ts +109 -16
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +132 -0
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +90 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +200 -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.ts +1128 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- 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 +5 -3
- package/packages/server/src/pairing/browser-gateway.ts +108 -8
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/pairing.ts +154 -27
- 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 +116 -7
- package/packages/server/src/pi/bridge-upgrade-auth.ts +32 -21
- package/packages/server/src/pi/folder-commands.ts +141 -0
- 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 +158 -33
- package/packages/server/src/pi/pi-gateway.ts +93 -9
- 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/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 +123 -5
- 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/file-routes.ts +366 -75
- package/packages/server/src/routes/file-write-binary-routes.ts +473 -0
- package/packages/server/src/routes/folder-project-routes.ts +99 -0
- package/packages/server/src/routes/git-routes.ts +17 -2
- package/packages/server/src/routes/known-servers-routes.ts +333 -53
- package/packages/server/src/routes/live-server-routes.ts +72 -4
- package/packages/server/src/routes/local-proof-routes.ts +12 -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/openspec-routes.ts +270 -40
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +28 -1
- package/packages/server/src/routes/pairing-routes.ts +158 -24
- 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/plugin-activation-routes.ts +87 -27
- package/packages/server/src/routes/provider-auth-routes.ts +22 -5
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +16 -32
- package/packages/server/src/routes/session-routes.ts +49 -5
- package/packages/server/src/routes/system-routes.ts +207 -23
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- 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 +919 -139
- 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/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +53 -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/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-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/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 +67 -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-config-validation.ts +92 -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/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +294 -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/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 +385 -71
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +473 -26
- 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/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +71 -0
- package/packages/shared/src/dashboard-plugin/index.ts +7 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +106 -2
- 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 +95 -0
- package/packages/shared/src/dashboard-plugin/slot-types.ts +64 -4
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +22 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/doctor-core.ts +25 -107
- 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/local-credential-proof.ts +219 -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/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +392 -42
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +210 -9
- 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 +261 -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-mirror-snapshot.ts +200 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +57 -0
- package/packages/shared/src/pi-trust-mirror.ts +328 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- package/packages/shared/src/platform/git.ts +204 -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 +51 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- 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/project-name.ts +42 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +133 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +80 -23
- package/packages/shared/src/recovery-timing.ts +12 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/rest-api.ts +484 -1
- 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 +127 -0
- 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/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +12 -33
- package/packages/shared/src/server-pinning.ts +81 -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/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-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +26 -4
- 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/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +104 -9
- package/packages/shared/src/vault-delivery.ts +73 -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 +135 -0
- package/tsconfig.base.json +1 -0
|
@@ -30,6 +30,7 @@ import path from "node:path";
|
|
|
30
30
|
import { fileURLToPath } from "node:url";
|
|
31
31
|
import type { OAuthLoginFlow, OAuthRegistryEntry } from "./pi-oauth-types.js";
|
|
32
32
|
import { applyRadiusOverride, setAgentDirSource } from "./radius-override.js";
|
|
33
|
+
import type { RuntimeCatalogueSource } from "./runtime-provider-catalogue.js";
|
|
33
34
|
|
|
34
35
|
/** Package the runtime comes from (version diagnostics only). */
|
|
35
36
|
const PI_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
@@ -65,7 +66,7 @@ interface PiProviderLike {
|
|
|
65
66
|
*/
|
|
66
67
|
interface RuntimeHandleLike {
|
|
67
68
|
/** Provider shapes are checked at runtime by {@link mapProviders}'s filter. */
|
|
68
|
-
runtime: { getProviders(): readonly unknown[] }
|
|
69
|
+
runtime: { getProviders(): readonly unknown[] } & Partial<Pick<RuntimeCatalogueSource, "checkAuth">>;
|
|
69
70
|
version?: string;
|
|
70
71
|
/** pi's `getAgentDir` (honours `PI_CODING_AGENT_DIR`); locates `models.json`. */
|
|
71
72
|
getAgentDir?: () => string;
|
|
@@ -82,6 +83,28 @@ let runtimeSource: RuntimeSource | undefined;
|
|
|
82
83
|
export function setOAuthRegistryRuntimeSource(source: RuntimeSource | undefined): void {
|
|
83
84
|
runtimeSource = source;
|
|
84
85
|
readyPromise = undefined;
|
|
86
|
+
// A stale in-flight init must not write after a reset; the retained runtime
|
|
87
|
+
// belongs to the old source. See change: fix-provider-catalogue-first-run (D3).
|
|
88
|
+
initGeneration += 1;
|
|
89
|
+
registryRuntime = undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let initGeneration = 0;
|
|
93
|
+
/** The runtime the registry resolved, retained even when its OAuth list is empty. */
|
|
94
|
+
let registryRuntime: RuntimeCatalogueSource | undefined;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The runtime the registry resolved, for the api-key fallback catalogue.
|
|
98
|
+
* `undefined` until a handle resolved, or after the source rejected / lacked
|
|
99
|
+
* `getProviders`. See change: fix-provider-catalogue-first-run (D3).
|
|
100
|
+
*/
|
|
101
|
+
export function getRegistryRuntime(): RuntimeCatalogueSource | undefined {
|
|
102
|
+
return registryRuntime;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Test seam: set (or clear with `null`) the retained runtime. */
|
|
106
|
+
export function _setRegistryRuntimeForTests(rt: RuntimeCatalogueSource | null): void {
|
|
107
|
+
registryRuntime = rt ?? undefined;
|
|
85
108
|
}
|
|
86
109
|
|
|
87
110
|
type OAuthProvider = PiProviderLike & { auth: { oauth: OAuthLoginFlow } };
|
|
@@ -187,6 +210,8 @@ export async function initOAuthRegistry(deps: OAuthRegistryInitDeps = {}): Promi
|
|
|
187
210
|
const log = deps.log ?? ((message: string) => console.error(message));
|
|
188
211
|
|
|
189
212
|
let version = readVersion();
|
|
213
|
+
const generation = initGeneration;
|
|
214
|
+
let retained = false;
|
|
190
215
|
try {
|
|
191
216
|
if (!getRuntime) throw new Error("the server model runtime is not wired (setOAuthRegistryRuntimeSource)");
|
|
192
217
|
let handle: RuntimeHandleLike;
|
|
@@ -198,21 +223,30 @@ export async function initOAuthRegistry(deps: OAuthRegistryInitDeps = {}): Promi
|
|
|
198
223
|
throw err;
|
|
199
224
|
}
|
|
200
225
|
if (typeof handle?.version === "string" && handle.version) version = handle.version;
|
|
226
|
+
if (generation !== initGeneration) return;
|
|
201
227
|
setAgentDirSource(typeof handle?.getAgentDir === "function" ? handle.getAgentDir : undefined);
|
|
202
228
|
const runtime = handle?.runtime;
|
|
203
229
|
if (typeof runtime?.getProviders !== "function") {
|
|
204
230
|
throw new Error("ModelRuntime.getProviders is not a function");
|
|
205
231
|
}
|
|
232
|
+
// Retain BEFORE the OAuth check: a runtime with no OAuth provider still
|
|
233
|
+
// serves the api-key fallback. See change: fix-provider-catalogue-first-run (D3).
|
|
234
|
+
registryRuntime = runtime as RuntimeCatalogueSource;
|
|
235
|
+
retained = true;
|
|
206
236
|
const entries = mapProviders(runtime.getProviders() as readonly PiProviderLike[]);
|
|
207
237
|
if (entries.length === 0) {
|
|
208
238
|
throw new Error("the runtime exposes no provider with an OAuth login");
|
|
209
239
|
}
|
|
210
240
|
setRegistry(entries, null);
|
|
211
241
|
} catch (err) {
|
|
242
|
+
if (generation !== initGeneration) return;
|
|
212
243
|
const message = err instanceof Error ? err.message : String(err);
|
|
213
244
|
const detail = `${message} (pi-coding-agent ${version})`;
|
|
214
245
|
setAgentDirSource(undefined);
|
|
215
246
|
setRegistry([], detail);
|
|
247
|
+
// Only a runtime that never resolved loses the fallback; an empty OAuth
|
|
248
|
+
// list keeps it.
|
|
249
|
+
if (!retained) registryRuntime = undefined;
|
|
216
250
|
log(`[provider-auth] OAuth registry unavailable: ${detail}`);
|
|
217
251
|
}
|
|
218
252
|
}
|
|
@@ -16,22 +16,25 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
16
16
|
|
|
17
17
|
import type { ProviderAuthStatus } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
18
18
|
import type { ProviderInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
19
|
-
import { getLatestCatalogue } from "../package/provider-catalogue-cache.js";
|
|
20
|
-
import {
|
|
21
|
-
getOAuthRegistry,
|
|
22
|
-
type OAuthRegistryEntry,
|
|
23
|
-
} from "./provider-auth-handlers.js";
|
|
19
|
+
import { getLatestCatalogue, isCatalogueReady } from "../package/provider-catalogue-cache.js";
|
|
20
|
+
import { readProvidersFromDisk } from "../package/provider-probe.js";
|
|
24
21
|
import {
|
|
22
|
+
_resetQuarantineDedupForTests as _resetLockedJsonQuarantineDedup,
|
|
25
23
|
type CheckedJsonRead,
|
|
26
24
|
corruptUnbackedRefusal as corruptUnbackedRefusal_,
|
|
27
25
|
LOCK_OPTIONS,
|
|
28
26
|
type NotPromise,
|
|
29
|
-
_resetQuarantineDedupForTests as _resetLockedJsonQuarantineDedup,
|
|
30
27
|
readJsonChecked,
|
|
31
28
|
tryReadJson,
|
|
32
29
|
withLockedJsonFile,
|
|
33
30
|
writeJsonAtomic,
|
|
34
31
|
} from "./locked-json-file.js";
|
|
32
|
+
import {
|
|
33
|
+
getOAuthRegistry,
|
|
34
|
+
type OAuthRegistryEntry,
|
|
35
|
+
} from "./provider-auth-handlers.js";
|
|
36
|
+
import { getRegistryRuntime } from "./provider-auth-registry.js";
|
|
37
|
+
import { buildRuntimeCatalogue } from "./runtime-provider-catalogue.js";
|
|
35
38
|
|
|
36
39
|
// ── Constants ────────────────────────────────────────────────────────────────
|
|
37
40
|
|
|
@@ -290,6 +293,36 @@ export async function writeCredential(provider: string, credential: AuthCredenti
|
|
|
290
293
|
});
|
|
291
294
|
}
|
|
292
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Persist an API-key credential only when the provider holds NO credential. The
|
|
298
|
+
* absence check and the write share one lock acquisition, so a credential saved
|
|
299
|
+
* concurrently through Settings → Providers is never overwritten. Used by the
|
|
300
|
+
* legacy settings.json key move. See change: pi-settings-full-coverage (D4).
|
|
301
|
+
*/
|
|
302
|
+
export async function writeCredentialIfAbsent(provider: string, credential: ApiKeyCredential): Promise<"written" | "exists"> {
|
|
303
|
+
return withLock(() => {
|
|
304
|
+
const checked = readAuthJsonChecked();
|
|
305
|
+
if (checked.corrupt && !checked.quarantined) throw corruptUnbackedRefusal();
|
|
306
|
+
const data = checked.data;
|
|
307
|
+
if (Object.hasOwn(data, provider)) return "exists" as const;
|
|
308
|
+
data[provider] = credential;
|
|
309
|
+
writeAuthJson(data, checked.corrupt ? 0o600 : undefined);
|
|
310
|
+
return "written" as const;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Snapshot of auth.json under the bounded lock (never creates it), reporting
|
|
316
|
+
* `corrupt` instead of hiding it — the legacy-credential plan treats a corrupt
|
|
317
|
+
* file as "cannot be relied on". See change: pi-settings-full-coverage (D4).
|
|
318
|
+
*/
|
|
319
|
+
export async function readAuthSnapshotLocked(signal?: AbortSignal): Promise<{ data: AuthData; corrupt: boolean }> {
|
|
320
|
+
return withLock(() => {
|
|
321
|
+
const checked = readAuthJsonChecked();
|
|
322
|
+
return { data: checked.data, corrupt: checked.corrupt };
|
|
323
|
+
}, refreshLockOptions(signal));
|
|
324
|
+
}
|
|
325
|
+
|
|
293
326
|
/** Remove one provider credential. Async — see `writeCredential`.
|
|
294
327
|
*
|
|
295
328
|
* `expectedKind` carries the kind of the UI row the removal was addressed to
|
|
@@ -500,8 +533,22 @@ export function _buildAuthStatus(
|
|
|
500
533
|
|
|
501
534
|
// ── Public API: status / OAuth meta / id resolution ─────────────────────────
|
|
502
535
|
|
|
503
|
-
|
|
504
|
-
|
|
536
|
+
/**
|
|
537
|
+
* The catalogue the api-key rows derive from: the bridge's push when held,
|
|
538
|
+
* else a fallback built from the server's own runtime (never stored), else
|
|
539
|
+
* `[]`. See change: fix-provider-catalogue-first-run (D2).
|
|
540
|
+
*/
|
|
541
|
+
export async function resolveCatalogue(): Promise<ProviderInfo[]> {
|
|
542
|
+
if (isCatalogueReady()) return getLatestCatalogue();
|
|
543
|
+
return buildRuntimeCatalogue(getRegistryRuntime(), {
|
|
544
|
+
customIds: Object.keys(readProvidersFromDisk()),
|
|
545
|
+
authData: tryReadAuthJson(),
|
|
546
|
+
env: process.env,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export async function getAuthStatus(): Promise<ProviderAuthStatus[]> {
|
|
551
|
+
return _buildAuthStatus(await resolveCatalogue(), readAuthJson(), getOAuthRegistry());
|
|
505
552
|
}
|
|
506
553
|
|
|
507
554
|
export function getOAuthProvidersMeta(
|
|
@@ -58,6 +58,19 @@ export function setAgentDirSource(source: (() => string) | undefined): void {
|
|
|
58
58
|
cached = undefined;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* pi's agent dir from the wired runtime `getAgentDir` (honours
|
|
63
|
+
* `PI_CODING_AGENT_DIR`), or `undefined` when the runtime is unavailable or
|
|
64
|
+
* throws. See change: update-pi-core-1-1-adopt-apis.
|
|
65
|
+
*/
|
|
66
|
+
export function getRuntimeAgentDir(): string | undefined {
|
|
67
|
+
try {
|
|
68
|
+
return agentDirSource?.() || undefined;
|
|
69
|
+
} catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
61
74
|
/** False when the pi runtime did not load (callers must not assume "no override"). */
|
|
62
75
|
export function isRadiusRuntimeAvailable(): boolean {
|
|
63
76
|
return agentDirSource !== undefined;
|
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
*
|
|
9
9
|
* The gate's scope is deliberately narrow, and each exclusion is a decision:
|
|
10
10
|
*
|
|
11
|
-
* - It applies
|
|
12
|
-
* (`request.authVia === "device"`)
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* - It applies when admission rested on the device bearer
|
|
12
|
+
* (`request.authVia === "device"`) or on a login session
|
|
13
|
+
* (`authVia === "session"`, tier from the JWT `tier` claim; a claim-less
|
|
14
|
+
* legacy JWT is `operate`, so it is never refused — add-passkey-user-auth
|
|
15
|
+
* D4). A local-token caller or an undecorated request is left to the
|
|
16
|
+
* existing rules.
|
|
16
17
|
* - A genuinely-local caller (loopback, no forwarding headers) or a
|
|
17
18
|
* trusted-network caller is exempt, exactly as `networkGuard` treats it:
|
|
18
19
|
* same-machine processes are trusted via `~/.pi` and the local token
|
|
19
20
|
* regardless, so there is nothing to narrow.
|
|
20
|
-
* - `/api/*`
|
|
21
|
-
*
|
|
21
|
+
* - `/api/*` (via the route→tier map) and `/live/*` (live-preview proxy,
|
|
22
|
+
* `LIVE_PREVIEW_TIER`). `/mcp`, `/auth/*` and `/v1/*` have their own
|
|
23
|
+
* admission and sit outside the map.
|
|
22
24
|
*
|
|
23
25
|
* The gate only ever REFUSES. A request with no resolvable principal is left
|
|
24
26
|
* untouched, so the pre-change 401/403 path is unchanged (E24).
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
*/
|
|
28
30
|
import { rank, type Tier } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
|
|
29
31
|
import { routeTier } from "@blackbelt-technology/pi-dashboard-shared/route-tiers.js";
|
|
32
|
+
import { LIVE_PREVIEW_TIER } from "@blackbelt-technology/pi-dashboard-shared/ws-message-tiers.js";
|
|
30
33
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
31
34
|
import type { LocalTrustContext } from "./local-proof.js";
|
|
32
35
|
import { isLocallyTrusted, isTrustedSource } from "./localhost-guard.js";
|
|
@@ -61,13 +64,22 @@ function scopeChallenge(scope: Tier): string {
|
|
|
61
64
|
* (`POST /api/session/:id/lifecycle` for `force_kill`/`kill_process`), because
|
|
62
65
|
* the network exemptions must apply identically in both places.
|
|
63
66
|
*/
|
|
67
|
+
/**
|
|
68
|
+
* Credentials the tier applies to: a paired-device bearer and (since
|
|
69
|
+
* add-passkey-user-auth, D4) a login session carrying a `tier` claim.
|
|
70
|
+
*/
|
|
71
|
+
function isTieredCredential(request: FastifyRequest): boolean {
|
|
72
|
+
const via = (request as any).authVia;
|
|
73
|
+
return via === "device" || via === "session";
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
export function tierRefusalFor(
|
|
65
77
|
request: FastifyRequest,
|
|
66
78
|
requiredTier: Tier,
|
|
67
79
|
getTrustedNetworks: () => string[],
|
|
68
80
|
localTrust?: LocalTrustContext,
|
|
69
81
|
): { scope: Tier; deviceId?: string } | null {
|
|
70
|
-
if ((request
|
|
82
|
+
if (!isTieredCredential(request)) return null;
|
|
71
83
|
const headers = request.headers as Record<string, unknown>;
|
|
72
84
|
if (isLocallyTrusted({ ip: request.ip, headers }, localTrust)) return null;
|
|
73
85
|
if (isTrustedSource(request.ip, headers, getTrustedNetworks(), localTrust)) return null;
|
|
@@ -102,14 +114,18 @@ export function createRouteTierGate(deps: RouteTierGateDeps) {
|
|
|
102
114
|
request: FastifyRequest,
|
|
103
115
|
reply: FastifyReply,
|
|
104
116
|
): Promise<void> {
|
|
105
|
-
if ((request
|
|
117
|
+
if (!isTieredCredential(request)) return;
|
|
106
118
|
|
|
107
119
|
// `onRequest` runs AFTER routing, so this is the normalized route PATTERN
|
|
108
120
|
// (never the raw URL — path tricks either 404 or resolve to the pattern).
|
|
109
121
|
const route = request.routeOptions?.url ?? "";
|
|
110
|
-
|
|
122
|
+
// `/api/*` → ROUTE_TIERS; `/live/*` (live-preview HTTP proxy) → the same
|
|
123
|
+
// tier its WS upgrade needs. See change: add-passkey-user-auth.
|
|
124
|
+
let requiredTier: Tier;
|
|
125
|
+
if (route.startsWith("/api/")) requiredTier = routeTier(request.method, route);
|
|
126
|
+
else if (route.startsWith("/live/")) requiredTier = LIVE_PREVIEW_TIER;
|
|
127
|
+
else return;
|
|
111
128
|
|
|
112
|
-
const requiredTier = routeTier(request.method, route);
|
|
113
129
|
const refusal = tierRefusalFor(request, requiredTier, deps.getTrustedNetworks, deps.localTrust);
|
|
114
130
|
if (!refusal) return;
|
|
115
131
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback provider catalogue derived from the server's OWN pi `ModelRuntime`.
|
|
3
|
+
*
|
|
4
|
+
* The api-key rows of `GET /api/provider-auth/status` normally come from the
|
|
5
|
+
* catalogue a pi session's bridge pushes. On a fresh install no session exists
|
|
6
|
+
* yet, so there is no catalogue and no api-key row — and onboarding cannot
|
|
7
|
+
* create a session without a provider (a deadlock). This module projects the
|
|
8
|
+
* runtime's provider list onto `ProviderInfo[]` so the pure `_buildAuthStatus`
|
|
9
|
+
* keeps ONE implementation of the row rules.
|
|
10
|
+
*
|
|
11
|
+
* Structural types only: `auth/` must not import `model-proxy/`, and the server
|
|
12
|
+
* never imports pi-ai. `checkAuth` is public, async, refreshes no OAuth token
|
|
13
|
+
* and writes nothing (design D1).
|
|
14
|
+
*
|
|
15
|
+
* Never throws: any failure degrades to `[]` (the OAuth rows keep serving).
|
|
16
|
+
*
|
|
17
|
+
* See change: fix-provider-catalogue-first-run (D1).
|
|
18
|
+
*/
|
|
19
|
+
import type { ProviderInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
20
|
+
import type { AuthData } from "./provider-auth-storage.js";
|
|
21
|
+
|
|
22
|
+
/** pi-ai `AuthCheck` slice. */
|
|
23
|
+
export interface AuthCheckLike {
|
|
24
|
+
source?: string;
|
|
25
|
+
type: "api_key" | "oauth";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The slice of pi's `ModelRuntime` the fallback reads. `checkAuth` is REQUIRED. */
|
|
29
|
+
export interface RuntimeCatalogueSource {
|
|
30
|
+
getProviders(): readonly { id: string; name?: string; auth?: { oauth?: unknown } }[];
|
|
31
|
+
checkAuth(providerId: string): Promise<AuthCheckLike | undefined>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RuntimeCatalogueOptions {
|
|
35
|
+
/** Ids registered from `providers.json`; their rows are the LLM Providers section's. */
|
|
36
|
+
customIds: ReadonlySet<string> | readonly string[];
|
|
37
|
+
/** The caller's single auth.json read. `null` = unparseable → resolve `[]`. */
|
|
38
|
+
authData: AuthData | null;
|
|
39
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ENV_NAME = /^[A-Z][A-Z0-9_]*$/;
|
|
43
|
+
|
|
44
|
+
/** First env-var-shaped name in a pi auth label (`"A_KEY, B_KEY"`) that is actually set. */
|
|
45
|
+
function deriveEnvVar(
|
|
46
|
+
label: string | undefined,
|
|
47
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
48
|
+
): string | undefined {
|
|
49
|
+
if (!label) return undefined;
|
|
50
|
+
return label
|
|
51
|
+
.split(",")
|
|
52
|
+
.map((n) => n.trim())
|
|
53
|
+
.find((n) => ENV_NAME.test(n) && !!env[n]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True when the runtime offers the surface the fallback needs. */
|
|
57
|
+
export function isRuntimeCatalogueSource(rt: unknown): rt is RuntimeCatalogueSource {
|
|
58
|
+
const r = rt as Partial<RuntimeCatalogueSource> | null | undefined;
|
|
59
|
+
return typeof r?.getProviders === "function" && typeof r?.checkAuth === "function";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function buildRuntimeCatalogue(
|
|
63
|
+
source: RuntimeCatalogueSource | undefined,
|
|
64
|
+
opts: RuntimeCatalogueOptions,
|
|
65
|
+
): Promise<ProviderInfo[]> {
|
|
66
|
+
try {
|
|
67
|
+
if (!isRuntimeCatalogueSource(source)) return [];
|
|
68
|
+
// Unparseable auth.json: every credential-store read would fall to the
|
|
69
|
+
// locked path (~40 lock acquisitions + quarantine attempts). Skip the
|
|
70
|
+
// checks; the OAuth rows still render.
|
|
71
|
+
if (opts.authData === null) return [];
|
|
72
|
+
const authData = opts.authData;
|
|
73
|
+
const customIds = new Set(opts.customIds);
|
|
74
|
+
const providers = source.getProviders();
|
|
75
|
+
return await Promise.all(
|
|
76
|
+
providers.map(async (p): Promise<ProviderInfo> => {
|
|
77
|
+
const info: ProviderInfo = {
|
|
78
|
+
id: p.id,
|
|
79
|
+
displayName: p.name || p.id,
|
|
80
|
+
hasOAuth: !!p.auth?.oauth,
|
|
81
|
+
configured: false,
|
|
82
|
+
};
|
|
83
|
+
if (customIds.has(p.id)) info.custom = true;
|
|
84
|
+
let check: AuthCheckLike | undefined;
|
|
85
|
+
try {
|
|
86
|
+
check = await source.checkAuth(p.id);
|
|
87
|
+
} catch {
|
|
88
|
+
check = undefined;
|
|
89
|
+
}
|
|
90
|
+
// A stored OAuth credential is not api-key evidence.
|
|
91
|
+
if (!check || check.type === "oauth") return info;
|
|
92
|
+
info.configured = true;
|
|
93
|
+
if (authData[p.id]) {
|
|
94
|
+
info.source = "stored";
|
|
95
|
+
return info;
|
|
96
|
+
}
|
|
97
|
+
info.source = "environment";
|
|
98
|
+
if (check.source) info.authLabel = check.source;
|
|
99
|
+
const envVar = deriveEnvVar(check.source, opts.env);
|
|
100
|
+
if (envVar) info.envVar = envVar;
|
|
101
|
+
return info;
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
} catch {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only scan of pi's agent dir for the provider id pi 1.0.3 renamed
|
|
3
|
+
* (`azure-openai-responses` → `azure`). Sessions still using the old id fall
|
|
4
|
+
* back to another model and lose their prompt cache, so the dashboard names
|
|
5
|
+
* where it was found.
|
|
6
|
+
*
|
|
7
|
+
* Side-effect free: `tryReadJson` takes no lock, writes nothing and never
|
|
8
|
+
* quarantines. Each file is read in its own try/catch, so a missing,
|
|
9
|
+
* unreadable, torn or wrong-shaped file contributes nothing and cannot affect
|
|
10
|
+
* the others. The result carries ids and location tokens only — never a value.
|
|
11
|
+
*
|
|
12
|
+
* Glob/fuzzy `enabledModels` patterns are not interpreted (documented gap).
|
|
13
|
+
* `providers.json` is excluded: it only holds dashboard-created custom
|
|
14
|
+
* providers, which never used the built-in id.
|
|
15
|
+
*
|
|
16
|
+
* See change: update-pi-core-1-1-adopt-apis (design D4).
|
|
17
|
+
*/
|
|
18
|
+
import os from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import type { LegacyProviderIdEntry } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
21
|
+
import { tryReadJson } from "./locked-json-file.js";
|
|
22
|
+
import { getRuntimeAgentDir } from "./radius-override.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* pi's provider id renames (`old → current`). The single source: the settings
|
|
26
|
+
* legacy-credential detector normalises provider ids through it too.
|
|
27
|
+
* See change: pi-settings-full-coverage (design D5a).
|
|
28
|
+
*/
|
|
29
|
+
export const PI_RENAMED_PROVIDER_IDS: Readonly<Record<string, string>> = Object.freeze({
|
|
30
|
+
"azure-openai-responses": "azure",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const [[LEGACY_ID, NEW_ID]] = Object.entries(PI_RENAMED_PROVIDER_IDS) as [[string, string]];
|
|
34
|
+
|
|
35
|
+
/** `id` itself, or `id/<model>` — the `/` boundary rejects `azure-openai-responses2`. */
|
|
36
|
+
const isLegacy = (value: unknown): boolean =>
|
|
37
|
+
typeof value === "string" && (value === LEGACY_ID || value.startsWith(`${LEGACY_ID}/`));
|
|
38
|
+
|
|
39
|
+
function readObject(file: string): Record<string, unknown> | undefined {
|
|
40
|
+
try {
|
|
41
|
+
const read = tryReadJson(file);
|
|
42
|
+
return read.ok ? read.data : undefined;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined; // unreadable (EACCES, EISDIR, …): skip until the next poll
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const asObject = (v: unknown): Record<string, unknown> | undefined =>
|
|
49
|
+
v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : undefined;
|
|
50
|
+
|
|
51
|
+
function resolveAgentDir(): string {
|
|
52
|
+
return (
|
|
53
|
+
getRuntimeAgentDir() ??
|
|
54
|
+
process.env.PI_CODING_AGENT_DIR ??
|
|
55
|
+
path.join(os.homedir(), ".pi", "agent")
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function scanLegacyProviderIds(opts: { agentDir?: string } = {}): LegacyProviderIdEntry[] {
|
|
60
|
+
const dir = opts.agentDir ?? resolveAgentDir();
|
|
61
|
+
const locations: string[] = [];
|
|
62
|
+
|
|
63
|
+
const auth = readObject(path.join(dir, "auth.json"));
|
|
64
|
+
if (auth && Object.hasOwn(auth, LEGACY_ID)) locations.push("auth.json");
|
|
65
|
+
|
|
66
|
+
const settings = readObject(path.join(dir, "settings.json"));
|
|
67
|
+
if (settings) {
|
|
68
|
+
if (isLegacy(settings.defaultProvider)) locations.push("settings.json:defaultProvider");
|
|
69
|
+
if (Array.isArray(settings.enabledModels) && settings.enabledModels.some(isLegacy)) {
|
|
70
|
+
locations.push("settings.json:enabledModels");
|
|
71
|
+
}
|
|
72
|
+
const levels = asObject(settings.modelThinkingLevels);
|
|
73
|
+
if (levels && Object.keys(levels).some(isLegacy)) locations.push("settings.json:modelThinkingLevels");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const providers = asObject(readObject(path.join(dir, "models.json"))?.providers);
|
|
77
|
+
if (providers && Object.hasOwn(providers, LEGACY_ID)) locations.push("models.json:providers");
|
|
78
|
+
|
|
79
|
+
return locations.length > 0 ? [{ legacyId: LEGACY_ID, newId: NEW_ID, locations }] : [];
|
|
80
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host side of `ctx.serveApp`: the trust gate (design D2) and the per-plugin
|
|
3
|
+
* binding handed to `createServerPluginContext`. The mount itself (validation,
|
|
4
|
+
* registry, request handling) lives in the runtime package (`mountApp`).
|
|
5
|
+
*
|
|
6
|
+
* A plugin is TRUSTED when its package DIRECTORY name is in
|
|
7
|
+
* `packages/server/package.json#piDashboard.bundledPlugins`, or its manifest id is
|
|
8
|
+
* in config `auth.capabilityRoutePlugins`. `manifest.priority` is a render-order
|
|
9
|
+
* knob and never trust. An untrusted call mounts nothing and warns once, so an
|
|
10
|
+
* untrusted plugin cannot squat a trusted app's id.
|
|
11
|
+
*
|
|
12
|
+
* API guardrail against accidents, not a boundary against a malicious in-process plugin.
|
|
13
|
+
*
|
|
14
|
+
* See change: add-plugin-capability-routes (D2, D5).
|
|
15
|
+
*/
|
|
16
|
+
import { createRequire } from "node:module";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { mountApp, type ServeAppOptions } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
19
|
+
import type { FastifyInstance } from "fastify";
|
|
20
|
+
|
|
21
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
let bundledDirsCache: ReadonlySet<string> | undefined;
|
|
24
|
+
|
|
25
|
+
/** `piDashboard.bundledPlugins` of the server package (package DIRECTORY names, e.g. `goal-plugin`). Cached. */
|
|
26
|
+
export function readBundledPluginDirs(): ReadonlySet<string> {
|
|
27
|
+
if (!bundledDirsCache) {
|
|
28
|
+
let dirs: string[] = [];
|
|
29
|
+
try {
|
|
30
|
+
const list = (nodeRequire("../../package.json") as { piDashboard?: { bundledPlugins?: unknown } }).piDashboard?.bundledPlugins;
|
|
31
|
+
if (Array.isArray(list)) dirs = list.filter((d): d is string => typeof d === "string");
|
|
32
|
+
} catch {
|
|
33
|
+
/* unreadable → no bundled trust (fail closed) */
|
|
34
|
+
}
|
|
35
|
+
bundledDirsCache = new Set(dirs);
|
|
36
|
+
}
|
|
37
|
+
return bundledDirsCache;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ServeAppTrustInput {
|
|
41
|
+
/** Absolute path of the plugin package directory (its basename is the bundled-list key). */
|
|
42
|
+
packageDir: string;
|
|
43
|
+
/** Manifest id (the `auth.capabilityRoutePlugins` key). */
|
|
44
|
+
manifestId: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Pure trust decision: bundled by directory name, OR named in `auth.capabilityRoutePlugins`. */
|
|
48
|
+
export function isServeAppTrusted(
|
|
49
|
+
plugin: ServeAppTrustInput,
|
|
50
|
+
lists: { bundledDirs: ReadonlySet<string>; configuredIds: readonly string[] },
|
|
51
|
+
): boolean {
|
|
52
|
+
return lists.bundledDirs.has(path.basename(plugin.packageDir)) || lists.configuredIds.includes(plugin.manifestId);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface HostServeAppDeps {
|
|
56
|
+
fastify: FastifyInstance;
|
|
57
|
+
plugin: ServeAppTrustInput;
|
|
58
|
+
/** Live read of `auth.capabilityRoutePlugins` (read when the plugin activates). */
|
|
59
|
+
readConfiguredIds: () => readonly string[];
|
|
60
|
+
/** Overridable for tests; defaults to the server package's bundled list. */
|
|
61
|
+
bundledDirs?: ReadonlySet<string>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The `deps.serveApp` binding for one plugin: trust-gate, then mount. */
|
|
65
|
+
export function createHostServeApp(deps: HostServeAppDeps): (opts: ServeAppOptions, env: { dataDir: string }) => void {
|
|
66
|
+
const { plugin } = deps;
|
|
67
|
+
let warned = false;
|
|
68
|
+
return (opts, env) => {
|
|
69
|
+
const trusted = isServeAppTrusted(plugin, {
|
|
70
|
+
bundledDirs: deps.bundledDirs ?? readBundledPluginDirs(),
|
|
71
|
+
configuredIds: deps.readConfiguredIds(),
|
|
72
|
+
});
|
|
73
|
+
if (!trusted) {
|
|
74
|
+
if (!warned) {
|
|
75
|
+
warned = true;
|
|
76
|
+
console.warn(
|
|
77
|
+
`[serveApp] plugin '${plugin.manifestId}' is not trusted to mount an app (bundled plugin or auth.capabilityRoutePlugins); ignoring`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
mountApp(
|
|
83
|
+
{
|
|
84
|
+
fastify: deps.fastify,
|
|
85
|
+
pluginId: plugin.manifestId,
|
|
86
|
+
packageRoot: plugin.packageDir,
|
|
87
|
+
dataDir: env.dataDir,
|
|
88
|
+
logger: {
|
|
89
|
+
info: (msg, ...args) => console.info(`[plugin:${plugin.manifestId}]`, msg, ...args),
|
|
90
|
+
warn: (msg, ...args) => console.warn(`[plugin:${plugin.manifestId}]`, msg, ...args),
|
|
91
|
+
error: (msg, ...args) => console.error(`[plugin:${plugin.manifestId}]`, msg, ...args),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
opts,
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one-time boot trust-mode decision (see `trust-mode.ts`). Separate module:
|
|
3
|
+
* it writes config, so it imports the config writer, which the read-only
|
|
4
|
+
* admission path must not drag in.
|
|
5
|
+
*
|
|
6
|
+
* See change: retire-trusted-networks-bypass (design D2).
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { isLoopbackOnlyEntry } from "@blackbelt-technology/pi-dashboard-shared/bind-reachability.js";
|
|
12
|
+
import {
|
|
13
|
+
type DashboardConfig,
|
|
14
|
+
loadConfig,
|
|
15
|
+
resolveTrustMode,
|
|
16
|
+
type TrustMode,
|
|
17
|
+
} from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
18
|
+
import { writeConfigPartial as defaultWriteConfigPartial } from "../config-api.js";
|
|
19
|
+
import { setBootTrustFallback } from "./trust-mode.js";
|
|
20
|
+
|
|
21
|
+
function configFile(): string {
|
|
22
|
+
return path.join(os.homedir(), ".pi", "dashboard", "config.json");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** True when `config.json` exists, is non-empty, and is not a JSON object. */
|
|
26
|
+
function configFileUnparseable(): boolean {
|
|
27
|
+
let raw: string;
|
|
28
|
+
try {
|
|
29
|
+
raw = fs.readFileSync(configFile(), "utf-8");
|
|
30
|
+
} catch {
|
|
31
|
+
return false; // absent → a fresh install, decide below
|
|
32
|
+
}
|
|
33
|
+
if (raw.trim() === "") return false;
|
|
34
|
+
try {
|
|
35
|
+
const parsed: unknown = JSON.parse(raw);
|
|
36
|
+
return typeof parsed !== "object" || parsed === null || Array.isArray(parsed);
|
|
37
|
+
} catch {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BootTrustDecision {
|
|
43
|
+
/** What was decided (or the fallback used); `null` when a recognised/unrecognised value was already stored. */
|
|
44
|
+
mode: TrustMode | null;
|
|
45
|
+
/** True when the decision was persisted. */
|
|
46
|
+
persisted: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The one-time boot decision. Call before the server listens (so no operator
|
|
51
|
+
* write can race it). Never re-derives a stored mode; never writes over a
|
|
52
|
+
* `config.json` it cannot parse (a rewrite from `{}` would drop its secrets).
|
|
53
|
+
*/
|
|
54
|
+
export function decideBootTrustMode(
|
|
55
|
+
deps: {
|
|
56
|
+
write?: (partial: Record<string, unknown>, opts: { trustModeOrigin: "upgrade" }) => { success: boolean; error?: string };
|
|
57
|
+
load?: () => DashboardConfig;
|
|
58
|
+
} = {},
|
|
59
|
+
): BootTrustDecision {
|
|
60
|
+
const write = deps.write ?? defaultWriteConfigPartial;
|
|
61
|
+
const load = deps.load ?? loadConfig;
|
|
62
|
+
|
|
63
|
+
// A present-but-unparseable file is never decided or written.
|
|
64
|
+
if (configFileUnparseable()) {
|
|
65
|
+
setBootTrustFallback("legacy");
|
|
66
|
+
console.error(
|
|
67
|
+
'[trusted-networks] config.json is unparseable — not deciding a trust mode; using "legacy" for this process',
|
|
68
|
+
);
|
|
69
|
+
return { mode: "legacy", persisted: false };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const config = load();
|
|
73
|
+
if (resolveTrustMode(config).mode !== null) return { mode: null, persisted: false };
|
|
74
|
+
|
|
75
|
+
const list = config.resolvedTrustedNetworks ?? [];
|
|
76
|
+
const decided: TrustMode = list.every(isLoopbackOnlyEntry) ? "pair" : "legacy";
|
|
77
|
+
let failure: string | null = null;
|
|
78
|
+
try {
|
|
79
|
+
const result = write({ network: { trustMode: decided } }, { trustModeOrigin: "upgrade" });
|
|
80
|
+
if (!result.success) failure = result.error ?? "write failed";
|
|
81
|
+
} catch (err) {
|
|
82
|
+
failure = err instanceof Error ? err.message : String(err);
|
|
83
|
+
}
|
|
84
|
+
if (failure !== null) {
|
|
85
|
+
setBootTrustFallback(decided);
|
|
86
|
+
console.error(
|
|
87
|
+
`[trusted-networks] could not persist network.trustMode "${decided}" (${failure}) — using it for this process; will decide again on the next boot`,
|
|
88
|
+
);
|
|
89
|
+
return { mode: decided, persisted: false };
|
|
90
|
+
}
|
|
91
|
+
console.log(`[trusted-networks] decided network.trustMode "${decided}" (origin: upgrade)`);
|
|
92
|
+
return { mode: decided, persisted: true };
|
|
93
|
+
}
|