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,2067 @@
1
+ import { z } from "zod";
2
+ import { PANE_STREAM_MAX_HELD_DELTAS, PANE_STREAM_MAX_OUTPUT_BYTES, PANE_STREAM_MAX_PANES, PANE_STREAM_MAX_SEED_BYTES, PANE_STREAM_PROTOCOL_VERSION, PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL, PaneStreamClientFrameSchemaZ, PaneStreamLoopbackWebSocketUrlSchemaZ, PaneStreamRedeemFrameSchemaZ, PaneStreamServerFrameSchemaZ, sharedMonotonicMicros, } from "@tmux-ide/contracts";
3
+ import { canonicalOriginOrNull, digestSecret, digestsEqual, rawDataByteLength, rawDataToBuffer, safeCloseSocket, strictJsonParse, } from "../attachments/admission-util.js";
4
+ import { SessionRuntimeControllerLeaseError } from "../session-runtime/registry.js";
5
+ import { terminalDeliveryObservationOrdinal } from "../session-runtime/terminal-delivery-observation-identity.js";
6
+ import { PaneStreamLeaseError, } from "./lease-manager.js";
7
+ import { DEFAULT_PANE_STREAM_FLOW_BUDGETS, PaneStreamWireLedger, } from "./wire-ledger.js";
8
+ /**
9
+ * The pane-stream WebSocket endpoint (m43 card 2): redeems a one-time `ps1_`
10
+ * ticket and bridges MirrorService subscriptions to wire frames. Admission is
11
+ * the direct-websocket discipline verbatim — Origin-gated upgrade reservation,
12
+ * digest-only pending tickets, one text redemption frame, delivery-bound TTL —
13
+ * applied to a session-scoped lease whose pane set was enumerated at issue.
14
+ *
15
+ * Flow control at the wire is a LEDGER per (client x pane x owner): a stalled
16
+ * client freezes ONLY its own MirrorService subscription for the exhausted
17
+ * pane (siblings and other clients keep flowing; the upstream control-mode
18
+ * pause engages only when every subscriber of a pane is parked, which the
19
+ * session channel already models), tickets force-return on WS close within
20
+ * one tick, and thaw rides the service's atomic reseed.
21
+ */
22
+ export { PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL };
23
+ export const PANE_STREAM_MAX_REDEMPTION_BYTES = 4 * 1024;
24
+ export const PANE_STREAM_MAX_CONTROL_BYTES = 4 * 1024;
25
+ export const PANE_STREAM_MAX_REDEMPTION_MS = 1_000;
26
+ const WS_OPEN = 1;
27
+ const CANONICAL_KEY_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"key",', "utf8");
28
+ const CANONICAL_TEXT_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"text",', "utf8");
29
+ const SEMANTIC_BACKEND_REFUSALS = new Set([
30
+ "pane_inventory_not_ready",
31
+ "pane_identity_changed_before_select",
32
+ "pane_not_active",
33
+ ]);
34
+ function semanticBackendRefusal(error) {
35
+ let candidate = error;
36
+ for (let depth = 0; depth < 3; depth += 1) {
37
+ if (!candidate || typeof candidate !== "object")
38
+ return null;
39
+ const context = "context" in candidate ? candidate.context : null;
40
+ const reason = context && typeof context === "object" && "reason" in context ? context.reason : null;
41
+ if (typeof reason === "string" && SEMANTIC_BACKEND_REFUSALS.has(reason))
42
+ return reason;
43
+ candidate = "cause" in candidate ? candidate.cause : null;
44
+ }
45
+ return null;
46
+ }
47
+ const TYPE_FIRST_INPUT_FRAME_PREFIX = Buffer.from('{"type":"input",', "utf8");
48
+ function startsWithBuffer(raw, prefix) {
49
+ return (raw.length >= prefix.length && raw.compare(prefix, 0, prefix.length, 0, prefix.length) === 0);
50
+ }
51
+ function hasCanonicalInputFramePrefix(raw) {
52
+ return (startsWithBuffer(raw, CANONICAL_KEY_INPUT_FRAME_PREFIX) ||
53
+ startsWithBuffer(raw, CANONICAL_TEXT_INPUT_FRAME_PREFIX) ||
54
+ startsWithBuffer(raw, TYPE_FIRST_INPUT_FRAME_PREFIX));
55
+ }
56
+ const TicketPattern = /^ps1_[A-Za-z0-9_-]{43}$/u;
57
+ const BindingIdSchemaZ = z
58
+ .string()
59
+ .min(1)
60
+ .max(4096)
61
+ .refine((value) => !value.includes("\0"));
62
+ export class PaneStreamAdmissionError extends Error {
63
+ code;
64
+ constructor(code, message) {
65
+ super(message);
66
+ this.name = "PaneStreamAdmissionError";
67
+ this.code = code;
68
+ }
69
+ }
70
+ function defaultSchedule(callback, delayMs) {
71
+ const timer = setTimeout(callback, delayMs);
72
+ timer.unref?.();
73
+ return () => clearTimeout(timer);
74
+ }
75
+ function boundedInteger(value, fallback, maximum) {
76
+ const selected = value ?? fallback;
77
+ if (!Number.isSafeInteger(selected) || selected <= 0 || selected > maximum) {
78
+ throw new TypeError("Pane-stream admission limit is invalid.");
79
+ }
80
+ return selected;
81
+ }
82
+ function sendControl(socket, frame) {
83
+ if (socket.readyState !== WS_OPEN)
84
+ return;
85
+ const encoded = JSON.stringify(frame);
86
+ if (Buffer.byteLength(encoded, "utf8") > PANE_STREAM_MAX_CONTROL_BYTES) {
87
+ throw new TypeError("Pane-stream control frame exceeded its bound.");
88
+ }
89
+ socket.send(encoded, { binary: false });
90
+ }
91
+ function errorFrameCode(error) {
92
+ if (error instanceof PaneStreamLeaseError && error.code === "ticket-expired") {
93
+ return "ticket-expired";
94
+ }
95
+ if (error instanceof PaneStreamAdmissionError) {
96
+ switch (error.code) {
97
+ case "live-capacity-exhausted":
98
+ return "live-capacity-exhausted";
99
+ case "pane-not-found":
100
+ case "stream-unavailable":
101
+ return "stream-unavailable";
102
+ default:
103
+ return "redemption-rejected";
104
+ }
105
+ }
106
+ return "stream-unavailable";
107
+ }
108
+ /**
109
+ * In-memory admission authority for one daemon instance. It retains only
110
+ * ticket digests; a daemon restart makes every prior descriptor inert.
111
+ */
112
+ export class PaneStreamAdmissionCoordinator {
113
+ #instanceId;
114
+ #webSocketUrl;
115
+ #leaseManager;
116
+ #mirror;
117
+ #bindSessionRuntime;
118
+ #maxPending;
119
+ #maxPreAuth;
120
+ #maxLive;
121
+ #redemptionTimeoutMs;
122
+ #flowBudgets;
123
+ #drainTickMs;
124
+ #maxSocketBufferedBytes;
125
+ #maxInputFrames;
126
+ #maxInputBytes;
127
+ #inputRateWindowMs;
128
+ #now;
129
+ #schedule;
130
+ #observability;
131
+ #diagnosticSharedNowMicros;
132
+ #diagnosticAfterFrameParse;
133
+ #ledger;
134
+ #pending = new Map();
135
+ #preAuth = new Set();
136
+ #live = new Set();
137
+ #retiringReleases = new Set();
138
+ #clientCounter = 0;
139
+ #operationTail = Promise.resolve();
140
+ #shuttingDown = false;
141
+ #shutdownPromise = null;
142
+ constructor(options) {
143
+ this.#instanceId = BindingIdSchemaZ.parse(options.daemonInstanceId);
144
+ this.#webSocketUrl = PaneStreamLoopbackWebSocketUrlSchemaZ.parse(options.webSocketUrl);
145
+ this.#leaseManager = options.leaseManager;
146
+ this.#mirror = options.mirror;
147
+ this.#bindSessionRuntime = options.bindSessionRuntime;
148
+ this.#maxPending = boundedInteger(options.maxPendingTickets, 32, 1_024);
149
+ this.#maxPreAuth = boundedInteger(options.maxPreAuthSockets, 16, 1_024);
150
+ this.#maxLive = boundedInteger(options.maxLiveConnections, 16, 1_024);
151
+ this.#redemptionTimeoutMs = boundedInteger(options.redemptionTimeoutMs, PANE_STREAM_MAX_REDEMPTION_MS, PANE_STREAM_MAX_REDEMPTION_MS);
152
+ this.#flowBudgets = options.flowBudgets ?? DEFAULT_PANE_STREAM_FLOW_BUDGETS;
153
+ this.#ledger = new PaneStreamWireLedger(this.#flowBudgets);
154
+ this.#drainTickMs = boundedInteger(options.drainTickMs, 15, 1_000);
155
+ this.#maxSocketBufferedBytes = boundedInteger(options.maxSocketBufferedBytes, 32 << 20, 256 << 20);
156
+ this.#maxInputFrames = boundedInteger(options.maxInputFramesPerWindow, 16_384, 1 << 20);
157
+ this.#maxInputBytes = boundedInteger(options.maxInputBytesPerWindow, 4 << 20, 64 << 20);
158
+ this.#inputRateWindowMs = boundedInteger(options.inputRateWindowMs, 1_000, 60_000);
159
+ this.#now = options.now ?? Date.now;
160
+ this.#schedule = options.schedule ?? defaultSchedule;
161
+ this.#observability = options.observability;
162
+ this.#diagnosticSharedNowMicros = options.diagnosticSharedNowMicros;
163
+ this.#diagnosticAfterFrameParse = options.diagnosticAfterFrameParse;
164
+ }
165
+ issue(request, context) {
166
+ const trace = this.#observability?.beginTrace("pane-stream-connect", { generation: this.#instanceId, incarnation: null }, context.requestId);
167
+ const queuedAtMicros = trace ? this.#observability.nowMicros() : 0;
168
+ return this.#exclusive(async () => {
169
+ const admittedAtMicros = trace ? this.#observability.nowMicros() : 0;
170
+ if (trace)
171
+ this.#observability.recordSpan("transport", "pane-stream-issue-queue", queuedAtMicros, admittedAtMicros, trace);
172
+ if (this.#shuttingDown) {
173
+ throw new PaneStreamAdmissionError("daemon-shutting-down", "Pane-stream admission is shutting down.");
174
+ }
175
+ const origin = canonicalOriginOrNull(context.rendererOrigin);
176
+ if (origin === null) {
177
+ throw new PaneStreamAdmissionError("invalid-origin", "Renderer Origin is invalid.");
178
+ }
179
+ const requestId = z.uuid().parse(context.requestId);
180
+ const projectIdentity = BindingIdSchemaZ.parse(context.projectIdentity);
181
+ if (this.#pending.size >= this.#maxPending) {
182
+ throw new PaneStreamAdmissionError("pending-capacity-exhausted", "Pane-stream ticket capacity is exhausted.");
183
+ }
184
+ // The pane set is enumerated at issue: every requested pane must exist
185
+ // under verified semantic identity NOW. A describe failure is a probe
186
+ // failure and never reads as absence.
187
+ let described;
188
+ let runtimeSessionId = null;
189
+ try {
190
+ const describeStartedAtMicros = trace ? this.#observability.nowMicros() : 0;
191
+ if (this.#mirror.describeSessionAuthority) {
192
+ const authority = await this.#mirror.describeSessionAuthority(context.sessionName);
193
+ described = authority.description;
194
+ runtimeSessionId = authority.runtimeSessionId;
195
+ }
196
+ else {
197
+ described = await this.#mirror.describeSession(context.sessionName);
198
+ }
199
+ if (trace)
200
+ this.#observability.recordSpan("transport", "pane-stream-describe-session", describeStartedAtMicros, this.#observability.nowMicros(), trace);
201
+ }
202
+ catch {
203
+ throw new PaneStreamAdmissionError("stream-unavailable", "The workspace session could not be described.");
204
+ }
205
+ const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
206
+ for (const pane of request.panes) {
207
+ if (!known.has(pane)) {
208
+ throw new PaneStreamAdmissionError("pane-not-found", `The pane ${pane} is not present in the workspace session.`);
209
+ }
210
+ }
211
+ const issued = await this.#leaseManager.issue(request, {
212
+ requestId,
213
+ projectIdentity,
214
+ sessionName: context.sessionName,
215
+ ...(runtimeSessionId ? { runtimeSessionId } : {}),
216
+ ...(context.hostClientId ? { hostClientId: context.hostClientId } : {}),
217
+ });
218
+ const descriptor = issued.descriptor;
219
+ const ticket = issued.redemptionTicket;
220
+ const valid = TicketPattern.test(ticket) &&
221
+ z.uuid().safeParse(descriptor.leaseId).success &&
222
+ descriptor.requestId === requestId &&
223
+ (this.#mirror.describeSessionAuthority === undefined ||
224
+ descriptor.runtimeSessionId === runtimeSessionId) &&
225
+ descriptor.status === "awaiting-redemption" &&
226
+ descriptor.viewerMode === request.viewerMode &&
227
+ descriptor.workspaceName === request.workspaceName &&
228
+ descriptor.panes.length === request.panes.length &&
229
+ descriptor.panes.every((pane, index) => pane === request.panes[index]) &&
230
+ descriptor.expiresAt > this.#now();
231
+ const ticketDigest = digestSecret(ticket);
232
+ const duplicate = [...this.#pending.values()].some((pending) => digestsEqual(pending.ticketDigest, ticketDigest));
233
+ if (!valid || duplicate) {
234
+ ticketDigest.fill(0);
235
+ await this.#releaseLease(descriptor.leaseId, {
236
+ daemonInstanceId: this.#instanceId,
237
+ requestId,
238
+ projectIdentity,
239
+ });
240
+ throw new PaneStreamAdmissionError("stream-unavailable", "Pane-stream ticket generation failed.");
241
+ }
242
+ const pending = {
243
+ leaseId: descriptor.leaseId,
244
+ requestId,
245
+ projectIdentity,
246
+ origin,
247
+ ticketDigest,
248
+ descriptor: structuredClone(descriptor),
249
+ cancelExpiry: null,
250
+ };
251
+ pending.cancelExpiry = this.#schedule(() => {
252
+ void this.#exclusive(() => this.#retirePending(pending));
253
+ }, Math.max(1, descriptor.expiresAt - this.#now()));
254
+ this.#pending.set(pending.leaseId, pending);
255
+ if (trace)
256
+ this.#observability.recordSpan("transport", "pane-stream-issue-total", admittedAtMicros, this.#observability.nowMicros(), trace);
257
+ return Object.freeze({
258
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
259
+ webSocketUrl: this.#webSocketUrl,
260
+ redemptionTicket: ticket,
261
+ daemonInstanceId: this.#instanceId,
262
+ requestId,
263
+ expiresAt: descriptor.expiresAt,
264
+ panes: [...descriptor.panes],
265
+ effectiveViewerMode: descriptor.viewerMode,
266
+ });
267
+ });
268
+ }
269
+ reserveUpgrade(input) {
270
+ if (this.#shuttingDown) {
271
+ return { accepted: false, code: "daemon-shutting-down", httpStatus: 503 };
272
+ }
273
+ if (input.path !== PANE_STREAM_REDEEM_PATH) {
274
+ return { accepted: false, code: "invalid-path", httpStatus: 404 };
275
+ }
276
+ if (input.protocols.length !== 1 || input.protocols[0] !== PANE_STREAM_WEBSOCKET_SUBPROTOCOL) {
277
+ return { accepted: false, code: "invalid-subprotocol", httpStatus: 426 };
278
+ }
279
+ const origin = canonicalOriginOrNull(input.origin ?? "");
280
+ if (origin === null) {
281
+ return { accepted: false, code: "invalid-origin", httpStatus: 403 };
282
+ }
283
+ const hostClientId = input.hostClientId
284
+ ? BindingIdSchemaZ.safeParse(input.hostClientId).data
285
+ : undefined;
286
+ if (input.hostClientId && !hostClientId) {
287
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
288
+ }
289
+ const requestId = input.requestId ? z.uuid().safeParse(input.requestId).data : undefined;
290
+ if (input.requestId && !requestId) {
291
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
292
+ }
293
+ if (![...this.#pending.values()].some((pending) => pending.origin === origin &&
294
+ (!requestId || pending.requestId === requestId) &&
295
+ (!hostClientId || pending.descriptor.hostClientId === hostClientId))) {
296
+ return { accepted: false, code: "origin-rejected", httpStatus: 403 };
297
+ }
298
+ if (requestId && this.#observability?.enabled) {
299
+ const trace = this.#observability.beginTrace("pane-stream-connect", { generation: this.#instanceId, incarnation: null }, requestId);
300
+ const atMicros = this.#observability.nowMicros();
301
+ this.#observability.recordSpan("transport", "pane-stream-upgrade-arrival", atMicros, atMicros, trace);
302
+ }
303
+ if (this.#preAuth.size >= this.#maxPreAuth) {
304
+ return { accepted: false, code: "preauth-capacity-exhausted", httpStatus: 503 };
305
+ }
306
+ const admission = new PreAuthAdmission({
307
+ origin,
308
+ hostClientId: hostClientId ?? null,
309
+ timeoutMs: this.#redemptionTimeoutMs,
310
+ schedule: this.#schedule,
311
+ onRelease: (released) => this.#preAuth.delete(released),
312
+ onRedeem: (active, frame, socket) => this.#redeem(active, frame, socket),
313
+ });
314
+ this.#preAuth.add(admission);
315
+ return { accepted: true, admission };
316
+ }
317
+ snapshot() {
318
+ return Object.freeze({
319
+ pendingTickets: this.#pending.size,
320
+ preAuthSockets: this.#preAuth.size,
321
+ liveConnections: this.#live.size,
322
+ shuttingDown: this.#shuttingDown,
323
+ });
324
+ }
325
+ /** Detached (client x pane x owner) outstanding-ticket snapshot. */
326
+ flowSnapshot() {
327
+ return this.#ledger.snapshot();
328
+ }
329
+ shutdown() {
330
+ if (this.#shutdownPromise)
331
+ return this.#shutdownPromise;
332
+ this.#shuttingDown = true;
333
+ this.#shutdownPromise = this.#finishShutdown();
334
+ return this.#shutdownPromise;
335
+ }
336
+ async #finishShutdown() {
337
+ for (const admission of [...this.#preAuth])
338
+ admission.close(1001, "daemon-shutdown");
339
+ await this.#exclusive(async () => {
340
+ for (const connection of [...this.#live])
341
+ connection.close(1001, "daemon-shutdown");
342
+ for (const pending of [...this.#pending.values()])
343
+ await this.#retirePending(pending);
344
+ });
345
+ await Promise.all([...this.#retiringReleases]);
346
+ }
347
+ #redeem(admission, frame, socket) {
348
+ // Stamp authenticated frame arrival BEFORE queueing: a queue wait must not
349
+ // consume the ticket's delivery TTL (execution has its own budget).
350
+ const receivedAt = this.#now();
351
+ return this.#exclusive(async () => {
352
+ if (this.#shuttingDown || frame.daemonInstanceId !== this.#instanceId) {
353
+ throw new PaneStreamAdmissionError("redemption-rejected", "Pane-stream redemption was rejected.");
354
+ }
355
+ const candidateDigest = digestSecret(frame.ticket);
356
+ let pending;
357
+ for (const entry of this.#pending.values()) {
358
+ if (digestsEqual(entry.ticketDigest, candidateDigest))
359
+ pending = entry;
360
+ }
361
+ candidateDigest.fill(0);
362
+ if (!pending ||
363
+ pending.origin !== admission.origin ||
364
+ (admission.hostClientId !== null &&
365
+ pending.descriptor.hostClientId !== admission.hostClientId) ||
366
+ pending.requestId !== frame.requestId) {
367
+ throw new PaneStreamAdmissionError("redemption-rejected", "Pane-stream redemption was rejected.");
368
+ }
369
+ const binding = {
370
+ daemonInstanceId: this.#instanceId,
371
+ requestId: pending.requestId,
372
+ projectIdentity: pending.projectIdentity,
373
+ };
374
+ if (!admission.isOpen()) {
375
+ this.#removePending(pending);
376
+ await this.#releaseLease(pending.leaseId, binding);
377
+ throw new PaneStreamAdmissionError("redemption-rejected", "Pane-stream redemption was rejected.");
378
+ }
379
+ this.#removePending(pending);
380
+ if (this.#live.size >= this.#maxLive) {
381
+ await this.#releaseLease(pending.leaseId, binding);
382
+ throw new PaneStreamAdmissionError("live-capacity-exhausted", "Pane-stream live capacity is exhausted.");
383
+ }
384
+ try {
385
+ const redeemed = await this.#leaseManager.redeem(frame.ticket, binding, receivedAt);
386
+ const descriptor = redeemed.descriptor;
387
+ if (descriptor.terminalDelivery && frame.deliveryAcks === true) {
388
+ throw new PaneStreamAdmissionError("stream-unavailable", "Semantic terminal delivery owns its ACK lifecycle; legacy renderer ACKs are invalid.");
389
+ }
390
+ if (descriptor.leaseId !== pending.leaseId ||
391
+ descriptor.requestId !== pending.requestId ||
392
+ descriptor.status !== "active" ||
393
+ descriptor.viewerMode !== pending.descriptor.viewerMode ||
394
+ descriptor.panes.length !== pending.descriptor.panes.length) {
395
+ throw new PaneStreamAdmissionError("stream-unavailable", "Pane-stream lease identity was unavailable.");
396
+ }
397
+ if (!admission.isOpen()) {
398
+ throw new PaneStreamAdmissionError("redemption-rejected", "Pane-stream redemption was rejected.");
399
+ }
400
+ this.#clientCounter += 1;
401
+ const sessionRuntimeBinding = this.#bindSessionRuntime?.(descriptor) ?? null;
402
+ let live;
403
+ try {
404
+ live = new PaneStreamLiveConnection({
405
+ clientId: `psc-${this.#clientCounter}`,
406
+ socket,
407
+ descriptor: structuredClone(descriptor),
408
+ sessionRuntimeBinding,
409
+ binding,
410
+ deliveryAcks: frame.deliveryAcks === true,
411
+ diagnosticCapabilities: frame.diagnosticCapabilities ?? [],
412
+ causalCellCapability: descriptor.terminalDelivery !== null &&
413
+ descriptor.viewerMode === "interactive" &&
414
+ frame.diagnosticCapabilities?.includes("causal-cell-v1") === true,
415
+ mirror: this.#mirror,
416
+ leaseManager: this.#leaseManager,
417
+ ledger: this.#ledger,
418
+ drainTickMs: this.#drainTickMs,
419
+ maxSocketBufferedBytes: this.#maxSocketBufferedBytes,
420
+ maxInputFrames: this.#maxInputFrames,
421
+ maxInputBytes: this.#maxInputBytes,
422
+ inputRateWindowMs: this.#inputRateWindowMs,
423
+ now: this.#now,
424
+ schedule: this.#schedule,
425
+ observability: this.#observability,
426
+ diagnosticSharedNowMicros: this.#diagnosticSharedNowMicros,
427
+ diagnosticAfterFrameParse: this.#diagnosticAfterFrameParse,
428
+ onRetire: (connection) => this.#trackRetiringRelease(connection),
429
+ });
430
+ }
431
+ catch (error) {
432
+ await sessionRuntimeBinding?.close();
433
+ throw error;
434
+ }
435
+ this.#live.add(live);
436
+ admission.promote();
437
+ live.start();
438
+ return live;
439
+ }
440
+ catch (error) {
441
+ await this.#releaseLease(pending.leaseId, binding);
442
+ throw error;
443
+ }
444
+ });
445
+ }
446
+ #removePending(pending) {
447
+ if (this.#pending.get(pending.leaseId) !== pending)
448
+ return;
449
+ this.#pending.delete(pending.leaseId);
450
+ pending.cancelExpiry?.();
451
+ pending.cancelExpiry = null;
452
+ pending.ticketDigest.fill(0);
453
+ }
454
+ async #retirePending(pending) {
455
+ if (this.#pending.get(pending.leaseId) !== pending)
456
+ return;
457
+ const binding = {
458
+ daemonInstanceId: this.#instanceId,
459
+ requestId: pending.requestId,
460
+ projectIdentity: pending.projectIdentity,
461
+ };
462
+ this.#removePending(pending);
463
+ await this.#releaseLease(pending.leaseId, binding);
464
+ }
465
+ async #releaseLease(leaseId, binding) {
466
+ try {
467
+ await this.#leaseManager.release(leaseId, binding);
468
+ }
469
+ catch {
470
+ // The lease manager may already have retired the one-use lease.
471
+ }
472
+ }
473
+ #trackRetiringRelease(connection) {
474
+ this.#live.delete(connection);
475
+ const release = connection.waitForRelease();
476
+ this.#retiringReleases.add(release);
477
+ void release.then(() => this.#retiringReleases.delete(release), () => this.#retiringReleases.delete(release));
478
+ }
479
+ #exclusive(operation) {
480
+ const run = this.#operationTail.then(operation, operation);
481
+ this.#operationTail = run.then(() => undefined, () => undefined);
482
+ return run;
483
+ }
484
+ }
485
+ class PreAuthAdmission {
486
+ origin;
487
+ hostClientId;
488
+ #onRelease;
489
+ #onRedeem;
490
+ #cancelDeadline;
491
+ #socket = null;
492
+ #frameReceived = false;
493
+ #open = true;
494
+ #promoted = false;
495
+ constructor(options) {
496
+ this.origin = options.origin;
497
+ this.hostClientId = options.hostClientId;
498
+ this.#onRelease = options.onRelease;
499
+ this.#onRedeem = options.onRedeem;
500
+ this.#cancelDeadline = options.schedule(() => this.close(1008, "redemption-timeout"), options.timeoutMs);
501
+ }
502
+ isOpen() {
503
+ return this.#open && !this.#promoted;
504
+ }
505
+ bind(socket) {
506
+ if (!this.#open || this.#socket) {
507
+ safeCloseSocket(socket, 1008, "redemption-rejected");
508
+ return;
509
+ }
510
+ this.#socket = socket;
511
+ socket.on("message", this.#onMessage);
512
+ socket.on("close", this.#onClose);
513
+ socket.on("error", this.#onClose);
514
+ }
515
+ cancelBeforeBind() {
516
+ this.close(1008, "upgrade-rejected");
517
+ }
518
+ promote() {
519
+ if (!this.#open)
520
+ return;
521
+ this.#promoted = true;
522
+ this.#open = false;
523
+ this.#cancelDeadline();
524
+ this.#detach();
525
+ this.#onRelease(this);
526
+ }
527
+ close(code = 1008, reason = "redemption-rejected") {
528
+ if (!this.#open)
529
+ return;
530
+ this.#open = false;
531
+ this.#cancelDeadline();
532
+ const socket = this.#socket;
533
+ this.#detach();
534
+ this.#onRelease(this);
535
+ if (socket)
536
+ safeCloseSocket(socket, code, reason);
537
+ }
538
+ #onMessage = (data, isBinary) => {
539
+ if (!this.#open || this.#frameReceived) {
540
+ this.close(1008, "redemption-frame-rejected");
541
+ return;
542
+ }
543
+ this.#frameReceived = true;
544
+ const byteLength = rawDataByteLength(data, PANE_STREAM_MAX_REDEMPTION_BYTES);
545
+ if (isBinary || byteLength === 0 || byteLength > PANE_STREAM_MAX_REDEMPTION_BYTES) {
546
+ this.close(1009, "redemption-frame-rejected");
547
+ return;
548
+ }
549
+ let frame;
550
+ try {
551
+ frame = PaneStreamRedeemFrameSchemaZ.parse(strictJsonParse(rawDataToBuffer(data)));
552
+ }
553
+ catch {
554
+ this.close(1008, "redemption-frame-rejected");
555
+ return;
556
+ }
557
+ const socket = this.#socket;
558
+ if (!socket) {
559
+ this.close(1008, "redemption-rejected");
560
+ return;
561
+ }
562
+ this.#cancelDeadline();
563
+ void this.#onRedeem(this, frame, socket).catch((error) => {
564
+ if (!this.#open)
565
+ return;
566
+ const code = errorFrameCode(error);
567
+ try {
568
+ sendControl(socket, {
569
+ type: "error",
570
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
571
+ code,
572
+ retryable: code === "live-capacity-exhausted" || code === "ticket-expired",
573
+ });
574
+ }
575
+ catch {
576
+ // Closing below is the fail-closed response.
577
+ }
578
+ this.close(code === "live-capacity-exhausted" ? 1013 : 1008, "redemption-rejected");
579
+ });
580
+ };
581
+ #onClose = () => this.close(1008, "redemption-rejected");
582
+ #detach() {
583
+ const socket = this.#socket;
584
+ this.#socket = null;
585
+ if (!socket)
586
+ return;
587
+ socket.off("message", this.#onMessage);
588
+ socket.off("close", this.#onClose);
589
+ socket.off("error", this.#onClose);
590
+ }
591
+ }
592
+ export class PaneStreamLiveConnection {
593
+ #clientId;
594
+ #socket;
595
+ #descriptor;
596
+ #binding;
597
+ #sessionRuntimeBinding;
598
+ #deliveryAcks;
599
+ #causalCellCapability;
600
+ #diagnosticCapabilities;
601
+ #mirror;
602
+ #leaseManager;
603
+ #ledger;
604
+ #drainTickMs;
605
+ #maxSocketBufferedBytes;
606
+ #maxInputFrames;
607
+ #maxInputBytes;
608
+ #inputRateWindowMs;
609
+ #now;
610
+ #schedule;
611
+ #observability;
612
+ #diagnosticSharedRawMicros;
613
+ #diagnosticAfterFrameParse;
614
+ #onRetire;
615
+ #panes = new Map();
616
+ #semanticLayouts = new Map();
617
+ #semanticExpectedPaneIds = null;
618
+ #semanticRuntimeSessionId = null;
619
+ #semanticTopologyEpoch = -1;
620
+ #sendQueue = [];
621
+ #semanticDrainWaiters = new Map();
622
+ #layoutSubscription = null;
623
+ #sentBytesTotal = 0;
624
+ #drainedBytesTotal = 0;
625
+ #cancelDrainTick = null;
626
+ #inputWindowStartedAt;
627
+ #inputWindowFrames = 0;
628
+ #inputWindowBytes = 0;
629
+ #nextViewportSeq = 1;
630
+ #nextClockProbe = 1;
631
+ #requestedAuthorities = new Set();
632
+ #usesExplicitAuthority = false;
633
+ #legacyInputActivated = false;
634
+ #legacyGeometryActivated = false;
635
+ #closed = false;
636
+ #releasePromise = null;
637
+ #stopAuthoritySnapshots = null;
638
+ #sharedClockOriginMicros = null;
639
+ #diagnosticFirstSeedObserved = false;
640
+ #diagnosticLifecycleStages;
641
+ #recordDiagnosticLifecycle(operation, closeCode, closeReason) {
642
+ if (!this.#observability?.enabled || !this.#diagnosticLifecycleStages)
643
+ return;
644
+ if (this.#diagnosticLifecycleStages.has(operation))
645
+ return;
646
+ this.#diagnosticLifecycleStages.add(operation);
647
+ const trace = this.#observability.beginTrace("pane-stream-connect", { generation: this.#binding.daemonInstanceId, incarnation: null }, this.#binding.requestId);
648
+ const atMicros = this.#observability.nowMicros();
649
+ const legalReason = (new Set([
650
+ "stream-retired",
651
+ "stream-unavailable",
652
+ "stream-closed",
653
+ "topology-changed",
654
+ "output-backpressure",
655
+ "panes-closed",
656
+ "peer-closed",
657
+ "daemon-shutdown",
658
+ "redemption-rejected",
659
+ "unknown",
660
+ ]).has(closeReason ?? "")
661
+ ? closeReason
662
+ : closeReason
663
+ ? "unknown"
664
+ : "none");
665
+ this.#observability.recordSpan("transport", operation, atMicros, atMicros, trace, undefined, Object.freeze({
666
+ paneStreamCloseCode: Number.isInteger(closeCode) && closeCode >= 1000 && closeCode <= 4999 ? closeCode : 0,
667
+ paneStreamCloseReason: legalReason,
668
+ }));
669
+ }
670
+ #sharedMicros() {
671
+ const raw = this.#diagnosticSharedRawMicros();
672
+ this.#sharedClockOriginMicros ??= raw;
673
+ const elapsed = raw - this.#sharedClockOriginMicros;
674
+ if (!Number.isSafeInteger(elapsed) || elapsed < 0)
675
+ throw new Error("Daemon shared monotonic clock regressed");
676
+ return elapsed;
677
+ }
678
+ constructor(options) {
679
+ this.#clientId = options.clientId;
680
+ this.#socket = options.socket;
681
+ this.#descriptor = options.descriptor;
682
+ this.#binding = options.binding;
683
+ this.#sessionRuntimeBinding = options.sessionRuntimeBinding;
684
+ this.#usesExplicitAuthority = options.sessionRuntimeBinding?.explicitAuthority === true;
685
+ if (this.#descriptor.viewerMode === "interactive" && !this.#sessionRuntimeBinding) {
686
+ throw new Error("Interactive pane stream requires SessionRuntime authority");
687
+ }
688
+ this.#deliveryAcks = options.deliveryAcks;
689
+ this.#causalCellCapability = options.causalCellCapability;
690
+ this.#diagnosticCapabilities = options.diagnosticCapabilities;
691
+ this.#mirror = options.mirror;
692
+ this.#leaseManager = options.leaseManager;
693
+ this.#ledger = options.ledger;
694
+ this.#drainTickMs = options.drainTickMs;
695
+ this.#maxSocketBufferedBytes = options.maxSocketBufferedBytes;
696
+ this.#maxInputFrames = options.maxInputFrames;
697
+ this.#maxInputBytes = options.maxInputBytes;
698
+ this.#inputRateWindowMs = options.inputRateWindowMs;
699
+ this.#now = options.now;
700
+ this.#inputWindowStartedAt = this.#now();
701
+ this.#schedule = options.schedule;
702
+ this.#observability = options.observability;
703
+ this.#diagnosticLifecycleStages = options.observability?.enabled ? new Set() : null;
704
+ this.#diagnosticSharedRawMicros = this.#diagnosticCapabilities.includes("clock-bounds-v1")
705
+ ? (options.diagnosticSharedNowMicros ?? sharedMonotonicMicros)
706
+ : undefined;
707
+ this.#diagnosticAfterFrameParse = options.diagnosticAfterFrameParse;
708
+ this.#onRetire = options.onRetire;
709
+ for (const pane of options.descriptor.panes) {
710
+ this.#panes.set(pane, {
711
+ semanticPaneId: pane,
712
+ sub: null,
713
+ delivery: null,
714
+ deliveryAddress: null,
715
+ serverSeq: 0,
716
+ sentPaneFrames: 0,
717
+ consumedSeq: 0,
718
+ nextInputSeq: 1,
719
+ frozenByWire: false,
720
+ closed: false,
721
+ batch: null,
722
+ });
723
+ }
724
+ }
725
+ get clientId() {
726
+ return this.#clientId;
727
+ }
728
+ start() {
729
+ if (this.#closed || this.#socket.readyState !== WS_OPEN) {
730
+ this.close(1008, "stream-retired");
731
+ return;
732
+ }
733
+ this.#socket.on("message", this.#onMessage);
734
+ this.#socket.on("close", this.#onSocketClose);
735
+ this.#socket.on("error", this.#onSocketClose);
736
+ try {
737
+ sendControl(this.#socket, {
738
+ type: "ready",
739
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
740
+ daemonInstanceId: this.#binding.daemonInstanceId,
741
+ requestId: this.#binding.requestId,
742
+ ...(this.#sessionRuntimeBinding
743
+ ? { connectionClientId: this.#sessionRuntimeBinding.clientId }
744
+ : {}),
745
+ panes: [...this.#descriptor.panes],
746
+ effectiveViewerMode: this.#descriptor.viewerMode,
747
+ ...(this.#diagnosticCapabilities.length > 0
748
+ ? { diagnosticCapabilities: [...this.#diagnosticCapabilities] }
749
+ : {}),
750
+ });
751
+ this.#recordDiagnosticLifecycle("pane-stream-server-ready");
752
+ }
753
+ catch {
754
+ this.close(1011, "stream-unavailable-describe");
755
+ return;
756
+ }
757
+ this.#stopAuthoritySnapshots =
758
+ this.#sessionRuntimeBinding?.onAuthoritySnapshot?.((snapshot) => this.#usesExplicitAuthority ? this.#sendAuthoritySnapshot(snapshot) : undefined) ?? null;
759
+ void this.#subscribeAll();
760
+ }
761
+ close(code = 1000, reason = "stream-closed") {
762
+ if (this.#closed)
763
+ return;
764
+ this.#recordDiagnosticLifecycle("pane-stream-terminal", code, reason);
765
+ this.#closed = true;
766
+ this.#cancelDrainTick?.();
767
+ this.#cancelDrainTick = null;
768
+ // Departure force-returns every ticket within this same tick.
769
+ this.#ledger.forceReturnClient(this.#clientId);
770
+ this.#sendQueue.length = 0;
771
+ for (const waiters of this.#semanticDrainWaiters.values())
772
+ for (const resolve of waiters)
773
+ resolve();
774
+ this.#semanticDrainWaiters.clear();
775
+ this.#socket.off("message", this.#onMessage);
776
+ this.#socket.off("close", this.#onSocketClose);
777
+ this.#socket.off("error", this.#onSocketClose);
778
+ this.#stopAuthoritySnapshots?.();
779
+ this.#stopAuthoritySnapshots = null;
780
+ const closures = [];
781
+ const layoutSubscription = this.#layoutSubscription;
782
+ this.#layoutSubscription = null;
783
+ if (layoutSubscription)
784
+ closures.push(layoutSubscription.close().catch(() => undefined));
785
+ for (const channel of this.#panes.values()) {
786
+ const sub = channel.sub;
787
+ channel.sub = null;
788
+ const delivery = channel.delivery;
789
+ channel.delivery = null;
790
+ channel.closed = true;
791
+ if (sub)
792
+ closures.push(sub.close().catch(() => undefined));
793
+ if (delivery)
794
+ closures.push(delivery.close().catch(() => undefined));
795
+ }
796
+ this.#releasePromise = Promise.allSettled([
797
+ ...closures,
798
+ this.#leaseManager.release(this.#descriptor.leaseId, this.#binding).catch(() => undefined),
799
+ this.#sessionRuntimeBinding?.close() ?? Promise.resolve(),
800
+ ]);
801
+ this.#onRetire(this);
802
+ safeCloseSocket(this.#socket, code, reason);
803
+ }
804
+ async waitForRelease() {
805
+ await this.#releasePromise;
806
+ }
807
+ /** TESTS ONLY — run one drain evaluation without waiting for the tick. */
808
+ drainNowForTest() {
809
+ this.#drainNow();
810
+ }
811
+ async #subscribeAll() {
812
+ // Fresh truth once for the whole set: a pane listed at issue but gone by
813
+ // redeem gets an honest `closed` frame (a successful describe omitting it
814
+ // is absence; a describe FAILURE is not and fails the connection).
815
+ let described;
816
+ try {
817
+ described = await this.#mirror.describeSession(this.#descriptor.sessionName);
818
+ }
819
+ catch {
820
+ this.close(1011, "stream-unavailable");
821
+ return;
822
+ }
823
+ if (this.#closed)
824
+ return;
825
+ const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
826
+ if (this.#descriptor.terminalDelivery) {
827
+ await this.#subscribeSemantic(known);
828
+ return;
829
+ }
830
+ if (this.#mirror.subscribeLayout) {
831
+ try {
832
+ const layoutSubscription = await this.#mirror.subscribeLayout(this.#descriptor.sessionName, (event) => this.#onLayout(event));
833
+ if (this.#closed) {
834
+ await layoutSubscription.close().catch(() => undefined);
835
+ return;
836
+ }
837
+ this.#layoutSubscription = layoutSubscription;
838
+ }
839
+ catch {
840
+ this.close(1011, "stream-unavailable");
841
+ return;
842
+ }
843
+ }
844
+ let layoutAttached = this.#layoutSubscription !== null;
845
+ for (const channel of this.#panes.values()) {
846
+ if (this.#closed)
847
+ return;
848
+ if (!known.has(channel.semanticPaneId)) {
849
+ this.#emitClosed(channel);
850
+ continue;
851
+ }
852
+ try {
853
+ const sub = await this.#mirror.subscribe({
854
+ session: this.#descriptor.sessionName,
855
+ semanticPaneId: channel.semanticPaneId,
856
+ onEvent: (event) => this.#onPaneEvent(channel, event),
857
+ ...(layoutAttached ? {} : { onLayout: (event) => this.#onLayout(event) }),
858
+ });
859
+ layoutAttached = true;
860
+ if (this.#closed || channel.closed) {
861
+ void sub.close().catch(() => undefined);
862
+ continue;
863
+ }
864
+ channel.sub = sub;
865
+ }
866
+ catch {
867
+ this.close(1011, "stream-unavailable");
868
+ return;
869
+ }
870
+ }
871
+ this.#closeIfAllPanesGone();
872
+ }
873
+ async #subscribeSemantic(known) {
874
+ const binding = this.#sessionRuntimeBinding;
875
+ const offer = this.#descriptor.terminalDelivery;
876
+ if (!binding || !offer) {
877
+ this.close(1011, "stream-unavailable");
878
+ return;
879
+ }
880
+ const expectedPaneIds = [...this.#descriptor.panes].sort();
881
+ if (expectedPaneIds.some((pane) => !known.has(pane))) {
882
+ this.#failTopologyChanged();
883
+ return;
884
+ }
885
+ const channels = [...this.#panes.values()];
886
+ if (this.#closed || channels.length === 0)
887
+ return;
888
+ let stagedAuthority = null;
889
+ let authorityMalformed = false;
890
+ let layoutActivated = false;
891
+ // Establish the single session layout observer first. MirrorService owns
892
+ // this lifecycle and may share native control state with delivery setup;
893
+ // only the independent pane delivery opens below are parallelized.
894
+ try {
895
+ if (!this.#mirror.subscribeLayout)
896
+ throw new Error("authoritative layout is unavailable");
897
+ const subscription = await this.#mirror.subscribeLayout(this.#descriptor.sessionName, () => undefined, {
898
+ expectedSemanticPaneIds: expectedPaneIds,
899
+ expectedRuntimeSessionId: this.#descriptor.runtimeSessionId,
900
+ onAuthority: (snapshot) => {
901
+ this.#recordDiagnosticLifecycle("pane-stream-layout-staged");
902
+ if (snapshot.layouts.length > PANE_STREAM_MAX_PANES)
903
+ authorityMalformed = true;
904
+ else if (!layoutActivated)
905
+ stagedAuthority = snapshot;
906
+ else
907
+ this.#onLayoutAuthority(snapshot);
908
+ },
909
+ });
910
+ if (this.#closed) {
911
+ await subscription.close().catch(() => undefined);
912
+ return;
913
+ }
914
+ const authority = stagedAuthority;
915
+ const stagedInitialFrames = authorityMalformed ||
916
+ authority === null ||
917
+ authority.session !== this.#descriptor.sessionName ||
918
+ this.#descriptor.runtimeSessionId === null ||
919
+ authority.runtimeSessionId !== this.#descriptor.runtimeSessionId ||
920
+ authority.topologyEpoch < 0
921
+ ? null
922
+ : this.#validateInitialLayout(authority.layouts, expectedPaneIds);
923
+ if (!stagedInitialFrames) {
924
+ await subscription.close().catch(() => undefined);
925
+ this.#failTopologyChanged();
926
+ return;
927
+ }
928
+ this.#layoutSubscription = subscription;
929
+ }
930
+ catch (cause) {
931
+ if (cause instanceof Error && cause.name === "MirrorTopologyChangedError") {
932
+ this.#failTopologyChanged();
933
+ return;
934
+ }
935
+ this.close(1011, "stream-unavailable");
936
+ return;
937
+ }
938
+ // Delivery owners are pane-scoped and independent. Open them concurrently,
939
+ // then publish in descriptor order only after every pane is coherent. This
940
+ // removes N x attachment latency without allowing a fast pane to make the
941
+ // session look ready while a sibling is still missing. allSettled is
942
+ // deliberate: partial success is always closed before the socket retires.
943
+ const openings = channels.map(async (channel) => {
944
+ const pending = [];
945
+ let ready = false;
946
+ const delivery = await binding.openTerminalDelivery(channel.semanticPaneId, offer, (message) => {
947
+ if (!ready)
948
+ pending.push(message);
949
+ else
950
+ return this.#sendTerminalDelivery(channel.semanticPaneId, message);
951
+ });
952
+ return {
953
+ channel,
954
+ delivery,
955
+ pending,
956
+ markReady: () => {
957
+ ready = true;
958
+ },
959
+ };
960
+ });
961
+ const settled = await Promise.allSettled(openings);
962
+ const opened = settled.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
963
+ if (this.#closed ||
964
+ settled.some((result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted)) {
965
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
966
+ if (!this.#closed)
967
+ this.close(1011, "stream-unavailable");
968
+ return;
969
+ }
970
+ const deliveryIdentityChanged = opened.some(({ channel, delivery, pending }) => {
971
+ if (!delivery.negotiation.accepted)
972
+ return true;
973
+ const negotiated = delivery.negotiation.negotiated;
974
+ if (negotiated.generation !== this.#binding.daemonInstanceId)
975
+ return true;
976
+ let incarnation = null;
977
+ for (const message of pending) {
978
+ if (message.type !== "terminal.delivery")
979
+ continue;
980
+ if (message.workspaceName !== this.#descriptor.sessionName ||
981
+ message.semanticPaneId !== channel.semanticPaneId ||
982
+ message.generation !== negotiated.generation ||
983
+ message.deliveryNonce !== negotiated.deliveryNonce ||
984
+ (incarnation !== null && message.incarnation !== incarnation))
985
+ return true;
986
+ incarnation = message.incarnation;
987
+ }
988
+ return false;
989
+ });
990
+ if (deliveryIdentityChanged) {
991
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
992
+ this.#failTopologyChanged();
993
+ return;
994
+ }
995
+ const authority = stagedAuthority;
996
+ const initialFrames = authorityMalformed ||
997
+ authority === null ||
998
+ authority.session !== this.#descriptor.sessionName ||
999
+ this.#descriptor.runtimeSessionId === null ||
1000
+ authority.runtimeSessionId !== this.#descriptor.runtimeSessionId ||
1001
+ authority.topologyEpoch < 0
1002
+ ? null
1003
+ : this.#validateInitialLayout(authority.layouts, expectedPaneIds);
1004
+ if (!initialFrames) {
1005
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1006
+ this.#failTopologyChanged();
1007
+ return;
1008
+ }
1009
+ this.#recordDiagnosticLifecycle("pane-stream-layout-validated");
1010
+ this.#semanticExpectedPaneIds = expectedPaneIds;
1011
+ this.#semanticRuntimeSessionId = authority.runtimeSessionId;
1012
+ this.#semanticTopologyEpoch = authority.topologyEpoch;
1013
+ this.#semanticLayouts.clear();
1014
+ for (const event of authority.layouts)
1015
+ this.#semanticLayouts.set(event.semanticWindowId, event);
1016
+ this.#sendFrame(null, {
1017
+ type: "layout-snapshot",
1018
+ topologyEpoch: authority.topologyEpoch,
1019
+ layouts: initialFrames,
1020
+ });
1021
+ layoutActivated = true;
1022
+ this.#recordDiagnosticLifecycle("pane-stream-delivery-open");
1023
+ for (const { channel, delivery, pending, markReady } of opened) {
1024
+ if (this.#closed || channel.closed) {
1025
+ await delivery.close();
1026
+ continue;
1027
+ }
1028
+ // The rejected case was eliminated above; retain this narrowing at the
1029
+ // publication boundary so an invalid negotiation cannot leak a nonce.
1030
+ if (!delivery.negotiation.accepted)
1031
+ continue;
1032
+ channel.delivery = delivery;
1033
+ void delivery.closed?.then((reason) => {
1034
+ if (reason === "sink-failed" &&
1035
+ !this.#closed &&
1036
+ !channel.closed &&
1037
+ channel.delivery === delivery)
1038
+ this.close(1013, "output-backpressure");
1039
+ });
1040
+ channel.deliveryAddress = {
1041
+ workspaceName: this.#descriptor.workspaceName,
1042
+ generation: delivery.negotiation.negotiated.generation,
1043
+ incarnation: null,
1044
+ deliveryNonce: delivery.negotiation.negotiated.deliveryNonce,
1045
+ };
1046
+ this.#sendFrame(null, {
1047
+ type: "terminal-delivery-ready",
1048
+ pane: channel.semanticPaneId,
1049
+ negotiation: delivery.negotiation,
1050
+ });
1051
+ markReady();
1052
+ for (const message of pending)
1053
+ await this.#sendTerminalDelivery(channel.semanticPaneId, message);
1054
+ }
1055
+ this.#closeIfAllPanesGone();
1056
+ }
1057
+ async #sendTerminalDelivery(pane, message) {
1058
+ if (message.type === "terminal.delivery") {
1059
+ if (!this.#diagnosticFirstSeedObserved) {
1060
+ this.#diagnosticFirstSeedObserved = true;
1061
+ this.#recordDiagnosticLifecycle("pane-stream-first-seed");
1062
+ }
1063
+ const channel = this.#panes.get(pane);
1064
+ if (channel?.deliveryAddress)
1065
+ channel.deliveryAddress.incarnation = message.incarnation;
1066
+ // SessionRuntime keys canonical replicas by the tmux session, while the
1067
+ // public pane-stream lease is keyed by its workspace identity. Translate
1068
+ // at this boundary so the renderer has one coherent address vocabulary.
1069
+ const detailedDeliveryObservation = this.#observability?.enabled === true;
1070
+ const trace = message.performanceTraceId && detailedDeliveryObservation
1071
+ ? this.#observability.beginTrace("terminal-input-to-paint", { generation: message.generation, incarnation: message.incarnation }, message.performanceTraceId)
1072
+ : null;
1073
+ let startedAtMicros = null;
1074
+ if (detailedDeliveryObservation)
1075
+ try {
1076
+ startedAtMicros = this.#observability.nowMicros();
1077
+ }
1078
+ catch {
1079
+ // Detailed delivery timing cannot alter socket delivery.
1080
+ }
1081
+ let startedAtSharedMicros = null;
1082
+ if (startedAtMicros !== null && this.#diagnosticSharedRawMicros) {
1083
+ try {
1084
+ startedAtSharedMicros = this.#sharedMicros();
1085
+ }
1086
+ catch {
1087
+ // Shared-clock diagnostics cannot alter terminal delivery.
1088
+ }
1089
+ }
1090
+ this.#sendFrame(pane, {
1091
+ type: "terminal-delivery-envelope",
1092
+ pane,
1093
+ envelope: { ...message, workspaceName: this.#descriptor.workspaceName },
1094
+ });
1095
+ if (startedAtMicros !== null) {
1096
+ let endedAtMicros;
1097
+ try {
1098
+ endedAtMicros = this.#observability.nowMicros();
1099
+ }
1100
+ catch {
1101
+ return;
1102
+ }
1103
+ let endedAtSharedMicros = null;
1104
+ if (startedAtSharedMicros !== null) {
1105
+ try {
1106
+ endedAtSharedMicros = this.#sharedMicros();
1107
+ }
1108
+ catch {
1109
+ // Preserve the process-local span when shared sampling fails.
1110
+ }
1111
+ }
1112
+ try {
1113
+ this.#observability.recordSpan("transport", "pane-stream-socket-send", startedAtMicros, endedAtMicros, trace, startedAtSharedMicros === null || endedAtSharedMicros === null
1114
+ ? undefined
1115
+ : {
1116
+ startedAtMicros: startedAtSharedMicros,
1117
+ endedAtMicros: endedAtSharedMicros,
1118
+ }, Object.freeze({
1119
+ workspaceName: message.workspaceName,
1120
+ semanticPaneId: message.semanticPaneId,
1121
+ canonicalGeneration: message.generation,
1122
+ canonicalIncarnation: message.incarnation,
1123
+ canonicalRevision: message.canonicalRevision,
1124
+ canonicalStateHash: message.canonicalStateHash,
1125
+ transactionId: message.transactionId,
1126
+ ...(terminalDeliveryObservationOrdinal(message) === null
1127
+ ? {}
1128
+ : { deliveryOrdinal: terminalDeliveryObservationOrdinal(message) }),
1129
+ deliveryClientId: this.#sessionRuntimeBinding?.clientId ?? this.#clientId,
1130
+ deliverySurface: this.#sessionRuntimeBinding?.surface ?? "unknown",
1131
+ deliveryLaneId: this.#sessionRuntimeBinding?.deliveryLaneId ?? this.#clientId,
1132
+ deliveryRequestId: this.#sessionRuntimeBinding?.deliveryRequestId ?? this.#clientId,
1133
+ deliveryNonce: message.deliveryNonce,
1134
+ }));
1135
+ }
1136
+ catch {
1137
+ // Diagnostics cannot alter terminal delivery.
1138
+ }
1139
+ }
1140
+ }
1141
+ else if (message.type === "terminal.delivery.chunk") {
1142
+ this.#sendFrame(pane, {
1143
+ type: "terminal-delivery-chunk",
1144
+ pane,
1145
+ transactionId: message.transactionId,
1146
+ index: message.index,
1147
+ data: Buffer.from(message.bytes).toString("base64"),
1148
+ });
1149
+ }
1150
+ else {
1151
+ this.#sendFrame(pane, { type: "terminal-delivery-fault", pane, fault: message });
1152
+ // Lifecycle/control truth must never queue behind bulk terminal bytes.
1153
+ // The hard socket-wide ceiling still closes a genuinely wedged client in
1154
+ // #drainNow; a source-close frame itself is small and immediately useful.
1155
+ return;
1156
+ }
1157
+ await this.#awaitSemanticCredit(pane);
1158
+ }
1159
+ #awaitSemanticCredit(pane) {
1160
+ // Backpressure is pane-local. Aggregate pressure is guarded by the hard
1161
+ // socket ceiling in #drainNow, but must not let a noisy sibling prevent a
1162
+ // pane-close (or any other pane's next semantic delivery) from surfacing.
1163
+ if (!this.#ledger.isStalled(this.#clientId, pane))
1164
+ return Promise.resolve();
1165
+ return new Promise((resolve) => {
1166
+ const waiters = this.#semanticDrainWaiters.get(pane) ?? [];
1167
+ waiters.push(resolve);
1168
+ this.#semanticDrainWaiters.set(pane, waiters);
1169
+ this.#ensureDrainTick();
1170
+ });
1171
+ }
1172
+ // ── Mirror events → frames ────────────────────────────────────────────────
1173
+ #onPaneEvent(channel, event) {
1174
+ if (this.#closed || channel.closed)
1175
+ return;
1176
+ switch (event.type) {
1177
+ case "reset": {
1178
+ channel.batch = {
1179
+ reset: { cols: event.cols, rows: event.rows },
1180
+ seed: null,
1181
+ held: [],
1182
+ guardArmed: false,
1183
+ };
1184
+ this.#armBatchGuard(channel);
1185
+ return;
1186
+ }
1187
+ case "seed": {
1188
+ if (channel.batch)
1189
+ channel.batch.seed = event.data;
1190
+ else {
1191
+ channel.batch = { reset: null, seed: event.data, held: [], guardArmed: false };
1192
+ this.#armBatchGuard(channel);
1193
+ }
1194
+ return;
1195
+ }
1196
+ case "delta": {
1197
+ const batch = channel.batch;
1198
+ if (batch && batch.seed !== null) {
1199
+ batch.held.push(event.data);
1200
+ return;
1201
+ }
1202
+ if (batch) {
1203
+ // A delta cannot precede the capture of an armed reseed (the feed
1204
+ // discards those); treat an impossible ordering as live output.
1205
+ this.#flushBatch(channel, null);
1206
+ }
1207
+ this.#emitOutput(channel, event.data);
1208
+ return;
1209
+ }
1210
+ case "cursor": {
1211
+ if (channel.batch) {
1212
+ this.#flushBatch(channel, { x: event.x, y: event.y });
1213
+ return;
1214
+ }
1215
+ this.#sendPaneFrame(channel, {
1216
+ type: "cursor",
1217
+ pane: channel.semanticPaneId,
1218
+ seq: this.#nextSeq(channel),
1219
+ x: event.x,
1220
+ y: event.y,
1221
+ });
1222
+ return;
1223
+ }
1224
+ case "flow": {
1225
+ if (channel.batch)
1226
+ this.#flushBatch(channel, null);
1227
+ this.#sendPaneFrame(channel, {
1228
+ type: "flow",
1229
+ pane: channel.semanticPaneId,
1230
+ seq: this.#nextSeq(channel),
1231
+ state: event.state,
1232
+ reason: event.reason,
1233
+ });
1234
+ return;
1235
+ }
1236
+ case "closed": {
1237
+ if (channel.batch)
1238
+ this.#flushBatch(channel, null);
1239
+ this.#emitClosed(channel);
1240
+ this.#closeIfAllPanesGone();
1241
+ return;
1242
+ }
1243
+ }
1244
+ }
1245
+ /** The atomic batch arrives in ONE synchronous callback burst; a microtask
1246
+ * guard flushes the degraded no-cursor path without reordering anything. */
1247
+ #armBatchGuard(channel) {
1248
+ const batch = channel.batch;
1249
+ if (!batch || batch.guardArmed)
1250
+ return;
1251
+ batch.guardArmed = true;
1252
+ queueMicrotask(() => {
1253
+ if (channel.batch === batch)
1254
+ this.#flushBatch(channel, null);
1255
+ });
1256
+ }
1257
+ #flushBatch(channel, cursor) {
1258
+ const batch = channel.batch;
1259
+ channel.batch = null;
1260
+ if (!batch || this.#closed || channel.closed)
1261
+ return;
1262
+ let seed = batch.seed ?? new Uint8Array(0);
1263
+ if (seed.byteLength > PANE_STREAM_MAX_SEED_BYTES) {
1264
+ // Pathological guard: keep the tail, resynchronizing at a line seam.
1265
+ let start = seed.byteLength - PANE_STREAM_MAX_SEED_BYTES;
1266
+ while (start < seed.byteLength && seed[start] !== 0x0a)
1267
+ start += 1;
1268
+ seed = seed.subarray(Math.min(start + 1, seed.byteLength));
1269
+ }
1270
+ const held = chunkBytes(concatBytes(batch.held), PANE_STREAM_MAX_OUTPUT_BYTES).slice(0, PANE_STREAM_MAX_HELD_DELTAS);
1271
+ this.#sendPaneFrame(channel, {
1272
+ type: "seed-batch",
1273
+ pane: channel.semanticPaneId,
1274
+ seq: this.#nextSeq(channel),
1275
+ reset: batch.reset,
1276
+ seed: Buffer.from(seed).toString("base64"),
1277
+ held: held.map((chunk) => Buffer.from(chunk).toString("base64")),
1278
+ cursor,
1279
+ });
1280
+ }
1281
+ #emitOutput(channel, data) {
1282
+ for (const chunk of chunkBytes(data, PANE_STREAM_MAX_OUTPUT_BYTES)) {
1283
+ this.#sendPaneFrame(channel, {
1284
+ type: "output",
1285
+ pane: channel.semanticPaneId,
1286
+ seq: this.#nextSeq(channel),
1287
+ data: Buffer.from(chunk).toString("base64"),
1288
+ });
1289
+ }
1290
+ }
1291
+ #emitClosed(channel) {
1292
+ if (channel.closed)
1293
+ return;
1294
+ channel.closed = true;
1295
+ const sub = channel.sub;
1296
+ channel.sub = null;
1297
+ if (sub)
1298
+ void sub.close().catch(() => undefined);
1299
+ this.#sendPaneFrame(channel, {
1300
+ type: "closed",
1301
+ pane: channel.semanticPaneId,
1302
+ seq: this.#nextSeq(channel),
1303
+ });
1304
+ this.#ledger.forgetPane(this.#clientId, channel.semanticPaneId);
1305
+ }
1306
+ #onLayoutAuthority(snapshot) {
1307
+ if (this.#closed || !this.#semanticExpectedPaneIds || !this.#semanticRuntimeSessionId)
1308
+ return;
1309
+ if (snapshot.session !== this.#descriptor.sessionName ||
1310
+ snapshot.runtimeSessionId !== this.#semanticRuntimeSessionId ||
1311
+ snapshot.topologyEpoch <= this.#semanticTopologyEpoch ||
1312
+ snapshot.layouts.length > PANE_STREAM_MAX_PANES) {
1313
+ this.#failTopologyChanged();
1314
+ return;
1315
+ }
1316
+ const frames = this.#validateInitialLayout(snapshot.layouts, this.#semanticExpectedPaneIds);
1317
+ if (!frames) {
1318
+ this.#failTopologyChanged();
1319
+ return;
1320
+ }
1321
+ this.#semanticTopologyEpoch = snapshot.topologyEpoch;
1322
+ this.#semanticLayouts.clear();
1323
+ for (const event of snapshot.layouts)
1324
+ this.#semanticLayouts.set(event.semanticWindowId, event);
1325
+ this.#sendFrame(null, {
1326
+ type: "layout-snapshot",
1327
+ topologyEpoch: snapshot.topologyEpoch,
1328
+ layouts: frames,
1329
+ });
1330
+ }
1331
+ #onLayout(event) {
1332
+ if (this.#closed)
1333
+ return;
1334
+ /*
1335
+ * Every window of the session, not only the leased panes' own.
1336
+ *
1337
+ * The lease is SESSION-scoped by design — one socket for one workspace —
1338
+ * and layout is that session's geometry rather than a per-pane stream. A
1339
+ * client that saw only its leased window could not render a window LIST at
1340
+ * all, which is what the layout-faithful view is built from (m50), and it
1341
+ * would have to lease every pane in the session to get one.
1342
+ *
1343
+ * Nothing new crosses the boundary: the frame carries semantic pane ids and
1344
+ * cell rectangles, and the same renderer is already told every pane's
1345
+ * semantic identity by the application-shell inventory. No runtime tmux id,
1346
+ * command, cwd or credential appears here.
1347
+ */
1348
+ const frame = this.#layoutFrame(event);
1349
+ if (!frame) {
1350
+ this.#failTopologyChanged();
1351
+ return;
1352
+ }
1353
+ this.#sendFrame(null, frame);
1354
+ }
1355
+ #layoutFrame(event) {
1356
+ const frame = {
1357
+ type: "layout",
1358
+ semanticWindowId: event.semanticWindowId,
1359
+ windowName: event.windowName === null ? null : event.windowName.slice(0, 256),
1360
+ currentWindow: event.currentWindow,
1361
+ cols: event.cols,
1362
+ rows: event.rows,
1363
+ zoomed: event.zoomed,
1364
+ paneBorderStatus: event.paneBorderStatus,
1365
+ modeKeys: event.modeKeys,
1366
+ panes: event.panes.map((pane) => ({
1367
+ pane: pane.semanticPaneId,
1368
+ displayName: pane.displayName,
1369
+ displayNameSource: pane.displayNameSource,
1370
+ left: pane.left,
1371
+ top: pane.top,
1372
+ width: pane.width,
1373
+ height: pane.height,
1374
+ active: pane.active,
1375
+ })),
1376
+ };
1377
+ // Layout carries user-authored names and unbounded tmux geometry; gate it
1378
+ // through the schema and skip rather than ever sending an invalid frame.
1379
+ const parsed = PaneStreamServerFrameSchemaZ.safeParse(frame);
1380
+ return parsed.success ? parsed.data : null;
1381
+ }
1382
+ #validateInitialLayout(events, expectedPaneIds) {
1383
+ if (events.length === 0)
1384
+ return null;
1385
+ const windows = new Set();
1386
+ const panes = [];
1387
+ const frames = [];
1388
+ let currentWindows = 0;
1389
+ for (const event of events) {
1390
+ if (event.session !== this.#descriptor.sessionName ||
1391
+ typeof event.semanticWindowId !== "string" ||
1392
+ windows.has(event.semanticWindowId))
1393
+ return null;
1394
+ windows.add(event.semanticWindowId);
1395
+ if (event.currentWindow)
1396
+ currentWindows += 1;
1397
+ const frame = this.#layoutFrame(event);
1398
+ if (!frame || frame.type !== "layout")
1399
+ return null;
1400
+ frames.push(frame);
1401
+ for (const pane of event.panes) {
1402
+ if (typeof pane.semanticPaneId !== "string")
1403
+ return null;
1404
+ panes.push(pane.semanticPaneId);
1405
+ }
1406
+ }
1407
+ panes.sort();
1408
+ if (currentWindows !== 1 ||
1409
+ new Set(panes).size !== panes.length ||
1410
+ events.some((event) => event.zoomed && event.panes.length !== 1) ||
1411
+ (panes.length !== expectedPaneIds.length && !events.some((event) => event.zoomed)) ||
1412
+ panes.some((pane) => !expectedPaneIds.includes(pane)))
1413
+ return null;
1414
+ return frames;
1415
+ }
1416
+ #failTopologyChanged() {
1417
+ if (this.#closed)
1418
+ return;
1419
+ this.#sendFrame(null, {
1420
+ type: "error",
1421
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
1422
+ code: "topology-changed",
1423
+ retryable: true,
1424
+ });
1425
+ this.close(1012, "topology-changed");
1426
+ }
1427
+ // ── Send path + flow ledger ───────────────────────────────────────────────
1428
+ #nextSeq(channel) {
1429
+ channel.serverSeq += 1;
1430
+ return channel.serverSeq;
1431
+ }
1432
+ #sendPaneFrame(channel, frame) {
1433
+ channel.sentPaneFrames += 1;
1434
+ this.#sendFrame(channel.semanticPaneId, frame);
1435
+ }
1436
+ #sendFrame(pane, frame) {
1437
+ if (this.#closed || this.#socket.readyState !== WS_OPEN)
1438
+ return;
1439
+ const encoded = JSON.stringify(frame);
1440
+ const bytes = Buffer.byteLength(encoded, "utf8");
1441
+ if (pane !== null) {
1442
+ this.#ledger.take(this.#clientId, pane, "ws-send-buffer", bytes);
1443
+ if (this.#deliveryAcks)
1444
+ this.#ledger.take(this.#clientId, pane, "renderer-backlog", 1);
1445
+ }
1446
+ this.#sendQueue.push({ pane, remaining: bytes });
1447
+ this.#sentBytesTotal += bytes;
1448
+ try {
1449
+ this.#socket.send(encoded, { binary: false });
1450
+ }
1451
+ catch {
1452
+ this.close(1011, "stream-unavailable");
1453
+ return;
1454
+ }
1455
+ // Stall is judged on the drain tick, never synchronously at send: the
1456
+ // socket must get its chance to drain first, or a single seed batch
1457
+ // larger than the budget would park even a healthy client.
1458
+ this.#ensureDrainTick();
1459
+ }
1460
+ #evaluateStall(pane) {
1461
+ const channel = this.#panes.get(pane);
1462
+ if (!channel || channel.closed || channel.frozenByWire || !channel.sub)
1463
+ return;
1464
+ if (this.#ledger.isStalled(this.#clientId, pane)) {
1465
+ // Park exactly this subscriber: siblings and other clients keep flowing;
1466
+ // upstream %pause only engages when every subscriber of the pane parks.
1467
+ channel.frozenByWire = true;
1468
+ channel.sub.freeze();
1469
+ }
1470
+ }
1471
+ #evaluateResume(pane) {
1472
+ const channel = this.#panes.get(pane);
1473
+ if (!channel || channel.closed || !channel.frozenByWire || !channel.sub)
1474
+ return;
1475
+ if (this.#ledger.shouldResume(this.#clientId, pane)) {
1476
+ channel.frozenByWire = false;
1477
+ channel.sub.thaw();
1478
+ }
1479
+ }
1480
+ #ensureDrainTick() {
1481
+ if (this.#cancelDrainTick || this.#closed || this.#sendQueue.length === 0)
1482
+ return;
1483
+ this.#cancelDrainTick = this.#schedule(() => {
1484
+ this.#cancelDrainTick = null;
1485
+ this.#drainNow();
1486
+ this.#ensureDrainTick();
1487
+ }, this.#drainTickMs);
1488
+ }
1489
+ #drainNow() {
1490
+ if (this.#closed)
1491
+ return;
1492
+ const buffered = this.#socket.bufferedAmount ?? 0;
1493
+ if (!Number.isSafeInteger(buffered) || buffered < 0) {
1494
+ this.close(1011, "stream-unavailable");
1495
+ return;
1496
+ }
1497
+ if (buffered > this.#maxSocketBufferedBytes) {
1498
+ this.close(1013, "output-backpressure");
1499
+ return;
1500
+ }
1501
+ let newlyDrained = this.#sentBytesTotal - buffered - this.#drainedBytesTotal;
1502
+ while (newlyDrained > 0 && this.#sendQueue.length > 0) {
1503
+ const head = this.#sendQueue[0];
1504
+ const applied = Math.min(newlyDrained, head.remaining);
1505
+ head.remaining -= applied;
1506
+ newlyDrained -= applied;
1507
+ this.#drainedBytesTotal += applied;
1508
+ if (head.pane !== null) {
1509
+ this.#ledger.give(this.#clientId, head.pane, "ws-send-buffer", applied);
1510
+ }
1511
+ if (head.remaining === 0)
1512
+ this.#sendQueue.shift();
1513
+ }
1514
+ for (const [pane, channel] of this.#panes) {
1515
+ if (channel.frozenByWire)
1516
+ this.#evaluateResume(pane);
1517
+ else
1518
+ this.#evaluateStall(pane);
1519
+ const waiters = this.#semanticDrainWaiters.get(pane);
1520
+ if (waiters && this.#ledger.shouldResume(this.#clientId, pane)) {
1521
+ this.#semanticDrainWaiters.delete(pane);
1522
+ for (const resolve of waiters)
1523
+ resolve();
1524
+ }
1525
+ }
1526
+ }
1527
+ // ── Client frames ─────────────────────────────────────────────────────────
1528
+ #onMessage = (data, isBinary) => {
1529
+ if (this.#closed)
1530
+ return;
1531
+ let callbackAtSharedMicros = null;
1532
+ let ingressAtSharedMicros = null;
1533
+ let ingressAtMicros = null;
1534
+ if (this.#observability?.enabled) {
1535
+ try {
1536
+ ingressAtMicros = this.#observability.nowMicros();
1537
+ }
1538
+ catch {
1539
+ // Diagnostics cannot alter protocol truth.
1540
+ }
1541
+ }
1542
+ const byteLength = rawDataByteLength(data, PANE_STREAM_MAX_CONTROL_BYTES);
1543
+ if (isBinary || byteLength === 0 || byteLength > PANE_STREAM_MAX_CONTROL_BYTES) {
1544
+ this.#failProtocol("protocol-error");
1545
+ return;
1546
+ }
1547
+ const raw = rawDataToBuffer(data);
1548
+ if (this.#diagnosticSharedRawMicros && hasCanonicalInputFramePrefix(raw)) {
1549
+ try {
1550
+ callbackAtSharedMicros = this.#sharedMicros();
1551
+ }
1552
+ catch {
1553
+ // Preserve the process-local callback timestamp and product traffic.
1554
+ }
1555
+ }
1556
+ let frame;
1557
+ try {
1558
+ frame = PaneStreamClientFrameSchemaZ.parse(strictJsonParse(raw));
1559
+ }
1560
+ catch {
1561
+ this.#failProtocol("protocol-error");
1562
+ return;
1563
+ }
1564
+ if (this.#diagnosticSharedRawMicros) {
1565
+ try {
1566
+ this.#diagnosticAfterFrameParse?.();
1567
+ }
1568
+ catch {
1569
+ // Test-only diagnostics cannot alter protocol truth.
1570
+ }
1571
+ if (frame.type === "input") {
1572
+ try {
1573
+ ingressAtSharedMicros = this.#sharedMicros();
1574
+ }
1575
+ catch {
1576
+ // Preserve callback timing and product traffic without a parse-complete sample.
1577
+ }
1578
+ }
1579
+ }
1580
+ if (frame.type === "clock-probe") {
1581
+ if (!this.#diagnosticCapabilities.includes("clock-bounds-v1") ||
1582
+ frame.requestId !== this.#binding.requestId ||
1583
+ frame.probe !== this.#nextClockProbe)
1584
+ return this.#failProtocol("protocol-error");
1585
+ this.#nextClockProbe += 1;
1586
+ try {
1587
+ ingressAtSharedMicros = this.#sharedMicros();
1588
+ }
1589
+ catch {
1590
+ return;
1591
+ }
1592
+ try {
1593
+ const daemonSendMicros = this.#sharedMicros();
1594
+ this.#sendFrame(null, {
1595
+ type: "clock-probe-ack",
1596
+ requestId: this.#binding.requestId,
1597
+ daemonInstanceId: this.#binding.daemonInstanceId,
1598
+ probe: frame.probe,
1599
+ clientSendMicros: frame.clientSendMicros,
1600
+ daemonReceiveMicros: ingressAtSharedMicros,
1601
+ daemonSendMicros,
1602
+ });
1603
+ }
1604
+ catch {
1605
+ // Client timeout reports calibration unavailable; product traffic continues.
1606
+ }
1607
+ return;
1608
+ }
1609
+ if (frame.type === "consumed") {
1610
+ this.#acceptConsumed(frame.pane, frame.seq);
1611
+ return;
1612
+ }
1613
+ if (frame.type === "presence") {
1614
+ if (!this.#acceptAuthorityGeneration(frame.generation))
1615
+ return;
1616
+ this.#usesExplicitAuthority = true;
1617
+ if (!this.#sessionRuntimeBinding?.updatePresence)
1618
+ return this.#failProtocol("protocol-error");
1619
+ const snapshot = this.#sessionRuntimeBinding.updatePresence(frame.state);
1620
+ if (!this.#sessionRuntimeBinding.onAuthoritySnapshot)
1621
+ this.#sendAuthoritySnapshot(snapshot);
1622
+ return;
1623
+ }
1624
+ if (frame.type === "activity") {
1625
+ if (!this.#acceptAuthorityGeneration(frame.generation))
1626
+ return;
1627
+ this.#usesExplicitAuthority = true;
1628
+ if (!this.#sessionRuntimeBinding?.noteActivity)
1629
+ return this.#failProtocol("protocol-error");
1630
+ const snapshot = this.#sessionRuntimeBinding.noteActivity(frame.activity);
1631
+ if (!this.#sessionRuntimeBinding.onAuthoritySnapshot)
1632
+ this.#sendAuthoritySnapshot(snapshot);
1633
+ return;
1634
+ }
1635
+ if (frame.type === "authority-request") {
1636
+ if (!this.#acceptAuthorityGeneration(frame.generation))
1637
+ return;
1638
+ this.#usesExplicitAuthority = true;
1639
+ if (!this.#sessionRuntimeBinding?.requestAuthority ||
1640
+ !this.#sessionRuntimeBinding.authoritySnapshot)
1641
+ return this.#failProtocol("protocol-error");
1642
+ const lease = this.#sessionRuntimeBinding.requestAuthority(frame.authority);
1643
+ if (lease)
1644
+ this.#requestedAuthorities.add(frame.authority);
1645
+ this.#sendFrame(null, {
1646
+ type: "authority-receipt",
1647
+ requestId: frame.requestId,
1648
+ authority: frame.authority,
1649
+ status: lease ? "granted" : "rejected",
1650
+ lease,
1651
+ snapshot: this.#sessionRuntimeBinding.authoritySnapshot(),
1652
+ });
1653
+ return;
1654
+ }
1655
+ if (frame.type === "authority-release") {
1656
+ if (!this.#acceptAuthorityGeneration(frame.generation))
1657
+ return;
1658
+ this.#usesExplicitAuthority = true;
1659
+ this.#requestedAuthorities.delete(frame.authority);
1660
+ if (!this.#sessionRuntimeBinding?.releaseAuthority)
1661
+ return this.#failProtocol("protocol-error");
1662
+ const snapshot = this.#sessionRuntimeBinding.releaseAuthority(frame.authority);
1663
+ this.#sendFrame(null, {
1664
+ type: "authority-receipt",
1665
+ requestId: frame.requestId,
1666
+ authority: frame.authority,
1667
+ status: "released",
1668
+ lease: null,
1669
+ snapshot,
1670
+ });
1671
+ return;
1672
+ }
1673
+ if (frame.type === "terminal-delivery-ack") {
1674
+ const channel = this.#deliveryChannel(frame.ack);
1675
+ if (!channel)
1676
+ return;
1677
+ channel.delivery.ack({ ...frame.ack, workspaceName: this.#descriptor.sessionName });
1678
+ return;
1679
+ }
1680
+ if (frame.type === "terminal-delivery-nack") {
1681
+ const channel = this.#deliveryChannel(frame.nack);
1682
+ if (!channel)
1683
+ return;
1684
+ channel.delivery.nack({ ...frame.nack, workspaceName: this.#descriptor.sessionName });
1685
+ return;
1686
+ }
1687
+ if (frame.type === "terminal-delivery-visibility") {
1688
+ const channel = this.#deliveryChannel({
1689
+ workspaceName: frame.workspaceName,
1690
+ semanticPaneId: frame.pane,
1691
+ generation: frame.generation,
1692
+ incarnation: frame.incarnation,
1693
+ deliveryNonce: frame.deliveryNonce,
1694
+ });
1695
+ if (!channel)
1696
+ return;
1697
+ channel.delivery.setVisibility(frame.visibility);
1698
+ return;
1699
+ }
1700
+ if (frame.type === "semantic-intent") {
1701
+ this.#acceptSemanticIntent(frame.operationId, frame.intent);
1702
+ return;
1703
+ }
1704
+ if (frame.type === "viewport") {
1705
+ if (!this.#descriptor.terminalDelivery ||
1706
+ this.#descriptor.viewerMode !== "interactive" ||
1707
+ frame.seq !== this.#nextViewportSeq ||
1708
+ (this.#usesExplicitAuthority && !this.#requestedAuthorities.has("geometry"))) {
1709
+ this.#failProtocol("input-rejected");
1710
+ return;
1711
+ }
1712
+ if (!this.#prepareInputAuthority(true))
1713
+ return;
1714
+ this.#nextViewportSeq += 1;
1715
+ try {
1716
+ this.#sessionRuntimeBinding.fitViewport(frame.authorityLease, frame.cols, frame.rows);
1717
+ this.#sendFrame(null, {
1718
+ type: "viewport-ack",
1719
+ seq: frame.seq,
1720
+ cols: frame.cols,
1721
+ rows: frame.rows,
1722
+ outcome: "ok",
1723
+ authorityLease: frame.authorityLease,
1724
+ });
1725
+ }
1726
+ catch (error) {
1727
+ if (error instanceof SessionRuntimeControllerLeaseError &&
1728
+ (error.code === "invalid-client-capability" || error.code === "stale-controller-lease")) {
1729
+ this.#sendFrame(null, {
1730
+ type: "viewport-ack",
1731
+ seq: frame.seq,
1732
+ cols: frame.cols,
1733
+ rows: frame.rows,
1734
+ outcome: "geometry-authority-conflict",
1735
+ authorityLease: frame.authorityLease,
1736
+ });
1737
+ return;
1738
+ }
1739
+ this.#failProtocol("input-rejected");
1740
+ }
1741
+ return;
1742
+ }
1743
+ this.#acceptInput(frame.pane, frame.seq, frame.kind, frame.data, byteLength, frame.performanceTraceId, frame.causalProbe, ingressAtMicros, callbackAtSharedMicros, ingressAtSharedMicros);
1744
+ };
1745
+ #acceptAuthorityGeneration(generation) {
1746
+ if (!this.#sessionRuntimeBinding || generation !== this.#sessionRuntimeBinding.generation) {
1747
+ this.#failProtocol("protocol-error");
1748
+ return false;
1749
+ }
1750
+ return true;
1751
+ }
1752
+ #sendAuthoritySnapshot(snapshot) {
1753
+ this.#sendFrame(null, { type: "authority-snapshot", snapshot });
1754
+ }
1755
+ #prepareInputAuthority(geometry) {
1756
+ if (this.#usesExplicitAuthority) {
1757
+ const required = geometry ? "geometry" : "input";
1758
+ if (!this.#requestedAuthorities.has(required)) {
1759
+ this.#failProtocol("input-rejected");
1760
+ return false;
1761
+ }
1762
+ return true;
1763
+ }
1764
+ if (this.#legacyInputActivated && (!geometry || this.#legacyGeometryActivated))
1765
+ return true;
1766
+ try {
1767
+ // A genuine old binding acquired at admission and has no adapter method.
1768
+ // New deferred bindings activate only here, before explicit mode exists.
1769
+ this.#sessionRuntimeBinding?.activateLegacyAuthority?.(geometry);
1770
+ this.#legacyInputActivated = true;
1771
+ if (geometry)
1772
+ this.#legacyGeometryActivated = true;
1773
+ return true;
1774
+ }
1775
+ catch {
1776
+ this.#failProtocol("input-rejected");
1777
+ return false;
1778
+ }
1779
+ }
1780
+ #deliveryChannel(address) {
1781
+ const channel = this.#panes.get(address.semanticPaneId);
1782
+ const expected = channel?.deliveryAddress;
1783
+ if (!channel?.delivery ||
1784
+ !expected ||
1785
+ expected.workspaceName !== address.workspaceName ||
1786
+ expected.generation !== address.generation ||
1787
+ expected.deliveryNonce !== address.deliveryNonce ||
1788
+ expected.incarnation === null) {
1789
+ this.#failProtocol("protocol-error");
1790
+ return null;
1791
+ }
1792
+ // More than one canonical delivery can legitimately be in flight. The
1793
+ // cached address records only the newest incarnation, so comparing an ACK
1794
+ // against that single value rejects an earlier valid delivery during a
1795
+ // reseed/reconnect burst. Generation + one-use delivery nonce identify the
1796
+ // channel here; the retained delivery owner validates incarnation,
1797
+ // transaction and revision ordering authoritatively below.
1798
+ return channel;
1799
+ }
1800
+ #acceptSemanticIntent(operationId, intent) {
1801
+ if (!this.#descriptor.terminalDelivery || this.#descriptor.viewerMode !== "interactive") {
1802
+ this.#failProtocol("input-rejected");
1803
+ return;
1804
+ }
1805
+ if (!this.#prepareInputAuthority(false))
1806
+ return;
1807
+ void this.#sessionRuntimeBinding.submitIntent(operationId, intent)
1808
+ .then((result) => {
1809
+ this.#sendFrame(null, {
1810
+ type: "semantic-intent-ack",
1811
+ operationId,
1812
+ outcome: { status: "applied", result: result ?? null },
1813
+ });
1814
+ })
1815
+ .catch((error) => {
1816
+ const backendRefusal = semanticBackendRefusal(error);
1817
+ const rawCode = backendRefusal ??
1818
+ (error && typeof error === "object" && "code" in error
1819
+ ? String(error.code)
1820
+ : error && typeof error === "object" && "outcome" in error
1821
+ ? `intent-${String(error.outcome)}`
1822
+ : "stream-unavailable");
1823
+ const code = [
1824
+ "controller-conflict",
1825
+ "controller-target-unavailable",
1826
+ "stale-controller-lease",
1827
+ "invalid-client-capability",
1828
+ "invalid-source-pane-binding",
1829
+ "intent-session-mismatch",
1830
+ "intent-rejected",
1831
+ "intent-timed-out",
1832
+ "pane_inventory_not_ready",
1833
+ "pane_identity_changed_before_select",
1834
+ "pane_not_active",
1835
+ ].includes(rawCode)
1836
+ ? rawCode
1837
+ : "stream-unavailable";
1838
+ this.#sendFrame(null, {
1839
+ type: "semantic-intent-ack",
1840
+ operationId,
1841
+ outcome: {
1842
+ status: "rejected",
1843
+ code,
1844
+ message: error instanceof Error ? error.message.slice(0, 512) : "Semantic intent failed",
1845
+ },
1846
+ });
1847
+ });
1848
+ }
1849
+ #acceptConsumed(pane, seq) {
1850
+ const channel = this.#panes.get(pane);
1851
+ if (!this.#deliveryAcks ||
1852
+ !channel ||
1853
+ seq <= channel.consumedSeq ||
1854
+ seq > channel.sentPaneFrames) {
1855
+ this.#failProtocol("protocol-error");
1856
+ return;
1857
+ }
1858
+ const returned = seq - channel.consumedSeq;
1859
+ channel.consumedSeq = seq;
1860
+ this.#ledger.give(this.#clientId, pane, "renderer-backlog", returned);
1861
+ this.#evaluateResume(pane);
1862
+ }
1863
+ #acceptInput(pane, seq, kind, data, frameBytes, performanceTraceId, causalProbe, ingressAtMicros = null, callbackAtSharedMicros = null, ingressAtSharedMicros = null) {
1864
+ if (this.#descriptor.viewerMode !== "interactive") {
1865
+ this.#failProtocol("input-rejected");
1866
+ return;
1867
+ }
1868
+ const channel = this.#panes.get(pane);
1869
+ const semanticDelivery = this.#descriptor.terminalDelivery !== null;
1870
+ if (!channel ||
1871
+ channel.closed ||
1872
+ (semanticDelivery ? !channel.delivery : !channel.sub) ||
1873
+ seq !== channel.nextInputSeq) {
1874
+ this.#failProtocol("input-rejected");
1875
+ return;
1876
+ }
1877
+ if (causalProbe) {
1878
+ const address = channel.deliveryAddress;
1879
+ if (!this.#causalCellCapability ||
1880
+ !address ||
1881
+ causalProbe.clientId !== this.#sessionRuntimeBinding?.clientId ||
1882
+ causalProbe.transportNonce !== this.#binding.requestId ||
1883
+ causalProbe.deliveryNonce !== address.deliveryNonce ||
1884
+ causalProbe.inputSequence !== seq ||
1885
+ causalProbe.semanticPaneId !== pane ||
1886
+ causalProbe.generation !== address.generation ||
1887
+ causalProbe.incarnation !== address.incarnation) {
1888
+ this.#failProtocol("input-rejected");
1889
+ return;
1890
+ }
1891
+ }
1892
+ const now = this.#now();
1893
+ if (now < this.#inputWindowStartedAt ||
1894
+ now - this.#inputWindowStartedAt >= this.#inputRateWindowMs) {
1895
+ this.#inputWindowStartedAt = now;
1896
+ this.#inputWindowFrames = 0;
1897
+ this.#inputWindowBytes = 0;
1898
+ }
1899
+ if (this.#inputWindowFrames + 1 > this.#maxInputFrames ||
1900
+ this.#inputWindowBytes + frameBytes > this.#maxInputBytes) {
1901
+ this.#failProtocol("input-rejected");
1902
+ return;
1903
+ }
1904
+ if (!this.#prepareInputAuthority(false))
1905
+ return;
1906
+ let trace = null;
1907
+ if (performanceTraceId && this.#observability?.enabled) {
1908
+ try {
1909
+ trace = this.#observability.beginTrace("terminal-input-to-paint", {
1910
+ generation: this.#sessionRuntimeBinding.generation,
1911
+ incarnation: causalProbe?.incarnation ?? channel.deliveryAddress?.incarnation ?? null,
1912
+ }, performanceTraceId);
1913
+ if (trace && ingressAtMicros !== null) {
1914
+ this.#observability.recordSpan("transport", "pane-stream-socket-message-callback-entry", ingressAtMicros, ingressAtMicros, trace, callbackAtSharedMicros === null
1915
+ ? undefined
1916
+ : {
1917
+ startedAtMicros: callbackAtSharedMicros,
1918
+ endedAtMicros: callbackAtSharedMicros,
1919
+ });
1920
+ this.#observability.recordSpan("transport", "pane-stream-input-frame-ingress", ingressAtMicros, ingressAtMicros, trace, ingressAtSharedMicros === null
1921
+ ? undefined
1922
+ : { startedAtMicros: ingressAtSharedMicros, endedAtMicros: ingressAtSharedMicros });
1923
+ }
1924
+ }
1925
+ catch {
1926
+ trace = null;
1927
+ }
1928
+ }
1929
+ this.#inputWindowFrames += 1;
1930
+ this.#inputWindowBytes += frameBytes;
1931
+ channel.nextInputSeq += 1;
1932
+ try {
1933
+ this.#sessionRuntimeBinding.assertController(pane);
1934
+ if (semanticDelivery)
1935
+ this.#sessionRuntimeBinding.sendInput(pane, { kind, data }, performanceTraceId, causalProbe, causalProbe
1936
+ ? (result) => {
1937
+ if (this.#closed)
1938
+ return;
1939
+ if (result.status === "proved") {
1940
+ this.#sendFrame(null, { type: "causal-cell-proof", proof: result.proof });
1941
+ }
1942
+ else {
1943
+ this.#sendFrame(null, {
1944
+ type: "causal-cell-failure",
1945
+ failure: {
1946
+ version: 1,
1947
+ capability: "causal-cell-v1",
1948
+ traceId: result.traceId,
1949
+ reason: result.reason,
1950
+ ...(result.diagnostic ? { diagnostic: result.diagnostic } : {}),
1951
+ },
1952
+ });
1953
+ }
1954
+ }
1955
+ : undefined);
1956
+ else if (kind === "text")
1957
+ channel.sub.sendText(data);
1958
+ else
1959
+ channel.sub.sendKey(data);
1960
+ let ackStartedAtMicros = null;
1961
+ let ackStartedAtSharedMicros = null;
1962
+ if (trace) {
1963
+ try {
1964
+ ackStartedAtMicros = this.#observability.nowMicros();
1965
+ }
1966
+ catch {
1967
+ // Diagnostics cannot alter protocol truth.
1968
+ }
1969
+ if (this.#diagnosticSharedRawMicros) {
1970
+ try {
1971
+ ackStartedAtSharedMicros = this.#sharedMicros();
1972
+ }
1973
+ catch {
1974
+ // Preserve process-local ACK diagnostics.
1975
+ }
1976
+ }
1977
+ }
1978
+ sendControl(this.#socket, { type: "input-ack", pane, seq });
1979
+ if (trace && ackStartedAtMicros !== null) {
1980
+ let ackEndedAtMicros = null;
1981
+ try {
1982
+ ackEndedAtMicros = this.#observability.nowMicros();
1983
+ }
1984
+ catch {
1985
+ // Diagnostics cannot alter protocol truth.
1986
+ }
1987
+ let ackEndedAtSharedMicros = null;
1988
+ if (ackStartedAtSharedMicros !== null) {
1989
+ try {
1990
+ ackEndedAtSharedMicros = this.#sharedMicros();
1991
+ }
1992
+ catch {
1993
+ // Preserve process-local ACK diagnostics.
1994
+ }
1995
+ }
1996
+ if (ackEndedAtMicros !== null) {
1997
+ try {
1998
+ this.#observability.recordSpan("transport", "pane-stream-input-ack-socket-send", ackStartedAtMicros, ackEndedAtMicros, trace, ackStartedAtSharedMicros === null || ackEndedAtSharedMicros === null
1999
+ ? undefined
2000
+ : {
2001
+ startedAtMicros: ackStartedAtSharedMicros,
2002
+ endedAtMicros: ackEndedAtSharedMicros,
2003
+ });
2004
+ }
2005
+ catch {
2006
+ // Diagnostics cannot alter protocol truth.
2007
+ }
2008
+ }
2009
+ }
2010
+ }
2011
+ catch {
2012
+ this.close(1011, "stream-unavailable");
2013
+ }
2014
+ }
2015
+ #failProtocol(code) {
2016
+ try {
2017
+ sendControl(this.#socket, {
2018
+ type: "error",
2019
+ protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
2020
+ code,
2021
+ retryable: false,
2022
+ });
2023
+ }
2024
+ catch {
2025
+ this.close(1011, "stream-unavailable");
2026
+ return;
2027
+ }
2028
+ this.close(1008, code);
2029
+ }
2030
+ #closeIfAllPanesGone() {
2031
+ if (this.#closed)
2032
+ return;
2033
+ for (const channel of this.#panes.values()) {
2034
+ if (!channel.closed)
2035
+ return;
2036
+ }
2037
+ this.close(1000, "panes-closed");
2038
+ }
2039
+ #onSocketClose = () => this.close(1000, "peer-closed");
2040
+ }
2041
+ function concatBytes(chunks) {
2042
+ if (chunks.length === 0)
2043
+ return new Uint8Array(0);
2044
+ if (chunks.length === 1)
2045
+ return chunks[0];
2046
+ let total = 0;
2047
+ for (const chunk of chunks)
2048
+ total += chunk.byteLength;
2049
+ const merged = new Uint8Array(total);
2050
+ let offset = 0;
2051
+ for (const chunk of chunks) {
2052
+ merged.set(chunk, offset);
2053
+ offset += chunk.byteLength;
2054
+ }
2055
+ return merged;
2056
+ }
2057
+ function chunkBytes(data, maxChunk) {
2058
+ if (data.byteLength === 0)
2059
+ return [];
2060
+ if (data.byteLength <= maxChunk)
2061
+ return [data];
2062
+ const chunks = [];
2063
+ for (let offset = 0; offset < data.byteLength; offset += maxChunk) {
2064
+ chunks.push(data.subarray(offset, Math.min(offset + maxChunk, data.byteLength)));
2065
+ }
2066
+ return chunks;
2067
+ }