Skip to content

Commit 736314a

Browse files
Merge branch 'main' into feat/sidebar-thread-file-drop
2 parents 8b68362 + d7a59c6 commit 736314a

15 files changed

Lines changed: 398 additions & 706 deletions

‎apps/web/src/components/CommandPalette.logic.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
22
import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
3-
import type { Thread } from "../types";
3+
import type { Project, Thread } from "../types";
44
import {
55
buildBrowseGroups,
6+
buildProjectActionItems,
67
buildThreadActionItems,
78
enumerateCommandPaletteItems,
89
filterPinnedBrowseEntries,
@@ -112,6 +113,20 @@ describe("enumerateCommandPaletteItems", () => {
112113
const LOCAL_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
113114
const PROJECT_ID = ProjectId.make("project-1");
114115

116+
function makeProject(overrides: Partial<Project> = {}): Project {
117+
return {
118+
id: PROJECT_ID,
119+
environmentId: LOCAL_ENVIRONMENT_ID,
120+
title: "Project",
121+
workspaceRoot: "/workspace/project",
122+
defaultModelSelection: null,
123+
scripts: [],
124+
createdAt: "2026-03-01T00:00:00.000Z",
125+
updatedAt: "2026-03-01T00:00:00.000Z",
126+
...overrides,
127+
};
128+
}
129+
115130
function makeThread(overrides: Partial<Thread> = {}): Thread {
116131
return {
117132
id: ThreadId.make("thread-1"),
@@ -139,6 +154,28 @@ function makeThread(overrides: Partial<Thread> = {}): Thread {
139154
};
140155
}
141156

157+
describe("buildProjectActionItems", () => {
158+
it("shows the grouped display name but keeps the real title for icons", () => {
159+
const project = makeProject({ title: "fleet", workspaceRoot: "/Users/theo/Code/p/fleet" });
160+
const iconTitles: string[] = [];
161+
const [item] = buildProjectActionItems({
162+
projects: [{ ...project, displayName: "t3dotgg/fleet" }],
163+
valuePrefix: "project",
164+
icon: (candidate) => {
165+
iconTitles.push(candidate.title);
166+
return null;
167+
},
168+
runProject: async () => undefined,
169+
});
170+
171+
expect(item?.title).toBe("t3dotgg/fleet");
172+
expect(item?.searchTerms).toEqual(
173+
expect.arrayContaining(["t3dotgg/fleet", "fleet", "/Users/theo/Code/p/fleet"]),
174+
);
175+
expect(iconTitles).toEqual(["fleet"]);
176+
});
177+
});
178+
142179
describe("buildThreadActionItems", () => {
143180
it("orders threads by most recent activity and formats timestamps from updatedAt", () => {
144181
vi.useFakeTimers();

‎apps/web/src/components/CommandPalette.logic.ts‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,31 @@ export function enumerateCommandPaletteItems(
139139

140140
export type CommandPaletteMode = "root" | "root-browse" | "submenu" | "submenu-browse";
141141

142+
// A project as the palette shows it. `displayName` is the grouped label (for
143+
// example "owner/repo" when projects are merged across machines). Keep `title`
144+
// as the real project title: the automatic project icon is derived from it, and
145+
// every other surface uses the real title, so overriding it desyncs the icon.
146+
export type CommandPaletteProject = Project & { readonly displayName: string };
147+
142148
export function buildProjectActionItems(input: {
143-
projects: ReadonlyArray<Project>;
149+
projects: ReadonlyArray<CommandPaletteProject>;
144150
valuePrefix: string;
145-
icon: (project: Project) => ReactNode;
146-
runProject: (project: Project) => Promise<void>;
147-
searchTerms?: (project: Project) => ReadonlyArray<string>;
148-
renderDescription?: (project: Project) => ReactNode;
151+
icon: (project: CommandPaletteProject) => ReactNode;
152+
runProject: (project: CommandPaletteProject) => Promise<void>;
153+
searchTerms?: (project: CommandPaletteProject) => ReadonlyArray<string>;
154+
renderDescription?: (project: CommandPaletteProject) => ReactNode;
149155
shortcutCommand?: KeybindingCommand;
150156
}): CommandPaletteActionItem[] {
151157
return input.projects.map((project) => ({
152158
kind: "action",
153159
value: `${input.valuePrefix}:${project.environmentId}:${project.id}`,
154-
searchTerms: [project.title, project.workspaceRoot, ...(input.searchTerms?.(project) ?? [])],
155-
title: project.title,
160+
searchTerms: [
161+
project.displayName,
162+
project.title,
163+
project.workspaceRoot,
164+
...(input.searchTerms?.(project) ?? []),
165+
],
166+
title: project.displayName,
156167
description: input.renderDescription?.(project) ?? project.workspaceRoot,
157168
icon: input.icon(project),
158169
...(input.shortcutCommand !== undefined ? { shortcutCommand: input.shortcutCommand } : {}),

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ function OpenCommandPaletteDialog(props: {
794794
() =>
795795
projectPickerEntries.map(({ group, targetProject }) => ({
796796
...targetProject,
797-
title: group.displayName,
797+
displayName: group.displayName,
798798
})),
799799
[projectPickerEntries],
800800
);

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ function WorkingDuration(props: { startedAt: string | null }) {
290290
}
291291

292292
const EMPTY_PROVIDER_ENTRIES: ReadonlyMap<string, ProviderInstanceEntry> = new Map();
293+
// Collapsed shelves share one empty list so a route change alone does not
294+
// give the sidebar list a new identity.
295+
const EMPTY_THREADS: readonly EnvironmentThreadShell[] = [];
293296

294297
function terminalProcessLabel(count: number): string {
295298
return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
@@ -1572,7 +1575,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15721575
{...sortableRootProps}
15731576
{...(fileDropHandlers ?? {})}
15741577
className={cn(
1575-
"list-none [content-visibility:auto] [contain-intrinsic-size:auto_34px]",
1578+
// Matches the h-9 row so unrendered rows never shift the list when they paint.
1579+
"list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]",
15761580
sortable?.isDragging && "relative z-20",
15771581
)}
15781582
>
@@ -1731,7 +1735,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17311735
{...sortableRootProps}
17321736
{...(fileDropHandlers ?? {})}
17331737
className={cn(
1734-
"list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_96px]",
1738+
// Matches the h-[4.875rem] content box; the py-0.5 padding is added on top.
1739+
"list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",
17351740
sortable?.isDragging && "relative z-20",
17361741
)}
17371742
>
@@ -2702,12 +2707,12 @@ export default function Sidebar() {
27022707
);
27032708
const renderedSettledThreads = useMemo(() => {
27042709
if (settledShelfExpanded) return visibleSettledThreads;
2705-
if (routeThreadKey === null) return [];
2710+
if (routeThreadKey === null) return EMPTY_THREADS;
27062711
const routeThread = visibleSettledThreads.find(
27072712
(thread) =>
27082713
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)) === routeThreadKey,
27092714
);
2710-
return routeThread === undefined ? [] : [routeThread];
2715+
return routeThread === undefined ? EMPTY_THREADS : [routeThread];
27112716
}, [routeThreadKey, settledShelfExpanded, visibleSettledThreads]);
27122717

27132718
// The snoozed shelf is collapsed by default: out of the way, never gone.
@@ -2728,12 +2733,12 @@ export default function Sidebar() {
27282733
// snoozed thread reached by route (deep link, open before snoozing
27292734
// elsewhere) keeps its row — with highlight and wake affordance — same
27302735
// exception the settled tail's "Show more" makes.
2731-
if (routeThreadKey === null) return [];
2736+
if (routeThreadKey === null) return EMPTY_THREADS;
27322737
const routeThread = snoozedThreads.find(
27332738
(thread) =>
27342739
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)) === routeThreadKey,
27352740
);
2736-
return routeThread === undefined ? [] : [routeThread];
2741+
return routeThread === undefined ? EMPTY_THREADS : [routeThread];
27372742
}, [routeThreadKey, snoozedShelfExpanded, snoozedThreads]);
27382743

27392744
const orderedThreads = useMemo(
@@ -3362,15 +3367,32 @@ export default function Sidebar() {
33623367
}
33633368
}, [cancelThreadDrag, dragState, sidebarListItems]);
33643369
const listMotionPaused = dragState !== null;
3370+
// Every shell event rebuilds sidebarListItems, but rows only move when the
3371+
// rendered order or a row's section changes. Keying the motion pass on that
3372+
// keeps ordinary updates from forcing a layout read and animating rows
3373+
// whose position drifted for other reasons.
3374+
const sidebarListOrderKey = useMemo(
3375+
() =>
3376+
sidebarListItems
3377+
.map((item) => (item.kind === "thread" ? `${item.key}:${item.section}` : item.marker))
3378+
.join("\0"),
3379+
[sidebarListItems],
3380+
);
3381+
const sidebarListHasRows = sidebarListItems.length + visibleDraftSessionCount > 0;
33653382
useLayoutEffect(() => {
33663383
// Drag release clears the baseline, so its commit cannot replay the
33673384
// sortable preview; rows glide from their released positions instead.
33683385
// Later thread actions can animate while writes settle.
33693386
// Draft navigation can reveal a frozen row without changing the draft count.
3370-
listMotionRef.current?.update(
3371-
!listMotionPaused && sidebarListItems.length + visibleDraftSessionCount > 0,
3372-
);
3373-
}, [listMotionPaused, routeDraftIdForRows, sidebarListItems, visibleDraftSessionCount]);
3387+
void sidebarListOrderKey;
3388+
listMotionRef.current?.update(!listMotionPaused && sidebarListHasRows);
3389+
}, [
3390+
listMotionPaused,
3391+
routeDraftIdForRows,
3392+
sidebarListHasRows,
3393+
sidebarListOrderKey,
3394+
visibleDraftSessionCount,
3395+
]);
33743396
const handleThreadDragOver = useCallback(
33753397
(event: DragOverEvent) => {
33763398
const target = event.over

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,34 @@ export function resolveTimelineMinimapIndexFromPointer(input: {
197197
return Math.max(0, Math.min(input.itemCount - 1, Math.round(progress * (input.itemCount - 1))));
198198
}
199199

200+
export function resolveTimelineMinimapCurrentIndex(input: {
201+
readonly scrollTop: number;
202+
readonly scrollBottom: number;
203+
readonly itemBounds: ReadonlyArray<{
204+
readonly top: number | null;
205+
readonly height: number | null;
206+
}>;
207+
}): number | null {
208+
let precedingIndex: number | null = null;
209+
210+
for (const [index, item] of input.itemBounds.entries()) {
211+
if (item.top === null) {
212+
continue;
213+
}
214+
const inView =
215+
item.top < input.scrollBottom && item.top + Math.max(1, item.height ?? 1) > input.scrollTop;
216+
if (inView) {
217+
// The first visible marker is the turn at the reader's current position.
218+
return index;
219+
}
220+
if (item.top <= input.scrollTop) {
221+
precedingIndex = index;
222+
}
223+
}
224+
225+
return precedingIndex;
226+
}
227+
200228
export function resolveTimelineMinimapHasPersistentGutter(viewportWidth: number): boolean {
201229
if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
202230
return false;

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,25 @@ function buildSnapShotTimelineEntry(previewUrl?: string) {
272272
}
273273

274274
describe("MessagesTimeline", () => {
275+
it("renders previous and next controls with the minimap", () => {
276+
const first = buildUserTimelineEntry("First turn");
277+
const secondBase = buildUserTimelineEntry("Second turn");
278+
const second = {
279+
...secondBase,
280+
id: "entry-2",
281+
message: {
282+
...secondBase.message,
283+
id: MessageId.make("message-2"),
284+
},
285+
};
286+
const markup = renderToStaticMarkup(
287+
<MessagesTimeline {...buildProps()} timelineEntries={[first, second]} />,
288+
);
289+
290+
expect(markup).toContain('aria-label="Previous turn"');
291+
expect(markup).toContain('aria-label="Next turn"');
292+
});
293+
275294
// Expanding history uses this suite's existing test renderer, deprecated in
276295
// React 19. Migrate these interaction tests together when a DOM test setup is added.
277296
it.each([{}, { text: "Text-only answer", file: "Answer with a file" }])(
@@ -524,6 +543,7 @@ describe("MessagesTimeline", () => {
524543
const {
525544
resolveTimelineIsAtEnd,
526545
resolveTimelineMinimapHasPersistentGutter,
546+
resolveTimelineMinimapCurrentIndex,
527547
resolveTimelineMinimapHeightStyle,
528548
resolveTimelineMinimapHitStripWidth,
529549
resolveTimelineMinimapIndexFromPointer,
@@ -583,6 +603,35 @@ describe("MessagesTimeline", () => {
583603
pointerY: 999,
584604
}),
585605
).toBe(100);
606+
expect(
607+
resolveTimelineMinimapCurrentIndex({
608+
scrollTop: 100,
609+
scrollBottom: 500,
610+
itemBounds: [
611+
{ top: 80, height: 20 },
612+
{ top: 120, height: 20 },
613+
{ top: 220, height: 20 },
614+
],
615+
}),
616+
).toBe(1);
617+
expect(
618+
resolveTimelineMinimapCurrentIndex({
619+
scrollTop: 150,
620+
scrollBottom: 200,
621+
itemBounds: [
622+
{ top: 80, height: 20 },
623+
{ top: 120, height: 20 },
624+
{ top: 220, height: 20 },
625+
],
626+
}),
627+
).toBe(1);
628+
expect(
629+
resolveTimelineMinimapCurrentIndex({
630+
scrollTop: 0,
631+
scrollBottom: 50,
632+
itemBounds: [{ top: 80, height: 20 }],
633+
}),
634+
).toBeNull();
586635
expect(resolveTimelineMinimapHasPersistentGutter(832)).toBe(false);
587636
expect(resolveTimelineMinimapHasPersistentGutter(863)).toBe(false);
588637
expect(resolveTimelineMinimapHasPersistentGutter(864)).toBe(true);

0 commit comments

Comments
 (0)