@devries-cameron20 / t3code Mirror · read-only / commits / 00ceb2dc74
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

refactor(web): the sidebar's thread rows live in their own file (#22696)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:24 UTC 00ceb2dc7492115f8a95a867bc7c0e3a05b40bd3
2 files changed +1682 -1639
apps/web/src/components/Sidebar.tsx
+14 -1639
@@ -1,8 +1,6 @@
1 import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts";
2 import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";
3 -import { ThreadHoverCard, ThreadHoverCardPopup } from "./ThreadHoverCard";
3 import { CollapsibleSectionHeader } from "./ui/collapsible-section-header";
5 -import { ThreadTerminalStatusButton } from "./ThreadStatusIndicators";
4 import { ThreadContextDragGhost } from "./chat/ThreadContextDragGhost";
5 import {
6 dropThreadContext,
@@ -11,8 +9,6 @@ import {
9 } from "./chat/threadContextDrag";
10 import { discardComposerDraft } from "../lib/discardComposerDraft";
11 import { requestCustomSnooze } from "./CustomSnoozeDialog";
14 -import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
15 -import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";
12 import { useAtomValue } from "@effect/atom-react";
13 import * as Option from "effect/Option";
14 import { Atom } from "effect/reactivity";
@@ -33,23 +29,12 @@ import { CSS } from "@dnd-kit/utilities";
29 import {
30 canSnooze,
31 effectiveSnoozed,
36 - hasQueuedTurnStart,
37 - QUEUED_TURN_START_GRACE_MS,
32 threadWokeAt,
33 } from "@t3tools/client-runtime/state/thread-settled";
34 import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
41 -import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
35 +import { sortSettledThreads } from "@t3tools/client-runtime/state/thread-sort";
36 +import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
37 import {
43 - resolveSettledThreadTimestamp,
44 - sortSettledThreads,
45 -} from "@t3tools/client-runtime/state/thread-sort";
46 -import {
47 - threadSearchMatchKey,
48 - type EnvironmentThreadSearchMatch,
49 -} from "@t3tools/client-runtime/state/thread-search";
50 -import {
51 - formatWorkingDurationLabel,
52 - resolveThreadProviderStack,
38 threadRuntimeCanArchive,
39 type EnvironmentThreadShell,
40 } from "@t3tools/client-runtime/state/models";
@@ -61,34 +46,16 @@ import {
46 } from "@t3tools/client-runtime/environment";
47 import {
48 AuthOrchestrationOperateScope,
64 - type EnvironmentMachineKind,
49 type ScopedThreadRef,
50 type ThreadId,
51 } from "@t3tools/contracts";
52
69 -import type { TimestampFormat } from "@t3tools/contracts/settings";
53 import {
71 - AlarmClockIcon,
72 - AlarmClockOffIcon,
73 - ArrowRightLeftIcon,
74 - CheckIcon,
75 - CircleAlertIcon,
76 - CircleCheckIcon,
77 - CircleDashedIcon,
78 - CircleDotDashedIcon,
79 - ClockIcon,
54 FolderIcon,
81 - GitBranchIcon,
55 ListFilterIcon,
83 - MessageCircleQuestionIcon,
84 - PinIcon,
85 - PinOffIcon,
56 PlusIcon,
57 SettingsIcon,
88 - ShieldQuestionIcon,
58 SquarePenIcon,
90 - TerminalIcon,
91 - Undo2Icon,
59 XIcon,
60 } from "lucide-react";
61 import {
@@ -100,12 +67,10 @@ import {
67 useState,
68 type KeyboardEvent as ReactKeyboardEvent,
69 type MouseEvent as ReactMouseEvent,
103 - type PointerEvent as ReactPointerEvent,
70 type ReactNode,
71 } from "react";
72 import { useRouter } from "@tanstack/react-router";
73
108 -import { useRightPanelStore } from "../rightPanelStore";
74 import {
75 isAtomCommandInterrupted,
76 settlePromise,
@@ -126,7 +91,6 @@ import { isTerminalFocused } from "../lib/terminalFocus";
91 import { isModelPickerOpen } from "../modelPickerVisibility";
92 import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
93 import { isMacPlatform } from "~/lib/utils";
129 -import { useOpenPrLink } from "../lib/openPullRequestLink";
94 import { readLocalApi } from "../localApi";
95 import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
96 import { selectProjectGroupingSettings } from "../logicalProject";
@@ -152,7 +116,6 @@ import { useClientSettings } from "../hooks/useSettings";
116 import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
117 import { useLocalStorage } from "../hooks/useLocalStorage";
118 import { useNowMinute } from "../hooks/useNowMinute";
155 -import { useNowSecond } from "../hooks/useNowSecond";
119 import {
120 useEnvironmentIdentities,
121 useConnectedEnvironmentIds,
@@ -169,19 +132,15 @@ import {
132 import { environmentPresentations } from "../state/presentation";
133 import { primaryServerKeybindingsAtom } from "../state/server";
134 import { environmentProjects } from "../state/projects";
172 -import { vcsEnvironment } from "../state/vcs";
135 import { threadEnvironment } from "../state/threads";
174 -import { useEnvironmentQuery } from "../state/query";
136 import { useThreadSearch } from "../state/queries";
137 import { useOrchestrationCommand } from "../state/use-orchestration-command";
177 -import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
138 +import { readEnvironmentScope } from "../state/session";
139 import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
179 -import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat";
140 import type { SidebarThreadSummary } from "../types";
141 import { isScratchProject } from "@t3tools/client-runtime/state/projects";
142 import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
143 import { cn } from "~/lib/utils";
184 -import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
144 import { ProjectEnvironmentBadge } from "./ProjectEnvironmentBadge";
145 import {
146 buildDraftActionMenuItems,
@@ -197,7 +156,6 @@ import {
156 deleteSelectedThreadEntries,
157 filterSidebarProjectScopeItems,
158 firstValidTimestampMs,
200 - hasUnseenCompletion,
159 isSidebarNestedLinkClick,
160 isSidebarThreadWorking,
161 isTrailingDoubleClick,
@@ -210,14 +168,9 @@ import {
168 resolveSidebarDropVerb,
169 resolveSidebarThreadSection,
170 resolveSidebarRowAccessibility,
213 - type SidebarDropVerb,
214 - resolveSidebarThreadStatus,
215 - resolveThreadLastVisitedAt,
171 searchSidebarThreads,
172 shouldCreateNewThreadInCurrentProject,
173 shouldNavigateAfterThreadPark,
219 - shouldRecedeSidebarThread,
220 - resolveWorkingStartedAt,
174 sidebarListItemId,
175 sidebarMarkerId,
176 sidebarThreadKeyAtY,
@@ -226,14 +179,11 @@ import {
179 sortThreadsForSidebar,
180 sortWorkingThreadsBySend,
181 useThreadJumpHintVisibility,
229 - useRetainedValue,
230 - useSidebarRowSubscriptionLease,
182 type SidebarListItem,
183 type SidebarListMarker,
184 type SidebarSection,
185 resolveSidebarRowThreadId,
186 } from "./Sidebar.logic";
236 -import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";
187 import {
188 createSidebarCollisionDetection,
189 createSidebarSortingStrategy,
@@ -241,32 +191,12 @@ import {
191 } from "./Sidebar.drag";
192 import { SidebarDragLifecycle, SidebarPointerSensor } from "./Sidebar.pointer";
193 import { createSidebarListMotion } from "./Sidebar.motion";
244 -import {
245 - ThreadPullRequestBadgeControl,
246 - ThreadPullRequestsMiniList,
247 - ThreadWorktreeIndicator,
248 - prStatusIndicator,
249 - resolveThreadPullRequestBadge,
250 - terminalStatusFromRunningIds,
251 - type TerminalStatusIndicator,
252 - useLinkedThreadPullRequest,
253 - ThreadSearchPullRequestNumber,
254 -} from "./ThreadStatusIndicators";
194 import { resolveSnoozePresets, snoozeWakeLabel, type SnoozePreset } from "./Sidebar.snooze";
195 import { ProjectFavicon, type ProjectFaviconProject } from "./ProjectFavicon";
257 -import { ThreadSearchMatchExcerpt } from "./ThreadSearchMatch";
258 -import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop";
259 -import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
260 -import { getTriggerDisplayModelLabel } from "./chat/providerIconUtils";
261 -import {
262 - deriveProviderEntriesByEnvironment,
263 - shouldShowInstanceBadge,
264 - type ProviderInstanceEntry,
265 -} from "../providerInstances";
266 -import { useThreadRunningTerminalIds } from "../state/terminalSessions";
196 +import { deriveProviderEntriesByEnvironment } from "../providerInstances";
197 import { useStableCallback } from "../hooks/useStableCallback";
198 import { stackedThreadToast, toastManager } from "./ui/toast";
269 -import { Button, InlineButton } from "./ui/button";
199 +import { Button } from "./ui/button";
200 import {
201 Combobox,
202 ComboboxEmpty,
@@ -280,33 +210,24 @@ import {
210 import { SidebarContent, SidebarGroup, useSidebar } from "./ui/sidebar";
211 import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";
212 import { SidebarHeaderIconButton, SidebarThreadHeader } from "./sidebar/SidebarThreadHeader";
283 -import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuTrigger } from "./ui/menu";
213 import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
285 -import { MiddleTruncate } from "./ui/middle-truncate";
214 import {
215 composerDraftHasUserContent,
216 DraftId,
217 useComposerDraftStore,
290 - useThreadHasUnsentDraft,
218 type ComposerThreadDraftState,
219 type DraftSessionState,
220 } from "../composerDraftStore";
221 import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
295 -
296 -// The fields thread rows show. Provider status pushes refresh `checkedAt`,
297 -// status and auth on every provider; leaving those out keeps each
298 -// environment's map, and every memoized row, stable across them.
299 -type SidebarProviderEntry = Pick<
300 - ProviderInstanceEntry,
301 - | "instanceId"
302 - | "driverKind"
303 - | "enabled"
304 - | "displayName"
305 - | "accentColor"
306 - | "acpRegistryAgentId"
307 - | "acpRegistryIconUrl"
308 - | "models"
309 ->;
222 +import {
223 + SIDEBAR_SORTABLE_DRAG_DISABLED,
224 + draftPenClassName,
225 + draftSurfaceClassName,
226 + SidebarSearchResultRow,
227 + SortableThreadRow,
228 + type SidebarProviderEntry,
229 + type SidebarSweepAction,
230 +} from "./sidebar/SidebarThreadRow";
231
232 function sameSidebarProviderEntries(
233 left: ReadonlyMap<string, SidebarProviderEntry>,
@@ -835,350 +756,6 @@ function checkThreadOperations(
756 return false;
757 }
758
838 -function compactSidebarTimeLabel(label: string): string {
839 - if (label === "just now") return "now";
840 - return label.endsWith(" ago") ? label.slice(0, -4) : label;
841 -}
842 -
843 -// Subscribes to the minute tick itself, so only the label re-renders each
844 -// minute. The minute is passed as the clock so it is the formatter's input.
845 -function RelativeTimeLabel(props: { timestamp: string | null }) {
846 - const nowMinute = useNowMinute();
847 - return props.timestamp === null
848 - ? null
849 - : compactSidebarTimeLabel(
850 - formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),
851 - );
852 -}
853 -
854 -function threadTimeTimestamp(thread: SidebarThreadSummary): string {
855 - return thread.latestUserMessageAt ?? thread.updatedAt;
856 -}
857 -
858 -function JumpHintBadge(props: { label: string }) {
859 - return (
860 - <span
861 - aria-hidden
862 - className="pointer-events-none absolute right-1.5 top-1/2 z-10 inline-flex h-5 -translate-y-1/2 items-center rounded-full border border-border/80 bg-background/95 px-1.5 font-mono text-3xs font-medium tracking-tight text-foreground shadow-sm"
863 - >
864 - {props.label}
865 - </span>
866 - );
867 -}
868 -
869 -function WorkingDuration(props: { startedAt: string | null }) {
870 - const startedMs = props.startedAt !== null ? Date.parse(props.startedAt) : Number.NaN;
871 - if (Number.isNaN(startedMs)) return null;
872 - return <WorkingDurationLabel startedMs={startedMs} />;
873 -}
874 -
875 -// Self-ticking so only this span re-renders each second, not the whole row;
876 -// the shared tick lands every working row's update in the same frame.
877 -function WorkingDurationLabel(props: { startedMs: number }) {
878 - const nowMs = useNowSecond();
879 - return (
880 - <span className="tabular-nums">{formatWorkingDurationLabel(nowMs - props.startedMs)}</span>
881 - );
882 -}
883 -
884 -function terminalProcessLabel(count: number): string {
885 - return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
886 -}
887 -
888 -function SidebarProviderStack(props: {
889 - thread: SidebarThreadSummary;
890 - providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
891 -}) {
892 - const stack = resolveThreadProviderStack(props.thread);
893 - const currentInstanceId = stack[stack.length - 1]!;
894 - const currentEntry = props.providerEntryByInstanceId.get(currentInstanceId) ?? null;
895 - if (currentEntry === null) return null;
896 - const showInstanceBadge = shouldShowInstanceBadge(
897 - currentEntry,
898 - props.providerEntryByInstanceId.values(),
899 - );
900 - const current = (
901 - <ProviderInstanceIcon
902 - driverKind={currentEntry.driverKind}
903 - displayName={currentEntry.displayName}
904 - accentColor={currentEntry.accentColor}
905 - acpRegistryAgentId={currentEntry.acpRegistryAgentId}
906 - acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}
907 - showBadge={showInstanceBadge}
908 - size="compact"
909 - iconClassName="opacity-60"
910 - />
911 - );
912 - if (stack.length === 1) {
913 - return <span className="inline-flex shrink-0 items-center">{current}</span>;
914 - }
915 - return (
916 - <span className="inline-flex shrink-0 items-center gap-1.5">
917 - {stack.slice(0, -1).map((instanceId) => {
918 - const entry = props.providerEntryByInstanceId.get(instanceId);
919 - if (entry === undefined) return null;
920 - return (
921 - <ProviderInstanceIcon
922 - key={instanceId}
923 - driverKind={entry.driverKind}
924 - displayName={entry.displayName}
925 - acpRegistryAgentId={entry.acpRegistryAgentId}
926 - acpRegistryIconUrl={entry.acpRegistryIconUrl}
927 - iconClassName="size-3 opacity-35 grayscale"
928 - />
929 - );
930 - })}
931 - <span className="relative z-10 inline-flex items-center">{current}</span>
932 - </span>
933 - );
934 -}
935 -
936 -function SidebarThreadTooltip({
937 - thread,
938 - project,
939 - projectDisplayName,
940 - environmentLabel,
941 - environmentMachine,
942 - providerEntry,
943 - providerEntryByInstanceId,
944 - showInstanceBadge,
945 - modelInstanceId,
946 - modelLabel,
947 - branchMismatch,
948 - terminalStatus,
949 - terminalProcessCount,
950 -}: {
951 - thread: SidebarThreadSummary;
952 - project: ProjectFaviconProject | null;
953 - projectDisplayName: string | null;
954 - environmentLabel: string | null;
955 - environmentMachine: EnvironmentMachineKind;
956 - providerEntry: SidebarProviderEntry | null;
957 - providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
958 - showInstanceBadge: boolean;
959 - modelInstanceId: string;
960 - modelLabel: string;
961 - branchMismatch: {
962 - threadBranch: string;
963 - currentBranch: string;
964 - } | null;
965 - terminalStatus: TerminalStatusIndicator | null;
966 - terminalProcessCount: number;
967 -}) {
968 - const driverKind = providerEntry?.driverKind ?? null;
969 - const previousProviderNames = thread.providerInstanceHistory
970 - .filter((instanceId) => instanceId !== modelInstanceId)
971 - .map((instanceId) => providerEntryByInstanceId.get(instanceId)?.displayName ?? instanceId);
972 - const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
973 - return (
974 - <ThreadHoverCardPopup side="right" align="start" sideOffset={4}>
975 - <ThreadHoverCard
976 - title={thread.title}
977 - footer={
978 - supportsMultiplePullRequests && thread.pullRequests.length > 0 ? (
979 - <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground">
980 - <ThreadPullRequestsMiniList pullRequests={thread.pullRequests} />
981 - </div>
982 - ) : null
983 - }
984 - >
985 - {projectDisplayName ? (
986 - <div className="flex min-w-0 items-center gap-2">
987 - {project ? <ProjectFavicon project={project} className="size-3 shrink-0" /> : null}
988 - <div className="min-w-0 truncate text-foreground/75">{projectDisplayName}</div>
989 - </div>
990 - ) : null}
991 - {environmentLabel ? (
992 - <div className="flex min-w-0 items-center gap-2">
993 - <EnvironmentMachineIcon
994 - kind={environmentMachine}
995 - className="size-3 shrink-0 stroke-muted-foreground"
996 - />
997 - <div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div>
998 - </div>
999 - ) : null}
1000 - {thread.branch ? (
1001 - <div className="flex min-w-0 items-center gap-2">
1002 - <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />
1003 - <MiddleTruncate value={thread.branch} className="flex" />
1004 - </div>
1005 - ) : null}
1006 - {branchMismatch ? (
1007 - <div className="flex min-w-0 items-start gap-2 text-warning">
1008 - <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />
1009 - <div className="min-w-0 flex-1 wrap-break-word">
1010 - You're currently checked out on another branch.
1011 - </div>
1012 - </div>
1013 - ) : null}
1014 - {driverKind ? (
1015 - <div className="flex min-w-0 items-center gap-2">
1016 - <ProviderInstanceIcon
1017 - driverKind={driverKind}
1018 - displayName={
1019 - providerEntry?.displayName ?? thread.runtime?.providerName ?? modelInstanceId
1020 - }
1021 - accentColor={providerEntry?.accentColor}
1022 - acpRegistryAgentId={providerEntry?.acpRegistryAgentId}
1023 - acpRegistryIconUrl={providerEntry?.acpRegistryIconUrl}
1024 - showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined}
1025 - badgeContent="none"
1026 - badgeClassName="h-2 min-w-2 px-0"
1027 - iconClassName="size-3 shrink-0 grayscale opacity-60"
1028 - />
1029 - <div className="min-w-0 truncate text-foreground/75">
1030 - {showInstanceBadge && providerEntry
1031 - ? `${modelLabel} · ${providerEntry.displayName}`
1032 - : modelLabel}
1033 - </div>
1034 - </div>
1035 - ) : null}
1036 - {previousProviderNames.length > 0 ? (
1037 - <div className="flex min-w-0 items-center gap-2">
1038 - <ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" />
1039 - <div className="min-w-0 truncate text-foreground/75">
1040 - Handed off from {previousProviderNames.join(", ")}
1041 - </div>
1042 - </div>
1043 - ) : null}
1044 - {terminalStatus ? (
1045 - <div className="flex min-w-0 items-center gap-2">
1046 - <TerminalIcon
1047 - aria-hidden
1048 - className={cn("size-3 shrink-0", terminalStatus.colorClass)}
1049 - />
1050 - <div className="min-w-0 truncate text-foreground/75">
1051 - {terminalProcessLabel(terminalProcessCount)}
1052 - </div>
1053 - </div>
1054 - ) : null}
1055 - {thread.runtime?.lastError ? (
1056 - <div
1057 - className={cn(
1058 - "flex min-w-0 items-center gap-2",
1059 - thread.runtime.lastErrorClass === "usage_limit" ? "text-warning" : "text-error",
1060 - )}
1061 - >
1062 - <CircleAlertIcon className="size-3 shrink-0 stroke-current" />
1063 - <div className="min-w-0 truncate">
1064 - {thread.runtime.lastErrorClass === "usage_limit"
1065 - ? "Usage limit reached"
1066 - : "Error occurred"}
1067 - </div>
1068 - </div>
1069 - ) : null}
1070 - </ThreadHoverCard>
1071 - </ThreadHoverCardPopup>
1072 - );
1073 -}
1074 -
1075 -function SnoozeMenuButton(props: {
1076 - open: boolean;
1077 - onOpenChange: (open: boolean) => void;
1078 - onSnooze: (preset: Pick<SnoozePreset, "snoozedUntil">) => void;
1079 - timestampFormat: TimestampFormat;
1080 -}) {
1081 - const { open, onOpenChange, onSnooze, timestampFormat } = props;
1082 - const presets = open ? resolveSnoozePresets(new Date(), timestampFormat) : [];
1083 - return (
1084 - <Menu open={open} onOpenChange={onOpenChange}>
1085 - <Tooltip>
1086 - <TooltipTrigger
1087 - render={
1088 - <MenuTrigger
1089 - render={
1090 - <button
1091 - type="button"
1092 - aria-label="Snooze thread"
1093 - onClick={(event) => event.stopPropagation()}
1094 - onDoubleClick={(event) => event.stopPropagation()}
1095 - className="inline-flex h-full cursor-pointer items-center gap-0.5 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
1096 - />
1097 - }
1098 - />
1099 - }
1100 - >
1101 - <ClockIcon className="size-3" />
1102 - </TooltipTrigger>
1103 - <TooltipPopup>Snooze thread</TooltipPopup>
1104 - </Tooltip>
1105 - <MenuPopup side="bottom" align="end">
1106 - {presets.map((preset) => (
1107 - <MenuItem
1108 - key={preset.id}
1109 - onClick={(event) => {
1110 - event.stopPropagation();
1111 - onSnooze(preset);
1112 - }}
1113 - >
1114 - {preset.label}
1115 - <MenuShortcut>{preset.whenLabel}</MenuShortcut>
1116 - </MenuItem>
1117 - ))}
1118 - <MenuSeparator />
1119 - <MenuItem
1120 - onClick={async (event) => {
1121 - event.stopPropagation();
1122 - const choice = await requestCustomSnooze();
1123 - if (choice) onSnooze(choice);
1124 - }}
1125 - >
1126 - Custom…
1127 - </MenuItem>
1128 - </MenuPopup>
1129 - </Menu>
1130 - );
1131 -}
1132 -
1133 -type SortableThreadRowBag = Pick<
1134 - ReturnType<typeof useSortable>,
1135 - "listeners" | "setNodeRef" | "transform" | "transition" | "isDragging"
1136 ->;
1137 -
1138 -// useSortable memoizes on its `disabled` object, so a fresh one per render
1139 -// re-renders every row and marker on each sidebar update.
1140 -const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;
1141 -const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;
1142 -
1143 -// Takes the row's props rather than a render function: a closure from the
1144 -// sidebar body is new on every sidebar render, which rebuilt the bag and
1145 -// re-rendered every memoized row with it.
1146 -function SortableThreadRow(
1147 - props: Omit<SidebarThreadRowProps, "sortable"> & {
1148 - sortableId: string;
1149 - sortableDisabled: boolean;
1150 - contextDrag: boolean;
1151 - },
1152 -) {
1153 - const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props;
1154 - const canOperateThread = useEnvironmentScope(
1155 - rowProps.thread.environmentId,
1156 - AuthOrchestrationOperateScope,
1157 - );
1158 - const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({
1159 - id: sortableId,
1160 - disabled:
1161 - sortableDisabled || !canOperateThread
1162 - ? SIDEBAR_SORTABLE_DRAG_DISABLED
1163 - : SIDEBAR_SORTABLE_DRAG_ENABLED,
1164 - animateLayoutChanges: animateSidebarLayoutChanges,
1165 - });
1166 - // dnd-kit memoizes each field but not the bag, so the memoized row would
1167 - // rerender on every shell update without this.
1168 - const bag = {
1169 - listeners,
1170 - setNodeRef,
1171 - transform: contextDrag ? null : transform,
1172 - transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,
1173 - isDragging: isDragging && !contextDrag,
1174 - };
1175 - // Keyed by variant so a card/slim switch remounts the row.
1176 - return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;
1177 -}
1178 -
1179 -const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8";
1180 -const draftPenClassName = "size-3 shrink-0 text-warning-foreground";
1181 -
759 function SortableSidebarMarker(props: {
760 marker: SidebarListMarker;
761 className?: string;
@@ -1235,8 +812,6 @@ function SidebarSectionPlaceholder(props: {
812
813 const SIDEBAR_DRAG_DISTANCE = 6;
814
1238 -type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";
1239 -
815 const SIDEBAR_DRAG_LABEL_HEIGHT = 24;
816
817 function SidebarDragBoundary(props: {
@@ -1509,1206 +1084,6 @@ const SidebarDraftBlock = memo(function SidebarDraftBlock(props: {
1084 );
1085 });
1086
1512 -const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
1513 - pin: (
1514 - <>
1515 - <PinIcon aria-hidden className="size-3" />
1516 - Pin
1517 - </>
1518 - ),
1519 - unpin: (
1520 - <>
1521 - <PinOffIcon aria-hidden className="size-3" />
1522 - Unpin
1523 - </>
1524 - ),
1525 - settle: (
1526 - <>
1527 - <CircleCheckIcon aria-hidden className="size-3" />
1528 - Settle
1529 - </>
1530 - ),
1531 - unsettle: (
1532 - <>
1533 - <Undo2Icon aria-hidden className="size-3" />
1534 - Un-settle
1535 - </>
1536 - ),
1537 - wake: (
1538 - <>
1539 - <AlarmClockOffIcon aria-hidden className="size-3" />
1540 - Wake
1541 - </>
1542 - ),
1543 -};
1544 -
1545 -type SidebarThreadRowProps = {
1546 - thread: SidebarThreadSummary;
1547 - variant: "card" | "slim";
1548 - variantAction: SidebarSweepAction;
1549 - settlementSupported: boolean;
1550 - snoozeSupported: boolean;
1551 - pinningSupported: boolean;
1552 - isPinned: boolean;
1553 - sortable?: SortableThreadRowBag | undefined;
1554 - dropVerb: SidebarDropVerb | null;
1555 - dragOverPinned: boolean;
1556 - sweepAction: SidebarSweepAction | null;
1557 - snoozeWakeLabelText: string | null;
1558 - wokeAt: string | null;
1559 - isActive: boolean;
1560 - // Unlike isActive, never true for the ancestor standing in for an open
1561 - // subagent: drafts and PR clicks care about which composer is on screen.
1562 - isRouteThread: boolean;
1563 - openPullRequestsInRightPanel: boolean;
1564 - jumpLabel: string | null;
1565 - currentEnvironmentId: string | null;
1566 - environmentLabel: string | null;
1567 - environmentMachine: EnvironmentMachineKind;
1568 - scratchMachineLabel: string | null;
1569 - project: EnvironmentProject | null;
1570 - projectDisplayName: string | null;
1571 - providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
1572 - timestampFormat: TimestampFormat;
1573 - onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void;
1574 - onThreadActivate: (threadRef: ScopedThreadRef) => void;
1575 - onStartRename: (threadRef: ScopedThreadRef, title: string) => void;
1576 - onRenameTitleChange: (title: string) => void;
1577 - onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void;
1578 - onCancelRename: () => void;
1579 - isRenaming: boolean;
1580 - renamingTitle: string;
1581 - onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;
1582 - onSettle: (threadRef: ScopedThreadRef) => void;
1583 - onActionSweepStart: (
1584 - threadRef: ScopedThreadRef,
1585 - action: SidebarSweepAction,
1586 - event: PointerEvent,
1587 - ) => void;
1588 - onUnsettle: (threadRef: ScopedThreadRef) => void;
1589 - onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void;
1590 - onUnsnooze: (threadRef: ScopedThreadRef) => void;
1591 - onUnpin: (threadRef: ScopedThreadRef) => void;
1592 - onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;
1593 - onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined;
1594 -};
1595 -
1596 -const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {
1597 - const {
1598 - isRenaming,
1599 - onCancelRename,
1600 - onCommitRename,
1601 - onContextMenu,
1602 - onAcknowledgeWoke,
1603 - onFileDropThreads,
1604 - onRenameTitleChange,
1605 - onSettle,
1606 - onActionSweepStart,
1607 - onSnooze,
1608 - onStartRename,
1609 - onThreadActivate,
1610 - onThreadClick,
1611 - onUnsettle,
1612 - onUnsnooze,
1613 - onUnpin,
1614 - openPullRequestsInRightPanel,
1615 - renamingTitle,
1616 - thread,
1617 - variant,
1618 - variantAction,
1619 - } = props;
1620 - const threadRef = scopeThreadRef(thread.environmentId, thread.id);
1621 - const threadKey = scopedThreadKey(threadRef);
1622 - const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);
1623 - useEffect(() => {
1624 - if (!canOperateThread && isRenaming) onCancelRename();
1625 - }, [canOperateThread, isRenaming, onCancelRename]);
1626 - const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(props.isActive);
1627 - const isRegeneratingTitle = thread.titleRegeneration != null;
1628 - const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);
1629 - const lastVisitedAt = resolveThreadLastVisitedAt(thread.lastVisitedAt, localLastVisitedAt);
1630 - const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));
1631 - const openPrLink = useOpenPrLink();
1632 - const runningTerminalIds = useThreadRunningTerminalIds({
1633 - environmentId: thread.environmentId,
1634 - threadId: thread.id,
1635 - });
1636 - const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
1637 - const terminalProcessCount = runningTerminalIds.length;
1638 - const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread;
1639 - const handleDiscardDraftClick = (event: ReactMouseEvent) => {
1640 - event.preventDefault();
1641 - event.stopPropagation();
1642 - discardComposerDraft(threadRef);
1643 - };
1644 -
1645 - const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;
1646 - const linkedPullRequestStatus = useLinkedThreadPullRequest(
1647 - thread.environmentId,
1648 - thread.linkedPullRequest,
1649 - leaseLiveStatus,
1650 - thread.pullRequests,
1651 - thread.branchPullRequest,
1652 - );
1653 - const gitStatus = useEnvironmentQuery(
1654 - leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
1655 - ? vcsEnvironment.status({
1656 - environmentId: thread.environmentId,
1657 - input: { cwd: gitCwd, includeRemote: false },
1658 - })
1659 - : null,
1660 - );
1661 - const visibleGitStatus = useRetainedValue(
1662 - JSON.stringify([thread.environmentId, gitCwd]),
1663 - gitStatus.data,
1664 - );
1665 - const pr = linkedPullRequestStatus?.pr ?? null;
1666 - const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
1667 - const currentLinkedPr = supportsMultiplePullRequests
1668 - ? resolveThreadCurrentPullRequestLink(thread.pullRequests)
1669 - : null;
1670 -
1671 - const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });
1672 - const status = resolveSidebarThreadStatus(thread);
1673 - const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
1674 - const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
1675 - const isWoke =
1676 - wokeAtDate !== null &&
1677 - (lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
1678 - thread.settledOverride !== "settled";
1679 - const shouldRecede = shouldRecedeSidebarThread({
1680 - status,
1681 - isUnread,
1682 - isWoke,
1683 - isActive: props.isActive,
1684 - isSelected,
1685 - });
1686 - const topStatus =
1687 - status === "working"
1688 - ? {
1689 - label: thread.goal?.status === "active" ? "Goal" : "Working",
1690 - icon: "working" as const,
1691 - className: "text-info",
1692 - }
1693 - : status === "waiting"
1694 - ? {
1695 - label: "Waiting",
1696 - icon: "waiting" as const,
1697 - className: "text-muted-foreground",
1698 - }
1699 - : status === "approval"
1700 - ? {
1701 - label: "Approval",
1702 - icon: "approval" as const,
1703 - className: "text-warning-foreground",
1704 - }
1705 - : status === "input"
1706 - ? {
1707 - label: "Input",
1708 - icon: "input" as const,
1709 - className: "text-indigo-600 dark:text-indigo-300",
1710 - }
1711 - : status === "limited"
1712 - ? {
1713 - label: "Limited",
1714 - icon: "failed" as const,
1715 - className: "text-warning",
1716 - }
1717 - : status === "failed"
1718 - ? {
1719 - label: "Failed",
1720 - icon: "failed" as const,
1721 - className: "text-error",
1722 - }
1723 - : isWoke
1724 - ? {
1725 - label: "Woke",
1726 - icon: "woke" as const,
1727 - className: "text-warning",
1728 - }
1729 - : isUnread
1730 - ? {
1731 - label: "Done",
1732 - icon: "done" as const,
1733 - className: "text-success",
1734 - }
1735 - : null;
1736 - const isWokeStatus = topStatus?.icon === "woke";
1737 -
1738 - const branchMismatch = resolveLocalCheckoutBranchMismatch({
1739 - effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
1740 - activeWorktreePath: thread.worktreePath,
1741 - activeThreadBranch: thread.branch,
1742 - currentGitBranch: visibleGitStatus?.refName ?? null,
1743 - });
1744 - const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider);
1745 -
1746 - const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;
1747 - const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
1748 - const showInstanceBadge =
1749 - providerEntry !== null &&
1750 - shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
1751 - const selectedModel = providerEntry?.models.find(
1752 - (model) => model.slug === thread.modelSelection.model,
1753 - );
1754 - const modelLabel = selectedModel
1755 - ? getTriggerDisplayModelLabel(selectedModel)
1756 - : thread.modelSelection.model;
1757 -
1758 - const isRemote = thread.environmentId !== props.currentEnvironmentId;
1759 - const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;
1760 -
1761 - const detailsTooltip = (
1762 - <SidebarThreadTooltip
1763 - thread={thread}
1764 - project={props.project}
1765 - projectDisplayName={props.projectDisplayName}
1766 - environmentLabel={props.environmentLabel}
1767 - environmentMachine={props.environmentMachine}
1768 - providerEntry={providerEntry}
1769 - providerEntryByInstanceId={props.providerEntryByInstanceId}
1770 - showInstanceBadge={showInstanceBadge}
1771 - modelInstanceId={modelInstanceId}
1772 - modelLabel={modelLabel}
1773 - branchMismatch={branchMismatch}
1774 - terminalStatus={terminalStatus}
1775 - terminalProcessCount={terminalProcessCount}
1776 - />
1777 - );
1778 -
1779 - const handleClick = (event: ReactMouseEvent) => {
1780 - onThreadClick(event, threadRef);
1781 - };
1782 - const handleAcknowledgeWokeClick = (event: ReactMouseEvent) => {
1783 - event.preventDefault();
1784 - event.stopPropagation();
1785 - if (props.wokeAt === null) return;
1786 - onAcknowledgeWoke(threadRef, props.wokeAt);
1787 - };
1788 - const handleContextMenu = (event: ReactMouseEvent) => {
1789 - event.preventDefault();
1790 - onContextMenu(threadRef, { x: event.clientX, y: event.clientY });
1791 - };
1792 - const handleKeyDown = (event: ReactKeyboardEvent) => {
1793 - if (event.target !== event.currentTarget) return;
1794 - if (event.key !== "Enter" && event.key !== " ") return;
1795 - event.preventDefault();
1796 - onThreadActivate(threadRef);
1797 - };
1798 - const handleDoubleClick = (event: ReactMouseEvent) => {
1799 - if (
1800 - !readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) ||
1801 - isRenaming ||
1802 - event.metaKey ||
1803 - event.ctrlKey ||
1804 - event.shiftKey ||
1805 - event.altKey
1806 - ) {
1807 - return;
1808 - }
1809 - if ((event.target as HTMLElement).closest("button, a, input")) return;
1810 - event.preventDefault();
1811 - onStartRename(threadRef, thread.title);
1812 - };
1813 - const [isFileDragOver, setIsFileDragOver] = useState(false);
1814 - const fileDropHandlers = onFileDropThreads
1815 - ? makeWorkspaceFileDropHandlers({
1816 - setDragActive: setIsFileDragOver,
1817 - addFiles: (files) => {
1818 - onFileDropThreads(threadRef, files);
1819 - },
1820 - addFolders: () => {},
1821 - })
1822 - : null;
1823 - useEffect(() => {
1824 - if (!isFileDragOver) return;
1825 - const clearFileDrag = () => setIsFileDragOver(false);
1826 - window.addEventListener("dragend", clearFileDrag);
1827 - return () => window.removeEventListener("dragend", clearFileDrag);
1828 - }, [isFileDragOver]);
1829 - const renameCommittedRef = useRef(false);
1830 - useEffect(() => {
1831 - if (isRenaming) renameCommittedRef.current = false;
1832 - }, [isRenaming]);
1833 - const handleRenameKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
1834 - event.stopPropagation();
1835 - if (event.nativeEvent.isComposing || event.keyCode === 229) return;
1836 - if (event.key === "Enter") {
1837 - event.preventDefault();
1838 - renameCommittedRef.current = true;
1839 - onCommitRename(threadRef, renamingTitle, thread.title);
1840 - } else if (event.key === "Escape") {
1841 - event.preventDefault();
1842 - renameCommittedRef.current = true;
1843 - onCancelRename();
1844 - }
1845 - };
1846 - const handleRenameBlur = () => {
1847 - if (!renameCommittedRef.current) {
1848 - onCommitRename(threadRef, renamingTitle, thread.title);
1849 - }
1850 - };
1851 - const handleSettleClick = (event: ReactMouseEvent) => {
1852 - event.preventDefault();
1853 - event.stopPropagation();
1854 - onSettle(threadRef);
1855 - };
1856 - const handleActionPointerDown = (event: ReactPointerEvent) => {
1857 - if (!event.isPrimary || event.button !== 0) return;
1858 - event.stopPropagation();
1859 - onActionSweepStart(threadRef, variantAction, event.nativeEvent);
1860 - };
1861 - const handleUnsettleClick = (event: ReactMouseEvent) => {
1862 - event.preventDefault();
1863 - event.stopPropagation();
1864 - onUnsettle(threadRef);
1865 - };
1866 - const handleUnsnoozeClick = (event: ReactMouseEvent) => {
1867 - event.preventDefault();
1868 - event.stopPropagation();
1869 - onUnsnooze(threadRef);
1870 - };
1871 - const handleUnpinClick = (event: ReactMouseEvent) => {
1872 - event.preventDefault();
1873 - event.stopPropagation();
1874 - onUnpin(threadRef);
1875 - };
1876 - const handleSnoozePreset = (preset: Pick<SnoozePreset, "snoozedUntil">) => {
1877 - onSnooze(threadRef, preset);
1878 - };
1879 - const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);
1880 - // The React Compiler caches render results on their inputs, so a clock read
1881 - // here would stay frozen until `thread` changes and a queued-turn gate would
1882 - // never reopen. The gate's clock is state, reset with the thread.
1883 - const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({
1884 - thread,
1885 - now: new Date().toISOString(),
1886 - }));
1887 - if (snoozeGateClock.thread !== thread) {
1888 - setSnoozeGateClock({ thread, now: new Date().toISOString() });
1889 - }
1890 - const snoozeGateNow = snoozeGateClock.now;
1891 - const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })
1892 - ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS
1893 - : Number.NaN;
1894 - useEffect(() => {
1895 - // A gate still closed past its expiry is held by runtime status, not time,
1896 - // so no clock tick can open it.
1897 - if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {
1898 - return;
1899 - }
1900 - const id = window.setTimeout(
1901 - () => setSnoozeGateClock({ thread, now: new Date().toISOString() }),
1902 - Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),
1903 - );
1904 - return () => window.clearTimeout(id);
1905 - }, [snoozeGateExpiryMs, snoozeGateNow, thread]);
1906 - const showSnoozeButton =
1907 - canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });
1908 - // Closing here, not just masking, keeps the menu from reopening when the button returns.
1909 - if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
1910 - const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;
1911 - const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {
1912 - const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;
1913 - if (!url) return;
1914 - const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
1915 - const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
1916 - if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
1917 - onThreadActivate(threadRef);
1918 - }
1919 - };
1920 -
1921 - const rowSurfaceClassName = cn(
1922 - "group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
1923 - variantAction === "unsettle" && "[&:not(:hover):not(:focus-within)_*]:text-secondary-label/70",
1924 - props.isActive
1925 - ? "bg-sidebar-row-active text-sidebar-foreground"
1926 - : isSelected || props.sweepAction !== null
1927 - ? "bg-sidebar-row-selected text-sidebar-foreground"
1928 - : hasUnsentDraft
1929 - ? cn(draftSurfaceClassName, "text-sidebar-foreground")
1930 - : shouldRecede
1931 - ? "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"
1932 - : "bg-transparent text-sidebar-foreground hover:bg-sidebar-row-hover",
1933 - shouldRecede &&
1934 - status === "working" &&
1935 - "opacity-70 transition-opacity hover:opacity-100 focus-within:opacity-100 motion-reduce:transition-none",
1936 - isFileDragOver && "ring-1 ring-inset ring-primary/70",
1937 - isFileDragOver && !props.isActive && !isSelected && "bg-sidebar-row-hover",
1938 - props.sortable?.isDragging &&
1939 - "bg-sidebar bg-linear-to-b from-sidebar-row-active to-sidebar-row-active text-sidebar-foreground opacity-100 shadow-lg",
1940 - );
1941 - const sortable = props.sortable;
1942 - const sortableRootProps = sortable
1943 - ? {
1944 - ref: sortable.setNodeRef,
1945 - style: {
1946 - transform: CSS.Translate.toString(sortable.transform),
1947 - transition: sortable.transition,
1948 - // A zero-height boundary also makes dnd-kit scale the source to
1949 - // zero. Only projected peers use scaleY as a visibility sentinel.
1950 - visibility:
1951 - !sortable.isDragging && sortable.transform?.scaleY === 0
1952 - ? ("hidden" as const)
1953 - : undefined,
1954 - },
1955 - ...sortable.listeners,
1956 - }
1957 - : {};
1958 - const destinationVerb = sortable?.isDragging
1959 - ? props.dropVerb
1960 - : props.sweepAction === "unsnooze"
1961 - ? "wake"
1962 - : props.sweepAction;
1963 - const dragDestination =
1964 - destinationVerb !== null ? (
1965 - <span
1966 - role="status"
1967 - className="pointer-events-none ml-auto inline-flex h-5 shrink-0 items-center gap-1 rounded-sm border border-primary/40 bg-primary/10 px-1.5 text-2xs font-medium text-primary"
1968 - >
1969 - {dropVerbBadge[destinationVerb]}
1970 - </span>
1971 - ) : null;
1972 -
1973 - const accessibility = resolveSidebarRowAccessibility({
1974 - title: thread.title,
1975 - statusLabel: topStatus?.label ?? null,
1976 - projectDisplayName: props.projectDisplayName,
1977 - isActive: props.isActive,
1978 - });
1979 -
1980 - const title =
1981 - isRenaming && canOperateThread ? (
1982 - <input
1983 - autoFocus
1984 - value={renamingTitle}
1985 - aria-label="Thread title"
1986 - onChange={(event) => onRenameTitleChange(event.target.value)}
1987 - onFocus={(event) => event.currentTarget.select()}
1988 - onKeyDown={handleRenameKeyDown}
1989 - onBlur={handleRenameBlur}
1990 - onClick={(event) => event.stopPropagation()}
1991 - onDoubleClick={(event) => event.stopPropagation()}
1992 - className="min-w-0 flex-1 rounded-sm border border-input bg-card px-1 text-sm font-medium text-card-foreground outline-none focus:border-foreground"
1993 - />
1994 - ) : (
1995 - <span
1996 - aria-hidden
1997 - className={cn(
1998 - "min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",
1999 - shouldRecede ? "font-normal" : "font-medium",
2000 - variant === "card"
2001 - ? cn(
2002 - "truncate",
2003 - shouldRecede
2004 - ? "text-secondary-label"
2005 - : isUnread || isWoke || status === "input"
2006 - ? "text-foreground"
2007 - : status === "failed"
2008 - ? "text-foreground/95"
2009 - : "text-foreground/90",
2010 - )
2011 - : cn(
2012 - "truncate group-focus-within/sidebar-row:text-foreground group-hover/sidebar-row:text-foreground",
2013 - shouldRecede
2014 - ? "text-secondary-label/70"
2015 - : props.isActive || isWoke || status === "input"
2016 - ? "text-foreground"
2017 - : isUnread
2018 - ? "text-muted-foreground"
2019 - : "text-secondary-label/70",
2020 - ),
2021 - isRegeneratingTitle && "opacity-55",
2022 - )}
2023 - >
2024 - {thread.title}
2025 - </span>
2026 - );
2027 - const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;
2028 -
2029 - const prBadgeShape = supportsMultiplePullRequests
2030 - ? resolveThreadPullRequestBadge(thread.pullRequests)
2031 - : null;
2032 - const handlePrListClick = () => {
2033 - useRightPanelStore.getState().open(threadRef, "pull-requests");
2034 - if (!props.isRouteThread) onThreadActivate(threadRef);
2035 - };
2036 - const prBadge =
2037 - prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? (
2038 - <ThreadPullRequestBadgeControl
2039 - render={<InlineButton />}
2040 - badge={prBadgeShape}
2041 - pullRequests={thread.pullRequests}
2042 - number={pr?.number ?? currentLinkedPr?.number}
2043 - url={pr?.url ?? currentLinkedPr?.url}
2044 - status={prStatus}
2045 - onOpenList={handlePrListClick}
2046 - onOpenPullRequest={handlePrClick}
2047 - />
2048 - ) : null;
2049 - const terminalStatusIcon = (
2050 - <ThreadTerminalStatusButton
2051 - threadRef={threadRef}
2052 - terminalIds={runningTerminalIds}
2053 - onThreadActivate={onThreadActivate}
2054 - />
2055 - );
2056 - const draftIndicator = hasUnsentDraft ? (
2057 - <Tooltip>
2058 - <TooltipTrigger
2059 - render={
2060 - <span
2061 - role="img"
2062 - aria-label="Unsent draft"
2063 - data-testid={`sidebar-draft-indicator-${thread.id}`}
2064 - className="inline-flex shrink-0 items-center"
2065 - />
2066 - }
2067 - >
2068 - <SquarePenIcon aria-hidden className={draftPenClassName} />
2069 - </TooltipTrigger>
2070 - <TooltipPopup side="top">Unsent draft</TooltipPopup>
2071 - </Tooltip>
2072 - ) : null;
2073 - const showPin =
2074 - props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null));
2075 - const pinIndicator = showPin ? (
2076 - props.pinningSupported && canOperateThread && !sortable?.isDragging ? (
2077 - <Tooltip>
2078 - <TooltipTrigger
2079 - render={
2080 - <button
2081 - type="button"
2082 - aria-label="Unpin thread"
2083 - onClick={handleUnpinClick}
2084 - className="group/unpin inline-flex cursor-pointer items-center rounded-sm text-muted-foreground/65 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
2085 - />
2086 - }
2087 - >
2088 - <PinIcon
2089 - aria-hidden
2090 - className="size-3 shrink-0 group-hover/unpin:hidden group-focus-visible/unpin:hidden"
2091 - />
2092 - <PinOffIcon
2093 - aria-hidden
2094 - className="hidden size-3 shrink-0 group-hover/unpin:block group-focus-visible/unpin:block"
2095 - />
2096 - </TooltipTrigger>
2097 - <TooltipPopup>Unpin thread</TooltipPopup>
2098 - </Tooltip>
2099 - ) : (
2100 - <PinIcon
2101 - aria-label="Pinned"
2102 - role="img"
2103 - className="size-3 shrink-0 text-muted-foreground/65"
2104 - />
2105 - )
2106 - ) : null;
2107 -
2108 - if (variant === "slim") {
2109 - return (
2110 - <li
2111 - data-thread-item={threadKey}
2112 - {...sortableRootProps}
2113 - {...(fileDropHandlers ?? {})}
2114 - className={cn(
2115 - "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]",
2116 - sortable?.isDragging && "relative z-20",
2117 - )}
2118 - >
2119 - <Tooltip disabled={sortable?.isDragging}>
2120 - <TooltipTrigger
2121 - render={
2122 - <div
2123 - ref={rowRef}
2124 - role="button"
2125 - tabIndex={0}
2126 - aria-label={accessibility.label}
2127 - aria-current={accessibility.current}
2128 - data-testid="sidebar-row-slim"
2129 - aria-busy={isRegeneratingTitle || undefined}
2130 - className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}
2131 - onClick={handleClick}
2132 - onDoubleClick={handleDoubleClick}
2133 - onKeyDown={handleKeyDown}
2134 - onContextMenu={handleContextMenu}
2135 - />
2136 - }
2137 - >
2138 - {accessibleTitle}
2139 - <span
2140 - className={cn(
2141 - "flex shrink-0 items-center transition-opacity",
2142 - (!props.isActive || variantAction === "unsettle") &&
2143 - "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",
2144 - )}
2145 - >
2146 - {props.project ? <ProjectFavicon project={props.project} className="size-4" /> : null}
2147 - </span>
2148 - {draftIndicator}
2149 - {title}
2150 - {pinIndicator}
2151 - {terminalStatusIcon}
2152 - {isRegeneratingTitle ? (
2153 - <span role="status" className="sr-only">
2154 - Regenerating title
2155 - </span>
2156 - ) : null}
2157 - {prBadge}
2158 - {sortable?.isDragging ? (
2159 - dragDestination
2160 - ) : (
2161 - <span
2162 - className={cn(
2163 - "relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end",
2164 - props.sweepAction !== null && "hidden",
2165 - )}
2166 - >
2167 - <span
2168 - className={cn(
2169 - "inline-flex justify-end tabular-nums text-secondary-label transition-opacity",
2170 - !isWoke && "group-any-hover/sidebar-row:opacity-0",
2171 - )}
2172 - >
2173 - {variantAction === "unsnooze" && props.snoozeWakeLabelText !== null ? (
2174 - <span className="text-xs text-info-foreground tabular-nums">
2175 - {props.snoozeWakeLabelText}
2176 - </span>
2177 - ) : isWoke ? (
2178 - <Tooltip>
2179 - <TooltipTrigger
2180 - render={
2181 - <button
2182 - type="button"
2183 - aria-label="Dismiss Woke notification"
2184 - onClick={handleAcknowledgeWokeClick}
2185 - className="inline-flex cursor-pointer items-center gap-1 rounded-sm text-xs font-medium text-warning-foreground outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
2186 - >
2187 - <AlarmClockIcon aria-hidden className="size-3" />
2188 - <span role="status">Woke</span>
2189 - </button>
2190 - }
2191 - />
2192 - <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>
2193 - </Tooltip>
2194 - ) : (
2195 - <span className="text-xs">
2196 - <RelativeTimeLabel
2197 - timestamp={
2198 - variantAction === "unsettle"
2199 - ? resolveSettledThreadTimestamp(thread)
2200 - : threadTimeTimestamp(thread)
2201 - }
2202 - />
2203 - </span>
2204 - )}
2205 - </span>
2206 - {variantAction === "unsnooze" ? (
2207 - !props.snoozeSupported ? null : (
2208 - <button
2209 - type="button"
2210 - aria-label="Wake thread now"
2211 - onClick={handleUnsnoozeClick}
2212 - onPointerDown={handleActionPointerDown}
2213 - className={cn(
2214 - "pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
2215 - isWoke && "group-any-hover/sidebar-row:static",
2216 - )}
2217 - >
2218 - <AlarmClockOffIcon className="mb-px size-3" />
2219 - </button>
2220 - )
2221 - ) : !props.settlementSupported ? null : variantAction === "unsettle" ? (
2222 - <Tooltip>
2223 - <TooltipTrigger
2224 - render={
2225 - <button
2226 - type="button"
2227 - aria-label="Un-settle thread"
2228 - onClick={handleUnsettleClick}
2229 - onPointerDown={handleActionPointerDown}
2230 - className={cn(
2231 - "pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
2232 - isWoke && "group-any-hover/sidebar-row:static",
2233 - )}
2234 - />
2235 - }
2236 - >
2237 - <Undo2Icon className="mb-px size-3.5" />
2238 - </TooltipTrigger>
2239 - <TooltipPopup side="top">Un-settle thread</TooltipPopup>
2240 - </Tooltip>
2241 - ) : (
2242 - <button
2243 - type="button"
2244 - aria-label="Settle thread"
2245 - onClick={handleSettleClick}
2246 - onPointerDown={handleActionPointerDown}
2247 - className={cn(
2248 - "pointer-events-none absolute inset-y-0 right-0 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-2 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
2249 - isWoke && "group-any-hover/sidebar-row:static",
2250 - )}
2251 - >
2252 - <CheckIcon className="size-3" />
2253 - </button>
2254 - )}
2255 - </span>
2256 - )}
2257 - {props.sweepAction !== null ? dragDestination : null}
2258 - {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}
2259 - </TooltipTrigger>
2260 - {detailsTooltip}
2261 - </Tooltip>
2262 - </li>
2263 - );
2264 - }
2265 -
2266 - const diff = latestRunDiff(thread);
2267 -
2268 - return (
2269 - <li
2270 - data-thread-item={threadKey}
2271 - {...sortableRootProps}
2272 - {...(fileDropHandlers ?? {})}
2273 - className={cn(
2274 - "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",
2275 - sortable?.isDragging && "relative z-20",
2276 - )}
2277 - >
2278 - <Tooltip disabled={snoozeMenuOpen || sortable?.isDragging}>
2279 - <TooltipTrigger
2280 - render={
2281 - <div
2282 - ref={rowRef}
2283 - role="button"
2284 - tabIndex={0}
2285 - aria-label={accessibility.label}
2286 - aria-current={accessibility.current}
2287 - data-testid="sidebar-row-card"
2288 - aria-busy={isRegeneratingTitle || undefined}
2289 - className={rowSurfaceClassName}
2290 - onClick={handleClick}
2291 - onDoubleClick={handleDoubleClick}
2292 - onKeyDown={handleKeyDown}
2293 - onContextMenu={handleContextMenu}
2294 - />
2295 - }
2296 - >
2297 - {accessibleTitle}
2298 - <div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
2299 - <div className="flex h-5 min-w-0 items-center gap-1.5">
2300 - {draftIndicator}
2301 - {props.project ? (
2302 - <ProjectFavicon project={props.project} className="size-4 shrink-0" />
2303 - ) : null}
2304 - {/* Left of the status slot, the pin would slide when hover swaps the
2305 - label for the wider row controls. */}
2306 - {pinIndicator}
2307 - {props.projectDisplayName ? (
2308 - <span
2309 - className={cn(
2310 - "min-w-0 flex-1 truncate text-secondary-label text-xs",
2311 - shouldRecede ? "font-normal" : "font-medium",
2312 - )}
2313 - >
2314 - {props.projectDisplayName}
2315 - </span>
2316 - ) : (
2317 - <span className="flex-1" />
2318 - )}
2319 - {sortable?.isDragging ? (
2320 - dragDestination
2321 - ) : (
2322 - <span
2323 - className={cn(
2324 - "group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs",
2325 - props.sweepAction !== null && "hidden",
2326 - )}
2327 - >
2328 - <span
2329 - className={cn(
2330 - isWokeStatus
2331 - ? "pointer-events-auto"
2332 - : "pointer-events-none group-has-[:focus-visible]/sidebar-status-slot:absolute group-has-[:focus-visible]/sidebar-status-slot:right-0 group-has-[:focus-visible]/sidebar-status-slot:opacity-0 group-any-hover/sidebar-row:absolute group-any-hover/sidebar-row:right-0 group-any-hover/sidebar-row:opacity-0",
2333 - "flex items-center self-center justify-self-end tabular-nums text-secondary-label transition-opacity",
2334 - snoozeMenuOpen && "pointer-events-none absolute right-0 opacity-0",
2335 - )}
2336 - >
2337 - {topStatus ? (
2338 - isWokeStatus ? (
2339 - <Tooltip>
2340 - <TooltipTrigger
2341 - render={
2342 - <button
2343 - type="button"
2344 - aria-label="Dismiss Woke notification"
2345 - onClick={handleAcknowledgeWokeClick}
2346 - className={cn(
2347 - "inline-flex cursor-pointer items-center gap-1 rounded-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
2348 - topStatus.className,
2349 - )}
2350 - >
2351 - <AlarmClockIcon aria-hidden className="size-4 shrink-0" />
2352 - <span role="status">{topStatus.label}</span>
2353 - </button>
2354 - }
2355 - />
2356 - <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>
2357 - </Tooltip>
2358 - ) : (
2359 - <span
2360 - className={cn(
2361 - "inline-flex items-center gap-1 font-medium",
2362 - topStatus.className,
2363 - )}
2364 - >
2365 - {topStatus.icon === "working" ? (
2366 - <CircleDashedIcon aria-hidden className="size-4 shrink-0" />
2367 - ) : topStatus.icon === "waiting" ? (
2368 - <CircleDotDashedIcon aria-hidden className="size-4 shrink-0" />
2369 - ) : topStatus.icon === "input" ? (
2370 - <MessageCircleQuestionIcon aria-hidden className="size-4 shrink-0" />
2371 - ) : topStatus.icon === "approval" ? (
2372 - <ShieldQuestionIcon aria-hidden className="size-4 shrink-0" />
2373 - ) : topStatus.icon === "failed" ? (
2374 - <CircleAlertIcon aria-hidden className="size-4 shrink-0" />
2375 - ) : topStatus.icon === "done" ? (
2376 - <CircleCheckIcon aria-hidden className="size-4 shrink-0" />
2377 - ) : null}
2378 - {/* The label alone is the live region: a role="status"
2379 - wrapper around the ticking duration would make
2380 - screen readers announce every second. */}
2381 - <span role="status">{topStatus.label}</span>
2382 - {status === "working" ? (
2383 - <span aria-hidden>
2384 - <WorkingDuration startedAt={resolveWorkingStartedAt(thread)} />
2385 - </span>
2386 - ) : status === "waiting" ? (
2387 - <span aria-hidden>
2388 - <WorkingDuration startedAt={thread.latestRun?.completedAt ?? null} />
2389 - </span>
2390 - ) : null}
2391 - </span>
2392 - )
2393 - ) : (
2394 - <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
2395 - )}
2396 - </span>
2397 - {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (
2398 - <span
2399 - className={cn(
2400 - // focus-visible, not focus-within: a mouse click leaves
2401 - // the Settle button focused, and a plain focus-within
2402 - // would keep the controls pinned over the status label
2403 - // once the pointer moves away (e.g. after a failed
2404 - // settle) instead of cross-fading back.
2405 - "pointer-events-none absolute inset-y-0 right-0 flex items-stretch opacity-0 transition-opacity has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:static has-[:focus-visible]:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:static group-any-hover/sidebar-row:opacity-100",
2406 - snoozeMenuOpen && "pointer-events-auto static opacity-100",
2407 - )}
2408 - >
2409 - {hasUnsentDraft ? (
2410 - <Tooltip>
2411 - <TooltipTrigger
2412 - render={
2413 - <button
2414 - type="button"
2415 - aria-label="Discard draft"
2416 - onClick={handleDiscardDraftClick}
2417 - className="inline-flex cursor-pointer items-center rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
2418 - />
2419 - }
2420 - >
2421 - <XIcon className="size-3.5" />
2422 - </TooltipTrigger>
2423 - <TooltipPopup side="top">Discard draft</TooltipPopup>
2424 - </Tooltip>
2425 - ) : null}
2426 - {showSnoozeButton ? (
2427 - <SnoozeMenuButton
2428 - open={snoozeMenuOpen}
2429 - onOpenChange={setSnoozeMenuOpen}
2430 - onSnooze={handleSnoozePreset}
2431 - timestampFormat={props.timestampFormat}
2432 - />
2433 - ) : null}
2434 - {props.settlementSupported ? (
2435 - <Tooltip>
2436 - <TooltipTrigger
2437 - render={
2438 - <button
2439 - type="button"
2440 - aria-label="Settle thread"
2441 - onClick={handleSettleClick}
2442 - onPointerDown={handleActionPointerDown}
2443 - className="-mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
2444 - />
2445 - }
2446 - >
2447 - <CheckIcon className="size-3.5" />
2448 - Settle
2449 - </TooltipTrigger>
2450 - <TooltipPopup>Settle thread</TooltipPopup>
2451 - </Tooltip>
2452 - ) : null}
2453 - </span>
2454 - ) : null}
2455 - </span>
2456 - )}
2457 - {props.sweepAction !== null ? dragDestination : null}
2458 - </div>
2459 - <div className="mt-1 flex min-w-0">
2460 - {title}
2461 - {isRegeneratingTitle ? (
2462 - <span role="status" className="sr-only">
2463 - Regenerating title
2464 - </span>
2465 - ) : null}
2466 - </div>
2467 - <div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
2468 - {thread.branch ? (
2469 - <>
2470 - <ThreadWorktreeIndicator thread={thread} />
2471 - <span className="flex min-w-0 flex-1 text-muted-foreground/40">
2472 - <MiddleTruncate value={thread.branch} showTitle={false} />
2473 - </span>
2474 - </>
2475 - ) : showsScratchMachine ? (
2476 - <>
2477 - <EnvironmentMachineIcon
2478 - aria-hidden
2479 - kind={props.environmentMachine}
2480 - className="size-3 shrink-0 text-muted-foreground/40"
2481 - />
2482 - <span className="min-w-0 flex-1 truncate text-muted-foreground/40">
2483 - {props.scratchMachineLabel}
2484 - </span>
2485 - </>
2486 - ) : (
2487 - <span className="flex-1" />
2488 - )}
2489 - {terminalStatusIcon}
2490 - {prBadge}
2491 - {diff ? (
2492 - <span className="shrink-0 font-mono">
2493 - <span className="text-diff-addition-foreground">
2494 - +{formatDiffCount(diff.insertions)}
2495 - </span>{" "}
2496 - <span className="text-diff-deletion-foreground">
2497 - −{formatDiffCount(diff.deletions)}
2498 - </span>
2499 - </span>
2500 - ) : null}
2501 - <span
2502 - aria-hidden
2503 - className="pointer-events-none ml-auto inline-flex shrink-0 items-center gap-1"
2504 - >
2505 - {isRemote && !showsScratchMachine ? (
2506 - <span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70">
2507 - <EnvironmentMachineIcon
2508 - aria-hidden
2509 - kind={props.environmentMachine}
2510 - className="size-3.5"
2511 - />
2512 - </span>
2513 - ) : null}
2514 - <SidebarProviderStack
2515 - thread={thread}
2516 - providerEntryByInstanceId={props.providerEntryByInstanceId}
2517 - />
2518 - </span>
2519 - </div>
2520 - </div>
2521 - {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}
2522 - </TooltipTrigger>
2523 - {detailsTooltip}
2524 - </Tooltip>
2525 - </li>
2526 - );
2527 -});
2528 -
2529 -function latestRunDiff(
2530 - thread: SidebarThreadSummary,
2531 -): { insertions: number; deletions: number } | null {
2532 - void thread;
2533 - return null;
2534 -}
2535 -
2536 -const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
2537 - isSettled: boolean;
2538 - thread: SidebarThreadSummary;
2539 - project: EnvironmentProject | null;
2540 - projectDisplayName: string | null;
2541 - environmentLabel: string | null;
2542 - environmentMachine: EnvironmentMachineKind;
2543 - providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
2544 - isHighlighted: boolean;
2545 - isRouteActive: boolean;
2546 - resultId: string;
2547 - searchMatch: EnvironmentThreadSearchMatch | null;
2548 - searchQuery: string;
2549 - onHighlight: () => void;
2550 - onSelect: () => void;
2551 - onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;
2552 -}) {
2553 - const { thread } = props;
2554 - const accessibility = resolveSidebarRowAccessibility({
2555 - title: thread.title,
2556 - statusLabel: null,
2557 - projectDisplayName: props.projectDisplayName,
2558 - isActive: props.isRouteActive,
2559 - });
2560 - const threadRef = scopeThreadRef(thread.environmentId, thread.id);
2561 - const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(
2562 - props.isHighlighted || props.isRouteActive,
2563 - );
2564 - const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;
2565 - const gitStatus = useEnvironmentQuery(
2566 - leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
2567 - ? vcsEnvironment.status({
2568 - environmentId: thread.environmentId,
2569 - input: { cwd: gitCwd, includeRemote: false },
2570 - })
2571 - : null,
2572 - );
2573 - const visibleGitStatus = useRetainedValue(
2574 - JSON.stringify([thread.environmentId, gitCwd]),
2575 - gitStatus.data,
2576 - );
2577 - const branchMismatch = resolveLocalCheckoutBranchMismatch({
2578 - effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
2579 - activeWorktreePath: thread.worktreePath,
2580 - activeThreadBranch: thread.branch,
2581 - currentGitBranch: visibleGitStatus?.refName ?? null,
2582 - });
2583 - const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;
2584 - const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
2585 - const showInstanceBadge =
2586 - providerEntry !== null &&
2587 - shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
2588 - const selectedModel = providerEntry?.models.find(
2589 - (model) => model.slug === thread.modelSelection.model,
2590 - );
2591 - const modelLabel = selectedModel
2592 - ? getTriggerDisplayModelLabel(selectedModel)
2593 - : thread.modelSelection.model;
2594 - const runningTerminalIds = useThreadRunningTerminalIds({
2595 - environmentId: thread.environmentId,
2596 - threadId: thread.id,
2597 - });
2598 - const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
2599 - const [isFileDragOver, setIsFileDragOver] = useState(false);
2600 - const onFileDropThreads = props.onFileDropThreads;
2601 - const fileDropHandlers = makeWorkspaceFileDropHandlers({
2602 - setDragActive: setIsFileDragOver,
2603 - addFiles: (files) => {
2604 - onFileDropThreads(threadRef, files);
2605 - },
2606 - addFolders: () => {},
2607 - });
2608 - useEffect(() => {
2609 - if (!isFileDragOver) return;
2610 - const clearFileDrag = () => setIsFileDragOver(false);
2611 - window.addEventListener("dragend", clearFileDrag);
2612 - return () => window.removeEventListener("dragend", clearFileDrag);
2613 - }, [isFileDragOver]);
2614 - return (
2615 - <li role="presentation" className="list-none" {...fileDropHandlers}>
2616 - <Tooltip>
2617 - <TooltipTrigger
2618 - render={
2619 - <button
2620 - ref={rowRef}
2621 - id={props.resultId}
2622 - data-search-result-key={scopedThreadKey(threadRef)}
2623 - type="button"
2624 - role="option"
2625 - tabIndex={-1}
2626 - aria-selected={props.isHighlighted}
2627 - aria-current={accessibility.current}
2628 - aria-describedby={`${props.resultId}-pr`}
2629 - aria-label={accessibility.label}
2630 - onMouseMove={props.onHighlight}
2631 - onClick={props.onSelect}
2632 - className={cn(
2633 - "group/sidebar-row group/v2-row flex min-h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1 text-left text-sm outline-none",
2634 - props.isHighlighted || props.isRouteActive
2635 - ? "bg-sidebar-row-active text-sidebar-foreground"
2636 - : "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground",
2637 - isFileDragOver && "ring-1 ring-inset ring-primary/70",
2638 - isFileDragOver && !props.isRouteActive && "bg-sidebar-row-hover",
2639 - )}
2640 - />
2641 - }
2642 - >
2643 - {props.project ? (
2644 - <ProjectFavicon
2645 - project={props.project}
2646 - className={cn(
2647 - "size-4 shrink-0 transition-opacity",
2648 - props.isSettled &&
2649 - !props.isRouteActive &&
2650 - !props.isHighlighted &&
2651 - "opacity-40 grayscale group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",
2652 - )}
2653 - />
2654 - ) : null}
2655 - <span className="flex min-w-0 flex-1 flex-col">
2656 - <span className="flex min-w-0 items-center gap-2.5">
2657 - <span
2658 - className={cn(
2659 - "min-w-0 flex-1 truncate",
2660 - props.isSettled
2661 - ? "font-normal text-secondary-label/70 group-hover/sidebar-row:text-foreground"
2662 - : "font-medium text-foreground",
2663 - (props.isHighlighted || props.isRouteActive) && "text-foreground",
2664 - thread.titleRegeneration != null && "opacity-55",
2665 - )}
2666 - >
2667 - {thread.title}
2668 - </span>
2669 - <span id={`${props.resultId}-pr`} className="contents">
2670 - <ThreadSearchPullRequestNumber
2671 - thread={thread}
2672 - query={props.searchQuery}
2673 - enabled={leaseLiveStatus}
2674 - settled={props.isSettled}
2675 - />
2676 - </span>
2677 - <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">
2678 - <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
2679 - </span>
2680 - </span>
2681 - {props.searchMatch ? (
2682 - <ThreadSearchMatchExcerpt
2683 - match={{
2684 - source: props.searchMatch.source,
2685 - snippet: props.searchMatch.snippet,
2686 - query: props.searchQuery,
2687 - }}
2688 - />
2689 - ) : null}
2690 - </span>
2691 - </TooltipTrigger>
2692 - <SidebarThreadTooltip
2693 - thread={thread}
2694 - project={props.project}
2695 - projectDisplayName={props.projectDisplayName}
2696 - environmentLabel={props.environmentLabel}
2697 - environmentMachine={props.environmentMachine}
2698 - providerEntry={providerEntry}
2699 - providerEntryByInstanceId={props.providerEntryByInstanceId}
2700 - showInstanceBadge={showInstanceBadge}
2701 - modelInstanceId={modelInstanceId}
2702 - modelLabel={modelLabel}
2703 - branchMismatch={branchMismatch}
2704 - terminalStatus={terminalStatus}
2705 - terminalProcessCount={runningTerminalIds.length}
2706 - />
2707 - </Tooltip>
2708 - </li>
2709 - );
2710 -});
2711 -
1087 export default function Sidebar() {
1088 const {
1089 projects,
apps/web/src/components/sidebar/SidebarThreadRow.tsx new
+1668
@@ -0,0 +1,1668 @@
1 +import { ThreadHoverCard, ThreadHoverCardPopup } from "../ThreadHoverCard";
2 +import { ThreadTerminalStatusButton } from "../ThreadStatusIndicators";
3 +import { discardComposerDraft } from "../../lib/discardComposerDraft";
4 +import { requestCustomSnooze } from "../CustomSnoozeDialog";
5 +import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
6 +import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";
7 +import { useSortable } from "@dnd-kit/sortable";
8 +import { CSS } from "@dnd-kit/utilities";
9 +import {
10 + canSnooze,
11 + hasQueuedTurnStart,
12 + QUEUED_TURN_START_GRACE_MS,
13 +} from "@t3tools/client-runtime/state/thread-settled";
14 +import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
15 +import { resolveSettledThreadTimestamp } from "@t3tools/client-runtime/state/thread-sort";
16 +import { type EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
17 +import {
18 + formatWorkingDurationLabel,
19 + resolveThreadProviderStack,
20 +} from "@t3tools/client-runtime/state/models";
21 +import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";
22 +import {
23 + AuthOrchestrationOperateScope,
24 + type EnvironmentMachineKind,
25 + type ScopedThreadRef,
26 +} from "@t3tools/contracts";
27 +
28 +import type { TimestampFormat } from "@t3tools/contracts/settings";
29 +import {
30 + AlarmClockIcon,
31 + AlarmClockOffIcon,
32 + ArrowRightLeftIcon,
33 + CheckIcon,
34 + CircleAlertIcon,
35 + CircleCheckIcon,
36 + CircleDashedIcon,
37 + CircleDotDashedIcon,
38 + ClockIcon,
39 + GitBranchIcon,
40 + MessageCircleQuestionIcon,
41 + PinIcon,
42 + PinOffIcon,
43 + ShieldQuestionIcon,
44 + SquarePenIcon,
45 + TerminalIcon,
46 + Undo2Icon,
47 + XIcon,
48 +} from "lucide-react";
49 +import {
50 + memo,
51 + useEffect,
52 + useRef,
53 + useState,
54 + type KeyboardEvent as ReactKeyboardEvent,
55 + type MouseEvent as ReactMouseEvent,
56 + type PointerEvent as ReactPointerEvent,
57 + type ReactNode,
58 +} from "react";
59 +
60 +import { useRightPanelStore } from "../../rightPanelStore";
61 +import { useOpenPrLink } from "../../lib/openPullRequestLink";
62 +import { useUiStateStore } from "../../uiStateStore";
63 +import { useThreadSelectionStore } from "../../threadSelectionStore";
64 +import { useNowMinute } from "../../hooks/useNowMinute";
65 +import { useNowSecond } from "../../hooks/useNowSecond";
66 +import { vcsEnvironment } from "../../state/vcs";
67 +import { useEnvironmentQuery } from "../../state/query";
68 +import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
69 +import { formatRelativeTimeLabel, parseTimestampDate } from "../../timestampFormat";
70 +import type { SidebarThreadSummary } from "../../types";
71 +import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
72 +import { cn } from "~/lib/utils";
73 +import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
74 +import {
75 + animateSidebarLayoutChanges,
76 + hasUnseenCompletion,
77 + resolveSidebarRowAccessibility,
78 + type SidebarDropVerb,
79 + resolveSidebarThreadStatus,
80 + resolveThreadLastVisitedAt,
81 + shouldRecedeSidebarThread,
82 + resolveWorkingStartedAt,
83 + useRetainedValue,
84 + useSidebarRowSubscriptionLease,
85 +} from "../Sidebar.logic";
86 +import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic";
87 +import {
88 + ThreadPullRequestBadgeControl,
89 + ThreadPullRequestsMiniList,
90 + ThreadWorktreeIndicator,
91 + prStatusIndicator,
92 + resolveThreadPullRequestBadge,
93 + terminalStatusFromRunningIds,
94 + type TerminalStatusIndicator,
95 + useLinkedThreadPullRequest,
96 + ThreadSearchPullRequestNumber,
97 +} from "../ThreadStatusIndicators";
98 +import { resolveSnoozePresets, type SnoozePreset } from "../Sidebar.snooze";
99 +import { ProjectFavicon, type ProjectFaviconProject } from "../ProjectFavicon";
100 +import { ThreadSearchMatchExcerpt } from "../ThreadSearchMatch";
101 +import { makeWorkspaceFileDropHandlers } from "../chat/workspaceFileDrop";
102 +import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
103 +import { getTriggerDisplayModelLabel } from "../chat/providerIconUtils";
104 +import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances";
105 +import { useThreadRunningTerminalIds } from "../../state/terminalSessions";
106 +import { InlineButton } from "../ui/button";
107 +import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuTrigger } from "../ui/menu";
108 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
109 +import { MiddleTruncate } from "../ui/middle-truncate";
110 +import { useThreadHasUnsentDraft } from "../../composerDraftStore";
111 +
112 +// The fields thread rows show. Provider status pushes refresh `checkedAt`,
113 +// status and auth on every provider; leaving those out keeps each
114 +// environment's map, and every memoized row, stable across them.
115 +export type SidebarProviderEntry = Pick<
116 + ProviderInstanceEntry,
117 + | "instanceId"
118 + | "driverKind"
119 + | "enabled"
120 + | "displayName"
121 + | "accentColor"
122 + | "acpRegistryAgentId"
123 + | "acpRegistryIconUrl"
124 + | "models"
125 +>;
126 +function compactSidebarTimeLabel(label: string): string {
127 + if (label === "just now") return "now";
128 + return label.endsWith(" ago") ? label.slice(0, -4) : label;
129 +}
130 +
131 +// Subscribes to the minute tick itself, so only the label re-renders each
132 +// minute. The minute is passed as the clock so it is the formatter's input.
133 +function RelativeTimeLabel(props: { timestamp: string | null }) {
134 + const nowMinute = useNowMinute();
135 + return props.timestamp === null
136 + ? null
137 + : compactSidebarTimeLabel(
138 + formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),
139 + );
140 +}
141 +
142 +function threadTimeTimestamp(thread: SidebarThreadSummary): string {
143 + return thread.latestUserMessageAt ?? thread.updatedAt;
144 +}
145 +
146 +function JumpHintBadge(props: { label: string }) {
147 + return (
148 + <span
149 + aria-hidden
150 + className="pointer-events-none absolute right-1.5 top-1/2 z-10 inline-flex h-5 -translate-y-1/2 items-center rounded-full border border-border/80 bg-background/95 px-1.5 font-mono text-3xs font-medium tracking-tight text-foreground shadow-sm"
151 + >
152 + {props.label}
153 + </span>
154 + );
155 +}
156 +
157 +function WorkingDuration(props: { startedAt: string | null }) {
158 + const startedMs = props.startedAt !== null ? Date.parse(props.startedAt) : Number.NaN;
159 + if (Number.isNaN(startedMs)) return null;
160 + return <WorkingDurationLabel startedMs={startedMs} />;
161 +}
162 +
163 +// Self-ticking so only this span re-renders each second, not the whole row;
164 +// the shared tick lands every working row's update in the same frame.
165 +function WorkingDurationLabel(props: { startedMs: number }) {
166 + const nowMs = useNowSecond();
167 + return (
168 + <span className="tabular-nums">{formatWorkingDurationLabel(nowMs - props.startedMs)}</span>
169 + );
170 +}
171 +
172 +function terminalProcessLabel(count: number): string {
173 + return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
174 +}
175 +
176 +function SidebarProviderStack(props: {
177 + thread: SidebarThreadSummary;
178 + providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
179 +}) {
180 + const stack = resolveThreadProviderStack(props.thread);
181 + const currentInstanceId = stack[stack.length - 1]!;
182 + const currentEntry = props.providerEntryByInstanceId.get(currentInstanceId) ?? null;
183 + if (currentEntry === null) return null;
184 + const showInstanceBadge = shouldShowInstanceBadge(
185 + currentEntry,
186 + props.providerEntryByInstanceId.values(),
187 + );
188 + const current = (
189 + <ProviderInstanceIcon
190 + driverKind={currentEntry.driverKind}
191 + displayName={currentEntry.displayName}
192 + accentColor={currentEntry.accentColor}
193 + acpRegistryAgentId={currentEntry.acpRegistryAgentId}
194 + acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}
195 + showBadge={showInstanceBadge}
196 + size="compact"
197 + iconClassName="opacity-60"
198 + />
199 + );
200 + if (stack.length === 1) {
201 + return <span className="inline-flex shrink-0 items-center">{current}</span>;
202 + }
203 + return (
204 + <span className="inline-flex shrink-0 items-center gap-1.5">
205 + {stack.slice(0, -1).map((instanceId) => {
206 + const entry = props.providerEntryByInstanceId.get(instanceId);
207 + if (entry === undefined) return null;
208 + return (
209 + <ProviderInstanceIcon
210 + key={instanceId}
211 + driverKind={entry.driverKind}
212 + displayName={entry.displayName}
213 + acpRegistryAgentId={entry.acpRegistryAgentId}
214 + acpRegistryIconUrl={entry.acpRegistryIconUrl}
215 + iconClassName="size-3 opacity-35 grayscale"
216 + />
217 + );
218 + })}
219 + <span className="relative z-10 inline-flex items-center">{current}</span>
220 + </span>
221 + );
222 +}
223 +
224 +function SidebarThreadTooltip({
225 + thread,
226 + project,
227 + projectDisplayName,
228 + environmentLabel,
229 + environmentMachine,
230 + providerEntry,
231 + providerEntryByInstanceId,
232 + showInstanceBadge,
233 + modelInstanceId,
234 + modelLabel,
235 + branchMismatch,
236 + terminalStatus,
237 + terminalProcessCount,
238 +}: {
239 + thread: SidebarThreadSummary;
240 + project: ProjectFaviconProject | null;
241 + projectDisplayName: string | null;
242 + environmentLabel: string | null;
243 + environmentMachine: EnvironmentMachineKind;
244 + providerEntry: SidebarProviderEntry | null;
245 + providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
246 + showInstanceBadge: boolean;
247 + modelInstanceId: string;
248 + modelLabel: string;
249 + branchMismatch: {
250 + threadBranch: string;
251 + currentBranch: string;
252 + } | null;
253 + terminalStatus: TerminalStatusIndicator | null;
254 + terminalProcessCount: number;
255 +}) {
256 + const driverKind = providerEntry?.driverKind ?? null;
257 + const previousProviderNames = thread.providerInstanceHistory
258 + .filter((instanceId) => instanceId !== modelInstanceId)
259 + .map((instanceId) => providerEntryByInstanceId.get(instanceId)?.displayName ?? instanceId);
260 + const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
261 + return (
262 + <ThreadHoverCardPopup side="right" align="start" sideOffset={4}>
263 + <ThreadHoverCard
264 + title={thread.title}
265 + footer={
266 + supportsMultiplePullRequests && thread.pullRequests.length > 0 ? (
267 + <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground">
268 + <ThreadPullRequestsMiniList pullRequests={thread.pullRequests} />
269 + </div>
270 + ) : null
271 + }
272 + >
273 + {projectDisplayName ? (
274 + <div className="flex min-w-0 items-center gap-2">
275 + {project ? <ProjectFavicon project={project} className="size-3 shrink-0" /> : null}
276 + <div className="min-w-0 truncate text-foreground/75">{projectDisplayName}</div>
277 + </div>
278 + ) : null}
279 + {environmentLabel ? (
280 + <div className="flex min-w-0 items-center gap-2">
281 + <EnvironmentMachineIcon
282 + kind={environmentMachine}
283 + className="size-3 shrink-0 stroke-muted-foreground"
284 + />
285 + <div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div>
286 + </div>
287 + ) : null}
288 + {thread.branch ? (
289 + <div className="flex min-w-0 items-center gap-2">
290 + <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />
291 + <MiddleTruncate value={thread.branch} className="flex" />
292 + </div>
293 + ) : null}
294 + {branchMismatch ? (
295 + <div className="flex min-w-0 items-start gap-2 text-warning">
296 + <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />
297 + <div className="min-w-0 flex-1 wrap-break-word">
298 + You're currently checked out on another branch.
299 + </div>
300 + </div>
301 + ) : null}
302 + {driverKind ? (
303 + <div className="flex min-w-0 items-center gap-2">
304 + <ProviderInstanceIcon
305 + driverKind={driverKind}
306 + displayName={
307 + providerEntry?.displayName ?? thread.runtime?.providerName ?? modelInstanceId
308 + }
309 + accentColor={providerEntry?.accentColor}
310 + acpRegistryAgentId={providerEntry?.acpRegistryAgentId}
311 + acpRegistryIconUrl={providerEntry?.acpRegistryIconUrl}
312 + showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined}
313 + badgeContent="none"
314 + badgeClassName="h-2 min-w-2 px-0"
315 + iconClassName="size-3 shrink-0 grayscale opacity-60"
316 + />
317 + <div className="min-w-0 truncate text-foreground/75">
318 + {showInstanceBadge && providerEntry
319 + ? `${modelLabel} · ${providerEntry.displayName}`
320 + : modelLabel}
321 + </div>
322 + </div>
323 + ) : null}
324 + {previousProviderNames.length > 0 ? (
325 + <div className="flex min-w-0 items-center gap-2">
326 + <ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" />
327 + <div className="min-w-0 truncate text-foreground/75">
328 + Handed off from {previousProviderNames.join(", ")}
329 + </div>
330 + </div>
331 + ) : null}
332 + {terminalStatus ? (
333 + <div className="flex min-w-0 items-center gap-2">
334 + <TerminalIcon
335 + aria-hidden
336 + className={cn("size-3 shrink-0", terminalStatus.colorClass)}
337 + />
338 + <div className="min-w-0 truncate text-foreground/75">
339 + {terminalProcessLabel(terminalProcessCount)}
340 + </div>
341 + </div>
342 + ) : null}
343 + {thread.runtime?.lastError ? (
344 + <div
345 + className={cn(
346 + "flex min-w-0 items-center gap-2",
347 + thread.runtime.lastErrorClass === "usage_limit" ? "text-warning" : "text-error",
348 + )}
349 + >
350 + <CircleAlertIcon className="size-3 shrink-0 stroke-current" />
351 + <div className="min-w-0 truncate">
352 + {thread.runtime.lastErrorClass === "usage_limit"
353 + ? "Usage limit reached"
354 + : "Error occurred"}
355 + </div>
356 + </div>
357 + ) : null}
358 + </ThreadHoverCard>
359 + </ThreadHoverCardPopup>
360 + );
361 +}
362 +
363 +function SnoozeMenuButton(props: {
364 + open: boolean;
365 + onOpenChange: (open: boolean) => void;
366 + onSnooze: (preset: Pick<SnoozePreset, "snoozedUntil">) => void;
367 + timestampFormat: TimestampFormat;
368 +}) {
369 + const { open, onOpenChange, onSnooze, timestampFormat } = props;
370 + const presets = open ? resolveSnoozePresets(new Date(), timestampFormat) : [];
371 + return (
372 + <Menu open={open} onOpenChange={onOpenChange}>
373 + <Tooltip>
374 + <TooltipTrigger
375 + render={
376 + <MenuTrigger
377 + render={
378 + <button
379 + type="button"
380 + aria-label="Snooze thread"
381 + onClick={(event) => event.stopPropagation()}
382 + onDoubleClick={(event) => event.stopPropagation()}
383 + className="inline-flex h-full cursor-pointer items-center gap-0.5 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
384 + />
385 + }
386 + />
387 + }
388 + >
389 + <ClockIcon className="size-3" />
390 + </TooltipTrigger>
391 + <TooltipPopup>Snooze thread</TooltipPopup>
392 + </Tooltip>
393 + <MenuPopup side="bottom" align="end">
394 + {presets.map((preset) => (
395 + <MenuItem
396 + key={preset.id}
397 + onClick={(event) => {
398 + event.stopPropagation();
399 + onSnooze(preset);
400 + }}
401 + >
402 + {preset.label}
403 + <MenuShortcut>{preset.whenLabel}</MenuShortcut>
404 + </MenuItem>
405 + ))}
406 + <MenuSeparator />
407 + <MenuItem
408 + onClick={async (event) => {
409 + event.stopPropagation();
410 + const choice = await requestCustomSnooze();
411 + if (choice) onSnooze(choice);
412 + }}
413 + >
414 + Custom…
415 + </MenuItem>
416 + </MenuPopup>
417 + </Menu>
418 + );
419 +}
420 +
421 +type SortableThreadRowBag = Pick<
422 + ReturnType<typeof useSortable>,
423 + "listeners" | "setNodeRef" | "transform" | "transition" | "isDragging"
424 +>;
425 +
426 +export const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8";
427 +export const draftPenClassName = "size-3 shrink-0 text-warning-foreground";
428 +
429 +// useSortable memoizes on its `disabled` object, so a fresh one per render
430 +// re-renders every row and marker on each sidebar update.
431 +export const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;
432 +const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;
433 +
434 +// Takes the row's props rather than a render function: a closure from the
435 +// sidebar body is new on every sidebar render, which rebuilt the bag and
436 +// re-rendered every memoized row with it.
437 +export function SortableThreadRow(
438 + props: Omit<SidebarThreadRowProps, "sortable"> & {
439 + sortableId: string;
440 + sortableDisabled: boolean;
441 + contextDrag: boolean;
442 + },
443 +) {
444 + const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props;
445 + const canOperateThread = useEnvironmentScope(
446 + rowProps.thread.environmentId,
447 + AuthOrchestrationOperateScope,
448 + );
449 + const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({
450 + id: sortableId,
451 + disabled:
452 + sortableDisabled || !canOperateThread
453 + ? SIDEBAR_SORTABLE_DRAG_DISABLED
454 + : SIDEBAR_SORTABLE_DRAG_ENABLED,
455 + animateLayoutChanges: animateSidebarLayoutChanges,
456 + });
457 + // dnd-kit memoizes each field but not the bag, so the memoized row would
458 + // rerender on every shell update without this.
459 + const bag = {
460 + listeners,
461 + setNodeRef,
462 + transform: contextDrag ? null : transform,
463 + transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,
464 + isDragging: isDragging && !contextDrag,
465 + };
466 + // Keyed by variant so a card/slim switch remounts the row.
467 + return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;
468 +}
469 +export type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";
470 +const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
471 + pin: (
472 + <>
473 + <PinIcon aria-hidden className="size-3" />
474 + Pin
475 + </>
476 + ),
477 + unpin: (
478 + <>
479 + <PinOffIcon aria-hidden className="size-3" />
480 + Unpin
481 + </>
482 + ),
483 + settle: (
484 + <>
485 + <CircleCheckIcon aria-hidden className="size-3" />
486 + Settle
487 + </>
488 + ),
489 + unsettle: (
490 + <>
491 + <Undo2Icon aria-hidden className="size-3" />
492 + Un-settle
493 + </>
494 + ),
495 + wake: (
496 + <>
497 + <AlarmClockOffIcon aria-hidden className="size-3" />
498 + Wake
499 + </>
500 + ),
501 +};
502 +
503 +type SidebarThreadRowProps = {
504 + thread: SidebarThreadSummary;
505 + variant: "card" | "slim";
506 + variantAction: SidebarSweepAction;
507 + settlementSupported: boolean;
508 + snoozeSupported: boolean;
509 + pinningSupported: boolean;
510 + isPinned: boolean;
511 + sortable?: SortableThreadRowBag | undefined;
512 + dropVerb: SidebarDropVerb | null;
513 + dragOverPinned: boolean;
514 + sweepAction: SidebarSweepAction | null;
515 + snoozeWakeLabelText: string | null;
516 + wokeAt: string | null;
517 + isActive: boolean;
518 + // Unlike isActive, never true for the ancestor standing in for an open
519 + // subagent: drafts and PR clicks care about which composer is on screen.
520 + isRouteThread: boolean;
521 + openPullRequestsInRightPanel: boolean;
522 + jumpLabel: string | null;
523 + currentEnvironmentId: string | null;
524 + environmentLabel: string | null;
525 + environmentMachine: EnvironmentMachineKind;
526 + scratchMachineLabel: string | null;
527 + project: EnvironmentProject | null;
528 + projectDisplayName: string | null;
529 + providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
530 + timestampFormat: TimestampFormat;
531 + onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void;
532 + onThreadActivate: (threadRef: ScopedThreadRef) => void;
533 + onStartRename: (threadRef: ScopedThreadRef, title: string) => void;
534 + onRenameTitleChange: (title: string) => void;
535 + onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void;
536 + onCancelRename: () => void;
537 + isRenaming: boolean;
538 + renamingTitle: string;
539 + onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;
540 + onSettle: (threadRef: ScopedThreadRef) => void;
541 + onActionSweepStart: (
542 + threadRef: ScopedThreadRef,
543 + action: SidebarSweepAction,
544 + event: PointerEvent,
545 + ) => void;
546 + onUnsettle: (threadRef: ScopedThreadRef) => void;
547 + onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void;
548 + onUnsnooze: (threadRef: ScopedThreadRef) => void;
549 + onUnpin: (threadRef: ScopedThreadRef) => void;
550 + onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;
551 + onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined;
552 +};
553 +
554 +const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {
555 + const {
556 + isRenaming,
557 + onCancelRename,
558 + onCommitRename,
559 + onContextMenu,
560 + onAcknowledgeWoke,
561 + onFileDropThreads,
562 + onRenameTitleChange,
563 + onSettle,
564 + onActionSweepStart,
565 + onSnooze,
566 + onStartRename,
567 + onThreadActivate,
568 + onThreadClick,
569 + onUnsettle,
570 + onUnsnooze,
571 + onUnpin,
572 + openPullRequestsInRightPanel,
573 + renamingTitle,
574 + thread,
575 + variant,
576 + variantAction,
577 + } = props;
578 + const threadRef = scopeThreadRef(thread.environmentId, thread.id);
579 + const threadKey = scopedThreadKey(threadRef);
580 + const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);
581 + useEffect(() => {
582 + if (!canOperateThread && isRenaming) onCancelRename();
583 + }, [canOperateThread, isRenaming, onCancelRename]);
584 + const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(props.isActive);
585 + const isRegeneratingTitle = thread.titleRegeneration != null;
586 + const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);
587 + const lastVisitedAt = resolveThreadLastVisitedAt(thread.lastVisitedAt, localLastVisitedAt);
588 + const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));
589 + const openPrLink = useOpenPrLink();
590 + const runningTerminalIds = useThreadRunningTerminalIds({
591 + environmentId: thread.environmentId,
592 + threadId: thread.id,
593 + });
594 + const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
595 + const terminalProcessCount = runningTerminalIds.length;
596 + const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread;
597 + const handleDiscardDraftClick = (event: ReactMouseEvent) => {
598 + event.preventDefault();
599 + event.stopPropagation();
600 + discardComposerDraft(threadRef);
601 + };
602 +
603 + const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;
604 + const linkedPullRequestStatus = useLinkedThreadPullRequest(
605 + thread.environmentId,
606 + thread.linkedPullRequest,
607 + leaseLiveStatus,
608 + thread.pullRequests,
609 + thread.branchPullRequest,
610 + );
611 + const gitStatus = useEnvironmentQuery(
612 + leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
613 + ? vcsEnvironment.status({
614 + environmentId: thread.environmentId,
615 + input: { cwd: gitCwd, includeRemote: false },
616 + })
617 + : null,
618 + );
619 + const visibleGitStatus = useRetainedValue(
620 + JSON.stringify([thread.environmentId, gitCwd]),
621 + gitStatus.data,
622 + );
623 + const pr = linkedPullRequestStatus?.pr ?? null;
624 + const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
625 + const currentLinkedPr = supportsMultiplePullRequests
626 + ? resolveThreadCurrentPullRequestLink(thread.pullRequests)
627 + : null;
628 +
629 + const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });
630 + const status = resolveSidebarThreadStatus(thread);
631 + const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);
632 + const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);
633 + const isWoke =
634 + wokeAtDate !== null &&
635 + (lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
636 + thread.settledOverride !== "settled";
637 + const shouldRecede = shouldRecedeSidebarThread({
638 + status,
639 + isUnread,
640 + isWoke,
641 + isActive: props.isActive,
642 + isSelected,
643 + });
644 + const topStatus =
645 + status === "working"
646 + ? {
647 + label: thread.goal?.status === "active" ? "Goal" : "Working",
648 + icon: "working" as const,
649 + className: "text-info",
650 + }
651 + : status === "waiting"
652 + ? {
653 + label: "Waiting",
654 + icon: "waiting" as const,
655 + className: "text-muted-foreground",
656 + }
657 + : status === "approval"
658 + ? {
659 + label: "Approval",
660 + icon: "approval" as const,
661 + className: "text-warning-foreground",
662 + }
663 + : status === "input"
664 + ? {
665 + label: "Input",
666 + icon: "input" as const,
667 + className: "text-indigo-600 dark:text-indigo-300",
668 + }
669 + : status === "limited"
670 + ? {
671 + label: "Limited",
672 + icon: "failed" as const,
673 + className: "text-warning",
674 + }
675 + : status === "failed"
676 + ? {
677 + label: "Failed",
678 + icon: "failed" as const,
679 + className: "text-error",
680 + }
681 + : isWoke
682 + ? {
683 + label: "Woke",
684 + icon: "woke" as const,
685 + className: "text-warning",
686 + }
687 + : isUnread
688 + ? {
689 + label: "Done",
690 + icon: "done" as const,
691 + className: "text-success",
692 + }
693 + : null;
694 + const isWokeStatus = topStatus?.icon === "woke";
695 +
696 + const branchMismatch = resolveLocalCheckoutBranchMismatch({
697 + effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
698 + activeWorktreePath: thread.worktreePath,
699 + activeThreadBranch: thread.branch,
700 + currentGitBranch: visibleGitStatus?.refName ?? null,
701 + });
702 + const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider);
703 +
704 + const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;
705 + const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
706 + const showInstanceBadge =
707 + providerEntry !== null &&
708 + shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
709 + const selectedModel = providerEntry?.models.find(
710 + (model) => model.slug === thread.modelSelection.model,
711 + );
712 + const modelLabel = selectedModel
713 + ? getTriggerDisplayModelLabel(selectedModel)
714 + : thread.modelSelection.model;
715 +
716 + const isRemote = thread.environmentId !== props.currentEnvironmentId;
717 + const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;
718 +
719 + const detailsTooltip = (
720 + <SidebarThreadTooltip
721 + thread={thread}
722 + project={props.project}
723 + projectDisplayName={props.projectDisplayName}
724 + environmentLabel={props.environmentLabel}
725 + environmentMachine={props.environmentMachine}
726 + providerEntry={providerEntry}
727 + providerEntryByInstanceId={props.providerEntryByInstanceId}
728 + showInstanceBadge={showInstanceBadge}
729 + modelInstanceId={modelInstanceId}
730 + modelLabel={modelLabel}
731 + branchMismatch={branchMismatch}
732 + terminalStatus={terminalStatus}
733 + terminalProcessCount={terminalProcessCount}
734 + />
735 + );
736 +
737 + const handleClick = (event: ReactMouseEvent) => {
738 + onThreadClick(event, threadRef);
739 + };
740 + const handleAcknowledgeWokeClick = (event: ReactMouseEvent) => {
741 + event.preventDefault();
742 + event.stopPropagation();
743 + if (props.wokeAt === null) return;
744 + onAcknowledgeWoke(threadRef, props.wokeAt);
745 + };
746 + const handleContextMenu = (event: ReactMouseEvent) => {
747 + event.preventDefault();
748 + onContextMenu(threadRef, { x: event.clientX, y: event.clientY });
749 + };
750 + const handleKeyDown = (event: ReactKeyboardEvent) => {
751 + if (event.target !== event.currentTarget) return;
752 + if (event.key !== "Enter" && event.key !== " ") return;
753 + event.preventDefault();
754 + onThreadActivate(threadRef);
755 + };
756 + const handleDoubleClick = (event: ReactMouseEvent) => {
757 + if (
758 + !readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) ||
759 + isRenaming ||
760 + event.metaKey ||
761 + event.ctrlKey ||
762 + event.shiftKey ||
763 + event.altKey
764 + ) {
765 + return;
766 + }
767 + if ((event.target as HTMLElement).closest("button, a, input")) return;
768 + event.preventDefault();
769 + onStartRename(threadRef, thread.title);
770 + };
771 + const [isFileDragOver, setIsFileDragOver] = useState(false);
772 + const fileDropHandlers = onFileDropThreads
773 + ? makeWorkspaceFileDropHandlers({
774 + setDragActive: setIsFileDragOver,
775 + addFiles: (files) => {
776 + onFileDropThreads(threadRef, files);
777 + },
778 + addFolders: () => {},
779 + })
780 + : null;
781 + useEffect(() => {
782 + if (!isFileDragOver) return;
783 + const clearFileDrag = () => setIsFileDragOver(false);
784 + window.addEventListener("dragend", clearFileDrag);
785 + return () => window.removeEventListener("dragend", clearFileDrag);
786 + }, [isFileDragOver]);
787 + const renameCommittedRef = useRef(false);
788 + useEffect(() => {
789 + if (isRenaming) renameCommittedRef.current = false;
790 + }, [isRenaming]);
791 + const handleRenameKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
792 + event.stopPropagation();
793 + if (event.nativeEvent.isComposing || event.keyCode === 229) return;
794 + if (event.key === "Enter") {
795 + event.preventDefault();
796 + renameCommittedRef.current = true;
797 + onCommitRename(threadRef, renamingTitle, thread.title);
798 + } else if (event.key === "Escape") {
799 + event.preventDefault();
800 + renameCommittedRef.current = true;
801 + onCancelRename();
802 + }
803 + };
804 + const handleRenameBlur = () => {
805 + if (!renameCommittedRef.current) {
806 + onCommitRename(threadRef, renamingTitle, thread.title);
807 + }
808 + };
809 + const handleSettleClick = (event: ReactMouseEvent) => {
810 + event.preventDefault();
811 + event.stopPropagation();
812 + onSettle(threadRef);
813 + };
814 + const handleActionPointerDown = (event: ReactPointerEvent) => {
815 + if (!event.isPrimary || event.button !== 0) return;
816 + event.stopPropagation();
817 + onActionSweepStart(threadRef, variantAction, event.nativeEvent);
818 + };
819 + const handleUnsettleClick = (event: ReactMouseEvent) => {
820 + event.preventDefault();
821 + event.stopPropagation();
822 + onUnsettle(threadRef);
823 + };
824 + const handleUnsnoozeClick = (event: ReactMouseEvent) => {
825 + event.preventDefault();
826 + event.stopPropagation();
827 + onUnsnooze(threadRef);
828 + };
829 + const handleUnpinClick = (event: ReactMouseEvent) => {
830 + event.preventDefault();
831 + event.stopPropagation();
832 + onUnpin(threadRef);
833 + };
834 + const handleSnoozePreset = (preset: Pick<SnoozePreset, "snoozedUntil">) => {
835 + onSnooze(threadRef, preset);
836 + };
837 + const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);
838 + // The React Compiler caches render results on their inputs, so a clock read
839 + // here would stay frozen until `thread` changes and a queued-turn gate would
840 + // never reopen. The gate's clock is state, reset with the thread.
841 + const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({
842 + thread,
843 + now: new Date().toISOString(),
844 + }));
845 + if (snoozeGateClock.thread !== thread) {
846 + setSnoozeGateClock({ thread, now: new Date().toISOString() });
847 + }
848 + const snoozeGateNow = snoozeGateClock.now;
849 + const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })
850 + ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS
851 + : Number.NaN;
852 + useEffect(() => {
853 + // A gate still closed past its expiry is held by runtime status, not time,
854 + // so no clock tick can open it.
855 + if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {
856 + return;
857 + }
858 + const id = window.setTimeout(
859 + () => setSnoozeGateClock({ thread, now: new Date().toISOString() }),
860 + Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),
861 + );
862 + return () => window.clearTimeout(id);
863 + }, [snoozeGateExpiryMs, snoozeGateNow, thread]);
864 + const showSnoozeButton =
865 + canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });
866 + // Closing here, not just masking, keeps the menu from reopening when the button returns.
867 + if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);
868 + const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;
869 + const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {
870 + const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;
871 + if (!url) return;
872 + const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
873 + const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
874 + if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
875 + onThreadActivate(threadRef);
876 + }
877 + };
878 +
879 + const rowSurfaceClassName = cn(
880 + "group/sidebar-row relative w-full cursor-pointer overflow-hidden rounded-md text-left outline-none select-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
881 + variantAction === "unsettle" && "[&:not(:hover):not(:focus-within)_*]:text-secondary-label/70",
882 + props.isActive
883 + ? "bg-sidebar-row-active text-sidebar-foreground"
884 + : isSelected || props.sweepAction !== null
885 + ? "bg-sidebar-row-selected text-sidebar-foreground"
886 + : hasUnsentDraft
887 + ? cn(draftSurfaceClassName, "text-sidebar-foreground")
888 + : shouldRecede
889 + ? "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"
890 + : "bg-transparent text-sidebar-foreground hover:bg-sidebar-row-hover",
891 + shouldRecede &&
892 + status === "working" &&
893 + "opacity-70 transition-opacity hover:opacity-100 focus-within:opacity-100 motion-reduce:transition-none",
894 + isFileDragOver && "ring-1 ring-inset ring-primary/70",
895 + isFileDragOver && !props.isActive && !isSelected && "bg-sidebar-row-hover",
896 + props.sortable?.isDragging &&
897 + "bg-sidebar bg-linear-to-b from-sidebar-row-active to-sidebar-row-active text-sidebar-foreground opacity-100 shadow-lg",
898 + );
899 + const sortable = props.sortable;
900 + const sortableRootProps = sortable
901 + ? {
902 + ref: sortable.setNodeRef,
903 + style: {
904 + transform: CSS.Translate.toString(sortable.transform),
905 + transition: sortable.transition,
906 + // A zero-height boundary also makes dnd-kit scale the source to
907 + // zero. Only projected peers use scaleY as a visibility sentinel.
908 + visibility:
909 + !sortable.isDragging && sortable.transform?.scaleY === 0
910 + ? ("hidden" as const)
911 + : undefined,
912 + },
913 + ...sortable.listeners,
914 + }
915 + : {};
916 + const destinationVerb = sortable?.isDragging
917 + ? props.dropVerb
918 + : props.sweepAction === "unsnooze"
919 + ? "wake"
920 + : props.sweepAction;
921 + const dragDestination =
922 + destinationVerb !== null ? (
923 + <span
924 + role="status"
925 + className="pointer-events-none ml-auto inline-flex h-5 shrink-0 items-center gap-1 rounded-sm border border-primary/40 bg-primary/10 px-1.5 text-2xs font-medium text-primary"
926 + >
927 + {dropVerbBadge[destinationVerb]}
928 + </span>
929 + ) : null;
930 +
931 + const accessibility = resolveSidebarRowAccessibility({
932 + title: thread.title,
933 + statusLabel: topStatus?.label ?? null,
934 + projectDisplayName: props.projectDisplayName,
935 + isActive: props.isActive,
936 + });
937 +
938 + const title =
939 + isRenaming && canOperateThread ? (
940 + <input
941 + autoFocus
942 + value={renamingTitle}
943 + aria-label="Thread title"
944 + onChange={(event) => onRenameTitleChange(event.target.value)}
945 + onFocus={(event) => event.currentTarget.select()}
946 + onKeyDown={handleRenameKeyDown}
947 + onBlur={handleRenameBlur}
948 + onClick={(event) => event.stopPropagation()}
949 + onDoubleClick={(event) => event.stopPropagation()}
950 + className="min-w-0 flex-1 rounded-sm border border-input bg-card px-1 text-sm font-medium text-card-foreground outline-none focus:border-foreground"
951 + />
952 + ) : (
953 + <span
954 + aria-hidden
955 + className={cn(
956 + "min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",
957 + shouldRecede ? "font-normal" : "font-medium",
958 + variant === "card"
959 + ? cn(
960 + "truncate",
961 + shouldRecede
962 + ? "text-secondary-label"
963 + : isUnread || isWoke || status === "input"
964 + ? "text-foreground"
965 + : status === "failed"
966 + ? "text-foreground/95"
967 + : "text-foreground/90",
968 + )
969 + : cn(
970 + "truncate group-focus-within/sidebar-row:text-foreground group-hover/sidebar-row:text-foreground",
971 + shouldRecede
972 + ? "text-secondary-label/70"
973 + : props.isActive || isWoke || status === "input"
974 + ? "text-foreground"
975 + : isUnread
976 + ? "text-muted-foreground"
977 + : "text-secondary-label/70",
978 + ),
979 + isRegeneratingTitle && "opacity-55",
980 + )}
981 + >
982 + {thread.title}
983 + </span>
984 + );
985 + const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;
986 +
987 + const prBadgeShape = supportsMultiplePullRequests
988 + ? resolveThreadPullRequestBadge(thread.pullRequests)
989 + : null;
990 + const handlePrListClick = () => {
991 + useRightPanelStore.getState().open(threadRef, "pull-requests");
992 + if (!props.isRouteThread) onThreadActivate(threadRef);
993 + };
994 + const prBadge =
995 + prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? (
996 + <ThreadPullRequestBadgeControl
997 + render={<InlineButton />}
998 + badge={prBadgeShape}
999 + pullRequests={thread.pullRequests}
1000 + number={pr?.number ?? currentLinkedPr?.number}
1001 + url={pr?.url ?? currentLinkedPr?.url}
1002 + status={prStatus}
1003 + onOpenList={handlePrListClick}
1004 + onOpenPullRequest={handlePrClick}
1005 + />
1006 + ) : null;
1007 + const terminalStatusIcon = (
1008 + <ThreadTerminalStatusButton
1009 + threadRef={threadRef}
1010 + terminalIds={runningTerminalIds}
1011 + onThreadActivate={onThreadActivate}
1012 + />
1013 + );
1014 + const draftIndicator = hasUnsentDraft ? (
1015 + <Tooltip>
1016 + <TooltipTrigger
1017 + render={
1018 + <span
1019 + role="img"
1020 + aria-label="Unsent draft"
1021 + data-testid={`sidebar-draft-indicator-${thread.id}`}
1022 + className="inline-flex shrink-0 items-center"
1023 + />
1024 + }
1025 + >
1026 + <SquarePenIcon aria-hidden className={draftPenClassName} />
1027 + </TooltipTrigger>
1028 + <TooltipPopup side="top">Unsent draft</TooltipPopup>
1029 + </Tooltip>
1030 + ) : null;
1031 + const showPin =
1032 + props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null));
1033 + const pinIndicator = showPin ? (
1034 + props.pinningSupported && canOperateThread && !sortable?.isDragging ? (
1035 + <Tooltip>
1036 + <TooltipTrigger
1037 + render={
1038 + <button
1039 + type="button"
1040 + aria-label="Unpin thread"
1041 + onClick={handleUnpinClick}
1042 + className="group/unpin inline-flex cursor-pointer items-center rounded-sm text-muted-foreground/65 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
1043 + />
1044 + }
1045 + >
1046 + <PinIcon
1047 + aria-hidden
1048 + className="size-3 shrink-0 group-hover/unpin:hidden group-focus-visible/unpin:hidden"
1049 + />
1050 + <PinOffIcon
1051 + aria-hidden
1052 + className="hidden size-3 shrink-0 group-hover/unpin:block group-focus-visible/unpin:block"
1053 + />
1054 + </TooltipTrigger>
1055 + <TooltipPopup>Unpin thread</TooltipPopup>
1056 + </Tooltip>
1057 + ) : (
1058 + <PinIcon
1059 + aria-label="Pinned"
1060 + role="img"
1061 + className="size-3 shrink-0 text-muted-foreground/65"
1062 + />
1063 + )
1064 + ) : null;
1065 +
1066 + if (variant === "slim") {
1067 + return (
1068 + <li
1069 + data-thread-item={threadKey}
1070 + {...sortableRootProps}
1071 + {...(fileDropHandlers ?? {})}
1072 + className={cn(
1073 + "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]",
1074 + sortable?.isDragging && "relative z-20",
1075 + )}
1076 + >
1077 + <Tooltip disabled={sortable?.isDragging}>
1078 + <TooltipTrigger
1079 + render={
1080 + <div
1081 + ref={rowRef}
1082 + role="button"
1083 + tabIndex={0}
1084 + aria-label={accessibility.label}
1085 + aria-current={accessibility.current}
1086 + data-testid="sidebar-row-slim"
1087 + aria-busy={isRegeneratingTitle || undefined}
1088 + className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}
1089 + onClick={handleClick}
1090 + onDoubleClick={handleDoubleClick}
1091 + onKeyDown={handleKeyDown}
1092 + onContextMenu={handleContextMenu}
1093 + />
1094 + }
1095 + >
1096 + {accessibleTitle}
1097 + <span
1098 + className={cn(
1099 + "flex shrink-0 items-center transition-opacity",
1100 + (!props.isActive || variantAction === "unsettle") &&
1101 + "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",
1102 + )}
1103 + >
1104 + {props.project ? <ProjectFavicon project={props.project} className="size-4" /> : null}
1105 + </span>
1106 + {draftIndicator}
1107 + {title}
1108 + {pinIndicator}
1109 + {terminalStatusIcon}
1110 + {isRegeneratingTitle ? (
1111 + <span role="status" className="sr-only">
1112 + Regenerating title
1113 + </span>
1114 + ) : null}
1115 + {prBadge}
1116 + {sortable?.isDragging ? (
1117 + dragDestination
1118 + ) : (
1119 + <span
1120 + className={cn(
1121 + "relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end",
1122 + props.sweepAction !== null && "hidden",
1123 + )}
1124 + >
1125 + <span
1126 + className={cn(
1127 + "inline-flex justify-end tabular-nums text-secondary-label transition-opacity",
1128 + !isWoke && "group-any-hover/sidebar-row:opacity-0",
1129 + )}
1130 + >
1131 + {variantAction === "unsnooze" && props.snoozeWakeLabelText !== null ? (
1132 + <span className="text-xs text-info-foreground tabular-nums">
1133 + {props.snoozeWakeLabelText}
1134 + </span>
1135 + ) : isWoke ? (
1136 + <Tooltip>
1137 + <TooltipTrigger
1138 + render={
1139 + <button
1140 + type="button"
1141 + aria-label="Dismiss Woke notification"
1142 + onClick={handleAcknowledgeWokeClick}
1143 + className="inline-flex cursor-pointer items-center gap-1 rounded-sm text-xs font-medium text-warning-foreground outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
1144 + >
1145 + <AlarmClockIcon aria-hidden className="size-3" />
1146 + <span role="status">Woke</span>
1147 + </button>
1148 + }
1149 + />
1150 + <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>
1151 + </Tooltip>
1152 + ) : (
1153 + <span className="text-xs">
1154 + <RelativeTimeLabel
1155 + timestamp={
1156 + variantAction === "unsettle"
1157 + ? resolveSettledThreadTimestamp(thread)
1158 + : threadTimeTimestamp(thread)
1159 + }
1160 + />
1161 + </span>
1162 + )}
1163 + </span>
1164 + {variantAction === "unsnooze" ? (
1165 + !props.snoozeSupported ? null : (
1166 + <button
1167 + type="button"
1168 + aria-label="Wake thread now"
1169 + onClick={handleUnsnoozeClick}
1170 + onPointerDown={handleActionPointerDown}
1171 + className={cn(
1172 + "pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
1173 + isWoke && "group-any-hover/sidebar-row:static",
1174 + )}
1175 + >
1176 + <AlarmClockOffIcon className="mb-px size-3" />
1177 + </button>
1178 + )
1179 + ) : !props.settlementSupported ? null : variantAction === "unsettle" ? (
1180 + <Tooltip>
1181 + <TooltipTrigger
1182 + render={
1183 + <button
1184 + type="button"
1185 + aria-label="Un-settle thread"
1186 + onClick={handleUnsettleClick}
1187 + onPointerDown={handleActionPointerDown}
1188 + className={cn(
1189 + "pointer-events-none absolute inset-y-0 right-0 -mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
1190 + isWoke && "group-any-hover/sidebar-row:static",
1191 + )}
1192 + />
1193 + }
1194 + >
1195 + <Undo2Icon className="mb-px size-3.5" />
1196 + </TooltipTrigger>
1197 + <TooltipPopup side="top">Un-settle thread</TooltipPopup>
1198 + </Tooltip>
1199 + ) : (
1200 + <button
1201 + type="button"
1202 + aria-label="Settle thread"
1203 + onClick={handleSettleClick}
1204 + onPointerDown={handleActionPointerDown}
1205 + className={cn(
1206 + "pointer-events-none absolute inset-y-0 right-0 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-2 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100",
1207 + isWoke && "group-any-hover/sidebar-row:static",
1208 + )}
1209 + >
1210 + <CheckIcon className="size-3" />
1211 + </button>
1212 + )}
1213 + </span>
1214 + )}
1215 + {props.sweepAction !== null ? dragDestination : null}
1216 + {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}
1217 + </TooltipTrigger>
1218 + {detailsTooltip}
1219 + </Tooltip>
1220 + </li>
1221 + );
1222 + }
1223 +
1224 + const diff = latestRunDiff(thread);
1225 +
1226 + return (
1227 + <li
1228 + data-thread-item={threadKey}
1229 + {...sortableRootProps}
1230 + {...(fileDropHandlers ?? {})}
1231 + className={cn(
1232 + "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",
1233 + sortable?.isDragging && "relative z-20",
1234 + )}
1235 + >
1236 + <Tooltip disabled={snoozeMenuOpen || sortable?.isDragging}>
1237 + <TooltipTrigger
1238 + render={
1239 + <div
1240 + ref={rowRef}
1241 + role="button"
1242 + tabIndex={0}
1243 + aria-label={accessibility.label}
1244 + aria-current={accessibility.current}
1245 + data-testid="sidebar-row-card"
1246 + aria-busy={isRegeneratingTitle || undefined}
1247 + className={rowSurfaceClassName}
1248 + onClick={handleClick}
1249 + onDoubleClick={handleDoubleClick}
1250 + onKeyDown={handleKeyDown}
1251 + onContextMenu={handleContextMenu}
1252 + />
1253 + }
1254 + >
1255 + {accessibleTitle}
1256 + <div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">
1257 + <div className="flex h-5 min-w-0 items-center gap-1.5">
1258 + {draftIndicator}
1259 + {props.project ? (
1260 + <ProjectFavicon project={props.project} className="size-4 shrink-0" />
1261 + ) : null}
1262 + {/* Left of the status slot, the pin would slide when hover swaps the
1263 + label for the wider row controls. */}
1264 + {pinIndicator}
1265 + {props.projectDisplayName ? (
1266 + <span
1267 + className={cn(
1268 + "min-w-0 flex-1 truncate text-secondary-label text-xs",
1269 + shouldRecede ? "font-normal" : "font-medium",
1270 + )}
1271 + >
1272 + {props.projectDisplayName}
1273 + </span>
1274 + ) : (
1275 + <span className="flex-1" />
1276 + )}
1277 + {sortable?.isDragging ? (
1278 + dragDestination
1279 + ) : (
1280 + <span
1281 + className={cn(
1282 + "group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs",
1283 + props.sweepAction !== null && "hidden",
1284 + )}
1285 + >
1286 + <span
1287 + className={cn(
1288 + isWokeStatus
1289 + ? "pointer-events-auto"
1290 + : "pointer-events-none group-has-[:focus-visible]/sidebar-status-slot:absolute group-has-[:focus-visible]/sidebar-status-slot:right-0 group-has-[:focus-visible]/sidebar-status-slot:opacity-0 group-any-hover/sidebar-row:absolute group-any-hover/sidebar-row:right-0 group-any-hover/sidebar-row:opacity-0",
1291 + "flex items-center self-center justify-self-end tabular-nums text-secondary-label transition-opacity",
1292 + snoozeMenuOpen && "pointer-events-none absolute right-0 opacity-0",
1293 + )}
1294 + >
1295 + {topStatus ? (
1296 + isWokeStatus ? (
1297 + <Tooltip>
1298 + <TooltipTrigger
1299 + render={
1300 + <button
1301 + type="button"
1302 + aria-label="Dismiss Woke notification"
1303 + onClick={handleAcknowledgeWokeClick}
1304 + className={cn(
1305 + "inline-flex cursor-pointer items-center gap-1 rounded-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
1306 + topStatus.className,
1307 + )}
1308 + >
1309 + <AlarmClockIcon aria-hidden className="size-4 shrink-0" />
1310 + <span role="status">{topStatus.label}</span>
1311 + </button>
1312 + }
1313 + />
1314 + <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>
1315 + </Tooltip>
1316 + ) : (
1317 + <span
1318 + className={cn(
1319 + "inline-flex items-center gap-1 font-medium",
1320 + topStatus.className,
1321 + )}
1322 + >
1323 + {topStatus.icon === "working" ? (
1324 + <CircleDashedIcon aria-hidden className="size-4 shrink-0" />
1325 + ) : topStatus.icon === "waiting" ? (
1326 + <CircleDotDashedIcon aria-hidden className="size-4 shrink-0" />
1327 + ) : topStatus.icon === "input" ? (
1328 + <MessageCircleQuestionIcon aria-hidden className="size-4 shrink-0" />
1329 + ) : topStatus.icon === "approval" ? (
1330 + <ShieldQuestionIcon aria-hidden className="size-4 shrink-0" />
1331 + ) : topStatus.icon === "failed" ? (
1332 + <CircleAlertIcon aria-hidden className="size-4 shrink-0" />
1333 + ) : topStatus.icon === "done" ? (
1334 + <CircleCheckIcon aria-hidden className="size-4 shrink-0" />
1335 + ) : null}
1336 + {/* The label alone is the live region: a role="status"
1337 + wrapper around the ticking duration would make
1338 + screen readers announce every second. */}
1339 + <span role="status">{topStatus.label}</span>
1340 + {status === "working" ? (
1341 + <span aria-hidden>
1342 + <WorkingDuration startedAt={resolveWorkingStartedAt(thread)} />
1343 + </span>
1344 + ) : status === "waiting" ? (
1345 + <span aria-hidden>
1346 + <WorkingDuration startedAt={thread.latestRun?.completedAt ?? null} />
1347 + </span>
1348 + ) : null}
1349 + </span>
1350 + )
1351 + ) : (
1352 + <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
1353 + )}
1354 + </span>
1355 + {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (
1356 + <span
1357 + className={cn(
1358 + // focus-visible, not focus-within: a mouse click leaves
1359 + // the Settle button focused, and a plain focus-within
1360 + // would keep the controls pinned over the status label
1361 + // once the pointer moves away (e.g. after a failed
1362 + // settle) instead of cross-fading back.
1363 + "pointer-events-none absolute inset-y-0 right-0 flex items-stretch opacity-0 transition-opacity has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:static has-[:focus-visible]:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:static group-any-hover/sidebar-row:opacity-100",
1364 + snoozeMenuOpen && "pointer-events-auto static opacity-100",
1365 + )}
1366 + >
1367 + {hasUnsentDraft ? (
1368 + <Tooltip>
1369 + <TooltipTrigger
1370 + render={
1371 + <button
1372 + type="button"
1373 + aria-label="Discard draft"
1374 + onClick={handleDiscardDraftClick}
1375 + className="inline-flex cursor-pointer items-center rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
1376 + />
1377 + }
1378 + >
1379 + <XIcon className="size-3.5" />
1380 + </TooltipTrigger>
1381 + <TooltipPopup side="top">Discard draft</TooltipPopup>
1382 + </Tooltip>
1383 + ) : null}
1384 + {showSnoozeButton ? (
1385 + <SnoozeMenuButton
1386 + open={snoozeMenuOpen}
1387 + onOpenChange={setSnoozeMenuOpen}
1388 + onSnooze={handleSnoozePreset}
1389 + timestampFormat={props.timestampFormat}
1390 + />
1391 + ) : null}
1392 + {props.settlementSupported ? (
1393 + <Tooltip>
1394 + <TooltipTrigger
1395 + render={
1396 + <button
1397 + type="button"
1398 + aria-label="Settle thread"
1399 + onClick={handleSettleClick}
1400 + onPointerDown={handleActionPointerDown}
1401 + className="-mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"
1402 + />
1403 + }
1404 + >
1405 + <CheckIcon className="size-3.5" />
1406 + Settle
1407 + </TooltipTrigger>
1408 + <TooltipPopup>Settle thread</TooltipPopup>
1409 + </Tooltip>
1410 + ) : null}
1411 + </span>
1412 + ) : null}
1413 + </span>
1414 + )}
1415 + {props.sweepAction !== null ? dragDestination : null}
1416 + </div>
1417 + <div className="mt-1 flex min-w-0">
1418 + {title}
1419 + {isRegeneratingTitle ? (
1420 + <span role="status" className="sr-only">
1421 + Regenerating title
1422 + </span>
1423 + ) : null}
1424 + </div>
1425 + <div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
1426 + {thread.branch ? (
1427 + <>
1428 + <ThreadWorktreeIndicator thread={thread} />
1429 + <span className="flex min-w-0 flex-1 text-muted-foreground/40">
1430 + <MiddleTruncate value={thread.branch} showTitle={false} />
1431 + </span>
1432 + </>
1433 + ) : showsScratchMachine ? (
1434 + <>
1435 + <EnvironmentMachineIcon
1436 + aria-hidden
1437 + kind={props.environmentMachine}
1438 + className="size-3 shrink-0 text-muted-foreground/40"
1439 + />
1440 + <span className="min-w-0 flex-1 truncate text-muted-foreground/40">
1441 + {props.scratchMachineLabel}
1442 + </span>
1443 + </>
1444 + ) : (
1445 + <span className="flex-1" />
1446 + )}
1447 + {terminalStatusIcon}
1448 + {prBadge}
1449 + {diff ? (
1450 + <span className="shrink-0 font-mono">
1451 + <span className="text-diff-addition-foreground">
1452 + +{formatDiffCount(diff.insertions)}
1453 + </span>{" "}
1454 + <span className="text-diff-deletion-foreground">
1455 + −{formatDiffCount(diff.deletions)}
1456 + </span>
1457 + </span>
1458 + ) : null}
1459 + <span
1460 + aria-hidden
1461 + className="pointer-events-none ml-auto inline-flex shrink-0 items-center gap-1"
1462 + >
1463 + {isRemote && !showsScratchMachine ? (
1464 + <span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70">
1465 + <EnvironmentMachineIcon
1466 + aria-hidden
1467 + kind={props.environmentMachine}
1468 + className="size-3.5"
1469 + />
1470 + </span>
1471 + ) : null}
1472 + <SidebarProviderStack
1473 + thread={thread}
1474 + providerEntryByInstanceId={props.providerEntryByInstanceId}
1475 + />
1476 + </span>
1477 + </div>
1478 + </div>
1479 + {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}
1480 + </TooltipTrigger>
1481 + {detailsTooltip}
1482 + </Tooltip>
1483 + </li>
1484 + );
1485 +});
1486 +
1487 +function latestRunDiff(
1488 + thread: SidebarThreadSummary,
1489 +): { insertions: number; deletions: number } | null {
1490 + void thread;
1491 + return null;
1492 +}
1493 +
1494 +export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
1495 + isSettled: boolean;
1496 + thread: SidebarThreadSummary;
1497 + project: EnvironmentProject | null;
1498 + projectDisplayName: string | null;
1499 + environmentLabel: string | null;
1500 + environmentMachine: EnvironmentMachineKind;
1501 + providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;
1502 + isHighlighted: boolean;
1503 + isRouteActive: boolean;
1504 + resultId: string;
1505 + searchMatch: EnvironmentThreadSearchMatch | null;
1506 + searchQuery: string;
1507 + onHighlight: () => void;
1508 + onSelect: () => void;
1509 + onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;
1510 +}) {
1511 + const { thread } = props;
1512 + const accessibility = resolveSidebarRowAccessibility({
1513 + title: thread.title,
1514 + statusLabel: null,
1515 + projectDisplayName: props.projectDisplayName,
1516 + isActive: props.isRouteActive,
1517 + });
1518 + const threadRef = scopeThreadRef(thread.environmentId, thread.id);
1519 + const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(
1520 + props.isHighlighted || props.isRouteActive,
1521 + );
1522 + const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;
1523 + const gitStatus = useEnvironmentQuery(
1524 + leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
1525 + ? vcsEnvironment.status({
1526 + environmentId: thread.environmentId,
1527 + input: { cwd: gitCwd, includeRemote: false },
1528 + })
1529 + : null,
1530 + );
1531 + const visibleGitStatus = useRetainedValue(
1532 + JSON.stringify([thread.environmentId, gitCwd]),
1533 + gitStatus.data,
1534 + );
1535 + const branchMismatch = resolveLocalCheckoutBranchMismatch({
1536 + effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
1537 + activeWorktreePath: thread.worktreePath,
1538 + activeThreadBranch: thread.branch,
1539 + currentGitBranch: visibleGitStatus?.refName ?? null,
1540 + });
1541 + const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;
1542 + const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
1543 + const showInstanceBadge =
1544 + providerEntry !== null &&
1545 + shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
1546 + const selectedModel = providerEntry?.models.find(
1547 + (model) => model.slug === thread.modelSelection.model,
1548 + );
1549 + const modelLabel = selectedModel
1550 + ? getTriggerDisplayModelLabel(selectedModel)
1551 + : thread.modelSelection.model;
1552 + const runningTerminalIds = useThreadRunningTerminalIds({
1553 + environmentId: thread.environmentId,
1554 + threadId: thread.id,
1555 + });
1556 + const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
1557 + const [isFileDragOver, setIsFileDragOver] = useState(false);
1558 + const onFileDropThreads = props.onFileDropThreads;
1559 + const fileDropHandlers = makeWorkspaceFileDropHandlers({
1560 + setDragActive: setIsFileDragOver,
1561 + addFiles: (files) => {
1562 + onFileDropThreads(threadRef, files);
1563 + },
1564 + addFolders: () => {},
1565 + });
1566 + useEffect(() => {
1567 + if (!isFileDragOver) return;
1568 + const clearFileDrag = () => setIsFileDragOver(false);
1569 + window.addEventListener("dragend", clearFileDrag);
1570 + return () => window.removeEventListener("dragend", clearFileDrag);
1571 + }, [isFileDragOver]);
1572 + return (
1573 + <li role="presentation" className="list-none" {...fileDropHandlers}>
1574 + <Tooltip>
1575 + <TooltipTrigger
1576 + render={
1577 + <button
1578 + ref={rowRef}
1579 + id={props.resultId}
1580 + data-search-result-key={scopedThreadKey(threadRef)}
1581 + type="button"
1582 + role="option"
1583 + tabIndex={-1}
1584 + aria-selected={props.isHighlighted}
1585 + aria-current={accessibility.current}
1586 + aria-describedby={`${props.resultId}-pr`}
1587 + aria-label={accessibility.label}
1588 + onMouseMove={props.onHighlight}
1589 + onClick={props.onSelect}
1590 + className={cn(
1591 + "group/sidebar-row group/v2-row flex min-h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1 text-left text-sm outline-none",
1592 + props.isHighlighted || props.isRouteActive
1593 + ? "bg-sidebar-row-active text-sidebar-foreground"
1594 + : "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground",
1595 + isFileDragOver && "ring-1 ring-inset ring-primary/70",
1596 + isFileDragOver && !props.isRouteActive && "bg-sidebar-row-hover",
1597 + )}
1598 + />
1599 + }
1600 + >
1601 + {props.project ? (
1602 + <ProjectFavicon
1603 + project={props.project}
1604 + className={cn(
1605 + "size-4 shrink-0 transition-opacity",
1606 + props.isSettled &&
1607 + !props.isRouteActive &&
1608 + !props.isHighlighted &&
1609 + "opacity-40 grayscale group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",
1610 + )}
1611 + />
1612 + ) : null}
1613 + <span className="flex min-w-0 flex-1 flex-col">
1614 + <span className="flex min-w-0 items-center gap-2.5">
1615 + <span
1616 + className={cn(
1617 + "min-w-0 flex-1 truncate",
1618 + props.isSettled
1619 + ? "font-normal text-secondary-label/70 group-hover/sidebar-row:text-foreground"
1620 + : "font-medium text-foreground",
1621 + (props.isHighlighted || props.isRouteActive) && "text-foreground",
1622 + thread.titleRegeneration != null && "opacity-55",
1623 + )}
1624 + >
1625 + {thread.title}
1626 + </span>
1627 + <span id={`${props.resultId}-pr`} className="contents">
1628 + <ThreadSearchPullRequestNumber
1629 + thread={thread}
1630 + query={props.searchQuery}
1631 + enabled={leaseLiveStatus}
1632 + settled={props.isSettled}
1633 + />
1634 + </span>
1635 + <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">
1636 + <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />
1637 + </span>
1638 + </span>
1639 + {props.searchMatch ? (
1640 + <ThreadSearchMatchExcerpt
1641 + match={{
1642 + source: props.searchMatch.source,
1643 + snippet: props.searchMatch.snippet,
1644 + query: props.searchQuery,
1645 + }}
1646 + />
1647 + ) : null}
1648 + </span>
1649 + </TooltipTrigger>
1650 + <SidebarThreadTooltip
1651 + thread={thread}
1652 + project={props.project}
1653 + projectDisplayName={props.projectDisplayName}
1654 + environmentLabel={props.environmentLabel}
1655 + environmentMachine={props.environmentMachine}
1656 + providerEntry={providerEntry}
1657 + providerEntryByInstanceId={props.providerEntryByInstanceId}
1658 + showInstanceBadge={showInstanceBadge}
1659 + modelInstanceId={modelInstanceId}
1660 + modelLabel={modelLabel}
1661 + branchMismatch={branchMismatch}
1662 + terminalStatus={terminalStatus}
1663 + terminalProcessCount={runningTerminalIds.length}
1664 + />
1665 + </Tooltip>
1666 + </li>
1667 + );
1668 +});