@kabmo-labs/kabmo 0.24.0 → 0.26.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 +585 -512
  3. package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  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/code-surface/shiki.test.ts +82 -0
  13. package/src/client/components/common/code-surface/shiki.ts +28 -7
  14. package/src/client/components/common/session-actions-menu/index.tsx +59 -2
  15. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  16. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  17. package/src/client/components/common/session-branch/index.tsx +169 -0
  18. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  19. package/src/client/components/common/session-branch/style.ts +29 -0
  20. package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
  21. package/src/client/components/common/session-row/index.tsx +28 -3
  22. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  23. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  24. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  25. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
  26. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  27. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  28. package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
  29. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
  31. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
  32. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  33. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
  34. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
  35. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
  36. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
  37. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
  38. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  39. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
  40. package/src/client/components/settings/Sidebar.tsx +1 -1
  41. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  42. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  43. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  44. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  45. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  46. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  47. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  48. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
  49. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  50. package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
  51. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  52. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  53. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  55. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  56. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  58. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  59. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  60. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  61. package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
  62. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  63. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  64. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  65. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  66. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  67. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  68. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  69. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  70. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  71. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  72. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  73. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  74. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  75. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  76. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  77. package/src/client/data/settings/omp-schema.json +1 -1
  78. package/src/client/data/theme/terminal.test.ts +25 -0
  79. package/src/client/data/theme/terminal.ts +96 -79
  80. package/src/client/hooks/chat/composer/items.test.ts +31 -26
  81. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  82. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  83. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  84. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  85. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  86. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  87. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  88. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  89. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  90. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  91. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  92. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  93. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  94. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  95. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  96. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  97. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  98. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  99. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  100. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  101. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  102. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  103. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  104. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  105. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  106. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  107. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  108. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  109. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  110. package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
  111. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  112. package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
  113. package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
  114. package/src/client/hooks/chat/timeline/send.test.ts +3 -1
  115. package/src/client/hooks/chat/timeline/send.ts +48 -133
  116. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  117. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  118. package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
  119. package/src/client/hooks/models/use-harness-update.test.ts +286 -0
  120. package/src/client/hooks/models/use-harness-update.ts +250 -0
  121. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  122. package/src/client/hooks/ui/notifications.ts +45 -0
  123. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  124. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  125. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  126. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  127. package/src/client/lib/native/open-session.ts +33 -0
  128. package/src/client/lib/notifications/os.test.ts +125 -0
  129. package/src/client/lib/notifications/os.ts +130 -0
  130. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  131. package/src/client/lib/router/open-session.test.ts +75 -0
  132. package/src/client/lib/router/open-session.ts +34 -0
  133. package/src/client/lib/session-tree.test.ts +50 -0
  134. package/src/client/lib/session-tree.ts +59 -0
  135. package/src/client/lib/signals.ts +5 -1
  136. package/src/client/main.tsx +6 -0
  137. package/src/client/tailwind.css +17 -11
  138. package/src/server/index.ts +2 -0
  139. package/src/server/lib/auth/guard.ts +10 -0
  140. package/src/server/lib/btw/session-copy.server.ts +6 -44
  141. package/src/server/lib/btw/session-copy.test.ts +2 -1
  142. package/src/server/lib/db/schema.ts +5 -0
  143. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  144. package/src/server/lib/db/seed.test.ts +1 -1
  145. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  146. package/src/server/lib/harness/acp/background-work.ts +320 -0
  147. package/src/server/lib/harness/acp/calls.ts +15 -1
  148. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  149. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  150. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  151. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  152. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  153. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  154. package/src/server/lib/harness/acp/client.ts +33 -23
  155. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  156. package/src/server/lib/harness/acp/commands.ts +14 -2
  157. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  158. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  159. package/src/server/lib/harness/acp/frames.ts +71 -158
  160. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  161. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  162. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  163. package/src/server/lib/harness/acp/mapper.ts +12 -0
  164. package/src/server/lib/harness/acp/permissions.ts +6 -0
  165. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  166. package/src/server/lib/harness/acp/prompt.ts +19 -3
  167. package/src/server/lib/harness/acp/protocol.ts +41 -2
  168. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  169. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  170. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  171. package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
  172. package/src/server/lib/harness/acp/session-handshake.ts +110 -7
  173. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  174. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  175. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  176. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  177. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  178. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  179. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  180. package/src/server/lib/harness/acp/session-requests.ts +89 -0
  181. package/src/server/lib/harness/acp/session-turns.ts +28 -8
  182. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  183. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  184. package/src/server/lib/harness/acp/session.test-util.ts +42 -2
  185. package/src/server/lib/harness/acp/session.ts +115 -115
  186. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  187. package/src/server/lib/harness/acp/turn.test.ts +183 -0
  188. package/src/server/lib/harness/acp/turn.ts +102 -10
  189. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  190. package/src/server/lib/harness/acp/v2.ts +220 -0
  191. package/src/server/lib/harness/acp/verbs.ts +58 -8
  192. package/src/server/lib/harness/launch.test.ts +25 -0
  193. package/src/server/lib/harness/launch.ts +24 -10
  194. package/src/server/lib/harness/session.ts +3 -0
  195. package/src/server/lib/harness/spawn.server.ts +15 -2
  196. package/src/server/lib/harness/update-job-store.test.ts +151 -0
  197. package/src/server/lib/harness/update-job-store.ts +115 -0
  198. package/src/server/lib/harness/update-job.server.ts +94 -0
  199. package/src/server/lib/harness/update-queue.server.ts +292 -0
  200. package/src/server/lib/harness/update-queue.test.ts +265 -0
  201. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  202. package/src/server/lib/harness/update-worker.test.ts +153 -0
  203. package/src/server/lib/harness/update-worker.ts +202 -0
  204. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  205. package/src/server/lib/lifecycle/paths.ts +28 -0
  206. package/src/server/lib/omp/rpc/manager.ts +5 -5
  207. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  208. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  209. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  210. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  211. package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
  212. package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
  213. package/src/server/lib/omp/session/delete.server.ts +5 -0
  214. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  215. package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
  216. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  217. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  218. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  219. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  220. package/src/server/lib/sessions/answers.server.ts +37 -0
  221. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  222. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  223. package/src/server/lib/sessions/fork.server.test.ts +277 -0
  224. package/src/server/lib/sessions/fork.server.ts +329 -0
  225. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  226. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  227. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  228. package/src/server/lib/sessions/notify.server.ts +212 -0
  229. package/src/server/lib/sessions/relation-types.ts +76 -0
  230. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  231. package/src/server/lib/sessions/relations.server.ts +337 -0
  232. package/src/server/lib/sessions/resolve.server.ts +106 -0
  233. package/src/server/lib/sessions/schema.server.ts +82 -0
  234. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  235. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  236. package/src/server/lib/sessions/spawn.server.test.ts +237 -0
  237. package/src/server/lib/sessions/spawn.server.ts +335 -0
  238. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  239. package/src/server/lib/terminal/output.test.ts +2 -2
  240. package/src/server/lib/terminal/output.ts +1 -1
  241. package/src/server/lib/terminal/resize.test.ts +99 -0
  242. package/src/server/lib/terminal/runtime.server.ts +26 -6
  243. package/src/server/lib/terminal/send-result.test.ts +18 -1
  244. package/src/server/lib/terminal/send-result.ts +26 -2
  245. package/src/server/lib/terminal/session.server.ts +6 -6
  246. package/src/server/lib/usage/new-api.test.ts +92 -0
  247. package/src/server/lib/usage/new-api.ts +131 -0
  248. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  249. package/src/server/lib/usage/provider-key.ts +33 -0
  250. package/src/server/lib/usage/providers.server.ts +10 -3
  251. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  252. package/src/server/lib/usage/vendor-http.ts +41 -0
  253. package/src/server/lib/usage/window.ts +55 -0
  254. package/src/server/routes/agent/command.ts +14 -1
  255. package/src/server/routes/agent/harness-command.ts +12 -5
  256. package/src/server/routes/agent/new.ts +15 -0
  257. package/src/server/routes/chat/stream.ts +7 -2
  258. package/src/server/routes/harness/add-provider.test.ts +9 -1
  259. package/src/server/routes/harness/import-action.ts +4 -0
  260. package/src/server/routes/harness/import.test.ts +1 -1
  261. package/src/server/routes/harness/index.ts +5 -1
  262. package/src/server/routes/harness/update-status.ts +32 -0
  263. package/src/server/routes/harness/update.test.ts +156 -0
  264. package/src/server/routes/harness/update.ts +64 -147
  265. package/src/server/routes/sessions/answer.ts +24 -0
  266. package/src/server/routes/sessions/batch-delete.ts +11 -5
  267. package/src/server/routes/sessions/body-readers.ts +43 -0
  268. package/src/server/routes/sessions/delete.ts +4 -2
  269. package/src/server/routes/sessions/fork.ts +89 -0
  270. package/src/server/routes/sessions/index.ts +14 -0
  271. package/src/server/routes/sessions/relations.ts +85 -0
  272. package/src/server/routes/sessions/routes.test.ts +1 -2
  273. package/src/server/routes/sessions/session.ts +23 -0
  274. package/src/server/routes/sessions/spawn.ts +137 -0
  275. package/src/server/routes/terminal/ws.ts +3 -3
  276. package/src/shared/lib/chat/composer/client.ts +31 -2
  277. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  278. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  279. package/src/shared/lib/chat/notice-text.ts +1 -1
  280. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  281. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  282. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  283. package/src/shared/lib/code/ansi.ts +1 -1
  284. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  285. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  286. package/src/shared/lib/harness/mode-signal.ts +20 -0
  287. package/src/shared/lib/harness/provider-facts.test.ts +27 -0
  288. package/src/shared/lib/harness/providers.ts +35 -1
  289. package/src/shared/lib/harness/session-modes.ts +24 -0
  290. package/src/shared/lib/harness/update-job.ts +80 -0
  291. package/src/shared/lib/harness/update-plan.test.ts +21 -6
  292. package/src/shared/lib/harness/update-plan.ts +12 -4
  293. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  294. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  295. package/src/shared/lib/notifications/outcomes.ts +64 -0
  296. package/src/shared/lib/notifications/settings.test.ts +49 -0
  297. package/src/shared/lib/notifications/settings.ts +34 -0
  298. package/src/shared/lib/omp/session/default-title.ts +5 -4
  299. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  300. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  301. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  302. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  303. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  304. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  305. package/src/shared/lib/settings/defaults.ts +3 -0
  306. package/src/shared/lib/theme/catalog.test.ts +13 -9
  307. package/src/shared/lib/theme/color.test.ts +2 -2
  308. package/src/shared/lib/theme/color.ts +4 -4
  309. package/src/shared/lib/theme/theme.test.ts +1 -1
  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 +89 -0
  316. package/src/shared/types/omp/agent.ts +19 -2
  317. package/src/shared/types/realtime.ts +2 -0
  318. package/src/shared/types/settings/state.ts +10 -0
  319. package/src/shared/types/workspace.ts +8 -0
  320. package/src/test-support/fake-omp-fork.ts +16 -2
  321. package/src/test-support/harness-table.test-util.ts +31 -1
  322. package/dist/client/static/js/index-z3w7n85q.css +0 -1
  323. package/src/client/components/common/subagent-list/index.tsx +0 -165
  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,233 @@
1
+ // `kabmo session` — the agent-facing half of the console.
2
+ //
3
+ // Every command talks to the SAME HTTP routes the browser uses, with the
4
+ // per-session bearer token injected at spawn. No second API and no direct
5
+ // database access: an agent must be able to do exactly what a tab can.
6
+ //
7
+ // Usage:
8
+ // kabmo session spawn --prompt-file - [--parent-self] [--harness <id>] [--model <provider/model>] [--thinking <level>] [--json]
9
+ // kabmo session fork <source-id> [--anchor-entry <id>] [--prompt-file -] [--json]
10
+ // kabmo session tell <id> --message-file - [--json]
11
+ // kabmo session relations <id> [--json]
12
+ // kabmo session output <id> [--json]
13
+ // kabmo session wait <id> [--timeout 600] [--json]
14
+
15
+ import { readFileSync } from 'node:fs';
16
+ import { fail, log, ok, printJson, isJson } from '@/cli/lib/output.js';
17
+
18
+ const SERVER_URL = () => Bun.env.KABMO_SERVER_URL || 'http://localhost:3000';
19
+ const AGENT_TOKEN = () => Bun.env.KABMO_AGENT_TOKEN || '';
20
+
21
+ function usage() {
22
+ return `Usage: kabmo session <command> [options]
23
+
24
+ COMMANDS:
25
+ spawn Create a child session (requires --prompt/-file)
26
+ fork <source-id> Branch a session at an entry (or its tip)
27
+ tell <id> Send a prompt to a session
28
+ relations <id> Print the parent, children, forks and owner
29
+ output <id> Print the session's last assistant answer
30
+ wait <id> Wait until the session is idle (default 600s)
31
+
32
+ OPTIONS:
33
+ --prompt <text> First prompt (spawn/fork)
34
+ --prompt-file <path> Read it from a file; '-' reads stdin
35
+ --message <text> Message (tell)
36
+ --message-file <path> Read it from a file; '-' reads stdin
37
+ --parent-self Parent the new session to this agent's session
38
+ --harness <id> Harness for the child (omp-rpc, claude, codex, ...)
39
+ --model <provider/model> Pin the child's model; omit for the harness default
40
+ --thinking <level> Pin the child's thinking/effort level
41
+ --cwd <path> Working directory (defaults to the parent's)
42
+ --anchor-entry <id> Fork at this entry instead of the tip
43
+ --timeout <seconds> wait's deadline (default 600)
44
+ --json Machine-readable output
45
+ `;
46
+ }
47
+
48
+ function readText(options, inlineKey, fileKey) {
49
+ const inline = options[inlineKey];
50
+ const file = options[fileKey];
51
+ if (inline && file) fail(`Use --${inlineKey} or --${fileKey}, not both.`);
52
+ if (typeof inline === 'string') return inline;
53
+ if (typeof file !== 'string') fail(`--${inlineKey} or --${fileKey} is required.`);
54
+ if (file === '-') {
55
+ // Bun.stdin.text() is the CLI's own stdin; `session spawn` is normally run
56
+ // by an agent with a heredoc, never interactively.
57
+ return Bun.stdin.text();
58
+ }
59
+ try {
60
+ return readFileSync(file, 'utf8');
61
+ } catch (cause) {
62
+ fail(`Could not read ${file}: ${cause.message}`);
63
+ }
64
+ }
65
+
66
+ async function call(path, init = {}) {
67
+ const token = AGENT_TOKEN();
68
+ const base = SERVER_URL();
69
+ const request = (origin) => fetch(`${origin}${path}`, {
70
+ ...init,
71
+ headers: {
72
+ 'content-type': 'application/json',
73
+ ...(token ? { authorization: `Bearer ${token}` } : {}),
74
+ ...(init.headers ?? {}),
75
+ },
76
+ });
77
+ let response;
78
+ try {
79
+ response = await request(base);
80
+ } catch (cause) {
81
+ // localhost may resolve to ::1 while the operator wrote 127.0.0.1 (or the
82
+ // reverse). Try the other loopback spelling before reporting a dead server.
83
+ const alternate = alternateLoopback(base);
84
+ if (!alternate) fail(`Could not reach Kabmo at ${base}: ${cause.message}`);
85
+ try {
86
+ response = await request(alternate);
87
+ } catch {
88
+ fail(`Could not reach Kabmo at ${base}: ${cause.message}`);
89
+ }
90
+ }
91
+ const body = await response.json().catch(() => null);
92
+ if (!response.ok) {
93
+ fail(body?.error ?? `${response.status} ${response.statusText}`);
94
+ }
95
+ return body;
96
+ }
97
+
98
+ /** The other loopback spelling, or null for a non-loopback host. */
99
+ function alternateLoopback(base) {
100
+ try {
101
+ const url = new URL(base);
102
+ const host = url.hostname;
103
+ if (host === '127.0.0.1') url.hostname = 'localhost';
104
+ else if (host === 'localhost' || host === '::1' || host === '[::1]') url.hostname = '127.0.0.1';
105
+ else return null;
106
+ return url.origin;
107
+ } catch {
108
+ return null;
109
+ }
110
+ }
111
+
112
+ async function spawn(options) {
113
+ const prompt = await readText(options, 'prompt', 'prompt-file');
114
+ const model = typeof options.model === 'string' && options.model.trim()
115
+ ? modelSelection(options.model.trim())
116
+ : null;
117
+ const body = await call('/api/sessions/spawn', {
118
+ method: 'POST',
119
+ body: JSON.stringify({
120
+ prompt: prompt.trim(),
121
+ ...(options['parent-self'] ? { parentSelf: true } : {}),
122
+ ...(options.harness ? { harness: options.harness } : {}),
123
+ ...(model ? { model } : {}),
124
+ ...(options.thinking ? { thinkingLevel: options.thinking } : {}),
125
+ ...(options.cwd ? { cwd: options.cwd } : {}),
126
+ }),
127
+ });
128
+ if (isJson()) return printJson(body);
129
+ ok(`Spawned ${body.sessionId} (${body.harness}, depth ${body.depth})`);
130
+ log(body.sessionId);
131
+ }
132
+
133
+ /** `provider/model` as the spawn route stores it. A bare value keeps an empty
134
+ * provider: an ACP agent matches its own `modelId`, and omp resolves its own. */
135
+ function modelSelection(value) {
136
+ const slash = value.indexOf('/');
137
+ return slash > 0
138
+ ? { provider: value.slice(0, slash), modelId: value.slice(slash + 1) }
139
+ : { provider: '', modelId: value };
140
+ }
141
+
142
+ async function fork(options, sourceId) {
143
+ if (!sourceId) fail('fork needs a source session id.');
144
+ const prompt = options.prompt || options['prompt-file']
145
+ ? (await readText(options, 'prompt', 'prompt-file')).trim()
146
+ : '';
147
+ const body = await call(`/api/sessions/${encodeURIComponent(sourceId)}/fork`, {
148
+ method: 'POST',
149
+ body: JSON.stringify({
150
+ ...(options['anchor-entry'] ? { anchorEntryId: options['anchor-entry'] } : {}),
151
+ ...(prompt ? { prompt } : {}),
152
+ }),
153
+ });
154
+ if (isJson()) return printJson(body);
155
+ ok(`Forked ${sourceId} → ${body.sessionId}`);
156
+ log(body.sessionId);
157
+ }
158
+
159
+ async function tell(options, sessionId) {
160
+ if (!sessionId) fail('tell needs a session id.');
161
+ const message = (await readText(options, 'message', 'message-file')).trim();
162
+ const body = await call(`/api/agent/${encodeURIComponent(sessionId)}`, {
163
+ method: 'POST',
164
+ body: JSON.stringify({ type: 'prompt', message }),
165
+ });
166
+ if (isJson()) return printJson(body);
167
+ ok(`Sent to ${sessionId}`);
168
+ }
169
+
170
+ async function relations(options, sessionId) {
171
+ if (!sessionId) fail('relations needs a session id.');
172
+ const body = await call(`/api/sessions/${encodeURIComponent(sessionId)}/relations`);
173
+ if (isJson()) return printJson(body);
174
+ log(`parent: ${body.parent?.sessionId ?? '—'}`);
175
+ log(`children: ${body.children.map((row) => row.sessionId).join(', ') || '—'}`);
176
+ log(`forks: ${body.forks.map((row) => row.sessionId).join(', ') || '—'}`);
177
+ log(`owner: ${body.lifecycleOwner?.sessionId ?? '—'}`);
178
+ }
179
+
180
+ async function wait(options, sessionId) {
181
+ if (!sessionId) fail('wait needs a session id.');
182
+ const deadline = Date.now() + (Number(options.timeout ?? 600) * 1000);
183
+ const interval = Number(Bun.env.KABMO_WAIT_INTERVAL_MS ?? 2000);
184
+ let state = { running: true };
185
+ while (Date.now() < deadline) {
186
+ state = await call(`/api/agent/${encodeURIComponent(sessionId)}`);
187
+ if (state?.running !== true) break;
188
+ await Bun.sleep(interval);
189
+ }
190
+ if (state?.running === true) fail(`Timed out waiting for ${sessionId}.`);
191
+ if (isJson()) return printJson(state);
192
+ ok(`${sessionId} is idle`);
193
+ }
194
+
195
+ async function output(options, sessionId) {
196
+ if (!sessionId) fail('output needs a session id.');
197
+ const body = await call(`/api/chat/${encodeURIComponent(sessionId)}`);
198
+ if (isJson()) return printJson(body);
199
+ const messages = body?.session?.messages ?? [];
200
+ const assistant = [...messages].reverse().find((message) => message.role === 'assistant' || message.role === 'ai');
201
+ if (assistant?.content) {
202
+ log(assistant.content);
203
+ return;
204
+ }
205
+ // ACP keeps its history with the agent; Kabmo stores the last closed answer
206
+ // precisely so this command still has something to print.
207
+ const stored = await call(`/api/sessions/${encodeURIComponent(sessionId)}/answer`);
208
+ log(stored?.answer ?? 'No assistant answer recorded.');
209
+ }
210
+
211
+ export async function run(options) {
212
+ const [subcommand, ...args] = options.args ?? [];
213
+ if (!subcommand || options.help) {
214
+ process.stdout.write(usage());
215
+ return;
216
+ }
217
+ switch (subcommand) {
218
+ case 'spawn':
219
+ return spawn(options);
220
+ case 'fork':
221
+ return fork(options, args[0]);
222
+ case 'tell':
223
+ return tell(options, args[0]);
224
+ case 'relations':
225
+ return relations(options, args[0]);
226
+ case 'output':
227
+ return output(options, args[0]);
228
+ case 'wait':
229
+ return wait(options, args[0]);
230
+ default:
231
+ fail(`Unknown session command: ${subcommand}\n${usage()}`);
232
+ }
233
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The CLI is a thin client: these cases prove it sends the right path, body and
8
+ * bearer token, not that the server handles them (route tests own that).
9
+ */
10
+
11
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
12
+ import { run } from './session.js';
13
+
14
+ let server;
15
+ let captured;
16
+ let waitCalls;
17
+ let savedUrl;
18
+ let savedToken;
19
+
20
+ beforeEach(() => {
21
+ captured = [];
22
+ waitCalls = 0;
23
+ savedUrl = Bun.env.KABMO_SERVER_URL;
24
+ savedToken = Bun.env.KABMO_AGENT_TOKEN;
25
+ server = Bun.serve({
26
+ port: 0,
27
+ async fetch(request) {
28
+ const body = request.method === 'POST' ? await request.json().catch(() => null) : null;
29
+ captured.push({
30
+ url: new URL(request.url).pathname,
31
+ method: request.method,
32
+ authorization: request.headers.get('authorization'),
33
+ body,
34
+ });
35
+ if (request.url.endsWith('/api/agent/w')) {
36
+ waitCalls += 1;
37
+ return Response.json({ running: waitCalls < 2 });
38
+ }
39
+ if (request.url.includes('/fork')) {
40
+ return Response.json({ sessionId: 'child', sourceSessionId: 'root', originKind: 'fork' });
41
+ }
42
+ if (request.url.endsWith('/api/sessions/spawn')) {
43
+ return Response.json({ sessionId: 'child', harness: 'omp-rpc', parentSessionId: 'root', depth: 1 });
44
+ }
45
+ return Response.json({ ok: true });
46
+ },
47
+ });
48
+ Bun.env.KABMO_SERVER_URL = `http://127.0.0.1:${server.port}`;
49
+ Bun.env.KABMO_AGENT_TOKEN = 'agent-token';
50
+ });
51
+
52
+ afterEach(() => {
53
+ server.stop(true);
54
+ if (savedUrl === undefined) delete Bun.env.KABMO_SERVER_URL;
55
+ else Bun.env.KABMO_SERVER_URL = savedUrl;
56
+ if (savedToken === undefined) delete Bun.env.KABMO_AGENT_TOKEN;
57
+ else Bun.env.KABMO_AGENT_TOKEN = savedToken;
58
+ });
59
+
60
+ describe('kabmo session', () => {
61
+ test('spawn sends parentSelf and the token', async () => {
62
+ await run({ args: ['spawn'], prompt: 'review this', 'parent-self': true, harness: 'codex', json: true });
63
+ expect(captured).toEqual([
64
+ {
65
+ url: '/api/sessions/spawn',
66
+ method: 'POST',
67
+ authorization: 'Bearer agent-token',
68
+ body: { prompt: 'review this', parentSelf: true, harness: 'codex' },
69
+ },
70
+ ]);
71
+ });
72
+
73
+ test('fork sends the anchor and no empty prompt', async () => {
74
+ await run({ args: ['fork', 'root'], 'anchor-entry': 'a1', json: true });
75
+ expect(captured[0]).toMatchObject({
76
+ url: '/api/sessions/root/fork',
77
+ method: 'POST',
78
+ body: { anchorEntryId: 'a1' },
79
+ });
80
+ });
81
+
82
+ test('tell posts the prompt command to the agent route', async () => {
83
+ await run({ args: ['tell', 'child'], message: 'hello', json: true });
84
+ expect(captured[0]).toMatchObject({
85
+ url: '/api/agent/child',
86
+ method: 'POST',
87
+ body: { type: 'prompt', message: 'hello' },
88
+ });
89
+ });
90
+
91
+ test('wait polls until the session is idle', async () => {
92
+ const savedInterval = Bun.env.KABMO_WAIT_INTERVAL_MS;
93
+ Bun.env.KABMO_WAIT_INTERVAL_MS = '1';
94
+ try {
95
+ await run({ args: ['wait', 'w'], timeout: 5, json: true });
96
+ } finally {
97
+ if (savedInterval === undefined) delete Bun.env.KABMO_WAIT_INTERVAL_MS;
98
+ else Bun.env.KABMO_WAIT_INTERVAL_MS = savedInterval;
99
+ }
100
+ expect(waitCalls).toBe(2);
101
+ expect(captured.map((entry) => entry.url)).toEqual(['/api/agent/w', '/api/agent/w']);
102
+ });
103
+ });
package/src/cli/main.js CHANGED
@@ -16,7 +16,7 @@ import { migrateLegacyDataDir } from '@/server/lib/lifecycle/paths';
16
16
 
17
17
  const { version } = packageJson;
18
18
 
19
- const COMMANDS = ['serve', 'update', 'stop', 'restart', 'status', 'doctor', 'logs', 'plugin'];
19
+ const COMMANDS = ['serve', 'update', 'stop', 'restart', 'status', 'doctor', 'logs', 'plugin', 'session'];
20
20
 
21
21
  export async function runCli(bin = 'kabmo') {
22
22
  const { command, positionals, options, unknown } = parseArgs(process.argv.slice(2));
@@ -120,6 +120,9 @@ export function ComposerPicker({
120
120
  <span className="truncate">
121
121
  <OptionName item={item} />
122
122
  </span>
123
+ {item.source === 'harness' && (
124
+ <span className="text-ink/40 text-[10px] uppercase shrink-0">harness</span>
125
+ )}
123
126
  {item.source === 'file' && (
124
127
  <span className="text-ink/40 text-[10px] uppercase shrink-0">file</span>
125
128
  )}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The tokenizer's long-line guard, per language.
8
+ *
9
+ * Markdown's grammar backtracks superlinearly on a long prose line (see
10
+ * `LINE_CHAR_LIMITS` in `shiki.ts`), which is why the guard is tighter than the
11
+ * minified-bundle default. The rule is silent when it regresses — a viewport
12
+ * simply costs seconds — so the guard is asserted through a mounted view: the
13
+ * short line paints `shiki-tok` spans, the long one stays plain text.
14
+ */
15
+
16
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
17
+ import { EditorState } from '@codemirror/state';
18
+ import { EditorView } from '@codemirror/view';
19
+ import { Window } from 'happy-dom';
20
+
21
+ import { shikiHighlight } from '@/client/components/common/code-surface/shiki';
22
+ import { bootSyntax, getHighlighterSync } from '@/shared/lib/code/highlighter';
23
+ import { ensureLanguage } from '@/shared/lib/code/highlighter-lazy';
24
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
25
+
26
+ const EXTRA_GLOBALS = ['MutationObserver', 'ResizeObserver'] as const;
27
+ const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
28
+
29
+ beforeAll(async () => {
30
+ const win = new Window({ url: 'http://localhost' });
31
+ installDomGlobals(win);
32
+ const target = globalThis as unknown as Record<string, unknown>;
33
+ for (const key of EXTRA_GLOBALS) {
34
+ native[key] = target[key];
35
+ target[key] = (win as unknown as Record<string, unknown>)[key];
36
+ }
37
+ await bootSyntax();
38
+ const highlighter = getHighlighterSync();
39
+ if (highlighter) await ensureLanguage(highlighter, 'markdown');
40
+ });
41
+
42
+ afterAll(() => {
43
+ const target = globalThis as unknown as Record<string, unknown>;
44
+ for (const key of EXTRA_GLOBALS) {
45
+ if (native[key] === undefined) delete target[key];
46
+ else target[key] = native[key];
47
+ }
48
+ restoreDomGlobals();
49
+ });
50
+
51
+ /** `- **bold** words …`, padded past the guard so the grammar would pay for it. */
52
+ function longMarkdownLine(): string {
53
+ return `- **${'bold words '.repeat(120)}** tail`;
54
+ }
55
+
56
+ function mountMarkdown(doc: string): { view: EditorView; host: HTMLElement } {
57
+ const host = document.body.appendChild(document.createElement('div'));
58
+ const view = new EditorView({
59
+ parent: host,
60
+ state: EditorState.create({ doc, extensions: [shikiHighlight('markdown')] }),
61
+ });
62
+ return { view, host };
63
+ }
64
+
65
+ describe('markdown long-line guard', () => {
66
+ test('a line past the guard renders plain while a short line still tokenizes', () => {
67
+ const long = longMarkdownLine();
68
+ expect(long.length).toBeGreaterThanOrEqual(1_000);
69
+
70
+ const { view, host } = mountMarkdown(['short **bold** line', long].join('\n'));
71
+ try {
72
+ const lines = host.querySelectorAll<HTMLElement>('.cm-line');
73
+ expect(lines.length).toBe(2);
74
+ expect(lines[0].querySelectorAll('.shiki-tok').length).toBeGreaterThan(0);
75
+ expect(lines[1].textContent).toBe(long);
76
+ expect(lines[1].querySelectorAll('.shiki-tok').length).toBe(0);
77
+ } finally {
78
+ view.destroy();
79
+ host.remove();
80
+ }
81
+ });
82
+ });
@@ -18,9 +18,10 @@
18
18
  * window that opens inside a block comment or a template literal still
19
19
  * tokenizes as one. Measured: 2.1 ms per keystroke at 20 000 lines, flat,
20
20
  * because the window is ~100 lines whatever the document is.
21
- * - **A line at or past `MAX_LINE_CHARS` is left plain.** A minified bundle is
22
- * one line of hundreds of KB, and tokenizing it on every scroll is what makes
23
- * an editor feel dead.
21
+ * - **A line at or past the language's guard is left plain.** A minified bundle
22
+ * is one line of hundreds of KB, and tokenizing it on every scroll is what
23
+ * makes an editor feel dead. Markdown gets a tighter guard because its
24
+ * grammar's own cost grows with the spans on a line — see `LINE_CHAR_LIMITS`.
24
25
  *
25
26
  * The colours are NOT inline. Every token carries Shiki's two custom properties
26
27
  * (`--shiki-light` / `--shiki-dark`) and `theme.ts` picks one through
@@ -38,8 +39,27 @@ import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
38
39
  /** Lines tokenized above the viewport, to seed the grammar's own state. */
39
40
  const CONTEXT_LINES = 40;
40
41
 
41
- /** Lines at or above this length render as plain text (see the module note). */
42
- const MAX_LINE_CHARS = 12_000;
42
+ /**
43
+ * Lines at or above this length render as plain text (see the module note).
44
+ *
45
+ * The default is the minified-bundle guard: one line of hundreds of KB is not
46
+ * worth tokenizing on every scroll.
47
+ */
48
+ const DEFAULT_LINE_CHARS = 12_000;
49
+
50
+ /**
51
+ * Per-language tighter guards, for grammars whose own rules make a long line far
52
+ * more expensive than its length suggests.
53
+ *
54
+ * Markdown is the measured case. Its `bold`/`italic` rules are nested
55
+ * lookarounds, and with Shiki's JS regex engine the cost grows with the number
56
+ * of spans on the line: measured on `.wiki/App-Shell-and-Layout.md`, tokenizing
57
+ * one 140-line viewport took **6.3 s** at the default cap (4 100 ms at 4 000,
58
+ * 500 ms at 2 000) and **12–38 ms** once lines of 1 000+ characters are left
59
+ * plain. Those are exactly the prose bullets the wiki is written in, which is
60
+ * why opening a markdown diff felt broken while a code diff did not.
61
+ */
62
+ const LINE_CHAR_LIMITS: Record<string, number> = { markdown: 1_000 };
43
63
 
44
64
  /** Marks are shared by their style string: a file has a few dozen distinct ones. */
45
65
  const markCache = new Map<string, Decoration>();
@@ -94,6 +114,7 @@ function buildDecorations(
94
114
  if (!highlighter || language === 'text' || !requestLanguage(language)) return Decoration.none;
95
115
 
96
116
  const doc = view.state.doc;
117
+ const lineLimit = LINE_CHAR_LIMITS[language] ?? DEFAULT_LINE_CHARS;
97
118
  const firstLine = doc.lineAt(view.viewport.from).number;
98
119
  const lastLine = doc.lineAt(view.viewport.to).number;
99
120
  const contextStart = Math.max(1, firstLine - CONTEXT_LINES);
@@ -110,7 +131,7 @@ function buildDecorations(
110
131
  // the pair is a plain string map, which is what it accepts at runtime.
111
132
  themes: themes as unknown as Record<string, string>,
112
133
  defaultColor: false,
113
- tokenizeMaxLineLength: MAX_LINE_CHARS,
134
+ tokenizeMaxLineLength: lineLimit,
114
135
  }).tokens as typeof tokenized;
115
136
  } catch {
116
137
  // A grammar the engine refuses (or a Shiki internal): plain text is the
@@ -121,7 +142,7 @@ function buildDecorations(
121
142
  const builder = new RangeSetBuilder<Decoration>();
122
143
  for (let index = 0; index < tokenized.length && index < lines.length; index++) {
123
144
  const line = doc.line(contextStart + index);
124
- if (line.length >= MAX_LINE_CHARS) continue;
145
+ if (line.length >= lineLimit) continue;
125
146
  let offset = 0;
126
147
  for (const token of tokenized[index]) {
127
148
  const length = token.content.length;
@@ -28,7 +28,12 @@
28
28
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
29
29
  import type { TargetedMouseEvent } from 'preact';
30
30
  import { createPortal } from 'preact/compat';
31
- import { Archive, ArchiveRestore, Hourglass, Pencil, Trash2, WandSparkles } from 'lucide-preact';
31
+ import { Archive, ArchiveRestore, GitBranch, Hourglass, Pencil, Trash2, WandSparkles } from 'lucide-preact';
32
+ import { useSearchParams } from '@/client/lib/router/search-params';
33
+ import { startPendingSession } from '@/client/hooks/chat/omp/pending-sessions';
34
+ import { expandSessionBranch } from '@/client/hooks/workspace/expanded-sessions';
35
+ import { setHarnessPick } from '@/client/hooks/chat/timeline/session-harness';
36
+ import { formatNewSessionTitle } from '@/shared/lib/omp/session/default-title';
32
37
 
33
38
  /** Viewport coordinates the menu hangs off, plus which edge it aligns to. */
34
39
  export interface MenuAnchor {
@@ -82,6 +87,12 @@ export function useRowMenu(): RowMenuHandle {
82
87
 
83
88
  export interface SessionActionsMenuProps {
84
89
  anchor: MenuAnchor;
90
+ /** The row's id; enables "New child session". Absent on a synthetic row. */
91
+ sessionId?: string | number;
92
+ /** The row's harness, so the child dialog starts on the agent that ran it. */
93
+ harness?: string;
94
+ /** The row's folder, so a pending child lands in the right workspace. */
95
+ folderId?: number | string;
85
96
  isArchived?: boolean;
86
97
  /** Omitted when the row cannot be renamed (a pending `new-…` chat). */
87
98
  onRename?: () => void;
@@ -102,6 +113,9 @@ export interface SessionActionsMenuProps {
102
113
 
103
114
  export function SessionActionsMenu({
104
115
  anchor,
116
+ sessionId,
117
+ harness,
118
+ folderId,
105
119
  isArchived = false,
106
120
  onRename,
107
121
  onRenameWithAi,
@@ -112,6 +126,36 @@ export function SessionActionsMenu({
112
126
  }: SessionActionsMenuProps) {
113
127
  const menuRef = useRef<HTMLDivElement>(null);
114
128
  const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
129
+ const [, setSearchParams] = useSearchParams();
130
+ const canSpawnChild =
131
+ sessionId !== undefined &&
132
+ !String(sessionId).startsWith('new-') &&
133
+ !isArchived;
134
+
135
+ /**
136
+ * "New child session" opens the SAME pending-chat composer as New Session,
137
+ * with the parent recorded on the row. A modal would have hid the workspace,
138
+ * worktree and parent pickers the composer already owns.
139
+ */
140
+ const startChildSession = () => {
141
+ if (sessionId === undefined) return;
142
+ const parentId = String(sessionId);
143
+ const pendingId = startPendingSession(folderId ?? null, {
144
+ parentSessionId: parentId,
145
+ ...(harness ? { harness } : {}),
146
+ title: formatNewSessionTitle(new Date(), 'New Child'),
147
+ });
148
+ // The picker's first tab is the parent's agent, not omp's default.
149
+ if (harness) setHarnessPick(pendingId, harness);
150
+ expandSessionBranch(parentId);
151
+ setSearchParams((prev) => {
152
+ const next = new URLSearchParams(prev);
153
+ next.set('sessionId', pendingId);
154
+ next.set('parentSessionId', parentId);
155
+ if (folderId !== undefined) next.set('folderId', String(folderId));
156
+ return next;
157
+ }, { replace: true });
158
+ };
115
159
 
116
160
  useLayoutEffect(() => {
117
161
  const el = menuRef.current;
@@ -148,6 +192,7 @@ export function SessionActionsMenu({
148
192
  };
149
193
 
150
194
  return createPortal(
195
+ <>
151
196
  <div
152
197
  className="fixed inset-0 z-[70]"
153
198
  onClick={onClose}
@@ -170,6 +215,17 @@ export function SessionActionsMenu({
170
215
  className="glass-popover fixed z-[70] w-44 bg-paper border border-ink/15 rounded-lg shadow-xl py-1 text-xs text-ink font-sans"
171
216
  onClick={(e) => e.stopPropagation()}
172
217
  >
218
+ {canSpawnChild && (
219
+ <button
220
+ type="button"
221
+ role="menuitem"
222
+ onClick={run(startChildSession)}
223
+ className="w-full text-left px-3 py-1.5 hover:bg-ink/5 flex items-center gap-2 transition-colors cursor-pointer"
224
+ >
225
+ <GitBranch size={12} className="text-ink/60" />
226
+ <span>New child session</span>
227
+ </button>
228
+ )}
173
229
  {onRename && (
174
230
  <button
175
231
  type="button"
@@ -235,7 +291,8 @@ export function SessionActionsMenu({
235
291
  </button>
236
292
  )}
237
293
  </div>
238
- </div>,
294
+ </div>
295
+ </>,
239
296
  document.body,
240
297
  );
241
298
  }