@kabmo-labs/kabmo 0.25.0 → 0.27.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 (241) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +448 -444
  3. package/dist/client/static/js/index-32rpkj6b.css +1 -0
  4. package/dist/client/static/js/{index-ga8cbpt4.js → index-e3qh2yps.js} +950 -950
  5. package/package.json +1 -1
  6. package/src/client/components/common/Toast.test.tsx +28 -2
  7. package/src/client/components/common/Toast.tsx +21 -9
  8. package/src/client/components/common/session-actions-menu/index.tsx +38 -12
  9. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  10. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  11. package/src/client/components/common/session-branch/index.tsx +169 -0
  12. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  13. package/src/client/components/common/session-branch/style.ts +29 -0
  14. package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
  15. package/src/client/components/common/session-row/index.tsx +24 -25
  16. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  17. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  18. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  19. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +66 -69
  20. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  21. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  22. package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
  23. package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
  26. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
  28. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
  29. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
  30. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +30 -14
  31. package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
  32. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +69 -85
  33. package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
  34. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
  35. package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
  36. package/src/client/components/mobile/SessionSidebar.tsx +2 -1
  37. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
  38. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +59 -62
  39. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
  40. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  41. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
  42. package/src/client/components/settings/Modal.tsx +1 -1
  43. package/src/client/components/settings/Sidebar.tsx +1 -1
  44. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  45. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  46. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  47. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  48. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
  49. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
  50. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
  51. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
  52. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
  53. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  54. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  55. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +86 -93
  56. package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
  57. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +21 -1
  58. package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
  59. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  60. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  61. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  62. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  63. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  64. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  65. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  66. package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
  67. package/src/client/components/workspace/chat-timeline/index.tsx +16 -22
  68. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +116 -0
  69. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  70. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
  71. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  72. package/src/client/components/workspace/git-panel/index.tsx +2 -2
  73. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
  74. package/src/client/components/workspace/terminal-panel/index.tsx +3 -0
  75. package/src/client/hooks/chat/composer/items.test.ts +19 -0
  76. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  77. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  78. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  79. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  80. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  81. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  82. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  83. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  84. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  85. package/src/client/hooks/chat/omp/session-list.tsx +9 -0
  86. package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
  87. package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
  88. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  89. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  90. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  91. package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
  92. package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
  93. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  94. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  95. package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
  96. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  97. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  98. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  99. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  100. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  101. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  102. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  103. package/src/client/hooks/chat/timeline/pending-branch.ts +214 -0
  104. package/src/client/hooks/chat/timeline/pending-dispatch.ts +302 -0
  105. package/src/client/hooks/chat/timeline/send.ts +17 -103
  106. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  107. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  108. package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
  109. package/src/client/hooks/chat/waiting/cancel.ts +2 -1
  110. package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
  111. package/src/client/hooks/chat/waiting/held.ts +2 -1
  112. package/src/client/hooks/models/use-harness-update.test.ts +137 -44
  113. package/src/client/hooks/models/use-harness-update.ts +133 -85
  114. package/src/client/hooks/settings/providers/actions.ts +3 -2
  115. package/src/client/hooks/settings/providers/messages.ts +9 -7
  116. package/src/client/hooks/settings/providers/model-actions.ts +2 -1
  117. package/src/client/hooks/ui/editor-error-toast.ts +2 -1
  118. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  119. package/src/client/hooks/ui/notifications.ts +45 -0
  120. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  121. package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
  122. package/src/client/hooks/workspace/batch-archive.ts +4 -2
  123. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  124. package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
  125. package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
  126. package/src/client/hooks/workspace/session-actions.test.ts +2 -1
  127. package/src/client/hooks/workspace/session-actions.ts +2 -1
  128. package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
  129. package/src/client/hooks/workspace/terminal/connection.ts +47 -0
  130. package/src/client/hooks/workspace/terminal/index.ts +35 -4
  131. package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
  132. package/src/client/lib/native/open-session.ts +33 -0
  133. package/src/client/lib/notifications/os.test.ts +125 -0
  134. package/src/client/lib/notifications/os.ts +130 -0
  135. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  136. package/src/client/lib/router/open-session.test.ts +75 -0
  137. package/src/client/lib/router/open-session.ts +34 -0
  138. package/src/client/lib/signals.ts +5 -1
  139. package/src/client/main.tsx +6 -0
  140. package/src/server/lib/db/schema.ts +1 -0
  141. package/src/server/lib/harness/acp/calls.ts +15 -1
  142. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  143. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  144. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  145. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  146. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  147. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  148. package/src/server/lib/harness/acp/client.ts +31 -21
  149. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  150. package/src/server/lib/harness/acp/commands.ts +14 -2
  151. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  152. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  153. package/src/server/lib/harness/acp/frames.ts +71 -158
  154. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  155. package/src/server/lib/harness/acp/mapper.ts +12 -0
  156. package/src/server/lib/harness/acp/permissions.ts +6 -0
  157. package/src/server/lib/harness/acp/protocol.ts +41 -2
  158. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  159. package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
  160. package/src/server/lib/harness/acp/session-handshake.ts +83 -6
  161. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  162. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  163. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  164. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  165. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  166. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  167. package/src/server/lib/harness/acp/session-requests.ts +48 -6
  168. package/src/server/lib/harness/acp/session-turns.ts +8 -3
  169. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  170. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  171. package/src/server/lib/harness/acp/session.test-util.ts +19 -1
  172. package/src/server/lib/harness/acp/session.ts +60 -60
  173. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  174. package/src/server/lib/harness/acp/turn.test.ts +102 -0
  175. package/src/server/lib/harness/acp/turn.ts +81 -6
  176. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  177. package/src/server/lib/harness/acp/v2.ts +220 -0
  178. package/src/server/lib/harness/acp/verbs.ts +46 -6
  179. package/src/server/lib/harness/launch.test.ts +25 -0
  180. package/src/server/lib/harness/launch.ts +21 -9
  181. package/src/server/lib/harness/session.ts +3 -0
  182. package/src/server/lib/harness/update-job-store.test.ts +37 -12
  183. package/src/server/lib/harness/update-job-store.ts +22 -16
  184. package/src/server/lib/harness/update-job.server.ts +66 -175
  185. package/src/server/lib/harness/update-queue.server.ts +292 -0
  186. package/src/server/lib/harness/update-queue.test.ts +265 -0
  187. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  188. package/src/server/lib/harness/update-worker.ts +8 -3
  189. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  190. package/src/server/lib/lifecycle/paths.ts +14 -9
  191. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  192. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  193. package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
  194. package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
  195. package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
  196. package/src/server/lib/sessions/fork.server.test.ts +68 -0
  197. package/src/server/lib/sessions/fork.server.ts +31 -6
  198. package/src/server/lib/sessions/spawn.server.test.ts +41 -0
  199. package/src/server/lib/sessions/spawn.server.ts +27 -2
  200. package/src/server/lib/usage/report.server.ts +57 -0
  201. package/src/server/routes/agent/harness-command.ts +6 -5
  202. package/src/server/routes/chat/stream.ts +7 -2
  203. package/src/server/routes/harness/update-status.ts +18 -12
  204. package/src/server/routes/harness/update.test.ts +53 -16
  205. package/src/server/routes/harness/update.ts +13 -8
  206. package/src/server/routes/sessions/body-readers.ts +43 -0
  207. package/src/server/routes/sessions/fork.ts +19 -4
  208. package/src/server/routes/sessions/routes.test.ts +1 -2
  209. package/src/server/routes/sessions/session.ts +19 -0
  210. package/src/server/routes/sessions/spawn.ts +16 -13
  211. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  212. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  213. package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
  214. package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
  215. package/src/shared/lib/harness/mode-signal.ts +20 -0
  216. package/src/shared/lib/harness/session-modes.ts +24 -0
  217. package/src/shared/lib/harness/update-job.ts +53 -6
  218. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  219. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  220. package/src/shared/lib/notifications/outcomes.ts +64 -0
  221. package/src/shared/lib/notifications/settings.test.ts +49 -0
  222. package/src/shared/lib/notifications/settings.ts +34 -0
  223. package/src/shared/lib/omp/session/default-title.ts +5 -4
  224. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  225. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  226. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  227. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  228. package/src/shared/lib/settings/defaults.ts +3 -0
  229. package/src/shared/lib/ui/toast-duration.test.ts +25 -1
  230. package/src/shared/lib/ui/toast-duration.ts +22 -4
  231. package/src/shared/lib/workspace/session-state/store.ts +4 -0
  232. package/src/shared/types/harness-update.ts +24 -0
  233. package/src/shared/types/realtime.ts +2 -0
  234. package/src/shared/types/settings/state.ts +10 -0
  235. package/src/shared/types/workspace.ts +4 -0
  236. package/src/test-support/harness-table.test-util.ts +25 -9
  237. package/dist/client/static/js/index-bc9aa4mx.css +0 -1
  238. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
  239. package/src/client/components/common/subagent-list/index.tsx +0 -165
  240. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
  241. package/src/client/hooks/workspace/child-expansion.ts +0 -33
@@ -13,7 +13,10 @@ import { useChatTimeline } from '@/client/hooks/chat/timeline';
13
13
  import { useSessionTitle } from '@/client/hooks/chat/timeline/session-title';
14
14
  import { useSubagentView } from '@/client/hooks/chat/timeline/subagent-view';
15
15
  import { useUndoConfirmation } from '@/client/hooks/chat/timeline/undo-confirmation';
16
+ import { usePendingBranch } from '@/client/hooks/chat/timeline/pending-branch';
17
+ import { useForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
16
18
  import { useForkSession } from '@/client/hooks/chat/timeline/use-fork-session';
19
+ import { useStopWithQueuedPrompts } from '@/client/hooks/chat/timeline/stop-with-queue';
17
20
  import { useModelNames } from '@/client/hooks/models/use-model-names';
18
21
  import { useRunIdentity } from '@/client/hooks/chat/timeline/run-identity';
19
22
  import { useProviderNames } from '@/client/hooks/models/use-provider-names';
@@ -119,23 +122,8 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
119
122
  const [searchParams, setSearchParams] = useSearchParams();
120
123
 
121
124
  // Stop-all semantics: the run stops AND the queued follow-ups stay in the
122
- // panel (the auto-process holds off). Surface what just happened and how to
123
- // proceed — the toast action delivers the head item immediately.
124
- const handleStop = useCallback(() => {
125
- const heldCount = stopGenerating();
126
- if (heldCount === 0) return;
127
- pushToast(
128
- `Stopped. ${heldCount} message${heldCount > 1 ? 's' : ''} still queued — nothing was sent.`,
129
- 'success',
130
- {
131
- action: { label: 'Send now', onClick: () => {
132
- const first = messageQueue[0];
133
- if (first) void handleSendNowQueueItem(first);
134
- } },
135
- duration: 8000,
136
- },
137
- );
138
- }, [stopGenerating, pushToast, messageQueue, handleSendNowQueueItem]);
125
+ // panel (the auto-process holds off); the toast offers the head item.
126
+ const handleStop = useStopWithQueuedPrompts(stopGenerating, messageQueue, handleSendNowQueueItem, pushToast);
139
127
  const { activeSubagent, back: handleSubagentBack } = useSubagentView(
140
128
  sessionId,
141
129
  searchParams.get('subagent'),
@@ -149,7 +137,6 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
149
137
  }, [jumpToUserTurn]);
150
138
 
151
139
  const handleNewChat = newChat.open;
152
- const handleFork = useForkSession(sessionId, pushToast);
153
140
  const modelNames = useModelNames();
154
141
  const { sessionProvider, sessionModelName } = useRunIdentity({ folders, sessionId, sessionData, modelNames });
155
142
  const providerNames = useProviderNames();
@@ -164,6 +151,11 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
164
151
  // uses, so the pending composer's pill does not promise Kabmo's global pick.
165
152
  const pendingProjectModel = usePendingProjectModel(folders, selectedFolderId);
166
153
  const sessionDataModel = typeof sessionData?.model === 'object' ? sessionData.model : null;
154
+ const branch = usePendingBranch({ sessionId, folders, selectedFolderId, setSelectedFolderId, urlParentId: searchParams.get('parentSessionId'), urlForkFrom: searchParams.get('forkFrom'), urlForkAt: searchParams.get('forkAt'), setSearchParams, harnessPicker: activeHarness.picker, pendingHarnessRef });
155
+ const fork = useForkSession(sessionId, folders, selectedFolderId);
156
+ // A fork's source transcript, drawn above the pending composer and reloaded
157
+ // when "Fork from" moves to another session.
158
+ const forkPreview = useForkPreview(branch.forkSourceSessionId, branch.forkAnchorEntryId);
167
159
 
168
160
  // The chat-level "a run is in flight" flag is computed in `useChatTimeline`
169
161
  // (it owns the queue-vs-send decision that depends on it) and consumed here
@@ -203,7 +195,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
203
195
  modes={modes}
204
196
  composerModelRef={composerModelRef}
205
197
  deferredComposerPickRef={deferredComposerPickRef}
206
- sessionModel={sessionDataModel ?? pendingProjectModel}
198
+ sessionModel={branch.parentModel ?? sessionDataModel ?? pendingProjectModel}
207
199
  sessionThinkingLevel={sessionData?.thinkingLevel}
208
200
  generatingVerb={generatingVerb}
209
201
  variant={variant}
@@ -218,8 +210,10 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
218
210
  onCancelWait={cancelHeldWait}
219
211
  spawnTarget={spawnTarget}
220
212
  onSpawnTargetChange={setSpawnTarget}
221
- onWorktreeReport={(message) => pushToast(message, 'success', { duration: 6000 })}
222
- {...activeHarness.picker}
213
+ {...branch.viewProps}
214
+ {...(branch.forkSourceSessionId ? { branchPreview: forkPreview } : {})}
215
+ onWorktreeReport={(message, tone) => pushToast(message, tone ?? 'success', { duration: 6000 })}
216
+ {...branch.composerProps}
223
217
  />
224
218
  );
225
219
  }
@@ -267,7 +261,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
267
261
  onUndo={handleRequestUndo}
268
262
  onRetry={handleRetry}
269
263
  onNewChat={handleNewChat}
270
- onFork={handleFork}
264
+ onFork={fork}
271
265
  showScrollBottom={showScrollBottom}
272
266
  jumpToBottom={jumpToBottom}
273
267
  rowWindow={rowWindow}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The draft-target row above a not-yet-started chat: where it runs, in which
8
+ * checkout, under which parent, and what it waits for.
9
+ *
10
+ * One row because these are one question — the context the first prompt is born
11
+ * into — and splitting it back into the composer would put four independent
12
+ * placements in two files. Extracted from `EmptyWorkspacePrompt` for the
13
+ * per-file ceiling.
14
+ */
15
+
16
+ import { WorkspacePicker } from '@/client/components/workspace/chat-timeline/target-picker/WorkspacePicker';
17
+ import { WorktreePicker } from '@/client/components/workspace/chat-timeline/target-picker/WorktreePicker';
18
+ import { ParentSessionPicker } from '@/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker';
19
+ import {
20
+ WaitingDependencyPicker,
21
+ type WaitingCandidate,
22
+ } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
23
+ import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
24
+ import type { WorkspaceFolderData } from '@/shared/types';
25
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
26
+
27
+ export interface DraftTargetRowProps {
28
+ folders: WorkspaceFolderData[];
29
+ selectedFolderId: number | null;
30
+ setSelectedFolderId: (id: number | null) => void;
31
+ spawnTarget?: SpawnTarget | null;
32
+ onSpawnTargetChange?: (next: SpawnTarget | null) => void;
33
+ /** Reports a worktree the composer created or failed to create. */
34
+ onWorktreeReport?: (message: string, tone?: ToastTone) => void;
35
+ /** The session this chat runs under, or null for a top-level chat. */
36
+ parentSessionId?: string | null;
37
+ onParentSessionChange?: (sessionId: string | null) => void;
38
+ /** "Parent session" for a child, "Fork from" for a fork. */
39
+ branchLabel?: string;
40
+ /** False when the pending chat must have a source (a fork). */
41
+ branchAllowNone?: boolean;
42
+ waitingFor?: WaitingCandidate | null;
43
+ onWaitingForChange?: (candidate: WaitingCandidate | null) => void;
44
+ streamStatusMap?: Record<string, string | undefined>;
45
+ /** A name for a streaming session the sidebar has not scanned yet. */
46
+ titleForSession?: (id: string) => string | undefined;
47
+ candidates: WaitingCandidate[];
48
+ }
49
+
50
+ export function DraftTargetRow({
51
+ folders,
52
+ selectedFolderId,
53
+ setSelectedFolderId,
54
+ spawnTarget = null,
55
+ onSpawnTargetChange,
56
+ onWorktreeReport,
57
+ parentSessionId = null,
58
+ onParentSessionChange,
59
+ branchLabel = 'Parent session',
60
+ branchAllowNone = true,
61
+ waitingFor = null,
62
+ onWaitingForChange,
63
+ streamStatusMap = {},
64
+ titleForSession,
65
+ candidates,
66
+ }: DraftTargetRowProps) {
67
+ return (
68
+ <div className="flex items-center gap-1 flex-wrap">
69
+ {/* Two controls, because they answer two questions: the workspace (which
70
+ project) and the worktree (which checkout of it). The worktree control
71
+ draws itself only for a git repository, and it reads its list on mount
72
+ because its own trigger names the branch the project root holds. */}
73
+ <WorkspacePicker
74
+ folders={folders}
75
+ selectedFolderId={selectedFolderId}
76
+ setSelectedFolderId={setSelectedFolderId}
77
+ onClearWorktree={() => onSpawnTargetChange?.(null)}
78
+ />
79
+ {onSpawnTargetChange && (
80
+ <WorktreePicker
81
+ folders={folders}
82
+ selectedFolderId={selectedFolderId}
83
+ target={spawnTarget}
84
+ setTarget={onSpawnTargetChange}
85
+ onReport={onWorktreeReport}
86
+ />
87
+ )}
88
+ {/* ALL sessions, not just the active one: the composer may have been
89
+ opened from one row and the user may want the chat under another.
90
+ Choosing a parent also moves the workspace to that session's folder. */}
91
+ {onParentSessionChange && (
92
+ <ParentSessionPicker
93
+ folders={folders}
94
+ value={parentSessionId}
95
+ onChange={onParentSessionChange}
96
+ label={branchLabel}
97
+ allowNone={branchAllowNone}
98
+ />
99
+ )}
100
+ {/* The wait picker sits BESIDE the workspace picker, because both answer
101
+ the same question about the chat that has not started: where it runs,
102
+ and what it waits for. It only appears while there is something to
103
+ wait for (or a pick already made). */}
104
+ {onWaitingForChange && (waitingFor || candidates.length > 0) && (
105
+ <WaitingDependencyPicker
106
+ folders={folders}
107
+ streamStatusMap={streamStatusMap}
108
+ sessionId={null}
109
+ titleFor={titleForSession}
110
+ value={waitingFor}
111
+ onChange={onWaitingForChange}
112
+ />
113
+ )}
114
+ </div>
115
+ );
116
+ }
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * "Parent session" — which session a NEW chat branches under.
8
+ *
9
+ * The composer's draft-target row already answers where a chat runs; this is
10
+ * the other half of the same question for a child: what it runs UNDER. The
11
+ * list is ALL real sessions, not only the active one, because the row that
12
+ * opened the composer may not be the parent the user ends up wanting.
13
+ *
14
+ * A pending chat is never offered (it has no id to parent), and neither is an
15
+ * archived one (the server refuses to spawn under it).
16
+ */
17
+
18
+ import { useCallback, useMemo, useRef, useState } from 'preact/hooks';
19
+ import { Check, ChevronDown, GitBranch, X } from 'lucide-preact';
20
+ import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
21
+ import type { WorkspaceFolderData } from '@/shared/types';
22
+
23
+ export interface ParentSessionOption {
24
+ id: string;
25
+ title: string;
26
+ folderId: number | string;
27
+ folderName: string;
28
+ harness?: string;
29
+ }
30
+
31
+ /** Every real session, in sidebar order, excluding the chat being composed. */
32
+ export function parentSessionOptions(
33
+ folders: WorkspaceFolderData[],
34
+ excludeId?: string | null,
35
+ ): ParentSessionOption[] {
36
+ const options: ParentSessionOption[] = [];
37
+ for (const folder of folders) {
38
+ for (const session of folder.sessions ?? []) {
39
+ const id = String(session.id);
40
+ if (id.startsWith('new-') || session.is_archived === 1) continue;
41
+ if (excludeId && id === excludeId) continue;
42
+ options.push({
43
+ id,
44
+ title: session.title || id,
45
+ folderId: folder.id,
46
+ folderName: folder.name,
47
+ ...(session.harness ? { harness: session.harness } : {}),
48
+ });
49
+ }
50
+ }
51
+ return options;
52
+ }
53
+
54
+ export interface ParentSessionPickerProps {
55
+ folders: WorkspaceFolderData[];
56
+ /** The pending chat itself, never offered as its own parent. */
57
+ sessionId?: string | null;
58
+ value: string | null;
59
+ onChange: (sessionId: string | null) => void;
60
+ /** "Parent session" for a child, "Fork from" for a fork. */
61
+ label?: string;
62
+ /** False when the pending chat MUST have a source (a fork). */
63
+ allowNone?: boolean;
64
+ }
65
+
66
+ export function ParentSessionPicker({
67
+ folders,
68
+ sessionId,
69
+ value,
70
+ onChange,
71
+ label = 'Parent session',
72
+ allowNone = true,
73
+ }: ParentSessionPickerProps) {
74
+ const [open, setOpen] = useState(false);
75
+ const ref = useRef<HTMLDivElement>(null);
76
+ const close = useCallback(() => setOpen(false), []);
77
+ useOnClickOutside(ref, close);
78
+ const options = useMemo(() => parentSessionOptions(folders, sessionId), [folders, sessionId]);
79
+ const selected = value ? options.find((option) => option.id === value) : undefined;
80
+ const triggerLabel = selected ? selected.title : value ? value : `${label}: none`;
81
+
82
+ return (
83
+ <div className="relative shrink-0" ref={ref}>
84
+ <button
85
+ type="button"
86
+ data-testid="parent-session-picker"
87
+ onClick={() => setOpen((prev) => !prev)}
88
+ title={selected ? `${label}: ${selected.title}` : `Choose a session for ${label.toLowerCase()}`}
89
+ aria-label={selected ? `${label}: ${selected.title}` : label}
90
+ aria-expanded={open}
91
+ className={`tap-chip group flex items-center gap-1.5 rounded-md px-1.5 py-1 text-xs font-medium transition-all focus-visible:bg-ink/5 cursor-pointer select-none ${
92
+ selected ? 'bg-ink/10 text-ink' : 'text-ink/75 hover:text-ink hover:bg-ink/5'
93
+ }`}
94
+ >
95
+ <GitBranch size={13} className={`flex-shrink-0 ${selected ? 'text-ink/80' : 'text-ink/50 group-hover:text-ink/80'}`} />
96
+ <span className="max-w-[220px] truncate tracking-tight">{triggerLabel}</span>
97
+ <ChevronDown
98
+ size={13}
99
+ className={`flex-shrink-0 text-ink/40 transition-transform duration-150 ${open ? 'rotate-180 text-ink/70' : ''}`}
100
+ />
101
+ </button>
102
+
103
+ {open && (
104
+ <div className="glass-popover absolute bottom-full left-0 mb-1.5 w-80 bg-paper border border-ink/10 rounded-lg shadow-lg z-50 flex flex-col overflow-hidden text-xs py-1">
105
+ <div className="flex items-center justify-between px-3 py-1.5 border-b border-ink/5">
106
+ <span className="text-[10px] uppercase tracking-wider text-ink/40 font-semibold">
107
+ {label}
108
+ </span>
109
+ {value && allowNone && (
110
+ <button
111
+ type="button"
112
+ onClick={() => {
113
+ onChange(null);
114
+ setOpen(false);
115
+ }}
116
+ title="Start a top-level chat"
117
+ aria-label="Clear parent session"
118
+ className="flex items-center gap-1 text-[10px] text-ink/50 hover:text-ink cursor-pointer"
119
+ >
120
+ <X size={10} /> clear
121
+ </button>
122
+ )}
123
+ </div>
124
+ <div className="max-h-64 scrollbar-overlay-container py-1">
125
+ {allowNone && (
126
+ <button
127
+ type="button"
128
+ data-testid="parent-candidate-none"
129
+ onClick={() => {
130
+ onChange(null);
131
+ setOpen(false);
132
+ }}
133
+ className={`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors cursor-pointer hover:bg-ink/5 ${
134
+ value ? 'text-ink/70' : 'text-ink font-medium'
135
+ }`}
136
+ >
137
+ <span className="w-3 shrink-0">{!value && <Check size={11} />}</span>
138
+ <span className="min-w-0 flex-1 truncate">No parent (top-level chat)</span>
139
+ </button>
140
+ )}
141
+ {options.map((option) => {
142
+ const active = option.id === value;
143
+ return (
144
+ <button
145
+ key={option.id}
146
+ type="button"
147
+ data-testid="parent-candidate"
148
+ data-session-id={option.id}
149
+ onClick={() => {
150
+ onChange(option.id);
151
+ setOpen(false);
152
+ }}
153
+ className={`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors cursor-pointer hover:bg-ink/5 ${
154
+ active ? 'text-ink font-medium' : 'text-ink/70'
155
+ }`}
156
+ >
157
+ <span className="w-3 shrink-0">{active && <Check size={11} />}</span>
158
+ <span className="min-w-0 flex-1 truncate">{option.title}</span>
159
+ <span className="shrink-0 max-w-[7rem] truncate text-[10px] text-ink/40">
160
+ {option.folderName}
161
+ </span>
162
+ </button>
163
+ );
164
+ })}
165
+ {options.length === 0 && (
166
+ <div className="px-3 py-2 text-ink/40 italic">No sessions to parent under yet</div>
167
+ )}
168
+ </div>
169
+ </div>
170
+ )}
171
+ </div>
172
+ );
173
+ }
@@ -32,6 +32,7 @@ import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
32
32
  import type { WorktreeInfo } from '@/shared/lib/workspace/worktree/types';
33
33
  import { lastPathSegment } from '@/shared/lib/fs/paths';
34
34
  import type { WorkspaceFolderData } from '@/shared/types';
35
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
35
36
 
36
37
  export interface WorktreePickerProps {
37
38
  folders: WorkspaceFolderData[];
@@ -39,7 +40,7 @@ export interface WorktreePickerProps {
39
40
  target: SpawnTarget | null;
40
41
  setTarget: (next: SpawnTarget | null) => void;
41
42
  /** Reports a completed create, or the refusal that stopped one. */
42
- onReport?: (message: string) => void;
43
+ onReport?: (message: string, tone?: ToastTone) => void;
43
44
  }
44
45
 
45
46
  /** The worktree row the pick names, or null for the project root. */
@@ -131,9 +132,9 @@ export function WorktreePicker({ folders, selectedFolderId, target, setTarget, o
131
132
  // is `wt/groovy-yak` (measured in the browser, and for the whole time the
132
133
  // menu stays closed, which is when the label matters).
133
134
  await refresh();
134
- onReport?.(`Worktree ${created.branch || lastPathSegment(created.path)} created`);
135
+ onReport?.(`Worktree ${created.branch || lastPathSegment(created.path)} created`, 'success');
135
136
  } catch (failure) {
136
- onReport?.(failure instanceof Error ? failure.message : String(failure));
137
+ onReport?.(failure instanceof Error ? failure.message : String(failure), 'error');
137
138
  } finally {
138
139
  setCreating(false);
139
140
  }
@@ -277,7 +278,7 @@ export function WorktreePicker({ folders, selectedFolderId, target, setTarget, o
277
278
  // this control holds has never seen, so the trigger would fall back to
278
279
  // the folder name until the menu was opened again.
279
280
  void refresh();
280
- onReport?.(`Worktree ${created.branch} created`);
281
+ onReport?.(`Worktree ${created.branch} created`, 'success');
281
282
  }}
282
283
  />
283
284
  </div>
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which sessions the child composer may name as a parent: every REAL session,
8
+ * in sidebar order, never a pending or archived one.
9
+ */
10
+
11
+ import { describe, expect, test } from 'bun:test';
12
+ import { parentSessionOptions } from '@/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker';
13
+ import type { WorkspaceFolderData } from '@/shared/types';
14
+
15
+ const folders = [
16
+ {
17
+ id: 1,
18
+ name: 'one',
19
+ sessions: [
20
+ { id: 'a', folder_id: 1, title: 'Alpha' },
21
+ { id: 'new-123', folder_id: 1, title: 'Pending' },
22
+ { id: 'archived', folder_id: 1, title: 'Old', is_archived: 1 },
23
+ ],
24
+ },
25
+ {
26
+ id: 2,
27
+ name: 'two',
28
+ sessions: [{ id: 'b', folder_id: 2, title: 'Beta', harness: 'claude' }],
29
+ },
30
+ ] as unknown as WorkspaceFolderData[];
31
+
32
+ describe('parentSessionOptions', () => {
33
+ test('lists real sessions in sidebar order with their folder', () => {
34
+ expect(parentSessionOptions(folders)).toEqual([
35
+ { id: 'a', title: 'Alpha', folderId: 1, folderName: 'one' },
36
+ { id: 'b', title: 'Beta', folderId: 2, folderName: 'two', harness: 'claude' },
37
+ ]);
38
+ });
39
+
40
+ test('never offers a pending chat or an archived session', () => {
41
+ const ids = parentSessionOptions(folders).map((option) => option.id);
42
+ expect(ids).not.toContain('new-123');
43
+ expect(ids).not.toContain('archived');
44
+ });
45
+
46
+ test('excludes the chat being composed', () => {
47
+ expect(parentSessionOptions(folders, 'a').map((option) => option.id)).toEqual(['b']);
48
+ });
49
+ });
@@ -88,8 +88,8 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
88
88
  fetcher: actionFetcher,
89
89
  onPage: setViewingOutput,
90
90
  onReload: loadRepo,
91
- onSuccess: (message) => pushToast(message, 'success'),
92
- onError: (message) => pushToast(message),
91
+ onSuccess: (message, tone) => pushToast(message, tone),
92
+ onError: (message) => pushToast(message, 'error'),
93
93
  });
94
94
 
95
95
  useOnClickOutside(optionsRef, () => setShowOptions(false));
@@ -156,12 +156,15 @@ export const RealtimeTerminalView = forwardRef<RealtimeTerminalHandle, RealtimeT
156
156
  };
157
157
  }, []);
158
158
 
159
- // No background and no padding: the terminal is not a surface of its own,
160
- // and the panel's paper shows through the strip the fit addon leaves for
161
- // its in-canvas scrollbar. `p-1.5` also made the grid narrower than the
162
- // panel, which read as a terminal that was not full width.
159
+ // The gutter lives on this WRAPPER, never on the measured container:
160
+ // `safeFit` gates on `container.clientWidth/clientHeight`, and `clientWidth`
161
+ // includes padding — padding on the container itself would size the canvas
162
+ // wider than the box it is drawn in. Here the grid is measured against the
163
+ // content box, so it is narrower by exactly the padding, which is the point.
164
+ // No background: the terminal is not a surface of its own, and the panel's
165
+ // paper shows through the strip the fit addon leaves for its scrollbar.
163
166
  return (
164
- <div className="relative flex-1 w-full h-full overflow-hidden">
167
+ <div className="relative flex-1 w-full h-full overflow-hidden p-2">
165
168
  <div
166
169
  ref={containerRef}
167
170
  data-terminal-root=""
@@ -72,6 +72,9 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
72
72
  restart,
73
73
  reattach,
74
74
  } = useTerminal({
75
+ // "Open" is this panel being selected with its column shown; the view is
76
+ // mounted even when hidden, so mounting alone must never start a shell.
77
+ visible: active && enabled,
75
78
  root: enabled ? rootPath : undefined,
76
79
  repo: activeRepo,
77
80
  theme: isDark ? 'dark' : 'light',
@@ -301,6 +301,25 @@ describe('loadComposerItems', () => {
301
301
  expect(requested.length).toBe(6);
302
302
  });
303
303
 
304
+ test('commands are scoped to the live session, with one cache entry per session', async () => {
305
+ answer = (url) => (url.includes('sessionId=s1')
306
+ ? { body: { commands: [{ id: 'c1', name: 'test', description: 'Run tests', scope: 'system', template: '' }], skills: [] } }
307
+ : { body: { commands: [], skills: [] } });
308
+
309
+ const forS1 = await loadComposerItems('command', '/repo', 's1');
310
+ expect(requested).toContain('/api/settings/commands?root=%2Frepo&sessionId=s1');
311
+ expect(forS1.some((item) => item.name === 'test')).toBe(true);
312
+
313
+ // Another chat must not be served s1's vocabulary from the cache.
314
+ const forS2 = await loadComposerItems('command', '/repo', 's2');
315
+ expect(requested.some((url) => url.includes('sessionId=s2'))).toBe(true);
316
+ expect(forS2.some((item) => item.name === 'test')).toBe(false);
317
+
318
+ const before = requested.length;
319
+ await loadComposerItems('command', '/repo', 's1');
320
+ expect(requested.length).toBe(before);
321
+ });
322
+
304
323
  test('a command entry is a /name token and a skill is prefixed', async () => {
305
324
  answer = (url) => url.includes('/commands')
306
325
  ? { body: { commands: [{ id: 'c', name: 'fix', description: 'fix it', scope: 'user', template: '/fix' }] } }
@@ -25,7 +25,7 @@
25
25
  */
26
26
 
27
27
  import { useEffect, useMemo, useRef } from 'preact/hooks';
28
- import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-sessions';
28
+ import type { PendingSessionEntry } from '@/client/hooks/chat/omp/pending-entry';
29
29
  import { pendingHostFolderIds } from '@/client/hooks/chat/omp/pending-rows';
30
30
  import { setFolderExpanded } from '@/client/hooks/workspace/folder-expansion';
31
31
  import type { WorkspaceFolderData } from '@/shared/types';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The pending → real id switch a spawn performs, and who may claim it.
8
+ *
9
+ * Split from the store (`pending-sessions.ts`) because the two readers ask
10
+ * different questions of the same record: the session-state provider claims it
11
+ * once to carry a draft across, while the agent hook only peeks to know the
12
+ * conversation did not change. Neither may treat a plain session switch as an
13
+ * adoption — that mistake copied one chat's draft into another and cleared the
14
+ * run's tool map mid-turn.
15
+ */
16
+
17
+ /** `toId → fromId` for a spawn adoption, written where the spawn answers. */
18
+ const adoptions = new Map<string, string>();
19
+
20
+ /** Record a spawn adoption; bounded by the store, which drops the source. */
21
+ export function recordAdoption(fromId: string, toId: string): void {
22
+ adoptions.set(toId, fromId);
23
+ }
24
+
25
+ /**
26
+ * Whether `toId` is the id a spawn answered with for `fromId` — consuming the
27
+ * record so one adoption is claimed once.
28
+ *
29
+ * Only a real spawn may carry the transient slot's UI state across: clicking a
30
+ * different session from a pending chat is the same URL transition, and was
31
+ * measured copying `chat.draft` into the other session.
32
+ */
33
+ export function consumeAdoption(fromId: string | null | undefined, toId: string): boolean {
34
+ if (!fromId || adoptions.get(toId) !== fromId) return false;
35
+ adoptions.delete(toId);
36
+ return true;
37
+ }
38
+
39
+ /**
40
+ * Whether `toId` is the id a spawn answered with for `fromId`, WITHOUT claiming
41
+ * the record.
42
+ *
43
+ * The agent hook's question is "is this the SAME conversation under a new id",
44
+ * not "may I carry this UI state across": treating an adoption as a session
45
+ * switch threw away `toolResultsRef`/`lastToolMessageRef` mid-turn, so every
46
+ * later progress frame lost its card. The provider still owns the single claim,
47
+ * so peeking here cannot steal it.
48
+ */
49
+ export function isSpawnAdoption(fromId: string | null | undefined, toId: string): boolean {
50
+ return Boolean(fromId) && adoptions.get(toId) === fromId;
51
+ }