@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
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST routes for pi's global `settings.json` editor (pi-agent-settings-editor).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/pi-settings → { settings, raw, etag, parseError? }
|
|
5
|
+
* PUT /api/pi-settings → typed leaf patch (merge-preserving)
|
|
6
|
+
* PUT /api/pi-settings/raw → whole-file raw write (256 KiB cap)
|
|
7
|
+
* POST /api/pi-settings/sync-defaults → mirror the dashboard default
|
|
8
|
+
* model/thinking level into pi (drift repair)
|
|
9
|
+
* POST /api/pi-settings/legacy-credentials → move/remove plain-text API keys
|
|
10
|
+
* (settings.json → auth.json); key paths in,
|
|
11
|
+
* masked list out — never a value
|
|
12
|
+
*
|
|
13
|
+
* Status map: 200 ok · 400 invalid/unparseable · 409 stale token (body carries
|
|
14
|
+
* the current state) · 413 body too large · 503 lock busy. Typed/raw writes
|
|
15
|
+
* reload every connected session on success only; sync-defaults never does
|
|
16
|
+
* (defaults are read only at session construction). The parsed `settings` field of
|
|
17
|
+
* every response omits legacy API-key values (the masked `legacyCredentials` list
|
|
18
|
+
* and the stored `raw` text are the only carriers). All routes sit behind the
|
|
19
|
+
* shared network guard, like `/api/config` and `/api/pi-retry`. Logs carry the
|
|
20
|
+
* outcome and reload count only — never settings values.
|
|
21
|
+
*
|
|
22
|
+
* See change: edit-pi-agent-settings (design D1–D7).
|
|
23
|
+
*/
|
|
24
|
+
import { resolvePiAgentDir } from "@blackbelt-technology/pi-dashboard-shared/dashboard-paths.js";
|
|
25
|
+
import type {
|
|
26
|
+
PiLegacyCredentialsRequest,
|
|
27
|
+
PiLegacyCredentialsResponse,
|
|
28
|
+
PiSettingsConflict,
|
|
29
|
+
PiSettingsReadResponse,
|
|
30
|
+
PiSettingsSyncResponse,
|
|
31
|
+
PiSettingsWriteResponse,
|
|
32
|
+
PutPiSettingsRawRequest,
|
|
33
|
+
PutPiSettingsRequest,
|
|
34
|
+
} from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
35
|
+
import type { FastifyInstance, FastifyReply } from "fastify";
|
|
36
|
+
import {
|
|
37
|
+
applyLegacyCredentialActions,
|
|
38
|
+
detectLegacyCredentials,
|
|
39
|
+
type LegacyAction,
|
|
40
|
+
readAuthSnapshotUnlocked,
|
|
41
|
+
withoutLegacyValues,
|
|
42
|
+
} from "../auth/pi-legacy-credentials.js";
|
|
43
|
+
import { scanPiResources } from "../pi/pi-resource-scanner.js";
|
|
44
|
+
import {
|
|
45
|
+
applyPiSettingsPatch,
|
|
46
|
+
type DashboardDefaults,
|
|
47
|
+
type FsDeps,
|
|
48
|
+
mirrorDefaultsToPi,
|
|
49
|
+
type PiSettingsWriteResult,
|
|
50
|
+
readPiSettings,
|
|
51
|
+
writePiSettingsRaw,
|
|
52
|
+
} from "../pi-agent-settings.js";
|
|
53
|
+
import { createThemeLister, type ScanThemes } from "../pi-settings-themes.js";
|
|
54
|
+
import type { NetworkGuard } from "./route-deps.js";
|
|
55
|
+
|
|
56
|
+
/** Request-body cap for the raw editor (design D6). */
|
|
57
|
+
export const PI_SETTINGS_RAW_BODY_LIMIT = 256 * 1024;
|
|
58
|
+
|
|
59
|
+
const ERROR_STATUS = { invalid: 400, parse: 400, stale: 409, busy: 503, io: 500 } as const;
|
|
60
|
+
|
|
61
|
+
type LegacyFailure = Exclude<Awaited<ReturnType<typeof applyLegacyCredentialActions>>, { ok: true }>;
|
|
62
|
+
|
|
63
|
+
/** HTTP status + body of a failed legacy-credentials request. No value ever appears in either. */
|
|
64
|
+
function legacyFailure(r: LegacyFailure): { status: number; body: Record<string, unknown> } {
|
|
65
|
+
switch (r.error) {
|
|
66
|
+
case "stale":
|
|
67
|
+
return {
|
|
68
|
+
status: 409,
|
|
69
|
+
body: {
|
|
70
|
+
success: false,
|
|
71
|
+
error: "stale",
|
|
72
|
+
etag: r.state.etag,
|
|
73
|
+
settings: withoutLegacyValues(r.state.settings),
|
|
74
|
+
raw: r.state.raw,
|
|
75
|
+
legacyCredentials: r.legacy,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
case "invalid":
|
|
79
|
+
return { status: 400, body: { success: false, error: r.message, legacyCredentials: r.legacy } };
|
|
80
|
+
case "conflict":
|
|
81
|
+
return { status: 409, body: { success: false, error: r.message, legacyCredentials: r.legacy } };
|
|
82
|
+
case "parse":
|
|
83
|
+
return { status: 400, body: { success: false, error: r.parseError, parseError: r.parseError } };
|
|
84
|
+
case "busy":
|
|
85
|
+
return { status: 503, body: { success: false, error: "busy" } };
|
|
86
|
+
case "io":
|
|
87
|
+
return { status: 500, body: { success: false, error: r.message, ...(r.legacy ? { legacyCredentials: r.legacy } : {}) } };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const isLegacyAction = (a: unknown): boolean =>
|
|
92
|
+
typeof a === "object" &&
|
|
93
|
+
a !== null &&
|
|
94
|
+
typeof (a as LegacyAction).key === "string" &&
|
|
95
|
+
((a as LegacyAction).action === "move" || (a as LegacyAction).action === "remove");
|
|
96
|
+
|
|
97
|
+
export function registerPiSettingsRoutes(
|
|
98
|
+
fastify: FastifyInstance,
|
|
99
|
+
deps: {
|
|
100
|
+
networkGuard: NetworkGuard;
|
|
101
|
+
/** Reload every connected session; returns how many were signalled. */
|
|
102
|
+
reloadConnectedSessions: () => number;
|
|
103
|
+
/** Persisted dashboard defaults (read inside the lock by the mirror). */
|
|
104
|
+
readDashboardConfig: () => DashboardDefaults;
|
|
105
|
+
/** Test seam: agent dir / fs overrides. */
|
|
106
|
+
fsDeps?: FsDeps;
|
|
107
|
+
/** Test seam: theme resource scanner (default: pi's resolver, global + package themes). */
|
|
108
|
+
scanThemes?: ScanThemes;
|
|
109
|
+
},
|
|
110
|
+
) {
|
|
111
|
+
const { networkGuard, reloadConnectedSessions, readDashboardConfig, fsDeps } = deps;
|
|
112
|
+
const scanThemes: ScanThemes =
|
|
113
|
+
deps.scanThemes ??
|
|
114
|
+
(() => {
|
|
115
|
+
// GLOBAL file only: the agent dir is BOTH the scan root (no project `.pi/settings.json`
|
|
116
|
+
// to pull local packages in) and `globalDir` (else the scanner defaults to `~/.pi/agent`
|
|
117
|
+
// and ignores `PI_CODING_AGENT_DIR`).
|
|
118
|
+
const globalDir = resolvePiAgentDir({ homedir: fsDeps?.home, agentDirEnv: fsDeps?.agentDirEnv });
|
|
119
|
+
return scanPiResources(globalDir, { globalDir });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const themeLister = createThemeLister(scanThemes);
|
|
123
|
+
|
|
124
|
+
const logWrite = (route: string, outcome: string, reloaded?: number) => {
|
|
125
|
+
console.log(`[pi-settings] ${route} ${outcome}${reloaded !== undefined ? ` reloaded=${reloaded}` : ""}`);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Map a non-ok write result to its HTTP reply. */
|
|
129
|
+
const reject = (route: string, reply: FastifyReply, r: Exclude<PiSettingsWriteResult, { ok: true }>) => {
|
|
130
|
+
logWrite(route, r.error === "invalid" ? "invalid" : r.error);
|
|
131
|
+
reply.code(ERROR_STATUS[r.error]);
|
|
132
|
+
if (r.error === "stale") {
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
error: "stale",
|
|
136
|
+
etag: r.state.etag,
|
|
137
|
+
settings: withoutLegacyValues(r.state.settings),
|
|
138
|
+
raw: r.state.raw,
|
|
139
|
+
} satisfies PiSettingsConflict;
|
|
140
|
+
}
|
|
141
|
+
if (r.error === "invalid") {
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
error: r.errors.map((e) => e.message).join("; "),
|
|
145
|
+
errors: r.errors,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (r.error === "parse") return { success: false, error: r.parseError, parseError: r.parseError };
|
|
149
|
+
if (r.error === "busy") return { success: false, error: "busy" };
|
|
150
|
+
return { success: false, error: r.message };
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const ok = (route: string, r: Extract<PiSettingsWriteResult, { ok: true }>): PiSettingsWriteResponse => {
|
|
154
|
+
// Apply to running sessions only after a successful write.
|
|
155
|
+
themeLister.invalidate();
|
|
156
|
+
const reloadedSessions = reloadConnectedSessions();
|
|
157
|
+
logWrite(route, "ok", reloadedSessions);
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
settings: withoutLegacyValues(r.state.settings),
|
|
161
|
+
raw: r.state.raw,
|
|
162
|
+
etag: r.state.etag,
|
|
163
|
+
reloadedSessions,
|
|
164
|
+
legacyCredentials: detectLegacyCredentials(r.state.settings, readAuthSnapshotUnlocked()),
|
|
165
|
+
...(r.restoredKeys ? { restoredKeys: r.restoredKeys } : {}),
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
fastify.get("/api/pi-settings", { preHandler: networkGuard }, async (): Promise<PiSettingsReadResponse> => {
|
|
170
|
+
const s = readPiSettings(fsDeps);
|
|
171
|
+
return {
|
|
172
|
+
success: true,
|
|
173
|
+
settings: withoutLegacyValues(s.settings),
|
|
174
|
+
raw: s.raw,
|
|
175
|
+
etag: s.etag,
|
|
176
|
+
...(s.parseError ? { parseError: s.parseError } : {}),
|
|
177
|
+
themes: await themeLister.list(),
|
|
178
|
+
legacyCredentials: detectLegacyCredentials(s.settings, readAuthSnapshotUnlocked()),
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
fastify.put<{ Body: PutPiSettingsRequest }>(
|
|
183
|
+
"/api/pi-settings",
|
|
184
|
+
{ preHandler: networkGuard },
|
|
185
|
+
async (request, reply) => {
|
|
186
|
+
const { patch, baseEtag } = request.body ?? ({} as Partial<PutPiSettingsRequest>);
|
|
187
|
+
if (typeof baseEtag !== "string") {
|
|
188
|
+
return reply.code(400).send({ success: false, error: "baseEtag is required" });
|
|
189
|
+
}
|
|
190
|
+
const r = await applyPiSettingsPatch(patch, baseEtag, fsDeps);
|
|
191
|
+
return r.ok ? ok("typed", r) : reject("typed", reply, r);
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
fastify.put<{ Body: PutPiSettingsRawRequest }>(
|
|
196
|
+
"/api/pi-settings/raw",
|
|
197
|
+
{
|
|
198
|
+
preHandler: networkGuard,
|
|
199
|
+
bodyLimit: PI_SETTINGS_RAW_BODY_LIMIT,
|
|
200
|
+
// A body over the cap arrives as a framework error; answer in the
|
|
201
|
+
// standard `{ success:false, error }` envelope.
|
|
202
|
+
errorHandler: (err, _request, reply) => {
|
|
203
|
+
const status = (err as { statusCode?: number }).statusCode ?? 500;
|
|
204
|
+
if (status === 413) logWrite("raw", "too-large");
|
|
205
|
+
return reply.code(status).send({ success: false, error: status === 413 ? "Request body too large" : err.message });
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
async (request, reply) => {
|
|
209
|
+
const { raw, baseEtag } = request.body ?? ({} as Partial<PutPiSettingsRawRequest>);
|
|
210
|
+
if (typeof baseEtag !== "string") {
|
|
211
|
+
return reply.code(400).send({ success: false, error: "baseEtag is required" });
|
|
212
|
+
}
|
|
213
|
+
const r = await writePiSettingsRaw(raw, baseEtag, fsDeps);
|
|
214
|
+
return r.ok ? ok("raw", r) : reject("raw", reply, r);
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
fastify.post("/api/pi-settings/sync-defaults", { preHandler: networkGuard }, async (_request, reply) => {
|
|
219
|
+
const mirror = await mirrorDefaultsToPi(readDashboardConfig, ["defaultModel", "defaultThinkingLevel"], fsDeps);
|
|
220
|
+
if (!mirror.ok) {
|
|
221
|
+
logWrite("sync-defaults", mirror.error ?? "io");
|
|
222
|
+
reply.code(ERROR_STATUS[mirror.error ?? "io"]);
|
|
223
|
+
return { success: false, error: mirror.error ?? "io" };
|
|
224
|
+
}
|
|
225
|
+
logWrite("sync-defaults", "ok");
|
|
226
|
+
const s = readPiSettings(fsDeps);
|
|
227
|
+
return {
|
|
228
|
+
success: true,
|
|
229
|
+
piMirror: mirror,
|
|
230
|
+
settings: withoutLegacyValues(s.settings),
|
|
231
|
+
raw: s.raw,
|
|
232
|
+
etag: s.etag,
|
|
233
|
+
} satisfies PiSettingsSyncResponse;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
fastify.post<{ Body: PiLegacyCredentialsRequest }>(
|
|
237
|
+
"/api/pi-settings/legacy-credentials",
|
|
238
|
+
{ preHandler: networkGuard },
|
|
239
|
+
async (request, reply) => {
|
|
240
|
+
const { baseEtag, actions } = request.body ?? ({} as Partial<PiLegacyCredentialsRequest>);
|
|
241
|
+
if (typeof baseEtag !== "string") return reply.code(400).send({ success: false, error: "baseEtag is required" });
|
|
242
|
+
if (!Array.isArray(actions) || actions.length === 0 || !actions.every(isLegacyAction)) {
|
|
243
|
+
return reply.code(400).send({ success: false, error: "actions must be a non-empty list of { key, action: move|remove }" });
|
|
244
|
+
}
|
|
245
|
+
const r = await applyLegacyCredentialActions(actions as LegacyAction[], baseEtag, fsDeps);
|
|
246
|
+
if (r.ok) {
|
|
247
|
+
themeLister.invalidate();
|
|
248
|
+
const reloadedSessions = reloadConnectedSessions();
|
|
249
|
+
logWrite("legacy-credentials", "ok", reloadedSessions);
|
|
250
|
+
return {
|
|
251
|
+
success: true,
|
|
252
|
+
settings: withoutLegacyValues(r.state.settings),
|
|
253
|
+
raw: r.state.raw,
|
|
254
|
+
etag: r.state.etag,
|
|
255
|
+
reloadedSessions,
|
|
256
|
+
legacyCredentials: r.legacy,
|
|
257
|
+
} satisfies PiLegacyCredentialsResponse;
|
|
258
|
+
}
|
|
259
|
+
logWrite("legacy-credentials", r.error);
|
|
260
|
+
const failure = legacyFailure(r);
|
|
261
|
+
return reply.code(failure.status).send(failure.body);
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import path from "node:path";
|
|
16
|
-
import { writeConfigFileSecure } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
17
16
|
import {
|
|
18
17
|
buildGraph,
|
|
19
18
|
computeToggleImpact,
|
|
@@ -26,7 +25,9 @@ import {
|
|
|
26
25
|
transitiveDependents,
|
|
27
26
|
} from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
28
27
|
import type { ServerToBrowserMessage } from "@blackbelt-technology/pi-dashboard-shared/browser-protocol.js";
|
|
28
|
+
import { writeConfigFileSecure } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
29
29
|
import type { FastifyInstance } from "fastify";
|
|
30
|
+
import { PLUGIN_CONFIG_LOCK_KEY, withSettingsWriteLock } from "../pi/settings-write-lock.js";
|
|
30
31
|
import type { NetworkGuard } from "./route-deps.js";
|
|
31
32
|
|
|
32
33
|
// Resolved lazily so tests that override $HOME after import still work.
|
|
@@ -35,7 +36,7 @@ function configPaths() {
|
|
|
35
36
|
return { dir, file: path.join(dir, "config.json") };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
function readRawConfig(): Record<string, unknown> {
|
|
39
|
+
export function readRawConfig(): Record<string, unknown> {
|
|
39
40
|
try {
|
|
40
41
|
return JSON.parse(fs.readFileSync(configPaths().file, "utf-8"));
|
|
41
42
|
} catch {
|
|
@@ -148,6 +149,81 @@ function teardownDisabledWsRoutes(
|
|
|
148
149
|
for (const flip of flips) registry.teardownPlugin(flip.id);
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
export interface SetPluginsEnabledDeps {
|
|
153
|
+
broadcast: (msg: ServerToBrowserMessage) => void;
|
|
154
|
+
repoRoot?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type SetPluginsEnabledResult =
|
|
158
|
+
| { ok: false; status: 404; error: string }
|
|
159
|
+
| { ok: false; status: 409; blockers: string[] }
|
|
160
|
+
| {
|
|
161
|
+
ok: true;
|
|
162
|
+
/** Every plugin id whose `enabled` flips, the toggled one first. */
|
|
163
|
+
flips: Array<{ id: string; enabled: boolean }>;
|
|
164
|
+
impact: { cascadeEnable: string[]; cascadeDisable: string[]; blockers: string[] };
|
|
165
|
+
/** Put the plugin config back as it was before this call (and re-broadcast). */
|
|
166
|
+
rollback: () => void;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Enable/disable plugin `id` with its dependency cascade in ONE config write,
|
|
171
|
+
* broadcast one `plugin_config_update` per flipped id and tear down WS routes of
|
|
172
|
+
* disabled plugins. Shared by `POST /api/plugins/:id/toggle` and the Add-ons hub
|
|
173
|
+
* toggle (`POST /api/addons/:featureId/toggle`). `dryRun` computes the cascade
|
|
174
|
+
* only. NOT locked: callers wrap it in `withSettingsWriteLock(PLUGIN_CONFIG_LOCK_KEY)`.
|
|
175
|
+
*
|
|
176
|
+
* See change: addons-hub-feature-catalog (design D5).
|
|
177
|
+
*/
|
|
178
|
+
export function setPluginsEnabled(
|
|
179
|
+
id: string,
|
|
180
|
+
enabled: boolean,
|
|
181
|
+
deps: SetPluginsEnabledDeps,
|
|
182
|
+
opts: { dryRun?: boolean } = {},
|
|
183
|
+
): SetPluginsEnabledResult {
|
|
184
|
+
const { broadcast, repoRoot } = deps;
|
|
185
|
+
const plugins = discoverPlugins(repoRoot);
|
|
186
|
+
if (!plugins.some((p) => p.manifest.id === id)) {
|
|
187
|
+
return { ok: false, status: 404, error: `Plugin "${id}" not found` };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const existing = readRawConfig();
|
|
191
|
+
const existingPlugins = (existing.plugins as Record<string, unknown> | undefined) ?? {};
|
|
192
|
+
const impact = toggleImpactFor(plugins, existingPlugins, id, enabled);
|
|
193
|
+
if (enabled && impact.blockers.length > 0) {
|
|
194
|
+
return { ok: false, status: 409, blockers: impact.blockers };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Atomic cascade write: collect every id whose `enabled` flips, write them all
|
|
198
|
+
// in a single config write, then emit one plugin_config_update per affected id.
|
|
199
|
+
const flips = toggleFlips(id, enabled, impact);
|
|
200
|
+
const noop = () => {};
|
|
201
|
+
if (opts.dryRun) return { ok: true, flips, impact, rollback: noop };
|
|
202
|
+
|
|
203
|
+
const { nextPlugins, mergedPerId } = applyToggleFlips(existingPlugins, flips);
|
|
204
|
+
writeRawConfig({ ...existing, plugins: nextPlugins });
|
|
205
|
+
broadcastToggleUpdates(broadcast, mergedPerId, repoRoot);
|
|
206
|
+
teardownDisabledWsRoutes(enabled, flips);
|
|
207
|
+
|
|
208
|
+
const rollback = () => {
|
|
209
|
+
const current = readRawConfig();
|
|
210
|
+
const restored: Record<string, unknown> = { ...((current.plugins as Record<string, unknown> | undefined) ?? {}) };
|
|
211
|
+
const restoredBlocks = new Map<string, Record<string, unknown>>();
|
|
212
|
+
for (const flip of flips) {
|
|
213
|
+
if (flip.id in existingPlugins) {
|
|
214
|
+
restored[flip.id] = existingPlugins[flip.id];
|
|
215
|
+
restoredBlocks.set(flip.id, (existingPlugins[flip.id] as Record<string, unknown>) ?? {});
|
|
216
|
+
} else {
|
|
217
|
+
delete restored[flip.id];
|
|
218
|
+
restoredBlocks.set(flip.id, {});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
writeRawConfig({ ...current, plugins: restored });
|
|
222
|
+
broadcastToggleUpdates(broadcast, restoredBlocks, repoRoot);
|
|
223
|
+
};
|
|
224
|
+
return { ok: true, flips, impact, rollback };
|
|
225
|
+
}
|
|
226
|
+
|
|
151
227
|
export function registerPluginActivationRoutes(
|
|
152
228
|
fastify: FastifyInstance,
|
|
153
229
|
deps: {
|
|
@@ -238,34 +314,18 @@ export function registerPluginActivationRoutes(
|
|
|
238
314
|
.send({ success: false, error: "body.enabled must be boolean" });
|
|
239
315
|
}
|
|
240
316
|
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
.send({ success: false, error:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const existing = readRawConfig();
|
|
250
|
-
const existingPlugins =
|
|
251
|
-
(existing.plugins as Record<string, unknown> | undefined) ?? {};
|
|
252
|
-
|
|
253
|
-
const impact = toggleImpactFor(plugins, existingPlugins, id, body.enabled);
|
|
254
|
-
|
|
255
|
-
if (body.enabled && impact.blockers.length > 0) {
|
|
317
|
+
const result = await withSettingsWriteLock(PLUGIN_CONFIG_LOCK_KEY, async () =>
|
|
318
|
+
setPluginsEnabled(id, body.enabled as boolean, { broadcast, repoRoot }),
|
|
319
|
+
);
|
|
320
|
+
if (!result.ok) {
|
|
321
|
+
if (result.status === 404) {
|
|
322
|
+
return reply.status(404).send({ success: false, error: result.error });
|
|
323
|
+
}
|
|
256
324
|
return reply
|
|
257
325
|
.status(409)
|
|
258
|
-
.send({ success: false, reason: "blockers", blockers:
|
|
326
|
+
.send({ success: false, reason: "blockers", blockers: result.blockers });
|
|
259
327
|
}
|
|
260
|
-
|
|
261
|
-
// Atomic cascade write: collect every id whose `enabled` flips, write
|
|
262
|
-
// them all in a single config write, then emit one plugin_config_update
|
|
263
|
-
// per affected id.
|
|
264
|
-
const flips = toggleFlips(id, body.enabled, impact);
|
|
265
|
-
const { nextPlugins, mergedPerId } = applyToggleFlips(existingPlugins, flips);
|
|
266
|
-
writeRawConfig({ ...existing, plugins: nextPlugins });
|
|
267
|
-
broadcastToggleUpdates(broadcast, mergedPerId, repoRoot);
|
|
268
|
-
teardownDisabledWsRoutes(body.enabled, flips);
|
|
328
|
+
const { impact } = result;
|
|
269
329
|
|
|
270
330
|
return reply.status(200).send({
|
|
271
331
|
success: true,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
import type { CatalogueReadyResponse, LegacyProviderIdsResponse } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
14
15
|
import type { FastifyInstance } from "fastify";
|
|
15
16
|
import { beginFlow, isPluginFlow } from "../auth/begin-flow.js";
|
|
16
17
|
import {
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
readAuthJson,
|
|
37
38
|
removeCredential,
|
|
38
39
|
resolveAuthJsonKey,
|
|
40
|
+
resolveCatalogue,
|
|
39
41
|
writeCredential,
|
|
40
42
|
} from "../auth/provider-auth-storage.js";
|
|
41
43
|
import {
|
|
@@ -48,8 +50,9 @@ import {
|
|
|
48
50
|
isRadiusOverridden,
|
|
49
51
|
isRadiusRuntimeAvailable,
|
|
50
52
|
} from "../auth/radius-override.js";
|
|
53
|
+
import { scanLegacyProviderIds } from "../auth/scan-legacy-provider-ids.js";
|
|
51
54
|
import { refreshModelRegistry } from "../model-proxy/registry-singleton.js";
|
|
52
|
-
import {
|
|
55
|
+
import { isCatalogueReady } from "../package/provider-catalogue-cache.js";
|
|
53
56
|
import type { BrowserGateway } from "../pairing/browser-gateway.js";
|
|
54
57
|
import type { PiGateway } from "../pi/pi-gateway.js";
|
|
55
58
|
|
|
@@ -166,12 +169,12 @@ export function registerProviderAuthRoutes(
|
|
|
166
169
|
// Cold-cache nudge: if no bridge has pushed a catalogue yet, ask
|
|
167
170
|
// every connected pi to send one. Best-effort, doesn't block this
|
|
168
171
|
// response. See change: replace-hardcoded-provider-lists.
|
|
169
|
-
if (
|
|
172
|
+
if (!isCatalogueReady()) {
|
|
170
173
|
for (const sid of piGateway.getConnectedSessionIds()) {
|
|
171
174
|
piGateway.sendToSession(sid, { type: "request_providers", sessionId: sid });
|
|
172
175
|
}
|
|
173
176
|
}
|
|
174
|
-
return getAuthStatus();
|
|
177
|
+
return await getAuthStatus();
|
|
175
178
|
});
|
|
176
179
|
|
|
177
180
|
// Catalogue availability (D5): lets the client distinguish "no api-key
|
|
@@ -179,8 +182,22 @@ export function registerProviderAuthRoutes(
|
|
|
179
182
|
// route on purpose — the /status body is a bare array clients pin, and a
|
|
180
183
|
// header is invisible to non-browser consumers. See change:
|
|
181
184
|
// redesign-providers-settings-page.
|
|
182
|
-
fastify.get("/api/provider-auth/catalogue-ready", async () => {
|
|
183
|
-
|
|
185
|
+
fastify.get("/api/provider-auth/catalogue-ready", async (): Promise<CatalogueReadyResponse> => {
|
|
186
|
+
await registryReady;
|
|
187
|
+
const ready = isCatalogueReady();
|
|
188
|
+
if (ready) return { ready, fallback: false };
|
|
189
|
+
// `fallback`: an api-key row can actually be shown (computed after the
|
|
190
|
+
// custom filter). See change: fix-provider-catalogue-first-run (D4).
|
|
191
|
+
const fallbackRows = await resolveCatalogue();
|
|
192
|
+
return { ready, fallback: fallbackRows.some((e) => !e.custom) };
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Provider ids pi renamed that still appear in pi's agent-dir files. A
|
|
196
|
+
// separate route (the /status body is a bare array clients pin). Read-only,
|
|
197
|
+
// lock-free scan; ids + location tokens only. See change:
|
|
198
|
+
// update-pi-core-1-1-adopt-apis (D4).
|
|
199
|
+
fastify.get("/api/provider-auth/legacy-provider-ids", async (): Promise<LegacyProviderIdsResponse> => {
|
|
200
|
+
return { legacyProviderIds: scanLegacyProviderIds() };
|
|
184
201
|
});
|
|
185
202
|
|
|
186
203
|
// Start a sign-in flow of any shape. Answers once the flow produced its
|
|
@@ -51,6 +51,9 @@ async function probeAndCacheProvider(name: string, entry: ProviderEntry): Promis
|
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
const result = await probeProvider({ baseUrl: entry.baseUrl, apiKey: resolved.key, api: entry.api as ProbeApi });
|
|
54
|
+
// An upstream error body can echo the credential; health is served to the
|
|
55
|
+
// browser, so scrub it. See change: add-provider-models-refresh (D8).
|
|
56
|
+
if (!result.ok && resolved.key) result.error = result.error.split(resolved.key).join(REDACTED);
|
|
54
57
|
setProviderHealth(name, toHealth(result));
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -539,6 +542,32 @@ export function registerProviderRoutes(fastify: FastifyInstance, deps: { network
|
|
|
539
542
|
},
|
|
540
543
|
);
|
|
541
544
|
|
|
545
|
+
// Explicit models refresh for one saved provider: no file write. Sessions
|
|
546
|
+
// force-re-register it (re-fetch /models); the server catalogue re-discovers
|
|
547
|
+
// (detached); the probe is AWAITED so the caller gets the fresh model count.
|
|
548
|
+
// See change: add-provider-models-refresh (D1, D3, D4, D7).
|
|
549
|
+
fastify.post<{ Params: { name: string } }>(
|
|
550
|
+
"/api/providers/:name/refresh",
|
|
551
|
+
{ preHandler: networkGuard },
|
|
552
|
+
async (request, reply) => {
|
|
553
|
+
const name = request.params.name;
|
|
554
|
+
const read = readProvidersFileDataChecked();
|
|
555
|
+
if (read.corrupt) {
|
|
556
|
+
return reply.code(409).send(corruptProvidersRefusal(read.quarantined));
|
|
557
|
+
}
|
|
558
|
+
const providers: Record<string, ProviderEntry> = read.fileData.providers ?? {};
|
|
559
|
+
if (typeof name !== "string" || !Object.hasOwn(providers, name)) {
|
|
560
|
+
return reply.code(404).send({ success: false, error: `Provider "${name}" not found` });
|
|
561
|
+
}
|
|
562
|
+
if (piGateway) {
|
|
563
|
+
piGateway.broadcast({ type: "credentials_updated", refreshProviders: [name] });
|
|
564
|
+
}
|
|
565
|
+
refreshModelRegistry().catch(() => {});
|
|
566
|
+
await probeAndCacheProvider(name, providers[name]).catch(() => {});
|
|
567
|
+
return { success: true, health: getAllProviderHealth()[name] ?? null };
|
|
568
|
+
},
|
|
569
|
+
);
|
|
570
|
+
|
|
542
571
|
// Test a provider configuration without saving it. Accepts literal api keys,
|
|
543
572
|
// $ENV_VAR references, or the REDACTED sentinel (***) for already-saved entries.
|
|
544
573
|
fastify.post(
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
* (mirrors file-routes.ts). See change: folder-resource-activation-toggle.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
import * as path from "node:path";
|
|
30
29
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
31
30
|
import type { FastifyInstance } from "fastify";
|
|
32
31
|
import type { PiGateway } from "../pi/pi-gateway.js";
|
|
@@ -38,36 +37,19 @@ import {
|
|
|
38
37
|
type ToggleType,
|
|
39
38
|
} from "../pi/resource-activation-toggle.js";
|
|
40
39
|
import { persistTrustDecision, trustOptionsFor } from "../pi/resource-toggle-trust.js";
|
|
40
|
+
import { withSettingsWriteLock } from "../pi/settings-write-lock.js";
|
|
41
|
+
import {
|
|
42
|
+
__resetTrustChallenges,
|
|
43
|
+
clearTrustChallenge,
|
|
44
|
+
hasTrustChallenge,
|
|
45
|
+
registerTrustChallenge,
|
|
46
|
+
} from "../pi/trust-challenges.js";
|
|
41
47
|
import type { SessionManager } from "../session/memory-session-manager.js";
|
|
42
48
|
import type { NetworkGuard } from "./route-deps.js";
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* a caller cannot plant a durable trust record for a path of its choosing.
|
|
48
|
-
* Process-lifetime and in-memory: a restart simply makes the user re-toggle.
|
|
49
|
-
*/
|
|
50
|
-
const outstandingTrustChallenges = new Set<string>();
|
|
51
|
-
|
|
52
|
-
/** Test seam: clear the outstanding challenges (simulates a fresh process). */
|
|
53
|
-
export function __resetTrustChallenges(): void {
|
|
54
|
-
outstandingTrustChallenges.clear();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Per-settings-file write serialization (see file-routes.ts for the rationale).
|
|
58
|
-
const settingsWriteLocks = new Map<string, Promise<unknown>>();
|
|
59
|
-
function serializeWrite<T>(key: string, task: () => Promise<T>): Promise<T> {
|
|
60
|
-
const run = (settingsWriteLocks.get(key) ?? Promise.resolve()).then(task, task);
|
|
61
|
-
const tail = run.then(
|
|
62
|
-
() => {},
|
|
63
|
-
() => {},
|
|
64
|
-
);
|
|
65
|
-
settingsWriteLocks.set(key, tail);
|
|
66
|
-
void tail.then(() => {
|
|
67
|
-
if (settingsWriteLocks.get(key) === tail) settingsWriteLocks.delete(key);
|
|
68
|
-
});
|
|
69
|
-
return run;
|
|
70
|
-
}
|
|
50
|
+
// Outstanding trust challenges live in `pi/trust-challenges.ts`, shared with the
|
|
51
|
+
// Add-ons folder toggle. Re-exported so existing test imports keep working.
|
|
52
|
+
export { __resetTrustChallenges };
|
|
71
53
|
|
|
72
54
|
/** Session ids governed by a scope: local → folder prefix-match, global → all. */
|
|
73
55
|
/**
|
|
@@ -155,7 +137,7 @@ export function registerResourceActivationRoutes(
|
|
|
155
137
|
}
|
|
156
138
|
|
|
157
139
|
const key = settingsPathForScope(scope, body.cwd);
|
|
158
|
-
const result = await
|
|
140
|
+
const result = await withSettingsWriteLock(key, () =>
|
|
159
141
|
applyResourceToggle({
|
|
160
142
|
scope,
|
|
161
143
|
cwd: body.cwd,
|
|
@@ -169,7 +151,7 @@ export function registerResourceActivationRoutes(
|
|
|
169
151
|
if (!result.ok) {
|
|
170
152
|
reply.code(result.status);
|
|
171
153
|
if (result.trustRequired) {
|
|
172
|
-
if (body.cwd)
|
|
154
|
+
if (body.cwd) registerTrustChallenge(body.cwd);
|
|
173
155
|
return {
|
|
174
156
|
success: false,
|
|
175
157
|
error: result.error,
|
|
@@ -177,6 +159,8 @@ export function registerResourceActivationRoutes(
|
|
|
177
159
|
trustRequired: true,
|
|
178
160
|
trustOptions: result.trustOptions,
|
|
179
161
|
implicitlyTrusted: result.implicitlyTrusted,
|
|
162
|
+
...(result.preselected ? { preselected: result.preselected } : {}),
|
|
163
|
+
...(result.dashboardSource ? { dashboardSource: result.dashboardSource } : {}),
|
|
180
164
|
},
|
|
181
165
|
} satisfies ApiResponse;
|
|
182
166
|
}
|
|
@@ -203,7 +187,7 @@ export function registerResourceActivationRoutes(
|
|
|
203
187
|
reply.code(400);
|
|
204
188
|
return { success: false, error: "cwd is required" } satisfies ApiResponse;
|
|
205
189
|
}
|
|
206
|
-
if (!
|
|
190
|
+
if (!hasTrustChallenge(cwd)) {
|
|
207
191
|
reply.code(409);
|
|
208
192
|
return {
|
|
209
193
|
success: false,
|
|
@@ -230,7 +214,7 @@ export function registerResourceActivationRoutes(
|
|
|
230
214
|
error: `failed to record the project trust decision: ${(err as Error)?.message ?? String(err)}`,
|
|
231
215
|
} satisfies ApiResponse;
|
|
232
216
|
}
|
|
233
|
-
|
|
217
|
+
clearTrustChallenge(cwd);
|
|
234
218
|
return { success: true, data: { trusted: option.trusted } } satisfies ApiResponse;
|
|
235
219
|
},
|
|
236
220
|
);
|