@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
@@ -21,8 +21,10 @@
21
21
  import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
22
22
  import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
23
23
  import { methodNotAllowed } from '@/server/lib/route-adapter';
24
- import { runScheduledTask } from '@/server/lib/schedule/runtime.server';
24
+ import { runScheduledTask, isTaskRunning } from '@/server/lib/schedule/runtime.server';
25
25
  import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
26
+ import { isValidTimeZone, serverTimeZone } from '@/shared/lib/schedule/timezone';
27
+ import { harnessDescriptor } from '@/shared/lib/harness/catalog';
26
28
  import {
27
29
  createScheduledTask,
28
30
  deleteScheduledTask,
@@ -41,7 +43,7 @@ import {
41
43
  } from '@/server/routes/schedule/body';
42
44
 
43
45
  export async function loader(_args: LoaderFunctionArgs) {
44
- return json({ tasks: await listScheduledTasks() }, { headers: NO_STORE_HEADERS });
46
+ return json({ tasks: await listScheduledTasks(), serverTimeZone: serverTimeZone() }, { headers: NO_STORE_HEADERS });
45
47
  }
46
48
 
47
49
  /** POST — create a task. */
@@ -49,7 +51,7 @@ async function createTask({ request }: ActionFunctionArgs) {
49
51
  const body = readTaskBody(await request.json().catch(() => null));
50
52
  if (!body) {
51
53
  return json(
52
- { error: 'Expected { prompt, kind: once|every|cron, spec } with a non-empty prompt and spec.' },
54
+ { error: 'Expected { prompt, kind: once|every|cron, spec, harness?, timezone? } with a non-empty prompt and spec.' },
53
55
  { status: 400 },
54
56
  );
55
57
  }
@@ -59,10 +61,14 @@ async function createTask({ request }: ActionFunctionArgs) {
59
61
  prompt: body.prompt,
60
62
  kind: body.kind,
61
63
  spec: body.spec,
64
+ harness: body.harness,
65
+ timezone: body.timezone,
62
66
  folderId: body.folderId,
63
67
  cwd: await resolveTaskCwd(body.folderId),
64
68
  sessionId: body.sessionId,
65
- model: body.model ?? (await resolveDefaultTaskModel()),
69
+ // The composer's persisted model is an omp model; an ACP harness has its
70
+ // own catalog, so a task on one starts on that harness's default instead.
71
+ model: body.model ?? (body.harness === 'omp-rpc' ? await resolveDefaultTaskModel() : null),
66
72
  });
67
73
  emitRealtimeSignal('schedule-changed');
68
74
  return json({ task, tasks: await listScheduledTasks() });
@@ -94,6 +100,20 @@ async function patchTask({ request }: ActionFunctionArgs) {
94
100
  }
95
101
  patch.spec = raw.spec.trim();
96
102
  }
103
+ if (raw.harness !== undefined) {
104
+ const harness = optionalText(raw.harness);
105
+ if (!harness || !harnessDescriptor(harness)) {
106
+ return json({ error: 'harness must be a known harness id' }, { status: 400 });
107
+ }
108
+ patch.harness = harness;
109
+ }
110
+ if (raw.timezone !== undefined) {
111
+ const timezone = optionalText(raw.timezone);
112
+ if (!timezone || !isValidTimeZone(timezone)) {
113
+ return json({ error: 'timezone must be an IANA zone, e.g. Europe/Kyiv' }, { status: 400 });
114
+ }
115
+ patch.timezone = timezone;
116
+ }
97
117
  if (raw.folderId !== undefined) {
98
118
  patch.folderId = typeof raw.folderId === 'number' ? raw.folderId : null;
99
119
  patch.cwd = await resolveTaskCwd(patch.folderId);
@@ -137,6 +157,10 @@ async function runNow({ request }: ActionFunctionArgs) {
137
157
  const task = await getScheduledTask(id);
138
158
  if (!task) return json({ error: 'Task not found' }, { status: 404 });
139
159
  if (!task.prompt.trim()) return json({ error: 'This task has no prompt to run' }, { status: 400 });
160
+ // A second click (or a click while the scheduled fire is still dispatching)
161
+ // would spawn a second omp session for the same prompt. The runtime tracks
162
+ // the in-flight run; this is the user-facing refusal.
163
+ if (isTaskRunning(id)) return json({ error: 'This task is already running.' }, { status: 409 });
140
164
  const sessionId = await runScheduledTask(task, { manual: true });
141
165
  const updated = await getScheduledTask(id);
142
166
  if (!sessionId) {
@@ -1,34 +1,17 @@
1
1
  import { json } from '@/server/lib/remix-compat';
2
2
  import type { ActionFunctionArgs, LoaderFunctionArgs } from '@/server/lib/remix-compat';
3
3
  import { methodNotAllowed } from '@/server/lib/route-adapter';
4
- import type { DbClient } from '@/server/lib/db/client';
5
4
  import { getDb } from '@/server/db.server';
6
5
  import { DEFAULT_MCP_SERVERS } from '@/client/data/settings/mcp';
7
6
  import { isMockMode } from '@/server/mock.server';
8
- import { createSettingsListStore } from '@/server/lib/db/settings-store';
7
+ import { mcpStore, readCustomMcpServers, writeCustomMcpServers } from '@/server/lib/mcp/store.server';
9
8
  import { resolveRoot } from '@/server/lib/fs/root';
10
9
  import type { McpServerItem } from '@/shared/types';
11
10
  import { deleteProjectMcpServer, deleteUserMcpServer, nativeToServerItem, readProjectMcpConfig, readUserMcpConfig, redactEnvVars, writeProjectMcpServer, writeUserMcpServer } from '@/server/lib/omp/config/mcp';
12
11
 
13
- const mcpStore = createSettingsListStore<McpServerItem>({
14
- key: 'omp_mcp_servers',
15
- mockDefaults: DEFAULT_MCP_SERVERS,
16
- idOf: (server) => server.id,
17
- singular: 'server',
18
- plural: 'servers',
19
- });
20
-
21
12
  const NATIVE_USER_PREFIX = 'omp-user-';
22
13
  const NATIVE_PROJECT_PREFIX = 'omp-project-';
23
14
 
24
- async function readCustomServers(db: DbClient): Promise<McpServerItem[]> {
25
- return mcpStore.readStored(db, { absent: isMockMode() ? DEFAULT_MCP_SERVERS : [] });
26
- }
27
-
28
- async function writeCustomServers(db: DbClient, servers: McpServerItem[]): Promise<void> {
29
- await mcpStore.write(db, servers);
30
- }
31
-
32
15
  /** Resolve a client-supplied path to a registered workspace project root. */
33
16
  async function validateProjectPath(raw: unknown): Promise<string | null> {
34
17
  if (typeof raw !== 'string' || !raw.trim()) return null;
@@ -126,7 +109,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
126
109
  return json({ error: 'Project is not a registered workspace folder' }, { status: 400 });
127
110
  }
128
111
 
129
- let servers = await mcpStore.read(db);
112
+ let servers = await readCustomMcpServers(db);
130
113
 
131
114
  if (includeNative && !mock) {
132
115
  servers = await mergeServers(servers, projectPath ?? undefined);
@@ -159,7 +142,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
159
142
  return json({ error: 'Project is not a registered workspace folder' }, { status: 400 });
160
143
  }
161
144
 
162
- let custom = await readCustomServers(db);
145
+ let custom = await readCustomMcpServers(db);
163
146
  const target = custom.find((server) => server.id === id);
164
147
 
165
148
  // Native omp server deletion (id prefix omp-user-/omp-project-) hits mcp.json directly.
@@ -167,7 +150,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
167
150
  const name = id.slice(NATIVE_USER_PREFIX.length);
168
151
  try { await deleteUserMcpServer(name); } catch {}
169
152
  custom = custom.filter((server) => server.name.toLowerCase() !== name.toLowerCase());
170
- await writeCustomServers(db, custom);
153
+ await writeCustomMcpServers(db, custom);
171
154
  return json({ success: true, servers: await mergeServers(custom, projectPath ?? undefined) });
172
155
  }
173
156
 
@@ -178,7 +161,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
178
161
  }
179
162
  try { await deleteProjectMcpServer(projectPath, name); } catch {}
180
163
  custom = custom.filter((server) => server.name.toLowerCase() !== name.toLowerCase());
181
- await writeCustomServers(db, custom);
164
+ await writeCustomMcpServers(db, custom);
182
165
  return json({ success: true, servers: await mergeServers(custom, projectPath) });
183
166
  }
184
167
 
@@ -196,7 +179,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
196
179
  } catch {}
197
180
  }
198
181
  custom = custom.filter((server) => server.id !== id);
199
- await writeCustomServers(db, custom);
182
+ await writeCustomMcpServers(db, custom);
200
183
  return json({ success: true, servers: isMockMode() ? custom : await mergeServers(custom, projectPath ?? undefined) });
201
184
  }
202
185
 
@@ -206,13 +189,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
206
189
  // Backward-compatible explicit user-scope write: { scope: "user", name, server }
207
190
  if (body.scope === 'user' && typeof body.name === 'string' && body.server) {
208
191
  await writeUserMcpServer(body.name, toNativeServer(body.server));
209
- const custom = await readCustomServers(db);
192
+ const custom = await readCustomMcpServers(db);
210
193
  return json({ success: true, servers: await mergeServers(custom) });
211
194
  }
212
195
 
213
196
  if (Array.isArray(body) || Array.isArray(body.servers)) {
214
197
  const updatedServers: McpServerItem[] = Array.isArray(body) ? body : body.servers;
215
- await writeCustomServers(db, updatedServers);
198
+ await writeCustomMcpServers(db, updatedServers);
216
199
  return json({ success: true, servers: isMockMode() ? updatedServers : await mergeServers(updatedServers) });
217
200
  }
218
201
 
@@ -257,7 +240,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
257
240
  const custom = previousName
258
241
  ? upserted.filter((entry) => entry.name.toLowerCase() !== previousName.toLowerCase())
259
242
  : upserted;
260
- await writeCustomServers(db, custom);
243
+ await writeCustomMcpServers(db, custom);
261
244
 
262
245
  return json({ success: true, servers: mock ? custom : await mergeServers(custom, projectPath ?? undefined) });
263
246
  }
@@ -33,6 +33,7 @@ import {
33
33
  import { attachmentHasPayload } from '@/shared/lib/chat/attachments';
34
34
  import { parseModeSelection } from '@/server/lib/omp/mode/request';
35
35
  import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
36
+ import { resolveSessionRef } from '@/server/lib/sessions/resolve.server';
36
37
  import { isMockMode } from '@/server/mock.server';
37
38
 
38
39
  /** GET — every prompt a client may still need (waiting + recent outcomes). */
@@ -61,6 +62,19 @@ async function createPrompt(request: Request) {
61
62
  }
62
63
  const prompt = typeof body.prompt === 'string' ? body.prompt : '';
63
64
  const attachments = Array.isArray(body.attachments) ? body.attachments : [];
65
+ // A NEXT prompt in an existing chat names its target; a pending chat names
66
+ // none and the dispatch spawns the session. The two are exclusive: a prompt
67
+ // with both would either spawn a second chat or silently pick one.
68
+ const targetSessionId = typeof body.targetSessionId === 'string' ? body.targetSessionId.trim() : '';
69
+ if (targetSessionId && !isSinglePathSegment(targetSessionId)) {
70
+ return json({ error: 'The target session id is not valid', code: 'target_invalid' }, { status: 400 });
71
+ }
72
+ if (targetSessionId && targetSessionId === dependsOn) {
73
+ return json(
74
+ { error: 'A prompt cannot wait for the session it is sent to.', code: 'target_self' },
75
+ { status: 400 },
76
+ );
77
+ }
64
78
  // Same rule the composer's own send guard applies: an empty prompt is not a
65
79
  // prompt. Without it a row would be created, spawn a session, and deliver
66
80
  // nothing to it.
@@ -68,11 +82,15 @@ async function createPrompt(request: Request) {
68
82
  return json({ error: 'The prompt is empty', code: 'prompt_required' }, { status: 400 });
69
83
  }
70
84
  const cwd = typeof body.cwd === 'string' ? body.cwd.trim() : '';
85
+ // An existing chat already has a home: its session's own cwd is the truthful
86
+ // answer, and a client that forgot to send one must not be refused. The spawn
87
+ // path still requires an absolute directory (a new chat has no other source).
88
+ const resolvedCwd = cwd || (targetSessionId ? (await resolveSessionRef(targetSessionId)).cwd ?? '' : '');
71
89
  // `isAbsolute`, not `startsWith('/')`: a Windows workspace names its directory
72
90
  // `C:\…`, and the POSIX-only test refused every hold there with
73
91
  // `cwd_required` — the prompt was sent immediately instead of being held
74
92
  // (measured on the Windows CI leg of `waiting-prompt.e2e.ts`).
75
- if (!isAbsolute(cwd)) {
93
+ if (!isAbsolute(resolvedCwd)) {
76
94
  return json({ error: 'An absolute working directory is required', code: 'cwd_required' }, { status: 400 });
77
95
  }
78
96
  if (await isDependencySettled(dependsOn)) {
@@ -86,11 +104,12 @@ async function createPrompt(request: Request) {
86
104
  pendingId: typeof body.pendingId === 'string' ? body.pendingId : null,
87
105
  dependsOn,
88
106
  dependsOnTitle: typeof body.dependsOnTitle === 'string' ? body.dependsOnTitle : null,
107
+ targetSessionId: targetSessionId || null,
89
108
  prompt,
90
109
  attachments,
91
110
  model: body.model,
92
111
  modes: body.modes === undefined ? null : parseModeSelection(asRecord(body.modes)),
93
- cwd,
112
+ cwd: resolvedCwd,
94
113
  folderId: typeof body.folderId === 'number' ? body.folderId : null,
95
114
  });
96
115
  emitRealtimeSignal('waiting-changed');
@@ -118,4 +118,25 @@ describe('/api/waiting — the rest of the validation order', () => {
118
118
  await call({ dependsOn: 'sess-anything', prompt: 'x', cwd: 'relative/path' });
119
119
  expect(await listWaitingPrompts()).toHaveLength(0);
120
120
  });
121
+
122
+ test('a prompt cannot wait for the chat it is sent to', async () => {
123
+ const res = await call({ dependsOn: 'sess-a', targetSessionId: 'sess-a', prompt: 'x', cwd: '/tmp/x' });
124
+ expect(res.status).toBe(400);
125
+ expect(res.body.code).toBe('target_self');
126
+ });
127
+
128
+ test('a target id that could name a path is refused', async () => {
129
+ const res = await call({ dependsOn: 'sess-a', targetSessionId: '../sess', prompt: 'x', cwd: '/tmp/x' });
130
+ expect(res.status).toBe(400);
131
+ expect(res.body.code).toBe('target_invalid');
132
+ });
133
+
134
+ // An existing chat's home is its session's own cwd. When neither the client
135
+ // nor the session can name one, the hold is refused rather than stored with
136
+ // an empty directory for a later sweep to spawn into.
137
+ test('a target session with no resolvable cwd is refused', async () => {
138
+ const res = await call({ dependsOn: 'sess-a', targetSessionId: 'unknown-session', prompt: 'x' });
139
+ expect(res.status).toBe(400);
140
+ expect(res.body.code).toBe('cwd_required');
141
+ });
121
142
  });
@@ -17,7 +17,7 @@
17
17
  * known agent name.
18
18
  */
19
19
 
20
- import { HARNESS_CATALOG, HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
20
+ import { harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
21
21
 
22
22
  export interface HarnessDelegation {
23
23
  harness: HarnessId;
@@ -59,7 +59,7 @@ const HARNESS_ALIASES: Readonly<Record<string, HarnessId>> = {
59
59
  };
60
60
 
61
61
  function harnessIdFor(name: string): HarnessId | null {
62
- return HARNESS_ALIASES[name] ?? (HARNESS_IDS.includes(name as HarnessId) ? (name as HarnessId) : null);
62
+ return HARNESS_ALIASES[name] ?? (harnessDescriptor(name) ? (name as HarnessId) : null);
63
63
  }
64
64
 
65
65
  /**
@@ -182,7 +182,7 @@ export function formatDelegationPrompt(plan: DelegationPlan): string {
182
182
  const model = delegation.model ?? 'default model';
183
183
  lines.push(
184
184
  '',
185
- `${index + 1}. ${HARNESS_CATALOG[delegation.harness]?.label ?? delegation.harness} · ${model}`,
185
+ `${index + 1}. ${harnessDescriptor(delegation.harness)?.label ?? delegation.harness} · ${model}`,
186
186
  delegationCommand(delegation, index),
187
187
  );
188
188
  });
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The anchor a per-message Fork carries. Only a transcript Kabmo can read can
8
+ * be cut at a message; an agent that keeps its own history forks the chat whole
9
+ * — except the adapters that read the AIR fork point, which fork at an
10
+ * assistant message.
11
+ */
12
+
13
+ import { describe, expect, test } from 'bun:test';
14
+ import { canForkAt, forkAnchorFor } from '@/shared/lib/chat/timeline/fork-anchor';
15
+ import { canForkChat, forkCapability } from '@/shared/lib/harness/fork';
16
+
17
+ describe('forkCapability', () => {
18
+ test('omp and the AIR adapters fork at a message', () => {
19
+ expect(forkCapability('omp-rpc')).toBe('message');
20
+ expect(forkCapability('omp-acp')).toBe('message');
21
+ expect(forkCapability('claude')).toBe('message');
22
+ expect(forkCapability('codex')).toBe('message');
23
+ });
24
+
25
+ test('a whole-chat-only harness is tip', () => {
26
+ expect(forkCapability('opencode')).toBe('tip');
27
+ expect(forkCapability('minimax')).toBe('tip');
28
+ expect(forkCapability('zcode')).toBe('tip');
29
+ });
30
+
31
+ test('a harness with no session/fork is none', () => {
32
+ expect(forkCapability('qwen')).toBe('none');
33
+ expect(forkCapability('dsh')).toBe('none');
34
+ expect(forkCapability('antigravity')).toBe('none');
35
+ });
36
+ });
37
+
38
+ describe('canForkChat', () => {
39
+ test('the probe is authoritative when it has an answer', () => {
40
+ expect(canForkChat('qwen', true)).toBe(true);
41
+ expect(canForkChat('claude', false)).toBe(false);
42
+ });
43
+
44
+ test('without a probe the expected capability decides', () => {
45
+ expect(canForkChat('zcode')).toBe(true);
46
+ expect(canForkChat('qwen')).toBe(false);
47
+ });
48
+ });
49
+
50
+ describe('canForkAt', () => {
51
+ test('omp forks at either row', () => {
52
+ expect(canForkAt('omp-rpc', 'user')).toBe(true);
53
+ expect(canForkAt('omp-acp', 'assistant')).toBe(true);
54
+ });
55
+
56
+ test('an AIR adapter forks at an assistant row only', () => {
57
+ expect(canForkAt('claude', 'assistant')).toBe(true);
58
+ expect(canForkAt('codex', 'assistant')).toBe(true);
59
+ expect(canForkAt('claude', 'user')).toBe(false);
60
+ expect(canForkAt('codex', 'user')).toBe(false);
61
+ });
62
+
63
+ test('a whole-chat-only harness forks at neither row', () => {
64
+ expect(canForkAt('zcode', 'assistant')).toBe(false);
65
+ expect(canForkAt('opencode', 'user')).toBe(false);
66
+ });
67
+
68
+ test('an unresolved harness keeps the historical allow', () => {
69
+ expect(canForkAt(undefined, 'user')).toBe(true);
70
+ });
71
+ });
72
+
73
+ describe('forkAnchorFor', () => {
74
+ test('an omp chat forks at the clicked message, user or assistant', () => {
75
+ expect(forkAnchorFor('omp-rpc', 'u2', 'user')).toBe('u2');
76
+ expect(forkAnchorFor('omp-acp', 'a2', 'assistant')).toBe('a2');
77
+ });
78
+
79
+ test('claude and codex fork at an assistant message through the AIR extension', () => {
80
+ expect(forkAnchorFor('claude', 'a2', 'assistant')).toBe('a2');
81
+ expect(forkAnchorFor('codex', 'a2', 'assistant')).toBe('a2');
82
+ });
83
+
84
+ test('an AIR adapter has no fork point on a user row', () => {
85
+ expect(forkAnchorFor('claude', 'u2', 'user')).toBeNull();
86
+ expect(forkAnchorFor('codex', 'u2', 'user')).toBeNull();
87
+ });
88
+
89
+ test('a harness with its own store and no fork point forks the whole chat', () => {
90
+ expect(forkAnchorFor('zcode', 'a2', 'assistant')).toBeNull();
91
+ expect(forkAnchorFor('opencode', 'u2', 'user')).toBeNull();
92
+ });
93
+
94
+ test('an unresolved harness keeps the anchor', () => {
95
+ expect(forkAnchorFor(undefined, 'u2', 'user')).toBe('u2');
96
+ });
97
+ });
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The anchor a per-message Fork may carry.
8
+ *
9
+ * A fork cuts the transcript Kabmo can read, so the anchor is only meaningful
10
+ * where that transcript exists (`harnessHasLocalTranscript`). An agent that
11
+ * keeps its history in its own store forks the chat WHOLE — `session/fork`
12
+ * takes no anchor — so the anchor is dropped here and the composer's preview
13
+ * shows every row the branch will hold, instead of promising a cut the agent
14
+ * cannot make.
15
+ *
16
+ * `claude` is the exception: claude-agent-acp reads a fork point from
17
+ * `_meta.jetbrains.air.fork` (the AIR extension) and keeps the history up to
18
+ * that message. Its resolver only groups ASSISTANT entries, so a user row has
19
+ * no fork point there and stays a whole-chat fork.
20
+ */
21
+
22
+ import { harnessHasLocalTranscript } from '@/shared/lib/harness/transcript';
23
+ import { forkCapability } from '@/shared/lib/harness/fork';
24
+
25
+ /** The two rows that offer Fork: a user turn and an assistant run footer. */
26
+ export type ForkAnchorRole = 'user' | 'assistant';
27
+
28
+ /**
29
+ * Whether this harness can fork at a row of this role at all. The UI asks this
30
+ * before drawing the button: a control that can only answer "whole chat" (or
31
+ * nothing) is not a per-message fork.
32
+ */
33
+ export function canForkAt(
34
+ harness: string | null | undefined,
35
+ role: ForkAnchorRole,
36
+ ): boolean {
37
+ if (forkCapability(harness) !== 'message') return false;
38
+ return harnessHasLocalTranscript(harness) || role === 'assistant';
39
+ }
40
+
41
+ export function forkAnchorFor(
42
+ harness: string | null | undefined,
43
+ messageId: string,
44
+ role: ForkAnchorRole,
45
+ ): string | null {
46
+ return canForkAt(harness, role) ? messageId : null;
47
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The slice a fork preview shows.
8
+ *
9
+ * It mirrors the server cut (`cutIndexFor` in `fork.server.ts`), because a
10
+ * preview that ends on a different row than the branch file does is a promise
11
+ * the first send breaks.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import { forkPreviewMessages } from '@/shared/lib/chat/timeline/fork-preview';
16
+ import type { ChatMessageData } from '@/shared/types';
17
+
18
+ const row = (id: string, role: ChatMessageData['role']): ChatMessageData => ({ id, role, content: id });
19
+
20
+ // u1 a1 u2 a2 u3 a3 — a turn is a user row plus everything after it.
21
+ const transcript: ChatMessageData[] = [
22
+ row('u1', 'user'),
23
+ row('a1', 'ai'),
24
+ row('u2', 'user'),
25
+ row('a2', 'ai'),
26
+ row('u3', 'user'),
27
+ row('a3', 'ai'),
28
+ ];
29
+
30
+ describe('forkPreviewMessages', () => {
31
+ test('no anchor is the tip: the whole transcript', () => {
32
+ expect(forkPreviewMessages(transcript, null).map((m) => m.id)).toEqual([
33
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
34
+ ]);
35
+ });
36
+
37
+ test('an anchor the transcript does not carry falls back to the tip', () => {
38
+ // A reload can outlive a message the source no longer has; the fork then
39
+ // branches at the tip, so the preview must not claim otherwise.
40
+ expect(forkPreviewMessages(transcript, 'gone').map((m) => m.id)).toEqual([
41
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
42
+ ]);
43
+ });
44
+
45
+ test('a user anchor branches BEFORE that turn', () => {
46
+ expect(forkPreviewMessages(transcript, 'u2').map((m) => m.id)).toEqual(['u1', 'a1']);
47
+ });
48
+
49
+ test('an assistant anchor keeps the turn that contains it', () => {
50
+ expect(forkPreviewMessages(transcript, 'a2').map((m) => m.id)).toEqual([
51
+ 'u1', 'a1', 'u2', 'a2',
52
+ ]);
53
+ });
54
+
55
+ test('the first user turn forks to an empty transcript', () => {
56
+ expect(forkPreviewMessages(transcript, 'u1')).toEqual([]);
57
+ });
58
+
59
+ test('an anchor on the last turn keeps the whole transcript', () => {
60
+ expect(forkPreviewMessages(transcript, 'a3')).toHaveLength(6);
61
+ });
62
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The source transcript a fork will carry, for the pending composer's preview.
8
+ *
9
+ * A fork is composed as an EMPTY chat today, so the operator picks the first
10
+ * turn without seeing the history that turn continues. This slices the source's
11
+ * rows the way the server slices its JSONL (`cutIndexFor` in
12
+ * `fork.server.ts`), so what the preview shows is exactly what the branch file
13
+ * will hold:
14
+ *
15
+ * - an anchor on a USER turn branches BEFORE it — that message is the one
16
+ * being replaced, so it is not part of the fork;
17
+ * - an anchor anywhere else (an assistant reply, a tool row) branches AFTER
18
+ * the turn that contains it — the reply the user pointed at is kept;
19
+ * - no anchor, or an id the transcript does not carry, is the tip: everything.
20
+ */
21
+
22
+ import type { ChatMessageData } from '@/shared/types';
23
+
24
+ export function forkPreviewMessages(
25
+ messages: ChatMessageData[],
26
+ anchorEntryId: string | null | undefined,
27
+ ): ChatMessageData[] {
28
+ if (!anchorEntryId) return messages;
29
+ const anchorIndex = messages.findIndex((message) => message.id === anchorEntryId);
30
+ if (anchorIndex === -1) return messages;
31
+ if (messages[anchorIndex]?.role === 'user') return messages.slice(0, anchorIndex);
32
+ const nextTurn = messages.findIndex(
33
+ (message, index) => index > anchorIndex && message.role === 'user',
34
+ );
35
+ return messages.slice(0, nextTurn === -1 ? messages.length : nextTurn);
36
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The content fingerprint the editor uses to decide whether the file on disk is
8
+ * still the one its buffer holds.
9
+ *
10
+ * An mtime is the wrong question. `git checkout`, a formatter, a `touch` and a
11
+ * save that writes identical bytes all move it without changing a byte, so an
12
+ * mtime-only watcher reloads a tab (and loses the caret) over a file that is
13
+ * exactly what the reader already has. The inverse also happens: one
14
+ * millisecond of filesystem clock granularity can hide two writes, which the
15
+ * save path's conflict guard documents as its own blind spot.
16
+ *
17
+ * SHA-256 rather than MD5 because it comes from WebCrypto, which the page and
18
+ * the server both already have with no import; this is a change DETECTOR, not a
19
+ * security boundary.
20
+ *
21
+ * Every producer hashes the SAME thing — the UTF-8 encoding of the text the
22
+ * read route returned — so the server's digest of a file, the digest of the
23
+ * bytes a client wrote, and the digest of the buffer the client holds are the
24
+ * same string whenever the bytes are.
25
+ */
26
+ export async function contentHash(text: string): Promise<string> {
27
+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
28
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
29
+ }
@@ -24,7 +24,7 @@
24
24
  * own body is `exec "$(dirname "$0")/opencode" "$@"`. A second catalog entry for
25
25
  * the same binary would offer two tabs that run one program.
26
26
  */
27
- export type HarnessId =
27
+ export type BuiltinHarnessId =
28
28
  | 'omp-rpc'
29
29
  | 'omp-acp'
30
30
  | 'claude'
@@ -48,8 +48,19 @@ export type HarnessId =
48
48
  * bridge and the bridge finds the CLI by itself. */
49
49
  | 'zcode';
50
50
 
51
- /** Every harness this build knows how to launch or display. */
52
- export const HARNESS_IDS: readonly HarnessId[] = [
51
+ /**
52
+ * A harness id: one this build ships, or one the user added.
53
+ *
54
+ * The union stays for the built-ins so a typo in a table is still a compile
55
+ * error, while `(string & {})` lets a runtime id through without widening every
56
+ * call site to `string` (which would lose the autocomplete that makes the
57
+ * built-in list discoverable). Tables that must be COMPLETE are keyed by
58
+ * `BuiltinHarnessId`; tables that may be partial use `HarnessId`.
59
+ */
60
+ export type HarnessId = BuiltinHarnessId | (string & {});
61
+
62
+ /** Every harness this build ships. Custom ids are added at runtime. */
63
+ export const HARNESS_IDS: readonly BuiltinHarnessId[] = [
53
64
  'omp-rpc',
54
65
  'omp-acp',
55
66
  'claude',
@@ -115,13 +126,15 @@ export type HarnessGlyph =
115
126
  | 'qwen'
116
127
  | 'cursor'
117
128
  | 'antigravity'
118
- | 'zcode';
129
+ | 'zcode'
130
+ /** A user-added ACP harness: no vendor mark, drawn as its initial. */
131
+ | 'custom';
119
132
 
120
133
  /**
121
134
  * The catalog. Order is the tab/legend order: omp's two surfaces first because
122
135
  * they are the default, then the adapters in the order the research measured.
123
136
  */
124
- export const HARNESS_CATALOG: Readonly<Record<HarnessId, HarnessDescriptor>> = {
137
+ export const HARNESS_CATALOG: Readonly<Record<BuiltinHarnessId, HarnessDescriptor>> = {
125
138
  'omp-rpc': { id: 'omp-rpc', label: 'omp', initial: 'o', transport: 'rpc', glyph: 'omp', builtIn: true },
126
139
  'omp-acp': { id: 'omp-acp', label: 'omp (ACP)', initial: 'o', transport: 'acp', glyph: 'omp' },
127
140
  claude: { id: 'claude', label: 'claude', initial: 'A', transport: 'acp', glyph: 'claudecode' },
@@ -150,11 +163,40 @@ export const HARNESS_CATALOG: Readonly<Record<HarnessId, HarnessDescriptor>> = {
150
163
  */
151
164
  export const DEFAULT_HARNESS_ID: HarnessId = 'omp-rpc';
152
165
 
166
+ /**
167
+ * Descriptors for harnesses the user added, process-wide.
168
+ *
169
+ * The server fills this from `custom_harnesses` at boot and after every write;
170
+ * the client fills it from the `/api/harness` payload. One overlay rather than a
171
+ * second catalog keeps `harnessDescriptor` synchronous for the ~40 call sites
172
+ * that only need a label or a transport.
173
+ */
174
+ const customDescriptors = new Map<string, HarnessDescriptor>();
175
+
176
+ /** Replace the custom descriptors. Built-in ids are ignored: the static table wins. */
177
+ export function registerHarnessDescriptors(descriptors: readonly HarnessDescriptor[]): void {
178
+ customDescriptors.clear();
179
+ for (const descriptor of descriptors) {
180
+ if ((HARNESS_CATALOG as Record<string, HarnessDescriptor | undefined>)[descriptor.id]) continue;
181
+ customDescriptors.set(descriptor.id, descriptor);
182
+ }
183
+ }
184
+
185
+ /** True for an id this build ships (not a user-added one). */
186
+ export function isBuiltinHarness(id: string | null | undefined): id is BuiltinHarnessId {
187
+ return Boolean(id) && (HARNESS_IDS as readonly string[]).includes(id as string);
188
+ }
189
+
190
+ /** Every id this process knows: the built-ins, then the custom ones. */
191
+ export function harnessIds(): string[] {
192
+ return [...HARNESS_IDS, ...customDescriptors.keys()];
193
+ }
194
+
153
195
  /** The descriptor for an id, or undefined for a value this build does not know
154
196
  * (a newer adapter's id arriving over the wire). */
155
197
  export function harnessDescriptor(id: string | null | undefined): HarnessDescriptor | undefined {
156
198
  if (!id) return undefined;
157
- return (HARNESS_CATALOG as Record<string, HarnessDescriptor | undefined>)[id];
199
+ return (HARNESS_CATALOG as Record<string, HarnessDescriptor | undefined>)[id] ?? customDescriptors.get(id);
158
200
  }
159
201
 
160
202
  /**