@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
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Updating ONE harness — and refusing where Kabmo must not act.
7
+ * Updating ONE harness — as a BACKGROUND job, and refusing where Kabmo must not act.
8
8
  *
9
9
  * Three mechanisms, and the refusal is as much of the feature as the button:
10
10
  *
@@ -21,103 +21,65 @@
21
21
  * **An adapter is TWO installs.** `claude` is `@agentclientprotocol/claude-agent-acp`
22
22
  * (the number the probe reports) on top of the `claude` CLI, and they move
23
23
  * independently — measured here: adapter 0.100.0 under CLI 2.1.318. So one press
24
- * moves EVERY part that is behind and none that is current:
24
+ * moves EVERY part that is behind and none that is current. The decision itself
25
+ * is pure (`planHarnessUpdate`); this route only resolves the facts it needs and
26
+ * hands the argv to the worker.
25
27
  *
26
- * - both behind → `npm i -g <adapter>@<latest>` then `claude update`;
27
- * - only the CLI → `claude update`, with no adapter install at all;
28
- * - only the adapter → the npm install alone.
29
- *
30
- * Running both unconditionally was the first shape, and it reinstalled an adapter
31
- * that was already current while reporting "updated to 0.101.0" about a version
32
- * that never moved.
33
- *
34
- * Every run is a POST that answers plain JSON, not an SSE stream: an npm install
35
- * of one package, or one `upgrade` subcommand, is seconds rather than the minutes
36
- * `omp update` and the Kabmo self-update take. If one of these grows long enough
37
- * to need streaming, it should reuse `updates/apply.ts` rather than grow a second
38
- * progress protocol here.
28
+ * **The route does not run the installs.** They used to run here, inside the POST:
29
+ * the request stayed open for minutes, a reload forgot the run, and a five-minute
30
+ * child timeout could kill `npm install -g` halfway through writing a package
31
+ * tree — the corruption this design removes. The run is a detached worker
32
+ * (`update-worker.ts`) that writes progress to `harness-update.json`; this route
33
+ * answers `202` in milliseconds and `GET /api/harness/update/status` reports the
34
+ * outcome. A second press while one runs is a `409`, read from that same record,
35
+ * so a reloaded page cannot start a competing install.
39
36
  */
40
37
 
41
- import { json } from '@/server/lib/remix-compat';
38
+ import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
42
39
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
43
40
  import { methodNotAllowed } from '@/server/lib/route-adapter';
44
41
  import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
45
- import { harnessUpdateFacts, latestSourceFor, type HarnessUpdateFacts } from '@/shared/lib/harness/updates';
46
- import { forgetProbe, loadProbes } from '@/server/lib/harness/probe-cache.server';
47
- import { forgetCliVersion, harnessVersionState } from '@/server/lib/harness/update-state.server';
48
- import { planHarnessUpdate, repointAdapterLaunch, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
49
- import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/config.server';
42
+ import { harnessUpdateFacts, latestSourceFor } from '@/shared/lib/harness/updates';
43
+ import { loadProbes } from '@/server/lib/harness/probe-cache.server';
44
+ import { harnessVersionState, type HarnessVersionState } from '@/server/lib/harness/update-state.server';
45
+ import { planHarnessUpdate, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
50
46
  import { resolveOmpBin } from '@/server/lib/omp/core/cli';
51
- import { harnessVersionRows } from '@/server/routes/harness/versions';
52
-
53
- /** Longest one update may run before it is killed and reported as a timeout. */
54
- const UPDATE_TIMEOUT_MS = 5 * 60_000;
47
+ import {
48
+ startHarnessUpdateJob,
49
+ unfinishedUpdateJob,
50
+ } from '@/server/lib/harness/update-job.server';
51
+ import { jobQueued } from '@/shared/lib/harness/update-job';
55
52
 
56
- /** The result the UI reports, in the agent's own terms. */
53
+ /** The answer to a press that has nothing to move, still plain JSON. */
57
54
  interface HarnessUpdateOutcome {
58
55
  success: boolean;
59
56
  id: string;
60
57
  message: string;
61
- /** The commands that ran, so the reader can repeat them themselves. */
62
- command?: string;
63
- /** The tail of their output — what actually failed, when it failed. */
64
- output?: string;
65
- }
66
-
67
- /** Run a command, capturing its combined output for the report. */
68
- async function run(command: string[], cwd?: string): Promise<{ code: number | null; output: string }> {
69
- const proc = Bun.spawn({
70
- cmd: command,
71
- stdin: 'ignore',
72
- stdout: 'pipe',
73
- stderr: 'pipe',
74
- timeout: UPDATE_TIMEOUT_MS,
75
- env: { ...Bun.env, PAGER: 'cat', FORCE_COLOR: '0' },
76
- ...(cwd ? { cwd } : {}),
77
- });
78
- const [stdout, stderr] = await Promise.all([
79
- new Response(proc.stdout).text(),
80
- new Response(proc.stderr).text(),
81
- ]);
82
- const code = await proc.exited;
83
- return { code, output: [stdout, stderr].filter(Boolean).join('\n').trim() };
84
58
  }
85
59
 
86
- /** The last few lines of a run, which is where a failure explains itself. */
87
- function tail(output: string, lines = 12): string {
88
- const all = output.split('\n');
89
- return all.slice(Math.max(0, all.length - lines)).join('\n').trim();
60
+ /** A readable description of the numbers currently on disk, for "already current". */
61
+ function currentParts(state: HarnessVersionState, cliName: string | undefined): string {
62
+ return [
63
+ state.agent.version && `adapter ${state.agent.version}`,
64
+ state.cli?.version && `${cliName ?? 'CLI'} ${state.cli.version}`,
65
+ ].filter(Boolean).join(', ');
90
66
  }
91
67
 
92
68
  /**
93
- * Make an adapter install the one the next spawn runs.
69
+ * The argv for a `self` harness: the vendor's own updater, resolved by name.
94
70
  *
95
- * The launch table starts an npm adapter through a PINNED `npx -y pkg@x.y.z`
96
- * (measured versions), while the update installs the package GLOBALLY. Those are
97
- * two different resolvers: `npm i -g` writes a binary onto PATH that `npx` never
98
- * consults, so the press reported success while every new session still started
99
- * the old pinned build — measured on `claude` (global 0.101.0, launch requested
100
- * 0.100.0) and reproduced for codex/pi/zcode by construction.
101
- *
102
- * Once the install succeeded AND the binary is on PATH, the harness's launch
103
- * line is pointed at it. A user's own configured command is never replaced: it
104
- * is an explicit choice about how this machine launches the harness.
71
+ * `omp` has its own resolver (`KABMO_OMP_BIN`, then PATH): a custom install is
72
+ * launchable and already reported as installed, so checking PATH alone refused
73
+ * the one updater the harness actually has.
105
74
  */
106
- async function pointAtInstalledAdapter(
107
- harness: HarnessId,
108
- facts: HarnessUpdateFacts,
109
- steps: HarnessUpdateStep[],
110
- ): Promise<string | null> {
111
- const config = await loadHarnessConfig(harness);
112
- const bin = repointAdapterLaunch(
113
- facts,
114
- steps,
115
- config.command,
116
- facts.agentBin ? Boolean(Bun.which(facts.agentBin)) : false,
117
- );
118
- if (!bin) return null;
119
- await saveHarnessConfig(harness, { ...config, command: bin });
120
- return bin;
75
+ function selfSteps(harness: HarnessId, label: string, command: string): { steps: HarnessUpdateStep[]; error?: string } {
76
+ const argv = command.split(' ');
77
+ const binary = argv[0];
78
+ const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
79
+ if (!binary || !resolved) {
80
+ return { steps: [], error: `${label}: \`${binary || 'the updater'}\` is not on PATH` };
81
+ }
82
+ return { steps: [{ part: label, command, argv: [resolved, ...argv.slice(1)] }] };
121
83
  }
122
84
 
123
85
  export async function action({ request, params }: ActionFunctionArgs) {
@@ -150,26 +112,27 @@ export async function action({ request, params }: ActionFunctionArgs) {
150
112
  }, { status: 400 });
151
113
  }
152
114
 
115
+ // Read BEFORE planning: the answer to a press must not depend on what this
116
+ // press would have planned, and planning reads the npm registry.
117
+ //
118
+ // Only THIS harness's own unfinished record refuses the press. A different
119
+ // harness is ACCEPTED and queued: one install runs at a time (they share the
120
+ // global npm prefix), but "update these two" is one decision the user gets to
121
+ // make, and the queue is what makes the second press work instead of 409.
122
+ const running = await unfinishedUpdateJob(harness);
123
+ if (running) {
124
+ return json({
125
+ error: `${running.label} update is already ${jobQueued(running) ? 'queued' : 'running'} — it continues in the background`,
126
+ job: running,
127
+ }, { status: 409, headers: NO_STORE_HEADERS });
128
+ }
129
+
153
130
  if (facts.kind === 'self') {
154
- const command = facts.command?.split(' ') ?? [];
155
- const binary = command[0];
156
- // `omp` has its own resolver (`KABMO_OMP_BIN`, then PATH): a custom install
157
- // is launchable and already reported as installed by `commandAvailable`, so
158
- // checking PATH alone refused the one updater the harness actually has.
159
- const resolved = harness === 'omp-acp' ? resolveOmpBin() : binary ? Bun.which(binary) : null;
160
- if (!binary || !resolved) {
161
- return json({ error: `${label}: \`${binary ?? 'the updater'}\` is not on PATH` }, { status: 400 });
162
- }
163
- const result = await run([resolved, ...command.slice(1)]);
164
- const ok = result.code === 0;
165
- const outcome: HarnessUpdateOutcome = {
166
- success: ok,
167
- id: harness,
168
- message: ok ? `${label} updated` : `${label} update failed (exit ${result.code ?? 'killed'})`,
169
- command: facts.command,
170
- ...(result.output ? { output: tail(result.output) } : {}),
171
- };
172
- return json(outcome);
131
+ if (!facts.command) return json({ error: `${label} names no updater command` }, { status: 400 });
132
+ const { steps, error } = selfSteps(harness, label, facts.command);
133
+ if (error) return json({ error }, { status: 400 });
134
+ const job = await startHarnessUpdateJob(harness, label, steps);
135
+ return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
173
136
  }
174
137
 
175
138
  // `npm`: install the package at the version the registry reports NOW, so the
@@ -191,17 +154,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
191
154
  return json({ error: `${label} is not installed on this machine` }, { status: 400 });
192
155
  }
193
156
 
194
- // `harnessVersionState` was read with `force`, so both latest numbers are what
195
- // the registry serves NOW rather than what the dialog remembered.
196
-
197
157
  const steps = planHarnessUpdate(label, facts, state, agentVersion);
198
158
 
199
159
  if (steps.length === 0) {
200
160
  // Nothing to install. Reported as a success the UI can state plainly, rather
201
161
  // than running an install that would change nothing.
202
- const current = [state.agent.version && `adapter ${state.agent.version}`, state.cli?.version && `${facts.cli?.name} ${state.cli.version}`]
203
- .filter(Boolean)
204
- .join(', ');
162
+ const current = currentParts(state, facts.cli?.name);
205
163
  return json({
206
164
  success: true,
207
165
  id: harness,
@@ -213,47 +171,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
213
171
  } satisfies HarnessUpdateOutcome);
214
172
  }
215
173
 
216
- /** Did every step that ran succeed, and what did each print? */
217
- const outputs: string[] = [];
218
- let ok = true;
219
- for (const step of steps) {
220
- const result = await run(step.argv);
221
- if (result.output) outputs.push(result.output);
222
- if (result.code !== 0) {
223
- ok = false;
224
- // The first failure ends the run: installing the CLI on top of a failed
225
- // adapter install would report two outcomes for one broken state.
226
- break;
227
- }
228
- }
229
-
230
- if (ok) {
231
- // The cached probe describes the binary that WAS installed. Keeping it would
232
- // report the old version until the TTL (30 min) or a manual re-probe — and
233
- // measured after a real `npm install`: the row still read 0.100.0 while npm
234
- // had 0.101.0 on disk, because the running adapter was the previous process.
235
- await forgetProbe(harness);
236
- // The CLI's `--version` read has the same problem: it is cached for ten
237
- // minutes, so the row would keep claiming the old number after it moved.
238
- if (facts.cli) forgetCliVersion(facts.cli.bin);
239
- }
240
- // Only after the install succeeded: the launch line is repointed at the binary
241
- // that install wrote, or the next session would start the pinned one forever.
242
- const repointed = ok ? await pointAtInstalledAdapter(harness, facts, steps) : null;
243
-
244
- const moved = steps.map((step) => step.part);
245
- return json({
246
- success: ok,
247
- id: harness,
248
- message: ok
249
- ? `${label} updated (${moved.join(' + ')})${repointed ? ` — launches now run \`${repointed}\`` : ''} — check its status to read the new version`
250
- : `${label} update failed`,
251
- command: steps.map((step) => step.command).join(' && '),
252
- ...(outputs.length > 0 ? { output: tail(outputs.join('\n')) } : {}),
253
- } satisfies HarnessUpdateOutcome);
254
- }
255
-
256
- /** GET answers the same rows the versions route does, so a mistake reads plainly. */
257
- export async function loader() {
258
- return json({ harnesses: await harnessVersionRows() });
174
+ const job = await startHarnessUpdateJob(harness, label, steps);
175
+ return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
259
176
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * GET /api/sessions/:sessionId/answer — the last assistant text a turn closed.
8
+ *
9
+ * ACP has no transcript for `/api/chat/:id` to read after the process dies, so
10
+ * `kabmo session output` needs this row. A null answer is a real state (the
11
+ * session has not answered yet), not an error.
12
+ */
13
+
14
+ import { json } from '@/server/lib/remix-compat';
15
+ import type { LoaderFunctionArgs } from '@/server/lib/remix-compat';
16
+ import { methodNotAllowed } from '@/server/lib/route-adapter';
17
+ import { loadSessionAnswer } from '@/server/lib/sessions/answers.server';
18
+
19
+ export async function getSessionAnswer({ request, params }: LoaderFunctionArgs) {
20
+ if (request.method !== 'GET') return methodNotAllowed({ request, params });
21
+ const sessionId = params.sessionId;
22
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
23
+ return json({ sessionId, answer: await loadSessionAnswer(sessionId) });
24
+ }
@@ -20,7 +20,7 @@
20
20
  import { json } from '@/server/lib/remix-compat';
21
21
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
22
22
  import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
23
- import { removeSession } from '@/server/lib/omp/session/delete-flow.server';
23
+ import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
24
24
 
25
25
  /** One request cannot carry an unbounded selection. */
26
26
  const MAX_BATCH = 500;
@@ -44,6 +44,7 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
44
44
  }
45
45
 
46
46
  const removed: string[] = [];
47
+ const removedDependents: string[] = [];
47
48
  const refused: { id: string; error: string; code?: string }[] = [];
48
49
 
49
50
  // Sequential, deliberately: every removal may have to destroy an omp child
@@ -51,10 +52,15 @@ export async function batchDeleteSessions({ request }: ActionFunctionArgs) {
51
52
  // transcript writer per session at once for no gain — the work is dominated
52
53
  // by process teardown, not by the filesystem.
53
54
  for (const id of ids) {
54
- const result = await removeSession(id);
55
- if (result.ok) removed.push(id);
56
- else refused.push({ id, error: result.error ?? 'Could not delete the session.', code: result.code });
55
+ const tree = await removeSessionTree(id);
56
+ const result = tree.result;
57
+ if (result.ok) {
58
+ removed.push(id);
59
+ removedDependents.push(...tree.removedDependents);
60
+ } else {
61
+ refused.push({ id, error: result.error ?? 'Could not delete the session.', code: result.code });
62
+ }
57
63
  }
58
64
 
59
- return json({ success: refused.length === 0, removed, refused });
65
+ return json({ success: refused.length === 0, removed, removedDependents, refused });
60
66
  }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The JSON body readers shared by the session routes that accept a composer's
8
+ * picks: `/api/sessions/spawn` and `/api/sessions/:id/fork`.
9
+ *
10
+ * One copy, because the two endpoints promise the same shape (`harness`-style
11
+ * explicit picks, a model pair, images) and a second parser would drift into
12
+ * accepting something the other refuses.
13
+ */
14
+
15
+ import type { AgentImage } from '@/shared/types/omp/agent';
16
+ import type { SelectedModel } from '@/shared/types/models';
17
+
18
+ /** A trimmed non-empty string, or null — the routes' "absent" spelling. */
19
+ export function readString(value: unknown): string | null {
20
+ return typeof value === 'string' && value.trim() ? value.trim() : null;
21
+ }
22
+
23
+ /** A `{provider, modelId}` pair, or null when either half is missing. */
24
+ export function readModel(value: unknown): SelectedModel | null {
25
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
26
+ const record = value as Record<string, unknown>;
27
+ return typeof record.provider === 'string' && typeof record.modelId === 'string'
28
+ ? { provider: record.provider, modelId: record.modelId }
29
+ : null;
30
+ }
31
+
32
+ /** Image parts of a prompt, dropping entries without bytes or a MIME type. */
33
+ export function readImages(value: unknown): AgentImage[] | null {
34
+ if (!Array.isArray(value)) return null;
35
+ const images = value.flatMap((entry): AgentImage[] => {
36
+ if (!entry || typeof entry !== 'object') return [];
37
+ const record = entry as Record<string, unknown>;
38
+ return typeof record.data === 'string' && typeof record.mimeType === 'string'
39
+ ? [{ type: 'image', data: record.data, mimeType: record.mimeType }]
40
+ : [];
41
+ });
42
+ return images.length ? images : null;
43
+ }
@@ -17,7 +17,7 @@
17
17
  import { json } from '@/server/lib/remix-compat';
18
18
  import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
19
19
  import { methodNotAllowed } from '@/server/lib/route-adapter';
20
- import { removeSession } from '@/server/lib/omp/session/delete-flow.server';
20
+ import { removeSessionTree } from '@/server/lib/omp/session/delete-flow.server';
21
21
 
22
22
  export async function deleteSession({ request, params }: ActionFunctionArgs) {
23
23
  if (request.method !== 'DELETE') {
@@ -27,7 +27,8 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
27
27
  const sessionId = params.sessionId;
28
28
  if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
29
29
 
30
- const result = await removeSession(sessionId);
30
+ const tree = await removeSessionTree(sessionId);
31
+ const result = tree.result;
31
32
  if (!result.ok) {
32
33
  return json(
33
34
  { error: result.error, code: result.code },
@@ -38,6 +39,7 @@ export async function deleteSession({ request, params }: ActionFunctionArgs) {
38
39
  return json({
39
40
  success: true,
40
41
  sessionId,
42
+ removedDependents: tree.removedDependents,
41
43
  fileRemoved: result.fileRemoved,
42
44
  artifactsRemoved: result.artifactsRemoved,
43
45
  btwTopicsRemoved: result.btwTopicsRemoved,
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * POST /api/sessions/:sessionId/fork — branch a session at an anchor.
8
+ *
9
+ * Mounted under the same `:sessionId` position as the folder loader, so the
10
+ * parameter keeps that name; the suffix is what makes the route distinct.
11
+ */
12
+
13
+ import { json } from '@/server/lib/remix-compat';
14
+ import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
15
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
16
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
17
+ import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
18
+ import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
19
+ import { isMockMode } from '@/server/mock.server';
20
+ import {
21
+ SessionForkError,
22
+ forkSession,
23
+ } from '@/server/lib/sessions/fork.server';
24
+
25
+ interface ForkBody {
26
+ anchorEntryId?: unknown;
27
+ prompt?: unknown;
28
+ images?: unknown;
29
+ model?: unknown;
30
+ thinkingLevel?: unknown;
31
+ accessMode?: unknown;
32
+ title?: unknown;
33
+ cwd?: unknown;
34
+ visibility?: unknown;
35
+ lifecycleOwnerSessionId?: unknown;
36
+ }
37
+
38
+ export async function forkSessionRoute({ request, params }: ActionFunctionArgs) {
39
+ if (request.method !== 'POST') return methodNotAllowed({ request, params });
40
+ const sourceSessionId = params.sessionId;
41
+ if (!sourceSessionId) return json({ error: 'Missing session id' }, { status: 400 });
42
+
43
+ const parsed = await parseJsonBody<ForkBody>(request);
44
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
45
+ // MOCK mode has no transcript to branch. The client answers with the
46
+ // simulated stream on this CODE, as it does for a new chat.
47
+ if (isMockMode()) {
48
+ return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
49
+ }
50
+ const visibility = parsed.body.visibility;
51
+ if (visibility !== undefined && visibility !== 'visible' && visibility !== 'hidden') {
52
+ return json({ error: 'visibility must be "visible" or "hidden"' }, { status: 400 });
53
+ }
54
+ if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
55
+ return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
56
+ }
57
+
58
+ try {
59
+ const result = await forkSession({
60
+ sourceSessionId,
61
+ anchorEntryId: readString(parsed.body.anchorEntryId),
62
+ prompt: readString(parsed.body.prompt),
63
+ images: readImages(parsed.body.images),
64
+ model: readModel(parsed.body.model),
65
+ thinkingLevel: readString(parsed.body.thinkingLevel),
66
+ accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
67
+ title: readString(parsed.body.title),
68
+ cwd: readString(parsed.body.cwd),
69
+ ...(visibility ? { visibility: visibility as 'visible' | 'hidden' } : {}),
70
+ lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
71
+ });
72
+ emitRealtimeSignal('sidebar-structure');
73
+ return json(result, { status: 201 });
74
+ } catch (error) {
75
+ if (error instanceof SessionForkError) {
76
+ const status =
77
+ error.code === 'source_not_found'
78
+ ? 404
79
+ : error.code === 'source_archived' || error.code === 'fork_requires_checkpoint'
80
+ ? 409
81
+ : 400;
82
+ return json({ error: error.message, code: error.code }, { status });
83
+ }
84
+ return json(
85
+ { error: error instanceof Error ? error.message : 'Could not fork the session' },
86
+ { status: 500 },
87
+ );
88
+ }
89
+ }
@@ -16,9 +16,16 @@ import { cancelSubagent, steerSubagent } from '@/server/routes/sessions/subagent
16
16
  import { deleteSession } from '@/server/routes/sessions/delete';
17
17
  import { batchDeleteSessions } from '@/server/routes/sessions/batch-delete';
18
18
  import { batchArchiveSessions } from '@/server/routes/sessions/batch-archive';
19
+ import { spawnSession } from '@/server/routes/sessions/spawn';
20
+ import { getSessionRelations, updateSessionParent } from '@/server/routes/sessions/relations';
21
+ import { forkSessionRoute } from '@/server/routes/sessions/fork';
22
+ import { getSessionAnswer } from '@/server/routes/sessions/answer';
19
23
 
20
24
  export const sessionsBindings: HandlerBinding[] = [
21
25
  ...bindingsFor(sessionsList, '/api/sessions/list'),
26
+ // Static before the `:sessionId` routes, for the same reason batch-delete is:
27
+ // a parameter route winning the match answers 405.
28
+ { method: 'POST', path: '/api/sessions/spawn', handler: spawnSession },
22
29
  // Registered BEFORE the `:sessionId` routes: the segment is static, and the
23
30
  // batch route is POST while `:sessionId` answers DELETE, so an id route
24
31
  // winning the match would turn every batch into a 405.
@@ -27,6 +34,13 @@ export const sessionsBindings: HandlerBinding[] = [
27
34
  // `:sessionId` routes for the same reason as batch-delete.
28
35
  { method: 'POST', path: '/api/sessions/batch-archive', handler: batchArchiveSessions },
29
36
  ...bindingsFor(sessionsFolder, '/api/sessions/:sessionId'),
37
+ // The tree around one session. Both are static suffixes under the same
38
+ // `:sessionId` position, whose name must stay `sessionId` — Elysia requires
39
+ // one parameter name per position across every `/api/sessions/*` route.
40
+ { method: 'GET', path: '/api/sessions/:sessionId/relations', handler: getSessionRelations },
41
+ { method: 'POST', path: '/api/sessions/:sessionId/parent', handler: updateSessionParent },
42
+ { method: 'POST', path: '/api/sessions/:sessionId/fork', handler: forkSessionRoute },
43
+ { method: 'GET', path: '/api/sessions/:sessionId/answer', handler: getSessionAnswer },
30
44
  // DELETE-only on the same path the folder loader answers GET on: mounting it
31
45
  // through `actionBindings` would register a 405 GET fallback that Elysia
32
46
  // applies after the loader, replacing the workspace listing with it.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The tree around one session: its parent, children, forks and cleanup owner.
8
+ *
9
+ * A fork is deliberately NOT in `children`: it is a source-derived session and
10
+ * stays silent, so listing it under the parent edge would promise a
11
+ * notification that never comes. The info panel draws it from `forks`.
12
+ */
13
+
14
+ import { json } from '@/server/lib/remix-compat';
15
+ import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
16
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
17
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
18
+ import { SessionRelationError } from '@/server/lib/sessions/relation-types';
19
+ import {
20
+ getSessionRelation,
21
+ listChildRelations,
22
+ listForkRelations,
23
+ listOwnedRelations,
24
+ setSessionParent,
25
+ } from '@/server/lib/sessions/relations.server';
26
+
27
+ export async function getSessionRelations({ request, params }: LoaderFunctionArgs) {
28
+ if (request.method !== 'GET') return methodNotAllowed({ request, params });
29
+ const sessionId = params.sessionId;
30
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
31
+
32
+ const [relation, children, forks, owned] = await Promise.all([
33
+ getSessionRelation(sessionId),
34
+ listChildRelations(sessionId),
35
+ listForkRelations(sessionId),
36
+ listOwnedRelations(sessionId),
37
+ ]);
38
+ return json({
39
+ sessionId,
40
+ parent: relation?.parentSessionId ? { sessionId: relation.parentSessionId } : null,
41
+ parentNotifications: relation?.parentNotifications ?? 'auto',
42
+ visibility: relation?.visibility ?? 'visible',
43
+ origin: relation?.originKind
44
+ ? { kind: relation.originKind, sourceSessionId: relation.sourceSessionId }
45
+ : null,
46
+ children: children.map((row) => ({
47
+ sessionId: row.sessionId,
48
+ visibility: row.visibility,
49
+ parentNotifications: row.parentNotifications,
50
+ depth: row.depth,
51
+ })),
52
+ forks: forks.map((row) => ({ sessionId: row.sessionId, visibility: row.visibility })),
53
+ lifecycleOwner: relation?.lifecycleOwnerSessionId
54
+ ? { sessionId: relation.lifecycleOwnerSessionId }
55
+ : null,
56
+ owned: owned.map((row) => ({ sessionId: row.sessionId })),
57
+ });
58
+ }
59
+
60
+ export async function updateSessionParent({ request, params }: ActionFunctionArgs) {
61
+ if (request.method !== 'POST') return methodNotAllowed({ request, params });
62
+ const sessionId = params.sessionId;
63
+ if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
64
+
65
+ const parsed = await parseJsonBody<{ parentSessionId?: unknown }>(request);
66
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
67
+ const raw = parsed.body.parentSessionId;
68
+ if (raw !== null && typeof raw !== 'string') {
69
+ return json({ error: 'parentSessionId must be a string or null' }, { status: 400 });
70
+ }
71
+
72
+ try {
73
+ const relation = await setSessionParent(sessionId, raw);
74
+ emitRealtimeSignal('sidebar-structure');
75
+ return json({ ok: true, parentSessionId: relation.parentSessionId, depth: relation.depth });
76
+ } catch (error) {
77
+ if (error instanceof SessionRelationError) {
78
+ return json({ error: error.message, code: error.code }, { status: 409 });
79
+ }
80
+ return json(
81
+ { error: error instanceof Error ? error.message : 'Could not reparent the session' },
82
+ { status: 500 },
83
+ );
84
+ }
85
+ }
@@ -206,8 +206,7 @@ describe('getSessionModes', () => {
206
206
  claimHarness(wrapper as never, 'claude');
207
207
  try {
208
208
  const res = (await getSessionModes(loaderArgs(acpId)) as unknown as Response);
209
- expect(res.status).toBe(200);
210
- expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false } });
209
+ expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false, mode: { currentValue: 'plan' } } });
211
210
  } finally {
212
211
  globalThis.__ompSessions.delete(acpId);
213
212
  }