@kabmo-labs/kabmo 0.13.0 → 0.14.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 (133) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +319 -319
  3. package/dist/client/static/js/{index-vzb1qz51.js → index-nfsg1jpt.js} +779 -779
  4. package/dist/client/static/js/index-tsgy3gd1.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  7. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  8. package/src/client/components/common/code-surface/extensions.ts +7 -1
  9. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  10. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  11. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  12. package/src/client/components/common/session-row/index.tsx +205 -0
  13. package/src/client/components/common/session-row/session-row.test.tsx +144 -0
  14. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  15. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  16. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  17. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  18. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  19. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  20. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +55 -0
  21. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +184 -0
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  23. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  24. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  25. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  26. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  27. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  28. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  29. package/src/client/components/settings/Modal.tsx +5 -27
  30. package/src/client/components/settings/Sidebar.tsx +1 -1
  31. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  32. package/src/client/components/settings/apply-side-effects.ts +90 -0
  33. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  34. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  35. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  36. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  37. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  38. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  39. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  40. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  41. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  42. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  43. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  44. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  45. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  46. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +14 -5
  47. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  48. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  49. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +108 -67
  50. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  51. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  52. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  53. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +158 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  55. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  56. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  58. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  59. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  60. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  61. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  62. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  63. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  64. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  65. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  66. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  67. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  68. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  69. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  70. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  71. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  73. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  80. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  81. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  82. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  83. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  84. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  85. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  86. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  87. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  88. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  89. package/src/client/data/settings/omp-schema.json +151 -6
  90. package/src/client/hooks/chat/composer/style.ts +66 -0
  91. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  92. package/src/client/hooks/settings/providers/login.ts +11 -2
  93. package/src/client/hooks/ui/window-event.ts +20 -4
  94. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  95. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  96. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  97. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  98. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  99. package/src/client/tailwind.css +111 -0
  100. package/src/server/index.ts +10 -134
  101. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  102. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  103. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  104. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  105. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  106. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  107. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  108. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  109. package/src/server/lib/plugins/background.server.ts +17 -1
  110. package/src/server/lib/plugins/background.test.ts +33 -0
  111. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  112. package/src/server/routes/sessions/batch-archive.ts +80 -0
  113. package/src/server/routes/sessions/index.ts +4 -0
  114. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  115. package/src/shared/lib/chat/composer/style.ts +171 -0
  116. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  117. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  118. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  119. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  120. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  121. package/src/shared/lib/chat/timeline/trace-groups.test.ts +120 -0
  122. package/src/shared/lib/chat/timeline/trace-groups.ts +68 -0
  123. package/src/shared/lib/settings/defaults.ts +6 -0
  124. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  125. package/src/shared/lib/workspace/session-focus.ts +71 -0
  126. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  127. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  128. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  129. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  130. package/src/shared/types/omp/agent.ts +6 -0
  131. package/src/shared/types/settings/state.ts +31 -0
  132. package/dist/client/static/js/index-68w8h33q.css +0 -1
  133. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -48,7 +48,7 @@ import {
48
48
  } from '@codemirror/view';
49
49
  import { highlightSelectionMatches } from '@codemirror/search';
50
50
  import { history } from '@codemirror/commands';
51
- import { bracketMatching, foldGutter, indentUnit } from '@codemirror/language';
51
+ import { bracketMatching, codeFolding, foldGutter, indentUnit } from '@codemirror/language';
52
52
 
53
53
  import { commentSyntaxFor } from '@/shared/lib/code/editor/comment-syntax';
54
54
  import type { EditorCommand } from '@/shared/lib/code/editor/keymap';
@@ -56,6 +56,7 @@ import { bracketGuide } from '@/client/components/common/code-surface/bracket-gu
56
56
  import { indentDataExtension, indentExtensions } from '@/client/components/common/code-surface/indent';
57
57
  import { typingExtensions, type EditorTypingOptions } from '@/client/components/common/code-surface/typing';
58
58
  import { indentFoldService } from '@/client/components/common/code-surface/fold';
59
+ import { foldPlaceholderDom } from '@/client/components/common/code-surface/fold-placeholder';
59
60
  import { indentGuides } from '@/client/components/common/code-surface/indent-guide';
60
61
  import { findMarksField } from '@/client/components/common/code-surface/marks';
61
62
  import { surfaceKeymap } from '@/client/components/common/code-surface/keymap';
@@ -288,6 +289,11 @@ export function surfaceExtensions({
288
289
  // dropped silently — verified: no placeholder, no error.
289
290
  indentFoldService,
290
291
  foldGutter(),
292
+ // `foldGutter()` brings `codeFolding()` with its package placeholder, which
293
+ // WebKit loses to the editor's own mouse selection — see
294
+ // `fold-placeholder.ts` for the measurement. A later config wins in
295
+ // `combineConfig`, so this one replaces the package default.
296
+ codeFolding({ placeholderDOM: foldPlaceholderDom }),
291
297
  themeCompartment.of(shikiHighlight(language, themes)),
292
298
  surfaceTheme(),
293
299
  // Line blame, when the panel turned it on: the labels, the state field they
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `…` a folded range collapses into.
8
+ *
9
+ * CodeMirror's default placeholder is a bare span whose only handler is
10
+ * `onclick`. That is enough on Chromium and not on WebKit: a `mousedown`
11
+ * inside the content DOM starts CodeMirror's own mouse selection, which
12
+ * re-creates the widget's DOM before `mouseup`, so the click lands on a node
13
+ * that is no longer in the document and the fold never opens — measured on
14
+ * WebKit 27 with `@codemirror/language` 6: the placeholder was removed and
15
+ * re-added inside the same mousedown, and no `click` event followed.
16
+ *
17
+ * Cancelling the press fixes it at the source: the editor never starts a
18
+ * selection over the widget, the node survives, and the browser dispatches the
19
+ * click the package already listens for. `preventDefault` alone is not enough
20
+ * to stop the DOM churn in every case, so propagation is stopped too — the
21
+ * widget owns its own pointer events and has nothing to hand upward.
22
+ */
23
+ import type { EditorView } from '@codemirror/view';
24
+
25
+ export type FoldPlaceholderClick = (event: MouseEvent) => void;
26
+
27
+ /** The fold widget's DOM, wired so its click survives a press. */
28
+ export function foldPlaceholderDom(
29
+ view: EditorView,
30
+ onclick: FoldPlaceholderClick,
31
+ ): HTMLElement {
32
+ const element = document.createElement('span');
33
+ element.className = 'cm-foldPlaceholder';
34
+ element.textContent = '…';
35
+ element.setAttribute('aria-label', view.state.phrase('folded code'));
36
+ element.title = view.state.phrase('unfold');
37
+ element.onclick = onclick;
38
+ element.addEventListener('mousedown', (event) => {
39
+ event.preventDefault();
40
+ event.stopPropagation();
41
+ });
42
+ return element;
43
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The 16px leading slot of a session row, in the `modern` style.
8
+ *
9
+ * One slot owns every glyph — never two side by side — which is the rule both
10
+ * shipped rows already follow and the reason a running session does not push
11
+ * its title sideways. The order of precedence is unchanged, because each rung
12
+ * is a bug the previous one fixed:
13
+ *
14
+ * 1. an in-flight rename — it answers a click that is still pending;
15
+ * 2. blocked on a question — says it is YOUR turn, not that work is happening;
16
+ * 3. a held prompt — the row exists only because a prompt is waiting;
17
+ * 4. a run in flight — the spinner;
18
+ * 5. the roster chevron, PINNED while the row has subagents.
19
+ *
20
+ * A batch checkbox replaces the whole slot: in that mode the row is a choice,
21
+ * and a run spinner beside a checkbox reads as a second, unrelated control.
22
+ */
23
+
24
+ import type { TargetedMouseEvent } from 'preact';
25
+ import { Check, ChevronDown, ChevronRight, CircleQuestionMark, Hourglass, Loader2 } from 'lucide-preact';
26
+ import { SelectionCheckbox } from '@/client/components/common/batch-selection/SelectionCheckbox';
27
+
28
+ export interface StatusSlotProps {
29
+ title: string;
30
+ status?: 'stream' | 'finish' | 'abort';
31
+ awaitingInput?: boolean;
32
+ renaming?: boolean;
33
+ waitingFor?: { title: string | null };
34
+ /** The row has a subagent roster, so the chevron exists. */
35
+ expandable?: boolean;
36
+ isExpanded?: boolean;
37
+ onToggleExpand?: (event: TargetedMouseEvent<HTMLElement>) => void;
38
+ selectable?: boolean;
39
+ selected?: boolean;
40
+ onToggleSelect?: () => void;
41
+ /** Larger glyphs for a touch row. */
42
+ touch?: boolean;
43
+ }
44
+
45
+ export function StatusSlot({
46
+ title,
47
+ status,
48
+ awaitingInput = false,
49
+ renaming = false,
50
+ waitingFor,
51
+ expandable = false,
52
+ isExpanded = false,
53
+ onToggleExpand,
54
+ selectable = false,
55
+ selected = false,
56
+ onToggleSelect,
57
+ touch = false,
58
+ }: StatusSlotProps) {
59
+ if (selectable) {
60
+ return (
61
+ <span className="flex shrink-0 items-center">
62
+ <SelectionCheckbox
63
+ checked={selected}
64
+ label={`Select ${title}`}
65
+ onChange={() => onToggleSelect?.()}
66
+ />
67
+ <span className="w-2 shrink-0" />
68
+ </span>
69
+ );
70
+ }
71
+
72
+ const size = touch ? 14 : 13;
73
+ const waiting = Boolean(waitingFor);
74
+ const liveRun = awaitingInput || status === 'stream' || waiting;
75
+ const chevronPinned = Boolean(expandable && onToggleExpand) && !liveRun && !renaming;
76
+ // `waiting` belongs in this list on its own: a held prompt is a pending
77
+ // `new-…` chat, which has no transcript and therefore no `status` — without it
78
+ // the one cue saying the row exists at all was never drawn.
79
+ const showStatus = Boolean(renaming || awaitingInput || waiting || status) && !chevronPinned;
80
+
81
+ return (
82
+ <>
83
+ <span className={`relative shrink-0 ${touch ? 'w-[18px] h-5' : 'w-4 h-4'}`}>
84
+ {expandable && onToggleExpand && (
85
+ <button
86
+ type="button"
87
+ onClick={(event) => {
88
+ event.stopPropagation();
89
+ onToggleExpand(event);
90
+ }}
91
+ title={isExpanded ? 'Collapse subagents' : 'Expand subagents'}
92
+ aria-expanded={isExpanded}
93
+ aria-label={isExpanded ? 'Collapse subagents' : 'Expand subagents'}
94
+ className={`peer absolute inset-0 flex items-center justify-center rounded cursor-pointer transition-opacity ${
95
+ chevronPinned
96
+ ? 'text-ink/55 hover:text-ink'
97
+ : 'text-ink/40 opacity-0 hover:text-ink group-hover/item:opacity-100 focus-visible:opacity-100'
98
+ }`}
99
+ >
100
+ {isExpanded ? <ChevronDown size={size} /> : <ChevronRight size={size} />}
101
+ </button>
102
+ )}
103
+
104
+ {showStatus && (
105
+ <span
106
+ className={`pointer-events-none absolute inset-0 flex items-center justify-center text-ink/60 transition-opacity ${
107
+ expandable ? 'group-hover/item:opacity-0 peer-focus-visible:opacity-0' : ''
108
+ }`}
109
+ >
110
+ {renaming ? (
111
+ <span role="status" aria-label="Generating a name…">
112
+ <Loader2 size={size - 1} className="animate-spin" />
113
+ </span>
114
+ ) : awaitingInput ? (
115
+ <CircleQuestionMark size={size - 1} className="animate-pulse text-warning" />
116
+ ) : waiting ? (
117
+ <span role="status" aria-label={`Waiting for ${waitingFor?.title ?? 'another session'}`}>
118
+ <Hourglass size={size - 1} className="animate-pulse" />
119
+ </span>
120
+ ) : status === 'stream' ? (
121
+ <span role="status" aria-label="Running">
122
+ <Loader2 size={size - 1} className="animate-spin" />
123
+ </span>
124
+ ) : (
125
+ <Check size={size - 1} />
126
+ )}
127
+ </span>
128
+ )}
129
+ </span>
130
+ <span className="w-2 shrink-0" />
131
+ </>
132
+ );
133
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The trailing column of a `modern` session row: the age at rest, the actions
8
+ * trigger on hover.
9
+ *
10
+ * The two share ONE box because they answer the same question — "which of these
11
+ * identically-titled chats is this?" — and the row cannot afford both at the
12
+ * width a sidebar actually has (264px at its floor leaves ~176px for the
13
+ * title). The trigger is always in the DOM and always hit-testable: only its
14
+ * OPACITY moves, so a keyboard user reaches it with Tab, a browser spec clicks
15
+ * it by role and name, and nothing becomes unreachable when the pointer is
16
+ * elsewhere. On a touch row there is no hover to reveal anything, so both are
17
+ * drawn side by side.
18
+ *
19
+ * The trigger's BOX is 22px on desktop and 28px on touch — the same boxes the
20
+ * workspace header's action cluster uses, so the two `⋯` columns share one
21
+ * centre. A box that merely fit the glyph (14px + a 4px pad) put the row's dots
22
+ * 2px left of the header's on touch.
23
+ */
24
+
25
+ import type { TargetedMouseEvent } from 'preact';
26
+ import { MoreHorizontal } from 'lucide-preact';
27
+
28
+ export interface TrailingSlotProps {
29
+ timeAgo?: string | null;
30
+ /** Null when the row has nothing to offer a menu. */
31
+ onOpenMenu?: (event: TargetedMouseEvent<HTMLElement>) => void;
32
+ menuOpen?: boolean;
33
+ touch?: boolean;
34
+ }
35
+
36
+ export function TrailingSlot({ timeAgo, onOpenMenu, menuOpen = false, touch = false }: TrailingSlotProps) {
37
+ if (!onOpenMenu) {
38
+ return timeAgo
39
+ ? <span className="ml-2 shrink-0 font-mono text-[10px] text-ink/40">{timeAgo}</span>
40
+ : null;
41
+ }
42
+
43
+ const trigger = (
44
+ <button
45
+ type="button"
46
+ onClick={onOpenMenu}
47
+ title="Session actions"
48
+ aria-label="Session actions"
49
+ aria-haspopup="menu"
50
+ aria-expanded={menuOpen}
51
+ className={`shrink-0 rounded text-ink/40 hover:bg-ink/10 hover:text-ink cursor-pointer ${
52
+ touch ? 'p-1.5' : 'p-1'
53
+ } ${
54
+ touch ? '' : 'opacity-0 transition-opacity group-hover/item:opacity-100 group-focus-within/item:opacity-100 focus-visible:opacity-100'
55
+ }`}
56
+ >
57
+ <MoreHorizontal size={touch ? 16 : 14} />
58
+ </button>
59
+ );
60
+
61
+ if (touch) {
62
+ return (
63
+ <span className="ml-1 flex shrink-0 items-center gap-0.5">
64
+ {timeAgo && <span className="font-mono text-[10px] text-ink/40">{timeAgo}</span>}
65
+ {trigger}
66
+ </span>
67
+ );
68
+ }
69
+
70
+ return (
71
+ <span className="relative ml-2 flex h-4 w-8 shrink-0 items-center justify-end">
72
+ {timeAgo && (
73
+ <span className="absolute right-1 font-mono text-[10px] leading-none text-ink/40 transition-opacity group-hover/item:opacity-0 group-focus-within/item:opacity-0">
74
+ {timeAgo}
75
+ </span>
76
+ )}
77
+ {/* `-my-1`: the glyph's 22px hit area is larger than the row's trailing
78
+ box, and negative margin keeps that height out of the row's own — the
79
+ row is 30px by construction, not 30px plus whatever the trigger needs
80
+ for a comfortable tap. */}
81
+ <span className="absolute right-0 -my-1 flex">{trigger}</span>
82
+ </span>
83
+ );
84
+ }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * One session row for the `modern` sidebar style, at both densities.
8
+ *
9
+ * ONE component for the desktop list and the phone drawer, because the row is
10
+ * the same decision in both places: which chat is this, is it running, does it
11
+ * have a roster, and what can I do to it. The densities differ in touch target
12
+ * and in how the trailing column reveals itself — `touch` has no hover, so the
13
+ * age and the actions trigger are drawn side by side — and in nothing else.
14
+ *
15
+ * Three facts are shared with the shipped rows rather than re-derived, because
16
+ * each one has a bug behind it:
17
+ *
18
+ * - the rename state comes from `useSessionRenaming`, so a rename started in
19
+ * either style (or on the phone) is visible here immediately;
20
+ * - the action menu is `SessionActionsMenu` + `useRowMenu`, so a new action
21
+ * appears in every row everywhere;
22
+ * - `data-testid="session-item"` and the row's accessible names are unchanged,
23
+ * so the browser specs address the same thing in both styles.
24
+ *
25
+ * ## The gutter is shared with the workspace header, numerically
26
+ *
27
+ * 4px of inset, the leading slot (16px; 18px on touch), then 8px before the
28
+ * text; and on the trailing side a 22px (28px on touch) box ending 4px inside
29
+ * the row's own edge — the same numbers `WorkspaceHeader` uses, so the status
30
+ * glyph sits under the folder mark, the title under the folder name, and the two
31
+ * `⋯` triggers share one column. `pl-1 pr-1`, not the `px-2` this row started
32
+ * with: the header's own `px-1` is inside a container that starts at the list's
33
+ * edge, and matching the row's padding to the header's is what makes the columns
34
+ * line up.
35
+ */
36
+
37
+ import type { TargetedMouseEvent } from 'preact';
38
+ import { useInlineRename } from '@/client/hooks/ui/inline-rename';
39
+ import { useSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
40
+ import { SessionActionsMenu, useRowMenu } from '@/client/components/common/session-actions-menu';
41
+ import { StatusSlot } from '@/client/components/common/session-row/StatusSlot';
42
+ import { TrailingSlot } from '@/client/components/common/session-row/TrailingSlot';
43
+ import { WorktreeBadge } from '@/client/components/layout/session-sidebar/WorktreeBadge';
44
+ import type { SessionWorktreeInfo } from '@/shared/lib/workspace/worktree/types';
45
+
46
+ export type SessionRowDensity = 'compact' | 'touch';
47
+
48
+ export interface SessionRowProps {
49
+ sessionId: string | number;
50
+ title: string;
51
+ isActive?: boolean;
52
+ isArchived?: boolean;
53
+ status?: 'stream' | 'finish' | 'abort';
54
+ awaitingInput?: boolean;
55
+ timeAgo?: string | null;
56
+ worktree?: SessionWorktreeInfo;
57
+ /** The row's prompt is held until another session finishes. */
58
+ waitingFor?: { title: string | null };
59
+ hasSubagents?: boolean;
60
+ isExpanded?: boolean;
61
+ onToggleExpand?: (event: TargetedMouseEvent<HTMLElement>) => void;
62
+ onClick?: () => void;
63
+ onRename?: (name: string) => void;
64
+ onRenameWithAi?: () => void;
65
+ onArchive?: () => void;
66
+ /** Omitted for a chat that cannot be deleted yet (a pending `new-…` row). */
67
+ onDelete?: () => void;
68
+ onCancelWait?: () => void;
69
+ selectable?: boolean;
70
+ selected?: boolean;
71
+ onToggleSelect?: () => void;
72
+ density?: SessionRowDensity;
73
+ }
74
+
75
+ export function SessionRow({
76
+ sessionId,
77
+ title,
78
+ isActive = false,
79
+ isArchived = false,
80
+ status,
81
+ awaitingInput = false,
82
+ timeAgo,
83
+ worktree,
84
+ waitingFor,
85
+ hasSubagents = false,
86
+ isExpanded = false,
87
+ onToggleExpand,
88
+ onClick,
89
+ onRename,
90
+ onRenameWithAi,
91
+ onArchive,
92
+ onDelete,
93
+ onCancelWait,
94
+ selectable = false,
95
+ selected = false,
96
+ onToggleSelect,
97
+ density = 'compact',
98
+ }: SessionRowProps) {
99
+ const touch = density === 'touch';
100
+ const renaming = useSessionRenaming(sessionId);
101
+ const menu = useRowMenu();
102
+ const {
103
+ isEditing,
104
+ draft,
105
+ setDraft,
106
+ inputRef,
107
+ startRename,
108
+ handleKeyDown,
109
+ handleBlur,
110
+ } = useInlineRename(title, onRename);
111
+ const hasActions = Boolean(onRename || onArchive || onDelete || onCancelWait);
112
+ const waiting = Boolean(waitingFor);
113
+ const displayTitle = title.charAt(0).toUpperCase() + title.slice(1);
114
+
115
+ if (isEditing) {
116
+ return (
117
+ <div className={`flex w-full items-center rounded-lg bg-ink/10 ${touch ? 'px-2 py-1.5' : 'px-2 py-1'}`}>
118
+ <input
119
+ ref={inputRef}
120
+ autoFocus
121
+ value={draft}
122
+ onChange={(event) => setDraft(event.currentTarget.value)}
123
+ onClick={(event) => event.stopPropagation()}
124
+ onKeyDown={handleKeyDown}
125
+ onBlur={handleBlur}
126
+ aria-label="Session name"
127
+ className="min-w-0 flex-1 rounded border border-ink/25 bg-paper px-2 py-0.5 text-xs text-ink outline-none focus:border-ink/50"
128
+ />
129
+ </div>
130
+ );
131
+ }
132
+
133
+ return (
134
+ <>
135
+ <div
136
+ data-testid="session-item"
137
+ data-session-id={String(sessionId)}
138
+ data-selected={selectable && selected ? 'true' : undefined}
139
+ onClick={selectable ? onToggleSelect : onClick}
140
+ onContextMenu={hasActions && !selectable ? menu.openAtCursor : undefined}
141
+ className={`group/item relative flex w-full items-center rounded-lg text-xs transition-colors select-none cursor-pointer ${
142
+ touch ? 'py-2.5 pl-1 pr-1' : 'py-[7px] pl-1 pr-1'
143
+ } ${
144
+ selectable && selected
145
+ ? 'bg-ink/10 text-ink ring-1 ring-inset ring-ink/20'
146
+ : isActive
147
+ ? 'bg-ink/[0.08] font-medium text-ink'
148
+ : 'text-ink/75 hover:bg-ink/[0.04] hover:text-ink'
149
+ }`}
150
+ >
151
+ {/* The active marker is a POSITION cue, not a tint: a 2px bar survives a
152
+ palette where `bg-ink/10` is nearly invisible, and it survives being
153
+ read by someone who cannot separate two low-contrast greys. */}
154
+ {isActive && !selectable && (
155
+ <span aria-hidden="true" className="absolute left-0 top-1.5 bottom-1.5 w-[2px] rounded-full bg-ink" />
156
+ )}
157
+
158
+ <StatusSlot
159
+ title={title}
160
+ status={status}
161
+ awaitingInput={awaitingInput}
162
+ renaming={renaming}
163
+ waitingFor={waitingFor}
164
+ expandable={hasSubagents}
165
+ isExpanded={isExpanded}
166
+ onToggleExpand={onToggleExpand}
167
+ selectable={selectable}
168
+ selected={selected}
169
+ onToggleSelect={onToggleSelect}
170
+ touch={touch}
171
+ />
172
+
173
+ <span className={`flex min-w-0 flex-1 flex-col leading-snug ${isArchived ? 'text-ink/45' : ''}`}>
174
+ <span className="truncate">{displayTitle}</span>
175
+ {waiting && (
176
+ <span className="truncate text-[10px] font-normal text-ink/40">
177
+ waiting for {waitingFor?.title ?? 'another session'}
178
+ </span>
179
+ )}
180
+ {worktree && <WorktreeBadge worktree={worktree} />}
181
+ </span>
182
+
183
+ <TrailingSlot
184
+ timeAgo={timeAgo}
185
+ touch={touch}
186
+ menuOpen={menu.anchor !== null}
187
+ onOpenMenu={hasActions && !selectable ? menu.openBelow : undefined}
188
+ />
189
+ </div>
190
+
191
+ {menu.anchor && (
192
+ <SessionActionsMenu
193
+ anchor={menu.anchor}
194
+ isArchived={isArchived}
195
+ onRename={onRename ? startRename : undefined}
196
+ onRenameWithAi={onRenameWithAi}
197
+ onArchive={onArchive}
198
+ onDelete={onDelete}
199
+ onCancelWait={onCancelWait}
200
+ onClose={menu.close}
201
+ />
202
+ )}
203
+ </>
204
+ );
205
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `modern` row: the same facts, the same names, the same contract.
8
+ *
9
+ * The style setting only swaps CHROME, so a row that loses an accessible name,
10
+ * a testid or a status label when it moves from `SessionItem` to `SessionRow`
11
+ * would break every browser spec and every screen-reader query without breaking
12
+ * the build. These assertions are the seam that keeps the two rows
13
+ * interchangeable, and each one names something a spec or a user relies on:
14
+ *
15
+ * - `data-testid="session-item"` scopes a list query;
16
+ * - `aria-label="Session actions"` is how a row's menu is found by role;
17
+ * - the run/blocked/held cues keep their `role="status"` labels;
18
+ * - the trailing slot keeps the age readable at rest and the trigger reachable
19
+ * by keyboard (opacity only — never `display: none`).
20
+ *
21
+ * Rendered with `h()` (no JSX) against happy-dom, following
22
+ * `session-sidebar/SessionItem.test.ts`.
23
+ */
24
+
25
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
26
+ import { Window } from 'happy-dom';
27
+ import { h, render } from 'preact';
28
+ import { act } from 'preact/test-utils';
29
+
30
+ import { SessionRow } from '@/client/components/common/session-row';
31
+ import type { SessionRowProps } from '@/client/components/common/session-row';
32
+ import { setSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
33
+
34
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent'] as const;
35
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
36
+
37
+ let container: HTMLElement;
38
+
39
+ beforeAll(() => {
40
+ const win = new Window({ url: 'http://localhost' });
41
+ const target = globalThis as unknown as Record<string, unknown>;
42
+ for (const key of DOM_GLOBALS) {
43
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
44
+ target[key] = (win as unknown as Record<string, unknown>)[key];
45
+ }
46
+ });
47
+
48
+ afterAll(() => {
49
+ const target = globalThis as unknown as Record<string, unknown>;
50
+ for (const key of DOM_GLOBALS) {
51
+ if (nativeGlobals[key] === undefined) delete target[key];
52
+ else target[key] = nativeGlobals[key];
53
+ }
54
+ });
55
+
56
+ afterEach(() => {
57
+ if (container) render(null, container);
58
+ container?.remove();
59
+ setSessionRenaming('s1', false);
60
+ });
61
+
62
+ async function mount(overrides: Partial<SessionRowProps> = {}) {
63
+ container = document.createElement('div');
64
+ document.body.appendChild(container);
65
+ await act(async () => {
66
+ render(h(SessionRow, { sessionId: 's1', title: 'hello world', ...overrides }), container);
67
+ });
68
+ return container;
69
+ }
70
+
71
+ describe('modern session row', () => {
72
+ test('keeps the testid and the session id every list query scopes on', async () => {
73
+ const el = await mount();
74
+ const row = el.querySelector('[data-testid="session-item"]');
75
+ expect(row).not.toBeNull();
76
+ expect(row?.getAttribute('data-session-id')).toBe('s1');
77
+ });
78
+
79
+ test('capitalises the title the way both shipped rows do', async () => {
80
+ const el = await mount({ title: 'hello world' });
81
+ expect(el.textContent).toContain('Hello world');
82
+ });
83
+
84
+ test('a live run keeps a labelled status cue', async () => {
85
+ const el = await mount({ status: 'stream' });
86
+ expect(el.querySelector('[role="status"]')?.getAttribute('aria-label')).toBe('Running');
87
+ });
88
+
89
+ test('an agent blocked on a question is announced before any run cue', async () => {
90
+ const el = await mount({ status: 'stream', awaitingInput: true });
91
+ // The blocked cue is a pulse, not a spinner, and it carries no status role —
92
+ // the desktop row has always drawn it that way; what must not change is that
93
+ // it REPLACES the spinner rather than sitting beside it.
94
+ expect(el.querySelector('[role="status"]')).toBeNull();
95
+ expect(el.querySelector('.animate-pulse')).not.toBeNull();
96
+ });
97
+
98
+ test('a held prompt says what it is waiting for', async () => {
99
+ const el = await mount({ waitingFor: { title: 'other chat' } });
100
+ expect(el.textContent).toContain('waiting for other chat');
101
+ expect(el.querySelector('[role="status"]')?.getAttribute('aria-label')).toBe('Waiting for other chat');
102
+ });
103
+
104
+ test('an in-flight rename answers the click that is still pending', async () => {
105
+ setSessionRenaming('s1', true);
106
+ const el = await mount();
107
+ expect(el.querySelector('[role="status"]')?.getAttribute('aria-label')).toBe('Generating a name…');
108
+ });
109
+
110
+ test('the actions trigger is drawn and named, and is not hidden from the keyboard', async () => {
111
+ const el = await mount({ onRename: () => {} });
112
+ const trigger = el.querySelector('[aria-label="Session actions"]');
113
+ expect(trigger).not.toBeNull();
114
+ // Hidden by opacity, never by `hidden`/`display`, so Tab still reaches it.
115
+ expect(trigger?.hasAttribute('hidden')).toBe(false);
116
+ expect(trigger?.getAttribute('style') ?? '').not.toContain('display: none');
117
+ });
118
+
119
+ test('the trailing slot keeps the age at rest', async () => {
120
+ const el = await mount({ timeAgo: '2m', onRename: () => {} });
121
+ expect(el.textContent).toContain('2m');
122
+ });
123
+
124
+ test('batch mode swaps the status slot for the checkbox', async () => {
125
+ const el = await mount({ selectable: true, selected: true, status: 'stream' });
126
+ expect(el.querySelector('input[type="checkbox"]')).not.toBeNull();
127
+ // The run cue and the checkbox are never both drawn: in this mode the row
128
+ // is a choice, not a status report.
129
+ expect(el.querySelector('[role="status"]')).toBeNull();
130
+ expect(el.querySelector('[data-testid="session-item"]')?.getAttribute('data-selected')).toBe('true');
131
+ });
132
+
133
+ test('the touch density draws the trigger without a hover reveal', async () => {
134
+ const el = await mount({ density: 'touch', onRename: () => {}, timeAgo: '5m' });
135
+ const trigger = el.querySelector('[aria-label="Session actions"]');
136
+ expect(trigger?.className ?? '').not.toContain('opacity-0');
137
+ expect(el.textContent).toContain('5m');
138
+ });
139
+
140
+ test('a row with nothing to offer draws no menu trigger', async () => {
141
+ const el = await mount();
142
+ expect(el.querySelector('[aria-label="Session actions"]')).toBeNull();
143
+ });
144
+ });