diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 99f42874066b2..e3b3e2a84cdb1 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -102,7 +102,7 @@ import { getSidebarProjectSettingsKey, type SidebarProjectSnapshot, } from "../sidebarProjectGrouping"; -import { useUiStateStore } from "../uiStateStore"; +import { resolveProjectExpanded, useUiStateStore } from "../uiStateStore"; import { getThreadKeysToDeselectAfterDelete, useThreadSelectionStore, @@ -198,6 +198,7 @@ import { SidebarPointerSensor } from "./Sidebar.pointer"; import { createSidebarListMotion } from "./Sidebar.motion"; import { resolveSnoozePresets, snoozeWakeLabel, type SnoozePreset } from "./Sidebar.snooze"; import { ProjectFavicon } from "./ProjectFavicon"; +import { SidebarProjectGroupHeader } from "./sidebar/SidebarProjectGroupHeader"; import { deriveProviderEntriesByEnvironment } from "../providerInstances"; import { useStableCallback } from "../hooks/useStableCallback"; import { @@ -365,6 +366,42 @@ function routeThreadOnly( } // Separate hooks cache maps independently of later Sidebar hooks and preserve dnd-kit inputs. +type SidebarThreadProjectGrouping = { + readonly groupKeyByProjectKey: ReadonlyMap; + readonly groupOrder: readonly string[]; + readonly isExpanded: (groupKey: string) => boolean; +}; + +function sidebarThreadGroupKey( + thread: Pick, + grouping: SidebarThreadProjectGrouping, +): string | null { + return grouping.groupKeyByProjectKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null; +} + +function groupActiveThreadsByProject( + threads: readonly EnvironmentThreadShell[], + grouping: SidebarThreadProjectGrouping, + routeRowThreadKey: string | null, +): EnvironmentThreadShell[] { + const rank = new Map(grouping.groupOrder.map((key, index) => [key, index] as const)); + const rankOf = (thread: EnvironmentThreadShell) => { + const key = sidebarThreadGroupKey(thread, grouping); + return key === null + ? grouping.groupOrder.length + : (rank.get(key) ?? grouping.groupOrder.length); + }; + // toSorted is stable, so threads keep the inbox order within each project. + return threads + .filter((thread) => { + const key = sidebarThreadGroupKey(thread, grouping); + return ( + key === null || grouping.isExpanded(key) || threadShellKey(thread) === routeRowThreadKey + ); + }) + .toSorted((left, right) => rankOf(left) - rankOf(right)); +} + function useSidebarThreads(input: { readonly projectScopeKey: string | null; readonly scopedProjectKeys: ReadonlySet | null; @@ -372,6 +409,7 @@ function useSidebarThreads(input: { readonly optimisticDrop: SidebarOptimisticDrop | null; readonly threads: readonly EnvironmentThreadShell[]; readonly routeRowThreadKey: string | null; + readonly projectGrouping: SidebarThreadProjectGrouping | null; }) { const { projectScopeKey, @@ -380,6 +418,7 @@ function useSidebarThreads(input: { optimisticDrop, threads, routeRowThreadKey, + projectGrouping, } = input; const workingShelfEnabled = useClientSettings((s) => s.sidebarWorkingShelfEnabled); const inboxReturnsVersion = useSyncExternalStore( @@ -457,9 +496,14 @@ function useSidebarThreads(input: { const visibleWorkingThreads = workingShelfExpanded ? workingThreads : routeThreadOnly(workingThreads, routeRowThreadKey); + // Grouped, active rows run in project order and collapsed projects list only the open thread. + const listedActiveThreads = + projectGrouping === null + ? activeThreads + : groupActiveThreadsByProject(activeThreads, projectGrouping, routeRowThreadKey); const orderedThreads = [ ...pinnedThreads, - ...activeThreads, + ...listedActiveThreads, ...visibleWorkingThreads, ...visibleSnoozedThreads, ...renderedSettledThreads, @@ -476,6 +520,7 @@ function useSidebarThreads(input: { } return { ...partition, + listedActiveThreads, threads, workingShelfEnabled, searchableThreads: [ @@ -798,6 +843,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive); const timestampFormat = useClientSettings((s) => s.timestampFormat); const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings); + const groupThreadsByProject = useClientSettings((s) => s.sidebarGroupThreadsByProject); + const threadCardStyle = useClientSettings((s) => s.sidebarThreadCardStyle); + const projectExpandedById = useUiStateStore((store) => store.projectExpandedById); + const setProjectExpanded = useUiStateStore((store) => store.setProjectExpanded); const { settleThread, unsettleThread, @@ -1097,12 +1146,29 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve }, ); + // Grouping follows the project filter: a scoped sidebar shows only that project's header. + const visibleProjectGroups = scopedProjectGroup === null ? projectGroups : [scopedProjectGroup]; + const projectGrouping: SidebarThreadProjectGrouping | null = groupThreadsByProject + ? { + groupKeyByProjectKey: new Map( + visibleProjectGroups.flatMap((group) => + group.memberProjectRefs.map( + (projectRef) => + [`${projectRef.environmentId}:${projectRef.projectId}`, group.projectKey] as const, + ), + ), + ), + groupOrder: visibleProjectGroups.map((group) => group.projectKey), + isExpanded: (groupKey) => resolveProjectExpanded(projectExpandedById, [groupKey]), + } + : null; const { workingShelfEnabled, pinnedThreads, draggableThreadKeys, activeReorderableThreadKeys, activeThreads, + listedActiveThreads, workingThreads, snoozedThreads, settledThreads, @@ -1138,6 +1204,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve optimisticDrop, threads, routeRowThreadKey, + projectGrouping, }); // Ranked across environments as the palette ranks them, so one @@ -1691,6 +1758,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve event.activatorEvent instanceof PointerEvent ? event.activatorEvent.clientY : null, }); }; + // Grouped rows are ordered by project, so a drop cannot express an inbox position. + const resolveDropTarget = ( + items: readonly SidebarListItem[], + activeKey: string, + overId: string, + ) => { + const target = resolveSidebarDropTarget(items, activeKey, overId); + return groupThreadsByProject && target?.section === "active" ? null : target; + }; const sidebarListItemsFresh = ((): readonly SidebarListItem[] => { const rowsOf = ( list: readonly EnvironmentThreadShell[], @@ -1714,7 +1790,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const pinnedRows = rowsOf(pinnedThreads, "pinned"); items.push(...pinnedRows); items.push({ kind: "marker", marker: "pinned-divider" }); - const activeRows = rowsOf(activeThreads, "active"); + const activeRows = rowsOf(listedActiveThreads, "active"); items.push({ kind: "marker", marker: "active-placeholder" }); items.push(...activeRows); if (workingThreads.length > 0) { @@ -1767,7 +1843,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve }, [listMotionPass]); const handleThreadDragOver = (event: DragOverEvent) => { const target = event.over - ? resolveSidebarDropTarget(sidebarListItems, String(event.active.id), String(event.over.id)) + ? resolveDropTarget(sidebarListItems, String(event.active.id), String(event.over.id)) : null; setDragState((current) => current === null || current.activeKey !== String(event.active.id) @@ -1808,7 +1884,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve if (source === undefined) return createSidebarCollisionDetection(() => false); return createSidebarCollisionDetection( (id) => { - const target = resolveSidebarDropTarget(sidebarListItems, draggedThreadKey, id); + const target = resolveDropTarget(sidebarListItems, draggedThreadKey, id); if (target === null) return false; return ( planSidebarThreadDrop({ @@ -1842,7 +1918,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const target = event.over === null ? null - : resolveSidebarDropTarget(sidebarListItems, activeKey, String(event.over.id)); + : resolveDropTarget(sidebarListItems, activeKey, String(event.over.id)); const activeThread = threadByKey.get(activeKey); if (activeSection === undefined || target === null || activeThread === undefined) return; const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id); @@ -2955,19 +3031,29 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve ); const isCard = section === "active" || section === "pinned" || section === "working"; - const rowVariant = isCard ? "card" : "slim"; + const rowVariant = + threadCardStyle === "row" + ? "row" + : isCard + ? threadCardStyle === "compact" + ? "compact" + : "card" + : "slim"; + const underProjectHeader = projectGrouping !== null && section === "active"; return ( , ]; + // Project headers render around the active rows without joining the drag model. + const projectGroupByKey = new Map( + visibleProjectGroups.map((group) => [group.projectKey, group] as const), + ); + const activeCountByGroup = new Map(); + if (projectGrouping !== null) { + for (const thread of activeThreads) { + const groupKey = sidebarThreadGroupKey(thread, projectGrouping); + if (groupKey === null) continue; + activeCountByGroup.set( + groupKey, + (activeCountByGroup.get(groupKey) ?? 0) + 1, + ); + } + } + let nextGroupIndex = 0; + const pushProjectHeadersThrough = (endIndex: number) => { + if (projectGrouping === null) return; + for (; nextGroupIndex < endIndex; nextGroupIndex += 1) { + const groupKey = projectGrouping.groupOrder[nextGroupIndex]!; + const group = projectGroupByKey.get(groupKey); + if (group === undefined) continue; + const expanded = projectGrouping.isExpanded(groupKey); + const firstRef = group.memberProjectRefs[0]; + items.push( + setProjectExpanded([groupKey], !expanded)} + onOpenSettings={() => openProjectSettings(group)} + onNewThread={() => { + if (firstRef === undefined) return; + void handleNewThread( + scopeProjectRef(firstRef.environmentId, firstRef.projectId), + ); + }} + />, + ); + } + }; + let inActiveRows = false; for (const item of sidebarListItems) { if (item.kind === "thread") { - items.push(renderThreadRow(threadByKey.get(item.key)!, item.section)); + const thread = threadByKey.get(item.key)!; + if (projectGrouping !== null && item.section === "active") { + inActiveRows = true; + const groupKey = sidebarThreadGroupKey(thread, projectGrouping); + const groupIndex = + groupKey === null ? -1 : projectGrouping.groupOrder.indexOf(groupKey); + if (groupIndex >= nextGroupIndex) + pushProjectHeadersThrough(groupIndex + 1); + } else if (inActiveRows) { + inActiveRows = false; + pushProjectHeadersThrough(projectGrouping?.groupOrder.length ?? 0); + } + items.push(renderThreadRow(thread, item.section)); continue; } + if ( + projectGrouping !== null && + item.marker !== "pinned-header" && + item.marker !== "pinned-divider" && + item.marker !== "active-placeholder" + ) { + // The first shelf after the active rows closes the project list. + inActiveRows = false; + pushProjectHeadersThrough(projectGrouping.groupOrder.length); + } switch (item.marker) { case "pinned-header": items.push( @@ -3190,6 +3341,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve break; } } + pushProjectHeadersThrough(projectGrouping?.groupOrder.length ?? 0); return items; })()} {settledShelfExpanded && hiddenSettledCount > 0 ? ( diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index a9594cb0894e6..e16056c9d876a 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -19,6 +19,7 @@ import { type ResponseStreamingMode, type QuitConfirmationMode, SidebarProjectSortOrder, + SidebarThreadCardStyle, } from "@t3tools/contracts/settings"; import { createModelSelection } from "@t3tools/shared/model"; import * as Equal from "effect/Equal"; @@ -114,7 +115,14 @@ const SIDEBAR_PROJECT_SORT_ORDER_LABELS: Record created_at: "Created at", manual: "Manual", }; + +const SIDEBAR_THREAD_CARD_STYLE_LABELS: Record = { + full: "Full", + compact: "Compact", + row: "Row", +}; const isSidebarProjectSortOrder = Schema.is(SidebarProjectSortOrder); +const isSidebarThreadCardStyle = Schema.is(SidebarThreadCardStyle); const TIMESTAMP_FORMAT_LABELS = { locale: "System default", @@ -408,6 +416,13 @@ export function useSettingsRestore(onRestored?: () => void) { ...(settings.mathRenderingEnabled !== DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled ? ["Render math"] : []), + ...(settings.sidebarGroupThreadsByProject !== + DEFAULT_UNIFIED_SETTINGS.sidebarGroupThreadsByProject + ? ["Group threads by project"] + : []), + ...(settings.sidebarThreadCardStyle !== DEFAULT_UNIFIED_SETTINGS.sidebarThreadCardStyle + ? ["Thread card style"] + : []), ...(settings.panelAnimationDurationMs !== DEFAULT_UNIFIED_SETTINGS.panelAnimationDurationMs ? ["Panel animations"] : []), @@ -581,6 +596,8 @@ export function useSettingsRestore(onRestored?: () => void) { diffColorScheme: DEFAULT_UNIFIED_SETTINGS.diffColorScheme, chatWidth: DEFAULT_UNIFIED_SETTINGS.chatWidth, mathRenderingEnabled: DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled, + sidebarGroupThreadsByProject: DEFAULT_UNIFIED_SETTINGS.sidebarGroupThreadsByProject, + sidebarThreadCardStyle: DEFAULT_UNIFIED_SETTINGS.sidebarThreadCardStyle, timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat, notificationMode: DEFAULT_UNIFIED_SETTINGS.notificationMode, inAppNotificationsEnabled: DEFAULT_UNIFIED_SETTINGS.inAppNotificationsEnabled, @@ -844,6 +861,72 @@ export function GeneralSettingsPanel() { } /> + + updateSettings({ + sidebarGroupThreadsByProject: + DEFAULT_UNIFIED_SETTINGS.sidebarGroupThreadsByProject, + }) + } + /> + ) : null + } + control={ + + updateSettings({ sidebarGroupThreadsByProject: Boolean(checked) }) + } + aria-label="Group threads by project" + /> + } + /> + + updateSettings({ + sidebarThreadCardStyle: DEFAULT_UNIFIED_SETTINGS.sidebarThreadCardStyle, + }) + } + /> + ) : null + } + control={ + + } + /> void; + onOpenSettings: () => void; + onNewThread: () => void; +}) { + const label = props.expanded ? "Hide its threads" : "Show its threads"; + return ( +
  • +
    + + + } + > + + {/* The chevron stands in for the favicon on hover, as in a file tree. */} + + + + + + {props.project.displayName} + {props.threadCount > 0 ? ( + + {props.threadCount} + + ) : null} + + {label} + + + + + } + > + + + Project settings + + + + } + > + + + New thread + + +
    +
  • + ); +} diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index 449be6dff7aa8..10c4cba114a6d 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -36,6 +36,7 @@ import { CircleCheckIcon, CircleDashedIcon, CircleDotDashedIcon, + CircleIcon, ClockIcon, GitBranchIcon, MessageCircleQuestionIcon, @@ -512,7 +513,10 @@ const dropVerbBadge: Record = { type SidebarThreadRowProps = { thread: SidebarThreadSummary; - variant: "card" | "slim"; + // Card and slim are the full style's inbox and shelf rows; compact and row are denser. + variant: "card" | "compact" | "slim" | "row"; + // Off under a project header, which already names the project. + showProject?: boolean | undefined; variantAction: SidebarSweepAction; settlementSupported: boolean; snoozeSupported: boolean; @@ -753,6 +757,29 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP } : null; const isWokeStatus = topStatus?.icon === "woke"; + const showProject = props.showProject ?? true; + // Compact and row step their icons down with the title. + const isDense = variant === "compact" || variant === "row"; + const threadIconSize = isDense ? "size-3.5" : "size-4"; + const statusIconClassName = cn(threadIconSize, "shrink-0"); + const statusIcon = + topStatus === null ? null : topStatus.icon === "working" ? ( + + ) : topStatus.icon === "waiting" ? ( + + ) : topStatus.icon === "input" ? ( + + ) : topStatus.icon === "request" ? ( + + ) : topStatus.icon === "approval" ? ( + + ) : topStatus.icon === "failed" ? ( + + ) : topStatus.icon === "done" ? ( + + ) : topStatus.icon === "woke" ? ( + + ) : null; const branchMismatch = resolveLocalCheckoutBranchMismatch({ effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree", @@ -980,9 +1007,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP + +{formatDiffCount(diff.insertions)}{" "} + −{formatDiffCount(diff.deletions)} + + ) : null; + + if (variant === "slim" || variant === "row") { + const isRow = variant === "row"; + // A row under a project header leads with what the thread is doing, or where it works. + const rowLeading = + statusIcon !== null && topStatus !== null ? ( + {statusIcon} + ) : thread.branch ? ( + + ) : ( + + ); return (
  • @@ -1109,9 +1163,14 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP tabIndex={0} aria-label={accessibility.label} aria-current={accessibility.current} - data-testid="sidebar-row-slim" + data-testid={isRow ? "sidebar-row-row" : "sidebar-row-slim"} aria-busy={isRegeneratingTitle || undefined} - className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")} + className={cn( + rowSurfaceClassName, + isRow + ? "flex h-8 items-center gap-2 px-2" + : "flex h-9 items-center gap-2.5 px-2.5", + )} onClick={handleClick} onDoubleClick={handleDoubleClick} onKeyDown={handleKeyDown} @@ -1127,12 +1186,17 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP "opacity-40 grayscale group-focus-within/sidebar-row:opacity-100 group-focus-within/sidebar-row:grayscale-0 group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0", )} > - {props.project ? : null} + {isRow && !showProject ? ( + rowLeading + ) : props.project ? ( + + ) : null} {draftIndicator} {title} {pinIndicator} {terminalStatusIcon} + {isRow && !sortable?.isDragging ? diffLabel : null} {isRegeneratingTitle ? ( Regenerating title @@ -1248,7 +1312,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP ); } - const diff = latestRunDiff(thread); + const isCompact = variant === "compact"; + // Under a project header the project line would be empty, so the title takes its place. + const titleOnTop = isCompact || !showProject; // Only the provider icon would remain, so the row drops the line instead of leaving it blank. const metaLineEmpty = !thread.branch && @@ -1264,8 +1330,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP {...sortableRootProps} {...(fileDropHandlers ?? {})} className={cn( - "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]", - metaLineEmpty && "[contain-intrinsic-size:auto_58px]", + "list-none [content-visibility:auto]", + isCompact + ? metaLineEmpty + ? "[contain-intrinsic-size:auto_32px]" + : "[contain-intrinsic-size:auto_52px]" + : cn( + "py-0.5 [contain-intrinsic-size:auto_78px]", + metaLineEmpty && "[contain-intrinsic-size:auto_58px]", + ), sortable?.isDragging && "relative z-20", )} > @@ -1291,19 +1364,29 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP {accessibleTitle}
    {draftIndicator} - {props.project ? ( - + {props.project && showProject ? ( + ) : null} {/* Left of the status slot, the pin would slide when hover swaps the label for the wider row controls. */} {pinIndicator} - {props.projectDisplayName ? ( + {titleOnTop ? ( + title + ) : props.projectDisplayName ? ( @@ -1358,21 +1441,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP topStatus.className, )} > - {topStatus.icon === "working" ? ( - - ) : topStatus.icon === "waiting" ? ( - - ) : topStatus.icon === "input" ? ( - - ) : topStatus.icon === "request" ? ( - - ) : topStatus.icon === "approval" ? ( - - ) : topStatus.icon === "failed" ? ( - - ) : topStatus.icon === "done" ? ( - - ) : null} + {statusIcon} {/* Not a live region: a collapsed sidebar is inert, so BackgroundThreadAnnouncer and the open thread's timeline speak status changes instead. */} @@ -1451,8 +1520,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP )} {props.sweepAction !== null ? dragDestination : null}
    -
    - {title} +
    + {!titleOnTop ? title : null} {isRegeneratingTitle ? ( Regenerating title @@ -1490,16 +1559,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP )} {terminalStatusIcon} {prBadge} - {diff ? ( - - - +{formatDiffCount(diff.insertions)} - {" "} - - −{formatDiffCount(diff.deletions)} - - - ) : null} + {diffLabel}