@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
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `modern` sidebar's filter row: what the list is showing, plus the way into
8
+ * batch selection.
9
+ *
10
+ * Two chips and one mode, and they are two different kinds of thing:
11
+ *
12
+ * - **All / Running** are one choice — the focus. Selecting one deselects the
13
+ * other, so they are drawn as a segmented pair and report `aria-pressed`.
14
+ * - **Archived** is a separate axis: it changes which rows are OFFERED, and it
15
+ * can be on at the same time as either focus. It carries a colour
16
+ * (`--theme-warning`) because an archived list is not the list the user
17
+ * expects, and that fact should not be readable only from a label.
18
+ * - **Select** enters batch mode. It has TWO forms, chosen by measured width
19
+ * (`filterSelectForm`): a trailing glyph while the row is narrow, and a chip
20
+ * once four chips fit. Either way it is the LAST item and it alone sits at the
21
+ * row's trailing edge (`ml-auto`) — the three filter chips never move.
22
+ *
23
+ * **Only Select is right-aligned, never the chip group.** The group is a reading
24
+ * order — All, Running, Archived — and it starts at the same left edge as the
25
+ * search field and the rows below it. Pushing the group to the right edge when
26
+ * the fourth chip appears (which is what this row did first) made the filters
27
+ * jump sideways as the panel was dragged, and left them under the title column
28
+ * instead of over it.
29
+ *
30
+ * **This row never wraps.** It is a control strip, and a second line of chips
31
+ * pushes the list down and reads as a layout break: the four-chip version
32
+ * measured 265px against 256px of content at the 280px default, which is what
33
+ * `Select` falling onto a line of its own looked like.
34
+ */
35
+
36
+ import { Archive, ListChecks, X } from 'lucide-preact';
37
+ import { useToolbarRowWidth } from '@/client/hooks/workspace/toolbar-row-width';
38
+ import { filterSelectForm } from '@/shared/lib/workspace/sidebar-filter-row';
39
+ import type { SessionFocus } from '@/shared/lib/workspace/session-focus';
40
+
41
+ interface FilterChipsProps {
42
+ focus: SessionFocus;
43
+ onFocusChange: (focus: SessionFocus) => void;
44
+ /** Rows the focus would keep, for the Running chip's badge. */
45
+ runningCount: number;
46
+ showArchived: boolean;
47
+ onToggleArchived: () => void;
48
+ /** True while a batch selection is active — the control reads pressed. */
49
+ selecting: boolean;
50
+ /** Enter or leave workspace batch-selection mode. */
51
+ onToggleSelect: () => void;
52
+ }
53
+
54
+ const CHIP_BASE = 'inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium transition-colors cursor-pointer';
55
+ const CHIP_ON = 'border-ink bg-ink text-paper';
56
+ const CHIP_OFF = 'border-ink/15 text-ink/60 hover:border-ink/30 hover:text-ink';
57
+ const SELECT_LABEL = (selecting: boolean) => (selecting ? 'Cancel' : 'Select');
58
+
59
+ export function FilterChips({
60
+ focus,
61
+ onFocusChange,
62
+ runningCount,
63
+ showArchived,
64
+ onToggleArchived,
65
+ selecting,
66
+ onToggleSelect,
67
+ }: FilterChipsProps) {
68
+ // Measured, not guessed: the sidebar is dragged, so the form has to follow the
69
+ // panel's real content width (see `filterSelectForm`). The row carries no
70
+ // padding of its own — its `px-3` lives on the wrapper — hence `0`.
71
+ const { ref, width } = useToolbarRowWidth(0);
72
+ const form = filterSelectForm(width, runningCount);
73
+ const selectGlyph = selecting ? <X size={10} /> : <ListChecks size={10} />;
74
+
75
+ return (
76
+ <div className="px-3 pb-2">
77
+ <div ref={ref} className="flex flex-nowrap items-center gap-1">
78
+ <div className="flex shrink-0 items-center gap-1" role="group" aria-label="Session filters">
79
+ <button
80
+ type="button"
81
+ onClick={() => onFocusChange('all')}
82
+ aria-pressed={focus === 'all'}
83
+ className={`${CHIP_BASE} ${focus === 'all' ? CHIP_ON : CHIP_OFF}`}
84
+ >
85
+ All
86
+ </button>
87
+ <button
88
+ type="button"
89
+ onClick={() => onFocusChange('running')}
90
+ aria-pressed={focus === 'running'}
91
+ title={runningCount > 0 ? `${runningCount} running or waiting` : 'Nothing running'}
92
+ className={`${CHIP_BASE} ${focus === 'running' ? CHIP_ON : CHIP_OFF}`}
93
+ >
94
+ {/* A dot, not a spinner: the chip reports a COUNT of rows, and a
95
+ spinner here would claim the chip itself is loading. */}
96
+ <span
97
+ aria-hidden="true"
98
+ className={`h-1.5 w-1.5 rounded-full ${runningCount > 0 ? 'bg-current' : 'bg-current opacity-30'}`}
99
+ />
100
+ Running
101
+ {runningCount > 0 && <span className="font-mono tabular-nums opacity-70">{runningCount}</span>}
102
+ </button>
103
+ <button
104
+ type="button"
105
+ onClick={onToggleArchived}
106
+ aria-pressed={showArchived}
107
+ title={showArchived ? 'Hide archived sessions' : 'Show archived sessions'}
108
+ className={`${CHIP_BASE} ${
109
+ showArchived ? 'border-warning/40 bg-warning/10 text-warning hover:bg-warning/15' : CHIP_OFF
110
+ }`}
111
+ >
112
+ <Archive size={10} />
113
+ Archived
114
+ </button>
115
+ </div>
116
+
117
+ {/* Select is a SIBLING of the filter group, never a member of it. Inside
118
+ the group `ml-auto` has no free space to claim — the group is
119
+ `shrink-0` and only as wide as its chips — so the fourth chip landed
120
+ immediately after `Archived` instead of at the row's trailing edge.
121
+ Out here it is the row's own spare space that pushes it right. */}
122
+ {form === 'chip' ? (
123
+ <button
124
+ type="button"
125
+ onClick={onToggleSelect}
126
+ aria-pressed={selecting}
127
+ title={selecting ? 'Cancel selection' : 'Select workspaces'}
128
+ className={`${CHIP_BASE} ml-auto ${selecting ? CHIP_ON : CHIP_OFF}`}
129
+ >
130
+ {selectGlyph}
131
+ {SELECT_LABEL(selecting)}
132
+ </button>
133
+ ) : (
134
+ <button
135
+ type="button"
136
+ onClick={onToggleSelect}
137
+ title={selecting ? 'Cancel selection' : 'Select workspaces'}
138
+ aria-label={selecting ? 'Cancel selection' : 'Select workspaces'}
139
+ aria-pressed={selecting}
140
+ className={`ml-auto inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors cursor-pointer ${
141
+ selecting ? 'bg-ink/10 text-ink' : 'text-ink/55 hover:bg-ink/[0.06] hover:text-ink'
142
+ }`}
143
+ >
144
+ {selecting ? <X size={14} /> : <ListChecks size={14} />}
145
+ </button>
146
+ )}
147
+ </div>
148
+ </div>
149
+ );
150
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `modern` sidebar's search line.
8
+ *
9
+ * A FIELD, not a mode: the classic toolbar spends a 28px button on toggling a
10
+ * search box that then pushes the list down, which costs a click before the
11
+ * user can type and moves every row when it opens. Here the field is always
12
+ * there, at the top, and the list never shifts — so search is something you do,
13
+ * not something you enter.
14
+ *
15
+ * The icon, the input and the clear control are FLEX SIBLINGS inside the field
16
+ * box rather than three absolutely-positioned layers. The earlier version
17
+ * centred the glyph against the wrapper — which includes the field's own bottom
18
+ * margin — so the icon sat 4px below the placeholder's optical centre, and its
19
+ * `left`/`pl` pair had to be kept in sync by hand. As siblings they share one
20
+ * baseline and one vertical centre by construction.
21
+ *
22
+ * The clear control appears only while there is a query, and `aria-label` names
23
+ * it: an icon-only button with no name is unreachable to a screen reader and
24
+ * to `getByRole`, which is why every control in this app carries one.
25
+ */
26
+
27
+ import { Search, X } from 'lucide-preact';
28
+
29
+ interface SearchFieldProps {
30
+ value: string;
31
+ onChange: (value: string) => void;
32
+ /** Larger target and text for a touch row. */
33
+ touch?: boolean;
34
+ }
35
+
36
+ export function SearchField({ value, onChange, touch = false }: SearchFieldProps) {
37
+ return (
38
+ // `pt-2`/`pt-3` keeps the field off the column's own top edge: flush against
39
+ // it the rounded corner read as the panel's corner, not as a control.
40
+ <div className={touch ? 'px-3 pt-3 pb-2' : 'px-3 pt-2 pb-2'}>
41
+ <div
42
+ className={`flex items-center gap-1.5 rounded-lg border border-ink/10 bg-ink/[0.04] px-2 transition-colors focus-within:border-ink/30 focus-within:bg-paper ${
43
+ touch ? 'h-9' : 'h-7'
44
+ }`}
45
+ >
46
+ <Search
47
+ size={touch ? 15 : 13}
48
+ aria-hidden="true"
49
+ className="shrink-0 text-ink/35"
50
+ />
51
+ <input
52
+ type="search"
53
+ value={value}
54
+ onChange={(event) => onChange(event.currentTarget.value)}
55
+ placeholder="Search workspaces & sessions"
56
+ aria-label="Search workspaces and sessions"
57
+ className={`min-w-0 flex-1 bg-transparent text-ink outline-none placeholder:text-ink/40 ${
58
+ touch ? 'text-[13px]' : 'text-xs'
59
+ }`}
60
+ />
61
+ {value.length > 0 && (
62
+ <button
63
+ type="button"
64
+ onClick={() => onChange('')}
65
+ title="Clear search"
66
+ aria-label="Clear search"
67
+ className="-mr-0.5 shrink-0 rounded p-0.5 text-ink/40 transition-colors cursor-pointer hover:bg-ink/10 hover:text-ink"
68
+ >
69
+ <X size={touch ? 14 : 12} />
70
+ </button>
71
+ )}
72
+ </div>
73
+ </div>
74
+ );
75
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The `modern` sidebar's placeholder for the list area while the first fetch is
8
+ * in flight.
9
+ *
10
+ * It draws ONLY the list: the search line, the chips and the action row above
11
+ * it are real controls that render during initialization too, and a skeleton
12
+ * that drew its own copies of them put two search fields on screen for a beat
13
+ * and then moved the real one. The earlier version also carried its own
14
+ * `px-2 pb-3` while the view already padded the same box — 8px of double inset,
15
+ * visible as the placeholder sitting narrower than the rows it stood in for.
16
+ *
17
+ * The geometry is the live geometry, measured rather than approximated: the
18
+ * workspace header is 26px (32 on touch) with its mark in the same 4px + 16px
19
+ * (18px) gutter the real header uses, and the rows are 31px (44 on touch) —
20
+ * the live row's own measured height, not `padding + bar`. A placeholder whose
21
+ * heights differ from the content is a layout shift with extra steps.
22
+ */
23
+
24
+ const PLACEHOLDER_FOLDERS = [3, 2];
25
+
26
+ export function ModernSidebarSkeleton({ touch = false }: { touch?: boolean }) {
27
+ return (
28
+ <div className="space-y-3" aria-hidden="true">
29
+ {PLACEHOLDER_FOLDERS.map((rows, folderIndex) => (
30
+ <div key={folderIndex} className="space-y-0.5">
31
+ <div className={`flex items-center gap-2 px-1 ${touch ? 'h-8' : 'h-[26px]'}`}>
32
+ <span className={`animate-pulse rounded-sm bg-ink/10 ${touch ? 'h-[18px] w-[18px]' : 'h-4 w-4'}`} />
33
+ <span className="h-3 w-24 animate-pulse rounded bg-ink/10" />
34
+ </div>
35
+ {Array.from({ length: rows }, (_, rowIndex) => (
36
+ <div
37
+ key={rowIndex}
38
+ className={`flex items-center gap-2 pl-1 pr-2 ${touch ? 'h-11' : 'h-[31px]'}`}
39
+ >
40
+ <span
41
+ className={`shrink-0 animate-pulse rounded-full bg-ink/10 ${
42
+ touch ? 'h-[18px] w-[18px]' : 'h-4 w-4'
43
+ }`}
44
+ />
45
+ <span
46
+ className="h-3 animate-pulse rounded bg-ink/10"
47
+ style={{ width: `${58 - (rowIndex % 3) * 12}%` }}
48
+ />
49
+ </div>
50
+ ))}
51
+ </div>
52
+ ))}
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A workspace's header in the `modern` sidebar: the mark, the name, how many
8
+ * chats it holds, and its two actions.
9
+ *
10
+ * Differences from the classic header are presentation only, and each one is
11
+ * there for a reason:
12
+ *
13
+ * - **It sticks.** Scrolling a long workspace used to leave the rows with no
14
+ * visible owner; the name is the only thing that says which project these
15
+ * chats belong to.
16
+ * - **It states a count.** "3" answers "does this workspace have anything in
17
+ * it?" without expanding it, which is the question a collapsed row raises.
18
+ * - **The mark keeps the accent.** A folder's colour is a fact the user chose;
19
+ * the classic header only shows it until hover, when the chevron replaces it.
20
+ * Here the accent is a dot beside the name, so it survives both states.
21
+ *
22
+ * ## The gutter is shared with the rows, numerically
23
+ *
24
+ * The icon column, the title column and the TRAILING column are the same columns
25
+ * as a session row's (`common/session-row`): 4px of inset, a 16px slot (18px on
26
+ * touch), then 8px before the text; and on the right, a 22px (28px on touch)
27
+ * action box ending 4px inside the list's content edge. Measured before this
28
+ * rule existed, the folder mark's centre sat at x=20 while the row's status glyph
29
+ * sat at 24, the folder name at 34 while the session title started at 40, and the
30
+ * two `⋯` triggers were 9px apart (8px vs 16px from the panel edge) — three steps
31
+ * that made the list look like two lists. A header that "looked about right" is
32
+ * what produced them: the pair has to be stated, so it is stated here and in
33
+ * `session-row`.
34
+ *
35
+ * The actions are the same components the classic header uses — `+` opens a
36
+ * chat in THIS folder and `⋯` is `WorkspaceOptionsMenu` — so pin, delete,
37
+ * reveal, worktree and session-selection exist in both styles by construction.
38
+ */
39
+
40
+ import type { ReactNode } from 'preact/compat';
41
+ import { ChevronDown, ChevronRight, MoreHorizontal, Pin, Plus } from 'lucide-preact';
42
+ import { SelectionCheckbox } from '@/client/components/common/batch-selection/SelectionCheckbox';
43
+ import type { CategoryHeaderCheckbox } from '@/client/components/layout/session-sidebar/CategoryHeader';
44
+ import { getProjectIcon } from '@/shared/lib/workspace/project-icon';
45
+ import type { WorkspaceFolderData } from '@/shared/types';
46
+
47
+ export interface WorkspaceHeaderProps {
48
+ folder: WorkspaceFolderData;
49
+ isOpen: boolean;
50
+ onToggleFolder: () => void;
51
+ /** Rows the folder offers under the current archive filter. */
52
+ sessionCount: number;
53
+ checkbox: CategoryHeaderCheckbox | null;
54
+ batchActive: boolean;
55
+ menuRef: { current: HTMLDivElement | null };
56
+ showMenu: boolean;
57
+ onToggleMenu: () => void;
58
+ onNewSession: () => void;
59
+ /** The menu body, drawn in this header's anchored container while open. */
60
+ menu?: ReactNode;
61
+ /** Taller row and larger tap targets for the phone drawer. */
62
+ touch?: boolean;
63
+ }
64
+
65
+ export function WorkspaceHeader({
66
+ folder,
67
+ isOpen,
68
+ onToggleFolder,
69
+ sessionCount,
70
+ checkbox,
71
+ batchActive,
72
+ menuRef,
73
+ showMenu,
74
+ onToggleMenu,
75
+ onNewSession,
76
+ menu,
77
+ touch = false,
78
+ }: WorkspaceHeaderProps) {
79
+ const ProjectIcon = getProjectIcon(folder.icon);
80
+ const accent = folder.accentColor || undefined;
81
+
82
+ return (
83
+ <div
84
+ className={`group/ws sticky top-0 z-10 -mx-1 flex items-center gap-1 rounded-md bg-paper px-1 text-xs font-semibold text-ink ${
85
+ touch ? 'h-8' : 'h-[26px]'
86
+ }`}
87
+ >
88
+ <button
89
+ type="button"
90
+ onClick={batchActive ? undefined : onToggleFolder}
91
+ aria-expanded={isOpen}
92
+ aria-label={`${folder.name}${isOpen ? ', collapse' : ', expand'}`}
93
+ className="flex h-full min-w-0 flex-1 items-center gap-2 rounded-md px-1 text-left cursor-pointer hover:bg-ink/[0.04]"
94
+ >
95
+ {checkbox ? (
96
+ <SelectionCheckbox
97
+ size="md"
98
+ checked={checkbox.checked}
99
+ indeterminate={checkbox.indeterminate}
100
+ label={checkbox.label}
101
+ onChange={checkbox.onChange}
102
+ />
103
+ ) : (
104
+ <span className={`relative flex shrink-0 items-center justify-center ${touch ? 'h-[18px] w-[18px]' : 'h-4 w-4'}`}>
105
+ {folder.customIconUrl ? (
106
+ <img
107
+ src={folder.customIconUrl}
108
+ alt=""
109
+ className="h-[15px] w-[15px] shrink-0 rounded-xs object-contain"
110
+ referrerPolicy="no-referrer"
111
+ />
112
+ ) : (
113
+ <ProjectIcon size={15} className="text-ink/70" style={{ color: accent }} />
114
+ )}
115
+ </span>
116
+ )}
117
+
118
+ <span className="truncate text-[13px] font-semibold tracking-tight">{folder.name}</span>
119
+ {folder.isPinned && <Pin size={10} className="shrink-0 text-ink/45" />}
120
+
121
+ {/* The accent as a dot: the icon column keeps the chevron's slot, so the
122
+ colour needs a place that is not hover-dependent. */}
123
+ {accent && !checkbox && (
124
+ <span aria-hidden="true" className="h-1.5 w-1.5 shrink-0 rounded-full" style={{ backgroundColor: accent }} />
125
+ )}
126
+
127
+ <span className="shrink-0 font-mono text-[10px] font-normal tabular-nums text-ink/35">{sessionCount}</span>
128
+
129
+ <span className="ml-auto shrink-0 text-ink/40">
130
+ {isOpen ? <ChevronDown size={touch ? 14 : 12} /> : <ChevronRight size={touch ? 14 : 12} />}
131
+ </span>
132
+ </button>
133
+
134
+ {/* `pr-1`: the action cluster ends where a session row's trailing control
135
+ ends (4px inside the list's content edge), so the two `⋯` columns are
136
+ one column — measured before this rule, the folder's sat 8px from the
137
+ panel edge and the row's 16px, a 9px step between glyph centres. */}
138
+ {!batchActive && (
139
+ <div className="flex shrink-0 items-center gap-0.5 pr-1">
140
+ <button
141
+ type="button"
142
+ title="New Session"
143
+ aria-label={`New session in ${folder.name}`}
144
+ onClick={(event) => {
145
+ event.stopPropagation();
146
+ onNewSession();
147
+ }}
148
+ className={`flex items-center justify-center rounded text-ink/40 transition-colors cursor-pointer hover:bg-ink/10 hover:text-ink ${
149
+ touch ? 'h-7 w-7' : 'h-[22px] w-[22px]'
150
+ }`}
151
+ >
152
+ <Plus size={touch ? 15 : 12} />
153
+ </button>
154
+
155
+ <div className="relative flex items-center" ref={menuRef}>
156
+ <button
157
+ type="button"
158
+ title={`Options for ${folder.name}`}
159
+ aria-label={`Options for ${folder.name}`}
160
+ aria-haspopup="menu"
161
+ aria-expanded={showMenu}
162
+ onClick={(event) => {
163
+ event.stopPropagation();
164
+ onToggleMenu();
165
+ }}
166
+ className={`flex items-center justify-center rounded text-ink/40 transition-colors cursor-pointer hover:bg-ink/10 hover:text-ink ${
167
+ touch ? 'h-7 w-7' : 'h-[22px] w-[22px]'
168
+ }`}
169
+ >
170
+ <MoreHorizontal size={touch ? 15 : 12} />
171
+ </button>
172
+ {/* The menu body is the caller's: it owns the state the menu acts
173
+ on (pin, delete confirmation, the worktree dialog). */}
174
+ {showMenu && menu && (
175
+ <div className="absolute right-0 top-full z-50 mt-1 w-44 rounded-md border border-ink/15 bg-paper py-1 text-xs shadow-lg">
176
+ {menu}
177
+ </div>
178
+ )}
179
+ </div>
180
+ </div>
181
+ )}
182
+ </div>
183
+ );
184
+ }