@kabmo-labs/kabmo 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +805 -736
  3. package/dist/client/static/js/index-bc9aa4mx.css +1 -0
  4. package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/Modal.tsx +2 -6
  13. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  14. package/src/client/components/common/code-surface/shiki.ts +28 -7
  15. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
  16. package/src/client/components/common/session-actions-menu/index.tsx +33 -2
  17. package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
  18. package/src/client/components/common/session-row/index.tsx +27 -1
  19. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
  20. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  21. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
  22. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
  23. package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
  26. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  28. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
  29. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
  31. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
  33. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
  34. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
  35. package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
  36. package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
  37. package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
  38. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  39. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  40. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
  41. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  42. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
  43. package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
  44. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  45. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
  46. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  47. package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
  48. package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
  49. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
  50. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
  51. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
  52. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
  53. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
  54. package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
  55. package/src/client/components/workspace/file-explorer/index.tsx +9 -3
  56. package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
  57. package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
  58. package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
  59. package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
  60. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  61. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  62. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  63. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  64. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  65. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  66. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  67. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  68. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  69. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  70. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  71. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  72. package/src/client/data/settings/omp-schema.json +5 -5
  73. package/src/client/data/theme/terminal.test.ts +25 -0
  74. package/src/client/data/theme/terminal.ts +96 -79
  75. package/src/client/hooks/chat/composer/items.test.ts +12 -26
  76. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  77. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  78. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  79. package/src/client/hooks/chat/timeline/actions.ts +2 -2
  80. package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
  81. package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
  82. package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
  83. package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
  84. package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
  85. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  86. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  87. package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
  88. package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
  89. package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
  90. package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
  91. package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
  92. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  93. package/src/client/hooks/chat/timeline/send-props.ts +5 -3
  94. package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
  95. package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
  96. package/src/client/hooks/chat/timeline/send.test.ts +4 -4
  97. package/src/client/hooks/chat/timeline/send.ts +59 -53
  98. package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
  99. package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
  100. package/src/client/hooks/chat/timeline/session-load.ts +6 -14
  101. package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
  102. package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
  103. package/src/client/hooks/models/harness-catalog.ts +114 -0
  104. package/src/client/hooks/models/provider-writes.test.ts +81 -0
  105. package/src/client/hooks/models/provider-writes.ts +10 -3
  106. package/src/client/hooks/models/use-harness-update.test.ts +193 -0
  107. package/src/client/hooks/models/use-harness-update.ts +202 -0
  108. package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
  109. package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
  110. package/src/client/hooks/models/use-harnesses.test.ts +2 -1
  111. package/src/client/hooks/models/use-harnesses.ts +48 -114
  112. package/src/client/hooks/workspace/child-expansion.ts +33 -0
  113. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  114. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  115. package/src/client/lib/session-tree.test.ts +50 -0
  116. package/src/client/lib/session-tree.ts +59 -0
  117. package/src/client/tailwind.css +26 -12
  118. package/src/server/index.ts +2 -0
  119. package/src/server/lib/auth/guard.ts +10 -0
  120. package/src/server/lib/btw/session-copy.server.ts +6 -44
  121. package/src/server/lib/btw/session-copy.test.ts +2 -1
  122. package/src/server/lib/db/schema.ts +4 -0
  123. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  124. package/src/server/lib/db/seed.test.ts +1 -1
  125. package/src/server/lib/harness/acp/activation.test.ts +81 -0
  126. package/src/server/lib/harness/acp/activation.ts +72 -0
  127. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  128. package/src/server/lib/harness/acp/background-work.ts +320 -0
  129. package/src/server/lib/harness/acp/client.ts +2 -2
  130. package/src/server/lib/harness/acp/frames.test.ts +50 -1
  131. package/src/server/lib/harness/acp/frames.ts +17 -5
  132. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  133. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  134. package/src/server/lib/harness/acp/mapper.ts +6 -4
  135. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  136. package/src/server/lib/harness/acp/prompt.ts +19 -3
  137. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  138. package/src/server/lib/harness/acp/session-config.test.ts +73 -0
  139. package/src/server/lib/harness/acp/session-config.ts +87 -6
  140. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  141. package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
  142. package/src/server/lib/harness/acp/session-handshake.ts +36 -3
  143. package/src/server/lib/harness/acp/session-idle.ts +51 -0
  144. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  145. package/src/server/lib/harness/acp/session-notifications.ts +19 -3
  146. package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
  147. package/src/server/lib/harness/acp/session-options.ts +33 -0
  148. package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
  149. package/src/server/lib/harness/acp/session-requests.ts +47 -0
  150. package/src/server/lib/harness/acp/session-turns.ts +20 -5
  151. package/src/server/lib/harness/acp/session.test-util.ts +54 -3
  152. package/src/server/lib/harness/acp/session.test.ts +65 -3
  153. package/src/server/lib/harness/acp/session.ts +79 -79
  154. package/src/server/lib/harness/acp/turn.test.ts +81 -0
  155. package/src/server/lib/harness/acp/turn.ts +54 -13
  156. package/src/server/lib/harness/acp/verbs.ts +12 -2
  157. package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
  158. package/src/server/lib/harness/auto-probe.server.ts +178 -0
  159. package/src/server/lib/harness/config.server.test.ts +1 -1
  160. package/src/server/lib/harness/config.server.ts +1 -1
  161. package/src/server/lib/harness/launch-table.ts +195 -0
  162. package/src/server/lib/harness/launch.test.ts +37 -0
  163. package/src/server/lib/harness/launch.ts +16 -116
  164. package/src/server/lib/harness/provider-entry.ts +32 -0
  165. package/src/server/lib/harness/provider-file.server.ts +3 -0
  166. package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
  167. package/src/server/lib/harness/provider-sources.server.ts +26 -2
  168. package/src/server/lib/harness/provider-write.server.ts +21 -32
  169. package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
  170. package/src/server/lib/harness/provider-zcode.server.ts +324 -0
  171. package/src/server/lib/harness/spawn.server.ts +15 -2
  172. package/src/server/lib/harness/update-job-store.test.ts +126 -0
  173. package/src/server/lib/harness/update-job-store.ts +109 -0
  174. package/src/server/lib/harness/update-job.server.ts +203 -0
  175. package/src/server/lib/harness/update-state.server.ts +15 -20
  176. package/src/server/lib/harness/update-worker.test.ts +153 -0
  177. package/src/server/lib/harness/update-worker.ts +197 -0
  178. package/src/server/lib/lifecycle/after-listen.ts +7 -0
  179. package/src/server/lib/lifecycle/paths.ts +23 -0
  180. package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
  181. package/src/server/lib/models/registry-refresh.server.ts +98 -0
  182. package/src/server/lib/omp/rpc/child-config.ts +5 -4
  183. package/src/server/lib/omp/rpc/constants.test.ts +2 -1
  184. package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
  185. package/src/server/lib/omp/rpc/manager.ts +5 -5
  186. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  187. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  188. package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
  189. package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
  190. package/src/server/lib/omp/session/delete.server.ts +17 -0
  191. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  192. package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
  193. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  194. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  195. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  196. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  197. package/src/server/lib/sessions/answers.server.ts +37 -0
  198. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  199. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  200. package/src/server/lib/sessions/fork.server.test.ts +209 -0
  201. package/src/server/lib/sessions/fork.server.ts +304 -0
  202. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  203. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  204. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  205. package/src/server/lib/sessions/notify.server.ts +212 -0
  206. package/src/server/lib/sessions/relation-types.ts +76 -0
  207. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  208. package/src/server/lib/sessions/relations.server.ts +337 -0
  209. package/src/server/lib/sessions/resolve.server.ts +106 -0
  210. package/src/server/lib/sessions/schema.server.ts +82 -0
  211. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  212. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  213. package/src/server/lib/sessions/spawn.server.test.ts +196 -0
  214. package/src/server/lib/sessions/spawn.server.ts +310 -0
  215. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  216. package/src/server/lib/terminal/output.test.ts +2 -2
  217. package/src/server/lib/terminal/output.ts +1 -1
  218. package/src/server/lib/terminal/resize.test.ts +99 -0
  219. package/src/server/lib/terminal/runtime.server.ts +26 -6
  220. package/src/server/lib/terminal/send-result.test.ts +18 -1
  221. package/src/server/lib/terminal/send-result.ts +26 -2
  222. package/src/server/lib/terminal/session.server.ts +6 -6
  223. package/src/server/lib/usage/new-api.test.ts +92 -0
  224. package/src/server/lib/usage/new-api.ts +131 -0
  225. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  226. package/src/server/lib/usage/provider-key.ts +33 -0
  227. package/src/server/lib/usage/providers.server.ts +10 -3
  228. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  229. package/src/server/lib/usage/vendor-http.ts +41 -0
  230. package/src/server/lib/usage/window.ts +55 -0
  231. package/src/server/routes/agent/command.ts +14 -1
  232. package/src/server/routes/agent/harness-command.ts +6 -0
  233. package/src/server/routes/agent/new.ts +15 -0
  234. package/src/server/routes/chat/rewind.test.ts +147 -0
  235. package/src/server/routes/chat/rewind.ts +29 -7
  236. package/src/server/routes/chat/session.test.ts +165 -10
  237. package/src/server/routes/chat/session.ts +60 -7
  238. package/src/server/routes/harness/add-provider.test.ts +9 -1
  239. package/src/server/routes/harness/import-action.ts +22 -4
  240. package/src/server/routes/harness/import.test.ts +1 -1
  241. package/src/server/routes/harness/index.ts +5 -1
  242. package/src/server/routes/harness/root.ts +8 -49
  243. package/src/server/routes/harness/toggle.test.ts +20 -0
  244. package/src/server/routes/harness/update-status.ts +26 -0
  245. package/src/server/routes/harness/update.test.ts +119 -0
  246. package/src/server/routes/harness/update.ts +67 -113
  247. package/src/server/routes/harness/versions.ts +5 -1
  248. package/src/server/routes/sessions/answer.ts +24 -0
  249. package/src/server/routes/sessions/batch-delete.ts +11 -5
  250. package/src/server/routes/sessions/delete-acp.test.ts +227 -0
  251. package/src/server/routes/sessions/delete.ts +4 -2
  252. package/src/server/routes/sessions/fork.ts +74 -0
  253. package/src/server/routes/sessions/index.ts +14 -0
  254. package/src/server/routes/sessions/relations.ts +85 -0
  255. package/src/server/routes/sessions/session.ts +4 -0
  256. package/src/server/routes/sessions/spawn.ts +134 -0
  257. package/src/server/routes/settings/model-override.ts +5 -2
  258. package/src/server/routes/settings/provider-entry.ts +2 -2
  259. package/src/server/routes/settings/provider-model.ts +2 -2
  260. package/src/server/routes/settings/provider-models.ts +2 -2
  261. package/src/server/routes/settings/provider-refresh.ts +6 -4
  262. package/src/server/routes/settings/providers.ts +3 -1
  263. package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
  264. package/src/server/routes/terminal/ws.ts +3 -3
  265. package/src/shared/lib/chat/ask-form/fields.ts +76 -0
  266. package/src/shared/lib/chat/ask-form/index.ts +323 -0
  267. package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
  268. package/src/shared/lib/chat/ask-form/types.ts +43 -0
  269. package/src/shared/lib/chat/ask-form.test.ts +137 -0
  270. package/src/shared/lib/chat/ask-questions.test.ts +65 -1
  271. package/src/shared/lib/chat/ask-questions.ts +51 -145
  272. package/src/shared/lib/chat/ask-results.ts +198 -0
  273. package/src/shared/lib/chat/composer/client.ts +31 -2
  274. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  275. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  276. package/src/shared/lib/chat/notice-text.ts +1 -1
  277. package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
  278. package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
  279. package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
  280. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  281. package/src/shared/lib/code/ansi.ts +1 -1
  282. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  283. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  284. package/src/shared/lib/harness/catalog.test.ts +1 -1
  285. package/src/shared/lib/harness/config-fields.test.ts +4 -0
  286. package/src/shared/lib/harness/config-fields.ts +19 -4
  287. package/src/shared/lib/harness/dialects.test.ts +8 -0
  288. package/src/shared/lib/harness/dialects.ts +12 -0
  289. package/src/shared/lib/harness/provider-facts.test.ts +59 -8
  290. package/src/shared/lib/harness/provider-facts.ts +46 -11
  291. package/src/shared/lib/harness/providers.ts +44 -1
  292. package/src/shared/lib/harness/rewind.ts +24 -0
  293. package/src/shared/lib/harness/update-job.ts +33 -0
  294. package/src/shared/lib/harness/update-plan.test.ts +69 -4
  295. package/src/shared/lib/harness/update-plan.ts +57 -9
  296. package/src/shared/lib/harness/updates.test.ts +22 -0
  297. package/src/shared/lib/harness/updates.ts +24 -1
  298. package/src/shared/lib/models/client.ts +10 -1
  299. package/src/shared/lib/omp/dialog-methods.ts +4 -3
  300. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  301. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  302. package/src/shared/lib/theme/catalog.test.ts +13 -9
  303. package/src/shared/lib/theme/color.test.ts +2 -2
  304. package/src/shared/lib/theme/color.ts +4 -4
  305. package/src/shared/lib/theme/css.ts +2 -0
  306. package/src/shared/lib/theme/ink-scale.ts +21 -1
  307. package/src/shared/lib/theme/theme.test.ts +26 -10
  308. package/src/shared/lib/ui/safe-area.test.ts +28 -0
  309. package/src/shared/lib/ui/safe-area.ts +42 -0
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +65 -0
  316. package/src/shared/types/harness.ts +30 -4
  317. package/src/shared/types/omp/agent.ts +19 -2
  318. package/src/shared/types/workspace.ts +4 -0
  319. package/src/test-support/fake-omp-fork.ts +16 -2
  320. package/src/test-support/file-explorer-render.test-util.ts +37 -0
  321. package/src/test-support/file-explorer.test-util.ts +20 -18
  322. package/src/test-support/harness-table.test-util.ts +21 -4
  323. package/dist/client/static/js/index-jhmg4w91.css +0 -1
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { describe, expect, test } from 'bun:test';
7
+ import {
8
+ GRID_SETTLE_MS,
9
+ MIN_REPORT_COLS,
10
+ MIN_REPORT_ROWS,
11
+ gridDecision,
12
+ } from '@/client/components/workspace/terminal-panel/grid';
13
+
14
+ const UNATTACHED = { attached: false, committed: { cols: 0, rows: 0 } };
15
+
16
+ describe('gridDecision', () => {
17
+ test('announces the first real grid as the attach size', () => {
18
+ expect(gridDecision({ cols: 41, rows: 47, ...UNATTACHED })).toEqual({
19
+ kind: 'attach',
20
+ cols: 41,
21
+ rows: 47,
22
+ });
23
+ });
24
+
25
+ test('ignores a squeezed panel instead of resizing the shell', () => {
26
+ // Measured: `resize 5x37` reached a real shell while the panel was opening
27
+ // its width transition, and the shell redrew its prompt hard-wrapped.
28
+ expect(gridDecision({ cols: 5, rows: 37, ...UNATTACHED })).toEqual({ kind: 'ignore' });
29
+ expect(gridDecision({ cols: MIN_REPORT_COLS - 1, rows: 47, ...UNATTACHED })).toEqual({
30
+ kind: 'ignore',
31
+ });
32
+ expect(gridDecision({ cols: 41, rows: MIN_REPORT_ROWS - 1, ...UNATTACHED })).toEqual({
33
+ kind: 'ignore',
34
+ });
35
+ });
36
+
37
+ test('maps a corrected grid onto a resize once attached', () => {
38
+ const attached = { attached: true, committed: { cols: 41, rows: 47 } };
39
+ expect(gridDecision({ cols: 41, rows: 47, ...attached })).toEqual({ kind: 'ignore' });
40
+ expect(gridDecision({ cols: 40, rows: 47, ...attached })).toEqual({
41
+ kind: 'change',
42
+ cols: 40,
43
+ rows: 47,
44
+ });
45
+ });
46
+
47
+ test('waits longer than a frame before announcing', () => {
48
+ // The panel's width transition outlives one animation frame; a gate shorter
49
+ // than ~100 ms measured the animating box again.
50
+ expect(GRID_SETTLE_MS).toBeGreaterThanOrEqual(100);
51
+ });
52
+ });
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * When a terminal grid may be announced to the shell.
8
+ *
9
+ * A terminal's grid is a PTY size, and a PTY size is a `SIGWINCH`: the shell
10
+ * answers each one by redrawing its prompt, and those redraws are output that
11
+ * lives in the scrollback forever. The right panel opens with a width
12
+ * transition, so fits during it measure a squeezed box — announcing one sent
13
+ * `resize 5x37` to a real shell, which redrew its prompt hard-wrapped at five
14
+ * columns. Worse, before the first fit the terminal still holds ghostty's 80×24
15
+ * default, which looks like a plausible size: a reload announced `80x24` and the
16
+ * shell answered by rewrapping its prompt at 80 columns. Both left garbage in
17
+ * the history, and every later reload replayed one more block of it above the
18
+ * live prompt, which is why the prompt marched down the panel.
19
+ *
20
+ * Two rules follow, and they are this module:
21
+ *
22
+ * - **A grid is announced only after it has held still** (`GRID_SETTLE_MS`), so
23
+ * a value read mid-animation never leaves the client.
24
+ * - **A grid comes from a real fit**, never from the terminal's default: the
25
+ * caller's `fit()` reports whether the container was measurable, and the
26
+ * decision below is not even asked when it was not.
27
+ */
28
+
29
+ import type { Terminal } from 'ghostty-web';
30
+
31
+ /** A grid below this is a panel mid-transition, not a size someone chose. */
32
+ export const MIN_REPORT_COLS = 10;
33
+ export const MIN_REPORT_ROWS = 5;
34
+ /** How long a grid must hold still before it is announced to the shell. */
35
+ export const GRID_SETTLE_MS = 120;
36
+
37
+ export type GridEvent =
38
+ | { kind: 'ignore' }
39
+ | { kind: 'attach'; cols: number; rows: number }
40
+ | { kind: 'change'; cols: number; rows: number };
41
+
42
+ /**
43
+ * Classify a measured grid against what has already been announced.
44
+ *
45
+ * Pure, so the rules can be pinned without a renderer, a timer or a socket.
46
+ */
47
+ export function gridDecision(input: {
48
+ cols: number;
49
+ rows: number;
50
+ attached: boolean;
51
+ committed: { cols: number; rows: number };
52
+ }): GridEvent {
53
+ const { cols, rows, attached, committed } = input;
54
+ if (cols < MIN_REPORT_COLS || rows < MIN_REPORT_ROWS) return { kind: 'ignore' };
55
+ if (!attached) return { kind: 'attach', cols, rows };
56
+ if (cols === committed.cols && rows === committed.rows) return { kind: 'ignore' };
57
+ return { kind: 'change', cols, rows };
58
+ }
59
+
60
+ export interface GridAnnouncerOptions {
61
+ /** The live terminal; the announcer never holds it, a theme rebuild replaces it. */
62
+ current: () => Terminal | undefined;
63
+ /** Fit to the container. False when the panel is hidden or the cell unmeasured. */
64
+ fit: () => boolean;
65
+ onReady: (cols: number, rows: number) => void;
66
+ onGridChange: (cols: number, rows: number) => void;
67
+ }
68
+
69
+ export interface GridAnnouncer {
70
+ /** Announce after the grid has held still for `GRID_SETTLE_MS`. */
71
+ schedule: () => void;
72
+ /** Forget what was announced, so the next commit states the grid again. */
73
+ restate: () => void;
74
+ /** True once the first real grid has been announced. */
75
+ isAttached: () => boolean;
76
+ dispose: () => void;
77
+ }
78
+
79
+ export function createGridAnnouncer(options: GridAnnouncerOptions): GridAnnouncer {
80
+ let committed = { cols: 0, rows: 0 };
81
+ let attached = false;
82
+ let timer: ReturnType<typeof setTimeout> | undefined;
83
+
84
+ const commit = (): void => {
85
+ if (!options.fit()) return;
86
+ const term = options.current();
87
+ if (!term) return;
88
+ const event = gridDecision({
89
+ cols: term.cols,
90
+ rows: term.rows,
91
+ attached,
92
+ committed,
93
+ });
94
+ if (event.kind === 'ignore') return;
95
+ committed = { cols: event.cols, rows: event.rows };
96
+ if (event.kind === 'attach') {
97
+ attached = true;
98
+ options.onReady(event.cols, event.rows);
99
+ return;
100
+ }
101
+ options.onGridChange(event.cols, event.rows);
102
+ };
103
+
104
+ return {
105
+ schedule() {
106
+ clearTimeout(timer);
107
+ timer = setTimeout(commit, GRID_SETTLE_MS);
108
+ },
109
+ restate() {
110
+ committed = { cols: 0, rows: 0 };
111
+ },
112
+ isAttached: () => attached,
113
+ dispose() {
114
+ clearTimeout(timer);
115
+ timer = undefined;
116
+ },
117
+ };
118
+ }
@@ -8,7 +8,7 @@ import { copyToClipboard, readClipboardText } from '@/client/hooks/ui/clipboard'
8
8
  import { TerminalHeader } from '@/client/components/workspace/terminal-panel/Header';
9
9
  import { TerminalQuickActions } from '@/client/components/workspace/terminal-panel/QuickActions';
10
10
  import { TerminalKeyBar } from '@/client/components/workspace/terminal-panel/KeyBar';
11
- import { RealtimeXtermView, type RealtimeXtermHandle } from '@/client/components/workspace/terminal-panel/RealtimeXtermView';
11
+ import { RealtimeTerminalView, type RealtimeTerminalHandle } from '@/client/components/workspace/terminal-panel/RealtimeTerminalView';
12
12
  import {
13
13
  NO_MODIFIERS,
14
14
  applyModifiers,
@@ -30,7 +30,7 @@ interface TerminalPanelProps {
30
30
  const encoder = new TextEncoder();
31
31
 
32
32
  export function TerminalPanel({ className = '', enabled = true, rootPath, showHeader = true, active = true }: TerminalPanelProps) {
33
- const xtermRef = useRef<RealtimeXtermHandle>(null);
33
+ const terminalRef = useRef<RealtimeTerminalHandle>(null);
34
34
  const { isDark } = useTheme();
35
35
  // Only a device without a physical keyboard gets the key bar: on a desktop
36
36
  // every one of those keys is already under the user's fingers, and a strip of
@@ -44,21 +44,21 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
44
44
  const { activeRepo, setActiveRepo } = useRepoScope(rootPath);
45
45
  const { repos, scanning: reposScanning, rescan: rescanRepos } = useRepoList(rootPath, enabled);
46
46
  const gridRef = useRef<{ cols: number; rows: number } | null>(null);
47
- // The latch is read inside `handleInput`, which xterm calls outside React's
47
+ // The latch is read inside `handleInput`, which the terminal calls outside React's
48
48
  // render — a ref is what makes it the value at the keystroke, not at mount.
49
49
  const modifiersRef = useRef(modifiers);
50
50
  modifiersRef.current = modifiers;
51
51
 
52
52
  const handleOutput = useCallback((bytes: Uint8Array) => {
53
- xtermRef.current?.write(bytes);
53
+ terminalRef.current?.write(bytes);
54
54
  }, []);
55
55
 
56
56
  const handleReplay = useCallback((bytes: Uint8Array, frame: { replayCols: number; replayRows: number }) => {
57
- xtermRef.current?.writeReplay(bytes, frame.replayCols, frame.replayRows);
57
+ terminalRef.current?.writeReplay(bytes, frame.replayCols, frame.replayRows);
58
58
  }, []);
59
59
 
60
60
  const handleRestart = useCallback(() => {
61
- xtermRef.current?.reset();
61
+ terminalRef.current?.reset();
62
62
  }, []);
63
63
 
64
64
  const {
@@ -70,6 +70,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
70
70
  resize,
71
71
  input,
72
72
  restart,
73
+ reattach,
73
74
  } = useTerminal({
74
75
  root: enabled ? rootPath : undefined,
75
76
  repo: activeRepo,
@@ -112,19 +113,19 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
112
113
 
113
114
  const handleToggleModifier = useCallback((modifier: TerminalModifier) => {
114
115
  setModifiers((previous) => ({ ...previous, [modifier]: !previous[modifier] }));
115
- xtermRef.current?.focus();
116
+ terminalRef.current?.focus();
116
117
  }, []);
117
118
 
118
119
  const handleKey = useCallback((id: TerminalKeyId) => {
119
120
  const sequence = resolveKeySequence(id, {
120
- applicationCursorKeys: xtermRef.current?.applicationCursorKeys() ?? false,
121
+ applicationCursorKeys: terminalRef.current?.applicationCursorKeys() ?? false,
121
122
  modifiers: modifiersRef.current,
122
123
  });
123
124
  if (!sequence) return;
124
125
  input(encoder.encode(sequence));
125
126
  setModifiers(NO_MODIFIERS);
126
127
  // Keep the OS keyboard where it was; a key bar tap must not dismiss it.
127
- xtermRef.current?.focus();
128
+ terminalRef.current?.focus();
128
129
  }, [input]);
129
130
 
130
131
  /**
@@ -134,7 +135,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
134
135
  * instead of flashing success over an untouched clipboard.
135
136
  */
136
137
  const handleCopy = useCallback(async () => {
137
- const selection = xtermRef.current?.getSelection() ?? '';
138
+ const selection = terminalRef.current?.getSelection() ?? '';
138
139
  if (!selection) return false;
139
140
  return copyToClipboard(selection);
140
141
  }, []);
@@ -142,27 +143,29 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
142
143
  const handlePaste = useCallback(async () => {
143
144
  const text = await readClipboardText();
144
145
  if (text === null || text.length === 0) return false;
145
- // Through xterm's own paste, so a bracketed-paste shell gets its markers.
146
- xtermRef.current?.paste(text);
147
- xtermRef.current?.focus();
146
+ // Through the terminal's own paste, so a bracketed-paste shell gets its markers.
147
+ terminalRef.current?.paste(text);
148
+ terminalRef.current?.focus();
148
149
  return true;
149
150
  }, []);
150
151
 
151
- const handleBinaryInput = useCallback((data: string) => {
152
- const bytes = new Uint8Array(data.length);
153
- for (let i = 0; i < data.length; i += 1) bytes[i] = data.charCodeAt(i) & 0xff;
152
+ const handleBinaryInput = useCallback((bytes: Uint8Array) => {
154
153
  input(bytes);
155
154
  }, [input]);
156
155
 
157
156
  const handleQuickAction = useCallback((command: string) => {
158
157
  input(encoder.encode(`${command}\r`));
159
- xtermRef.current?.focus();
158
+ terminalRef.current?.focus();
160
159
  }, [input]);
161
160
 
162
161
  const handleRestartClick = useCallback(() => {
163
162
  restart();
164
163
  }, [restart]);
165
164
 
165
+ const handleReattach = useCallback(() => {
166
+ reattach();
167
+ }, [reattach]);
168
+
166
169
  if (!enabled) {
167
170
  return (
168
171
  <div className={`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${className}`}>
@@ -175,6 +178,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
175
178
  <div
176
179
  ref={rootRef}
177
180
  className={`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${className}`}
181
+ aria-hidden={!active}
178
182
  // The soft keyboard covers the bottom of the visual viewport without
179
183
  // shrinking the layout one, so the key bar would sit behind the keys the
180
184
  // user is typing on. Lifting by the panel's actual overlap with the
@@ -207,15 +211,15 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
207
211
  </div>
208
212
  )}
209
213
 
210
- {/* Real-time Xterm Terminal Canvas, driven by the PTY socket */}
214
+ {/* Real-time terminal canvas, driven by the PTY socket */}
211
215
  <div className="flex-1 w-full min-h-0 bg-canvas overflow-hidden">
212
- <RealtimeXtermView
213
- ref={xtermRef}
216
+ <RealtimeTerminalView
217
+ ref={terminalRef}
214
218
  onInput={handleInput}
215
219
  onBinaryInput={handleBinaryInput}
216
220
  onReady={handleReady}
217
221
  onGridChange={handleGridChange}
218
- visible={active}
222
+ onReattach={handleReattach}
219
223
  />
220
224
  </div>
221
225