tmux-ide 2.8.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 (1431) hide show
  1. package/README.md +88 -125
  2. package/bin/cli.js +80738 -13789
  3. package/package.json +73 -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__/daemon-events.test.ts +400 -0
  15. package/packages/contracts/src/__tests__/daemon-resources.test.ts +143 -0
  16. package/packages/contracts/src/__tests__/daemon-wire.test.ts +117 -0
  17. package/packages/contracts/src/__tests__/desktop-host.test.ts +269 -0
  18. package/packages/contracts/src/__tests__/desktop-missions.test.ts +211 -0
  19. package/packages/contracts/src/__tests__/experience-conformance.test.ts +153 -0
  20. package/packages/contracts/src/__tests__/experience-kernel-boundary.test.ts +109 -0
  21. package/packages/contracts/src/__tests__/experience-shell.test.ts +65 -0
  22. package/packages/contracts/src/__tests__/fixtures/daemon-wire-v2.json +35 -0
  23. package/packages/contracts/src/__tests__/fleet-agent-graph.test.ts +231 -0
  24. package/packages/contracts/src/__tests__/fleet-catalog.test.ts +268 -0
  25. package/packages/contracts/src/__tests__/fleet-lifecycle.test.ts +62 -0
  26. package/packages/contracts/src/__tests__/focus-overlay.test.ts +110 -0
  27. package/packages/contracts/src/__tests__/ide-config.test.ts +18 -0
  28. package/packages/contracts/src/__tests__/issue-error.test.ts +78 -0
  29. package/packages/contracts/src/__tests__/mission-projections.test.ts +186 -0
  30. package/packages/contracts/src/__tests__/missions.test.ts +272 -0
  31. package/packages/contracts/src/__tests__/multiplexer-verbs.test.ts +240 -0
  32. package/packages/contracts/src/__tests__/pane-appearance.test.ts +146 -0
  33. package/packages/contracts/src/__tests__/pane-stream.test.ts +488 -0
  34. package/packages/contracts/src/__tests__/pane-widget-marker.test.ts +327 -0
  35. package/packages/contracts/src/__tests__/performance-metrics.test.ts +73 -0
  36. package/packages/contracts/src/__tests__/performance-qualification.test.ts +137 -0
  37. package/packages/contracts/src/__tests__/rich-card-widget.test.ts +29 -0
  38. package/packages/contracts/src/__tests__/session-runtime.test.ts +504 -0
  39. package/packages/contracts/src/__tests__/startup-readiness.test.ts +409 -0
  40. package/packages/contracts/src/__tests__/terminal-attachment-stream.test.ts +72 -0
  41. package/packages/contracts/src/__tests__/terminal-attachments.test.ts +329 -0
  42. package/packages/contracts/src/__tests__/terminal-delivery.test.ts +88 -0
  43. package/packages/contracts/src/__tests__/terminal-runtime-inventory.test.ts +68 -0
  44. package/packages/contracts/src/__tests__/visual-tokens.test.ts +224 -0
  45. package/packages/contracts/src/__tests__/workspace-changes-resource.test.ts +317 -0
  46. package/packages/contracts/src/__tests__/workspace-changes-view.test.ts +122 -0
  47. package/packages/contracts/src/__tests__/workspace-config.test.ts +294 -0
  48. package/packages/contracts/src/__tests__/workspace-files-resource.test.ts +261 -0
  49. package/packages/contracts/src/__tests__/workspace-files-tree.test.ts +147 -0
  50. package/packages/contracts/src/__tests__/workspace-pane-creation.test.ts +249 -0
  51. package/packages/contracts/src/__tests__/workspace-promotion.test.ts +94 -0
  52. package/packages/contracts/src/__tests__/workspace-resource-identity.test.ts +90 -0
  53. package/packages/contracts/src/actions-contract.ts +205 -0
  54. package/packages/contracts/src/actions-errors.ts +20 -0
  55. package/packages/contracts/src/agent-graph-overlay.ts +425 -0
  56. package/packages/contracts/src/app-window-mutation.ts +103 -0
  57. package/packages/contracts/src/app-window-state.ts +446 -0
  58. package/packages/contracts/src/application-shell-resource.ts +54 -0
  59. package/packages/contracts/src/application-shell.ts +1094 -0
  60. package/packages/contracts/src/causal-cell.ts +168 -0
  61. package/packages/contracts/src/client-view-state.ts +156 -0
  62. package/packages/contracts/src/cohesion-fixture.ts +647 -0
  63. package/packages/contracts/src/commands.ts +153 -0
  64. package/packages/contracts/src/daemon-events.ts +374 -0
  65. package/packages/contracts/src/daemon-resource-request.test.ts +192 -0
  66. package/packages/contracts/src/daemon-resource-request.ts +397 -0
  67. package/packages/contracts/src/daemon-resources.ts +108 -0
  68. package/packages/contracts/src/daemon-wire.ts +100 -0
  69. package/packages/contracts/src/desktop-daemon-issue.ts +83 -0
  70. package/packages/contracts/src/desktop-host.ts +746 -0
  71. package/packages/contracts/src/desktop-missions.ts +159 -0
  72. package/packages/contracts/src/desktop-update.ts +48 -0
  73. package/packages/contracts/src/desktop-workspace-name.ts +18 -0
  74. package/packages/contracts/src/domain.ts +493 -0
  75. package/packages/contracts/src/experience-identifiers.ts +53 -0
  76. package/packages/contracts/src/experience-shell.ts +249 -0
  77. package/packages/contracts/src/fleet-agent-graph.ts +171 -0
  78. package/packages/contracts/src/fleet-catalog.ts +190 -0
  79. package/packages/contracts/src/fleet-lifecycle.ts +136 -0
  80. package/packages/contracts/src/focus-overlay.ts +175 -0
  81. package/packages/contracts/src/ide-config.ts +40 -20
  82. package/packages/contracts/src/index.ts +63 -0
  83. package/packages/contracts/src/interaction-receipts.ts +438 -0
  84. package/packages/contracts/src/issue-error.ts +107 -0
  85. package/packages/contracts/src/mission-projections.ts +269 -0
  86. package/packages/contracts/src/multiplexer-verbs.ts +447 -0
  87. package/packages/contracts/src/pane-appearance.ts +248 -0
  88. package/packages/contracts/src/pane-stream.ts +711 -0
  89. package/packages/contracts/src/pane-widget-descriptor.ts +62 -0
  90. package/packages/contracts/src/pane-widget-marker.ts +301 -0
  91. package/packages/contracts/src/performance-metrics.ts +128 -0
  92. package/packages/contracts/src/performance-qualification.ts +276 -0
  93. package/packages/contracts/src/rich-card-widget.ts +72 -0
  94. package/packages/contracts/src/saved-machines.ts +50 -0
  95. package/packages/contracts/src/semantic-identity.ts +39 -0
  96. package/packages/contracts/src/session-runtime.ts +364 -0
  97. package/packages/contracts/src/shared-monotonic-clock.ts +18 -0
  98. package/packages/contracts/src/startup-readiness.ts +432 -0
  99. package/packages/contracts/src/terminal-attachment-stream.ts +119 -0
  100. package/packages/contracts/src/terminal-attachments.ts +347 -0
  101. package/packages/contracts/src/terminal-delivery.ts +245 -0
  102. package/packages/contracts/src/terminal-replica.ts +133 -0
  103. package/packages/contracts/src/terminal-runtime-inventory.ts +42 -0
  104. package/packages/contracts/src/visual-recipes.ts +126 -0
  105. package/packages/contracts/src/visual-theme-presets.ts +499 -0
  106. package/packages/contracts/src/visual-tokens.ts +883 -0
  107. package/packages/contracts/src/widget-asset.ts +43 -0
  108. package/packages/contracts/src/workspace-catalog-resource.test.ts +146 -0
  109. package/packages/contracts/src/workspace-catalog-resource.ts +180 -0
  110. package/packages/contracts/src/workspace-changes-resource.ts +405 -0
  111. package/packages/contracts/src/workspace-changes-view.ts +195 -0
  112. package/packages/contracts/src/workspace-config.ts +303 -0
  113. package/packages/contracts/src/workspace-files-resource.ts +310 -0
  114. package/packages/contracts/src/workspace-files-tree.ts +167 -0
  115. package/packages/contracts/src/workspace-missions-resource.ts +32 -0
  116. package/packages/contracts/src/workspace-multiplexer.ts +373 -0
  117. package/packages/contracts/src/workspace-open-handoff.ts +99 -0
  118. package/packages/contracts/src/workspace-open.ts +64 -0
  119. package/packages/contracts/src/workspace-pane-creation.ts +223 -0
  120. package/packages/contracts/src/workspace-promotion.ts +109 -0
  121. package/packages/contracts/src/workspace-resource-identity.ts +81 -0
  122. package/packages/contracts/src/workspace-state.ts +530 -0
  123. package/packages/contracts/src/workspace.ts +14 -2
  124. package/packages/core/package.json +35 -0
  125. package/packages/core/src/agent-provisioning.test.ts +42 -0
  126. package/packages/core/src/agent-provisioning.ts +112 -0
  127. package/packages/core/src/app-window-identity.ts +33 -0
  128. package/packages/core/src/application-shell-session.test.ts +105 -0
  129. package/packages/core/src/application-shell-session.ts +195 -0
  130. package/packages/core/src/index.ts +17 -0
  131. package/packages/core/src/interaction-flow.test.ts +66 -0
  132. package/packages/core/src/interaction-flow.ts +159 -0
  133. package/packages/core/src/interaction-receipts.test.ts +361 -0
  134. package/packages/core/src/interaction-receipts.ts +336 -0
  135. package/packages/core/src/navigator.test.ts +34 -0
  136. package/packages/core/src/navigator.ts +74 -0
  137. package/packages/core/src/optimistic-projection-conformance.test.ts +75 -0
  138. package/packages/core/src/optimistic-projection-conformance.ts +61 -0
  139. package/packages/core/src/optimistic-projection-store.ts +71 -0
  140. package/packages/core/src/optimistic-projection.test.ts +118 -0
  141. package/packages/core/src/optimistic-projection.ts +194 -0
  142. package/packages/core/src/performance-metrics.test.ts +121 -0
  143. package/packages/core/src/performance-metrics.ts +241 -0
  144. package/packages/core/src/performance-qualification.test.ts +283 -0
  145. package/packages/core/src/performance-qualification.ts +360 -0
  146. package/packages/core/src/saved-machines.test.ts +80 -0
  147. package/packages/core/src/saved-machines.ts +53 -0
  148. package/packages/core/src/terminal-compact-capability.ts +31 -0
  149. package/packages/core/src/terminal-compact-cold.test.ts +87 -0
  150. package/packages/core/src/terminal-conformance.test.ts +48 -0
  151. package/packages/core/src/terminal-conformance.ts +405 -0
  152. package/packages/core/src/terminal-delivery.test.ts +1400 -0
  153. package/packages/core/src/terminal-delivery.ts +2977 -0
  154. package/packages/core/src/terminal-fnv64-wasm-bytes.ts +20 -0
  155. package/packages/core/src/terminal-fnv64-wasm.test.ts +61 -0
  156. package/packages/core/src/terminal-fnv64-wasm.ts +110 -0
  157. package/packages/core/src/terminal-replica-cold.test.ts +31 -0
  158. package/packages/core/src/terminal-replica-hash-cache.test.ts +283 -0
  159. package/packages/core/src/terminal-replica-hash-cache.ts +399 -0
  160. package/packages/core/src/terminal-replica.test.ts +347 -0
  161. package/packages/core/src/terminal-replica.ts +950 -0
  162. package/packages/core/src/workspace-selection.test.ts +63 -0
  163. package/packages/core/src/workspace-selection.ts +97 -0
  164. package/packages/daemon/dist/attach.js +2 -2
  165. package/packages/daemon/dist/canonical.js +1 -1
  166. package/packages/daemon/dist/cli.js +38 -37
  167. package/packages/daemon/dist/command-center/actions/command-definitions.js +70 -0
  168. package/packages/daemon/dist/command-center/actions/dispatcher.js +228 -10
  169. package/packages/daemon/dist/command-center/actions/handlers/_project-context.js +3 -4
  170. package/packages/daemon/dist/command-center/actions/handlers/app-set-remote-access.js +6 -2
  171. package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.js +39 -0
  172. package/packages/daemon/dist/command-center/actions/handlers/config-actions.js +44 -20
  173. package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.js +11 -1
  174. package/packages/daemon/dist/command-center/actions/handlers/fleet-lifecycle.js +56 -0
  175. package/packages/daemon/dist/command-center/actions/handlers/project-launch.js +16 -4
  176. package/packages/daemon/dist/command-center/actions/handlers/workspace-multiplexer.js +55 -0
  177. package/packages/daemon/dist/command-center/actions/handlers/workspace-open.js +89 -0
  178. package/packages/daemon/dist/command-center/actions/handlers/workspace-pane-create.js +34 -0
  179. package/packages/daemon/dist/command-center/actions/handlers/workspace-promote.js +34 -0
  180. package/packages/daemon/dist/command-center/actions/registry.js +126 -0
  181. package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.js +16 -0
  182. package/packages/daemon/dist/command-center/agent-status-watch.js +170 -0
  183. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +395 -0
  184. package/packages/daemon/dist/command-center/discovery.js +262 -3
  185. package/packages/daemon/dist/command-center/owner-authority.js +46 -0
  186. package/packages/daemon/dist/command-center/pane-stream-issue.js +185 -0
  187. package/packages/daemon/dist/command-center/resources/agent-graph-overlay.js +234 -0
  188. package/packages/daemon/dist/command-center/resources/application-shell.js +641 -0
  189. package/packages/daemon/dist/command-center/resources/desktop-missions.js +132 -0
  190. package/packages/daemon/dist/command-center/resources/fleet-catalog.js +163 -0
  191. package/packages/daemon/dist/command-center/resources/fleet-resource-route.js +48 -0
  192. package/packages/daemon/dist/command-center/resources/startup-readiness-route.js +121 -0
  193. package/packages/daemon/dist/command-center/resources/startup-readiness.js +183 -0
  194. package/packages/daemon/dist/command-center/resources/terminal-native-backing-route.js +82 -0
  195. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +24 -0
  196. package/packages/daemon/dist/command-center/resources/workspace-changes-authority.js +451 -0
  197. package/packages/daemon/dist/command-center/resources/workspace-changes-git.js +222 -0
  198. package/packages/daemon/dist/command-center/resources/workspace-files-authority.js +493 -0
  199. package/packages/daemon/dist/command-center/resources/workspace-missions-route.js +75 -0
  200. package/packages/daemon/dist/command-center/resources/workspace-resource-ids.js +69 -0
  201. package/packages/daemon/dist/command-center/resources/workspace-resource-routes.js +116 -0
  202. package/packages/daemon/dist/command-center/server.js +540 -51
  203. package/packages/daemon/dist/command-center/terminal-attachment-issue.js +191 -0
  204. package/packages/daemon/dist/command-center/workspace-resource-observer.js +453 -0
  205. package/packages/daemon/dist/command-center/ws-events.js +681 -63
  206. package/packages/daemon/dist/config.js +31 -25
  207. package/packages/daemon/dist/control/lifecycle.js +12 -2
  208. package/packages/daemon/dist/control/server.js +3 -3
  209. package/packages/daemon/dist/detect.js +23 -20
  210. package/packages/daemon/dist/doctor.js +25 -8
  211. package/packages/daemon/dist/index.js +20 -1
  212. package/packages/daemon/dist/init.js +24 -22
  213. package/packages/daemon/dist/inspect.js +33 -8
  214. package/packages/daemon/dist/launch.js +38 -26
  215. package/packages/daemon/dist/lib/__tests__/fixtures/workspace-state-writer.js +58 -0
  216. package/packages/daemon/dist/lib/agent-kind.js +24 -0
  217. package/packages/daemon/dist/lib/app-config.js +29 -1
  218. package/packages/daemon/dist/lib/app-window-kernel.js +556 -0
  219. package/packages/daemon/dist/lib/app-window-mutation.js +139 -0
  220. package/packages/daemon/dist/lib/app-window-repository.js +368 -0
  221. package/packages/daemon/dist/lib/app-window-state.js +415 -0
  222. package/packages/daemon/dist/lib/application-shell-app-windows.js +285 -0
  223. package/packages/daemon/dist/lib/auth/middleware.js +7 -3
  224. package/packages/daemon/dist/lib/bundled-tmux.js +90 -0
  225. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +276 -0
  226. package/packages/daemon/dist/lib/canonical-daemon.js +507 -70
  227. package/packages/daemon/dist/lib/chrome-front-door.js +13 -0
  228. package/packages/daemon/dist/lib/cli-action-bridge.js +112 -82
  229. package/packages/daemon/dist/lib/command-registry.js +107 -0
  230. package/packages/daemon/dist/lib/config-context.js +34 -0
  231. package/packages/daemon/dist/lib/daemon-embed.js +1072 -363
  232. package/packages/daemon/dist/lib/daemon-session-monitor.js +194 -0
  233. package/packages/daemon/dist/lib/daemon.js +3 -47
  234. package/packages/daemon/dist/lib/directory-watcher.js +118 -0
  235. package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +102 -0
  236. package/packages/daemon/dist/lib/environment-identity.js +79 -0
  237. package/packages/daemon/dist/lib/fleet-agent-lifecycle.js +65 -0
  238. package/packages/daemon/dist/lib/fleet-lifecycle-authority.js +437 -0
  239. package/packages/daemon/dist/lib/headless-daemon.js +353 -0
  240. package/packages/daemon/dist/lib/launch-plan.js +96 -1
  241. package/packages/daemon/dist/lib/legacy-config-adapter.js +19 -0
  242. package/packages/daemon/dist/lib/legacy-config-migration.js +110 -0
  243. package/packages/daemon/dist/lib/legacy-theme-compat.js +25 -0
  244. package/packages/daemon/dist/lib/mission-projections.js +615 -0
  245. package/packages/daemon/dist/lib/mission-repository.js +775 -0
  246. package/packages/daemon/dist/lib/onboarding-marker.js +51 -0
  247. package/packages/daemon/dist/lib/pane-chrome.js +12 -0
  248. package/packages/daemon/dist/lib/pane-source-credentials.js +178 -0
  249. package/packages/daemon/dist/lib/pane-widget.js +126 -0
  250. package/packages/daemon/dist/lib/project-inspect.js +4 -0
  251. package/packages/daemon/dist/lib/project-onboard.js +17 -21
  252. package/packages/daemon/dist/lib/project-probe.js +28 -22
  253. package/packages/daemon/dist/lib/project-readiness-probe.js +425 -0
  254. package/packages/daemon/dist/lib/project-readiness.js +680 -0
  255. package/packages/daemon/dist/lib/project-registry.js +42 -9
  256. package/packages/daemon/dist/lib/project-resolver.js +245 -0
  257. package/packages/daemon/dist/lib/project-runtime-errors.js +21 -0
  258. package/packages/daemon/dist/lib/project-runtime-repository.js +876 -0
  259. package/packages/daemon/dist/lib/remote-daemon-info.js +21 -0
  260. package/packages/daemon/dist/lib/resolved-config.js +318 -0
  261. package/packages/daemon/dist/lib/runtime-namespace.js +136 -0
  262. package/packages/daemon/dist/lib/saved-machines.js +53 -0
  263. package/packages/daemon/dist/lib/semantic-resource-id.js +14 -0
  264. package/packages/daemon/dist/lib/session-monitor.js +29 -23
  265. package/packages/daemon/dist/lib/session-options.js +3 -10
  266. package/packages/daemon/dist/lib/ssh-daemon-transport.js +280 -0
  267. package/packages/daemon/dist/lib/state-home.js +2 -3
  268. package/packages/daemon/dist/lib/theme-mode.js +9 -0
  269. package/packages/daemon/dist/lib/tmux-authority-replacement.js +102 -0
  270. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +534 -0
  271. package/packages/daemon/dist/lib/tmux-interaction-options.js +126 -0
  272. package/packages/daemon/dist/lib/tmux-named-socket-fence.js +61 -0
  273. package/packages/daemon/dist/lib/tmux-terminal-color.js +37 -0
  274. package/packages/daemon/dist/lib/tui-binary.js +291 -28
  275. package/packages/daemon/dist/lib/unix-socket-authority.js +48 -0
  276. package/packages/daemon/dist/lib/widget-asset-policy.js +3 -0
  277. package/packages/daemon/dist/lib/widget-asset-store.js +166 -0
  278. package/packages/daemon/dist/lib/workspace-config-loader.js +280 -0
  279. package/packages/daemon/dist/lib/workspace-multiplexer-verbs.js +1138 -0
  280. package/packages/daemon/dist/lib/workspace-open-handoff.js +219 -0
  281. package/packages/daemon/dist/lib/workspace-open.js +740 -0
  282. package/packages/daemon/dist/lib/workspace-pane-creation.js +1137 -0
  283. package/packages/daemon/dist/lib/workspace-promotion.js +809 -0
  284. package/packages/daemon/dist/lib/workspace-registry.js +150 -23
  285. package/packages/daemon/dist/lib/workspace-state-repository.js +790 -0
  286. package/packages/daemon/dist/lib/workspace-state.js +765 -0
  287. package/packages/daemon/dist/lib/yaml-io.js +4 -18
  288. package/packages/daemon/dist/migrate.js +105 -0
  289. package/packages/daemon/dist/native/tmux/darwin-arm64/COPYING +13 -0
  290. package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libevent_core-2.1.7.dylib +0 -0
  291. package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libncursesw.6.dylib +0 -0
  292. package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libutf8proc.3.2.3.dylib +0 -0
  293. package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libevent_core-2.1.7.dylib.txt +99 -0
  294. package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libncursesw.6.dylib.txt +29 -0
  295. package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libutf8proc.3.2.3.dylib.txt +93 -0
  296. package/packages/daemon/dist/native/tmux/darwin-arm64/manifest.json +21 -0
  297. package/packages/daemon/dist/native/tmux/darwin-arm64/tmux +0 -0
  298. package/packages/daemon/dist/restart.js +2 -2
  299. package/packages/daemon/dist/restore.js +10 -6
  300. package/packages/daemon/dist/schemas/inspect.js +9 -1
  301. package/packages/daemon/dist/schemas/registry.js +5 -19
  302. package/packages/daemon/dist/schemas/ws-events.js +4 -107
  303. package/packages/daemon/dist/send.js +106 -3
  304. package/packages/daemon/dist/server/index.js +4 -2
  305. package/packages/daemon/dist/server/pane-stream-upgrade.js +117 -0
  306. package/packages/daemon/dist/server/terminal-attachment-upgrade.js +121 -0
  307. package/packages/daemon/dist/status.js +11 -8
  308. package/packages/daemon/dist/stop.js +2 -2
  309. package/packages/daemon/dist/terminal/MonotonicPtyInput.js +130 -0
  310. package/packages/daemon/dist/terminal/NodePtyAdapter.js +37 -10
  311. package/packages/daemon/dist/terminal/PtyAdapter.js +18 -0
  312. package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.js +33 -6
  313. package/packages/daemon/dist/terminal/attachments/admission-util.js +87 -0
  314. package/packages/daemon/dist/terminal/attachments/agent-status-probe.js +325 -0
  315. package/packages/daemon/dist/terminal/attachments/direct-websocket.js +1069 -0
  316. package/packages/daemon/dist/terminal/attachments/grouped-tmux.js +213 -0
  317. package/packages/daemon/dist/terminal/attachments/lease-manager.js +655 -0
  318. package/packages/daemon/dist/terminal/attachments/native-runtime.js +1597 -0
  319. package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.js +607 -0
  320. package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.js +208 -0
  321. package/packages/daemon/dist/terminal/attachments/tmux-view-executor.js +825 -0
  322. package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.js +86 -0
  323. package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.js +147 -0
  324. package/packages/daemon/dist/terminal/mirror/control-channel.js +739 -0
  325. package/packages/daemon/dist/terminal/mirror/control-mode-ownership.js +30 -0
  326. package/packages/daemon/dist/terminal/mirror/events.js +18 -0
  327. package/packages/daemon/dist/terminal/mirror/flow-ledger.js +56 -0
  328. package/packages/daemon/dist/terminal/mirror/mirror-service.js +338 -0
  329. package/packages/daemon/dist/terminal/mirror/native-frozen-grid.js +126 -0
  330. package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +144 -0
  331. package/packages/daemon/dist/terminal/mirror/native-grid-projection.js +99 -0
  332. package/packages/daemon/dist/terminal/mirror/native-grid-reader.js +81 -0
  333. package/packages/daemon/dist/terminal/mirror/native-grid-reflow.js +183 -0
  334. package/packages/daemon/dist/terminal/mirror/pane-feed.js +196 -0
  335. package/packages/daemon/dist/terminal/mirror/session-channel.js +2670 -0
  336. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +245 -0
  337. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +2067 -0
  338. package/packages/daemon/dist/terminal/pane-stream/runtime.js +53 -0
  339. package/packages/daemon/dist/terminal/pane-stream/wire-ledger.js +110 -0
  340. package/packages/daemon/dist/terminal/protocol/chunk-bytes.js +21 -0
  341. package/packages/daemon/dist/terminal/protocol/control.js +111 -0
  342. package/packages/daemon/dist/terminal/protocol/input-coalescer.js +125 -0
  343. package/packages/daemon/dist/terminal/protocol/layout-parse.js +127 -0
  344. package/packages/daemon/dist/terminal/protocol/native-backing-client.js +44 -0
  345. package/packages/daemon/dist/terminal/protocol/pane-display-name.js +155 -0
  346. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +294 -0
  347. package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.js +213 -0
  348. package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.js +266 -0
  349. package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.js +278 -0
  350. package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.js +147 -0
  351. package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.js +116 -0
  352. package/packages/daemon/dist/terminal/session-runtime/registry.js +1387 -0
  353. package/packages/daemon/dist/terminal/session-runtime/runtime-observability.js +72 -0
  354. package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.js +10 -0
  355. package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.js +48 -0
  356. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-executor.js +353 -0
  357. package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-resource-changes.js +32 -0
  358. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +1399 -0
  359. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.js +9 -0
  360. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +559 -0
  361. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +552 -0
  362. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.js +21 -0
  363. package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +474 -0
  364. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +414 -0
  365. package/packages/daemon/dist/tui/async-disposable-slot.js +57 -0
  366. package/packages/daemon/dist/tui/chrome/cheatsheet.js +211 -0
  367. package/packages/daemon/dist/tui/chrome/chip.js +25 -0
  368. package/packages/daemon/dist/tui/chrome/events.js +94 -0
  369. package/packages/daemon/dist/tui/chrome/front-door.js +16 -0
  370. package/packages/daemon/dist/tui/chrome/kitty-keys.js +54 -0
  371. package/packages/daemon/dist/tui/chrome/menu.js +251 -0
  372. package/packages/daemon/dist/tui/chrome/notify-prefs.js +13 -0
  373. package/packages/daemon/dist/tui/chrome/notify-state.js +77 -0
  374. package/packages/daemon/dist/tui/chrome/notify.js +711 -0
  375. package/packages/daemon/dist/tui/chrome/panels.js +60 -0
  376. package/packages/daemon/dist/tui/chrome/sidebar.js +183 -0
  377. package/packages/daemon/dist/tui/chrome/snapshot.js +290 -0
  378. package/packages/daemon/dist/tui/chrome/statusline.js +552 -0
  379. package/packages/daemon/dist/tui/chrome/updater.js +651 -0
  380. package/packages/daemon/dist/tui/chrome/welcome.js +117 -0
  381. package/packages/daemon/dist/tui/compiled.js +194 -0
  382. package/packages/daemon/dist/tui/detect/agent-resolution.js +60 -0
  383. package/packages/daemon/dist/tui/detect/classify.js +184 -0
  384. package/packages/daemon/dist/tui/detect/manifest-loader.js +242 -0
  385. package/packages/daemon/dist/tui/detect/manifest.js +126 -0
  386. package/packages/daemon/dist/tui/detect/manifests.js +535 -0
  387. package/packages/daemon/dist/tui/detect/process-tree.js +194 -0
  388. package/packages/daemon/dist/tui/detect/session-id.js +414 -0
  389. package/packages/daemon/dist/tui/detect/snapshot.js +81 -0
  390. package/packages/daemon/dist/tui/integrations/claude.js +151 -0
  391. package/packages/daemon/dist/tui/integrations/offer.js +134 -0
  392. package/packages/daemon/dist/tui/integrations/opencode.js +117 -0
  393. package/packages/daemon/dist/tui/mirror/ack-writer.js +78 -0
  394. package/packages/daemon/dist/tui/mirror/activity-surface-view.jsx +69 -0
  395. package/packages/daemon/dist/tui/mirror/activity-surface.js +271 -0
  396. package/packages/daemon/dist/tui/mirror/agent-chip.js +84 -0
  397. package/packages/daemon/dist/tui/mirror/agent-lifecycle.js +372 -0
  398. package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.js +111 -0
  399. package/packages/daemon/dist/tui/mirror/agent-rows.js +126 -0
  400. package/packages/daemon/dist/tui/mirror/ansi-palette.js +3 -0
  401. package/packages/daemon/dist/tui/mirror/app-state.js +294 -0
  402. package/packages/daemon/dist/tui/mirror/application-keybindings.js +33 -0
  403. package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.js +270 -0
  404. package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.js +45 -0
  405. package/packages/daemon/dist/tui/mirror/attention.js +59 -0
  406. package/packages/daemon/dist/tui/mirror/blit.js +120 -0
  407. package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.js +54 -0
  408. package/packages/daemon/dist/tui/mirror/changes-surface-view.jsx +92 -0
  409. package/packages/daemon/dist/tui/mirror/changes-surface.js +210 -0
  410. package/packages/daemon/dist/tui/mirror/composite-layout.js +539 -0
  411. package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.js +134 -0
  412. package/packages/daemon/dist/tui/mirror/dialog-model.js +183 -0
  413. package/packages/daemon/dist/tui/mirror/dialog-stack-core.js +232 -0
  414. package/packages/daemon/dist/tui/mirror/dialog-stack.js +2 -0
  415. package/packages/daemon/dist/tui/mirror/diff-model.js +332 -0
  416. package/packages/daemon/dist/tui/mirror/editor-buffer.js +47 -0
  417. package/packages/daemon/dist/tui/mirror/editor-open-policy.js +9 -0
  418. package/packages/daemon/dist/tui/mirror/features/changes/controller.js +454 -0
  419. package/packages/daemon/dist/tui/mirror/features/changes/feature.jsx +9 -0
  420. package/packages/daemon/dist/tui/mirror/features/dialogs/feature.jsx +123 -0
  421. package/packages/daemon/dist/tui/mirror/features/dialogs/session.js +160 -0
  422. package/packages/daemon/dist/tui/mirror/features/files/feature.jsx +15 -0
  423. package/packages/daemon/dist/tui/mirror/features/files/session.js +617 -0
  424. package/packages/daemon/dist/tui/mirror/features/home/feature.jsx +122 -0
  425. package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.js +3 -0
  426. package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.jsx +5 -0
  427. package/packages/daemon/dist/tui/mirror/features/missions-activity/session.js +377 -0
  428. package/packages/daemon/dist/tui/mirror/features/palette/buffer-geometry.js +36 -0
  429. package/packages/daemon/dist/tui/mirror/features/palette/contract.js +9 -0
  430. package/packages/daemon/dist/tui/mirror/features/palette/feature.js +3 -0
  431. package/packages/daemon/dist/tui/mirror/features/palette/session.js +394 -0
  432. package/packages/daemon/dist/tui/mirror/features/palette/surface.jsx +50 -0
  433. package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.jsx +2 -0
  434. package/packages/daemon/dist/tui/mirror/features/performance-hud/session.js +148 -0
  435. package/packages/daemon/dist/tui/mirror/features/performance-hud/surface.jsx +64 -0
  436. package/packages/daemon/dist/tui/mirror/features/rich-preview/asset-loader.js +125 -0
  437. package/packages/daemon/dist/tui/mirror/features/rich-preview/contract.js +1 -0
  438. package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.jsx +103 -0
  439. package/packages/daemon/dist/tui/mirror/features/rich-preview/session.js +310 -0
  440. package/packages/daemon/dist/tui/mirror/features/settings/catalog.js +10 -0
  441. package/packages/daemon/dist/tui/mirror/features/settings/contract.js +1 -0
  442. package/packages/daemon/dist/tui/mirror/features/settings/feature.js +2 -0
  443. package/packages/daemon/dist/tui/mirror/features/settings/session.js +309 -0
  444. package/packages/daemon/dist/tui/mirror/file-tree.js +283 -0
  445. package/packages/daemon/dist/tui/mirror/files-surface-view.jsx +92 -0
  446. package/packages/daemon/dist/tui/mirror/files-surface.js +237 -0
  447. package/packages/daemon/dist/tui/mirror/focus-projection.js +80 -0
  448. package/packages/daemon/dist/tui/mirror/folder-picker.js +114 -0
  449. package/packages/daemon/dist/tui/mirror/frame-coalescer.js +74 -0
  450. package/packages/daemon/dist/tui/mirror/home-model.js +125 -0
  451. package/packages/daemon/dist/tui/mirror/home-surface-model.js +297 -0
  452. package/packages/daemon/dist/tui/mirror/home-surface.jsx +110 -0
  453. package/packages/daemon/dist/tui/mirror/host-terminal.js +33 -0
  454. package/packages/daemon/dist/tui/mirror/hosted.js +239 -0
  455. package/packages/daemon/dist/tui/mirror/input-lifecycle.js +147 -0
  456. package/packages/daemon/dist/tui/mirror/interaction-flow.js +41 -0
  457. package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.js +84 -0
  458. package/packages/daemon/dist/tui/mirror/menu-model.js +143 -0
  459. package/packages/daemon/dist/tui/mirror/missions-dashboard.js +261 -0
  460. package/packages/daemon/dist/tui/mirror/missions-render-fixtures.js +330 -0
  461. package/packages/daemon/dist/tui/mirror/missions-surface-controller.js +314 -0
  462. package/packages/daemon/dist/tui/mirror/missions-surface.jsx +239 -0
  463. package/packages/daemon/dist/tui/mirror/missions-workspace.js +1399 -0
  464. package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.js +252 -0
  465. package/packages/daemon/dist/tui/mirror/open-tui-pane-stream-socket.js +32 -0
  466. package/packages/daemon/dist/tui/mirror/open-tui-verified-routing.js +95 -0
  467. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +1087 -0
  468. package/packages/daemon/dist/tui/mirror/palette-surface-adapter.js +384 -0
  469. package/packages/daemon/dist/tui/mirror/palette.js +522 -0
  470. package/packages/daemon/dist/tui/mirror/pane-frame-state.js +124 -0
  471. package/packages/daemon/dist/tui/mirror/pane-mirror.js +584 -0
  472. package/packages/daemon/dist/tui/mirror/pane-surface.jsx +950 -0
  473. package/packages/daemon/dist/tui/mirror/panel-host-reactive.js +13 -0
  474. package/packages/daemon/dist/tui/mirror/panel-host.js +242 -0
  475. package/packages/daemon/dist/tui/mirror/perf-tap.js +32 -0
  476. package/packages/daemon/dist/tui/mirror/performance-events.js +46 -0
  477. package/packages/daemon/dist/tui/mirror/recipe-components.jsx +135 -0
  478. package/packages/daemon/dist/tui/mirror/recipes.js +395 -0
  479. package/packages/daemon/dist/tui/mirror/reference-performance-trace.js +598 -0
  480. package/packages/daemon/dist/tui/mirror/renderer-commands.js +250 -0
  481. package/packages/daemon/dist/tui/mirror/resize-model.js +105 -0
  482. package/packages/daemon/dist/tui/mirror/resize-transaction.js +221 -0
  483. package/packages/daemon/dist/tui/mirror/rich-placement-projection.js +80 -0
  484. package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.js +176 -0
  485. package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.js +51 -0
  486. package/packages/daemon/dist/tui/mirror/runtime/application-daemon-authority-owner.js +235 -0
  487. package/packages/daemon/dist/tui/mirror/runtime/application-daemon-authority.js +8 -0
  488. package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.js +90 -0
  489. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +86 -0
  490. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-observer.js +301 -0
  491. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-roster.jsx +170 -0
  492. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-selection.js +83 -0
  493. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-transport.js +199 -0
  494. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +221 -0
  495. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents.js +30 -0
  496. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.js +104 -0
  497. package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.js +329 -0
  498. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-binding.js +111 -0
  499. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-capability.js +25 -0
  500. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-presentation.js +129 -0
  501. package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-test-control.js +242 -0
  502. package/packages/daemon/dist/tui/mirror/runtime/application-input-readiness.js +20 -0
  503. package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.js +297 -0
  504. package/packages/daemon/dist/tui/mirror/runtime/application-machine-authority.js +289 -0
  505. package/packages/daemon/dist/tui/mirror/runtime/application-machine-catalog.js +223 -0
  506. package/packages/daemon/dist/tui/mirror/runtime/application-machine-navigation.js +133 -0
  507. package/packages/daemon/dist/tui/mirror/runtime/application-machine-sidebar.jsx +156 -0
  508. package/packages/daemon/dist/tui/mirror/runtime/application-machine-startup.js +35 -0
  509. package/packages/daemon/dist/tui/mirror/runtime/application-optional-features.js +12 -0
  510. package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +132 -0
  511. package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.js +69 -0
  512. package/packages/daemon/dist/tui/mirror/runtime/application-palette-search-owner.js +67 -0
  513. package/packages/daemon/dist/tui/mirror/runtime/application-pane-activity-owner.js +61 -0
  514. package/packages/daemon/dist/tui/mirror/runtime/application-pane-menu-owner.js +82 -0
  515. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.js +41 -0
  516. package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.js +46 -0
  517. package/packages/daemon/dist/tui/mirror/runtime/application-pending-terminal-input.js +74 -0
  518. package/packages/daemon/dist/tui/mirror/runtime/application-performance-log.js +126 -0
  519. package/packages/daemon/dist/tui/mirror/runtime/application-post-render-runtime.js +117 -0
  520. package/packages/daemon/dist/tui/mirror/runtime/application-root-configuration.js +21 -0
  521. package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.js +160 -0
  522. package/packages/daemon/dist/tui/mirror/runtime/application-session-focus-owner.js +65 -0
  523. package/packages/daemon/dist/tui/mirror/runtime/application-shell-binding.js +313 -0
  524. package/packages/daemon/dist/tui/mirror/runtime/application-shell-home.jsx +113 -0
  525. package/packages/daemon/dist/tui/mirror/runtime/application-shell-viewport.js +14 -0
  526. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-frame-readiness-owner.js +20 -0
  527. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-host-focus-owner.js +25 -0
  528. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-input-ingress.js +102 -0
  529. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +1360 -0
  530. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-palette-owner.js +217 -0
  531. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-paste.js +22 -0
  532. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-renderer-sources.js +31 -0
  533. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-selection-owner.js +217 -0
  534. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.js +193 -0
  535. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.jsx +1286 -0
  536. package/packages/daemon/dist/tui/mirror/runtime/application-theme-repaint.js +34 -0
  537. package/packages/daemon/dist/tui/mirror/runtime/application-transient-note-owner.js +29 -0
  538. package/packages/daemon/dist/tui/mirror/runtime/bounded-performance-record-writer.js +67 -0
  539. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-client-ledger.js +281 -0
  540. package/packages/daemon/dist/tui/mirror/runtime/causal-cell-input-fixture.js +43 -0
  541. package/packages/daemon/dist/tui/mirror/runtime/changes-deferred-identity.js +17 -0
  542. package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.js +128 -0
  543. package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.js +40 -0
  544. package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.js +39 -0
  545. package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.js +9 -0
  546. package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.js +30 -0
  547. package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.js +53 -0
  548. package/packages/daemon/dist/tui/mirror/runtime/generation-bound-slot.js +23 -0
  549. package/packages/daemon/dist/tui/mirror/runtime/host-local-tmux-adapter.js +203 -0
  550. package/packages/daemon/dist/tui/mirror/runtime/hosted-tty-size-bridge.js +166 -0
  551. package/packages/daemon/dist/tui/mirror/runtime/latest-intent-fence.js +14 -0
  552. package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.js +58 -0
  553. package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.js +118 -0
  554. package/packages/daemon/dist/tui/mirror/runtime/modal-pointer-capture.js +12 -0
  555. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +833 -0
  556. package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.js +178 -0
  557. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.js +178 -0
  558. package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.typecheck.js +1 -0
  559. package/packages/daemon/dist/tui/mirror/runtime/palette-production-controller.js +126 -0
  560. package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.js +17 -0
  561. package/packages/daemon/dist/tui/mirror/runtime/pane-scoped-terminal-surface.jsx +67 -0
  562. package/packages/daemon/dist/tui/mirror/runtime/product-surface-policy.js +12 -0
  563. package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.js +7 -0
  564. package/packages/daemon/dist/tui/mirror/runtime/renderer-frame-optimizer.js +88 -0
  565. package/packages/daemon/dist/tui/mirror/runtime/renderer-output-transport.js +56 -0
  566. package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.js +91 -0
  567. package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.js +14 -0
  568. package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.js +111 -0
  569. package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.js +90 -0
  570. package/packages/daemon/dist/tui/mirror/runtime/semantic-pane-publication.js +14 -0
  571. package/packages/daemon/dist/tui/mirror/runtime/semantic-shell-viewport-resize.js +56 -0
  572. package/packages/daemon/dist/tui/mirror/runtime/terminal-copy-cursor.js +122 -0
  573. package/packages/daemon/dist/tui/mirror/runtime/terminal-copy-selection.js +65 -0
  574. package/packages/daemon/dist/tui/mirror/runtime/terminal-dimensions-owner.js +9 -0
  575. package/packages/daemon/dist/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.js +901 -0
  576. package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.js +84 -0
  577. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-focus.js +347 -0
  578. package/packages/daemon/dist/tui/mirror/runtime/terminal-host-frame-diagnostics.js +37 -0
  579. package/packages/daemon/dist/tui/mirror/runtime/terminal-input-adapter.js +50 -0
  580. package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.js +105 -0
  581. package/packages/daemon/dist/tui/mirror/runtime/terminal-link-opener.js +23 -0
  582. package/packages/daemon/dist/tui/mirror/runtime/terminal-links.js +81 -0
  583. package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.js +83 -0
  584. package/packages/daemon/dist/tui/mirror/runtime/terminal-row-projection-cache.js +88 -0
  585. package/packages/daemon/dist/tui/mirror/runtime/terminal-selection-units.js +123 -0
  586. package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.js +202 -0
  587. package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.js +89 -0
  588. package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.js +64 -0
  589. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.js +636 -0
  590. package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.js +169 -0
  591. package/packages/daemon/dist/tui/mirror/runtime/viewport-fit-coordinator.js +7 -0
  592. package/packages/daemon/dist/tui/mirror/runtime/workspace-terminal-fast-lane.js +498 -0
  593. package/packages/daemon/dist/tui/mirror/scrollbar-model.js +64 -0
  594. package/packages/daemon/dist/tui/mirror/search-model.js +62 -0
  595. package/packages/daemon/dist/tui/mirror/selection.js +264 -0
  596. package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.js +581 -0
  597. package/packages/daemon/dist/tui/mirror/semantic-session-view.js +269 -0
  598. package/packages/daemon/dist/tui/mirror/settings-model.js +304 -0
  599. package/packages/daemon/dist/tui/mirror/shell-chrome.js +313 -0
  600. package/packages/daemon/dist/tui/mirror/size-truth.js +104 -0
  601. package/packages/daemon/dist/tui/mirror/spans.js +31 -0
  602. package/packages/daemon/dist/tui/mirror/status-grammar.js +29 -0
  603. package/packages/daemon/dist/tui/mirror/terminal-native-reflow.js +1 -0
  604. package/packages/daemon/dist/tui/mirror/terminal-retained-row.js +10 -0
  605. package/packages/daemon/dist/tui/mirror/terminal-surface.js +92 -0
  606. package/packages/daemon/dist/tui/mirror/terminal-text.js +52 -0
  607. package/packages/daemon/dist/tui/mirror/terminal-viewport.js +436 -0
  608. package/packages/daemon/dist/tui/mirror/theme.js +765 -0
  609. package/packages/daemon/dist/tui/mirror/ui/agent-badge.jsx +14 -0
  610. package/packages/daemon/dist/tui/mirror/ui/badge.jsx +15 -0
  611. package/packages/daemon/dist/tui/mirror/ui/button.jsx +66 -0
  612. package/packages/daemon/dist/tui/mirror/ui/dialog.jsx +8 -0
  613. package/packages/daemon/dist/tui/mirror/ui/index.js +16 -0
  614. package/packages/daemon/dist/tui/mirror/ui/key-hint.jsx +39 -0
  615. package/packages/daemon/dist/tui/mirror/ui/keyboard-router.jsx +46 -0
  616. package/packages/daemon/dist/tui/mirror/ui/menu.jsx +24 -0
  617. package/packages/daemon/dist/tui/mirror/ui/navigation-row.jsx +62 -0
  618. package/packages/daemon/dist/tui/mirror/ui/overlay-frame.jsx +54 -0
  619. package/packages/daemon/dist/tui/mirror/ui/overlay-host.jsx +33 -0
  620. package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.jsx +29 -0
  621. package/packages/daemon/dist/tui/mirror/ui/overlay-model.js +45 -0
  622. package/packages/daemon/dist/tui/mirror/ui/state.js +171 -0
  623. package/packages/daemon/dist/tui/mirror/ui/status-bar.jsx +102 -0
  624. package/packages/daemon/dist/tui/mirror/ui/surface.jsx +45 -0
  625. package/packages/daemon/dist/tui/mirror/ui/tabs.jsx +88 -0
  626. package/packages/daemon/dist/tui/mirror/widget-fallback.js +52 -0
  627. package/packages/daemon/dist/tui/mirror/widget-surface-model.js +145 -0
  628. package/packages/daemon/dist/tui/mirror/widget-surface.jsx +31 -0
  629. package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.js +77 -0
  630. package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +44 -0
  631. package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.js +99 -0
  632. package/packages/daemon/dist/tui/mirror/workspace/application-shell-controller.js +292 -0
  633. package/packages/daemon/dist/tui/mirror/workspace/application-shell-surface-commands.js +28 -0
  634. package/packages/daemon/dist/tui/mirror/workspace/application-shell.js +97 -0
  635. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface-view.jsx +158 -0
  636. package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface.js +353 -0
  637. package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +99 -0
  638. package/packages/daemon/dist/tui/mirror/workspace/icons.js +43 -0
  639. package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu-model.js +8 -0
  640. package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.jsx +15 -0
  641. package/packages/daemon/dist/tui/mirror/workspace/pane-frame.js +452 -0
  642. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.js +555 -0
  643. package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.jsx +159 -0
  644. package/packages/daemon/dist/tui/mirror/workspace/terminal-scrollback.js +179 -0
  645. package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.jsx +253 -0
  646. package/packages/daemon/dist/tui/mirror/workspace/text.js +27 -0
  647. package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.js +34 -0
  648. package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.js +286 -0
  649. package/packages/daemon/dist/tui/mirror/workspace-ui-state.js +885 -0
  650. package/packages/daemon/dist/tui/readiness.js +34 -0
  651. package/packages/daemon/dist/tui/team/entry.js +20 -0
  652. package/packages/daemon/dist/tui/team/fuzzy.js +141 -0
  653. package/packages/daemon/dist/tui/team/home.js +115 -0
  654. package/packages/daemon/dist/tui/team/input.js +21 -0
  655. package/packages/daemon/dist/tui/team/keymap.js +99 -0
  656. package/packages/daemon/dist/tui/team/mouse.js +17 -0
  657. package/packages/daemon/dist/tui/team/nav.js +33 -0
  658. package/packages/daemon/dist/tui/team/preview.js +35 -0
  659. package/packages/daemon/dist/tui/team/projects.js +159 -0
  660. package/packages/daemon/dist/tui/team/report.js +37 -0
  661. package/packages/daemon/dist/tui/team/sessions.js +292 -0
  662. package/packages/daemon/dist/tui/team/tree.js +42 -0
  663. package/packages/daemon/dist/tui/team/wait-receipts.js +153 -0
  664. package/packages/daemon/dist/tui/team/wait.js +90 -0
  665. package/packages/daemon/dist/validate.js +16 -10
  666. package/packages/daemon/dist/widgets/lib/watcher.js +5 -92
  667. package/packages/daemon/dist/widgets/resolve.js +12 -9
  668. package/packages/daemon/dist/widgets/setup/setup-model.js +7 -9
  669. package/packages/daemon/src/attach.ts +2 -2
  670. package/packages/daemon/src/canonical.ts +19 -2
  671. package/packages/daemon/src/cli.ts +39 -37
  672. package/packages/daemon/src/command-center/actions/command-definitions.ts +91 -0
  673. package/packages/daemon/src/command-center/actions/dispatcher.ts +291 -10
  674. package/packages/daemon/src/command-center/actions/errors.ts +40 -0
  675. package/packages/daemon/src/command-center/actions/handlers/_project-context.ts +4 -5
  676. package/packages/daemon/src/command-center/actions/handlers/app-set-remote-access.ts +9 -1
  677. package/packages/daemon/src/command-center/actions/handlers/app-window-mutate.ts +54 -0
  678. package/packages/daemon/src/command-center/actions/handlers/config-actions.ts +59 -29
  679. package/packages/daemon/src/command-center/actions/handlers/daemon-shutdown.ts +12 -0
  680. package/packages/daemon/src/command-center/actions/handlers/fleet-lifecycle.ts +104 -0
  681. package/packages/daemon/src/command-center/actions/handlers/project-launch.ts +20 -4
  682. package/packages/daemon/src/command-center/actions/handlers/workspace-multiplexer.ts +96 -0
  683. package/packages/daemon/src/command-center/actions/handlers/workspace-open.ts +141 -0
  684. package/packages/daemon/src/command-center/actions/handlers/workspace-pane-create.ts +48 -0
  685. package/packages/daemon/src/command-center/actions/handlers/workspace-promote.ts +48 -0
  686. package/packages/daemon/src/command-center/actions/registry.ts +200 -1
  687. package/packages/daemon/src/command-center/actions/semantic-multiplexer-actions.ts +26 -0
  688. package/packages/daemon/src/command-center/agent-status-watch.ts +222 -0
  689. package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +465 -0
  690. package/packages/daemon/src/command-center/discovery.ts +310 -5
  691. package/packages/daemon/src/command-center/owner-authority.ts +118 -0
  692. package/packages/daemon/src/command-center/pane-stream-issue.ts +247 -0
  693. package/packages/daemon/src/command-center/resources/agent-graph-overlay.ts +270 -0
  694. package/packages/daemon/src/command-center/resources/application-shell.ts +909 -0
  695. package/packages/daemon/src/command-center/resources/desktop-missions.ts +171 -0
  696. package/packages/daemon/src/command-center/resources/fleet-catalog.ts +200 -0
  697. package/packages/daemon/src/command-center/resources/fleet-resource-route.ts +69 -0
  698. package/packages/daemon/src/command-center/resources/startup-readiness-route.ts +172 -0
  699. package/packages/daemon/src/command-center/resources/startup-readiness.ts +250 -0
  700. package/packages/daemon/src/command-center/resources/terminal-native-backing-route.ts +87 -0
  701. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +45 -0
  702. package/packages/daemon/src/command-center/resources/workspace-changes-authority.ts +594 -0
  703. package/packages/daemon/src/command-center/resources/workspace-changes-git.ts +278 -0
  704. package/packages/daemon/src/command-center/resources/workspace-files-authority.ts +583 -0
  705. package/packages/daemon/src/command-center/resources/workspace-missions-route.ts +125 -0
  706. package/packages/daemon/src/command-center/resources/workspace-resource-ids.ts +81 -0
  707. package/packages/daemon/src/command-center/resources/workspace-resource-routes.ts +147 -0
  708. package/packages/daemon/src/command-center/server.ts +732 -59
  709. package/packages/daemon/src/command-center/terminal-attachment-issue.ts +257 -0
  710. package/packages/daemon/src/command-center/workspace-resource-observer.ts +560 -0
  711. package/packages/daemon/src/command-center/ws-events.ts +853 -66
  712. package/packages/daemon/src/config.ts +35 -25
  713. package/packages/daemon/src/control/lifecycle.ts +14 -2
  714. package/packages/daemon/src/control/server.ts +3 -3
  715. package/packages/daemon/src/detect.ts +25 -20
  716. package/packages/daemon/src/doctor.ts +24 -7
  717. package/packages/daemon/src/index.ts +244 -2
  718. package/packages/daemon/src/init.ts +23 -22
  719. package/packages/daemon/src/inspect.ts +41 -8
  720. package/packages/daemon/src/launch.ts +56 -28
  721. package/packages/daemon/src/lib/agent-kind.ts +23 -0
  722. package/packages/daemon/src/lib/app-config.ts +44 -5
  723. package/packages/daemon/src/lib/app-window-kernel.ts +777 -0
  724. package/packages/daemon/src/lib/app-window-mutation.ts +178 -0
  725. package/packages/daemon/src/lib/app-window-repository.ts +650 -0
  726. package/packages/daemon/src/lib/app-window-state.ts +599 -0
  727. package/packages/daemon/src/lib/application-shell-app-windows.ts +357 -0
  728. package/packages/daemon/src/lib/auth/middleware.ts +9 -3
  729. package/packages/daemon/src/lib/bundled-tmux.ts +100 -0
  730. package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +392 -0
  731. package/packages/daemon/src/lib/canonical-daemon.ts +695 -73
  732. package/packages/daemon/src/lib/chrome-front-door.ts +17 -0
  733. package/packages/daemon/src/lib/cli-action-bridge.ts +127 -91
  734. package/packages/daemon/src/lib/command-registry.ts +152 -0
  735. package/packages/daemon/src/lib/config-context.ts +61 -0
  736. package/packages/daemon/src/lib/daemon-embed.ts +1373 -390
  737. package/packages/daemon/src/lib/daemon-session-monitor.ts +274 -0
  738. package/packages/daemon/src/lib/daemon.ts +3 -46
  739. package/packages/daemon/src/lib/directory-watcher.ts +166 -0
  740. package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +106 -0
  741. package/packages/daemon/src/lib/environment-identity.ts +82 -0
  742. package/packages/daemon/src/lib/errors.ts +7 -1
  743. package/packages/daemon/src/lib/fleet-agent-lifecycle.ts +74 -0
  744. package/packages/daemon/src/lib/fleet-lifecycle-authority.ts +535 -0
  745. package/packages/daemon/src/lib/headless-daemon.ts +459 -0
  746. package/packages/daemon/src/lib/launch-plan.ts +123 -4
  747. package/packages/daemon/src/lib/legacy-config-adapter.ts +28 -0
  748. package/packages/daemon/src/lib/legacy-config-migration.ts +145 -0
  749. package/packages/daemon/src/lib/legacy-theme-compat.ts +40 -0
  750. package/packages/daemon/src/lib/mission-projections.ts +775 -0
  751. package/packages/daemon/src/lib/mission-repository.ts +1311 -0
  752. package/packages/daemon/src/lib/onboarding-marker.ts +51 -0
  753. package/packages/daemon/src/lib/pane-chrome.ts +14 -0
  754. package/packages/daemon/src/lib/pane-source-credentials.ts +200 -0
  755. package/packages/daemon/src/lib/pane-widget.ts +182 -0
  756. package/packages/daemon/src/lib/project-inspect.ts +4 -0
  757. package/packages/daemon/src/lib/project-onboard.ts +19 -24
  758. package/packages/daemon/src/lib/project-probe.ts +38 -30
  759. package/packages/daemon/src/lib/project-readiness-probe.ts +578 -0
  760. package/packages/daemon/src/lib/project-readiness.ts +1034 -0
  761. package/packages/daemon/src/lib/project-registry.ts +45 -9
  762. package/packages/daemon/src/lib/project-resolver.ts +350 -0
  763. package/packages/daemon/src/lib/project-runtime-errors.ts +41 -0
  764. package/packages/daemon/src/lib/project-runtime-repository.ts +1194 -0
  765. package/packages/daemon/src/lib/remote-daemon-info.ts +42 -0
  766. package/packages/daemon/src/lib/resolved-config.ts +425 -0
  767. package/packages/daemon/src/lib/runtime-namespace.ts +186 -0
  768. package/packages/daemon/src/lib/saved-machines.ts +63 -0
  769. package/packages/daemon/src/lib/semantic-resource-id.ts +17 -0
  770. package/packages/daemon/src/lib/session-monitor.ts +28 -20
  771. package/packages/daemon/src/lib/session-options.ts +3 -10
  772. package/packages/daemon/src/lib/ssh-daemon-transport.ts +303 -0
  773. package/packages/daemon/src/lib/state-home.ts +2 -3
  774. package/packages/daemon/src/lib/theme-mode.ts +11 -0
  775. package/packages/daemon/src/lib/tmux-authority-replacement.ts +119 -0
  776. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +632 -0
  777. package/packages/daemon/src/lib/tmux-interaction-options.ts +171 -0
  778. package/packages/daemon/src/lib/tmux-named-socket-fence.ts +66 -0
  779. package/packages/daemon/src/lib/tmux-terminal-color.ts +44 -0
  780. package/packages/daemon/src/lib/tui-binary.ts +354 -34
  781. package/packages/daemon/src/lib/unix-socket-authority.ts +65 -0
  782. package/packages/daemon/src/lib/widget-asset-policy.ts +3 -0
  783. package/packages/daemon/src/lib/widget-asset-store.ts +218 -0
  784. package/packages/daemon/src/lib/workspace-config-loader.ts +378 -0
  785. package/packages/daemon/src/lib/workspace-multiplexer-verbs.ts +1362 -0
  786. package/packages/daemon/src/lib/workspace-open-handoff.ts +340 -0
  787. package/packages/daemon/src/lib/workspace-open.ts +983 -0
  788. package/packages/daemon/src/lib/workspace-pane-creation.ts +1434 -0
  789. package/packages/daemon/src/lib/workspace-promotion.ts +1035 -0
  790. package/packages/daemon/src/lib/workspace-registry.ts +193 -25
  791. package/packages/daemon/src/lib/workspace-state-repository.ts +1204 -0
  792. package/packages/daemon/src/lib/workspace-state.ts +960 -0
  793. package/packages/daemon/src/lib/yaml-io.ts +8 -17
  794. package/packages/daemon/src/migrate.ts +134 -0
  795. package/packages/daemon/src/restart.ts +2 -2
  796. package/packages/daemon/src/restore.ts +14 -9
  797. package/packages/daemon/src/schemas/inspect.ts +9 -1
  798. package/packages/daemon/src/schemas/registry.ts +12 -22
  799. package/packages/daemon/src/schemas/ws-events.ts +14 -131
  800. package/packages/daemon/src/send.ts +138 -3
  801. package/packages/daemon/src/server/README.md +1 -1
  802. package/packages/daemon/src/server/index.ts +6 -2
  803. package/packages/daemon/src/server/pane-stream-upgrade.ts +141 -0
  804. package/packages/daemon/src/server/terminal-attachment-upgrade.ts +153 -0
  805. package/packages/daemon/src/status.ts +13 -8
  806. package/packages/daemon/src/stop.ts +2 -2
  807. package/packages/daemon/src/terminal/MonotonicPtyInput.ts +153 -0
  808. package/packages/daemon/src/terminal/NodePtyAdapter.ts +53 -11
  809. package/packages/daemon/src/terminal/PtyAdapter.ts +111 -3
  810. package/packages/daemon/src/terminal/README.md +34 -16
  811. package/packages/daemon/src/terminal/attachments/admission-util.ts +97 -0
  812. package/packages/daemon/src/terminal/attachments/agent-status-probe.ts +474 -0
  813. package/packages/daemon/src/terminal/attachments/direct-websocket.ts +1482 -0
  814. package/packages/daemon/src/terminal/attachments/grouped-tmux.ts +293 -0
  815. package/packages/daemon/src/terminal/attachments/lease-manager.ts +1042 -0
  816. package/packages/daemon/src/terminal/attachments/native-runtime.ts +2246 -0
  817. package/packages/daemon/src/terminal/attachments/pty-tmux-attachment-launcher.ts +750 -0
  818. package/packages/daemon/src/terminal/attachments/semantic-pane-catalog.ts +365 -0
  819. package/packages/daemon/src/terminal/attachments/tmux-view-executor.ts +1095 -0
  820. package/packages/daemon/src/terminal/mirror/control-channel.ts +1003 -0
  821. package/packages/daemon/src/terminal/mirror/control-mode-ownership.ts +34 -0
  822. package/packages/daemon/src/terminal/mirror/events.ts +159 -0
  823. package/packages/daemon/src/terminal/mirror/flow-ledger.ts +65 -0
  824. package/packages/daemon/src/terminal/mirror/mirror-service.ts +501 -0
  825. package/packages/daemon/src/terminal/mirror/native-frozen-grid.ts +152 -0
  826. package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +182 -0
  827. package/packages/daemon/src/terminal/mirror/native-grid-projection.ts +125 -0
  828. package/packages/daemon/src/terminal/mirror/native-grid-reader.ts +109 -0
  829. package/packages/daemon/src/terminal/mirror/native-grid-reflow.ts +217 -0
  830. package/packages/daemon/src/terminal/mirror/pane-feed.ts +258 -0
  831. package/packages/daemon/src/terminal/mirror/session-channel.ts +3253 -0
  832. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +29 -0
  833. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +375 -0
  834. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +2625 -0
  835. package/packages/daemon/src/terminal/pane-stream/runtime.ts +78 -0
  836. package/packages/daemon/src/terminal/pane-stream/wire-ledger.ts +155 -0
  837. package/packages/daemon/src/terminal/protocol/README.md +14 -0
  838. package/packages/daemon/src/terminal/protocol/chunk-bytes.ts +20 -0
  839. package/packages/daemon/src/terminal/protocol/control.ts +130 -0
  840. package/packages/daemon/src/terminal/protocol/input-coalescer.ts +131 -0
  841. package/packages/daemon/src/terminal/protocol/native-backing-client.ts +65 -0
  842. package/packages/daemon/src/terminal/protocol/pane-display-name.ts +192 -0
  843. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +382 -0
  844. package/packages/daemon/src/terminal/protocol/workspace-tmux-adapter.ts +470 -0
  845. package/packages/daemon/src/terminal/session-runtime/authority-arbiter.ts +318 -0
  846. package/packages/daemon/src/terminal/session-runtime/causal-cell-ledger.ts +359 -0
  847. package/packages/daemon/src/terminal/session-runtime/interaction-receipt-facts.ts +173 -0
  848. package/packages/daemon/src/terminal/session-runtime/multiplexer-backend.ts +194 -0
  849. package/packages/daemon/src/terminal/session-runtime/registry.ts +2074 -0
  850. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +267 -0
  851. package/packages/daemon/src/terminal/session-runtime/runtime-scheduler.ts +22 -0
  852. package/packages/daemon/src/terminal/session-runtime/runtime-trace-correlator.ts +58 -0
  853. package/packages/daemon/src/terminal/session-runtime/semantic-mutation-executor.ts +555 -0
  854. package/packages/daemon/src/terminal/session-runtime/semantic-mutation-resource-changes.ts +48 -0
  855. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +1853 -0
  856. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-observation-identity.ts +18 -0
  857. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +74 -0
  858. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +738 -0
  859. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +681 -0
  860. package/packages/daemon/src/terminal/session-runtime/terminal-replica-shadow-projections.ts +36 -0
  861. package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +682 -0
  862. package/packages/daemon/src/terminal/session-runtime/xterm-headless-provenance.json +51 -0
  863. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +556 -0
  864. package/packages/daemon/src/tui/async-disposable-slot.ts +60 -0
  865. package/packages/daemon/src/tui/chrome/front-door.ts +11 -23
  866. package/packages/daemon/src/tui/chrome/sidebar.ts +11 -5
  867. package/packages/daemon/src/tui/chrome/statusline.ts +15 -6
  868. package/packages/daemon/src/tui/chrome/updater.ts +100 -3
  869. package/packages/daemon/src/tui/compiled.ts +132 -6
  870. package/packages/daemon/src/tui/detect/agent-resolution.ts +85 -0
  871. package/packages/daemon/src/tui/detect/process-tree.ts +17 -1
  872. package/packages/daemon/src/tui/detect/snapshot.ts +38 -3
  873. package/packages/daemon/src/tui/integrations/claude.ts +1 -0
  874. package/packages/daemon/src/tui/main.ts +56 -0
  875. package/packages/daemon/src/tui/mirror/RECIPES.md +59 -0
  876. package/packages/daemon/src/tui/mirror/SHELL_CHROME.md +39 -0
  877. package/packages/daemon/src/tui/mirror/THEME.md +48 -0
  878. package/packages/daemon/src/tui/mirror/__snapshots__/activity-surface-renderer.test.tsx.snap +42 -0
  879. package/packages/daemon/src/tui/mirror/__snapshots__/changes-terminal-surface-renderer.test.tsx.snap +267 -0
  880. package/packages/daemon/src/tui/mirror/__snapshots__/home-files-surface-renderer.test.tsx.snap +267 -0
  881. package/packages/daemon/src/tui/mirror/__snapshots__/missions-surface-renderer.test.tsx.snap +134 -0
  882. package/packages/daemon/src/tui/mirror/__snapshots__/recipes-gallery-renderer.test.tsx.snap +141 -0
  883. package/packages/daemon/src/tui/mirror/__snapshots__/shell-chrome-renderer.test.tsx.snap +134 -0
  884. package/packages/daemon/src/tui/mirror/activity-surface-view.tsx +169 -0
  885. package/packages/daemon/src/tui/mirror/activity-surface.ts +430 -0
  886. package/packages/daemon/src/tui/mirror/agent-lifecycle.ts +36 -5
  887. package/packages/daemon/src/tui/mirror/agent-provisioning-executor.ts +175 -0
  888. package/packages/daemon/src/tui/mirror/agent-rows.ts +34 -0
  889. package/packages/daemon/src/tui/mirror/ansi-palette.ts +3 -0
  890. package/packages/daemon/src/tui/mirror/app-state.ts +14 -1
  891. package/packages/daemon/src/tui/mirror/app.tsx +2 -7047
  892. package/packages/daemon/src/tui/mirror/application-keybindings.ts +54 -0
  893. package/packages/daemon/src/tui/mirror/application-shell-daemon-connection.ts +370 -0
  894. package/packages/daemon/src/tui/mirror/application-shell-daemon-session.ts +74 -0
  895. package/packages/daemon/src/tui/mirror/canonical-workspace-routing.ts +90 -0
  896. package/packages/daemon/src/tui/mirror/changes-surface-view.tsx +263 -0
  897. package/packages/daemon/src/tui/mirror/changes-surface.ts +338 -0
  898. package/packages/daemon/src/tui/mirror/composite-layout.ts +710 -0
  899. package/packages/daemon/src/tui/mirror/configless-session-bootstrap.ts +192 -0
  900. package/packages/daemon/src/tui/mirror/dialog-model.ts +2 -2
  901. package/packages/daemon/src/tui/mirror/dialog-stack-core.ts +264 -0
  902. package/packages/daemon/src/tui/mirror/dialog-stack.ts +2 -367
  903. package/packages/daemon/src/tui/mirror/editor-buffer.ts +9 -70
  904. package/packages/daemon/src/tui/mirror/editor-open-policy.ts +16 -0
  905. package/packages/daemon/src/tui/mirror/features/changes/contract.ts +84 -0
  906. package/packages/daemon/src/tui/mirror/features/changes/controller.ts +470 -0
  907. package/packages/daemon/src/tui/mirror/features/changes/feature.tsx +19 -0
  908. package/packages/daemon/src/tui/mirror/features/dialogs/contract.ts +64 -0
  909. package/packages/daemon/src/tui/mirror/features/dialogs/feature.tsx +227 -0
  910. package/packages/daemon/src/tui/mirror/features/dialogs/session.ts +186 -0
  911. package/packages/daemon/src/tui/mirror/features/files/feature.tsx +54 -0
  912. package/packages/daemon/src/tui/mirror/features/files/session.ts +694 -0
  913. package/packages/daemon/src/tui/mirror/features/home/feature.tsx +172 -0
  914. package/packages/daemon/src/tui/mirror/features/missions-activity/contract.ts +106 -0
  915. package/packages/daemon/src/tui/mirror/features/missions-activity/feature.tsx +19 -0
  916. package/packages/daemon/src/tui/mirror/features/missions-activity/session.ts +470 -0
  917. package/packages/daemon/src/tui/mirror/features/palette/buffer-geometry.ts +46 -0
  918. package/packages/daemon/src/tui/mirror/features/palette/contract.ts +121 -0
  919. package/packages/daemon/src/tui/mirror/features/palette/feature.ts +14 -0
  920. package/packages/daemon/src/tui/mirror/features/palette/session.ts +443 -0
  921. package/packages/daemon/src/tui/mirror/features/palette/surface.tsx +133 -0
  922. package/packages/daemon/src/tui/mirror/features/performance-hud/contract.ts +20 -0
  923. package/packages/daemon/src/tui/mirror/features/performance-hud/feature.tsx +8 -0
  924. package/packages/daemon/src/tui/mirror/features/performance-hud/session.ts +152 -0
  925. package/packages/daemon/src/tui/mirror/features/performance-hud/surface.tsx +137 -0
  926. package/packages/daemon/src/tui/mirror/features/rich-preview/asset-loader.ts +153 -0
  927. package/packages/daemon/src/tui/mirror/features/rich-preview/contract.ts +94 -0
  928. package/packages/daemon/src/tui/mirror/features/rich-preview/feature.tsx +141 -0
  929. package/packages/daemon/src/tui/mirror/features/rich-preview/session.ts +387 -0
  930. package/packages/daemon/src/tui/mirror/features/settings/catalog.ts +26 -0
  931. package/packages/daemon/src/tui/mirror/features/settings/contract.ts +41 -0
  932. package/packages/daemon/src/tui/mirror/features/settings/feature.ts +3 -0
  933. package/packages/daemon/src/tui/mirror/features/settings/session.ts +375 -0
  934. package/packages/daemon/src/tui/mirror/files-surface-view.tsx +242 -0
  935. package/packages/daemon/src/tui/mirror/files-surface.ts +371 -0
  936. package/packages/daemon/src/tui/mirror/focus-projection.ts +113 -0
  937. package/packages/daemon/src/tui/mirror/frame-coalescer.ts +87 -0
  938. package/packages/daemon/src/tui/mirror/home-model.ts +1 -1
  939. package/packages/daemon/src/tui/mirror/home-surface-model.ts +440 -0
  940. package/packages/daemon/src/tui/mirror/home-surface.tsx +254 -0
  941. package/packages/daemon/src/tui/mirror/hosted.ts +87 -6
  942. package/packages/daemon/src/tui/mirror/input-lifecycle.ts +248 -0
  943. package/packages/daemon/src/tui/mirror/interaction-flow.ts +83 -0
  944. package/packages/daemon/src/tui/mirror/legacy/missions-workspace-loader.ts +117 -0
  945. package/packages/daemon/src/tui/mirror/menu-model.ts +1 -14
  946. package/packages/daemon/src/tui/mirror/missions-dashboard.ts +451 -0
  947. package/packages/daemon/src/tui/mirror/missions-render-fixtures.ts +371 -0
  948. package/packages/daemon/src/tui/mirror/missions-surface-controller.ts +530 -0
  949. package/packages/daemon/src/tui/mirror/missions-surface.tsx +434 -0
  950. package/packages/daemon/src/tui/mirror/missions-workspace.ts +1996 -0
  951. package/packages/daemon/src/tui/mirror/multiplexer-action-executor.ts +393 -0
  952. package/packages/daemon/src/tui/mirror/open-tui-pane-stream-socket.ts +47 -0
  953. package/packages/daemon/src/tui/mirror/open-tui-verified-routing.ts +152 -0
  954. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +1340 -0
  955. package/packages/daemon/src/tui/mirror/palette-surface-adapter.ts +465 -0
  956. package/packages/daemon/src/tui/mirror/palette.ts +189 -28
  957. package/packages/daemon/src/tui/mirror/pane-frame-state.ts +209 -0
  958. package/packages/daemon/src/tui/mirror/pane-mirror.ts +134 -46
  959. package/packages/daemon/src/tui/mirror/pane-surface.tsx +858 -53
  960. package/packages/daemon/src/tui/mirror/panel-host-reactive.ts +17 -0
  961. package/packages/daemon/src/tui/mirror/panel-host.ts +384 -0
  962. package/packages/daemon/src/tui/mirror/perf-tap.ts +1 -148
  963. package/packages/daemon/src/tui/mirror/performance-events.ts +488 -0
  964. package/packages/daemon/src/tui/mirror/recipe-components.tsx +310 -0
  965. package/packages/daemon/src/tui/mirror/recipes-gallery.tsx +256 -0
  966. package/packages/daemon/src/tui/mirror/recipes.ts +543 -0
  967. package/packages/daemon/src/tui/mirror/reference-performance-trace.ts +727 -0
  968. package/packages/daemon/src/tui/mirror/renderer-commands.ts +344 -0
  969. package/packages/daemon/src/tui/mirror/resize-model.ts +74 -9
  970. package/packages/daemon/src/tui/mirror/resize-transaction.ts +342 -0
  971. package/packages/daemon/src/tui/mirror/rich-placement-projection.ts +173 -0
  972. package/packages/daemon/src/tui/mirror/runtime/__snapshots__/application-shell-view-renderer.test.tsx.snap +87 -0
  973. package/packages/daemon/src/tui/mirror/runtime/application-add-machine-dialog.tsx +88 -0
  974. package/packages/daemon/src/tui/mirror/runtime/application-appearance-owner.ts +229 -0
  975. package/packages/daemon/src/tui/mirror/runtime/application-bootstrap.ts +118 -0
  976. package/packages/daemon/src/tui/mirror/runtime/application-daemon-authority-owner.ts +259 -0
  977. package/packages/daemon/src/tui/mirror/runtime/application-daemon-authority.ts +16 -0
  978. package/packages/daemon/src/tui/mirror/runtime/application-entry.ts +226 -0
  979. package/packages/daemon/src/tui/mirror/runtime/application-generation-starter.ts +130 -0
  980. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +174 -0
  981. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-observer.ts +363 -0
  982. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-roster.tsx +276 -0
  983. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-selection.ts +99 -0
  984. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-transport.ts +232 -0
  985. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +295 -0
  986. package/packages/daemon/src/tui/mirror/runtime/application-home-agents.ts +70 -0
  987. package/packages/daemon/src/tui/mirror/runtime/application-home-catalog-owner.ts +130 -0
  988. package/packages/daemon/src/tui/mirror/runtime/application-home-catalog.ts +451 -0
  989. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-binding.ts +143 -0
  990. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-capability.ts +46 -0
  991. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-presentation.ts +176 -0
  992. package/packages/daemon/src/tui/mirror/runtime/application-host-focus-test-control.ts +313 -0
  993. package/packages/daemon/src/tui/mirror/runtime/application-input-readiness.ts +28 -0
  994. package/packages/daemon/src/tui/mirror/runtime/application-lifecycle.ts +374 -0
  995. package/packages/daemon/src/tui/mirror/runtime/application-machine-authority.ts +337 -0
  996. package/packages/daemon/src/tui/mirror/runtime/application-machine-catalog.ts +256 -0
  997. package/packages/daemon/src/tui/mirror/runtime/application-machine-navigation.ts +140 -0
  998. package/packages/daemon/src/tui/mirror/runtime/application-machine-sidebar.tsx +248 -0
  999. package/packages/daemon/src/tui/mirror/runtime/application-machine-startup.ts +39 -0
  1000. package/packages/daemon/src/tui/mirror/runtime/application-optional-features.ts +25 -0
  1001. package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +162 -0
  1002. package/packages/daemon/src/tui/mirror/runtime/application-palette-input.ts +108 -0
  1003. package/packages/daemon/src/tui/mirror/runtime/application-palette-search-owner.ts +78 -0
  1004. package/packages/daemon/src/tui/mirror/runtime/application-pane-activity-owner.ts +79 -0
  1005. package/packages/daemon/src/tui/mirror/runtime/application-pane-menu-owner.ts +95 -0
  1006. package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-input.ts +61 -0
  1007. package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-owner.ts +50 -0
  1008. package/packages/daemon/src/tui/mirror/runtime/application-pending-terminal-input.ts +117 -0
  1009. package/packages/daemon/src/tui/mirror/runtime/application-performance-log.ts +166 -0
  1010. package/packages/daemon/src/tui/mirror/runtime/application-post-render-runtime.ts +163 -0
  1011. package/packages/daemon/src/tui/mirror/runtime/application-root-configuration.ts +47 -0
  1012. package/packages/daemon/src/tui/mirror/runtime/application-root-renderer.ts +165 -0
  1013. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +588 -0
  1014. package/packages/daemon/src/tui/mirror/runtime/application-session-focus-owner.ts +80 -0
  1015. package/packages/daemon/src/tui/mirror/runtime/application-shell-binding.ts +375 -0
  1016. package/packages/daemon/src/tui/mirror/runtime/application-shell-catalog.tsx +448 -0
  1017. package/packages/daemon/src/tui/mirror/runtime/application-shell-home.tsx +252 -0
  1018. package/packages/daemon/src/tui/mirror/runtime/application-shell-overlay-stack.tsx +37 -0
  1019. package/packages/daemon/src/tui/mirror/runtime/application-shell-overlays.tsx +381 -0
  1020. package/packages/daemon/src/tui/mirror/runtime/application-shell-sidebar.tsx +188 -0
  1021. package/packages/daemon/src/tui/mirror/runtime/application-shell-view.tsx +531 -0
  1022. package/packages/daemon/src/tui/mirror/runtime/application-shell-viewport.ts +18 -0
  1023. package/packages/daemon/src/tui/mirror/runtime/application-terminal-frame-readiness-owner.ts +33 -0
  1024. package/packages/daemon/src/tui/mirror/runtime/application-terminal-host-focus-owner.ts +36 -0
  1025. package/packages/daemon/src/tui/mirror/runtime/application-terminal-input-ingress.ts +139 -0
  1026. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +1673 -0
  1027. package/packages/daemon/src/tui/mirror/runtime/application-terminal-palette-owner.ts +302 -0
  1028. package/packages/daemon/src/tui/mirror/runtime/application-terminal-paste.ts +33 -0
  1029. package/packages/daemon/src/tui/mirror/runtime/application-terminal-renderer-sources.ts +33 -0
  1030. package/packages/daemon/src/tui/mirror/runtime/application-terminal-selection-owner.ts +277 -0
  1031. package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace-policy.ts +311 -0
  1032. package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace.tsx +1921 -0
  1033. package/packages/daemon/src/tui/mirror/runtime/application-theme-repaint.ts +45 -0
  1034. package/packages/daemon/src/tui/mirror/runtime/application-transient-note-owner.ts +42 -0
  1035. package/packages/daemon/src/tui/mirror/runtime/bounded-performance-record-writer.ts +75 -0
  1036. package/packages/daemon/src/tui/mirror/runtime/causal-cell-client-ledger.ts +406 -0
  1037. package/packages/daemon/src/tui/mirror/runtime/causal-cell-input-fixture.ts +55 -0
  1038. package/packages/daemon/src/tui/mirror/runtime/changes-deferred-identity.ts +34 -0
  1039. package/packages/daemon/src/tui/mirror/runtime/daemon-authority-rebind.ts +163 -0
  1040. package/packages/daemon/src/tui/mirror/runtime/deferred-intent-queue.ts +45 -0
  1041. package/packages/daemon/src/tui/mirror/runtime/editor-primitives.ts +56 -0
  1042. package/packages/daemon/src/tui/mirror/runtime/file-content-primitives.ts +8 -0
  1043. package/packages/daemon/src/tui/mirror/runtime/fleet-lifecycle-client.ts +67 -0
  1044. package/packages/daemon/src/tui/mirror/runtime/focus-framebuffer-projection.ts +71 -0
  1045. package/packages/daemon/src/tui/mirror/runtime/generation-bound-slot.ts +23 -0
  1046. package/packages/daemon/src/tui/mirror/runtime/host-local-tmux-adapter.ts +233 -0
  1047. package/packages/daemon/src/tui/mirror/runtime/hosted-tty-size-bridge.ts +213 -0
  1048. package/packages/daemon/src/tui/mirror/runtime/latest-intent-fence.ts +22 -0
  1049. package/packages/daemon/src/tui/mirror/runtime/local-view-controller.ts +95 -0
  1050. package/packages/daemon/src/tui/mirror/runtime/modal-admission-coordinator.ts +158 -0
  1051. package/packages/daemon/src/tui/mirror/runtime/modal-pointer-capture.ts +23 -0
  1052. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +1003 -0
  1053. package/packages/daemon/src/tui/mirror/runtime/open-tui-session-owner.ts +229 -0
  1054. package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.ts +234 -0
  1055. package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.typecheck.ts +14 -0
  1056. package/packages/daemon/src/tui/mirror/runtime/palette-production-controller.ts +170 -0
  1057. package/packages/daemon/src/tui/mirror/runtime/palette-production-overlay.tsx +65 -0
  1058. package/packages/daemon/src/tui/mirror/runtime/pane-resize-geometry.ts +29 -0
  1059. package/packages/daemon/src/tui/mirror/runtime/pane-scoped-terminal-surface.tsx +156 -0
  1060. package/packages/daemon/src/tui/mirror/runtime/product-surface-policy.ts +16 -0
  1061. package/packages/daemon/src/tui/mirror/runtime/renderer-cadence.ts +7 -0
  1062. package/packages/daemon/src/tui/mirror/runtime/renderer-frame-optimizer.ts +92 -0
  1063. package/packages/daemon/src/tui/mirror/runtime/renderer-output-transport.ts +57 -0
  1064. package/packages/daemon/src/tui/mirror/runtime/resize-terminal-pane.ts +134 -0
  1065. package/packages/daemon/src/tui/mirror/runtime/rich-preview-demand.ts +26 -0
  1066. package/packages/daemon/src/tui/mirror/runtime/rich-preview-overlay.tsx +54 -0
  1067. package/packages/daemon/src/tui/mirror/runtime/runtime-layout-presentation.ts +119 -0
  1068. package/packages/daemon/src/tui/mirror/runtime/select-terminal-pane.ts +127 -0
  1069. package/packages/daemon/src/tui/mirror/runtime/semantic-pane-publication.ts +26 -0
  1070. package/packages/daemon/src/tui/mirror/runtime/semantic-shell-viewport-resize.ts +88 -0
  1071. package/packages/daemon/src/tui/mirror/runtime/terminal-copy-cursor.ts +169 -0
  1072. package/packages/daemon/src/tui/mirror/runtime/terminal-copy-selection.ts +79 -0
  1073. package/packages/daemon/src/tui/mirror/runtime/terminal-dimensions-owner.ts +20 -0
  1074. package/packages/daemon/src/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.ts +1065 -0
  1075. package/packages/daemon/src/tui/mirror/runtime/terminal-frame-readiness.ts +100 -0
  1076. package/packages/daemon/src/tui/mirror/runtime/terminal-host-focus.ts +519 -0
  1077. package/packages/daemon/src/tui/mirror/runtime/terminal-host-frame-diagnostics.ts +47 -0
  1078. package/packages/daemon/src/tui/mirror/runtime/terminal-input-adapter.ts +69 -0
  1079. package/packages/daemon/src/tui/mirror/runtime/terminal-layout-projection.ts +145 -0
  1080. package/packages/daemon/src/tui/mirror/runtime/terminal-link-opener.ts +30 -0
  1081. package/packages/daemon/src/tui/mirror/runtime/terminal-links.ts +97 -0
  1082. package/packages/daemon/src/tui/mirror/runtime/terminal-pane-input-router.ts +95 -0
  1083. package/packages/daemon/src/tui/mirror/runtime/terminal-row-projection-cache.ts +115 -0
  1084. package/packages/daemon/src/tui/mirror/runtime/terminal-selection-units.ts +128 -0
  1085. package/packages/daemon/src/tui/mirror/runtime/terminal-selection.ts +285 -0
  1086. package/packages/daemon/src/tui/mirror/runtime/terminal-session-handoff.ts +143 -0
  1087. package/packages/daemon/src/tui/mirror/runtime/terminal-tool-readiness.ts +72 -0
  1088. package/packages/daemon/src/tui/mirror/runtime/tool-resource-controller.ts +799 -0
  1089. package/packages/daemon/src/tui/mirror/runtime/tool-resource-projection.ts +223 -0
  1090. package/packages/daemon/src/tui/mirror/runtime/viewport-fit-coordinator.ts +12 -0
  1091. package/packages/daemon/src/tui/mirror/runtime/workspace-terminal-fast-lane.ts +597 -0
  1092. package/packages/daemon/src/tui/mirror/selection.ts +0 -21
  1093. package/packages/daemon/src/tui/mirror/semantic-pane-render-source.ts +786 -0
  1094. package/packages/daemon/src/tui/mirror/semantic-session-view.ts +366 -0
  1095. package/packages/daemon/src/tui/mirror/settings-model.ts +24 -66
  1096. package/packages/daemon/src/tui/mirror/shell-chrome-view.tsx +346 -0
  1097. package/packages/daemon/src/tui/mirror/shell-chrome.ts +509 -0
  1098. package/packages/daemon/src/tui/mirror/sidebar.tsx +138 -35
  1099. package/packages/daemon/src/tui/mirror/size-truth.ts +1 -1
  1100. package/packages/daemon/src/tui/mirror/terminal-native-reflow.ts +1 -0
  1101. package/packages/daemon/src/tui/mirror/terminal-retained-row.ts +24 -0
  1102. package/packages/daemon/src/tui/mirror/terminal-surface.ts +157 -0
  1103. package/packages/daemon/src/tui/mirror/terminal-surface.tsx +84 -0
  1104. package/packages/daemon/src/tui/mirror/terminal-text.ts +54 -0
  1105. package/packages/daemon/src/tui/mirror/terminal-viewport.ts +514 -0
  1106. package/packages/daemon/src/tui/mirror/theme.ts +1069 -33
  1107. package/packages/daemon/src/tui/mirror/ui/agent-badge.tsx +41 -0
  1108. package/packages/daemon/src/tui/mirror/ui/badge.tsx +42 -0
  1109. package/packages/daemon/src/tui/mirror/ui/button.tsx +127 -0
  1110. package/packages/daemon/src/tui/mirror/ui/dialog.tsx +45 -0
  1111. package/packages/daemon/src/tui/mirror/ui/index.ts +59 -0
  1112. package/packages/daemon/src/tui/mirror/ui/key-hint.tsx +63 -0
  1113. package/packages/daemon/src/tui/mirror/ui/keyboard-router.tsx +72 -0
  1114. package/packages/daemon/src/tui/mirror/ui/menu.tsx +86 -0
  1115. package/packages/daemon/src/tui/mirror/ui/navigation-row.tsx +114 -0
  1116. package/packages/daemon/src/tui/mirror/ui/overlay-frame.tsx +117 -0
  1117. package/packages/daemon/src/tui/mirror/ui/overlay-host.tsx +71 -0
  1118. package/packages/daemon/src/tui/mirror/ui/overlay-list-row.tsx +68 -0
  1119. package/packages/daemon/src/tui/mirror/ui/overlay-model.ts +75 -0
  1120. package/packages/daemon/src/tui/mirror/ui/state.ts +218 -0
  1121. package/packages/daemon/src/tui/mirror/ui/status-bar.tsx +208 -0
  1122. package/packages/daemon/src/tui/mirror/ui/surface.tsx +71 -0
  1123. package/packages/daemon/src/tui/mirror/ui/tabs.tsx +168 -0
  1124. package/packages/daemon/src/tui/mirror/widget-fallback.ts +66 -0
  1125. package/packages/daemon/src/tui/mirror/widget-surface-model.ts +170 -0
  1126. package/packages/daemon/src/tui/mirror/widget-surface.tsx +79 -0
  1127. package/packages/daemon/src/tui/mirror/workspace/README.md +79 -0
  1128. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/agent-terminal-canvas-renderer.test.tsx.snap +348 -0
  1129. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/application-shell-renderer.test.tsx.snap +134 -0
  1130. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/command-palette-surface-renderer.test.tsx.snap +255 -0
  1131. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/pane-frame-renderer.test.tsx.snap +525 -0
  1132. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/terminal-pane-header-polish-renderer.test.tsx.snap +31 -0
  1133. package/packages/daemon/src/tui/mirror/workspace/__snapshots__/workbench-shell-renderer.test.tsx.snap +134 -0
  1134. package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas-view.tsx +61 -0
  1135. package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas.ts +131 -0
  1136. package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +77 -0
  1137. package/packages/daemon/src/tui/mirror/workspace/application-root-controller.ts +169 -0
  1138. package/packages/daemon/src/tui/mirror/workspace/application-shell-controller.ts +430 -0
  1139. package/packages/daemon/src/tui/mirror/workspace/application-shell-surface-commands.ts +64 -0
  1140. package/packages/daemon/src/tui/mirror/workspace/application-shell-view.tsx +169 -0
  1141. package/packages/daemon/src/tui/mirror/workspace/application-shell.ts +179 -0
  1142. package/packages/daemon/src/tui/mirror/workspace/command-palette-surface-view.tsx +356 -0
  1143. package/packages/daemon/src/tui/mirror/workspace/command-palette-surface.ts +557 -0
  1144. package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +105 -0
  1145. package/packages/daemon/src/tui/mirror/workspace/icons.ts +56 -0
  1146. package/packages/daemon/src/tui/mirror/workspace/pane-action-menu-model.ts +33 -0
  1147. package/packages/daemon/src/tui/mirror/workspace/pane-action-menu.tsx +54 -0
  1148. package/packages/daemon/src/tui/mirror/workspace/pane-frame.ts +675 -0
  1149. package/packages/daemon/src/tui/mirror/workspace/pane-frame.tsx +490 -0
  1150. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome-view.tsx +125 -0
  1151. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome.ts +833 -0
  1152. package/packages/daemon/src/tui/mirror/workspace/terminal-pane-header.tsx +326 -0
  1153. package/packages/daemon/src/tui/mirror/workspace/terminal-scrollback.ts +216 -0
  1154. package/packages/daemon/src/tui/mirror/workspace/terminal-window-strip.tsx +466 -0
  1155. package/packages/daemon/src/tui/mirror/workspace/text.ts +28 -0
  1156. package/packages/daemon/src/tui/mirror/workspace/workbench-controller.ts +75 -0
  1157. package/packages/daemon/src/tui/mirror/workspace/workbench-dock-opentui.tsx +224 -0
  1158. package/packages/daemon/src/tui/mirror/workspace/workbench-shell.ts +486 -0
  1159. package/packages/daemon/src/tui/mirror/workspace/workbench-shell.tsx +95 -0
  1160. package/packages/daemon/src/tui/mirror/workspace-ui-state.ts +1278 -0
  1161. package/packages/daemon/src/tui/readiness.ts +52 -0
  1162. package/packages/daemon/src/tui/team/entry.ts +23 -13
  1163. package/packages/daemon/src/tui/team/home.ts +1 -1
  1164. package/packages/daemon/src/tui/team/index.tsx +27 -8
  1165. package/packages/daemon/src/tui/team/projects.ts +12 -0
  1166. package/packages/daemon/src/tui/team/sessions.ts +43 -48
  1167. package/packages/daemon/src/tui/team/wait-receipts.ts +192 -0
  1168. package/packages/daemon/src/ui/pane-frame/fixture.ts +43 -0
  1169. package/packages/daemon/src/ui/workbench-dock/fixture.ts +61 -0
  1170. package/packages/daemon/src/validate.ts +21 -9
  1171. package/packages/daemon/src/widgets/config/README.md +1 -1
  1172. package/packages/daemon/src/widgets/config/index.tsx +15 -115
  1173. package/packages/daemon/src/widgets/lib/watcher.ts +3 -130
  1174. package/packages/daemon/src/widgets/resolve.ts +18 -9
  1175. package/packages/daemon/src/widgets/setup/footer.tsx +0 -7
  1176. package/packages/daemon/src/widgets/setup/index.tsx +18 -20
  1177. package/packages/daemon/src/widgets/setup/review-panel.tsx +15 -10
  1178. package/packages/daemon/src/widgets/setup/setup-model.ts +7 -10
  1179. package/packages/daemon-client/package.json +42 -0
  1180. package/packages/daemon-client/src/application-shell-session.test.ts +196 -0
  1181. package/packages/daemon-client/src/application-shell-session.ts +450 -0
  1182. package/packages/daemon-client/src/bootstrap-coordinator.test.ts +122 -0
  1183. package/packages/daemon-client/src/bootstrap-coordinator.ts +293 -0
  1184. package/packages/daemon-client/src/connection-supervisor.test.ts +109 -0
  1185. package/packages/daemon-client/src/connection-supervisor.ts +216 -0
  1186. package/packages/daemon-client/src/direct-application-shell-transport.test.ts +939 -0
  1187. package/packages/daemon-client/src/direct-application-shell-transport.ts +1144 -0
  1188. package/packages/daemon-client/src/first-latest-coordinator.test.ts +175 -0
  1189. package/packages/daemon-client/src/first-latest-coordinator.ts +82 -0
  1190. package/packages/daemon-client/src/generation-bound-store-timers.test.ts +74 -0
  1191. package/packages/daemon-client/src/generation-bound-store.ts +908 -0
  1192. package/packages/daemon-client/src/index.ts +25 -0
  1193. package/packages/daemon-client/src/owner-action-client.test.ts +180 -0
  1194. package/packages/daemon-client/src/owner-action-client.ts +113 -0
  1195. package/packages/daemon-client/src/pane-stream-client.test.ts +2771 -0
  1196. package/packages/daemon-client/src/pane-stream-client.ts +1665 -0
  1197. package/packages/daemon-client/src/pane-stream-clock-calibration.test.ts +207 -0
  1198. package/packages/daemon-client/src/pane-stream-clock-calibration.ts +161 -0
  1199. package/packages/daemon-client/src/pane-stream-loopback-benchmark.test.ts +51 -0
  1200. package/packages/daemon-client/src/push-resource-session.test.ts +509 -0
  1201. package/packages/daemon-client/src/push-resource-session.ts +797 -0
  1202. package/packages/daemon-client/src/resource-replica.test.ts +186 -0
  1203. package/packages/daemon-client/src/resource-replica.ts +280 -0
  1204. package/packages/daemon-client/src/runtime-resource-ledger.test.ts +18 -0
  1205. package/packages/daemon-client/src/runtime-resource-ledger.ts +69 -0
  1206. package/packages/daemon-client/src/terminal-fast-lane.test.ts +817 -0
  1207. package/packages/daemon-client/src/terminal-fast-lane.ts +817 -0
  1208. package/packages/daemon-client/src/terminal-fast-lane.typecheck.ts +16 -0
  1209. package/packages/daemon-client/src/workspace-catalog-v2.test.ts +109 -0
  1210. package/packages/daemon-client/src/workspace-catalog-v2.ts +66 -0
  1211. package/packages/daemon-client/src/workspace-client-boundaries.test.ts +59 -0
  1212. package/packages/daemon-client/src/workspace-client-conformance.ts +67 -0
  1213. package/packages/daemon-client/src/workspace-client-operations.test.ts +47 -0
  1214. package/packages/daemon-client/src/workspace-client-operations.ts +220 -0
  1215. package/packages/daemon-client/src/workspace-client-types.ts +302 -0
  1216. package/packages/daemon-client/src/workspace-client.test.ts +2752 -0
  1217. package/packages/daemon-client/src/workspace-client.ts +1452 -0
  1218. package/packages/daemon-client/src/workspace-event-supervisor.test.ts +1086 -0
  1219. package/packages/daemon-client/src/workspace-event-supervisor.ts +719 -0
  1220. package/packages/daemon-client/src/workspace-pane-client.test.ts +80 -0
  1221. package/packages/daemon-client/src/workspace-pane-client.ts +63 -0
  1222. package/packages/presentation/package.json +28 -0
  1223. package/packages/presentation/src/index.ts +2 -0
  1224. package/packages/presentation/src/pane-frame/action-state.ts +72 -0
  1225. package/packages/presentation/src/pane-frame/index.ts +3 -0
  1226. package/packages/presentation/src/pane-frame/model.ts +517 -0
  1227. package/packages/presentation/src/pane-frame/presenter.tsx +335 -0
  1228. package/packages/presentation/src/pane-frame/web-entry.tsx +22 -0
  1229. package/packages/presentation/src/pane-frame/web-host-unstyled.tsx +280 -0
  1230. package/packages/presentation/src/pane-frame/web-host.css +388 -0
  1231. package/packages/presentation/src/pane-frame/web-host.tsx +3 -0
  1232. package/packages/presentation/src/presentation-contract.test.ts +63 -0
  1233. package/packages/presentation/src/workbench-dock/index.ts +2 -0
  1234. package/packages/presentation/src/workbench-dock/navigation.ts +54 -0
  1235. package/packages/presentation/src/workbench-dock/presenter.tsx +252 -0
  1236. package/packages/presentation/src/workbench-dock/web-entry.tsx +19 -0
  1237. package/packages/presentation/src/workbench-dock/web-host-unstyled.tsx +198 -0
  1238. package/packages/presentation/src/workbench-dock/web-host.css +204 -0
  1239. package/packages/presentation/src/workbench-dock/web-host.tsx +3 -0
  1240. package/packages/tmux-bridge/src/index.ts +9 -1
  1241. package/packages/tmux-bridge/src/panes.ts +4 -0
  1242. package/packages/tmux-bridge/src/runner.test.ts +72 -0
  1243. package/packages/tmux-bridge/src/runner.ts +43 -2
  1244. package/packages/tmux-bridge/src/sessions.ts +8 -1
  1245. package/scripts/postinstall.js +57 -6
  1246. package/skill/SKILL.md +27 -28
  1247. package/templates/agent-team-monorepo.yml +28 -30
  1248. package/templates/agent-team-nextjs.yml +24 -26
  1249. package/templates/agent-team.yml +24 -24
  1250. package/templates/convex.yml +24 -16
  1251. package/templates/default.yml +26 -21
  1252. package/templates/go.yml +21 -14
  1253. package/templates/missions.yml +25 -40
  1254. package/templates/nextjs.yml +24 -16
  1255. package/templates/python.yml +21 -14
  1256. package/templates/vite.yml +21 -14
  1257. package/bin/cli.ts +0 -1773
  1258. package/packages/daemon/dist/__tests__/support.d.ts +0 -7
  1259. package/packages/daemon/dist/agent-explain.d.ts +0 -52
  1260. package/packages/daemon/dist/attach.d.ts +0 -3
  1261. package/packages/daemon/dist/bin.d.ts +0 -2
  1262. package/packages/daemon/dist/canonical.d.ts +0 -2
  1263. package/packages/daemon/dist/cli.d.ts +0 -1
  1264. package/packages/daemon/dist/command-center/actions/contract.d.ts +0 -1
  1265. package/packages/daemon/dist/command-center/actions/dispatcher.d.ts +0 -27
  1266. package/packages/daemon/dist/command-center/actions/errors.d.ts +0 -38
  1267. package/packages/daemon/dist/command-center/actions/handlers/_project-context.d.ts +0 -12
  1268. package/packages/daemon/dist/command-center/actions/handlers/_resolve-project.d.ts +0 -42
  1269. package/packages/daemon/dist/command-center/actions/handlers/app-set-remote-access.d.ts +0 -23
  1270. package/packages/daemon/dist/command-center/actions/handlers/config-actions.d.ts +0 -12
  1271. package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.d.ts +0 -6
  1272. package/packages/daemon/dist/command-center/actions/handlers/project-activate.d.ts +0 -7
  1273. package/packages/daemon/dist/command-center/actions/handlers/project-launch.d.ts +0 -18
  1274. package/packages/daemon/dist/command-center/actions/handlers/project-open-terminal.d.ts +0 -32
  1275. package/packages/daemon/dist/command-center/actions/handlers/project-restart.d.ts +0 -17
  1276. package/packages/daemon/dist/command-center/actions/handlers/project-stop.d.ts +0 -24
  1277. package/packages/daemon/dist/command-center/actions/handlers/terminal-respawn.d.ts +0 -24
  1278. package/packages/daemon/dist/command-center/actions/handlers/terminal-stop.d.ts +0 -14
  1279. package/packages/daemon/dist/command-center/actions/registry.d.ts +0 -35
  1280. package/packages/daemon/dist/command-center/discovery.d.ts +0 -23
  1281. package/packages/daemon/dist/command-center/index.d.ts +0 -10
  1282. package/packages/daemon/dist/command-center/schemas.d.ts +0 -76
  1283. package/packages/daemon/dist/command-center/server.d.ts +0 -26
  1284. package/packages/daemon/dist/command-center/ws-events.d.ts +0 -59
  1285. package/packages/daemon/dist/config.d.ts +0 -19
  1286. package/packages/daemon/dist/control/client.d.ts +0 -23
  1287. package/packages/daemon/dist/control/dispatch.d.ts +0 -34
  1288. package/packages/daemon/dist/control/fanout.d.ts +0 -19
  1289. package/packages/daemon/dist/control/frames.d.ts +0 -23
  1290. package/packages/daemon/dist/control/lifecycle.d.ts +0 -45
  1291. package/packages/daemon/dist/control/server.d.ts +0 -16
  1292. package/packages/daemon/dist/control/verbs.d.ts +0 -11
  1293. package/packages/daemon/dist/detect.d.ts +0 -15
  1294. package/packages/daemon/dist/doctor.d.ts +0 -39
  1295. package/packages/daemon/dist/embed.d.ts +0 -1
  1296. package/packages/daemon/dist/index.d.ts +0 -3
  1297. package/packages/daemon/dist/init.d.ts +0 -4
  1298. package/packages/daemon/dist/inspect.d.ts +0 -54
  1299. package/packages/daemon/dist/launch.d.ts +0 -23
  1300. package/packages/daemon/dist/lib/active-projects.d.ts +0 -12
  1301. package/packages/daemon/dist/lib/agent-discovery.d.ts +0 -68
  1302. package/packages/daemon/dist/lib/app-config.d.ts +0 -253
  1303. package/packages/daemon/dist/lib/app-settings.d.ts +0 -9
  1304. package/packages/daemon/dist/lib/auth/auth-service.d.ts +0 -33
  1305. package/packages/daemon/dist/lib/auth/middleware.d.ts +0 -16
  1306. package/packages/daemon/dist/lib/auth/types.d.ts +0 -1
  1307. package/packages/daemon/dist/lib/auth-token.d.ts +0 -1
  1308. package/packages/daemon/dist/lib/authorship.d.ts +0 -62
  1309. package/packages/daemon/dist/lib/canonical-daemon.d.ts +0 -21
  1310. package/packages/daemon/dist/lib/cli-action-bridge.d.ts +0 -27
  1311. package/packages/daemon/dist/lib/daemon-embed.d.ts +0 -31
  1312. package/packages/daemon/dist/lib/daemon-watchdog.d.ts +0 -16
  1313. package/packages/daemon/dist/lib/daemon.d.ts +0 -8
  1314. package/packages/daemon/dist/lib/dot-path.d.ts +0 -2
  1315. package/packages/daemon/dist/lib/errors.d.ts +0 -37
  1316. package/packages/daemon/dist/lib/filesystem-browser.d.ts +0 -85
  1317. package/packages/daemon/dist/lib/launch-plan.d.ts +0 -6
  1318. package/packages/daemon/dist/lib/log.d.ts +0 -40
  1319. package/packages/daemon/dist/lib/manifest-pack.d.ts +0 -79
  1320. package/packages/daemon/dist/lib/output.d.ts +0 -9
  1321. package/packages/daemon/dist/lib/project-init-runner.d.ts +0 -46
  1322. package/packages/daemon/dist/lib/project-inspect.d.ts +0 -28
  1323. package/packages/daemon/dist/lib/project-onboard.d.ts +0 -58
  1324. package/packages/daemon/dist/lib/project-probe.d.ts +0 -35
  1325. package/packages/daemon/dist/lib/project-registry.d.ts +0 -76
  1326. package/packages/daemon/dist/lib/session-monitor.d.ts +0 -15
  1327. package/packages/daemon/dist/lib/session-options.d.ts +0 -13
  1328. package/packages/daemon/dist/lib/shell.d.ts +0 -5
  1329. package/packages/daemon/dist/lib/sizes.d.ts +0 -16
  1330. package/packages/daemon/dist/lib/skill-sync.d.ts +0 -60
  1331. package/packages/daemon/dist/lib/slugify.d.ts +0 -4
  1332. package/packages/daemon/dist/lib/state-home.d.ts +0 -2
  1333. package/packages/daemon/dist/lib/terminals-store.d.ts +0 -27
  1334. package/packages/daemon/dist/lib/tui-binary.d.ts +0 -57
  1335. package/packages/daemon/dist/lib/update-check.d.ts +0 -118
  1336. package/packages/daemon/dist/lib/update.d.ts +0 -65
  1337. package/packages/daemon/dist/lib/workspace-registry.d.ts +0 -84
  1338. package/packages/daemon/dist/lib/worktree.d.ts +0 -76
  1339. package/packages/daemon/dist/lib/yaml-io.d.ts +0 -10
  1340. package/packages/daemon/dist/ls.d.ts +0 -3
  1341. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +0 -34
  1342. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  1343. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/PkgInfo +0 -1
  1344. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/AppIcon.icns +0 -0
  1345. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  1346. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +0 -139
  1347. package/packages/daemon/dist/restart.d.ts +0 -4
  1348. package/packages/daemon/dist/restore.d.ts +0 -113
  1349. package/packages/daemon/dist/schemas/domain.d.ts +0 -1
  1350. package/packages/daemon/dist/schemas/filesystem.d.ts +0 -29
  1351. package/packages/daemon/dist/schemas/ide-config.d.ts +0 -1
  1352. package/packages/daemon/dist/schemas/index.d.ts +0 -12
  1353. package/packages/daemon/dist/schemas/inspect.d.ts +0 -53
  1354. package/packages/daemon/dist/schemas/registry.d.ts +0 -35
  1355. package/packages/daemon/dist/schemas/ws-events.d.ts +0 -72
  1356. package/packages/daemon/dist/send.d.ts +0 -59
  1357. package/packages/daemon/dist/server/index.d.ts +0 -10
  1358. package/packages/daemon/dist/server/pty-bridge.d.ts +0 -174
  1359. package/packages/daemon/dist/server/ws-route.d.ts +0 -74
  1360. package/packages/daemon/dist/status.d.ts +0 -3
  1361. package/packages/daemon/dist/stop.d.ts +0 -3
  1362. package/packages/daemon/dist/terminal/NodePtyAdapter.d.ts +0 -44
  1363. package/packages/daemon/dist/terminal/PtyAdapter.d.ts +0 -124
  1364. package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.d.ts +0 -77
  1365. package/packages/daemon/dist/types.d.ts +0 -2
  1366. package/packages/daemon/dist/validate.d.ts +0 -4
  1367. package/packages/daemon/dist/widgets/changes/index.jsx +0 -575
  1368. package/packages/daemon/dist/widgets/config/index.d.ts +0 -1
  1369. package/packages/daemon/dist/widgets/config/index.jsx +0 -395
  1370. package/packages/daemon/dist/widgets/explorer/breadcrumbs.d.ts +0 -10
  1371. package/packages/daemon/dist/widgets/explorer/breadcrumbs.jsx +0 -51
  1372. package/packages/daemon/dist/widgets/explorer/footer.d.ts +0 -6
  1373. package/packages/daemon/dist/widgets/explorer/footer.jsx +0 -11
  1374. package/packages/daemon/dist/widgets/explorer/index.jsx +0 -393
  1375. package/packages/daemon/dist/widgets/explorer/tree-model.d.ts +0 -13
  1376. package/packages/daemon/dist/widgets/explorer/tree.d.ts +0 -13
  1377. package/packages/daemon/dist/widgets/explorer/tree.jsx +0 -108
  1378. package/packages/daemon/dist/widgets/lib/config-model.d.ts +0 -22
  1379. package/packages/daemon/dist/widgets/lib/files.d.ts +0 -11
  1380. package/packages/daemon/dist/widgets/lib/git.d.ts +0 -11
  1381. package/packages/daemon/dist/widgets/lib/grammar.d.ts +0 -79
  1382. package/packages/daemon/dist/widgets/lib/help-overlay.d.ts +0 -19
  1383. package/packages/daemon/dist/widgets/lib/help-overlay.jsx +0 -69
  1384. package/packages/daemon/dist/widgets/lib/pane-comms.d.ts +0 -28
  1385. package/packages/daemon/dist/widgets/lib/theme.d.ts +0 -44
  1386. package/packages/daemon/dist/widgets/lib/watcher.d.ts +0 -9
  1387. package/packages/daemon/dist/widgets/preview/index.jsx +0 -371
  1388. package/packages/daemon/dist/widgets/resolve.d.ts +0 -20
  1389. package/packages/daemon/dist/widgets/setup/agent-naming.d.ts +0 -9
  1390. package/packages/daemon/dist/widgets/setup/agent-naming.jsx +0 -81
  1391. package/packages/daemon/dist/widgets/setup/config-tree.d.ts +0 -13
  1392. package/packages/daemon/dist/widgets/setup/config-tree.jsx +0 -203
  1393. package/packages/daemon/dist/widgets/setup/detect-panel.d.ts +0 -14
  1394. package/packages/daemon/dist/widgets/setup/detect-panel.jsx +0 -48
  1395. package/packages/daemon/dist/widgets/setup/field-editor.d.ts +0 -12
  1396. package/packages/daemon/dist/widgets/setup/field-editor.jsx +0 -163
  1397. package/packages/daemon/dist/widgets/setup/footer.d.ts +0 -17
  1398. package/packages/daemon/dist/widgets/setup/footer.jsx +0 -64
  1399. package/packages/daemon/dist/widgets/setup/index.d.ts +0 -1
  1400. package/packages/daemon/dist/widgets/setup/index.jsx +0 -261
  1401. package/packages/daemon/dist/widgets/setup/layout-picker.d.ts +0 -9
  1402. package/packages/daemon/dist/widgets/setup/layout-picker.jsx +0 -69
  1403. package/packages/daemon/dist/widgets/setup/setup-model.d.ts +0 -15
  1404. package/packages/daemon/dist/widgets/sidebar/index.jsx +0 -462
  1405. package/packages/daemon/src/tui/mirror/control-client.ts +0 -214
  1406. package/packages/daemon/src/tui/mirror/control.ts +0 -97
  1407. package/packages/daemon/src/tui/mirror/focus-border.ts +0 -57
  1408. package/packages/daemon/src/tui/mirror/input-coalescer.ts +0 -105
  1409. package/packages/daemon/src/tui/mirror/session-mirror.ts +0 -724
  1410. package/packages/daemon/src/widgets/setup/orchestrator-panel.tsx +0 -200
  1411. package/scripts/build-cli.mjs +0 -101
  1412. package/scripts/build-macos-notifier.mjs +0 -160
  1413. package/scripts/build-tui.mjs +0 -65
  1414. package/scripts/capture-codex-traffic.mjs +0 -195
  1415. package/scripts/check-src-additions.sh +0 -74
  1416. package/scripts/coverage-summary.mjs +0 -68
  1417. package/scripts/install-git-hooks.js +0 -53
  1418. package/scripts/merge-update-manifests.mjs +0 -58
  1419. package/scripts/merge-update-manifests.test.mjs +0 -82
  1420. package/scripts/pack-check-run.mjs +0 -83
  1421. package/scripts/perf-mirror.mjs +0 -313
  1422. package/scripts/prepublish-check.mjs +0 -80
  1423. package/scripts/publish-tap.sh +0 -55
  1424. package/scripts/stress-test.ts +0 -141
  1425. package/scripts/verify-endpoints.sh +0 -90
  1426. /package/packages/daemon/dist/{server/standalone.d.ts → terminal/mirror/trusted-inventory.js} +0 -0
  1427. /package/packages/daemon/dist/{widgets/changes/index.d.ts → terminal/session-runtime/terminal-interpreter-backend.js} +0 -0
  1428. /package/packages/daemon/dist/{widgets/explorer/index.d.ts → tui/mirror/features/changes/contract.js} +0 -0
  1429. /package/packages/daemon/dist/{widgets/preview/index.d.ts → tui/mirror/features/dialogs/contract.js} +0 -0
  1430. /package/packages/daemon/dist/{widgets/sidebar/index.d.ts → tui/mirror/features/performance-hud/contract.js} +0 -0
  1431. /package/packages/daemon/src/{tui/mirror → terminal/protocol}/layout-parse.ts +0 -0
@@ -0,0 +1,2670 @@
1
+ /**
2
+ * SessionChannel — one control-mode channel serving every pane subscription
3
+ * of one tmux session (m43 card 1).
4
+ *
5
+ * Responsibilities, in the order the bytes see them:
6
+ *
7
+ * - ROUTING: `%output`/`%extended-output` bytes are keyed by runtime `%N`
8
+ * and fanned out to that pane's subscribers through their {@link PaneFeed}
9
+ * gates. Runtime ids never leave this module — the public surface
10
+ * (subscribe, describe, layout events) speaks semantic ids only.
11
+ * - IDENTITY: the descriptor discovery ({@link SessionDescriptorDiscovery})
12
+ * feeds the workspace-tmux-adapter reconciliation; stamps are untrusted
13
+ * until verified, generated ids become real only after their pane-local
14
+ * stamp-back succeeds, and duplicate stamps are ALL restamped.
15
+ * - SEED/RESEED: the atomic recipe (capture + cursor probe back-to-back on
16
+ * the control channel, discard-until-reply) via `commandInline`, whose
17
+ * callbacks fire synchronously in channel read order.
18
+ * - FLOW: `%pause` bookkeeping in the {@link FlowLedger}; sticky-pause
19
+ * recovery continues+reseeds EVERY backpressure-paused pane that still has
20
+ * an unfrozen subscriber; explicit freeze/thaw parks one pane without
21
+ * touching siblings.
22
+ * - LAYOUT: `%layout-change`/`%window-pane-changed`/`%session-window-changed`
23
+ * are applied synchronously in notification order (ahead of any output the
24
+ * server emitted after the layout), joined to semantic window/pane ids.
25
+ * - INPUT: literals coalesce per pane (measured 256-byte chunks) and named
26
+ * keys flush pending literals first — the shared {@link InputCoalescer}
27
+ * discipline — leaving fire-and-forget via the channel.
28
+ */
29
+ import { createHash, randomBytes } from "node:crypto";
30
+ import { hostname } from "node:os";
31
+ import { WORKSPACE_SEMANTIC_PANE_OPTION, WORKSPACE_SEMANTIC_WINDOW_OPTION, WorkspaceIdSchemaZ, } from "@tmux-ide/contracts";
32
+ import { textToHexKeys } from "../protocol/control.js";
33
+ import { InputCoalescer } from "../protocol/input-coalescer.js";
34
+ import { NativeGridCaptureReader } from "./native-grid-reader.js";
35
+ import { parseLayout, parseLayoutChange, parseSessionWindowChanged, parseWindowPaneChanged, } from "../protocol/layout-parse.js";
36
+ import { SESSION_PANE_DESCRIPTOR_FORMAT, SessionDescriptorDiscovery, decodeControlReplyUtf8, decodeTmuxArgument, parseSessionPaneDescriptorReply, } from "../protocol/session-descriptor-discovery.js";
37
+ import { resolvePaneDisplayName } from "../protocol/pane-display-name.js";
38
+ import { finalizeWorkspaceTmuxReconciliation, planWorkspaceTmuxReconciliation, } from "../protocol/workspace-tmux-adapter.js";
39
+ import { FlowLedger } from "./flow-ledger.js";
40
+ import { PaneFeed } from "./pane-feed.js";
41
+ import { INTERNAL_READ_OPERATION_OPTION, registerInternalReadOperation, retireInternalReadOperation, } from "../../lib/tmux-interaction-options.js";
42
+ const TMUX_SERVER_HOSTNAME = hostname();
43
+ /** Notifications whose payload cannot be applied directly — fall back to the
44
+ * debounced truth sync (shared by all semantic terminal clients). */
45
+ const STRUCTURAL_NOTIFICATIONS = new Set([
46
+ "window-add",
47
+ "window-close",
48
+ "window-renamed",
49
+ "unlinked-window-close",
50
+ ]);
51
+ const NATIVE_CLIENT_NOTIFICATIONS = new Set([
52
+ "client-attached",
53
+ "client-detached",
54
+ "client-resized",
55
+ "client-session-changed",
56
+ "subscription-changed",
57
+ ]);
58
+ const NATIVE_CLIENT_SUBSCRIPTION = "tmux-ide-native-clients";
59
+ const SYNC_DEBOUNCE_MS = 40;
60
+ /** Foreground-command labels follow output, but never turn a busy pane into a probe loop. */
61
+ const DISPLAY_NAME_SYNC_INTERVAL_MS = 750;
62
+ const RECOVERY_QUIET_MS = 40;
63
+ const RECOVERY_COMMAND_DEADLINE_MS = 500;
64
+ const RECOVERY_NO_PROGRESS_DEADLINE_MS = 3_000;
65
+ const RECOVERY_ABSOLUTE_DEADLINE_MS = 5_000;
66
+ const RECOVERY_MAX_ATTEMPTS = 4;
67
+ const MAX_QUEUED_PLAIN_RESEEDS = 64;
68
+ const RECOVERY_CAPTURE_MAX_BYTES = 16 * 1024 * 1024;
69
+ // Budget row bookkeeping separately from wire bytes (64 bytes per retained
70
+ // line). A fixed 8192-row ceiling rejected small captures of ordinary history.
71
+ // Both the wire-byte cap and this finite allocation bound remain enforced.
72
+ const RECOVERY_CAPTURE_MAX_LINES = RECOVERY_CAPTURE_MAX_BYTES / 64;
73
+ const RECOVERY_CURSOR_MAX_BYTES = 1_024;
74
+ const MAX_CONTINUE_NOTIFICATION_QUEUE = 32;
75
+ const MAX_CONTINUE_NOTIFICATION_DEBT = 65_536;
76
+ const RECOVERY_CURSOR_PROBE_FORMAT = [
77
+ "#{cursor_x}",
78
+ "#{cursor_y}",
79
+ "#{pane_width}",
80
+ "#{pane_height}",
81
+ "#{alternate_on}",
82
+ "#{cursor_flag}",
83
+ "#{insert_flag}",
84
+ "#{keypad_cursor_flag}",
85
+ "#{keypad_flag}",
86
+ "#{mouse_any_flag}",
87
+ "#{mouse_button_flag}",
88
+ "#{mouse_standard_flag}",
89
+ "#{origin_flag}",
90
+ "#{wrap_flag}",
91
+ "#{history_size}",
92
+ "#{history_limit}",
93
+ "#{bracket_paste_flag}",
94
+ "#{mouse_all_flag}",
95
+ "#{mouse_sgr_flag}",
96
+ "#{mouse_utf8_flag}",
97
+ "#{scroll_region_upper}",
98
+ "#{scroll_region_lower}",
99
+ "#{scroll-on-clear}",
100
+ ].join(" ");
101
+ const FAILED_RESEED_RESULT = Object.freeze({
102
+ ok: false,
103
+ fingerprint: null,
104
+ publish: () => false,
105
+ hold: () => { },
106
+ });
107
+ function snapshotFingerprint(captureLines, cursorLine, fallbackSize) {
108
+ const hash = createHash("sha256");
109
+ const append = (bytes) => {
110
+ const length = Buffer.allocUnsafe(4);
111
+ length.writeUInt32BE(bytes.byteLength);
112
+ hash.update(length);
113
+ hash.update(bytes);
114
+ };
115
+ hash.update("tmux-ide/recovery-snapshot/v1\0");
116
+ const count = Buffer.allocUnsafe(4);
117
+ count.writeUInt32BE(captureLines.length);
118
+ hash.update(count);
119
+ for (const line of captureLines)
120
+ append(Buffer.from(line, "latin1"));
121
+ append(Buffer.from(cursorLine, "utf8"));
122
+ append(Buffer.from(fallbackSize ? `${fallbackSize.cols}x${fallbackSize.rows}` : "no-layout-fallback", "ascii"));
123
+ return hash.digest("hex");
124
+ }
125
+ // tmux concatenates adjacent quoted/unquoted fragments; doubled single quotes
126
+ // do not escape a quote. Preserve nested commands across both parser passes.
127
+ function tmuxSingleQuote(value) {
128
+ return `'${value.replaceAll("'", "'\\''")}'`;
129
+ }
130
+ export function defaultMirrorPaneId() {
131
+ return `pane.mirror.${randomBytes(8).toString("hex")}`;
132
+ }
133
+ export function defaultMirrorWindowId() {
134
+ return `window.mirror.${randomBytes(8).toString("hex")}`;
135
+ }
136
+ export class SessionChannel {
137
+ opts;
138
+ io;
139
+ ledger = new FlowLedger();
140
+ discovery;
141
+ panesByRuntime = new Map();
142
+ panesBySemantic = new Map();
143
+ windowsByRuntime = new Map();
144
+ layoutByWindow = new Map();
145
+ activePaneByWindow = new Map();
146
+ layoutSubscribers = new Set();
147
+ layoutAuthoritySubscribers = new Set();
148
+ layoutTopologyEpoch = 0;
149
+ truthActive = new Map();
150
+ truthWindow = new Map();
151
+ currentWindow = "";
152
+ diagnostics = [];
153
+ degraded = false;
154
+ ageByRuntime = new Map();
155
+ maxAgeMs = 0;
156
+ geometryParticipating = false;
157
+ cancelSync = null;
158
+ lastDisplayNameSyncAtMs = 0;
159
+ disposed = false;
160
+ nativeGrid;
161
+ nativeClientProbePending = false;
162
+ windowAuthorityOrdinal = 0;
163
+ paneIncarnation = 0;
164
+ recoveryOrdinal = 0;
165
+ plainReseedActive = null;
166
+ plainReseedQueue = new Map();
167
+ outputOrdinals = new Map();
168
+ pendingLayoutOutput = new Map();
169
+ recoveries = new Map();
170
+ continueNotificationQueues = new Map();
171
+ trustedInventoryFlight = null;
172
+ trustedInventoryFlightSessionId = null;
173
+ attachedIdentity = null;
174
+ /** Settles once the FIRST identity join lands (or is proven impossible), so
175
+ * `start()` returns a channel whose semantic ids are subscribable. */
176
+ resolveFirstJoin = null;
177
+ firstJoin = new Promise((resolve) => {
178
+ this.resolveFirstJoin = resolve;
179
+ });
180
+ input = new InputCoalescer((action) => {
181
+ const startedAtMicros = action.traceIds?.length ? Math.floor(performance.now() * 1_000) : 0;
182
+ const pendingBeforeSend = action.traceIds?.length ? (this.io.pendingCount ?? 0) : 0;
183
+ const onReply = action.traceIds?.length
184
+ ? (reply) => this.opts.onInputAccepted?.(action, Math.floor(performance.now() * 1_000), reply.ok)
185
+ : undefined;
186
+ if (action.kind === "literal") {
187
+ this.io.send(`send-keys -t ${action.pane} -H ${textToHexKeys(action.text).join(" ")}`, onReply);
188
+ }
189
+ else if (action.kind === "bytes") {
190
+ this.io.send(`send-keys -t ${action.pane} -H ${Array.from(action.data, (byte) => byte.toString(16).padStart(2, "0")).join(" ")}`, onReply);
191
+ }
192
+ else {
193
+ this.io.send(`send-keys -t ${action.pane} ${action.key}`, onReply);
194
+ }
195
+ if (action.traceIds?.length)
196
+ this.opts.onInputWrite?.(action, startedAtMicros, Math.floor(performance.now() * 1_000), pendingBeforeSend);
197
+ }, (flush) => queueMicrotask(flush));
198
+ constructor(opts) {
199
+ this.opts = opts;
200
+ this.io = opts.createIo({
201
+ onOutput: (pane, data, ageMs, timing) => this.onOutput(pane, data, ageMs, timing),
202
+ onNotify: (name, rest) => this.onNotify(name, rest),
203
+ onExit: () => this.onChannelExit(),
204
+ });
205
+ this.nativeGrid = new NativeGridCaptureReader({
206
+ commandBoundedInline: this.io.commandListBoundedInline
207
+ ? (command, limits, onReply) => {
208
+ const runtime = /-t (%(?:0|[1-9][0-9]*))$/.exec(command)?.[1];
209
+ if (!runtime) {
210
+ onReply({ ok: false, lines: [] });
211
+ return;
212
+ }
213
+ const marker = registerInternalReadOperation(runtime);
214
+ this.io.commandListBoundedInline(`set-option -p -t ${runtime} ${INTERNAL_READ_OPERATION_OPTION} ${marker} ; ${command}`, 2, 1, limits, (reply) => {
215
+ if (!reply.ok)
216
+ this.retireInternalReadMarker(runtime, marker);
217
+ onReply(reply);
218
+ });
219
+ }
220
+ : undefined,
221
+ });
222
+ this.discovery = new SessionDescriptorDiscovery({
223
+ query: () => this.io.request(`list-panes -s -t "${this.opts.session}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`),
224
+ onDescriptors: (descriptors, listed) => {
225
+ void this.reconcileIdentity(descriptors, listed).catch(() => { });
226
+ },
227
+ onStatus: (status) => {
228
+ if (status) {
229
+ this.pushDiagnostic({
230
+ code: `DESCRIPTOR_${status.status.toUpperCase()}`,
231
+ message: status.message,
232
+ degraded: status.degraded,
233
+ });
234
+ // Discovery gave up: identity will not improve on its own — let
235
+ // start() return the (degraded) channel rather than hang.
236
+ if (status.status === "failed")
237
+ this.settleFirstJoin();
238
+ }
239
+ },
240
+ });
241
+ }
242
+ async start() {
243
+ await this.io.start();
244
+ await this.captureAttachedSessionIdentity();
245
+ // Changing border placement can resize PTYs without changing the layout
246
+ // string, so tmux emits no layout-change. Subscribe to this window option.
247
+ this.io.send("refresh-client -B 'tmux-ide-pane-borders:@*:#{pane-border-status}'");
248
+ this.io.send("refresh-client -B 'tmux-ide-copy-keys:@*:#{mode-keys}'");
249
+ this.io.send("refresh-client -B 'tmux-ide-pane-history:%*:#{history_size}'");
250
+ this.io.send("refresh-client -B 'tmux-ide-scroll-on-clear:%*:#{scroll-on-clear}'");
251
+ if (this.opts.onNativeClientActivity) {
252
+ // tmux does not guarantee `%client-attached` is broadcast to an
253
+ // existing control client. A format subscription is the documented,
254
+ // event-driven observation seam; its notification only schedules the
255
+ // coalesced list-clients proof below.
256
+ this.io.send(`refresh-client -B '${NATIVE_CLIENT_SUBSCRIPTION}::#{session_attached}'`);
257
+ }
258
+ await this.syncNow();
259
+ await this.firstJoin;
260
+ }
261
+ // ── Public surface (semantic ids only) ──────────────────────────────────
262
+ describe() {
263
+ const panes = [...this.panesBySemantic.values()].map((pane) => {
264
+ const display = resolvePaneDisplayName({
265
+ hostName: TMUX_SERVER_HOSTNAME,
266
+ semanticPaneId: pane.semanticId,
267
+ configuredName: pane.descriptor?.name,
268
+ configuredNameSource: pane.descriptor?.nameSource,
269
+ currentCommand: pane.descriptor?.currentCommand,
270
+ title: pane.descriptor?.title,
271
+ paneType: pane.descriptor?.type,
272
+ });
273
+ return {
274
+ semanticPaneId: pane.semanticId,
275
+ semanticWindowId: pane.windowRuntimeId
276
+ ? (this.windowsByRuntime.get(pane.windowRuntimeId)?.semanticId ?? null)
277
+ : null,
278
+ role: pane.descriptor?.role ?? null,
279
+ paneType: pane.descriptor?.type ?? null,
280
+ currentCommand: pane.descriptor?.currentCommand ?? null,
281
+ cwd: pane.descriptor?.cwd ?? null,
282
+ title: pane.descriptor?.title ?? null,
283
+ displayName: display.name,
284
+ displayNameSource: display.source,
285
+ windowName: pane.descriptor?.windowName ?? null,
286
+ active: pane.active,
287
+ };
288
+ });
289
+ return {
290
+ session: this.opts.session,
291
+ panes,
292
+ diagnostics: [...this.diagnostics],
293
+ degraded: this.degraded,
294
+ };
295
+ }
296
+ /**
297
+ * Strict daemon-internal inventory from this channel's current tmux truth.
298
+ * Unlike the background discovery path, this query awaits descriptor
299
+ * reconciliation before projecting and rejects incomplete identity rather
300
+ * than returning the previous descriptor snapshot.
301
+ */
302
+ describeTrustedInventory(expectedRuntimeSessionId) {
303
+ if (this.disposed) {
304
+ return Promise.reject(new Error(`mirror session ${this.opts.session} is disposed`));
305
+ }
306
+ if (this.trustedInventoryFlight) {
307
+ return this.trustedInventoryFlightSessionId === expectedRuntimeSessionId
308
+ ? this.trustedInventoryFlight
309
+ : Promise.reject(new Error(`trusted inventory identity changed for ${this.opts.session}`));
310
+ }
311
+ const flight = this.refreshTrustedInventory(expectedRuntimeSessionId).finally(() => {
312
+ if (this.trustedInventoryFlight === flight) {
313
+ this.trustedInventoryFlight = null;
314
+ this.trustedInventoryFlightSessionId = null;
315
+ }
316
+ });
317
+ this.trustedInventoryFlight = flight;
318
+ this.trustedInventoryFlightSessionId = expectedRuntimeSessionId;
319
+ return flight;
320
+ }
321
+ /** Read-only proof of the session this control client is actually attached to. */
322
+ async attachedSessionIdentity() {
323
+ if (this.disposed)
324
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
325
+ if (!this.attachedIdentity)
326
+ throw new Error(`mirror session ${this.opts.session} identity is absent`);
327
+ return this.attachedIdentity;
328
+ }
329
+ async captureAttachedSessionIdentity() {
330
+ const lines = await this.io.request(`display-message -p "#{qa:session_name}\t#{session_id}"`);
331
+ if (lines.length !== 1)
332
+ throw new Error(`mirror session ${this.opts.session} identity is absent`);
333
+ const decodedLine = decodeControlReplyUtf8(lines[0]);
334
+ if (decodedLine === null)
335
+ throw new Error(`mirror session ${this.opts.session} identity is malformed`);
336
+ const [encodedName = "", runtimeSessionId = ""] = decodedLine.split("\t");
337
+ const sessionName = decodeTmuxArgument(encodedName);
338
+ if (sessionName.length === 0 ||
339
+ sessionName.length > 160 ||
340
+ !/^\$(?:0|[1-9][0-9]*)$/u.test(runtimeSessionId) ||
341
+ runtimeSessionId.length > 32) {
342
+ throw new Error(`mirror session ${this.opts.session} identity is malformed`);
343
+ }
344
+ this.attachedIdentity = Object.freeze({ sessionName, runtimeSessionId });
345
+ }
346
+ /** Optional native backing, addressed through the verified semantic binding. */
347
+ captureNativeBacking(semanticPaneId, ownsSubscription = () => true) {
348
+ const pane = this.panesBySemantic.get(semanticPaneId);
349
+ if (!pane || this.disposed || !ownsSubscription())
350
+ return Promise.resolve({ status: "retired" });
351
+ const { runtimeId, incarnation } = pane;
352
+ this.input.flush();
353
+ const outputOrdinal = this.outputOrdinals.get(runtimeId) ?? 0;
354
+ const topologyEpoch = this.layoutTopologyEpoch;
355
+ const authorityOrdinal = this.windowAuthorityOrdinal;
356
+ return this.nativeGrid.read(runtimeId, () => !this.disposed &&
357
+ ownsSubscription() &&
358
+ this.panesBySemantic.get(semanticPaneId) === pane &&
359
+ this.panesByRuntime.get(runtimeId) === pane &&
360
+ pane.runtimeId === runtimeId &&
361
+ pane.incarnation === incarnation,
362
+ // This remains raw backing, not a canonical revision. Reject observed
363
+ // output/layout crossings before an owner can try to qualify it.
364
+ () => (this.outputOrdinals.get(runtimeId) ?? 0) === outputOrdinal &&
365
+ this.layoutTopologyEpoch === topologyEpoch &&
366
+ this.windowAuthorityOrdinal === authorityOrdinal);
367
+ }
368
+ subscribePane(semanticPaneId, onEvent, onLayout) {
369
+ const pane = this.panesBySemantic.get(semanticPaneId);
370
+ if (!pane) {
371
+ throw new Error(`unknown semantic pane ${semanticPaneId} in session ${this.opts.session}`);
372
+ }
373
+ const sub = {
374
+ feed: new PaneFeed(),
375
+ onEvent,
376
+ onLayout: onLayout ?? null,
377
+ pane,
378
+ frozen: false,
379
+ closed: false,
380
+ };
381
+ pane.subs.add(sub);
382
+ // A paused pane gains an unfrozen watcher: release the park before the
383
+ // seed so the capture reflects a flowing pane.
384
+ const recoveryReason = this.ledger.isRequested(pane.runtimeId)
385
+ ? "requested"
386
+ : this.ledger.isBackpressured(pane.runtimeId)
387
+ ? "backpressure"
388
+ : null;
389
+ if (recoveryReason)
390
+ this.beginRecovery(pane, recoveryReason);
391
+ else
392
+ this.reseedPlain(sub);
393
+ this.emitLayoutSnapshot(sub);
394
+ return {
395
+ semanticPaneId,
396
+ captureNativeBacking: () => this.captureNativeBacking(semanticPaneId, () => !sub.closed && sub.pane === pane && this.panesBySemantic.get(semanticPaneId) === pane),
397
+ readHistorySize: () => new Promise((resolve) => {
398
+ const current = () => !this.disposed &&
399
+ !sub.closed &&
400
+ !sub.frozen &&
401
+ this.panesByRuntime.get(pane.runtimeId) === pane;
402
+ if (!current()) {
403
+ resolve(null);
404
+ return;
405
+ }
406
+ this.io.commandInline(`display-message -p -t ${pane.runtimeId} "#{history_size}"`, (reply) => {
407
+ const value = reply.lines[0]?.trim() ?? "";
408
+ const size = Number(value);
409
+ resolve(current() && reply.ok && /^[0-9]+$/u.test(value) && Number.isSafeInteger(size)
410
+ ? size
411
+ : null);
412
+ });
413
+ }),
414
+ freeze: () => this.freeze(sub),
415
+ thaw: () => this.thaw(sub),
416
+ reseed: () => this.reseedPlain(sub),
417
+ sendText: (text) => {
418
+ if (!sub.closed)
419
+ this.input.literal(sub.pane.runtimeId, text);
420
+ },
421
+ sendKey: (key) => {
422
+ if (!sub.closed)
423
+ this.input.key(sub.pane.runtimeId, key);
424
+ },
425
+ close: () => this.closeSub(sub),
426
+ };
427
+ }
428
+ /** Session geometry without a dummy pane feed or terminal-content seed. */
429
+ subscribeLayout(onLayout) {
430
+ if (this.disposed)
431
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
432
+ this.layoutSubscribers.add(onLayout);
433
+ for (const windowRuntimeId of this.layoutByWindow.keys()) {
434
+ const event = this.layoutEventFor(windowRuntimeId);
435
+ if (event)
436
+ onLayout(event);
437
+ }
438
+ let closed = false;
439
+ return {
440
+ close: () => {
441
+ if (closed)
442
+ return;
443
+ closed = true;
444
+ this.layoutSubscribers.delete(onLayout);
445
+ },
446
+ };
447
+ }
448
+ /**
449
+ * Refresh all session/window authority before exposing a global layout
450
+ * subscription. A cached control-mode channel may have been retained while
451
+ * only the current window had emitted geometry; replaying that cache would
452
+ * strand a multi-window renderer behind its exact inventory-coverage gate.
453
+ */
454
+ async subscribeAuthoritativeLayout(onLayout, expectedSemanticPaneIds, onAuthority) {
455
+ if (this.disposed)
456
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
457
+ const identity = await this.attachedSessionIdentity();
458
+ const inventory = await this.describeTrustedInventory(identity.runtimeSessionId);
459
+ if (this.disposed)
460
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
461
+ const expectedByWindow = new Map();
462
+ for (const pane of inventory.panes) {
463
+ const expected = expectedByWindow.get(pane.runtimeWindowId) ?? new Set();
464
+ expected.add(pane.semanticPaneId);
465
+ expectedByWindow.set(pane.runtimeWindowId, expected);
466
+ }
467
+ if (expectedSemanticPaneIds) {
468
+ const requested = [...expectedSemanticPaneIds].sort();
469
+ const authoritative = inventory.panes.map(({ semanticPaneId }) => semanticPaneId).sort();
470
+ if (requested.length === 0 ||
471
+ new Set(requested).size !== requested.length ||
472
+ requested.length !== authoritative.length ||
473
+ requested.some((pane, index) => pane !== authoritative[index])) {
474
+ const error = new Error(`authoritative layout for ${this.opts.session} changed topology`);
475
+ error.name = "MirrorTopologyChangedError";
476
+ throw error;
477
+ }
478
+ }
479
+ if (expectedByWindow.size !== inventory.panes[0].sessionWindowCount ||
480
+ expectedByWindow.size !== this.windowsByRuntime.size) {
481
+ throw new Error(`authoritative layout for ${this.opts.session} has incomplete windows`);
482
+ }
483
+ for (const [runtimeWindowId, expectedPanes] of expectedByWindow) {
484
+ const event = this.layoutEventFor(runtimeWindowId);
485
+ if (!event)
486
+ throw new Error(`authoritative layout for ${this.opts.session} has incomplete panes`);
487
+ const observed = event.panes.flatMap(({ semanticPaneId }) => typeof semanticPaneId === "string" ? [semanticPaneId] : []);
488
+ if (observed.length !== event.panes.length ||
489
+ (event.zoomed ? observed.length !== 1 : observed.length !== expectedPanes.size) ||
490
+ new Set(observed).size !== observed.length ||
491
+ observed.some((pane) => !expectedPanes.has(pane))) {
492
+ throw new Error(`authoritative layout for ${this.opts.session} has incomplete panes`);
493
+ }
494
+ }
495
+ const handle = this.subscribeLayout(onLayout);
496
+ if (onAuthority) {
497
+ this.layoutAuthoritySubscribers.add(onAuthority);
498
+ this.emitLayoutAuthorityTo(onAuthority, identity.runtimeSessionId);
499
+ }
500
+ return {
501
+ close: () => {
502
+ handle.close();
503
+ if (onAuthority)
504
+ this.layoutAuthoritySubscribers.delete(onAuthority);
505
+ },
506
+ };
507
+ }
508
+ /** Controller-authorized input fast path. It deliberately reuses the one
509
+ * session InputCoalescer, so literal/key ordering and tmux application-mode
510
+ * named-key semantics are identical for GUI, TUI and direct subscribers. */
511
+ sendText(semanticPaneId, text, performanceTraceId, isolated = false) {
512
+ const pane = this.panesBySemantic.get(semanticPaneId);
513
+ if (!pane)
514
+ throw new Error(`unknown semantic pane ${semanticPaneId} in session ${this.opts.session}`);
515
+ if (isolated)
516
+ this.input.flush();
517
+ this.input.literal(pane.runtimeId, text, performanceTraceId);
518
+ if (isolated)
519
+ this.input.flush();
520
+ }
521
+ sendBytes(semanticPaneId, data, performanceTraceId) {
522
+ const pane = this.panesBySemantic.get(semanticPaneId);
523
+ if (!pane)
524
+ throw new Error(`unknown semantic pane ${semanticPaneId} in session ${this.opts.session}`);
525
+ this.input.bytes(pane.runtimeId, data, performanceTraceId);
526
+ }
527
+ sendKey(semanticPaneId, key, performanceTraceId) {
528
+ const pane = this.panesBySemantic.get(semanticPaneId);
529
+ if (!pane)
530
+ throw new Error(`unknown semantic pane ${semanticPaneId} in session ${this.opts.session}`);
531
+ this.input.key(pane.runtimeId, key, performanceTraceId);
532
+ }
533
+ fitViewport(cols, rows) {
534
+ if (!Number.isSafeInteger(cols) || !Number.isSafeInteger(rows) || cols < 2 || rows < 2) {
535
+ throw new RangeError("viewport must contain positive bounded terminal cells");
536
+ }
537
+ this.input.flush();
538
+ this.io.send(`refresh-client -C ${cols}x${rows}`);
539
+ }
540
+ /** Toggle whether the retained control client participates in tmux sizing. */
541
+ setGeometryParticipation(active) {
542
+ if (this.geometryParticipating === active)
543
+ return;
544
+ this.geometryParticipating = active;
545
+ this.input.flush();
546
+ this.io.send(`refresh-client -f ${active ? "!ignore-size" : "ignore-size"}`);
547
+ }
548
+ subscriberCount() {
549
+ let count = 0;
550
+ for (const pane of this.panesByRuntime.values())
551
+ count += pane.subs.size;
552
+ return count;
553
+ }
554
+ /** Fall-behind telemetry from the `%extended-output` age field. */
555
+ ageTelemetry() {
556
+ const byPane = {};
557
+ for (const [runtime, age] of this.ageByRuntime) {
558
+ const semantic = this.panesByRuntime.get(runtime)?.semanticId;
559
+ if (semantic)
560
+ byPane[semantic] = age;
561
+ }
562
+ return { maxAgeMs: this.maxAgeMs, byPane };
563
+ }
564
+ flowSnapshot() {
565
+ const toSemantic = (runtime) => this.panesByRuntime.get(runtime)?.semanticId ?? "(unidentified)";
566
+ const snapshot = this.ledger.snapshot();
567
+ return {
568
+ backpressured: snapshot.backpressured.map(toSemantic),
569
+ requested: snapshot.requested.map(toSemantic),
570
+ };
571
+ }
572
+ async dispose() {
573
+ if (this.disposed)
574
+ return;
575
+ this.disposed = true;
576
+ this.nativeGrid.dispose();
577
+ this.settleFirstJoin();
578
+ this.cancelSync?.();
579
+ this.cancelSync = null;
580
+ for (const runtime of [...this.recoveries.keys()])
581
+ this.cancelRecovery(runtime);
582
+ this.continueNotificationQueues.clear();
583
+ this.discovery.dispose();
584
+ this.input.flush();
585
+ for (const pane of this.panesByRuntime.values()) {
586
+ for (const sub of pane.subs) {
587
+ if (!sub.closed) {
588
+ sub.closed = true;
589
+ sub.cancelCapture?.();
590
+ sub.onEvent({ type: "closed" });
591
+ }
592
+ }
593
+ pane.subs.clear();
594
+ }
595
+ this.pendingLayoutOutput.clear();
596
+ this.layoutSubscribers.clear();
597
+ this.layoutAuthoritySubscribers.clear();
598
+ await this.io.dispose();
599
+ }
600
+ // ── Byte routing ─────────────────────────────────────────────────────────
601
+ onOutput(runtimePane, data, ageMs, timing) {
602
+ const windowId = this.panesByRuntime.get(runtimePane)?.windowRuntimeId;
603
+ const pending = windowId ? this.pendingLayoutOutput.get(windowId) : undefined;
604
+ if (pending) {
605
+ if (!pending.overflowed) {
606
+ pending.bytes += data.byteLength;
607
+ if (pending.bytes > 1024 * 1024 || pending.records.length >= 1024) {
608
+ pending.overflowed = true;
609
+ pending.records = [];
610
+ }
611
+ else
612
+ pending.records.push({ pane: runtimePane, data: data.slice(), ageMs, timing });
613
+ }
614
+ return;
615
+ }
616
+ const now = Date.now();
617
+ if (now - this.lastDisplayNameSyncAtMs >= DISPLAY_NAME_SYNC_INTERVAL_MS) {
618
+ this.lastDisplayNameSyncAtMs = now;
619
+ this.scheduleSync();
620
+ }
621
+ if (ageMs !== null) {
622
+ this.ageByRuntime.set(runtimePane, ageMs);
623
+ if (ageMs > this.maxAgeMs)
624
+ this.maxAgeMs = ageMs;
625
+ }
626
+ const pane = this.panesByRuntime.get(runtimePane);
627
+ if (!pane)
628
+ return;
629
+ const outputOrdinal = (this.outputOrdinals.get(runtimePane) ?? 0) + 1;
630
+ this.outputOrdinals.set(runtimePane, outputOrdinal);
631
+ this.opts.onOutputObserved?.(pane.semanticId, ageMs, timing);
632
+ let overflowed = false;
633
+ for (const sub of pane.subs) {
634
+ if (sub.frozen || sub.closed)
635
+ continue;
636
+ for (const event of sub.feed.delta(data))
637
+ sub.onEvent(event);
638
+ if (sub.feed.takeOverflowed())
639
+ overflowed = true;
640
+ }
641
+ if (overflowed)
642
+ this.restartRecoveryAfterOutputOverflow(pane);
643
+ this.noteRecoveryOutput(pane, outputOrdinal);
644
+ }
645
+ // ── Seed / reseed (the atomic recipe) ────────────────────────────────────
646
+ reseed(sub, onSettled, deferPublish = false) {
647
+ if (sub.closed || sub.frozen || this.disposed) {
648
+ onSettled?.(FAILED_RESEED_RESULT);
649
+ return;
650
+ }
651
+ sub.cancelCapture?.();
652
+ const runtime = sub.pane.runtimeId;
653
+ const epoch = sub.feed.beginReseed();
654
+ let settled = false;
655
+ let captureSucceeded = false;
656
+ let markerRetired = false;
657
+ let captureLines = null;
658
+ let cancelDeadline = null;
659
+ const settle = (result) => {
660
+ if (settled)
661
+ return;
662
+ settled = true;
663
+ cancelDeadline?.();
664
+ sub.cancelCapture = null;
665
+ onSettled?.(result);
666
+ };
667
+ // Keystroke ordering: pending coalesced input leaves before the probes.
668
+ this.input.flush();
669
+ const history = this.opts.historyLines ?? "";
670
+ const internalReadMarker = registerInternalReadOperation(runtime);
671
+ const retireMarker = () => {
672
+ if (markerRetired)
673
+ return;
674
+ markerRetired = true;
675
+ this.retireInternalReadMarker(runtime, internalReadMarker);
676
+ };
677
+ sub.cancelCapture = () => {
678
+ if (settled)
679
+ return;
680
+ settled = true;
681
+ cancelDeadline?.();
682
+ sub.cancelCapture = null;
683
+ sub.feed.abort(epoch);
684
+ if (!captureSucceeded)
685
+ retireMarker();
686
+ };
687
+ cancelDeadline = this.scheduleRecovery(() => {
688
+ if (settled)
689
+ return;
690
+ sub.feed.abort(epoch);
691
+ if (!captureSucceeded)
692
+ retireMarker();
693
+ settle(FAILED_RESEED_RESULT);
694
+ }, RECOVERY_ABSOLUTE_DEADLINE_MS);
695
+ // Keep retired reply slots in the control FIFO; their callbacks become
696
+ // no-ops so late responses cannot publish or consume a newer capture.
697
+ // Both probes ride one write burst; the FIFO reply order is the seam.
698
+ this.io.commandListInline(`set-option -p -t ${runtime} ${INTERNAL_READ_OPERATION_OPTION} ${internalReadMarker} ; capture-pane -p -e -J -S -${history} -t ${runtime}`, 2, 1, (reply) => {
699
+ if (settled)
700
+ return;
701
+ if (!reply.ok) {
702
+ // Successful captures consume the marker atomically inside the tmux
703
+ // after-capture-pane hook. The command-list also prevents a concurrent
704
+ // mirror from stealing the marker. Only failures need cleanup.
705
+ retireMarker();
706
+ sub.feed.abort(epoch);
707
+ settle(FAILED_RESEED_RESULT);
708
+ return;
709
+ }
710
+ captureSucceeded = true;
711
+ if (sub.closed || sub.frozen || this.disposed) {
712
+ sub.feed.abort(epoch);
713
+ settle(FAILED_RESEED_RESULT);
714
+ return;
715
+ }
716
+ captureLines = [...reply.lines];
717
+ sub.feed.captureReply(epoch, reply.lines);
718
+ });
719
+ this.io.commandInline(`display-message -p -t ${runtime} "${RECOVERY_CURSOR_PROBE_FORMAT}"`, (reply) => {
720
+ if (settled)
721
+ return;
722
+ if (sub.closed || sub.frozen || this.disposed) {
723
+ sub.feed.abort(epoch);
724
+ settle(FAILED_RESEED_RESULT);
725
+ return;
726
+ }
727
+ if (!reply.ok) {
728
+ if (!captureSucceeded)
729
+ retireMarker();
730
+ sub.feed.abort(epoch);
731
+ settle(FAILED_RESEED_RESULT);
732
+ return;
733
+ }
734
+ const cursorLine = reply.lines[0] ?? "";
735
+ const historySize = Number(cursorLine.trim().split(/\s+/)[14]);
736
+ if (Number.isSafeInteger(historySize) && historySize >= 0)
737
+ sub.pane.historySize = historySize;
738
+ const fallbackSize = this.layoutSizeFor(runtime);
739
+ this.observeScrollOnClear(sub.pane, cursorLine);
740
+ const events = sub.feed.cursorReply(epoch, cursorLine, fallbackSize);
741
+ let published = false;
742
+ const publish = () => {
743
+ if (published)
744
+ return true;
745
+ if (sub.closed || sub.frozen || this.disposed)
746
+ return false;
747
+ published = true;
748
+ for (const event of events)
749
+ sub.onEvent(event);
750
+ return true;
751
+ };
752
+ const ok = events.length > 0 && !sub.closed && captureLines !== null;
753
+ const result = {
754
+ ok,
755
+ fingerprint: ok ? snapshotFingerprint(captureLines, cursorLine, fallbackSize) : null,
756
+ publish,
757
+ hold: () => sub.feed.quarantine(epoch),
758
+ };
759
+ if (!deferPublish)
760
+ publish();
761
+ settle(result);
762
+ });
763
+ }
764
+ reseedPlain(sub, resumeReason = null) {
765
+ if (sub.closed || sub.frozen || this.disposed)
766
+ return;
767
+ if (this.plainReseedActive === sub)
768
+ sub.cancelCapture?.();
769
+ if (!this.plainReseedQueue.has(sub) && this.plainReseedQueue.size >= MAX_QUEUED_PLAIN_RESEEDS) {
770
+ this.failPlainReseed(sub);
771
+ return;
772
+ }
773
+ this.plainReseedQueue.set(sub, resumeReason);
774
+ if (this.plainReseedActive !== sub) {
775
+ // Output before this queued recipe starts is already in its future
776
+ // capture. Do not publish it using the prior geometry in the meantime.
777
+ sub.feed.beginReseed();
778
+ sub.cancelCapture = () => {
779
+ this.plainReseedQueue.delete(sub);
780
+ sub.cancelCapture = null;
781
+ sub.feed.abortCurrent();
782
+ };
783
+ }
784
+ this.drainPlainReseeds();
785
+ }
786
+ failPlainReseed(sub) {
787
+ if (sub.closed ||
788
+ sub.frozen ||
789
+ this.disposed ||
790
+ this.recoveries.has(sub.pane.runtimeId) ||
791
+ this.panesByRuntime.get(sub.pane.runtimeId) !== sub.pane)
792
+ return;
793
+ this.beginLocalOverflowRecovery(sub.pane);
794
+ }
795
+ drainPlainReseeds() {
796
+ if (this.plainReseedActive || this.disposed)
797
+ return;
798
+ const next = this.plainReseedQueue.entries().next().value;
799
+ if (!next)
800
+ return;
801
+ const [sub, resumeReason] = next;
802
+ this.plainReseedQueue.delete(sub);
803
+ if (sub.closed || sub.frozen) {
804
+ this.drainPlainReseeds();
805
+ return;
806
+ }
807
+ this.plainReseedActive = sub;
808
+ // Only the recipe actually submitted to the control FIFO owns a five
809
+ // second deadline. A large sibling projection cannot consume the waiting
810
+ // panes' entire capture budgets before their commands have been written.
811
+ this.reseed(sub, (result) => {
812
+ if (this.plainReseedActive !== sub)
813
+ return;
814
+ this.plainReseedActive = null;
815
+ if (!result.ok) {
816
+ // A stalled FIFO cannot make progress for queued recipes either. Retire
817
+ // them together instead of granting each another wait behind that slot.
818
+ const waiting = [...this.plainReseedQueue.keys()];
819
+ this.plainReseedQueue.clear();
820
+ for (const queued of waiting)
821
+ queued.cancelCapture?.();
822
+ this.failPlainReseed(sub);
823
+ for (const queued of waiting)
824
+ this.failPlainReseed(queued);
825
+ return;
826
+ }
827
+ // Admit the next recipe before publishing this potentially large seed.
828
+ this.drainPlainReseeds();
829
+ result.publish();
830
+ if (resumeReason && !sub.closed && !sub.frozen)
831
+ sub.onEvent({ type: "flow", state: "resumed", reason: resumeReason });
832
+ }, true);
833
+ if (this.plainReseedActive === sub) {
834
+ const cancel = sub.cancelCapture;
835
+ sub.cancelCapture = () => {
836
+ cancel?.();
837
+ this.plainReseedQueue.delete(sub);
838
+ if (this.plainReseedActive === sub)
839
+ this.plainReseedActive = null;
840
+ this.drainPlainReseeds();
841
+ };
842
+ }
843
+ }
844
+ retireInternalReadMarker(runtime, marker) {
845
+ if (!/^%(?:0|[1-9][0-9]*)$/u.test(runtime))
846
+ throw new TypeError("internal read cleanup requires a runtime pane id");
847
+ retireInternalReadOperation(marker, runtime);
848
+ // Pane capture phases overlap under cancellation. Clear only the exact
849
+ // failed marker so a late A callback cannot erase the newer B authority.
850
+ this.io.send(`if-shell -t ${runtime} -F "#{==:#{${INTERNAL_READ_OPERATION_OPTION}},${marker}}" ` +
851
+ `"set-option -pu -t ${runtime} ${INTERNAL_READ_OPERATION_OPTION}" ""`);
852
+ }
853
+ layoutSizeFor(runtime) {
854
+ for (const layout of this.layoutByWindow.values()) {
855
+ const leaf = layout.leaves.find((candidate) => candidate.id === runtime);
856
+ if (leaf)
857
+ return { cols: leaf.width, rows: leaf.height };
858
+ }
859
+ return null;
860
+ }
861
+ // ── Flow control ─────────────────────────────────────────────────────────
862
+ freeze(sub) {
863
+ if (sub.frozen || sub.closed)
864
+ return;
865
+ sub.frozen = true;
866
+ sub.cancelCapture?.();
867
+ sub.onEvent({ type: "flow", state: "paused", reason: "requested" });
868
+ const pane = sub.pane;
869
+ const allFrozen = [...pane.subs].every((candidate) => candidate.frozen || candidate.closed);
870
+ if (allFrozen) {
871
+ this.cancelRecovery(pane.runtimeId);
872
+ this.ledger.requestPause(pane.runtimeId);
873
+ this.io.send(`refresh-client -A '${pane.runtimeId}:pause'`);
874
+ }
875
+ }
876
+ thaw(sub) {
877
+ if (!sub.frozen || sub.closed)
878
+ return;
879
+ sub.frozen = false;
880
+ const runtime = sub.pane.runtimeId;
881
+ if (this.ledger.isRequested(runtime) || this.ledger.isBackpressured(runtime))
882
+ this.beginRecovery(sub.pane, "requested");
883
+ else
884
+ this.reseedPlain(sub, "requested");
885
+ this.recoverSticky();
886
+ }
887
+ continuePane(runtime) {
888
+ this.io.send(`refresh-client -A '${runtime}:continue'`);
889
+ this.ledger.noteContinued(runtime);
890
+ }
891
+ scheduleRecovery(callback, delayMs) {
892
+ if (this.opts.scheduleRecovery)
893
+ return this.opts.scheduleRecovery(callback, delayMs);
894
+ const timer = setTimeout(callback, delayMs);
895
+ return () => clearTimeout(timer);
896
+ }
897
+ observeRecovery(pane, recovery, phase, failureReason = null, fingerprintExact = null) {
898
+ const elapsedMicros = Math.min(RECOVERY_ABSOLUTE_DEADLINE_MS * 1_000, Math.max(0, Math.floor((this.recoveryNowMs() - recovery.startedAtMs) * 1_000)));
899
+ try {
900
+ this.opts.onFlowRecoveryObserved?.(Object.freeze({
901
+ semanticPaneId: pane.semanticId,
902
+ phase,
903
+ recoveryOrdinal: recovery.ordinal,
904
+ paneIncarnation: recovery.paneIncarnation,
905
+ outputOrdinal: this.outputOrdinals.get(recovery.runtimeId) ?? 0,
906
+ failureReason,
907
+ elapsedMicros,
908
+ fingerprintExact,
909
+ confirmationOrdinal: recovery.confirmationOrdinal,
910
+ collectorStarted: recovery.collectorStarted,
911
+ collectorLastCompletedOrdinal: recovery.collectorLastCompletedOrdinal,
912
+ collectorCaptureLineCount: recovery.collectorCaptureLineCount,
913
+ collectorCaptureByteCount: recovery.collectorCaptureByteCount,
914
+ collectorContinueObserved: recovery.collectorContinueObserved,
915
+ collectorStatusObserved: recovery.collectorStatusObserved,
916
+ collectorObserverEmissionObserved: recovery.collectorObserverEmissionObserved,
917
+ collectorFailureReason: recovery.collectorFailureReason,
918
+ }));
919
+ }
920
+ catch {
921
+ // Optional diagnostics cannot prevent recovery or failure delivery.
922
+ }
923
+ }
924
+ recoveryNowMs() {
925
+ return this.opts.recoveryNowMs?.() ?? performance.now();
926
+ }
927
+ recoveryPane(recovery) {
928
+ const pane = this.panesByRuntime.get(recovery.runtimeId);
929
+ return !this.disposed &&
930
+ this.recoveries.get(recovery.runtimeId) === recovery &&
931
+ pane?.incarnation === recovery.paneIncarnation
932
+ ? !recovery.retired
933
+ ? pane
934
+ : null
935
+ : null;
936
+ }
937
+ cancelRecovery(runtime) {
938
+ const recovery = this.recoveries.get(runtime);
939
+ if (!recovery)
940
+ return;
941
+ recovery.retired = true;
942
+ recovery.cancelQuiet?.();
943
+ recovery.cancelCommandDeadline?.();
944
+ recovery.cancelNoProgressDeadline?.();
945
+ recovery.cancelAbsoluteDeadline?.();
946
+ if (recovery.atomicCollectorNonce)
947
+ this.io.retireAtomicPaneSnapshotCollector?.(recovery.atomicCollectorNonce, "retired");
948
+ recovery.atomicCollectorNonce = null;
949
+ this.recoveries.delete(runtime);
950
+ this.retireContinueNotificationOwner(recovery);
951
+ const pane = this.panesByRuntime.get(runtime);
952
+ if (pane?.incarnation === recovery.paneIncarnation)
953
+ for (const sub of pane.subs)
954
+ sub.feed.abortCurrent();
955
+ }
956
+ beginRecovery(pane, reason) {
957
+ for (const sub of pane.subs)
958
+ sub.cancelCapture?.();
959
+ const runtime = pane.runtimeId;
960
+ this.cancelRecovery(runtime);
961
+ const recovery = {
962
+ ordinal: ++this.recoveryOrdinal,
963
+ runtimeId: runtime,
964
+ paneIncarnation: pane.incarnation,
965
+ reason,
966
+ startedAtMs: this.recoveryNowMs(),
967
+ retired: false,
968
+ continueReply: false,
969
+ continueNotify: false,
970
+ stage: "continue",
971
+ attempts: 0,
972
+ reseedOrdinal: 0,
973
+ outputOrdinal: this.outputOrdinals.get(runtime) ?? 0,
974
+ candidateFingerprint: null,
975
+ confirmationFingerprint: null,
976
+ confirmationOrdinal: 0,
977
+ atomicCollectorNonce: null,
978
+ collectorStarted: false,
979
+ collectorLastCompletedOrdinal: -1,
980
+ collectorCaptureLineCount: 0,
981
+ collectorCaptureByteCount: 0,
982
+ collectorContinueObserved: false,
983
+ collectorStatusObserved: false,
984
+ collectorObserverEmissionObserved: false,
985
+ collectorFailureReason: null,
986
+ cancelQuiet: null,
987
+ cancelCommandDeadline: null,
988
+ cancelNoProgressDeadline: null,
989
+ cancelAbsoluteDeadline: null,
990
+ };
991
+ this.recoveries.set(runtime, recovery);
992
+ for (const sub of pane.subs) {
993
+ if (!sub.frozen && !sub.closed)
994
+ sub.feed.abortCurrent();
995
+ }
996
+ this.observeRecovery(pane, recovery, "pause");
997
+ this.observeRecovery(pane, recovery, "continue-request");
998
+ recovery.cancelCommandDeadline = this.scheduleRecovery(() => {
999
+ if (this.recoveryPane(recovery) && !recovery.continueReply)
1000
+ this.failRecovery(recovery, "command-timeout");
1001
+ }, RECOVERY_COMMAND_DEADLINE_MS);
1002
+ const queue = this.continueNotificationQueues.get(runtime) ?? [];
1003
+ if (queue.length >= MAX_CONTINUE_NOTIFICATION_QUEUE) {
1004
+ this.failRecovery(recovery, "notification-queue-overflow");
1005
+ return;
1006
+ }
1007
+ queue.push({ kind: "owner", recovery });
1008
+ this.continueNotificationQueues.set(runtime, queue);
1009
+ this.io.send(`refresh-client -A '${runtime}:continue'`, (reply) => {
1010
+ const current = this.recoveryPane(recovery);
1011
+ if (!reply.ok) {
1012
+ this.removeContinueNotificationOwner(recovery);
1013
+ if (current)
1014
+ this.failRecovery(recovery, "command-error");
1015
+ return;
1016
+ }
1017
+ recovery.continueReply = true;
1018
+ if (!current) {
1019
+ this.retireContinueNotificationOwner(recovery);
1020
+ return;
1021
+ }
1022
+ recovery.cancelCommandDeadline?.();
1023
+ recovery.cancelCommandDeadline = null;
1024
+ this.beginRecoveryConvergence(recovery);
1025
+ this.observeRecovery(current, recovery, "continue-reply");
1026
+ this.noteRecoveryProgress(recovery);
1027
+ this.beginFinalRecovery(recovery);
1028
+ });
1029
+ }
1030
+ beginLocalOverflowRecovery(pane) {
1031
+ for (const sub of pane.subs)
1032
+ sub.cancelCapture?.();
1033
+ const runtime = pane.runtimeId;
1034
+ this.cancelRecovery(runtime);
1035
+ const recovery = {
1036
+ ordinal: ++this.recoveryOrdinal,
1037
+ runtimeId: runtime,
1038
+ paneIncarnation: pane.incarnation,
1039
+ reason: "backpressure",
1040
+ startedAtMs: this.recoveryNowMs(),
1041
+ retired: false,
1042
+ continueReply: true,
1043
+ continueNotify: true,
1044
+ stage: "continue",
1045
+ attempts: 0,
1046
+ reseedOrdinal: 0,
1047
+ outputOrdinal: this.outputOrdinals.get(runtime) ?? 0,
1048
+ candidateFingerprint: null,
1049
+ confirmationFingerprint: null,
1050
+ confirmationOrdinal: 0,
1051
+ atomicCollectorNonce: null,
1052
+ collectorStarted: false,
1053
+ collectorLastCompletedOrdinal: -1,
1054
+ collectorCaptureLineCount: 0,
1055
+ collectorCaptureByteCount: 0,
1056
+ collectorContinueObserved: false,
1057
+ collectorStatusObserved: false,
1058
+ collectorObserverEmissionObserved: false,
1059
+ collectorFailureReason: null,
1060
+ cancelQuiet: null,
1061
+ cancelCommandDeadline: null,
1062
+ cancelNoProgressDeadline: null,
1063
+ cancelAbsoluteDeadline: null,
1064
+ };
1065
+ this.recoveries.set(runtime, recovery);
1066
+ for (const sub of pane.subs) {
1067
+ if (!sub.frozen && !sub.closed)
1068
+ sub.onEvent({ type: "flow", state: "paused", reason: "backpressure" });
1069
+ }
1070
+ this.observeRecovery(pane, recovery, "pause");
1071
+ this.beginRecoveryConvergence(recovery);
1072
+ this.beginFinalRecovery(recovery);
1073
+ }
1074
+ beginRecoveryConvergence(recovery) {
1075
+ if (recovery.cancelAbsoluteDeadline)
1076
+ return;
1077
+ recovery.cancelAbsoluteDeadline = this.scheduleRecovery(() => {
1078
+ if (this.recoveryPane(recovery))
1079
+ this.failRecovery(recovery, "absolute-deadline");
1080
+ }, RECOVERY_ABSOLUTE_DEADLINE_MS);
1081
+ this.noteRecoveryProgress(recovery);
1082
+ }
1083
+ noteRecoveryProgress(recovery) {
1084
+ if (!this.recoveryPane(recovery) || !recovery.cancelAbsoluteDeadline)
1085
+ return;
1086
+ recovery.cancelNoProgressDeadline?.();
1087
+ recovery.cancelNoProgressDeadline = this.scheduleRecovery(() => {
1088
+ if (this.recoveryPane(recovery))
1089
+ this.failRecovery(recovery, "no-progress");
1090
+ }, RECOVERY_NO_PROGRESS_DEADLINE_MS);
1091
+ }
1092
+ noteAtomicCollectorProgress(recovery, nonce, progress) {
1093
+ if (this.recoveryPane(recovery) === null ||
1094
+ recovery.atomicCollectorNonce !== nonce ||
1095
+ !progress.started)
1096
+ return;
1097
+ recovery.collectorStarted = true;
1098
+ recovery.collectorLastCompletedOrdinal = Math.max(recovery.collectorLastCompletedOrdinal, progress.lastCompletedOrdinal);
1099
+ recovery.collectorCaptureLineCount = Math.max(recovery.collectorCaptureLineCount, progress.captureLineCount);
1100
+ recovery.collectorCaptureByteCount = Math.max(recovery.collectorCaptureByteCount, progress.captureByteCount);
1101
+ recovery.collectorContinueObserved ||= progress.continueObserved;
1102
+ recovery.collectorStatusObserved ||= progress.statusObserved;
1103
+ recovery.collectorObserverEmissionObserved ||= progress.observerEmissionObserved;
1104
+ this.noteRecoveryProgress(recovery);
1105
+ }
1106
+ reseedRecoverySubscribers(pane, recovery, done, deferPublish = false) {
1107
+ if (this.io.armAtomicPaneSnapshotCollector && this.io.retireAtomicPaneSnapshotCollector) {
1108
+ this.reseedRecoverySubscribersAtomic(pane, recovery, done, deferPublish);
1109
+ return;
1110
+ }
1111
+ const live = [...pane.subs].filter((sub) => !sub.frozen && !sub.closed);
1112
+ if (live.length === 0) {
1113
+ done(FAILED_RESEED_RESULT);
1114
+ return;
1115
+ }
1116
+ const participants = live.map((sub) => Object.freeze({ sub, epoch: sub.feed.beginReseed() }));
1117
+ const reseedOrdinal = ++recovery.reseedOrdinal;
1118
+ let settled = false;
1119
+ let captureSucceeded = false;
1120
+ let markerRetired = false;
1121
+ let captureLines = null;
1122
+ // One pane authority capture is enough for every subscriber. Per-feed
1123
+ // epochs still independently fence delivery, while membership is frozen
1124
+ // across both FIFO replies so no subscriber can join half a snapshot.
1125
+ this.input.flush();
1126
+ const history = this.opts.historyLines ?? "";
1127
+ const internalReadMarker = registerInternalReadOperation(pane.runtimeId);
1128
+ const participantsExact = () => {
1129
+ if (this.recoveryPane(recovery) !== pane ||
1130
+ recovery.reseedOrdinal !== reseedOrdinal ||
1131
+ participants.some(({ sub }) => sub.closed || sub.frozen || sub.pane !== pane || !pane.subs.has(sub)))
1132
+ return false;
1133
+ const current = [...pane.subs].filter((sub) => !sub.frozen && !sub.closed);
1134
+ return (current.length === participants.length &&
1135
+ current.every((sub) => participants.some((participant) => participant.sub === sub)));
1136
+ };
1137
+ const retireMarker = () => {
1138
+ if (markerRetired)
1139
+ return;
1140
+ markerRetired = true;
1141
+ this.retireInternalReadMarker(pane.runtimeId, internalReadMarker);
1142
+ };
1143
+ const fail = () => {
1144
+ if (settled)
1145
+ return;
1146
+ settled = true;
1147
+ if (!captureSucceeded)
1148
+ retireMarker();
1149
+ for (const { sub } of participants)
1150
+ sub.feed.abortCurrent();
1151
+ done(FAILED_RESEED_RESULT);
1152
+ };
1153
+ this.io.commandListInline(`set-option -p -t ${pane.runtimeId} ${INTERNAL_READ_OPERATION_OPTION} ${internalReadMarker} ; capture-pane -p -e -J -S -${history} -t ${pane.runtimeId}`, 2, 1, (reply) => {
1154
+ if (!reply.ok) {
1155
+ fail();
1156
+ return;
1157
+ }
1158
+ captureSucceeded = true;
1159
+ if (!participantsExact()) {
1160
+ fail();
1161
+ return;
1162
+ }
1163
+ captureLines = Object.freeze([...reply.lines]);
1164
+ for (const { sub, epoch } of participants)
1165
+ sub.feed.captureReply(epoch, captureLines);
1166
+ });
1167
+ this.io.commandInline(`display-message -p -t ${pane.runtimeId} "${RECOVERY_CURSOR_PROBE_FORMAT}"`, (reply) => {
1168
+ if (settled)
1169
+ return;
1170
+ if (!participantsExact() || captureLines === null || !reply.ok) {
1171
+ fail();
1172
+ return;
1173
+ }
1174
+ const cursorLine = reply.lines[0] ?? "";
1175
+ const fallbackSize = this.layoutSizeFor(pane.runtimeId);
1176
+ this.observeScrollOnClear(pane, cursorLine);
1177
+ const deliveries = participants.map(({ sub, epoch }) => ({
1178
+ sub,
1179
+ epoch,
1180
+ events: sub.feed.cursorReply(epoch, cursorLine, fallbackSize),
1181
+ }));
1182
+ if (!participantsExact() || deliveries.some(({ events }) => events.length === 0)) {
1183
+ fail();
1184
+ return;
1185
+ }
1186
+ let published = false;
1187
+ const publish = () => {
1188
+ if (published)
1189
+ return true;
1190
+ if (!participantsExact())
1191
+ return false;
1192
+ published = true;
1193
+ for (const { sub, events } of deliveries)
1194
+ for (const event of events)
1195
+ sub.onEvent(event);
1196
+ return participantsExact();
1197
+ };
1198
+ if (!deferPublish && !publish()) {
1199
+ fail();
1200
+ return;
1201
+ }
1202
+ for (const { sub, epoch } of deliveries)
1203
+ sub.feed.quarantine(epoch);
1204
+ settled = true;
1205
+ done({
1206
+ ok: true,
1207
+ fingerprint: snapshotFingerprint(captureLines, cursorLine, fallbackSize),
1208
+ publish,
1209
+ hold: () => { },
1210
+ });
1211
+ });
1212
+ }
1213
+ reseedRecoverySubscribersAtomic(pane, recovery, done, deferPublish) {
1214
+ const live = [...pane.subs].filter((sub) => !sub.frozen && !sub.closed);
1215
+ if (live.length === 0) {
1216
+ done(FAILED_RESEED_RESULT);
1217
+ return;
1218
+ }
1219
+ const participants = live.map((sub) => Object.freeze({ sub, epoch: sub.feed.beginReseed() }));
1220
+ const reseedOrdinal = ++recovery.reseedOrdinal;
1221
+ const nonce = this.opts.generateAtomicHookNonce?.() ?? randomBytes(24).toString("hex");
1222
+ if (!/^[0-9a-f]{32,128}$/u.test(nonce)) {
1223
+ for (const { sub } of participants)
1224
+ sub.feed.abortCurrent();
1225
+ done(FAILED_RESEED_RESULT);
1226
+ return;
1227
+ }
1228
+ const hookName = `@tmux_ide_atomic_${nonce}`;
1229
+ const expectedName = `@tmux_ide_atomic_expected_${nonce}`;
1230
+ const ownerName = `@tmux_ide_atomic_owner_${nonce}`;
1231
+ const internalReadMarker = registerInternalReadOperation(pane.runtimeId);
1232
+ recovery.atomicCollectorNonce = nonce;
1233
+ recovery.collectorStarted = false;
1234
+ recovery.collectorLastCompletedOrdinal = -1;
1235
+ recovery.collectorCaptureLineCount = 0;
1236
+ recovery.collectorCaptureByteCount = 0;
1237
+ recovery.collectorContinueObserved = false;
1238
+ recovery.collectorStatusObserved = false;
1239
+ recovery.collectorObserverEmissionObserved = false;
1240
+ recovery.collectorFailureReason = null;
1241
+ const participantsExact = () => {
1242
+ if (this.recoveryPane(recovery) !== pane ||
1243
+ recovery.reseedOrdinal !== reseedOrdinal ||
1244
+ participants.some(({ sub }) => sub.closed || sub.frozen || sub.pane !== pane || !pane.subs.has(sub)))
1245
+ return false;
1246
+ const current = [...pane.subs].filter((sub) => !sub.frozen && !sub.closed);
1247
+ return (current.length === participants.length &&
1248
+ current.every((sub) => participants.some((participant) => participant.sub === sub)));
1249
+ };
1250
+ let settled = false;
1251
+ let observerEmitted = false;
1252
+ const hookOwned = `#{==:#{${ownerName}},${nonce}}`;
1253
+ const hookUnchanged = `#{==:#{${hookName}},#{${expectedName}}}`;
1254
+ const cleanupHook = () => {
1255
+ this.io.commandListInline(`if-shell -t ${pane.runtimeId} -F "#{&&:${hookOwned},${hookUnchanged}}" ` +
1256
+ `${tmuxSingleQuote(`set-option -pu -t ${pane.runtimeId} ${hookName}`)} ` +
1257
+ tmuxSingleQuote(`display-message -p -t ${pane.runtimeId} tmux-ide-atomic-cleanup-hook-skip-v1:${nonce}`), 2, 1, () => { });
1258
+ this.io.commandListInline(`if-shell -t ${pane.runtimeId} -F "${hookOwned}" ` +
1259
+ tmuxSingleQuote(`set-option -pu -t ${pane.runtimeId} ${expectedName}`) +
1260
+ ` ${tmuxSingleQuote(`display-message -p -t ${pane.runtimeId} tmux-ide-atomic-cleanup-expected-skip-v1:${nonce}`)}`, 2, 1, () => { });
1261
+ this.io.commandListInline(`if-shell -t ${pane.runtimeId} -F "${hookOwned}" ` +
1262
+ tmuxSingleQuote(`set-option -pu -t ${pane.runtimeId} ${ownerName}`) +
1263
+ ` ${tmuxSingleQuote(`display-message -p -t ${pane.runtimeId} tmux-ide-atomic-cleanup-owner-skip-v1:${nonce}`)}`, 2, 1, () => { });
1264
+ };
1265
+ const fail = (statusObserved = false) => {
1266
+ if (settled)
1267
+ return;
1268
+ settled = true;
1269
+ if (recovery.atomicCollectorNonce === nonce)
1270
+ recovery.atomicCollectorNonce = null;
1271
+ cleanupHook();
1272
+ if (!statusObserved && !observerEmitted)
1273
+ this.retireInternalReadMarker(pane.runtimeId, internalReadMarker);
1274
+ for (const { sub } of participants)
1275
+ sub.feed.abortCurrent();
1276
+ done(FAILED_RESEED_RESULT);
1277
+ };
1278
+ let observer;
1279
+ try {
1280
+ observer = this.opts.internalReadHookEmission?.(pane.runtimeId, internalReadMarker) ?? null;
1281
+ }
1282
+ catch {
1283
+ fail();
1284
+ return;
1285
+ }
1286
+ const safeObserver = observer !== null &&
1287
+ /^[A-Za-z0-9._-]{1,256}$/u.test(observer.bufferName) &&
1288
+ /^[A-Za-z0-9._-]{1,256}$/u.test(observer.signalChannel) &&
1289
+ /^[A-Za-z0-9%:._|-]{1,1024}$/u.test(observer.record);
1290
+ if (!safeObserver) {
1291
+ fail();
1292
+ return;
1293
+ }
1294
+ const sentinel = (kind) => `display-message -p -l -t ${pane.runtimeId} ` + `"%tmux-ide-atomic-v1 ${nonce} ${kind}"`;
1295
+ const observerCommands = ` ; set-buffer -a -b ${observer.bufferName} ${tmuxSingleQuote(observer.record)}` +
1296
+ ` ; wait-for -S ${observer.signalChannel}`;
1297
+ const body = `set-option -po -t ${pane.runtimeId} ${INTERNAL_READ_OPERATION_OPTION} ${internalReadMarker}` +
1298
+ ` ; ${sentinel("start")}` +
1299
+ ` ; capture-pane -p -e -J -S -${this.opts.historyLines ?? ""} -t ${pane.runtimeId}` +
1300
+ ` ; ${sentinel("capture-end")}` +
1301
+ ` ; display-message -p -t ${pane.runtimeId} "${RECOVERY_CURSOR_PROBE_FORMAT}"` +
1302
+ ` ; ${sentinel("cursor-end")}` +
1303
+ ` ; refresh-client -A ${tmuxSingleQuote(`${pane.runtimeId}:continue`)}` +
1304
+ observerCommands +
1305
+ ` ; if-shell -t ${pane.runtimeId} -F ` +
1306
+ `"#{==:#{${INTERNAL_READ_OPERATION_OPTION}},${internalReadMarker}}" ` +
1307
+ tmuxSingleQuote(`set-option -pu -t ${pane.runtimeId} ${INTERNAL_READ_OPERATION_OPTION}`) +
1308
+ ` ${tmuxSingleQuote(`${sentinel("marker-rejected")}`)}` +
1309
+ ` ; ${sentinel("status-ok")}` +
1310
+ ` ; set-option -pu -t ${pane.runtimeId} ${hookName}` +
1311
+ ` ; ${sentinel("complete")}`;
1312
+ this.input.flush();
1313
+ const invoke = (reply) => {
1314
+ if (!reply.ok || !participantsExact()) {
1315
+ fail();
1316
+ return;
1317
+ }
1318
+ const remaining = Math.floor(RECOVERY_ABSOLUTE_DEADLINE_MS - (this.recoveryNowMs() - recovery.startedAtMs));
1319
+ if (remaining <= 0) {
1320
+ fail();
1321
+ return;
1322
+ }
1323
+ const armed = this.io.armAtomicPaneSnapshotCollector({
1324
+ nonce,
1325
+ runtimePaneId: pane.runtimeId,
1326
+ maxCaptureBytes: RECOVERY_CAPTURE_MAX_BYTES,
1327
+ maxCaptureLines: RECOVERY_CAPTURE_MAX_LINES,
1328
+ maxCursorBytes: RECOVERY_CURSOR_MAX_BYTES,
1329
+ observerCommandCount: 2,
1330
+ onProgress: (progress) => this.noteAtomicCollectorProgress(recovery, nonce, progress),
1331
+ onSettled: (result) => {
1332
+ if (recovery.atomicCollectorNonce === nonce)
1333
+ recovery.atomicCollectorNonce = null;
1334
+ recovery.collectorStarted ||= result.started;
1335
+ recovery.collectorLastCompletedOrdinal = Math.max(recovery.collectorLastCompletedOrdinal, result.lastCompletedOrdinal);
1336
+ recovery.collectorCaptureLineCount = Math.max(recovery.collectorCaptureLineCount, result.captureLineCount);
1337
+ recovery.collectorCaptureByteCount = Math.max(recovery.collectorCaptureByteCount, result.captureByteCount);
1338
+ recovery.collectorContinueObserved ||= result.continueObserved;
1339
+ recovery.collectorStatusObserved ||= result.statusObserved;
1340
+ recovery.collectorObserverEmissionObserved ||= result.observerEmissionObserved;
1341
+ recovery.collectorFailureReason = result.failureReason;
1342
+ observerEmitted = result.observerEmissionObserved && safeObserver;
1343
+ cleanupHook();
1344
+ if (settled)
1345
+ return;
1346
+ if (!result.ok || !participantsExact() || result.cursorLine === null) {
1347
+ fail(result.statusObserved);
1348
+ return;
1349
+ }
1350
+ const captureLines = Object.freeze([...result.captureLines]);
1351
+ for (const { sub, epoch } of participants)
1352
+ sub.feed.captureReply(epoch, captureLines);
1353
+ const fallbackSize = this.layoutSizeFor(pane.runtimeId);
1354
+ this.observeScrollOnClear(pane, result.cursorLine);
1355
+ const deliveries = participants.map(({ sub, epoch }) => ({
1356
+ sub,
1357
+ epoch,
1358
+ events: sub.feed.cursorReply(epoch, result.cursorLine, fallbackSize),
1359
+ }));
1360
+ if (!participantsExact() || deliveries.some(({ events }) => events.length === 0)) {
1361
+ fail(true);
1362
+ return;
1363
+ }
1364
+ let published = false;
1365
+ const publish = () => {
1366
+ if (published)
1367
+ return true;
1368
+ if (!participantsExact())
1369
+ return false;
1370
+ published = true;
1371
+ for (const { sub, events } of deliveries)
1372
+ for (const event of events)
1373
+ sub.onEvent(event);
1374
+ return participantsExact();
1375
+ };
1376
+ if (!deferPublish && !publish()) {
1377
+ fail(true);
1378
+ return;
1379
+ }
1380
+ for (const { sub, epoch } of deliveries)
1381
+ sub.feed.quarantine(epoch);
1382
+ settled = true;
1383
+ done({
1384
+ ok: true,
1385
+ fingerprint: snapshotFingerprint(captureLines, result.cursorLine, fallbackSize),
1386
+ publish,
1387
+ hold: () => { },
1388
+ });
1389
+ },
1390
+ }, remaining);
1391
+ if (!armed) {
1392
+ fail();
1393
+ return;
1394
+ }
1395
+ const rejected = `tmux-ide-atomic-invoke-rejected-v1:${nonce}`;
1396
+ this.io.commandListInline(`if-shell -t ${pane.runtimeId} -F "#{&&:${hookOwned},${hookUnchanged}}" ` +
1397
+ `${tmuxSingleQuote(`set-hook -Rp -t ${pane.runtimeId} ${hookName}`)} ` +
1398
+ tmuxSingleQuote(`display-message -p -t ${pane.runtimeId} ${rejected}`), 2, 1, (hookReply) => {
1399
+ if (!hookReply.ok || hookReply.lines.length > 0) {
1400
+ this.io.retireAtomicPaneSnapshotCollector?.(nonce, "retired");
1401
+ fail();
1402
+ }
1403
+ });
1404
+ };
1405
+ // Three owner-local create-only writes avoid a command-group partial-error
1406
+ // ambiguity: every accepted step has its own ordered reply and any later
1407
+ // failure can conditionally retire exactly the already-created prefix.
1408
+ this.io.commandInline(`set-option -po -t ${pane.runtimeId} ${ownerName} ${nonce}`, (ownerReply) => {
1409
+ if (!ownerReply.ok || !participantsExact()) {
1410
+ fail();
1411
+ return;
1412
+ }
1413
+ this.io.commandInline(`set-option -po -t ${pane.runtimeId} ${expectedName} ${tmuxSingleQuote(body)}`, (expectedReply) => {
1414
+ if (!expectedReply.ok || !participantsExact()) {
1415
+ fail();
1416
+ return;
1417
+ }
1418
+ this.io.commandInline(`set-option -po -t ${pane.runtimeId} ${hookName} ${tmuxSingleQuote(body)}`, invoke);
1419
+ });
1420
+ });
1421
+ }
1422
+ armRecoveryQuiet(recovery, callback) {
1423
+ recovery.cancelQuiet?.();
1424
+ recovery.cancelQuiet = this.scheduleRecovery(() => {
1425
+ recovery.cancelQuiet = null;
1426
+ if (this.recoveryPane(recovery))
1427
+ callback();
1428
+ }, RECOVERY_QUIET_MS);
1429
+ }
1430
+ beginFinalRecovery(recovery) {
1431
+ const pane = this.recoveryPane(recovery);
1432
+ if (!pane)
1433
+ return;
1434
+ if (recovery.attempts >= RECOVERY_MAX_ATTEMPTS) {
1435
+ this.failRecovery(recovery, "attempts-exhausted");
1436
+ return;
1437
+ }
1438
+ recovery.attempts += 1;
1439
+ recovery.stage = "final";
1440
+ this.noteRecoveryProgress(recovery);
1441
+ // The final read is only a private candidate. Publishing it here can put
1442
+ // expensive replica projection ahead of the confirmation timers and, more
1443
+ // importantly, exposes a snapshot that has not yet survived the two-read
1444
+ // authority proof.
1445
+ this.reseedRecoverySubscribers(pane, recovery, ({ ok, fingerprint }) => {
1446
+ const current = this.recoveryPane(recovery);
1447
+ if (!current)
1448
+ return;
1449
+ if (!ok || fingerprint === null) {
1450
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1451
+ return;
1452
+ }
1453
+ recovery.outputOrdinal = this.outputOrdinals.get(recovery.runtimeId) ?? 0;
1454
+ recovery.candidateFingerprint = fingerprint;
1455
+ recovery.confirmationFingerprint = null;
1456
+ recovery.confirmationOrdinal = 0;
1457
+ recovery.stage = "confirm";
1458
+ this.observeRecovery(current, recovery, "final-reseed");
1459
+ this.noteRecoveryProgress(recovery);
1460
+ this.armRecoveryQuiet(recovery, () => this.confirmRecovery(recovery));
1461
+ }, true);
1462
+ }
1463
+ confirmRecovery(recovery) {
1464
+ const pane = this.recoveryPane(recovery);
1465
+ if (!pane)
1466
+ return;
1467
+ if ((this.outputOrdinals.get(recovery.runtimeId) ?? 0) !== recovery.outputOrdinal) {
1468
+ this.beginFinalRecovery(recovery);
1469
+ return;
1470
+ }
1471
+ recovery.stage = "final";
1472
+ this.noteRecoveryProgress(recovery);
1473
+ this.reseedRecoverySubscribers(pane, recovery, ({ ok, fingerprint, publish }) => {
1474
+ const current = this.recoveryPane(recovery);
1475
+ if (!current)
1476
+ return;
1477
+ if (!ok || fingerprint === null) {
1478
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1479
+ return;
1480
+ }
1481
+ const outputOrdinal = this.outputOrdinals.get(recovery.runtimeId) ?? 0;
1482
+ const ordinalExact = outputOrdinal === recovery.outputOrdinal;
1483
+ const candidateExact = ordinalExact && fingerprint === recovery.candidateFingerprint;
1484
+ const consecutiveExact = candidateExact &&
1485
+ recovery.confirmationFingerprint !== null &&
1486
+ fingerprint === recovery.confirmationFingerprint;
1487
+ recovery.confirmationOrdinal += 1;
1488
+ this.observeRecovery(current, recovery, "confirmation-reseed", null, consecutiveExact);
1489
+ this.noteRecoveryProgress(recovery);
1490
+ if (!ordinalExact) {
1491
+ recovery.stage = "confirm";
1492
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1493
+ return;
1494
+ }
1495
+ if (!candidateExact) {
1496
+ if (recovery.attempts >= RECOVERY_MAX_ATTEMPTS) {
1497
+ this.failRecovery(recovery, "attempts-exhausted");
1498
+ return;
1499
+ }
1500
+ // A changed confirmation replaces the private candidate without
1501
+ // becoming observable. Two subsequent reads must confirm this truth.
1502
+ recovery.attempts += 1;
1503
+ recovery.candidateFingerprint = fingerprint;
1504
+ recovery.confirmationFingerprint = null;
1505
+ recovery.outputOrdinal = outputOrdinal;
1506
+ recovery.stage = "confirm";
1507
+ this.armRecoveryQuiet(recovery, () => this.confirmRecovery(recovery));
1508
+ return;
1509
+ }
1510
+ if (!consecutiveExact) {
1511
+ recovery.confirmationFingerprint = fingerprint;
1512
+ recovery.outputOrdinal = outputOrdinal;
1513
+ recovery.stage = "confirm";
1514
+ this.armRecoveryQuiet(recovery, () => this.confirmRecovery(recovery));
1515
+ return;
1516
+ }
1517
+ // This publisher belongs to the current second matching read, not the
1518
+ // older candidate. Publish exactly once while every participant is
1519
+ // still fenced, then synchronously retire recovery before downstream
1520
+ // projection work can run.
1521
+ if (!publish()) {
1522
+ recovery.stage = "confirm";
1523
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1524
+ return;
1525
+ }
1526
+ this.convergeRecovery(current, recovery);
1527
+ }, true);
1528
+ }
1529
+ convergeRecovery(pane, recovery) {
1530
+ recovery.cancelCommandDeadline?.();
1531
+ recovery.cancelCommandDeadline = null;
1532
+ recovery.cancelNoProgressDeadline?.();
1533
+ recovery.cancelNoProgressDeadline = null;
1534
+ recovery.cancelAbsoluteDeadline?.();
1535
+ recovery.cancelAbsoluteDeadline = null;
1536
+ this.recoveries.delete(recovery.runtimeId);
1537
+ recovery.retired = true;
1538
+ this.retireContinueNotificationOwner(recovery);
1539
+ this.ledger.noteContinued(recovery.runtimeId);
1540
+ if (recovery.reason === "requested")
1541
+ this.ledger.clearRequest(recovery.runtimeId);
1542
+ for (const sub of pane.subs) {
1543
+ if (!sub.frozen && !sub.closed) {
1544
+ sub.feed.releaseQuarantine();
1545
+ sub.onEvent({ type: "flow", state: "resumed", reason: recovery.reason });
1546
+ }
1547
+ }
1548
+ this.observeRecovery(pane, recovery, "converged", null, true);
1549
+ }
1550
+ noteRecoveryOutput(pane, outputOrdinal) {
1551
+ const recovery = this.recoveries.get(pane.runtimeId);
1552
+ if (!recovery || recovery.paneIncarnation !== pane.incarnation)
1553
+ return;
1554
+ recovery.outputOrdinal = outputOrdinal;
1555
+ if (recovery.continueReply)
1556
+ this.noteRecoveryProgress(recovery);
1557
+ if (recovery.stage === "quiet")
1558
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1559
+ else if (recovery.stage === "confirm")
1560
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1561
+ }
1562
+ restartRecoveryAfterOutputOverflow(pane) {
1563
+ const recovery = this.recoveries.get(pane.runtimeId);
1564
+ if (recovery?.paneIncarnation === pane.incarnation) {
1565
+ if (recovery.stage === "quiet" || recovery.stage === "confirm")
1566
+ this.armRecoveryQuiet(recovery, () => this.beginFinalRecovery(recovery));
1567
+ return;
1568
+ }
1569
+ this.beginLocalOverflowRecovery(pane);
1570
+ }
1571
+ failRecovery(recovery, failureReason) {
1572
+ const pane = this.recoveryPane(recovery);
1573
+ if (!pane)
1574
+ return;
1575
+ recovery.cancelQuiet?.();
1576
+ recovery.cancelQuiet = null;
1577
+ recovery.cancelCommandDeadline?.();
1578
+ recovery.cancelCommandDeadline = null;
1579
+ recovery.cancelNoProgressDeadline?.();
1580
+ recovery.cancelNoProgressDeadline = null;
1581
+ recovery.cancelAbsoluteDeadline?.();
1582
+ recovery.cancelAbsoluteDeadline = null;
1583
+ recovery.retired = true;
1584
+ const collectorNonce = recovery.atomicCollectorNonce;
1585
+ recovery.atomicCollectorNonce = null;
1586
+ if (collectorNonce)
1587
+ this.io.retireAtomicPaneSnapshotCollector?.(collectorNonce, "retired");
1588
+ this.recoveries.delete(recovery.runtimeId);
1589
+ this.retireContinueNotificationOwner(recovery);
1590
+ for (const sub of pane.subs)
1591
+ sub.feed.abortCurrent();
1592
+ this.observeRecovery(pane, recovery, "nonconverged", failureReason);
1593
+ for (const sub of pane.subs) {
1594
+ sub.cancelCapture?.();
1595
+ if (sub.closed || sub.frozen)
1596
+ continue;
1597
+ try {
1598
+ sub.onEvent({ type: "fault", reason: "native-recovery-failed" });
1599
+ }
1600
+ catch {
1601
+ // A consumer must not prevent sibling subscribers from retiring.
1602
+ }
1603
+ }
1604
+ }
1605
+ removeContinueNotificationOwner(recovery) {
1606
+ const queue = this.continueNotificationQueues.get(recovery.runtimeId);
1607
+ if (!queue)
1608
+ return;
1609
+ const index = queue.findIndex((entry) => entry.kind === "owner" && entry.recovery === recovery);
1610
+ if (index < 0)
1611
+ return;
1612
+ queue.splice(index, 1);
1613
+ this.compactContinueNotificationQueue(recovery.runtimeId, queue);
1614
+ }
1615
+ retireContinueNotificationOwner(recovery) {
1616
+ if (!recovery.continueReply)
1617
+ return;
1618
+ const queue = this.continueNotificationQueues.get(recovery.runtimeId);
1619
+ if (!queue)
1620
+ return;
1621
+ const index = queue.findIndex((entry) => entry.kind === "owner" && entry.recovery === recovery);
1622
+ if (index < 0)
1623
+ return;
1624
+ queue.splice(index, 1, { kind: "debt", count: 1, saturated: false });
1625
+ this.compactContinueNotificationQueue(recovery.runtimeId, queue);
1626
+ }
1627
+ compactContinueNotificationQueue(runtime, queue) {
1628
+ for (let index = 1; index < queue.length;) {
1629
+ const previous = queue[index - 1];
1630
+ const current = queue[index];
1631
+ if (previous?.kind !== "debt" || current?.kind !== "debt") {
1632
+ index += 1;
1633
+ continue;
1634
+ }
1635
+ const total = previous.count + current.count;
1636
+ previous.count = Math.min(total, MAX_CONTINUE_NOTIFICATION_DEBT);
1637
+ previous.saturated =
1638
+ previous.saturated || current.saturated || total > MAX_CONTINUE_NOTIFICATION_DEBT;
1639
+ queue.splice(index, 1);
1640
+ }
1641
+ if (queue.length === 0)
1642
+ this.continueNotificationQueues.delete(runtime);
1643
+ else
1644
+ this.continueNotificationQueues.set(runtime, queue);
1645
+ }
1646
+ /** Continue + reseed EVERY backpressure-paused pane that still has an
1647
+ * unfrozen subscriber. %pause is sticky and hits quiet panes after any
1648
+ * stall — recovering only the noisy pane leaves siblings dark. */
1649
+ recoverSticky() {
1650
+ for (const runtime of this.ledger.stickyRecoverySet()) {
1651
+ if (this.recoveries.has(runtime))
1652
+ continue;
1653
+ const pane = this.panesByRuntime.get(runtime);
1654
+ const live = pane ? [...pane.subs].filter((sub) => !sub.frozen && !sub.closed) : [];
1655
+ if (live.length === 0)
1656
+ continue; // nobody watching: staying paused is free
1657
+ this.beginRecovery(pane, "backpressure");
1658
+ }
1659
+ }
1660
+ closeSub(sub) {
1661
+ if (sub.closed)
1662
+ return;
1663
+ sub.closed = true;
1664
+ sub.cancelCapture?.();
1665
+ const pane = sub.pane;
1666
+ pane.subs.delete(sub);
1667
+ if ([...pane.subs].every((candidate) => candidate.closed || candidate.frozen))
1668
+ this.cancelRecovery(pane.runtimeId);
1669
+ // Ticket return on departure: a pane parked by a now-gone subscriber must
1670
+ // not stay paused forever.
1671
+ if (pane.subs.size === 0 && this.ledger.isRequested(pane.runtimeId)) {
1672
+ this.ledger.clearRequest(pane.runtimeId);
1673
+ this.continuePane(pane.runtimeId);
1674
+ }
1675
+ }
1676
+ // ── Notifications (channel order is the invariant) ──────────────────────
1677
+ observeScrollOnClear(pane, cursorLine) {
1678
+ const value = cursorLine.trim().split(/\s+/)[22];
1679
+ pane.scrollOnClear = value === "0" || value === "1" ? value === "1" : undefined;
1680
+ }
1681
+ onNotify(name, rest) {
1682
+ if (name === "subscription-changed") {
1683
+ const policy = /^tmux-ide-scroll-on-clear\s+\$[0-9]+\s+@[0-9]+\s+[0-9]+\s+(%[0-9]+)\s+:\s+([01])\s*$/u.exec(rest);
1684
+ if (policy) {
1685
+ const pane = this.panesByRuntime.get(policy[1]);
1686
+ const enabled = policy[2] === "1";
1687
+ if (pane && pane.scrollOnClear !== enabled) {
1688
+ pane.scrollOnClear = enabled;
1689
+ // A pending capture already reads policy in its ordered cursor
1690
+ // probe. Cancelling it here can repeatedly retire opening recipes
1691
+ // while tmux delivers the initial sampled option notification.
1692
+ // Live feeds instead replace content and policy together.
1693
+ if (!this.recoveries.has(pane.runtimeId))
1694
+ for (const sub of pane.subs)
1695
+ if (!sub.closed && !sub.frozen && sub.feed.currentState() === "live")
1696
+ this.reseedPlain(sub);
1697
+ }
1698
+ return;
1699
+ }
1700
+ const history = /^tmux-ide-pane-history\s+\$[0-9]+\s+@[0-9]+\s+[0-9]+\s+(%[0-9]+)\s+:\s+([0-9]+)\s*$/u.exec(rest);
1701
+ if (history) {
1702
+ const pane = this.panesByRuntime.get(history[1]);
1703
+ const size = Number(history[2]);
1704
+ if (pane && Number.isSafeInteger(size)) {
1705
+ const cleared = size === 0 && (pane.historySize ?? 0) > 0;
1706
+ pane.historySize = size;
1707
+ // A quiet native clear writes no PTY bytes. Reuse the ordered seed path.
1708
+ if (cleared && !this.recoveries.has(pane.runtimeId)) {
1709
+ for (const sub of pane.subs)
1710
+ if (!sub.closed && !sub.frozen)
1711
+ this.reseedPlain(sub);
1712
+ }
1713
+ }
1714
+ return;
1715
+ }
1716
+ }
1717
+ if (name === "subscription-changed" &&
1718
+ (/^tmux-ide-pane-borders\s+\$[0-9]+\s+@[0-9]+\s+[0-9]+\s+-\s*:\s*(top|bottom|off)\s*$/u.test(rest) ||
1719
+ /^tmux-ide-copy-keys\s+\$[0-9]+\s+@[0-9]+\s+[0-9]+\s+-\s*:\s*(emacs|vi)\s*$/u.test(rest))) {
1720
+ this.windowAuthorityOrdinal += 1;
1721
+ this.scheduleSync();
1722
+ return;
1723
+ }
1724
+ if (name === "layout-change" ||
1725
+ name === "window-pane-changed" ||
1726
+ name === "session-window-changed" ||
1727
+ STRUCTURAL_NOTIFICATIONS.has(name)) {
1728
+ this.windowAuthorityOrdinal += 1;
1729
+ }
1730
+ // Layout changes remain a second honest wake-up: a native resize can arrive
1731
+ // before the once-per-second subscription notification. The inventory
1732
+ // (not either notification) remains the proof.
1733
+ if (this.opts.onNativeClientActivity &&
1734
+ (NATIVE_CLIENT_NOTIFICATIONS.has(name) || name === "layout-change")) {
1735
+ this.probeNativeClientActivity();
1736
+ }
1737
+ if (name === "pause") {
1738
+ const runtime = rest.trim().split(/\s+/)[0] ?? "";
1739
+ if (!runtime.startsWith("%"))
1740
+ return;
1741
+ this.cancelRecovery(runtime);
1742
+ this.ledger.notePause(runtime);
1743
+ const pane = this.panesByRuntime.get(runtime);
1744
+ if (pane) {
1745
+ for (const sub of pane.subs) {
1746
+ if (!sub.frozen && !sub.closed) {
1747
+ sub.onEvent({ type: "flow", state: "paused", reason: "backpressure" });
1748
+ }
1749
+ }
1750
+ }
1751
+ this.recoverSticky();
1752
+ return;
1753
+ }
1754
+ if (name === "continue") {
1755
+ const runtime = rest.trim().split(/\s+/)[0] ?? "";
1756
+ if (runtime.startsWith("%")) {
1757
+ const queue = this.continueNotificationQueues.get(runtime);
1758
+ const entry = queue?.[0] ?? null;
1759
+ if (entry?.kind === "debt") {
1760
+ if (!entry.saturated) {
1761
+ entry.count -= 1;
1762
+ if (entry.count === 0)
1763
+ queue.shift();
1764
+ }
1765
+ this.compactContinueNotificationQueue(runtime, queue);
1766
+ }
1767
+ else if (entry?.kind === "owner") {
1768
+ queue.shift();
1769
+ this.compactContinueNotificationQueue(runtime, queue);
1770
+ const owner = entry.recovery;
1771
+ const pane = this.recoveryPane(owner);
1772
+ owner.continueNotify = true;
1773
+ if (pane) {
1774
+ this.observeRecovery(pane, owner, "continue-notify");
1775
+ }
1776
+ }
1777
+ }
1778
+ return;
1779
+ }
1780
+ if (name === "layout-change") {
1781
+ const change = parseLayoutChange(rest);
1782
+ if (!change)
1783
+ return;
1784
+ const parsed = parseLayout(change.visible);
1785
+ if (!parsed) {
1786
+ this.scheduleSync(); // never guess from a failed parse
1787
+ return;
1788
+ }
1789
+ const pendingLayout = {
1790
+ ...parsed,
1791
+ zoomed: change.zoomed,
1792
+ unzoomed: parseLayout(change.layout) ?? undefined,
1793
+ };
1794
+ // Resync on BOTH structural deltas: an unknown leaf (new pane) and a
1795
+ // known pane of this window missing from the leaves (a killed pane in a
1796
+ // surviving window emits only %layout-change — without this, its
1797
+ // subscribers never receive `closed`). Closure itself still comes only
1798
+ // from the truth reply; a probe failure never reads as absence.
1799
+ // Structural membership comes from the full tmux layout. Zoom only
1800
+ // changes visible geometry and must not look like sibling deletion.
1801
+ const membership = change.zoomed ? parseLayout(change.layout) : parsed;
1802
+ if (!membership) {
1803
+ this.scheduleSync();
1804
+ return;
1805
+ }
1806
+ const leafIds = new Set(membership.leaves.map((leaf) => leaf.id));
1807
+ const knownPaneVanished = [...this.panesByRuntime.values()].some((pane) => pane.windowRuntimeId === change.windowId && !leafIds.has(pane.runtimeId));
1808
+ if (membership.leaves.some((leaf) => !this.panesByRuntime.has(leaf.id)) ||
1809
+ knownPaneVanished) {
1810
+ this.scheduleSync();
1811
+ }
1812
+ // %layout-change omits pane-border-status. Pairing fresh geometry with
1813
+ // the old cached option can reject every native capture after a border
1814
+ // change (for example 41 layout rows versus 40 content rows).
1815
+ // Keep the last qualified window visible in authority snapshots. A
1816
+ // pending option query is not evidence that the window disappeared.
1817
+ const held = this.pendingLayoutOutput.get(change.windowId);
1818
+ if (held)
1819
+ held.layout = pendingLayout;
1820
+ else
1821
+ this.pendingLayoutOutput.set(change.windowId, {
1822
+ layout: pendingLayout,
1823
+ bytes: 0,
1824
+ overflowed: false,
1825
+ records: [],
1826
+ });
1827
+ this.io.commandInline(`display-message -p -t ${change.windowId} "#{pane-border-status}"`, (reply) => {
1828
+ if (this.disposed ||
1829
+ this.pendingLayoutOutput.get(change.windowId)?.layout !== pendingLayout)
1830
+ return;
1831
+ const border = reply.lines[0];
1832
+ const window = this.windowsByRuntime.get(change.windowId);
1833
+ if (!reply.ok ||
1834
+ !window ||
1835
+ (border !== "top" && border !== "bottom" && border !== "off")) {
1836
+ this.scheduleSync();
1837
+ return;
1838
+ }
1839
+ if (window.paneBorderStatus !== border) {
1840
+ // A query can observe an intermediate option between tmux's 1s
1841
+ // subscription samples. Reset its last-value cache so a return to
1842
+ // the previous value still produces a final authoritative refresh.
1843
+ this.io.send("refresh-client -B 'tmux-ide-pane-borders:@*:#{pane-border-status}'");
1844
+ }
1845
+ this.windowsByRuntime.set(change.windowId, { ...window, paneBorderStatus: border });
1846
+ this.layoutByWindow.set(change.windowId, pendingLayout);
1847
+ this.releasePendingLayout(change.windowId);
1848
+ this.emitLayoutAuthority();
1849
+ });
1850
+ return;
1851
+ }
1852
+ if (name === "window-pane-changed") {
1853
+ const change = parseWindowPaneChanged(rest);
1854
+ if (!change)
1855
+ return;
1856
+ this.activePaneByWindow.set(change.windowId, change.paneId);
1857
+ for (const pane of this.panesByRuntime.values()) {
1858
+ if (pane.windowRuntimeId === change.windowId)
1859
+ pane.active = pane.runtimeId === change.paneId;
1860
+ }
1861
+ this.emitLayout(change.windowId);
1862
+ this.emitLayoutAuthority();
1863
+ return;
1864
+ }
1865
+ if (name === "session-window-changed") {
1866
+ const change = parseSessionWindowChanged(rest);
1867
+ if (!change)
1868
+ return;
1869
+ const previous = this.currentWindow;
1870
+ this.currentWindow = change.windowId;
1871
+ if (previous === change.windowId)
1872
+ return;
1873
+ /*
1874
+ * Re-emit BOTH windows.
1875
+ *
1876
+ * `currentWindow` is carried on the layout frame, and this notification is
1877
+ * the only thing that changes it. Without a re-emit the flag stays as it
1878
+ * was until something else about a layout happens to move — so a view
1879
+ * whose window tabs come from these frames (m50) would keep marking the
1880
+ * window the user just left as the one they are in, indefinitely.
1881
+ */
1882
+ if (previous)
1883
+ this.emitLayout(previous);
1884
+ this.emitLayout(change.windowId);
1885
+ this.emitLayoutAuthority();
1886
+ return;
1887
+ }
1888
+ if (STRUCTURAL_NOTIFICATIONS.has(name))
1889
+ this.scheduleSync();
1890
+ }
1891
+ probeNativeClientActivity() {
1892
+ if (this.nativeClientProbePending || this.disposed)
1893
+ return;
1894
+ this.nativeClientProbePending = true;
1895
+ void this.io
1896
+ .request(`list-clients -t "${this.opts.session}" -F "#{client_control_mode}\t#{client_activity}"`)
1897
+ .then((lines) => {
1898
+ // The daemon's own mirror is a control-mode client. Only a tmux-owned
1899
+ // attached client (control mode = 0) is honest evidence for yielding
1900
+ // geometry; notification names alone can include our own lifecycle.
1901
+ if (lines.some((line) => /^0\t\d+$/u.test(line.trim()))) {
1902
+ this.opts.onNativeClientActivity?.();
1903
+ }
1904
+ })
1905
+ .catch(() => undefined)
1906
+ .finally(() => {
1907
+ this.nativeClientProbePending = false;
1908
+ });
1909
+ }
1910
+ releasePendingLayout(windowRuntimeId) {
1911
+ const pending = this.pendingLayoutOutput.get(windowRuntimeId);
1912
+ this.pendingLayoutOutput.delete(windowRuntimeId);
1913
+ this.emitLayout(windowRuntimeId);
1914
+ if (pending?.overflowed) {
1915
+ for (const pane of this.panesByRuntime.values()) {
1916
+ if (pane.windowRuntimeId === windowRuntimeId)
1917
+ this.restartRecoveryAfterOutputOverflow(pane);
1918
+ }
1919
+ }
1920
+ else {
1921
+ for (const record of pending?.records ?? [])
1922
+ this.onOutput(record.pane, record.data, record.ageMs, record.timing);
1923
+ }
1924
+ }
1925
+ emitLayout(windowRuntimeId) {
1926
+ const event = this.layoutEventFor(windowRuntimeId);
1927
+ if (!event)
1928
+ return;
1929
+ for (const subscriber of this.layoutSubscribers)
1930
+ subscriber(event);
1931
+ for (const pane of this.panesByRuntime.values()) {
1932
+ if (pane.windowRuntimeId !== windowRuntimeId)
1933
+ continue;
1934
+ for (const sub of pane.subs) {
1935
+ if (!sub.closed && sub.onLayout)
1936
+ sub.onLayout(this.layoutEventFor(windowRuntimeId, pane.runtimeId) ?? event);
1937
+ }
1938
+ }
1939
+ }
1940
+ emitLayoutAuthority() {
1941
+ const runtimeSessionId = this.attachedIdentity?.runtimeSessionId;
1942
+ if (!runtimeSessionId || this.layoutAuthoritySubscribers.size === 0)
1943
+ return;
1944
+ this.layoutTopologyEpoch += 1;
1945
+ for (const subscriber of this.layoutAuthoritySubscribers)
1946
+ this.emitLayoutAuthorityTo(subscriber, runtimeSessionId);
1947
+ }
1948
+ emitLayoutAuthorityTo(subscriber, runtimeSessionId) {
1949
+ const layouts = [...this.layoutByWindow.keys()]
1950
+ .map((runtimeId) => this.layoutEventFor(runtimeId))
1951
+ .filter((event) => event !== null);
1952
+ subscriber({
1953
+ session: this.opts.session,
1954
+ runtimeSessionId,
1955
+ topologyEpoch: this.layoutTopologyEpoch,
1956
+ layouts,
1957
+ });
1958
+ }
1959
+ /**
1960
+ * Hand ONE new subscriber the geometry of its owning window.
1961
+ *
1962
+ * Without it a subscriber's first layout frame arrives only when a layout
1963
+ * happens to change, so a view built from these frames opens empty and stays
1964
+ * empty until the user moves something — which reads as the app failing to
1965
+ * find the session's windows at all.
1966
+ */
1967
+ emitLayoutSnapshot(sub) {
1968
+ if (!sub.onLayout)
1969
+ return;
1970
+ const windowRuntimeId = sub.pane.windowRuntimeId;
1971
+ if (windowRuntimeId === null)
1972
+ return;
1973
+ const event = this.layoutEventFor(windowRuntimeId, sub.pane.runtimeId);
1974
+ if (!sub.closed && event)
1975
+ sub.onLayout(event);
1976
+ }
1977
+ layoutEventFor(windowRuntimeId, subscriberPane) {
1978
+ const visible = this.layoutByWindow.get(windowRuntimeId);
1979
+ if (!visible)
1980
+ return null;
1981
+ // Hidden terminal owners still need their real saved geometry to qualify
1982
+ // atomic seeds. Global layout subscribers receive only visible geometry.
1983
+ const layout = subscriberPane &&
1984
+ visible.zoomed &&
1985
+ visible.unzoomed &&
1986
+ !visible.leaves.some((leaf) => leaf.id === subscriberPane)
1987
+ ? { ...visible.unzoomed, zoomed: true }
1988
+ : visible;
1989
+ const windowRecord = this.windowsByRuntime.get(windowRuntimeId) ?? null;
1990
+ const activePane = this.activePaneByWindow.get(windowRuntimeId) ?? "";
1991
+ const event = {
1992
+ type: "layout",
1993
+ session: this.opts.session,
1994
+ semanticWindowId: windowRecord?.semanticId ?? null,
1995
+ windowName: windowRecord?.name ?? null,
1996
+ currentWindow: windowRuntimeId === this.currentWindow,
1997
+ cols: layout.width,
1998
+ rows: layout.height,
1999
+ zoomed: layout.zoomed,
2000
+ paneBorderStatus: windowRecord?.paneBorderStatus ?? "off",
2001
+ modeKeys: windowRecord?.modeKeys,
2002
+ panes: layout.leaves.map((leaf) => {
2003
+ const pane = this.panesByRuntime.get(leaf.id) ?? null;
2004
+ const display = pane
2005
+ ? resolvePaneDisplayName({
2006
+ hostName: TMUX_SERVER_HOSTNAME,
2007
+ semanticPaneId: pane.semanticId,
2008
+ configuredName: pane.descriptor?.name,
2009
+ configuredNameSource: pane.descriptor?.nameSource,
2010
+ currentCommand: pane.descriptor?.currentCommand,
2011
+ title: pane.descriptor?.title,
2012
+ paneType: pane.descriptor?.type,
2013
+ })
2014
+ : null;
2015
+ return {
2016
+ semanticPaneId: pane?.semanticId ?? null,
2017
+ displayName: display?.name ?? null,
2018
+ displayNameSource: display?.source ?? null,
2019
+ left: leaf.left,
2020
+ top: leaf.top,
2021
+ width: leaf.width,
2022
+ height: leaf.height,
2023
+ active: leaf.id === activePane,
2024
+ };
2025
+ }),
2026
+ };
2027
+ return event;
2028
+ }
2029
+ // ── Truth sync + identity join ───────────────────────────────────────────
2030
+ scheduleSync() {
2031
+ if (this.cancelSync || this.disposed)
2032
+ return;
2033
+ const schedule = this.opts.scheduleSync ??
2034
+ ((callback, delayMs) => {
2035
+ const timer = setTimeout(callback, delayMs);
2036
+ return () => clearTimeout(timer);
2037
+ });
2038
+ this.cancelSync = schedule(() => {
2039
+ this.cancelSync = null;
2040
+ void this.syncNow().catch(() => { });
2041
+ }, SYNC_DEBOUNCE_MS);
2042
+ }
2043
+ async syncNow() {
2044
+ if (this.disposed)
2045
+ return;
2046
+ const lines = await this.io.request(`list-panes -s -t "${this.opts.session}" -F "#{pane_id}\t#{pane_active}\t#{window_id}\t#{?window_active,1,0}"`);
2047
+ const truth = [];
2048
+ for (const line of lines) {
2049
+ const [runtime = "", active = "", windowId = "", windowActive = ""] = line.split("\t");
2050
+ if (!/^%[0-9]+$/u.test(runtime))
2051
+ continue;
2052
+ truth.push({
2053
+ runtimePaneId: runtime,
2054
+ active: active === "1",
2055
+ runtimeWindowId: windowId,
2056
+ windowActive: windowActive === "1",
2057
+ });
2058
+ }
2059
+ const { listed, movedWindowRuntimeIds } = this.applyPaneTruth(truth);
2060
+ await this.syncWindows(this.opts.session, movedWindowRuntimeIds);
2061
+ this.discovery.discover(listed);
2062
+ }
2063
+ applyPaneTruth(truth) {
2064
+ const listed = new Set();
2065
+ const movedWindowRuntimeIds = new Set();
2066
+ this.truthActive.clear();
2067
+ this.truthWindow.clear();
2068
+ this.activePaneByWindow.clear();
2069
+ for (const row of truth) {
2070
+ listed.add(row.runtimePaneId);
2071
+ this.truthActive.set(row.runtimePaneId, row.active);
2072
+ this.truthWindow.set(row.runtimePaneId, row.runtimeWindowId);
2073
+ if (row.active)
2074
+ this.activePaneByWindow.set(row.runtimeWindowId, row.runtimePaneId);
2075
+ if (row.windowActive)
2076
+ this.currentWindow = row.runtimeWindowId;
2077
+ }
2078
+ // Closure is decided ONLY by a successful truth reply that omits the pane
2079
+ // (probe failure never reads as absence — a thrown request skips all this).
2080
+ for (const [runtime, pane] of [...this.panesByRuntime]) {
2081
+ if (listed.has(runtime)) {
2082
+ pane.active = this.truthActive.get(runtime) ?? pane.active;
2083
+ const nextWindowRuntimeId = this.truthWindow.get(runtime) ?? pane.windowRuntimeId;
2084
+ if (nextWindowRuntimeId !== pane.windowRuntimeId && nextWindowRuntimeId !== null)
2085
+ movedWindowRuntimeIds.add(nextWindowRuntimeId);
2086
+ pane.windowRuntimeId = nextWindowRuntimeId;
2087
+ continue;
2088
+ }
2089
+ this.cancelRecovery(runtime);
2090
+ this.continueNotificationQueues.delete(runtime);
2091
+ this.panesByRuntime.delete(runtime);
2092
+ this.outputOrdinals.delete(runtime);
2093
+ this.panesBySemantic.delete(pane.semanticId);
2094
+ this.ledger.forget(runtime);
2095
+ this.ageByRuntime.delete(runtime);
2096
+ for (const sub of pane.subs) {
2097
+ if (!sub.closed) {
2098
+ sub.closed = true;
2099
+ sub.cancelCapture?.();
2100
+ sub.onEvent({ type: "closed" });
2101
+ }
2102
+ }
2103
+ pane.subs.clear();
2104
+ }
2105
+ return { listed, movedWindowRuntimeIds };
2106
+ }
2107
+ async refreshTrustedInventory(expectedRuntimeSessionId, attempt = 0) {
2108
+ const authorityOrdinal = this.windowAuthorityOrdinal;
2109
+ const beforeLines = await this.io.request(`list-panes -s -t "${expectedRuntimeSessionId}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`);
2110
+ if (this.disposed)
2111
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
2112
+ const parsed = parseSessionPaneDescriptorReply(beforeLines);
2113
+ if (parsed.malformedUtf8Records !== 0 ||
2114
+ parsed.descriptors.length === 0 ||
2115
+ parsed.descriptors.length !== beforeLines.length) {
2116
+ throw new Error(`trusted inventory for ${this.opts.session} is malformed`);
2117
+ }
2118
+ const descriptors = parsed.descriptors;
2119
+ const runtimePaneIds = new Set(descriptors.map((pane) => pane.runtimePaneId));
2120
+ const runtimeSessionIds = new Set(descriptors.map((pane) => pane.runtimeSessionId));
2121
+ const activeWindowIds = new Set(descriptors.filter((pane) => pane.windowActive).map((pane) => pane.windowId));
2122
+ const globallyActivePanes = descriptors.filter((pane) => pane.paneActive && pane.windowActive);
2123
+ if (runtimePaneIds.size !== descriptors.length ||
2124
+ runtimeSessionIds.size !== 1 ||
2125
+ runtimeSessionIds.values().next().value !== expectedRuntimeSessionId ||
2126
+ descriptors.some((pane) => pane.sessionName !== this.opts.session) ||
2127
+ descriptors.some((pane) => pane.windowId === null) ||
2128
+ activeWindowIds.size !== 1 ||
2129
+ globallyActivePanes.length !== 1) {
2130
+ throw new Error(`trusted inventory for ${this.opts.session} is inconsistent`);
2131
+ }
2132
+ const computedWindowCounts = new Map();
2133
+ for (const descriptor of descriptors) {
2134
+ const runtimeWindowId = descriptor.windowId;
2135
+ computedWindowCounts.set(runtimeWindowId, (computedWindowCounts.get(runtimeWindowId) ?? 0) + 1);
2136
+ }
2137
+ if (descriptors.some((pane) => pane.windowPaneCount !== computedWindowCounts.get(pane.windowId) ||
2138
+ pane.sessionWindowCount !== computedWindowCounts.size)) {
2139
+ throw new Error(`trusted inventory for ${this.opts.session} has incomplete counts`);
2140
+ }
2141
+ const windowStage = await this.stageWindows(expectedRuntimeSessionId);
2142
+ const repairedPanes = await this.repairTrustedPaneIdentity(descriptors, windowStage.layouts);
2143
+ const afterLines = await this.io.request(`list-panes -s -t "${expectedRuntimeSessionId}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`);
2144
+ const confirmedWindowStage = await this.stageWindows(expectedRuntimeSessionId);
2145
+ const coherent = beforeLines.length === afterLines.length &&
2146
+ beforeLines.every((line, index) => line === afterLines[index]);
2147
+ if (windowStage.repairedIdentity ||
2148
+ confirmedWindowStage.repairedIdentity ||
2149
+ repairedPanes ||
2150
+ !coherent ||
2151
+ !this.windowStagesEqual(windowStage, confirmedWindowStage) ||
2152
+ authorityOrdinal !== this.windowAuthorityOrdinal) {
2153
+ if (attempt >= 1)
2154
+ throw new Error(`trusted inventory for ${this.opts.session} did not settle`);
2155
+ return await this.refreshTrustedInventory(expectedRuntimeSessionId, attempt + 1);
2156
+ }
2157
+ if (this.disposed)
2158
+ throw new Error(`mirror session ${this.opts.session} is disposed`);
2159
+ const activeWindowId = activeWindowIds.values().next().value;
2160
+ const descriptorWindowByPane = new Map(descriptors.map((descriptor) => [descriptor.runtimePaneId, descriptor.windowId]));
2161
+ const stagedPaneIds = new Set();
2162
+ let stagedPaneCount = 0;
2163
+ let stagedPaneMembershipExact = true;
2164
+ for (const [runtimeWindowId, layout] of confirmedWindowStage.layouts) {
2165
+ const membership = layout.zoomed ? layout.unzoomed : layout;
2166
+ if (!membership || membership.leaves.length !== computedWindowCounts.get(runtimeWindowId)) {
2167
+ stagedPaneMembershipExact = false;
2168
+ break;
2169
+ }
2170
+ for (const leaf of membership.leaves) {
2171
+ stagedPaneCount += 1;
2172
+ if (stagedPaneIds.has(leaf.id) || descriptorWindowByPane.get(leaf.id) !== runtimeWindowId) {
2173
+ stagedPaneMembershipExact = false;
2174
+ break;
2175
+ }
2176
+ stagedPaneIds.add(leaf.id);
2177
+ }
2178
+ if (!stagedPaneMembershipExact)
2179
+ break;
2180
+ }
2181
+ if (confirmedWindowStage.currentWindow !== activeWindowId ||
2182
+ confirmedWindowStage.windows.size !== computedWindowCounts.size ||
2183
+ !stagedPaneMembershipExact ||
2184
+ stagedPaneCount !== descriptors.length ||
2185
+ stagedPaneIds.size !== descriptors.length ||
2186
+ [...computedWindowCounts.keys()].some((runtimeWindowId) => !confirmedWindowStage.windows.has(runtimeWindowId)) ||
2187
+ descriptors.some((descriptor) => {
2188
+ const pane = this.panesByRuntime.get(descriptor.runtimePaneId);
2189
+ const window = confirmedWindowStage.windows.get(descriptor.windowId);
2190
+ return (!pane ||
2191
+ !window?.semanticId ||
2192
+ descriptor.semanticPaneId !== pane.semanticId ||
2193
+ descriptor.semanticWindowId !== window.semanticId ||
2194
+ !WorkspaceIdSchemaZ.safeParse(pane.semanticId).success ||
2195
+ !WorkspaceIdSchemaZ.safeParse(window.semanticId).success);
2196
+ })) {
2197
+ throw new Error(`trusted inventory for ${this.opts.session} lacks verified identity`);
2198
+ }
2199
+ const previousCurrentWindow = this.currentWindow;
2200
+ const { movedWindowRuntimeIds } = this.applyPaneTruth(descriptors.map((pane) => ({
2201
+ runtimePaneId: pane.runtimePaneId,
2202
+ active: pane.paneActive,
2203
+ runtimeWindowId: pane.windowId,
2204
+ windowActive: pane.windowActive,
2205
+ })));
2206
+ for (const descriptor of descriptors) {
2207
+ const pane = this.panesByRuntime.get(descriptor.runtimePaneId);
2208
+ pane.descriptor = descriptor;
2209
+ pane.active = descriptor.paneActive;
2210
+ }
2211
+ this.commitWindowStage(confirmedWindowStage, movedWindowRuntimeIds, previousCurrentWindow);
2212
+ if (this.degraded ||
2213
+ this.panesByRuntime.size !== descriptors.length ||
2214
+ this.windowsByRuntime.size !== computedWindowCounts.size ||
2215
+ [...computedWindowCounts.keys()].some((runtimeWindowId) => !this.windowsByRuntime.has(runtimeWindowId))) {
2216
+ throw new Error(`trusted inventory for ${this.opts.session} is degraded`);
2217
+ }
2218
+ const windowCounts = computedWindowCounts;
2219
+ const sessionWindowCount = computedWindowCounts.size;
2220
+ const panes = descriptors.map((descriptor) => {
2221
+ const record = this.panesByRuntime.get(descriptor.runtimePaneId);
2222
+ const runtimeWindowId = descriptor.windowId;
2223
+ const window = this.windowsByRuntime.get(runtimeWindowId);
2224
+ if (!record ||
2225
+ record.windowRuntimeId !== descriptor.windowId ||
2226
+ !window?.semanticId ||
2227
+ descriptor.semanticPaneId !== record.semanticId ||
2228
+ descriptor.semanticWindowId !== window.semanticId ||
2229
+ !WorkspaceIdSchemaZ.safeParse(record.semanticId).success ||
2230
+ !WorkspaceIdSchemaZ.safeParse(window.semanticId).success) {
2231
+ throw new Error(`trusted inventory for ${this.opts.session} lacks verified identity`);
2232
+ }
2233
+ return Object.freeze({
2234
+ runtimeSessionId: descriptor.runtimeSessionId,
2235
+ runtimeWindowId,
2236
+ runtimePaneId: descriptor.runtimePaneId,
2237
+ semanticWindowId: window.semanticId,
2238
+ semanticPaneId: record.semanticId,
2239
+ windowPaneCount: windowCounts.get(runtimeWindowId),
2240
+ sessionWindowCount,
2241
+ paneIndex: descriptor.paneIndex,
2242
+ title: descriptor.title ?? "",
2243
+ currentCommand: descriptor.currentCommand ?? "",
2244
+ active: descriptor.paneActive && descriptor.windowActive,
2245
+ role: descriptor.role,
2246
+ name: descriptor.name,
2247
+ type: descriptor.type,
2248
+ missionStamp: descriptor.missionStamp,
2249
+ dir: descriptor.cwd ?? "",
2250
+ });
2251
+ });
2252
+ return Object.freeze({
2253
+ sessionName: this.opts.session,
2254
+ runtimeSessionId: descriptors[0].runtimeSessionId,
2255
+ panes: Object.freeze(panes),
2256
+ });
2257
+ }
2258
+ async syncWindows(target = this.opts.session, requiredLayoutEmits = new Set()) {
2259
+ const stage = await this.stageWindows(target);
2260
+ this.commitWindowStage(stage, requiredLayoutEmits);
2261
+ return stage.repairedIdentity;
2262
+ }
2263
+ commitWindowStage(stage, requiredLayoutEmits = new Set(), previousCurrentWindow = this.currentWindow) {
2264
+ const changedWindows = new Set();
2265
+ for (const [runtimeId, record] of stage.windows) {
2266
+ const previous = this.windowsByRuntime.get(runtimeId);
2267
+ const previousLayout = this.layoutByWindow.get(runtimeId);
2268
+ const nextLayout = stage.layouts.get(runtimeId);
2269
+ if (!previous ||
2270
+ previous.name !== record.name ||
2271
+ previous.semanticId !== record.semanticId ||
2272
+ previous.paneBorderStatus !== record.paneBorderStatus ||
2273
+ previous.modeKeys !== record.modeKeys ||
2274
+ !previousLayout ||
2275
+ previousLayout.zoomed !== nextLayout.zoomed ||
2276
+ JSON.stringify(previousLayout.unzoomed) !== JSON.stringify(nextLayout.unzoomed) ||
2277
+ previousLayout.width !== nextLayout.width ||
2278
+ previousLayout.height !== nextLayout.height ||
2279
+ previousLayout.leaves.length !== nextLayout.leaves.length ||
2280
+ previousLayout.leaves.some((leaf, index) => {
2281
+ const candidate = nextLayout.leaves[index];
2282
+ return (!candidate ||
2283
+ leaf.id !== candidate.id ||
2284
+ leaf.left !== candidate.left ||
2285
+ leaf.top !== candidate.top ||
2286
+ leaf.width !== candidate.width ||
2287
+ leaf.height !== candidate.height);
2288
+ })) {
2289
+ changedWindows.add(runtimeId);
2290
+ }
2291
+ }
2292
+ const windowSetChanged = stage.windows.size !== this.windowsByRuntime.size;
2293
+ if (previousCurrentWindow !== stage.currentWindow) {
2294
+ if (stage.windows.has(previousCurrentWindow))
2295
+ changedWindows.add(previousCurrentWindow);
2296
+ if (stage.windows.has(stage.currentWindow))
2297
+ changedWindows.add(stage.currentWindow);
2298
+ }
2299
+ this.currentWindow = stage.currentWindow;
2300
+ this.windowsByRuntime.clear();
2301
+ for (const [key, value] of stage.windows)
2302
+ this.windowsByRuntime.set(key, value);
2303
+ this.layoutByWindow.clear();
2304
+ for (const [key, value] of stage.layouts)
2305
+ this.layoutByWindow.set(key, value);
2306
+ const layoutEmits = windowSetChanged
2307
+ ? new Set(stage.windows.keys())
2308
+ : new Set([...changedWindows, ...requiredLayoutEmits, ...this.pendingLayoutOutput.keys()].filter((runtimeId) => stage.windows.has(runtimeId)));
2309
+ for (const runtimeId of this.pendingLayoutOutput.keys())
2310
+ if (!stage.windows.has(runtimeId))
2311
+ this.pendingLayoutOutput.delete(runtimeId);
2312
+ for (const runtimeId of layoutEmits)
2313
+ this.releasePendingLayout(runtimeId);
2314
+ this.emitLayoutAuthority();
2315
+ }
2316
+ windowStagesEqual(left, right) {
2317
+ if (left.currentWindow !== right.currentWindow ||
2318
+ left.windows.size !== right.windows.size ||
2319
+ left.layouts.size !== right.layouts.size) {
2320
+ return false;
2321
+ }
2322
+ for (const [runtimeId, leftWindow] of left.windows) {
2323
+ const rightWindow = right.windows.get(runtimeId);
2324
+ const leftLayout = left.layouts.get(runtimeId);
2325
+ const rightLayout = right.layouts.get(runtimeId);
2326
+ if (!rightWindow ||
2327
+ !leftLayout ||
2328
+ !rightLayout ||
2329
+ leftWindow.semanticId !== rightWindow.semanticId ||
2330
+ leftWindow.name !== rightWindow.name ||
2331
+ leftWindow.paneBorderStatus !== rightWindow.paneBorderStatus ||
2332
+ leftWindow.modeKeys !== rightWindow.modeKeys ||
2333
+ leftLayout.zoomed !== rightLayout.zoomed ||
2334
+ JSON.stringify(leftLayout.unzoomed) !== JSON.stringify(rightLayout.unzoomed) ||
2335
+ leftLayout.width !== rightLayout.width ||
2336
+ leftLayout.height !== rightLayout.height ||
2337
+ leftLayout.leaves.length !== rightLayout.leaves.length ||
2338
+ leftLayout.leaves.some((leaf, index) => {
2339
+ const candidate = rightLayout.leaves[index];
2340
+ return (!candidate ||
2341
+ leaf.id !== candidate.id ||
2342
+ leaf.left !== candidate.left ||
2343
+ leaf.top !== candidate.top ||
2344
+ leaf.width !== candidate.width ||
2345
+ leaf.height !== candidate.height);
2346
+ })) {
2347
+ return false;
2348
+ }
2349
+ }
2350
+ return true;
2351
+ }
2352
+ async stageWindows(target = this.opts.session) {
2353
+ const lines = await this.io.request(`list-windows -t "${target}" -F "#{window_id}\t#{qa:@tmux_ide_window_id}\t#{qa:window_name}\t#{window_active}\t#{window_visible_layout}\t#{?window_zoomed_flag,1,0}\t#{pane-border-status}\t#{window_layout}\t#{mode-keys}"`);
2354
+ const rows = [];
2355
+ const seenRuntimeIds = new Set();
2356
+ for (const raw of lines) {
2357
+ // Replies are latin1 byte strings; recover UTF-8 window names first.
2358
+ const line = Buffer.from(raw, "latin1").toString("utf8");
2359
+ const parts = line.split("\t");
2360
+ if (parts.length !== 7 && parts.length !== 8 && parts.length !== 9) {
2361
+ throw new Error(`window layout truth for ${this.opts.session} is malformed`);
2362
+ }
2363
+ const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatus = "off", full = visible, modeKeys,] = parts;
2364
+ if (!/^@[0-9]+$/u.test(runtimeId) ||
2365
+ seenRuntimeIds.has(runtimeId) ||
2366
+ (active !== "0" && active !== "1") ||
2367
+ (zoomed !== "0" && zoomed !== "1") ||
2368
+ (borderStatus !== "top" && borderStatus !== "bottom" && borderStatus !== "off") ||
2369
+ (modeKeys !== undefined && modeKeys !== "emacs" && modeKeys !== "vi")) {
2370
+ throw new Error(`window layout truth for ${this.opts.session} is malformed`);
2371
+ }
2372
+ seenRuntimeIds.add(runtimeId);
2373
+ const stamp = decodeTmuxArgument(stampRaw);
2374
+ const name = decodeTmuxArgument(nameRaw);
2375
+ rows.push({
2376
+ runtimeId,
2377
+ stamp: stamp.length > 0 ? stamp : null,
2378
+ name: name.length > 0 ? name : null,
2379
+ active: active === "1",
2380
+ visible,
2381
+ full,
2382
+ zoomed: zoomed === "1",
2383
+ paneBorderStatus: borderStatus,
2384
+ modeKeys,
2385
+ });
2386
+ }
2387
+ if (rows.length === 0) {
2388
+ throw new Error(`window layout truth for ${this.opts.session} is missing`);
2389
+ }
2390
+ const activeRows = rows.filter(({ active }) => active);
2391
+ if (activeRows.length !== 1) {
2392
+ throw new Error(`window layout truth for ${this.opts.session} has inconsistent active window`);
2393
+ }
2394
+ const nextLayoutByWindow = new Map();
2395
+ for (const row of rows) {
2396
+ const parsed = parseLayout(row.visible);
2397
+ if (!parsed) {
2398
+ throw new Error(`window layout truth for ${this.opts.session} is malformed`);
2399
+ }
2400
+ const unzoomed = parseLayout(row.full);
2401
+ if (!unzoomed)
2402
+ throw new Error(`full window layout for ${this.opts.session} is malformed`);
2403
+ nextLayoutByWindow.set(row.runtimeId, { ...parsed, zoomed: row.zoomed, unzoomed });
2404
+ }
2405
+ // Valid unique stamps are identity; missing/invalid/duplicated stamps are
2406
+ // ALL regenerated and stamped back (the pane policy, applied to windows).
2407
+ const stampCounts = new Map();
2408
+ for (const row of rows) {
2409
+ if (row.stamp && WorkspaceIdSchemaZ.safeParse(row.stamp).success) {
2410
+ stampCounts.set(row.stamp, (stampCounts.get(row.stamp) ?? 0) + 1);
2411
+ }
2412
+ }
2413
+ const claimed = new Set(stampCounts.keys());
2414
+ const generateWindowId = this.opts.generateWindowId ?? defaultMirrorWindowId;
2415
+ let repairedIdentity = false;
2416
+ const next = new Map();
2417
+ let nextCurrentWindow = "";
2418
+ for (const row of rows) {
2419
+ if (row.active)
2420
+ nextCurrentWindow = row.runtimeId;
2421
+ let semanticId = null;
2422
+ if (row.stamp && stampCounts.get(row.stamp) === 1) {
2423
+ semanticId = row.stamp;
2424
+ }
2425
+ else {
2426
+ repairedIdentity = true;
2427
+ let candidate = null;
2428
+ for (let attempt = 0; attempt < 32 && !candidate; attempt += 1) {
2429
+ const generated = generateWindowId();
2430
+ if (WorkspaceIdSchemaZ.safeParse(generated).success && !claimed.has(generated)) {
2431
+ candidate = generated;
2432
+ }
2433
+ }
2434
+ if (candidate) {
2435
+ claimed.add(candidate);
2436
+ const ok = await this.io
2437
+ .request(`set-option -w -t ${row.runtimeId} ${WORKSPACE_SEMANTIC_WINDOW_OPTION} "${candidate}"`)
2438
+ .then(() => true, () => false);
2439
+ if (ok)
2440
+ semanticId = candidate;
2441
+ else {
2442
+ this.pushDiagnostic({
2443
+ code: "WINDOW_STAMP_BACK_FAILED",
2444
+ message: `Could not stamp semantic window identity ${candidate}.`,
2445
+ degraded: true,
2446
+ });
2447
+ }
2448
+ }
2449
+ }
2450
+ next.set(row.runtimeId, {
2451
+ runtimeId: row.runtimeId,
2452
+ semanticId,
2453
+ name: row.name,
2454
+ paneBorderStatus: row.paneBorderStatus,
2455
+ modeKeys: row.modeKeys,
2456
+ });
2457
+ }
2458
+ return {
2459
+ windows: next,
2460
+ layouts: nextLayoutByWindow,
2461
+ currentWindow: nextCurrentWindow,
2462
+ repairedIdentity,
2463
+ };
2464
+ }
2465
+ async reconcileIdentity(descriptors, listed) {
2466
+ if (this.disposed)
2467
+ return false;
2468
+ const snapshots = descriptors
2469
+ .filter((descriptor) => listed.has(descriptor.runtimePaneId))
2470
+ .map((descriptor) => ({
2471
+ runtimePaneId: descriptor.runtimePaneId,
2472
+ semanticPaneId: descriptor.semanticPaneId,
2473
+ role: descriptor.role,
2474
+ type: descriptor.type,
2475
+ currentCommand: descriptor.currentCommand,
2476
+ cwd: descriptor.cwd,
2477
+ title: descriptor.title,
2478
+ rect: this.rectFor(descriptor.runtimePaneId),
2479
+ active: this.truthActive.get(descriptor.runtimePaneId) ?? false,
2480
+ }));
2481
+ const plan = planWorkspaceTmuxReconciliation({
2482
+ panes: snapshots,
2483
+ generateSemanticPaneId: this.opts.generatePaneId ?? defaultMirrorPaneId,
2484
+ });
2485
+ const outcomes = await Promise.all(plan.stampEffects.map((effect) => this.io
2486
+ .request(`set-option -p -t ${effect.runtimePaneId} ${WORKSPACE_SEMANTIC_PANE_OPTION} "${effect.value}"`)
2487
+ .then(() => ({ runtimePaneId: effect.runtimePaneId, ok: true }), (cause) => ({
2488
+ runtimePaneId: effect.runtimePaneId,
2489
+ ok: false,
2490
+ error: cause instanceof Error ? cause.message : String(cause),
2491
+ }))));
2492
+ if (this.disposed)
2493
+ return plan.stampEffects.length > 0;
2494
+ const reconciliation = finalizeWorkspaceTmuxReconciliation(plan, outcomes);
2495
+ const descriptorByRuntime = new Map(descriptors.map((d) => [d.runtimePaneId, d]));
2496
+ for (const verified of reconciliation.panes) {
2497
+ if (!listed.has(verified.runtimePaneId))
2498
+ continue;
2499
+ const descriptor = descriptorByRuntime.get(verified.runtimePaneId) ?? null;
2500
+ const windowRuntimeId = this.truthWindow.get(verified.runtimePaneId) ?? descriptor?.windowId ?? null;
2501
+ const existingBySemantic = this.panesBySemantic.get(verified.semanticPaneId);
2502
+ const existingByRuntime = this.panesByRuntime.get(verified.runtimePaneId);
2503
+ if (existingBySemantic && existingBySemantic.runtimeId !== verified.runtimePaneId) {
2504
+ // The semantic identity moved to a different runtime address (respawn/
2505
+ // restore). Follow it and reseed every live subscriber — the old
2506
+ // address's bytes are a different pane's now.
2507
+ const retiredRuntime = existingBySemantic.runtimeId;
2508
+ this.cancelRecovery(retiredRuntime);
2509
+ this.continueNotificationQueues.delete(retiredRuntime);
2510
+ this.panesByRuntime.delete(retiredRuntime);
2511
+ this.outputOrdinals.delete(retiredRuntime);
2512
+ this.ledger.forget(retiredRuntime);
2513
+ existingBySemantic.runtimeId = verified.runtimePaneId;
2514
+ existingBySemantic.incarnation = ++this.paneIncarnation;
2515
+ existingBySemantic.descriptor = descriptor;
2516
+ existingBySemantic.active = verified.active;
2517
+ existingBySemantic.windowRuntimeId = windowRuntimeId;
2518
+ this.panesByRuntime.set(verified.runtimePaneId, existingBySemantic);
2519
+ for (const sub of existingBySemantic.subs) {
2520
+ if (!sub.closed && !sub.frozen)
2521
+ this.reseedPlain(sub);
2522
+ }
2523
+ continue;
2524
+ }
2525
+ if (existingByRuntime && existingByRuntime.semanticId === verified.semanticPaneId) {
2526
+ existingByRuntime.descriptor = descriptor;
2527
+ existingByRuntime.active = verified.active;
2528
+ existingByRuntime.windowRuntimeId = windowRuntimeId;
2529
+ continue;
2530
+ }
2531
+ if (existingByRuntime) {
2532
+ // The runtime address was restamped to a new identity (duplicate
2533
+ // resolution). The old semantic id is gone.
2534
+ this.panesBySemantic.delete(existingByRuntime.semanticId);
2535
+ this.cancelRecovery(existingByRuntime.runtimeId);
2536
+ this.continueNotificationQueues.delete(existingByRuntime.runtimeId);
2537
+ this.ledger.forget(existingByRuntime.runtimeId);
2538
+ this.outputOrdinals.delete(existingByRuntime.runtimeId);
2539
+ for (const sub of existingByRuntime.subs) {
2540
+ if (sub.closed)
2541
+ continue;
2542
+ sub.closed = true;
2543
+ sub.cancelCapture?.();
2544
+ sub.feed.abortCurrent();
2545
+ sub.onEvent({ type: "closed" });
2546
+ }
2547
+ existingByRuntime.subs.clear();
2548
+ existingByRuntime.incarnation = ++this.paneIncarnation;
2549
+ existingByRuntime.semanticId = verified.semanticPaneId;
2550
+ existingByRuntime.descriptor = descriptor;
2551
+ existingByRuntime.active = verified.active;
2552
+ existingByRuntime.windowRuntimeId = windowRuntimeId;
2553
+ this.panesBySemantic.set(verified.semanticPaneId, existingByRuntime);
2554
+ continue;
2555
+ }
2556
+ const record = {
2557
+ runtimeId: verified.runtimePaneId,
2558
+ semanticId: verified.semanticPaneId,
2559
+ descriptor,
2560
+ active: verified.active,
2561
+ windowRuntimeId,
2562
+ subs: new Set(),
2563
+ incarnation: ++this.paneIncarnation,
2564
+ };
2565
+ this.panesByRuntime.set(record.runtimeId, record);
2566
+ this.panesBySemantic.set(record.semanticId, record);
2567
+ }
2568
+ // Diagnostics cross the semantic boundary too: rewrite runtime addresses
2569
+ // to the joined semantic id (or an honest placeholder for panes that never
2570
+ // verified) so `%N` never leaves the service.
2571
+ const semanticByRuntime = new Map(reconciliation.panes.map((pane) => [pane.runtimePaneId, pane.semanticPaneId]));
2572
+ this.diagnostics = reconciliation.diagnostics.map((diagnostic) => ({
2573
+ code: diagnostic.code,
2574
+ message: diagnostic.message.replace(/%[0-9]+/gu, (runtime) => semanticByRuntime.get(runtime) ?? "(unidentified pane)"),
2575
+ degraded: diagnostic.degraded,
2576
+ }));
2577
+ this.degraded = reconciliation.degraded;
2578
+ /*
2579
+ * Re-emit every window's layout now that panes carry semantic identity.
2580
+ *
2581
+ * A pane created by a split appears in the %layout-change frame BEFORE its
2582
+ * `@tmux_ide_pane_id` stamp exists, so the frame names it null — and a
2583
+ * consumer that renders semantic identities has nothing to draw for it. The
2584
+ * stamp-back lands here, in a sync, which emits no layout of its own; so
2585
+ * without this the new pane stays invisible until something else happens to
2586
+ * move a layout, and a split looks like it did not reach the view.
2587
+ */
2588
+ for (const runtimeId of this.layoutByWindow.keys())
2589
+ this.emitLayout(runtimeId);
2590
+ this.emitLayoutAuthority();
2591
+ this.settleFirstJoin();
2592
+ return plan.stampEffects.length > 0;
2593
+ }
2594
+ async repairTrustedPaneIdentity(descriptors, layouts) {
2595
+ const rectForRuntime = (runtimePaneId) => {
2596
+ for (const layout of layouts.values()) {
2597
+ const leaf = layout.leaves.find(({ id }) => id === runtimePaneId);
2598
+ if (leaf) {
2599
+ return {
2600
+ left: leaf.left,
2601
+ top: leaf.top,
2602
+ width: leaf.width,
2603
+ height: leaf.height,
2604
+ };
2605
+ }
2606
+ }
2607
+ return { left: 0, top: 0, width: 1, height: 1 };
2608
+ };
2609
+ const plan = planWorkspaceTmuxReconciliation({
2610
+ panes: descriptors.map((descriptor) => ({
2611
+ runtimePaneId: descriptor.runtimePaneId,
2612
+ semanticPaneId: descriptor.semanticPaneId,
2613
+ role: descriptor.role,
2614
+ type: descriptor.type,
2615
+ currentCommand: descriptor.currentCommand,
2616
+ cwd: descriptor.cwd,
2617
+ title: descriptor.title,
2618
+ rect: rectForRuntime(descriptor.runtimePaneId),
2619
+ active: descriptor.paneActive && descriptor.windowActive,
2620
+ })),
2621
+ generateSemanticPaneId: this.opts.generatePaneId ?? defaultMirrorPaneId,
2622
+ });
2623
+ if (plan.stampEffects.length === 0)
2624
+ return false;
2625
+ const outcomes = await Promise.all(plan.stampEffects.map((effect) => this.io
2626
+ .request(`set-option -p -t ${effect.runtimePaneId} ${WORKSPACE_SEMANTIC_PANE_OPTION} "${effect.value}"`)
2627
+ .then(() => true, () => false)));
2628
+ if (outcomes.some((ok) => !ok)) {
2629
+ throw new Error(`trusted inventory for ${this.opts.session} could not repair identity`);
2630
+ }
2631
+ return true;
2632
+ }
2633
+ settleFirstJoin() {
2634
+ this.resolveFirstJoin?.();
2635
+ this.resolveFirstJoin = null;
2636
+ }
2637
+ rectFor(runtime) {
2638
+ for (const layout of this.layoutByWindow.values()) {
2639
+ const leaf = layout.leaves.find((candidate) => candidate.id === runtime);
2640
+ if (leaf)
2641
+ return { left: leaf.left, top: leaf.top, width: leaf.width, height: leaf.height };
2642
+ }
2643
+ return { left: 0, top: 0, width: 1, height: 1 };
2644
+ }
2645
+ pushDiagnostic(diagnostic) {
2646
+ this.diagnostics = [...this.diagnostics.slice(-31), diagnostic];
2647
+ if (diagnostic.degraded)
2648
+ this.degraded = true;
2649
+ }
2650
+ onChannelExit() {
2651
+ if (this.disposed)
2652
+ return;
2653
+ this.nativeGrid.dispose();
2654
+ this.settleFirstJoin();
2655
+ for (const runtime of [...this.recoveries.keys()])
2656
+ this.cancelRecovery(runtime);
2657
+ this.continueNotificationQueues.clear();
2658
+ for (const pane of this.panesByRuntime.values()) {
2659
+ for (const sub of pane.subs) {
2660
+ if (!sub.closed) {
2661
+ sub.closed = true;
2662
+ sub.cancelCapture?.();
2663
+ sub.onEvent({ type: "closed" });
2664
+ }
2665
+ }
2666
+ pane.subs.clear();
2667
+ }
2668
+ this.opts.onExit?.();
2669
+ }
2670
+ }