@blackbelt-technology/pi-agent-dashboard 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -0
- package/README.md +17 -12
- package/docs/architecture.md +973 -224
- package/package.json +29 -18
- package/packages/extension/package.json +16 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +54 -69
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +21 -12
- package/packages/extension/src/bridge-handlers/lifecycle.ts +84 -40
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge.ts +272 -260
- package/packages/extension/src/command-handler.ts +26 -31
- package/packages/extension/src/connection.ts +123 -31
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust.ts +24 -15
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +428 -28
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +21 -4
- package/packages/extension/src/server-auto-start.ts +68 -2
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/session-sync.ts +11 -12
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +244 -58
- package/packages/server/src/access/access-plane.ts +7 -0
- package/packages/server/src/access/containment-gate.ts +66 -21
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-mirror-service.ts +7 -1
- package/packages/server/src/access/planes.ts +1 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +10 -2
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +1 -1
- package/packages/server/src/auth/audit-log.ts +28 -0
- package/packages/server/src/auth/auth-plugin.ts +188 -15
- package/packages/server/src/auth/auth.ts +80 -0
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +14 -1
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +0 -5
- package/packages/server/src/auth/csp.ts +74 -36
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/localhost-guard.ts +50 -23
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/provider-auth-storage.ts +208 -11
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +1 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +11 -24
- package/packages/server/src/browser-handlers/session-action-handler.ts +158 -62
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +46 -1
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +21 -16
- package/packages/server/src/config-api.ts +34 -38
- package/packages/server/src/config-snapshot.ts +149 -0
- package/packages/server/src/directory-service.ts +33 -14
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +181 -101
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +1 -1
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +5 -1
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +10 -3
- package/packages/server/src/identity/ws-road-classification.ts +2 -1
- package/packages/server/src/lib/browse-roots.ts +13 -2
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +304 -21
- package/packages/server/src/lib/eml.ts +2 -2
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep.ts +4 -1
- package/packages/server/src/lib/index-html.ts +2 -2
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +47 -10
- package/packages/server/src/lib/path-containment.ts +45 -12
- package/packages/server/src/lib/resolve-file-mention.ts +230 -38
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +22 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/live-server/capability-redact.ts +21 -5
- package/packages/server/src/live-server/live-capability.ts +416 -52
- package/packages/server/src/live-server/live-csp-report.ts +1 -1
- package/packages/server/src/live-server/live-csp.ts +64 -16
- package/packages/server/src/live-server/live-log.ts +5 -1
- package/packages/server/src/live-server/live-server-manager.ts +11 -0
- package/packages/server/src/live-server/live-server-proxy.ts +268 -52
- package/packages/server/src/live-server/live-static.ts +4 -1
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/package/provider-probe.ts +194 -5
- package/packages/server/src/pairing/browser-gateway.ts +140 -42
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/paired-devices.ts +370 -8
- package/packages/server/src/pairing/pairing.ts +69 -7
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +52 -2
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/host-project-trust.ts +15 -9
- package/packages/server/src/pi/pi-gateway.ts +208 -21
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +17 -6
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +23 -6
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +1 -1
- package/packages/server/src/routes/file-routes.ts +327 -86
- package/packages/server/src/routes/file-write-binary-routes.ts +20 -4
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +29 -78
- package/packages/server/src/routes/grep-routes.ts +26 -0
- package/packages/server/src/routes/live-server-routes.ts +198 -4
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/openspec-routes.ts +17 -3
- package/packages/server/src/routes/pairing-routes.ts +200 -11
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +167 -9
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/session-routes.ts +25 -22
- package/packages/server/src/routes/system-routes.ts +87 -39
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +512 -175
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/memory-session-manager.ts +24 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +22 -3
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +383 -72
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/vault/vault-delivery-hub.ts +17 -1
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +137 -57
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +73 -136
- package/packages/shared/src/containment-guard.ts +14 -4
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +1 -1
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +4 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +2 -0
- package/packages/shared/src/dashboard-plugin/slot-types.ts +1 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +11 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +20 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +1 -3
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/pairing-knock-client.ts +92 -8
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +16 -4
- package/packages/shared/src/pi-trust-mirror-types.ts +2 -0
- package/packages/shared/src/pi-trust-mirror.ts +18 -8
- package/packages/shared/src/pi-trust-resource-digest.ts +18 -12
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +404 -1
- package/packages/shared/src/platform/resolve-pi-shell.ts +38 -9
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/preview-egress.ts +56 -2
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +147 -85
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +79 -26
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +93 -3
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +94 -3
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/strategies.ts +1 -1
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +68 -109
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +10 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +0 -9
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +0 -219
|
@@ -15,14 +15,20 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import type { TLSSocket } from "node:tls";
|
|
18
|
+
import {
|
|
19
|
+
devbindMessage,
|
|
20
|
+
devcheckMessage,
|
|
21
|
+
isDevicePub,
|
|
22
|
+
} from "@blackbelt-technology/pi-dashboard-shared/device-key-proof.js";
|
|
18
23
|
import type { PairPollData } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
19
24
|
import { isTier, TIERS } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
|
|
20
25
|
import { TLS_ONLY_TOKEN_UNTRUSTED_CHANNEL } from "@blackbelt-technology/pi-dashboard-shared/tls-only-token.js";
|
|
21
26
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
22
27
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
23
28
|
import { describeApprovalRefusal } from "../auth/approval-refusal.js";
|
|
24
|
-
import { auditLine, auditPrefix, auditRequestFields } from "../auth/audit-log.js";
|
|
29
|
+
import { auditDeviceEvent, auditKeyEvent, auditLine, auditPrefix, auditRequestFields } from "../auth/audit-log.js";
|
|
25
30
|
import { parseBearerHeader, ROTATE_ROUTE } from "../auth/bearer-auth.js";
|
|
31
|
+
import { DeviceNonceStore, DeviceStatusLimiter, RevokedAnswerLog, verifyNonceProof } from "../auth/device-proof.js";
|
|
26
32
|
import { type HostAdmissionOptions, isHostAdmitted } from "../auth/host-admission.js";
|
|
27
33
|
import type { ServerIdentity } from "../auth/identity.js";
|
|
28
34
|
import { signNonce } from "../auth/identity.js";
|
|
@@ -38,8 +44,14 @@ import {
|
|
|
38
44
|
knockPeerInput,
|
|
39
45
|
knockPeerState,
|
|
40
46
|
} from "../pairing/knock-admission.js";
|
|
41
|
-
import {
|
|
42
|
-
import
|
|
47
|
+
import { createDeviceKeyIntake } from "../pairing/device-key-intake.js";
|
|
48
|
+
import {
|
|
49
|
+
BRIDGE_TOKEN_REQUIRES_HTTPS,
|
|
50
|
+
keyIdOf,
|
|
51
|
+
type PairedDeviceRegistry,
|
|
52
|
+
type PairedDeviceView,
|
|
53
|
+
} from "../pairing/paired-devices.js";
|
|
54
|
+
import type { ApprovedKeys, ApproveResult, PairingManager, PendingDeviceView } from "../pairing/pairing.js";
|
|
43
55
|
import { SUPPORTED_PAIRING_VERSIONS } from "../pairing/pairing.js";
|
|
44
56
|
import { localEndpoints } from "../tunnel/tunnel-endpoints.js";
|
|
45
57
|
import type { NetworkGuard } from "./route-deps.js";
|
|
@@ -73,6 +85,9 @@ function stripTrailingSlashes(u: string): string {
|
|
|
73
85
|
/** URL prefixes of the PUBLIC device-facing pairing routes (auth-exempt). */
|
|
74
86
|
export const PUBLIC_PAIRING_PREFIXES = [
|
|
75
87
|
"/api/pair/challenge",
|
|
88
|
+
// device-key-mutual-check (D1): answers only a signed proof of the asked-about key. NOT a string prefix of
|
|
89
|
+
// `/api/pair/device-key` (the credentialed bind route) — the auth hook matches by `startsWith`.
|
|
90
|
+
"/api/pair/device-status",
|
|
76
91
|
"/api/pair/redeem",
|
|
77
92
|
"/api/pair/poll",
|
|
78
93
|
// Device-initiated knock: public like `redeem`; the admission gates in
|
|
@@ -105,6 +120,19 @@ function approveFailure(
|
|
|
105
120
|
: { success: false, error: result.error };
|
|
106
121
|
}
|
|
107
122
|
|
|
123
|
+
/** One audit line per key / companion outcome of an approval, caused by the operator's request. */
|
|
124
|
+
function auditApprovedKeys(request: FastifyRequest, deviceId: string, keys: ApprovedKeys | undefined): void {
|
|
125
|
+
if (!keys) return;
|
|
126
|
+
if (keys.key) auditKeyEvent(keys.key.bound ? "key_bound" : "key_ignored", deviceId, keys.key.id, request);
|
|
127
|
+
if (keys.companion) auditKeyEvent(keys.companion.allowed ? "companion_allowed" : "key_ignored", deviceId, keys.companion.id, request);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Optional `allowCompanion`: absent → false; a supplied non-boolean is invalid (null). */
|
|
131
|
+
function parseAllowCompanion(v: unknown): boolean | null {
|
|
132
|
+
if (v === undefined) return false;
|
|
133
|
+
return typeof v === "boolean" ? v : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
108
136
|
/**
|
|
109
137
|
* Operator guard for the credential-bearing pairing routes (D5): mint,
|
|
110
138
|
* approve, pending list, deny, revoke.
|
|
@@ -316,6 +344,12 @@ export function registerPairingRoutes(
|
|
|
316
344
|
/** Injectable limiter / refusal logger (tests). */
|
|
317
345
|
knockLimiter?: KnockLimiter;
|
|
318
346
|
logKnockRefusal?: ReturnType<typeof createRefusalLogger>;
|
|
347
|
+
/** Injectable device-check state (tests, injected clocks). See change: device-key-mutual-check. */
|
|
348
|
+
deviceNonces?: DeviceNonceStore;
|
|
349
|
+
deviceStatusLimiter?: DeviceStatusLimiter;
|
|
350
|
+
revokedAnswerLog?: RevokedAnswerLog;
|
|
351
|
+
/** Clock for the companion `ts` window (tests). */
|
|
352
|
+
now?: () => number;
|
|
319
353
|
},
|
|
320
354
|
) {
|
|
321
355
|
const { networkGuard, identity, pairing, registry, localToken, hostAdmission } = deps;
|
|
@@ -327,6 +361,15 @@ export function registerPairingRoutes(
|
|
|
327
361
|
loginAvailable: deps.loginAvailable,
|
|
328
362
|
getConfigPort: deps.getPort,
|
|
329
363
|
});
|
|
364
|
+
const deviceNonces = deps.deviceNonces ?? new DeviceNonceStore();
|
|
365
|
+
const deviceStatusLimiter = deps.deviceStatusLimiter ?? new DeviceStatusLimiter();
|
|
366
|
+
const revokedAnswerLog = deps.revokedAnswerLog ?? new RevokedAnswerLog();
|
|
367
|
+
const keyIntake = createDeviceKeyIntake({
|
|
368
|
+
nonces: deviceNonces,
|
|
369
|
+
registry,
|
|
370
|
+
fingerprint: () => identity.fingerprint,
|
|
371
|
+
now: deps.now,
|
|
372
|
+
});
|
|
330
373
|
const knockLimiter = deps.knockLimiter ?? new KnockLimiter();
|
|
331
374
|
const logKnockRefusal = deps.logKnockRefusal ?? createRefusalLogger();
|
|
332
375
|
// Denial / lockout start the source's cooldown; approve + expiry do not (D12).
|
|
@@ -341,7 +384,10 @@ export function registerPairingRoutes(
|
|
|
341
384
|
// pinned public key and detect an impostor on a reused URL.
|
|
342
385
|
fastify.post<{ Body: { nonce?: string } }>(
|
|
343
386
|
"/api/pair/challenge",
|
|
344
|
-
async (
|
|
387
|
+
async (
|
|
388
|
+
request,
|
|
389
|
+
reply,
|
|
390
|
+
): Promise<ApiResponse<{ fingerprint: string; publicKey: string; signature: string; v: number; deviceNonce: string }>> => {
|
|
345
391
|
const nonce = request.body?.nonce;
|
|
346
392
|
if (typeof nonce !== "string" || nonce.length < 8 || nonce.length > 512) {
|
|
347
393
|
reply.code(400);
|
|
@@ -354,11 +400,70 @@ export function registerPairingRoutes(
|
|
|
354
400
|
publicKey: identity.publicKeyB64,
|
|
355
401
|
signature: signNonce(identity, nonce),
|
|
356
402
|
v: Math.max(...SUPPORTED_PAIRING_VERSIONS),
|
|
403
|
+
// Step 2 of the device check: single-use, 60 s. Never rate-limited by the status limiter.
|
|
404
|
+
deviceNonce: deviceNonces.issue(),
|
|
357
405
|
},
|
|
358
406
|
};
|
|
359
407
|
},
|
|
360
408
|
);
|
|
361
409
|
|
|
410
|
+
// ── Device check, step 2 (public): the status of the caller's OWN key ──
|
|
411
|
+
// Verify-before-lookup. Every failure — bad shape, bad signature, unknown / expired / used nonce,
|
|
412
|
+
// rate limit, even an unparseable body — is the same `{"status":"unverified"}` at HTTP 200, so the
|
|
413
|
+
// reply never says whether a key exists. See change: device-key-mutual-check (D1, D2).
|
|
414
|
+
const UNVERIFIED = { status: "unverified" } as const;
|
|
415
|
+
fastify.post<{ Body: unknown }>(
|
|
416
|
+
"/api/pair/device-status",
|
|
417
|
+
{
|
|
418
|
+
errorHandler: (_err, _request, reply) => {
|
|
419
|
+
reply.header("Cache-Control", "no-store").code(200).send(UNVERIFIED);
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
async (request, reply) => {
|
|
423
|
+
reply.header("Cache-Control", "no-store");
|
|
424
|
+
// Socket peer, like the knock admission — never `request.ip`.
|
|
425
|
+
if (!deviceStatusLimiter.allow(request.socket.remoteAddress ?? "unknown")) return UNVERIFIED;
|
|
426
|
+
const body = request.body;
|
|
427
|
+
const fields = body !== null && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
428
|
+
if (!verifyNonceProof(deviceNonces, fields, (n) => devcheckMessage(identity.fingerprint, n))) return UNVERIFIED;
|
|
429
|
+
const answer = registry.deviceKeyStatus(fields.pub as string);
|
|
430
|
+
revokedAnswerLog.note(keyIdOf(fields.pub as string), answer.status);
|
|
431
|
+
return answer;
|
|
432
|
+
},
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
// ── Credentialed device: bind / replace its own key (D3) ───────────────
|
|
436
|
+
// Only the device's OWN credential (bearer or cookie → `authVia === "device"`), at any tier. No
|
|
437
|
+
// `networkGuard`: the device credential itself is the stricter condition and anonymous is 401 here.
|
|
438
|
+
fastify.post<{ Body: unknown }>(
|
|
439
|
+
"/api/pair/device-key",
|
|
440
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
441
|
+
const authed = request as { authVia?: string; principalDeviceId?: string };
|
|
442
|
+
if (authed.authVia !== "device" || typeof authed.principalDeviceId !== "string") {
|
|
443
|
+
reply.code(401);
|
|
444
|
+
return { success: false, error: "device credential required" };
|
|
445
|
+
}
|
|
446
|
+
const body = request.body;
|
|
447
|
+
const fields = body !== null && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
448
|
+
if (!verifyNonceProof(deviceNonces, fields, (n) => devbindMessage(identity.fingerprint, n))) {
|
|
449
|
+
reply.code(400);
|
|
450
|
+
return { success: false, error: "invalid_device_key_proof" };
|
|
451
|
+
}
|
|
452
|
+
const pub = fields.pub as string;
|
|
453
|
+
const result = registry.bindKey(authed.principalDeviceId, pub);
|
|
454
|
+
if (result === "held") {
|
|
455
|
+
reply.code(409);
|
|
456
|
+
return { success: false, error: "key_held" };
|
|
457
|
+
}
|
|
458
|
+
if (result === "no-device") {
|
|
459
|
+
reply.code(401);
|
|
460
|
+
return { success: false, error: "device credential required" };
|
|
461
|
+
}
|
|
462
|
+
auditKeyEvent(result === "replaced" ? "key_replaced" : "key_bound", authed.principalDeviceId, keyIdOf(pub), request);
|
|
463
|
+
return { success: true };
|
|
464
|
+
},
|
|
465
|
+
);
|
|
466
|
+
|
|
362
467
|
// ── Dashboard: mint a pairing payload (authenticated) — Task 2.3 ───────
|
|
363
468
|
fastify.get(
|
|
364
469
|
"/api/pair/payload",
|
|
@@ -376,7 +481,7 @@ export function registerPairingRoutes(
|
|
|
376
481
|
);
|
|
377
482
|
|
|
378
483
|
// ── Device: redeem a code → pending device + confirm code (public) ─────
|
|
379
|
-
fastify.post<{ Body: { code?: string; holder?: unknown } }>(
|
|
484
|
+
fastify.post<{ Body: { code?: string; holder?: unknown; deviceKey?: unknown } }>(
|
|
380
485
|
"/api/pair/redeem",
|
|
381
486
|
async (request, reply): Promise<ApiResponse<{ pendingId: string; confirmCode: string }>> => {
|
|
382
487
|
const code = request.body?.code;
|
|
@@ -384,9 +489,13 @@ export function registerPairingRoutes(
|
|
|
384
489
|
reply.code(400);
|
|
385
490
|
return { success: false, error: "code required" };
|
|
386
491
|
}
|
|
492
|
+
// The device key (if any) is verified and its nonce consumed on ARRIVAL; an invalid / held key is
|
|
493
|
+
// dropped silently and the response is unchanged. See change: device-key-mutual-check (D3).
|
|
494
|
+
const { deviceKey } = keyIntake.accept({ deviceKey: request.body?.deviceKey });
|
|
387
495
|
// Redeemer metadata is untrusted display text for the operator dialog;
|
|
388
496
|
// the manager bounds it and never uses it for a decision (D4).
|
|
389
497
|
const result = pairing.redeem(code, {
|
|
498
|
+
...(deviceKey ? { deviceKey } : {}),
|
|
390
499
|
userAgent: headerString(request.headers["user-agent"]),
|
|
391
500
|
host: headerString(request.headers.host),
|
|
392
501
|
remoteAddress: request.ip,
|
|
@@ -409,7 +518,7 @@ export function registerPairingRoutes(
|
|
|
409
518
|
// semantics), the LAN gates, the switch and the limits. Admission uses the
|
|
410
519
|
// SOCKET peer address — never `request.ip` — and that same address is recorded
|
|
411
520
|
// as the pending device's remote address.
|
|
412
|
-
fastify.post<{ Body: { name?: unknown; holder?: unknown } | null }>(
|
|
521
|
+
fastify.post<{ Body: { name?: unknown; holder?: unknown; deviceKey?: unknown; companion?: unknown } | null }>(
|
|
413
522
|
"/api/pair/request",
|
|
414
523
|
async (
|
|
415
524
|
request,
|
|
@@ -447,6 +556,8 @@ export function registerPairingRoutes(
|
|
|
447
556
|
? { success: false, error: decision.error }
|
|
448
557
|
: { success: false, error: decision.error, retryAfter: decision.retryAfter };
|
|
449
558
|
}
|
|
559
|
+
// Verified only for an ADMITTED knock, on arrival; invalid / replayed / held → dropped silently.
|
|
560
|
+
const keys = keyIntake.accept(request.body);
|
|
450
561
|
const result = pairing.knock({
|
|
451
562
|
sourceKey: decision.sourceKey,
|
|
452
563
|
name: request.body?.name,
|
|
@@ -456,6 +567,7 @@ export function registerPairingRoutes(
|
|
|
456
567
|
host: headerString(request.headers.host),
|
|
457
568
|
remoteAddress: decision.sourceKey,
|
|
458
569
|
holder: request.body?.holder,
|
|
570
|
+
...keys,
|
|
459
571
|
},
|
|
460
572
|
});
|
|
461
573
|
return {
|
|
@@ -476,7 +588,7 @@ export function registerPairingRoutes(
|
|
|
476
588
|
// could mint a second durable token that survives its own revocation
|
|
477
589
|
// (CodeRabbit CWE-862). `operatorGuard` admits only a dashboard login session,
|
|
478
590
|
// the local token, or a genuinely-local caller.
|
|
479
|
-
fastify.post<{ Body: { code?: string; confirmCode?: string; label?: string; tier?: unknown } }>(
|
|
591
|
+
fastify.post<{ Body: { code?: string; confirmCode?: string; label?: string; tier?: unknown; allowCompanion?: unknown } }>(
|
|
480
592
|
"/api/pair/approve",
|
|
481
593
|
{ preHandler: approvalGuard },
|
|
482
594
|
async (request, reply): Promise<ApiResponse<PairedDeviceView>> => {
|
|
@@ -508,7 +620,12 @@ export function registerPairingRoutes(
|
|
|
508
620
|
}
|
|
509
621
|
label = trimmed;
|
|
510
622
|
}
|
|
511
|
-
const
|
|
623
|
+
const allowCompanion = parseAllowCompanion(request.body?.allowCompanion);
|
|
624
|
+
if (allowCompanion === null) {
|
|
625
|
+
reply.code(400);
|
|
626
|
+
return { success: false, error: "allowCompanion must be a boolean" };
|
|
627
|
+
}
|
|
628
|
+
const result = pairing.approve(code, confirmCode, label, isTier(tier) ? tier : undefined, { allowCompanion });
|
|
512
629
|
if (!result.ok) {
|
|
513
630
|
// Status codes unchanged for this route (no_pending stays 400); a
|
|
514
631
|
// mismatch additionally carries `attemptsLeft` (additive, D2).
|
|
@@ -517,6 +634,7 @@ export function registerPairingRoutes(
|
|
|
517
634
|
? ({ success: false, error: result.error, attemptsLeft: result.attemptsLeft } as ApiResponse<PairedDeviceView>)
|
|
518
635
|
: { success: false, error: result.error };
|
|
519
636
|
}
|
|
637
|
+
auditApprovedKeys(request, result.device.id, result.keys);
|
|
520
638
|
return { success: true, data: result.device };
|
|
521
639
|
},
|
|
522
640
|
);
|
|
@@ -531,7 +649,9 @@ export function registerPairingRoutes(
|
|
|
531
649
|
);
|
|
532
650
|
|
|
533
651
|
// ── Dashboard: approve by pendingId (typed confirm code, operator-only) ─
|
|
534
|
-
fastify.post<{
|
|
652
|
+
fastify.post<{
|
|
653
|
+
Body: { pendingId?: unknown; confirmCode?: unknown; label?: unknown; tier?: unknown; allowCompanion?: unknown };
|
|
654
|
+
}>(
|
|
535
655
|
"/api/pair/approve-pending",
|
|
536
656
|
{ preHandler: approvalGuard },
|
|
537
657
|
async (request, reply): Promise<ApiResponse<PairedDeviceView> & { attemptsLeft?: number }> => {
|
|
@@ -553,8 +673,15 @@ export function registerPairingRoutes(
|
|
|
553
673
|
reply.code(400);
|
|
554
674
|
return { success: false, error: `label must be 1..${MAX_DEVICE_LABEL_BYTES} UTF-8 bytes` };
|
|
555
675
|
}
|
|
556
|
-
|
|
676
|
+
// Opt-in, default off: the companion is stored only when the operator ticked the box.
|
|
677
|
+
const allowCompanion = parseAllowCompanion(request.body?.allowCompanion);
|
|
678
|
+
if (allowCompanion === null) {
|
|
679
|
+
reply.code(400);
|
|
680
|
+
return { success: false, error: "allowCompanion must be a boolean" };
|
|
681
|
+
}
|
|
682
|
+
const result = pairing.approvePending(pendingId, confirmCode, name, isTier(tier) ? tier : undefined, { allowCompanion });
|
|
557
683
|
if (!result.ok) return approveFailure(result, reply);
|
|
684
|
+
auditApprovedKeys(request, result.device.id, result.keys);
|
|
558
685
|
return { success: true, data: result.device };
|
|
559
686
|
},
|
|
560
687
|
);
|
|
@@ -624,7 +751,7 @@ export function registerPairingRoutes(
|
|
|
624
751
|
"/api/paired-devices/:id",
|
|
625
752
|
{ preHandler: operatorGuard },
|
|
626
753
|
async (request, reply): Promise<ApiResponse> => {
|
|
627
|
-
const removed = registry.revoke(request.params.id);
|
|
754
|
+
const removed = registry.revoke(request.params.id, auditRequestFields(request).actor);
|
|
628
755
|
if (!removed) {
|
|
629
756
|
reply.code(404);
|
|
630
757
|
return { success: false, error: "device not found" };
|
|
@@ -635,6 +762,68 @@ export function registerPairingRoutes(
|
|
|
635
762
|
},
|
|
636
763
|
);
|
|
637
764
|
|
|
765
|
+
// ── Held (revoked) devices: operator-only list / restore / delete-now (D6) ─
|
|
766
|
+
// Static `revoked` segments win over `:id` in Fastify's router. A device bearer is refused 401 by
|
|
767
|
+
// `operatorGuard`. Audit lines only after a successful change (never on 404 / 409).
|
|
768
|
+
fastify.get(
|
|
769
|
+
"/api/paired-devices/revoked",
|
|
770
|
+
{ preHandler: operatorGuard },
|
|
771
|
+
async (): Promise<ApiResponse<ReturnType<PairedDeviceRegistry["listRevoked"]>["devices"]> & { warning?: "unreadable" }> => {
|
|
772
|
+
const { devices, warning } = registry.listRevoked();
|
|
773
|
+
return { success: true, data: devices, ...(warning ? { warning } : {}) };
|
|
774
|
+
},
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
fastify.post<{ Params: { id: string } }>(
|
|
778
|
+
"/api/paired-devices/:id/restore",
|
|
779
|
+
{ preHandler: operatorGuard },
|
|
780
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
781
|
+
const result = registry.restore(request.params.id);
|
|
782
|
+
if (result === "not-found") {
|
|
783
|
+
reply.code(404);
|
|
784
|
+
return { success: false, error: "device not found" };
|
|
785
|
+
}
|
|
786
|
+
if (result === "active") {
|
|
787
|
+
reply.code(409);
|
|
788
|
+
return { success: false, error: "device_active" };
|
|
789
|
+
}
|
|
790
|
+
auditDeviceEvent("restored", request.params.id, request);
|
|
791
|
+
return { success: true };
|
|
792
|
+
},
|
|
793
|
+
);
|
|
794
|
+
|
|
795
|
+
fastify.delete<{ Params: { id: string } }>(
|
|
796
|
+
"/api/paired-devices/revoked/:id",
|
|
797
|
+
{ preHandler: operatorGuard },
|
|
798
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
799
|
+
const result = registry.deleteRevoked(request.params.id);
|
|
800
|
+
if (result === "not-found") {
|
|
801
|
+
reply.code(404);
|
|
802
|
+
return { success: false, error: "device not found" };
|
|
803
|
+
}
|
|
804
|
+
if (result === "active") {
|
|
805
|
+
reply.code(409);
|
|
806
|
+
return { success: false, error: "device_active" };
|
|
807
|
+
}
|
|
808
|
+
auditDeviceEvent("deleted", request.params.id, request);
|
|
809
|
+
return { success: true };
|
|
810
|
+
},
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
// Remove ONE companion key of an active device (the operator's "Remove"). Keyed by the short key id.
|
|
814
|
+
fastify.delete<{ Params: { id: string; companionId: string } }>(
|
|
815
|
+
"/api/paired-devices/:id/companions/:companionId",
|
|
816
|
+
{ preHandler: operatorGuard },
|
|
817
|
+
async (request, reply): Promise<ApiResponse> => {
|
|
818
|
+
if (!registry.removeCompanion(request.params.id, request.params.companionId)) {
|
|
819
|
+
reply.code(404);
|
|
820
|
+
return { success: false, error: "companion not found" };
|
|
821
|
+
}
|
|
822
|
+
auditKeyEvent("companion_removed", request.params.id, request.params.companionId, request);
|
|
823
|
+
return { success: true };
|
|
824
|
+
},
|
|
825
|
+
);
|
|
826
|
+
|
|
638
827
|
// ── Browser device: rotate its own bearer (bearer-only credential) ────
|
|
639
828
|
registerBearerRotateRoute(fastify, { registry });
|
|
640
829
|
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
readPiSettings,
|
|
51
51
|
writePiSettingsRaw,
|
|
52
52
|
} from "../pi-agent-settings.js";
|
|
53
|
+
import { notePiMirrorWrite } from "../pi-default-remirror.js";
|
|
53
54
|
import { createThemeLister, type ScanThemes } from "../pi-settings-themes.js";
|
|
54
55
|
import type { NetworkGuard } from "./route-deps.js";
|
|
55
56
|
|
|
@@ -223,6 +224,7 @@ export function registerPiSettingsRoutes(
|
|
|
223
224
|
return { success: false, error: mirror.error ?? "io" };
|
|
224
225
|
}
|
|
225
226
|
logWrite("sync-defaults", "ok");
|
|
227
|
+
notePiMirrorWrite(); // See change: default-model-follows-role (D4).
|
|
226
228
|
const s = readPiSettings(fsDeps);
|
|
227
229
|
return {
|
|
228
230
|
success: true,
|
|
@@ -17,6 +17,7 @@ import type { PiGateway } from "../pi/pi-gateway.js";
|
|
|
17
17
|
import type { PreferencesStore } from "../persistence/preferences-store.js";
|
|
18
18
|
import type { NetworkGuard } from "./route-deps.js";
|
|
19
19
|
import { autoNameOutcomes } from "../auto-name-outcome-store.js";
|
|
20
|
+
import { buildPreferencesUpdate } from "../preferences-relay.js";
|
|
20
21
|
|
|
21
22
|
export function registerPreferencesAutoNameRoutes(
|
|
22
23
|
fastify: FastifyInstance,
|
|
@@ -58,8 +59,10 @@ export function registerPreferencesAutoNameRoutes(
|
|
|
58
59
|
return reply.code(400).send({ error: "Invalid body: expected { value: boolean }" });
|
|
59
60
|
}
|
|
60
61
|
preferencesStore.setAutoNameSessions(body.value);
|
|
61
|
-
// Relay to every connected bridge so live
|
|
62
|
-
|
|
62
|
+
// Relay the full preferences snapshot to every connected bridge so live
|
|
63
|
+
// sessions pick up the change without resetting other values.
|
|
64
|
+
// See change: retire-anthropic-messages-bridge (design D3).
|
|
65
|
+
piGateway.broadcast(buildPreferencesUpdate(preferencesStore));
|
|
63
66
|
return { autoNameSessions: preferencesStore.getAutoNameSessions() };
|
|
64
67
|
},
|
|
65
68
|
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude subscription compat switch REST routes.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/preferences/claude-subscription-compat → { claudeSubscriptionCompat: boolean }
|
|
5
|
+
* PATCH /api/preferences/claude-subscription-compat { value } → { claudeSubscriptionCompat: boolean }
|
|
6
|
+
*
|
|
7
|
+
* Persisted via the preferences store (preferences.json, default false). On
|
|
8
|
+
* change the full preferences snapshot is broadcast to every connected bridge
|
|
9
|
+
* as `preferences_update`, so the flows-plugin bridge applies the docs-section
|
|
10
|
+
* rewrite on the next agent run without a session restart.
|
|
11
|
+
*
|
|
12
|
+
* See change: retire-anthropic-messages-bridge.
|
|
13
|
+
*/
|
|
14
|
+
import type { FastifyInstance } from "fastify";
|
|
15
|
+
import type { PiGateway } from "../pi/pi-gateway.js";
|
|
16
|
+
import type { PreferencesStore } from "../persistence/preferences-store.js";
|
|
17
|
+
import { buildPreferencesUpdate } from "../preferences-relay.js";
|
|
18
|
+
import type { NetworkGuard } from "./route-deps.js";
|
|
19
|
+
|
|
20
|
+
export function registerPreferencesClaudeCompatRoutes(
|
|
21
|
+
fastify: FastifyInstance,
|
|
22
|
+
deps: {
|
|
23
|
+
preferencesStore: PreferencesStore;
|
|
24
|
+
piGateway: Pick<PiGateway, "broadcast">;
|
|
25
|
+
networkGuard: NetworkGuard;
|
|
26
|
+
},
|
|
27
|
+
): void {
|
|
28
|
+
const { preferencesStore, piGateway, networkGuard } = deps;
|
|
29
|
+
|
|
30
|
+
fastify.get(
|
|
31
|
+
"/api/preferences/claude-subscription-compat",
|
|
32
|
+
{ preHandler: networkGuard },
|
|
33
|
+
async () => ({ claudeSubscriptionCompat: preferencesStore.getClaudeSubscriptionCompat() }),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
fastify.patch<{ Body: { value?: unknown } }>(
|
|
37
|
+
"/api/preferences/claude-subscription-compat",
|
|
38
|
+
{ preHandler: networkGuard },
|
|
39
|
+
async (request, reply) => {
|
|
40
|
+
const body = request.body;
|
|
41
|
+
if (!body || typeof body !== "object" || typeof body.value !== "boolean") {
|
|
42
|
+
return reply.code(400).send({ error: "Invalid body: expected { value: boolean }" });
|
|
43
|
+
}
|
|
44
|
+
preferencesStore.setClaudeSubscriptionCompat(body.value);
|
|
45
|
+
piGateway.broadcast(buildPreferencesUpdate(preferencesStore));
|
|
46
|
+
return { claudeSubscriptionCompat: preferencesStore.getClaudeSubscriptionCompat() };
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
}
|