@kabmo-labs/kabmo 0.27.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 (303) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +495 -467
  3. package/dist/client/static/js/index-81f7berm.css +1 -0
  4. package/dist/client/static/js/{index-e3qh2yps.js → index-xzvyrxya.js} +795 -795
  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/harness-glyph/index.tsx +18 -1
  45. package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
  46. package/src/client/components/common/session-actions-menu/index.tsx +43 -1
  47. package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
  48. package/src/client/components/common/session-row/index.tsx +4 -0
  49. package/src/client/components/common/session-row/session-row.test.tsx +6 -0
  50. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
  51. package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
  52. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -1
  53. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
  54. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
  55. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
  56. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
  57. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
  58. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
  59. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
  60. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
  61. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
  62. package/src/client/components/settings/Modal.tsx +6 -2
  63. package/src/client/components/settings/Sidebar.tsx +30 -3
  64. package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
  65. package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
  66. package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
  67. package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
  68. package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
  69. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
  70. package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
  71. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
  72. package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
  73. package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
  74. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
  75. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
  76. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
  77. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -2
  78. package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
  79. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
  80. package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
  81. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
  82. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
  83. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
  84. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
  85. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
  86. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
  87. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
  88. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
  89. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
  90. package/src/client/components/workspace/chat-timeline/index.tsx +11 -5
  91. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +1 -9
  92. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
  93. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
  94. package/src/client/components/workspace/editor/FilePane.tsx +9 -4
  95. package/src/client/components/workspace/editor/Notices.tsx +2 -2
  96. package/src/client/components/workspace/editor/Pane.tsx +2 -2
  97. package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
  98. package/src/client/components/workspace/editor/index.tsx +6 -10
  99. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
  100. package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
  101. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +9 -1
  102. package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
  103. package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
  104. package/src/client/components/workspace/terminal-panel/index.tsx +14 -1
  105. package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
  106. package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
  107. package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
  108. package/src/client/hooks/chat/composer/use-draft.ts +45 -1
  109. package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
  110. package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
  111. package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
  112. package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
  113. package/src/client/hooks/chat/timeline/actions.ts +4 -4
  114. package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
  115. package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
  116. package/src/client/hooks/chat/timeline/index.ts +5 -2
  117. package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
  118. package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
  119. package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
  120. package/src/client/hooks/chat/timeline/modes.ts +32 -52
  121. package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
  122. package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
  123. package/src/client/hooks/chat/timeline/pending-dispatch.ts +4 -0
  124. package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
  125. package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
  126. package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
  127. package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
  128. package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
  129. package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
  130. package/src/client/hooks/chat/timeline/send-props.ts +2 -0
  131. package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
  132. package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
  133. package/src/client/hooks/chat/timeline/send.test.ts +1 -0
  134. package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
  135. package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
  136. package/src/client/hooks/chat/waiting/cancel.ts +13 -6
  137. package/src/client/hooks/chat/waiting/choice.ts +13 -16
  138. package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
  139. package/src/client/hooks/chat/waiting/dispatch.ts +48 -28
  140. package/src/client/hooks/chat/waiting/held.ts +37 -13
  141. package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
  142. package/src/client/hooks/chat/waiting/hold.ts +20 -11
  143. package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
  144. package/src/client/hooks/chat/waiting/restore.ts +34 -0
  145. package/src/client/hooks/chat/waiting/store.ts +9 -3
  146. package/src/client/hooks/editor/file-editor-types.ts +21 -12
  147. package/src/client/hooks/editor/save-file.test.ts +1 -1
  148. package/src/client/hooks/editor/save-file.ts +35 -8
  149. package/src/client/hooks/editor/target-key.ts +17 -0
  150. package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
  151. package/src/client/hooks/editor/use-disk-digest.ts +164 -0
  152. package/src/client/hooks/editor/use-disk-sync.ts +212 -0
  153. package/src/client/hooks/editor/use-file-cache.ts +113 -0
  154. package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
  155. package/src/client/hooks/editor/use-file-editor.ts +90 -52
  156. package/src/client/hooks/editor/use-file-read.ts +24 -10
  157. package/src/client/hooks/editor/use-file-writes.ts +4 -4
  158. package/src/client/hooks/models/harness-catalog.ts +15 -0
  159. package/src/client/hooks/ui/notifications.ts +17 -8
  160. package/src/client/hooks/workspace/panel-registry.ts +1 -1
  161. package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
  162. package/src/client/lib/notifications/os.test.ts +1 -30
  163. package/src/client/lib/notifications/os.ts +0 -15
  164. package/src/client/lib/notifications/platform.test.ts +68 -0
  165. package/src/client/lib/notifications/platform.ts +36 -0
  166. package/src/server/index.ts +7 -0
  167. package/src/server/lib/harness/acp/client.ts +81 -87
  168. package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
  169. package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
  170. package/src/server/lib/harness/acp/prompt.test.ts +70 -1
  171. package/src/server/lib/harness/acp/prompt.ts +32 -1
  172. package/src/server/lib/harness/acp/protocol.ts +23 -0
  173. package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
  174. package/src/server/lib/harness/acp/session-handshake.ts +22 -20
  175. package/src/server/lib/harness/acp/session-options.ts +16 -0
  176. package/src/server/lib/harness/acp/session-process.ts +43 -0
  177. package/src/server/lib/harness/acp/session.ts +11 -12
  178. package/src/server/lib/harness/acp/stdio.ts +129 -0
  179. package/src/server/lib/harness/acp/verbs.test.ts +97 -0
  180. package/src/server/lib/harness/acp/verbs.ts +16 -6
  181. package/src/server/lib/harness/auto-probe.server.ts +4 -3
  182. package/src/server/lib/harness/capabilities.ts +8 -0
  183. package/src/server/lib/harness/config.server.ts +3 -2
  184. package/src/server/lib/harness/custom.server.ts +209 -0
  185. package/src/server/lib/harness/launch.ts +6 -1
  186. package/src/server/lib/harness/register.server.ts +8 -1
  187. package/src/server/lib/harness/schema.server.ts +21 -0
  188. package/src/server/lib/harness/session-lease.server.test.ts +99 -0
  189. package/src/server/lib/harness/session-lease.server.ts +193 -0
  190. package/src/server/lib/harness/session-store.server.test.ts +8 -8
  191. package/src/server/lib/harness/session-store.server.ts +25 -4
  192. package/src/server/lib/harness/session-title.server.ts +12 -2
  193. package/src/server/lib/harness/spawn.server.ts +123 -20
  194. package/src/server/lib/harness/update-queue.server.ts +3 -3
  195. package/src/server/lib/lifecycle/after-listen.ts +12 -1
  196. package/src/server/lib/lifecycle/paths.ts +19 -1
  197. package/src/server/lib/mcp/registry.server.ts +155 -0
  198. package/src/server/lib/mcp/registry.test.ts +169 -0
  199. package/src/server/lib/mcp/store.server.ts +38 -0
  200. package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
  201. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
  202. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
  203. package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
  204. package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
  205. package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
  206. package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
  207. package/src/server/lib/omp/rpc/run-model.ts +4 -2
  208. package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
  209. package/src/server/lib/omp/session/standby.server.ts +13 -2
  210. package/src/server/lib/panels/manifest.test.ts +47 -1
  211. package/src/server/lib/panels/manifest.ts +19 -0
  212. package/src/server/lib/panels/registry.server.ts +19 -2
  213. package/src/server/lib/panels/scan.server.ts +26 -2
  214. package/src/server/lib/panels/settings-schema.server.ts +72 -0
  215. package/src/server/lib/plugins/background.server.ts +21 -3
  216. package/src/server/lib/plugins/background.test.ts +13 -0
  217. package/src/server/lib/plugins/loader.server.ts +35 -51
  218. package/src/server/lib/plugins/mcp.server.ts +100 -0
  219. package/src/server/lib/plugins/mcp.test.ts +75 -0
  220. package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
  221. package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
  222. package/src/server/lib/plugins/schedule-store.server.ts +107 -0
  223. package/src/server/lib/plugins/schema.server.ts +8 -0
  224. package/src/server/lib/plugins/settings.server.ts +56 -19
  225. package/src/server/lib/plugins/shutdown.server.ts +58 -0
  226. package/src/server/lib/plugins/shutdown.test.ts +28 -3
  227. package/src/server/lib/realtime/topics/global.server.ts +5 -1
  228. package/src/server/lib/schedule/rows.server.ts +9 -0
  229. package/src/server/lib/schedule/runtime.server.test.ts +91 -0
  230. package/src/server/lib/schedule/runtime.server.ts +101 -23
  231. package/src/server/lib/schedule/schema.server.ts +15 -0
  232. package/src/server/lib/schedule/store.server.test.ts +34 -0
  233. package/src/server/lib/schedule/store.server.ts +33 -9
  234. package/src/server/lib/sessions/fork.server.test.ts +47 -0
  235. package/src/server/lib/sessions/fork.server.ts +17 -1
  236. package/src/server/lib/sessions/spawn.server.ts +2 -2
  237. package/src/server/lib/waiting/runtime.server.test.ts +48 -0
  238. package/src/server/lib/waiting/runtime.server.ts +22 -0
  239. package/src/server/lib/waiting/schema.server.ts +8 -0
  240. package/src/server/lib/waiting/store.server.test.ts +14 -0
  241. package/src/server/lib/waiting/store.server.ts +6 -2
  242. package/src/server/routes/agent/command-resume.test.ts +9 -4
  243. package/src/server/routes/agent/new-mode.test.ts +40 -0
  244. package/src/server/routes/agent/new.ts +31 -10
  245. package/src/server/routes/agent/prewarm.ts +48 -7
  246. package/src/server/routes/fs/action.ts +9 -1
  247. package/src/server/routes/fs/digest.test.ts +100 -0
  248. package/src/server/routes/fs/digest.ts +106 -0
  249. package/src/server/routes/fs/index.ts +2 -0
  250. package/src/server/routes/fs/read.ts +6 -1
  251. package/src/server/routes/harness/custom.test.ts +131 -0
  252. package/src/server/routes/harness/import-action.ts +2 -2
  253. package/src/server/routes/harness/root.ts +41 -8
  254. package/src/server/routes/harness/update.ts +2 -2
  255. package/src/server/routes/panels/bindings.ts +2 -0
  256. package/src/server/routes/panels/settings.test.ts +165 -0
  257. package/src/server/routes/panels/settings.ts +106 -0
  258. package/src/server/routes/schedule/body.ts +14 -0
  259. package/src/server/routes/schedule/index.ts +28 -4
  260. package/src/server/routes/settings/mcp.ts +9 -26
  261. package/src/server/routes/waiting/index.ts +21 -2
  262. package/src/server/routes/waiting/routes.test.ts +21 -0
  263. package/src/shared/lib/chat/composer/delegation.ts +3 -3
  264. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
  265. package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
  266. package/src/shared/lib/fs/content-hash.ts +29 -0
  267. package/src/shared/lib/harness/catalog.ts +48 -6
  268. package/src/shared/lib/harness/fork.ts +60 -0
  269. package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
  270. package/src/shared/lib/harness/mcp-facts.ts +65 -0
  271. package/src/shared/lib/harness/menu.test.ts +16 -1
  272. package/src/shared/lib/harness/menu.ts +2 -2
  273. package/src/shared/lib/harness/rewind.ts +6 -6
  274. package/src/shared/lib/harness/session-modes.ts +31 -0
  275. package/src/shared/lib/harness/transcript.test.ts +29 -0
  276. package/src/shared/lib/harness/transcript.ts +19 -0
  277. package/src/shared/lib/notifications/settings.test.ts +21 -0
  278. package/src/shared/lib/notifications/settings.ts +24 -0
  279. package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
  280. package/src/shared/lib/omp/session/prewarm.ts +25 -6
  281. package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
  282. package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
  283. package/src/shared/lib/panels/capabilities.test.ts +1 -1
  284. package/src/shared/lib/panels/capabilities.ts +3 -0
  285. package/src/shared/lib/plugins/settings.ts +22 -0
  286. package/src/shared/lib/schedule/parse.test.ts +48 -0
  287. package/src/shared/lib/schedule/parse.ts +69 -45
  288. package/src/shared/lib/schedule/timezone.ts +128 -0
  289. package/src/shared/lib/settings/defaults.ts +2 -0
  290. package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
  291. package/src/shared/lib/workspace/relative-time.ts +16 -0
  292. package/src/shared/types/harness.ts +7 -0
  293. package/src/shared/types/omp/agent.ts +6 -0
  294. package/src/shared/types/panels-registry.ts +3 -3
  295. package/src/shared/types/panels.ts +4 -2
  296. package/src/shared/types/schedule.ts +13 -0
  297. package/src/shared/types/settings/state.ts +12 -1
  298. package/src/shared/types/waiting.ts +9 -0
  299. package/src/test-support/file-editor.test-util.ts +70 -5
  300. package/dist/client/static/js/index-32rpkj6b.css +0 -1
  301. package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
  302. package/src/client/hooks/editor/use-external-change.test.ts +0 -88
  303. package/src/client/hooks/editor/use-external-change.ts +0 -146
@@ -27,9 +27,12 @@
27
27
 
28
28
  import { startNewRpcSession, startRpcSession, resolveSpawnCwd } from '@/server/lib/omp/rpc/manager';
29
29
  import { resolveSessionPathOr404 } from '@/server/lib/omp/session/locator';
30
+ import { startAcpSession, type AcpSpawnRequest } from '@/server/lib/harness/spawn.server';
31
+ import { loadHarnessSession } from '@/server/lib/harness/session-store.server';
30
32
  import { loadPersistedAccessMode } from '@/shared/lib/omp/config/access-mode.server';
31
33
  import { claimDueTasks, finishScheduledRun, startScheduledRun } from '@/server/lib/schedule/store.server';
32
34
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
35
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
33
36
  import type { ScheduledTask } from '@/shared/types/schedule';
34
37
 
35
38
  /**
@@ -78,6 +81,10 @@ export interface ScheduleDeps {
78
81
  ): Promise<{ session: ScheduleSessionHandle; realSessionId: string }>;
79
82
  resolveSpawnCwd(recordedCwd?: string | null): Promise<string>;
80
83
  resolveSessionPathOr404(sessionId: string): Promise<{ filePath: string; recordedCwd: string | null } | { response: Response }>;
84
+ /** Start an ACP session for a task whose harness is not the built-in RPC. */
85
+ startAcpSession(request: AcpSpawnRequest): Promise<{ session: ScheduleSessionHandle; realSessionId: string }>;
86
+ /** The agent's own session id, for resuming an ACP chat. */
87
+ loadHarnessSession(sessionId: string): Promise<{ harness: string; agentSessionId: string } | null>;
81
88
  loadPersistedAccessMode(): Promise<ApprovalMode>;
82
89
  claimDueTasks(now: number): Promise<ScheduledTask[]>;
83
90
  startScheduledRun(taskId: string, sessionId: string | null): Promise<string>;
@@ -95,6 +102,8 @@ const defaultDeps: ScheduleDeps = {
95
102
  startRpcSession,
96
103
  resolveSpawnCwd,
97
104
  resolveSessionPathOr404,
105
+ startAcpSession,
106
+ loadHarnessSession,
98
107
  loadPersistedAccessMode,
99
108
  claimDueTasks,
100
109
  startScheduledRun,
@@ -105,6 +114,13 @@ interface ScheduleRuntimeSlot {
105
114
  timer: NodeJS.Timeout | null;
106
115
  /** In-flight tick, so a slow dispatch does not overlap the next interval. */
107
116
  ticking: boolean;
117
+ /**
118
+ * Runs in flight, keyed by task id. A manual "Run now" is refused while one
119
+ * is present: a second click would spawn a second omp session for the same
120
+ * prompt. A scheduled fire is NOT refused — the claim already advanced its
121
+ * clock, so skipping it would lose the fire.
122
+ */
123
+ running: Map<string, number>;
108
124
  }
109
125
 
110
126
  declare global {
@@ -113,7 +129,12 @@ declare global {
113
129
  }
114
130
 
115
131
  function slot(): ScheduleRuntimeSlot {
116
- return (globalThis.__kabmoScheduleRuntime ??= { timer: null, ticking: false });
132
+ return (globalThis.__kabmoScheduleRuntime ??= { timer: null, ticking: false, running: new Map() });
133
+ }
134
+
135
+ /** Whether a run for this task is in flight right now. */
136
+ export function isTaskRunning(id: string): boolean {
137
+ return (slot().running.get(id) ?? 0) > 0;
117
138
  }
118
139
 
119
140
  function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
@@ -133,7 +154,46 @@ function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promi
133
154
  }
134
155
 
135
156
  /**
136
- * Resolve the omp child a fire should drive, and the prompt to send.
157
+ * Open an ACP session for a task whose harness is not the built-in RPC.
158
+ *
159
+ * A task that names a session resumes it only when the recorded row belongs to
160
+ * the SAME harness: an omp session id means nothing to `claude`, and asking the
161
+ * agent to load it would fail the run. A missing or foreign row starts a fresh
162
+ * conversation, which is the same fallback the RPC path uses for a pruned file.
163
+ */
164
+ async function openAcpTarget(
165
+ task: ScheduledTask,
166
+ deps: ScheduleDeps,
167
+ mode: ApprovalMode,
168
+ ): Promise<{ session: ScheduleSessionHandle; sessionId: string; note: string }> {
169
+ const cwd = await deps.resolveSpawnCwd(task.cwd);
170
+ let resumeAgentSessionId: string | undefined;
171
+ let note = 'new session';
172
+
173
+ if (task.sessionId) {
174
+ const recorded = await deps.loadHarnessSession(task.sessionId);
175
+ if (recorded && recorded.harness === task.harness && recorded.agentSessionId) {
176
+ resumeAgentSessionId = recorded.agentSessionId;
177
+ note = 'resumed session';
178
+ } else {
179
+ note = 'session not found; started a new one';
180
+ }
181
+ }
182
+
183
+ const { session, realSessionId } = await deps.startAcpSession({
184
+ harness: task.harness as HarnessId,
185
+ sessionId: `__new__${crypto.randomUUID()}`,
186
+ cwd,
187
+ model: task.model ? { provider: task.model.provider, modelId: task.model.modelId } : null,
188
+ thinkingLevel: task.model?.thinkingLevel ?? null,
189
+ accessMode: mode,
190
+ ...(resumeAgentSessionId ? { resumeAgentSessionId } : {}),
191
+ });
192
+ return { session, sessionId: realSessionId, note };
193
+ }
194
+
195
+ /**
196
+ * Resolve the child a fire should drive, and the prompt to send.
137
197
  *
138
198
  * A task with `sessionId` RESUMES that conversation, so "every morning, in this
139
199
  * thread" keeps one transcript. A missing file falls back to a fresh session
@@ -146,6 +206,10 @@ async function openDispatchTarget(
146
206
  ): Promise<{ session: ScheduleSessionHandle; sessionId: string; note: string }> {
147
207
  const mode = task.model?.accessMode ?? (await deps.loadPersistedAccessMode());
148
208
 
209
+ if (task.harness && task.harness !== 'omp-rpc') {
210
+ return openAcpTarget(task, deps, mode);
211
+ }
212
+
149
213
  if (task.sessionId) {
150
214
  const resolved = await deps.resolveSessionPathOr404(task.sessionId);
151
215
  if (!('response' in resolved)) {
@@ -179,30 +243,44 @@ export async function runScheduledTask(
179
243
  options: { manual?: boolean; deps?: ScheduleDeps } = {},
180
244
  ): Promise<string> {
181
245
  const deps = options.deps ?? defaultDeps;
182
- const runId = await deps.startScheduledRun(task.id, task.sessionId);
246
+ const state = slot();
247
+ // Backstop for the route's own check: a manual run never overlaps another
248
+ // run of the same task.
249
+ if (options.manual && isTaskRunning(task.id)) return '';
250
+ state.running.set(task.id, (state.running.get(task.id) ?? 0) + 1);
183
251
  try {
184
- const target = await withTimeout(openDispatchTarget(task, deps), DISPATCH_TIMEOUT_MS, 'The omp process did not start in time.');
185
- if (task.model) {
186
- await target.session.send({ type: 'set_model', provider: task.model.provider, modelId: task.model.modelId });
187
- if (task.model.thinkingLevel !== 'auto') {
188
- await target.session.send({ type: 'set_thinking_level', level: task.model.thinkingLevel });
252
+ const runId = await deps.startScheduledRun(task.id, task.sessionId);
253
+ try {
254
+ const target = await withTimeout(openDispatchTarget(task, deps), DISPATCH_TIMEOUT_MS, 'The omp process did not start in time.');
255
+ // An ACP session applies the model and thinking picks during its
256
+ // handshake; sending them again would ask an agent that may publish no
257
+ // such selector, and the spawn already refused a model it does not list.
258
+ if (task.harness === 'omp-rpc' && task.model) {
259
+ await target.session.send({ type: 'set_model', provider: task.model.provider, modelId: task.model.modelId });
260
+ if (task.model.thinkingLevel !== 'auto') {
261
+ await target.session.send({ type: 'set_thinking_level', level: task.model.thinkingLevel });
262
+ }
189
263
  }
264
+ await withTimeout(
265
+ target.session.send({ type: 'prompt', message: task.prompt }),
266
+ DISPATCH_TIMEOUT_MS,
267
+ 'The omp session did not accept the prompt in time.',
268
+ );
269
+ const detail = options.manual ? `Ran now (${target.note})` : target.note;
270
+ await deps.finishScheduledRun(runId, task.id, 'success', detail, {
271
+ sessionId: target.sessionId,
272
+ countRun: !options.manual,
273
+ });
274
+ return target.sessionId;
275
+ } catch (error) {
276
+ const message = error instanceof Error ? error.message : String(error);
277
+ await deps.finishScheduledRun(runId, task.id, 'error', message, { countRun: !options.manual });
278
+ return '';
190
279
  }
191
- await withTimeout(
192
- target.session.send({ type: 'prompt', message: task.prompt }),
193
- DISPATCH_TIMEOUT_MS,
194
- 'The omp session did not accept the prompt in time.',
195
- );
196
- const detail = options.manual ? `Ran now (${target.note})` : target.note;
197
- await deps.finishScheduledRun(runId, task.id, 'success', detail, {
198
- sessionId: target.sessionId,
199
- countRun: !options.manual,
200
- });
201
- return target.sessionId;
202
- } catch (error) {
203
- const message = error instanceof Error ? error.message : String(error);
204
- await deps.finishScheduledRun(runId, task.id, 'error', message, { countRun: !options.manual });
205
- return '';
280
+ } finally {
281
+ const remaining = (state.running.get(task.id) ?? 1) - 1;
282
+ if (remaining > 0) state.running.set(task.id, remaining);
283
+ else state.running.delete(task.id);
206
284
  }
207
285
  }
208
286
 
@@ -24,6 +24,8 @@ const SCHEDULE_SCHEMA_SQL = `
24
24
  prompt TEXT NOT NULL DEFAULT '',
25
25
  kind TEXT NOT NULL,
26
26
  spec TEXT NOT NULL,
27
+ harness TEXT,
28
+ timezone TEXT,
27
29
  folder_id INTEGER,
28
30
  cwd TEXT,
29
31
  session_id TEXT,
@@ -57,4 +59,17 @@ const SCHEDULE_SCHEMA_SQL = `
57
59
  /** Idempotent: the scheduler's own tables, created on every database open. */
58
60
  export async function ensureScheduleSchema(db: DbClient): Promise<void> {
59
61
  await db.exec(SCHEDULE_SCHEMA_SQL);
62
+ // `timezone` arrived after the table shipped. `CREATE TABLE IF NOT EXISTS`
63
+ // leaves an existing table alone, so an install created before it would miss
64
+ // the column and every read would fail on the absent field. A legacy row
65
+ // reads as the server's zone, which is the behaviour it had.
66
+ const columns = (await db.all('PRAGMA table_info(scheduled_tasks)')) as { name?: string }[];
67
+ if (!columns.some((column) => column.name === 'timezone')) {
68
+ await db.exec('ALTER TABLE scheduled_tasks ADD COLUMN timezone TEXT');
69
+ }
70
+ // `harness` arrived with the per-task harness picker. A legacy row reads as
71
+ // `omp-rpc`, which is the transport it actually ran on.
72
+ if (!columns.some((column) => column.name === 'harness')) {
73
+ await db.exec('ALTER TABLE scheduled_tasks ADD COLUMN harness TEXT');
74
+ }
60
75
  }
@@ -28,6 +28,8 @@ import { tmpdir } from 'node:os';
28
28
  import { join } from 'node:path';
29
29
  import { createDb, type DbClient } from '@/server/lib/db/client';
30
30
  import { ensureScheduleSchema } from '@/server/lib/schedule/schema.server';
31
+ import { rowToScheduledTask, type TaskRow } from '@/server/lib/schedule/rows.server';
32
+ import { serverTimeZone } from '@/shared/lib/schedule/timezone';
31
33
 
32
34
  const paths: string[] = [];
33
35
 
@@ -145,6 +147,38 @@ describe('ensureScheduleSchema', () => {
145
147
  const indexes = (await db.all("SELECT name FROM sqlite_master WHERE type = 'index'")) as { name: string }[];
146
148
  expect(indexes.map((index) => index.name)).toContain('idx_scheduled_tasks_due');
147
149
  });
150
+
151
+ test('adds the timezone column to a table created before it existed', async () => {
152
+ const path = join(tmpdir(), `schedule-legacy-${crypto.randomUUID()}.sqlite`);
153
+ paths.push(path);
154
+ const db = createDb(path);
155
+ await db.exec(`CREATE TABLE scheduled_tasks (
156
+ id TEXT PRIMARY KEY, name TEXT NOT NULL DEFAULT '', prompt TEXT NOT NULL DEFAULT '',
157
+ kind TEXT NOT NULL, spec TEXT NOT NULL, folder_id INTEGER, cwd TEXT, session_id TEXT,
158
+ provider TEXT, model_id TEXT, thinking_level TEXT, access_mode TEXT,
159
+ enabled INTEGER NOT NULL DEFAULT 1, next_run_at INTEGER, last_run_at INTEGER,
160
+ last_status TEXT, last_error TEXT, run_count INTEGER NOT NULL DEFAULT 0,
161
+ created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL
162
+ )`);
163
+ await ensureScheduleSchema(db);
164
+ const columns = (await db.all('PRAGMA table_info(scheduled_tasks)')) as { name: string }[];
165
+ expect(columns.map((column) => column.name)).toContain('timezone');
166
+ expect(columns.map((column) => column.name)).toContain('harness');
167
+ });
168
+
169
+ test('a legacy row with no timezone reads as the server zone', async () => {
170
+ const db = await tempDb();
171
+ await insertTask(db, { id: 'legacy', kind: 'cron', spec: '0 9 * * *' });
172
+ const row = db.raw.query('SELECT * FROM scheduled_tasks WHERE id = ?').get('legacy') as TaskRow;
173
+ expect(rowToScheduledTask(row).timezone).toBe(serverTimeZone());
174
+ });
175
+
176
+ test('a legacy row with no harness reads as omp-rpc', async () => {
177
+ const db = await tempDb();
178
+ await insertTask(db, { id: 'legacy-harness', kind: 'every', spec: '1h' });
179
+ const row = db.raw.query('SELECT * FROM scheduled_tasks WHERE id = ?').get('legacy-harness') as TaskRow;
180
+ expect(rowToScheduledTask(row).harness).toBe('omp-rpc');
181
+ });
148
182
  });
149
183
 
150
184
  describe('claiming due tasks', () => {
@@ -22,6 +22,8 @@
22
22
  import { getDb } from '@/server/db.server';
23
23
  import { withTransaction } from '@/shared/lib/db/transaction.server';
24
24
  import { nextRunAfter, validateSchedule } from '@/shared/lib/schedule/parse';
25
+ import { isValidTimeZone, serverTimeZone } from '@/shared/lib/schedule/timezone';
26
+ import { harnessDescriptor } from '@/shared/lib/harness/catalog';
25
27
  import { rowToRun, rowToScheduledTask, type RunRow, type TaskRow } from '@/server/lib/schedule/rows.server';
26
28
  import type {
27
29
  ScheduleKind,
@@ -63,6 +65,8 @@ export interface ScheduledTaskInput {
63
65
  prompt: string;
64
66
  kind: ScheduleKind;
65
67
  spec: string;
68
+ harness: string;
69
+ timezone: string;
66
70
  folderId: number | null;
67
71
  cwd: string | null;
68
72
  sessionId: string | null;
@@ -75,19 +79,24 @@ export interface ScheduledTaskInput {
75
79
  * be a task the runtime can only skip forever.
76
80
  */
77
81
  export async function createScheduledTask(input: ScheduledTaskInput): Promise<ScheduledTask> {
78
- const validation = validateSchedule(input.kind, input.spec);
82
+ const harness = input.harness.trim() || 'omp-rpc';
83
+ if (!harnessDescriptor(harness)) throw new Error(`Unknown harness: ${harness}`);
84
+ const timezone = input.timezone.trim() || serverTimeZone();
85
+ if (!isValidTimeZone(timezone)) throw new Error(`Unknown timezone: ${timezone}`);
86
+ const validation = validateSchedule(input.kind, input.spec, Date.now(), timezone);
79
87
  if (!validation.ok) throw new Error(validation.error);
80
88
  const db = await getDb();
81
89
  const now = Date.now();
82
90
  const id = crypto.randomUUID();
83
91
  await db.run(
84
92
  `INSERT INTO scheduled_tasks
85
- (id, name, prompt, kind, spec, folder_id, cwd, session_id,
93
+ (id, name, prompt, kind, spec, harness, timezone, folder_id, cwd, session_id,
86
94
  provider, model_id, thinking_level, access_mode,
87
95
  enabled, next_run_at, run_count, created_at, updated_at)
88
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, 0, ?, ?)`,
96
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, 0, ?, ?)`,
89
97
  [
90
- id, input.name, input.prompt, input.kind, input.spec.trim(), input.folderId, input.cwd, input.sessionId,
98
+ id, input.name, input.prompt, input.kind, input.spec.trim(), harness, timezone,
99
+ input.folderId, input.cwd, input.sessionId,
91
100
  input.model?.provider ?? null, input.model?.modelId ?? null,
92
101
  input.model?.thinkingLevel ?? null, input.model?.accessMode ?? null,
93
102
  validation.nextRunAt, now, now,
@@ -101,6 +110,8 @@ export interface ScheduledTaskPatch {
101
110
  prompt?: string;
102
111
  kind?: ScheduleKind;
103
112
  spec?: string;
113
+ harness?: string;
114
+ timezone?: string;
104
115
  folderId?: number | null;
105
116
  cwd?: string | null;
106
117
  sessionId?: string | null;
@@ -121,16 +132,24 @@ export async function updateScheduledTask(id: string, patch: ScheduledTaskPatch)
121
132
 
122
133
  const kind = patch.kind ?? existing.kind;
123
134
  const spec = patch.spec !== undefined ? patch.spec.trim() : existing.spec;
135
+ const harness = patch.harness !== undefined ? patch.harness.trim() : existing.harness;
136
+ if (!harnessDescriptor(harness)) throw new Error(`Unknown harness: ${harness}`);
137
+ const harnessChanged = harness !== existing.harness;
138
+ const timezone = patch.timezone !== undefined ? patch.timezone.trim() : existing.timezone;
139
+ if (!isValidTimeZone(timezone)) throw new Error(`Unknown timezone: ${timezone}`);
124
140
  const enabled = patch.enabled ?? existing.enabled;
125
141
  const scheduleChanged = patch.kind !== undefined || patch.spec !== undefined;
142
+ // A zone change moves every wall-clock fire, so it resets the clock exactly
143
+ // like a spec edit does.
144
+ const timezoneChanged = timezone !== existing.timezone;
126
145
 
127
146
  let nextRunAt = existing.nextRunAt;
128
- if (scheduleChanged || (enabled && !existing.enabled)) {
147
+ if (scheduleChanged || timezoneChanged || (enabled && !existing.enabled)) {
129
148
  // The old clock described a schedule (or a pause) that no longer applies.
130
149
  if (!enabled) {
131
150
  nextRunAt = null;
132
151
  } else {
133
- const validation = validateSchedule(kind, spec);
152
+ const validation = validateSchedule(kind, spec, Date.now(), timezone);
134
153
  if (!validation.ok) throw new Error(validation.error);
135
154
  nextRunAt = validation.nextRunAt;
136
155
  }
@@ -138,11 +157,14 @@ export async function updateScheduledTask(id: string, patch: ScheduledTaskPatch)
138
157
  nextRunAt = null;
139
158
  }
140
159
 
141
- const model = patch.model !== undefined ? patch.model : existing.model;
160
+ // A model snapshot belongs to the harness that published it: an omp model id
161
+ // means nothing to an ACP agent. A harness change without an explicit model
162
+ // therefore drops the snapshot and lets the new harness's default apply.
163
+ const model = patch.model !== undefined ? patch.model : harnessChanged ? null : existing.model;
142
164
  const db = await getDb();
143
165
  await db.run(
144
166
  `UPDATE scheduled_tasks SET
145
- name = ?, prompt = ?, kind = ?, spec = ?, folder_id = ?, cwd = ?, session_id = ?,
167
+ name = ?, prompt = ?, kind = ?, spec = ?, harness = ?, timezone = ?, folder_id = ?, cwd = ?, session_id = ?,
146
168
  provider = ?, model_id = ?, thinking_level = ?, access_mode = ?,
147
169
  enabled = ?, next_run_at = ?, updated_at = ?
148
170
  WHERE id = ?`,
@@ -151,6 +173,8 @@ export async function updateScheduledTask(id: string, patch: ScheduledTaskPatch)
151
173
  patch.prompt ?? existing.prompt,
152
174
  kind,
153
175
  spec,
176
+ harness,
177
+ timezone,
154
178
  patch.folderId !== undefined ? patch.folderId : existing.folderId,
155
179
  patch.cwd !== undefined ? patch.cwd : existing.cwd,
156
180
  patch.sessionId !== undefined ? patch.sessionId : existing.sessionId,
@@ -197,7 +221,7 @@ export async function claimDueTasks(now: number): Promise<ScheduledTask[]> {
197
221
  const claimed: ScheduledTask[] = [];
198
222
  for (const row of rows) {
199
223
  const task = rowToScheduledTask(row);
200
- const next = nextRunAfter(task.kind, task.spec, now);
224
+ const next = nextRunAfter(task.kind, task.spec, now, task.timezone);
201
225
  db.raw.run(
202
226
  'UPDATE scheduled_tasks SET next_run_at = ?, enabled = ?, updated_at = ? WHERE id = ?',
203
227
  [next, next === null ? 0 : 1, now, task.id],
@@ -245,6 +245,53 @@ describe('forkSession (ACP)', () => {
245
245
  ]);
246
246
  });
247
247
 
248
+ test('an anchored fork of a session with no local transcript is refused, not forked whole', async () => {
249
+ await saveHarnessSession({
250
+ sessionId: 'acp-source',
251
+ harness: 'zcode',
252
+ agentSessionId: 'agent-1',
253
+ cwd: '/tmp/project',
254
+ });
255
+ const deps = fakeDeps('never', { forkSupported: true });
256
+ await expect(
257
+ forkSession({ sourceSessionId: 'acp-source', anchorEntryId: 'u1' }, deps),
258
+ ).rejects.toMatchObject({ code: 'anchor_unsupported' });
259
+ expect(deps.acpCalls).toHaveLength(0);
260
+ expect(await getSessionRelation('never')).toBeNull();
261
+ });
262
+
263
+ test('claude and codex fork at the anchored message through the AIR extension', async () => {
264
+ for (const harness of ['claude', 'codex'] as const) {
265
+ await saveHarnessSession({
266
+ sessionId: 'acp-source',
267
+ harness,
268
+ agentSessionId: 'agent-1',
269
+ cwd: '/tmp/project',
270
+ });
271
+ const deps = fakeDeps(`acp-fork-${harness}`, { forkSupported: true });
272
+ await forkSession({ sourceSessionId: 'acp-source', anchorEntryId: 'a2' }, deps);
273
+ expect(deps.acpCalls).toEqual([
274
+ expect.objectContaining({
275
+ harness,
276
+ forkMeta: { jetbrains: { air: { fork: { version: 1, messageId: 'a2' } } } },
277
+ }),
278
+ ]);
279
+ }
280
+ });
281
+
282
+ test('a whole-chat claude fork sends no fork point', async () => {
283
+ await saveHarnessSession({
284
+ sessionId: 'acp-source',
285
+ harness: 'claude',
286
+ agentSessionId: 'agent-1',
287
+ cwd: '/tmp/project',
288
+ });
289
+ const deps = fakeDeps('acp-fork', { forkSupported: true });
290
+ await forkSession({ sourceSessionId: 'acp-source' }, deps);
291
+ expect(deps.acpCalls).toEqual([expect.objectContaining({ harness: 'claude' })]);
292
+ expect(deps.acpCalls[0]).not.toHaveProperty('forkMeta');
293
+ });
294
+
248
295
  test('a harness without fork support is refused before spawning', async () => {
249
296
  await saveHarnessSession({
250
297
  sessionId: 'acp-source',
@@ -36,6 +36,7 @@ import {
36
36
  transcriptTitle,
37
37
  } from '@/server/lib/omp/session/transcript-copy';
38
38
  import type { HarnessId } from '@/shared/lib/harness/catalog';
39
+ import { airForkPoint, harnessForksAtMessage } from '@/shared/lib/harness/fork';
39
40
  import type { SelectedModel } from '@/shared/types/models';
40
41
  import type { AgentImage } from '@/shared/types/omp/agent';
41
42
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
@@ -56,6 +57,7 @@ export type SessionForkErrorCode =
56
57
  | 'source_archived'
57
58
  | 'cwd_required'
58
59
  | 'anchor_not_found'
60
+ | 'anchor_unsupported'
59
61
  | 'fork_unsupported'
60
62
  | 'fork_requires_checkpoint'
61
63
  | 'fork_failed';
@@ -89,6 +91,8 @@ export interface ForkSessionDeps {
89
91
  harness: HarnessId;
90
92
  sessionId: string;
91
93
  forkAgentSessionId: string;
94
+ /** The fork point an agent extension reads; omitted forks the whole chat. */
95
+ forkMeta?: Record<string, unknown>;
92
96
  cwd: string;
93
97
  accessMode: ApprovalMode;
94
98
  model: SelectedModel | null;
@@ -228,7 +232,7 @@ export async function forkSession(
228
232
  if (input.anchorEntryId && !records.some((record) => record?.id === input.anchorEntryId)) {
229
233
  throw new SessionForkError(
230
234
  'anchor_not_found',
231
- `The transcript has no entry ${input.anchorEntryId}`,
235
+ `The transcript has no entry ${input.anchorEntryId}; a builtin command's row is stored by Kabmo only, so fork at a chat turn instead.`,
232
236
  );
233
237
  }
234
238
  const cutIndex = cutIndexFor(records, input.anchorEntryId ?? null);
@@ -255,6 +259,17 @@ export async function forkSession(
255
259
  if (!harness || harness === 'omp-rpc') {
256
260
  throw new SessionForkError('fork_unsupported', 'This session has no transcript to fork');
257
261
  }
262
+ // `session/fork` copies the agent's WHOLE history and takes no anchor.
263
+ // The AIR adapters (claude, codex) read a fork point from `_meta` and keep
264
+ // the history up to that message. Every other agent would silently hand
265
+ // back turns the user did not point at, so an anchor there is refused
266
+ // instead of being answered with the tip.
267
+ if (input.anchorEntryId && !harnessForksAtMessage(harness)) {
268
+ throw new SessionForkError(
269
+ 'anchor_unsupported',
270
+ `${harness} keeps this chat's history in its own store, so it can only be forked whole.`,
271
+ );
272
+ }
258
273
  if (!(await deps.probeForkSupported(harness))) {
259
274
  throw new SessionForkError('fork_unsupported', `${harness} does not support session/fork`);
260
275
  }
@@ -263,6 +278,7 @@ export async function forkSession(
263
278
  harness,
264
279
  sessionId: `__new__${Bun.randomUUIDv7()}`,
265
280
  forkAgentSessionId: source.agentSessionId || input.sourceSessionId,
281
+ ...(input.anchorEntryId ? { forkMeta: airForkPoint(input.anchorEntryId) } : {}),
266
282
  cwd,
267
283
  accessMode,
268
284
  model,
@@ -29,7 +29,7 @@ import { startAcpSession } from '@/server/lib/harness/spawn.server';
29
29
  import { getLiveSession, harnessOfSession, startNewRpcSession } from '@/server/lib/omp/rpc/session-registry';
30
30
  import { harnessProbeModels } from '@/server/lib/harness/probe-cache.server';
31
31
  import { getDb } from '@/server/db.server';
32
- import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
32
+ import { harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
33
33
  import type { SelectedModel } from '@/shared/types/models';
34
34
  import type { AgentImage } from '@/shared/types/omp/agent';
35
35
  import { MAX_SESSION_DEPTH } from '@/server/lib/sessions/relation-types';
@@ -122,7 +122,7 @@ export interface SpawnChildSessionResult {
122
122
 
123
123
  function harnessOf(value: string | null | undefined): HarnessId | null {
124
124
  if (!value) return null;
125
- return HARNESS_IDS.includes(value as HarnessId) ? (value as HarnessId) : null;
125
+ return harnessDescriptor(value) ? (value as HarnessId) : null;
126
126
  }
127
127
 
128
128
  /**
@@ -34,6 +34,7 @@ function prompt(overrides: Partial<WaitingPrompt> = {}): WaitingPrompt {
34
34
  pendingId: 'new-1',
35
35
  dependsOn: 'dep-a',
36
36
  dependsOnTitle: 'Session A',
37
+ targetSessionId: null,
37
38
  prompt: 'do the thing',
38
39
  attachments: [],
39
40
  model: null,
@@ -61,6 +62,8 @@ interface Harness {
61
62
  setRowWrittenAt(at: number | null): void;
62
63
  setQueued(queued: boolean): void;
63
64
  setDelivering(delivering: boolean): void;
65
+ /** Make an existing chat live, and record the commands sent to it. */
66
+ setExisting(sessionId: string): void;
64
67
  failSpawnWith(error: Error | null): void;
65
68
  failSendWith(error: Error | null): void;
66
69
  }
@@ -76,6 +79,7 @@ function harness(initial: WaitingPrompt[] = [prompt()]): Harness {
76
79
  let delivering = false;
77
80
  let spawnError: Error | null = null;
78
81
  let sendError: Error | null = null;
82
+ let existing: Record<string, { sessionId: string; isAlive(): boolean; isBusy(): boolean; send(command: Record<string, unknown>): Promise<unknown> }> = {};
79
83
  const sent: Harness['sent'] = {};
80
84
  const spawned: string[] = [];
81
85
  const writes: string[] = [];
@@ -100,6 +104,12 @@ function harness(initial: WaitingPrompt[] = [prompt()]): Harness {
100
104
  };
101
105
  },
102
106
  getSession: () => undefined,
107
+ ensureSessionLive: async (sessionId) => {
108
+ const host = existing[sessionId];
109
+ if (!host) return null;
110
+ sent[sessionId] = [];
111
+ return host;
112
+ },
103
113
  loadStreamStates: async () => streams,
104
114
  streamRowWrittenAt: async () => rowWrittenAt,
105
115
  hasQueuedItem: async () => queued,
@@ -159,6 +169,22 @@ function harness(initial: WaitingPrompt[] = [prompt()]): Harness {
159
169
  setDelivering: (next) => {
160
170
  delivering = next;
161
171
  },
172
+ setExisting: (sessionId) => {
173
+ sent[sessionId] = [];
174
+ existing = {
175
+ ...existing,
176
+ [sessionId]: {
177
+ sessionId,
178
+ isAlive: () => true,
179
+ isBusy: () => false,
180
+ async send(command) {
181
+ if (sendError) throw sendError;
182
+ sent[sessionId].push(command);
183
+ return null;
184
+ },
185
+ },
186
+ };
187
+ },
162
188
  failSpawnWith: (error) => {
163
189
  spawnError = error;
164
190
  },
@@ -275,4 +301,26 @@ describe('sweepWaitingPrompts', () => {
275
301
  expect(await sweepWaitingPrompts({ now: NOW, deps: h.deps })).toBe(0);
276
302
  expect(h.spawned).toEqual([]);
277
303
  });
304
+
305
+ // A NEXT prompt in a chat that already exists belongs to that chat. Spawning
306
+ // a second session would strand the text in a conversation the user never
307
+ // opened.
308
+ test('delivers a next prompt into the existing session it names', async () => {
309
+ const h = harness([prompt({ pendingId: null, targetSessionId: 'sess-open' })]);
310
+ h.setExisting('sess-open');
311
+ expect(await sweepWaitingPrompts({ now: NOW, deps: h.deps })).toBe(1);
312
+ expect(h.spawned).toEqual([]);
313
+ expect(h.sent['sess-open']).toEqual([{ type: 'prompt', message: 'do the thing' }]);
314
+ expect(h.writes).toContain('dispatched wait-1 sess-open');
315
+ });
316
+
317
+ // The target may itself be mid-turn when the dependency ends. omp refuses a
318
+ // prompt mid-turn and drops it, so the row stays `waiting` for a later sweep.
319
+ test('holds the prompt while its target session is still streaming', async () => {
320
+ const h = harness([prompt({ pendingId: null, targetSessionId: 'sess-open' })]);
321
+ h.setExisting('sess-open');
322
+ h.setStreams({ 'dep-a': { status: 'finish' }, 'sess-open': { status: 'stream' } });
323
+ expect(await sweepWaitingPrompts({ now: NOW, deps: h.deps })).toBe(0);
324
+ expect(h.sent['sess-open']).toEqual([]);
325
+ });
278
326
  });
@@ -31,6 +31,8 @@ import {
31
31
  type AgentSessionWrapper,
32
32
  } from '@/server/lib/omp/rpc/manager';
33
33
  import { getRpcSession } from '@/server/lib/omp/rpc/session-registry';
34
+ import { ensureSessionLive } from '@/server/lib/sessions/dispatch.server';
35
+ import type { QueueDeliveryHost } from '@/server/lib/queue/delivery.server';
34
36
  import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
35
37
  import { hasQueuedItem } from '@/server/lib/queue/store.server';
36
38
  import { hasPendingDelivery } from '@/server/lib/queue/delivery.server';
@@ -86,6 +88,8 @@ export interface WaitingDeps {
86
88
  modeEnv?: Record<string, string>,
87
89
  ): Promise<{ session: WaitingSessionHandle; realSessionId: string }>;
88
90
  getSession(sessionId: string): AgentSessionWrapper | undefined;
91
+ /** Wake an EXISTING chat so a held next prompt can be delivered into it. */
92
+ ensureSessionLive(sessionId: string): Promise<QueueDeliveryHost | null>;
89
93
  loadStreamStates(): Promise<StreamRowMap>;
90
94
  /** Epoch ms of a session's last status write, or null when unknown. */
91
95
  streamRowWrittenAt(sessionId: string): Promise<number | null>;
@@ -113,6 +117,7 @@ function defaultDeps(): WaitingDeps {
113
117
  return {
114
118
  startNewRpcSession,
115
119
  getSession: getRpcSession,
120
+ ensureSessionLive,
116
121
  loadStreamStates,
117
122
  streamRowWrittenAt,
118
123
  hasQueuedItem,
@@ -181,6 +186,16 @@ async function dispatchWaitingPrompt(
181
186
  prompt: WaitingPrompt,
182
187
  deps: WaitingDeps,
183
188
  ): Promise<{ sessionId: string }> {
189
+ // A next prompt in a chat that already exists is delivered THERE. Spawning
190
+ // would create a second session for text the user wrote in the first one.
191
+ if (prompt.targetSessionId) {
192
+ const target = await deps.ensureSessionLive(prompt.targetSessionId);
193
+ if (!target) throw new Error(`Session ${prompt.targetSessionId} could not be woken for the held prompt.`);
194
+ const send = (command: Record<string, unknown>) => target.send(command);
195
+ await applyModelSnapshot(send, prompt.model);
196
+ await send(promptCommand({ text: prompt.prompt, attachments: prompt.attachments, model: prompt.model }));
197
+ return { sessionId: prompt.targetSessionId };
198
+ }
184
199
  const accessMode = prompt.model?.accessMode ?? (await deps.loadPersistedAccessMode());
185
200
  const modeEnv = prompt.modes ? kabmoModeEnv(prompt.modes) : undefined;
186
201
  const { session, realSessionId } = await deps.startNewRpcSession(prompt.cwd, accessMode, modeEnv);
@@ -215,6 +230,13 @@ export async function sweepWaitingPrompts(
215
230
  for (const prompt of waiting) {
216
231
  const state = await readDependencyState(prompt.dependsOn, deps, streams);
217
232
  if (!dependencyVerdict(state, now).settled) continue;
233
+ // A target that is itself mid-turn refuses a prompt (omp drops it). The
234
+ // prompt is still wanted, so it stays `waiting` for the next sweep — the
235
+ // same conservative rule the dependency's own queue uses.
236
+ if (prompt.targetSessionId) {
237
+ const target = await readDependencyState(prompt.targetSessionId, deps, streams);
238
+ if (!dependencyVerdict(target, now).settled) continue;
239
+ }
218
240
  if (!(await deps.claimWaitingPrompt(prompt.id))) continue;
219
241
  try {
220
242
  const { sessionId } = await withTimeout(