@kabmo-labs/kabmo 0.26.0 → 0.28.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 (354) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +502 -474
  3. package/dist/client/static/js/index-81f7berm.css +1 -0
  4. package/dist/client/static/js/{index-95b3n20k.js → index-xzvyrxya.js} +799 -799
  5. package/marketplace/plugins/command-runner/package.json +3 -17
  6. package/marketplace/plugins/command-runner/settings-schema.json +14 -0
  7. package/marketplace/plugins/git-forge/README.md +17 -7
  8. package/marketplace/plugins/git-forge/package.json +4 -30
  9. package/marketplace/plugins/git-forge/panel.css +16 -0
  10. package/marketplace/plugins/git-forge/settings-schema.json +27 -0
  11. package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
  12. package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
  13. package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
  14. package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
  15. package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
  16. package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
  17. package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
  18. package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
  19. package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
  20. package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
  21. package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
  22. package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
  23. package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
  24. package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
  25. package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
  26. package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
  27. package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
  28. package/marketplace/plugins/session-info/package.json +2 -10
  29. package/marketplace/plugins/session-info/settings-schema.json +8 -0
  30. package/marketplace/plugins/stats/README.md +17 -5
  31. package/marketplace/plugins/stats/package.json +3 -23
  32. package/marketplace/plugins/stats/settings-schema.json +20 -0
  33. package/marketplace/plugins/stats/src/app.tsx +1 -1
  34. package/marketplace/plugins/stats/src/groups.test.ts +46 -1
  35. package/marketplace/plugins/stats/src/groups.ts +22 -11
  36. package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
  37. package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
  38. package/marketplace/plugins/stats/src/labels.test.ts +54 -1
  39. package/marketplace/plugins/stats/src/labels.ts +33 -7
  40. package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
  41. package/marketplace/plugins/stats/src/sampler.ts +39 -5
  42. package/marketplace/plugins/stats/src/snapshot.ts +6 -0
  43. package/package.json +2 -2
  44. package/src/client/components/common/Toast.test.tsx +28 -2
  45. package/src/client/components/common/Toast.tsx +21 -9
  46. package/src/client/components/common/harness-glyph/index.tsx +18 -1
  47. package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
  48. package/src/client/components/common/session-actions-menu/index.tsx +43 -1
  49. package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
  50. package/src/client/components/common/session-row/index.tsx +4 -0
  51. package/src/client/components/common/session-row/session-row.test.tsx +6 -0
  52. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  53. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +4 -2
  54. package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
  55. package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
  56. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
  57. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -1
  58. package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
  59. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +12 -29
  60. package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
  61. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
  62. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
  63. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
  64. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +5 -1
  65. package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
  66. package/src/client/components/mobile/SessionSidebar.tsx +2 -1
  67. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
  68. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
  69. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
  70. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +4 -2
  71. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
  72. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
  73. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
  74. package/src/client/components/settings/Modal.tsx +7 -3
  75. package/src/client/components/settings/Sidebar.tsx +30 -3
  76. package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
  77. package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
  78. package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
  79. package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
  80. package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
  81. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
  82. package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
  83. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
  84. package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
  85. package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
  86. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  87. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
  88. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
  89. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
  90. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
  91. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
  92. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
  93. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
  94. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
  95. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +61 -56
  96. package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
  97. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
  98. package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
  99. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +11 -1
  100. package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
  101. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
  102. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
  103. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
  104. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
  105. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
  106. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
  107. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
  108. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
  109. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
  110. package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
  111. package/src/client/components/workspace/chat-timeline/index.tsx +17 -6
  112. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +3 -10
  113. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
  114. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
  115. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
  116. package/src/client/components/workspace/editor/FilePane.tsx +9 -4
  117. package/src/client/components/workspace/editor/Notices.tsx +2 -2
  118. package/src/client/components/workspace/editor/Pane.tsx +2 -2
  119. package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
  120. package/src/client/components/workspace/editor/index.tsx +6 -10
  121. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
  122. package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
  123. package/src/client/components/workspace/git-panel/index.tsx +2 -2
  124. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +17 -6
  125. package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
  126. package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
  127. package/src/client/components/workspace/terminal-panel/index.tsx +17 -1
  128. package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
  129. package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
  130. package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
  131. package/src/client/hooks/chat/composer/use-draft.ts +45 -1
  132. package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
  133. package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
  134. package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
  135. package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
  136. package/src/client/hooks/chat/omp/session-list.tsx +5 -0
  137. package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
  138. package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
  139. package/src/client/hooks/chat/timeline/actions.ts +4 -4
  140. package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
  141. package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
  142. package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
  143. package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
  144. package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
  145. package/src/client/hooks/chat/timeline/index.ts +5 -2
  146. package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
  147. package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
  148. package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
  149. package/src/client/hooks/chat/timeline/modes.ts +32 -52
  150. package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
  151. package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
  152. package/src/client/hooks/chat/timeline/pending-branch.ts +9 -0
  153. package/src/client/hooks/chat/timeline/pending-dispatch.ts +53 -0
  154. package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
  155. package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
  156. package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
  157. package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
  158. package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
  159. package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
  160. package/src/client/hooks/chat/timeline/send-props.ts +2 -0
  161. package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
  162. package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
  163. package/src/client/hooks/chat/timeline/send.test.ts +1 -0
  164. package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
  165. package/src/client/hooks/chat/timeline/stop-with-queue.ts +1 -1
  166. package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
  167. package/src/client/hooks/chat/waiting/cancel.ts +15 -7
  168. package/src/client/hooks/chat/waiting/choice.ts +13 -16
  169. package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
  170. package/src/client/hooks/chat/waiting/dispatch.ts +50 -29
  171. package/src/client/hooks/chat/waiting/held.ts +38 -13
  172. package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
  173. package/src/client/hooks/chat/waiting/hold.ts +20 -11
  174. package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
  175. package/src/client/hooks/chat/waiting/restore.ts +34 -0
  176. package/src/client/hooks/chat/waiting/store.ts +9 -3
  177. package/src/client/hooks/editor/file-editor-types.ts +21 -12
  178. package/src/client/hooks/editor/save-file.test.ts +1 -1
  179. package/src/client/hooks/editor/save-file.ts +35 -8
  180. package/src/client/hooks/editor/target-key.ts +17 -0
  181. package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
  182. package/src/client/hooks/editor/use-disk-digest.ts +164 -0
  183. package/src/client/hooks/editor/use-disk-sync.ts +212 -0
  184. package/src/client/hooks/editor/use-file-cache.ts +113 -0
  185. package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
  186. package/src/client/hooks/editor/use-file-editor.ts +90 -52
  187. package/src/client/hooks/editor/use-file-read.ts +24 -10
  188. package/src/client/hooks/editor/use-file-writes.ts +4 -4
  189. package/src/client/hooks/models/harness-catalog.ts +15 -0
  190. package/src/client/hooks/settings/providers/actions.ts +3 -2
  191. package/src/client/hooks/settings/providers/messages.ts +9 -7
  192. package/src/client/hooks/settings/providers/model-actions.ts +2 -1
  193. package/src/client/hooks/ui/editor-error-toast.ts +2 -1
  194. package/src/client/hooks/ui/notifications.ts +17 -8
  195. package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
  196. package/src/client/hooks/workspace/batch-archive.ts +4 -2
  197. package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
  198. package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
  199. package/src/client/hooks/workspace/panel-registry.ts +1 -1
  200. package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
  201. package/src/client/hooks/workspace/session-actions.test.ts +2 -1
  202. package/src/client/hooks/workspace/session-actions.ts +2 -1
  203. package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
  204. package/src/client/hooks/workspace/terminal/connection.ts +47 -0
  205. package/src/client/hooks/workspace/terminal/index.ts +35 -4
  206. package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
  207. package/src/client/lib/notifications/os.test.ts +1 -30
  208. package/src/client/lib/notifications/os.ts +0 -15
  209. package/src/client/lib/notifications/platform.test.ts +68 -0
  210. package/src/client/lib/notifications/platform.ts +36 -0
  211. package/src/server/index.ts +7 -0
  212. package/src/server/lib/harness/acp/client.ts +81 -87
  213. package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
  214. package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
  215. package/src/server/lib/harness/acp/prompt.test.ts +70 -1
  216. package/src/server/lib/harness/acp/prompt.ts +32 -1
  217. package/src/server/lib/harness/acp/protocol.ts +23 -0
  218. package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
  219. package/src/server/lib/harness/acp/session-handshake.ts +22 -20
  220. package/src/server/lib/harness/acp/session-options.ts +16 -0
  221. package/src/server/lib/harness/acp/session-process.ts +43 -0
  222. package/src/server/lib/harness/acp/session.ts +11 -12
  223. package/src/server/lib/harness/acp/stdio.ts +129 -0
  224. package/src/server/lib/harness/acp/verbs.test.ts +97 -0
  225. package/src/server/lib/harness/acp/verbs.ts +16 -6
  226. package/src/server/lib/harness/auto-probe.server.ts +4 -3
  227. package/src/server/lib/harness/capabilities.ts +8 -0
  228. package/src/server/lib/harness/config.server.ts +3 -2
  229. package/src/server/lib/harness/custom.server.ts +209 -0
  230. package/src/server/lib/harness/launch.ts +6 -1
  231. package/src/server/lib/harness/register.server.ts +8 -1
  232. package/src/server/lib/harness/schema.server.ts +21 -0
  233. package/src/server/lib/harness/session-lease.server.test.ts +99 -0
  234. package/src/server/lib/harness/session-lease.server.ts +193 -0
  235. package/src/server/lib/harness/session-store.server.test.ts +8 -8
  236. package/src/server/lib/harness/session-store.server.ts +25 -4
  237. package/src/server/lib/harness/session-title.server.ts +12 -2
  238. package/src/server/lib/harness/spawn.server.ts +123 -20
  239. package/src/server/lib/harness/update-queue.server.ts +3 -3
  240. package/src/server/lib/lifecycle/after-listen.ts +12 -1
  241. package/src/server/lib/lifecycle/paths.ts +19 -1
  242. package/src/server/lib/mcp/registry.server.ts +155 -0
  243. package/src/server/lib/mcp/registry.test.ts +169 -0
  244. package/src/server/lib/mcp/store.server.ts +38 -0
  245. package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
  246. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
  247. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
  248. package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
  249. package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
  250. package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
  251. package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
  252. package/src/server/lib/omp/rpc/run-model.ts +4 -2
  253. package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
  254. package/src/server/lib/omp/session/standby.server.ts +13 -2
  255. package/src/server/lib/panels/manifest.test.ts +47 -1
  256. package/src/server/lib/panels/manifest.ts +19 -0
  257. package/src/server/lib/panels/registry.server.ts +19 -2
  258. package/src/server/lib/panels/scan.server.ts +26 -2
  259. package/src/server/lib/panels/settings-schema.server.ts +72 -0
  260. package/src/server/lib/plugins/background.server.ts +21 -3
  261. package/src/server/lib/plugins/background.test.ts +13 -0
  262. package/src/server/lib/plugins/loader.server.ts +35 -51
  263. package/src/server/lib/plugins/mcp.server.ts +100 -0
  264. package/src/server/lib/plugins/mcp.test.ts +75 -0
  265. package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
  266. package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
  267. package/src/server/lib/plugins/schedule-store.server.ts +107 -0
  268. package/src/server/lib/plugins/schema.server.ts +8 -0
  269. package/src/server/lib/plugins/settings.server.ts +56 -19
  270. package/src/server/lib/plugins/shutdown.server.ts +58 -0
  271. package/src/server/lib/plugins/shutdown.test.ts +28 -3
  272. package/src/server/lib/realtime/topics/global.server.ts +5 -1
  273. package/src/server/lib/schedule/rows.server.ts +9 -0
  274. package/src/server/lib/schedule/runtime.server.test.ts +91 -0
  275. package/src/server/lib/schedule/runtime.server.ts +101 -23
  276. package/src/server/lib/schedule/schema.server.ts +15 -0
  277. package/src/server/lib/schedule/store.server.test.ts +34 -0
  278. package/src/server/lib/schedule/store.server.ts +33 -9
  279. package/src/server/lib/sessions/fork.server.test.ts +47 -0
  280. package/src/server/lib/sessions/fork.server.ts +17 -1
  281. package/src/server/lib/sessions/spawn.server.ts +2 -2
  282. package/src/server/lib/usage/report.server.ts +57 -0
  283. package/src/server/lib/waiting/runtime.server.test.ts +48 -0
  284. package/src/server/lib/waiting/runtime.server.ts +22 -0
  285. package/src/server/lib/waiting/schema.server.ts +8 -0
  286. package/src/server/lib/waiting/store.server.test.ts +14 -0
  287. package/src/server/lib/waiting/store.server.ts +6 -2
  288. package/src/server/routes/agent/command-resume.test.ts +9 -4
  289. package/src/server/routes/agent/new-mode.test.ts +40 -0
  290. package/src/server/routes/agent/new.ts +31 -10
  291. package/src/server/routes/agent/prewarm.ts +48 -7
  292. package/src/server/routes/fs/action.ts +9 -1
  293. package/src/server/routes/fs/digest.test.ts +100 -0
  294. package/src/server/routes/fs/digest.ts +106 -0
  295. package/src/server/routes/fs/index.ts +2 -0
  296. package/src/server/routes/fs/read.ts +6 -1
  297. package/src/server/routes/harness/custom.test.ts +131 -0
  298. package/src/server/routes/harness/import-action.ts +2 -2
  299. package/src/server/routes/harness/root.ts +41 -8
  300. package/src/server/routes/harness/update.ts +2 -2
  301. package/src/server/routes/panels/bindings.ts +2 -0
  302. package/src/server/routes/panels/settings.test.ts +165 -0
  303. package/src/server/routes/panels/settings.ts +106 -0
  304. package/src/server/routes/schedule/body.ts +14 -0
  305. package/src/server/routes/schedule/index.ts +28 -4
  306. package/src/server/routes/settings/mcp.ts +9 -26
  307. package/src/server/routes/waiting/index.ts +21 -2
  308. package/src/server/routes/waiting/routes.test.ts +21 -0
  309. package/src/shared/lib/chat/composer/delegation.ts +3 -3
  310. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
  311. package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
  312. package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
  313. package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
  314. package/src/shared/lib/fs/content-hash.ts +29 -0
  315. package/src/shared/lib/harness/catalog.ts +48 -6
  316. package/src/shared/lib/harness/fork.ts +60 -0
  317. package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
  318. package/src/shared/lib/harness/mcp-facts.ts +65 -0
  319. package/src/shared/lib/harness/menu.test.ts +16 -1
  320. package/src/shared/lib/harness/menu.ts +2 -2
  321. package/src/shared/lib/harness/rewind.ts +6 -6
  322. package/src/shared/lib/harness/session-modes.ts +31 -0
  323. package/src/shared/lib/harness/transcript.test.ts +29 -0
  324. package/src/shared/lib/harness/transcript.ts +19 -0
  325. package/src/shared/lib/notifications/settings.test.ts +21 -0
  326. package/src/shared/lib/notifications/settings.ts +24 -0
  327. package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
  328. package/src/shared/lib/omp/session/prewarm.ts +25 -6
  329. package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
  330. package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
  331. package/src/shared/lib/panels/capabilities.test.ts +1 -1
  332. package/src/shared/lib/panels/capabilities.ts +3 -0
  333. package/src/shared/lib/plugins/settings.ts +22 -0
  334. package/src/shared/lib/schedule/parse.test.ts +48 -0
  335. package/src/shared/lib/schedule/parse.ts +69 -45
  336. package/src/shared/lib/schedule/timezone.ts +128 -0
  337. package/src/shared/lib/settings/defaults.ts +2 -0
  338. package/src/shared/lib/ui/toast-duration.test.ts +25 -1
  339. package/src/shared/lib/ui/toast-duration.ts +22 -4
  340. package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
  341. package/src/shared/lib/workspace/relative-time.ts +16 -0
  342. package/src/shared/lib/workspace/session-state/store.ts +4 -0
  343. package/src/shared/types/harness.ts +7 -0
  344. package/src/shared/types/omp/agent.ts +6 -0
  345. package/src/shared/types/panels-registry.ts +3 -3
  346. package/src/shared/types/panels.ts +4 -2
  347. package/src/shared/types/schedule.ts +13 -0
  348. package/src/shared/types/settings/state.ts +12 -1
  349. package/src/shared/types/waiting.ts +9 -0
  350. package/src/test-support/file-editor.test-util.ts +70 -5
  351. package/dist/client/static/js/index-p2yw9ywf.css +0 -1
  352. package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
  353. package/src/client/hooks/editor/use-external-change.test.ts +0 -88
  354. package/src/client/hooks/editor/use-external-change.ts +0 -146
@@ -28,6 +28,7 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'p
28
28
  import { createContext } from 'preact/compat';
29
29
  import type { ReactNode } from 'preact/compat';
30
30
  import { useRealtimeTopic } from '@/client/hooks/ui/realtime';
31
+ import { useSidebarFullReload } from '@/client/hooks/chat/omp/sidebar-reload';
31
32
  import { useInputRequiredAlert } from '@/client/hooks/ui/input-required-alert';
32
33
  import { useRunOutcomeAlert } from '@/client/hooks/ui/run-outcome-alert';
33
34
 
@@ -186,6 +187,10 @@ export function SidebarDataProvider({ children, initialFolders = [] }: { childre
186
187
  realtimeClient.refresh(TOPIC_SIDEBAR_ACTIVITY);
187
188
  }, []);
188
189
 
190
+ // The list's own beat, so a row moved by another Kabmo instance, a CLI run or
191
+ // omp writing its session file late converges without a page reload.
192
+ useSidebarFullReload(refresh);
193
+
189
194
  // The spinner follows a user's click only: it is raised here and lowered when
190
195
  // the next structure snapshot arrives (the status snapshot may land first, and
191
196
  // the list is what the user is looking at).
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The full-reload beat: it fires on the interval, and stops when the mount
8
+ * goes away. A live timer after unmount is what keeps a list re-reading from a
9
+ * component nobody is looking at.
10
+ */
11
+
12
+ import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'bun:test';
13
+ import { Window } from 'happy-dom';
14
+ import { h, render } from 'preact';
15
+ import { act } from 'preact/test-utils';
16
+
17
+ import { SIDEBAR_FULL_RELOAD_MS, useSidebarFullReload } from '@/client/hooks/chat/omp/sidebar-reload';
18
+
19
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event'] as const;
20
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
21
+ let container: HTMLElement;
22
+
23
+ beforeAll(() => {
24
+ const win = new Window({ url: 'http://localhost' });
25
+ const target = globalThis as unknown as Record<string, unknown>;
26
+ for (const key of DOM_GLOBALS) {
27
+ nativeGlobals[key] = target[key];
28
+ target[key] = (win as unknown as Record<string, unknown>)[key];
29
+ }
30
+ container = document.createElement('div');
31
+ document.body.appendChild(container);
32
+ });
33
+
34
+ afterAll(() => {
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (nativeGlobals[key] === undefined) delete target[key];
38
+ else target[key] = nativeGlobals[key];
39
+ }
40
+ container.remove();
41
+ });
42
+
43
+ afterEach(() => {
44
+ vi.useRealTimers();
45
+ });
46
+
47
+ function mount(refresh: () => void): void {
48
+ function Probe() {
49
+ useSidebarFullReload(refresh);
50
+ return null;
51
+ }
52
+ act(() => {
53
+ render(h(Probe, null), container);
54
+ });
55
+ }
56
+
57
+ describe('useSidebarFullReload', () => {
58
+ test('refreshes once per interval, not before it', () => {
59
+ vi.useFakeTimers();
60
+ const refresh = vi.fn();
61
+ mount(refresh);
62
+
63
+ vi.advanceTimersByTime(SIDEBAR_FULL_RELOAD_MS - 1);
64
+ expect(refresh).not.toHaveBeenCalled();
65
+
66
+ vi.advanceTimersByTime(1);
67
+ expect(refresh).toHaveBeenCalledTimes(1);
68
+
69
+ vi.advanceTimersByTime(SIDEBAR_FULL_RELOAD_MS * 2);
70
+ expect(refresh).toHaveBeenCalledTimes(3);
71
+ });
72
+
73
+ test('stops the beat when the mount goes away', () => {
74
+ vi.useFakeTimers();
75
+ const refresh = vi.fn();
76
+ mount(refresh);
77
+
78
+ act(() => {
79
+ render(null, container);
80
+ });
81
+ vi.advanceTimersByTime(SIDEBAR_FULL_RELOAD_MS * 3);
82
+
83
+ expect(refresh).not.toHaveBeenCalled();
84
+ });
85
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The sidebar's full-reload beat: one request for every topic per interval.
8
+ *
9
+ * omp's own writes cover most of the list, but something outside this tab —
10
+ * another Kabmo instance, a CLI-driven run, omp writing a session file late —
11
+ * can move a row with no push reaching this client. The watcher narrows that
12
+ * window; it does not close it. This beat re-reads structure, status and
13
+ * activity so the list converges on its own instead of waiting for a reload.
14
+ *
15
+ * The transport coalesces a request that arrives while a snapshot is in
16
+ * flight, so a slow scan cannot queue snapshots behind each other.
17
+ */
18
+
19
+ import { useEffect } from 'preact/hooks';
20
+
21
+ /** How often the sidebar re-reads the whole list, in milliseconds. */
22
+ export const SIDEBAR_FULL_RELOAD_MS = 15_000;
23
+
24
+ /** Re-read every sidebar topic on a fixed beat while the mount is alive. */
25
+ export function useSidebarFullReload(refresh: () => void): void {
26
+ useEffect(() => {
27
+ const timer = setInterval(refresh, SIDEBAR_FULL_RELOAD_MS);
28
+ return () => clearInterval(timer);
29
+ }, [refresh]);
30
+ }
@@ -185,10 +185,10 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
185
185
  // keep the draft so the user can edit or retype it.
186
186
  if (blockTuiOnlySend(textToSend, setLocalMessages, harness)) return;
187
187
 
188
- // A NEW chat whose prompt is held for another session: nothing is sent now,
189
- // and the pending row stays on screen saying what it waits for. Checked
190
- // before the queue-vs-send split — a pending chat has no run to queue behind.
191
- if (await holdFromComposer(deps, textToSend, attachments, isGenerating || chatRunning)) return;
188
+ // A prompt held for another session: nothing is sent now, and the chat's
189
+ // pending/held row stays on screen saying what it waits for. Checked before
190
+ // the queue-vs-send split, so a busy chat still defers instead of queueing.
191
+ if (await holdFromComposer(deps, textToSend, attachments)) return;
192
192
 
193
193
  // "A run is in flight" is the CHAT-level flag, not this client's own:
194
194
  // `isGenerating` only knows the run THIS page started, so a second tab, a
@@ -33,9 +33,20 @@ export function useComposerModes(sessionId: string | null, harness?: string | nu
33
33
  // mode list is the agent's own, and a non-omp agent has no `/kabmo-mode`
34
34
  // extension to fall back on.
35
35
  const { harnesses } = useHarnesses();
36
- const modeValues = harnesses.find((entry) => entry.id === harness)?.probe?.capabilities.modeValues;
36
+ const probe = harnesses.find((entry) => entry.id === harness)?.probe;
37
+ const modeValues = probe?.capabilities.modeValues;
38
+ // The ladder itself comes from the same probe, so a pending chat — which has
39
+ // no session to ask — still shows the agent's own modes as soon as its harness
40
+ // is picked. `omp-acp` is excluded for the reason `GET /modes` excludes it:
41
+ // its selectors are default/plan, which the dedicated Plan toggle expresses.
42
+ const modeChoices = harness && harness !== 'omp-acp' && probe?.modes.length ? probe.modes : undefined;
37
43
  return {
38
- modes: useChatTimelineModes(sessionId, { harness, ...(modeValues ? { modeValues } : {}) }),
44
+ modes: useChatTimelineModes(sessionId, {
45
+ harness,
46
+ ...(modeValues ? { modeValues } : {}),
47
+ ...(modeChoices ? { modeChoices } : {}),
48
+ ...(modeChoices && probe?.currentMode ? { modeCurrent: probe.currentMode } : {}),
49
+ }),
39
50
  planReview: usePlanReview(sessionId),
40
51
  };
41
52
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Open a FORK as the same pending-chat composer New Session uses.
8
+ *
9
+ * Two entry points share this: the per-message Fork (with an anchor) and the
10
+ * session menu's "Fork chat" (whole chat, no anchor). The pending entry carries
11
+ * the source and the anchor, so the normal empty-workspace composer writes the
12
+ * branch's first turn; the POST happens on SEND, in `pending-dispatch.ts`.
13
+ */
14
+
15
+ import { startPendingSession } from '@/client/hooks/chat/omp/pending-sessions';
16
+ import { setHarnessPick } from '@/client/hooks/chat/timeline/session-harness';
17
+ import { formatNewSessionTitle } from '@/shared/lib/omp/session/default-title';
18
+ import type { SetSearchParams } from '@/client/lib/router/search-params';
19
+
20
+ export interface OpenForkSessionArgs {
21
+ sourceSessionId: string;
22
+ /** The source's agent; the fork cannot change provider. */
23
+ harness?: string;
24
+ folderId: number | string | null;
25
+ /** The row the fork cuts at; null forks the whole chat. */
26
+ anchorEntryId: string | null;
27
+ setSearchParams: SetSearchParams;
28
+ }
29
+
30
+ /** Returns the pending chat's id. */
31
+ export function openForkSession(args: OpenForkSessionArgs): string {
32
+ const pendingId = startPendingSession(args.folderId, {
33
+ title: formatNewSessionTitle(new Date(), 'Fork'),
34
+ ...(args.harness ? { harness: args.harness } : {}),
35
+ forkSourceSessionId: args.sourceSessionId,
36
+ ...(args.anchorEntryId ? { forkAnchorEntryId: args.anchorEntryId } : {}),
37
+ });
38
+ // The picker's first tab is the source's agent; the fork cannot change
39
+ // provider because that agent owns the history being branched.
40
+ if (args.harness) setHarnessPick(pendingId, args.harness);
41
+ args.setSearchParams((prev) => {
42
+ const next = new URLSearchParams(prev);
43
+ next.set('sessionId', pendingId);
44
+ next.set('forkFrom', args.sourceSessionId);
45
+ if (args.anchorEntryId) next.set('forkAt', args.anchorEntryId);
46
+ else next.delete('forkAt');
47
+ next.delete('parentSessionId');
48
+ if (args.folderId !== null && args.folderId !== undefined) next.set('folderId', String(args.folderId));
49
+ return next;
50
+ }, { replace: true });
51
+ return pendingId;
52
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The fork preview's TRANSPORT half: which source it reads, and what happens
8
+ * when "Fork from" moves.
9
+ *
10
+ * The slice itself is asserted in `shared/lib/chat/timeline/fork-preview.test.ts`;
11
+ * this pins the two behaviours the picker depends on — a source switch refetches
12
+ * (the old rows must not stand in for the new source) and a late answer for a
13
+ * source that is no longer selected is dropped, not painted.
14
+ */
15
+
16
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
17
+ import { Window } from 'happy-dom';
18
+ import { h, render } from 'preact';
19
+ import { act } from 'preact/test-utils';
20
+
21
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
22
+ import { useForkPreview, type ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
23
+ import type { ChatMessageData } from '@/shared/types';
24
+
25
+ let container: HTMLElement;
26
+ let requested: string[];
27
+ /** The runner's own fetch: a stub left installed poisons every later suite. */
28
+ const originalFetch = Bun.fetch;
29
+ interface DeferredResponse {
30
+ promise: Promise<Response>;
31
+ resolve: (value: Response) => void;
32
+ }
33
+ const gates = new Map<string, DeferredResponse>();
34
+
35
+ beforeAll(() => installDomGlobals(new Window({ url: 'http://localhost' })));
36
+ afterAll(() => restoreDomGlobals());
37
+
38
+ beforeEach(() => {
39
+ requested = [];
40
+ gates.clear();
41
+ globalThis.fetch = ((input: RequestInfo | URL) => {
42
+ const url = String(input);
43
+ requested.push(url);
44
+ const gate = Promise.withResolvers<Response>();
45
+ gates.set(url, gate);
46
+ return gate.promise;
47
+ }) as typeof fetch;
48
+ container = document.createElement('div');
49
+ document.body.appendChild(container);
50
+ });
51
+
52
+ afterEach(() => {
53
+ globalThis.fetch = originalFetch;
54
+ render(null, container);
55
+ container.remove();
56
+ });
57
+
58
+ const sessionResponse = (id: string, messages: ChatMessageData[]) =>
59
+ Response.json({ session: { id, messages } });
60
+
61
+ /** Mounts the hook and records its latest value. */
62
+ function mount(source: string | null, anchor: string | null): { current: ForkPreview | null } {
63
+ const state: { current: ForkPreview | null } = { current: null };
64
+ function Probe({ sourceId, anchorId }: { sourceId: string | null; anchorId: string | null }) {
65
+ state.current = useForkPreview(sourceId, anchorId);
66
+ return null;
67
+ }
68
+ act(() => render(h(Probe, { sourceId: source, anchorId: anchor }), container));
69
+ return state;
70
+ }
71
+
72
+ async function settle(): Promise<void> {
73
+ // The fetch chain is microtasks only: drain them deterministically rather
74
+ // than guessing a wall-clock delay.
75
+ await act(async () => {
76
+ for (let tick = 0; tick < 8; tick += 1) await Promise.resolve();
77
+ });
78
+ }
79
+
80
+ describe('useForkPreview', () => {
81
+ test('reads the whole source transcript and slices it at the anchor', async () => {
82
+ const state = mount('sess-a', 'a1');
83
+ expect(requested).toEqual(['/api/chat/sess-a?limit=all']);
84
+
85
+ const gate = gates.get('/api/chat/sess-a?limit=all')!;
86
+ gate.resolve(sessionResponse('sess-a', [
87
+ { id: 'u1', role: 'user', content: 'one' },
88
+ { id: 'a1', role: 'ai', content: 'two' },
89
+ { id: 'u2', role: 'user', content: 'three' },
90
+ ]));
91
+ await settle();
92
+
93
+ expect(state.current?.loading).toBe(false);
94
+ expect(state.current?.messages.map((m) => m.id)).toEqual(['u1', 'a1']);
95
+ });
96
+
97
+ test('a new "Fork from" refetches and never shows the previous source rows', async () => {
98
+ const state = mount('sess-a', null);
99
+ gates.get('/api/chat/sess-a?limit=all')!.resolve(sessionResponse('sess-a', [
100
+ { id: 'a1', role: 'user', content: 'from A' },
101
+ ]));
102
+ await settle();
103
+ expect(state.current?.messages.map((m) => m.id)).toEqual(['a1']);
104
+
105
+ act(() => {
106
+ render(h(function Next() {
107
+ state.current = useForkPreview('sess-b', null);
108
+ return null;
109
+ }, {}), container);
110
+ });
111
+ // The picker moved: A's transcript is gone from the surface immediately.
112
+ expect(state.current?.messages).toEqual([]);
113
+ expect(requested.at(-1)).toBe('/api/chat/sess-b?limit=all');
114
+
115
+ gates.get('/api/chat/sess-b?limit=all')!.resolve(sessionResponse('sess-b', [
116
+ { id: 'b1', role: 'user', content: 'from B' },
117
+ ]));
118
+ await settle();
119
+ expect(state.current?.messages.map((m) => m.id)).toEqual(['b1']);
120
+ });
121
+
122
+ test('a late answer for an abandoned source is dropped', async () => {
123
+ const state = mount('sess-a', null);
124
+ act(() => {
125
+ render(h(function Next() {
126
+ state.current = useForkPreview('sess-b', null);
127
+ return null;
128
+ }, {}), container);
129
+ });
130
+ gates.get('/api/chat/sess-b?limit=all')!.resolve(sessionResponse('sess-b', [
131
+ { id: 'b1', role: 'user', content: 'from B' },
132
+ ]));
133
+ await settle();
134
+ gates.get('/api/chat/sess-a?limit=all')!.resolve(sessionResponse('sess-a', [
135
+ { id: 'a1', role: 'user', content: 'from A' },
136
+ ]));
137
+ await settle();
138
+ expect(state.current?.messages.map((m) => m.id)).toEqual(['b1']);
139
+ });
140
+
141
+ test('a failed read is reported, not replaced with an empty transcript', async () => {
142
+ const state = mount('sess-a', null);
143
+ gates.get('/api/chat/sess-a?limit=all')!.resolve(Response.json({ error: 'not found' }, { status: 404 }));
144
+ await settle();
145
+ expect(state.current?.error).toBe('not found');
146
+ expect(state.current?.messages).toEqual([]);
147
+ });
148
+ });
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The SOURCE transcript of the fork being composed.
8
+ *
9
+ * A fork chat is empty until the first send, so the operator had no sight of
10
+ * the history the first turn continues — and after switching "Fork from" the
11
+ * old preview stayed. This reads the source session and slices it the way the
12
+ * server will cut the branch (`forkPreviewMessages`), refetching when the
13
+ * source changes.
14
+ *
15
+ * `limit=all` on purpose: the default 120-row window would cut the preview at
16
+ * a different row than the branch file, and a fork of a long session usually
17
+ * anchors further back than that window covers.
18
+ */
19
+
20
+ import { useEffect, useMemo, useState } from 'preact/hooks';
21
+ import type { ChatMessageData } from '@/shared/types';
22
+ import { forkPreviewMessages } from '@/shared/lib/chat/timeline/fork-preview';
23
+
24
+ export interface ForkPreview {
25
+ /** The rows the fork will carry, in source order; empty while loading. */
26
+ messages: ChatMessageData[];
27
+ loading: boolean;
28
+ /** Why the source transcript could not be read, or null. */
29
+ error: string | null;
30
+ }
31
+
32
+ interface LoadedSource {
33
+ id: string;
34
+ messages: ChatMessageData[];
35
+ }
36
+
37
+ const EMPTY: ChatMessageData[] = [];
38
+
39
+ export function useForkPreview(
40
+ sourceSessionId: string | null,
41
+ anchorEntryId: string | null,
42
+ ): ForkPreview {
43
+ const [loaded, setLoaded] = useState<LoadedSource | null>(null);
44
+ const [loading, setLoading] = useState(false);
45
+ const [error, setError] = useState<{ id: string; message: string } | null>(null);
46
+
47
+ useEffect(() => {
48
+ if (!sourceSessionId) {
49
+ setLoaded(null);
50
+ setLoading(false);
51
+ setError(null);
52
+ return;
53
+ }
54
+ const controller = new AbortController();
55
+ let live = true;
56
+ setLoading(true);
57
+ setError(null);
58
+ fetch(`/api/chat/${encodeURIComponent(sourceSessionId)}?limit=all`, {
59
+ signal: controller.signal,
60
+ })
61
+ .then(async (response) => {
62
+ const body = (await response.json().catch(() => null)) as
63
+ | { session?: { messages?: ChatMessageData[] }; error?: string }
64
+ | null;
65
+ if (!live) return;
66
+ if (!response.ok) {
67
+ setError({ id: sourceSessionId, message: body?.error ?? `HTTP ${response.status}` });
68
+ setLoaded(null);
69
+ return;
70
+ }
71
+ setLoaded({ id: sourceSessionId, messages: body?.session?.messages ?? [] });
72
+ })
73
+ .catch((err: unknown) => {
74
+ if (!live || controller.signal.aborted) return;
75
+ setError({
76
+ id: sourceSessionId,
77
+ message: err instanceof Error ? err.message : 'Could not load the source transcript',
78
+ });
79
+ setLoaded(null);
80
+ })
81
+ .finally(() => {
82
+ if (live) setLoading(false);
83
+ });
84
+ return () => {
85
+ live = false;
86
+ controller.abort();
87
+ };
88
+ }, [sourceSessionId]);
89
+
90
+ // Rows from a previous source are not this fork's history: they disappear
91
+ // the moment the picker moves, rather than standing in for the new source.
92
+ const messages = useMemo(
93
+ () => (loaded && loaded.id === sourceSessionId
94
+ ? forkPreviewMessages(loaded.messages, anchorEntryId)
95
+ : EMPTY),
96
+ [loaded, sourceSessionId, anchorEntryId],
97
+ );
98
+
99
+ return {
100
+ messages,
101
+ loading,
102
+ error: error && error.id === sourceSessionId ? error.message : null,
103
+ };
104
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The FORK send: the branch inherits the source's history, so the chat that
8
+ * continues it must render that history — not just the new turn.
9
+ *
10
+ * The fork's file on disk already holds the copied rows, but the timeline skips
11
+ * a committed read while a run this page dispatched owns the rows, and a run
12
+ * that ends cleanly never re-reads the transcript. Measured symptom: the first
13
+ * forked turn appeared in an empty-looking chat and the conversation it
14
+ * continued only came back after a reload.
15
+ */
16
+
17
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
18
+ import {
19
+ act,
20
+ installDomGlobals,
21
+ makeSendHarness,
22
+ originalFetch,
23
+ requests,
24
+ restoreDomGlobals,
25
+ } from '@/client/hooks/chat/timeline/send.test-util';
26
+ import {
27
+ listPendingSessions,
28
+ releasePendingSession,
29
+ startPendingSession,
30
+ } from '@/client/hooks/chat/omp/pending-sessions';
31
+
32
+ beforeAll(() => installDomGlobals());
33
+ afterAll(() => restoreDomGlobals());
34
+ afterEach(() => {
35
+ globalThis.fetch = originalFetch;
36
+ for (const entry of listPendingSessions()) releasePendingSession(entry.id);
37
+ });
38
+ beforeEach(() => {
39
+ requests.length = 0;
40
+ });
41
+
42
+ const SOURCE_MESSAGES = [
43
+ { id: 'u1', role: 'user', content: 'first question' },
44
+ { id: 'a1', role: 'ai', content: 'first answer' },
45
+ { id: 'u2', role: 'user', content: 'second question' },
46
+ { id: 'a2', role: 'ai', content: 'second answer' },
47
+ ];
48
+
49
+ interface ForkStub {
50
+ /** Resolves the source transcript read, so a case can order the race. */
51
+ resolveSource: (body: unknown) => void;
52
+ }
53
+
54
+ /** Answers the fork POST and holds the source read open until a case asks. */
55
+ function stubForkFetch(): ForkStub {
56
+ const source = Promise.withResolvers<Response>();
57
+ globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
58
+ const url = String(input);
59
+ requests.push({ url, method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
60
+ if (url.startsWith('/api/sessions/src-1/fork')) {
61
+ return Response.json({ sessionId: 'fork-9', sourceSessionId: 'src-1', originKind: 'fork' }, { status: 201 });
62
+ }
63
+ if (url.startsWith('/api/chat/src-1?limit=all')) return source.promise;
64
+ return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
65
+ }) as typeof fetch;
66
+ return { resolveSource: (body) => source.resolve(Response.json(body)) };
67
+ }
68
+
69
+ /** A pending fork chat bound to `src-1`, anchored at `anchor` (null = tip). */
70
+ function pendingFork(anchor: string | null): string {
71
+ return startPendingSession(4, {
72
+ forkSourceSessionId: 'src-1',
73
+ ...(anchor ? { forkAnchorEntryId: anchor } : {}),
74
+ });
75
+ }
76
+
77
+ async function flush(): Promise<void> {
78
+ await act(async () => {
79
+ for (let tick = 0; tick < 8; tick += 1) await Promise.resolve();
80
+ });
81
+ }
82
+
83
+ describe('fork send inherits the source history', () => {
84
+ test('the branch transcript lands above the optimistic turn', async () => {
85
+ const stub = stubForkFetch();
86
+ const h1 = makeSendHarness({
87
+ isOmpSession: false,
88
+ sessionId: pendingFork('a2'),
89
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
90
+ selectedFolderId: 4,
91
+ });
92
+ await act(async () => {
93
+ await h1.sends.executeSend('continue it', []);
94
+ });
95
+ expect(h1.adoptedSessionIdRef.current).toBe('fork-9');
96
+
97
+ stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
98
+ await flush();
99
+
100
+ expect(h1.state.messages.map((m) => m.id)).toEqual([
101
+ 'u1', 'a1', 'u2', 'a2', expect.stringMatching(/^msg-\d+-user$/), expect.stringMatching(/^msg-\d+-ai$/),
102
+ ]);
103
+ });
104
+
105
+ test('the anchor cuts the prefix the same way the branch cuts the file', async () => {
106
+ const stub = stubForkFetch();
107
+ const h1 = makeSendHarness({
108
+ isOmpSession: false,
109
+ sessionId: pendingFork('u2'),
110
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
111
+ selectedFolderId: 4,
112
+ });
113
+ await act(async () => {
114
+ await h1.sends.executeSend('continue it', []);
115
+ });
116
+ stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
117
+ await flush();
118
+ // A user anchor branches BEFORE that turn: 'u2' is the message being replaced.
119
+ expect(h1.state.messages.slice(0, 2).map((m) => m.id)).toEqual(['u1', 'a1']);
120
+ });
121
+
122
+ test('a read that lands after the chat moved on is dropped', async () => {
123
+ const stub = stubForkFetch();
124
+ const h1 = makeSendHarness({
125
+ isOmpSession: false,
126
+ sessionId: pendingFork(null),
127
+ folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
128
+ selectedFolderId: 4,
129
+ });
130
+ await act(async () => {
131
+ await h1.sends.executeSend('continue it', []);
132
+ });
133
+ h1.adoptedSessionIdRef.current = 'another-chat';
134
+ stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
135
+ await flush();
136
+ expect(h1.state.messages).toHaveLength(2);
137
+ expect(h1.state.messages[0]?.id).toMatch(/^msg-\d+-user$/);
138
+ });
139
+ });
@@ -141,8 +141,9 @@ export function useChatTimeline({
141
141
  // Access control is a GLOBAL persisted preference, unlike per-session picks.
142
142
  const { accessMode, accessModeRef, setAccessMode: handleAccessModeChange } = useChatTimelineAccessMode(appSettings);
143
143
 
144
- // "Wait for session" on a NEW chat: the pick and the ref the send reads.
145
- const waitingDependency = useWaitingDependencyChoice(sessionId);
144
+ // "Wait for session": the pick (first prompt or a NEXT one) and the ref the
145
+ // send reads. It is per-session UI state, so each chat keeps its own.
146
+ const waitingDependency = useWaitingDependencyChoice();
146
147
 
147
148
  const persistMessages = useCallback((messagesToSave: any[]) => {
148
149
  if (!sessionId) return;
@@ -231,6 +232,7 @@ export function useChatTimeline({
231
232
  pendingHarnessRef,
232
233
  accessModeRef,
233
234
  spawnSelectionRef: modes.spawnSelectionRef,
235
+ pendingAgentModeRef: modes.pendingAgentModeRef,
234
236
  goalArmRef: modes.goalArmRef,
235
237
  disarmGoal: modes.disarmGoal,
236
238
  spawnWorktreeRef: spawn.worktreePathRef,
@@ -292,6 +294,7 @@ export function useChatTimeline({
292
294
  localMessages,
293
295
  isGenerating,
294
296
  timelineRunning,
297
+ reloadMessages,
295
298
  hasMore,
296
299
  loadingOlder,
297
300
  loadOlderError,
@@ -17,12 +17,19 @@
17
17
  * arrived yet.
18
18
  */
19
19
 
20
+ import type { SessionModeChoice } from '@/shared/lib/harness/session-modes';
21
+
20
22
  export interface ModeCapabilities {
21
23
  /** The harness that owns this chat, when the tab knows it. */
22
24
  harness?: string | null;
23
25
  /** The harness's own `mode` values, from its probe: `plan` is a real mode on
24
26
  * the agents that publish one. */
25
27
  modeValues?: string[];
28
+ /** The ladder itself (value + label) from the same probe, so a chat that has
29
+ * not spawned can still draw the agent's mode control. */
30
+ modeChoices?: readonly SessionModeChoice[];
31
+ /** The mode the agent reported as current at probe time, when it said. */
32
+ modeCurrent?: string;
26
33
  }
27
34
 
28
35
  export function modeAvailability(capabilities: ModeCapabilities): { plan: boolean; goal: boolean } {