tmux-ide 2.7.0 → 2.9.0-beta.11

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