@blackbelt-technology/pi-agent-dashboard 0.10.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.
Files changed (474) hide show
  1. package/AGENTS.md +4 -2
  2. package/README.md +64 -18
  3. package/docs/architecture.md +2325 -270
  4. package/package.json +36 -20
  5. package/packages/extension/package.json +18 -9
  6. package/packages/extension/src/bridge-context.ts +6 -0
  7. package/packages/extension/src/bridge-handlers/dispatch.ts +109 -70
  8. package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
  9. package/packages/extension/src/bridge-handlers/instance.ts +31 -13
  10. package/packages/extension/src/bridge-handlers/lifecycle.ts +149 -66
  11. package/packages/extension/src/bridge-shutdown.ts +44 -0
  12. package/packages/extension/src/bridge-ticket-client.ts +61 -7
  13. package/packages/extension/src/bridge-tls-checks.ts +79 -0
  14. package/packages/extension/src/bridge.ts +309 -284
  15. package/packages/extension/src/canvas-tool.ts +2 -0
  16. package/packages/extension/src/command-handler.ts +106 -37
  17. package/packages/extension/src/connect-target.ts +23 -0
  18. package/packages/extension/src/connection.ts +153 -38
  19. package/packages/extension/src/credential-guard.ts +300 -0
  20. package/packages/extension/src/custom-entry-forward.ts +27 -18
  21. package/packages/extension/src/dashboard-http-origin.ts +88 -0
  22. package/packages/extension/src/default-model-apply.ts +83 -0
  23. package/packages/extension/src/dev-build.ts +11 -1
  24. package/packages/extension/src/flow-event-wiring.ts +19 -95
  25. package/packages/extension/src/followup-drain.ts +19 -5
  26. package/packages/extension/src/git-link-builder.ts +11 -2
  27. package/packages/extension/src/inbound-limits.ts +138 -0
  28. package/packages/extension/src/local-token-header.ts +77 -6
  29. package/packages/extension/src/model-refresh.ts +69 -0
  30. package/packages/extension/src/path-gate/decide.ts +68 -5
  31. package/packages/extension/src/path-gate/handler.ts +16 -8
  32. package/packages/extension/src/path-gate/index.ts +2 -2
  33. package/packages/extension/src/path-gate/roots.ts +15 -3
  34. package/packages/extension/src/path-gate/suppression.ts +3 -0
  35. package/packages/extension/src/pi-env.d.ts +8 -1
  36. package/packages/extension/src/pi-retry-settings.ts +11 -2
  37. package/packages/extension/src/pinned-endpoint.ts +44 -0
  38. package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
  39. package/packages/extension/src/preview-path-link.ts +151 -0
  40. package/packages/extension/src/project-init/scaffold.ts +98 -35
  41. package/packages/extension/src/project-trust-live.ts +143 -0
  42. package/packages/extension/src/project-trust.ts +178 -30
  43. package/packages/extension/src/provider-model-cache.ts +118 -0
  44. package/packages/extension/src/provider-register.ts +487 -46
  45. package/packages/extension/src/remote-registration-gate.ts +21 -21
  46. package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
  47. package/packages/extension/src/retry-tracker.ts +90 -7
  48. package/packages/extension/src/role-manager.ts +4 -2
  49. package/packages/extension/src/role-model-tools.ts +68 -10
  50. package/packages/extension/src/server-auto-start.ts +69 -3
  51. package/packages/extension/src/server-launcher.ts +26 -8
  52. package/packages/extension/src/server-proof-probe.ts +117 -0
  53. package/packages/extension/src/session-sync.ts +53 -24
  54. package/packages/extension/src/spawn-new-session.ts +22 -0
  55. package/packages/extension/src/steer-buffer.ts +164 -0
  56. package/packages/extension/src/stream-forward-buffer.ts +64 -15
  57. package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
  58. package/packages/extension/src/sudo-askpass/controller.ts +405 -0
  59. package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
  60. package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
  61. package/packages/extension/src/sudo-askpass/index.ts +11 -0
  62. package/packages/extension/src/sudo-askpass/install.ts +143 -0
  63. package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
  64. package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
  65. package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
  66. package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
  67. package/packages/extension/src/terminal-reload.ts +19 -5
  68. package/packages/extension/src/tool-update-filter-registry.ts +210 -0
  69. package/packages/extension/src/vault-delivery.ts +11 -1
  70. package/packages/extension/src/vault-redaction.ts +4 -3
  71. package/packages/server/package.json +17 -14
  72. package/packages/server/src/access/access-denials.ts +8 -0
  73. package/packages/server/src/access/access-grants.ts +303 -64
  74. package/packages/server/src/access/access-health.ts +10 -0
  75. package/packages/server/src/access/access-plane.ts +12 -1
  76. package/packages/server/src/access/containment-gate.ts +113 -30
  77. package/packages/server/src/access/cwd-verdict.ts +3 -3
  78. package/packages/server/src/access/denial-hold.ts +3 -0
  79. package/packages/server/src/access/grant-coordinator.ts +17 -1
  80. package/packages/server/src/access/named-grant.ts +3 -0
  81. package/packages/server/src/access/pending-grant-registry.ts +32 -5
  82. package/packages/server/src/access/pi-trust-live.ts +244 -0
  83. package/packages/server/src/access/pi-trust-mirror-service.ts +50 -11
  84. package/packages/server/src/access/planes.ts +107 -1
  85. package/packages/server/src/access/preview-egress-store.ts +153 -0
  86. package/packages/server/src/access/prompt-channel.ts +5 -0
  87. package/packages/server/src/access/provisioning-wiring.ts +113 -0
  88. package/packages/server/src/access/provisioning.ts +763 -0
  89. package/packages/server/src/access/verified-read.ts +24 -7
  90. package/packages/server/src/access/yolo-session.ts +54 -2
  91. package/packages/server/src/acp-bridge/acp-session-adapter.ts +18 -5
  92. package/packages/server/src/acp-bridge/server-requests.ts +10 -4
  93. package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
  94. package/packages/server/src/auth/audit-log.ts +108 -0
  95. package/packages/server/src/auth/auth-plugin.ts +230 -38
  96. package/packages/server/src/auth/auth.ts +104 -4
  97. package/packages/server/src/auth/bearer-auth.ts +52 -12
  98. package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
  99. package/packages/server/src/auth/cors-origin.ts +90 -30
  100. package/packages/server/src/auth/credential-envelope.ts +233 -0
  101. package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
  102. package/packages/server/src/auth/credential-key-worker.mjs +108 -0
  103. package/packages/server/src/auth/credential-key.ts +479 -0
  104. package/packages/server/src/auth/credential-migration.ts +162 -0
  105. package/packages/server/src/auth/csp-report-paths.ts +26 -0
  106. package/packages/server/src/auth/csp-report-sink.ts +302 -0
  107. package/packages/server/src/auth/csp-report-store.ts +406 -0
  108. package/packages/server/src/auth/csp.ts +145 -11
  109. package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
  110. package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
  111. package/packages/server/src/auth/device-proof.ts +202 -0
  112. package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
  113. package/packages/server/src/auth/host-admission.ts +7 -0
  114. package/packages/server/src/auth/host-gate.ts +13 -2
  115. package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
  116. package/packages/server/src/auth/local-proof.ts +69 -18
  117. package/packages/server/src/auth/localhost-guard.ts +98 -33
  118. package/packages/server/src/auth/locked-json-file.ts +68 -6
  119. package/packages/server/src/auth/models-json-store.ts +269 -0
  120. package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
  121. package/packages/server/src/auth/nav-intent.ts +72 -0
  122. package/packages/server/src/auth/node-guard.ts +36 -49
  123. package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
  124. package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
  125. package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
  126. package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
  127. package/packages/server/src/auth/plugin-credential-store.ts +81 -10
  128. package/packages/server/src/auth/plugin-server-trust.ts +29 -0
  129. package/packages/server/src/auth/plugin-trust-store.ts +103 -0
  130. package/packages/server/src/auth/proven-tls.ts +45 -0
  131. package/packages/server/src/auth/provider-auth-storage.ts +214 -12
  132. package/packages/server/src/auth/provider-block-checks.ts +321 -0
  133. package/packages/server/src/auth/provider-host-detect.ts +151 -0
  134. package/packages/server/src/auth/provider-key-file.ts +71 -0
  135. package/packages/server/src/auth/provider-readiness.ts +91 -0
  136. package/packages/server/src/auth/radius-mcp.ts +1 -1
  137. package/packages/server/src/auth/request-principal.ts +32 -0
  138. package/packages/server/src/auth/route-tier-gate.ts +3 -2
  139. package/packages/server/src/auth/secret-rotation.ts +246 -0
  140. package/packages/server/src/auth/secure-origin.ts +56 -0
  141. package/packages/server/src/auth/serve-app-host.ts +111 -11
  142. package/packages/server/src/auth/vertex-key-check.ts +140 -0
  143. package/packages/server/src/auth/ws-ticket.ts +40 -2
  144. package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
  145. package/packages/server/src/browse.ts +73 -20
  146. package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
  147. package/packages/server/src/browser-handlers/directory-handler.ts +34 -24
  148. package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
  149. package/packages/server/src/browser-handlers/handler-context.ts +25 -2
  150. package/packages/server/src/browser-handlers/session-action-handler.ts +167 -63
  151. package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
  152. package/packages/server/src/browser-handlers/subscription-handler.ts +146 -3
  153. package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
  154. package/packages/server/src/build-plugin-send-prompt.ts +18 -0
  155. package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
  156. package/packages/server/src/cli/credentials-command.ts +555 -0
  157. package/packages/server/src/cli.ts +229 -53
  158. package/packages/server/src/config-api.ts +53 -35
  159. package/packages/server/src/config-snapshot.ts +197 -1
  160. package/packages/server/src/directory-service.ts +193 -68
  161. package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
  162. package/packages/server/src/event-wiring.ts +322 -207
  163. package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
  164. package/packages/server/src/git-worktree/git-operations.ts +45 -11
  165. package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
  166. package/packages/server/src/git-worktree/ref-arg.ts +39 -0
  167. package/packages/server/src/git-worktree/repo-lock.ts +42 -0
  168. package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
  169. package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
  170. package/packages/server/src/git-worktree/worktree-init.ts +5 -1
  171. package/packages/server/src/identity/http-road-classification.ts +18 -2
  172. package/packages/server/src/identity/identity-floor.ts +5 -2
  173. package/packages/server/src/identity/ws-message-scope.ts +11 -3
  174. package/packages/server/src/identity/ws-road-classification.ts +3 -1
  175. package/packages/server/src/known-server-moves.ts +36 -15
  176. package/packages/server/src/lib/browse-roots.ts +129 -17
  177. package/packages/server/src/lib/client-dist.ts +36 -21
  178. package/packages/server/src/lib/content-disposition.ts +20 -0
  179. package/packages/server/src/lib/dashboard-state-guard.ts +513 -0
  180. package/packages/server/src/lib/diagram-render.ts +4 -6
  181. package/packages/server/src/lib/eml.ts +5 -10
  182. package/packages/server/src/lib/file-cwd-admission.ts +145 -0
  183. package/packages/server/src/lib/frame-policy-probe.ts +308 -0
  184. package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
  185. package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
  186. package/packages/server/src/lib/grep-worker.ts +23 -0
  187. package/packages/server/src/lib/grep.ts +96 -7
  188. package/packages/server/src/lib/index-html.ts +81 -0
  189. package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
  190. package/packages/server/src/lib/office-preview.ts +49 -13
  191. package/packages/server/src/lib/path-containment.ts +50 -10
  192. package/packages/server/src/lib/resolve-file-mention.ts +234 -40
  193. package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
  194. package/packages/server/src/lib/route-admission.ts +80 -0
  195. package/packages/server/src/lib/writable-handler-target.ts +4 -0
  196. package/packages/server/src/lib/writable-md-target.ts +26 -0
  197. package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
  198. package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
  199. package/packages/server/src/lifecycle/exit-signal.ts +43 -0
  200. package/packages/server/src/lifecycle/recovery-server.ts +65 -18
  201. package/packages/server/src/live-server/capability-redact.ts +31 -0
  202. package/packages/server/src/live-server/live-browser-gate.ts +22 -0
  203. package/packages/server/src/live-server/live-capability.ts +615 -44
  204. package/packages/server/src/live-server/live-csp-report.ts +63 -0
  205. package/packages/server/src/live-server/live-csp.ts +141 -0
  206. package/packages/server/src/live-server/live-egress.ts +435 -0
  207. package/packages/server/src/live-server/live-exposure.ts +149 -0
  208. package/packages/server/src/live-server/live-log.ts +25 -0
  209. package/packages/server/src/live-server/live-origin-scan.ts +298 -0
  210. package/packages/server/src/live-server/live-server-manager.ts +220 -33
  211. package/packages/server/src/live-server/live-server-proxy.ts +411 -50
  212. package/packages/server/src/live-server/live-static.ts +231 -0
  213. package/packages/server/src/live-server/preview-dispatch.ts +286 -0
  214. package/packages/server/src/live-server/preview-observe.ts +53 -0
  215. package/packages/server/src/live-server/preview-origin.ts +182 -0
  216. package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
  217. package/packages/server/src/live-server/preview-path-store.ts +420 -0
  218. package/packages/server/src/live-server/preview-path.ts +40 -0
  219. package/packages/server/src/live-server/preview-pool.ts +385 -0
  220. package/packages/server/src/live-server/preview-preflight.ts +41 -0
  221. package/packages/server/src/live-server/preview-reserve.ts +44 -0
  222. package/packages/server/src/live-server/preview-tier.ts +217 -0
  223. package/packages/server/src/live-server/preview-viewers.ts +54 -0
  224. package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
  225. package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
  226. package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
  227. package/packages/server/src/model-proxy/internal-registry.ts +283 -21
  228. package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
  229. package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
  230. package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
  231. package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
  232. package/packages/server/src/openspec/dependencies-file.ts +122 -0
  233. package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
  234. package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
  235. package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
  236. package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
  237. package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
  238. package/packages/server/src/openspec/readiness.ts +1 -1
  239. package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
  240. package/packages/server/src/openspec/workflow-schema.ts +141 -267
  241. package/packages/server/src/package/npm-search-proxy.ts +5 -2
  242. package/packages/server/src/package/provider-probe.ts +202 -7
  243. package/packages/server/src/pairing/browser-gateway.ts +325 -51
  244. package/packages/server/src/pairing/device-key-intake.ts +120 -0
  245. package/packages/server/src/pairing/device-token-services.ts +26 -0
  246. package/packages/server/src/pairing/paired-devices.ts +702 -27
  247. package/packages/server/src/pairing/pairing.ts +103 -11
  248. package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
  249. package/packages/server/src/pairing/socket-locality.ts +26 -0
  250. package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
  251. package/packages/server/src/pending/pending-attach-registry.ts +15 -0
  252. package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
  253. package/packages/server/src/persistence/memory-event-store.ts +251 -296
  254. package/packages/server/src/persistence/preferences-store.ts +61 -2
  255. package/packages/server/src/pi/bridge-channel.ts +33 -0
  256. package/packages/server/src/pi/bridge-contention.ts +84 -2
  257. package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
  258. package/packages/server/src/pi/gateway-listeners.ts +9 -3
  259. package/packages/server/src/pi/host-project-trust.ts +29 -15
  260. package/packages/server/src/pi/pi-gateway.ts +398 -41
  261. package/packages/server/src/pi/provisional-registration.ts +4 -1
  262. package/packages/server/src/pi/resource-toggle-trust.ts +18 -7
  263. package/packages/server/src/pi-agent-settings.ts +95 -301
  264. package/packages/server/src/pi-default-remirror.ts +89 -0
  265. package/packages/server/src/plugin-append-event.ts +35 -0
  266. package/packages/server/src/plugin-discovery-wiring.ts +142 -0
  267. package/packages/server/src/plugin-entry-stats.ts +61 -0
  268. package/packages/server/src/plugin-event-seam.ts +116 -4
  269. package/packages/server/src/plugin-local-request.ts +207 -0
  270. package/packages/server/src/plugin-ownership.ts +111 -0
  271. package/packages/server/src/plugin-policy-registry.ts +297 -0
  272. package/packages/server/src/plugin-request-lane.ts +92 -16
  273. package/packages/server/src/plugin-runtime-clients.ts +89 -0
  274. package/packages/server/src/preferences-relay.ts +20 -0
  275. package/packages/server/src/project-seed.ts +347 -0
  276. package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
  277. package/packages/server/src/questions/question-store.ts +3 -2
  278. package/packages/server/src/routes/access-routes.ts +182 -15
  279. package/packages/server/src/routes/acme-routes.ts +14 -4
  280. package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
  281. package/packages/server/src/routes/canvas-types-routes.ts +20 -6
  282. package/packages/server/src/routes/csp-violations-routes.ts +162 -0
  283. package/packages/server/src/routes/file-routes.ts +640 -279
  284. package/packages/server/src/routes/file-write-binary-routes.ts +97 -24
  285. package/packages/server/src/routes/folder-project-routes.ts +18 -12
  286. package/packages/server/src/routes/frame-policy-routes.ts +215 -0
  287. package/packages/server/src/routes/git-routes.ts +340 -273
  288. package/packages/server/src/routes/grep-routes.ts +64 -14
  289. package/packages/server/src/routes/known-servers-routes.ts +189 -91
  290. package/packages/server/src/routes/live-server-routes.ts +572 -15
  291. package/packages/server/src/routes/local-proof-routes.ts +14 -0
  292. package/packages/server/src/routes/models-introspection-routes.ts +1 -1
  293. package/packages/server/src/routes/nav-intent-routes.ts +46 -0
  294. package/packages/server/src/routes/openspec-group-routes.ts +53 -44
  295. package/packages/server/src/routes/openspec-routes.ts +396 -31
  296. package/packages/server/src/routes/package-routes.ts +58 -10
  297. package/packages/server/src/routes/pairing-routes.ts +342 -17
  298. package/packages/server/src/routes/pi-settings-routes.ts +2 -0
  299. package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
  300. package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
  301. package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
  302. package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
  303. package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
  304. package/packages/server/src/routes/provider-auth-routes.ts +181 -10
  305. package/packages/server/src/routes/provider-override-routes.ts +158 -0
  306. package/packages/server/src/routes/provider-routes.ts +348 -86
  307. package/packages/server/src/routes/resource-activation-routes.ts +18 -4
  308. package/packages/server/src/routes/session-routes.ts +75 -25
  309. package/packages/server/src/routes/system-routes.ts +169 -52
  310. package/packages/server/src/routes/ui-link-base.ts +88 -0
  311. package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
  312. package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
  313. package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
  314. package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
  315. package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
  316. package/packages/server/src/server.ts +1139 -291
  317. package/packages/server/src/services/cli-service.ts +59 -10
  318. package/packages/server/src/services/secrets-resolver.ts +46 -30
  319. package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
  320. package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
  321. package/packages/server/src/session/death-reason.ts +11 -7
  322. package/packages/server/src/session/event-status-extraction.ts +5 -1
  323. package/packages/server/src/session/hydration-state.ts +148 -0
  324. package/packages/server/src/session/memory-session-manager.ts +31 -2
  325. package/packages/server/src/session/open-tool-calls.ts +81 -47
  326. package/packages/server/src/session/pid-target.ts +127 -0
  327. package/packages/server/src/session/replay-compaction.ts +18 -5
  328. package/packages/server/src/session/replay-exit-controller.ts +221 -0
  329. package/packages/server/src/session/retained-transcript.ts +9 -2
  330. package/packages/server/src/session/seed-discovered-history.ts +85 -0
  331. package/packages/server/src/session/server-pid-context.ts +14 -0
  332. package/packages/server/src/session/session-api.ts +78 -29
  333. package/packages/server/src/session/session-archive.ts +7 -0
  334. package/packages/server/src/session/session-bootstrap.ts +9 -54
  335. package/packages/server/src/session/session-load-worker-pool.ts +11 -1
  336. package/packages/server/src/session/session-load-worker.ts +32 -4
  337. package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
  338. package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
  339. package/packages/server/src/spawn-process/headless-pid-registry.ts +393 -77
  340. package/packages/server/src/spawn-process/link-register.ts +42 -0
  341. package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
  342. package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
  343. package/packages/server/src/spawn-process/process-classifier.ts +8 -3
  344. package/packages/server/src/spawn-process/process-manager.ts +61 -6
  345. package/packages/server/src/spawn-process/restored-identity.ts +112 -0
  346. package/packages/server/src/spawn-process/session-terminator.ts +179 -18
  347. package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
  348. package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
  349. package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
  350. package/packages/server/src/sudo-credential/relay.ts +337 -0
  351. package/packages/server/src/terminal/terminal-gateway.ts +10 -0
  352. package/packages/server/src/terminal/terminal-manager.ts +54 -46
  353. package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
  354. package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
  355. package/packages/server/src/tls/tls-bridge-route.ts +61 -0
  356. package/packages/server/src/tls/tls-config-validation.ts +2 -0
  357. package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
  358. package/packages/server/src/vault/vault-delivery-hub.ts +172 -26
  359. package/packages/server/src/vault/vault-routes.ts +9 -2
  360. package/packages/server/src/vault/vault-store.ts +87 -24
  361. package/packages/server/src/watch-files-handler.ts +66 -0
  362. package/packages/server/vendor/xlsx/LICENSE +201 -0
  363. package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
  364. package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
  365. package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
  366. package/packages/shared/package.json +4 -2
  367. package/packages/shared/src/agent-credential-files.ts +32 -0
  368. package/packages/shared/src/browser-protocol.ts +285 -59
  369. package/packages/shared/src/canvas-declare.ts +27 -0
  370. package/packages/shared/src/canvas-detect.ts +1 -1
  371. package/packages/shared/src/canvas-types.ts +2 -2
  372. package/packages/shared/src/config.ts +443 -187
  373. package/packages/shared/src/containment-guard.ts +45 -0
  374. package/packages/shared/src/credential-encryption.ts +87 -0
  375. package/packages/shared/src/custom-event-groups.ts +2 -0
  376. package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
  377. package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
  378. package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
  379. package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
  380. package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
  381. package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
  382. package/packages/shared/src/dashboard-plugin/index.ts +2 -0
  383. package/packages/shared/src/dashboard-plugin/manifest-types.ts +100 -1
  384. package/packages/shared/src/dashboard-plugin/plugin-status.ts +58 -3
  385. package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
  386. package/packages/shared/src/dashboard-plugin/slot-props.ts +47 -3
  387. package/packages/shared/src/dashboard-plugin/slot-types.ts +9 -1
  388. package/packages/shared/src/dashboard-plugin/ui-primitives.ts +39 -3
  389. package/packages/shared/src/device-key-proof.ts +309 -0
  390. package/packages/shared/src/display-prefs.ts +13 -0
  391. package/packages/shared/src/doctor-core.ts +94 -27
  392. package/packages/shared/src/event-forward-declaration.ts +85 -12
  393. package/packages/shared/src/forbidden-subjects.ts +126 -14
  394. package/packages/shared/src/heap-limits.ts +0 -30
  395. package/packages/shared/src/host-admission.ts +2 -1
  396. package/packages/shared/src/index.ts +7 -6
  397. package/packages/shared/src/live-server.ts +161 -0
  398. package/packages/shared/src/local-proof-signal.ts +16 -0
  399. package/packages/shared/src/loopback-host.ts +26 -0
  400. package/packages/shared/src/mcp/verb-tiers.generated.ts +176 -0
  401. package/packages/shared/src/mdns-discovery.ts +25 -6
  402. package/packages/shared/src/models-json-reader.ts +41 -0
  403. package/packages/shared/src/nav-intent.ts +29 -0
  404. package/packages/shared/src/network-denial-signal.ts +15 -0
  405. package/packages/shared/src/node-version.ts +63 -60
  406. package/packages/shared/src/openspec-dependencies.ts +760 -0
  407. package/packages/shared/src/openspec-poller.ts +3 -2
  408. package/packages/shared/src/pairing-knock-client.ts +135 -11
  409. package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
  410. package/packages/shared/src/pi-path-compare.ts +31 -0
  411. package/packages/shared/src/pi-settings-schema.ts +52 -9
  412. package/packages/shared/src/pi-trust-live-query.ts +93 -0
  413. package/packages/shared/src/pi-trust-mirror-snapshot.ts +21 -11
  414. package/packages/shared/src/pi-trust-mirror-types.ts +38 -3
  415. package/packages/shared/src/pi-trust-mirror.ts +47 -11
  416. package/packages/shared/src/pi-trust-resource-digest.ts +261 -0
  417. package/packages/shared/src/pid-namespace.ts +86 -0
  418. package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
  419. package/packages/shared/src/platform/git-source.ts +88 -26
  420. package/packages/shared/src/platform/git.ts +14 -8
  421. package/packages/shared/src/platform/native-ts-register.mjs +1 -1
  422. package/packages/shared/src/platform/process.ts +452 -5
  423. package/packages/shared/src/platform/resolve-pi-shell.ts +105 -0
  424. package/packages/shared/src/platform/select-git-source.ts +7 -0
  425. package/packages/shared/src/platform/spawn-runtime.ts +193 -7
  426. package/packages/shared/src/plugin-route-cwd.ts +95 -0
  427. package/packages/shared/src/preview-egress.ts +192 -0
  428. package/packages/shared/src/preview-origins.ts +398 -0
  429. package/packages/shared/src/project-root.ts +16 -0
  430. package/packages/shared/src/prompt-answer.ts +9 -5
  431. package/packages/shared/src/protocol.ts +187 -86
  432. package/packages/shared/src/provider-env-catalog.ts +413 -0
  433. package/packages/shared/src/provider-overrides.ts +112 -0
  434. package/packages/shared/src/question-types.ts +6 -0
  435. package/packages/shared/src/recommended-extensions.ts +97 -26
  436. package/packages/shared/src/recovery-timing.ts +27 -0
  437. package/packages/shared/src/remote-credentials.ts +63 -0
  438. package/packages/shared/src/renderer-by-ext.ts +5 -2
  439. package/packages/shared/src/rest-api.ts +148 -11
  440. package/packages/shared/src/role-schema.ts +24 -0
  441. package/packages/shared/src/route-tiers.ts +149 -4
  442. package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
  443. package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
  444. package/packages/shared/src/runtime-overlay/compat.ts +70 -6
  445. package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
  446. package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
  447. package/packages/shared/src/safe-local-path.ts +24 -0
  448. package/packages/shared/src/sanitize-profiles.ts +98 -0
  449. package/packages/shared/src/secret-patterns.ts +49 -0
  450. package/packages/shared/src/server-launcher.ts +9 -1
  451. package/packages/shared/src/server-pinning.ts +55 -2
  452. package/packages/shared/src/server-routes.ts +462 -0
  453. package/packages/shared/src/session-ui-path.ts +11 -0
  454. package/packages/shared/src/source-matching.ts +2 -2
  455. package/packages/shared/src/state-replay.ts +40 -24
  456. package/packages/shared/src/sudo-credential.ts +71 -0
  457. package/packages/shared/src/tls-only-token.ts +16 -0
  458. package/packages/shared/src/tool-path-resolve.ts +16 -1
  459. package/packages/shared/src/tool-registry/definitions.ts +5 -5
  460. package/packages/shared/src/tool-registry/strategies.ts +13 -12
  461. package/packages/shared/src/tool-workdir.ts +56 -0
  462. package/packages/shared/src/trusted-types-mode.ts +72 -0
  463. package/packages/shared/src/types.ts +134 -109
  464. package/packages/shared/src/url-policy.ts +96 -0
  465. package/packages/shared/src/vault-delivery.ts +15 -0
  466. package/packages/shared/src/vertex-regions.ts +81 -0
  467. package/packages/shared/src/ws-message-tiers.ts +11 -3
  468. package/packages/extension/src/subagent-fanout-admission.ts +0 -234
  469. package/packages/extension/src/subagent-forward-sites.ts +0 -69
  470. package/packages/extension/src/subagent-frame-buffer.ts +0 -245
  471. package/packages/extension/src/subagent-frame-strip.ts +0 -109
  472. package/packages/extension/src/subagent-saturation.ts +0 -196
  473. package/packages/extension/src/subagent-tick-throttle.ts +0 -252
  474. package/packages/shared/src/anthropic-messages-source.ts +0 -8
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Path-bound containment guard for static analysis.
3
+ *
4
+ * `evaluateContainment` (packages/server/src/access/containment-gate.ts) is async and
5
+ * returns a decision CodeQL cannot see through. File routes therefore branch on this
6
+ * sync predicate right after the `await`; it is modelled as a `js/path-injection`
7
+ * barrier guard in `.github/codeql/extensions/cwd-guard.model.yml`.
8
+ *
9
+ * The decision carries the exact string it decided (`resolved`) and the predicate
10
+ * compares it by strict equality, so a decision for path A can never bless path B.
11
+ * `PathDecision` is branded (type-only): only `containment-gate.ts` casts to it.
12
+ *
13
+ * See change: codeql-file-containment-barrier.
14
+ */
15
+
16
+ /** Type-only brand: no runtime value exists, so no module can forge a `PathDecision` without a cast. */
17
+ export declare const pathDecisionBrand: unique symbol;
18
+
19
+ /** A containment verdict bound to the path it was made for. Built only by `containment-gate.ts`. */
20
+ export interface PathDecision {
21
+ readonly allowed: boolean;
22
+ /** True when the grant layer (not layers ①/②) admitted the path. */
23
+ readonly viaGrant: boolean;
24
+ /** The exact string passed to the decision function. */
25
+ readonly resolved: string;
26
+ /**
27
+ * The real path the decision was made on (symlinks resolved once). Callers open THIS, bound by
28
+ * `decidedReal`, never the lexical `resolved`. `undefined` on every refusal.
29
+ * See change: close-local-listener-and-egress-gaps.
30
+ */
31
+ readonly real: string | undefined;
32
+ readonly [pathDecisionBrand]: true;
33
+ }
34
+
35
+ /**
36
+ * True only when `decision` allowed AND was made for exactly `resolved` AND carries the real path it
37
+ * decided on (an admitting decision without `real` cannot bind an open, so it fails closed). Sync, so
38
+ * static analysis treats a branch on it as a guard for `resolved`; narrows `real` to `string`.
39
+ */
40
+ export function containmentAllows<D extends PathDecision>(
41
+ decision: D,
42
+ resolved: string,
43
+ ): decision is D & { readonly real: string } {
44
+ return decision.allowed === true && decision.resolved === resolved && decision.real !== undefined;
45
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Shared constants for credential-at-rest encryption: keychain identity, file
3
+ * ids, the envelope magic line, the lock/key reason codes and the fixed
4
+ * reason → remedy table (used by the vault status, the page and refusal
5
+ * messages). Import-free leaf: no node built-ins, safe for client bundles.
6
+ *
7
+ * Remedy texts are fixed, non-secret strings: never interpolate key material.
8
+ * See change: encrypt-credentials-at-rest (D3, D4, D5, D6, D12).
9
+ */
10
+
11
+ /** Keychain service. Distinct from `pi-dashboard`, which users own for `keychain:` refs (D4, D10). */
12
+ export const CREDENTIAL_KEYCHAIN_SERVICE = "pi-dashboard-credential-key";
13
+
14
+ /** Keychain account (item username). */
15
+ export const CREDENTIAL_KEYCHAIN_ACCOUNT = "data-key-v1";
16
+
17
+ /** Env var naming the explicit key file. When set it is the ONLY key source (D6). */
18
+ export const DATA_KEY_FILE_ENV = "PI_DASHBOARD_DATA_KEY_FILE";
19
+
20
+ /** Identity of an encrypted credential file; bound into the AEAD additional data. */
21
+ export const CREDENTIAL_FILE_IDS = ["plugin-credentials", "vault"] as const;
22
+ export type CredentialFileId = (typeof CREDENTIAL_FILE_IDS)[number];
23
+
24
+ /** On-disk basename of each credential file (the agent credential guard protects these). */
25
+ export const CREDENTIAL_FILE_BASENAMES: Readonly<Record<CredentialFileId, string>> = {
26
+ "plugin-credentials": "plugin-credentials.json",
27
+ vault: "vault.json",
28
+ };
29
+
30
+ /** Any file whose first line starts with this is an envelope and is never "corrupt" (D2). */
31
+ export const ENVELOPE_MAGIC_PREFIX = "pi-dashboard-encrypted:";
32
+
33
+ /** First line of a v1 envelope file. */
34
+ export const ENVELOPE_MAGIC_V1 = "pi-dashboard-encrypted:v1";
35
+
36
+ /** Reasons the data key is not available (the key state's reason). */
37
+ export const CREDENTIAL_KEY_FAILURE_REASONS = [
38
+ "keychain_unavailable",
39
+ "keychain_timeout",
40
+ "key_missing",
41
+ "key_file_missing",
42
+ "key_file_invalid",
43
+ "key_file_insecure",
44
+ "key_uninitialized",
45
+ ] as const;
46
+ export type CredentialKeyFailureReason = (typeof CREDENTIAL_KEY_FAILURE_REASONS)[number];
47
+
48
+ /** Reasons a file is locked: a key failure, or a problem with the envelope itself. */
49
+ export const CREDENTIAL_LOCK_REASONS = [
50
+ ...CREDENTIAL_KEY_FAILURE_REASONS,
51
+ "key_mismatch",
52
+ "unsupported_format",
53
+ "envelope_damaged",
54
+ ] as const;
55
+ export type CredentialLockReason = (typeof CREDENTIAL_LOCK_REASONS)[number];
56
+
57
+ /** Narrowing guard. An unknown future reason must still render as locked, never as ok. */
58
+ export function isCredentialLockReason(value: unknown): value is CredentialLockReason {
59
+ return typeof value === "string" && (CREDENTIAL_LOCK_REASONS as readonly string[]).includes(value);
60
+ }
61
+
62
+ const KEY_FILE_HINT =
63
+ `Set ${DATA_KEY_FILE_ENV} to an owner-only file holding \`openssl rand -base64 32\` and restart the server.`;
64
+ const RESET_HINT =
65
+ "Restore the key, or run `pi-dashboard credentials reset --vault` " +
66
+ "(`--plugin-credentials` for the plugin credential file) with the server stopped and enter the credentials again.";
67
+
68
+ /** Reason → remedy (decision G3). Every reason has a non-empty, non-secret remedy. */
69
+ export const CREDENTIAL_REASON_REMEDY: Readonly<Record<CredentialLockReason, string>> = {
70
+ keychain_unavailable: `The OS keychain cannot be used. ${KEY_FILE_HINT}`,
71
+ keychain_timeout: `The OS keychain did not answer in time. ${KEY_FILE_HINT}`,
72
+ key_missing: `The data key is missing. ${RESET_HINT}`,
73
+ key_file_missing: `The key file named by ${DATA_KEY_FILE_ENV} does not exist. ${KEY_FILE_HINT}`,
74
+ key_file_invalid: `The key file named by ${DATA_KEY_FILE_ENV} is not a readable base64 32-byte key. ${KEY_FILE_HINT}`,
75
+ key_file_insecure: `The key file named by ${DATA_KEY_FILE_ENV} is readable by other users. Run chmod 600 on it, then restart the server.`,
76
+ key_uninitialized: "The data key has not been loaded yet. Restart the server.",
77
+ key_mismatch: `The file was encrypted with a different key. ${RESET_HINT}`,
78
+ unsupported_format: "The file uses a newer encryption format. Upgrade the dashboard.",
79
+ envelope_damaged: "The encrypted file is damaged. Restore it from a backup, or reset it with `pi-dashboard credentials reset`.",
80
+ };
81
+
82
+ /** The remedy for a lock reason. Unknown reasons get the generic fallback. */
83
+ export function credentialRemedy(reason: string): string {
84
+ return isCredentialLockReason(reason)
85
+ ? CREDENTIAL_REASON_REMEDY[reason]
86
+ : "The credential file is locked. Check the dashboard server log.";
87
+ }
@@ -60,6 +60,8 @@ export const SHIPPED_CUSTOM_EVENT_GROUPS: readonly CustomEventGroup[] = [
60
60
  { id: "goals", label: "Goals", pattern: "^pi-goal-hermes:", default: true },
61
61
  // Forensic records (subagent fan-out admission refusals). Hidden by default:
62
62
  // the refused tool call already shows its reason. See change: render-unclaimed-custom-entries.
63
+ // No longer written (the admission gate was removed, change: subagent-queue-visibility);
64
+ // kept so OLD transcripts still carrying these entries stay hidden by default.
63
65
  { id: "diagnostics", label: "Diagnostics", pattern: "^subagent-admission-refused$", default: false },
64
66
  ];
65
67
 
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Claude subscription compat — rewrites pi's built-in `docs` prompt section.
3
+ *
4
+ * Anthropic bills a Claude subscription request as "extra usage" when pi's
5
+ * default `docs` section carries the lines "pi itself" and "pi packages".
6
+ * When the dashboard compat switch is on and the model provider is
7
+ * `anthropic`, the handlers replace exactly those two phrases inside that one
8
+ * section. They never force the whole prompt, never touch other sections, and
9
+ * never rename tools.
10
+ *
11
+ * `before_agent_start` (pi 1.4.0): an extension-supplied `sections.docs`
12
+ * replaces the built-in section; the body is read from the rendered
13
+ * `event.systemPrompt`, anchored on pi's first docs line, rewritten only when
14
+ * exactly one such block exists.
15
+ *
16
+ * `before_provider_request`: pi 1.4 sends a session's FIRST system message as
17
+ * Anthropic's `system` field for the session's whole life (pi-ai
18
+ * `anthropic-messages.js` buildParams); a later section change reaches the
19
+ * wire only as a mid-conversation patch. So the outgoing `system` text is
20
+ * rewritten too, covering sessions started before the switch was on.
21
+ *
22
+ * The dashboard extension registers `claudeCompatExtension` on EVERY pi it
23
+ * loads into (main sessions, subagent children, any session built from the
24
+ * settings packages), so no plugin or package must opt in.
25
+ *
26
+ * See change: retire-anthropic-messages-bridge (design D1, D2, D6b),
27
+ * seed-claude-compat-on-upgrade.
28
+ */
29
+
30
+ const DOCS_BLOCK_RE = /<docs>\n(Pi documentation \([\s\S]*?)\n<\/docs>/g;
31
+ const REPLACEMENTS: ReadonlyArray<readonly [string, string]> = [
32
+ ["pi itself", "the cli itself"],
33
+ ["pi packages", "cli packages"],
34
+ ];
35
+
36
+ type CompatState = "applied" | "off" | "not-anthropic" | "custom-or-forced" | "no-match";
37
+
38
+ /** Replace the flagged phrases. Idempotent: rewritten text has none left. */
39
+ export function rewriteDocsSection(text: string): { text: string; replaced: number } {
40
+ let out = text;
41
+ let replaced = 0;
42
+ for (const [from, to] of REPLACEMENTS) {
43
+ const parts = out.split(from);
44
+ replaced += parts.length - 1;
45
+ out = parts.join(to);
46
+ }
47
+ return { text: out, replaced };
48
+ }
49
+
50
+ /** Body of pi's built-in docs section when the prompt holds exactly one anchored block. */
51
+ function extractDocsBody(systemPrompt: string): { body: string } | { count: number } {
52
+ const matches = [...systemPrompt.matchAll(DOCS_BLOCK_RE)];
53
+ if (matches.length !== 1) return { count: matches.length };
54
+ return { body: matches[0]![1]! };
55
+ }
56
+
57
+ interface PromptOptionsLike {
58
+ sections?: Record<string, string>;
59
+ customPrompt?: string;
60
+ forceSystemPrompt?: string;
61
+ }
62
+
63
+ interface BeforeAgentStartLike {
64
+ systemPrompt?: string;
65
+ systemPromptOptions?: PromptOptionsLike;
66
+ }
67
+
68
+ interface PiLike {
69
+ on(name: string, handler: (event: unknown, ctx: unknown) => unknown): unknown;
70
+ }
71
+
72
+ function decide(event: BeforeAgentStartLike, ctx: unknown, switchOn: boolean): { state: CompatState; docs?: string } {
73
+ if (!switchOn) return { state: "off" };
74
+ const provider = (ctx as { model?: { provider?: unknown } } | undefined)?.model?.provider;
75
+ if (provider !== "anthropic") return { state: "not-anthropic" };
76
+ const opts = event.systemPromptOptions;
77
+ if (!opts || typeof opts !== "object") return { state: "custom-or-forced" };
78
+ if (opts.customPrompt || opts.forceSystemPrompt !== undefined) return { state: "custom-or-forced" };
79
+ const found = extractDocsBody(typeof event.systemPrompt === "string" ? event.systemPrompt : "");
80
+ if ("count" in found) return { state: found.count === 0 ? "custom-or-forced" : "no-match" };
81
+ const { text, replaced } = rewriteDocsSection(found.body);
82
+ if (replaced === 0) return { state: "no-match" };
83
+ return { state: "applied", docs: text };
84
+ }
85
+
86
+ type SystemBlock = { type?: unknown; text?: unknown };
87
+
88
+ /**
89
+ * Rewrite the one anchored docs block in an Anthropic payload's `system`
90
+ * (string or text-block array). Returns a new payload, or `undefined` when
91
+ * there is nothing to change: no `system`, zero or several anchored blocks
92
+ * across all system text, or no flagged phrase left.
93
+ */
94
+ export function rewritePayloadSystem(payload: unknown): unknown {
95
+ if (!payload || typeof payload !== "object") return undefined;
96
+ const system = (payload as { system?: unknown }).system;
97
+ const texts: string[] =
98
+ typeof system === "string"
99
+ ? [system]
100
+ : Array.isArray(system)
101
+ ? system.map((b: SystemBlock) => (b && b.type === "text" && typeof b.text === "string" ? b.text : ""))
102
+ : [];
103
+ const blockCounts = texts.map((t) => [...t.matchAll(DOCS_BLOCK_RE)].length);
104
+ if (blockCounts.reduce((a, b) => a + b, 0) !== 1) return undefined;
105
+ const idx = blockCounts.indexOf(1);
106
+ let replaced = 0;
107
+ const newText = texts[idx]!.replace(DOCS_BLOCK_RE, (_whole, body: string) => {
108
+ const r = rewriteDocsSection(body);
109
+ replaced = r.replaced;
110
+ return `<docs>\n${r.text}\n</docs>`;
111
+ });
112
+ if (replaced === 0) return undefined;
113
+ const newSystem =
114
+ typeof system === "string"
115
+ ? newText
116
+ : (system as SystemBlock[]).map((b, i) => (i === idx ? { ...b, text: newText } : b));
117
+ return { ...(payload as object), system: newSystem };
118
+ }
119
+
120
+ /**
121
+ * Extension factory. `readSwitch` returns the live switch value. One factory
122
+ * call per pi instance keeps its own log state, so
123
+ * each session or agent logs its state once and again only on change.
124
+ */
125
+ export function claudeCompatExtension(readSwitch: () => boolean): (pi: PiLike) => void {
126
+ return (pi: PiLike) => {
127
+ if (!pi || typeof pi.on !== "function") return;
128
+ let lastState: CompatState | undefined;
129
+ pi.on("before_agent_start", (event: unknown, ctx: unknown) => {
130
+ try {
131
+ const e = (event ?? {}) as BeforeAgentStartLike;
132
+ const { state, docs } = decide(e, ctx, readSwitch());
133
+ if (docs !== undefined && e.systemPromptOptions) {
134
+ e.systemPromptOptions.sections ??= {};
135
+ e.systemPromptOptions.sections.docs = docs;
136
+ }
137
+ if (state !== lastState) {
138
+ lastState = state;
139
+ const line = `[dashboard] claude-compat: state=${state}`;
140
+ if (state === "no-match") console.warn(`${line} (switch on, but pi's docs wording did not match; requests may be billed as extra usage)`);
141
+ else console.log(line);
142
+ }
143
+ } catch {
144
+ /* compat is best-effort; never block a run */
145
+ }
146
+ return undefined;
147
+ });
148
+ pi.on("before_provider_request", (event: unknown, ctx: unknown) => {
149
+ try {
150
+ if (!readSwitch()) return undefined;
151
+ const provider = (ctx as { model?: { provider?: unknown } } | undefined)?.model?.provider;
152
+ if (provider !== "anthropic") return undefined;
153
+ return rewritePayloadSystem((event as { payload?: unknown } | undefined)?.payload);
154
+ } catch {
155
+ return undefined; /* best-effort; never block a request */
156
+ }
157
+ });
158
+ };
159
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Plugin event-type ownership — pure pattern matching.
3
+ *
4
+ * A plugin manifest declares `eventTypes`: exact names or `prefix_*` (a single
5
+ * trailing `*`). The shell reads ownership from every registered plugin's
6
+ * manifest (enabled or not) and never hard-codes a plugin prefix.
7
+ * See change: decouple-plugins-from-core (design D5 item 2).
8
+ */
9
+
10
+ /** One plugin's declared event types, as read from its manifest summary. */
11
+ export interface EventTypeOwner {
12
+ ownerId: string;
13
+ displayName: string;
14
+ eventTypes: readonly string[];
15
+ }
16
+
17
+ const PATTERN = /^[A-Za-z0-9_.:-]+\*?$/;
18
+
19
+ /** An exact event name, or a name followed by a single trailing `*`. */
20
+ export function isValidEventTypePattern(pattern: string): boolean {
21
+ return PATTERN.test(pattern);
22
+ }
23
+
24
+ /** Trailing `*` = prefix glob; otherwise exact equality. */
25
+ export function matchesEventTypePattern(pattern: string, eventType: string): boolean {
26
+ return pattern.endsWith("*") ? eventType.startsWith(pattern.slice(0, -1)) : pattern === eventType;
27
+ }
28
+
29
+ /**
30
+ * Owner of `eventType`, or undefined. An exact declaration beats a prefix glob;
31
+ * among globs the longest prefix wins; ties keep the earlier owner.
32
+ */
33
+ export function matchEventTypeOwner(
34
+ owners: readonly EventTypeOwner[],
35
+ eventType: string,
36
+ ): EventTypeOwner | undefined {
37
+ let best: EventTypeOwner | undefined;
38
+ let bestScore = -1;
39
+ for (const owner of owners) {
40
+ for (const pattern of owner.eventTypes) {
41
+ if (!matchesEventTypePattern(pattern, eventType)) continue;
42
+ const score = pattern.endsWith("*") ? pattern.length - 1 : Number.MAX_SAFE_INTEGER;
43
+ if (score > bestScore) {
44
+ best = owner;
45
+ bestScore = score;
46
+ }
47
+ }
48
+ }
49
+ return best;
50
+ }
@@ -49,6 +49,8 @@ export interface FileHandlerClaimMeta {
49
49
  maxBytes?: number;
50
50
  firstOverwriteNotice?: string;
51
51
  copySuffix?: string;
52
+ /** Edit mode: native sibling extensions (`write-binary?mode=copy&siblingExt=`). See change: extend-craft-web-to-all-apps (D6). */
53
+ siblingExtensions?: string[];
52
54
  validator?: boolean;
53
55
  }
54
56
 
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Plugin host API version contract (design D7).
3
+ *
4
+ * `PLUGIN_HOST_API_VERSION` is the semver of the public runtime surface
5
+ * (`dashboard-plugin-runtime/src/public.ts` + `./sdk`), NOT the package release
6
+ * version. A plugin manifest declares the range it was built against in
7
+ * `hostApi`; discovery evaluates it. Written in-house: caret + exact only, no
8
+ * semver dependency (shared stays dependency-free).
9
+ *
10
+ * See change: decouple-plugins-from-core.
11
+ */
12
+
13
+ /** Current host API version. Bump per the snapshot rules in `scripts/host-api-surface.mjs`. */
14
+ export const PLUGIN_HOST_API_VERSION = "2.2.0";
15
+
16
+ /** A manifest `hostApi` range: `^MAJOR.MINOR[.PATCH]` or an exact `MAJOR.MINOR.PATCH`. */
17
+ export type HostApiRange = string;
18
+
19
+ const NUM = "(0|[1-9]\\d*)";
20
+ const VERSION_RE = new RegExp(`^${NUM}\\.${NUM}\\.${NUM}$`);
21
+ const CARET_RE = new RegExp(`^\\^${NUM}\\.${NUM}(?:\\.${NUM})?$`);
22
+
23
+ type Triple = readonly [number, number, number];
24
+
25
+ function parseVersion(version: string): Triple | null {
26
+ const m = VERSION_RE.exec(version);
27
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
28
+ }
29
+
30
+ /** True when `range` is syntactically valid (caret `^MAJOR.MINOR[.PATCH]` or exact `MAJOR.MINOR.PATCH`). */
31
+ export function isValidHostApiRange(range: unknown): range is HostApiRange {
32
+ return typeof range === "string" && (CARET_RE.test(range) || VERSION_RE.test(range));
33
+ }
34
+
35
+ function compare(a: Triple, b: Triple): number {
36
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
37
+ }
38
+
39
+ /**
40
+ * Does `version` (`MAJOR.MINOR.PATCH`) satisfy `range`? Caret follows semver:
41
+ * `^1.2` = `>=1.2.0 <2.0.0`, `^0.9.0` = `>=0.9.0 <0.10.0`, `^0.0.3` = exactly `0.0.3`.
42
+ * An exact range matches only that version. Invalid input never satisfies.
43
+ */
44
+ export function satisfiesHostApiRange(version: string, range: string): boolean {
45
+ const v = parseVersion(version);
46
+ if (!v) return false;
47
+ const exact = parseVersion(range);
48
+ if (exact) return compare(v, exact) === 0;
49
+ const m = CARET_RE.exec(range);
50
+ if (!m) return false;
51
+ const low: Triple = [Number(m[1]), Number(m[2]), m[3] === undefined ? 0 : Number(m[3])];
52
+ if (compare(v, low) < 0) return false;
53
+ if (low[0] > 0) return v[0] === low[0];
54
+ if (low[1] > 0 || m[3] === undefined) return v[0] === 0 && v[1] === low[1];
55
+ return v[0] === 0 && v[1] === 0 && v[2] === low[2];
56
+ }
57
+
58
+ /** `satisfiesHostApiRange` bound to {@link PLUGIN_HOST_API_VERSION} — the HOST's version, never a bundled copy's. */
59
+ export function satisfiesHostApi(range: string): boolean {
60
+ return satisfiesHostApiRange(PLUGIN_HOST_API_VERSION, range);
61
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Host-owned global CSS FX class names a plugin may apply by name (session-card
3
+ * stripes / glow / ring). The rules live in `packages/client/src/index.css`, gated
4
+ * by `prefers-reduced-motion` and the `data-fx-*` user toggles. Plugin code uses
5
+ * these constants instead of literal class strings so a rename is one edit and the
6
+ * host API surface snapshot (`host-api-surface.json`) records every value.
7
+ *
8
+ * See change: decouple-plugins-from-core (design D6/D7).
9
+ */
10
+ export const HOST_FX_CLASSES = {
11
+ /** Diagonal-stripes overlay base. */
12
+ stripes: "card-stripes-fx",
13
+ /** Animated modifier of `stripes` for a running card. */
14
+ stripesRunning: "card-stripes-running",
15
+ /** Static neon glow overlay of a selected card. */
16
+ glow: "card-glow-fx",
17
+ /** Wider outer glow layer, paired with `glow`. */
18
+ glowOuter: "card-glow-fx-outer",
19
+ /** Rim ring of a selected card. */
20
+ ring: "card-ring-fx",
21
+ } as const;
22
+
23
+ export type HostFxClass = (typeof HOST_FX_CLASSES)[keyof typeof HOST_FX_CLASSES];
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The host import map (design D9/D21): bare specifier → URL of the host-built shim entry
3
+ * (`dist/host/<name>.js`, built by the client's rollup `input`, task 6.3).
4
+ *
5
+ * ONE list shared by the server (`sendIndexWithImportMap`) and the host-API surface snapshot
6
+ * (`scripts/host-api-surface.mjs` `IMPORT_MAP_SPECIFIERS`, kept in lock-step by a server test).
7
+ * Phase 6 appended `embedded-app`, `app-kit/react` and `wouter` (task 7.1).
8
+ *
9
+ * See change: decouple-plugins-from-core (tasks 6.3, 6.4).
10
+ */
11
+
12
+ /** `@blackbelt-technology/dashboard-plugin-runtime`, built by concatenation (pnpm contract test scans literals for undeclared workspace imports). */
13
+ export const HOST_RUNTIME_SPECIFIER = `${"@blackbelt-technology"}/dashboard-plugin-runtime`;
14
+
15
+ /** `@blackbelt-technology/dashboard-plugin-runtime/embedded-app` (concatenated for the same reason). */
16
+ export const HOST_EMBEDDED_APP_SPECIFIER = `${HOST_RUNTIME_SPECIFIER}/embedded-app`;
17
+
18
+ /** `@blackbelt-technology/pi-dashboard-app-kit/react` (concatenated: shared does not depend on app-kit). */
19
+ export const HOST_APP_KIT_REACT_SPECIFIER = `${"@blackbelt-technology"}/pi-dashboard-app-kit/react`;
20
+
21
+ /** Specifier → shim URL, in map order. */
22
+ export const HOST_IMPORT_MAP_IMPORTS: Readonly<Record<string, string>> = Object.freeze({
23
+ react: "/host/react.js",
24
+ "react/jsx-runtime": "/host/react-jsx-runtime.js",
25
+ "react-dom": "/host/react-dom.js",
26
+ "react-dom/client": "/host/react-dom-client.js",
27
+ [HOST_RUNTIME_SPECIFIER]: "/host/runtime.js",
28
+ [HOST_EMBEDDED_APP_SPECIFIER]: "/host/embedded-app.js",
29
+ [HOST_APP_KIT_REACT_SPECIFIER]: "/host/app-kit-react.js",
30
+ wouter: "/host/wouter.js",
31
+ });
32
+
33
+ export const HOST_IMPORT_MAP_SPECIFIERS: readonly string[] = Object.freeze(Object.keys(HOST_IMPORT_MAP_IMPORTS));
34
+
35
+ /** The static `<script type="importmap">` body. Deterministic: identical bytes on every call. */
36
+ export function hostImportMapJson(): string {
37
+ return JSON.stringify({ imports: HOST_IMPORT_MAP_IMPORTS });
38
+ }
@@ -7,6 +7,8 @@
7
7
  */
8
8
 
9
9
  export * from "./file-handler.js";
10
+ export * from "./host-api.js";
11
+ export * from "./host-fx-classes.js";
10
12
  export * from "./intent-types.js";
11
13
  export * from "./manifest-types.js";
12
14
  export * from "./plugin-status.js";
@@ -78,6 +78,13 @@ export interface PluginClaim {
78
78
  firstOverwriteNotice?: string;
79
79
  /** For `editor-pane-file-handler` edit mode: `<stem>.<copySuffix>.<ext>` suffix, `^[a-z][a-z0-9-]{1,31}$` (required for edit). */
80
80
  copySuffix?: string;
81
+ /**
82
+ * For `editor-pane-file-handler` edit mode: native-format extensions a save may create as a NEW sibling
83
+ * `<stem><ext>` next to the tab's file (never-overwrite). Same per-extension rules as `extensions`, disjoint
84
+ * from them; edit claims only. An older runtime drops the key (saves then go to the device).
85
+ * See change: extend-craft-web-to-all-apps (D6).
86
+ */
87
+ siblingExtensions?: string[];
81
88
  /**
82
89
  * For `editor-pane-file-handler`: `true` = saves require the plugin's
83
90
  * `ctx.registerFileValidator` validator; fail closed (503) while it is not loaded.
@@ -204,6 +211,52 @@ export interface PluginClaim {
204
211
  * See change: auto-hide-empty-session-subcards.
205
212
  */
206
213
  shouldRender?: string;
214
+ /**
215
+ * `tool-renderer` claims only: when true the tool row starts EXPANDED while
216
+ * its status is `running` (the card is the live progress surface). Replaces
217
+ * the shell's hard-coded per-tool auto-expand. Absent = false.
218
+ * See change: decouple-plugins-from-core (design D5 item 7).
219
+ */
220
+ expandWhileRunning?: boolean;
221
+ /**
222
+ * `tool-renderer` claims only: exported sync predicate name
223
+ * `(toolDetails, session) => boolean` that says the row's result never reached
224
+ * this browser; the shell then shows its neutral "recovered" badge. `session`
225
+ * is `ToolContext.session`. MUST be synchronous.
226
+ * See change: decouple-plugins-from-core (design D5 item 7).
227
+ */
228
+ resultPending?: string;
229
+ /**
230
+ * `tool-renderer` claims only: exported sync predicate name
231
+ * `(toolDetails, session) => boolean`. True = a COMPLETE row opens expanded
232
+ * (mount seed, and on each running→complete transition until the user toggles).
233
+ * A throw or non-boolean counts as false. MUST be synchronous.
234
+ * See change: add-agent-control-renderer (design D3).
235
+ */
236
+ expandWhenComplete?: string;
237
+ /**
238
+ * `tool-renderer` claims only: exported sync fn name
239
+ * `(toolDetails, session) => { state: "queued" | "stopped"; label?: string } | undefined`.
240
+ * `queued` replaces the spinner/elapsed badge of a RUNNING row with a static
241
+ * clock + label; `stopped` replaces the success check of a non-error terminal
242
+ * row with a neutral stop glyph. Error and elided rows are never overridden.
243
+ * MUST be synchronous. See change: subagent-queue-visibility (design D2).
244
+ */
245
+ rowStatus?: string;
246
+ /**
247
+ * `tool-renderer` claims only: exported fn name
248
+ * `({ sessionId, toolCallId, toolDetails }) => boolean` consulted BEFORE the
249
+ * row's own abort and before an enclosing burst-group stop controller.
250
+ * `true` consumes the click; otherwise the existing stop path runs.
251
+ * See change: subagent-queue-visibility (design D2).
252
+ */
253
+ stop?: string;
254
+ /**
255
+ * `tool-renderer` claims only: exported fn name
256
+ * `(toolDetails) => string | undefined` supplying the row stop's accessible
257
+ * label. See change: subagent-queue-visibility (design D2).
258
+ */
259
+ stopLabel?: string;
207
260
  }
208
261
 
209
262
  /**
@@ -221,6 +274,13 @@ export interface PluginRequirements {
221
274
  /** pi extension package identifiers (matched via the same logic
222
275
  RECOMMENDED_EXTENSIONS uses: name / id / source / displayName). */
223
276
  piExtensions?: string[];
277
+ /**
278
+ * Minimum installed version per pi extension package name (semver range,
279
+ * e.g. `">=0.7.0"`). An unmet range is listed in `missingRequirements` as
280
+ * `<name> <range>`. A git/local install without a valid version counts as
281
+ * satisfied (warning in plugin status). See change: move-subagents-to-plugin (D9).
282
+ */
283
+ piExtensionVersions?: Record<string, string>;
224
284
  /** Binaries that must resolve on PATH via the tool-registry. */
225
285
  binaries?: string[];
226
286
  /** Named service probes (closed built-in registry; "model-proxy" only in V1). */
@@ -283,8 +343,16 @@ export interface PluginManifest {
283
343
  * Default 1000. First-party plugins use 100.
284
344
  */
285
345
  priority?: number;
286
- /** Relative path to the bundled client entry (from package root). */
346
+ /** Relative path to the bundled client entry (from package root). The build-time source entry. */
287
347
  client?: string;
348
+ /**
349
+ * Package-relative path to a PREBUILT ES entry module for runtime delivery. Its directory is the
350
+ * served asset root and must be a dedicated client output dir (not the package root, no server/bridge
351
+ * entry inside). See change: decouple-plugins-from-core (design D10).
352
+ */
353
+ clientBundle?: string;
354
+ /** Package-relative path to a prebuilt CSS file; must lie inside the `clientBundle` directory. */
355
+ clientStyles?: string;
288
356
  /** Optional relative path to the server entry. */
289
357
  server?: string;
290
358
  /** Optional relative path to a pi-extension/bridge entry. */
@@ -347,6 +415,37 @@ export interface PluginManifest {
347
415
  * while this plugin is loaded and enabled. See change: add-project-scoped-apps.
348
416
  */
349
417
  projectTypes?: ProjectTypeRule[];
418
+ /**
419
+ * Event types this plugin owns: exact names or `prefix_*` (one trailing `*`).
420
+ * The shell groups an owned event that no reducer slice consumed into one row
421
+ * per type and names this plugin when it is unavailable. Ownership is known
422
+ * for every registered plugin, enabled or not.
423
+ * See change: decouple-plugins-from-core (design D5).
424
+ */
425
+ eventTypes?: string[];
426
+ /**
427
+ * Event types this plugin may emit into sessions via `ctx.emitEventToSession`
428
+ * (exact names, no reserved host prefix). Absent / empty = emits nothing.
429
+ * Distinct from the inbound `eventTypes`. Enforced at the server seam.
430
+ * See change: harden-git-terminal-plugin-boundaries (D16).
431
+ */
432
+ emits?: string[];
433
+ /**
434
+ * Persisted `type: "custom"` entry types this plugin owns (e.g. flows:
435
+ * `["flow-event"]`). An enabled plugin's types replay as their recorded
436
+ * `{ seq, eventType, data }` protocol events; every declared type is kept out
437
+ * of the generic custom-entry rendering. Malformed values contribute nothing.
438
+ * See change: update-flows-plugin (D3).
439
+ */
440
+ replayEntryTypes?: string[];
441
+ /**
442
+ * Host API range this plugin was built against: `^MAJOR.MINOR[.PATCH]` or an
443
+ * exact `MAJOR.MINOR.PATCH`. Evaluated at discovery against
444
+ * `PLUGIN_HOST_API_VERSION`; one range covers the server and client halves.
445
+ * Required for `pi-package`-source plugins and `clientBundle` plugins.
446
+ * See change: decouple-plugins-from-core (design D7).
447
+ */
448
+ hostApi?: string;
350
449
  }
351
450
 
352
451
  /**