@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
@@ -38,10 +38,15 @@
38
38
  * is the panel's own overlap with the visible area (`useKeyboardInset`),
39
39
  * applied as padding; with no keyboard the padding is the home indicator's
40
40
  * inset instead.
41
- * - **A send collapses the mobile stretch.** The stretched composer covers the
42
- * transcript, so staying stretched would hide the answer being streamed. On
43
- * desktop it stays: the chat is visible either way, and a composer that
44
- * snapped back on every send would move the box the user is typing in.
41
+ * - **A send collapses the stretch, on BOTH layouts, and only a DISPATCHED
42
+ * send does.** The stretched composer covers the transcript on a phone and
43
+ * covers a third of the conversation on a desktop, so it returns to the dock
44
+ * once the prompt is on its way — but the collapse is driven by the send
45
+ * pipeline's own `onSent`, never by the click: a Send press that dispatched
46
+ * nothing (an empty draft, an attachment whose read produced no body) must
47
+ * leave the box exactly where the user put it, or a refused send would look
48
+ * like a successful one. Escape collapses either layout too, from a document
49
+ * listener, so the popup's own Escape handling cannot trap the user.
45
50
  */
46
51
 
47
52
  import type { CSSProperties } from 'preact';
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from 'preact/hooks';
1
+ import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
2
2
  import type { ClipboardEvent, SetStateAction } from 'preact/compat';
3
3
  import { AlertTriangle, X } from 'lucide-preact';
4
4
  import type { Attachment } from '@/shared/types';
@@ -106,6 +106,17 @@ export function ChatInput({
106
106
  }
107
107
  };
108
108
 
109
+ // A DISPATCHED send returns the composer to its docked size, on BOTH layouts.
110
+ // Hooked into the pipeline rather than the click handler so every way in —
111
+ // the Send button, Enter, Cmd+Enter steering, a queued follow-up — collapses
112
+ // it, while a click that dispatched nothing (an empty draft, an unreadable
113
+ // attachment) leaves the stretched box exactly where the user put it. Staying
114
+ // stretched hides the answer being streamed on a phone, and on a desktop it
115
+ // keeps a 38vh box over the conversation the prompt was written against.
116
+ // Stable identity: the pipeline's `submit` closes over it, and a fresh arrow
117
+ // per render would rebuild `submit` on every keystroke.
118
+ const collapseOnSend = useCallback(() => setExpanded(false), []);
119
+
109
120
  // Attach-and-send pipeline: drop handling, the inline notice, and the send
110
121
  // guard all live in the hook, because a drop registers files before this
111
122
  // component re-renders and the send decision cannot read a stale prop.
@@ -116,6 +127,7 @@ export function ChatInput({
116
127
  disabled,
117
128
  rootPath,
118
129
  onSend,
130
+ onSent: collapseOnSend,
119
131
  });
120
132
 
121
133
  // Publishes this composer's state to the plugin kit, and gives the kit a way
@@ -167,14 +179,6 @@ export function ChatInput({
167
179
  return () => document.removeEventListener('keydown', onKey);
168
180
  }, [expanded]);
169
181
 
170
- // A send on a phone collapses the stretch: it covers the transcript, so
171
- // staying stretched would hide the answer being streamed. On a desktop the
172
- // chat is visible either way and the box stays where the user put it.
173
- const handleSubmit = (options?: { steering?: boolean }) => {
174
- if (isMobile) setExpanded(false);
175
- submit(options);
176
- };
177
-
178
182
  // Browser dictation, delegated to omp's own local STT worker. The hook owns
179
183
  // capture + the socket; this component owns where the text lands and the
180
184
  // status line while a first-run model download is still going.
@@ -275,7 +279,7 @@ export function ChatInput({
275
279
  <ComposerTextarea
276
280
  value={value}
277
281
  onChange={onChange}
278
- onSend={handleSubmit}
282
+ onSend={submit}
279
283
  disabled={disabled}
280
284
  appSettings={appSettings}
281
285
  rootPath={rootPath}
@@ -308,7 +312,7 @@ export function ChatInput({
308
312
  isGenerating={isGenerating}
309
313
  chatRunning={chatRunning}
310
314
  onStop={onStop}
311
- onSend={() => handleSubmit()}
315
+ onSend={() => submit()}
312
316
  sendDisabled={disabled || (!value.trim() && attachments.length === 0)}
313
317
  accessMode={accessMode}
314
318
  onSelectAccess={onAccessModeChange}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * A DISPATCHED send returns the composer to its docked size, on BOTH layouts.
8
+ *
9
+ * This is the rule the click handler used to own as `if (isMobile)
10
+ * setExpanded(false)`, which was wrong twice over. A desktop kept its 38vh box
11
+ * over the conversation the prompt was written against, and on EITHER layout a
12
+ * press that dispatched nothing (an empty draft, an attachment whose read
13
+ * produced no body) collapsed a box whose content had never been sent — a
14
+ * refusal that read as success.
15
+ *
16
+ * The collapse therefore lives in the send pipeline's `onSent`, after every
17
+ * guard. These cases pin both directions from the component the user actually
18
+ * presses: the Maximize control, then a send, then the frame it is in.
19
+ */
20
+
21
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
22
+ import { Window } from 'happy-dom';
23
+ import { h, render } from 'preact';
24
+ import { act } from 'preact/test-utils';
25
+ import type { Attachment } from '@/shared/types';
26
+ import { ChatInput } from '@/client/components/workspace/chat-timeline/chat-input';
27
+ import { delay } from '@/client/hooks/chat/composer/file-reads';
28
+ import { restoreRealtime, silenceRealtime } from '@/test-support/silent-socket';
29
+
30
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'PointerEvent'] as const;
31
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
32
+
33
+ beforeAll(() => {
34
+ const win = new Window({ url: 'http://localhost' });
35
+ const target = globalThis as unknown as Record<string, unknown>;
36
+ for (const key of DOM_GLOBALS) {
37
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
38
+ target[key] = (win as unknown as Record<string, unknown>)[key];
39
+ }
40
+ });
41
+
42
+ afterAll(() => {
43
+ const target = globalThis as unknown as Record<string, unknown>;
44
+ for (const key of DOM_GLOBALS) {
45
+ if (nativeGlobals[key] === undefined) delete target[key];
46
+ else target[key] = nativeGlobals[key];
47
+ }
48
+ });
49
+
50
+ let container: HTMLElement | null = null;
51
+ /** Every dispatch the composer made, so a case can assert what was NOT sent. */
52
+ const sent: Attachment[][] = [];
53
+
54
+ beforeEach(() => {
55
+ silenceRealtime();
56
+ sent.length = 0;
57
+ });
58
+
59
+ afterEach(async () => {
60
+ // Unmount inside `act`, then drain AFTER the realtime reset and WHILE this
61
+ // window still exists. A stretched composer runs `useKeyboardInset` — a
62
+ // `ResizeObserver`, four window listeners and a deferred
63
+ // `requestAnimationFrame` — and the send pipeline resolves on a zero-delay
64
+ // read-back, so a case can leave work queued on this window; Preact's own
65
+ // effect flush is deferred too, so an unmount outside `act` lets a render land
66
+ // after `afterAll` deletes the globals. Measured as `document is not defined`
67
+ // inside whichever file bun runs next: 9 of 12 folder runs without this
68
+ // drain, 0 of 10 with it. The drain must be a BARE timer — wrapping it in
69
+ // `act` queues another flush and reintroduces the leak.
70
+ const host = container;
71
+ if (host) {
72
+ // The local binding is the narrowing: a closure cannot carry it.
73
+ await act(async () => { render(null, host); });
74
+ host.remove();
75
+ }
76
+ container = null;
77
+ restoreRealtime();
78
+ await delay(50);
79
+ });
80
+
81
+
82
+ interface MountOptions {
83
+ value?: string;
84
+ variant?: 'desktop' | 'mobile';
85
+ }
86
+
87
+ async function mount({ value = '', variant = 'desktop' }: MountOptions = {}): Promise<HTMLElement> {
88
+ const host = document.createElement('div');
89
+ document.body.appendChild(host);
90
+ await act(async () => {
91
+ render(
92
+ h(ChatInput, {
93
+ value,
94
+ onChange: () => {},
95
+ onSend: (attachments: Attachment[]) => { sent.push(attachments); },
96
+ isGenerating: false,
97
+ composerModelRef: { current: null },
98
+ variant,
99
+ expandable: true,
100
+ sessionId: 'composer-stretch-test',
101
+ }),
102
+ host,
103
+ );
104
+ });
105
+ container = host;
106
+ return host;
107
+ }
108
+
109
+ const byLabel = (el: HTMLElement, label: string) =>
110
+ el.querySelector(`[aria-label="${label}"]`) as HTMLButtonElement | null;
111
+ const isExpanded = (el: HTMLElement) => byLabel(el, 'Restore composer') !== null;
112
+
113
+ /** Clicks the Maximize control, the way the user starts a stretched draft. */
114
+ async function stretch(el: HTMLElement) {
115
+ const maximize = byLabel(el, 'Maximize composer');
116
+ expect(maximize).not.toBeNull();
117
+ await act(async () => { maximize!.click(); });
118
+ expect(isExpanded(el)).toBe(true);
119
+ }
120
+
121
+ /** Drains the pipeline's own zero-delay wait plus the renders it lands. */
122
+ async function settle(rounds = 6) {
123
+ for (let i = 0; i < rounds; i += 1) {
124
+ await act(async () => { await delay(0); });
125
+ }
126
+ }
127
+
128
+ describe('a send collapses the stretch', () => {
129
+ for (const variant of ['desktop', 'mobile'] as const) {
130
+ test(`a ${variant} send returns the composer to the dock`, async () => {
131
+ const el = await mount({ value: 'collapse me', variant });
132
+ await stretch(el);
133
+
134
+ const send = byLabel(el, 'Send message');
135
+ expect(send).not.toBeNull();
136
+ await act(async () => { send!.click(); });
137
+ await settle();
138
+
139
+ expect(sent.length).toBe(1);
140
+ // Back to the docked frame: the control offers Maximize again.
141
+ expect(isExpanded(el)).toBe(false);
142
+ });
143
+ }
144
+
145
+ test('a send that dispatched nothing leaves the stretched box alone', async () => {
146
+ const el = await mount({ variant: 'desktop' });
147
+ await stretch(el);
148
+
149
+ // Enter with an empty draft: the pipeline returns before it dispatches, so
150
+ // the box the user stretched stays exactly as they left it.
151
+ const textarea = el.querySelector('textarea')!;
152
+ await act(async () => {
153
+ textarea.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
154
+ });
155
+ await settle();
156
+
157
+ expect(sent).toEqual([]);
158
+ expect(isExpanded(el)).toBe(true);
159
+
160
+ // Collapse before teardown: a stretched composer keeps `useKeyboardInset`
161
+ // live (a `ResizeObserver` plus a deferred frame), and leaving one mounted
162
+ // past `afterAll` lets its work run after the DOM globals are gone.
163
+ await act(async () => { byLabel(el, 'Restore composer')!.click(); });
164
+ });
165
+ });
@@ -70,14 +70,28 @@ describe('DiffView height ceiling', () => {
70
70
  expect(wrap.className).not.toContain('overflow-auto');
71
71
  });
72
72
 
73
- test('the wrapper is a flex column with min-h-0, so the view gets a definite height', async () => {
73
+ test('the wrapper is the ceiling and the host is the marker the fill rule keys on', async () => {
74
74
  const el = await mount();
75
75
  const wrap = el.querySelector('div[class*="max-h-72"]') as HTMLElement;
76
76
  expect(wrap.className).toContain('flex');
77
77
  expect(wrap.className).toContain('flex-col');
78
- // Without `min-h-0` a flex item refuses to shrink below its content, the
79
- // view's height resolves to `auto`, and nothing scrolls.
78
+ // Without `min-h-0` a flex item refuses to shrink below its content, so the
79
+ // view can never be shorter than the file.
80
80
  expect(wrap.className).toContain('min-h-0');
81
+
82
+ // `min-h-0` alone is NOT enough, and this test used to claim it was. It
83
+ // lets the item shrink; what the editor root needs is a height to shrink
84
+ // TO. `.cm-editor` is `height: 100%`, a percentage resolves against a
85
+ // DEFINITE containing block, and a `max-height` ancestor is indefinite for
86
+ // that — measured in the timeline, a 1847px root inside a 288px wrapper,
87
+ // clipped by `overflow-hidden` with `scrollHeight === clientHeight`, so a
88
+ // 30-line edit card showed 9 rows and could not scroll. The height now
89
+ // arrives through LAYOUT (`[data-code-surface]` is a column flex container
90
+ // and the root a shrinking item — `css.test.ts` gates the rule), which is
91
+ // why the host must carry the marker: without it the rule matches nothing
92
+ // and the clipping comes back with no error anywhere.
93
+ const host = wrap.querySelector('[data-code-surface]') as HTMLElement | null;
94
+ expect(host).not.toBeNull();
81
95
  });
82
96
 
83
97
  test('the header counts come from the patch, not from git', async () => {
@@ -143,12 +143,16 @@ export function DiffView({ text, path = '', maxHeightClass = 'max-h-72' }: DiffV
143
143
  {/* The panel views are `w-full h-full overflow-auto`, but their parent in
144
144
  the diff panel has a DEFINITE height while this one only has a
145
145
  `max-height` — and `height: 100%` against an auto-height box resolves
146
- to `auto`, so the view grew to its content (measured 1521px inside a
147
- 288px parent) and `overflow-hidden` clipped it: `scrollHeight ===
148
- clientHeight` and nothing could scroll.
149
- A flex column with `min-h-0` gives the view the definite height it
150
- needs to resolve `h-full` (measured 288px), so the view scrolls its
151
- own content and this wrapper only bounds it. */}
146
+ to `auto`. `min-h-0` on this flex column is necessary but NOT
147
+ sufficient: it lets the item shrink, while what the view needs is a
148
+ height to shrink TO, and a `max-height` ancestor does not give a
149
+ percentage one. Measured with only this wrapper in place: the editor
150
+ root resolved to 1847px inside the 288px box and `overflow-hidden`
151
+ clipped it, so `scrollHeight === clientHeight` and a 30-line edit card
152
+ showed 9 rows with no way to reach the rest — in both shapes.
153
+ `[data-code-surface]` in `tailwind.css` is the other half: the host is
154
+ a column flex container and the editor root a shrinking item, which
155
+ gives it the height through layout instead of through a percentage. */}
152
156
  <div className={`flex ${maxHeightClass} min-h-0 flex-col overflow-hidden`}>
153
157
  {/* No tab key: this diff lives inside a chat card, and the timeline —
154
158
  not the card — is what the reader scrolls. No counts either: the
@@ -27,6 +27,16 @@ interface EditorBodyProps {
27
27
  setZoomLevel: (update: (current: number) => number) => void;
28
28
  paletteOpen: boolean;
29
29
  setPaletteOpen: (open: boolean) => void;
30
+ /** Bumped when the user asks for "go to line"; the document owns the dialog. */
31
+ goToLineRequest: number;
32
+ /** Open the Save As dialog. */
33
+ onSaveAs: () => void;
34
+ /** The file picker is open. */
35
+ quickOpen: boolean;
36
+ onCloseQuickOpen: () => void;
37
+ onOpenPath?: (path: string) => void;
38
+ rootPath?: string | null;
39
+ repoPath?: string | null;
30
40
  runCommand: (command: EditorCommand) => void;
31
41
  editorFontFamily: string;
32
42
  editorTheme: EditorThemeState;
@@ -61,6 +71,13 @@ export function EditorBody({
61
71
  setZoomLevel,
62
72
  paletteOpen,
63
73
  setPaletteOpen,
74
+ goToLineRequest,
75
+ onSaveAs,
76
+ quickOpen,
77
+ onCloseQuickOpen,
78
+ onOpenPath,
79
+ rootPath = null,
80
+ repoPath = null,
64
81
  runCommand,
65
82
  editorFontFamily,
66
83
  editorTheme,
@@ -113,6 +130,13 @@ export function EditorBody({
113
130
  setZoomLevel={setZoomLevel}
114
131
  paletteOpen={paletteOpen}
115
132
  setPaletteOpen={setPaletteOpen}
133
+ goToLineRequest={goToLineRequest}
134
+ onSaveAs={onSaveAs}
135
+ quickOpen={quickOpen}
136
+ onCloseQuickOpen={onCloseQuickOpen}
137
+ onOpenPath={onOpenPath}
138
+ rootPath={rootPath}
139
+ repoPath={repoPath}
116
140
  runCommand={runCommand}
117
141
  editorFontFamily={editorFontFamily}
118
142
  editorTheme={editorTheme}
@@ -12,10 +12,10 @@
12
12
  * list to keep in sync — a command cannot be listed here and unbound there, and
13
13
  * a chord cannot be shown that does not work.
14
14
  *
15
- * Commands this editor deliberately does not have (folding, go-to-definition,
16
- * the `⌘K` prefix chords) are absent rather than listed and inert: a palette
17
- * entry that does nothing is worse than no entry, because the user concludes
18
- * the editor is broken rather than that the feature is missing.
15
+ * Commands this editor deliberately does not have (go-to-definition, the `⌘K`
16
+ * prefix chords) are absent rather than listed and inert: a palette entry that
17
+ * does nothing is worse than no entry, because the user concludes the editor is
18
+ * broken rather than that the feature is missing.
19
19
  */
20
20
 
21
21
  import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The write-conflict strip: "this file changed on disk".
8
+ *
9
+ * A save refused with `409` is not a failure — the buffer is intact and the disk
10
+ * holds someone else's bytes — so the panel cannot report it as one. It offers the
11
+ * two answers that actually exist:
12
+ *
13
+ * - **Reload** takes the disk copy and discards the buffer's edits.
14
+ * - **Keep mine** writes the buffer over it, adopting the disk mtime as the new
15
+ * base so the same refusal cannot come straight back.
16
+ *
17
+ * The strip sits above the document rather than in a modal: the user has to see
18
+ * what they are choosing between, and a modal over the editor hides it. It is
19
+ * also the reason the toolbar's save status stays `idle` on a conflict — two
20
+ * indicators for one event would disagree about whether the file was written.
21
+ */
22
+
23
+ import { AlertTriangle } from 'lucide-preact';
24
+
25
+ interface ConflictStripProps {
26
+ /** The mtime the disk holds now, or null when the refusal named none. */
27
+ diskMtimeMs: number | null;
28
+ fileName: string;
29
+ onReload: () => void;
30
+ onKeepMine: () => void;
31
+ }
32
+
33
+ /** `14:32:07` — the disk copy's own clock, so the two sides are comparable. */
34
+ function formatTime(mtimeMs: number | null): string | null {
35
+ if (mtimeMs === null) return null;
36
+ const date = new Date(mtimeMs);
37
+ if (Number.isNaN(date.getTime())) return null;
38
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
39
+ }
40
+
41
+ export function ConflictStrip({ diskMtimeMs, fileName, onReload, onKeepMine }: ConflictStripProps) {
42
+ const at = formatTime(diskMtimeMs);
43
+ return (
44
+ <div
45
+ className="flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-[11px] text-ink flex-shrink-0"
46
+ role="alert"
47
+ data-conflict-strip=""
48
+ >
49
+ <AlertTriangle size={13} className="text-warning flex-shrink-0 mt-0.5" />
50
+ <div className="min-w-0 flex-1">
51
+ <div className="font-medium">
52
+ <span className="font-mono">{fileName}</span> changed on disk
53
+ {at ? <span className="text-ink/60"> at {at}</span> : null}.
54
+ </div>
55
+ <div className="text-ink/60 mt-0.5">Your save was refused so nothing was overwritten.</div>
56
+ </div>
57
+ <div className="flex items-center gap-1 flex-shrink-0">
58
+ <button
59
+ type="button"
60
+ onClick={onReload}
61
+ className="px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer"
62
+ title="Discard my changes and take the file from disk"
63
+ >
64
+ Reload
65
+ </button>
66
+ <button
67
+ type="button"
68
+ onClick={onKeepMine}
69
+ className="px-2 py-1 rounded border border-warning/50 text-warning hover:bg-warning/10 transition-colors cursor-pointer"
70
+ title="Write my buffer over the file on disk"
71
+ >
72
+ Keep mine
73
+ </button>
74
+ </div>
75
+ </div>
76
+ );
77
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The two questions the editor panel can ask, in one place.
8
+ *
9
+ * Both are MODALS and both outlive a tab switch, which is why neither is owned by the
10
+ * component that raises it: the close confirmation is raised by the tab strip, and the
11
+ * deleted-file confirmation by the write path — and a tab switch must not dismiss a
12
+ * question the user has not answered.
13
+ *
14
+ * They are also mutually exclusive in practice (a save on a deleted file and a close on a
15
+ * dirty one cannot both be waiting), so drawing them together would stack two backdrops.
16
+ * The close confirmation wins, because it is the one that ends with a tab gone.
17
+ */
18
+
19
+ import { CloseDirtyTabModal } from '@/client/hooks/editor/use-unload-guard';
20
+ import { SaveDeletedFileModal } from '@/client/components/workspace/editor/SaveDeletedFileModal';
21
+ import type { CloseGuard } from '@/client/hooks/editor/use-close-guard';
22
+ import type { OpenedFile } from '@/shared/types/fs';
23
+
24
+ interface EditorDialogsProps {
25
+ closeGuard: CloseGuard;
26
+ activeFile: OpenedFile | undefined;
27
+ saveMissingConfirm: boolean;
28
+ onCancelSaveMissing: () => void;
29
+ onConfirmSaveMissing: () => void;
30
+ }
31
+
32
+ export function EditorDialogs({
33
+ closeGuard,
34
+ activeFile,
35
+ saveMissingConfirm,
36
+ onCancelSaveMissing,
37
+ onConfirmSaveMissing,
38
+ }: EditorDialogsProps) {
39
+ if (closeGuard.pending) {
40
+ return <CloseDirtyTabModal fileName={closeGuard.pending.name} onAnswer={closeGuard.answer} />;
41
+ }
42
+ if (saveMissingConfirm && activeFile) {
43
+ return (
44
+ <SaveDeletedFileModal
45
+ fileName={activeFile.name}
46
+ filePath={activeFile.path}
47
+ onClose={onCancelSaveMissing}
48
+ onConfirm={onConfirmSaveMissing}
49
+ />
50
+ );
51
+ }
52
+ return null;
53
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The editor column with nothing open.
8
+ *
9
+ * Its own component for the per-file ceiling, and because the sentence is a promise the
10
+ * panel has to keep: the column is open (the user toggled it) and there is no file in it,
11
+ * so the only thing to say is how to put one there.
12
+ */
13
+
14
+ import { FileIcon } from '@/client/components/common/file-icon';
15
+
16
+ export function EmptyEditor({ className = '' }: { className?: string }) {
17
+ return (
18
+ <div className={`flex flex-col h-full bg-canvas items-center justify-center text-ink/40 ${className}`}>
19
+ <FileIcon name="placeholder.txt" size={48} className="mb-4 opacity-20" />
20
+ <p className="font-mono text-sm">Select a file to open</p>
21
+ </div>
22
+ );
23
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The external-change strip: "this file changed on disk while you were editing".
8
+ *
9
+ * Distinct from `ConflictStrip` on purpose, and the difference is what the user can
10
+ * do. A CONFLICT is a save the server refused — the buffer is still ahead and the
11
+ * choice is which side wins. This is the earlier warning: the disk moved and the
12
+ * buffer has NOT been written, so the choice is "take theirs now" or "keep editing
13
+ * mine". Both offer Reload/Keep, and neither is a modal: the user has to see the
14
+ * file they are choosing about.
15
+ */
16
+
17
+ import { RefreshCw } from 'lucide-preact';
18
+
19
+ interface ExternalChangeStripProps {
20
+ fileName: string;
21
+ onReload: () => void;
22
+ onKeepMine: () => void;
23
+ }
24
+
25
+ export function ExternalChangeStrip({ fileName, onReload, onKeepMine }: ExternalChangeStripProps) {
26
+ return (
27
+ <div
28
+ className="flex items-start gap-2 px-3 py-2 border-b border-info/30 bg-info/10 text-[11px] text-ink flex-shrink-0"
29
+ role="status"
30
+ data-external-change-strip=""
31
+ >
32
+ <RefreshCw size={13} className="text-info flex-shrink-0 mt-0.5" />
33
+ <div className="min-w-0 flex-1">
34
+ <div className="font-medium">
35
+ <span className="font-mono">{fileName}</span> changed on disk.
36
+ </div>
37
+ <div className="text-ink/60 mt-0.5">
38
+ Reload takes the disk copy and discards your edits. Keep mine writes yours over it.
39
+ </div>
40
+ </div>
41
+ <div className="flex items-center gap-1 flex-shrink-0">
42
+ <button
43
+ type="button"
44
+ onClick={onReload}
45
+ className="px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer"
46
+ title="Take the file from disk"
47
+ >
48
+ Reload
49
+ </button>
50
+ <button
51
+ type="button"
52
+ onClick={onKeepMine}
53
+ className="px-2 py-1 rounded border border-info/50 text-info hover:bg-info/10 transition-colors cursor-pointer"
54
+ title="Keep my buffer; the next save writes it"
55
+ >
56
+ Keep mine
57
+ </button>
58
+ </div>
59
+ </div>
60
+ );
61
+ }