tmux-ide 2.7.0 → 2.9.0-beta.5

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 (1746) hide show
  1. package/README.md +95 -115
  2. package/bin/cli.js +69987 -11819
  3. package/bin/cli.ts +772 -114
  4. package/package.json +64 -30
  5. package/packages/contracts/package.json +3 -2
  6. package/packages/contracts/src/__tests__/actions-contract.test.ts +119 -0
  7. package/packages/contracts/src/__tests__/agent-graph-overlay.test.ts +428 -0
  8. package/packages/contracts/src/__tests__/app-window-mutation.test.ts +51 -0
  9. package/packages/contracts/src/__tests__/app-window-state.test.ts +34 -0
  10. package/packages/contracts/src/__tests__/application-shell.test.ts +635 -0
  11. package/packages/contracts/src/__tests__/causal-cell.test.ts +47 -0
  12. package/packages/contracts/src/__tests__/client-view-state.test.ts +115 -0
  13. package/packages/contracts/src/__tests__/cohesion-fixture.test.ts +106 -0
  14. package/packages/contracts/src/__tests__/commands.test.ts +86 -0
  15. package/packages/contracts/src/__tests__/control.test.ts +154 -0
  16. package/packages/contracts/src/__tests__/daemon-events.test.ts +400 -0
  17. package/packages/contracts/src/__tests__/daemon-resources.test.ts +143 -0
  18. package/packages/contracts/src/__tests__/daemon-wire.test.ts +117 -0
  19. package/packages/contracts/src/__tests__/desktop-host.test.ts +269 -0
  20. package/packages/contracts/src/__tests__/desktop-missions.test.ts +211 -0
  21. package/packages/contracts/src/__tests__/experience-conformance.test.ts +153 -0
  22. package/packages/contracts/src/__tests__/experience-kernel-boundary.test.ts +109 -0
  23. package/packages/contracts/src/__tests__/experience-shell.test.ts +65 -0
  24. package/packages/contracts/src/__tests__/fixtures/daemon-wire-v2.json +35 -0
  25. package/packages/contracts/src/__tests__/fleet-agent-graph.test.ts +231 -0
  26. package/packages/contracts/src/__tests__/fleet-catalog.test.ts +268 -0
  27. package/packages/contracts/src/__tests__/fleet-lifecycle.test.ts +62 -0
  28. package/packages/contracts/src/__tests__/focus-overlay.test.ts +110 -0
  29. package/packages/contracts/src/__tests__/ide-config.test.ts +18 -0
  30. package/packages/contracts/src/__tests__/issue-error.test.ts +78 -0
  31. package/packages/contracts/src/__tests__/mission-projections.test.ts +186 -0
  32. package/packages/contracts/src/__tests__/missions.test.ts +272 -0
  33. package/packages/contracts/src/__tests__/multiplexer-verbs.test.ts +240 -0
  34. package/packages/contracts/src/__tests__/pane-appearance.test.ts +146 -0
  35. package/packages/contracts/src/__tests__/pane-stream.test.ts +466 -0
  36. package/packages/contracts/src/__tests__/pane-widget-marker.test.ts +327 -0
  37. package/packages/contracts/src/__tests__/performance-metrics.test.ts +73 -0
  38. package/packages/contracts/src/__tests__/performance-qualification.test.ts +137 -0
  39. package/packages/contracts/src/__tests__/rich-card-widget.test.ts +29 -0
  40. package/packages/contracts/src/__tests__/session-runtime.test.ts +490 -0
  41. package/packages/contracts/src/__tests__/startup-readiness.test.ts +409 -0
  42. package/packages/contracts/src/__tests__/terminal-attachment-stream.test.ts +72 -0
  43. package/packages/contracts/src/__tests__/terminal-attachments.test.ts +329 -0
  44. package/packages/contracts/src/__tests__/terminal-delivery.test.ts +88 -0
  45. package/packages/contracts/src/__tests__/terminal-runtime-inventory.test.ts +68 -0
  46. package/packages/contracts/src/__tests__/visual-tokens.test.ts +224 -0
  47. package/packages/contracts/src/__tests__/workspace-changes-resource.test.ts +317 -0
  48. package/packages/contracts/src/__tests__/workspace-changes-view.test.ts +122 -0
  49. package/packages/contracts/src/__tests__/workspace-config.test.ts +294 -0
  50. package/packages/contracts/src/__tests__/workspace-files-resource.test.ts +261 -0
  51. package/packages/contracts/src/__tests__/workspace-files-tree.test.ts +147 -0
  52. package/packages/contracts/src/__tests__/workspace-pane-creation.test.ts +249 -0
  53. package/packages/contracts/src/__tests__/workspace-promotion.test.ts +94 -0
  54. package/packages/contracts/src/__tests__/workspace-resource-identity.test.ts +90 -0
  55. package/packages/contracts/src/actions-contract.ts +205 -0
  56. package/packages/contracts/src/actions-errors.ts +20 -0
  57. package/packages/contracts/src/agent-graph-overlay.ts +425 -0
  58. package/packages/contracts/src/app-window-mutation.ts +103 -0
  59. package/packages/contracts/src/app-window-state.ts +446 -0
  60. package/packages/contracts/src/application-shell-resource.ts +54 -0
  61. package/packages/contracts/src/application-shell.ts +1094 -0
  62. package/packages/contracts/src/causal-cell.ts +168 -0
  63. package/packages/contracts/src/client-view-state.ts +156 -0
  64. package/packages/contracts/src/cohesion-fixture.ts +647 -0
  65. package/packages/contracts/src/commands.ts +153 -0
  66. package/packages/contracts/src/control.ts +217 -0
  67. package/packages/contracts/src/daemon-events.ts +374 -0
  68. package/packages/contracts/src/daemon-resource-request.test.ts +192 -0
  69. package/packages/contracts/src/daemon-resource-request.ts +397 -0
  70. package/packages/contracts/src/daemon-resources.ts +108 -0
  71. package/packages/contracts/src/daemon-wire.ts +100 -0
  72. package/packages/contracts/src/desktop-daemon-issue.ts +83 -0
  73. package/packages/contracts/src/desktop-host.ts +746 -0
  74. package/packages/contracts/src/desktop-missions.ts +159 -0
  75. package/packages/contracts/src/desktop-update.ts +48 -0
  76. package/packages/contracts/src/desktop-workspace-name.ts +18 -0
  77. package/packages/contracts/src/domain.ts +493 -0
  78. package/packages/contracts/src/experience-identifiers.ts +53 -0
  79. package/packages/contracts/src/experience-shell.ts +249 -0
  80. package/packages/contracts/src/fleet-agent-graph.ts +171 -0
  81. package/packages/contracts/src/fleet-catalog.ts +190 -0
  82. package/packages/contracts/src/fleet-lifecycle.ts +136 -0
  83. package/packages/contracts/src/focus-overlay.ts +175 -0
  84. package/packages/contracts/src/ide-config.ts +40 -20
  85. package/packages/contracts/src/index.ts +60 -0
  86. package/packages/contracts/src/interaction-receipts.ts +438 -0
  87. package/packages/contracts/src/issue-error.ts +107 -0
  88. package/packages/contracts/src/mission-projections.ts +269 -0
  89. package/packages/contracts/src/multiplexer-verbs.ts +447 -0
  90. package/packages/contracts/src/pane-appearance.ts +248 -0
  91. package/packages/contracts/src/pane-stream.ts +709 -0
  92. package/packages/contracts/src/pane-widget-descriptor.ts +62 -0
  93. package/packages/contracts/src/pane-widget-marker.ts +301 -0
  94. package/packages/contracts/src/performance-metrics.ts +128 -0
  95. package/packages/contracts/src/performance-qualification.ts +276 -0
  96. package/packages/contracts/src/rich-card-widget.ts +72 -0
  97. package/packages/contracts/src/semantic-identity.ts +39 -0
  98. package/packages/contracts/src/session-runtime.ts +351 -0
  99. package/packages/contracts/src/shared-monotonic-clock.ts +18 -0
  100. package/packages/contracts/src/startup-readiness.ts +432 -0
  101. package/packages/contracts/src/terminal-attachment-stream.ts +119 -0
  102. package/packages/contracts/src/terminal-attachments.ts +347 -0
  103. package/packages/contracts/src/terminal-delivery.ts +245 -0
  104. package/packages/contracts/src/terminal-replica.ts +133 -0
  105. package/packages/contracts/src/terminal-runtime-inventory.ts +42 -0
  106. package/packages/contracts/src/visual-recipes.ts +126 -0
  107. package/packages/contracts/src/visual-tokens.ts +883 -0
  108. package/packages/contracts/src/widget-asset.ts +43 -0
  109. package/packages/contracts/src/workspace-catalog-resource.test.ts +146 -0
  110. package/packages/contracts/src/workspace-catalog-resource.ts +180 -0
  111. package/packages/contracts/src/workspace-changes-resource.ts +405 -0
  112. package/packages/contracts/src/workspace-changes-view.ts +195 -0
  113. package/packages/contracts/src/workspace-config.ts +303 -0
  114. package/packages/contracts/src/workspace-files-resource.ts +310 -0
  115. package/packages/contracts/src/workspace-files-tree.ts +167 -0
  116. package/packages/contracts/src/workspace-missions-resource.ts +32 -0
  117. package/packages/contracts/src/workspace-multiplexer.ts +373 -0
  118. package/packages/contracts/src/workspace-open-handoff.ts +99 -0
  119. package/packages/contracts/src/workspace-open.ts +64 -0
  120. package/packages/contracts/src/workspace-pane-creation.ts +223 -0
  121. package/packages/contracts/src/workspace-promotion.ts +109 -0
  122. package/packages/contracts/src/workspace-resource-identity.ts +81 -0
  123. package/packages/contracts/src/workspace-state.ts +530 -0
  124. package/packages/contracts/src/workspace.ts +14 -2
  125. package/packages/core/package.json +35 -0
  126. package/packages/core/src/agent-provisioning.test.ts +42 -0
  127. package/packages/core/src/agent-provisioning.ts +112 -0
  128. package/packages/core/src/app-window-identity.ts +33 -0
  129. package/packages/core/src/application-shell-session.test.ts +105 -0
  130. package/packages/core/src/application-shell-session.ts +195 -0
  131. package/packages/core/src/index.ts +15 -0
  132. package/packages/core/src/interaction-flow.test.ts +66 -0
  133. package/packages/core/src/interaction-flow.ts +159 -0
  134. package/packages/core/src/interaction-receipts.test.ts +361 -0
  135. package/packages/core/src/interaction-receipts.ts +335 -0
  136. package/packages/core/src/navigator.test.ts +34 -0
  137. package/packages/core/src/navigator.ts +74 -0
  138. package/packages/core/src/optimistic-projection-conformance.test.ts +75 -0
  139. package/packages/core/src/optimistic-projection-conformance.ts +61 -0
  140. package/packages/core/src/optimistic-projection-store.ts +71 -0
  141. package/packages/core/src/optimistic-projection.test.ts +118 -0
  142. package/packages/core/src/optimistic-projection.ts +194 -0
  143. package/packages/core/src/performance-metrics.test.ts +121 -0
  144. package/packages/core/src/performance-metrics.ts +241 -0
  145. package/packages/core/src/performance-qualification.test.ts +283 -0
  146. package/packages/core/src/performance-qualification.ts +360 -0
  147. package/packages/core/src/terminal-compact-capability.ts +31 -0
  148. package/packages/core/src/terminal-compact-cold.test.ts +87 -0
  149. package/packages/core/src/terminal-conformance.test.ts +48 -0
  150. package/packages/core/src/terminal-conformance.ts +405 -0
  151. package/packages/core/src/terminal-delivery.test.ts +1196 -0
  152. package/packages/core/src/terminal-delivery.ts +2918 -0
  153. package/packages/core/src/terminal-replica-cold.test.ts +31 -0
  154. package/packages/core/src/terminal-replica-hash-cache.test.ts +201 -0
  155. package/packages/core/src/terminal-replica-hash-cache.ts +367 -0
  156. package/packages/core/src/terminal-replica.test.ts +282 -0
  157. package/packages/core/src/terminal-replica.ts +943 -0
  158. package/packages/core/src/workspace-selection.test.ts +63 -0
  159. package/packages/core/src/workspace-selection.ts +97 -0
  160. package/packages/daemon/dist/attach.js +2 -2
  161. package/packages/daemon/dist/canonical.d.ts +2 -2
  162. package/packages/daemon/dist/canonical.js +1 -1
  163. package/packages/daemon/dist/cli.js +37 -36
  164. package/packages/daemon/dist/command-center/actions/command-definitions.d.ts +4 -0
  165. package/packages/daemon/dist/command-center/actions/command-definitions.js +70 -0
  166. package/packages/daemon/dist/command-center/actions/dispatcher.d.ts +29 -0
  167. package/packages/daemon/dist/command-center/actions/dispatcher.js +228 -10
  168. package/packages/daemon/dist/command-center/actions/errors.d.ts +1 -1
  169. package/packages/daemon/dist/command-center/actions/handlers/_project-context.d.ts +1 -1
  170. package/packages/daemon/dist/command-center/actions/handlers/_project-context.js +3 -4
  171. package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.d.ts +8 -0
  172. package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.js +39 -0
  173. package/packages/daemon/dist/command-center/actions/handlers/config-actions.d.ts +6 -6
  174. package/packages/daemon/dist/command-center/actions/handlers/config-actions.js +44 -20
  175. package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.d.ts +2 -1
  176. package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.js +11 -1
  177. package/packages/daemon/dist/command-center/actions/handlers/fleet-lifecycle.d.ts +10 -0
  178. package/packages/daemon/dist/command-center/actions/handlers/fleet-lifecycle.js +56 -0
  179. package/packages/daemon/dist/command-center/actions/handlers/project-launch.js +16 -4
  180. package/packages/daemon/dist/command-center/actions/handlers/workspace-multiplexer.d.ts +186 -0
  181. package/packages/daemon/dist/command-center/actions/handlers/workspace-multiplexer.js +55 -0
  182. package/packages/daemon/dist/command-center/actions/handlers/workspace-open.d.ts +16 -0
  183. package/packages/daemon/dist/command-center/actions/handlers/workspace-open.js +89 -0
  184. package/packages/daemon/dist/command-center/actions/handlers/workspace-pane-create.d.ts +8 -0
  185. package/packages/daemon/dist/command-center/actions/handlers/workspace-pane-create.js +34 -0
  186. package/packages/daemon/dist/command-center/actions/handlers/workspace-promote.d.ts +8 -0
  187. package/packages/daemon/dist/command-center/actions/handlers/workspace-promote.js +34 -0
  188. package/packages/daemon/dist/command-center/actions/registry.d.ts +33 -2
  189. package/packages/daemon/dist/command-center/actions/registry.js +126 -0
  190. package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.d.ts +3 -0
  191. package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.js +16 -0
  192. package/packages/daemon/dist/command-center/agent-status-watch.d.ts +100 -0
  193. package/packages/daemon/dist/command-center/agent-status-watch.js +170 -0
  194. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.d.ts +57 -0
  195. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +395 -0
  196. package/packages/daemon/dist/command-center/discovery.d.ts +98 -1
  197. package/packages/daemon/dist/command-center/discovery.js +262 -3
  198. package/packages/daemon/dist/command-center/owner-authority.d.ts +71 -0
  199. package/packages/daemon/dist/command-center/owner-authority.js +46 -0
  200. package/packages/daemon/dist/command-center/pane-stream-issue.d.ts +26 -0
  201. package/packages/daemon/dist/command-center/pane-stream-issue.js +185 -0
  202. package/packages/daemon/dist/command-center/resources/agent-graph-overlay.d.ts +45 -0
  203. package/packages/daemon/dist/command-center/resources/agent-graph-overlay.js +234 -0
  204. package/packages/daemon/dist/command-center/resources/application-shell.d.ts +201 -0
  205. package/packages/daemon/dist/command-center/resources/application-shell.js +641 -0
  206. package/packages/daemon/dist/command-center/resources/desktop-missions.d.ts +10 -0
  207. package/packages/daemon/dist/command-center/resources/desktop-missions.js +132 -0
  208. package/packages/daemon/dist/command-center/resources/fleet-catalog.d.ts +25 -0
  209. package/packages/daemon/dist/command-center/resources/fleet-catalog.js +163 -0
  210. package/packages/daemon/dist/command-center/resources/fleet-resource-route.d.ts +25 -0
  211. package/packages/daemon/dist/command-center/resources/fleet-resource-route.js +46 -0
  212. package/packages/daemon/dist/command-center/resources/startup-readiness-route.d.ts +38 -0
  213. package/packages/daemon/dist/command-center/resources/startup-readiness-route.js +121 -0
  214. package/packages/daemon/dist/command-center/resources/startup-readiness.d.ts +57 -0
  215. package/packages/daemon/dist/command-center/resources/startup-readiness.js +183 -0
  216. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.d.ts +5 -0
  217. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +24 -0
  218. package/packages/daemon/dist/command-center/resources/workspace-changes-authority.d.ts +39 -0
  219. package/packages/daemon/dist/command-center/resources/workspace-changes-authority.js +451 -0
  220. package/packages/daemon/dist/command-center/resources/workspace-changes-git.d.ts +63 -0
  221. package/packages/daemon/dist/command-center/resources/workspace-changes-git.js +222 -0
  222. package/packages/daemon/dist/command-center/resources/workspace-files-authority.d.ts +44 -0
  223. package/packages/daemon/dist/command-center/resources/workspace-files-authority.js +493 -0
  224. package/packages/daemon/dist/command-center/resources/workspace-missions-route.d.ts +22 -0
  225. package/packages/daemon/dist/command-center/resources/workspace-missions-route.js +75 -0
  226. package/packages/daemon/dist/command-center/resources/workspace-resource-ids.d.ts +24 -0
  227. package/packages/daemon/dist/command-center/resources/workspace-resource-ids.js +69 -0
  228. package/packages/daemon/dist/command-center/resources/workspace-resource-routes.d.ts +17 -0
  229. package/packages/daemon/dist/command-center/resources/workspace-resource-routes.js +116 -0
  230. package/packages/daemon/dist/command-center/schemas.d.ts +1 -1
  231. package/packages/daemon/dist/command-center/server.d.ts +57 -1
  232. package/packages/daemon/dist/command-center/server.js +540 -51
  233. package/packages/daemon/dist/command-center/terminal-attachment-issue.d.ts +22 -0
  234. package/packages/daemon/dist/command-center/terminal-attachment-issue.js +191 -0
  235. package/packages/daemon/dist/command-center/workspace-resource-observer.d.ts +50 -0
  236. package/packages/daemon/dist/command-center/workspace-resource-observer.js +453 -0
  237. package/packages/daemon/dist/command-center/ws-events.d.ts +82 -7
  238. package/packages/daemon/dist/command-center/ws-events.js +681 -63
  239. package/packages/daemon/dist/config.js +31 -25
  240. package/packages/daemon/dist/control/client.d.ts +23 -0
  241. package/packages/daemon/dist/control/client.js +105 -0
  242. package/packages/daemon/dist/control/dispatch.d.ts +34 -0
  243. package/packages/daemon/dist/control/dispatch.js +83 -0
  244. package/packages/daemon/dist/control/fanout.d.ts +19 -0
  245. package/packages/daemon/dist/control/fanout.js +37 -0
  246. package/packages/daemon/dist/control/frames.d.ts +23 -0
  247. package/packages/daemon/dist/control/frames.js +37 -0
  248. package/packages/daemon/dist/control/lifecycle.d.ts +45 -0
  249. package/packages/daemon/dist/control/lifecycle.js +124 -0
  250. package/packages/daemon/dist/control/server.d.ts +16 -0
  251. package/packages/daemon/dist/control/server.js +214 -0
  252. package/packages/daemon/dist/control/verbs.d.ts +11 -0
  253. package/packages/daemon/dist/control/verbs.js +91 -0
  254. package/packages/daemon/dist/detect.js +23 -20
  255. package/packages/daemon/dist/doctor.d.ts +18 -0
  256. package/packages/daemon/dist/doctor.js +127 -21
  257. package/packages/daemon/dist/index.d.ts +21 -2
  258. package/packages/daemon/dist/index.js +20 -1
  259. package/packages/daemon/dist/init.js +24 -22
  260. package/packages/daemon/dist/inspect.d.ts +7 -1
  261. package/packages/daemon/dist/inspect.js +33 -8
  262. package/packages/daemon/dist/launch.d.ts +2 -0
  263. package/packages/daemon/dist/launch.js +38 -26
  264. package/packages/daemon/dist/lib/__tests__/fixtures/workspace-state-writer.js +58 -0
  265. package/packages/daemon/dist/lib/agent-discovery.d.ts +27 -2
  266. package/packages/daemon/dist/lib/agent-discovery.js +29 -14
  267. package/packages/daemon/dist/lib/agent-kind.d.ts +7 -0
  268. package/packages/daemon/dist/lib/agent-kind.js +24 -0
  269. package/packages/daemon/dist/lib/app-config.d.ts +111 -0
  270. package/packages/daemon/dist/lib/app-config.js +130 -5
  271. package/packages/daemon/dist/lib/app-window-kernel.d.ts +64 -0
  272. package/packages/daemon/dist/lib/app-window-kernel.js +556 -0
  273. package/packages/daemon/dist/lib/app-window-mutation.d.ts +28 -0
  274. package/packages/daemon/dist/lib/app-window-mutation.js +139 -0
  275. package/packages/daemon/dist/lib/app-window-repository.d.ts +81 -0
  276. package/packages/daemon/dist/lib/app-window-repository.js +368 -0
  277. package/packages/daemon/dist/lib/app-window-state.d.ts +57 -0
  278. package/packages/daemon/dist/lib/app-window-state.js +415 -0
  279. package/packages/daemon/dist/lib/application-shell-app-windows.d.ts +16 -0
  280. package/packages/daemon/dist/lib/application-shell-app-windows.js +285 -0
  281. package/packages/daemon/dist/lib/auth/middleware.d.ts +1 -1
  282. package/packages/daemon/dist/lib/auth/middleware.js +7 -3
  283. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.d.ts +25 -0
  284. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +174 -0
  285. package/packages/daemon/dist/lib/canonical-daemon.d.ts +80 -14
  286. package/packages/daemon/dist/lib/canonical-daemon.js +507 -70
  287. package/packages/daemon/dist/lib/chrome-front-door.d.ts +7 -0
  288. package/packages/daemon/dist/lib/chrome-front-door.js +13 -0
  289. package/packages/daemon/dist/lib/cli-action-bridge.d.ts +8 -3
  290. package/packages/daemon/dist/lib/cli-action-bridge.js +112 -82
  291. package/packages/daemon/dist/lib/command-registry.d.ts +37 -0
  292. package/packages/daemon/dist/lib/command-registry.js +107 -0
  293. package/packages/daemon/dist/lib/config-context.d.ts +18 -0
  294. package/packages/daemon/dist/lib/config-context.js +34 -0
  295. package/packages/daemon/dist/lib/daemon-embed.d.ts +30 -0
  296. package/packages/daemon/dist/lib/daemon-embed.js +1060 -356
  297. package/packages/daemon/dist/lib/daemon-session-monitor.d.ts +50 -0
  298. package/packages/daemon/dist/lib/daemon-session-monitor.js +194 -0
  299. package/packages/daemon/dist/lib/daemon.js +3 -47
  300. package/packages/daemon/dist/lib/directory-watcher.d.ts +12 -0
  301. package/packages/daemon/dist/lib/directory-watcher.js +118 -0
  302. package/packages/daemon/dist/lib/environment-identity.d.ts +9 -0
  303. package/packages/daemon/dist/lib/environment-identity.js +79 -0
  304. package/packages/daemon/dist/lib/errors.d.ts +1 -1
  305. package/packages/daemon/dist/lib/fleet-agent-lifecycle.d.ts +8 -0
  306. package/packages/daemon/dist/lib/fleet-agent-lifecycle.js +65 -0
  307. package/packages/daemon/dist/lib/fleet-lifecycle-authority.d.ts +21 -0
  308. package/packages/daemon/dist/lib/fleet-lifecycle-authority.js +437 -0
  309. package/packages/daemon/dist/lib/headless-daemon.d.ts +33 -0
  310. package/packages/daemon/dist/lib/headless-daemon.js +306 -0
  311. package/packages/daemon/dist/lib/launch-plan.d.ts +20 -1
  312. package/packages/daemon/dist/lib/launch-plan.js +96 -1
  313. package/packages/daemon/dist/lib/legacy-config-adapter.d.ts +12 -0
  314. package/packages/daemon/dist/lib/legacy-config-adapter.js +19 -0
  315. package/packages/daemon/dist/lib/legacy-config-migration.d.ts +15 -0
  316. package/packages/daemon/dist/lib/legacy-config-migration.js +110 -0
  317. package/packages/daemon/dist/lib/legacy-theme-compat.d.ts +14 -0
  318. package/packages/daemon/dist/lib/legacy-theme-compat.js +25 -0
  319. package/packages/daemon/dist/lib/manifest-pack.d.ts +79 -0
  320. package/packages/daemon/dist/lib/manifest-pack.js +232 -0
  321. package/packages/daemon/dist/lib/mission-projections.d.ts +24 -0
  322. package/packages/daemon/dist/lib/mission-projections.js +615 -0
  323. package/packages/daemon/dist/lib/mission-repository.d.ts +941 -0
  324. package/packages/daemon/dist/lib/mission-repository.js +775 -0
  325. package/packages/daemon/dist/lib/onboarding-marker.d.ts +13 -0
  326. package/packages/daemon/dist/lib/onboarding-marker.js +51 -0
  327. package/packages/daemon/dist/lib/pane-chrome.d.ts +12 -0
  328. package/packages/daemon/dist/lib/pane-chrome.js +12 -0
  329. package/packages/daemon/dist/lib/pane-source-credentials.d.ts +32 -0
  330. package/packages/daemon/dist/lib/pane-source-credentials.js +178 -0
  331. package/packages/daemon/dist/lib/pane-widget.d.ts +61 -0
  332. package/packages/daemon/dist/lib/pane-widget.js +126 -0
  333. package/packages/daemon/dist/lib/project-inspect.js +4 -0
  334. package/packages/daemon/dist/lib/project-onboard.d.ts +5 -5
  335. package/packages/daemon/dist/lib/project-onboard.js +17 -21
  336. package/packages/daemon/dist/lib/project-probe.d.ts +9 -3
  337. package/packages/daemon/dist/lib/project-probe.js +28 -22
  338. package/packages/daemon/dist/lib/project-readiness-probe.d.ts +60 -0
  339. package/packages/daemon/dist/lib/project-readiness-probe.js +425 -0
  340. package/packages/daemon/dist/lib/project-readiness.d.ts +157 -0
  341. package/packages/daemon/dist/lib/project-readiness.js +680 -0
  342. package/packages/daemon/dist/lib/project-registry.d.ts +8 -0
  343. package/packages/daemon/dist/lib/project-registry.js +42 -9
  344. package/packages/daemon/dist/lib/project-resolver.d.ts +77 -0
  345. package/packages/daemon/dist/lib/project-resolver.js +245 -0
  346. package/packages/daemon/dist/lib/project-runtime-errors.d.ts +13 -0
  347. package/packages/daemon/dist/lib/project-runtime-errors.js +21 -0
  348. package/packages/daemon/dist/lib/project-runtime-repository.d.ts +193 -0
  349. package/packages/daemon/dist/lib/project-runtime-repository.js +876 -0
  350. package/packages/daemon/dist/lib/resolved-config.d.ts +48 -0
  351. package/packages/daemon/dist/lib/resolved-config.js +318 -0
  352. package/packages/daemon/dist/lib/runtime-namespace.d.ts +34 -0
  353. package/packages/daemon/dist/lib/runtime-namespace.js +136 -0
  354. package/packages/daemon/dist/lib/semantic-resource-id.d.ts +7 -0
  355. package/packages/daemon/dist/lib/semantic-resource-id.js +14 -0
  356. package/packages/daemon/dist/lib/session-monitor.d.ts +2 -0
  357. package/packages/daemon/dist/lib/session-monitor.js +29 -23
  358. package/packages/daemon/dist/lib/session-options.js +3 -10
  359. package/packages/daemon/dist/lib/state-home.d.ts +2 -0
  360. package/packages/daemon/dist/lib/state-home.js +11 -0
  361. package/packages/daemon/dist/lib/theme-mode.d.ts +10 -0
  362. package/packages/daemon/dist/lib/theme-mode.js +9 -0
  363. package/packages/daemon/dist/lib/tmux-external-interaction-observer.d.ts +88 -0
  364. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +534 -0
  365. package/packages/daemon/dist/lib/tmux-interaction-options.d.ts +34 -0
  366. package/packages/daemon/dist/lib/tmux-interaction-options.js +126 -0
  367. package/packages/daemon/dist/lib/tmux-terminal-color.d.ts +18 -0
  368. package/packages/daemon/dist/lib/tmux-terminal-color.js +37 -0
  369. package/packages/daemon/dist/lib/tui-binary.d.ts +30 -5
  370. package/packages/daemon/dist/lib/tui-binary.js +291 -28
  371. package/packages/daemon/dist/lib/unix-socket-authority.d.ts +9 -0
  372. package/packages/daemon/dist/lib/unix-socket-authority.js +48 -0
  373. package/packages/daemon/dist/lib/update-check.js +5 -0
  374. package/packages/daemon/dist/lib/widget-asset-policy.d.ts +3 -0
  375. package/packages/daemon/dist/lib/widget-asset-policy.js +3 -0
  376. package/packages/daemon/dist/lib/widget-asset-store.d.ts +22 -0
  377. package/packages/daemon/dist/lib/widget-asset-store.js +166 -0
  378. package/packages/daemon/dist/lib/workspace-config-loader.d.ts +68 -0
  379. package/packages/daemon/dist/lib/workspace-config-loader.js +280 -0
  380. package/packages/daemon/dist/lib/workspace-multiplexer-verbs.d.ts +109 -0
  381. package/packages/daemon/dist/lib/workspace-multiplexer-verbs.js +1138 -0
  382. package/packages/daemon/dist/lib/workspace-open-handoff.d.ts +41 -0
  383. package/packages/daemon/dist/lib/workspace-open-handoff.js +219 -0
  384. package/packages/daemon/dist/lib/workspace-open.d.ts +44 -0
  385. package/packages/daemon/dist/lib/workspace-open.js +740 -0
  386. package/packages/daemon/dist/lib/workspace-pane-creation.d.ts +64 -0
  387. package/packages/daemon/dist/lib/workspace-pane-creation.js +1107 -0
  388. package/packages/daemon/dist/lib/workspace-promotion.d.ts +41 -0
  389. package/packages/daemon/dist/lib/workspace-promotion.js +804 -0
  390. package/packages/daemon/dist/lib/workspace-registry.d.ts +49 -2
  391. package/packages/daemon/dist/lib/workspace-registry.js +150 -23
  392. package/packages/daemon/dist/lib/workspace-state-repository.d.ts +139 -0
  393. package/packages/daemon/dist/lib/workspace-state-repository.js +790 -0
  394. package/packages/daemon/dist/lib/workspace-state.d.ts +37 -0
  395. package/packages/daemon/dist/lib/workspace-state.js +765 -0
  396. package/packages/daemon/dist/lib/yaml-io.js +4 -18
  397. package/packages/daemon/dist/migrate.d.ts +11 -0
  398. package/packages/daemon/dist/migrate.js +105 -0
  399. package/packages/daemon/dist/restart.js +2 -2
  400. package/packages/daemon/dist/restore.d.ts +40 -13
  401. package/packages/daemon/dist/restore.js +62 -21
  402. package/packages/daemon/dist/schemas/inspect.d.ts +8 -0
  403. package/packages/daemon/dist/schemas/inspect.js +9 -1
  404. package/packages/daemon/dist/schemas/registry.d.ts +18 -4
  405. package/packages/daemon/dist/schemas/registry.js +5 -19
  406. package/packages/daemon/dist/schemas/ws-events.d.ts +5 -69
  407. package/packages/daemon/dist/schemas/ws-events.js +4 -107
  408. package/packages/daemon/dist/send.d.ts +41 -1
  409. package/packages/daemon/dist/send.js +136 -20
  410. package/packages/daemon/dist/server/pane-stream-upgrade.d.ts +12 -0
  411. package/packages/daemon/dist/server/pane-stream-upgrade.js +117 -0
  412. package/packages/daemon/dist/server/terminal-attachment-upgrade.d.ts +11 -0
  413. package/packages/daemon/dist/server/terminal-attachment-upgrade.js +121 -0
  414. package/packages/daemon/dist/status.js +11 -8
  415. package/packages/daemon/dist/stop.js +2 -2
  416. package/packages/daemon/dist/terminal/MonotonicPtyInput.d.ts +30 -0
  417. package/packages/daemon/dist/terminal/MonotonicPtyInput.js +130 -0
  418. package/packages/daemon/dist/terminal/NodePtyAdapter.d.ts +9 -3
  419. package/packages/daemon/dist/terminal/NodePtyAdapter.js +37 -10
  420. package/packages/daemon/dist/terminal/PtyAdapter.d.ts +93 -3
  421. package/packages/daemon/dist/terminal/PtyAdapter.js +18 -0
  422. package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.d.ts +14 -4
  423. package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.js +33 -6
  424. package/packages/daemon/dist/terminal/attachments/admission-util.d.ts +14 -0
  425. package/packages/daemon/dist/terminal/attachments/admission-util.js +87 -0
  426. package/packages/daemon/dist/terminal/attachments/agent-status-probe.d.ts +102 -0
  427. package/packages/daemon/dist/terminal/attachments/agent-status-probe.js +325 -0
  428. package/packages/daemon/dist/terminal/attachments/direct-websocket.d.ts +141 -0
  429. package/packages/daemon/dist/terminal/attachments/direct-websocket.js +1069 -0
  430. package/packages/daemon/dist/terminal/attachments/grouped-tmux.d.ts +106 -0
  431. package/packages/daemon/dist/terminal/attachments/grouped-tmux.js +213 -0
  432. package/packages/daemon/dist/terminal/attachments/lease-manager.d.ts +188 -0
  433. package/packages/daemon/dist/terminal/attachments/lease-manager.js +655 -0
  434. package/packages/daemon/dist/terminal/attachments/native-runtime.d.ts +196 -0
  435. package/packages/daemon/dist/terminal/attachments/native-runtime.js +1564 -0
  436. package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.d.ts +66 -0
  437. package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.js +607 -0
  438. package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.d.ts +81 -0
  439. package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.js +208 -0
  440. package/packages/daemon/dist/terminal/attachments/tmux-view-executor.d.ts +111 -0
  441. package/packages/daemon/dist/terminal/attachments/tmux-view-executor.js +825 -0
  442. package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.d.ts +25 -0
  443. package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.js +80 -0
  444. package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.d.ts +66 -0
  445. package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.js +133 -0
  446. package/packages/daemon/dist/terminal/mirror/control-channel.d.ts +188 -0
  447. package/packages/daemon/dist/terminal/mirror/control-channel.js +624 -0
  448. package/packages/daemon/dist/terminal/mirror/control-mode-ownership.d.ts +14 -0
  449. package/packages/daemon/dist/terminal/mirror/control-mode-ownership.js +30 -0
  450. package/packages/daemon/dist/terminal/mirror/events.d.ts +115 -0
  451. package/packages/daemon/dist/terminal/mirror/events.js +18 -0
  452. package/packages/daemon/dist/terminal/mirror/flow-ledger.d.ts +40 -0
  453. package/packages/daemon/dist/terminal/mirror/flow-ledger.js +56 -0
  454. package/packages/daemon/dist/terminal/mirror/mirror-service.d.ts +137 -0
  455. package/packages/daemon/dist/terminal/mirror/mirror-service.js +329 -0
  456. package/packages/daemon/dist/terminal/mirror/pane-feed.d.ts +90 -0
  457. package/packages/daemon/dist/terminal/mirror/pane-feed.js +140 -0
  458. package/packages/daemon/dist/terminal/mirror/session-channel.d.ts +216 -0
  459. package/packages/daemon/dist/terminal/mirror/session-channel.js +2301 -0
  460. package/packages/daemon/dist/terminal/mirror/trusted-inventory.d.ts +28 -0
  461. package/packages/daemon/dist/terminal/pane-stream/lease-manager.d.ts +72 -0
  462. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +245 -0
  463. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.d.ts +208 -0
  464. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +2058 -0
  465. package/packages/daemon/dist/terminal/pane-stream/runtime.d.ts +26 -0
  466. package/packages/daemon/dist/terminal/pane-stream/runtime.js +53 -0
  467. package/packages/daemon/dist/terminal/pane-stream/wire-ledger.d.ts +59 -0
  468. package/packages/daemon/dist/terminal/pane-stream/wire-ledger.js +110 -0
  469. package/packages/daemon/dist/terminal/protocol/chunk-bytes.d.ts +3 -0
  470. package/packages/daemon/dist/terminal/protocol/chunk-bytes.js +21 -0
  471. package/packages/daemon/dist/terminal/protocol/control.d.ts +66 -0
  472. package/packages/daemon/dist/terminal/protocol/control.js +111 -0
  473. package/packages/daemon/dist/terminal/protocol/input-coalescer.d.ts +55 -0
  474. package/packages/daemon/dist/terminal/protocol/input-coalescer.js +111 -0
  475. package/packages/daemon/dist/terminal/protocol/layout-parse.d.ts +68 -0
  476. package/packages/daemon/dist/terminal/protocol/layout-parse.js +127 -0
  477. package/packages/daemon/dist/terminal/protocol/pane-display-name.d.ts +16 -0
  478. package/packages/daemon/dist/terminal/protocol/pane-display-name.js +153 -0
  479. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.d.ts +78 -0
  480. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +294 -0
  481. package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.d.ts +90 -0
  482. package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.js +213 -0
  483. package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.d.ts +36 -0
  484. package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.js +260 -0
  485. package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.d.ts +29 -0
  486. package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.js +278 -0
  487. package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.d.ts +12 -0
  488. package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.js +147 -0
  489. package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.d.ts +16 -0
  490. package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.js +116 -0
  491. package/packages/daemon/dist/terminal/session-runtime/registry.d.ts +148 -0
  492. package/packages/daemon/dist/terminal/session-runtime/registry.js +1368 -0
  493. package/packages/daemon/dist/terminal/session-runtime/runtime-observability.d.ts +118 -0
  494. package/packages/daemon/dist/terminal/session-runtime/runtime-observability.js +72 -0
  495. package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.d.ts +11 -0
  496. package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.js +10 -0
  497. package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.d.ts +18 -0
  498. package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.js +48 -0
  499. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-executor.d.ts +69 -0
  500. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-executor.js +353 -0
  501. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-resource-changes.d.ts +8 -0
  502. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-resource-changes.js +32 -0
  503. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.d.ts +91 -0
  504. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +1362 -0
  505. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.d.ts +3 -0
  506. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.js +9 -0
  507. package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.d.ts +55 -0
  508. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.d.ts +91 -0
  509. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +528 -0
  510. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.d.ts +50 -0
  511. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +387 -0
  512. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.d.ts +37 -0
  513. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.js +21 -0
  514. package/packages/daemon/dist/terminal/session-runtime/transport-binding.d.ts +75 -0
  515. package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +474 -0
  516. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.d.ts +26 -0
  517. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +276 -0
  518. package/packages/daemon/dist/tui/async-disposable-slot.d.ts +18 -0
  519. package/packages/daemon/dist/tui/async-disposable-slot.js +57 -0
  520. package/packages/daemon/dist/tui/chrome/cheatsheet.d.ts +59 -0
  521. package/packages/daemon/dist/tui/chrome/cheatsheet.js +211 -0
  522. package/packages/daemon/dist/tui/chrome/chip.d.ts +21 -0
  523. package/packages/daemon/dist/tui/chrome/chip.js +25 -0
  524. package/packages/daemon/dist/tui/chrome/events.d.ts +51 -0
  525. package/packages/daemon/dist/tui/chrome/events.js +94 -0
  526. package/packages/daemon/dist/tui/chrome/front-door.d.ts +16 -0
  527. package/packages/daemon/dist/tui/chrome/front-door.js +16 -0
  528. package/packages/daemon/dist/tui/chrome/kitty-keys.d.ts +41 -0
  529. package/packages/daemon/dist/tui/chrome/kitty-keys.js +54 -0
  530. package/packages/daemon/dist/tui/chrome/menu.d.ts +92 -0
  531. package/packages/daemon/dist/tui/chrome/menu.js +251 -0
  532. package/packages/daemon/dist/tui/chrome/notify-prefs.d.ts +47 -0
  533. package/packages/daemon/dist/tui/chrome/notify-prefs.js +13 -0
  534. package/packages/daemon/dist/tui/chrome/notify-state.d.ts +13 -0
  535. package/packages/daemon/dist/tui/chrome/notify-state.js +77 -0
  536. package/packages/daemon/dist/tui/chrome/notify.d.ts +361 -0
  537. package/packages/daemon/dist/tui/chrome/notify.js +711 -0
  538. package/packages/daemon/dist/tui/chrome/panels.d.ts +72 -0
  539. package/packages/daemon/dist/tui/chrome/panels.js +60 -0
  540. package/packages/daemon/dist/tui/chrome/sidebar.d.ts +77 -0
  541. package/packages/daemon/dist/tui/chrome/sidebar.js +183 -0
  542. package/packages/daemon/dist/tui/chrome/snapshot.d.ts +110 -0
  543. package/packages/daemon/dist/tui/chrome/snapshot.js +290 -0
  544. package/packages/daemon/dist/tui/chrome/statusline.d.ts +237 -0
  545. package/packages/daemon/dist/tui/chrome/statusline.js +552 -0
  546. package/packages/daemon/dist/tui/chrome/updater.d.ts +230 -0
  547. package/packages/daemon/dist/tui/chrome/updater.js +651 -0
  548. package/packages/daemon/dist/tui/chrome/welcome.d.ts +41 -0
  549. package/packages/daemon/dist/tui/chrome/welcome.js +117 -0
  550. package/packages/daemon/dist/tui/compiled.d.ts +86 -0
  551. package/packages/daemon/dist/tui/compiled.js +165 -0
  552. package/packages/daemon/dist/tui/detect/agent-resolution.d.ts +56 -0
  553. package/packages/daemon/dist/tui/detect/agent-resolution.js +60 -0
  554. package/packages/daemon/dist/tui/detect/classify.d.ts +107 -0
  555. package/packages/daemon/dist/tui/detect/classify.js +184 -0
  556. package/packages/daemon/dist/tui/detect/manifest-loader.d.ts +54 -0
  557. package/packages/daemon/dist/tui/detect/manifest-loader.js +242 -0
  558. package/packages/daemon/dist/tui/detect/manifest.d.ts +111 -0
  559. package/packages/daemon/dist/tui/detect/manifest.js +126 -0
  560. package/packages/daemon/dist/tui/detect/manifests.d.ts +40 -0
  561. package/packages/daemon/dist/tui/detect/manifests.js +535 -0
  562. package/packages/daemon/dist/tui/detect/process-tree.d.ts +96 -0
  563. package/packages/daemon/dist/tui/detect/process-tree.js +194 -0
  564. package/packages/daemon/dist/tui/detect/session-id.d.ts +110 -0
  565. package/packages/daemon/dist/tui/detect/session-id.js +414 -0
  566. package/packages/daemon/dist/tui/detect/snapshot.d.ts +27 -0
  567. package/packages/daemon/dist/tui/detect/snapshot.js +81 -0
  568. package/packages/daemon/dist/tui/integrations/claude.d.ts +65 -0
  569. package/packages/daemon/dist/tui/integrations/claude.js +151 -0
  570. package/packages/daemon/dist/tui/integrations/offer.d.ts +47 -0
  571. package/packages/daemon/dist/tui/integrations/offer.js +134 -0
  572. package/packages/daemon/dist/tui/integrations/opencode.d.ts +37 -0
  573. package/packages/daemon/dist/tui/integrations/opencode.js +117 -0
  574. package/packages/daemon/dist/tui/mirror/ack-writer.d.ts +36 -0
  575. package/packages/daemon/dist/tui/mirror/ack-writer.js +78 -0
  576. package/packages/daemon/dist/tui/mirror/activity-surface-view.d.ts +8 -0
  577. package/packages/daemon/dist/tui/mirror/activity-surface-view.jsx +69 -0
  578. package/packages/daemon/dist/tui/mirror/activity-surface.d.ts +103 -0
  579. package/packages/daemon/dist/tui/mirror/activity-surface.js +271 -0
  580. package/packages/daemon/dist/tui/mirror/agent-chip.d.ts +76 -0
  581. package/packages/daemon/dist/tui/mirror/agent-chip.js +84 -0
  582. package/packages/daemon/dist/tui/mirror/agent-lifecycle.d.ts +217 -0
  583. package/packages/daemon/dist/tui/mirror/agent-lifecycle.js +372 -0
  584. package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.d.ts +42 -0
  585. package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.js +86 -0
  586. package/packages/daemon/dist/tui/mirror/agent-rows.d.ts +119 -0
  587. package/packages/daemon/dist/tui/mirror/agent-rows.js +126 -0
  588. package/packages/daemon/dist/tui/mirror/ansi-palette.d.ts +3 -0
  589. package/packages/daemon/dist/tui/mirror/ansi-palette.js +3 -0
  590. package/packages/daemon/dist/tui/mirror/app-state.d.ts +114 -0
  591. package/packages/daemon/dist/tui/mirror/app-state.js +294 -0
  592. package/packages/daemon/dist/tui/mirror/application-keybindings.d.ts +18 -0
  593. package/packages/daemon/dist/tui/mirror/application-keybindings.js +33 -0
  594. package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.d.ts +53 -0
  595. package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.js +253 -0
  596. package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.d.ts +22 -0
  597. package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.js +45 -0
  598. package/packages/daemon/dist/tui/mirror/attention.d.ts +63 -0
  599. package/packages/daemon/dist/tui/mirror/attention.js +59 -0
  600. package/packages/daemon/dist/tui/mirror/blit.d.ts +82 -0
  601. package/packages/daemon/dist/tui/mirror/blit.js +120 -0
  602. package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.d.ts +11 -0
  603. package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.js +45 -0
  604. package/packages/daemon/dist/tui/mirror/changes-surface-view.d.ts +19 -0
  605. package/packages/daemon/dist/tui/mirror/changes-surface-view.jsx +92 -0
  606. package/packages/daemon/dist/tui/mirror/changes-surface.d.ts +115 -0
  607. package/packages/daemon/dist/tui/mirror/changes-surface.js +210 -0
  608. package/packages/daemon/dist/tui/mirror/composite-layout.d.ts +91 -0
  609. package/packages/daemon/dist/tui/mirror/composite-layout.js +539 -0
  610. package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.d.ts +39 -0
  611. package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.js +133 -0
  612. package/packages/daemon/dist/tui/mirror/dialog-model.d.ts +154 -0
  613. package/packages/daemon/dist/tui/mirror/dialog-model.js +183 -0
  614. package/packages/daemon/dist/tui/mirror/dialog-stack-core.d.ts +45 -0
  615. package/packages/daemon/dist/tui/mirror/dialog-stack-core.js +232 -0
  616. package/packages/daemon/dist/tui/mirror/dialog-stack.d.ts +2 -0
  617. package/packages/daemon/dist/tui/mirror/dialog-stack.js +2 -0
  618. package/packages/daemon/dist/tui/mirror/diff-model.d.ts +169 -0
  619. package/packages/daemon/dist/tui/mirror/diff-model.js +332 -0
  620. package/packages/daemon/dist/tui/mirror/editor-buffer.d.ts +24 -0
  621. package/packages/daemon/dist/tui/mirror/editor-buffer.js +47 -0
  622. package/packages/daemon/dist/tui/mirror/editor-open-policy.d.ts +9 -0
  623. package/packages/daemon/dist/tui/mirror/editor-open-policy.js +9 -0
  624. package/packages/daemon/dist/tui/mirror/features/changes/contract.d.ts +75 -0
  625. package/packages/daemon/dist/tui/mirror/features/changes/controller.d.ts +10 -0
  626. package/packages/daemon/dist/tui/mirror/features/changes/controller.js +454 -0
  627. package/packages/daemon/dist/tui/mirror/features/changes/feature.d.ts +10 -0
  628. package/packages/daemon/dist/tui/mirror/features/changes/feature.jsx +9 -0
  629. package/packages/daemon/dist/tui/mirror/features/dialogs/contract.d.ts +47 -0
  630. package/packages/daemon/dist/tui/mirror/features/dialogs/contract.js +1 -0
  631. package/packages/daemon/dist/tui/mirror/features/dialogs/feature.d.ts +12 -0
  632. package/packages/daemon/dist/tui/mirror/features/dialogs/feature.jsx +123 -0
  633. package/packages/daemon/dist/tui/mirror/features/dialogs/session.d.ts +9 -0
  634. package/packages/daemon/dist/tui/mirror/features/dialogs/session.js +160 -0
  635. package/packages/daemon/dist/tui/mirror/features/files/feature.d.ts +16 -0
  636. package/packages/daemon/dist/tui/mirror/features/files/feature.jsx +15 -0
  637. package/packages/daemon/dist/tui/mirror/features/files/session.d.ts +133 -0
  638. package/packages/daemon/dist/tui/mirror/features/files/session.js +617 -0
  639. package/packages/daemon/dist/tui/mirror/features/home/feature.d.ts +28 -0
  640. package/packages/daemon/dist/tui/mirror/features/home/feature.jsx +122 -0
  641. package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.d.ts +84 -0
  642. package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.js +3 -0
  643. package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.d.ts +6 -0
  644. package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.jsx +5 -0
  645. package/packages/daemon/dist/tui/mirror/features/missions-activity/session.d.ts +5 -0
  646. package/packages/daemon/dist/tui/mirror/features/missions-activity/session.js +377 -0
  647. package/packages/daemon/dist/tui/mirror/features/palette/contract.d.ts +116 -0
  648. package/packages/daemon/dist/tui/mirror/features/palette/contract.js +9 -0
  649. package/packages/daemon/dist/tui/mirror/features/palette/feature.d.ts +4 -0
  650. package/packages/daemon/dist/tui/mirror/features/palette/feature.js +3 -0
  651. package/packages/daemon/dist/tui/mirror/features/palette/session.d.ts +2 -0
  652. package/packages/daemon/dist/tui/mirror/features/palette/session.js +393 -0
  653. package/packages/daemon/dist/tui/mirror/features/palette/surface.d.ts +7 -0
  654. package/packages/daemon/dist/tui/mirror/features/palette/surface.jsx +48 -0
  655. package/packages/daemon/dist/tui/mirror/features/performance-hud/contract.d.ts +17 -0
  656. package/packages/daemon/dist/tui/mirror/features/performance-hud/contract.js +1 -0
  657. package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.d.ts +3 -0
  658. package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.jsx +2 -0
  659. package/packages/daemon/dist/tui/mirror/features/performance-hud/session.d.ts +8 -0
  660. package/packages/daemon/dist/tui/mirror/features/performance-hud/session.js +148 -0
  661. package/packages/daemon/dist/tui/mirror/features/performance-hud/surface.d.ts +17 -0
  662. package/packages/daemon/dist/tui/mirror/features/performance-hud/surface.jsx +64 -0
  663. package/packages/daemon/dist/tui/mirror/features/rich-preview/asset-loader.d.ts +9 -0
  664. package/packages/daemon/dist/tui/mirror/features/rich-preview/asset-loader.js +125 -0
  665. package/packages/daemon/dist/tui/mirror/features/rich-preview/contract.d.ts +71 -0
  666. package/packages/daemon/dist/tui/mirror/features/rich-preview/contract.js +1 -0
  667. package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.d.ts +23 -0
  668. package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.jsx +103 -0
  669. package/packages/daemon/dist/tui/mirror/features/rich-preview/session.d.ts +23 -0
  670. package/packages/daemon/dist/tui/mirror/features/rich-preview/session.js +310 -0
  671. package/packages/daemon/dist/tui/mirror/features/settings/catalog.d.ts +7 -0
  672. package/packages/daemon/dist/tui/mirror/features/settings/catalog.js +10 -0
  673. package/packages/daemon/dist/tui/mirror/features/settings/contract.d.ts +35 -0
  674. package/packages/daemon/dist/tui/mirror/features/settings/contract.js +1 -0
  675. package/packages/daemon/dist/tui/mirror/features/settings/feature.d.ts +3 -0
  676. package/packages/daemon/dist/tui/mirror/features/settings/feature.js +2 -0
  677. package/packages/daemon/dist/tui/mirror/features/settings/session.d.ts +3 -0
  678. package/packages/daemon/dist/tui/mirror/features/settings/session.js +309 -0
  679. package/packages/daemon/dist/tui/mirror/file-tree.d.ts +142 -0
  680. package/packages/daemon/dist/tui/mirror/file-tree.js +283 -0
  681. package/packages/daemon/dist/tui/mirror/files-surface-view.d.ts +17 -0
  682. package/packages/daemon/dist/tui/mirror/files-surface-view.jsx +92 -0
  683. package/packages/daemon/dist/tui/mirror/files-surface.d.ts +123 -0
  684. package/packages/daemon/dist/tui/mirror/files-surface.js +237 -0
  685. package/packages/daemon/dist/tui/mirror/focus-projection.d.ts +20 -0
  686. package/packages/daemon/dist/tui/mirror/focus-projection.js +80 -0
  687. package/packages/daemon/dist/tui/mirror/folder-picker.d.ts +38 -0
  688. package/packages/daemon/dist/tui/mirror/folder-picker.js +114 -0
  689. package/packages/daemon/dist/tui/mirror/frame-coalescer.d.ts +29 -0
  690. package/packages/daemon/dist/tui/mirror/frame-coalescer.js +74 -0
  691. package/packages/daemon/dist/tui/mirror/home-model.d.ts +81 -0
  692. package/packages/daemon/dist/tui/mirror/home-model.js +125 -0
  693. package/packages/daemon/dist/tui/mirror/home-surface-model.d.ts +113 -0
  694. package/packages/daemon/dist/tui/mirror/home-surface-model.js +297 -0
  695. package/packages/daemon/dist/tui/mirror/home-surface.d.ts +11 -0
  696. package/packages/daemon/dist/tui/mirror/home-surface.jsx +110 -0
  697. package/packages/daemon/dist/tui/mirror/host-terminal.d.ts +28 -0
  698. package/packages/daemon/dist/tui/mirror/host-terminal.js +33 -0
  699. package/packages/daemon/dist/tui/mirror/hosted.d.ts +179 -0
  700. package/packages/daemon/dist/tui/mirror/hosted.js +239 -0
  701. package/packages/daemon/dist/tui/mirror/input-lifecycle.d.ts +140 -0
  702. package/packages/daemon/dist/tui/mirror/input-lifecycle.js +147 -0
  703. package/packages/daemon/dist/tui/mirror/interaction-flow.d.ts +30 -0
  704. package/packages/daemon/dist/tui/mirror/interaction-flow.js +41 -0
  705. package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.d.ts +19 -0
  706. package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.js +84 -0
  707. package/packages/daemon/dist/tui/mirror/menu-model.d.ts +89 -0
  708. package/packages/daemon/dist/tui/mirror/menu-model.js +143 -0
  709. package/packages/daemon/dist/tui/mirror/missions-dashboard.d.ts +68 -0
  710. package/packages/daemon/dist/tui/mirror/missions-dashboard.js +261 -0
  711. package/packages/daemon/dist/tui/mirror/missions-render-fixtures.d.ts +13 -0
  712. package/packages/daemon/dist/tui/mirror/missions-render-fixtures.js +330 -0
  713. package/packages/daemon/dist/tui/mirror/missions-surface-controller.d.ts +84 -0
  714. package/packages/daemon/dist/tui/mirror/missions-surface-controller.js +314 -0
  715. package/packages/daemon/dist/tui/mirror/missions-surface.d.ts +17 -0
  716. package/packages/daemon/dist/tui/mirror/missions-surface.jsx +239 -0
  717. package/packages/daemon/dist/tui/mirror/missions-workspace.d.ts +341 -0
  718. package/packages/daemon/dist/tui/mirror/missions-workspace.js +1399 -0
  719. package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.d.ts +71 -0
  720. package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.js +233 -0
  721. package/packages/daemon/dist/tui/mirror/open-tui-pane-stream-socket.d.ts +16 -0
  722. package/packages/daemon/dist/tui/mirror/open-tui-pane-stream-socket.js +32 -0
  723. package/packages/daemon/dist/tui/mirror/open-tui-verified-routing.d.ts +19 -0
  724. package/packages/daemon/dist/tui/mirror/open-tui-verified-routing.js +45 -0
  725. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.d.ts +36 -0
  726. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +1069 -0
  727. package/packages/daemon/dist/tui/mirror/palette-surface-adapter.d.ts +58 -0
  728. package/packages/daemon/dist/tui/mirror/palette-surface-adapter.js +384 -0
  729. package/packages/daemon/dist/tui/mirror/palette.d.ts +315 -0
  730. package/packages/daemon/dist/tui/mirror/palette.js +522 -0
  731. package/packages/daemon/dist/tui/mirror/pane-frame-state.d.ts +68 -0
  732. package/packages/daemon/dist/tui/mirror/pane-frame-state.js +124 -0
  733. package/packages/daemon/dist/tui/mirror/pane-mirror.d.ts +205 -0
  734. package/packages/daemon/dist/tui/mirror/pane-mirror.js +584 -0
  735. package/packages/daemon/dist/tui/mirror/pane-surface.d.ts +257 -0
  736. package/packages/daemon/dist/tui/mirror/pane-surface.jsx +855 -0
  737. package/packages/daemon/dist/tui/mirror/panel-host-reactive.d.ts +7 -0
  738. package/packages/daemon/dist/tui/mirror/panel-host-reactive.js +13 -0
  739. package/packages/daemon/dist/tui/mirror/panel-host.d.ts +69 -0
  740. package/packages/daemon/dist/tui/mirror/panel-host.js +242 -0
  741. package/packages/daemon/dist/tui/mirror/perf-tap.d.ts +13 -0
  742. package/packages/daemon/dist/tui/mirror/perf-tap.js +32 -0
  743. package/packages/daemon/dist/tui/mirror/performance-events.d.ts +404 -0
  744. package/packages/daemon/dist/tui/mirror/performance-events.js +46 -0
  745. package/packages/daemon/dist/tui/mirror/recipe-components.d.ts +93 -0
  746. package/packages/daemon/dist/tui/mirror/recipe-components.jsx +135 -0
  747. package/packages/daemon/dist/tui/mirror/recipes.d.ts +90 -0
  748. package/packages/daemon/dist/tui/mirror/recipes.js +395 -0
  749. package/packages/daemon/dist/tui/mirror/reference-performance-trace.d.ts +80 -0
  750. package/packages/daemon/dist/tui/mirror/reference-performance-trace.js +597 -0
  751. package/packages/daemon/dist/tui/mirror/renderer-commands.d.ts +60 -0
  752. package/packages/daemon/dist/tui/mirror/renderer-commands.js +250 -0
  753. package/packages/daemon/dist/tui/mirror/resize-model.d.ts +76 -0
  754. package/packages/daemon/dist/tui/mirror/resize-model.js +105 -0
  755. package/packages/daemon/dist/tui/mirror/resize-transaction.d.ts +102 -0
  756. package/packages/daemon/dist/tui/mirror/resize-transaction.js +221 -0
  757. package/packages/daemon/dist/tui/mirror/rich-placement-projection.d.ts +64 -0
  758. package/packages/daemon/dist/tui/mirror/rich-placement-projection.js +80 -0
  759. package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.d.ts +22 -0
  760. package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.js +79 -0
  761. package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.d.ts +61 -0
  762. package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.js +51 -0
  763. package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.d.ts +26 -0
  764. package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.js +80 -0
  765. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.d.ts +21 -0
  766. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.js +88 -0
  767. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.d.ts +60 -0
  768. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.js +320 -0
  769. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-binding.d.ts +28 -0
  770. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-binding.js +111 -0
  771. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-capability.d.ts +16 -0
  772. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-capability.js +25 -0
  773. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-presentation.d.ts +38 -0
  774. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-presentation.js +129 -0
  775. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-test-control.d.ts +43 -0
  776. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-test-control.js +242 -0
  777. package/packages/daemon/dist/tui/mirror/runtime/application-input-readiness.d.ts +5 -0
  778. package/packages/daemon/dist/tui/mirror/runtime/application-input-readiness.js +20 -0
  779. package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.d.ts +72 -0
  780. package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.js +297 -0
  781. package/packages/daemon/dist/tui/mirror/runtime/application-optional-features.d.ts +14 -0
  782. package/packages/daemon/dist/tui/mirror/runtime/application-optional-features.js +12 -0
  783. package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.d.ts +23 -0
  784. package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +61 -0
  785. package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.d.ts +31 -0
  786. package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.js +60 -0
  787. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.d.ts +22 -0
  788. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.js +30 -0
  789. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.d.ts +14 -0
  790. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.js +38 -0
  791. package/packages/daemon/dist/tui/mirror/runtime/application-pending-terminal-input.d.ts +53 -0
  792. package/packages/daemon/dist/tui/mirror/runtime/application-pending-terminal-input.js +74 -0
  793. package/packages/daemon/dist/tui/mirror/runtime/application-performance-log.d.ts +20 -0
  794. package/packages/daemon/dist/tui/mirror/runtime/application-performance-log.js +81 -0
  795. package/packages/daemon/dist/tui/mirror/runtime/application-post-render-runtime.d.ts +37 -0
  796. package/packages/daemon/dist/tui/mirror/runtime/application-post-render-runtime.js +117 -0
  797. package/packages/daemon/dist/tui/mirror/runtime/application-root-configuration.d.ts +21 -0
  798. package/packages/daemon/dist/tui/mirror/runtime/application-root-configuration.js +21 -0
  799. package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.d.ts +9 -0
  800. package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.js +27 -0
  801. package/packages/daemon/dist/tui/mirror/runtime/application-session-focus-owner.d.ts +14 -0
  802. package/packages/daemon/dist/tui/mirror/runtime/application-session-focus-owner.js +65 -0
  803. package/packages/daemon/dist/tui/mirror/runtime/application-shell-binding.d.ts +34 -0
  804. package/packages/daemon/dist/tui/mirror/runtime/application-shell-binding.js +307 -0
  805. package/packages/daemon/dist/tui/mirror/runtime/application-shell-viewport.d.ts +8 -0
  806. package/packages/daemon/dist/tui/mirror/runtime/application-shell-viewport.js +14 -0
  807. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-frame-readiness-owner.d.ts +6 -0
  808. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-frame-readiness-owner.js +20 -0
  809. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-host-focus-owner.d.ts +3 -0
  810. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-host-focus-owner.js +25 -0
  811. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-input-ingress.d.ts +15 -0
  812. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-input-ingress.js +96 -0
  813. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.d.ts +65 -0
  814. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +1326 -0
  815. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-palette-owner.d.ts +65 -0
  816. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-palette-owner.js +217 -0
  817. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-paste.d.ts +4 -0
  818. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-paste.js +22 -0
  819. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-renderer-sources.d.ts +15 -0
  820. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-renderer-sources.js +31 -0
  821. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-selection-owner.d.ts +47 -0
  822. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-selection-owner.js +161 -0
  823. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.d.ts +44 -0
  824. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.js +177 -0
  825. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.d.ts +103 -0
  826. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.jsx +720 -0
  827. package/packages/daemon/dist/tui/mirror/runtime/application-theme-repaint.d.ts +24 -0
  828. package/packages/daemon/dist/tui/mirror/runtime/application-theme-repaint.js +34 -0
  829. package/packages/daemon/dist/tui/mirror/runtime/application-transient-note-owner.d.ts +15 -0
  830. package/packages/daemon/dist/tui/mirror/runtime/application-transient-note-owner.js +29 -0
  831. package/packages/daemon/dist/tui/mirror/runtime/bounded-performance-record-writer.d.ts +17 -0
  832. package/packages/daemon/dist/tui/mirror/runtime/bounded-performance-record-writer.js +67 -0
  833. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-client-ledger.d.ts +64 -0
  834. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-client-ledger.js +271 -0
  835. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-input-fixture.d.ts +12 -0
  836. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-input-fixture.js +43 -0
  837. package/packages/daemon/dist/tui/mirror/runtime/changes-deferred-identity.d.ts +15 -0
  838. package/packages/daemon/dist/tui/mirror/runtime/changes-deferred-identity.js +17 -0
  839. package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.d.ts +29 -0
  840. package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.js +128 -0
  841. package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.d.ts +12 -0
  842. package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.js +40 -0
  843. package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.d.ts +23 -0
  844. package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.js +39 -0
  845. package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.d.ts +3 -0
  846. package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.js +9 -0
  847. package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.d.ts +4 -0
  848. package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.js +27 -0
  849. package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.d.ts +16 -0
  850. package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.js +53 -0
  851. package/packages/daemon/dist/tui/mirror/runtime/generation-bound-slot.d.ts +7 -0
  852. package/packages/daemon/dist/tui/mirror/runtime/generation-bound-slot.js +23 -0
  853. package/packages/daemon/dist/tui/mirror/runtime/host-local-tmux-adapter.d.ts +17 -0
  854. package/packages/daemon/dist/tui/mirror/runtime/host-local-tmux-adapter.js +90 -0
  855. package/packages/daemon/dist/tui/mirror/runtime/hosted-tty-size-bridge.d.ts +55 -0
  856. package/packages/daemon/dist/tui/mirror/runtime/hosted-tty-size-bridge.js +166 -0
  857. package/packages/daemon/dist/tui/mirror/runtime/latest-intent-fence.d.ts +11 -0
  858. package/packages/daemon/dist/tui/mirror/runtime/latest-intent-fence.js +14 -0
  859. package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.d.ts +30 -0
  860. package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.js +58 -0
  861. package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.d.ts +44 -0
  862. package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.js +118 -0
  863. package/packages/daemon/dist/tui/mirror/runtime/modal-pointer-capture.d.ts +13 -0
  864. package/packages/daemon/dist/tui/mirror/runtime/modal-pointer-capture.js +12 -0
  865. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.d.ts +68 -0
  866. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +834 -0
  867. package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.d.ts +19 -0
  868. package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.js +146 -0
  869. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.d.ts +45 -0
  870. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.js +178 -0
  871. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.typecheck.d.ts +11 -0
  872. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.typecheck.js +1 -0
  873. package/packages/daemon/dist/tui/mirror/runtime/palette-production-controller.d.ts +55 -0
  874. package/packages/daemon/dist/tui/mirror/runtime/palette-production-controller.js +126 -0
  875. package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.d.ts +11 -0
  876. package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.js +13 -0
  877. package/packages/daemon/dist/tui/mirror/runtime/pane-scoped-terminal-surface.d.ts +42 -0
  878. package/packages/daemon/dist/tui/mirror/runtime/pane-scoped-terminal-surface.jsx +67 -0
  879. package/packages/daemon/dist/tui/mirror/runtime/product-surface-policy.d.ts +11 -0
  880. package/packages/daemon/dist/tui/mirror/runtime/product-surface-policy.js +12 -0
  881. package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.d.ts +4 -0
  882. package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.js +4 -0
  883. package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.d.ts +35 -0
  884. package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.js +91 -0
  885. package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.d.ts +14 -0
  886. package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.js +14 -0
  887. package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.d.ts +20 -0
  888. package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.js +111 -0
  889. package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.d.ts +25 -0
  890. package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.js +90 -0
  891. package/packages/daemon/dist/tui/mirror/runtime/semantic-pane-publication.d.ts +10 -0
  892. package/packages/daemon/dist/tui/mirror/runtime/semantic-pane-publication.js +14 -0
  893. package/packages/daemon/dist/tui/mirror/runtime/semantic-shell-viewport-resize.d.ts +15 -0
  894. package/packages/daemon/dist/tui/mirror/runtime/semantic-shell-viewport-resize.js +56 -0
  895. package/packages/daemon/dist/tui/mirror/runtime/terminal-dimensions-owner.d.ts +9 -0
  896. package/packages/daemon/dist/tui/mirror/runtime/terminal-dimensions-owner.js +9 -0
  897. package/packages/daemon/dist/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.d.ts +52 -0
  898. package/packages/daemon/dist/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.js +610 -0
  899. package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.d.ts +16 -0
  900. package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.js +84 -0
  901. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-focus.d.ts +41 -0
  902. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-focus.js +347 -0
  903. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-frame-diagnostics.d.ts +3 -0
  904. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-frame-diagnostics.js +37 -0
  905. package/packages/daemon/dist/tui/mirror/runtime/terminal-input-adapter.d.ts +10 -0
  906. package/packages/daemon/dist/tui/mirror/runtime/terminal-input-adapter.js +50 -0
  907. package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.d.ts +22 -0
  908. package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.js +28 -0
  909. package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.d.ts +23 -0
  910. package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.js +82 -0
  911. package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.d.ts +66 -0
  912. package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.js +141 -0
  913. package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.d.ts +50 -0
  914. package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.js +89 -0
  915. package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.d.ts +31 -0
  916. package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.js +64 -0
  917. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.d.ts +92 -0
  918. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.js +636 -0
  919. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.d.ts +59 -0
  920. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.js +169 -0
  921. package/packages/daemon/dist/tui/mirror/runtime/viewport-fit-coordinator.d.ts +8 -0
  922. package/packages/daemon/dist/tui/mirror/runtime/viewport-fit-coordinator.js +7 -0
  923. package/packages/daemon/dist/tui/mirror/runtime/workspace-terminal-fast-lane.d.ts +22 -0
  924. package/packages/daemon/dist/tui/mirror/runtime/workspace-terminal-fast-lane.js +498 -0
  925. package/packages/daemon/dist/tui/mirror/scrollbar-model.d.ts +35 -0
  926. package/packages/daemon/dist/tui/mirror/scrollbar-model.js +64 -0
  927. package/packages/daemon/dist/tui/mirror/search-model.d.ts +41 -0
  928. package/packages/daemon/dist/tui/mirror/search-model.js +62 -0
  929. package/packages/daemon/dist/tui/mirror/selection.d.ts +175 -0
  930. package/packages/daemon/dist/tui/mirror/selection.js +264 -0
  931. package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.d.ts +147 -0
  932. package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.js +562 -0
  933. package/packages/daemon/dist/tui/mirror/semantic-session-view.d.ts +86 -0
  934. package/packages/daemon/dist/tui/mirror/semantic-session-view.js +269 -0
  935. package/packages/daemon/dist/tui/mirror/settings-model.d.ts +108 -0
  936. package/packages/daemon/dist/tui/mirror/settings-model.js +304 -0
  937. package/packages/daemon/dist/tui/mirror/shell-chrome.d.ts +151 -0
  938. package/packages/daemon/dist/tui/mirror/shell-chrome.js +313 -0
  939. package/packages/daemon/dist/tui/mirror/size-truth.d.ts +92 -0
  940. package/packages/daemon/dist/tui/mirror/size-truth.js +104 -0
  941. package/packages/daemon/dist/tui/mirror/spans.d.ts +26 -0
  942. package/packages/daemon/dist/tui/mirror/spans.js +31 -0
  943. package/packages/daemon/dist/tui/mirror/status-grammar.d.ts +18 -0
  944. package/packages/daemon/dist/tui/mirror/status-grammar.js +29 -0
  945. package/packages/daemon/dist/tui/mirror/terminal-surface.d.ts +55 -0
  946. package/packages/daemon/dist/tui/mirror/terminal-surface.js +92 -0
  947. package/packages/daemon/dist/tui/mirror/terminal-text.d.ts +9 -0
  948. package/packages/daemon/dist/tui/mirror/terminal-text.js +38 -0
  949. package/packages/daemon/dist/tui/mirror/theme.d.ts +207 -0
  950. package/packages/daemon/dist/tui/mirror/theme.js +744 -0
  951. package/packages/daemon/dist/tui/mirror/ui/agent-badge.d.ts +11 -0
  952. package/packages/daemon/dist/tui/mirror/ui/agent-badge.jsx +14 -0
  953. package/packages/daemon/dist/tui/mirror/ui/badge.d.ts +13 -0
  954. package/packages/daemon/dist/tui/mirror/ui/badge.jsx +15 -0
  955. package/packages/daemon/dist/tui/mirror/ui/button.d.ts +26 -0
  956. package/packages/daemon/dist/tui/mirror/ui/button.jsx +66 -0
  957. package/packages/daemon/dist/tui/mirror/ui/dialog.d.ts +19 -0
  958. package/packages/daemon/dist/tui/mirror/ui/dialog.jsx +8 -0
  959. package/packages/daemon/dist/tui/mirror/ui/index.d.ts +16 -0
  960. package/packages/daemon/dist/tui/mirror/ui/index.js +16 -0
  961. package/packages/daemon/dist/tui/mirror/ui/key-hint.d.ts +13 -0
  962. package/packages/daemon/dist/tui/mirror/ui/key-hint.jsx +39 -0
  963. package/packages/daemon/dist/tui/mirror/ui/keyboard-router.d.ts +25 -0
  964. package/packages/daemon/dist/tui/mirror/ui/keyboard-router.jsx +46 -0
  965. package/packages/daemon/dist/tui/mirror/ui/menu.d.ts +24 -0
  966. package/packages/daemon/dist/tui/mirror/ui/menu.jsx +15 -0
  967. package/packages/daemon/dist/tui/mirror/ui/navigation-row.d.ts +21 -0
  968. package/packages/daemon/dist/tui/mirror/ui/navigation-row.jsx +62 -0
  969. package/packages/daemon/dist/tui/mirror/ui/overlay-frame.d.ts +25 -0
  970. package/packages/daemon/dist/tui/mirror/ui/overlay-frame.jsx +52 -0
  971. package/packages/daemon/dist/tui/mirror/ui/overlay-host.d.ts +24 -0
  972. package/packages/daemon/dist/tui/mirror/ui/overlay-host.jsx +33 -0
  973. package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.d.ts +13 -0
  974. package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.jsx +23 -0
  975. package/packages/daemon/dist/tui/mirror/ui/overlay-model.d.ts +29 -0
  976. package/packages/daemon/dist/tui/mirror/ui/overlay-model.js +45 -0
  977. package/packages/daemon/dist/tui/mirror/ui/state.d.ts +27 -0
  978. package/packages/daemon/dist/tui/mirror/ui/state.js +171 -0
  979. package/packages/daemon/dist/tui/mirror/ui/status-bar.d.ts +43 -0
  980. package/packages/daemon/dist/tui/mirror/ui/status-bar.jsx +102 -0
  981. package/packages/daemon/dist/tui/mirror/ui/surface.d.ts +14 -0
  982. package/packages/daemon/dist/tui/mirror/ui/surface.jsx +45 -0
  983. package/packages/daemon/dist/tui/mirror/ui/tabs.d.ts +26 -0
  984. package/packages/daemon/dist/tui/mirror/ui/tabs.jsx +88 -0
  985. package/packages/daemon/dist/tui/mirror/widget-fallback.d.ts +15 -0
  986. package/packages/daemon/dist/tui/mirror/widget-fallback.js +52 -0
  987. package/packages/daemon/dist/tui/mirror/widget-surface-model.d.ts +26 -0
  988. package/packages/daemon/dist/tui/mirror/widget-surface-model.js +145 -0
  989. package/packages/daemon/dist/tui/mirror/widget-surface.d.ts +13 -0
  990. package/packages/daemon/dist/tui/mirror/widget-surface.jsx +31 -0
  991. package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.d.ts +53 -0
  992. package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.js +77 -0
  993. package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.d.ts +266 -0
  994. package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.js +99 -0
  995. package/packages/daemon/dist/tui/mirror/workspace/application-shell-controller.d.ts +83 -0
  996. package/packages/daemon/dist/tui/mirror/workspace/application-shell-controller.js +292 -0
  997. package/packages/daemon/dist/tui/mirror/workspace/application-shell-surface-commands.d.ts +5 -0
  998. package/packages/daemon/dist/tui/mirror/workspace/application-shell-surface-commands.js +28 -0
  999. package/packages/daemon/dist/tui/mirror/workspace/application-shell.d.ts +49 -0
  1000. package/packages/daemon/dist/tui/mirror/workspace/application-shell.js +97 -0
  1001. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface-view.d.ts +11 -0
  1002. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface-view.jsx +158 -0
  1003. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface.d.ts +128 -0
  1004. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface.js +342 -0
  1005. package/packages/daemon/dist/tui/mirror/workspace/icons.d.ts +154 -0
  1006. package/packages/daemon/dist/tui/mirror/workspace/icons.js +43 -0
  1007. package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.d.ts +24 -0
  1008. package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.jsx +20 -0
  1009. package/packages/daemon/dist/tui/mirror/workspace/pane-frame.d.ts +143 -0
  1010. package/packages/daemon/dist/tui/mirror/workspace/pane-frame.js +452 -0
  1011. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.d.ts +152 -0
  1012. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.js +555 -0
  1013. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.d.ts +58 -0
  1014. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.jsx +93 -0
  1015. package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.d.ts +75 -0
  1016. package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.jsx +253 -0
  1017. package/packages/daemon/dist/tui/mirror/workspace/text.d.ts +2 -0
  1018. package/packages/daemon/dist/tui/mirror/workspace/text.js +27 -0
  1019. package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.d.ts +23 -0
  1020. package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.js +34 -0
  1021. package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.d.ts +123 -0
  1022. package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.js +286 -0
  1023. package/packages/daemon/dist/tui/mirror/workspace-ui-state.d.ts +174 -0
  1024. package/packages/daemon/dist/tui/mirror/workspace-ui-state.js +885 -0
  1025. package/packages/daemon/dist/tui/readiness.d.ts +22 -0
  1026. package/packages/daemon/dist/tui/readiness.js +34 -0
  1027. package/packages/daemon/dist/tui/team/entry.d.ts +37 -0
  1028. package/packages/daemon/dist/tui/team/entry.js +20 -0
  1029. package/packages/daemon/dist/tui/team/fuzzy.d.ts +38 -0
  1030. package/packages/daemon/dist/tui/team/fuzzy.js +141 -0
  1031. package/packages/daemon/dist/tui/team/home.d.ts +94 -0
  1032. package/packages/daemon/dist/tui/team/home.js +115 -0
  1033. package/packages/daemon/dist/tui/team/input.d.ts +22 -0
  1034. package/packages/daemon/dist/tui/team/input.js +21 -0
  1035. package/packages/daemon/dist/tui/team/keymap.d.ts +33 -0
  1036. package/packages/daemon/dist/tui/team/keymap.js +99 -0
  1037. package/packages/daemon/dist/tui/team/mouse.d.ts +18 -0
  1038. package/packages/daemon/dist/tui/team/mouse.js +17 -0
  1039. package/packages/daemon/dist/tui/team/nav.d.ts +21 -0
  1040. package/packages/daemon/dist/tui/team/nav.js +33 -0
  1041. package/packages/daemon/dist/tui/team/preview.d.ts +19 -0
  1042. package/packages/daemon/dist/tui/team/preview.js +35 -0
  1043. package/packages/daemon/dist/tui/team/projects.d.ts +52 -0
  1044. package/packages/daemon/dist/tui/team/projects.js +159 -0
  1045. package/packages/daemon/dist/tui/team/report.d.ts +51 -0
  1046. package/packages/daemon/dist/tui/team/report.js +37 -0
  1047. package/packages/daemon/dist/tui/team/sessions.d.ts +235 -0
  1048. package/packages/daemon/dist/tui/team/sessions.js +292 -0
  1049. package/packages/daemon/dist/tui/team/tree.d.ts +41 -0
  1050. package/packages/daemon/dist/tui/team/tree.js +42 -0
  1051. package/packages/daemon/dist/tui/team/wait-receipts.d.ts +60 -0
  1052. package/packages/daemon/dist/tui/team/wait-receipts.js +153 -0
  1053. package/packages/daemon/dist/tui/team/wait.d.ts +62 -0
  1054. package/packages/daemon/dist/tui/team/wait.js +90 -0
  1055. package/packages/daemon/dist/validate.js +16 -10
  1056. package/packages/daemon/dist/widgets/lib/watcher.d.ts +5 -9
  1057. package/packages/daemon/dist/widgets/lib/watcher.js +5 -92
  1058. package/packages/daemon/dist/widgets/resolve.js +10 -7
  1059. package/packages/daemon/dist/widgets/setup/setup-model.js +7 -9
  1060. package/packages/daemon/src/attach.ts +2 -2
  1061. package/packages/daemon/src/canonical.ts +19 -2
  1062. package/packages/daemon/src/cli.ts +38 -36
  1063. package/packages/daemon/src/command-center/actions/command-definitions.ts +91 -0
  1064. package/packages/daemon/src/command-center/actions/dispatcher.ts +291 -10
  1065. package/packages/daemon/src/command-center/actions/errors.ts +40 -0
  1066. package/packages/daemon/src/command-center/actions/handlers/_project-context.ts +4 -5
  1067. package/packages/daemon/src/command-center/actions/handlers/app-window-mutate.ts +54 -0
  1068. package/packages/daemon/src/command-center/actions/handlers/config-actions.ts +59 -29
  1069. package/packages/daemon/src/command-center/actions/handlers/daemon-shutdown.ts +12 -0
  1070. package/packages/daemon/src/command-center/actions/handlers/fleet-lifecycle.ts +104 -0
  1071. package/packages/daemon/src/command-center/actions/handlers/project-launch.ts +20 -4
  1072. package/packages/daemon/src/command-center/actions/handlers/workspace-multiplexer.ts +96 -0
  1073. package/packages/daemon/src/command-center/actions/handlers/workspace-open.ts +141 -0
  1074. package/packages/daemon/src/command-center/actions/handlers/workspace-pane-create.ts +48 -0
  1075. package/packages/daemon/src/command-center/actions/handlers/workspace-promote.ts +48 -0
  1076. package/packages/daemon/src/command-center/actions/registry.ts +200 -1
  1077. package/packages/daemon/src/command-center/actions/semantic-multiplexer-actions.ts +26 -0
  1078. package/packages/daemon/src/command-center/agent-status-watch.ts +222 -0
  1079. package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +465 -0
  1080. package/packages/daemon/src/command-center/discovery.ts +310 -5
  1081. package/packages/daemon/src/command-center/owner-authority.ts +118 -0
  1082. package/packages/daemon/src/command-center/pane-stream-issue.ts +247 -0
  1083. package/packages/daemon/src/command-center/resources/agent-graph-overlay.ts +270 -0
  1084. package/packages/daemon/src/command-center/resources/application-shell.ts +909 -0
  1085. package/packages/daemon/src/command-center/resources/desktop-missions.ts +171 -0
  1086. package/packages/daemon/src/command-center/resources/fleet-catalog.ts +200 -0
  1087. package/packages/daemon/src/command-center/resources/fleet-resource-route.ts +61 -0
  1088. package/packages/daemon/src/command-center/resources/startup-readiness-route.ts +172 -0
  1089. package/packages/daemon/src/command-center/resources/startup-readiness.ts +250 -0
  1090. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +45 -0
  1091. package/packages/daemon/src/command-center/resources/workspace-changes-authority.ts +594 -0
  1092. package/packages/daemon/src/command-center/resources/workspace-changes-git.ts +278 -0
  1093. package/packages/daemon/src/command-center/resources/workspace-files-authority.ts +583 -0
  1094. package/packages/daemon/src/command-center/resources/workspace-missions-route.ts +125 -0
  1095. package/packages/daemon/src/command-center/resources/workspace-resource-ids.ts +81 -0
  1096. package/packages/daemon/src/command-center/resources/workspace-resource-routes.ts +147 -0
  1097. package/packages/daemon/src/command-center/server.ts +732 -59
  1098. package/packages/daemon/src/command-center/terminal-attachment-issue.ts +257 -0
  1099. package/packages/daemon/src/command-center/workspace-resource-observer.ts +560 -0
  1100. package/packages/daemon/src/command-center/ws-events.ts +853 -66
  1101. package/packages/daemon/src/config.ts +35 -25
  1102. package/packages/daemon/src/control/client.ts +128 -0
  1103. package/packages/daemon/src/control/dispatch.ts +107 -0
  1104. package/packages/daemon/src/control/fanout.ts +44 -0
  1105. package/packages/daemon/src/control/frames.ts +40 -0
  1106. package/packages/daemon/src/control/lifecycle.ts +163 -0
  1107. package/packages/daemon/src/control/server.ts +237 -0
  1108. package/packages/daemon/src/control/verbs.ts +118 -0
  1109. package/packages/daemon/src/detect.ts +25 -20
  1110. package/packages/daemon/src/doctor.ts +133 -33
  1111. package/packages/daemon/src/index.ts +244 -2
  1112. package/packages/daemon/src/init.ts +23 -22
  1113. package/packages/daemon/src/inspect.ts +41 -8
  1114. package/packages/daemon/src/launch.ts +56 -28
  1115. package/packages/daemon/src/lib/agent-discovery.ts +53 -13
  1116. package/packages/daemon/src/lib/agent-kind.ts +23 -0
  1117. package/packages/daemon/src/lib/app-config.ts +143 -9
  1118. package/packages/daemon/src/lib/app-window-kernel.ts +777 -0
  1119. package/packages/daemon/src/lib/app-window-mutation.ts +178 -0
  1120. package/packages/daemon/src/lib/app-window-repository.ts +650 -0
  1121. package/packages/daemon/src/lib/app-window-state.ts +599 -0
  1122. package/packages/daemon/src/lib/application-shell-app-windows.ts +357 -0
  1123. package/packages/daemon/src/lib/auth/middleware.ts +9 -3
  1124. package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +266 -0
  1125. package/packages/daemon/src/lib/canonical-daemon.ts +695 -73
  1126. package/packages/daemon/src/lib/chrome-front-door.ts +17 -0
  1127. package/packages/daemon/src/lib/cli-action-bridge.ts +127 -91
  1128. package/packages/daemon/src/lib/command-registry.ts +152 -0
  1129. package/packages/daemon/src/lib/config-context.ts +61 -0
  1130. package/packages/daemon/src/lib/daemon-embed.ts +1347 -387
  1131. package/packages/daemon/src/lib/daemon-session-monitor.ts +274 -0
  1132. package/packages/daemon/src/lib/daemon.ts +3 -46
  1133. package/packages/daemon/src/lib/directory-watcher.ts +166 -0
  1134. package/packages/daemon/src/lib/environment-identity.ts +82 -0
  1135. package/packages/daemon/src/lib/errors.ts +7 -1
  1136. package/packages/daemon/src/lib/fleet-agent-lifecycle.ts +74 -0
  1137. package/packages/daemon/src/lib/fleet-lifecycle-authority.ts +535 -0
  1138. package/packages/daemon/src/lib/headless-daemon.ts +406 -0
  1139. package/packages/daemon/src/lib/launch-plan.ts +123 -4
  1140. package/packages/daemon/src/lib/legacy-config-adapter.ts +28 -0
  1141. package/packages/daemon/src/lib/legacy-config-migration.ts +145 -0
  1142. package/packages/daemon/src/lib/legacy-theme-compat.ts +40 -0
  1143. package/packages/daemon/src/lib/manifest-pack.ts +255 -0
  1144. package/packages/daemon/src/lib/mission-projections.ts +775 -0
  1145. package/packages/daemon/src/lib/mission-repository.ts +1311 -0
  1146. package/packages/daemon/src/lib/onboarding-marker.ts +51 -0
  1147. package/packages/daemon/src/lib/pane-chrome.ts +14 -0
  1148. package/packages/daemon/src/lib/pane-source-credentials.ts +200 -0
  1149. package/packages/daemon/src/lib/pane-widget.ts +182 -0
  1150. package/packages/daemon/src/lib/project-inspect.ts +4 -0
  1151. package/packages/daemon/src/lib/project-onboard.ts +19 -24
  1152. package/packages/daemon/src/lib/project-probe.ts +38 -30
  1153. package/packages/daemon/src/lib/project-readiness-probe.ts +578 -0
  1154. package/packages/daemon/src/lib/project-readiness.ts +1034 -0
  1155. package/packages/daemon/src/lib/project-registry.ts +45 -9
  1156. package/packages/daemon/src/lib/project-resolver.ts +350 -0
  1157. package/packages/daemon/src/lib/project-runtime-errors.ts +41 -0
  1158. package/packages/daemon/src/lib/project-runtime-repository.ts +1194 -0
  1159. package/packages/daemon/src/lib/resolved-config.ts +425 -0
  1160. package/packages/daemon/src/lib/runtime-namespace.ts +186 -0
  1161. package/packages/daemon/src/lib/semantic-resource-id.ts +17 -0
  1162. package/packages/daemon/src/lib/session-monitor.ts +28 -20
  1163. package/packages/daemon/src/lib/session-options.ts +3 -10
  1164. package/packages/daemon/src/lib/state-home.ts +12 -0
  1165. package/packages/daemon/src/lib/theme-mode.ts +11 -0
  1166. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +632 -0
  1167. package/packages/daemon/src/lib/tmux-interaction-options.ts +171 -0
  1168. package/packages/daemon/src/lib/tmux-terminal-color.ts +44 -0
  1169. package/packages/daemon/src/lib/tui-binary.ts +354 -34
  1170. package/packages/daemon/src/lib/unix-socket-authority.ts +65 -0
  1171. package/packages/daemon/src/lib/update-check.ts +5 -0
  1172. package/packages/daemon/src/lib/widget-asset-policy.ts +3 -0
  1173. package/packages/daemon/src/lib/widget-asset-store.ts +218 -0
  1174. package/packages/daemon/src/lib/workspace-config-loader.ts +378 -0
  1175. package/packages/daemon/src/lib/workspace-multiplexer-verbs.ts +1362 -0
  1176. package/packages/daemon/src/lib/workspace-open-handoff.ts +340 -0
  1177. package/packages/daemon/src/lib/workspace-open.ts +983 -0
  1178. package/packages/daemon/src/lib/workspace-pane-creation.ts +1406 -0
  1179. package/packages/daemon/src/lib/workspace-promotion.ts +1031 -0
  1180. package/packages/daemon/src/lib/workspace-registry.ts +193 -25
  1181. package/packages/daemon/src/lib/workspace-state-repository.ts +1204 -0
  1182. package/packages/daemon/src/lib/workspace-state.ts +960 -0
  1183. package/packages/daemon/src/lib/yaml-io.ts +8 -17
  1184. package/packages/daemon/src/migrate.ts +134 -0
  1185. package/packages/daemon/src/restart.ts +2 -2
  1186. package/packages/daemon/src/restore.ts +67 -24
  1187. package/packages/daemon/src/schemas/inspect.ts +9 -1
  1188. package/packages/daemon/src/schemas/registry.ts +12 -22
  1189. package/packages/daemon/src/schemas/ws-events.ts +14 -131
  1190. package/packages/daemon/src/send.ts +191 -22
  1191. package/packages/daemon/src/server/pane-stream-upgrade.ts +141 -0
  1192. package/packages/daemon/src/server/terminal-attachment-upgrade.ts +153 -0
  1193. package/packages/daemon/src/status.ts +13 -8
  1194. package/packages/daemon/src/stop.ts +2 -2
  1195. package/packages/daemon/src/terminal/MonotonicPtyInput.ts +153 -0
  1196. package/packages/daemon/src/terminal/NodePtyAdapter.ts +53 -11
  1197. package/packages/daemon/src/terminal/PtyAdapter.ts +111 -3
  1198. package/packages/daemon/src/terminal/README.md +34 -16
  1199. package/packages/daemon/src/terminal/attachments/admission-util.ts +97 -0
  1200. package/packages/daemon/src/terminal/attachments/agent-status-probe.ts +474 -0
  1201. package/packages/daemon/src/terminal/attachments/direct-websocket.ts +1482 -0
  1202. package/packages/daemon/src/terminal/attachments/grouped-tmux.ts +293 -0
  1203. package/packages/daemon/src/terminal/attachments/lease-manager.ts +1042 -0
  1204. package/packages/daemon/src/terminal/attachments/native-runtime.ts +2206 -0
  1205. package/packages/daemon/src/terminal/attachments/pty-tmux-attachment-launcher.ts +750 -0
  1206. package/packages/daemon/src/terminal/attachments/semantic-pane-catalog.ts +365 -0
  1207. package/packages/daemon/src/terminal/attachments/tmux-view-executor.ts +1095 -0
  1208. package/packages/daemon/src/terminal/mirror/control-channel.ts +827 -0
  1209. package/packages/daemon/src/terminal/mirror/control-mode-ownership.ts +34 -0
  1210. package/packages/daemon/src/terminal/mirror/events.ts +128 -0
  1211. package/packages/daemon/src/terminal/mirror/flow-ledger.ts +65 -0
  1212. package/packages/daemon/src/terminal/mirror/mirror-service.ts +480 -0
  1213. package/packages/daemon/src/terminal/mirror/pane-feed.ts +193 -0
  1214. package/packages/daemon/src/terminal/mirror/session-channel.ts +2820 -0
  1215. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +29 -0
  1216. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +375 -0
  1217. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +2612 -0
  1218. package/packages/daemon/src/terminal/pane-stream/runtime.ts +78 -0
  1219. package/packages/daemon/src/terminal/pane-stream/wire-ledger.ts +155 -0
  1220. package/packages/daemon/src/terminal/protocol/README.md +14 -0
  1221. package/packages/daemon/src/terminal/protocol/chunk-bytes.ts +20 -0
  1222. package/packages/daemon/src/{tui/mirror → terminal/protocol}/control.ts +39 -6
  1223. package/packages/daemon/src/{tui/mirror → terminal/protocol}/input-coalescer.ts +18 -7
  1224. package/packages/daemon/src/terminal/protocol/layout-parse.ts +154 -0
  1225. package/packages/daemon/src/terminal/protocol/pane-display-name.ts +185 -0
  1226. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +382 -0
  1227. package/packages/daemon/src/terminal/protocol/workspace-tmux-adapter.ts +470 -0
  1228. package/packages/daemon/src/terminal/session-runtime/authority-arbiter.ts +312 -0
  1229. package/packages/daemon/src/terminal/session-runtime/causal-cell-ledger.ts +359 -0
  1230. package/packages/daemon/src/terminal/session-runtime/interaction-receipt-facts.ts +173 -0
  1231. package/packages/daemon/src/terminal/session-runtime/multiplexer-backend.ts +194 -0
  1232. package/packages/daemon/src/terminal/session-runtime/registry.ts +2047 -0
  1233. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +267 -0
  1234. package/packages/daemon/src/terminal/session-runtime/runtime-scheduler.ts +22 -0
  1235. package/packages/daemon/src/terminal/session-runtime/runtime-trace-correlator.ts +58 -0
  1236. package/packages/daemon/src/terminal/session-runtime/semantic-mutation-executor.ts +555 -0
  1237. package/packages/daemon/src/terminal/session-runtime/semantic-mutation-resource-changes.ts +48 -0
  1238. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +1806 -0
  1239. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-observation-identity.ts +18 -0
  1240. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +64 -0
  1241. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +690 -0
  1242. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +498 -0
  1243. package/packages/daemon/src/terminal/session-runtime/terminal-replica-shadow-projections.ts +36 -0
  1244. package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +682 -0
  1245. package/packages/daemon/src/terminal/session-runtime/xterm-headless-provenance.json +25 -0
  1246. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +379 -0
  1247. package/packages/daemon/src/tui/async-disposable-slot.ts +60 -0
  1248. package/packages/daemon/src/tui/chrome/events.ts +4 -4
  1249. package/packages/daemon/src/tui/chrome/front-door.ts +27 -0
  1250. package/packages/daemon/src/tui/chrome/notify-prefs.ts +58 -0
  1251. package/packages/daemon/src/tui/chrome/notify-state.ts +76 -0
  1252. package/packages/daemon/src/tui/chrome/notify.ts +582 -84
  1253. package/packages/daemon/src/tui/chrome/sidebar.ts +9 -4
  1254. package/packages/daemon/src/tui/chrome/statusline.ts +15 -6
  1255. package/packages/daemon/src/tui/chrome/updater.ts +367 -64
  1256. package/packages/daemon/src/tui/compiled.ts +102 -6
  1257. package/packages/daemon/src/tui/detect/agent-resolution.ts +85 -0
  1258. package/packages/daemon/src/tui/detect/classify.ts +34 -0
  1259. package/packages/daemon/src/tui/detect/manifest-loader.ts +54 -5
  1260. package/packages/daemon/src/tui/detect/manifest.ts +24 -3
  1261. package/packages/daemon/src/tui/detect/manifests.ts +240 -6
  1262. package/packages/daemon/src/tui/detect/process-tree.ts +30 -4
  1263. package/packages/daemon/src/tui/detect/session-id.ts +503 -0
  1264. package/packages/daemon/src/tui/detect/snapshot.ts +38 -3
  1265. package/packages/daemon/src/tui/integrations/claude.ts +1 -0
  1266. package/packages/daemon/src/tui/integrations/opencode.ts +121 -0
  1267. package/packages/daemon/src/tui/main.ts +53 -0
  1268. package/packages/daemon/src/tui/mirror/RECIPES.md +59 -0
  1269. package/packages/daemon/src/tui/mirror/SHELL_CHROME.md +39 -0
  1270. package/packages/daemon/src/tui/mirror/THEME.md +48 -0
  1271. package/packages/daemon/src/tui/mirror/__snapshots__/activity-surface-renderer.test.tsx.snap +42 -0
  1272. package/packages/daemon/src/tui/mirror/__snapshots__/changes-terminal-surface-renderer.test.tsx.snap +267 -0
  1273. package/packages/daemon/src/tui/mirror/__snapshots__/home-files-surface-renderer.test.tsx.snap +267 -0
  1274. package/packages/daemon/src/tui/mirror/__snapshots__/missions-surface-renderer.test.tsx.snap +134 -0
  1275. package/packages/daemon/src/tui/mirror/__snapshots__/recipes-gallery-renderer.test.tsx.snap +141 -0
  1276. package/packages/daemon/src/tui/mirror/__snapshots__/shell-chrome-renderer.test.tsx.snap +134 -0
  1277. package/packages/daemon/src/tui/mirror/activity-surface-view.tsx +169 -0
  1278. package/packages/daemon/src/tui/mirror/activity-surface.ts +430 -0
  1279. package/packages/daemon/src/tui/mirror/agent-chip.ts +40 -11
  1280. package/packages/daemon/src/tui/mirror/agent-lifecycle.ts +468 -0
  1281. package/packages/daemon/src/tui/mirror/agent-provisioning-executor.ts +151 -0
  1282. package/packages/daemon/src/tui/mirror/agent-rows.ts +61 -5
  1283. package/packages/daemon/src/tui/mirror/ansi-palette.ts +3 -0
  1284. package/packages/daemon/src/tui/mirror/app-state.ts +185 -9
  1285. package/packages/daemon/src/tui/mirror/app.tsx +2 -5264
  1286. package/packages/daemon/src/tui/mirror/application-keybindings.ts +54 -0
  1287. package/packages/daemon/src/tui/mirror/application-shell-daemon-connection.ts +344 -0
  1288. package/packages/daemon/src/tui/mirror/application-shell-daemon-session.ts +74 -0
  1289. package/packages/daemon/src/tui/mirror/attention.ts +110 -0
  1290. package/packages/daemon/src/tui/mirror/canonical-workspace-routing.ts +63 -0
  1291. package/packages/daemon/src/tui/mirror/changes-surface-view.tsx +263 -0
  1292. package/packages/daemon/src/tui/mirror/changes-surface.ts +338 -0
  1293. package/packages/daemon/src/tui/mirror/composite-layout.ts +710 -0
  1294. package/packages/daemon/src/tui/mirror/configless-session-bootstrap.ts +192 -0
  1295. package/packages/daemon/src/tui/mirror/dialog-model.ts +2 -2
  1296. package/packages/daemon/src/tui/mirror/dialog-stack-core.ts +264 -0
  1297. package/packages/daemon/src/tui/mirror/dialog-stack.ts +2 -354
  1298. package/packages/daemon/src/tui/mirror/diff-model.ts +279 -4
  1299. package/packages/daemon/src/tui/mirror/editor-buffer.ts +9 -70
  1300. package/packages/daemon/src/tui/mirror/editor-open-policy.ts +16 -0
  1301. package/packages/daemon/src/tui/mirror/features/changes/contract.ts +84 -0
  1302. package/packages/daemon/src/tui/mirror/features/changes/controller.ts +470 -0
  1303. package/packages/daemon/src/tui/mirror/features/changes/feature.tsx +19 -0
  1304. package/packages/daemon/src/tui/mirror/features/dialogs/contract.ts +64 -0
  1305. package/packages/daemon/src/tui/mirror/features/dialogs/feature.tsx +227 -0
  1306. package/packages/daemon/src/tui/mirror/features/dialogs/session.ts +186 -0
  1307. package/packages/daemon/src/tui/mirror/features/files/feature.tsx +54 -0
  1308. package/packages/daemon/src/tui/mirror/features/files/session.ts +694 -0
  1309. package/packages/daemon/src/tui/mirror/features/home/feature.tsx +172 -0
  1310. package/packages/daemon/src/tui/mirror/features/missions-activity/contract.ts +106 -0
  1311. package/packages/daemon/src/tui/mirror/features/missions-activity/feature.tsx +19 -0
  1312. package/packages/daemon/src/tui/mirror/features/missions-activity/session.ts +470 -0
  1313. package/packages/daemon/src/tui/mirror/features/palette/contract.ts +121 -0
  1314. package/packages/daemon/src/tui/mirror/features/palette/feature.ts +14 -0
  1315. package/packages/daemon/src/tui/mirror/features/palette/session.ts +427 -0
  1316. package/packages/daemon/src/tui/mirror/features/palette/surface.tsx +92 -0
  1317. package/packages/daemon/src/tui/mirror/features/performance-hud/contract.ts +20 -0
  1318. package/packages/daemon/src/tui/mirror/features/performance-hud/feature.tsx +8 -0
  1319. package/packages/daemon/src/tui/mirror/features/performance-hud/session.ts +152 -0
  1320. package/packages/daemon/src/tui/mirror/features/performance-hud/surface.tsx +137 -0
  1321. package/packages/daemon/src/tui/mirror/features/rich-preview/asset-loader.ts +153 -0
  1322. package/packages/daemon/src/tui/mirror/features/rich-preview/contract.ts +94 -0
  1323. package/packages/daemon/src/tui/mirror/features/rich-preview/feature.tsx +141 -0
  1324. package/packages/daemon/src/tui/mirror/features/rich-preview/session.ts +387 -0
  1325. package/packages/daemon/src/tui/mirror/features/settings/catalog.ts +26 -0
  1326. package/packages/daemon/src/tui/mirror/features/settings/contract.ts +41 -0
  1327. package/packages/daemon/src/tui/mirror/features/settings/feature.ts +3 -0
  1328. package/packages/daemon/src/tui/mirror/features/settings/session.ts +375 -0
  1329. package/packages/daemon/src/tui/mirror/file-tree.ts +231 -6
  1330. package/packages/daemon/src/tui/mirror/files-surface-view.tsx +242 -0
  1331. package/packages/daemon/src/tui/mirror/files-surface.ts +371 -0
  1332. package/packages/daemon/src/tui/mirror/focus-projection.ts +113 -0
  1333. package/packages/daemon/src/tui/mirror/frame-coalescer.ts +87 -0
  1334. package/packages/daemon/src/tui/mirror/home-model.ts +1 -1
  1335. package/packages/daemon/src/tui/mirror/home-surface-model.ts +440 -0
  1336. package/packages/daemon/src/tui/mirror/home-surface.tsx +254 -0
  1337. package/packages/daemon/src/tui/mirror/host-terminal.ts +49 -0
  1338. package/packages/daemon/src/tui/mirror/hosted.ts +286 -0
  1339. package/packages/daemon/src/tui/mirror/input-lifecycle.ts +248 -0
  1340. package/packages/daemon/src/tui/mirror/interaction-flow.ts +83 -0
  1341. package/packages/daemon/src/tui/mirror/legacy/missions-workspace-loader.ts +117 -0
  1342. package/packages/daemon/src/tui/mirror/menu-model.ts +28 -18
  1343. package/packages/daemon/src/tui/mirror/missions-dashboard.ts +451 -0
  1344. package/packages/daemon/src/tui/mirror/missions-render-fixtures.ts +371 -0
  1345. package/packages/daemon/src/tui/mirror/missions-surface-controller.ts +530 -0
  1346. package/packages/daemon/src/tui/mirror/missions-surface.tsx +434 -0
  1347. package/packages/daemon/src/tui/mirror/missions-workspace.ts +1996 -0
  1348. package/packages/daemon/src/tui/mirror/multiplexer-action-executor.ts +379 -0
  1349. package/packages/daemon/src/tui/mirror/open-tui-pane-stream-socket.ts +47 -0
  1350. package/packages/daemon/src/tui/mirror/open-tui-verified-routing.ts +83 -0
  1351. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +1314 -0
  1352. package/packages/daemon/src/tui/mirror/palette-surface-adapter.ts +465 -0
  1353. package/packages/daemon/src/tui/mirror/palette.ts +485 -34
  1354. package/packages/daemon/src/tui/mirror/pane-frame-state.ts +209 -0
  1355. package/packages/daemon/src/tui/mirror/pane-mirror.ts +215 -50
  1356. package/packages/daemon/src/tui/mirror/pane-surface.tsx +720 -51
  1357. package/packages/daemon/src/tui/mirror/panel-host-reactive.ts +17 -0
  1358. package/packages/daemon/src/tui/mirror/panel-host.ts +384 -0
  1359. package/packages/daemon/src/tui/mirror/perf-tap.ts +1 -122
  1360. package/packages/daemon/src/tui/mirror/performance-events.ts +488 -0
  1361. package/packages/daemon/src/tui/mirror/recipe-components.tsx +310 -0
  1362. package/packages/daemon/src/tui/mirror/recipes-gallery.tsx +256 -0
  1363. package/packages/daemon/src/tui/mirror/recipes.ts +543 -0
  1364. package/packages/daemon/src/tui/mirror/reference-performance-trace.ts +726 -0
  1365. package/packages/daemon/src/tui/mirror/renderer-commands.ts +344 -0
  1366. package/packages/daemon/src/tui/mirror/resize-model.ts +74 -9
  1367. package/packages/daemon/src/tui/mirror/resize-transaction.ts +342 -0
  1368. package/packages/daemon/src/tui/mirror/rich-placement-projection.ts +173 -0
  1369. package/packages/daemon/src/tui/mirror/runtime/__snapshots__/application-shell-view-renderer.test.tsx.snap +87 -0
  1370. package/packages/daemon/src/tui/mirror/runtime/application-appearance-owner.ts +121 -0
  1371. package/packages/daemon/src/tui/mirror/runtime/application-bootstrap.ts +118 -0
  1372. package/packages/daemon/src/tui/mirror/runtime/application-entry.ts +194 -0
  1373. package/packages/daemon/src/tui/mirror/runtime/application-generation-starter.ts +116 -0
  1374. package/packages/daemon/src/tui/mirror/runtime/application-home-catalog-owner.ts +112 -0
  1375. package/packages/daemon/src/tui/mirror/runtime/application-home-catalog.ts +440 -0
  1376. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-binding.ts +143 -0
  1377. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-capability.ts +46 -0
  1378. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-presentation.ts +176 -0
  1379. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-test-control.ts +313 -0
  1380. package/packages/daemon/src/tui/mirror/runtime/application-input-readiness.ts +28 -0
  1381. package/packages/daemon/src/tui/mirror/runtime/application-lifecycle.ts +374 -0
  1382. package/packages/daemon/src/tui/mirror/runtime/application-optional-features.ts +25 -0
  1383. package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +87 -0
  1384. package/packages/daemon/src/tui/mirror/runtime/application-palette-input.ts +105 -0
  1385. package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-input.ts +43 -0
  1386. package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-owner.ts +43 -0
  1387. package/packages/daemon/src/tui/mirror/runtime/application-pending-terminal-input.ts +117 -0
  1388. package/packages/daemon/src/tui/mirror/runtime/application-performance-log.ts +110 -0
  1389. package/packages/daemon/src/tui/mirror/runtime/application-post-render-runtime.ts +163 -0
  1390. package/packages/daemon/src/tui/mirror/runtime/application-root-configuration.ts +47 -0
  1391. package/packages/daemon/src/tui/mirror/runtime/application-root-renderer.ts +32 -0
  1392. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +506 -0
  1393. package/packages/daemon/src/tui/mirror/runtime/application-session-focus-owner.ts +80 -0
  1394. package/packages/daemon/src/tui/mirror/runtime/application-shell-binding.ts +365 -0
  1395. package/packages/daemon/src/tui/mirror/runtime/application-shell-catalog.tsx +372 -0
  1396. package/packages/daemon/src/tui/mirror/runtime/application-shell-home.tsx +161 -0
  1397. package/packages/daemon/src/tui/mirror/runtime/application-shell-overlay-stack.tsx +42 -0
  1398. package/packages/daemon/src/tui/mirror/runtime/application-shell-overlays.tsx +154 -0
  1399. package/packages/daemon/src/tui/mirror/runtime/application-shell-sidebar.tsx +140 -0
  1400. package/packages/daemon/src/tui/mirror/runtime/application-shell-view.tsx +425 -0
  1401. package/packages/daemon/src/tui/mirror/runtime/application-shell-viewport.ts +18 -0
  1402. package/packages/daemon/src/tui/mirror/runtime/application-terminal-frame-readiness-owner.ts +33 -0
  1403. package/packages/daemon/src/tui/mirror/runtime/application-terminal-host-focus-owner.ts +36 -0
  1404. package/packages/daemon/src/tui/mirror/runtime/application-terminal-input-ingress.ts +133 -0
  1405. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +1630 -0
  1406. package/packages/daemon/src/tui/mirror/runtime/application-terminal-palette-owner.ts +302 -0
  1407. package/packages/daemon/src/tui/mirror/runtime/application-terminal-paste.ts +33 -0
  1408. package/packages/daemon/src/tui/mirror/runtime/application-terminal-renderer-sources.ts +33 -0
  1409. package/packages/daemon/src/tui/mirror/runtime/application-terminal-selection-owner.ts +218 -0
  1410. package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace-policy.ts +285 -0
  1411. package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace.tsx +1150 -0
  1412. package/packages/daemon/src/tui/mirror/runtime/application-theme-repaint.ts +45 -0
  1413. package/packages/daemon/src/tui/mirror/runtime/application-transient-note-owner.ts +42 -0
  1414. package/packages/daemon/src/tui/mirror/runtime/bounded-performance-record-writer.ts +75 -0
  1415. package/packages/daemon/src/tui/mirror/runtime/causal-cell-client-ledger.ts +394 -0
  1416. package/packages/daemon/src/tui/mirror/runtime/causal-cell-input-fixture.ts +55 -0
  1417. package/packages/daemon/src/tui/mirror/runtime/changes-deferred-identity.ts +34 -0
  1418. package/packages/daemon/src/tui/mirror/runtime/daemon-authority-rebind.ts +163 -0
  1419. package/packages/daemon/src/tui/mirror/runtime/deferred-intent-queue.ts +45 -0
  1420. package/packages/daemon/src/tui/mirror/runtime/editor-primitives.ts +56 -0
  1421. package/packages/daemon/src/tui/mirror/runtime/file-content-primitives.ts +8 -0
  1422. package/packages/daemon/src/tui/mirror/runtime/fleet-lifecycle-client.ts +61 -0
  1423. package/packages/daemon/src/tui/mirror/runtime/focus-framebuffer-projection.ts +71 -0
  1424. package/packages/daemon/src/tui/mirror/runtime/generation-bound-slot.ts +23 -0
  1425. package/packages/daemon/src/tui/mirror/runtime/host-local-tmux-adapter.ts +105 -0
  1426. package/packages/daemon/src/tui/mirror/runtime/hosted-tty-size-bridge.ts +213 -0
  1427. package/packages/daemon/src/tui/mirror/runtime/latest-intent-fence.ts +22 -0
  1428. package/packages/daemon/src/tui/mirror/runtime/local-view-controller.ts +95 -0
  1429. package/packages/daemon/src/tui/mirror/runtime/modal-admission-coordinator.ts +158 -0
  1430. package/packages/daemon/src/tui/mirror/runtime/modal-pointer-capture.ts +23 -0
  1431. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +996 -0
  1432. package/packages/daemon/src/tui/mirror/runtime/open-tui-session-owner.ts +195 -0
  1433. package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.ts +234 -0
  1434. package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.typecheck.ts +14 -0
  1435. package/packages/daemon/src/tui/mirror/runtime/palette-production-controller.ts +170 -0
  1436. package/packages/daemon/src/tui/mirror/runtime/palette-production-overlay.tsx +65 -0
  1437. package/packages/daemon/src/tui/mirror/runtime/pane-resize-geometry.ts +22 -0
  1438. package/packages/daemon/src/tui/mirror/runtime/pane-scoped-terminal-surface.tsx +146 -0
  1439. package/packages/daemon/src/tui/mirror/runtime/product-surface-policy.ts +16 -0
  1440. package/packages/daemon/src/tui/mirror/runtime/renderer-cadence.ts +4 -0
  1441. package/packages/daemon/src/tui/mirror/runtime/resize-terminal-pane.ts +134 -0
  1442. package/packages/daemon/src/tui/mirror/runtime/rich-preview-demand.ts +26 -0
  1443. package/packages/daemon/src/tui/mirror/runtime/rich-preview-overlay.tsx +54 -0
  1444. package/packages/daemon/src/tui/mirror/runtime/runtime-layout-presentation.ts +119 -0
  1445. package/packages/daemon/src/tui/mirror/runtime/select-terminal-pane.ts +127 -0
  1446. package/packages/daemon/src/tui/mirror/runtime/semantic-pane-publication.ts +26 -0
  1447. package/packages/daemon/src/tui/mirror/runtime/semantic-shell-viewport-resize.ts +78 -0
  1448. package/packages/daemon/src/tui/mirror/runtime/terminal-dimensions-owner.ts +20 -0
  1449. package/packages/daemon/src/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.ts +719 -0
  1450. package/packages/daemon/src/tui/mirror/runtime/terminal-frame-readiness.ts +100 -0
  1451. package/packages/daemon/src/tui/mirror/runtime/terminal-host-focus.ts +519 -0
  1452. package/packages/daemon/src/tui/mirror/runtime/terminal-host-frame-diagnostics.ts +47 -0
  1453. package/packages/daemon/src/tui/mirror/runtime/terminal-input-adapter.ts +69 -0
  1454. package/packages/daemon/src/tui/mirror/runtime/terminal-layout-projection.ts +45 -0
  1455. package/packages/daemon/src/tui/mirror/runtime/terminal-pane-input-router.ts +94 -0
  1456. package/packages/daemon/src/tui/mirror/runtime/terminal-selection.ts +218 -0
  1457. package/packages/daemon/src/tui/mirror/runtime/terminal-session-handoff.ts +143 -0
  1458. package/packages/daemon/src/tui/mirror/runtime/terminal-tool-readiness.ts +72 -0
  1459. package/packages/daemon/src/tui/mirror/runtime/tool-resource-controller.ts +799 -0
  1460. package/packages/daemon/src/tui/mirror/runtime/tool-resource-projection.ts +223 -0
  1461. package/packages/daemon/src/tui/mirror/runtime/viewport-fit-coordinator.ts +12 -0
  1462. package/packages/daemon/src/tui/mirror/runtime/workspace-terminal-fast-lane.ts +597 -0
  1463. package/packages/daemon/src/tui/mirror/selection.ts +122 -29
  1464. package/packages/daemon/src/tui/mirror/semantic-pane-render-source.ts +767 -0
  1465. package/packages/daemon/src/tui/mirror/semantic-session-view.ts +366 -0
  1466. package/packages/daemon/src/tui/mirror/settings-model.ts +95 -57
  1467. package/packages/daemon/src/tui/mirror/shell-chrome-view.tsx +346 -0
  1468. package/packages/daemon/src/tui/mirror/shell-chrome.ts +508 -0
  1469. package/packages/daemon/src/tui/mirror/sidebar.tsx +321 -0
  1470. package/packages/daemon/src/tui/mirror/size-truth.ts +53 -0
  1471. package/packages/daemon/src/tui/mirror/terminal-surface.ts +157 -0
  1472. package/packages/daemon/src/tui/mirror/terminal-surface.tsx +84 -0
  1473. package/packages/daemon/src/tui/mirror/terminal-text.ts +42 -0
  1474. package/packages/daemon/src/tui/mirror/theme.ts +1059 -0
  1475. package/packages/daemon/src/tui/mirror/ui/agent-badge.tsx +41 -0
  1476. package/packages/daemon/src/tui/mirror/ui/badge.tsx +42 -0
  1477. package/packages/daemon/src/tui/mirror/ui/button.tsx +127 -0
  1478. package/packages/daemon/src/tui/mirror/ui/dialog.tsx +45 -0
  1479. package/packages/daemon/src/tui/mirror/ui/index.ts +59 -0
  1480. package/packages/daemon/src/tui/mirror/ui/key-hint.tsx +63 -0
  1481. package/packages/daemon/src/tui/mirror/ui/keyboard-router.tsx +72 -0
  1482. package/packages/daemon/src/tui/mirror/ui/menu.tsx +68 -0
  1483. package/packages/daemon/src/tui/mirror/ui/navigation-row.tsx +114 -0
  1484. package/packages/daemon/src/tui/mirror/ui/overlay-frame.tsx +115 -0
  1485. package/packages/daemon/src/tui/mirror/ui/overlay-host.tsx +71 -0
  1486. package/packages/daemon/src/tui/mirror/ui/overlay-list-row.tsx +59 -0
  1487. package/packages/daemon/src/tui/mirror/ui/overlay-model.ts +75 -0
  1488. package/packages/daemon/src/tui/mirror/ui/state.ts +218 -0
  1489. package/packages/daemon/src/tui/mirror/ui/status-bar.tsx +208 -0
  1490. package/packages/daemon/src/tui/mirror/ui/surface.tsx +71 -0
  1491. package/packages/daemon/src/tui/mirror/ui/tabs.tsx +168 -0
  1492. package/packages/daemon/src/tui/mirror/widget-fallback.ts +66 -0
  1493. package/packages/daemon/src/tui/mirror/widget-surface-model.ts +170 -0
  1494. package/packages/daemon/src/tui/mirror/widget-surface.tsx +79 -0
  1495. package/packages/daemon/src/tui/mirror/workspace/README.md +79 -0
  1496. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/agent-terminal-canvas-renderer.test.tsx.snap +348 -0
  1497. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/application-shell-renderer.test.tsx.snap +134 -0
  1498. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/command-palette-surface-renderer.test.tsx.snap +255 -0
  1499. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/pane-frame-renderer.test.tsx.snap +525 -0
  1500. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/workbench-shell-renderer.test.tsx.snap +134 -0
  1501. package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas-view.tsx +61 -0
  1502. package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas.ts +131 -0
  1503. package/packages/daemon/src/tui/mirror/workspace/application-root-controller.ts +169 -0
  1504. package/packages/daemon/src/tui/mirror/workspace/application-shell-controller.ts +430 -0
  1505. package/packages/daemon/src/tui/mirror/workspace/application-shell-surface-commands.ts +64 -0
  1506. package/packages/daemon/src/tui/mirror/workspace/application-shell-view.tsx +169 -0
  1507. package/packages/daemon/src/tui/mirror/workspace/application-shell.ts +179 -0
  1508. package/packages/daemon/src/tui/mirror/workspace/command-palette-surface-view.tsx +356 -0
  1509. package/packages/daemon/src/tui/mirror/workspace/command-palette-surface.ts +544 -0
  1510. package/packages/daemon/src/tui/mirror/workspace/icons.ts +56 -0
  1511. package/packages/daemon/src/tui/mirror/workspace/pane-action-menu.tsx +68 -0
  1512. package/packages/daemon/src/tui/mirror/workspace/pane-frame.ts +675 -0
  1513. package/packages/daemon/src/tui/mirror/workspace/pane-frame.tsx +490 -0
  1514. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome-view.tsx +125 -0
  1515. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome.ts +833 -0
  1516. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-header.tsx +225 -0
  1517. package/packages/daemon/src/tui/mirror/workspace/terminal-window-strip.tsx +466 -0
  1518. package/packages/daemon/src/tui/mirror/workspace/text.ts +28 -0
  1519. package/packages/daemon/src/tui/mirror/workspace/workbench-controller.ts +75 -0
  1520. package/packages/daemon/src/tui/mirror/workspace/workbench-dock-opentui.tsx +224 -0
  1521. package/packages/daemon/src/tui/mirror/workspace/workbench-shell.ts +486 -0
  1522. package/packages/daemon/src/tui/mirror/workspace/workbench-shell.tsx +95 -0
  1523. package/packages/daemon/src/tui/mirror/workspace-ui-state.ts +1278 -0
  1524. package/packages/daemon/src/tui/readiness.ts +52 -0
  1525. package/packages/daemon/src/tui/team/entry.ts +23 -13
  1526. package/packages/daemon/src/tui/team/fuzzy.ts +20 -0
  1527. package/packages/daemon/src/tui/team/home.ts +1 -1
  1528. package/packages/daemon/src/tui/team/index.tsx +27 -8
  1529. package/packages/daemon/src/tui/team/projects.ts +12 -0
  1530. package/packages/daemon/src/tui/team/sessions.ts +119 -46
  1531. package/packages/daemon/src/tui/team/wait-receipts.ts +192 -0
  1532. package/packages/daemon/src/tui/team/wait.ts +144 -0
  1533. package/packages/daemon/src/ui/pane-frame/fixture.ts +43 -0
  1534. package/packages/daemon/src/ui/workbench-dock/fixture.ts +61 -0
  1535. package/packages/daemon/src/validate.ts +21 -9
  1536. package/packages/daemon/src/widgets/config/README.md +1 -1
  1537. package/packages/daemon/src/widgets/config/index.tsx +15 -115
  1538. package/packages/daemon/src/widgets/lib/watcher.ts +3 -130
  1539. package/packages/daemon/src/widgets/resolve.ts +15 -7
  1540. package/packages/daemon/src/widgets/setup/footer.tsx +0 -7
  1541. package/packages/daemon/src/widgets/setup/index.tsx +18 -20
  1542. package/packages/daemon/src/widgets/setup/review-panel.tsx +15 -10
  1543. package/packages/daemon/src/widgets/setup/setup-model.ts +7 -10
  1544. package/packages/daemon-client/package.json +42 -0
  1545. package/packages/daemon-client/src/application-shell-session.test.ts +196 -0
  1546. package/packages/daemon-client/src/application-shell-session.ts +450 -0
  1547. package/packages/daemon-client/src/bootstrap-coordinator.test.ts +122 -0
  1548. package/packages/daemon-client/src/bootstrap-coordinator.ts +293 -0
  1549. package/packages/daemon-client/src/connection-supervisor.test.ts +109 -0
  1550. package/packages/daemon-client/src/connection-supervisor.ts +216 -0
  1551. package/packages/daemon-client/src/direct-application-shell-transport.test.ts +939 -0
  1552. package/packages/daemon-client/src/direct-application-shell-transport.ts +1144 -0
  1553. package/packages/daemon-client/src/first-latest-coordinator.test.ts +175 -0
  1554. package/packages/daemon-client/src/first-latest-coordinator.ts +82 -0
  1555. package/packages/daemon-client/src/generation-bound-store-timers.test.ts +74 -0
  1556. package/packages/daemon-client/src/generation-bound-store.ts +908 -0
  1557. package/packages/daemon-client/src/index.ts +25 -0
  1558. package/packages/daemon-client/src/owner-action-client.test.ts +180 -0
  1559. package/packages/daemon-client/src/owner-action-client.ts +113 -0
  1560. package/packages/daemon-client/src/pane-stream-client.test.ts +2754 -0
  1561. package/packages/daemon-client/src/pane-stream-client.ts +1665 -0
  1562. package/packages/daemon-client/src/pane-stream-clock-calibration.test.ts +207 -0
  1563. package/packages/daemon-client/src/pane-stream-clock-calibration.ts +161 -0
  1564. package/packages/daemon-client/src/pane-stream-loopback-benchmark.test.ts +51 -0
  1565. package/packages/daemon-client/src/push-resource-session.test.ts +509 -0
  1566. package/packages/daemon-client/src/push-resource-session.ts +797 -0
  1567. package/packages/daemon-client/src/resource-replica.test.ts +186 -0
  1568. package/packages/daemon-client/src/resource-replica.ts +280 -0
  1569. package/packages/daemon-client/src/runtime-resource-ledger.test.ts +18 -0
  1570. package/packages/daemon-client/src/runtime-resource-ledger.ts +69 -0
  1571. package/packages/daemon-client/src/terminal-fast-lane.test.ts +817 -0
  1572. package/packages/daemon-client/src/terminal-fast-lane.ts +817 -0
  1573. package/packages/daemon-client/src/terminal-fast-lane.typecheck.ts +16 -0
  1574. package/packages/daemon-client/src/workspace-catalog-v2.test.ts +109 -0
  1575. package/packages/daemon-client/src/workspace-catalog-v2.ts +66 -0
  1576. package/packages/daemon-client/src/workspace-client-boundaries.test.ts +59 -0
  1577. package/packages/daemon-client/src/workspace-client-conformance.ts +67 -0
  1578. package/packages/daemon-client/src/workspace-client-operations.ts +203 -0
  1579. package/packages/daemon-client/src/workspace-client-types.ts +302 -0
  1580. package/packages/daemon-client/src/workspace-client.test.ts +2626 -0
  1581. package/packages/daemon-client/src/workspace-client.ts +1421 -0
  1582. package/packages/daemon-client/src/workspace-event-supervisor.test.ts +1086 -0
  1583. package/packages/daemon-client/src/workspace-event-supervisor.ts +719 -0
  1584. package/packages/daemon-client/src/workspace-pane-client.test.ts +80 -0
  1585. package/packages/daemon-client/src/workspace-pane-client.ts +63 -0
  1586. package/packages/presentation/package.json +28 -0
  1587. package/packages/presentation/src/index.ts +2 -0
  1588. package/packages/presentation/src/pane-frame/action-state.ts +72 -0
  1589. package/packages/presentation/src/pane-frame/index.ts +3 -0
  1590. package/packages/presentation/src/pane-frame/model.ts +517 -0
  1591. package/packages/presentation/src/pane-frame/presenter.tsx +335 -0
  1592. package/packages/presentation/src/pane-frame/web-entry.tsx +22 -0
  1593. package/packages/presentation/src/pane-frame/web-host-unstyled.tsx +280 -0
  1594. package/packages/presentation/src/pane-frame/web-host.css +388 -0
  1595. package/packages/presentation/src/pane-frame/web-host.tsx +3 -0
  1596. package/packages/presentation/src/presentation-contract.test.ts +63 -0
  1597. package/packages/presentation/src/workbench-dock/index.ts +2 -0
  1598. package/packages/presentation/src/workbench-dock/navigation.ts +54 -0
  1599. package/packages/presentation/src/workbench-dock/presenter.tsx +252 -0
  1600. package/packages/presentation/src/workbench-dock/web-entry.tsx +19 -0
  1601. package/packages/presentation/src/workbench-dock/web-host-unstyled.tsx +198 -0
  1602. package/packages/presentation/src/workbench-dock/web-host.css +204 -0
  1603. package/packages/presentation/src/workbench-dock/web-host.tsx +3 -0
  1604. package/packages/tmux-bridge/src/index.ts +9 -1
  1605. package/packages/tmux-bridge/src/panes.ts +4 -0
  1606. package/packages/tmux-bridge/src/runner.test.ts +72 -0
  1607. package/packages/tmux-bridge/src/runner.ts +43 -2
  1608. package/packages/tmux-bridge/src/sessions.ts +8 -1
  1609. package/scripts/architecture-debt-budget.json +10 -0
  1610. package/scripts/architecture-debt-inventory.mjs +98 -0
  1611. package/scripts/build-cli.mjs +22 -1
  1612. package/scripts/build-macos-notifier.mjs +160 -0
  1613. package/scripts/build-tui.mjs +59 -3
  1614. package/scripts/check-control-bytes.mjs +70 -0
  1615. package/scripts/dev-web.mjs +66 -0
  1616. package/scripts/lib/bounded-child-command.mjs +59 -0
  1617. package/scripts/lib/bounded-child-command.test.mjs +148 -0
  1618. package/scripts/lib/bounded-diagnostic-tail.mjs +82 -0
  1619. package/scripts/lib/bounded-diagnostic-tail.test.mjs +97 -0
  1620. package/scripts/lib/npm-release-tag.mjs +27 -0
  1621. package/scripts/lib/npm-release-tag.test.mjs +116 -0
  1622. package/scripts/lib/packed-opentui-frame.mjs +18 -0
  1623. package/scripts/lib/packed-opentui-frame.test.mjs +40 -0
  1624. package/scripts/lib/performance-reference-budgets.mjs +36 -0
  1625. package/scripts/lib/performance-reference-report.mjs +157 -0
  1626. package/scripts/lib/performance-reference-report.test.mjs +62 -0
  1627. package/scripts/lib/portable-performance-evidence.mjs +210 -0
  1628. package/scripts/lib/portable-performance-evidence.test.mjs +208 -0
  1629. package/scripts/lib/product-ansi-cursor-alt-screen-fixture.mjs +132 -0
  1630. package/scripts/lib/product-ansi-cursor-alt-screen.mjs +4618 -0
  1631. package/scripts/lib/product-ansi-cursor-alt-screen.test.mjs +4120 -0
  1632. package/scripts/lib/product-ansi-tmux-precondition.mjs +159 -0
  1633. package/scripts/lib/product-ansi-tmux-precondition.test.mjs +147 -0
  1634. package/scripts/lib/product-card5-host-topology.mjs +873 -0
  1635. package/scripts/lib/product-card5-host-topology.test.mjs +1070 -0
  1636. package/scripts/lib/product-card5-production-host-owner.mjs +4864 -0
  1637. package/scripts/lib/product-card5-production-host-owner.test.mjs +5051 -0
  1638. package/scripts/lib/product-configless-owner.mjs +1578 -0
  1639. package/scripts/lib/product-configless-owner.test.mjs +2169 -0
  1640. package/scripts/lib/product-cross-client-handoff.mjs +1165 -0
  1641. package/scripts/lib/product-cross-client-handoff.test.mjs +1062 -0
  1642. package/scripts/lib/product-cross-client-host-evidence.mjs +4780 -0
  1643. package/scripts/lib/product-cross-client-host-evidence.test.mjs +3897 -0
  1644. package/scripts/lib/product-first-input.mjs +1546 -0
  1645. package/scripts/lib/product-first-input.test.mjs +1731 -0
  1646. package/scripts/lib/product-focus-tmux.mjs +46 -0
  1647. package/scripts/lib/product-focus.mjs +1198 -0
  1648. package/scripts/lib/product-focus.test.mjs +1504 -0
  1649. package/scripts/lib/product-idle-process-proof.mjs +270 -0
  1650. package/scripts/lib/product-idle-process-proof.test.mjs +210 -0
  1651. package/scripts/lib/product-keyboard-pointer-resize.mjs +471 -0
  1652. package/scripts/lib/product-keyboard-pointer-resize.test.mjs +363 -0
  1653. package/scripts/lib/product-rig-causal-cell-fixture.mjs +91 -0
  1654. package/scripts/lib/product-rig-causal-fixture-geometry.mjs +27 -0
  1655. package/scripts/lib/product-rig-causal-fixture-geometry.test.mjs +45 -0
  1656. package/scripts/lib/product-rig-sleep-assertion.mjs +179 -0
  1657. package/scripts/lib/product-selection-copy-app-mouse.mjs +1585 -0
  1658. package/scripts/lib/product-selection-copy-app-mouse.test.mjs +1602 -0
  1659. package/scripts/lib/product-tui-host-readiness.mjs +133 -0
  1660. package/scripts/lib/product-tui-host-readiness.test.mjs +258 -0
  1661. package/scripts/lib/product-window-lifecycle.mjs +1351 -0
  1662. package/scripts/lib/product-window-lifecycle.test.mjs +1305 -0
  1663. package/scripts/lib/release-source-state.mjs +28 -0
  1664. package/scripts/lib/release-source-state.test.mjs +26 -0
  1665. package/scripts/lib/tui-diagnostics.mjs +159 -0
  1666. package/scripts/lib/tui-host-publication.mjs +38 -0
  1667. package/scripts/lib/tui-testdrive-clipboard-hook.mjs +543 -0
  1668. package/scripts/lib/tui-testdrive-clipboard-hook.test.mjs +626 -0
  1669. package/scripts/lib/tui-testdrive-input.mjs +1940 -0
  1670. package/scripts/lib/tui-testdrive-input.test.mjs +3434 -0
  1671. package/scripts/lib/tui-testdrive-launch.mjs +180 -0
  1672. package/scripts/lib/tui-testdrive-launch.test.mjs +294 -0
  1673. package/scripts/opentui-release-check.mjs +209 -0
  1674. package/scripts/pack-check-run.mjs +1779 -30
  1675. package/scripts/pack-tui-check.mjs +73 -0
  1676. package/scripts/pack-web-check.mjs +19 -0
  1677. package/scripts/performance-portable-evidence.mjs +419 -0
  1678. package/scripts/performance-qualification.mjs +456 -0
  1679. package/scripts/performance-reference-memory.ts +177 -0
  1680. package/scripts/performance-reference-pane-stream.ts +74 -0
  1681. package/scripts/performance-reference.mjs +681 -0
  1682. package/scripts/postinstall.js +14 -6
  1683. package/scripts/prepublish-check.mjs +37 -1
  1684. package/scripts/prepublish-opentui-check.mjs +24 -0
  1685. package/scripts/product-test-rig-journeys.mjs +2700 -0
  1686. package/scripts/product-test-rig-journeys.test.mjs +3959 -0
  1687. package/scripts/product-test-rig-lib.mjs +2359 -0
  1688. package/scripts/product-test-rig-multiclient.ts +434 -0
  1689. package/scripts/product-test-rig-native-client.mjs +45 -0
  1690. package/scripts/product-test-rig.mjs +20260 -0
  1691. package/scripts/product-test-rig.test.mjs +3634 -0
  1692. package/scripts/publish-tap.sh +55 -0
  1693. package/scripts/smoke-tui-missions.mjs +329 -0
  1694. package/scripts/tui-diagnose.mjs +258 -0
  1695. package/scripts/tui-diagnose.test.mjs +200 -0
  1696. package/scripts/tui-testdrive-capture.test.mjs +161 -0
  1697. package/scripts/tui-testdrive.mjs +1955 -0
  1698. package/skill/SKILL.md +115 -30
  1699. package/templates/agent-team-monorepo.yml +28 -30
  1700. package/templates/agent-team-nextjs.yml +24 -26
  1701. package/templates/agent-team.yml +24 -24
  1702. package/templates/convex.yml +24 -16
  1703. package/templates/default.yml +26 -21
  1704. package/templates/go.yml +21 -14
  1705. package/templates/missions.yml +25 -40
  1706. package/templates/nextjs.yml +24 -16
  1707. package/templates/python.yml +21 -14
  1708. package/templates/vite.yml +21 -14
  1709. package/packages/daemon/dist/widgets/changes/index.jsx +0 -575
  1710. package/packages/daemon/dist/widgets/config/index.d.ts +0 -1
  1711. package/packages/daemon/dist/widgets/config/index.jsx +0 -395
  1712. package/packages/daemon/dist/widgets/explorer/breadcrumbs.d.ts +0 -10
  1713. package/packages/daemon/dist/widgets/explorer/breadcrumbs.jsx +0 -51
  1714. package/packages/daemon/dist/widgets/explorer/footer.d.ts +0 -6
  1715. package/packages/daemon/dist/widgets/explorer/footer.jsx +0 -11
  1716. package/packages/daemon/dist/widgets/explorer/index.jsx +0 -393
  1717. package/packages/daemon/dist/widgets/explorer/tree.d.ts +0 -13
  1718. package/packages/daemon/dist/widgets/explorer/tree.jsx +0 -108
  1719. package/packages/daemon/dist/widgets/lib/help-overlay.d.ts +0 -19
  1720. package/packages/daemon/dist/widgets/lib/help-overlay.jsx +0 -69
  1721. package/packages/daemon/dist/widgets/preview/index.jsx +0 -371
  1722. package/packages/daemon/dist/widgets/setup/agent-naming.d.ts +0 -9
  1723. package/packages/daemon/dist/widgets/setup/agent-naming.jsx +0 -81
  1724. package/packages/daemon/dist/widgets/setup/config-tree.d.ts +0 -13
  1725. package/packages/daemon/dist/widgets/setup/config-tree.jsx +0 -203
  1726. package/packages/daemon/dist/widgets/setup/detect-panel.d.ts +0 -14
  1727. package/packages/daemon/dist/widgets/setup/detect-panel.jsx +0 -48
  1728. package/packages/daemon/dist/widgets/setup/field-editor.d.ts +0 -12
  1729. package/packages/daemon/dist/widgets/setup/field-editor.jsx +0 -163
  1730. package/packages/daemon/dist/widgets/setup/footer.d.ts +0 -17
  1731. package/packages/daemon/dist/widgets/setup/footer.jsx +0 -64
  1732. package/packages/daemon/dist/widgets/setup/index.d.ts +0 -1
  1733. package/packages/daemon/dist/widgets/setup/index.jsx +0 -261
  1734. package/packages/daemon/dist/widgets/setup/layout-picker.d.ts +0 -9
  1735. package/packages/daemon/dist/widgets/setup/layout-picker.jsx +0 -69
  1736. package/packages/daemon/dist/widgets/sidebar/index.jsx +0 -462
  1737. package/packages/daemon/src/tui/mirror/control-client.ts +0 -214
  1738. package/packages/daemon/src/tui/mirror/focus-border.ts +0 -57
  1739. package/packages/daemon/src/tui/mirror/session-mirror.ts +0 -443
  1740. package/packages/daemon/src/widgets/setup/orchestrator-panel.tsx +0 -200
  1741. package/scripts/perf-mirror.mjs +0 -313
  1742. package/scripts/verify-endpoints.sh +0 -90
  1743. /package/packages/daemon/dist/{widgets/changes/index.d.ts → lib/__tests__/fixtures/workspace-state-writer.d.ts} +0 -0
  1744. /package/packages/daemon/dist/{widgets/explorer/index.d.ts → terminal/mirror/trusted-inventory.js} +0 -0
  1745. /package/packages/daemon/dist/{widgets/preview/index.d.ts → terminal/session-runtime/terminal-interpreter-backend.js} +0 -0
  1746. /package/packages/daemon/dist/{widgets/sidebar/index.d.ts → tui/mirror/features/changes/contract.js} +0 -0
@@ -0,0 +1,2612 @@
1
+ import { z } from "zod";
2
+ import {
3
+ PANE_STREAM_MAX_HELD_DELTAS,
4
+ PANE_STREAM_MAX_OUTPUT_BYTES,
5
+ PANE_STREAM_MAX_PANES,
6
+ PANE_STREAM_MAX_SEED_BYTES,
7
+ PANE_STREAM_PROTOCOL_VERSION,
8
+ PANE_STREAM_REDEEM_PATH,
9
+ PANE_STREAM_WEBSOCKET_SUBPROTOCOL,
10
+ PaneStreamClientFrameSchemaZ,
11
+ PaneStreamLoopbackWebSocketUrlSchemaZ,
12
+ PaneStreamRedeemFrameSchemaZ,
13
+ PaneStreamServerFrameSchemaZ,
14
+ sharedMonotonicMicros,
15
+ type PaneStreamErrorFrameCode,
16
+ type PaneStreamServerFrame,
17
+ type PaneStreamLeaseRequest,
18
+ type PaneStreamRedeemFrame,
19
+ type PaneStreamViewerMode,
20
+ type PaneStreamDiagnosticCapability,
21
+ type SessionRuntimeSemanticIntent,
22
+ type SessionRuntimeTerminalInput,
23
+ type CausalCellProbeV1,
24
+ type SessionRuntimeActivityKind,
25
+ type SessionRuntimeAuthorityKind,
26
+ type SessionRuntimeAuthorityLease,
27
+ type SessionRuntimeAuthoritySnapshot,
28
+ type SessionRuntimePresenceState,
29
+ type TerminalDeliveryAck,
30
+ type TerminalDeliveryNack,
31
+ type TerminalDeliveryOffer,
32
+ type TerminalDeliveryNegotiationResult,
33
+ type TerminalDeliveryServerMessage,
34
+ type TerminalDeliveryVisibility,
35
+ type WorkspaceMultiplexerMutationResult,
36
+ } from "@tmux-ide/contracts";
37
+ import type {
38
+ MirrorLayoutAuthoritySnapshot,
39
+ MirrorLayoutEvent,
40
+ MirrorPaneEvent,
41
+ MirrorSessionDescription,
42
+ } from "../mirror/events.ts";
43
+ import type {
44
+ MirrorLayoutSubscription,
45
+ MirrorSubscribeRequest,
46
+ MirrorSubscription,
47
+ } from "../mirror/mirror-service.ts";
48
+ import type { CausalCellLedgerResult } from "../session-runtime/causal-cell-ledger.ts";
49
+ import {
50
+ canonicalOriginOrNull,
51
+ digestSecret,
52
+ digestsEqual,
53
+ rawDataByteLength,
54
+ rawDataToBuffer,
55
+ safeCloseSocket,
56
+ strictJsonParse,
57
+ } from "../attachments/admission-util.ts";
58
+ import type { DirectTerminalSocket } from "../attachments/direct-websocket.ts";
59
+ import type { SessionRuntimeObservability } from "../session-runtime/runtime-observability.ts";
60
+ import { SessionRuntimeControllerLeaseError } from "../session-runtime/registry.ts";
61
+ import { terminalDeliveryObservationOrdinal } from "../session-runtime/terminal-delivery-observation-identity.ts";
62
+ import {
63
+ PaneStreamLeaseError,
64
+ type IssuedPaneStreamLease,
65
+ type PaneStreamLeaseBinding,
66
+ type PaneStreamLeaseDescriptor,
67
+ } from "./lease-manager.ts";
68
+ import {
69
+ DEFAULT_PANE_STREAM_FLOW_BUDGETS,
70
+ PaneStreamWireLedger,
71
+ type PaneStreamFlowBudgets,
72
+ } from "./wire-ledger.ts";
73
+
74
+ /**
75
+ * The pane-stream WebSocket endpoint (m43 card 2): redeems a one-time `ps1_`
76
+ * ticket and bridges MirrorService subscriptions to wire frames. Admission is
77
+ * the direct-websocket discipline verbatim — Origin-gated upgrade reservation,
78
+ * digest-only pending tickets, one text redemption frame, delivery-bound TTL —
79
+ * applied to a session-scoped lease whose pane set was enumerated at issue.
80
+ *
81
+ * Flow control at the wire is a LEDGER per (client x pane x owner): a stalled
82
+ * client freezes ONLY its own MirrorService subscription for the exhausted
83
+ * pane (siblings and other clients keep flowing; the upstream control-mode
84
+ * pause engages only when every subscriber of a pane is parked, which the
85
+ * session channel already models), tickets force-return on WS close within
86
+ * one tick, and thaw rides the service's atomic reseed.
87
+ */
88
+ export { PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL };
89
+ export const PANE_STREAM_MAX_REDEMPTION_BYTES = 4 * 1024;
90
+ export const PANE_STREAM_MAX_CONTROL_BYTES = 4 * 1024;
91
+ export const PANE_STREAM_MAX_REDEMPTION_MS = 1_000;
92
+
93
+ const WS_OPEN = 1;
94
+ const CANONICAL_KEY_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"key",', "utf8");
95
+ const CANONICAL_TEXT_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"text",', "utf8");
96
+ const SEMANTIC_BACKEND_REFUSALS = new Set([
97
+ "pane_inventory_not_ready",
98
+ "pane_identity_changed_before_select",
99
+ "pane_not_active",
100
+ ]);
101
+
102
+ function semanticBackendRefusal(error: unknown): string | null {
103
+ let candidate = error;
104
+ for (let depth = 0; depth < 3; depth += 1) {
105
+ if (!candidate || typeof candidate !== "object") return null;
106
+ const context = "context" in candidate ? candidate.context : null;
107
+ const reason =
108
+ context && typeof context === "object" && "reason" in context ? context.reason : null;
109
+ if (typeof reason === "string" && SEMANTIC_BACKEND_REFUSALS.has(reason)) return reason;
110
+ candidate = "cause" in candidate ? candidate.cause : null;
111
+ }
112
+ return null;
113
+ }
114
+ const TYPE_FIRST_INPUT_FRAME_PREFIX = Buffer.from('{"type":"input",', "utf8");
115
+
116
+ function startsWithBuffer(raw: Buffer, prefix: Buffer): boolean {
117
+ return (
118
+ raw.length >= prefix.length && raw.compare(prefix, 0, prefix.length, 0, prefix.length) === 0
119
+ );
120
+ }
121
+
122
+ function hasCanonicalInputFramePrefix(raw: Buffer): boolean {
123
+ return (
124
+ startsWithBuffer(raw, CANONICAL_KEY_INPUT_FRAME_PREFIX) ||
125
+ startsWithBuffer(raw, CANONICAL_TEXT_INPUT_FRAME_PREFIX) ||
126
+ startsWithBuffer(raw, TYPE_FIRST_INPUT_FRAME_PREFIX)
127
+ );
128
+ }
129
+ const TicketPattern = /^ps1_[A-Za-z0-9_-]{43}$/u;
130
+ const BindingIdSchemaZ = z
131
+ .string()
132
+ .min(1)
133
+ .max(4096)
134
+ .refine((value) => !value.includes("\0"));
135
+
136
+ /** The mirror surface the endpoint consumes (MirrorService satisfies it). */
137
+ export interface PaneStreamMirror {
138
+ describeSession(session: string): Promise<MirrorSessionDescription>;
139
+ describeSessionAuthority?(
140
+ session: string,
141
+ ): Promise<{ readonly description: MirrorSessionDescription; readonly runtimeSessionId: string }>;
142
+ subscribe(request: MirrorSubscribeRequest): Promise<MirrorSubscription>;
143
+ subscribeLayout?(
144
+ session: string,
145
+ onLayout: (event: MirrorLayoutEvent) => void,
146
+ authority?: {
147
+ readonly expectedSemanticPaneIds: readonly string[];
148
+ readonly expectedRuntimeSessionId: string;
149
+ readonly onAuthority?: (snapshot: MirrorLayoutAuthoritySnapshot) => void;
150
+ },
151
+ ): Promise<MirrorLayoutSubscription>;
152
+ }
153
+
154
+ export interface PaneStreamLeaseAuthority {
155
+ issue(
156
+ request: PaneStreamLeaseRequest,
157
+ context: { requestId: string; projectIdentity: string; sessionName: string },
158
+ ): Promise<IssuedPaneStreamLease>;
159
+ redeem(
160
+ ticket: string,
161
+ binding: PaneStreamLeaseBinding,
162
+ receivedAt?: number,
163
+ ): Promise<{ descriptor: PaneStreamLeaseDescriptor }>;
164
+ release(leaseId: string, binding: PaneStreamLeaseBinding): Promise<{ released: boolean }>;
165
+ }
166
+
167
+ export type PaneStreamAdmissionErrorCode =
168
+ | "daemon-shutting-down"
169
+ | "invalid-origin"
170
+ | "origin-rejected"
171
+ | "invalid-path"
172
+ | "invalid-subprotocol"
173
+ | "pending-capacity-exhausted"
174
+ | "preauth-capacity-exhausted"
175
+ | "live-capacity-exhausted"
176
+ | "pane-not-found"
177
+ | "redemption-rejected"
178
+ | "stream-unavailable";
179
+
180
+ export class PaneStreamAdmissionError extends Error {
181
+ readonly code: PaneStreamAdmissionErrorCode;
182
+
183
+ constructor(code: PaneStreamAdmissionErrorCode, message: string) {
184
+ super(message);
185
+ this.name = "PaneStreamAdmissionError";
186
+ this.code = code;
187
+ }
188
+ }
189
+
190
+ export interface PaneStreamIssueContext {
191
+ readonly requestId: string;
192
+ readonly projectIdentity: string;
193
+ readonly sessionName: string;
194
+ /** Canonical trusted renderer Origin supplied by the host, never the renderer body. */
195
+ readonly rendererOrigin: string;
196
+ /** Stable identity injected by the trusted host boundary, never renderer JSON. */
197
+ readonly hostClientId?: string;
198
+ }
199
+
200
+ export interface PaneStreamDescriptor {
201
+ readonly protocolVersion: typeof PANE_STREAM_PROTOCOL_VERSION;
202
+ readonly webSocketUrl: string;
203
+ readonly redemptionTicket: string;
204
+ readonly daemonInstanceId: string;
205
+ readonly requestId: string;
206
+ readonly expiresAt: number;
207
+ readonly panes: readonly string[];
208
+ readonly effectiveViewerMode: PaneStreamViewerMode;
209
+ }
210
+
211
+ export type PaneStreamUpgradeDecision =
212
+ | { readonly accepted: true; readonly admission: PaneStreamPreAuthAdmission }
213
+ | {
214
+ readonly accepted: false;
215
+ readonly code: PaneStreamAdmissionErrorCode;
216
+ readonly httpStatus: 403 | 404 | 426 | 503;
217
+ };
218
+
219
+ export interface PaneStreamPreAuthAdmission {
220
+ bind(socket: DirectTerminalSocket): void;
221
+ cancelBeforeBind(): void;
222
+ }
223
+
224
+ export interface PaneStreamAdmissionSnapshot {
225
+ readonly pendingTickets: number;
226
+ readonly preAuthSockets: number;
227
+ readonly liveConnections: number;
228
+ readonly shuttingDown: boolean;
229
+ }
230
+
231
+ export interface PaneStreamAdmissionCoordinatorOptions {
232
+ readonly daemonInstanceId: string;
233
+ readonly webSocketUrl: string;
234
+ readonly leaseManager: PaneStreamLeaseAuthority;
235
+ readonly mirror: PaneStreamMirror;
236
+ /** Trusted redemption boundary into the generation's SessionRuntime owner. */
237
+ readonly bindSessionRuntime?: (
238
+ descriptor: PaneStreamLeaseDescriptor,
239
+ ) => SessionRuntimePaneStreamTransportBinding;
240
+ readonly maxPendingTickets?: number;
241
+ readonly maxPreAuthSockets?: number;
242
+ readonly maxLiveConnections?: number;
243
+ readonly redemptionTimeoutMs?: number;
244
+ readonly flowBudgets?: PaneStreamFlowBudgets;
245
+ /** Cadence of the send-buffer drain check while frames are in flight. */
246
+ readonly drainTickMs?: number;
247
+ /** Hard whole-socket ceiling; the ledger should stall panes far earlier. */
248
+ readonly maxSocketBufferedBytes?: number;
249
+ /** Input flood budget for one rolling admission window, never a lifetime quota. */
250
+ readonly maxInputFramesPerWindow?: number;
251
+ readonly maxInputBytesPerWindow?: number;
252
+ readonly inputRateWindowMs?: number;
253
+ readonly now?: () => number;
254
+ readonly schedule?: (callback: () => void, delayMs: number) => () => void;
255
+ /** Opt-in daemon-local timing observer; disabled in normal production. */
256
+ readonly observability?: SessionRuntimeObservability;
257
+ /** Test seam consulted only for a negotiated clock-bounds capability. */
258
+ readonly diagnosticSharedNowMicros?: () => number;
259
+ /** Test-only parse-delay seam; consulted only with clock diagnostics. */
260
+ readonly diagnosticAfterFrameParse?: () => void;
261
+ }
262
+
263
+ export interface SessionRuntimePaneStreamTransportBinding {
264
+ readonly generation: string;
265
+ readonly session: string;
266
+ readonly clientId: string;
267
+ readonly surface?: string;
268
+ readonly explicitAuthority?: boolean;
269
+ readonly deliveryLaneId?: string;
270
+ readonly deliveryRequestId?: string;
271
+ /** Optional only for the bounded v1 transport adapter. New clients require these methods. */
272
+ authoritySnapshot?(): SessionRuntimeAuthoritySnapshot;
273
+ activateLegacyAuthority?(geometry: boolean): SessionRuntimeAuthoritySnapshot;
274
+ onAuthoritySnapshot?(listener: (snapshot: SessionRuntimeAuthoritySnapshot) => void): () => void;
275
+ updatePresence?(state: SessionRuntimePresenceState): SessionRuntimeAuthoritySnapshot;
276
+ noteActivity?(activity: SessionRuntimeActivityKind): SessionRuntimeAuthoritySnapshot;
277
+ requestAuthority?(authority: SessionRuntimeAuthorityKind): SessionRuntimeAuthorityLease | null;
278
+ releaseAuthority?(authority: SessionRuntimeAuthorityKind): SessionRuntimeAuthoritySnapshot;
279
+ assertController(semanticPaneId?: string): void;
280
+ openTerminalDelivery(
281
+ semanticPaneId: string,
282
+ offer: TerminalDeliveryOffer,
283
+ onMessage: (message: TerminalDeliveryServerMessage) => void | Promise<void>,
284
+ ): Promise<SessionRuntimeTerminalDeliveryConnection>;
285
+ submitIntent(
286
+ operationId: string,
287
+ intent: SessionRuntimeSemanticIntent,
288
+ ): Promise<WorkspaceMultiplexerMutationResult | void>;
289
+ sendInput(
290
+ semanticPaneId: string,
291
+ input: SessionRuntimeTerminalInput,
292
+ performanceTraceId?: string,
293
+ causalProbe?: CausalCellProbeV1,
294
+ onCausalResult?: (result: CausalCellLedgerResult) => void,
295
+ ): void;
296
+ fitViewport(lease: SessionRuntimeAuthorityLease, cols: number, rows: number): void;
297
+ close(): Promise<void>;
298
+ }
299
+
300
+ export interface SessionRuntimeTerminalDeliveryConnection {
301
+ readonly negotiation: TerminalDeliveryNegotiationResult;
302
+ ack(ack: TerminalDeliveryAck): void;
303
+ nack(nack: TerminalDeliveryNack): void;
304
+ setVisibility(visibility: TerminalDeliveryVisibility): void;
305
+ close(): Promise<void>;
306
+ }
307
+
308
+ interface PendingTicket {
309
+ readonly leaseId: string;
310
+ readonly requestId: string;
311
+ readonly projectIdentity: string;
312
+ readonly origin: string;
313
+ readonly ticketDigest: Buffer;
314
+ readonly descriptor: PaneStreamLeaseDescriptor;
315
+ cancelExpiry: (() => void) | null;
316
+ }
317
+
318
+ function defaultSchedule(callback: () => void, delayMs: number): () => void {
319
+ const timer = setTimeout(callback, delayMs);
320
+ timer.unref?.();
321
+ return () => clearTimeout(timer);
322
+ }
323
+
324
+ function boundedInteger(value: number | undefined, fallback: number, maximum: number): number {
325
+ const selected = value ?? fallback;
326
+ if (!Number.isSafeInteger(selected) || selected <= 0 || selected > maximum) {
327
+ throw new TypeError("Pane-stream admission limit is invalid.");
328
+ }
329
+ return selected;
330
+ }
331
+
332
+ function sendControl(socket: DirectTerminalSocket, frame: Readonly<Record<string, unknown>>): void {
333
+ if (socket.readyState !== WS_OPEN) return;
334
+ const encoded = JSON.stringify(frame);
335
+ if (Buffer.byteLength(encoded, "utf8") > PANE_STREAM_MAX_CONTROL_BYTES) {
336
+ throw new TypeError("Pane-stream control frame exceeded its bound.");
337
+ }
338
+ socket.send(encoded, { binary: false });
339
+ }
340
+
341
+ function errorFrameCode(error: unknown): PaneStreamErrorFrameCode {
342
+ if (error instanceof PaneStreamLeaseError && error.code === "ticket-expired") {
343
+ return "ticket-expired";
344
+ }
345
+ if (error instanceof PaneStreamAdmissionError) {
346
+ switch (error.code) {
347
+ case "live-capacity-exhausted":
348
+ return "live-capacity-exhausted";
349
+ case "pane-not-found":
350
+ case "stream-unavailable":
351
+ return "stream-unavailable";
352
+ default:
353
+ return "redemption-rejected";
354
+ }
355
+ }
356
+ return "stream-unavailable";
357
+ }
358
+
359
+ /**
360
+ * In-memory admission authority for one daemon instance. It retains only
361
+ * ticket digests; a daemon restart makes every prior descriptor inert.
362
+ */
363
+ export class PaneStreamAdmissionCoordinator {
364
+ readonly #instanceId: string;
365
+ readonly #webSocketUrl: string;
366
+ readonly #leaseManager: PaneStreamLeaseAuthority;
367
+ readonly #mirror: PaneStreamMirror;
368
+ readonly #bindSessionRuntime:
369
+ | PaneStreamAdmissionCoordinatorOptions["bindSessionRuntime"]
370
+ | undefined;
371
+ readonly #maxPending: number;
372
+ readonly #maxPreAuth: number;
373
+ readonly #maxLive: number;
374
+ readonly #redemptionTimeoutMs: number;
375
+ readonly #flowBudgets: PaneStreamFlowBudgets;
376
+ readonly #drainTickMs: number;
377
+ readonly #maxSocketBufferedBytes: number;
378
+ readonly #maxInputFrames: number;
379
+ readonly #maxInputBytes: number;
380
+ readonly #inputRateWindowMs: number;
381
+ readonly #now: () => number;
382
+ readonly #schedule: (callback: () => void, delayMs: number) => () => void;
383
+ readonly #observability: SessionRuntimeObservability | undefined;
384
+ readonly #diagnosticSharedNowMicros: (() => number) | undefined;
385
+ readonly #diagnosticAfterFrameParse: (() => void) | undefined;
386
+ readonly #ledger: PaneStreamWireLedger;
387
+ readonly #pending = new Map<string, PendingTicket>();
388
+ readonly #preAuth = new Set<PreAuthAdmission>();
389
+ readonly #live = new Set<PaneStreamLiveConnection>();
390
+ readonly #retiringReleases = new Set<Promise<void>>();
391
+ #clientCounter = 0;
392
+ #operationTail: Promise<void> = Promise.resolve();
393
+ #shuttingDown = false;
394
+ #shutdownPromise: Promise<void> | null = null;
395
+
396
+ constructor(options: PaneStreamAdmissionCoordinatorOptions) {
397
+ this.#instanceId = BindingIdSchemaZ.parse(options.daemonInstanceId);
398
+ this.#webSocketUrl = PaneStreamLoopbackWebSocketUrlSchemaZ.parse(options.webSocketUrl);
399
+ this.#leaseManager = options.leaseManager;
400
+ this.#mirror = options.mirror;
401
+ this.#bindSessionRuntime = options.bindSessionRuntime;
402
+ this.#maxPending = boundedInteger(options.maxPendingTickets, 32, 1_024);
403
+ this.#maxPreAuth = boundedInteger(options.maxPreAuthSockets, 16, 1_024);
404
+ this.#maxLive = boundedInteger(options.maxLiveConnections, 16, 1_024);
405
+ this.#redemptionTimeoutMs = boundedInteger(
406
+ options.redemptionTimeoutMs,
407
+ PANE_STREAM_MAX_REDEMPTION_MS,
408
+ PANE_STREAM_MAX_REDEMPTION_MS,
409
+ );
410
+ this.#flowBudgets = options.flowBudgets ?? DEFAULT_PANE_STREAM_FLOW_BUDGETS;
411
+ this.#ledger = new PaneStreamWireLedger(this.#flowBudgets);
412
+ this.#drainTickMs = boundedInteger(options.drainTickMs, 15, 1_000);
413
+ this.#maxSocketBufferedBytes = boundedInteger(
414
+ options.maxSocketBufferedBytes,
415
+ 32 << 20,
416
+ 256 << 20,
417
+ );
418
+ this.#maxInputFrames = boundedInteger(options.maxInputFramesPerWindow, 16_384, 1 << 20);
419
+ this.#maxInputBytes = boundedInteger(options.maxInputBytesPerWindow, 4 << 20, 64 << 20);
420
+ this.#inputRateWindowMs = boundedInteger(options.inputRateWindowMs, 1_000, 60_000);
421
+ this.#now = options.now ?? Date.now;
422
+ this.#schedule = options.schedule ?? defaultSchedule;
423
+ this.#observability = options.observability;
424
+ this.#diagnosticSharedNowMicros = options.diagnosticSharedNowMicros;
425
+ this.#diagnosticAfterFrameParse = options.diagnosticAfterFrameParse;
426
+ }
427
+
428
+ issue(
429
+ request: PaneStreamLeaseRequest,
430
+ context: PaneStreamIssueContext,
431
+ ): Promise<PaneStreamDescriptor> {
432
+ const trace = this.#observability?.beginTrace(
433
+ "pane-stream-connect",
434
+ { generation: this.#instanceId, incarnation: null },
435
+ context.requestId,
436
+ );
437
+ const queuedAtMicros = trace ? this.#observability!.nowMicros() : 0;
438
+ return this.#exclusive(async () => {
439
+ const admittedAtMicros = trace ? this.#observability!.nowMicros() : 0;
440
+ if (trace)
441
+ this.#observability!.recordSpan(
442
+ "transport",
443
+ "pane-stream-issue-queue",
444
+ queuedAtMicros,
445
+ admittedAtMicros,
446
+ trace,
447
+ );
448
+ if (this.#shuttingDown) {
449
+ throw new PaneStreamAdmissionError(
450
+ "daemon-shutting-down",
451
+ "Pane-stream admission is shutting down.",
452
+ );
453
+ }
454
+ const origin = canonicalOriginOrNull(context.rendererOrigin);
455
+ if (origin === null) {
456
+ throw new PaneStreamAdmissionError("invalid-origin", "Renderer Origin is invalid.");
457
+ }
458
+ const requestId = z.uuid().parse(context.requestId);
459
+ const projectIdentity = BindingIdSchemaZ.parse(context.projectIdentity);
460
+ if (this.#pending.size >= this.#maxPending) {
461
+ throw new PaneStreamAdmissionError(
462
+ "pending-capacity-exhausted",
463
+ "Pane-stream ticket capacity is exhausted.",
464
+ );
465
+ }
466
+
467
+ // The pane set is enumerated at issue: every requested pane must exist
468
+ // under verified semantic identity NOW. A describe failure is a probe
469
+ // failure and never reads as absence.
470
+ let described: MirrorSessionDescription;
471
+ let runtimeSessionId: string | null = null;
472
+ try {
473
+ const describeStartedAtMicros = trace ? this.#observability!.nowMicros() : 0;
474
+ if (this.#mirror.describeSessionAuthority) {
475
+ const authority = await this.#mirror.describeSessionAuthority(context.sessionName);
476
+ described = authority.description;
477
+ runtimeSessionId = authority.runtimeSessionId;
478
+ } else {
479
+ described = await this.#mirror.describeSession(context.sessionName);
480
+ }
481
+ if (trace)
482
+ this.#observability!.recordSpan(
483
+ "transport",
484
+ "pane-stream-describe-session",
485
+ describeStartedAtMicros,
486
+ this.#observability!.nowMicros(),
487
+ trace,
488
+ );
489
+ } catch {
490
+ throw new PaneStreamAdmissionError(
491
+ "stream-unavailable",
492
+ "The workspace session could not be described.",
493
+ );
494
+ }
495
+ const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
496
+ for (const pane of request.panes) {
497
+ if (!known.has(pane)) {
498
+ throw new PaneStreamAdmissionError(
499
+ "pane-not-found",
500
+ `The pane ${pane} is not present in the workspace session.`,
501
+ );
502
+ }
503
+ }
504
+
505
+ const issued = await this.#leaseManager.issue(request, {
506
+ requestId,
507
+ projectIdentity,
508
+ sessionName: context.sessionName,
509
+ ...(runtimeSessionId ? { runtimeSessionId } : {}),
510
+ ...(context.hostClientId ? { hostClientId: context.hostClientId } : {}),
511
+ });
512
+ const descriptor = issued.descriptor;
513
+ const ticket = issued.redemptionTicket;
514
+ const valid =
515
+ TicketPattern.test(ticket) &&
516
+ z.uuid().safeParse(descriptor.leaseId).success &&
517
+ descriptor.requestId === requestId &&
518
+ (this.#mirror.describeSessionAuthority === undefined ||
519
+ descriptor.runtimeSessionId === runtimeSessionId) &&
520
+ descriptor.status === "awaiting-redemption" &&
521
+ descriptor.viewerMode === request.viewerMode &&
522
+ descriptor.workspaceName === request.workspaceName &&
523
+ descriptor.panes.length === request.panes.length &&
524
+ descriptor.panes.every((pane, index) => pane === request.panes[index]) &&
525
+ descriptor.expiresAt > this.#now();
526
+ const ticketDigest = digestSecret(ticket);
527
+ const duplicate = [...this.#pending.values()].some((pending) =>
528
+ digestsEqual(pending.ticketDigest, ticketDigest),
529
+ );
530
+ if (!valid || duplicate) {
531
+ ticketDigest.fill(0);
532
+ await this.#releaseLease(descriptor.leaseId, {
533
+ daemonInstanceId: this.#instanceId,
534
+ requestId,
535
+ projectIdentity,
536
+ });
537
+ throw new PaneStreamAdmissionError(
538
+ "stream-unavailable",
539
+ "Pane-stream ticket generation failed.",
540
+ );
541
+ }
542
+ const pending: PendingTicket = {
543
+ leaseId: descriptor.leaseId,
544
+ requestId,
545
+ projectIdentity,
546
+ origin,
547
+ ticketDigest,
548
+ descriptor: structuredClone(descriptor),
549
+ cancelExpiry: null,
550
+ };
551
+ pending.cancelExpiry = this.#schedule(
552
+ () => {
553
+ void this.#exclusive(() => this.#retirePending(pending));
554
+ },
555
+ Math.max(1, descriptor.expiresAt - this.#now()),
556
+ );
557
+ this.#pending.set(pending.leaseId, pending);
558
+ if (trace)
559
+ this.#observability!.recordSpan(
560
+ "transport",
561
+ "pane-stream-issue-total",
562
+ admittedAtMicros,
563
+ this.#observability!.nowMicros(),
564
+ trace,
565
+ );
566
+ return Object.freeze({
567
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
568
+ webSocketUrl: this.#webSocketUrl,
569
+ redemptionTicket: ticket,
570
+ daemonInstanceId: this.#instanceId,
571
+ requestId,
572
+ expiresAt: descriptor.expiresAt,
573
+ panes: [...descriptor.panes],
574
+ effectiveViewerMode: descriptor.viewerMode,
575
+ });
576
+ });
577
+ }
578
+
579
+ reserveUpgrade(input: {
580
+ readonly path: string;
581
+ readonly protocols: readonly string[];
582
+ readonly origin: string | null | undefined;
583
+ readonly hostClientId?: string | undefined;
584
+ readonly requestId?: string | undefined;
585
+ }): PaneStreamUpgradeDecision {
586
+ if (this.#shuttingDown) {
587
+ return { accepted: false, code: "daemon-shutting-down", httpStatus: 503 };
588
+ }
589
+ if (input.path !== PANE_STREAM_REDEEM_PATH) {
590
+ return { accepted: false, code: "invalid-path", httpStatus: 404 };
591
+ }
592
+ if (input.protocols.length !== 1 || input.protocols[0] !== PANE_STREAM_WEBSOCKET_SUBPROTOCOL) {
593
+ return { accepted: false, code: "invalid-subprotocol", httpStatus: 426 };
594
+ }
595
+ const origin = canonicalOriginOrNull(input.origin ?? "");
596
+ if (origin === null) {
597
+ return { accepted: false, code: "invalid-origin", httpStatus: 403 };
598
+ }
599
+ const hostClientId = input.hostClientId
600
+ ? BindingIdSchemaZ.safeParse(input.hostClientId).data
601
+ : undefined;
602
+ if (input.hostClientId && !hostClientId) {
603
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
604
+ }
605
+ const requestId = input.requestId ? z.uuid().safeParse(input.requestId).data : undefined;
606
+ if (input.requestId && !requestId) {
607
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
608
+ }
609
+ if (
610
+ ![...this.#pending.values()].some(
611
+ (pending) =>
612
+ pending.origin === origin &&
613
+ (!requestId || pending.requestId === requestId) &&
614
+ (!hostClientId || pending.descriptor.hostClientId === hostClientId),
615
+ )
616
+ ) {
617
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
618
+ }
619
+ if (requestId && this.#observability?.enabled) {
620
+ const trace = this.#observability.beginTrace(
621
+ "pane-stream-connect",
622
+ { generation: this.#instanceId, incarnation: null },
623
+ requestId,
624
+ );
625
+ const atMicros = this.#observability.nowMicros();
626
+ this.#observability.recordSpan(
627
+ "transport",
628
+ "pane-stream-upgrade-arrival",
629
+ atMicros,
630
+ atMicros,
631
+ trace,
632
+ );
633
+ }
634
+ if (this.#preAuth.size >= this.#maxPreAuth) {
635
+ return { accepted: false, code: "preauth-capacity-exhausted", httpStatus: 503 };
636
+ }
637
+ const admission = new PreAuthAdmission({
638
+ origin,
639
+ hostClientId: hostClientId ?? null,
640
+ timeoutMs: this.#redemptionTimeoutMs,
641
+ schedule: this.#schedule,
642
+ onRelease: (released) => this.#preAuth.delete(released),
643
+ onRedeem: (active, frame, socket) => this.#redeem(active, frame, socket),
644
+ });
645
+ this.#preAuth.add(admission);
646
+ return { accepted: true, admission };
647
+ }
648
+
649
+ snapshot(): PaneStreamAdmissionSnapshot {
650
+ return Object.freeze({
651
+ pendingTickets: this.#pending.size,
652
+ preAuthSockets: this.#preAuth.size,
653
+ liveConnections: this.#live.size,
654
+ shuttingDown: this.#shuttingDown,
655
+ });
656
+ }
657
+
658
+ /** Detached (client x pane x owner) outstanding-ticket snapshot. */
659
+ flowSnapshot(): ReturnType<PaneStreamWireLedger["snapshot"]> {
660
+ return this.#ledger.snapshot();
661
+ }
662
+
663
+ shutdown(): Promise<void> {
664
+ if (this.#shutdownPromise) return this.#shutdownPromise;
665
+ this.#shuttingDown = true;
666
+ this.#shutdownPromise = this.#finishShutdown();
667
+ return this.#shutdownPromise;
668
+ }
669
+
670
+ async #finishShutdown(): Promise<void> {
671
+ for (const admission of [...this.#preAuth]) admission.close(1001, "daemon-shutdown");
672
+ await this.#exclusive(async () => {
673
+ for (const connection of [...this.#live]) connection.close(1001, "daemon-shutdown");
674
+ for (const pending of [...this.#pending.values()]) await this.#retirePending(pending);
675
+ });
676
+ await Promise.all([...this.#retiringReleases]);
677
+ }
678
+
679
+ #redeem(
680
+ admission: PreAuthAdmission,
681
+ frame: PaneStreamRedeemFrame,
682
+ socket: DirectTerminalSocket,
683
+ ): Promise<PaneStreamLiveConnection> {
684
+ // Stamp authenticated frame arrival BEFORE queueing: a queue wait must not
685
+ // consume the ticket's delivery TTL (execution has its own budget).
686
+ const receivedAt = this.#now();
687
+ return this.#exclusive(async () => {
688
+ if (this.#shuttingDown || frame.daemonInstanceId !== this.#instanceId) {
689
+ throw new PaneStreamAdmissionError(
690
+ "redemption-rejected",
691
+ "Pane-stream redemption was rejected.",
692
+ );
693
+ }
694
+ const candidateDigest = digestSecret(frame.ticket);
695
+ let pending: PendingTicket | undefined;
696
+ for (const entry of this.#pending.values()) {
697
+ if (digestsEqual(entry.ticketDigest, candidateDigest)) pending = entry;
698
+ }
699
+ candidateDigest.fill(0);
700
+ if (
701
+ !pending ||
702
+ pending.origin !== admission.origin ||
703
+ (admission.hostClientId !== null &&
704
+ pending.descriptor.hostClientId !== admission.hostClientId) ||
705
+ pending.requestId !== frame.requestId
706
+ ) {
707
+ throw new PaneStreamAdmissionError(
708
+ "redemption-rejected",
709
+ "Pane-stream redemption was rejected.",
710
+ );
711
+ }
712
+ const binding: PaneStreamLeaseBinding = {
713
+ daemonInstanceId: this.#instanceId,
714
+ requestId: pending.requestId,
715
+ projectIdentity: pending.projectIdentity,
716
+ };
717
+ if (!admission.isOpen()) {
718
+ this.#removePending(pending);
719
+ await this.#releaseLease(pending.leaseId, binding);
720
+ throw new PaneStreamAdmissionError(
721
+ "redemption-rejected",
722
+ "Pane-stream redemption was rejected.",
723
+ );
724
+ }
725
+ this.#removePending(pending);
726
+ if (this.#live.size >= this.#maxLive) {
727
+ await this.#releaseLease(pending.leaseId, binding);
728
+ throw new PaneStreamAdmissionError(
729
+ "live-capacity-exhausted",
730
+ "Pane-stream live capacity is exhausted.",
731
+ );
732
+ }
733
+ try {
734
+ const redeemed = await this.#leaseManager.redeem(frame.ticket, binding, receivedAt);
735
+ const descriptor = redeemed.descriptor;
736
+ if (descriptor.terminalDelivery && frame.deliveryAcks === true) {
737
+ throw new PaneStreamAdmissionError(
738
+ "stream-unavailable",
739
+ "Semantic terminal delivery owns its ACK lifecycle; legacy renderer ACKs are invalid.",
740
+ );
741
+ }
742
+ if (
743
+ descriptor.leaseId !== pending.leaseId ||
744
+ descriptor.requestId !== pending.requestId ||
745
+ descriptor.status !== "active" ||
746
+ descriptor.viewerMode !== pending.descriptor.viewerMode ||
747
+ descriptor.panes.length !== pending.descriptor.panes.length
748
+ ) {
749
+ throw new PaneStreamAdmissionError(
750
+ "stream-unavailable",
751
+ "Pane-stream lease identity was unavailable.",
752
+ );
753
+ }
754
+ if (!admission.isOpen()) {
755
+ throw new PaneStreamAdmissionError(
756
+ "redemption-rejected",
757
+ "Pane-stream redemption was rejected.",
758
+ );
759
+ }
760
+ this.#clientCounter += 1;
761
+ const sessionRuntimeBinding = this.#bindSessionRuntime?.(descriptor) ?? null;
762
+ let live: PaneStreamLiveConnection;
763
+ try {
764
+ live = new PaneStreamLiveConnection({
765
+ clientId: `psc-${this.#clientCounter}`,
766
+ socket,
767
+ descriptor: structuredClone(descriptor),
768
+ sessionRuntimeBinding,
769
+ binding,
770
+ deliveryAcks: frame.deliveryAcks === true,
771
+ diagnosticCapabilities: frame.diagnosticCapabilities ?? [],
772
+ causalCellCapability:
773
+ descriptor.terminalDelivery !== null &&
774
+ descriptor.viewerMode === "interactive" &&
775
+ frame.diagnosticCapabilities?.includes("causal-cell-v1") === true,
776
+ mirror: this.#mirror,
777
+ leaseManager: this.#leaseManager,
778
+ ledger: this.#ledger,
779
+ drainTickMs: this.#drainTickMs,
780
+ maxSocketBufferedBytes: this.#maxSocketBufferedBytes,
781
+ maxInputFrames: this.#maxInputFrames,
782
+ maxInputBytes: this.#maxInputBytes,
783
+ inputRateWindowMs: this.#inputRateWindowMs,
784
+ now: this.#now,
785
+ schedule: this.#schedule,
786
+ observability: this.#observability,
787
+ diagnosticSharedNowMicros: this.#diagnosticSharedNowMicros,
788
+ diagnosticAfterFrameParse: this.#diagnosticAfterFrameParse,
789
+ onRetire: (connection) => this.#trackRetiringRelease(connection),
790
+ });
791
+ } catch (error) {
792
+ await sessionRuntimeBinding?.close();
793
+ throw error;
794
+ }
795
+ this.#live.add(live);
796
+ admission.promote();
797
+ live.start();
798
+ return live;
799
+ } catch (error) {
800
+ await this.#releaseLease(pending.leaseId, binding);
801
+ throw error;
802
+ }
803
+ });
804
+ }
805
+
806
+ #removePending(pending: PendingTicket): void {
807
+ if (this.#pending.get(pending.leaseId) !== pending) return;
808
+ this.#pending.delete(pending.leaseId);
809
+ pending.cancelExpiry?.();
810
+ pending.cancelExpiry = null;
811
+ pending.ticketDigest.fill(0);
812
+ }
813
+
814
+ async #retirePending(pending: PendingTicket): Promise<void> {
815
+ if (this.#pending.get(pending.leaseId) !== pending) return;
816
+ const binding: PaneStreamLeaseBinding = {
817
+ daemonInstanceId: this.#instanceId,
818
+ requestId: pending.requestId,
819
+ projectIdentity: pending.projectIdentity,
820
+ };
821
+ this.#removePending(pending);
822
+ await this.#releaseLease(pending.leaseId, binding);
823
+ }
824
+
825
+ async #releaseLease(leaseId: string, binding: PaneStreamLeaseBinding): Promise<void> {
826
+ try {
827
+ await this.#leaseManager.release(leaseId, binding);
828
+ } catch {
829
+ // The lease manager may already have retired the one-use lease.
830
+ }
831
+ }
832
+
833
+ #trackRetiringRelease(connection: PaneStreamLiveConnection): void {
834
+ this.#live.delete(connection);
835
+ const release = connection.waitForRelease();
836
+ this.#retiringReleases.add(release);
837
+ void release.then(
838
+ () => this.#retiringReleases.delete(release),
839
+ () => this.#retiringReleases.delete(release),
840
+ );
841
+ }
842
+
843
+ #exclusive<T>(operation: () => Promise<T>): Promise<T> {
844
+ const run = this.#operationTail.then(operation, operation);
845
+ this.#operationTail = run.then(
846
+ () => undefined,
847
+ () => undefined,
848
+ );
849
+ return run;
850
+ }
851
+ }
852
+
853
+ interface PreAuthAdmissionOptions {
854
+ readonly origin: string;
855
+ readonly hostClientId: string | null;
856
+ readonly timeoutMs: number;
857
+ readonly schedule: (callback: () => void, delayMs: number) => () => void;
858
+ readonly onRelease: (admission: PreAuthAdmission) => void;
859
+ readonly onRedeem: (
860
+ admission: PreAuthAdmission,
861
+ frame: PaneStreamRedeemFrame,
862
+ socket: DirectTerminalSocket,
863
+ ) => Promise<PaneStreamLiveConnection>;
864
+ }
865
+
866
+ class PreAuthAdmission implements PaneStreamPreAuthAdmission {
867
+ readonly origin: string;
868
+ readonly hostClientId: string | null;
869
+ readonly #onRelease: PreAuthAdmissionOptions["onRelease"];
870
+ readonly #onRedeem: PreAuthAdmissionOptions["onRedeem"];
871
+ readonly #cancelDeadline: () => void;
872
+ #socket: DirectTerminalSocket | null = null;
873
+ #frameReceived = false;
874
+ #open = true;
875
+ #promoted = false;
876
+
877
+ constructor(options: PreAuthAdmissionOptions) {
878
+ this.origin = options.origin;
879
+ this.hostClientId = options.hostClientId;
880
+ this.#onRelease = options.onRelease;
881
+ this.#onRedeem = options.onRedeem;
882
+ this.#cancelDeadline = options.schedule(
883
+ () => this.close(1008, "redemption-timeout"),
884
+ options.timeoutMs,
885
+ );
886
+ }
887
+
888
+ isOpen(): boolean {
889
+ return this.#open && !this.#promoted;
890
+ }
891
+
892
+ bind(socket: DirectTerminalSocket): void {
893
+ if (!this.#open || this.#socket) {
894
+ safeCloseSocket(socket, 1008, "redemption-rejected");
895
+ return;
896
+ }
897
+ this.#socket = socket;
898
+ socket.on("message", this.#onMessage);
899
+ socket.on("close", this.#onClose);
900
+ socket.on("error", this.#onClose);
901
+ }
902
+
903
+ cancelBeforeBind(): void {
904
+ this.close(1008, "upgrade-rejected");
905
+ }
906
+
907
+ promote(): void {
908
+ if (!this.#open) return;
909
+ this.#promoted = true;
910
+ this.#open = false;
911
+ this.#cancelDeadline();
912
+ this.#detach();
913
+ this.#onRelease(this);
914
+ }
915
+
916
+ close(code = 1008, reason = "redemption-rejected"): void {
917
+ if (!this.#open) return;
918
+ this.#open = false;
919
+ this.#cancelDeadline();
920
+ const socket = this.#socket;
921
+ this.#detach();
922
+ this.#onRelease(this);
923
+ if (socket) safeCloseSocket(socket, code, reason);
924
+ }
925
+
926
+ readonly #onMessage = (
927
+ data: string | Buffer | ArrayBuffer | readonly Buffer[],
928
+ isBinary: boolean,
929
+ ): void => {
930
+ if (!this.#open || this.#frameReceived) {
931
+ this.close(1008, "redemption-frame-rejected");
932
+ return;
933
+ }
934
+ this.#frameReceived = true;
935
+ const byteLength = rawDataByteLength(data, PANE_STREAM_MAX_REDEMPTION_BYTES);
936
+ if (isBinary || byteLength === 0 || byteLength > PANE_STREAM_MAX_REDEMPTION_BYTES) {
937
+ this.close(1009, "redemption-frame-rejected");
938
+ return;
939
+ }
940
+ let frame: PaneStreamRedeemFrame;
941
+ try {
942
+ frame = PaneStreamRedeemFrameSchemaZ.parse(strictJsonParse(rawDataToBuffer(data)));
943
+ } catch {
944
+ this.close(1008, "redemption-frame-rejected");
945
+ return;
946
+ }
947
+ const socket = this.#socket;
948
+ if (!socket) {
949
+ this.close(1008, "redemption-rejected");
950
+ return;
951
+ }
952
+ this.#cancelDeadline();
953
+ void this.#onRedeem(this, frame, socket).catch((error: unknown) => {
954
+ if (!this.#open) return;
955
+ const code = errorFrameCode(error);
956
+ try {
957
+ sendControl(socket, {
958
+ type: "error",
959
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
960
+ code,
961
+ retryable: code === "live-capacity-exhausted" || code === "ticket-expired",
962
+ });
963
+ } catch {
964
+ // Closing below is the fail-closed response.
965
+ }
966
+ this.close(code === "live-capacity-exhausted" ? 1013 : 1008, "redemption-rejected");
967
+ });
968
+ };
969
+
970
+ readonly #onClose = (): void => this.close(1008, "redemption-rejected");
971
+
972
+ #detach(): void {
973
+ const socket = this.#socket;
974
+ this.#socket = null;
975
+ if (!socket) return;
976
+ socket.off("message", this.#onMessage);
977
+ socket.off("close", this.#onClose);
978
+ socket.off("error", this.#onClose);
979
+ }
980
+ }
981
+
982
+ interface LiveConnectionOptions {
983
+ readonly clientId: string;
984
+ readonly socket: DirectTerminalSocket;
985
+ readonly descriptor: PaneStreamLeaseDescriptor;
986
+ readonly sessionRuntimeBinding: SessionRuntimePaneStreamTransportBinding | null;
987
+ readonly binding: PaneStreamLeaseBinding;
988
+ readonly deliveryAcks: boolean;
989
+ readonly causalCellCapability: boolean;
990
+ readonly diagnosticCapabilities: readonly PaneStreamDiagnosticCapability[];
991
+ readonly mirror: PaneStreamMirror;
992
+ readonly leaseManager: PaneStreamLeaseAuthority;
993
+ readonly ledger: PaneStreamWireLedger;
994
+ readonly drainTickMs: number;
995
+ readonly maxSocketBufferedBytes: number;
996
+ readonly maxInputFrames: number;
997
+ readonly maxInputBytes: number;
998
+ readonly inputRateWindowMs: number;
999
+ readonly now: () => number;
1000
+ readonly schedule: (callback: () => void, delayMs: number) => () => void;
1001
+ readonly observability?: SessionRuntimeObservability;
1002
+ readonly diagnosticSharedNowMicros?: () => number;
1003
+ readonly diagnosticAfterFrameParse?: () => void;
1004
+ readonly onRetire: (connection: PaneStreamLiveConnection) => void;
1005
+ }
1006
+
1007
+ interface SeedBatch {
1008
+ reset: { cols: number; rows: number } | null;
1009
+ seed: Uint8Array | null;
1010
+ held: Uint8Array[];
1011
+ guardArmed: boolean;
1012
+ }
1013
+
1014
+ interface PaneChannel {
1015
+ readonly semanticPaneId: string;
1016
+ sub: MirrorSubscription | null;
1017
+ delivery: SessionRuntimeTerminalDeliveryConnection | null;
1018
+ deliveryAddress: {
1019
+ workspaceName: string;
1020
+ generation: string;
1021
+ incarnation: string | null;
1022
+ deliveryNonce: string;
1023
+ } | null;
1024
+ serverSeq: number;
1025
+ sentPaneFrames: number;
1026
+ consumedSeq: number;
1027
+ nextInputSeq: number;
1028
+ frozenByWire: boolean;
1029
+ closed: boolean;
1030
+ batch: SeedBatch | null;
1031
+ }
1032
+
1033
+ interface QueuedSend {
1034
+ readonly pane: string | null;
1035
+ remaining: number;
1036
+ }
1037
+
1038
+ export class PaneStreamLiveConnection {
1039
+ readonly #clientId: string;
1040
+ readonly #socket: DirectTerminalSocket;
1041
+ readonly #descriptor: PaneStreamLeaseDescriptor;
1042
+ readonly #binding: PaneStreamLeaseBinding;
1043
+ readonly #sessionRuntimeBinding: SessionRuntimePaneStreamTransportBinding | null;
1044
+ readonly #deliveryAcks: boolean;
1045
+ readonly #causalCellCapability: boolean;
1046
+ readonly #diagnosticCapabilities: readonly PaneStreamDiagnosticCapability[];
1047
+ readonly #mirror: PaneStreamMirror;
1048
+ readonly #leaseManager: PaneStreamLeaseAuthority;
1049
+ readonly #ledger: PaneStreamWireLedger;
1050
+ readonly #drainTickMs: number;
1051
+ readonly #maxSocketBufferedBytes: number;
1052
+ readonly #maxInputFrames: number;
1053
+ readonly #maxInputBytes: number;
1054
+ readonly #inputRateWindowMs: number;
1055
+ readonly #now: () => number;
1056
+ readonly #schedule: (callback: () => void, delayMs: number) => () => void;
1057
+ readonly #observability: SessionRuntimeObservability | undefined;
1058
+ readonly #diagnosticSharedRawMicros: (() => number) | undefined;
1059
+ readonly #diagnosticAfterFrameParse: (() => void) | undefined;
1060
+ readonly #onRetire: (connection: PaneStreamLiveConnection) => void;
1061
+ readonly #panes = new Map<string, PaneChannel>();
1062
+ readonly #semanticLayouts = new Map<string, MirrorLayoutEvent>();
1063
+ #semanticExpectedPaneIds: readonly string[] | null = null;
1064
+ #semanticRuntimeSessionId: string | null = null;
1065
+ #semanticTopologyEpoch = -1;
1066
+ readonly #sendQueue: QueuedSend[] = [];
1067
+ readonly #semanticDrainWaiters = new Map<string, Array<() => void>>();
1068
+ #layoutSubscription: MirrorLayoutSubscription | null = null;
1069
+ #sentBytesTotal = 0;
1070
+ #drainedBytesTotal = 0;
1071
+ #cancelDrainTick: (() => void) | null = null;
1072
+ #inputWindowStartedAt: number;
1073
+ #inputWindowFrames = 0;
1074
+ #inputWindowBytes = 0;
1075
+ #nextViewportSeq = 1;
1076
+ #nextClockProbe = 1;
1077
+ readonly #requestedAuthorities = new Set<SessionRuntimeAuthorityKind>();
1078
+ #usesExplicitAuthority = false;
1079
+ #legacyInputActivated = false;
1080
+ #legacyGeometryActivated = false;
1081
+ #closed = false;
1082
+ #releasePromise: Promise<unknown> | null = null;
1083
+ #stopAuthoritySnapshots: (() => void) | null = null;
1084
+ #sharedClockOriginMicros: number | null = null;
1085
+ #diagnosticFirstSeedObserved = false;
1086
+ readonly #diagnosticLifecycleStages: Set<string> | null;
1087
+
1088
+ #recordDiagnosticLifecycle(
1089
+ operation:
1090
+ | "pane-stream-server-ready"
1091
+ | "pane-stream-layout-staged"
1092
+ | "pane-stream-layout-validated"
1093
+ | "pane-stream-delivery-open"
1094
+ | "pane-stream-first-seed"
1095
+ | "pane-stream-terminal",
1096
+ closeCode?: number,
1097
+ closeReason?: string,
1098
+ ): void {
1099
+ if (!this.#observability?.enabled || !this.#diagnosticLifecycleStages) return;
1100
+ if (this.#diagnosticLifecycleStages.has(operation)) return;
1101
+ this.#diagnosticLifecycleStages.add(operation);
1102
+ const trace = this.#observability.beginTrace(
1103
+ "pane-stream-connect",
1104
+ { generation: this.#binding.daemonInstanceId, incarnation: null },
1105
+ this.#binding.requestId,
1106
+ );
1107
+ const atMicros = this.#observability.nowMicros();
1108
+ const legalReason = (
1109
+ new Set([
1110
+ "stream-retired",
1111
+ "stream-unavailable",
1112
+ "stream-closed",
1113
+ "topology-changed",
1114
+ "output-backpressure",
1115
+ "panes-closed",
1116
+ "peer-closed",
1117
+ "daemon-shutdown",
1118
+ "redemption-rejected",
1119
+ "unknown",
1120
+ ]).has(closeReason ?? "")
1121
+ ? closeReason!
1122
+ : closeReason
1123
+ ? "unknown"
1124
+ : "none"
1125
+ ) as
1126
+ | "none"
1127
+ | "stream-retired"
1128
+ | "stream-unavailable"
1129
+ | "stream-closed"
1130
+ | "topology-changed"
1131
+ | "output-backpressure"
1132
+ | "panes-closed"
1133
+ | "peer-closed"
1134
+ | "daemon-shutdown"
1135
+ | "redemption-rejected"
1136
+ | "unknown";
1137
+ this.#observability.recordSpan(
1138
+ "transport",
1139
+ operation,
1140
+ atMicros,
1141
+ atMicros,
1142
+ trace,
1143
+ undefined,
1144
+ Object.freeze({
1145
+ paneStreamCloseCode:
1146
+ Number.isInteger(closeCode) && closeCode! >= 1000 && closeCode! <= 4999 ? closeCode! : 0,
1147
+ paneStreamCloseReason: legalReason,
1148
+ }),
1149
+ );
1150
+ }
1151
+
1152
+ #sharedMicros(): number {
1153
+ const raw = this.#diagnosticSharedRawMicros!();
1154
+ this.#sharedClockOriginMicros ??= raw;
1155
+ const elapsed = raw - this.#sharedClockOriginMicros;
1156
+ if (!Number.isSafeInteger(elapsed) || elapsed < 0)
1157
+ throw new Error("Daemon shared monotonic clock regressed");
1158
+ return elapsed;
1159
+ }
1160
+
1161
+ constructor(options: LiveConnectionOptions) {
1162
+ this.#clientId = options.clientId;
1163
+ this.#socket = options.socket;
1164
+ this.#descriptor = options.descriptor;
1165
+ this.#binding = options.binding;
1166
+ this.#sessionRuntimeBinding = options.sessionRuntimeBinding;
1167
+ this.#usesExplicitAuthority = options.sessionRuntimeBinding?.explicitAuthority === true;
1168
+ if (this.#descriptor.viewerMode === "interactive" && !this.#sessionRuntimeBinding) {
1169
+ throw new Error("Interactive pane stream requires SessionRuntime authority");
1170
+ }
1171
+ this.#deliveryAcks = options.deliveryAcks;
1172
+ this.#causalCellCapability = options.causalCellCapability;
1173
+ this.#diagnosticCapabilities = options.diagnosticCapabilities;
1174
+ this.#mirror = options.mirror;
1175
+ this.#leaseManager = options.leaseManager;
1176
+ this.#ledger = options.ledger;
1177
+ this.#drainTickMs = options.drainTickMs;
1178
+ this.#maxSocketBufferedBytes = options.maxSocketBufferedBytes;
1179
+ this.#maxInputFrames = options.maxInputFrames;
1180
+ this.#maxInputBytes = options.maxInputBytes;
1181
+ this.#inputRateWindowMs = options.inputRateWindowMs;
1182
+ this.#now = options.now;
1183
+ this.#inputWindowStartedAt = this.#now();
1184
+ this.#schedule = options.schedule;
1185
+ this.#observability = options.observability;
1186
+ this.#diagnosticLifecycleStages = options.observability?.enabled ? new Set() : null;
1187
+ this.#diagnosticSharedRawMicros = this.#diagnosticCapabilities.includes("clock-bounds-v1")
1188
+ ? (options.diagnosticSharedNowMicros ?? sharedMonotonicMicros)
1189
+ : undefined;
1190
+ this.#diagnosticAfterFrameParse = options.diagnosticAfterFrameParse;
1191
+ this.#onRetire = options.onRetire;
1192
+ for (const pane of options.descriptor.panes) {
1193
+ this.#panes.set(pane, {
1194
+ semanticPaneId: pane,
1195
+ sub: null,
1196
+ delivery: null,
1197
+ deliveryAddress: null,
1198
+ serverSeq: 0,
1199
+ sentPaneFrames: 0,
1200
+ consumedSeq: 0,
1201
+ nextInputSeq: 1,
1202
+ frozenByWire: false,
1203
+ closed: false,
1204
+ batch: null,
1205
+ });
1206
+ }
1207
+ }
1208
+
1209
+ get clientId(): string {
1210
+ return this.#clientId;
1211
+ }
1212
+
1213
+ start(): void {
1214
+ if (this.#closed || this.#socket.readyState !== WS_OPEN) {
1215
+ this.close(1008, "stream-retired");
1216
+ return;
1217
+ }
1218
+ this.#socket.on("message", this.#onMessage);
1219
+ this.#socket.on("close", this.#onSocketClose);
1220
+ this.#socket.on("error", this.#onSocketClose);
1221
+ try {
1222
+ sendControl(this.#socket, {
1223
+ type: "ready",
1224
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
1225
+ daemonInstanceId: this.#binding.daemonInstanceId,
1226
+ requestId: this.#binding.requestId,
1227
+ ...(this.#sessionRuntimeBinding
1228
+ ? { connectionClientId: this.#sessionRuntimeBinding.clientId }
1229
+ : {}),
1230
+ panes: [...this.#descriptor.panes],
1231
+ effectiveViewerMode: this.#descriptor.viewerMode,
1232
+ ...(this.#diagnosticCapabilities.length > 0
1233
+ ? { diagnosticCapabilities: [...this.#diagnosticCapabilities] }
1234
+ : {}),
1235
+ });
1236
+ this.#recordDiagnosticLifecycle("pane-stream-server-ready");
1237
+ } catch {
1238
+ this.close(1011, "stream-unavailable-describe");
1239
+ return;
1240
+ }
1241
+ this.#stopAuthoritySnapshots =
1242
+ this.#sessionRuntimeBinding?.onAuthoritySnapshot?.((snapshot) =>
1243
+ this.#usesExplicitAuthority ? this.#sendAuthoritySnapshot(snapshot) : undefined,
1244
+ ) ?? null;
1245
+ void this.#subscribeAll();
1246
+ }
1247
+
1248
+ close(code = 1000, reason = "stream-closed"): void {
1249
+ if (this.#closed) return;
1250
+ this.#recordDiagnosticLifecycle("pane-stream-terminal", code, reason);
1251
+ this.#closed = true;
1252
+ this.#cancelDrainTick?.();
1253
+ this.#cancelDrainTick = null;
1254
+ // Departure force-returns every ticket within this same tick.
1255
+ this.#ledger.forceReturnClient(this.#clientId);
1256
+ this.#sendQueue.length = 0;
1257
+ for (const waiters of this.#semanticDrainWaiters.values())
1258
+ for (const resolve of waiters) resolve();
1259
+ this.#semanticDrainWaiters.clear();
1260
+ this.#socket.off("message", this.#onMessage);
1261
+ this.#socket.off("close", this.#onSocketClose);
1262
+ this.#socket.off("error", this.#onSocketClose);
1263
+ this.#stopAuthoritySnapshots?.();
1264
+ this.#stopAuthoritySnapshots = null;
1265
+ const closures: Promise<unknown>[] = [];
1266
+ const layoutSubscription = this.#layoutSubscription;
1267
+ this.#layoutSubscription = null;
1268
+ if (layoutSubscription) closures.push(layoutSubscription.close().catch(() => undefined));
1269
+ for (const channel of this.#panes.values()) {
1270
+ const sub = channel.sub;
1271
+ channel.sub = null;
1272
+ const delivery = channel.delivery;
1273
+ channel.delivery = null;
1274
+ channel.closed = true;
1275
+ if (sub) closures.push(sub.close().catch(() => undefined));
1276
+ if (delivery) closures.push(delivery.close().catch(() => undefined));
1277
+ }
1278
+ this.#releasePromise = Promise.allSettled([
1279
+ ...closures,
1280
+ this.#leaseManager.release(this.#descriptor.leaseId, this.#binding).catch(() => undefined),
1281
+ this.#sessionRuntimeBinding?.close() ?? Promise.resolve(),
1282
+ ]);
1283
+ this.#onRetire(this);
1284
+ safeCloseSocket(this.#socket, code, reason);
1285
+ }
1286
+
1287
+ async waitForRelease(): Promise<void> {
1288
+ await this.#releasePromise;
1289
+ }
1290
+
1291
+ /** TESTS ONLY — run one drain evaluation without waiting for the tick. */
1292
+ drainNowForTest(): void {
1293
+ this.#drainNow();
1294
+ }
1295
+
1296
+ async #subscribeAll(): Promise<void> {
1297
+ // Fresh truth once for the whole set: a pane listed at issue but gone by
1298
+ // redeem gets an honest `closed` frame (a successful describe omitting it
1299
+ // is absence; a describe FAILURE is not and fails the connection).
1300
+ let described: MirrorSessionDescription;
1301
+ try {
1302
+ described = await this.#mirror.describeSession(this.#descriptor.sessionName);
1303
+ } catch {
1304
+ this.close(1011, "stream-unavailable");
1305
+ return;
1306
+ }
1307
+ if (this.#closed) return;
1308
+ const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
1309
+ if (this.#descriptor.terminalDelivery) {
1310
+ await this.#subscribeSemantic(known);
1311
+ return;
1312
+ }
1313
+ if (this.#mirror.subscribeLayout) {
1314
+ try {
1315
+ const layoutSubscription = await this.#mirror.subscribeLayout(
1316
+ this.#descriptor.sessionName,
1317
+ (event) => this.#onLayout(event),
1318
+ );
1319
+ if (this.#closed) {
1320
+ await layoutSubscription.close().catch(() => undefined);
1321
+ return;
1322
+ }
1323
+ this.#layoutSubscription = layoutSubscription;
1324
+ } catch {
1325
+ this.close(1011, "stream-unavailable");
1326
+ return;
1327
+ }
1328
+ }
1329
+ let layoutAttached = this.#layoutSubscription !== null;
1330
+ for (const channel of this.#panes.values()) {
1331
+ if (this.#closed) return;
1332
+ if (!known.has(channel.semanticPaneId)) {
1333
+ this.#emitClosed(channel);
1334
+ continue;
1335
+ }
1336
+ try {
1337
+ const sub = await this.#mirror.subscribe({
1338
+ session: this.#descriptor.sessionName,
1339
+ semanticPaneId: channel.semanticPaneId,
1340
+ onEvent: (event) => this.#onPaneEvent(channel, event),
1341
+ ...(layoutAttached ? {} : { onLayout: (event) => this.#onLayout(event) }),
1342
+ });
1343
+ layoutAttached = true;
1344
+ if (this.#closed || channel.closed) {
1345
+ void sub.close().catch(() => undefined);
1346
+ continue;
1347
+ }
1348
+ channel.sub = sub;
1349
+ } catch {
1350
+ this.close(1011, "stream-unavailable");
1351
+ return;
1352
+ }
1353
+ }
1354
+ this.#closeIfAllPanesGone();
1355
+ }
1356
+
1357
+ async #subscribeSemantic(known: ReadonlySet<string>): Promise<void> {
1358
+ const binding = this.#sessionRuntimeBinding;
1359
+ const offer = this.#descriptor.terminalDelivery;
1360
+ if (!binding || !offer) {
1361
+ this.close(1011, "stream-unavailable");
1362
+ return;
1363
+ }
1364
+ const expectedPaneIds = [...this.#descriptor.panes].sort();
1365
+ if (expectedPaneIds.some((pane) => !known.has(pane))) {
1366
+ this.#failTopologyChanged();
1367
+ return;
1368
+ }
1369
+ const channels = [...this.#panes.values()];
1370
+ if (this.#closed || channels.length === 0) return;
1371
+ let stagedAuthority: MirrorLayoutAuthoritySnapshot | null = null;
1372
+ let authorityMalformed = false;
1373
+ let layoutActivated = false;
1374
+ // Establish the single session layout observer first. MirrorService owns
1375
+ // this lifecycle and may share native control state with delivery setup;
1376
+ // only the independent pane delivery opens below are parallelized.
1377
+ try {
1378
+ if (!this.#mirror.subscribeLayout) throw new Error("authoritative layout is unavailable");
1379
+ const subscription = await this.#mirror.subscribeLayout(
1380
+ this.#descriptor.sessionName,
1381
+ () => undefined,
1382
+ {
1383
+ expectedSemanticPaneIds: expectedPaneIds,
1384
+ expectedRuntimeSessionId: this.#descriptor.runtimeSessionId!,
1385
+ onAuthority: (snapshot) => {
1386
+ this.#recordDiagnosticLifecycle("pane-stream-layout-staged");
1387
+ if (snapshot.layouts.length > PANE_STREAM_MAX_PANES) authorityMalformed = true;
1388
+ else if (!layoutActivated) stagedAuthority = snapshot;
1389
+ else this.#onLayoutAuthority(snapshot);
1390
+ },
1391
+ },
1392
+ );
1393
+ if (this.#closed) {
1394
+ await subscription.close().catch(() => undefined);
1395
+ return;
1396
+ }
1397
+ const authority = stagedAuthority as MirrorLayoutAuthoritySnapshot | null;
1398
+ const stagedInitialFrames =
1399
+ authorityMalformed ||
1400
+ authority === null ||
1401
+ authority.session !== this.#descriptor.sessionName ||
1402
+ this.#descriptor.runtimeSessionId === null ||
1403
+ authority.runtimeSessionId !== this.#descriptor.runtimeSessionId ||
1404
+ authority.topologyEpoch < 0
1405
+ ? null
1406
+ : this.#validateInitialLayout(authority.layouts, expectedPaneIds);
1407
+ if (!stagedInitialFrames) {
1408
+ await subscription.close().catch(() => undefined);
1409
+ this.#failTopologyChanged();
1410
+ return;
1411
+ }
1412
+ this.#layoutSubscription = subscription;
1413
+ } catch (cause) {
1414
+ if (cause instanceof Error && cause.name === "MirrorTopologyChangedError") {
1415
+ this.#failTopologyChanged();
1416
+ return;
1417
+ }
1418
+ this.close(1011, "stream-unavailable");
1419
+ return;
1420
+ }
1421
+
1422
+ // Delivery owners are pane-scoped and independent. Open them concurrently,
1423
+ // then publish in descriptor order only after every pane is coherent. This
1424
+ // removes N x attachment latency without allowing a fast pane to make the
1425
+ // session look ready while a sibling is still missing. allSettled is
1426
+ // deliberate: partial success is always closed before the socket retires.
1427
+ const openings = channels.map(async (channel) => {
1428
+ const pending: TerminalDeliveryServerMessage[] = [];
1429
+ let ready = false;
1430
+ const delivery = await binding.openTerminalDelivery(
1431
+ channel.semanticPaneId,
1432
+ offer,
1433
+ (message) => {
1434
+ if (!ready) pending.push(message);
1435
+ else return this.#sendTerminalDelivery(channel.semanticPaneId, message);
1436
+ },
1437
+ );
1438
+ return {
1439
+ channel,
1440
+ delivery,
1441
+ pending,
1442
+ markReady: () => {
1443
+ ready = true;
1444
+ },
1445
+ };
1446
+ });
1447
+ const settled = await Promise.allSettled(openings);
1448
+ const opened = settled.flatMap((result) =>
1449
+ result.status === "fulfilled" ? [result.value] : [],
1450
+ );
1451
+ if (
1452
+ this.#closed ||
1453
+ settled.some(
1454
+ (result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted,
1455
+ )
1456
+ ) {
1457
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1458
+ if (!this.#closed) this.close(1011, "stream-unavailable");
1459
+ return;
1460
+ }
1461
+
1462
+ const deliveryIdentityChanged = opened.some(({ channel, delivery, pending }) => {
1463
+ if (!delivery.negotiation.accepted) return true;
1464
+ const negotiated = delivery.negotiation.negotiated;
1465
+ if (negotiated.generation !== this.#binding.daemonInstanceId) return true;
1466
+ let incarnation: string | null = null;
1467
+ for (const message of pending) {
1468
+ if (message.type !== "terminal.delivery") continue;
1469
+ if (
1470
+ message.workspaceName !== this.#descriptor.sessionName ||
1471
+ message.semanticPaneId !== channel.semanticPaneId ||
1472
+ message.generation !== negotiated.generation ||
1473
+ message.deliveryNonce !== negotiated.deliveryNonce ||
1474
+ (incarnation !== null && message.incarnation !== incarnation)
1475
+ )
1476
+ return true;
1477
+ incarnation = message.incarnation;
1478
+ }
1479
+ return false;
1480
+ });
1481
+ if (deliveryIdentityChanged) {
1482
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1483
+ this.#failTopologyChanged();
1484
+ return;
1485
+ }
1486
+
1487
+ const authority = stagedAuthority as MirrorLayoutAuthoritySnapshot | null;
1488
+ const initialFrames =
1489
+ authorityMalformed ||
1490
+ authority === null ||
1491
+ authority.session !== this.#descriptor.sessionName ||
1492
+ this.#descriptor.runtimeSessionId === null ||
1493
+ authority.runtimeSessionId !== this.#descriptor.runtimeSessionId ||
1494
+ authority.topologyEpoch < 0
1495
+ ? null
1496
+ : this.#validateInitialLayout(authority.layouts, expectedPaneIds);
1497
+ if (!initialFrames) {
1498
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1499
+ this.#failTopologyChanged();
1500
+ return;
1501
+ }
1502
+ this.#recordDiagnosticLifecycle("pane-stream-layout-validated");
1503
+ this.#semanticExpectedPaneIds = expectedPaneIds;
1504
+ this.#semanticRuntimeSessionId = authority!.runtimeSessionId;
1505
+ this.#semanticTopologyEpoch = authority!.topologyEpoch;
1506
+ this.#semanticLayouts.clear();
1507
+ for (const event of authority!.layouts)
1508
+ this.#semanticLayouts.set(event.semanticWindowId as string, event);
1509
+ this.#sendFrame(null, {
1510
+ type: "layout-snapshot",
1511
+ topologyEpoch: authority!.topologyEpoch,
1512
+ layouts: initialFrames,
1513
+ });
1514
+ layoutActivated = true;
1515
+ this.#recordDiagnosticLifecycle("pane-stream-delivery-open");
1516
+
1517
+ for (const { channel, delivery, pending, markReady } of opened) {
1518
+ if (this.#closed || channel.closed) {
1519
+ await delivery.close();
1520
+ continue;
1521
+ }
1522
+ // The rejected case was eliminated above; retain this narrowing at the
1523
+ // publication boundary so an invalid negotiation cannot leak a nonce.
1524
+ if (!delivery.negotiation.accepted) continue;
1525
+ channel.delivery = delivery;
1526
+ channel.deliveryAddress = {
1527
+ workspaceName: this.#descriptor.workspaceName,
1528
+ generation: delivery.negotiation.negotiated.generation,
1529
+ incarnation: null,
1530
+ deliveryNonce: delivery.negotiation.negotiated.deliveryNonce,
1531
+ };
1532
+ this.#sendFrame(null, {
1533
+ type: "terminal-delivery-ready",
1534
+ pane: channel.semanticPaneId,
1535
+ negotiation: delivery.negotiation,
1536
+ });
1537
+ markReady();
1538
+ for (const message of pending)
1539
+ await this.#sendTerminalDelivery(channel.semanticPaneId, message);
1540
+ }
1541
+ this.#closeIfAllPanesGone();
1542
+ }
1543
+
1544
+ async #sendTerminalDelivery(pane: string, message: TerminalDeliveryServerMessage): Promise<void> {
1545
+ if (message.type === "terminal.delivery") {
1546
+ if (!this.#diagnosticFirstSeedObserved) {
1547
+ this.#diagnosticFirstSeedObserved = true;
1548
+ this.#recordDiagnosticLifecycle("pane-stream-first-seed");
1549
+ }
1550
+ const channel = this.#panes.get(pane);
1551
+ if (channel?.deliveryAddress) channel.deliveryAddress.incarnation = message.incarnation;
1552
+ // SessionRuntime keys canonical replicas by the tmux session, while the
1553
+ // public pane-stream lease is keyed by its workspace identity. Translate
1554
+ // at this boundary so the renderer has one coherent address vocabulary.
1555
+ const detailedDeliveryObservation = this.#observability?.enabled === true;
1556
+ const trace =
1557
+ message.performanceTraceId && detailedDeliveryObservation
1558
+ ? this.#observability!.beginTrace(
1559
+ "terminal-input-to-paint",
1560
+ { generation: message.generation, incarnation: message.incarnation },
1561
+ message.performanceTraceId,
1562
+ )
1563
+ : null;
1564
+ let startedAtMicros: number | null = null;
1565
+ if (detailedDeliveryObservation)
1566
+ try {
1567
+ startedAtMicros = this.#observability!.nowMicros();
1568
+ } catch {
1569
+ // Detailed delivery timing cannot alter socket delivery.
1570
+ }
1571
+ let startedAtSharedMicros: number | null = null;
1572
+ if (startedAtMicros !== null && this.#diagnosticSharedRawMicros) {
1573
+ try {
1574
+ startedAtSharedMicros = this.#sharedMicros();
1575
+ } catch {
1576
+ // Shared-clock diagnostics cannot alter terminal delivery.
1577
+ }
1578
+ }
1579
+ this.#sendFrame(pane, {
1580
+ type: "terminal-delivery-envelope",
1581
+ pane,
1582
+ envelope: { ...message, workspaceName: this.#descriptor.workspaceName },
1583
+ });
1584
+ if (startedAtMicros !== null) {
1585
+ let endedAtMicros: number;
1586
+ try {
1587
+ endedAtMicros = this.#observability!.nowMicros();
1588
+ } catch {
1589
+ return;
1590
+ }
1591
+ let endedAtSharedMicros: number | null = null;
1592
+ if (startedAtSharedMicros !== null) {
1593
+ try {
1594
+ endedAtSharedMicros = this.#sharedMicros();
1595
+ } catch {
1596
+ // Preserve the process-local span when shared sampling fails.
1597
+ }
1598
+ }
1599
+ try {
1600
+ this.#observability!.recordSpan(
1601
+ "transport",
1602
+ "pane-stream-socket-send",
1603
+ startedAtMicros,
1604
+ endedAtMicros,
1605
+ trace,
1606
+ startedAtSharedMicros === null || endedAtSharedMicros === null
1607
+ ? undefined
1608
+ : {
1609
+ startedAtMicros: startedAtSharedMicros,
1610
+ endedAtMicros: endedAtSharedMicros,
1611
+ },
1612
+ Object.freeze({
1613
+ workspaceName: message.workspaceName,
1614
+ semanticPaneId: message.semanticPaneId,
1615
+ canonicalGeneration: message.generation,
1616
+ canonicalIncarnation: message.incarnation,
1617
+ canonicalRevision: message.canonicalRevision,
1618
+ canonicalStateHash: message.canonicalStateHash,
1619
+ transactionId: message.transactionId,
1620
+ ...(terminalDeliveryObservationOrdinal(message) === null
1621
+ ? {}
1622
+ : { deliveryOrdinal: terminalDeliveryObservationOrdinal(message)! }),
1623
+ deliveryClientId: this.#sessionRuntimeBinding?.clientId ?? this.#clientId,
1624
+ deliverySurface: this.#sessionRuntimeBinding?.surface ?? "unknown",
1625
+ deliveryLaneId: this.#sessionRuntimeBinding?.deliveryLaneId ?? this.#clientId,
1626
+ deliveryRequestId: this.#sessionRuntimeBinding?.deliveryRequestId ?? this.#clientId,
1627
+ deliveryNonce: message.deliveryNonce,
1628
+ }),
1629
+ );
1630
+ } catch {
1631
+ // Diagnostics cannot alter terminal delivery.
1632
+ }
1633
+ }
1634
+ } else if (message.type === "terminal.delivery.chunk") {
1635
+ this.#sendFrame(pane, {
1636
+ type: "terminal-delivery-chunk",
1637
+ pane,
1638
+ transactionId: message.transactionId,
1639
+ index: message.index,
1640
+ data: Buffer.from(message.bytes).toString("base64"),
1641
+ });
1642
+ } else {
1643
+ this.#sendFrame(pane, { type: "terminal-delivery-fault", pane, fault: message });
1644
+ // Lifecycle/control truth must never queue behind bulk terminal bytes.
1645
+ // The hard socket-wide ceiling still closes a genuinely wedged client in
1646
+ // #drainNow; a source-close frame itself is small and immediately useful.
1647
+ return;
1648
+ }
1649
+ await this.#awaitSemanticCredit(pane);
1650
+ }
1651
+
1652
+ #awaitSemanticCredit(pane: string): Promise<void> {
1653
+ // Backpressure is pane-local. Aggregate pressure is guarded by the hard
1654
+ // socket ceiling in #drainNow, but must not let a noisy sibling prevent a
1655
+ // pane-close (or any other pane's next semantic delivery) from surfacing.
1656
+ if (!this.#ledger.isStalled(this.#clientId, pane)) return Promise.resolve();
1657
+ return new Promise((resolve) => {
1658
+ const waiters = this.#semanticDrainWaiters.get(pane) ?? [];
1659
+ waiters.push(resolve);
1660
+ this.#semanticDrainWaiters.set(pane, waiters);
1661
+ this.#ensureDrainTick();
1662
+ });
1663
+ }
1664
+
1665
+ // ── Mirror events → frames ────────────────────────────────────────────────
1666
+
1667
+ #onPaneEvent(channel: PaneChannel, event: MirrorPaneEvent): void {
1668
+ if (this.#closed || channel.closed) return;
1669
+ switch (event.type) {
1670
+ case "reset": {
1671
+ channel.batch = {
1672
+ reset: { cols: event.cols, rows: event.rows },
1673
+ seed: null,
1674
+ held: [],
1675
+ guardArmed: false,
1676
+ };
1677
+ this.#armBatchGuard(channel);
1678
+ return;
1679
+ }
1680
+ case "seed": {
1681
+ if (channel.batch) channel.batch.seed = event.data;
1682
+ else {
1683
+ channel.batch = { reset: null, seed: event.data, held: [], guardArmed: false };
1684
+ this.#armBatchGuard(channel);
1685
+ }
1686
+ return;
1687
+ }
1688
+ case "delta": {
1689
+ const batch = channel.batch;
1690
+ if (batch && batch.seed !== null) {
1691
+ batch.held.push(event.data);
1692
+ return;
1693
+ }
1694
+ if (batch) {
1695
+ // A delta cannot precede the capture of an armed reseed (the feed
1696
+ // discards those); treat an impossible ordering as live output.
1697
+ this.#flushBatch(channel, null);
1698
+ }
1699
+ this.#emitOutput(channel, event.data);
1700
+ return;
1701
+ }
1702
+ case "cursor": {
1703
+ if (channel.batch) {
1704
+ this.#flushBatch(channel, { x: event.x, y: event.y });
1705
+ return;
1706
+ }
1707
+ this.#sendPaneFrame(channel, {
1708
+ type: "cursor",
1709
+ pane: channel.semanticPaneId,
1710
+ seq: this.#nextSeq(channel),
1711
+ x: event.x,
1712
+ y: event.y,
1713
+ });
1714
+ return;
1715
+ }
1716
+ case "flow": {
1717
+ if (channel.batch) this.#flushBatch(channel, null);
1718
+ this.#sendPaneFrame(channel, {
1719
+ type: "flow",
1720
+ pane: channel.semanticPaneId,
1721
+ seq: this.#nextSeq(channel),
1722
+ state: event.state,
1723
+ reason: event.reason,
1724
+ });
1725
+ return;
1726
+ }
1727
+ case "closed": {
1728
+ if (channel.batch) this.#flushBatch(channel, null);
1729
+ this.#emitClosed(channel);
1730
+ this.#closeIfAllPanesGone();
1731
+ return;
1732
+ }
1733
+ }
1734
+ }
1735
+
1736
+ /** The atomic batch arrives in ONE synchronous callback burst; a microtask
1737
+ * guard flushes the degraded no-cursor path without reordering anything. */
1738
+ #armBatchGuard(channel: PaneChannel): void {
1739
+ const batch = channel.batch;
1740
+ if (!batch || batch.guardArmed) return;
1741
+ batch.guardArmed = true;
1742
+ queueMicrotask(() => {
1743
+ if (channel.batch === batch) this.#flushBatch(channel, null);
1744
+ });
1745
+ }
1746
+
1747
+ #flushBatch(channel: PaneChannel, cursor: { x: number; y: number } | null): void {
1748
+ const batch = channel.batch;
1749
+ channel.batch = null;
1750
+ if (!batch || this.#closed || channel.closed) return;
1751
+ let seed = batch.seed ?? new Uint8Array(0);
1752
+ if (seed.byteLength > PANE_STREAM_MAX_SEED_BYTES) {
1753
+ // Pathological guard: keep the tail, resynchronizing at a line seam.
1754
+ let start = seed.byteLength - PANE_STREAM_MAX_SEED_BYTES;
1755
+ while (start < seed.byteLength && seed[start] !== 0x0a) start += 1;
1756
+ seed = seed.subarray(Math.min(start + 1, seed.byteLength));
1757
+ }
1758
+ const held = chunkBytes(concatBytes(batch.held), PANE_STREAM_MAX_OUTPUT_BYTES).slice(
1759
+ 0,
1760
+ PANE_STREAM_MAX_HELD_DELTAS,
1761
+ );
1762
+ this.#sendPaneFrame(channel, {
1763
+ type: "seed-batch",
1764
+ pane: channel.semanticPaneId,
1765
+ seq: this.#nextSeq(channel),
1766
+ reset: batch.reset,
1767
+ seed: Buffer.from(seed).toString("base64"),
1768
+ held: held.map((chunk) => Buffer.from(chunk).toString("base64")),
1769
+ cursor,
1770
+ });
1771
+ }
1772
+
1773
+ #emitOutput(channel: PaneChannel, data: Uint8Array): void {
1774
+ for (const chunk of chunkBytes(data, PANE_STREAM_MAX_OUTPUT_BYTES)) {
1775
+ this.#sendPaneFrame(channel, {
1776
+ type: "output",
1777
+ pane: channel.semanticPaneId,
1778
+ seq: this.#nextSeq(channel),
1779
+ data: Buffer.from(chunk).toString("base64"),
1780
+ });
1781
+ }
1782
+ }
1783
+
1784
+ #emitClosed(channel: PaneChannel): void {
1785
+ if (channel.closed) return;
1786
+ channel.closed = true;
1787
+ const sub = channel.sub;
1788
+ channel.sub = null;
1789
+ if (sub) void sub.close().catch(() => undefined);
1790
+ this.#sendPaneFrame(channel, {
1791
+ type: "closed",
1792
+ pane: channel.semanticPaneId,
1793
+ seq: this.#nextSeq(channel),
1794
+ });
1795
+ this.#ledger.forgetPane(this.#clientId, channel.semanticPaneId);
1796
+ }
1797
+
1798
+ #onLayoutAuthority(snapshot: MirrorLayoutAuthoritySnapshot): void {
1799
+ if (this.#closed || !this.#semanticExpectedPaneIds || !this.#semanticRuntimeSessionId) return;
1800
+ if (
1801
+ snapshot.session !== this.#descriptor.sessionName ||
1802
+ snapshot.runtimeSessionId !== this.#semanticRuntimeSessionId ||
1803
+ snapshot.topologyEpoch <= this.#semanticTopologyEpoch ||
1804
+ snapshot.layouts.length > PANE_STREAM_MAX_PANES
1805
+ ) {
1806
+ this.#failTopologyChanged();
1807
+ return;
1808
+ }
1809
+ const frames = this.#validateInitialLayout(snapshot.layouts, this.#semanticExpectedPaneIds);
1810
+ if (!frames) {
1811
+ this.#failTopologyChanged();
1812
+ return;
1813
+ }
1814
+ this.#semanticTopologyEpoch = snapshot.topologyEpoch;
1815
+ this.#semanticLayouts.clear();
1816
+ for (const event of snapshot.layouts)
1817
+ this.#semanticLayouts.set(event.semanticWindowId as string, event);
1818
+ this.#sendFrame(null, {
1819
+ type: "layout-snapshot",
1820
+ topologyEpoch: snapshot.topologyEpoch,
1821
+ layouts: frames,
1822
+ });
1823
+ }
1824
+
1825
+ #onLayout(event: MirrorLayoutEvent): void {
1826
+ if (this.#closed) return;
1827
+ /*
1828
+ * Every window of the session, not only the leased panes' own.
1829
+ *
1830
+ * The lease is SESSION-scoped by design — one socket for one workspace —
1831
+ * and layout is that session's geometry rather than a per-pane stream. A
1832
+ * client that saw only its leased window could not render a window LIST at
1833
+ * all, which is what the layout-faithful view is built from (m50), and it
1834
+ * would have to lease every pane in the session to get one.
1835
+ *
1836
+ * Nothing new crosses the boundary: the frame carries semantic pane ids and
1837
+ * cell rectangles, and the same renderer is already told every pane's
1838
+ * semantic identity by the application-shell inventory. No runtime tmux id,
1839
+ * command, cwd or credential appears here.
1840
+ */
1841
+ const frame = this.#layoutFrame(event);
1842
+ if (!frame) {
1843
+ this.#failTopologyChanged();
1844
+ return;
1845
+ }
1846
+ this.#sendFrame(null, frame);
1847
+ }
1848
+
1849
+ #layoutFrame(event: MirrorLayoutEvent): PaneStreamServerFrame | null {
1850
+ const frame = {
1851
+ type: "layout",
1852
+ semanticWindowId: event.semanticWindowId,
1853
+ windowName: event.windowName === null ? null : event.windowName.slice(0, 256),
1854
+ currentWindow: event.currentWindow,
1855
+ cols: event.cols,
1856
+ rows: event.rows,
1857
+ zoomed: event.zoomed,
1858
+ paneBorderStatus: event.paneBorderStatus,
1859
+ panes: event.panes.map((pane) => ({
1860
+ pane: pane.semanticPaneId,
1861
+ displayName: pane.displayName,
1862
+ displayNameSource: pane.displayNameSource,
1863
+ left: pane.left,
1864
+ top: pane.top,
1865
+ width: pane.width,
1866
+ height: pane.height,
1867
+ active: pane.active,
1868
+ })),
1869
+ };
1870
+ // Layout carries user-authored names and unbounded tmux geometry; gate it
1871
+ // through the schema and skip rather than ever sending an invalid frame.
1872
+ const parsed = PaneStreamServerFrameSchemaZ.safeParse(frame);
1873
+ return parsed.success ? parsed.data : null;
1874
+ }
1875
+
1876
+ #validateInitialLayout(
1877
+ events: readonly MirrorLayoutEvent[],
1878
+ expectedPaneIds: readonly string[],
1879
+ ): PaneStreamServerFrame[] | null {
1880
+ if (events.length === 0) return null;
1881
+ const windows = new Set<string>();
1882
+ const panes: string[] = [];
1883
+ const frames: PaneStreamServerFrame[] = [];
1884
+ let currentWindows = 0;
1885
+ for (const event of events) {
1886
+ if (
1887
+ event.session !== this.#descriptor.sessionName ||
1888
+ typeof event.semanticWindowId !== "string" ||
1889
+ windows.has(event.semanticWindowId)
1890
+ )
1891
+ return null;
1892
+ windows.add(event.semanticWindowId);
1893
+ if (event.currentWindow) currentWindows += 1;
1894
+ const frame = this.#layoutFrame(event);
1895
+ if (!frame || frame.type !== "layout") return null;
1896
+ frames.push(frame);
1897
+ for (const pane of event.panes) {
1898
+ if (typeof pane.semanticPaneId !== "string") return null;
1899
+ panes.push(pane.semanticPaneId);
1900
+ }
1901
+ }
1902
+ panes.sort();
1903
+ if (
1904
+ currentWindows !== 1 ||
1905
+ new Set(panes).size !== panes.length ||
1906
+ panes.length !== expectedPaneIds.length ||
1907
+ panes.some((pane, index) => pane !== expectedPaneIds[index])
1908
+ )
1909
+ return null;
1910
+ return frames;
1911
+ }
1912
+
1913
+ #failTopologyChanged(): void {
1914
+ if (this.#closed) return;
1915
+ this.#sendFrame(null, {
1916
+ type: "error",
1917
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
1918
+ code: "topology-changed",
1919
+ retryable: true,
1920
+ });
1921
+ this.close(1012, "topology-changed");
1922
+ }
1923
+
1924
+ // ── Send path + flow ledger ───────────────────────────────────────────────
1925
+
1926
+ #nextSeq(channel: PaneChannel): number {
1927
+ channel.serverSeq += 1;
1928
+ return channel.serverSeq;
1929
+ }
1930
+
1931
+ #sendPaneFrame(channel: PaneChannel, frame: Record<string, unknown>): void {
1932
+ channel.sentPaneFrames += 1;
1933
+ this.#sendFrame(channel.semanticPaneId, frame);
1934
+ }
1935
+
1936
+ #sendFrame(pane: string | null, frame: Record<string, unknown>): void {
1937
+ if (this.#closed || this.#socket.readyState !== WS_OPEN) return;
1938
+ const encoded = JSON.stringify(frame);
1939
+ const bytes = Buffer.byteLength(encoded, "utf8");
1940
+ if (pane !== null) {
1941
+ this.#ledger.take(this.#clientId, pane, "ws-send-buffer", bytes);
1942
+ if (this.#deliveryAcks) this.#ledger.take(this.#clientId, pane, "renderer-backlog", 1);
1943
+ }
1944
+ this.#sendQueue.push({ pane, remaining: bytes });
1945
+ this.#sentBytesTotal += bytes;
1946
+ try {
1947
+ this.#socket.send(encoded, { binary: false });
1948
+ } catch {
1949
+ this.close(1011, "stream-unavailable");
1950
+ return;
1951
+ }
1952
+ // Stall is judged on the drain tick, never synchronously at send: the
1953
+ // socket must get its chance to drain first, or a single seed batch
1954
+ // larger than the budget would park even a healthy client.
1955
+ this.#ensureDrainTick();
1956
+ }
1957
+
1958
+ #evaluateStall(pane: string): void {
1959
+ const channel = this.#panes.get(pane);
1960
+ if (!channel || channel.closed || channel.frozenByWire || !channel.sub) return;
1961
+ if (this.#ledger.isStalled(this.#clientId, pane)) {
1962
+ // Park exactly this subscriber: siblings and other clients keep flowing;
1963
+ // upstream %pause only engages when every subscriber of the pane parks.
1964
+ channel.frozenByWire = true;
1965
+ channel.sub.freeze();
1966
+ }
1967
+ }
1968
+
1969
+ #evaluateResume(pane: string): void {
1970
+ const channel = this.#panes.get(pane);
1971
+ if (!channel || channel.closed || !channel.frozenByWire || !channel.sub) return;
1972
+ if (this.#ledger.shouldResume(this.#clientId, pane)) {
1973
+ channel.frozenByWire = false;
1974
+ channel.sub.thaw();
1975
+ }
1976
+ }
1977
+
1978
+ #ensureDrainTick(): void {
1979
+ if (this.#cancelDrainTick || this.#closed || this.#sendQueue.length === 0) return;
1980
+ this.#cancelDrainTick = this.#schedule(() => {
1981
+ this.#cancelDrainTick = null;
1982
+ this.#drainNow();
1983
+ this.#ensureDrainTick();
1984
+ }, this.#drainTickMs);
1985
+ }
1986
+
1987
+ #drainNow(): void {
1988
+ if (this.#closed) return;
1989
+ const buffered = this.#socket.bufferedAmount ?? 0;
1990
+ if (!Number.isSafeInteger(buffered) || buffered < 0) {
1991
+ this.close(1011, "stream-unavailable");
1992
+ return;
1993
+ }
1994
+ if (buffered > this.#maxSocketBufferedBytes) {
1995
+ this.close(1013, "output-backpressure");
1996
+ return;
1997
+ }
1998
+ let newlyDrained = this.#sentBytesTotal - buffered - this.#drainedBytesTotal;
1999
+ while (newlyDrained > 0 && this.#sendQueue.length > 0) {
2000
+ const head = this.#sendQueue[0]!;
2001
+ const applied = Math.min(newlyDrained, head.remaining);
2002
+ head.remaining -= applied;
2003
+ newlyDrained -= applied;
2004
+ this.#drainedBytesTotal += applied;
2005
+ if (head.pane !== null) {
2006
+ this.#ledger.give(this.#clientId, head.pane, "ws-send-buffer", applied);
2007
+ }
2008
+ if (head.remaining === 0) this.#sendQueue.shift();
2009
+ }
2010
+ for (const [pane, channel] of this.#panes) {
2011
+ if (channel.frozenByWire) this.#evaluateResume(pane);
2012
+ else this.#evaluateStall(pane);
2013
+ const waiters = this.#semanticDrainWaiters.get(pane);
2014
+ if (waiters && this.#ledger.shouldResume(this.#clientId, pane)) {
2015
+ this.#semanticDrainWaiters.delete(pane);
2016
+ for (const resolve of waiters) resolve();
2017
+ }
2018
+ }
2019
+ }
2020
+
2021
+ // ── Client frames ─────────────────────────────────────────────────────────
2022
+
2023
+ readonly #onMessage = (
2024
+ data: string | Buffer | ArrayBuffer | readonly Buffer[],
2025
+ isBinary: boolean,
2026
+ ): void => {
2027
+ if (this.#closed) return;
2028
+ let callbackAtSharedMicros: number | null = null;
2029
+ let ingressAtSharedMicros: number | null = null;
2030
+ let ingressAtMicros: number | null = null;
2031
+ if (this.#observability?.enabled) {
2032
+ try {
2033
+ ingressAtMicros = this.#observability.nowMicros();
2034
+ } catch {
2035
+ // Diagnostics cannot alter protocol truth.
2036
+ }
2037
+ }
2038
+ const byteLength = rawDataByteLength(data, PANE_STREAM_MAX_CONTROL_BYTES);
2039
+ if (isBinary || byteLength === 0 || byteLength > PANE_STREAM_MAX_CONTROL_BYTES) {
2040
+ this.#failProtocol("protocol-error");
2041
+ return;
2042
+ }
2043
+ const raw = rawDataToBuffer(data);
2044
+ if (this.#diagnosticSharedRawMicros && hasCanonicalInputFramePrefix(raw)) {
2045
+ try {
2046
+ callbackAtSharedMicros = this.#sharedMicros();
2047
+ } catch {
2048
+ // Preserve the process-local callback timestamp and product traffic.
2049
+ }
2050
+ }
2051
+ let frame: z.infer<typeof PaneStreamClientFrameSchemaZ>;
2052
+ try {
2053
+ frame = PaneStreamClientFrameSchemaZ.parse(strictJsonParse(raw));
2054
+ } catch {
2055
+ this.#failProtocol("protocol-error");
2056
+ return;
2057
+ }
2058
+ if (this.#diagnosticSharedRawMicros) {
2059
+ try {
2060
+ this.#diagnosticAfterFrameParse?.();
2061
+ } catch {
2062
+ // Test-only diagnostics cannot alter protocol truth.
2063
+ }
2064
+ if (frame.type === "input") {
2065
+ try {
2066
+ ingressAtSharedMicros = this.#sharedMicros();
2067
+ } catch {
2068
+ // Preserve callback timing and product traffic without a parse-complete sample.
2069
+ }
2070
+ }
2071
+ }
2072
+ if (frame.type === "clock-probe") {
2073
+ if (
2074
+ !this.#diagnosticCapabilities.includes("clock-bounds-v1") ||
2075
+ frame.requestId !== this.#binding.requestId ||
2076
+ frame.probe !== this.#nextClockProbe
2077
+ )
2078
+ return this.#failProtocol("protocol-error");
2079
+ this.#nextClockProbe += 1;
2080
+ try {
2081
+ ingressAtSharedMicros = this.#sharedMicros();
2082
+ } catch {
2083
+ return;
2084
+ }
2085
+ try {
2086
+ const daemonSendMicros = this.#sharedMicros();
2087
+ this.#sendFrame(null, {
2088
+ type: "clock-probe-ack",
2089
+ requestId: this.#binding.requestId,
2090
+ daemonInstanceId: this.#binding.daemonInstanceId,
2091
+ probe: frame.probe,
2092
+ clientSendMicros: frame.clientSendMicros,
2093
+ daemonReceiveMicros: ingressAtSharedMicros,
2094
+ daemonSendMicros,
2095
+ });
2096
+ } catch {
2097
+ // Client timeout reports calibration unavailable; product traffic continues.
2098
+ }
2099
+ return;
2100
+ }
2101
+ if (frame.type === "consumed") {
2102
+ this.#acceptConsumed(frame.pane, frame.seq);
2103
+ return;
2104
+ }
2105
+ if (frame.type === "presence") {
2106
+ if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2107
+ this.#usesExplicitAuthority = true;
2108
+ if (!this.#sessionRuntimeBinding?.updatePresence) return this.#failProtocol("protocol-error");
2109
+ const snapshot = this.#sessionRuntimeBinding.updatePresence(frame.state);
2110
+ if (!this.#sessionRuntimeBinding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
2111
+ return;
2112
+ }
2113
+ if (frame.type === "activity") {
2114
+ if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2115
+ this.#usesExplicitAuthority = true;
2116
+ if (!this.#sessionRuntimeBinding?.noteActivity) return this.#failProtocol("protocol-error");
2117
+ const snapshot = this.#sessionRuntimeBinding.noteActivity(frame.activity);
2118
+ if (!this.#sessionRuntimeBinding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
2119
+ return;
2120
+ }
2121
+ if (frame.type === "authority-request") {
2122
+ if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2123
+ this.#usesExplicitAuthority = true;
2124
+ if (
2125
+ !this.#sessionRuntimeBinding?.requestAuthority ||
2126
+ !this.#sessionRuntimeBinding.authoritySnapshot
2127
+ )
2128
+ return this.#failProtocol("protocol-error");
2129
+ const lease = this.#sessionRuntimeBinding.requestAuthority(frame.authority);
2130
+ if (lease) this.#requestedAuthorities.add(frame.authority);
2131
+ this.#sendFrame(null, {
2132
+ type: "authority-receipt",
2133
+ requestId: frame.requestId,
2134
+ authority: frame.authority,
2135
+ status: lease ? "granted" : "rejected",
2136
+ lease,
2137
+ snapshot: this.#sessionRuntimeBinding.authoritySnapshot(),
2138
+ });
2139
+ return;
2140
+ }
2141
+ if (frame.type === "authority-release") {
2142
+ if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2143
+ this.#usesExplicitAuthority = true;
2144
+ this.#requestedAuthorities.delete(frame.authority);
2145
+ if (!this.#sessionRuntimeBinding?.releaseAuthority)
2146
+ return this.#failProtocol("protocol-error");
2147
+ const snapshot = this.#sessionRuntimeBinding.releaseAuthority(frame.authority);
2148
+ this.#sendFrame(null, {
2149
+ type: "authority-receipt",
2150
+ requestId: frame.requestId,
2151
+ authority: frame.authority,
2152
+ status: "released",
2153
+ lease: null,
2154
+ snapshot,
2155
+ });
2156
+ return;
2157
+ }
2158
+ if (frame.type === "terminal-delivery-ack") {
2159
+ const channel = this.#deliveryChannel(frame.ack);
2160
+ if (!channel) return;
2161
+ channel.delivery!.ack({ ...frame.ack, workspaceName: this.#descriptor.sessionName });
2162
+ return;
2163
+ }
2164
+ if (frame.type === "terminal-delivery-nack") {
2165
+ const channel = this.#deliveryChannel(frame.nack);
2166
+ if (!channel) return;
2167
+ channel.delivery!.nack({ ...frame.nack, workspaceName: this.#descriptor.sessionName });
2168
+ return;
2169
+ }
2170
+ if (frame.type === "terminal-delivery-visibility") {
2171
+ const channel = this.#deliveryChannel({
2172
+ workspaceName: frame.workspaceName,
2173
+ semanticPaneId: frame.pane,
2174
+ generation: frame.generation,
2175
+ incarnation: frame.incarnation,
2176
+ deliveryNonce: frame.deliveryNonce,
2177
+ });
2178
+ if (!channel) return;
2179
+ channel.delivery!.setVisibility(frame.visibility);
2180
+ return;
2181
+ }
2182
+ if (frame.type === "semantic-intent") {
2183
+ this.#acceptSemanticIntent(frame.operationId, frame.intent);
2184
+ return;
2185
+ }
2186
+ if (frame.type === "viewport") {
2187
+ if (
2188
+ !this.#descriptor.terminalDelivery ||
2189
+ this.#descriptor.viewerMode !== "interactive" ||
2190
+ frame.seq !== this.#nextViewportSeq ||
2191
+ (this.#usesExplicitAuthority && !this.#requestedAuthorities.has("geometry"))
2192
+ ) {
2193
+ this.#failProtocol("input-rejected");
2194
+ return;
2195
+ }
2196
+ if (!this.#prepareInputAuthority(true)) return;
2197
+ this.#nextViewportSeq += 1;
2198
+ try {
2199
+ this.#sessionRuntimeBinding!.fitViewport(frame.authorityLease, frame.cols, frame.rows);
2200
+ this.#sendFrame(null, {
2201
+ type: "viewport-ack",
2202
+ seq: frame.seq,
2203
+ cols: frame.cols,
2204
+ rows: frame.rows,
2205
+ outcome: "ok",
2206
+ authorityLease: frame.authorityLease,
2207
+ });
2208
+ } catch (error) {
2209
+ if (
2210
+ error instanceof SessionRuntimeControllerLeaseError &&
2211
+ (error.code === "invalid-client-capability" || error.code === "stale-controller-lease")
2212
+ ) {
2213
+ this.#sendFrame(null, {
2214
+ type: "viewport-ack",
2215
+ seq: frame.seq,
2216
+ cols: frame.cols,
2217
+ rows: frame.rows,
2218
+ outcome: "geometry-authority-conflict",
2219
+ authorityLease: frame.authorityLease,
2220
+ });
2221
+ return;
2222
+ }
2223
+ this.#failProtocol("input-rejected");
2224
+ }
2225
+ return;
2226
+ }
2227
+ this.#acceptInput(
2228
+ frame.pane,
2229
+ frame.seq,
2230
+ frame.kind,
2231
+ frame.data,
2232
+ byteLength,
2233
+ frame.performanceTraceId,
2234
+ frame.causalProbe,
2235
+ ingressAtMicros,
2236
+ callbackAtSharedMicros,
2237
+ ingressAtSharedMicros,
2238
+ );
2239
+ };
2240
+
2241
+ #acceptAuthorityGeneration(generation: string): boolean {
2242
+ if (!this.#sessionRuntimeBinding || generation !== this.#sessionRuntimeBinding.generation) {
2243
+ this.#failProtocol("protocol-error");
2244
+ return false;
2245
+ }
2246
+ return true;
2247
+ }
2248
+
2249
+ #sendAuthoritySnapshot(snapshot: SessionRuntimeAuthoritySnapshot): void {
2250
+ this.#sendFrame(null, { type: "authority-snapshot", snapshot });
2251
+ }
2252
+
2253
+ #prepareInputAuthority(geometry: boolean): boolean {
2254
+ if (this.#usesExplicitAuthority) {
2255
+ const required = geometry ? "geometry" : "input";
2256
+ if (!this.#requestedAuthorities.has(required)) {
2257
+ this.#failProtocol("input-rejected");
2258
+ return false;
2259
+ }
2260
+ return true;
2261
+ }
2262
+ if (this.#legacyInputActivated && (!geometry || this.#legacyGeometryActivated)) return true;
2263
+ try {
2264
+ // A genuine old binding acquired at admission and has no adapter method.
2265
+ // New deferred bindings activate only here, before explicit mode exists.
2266
+ this.#sessionRuntimeBinding?.activateLegacyAuthority?.(geometry);
2267
+ this.#legacyInputActivated = true;
2268
+ if (geometry) this.#legacyGeometryActivated = true;
2269
+ return true;
2270
+ } catch {
2271
+ this.#failProtocol("input-rejected");
2272
+ return false;
2273
+ }
2274
+ }
2275
+
2276
+ #deliveryChannel(address: {
2277
+ workspaceName: string;
2278
+ semanticPaneId: string;
2279
+ generation: string;
2280
+ incarnation: string;
2281
+ deliveryNonce: string;
2282
+ }): PaneChannel | null {
2283
+ const channel = this.#panes.get(address.semanticPaneId);
2284
+ const expected = channel?.deliveryAddress;
2285
+ if (
2286
+ !channel?.delivery ||
2287
+ !expected ||
2288
+ expected.workspaceName !== address.workspaceName ||
2289
+ expected.generation !== address.generation ||
2290
+ expected.deliveryNonce !== address.deliveryNonce ||
2291
+ expected.incarnation === null
2292
+ ) {
2293
+ this.#failProtocol("protocol-error");
2294
+ return null;
2295
+ }
2296
+ // More than one canonical delivery can legitimately be in flight. The
2297
+ // cached address records only the newest incarnation, so comparing an ACK
2298
+ // against that single value rejects an earlier valid delivery during a
2299
+ // reseed/reconnect burst. Generation + one-use delivery nonce identify the
2300
+ // channel here; the retained delivery owner validates incarnation,
2301
+ // transaction and revision ordering authoritatively below.
2302
+ return channel;
2303
+ }
2304
+
2305
+ #acceptSemanticIntent(operationId: string, intent: SessionRuntimeSemanticIntent): void {
2306
+ if (!this.#descriptor.terminalDelivery || this.#descriptor.viewerMode !== "interactive") {
2307
+ this.#failProtocol("input-rejected");
2308
+ return;
2309
+ }
2310
+ if (!this.#prepareInputAuthority(false)) return;
2311
+ void this.#sessionRuntimeBinding!.submitIntent(operationId, intent)
2312
+ .then((result) => {
2313
+ this.#sendFrame(null, {
2314
+ type: "semantic-intent-ack",
2315
+ operationId,
2316
+ outcome: { status: "applied", result: result ?? null },
2317
+ });
2318
+ })
2319
+ .catch((error: unknown) => {
2320
+ const backendRefusal = semanticBackendRefusal(error);
2321
+ const rawCode =
2322
+ backendRefusal ??
2323
+ (error && typeof error === "object" && "code" in error
2324
+ ? String(error.code)
2325
+ : error && typeof error === "object" && "outcome" in error
2326
+ ? `intent-${String(error.outcome)}`
2327
+ : "stream-unavailable");
2328
+ const code = [
2329
+ "controller-conflict",
2330
+ "controller-target-unavailable",
2331
+ "stale-controller-lease",
2332
+ "invalid-client-capability",
2333
+ "invalid-source-pane-binding",
2334
+ "intent-session-mismatch",
2335
+ "intent-rejected",
2336
+ "intent-timed-out",
2337
+ "pane_inventory_not_ready",
2338
+ "pane_identity_changed_before_select",
2339
+ "pane_not_active",
2340
+ ].includes(rawCode)
2341
+ ? rawCode
2342
+ : "stream-unavailable";
2343
+ this.#sendFrame(null, {
2344
+ type: "semantic-intent-ack",
2345
+ operationId,
2346
+ outcome: {
2347
+ status: "rejected",
2348
+ code,
2349
+ message:
2350
+ error instanceof Error ? error.message.slice(0, 512) : "Semantic intent failed",
2351
+ },
2352
+ });
2353
+ });
2354
+ }
2355
+
2356
+ #acceptConsumed(pane: string, seq: number): void {
2357
+ const channel = this.#panes.get(pane);
2358
+ if (
2359
+ !this.#deliveryAcks ||
2360
+ !channel ||
2361
+ seq <= channel.consumedSeq ||
2362
+ seq > channel.sentPaneFrames
2363
+ ) {
2364
+ this.#failProtocol("protocol-error");
2365
+ return;
2366
+ }
2367
+ const returned = seq - channel.consumedSeq;
2368
+ channel.consumedSeq = seq;
2369
+ this.#ledger.give(this.#clientId, pane, "renderer-backlog", returned);
2370
+ this.#evaluateResume(pane);
2371
+ }
2372
+
2373
+ #acceptInput(
2374
+ pane: string,
2375
+ seq: number,
2376
+ kind: "text" | "key",
2377
+ data: string,
2378
+ frameBytes: number,
2379
+ performanceTraceId?: string,
2380
+ causalProbe?: CausalCellProbeV1,
2381
+ ingressAtMicros: number | null = null,
2382
+ callbackAtSharedMicros: number | null = null,
2383
+ ingressAtSharedMicros: number | null = null,
2384
+ ): void {
2385
+ if (this.#descriptor.viewerMode !== "interactive") {
2386
+ this.#failProtocol("input-rejected");
2387
+ return;
2388
+ }
2389
+ const channel = this.#panes.get(pane);
2390
+ const semanticDelivery = this.#descriptor.terminalDelivery !== null;
2391
+ if (
2392
+ !channel ||
2393
+ channel.closed ||
2394
+ (semanticDelivery ? !channel.delivery : !channel.sub) ||
2395
+ seq !== channel.nextInputSeq
2396
+ ) {
2397
+ this.#failProtocol("input-rejected");
2398
+ return;
2399
+ }
2400
+ if (causalProbe) {
2401
+ const address = channel.deliveryAddress;
2402
+ if (
2403
+ !this.#causalCellCapability ||
2404
+ !address ||
2405
+ causalProbe.clientId !== this.#sessionRuntimeBinding?.clientId ||
2406
+ causalProbe.transportNonce !== this.#binding.requestId ||
2407
+ causalProbe.deliveryNonce !== address.deliveryNonce ||
2408
+ causalProbe.inputSequence !== seq ||
2409
+ causalProbe.semanticPaneId !== pane ||
2410
+ causalProbe.generation !== address.generation ||
2411
+ causalProbe.incarnation !== address.incarnation
2412
+ ) {
2413
+ this.#failProtocol("input-rejected");
2414
+ return;
2415
+ }
2416
+ }
2417
+ const now = this.#now();
2418
+ if (
2419
+ now < this.#inputWindowStartedAt ||
2420
+ now - this.#inputWindowStartedAt >= this.#inputRateWindowMs
2421
+ ) {
2422
+ this.#inputWindowStartedAt = now;
2423
+ this.#inputWindowFrames = 0;
2424
+ this.#inputWindowBytes = 0;
2425
+ }
2426
+ if (
2427
+ this.#inputWindowFrames + 1 > this.#maxInputFrames ||
2428
+ this.#inputWindowBytes + frameBytes > this.#maxInputBytes
2429
+ ) {
2430
+ this.#failProtocol("input-rejected");
2431
+ return;
2432
+ }
2433
+ if (!this.#prepareInputAuthority(false)) return;
2434
+ let trace: ReturnType<SessionRuntimeObservability["beginTrace"]> = null;
2435
+ if (performanceTraceId && this.#observability?.enabled) {
2436
+ try {
2437
+ trace = this.#observability.beginTrace(
2438
+ "terminal-input-to-paint",
2439
+ {
2440
+ generation: this.#sessionRuntimeBinding!.generation,
2441
+ incarnation: causalProbe?.incarnation ?? channel.deliveryAddress?.incarnation ?? null,
2442
+ },
2443
+ performanceTraceId,
2444
+ );
2445
+ if (trace && ingressAtMicros !== null) {
2446
+ this.#observability.recordSpan(
2447
+ "transport",
2448
+ "pane-stream-socket-message-callback-entry",
2449
+ ingressAtMicros,
2450
+ ingressAtMicros,
2451
+ trace,
2452
+ callbackAtSharedMicros === null
2453
+ ? undefined
2454
+ : {
2455
+ startedAtMicros: callbackAtSharedMicros,
2456
+ endedAtMicros: callbackAtSharedMicros,
2457
+ },
2458
+ );
2459
+ this.#observability.recordSpan(
2460
+ "transport",
2461
+ "pane-stream-input-frame-ingress",
2462
+ ingressAtMicros,
2463
+ ingressAtMicros,
2464
+ trace,
2465
+ ingressAtSharedMicros === null
2466
+ ? undefined
2467
+ : { startedAtMicros: ingressAtSharedMicros, endedAtMicros: ingressAtSharedMicros },
2468
+ );
2469
+ }
2470
+ } catch {
2471
+ trace = null;
2472
+ }
2473
+ }
2474
+ this.#inputWindowFrames += 1;
2475
+ this.#inputWindowBytes += frameBytes;
2476
+ channel.nextInputSeq += 1;
2477
+ try {
2478
+ this.#sessionRuntimeBinding!.assertController(pane);
2479
+ if (semanticDelivery)
2480
+ this.#sessionRuntimeBinding!.sendInput(
2481
+ pane,
2482
+ { kind, data },
2483
+ performanceTraceId,
2484
+ causalProbe,
2485
+ causalProbe
2486
+ ? (result) => {
2487
+ if (this.#closed) return;
2488
+ if (result.status === "proved") {
2489
+ this.#sendFrame(null, { type: "causal-cell-proof", proof: result.proof });
2490
+ } else {
2491
+ this.#sendFrame(null, {
2492
+ type: "causal-cell-failure",
2493
+ failure: {
2494
+ version: 1,
2495
+ capability: "causal-cell-v1",
2496
+ traceId: result.traceId,
2497
+ reason: result.reason,
2498
+ ...(result.diagnostic ? { diagnostic: result.diagnostic } : {}),
2499
+ },
2500
+ });
2501
+ }
2502
+ }
2503
+ : undefined,
2504
+ );
2505
+ else if (kind === "text") channel.sub!.sendText(data);
2506
+ else channel.sub!.sendKey(data);
2507
+ let ackStartedAtMicros: number | null = null;
2508
+ let ackStartedAtSharedMicros: number | null = null;
2509
+ if (trace) {
2510
+ try {
2511
+ ackStartedAtMicros = this.#observability!.nowMicros();
2512
+ } catch {
2513
+ // Diagnostics cannot alter protocol truth.
2514
+ }
2515
+ if (this.#diagnosticSharedRawMicros) {
2516
+ try {
2517
+ ackStartedAtSharedMicros = this.#sharedMicros();
2518
+ } catch {
2519
+ // Preserve process-local ACK diagnostics.
2520
+ }
2521
+ }
2522
+ }
2523
+ sendControl(this.#socket, { type: "input-ack", pane, seq });
2524
+ if (trace && ackStartedAtMicros !== null) {
2525
+ let ackEndedAtMicros: number | null = null;
2526
+ try {
2527
+ ackEndedAtMicros = this.#observability!.nowMicros();
2528
+ } catch {
2529
+ // Diagnostics cannot alter protocol truth.
2530
+ }
2531
+ let ackEndedAtSharedMicros: number | null = null;
2532
+ if (ackStartedAtSharedMicros !== null) {
2533
+ try {
2534
+ ackEndedAtSharedMicros = this.#sharedMicros();
2535
+ } catch {
2536
+ // Preserve process-local ACK diagnostics.
2537
+ }
2538
+ }
2539
+ if (ackEndedAtMicros !== null) {
2540
+ try {
2541
+ this.#observability!.recordSpan(
2542
+ "transport",
2543
+ "pane-stream-input-ack-socket-send",
2544
+ ackStartedAtMicros,
2545
+ ackEndedAtMicros,
2546
+ trace,
2547
+ ackStartedAtSharedMicros === null || ackEndedAtSharedMicros === null
2548
+ ? undefined
2549
+ : {
2550
+ startedAtMicros: ackStartedAtSharedMicros,
2551
+ endedAtMicros: ackEndedAtSharedMicros,
2552
+ },
2553
+ );
2554
+ } catch {
2555
+ // Diagnostics cannot alter protocol truth.
2556
+ }
2557
+ }
2558
+ }
2559
+ } catch {
2560
+ this.close(1011, "stream-unavailable");
2561
+ }
2562
+ }
2563
+
2564
+ #failProtocol(code: PaneStreamErrorFrameCode): void {
2565
+ try {
2566
+ sendControl(this.#socket, {
2567
+ type: "error",
2568
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
2569
+ code,
2570
+ retryable: false,
2571
+ });
2572
+ } catch {
2573
+ this.close(1011, "stream-unavailable");
2574
+ return;
2575
+ }
2576
+ this.close(1008, code);
2577
+ }
2578
+
2579
+ #closeIfAllPanesGone(): void {
2580
+ if (this.#closed) return;
2581
+ for (const channel of this.#panes.values()) {
2582
+ if (!channel.closed) return;
2583
+ }
2584
+ this.close(1000, "panes-closed");
2585
+ }
2586
+
2587
+ readonly #onSocketClose = (): void => this.close(1000, "peer-closed");
2588
+ }
2589
+
2590
+ function concatBytes(chunks: readonly Uint8Array[]): Uint8Array {
2591
+ if (chunks.length === 0) return new Uint8Array(0);
2592
+ if (chunks.length === 1) return chunks[0]!;
2593
+ let total = 0;
2594
+ for (const chunk of chunks) total += chunk.byteLength;
2595
+ const merged = new Uint8Array(total);
2596
+ let offset = 0;
2597
+ for (const chunk of chunks) {
2598
+ merged.set(chunk, offset);
2599
+ offset += chunk.byteLength;
2600
+ }
2601
+ return merged;
2602
+ }
2603
+
2604
+ function chunkBytes(data: Uint8Array, maxChunk: number): Uint8Array[] {
2605
+ if (data.byteLength === 0) return [];
2606
+ if (data.byteLength <= maxChunk) return [data];
2607
+ const chunks: Uint8Array[] = [];
2608
+ for (let offset = 0; offset < data.byteLength; offset += maxChunk) {
2609
+ chunks.push(data.subarray(offset, Math.min(offset + maxChunk, data.byteLength)));
2610
+ }
2611
+ return chunks;
2612
+ }