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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/README.md +38 -5
  2. package/docs/architecture.md +1673 -75
  3. package/package.json +23 -15
  4. package/packages/extension/package.json +8 -8
  5. package/packages/extension/src/ask-user-tool.ts +65 -3
  6. package/packages/extension/src/auto-session-namer.ts +190 -50
  7. package/packages/extension/src/bridge-handlers/dispatch.ts +450 -0
  8. package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
  9. package/packages/extension/src/bridge-handlers/instance.ts +220 -0
  10. package/packages/extension/src/bridge-handlers/lifecycle.ts +1030 -0
  11. package/packages/extension/src/bridge-handlers/ui-prompt-patch.ts +198 -0
  12. package/packages/extension/src/bridge-identity-log.ts +45 -0
  13. package/packages/extension/src/bridge.ts +480 -2510
  14. package/packages/extension/src/command-handler.ts +180 -11
  15. package/packages/extension/src/connection.ts +265 -18
  16. package/packages/extension/src/dashboard-context-injector.ts +26 -47
  17. package/packages/extension/src/empty-actionable-guard.ts +8 -3
  18. package/packages/extension/src/flow-event-wiring.ts +1 -1
  19. package/packages/extension/src/followup-buffer.ts +1 -1
  20. package/packages/extension/src/followup-drain.ts +79 -0
  21. package/packages/extension/src/local-token-header.ts +161 -17
  22. package/packages/extension/src/message-update-coalescer.ts +3 -1
  23. package/packages/extension/src/model-refresh.ts +19 -0
  24. package/packages/extension/src/multiselect-list.ts +6 -2
  25. package/packages/extension/src/multiselect-polyfill.ts +2 -2
  26. package/packages/extension/src/openspec-cli-shim.ts +1 -1
  27. package/packages/extension/src/path-gate/decide.ts +15 -41
  28. package/packages/extension/src/path-gate/grant-cache.ts +3 -1
  29. package/packages/extension/src/path-gate/handler.ts +51 -2
  30. package/packages/extension/src/path-gate/index.ts +12 -1
  31. package/packages/extension/src/path-gate/resolve.ts +6 -124
  32. package/packages/extension/src/path-gate/roots.ts +4 -1
  33. package/packages/extension/src/path-gate/suppression.ts +4 -1
  34. package/packages/extension/src/path-gate/yolo-link.ts +104 -0
  35. package/packages/extension/src/plugin-event-forward-registry.ts +200 -0
  36. package/packages/extension/src/project-trust.ts +119 -25
  37. package/packages/extension/src/prompt-expander.ts +5 -1
  38. package/packages/extension/src/prompt-meta.ts +64 -0
  39. package/packages/extension/src/provider-register.ts +87 -20
  40. package/packages/extension/src/role-manager.ts +5 -4
  41. package/packages/extension/src/server-auto-start.ts +12 -5
  42. package/packages/extension/src/server-launcher.ts +11 -13
  43. package/packages/extension/src/session-move.ts +19 -0
  44. package/packages/extension/src/session-sync.ts +31 -38
  45. package/packages/extension/src/spawn-token.ts +46 -0
  46. package/packages/extension/src/stream-forward-buffer.ts +161 -0
  47. package/packages/extension/src/subagent-frame-buffer.ts +6 -2
  48. package/packages/extension/src/subagent-tick-throttle.ts +3 -1
  49. package/packages/extension/src/vault-delivery.ts +394 -0
  50. package/packages/extension/src/vault-forwarder.ts +128 -0
  51. package/packages/extension/src/vault-masker.ts +165 -0
  52. package/packages/extension/src/vault-redaction.ts +181 -0
  53. package/packages/extension/src/vcs-info.ts +5 -2
  54. package/packages/server/bin/pi-dashboard.mjs +26 -89
  55. package/packages/server/package.json +29 -15
  56. package/packages/server/src/access/access-grants.ts +18 -0
  57. package/packages/server/src/access/agent-confirm-registry.ts +31 -13
  58. package/packages/server/src/access/agent-grant.ts +1 -1
  59. package/packages/server/src/access/agent-yolo.ts +91 -0
  60. package/packages/server/src/access/containment-gate.ts +28 -1
  61. package/packages/server/src/access/cwd-admission-log.ts +46 -0
  62. package/packages/server/src/access/cwd-verdict.ts +144 -0
  63. package/packages/server/src/access/grant-coordinator.ts +3 -1
  64. package/packages/server/src/access/pi-trust-mirror-service.ts +374 -0
  65. package/packages/server/src/access/planes.ts +10 -1
  66. package/packages/server/src/access/refusal-ledger.ts +6 -6
  67. package/packages/server/src/access/yolo-session.ts +73 -12
  68. package/packages/server/src/acp-bridge/acp-connection.ts +225 -0
  69. package/packages/server/src/acp-bridge/acp-restore.ts +41 -0
  70. package/packages/server/src/acp-bridge/acp-session-adapter.ts +544 -0
  71. package/packages/server/src/acp-bridge/child-env.ts +73 -0
  72. package/packages/server/src/acp-bridge/event-log.ts +194 -0
  73. package/packages/server/src/acp-bridge/gateway-client.ts +136 -0
  74. package/packages/server/src/acp-bridge/local-bridge-socket.ts +67 -0
  75. package/packages/server/src/acp-bridge/local-host.ts +132 -0
  76. package/packages/server/src/acp-bridge/main.ts +118 -0
  77. package/packages/server/src/acp-bridge/models.ts +33 -0
  78. package/packages/server/src/acp-bridge/permission-bridge.ts +106 -0
  79. package/packages/server/src/acp-bridge/server-requests.ts +136 -0
  80. package/packages/server/src/acp-bridge/session-state.ts +127 -0
  81. package/packages/server/src/addons/addon-toggle-restore.ts +110 -0
  82. package/packages/server/src/addons/addons-catalog.ts +408 -0
  83. package/packages/server/src/addons/addons-folder-service.ts +347 -0
  84. package/packages/server/src/addons/addons-folder.ts +310 -0
  85. package/packages/server/src/addons/addons-service.ts +470 -0
  86. package/packages/server/src/addons/package-contents.ts +99 -0
  87. package/packages/server/src/addons/settings-entries.ts +120 -0
  88. package/packages/server/src/attachments/fit-worker-pool.ts +12 -17
  89. package/packages/server/src/auth/approval-refusal.ts +87 -0
  90. package/packages/server/src/auth/auth-plugin.ts +292 -79
  91. package/packages/server/src/auth/auth.ts +78 -7
  92. package/packages/server/src/auth/bearer-auth.ts +23 -1
  93. package/packages/server/src/auth/cors-origin.ts +10 -0
  94. package/packages/server/src/auth/csp.ts +6 -0
  95. package/packages/server/src/auth/host-admission.ts +26 -0
  96. package/packages/server/src/auth/host-gate.ts +6 -1
  97. package/packages/server/src/auth/local-credential.ts +258 -0
  98. package/packages/server/src/auth/local-proof.ts +7 -4
  99. package/packages/server/src/auth/local-token.ts +16 -0
  100. package/packages/server/src/auth/localhost-guard.ts +251 -8
  101. package/packages/server/src/auth/network-trust-telemetry.ts +126 -0
  102. package/packages/server/src/auth/node-guard.ts +43 -0
  103. package/packages/server/src/auth/operate-required.ts +126 -0
  104. package/packages/server/src/auth/passkey/challenge-store.ts +90 -0
  105. package/packages/server/src/auth/passkey/passkey-log.ts +34 -0
  106. package/packages/server/src/auth/passkey/passkey-pages.ts +173 -0
  107. package/packages/server/src/auth/passkey/passkey-routes.ts +224 -0
  108. package/packages/server/src/auth/passkey/passkey-service.ts +247 -0
  109. package/packages/server/src/auth/passkey/phone-signin.ts +211 -0
  110. package/packages/server/src/auth/passkey/requester.ts +83 -0
  111. package/packages/server/src/auth/passkey/rp-context.ts +98 -0
  112. package/packages/server/src/auth/passkey/user-directory.ts +348 -0
  113. package/packages/server/src/auth/pi-legacy-credentials.ts +321 -0
  114. package/packages/server/src/auth/provider-auth-registry.ts +35 -1
  115. package/packages/server/src/auth/provider-auth-storage.ts +55 -8
  116. package/packages/server/src/auth/radius-override.ts +13 -0
  117. package/packages/server/src/auth/route-tier-gate.ts +27 -11
  118. package/packages/server/src/auth/runtime-provider-catalogue.ts +107 -0
  119. package/packages/server/src/auth/scan-legacy-provider-ids.ts +80 -0
  120. package/packages/server/src/auth/serve-app-host.ts +97 -0
  121. package/packages/server/src/auth/trust-mode-boot.ts +93 -0
  122. package/packages/server/src/auth/trust-mode.ts +83 -0
  123. package/packages/server/src/auto-name-outcome-store.ts +4 -1
  124. package/packages/server/src/browse.ts +114 -2
  125. package/packages/server/src/browser-handlers/acp-guard.ts +79 -0
  126. package/packages/server/src/browser-handlers/directory-handler.ts +128 -6
  127. package/packages/server/src/browser-handlers/session-action-handler.ts +129 -62
  128. package/packages/server/src/browser-handlers/session-meta-handler.ts +16 -6
  129. package/packages/server/src/browser-handlers/spawn-choice.ts +99 -0
  130. package/packages/server/src/cli.ts +883 -97
  131. package/packages/server/src/config-api.ts +143 -1
  132. package/packages/server/src/config-snapshot.ts +5 -0
  133. package/packages/server/src/directory-service.ts +435 -32
  134. package/packages/server/src/embed-lifecycle/caps.ts +35 -4
  135. package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +45 -4
  136. package/packages/server/src/embed-lifecycle/idle-reaper.ts +195 -20
  137. package/packages/server/src/embed-lifecycle/lifecycle-metrics.ts +38 -0
  138. package/packages/server/src/embed-lifecycle/plugin-session-close.ts +123 -0
  139. package/packages/server/src/embed-lifecycle/quiescence.ts +29 -3
  140. package/packages/server/src/embed-lifecycle/reclaim-give-up.ts +54 -0
  141. package/packages/server/src/event-wiring.ts +208 -35
  142. package/packages/server/src/file-watch-manager.ts +187 -39
  143. package/packages/server/src/git-worktree/git-operations.ts +16 -5
  144. package/packages/server/src/git-worktree/worktree-init-trust.ts +48 -5
  145. package/packages/server/src/git-worktree/worktree-init.ts +7 -56
  146. package/packages/server/src/identity/host-resources.ts +3 -0
  147. package/packages/server/src/identity/http-road-classification.ts +18 -0
  148. package/packages/server/src/identity/identity-registration-tracker.ts +4 -1
  149. package/packages/server/src/identity/plugin-identity.ts +19 -0
  150. package/packages/server/src/identity/policy-registry.ts +4 -1
  151. package/packages/server/src/identity/resolver-registry.ts +12 -3
  152. package/packages/server/src/identity/ws-message-scope.ts +9 -0
  153. package/packages/server/src/identity/ws-road-classification.ts +9 -0
  154. package/packages/server/src/known-server-moves.ts +175 -0
  155. package/packages/server/src/lib/browse-roots.ts +36 -0
  156. package/packages/server/src/lib/digest-gate.ts +82 -0
  157. package/packages/server/src/lib/file-write-lock.ts +24 -0
  158. package/packages/server/src/lib/folder-project.ts +439 -0
  159. package/packages/server/src/lib/purify.ts +13 -5
  160. package/packages/server/src/lib/writable-handler-target.ts +66 -0
  161. package/packages/server/src/lib/writable-md-target.ts +12 -1
  162. package/packages/server/src/lifecycle/classify-dashboard-port.ts +134 -0
  163. package/packages/server/src/lifecycle/home-lock.ts +344 -130
  164. package/packages/server/src/lifecycle/home-rendezvous.ts +41 -11
  165. package/packages/server/src/lifecycle/recovery-server.ts +77 -1
  166. package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
  167. package/packages/server/src/live-server/live-capability.ts +254 -0
  168. package/packages/server/src/live-server/live-server-proxy.ts +173 -26
  169. package/packages/server/src/metrics/eventloop-spike-metrics.ts +2 -2
  170. package/packages/server/src/model-proxy/internal-auth-storage.ts +27 -26
  171. package/packages/server/src/model-proxy/internal-registry.ts +6 -0
  172. package/packages/server/src/model-proxy/server-model-runtime.ts +6 -0
  173. package/packages/server/src/openspec/openspec-change-watcher.ts +109 -16
  174. package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +132 -0
  175. package/packages/server/src/openspec/openspec-poll-worker-pool.ts +90 -35
  176. package/packages/server/src/openspec/openspec-poll-worker.ts +200 -44
  177. package/packages/server/src/openspec/proposal-attach-naming.ts +5 -3
  178. package/packages/server/src/openspec/readiness.ts +9 -0
  179. package/packages/server/src/openspec/workflow-schema.ts +1128 -0
  180. package/packages/server/src/package/installed-package-enricher.ts +38 -3
  181. package/packages/server/src/package/package-health-scanner.ts +133 -0
  182. package/packages/server/src/package/package-manager-wrapper.ts +18 -2
  183. package/packages/server/src/package/provider-catalogue-cache.ts +17 -3
  184. package/packages/server/src/package/provider-probe.ts +5 -3
  185. package/packages/server/src/pairing/browser-gateway.ts +108 -8
  186. package/packages/server/src/pairing/knock-admission.ts +277 -0
  187. package/packages/server/src/pairing/pairing.ts +154 -27
  188. package/packages/server/src/pairing/subagent-resync-routing.ts +4 -1
  189. package/packages/server/src/pairing/ws-tier-gate.ts +34 -0
  190. package/packages/server/src/peer-servers.ts +77 -0
  191. package/packages/server/src/pending/pending-plugin-ref-registry.ts +57 -2
  192. package/packages/server/src/persistence/boot-state.ts +48 -1
  193. package/packages/server/src/persistence/memory-event-store.ts +216 -237
  194. package/packages/server/src/persistence/meta-persistence.ts +12 -1
  195. package/packages/server/src/persistence/preferences-store.ts +116 -7
  196. package/packages/server/src/pi/bridge-upgrade-auth.ts +32 -21
  197. package/packages/server/src/pi/folder-commands.ts +141 -0
  198. package/packages/server/src/pi/gateway-socket-bind.ts +9 -3
  199. package/packages/server/src/pi/gateway-transport-policy.ts +13 -0
  200. package/packages/server/src/pi/host-project-trust.ts +158 -33
  201. package/packages/server/src/pi/pi-gateway.ts +93 -9
  202. package/packages/server/src/pi/pi-resource-scanner.ts +15 -0
  203. package/packages/server/src/pi/resource-activation-toggle.ts +6 -0
  204. package/packages/server/src/pi/resource-toggle-trust.ts +34 -2
  205. package/packages/server/src/pi/session-skill-registry.ts +13 -3
  206. package/packages/server/src/pi/settings-write-lock.ts +32 -0
  207. package/packages/server/src/pi/trust-challenges.ts +38 -0
  208. package/packages/server/src/pi-agent-settings.ts +701 -100
  209. package/packages/server/src/pi-settings-themes.ts +104 -0
  210. package/packages/server/src/questions/brief-generator.ts +138 -0
  211. package/packages/server/src/questions/brief-model.ts +55 -0
  212. package/packages/server/src/questions/brief-policy.ts +36 -0
  213. package/packages/server/src/questions/brief-prompt.ts +92 -0
  214. package/packages/server/src/questions/brief-runtime.ts +50 -0
  215. package/packages/server/src/questions/question-answer.ts +55 -0
  216. package/packages/server/src/questions/question-broadcast.ts +106 -0
  217. package/packages/server/src/questions/question-files.ts +128 -0
  218. package/packages/server/src/questions/question-routes.ts +126 -0
  219. package/packages/server/src/questions/question-snapshot.ts +150 -0
  220. package/packages/server/src/questions/question-stack.ts +57 -0
  221. package/packages/server/src/questions/question-store.ts +477 -0
  222. package/packages/server/src/routes/access-prompt-routes.ts +5 -3
  223. package/packages/server/src/routes/access-routes.ts +123 -5
  224. package/packages/server/src/routes/acme-routes.ts +190 -0
  225. package/packages/server/src/routes/acp-routes.ts +16 -0
  226. package/packages/server/src/routes/addons-routes.ts +221 -0
  227. package/packages/server/src/routes/file-routes.ts +366 -75
  228. package/packages/server/src/routes/file-write-binary-routes.ts +473 -0
  229. package/packages/server/src/routes/folder-project-routes.ts +99 -0
  230. package/packages/server/src/routes/git-routes.ts +17 -2
  231. package/packages/server/src/routes/known-servers-routes.ts +333 -53
  232. package/packages/server/src/routes/live-server-routes.ts +72 -4
  233. package/packages/server/src/routes/local-proof-routes.ts +12 -7
  234. package/packages/server/src/routes/mermaid-repair-routes.ts +254 -0
  235. package/packages/server/src/routes/model-proxy-routes.ts +4 -2
  236. package/packages/server/src/routes/openspec-routes.ts +270 -40
  237. package/packages/server/src/routes/package-health-routes.ts +140 -0
  238. package/packages/server/src/routes/package-routes.ts +28 -1
  239. package/packages/server/src/routes/pairing-routes.ts +158 -24
  240. package/packages/server/src/routes/pi-retry-routes.ts +18 -2
  241. package/packages/server/src/routes/pi-settings-routes.ts +264 -0
  242. package/packages/server/src/routes/plugin-activation-routes.ts +87 -27
  243. package/packages/server/src/routes/provider-auth-routes.ts +22 -5
  244. package/packages/server/src/routes/provider-routes.ts +29 -0
  245. package/packages/server/src/routes/resource-activation-routes.ts +16 -32
  246. package/packages/server/src/routes/session-routes.ts +49 -5
  247. package/packages/server/src/routes/system-routes.ts +207 -23
  248. package/packages/server/src/routes/tls-routes.ts +55 -0
  249. package/packages/server/src/routes/user-routes.ts +192 -0
  250. package/packages/server/src/runtime-overlay/runtime-stager.ts +15 -2
  251. package/packages/server/src/runtime-overlay/runtime-update-checker.ts +11 -2
  252. package/packages/server/src/server.ts +919 -139
  253. package/packages/server/src/services/attached-driver.ts +175 -0
  254. package/packages/server/src/services/change-notifier.ts +55 -0
  255. package/packages/server/src/services/cli-service.ts +450 -0
  256. package/packages/server/src/services/command-runner.ts +92 -0
  257. package/packages/server/src/services/definitions-store.ts +121 -0
  258. package/packages/server/src/services/driver.ts +112 -0
  259. package/packages/server/src/services/health.ts +94 -0
  260. package/packages/server/src/services/leases.ts +117 -0
  261. package/packages/server/src/services/log-text.ts +97 -0
  262. package/packages/server/src/services/native-driver.ts +283 -0
  263. package/packages/server/src/services/oci-driver.ts +590 -0
  264. package/packages/server/src/services/output-capture.ts +183 -0
  265. package/packages/server/src/services/paths.ts +82 -0
  266. package/packages/server/src/services/ports.ts +26 -0
  267. package/packages/server/src/services/routes.ts +140 -0
  268. package/packages/server/src/services/runtime-detect.ts +108 -0
  269. package/packages/server/src/services/secret-delivery.ts +61 -0
  270. package/packages/server/src/services/secrets-resolver.ts +145 -0
  271. package/packages/server/src/services/secrets-store.ts +137 -0
  272. package/packages/server/src/services/service-manager.ts +1565 -0
  273. package/packages/server/src/services/start-record.ts +66 -0
  274. package/packages/server/src/services/state-machine.ts +241 -0
  275. package/packages/server/src/session/archive-sweeper.ts +92 -3
  276. package/packages/server/src/session/custom-event-group-matcher.ts +4 -3
  277. package/packages/server/src/session/in-flight-tool-calls.ts +74 -0
  278. package/packages/server/src/session/memory-session-manager.ts +53 -0
  279. package/packages/server/src/session/name-provenance.ts +102 -0
  280. package/packages/server/src/session/open-tool-calls.ts +15 -6
  281. package/packages/server/src/session/session-api.ts +47 -12
  282. package/packages/server/src/session/session-archive.ts +56 -4
  283. package/packages/server/src/session/session-diff-cache.ts +11 -4
  284. package/packages/server/src/session/session-load-worker-pool.ts +4 -3
  285. package/packages/server/src/session/session-scanner.ts +73 -3
  286. package/packages/server/src/session/session-to-meta.ts +15 -0
  287. package/packages/server/src/spawn-process/abort-spawned-run.ts +55 -0
  288. package/packages/server/src/spawn-process/acp-spawn.ts +131 -0
  289. package/packages/server/src/spawn-process/process-manager.ts +164 -30
  290. package/packages/server/src/spawn-process/restart-helper.ts +9 -8
  291. package/packages/server/src/spawn-process/server-pid.ts +16 -7
  292. package/packages/server/src/spawn-process/session-terminator.ts +218 -0
  293. package/packages/server/src/spawn-process/spawn-env-contributors.ts +159 -0
  294. package/packages/server/src/spawn-process/spawn-register-watchdog.ts +10 -1
  295. package/packages/server/src/terminal/terminal-manager.ts +67 -1
  296. package/packages/server/src/tls/cert-files.ts +228 -0
  297. package/packages/server/src/tls/cert-manager.ts +703 -0
  298. package/packages/server/src/tls/cert-store.ts +69 -0
  299. package/packages/server/src/tls/source-registry.ts +71 -0
  300. package/packages/server/src/tls/sources/acme/accounts.ts +76 -0
  301. package/packages/server/src/tls/sources/acme/acme-source.ts +508 -0
  302. package/packages/server/src/tls/sources/acme/config-projection.ts +34 -0
  303. package/packages/server/src/tls/sources/acme/credentials.ts +185 -0
  304. package/packages/server/src/tls/sources/acme/dns.ts +303 -0
  305. package/packages/server/src/tls/sources/acme/e2e-overrides.ts +49 -0
  306. package/packages/server/src/tls/sources/acme/entry.ts +180 -0
  307. package/packages/server/src/tls/sources/acme/gc.ts +78 -0
  308. package/packages/server/src/tls/sources/acme/runtime.ts +51 -0
  309. package/packages/server/src/tls/sources/acme/solvers/acme-dns.ts +154 -0
  310. package/packages/server/src/tls/sources/acme/solvers/cloudflare.ts +147 -0
  311. package/packages/server/src/tls/sources/acme/types.ts +72 -0
  312. package/packages/server/src/tls/sources/tailscale-cert.ts +172 -0
  313. package/packages/server/src/tls/tls-config-validation.ts +92 -0
  314. package/packages/server/src/tls/tls-listener.ts +351 -0
  315. package/packages/server/src/tls/types.ts +80 -0
  316. package/packages/server/src/tunnel/tunnel-block-events.ts +4 -1
  317. package/packages/server/src/tunnel/tunnel-core.ts +4 -1
  318. package/packages/server/src/tunnel/tunnel-endpoints.ts +4 -0
  319. package/packages/server/src/tunnel-providers/tailscale.ts +27 -6
  320. package/packages/server/src/vault/vault-bindings.ts +101 -0
  321. package/packages/server/src/vault/vault-delivery-hub.ts +294 -0
  322. package/packages/server/src/vault/vault-grants.ts +260 -0
  323. package/packages/server/src/vault/vault-import.ts +161 -0
  324. package/packages/server/src/vault/vault-permissions.ts +39 -0
  325. package/packages/server/src/vault/vault-plugin-read.ts +64 -0
  326. package/packages/server/src/vault/vault-projects.ts +156 -0
  327. package/packages/server/src/vault/vault-routes.ts +277 -0
  328. package/packages/server/src/vault/vault-store.ts +371 -0
  329. package/packages/shared/package.json +5 -2
  330. package/packages/shared/src/acp/acp-config.ts +123 -0
  331. package/packages/shared/src/acp/normalize-v1.ts +92 -0
  332. package/packages/shared/src/acp/paths.ts +36 -0
  333. package/packages/shared/src/acp/to-dashboard-events.ts +533 -0
  334. package/packages/shared/src/acp/update-model.ts +574 -0
  335. package/packages/shared/src/anthropic-messages-source.ts +8 -0
  336. package/packages/shared/src/bind-reachability.ts +21 -2
  337. package/packages/shared/src/boot-state.ts +6 -0
  338. package/packages/shared/src/browser-host-identity.ts +49 -0
  339. package/packages/shared/src/browser-host-ipc.ts +107 -0
  340. package/packages/shared/src/browser-protocol.ts +385 -71
  341. package/packages/shared/src/canonical-subject.ts +27 -2
  342. package/packages/shared/src/card-sections.ts +185 -1
  343. package/packages/shared/src/chrome-profiles.ts +188 -0
  344. package/packages/shared/src/config.ts +473 -26
  345. package/packages/shared/src/custom-event-groups.ts +5 -2
  346. package/packages/shared/src/cwd-guard.ts +381 -1
  347. package/packages/shared/src/dashboard-paths.ts +12 -0
  348. package/packages/shared/src/dashboard-plugin/editor-pane-tab.ts +26 -0
  349. package/packages/shared/src/dashboard-plugin/file-handler.ts +71 -0
  350. package/packages/shared/src/dashboard-plugin/index.ts +7 -3
  351. package/packages/shared/src/dashboard-plugin/manifest-types.ts +106 -2
  352. package/packages/shared/src/dashboard-plugin/project-identity.ts +42 -0
  353. package/packages/shared/src/dashboard-plugin/project-markers.ts +60 -0
  354. package/packages/shared/src/dashboard-plugin/slot-props.ts +95 -0
  355. package/packages/shared/src/dashboard-plugin/slot-types.ts +64 -4
  356. package/packages/shared/src/dashboard-plugin/ui-primitives.ts +22 -3
  357. package/packages/shared/src/dashboard-starter.ts +30 -0
  358. package/packages/shared/src/display-name.ts +42 -0
  359. package/packages/shared/src/doctor-core.ts +25 -107
  360. package/packages/shared/src/enabled-models-match.ts +47 -0
  361. package/packages/shared/src/event-forward-declaration.ts +187 -0
  362. package/packages/shared/src/file-kind.ts +54 -2
  363. package/packages/shared/src/git-worktree-helpers.ts +8 -4
  364. package/packages/shared/src/grammar-types.ts +3 -1
  365. package/packages/shared/src/host-admission.ts +2 -1
  366. package/packages/shared/src/host-port.ts +34 -0
  367. package/packages/shared/src/launcher-origin.ts +26 -0
  368. package/packages/shared/src/local-credential-proof.ts +219 -0
  369. package/packages/shared/src/markup-repair/asciidoc.ts +130 -0
  370. package/packages/shared/src/markup-repair/types.ts +13 -0
  371. package/packages/shared/src/md-table-cell.ts +11 -0
  372. package/packages/shared/src/mdns-discovery.ts +392 -42
  373. package/packages/shared/src/models-json-reader.ts +6 -0
  374. package/packages/shared/src/openspec-design-evidence.ts +25 -1
  375. package/packages/shared/src/openspec-poller.ts +210 -9
  376. package/packages/shared/src/openspec-status-all.ts +393 -0
  377. package/packages/shared/src/operate-required.ts +29 -0
  378. package/packages/shared/src/pairing-knock-client.ts +261 -0
  379. package/packages/shared/src/pairing-knock.ts +71 -0
  380. package/packages/shared/src/pairing-refusal.ts +32 -0
  381. package/packages/shared/src/path-containment-guard-name.ts +8 -0
  382. package/packages/shared/src/pi-settings-keys.ts +9 -0
  383. package/packages/shared/src/pi-settings-schema.ts +285 -0
  384. package/packages/shared/src/pi-trust-mirror-snapshot.ts +200 -0
  385. package/packages/shared/src/pi-trust-mirror-types.ts +57 -0
  386. package/packages/shared/src/pi-trust-mirror.ts +328 -0
  387. package/packages/shared/src/platform/binary-lookup.ts +2 -194
  388. package/packages/shared/src/platform/git.ts +204 -4
  389. package/packages/shared/src/platform/native-ts-hooks.mjs +93 -40
  390. package/packages/shared/src/platform/native-ts-register.mjs +22 -10
  391. package/packages/shared/src/platform/native-ts-tier.d.mts +1 -0
  392. package/packages/shared/src/platform/native-ts-tier.mjs +17 -0
  393. package/packages/shared/src/platform/node-spawn.ts +1 -2
  394. package/packages/shared/src/platform/openspec.ts +129 -31
  395. package/packages/shared/src/platform/process-scan.ts +199 -1
  396. package/packages/shared/src/platform/process.ts +51 -0
  397. package/packages/shared/src/platform/runner.ts +46 -2
  398. package/packages/shared/src/platform/spawn-mechanism.ts +14 -2
  399. package/packages/shared/src/platform/ts-loader-select.d.mts +1 -7
  400. package/packages/shared/src/platform/ts-loader-select.mjs +14 -43
  401. package/packages/shared/src/plugin-bridge-register.ts +24 -1
  402. package/packages/shared/src/project-name.ts +42 -0
  403. package/packages/shared/src/prompt-answer.ts +183 -0
  404. package/packages/shared/src/protocol.ts +133 -8
  405. package/packages/shared/src/question-types.ts +73 -0
  406. package/packages/shared/src/recommended-extensions.ts +80 -23
  407. package/packages/shared/src/recovery-timing.ts +12 -0
  408. package/packages/shared/src/redaction.ts +50 -0
  409. package/packages/shared/src/rest-api.ts +484 -1
  410. package/packages/shared/src/role-config-disk.ts +23 -0
  411. package/packages/shared/src/role-schema.ts +79 -0
  412. package/packages/shared/src/route-tiers.ts +127 -0
  413. package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +17 -0
  414. package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +119 -8
  415. package/packages/shared/src/server-identity.ts +51 -15
  416. package/packages/shared/src/server-launcher.ts +12 -33
  417. package/packages/shared/src/server-pinning.ts +81 -0
  418. package/packages/shared/src/services/offers.ts +114 -0
  419. package/packages/shared/src/services/schema.ts +628 -0
  420. package/packages/shared/src/services/status.ts +169 -0
  421. package/packages/shared/src/session-meta.ts +59 -2
  422. package/packages/shared/src/session-name.ts +8 -0
  423. package/packages/shared/src/skill-block-parser.ts +14 -0
  424. package/packages/shared/src/source-matching.ts +5 -1
  425. package/packages/shared/src/state-replay.ts +19 -0
  426. package/packages/shared/src/terminal-safe.ts +24 -0
  427. package/packages/shared/src/tls-status.ts +69 -0
  428. package/packages/shared/src/tool-path-resolve.ts +243 -0
  429. package/packages/shared/src/tool-registry/definitions.ts +26 -4
  430. package/packages/shared/src/tool-registry/index.ts +2 -2
  431. package/packages/shared/src/tool-registry/pi-tools.ts +32 -3
  432. package/packages/shared/src/tunnel-provider.ts +3 -2
  433. package/packages/shared/src/types.ts +104 -9
  434. package/packages/shared/src/vault-delivery.ts +73 -0
  435. package/packages/shared/src/vault-origin.ts +51 -0
  436. package/packages/shared/src/vault-project-key.ts +53 -0
  437. package/packages/shared/src/worktree-init-hook.ts +69 -0
  438. package/packages/shared/src/ws-message-tiers.ts +135 -0
  439. package/tsconfig.base.json +1 -0
@@ -7,15 +7,25 @@
7
7
  * new paths get an `fs.watch`, gone paths are closed. `clearConnection` tears
8
8
  * every watcher for a disconnected browser down so no file descriptors leak.
9
9
  *
10
- * Best-effort: `fs.watch` is path-based. On Linux (inotify) a rename-in-place
11
- * edit (tmp + rename) can detach the watch from the new inode, so a later
12
- * change may not fire. The banner is a hint, not a guarantee; the pane's manual
13
- * refresh stays authoritative.
10
+ * `fs.watch` is path-based but binds to the inode, so an atomic replace
11
+ * (tmp + `rename`: the pane's own Save, formatters, `git checkout`) leaves the
12
+ * watcher on the old inode and later changes would go unseen. On a `rename`
13
+ * event the entry therefore re-attaches SYNCHRONOUSLY to the path (only if it
14
+ * is a regular file); a path that is missing (delete + quick re-create) is
15
+ * retried at 100/300/600/1000 ms, then the key is dropped. A path replaced by a
16
+ * non-regular file (directory, FIFO) drops the key at once. `change` events
17
+ * never re-attach (no fd churn). Every event is still only a *candidate*: the
18
+ * client verifies it against a content digest before showing the banner.
14
19
  *
15
- * See change: split-editor-workspace.
20
+ * Timers (retry + debounce) live on the per-key entry and are cancelled by
21
+ * reconcile-removal / `clearConnection`, so no retry can resurrect a dropped
22
+ * key. Handlers act only on the watcher instance the entry still holds, so a
23
+ * stale `error`/event from a replaced watcher never touches its successor.
24
+ *
25
+ * See change: split-editor-workspace, gate-changed-on-disk-by-content (D5).
16
26
  */
17
27
 
18
- import { type FSWatcher, watch } from "node:fs";
28
+ import { type FSWatcher, statSync, watch } from "node:fs";
19
29
  import path from "node:path";
20
30
 
21
31
  /** Synchronous logical containment: `abs` equals or sits under `cwd`. */
@@ -42,25 +52,171 @@ export interface FileWatchManager {
42
52
  clearConnection(ws: object): void;
43
53
  /** Total live `fs.watch` handles (tests / diagnostics). */
44
54
  activeWatchCount(): number;
55
+ /** Pending retry + debounce timers on held keys (tests / diagnostics). */
56
+ pendingTimerCount(): number;
57
+ }
58
+
59
+ /** Test seams: the `fs.watch` factory. */
60
+ export interface FileWatchManagerDeps {
61
+ watchFn?: typeof watch;
45
62
  }
46
63
 
47
64
  const CHANGE_DEBOUNCE_MS = 40;
65
+ /** Delays (ms after the `rename`) at which a missing path is retried before the key is dropped. */
66
+ const REATTACH_RETRY_DELAYS_MS = [100, 300, 600, 1000] as const;
67
+
68
+ type PathState = "file" | "other" | "missing";
69
+
70
+ function pathState(abs: string): PathState {
71
+ try {
72
+ return statSync(abs).isFile() ? "file" : "other";
73
+ } catch {
74
+ return "missing";
75
+ }
76
+ }
77
+
78
+ /**
79
+ * One watched (connection, session, path) key: the live `fs.watch` handle plus
80
+ * the retry and debounce timers that belong to it. `drop` is invoked when the
81
+ * key must leave the manager's map (retries exhausted, non-regular file,
82
+ * watcher error); `release` frees the handle + retry timer, `cancel` also
83
+ * silences a pending debounce so nothing fires after a teardown.
84
+ */
85
+ class WatchedFile {
86
+ private watcher: FSWatcher | null = null;
87
+ private retryTimer: NodeJS.Timeout | null = null;
88
+ private debounceTimer: NodeJS.Timeout | null = null;
89
+ private cancelled = false;
90
+
91
+ private readonly abs: string;
92
+ private readonly watchFn: typeof watch;
93
+ private readonly emit: () => void;
94
+ private readonly drop: (self: WatchedFile) => void;
48
95
 
49
- export function createFileWatchManager(): FileWatchManager {
50
- // ws → keyString → FSWatcher. keyString = `${sessionId}\u0000${relPath}`.
51
- const byConnection = new Map<object, Map<string, FSWatcher>>();
96
+ constructor(abs: string, watchFn: typeof watch, emit: () => void, drop: (self: WatchedFile) => void) {
97
+ this.abs = abs;
98
+ this.watchFn = watchFn;
99
+ this.emit = emit;
100
+ this.drop = drop;
101
+ }
102
+
103
+ hasWatcher(): boolean {
104
+ return this.watcher !== null;
105
+ }
106
+
107
+ pendingTimers(): number {
108
+ return (this.retryTimer ? 1 : 0) + (this.debounceTimer ? 1 : 0);
109
+ }
110
+
111
+ /** Bind a fresh watcher to the path. Throws if the path cannot be watched. */
112
+ attach(): void {
113
+ const watcher = this.watchFn(this.abs, (eventType) => {
114
+ if (this.watcher !== watcher) return; // stale instance
115
+ if (eventType === "rename") this.reattach();
116
+ this.scheduleChange();
117
+ });
118
+ watcher.on("error", () => {
119
+ // Act only on the instance still held: an old watcher's late `error`
120
+ // must not close its re-attached successor.
121
+ if (this.watcher === watcher) this.drop(this);
122
+ });
123
+ this.watcher = watcher;
124
+ }
125
+
126
+ /** Free the handle + retry timer; a pending debounce still fires once. */
127
+ release(): void {
128
+ if (this.retryTimer) clearTimeout(this.retryTimer);
129
+ this.retryTimer = null;
130
+ this.closeHandle();
131
+ }
132
+
133
+ /** Explicit teardown: release AND cancel the debounce. */
134
+ cancel(): void {
135
+ this.cancelled = true;
136
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
137
+ this.debounceTimer = null;
138
+ this.release();
139
+ }
140
+
141
+ private closeHandle(): void {
142
+ const w = this.watcher;
143
+ this.watcher = null;
144
+ try {
145
+ w?.close();
146
+ } catch {
147
+ /* already closed */
148
+ }
149
+ }
150
+
151
+ private scheduleChange(): void {
152
+ if (this.debounceTimer) return; // debounce a burst of events into one
153
+ this.debounceTimer = setTimeout(() => {
154
+ this.debounceTimer = null;
155
+ if (!this.cancelled) this.emit();
156
+ }, CHANGE_DEBOUNCE_MS);
157
+ }
158
+
159
+ /** `rename`: the old inode is gone — bind to whatever is at the path now. */
160
+ private reattach(): void {
161
+ if (this.retryTimer) clearTimeout(this.retryTimer);
162
+ this.retryTimer = null;
163
+ this.closeHandle();
164
+ const state = pathState(this.abs);
165
+ if (state === "other") return this.drop(this); // never watch a directory / FIFO
166
+ if (state === "file" && this.tryAttach()) return;
167
+ this.retry(0);
168
+ }
169
+
170
+ private tryAttach(): boolean {
171
+ try {
172
+ this.attach();
173
+ return true;
174
+ } catch {
175
+ return false; // vanished between stat and watch
176
+ }
177
+ }
178
+
179
+ /** Retry a missing path at the bounded delays, then drop the key. */
180
+ private retry(attempt: number): void {
181
+ if (attempt >= REATTACH_RETRY_DELAYS_MS.length) return this.drop(this);
182
+ const prev = attempt === 0 ? 0 : REATTACH_RETRY_DELAYS_MS[attempt - 1];
183
+ this.retryTimer = setTimeout(() => {
184
+ this.retryTimer = null;
185
+ const state = pathState(this.abs);
186
+ if (state === "other") return this.drop(this);
187
+ if (state === "file" && this.tryAttach()) return this.scheduleChange(); // re-created: have the client re-verify
188
+ this.retry(attempt + 1);
189
+ }, REATTACH_RETRY_DELAYS_MS[attempt] - prev);
190
+ }
191
+ }
192
+
193
+ export function createFileWatchManager(deps: FileWatchManagerDeps = {}): FileWatchManager {
194
+ const watchFn = deps.watchFn ?? watch;
195
+ // ws → keyString → entry. keyString = `${sessionId}\u0000${relPath}`.
196
+ const byConnection = new Map<object, Map<string, WatchedFile>>();
52
197
 
53
198
  const keyOf = (k: WatchKey) => `${k.sessionId}\u0000${k.relPath}`;
54
199
 
55
- function closeWatcher(map: Map<string, FSWatcher>, keyString: string): void {
56
- const w = map.get(keyString);
57
- if (w) {
58
- try {
59
- w.close();
60
- } catch {
61
- /* already closed */
62
- }
63
- map.delete(keyString);
200
+ function closeEntry(map: Map<string, WatchedFile>, keyString: string): void {
201
+ map.get(keyString)?.cancel();
202
+ map.delete(keyString);
203
+ }
204
+
205
+ function addWatch(
206
+ map: Map<string, WatchedFile>,
207
+ keyString: string,
208
+ abs: string,
209
+ emit: () => void,
210
+ ): void {
211
+ const entry = new WatchedFile(abs, watchFn, emit, (self) => {
212
+ self.release();
213
+ if (map.get(keyString) === self) map.delete(keyString);
214
+ });
215
+ try {
216
+ entry.attach();
217
+ map.set(keyString, entry);
218
+ } catch {
219
+ /* file vanished / unwatchable — skip */
64
220
  }
65
221
  }
66
222
 
@@ -71,51 +227,43 @@ export function createFileWatchManager(): FileWatchManager {
71
227
  map = new Map();
72
228
  byConnection.set(ws, map);
73
229
  }
230
+ const held = map;
74
231
 
75
232
  // Desired keys for THIS session (other sessions on the same ws untouched).
76
233
  const desired = new Set(relPaths.map((rel) => keyOf({ sessionId, relPath: rel })));
77
234
 
78
235
  // Remove watchers for this session's paths that are no longer desired.
79
236
  const sessionPrefix = `${sessionId}\u0000`;
80
- for (const existing of [...map.keys()]) {
81
- if (existing.startsWith(sessionPrefix) && !desired.has(existing)) {
82
- closeWatcher(map, existing);
83
- }
237
+ for (const existing of [...held.keys()]) {
238
+ if (existing.startsWith(sessionPrefix) && !desired.has(existing)) closeEntry(held, existing);
84
239
  }
85
240
 
86
241
  // Add watchers for newly-desired paths (synchronous, cwd-contained).
87
242
  for (const rel of relPaths) {
88
243
  const keyString = keyOf({ sessionId, relPath: rel });
89
- if (map.has(keyString)) continue; // already watched
244
+ if (held.has(keyString)) continue; // already watched
90
245
  const abs = path.resolve(cwd, rel);
91
246
  if (!withinCwd(abs, cwd)) continue; // never watch outside cwd
92
- let timer: NodeJS.Timeout | null = null;
93
- try {
94
- const watcher = watch(abs, () => {
95
- if (timer) return; // debounce a burst of events into one
96
- timer = setTimeout(() => {
97
- timer = null;
98
- onChange(sessionId, rel);
99
- }, CHANGE_DEBOUNCE_MS);
100
- });
101
- watcher.on("error", () => closeWatcher(map!, keyString));
102
- map.set(keyString, watcher);
103
- } catch {
104
- /* file vanished / unwatchable — skip */
105
- }
247
+ addWatch(held, keyString, abs, () => onChange(sessionId, rel));
106
248
  }
107
249
  },
108
250
 
109
251
  clearConnection(ws) {
110
252
  const map = byConnection.get(ws);
111
253
  if (!map) return;
112
- for (const key of [...map.keys()]) closeWatcher(map, key);
254
+ for (const key of [...map.keys()]) closeEntry(map, key);
113
255
  byConnection.delete(ws);
114
256
  },
115
257
 
116
258
  activeWatchCount() {
117
259
  let n = 0;
118
- for (const map of byConnection.values()) n += map.size;
260
+ for (const map of byConnection.values()) for (const e of map.values()) if (e.hasWatcher()) n++;
261
+ return n;
262
+ },
263
+
264
+ pendingTimerCount() {
265
+ let n = 0;
266
+ for (const map of byConnection.values()) for (const e of map.values()) n += e.pendingTimers();
119
267
  return n;
120
268
  },
121
269
  };
@@ -11,6 +11,7 @@ import { execFile as nodeExecFile } from "node:child_process"; // ban:child_proc
11
11
  import fs from "node:fs";
12
12
  import path from "node:path";
13
13
  import { promisify } from "node:util";
14
+ import { collapseCheckRollup } from "@blackbelt-technology/pi-dashboard-shared/platform/check-rollup.js";
14
15
  import { type ChildProcess, execFileSync, spawn, spawnSync } from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
15
16
  import {
16
17
  checkoutRoots,
@@ -18,7 +19,6 @@ import {
18
19
  gitStatusV2,
19
20
  hasGitPathSegment,
20
21
  } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
21
- import { collapseCheckRollup } from "@blackbelt-technology/pi-dashboard-shared/platform/check-rollup.js";
22
22
  import { samePath } from "@blackbelt-technology/pi-dashboard-shared/platform/paths.js";
23
23
  import type { GitChangedFile, GitCommitResult } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
24
24
  import type { GitStatus } from "@blackbelt-technology/pi-dashboard-shared/types.js";
@@ -201,8 +201,15 @@ export function getGitStatus(cwd: string): GitStatus | undefined {
201
201
  * so the route can surface it to the dialog without string-matching stderr.
202
202
  */
203
203
  export class GitCommitError extends Error {
204
+ public code: | "not-a-repo"
205
+ | "path-escape"
206
+ | "no-files"
207
+ | "empty-message"
208
+ | "stage-failed"
209
+ | "commit-failed";
210
+
204
211
  constructor(
205
- public code:
212
+ code:
206
213
  | "not-a-repo"
207
214
  | "path-escape"
208
215
  | "no-files"
@@ -212,6 +219,7 @@ export class GitCommitError extends Error {
212
219
  message: string,
213
220
  ) {
214
221
  super(message);
222
+ this.code = code;
215
223
  this.name = "GitCommitError";
216
224
  }
217
225
  }
@@ -431,8 +439,10 @@ export function listBranches(cwd: string): BranchInfo {
431
439
 
432
440
  const localBranches: BranchInfo["branches"] = [];
433
441
  for (const line of rawLocal.split("\n").filter(Boolean)) {
434
- const isCurrent = line.includes("*");
435
- const name = line.replace("*", "").trim();
442
+ // `%(HEAD)` appends `*` for the current branch (git forbids `*` in ref names).
443
+ const t = line.trim();
444
+ const isCurrent = t.endsWith("*");
445
+ const name = (isCurrent ? t.slice(0, -1) : t).trim();
436
446
  if (!name) continue;
437
447
  localBranches.push({ name, isRemote: false, isCurrent });
438
448
  }
@@ -442,7 +452,8 @@ export function listBranches(cwd: string): BranchInfo {
442
452
 
443
453
  const remoteBranches: BranchInfo["branches"] = [];
444
454
  for (const line of rawRemote.split("\n").filter(Boolean)) {
445
- const name = line.replace("*", "").trim();
455
+ const t = line.trim();
456
+ const name = (t.endsWith("*") ? t.slice(0, -1) : t).trim();
446
457
  // Skip HEAD pointers like "origin/HEAD"
447
458
  if (name.endsWith("/HEAD")) continue;
448
459
  // Skip remote branches that have a local counterpart
@@ -34,6 +34,15 @@ function trustKey(repoRoot: string, hash: string): string {
34
34
  return `${path.resolve(repoRoot)}\u0000${hash}`;
35
35
  }
36
36
 
37
+ /**
38
+ * Notified after the persisted store is written. Feeds the pi-trust mirror
39
+ * snapshot; set once by the server. See change: mirror-dashboard-trust-to-pi.
40
+ */
41
+ let trustChanged: (() => void) | undefined;
42
+ export function setTrustChangedListener(fn: (() => void) | undefined): void {
43
+ trustChanged = fn;
44
+ }
45
+
37
46
  /** Trust scope. `session` = memory-only; `project` = persisted JSON store. */
38
47
  export type TrustScope = "session" | "project";
39
48
 
@@ -58,16 +67,45 @@ function load(): TrustMap {
58
67
  return {};
59
68
  }
60
69
 
61
- function save(map: TrustMap): void {
70
+ /**
71
+ * Persist the map. Default: a write failure is warned and swallowed (legacy
72
+ * behaviour — a grant must not crash a route). `strict` rethrows so a caller that
73
+ * reports success to the operator (revoking dashboard trust that is mirrored into
74
+ * pi) can report the failure instead. See change: mirror-dashboard-trust-to-pi.
75
+ */
76
+ function save(map: TrustMap, strict = false): void {
62
77
  const p = storePath();
63
78
  try {
64
79
  fs.mkdirSync(path.dirname(p), { recursive: true });
65
80
  fs.writeFileSync(p, JSON.stringify(map, null, 2), "utf8");
81
+ try {
82
+ trustChanged?.();
83
+ } catch {
84
+ /* a listener never fails a grant */
85
+ }
66
86
  } catch (err) {
87
+ if (strict) throw err;
67
88
  console.warn(`[worktree-init-trust] failed to persist: ${(err as Error)?.message}`);
68
89
  }
69
90
  }
70
91
 
92
+ /**
93
+ * The PERSISTED (project-scope) entries as `{ repoRoot, hash }` — never the
94
+ * in-memory session set (server-lifetime trust does not count toward the pi
95
+ * mirror). Keys are `path.resolve`d; the mirror translates them to pi's key form.
96
+ * See change: mirror-dashboard-trust-to-pi.
97
+ */
98
+ export function listPersistedTrust(): Array<{ repoRoot: string; hash: string }> {
99
+ const out: Array<{ repoRoot: string; hash: string }> = [];
100
+ for (const [key, value] of Object.entries(load())) {
101
+ if (value !== true) continue;
102
+ const i = key.indexOf("\u0000");
103
+ if (i <= 0) continue;
104
+ out.push({ repoRoot: key.slice(0, i), hash: key.slice(i + 1) });
105
+ }
106
+ return out;
107
+ }
108
+
71
109
  /**
72
110
  * True iff trust was recorded for this `repoRoot + hash` in EITHER the in-memory
73
111
  * session set OR the persisted project store (OR-combine).
@@ -84,7 +122,12 @@ export function isTrusted(repoRoot: string, hash: string): boolean {
84
122
  * and any omitted-field request preserves today's persistent behavior). A
85
123
  * `session` grant adds to the in-memory set and never writes disk.
86
124
  */
87
- export function recordTrust(repoRoot: string, hash: string, scope: TrustScope = "project"): void {
125
+ export function recordTrust(
126
+ repoRoot: string,
127
+ hash: string,
128
+ scope: TrustScope = "project",
129
+ opts: { strict?: boolean } = {},
130
+ ): void {
88
131
  const key = trustKey(repoRoot, hash);
89
132
  if (scope === "session") {
90
133
  sessionTrust.add(key);
@@ -92,7 +135,7 @@ export function recordTrust(repoRoot: string, hash: string, scope: TrustScope =
92
135
  }
93
136
  const map = load();
94
137
  map[key] = true;
95
- save(map);
138
+ save(map, opts.strict === true);
96
139
  }
97
140
 
98
141
  /**
@@ -115,7 +158,7 @@ export function recordTrust(repoRoot: string, hash: string, scope: TrustScope =
115
158
  * true — the button appeared to work and revoked nothing (found by the task 8.7
116
159
  * review; the route comment already claimed this semantics, unimplemented).
117
160
  */
118
- export function revokeTrust(repoRoot: string, hash?: string): void {
161
+ export function revokeTrust(repoRoot: string, hash?: string, opts: { strict?: boolean } = {}): void {
119
162
  const matches = (key: string): boolean =>
120
163
  hash ? key === trustKey(repoRoot, hash) : key.startsWith(trustKey(repoRoot, ""));
121
164
 
@@ -129,5 +172,5 @@ export function revokeTrust(repoRoot: string, hash?: string): void {
129
172
  changed = true;
130
173
  }
131
174
  }
132
- if (changed) save(map);
175
+ if (changed) save(map, opts.strict === true);
133
176
  }
@@ -20,7 +20,6 @@
20
20
  */
21
21
  import * as fs from "node:fs";
22
22
  import * as path from "node:path";
23
- import { createHash } from "node:crypto";
24
23
  import { spawn } from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
25
24
  import type { ChildProcess, SpawnOptions } from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
26
25
  import { getDefaultRegistry } from "@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js";
@@ -39,24 +38,13 @@ function defaultHookEnv(): NodeJS.ProcessEnv {
39
38
 
40
39
  // ── Types ─────────────────────────────────────────────────────────────────
41
40
 
42
- export interface ScriptRun {
43
- type: "script";
44
- command: string;
45
- }
46
-
47
- export interface AgentRun {
48
- type: "agent";
49
- prompt: string;
50
- model?: string;
51
- settings?: unknown;
52
- }
53
-
54
- export type InitRun = ScriptRun | AgentRun;
55
-
56
- export interface WorktreeInitHook {
57
- gate: string;
58
- run: InitRun;
59
- }
41
+ // Pure hook shape + hash live in shared (the bridge re-hashes hooks from the
42
+ // trust-mirror snapshot). Re-exported so existing importers are unchanged.
43
+ // See change: mirror-dashboard-trust-to-pi.
44
+ export type { ScriptRun, AgentRun, InitRun, WorktreeInitHook } from "@blackbelt-technology/pi-dashboard-shared/worktree-init-hook.js";
45
+ export { normalizeHook, hookDefHash } from "@blackbelt-technology/pi-dashboard-shared/worktree-init-hook.js";
46
+ import { normalizeHook } from "@blackbelt-technology/pi-dashboard-shared/worktree-init-hook.js";
47
+ import type { WorktreeInitHook } from "@blackbelt-technology/pi-dashboard-shared/worktree-init-hook.js";
60
48
 
61
49
  // ── 1. readInitHook ─────────────────────────────────────────────────────────
62
50
 
@@ -84,27 +72,6 @@ export function readInitHook(repoRoot: string): WorktreeInitHook | null {
84
72
  return normalizeHook(hook);
85
73
  }
86
74
 
87
- /** Validate the raw `worktreeInit` value into a typed hook, else `null`. */
88
- export function normalizeHook(hook: unknown): WorktreeInitHook | null {
89
- if (!hook || typeof hook !== "object" || Array.isArray(hook)) return null;
90
- const h = hook as { gate?: unknown; run?: unknown };
91
- if (typeof h.gate !== "string" || h.gate.length === 0) return null;
92
- if (!h.run || typeof h.run !== "object" || Array.isArray(h.run)) return null;
93
- const run = h.run as { type?: unknown; command?: unknown; prompt?: unknown; model?: unknown; settings?: unknown };
94
- if (run.type === "script") {
95
- if (typeof run.command !== "string" || run.command.length === 0) return null;
96
- return { gate: h.gate, run: { type: "script", command: run.command } };
97
- }
98
- if (run.type === "agent") {
99
- if (typeof run.prompt !== "string" || run.prompt.length === 0) return null;
100
- const agent: AgentRun = { type: "agent", prompt: run.prompt };
101
- if (typeof run.model === "string") agent.model = run.model;
102
- if (run.settings !== undefined) agent.settings = run.settings;
103
- return { gate: h.gate, run: agent };
104
- }
105
- return null;
106
- }
107
-
108
75
  // ── 2. evaluateGate ───────────────────────────────────────────────────────
109
76
 
110
77
  export interface GateResult {
@@ -417,19 +384,3 @@ function readTail(file: string, maxBytes: number): string {
417
384
  return "";
418
385
  }
419
386
  }
420
-
421
- // ── 4. hookDefHash ────────────────────────────────────────────────────────
422
-
423
- /** sha256 over a canonical (key-sorted) serialization of the hook. */
424
- export function hookDefHash(hook: WorktreeInitHook): string {
425
- return createHash("sha256").update(canonicalize(hook)).digest("hex");
426
- }
427
-
428
- /** Deterministic JSON with recursively sorted object keys. */
429
- function canonicalize(value: unknown): string {
430
- if (value === null || typeof value !== "object") return JSON.stringify(value);
431
- if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
432
- const obj = value as Record<string, unknown>;
433
- const keys = Object.keys(obj).sort();
434
- return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalize(obj[k])}`).join(",")}}`;
435
- }
@@ -43,6 +43,8 @@ export const HostActions = {
43
43
  editorWrite: "editor.write",
44
44
  liveRead: "live.read",
45
45
  liveWrite: "live.write",
46
+ /** Manage the credential vault (`/api/vault*`, `ungranted`). See change: retro-ux-credential-vault (D11). */
47
+ vaultManage: "vault.manage",
46
48
  /** A plugin-emitted global domain event (fan-out road, §10). */
47
49
  domainEvent: "domain.event",
48
50
  } as const satisfies Record<string, HostAction>;
@@ -54,6 +56,7 @@ export const hostResource = {
54
56
  branch: (cwd?: string): HostResource => ({ kind: "branch", ...(cwd ? { cwd } : {}) }),
55
57
  terminal: (id?: string): HostResource => ({ kind: "terminal", ...(id ? { id } : {}) }),
56
58
  system: (): HostResource => ({ kind: "system" }),
59
+ vault: (): HostResource => ({ kind: "vault" }),
57
60
  /** A plugin domain event; identifies the emitter + event type, never payload. */
58
61
  domain: (pluginId: string, eventType: string): HostResource => ({
59
62
  kind: "domain",
@@ -36,6 +36,7 @@ type Family =
36
36
  | "plugins"
37
37
  | "packages"
38
38
  | "access"
39
+ | "questions"
39
40
  | "gateway"
40
41
  | "system";
41
42
 
@@ -43,6 +44,8 @@ type Family =
43
44
  const FAMILY_BY_SEGMENT: Readonly<Record<string, Family>> = {
44
45
  // workspace: folders, directory pickers, pinned dirs
45
46
  browse: "workspace",
47
+ // folder project identity (`GET /api/folder/project`); change: add-project-scoped-apps
48
+ folder: "workspace",
46
49
  "pinned-dirs": "workspace",
47
50
  // openspec
48
51
  openspec: "openspec",
@@ -53,6 +56,8 @@ const FAMILY_BY_SEGMENT: Readonly<Record<string, Family>> = {
53
56
  file: "files",
54
57
  grep: "files",
55
58
  diagram: "files",
59
+ // on-demand AI mermaid repair (change: add-mermaid-ai-repair)
60
+ mermaid: "files",
56
61
  "reveal-in-file-manager": "files",
57
62
  "open-in-system": "files",
58
63
  "pi-resource-file": "files",
@@ -64,6 +69,7 @@ const FAMILY_BY_SEGMENT: Readonly<Record<string, Family>> = {
64
69
  "canvas-types": "config",
65
70
  "auto-name-outcomes": "config",
66
71
  "pi-retry": "config",
72
+ "pi-settings": "config",
67
73
  // providers / models
68
74
  providers: "providers",
69
75
  "provider-auth": "providers",
@@ -71,22 +77,31 @@ const FAMILY_BY_SEGMENT: Readonly<Record<string, Family>> = {
71
77
  "model-proxy": "providers",
72
78
  // packages / runtimes / tools
73
79
  packages: "packages",
80
+ // Add-ons hub catalog + feature toggle. See change: addons-hub-feature-catalog.
81
+ addons: "packages",
74
82
  resources: "packages",
75
83
  "pi-resources": "packages",
76
84
  "pi-core": "packages",
77
85
  pi: "packages",
78
86
  node: "packages",
79
87
  tools: "packages",
88
+ services: "packages",
80
89
  runtime: "packages",
81
90
  electron: "packages",
82
91
  // access / trust / pairing records
83
92
  access: "access",
84
93
  auth: "access",
85
94
  "paired-devices": "access",
95
+ // user directory + passkey invites (change: add-passkey-user-auth)
96
+ users: "access",
86
97
  "host-gate": "access",
98
+ // credential vault: accounts, grants, import (change: add-credential-vault)
99
+ vault: "access",
87
100
  // credential plumbing (change: harden-trust-and-credential-boundaries)
88
101
  "device-session": "access",
89
102
  "local-proof": "access",
103
+ // open ask_user questions; per-item visibility check in the handler (change: add-pending-question-stack)
104
+ questions: "questions",
90
105
  // gateway: tunnel, pairing handshake, discovery, push
91
106
  tunnel: "gateway",
92
107
  "tunnel-connect": "gateway",
@@ -95,12 +110,15 @@ const FAMILY_BY_SEGMENT: Readonly<Record<string, Family>> = {
95
110
  "tunnel-status-detail": "gateway",
96
111
  "tunnel-readiness": "gateway",
97
112
  "tunnel-reserved-name": "gateway",
113
+ // built-in HTTPS listener: operator "issue now" (change: add-tailscale-cert-tls)
114
+ tls: "gateway",
98
115
  pair: "gateway",
99
116
  "known-servers": "gateway",
100
117
  "discover-servers": "gateway",
101
118
  "network-interfaces": "gateway",
102
119
  push: "gateway",
103
120
  // system
121
+ acp: "workspace",
104
122
  restart: "system",
105
123
  shutdown: "system",
106
124
  doctor: "system",
@@ -7,11 +7,14 @@
7
7
  * login flow — the exact self-lockout D21 prevents.
8
8
  */
9
9
  export class IdentityRegistrationTracker {
10
+ private readonly onIgnored: (pluginId: string) => void;
10
11
  private readonly byPlugin = new Map<string, Array<() => void>>();
11
12
  private isFrozen = false;
12
13
 
13
14
  /** @param onIgnored called when a plugin invokes its handle after freeze(). */
14
- constructor(private readonly onIgnored: (pluginId: string) => void = () => {}) {}
15
+ constructor(onIgnored: (pluginId: string) => void = () => {}) {
16
+ this.onIgnored = onIgnored;
17
+ }
15
18
 
16
19
  /** True once enforcement has been decided; registrations are then immutable until restart. */
17
20
  get frozen(): boolean {