@kabmo-labs/kabmo 0.14.0 → 0.15.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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/static/js/index-28pwtt69.css +1 -0
- package/dist/client/static/js/{index-nfsg1jpt.js → index-mx658m43.js} +624 -624
- package/marketplace/plugins/command-runner/README.md +5 -3
- package/marketplace/plugins/command-runner/package.json +2 -2
- package/marketplace/plugins/command-runner/src/app.tsx +3 -3
- package/marketplace/plugins/command-runner/src/panel/Groups.test.tsx +25 -21
- package/marketplace/plugins/command-runner/src/panel/Groups.tsx +4 -1
- package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
- package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
- package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
- package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
- package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
- package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
- package/package.json +2 -2
- package/src/client/components/common/session-row/index.tsx +11 -1
- package/src/client/components/common/session-row/session-row.test.tsx +10 -0
- package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +5 -4
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +11 -2
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
- package/src/client/components/mobile/LayoutWrapper.tsx +11 -10
- package/src/client/components/mobile/open-file-payload.test.ts +29 -1
- package/src/client/components/mobile/open-file-payload.ts +28 -0
- package/src/client/components/settings/Modal.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +10 -9
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +21 -1
- package/src/client/components/workspace/editor/index.tsx +6 -8
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
- package/src/client/components/workspace/git-panel/branch-modal/index.tsx +4 -3
- package/src/client/components/workspace/git-panel/commit-modal/index.tsx +1 -1
- package/src/client/hooks/chat/timeline/index.ts +3 -6
- package/src/client/hooks/chat/timeline/jump-landing.ts +121 -0
- package/src/client/hooks/chat/timeline/jump-rail.ts +19 -10
- package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
- package/src/client/hooks/chat/timeline/row-window.ts +100 -134
- package/src/client/hooks/chat/timeline/scroll-probe.test-util.ts +23 -10
- package/src/client/hooks/chat/timeline/scroll.test.ts +61 -4
- package/src/client/hooks/chat/timeline/scroll.ts +77 -26
- package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
- package/src/client/hooks/workspace/missing-files.test.ts +20 -3
- package/src/client/hooks/workspace/missing-files.ts +41 -7
- package/src/client/tailwind.css +12 -1
- package/src/server/routes/fs/exists.test.ts +26 -1
- package/src/shared/lib/chat/timeline/trace-groups.test.ts +12 -0
- package/src/shared/lib/chat/timeline/trace-groups.ts +29 -2
- package/src/shared/lib/workspace/session-state/store.ts +5 -0
- package/dist/client/static/js/index-tsgy3gd1.css +0 -1
|
@@ -78,8 +78,10 @@ export interface ScrollProbe {
|
|
|
78
78
|
StubResizeObserver: typeof StubResizeObserver;
|
|
79
79
|
/** Preact's test-utils `act`, loaded after the DOM globals exist. */
|
|
80
80
|
act: typeof PreactAct;
|
|
81
|
-
/** Drain the deferred frames the hook scheduled.
|
|
82
|
-
|
|
81
|
+
/** Drain the deferred frames the hook scheduled. `rounds` runs the queue
|
|
82
|
+
* again for callbacks those frames scheduled themselves (a per-frame watch),
|
|
83
|
+
* which is the only way a multi-frame loop advances without a real clock. */
|
|
84
|
+
flushFrames(rounds?: number): Promise<void>;
|
|
83
85
|
message(id: string): ChatMessageData;
|
|
84
86
|
mountProbe(sessionId: string, messages: ChatMessageData[]): Promise<ProbeHandle>;
|
|
85
87
|
updateProbe(probe: ProbeHandle, sessionId: string, messages: ChatMessageData[]): Promise<void>;
|
|
@@ -158,7 +160,11 @@ export async function setupScrollProbe(): Promise<ScrollProbe> {
|
|
|
158
160
|
enabled: true,
|
|
159
161
|
});
|
|
160
162
|
props.holder.current = scroll;
|
|
161
|
-
|
|
163
|
+
// `scrollNodeRef`, not `scrollRef`: the product uses it, and it is what
|
|
164
|
+
// publishes the scroller as state for the subscriptions (the reader-input
|
|
165
|
+
// listeners, the row window). A probe on the bare ref subscribes to
|
|
166
|
+
// nothing, which is a state the product cannot be in.
|
|
167
|
+
return h('div', { ref: scroll.scrollNodeRef, onScroll: scroll.handleScroll },
|
|
162
168
|
h('div', { ref: scroll.contentRef }));
|
|
163
169
|
}
|
|
164
170
|
|
|
@@ -173,6 +179,11 @@ export async function setupScrollProbe(): Promise<ScrollProbe> {
|
|
|
173
179
|
await act(async () => { render(h(Probe, { sessionId, messages, holder }), node); });
|
|
174
180
|
const el = holder.current!.scrollRef.current!;
|
|
175
181
|
installScroller(el);
|
|
182
|
+
// A browser runs the frames a mount scheduled; the fake platform does not,
|
|
183
|
+
// so drain them here. Without this the open jump's landing watch is still
|
|
184
|
+
// armed when the test's first assertion runs, which is a state the product
|
|
185
|
+
// never stays in.
|
|
186
|
+
await flushFrames(8);
|
|
176
187
|
return { holder, node, el };
|
|
177
188
|
}
|
|
178
189
|
|
|
@@ -181,6 +192,7 @@ export async function setupScrollProbe(): Promise<ScrollProbe> {
|
|
|
181
192
|
await act(async () => {
|
|
182
193
|
render(h(Probe, { sessionId, messages, holder: probe.holder }), probe.node);
|
|
183
194
|
});
|
|
195
|
+
await flushFrames(8);
|
|
184
196
|
}
|
|
185
197
|
|
|
186
198
|
async function unmountProbe(probe: ProbeHandle) {
|
|
@@ -196,14 +208,15 @@ export async function setupScrollProbe(): Promise<ScrollProbe> {
|
|
|
196
208
|
* that fires an observer has to let the frame it scheduled run before the
|
|
197
209
|
* geometry it asserts on has been applied.
|
|
198
210
|
*/
|
|
199
|
-
async function flushFrames() {
|
|
200
|
-
for (let
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
async function flushFrames(rounds = 1) {
|
|
212
|
+
for (let round = 0; round < rounds; round++) {
|
|
213
|
+
const scheduled = pendingFrames.splice(0, pendingFrames.length);
|
|
214
|
+
if (scheduled.length === 0) return;
|
|
215
|
+
for (const callback of scheduled) {
|
|
216
|
+
if (!callback) continue;
|
|
217
|
+
await act(async () => { callback(); });
|
|
218
|
+
}
|
|
205
219
|
}
|
|
206
|
-
pendingFrames.length = 0;
|
|
207
220
|
}
|
|
208
221
|
|
|
209
222
|
function teardown() {
|
|
@@ -81,7 +81,9 @@ describe('timeline scroll', () => {
|
|
|
81
81
|
expect(scroll().jumpCountRef.current).toBe(1);
|
|
82
82
|
expect(scroll().jumpActiveRef.current).toBe(true);
|
|
83
83
|
|
|
84
|
-
// The user reads back
|
|
84
|
+
// The user reads back (a wheel, then the viewport moves up). A stream chunk
|
|
85
|
+
// must not yank it down...
|
|
86
|
+
await p.act(() => { probe.el.dispatchEvent(new Event('wheel')); });
|
|
85
87
|
probe.el.scrollTop = 100;
|
|
86
88
|
expect(scroll().followRef.current).toBe(false);
|
|
87
89
|
p.scrolled.length = 0;
|
|
@@ -97,20 +99,75 @@ describe('timeline scroll', () => {
|
|
|
97
99
|
await p.unmountProbe(probe);
|
|
98
100
|
});
|
|
99
101
|
|
|
100
|
-
test('the jump guard releases
|
|
102
|
+
test('the jump guard releases when the landing SETTLES, not on a clock', async () => {
|
|
101
103
|
p.scrolled.length = 0;
|
|
102
104
|
p.geometry.top = 0;
|
|
103
105
|
p.geometry.height = 5000;
|
|
104
106
|
const probe = await p.mountProbe('a', [p.message('a1')]);
|
|
105
107
|
const scroll = () => probe.holder.current!;
|
|
106
108
|
|
|
109
|
+
// A long session on a slow device is still animating seconds later. A guard
|
|
110
|
+
// released by a timer here is a guard released mid-flight: the paging
|
|
111
|
+
// trigger it was holding off then fires at the top of history, and the
|
|
112
|
+
// window it pages is one the jump must outrun.
|
|
107
113
|
fakeTimers.useFakeTimers();
|
|
114
|
+
await p.act(() => { scroll().jumpToBottom('smooth'); });
|
|
115
|
+
expect(scroll().jumpActiveRef.current).toBe(true);
|
|
116
|
+
await p.act(() => { fakeTimers.advanceTimersByTime(10_000); });
|
|
117
|
+
expect(scroll().jumpActiveRef.current).toBe(true);
|
|
118
|
+
fakeTimers.useRealTimers();
|
|
119
|
+
|
|
120
|
+
// Landed: the guard lets go, so history paging is not blocked for good.
|
|
121
|
+
await p.act(() => { probe.el.scrollTo({ top: p.geometry.height, behavior: 'instant' }); });
|
|
122
|
+
await p.flushFrames(6);
|
|
123
|
+
expect(scroll().jumpActiveRef.current).toBe(false);
|
|
124
|
+
await p.unmountProbe(probe);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a jump that lands short re-aims instead of leaving the button up', async () => {
|
|
128
|
+
p.scrolled.length = 0;
|
|
129
|
+
p.geometry.top = 0;
|
|
130
|
+
p.geometry.height = 5000;
|
|
131
|
+
const probe = await p.mountProbe('a', [p.message('a1')]);
|
|
132
|
+
const scroll = () => probe.holder.current!;
|
|
133
|
+
|
|
134
|
+
// A smooth scroll that never moves: the browser dropped it because the rows
|
|
135
|
+
// it was scrolling through were replaced by the mounted window. This is the
|
|
136
|
+
// reported "the button does nothing until I scroll the rest myself".
|
|
137
|
+
p.scrolled.length = 0;
|
|
138
|
+
await p.act(() => { scroll().jumpToBottom('smooth'); });
|
|
139
|
+
expect(p.scrolled.length).toBe(1);
|
|
140
|
+
expect(probe.el.scrollTop).toBe(0);
|
|
141
|
+
|
|
142
|
+
await p.flushFrames(8);
|
|
143
|
+
// The watch re-aimed on its own rather than giving up.
|
|
144
|
+
expect(p.scrolled.length).toBeGreaterThan(1);
|
|
145
|
+
expect(p.scrolled.at(-1)?.top).toBe(p.geometry.height);
|
|
146
|
+
await p.unmountProbe(probe);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('a layout clamp may not cancel a jump in flight; real input still may', async () => {
|
|
150
|
+
p.scrolled.length = 0;
|
|
151
|
+
p.geometry.top = 0;
|
|
152
|
+
p.geometry.height = 5000;
|
|
153
|
+
const probe = await p.mountProbe('a', [p.message('a1')]);
|
|
154
|
+
const scroll = () => probe.holder.current!;
|
|
155
|
+
|
|
108
156
|
await p.act(() => { scroll().jumpToBottom('instant'); });
|
|
109
157
|
expect(scroll().jumpActiveRef.current).toBe(true);
|
|
110
158
|
|
|
111
|
-
|
|
159
|
+
// A measurement replaced an estimate with a taller height and the browser
|
|
160
|
+
// clamped `scrollTop` UP. Nobody touched the scroller: the jump stands.
|
|
161
|
+
probe.el.scrollTop = 300;
|
|
162
|
+
expect(scroll().followRef.current).toBe(true);
|
|
163
|
+
expect(scroll().jumpActiveRef.current).toBe(true);
|
|
164
|
+
|
|
165
|
+
// The reader themselves: a wheel, then the viewport moves up. The jump must
|
|
166
|
+
// stand down rather than keep pulling the tail under them.
|
|
167
|
+
await p.act(() => { probe.el.dispatchEvent(new Event('wheel')); });
|
|
168
|
+
probe.el.scrollTop = 100;
|
|
169
|
+
expect(scroll().followRef.current).toBe(false);
|
|
112
170
|
expect(scroll().jumpActiveRef.current).toBe(false);
|
|
113
|
-
fakeTimers.useRealTimers();
|
|
114
171
|
await p.unmountProbe(probe);
|
|
115
172
|
});
|
|
116
173
|
|
|
@@ -21,14 +21,25 @@
|
|
|
21
21
|
* button, re-engages it. Programmatic jumps (`scrollTo`) never flip the mode.
|
|
22
22
|
*
|
|
23
23
|
* `jumpToBottom` is the unconditional bypass (`follow` is re-engaged, geometry
|
|
24
|
-
* is re-baselined, and the paging trigger stands down
|
|
25
|
-
* button's jump, the open-session jump, and the send jump all
|
|
26
|
-
* `follow` lives across session switches, so an open jump that
|
|
27
|
-
* simply refused for a session opened after the user had
|
|
24
|
+
* is re-baselined, and the paging trigger stands down until the landing
|
|
25
|
+
* settles) — the button's jump, the open-session jump, and the send jump all
|
|
26
|
+
* go through it. `follow` lives across session switches, so an open jump that
|
|
27
|
+
* honoured it was simply refused for a session opened after the user had
|
|
28
|
+
* scrolled up.
|
|
29
|
+
*
|
|
30
|
+
* A jump OWNS the viewport until it has actually landed, the same way
|
|
31
|
+
* `revealRow` owns it while it flies. The timeline mounts a window of its rows
|
|
32
|
+
* and ESTIMATES the rest, so `scrollHeight` changes while a jump mounts the
|
|
33
|
+
* rows it passes over — the target it was issued against is stale before the
|
|
34
|
+
* animation ends. The jump watch therefore re-reads the geometry every frame
|
|
35
|
+
* and re-aims until the viewport has SAT at the tail; the content observer and
|
|
36
|
+
* the row window stand down meanwhile, so no measurement drags the landing
|
|
37
|
+
* back. See `createJumpLanding` for what each state means.
|
|
28
38
|
*/
|
|
29
39
|
|
|
30
40
|
import type { RefObject } from 'preact/compat';
|
|
31
41
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
42
|
+
import { createJumpLanding, type JumpLanding } from '@/client/hooks/chat/timeline/jump-landing';
|
|
32
43
|
|
|
33
44
|
/** Distance from the tail, in pixels, that still counts as "at the bottom". */
|
|
34
45
|
const FOLLOW_BOTTOM_THRESHOLD_PX = 100;
|
|
@@ -47,12 +58,11 @@ const FOLLOW_BOTTOM_THRESHOLD_PX = 100;
|
|
|
47
58
|
*/
|
|
48
59
|
const COMPACT_TRIGGER_PX = FOLLOW_BOTTOM_THRESHOLD_PX + 64;
|
|
49
60
|
|
|
50
|
-
/** How long a
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
const JUMP_SETTLE_MS = 1000;
|
|
61
|
+
/** How long after a wheel/touch/pointer/key event an upward scroll still
|
|
62
|
+
* counts as the READER's. Only consulted while a jump is landing: a layout
|
|
63
|
+
* clamp moves `scrollTop` up with nobody behind it, and treating that as the
|
|
64
|
+
* reader taking the viewport back is what cancelled a jump mid-flight. */
|
|
65
|
+
const READER_INPUT_WINDOW_MS = 600;
|
|
56
66
|
|
|
57
67
|
export interface ChatTimelineScrollOptions {
|
|
58
68
|
/** Called when the viewport reaches the top (history paging trigger).
|
|
@@ -97,8 +107,10 @@ export interface ChatTimelineScrollResult {
|
|
|
97
107
|
* over the jump (reproduced: the jump stopped ~26k px short of the tail and
|
|
98
108
|
* only the next click reached it, once no window was left to page in). */
|
|
99
109
|
jumpCountRef: RefObject<number>;
|
|
100
|
-
/** True while a bottom jump is
|
|
101
|
-
* paging stands down
|
|
110
|
+
/** True while a bottom jump is landing: the jump owns the viewport, so
|
|
111
|
+
* history paging stands down and neither the content observer nor the row
|
|
112
|
+
* window writes a position under it. Released once the viewport has SAT at
|
|
113
|
+
* the tail (see `createJumpLanding`), never on a fixed timer. */
|
|
102
114
|
jumpActiveRef: RefObject<boolean>;
|
|
103
115
|
handleScroll: () => void;
|
|
104
116
|
scrollToBottom: (behavior?: ScrollBehavior) => void;
|
|
@@ -110,10 +122,6 @@ export interface ChatTimelineScrollResult {
|
|
|
110
122
|
/** Distance from the top that counts as "reached the history boundary". */
|
|
111
123
|
const SCROLL_TOP_TRIGGER_PX = 40;
|
|
112
124
|
|
|
113
|
-
/** Pending timeout handle. Named here rather than re-derived per ref because
|
|
114
|
-
* the DOM and Bun/Node typings disagree on what `setTimeout` returns. */
|
|
115
|
-
type TimeoutHandle = ReturnType<typeof setTimeout>;
|
|
116
|
-
|
|
117
125
|
export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}): ChatTimelineScrollResult {
|
|
118
126
|
const onScrollTopRef = useRef<(() => void) | undefined>(options.onScrollTop);
|
|
119
127
|
onScrollTopRef.current = options.onScrollTop ?? onScrollTopRef.current;
|
|
@@ -144,7 +152,14 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
144
152
|
// Bottom-jump bookkeeping; see ChatTimelineScrollResult for each ref.
|
|
145
153
|
const jumpCountRef = useRef(0);
|
|
146
154
|
const jumpActiveRef = useRef(false);
|
|
147
|
-
|
|
155
|
+
// The landing watch: owns the viewport until the jump has landed.
|
|
156
|
+
const landingRef = useRef<JumpLanding | null>(null);
|
|
157
|
+
// Last time the READER touched the scroller (wheel, touch, pointer, key).
|
|
158
|
+
// `scrollTop` moving up is not enough to tell them from a layout clamp.
|
|
159
|
+
// `-Infinity`, not `0`: the window is compared against `performance.now()`,
|
|
160
|
+
// which starts near zero, so a zero sentinel would read as input on the first
|
|
161
|
+
// moments of a page load.
|
|
162
|
+
const readerInputAtRef = useRef(Number.NEGATIVE_INFINITY);
|
|
148
163
|
|
|
149
164
|
const contentRef = useCallback((node: HTMLDivElement | null) => {
|
|
150
165
|
setContentNode(node);
|
|
@@ -183,10 +198,17 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
183
198
|
// mid-animation as content outgrows the animation. Re-engage whenever
|
|
184
199
|
// the viewport is back near the tail, whichever way it got there.
|
|
185
200
|
if (el.scrollTop < lastScrollTopRef.current - 1) {
|
|
186
|
-
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
|
|
201
|
+
// An upward move is not automatically the reader's: the row window
|
|
202
|
+
// replacing estimates with measured heights CLAMPS `scrollTop` up, and
|
|
203
|
+
// while a jump is landing that clamp used to cancel the jump outright —
|
|
204
|
+
// the animation stopped mid-flight, the button stayed up, and only the
|
|
205
|
+
// next click (or scrolling the rest of the way by hand) reached the
|
|
206
|
+
// tail. While the guard is up, only real input takes the viewport back.
|
|
207
|
+
const reader = performance.now() - readerInputAtRef.current < READER_INPUT_WINDOW_MS;
|
|
208
|
+
if (!jumpActiveRef.current || reader) {
|
|
209
|
+
followRef.current = false;
|
|
210
|
+
jumpActiveRef.current = false;
|
|
211
|
+
}
|
|
190
212
|
}
|
|
191
213
|
if (el.scrollHeight - el.scrollTop - el.clientHeight < FOLLOW_BOTTOM_THRESHOLD_PX) followRef.current = true;
|
|
192
214
|
lastScrollTopRef.current = el.scrollTop;
|
|
@@ -197,6 +219,14 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
197
219
|
syncFollowBottom();
|
|
198
220
|
}, [syncFollowBottom]);
|
|
199
221
|
|
|
222
|
+
/** The landing watch, created on first use. Lazily, because the open-session
|
|
223
|
+
* jump runs from a LAYOUT effect — before this hook's own passive effects —
|
|
224
|
+
* and a watch created there must not be replaced by a second one later. */
|
|
225
|
+
const landing = useCallback((): JumpLanding => {
|
|
226
|
+
landingRef.current ??= createJumpLanding({ scrollRef, jumpActiveRef, pinToBottom });
|
|
227
|
+
return landingRef.current;
|
|
228
|
+
}, [pinToBottom]);
|
|
229
|
+
|
|
200
230
|
const scrollToBottom = useCallback((behavior: ScrollBehavior = 'smooth') => {
|
|
201
231
|
// Follow-gated: a stream chunk in read mode (user scrolled away) must not
|
|
202
232
|
// yank the viewport down. jumpToBottom is the explicit bypass.
|
|
@@ -209,10 +239,12 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
209
239
|
followRef.current = true;
|
|
210
240
|
jumpActiveRef.current = true;
|
|
211
241
|
jumpCountRef.current += 1;
|
|
212
|
-
|
|
213
|
-
|
|
242
|
+
// The click that starts a jump is not a scroll input: the reader has not
|
|
243
|
+
// taken the viewport back, so a clamp right after this must not cancel it.
|
|
244
|
+
readerInputAtRef.current = Number.NEGATIVE_INFINITY;
|
|
245
|
+
landing().start();
|
|
214
246
|
pinToBottom(behavior);
|
|
215
|
-
}, [pinToBottom]);
|
|
247
|
+
}, [landing, pinToBottom]);
|
|
216
248
|
|
|
217
249
|
// Geometry, not events: content that grows without the user scrolling
|
|
218
250
|
// (history prepending, an accordion expanding, an image decoding, a late
|
|
@@ -255,7 +287,10 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
255
287
|
if (frame !== null) return;
|
|
256
288
|
frame = requestAnimationFrame(() => {
|
|
257
289
|
frame = null;
|
|
258
|
-
|
|
290
|
+
// A jump in flight owns the position: its watch re-aims at the tail
|
|
291
|
+
// itself, and a pin from here would replace a smooth landing with an
|
|
292
|
+
// instant snap on every measurement along the way.
|
|
293
|
+
if (followRef.current && !jumpActiveRef.current) pinToBottom('instant');
|
|
259
294
|
syncFollowBottom();
|
|
260
295
|
});
|
|
261
296
|
});
|
|
@@ -267,8 +302,24 @@ export function useChatTimelineScroll(options: ChatTimelineScrollOptions = {}):
|
|
|
267
302
|
};
|
|
268
303
|
}, [contentNode, scrollNode, pinToBottom, syncFollowBottom]);
|
|
269
304
|
|
|
305
|
+
// What counts as the reader having taken the viewport back, for
|
|
306
|
+
// `handleScroll`'s upward-scroll test. Wired on the scroller NODE (state, not
|
|
307
|
+
// the ref — the surface is swapped in a commit late), because a wheel, a
|
|
308
|
+
// finger or a key only ever arrives there.
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (!scrollNode) return;
|
|
311
|
+
const note = () => {
|
|
312
|
+
readerInputAtRef.current = performance.now();
|
|
313
|
+
};
|
|
314
|
+
const types = ['wheel', 'touchstart', 'touchmove', 'pointerdown', 'keydown'] as const;
|
|
315
|
+
for (const type of types) scrollNode.addEventListener(type, note, { passive: true });
|
|
316
|
+
return () => {
|
|
317
|
+
for (const type of types) scrollNode.removeEventListener(type, note);
|
|
318
|
+
};
|
|
319
|
+
}, [scrollNode]);
|
|
320
|
+
|
|
270
321
|
useEffect(() => () => {
|
|
271
|
-
|
|
322
|
+
landingRef.current?.stop();
|
|
272
323
|
}, []);
|
|
273
324
|
|
|
274
325
|
return {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether a thinking block is open, remembered per session and per message.
|
|
8
|
+
*
|
|
9
|
+
* The accordion kept this in a plain `useState`, and that was survivable while
|
|
10
|
+
* every row stayed mounted for the life of the session. It is not survivable
|
|
11
|
+
* now: `MessageList` mounts a WINDOW of rows (`useTimelineRowWindow`), so a
|
|
12
|
+
* block is unmounted whenever the window moves past it — which an expand does
|
|
13
|
+
* by itself, because the row it opens grows and the reader parked at the tail
|
|
14
|
+
* follows the new bottom. Measured in the browser on a real session: the click
|
|
15
|
+
* opened the body, the next measurement moved the viewport, the row unmounted
|
|
16
|
+
* and remounted with a fresh `useState(false)`, and the block was closed again
|
|
17
|
+
* — "sometimes it works" being exactly the case where enough content sat below
|
|
18
|
+
* the row to keep it mounted.
|
|
19
|
+
*
|
|
20
|
+
* The tool cards already answer this by persisting their openness per session
|
|
21
|
+
* (`useToolOpenState`), so this is the same rule for the same reason, not a
|
|
22
|
+
* second convention: a block's open state belongs to the conversation.
|
|
23
|
+
*
|
|
24
|
+
* Only a choice the reader MADE is stored. A generating run opens by default,
|
|
25
|
+
* and writing that default per block would put a row in the session blob for
|
|
26
|
+
* every thought the model produced.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
30
|
+
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
31
|
+
|
|
32
|
+
/** Session slot holding `{ [messageId]: open }` for the blocks the reader toggled. */
|
|
33
|
+
export const THINKING_OPEN_STATE_KEY = 'chat.thinkingOpen';
|
|
34
|
+
|
|
35
|
+
export interface ThinkingOpenState {
|
|
36
|
+
isOpen: boolean;
|
|
37
|
+
toggle: () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* `messageId` is optional so a block mounted outside a session (a spec, a
|
|
42
|
+
* preview) still toggles — it just cannot remember the choice.
|
|
43
|
+
*/
|
|
44
|
+
export function useThinkingOpenState(
|
|
45
|
+
messageId: string | undefined,
|
|
46
|
+
defaultOpen: boolean,
|
|
47
|
+
isGenerating: boolean,
|
|
48
|
+
): ThinkingOpenState {
|
|
49
|
+
const [stored, setStored] = useSessionState<Record<string, boolean>>(THINKING_OPEN_STATE_KEY, {});
|
|
50
|
+
const [local, setLocal] = useState(defaultOpen || isGenerating);
|
|
51
|
+
const choice = messageId ? stored[messageId] : undefined;
|
|
52
|
+
|
|
53
|
+
// A run that starts streaming opens itself, as it always has. This is the
|
|
54
|
+
// local half on purpose: the stored half is the reader's own choice, and it
|
|
55
|
+
// must not be overwritten by a default.
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (isGenerating) setLocal(true);
|
|
58
|
+
}, [isGenerating]);
|
|
59
|
+
|
|
60
|
+
const isOpen = choice ?? local;
|
|
61
|
+
const toggle = (): void => {
|
|
62
|
+
const next = !isOpen;
|
|
63
|
+
setLocal(next);
|
|
64
|
+
if (messageId) setStored((prev) => ({ ...prev, [messageId]: next }));
|
|
65
|
+
};
|
|
66
|
+
return { isOpen, toggle };
|
|
67
|
+
}
|
|
@@ -24,7 +24,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } fr
|
|
|
24
24
|
import { Window } from 'happy-dom';
|
|
25
25
|
import type { h as PreactH, render as PreactRender } from 'preact';
|
|
26
26
|
import type { act as PreactAct } from 'preact/test-utils';
|
|
27
|
-
import type { OpenTabScope, useMissingFiles as UseMissingFilesHook } from '@/client/hooks/workspace/missing-files';
|
|
27
|
+
import type { OpenTabScope, ProbeableTab, useMissingFiles as UseMissingFilesHook } from '@/client/hooks/workspace/missing-files';
|
|
28
28
|
|
|
29
29
|
let useMissingFiles: typeof UseMissingFilesHook;
|
|
30
30
|
let openTabScopeKey: (tab: OpenTabScope) => string;
|
|
@@ -66,8 +66,8 @@ async function settle() {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
async function mount(tabs:
|
|
70
|
-
const Probe = ({ tabs: current, refreshKey: key }: { tabs:
|
|
69
|
+
async function mount(tabs: ProbeableTab[], refreshKey = 0) {
|
|
70
|
+
const Probe = ({ tabs: current, refreshKey: key }: { tabs: ProbeableTab[]; refreshKey: number }) => {
|
|
71
71
|
mounted = useMissingFiles(current, key);
|
|
72
72
|
return null;
|
|
73
73
|
};
|
|
@@ -168,6 +168,23 @@ describe('useMissingFiles', () => {
|
|
|
168
168
|
expect([...(mounted ?? [])]).toEqual([1]);
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
+
test('a tab with no server-backed file is never probed', async () => {
|
|
172
|
+
// Measured on a phone: opening an attachment chip, a launched document or a
|
|
173
|
+
// file in a nested repo struck it through as deleted, because the caller
|
|
174
|
+
// filtered these itself and the phone's caller forgot. The rule now lives in
|
|
175
|
+
// `isProbeableTab`, so this asserts the SKIP for every such tab.
|
|
176
|
+
await mount([
|
|
177
|
+
{ id: 'chip', path: 'notes.md', content: '# inline' },
|
|
178
|
+
{ id: 'handle', path: 'launched.md', handleId: 'handle-1' },
|
|
179
|
+
{ id: 'device', path: 'report.md', deviceFile: true },
|
|
180
|
+
{ id: 'diff', path: 'src/a.ts', isDiff: true },
|
|
181
|
+
{ id: 'plain', path: 'src/a.ts' },
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
expect(probes.map((p) => p.path)).toEqual(['src/a.ts']);
|
|
185
|
+
expect([...(mounted ?? [])]).toEqual(['plain']);
|
|
186
|
+
});
|
|
187
|
+
|
|
171
188
|
test('the scope key keeps two trees apart', () => {
|
|
172
189
|
expect(openTabScopeKey({ id: 1, path: 'a.ts', root: '/ws', repo: '.' })).not.toBe(
|
|
173
190
|
openTabScopeKey({ id: 1, path: 'a.ts', root: '/ws', repo: 'projects/b' }),
|
|
@@ -36,6 +36,38 @@ export interface OpenTabScope {
|
|
|
36
36
|
repo?: string;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* An open tab as a layout holds it: the scope above, plus the facts that decide
|
|
41
|
+
* whether a probe can say anything true about the file behind it.
|
|
42
|
+
*/
|
|
43
|
+
export interface ProbeableTab extends OpenTabScope {
|
|
44
|
+
/** Inline bytes — an attachment chip is a name AND its content, not a file on disk. */
|
|
45
|
+
content?: string;
|
|
46
|
+
/** A launched/dropped file's live handle: no server path exists to `stat`. */
|
|
47
|
+
handleId?: string;
|
|
48
|
+
/** The bytes came from the DEVICE, so there is no path the server can reach. */
|
|
49
|
+
deviceFile?: boolean;
|
|
50
|
+
/** A diff tab's path names a CHANGE, not a document. */
|
|
51
|
+
isDiff?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether a probe about this tab means anything.
|
|
56
|
+
*
|
|
57
|
+
* The answer lives HERE, once, because the two layouts that ask it — the desktop
|
|
58
|
+
* tab strip and the phone's full-screen editor — disagreed: the desktop skipped
|
|
59
|
+
* a tab carrying inline `content` and the phone did not, so every attachment
|
|
60
|
+
* chip and every device/handle file opened on a phone was struck through as
|
|
61
|
+
* deleted while its buffer was on screen and perfectly fine. A predicate stated
|
|
62
|
+
* twice is how that happens; neither caller filters on its own any more.
|
|
63
|
+
*/
|
|
64
|
+
export function isProbeableTab(tab: ProbeableTab): boolean {
|
|
65
|
+
if (!tab.path) return false;
|
|
66
|
+
if (tab.content !== undefined) return false;
|
|
67
|
+
if (tab.handleId || tab.deviceFile) return false;
|
|
68
|
+
return !tab.isDiff;
|
|
69
|
+
}
|
|
70
|
+
|
|
39
71
|
/** The scope key a probe's verdict is stored under. Exported for its test. */
|
|
40
72
|
export function openTabScopeKey(tab: OpenTabScope): string {
|
|
41
73
|
return `${tab.root ?? ''}\u0000${tab.repo ?? '.'}\u0000${tab.path ?? ''}`;
|
|
@@ -66,11 +98,13 @@ async function probeExists(tab: OpenTabScope): Promise<boolean> {
|
|
|
66
98
|
* The tab ids whose file is gone.
|
|
67
99
|
*
|
|
68
100
|
* `refreshKey` is the workspace's own "something was written" counter, so a
|
|
69
|
-
* delete issued from any panel reaches here without a poll.
|
|
70
|
-
*
|
|
71
|
-
* behind their `path`, and probing
|
|
101
|
+
* delete issued from any panel reaches here without a poll. Which tabs can be
|
|
102
|
+
* probed at all is decided HERE (`isProbeableTab`), not at each call site: a
|
|
103
|
+
* diff tab and an attachment chip have no file behind their `path`, and probing
|
|
104
|
+
* one would strike it through on sight — a rule the two layouts used to apply
|
|
105
|
+
* differently, so the phone struck through files the desktop left alone.
|
|
72
106
|
*/
|
|
73
|
-
export function useMissingFiles(tabs: readonly
|
|
107
|
+
export function useMissingFiles(tabs: readonly ProbeableTab[], refreshKey: number): Set<number | string> {
|
|
74
108
|
const [missing, setMissing] = useState<Set<number | string>>(() => new Set());
|
|
75
109
|
// Bumped by a focus or a visibility change: the effect below owns the probe,
|
|
76
110
|
// and re-running it is the whole repair for an external deletion.
|
|
@@ -88,9 +122,9 @@ export function useMissingFiles(tabs: readonly OpenTabScope[], refreshKey: numbe
|
|
|
88
122
|
useEffect(() => {
|
|
89
123
|
let cancelled = false;
|
|
90
124
|
void (async () => {
|
|
91
|
-
const probes = new Map<string,
|
|
125
|
+
const probes = new Map<string, ProbeableTab>();
|
|
92
126
|
for (const tab of tabsRef.current) {
|
|
93
|
-
if (tab
|
|
127
|
+
if (isProbeableTab(tab)) probes.set(openTabScopeKey(tab), tab);
|
|
94
128
|
}
|
|
95
129
|
const results = await Promise.all(
|
|
96
130
|
[...probes.entries()].map(async ([key, tab]) => ({ key, exists: await probeExists(tab) })),
|
|
@@ -102,7 +136,7 @@ export function useMissingFiles(tabs: readonly OpenTabScope[], refreshKey: numbe
|
|
|
102
136
|
|
|
103
137
|
const next = new Set<number | string>();
|
|
104
138
|
for (const tab of tabsRef.current) {
|
|
105
|
-
if (tab
|
|
139
|
+
if (isProbeableTab(tab) && gone.has(openTabScopeKey(tab))) next.add(tab.id);
|
|
106
140
|
}
|
|
107
141
|
// A fresh Set only when the verdict moved: the tab strip is cheap, but a
|
|
108
142
|
// new identity on every probe would re-render it for nothing.
|
package/src/client/tailwind.css
CHANGED
|
@@ -404,11 +404,22 @@
|
|
|
404
404
|
padding-inline: 1rem;
|
|
405
405
|
padding-top: 0.875rem;
|
|
406
406
|
}
|
|
407
|
+
/* STRETCHED, the frosted card covers the transcript instead of sitting under
|
|
408
|
+
* it, so 58% paper stops being a surface and becomes a veil: message text
|
|
409
|
+
* reads through the draft at 42% and the two layers merge (measured: the
|
|
410
|
+
* expanded desktop card overlapped timeline rows at 58% with `blur(16px)`).
|
|
411
|
+
* The stretch exists to write a long prompt against that transcript, so the
|
|
412
|
+
* card must win the overlap — 92% paper keeps the tint and the blurred edge
|
|
413
|
+
* while leaving the text underneath 8% of its contrast. */
|
|
414
|
+
[data-composer-style="glass"][data-composer-expanded="true"] {
|
|
415
|
+
background-color: color-mix(in srgb, var(--theme-paper) 92%, transparent);
|
|
416
|
+
}
|
|
407
417
|
/* A browser without `backdrop-filter` gets an opaque card rather than a
|
|
408
418
|
* half-transparent one with nothing behind the blur: a 58% paper card over the
|
|
409
419
|
* canvas is legible, a 58% card over the transcript is not. */
|
|
410
420
|
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
|
|
411
|
-
[data-composer-style="glass"]
|
|
421
|
+
[data-composer-style="glass"],
|
|
422
|
+
[data-composer-style="glass"][data-composer-expanded="true"] {
|
|
412
423
|
background-color: var(--theme-paper);
|
|
413
424
|
}
|
|
414
425
|
}
|
|
@@ -20,18 +20,22 @@ import path from 'path';
|
|
|
20
20
|
import { fileExists } from '@/server/routes/fs/exists';
|
|
21
21
|
|
|
22
22
|
const PROBE = path.join(process.cwd(), 'tmp-exists-probe.txt');
|
|
23
|
+
/** A nested repo inside the workspace: the tree lists its files REPO-relative. */
|
|
24
|
+
const NESTED = path.join(process.cwd(), 'tmp-exists-repo');
|
|
23
25
|
|
|
24
26
|
afterEach(() => {
|
|
25
27
|
// The directory case leaves a folder where the file was, so the teardown has
|
|
26
28
|
// to remove either shape — `rmSync` on a directory without `recursive` throws
|
|
27
29
|
// EISDIR, which surfaced as three unrelated failures in the next cases.
|
|
28
30
|
fs.rmSync(PROBE, { recursive: true, force: true });
|
|
31
|
+
fs.rmSync(NESTED, { recursive: true, force: true });
|
|
29
32
|
});
|
|
30
33
|
|
|
31
|
-
async function probe(filePath: string, root: string = process.cwd()) {
|
|
34
|
+
async function probe(filePath: string, root: string = process.cwd(), repo?: string) {
|
|
32
35
|
const url = new URL('http://localhost/api/fs/exists');
|
|
33
36
|
url.searchParams.set('path', filePath);
|
|
34
37
|
url.searchParams.set('root', root);
|
|
38
|
+
if (repo) url.searchParams.set('repo', repo);
|
|
35
39
|
const res = await fileExists({ request: new Request(url) } as never);
|
|
36
40
|
return { status: res.status, body: (await res.json()) as { exists?: boolean; error?: string } };
|
|
37
41
|
}
|
|
@@ -73,4 +77,25 @@ describe('fs exists', () => {
|
|
|
73
77
|
expect(status).toBe(403);
|
|
74
78
|
expect(body.error).toBeTruthy();
|
|
75
79
|
});
|
|
80
|
+
|
|
81
|
+
test('a file inside a nested repo resolves with the repo the tree listed it under', async () => {
|
|
82
|
+
fs.mkdirSync(path.join(NESTED, 'src'), { recursive: true });
|
|
83
|
+
fs.writeFileSync(path.join(NESTED, 'src', 'inner.ts'), 'x');
|
|
84
|
+
|
|
85
|
+
// What the editor's tab scope sends: `root\0repo\0path`, all three.
|
|
86
|
+
expect((await probe('src/inner.ts', process.cwd(), 'tmp-exists-repo')).body.exists).toBe(true);
|
|
87
|
+
// Same file, asked root-relative — the other legitimate shape.
|
|
88
|
+
expect((await probe('tmp-exists-repo/src/inner.ts')).body.exists).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('a repo-relative path asked WITHOUT its repo is not the file', async () => {
|
|
92
|
+
fs.mkdirSync(path.join(NESTED, 'src'), { recursive: true });
|
|
93
|
+
fs.writeFileSync(path.join(NESTED, 'src', 'inner.ts'), 'x');
|
|
94
|
+
|
|
95
|
+
// This is the shape that struck a live tab through on the phone: the probe
|
|
96
|
+
// resolved a nested-repo path against the workspace root and answered "gone"
|
|
97
|
+
// for a file the editor had just read successfully. Pinned here so the
|
|
98
|
+
// client-side scope (which must carry `repo`) cannot silently regress.
|
|
99
|
+
expect((await probe('src/inner.ts')).body.exists).toBe(false);
|
|
100
|
+
});
|
|
76
101
|
});
|
|
@@ -80,6 +80,18 @@ describe('trace grouping', () => {
|
|
|
80
80
|
expect(groups[0].trace).toBe(true);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
test('a truncated run keeps the key of its first row, so a window shift cannot remount it', () => {
|
|
84
|
+
// The timeline mounts a WINDOW of rows, so the run is routinely rendered
|
|
85
|
+
// from the middle. Keying the group by `rows[0]` renamed it every time a
|
|
86
|
+
// measurement moved `start` by one row, and a renamed key remounts the
|
|
87
|
+
// whole run — which threw away the thinking accordion's own open state
|
|
88
|
+
// (measured: one expand removed and re-added all 14 rows of the run).
|
|
89
|
+
const whole = groupTraceRows(TURN, 1, 4);
|
|
90
|
+
const shifted = groupTraceRows(TURN, 2, 4);
|
|
91
|
+
expect(whole[0].key).toBe('a1');
|
|
92
|
+
expect(shifted[0].key).toBe(whole[0].key);
|
|
93
|
+
});
|
|
94
|
+
|
|
83
95
|
test('hasTraceContent reads each shape omp writes', () => {
|
|
84
96
|
expect(hasTraceContent({ id: 'x', role: 'ai', content: '', notice: 'n' } as unknown as ChatMessageData)).toBe(true);
|
|
85
97
|
expect(hasTraceContent({ id: 'x', role: 'ai', content: '', thinking: { thought: 't' } } as unknown as ChatMessageData)).toBe(true);
|