@kabmo-labs/kabmo 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +805 -736
  3. package/dist/client/static/js/index-bc9aa4mx.css +1 -0
  4. package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
  5. package/package.json +2 -4
  6. package/src/cli/lib/args.js +24 -1
  7. package/src/cli/lib/args.test.js +16 -0
  8. package/src/cli/lib/commands/session.js +233 -0
  9. package/src/cli/lib/commands/session.test.js +103 -0
  10. package/src/cli/main.js +1 -1
  11. package/src/client/components/common/ComposerPicker.tsx +3 -0
  12. package/src/client/components/common/Modal.tsx +2 -6
  13. package/src/client/components/common/code-surface/shiki.test.ts +82 -0
  14. package/src/client/components/common/code-surface/shiki.ts +28 -7
  15. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
  16. package/src/client/components/common/session-actions-menu/index.tsx +33 -2
  17. package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
  18. package/src/client/components/common/session-row/index.tsx +27 -1
  19. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
  20. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
  21. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
  22. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
  23. package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
  26. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
  28. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
  29. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
  30. package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
  31. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
  33. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
  34. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
  35. package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
  36. package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
  37. package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
  38. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
  39. package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
  40. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
  41. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
  42. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
  43. package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
  44. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
  45. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
  46. package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
  47. package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
  48. package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
  49. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
  50. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
  51. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
  52. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
  53. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
  54. package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
  55. package/src/client/components/workspace/file-explorer/index.tsx +9 -3
  56. package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
  57. package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
  58. package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
  59. package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
  60. package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
  61. package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
  62. package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
  63. package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
  64. package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
  65. package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
  66. package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
  67. package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
  68. package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
  69. package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
  70. package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
  71. package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
  72. package/src/client/data/settings/omp-schema.json +5 -5
  73. package/src/client/data/theme/terminal.test.ts +25 -0
  74. package/src/client/data/theme/terminal.ts +96 -79
  75. package/src/client/hooks/chat/composer/items.test.ts +12 -26
  76. package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
  77. package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
  78. package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
  79. package/src/client/hooks/chat/timeline/actions.ts +2 -2
  80. package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
  81. package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
  82. package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
  83. package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
  84. package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
  85. package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
  86. package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
  87. package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
  88. package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
  89. package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
  90. package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
  91. package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
  92. package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
  93. package/src/client/hooks/chat/timeline/send-props.ts +5 -3
  94. package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
  95. package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
  96. package/src/client/hooks/chat/timeline/send.test.ts +4 -4
  97. package/src/client/hooks/chat/timeline/send.ts +59 -53
  98. package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
  99. package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
  100. package/src/client/hooks/chat/timeline/session-load.ts +6 -14
  101. package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
  102. package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
  103. package/src/client/hooks/models/harness-catalog.ts +114 -0
  104. package/src/client/hooks/models/provider-writes.test.ts +81 -0
  105. package/src/client/hooks/models/provider-writes.ts +10 -3
  106. package/src/client/hooks/models/use-harness-update.test.ts +193 -0
  107. package/src/client/hooks/models/use-harness-update.ts +202 -0
  108. package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
  109. package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
  110. package/src/client/hooks/models/use-harnesses.test.ts +2 -1
  111. package/src/client/hooks/models/use-harnesses.ts +48 -114
  112. package/src/client/hooks/workspace/child-expansion.ts +33 -0
  113. package/src/client/hooks/workspace/terminal/index.ts +17 -3
  114. package/src/client/hooks/workspace/terminal/socket.ts +9 -4
  115. package/src/client/lib/session-tree.test.ts +50 -0
  116. package/src/client/lib/session-tree.ts +59 -0
  117. package/src/client/tailwind.css +26 -12
  118. package/src/server/index.ts +2 -0
  119. package/src/server/lib/auth/guard.ts +10 -0
  120. package/src/server/lib/btw/session-copy.server.ts +6 -44
  121. package/src/server/lib/btw/session-copy.test.ts +2 -1
  122. package/src/server/lib/db/schema.ts +4 -0
  123. package/src/server/lib/db/seed-terminal.test.ts +1 -1
  124. package/src/server/lib/db/seed.test.ts +1 -1
  125. package/src/server/lib/harness/acp/activation.test.ts +81 -0
  126. package/src/server/lib/harness/acp/activation.ts +72 -0
  127. package/src/server/lib/harness/acp/background-work.test.ts +262 -0
  128. package/src/server/lib/harness/acp/background-work.ts +320 -0
  129. package/src/server/lib/harness/acp/client.ts +2 -2
  130. package/src/server/lib/harness/acp/frames.test.ts +50 -1
  131. package/src/server/lib/harness/acp/frames.ts +17 -5
  132. package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
  133. package/src/server/lib/harness/acp/gateway-env.ts +70 -0
  134. package/src/server/lib/harness/acp/mapper.ts +6 -4
  135. package/src/server/lib/harness/acp/prompt.test.ts +20 -0
  136. package/src/server/lib/harness/acp/prompt.ts +19 -3
  137. package/src/server/lib/harness/acp/session-background.test.ts +129 -0
  138. package/src/server/lib/harness/acp/session-config.test.ts +73 -0
  139. package/src/server/lib/harness/acp/session-config.ts +87 -6
  140. package/src/server/lib/harness/acp/session-exit.ts +31 -0
  141. package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
  142. package/src/server/lib/harness/acp/session-handshake.ts +36 -3
  143. package/src/server/lib/harness/acp/session-idle.ts +51 -0
  144. package/src/server/lib/harness/acp/session-listeners.ts +31 -0
  145. package/src/server/lib/harness/acp/session-notifications.ts +19 -3
  146. package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
  147. package/src/server/lib/harness/acp/session-options.ts +33 -0
  148. package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
  149. package/src/server/lib/harness/acp/session-requests.ts +47 -0
  150. package/src/server/lib/harness/acp/session-turns.ts +20 -5
  151. package/src/server/lib/harness/acp/session.test-util.ts +54 -3
  152. package/src/server/lib/harness/acp/session.test.ts +65 -3
  153. package/src/server/lib/harness/acp/session.ts +79 -79
  154. package/src/server/lib/harness/acp/turn.test.ts +81 -0
  155. package/src/server/lib/harness/acp/turn.ts +54 -13
  156. package/src/server/lib/harness/acp/verbs.ts +12 -2
  157. package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
  158. package/src/server/lib/harness/auto-probe.server.ts +178 -0
  159. package/src/server/lib/harness/config.server.test.ts +1 -1
  160. package/src/server/lib/harness/config.server.ts +1 -1
  161. package/src/server/lib/harness/launch-table.ts +195 -0
  162. package/src/server/lib/harness/launch.test.ts +37 -0
  163. package/src/server/lib/harness/launch.ts +16 -116
  164. package/src/server/lib/harness/provider-entry.ts +32 -0
  165. package/src/server/lib/harness/provider-file.server.ts +3 -0
  166. package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
  167. package/src/server/lib/harness/provider-sources.server.ts +26 -2
  168. package/src/server/lib/harness/provider-write.server.ts +21 -32
  169. package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
  170. package/src/server/lib/harness/provider-zcode.server.ts +324 -0
  171. package/src/server/lib/harness/spawn.server.ts +15 -2
  172. package/src/server/lib/harness/update-job-store.test.ts +126 -0
  173. package/src/server/lib/harness/update-job-store.ts +109 -0
  174. package/src/server/lib/harness/update-job.server.ts +203 -0
  175. package/src/server/lib/harness/update-state.server.ts +15 -20
  176. package/src/server/lib/harness/update-worker.test.ts +153 -0
  177. package/src/server/lib/harness/update-worker.ts +197 -0
  178. package/src/server/lib/lifecycle/after-listen.ts +7 -0
  179. package/src/server/lib/lifecycle/paths.ts +23 -0
  180. package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
  181. package/src/server/lib/models/registry-refresh.server.ts +98 -0
  182. package/src/server/lib/omp/rpc/child-config.ts +5 -4
  183. package/src/server/lib/omp/rpc/constants.test.ts +2 -1
  184. package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
  185. package/src/server/lib/omp/rpc/manager.ts +5 -5
  186. package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
  187. package/src/server/lib/omp/rpc/session-registry.ts +14 -2
  188. package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
  189. package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
  190. package/src/server/lib/omp/session/delete.server.ts +17 -0
  191. package/src/server/lib/omp/session/rewind-file.ts +39 -21
  192. package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
  193. package/src/server/lib/omp/session/transcript-copy.ts +123 -0
  194. package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
  195. package/src/server/lib/sessions/agent-token.server.ts +134 -0
  196. package/src/server/lib/sessions/answers.server.test.ts +33 -0
  197. package/src/server/lib/sessions/answers.server.ts +37 -0
  198. package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
  199. package/src/server/lib/sessions/dispatch.server.ts +128 -0
  200. package/src/server/lib/sessions/fork.server.test.ts +209 -0
  201. package/src/server/lib/sessions/fork.server.ts +304 -0
  202. package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
  203. package/src/server/lib/sessions/lifecycle.server.ts +71 -0
  204. package/src/server/lib/sessions/notify.server.test.ts +112 -0
  205. package/src/server/lib/sessions/notify.server.ts +212 -0
  206. package/src/server/lib/sessions/relation-types.ts +76 -0
  207. package/src/server/lib/sessions/relations.server.test.ts +207 -0
  208. package/src/server/lib/sessions/relations.server.ts +337 -0
  209. package/src/server/lib/sessions/resolve.server.ts +106 -0
  210. package/src/server/lib/sessions/schema.server.ts +82 -0
  211. package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
  212. package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
  213. package/src/server/lib/sessions/spawn.server.test.ts +196 -0
  214. package/src/server/lib/sessions/spawn.server.ts +310 -0
  215. package/src/server/lib/terminal/attach-replay.test.ts +2 -2
  216. package/src/server/lib/terminal/output.test.ts +2 -2
  217. package/src/server/lib/terminal/output.ts +1 -1
  218. package/src/server/lib/terminal/resize.test.ts +99 -0
  219. package/src/server/lib/terminal/runtime.server.ts +26 -6
  220. package/src/server/lib/terminal/send-result.test.ts +18 -1
  221. package/src/server/lib/terminal/send-result.ts +26 -2
  222. package/src/server/lib/terminal/session.server.ts +6 -6
  223. package/src/server/lib/usage/new-api.test.ts +92 -0
  224. package/src/server/lib/usage/new-api.ts +131 -0
  225. package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
  226. package/src/server/lib/usage/provider-key.ts +33 -0
  227. package/src/server/lib/usage/providers.server.ts +10 -3
  228. package/src/server/lib/usage/vendor-balance.server.ts +4 -53
  229. package/src/server/lib/usage/vendor-http.ts +41 -0
  230. package/src/server/lib/usage/window.ts +55 -0
  231. package/src/server/routes/agent/command.ts +14 -1
  232. package/src/server/routes/agent/harness-command.ts +6 -0
  233. package/src/server/routes/agent/new.ts +15 -0
  234. package/src/server/routes/chat/rewind.test.ts +147 -0
  235. package/src/server/routes/chat/rewind.ts +29 -7
  236. package/src/server/routes/chat/session.test.ts +165 -10
  237. package/src/server/routes/chat/session.ts +60 -7
  238. package/src/server/routes/harness/add-provider.test.ts +9 -1
  239. package/src/server/routes/harness/import-action.ts +22 -4
  240. package/src/server/routes/harness/import.test.ts +1 -1
  241. package/src/server/routes/harness/index.ts +5 -1
  242. package/src/server/routes/harness/root.ts +8 -49
  243. package/src/server/routes/harness/toggle.test.ts +20 -0
  244. package/src/server/routes/harness/update-status.ts +26 -0
  245. package/src/server/routes/harness/update.test.ts +119 -0
  246. package/src/server/routes/harness/update.ts +67 -113
  247. package/src/server/routes/harness/versions.ts +5 -1
  248. package/src/server/routes/sessions/answer.ts +24 -0
  249. package/src/server/routes/sessions/batch-delete.ts +11 -5
  250. package/src/server/routes/sessions/delete-acp.test.ts +227 -0
  251. package/src/server/routes/sessions/delete.ts +4 -2
  252. package/src/server/routes/sessions/fork.ts +74 -0
  253. package/src/server/routes/sessions/index.ts +14 -0
  254. package/src/server/routes/sessions/relations.ts +85 -0
  255. package/src/server/routes/sessions/session.ts +4 -0
  256. package/src/server/routes/sessions/spawn.ts +134 -0
  257. package/src/server/routes/settings/model-override.ts +5 -2
  258. package/src/server/routes/settings/provider-entry.ts +2 -2
  259. package/src/server/routes/settings/provider-model.ts +2 -2
  260. package/src/server/routes/settings/provider-models.ts +2 -2
  261. package/src/server/routes/settings/provider-refresh.ts +6 -4
  262. package/src/server/routes/settings/providers.ts +3 -1
  263. package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
  264. package/src/server/routes/terminal/ws.ts +3 -3
  265. package/src/shared/lib/chat/ask-form/fields.ts +76 -0
  266. package/src/shared/lib/chat/ask-form/index.ts +323 -0
  267. package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
  268. package/src/shared/lib/chat/ask-form/types.ts +43 -0
  269. package/src/shared/lib/chat/ask-form.test.ts +137 -0
  270. package/src/shared/lib/chat/ask-questions.test.ts +65 -1
  271. package/src/shared/lib/chat/ask-questions.ts +51 -145
  272. package/src/shared/lib/chat/ask-results.ts +198 -0
  273. package/src/shared/lib/chat/composer/client.ts +31 -2
  274. package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
  275. package/src/shared/lib/chat/composer/delegation.ts +206 -0
  276. package/src/shared/lib/chat/notice-text.ts +1 -1
  277. package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
  278. package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
  279. package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
  280. package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
  281. package/src/shared/lib/code/ansi.ts +1 -1
  282. package/src/shared/lib/fonts/nerd-symbols.css +4 -3
  283. package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
  284. package/src/shared/lib/harness/catalog.test.ts +1 -1
  285. package/src/shared/lib/harness/config-fields.test.ts +4 -0
  286. package/src/shared/lib/harness/config-fields.ts +19 -4
  287. package/src/shared/lib/harness/dialects.test.ts +8 -0
  288. package/src/shared/lib/harness/dialects.ts +12 -0
  289. package/src/shared/lib/harness/provider-facts.test.ts +59 -8
  290. package/src/shared/lib/harness/provider-facts.ts +46 -11
  291. package/src/shared/lib/harness/providers.ts +44 -1
  292. package/src/shared/lib/harness/rewind.ts +24 -0
  293. package/src/shared/lib/harness/update-job.ts +33 -0
  294. package/src/shared/lib/harness/update-plan.test.ts +69 -4
  295. package/src/shared/lib/harness/update-plan.ts +57 -9
  296. package/src/shared/lib/harness/updates.test.ts +22 -0
  297. package/src/shared/lib/harness/updates.ts +24 -1
  298. package/src/shared/lib/models/client.ts +10 -1
  299. package/src/shared/lib/omp/dialog-methods.ts +4 -3
  300. package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
  301. package/src/shared/lib/omp/session/wait-idle.ts +12 -2
  302. package/src/shared/lib/theme/catalog.test.ts +13 -9
  303. package/src/shared/lib/theme/color.test.ts +2 -2
  304. package/src/shared/lib/theme/color.ts +4 -4
  305. package/src/shared/lib/theme/css.ts +2 -0
  306. package/src/shared/lib/theme/ink-scale.ts +21 -1
  307. package/src/shared/lib/theme/theme.test.ts +26 -10
  308. package/src/shared/lib/ui/safe-area.test.ts +28 -0
  309. package/src/shared/lib/ui/safe-area.ts +42 -0
  310. package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
  311. package/src/shared/lib/workspace/terminal/input.ts +33 -0
  312. package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
  313. package/src/shared/lib/workspace/terminal/keys.ts +7 -7
  314. package/src/shared/types/chat.ts +1 -1
  315. package/src/shared/types/harness-update.ts +65 -0
  316. package/src/shared/types/harness.ts +30 -4
  317. package/src/shared/types/omp/agent.ts +19 -2
  318. package/src/shared/types/workspace.ts +4 -0
  319. package/src/test-support/fake-omp-fork.ts +16 -2
  320. package/src/test-support/file-explorer-render.test-util.ts +37 -0
  321. package/src/test-support/file-explorer.test-util.ts +20 -18
  322. package/src/test-support/harness-table.test-util.ts +21 -4
  323. package/dist/client/static/js/index-jhmg4w91.css +0 -1
  324. package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
  325. package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
@@ -142,6 +142,45 @@ describe('executeSend', () => {
142
142
  expect(h1.params).toEqual(['sessionId=uuid-9']);
143
143
  });
144
144
 
145
+ test('a failed spawn reports the server reason and never simulates a reply', async () => {
146
+ const h1 = makeSendHarness({
147
+ isOmpSession: false,
148
+ sessionId: 'new-1',
149
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
150
+ selectedFolderId: 4,
151
+ agent: { spawnResult: null, spawnError: 'Cannot start dsh: deepseek-harness refused model "m"' },
152
+ });
153
+ await act(async () => {
154
+ const result = await h1.sends.executeSend('first prompt', []);
155
+ expect(result.ok).toBe(false);
156
+ expect(result.error).toContain('deepseek-harness refused model');
157
+ });
158
+ // Nothing may be left on screen for a turn the agent never took, and the
159
+ // failure may not fall through to the simulated stream — that is what made
160
+ // a refused ACP spawn look like a slow chat that then "answered".
161
+ expect(h1.state.messages).toEqual([]);
162
+ expect(h1.reported).toEqual(['Prompt not sent: Cannot start dsh: deepseek-harness refused model "m"']);
163
+ expect(h1.generating).toEqual([true, false]);
164
+ });
165
+
166
+ test('mock mode falls through to the simulated stream instead of reporting', async () => {
167
+ // Mock has no agent process BY DESIGN, so there is no failure to report —
168
+ // the demo shell answers from the simulated stream. Measured on the CI E2E
169
+ // legs: `POST /api/agent/new` answered 400 (no `omp` on the runner) and the
170
+ // landing composer did nothing at all, so no chat ever opened.
171
+ const h1 = makeSendHarness({
172
+ isOmpSession: false,
173
+ sessionId: 'new-1',
174
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
175
+ selectedFolderId: 4,
176
+ agent: { spawnResult: null, spawnError: 'Mock mode runs no agent process', spawnCode: 'mock_mode' },
177
+ });
178
+ await act(async () => {
179
+ await h1.sends.executeSend('first prompt', []);
180
+ });
181
+ expect(h1.reported).not.toContainEqual(expect.stringContaining('Prompt not sent'));
182
+ });
183
+
145
184
  test('a harness picked on the pending view rides the spawn body', async () => {
146
185
  const h1 = makeSendHarness({
147
186
  isOmpSession: false,
@@ -161,6 +200,23 @@ describe('executeSend', () => {
161
200
  expect(h1.deps.pendingHarnessRef.current).toBeNull();
162
201
  });
163
202
 
203
+ test('a New Chat harness inherited from the source chat outranks a stale pick', async () => {
204
+ // The dialog has no picker, so its `options.harness` is the only honest
205
+ // answer; a ref left by an earlier pick on the pending view must not win.
206
+ const h1 = makeSendHarness({
207
+ isOmpSession: false,
208
+ sessionId: 'new-1',
209
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
210
+ selectedFolderId: 4,
211
+ agent: { spawnResult: { sessionId: 'uuid-12' } },
212
+ });
213
+ h1.deps.pendingHarnessRef.current = 'opencode';
214
+ await act(async () => {
215
+ await h1.sends.executeSend('first prompt', [], { harness: 'omp-acp' });
216
+ });
217
+ expect(h1.agent.calls.newPrompts[0]?.options).toMatchObject({ harness: 'omp-acp' });
218
+ });
219
+
164
220
  test("the spawn's answered harness is what the run is reported as", async () => {
165
221
  const h1 = makeSendHarness({
166
222
  isOmpSession: false,
@@ -12,8 +12,9 @@
12
12
  import type { Dispatch, SetStateAction } from 'preact/compat';
13
13
  import type { AgentImage, Attachment, ChatMessageData, PromptDispatchResult } from '@/shared/types';
14
14
  import { streamChatResponse } from '@/client/hooks/chat/stream';
15
+ import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
15
16
  import { createMockStreamCallbacks } from '@/shared/lib/chat/timeline/stream-callbacks';
16
- import { attachmentImage, attachmentName, attachmentSize, attachmentType } from '@/shared/lib/chat/attachments';
17
+ import { readTextAttachments, attachmentImage, attachmentName, attachmentSize, attachmentType, type ReadTextAttachment } from '@/shared/lib/chat/attachments';
17
18
 
18
19
  /** The image payload of a delivery: the attachments that carry real bytes. A
19
20
  * replayed attachment has no live `File`, so it is dropped unless the data
@@ -62,6 +63,34 @@ export function buildOptimisticRows(args: {
62
63
  };
63
64
  }
64
65
 
66
+ /** What the send path needs from a prompt, before it decides which transport runs it. */
67
+ export type PromptAssembly =
68
+ | { ok: true; textFiles: ReadTextAttachment[]; promptText: string }
69
+ | { ok: false; error: string };
70
+
71
+ /**
72
+ * Read attachments and assemble the outgoing prompt once.
73
+ *
74
+ * A delegation refusal (two harnesses in one paragraph, an unknown harness, an
75
+ * empty task) is a send-time failure, not a prompt to send anyway: the caller
76
+ * reports it before any optimistic bubble exists.
77
+ */
78
+ export async function assemblePrompt(
79
+ text: string,
80
+ attachments: Attachment[],
81
+ includeAgents: boolean,
82
+ ): Promise<PromptAssembly> {
83
+ const textFiles = await readTextAttachments(attachments);
84
+ try {
85
+ return { ok: true, textFiles, promptText: await buildPromptText(text, textFiles, { includeAgents }) };
86
+ } catch (error) {
87
+ return {
88
+ ok: false,
89
+ error: error instanceof Error ? error.message : 'Prompt could not be assembled',
90
+ };
91
+ }
92
+ }
93
+
65
94
  /** The simulated SSE path, taken by a Kabmo-created session and as the
66
95
  * fallback when a real spawn is impossible (MOCK mode, no workspace cwd). */
67
96
  export async function streamMockFallback(args: {
@@ -15,7 +15,7 @@
15
15
  import type { Dispatch, SetStateAction } from 'preact/compat';
16
16
  import type { Attachment, ChatMessageData, OmpAgentHandle, PromptDispatchResult, QueuedMessageModel } from '@/shared/types';
17
17
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
18
- import type { SessionSeed } from '@/client/hooks/chat/timeline/session-load';
18
+ import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
19
19
  import type { DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
20
20
  import type { ArmedGoal } from '@/shared/lib/omp/mode/actions';
21
21
 
@@ -94,10 +94,12 @@ export interface ChatTimelineSendResult {
94
94
  steerOmpAgent: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
95
95
  /** `model` re-applies a queued item's snapshot before the prompt runs
96
96
  * (set_model / set_thinking_level RPC + prompt access mode). `busy: true`
97
- * means omp REFUSED the prompt mid-turn — the caller queues it instead. */
97
+ * means omp REFUSED the prompt mid-turn — the caller queues it instead.
98
+ * `harness` is the New Chat dialog's inherited agent, used only by the
99
+ * brand-new-session branch (`/api/agent/new`). */
98
100
  executeSend: (
99
101
  text: string,
100
102
  attachments: Attachment[],
101
- options?: { model?: QueuedMessageModel | null },
103
+ options?: { model?: QueuedMessageModel | null; harness?: string | null },
102
104
  ) => Promise<PromptDispatchResult>;
103
105
  }
@@ -18,9 +18,7 @@ import {
18
18
  type ChatTimelineSendDeps,
19
19
  type ChatTimelineSendResult,
20
20
  } from '@/client/hooks/chat/timeline/send';
21
- import {
22
- type SessionSeed,
23
- } from '@/client/hooks/chat/timeline/session-load';
21
+ import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
24
22
 
25
23
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
26
24
  /** The runner's own globals, restored on teardown so later files still have them. */
@@ -101,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
101
99
  },
102
100
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
103
101
  calls.newPrompts.push({ text, cwd, options });
104
- return calls.spawnResult;
102
+ return calls.spawnResult
103
+ ? { ok: true as const, session: calls.spawnResult }
104
+ : { ok: false as const, error: 'spawn failed' };
105
105
  },
106
106
  steerOmpRun: async (text: string, images: unknown) => {
107
107
  calls.steers.push({ text, images });
@@ -24,7 +24,7 @@ import {
24
24
  type ChatTimelineSendDeps,
25
25
  type ChatTimelineSendResult,
26
26
  } from '@/client/hooks/chat/timeline/send';
27
- import type { SessionSeed } from '@/client/hooks/chat/timeline/session-load';
27
+ import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
28
28
 
29
29
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
30
30
 
@@ -130,6 +130,10 @@ export interface AgentCalls {
130
130
  sendPromptBusy: boolean;
131
131
  /** The server-supplied reason, when the send was refused. */
132
132
  sendPromptError: string | undefined;
133
+ /** The reason a fresh spawn failed, when `spawnResult` is null. */
134
+ spawnError?: string;
135
+ /** The server's discriminator, e.g. `mock_mode`. */
136
+ spawnCode?: string;
133
137
  spawnResult: { sessionId: string; model?: { provider: string; modelId: string }; harness?: string } | null;
134
138
  }
135
139
 
@@ -158,7 +162,9 @@ export function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
158
162
  },
159
163
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
160
164
  calls.newPrompts.push({ text, cwd, options });
161
- return calls.spawnResult;
165
+ return calls.spawnResult
166
+ ? { ok: true as const, session: calls.spawnResult }
167
+ : { ok: false as const, error: calls.spawnError ?? 'spawn failed', ...(calls.spawnCode ? { code: calls.spawnCode } : {}) };
162
168
  },
163
169
  steerOmpRun: async (text: string, images: unknown) => {
164
170
  calls.interrupts.push({ text, images });
@@ -19,9 +19,7 @@ import {
19
19
  type ChatTimelineSendDeps,
20
20
  type ChatTimelineSendResult,
21
21
  } from '@/client/hooks/chat/timeline/send';
22
- import {
23
- type SessionSeed,
24
- } from '@/client/hooks/chat/timeline/session-load';
22
+ import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
25
23
 
26
24
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
27
25
  /** The runner's own globals, restored on teardown so later files still have them. */
@@ -101,7 +99,9 @@ function makeAgent(overrides: Partial<AgentCalls> = {}): AgentRecorder {
101
99
  },
102
100
  sendNewPrompt: async (text: string, cwd: string, _images: unknown, options: unknown) => {
103
101
  calls.newPrompts.push({ text, cwd, options });
104
- return calls.spawnResult;
102
+ return calls.spawnResult
103
+ ? { ok: true as const, session: calls.spawnResult }
104
+ : { ok: false as const, error: 'spawn failed' };
105
105
  },
106
106
  steerOmpRun: async (text: string, images: unknown) => {
107
107
  calls.interrupts.push({ text, images });
@@ -15,10 +15,8 @@ import type { ChatTimelineSendDeps, ChatTimelineSendResult } from '@/client/hook
15
15
 
16
16
  export type { ChatTimelineSendDeps, ChatTimelineSendResult };
17
17
  import type { AgentImage, Attachment, PromptDispatchResult, QueuedMessageModel } from '@/shared/types';
18
- import { buildPromptText } from '@/client/hooks/chat/timeline/prompt-text';
19
18
  import { flushDeferredPick } from '@/client/hooks/chat/timeline/deferred-model';
20
- import { readTextAttachments } from '@/shared/lib/chat/attachments';
21
- import { buildOptimisticRows, collectImages, streamMockFallback } from '@/client/hooks/chat/timeline/send-helpers';
19
+ import { buildOptimisticRows, collectImages, assemblePrompt, streamMockFallback } from '@/client/hooks/chat/timeline/send-helpers';
22
20
  import { adoptPendingSession, markPendingSessionSent } from '@/client/hooks/chat/omp/pending-sessions';
23
21
  import { recordSpawnHarness } from '@/client/hooks/chat/timeline/spawn-harness';
24
22
  import { postModeCommand } from '@/client/hooks/chat/timeline/mode-post';
@@ -67,24 +65,10 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
67
65
  const includeAgents = !harness || harness === 'omp-rpc' || harness === 'omp-acp';
68
66
 
69
67
  /**
70
- * Start the armed goal in `sessionId`, from the operator's own prompt.
71
- *
72
- * Awaited BEFORE the prompt leaves, so the order is a fact. Resolves TRUE when
73
- * the goal consumed the prompt — the caller must then not send it again.
74
- *
75
- * - `create` — the record is written with `startTurn: false`, and the prompt
76
- * that follows is the goal's first turn. The prompt is still sent.
77
- * - `guided` — there is no objective yet (the model writes it at the end of
78
- * the interview), so the operator's message IS the interview's opening
79
- * turn: the extension renders its kickoff prompt with their words folded
80
- * in (`<rough-goal>`) and runs that as turn one. The raw message is
81
- * therefore NOT sent separately — it is already inside that turn.
82
- *
83
- * A refusal is reported rather than swallowed, and the prompt still goes out
84
- * for `create`: the goal the operator set is missing, but their words are not
85
- * the goal's business. A refused `guided` cannot fall back the same way — the
86
- * interview kickoff is the extension's text — so it resolves false and the
87
- * caller sends the message as an ordinary prompt.
68
+ * Start the armed goal before the prompt leaves. `guided` folds the operator's
69
+ * words into the interview's opening turn (the caller must not send it again);
70
+ * `create` writes the record and lets the prompt be its first turn. A refusal
71
+ * is reported, and the prompt still goes out for `create`.
88
72
  */
89
73
  const startArmedGoal = useCallback(async (targetId: string, armed: ArmedGoal, promptText: string): Promise<boolean> => {
90
74
  const posted = armed.kind === 'guided'
@@ -114,11 +98,11 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
114
98
  text: string,
115
99
  attachments: Attachment[],
116
100
  ): Promise<{ promptText: string; images?: AgentImage[] }> => {
117
- const textFiles = await readTextAttachments(attachments);
118
- const promptText = await buildPromptText(text, textFiles, { includeAgents });
119
- pendingUserDisplaysRef.current = [...pendingUserDisplaysRef.current.slice(-7), { sent: promptText, display: text }];
120
- return { promptText, images: collectImages(attachments) };
121
- }, [includeAgents]);
101
+ const assembled = await assemblePrompt(text, attachments, includeAgents);
102
+ if (!assembled.ok) throw new Error(assembled.error);
103
+ pendingUserDisplaysRef.current = [...pendingUserDisplaysRef.current.slice(-7), { sent: assembled.promptText, display: text }];
104
+ return { promptText: assembled.promptText, images: collectImages(attachments) };
105
+ }, [includeAgents, pendingUserDisplaysRef]);
122
106
 
123
107
  // Steer the running omp agent (interrupt-and-reply). Returns the outcome so
124
108
  // the caller can report a refusal: the composer is cleared before this runs.
@@ -126,16 +110,24 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
126
110
  // A steer IS a new prompt: a pick made during the interrupted turn belongs
127
111
  // to it, so it is pushed before the interrupt-and-reply starts the turn.
128
112
  await flushDeferredPick(ompAgent, deferredComposerPickRef);
129
- const { promptText, images } = await prepareDeliverable(text, attachments);
130
- const result = await ompAgent.steerOmpRun(promptText, images);
113
+ let deliverable: { promptText: string; images?: AgentImage[] };
114
+ try {
115
+ deliverable = await prepareDeliverable(text, attachments);
116
+ } catch (error) {
117
+ const message = error instanceof Error ? error.message : String(error);
118
+ reportActionError(message);
119
+ setInputValue(text);
120
+ return { ok: false, busy: false, error: message };
121
+ }
122
+ const result = await ompAgent.steerOmpRun(deliverable.promptText, deliverable.images);
131
123
  if (!result.ok) setInputValue(text);
132
124
  return result;
133
- }, [ompAgent, prepareDeliverable, setInputValue, deferredComposerPickRef]);
125
+ }, [ompAgent, prepareDeliverable, setInputValue, deferredComposerPickRef, reportActionError]);
134
126
 
135
127
  const executeSend = useCallback(async (
136
128
  text: string,
137
129
  attachments: Attachment[],
138
- options?: { model?: QueuedMessageModel | null },
130
+ options?: { model?: QueuedMessageModel | null; harness?: string | null },
139
131
  ) => {
140
132
  // Last gate before a prompt leaves the client. `handleSend` already refuses
141
133
  // these, but `executeSend` is also reached by a retry of a stored turn, a
@@ -151,12 +143,15 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
151
143
  const userMsgId = `msg-${Date.now()}-user`;
152
144
  const aiPlaceholderId = `msg-${Date.now() + 1}-ai`;
153
145
 
154
- // Read text-file contents once: used for the editor (attachment.content)
155
- // and for inlining into the prompt. Reads a persisted `content` when the
156
- // attachment is a replay (queue delivery, retry) and has no live File.
157
- const textFiles = await readTextAttachments(attachments);
146
+ // A delegation refusal (two harnesses in one paragraph, an unknown
147
+ // harness, an empty task) must land before any optimistic bubble exists.
148
+ const assembled = await assemblePrompt(text, attachments, includeAgents);
149
+ if (!assembled.ok) {
150
+ reportActionError(assembled.error);
151
+ return { ok: false, busy: false, error: assembled.error };
152
+ }
153
+ const { textFiles, promptText } = assembled;
158
154
  const textContentById = new Map(textFiles.map((file) => [file.id, file.content]));
159
-
160
155
  const now = Date.now();
161
156
  const { newUserMsg, initialAiMsg } = buildOptimisticRows({
162
157
  text,
@@ -214,13 +209,7 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
214
209
  }
215
210
  }
216
211
  const images = collectImages(attachments);
217
- // Inline text-file contents into the prompt: the model sees the full file
218
- // content as fenced blocks, not just the filename.
219
- const promptText = await buildPromptText(text, textFiles, { includeAgents });
220
- // The armed goal is created HERE, at the fence of the prompt that will be
221
- // its first turn — never earlier (nothing to act on) and never after the
222
- // prompt (the goal would miss its opening turn). An armed INTERVIEW
223
- // consumes this prompt as its kickoff, so nothing is sent after it.
212
+ // `promptText` was assembled once above, so no refusal can reach here.
224
213
  const armed = goalArmRef.current;
225
214
  const consumed = armed && sessionId ? await startArmedGoal(sessionId, armed, promptText) : false;
226
215
  if (consumed) return { ok: true, busy: false };
@@ -250,7 +239,6 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
250
239
  const cwd = spawnWorktreeRef.current || currentFolder?.project_path || currentFolder?.name;
251
240
  if (cwd) {
252
241
  const images = collectImages(attachments);
253
- const promptText = await buildPromptText(text, textFiles, { includeAgents });
254
242
  optimisticUserIdRef.current = userMsgId;
255
243
  const composerModel = pendingComposerModelRef.current;
256
244
  const composerThinking = pendingThinkingLevelRef.current;
@@ -273,25 +261,31 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
273
261
  accessMode: accessModeRef.current,
274
262
  modes: spawnModes,
275
263
  // A harness picked on the pending view rides the spawn; cleared on
276
- // success below so it cannot leak onto the next new chat.
277
- ...(pendingHarnessRef.current ? { harness: pendingHarnessRef.current } : {}),
264
+ // success below so it cannot leak onto the next new chat. A New
265
+ // Chat opened from an ACP answer passes the SOURCE chat's harness
266
+ // explicitly (that dialog has no picker), and it must outrank the
267
+ // ref a previous pick left behind.
268
+ ...((options?.harness ?? pendingHarnessRef.current)
269
+ ? { harness: options?.harness ?? pendingHarnessRef.current }
270
+ : {}),
278
271
  },
279
272
  armed ? (id) => startArmedGoal(id, armed, promptText) : undefined,
280
273
  );
281
- if (spawned) {
274
+ if (spawned.ok) {
275
+ const { session } = spawned;
282
276
  // The harness the SERVER answered with: `new.ts` reports it for an ACP
283
277
  // spawn and omits it for the RPC branch, which means omp. Read rather
284
278
  // than replayed from the request, so a pick the server did not honour
285
279
  // cannot be reported as the agent running the chat.
286
- recordSpawnHarness(spawned.sessionId, spawned.harness ?? 'omp-rpc');
280
+ recordSpawnHarness(session.sessionId, session.harness ?? 'omp-rpc');
287
281
  spawnSelectionRef.current = null;
288
- adoptedSessionIdRef.current = spawned.sessionId;
282
+ adoptedSessionIdRef.current = session.sessionId;
289
283
  // The sidebar's row moves with the id: `new-…` was the client's own
290
284
  // placeholder, and the spawn answers with omp's real one, which omp
291
285
  // has still not written a transcript for. Without this the row
292
286
  // vanished at exactly the moment the URL stopped naming the pending
293
287
  // id, which is the gap this store exists to close.
294
- adoptPendingSession(sessionId, spawned.sessionId, currentFolder?.id ?? null);
288
+ adoptPendingSession(sessionId, session.sessionId, currentFolder?.id ?? null);
295
289
  // The placeholder ref is already armed (with its row) before the
296
290
  // spawn — see the note at the assignment; re-arming here would be
297
291
  // harmless but is redundant.
@@ -299,18 +293,18 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
299
293
  // composer taking over from the pending view reports the run's real
300
294
  // setting instead of a catalog default (the JSONL that carries it is
301
295
  // not locatable yet).
302
- seedSession({ model: spawned.model, thinkingLevel: composerThinking });
296
+ seedSession({ model: session.model, thinkingLevel: composerThinking });
303
297
  pendingComposerModelRef.current = null;
304
298
  pendingThinkingLevelRef.current = null;
305
299
  pendingHarnessRef.current = null;
306
- fetch(`/api/chat/${encodeURIComponent(spawned.sessionId)}`, {
300
+ fetch(`/api/chat/${encodeURIComponent(session.sessionId)}`, {
307
301
  method: 'POST',
308
302
  headers: { 'Content-Type': 'application/json' },
309
303
  body: JSON.stringify({ messages: [newUserMsg] }),
310
304
  }).catch(err => console.error('Error persisting spawned user turn:', err));
311
305
  setSearchParams(prev => {
312
306
  const next = new URLSearchParams(prev);
313
- next.set('sessionId', spawned.sessionId);
307
+ next.set('sessionId', session.sessionId);
314
308
  return next;
315
309
  }, { replace: true });
316
310
  // The sidebar already re-read at prompt dispatch (sendNewPrompt
@@ -318,6 +312,18 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
318
312
  // waiting for the JSONL to carry the user turn.
319
313
  return { ok: true, busy: false };
320
314
  }
315
+ // `mock_mode` is not a failure — mock has no agent process BY DESIGN, so
316
+ // the demo shell answers from the simulated stream below.
317
+ if (spawned.code !== 'mock_mode') {
318
+ // A real spawn failure REPORTS: falling through here once made a failed
319
+ // ACP spawn look like a slow chat that then "answered".
320
+ setLocalMessages(prev => prev.filter(m => m.id !== userMsgId && m.id !== aiPlaceholderId));
321
+ aiPlaceholderIdRef.current = null;
322
+ optimisticUserIdRef.current = null;
323
+ setGenerating(false);
324
+ reportActionError(`Prompt not sent: ${spawned.error}`);
325
+ return { ok: false, busy: false, error: spawned.error };
326
+ }
321
327
  }
322
328
  }
323
329
 
@@ -338,6 +344,6 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
338
344
  setGeneratingVerb,
339
345
  scrollToBottom,
340
346
  });
341
- }, [appSettings, folders, isOmpSession, harness, ompAgent, selectedFolderId, sessionId, scrollToBottom, jumpToBottom, persistMessages, seedSession, pendingComposerModelRef, pendingThinkingLevelRef, deferredComposerPickRef, accessModeRef, setLocalMessages]);
347
+ }, [appSettings, folders, isOmpSession, harness, ompAgent, selectedFolderId, sessionId, scrollToBottom, jumpToBottom, persistMessages, seedSession, pendingComposerModelRef, pendingThinkingLevelRef, deferredComposerPickRef, accessModeRef, setLocalMessages, reportActionError]);
342
348
  return { steerOmpAgent, executeSend };
343
349
  }
@@ -168,11 +168,15 @@ export async function mount(sessionId: string, api: ProbeApi): Promise<void> {
168
168
  }
169
169
 
170
170
  /** Land the registered fetch, as the server's response would. */
171
- export async function resolveLoad(messages: unknown[], index = 0): Promise<void> {
171
+ export async function resolveLoad(
172
+ messages: unknown[],
173
+ index = 0,
174
+ sessionExtra: Record<string, unknown> = {},
175
+ ): Promise<void> {
172
176
  const gate = gates[index];
173
177
  if (!gate) throw new Error('no session fetch was registered');
174
178
  await act(async () => {
175
- gate.resolve({ session: { id: 'sess-1', messages }, hasMore: false, oldestIndex: 0 });
179
+ gate.resolve({ session: { id: 'sess-1', messages, ...sessionExtra }, hasMore: false, oldestIndex: 0 });
176
180
  });
177
181
  for (let i = 0; i < 3; i += 1) await act(async () => {});
178
182
  }
@@ -29,6 +29,9 @@
29
29
 
30
30
  import { describe, expect, test } from 'bun:test';
31
31
  import { act } from 'preact/test-utils';
32
+ import { h, render } from 'preact';
33
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
34
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
32
35
  import {
33
36
  AI_PLACEHOLDER,
34
37
  ECHOED_TURN,
@@ -219,4 +222,32 @@ describe('a committed fetch with no local run', () => {
219
222
  expect(ids(api)).toEqual([]);
220
223
  expect(api.generatingCalls.length).toBe(before);
221
224
  });
225
+
226
+ test('publishes the live chat\'s selector lists to its harness', async () => {
227
+ stubChatFetch();
228
+ resetHarnessesStore();
229
+ const live = { models: [{ value: 'gpt-5-codex', name: 'GPT-5 Codex' }], thinking: [{ value: 'high', name: 'High' }] };
230
+ const seen: Record<string, unknown> = {};
231
+ const api = makeApi();
232
+ // The loader's session fetch is `gates[0]`; the store read below issues the
233
+ // harness-catalog read, so it must mount after the probe.
234
+ await mount('sess-1', api);
235
+ const box = document.body.appendChild(document.createElement('div'));
236
+ await act(async () => { render(h(LiveModelsRead, { sink: seen }), box); });
237
+
238
+ await resolveLoad([ECHOED_TURN], 0, { harness: 'codex', liveModels: live });
239
+
240
+ // The picker for that harness lists what the running chat reported, not what
241
+ // the throwaway probe guessed.
242
+ expect(seen.liveModels).toEqual({ codex: live });
243
+ await act(async () => { render(null, box); });
244
+ box.remove();
245
+ });
222
246
  });
247
+
248
+ /** Read the harness store the way a model picker does. */
249
+ function LiveModelsRead({ sink }: { sink: Record<string, unknown> }) {
250
+ const { liveModels } = useHarnesses();
251
+ sink.liveModels = liveModels;
252
+ return null;
253
+ }
@@ -21,25 +21,13 @@ import type { Dispatch, RefObject, SetStateAction } from 'preact/compat';
21
21
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
22
22
 
23
23
  import type { ChatMessageData } from '@/shared/types';
24
+ import type { SessionDataShape, SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
25
+ import { publishLiveModels } from '@/client/hooks/models/use-harnesses';
24
26
  import { SESSION_META_RETRY_SCHEDULE_MS } from '@/shared/lib/workspace/refresh-cadence';
25
27
  import { useSessionPagination } from '@/client/hooks/chat/timeline/session-pagination';
26
28
  import { useLostRunRecovery } from '@/client/hooks/chat/timeline/lost-run';
27
29
  import { isOwnSpawn, isSpawnArrival } from '@/client/hooks/chat/timeline/session-switch';
28
30
 
29
- export interface SessionDataShape {
30
- id?: string;
31
- title?: string;
32
- model?: string | { provider: string; modelId: string };
33
- thinkingLevel?: string;
34
- messages?: any[];
35
- }
36
-
37
- /** Session identity a spawn established before omp's JSONL is readable. */
38
- export interface SessionSeed {
39
- model?: { provider: string; modelId: string } | null;
40
- thinkingLevel?: string | null;
41
- }
42
-
43
31
  export interface UseSessionLoadDeps {
44
32
  sessionId: string | null;
45
33
  setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
@@ -106,6 +94,10 @@ export function useSessionLoad(deps: UseSessionLoadDeps) {
106
94
 
107
95
  const applySessionData = useCallback((incoming: SessionDataShape) => {
108
96
  if (incoming.model && typeof incoming.model === 'object') seededModelRef.current = incoming.model;
97
+ // The live chat's own selector lists are what the picker must list for this
98
+ // harness from now on: a probe is one throwaway spawn, and a chat already
99
+ // running can contradict it (codex refuses the probe while offering models).
100
+ if (incoming.harness && incoming.liveModels) publishLiveModels(incoming.harness, incoming.liveModels);
109
101
  const model = incoming.model ?? (isGeneratingRef.current ? seededModelRef.current ?? undefined : undefined);
110
102
  const thinkingLevel = incoming.thinkingLevel ?? seededThinkingLevelRef.current ?? undefined;
111
103
  setSessionData({ ...incoming, model, thinkingLevel });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The payload `/api/chat/:id` answers with, and the identity a spawn established
8
+ * before that payload can be trusted.
9
+ *
10
+ * Types only, in their own module: `session-load.ts` owns the fetching and the
11
+ * seeding rules and sits against the per-file size ceiling.
12
+ */
13
+
14
+ import type { LiveHarnessModels } from '@/shared/types/harness';
15
+
16
+ export interface SessionDataShape {
17
+ id?: string;
18
+ title?: string;
19
+ model?: string | { provider: string; modelId: string };
20
+ thinkingLevel?: string;
21
+ messages?: any[];
22
+ /** Harness the live session runs, with the model/thinking selectors it
23
+ * published. Only a live non-omp session reports them. */
24
+ harness?: string;
25
+ liveModels?: LiveHarnessModels;
26
+ }
27
+
28
+ /** Session identity a spawn established before omp's JSONL is readable. */
29
+ export interface SessionSeed {
30
+ model?: { provider: string; modelId: string } | null;
31
+ thinkingLevel?: string | null;
32
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Fork the current chat at a clicked row.
8
+ *
9
+ * The API call and the navigation live together because the refusal has to be
10
+ * shown where the action was taken. The server answers a typed code and a
11
+ * message; the hook surfaces the message and never navigates on a failure —
12
+ * a silent tip fork would be worse than the error.
13
+ */
14
+
15
+ import { useCallback } from 'preact/hooks';
16
+
17
+ type ToastKind = 'success' | 'error';
18
+
19
+ export function useForkSession(
20
+ sessionId: string | null | undefined,
21
+ pushToast: (message: string, type?: ToastKind) => void,
22
+ ): (messageId: string) => Promise<void> {
23
+ return useCallback(
24
+ async (messageId: string) => {
25
+ if (!sessionId) return;
26
+ try {
27
+ const response = await fetch(`/api/sessions/${encodeURIComponent(sessionId)}/fork`, {
28
+ method: 'POST',
29
+ headers: { 'content-type': 'application/json' },
30
+ body: JSON.stringify({ anchorEntryId: messageId }),
31
+ });
32
+ const body = (await response.json().catch(() => null)) as
33
+ | { sessionId?: string; error?: string }
34
+ | null;
35
+ if (!response.ok || !body?.sessionId) {
36
+ pushToast(body?.error ?? 'Could not fork this session.', 'error');
37
+ return;
38
+ }
39
+ // A full navigation is deliberate: the fork is a different session with
40
+ // its own transcript, and the workspace's session param is the source of
41
+ // truth the sidebar and the composer read on mount.
42
+ window.location.assign(`/?sessionId=${encodeURIComponent(body.sessionId)}`);
43
+ } catch {
44
+ pushToast('Could not fork this session.', 'error');
45
+ }
46
+ },
47
+ [sessionId, pushToast],
48
+ );
49
+ }