@kabmo-labs/kabmo 0.25.0 → 0.26.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 (188) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +440 -436
  3. package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
  4. package/dist/client/static/js/index-p2yw9ywf.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/session-actions-menu/index.tsx +38 -12
  7. package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
  8. package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
  9. package/src/client/components/common/session-branch/index.tsx +169 -0
  10. package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
  11. package/src/client/components/common/session-branch/style.ts +29 -0
  12. package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
  13. package/src/client/components/common/session-row/index.tsx +24 -25
  14. package/src/client/components/common/session-row/session-row.test.tsx +11 -0
  15. package/src/client/components/common/session-state-provider/index.tsx +1 -1
  16. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +64 -68
  17. package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
  18. package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
  19. package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
  20. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
  22. package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
  23. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
  25. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -13
  26. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
  27. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
  28. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
  29. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
  30. package/src/client/components/settings/Sidebar.tsx +1 -1
  31. package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
  32. package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
  33. package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
  34. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
  35. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
  36. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +28 -39
  37. package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
  38. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
  39. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
  40. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
  41. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
  42. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
  43. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
  44. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
  45. package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
  46. package/src/client/components/workspace/chat-timeline/index.tsx +10 -21
  47. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
  48. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
  49. package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
  50. package/src/client/hooks/chat/composer/items.test.ts +19 -0
  51. package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
  52. package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
  53. package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
  54. package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
  55. package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
  56. package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
  57. package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
  58. package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
  59. package/src/client/hooks/chat/omp/run-switch.ts +1 -1
  60. package/src/client/hooks/chat/omp/session-list.tsx +4 -0
  61. package/src/client/hooks/chat/subagents/roster.ts +122 -0
  62. package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
  63. package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
  64. package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
  65. package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
  66. package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
  67. package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
  68. package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
  69. package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
  70. package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
  71. package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
  72. package/src/client/hooks/chat/timeline/modes.ts +42 -29
  73. package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
  74. package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
  75. package/src/client/hooks/chat/timeline/send.ts +17 -103
  76. package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
  77. package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
  78. package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
  79. package/src/client/hooks/models/use-harness-update.test.ts +137 -44
  80. package/src/client/hooks/models/use-harness-update.ts +133 -85
  81. package/src/client/hooks/ui/input-required-alert.ts +12 -5
  82. package/src/client/hooks/ui/notifications.ts +45 -0
  83. package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
  84. package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
  85. package/src/client/lib/native/open-session.ts +33 -0
  86. package/src/client/lib/notifications/os.test.ts +125 -0
  87. package/src/client/lib/notifications/os.ts +130 -0
  88. package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
  89. package/src/client/lib/router/open-session.test.ts +75 -0
  90. package/src/client/lib/router/open-session.ts +34 -0
  91. package/src/client/lib/signals.ts +5 -1
  92. package/src/client/main.tsx +6 -0
  93. package/src/server/lib/db/schema.ts +1 -0
  94. package/src/server/lib/harness/acp/calls.ts +15 -1
  95. package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
  96. package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
  97. package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
  98. package/src/server/lib/harness/acp/client-fs.ts +131 -0
  99. package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
  100. package/src/server/lib/harness/acp/client-initialize.ts +84 -0
  101. package/src/server/lib/harness/acp/client.ts +31 -21
  102. package/src/server/lib/harness/acp/commands.test.ts +5 -5
  103. package/src/server/lib/harness/acp/commands.ts +14 -2
  104. package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
  105. package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
  106. package/src/server/lib/harness/acp/frames.ts +71 -158
  107. package/src/server/lib/harness/acp/mapper.test.ts +40 -0
  108. package/src/server/lib/harness/acp/mapper.ts +12 -0
  109. package/src/server/lib/harness/acp/permissions.ts +6 -0
  110. package/src/server/lib/harness/acp/protocol.ts +41 -2
  111. package/src/server/lib/harness/acp/session-facts.ts +1 -1
  112. package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
  113. package/src/server/lib/harness/acp/session-handshake.ts +83 -6
  114. package/src/server/lib/harness/acp/session-idle.ts +7 -6
  115. package/src/server/lib/harness/acp/session-notifications.ts +41 -2
  116. package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
  117. package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
  118. package/src/server/lib/harness/acp/session-permissions.ts +36 -0
  119. package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
  120. package/src/server/lib/harness/acp/session-requests.ts +48 -6
  121. package/src/server/lib/harness/acp/session-turns.ts +8 -3
  122. package/src/server/lib/harness/acp/session-usage.ts +4 -0
  123. package/src/server/lib/harness/acp/session-web-state.ts +30 -2
  124. package/src/server/lib/harness/acp/session.test-util.ts +19 -1
  125. package/src/server/lib/harness/acp/session.ts +60 -60
  126. package/src/server/lib/harness/acp/tool-calls.ts +223 -0
  127. package/src/server/lib/harness/acp/turn.test.ts +102 -0
  128. package/src/server/lib/harness/acp/turn.ts +81 -6
  129. package/src/server/lib/harness/acp/v2.test.ts +144 -0
  130. package/src/server/lib/harness/acp/v2.ts +220 -0
  131. package/src/server/lib/harness/acp/verbs.ts +46 -6
  132. package/src/server/lib/harness/launch.test.ts +25 -0
  133. package/src/server/lib/harness/launch.ts +21 -9
  134. package/src/server/lib/harness/session.ts +3 -0
  135. package/src/server/lib/harness/update-job-store.test.ts +37 -12
  136. package/src/server/lib/harness/update-job-store.ts +22 -16
  137. package/src/server/lib/harness/update-job.server.ts +66 -175
  138. package/src/server/lib/harness/update-queue.server.ts +292 -0
  139. package/src/server/lib/harness/update-queue.test.ts +265 -0
  140. package/src/server/lib/harness/update-spawn.server.ts +96 -0
  141. package/src/server/lib/harness/update-worker.ts +8 -3
  142. package/src/server/lib/lifecycle/after-listen.ts +9 -0
  143. package/src/server/lib/lifecycle/paths.ts +14 -9
  144. package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
  145. package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
  146. package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
  147. package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
  148. package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
  149. package/src/server/lib/sessions/fork.server.test.ts +68 -0
  150. package/src/server/lib/sessions/fork.server.ts +31 -6
  151. package/src/server/lib/sessions/spawn.server.test.ts +41 -0
  152. package/src/server/lib/sessions/spawn.server.ts +27 -2
  153. package/src/server/routes/agent/harness-command.ts +6 -5
  154. package/src/server/routes/chat/stream.ts +7 -2
  155. package/src/server/routes/harness/update-status.ts +18 -12
  156. package/src/server/routes/harness/update.test.ts +53 -16
  157. package/src/server/routes/harness/update.ts +13 -8
  158. package/src/server/routes/sessions/body-readers.ts +43 -0
  159. package/src/server/routes/sessions/fork.ts +19 -4
  160. package/src/server/routes/sessions/routes.test.ts +1 -2
  161. package/src/server/routes/sessions/session.ts +19 -0
  162. package/src/server/routes/sessions/spawn.ts +16 -13
  163. package/src/shared/lib/chat/omp/agent-events.ts +11 -0
  164. package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
  165. package/src/shared/lib/harness/mode-signal.ts +20 -0
  166. package/src/shared/lib/harness/session-modes.ts +24 -0
  167. package/src/shared/lib/harness/update-job.ts +53 -6
  168. package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
  169. package/src/shared/lib/notifications/outcomes.test.ts +96 -0
  170. package/src/shared/lib/notifications/outcomes.ts +64 -0
  171. package/src/shared/lib/notifications/settings.test.ts +49 -0
  172. package/src/shared/lib/notifications/settings.ts +34 -0
  173. package/src/shared/lib/omp/session/default-title.ts +5 -4
  174. package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
  175. package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
  176. package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
  177. package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
  178. package/src/shared/lib/settings/defaults.ts +3 -0
  179. package/src/shared/types/harness-update.ts +24 -0
  180. package/src/shared/types/realtime.ts +2 -0
  181. package/src/shared/types/settings/state.ts +10 -0
  182. package/src/shared/types/workspace.ts +4 -0
  183. package/src/test-support/harness-table.test-util.ts +25 -9
  184. package/dist/client/static/js/index-bc9aa4mx.css +0 -1
  185. package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
  186. package/src/client/components/common/subagent-list/index.tsx +0 -165
  187. package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
  188. package/src/client/hooks/workspace/child-expansion.ts +0 -33
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * One subagent in a session's branch.
8
+ *
9
+ * A subagent is a leaf: it is a tool call, not a session, and it opens the
10
+ * subagent transcript rather than `/sessions/:id`. The robot mark replaces the
11
+ * harness mark in the same column every session row puts it, and the leading
12
+ * 16px slot is the SHARED slot rule — one glyph there, and for a leaf that
13
+ * glyph is the run state, exactly as a parent row shows a status when it has
14
+ * no branch to disclose.
15
+ */
16
+
17
+ import { Bot, Square } from 'lucide-preact';
18
+ import { useSearchParams } from '@/client/lib/router/search-params';
19
+ import { SubagentStatusIcon } from '@/client/components/common/SubagentStatusIcon';
20
+ import type { BranchRowStyle } from '@/client/components/common/session-branch/style';
21
+ import { subagentRowLabel } from '@/shared/lib/omp/subagent/label';
22
+ import { cancelSubagent } from '@/shared/lib/omp/subagent/control';
23
+ import type { SubagentInfo } from '@/shared/types';
24
+
25
+ export interface SubagentRowProps {
26
+ subagent: SubagentInfo;
27
+ /** The session that owns the roster; the view event and cancel address it. */
28
+ sessionId: string;
29
+ style: BranchRowStyle;
30
+ /** A live run this process can stop (and show as pulsing). */
31
+ running: boolean;
32
+ }
33
+
34
+ export function SubagentRow({ subagent, sessionId, style, running }: SubagentRowProps) {
35
+ const [searchParams] = useSearchParams();
36
+ const viewed = subagent.id === searchParams.get('subagent');
37
+ const label = subagentRowLabel(subagent);
38
+ const brief = subagent.task ?? subagent.assignment ?? subagent.description ?? label;
39
+
40
+ return (
41
+ <div className="group/subagent-row flex items-center">
42
+ <button
43
+ type="button"
44
+ title={brief}
45
+ onClick={() => window.dispatchEvent(
46
+ new CustomEvent('omp:view-subagent', { detail: { sessionId, subagent } }),
47
+ )}
48
+ className={`flex-1 min-w-0 flex items-center text-left text-xs rounded-md ${style.inset} ${style.padding} cursor-pointer transition-colors select-none ${
49
+ viewed ? 'bg-ink/10 font-medium text-ink' : 'text-ink/70 hover:text-ink hover:bg-ink/5'
50
+ }`}
51
+ >
52
+ <span
53
+ data-testid="subagent-status-slot"
54
+ className="w-4 h-4 flex items-center justify-center shrink-0"
55
+ >
56
+ <SubagentStatusIcon status={subagent.status} live={running} size={11} />
57
+ </span>
58
+ <span className="w-2 shrink-0" />
59
+ <span data-testid="subagent-mark" className="mr-1.5 flex shrink-0 items-center text-ink/55">
60
+ <Bot size={style.glyph} aria-hidden="true" />
61
+ </span>
62
+ <span className="flex-1 min-w-0 truncate leading-snug">{label}</span>
63
+ </button>
64
+ {running && (
65
+ <button
66
+ type="button"
67
+ title="Stop this subagent"
68
+ aria-label="Stop this subagent"
69
+ onClick={() => void cancelSubagent(sessionId, subagent.id)}
70
+ className="touch-visible shrink-0 mr-1 w-5 h-5 flex items-center justify-center rounded text-ink/40 hover:text-error hover:bg-error/5 opacity-0 group-hover/subagent-row:opacity-100 transition-opacity cursor-pointer"
71
+ >
72
+ <Square size={10} />
73
+ </button>
74
+ )}
75
+ </div>
76
+ );
77
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The branch under ONE session row: its child sessions first, then its
8
+ * subagents, drawn as one tree.
9
+ *
10
+ * A session has exactly one disclosure. Before this, children and the subagent
11
+ * roster were two lists behind two controls (a chevron and a `Boxes` badge),
12
+ * which is why a row could be open in one sense and closed in the other. Now
13
+ * the chevron opens this branch, and the branch is the union of the two.
14
+ *
15
+ * Ordering is the order the lists already had: child sessions (the sidebar's
16
+ * own sort), then the roster (its own batch/index order). A child session can
17
+ * itself have a branch, so the renderer recurses one level per child — the
18
+ * guide cells carry the depth, not a second row style.
19
+ *
20
+ * The chrome owns the row component (classic, modern, mobile), so it supplies
21
+ * `renderSession`; everything below that is shared, including the subagent
22
+ * rows and the tree lines.
23
+ */
24
+
25
+ import { Fragment } from 'preact';
26
+ import type { ComponentChild } from 'preact';
27
+ import { BranchGuides } from '@/client/components/common/session-branch/BranchGuides';
28
+ import { SubagentRow } from '@/client/components/common/session-branch/SubagentRow';
29
+ import type { BranchRowStyle } from '@/client/components/common/session-branch/style';
30
+ import { useSubagentRoster } from '@/client/hooks/chat/subagents/roster';
31
+ import type { SessionItemData } from '@/shared/types';
32
+
33
+ /** What the chrome's row needs to know about its branch. */
34
+ export interface BranchControl {
35
+ /** The row has child sessions, subagents, or both. */
36
+ expandable: boolean;
37
+ isExpanded: boolean;
38
+ onToggleExpand: () => void;
39
+ /**
40
+ * This row is a CHILD session (it is drawn inside a branch). A leaf child
41
+ * has no chevron and no run cue, so its leading slot is otherwise empty; the
42
+ * row draws a child mark there instead of leaving a hole.
43
+ */
44
+ isChild: boolean;
45
+ }
46
+
47
+ /**
48
+ * The control a session row gets from its own subtree and the one expansion
49
+ * set. Shared by all three chromes: a row that is expandable in one layout and
50
+ * not in another is the same defect as two different branch lists.
51
+ */
52
+ export function branchControlFor(
53
+ session: SessionItemData,
54
+ childrenOf: Map<string, SessionItemData[]>,
55
+ expandedIds: ReadonlySet<string>,
56
+ onToggle: (sessionId: string) => void,
57
+ isChild = false,
58
+ ): BranchControl {
59
+ const key = String(session.id);
60
+ return {
61
+ expandable: (childrenOf.get(key)?.length ?? 0) > 0 || Boolean(session.hasSubagents),
62
+ isExpanded: expandedIds.has(key),
63
+ onToggleExpand: () => onToggle(key),
64
+ isChild,
65
+ };
66
+ }
67
+
68
+ export interface SessionBranchProps {
69
+ /** The session whose branch this is. */
70
+ parentId: string;
71
+ /** That session's own `hasSubagents` flag; false skips the roster read. */
72
+ hasSubagents: boolean;
73
+ childrenOf: Map<string, SessionItemData[]>;
74
+ /** One set for both halves of the branch. */
75
+ expandedIds: ReadonlySet<string>;
76
+ onToggle: (sessionId: string) => void;
77
+ /** The session the URL has open, so its roster can take live frames. */
78
+ activeSessionId: string | null;
79
+ renderSession: (session: SessionItemData, control: BranchControl) => ComponentChild;
80
+ style: BranchRowStyle;
81
+ /** `isLast` of each ancestor row, outermost first. */
82
+ ancestors?: readonly boolean[];
83
+ }
84
+
85
+ export function SessionBranch({
86
+ parentId,
87
+ hasSubagents,
88
+ childrenOf,
89
+ expandedIds,
90
+ onToggle,
91
+ activeSessionId,
92
+ renderSession,
93
+ style,
94
+ ancestors = [],
95
+ }: SessionBranchProps) {
96
+ const children = childrenOf.get(parentId) ?? [];
97
+ const { subagents, isLoading } = useSubagentRoster(parentId, activeSessionId === parentId, hasSubagents);
98
+ const rows = [
99
+ ...children.map((session) => ({ kind: 'session' as const, session })),
100
+ ...subagents.map((subagent) => ({ kind: 'subagent' as const, subagent })),
101
+ ];
102
+
103
+ if (rows.length === 0) {
104
+ if (!isLoading) return null;
105
+ return (
106
+ <div data-testid="session-branch" className="space-y-0.5">
107
+ <div className="flex items-stretch">
108
+ <BranchGuides ancestors={ancestors} isLast first style={style} />
109
+ <div className={`flex min-w-0 flex-1 items-center text-xs italic text-ink/40 ${style.inset} ${style.padding}`}>
110
+ Loading subagents…
111
+ </div>
112
+ </div>
113
+ </div>
114
+ );
115
+ }
116
+
117
+ return (
118
+ <div data-testid="session-branch" className="space-y-0.5">
119
+ {rows.map((row, index) => {
120
+ const isLast = index === rows.length - 1;
121
+ if (row.kind === 'subagent') {
122
+ return (
123
+ <div key={`subagent:${row.subagent.id}`} className="flex items-stretch">
124
+ <BranchGuides ancestors={ancestors} isLast={isLast} first={index === 0} style={style} />
125
+ <div className="min-w-0 flex-1">
126
+ <SubagentRow
127
+ subagent={row.subagent}
128
+ sessionId={parentId}
129
+ style={style}
130
+ running={activeSessionId === parentId && row.subagent.status === 'started'}
131
+ />
132
+ </div>
133
+ </div>
134
+ );
135
+ }
136
+
137
+ const key = String(row.session.id);
138
+ const childCount = childrenOf.get(key)?.length ?? 0;
139
+ const control: BranchControl = {
140
+ expandable: childCount > 0 || Boolean(row.session.hasSubagents),
141
+ isExpanded: expandedIds.has(key),
142
+ onToggleExpand: () => onToggle(key),
143
+ isChild: true,
144
+ };
145
+ return (
146
+ <Fragment key={key}>
147
+ <div className="flex items-stretch">
148
+ <BranchGuides ancestors={ancestors} isLast={isLast} first={index === 0} style={style} />
149
+ <div className="min-w-0 flex-1">{renderSession(row.session, control)}</div>
150
+ </div>
151
+ {control.isExpanded && (
152
+ <SessionBranch
153
+ parentId={key}
154
+ hasSubagents={Boolean(row.session.hasSubagents)}
155
+ childrenOf={childrenOf}
156
+ expandedIds={expandedIds}
157
+ onToggle={onToggle}
158
+ activeSessionId={activeSessionId}
159
+ renderSession={renderSession}
160
+ style={style}
161
+ ancestors={[...ancestors, isLast]}
162
+ />
163
+ )}
164
+ </Fragment>
165
+ );
166
+ })}
167
+ </div>
168
+ );
169
+ }
@@ -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}