@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,574 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed ACP v2 session-update model + upsert reducer.
|
|
3
|
+
*
|
|
4
|
+
* Single v1/v2 normalisation point (see `normalize-v1.ts`). Hand-written
|
|
5
|
+
* narrowing of the Draft v2 `SessionUpdate` schema (`@agentclientprotocol/sdk`
|
|
6
|
+
* `experimental/v2`) — no runtime dependency outside `packages/shared`.
|
|
7
|
+
*
|
|
8
|
+
* - `parseSessionUpdate` never throws: malformed / unknown payloads become
|
|
9
|
+
* `{ kind: "unknown", raw }` with the original object untouched.
|
|
10
|
+
* - `applyUpdate` is a pure upsert reducer keyed by `messageId` /
|
|
11
|
+
* `toolCallId` / `planId` / `terminalId`: an OMITTED field leaves the value
|
|
12
|
+
* unchanged, `null` clears it, a concrete value replaces it; chunk variants
|
|
13
|
+
* append to the entity with the matching id.
|
|
14
|
+
*
|
|
15
|
+
* Patch-field presence is encoded by key presence on the parsed update
|
|
16
|
+
* (`"title" in update`), so `null` and "omitted" stay distinguishable.
|
|
17
|
+
*
|
|
18
|
+
* See change: add-acp-session-driver (acp-update-model).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** An ACP content block (`text`, `image`, `resource_link`, … open enum). */
|
|
22
|
+
export interface AcpContentBlock {
|
|
23
|
+
type: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** An ACP tool-call content item (`content`, `diff`, `terminal`, … open enum). */
|
|
28
|
+
export interface AcpToolContent {
|
|
29
|
+
type: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AcpPlanEntry {
|
|
34
|
+
content: string;
|
|
35
|
+
priority?: string;
|
|
36
|
+
status?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AcpConfigOption {
|
|
40
|
+
configId: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
/** `mode` | `model` | `thought_level` | `_custom` … */
|
|
43
|
+
category?: string | null;
|
|
44
|
+
type: string;
|
|
45
|
+
currentValue: unknown;
|
|
46
|
+
options?: Array<{ value: string; name: string; description?: string | null }>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AcpCommand {
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Turn state of the foreground run. */
|
|
55
|
+
export type AcpRunState = "running" | "idle" | "requires_action";
|
|
56
|
+
|
|
57
|
+
export type AcpUpdate =
|
|
58
|
+
| { kind: "user_message"; messageId: string; content?: AcpContentBlock[] | null }
|
|
59
|
+
| { kind: "user_message_chunk"; messageId: string; content: AcpContentBlock }
|
|
60
|
+
| { kind: "agent_message"; messageId: string; content?: AcpContentBlock[] | null }
|
|
61
|
+
| { kind: "agent_message_chunk"; messageId: string; content: AcpContentBlock }
|
|
62
|
+
| { kind: "agent_thought"; messageId: string; content?: AcpContentBlock[] | null }
|
|
63
|
+
| { kind: "agent_thought_chunk"; messageId: string; content: AcpContentBlock }
|
|
64
|
+
| {
|
|
65
|
+
kind: "tool_call_update";
|
|
66
|
+
toolCallId: string;
|
|
67
|
+
/** Patch fields: key absent = unchanged, `null` = clear. */
|
|
68
|
+
name?: string | null;
|
|
69
|
+
title?: string | null;
|
|
70
|
+
toolKind?: string | null;
|
|
71
|
+
status?: string | null;
|
|
72
|
+
content?: AcpToolContent[] | null;
|
|
73
|
+
rawInput?: unknown;
|
|
74
|
+
rawOutput?: unknown;
|
|
75
|
+
}
|
|
76
|
+
| { kind: "tool_call_content_chunk"; toolCallId: string; content: AcpToolContent }
|
|
77
|
+
| { kind: "state_update"; state: AcpRunState; stopReason?: string | null; error?: unknown }
|
|
78
|
+
| {
|
|
79
|
+
kind: "plan_update";
|
|
80
|
+
planId: string;
|
|
81
|
+
/** `items` carries `entries`; other plan types keep the raw plan in `content`. */
|
|
82
|
+
type: string;
|
|
83
|
+
entries?: AcpPlanEntry[];
|
|
84
|
+
content?: unknown;
|
|
85
|
+
}
|
|
86
|
+
| { kind: "config_option_update"; options: AcpConfigOption[] }
|
|
87
|
+
| { kind: "available_commands_update"; commands: AcpCommand[] }
|
|
88
|
+
| {
|
|
89
|
+
kind: "usage_update";
|
|
90
|
+
used: number;
|
|
91
|
+
size: number;
|
|
92
|
+
cost?: { amount: number; currency: string } | null;
|
|
93
|
+
}
|
|
94
|
+
| { kind: "session_info_update"; title?: string | null; updatedAt?: string | null }
|
|
95
|
+
| {
|
|
96
|
+
kind: "terminal_update";
|
|
97
|
+
terminalId: string;
|
|
98
|
+
command?: string | null;
|
|
99
|
+
cwd?: string | null;
|
|
100
|
+
/** Authoritative replacement snapshot (base64 bytes) of the output. */
|
|
101
|
+
output?: { data: string } | null;
|
|
102
|
+
exitStatus?: { exitCode?: number | null; signal?: string | null } | null;
|
|
103
|
+
}
|
|
104
|
+
| { kind: "terminal_output_chunk"; terminalId: string; data: string }
|
|
105
|
+
| { kind: "unknown"; raw: unknown };
|
|
106
|
+
|
|
107
|
+
export type AcpUpdateKind = AcpUpdate["kind"];
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------- parsing
|
|
110
|
+
|
|
111
|
+
type Rec = Record<string, unknown>;
|
|
112
|
+
|
|
113
|
+
const isRec = (v: unknown): v is Rec => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
114
|
+
const isStr = (v: unknown): v is string => typeof v === "string";
|
|
115
|
+
const isNum = (v: unknown): v is number => typeof v === "number" && Number.isFinite(v);
|
|
116
|
+
const isBlock = (v: unknown): v is AcpContentBlock => isRec(v) && isStr(v.type);
|
|
117
|
+
|
|
118
|
+
/** `undefined` (key absent) | `null` | valid → ok; anything else → bad. */
|
|
119
|
+
function optPatch<T>(
|
|
120
|
+
raw: Rec,
|
|
121
|
+
key: string,
|
|
122
|
+
guard: (v: unknown) => v is T,
|
|
123
|
+
): { ok: true; present: boolean; value: T | null | undefined } | { ok: false } {
|
|
124
|
+
if (!(key in raw) || raw[key] === undefined) return { ok: true, present: false, value: undefined };
|
|
125
|
+
const v = raw[key];
|
|
126
|
+
if (v === null) return { ok: true, present: true, value: null };
|
|
127
|
+
return guard(v) ? { ok: true, present: true, value: v } : { ok: false };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const isBlockArray = (v: unknown): v is AcpContentBlock[] => Array.isArray(v) && v.every(isBlock);
|
|
131
|
+
|
|
132
|
+
function parseMessage(
|
|
133
|
+
kind: "user_message" | "agent_message" | "agent_thought",
|
|
134
|
+
raw: Rec,
|
|
135
|
+
): AcpUpdate | undefined {
|
|
136
|
+
if (!isStr(raw.messageId)) return undefined;
|
|
137
|
+
const content = optPatch(raw, "content", isBlockArray);
|
|
138
|
+
if (!content.ok) return undefined;
|
|
139
|
+
const out: Extract<AcpUpdate, { kind: typeof kind }> = { kind, messageId: raw.messageId };
|
|
140
|
+
if (content.present) out.content = content.value as AcpContentBlock[] | null;
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function parseChunk(
|
|
145
|
+
kind: "user_message_chunk" | "agent_message_chunk" | "agent_thought_chunk",
|
|
146
|
+
raw: Rec,
|
|
147
|
+
): AcpUpdate | undefined {
|
|
148
|
+
if (!isStr(raw.messageId) || !isBlock(raw.content)) return undefined;
|
|
149
|
+
return { kind, messageId: raw.messageId, content: raw.content };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const TOOL_PATCH_FIELDS = [
|
|
153
|
+
["name", "name"],
|
|
154
|
+
["title", "title"],
|
|
155
|
+
["status", "status"],
|
|
156
|
+
["kind", "toolKind"],
|
|
157
|
+
] as const;
|
|
158
|
+
|
|
159
|
+
function parseToolCall(raw: Rec): AcpUpdate | undefined {
|
|
160
|
+
if (!isStr(raw.toolCallId)) return undefined;
|
|
161
|
+
const out: Extract<AcpUpdate, { kind: "tool_call_update" }> = {
|
|
162
|
+
kind: "tool_call_update",
|
|
163
|
+
toolCallId: raw.toolCallId,
|
|
164
|
+
};
|
|
165
|
+
for (const [wire, field] of TOOL_PATCH_FIELDS) {
|
|
166
|
+
const p = optPatch(raw, wire, isStr);
|
|
167
|
+
if (!p.ok) return undefined;
|
|
168
|
+
if (p.present) out[field] = p.value as string | null;
|
|
169
|
+
}
|
|
170
|
+
const c = optPatch(raw, "content", (v): v is AcpToolContent[] => Array.isArray(v) && v.every(isBlock));
|
|
171
|
+
if (!c.ok) return undefined;
|
|
172
|
+
if (c.present) out.content = c.value as AcpToolContent[] | null;
|
|
173
|
+
if (raw.rawInput !== undefined) out.rawInput = raw.rawInput;
|
|
174
|
+
if (raw.rawOutput !== undefined) out.rawOutput = raw.rawOutput;
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function parsePlanEntry(e: unknown): AcpPlanEntry | undefined {
|
|
179
|
+
if (!isRec(e) || !isStr(e.content)) return undefined;
|
|
180
|
+
return {
|
|
181
|
+
content: e.content,
|
|
182
|
+
...(isStr(e.priority) ? { priority: e.priority } : {}),
|
|
183
|
+
...(isStr(e.status) ? { status: e.status } : {}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function parsePlan(raw: Rec): AcpUpdate | undefined {
|
|
188
|
+
const plan = raw.plan;
|
|
189
|
+
if (!isRec(plan) || !isStr(plan.type) || !isStr(plan.planId)) return undefined;
|
|
190
|
+
if (plan.type !== "items") return { kind: "plan_update", planId: plan.planId, type: plan.type, content: plan };
|
|
191
|
+
if (!Array.isArray(plan.entries)) return undefined;
|
|
192
|
+
const entries = plan.entries.map(parsePlanEntry);
|
|
193
|
+
if (entries.some((e) => e === undefined)) return undefined;
|
|
194
|
+
return { kind: "plan_update", planId: plan.planId, type: "items", entries: entries as AcpPlanEntry[] };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Flatten select groups (`{groupId, options:[…]}`) to a single value list. */
|
|
198
|
+
function flattenSelectOptions(options: unknown[]): NonNullable<AcpConfigOption["options"]> {
|
|
199
|
+
const flat: NonNullable<AcpConfigOption["options"]> = [];
|
|
200
|
+
for (const item of options) {
|
|
201
|
+
if (!isRec(item)) continue;
|
|
202
|
+
const inner = Array.isArray(item.options) ? item.options : [item];
|
|
203
|
+
for (const v of inner) {
|
|
204
|
+
if (isRec(v) && isStr(v.value) && isStr(v.name)) flat.push({ value: v.value, name: v.name });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return flat;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function parseConfigOption(o: unknown): AcpConfigOption | undefined {
|
|
211
|
+
if (!isRec(o) || !isStr(o.configId) || !isStr(o.type)) return undefined;
|
|
212
|
+
const opt: AcpConfigOption = { configId: o.configId, type: o.type, currentValue: o.currentValue };
|
|
213
|
+
if (isStr(o.name)) opt.name = o.name;
|
|
214
|
+
if (isStr(o.category) || o.category === null) opt.category = o.category as string | null;
|
|
215
|
+
if (Array.isArray(o.options)) opt.options = flattenSelectOptions(o.options);
|
|
216
|
+
return opt;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function parseConfigOptions(raw: Rec): AcpUpdate | undefined {
|
|
220
|
+
if (!Array.isArray(raw.configOptions)) return undefined;
|
|
221
|
+
const options = raw.configOptions.map(parseConfigOption);
|
|
222
|
+
if (options.some((o) => o === undefined)) return undefined;
|
|
223
|
+
return { kind: "config_option_update", options: options as AcpConfigOption[] };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function parseState(raw: Rec): AcpUpdate | undefined {
|
|
227
|
+
const state = raw.state;
|
|
228
|
+
if (state !== "running" && state !== "idle" && state !== "requires_action") return undefined;
|
|
229
|
+
const out: Extract<AcpUpdate, { kind: "state_update" }> = { kind: "state_update", state };
|
|
230
|
+
if (state !== "idle") return out;
|
|
231
|
+
const stop = optPatch(raw, "stopReason", isStr);
|
|
232
|
+
if (!stop.ok) return undefined;
|
|
233
|
+
if (stop.present || "stopReason" in raw) out.stopReason = (stop.value as string | null | undefined) ?? null;
|
|
234
|
+
if (raw.error !== undefined && raw.error !== null) out.error = raw.error;
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function parseCommands(raw: Rec): AcpUpdate | undefined {
|
|
239
|
+
if (!Array.isArray(raw.availableCommands)) return undefined;
|
|
240
|
+
const commands: AcpCommand[] = [];
|
|
241
|
+
for (const c of raw.availableCommands) {
|
|
242
|
+
if (!isRec(c) || !isStr(c.name)) return undefined;
|
|
243
|
+
commands.push({ name: c.name, ...(isStr(c.description) ? { description: c.description } : {}) });
|
|
244
|
+
}
|
|
245
|
+
return { kind: "available_commands_update", commands };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function parseCost(cost: unknown): { amount: number; currency: string } | null | undefined {
|
|
249
|
+
if (cost === null) return null;
|
|
250
|
+
if (isRec(cost) && isNum(cost.amount) && isStr(cost.currency)) return { amount: cost.amount, currency: cost.currency };
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function parseUsage(raw: Rec): AcpUpdate | undefined {
|
|
255
|
+
if (!isNum(raw.used) || !isNum(raw.size)) return undefined;
|
|
256
|
+
const out: Extract<AcpUpdate, { kind: "usage_update" }> = { kind: "usage_update", used: raw.used, size: raw.size };
|
|
257
|
+
const cost = parseCost(raw.cost);
|
|
258
|
+
if (cost !== undefined) out.cost = cost;
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function parseSessionInfo(raw: Rec): AcpUpdate | undefined {
|
|
263
|
+
const title = optPatch(raw, "title", isStr);
|
|
264
|
+
const updatedAt = optPatch(raw, "updatedAt", isStr);
|
|
265
|
+
if (!title.ok || !updatedAt.ok) return undefined;
|
|
266
|
+
const out: Extract<AcpUpdate, { kind: "session_info_update" }> = { kind: "session_info_update" };
|
|
267
|
+
if (title.present) out.title = title.value as string | null;
|
|
268
|
+
if (updatedAt.present) out.updatedAt = updatedAt.value as string | null;
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function parseExitStatus(v: unknown): { exitCode?: number | null; signal?: string | null } | null | undefined {
|
|
273
|
+
if (v === null) return null;
|
|
274
|
+
if (!isRec(v)) return undefined;
|
|
275
|
+
const out: { exitCode?: number | null; signal?: string | null } = {};
|
|
276
|
+
if (isNum(v.exitCode) || v.exitCode === null) out.exitCode = v.exitCode;
|
|
277
|
+
if (isStr(v.signal) || v.signal === null) out.signal = v.signal;
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function parseTerminalUpdate(raw: Rec): AcpUpdate | undefined {
|
|
282
|
+
if (!isStr(raw.terminalId)) return undefined;
|
|
283
|
+
const out: Extract<AcpUpdate, { kind: "terminal_update" }> = { kind: "terminal_update", terminalId: raw.terminalId };
|
|
284
|
+
for (const key of ["command", "cwd"] as const) {
|
|
285
|
+
const p = optPatch(raw, key, isStr);
|
|
286
|
+
if (!p.ok) return undefined;
|
|
287
|
+
if (p.present) out[key] = p.value as string | null;
|
|
288
|
+
}
|
|
289
|
+
if (raw.output === null) out.output = null;
|
|
290
|
+
else if (raw.output !== undefined) {
|
|
291
|
+
if (!isRec(raw.output) || !isStr(raw.output.data)) return undefined;
|
|
292
|
+
out.output = { data: raw.output.data };
|
|
293
|
+
}
|
|
294
|
+
if (raw.exitStatus !== undefined) {
|
|
295
|
+
const exit = parseExitStatus(raw.exitStatus);
|
|
296
|
+
if (exit === undefined) return undefined;
|
|
297
|
+
out.exitStatus = exit;
|
|
298
|
+
}
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const parseMessageUpdate = (kind: "user_message" | "agent_message" | "agent_thought") => (raw: Rec) =>
|
|
303
|
+
parseMessage(kind, raw);
|
|
304
|
+
const parseChunkUpdate = (kind: "user_message_chunk" | "agent_message_chunk" | "agent_thought_chunk") => (raw: Rec) =>
|
|
305
|
+
parseChunk(kind, raw);
|
|
306
|
+
|
|
307
|
+
const PARSERS: Record<string, (raw: Rec) => AcpUpdate | undefined> = {
|
|
308
|
+
user_message: parseMessageUpdate("user_message"),
|
|
309
|
+
agent_message: parseMessageUpdate("agent_message"),
|
|
310
|
+
agent_thought: parseMessageUpdate("agent_thought"),
|
|
311
|
+
user_message_chunk: parseChunkUpdate("user_message_chunk"),
|
|
312
|
+
agent_message_chunk: parseChunkUpdate("agent_message_chunk"),
|
|
313
|
+
agent_thought_chunk: parseChunkUpdate("agent_thought_chunk"),
|
|
314
|
+
tool_call_update: parseToolCall,
|
|
315
|
+
tool_call_content_chunk: (raw) =>
|
|
316
|
+
isStr(raw.toolCallId) && isBlock(raw.content)
|
|
317
|
+
? { kind: "tool_call_content_chunk", toolCallId: raw.toolCallId, content: raw.content }
|
|
318
|
+
: undefined,
|
|
319
|
+
state_update: parseState,
|
|
320
|
+
plan_update: parsePlan,
|
|
321
|
+
config_option_update: parseConfigOptions,
|
|
322
|
+
available_commands_update: parseCommands,
|
|
323
|
+
usage_update: parseUsage,
|
|
324
|
+
session_info_update: parseSessionInfo,
|
|
325
|
+
terminal_update: parseTerminalUpdate,
|
|
326
|
+
terminal_output_chunk: (raw) =>
|
|
327
|
+
isStr(raw.terminalId) && isStr(raw.data)
|
|
328
|
+
? { kind: "terminal_output_chunk", terminalId: raw.terminalId, data: raw.data }
|
|
329
|
+
: undefined,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Parse one v2 `session/update` payload (`{ sessionUpdate, …fields }`).
|
|
334
|
+
* Never throws. Unrecognised variants (including `_`-prefixed extensions and
|
|
335
|
+
* future non-underscore values) and malformed payloads yield
|
|
336
|
+
* `{ kind: "unknown", raw }` carrying the original object unmodified.
|
|
337
|
+
*/
|
|
338
|
+
export function parseSessionUpdate(raw: unknown): AcpUpdate {
|
|
339
|
+
try {
|
|
340
|
+
if (isRec(raw) && isStr(raw.sessionUpdate)) {
|
|
341
|
+
const parsed = Object.hasOwn(PARSERS, raw.sessionUpdate) ? PARSERS[raw.sessionUpdate]?.(raw) : undefined;
|
|
342
|
+
if (parsed) return parsed;
|
|
343
|
+
}
|
|
344
|
+
} catch {
|
|
345
|
+
// fall through to unknown
|
|
346
|
+
}
|
|
347
|
+
return { kind: "unknown", raw };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ---------------------------------------------------------------- state
|
|
351
|
+
|
|
352
|
+
export interface AcpMessage {
|
|
353
|
+
messageId: string;
|
|
354
|
+
role: "user" | "agent" | "thought";
|
|
355
|
+
content: AcpContentBlock[];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface AcpToolCall {
|
|
359
|
+
toolCallId: string;
|
|
360
|
+
name?: string;
|
|
361
|
+
title?: string;
|
|
362
|
+
toolKind?: string;
|
|
363
|
+
status?: string;
|
|
364
|
+
content: AcpToolContent[];
|
|
365
|
+
rawInput?: unknown;
|
|
366
|
+
rawOutput?: unknown;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface AcpTerminal {
|
|
370
|
+
terminalId: string;
|
|
371
|
+
command?: string;
|
|
372
|
+
cwd?: string;
|
|
373
|
+
/** Decoded output text accumulated from `terminal_output_chunk` / snapshots. */
|
|
374
|
+
output: string;
|
|
375
|
+
exitStatus?: { exitCode?: number | null; signal?: string | null };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface AcpPlan {
|
|
379
|
+
planId: string;
|
|
380
|
+
type: string;
|
|
381
|
+
entries: AcpPlanEntry[];
|
|
382
|
+
content?: unknown;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface AcpSessionState {
|
|
386
|
+
messages: ReadonlyMap<string, AcpMessage>;
|
|
387
|
+
toolCalls: ReadonlyMap<string, AcpToolCall>;
|
|
388
|
+
terminals: ReadonlyMap<string, AcpTerminal>;
|
|
389
|
+
plans: ReadonlyMap<string, AcpPlan>;
|
|
390
|
+
configOptions: ReadonlyMap<string, AcpConfigOption>;
|
|
391
|
+
commands: readonly AcpCommand[];
|
|
392
|
+
title?: string;
|
|
393
|
+
run: { state: AcpRunState; stopReason?: string | null };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function createAcpSessionState(): AcpSessionState {
|
|
397
|
+
return {
|
|
398
|
+
messages: new Map(),
|
|
399
|
+
toolCalls: new Map(),
|
|
400
|
+
terminals: new Map(),
|
|
401
|
+
plans: new Map(),
|
|
402
|
+
configOptions: new Map(),
|
|
403
|
+
commands: [],
|
|
404
|
+
run: { state: "idle" },
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Decode a base64 terminal payload to text (UTF-8). Chunks are independently
|
|
410
|
+
* encoded, so a multi-byte character split across two chunks decodes lossily
|
|
411
|
+
* (U+FFFD) — accepted for chat display. Never throws.
|
|
412
|
+
*/
|
|
413
|
+
export function decodeTerminalData(data: string): string {
|
|
414
|
+
try {
|
|
415
|
+
const bin = atob(data);
|
|
416
|
+
const bytes = new Uint8Array(bin.length);
|
|
417
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
418
|
+
return new TextDecoder().decode(bytes);
|
|
419
|
+
} catch {
|
|
420
|
+
return "";
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function withEntry<K, V>(map: ReadonlyMap<K, V>, key: K, value: V): Map<K, V> {
|
|
425
|
+
const next = new Map(map);
|
|
426
|
+
next.set(key, value);
|
|
427
|
+
return next;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function upsertMessage(
|
|
431
|
+
state: AcpSessionState,
|
|
432
|
+
role: AcpMessage["role"],
|
|
433
|
+
messageId: string,
|
|
434
|
+
mutate: (prev: AcpContentBlock[]) => AcpContentBlock[],
|
|
435
|
+
): AcpSessionState {
|
|
436
|
+
const prev = state.messages.get(messageId);
|
|
437
|
+
const next: AcpMessage = { messageId, role: prev?.role ?? role, content: mutate(prev?.content ?? []) };
|
|
438
|
+
return { ...state, messages: withEntry(state.messages, messageId, next) };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const MESSAGE_ROLE = {
|
|
442
|
+
user_message: "user",
|
|
443
|
+
user_message_chunk: "user",
|
|
444
|
+
agent_message: "agent",
|
|
445
|
+
agent_message_chunk: "agent",
|
|
446
|
+
agent_thought: "thought",
|
|
447
|
+
agent_thought_chunk: "thought",
|
|
448
|
+
} as const;
|
|
449
|
+
|
|
450
|
+
type ToolPatch = Partial<Record<string, unknown>>;
|
|
451
|
+
|
|
452
|
+
const TOOL_STRING_FIELDS = ["name", "title", "toolKind", "status"] as const;
|
|
453
|
+
|
|
454
|
+
function patchToolCall(prev: AcpToolCall | undefined, toolCallId: string, u: ToolPatch): AcpToolCall {
|
|
455
|
+
const next: AcpToolCall = { ...(prev ?? { toolCallId, content: [] }) };
|
|
456
|
+
for (const field of TOOL_STRING_FIELDS) {
|
|
457
|
+
if (!(field in u)) continue;
|
|
458
|
+
if (u[field] === null) delete next[field];
|
|
459
|
+
else next[field] = u[field] as string;
|
|
460
|
+
}
|
|
461
|
+
if ("content" in u) next.content = (u.content as AcpToolContent[] | null) ?? [];
|
|
462
|
+
for (const key of ["rawInput", "rawOutput"] as const) {
|
|
463
|
+
if (!(key in u)) continue;
|
|
464
|
+
if (u[key] === null) delete next[key];
|
|
465
|
+
else next[key] = u[key];
|
|
466
|
+
}
|
|
467
|
+
return next;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
type Reducer<K extends AcpUpdateKind> = (state: AcpSessionState, update: Extract<AcpUpdate, { kind: K }>) => AcpSessionState;
|
|
471
|
+
|
|
472
|
+
const applyMessage: Reducer<"user_message" | "agent_message" | "agent_thought"> = (state, update) => {
|
|
473
|
+
const role = MESSAGE_ROLE[update.kind];
|
|
474
|
+
// Whole-message upsert: content replaces everything accumulated so far.
|
|
475
|
+
if (!("content" in update)) return upsertMessage(state, role, update.messageId, (p) => p);
|
|
476
|
+
return upsertMessage(state, role, update.messageId, () => update.content ?? []);
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const applyChunk: Reducer<"user_message_chunk" | "agent_message_chunk" | "agent_thought_chunk"> = (state, update) =>
|
|
480
|
+
upsertMessage(state, MESSAGE_ROLE[update.kind], update.messageId, (p) => [...p, update.content]);
|
|
481
|
+
|
|
482
|
+
const applyToolCall: Reducer<"tool_call_update"> = (state, update) => {
|
|
483
|
+
const { kind: _k, toolCallId, ...patch } = update;
|
|
484
|
+
const next = patchToolCall(state.toolCalls.get(toolCallId), toolCallId, patch);
|
|
485
|
+
return { ...state, toolCalls: withEntry(state.toolCalls, toolCallId, next) };
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const applyToolChunk: Reducer<"tool_call_content_chunk"> = (state, update) => {
|
|
489
|
+
const next = patchToolCall(state.toolCalls.get(update.toolCallId), update.toolCallId, {});
|
|
490
|
+
next.content = [...next.content, update.content];
|
|
491
|
+
return { ...state, toolCalls: withEntry(state.toolCalls, update.toolCallId, next) };
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const applyRun: Reducer<"state_update"> = (state, update) => ({
|
|
495
|
+
...state,
|
|
496
|
+
run: { state: update.state, ...(update.stopReason !== undefined ? { stopReason: update.stopReason } : {}) },
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
const applyPlan: Reducer<"plan_update"> = (state, update) => ({
|
|
500
|
+
...state,
|
|
501
|
+
plans: withEntry(state.plans, update.planId, {
|
|
502
|
+
planId: update.planId,
|
|
503
|
+
type: update.type,
|
|
504
|
+
entries: update.entries ?? [],
|
|
505
|
+
...(update.content !== undefined ? { content: update.content } : {}),
|
|
506
|
+
}),
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const applyConfig: Reducer<"config_option_update"> = (state, update) => {
|
|
510
|
+
const next = new Map(state.configOptions);
|
|
511
|
+
for (const o of update.options) next.set(o.configId, o);
|
|
512
|
+
return { ...state, configOptions: next };
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
const applySessionInfo: Reducer<"session_info_update"> = (state, update) => {
|
|
516
|
+
if (!("title" in update)) return state;
|
|
517
|
+
const { title: _t, ...rest } = state;
|
|
518
|
+
return update.title ? { ...rest, title: update.title } : rest;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
function patchOptional<T extends object, K extends keyof T>(target: T, key: K, value: T[K] | null): void {
|
|
522
|
+
if (value === null) delete target[key];
|
|
523
|
+
else target[key] = value;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const applyTerminalUpdate: Reducer<"terminal_update"> = (state, update) => {
|
|
527
|
+
const next: AcpTerminal = { ...(state.terminals.get(update.terminalId) ?? { terminalId: update.terminalId, output: "" }) };
|
|
528
|
+
if ("command" in update) patchOptional(next, "command", update.command ?? null);
|
|
529
|
+
if ("cwd" in update) patchOptional(next, "cwd", update.cwd ?? null);
|
|
530
|
+
if ("exitStatus" in update) patchOptional(next, "exitStatus", update.exitStatus ?? null);
|
|
531
|
+
if ("output" in update) next.output = update.output ? decodeTerminalData(update.output.data) : "";
|
|
532
|
+
return { ...state, terminals: withEntry(state.terminals, update.terminalId, next) };
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const applyTerminalChunk: Reducer<"terminal_output_chunk"> = (state, update) => {
|
|
536
|
+
const prev = state.terminals.get(update.terminalId) ?? { terminalId: update.terminalId, output: "" };
|
|
537
|
+
const next = { ...prev, output: prev.output + decodeTerminalData(update.data) };
|
|
538
|
+
return { ...state, terminals: withEntry(state.terminals, update.terminalId, next) };
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
/** Pure upsert reducer. Unknown updates leave state unchanged. */
|
|
542
|
+
export function applyUpdate(state: AcpSessionState, update: AcpUpdate): AcpSessionState {
|
|
543
|
+
switch (update.kind) {
|
|
544
|
+
case "user_message":
|
|
545
|
+
case "agent_message":
|
|
546
|
+
case "agent_thought":
|
|
547
|
+
return applyMessage(state, update);
|
|
548
|
+
case "user_message_chunk":
|
|
549
|
+
case "agent_message_chunk":
|
|
550
|
+
case "agent_thought_chunk":
|
|
551
|
+
return applyChunk(state, update);
|
|
552
|
+
case "tool_call_update":
|
|
553
|
+
return applyToolCall(state, update);
|
|
554
|
+
case "tool_call_content_chunk":
|
|
555
|
+
return applyToolChunk(state, update);
|
|
556
|
+
case "state_update":
|
|
557
|
+
return applyRun(state, update);
|
|
558
|
+
case "plan_update":
|
|
559
|
+
return applyPlan(state, update);
|
|
560
|
+
case "config_option_update":
|
|
561
|
+
return applyConfig(state, update);
|
|
562
|
+
case "available_commands_update":
|
|
563
|
+
return { ...state, commands: update.commands };
|
|
564
|
+
case "session_info_update":
|
|
565
|
+
return applySessionInfo(state, update);
|
|
566
|
+
case "terminal_update":
|
|
567
|
+
return applyTerminalUpdate(state, update);
|
|
568
|
+
case "terminal_output_chunk":
|
|
569
|
+
return applyTerminalChunk(state, update);
|
|
570
|
+
case "usage_update":
|
|
571
|
+
case "unknown":
|
|
572
|
+
return state;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install source of the required `pi-anthropic-messages` peer — its own tiny
|
|
3
|
+
* module so the client's cold-landing peer probe (`anthropic-peer.ts`) can
|
|
4
|
+
* read it without pulling `recommended-extensions.ts` (every entry's
|
|
5
|
+
* description) into the gzipped index chunk (mdi-chunk-size cap). Bundlers
|
|
6
|
+
* keep a module whole, so a sibling export of the manifest would not help.
|
|
7
|
+
*/
|
|
8
|
+
export const ANTHROPIC_MESSAGES_SOURCE = "npm:@blackbelt-technology/pi-anthropic-messages";
|
|
@@ -131,6 +131,23 @@ export function trustEntryCovers(entry: string, ip: string): boolean {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* IPv6 loopback spellings the trust matcher cannot express but a hand-edited
|
|
136
|
+
* list may carry: `::1` (optionally `/128`) and IPv4-mapped `::ffff:127.x.y.z`
|
|
137
|
+
* (optionally `/104`..`/128`). Anything else IPv6 (`::/0`, `fe80::/10`) is NOT
|
|
138
|
+
* loopback-only. See change: retire-trusted-networks-bypass (design D2).
|
|
139
|
+
*/
|
|
140
|
+
function isLoopbackIpv6Entry(entry: string): boolean {
|
|
141
|
+
const [addr, bitsStr, ...rest] = entry.trim().toLowerCase().split("/");
|
|
142
|
+
if (rest.length > 0 || !addr) return false;
|
|
143
|
+
const bits = bitsStr === undefined ? null : /^\d{1,3}$/.test(bitsStr) ? Number.parseInt(bitsStr, 10) : Number.NaN;
|
|
144
|
+
if (bits !== null && Number.isNaN(bits)) return false;
|
|
145
|
+
if (addr === "::1" || addr === "0:0:0:0:0:0:0:1") return bits === null || bits === 128;
|
|
146
|
+
const mapped = /^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/.exec(addr);
|
|
147
|
+
if (mapped && isLoopbackIpv4(mapped[1])) return bits === null || (bits >= 104 && bits <= 128);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
134
151
|
/**
|
|
135
152
|
* True when EVERY address `entry` covers lies inside `127.0.0.0/8`.
|
|
136
153
|
*
|
|
@@ -141,6 +158,7 @@ export function trustEntryCovers(entry: string, ip: string): boolean {
|
|
|
141
158
|
* Note `127.0.0.0/7` is NOT loopback-only — it also covers `126.x`.
|
|
142
159
|
*/
|
|
143
160
|
export function isLoopbackOnlyEntry(entry: string): boolean {
|
|
161
|
+
if (isLoopbackIpv6Entry(entry)) return true;
|
|
144
162
|
if (!isValidTrustEntry(entry)) return false;
|
|
145
163
|
switch (entryKind(entry)) {
|
|
146
164
|
case "cidr": {
|
|
@@ -205,8 +223,9 @@ export interface TrustedEntriesConfigShape {
|
|
|
205
223
|
|
|
206
224
|
/**
|
|
207
225
|
* The union of `auth.bypassHosts` and the legacy top-level `trustedNetworks`,
|
|
208
|
-
* mirroring `hasGuardConfig()` and `resolvedTrustedNetworks
|
|
209
|
-
*
|
|
226
|
+
* mirroring `hasGuardConfig()` and `resolvedTrustedNetworks`. Both lists are
|
|
227
|
+
* scored for the reachability advisory. In `pair` trust mode they do not admit
|
|
228
|
+
* requests (knock eligibility only); in `legacy` mode both still admit.
|
|
210
229
|
*/
|
|
211
230
|
export function collectTrustedEntries(config: TrustedEntriesConfigShape | null | undefined): string[] {
|
|
212
231
|
return [...(config?.trustedNetworks ?? []), ...(config?.auth?.bypassHosts ?? [])];
|
|
@@ -33,6 +33,12 @@ export interface BootRecord {
|
|
|
33
33
|
*/
|
|
34
34
|
export interface BootState extends BootRecord {
|
|
35
35
|
ring: BootRecord[];
|
|
36
|
+
/**
|
|
37
|
+
* When the one-shot legacy leg of the service-session boot backfill ran
|
|
38
|
+
* (epoch ms). Absent ⇒ not yet run. Carried forward by every rewrite.
|
|
39
|
+
* See change: archive-service-sessions-on-end.
|
|
40
|
+
*/
|
|
41
|
+
serviceArchiveBackfillAt?: number;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
/** Prior boots retained beside the current one. */
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator browser-host identity primitives (Ed25519, `node:crypto` only).
|
|
3
|
+
*
|
|
4
|
+
* `hostId` = `host-` + first 32 hex chars of SHA-256(SPKI DER public key).
|
|
5
|
+
* Registration signs `"pi-browser-host-v1\n" + nonce + "\n" + serverId`, where
|
|
6
|
+
* `serverId` is the target server's `/api/health` `instanceId`.
|
|
7
|
+
*
|
|
8
|
+
* Wire encoding: public key = base64(SPKI DER); signature = base64.
|
|
9
|
+
* See change: add-operator-browser-relay (design D2).
|
|
10
|
+
*/
|
|
11
|
+
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
12
|
+
|
|
13
|
+
export const HOST_SIGNATURE_DOMAIN = "pi-browser-host-v1";
|
|
14
|
+
export const HOST_ID_PATTERN = /^host-[0-9a-f]{32}$/;
|
|
15
|
+
|
|
16
|
+
/** `host-` + 32 hex of SHA-256 over the SPKI DER bytes. */
|
|
17
|
+
export function hostIdFromPublicKey(publicKeyBase64: string): string {
|
|
18
|
+
const der = Buffer.from(publicKeyBase64, "base64");
|
|
19
|
+
return `host-${createHash("sha256").update(der).digest("hex").slice(0, 32)}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The exact byte string a host signs to register against `serverId`. */
|
|
23
|
+
export function buildHostSignedMessage(nonce: string, serverId: string): string {
|
|
24
|
+
return `${HOST_SIGNATURE_DOMAIN}\n${nonce}\n${serverId}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Verify a registration signature. Never throws — a malformed input is `false`. */
|
|
28
|
+
export function verifyHostSignature(
|
|
29
|
+
publicKeyBase64: string,
|
|
30
|
+
nonce: string,
|
|
31
|
+
serverId: string,
|
|
32
|
+
signatureBase64: string,
|
|
33
|
+
): boolean {
|
|
34
|
+
try {
|
|
35
|
+
const key = createPublicKey({
|
|
36
|
+
key: Buffer.from(publicKeyBase64, "base64"),
|
|
37
|
+
format: "der",
|
|
38
|
+
type: "spki",
|
|
39
|
+
});
|
|
40
|
+
return verify(
|
|
41
|
+
null,
|
|
42
|
+
Buffer.from(buildHostSignedMessage(nonce, serverId), "utf-8"),
|
|
43
|
+
key,
|
|
44
|
+
Buffer.from(signatureBase64, "base64"),
|
|
45
|
+
);
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|