@kabmo-labs/kabmo 0.9.0 → 0.10.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 (180) hide show
  1. package/README.md +45 -0
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +333 -333
  4. package/dist/client/static/js/index-18xe7655.css +1 -0
  5. package/dist/client/static/js/{index-bpptfkz2.js → index-nxpe7835.js} +768 -763
  6. package/package.json +3 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
  8. package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
  9. package/src/client/components/common/code-surface/documents.test.ts +5 -3
  10. package/src/client/components/common/code-surface/documents.ts +85 -0
  11. package/src/client/components/common/code-surface/extensions.test.ts +5 -0
  12. package/src/client/components/common/code-surface/extensions.ts +140 -7
  13. package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
  14. package/src/client/components/common/code-surface/fold.test.ts +148 -0
  15. package/src/client/components/common/code-surface/fold.ts +118 -0
  16. package/src/client/components/common/code-surface/indent-guide.ts +104 -0
  17. package/src/client/components/common/code-surface/indent.test.ts +239 -0
  18. package/src/client/components/common/code-surface/indent.ts +124 -0
  19. package/src/client/components/common/code-surface/index.tsx +76 -46
  20. package/src/client/components/common/code-surface/keymap.ts +12 -23
  21. package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
  22. package/src/client/components/common/code-surface/line-commands.ts +103 -0
  23. package/src/client/components/common/code-surface/props.ts +87 -0
  24. package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
  25. package/src/client/components/common/code-surface/stream-language.ts +123 -0
  26. package/src/client/components/common/code-surface/theme.test.ts +40 -5
  27. package/src/client/components/common/code-surface/theme.ts +113 -0
  28. package/src/client/components/common/code-surface/typing.test.ts +97 -0
  29. package/src/client/components/common/code-surface/typing.ts +111 -0
  30. package/src/client/components/common/toolbar-row/index.test.tsx +53 -4
  31. package/src/client/components/common/toolbar-row/index.tsx +101 -30
  32. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +17 -0
  33. package/src/client/components/layout/desktop-layout/index.tsx +18 -0
  34. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +35 -33
  35. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
  36. package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
  37. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  38. package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
  39. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
  40. package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
  41. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
  42. package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
  43. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +17 -3
  44. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +10 -6
  45. package/src/client/components/workspace/editor/Body.tsx +24 -0
  46. package/src/client/components/workspace/editor/CommandPalette.tsx +4 -4
  47. package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
  48. package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
  49. package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
  50. package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
  51. package/src/client/components/workspace/editor/FileDocument.tsx +89 -1
  52. package/src/client/components/workspace/editor/FilePane.tsx +43 -0
  53. package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
  54. package/src/client/components/workspace/editor/FindWidget.tsx +29 -0
  55. package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
  56. package/src/client/components/workspace/editor/Notices.tsx +71 -0
  57. package/src/client/components/workspace/editor/Pane.tsx +118 -0
  58. package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
  59. package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
  60. package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
  61. package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
  62. package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
  63. package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
  64. package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
  65. package/src/client/components/workspace/editor/Tabs.tsx +195 -18
  66. package/src/client/components/workspace/editor/Toolbar.tsx +54 -181
  67. package/src/client/components/workspace/editor/index.tsx +199 -189
  68. package/src/client/components/workspace/editor/props.ts +64 -0
  69. package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
  70. package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
  71. package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
  72. package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
  73. package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
  74. package/src/client/components/workspace/file-explorer/index.tsx +10 -48
  75. package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
  76. package/src/client/components/workspace/search-panel/Body.tsx +6 -1
  77. package/src/client/hooks/chat/composer/file-drop.ts +22 -37
  78. package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
  79. package/src/client/hooks/chat/composer/pipeline.ts +12 -1
  80. package/src/client/hooks/editor/caret-position.test.ts +58 -0
  81. package/src/client/hooks/editor/caret-position.ts +48 -0
  82. package/src/client/hooks/editor/file-editor-types.ts +200 -0
  83. package/src/client/hooks/editor/find-history.test.ts +132 -0
  84. package/src/client/hooks/editor/find-history.ts +46 -0
  85. package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
  86. package/src/client/hooks/editor/find-selection-range.ts +49 -0
  87. package/src/client/hooks/editor/find-state.ts +13 -0
  88. package/src/client/hooks/editor/font.test.ts +0 -93
  89. package/src/client/hooks/editor/indent-settings.test.ts +104 -0
  90. package/src/client/hooks/editor/indent-settings.ts +88 -0
  91. package/src/client/hooks/editor/quick-open.test.ts +141 -0
  92. package/src/client/hooks/editor/quick-open.ts +127 -0
  93. package/src/client/hooks/editor/save-as.test.ts +156 -0
  94. package/src/client/hooks/editor/save-as.ts +122 -0
  95. package/src/client/hooks/editor/save-file.test.ts +179 -0
  96. package/src/client/hooks/editor/save-file.ts +73 -28
  97. package/src/client/hooks/editor/typing-settings.test.ts +73 -0
  98. package/src/client/hooks/editor/typing-settings.ts +65 -0
  99. package/src/client/hooks/editor/use-close-guard.ts +98 -0
  100. package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
  101. package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
  102. package/src/client/hooks/editor/use-editor-drop.ts +58 -68
  103. package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
  104. package/src/client/hooks/editor/use-editor-find.ts +38 -3
  105. package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
  106. package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
  107. package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
  108. package/src/client/hooks/editor/use-external-change.test.ts +88 -0
  109. package/src/client/hooks/editor/use-external-change.ts +146 -0
  110. package/src/client/hooks/editor/use-file-editor.ts +83 -116
  111. package/src/client/hooks/editor/use-file-read.ts +16 -8
  112. package/src/client/hooks/editor/use-file-writes.ts +28 -3
  113. package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
  114. package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
  115. package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
  116. package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
  117. package/src/client/hooks/editor/use-split-editor.ts +91 -0
  118. package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
  119. package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
  120. package/src/client/hooks/editor/use-write-conflict.ts +152 -0
  121. package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
  122. package/src/client/hooks/editor/wheel-zoom.ts +96 -0
  123. package/src/client/hooks/ui/drag-presence.test.ts +193 -0
  124. package/src/client/hooks/ui/drag-presence.ts +108 -0
  125. package/src/client/hooks/ui/settings-modal.test.ts +115 -0
  126. package/src/client/hooks/workspace/file-listing.ts +36 -24
  127. package/src/client/hooks/workspace/file-tabs.test.ts +90 -0
  128. package/src/client/hooks/workspace/file-tabs.ts +46 -0
  129. package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
  130. package/src/client/lib/desktop/dropped-paths.ts +83 -0
  131. package/src/client/lib/editor/tab-menu.test.ts +127 -0
  132. package/src/client/lib/editor/tab-menu.ts +127 -0
  133. package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
  134. package/src/client/lib/editor-dirty-tabs.ts +103 -0
  135. package/src/client/lib/native/resume.test.ts +66 -0
  136. package/src/client/lib/native/resume.ts +42 -0
  137. package/src/client/main.tsx +8 -0
  138. package/src/client/tailwind.css +38 -0
  139. package/src/server/lib/bundler/css.test.ts +31 -0
  140. package/src/server/lib/fs/listing.test.ts +81 -16
  141. package/src/server/lib/fs/listing.ts +72 -5
  142. package/src/server/lib/fs/write-conflict.test.ts +68 -0
  143. package/src/server/lib/fs/write-conflict.ts +84 -0
  144. package/src/server/routes/fs/action-save-as.test.ts +82 -0
  145. package/src/server/routes/fs/action.test.ts +82 -0
  146. package/src/server/routes/fs/action.ts +54 -1
  147. package/src/server/routes/fs/exists.ts +11 -1
  148. package/src/server/routes/fs/read.ts +6 -1
  149. package/src/shared/lib/code/editor/find-replace.test.ts +1 -1
  150. package/src/shared/lib/code/editor/find-scan.test.ts +1 -1
  151. package/src/shared/lib/code/editor/find-scan.ts +22 -1
  152. package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
  153. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
  154. package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
  155. package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
  156. package/src/shared/lib/code/editor/indent-rules.ts +198 -0
  157. package/src/shared/lib/code/editor/keymap.test.ts +23 -0
  158. package/src/shared/lib/code/editor/keymap.ts +40 -3
  159. package/src/shared/lib/code/editor/palette.test.ts +25 -2
  160. package/src/shared/lib/code/editor/palette.ts +10 -0
  161. package/src/shared/lib/code/editor/stream-modes.ts +225 -0
  162. package/src/shared/lib/code/syntax-highlight.test.ts +1 -1
  163. package/src/shared/lib/fs/file-tree.test.ts +41 -0
  164. package/src/shared/lib/fs/file-tree.ts +126 -34
  165. package/src/shared/lib/fs/folder-chain.test.ts +87 -0
  166. package/src/shared/lib/fs/folder-chain.ts +91 -0
  167. package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
  168. package/src/shared/lib/realtime/connection.test.ts +5 -1
  169. package/src/shared/lib/realtime/connection.ts +25 -119
  170. package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
  171. package/src/shared/lib/realtime/resume.ts +223 -0
  172. package/src/shared/lib/realtime/state.ts +22 -0
  173. package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
  174. package/src/shared/lib/realtime/watchdog.test.ts +99 -0
  175. package/src/shared/lib/realtime/watchdog.ts +72 -0
  176. package/src/shared/lib/workspace/split-editor.test.ts +104 -0
  177. package/src/shared/lib/workspace/split-editor.ts +129 -0
  178. package/src/test-support/file-explorer-disk.test-util.ts +30 -3
  179. package/src/test-support/pristine-globals.ts +7 -0
  180. package/dist/client/static/js/index-k315p1e8.css +0 -1
@@ -0,0 +1,300 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The editor toolbar's controls, as data plus the button markup each one draws.
8
+ *
9
+ * Split out of `Toolbar.tsx` for the repository's per-file ceiling, and it earns
10
+ * the boundary: the toolbar is a row of clusters with a hiding order, and every
11
+ * control is the same shape — a label, an icon, a pressed state, and the same
12
+ * `aria-*` pair. Keeping the cluster table beside the buttons is what stops the two
13
+ * from disagreeing about which control is pinned.
14
+ *
15
+ * ## Two rules the row exists to enforce
16
+ *
17
+ * **Every action is an icon-only `<button>` carrying both a `title` and an
18
+ * `aria-label`** — a bare `<svg onClick>` is unreachable by keyboard and invisible
19
+ * to a screen reader. **Pinning is not the visual order**: `pinned` marks what a
20
+ * narrow panel must not bury, and the row is placed in the order a reader looks.
21
+ *
22
+ * **Revert is deliberately never pinned.** It is the only destructive control in
23
+ * the row, and a `⋯` menu is exactly the friction a destructive action should have.
24
+ */
25
+
26
+ import type { ComponentChildren } from 'preact';
27
+ import {
28
+ Copy,
29
+ Download,
30
+ Eye,
31
+ EyeOff,
32
+ Maximize,
33
+ Minimize,
34
+ RotateCcw,
35
+ Save,
36
+ SaveAll,
37
+ Search,
38
+ WrapText,
39
+ ZoomIn,
40
+ ZoomOut,
41
+ } from 'lucide-preact';
42
+
43
+ import type { ToolbarCluster } from '@/client/components/common/toolbar-row';
44
+
45
+ /** Shared icon-button shell. Every action here is icon-only, so each carries both names. */
46
+ export const ACTION_CLASS =
47
+ 'flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer disabled:cursor-default disabled:opacity-50';
48
+
49
+ /** The state the toolbar draws, already resolved by the caller. */
50
+ export interface ToolbarState {
51
+ byteViewer: boolean;
52
+ hasPreview: boolean;
53
+ isPreview: boolean;
54
+ wordWrap: boolean;
55
+ findOpen: boolean;
56
+ copied: boolean;
57
+ isMaximized: boolean;
58
+ saveDisabled: boolean;
59
+ canRevert: boolean;
60
+ saveButton: ComponentChildren;
61
+ previewLabel: string;
62
+ findLabel: string;
63
+ wordWrapLabel: string;
64
+ copyLabel: string;
65
+ maximizeLabel: string;
66
+ onTogglePreview: () => void;
67
+ onToggleFind: () => void;
68
+ onToggleWordWrap: () => void;
69
+ onZoomIn: () => void;
70
+ onZoomOut: () => void;
71
+ onCopy: () => void;
72
+ onDownload: () => void;
73
+ onRevert: () => void;
74
+ onSaveAs: () => void;
75
+ onToggleMaximize: () => void;
76
+ onSave: () => void;
77
+ viewModeActions: ToolbarCluster['actions'];
78
+ maximizeButton: ComponentChildren;
79
+ viewModeButtons: ComponentChildren;
80
+ }
81
+
82
+ /** One pressed-state toggle. */
83
+ function Toggle({
84
+ label,
85
+ pressed,
86
+ title,
87
+ onClick,
88
+ children,
89
+ }: {
90
+ label: string;
91
+ pressed: boolean;
92
+ title?: string;
93
+ onClick: () => void;
94
+ children: ComponentChildren;
95
+ }) {
96
+ return (
97
+ <button
98
+ type="button"
99
+ onClick={onClick}
100
+ className={`${ACTION_CLASS} hover:bg-ink/5 ${pressed ? 'text-ink' : 'hover:text-ink'}`}
101
+ title={title ?? label}
102
+ aria-label={label}
103
+ aria-pressed={pressed}
104
+ >
105
+ {children}
106
+ </button>
107
+ );
108
+ }
109
+
110
+ /**
111
+ * The clusters, in hiding order.
112
+ *
113
+ * ORDER is the hiding order, most important first: the row keeps the width modes
114
+ * and full screen (the controls this panel is FOR), then copy/download, and the
115
+ * reading aids (find, wrap, zoom, preview) move into the `⋯` menu on a narrow
116
+ * panel. Grouping is the existing one — zoom is a pair, copy/download is a pair,
117
+ * the modes are a pair — because splitting a pair leaves half of it on the row.
118
+ */
119
+ export function buildEditorClusters(state: ToolbarState): ToolbarCluster[] {
120
+ const clusters: ToolbarCluster[] = [];
121
+
122
+ if (!state.byteViewer) {
123
+ clusters.push({
124
+ id: 'save',
125
+ // The primary action of the panel: a menu row must never be the only way to
126
+ // save a file.
127
+ pinned: true,
128
+ actions: [{ label: 'Save file', icon: Save, onSelect: state.onSave, disabled: state.saveDisabled }],
129
+ children: state.saveButton,
130
+ });
131
+ }
132
+
133
+ if (state.hasPreview) {
134
+ clusters.push({
135
+ id: 'preview',
136
+ actions: [
137
+ {
138
+ label: state.previewLabel,
139
+ icon: state.isPreview ? EyeOff : Eye,
140
+ onSelect: state.onTogglePreview,
141
+ active: state.isPreview,
142
+ },
143
+ ],
144
+ children: (
145
+ <Toggle label={state.previewLabel} pressed={state.isPreview} onClick={state.onTogglePreview}>
146
+ {state.isPreview ? <EyeOff size={14} /> : <Eye size={14} />}
147
+ </Toggle>
148
+ ),
149
+ });
150
+ }
151
+
152
+ if (!state.byteViewer) {
153
+ clusters.push({
154
+ id: 'find',
155
+ actions: [{ label: state.findLabel, icon: Search, onSelect: state.onToggleFind, active: state.findOpen }],
156
+ children: (
157
+ <Toggle
158
+ label={state.findLabel}
159
+ pressed={state.findOpen}
160
+ title={`${state.findLabel} (Ctrl+F)`}
161
+ onClick={state.onToggleFind}
162
+ >
163
+ <Search size={14} />
164
+ </Toggle>
165
+ ),
166
+ });
167
+ clusters.push({
168
+ id: 'wrap',
169
+ actions: [
170
+ { label: state.wordWrapLabel, icon: WrapText, onSelect: state.onToggleWordWrap, active: state.wordWrap },
171
+ ],
172
+ children: (
173
+ <Toggle label={state.wordWrapLabel} pressed={state.wordWrap} onClick={state.onToggleWordWrap}>
174
+ <WrapText size={14} />
175
+ </Toggle>
176
+ ),
177
+ });
178
+ clusters.push({
179
+ id: 'zoom',
180
+ actions: [
181
+ { label: 'Decrease font size', icon: ZoomOut, onSelect: state.onZoomOut },
182
+ { label: 'Increase font size', icon: ZoomIn, onSelect: state.onZoomIn },
183
+ ],
184
+ children: (
185
+ <>
186
+ <button
187
+ type="button"
188
+ onClick={state.onZoomOut}
189
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
190
+ title="Decrease font size"
191
+ aria-label="Decrease font size"
192
+ >
193
+ <ZoomOut size={14} />
194
+ </button>
195
+ <button
196
+ type="button"
197
+ onClick={state.onZoomIn}
198
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
199
+ title="Increase font size"
200
+ aria-label="Increase font size"
201
+ >
202
+ <ZoomIn size={14} />
203
+ </button>
204
+ </>
205
+ ),
206
+ });
207
+ clusters.push({
208
+ id: 'save-as',
209
+ // Never pinned: it is a rare operation, and the row's space belongs to Save.
210
+ actions: [{ label: 'Save as…', icon: SaveAll, onSelect: state.onSaveAs }],
211
+ children: (
212
+ <button
213
+ type="button"
214
+ onClick={state.onSaveAs}
215
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
216
+ title="Save the buffer to a new file"
217
+ aria-label="Save as"
218
+ >
219
+ <SaveAll size={14} />
220
+ </button>
221
+ ),
222
+ });
223
+ clusters.push({
224
+ id: 'revert',
225
+ // Never `pinned`: it is the one destructive control in the row, and a menu is
226
+ // exactly the friction it should have.
227
+ actions: [
228
+ { label: 'Revert file', icon: RotateCcw, onSelect: state.onRevert, disabled: !state.canRevert },
229
+ ],
230
+ children: (
231
+ <button
232
+ type="button"
233
+ onClick={state.onRevert}
234
+ disabled={!state.canRevert}
235
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
236
+ title={state.canRevert ? 'Discard my changes and reload from disk' : 'No unsaved changes to discard'}
237
+ aria-label="Revert file"
238
+ >
239
+ <RotateCcw size={14} />
240
+ </button>
241
+ ),
242
+ });
243
+ }
244
+
245
+ clusters.push({
246
+ id: 'copy',
247
+ actions: [
248
+ { label: state.copyLabel, icon: Copy, onSelect: state.onCopy },
249
+ { label: 'Download file', icon: Download, onSelect: state.onDownload },
250
+ ],
251
+ children: (
252
+ <>
253
+ <button
254
+ type="button"
255
+ onClick={state.onCopy}
256
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
257
+ title={state.copyLabel}
258
+ aria-label={state.copyLabel}
259
+ >
260
+ {state.copied ? <Copy size={14} className="text-success" /> : <Copy size={14} />}
261
+ </button>
262
+ <button
263
+ type="button"
264
+ onClick={state.onDownload}
265
+ className={`${ACTION_CLASS} hover:bg-ink/5 hover:text-ink`}
266
+ title="Download file"
267
+ aria-label="Download file"
268
+ >
269
+ <Download size={14} />
270
+ </button>
271
+ </>
272
+ ),
273
+ });
274
+
275
+ // The width modes and full SCREEN are the controls this panel exists for, so they
276
+ // are the LAST clusters — the tail is what the menu takes.
277
+ clusters.push({
278
+ id: 'view-modes',
279
+ // The two width modes are why this toolbar grew these buttons, and a mode
280
+ // reachable only from a menu is a mode half the readers never find.
281
+ pinned: true,
282
+ actions: state.viewModeActions,
283
+ children: state.viewModeButtons,
284
+ });
285
+ clusters.push({
286
+ id: 'maximize',
287
+ pinned: true,
288
+ actions: [
289
+ {
290
+ label: state.maximizeLabel,
291
+ icon: state.isMaximized ? Minimize : Maximize,
292
+ onSelect: state.onToggleMaximize,
293
+ active: state.isMaximized,
294
+ },
295
+ ],
296
+ children: state.maximizeButton,
297
+ });
298
+
299
+ return clusters;
300
+ }
@@ -80,19 +80,32 @@ export function FileCreateModal({ folderPath, kind, value, error, isLoading, onC
80
80
  }
81
81
 
82
82
  interface DeleteModalProps {
83
+ /** The entry's real path — what is deleted, and what the dialog must name. */
83
84
  fileName: string;
85
+ /** The row's label, when it differs from the path (a collapsed chain). */
86
+ displayName?: string;
84
87
  isFolder: boolean;
85
88
  isLoading: boolean;
86
89
  onCancel: () => void;
87
90
  onConfirm: () => void;
88
91
  }
89
92
 
90
- export function FileDeleteModal({ fileName, isFolder, isLoading, onCancel, onConfirm }: DeleteModalProps) {
93
+ export function FileDeleteModal({ fileName, displayName, isFolder, isLoading, onCancel, onConfirm }: DeleteModalProps) {
91
94
  return createPortal(
92
95
  <div className="fixed inset-0 bg-ink/20 z-[100] flex items-center justify-center p-4 backdrop-blur-sm">
93
96
  <div className="bg-paper rounded shadow-xl p-4 w-full max-w-sm border border-ink/10 font-sans">
94
97
  <h3 className="font-semibold text-ink mb-2 text-sm">Delete {isFolder ? 'Folder' : 'File'}</h3>
95
98
  <p className="text-xs text-ink/70 mb-4">Are you sure you want to delete <span className="font-mono bg-canvas px-1 rounded">{fileName}</span>? This action cannot be undone.</p>
99
+ {/* A collapsed chain row is LABELLED `com/java/app/package` but its path
100
+ is the deepest directory, and that is what gets deleted. Naming only
101
+ the label would promise a removal of four directories and perform
102
+ one, so the dialog says which it is. */}
103
+ {displayName && displayName !== fileName && (
104
+ <p className="text-[11px] text-ink/50 mb-4">
105
+ The row is <span className="font-mono">{displayName}</span>; this deletes{' '}
106
+ <span className="font-mono">{fileName}</span> only.
107
+ </p>
108
+ )}
96
109
  <div className="flex justify-end space-x-2">
97
110
  <button
98
111
  onClick={onCancel}
@@ -310,7 +310,8 @@ export function FileTreeItem({
310
310
 
311
311
  {mounted && actions.showDeleteModal && (
312
312
  <FileDeleteModal
313
- fileName={file.name}
313
+ fileName={file.path}
314
+ displayName={file.name}
314
315
  isFolder={isFolder}
315
316
  isLoading={actions.busy}
316
317
  onCancel={actions.closeDelete}
@@ -132,7 +132,9 @@ describe('Files panel clipboard', () => {
132
132
  });
133
133
 
134
134
  test('the row menu hides Paste on a folder inside the copied folder’s own subtree', async () => {
135
- panel.disk = { '.': { src: null }, src: { deep: null }, 'src/deep': {} };
135
+ // `src` holds a folder AND a file, so it is its own row — a folder holding
136
+ // only one folder would be collapsed into one row naming the chain.
137
+ panel.disk = { '.': { src: null }, src: { deep: null, 'a.ts': 'file' }, 'src/deep': {} };
136
138
  await panel.mount();
137
139
 
138
140
  await panel.rightClickRow('src');
@@ -127,4 +127,65 @@ describe('Files panel listing', () => {
127
127
  expect(srcReads()).toBe(2);
128
128
  expect(panel.container.textContent).toContain('a.ts');
129
129
  });
130
+
131
+ test('a package tree is ONE row naming the whole chain, and it expands into the deepest folder', async () => {
132
+ panel.disk = {
133
+ '.': { com: null },
134
+ com: { java: null },
135
+ 'com/java': { app: null },
136
+ 'com/java/app': { package: null },
137
+ 'com/java/app/package': { 'Main.java': 'file' },
138
+ };
139
+ panel.dirReads = [];
140
+ await panel.mount();
141
+
142
+ // One row instead of four: the chain's own levels are not rows at all.
143
+ expect(panel.visibleNames()).toContain('com/java/app/package');
144
+ expect(panel.visibleNames()).not.toContain('com');
145
+ // Reading the row's own path is the read that would have happened on the
146
+ // fourth expand; the three levels above it are never asked about.
147
+ expect(panel.dirReads).toEqual(['.']);
148
+
149
+ await panel.clickRow('com/java/app/package');
150
+
151
+ expect(panel.container.textContent).toContain('Main.java');
152
+ expect(panel.dirReads).toContain('com/java/app/package');
153
+ expect(panel.dirReads).not.toContain('com');
154
+ expect(panel.dirReads).not.toContain('com/java');
155
+ });
156
+
157
+ test('a folder holding a folder and a file is not collapsed', async () => {
158
+ panel.disk = {
159
+ '.': { src: null },
160
+ src: { deep: null, 'a.ts': 'file' },
161
+ 'src/deep': { 'b.ts': 'file' },
162
+ };
163
+ await panel.mount();
164
+
165
+ expect(panel.visibleNames()).toContain('src');
166
+ expect(panel.visibleNames()).not.toContain('src/deep');
167
+ });
168
+
169
+ test('the delete dialog names the path it deletes, not just the chain label', async () => {
170
+ // A chain INSIDE a folder is labelled relative to that folder
171
+ // (`java/app/package`) while its path names the whole thing. Both are on
172
+ // screen, because the delete removes the deepest directory only — a dialog
173
+ // showing just the label would promise more than it performs.
174
+ panel.disk = {
175
+ '.': { com: null },
176
+ com: { java: null, 'README.md': 'file' },
177
+ 'com/java': { app: null },
178
+ 'com/java/app': { package: null },
179
+ 'com/java/app/package': { 'Main.java': 'file' },
180
+ };
181
+ await panel.mount();
182
+ await panel.clickRow('com');
183
+
184
+ await panel.rightClickRow('java/app/package');
185
+ await panel.clickMenuRow('Delete');
186
+
187
+ const text = panel.documentText();
188
+ expect(text).toContain('com/java/app/package');
189
+ expect(text).toContain('this deletes');
190
+ });
130
191
  });
@@ -10,7 +10,7 @@ import { useGitStatus } from '@/client/hooks/workspace/git-status';
10
10
  import { useFileListing } from '@/client/hooks/workspace/file-listing';
11
11
  import { useFileCreate } from '@/client/hooks/workspace/file-create';
12
12
  import { useFileClipboard, type ClipboardTarget } from '@/client/hooks/workspace/file-clipboard';
13
- import { rekeyExpansion } from '@/shared/lib/fs/file-tree';
13
+ import { useFileTreeEdits } from '@/client/hooks/workspace/file-tree-edits';
14
14
  import { filterFileTree } from '@/client/components/workspace/file-explorer/filter';
15
15
  import { useRepoList, useRepoScope } from '@/client/hooks/workspace/repo-scope';
16
16
  import { useRealtimeTopic } from '@/client/hooks/ui/realtime';
@@ -100,53 +100,6 @@ export function FileExplorer({ className = '', enabled = true, rootPath, onOpenF
100
100
  setActiveRepo(repo);
101
101
  };
102
102
 
103
- /**
104
- * Open every folder that leads to `path`.
105
- *
106
- * A nested create (`lib/parse.ts`) and a rename into a new folder both make
107
- * directories the user has never opened, and a row placed inside a collapsed
108
- * folder is a row nobody can see — the write would look like it failed. EVERY
109
- * ancestor is opened, not only the direct parent: expanding just the last one
110
- * still hides the entry behind a collapsed `lib`.
111
- */
112
- const revealPath = (path: string) => {
113
- const segments = path.split('/').slice(0, -1);
114
- if (segments.length === 0) return;
115
- const chain = segments.map((_, index) => segments.slice(0, index + 1).join('/'));
116
- setExpandedPaths(prev => {
117
- if (chain.every((folder) => prev.has(folder))) return prev;
118
- const next = new Set(prev);
119
- for (const folder of chain) next.add(folder);
120
- setStoredExpandedPaths(Array.from(next));
121
- return next;
122
- });
123
- };
124
-
125
- /** Place a row a create just produced, without re-reading the tree. */
126
- const insertCreated = (entry: { path: string; kind: 'file' | 'folder' }) => {
127
- listing.insertEntry(entry);
128
- revealPath(entry.path);
129
- };
130
-
131
- /**
132
- * Move a row a rename just relocated, without re-reading.
133
- *
134
- * A folder's descendants and every open branch beneath it carry its path as a
135
- * prefix, so the expansion set is rekeyed in the same step — an open `src`
136
- * renamed to `lib` must stay open as `lib`, not collapse.
137
- */
138
- const moveRenamed = (fromPath: string, toPath: string) => {
139
- listing.moveEntry(fromPath, toPath);
140
- setExpandedPaths(prev => {
141
- const next = rekeyExpansion(prev, fromPath, toPath);
142
- setStoredExpandedPaths(Array.from(next));
143
- return next;
144
- });
145
- // A rename INTO a new folder (`a.ts` → `nested/a.ts`) has the same problem a
146
- // nested create does: the destination folder is one nobody has opened.
147
- revealPath(toPath);
148
- };
149
-
150
103
  /**
151
104
  * Re-read everything this panel shows. Defined ABOVE the `!enabled` return so
152
105
  * the create flow below can use it: a hook cannot be called after a branch.
@@ -157,6 +110,15 @@ export function FileExplorer({ className = '', enabled = true, rootPath, onOpenF
157
110
  else void listing.reload();
158
111
  };
159
112
 
113
+ // A create and a rename land locally, and the row they produce is revealed
114
+ // through the rows that are DRAWN — see `useFileTreeEdits`.
115
+ const { insertCreated, moveRenamed } = useFileTreeEdits({
116
+ listing,
117
+ setExpandedPaths,
118
+ setStoredExpandedPaths,
119
+ reload: refresh,
120
+ });
121
+
160
122
  // One clipboard for the whole tree, owned here and passed down: a
161
123
  // subscription per row would be hundreds of listeners for a value that
162
124
  // changes on a right-click.
@@ -90,10 +90,15 @@ describe('Files panel local edits', () => {
90
90
  await panel.submitNewFile('lib/deep/parse.ts');
91
91
 
92
92
  // Every folder on the way is expanded and reads its own directory: the
93
- // entry is not somewhere the user has to go hunting for.
93
+ // entry is not somewhere the user has to go hunting for. `lib` and `deep`
94
+ // are ONE row here — a folder holding only one folder collapses into a row
95
+ // naming the chain — and that row is the one the create expands.
94
96
  expect(panel.visibleNames()).toContain('parse.ts');
95
- expect(panel.visibleNames()).toContain('deep');
96
- expect(panel.visibleNames()).toContain('lib');
97
+ expect(panel.visibleNames()).toContain('lib/deep');
98
+ // The reveal expands the row that is DRAWN, not the path's own segments:
99
+ // `lib` and `deep` are not rows, so nothing asks the server about them.
100
+ expect(panel.dirReads).not.toContain('lib');
101
+ expect(panel.dirReads).not.toContain('lib/deep');
97
102
  });
98
103
 
99
104
  test('a rename moves the row in place without re-reading the root', async () => {
@@ -107,7 +107,12 @@ export function SearchPanelBody({
107
107
 
108
108
  // The same flags the search ran with, so the editor's own matcher paints the
109
109
  // identical set of occurrences once the file opens.
110
- const options: FindOptions = useMemo(() => ({ matchCase, wholeWord, isRegex: useRegex }), [matchCase, wholeWord, useRegex]);
110
+ const options: FindOptions = useMemo(
111
+ // The workspace search has no selection to restrict to, so `inSelection` is false —
112
+ // the flag exists for the EDITOR's bar, where the range is the user's own selection.
113
+ () => ({ matchCase, wholeWord, isRegex: useRegex, inSelection: false }),
114
+ [matchCase, wholeWord, useRegex],
115
+ );
111
116
 
112
117
  /**
113
118
  * A row click opens the file AND points the editor at the hit.
@@ -30,9 +30,10 @@
30
30
  * awaits.
31
31
  */
32
32
 
33
- import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
33
+ import { useCallback, useEffect, useRef } from 'preact/hooks';
34
34
  import type { TargetedDragEvent } from 'preact';
35
35
  import { collectDroppedFileUris, hasDraggedFiles } from '@/client/hooks/chat/composer/drop-payload';
36
+ import { useDragPresence } from '@/client/hooks/ui/drag-presence';
36
37
  import { primeFileReads, primedPrefix } from '@/client/hooks/chat/composer/file-reads';
37
38
  import type { PrimedReads } from '@/client/hooks/chat/composer/file-reads';
38
39
  import {
@@ -73,11 +74,12 @@ export interface UseFileDropResult {
73
74
  }
74
75
 
75
76
  export function useFileDrop({ onFiles, disabled = false }: UseFileDropOptions): UseFileDropResult {
76
- const [isDragging, setIsDragging] = useState(false);
77
- // dragenter/dragleave fire for every nested child the pointer crosses, so a
78
- // boolean flag drops to false the instant the cursor moves from the card onto
79
- // the textarea. Counting them keeps the overlay steady.
80
- const depthRef = useRef(0);
77
+ // `relatedTarget`-based, not a counter: `dragenter` fires for every nested
78
+ // child the pointer crosses (the card's toolbar, the textarea, the attachment
79
+ // chips), so a counter rose with each crossing while a matching `dragleave` to
80
+ // a node still inside was ignored — and the overlay stayed on after the
81
+ // pointer left. See `useDragPresence`.
82
+ const presence = useDragPresence();
81
83
  // Latest callback and flag behind refs, so the handlers stay referentially
82
84
  // stable and the window guard sees the current `disabled`.
83
85
  const onFilesRef = useRef(onFiles);
@@ -85,24 +87,6 @@ export function useFileDrop({ onFiles, disabled = false }: UseFileDropOptions):
85
87
  const disabledRef = useRef(disabled);
86
88
  disabledRef.current = disabled;
87
89
 
88
- const reset = useCallback(() => {
89
- depthRef.current = 0;
90
- setIsDragging(false);
91
- }, []);
92
-
93
- // A drag can end without reaching this element again — released over the
94
- // page, cancelled with Escape, or its source node unmounted mid-drag. The
95
- // composer's own handlers have already run by the time these fire, so this
96
- // only clears state the drop handler did not.
97
- useEffect(() => {
98
- window.addEventListener('dragend', reset);
99
- window.addEventListener('drop', reset);
100
- return () => {
101
- window.removeEventListener('dragend', reset);
102
- window.removeEventListener('drop', reset);
103
- };
104
- }, [reset]);
105
-
106
90
  // Files dropped anywhere else would navigate the tab to `file://` and discard
107
91
  // Kabmo, so the default is cancelled app-wide. This runs after the
108
92
  // composer's own drop handler (the event bubbles up to window), by which point
@@ -123,27 +107,28 @@ export function useFileDrop({ onFiles, disabled = false }: UseFileDropOptions):
123
107
  if (!hasDraggedFiles(e.dataTransfer)) return;
124
108
  e.preventDefault();
125
109
  if (disabledRef.current) return;
126
- depthRef.current += 1;
127
- setIsDragging(true);
128
- }, []);
110
+ presence.enter();
111
+ }, [presence]);
129
112
 
130
113
  const onDragOver = useCallback((e: TargetedDragEvent<HTMLElement>) => {
131
114
  if (!hasDraggedFiles(e.dataTransfer)) return;
132
115
  // Required: without it the browser refuses the drop and navigates to the
133
116
  // file instead of handing it to the app.
134
117
  e.preventDefault();
118
+ // Every `dragover` here is proof the pointer is over the card; a child
119
+ // crossing fires the enter/leave pair in between, and this re-asserts the
120
+ // overlay without counting anything.
121
+ if (!disabledRef.current) presence.enter();
135
122
  if (!e.dataTransfer) return;
136
123
  // `none` is the only cursor that tells the truth about a closed composer.
137
124
  e.dataTransfer.dropEffect = disabledRef.current ? 'none' : 'copy';
138
- }, []);
125
+ }, [presence]);
139
126
 
140
127
  // Not gated on the payload: `dataTransfer.types` can already be empty on
141
- // dragleave. The counter is the gate — a text drag never raised it.
142
- const onDragLeave = useCallback(() => {
143
- if (depthRef.current === 0) return;
144
- depthRef.current -= 1;
145
- if (depthRef.current === 0) setIsDragging(false);
146
- }, []);
128
+ // dragleave. `useDragPresence.leave` is the gate.
129
+ const onDragLeave = useCallback((e: TargetedDragEvent<HTMLElement>) => {
130
+ presence.leave(e);
131
+ }, [presence]);
147
132
 
148
133
  const onDrop = useCallback((e: TargetedDragEvent<HTMLElement>) => {
149
134
  const dt = e.dataTransfer;
@@ -155,7 +140,7 @@ export function useFileDrop({ onFiles, disabled = false }: UseFileDropOptions):
155
140
 
156
141
  if (!dt || !hasDraggedFiles(dt)) return;
157
142
  e.preventDefault();
158
- reset();
143
+ presence.clear();
159
144
  if (disabledRef.current) return;
160
145
 
161
146
  // START THE READS NOW, in the drop handler's own tick. A dropped File's
@@ -192,9 +177,9 @@ export function useFileDrop({ onFiles, disabled = false }: UseFileDropOptions):
192
177
  // reports the ones that never produced content.
193
178
  if (resolved.length > 0) onFilesRef.current(resolved, incomplete, [], primed);
194
179
  });
195
- }, [reset]);
180
+ }, [presence]);
196
181
 
197
- return { isDragging, dropProps: { onDragEnter, onDragOver, onDragLeave, onDrop } };
182
+ return { isDragging: presence.active, dropProps: { onDragEnter, onDragOver, onDragLeave, onDrop } };
198
183
  }
199
184
 
200
185
  /**