@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +47 -6
  3. package/docs/architecture.md +1369 -63
  4. package/package.json +14 -9
  5. package/packages/extension/package.json +5 -3
  6. package/packages/extension/src/bridge-handlers/dispatch.ts +57 -3
  7. package/packages/extension/src/bridge-handlers/instance.ts +10 -1
  8. package/packages/extension/src/bridge-handlers/lifecycle.ts +65 -26
  9. package/packages/extension/src/bridge-ticket-client.ts +61 -7
  10. package/packages/extension/src/bridge-tls-checks.ts +79 -0
  11. package/packages/extension/src/bridge.ts +41 -28
  12. package/packages/extension/src/canvas-tool.ts +2 -0
  13. package/packages/extension/src/command-handler.ts +80 -6
  14. package/packages/extension/src/connect-target.ts +23 -0
  15. package/packages/extension/src/connection.ts +30 -7
  16. package/packages/extension/src/dashboard-http-origin.ts +88 -0
  17. package/packages/extension/src/dev-build.ts +11 -1
  18. package/packages/extension/src/git-link-builder.ts +11 -2
  19. package/packages/extension/src/inbound-limits.ts +138 -0
  20. package/packages/extension/src/local-token-header.ts +77 -6
  21. package/packages/extension/src/model-refresh.ts +69 -0
  22. package/packages/extension/src/pinned-endpoint.ts +44 -0
  23. package/packages/extension/src/project-trust-live.ts +143 -0
  24. package/packages/extension/src/project-trust.ts +159 -20
  25. package/packages/extension/src/provider-register.ts +59 -18
  26. package/packages/extension/src/remote-registration-gate.ts +21 -21
  27. package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
  28. package/packages/extension/src/role-model-tools.ts +47 -6
  29. package/packages/extension/src/server-auto-start.ts +1 -1
  30. package/packages/extension/src/server-proof-probe.ts +117 -0
  31. package/packages/extension/src/session-sync.ts +42 -12
  32. package/packages/extension/src/vault-delivery.ts +11 -1
  33. package/packages/server/package.json +8 -8
  34. package/packages/server/src/access/access-grants.ts +61 -8
  35. package/packages/server/src/access/access-health.ts +10 -0
  36. package/packages/server/src/access/access-plane.ts +5 -1
  37. package/packages/server/src/access/containment-gate.ts +55 -17
  38. package/packages/server/src/access/cwd-verdict.ts +3 -3
  39. package/packages/server/src/access/pi-trust-live.ts +244 -0
  40. package/packages/server/src/access/pi-trust-mirror-service.ts +44 -11
  41. package/packages/server/src/access/planes.ts +106 -1
  42. package/packages/server/src/access/preview-egress-store.ts +153 -0
  43. package/packages/server/src/access/prompt-channel.ts +5 -0
  44. package/packages/server/src/access/provisioning-wiring.ts +113 -0
  45. package/packages/server/src/access/provisioning.ts +763 -0
  46. package/packages/server/src/access/yolo-session.ts +54 -2
  47. package/packages/server/src/acp-bridge/acp-session-adapter.ts +8 -3
  48. package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
  49. package/packages/server/src/auth/audit-log.ts +80 -0
  50. package/packages/server/src/auth/auth-plugin.ts +44 -25
  51. package/packages/server/src/auth/auth.ts +24 -4
  52. package/packages/server/src/auth/bearer-auth.ts +52 -12
  53. package/packages/server/src/auth/cors-origin.ts +76 -29
  54. package/packages/server/src/auth/csp-report-paths.ts +31 -0
  55. package/packages/server/src/auth/csp-report-sink.ts +302 -0
  56. package/packages/server/src/auth/csp-report-store.ts +406 -0
  57. package/packages/server/src/auth/csp.ts +105 -9
  58. package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
  59. package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
  60. package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
  61. package/packages/server/src/auth/local-proof.ts +69 -18
  62. package/packages/server/src/auth/localhost-guard.ts +48 -10
  63. package/packages/server/src/auth/nav-intent.ts +72 -0
  64. package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
  65. package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
  66. package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
  67. package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
  68. package/packages/server/src/auth/plugin-server-trust.ts +29 -0
  69. package/packages/server/src/auth/plugin-trust-store.ts +103 -0
  70. package/packages/server/src/auth/proven-tls.ts +45 -0
  71. package/packages/server/src/auth/provider-auth-storage.ts +6 -1
  72. package/packages/server/src/auth/radius-mcp.ts +1 -1
  73. package/packages/server/src/auth/request-principal.ts +32 -0
  74. package/packages/server/src/auth/secret-rotation.ts +246 -0
  75. package/packages/server/src/auth/secure-origin.ts +56 -0
  76. package/packages/server/src/auth/serve-app-host.ts +111 -11
  77. package/packages/server/src/auth/ws-ticket.ts +39 -1
  78. package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
  79. package/packages/server/src/browser-handlers/directory-handler.ts +23 -0
  80. package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
  81. package/packages/server/src/browser-handlers/handler-context.ts +25 -2
  82. package/packages/server/src/browser-handlers/session-action-handler.ts +9 -1
  83. package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
  84. package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
  85. package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
  86. package/packages/server/src/cli.ts +210 -39
  87. package/packages/server/src/config-api.ts +23 -1
  88. package/packages/server/src/config-snapshot.ts +48 -1
  89. package/packages/server/src/directory-service.ts +160 -54
  90. package/packages/server/src/event-wiring.ts +143 -108
  91. package/packages/server/src/git-worktree/git-operations.ts +44 -10
  92. package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
  93. package/packages/server/src/git-worktree/ref-arg.ts +39 -0
  94. package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
  95. package/packages/server/src/identity/http-road-classification.ts +13 -1
  96. package/packages/server/src/identity/ws-message-scope.ts +1 -0
  97. package/packages/server/src/identity/ws-road-classification.ts +1 -0
  98. package/packages/server/src/known-server-moves.ts +36 -15
  99. package/packages/server/src/lib/browse-roots.ts +118 -17
  100. package/packages/server/src/lib/client-dist.ts +36 -21
  101. package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
  102. package/packages/server/src/lib/diagram-render.ts +4 -6
  103. package/packages/server/src/lib/eml.ts +3 -8
  104. package/packages/server/src/lib/file-cwd-admission.ts +145 -0
  105. package/packages/server/src/lib/grep-worker.ts +23 -0
  106. package/packages/server/src/lib/grep.ts +93 -7
  107. package/packages/server/src/lib/index-html.ts +81 -0
  108. package/packages/server/src/lib/office-preview.ts +2 -3
  109. package/packages/server/src/lib/path-containment.ts +7 -0
  110. package/packages/server/src/lib/resolve-file-mention.ts +11 -9
  111. package/packages/server/src/lib/route-admission.ts +80 -0
  112. package/packages/server/src/lib/writable-md-target.ts +4 -0
  113. package/packages/server/src/lifecycle/recovery-server.ts +65 -18
  114. package/packages/server/src/live-server/capability-redact.ts +15 -0
  115. package/packages/server/src/live-server/live-browser-gate.ts +22 -0
  116. package/packages/server/src/live-server/live-capability.ts +224 -17
  117. package/packages/server/src/live-server/live-csp-report.ts +63 -0
  118. package/packages/server/src/live-server/live-csp.ts +93 -0
  119. package/packages/server/src/live-server/live-egress.ts +435 -0
  120. package/packages/server/src/live-server/live-exposure.ts +149 -0
  121. package/packages/server/src/live-server/live-log.ts +21 -0
  122. package/packages/server/src/live-server/live-origin-scan.ts +298 -0
  123. package/packages/server/src/live-server/live-server-manager.ts +209 -33
  124. package/packages/server/src/live-server/live-server-proxy.ts +162 -17
  125. package/packages/server/src/live-server/live-static.ts +228 -0
  126. package/packages/server/src/openspec/dependencies-file.ts +122 -0
  127. package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
  128. package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
  129. package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
  130. package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
  131. package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
  132. package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
  133. package/packages/server/src/openspec/workflow-schema.ts +141 -267
  134. package/packages/server/src/package/npm-search-proxy.ts +5 -2
  135. package/packages/server/src/package/provider-probe.ts +8 -2
  136. package/packages/server/src/pairing/browser-gateway.ts +188 -12
  137. package/packages/server/src/pairing/device-token-services.ts +26 -0
  138. package/packages/server/src/pairing/paired-devices.ts +335 -22
  139. package/packages/server/src/pairing/pairing.ts +34 -4
  140. package/packages/server/src/pairing/socket-locality.ts +26 -0
  141. package/packages/server/src/persistence/preferences-store.ts +9 -0
  142. package/packages/server/src/pi/bridge-channel.ts +33 -0
  143. package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
  144. package/packages/server/src/pi/gateway-listeners.ts +9 -3
  145. package/packages/server/src/pi/host-project-trust.ts +14 -6
  146. package/packages/server/src/pi/pi-gateway.ts +191 -21
  147. package/packages/server/src/pi/resource-toggle-trust.ts +1 -1
  148. package/packages/server/src/plugin-discovery-wiring.ts +142 -0
  149. package/packages/server/src/plugin-event-seam.ts +116 -4
  150. package/packages/server/src/plugin-runtime-clients.ts +89 -0
  151. package/packages/server/src/routes/access-routes.ts +159 -9
  152. package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
  153. package/packages/server/src/routes/canvas-types-routes.ts +20 -6
  154. package/packages/server/src/routes/csp-violations-routes.ts +162 -0
  155. package/packages/server/src/routes/file-routes.ts +329 -209
  156. package/packages/server/src/routes/file-write-binary-routes.ts +77 -20
  157. package/packages/server/src/routes/folder-project-routes.ts +18 -12
  158. package/packages/server/src/routes/git-routes.ts +319 -203
  159. package/packages/server/src/routes/grep-routes.ts +38 -14
  160. package/packages/server/src/routes/known-servers-routes.ts +189 -91
  161. package/packages/server/src/routes/live-server-routes.ts +378 -15
  162. package/packages/server/src/routes/local-proof-routes.ts +14 -0
  163. package/packages/server/src/routes/nav-intent-routes.ts +46 -0
  164. package/packages/server/src/routes/openspec-group-routes.ts +53 -44
  165. package/packages/server/src/routes/openspec-routes.ts +379 -28
  166. package/packages/server/src/routes/package-routes.ts +58 -10
  167. package/packages/server/src/routes/pairing-routes.ts +146 -10
  168. package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
  169. package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
  170. package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
  171. package/packages/server/src/routes/provider-auth-routes.ts +15 -2
  172. package/packages/server/src/routes/resource-activation-routes.ts +18 -4
  173. package/packages/server/src/routes/session-routes.ts +51 -4
  174. package/packages/server/src/routes/system-routes.ts +84 -15
  175. package/packages/server/src/routes/ui-link-base.ts +88 -0
  176. package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
  177. package/packages/server/src/server.ts +648 -137
  178. package/packages/server/src/session/hydration-state.ts +148 -0
  179. package/packages/server/src/session/memory-session-manager.ts +7 -0
  180. package/packages/server/src/session/replay-exit-controller.ts +221 -0
  181. package/packages/server/src/session/retained-transcript.ts +9 -2
  182. package/packages/server/src/session/session-load-worker.ts +11 -2
  183. package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
  184. package/packages/server/src/terminal/terminal-manager.ts +54 -46
  185. package/packages/server/src/tls/tls-bridge-route.ts +61 -0
  186. package/packages/server/src/tls/tls-config-validation.ts +2 -0
  187. package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
  188. package/packages/server/src/vault/vault-delivery-hub.ts +155 -25
  189. package/packages/server/src/watch-files-handler.ts +66 -0
  190. package/packages/shared/package.json +1 -1
  191. package/packages/shared/src/browser-protocol.ts +148 -2
  192. package/packages/shared/src/canvas-declare.ts +27 -0
  193. package/packages/shared/src/config.ts +372 -53
  194. package/packages/shared/src/containment-guard.ts +35 -0
  195. package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
  196. package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
  197. package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
  198. package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
  199. package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
  200. package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
  201. package/packages/shared/src/dashboard-plugin/index.ts +2 -0
  202. package/packages/shared/src/dashboard-plugin/manifest-types.ts +54 -1
  203. package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
  204. package/packages/shared/src/dashboard-plugin/slot-props.ts +45 -3
  205. package/packages/shared/src/dashboard-plugin/slot-types.ts +8 -0
  206. package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
  207. package/packages/shared/src/dashboard-plugin/ui-primitives.ts +28 -0
  208. package/packages/shared/src/display-prefs.ts +13 -0
  209. package/packages/shared/src/doctor-core.ts +94 -27
  210. package/packages/shared/src/live-server.ts +141 -0
  211. package/packages/shared/src/local-proof-signal.ts +16 -0
  212. package/packages/shared/src/loopback-host.ts +26 -0
  213. package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
  214. package/packages/shared/src/mdns-discovery.ts +25 -6
  215. package/packages/shared/src/nav-intent.ts +29 -0
  216. package/packages/shared/src/openspec-dependencies.ts +760 -0
  217. package/packages/shared/src/openspec-poller.ts +3 -2
  218. package/packages/shared/src/pairing-knock-client.ts +44 -4
  219. package/packages/shared/src/pi-trust-live-query.ts +93 -0
  220. package/packages/shared/src/pi-trust-mirror-snapshot.ts +5 -7
  221. package/packages/shared/src/pi-trust-mirror-types.ts +36 -3
  222. package/packages/shared/src/pi-trust-mirror.ts +29 -3
  223. package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
  224. package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
  225. package/packages/shared/src/platform/git-source.ts +88 -26
  226. package/packages/shared/src/platform/git.ts +14 -8
  227. package/packages/shared/src/platform/process.ts +48 -4
  228. package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
  229. package/packages/shared/src/platform/select-git-source.ts +7 -0
  230. package/packages/shared/src/plugin-route-cwd.ts +95 -0
  231. package/packages/shared/src/preview-egress.ts +138 -0
  232. package/packages/shared/src/project-root.ts +16 -0
  233. package/packages/shared/src/protocol.ts +40 -1
  234. package/packages/shared/src/recommended-extensions.ts +18 -0
  235. package/packages/shared/src/recovery-timing.ts +27 -0
  236. package/packages/shared/src/remote-credentials.ts +63 -0
  237. package/packages/shared/src/rest-api.ts +55 -8
  238. package/packages/shared/src/route-tiers.ts +55 -1
  239. package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
  240. package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
  241. package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
  242. package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
  243. package/packages/shared/src/safe-local-path.ts +24 -0
  244. package/packages/shared/src/sanitize-profiles.ts +98 -0
  245. package/packages/shared/src/server-launcher.ts +9 -1
  246. package/packages/shared/src/server-pinning.ts +55 -2
  247. package/packages/shared/src/server-routes.ts +462 -0
  248. package/packages/shared/src/session-ui-path.ts +11 -0
  249. package/packages/shared/src/tls-only-token.ts +16 -0
  250. package/packages/shared/src/tool-registry/definitions.ts +5 -5
  251. package/packages/shared/src/tool-registry/strategies.ts +12 -11
  252. package/packages/shared/src/types.ts +66 -0
  253. package/packages/shared/src/url-policy.ts +96 -0
  254. package/packages/shared/src/vault-delivery.ts +15 -0
  255. package/packages/shared/src/ws-message-tiers.ts +1 -0
@@ -14,9 +14,12 @@ import path from "node:path";
14
14
  import {
15
15
  defaultTierForSource,
16
16
  isTier,
17
- type Tier,
18
17
  TIERS,
18
+ type Tier,
19
19
  } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
20
+ import { TLS_ONLY_TOKEN_PREFIX, isTlsOnlyToken } from "@blackbelt-technology/pi-dashboard-shared/tls-only-token.js";
21
+ import { auditLine, auditPrefix } from "../auth/audit-log.js";
22
+ import { type BearerChannel, isProvenChannel } from "../auth/proven-tls.js";
20
23
  import { readJsonFile, writeJsonFile } from "../persistence/json-store.js";
21
24
 
22
25
  const REGISTRY_FILENAME = "paired-devices.json";
@@ -25,6 +28,16 @@ const TOKEN_BYTES = 32; // 256-bit opaque bearer.
25
28
  // rewrite the registry file (write amplification). Coarse last-seen is fine.
26
29
  const LAST_SEEN_PERSIST_INTERVAL_MS = 60_000;
27
30
 
31
+ /** Browser-held bearer lifetime from issuance (matches the session cookie). */
32
+ const BROWSER_BEARER_TTL_MS = 7 * 24 * 60 * 60 * 1000;
33
+ /** Absolute lifetime of a browser-held row from original pairing (theft ceiling). */
34
+ const BROWSER_BEARER_CEILING_MS = 30 * 24 * 60 * 60 * 1000;
35
+ /** How long the immediately-previous bearer stays valid after a rotation. */
36
+ const ROTATION_GRACE_MS = 60_000;
37
+ /** Rotations allowed per device inside the sliding window. */
38
+ const ROTATE_LIMIT = 10;
39
+ const ROTATE_WINDOW_MS = 60_000;
40
+
28
41
  export interface PairedDevice {
29
42
  /** Stable per-device id. */
30
43
  id: string;
@@ -44,6 +57,69 @@ export interface PairedDevice {
44
57
  * D1). Rows written before the field existed read as `"operate"` — they
45
58
  * were minted with full access and keep it. */
46
59
  tier: Tier;
60
+ /**
61
+ * Browser-held bearer expiry, epoch ms. Absent / null = non-expiring (every
62
+ * legacy row, keyring/CLI/manual). A present value that is not a finite
63
+ * number > 0 is malformed and fails closed (treated as expired).
64
+ * See change: harden-auth-credentials (D5).
65
+ */
66
+ expiresAt?: number | null;
67
+ /** Original pairing (or browser-conversion) time, epoch ms; anchors the 30 d ceiling. */
68
+ pairedAt?: number;
69
+ /** SHA-256 hex of the immediately previous bearer, valid until `previousExpiresAt`. */
70
+ previousHash?: string;
71
+ /** End of the previous bearer's grace: `min(rotation + 60 s, its own expiresAt)`, epoch ms. */
72
+ previousExpiresAt?: number;
73
+ /**
74
+ * Bearer exposure record. Absent on rows written before it existed
75
+ * (`history-unknown`). `plaintextSeenAt` is the first time the bearer was
76
+ * presented or handed out off a proven channel; it is permanent (never cleared).
77
+ * See change: prove-vault-bridge-tls (D4).
78
+ */
79
+ exposure?: { trackedSince: string; plaintextSeenAt?: string };
80
+ }
81
+
82
+ /** What the vault trust gate may do with a device. See change: prove-vault-bridge-tls (D4). */
83
+ export type DeviceTrust = "eligible" | "inactive" | "exposed" | "history-unknown";
84
+
85
+ /** Why an `add` was refused (no row is created). */
86
+ export const BRIDGE_TOKEN_REQUIRES_HTTPS = "bridge_token_requires_https";
87
+
88
+ export interface AddOptions {
89
+ /** The channel that DELIVERS the token. Absent = no exposure decision (QR `approve()`, collected later by `markDelivered`). */
90
+ channel?: BearerChannel;
91
+ /** `"bridge"` mints a TLS-only `pi_tls_` token and requires a proven channel. */
92
+ purpose?: "bridge";
93
+ }
94
+
95
+ /** Outcome of resolving a presented bearer against the in-memory registry. */
96
+ export type BearerVerdict =
97
+ | { status: "ok"; id: string; tier: Tier; superseded: boolean }
98
+ | { status: "expired"; id: string }
99
+ /** A `pi_tls_` bearer presented off a proven channel: marked exposed, then refused. */
100
+ | { status: "tls_only_refused"; id: string }
101
+ | { status: "invalid" };
102
+
103
+ export type RotateResult =
104
+ | { ok: true; id: string; token: string; expiresAt: number }
105
+ | {
106
+ ok: false;
107
+ reason:
108
+ | "invalid"
109
+ | "expired"
110
+ | "superseded"
111
+ | "holder_declaration_required"
112
+ | "rate_limited"
113
+ | "persist_failed"
114
+ | "tls_only_untrusted_channel";
115
+ /** Device id when the bearer resolved to a row (for audit). */
116
+ id?: string;
117
+ retryAfterS?: number;
118
+ };
119
+
120
+ /** Finite number > 0 (the only valid shape for `expiresAt` / `pairedAt`). */
121
+ function isValidMs(v: unknown): v is number {
122
+ return typeof v === "number" && Number.isFinite(v) && v > 0;
47
123
  }
48
124
 
49
125
  /** Public view of a device (no token material) for Settings / listing. */
@@ -79,6 +155,11 @@ export class PairedDeviceRegistry {
79
155
  private devices: PairedDevice[];
80
156
  /** Per-device epoch ms of the last last-seen DISK write (in-memory only). */
81
157
  private lastPersistedAt = new Map<string, number>();
158
+ /** Per-device epoch ms of recent successful rotations (sliding limiter; in-memory only). */
159
+ private rotations = new Map<string, number[]>();
160
+ /** Device ids whose first-exposure mark has not reached the disk yet (in memory only). */
161
+ private pendingExposure = new Set<string>();
162
+ private listeners: Array<() => void> = [];
82
163
 
83
164
  constructor(filePath = defaultRegistryPath()) {
84
165
  this.filePath = filePath;
@@ -94,6 +175,8 @@ export class PairedDeviceRegistry {
94
175
 
95
176
  private persist(): void {
96
177
  writeJsonFile(this.filePath, this.devices);
178
+ // Every row (incl. any pending exposure mark) is on disk now.
179
+ this.pendingExposure.clear();
97
180
  // Enforce 0600 (json-store writes with default umask).
98
181
  try {
99
182
  fs.chmodSync(this.filePath, 0o600);
@@ -102,6 +185,73 @@ export class PairedDeviceRegistry {
102
185
  }
103
186
  }
104
187
 
188
+ /** Subscribe to registry changes: add, revoke, rotation and a first exposure. Returns an unsubscribe. */
189
+ onChange(listener: () => void): () => void {
190
+ this.listeners.push(listener);
191
+ return () => {
192
+ this.listeners = this.listeners.filter((l) => l !== listener);
193
+ };
194
+ }
195
+
196
+ private emitChange(): void {
197
+ for (const l of [...this.listeners]) {
198
+ try {
199
+ l();
200
+ } catch {
201
+ /* a listener fault never reaches the registry */
202
+ }
203
+ }
204
+ }
205
+
206
+ /** True while a first-exposure write has not reached the disk (the hub cannot prove its record is durable). */
207
+ exposurePending(): boolean {
208
+ return this.pendingExposure.size > 0;
209
+ }
210
+
211
+ /**
212
+ * Record the first off-channel use of a tracked row's bearer. The in-memory mark is set BEFORE the
213
+ * write and stays when the write fails (fail closed while running); the next successful persist
214
+ * clears the pending state. Written once per row. Legacy rows (no `exposure`) are already
215
+ * `history-unknown` and are left alone.
216
+ */
217
+ private markExposed(row: PairedDevice, channel: BearerChannel): void {
218
+ if (isProvenChannel(channel) || !row.exposure || row.exposure.plaintextSeenAt) return;
219
+ row.exposure.plaintextSeenAt = new Date().toISOString();
220
+ this.pendingExposure.add(row.id);
221
+ auditLine("pairing", "bearer-exposed", { id: auditPrefix(row.id), channel });
222
+ try {
223
+ this.persist();
224
+ } catch (err) {
225
+ console.error(`[pairing] exposure write failed id=${auditPrefix(row.id)}: ${(err as Error)?.name ?? "error"}`);
226
+ }
227
+ this.emitChange();
228
+ }
229
+
230
+ /** Mark a collected token's delivery channel (QR/knock `poll()`); no re-mint, holder and expiry unchanged. */
231
+ markDelivered(id: string, channel: BearerChannel): void {
232
+ const row = this.devices.find((d) => d.id === id);
233
+ if (row) this.markExposed(row, channel);
234
+ }
235
+
236
+ /** Is `token` any bearer this registry knows (current, or previous within its grace)? No side effects. */
237
+ isKnownBearer(token: string | undefined | null): boolean {
238
+ return !!token && this.resolve(token, Date.now()).status !== "invalid";
239
+ }
240
+
241
+ /** Ids of devices that are not expired now (revoked rows are gone). Feeds the expiry sweep. */
242
+ activeIds(): Set<string> {
243
+ const now = Date.now();
244
+ return new Set(this.devices.filter((d) => this.currentVerdict(d, now).status === "ok").map((d) => d.id));
245
+ }
246
+
247
+ /** The vault's view of a device: active + tracked + never off a proven channel → `eligible`. */
248
+ deviceTrust(id: string | undefined): DeviceTrust {
249
+ const row = id ? this.devices.find((d) => d.id === id) : undefined;
250
+ if (!row || this.currentVerdict(row, Date.now()).status !== "ok") return "inactive";
251
+ if (!row.exposure) return "history-unknown";
252
+ return row.exposure.plaintextSeenAt ? "exposed" : "eligible";
253
+ }
254
+
105
255
  /**
106
256
  * Register a new device, returning the plaintext bearer token (shown once).
107
257
  * The token is never persisted in plaintext.
@@ -112,56 +262,216 @@ export class PairedDeviceRegistry {
112
262
  * `manual` → `observe` (D1). An explicit value must be a valid `Tier`;
113
263
  * `add` throws BEFORE minting or persisting otherwise, so a bad tier leaves
114
264
  * the registry byte-identical (E3).
265
+ * @param holder `"browser"` (the only declaration that counts) issues an
266
+ * expiring row: `expiresAt = now + 7 d`, `pairedAt = now`. Anything else
267
+ * leaves the row non-expiring, byte-identical to a pre-change row.
115
268
  */
116
269
  add(
117
270
  label: string,
118
271
  source: "pairing" | "manual" = "pairing",
119
272
  tier?: Tier,
120
- ): { device: PairedDeviceView; token: string } {
273
+ holder?: unknown,
274
+ opts: AddOptions = {},
275
+ ): { device: PairedDeviceView; token: string; expiresAt?: number } {
121
276
  if (tier !== undefined && !isTier(tier)) {
122
277
  throw new Error(`invalid tier: ${String(tier)} (expected one of ${TIERS.join(", ")})`);
123
278
  }
124
- const resolvedTier: Tier = tier ?? defaultTierForSource(source);
125
- const token = crypto.randomBytes(TOKEN_BYTES).toString("base64url");
279
+ const bridge = opts.purpose === "bridge";
280
+ if (bridge && !(opts.channel && isProvenChannel(opts.channel))) throw new Error(BRIDGE_TOKEN_REQUIRES_HTTPS);
281
+ const resolvedTier: Tier = bridge ? "operate" : (tier ?? defaultTierForSource(source));
282
+ const token = (bridge ? TLS_ONLY_TOKEN_PREFIX : "") + crypto.randomBytes(TOKEN_BYTES).toString("base64url");
283
+ const createdAt = new Date().toISOString();
126
284
  const device: PairedDevice = {
127
285
  id: crypto.randomUUID(),
128
286
  label: label.trim() || "device",
129
287
  tokenHash: hashToken(token),
130
- createdAt: new Date().toISOString(),
288
+ createdAt,
131
289
  lastSeen: null,
132
290
  source,
133
291
  tier: resolvedTier,
292
+ exposure: { trackedSince: createdAt },
134
293
  };
294
+ // Issued over a non-proven channel: the row is born exposed (the bearer travelled in the clear).
295
+ if (opts.channel && !isProvenChannel(opts.channel)) {
296
+ device.exposure = { trackedSince: createdAt, plaintextSeenAt: createdAt };
297
+ auditLine("pairing", "bearer-exposed", { id: auditPrefix(device.id), channel: opts.channel });
298
+ }
299
+ if (holder === "browser") {
300
+ const now = Date.now();
301
+ device.pairedAt = now;
302
+ device.expiresAt = now + BROWSER_BEARER_TTL_MS;
303
+ }
135
304
  this.devices.push(device);
136
305
  this.persist();
137
- return { device: this.toView(device), token };
306
+ this.emitChange();
307
+ return {
308
+ device: this.toView(device),
309
+ token,
310
+ ...(device.expiresAt !== undefined ? { expiresAt: device.expiresAt as number } : {}),
311
+ };
312
+ }
313
+
314
+ /**
315
+ * Pairing-poll declaration: when `declared` and the row is not yet expiring,
316
+ * convert it (the token has not been handed out yet, so only the expiry
317
+ * changes). Returns the row's valid `expiresAt` for the poll response, or
318
+ * undefined for a non-expiring / unknown row.
319
+ */
320
+ browserExpiryFor(id: string, declared: boolean): number | undefined {
321
+ const d = this.devices.find((x) => x.id === id);
322
+ if (!d) return undefined;
323
+ if (declared && (d.expiresAt === undefined || d.expiresAt === null)) {
324
+ const now = Date.now();
325
+ d.pairedAt = now;
326
+ d.expiresAt = now + BROWSER_BEARER_TTL_MS;
327
+ try {
328
+ this.persist();
329
+ } catch {
330
+ delete d.pairedAt;
331
+ delete d.expiresAt;
332
+ return undefined;
333
+ }
334
+ }
335
+ return isValidMs(d.expiresAt) ? d.expiresAt : undefined;
138
336
  }
139
337
 
140
338
  /**
141
- * Verify a presented bearer token. On success updates last-seen and returns
142
- * the device id AND its tier; on failure returns null. Constant-time hash
143
- * comparison. The tier is read from the row on EVERY call (no caching), so a
144
- * tier change takes effect on the next request.
339
+ * Judge a presented bearer against IN-MEMORY state only (no file IO). The
340
+ * current hash is `ok` unless the row expires (`now >= min(expiresAt,
341
+ * pairedAt + 30 d)`, malformed expiry fields fail closed as `expired`); the
342
+ * immediately previous hash is `ok` + `superseded` until `previousExpiresAt`,
343
+ * after which it is plain `invalid` (indistinguishable from a never-issued
344
+ * bearer). Constant-time hash comparison.
145
345
  */
146
- verify(token: string | undefined | null): { id: string; tier: Tier } | null {
147
- if (!token) return null;
346
+ private resolve(token: string, now: number): (Exclude<BearerVerdict, { status: "tls_only_refused" }> & { row?: PairedDevice }) {
148
347
  const presented = hashToken(token);
149
- const now = Date.now();
150
348
  for (const d of this.devices) {
151
349
  if (timingSafeEqualHex(presented, d.tokenHash)) {
152
- // Update last-seen in memory always; persist to disk at most once per
153
- // interval. Compare against the last DISK-WRITE time (not the previous
154
- // request time), else an always-active device would never re-persist.
155
- d.lastSeen = new Date(now).toISOString();
156
- const lastWrite = this.lastPersistedAt.get(d.id) ?? 0;
157
- if (now - lastWrite >= LAST_SEEN_PERSIST_INTERVAL_MS) {
158
- this.lastPersistedAt.set(d.id, now);
350
+ return this.currentVerdict(d, now);
351
+ }
352
+ if (typeof d.previousHash === "string" && timingSafeEqualHex(presented, d.previousHash)) {
353
+ if (isValidMs(d.previousExpiresAt) && now < d.previousExpiresAt) {
354
+ return { status: "ok", id: d.id, tier: d.tier, superseded: true, row: d };
355
+ }
356
+ return { status: "invalid" };
357
+ }
358
+ }
359
+ return { status: "invalid" };
360
+ }
361
+
362
+ private currentVerdict(d: PairedDevice, now: number): Exclude<BearerVerdict, { status: "tls_only_refused" }> & { row?: PairedDevice } {
363
+ if (d.expiresAt !== undefined && d.expiresAt !== null) {
364
+ let ceiling: number;
365
+ if (d.pairedAt !== undefined && d.pairedAt !== null) {
366
+ if (!isValidMs(d.pairedAt)) return { status: "expired", id: d.id };
367
+ ceiling = d.pairedAt + BROWSER_BEARER_CEILING_MS;
368
+ } else {
369
+ ceiling = Date.parse(d.createdAt) + BROWSER_BEARER_CEILING_MS;
370
+ }
371
+ if (!isValidMs(d.expiresAt) || Number.isNaN(ceiling) || now >= Math.min(d.expiresAt, ceiling)) {
372
+ return { status: "expired", id: d.id };
373
+ }
374
+ }
375
+ return { status: "ok", id: d.id, tier: d.tier, superseded: false, row: d };
376
+ }
377
+
378
+ /**
379
+ * Verify a presented bearer token, distinguishing an expired browser bearer
380
+ * from an unknown one. On success updates last-seen (current hash only) and
381
+ * returns the verdict. The tier is read from the row on EVERY call (no
382
+ * caching), so a tier change takes effect on the next request.
383
+ */
384
+ verifyDetailed(token: string | undefined | null, channel: BearerChannel): BearerVerdict {
385
+ if (!token) return { status: "invalid" };
386
+ const now = Date.now();
387
+ const v = this.resolve(token, now);
388
+ if (v.status === "invalid") return v;
389
+ // Any resolving row (ok, superseded, expired) presented off a proven channel is marked exposed, in memory first.
390
+ const row = this.devices.find((x) => x.id === v.id);
391
+ if (row) this.markExposed(row, channel ?? "plain");
392
+ // A TLS-only bearer is never honoured off a proven channel (the hub cannot tell a relayed request from a sniffed one).
393
+ if (isTlsOnlyToken(token) && !isProvenChannel(channel ?? "plain")) return { status: "tls_only_refused", id: v.id };
394
+ if (v.status !== "ok") return { status: "expired", id: v.id };
395
+ const d = v.row as PairedDevice;
396
+ if (!v.superseded) {
397
+ // Update last-seen in memory always; persist to disk at most once per
398
+ // interval. Compare against the last DISK-WRITE time (not the previous
399
+ // request time), else an always-active device would never re-persist.
400
+ d.lastSeen = new Date(now).toISOString();
401
+ const lastWrite = this.lastPersistedAt.get(d.id) ?? 0;
402
+ if (now - lastWrite >= LAST_SEEN_PERSIST_INTERVAL_MS) {
403
+ this.lastPersistedAt.set(d.id, now);
404
+ try {
159
405
  this.persist();
406
+ } catch {
407
+ /* last-seen is best-effort: a persist fault must never reject a valid bearer */
160
408
  }
161
- return { id: d.id, tier: d.tier };
162
409
  }
163
410
  }
164
- return null;
411
+ return { status: "ok", id: v.id, tier: v.tier, superseded: v.superseded };
412
+ }
413
+
414
+ /** `{id, tier}` for a valid bearer (expired / unknown → null). */
415
+ verify(token: string | undefined | null, channel: BearerChannel): { id: string; tier: Tier } | null {
416
+ const v = this.verifyDetailed(token, channel);
417
+ return v.status === "ok" ? { id: v.id, tier: v.tier } : null;
418
+ }
419
+
420
+ /**
421
+ * Rotate the bearer that `token` identifies (the bearer rotates ITS OWN row;
422
+ * callers pass nothing else). Synchronous end to end, so two same-tick
423
+ * rotations with one bearer serialise: the second sees a superseded bearer.
424
+ *
425
+ * New `expiresAt = min(now + 7 d, pairedAt + 30 d)`. A non-expiring row
426
+ * converts only with `declaredBrowser` (30 d then counts from conversion).
427
+ * Persist failure → in-memory state restored, `persist_failed`.
428
+ */
429
+ rotate(token: string, declaredBrowser: boolean, opts: { channel: BearerChannel } = { channel: "plain" }): RotateResult {
430
+ const now = Date.now();
431
+ const v = this.resolve(token, now);
432
+ if (v.status === "invalid") return { ok: false, reason: "invalid" };
433
+ // The exposure mark is persisted on its own, BEFORE the rotation mutates anything, and a failed
434
+ // rotation never reverts it.
435
+ const marked = this.devices.find((x) => x.id === v.id);
436
+ if (marked) this.markExposed(marked, opts.channel);
437
+ if (isTlsOnlyToken(token) && !isProvenChannel(opts.channel)) return { ok: false, reason: "tls_only_untrusted_channel", id: v.id };
438
+ if (v.status === "expired") return { ok: false, reason: "expired", id: v.id };
439
+ if (v.superseded) return { ok: false, reason: "superseded", id: v.id };
440
+ const row = v.row as PairedDevice;
441
+ const expiring = row.expiresAt !== undefined && row.expiresAt !== null;
442
+ if (!expiring && !declaredBrowser) {
443
+ return { ok: false, reason: "holder_declaration_required", id: row.id };
444
+ }
445
+ const recent = (this.rotations.get(row.id) ?? []).filter((t) => t > now - ROTATE_WINDOW_MS);
446
+ if (recent.length >= ROTATE_LIMIT) {
447
+ return {
448
+ ok: false,
449
+ reason: "rate_limited",
450
+ id: row.id,
451
+ retryAfterS: Math.max(1, Math.ceil((recent[0] + ROTATE_WINDOW_MS - now) / 1000)),
452
+ };
453
+ }
454
+ const pairedAt = expiring ? (isValidMs(row.pairedAt) ? row.pairedAt : Date.parse(row.createdAt)) : now;
455
+ const expiresAt = Math.min(now + BROWSER_BEARER_TTL_MS, pairedAt + BROWSER_BEARER_CEILING_MS);
456
+ const before = { ...row };
457
+ // The new token keeps the old token's form.
458
+ const newToken = (isTlsOnlyToken(token) ? TLS_ONLY_TOKEN_PREFIX : "") + crypto.randomBytes(TOKEN_BYTES).toString("base64url");
459
+ row.previousHash = row.tokenHash;
460
+ row.previousExpiresAt = Math.min(now + ROTATION_GRACE_MS, isValidMs(row.expiresAt) ? row.expiresAt : Number.POSITIVE_INFINITY);
461
+ row.tokenHash = hashToken(newToken);
462
+ row.pairedAt = pairedAt;
463
+ row.expiresAt = expiresAt;
464
+ try {
465
+ this.persist();
466
+ } catch {
467
+ const i = this.devices.indexOf(row);
468
+ if (i >= 0) this.devices[i] = before;
469
+ return { ok: false, reason: "persist_failed", id: row.id };
470
+ }
471
+ recent.push(now);
472
+ this.rotations.set(row.id, recent);
473
+ this.emitChange();
474
+ return { ok: true, id: row.id, token: newToken, expiresAt };
165
475
  }
166
476
 
167
477
  /** Delete a device by id. Returns true if a row was removed. */
@@ -169,7 +479,10 @@ export class PairedDeviceRegistry {
169
479
  const before = this.devices.length;
170
480
  this.devices = this.devices.filter((d) => d.id !== id);
171
481
  if (this.devices.length === before) return false;
482
+ this.rotations.delete(id);
483
+ this.pendingExposure.delete(id);
172
484
  this.persist();
485
+ this.emitChange();
173
486
  return true;
174
487
  }
175
488
 
@@ -26,6 +26,7 @@ import {
26
26
  type Tier,
27
27
  } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
28
28
  import type { KnockOutcome } from "./knock-admission.js";
29
+ import type { BearerChannel } from "../auth/proven-tls.js";
29
30
  import type { PairedDeviceRegistry, PairedDeviceView } from "./paired-devices.js";
30
31
 
31
32
  /** Current pairing protocol version (D9). */
@@ -78,6 +79,13 @@ export interface RedeemMeta {
78
79
  remoteAddress?: string;
79
80
  /** Raw `X-Forwarded-For` header; only the first hop is kept. */
80
81
  forwardedFor?: string;
82
+ /**
83
+ * Holder declaration from the redeem / knock body. Only the exact string
84
+ * `"browser"` counts (anything else = no declaration): it makes the issued
85
+ * bearer expiring. Never displayed, never logged.
86
+ * See change: harden-auth-credentials (D5).
87
+ */
88
+ holder?: unknown;
81
89
  }
82
90
 
83
91
  /** Operator-facing view of one pending device — never carries a code (R5). */
@@ -130,6 +138,10 @@ interface PendingDevice {
130
138
  approveAttempts: number;
131
139
  /** Set once approved; the device polls to collect it. */
132
140
  issuedToken: string | null;
141
+ /** The device declared `holder:"browser"` at redeem / knock time. */
142
+ browserHolder: boolean;
143
+ /** Registry id of the row minted at approval (poll reads its expiry). */
144
+ deviceId?: string;
133
145
  /** Set once an operator denied it; the code is dead (D3). */
134
146
  rejected: boolean;
135
147
  userAgent?: string;
@@ -194,7 +206,7 @@ export type DenyResult = { ok: true } | { ok: false; error: "no_pending" };
194
206
 
195
207
  export type PollResult =
196
208
  | { status: "pending" }
197
- | { status: "approved"; token: string }
209
+ | { status: "approved"; token: string; expiresAt?: number }
198
210
  | { status: "rejected" }
199
211
  | { status: "unknown" };
200
212
 
@@ -390,6 +402,7 @@ export class PairingManager {
390
402
  createdAt: this.now(),
391
403
  approveAttempts: 0,
392
404
  issuedToken: null,
405
+ browserHolder: meta.holder === "browser",
393
406
  rejected: false,
394
407
  userAgent: bound(meta.userAgent, MAX_UA_CHARS),
395
408
  viaHost: bound(meta.host, MAX_HOST_CHARS),
@@ -595,8 +608,10 @@ export class PairingManager {
595
608
  label ?? pending.label,
596
609
  "pairing",
597
610
  isTier(tier) ? tier : defaultTierForSource("pairing"),
611
+ pending.browserHolder ? "browser" : undefined,
598
612
  );
599
613
  pending.issuedToken = token;
614
+ pending.deviceId = device.id;
600
615
  // Drop the code so it can never be reused; keep the pending slot so the
601
616
  // device's next poll collects the token, then it self-expires via sweep.
602
617
  entry.expiresAt = this.now() + RESOLVED_POLL_WINDOW_MS;
@@ -607,16 +622,31 @@ export class PairingManager {
607
622
  return { ok: true, device };
608
623
  }
609
624
 
610
- /** Device polls for its token after redemption. */
611
- poll(pendingId: string): PollResult {
625
+ /** Expiry (epoch ms) for a collected token's row, converting it when `holder:"browser"` was declared late. */
626
+ private browserExpiry(pending: PendingDevice, holder: unknown): number | undefined {
627
+ if (pending.deviceId === undefined) return undefined;
628
+ return this.deps.registry.browserExpiryFor(pending.deviceId, pending.browserHolder || holder === "browser");
629
+ }
630
+
631
+ /**
632
+ * Device polls for its token after redemption. A `holder:"browser"` on the
633
+ * poll body (exact string only) also counts when it was not declared at
634
+ * redeem: the still-uncollected token's row becomes an expiring browser row.
635
+ * `expiresAt` (epoch ms) is returned only for an expiring row.
636
+ */
637
+ poll(pendingId: string, holder?: unknown, channel: BearerChannel = "plain"): PollResult {
612
638
  this.sweep();
613
639
  for (const entry of this.codes.values()) {
614
640
  if (entry.pending?.pendingId === pendingId) {
615
641
  if (entry.pending.issuedToken) {
616
642
  const token = entry.pending.issuedToken;
643
+ // The token travels on THIS response: a non-proven delivery channel exposes it. `approve()`
644
+ // makes no exposure decision. See change: prove-vault-bridge-tls (D4).
645
+ if (entry.pending.deviceId !== undefined) this.deps.registry.markDelivered(entry.pending.deviceId, channel);
646
+ const expiresAt = this.browserExpiry(entry.pending, holder);
617
647
  // One-shot: clear so the token isn't re-served, drop the code.
618
648
  this.codes.delete(entry.code);
619
- return { status: "approved", token };
649
+ return expiresAt === undefined ? { status: "approved", token } : { status: "approved", token, expiresAt };
620
650
  }
621
651
  if (entry.pending.rejected) return { status: "rejected" };
622
652
  return { status: "pending" };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Per-socket locality bit. Computed ONCE at the `/ws` upgrade with
3
+ * `isLocallyTrusted` over the upgrade request and stamped on the socket (like
4
+ * `principal`), so handlers never re-derive it from a frame. An unstamped socket
5
+ * (in-process / virtual connections) is NOT local: fail closed.
6
+ * See change: harden-server-capability-bounds (D1b).
7
+ */
8
+ import type { IncomingMessage } from "node:http";
9
+ import type { LocalTrustContext } from "../auth/local-proof.js";
10
+ import { isLocallyTrusted } from "../auth/localhost-guard.js";
11
+
12
+ interface LocalitySocket {
13
+ locallyTrusted?: boolean;
14
+ }
15
+
16
+ export function stampSocketLocality(
17
+ ws: object,
18
+ request: Pick<IncomingMessage, "headers"> & { socket: { remoteAddress?: string } },
19
+ ctx?: LocalTrustContext,
20
+ ): boolean {
21
+ const local = isLocallyTrusted({ ip: request.socket.remoteAddress ?? "", headers: request.headers }, ctx);
22
+ (ws as LocalitySocket).locallyTrusted = local;
23
+ return local;
24
+ }
25
+
26
+ export const isSocketLocallyTrusted = (ws: object): boolean => (ws as LocalitySocket).locallyTrusted === true;
@@ -387,6 +387,11 @@ function backfillDisplayPrefs(
387
387
  if (typeof out.reasoningInlineFlow !== "boolean") {
388
388
  out = { ...out, reasoningInlineFlow: false };
389
389
  }
390
+ // Legacy prefs predating chat motion default it ON, matching the presets.
391
+ // See change: add-fluid-chat-motion.
392
+ if (typeof out.chatMotion !== "boolean") {
393
+ out = { ...out, chatMotion: true };
394
+ }
390
395
  // Custom event groups (add-custom-event-group-filters): migrate the removed
391
396
  // single `customEntryFallback` switch onto the `other` group (idempotent,
392
397
  // design D7), then seed every configured group so a gate is never
@@ -1121,6 +1126,9 @@ let dirty =
1121
1126
  showOutOfCwdSessionDiffs: false,
1122
1127
  notifyMinLevel: "all",
1123
1128
  reasoningInlineFlow: false,
1129
+ // Documented exception to the all-`false` base: the default is ON.
1130
+ // See change: add-fluid-chat-motion.
1131
+ chatMotion: true,
1124
1132
  customEventGroups: { ...seededCustomEventGroupDefaults },
1125
1133
  };
1126
1134
  const merged: DisplayPrefs = {
@@ -1143,6 +1151,7 @@ let dirty =
1143
1151
  partial.showOutOfCwdSessionDiffs ?? base.showOutOfCwdSessionDiffs,
1144
1152
  notifyMinLevel: partial.notifyMinLevel ?? base.notifyMinLevel,
1145
1153
  reasoningInlineFlow: partial.reasoningInlineFlow ?? base.reasoningInlineFlow,
1154
+ chatMotion: partial.chatMotion ?? base.chatMotion,
1146
1155
  customEventGroups: mergeCustomEventGroupPrefs(base.customEventGroups, partial.customEventGroups),
1147
1156
  };
1148
1157
  displayPrefs = merged;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * What the hub itself observed about how one bridge socket was admitted. Bound per socket by the gateway
3
+ * and answered by `channelOf(sessionId)` from the socket the session is currently ROUTED to, so the record
4
+ * follows the routing entry at register and at move-commit. The vault trust gate reads it; nothing here is
5
+ * a claim by the bridge.
6
+ *
7
+ * See change: prove-vault-bridge-tls (D3).
8
+ */
9
+
10
+ /** How the connection was admitted. */
11
+ export type BridgeAdmission =
12
+ | "unix"
13
+ | "local-proof"
14
+ | "in-process"
15
+ | "device-ticket"
16
+ | "local-ticket"
17
+ | "legacy-token"
18
+ | "grace";
19
+
20
+ export interface BridgeChannel {
21
+ admission: BridgeAdmission;
22
+ /** The upgrade arrived on the hub's own TLS socket with no forwarding header. */
23
+ provenTls: boolean;
24
+ /** The consumed ticket was minted on a proven-TLS request. */
25
+ ticketTls: boolean;
26
+ /** Device the consumed ticket was minted for (`device-ticket` admissions). */
27
+ ticketDeviceId?: string;
28
+ }
29
+
30
+ /** Admissions that prove the peer is on this host (unix socket, local credential proof, in-process). */
31
+ export function isLocallyAdmitted(admission: BridgeAdmission): boolean {
32
+ return admission === "unix" || admission === "local-proof" || admission === "in-process";
33
+ }