@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,128 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A provider write republishes the `models` topic, and the harness catalog is
8
+ * stale in exactly the same way: the server re-probed the ACP harnesses on that
9
+ * write. The hook therefore re-reads `GET /api/harness` when the topic fires —
10
+ * without this, the composer picker kept the pre-write probe until a reload.
11
+ *
12
+ * A real listener on a real socket, because the bug is frame delivery, not the
13
+ * fetch: a stubbed socket would only prove the fake's timing.
14
+ */
15
+
16
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
17
+ import { Window } from 'happy-dom';
18
+ import { h, render } from 'preact';
19
+ import { act } from 'preact/test-utils';
20
+
21
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
22
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
23
+ import type { HarnessesController } from '@/client/hooks/models/use-harnesses-controller';
24
+ import { TOPIC_MODELS } from '@/shared/lib/realtime/protocol';
25
+ import { resetRealtimeClient } from '@/shared/lib/realtime/client';
26
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
27
+ import { startRealtimeTestServer, type RealtimeTestServer } from '@/test-support/realtime-server';
28
+
29
+ const UNPROBED = { id: 'omp-acp', label: 'omp ACP', transport: 'acp', canLaunch: true, probe: null };
30
+ const PROBED = {
31
+ id: 'omp-acp',
32
+ label: 'omp ACP',
33
+ transport: 'acp',
34
+ canLaunch: true,
35
+ probe: {
36
+ harness: 'omp-acp',
37
+ capabilities: {
38
+ configModel: 2, configThinking: 0, configMode: 0, modeValues: [],
39
+ loadSession: true, listSessions: true, forkSession: true, deleteSession: true,
40
+ resumeSession: true, closeSession: true, hasUsage: false, hasPlan: false, steerMode: null,
41
+ },
42
+ models: [
43
+ { value: 'minimax/MiniMax-M2', name: 'MiniMax M2' },
44
+ { value: 'kimi/kimi-k2', name: 'Kimi K2' },
45
+ ],
46
+ thinking: [],
47
+ modes: [],
48
+ probedAt: Date.now(),
49
+ },
50
+ };
51
+
52
+ const realFetch = Bun.fetch;
53
+ let server: RealtimeTestServer;
54
+ let container: HTMLElement;
55
+ let catalogReads = 0;
56
+ /** The server's answer changed only when the write lands. */
57
+ let written = false;
58
+
59
+ beforeEach(async () => {
60
+ server = await startRealtimeTestServer(new Map([[TOPIC_MODELS, async () => ({ modelList: [] })]]));
61
+ installDomGlobals(new Window({ url: `http://127.0.0.1:${server.port}` }));
62
+ resetHarnessesStore();
63
+ catalogReads = 0;
64
+ written = false;
65
+ (globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown) => {
66
+ const url = String(input);
67
+ if (!url.includes('/api/harness')) return new Response('{}', { status: 200 });
68
+ catalogReads += 1;
69
+ const body = { harnesses: [written ? PROBED : UNPROBED], configs: {}, providerSupport: {} };
70
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
71
+ };
72
+ container = document.createElement('div');
73
+ document.body.append(container);
74
+ });
75
+
76
+ afterEach(() => {
77
+ render(null, container);
78
+ container.remove();
79
+ resetRealtimeClient();
80
+ server.stop();
81
+ restoreDomGlobals();
82
+ (globalThis as unknown as Record<string, unknown>).fetch = realFetch;
83
+ });
84
+
85
+ function mount(): { read: () => HarnessesController } {
86
+ const box = { latest: null as HarnessesController | null };
87
+ function Consumer() {
88
+ box.latest = useHarnesses();
89
+ return null;
90
+ }
91
+ const host = document.createElement('div');
92
+ container.appendChild(host);
93
+ act(() => render(h(Consumer, {}), host));
94
+ return {
95
+ read: () => {
96
+ if (!box.latest) throw new Error('consumer did not render');
97
+ return box.latest;
98
+ },
99
+ };
100
+ }
101
+
102
+ describe('the harness catalog follows the models topic', () => {
103
+ test('a models-changed frame re-reads the catalog and shows the new probe', async () => {
104
+ const consumer = mount();
105
+ await act(async () => {});
106
+ await server.waitForTopic(TOPIC_MODELS, (value) => value !== null);
107
+ expect(consumer.read().harnesses[0]?.probe).toBeNull();
108
+ // Mounting costs one read; the subscription's opening snapshot costs the
109
+ // second. That snapshot is the same catalog, so the probe is still absent.
110
+ expect(catalogReads).toBe(2);
111
+
112
+ written = true;
113
+ server.publish(TOPIC_MODELS, { modelList: [{ value: 'minimax/MiniMax-M2' }] });
114
+ // Wait on the client's own notification: the delta is a socket task, so a
115
+ // microtask drain alone could assert before the frame is even decoded.
116
+ await server.waitForTopic<{ modelList: { value: string }[] }>(
117
+ TOPIC_MODELS,
118
+ (value) => value?.modelList.length === 1,
119
+ );
120
+ // The subscriber's fetch starts from that notification; drain until the
121
+ // store's render reflects the post-write answer.
122
+ for (let i = 0; i < 20 && !consumer.read().harnesses[0]?.probe; i += 1) await act(async () => {});
123
+ await act(async () => {});
124
+
125
+ expect(catalogReads).toBeGreaterThan(2);
126
+ expect(consumer.read().harnesses[0]?.probe?.models).toHaveLength(2);
127
+ });
128
+ });
@@ -27,7 +27,8 @@ import { Window } from 'happy-dom';
27
27
  import { h, render } from 'preact';
28
28
  import { act } from 'preact/test-utils';
29
29
 
30
- import { resetHarnessesStore, useHarnesses } from '@/client/hooks/models/use-harnesses';
30
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
31
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
31
32
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
32
33
 
33
34
  const OPENCODE_UNPROBED = {
@@ -22,114 +22,57 @@
22
22
  */
23
23
 
24
24
  import { useEffect, useState } from 'preact/hooks';
25
- import type {
26
- HarnessConfig, HarnessImportOutcome, HarnessProviderSupport, HarnessesPayload, HarnessSummary,
27
- } from '@/shared/types/harness';
28
- import type { AddProviderInput } from '@/client/components/settings/categories/harness-settings/AddProviderForm';
25
+ import type { HarnessConfig, HarnessSummary, LiveHarnessModels } from '@/shared/types/harness';
26
+ import type { HarnessesController } from '@/client/hooks/models/use-harnesses-controller';
27
+ import {
28
+ emit, invalidateCatalog, listeners, loadCatalog, store,
29
+ } from '@/client/hooks/models/harness-catalog';
29
30
  import { addProvider, importProvider } from '@/client/hooks/models/provider-writes';
31
+ import { subscribeModelsUpdated } from '@/shared/lib/models/client';
30
32
 
31
- export interface HarnessesController {
32
- harnesses: HarnessSummary[];
33
- /** Per-harness config, keyed by id. Empty until the catalog is read. */
34
- configs: Record<string, HarnessConfig>;
35
- /** Persist one harness's config; resolves to the server's refusal, or null. */
36
- saveConfig: (id: string, config: HarnessConfig) => Promise<string | null>;
37
- /** What each harness can do about other providers, keyed by id. */
38
- providerSupport: Record<string, HarnessProviderSupport>;
39
- /** Copy one provider from a source registry into a harness.
40
- *
41
- * The ROW travels with the id: the writer needs the endpoint, dialect and
42
- * model list, and the server would otherwise have to look them up again. The
43
- * credential is not in the row — the server reads that from the source file. */
44
- importProvider: (
45
- id: string,
46
- sourceId: string,
47
- entry: HarnessProviderSupport['importable'][number],
48
- ) => Promise<HarnessImportOutcome>;
49
- /** Add a provider by typing its endpoint and key. */
50
- addProvider: (id: string, input: AddProviderInput) => Promise<HarnessImportOutcome>;
51
- isLoading: boolean;
52
- error: string | null;
53
- /** Re-read the catalog. */
54
- reload: () => void;
55
- /** Probe one harness (spawns that agent once) and merge the answer in. */
56
- probe: (id: string, cwd?: string) => Promise<string | null>;
57
- /** Switch one harness on or off. Switching ON also probes it once, server-side,
58
- * so its models are ready for the composer. Resolves to the refusal, or null. */
59
- setEnabled: (id: string, enabled: boolean) => Promise<string | null>;
33
+ /**
34
+ * Record the selectors a LIVE chat published for its harness.
35
+ *
36
+ * Called by the session loader on every session read, so the guard matters: an
37
+ * unchanged list must not notify every picker subscriber (the metadata refresh
38
+ * runs a few times per chat).
39
+ */
40
+ export function publishLiveModels(id: string, live: LiveHarnessModels): void {
41
+ if (!id || live.models.length === 0) return;
42
+ const current = store.liveModels[id];
43
+ if (current && sameSelectors(current, live)) return;
44
+ emit({ liveModels: { ...store.liveModels, [id]: live } });
60
45
  }
61
46
 
62
- interface HarnessStore {
63
- harnesses: HarnessSummary[];
64
- configs: Record<string, HarnessConfig>;
65
- providerSupport: Record<string, HarnessProviderSupport>;
66
- isLoading: boolean;
67
- error: string | null;
68
- /** Bumped on every change, so `useSyncExternalStore`-style subscribers can
69
- * detect it without holding the arrays themselves. */
70
- version: number;
71
- }
72
-
73
- const store: HarnessStore = {
74
- harnesses: [], configs: {}, providerSupport: {}, isLoading: true, error: null, version: 0,
75
- };
76
- /** Has the catalog been read at least once? A later mount must NOT re-fetch: the
77
- * answer is a property of the installed agents, and `reload()` is the explicit
78
- * way to re-read it. */
79
- let loaded = false;
80
- const listeners = new Set<() => void>();
81
- /** One in-flight catalog read shared by every mount; a second mount joins it
82
- * rather than firing its own `GET /api/harness`. */
83
- let inflight: Promise<void> | null = null;
84
-
85
- function emit(patch: Partial<HarnessStore>): void {
86
- Object.assign(store, patch);
87
- store.version += 1;
88
- for (const listener of listeners) listener();
47
+ function sameSelectors(a: LiveHarnessModels, b: LiveHarnessModels): boolean {
48
+ const keys = (list?: readonly { value: string; name: string }[]) =>
49
+ (list ?? []).map((entry) => `${entry.value}\u0000${entry.name}`).join('\u0001');
50
+ return a.models.length === b.models.length
51
+ && keys(a.models) === keys(b.models)
52
+ && keys(a.thinking) === keys(b.thinking);
89
53
  }
90
54
 
91
55
  /** Fold a landed provider write back into the store and re-read the catalog. */
92
- function announceProviderWrite(id: string, config?: HarnessConfig): void {
56
+ function announceProviderWrite(
57
+ id: string,
58
+ config?: HarnessConfig,
59
+ probeInvalidated?: readonly string[],
60
+ ): void {
93
61
  if (config) emit({ configs: { ...store.configs, [id]: config } });
94
62
  // The write landed in a FILE, which is the only thing that proves it, so the
95
63
  // list is re-read rather than patched: a card that kept the previous list would
96
64
  // show "nothing added" after a successful add. The store caches its first
97
65
  // answer on purpose, so the re-read has to clear it.
98
- loaded = false;
99
- void loadCatalog();
100
- }
101
-
102
- async function loadCatalog(): Promise<void> {
103
- if (inflight) return inflight;
104
- if (loaded) return;
105
- emit({ isLoading: true });
106
- inflight = fetch('/api/harness')
107
- .then(async (response) => {
108
- if (!response.ok) throw new Error(`GET /api/harness answered ${response.status}`);
109
- return (await response.json()) as HarnessesPayload;
110
- })
111
- .then((payload) => {
112
- loaded = true;
113
- emit({
114
- harnesses: Array.isArray(payload.harnesses) ? payload.harnesses : [],
115
- // Absent from an answer written before per-harness config existed: an
116
- // empty map is the honest reading, and every card then shows "not set".
117
- configs: payload.configs ?? {},
118
- providerSupport: payload.providerSupport ?? {},
119
- error: null,
120
- isLoading: false,
121
- });
122
- })
123
- .catch((cause: unknown) => {
124
- emit({
125
- error: cause instanceof Error ? cause.message : 'Could not read the harness list',
126
- isLoading: false,
127
- });
128
- })
129
- .finally(() => {
130
- inflight = null;
131
- });
132
- return inflight;
66
+ void invalidateCatalog().then(() => {
67
+ // The server names every tab whose probe measured the OLD file. Ask each
68
+ // launchable one to answer now, so the picker offers the new models without
69
+ // a manual "Check status". The built-in transport has no agent to probe.
70
+ for (const target of probeInvalidated ?? []) {
71
+ const entry = store.harnesses.find((harness) => harness.id === target);
72
+ if (!entry || entry.builtIn || entry.unavailable) continue;
73
+ void probeHarness(target);
74
+ }
75
+ });
133
76
  }
134
77
 
135
78
  /** One probe, shared: the settings page's "check status" and the tab strip's
@@ -241,8 +184,15 @@ export function useHarnesses(): HarnessesController {
241
184
  // first one already loaded, or the second surface renders empty forever.
242
185
  sync();
243
186
  void loadCatalog();
187
+ // A provider/model write republishes the `models` topic. The ACP pickers read
188
+ // PROBES, which the server refreshed on the same write, so the cached
189
+ // catalog is stale in exactly the same way the model list is.
190
+ const offModels = subscribeModelsUpdated(() => {
191
+ void invalidateCatalog();
192
+ });
244
193
  return () => {
245
194
  listeners.delete(sync);
195
+ offModels();
246
196
  };
247
197
  }, []);
248
198
 
@@ -251,31 +201,15 @@ export function useHarnesses(): HarnessesController {
251
201
  configs: snapshot.configs,
252
202
  saveConfig: saveHarnessConfig,
253
203
  providerSupport: snapshot.providerSupport,
204
+ liveModels: snapshot.liveModels,
254
205
  importProvider: (id, sourceId, entry) => importProvider(id, sourceId, entry, announceProviderWrite),
255
206
  addProvider: (id, input) => addProvider(id, input, announceProviderWrite),
256
207
  isLoading: snapshot.isLoading,
257
208
  error: snapshot.error,
258
209
  reload: () => {
259
- loaded = false;
260
- void loadCatalog();
210
+ void invalidateCatalog();
261
211
  },
262
212
  probe: probeHarness,
263
213
  setEnabled: setHarnessEnabled,
264
214
  };
265
215
  }
266
-
267
- /**
268
- * Forget everything this process learned about the harnesses.
269
- *
270
- * Two callers, one meaning: a test file starts from a cold store, and
271
- * `bun --hot` re-evaluates this module while the old store may still describe
272
- * agents that have since been installed or removed.
273
- */
274
- export function resetHarnessesStore(): void {
275
- inflight = null;
276
- loaded = false;
277
- Object.assign(store, {
278
- harnesses: [], configs: {}, providerSupport: {}, isLoading: true, error: null, version: 0,
279
- });
280
- for (const listener of listeners) listener();
281
- }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which session rows have their child tree open.
8
+ *
9
+ * Deliberately separate from `useExpandedSessions` (the subagent roster): one
10
+ * chevron cannot mean two different lists. Local, not persisted — a collapsed
11
+ * tree is one click away, while a persisted roster is what the phone and the
12
+ * desktop must agree on.
13
+ */
14
+
15
+ import { useCallback, useState } from 'preact/hooks';
16
+
17
+ export interface ChildExpansion {
18
+ expandedChildIds: Set<string>;
19
+ toggleChild: (sessionId: string) => void;
20
+ }
21
+
22
+ export function useChildExpansion(): ChildExpansion {
23
+ const [expandedChildIds, setExpandedChildIds] = useState<Set<string>>(() => new Set());
24
+ const toggleChild = useCallback((sessionId: string) => {
25
+ setExpandedChildIds((prev) => {
26
+ const next = new Set(prev);
27
+ if (next.has(sessionId)) next.delete(sessionId);
28
+ else next.add(sessionId);
29
+ return next;
30
+ });
31
+ }, []);
32
+ return { expandedChildIds, toggleChild };
33
+ }
@@ -5,7 +5,7 @@
5
5
 
6
6
  /**
7
7
  * Live terminal session for the right panel: the socket, its status, and the
8
- * attach/resize/input verbs the xterm view drives.
8
+ * attach/resize/input verbs the terminal view drives.
9
9
  *
10
10
  * The terminal id is per Kabmo session and persisted, which is what makes the
11
11
  * shell survive a page reload: the panel reattaches to the id it already owns
@@ -48,6 +48,12 @@ export interface UseTerminalResult {
48
48
  input: (data: Uint8Array) => void;
49
49
  /** Replace the shell with a fresh one. */
50
50
  restart: () => void;
51
+ /**
52
+ * Re-open the socket for the same terminal id. The server replays its
53
+ * retained scrollback, which is what lets a rebuilt renderer (a theme switch)
54
+ * regain its history without a new shell.
55
+ */
56
+ reattach: () => void;
51
57
  }
52
58
 
53
59
  export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult {
@@ -57,6 +63,8 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
57
63
  const [shell, setShell] = useState('');
58
64
  const [exitCode, setExitCode] = useState<number | null>(null);
59
65
  const [error, setError] = useState<string | null>(null);
66
+ /** Incremented by `reattach`; the socket effect owns the reconnect. */
67
+ const [generation, setGeneration] = useState(0);
60
68
 
61
69
  const socketRef = useRef<TerminalSocket | null>(null);
62
70
  // The grid the view reported, replayed on attach so a reconnect lands on the
@@ -133,7 +141,7 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
133
141
  socket.release();
134
142
  socketRef.current = null;
135
143
  };
136
- }, [ready, terminalId]);
144
+ }, [ready, terminalId, generation]);
137
145
 
138
146
  const restart = useCallback(() => {
139
147
  // Kill the old shell before minting a new id: leaving it to the idle
@@ -182,5 +190,11 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
182
190
  socketRef.current?.input(data);
183
191
  }, []);
184
192
 
185
- return { status, shell, exitCode, error, attach, resize, input, restart };
193
+ const reattach = useCallback(() => {
194
+ // The effect's cleanup releases the old socket and a new one attaches with
195
+ // the remembered size, so the server replays the same terminal id.
196
+ setGeneration((value) => value + 1);
197
+ }, []);
198
+
199
+ return { status, shell, exitCode, error, attach, resize, input, restart, reattach };
186
200
  }
@@ -13,9 +13,10 @@
13
13
  * bytes and is handed straight to `term.write(Uint8Array)`; the client never
14
14
  * decodes UTF-8 itself, which is what keeps a character split across two PTY
15
15
  * reads intact.
16
- * - **`onBinary` carries the same bytes as `onData`.** xterm reports non-UTF-8
17
- * payloads (some mouse reports, paste of raw bytes) on `onBinary`; forwarding
18
- * only `onData` would silently drop them.
16
+ * - **Non-UTF-8 payloads take the byte channel.** ghostty-web has no `onBinary`:
17
+ * it reports every keystroke and mouse report as one `onData` string, so
18
+ * `terminalInputFrame` splits the legacy X10 report back into bytes before the
19
+ * socket sees it. Encoding that payload as text would corrupt it.
19
20
  * - **Reconnect, not re-create.** A dropped socket re-dials the same terminal
20
21
  * id, so the shell and its scrollback survive a network blip or a page reload
21
22
  * instead of a second shell appearing.
@@ -99,7 +100,11 @@ export function connectTerminal(terminalId: string, handlers: TerminalSocketHand
99
100
  handleOutput(new Uint8Array(event.data));
100
101
  return;
101
102
  }
102
- const frame = decodeServerFrame(typeof event.data === 'string' ? event.data : '');
103
+ // Anything that is not a binary frame is a control frame. The server
104
+ // sends PTY bytes as Buffer views, so `event.data` is an ArrayBuffer and
105
+ // this branch only ever sees JSON.
106
+ if (typeof event.data !== 'string') return;
107
+ const frame = decodeServerFrame(event.data);
103
108
  if (frame) applyFrame(frame);
104
109
  };
105
110
 
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { describe, expect, test } from 'bun:test';
7
+ import { buildSessionTree, descendantsOf } from '@/client/lib/session-tree';
8
+ import type { SessionItemData } from '@/shared/types';
9
+
10
+ function session(id: string, parentSessionId?: string): SessionItemData {
11
+ return {
12
+ id,
13
+ folder_id: 1,
14
+ title: id,
15
+ ...(parentSessionId ? { parentSessionId } : {}),
16
+ };
17
+ }
18
+
19
+ describe('buildSessionTree', () => {
20
+ test('nests children under their parent and keeps orphans as roots', () => {
21
+ const tree = buildSessionTree([
22
+ session('root'),
23
+ session('child', 'root'),
24
+ session('grandchild', 'child'),
25
+ session('orphan', 'missing'),
26
+ ]);
27
+ expect(tree.roots.map((row) => row.id)).toEqual(['root', 'orphan']);
28
+ expect(tree.childrenOf.get('root')?.map((row) => row.id)).toEqual(['child']);
29
+ expect(tree.childrenOf.get('child')?.map((row) => row.id)).toEqual(['grandchild']);
30
+ });
31
+
32
+ test('a self-parent is a root rather than an invisible row', () => {
33
+ const tree = buildSessionTree([session('self', 'self')]);
34
+ expect(tree.roots.map((row) => row.id)).toEqual(['self']);
35
+ });
36
+
37
+ test('descendants carry depth and stop at a cycle', () => {
38
+ const childrenOf = new Map<string, SessionItemData[]>([
39
+ ['a', [session('b', 'a')]],
40
+ ['b', [session('c', 'b')]],
41
+ ]);
42
+ expect(descendantsOf('a', childrenOf).map((row) => [row.session.id, row.depth])).toEqual([
43
+ ['b', 1],
44
+ ['c', 2],
45
+ ]);
46
+ // A cycle is not walked forever.
47
+ childrenOf.set('c', [session('a', 'c')]);
48
+ expect(descendantsOf('a', childrenOf).map((row) => row.session.id)).toEqual(['b', 'c']);
49
+ });
50
+ });
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A flat session list → roots plus a parent→children map.
8
+ *
9
+ * A child session is a session, so the sidebar draws it under its parent. A
10
+ * session whose parent is not in the same folder (a cross-folder relation, or
11
+ * one the current filter/window removed) stays a root: hiding it would make a
12
+ * row the user can still open by URL unreachable from the sidebar.
13
+ *
14
+ * Pure and order-preserving: the list's own sort is the tree's sort.
15
+ */
16
+
17
+ import type { SessionItemData } from '@/shared/types';
18
+
19
+ export interface SessionTree {
20
+ roots: SessionItemData[];
21
+ childrenOf: Map<string, SessionItemData[]>;
22
+ }
23
+
24
+ export function buildSessionTree(sessions: readonly SessionItemData[]): SessionTree {
25
+ const present = new Set(sessions.map((session) => String(session.id)));
26
+ const childrenOf = new Map<string, SessionItemData[]>();
27
+ const roots: SessionItemData[] = [];
28
+
29
+ for (const session of sessions) {
30
+ const parentId = session.parentSessionId;
31
+ if (!parentId || !present.has(parentId) || parentId === String(session.id)) {
32
+ roots.push(session);
33
+ continue;
34
+ }
35
+ const bucket = childrenOf.get(parentId);
36
+ if (bucket) bucket.push(session);
37
+ else childrenOf.set(parentId, [session]);
38
+ }
39
+
40
+ return { roots, childrenOf };
41
+ }
42
+
43
+ /** Every descendant of a session, depth-first, with its depth (root child = 1). */
44
+ export function descendantsOf(
45
+ sessionId: string,
46
+ childrenOf: Map<string, SessionItemData[]>,
47
+ depth = 1,
48
+ seen = new Set<string>(),
49
+ ): Array<{ session: SessionItemData; depth: number }> {
50
+ if (seen.has(sessionId)) return [];
51
+ seen.add(sessionId);
52
+ const out: Array<{ session: SessionItemData; depth: number }> = [];
53
+ for (const child of childrenOf.get(sessionId) ?? []) {
54
+ if (seen.has(String(child.id))) continue;
55
+ out.push({ session: child, depth });
56
+ out.push(...descendantsOf(String(child.id), childrenOf, depth + 1, seen));
57
+ }
58
+ return out;
59
+ }
@@ -1,5 +1,4 @@
1
1
  @import "tailwindcss";
2
- @import "@xterm/xterm/css/xterm.css";
3
2
 
4
3
  @theme {
5
4
  /* The UI font stack, with the Nerd Font families LAST.
@@ -7,7 +6,7 @@
7
6
  * omp heads a session title with a card icon — a private-use glyph
8
7
  * (`title.icons: nf+emoji`, the default) that no Latin face contains. The
9
8
  * terminal already names a Nerd Font for exactly this reason
10
- * (`XTERM_GLYPH_FALLBACKS` + `NERD_SYMBOLS_FAMILY` in
9
+ * (`TERMINAL_GLYPH_FALLBACKS` + `NERD_SYMBOLS_FAMILY` in
11
10
  * `data/theme/terminal.ts`), but the UI stack did not, so a title card
12
11
  * rendered only where the DEVICE happened to have a Nerd Font installed: on
13
12
  * the developer's desktop Chromium fell back to one, and on a phone — which
@@ -24,7 +23,7 @@
24
23
  * fallback and downloads it on every machine.
25
24
  *
26
25
  * The family names are literals here because Tailwind's `@theme` cannot
27
- * import a TS constant; they must stay equal to `XTERM_GLYPH_FALLBACKS` and
26
+ * import a TS constant; they must stay equal to `TERMINAL_GLYPH_FALLBACKS` and
28
27
  * `NERD_SYMBOLS_FAMILY`, which `nerd-symbols.test.ts` asserts. */
29
28
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "FiraCode Nerd Font Mono", "FiraCode Nerd Font", "JetBrainsMono Nerd Font", "JetBrainsMono NF", "JetBrains Mono Nerd Font", "Hack Nerd Font", "MesloLGS NF", "MesloLGM Nerd Font", "CaskaydiaCove Nerd Font", "SauceCodePro Nerd Font", "Symbols Nerd Font Mono", "Symbols Nerd Font", "PowerlineSymbols", "Kabmo Nerd Symbols";
30
29
  --color-ink: var(--theme-ink);
@@ -553,16 +552,23 @@
553
552
  display: none;
554
553
  }
555
554
 
556
- /* The terminal keeps xterm's own `overflow-y: scroll` (its gutter is part of
557
- * the grid's geometry), but it is deliberately NOT given its own scrollbar
558
- * colours any more — it had 8px/22%/42% and a painted track while every other
559
- * container had 6px/20%/40% and a transparent one, which is exactly the drift
560
- * the block above exists to remove. It inherits the global rule, so the
561
- * terminal's bar is the same bar as everywhere else, and follows the theme
562
- * with it. The `touch-action`/momentum pair below is a separate concern. */
563
- .xterm .xterm-viewport {
555
+ /* The terminal host: ghostty-web draws its scrollbar inside the canvas, so
556
+ * there is no native viewport to style. The drag-to-scroll handlers in
557
+ * `terminal-panel/mount.ts` own the gesture; `pan-y` keeps the browser from
558
+ * claiming it first, and momentum stays the platform's.
559
+ *
560
+ * `caret-color: transparent` is not cosmetic. ghostty-web marks the host it is
561
+ * opened on `contenteditable="true"` and `tabindex="0"` (the IME/`beforeinput`
562
+ * path), and its visible input is a hidden textarea — so a click on the 6px
563
+ * padding focuses the DIV itself and the browser paints a NATIVE caret there:
564
+ * a black blinking bar at the left edge, whose height follows the host's
565
+ * inherited 16px/24px line box (measured in Chromium: 24px, and it changes
566
+ * with the content beside the click point). The terminal's cursor is the
567
+ * canvas block, so the DOM caret is never wanted. */
568
+ .kabmo-terminal {
564
569
  touch-action: pan-y;
565
570
  -webkit-overflow-scrolling: touch;
571
+ caret-color: transparent;
566
572
  }
567
573
 
568
574
  /* The chat column's width, in ONE variable and ONE class.
@@ -809,10 +815,18 @@
809
815
  .prose-content td, .prose-content th { line-height: inherit; overflow-wrap: break-word; }
810
816
  .prose-content th { background: color-mix(in srgb, var(--theme-ink) 5%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--theme-ink) 15%, transparent); padding: 0.375rem 0.75rem; font-weight: 600; }
811
817
  .prose-content td { border-bottom: 1px solid color-mix(in srgb, var(--theme-ink) 10%, transparent); padding: 0.375rem 0.75rem; }
818
+ /* The chip's fill is its OWN, opaque colour (`--theme-code-fill`, ink at 8% over
819
+ * the palette's paper). It used to be `color-mix(… 8%, transparent)`, an ALPHA:
820
+ * whatever was painted behind the chip showed through, so a hovered block's tint
821
+ * changed the code's colour mid-hover and with it the code/chip contrast —
822
+ * measured on a real session in the browser: `#e4e9ed` at rest against
823
+ * `#dce2e5` with the hover tint behind it. One solved colour per palette also
824
+ * removes lightningcss's `color-mix` fallback, which was
825
+ * `background: var(--theme-ink)` — a solid ink slab with ink text on it. */
812
826
  .prose-content code.inline-code {
813
827
  font-family: 'Fira Code', monospace; font-size: 0.75rem;
814
828
  padding: 0.0125rem 0.275rem; border-radius: 0.375rem;
815
- background: color-mix(in srgb, var(--theme-ink) 8%, transparent);
829
+ background: var(--theme-code-fill);
816
830
  color: var(--theme-ink);
817
831
  overflow-wrap: break-word;
818
832
  }
@@ -10,6 +10,7 @@ import { readHandoverFromStdin } from '@/shared/lib/auth/handover';
10
10
  import { ssrRoutes } from '@/server/plugins/ssr';
11
11
  import { setListener } from '@/server/lib/lifecycle/listener';
12
12
  import { getDatabasePath } from '@/server/db.server';
13
+ import { initAgentTokens } from '@/server/lib/sessions/agent-token.server';
13
14
  import { logDetectedRegistry } from '@/server/lib/models/detected-registry.server';
14
15
  import { ompStartupError, ompStartupLogLines } from '@/server/lib/omp/core/startup';
15
16
  import { readInstanceRecord, removeInstanceRecord, writeInstanceRecord } from '@/server/lib/lifecycle/instance';
@@ -67,6 +68,7 @@ console.log(`[kabmo] mock mode: ${isMockMode() ? 'true (demo presets)' : 'f
67
68
  console.log(`[kabmo] ui auth: ${authNotice}${runPassword.source === 'argv' ? ' [from argv]' : ''}`);
68
69
  for (const line of ompStartupLogLines()) console.log(`[kabmo] ${line}`);
69
70
  console.log(`[kabmo] db: ${await getDatabasePath()}`);
71
+ await initAgentTokens();
70
72
 
71
73
  const port = Number(Bun.env.PORT) || 3000;
72
74
  const host = Bun.env.HOST || 'localhost';