@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
@@ -0,0 +1,240 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The shared branch: one disclosure, one tree, one slot rule.
8
+ *
9
+ * The suite pins the three facts the design rests on after the two lists were
10
+ * merged: a child session is rendered by the CHROME's own row component, a
11
+ * deeper branch recurses with the guide flags of every ancestor, and a subagent
12
+ * is a leaf whose leading 16px slot carries its state while the robot takes the
13
+ * harness column.
14
+ *
15
+ * Rendered with `h()` (no JSX) against happy-dom, following `SessionItem.test.ts`.
16
+ */
17
+
18
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
19
+ import { Window } from 'happy-dom';
20
+ import { h, render } from 'preact';
21
+ import { act } from 'preact/test-utils';
22
+
23
+ import { SessionBranch } from '@/client/components/common/session-branch';
24
+ import type { BranchControl, SessionBranchProps } from '@/client/components/common/session-branch';
25
+ import { SubagentRow } from '@/client/components/common/session-branch/SubagentRow';
26
+ import type { SessionItemData, SubagentInfo } from '@/shared/types';
27
+
28
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent', 'CustomEvent'] as const;
29
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
30
+
31
+ let container: HTMLElement;
32
+
33
+ beforeAll(() => {
34
+ const win = new Window({ url: 'http://localhost' });
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
38
+ target[key] = (win as unknown as Record<string, unknown>)[key];
39
+ }
40
+ });
41
+
42
+ afterAll(() => {
43
+ const target = globalThis as unknown as Record<string, unknown>;
44
+ for (const key of DOM_GLOBALS) {
45
+ if (nativeGlobals[key] === undefined) delete target[key];
46
+ else target[key] = nativeGlobals[key];
47
+ }
48
+ });
49
+
50
+ afterEach(() => {
51
+ if (container) render(null, container);
52
+ container?.remove();
53
+ });
54
+
55
+ async function mount(node: preact.ComponentChild) {
56
+ container = document.createElement('div');
57
+ document.body.appendChild(container);
58
+ await act(async () => {
59
+ render(node, container);
60
+ });
61
+ return container;
62
+ }
63
+
64
+ /** A row stand-in that exposes the control the chrome would have received. */
65
+ const row = (session: SessionItemData, control: BranchControl) =>
66
+ h(
67
+ 'button',
68
+ {
69
+ 'data-testid': 'branch-row',
70
+ 'data-id': String(session.id),
71
+ 'data-expandable': String(control.expandable),
72
+ 'data-expanded': String(control.isExpanded),
73
+ },
74
+ session.title,
75
+ );
76
+
77
+ function branch(overrides: Partial<SessionBranchProps> = {}) {
78
+ const childrenOf = new Map<string, SessionItemData[]>([
79
+ ['root', [
80
+ { id: 'child-a', folder_id: 1, title: 'Child A' },
81
+ { id: 'child-b', folder_id: 1, title: 'Child B' },
82
+ ]],
83
+ ['child-a', [
84
+ { id: 'grandchild', folder_id: 1, title: 'Grandchild' },
85
+ ]],
86
+ ]);
87
+ return h(SessionBranch, {
88
+ parentId: 'root',
89
+ hasSubagents: false,
90
+ childrenOf,
91
+ expandedIds: new Set<string>(),
92
+ onToggle: () => {},
93
+ activeSessionId: null,
94
+ renderSession: row,
95
+ style: { inset: 'px-2', insetPx: 8, slotWidth: 16, markGap: 8, padding: 'py-1', glyph: 12 },
96
+ ...overrides,
97
+ });
98
+ }
99
+
100
+ describe('SessionBranch', () => {
101
+ test('renders the chrome row for each child, with the branch control', async () => {
102
+ const el = await mount(branch());
103
+ const rows = [...el.querySelectorAll<HTMLElement>('[data-testid="branch-row"]')];
104
+ expect(rows.map((r) => r.dataset.id)).toEqual(['child-a', 'child-b']);
105
+ // Child A has a child of its own, so its chevron exists; B has nothing.
106
+ expect(rows[0]?.dataset.expandable).toBe('true');
107
+ expect(rows[1]?.dataset.expandable).toBe('false');
108
+ });
109
+
110
+ test('a branch with only subagents keeps the session expandable', async () => {
111
+ const childrenOf = new Map([
112
+ ['root', [{ id: 'child-a', folder_id: 1, title: 'Child A', hasSubagents: true }]],
113
+ ]);
114
+ const el = await mount(branch({ childrenOf }));
115
+ expect(el.querySelector<HTMLElement>('[data-testid="branch-row"]')?.dataset.expandable).toBe('true');
116
+ });
117
+
118
+ test('guides mark the last sibling and continue the ancestors that have one', async () => {
119
+ const el = await mount(branch({
120
+ expandedIds: new Set(['child-a']),
121
+ renderSession: (session, control) => h('div', null, row(session, control)),
122
+ }));
123
+ const connectors = [...el.querySelectorAll<HTMLElement>('[data-guide="connector"]')];
124
+ expect(connectors).toHaveLength(3);
125
+ // Child A is not last at its level, the grandchild is its only child, and
126
+ // Child B is the last row of the branch.
127
+ expect(connectors[0]?.dataset.last).toBeUndefined();
128
+ expect(connectors[1]?.dataset.last).toBe('true');
129
+ expect(connectors[2]?.dataset.last).toBe('true');
130
+ // The grandchild inherits one ancestor line, and that ancestor (Child A)
131
+ // has a following sibling, so the line continues past the grandchild.
132
+ const inherited = [...el.querySelectorAll<HTMLElement>('[data-guide="ancestor"]')];
133
+ expect(inherited).toHaveLength(1);
134
+ expect(inherited[0]?.dataset.continues).toBe('true');
135
+ });
136
+
137
+ test('the guide stays on the chevron column and its arm reaches the child indicator', async () => {
138
+ const el = await mount(branch());
139
+ const connector = el.querySelector<HTMLElement>('[data-guide="connector"]');
140
+ const vertical = connector?.children[0] as HTMLElement;
141
+ const horizontal = connector?.children[1] as HTMLElement;
142
+ // Classic: one level is the 22px pitch (slot half + mark gap + glyph half),
143
+ // so the child's indicator slot centre lands on the parent's harness centre.
144
+ expect(connector?.style.width).toBe('22px');
145
+ // The line stays on the parent chevron's centre; spacing is vertical only.
146
+ expect(vertical.style.left).toBe('15px');
147
+ expect(horizontal.style.left).toBe('15px');
148
+ // The arm runs from the chevron column to the child slot's left edge.
149
+ expect(horizontal.style.width).toBe('15px');
150
+ expect(vertical.style.width).toBe('2px');
151
+ expect(horizontal.style.height).toBe('2px');
152
+ });
153
+
154
+ test('the first row starts its stem below the chevron', async () => {
155
+ const el = await mount(branch());
156
+ const firstVertical = el.querySelector<HTMLElement>('[data-guide="connector"]')?.children[0] as HTMLElement;
157
+ // Siblings after it continue from the row above, so only the first row
158
+ // carries the vertical gap.
159
+ expect(firstVertical.style.top).toBe('-6px');
160
+ });
161
+
162
+ test('the last sibling reaches its own centre, not just its top edge', async () => {
163
+ const el = await mount(branch());
164
+ const connectors = [...el.querySelectorAll<HTMLElement>('[data-guide="connector"]')];
165
+ const lastVertical = connectors[1]?.children[0] as HTMLElement;
166
+ expect(lastVertical.style.top).toBe('0px');
167
+ // From its own top edge to its centre: no overlap with the sibling above, so
168
+ // the translucent stroke cannot darken into a band.
169
+ expect(lastVertical.style.height).toBe('50%');
170
+ });
171
+
172
+ test('a first-and-only child stops at its centre', async () => {
173
+ const childrenOf = new Map<string, SessionItemData[]>([
174
+ ['root', [{ id: 'only', folder_id: 1, title: 'Only' }]],
175
+ ]);
176
+ const el = await mount(branch({ childrenOf }));
177
+ const vertical = el.querySelector<HTMLElement>('[data-guide="connector"]')?.children[0] as HTMLElement;
178
+ expect(vertical.style.top).toBe('-6px');
179
+ expect(vertical.style.height).toBe('calc(50% + 6px)');
180
+ });
181
+
182
+ test('an ancestor line sits on the same guide column as the connector', async () => {
183
+ const el = await mount(branch({ expandedIds: new Set(['child-a']) }));
184
+ const ancestorLine = el.querySelector<HTMLElement>('[data-guide="ancestor"] > span');
185
+ expect(ancestorLine?.style.left).toBe('15px');
186
+ });
187
+
188
+ test('does not recurse into a child that is collapsed', async () => {
189
+ const el = await mount(branch());
190
+ expect(el.querySelector('[data-id="grandchild"]')).toBeNull();
191
+ });
192
+
193
+ test('an expanded row with nothing under it draws nothing', async () => {
194
+ const el = await mount(branch({
195
+ childrenOf: new Map([['root', []]]),
196
+ hasSubagents: false,
197
+ }));
198
+ expect(el.querySelector('[data-testid="session-branch"]')).toBeNull();
199
+ });
200
+ });
201
+
202
+ describe('SubagentRow', () => {
203
+ const subagent: SubagentInfo = {
204
+ id: 'Sleeper',
205
+ agent: 'scout',
206
+ status: 'started',
207
+ index: 0,
208
+ lastUpdate: Date.now(),
209
+ };
210
+
211
+ test('the shared slot carries the state and the robot takes the harness column', async () => {
212
+ const el = await mount(h(SubagentRow, {
213
+ subagent,
214
+ sessionId: 'root',
215
+ style: { inset: 'px-2', insetPx: 8, slotWidth: 16, markGap: 8, padding: 'py-1', glyph: 12 },
216
+ running: true,
217
+ }));
218
+ const slot = el.querySelector('[data-testid="subagent-status-slot"]');
219
+ expect(slot).not.toBeNull();
220
+ // A live run is the pulsing dot, not an icon.
221
+ expect(slot?.querySelector('svg')).toBeNull();
222
+ expect(slot?.firstElementChild).not.toBeNull();
223
+ const mark = el.querySelector('[data-testid="subagent-mark"]');
224
+ expect(mark?.querySelector('svg')).not.toBeNull();
225
+ // It is a robot, not a harness: no harness glyph rides the row.
226
+ expect(el.querySelector('[data-harness]')).toBeNull();
227
+ expect(el.querySelector('button')?.textContent).toContain('Sleeper');
228
+ });
229
+
230
+ test('a settled subagent draws the terminal glyph instead of a spinner', async () => {
231
+ const el = await mount(h(SubagentRow, {
232
+ subagent: { ...subagent, status: 'completed' },
233
+ sessionId: 'root',
234
+ style: { inset: '', insetPx: 0, slotWidth: 16, markGap: 8, padding: 'py-2', glyph: 13 },
235
+ running: false,
236
+ }));
237
+ expect(el.querySelector('[data-testid="subagent-status-slot"] svg')).not.toBeNull();
238
+ expect(el.querySelector('[role="status"]')).toBeNull();
239
+ });
240
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The measurements a branch row borrows from the chrome's session row.
8
+ *
9
+ * A subagent row is a leaf of the same tree, so it has to keep the session
10
+ * row's inset, vertical rhythm and mark size — otherwise the robot sits a few
11
+ * pixels off the harness beside it. The tree lines need one more number: where
12
+ * the row's leading slot CENTRE sits, because that is the column a guide line
13
+ * must run under. The chrome that owns the row component exports its own
14
+ * instance of this.
15
+ */
16
+ export interface BranchRowStyle {
17
+ /** Horizontal padding of the chrome's session row (`px-2`, `pl-1 pr-1`, …). */
18
+ inset: string;
19
+ /** The same padding in px, for the guide geometry. */
20
+ insetPx: number;
21
+ /** Width of the row's leading slot: 16px, 18px on the modern touch row. */
22
+ slotWidth: number;
23
+ /** Gap between the leading slot and the harness/robot mark (the row's `w-2`). */
24
+ markGap: number;
25
+ /** Vertical padding of the chrome's session row, so heights match. */
26
+ padding: string;
27
+ /** Harness/robot mark width, in px. */
28
+ glyph: number;
29
+ }
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  import type { TargetedMouseEvent } from 'preact';
25
- import { Check, ChevronDown, ChevronRight, CircleQuestionMark, Hourglass, Loader2 } from 'lucide-preact';
25
+ import { Check, ChevronDown, ChevronRight, CircleQuestionMark, GitBranch, Hourglass, Loader2 } from 'lucide-preact';
26
26
  import { SelectionCheckbox } from '@/client/components/common/batch-selection/SelectionCheckbox';
27
27
 
28
28
  export interface StatusSlotProps {
@@ -35,6 +35,8 @@ export interface StatusSlotProps {
35
35
  expandable?: boolean;
36
36
  isExpanded?: boolean;
37
37
  onToggleExpand?: (event: TargetedMouseEvent<HTMLElement>) => void;
38
+ /** Drawn inside a parent's branch; a leaf child gets a child mark in its slot. */
39
+ child?: boolean;
38
40
  selectable?: boolean;
39
41
  selected?: boolean;
40
42
  onToggleSelect?: () => void;
@@ -51,6 +53,7 @@ export function StatusSlot({
51
53
  expandable = false,
52
54
  isExpanded = false,
53
55
  onToggleExpand,
56
+ child = false,
54
57
  selectable = false,
55
58
  selected = false,
56
59
  onToggleSelect,
@@ -88,9 +91,9 @@ export function StatusSlot({
88
91
  event.stopPropagation();
89
92
  onToggleExpand(event);
90
93
  }}
91
- title={isExpanded ? 'Collapse child sessions' : 'Expand child sessions'}
94
+ title={isExpanded ? 'Collapse sessions and subagents' : 'Expand sessions and subagents'}
92
95
  aria-expanded={isExpanded}
93
- aria-label={isExpanded ? 'Collapse child sessions' : 'Expand child sessions'}
96
+ aria-label={isExpanded ? 'Collapse sessions and subagents' : 'Expand sessions and subagents'}
94
97
  className={`peer absolute inset-0 flex items-center justify-center rounded cursor-pointer transition-opacity ${
95
98
  chevronPinned
96
99
  ? 'text-ink/55 hover:text-ink'
@@ -126,6 +129,15 @@ export function StatusSlot({
126
129
  )}
127
130
  </span>
128
131
  )}
132
+ {child && !(expandable && onToggleExpand) && !showStatus && (
133
+ <span
134
+ data-testid="child-indicator"
135
+ aria-hidden="true"
136
+ className="pointer-events-none absolute inset-0 flex items-center justify-center text-ink/35"
137
+ >
138
+ <GitBranch size={size - 1} aria-hidden="true" />
139
+ </span>
140
+ )}
129
141
  </span>
130
142
  <span className="w-2 shrink-0" />
131
143
  </>
@@ -45,18 +45,30 @@
45
45
  */
46
46
 
47
47
  import type { TargetedMouseEvent } from 'preact';
48
- import { Boxes } from 'lucide-preact';
49
48
  import { useInlineRename } from '@/client/hooks/ui/inline-rename';
50
49
  import { useSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
51
50
  import { SessionActionsMenu, useRowMenu } from '@/client/components/common/session-actions-menu';
52
51
  import { StatusSlot } from '@/client/components/common/session-row/StatusSlot';
53
52
  import { HarnessGlyph, HARNESS_GLYPH_SIZE } from '@/client/components/common/harness-glyph';
53
+ import type { BranchRowStyle } from '@/client/components/common/session-branch/style';
54
54
  import { TrailingSlot } from '@/client/components/common/session-row/TrailingSlot';
55
55
  import { WorktreeBadge } from '@/client/components/layout/session-sidebar/WorktreeBadge';
56
56
  import type { SessionWorktreeInfo } from '@/shared/lib/workspace/worktree/types';
57
57
 
58
58
  export type SessionRowDensity = 'compact' | 'touch';
59
59
 
60
+ /** What a subagent row under this chrome's rows borrows from it. */
61
+ export function sessionRowBranchStyle(touch: boolean): BranchRowStyle {
62
+ return {
63
+ inset: 'pl-1 pr-1',
64
+ insetPx: 4,
65
+ slotWidth: touch ? 18 : 16,
66
+ markGap: 8,
67
+ padding: touch ? 'py-0.5' : 'py-[7px]',
68
+ glyph: touch ? HARNESS_GLYPH_SIZE.touch : HARNESS_GLYPH_SIZE.compact,
69
+ };
70
+ }
71
+
60
72
  export interface SessionRowProps {
61
73
  sessionId: string | number;
62
74
  title: string;
@@ -71,14 +83,15 @@ export interface SessionRowProps {
71
83
  worktree?: SessionWorktreeInfo;
72
84
  /** The row's prompt is held until another session finishes. */
73
85
  waitingFor?: { title: string | null };
74
- hasSubagents?: boolean;
75
- /** Whether the subagent roster is open; a separate control from children. */
76
- subagentsExpanded?: boolean;
77
- onToggleSubagents?: (event: TargetedMouseEvent<HTMLElement>) => void;
78
- /** Whether this row can expand child sessions. */
86
+ /** Whether this row can expand its branch (child sessions and subagents). */
79
87
  expandable?: boolean;
80
88
  isExpanded?: boolean;
81
89
  onToggleExpand?: (event: TargetedMouseEvent<HTMLElement>) => void;
90
+ /** Drawn inside a parent's branch; a leaf child gets a child mark in its slot. */
91
+ isChild?: boolean;
92
+ /** The folder the row belongs to, so a child spawned from its menu lands in
93
+ * the right list before the server answers. */
94
+ folderId?: number | string;
82
95
  onClick?: () => void;
83
96
  onRename?: (name: string) => void;
84
97
  onRenameWithAi?: () => void;
@@ -103,12 +116,11 @@ export function SessionRow({
103
116
  timeAgo,
104
117
  worktree,
105
118
  waitingFor,
106
- hasSubagents = false,
107
- subagentsExpanded = false,
108
- onToggleSubagents,
109
119
  expandable = false,
110
120
  isExpanded = false,
111
121
  onToggleExpand,
122
+ isChild = false,
123
+ folderId,
112
124
  onClick,
113
125
  onRename,
114
126
  onRenameWithAi,
@@ -188,6 +200,7 @@ export function SessionRow({
188
200
  expandable={expandable}
189
201
  isExpanded={isExpanded}
190
202
  onToggleExpand={onToggleExpand}
203
+ child={isChild}
191
204
  selectable={selectable}
192
205
  selected={selected}
193
206
  onToggleSelect={onToggleSelect}
@@ -216,22 +229,6 @@ export function SessionRow({
216
229
  {worktree && <WorktreeBadge worktree={worktree} />}
217
230
  </span>
218
231
 
219
- {hasSubagents && onToggleSubagents && !selectable && (
220
- <button
221
- type="button"
222
- onClick={(event) => {
223
- event.stopPropagation();
224
- onToggleSubagents(event);
225
- }}
226
- title="Subagents (tool calls)"
227
- aria-label="Subagents"
228
- aria-expanded={subagentsExpanded}
229
- className={`shrink-0 rounded p-1 text-ink/40 hover:bg-ink/10 hover:text-ink cursor-pointer ${touch ? 'ml-1' : 'ml-0.5'}`}
230
- >
231
- <Boxes size={touch ? 15 : 13} />
232
- </button>
233
- )}
234
-
235
232
  <TrailingSlot
236
233
  timeAgo={timeAgo}
237
234
  touch={touch}
@@ -244,6 +241,8 @@ export function SessionRow({
244
241
  <SessionActionsMenu
245
242
  anchor={menu.anchor}
246
243
  sessionId={sessionId}
244
+ {...(harness ? { harness } : {})}
245
+ {...(folderId !== undefined ? { folderId } : {})}
247
246
  isArchived={isArchived}
248
247
  onRename={onRename ? startRename : undefined}
249
248
  onRenameWithAi={onRenameWithAi}
@@ -107,6 +107,17 @@ describe('modern session row', () => {
107
107
  expect(el.querySelector('[role="status"]')?.getAttribute('aria-label')).toBe('Generating a name…');
108
108
  });
109
109
 
110
+ test('a leaf child fills its empty slot with the child mark', async () => {
111
+ const el = await mount({ isChild: true });
112
+ expect(el.querySelector('[data-testid="child-indicator"] svg')).not.toBeNull();
113
+ });
114
+
115
+ test('a child with a branch keeps the chevron, not the mark', async () => {
116
+ const el = await mount({ isChild: true, expandable: true, onToggleExpand: () => {} });
117
+ expect(el.querySelector('[data-testid="child-indicator"]')).toBeNull();
118
+ expect(el.querySelector('button[aria-expanded]')).not.toBeNull();
119
+ });
120
+
110
121
  test('the actions trigger is drawn and named, and is not hidden from the keyboard', async () => {
111
122
  const el = await mount({ onRename: () => {} });
112
123
  const trigger = el.querySelector('[aria-label="Session actions"]');
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
2
2
  import type { ReactNode } from 'preact/compat';
3
3
  import { flushSession, loadSession, migrateSessionState, recordSessionOpen } from '@/shared/lib/workspace/session-state/store';
4
- import { consumeAdoption } from '@/client/hooks/chat/omp/pending-sessions';
4
+ import { consumeAdoption } from '@/client/hooks/chat/omp/pending-adoption';
5
5
  import { SessionStateContext } from '@/client/hooks/workspace/session-state/context';
6
6
 
7
7
  /**
@@ -51,6 +51,7 @@ import { useToasts } from '@/client/hooks/ui/toasts';
51
51
  import { useUpdates } from '@/client/hooks/ui/updates';
52
52
  import { UPDATE_REQUEST_EVENT } from '@/shared/lib/updates/popup-state';
53
53
  import { MAX_LEFT_PANEL_WIDTH } from '@/shared/lib/workspace/sidebar-width';
54
+ import { updateOutcomeTone } from '@/shared/lib/ui/toast-duration';
54
55
  import type { AgentStreamStatus } from '@/shared/lib/chat/omp/status';
55
56
 
56
57
  interface LeftColumnProps {
@@ -102,7 +103,7 @@ export function LeftColumn({
102
103
  setInfoOpen(true);
103
104
  void updates.apply('kabmo').then((result) => {
104
105
  if (!result) return;
105
- pushToast(result.message, result.success && !result.manual ? 'success' : 'error');
106
+ pushToast(result.message, updateOutcomeTone(result));
106
107
  });
107
108
  });
108
109
 
@@ -6,18 +6,19 @@ import { useShowMore } from '@/client/hooks/ui/show-more';
6
6
  import { useWorkspaceFolderActions } from '@/client/hooks/workspace/workspace-folder-actions';
7
7
  import { useSessionDelete } from '@/client/hooks/workspace/session-delete';
8
8
  import { SessionDeleteModal } from '@/client/components/common/session-delete-modal';
9
- import { SessionItem } from '@/client/components/layout/session-sidebar/SessionItem';
9
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
10
+ import { SessionItem, SESSION_ITEM_BRANCH_STYLE } from '@/client/components/layout/session-sidebar/SessionItem';
10
11
  import { CategoryHeader } from '@/client/components/layout/session-sidebar/CategoryHeader';
11
- import { SubagentList } from '@/client/components/common/subagent-list';
12
- import { ChildSessionList } from '@/client/components/layout/session-sidebar/ChildSessionList';
12
+ import { SessionBranch, branchControlFor } from '@/client/components/common/session-branch';
13
+ import type { BranchControl } from '@/client/components/common/session-branch';
13
14
  import { buildSessionTree } from '@/client/lib/session-tree';
14
15
  import { useExpandedSessions } from '@/client/hooks/workspace/expanded-sessions';
15
- import { useChildExpansion } from '@/client/hooks/workspace/child-expansion';
16
16
  import { relativeTimeAgo } from '@/shared/lib/workspace/relative-time';
17
+ import { isPendingSessionId } from '@/shared/lib/omp/session/default-title';
17
18
  import { useSidebarData } from '@/client/hooks/chat/omp/session-list';
18
19
  import type { BatchBinding } from '@/client/components/common/batch-selection/types';
19
20
  import { folderBatchState } from '@/client/components/common/batch-selection/folder-state';
20
- import type { WorkspaceFolderData } from '@/shared/types';
21
+ import type { SessionItemData, WorkspaceFolderData } from '@/shared/types';
21
22
 
22
23
  export { SessionItem };
23
24
 
@@ -43,7 +44,7 @@ export function Category({
43
44
  forceExpanded?: boolean;
44
45
  showArchived?: boolean;
45
46
  sessionStatus?: Record<string, 'stream' | 'finish' | 'abort'>;
46
- onToast?: (message: string, type?: 'success' | 'error') => void;
47
+ onToast?: (message: string, type?: ToastTone) => void;
47
48
  /** Present only while a batch selection is active; absent is the normal list. */
48
49
  batch?: BatchBinding;
49
50
  /** Start a session selection scoped to this workspace, from its `⋯` menu. */
@@ -58,10 +59,9 @@ export function Category({
58
59
  const urlSubagentId = searchParams.get('subagent');
59
60
  const urlSessionId = searchParams.get('sessionId');
60
61
 
61
- // Roster expansion is shared with the mobile drawer: one persisted set, so a
62
- // row expanded on the phone is expanded here too.
62
+ // ONE expansion set for the whole branch: child sessions and the subagent
63
+ // roster are the same disclosure now, so they cannot disagree.
63
64
  const { expandedSessionIds, toggleSession } = useExpandedSessions();
64
- const { expandedChildIds, toggleChild } = useChildExpansion();
65
65
 
66
66
  useEffect(() => {
67
67
  if (typeof folder.isExpanded === 'boolean') setIsOpen(folder.isExpanded);
@@ -155,6 +155,53 @@ export function Category({
155
155
  const listOpen = isActuallyOpen || sessionCheckboxes;
156
156
  const hasMore = hiddenCount > 0;
157
157
 
158
+ // One row renderer for roots and for every descendant: a child session is
159
+ // the same row as a root, so a rule fixed on one is fixed on both.
160
+ const renderSessionRow = (session: SessionItemData, control: BranchControl) => {
161
+ const sessionKey = String(session.id);
162
+ const isActive = activeSessionId !== null
163
+ ? String(activeSessionId) === sessionKey
164
+ : session.is_active === 1;
165
+ // While one of its subagents is being viewed, the row dims so the
166
+ // highlighted leaf reads as the active one.
167
+ const isViewingSubagent = isActive && urlSessionId === sessionKey && Boolean(urlSubagentId);
168
+ const pending = isPendingSessionId(sessionKey);
169
+ return (
170
+ <SessionItem
171
+ sessionId={session.id}
172
+ title={session.title}
173
+ harness={session.harness}
174
+ folderId={session.folder_id}
175
+ isActive={isActive && !isViewingSubagent}
176
+ isArchived={session.is_archived === 1}
177
+ status={sessionStatus[sessionKey]}
178
+ awaitingInput={Boolean(session.awaitingInput)}
179
+ worktree={session.worktree}
180
+ timeAgo={relativeTimeAgo(session.updated_at ?? session.created_at)}
181
+ onClick={() => onSelectSession(session.id)}
182
+ onArchive={() => handleArchive(session)}
183
+ // A pending `new-…` chat has no transcript anywhere yet — there is
184
+ // nothing to delete, and the server refuses it.
185
+ onDelete={pending ? undefined : () => sessionDelete.requestDelete(session)}
186
+ onRename={pending ? undefined : (name) => void handleRename(session, name)}
187
+ onRenameWithAi={pending ? undefined : () => void handleRenameWithAi(session)}
188
+ expandable={control.expandable} isChild={control.isChild}
189
+ isExpanded={control.isExpanded}
190
+ onToggleExpand={control.onToggleExpand}
191
+ waitingFor={session.waitingFor ? { title: session.waitingFor.title } : undefined}
192
+ onCancelWait={
193
+ session.waitingFor ? () => onCancelWait?.(session.waitingFor!.waitId) : undefined
194
+ }
195
+ selectable={sessionCheckboxes}
196
+ selected={Boolean(batch?.selected.includes(sessionKey))}
197
+ onToggleSelect={batch ? () => batch.toggle(sessionKey) : undefined}
198
+ />
199
+ );
200
+ };
201
+
202
+ const controlFor = (session: SessionItemData): BranchControl =>
203
+ branchControlFor(session, tree.childrenOf, expandedSessionIds, toggleSession);
204
+
158
205
  return (
159
206
  <div className="space-y-1">
160
207
  <CategoryHeader
@@ -195,72 +242,22 @@ export function Category({
195
242
  <div className="space-y-0.5">
196
243
  {tree.roots.map((session) => {
197
244
  const sessionKey = String(session.id);
198
- const isActive = activeSessionId !== null
199
- ? String(activeSessionId) === sessionKey
200
- : session.is_active === 1;
201
- // While one of its subagents is being viewed, the parent session
202
- // row dims so the highlighted roster entry reads as the active one.
203
- const isViewingSubagent = isActive && urlSessionId === sessionKey && Boolean(urlSubagentId);
204
- const canExpandActive = activeSessionId !== null && sessionKey === String(activeSessionId);
205
- // Two independent disclosures: children (the tree) and subagents
206
- // (a tool-call roster). The chevron belongs to the first, the badge
207
- // to the second.
208
- const hasChildren = (tree.childrenOf.get(sessionKey)?.length ?? 0) > 0;
209
- const hasSubagents = Boolean(session.hasSubagents);
210
- const childrenExpanded = hasChildren && expandedChildIds.has(sessionKey);
211
- const rosterExpanded = hasSubagents && expandedSessionIds.has(sessionKey);
212
-
245
+ const control = controlFor(session);
213
246
  return (
214
247
  <div key={session.id} className="space-y-0.5">
215
- <SessionItem
216
- sessionId={session.id}
217
- title={session.title}
218
- harness={session.harness}
219
- isActive={isActive && !isViewingSubagent}
220
- isArchived={session.is_archived === 1}
221
- status={sessionStatus[sessionKey]}
222
- awaitingInput={Boolean(session.awaitingInput)}
223
- worktree={session.worktree}
224
- timeAgo={relativeTimeAgo(session.updated_at ?? session.created_at)}
225
- onClick={() => onSelectSession(session.id)}
226
- onArchive={() => handleArchive(session)}
227
- onDelete={
228
- // A pending `new-…` chat has no transcript anywhere yet —
229
- // there is nothing to delete, and the server refuses it.
230
- String(session.id).startsWith('new-')
231
- ? undefined
232
- : () => sessionDelete.requestDelete(session)
233
- }
234
- onRename={String(session.id).startsWith('new-') ? undefined : (name) => void handleRename(session, name)}
235
- onRenameWithAi={
236
- String(session.id).startsWith('new-') ? undefined : () => void handleRenameWithAi(session)
237
- }
238
- expandable={hasChildren}
239
- hasSubagents={hasSubagents}
240
- isExpanded={childrenExpanded}
241
- onToggleExpand={() => toggleChild(sessionKey)}
242
- subagentsExpanded={rosterExpanded}
243
- onToggleSubagents={() => toggleSession(sessionKey)}
244
- waitingFor={session.waitingFor ? { title: session.waitingFor.title } : undefined}
245
- onCancelWait={
246
- session.waitingFor
247
- ? () => onCancelWait?.(session.waitingFor!.waitId)
248
- : undefined
249
- }
250
- selectable={sessionCheckboxes}
251
- selected={Boolean(batch?.selected.includes(sessionKey))}
252
- onToggleSelect={batch ? () => batch.toggle(sessionKey) : undefined}
253
- />
254
- {childrenExpanded && (
255
- <ChildSessionList
248
+ {renderSessionRow(session, control)}
249
+ {control.isExpanded && (
250
+ <SessionBranch
256
251
  parentId={sessionKey}
252
+ hasSubagents={Boolean(session.hasSubagents)}
257
253
  childrenOf={tree.childrenOf}
258
- onSelect={onSelectSession}
254
+ expandedIds={expandedSessionIds}
255
+ onToggle={toggleSession}
256
+ activeSessionId={activeSessionId === null ? null : String(activeSessionId)}
257
+ renderSession={renderSessionRow}
258
+ style={SESSION_ITEM_BRANCH_STYLE}
259
259
  />
260
260
  )}
261
- {rosterExpanded && (
262
- <SubagentList sessionId={session.id} isActiveSession={canExpandActive} />
263
- )}
264
261
  </div>
265
262
  );
266
263
  })}