TypeScript
refactor(web): the sidebar's thread rows live in their own file (#22696)
Julius Marminge00ceb2dc7492
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 70296a4806a..747e5e80954 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -1,8 +1,6 @@import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts";import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";-import { ThreadHoverCard, ThreadHoverCardPopup } from "./ThreadHoverCard";import { CollapsibleSectionHeader } from "./ui/collapsible-section-header";-import { ThreadTerminalStatusButton } from "./ThreadStatusIndicators";import { ThreadContextDragGhost } from "./chat/ThreadContextDragGhost";import {dropThreadContext,@@ -11,8 +9,6 @@ import {} from "./chat/threadContextDrag";import { discardComposerDraft } from "../lib/discardComposerDraft";import { requestCustomSnooze } from "./CustomSnoozeDialog";-import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";-import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";import { useAtomValue } from "@effect/atom-react";import * as Option from "effect/Option";import { Atom } from "effect/reactivity";@@ -33,23 +29,12 @@ import { CSS } from "@dnd-kit/utilities";import {canSnooze,effectiveSnoozed,- hasQueuedTurnStart,- QUEUED_TURN_START_GRACE_MS,threadWokeAt,} from "@t3tools/client-runtime/state/thread-settled";import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";-import { formatDiffCount } from "@t3tools/client-runtime/diff-count";+import { sortSettledThreads } from "@t3tools/client-runtime/state/thread-sort";+import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";import {- resolveSettledThreadTimestamp,- sortSettledThreads,-} from "@t3tools/client-runtime/state/thread-sort";-import {- threadSearchMatchKey,- type EnvironmentThreadSearchMatch,-} from "@t3tools/client-runtime/state/thread-search";-import {- formatWorkingDurationLabel,- resolveThreadProviderStack,threadRuntimeCanArchive,type EnvironmentThreadShell,} from "@t3tools/client-runtime/state/models";@@ -61,34 +46,16 @@ import {} from "@t3tools/client-runtime/environment";import {AuthOrchestrationOperateScope,- type EnvironmentMachineKind,type ScopedThreadRef,type ThreadId,} from "@t3tools/contracts";-import type { TimestampFormat } from "@t3tools/contracts/settings";import {- AlarmClockIcon,- AlarmClockOffIcon,- ArrowRightLeftIcon,- CheckIcon,- CircleAlertIcon,- CircleCheckIcon,- CircleDashedIcon,- CircleDotDashedIcon,- ClockIcon,FolderIcon,- GitBranchIcon,ListFilterIcon,- MessageCircleQuestionIcon,- PinIcon,- PinOffIcon,PlusIcon,SettingsIcon,- ShieldQuestionIcon,SquarePenIcon,- TerminalIcon,- Undo2Icon,XIcon,} from "lucide-react";import {@@ -100,12 +67,10 @@ import {useState,type KeyboardEvent as ReactKeyboardEvent,type MouseEvent as ReactMouseEvent,- type PointerEvent as ReactPointerEvent,type ReactNode,} from "react";import { useRouter } from "@tanstack/react-router";-import { useRightPanelStore } from "../rightPanelStore";import {isAtomCommandInterrupted,settlePromise,@@ -126,7 +91,6 @@ import { isTerminalFocused } from "../lib/terminalFocus";import { isModelPickerOpen } from "../modelPickerVisibility";import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";import { isMacPlatform } from "~/lib/utils";-import { useOpenPrLink } from "../lib/openPullRequestLink";import { readLocalApi } from "../localApi";import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";import { selectProjectGroupingSettings } from "../logicalProject";@@ -152,7 +116,6 @@ import { useClientSettings } from "../hooks/useSettings";import { useCopyToClipboard } from "../hooks/useCopyToClipboard";import { useLocalStorage } from "../hooks/useLocalStorage";import { useNowMinute } from "../hooks/useNowMinute";-import { useNowSecond } from "../hooks/useNowSecond";import {useEnvironmentIdentities,useConnectedEnvironmentIds,@@ -169,19 +132,15 @@ import {import { environmentPresentations } from "../state/presentation";import { primaryServerKeybindingsAtom } from "../state/server";import { environmentProjects } from "../state/projects";-import { vcsEnvironment } from "../state/vcs";import { threadEnvironment } from "../state/threads";-import { useEnvironmentQuery } from "../state/query";import { useThreadSearch } from "../state/queries";import { useOrchestrationCommand } from "../state/use-orchestration-command";-import { readEnvironmentScope, useEnvironmentScope } from "../state/session";+import { readEnvironmentScope } from "../state/session";import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";-import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat";import type { SidebarThreadSummary } from "../types";import { isScratchProject } from "@t3tools/client-runtime/state/projects";import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";import { cn } from "~/lib/utils";-import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";import { ProjectEnvironmentBadge } from "./ProjectEnvironmentBadge";import {buildDraftActionMenuItems,@@ -197,7 +156,6 @@ import {deleteSelectedThreadEntries,filterSidebarProjectScopeItems,firstValidTimestampMs,- hasUnseenCompletion,isSidebarNestedLinkClick,isSidebarThreadWorking,isTrailingDoubleClick,@@ -210,14 +168,9 @@ import {resolveSidebarDropVerb,resolveSidebarThreadSection,resolveSidebarRowAccessibility,- type SidebarDropVerb,- resolveSidebarThreadStatus,- resolveThreadLastVisitedAt,searchSidebarThreads,shouldCreateNewThreadInCurrentProject,shouldNavigateAfterThreadPark,- shouldRecedeSidebarThread,- resolveWorkingStartedAt,sidebarListItemId,sidebarMarkerId,sidebarThreadKeyAtY,@@ -226,14 +179,11 @@ import {sortThreadsForSidebar,sortWorkingThreadsBySend,useThreadJumpHintVisibility,- useRetainedValue,- useSidebarRowSubscriptionLease,type SidebarListItem,type SidebarListMarker,type SidebarSection,resolveSidebarRowThreadId,} from "./Sidebar.logic";-import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";import {createSidebarCollisionDetection,createSidebarSortingStrategy,@@ -241,32 +191,12 @@ import {} from "./Sidebar.drag";import { SidebarDragLifecycle, SidebarPointerSensor } from "./Sidebar.pointer";import { createSidebarListMotion } from "./Sidebar.motion";-import {- ThreadPullRequestBadgeControl,- ThreadPullRequestsMiniList,- ThreadWorktreeIndicator,- prStatusIndicator,- resolveThreadPullRequestBadge,- terminalStatusFromRunningIds,- type TerminalStatusIndicator,- useLinkedThreadPullRequest,- ThreadSearchPullRequestNumber,-} from "./ThreadStatusIndicators";import { resolveSnoozePresets, snoozeWakeLabel, type SnoozePreset } from "./Sidebar.snooze";import { ProjectFavicon, type ProjectFaviconProject } from "./ProjectFavicon";-import { ThreadSearchMatchExcerpt } from "./ThreadSearchMatch";-import { makeWorkspaceFileDropHandlers } from "./chat/workspaceFileDrop";-import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";-import { getTriggerDisplayModelLabel } from "./chat/providerIconUtils";-import {- deriveProviderEntriesByEnvironment,- shouldShowInstanceBadge,- type ProviderInstanceEntry,-} from "../providerInstances";-import { useThreadRunningTerminalIds } from "../state/terminalSessions";+import { deriveProviderEntriesByEnvironment } from "../providerInstances";import { useStableCallback } from "../hooks/useStableCallback";import { stackedThreadToast, toastManager } from "./ui/toast";-import { Button, InlineButton } from "./ui/button";+import { Button } from "./ui/button";import {Combobox,ComboboxEmpty,@@ -280,33 +210,24 @@ import {import { SidebarContent, SidebarGroup, useSidebar } from "./ui/sidebar";import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";import { SidebarHeaderIconButton, SidebarThreadHeader } from "./sidebar/SidebarThreadHeader";-import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuTrigger } from "./ui/menu";import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "./ui/tooltip";-import { MiddleTruncate } from "./ui/middle-truncate";import {composerDraftHasUserContent,DraftId,useComposerDraftStore,- useThreadHasUnsentDraft,type ComposerThreadDraftState,type DraftSessionState,} from "../composerDraftStore";import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";--// The fields thread rows show. Provider status pushes refresh `checkedAt`,-// status and auth on every provider; leaving those out keeps each-// environment's map, and every memoized row, stable across them.-type SidebarProviderEntry = Pick<- ProviderInstanceEntry,- | "instanceId"- | "driverKind"- | "enabled"- | "displayName"- | "accentColor"- | "acpRegistryAgentId"- | "acpRegistryIconUrl"- | "models"->;+import {+ SIDEBAR_SORTABLE_DRAG_DISABLED,+ draftPenClassName,+ draftSurfaceClassName,+ SidebarSearchResultRow,+ SortableThreadRow,+ type SidebarProviderEntry,+ type SidebarSweepAction,+} from "./sidebar/SidebarThreadRow";function sameSidebarProviderEntries(left: ReadonlyMap<string, SidebarProviderEntry>,@@ -835,350 +756,6 @@ function checkThreadOperations(return false;}-function compactSidebarTimeLabel(label: string): string {- if (label === "just now") return "now";- return label.endsWith(" ago") ? label.slice(0, -4) : label;-}--// Subscribes to the minute tick itself, so only the label re-renders each-// minute. The minute is passed as the clock so it is the formatter's input.-function RelativeTimeLabel(props: { timestamp: string | null }) {- const nowMinute = useNowMinute();- return props.timestamp === null- ? null- : compactSidebarTimeLabel(- formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),- );-}--function threadTimeTimestamp(thread: SidebarThreadSummary): string {- return thread.latestUserMessageAt ?? thread.updatedAt;-}--function JumpHintBadge(props: { label: string }) {- return (- <span- aria-hidden- 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"- >- {props.label}- </span>- );-}--function WorkingDuration(props: { startedAt: string | null }) {- const startedMs = props.startedAt !== null ? Date.parse(props.startedAt) : Number.NaN;- if (Number.isNaN(startedMs)) return null;- return <WorkingDurationLabel startedMs={startedMs} />;-}--// Self-ticking so only this span re-renders each second, not the whole row;-// the shared tick lands every working row's update in the same frame.-function WorkingDurationLabel(props: { startedMs: number }) {- const nowMs = useNowSecond();- return (- <span className="tabular-nums">{formatWorkingDurationLabel(nowMs - props.startedMs)}</span>- );-}--function terminalProcessLabel(count: number): string {- return `${count} terminal ${count === 1 ? "process" : "processes"} running`;-}--function SidebarProviderStack(props: {- thread: SidebarThreadSummary;- providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;-}) {- const stack = resolveThreadProviderStack(props.thread);- const currentInstanceId = stack[stack.length - 1]!;- const currentEntry = props.providerEntryByInstanceId.get(currentInstanceId) ?? null;- if (currentEntry === null) return null;- const showInstanceBadge = shouldShowInstanceBadge(- currentEntry,- props.providerEntryByInstanceId.values(),- );- const current = (- <ProviderInstanceIcon- driverKind={currentEntry.driverKind}- displayName={currentEntry.displayName}- accentColor={currentEntry.accentColor}- acpRegistryAgentId={currentEntry.acpRegistryAgentId}- acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}- showBadge={showInstanceBadge}- size="compact"- iconClassName="opacity-60"- />- );- if (stack.length === 1) {- return <span className="inline-flex shrink-0 items-center">{current}</span>;- }- return (- <span className="inline-flex shrink-0 items-center gap-1.5">- {stack.slice(0, -1).map((instanceId) => {- const entry = props.providerEntryByInstanceId.get(instanceId);- if (entry === undefined) return null;- return (- <ProviderInstanceIcon- key={instanceId}- driverKind={entry.driverKind}- displayName={entry.displayName}- acpRegistryAgentId={entry.acpRegistryAgentId}- acpRegistryIconUrl={entry.acpRegistryIconUrl}- iconClassName="size-3 opacity-35 grayscale"- />- );- })}- <span className="relative z-10 inline-flex items-center">{current}</span>- </span>- );-}--function SidebarThreadTooltip({- thread,- project,- projectDisplayName,- environmentLabel,- environmentMachine,- providerEntry,- providerEntryByInstanceId,- showInstanceBadge,- modelInstanceId,- modelLabel,- branchMismatch,- terminalStatus,- terminalProcessCount,-}: {- thread: SidebarThreadSummary;- project: ProjectFaviconProject | null;- projectDisplayName: string | null;- environmentLabel: string | null;- environmentMachine: EnvironmentMachineKind;- providerEntry: SidebarProviderEntry | null;- providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;- showInstanceBadge: boolean;- modelInstanceId: string;- modelLabel: string;- branchMismatch: {- threadBranch: string;- currentBranch: string;- } | null;- terminalStatus: TerminalStatusIndicator | null;- terminalProcessCount: number;-}) {- const driverKind = providerEntry?.driverKind ?? null;- const previousProviderNames = thread.providerInstanceHistory- .filter((instanceId) => instanceId !== modelInstanceId)- .map((instanceId) => providerEntryByInstanceId.get(instanceId)?.displayName ?? instanceId);- const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);- return (- <ThreadHoverCardPopup side="right" align="start" sideOffset={4}>- <ThreadHoverCard- title={thread.title}- footer={- supportsMultiplePullRequests && thread.pullRequests.length > 0 ? (- <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground">- <ThreadPullRequestsMiniList pullRequests={thread.pullRequests} />- </div>- ) : null- }- >- {projectDisplayName ? (- <div className="flex min-w-0 items-center gap-2">- {project ? <ProjectFavicon project={project} className="size-3 shrink-0" /> : null}- <div className="min-w-0 truncate text-foreground/75">{projectDisplayName}</div>- </div>- ) : null}- {environmentLabel ? (- <div className="flex min-w-0 items-center gap-2">- <EnvironmentMachineIcon- kind={environmentMachine}- className="size-3 shrink-0 stroke-muted-foreground"- />- <div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div>- </div>- ) : null}- {thread.branch ? (- <div className="flex min-w-0 items-center gap-2">- <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />- <MiddleTruncate value={thread.branch} className="flex" />- </div>- ) : null}- {branchMismatch ? (- <div className="flex min-w-0 items-start gap-2 text-warning">- <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />- <div className="min-w-0 flex-1 wrap-break-word">- You're currently checked out on another branch.- </div>- </div>- ) : null}- {driverKind ? (- <div className="flex min-w-0 items-center gap-2">- <ProviderInstanceIcon- driverKind={driverKind}- displayName={- providerEntry?.displayName ?? thread.runtime?.providerName ?? modelInstanceId- }- accentColor={providerEntry?.accentColor}- acpRegistryAgentId={providerEntry?.acpRegistryAgentId}- acpRegistryIconUrl={providerEntry?.acpRegistryIconUrl}- showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined}- badgeContent="none"- badgeClassName="h-2 min-w-2 px-0"- iconClassName="size-3 shrink-0 grayscale opacity-60"- />- <div className="min-w-0 truncate text-foreground/75">- {showInstanceBadge && providerEntry- ? `${modelLabel} · ${providerEntry.displayName}`- : modelLabel}- </div>- </div>- ) : null}- {previousProviderNames.length > 0 ? (- <div className="flex min-w-0 items-center gap-2">- <ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" />- <div className="min-w-0 truncate text-foreground/75">- Handed off from {previousProviderNames.join(", ")}- </div>- </div>- ) : null}- {terminalStatus ? (- <div className="flex min-w-0 items-center gap-2">- <TerminalIcon- aria-hidden- className={cn("size-3 shrink-0", terminalStatus.colorClass)}- />- <div className="min-w-0 truncate text-foreground/75">- {terminalProcessLabel(terminalProcessCount)}- </div>- </div>- ) : null}- {thread.runtime?.lastError ? (- <div- className={cn(- "flex min-w-0 items-center gap-2",- thread.runtime.lastErrorClass === "usage_limit" ? "text-warning" : "text-error",- )}- >- <CircleAlertIcon className="size-3 shrink-0 stroke-current" />- <div className="min-w-0 truncate">- {thread.runtime.lastErrorClass === "usage_limit"- ? "Usage limit reached"- : "Error occurred"}- </div>- </div>- ) : null}- </ThreadHoverCard>- </ThreadHoverCardPopup>- );-}--function SnoozeMenuButton(props: {- open: boolean;- onOpenChange: (open: boolean) => void;- onSnooze: (preset: Pick<SnoozePreset, "snoozedUntil">) => void;- timestampFormat: TimestampFormat;-}) {- const { open, onOpenChange, onSnooze, timestampFormat } = props;- const presets = open ? resolveSnoozePresets(new Date(), timestampFormat) : [];- return (- <Menu open={open} onOpenChange={onOpenChange}>- <Tooltip>- <TooltipTrigger- render={- <MenuTrigger- render={- <button- type="button"- aria-label="Snooze thread"- onClick={(event) => event.stopPropagation()}- onDoubleClick={(event) => event.stopPropagation()}- 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"- />- }- />- }- >- <ClockIcon className="size-3" />- </TooltipTrigger>- <TooltipPopup>Snooze thread</TooltipPopup>- </Tooltip>- <MenuPopup side="bottom" align="end">- {presets.map((preset) => (- <MenuItem- key={preset.id}- onClick={(event) => {- event.stopPropagation();- onSnooze(preset);- }}- >- {preset.label}- <MenuShortcut>{preset.whenLabel}</MenuShortcut>- </MenuItem>- ))}- <MenuSeparator />- <MenuItem- onClick={async (event) => {- event.stopPropagation();- const choice = await requestCustomSnooze();- if (choice) onSnooze(choice);- }}- >- Custom…- </MenuItem>- </MenuPopup>- </Menu>- );-}--type SortableThreadRowBag = Pick<- ReturnType<typeof useSortable>,- "listeners" | "setNodeRef" | "transform" | "transition" | "isDragging"->;--// useSortable memoizes on its `disabled` object, so a fresh one per render-// re-renders every row and marker on each sidebar update.-const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;-const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;--// Takes the row's props rather than a render function: a closure from the-// sidebar body is new on every sidebar render, which rebuilt the bag and-// re-rendered every memoized row with it.-function SortableThreadRow(- props: Omit<SidebarThreadRowProps, "sortable"> & {- sortableId: string;- sortableDisabled: boolean;- contextDrag: boolean;- },-) {- const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props;- const canOperateThread = useEnvironmentScope(- rowProps.thread.environmentId,- AuthOrchestrationOperateScope,- );- const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({- id: sortableId,- disabled:- sortableDisabled || !canOperateThread- ? SIDEBAR_SORTABLE_DRAG_DISABLED- : SIDEBAR_SORTABLE_DRAG_ENABLED,- animateLayoutChanges: animateSidebarLayoutChanges,- });- // dnd-kit memoizes each field but not the bag, so the memoized row would- // rerender on every shell update without this.- const bag = {- listeners,- setNodeRef,- transform: contextDrag ? null : transform,- transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,- isDragging: isDragging && !contextDrag,- };- // Keyed by variant so a card/slim switch remounts the row.- return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;-}--const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8";-const draftPenClassName = "size-3 shrink-0 text-warning-foreground";-function SortableSidebarMarker(props: {marker: SidebarListMarker;className?: string;@@ -1235,8 +812,6 @@ function SidebarSectionPlaceholder(props: {const SIDEBAR_DRAG_DISTANCE = 6;-type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";-const SIDEBAR_DRAG_LABEL_HEIGHT = 24;function SidebarDragBoundary(props: {@@ -1509,1206 +1084,6 @@ const SidebarDraftBlock = memo(function SidebarDraftBlock(props: {);});-const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {- pin: (- <>- <PinIcon aria-hidden className="size-3" />- Pin- </>- ),- unpin: (- <>- <PinOffIcon aria-hidden className="size-3" />- Unpin- </>- ),- settle: (- <>- <CircleCheckIcon aria-hidden className="size-3" />- Settle- </>- ),- unsettle: (- <>- <Undo2Icon aria-hidden className="size-3" />- Un-settle- </>- ),- wake: (- <>- <AlarmClockOffIcon aria-hidden className="size-3" />- Wake- </>- ),-};--type SidebarThreadRowProps = {- thread: SidebarThreadSummary;- variant: "card" | "slim";- variantAction: SidebarSweepAction;- settlementSupported: boolean;- snoozeSupported: boolean;- pinningSupported: boolean;- isPinned: boolean;- sortable?: SortableThreadRowBag | undefined;- dropVerb: SidebarDropVerb | null;- dragOverPinned: boolean;- sweepAction: SidebarSweepAction | null;- snoozeWakeLabelText: string | null;- wokeAt: string | null;- isActive: boolean;- // Unlike isActive, never true for the ancestor standing in for an open- // subagent: drafts and PR clicks care about which composer is on screen.- isRouteThread: boolean;- openPullRequestsInRightPanel: boolean;- jumpLabel: string | null;- currentEnvironmentId: string | null;- environmentLabel: string | null;- environmentMachine: EnvironmentMachineKind;- scratchMachineLabel: string | null;- project: EnvironmentProject | null;- projectDisplayName: string | null;- providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;- timestampFormat: TimestampFormat;- onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void;- onThreadActivate: (threadRef: ScopedThreadRef) => void;- onStartRename: (threadRef: ScopedThreadRef, title: string) => void;- onRenameTitleChange: (title: string) => void;- onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void;- onCancelRename: () => void;- isRenaming: boolean;- renamingTitle: string;- onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;- onSettle: (threadRef: ScopedThreadRef) => void;- onActionSweepStart: (- threadRef: ScopedThreadRef,- action: SidebarSweepAction,- event: PointerEvent,- ) => void;- onUnsettle: (threadRef: ScopedThreadRef) => void;- onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void;- onUnsnooze: (threadRef: ScopedThreadRef) => void;- onUnpin: (threadRef: ScopedThreadRef) => void;- onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;- onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined;-};--const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {- const {- isRenaming,- onCancelRename,- onCommitRename,- onContextMenu,- onAcknowledgeWoke,- onFileDropThreads,- onRenameTitleChange,- onSettle,- onActionSweepStart,- onSnooze,- onStartRename,- onThreadActivate,- onThreadClick,- onUnsettle,- onUnsnooze,- onUnpin,- openPullRequestsInRightPanel,- renamingTitle,- thread,- variant,- variantAction,- } = props;- const threadRef = scopeThreadRef(thread.environmentId, thread.id);- const threadKey = scopedThreadKey(threadRef);- const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);- useEffect(() => {- if (!canOperateThread && isRenaming) onCancelRename();- }, [canOperateThread, isRenaming, onCancelRename]);- const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(props.isActive);- const isRegeneratingTitle = thread.titleRegeneration != null;- const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);- const lastVisitedAt = resolveThreadLastVisitedAt(thread.lastVisitedAt, localLastVisitedAt);- const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));- const openPrLink = useOpenPrLink();- const runningTerminalIds = useThreadRunningTerminalIds({- environmentId: thread.environmentId,- threadId: thread.id,- });- const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);- const terminalProcessCount = runningTerminalIds.length;- const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread;- const handleDiscardDraftClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- discardComposerDraft(threadRef);- };-- const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;- const linkedPullRequestStatus = useLinkedThreadPullRequest(- thread.environmentId,- thread.linkedPullRequest,- leaseLiveStatus,- thread.pullRequests,- thread.branchPullRequest,- );- const gitStatus = useEnvironmentQuery(- leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null- ? vcsEnvironment.status({- environmentId: thread.environmentId,- input: { cwd: gitCwd, includeRemote: false },- })- : null,- );- const visibleGitStatus = useRetainedValue(- JSON.stringify([thread.environmentId, gitCwd]),- gitStatus.data,- );- const pr = linkedPullRequestStatus?.pr ?? null;- const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);- const currentLinkedPr = supportsMultiplePullRequests- ? resolveThreadCurrentPullRequestLink(thread.pullRequests)- : null;-- const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });- const status = resolveSidebarThreadStatus(thread);- const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);- const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);- const isWoke =- wokeAtDate !== null &&- (lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&- thread.settledOverride !== "settled";- const shouldRecede = shouldRecedeSidebarThread({- status,- isUnread,- isWoke,- isActive: props.isActive,- isSelected,- });- const topStatus =- status === "working"- ? {- label: thread.goal?.status === "active" ? "Goal" : "Working",- icon: "working" as const,- className: "text-info",- }- : status === "waiting"- ? {- label: "Waiting",- icon: "waiting" as const,- className: "text-muted-foreground",- }- : status === "approval"- ? {- label: "Approval",- icon: "approval" as const,- className: "text-warning-foreground",- }- : status === "input"- ? {- label: "Input",- icon: "input" as const,- className: "text-indigo-600 dark:text-indigo-300",- }- : status === "limited"- ? {- label: "Limited",- icon: "failed" as const,- className: "text-warning",- }- : status === "failed"- ? {- label: "Failed",- icon: "failed" as const,- className: "text-error",- }- : isWoke- ? {- label: "Woke",- icon: "woke" as const,- className: "text-warning",- }- : isUnread- ? {- label: "Done",- icon: "done" as const,- className: "text-success",- }- : null;- const isWokeStatus = topStatus?.icon === "woke";-- const branchMismatch = resolveLocalCheckoutBranchMismatch({- effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",- activeWorktreePath: thread.worktreePath,- activeThreadBranch: thread.branch,- currentGitBranch: visibleGitStatus?.refName ?? null,- });- const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider);-- const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;- const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;- const showInstanceBadge =- providerEntry !== null &&- shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());- const selectedModel = providerEntry?.models.find(- (model) => model.slug === thread.modelSelection.model,- );- const modelLabel = selectedModel- ? getTriggerDisplayModelLabel(selectedModel)- : thread.modelSelection.model;-- const isRemote = thread.environmentId !== props.currentEnvironmentId;- const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;-- const detailsTooltip = (- <SidebarThreadTooltip- thread={thread}- project={props.project}- projectDisplayName={props.projectDisplayName}- environmentLabel={props.environmentLabel}- environmentMachine={props.environmentMachine}- providerEntry={providerEntry}- providerEntryByInstanceId={props.providerEntryByInstanceId}- showInstanceBadge={showInstanceBadge}- modelInstanceId={modelInstanceId}- modelLabel={modelLabel}- branchMismatch={branchMismatch}- terminalStatus={terminalStatus}- terminalProcessCount={terminalProcessCount}- />- );-- const handleClick = (event: ReactMouseEvent) => {- onThreadClick(event, threadRef);- };- const handleAcknowledgeWokeClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- if (props.wokeAt === null) return;- onAcknowledgeWoke(threadRef, props.wokeAt);- };- const handleContextMenu = (event: ReactMouseEvent) => {- event.preventDefault();- onContextMenu(threadRef, { x: event.clientX, y: event.clientY });- };- const handleKeyDown = (event: ReactKeyboardEvent) => {- if (event.target !== event.currentTarget) return;- if (event.key !== "Enter" && event.key !== " ") return;- event.preventDefault();- onThreadActivate(threadRef);- };- const handleDoubleClick = (event: ReactMouseEvent) => {- if (- !readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) ||- isRenaming ||- event.metaKey ||- event.ctrlKey ||- event.shiftKey ||- event.altKey- ) {- return;- }- if ((event.target as HTMLElement).closest("button, a, input")) return;- event.preventDefault();- onStartRename(threadRef, thread.title);- };- const [isFileDragOver, setIsFileDragOver] = useState(false);- const fileDropHandlers = onFileDropThreads- ? makeWorkspaceFileDropHandlers({- setDragActive: setIsFileDragOver,- addFiles: (files) => {- onFileDropThreads(threadRef, files);- },- addFolders: () => {},- })- : null;- useEffect(() => {- if (!isFileDragOver) return;- const clearFileDrag = () => setIsFileDragOver(false);- window.addEventListener("dragend", clearFileDrag);- return () => window.removeEventListener("dragend", clearFileDrag);- }, [isFileDragOver]);- const renameCommittedRef = useRef(false);- useEffect(() => {- if (isRenaming) renameCommittedRef.current = false;- }, [isRenaming]);- const handleRenameKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {- event.stopPropagation();- if (event.nativeEvent.isComposing || event.keyCode === 229) return;- if (event.key === "Enter") {- event.preventDefault();- renameCommittedRef.current = true;- onCommitRename(threadRef, renamingTitle, thread.title);- } else if (event.key === "Escape") {- event.preventDefault();- renameCommittedRef.current = true;- onCancelRename();- }- };- const handleRenameBlur = () => {- if (!renameCommittedRef.current) {- onCommitRename(threadRef, renamingTitle, thread.title);- }- };- const handleSettleClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- onSettle(threadRef);- };- const handleActionPointerDown = (event: ReactPointerEvent) => {- if (!event.isPrimary || event.button !== 0) return;- event.stopPropagation();- onActionSweepStart(threadRef, variantAction, event.nativeEvent);- };- const handleUnsettleClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- onUnsettle(threadRef);- };- const handleUnsnoozeClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- onUnsnooze(threadRef);- };- const handleUnpinClick = (event: ReactMouseEvent) => {- event.preventDefault();- event.stopPropagation();- onUnpin(threadRef);- };- const handleSnoozePreset = (preset: Pick<SnoozePreset, "snoozedUntil">) => {- onSnooze(threadRef, preset);- };- const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);- // The React Compiler caches render results on their inputs, so a clock read- // here would stay frozen until `thread` changes and a queued-turn gate would- // never reopen. The gate's clock is state, reset with the thread.- const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({- thread,- now: new Date().toISOString(),- }));- if (snoozeGateClock.thread !== thread) {- setSnoozeGateClock({ thread, now: new Date().toISOString() });- }- const snoozeGateNow = snoozeGateClock.now;- const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })- ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS- : Number.NaN;- useEffect(() => {- // A gate still closed past its expiry is held by runtime status, not time,- // so no clock tick can open it.- if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {- return;- }- const id = window.setTimeout(- () => setSnoozeGateClock({ thread, now: new Date().toISOString() }),- Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),- );- return () => window.clearTimeout(id);- }, [snoozeGateExpiryMs, snoozeGateNow, thread]);- const showSnoozeButton =- canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });- // Closing here, not just masking, keeps the menu from reopening when the button returns.- if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);- const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;- const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {- const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;- if (!url) return;- const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;- const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);- if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {- onThreadActivate(threadRef);- }- };-- const rowSurfaceClassName = cn(- "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",- variantAction === "unsettle" && "[&:not(:hover):not(:focus-within)_*]:text-secondary-label/70",- props.isActive- ? "bg-sidebar-row-active text-sidebar-foreground"- : isSelected || props.sweepAction !== null- ? "bg-sidebar-row-selected text-sidebar-foreground"- : hasUnsentDraft- ? cn(draftSurfaceClassName, "text-sidebar-foreground")- : shouldRecede- ? "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"- : "bg-transparent text-sidebar-foreground hover:bg-sidebar-row-hover",- shouldRecede &&- status === "working" &&- "opacity-70 transition-opacity hover:opacity-100 focus-within:opacity-100 motion-reduce:transition-none",- isFileDragOver && "ring-1 ring-inset ring-primary/70",- isFileDragOver && !props.isActive && !isSelected && "bg-sidebar-row-hover",- props.sortable?.isDragging &&- "bg-sidebar bg-linear-to-b from-sidebar-row-active to-sidebar-row-active text-sidebar-foreground opacity-100 shadow-lg",- );- const sortable = props.sortable;- const sortableRootProps = sortable- ? {- ref: sortable.setNodeRef,- style: {- transform: CSS.Translate.toString(sortable.transform),- transition: sortable.transition,- // A zero-height boundary also makes dnd-kit scale the source to- // zero. Only projected peers use scaleY as a visibility sentinel.- visibility:- !sortable.isDragging && sortable.transform?.scaleY === 0- ? ("hidden" as const)- : undefined,- },- ...sortable.listeners,- }- : {};- const destinationVerb = sortable?.isDragging- ? props.dropVerb- : props.sweepAction === "unsnooze"- ? "wake"- : props.sweepAction;- const dragDestination =- destinationVerb !== null ? (- <span- role="status"- 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"- >- {dropVerbBadge[destinationVerb]}- </span>- ) : null;-- const accessibility = resolveSidebarRowAccessibility({- title: thread.title,- statusLabel: topStatus?.label ?? null,- projectDisplayName: props.projectDisplayName,- isActive: props.isActive,- });-- const title =- isRenaming && canOperateThread ? (- <input- autoFocus- value={renamingTitle}- aria-label="Thread title"- onChange={(event) => onRenameTitleChange(event.target.value)}- onFocus={(event) => event.currentTarget.select()}- onKeyDown={handleRenameKeyDown}- onBlur={handleRenameBlur}- onClick={(event) => event.stopPropagation()}- onDoubleClick={(event) => event.stopPropagation()}- 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"- />- ) : (- <span- aria-hidden- className={cn(- "min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",- shouldRecede ? "font-normal" : "font-medium",- variant === "card"- ? cn(- "truncate",- shouldRecede- ? "text-secondary-label"- : isUnread || isWoke || status === "input"- ? "text-foreground"- : status === "failed"- ? "text-foreground/95"- : "text-foreground/90",- )- : cn(- "truncate group-focus-within/sidebar-row:text-foreground group-hover/sidebar-row:text-foreground",- shouldRecede- ? "text-secondary-label/70"- : props.isActive || isWoke || status === "input"- ? "text-foreground"- : isUnread- ? "text-muted-foreground"- : "text-secondary-label/70",- ),- isRegeneratingTitle && "opacity-55",- )}- >- {thread.title}- </span>- );- const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;-- const prBadgeShape = supportsMultiplePullRequests- ? resolveThreadPullRequestBadge(thread.pullRequests)- : null;- const handlePrListClick = () => {- useRightPanelStore.getState().open(threadRef, "pull-requests");- if (!props.isRouteThread) onThreadActivate(threadRef);- };- const prBadge =- prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? (- <ThreadPullRequestBadgeControl- render={<InlineButton />}- badge={prBadgeShape}- pullRequests={thread.pullRequests}- number={pr?.number ?? currentLinkedPr?.number}- url={pr?.url ?? currentLinkedPr?.url}- status={prStatus}- onOpenList={handlePrListClick}- onOpenPullRequest={handlePrClick}- />- ) : null;- const terminalStatusIcon = (- <ThreadTerminalStatusButton- threadRef={threadRef}- terminalIds={runningTerminalIds}- onThreadActivate={onThreadActivate}- />- );- const draftIndicator = hasUnsentDraft ? (- <Tooltip>- <TooltipTrigger- render={- <span- role="img"- aria-label="Unsent draft"- data-testid={`sidebar-draft-indicator-${thread.id}`}- className="inline-flex shrink-0 items-center"- />- }- >- <SquarePenIcon aria-hidden className={draftPenClassName} />- </TooltipTrigger>- <TooltipPopup side="top">Unsent draft</TooltipPopup>- </Tooltip>- ) : null;- const showPin =- props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null));- const pinIndicator = showPin ? (- props.pinningSupported && canOperateThread && !sortable?.isDragging ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Unpin thread"- onClick={handleUnpinClick}- 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"- />- }- >- <PinIcon- aria-hidden- className="size-3 shrink-0 group-hover/unpin:hidden group-focus-visible/unpin:hidden"- />- <PinOffIcon- aria-hidden- className="hidden size-3 shrink-0 group-hover/unpin:block group-focus-visible/unpin:block"- />- </TooltipTrigger>- <TooltipPopup>Unpin thread</TooltipPopup>- </Tooltip>- ) : (- <PinIcon- aria-label="Pinned"- role="img"- className="size-3 shrink-0 text-muted-foreground/65"- />- )- ) : null;-- if (variant === "slim") {- return (- <li- data-thread-item={threadKey}- {...sortableRootProps}- {...(fileDropHandlers ?? {})}- className={cn(- "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]",- sortable?.isDragging && "relative z-20",- )}- >- <Tooltip disabled={sortable?.isDragging}>- <TooltipTrigger- render={- <div- ref={rowRef}- role="button"- tabIndex={0}- aria-label={accessibility.label}- aria-current={accessibility.current}- data-testid="sidebar-row-slim"- aria-busy={isRegeneratingTitle || undefined}- className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}- onClick={handleClick}- onDoubleClick={handleDoubleClick}- onKeyDown={handleKeyDown}- onContextMenu={handleContextMenu}- />- }- >- {accessibleTitle}- <span- className={cn(- "flex shrink-0 items-center transition-opacity",- (!props.isActive || variantAction === "unsettle") &&- "opacity-40 grayscale group-focus-within/sidebar-row:opacity-100 group-focus-within/sidebar-row:grayscale-0 group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",- )}- >- {props.project ? <ProjectFavicon project={props.project} className="size-4" /> : null}- </span>- {draftIndicator}- {title}- {pinIndicator}- {terminalStatusIcon}- {isRegeneratingTitle ? (- <span role="status" className="sr-only">- Regenerating title- </span>- ) : null}- {prBadge}- {sortable?.isDragging ? (- dragDestination- ) : (- <span- className={cn(- "relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end",- props.sweepAction !== null && "hidden",- )}- >- <span- className={cn(- "inline-flex justify-end tabular-nums text-secondary-label transition-opacity",- !isWoke && "group-any-hover/sidebar-row:opacity-0",- )}- >- {variantAction === "unsnooze" && props.snoozeWakeLabelText !== null ? (- <span className="text-xs text-info-foreground tabular-nums">- {props.snoozeWakeLabelText}- </span>- ) : isWoke ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Dismiss Woke notification"- onClick={handleAcknowledgeWokeClick}- 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"- >- <AlarmClockIcon aria-hidden className="size-3" />- <span role="status">Woke</span>- </button>- }- />- <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>- </Tooltip>- ) : (- <span className="text-xs">- <RelativeTimeLabel- timestamp={- variantAction === "unsettle"- ? resolveSettledThreadTimestamp(thread)- : threadTimeTimestamp(thread)- }- />- </span>- )}- </span>- {variantAction === "unsnooze" ? (- !props.snoozeSupported ? null : (- <button- type="button"- aria-label="Wake thread now"- onClick={handleUnsnoozeClick}- onPointerDown={handleActionPointerDown}- className={cn(- "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",- isWoke && "group-any-hover/sidebar-row:static",- )}- >- <AlarmClockOffIcon className="mb-px size-3" />- </button>- )- ) : !props.settlementSupported ? null : variantAction === "unsettle" ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Un-settle thread"- onClick={handleUnsettleClick}- onPointerDown={handleActionPointerDown}- className={cn(- "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",- isWoke && "group-any-hover/sidebar-row:static",- )}- />- }- >- <Undo2Icon className="mb-px size-3.5" />- </TooltipTrigger>- <TooltipPopup side="top">Un-settle thread</TooltipPopup>- </Tooltip>- ) : (- <button- type="button"- aria-label="Settle thread"- onClick={handleSettleClick}- onPointerDown={handleActionPointerDown}- className={cn(- "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",- isWoke && "group-any-hover/sidebar-row:static",- )}- >- <CheckIcon className="size-3" />- </button>- )}- </span>- )}- {props.sweepAction !== null ? dragDestination : null}- {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}- </TooltipTrigger>- {detailsTooltip}- </Tooltip>- </li>- );- }-- const diff = latestRunDiff(thread);-- return (- <li- data-thread-item={threadKey}- {...sortableRootProps}- {...(fileDropHandlers ?? {})}- className={cn(- "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",- sortable?.isDragging && "relative z-20",- )}- >- <Tooltip disabled={snoozeMenuOpen || sortable?.isDragging}>- <TooltipTrigger- render={- <div- ref={rowRef}- role="button"- tabIndex={0}- aria-label={accessibility.label}- aria-current={accessibility.current}- data-testid="sidebar-row-card"- aria-busy={isRegeneratingTitle || undefined}- className={rowSurfaceClassName}- onClick={handleClick}- onDoubleClick={handleDoubleClick}- onKeyDown={handleKeyDown}- onContextMenu={handleContextMenu}- />- }- >- {accessibleTitle}- <div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">- <div className="flex h-5 min-w-0 items-center gap-1.5">- {draftIndicator}- {props.project ? (- <ProjectFavicon project={props.project} className="size-4 shrink-0" />- ) : null}- {/* Left of the status slot, the pin would slide when hover swaps the- label for the wider row controls. */}- {pinIndicator}- {props.projectDisplayName ? (- <span- className={cn(- "min-w-0 flex-1 truncate text-secondary-label text-xs",- shouldRecede ? "font-normal" : "font-medium",- )}- >- {props.projectDisplayName}- </span>- ) : (- <span className="flex-1" />- )}- {sortable?.isDragging ? (- dragDestination- ) : (- <span- className={cn(- "group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs",- props.sweepAction !== null && "hidden",- )}- >- <span- className={cn(- isWokeStatus- ? "pointer-events-auto"- : "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",- "flex items-center self-center justify-self-end tabular-nums text-secondary-label transition-opacity",- snoozeMenuOpen && "pointer-events-none absolute right-0 opacity-0",- )}- >- {topStatus ? (- isWokeStatus ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Dismiss Woke notification"- onClick={handleAcknowledgeWokeClick}- className={cn(- "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",- topStatus.className,- )}- >- <AlarmClockIcon aria-hidden className="size-4 shrink-0" />- <span role="status">{topStatus.label}</span>- </button>- }- />- <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>- </Tooltip>- ) : (- <span- className={cn(- "inline-flex items-center gap-1 font-medium",- topStatus.className,- )}- >- {topStatus.icon === "working" ? (- <CircleDashedIcon aria-hidden className="size-4 shrink-0" />- ) : topStatus.icon === "waiting" ? (- <CircleDotDashedIcon aria-hidden className="size-4 shrink-0" />- ) : topStatus.icon === "input" ? (- <MessageCircleQuestionIcon aria-hidden className="size-4 shrink-0" />- ) : topStatus.icon === "approval" ? (- <ShieldQuestionIcon aria-hidden className="size-4 shrink-0" />- ) : topStatus.icon === "failed" ? (- <CircleAlertIcon aria-hidden className="size-4 shrink-0" />- ) : topStatus.icon === "done" ? (- <CircleCheckIcon aria-hidden className="size-4 shrink-0" />- ) : null}- {/* The label alone is the live region: a role="status"- wrapper around the ticking duration would make- screen readers announce every second. */}- <span role="status">{topStatus.label}</span>- {status === "working" ? (- <span aria-hidden>- <WorkingDuration startedAt={resolveWorkingStartedAt(thread)} />- </span>- ) : status === "waiting" ? (- <span aria-hidden>- <WorkingDuration startedAt={thread.latestRun?.completedAt ?? null} />- </span>- ) : null}- </span>- )- ) : (- <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />- )}- </span>- {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (- <span- className={cn(- // focus-visible, not focus-within: a mouse click leaves- // the Settle button focused, and a plain focus-within- // would keep the controls pinned over the status label- // once the pointer moves away (e.g. after a failed- // settle) instead of cross-fading back.- "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",- snoozeMenuOpen && "pointer-events-auto static opacity-100",- )}- >- {hasUnsentDraft ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Discard draft"- onClick={handleDiscardDraftClick}- className="inline-flex cursor-pointer items-center rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"- />- }- >- <XIcon className="size-3.5" />- </TooltipTrigger>- <TooltipPopup side="top">Discard draft</TooltipPopup>- </Tooltip>- ) : null}- {showSnoozeButton ? (- <SnoozeMenuButton- open={snoozeMenuOpen}- onOpenChange={setSnoozeMenuOpen}- onSnooze={handleSnoozePreset}- timestampFormat={props.timestampFormat}- />- ) : null}- {props.settlementSupported ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label="Settle thread"- onClick={handleSettleClick}- onPointerDown={handleActionPointerDown}- 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"- />- }- >- <CheckIcon className="size-3.5" />- Settle- </TooltipTrigger>- <TooltipPopup>Settle thread</TooltipPopup>- </Tooltip>- ) : null}- </span>- ) : null}- </span>- )}- {props.sweepAction !== null ? dragDestination : null}- </div>- <div className="mt-1 flex min-w-0">- {title}- {isRegeneratingTitle ? (- <span role="status" className="sr-only">- Regenerating title- </span>- ) : null}- </div>- <div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">- {thread.branch ? (- <>- <ThreadWorktreeIndicator thread={thread} />- <span className="flex min-w-0 flex-1 text-muted-foreground/40">- <MiddleTruncate value={thread.branch} showTitle={false} />- </span>- </>- ) : showsScratchMachine ? (- <>- <EnvironmentMachineIcon- aria-hidden- kind={props.environmentMachine}- className="size-3 shrink-0 text-muted-foreground/40"- />- <span className="min-w-0 flex-1 truncate text-muted-foreground/40">- {props.scratchMachineLabel}- </span>- </>- ) : (- <span className="flex-1" />- )}- {terminalStatusIcon}- {prBadge}- {diff ? (- <span className="shrink-0 font-mono">- <span className="text-diff-addition-foreground">- +{formatDiffCount(diff.insertions)}- </span>{" "}- <span className="text-diff-deletion-foreground">- −{formatDiffCount(diff.deletions)}- </span>- </span>- ) : null}- <span- aria-hidden- className="pointer-events-none ml-auto inline-flex shrink-0 items-center gap-1"- >- {isRemote && !showsScratchMachine ? (- <span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70">- <EnvironmentMachineIcon- aria-hidden- kind={props.environmentMachine}- className="size-3.5"- />- </span>- ) : null}- <SidebarProviderStack- thread={thread}- providerEntryByInstanceId={props.providerEntryByInstanceId}- />- </span>- </div>- </div>- {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}- </TooltipTrigger>- {detailsTooltip}- </Tooltip>- </li>- );-});--function latestRunDiff(- thread: SidebarThreadSummary,-): { insertions: number; deletions: number } | null {- void thread;- return null;-}--const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {- isSettled: boolean;- thread: SidebarThreadSummary;- project: EnvironmentProject | null;- projectDisplayName: string | null;- environmentLabel: string | null;- environmentMachine: EnvironmentMachineKind;- providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;- isHighlighted: boolean;- isRouteActive: boolean;- resultId: string;- searchMatch: EnvironmentThreadSearchMatch | null;- searchQuery: string;- onHighlight: () => void;- onSelect: () => void;- onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;-}) {- const { thread } = props;- const accessibility = resolveSidebarRowAccessibility({- title: thread.title,- statusLabel: null,- projectDisplayName: props.projectDisplayName,- isActive: props.isRouteActive,- });- const threadRef = scopeThreadRef(thread.environmentId, thread.id);- const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(- props.isHighlighted || props.isRouteActive,- );- const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;- const gitStatus = useEnvironmentQuery(- leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null- ? vcsEnvironment.status({- environmentId: thread.environmentId,- input: { cwd: gitCwd, includeRemote: false },- })- : null,- );- const visibleGitStatus = useRetainedValue(- JSON.stringify([thread.environmentId, gitCwd]),- gitStatus.data,- );- const branchMismatch = resolveLocalCheckoutBranchMismatch({- effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",- activeWorktreePath: thread.worktreePath,- activeThreadBranch: thread.branch,- currentGitBranch: visibleGitStatus?.refName ?? null,- });- const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;- const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;- const showInstanceBadge =- providerEntry !== null &&- shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());- const selectedModel = providerEntry?.models.find(- (model) => model.slug === thread.modelSelection.model,- );- const modelLabel = selectedModel- ? getTriggerDisplayModelLabel(selectedModel)- : thread.modelSelection.model;- const runningTerminalIds = useThreadRunningTerminalIds({- environmentId: thread.environmentId,- threadId: thread.id,- });- const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);- const [isFileDragOver, setIsFileDragOver] = useState(false);- const onFileDropThreads = props.onFileDropThreads;- const fileDropHandlers = makeWorkspaceFileDropHandlers({- setDragActive: setIsFileDragOver,- addFiles: (files) => {- onFileDropThreads(threadRef, files);- },- addFolders: () => {},- });- useEffect(() => {- if (!isFileDragOver) return;- const clearFileDrag = () => setIsFileDragOver(false);- window.addEventListener("dragend", clearFileDrag);- return () => window.removeEventListener("dragend", clearFileDrag);- }, [isFileDragOver]);- return (- <li role="presentation" className="list-none" {...fileDropHandlers}>- <Tooltip>- <TooltipTrigger- render={- <button- ref={rowRef}- id={props.resultId}- data-search-result-key={scopedThreadKey(threadRef)}- type="button"- role="option"- tabIndex={-1}- aria-selected={props.isHighlighted}- aria-current={accessibility.current}- aria-describedby={`${props.resultId}-pr`}- aria-label={accessibility.label}- onMouseMove={props.onHighlight}- onClick={props.onSelect}- className={cn(- "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",- props.isHighlighted || props.isRouteActive- ? "bg-sidebar-row-active text-sidebar-foreground"- : "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground",- isFileDragOver && "ring-1 ring-inset ring-primary/70",- isFileDragOver && !props.isRouteActive && "bg-sidebar-row-hover",- )}- />- }- >- {props.project ? (- <ProjectFavicon- project={props.project}- className={cn(- "size-4 shrink-0 transition-opacity",- props.isSettled &&- !props.isRouteActive &&- !props.isHighlighted &&- "opacity-40 grayscale group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",- )}- />- ) : null}- <span className="flex min-w-0 flex-1 flex-col">- <span className="flex min-w-0 items-center gap-2.5">- <span- className={cn(- "min-w-0 flex-1 truncate",- props.isSettled- ? "font-normal text-secondary-label/70 group-hover/sidebar-row:text-foreground"- : "font-medium text-foreground",- (props.isHighlighted || props.isRouteActive) && "text-foreground",- thread.titleRegeneration != null && "opacity-55",- )}- >- {thread.title}- </span>- <span id={`${props.resultId}-pr`} className="contents">- <ThreadSearchPullRequestNumber- thread={thread}- query={props.searchQuery}- enabled={leaseLiveStatus}- settled={props.isSettled}- />- </span>- <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">- <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />- </span>- </span>- {props.searchMatch ? (- <ThreadSearchMatchExcerpt- match={{- source: props.searchMatch.source,- snippet: props.searchMatch.snippet,- query: props.searchQuery,- }}- />- ) : null}- </span>- </TooltipTrigger>- <SidebarThreadTooltip- thread={thread}- project={props.project}- projectDisplayName={props.projectDisplayName}- environmentLabel={props.environmentLabel}- environmentMachine={props.environmentMachine}- providerEntry={providerEntry}- providerEntryByInstanceId={props.providerEntryByInstanceId}- showInstanceBadge={showInstanceBadge}- modelInstanceId={modelInstanceId}- modelLabel={modelLabel}- branchMismatch={branchMismatch}- terminalStatus={terminalStatus}- terminalProcessCount={runningTerminalIds.length}- />- </Tooltip>- </li>- );-});-export default function Sidebar() {const {projects,diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsxnew file mode 100644index 00000000000..a73ca0725a9--- /dev/null+++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx@@ -0,0 +1,1668 @@+import { ThreadHoverCard, ThreadHoverCardPopup } from "../ThreadHoverCard";+import { ThreadTerminalStatusButton } from "../ThreadStatusIndicators";+import { discardComposerDraft } from "../../lib/discardComposerDraft";+import { requestCustomSnooze } from "../CustomSnoozeDialog";+import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";+import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";+import { useSortable } from "@dnd-kit/sortable";+import { CSS } from "@dnd-kit/utilities";+import {+ canSnooze,+ hasQueuedTurnStart,+ QUEUED_TURN_START_GRACE_MS,+} from "@t3tools/client-runtime/state/thread-settled";+import { formatDiffCount } from "@t3tools/client-runtime/diff-count";+import { resolveSettledThreadTimestamp } from "@t3tools/client-runtime/state/thread-sort";+import { type EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";+import {+ formatWorkingDurationLabel,+ resolveThreadProviderStack,+} from "@t3tools/client-runtime/state/models";+import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";+import {+ AuthOrchestrationOperateScope,+ type EnvironmentMachineKind,+ type ScopedThreadRef,+} from "@t3tools/contracts";++import type { TimestampFormat } from "@t3tools/contracts/settings";+import {+ AlarmClockIcon,+ AlarmClockOffIcon,+ ArrowRightLeftIcon,+ CheckIcon,+ CircleAlertIcon,+ CircleCheckIcon,+ CircleDashedIcon,+ CircleDotDashedIcon,+ ClockIcon,+ GitBranchIcon,+ MessageCircleQuestionIcon,+ PinIcon,+ PinOffIcon,+ ShieldQuestionIcon,+ SquarePenIcon,+ TerminalIcon,+ Undo2Icon,+ XIcon,+} from "lucide-react";+import {+ memo,+ useEffect,+ useRef,+ useState,+ type KeyboardEvent as ReactKeyboardEvent,+ type MouseEvent as ReactMouseEvent,+ type PointerEvent as ReactPointerEvent,+ type ReactNode,+} from "react";++import { useRightPanelStore } from "../../rightPanelStore";+import { useOpenPrLink } from "../../lib/openPullRequestLink";+import { useUiStateStore } from "../../uiStateStore";+import { useThreadSelectionStore } from "../../threadSelectionStore";+import { useNowMinute } from "../../hooks/useNowMinute";+import { useNowSecond } from "../../hooks/useNowSecond";+import { vcsEnvironment } from "../../state/vcs";+import { useEnvironmentQuery } from "../../state/query";+import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";+import { formatRelativeTimeLabel, parseTimestampDate } from "../../timestampFormat";+import type { SidebarThreadSummary } from "../../types";+import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";+import { cn } from "~/lib/utils";+import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";+import {+ animateSidebarLayoutChanges,+ hasUnseenCompletion,+ resolveSidebarRowAccessibility,+ type SidebarDropVerb,+ resolveSidebarThreadStatus,+ resolveThreadLastVisitedAt,+ shouldRecedeSidebarThread,+ resolveWorkingStartedAt,+ useRetainedValue,+ useSidebarRowSubscriptionLease,+} from "../Sidebar.logic";+import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic";+import {+ ThreadPullRequestBadgeControl,+ ThreadPullRequestsMiniList,+ ThreadWorktreeIndicator,+ prStatusIndicator,+ resolveThreadPullRequestBadge,+ terminalStatusFromRunningIds,+ type TerminalStatusIndicator,+ useLinkedThreadPullRequest,+ ThreadSearchPullRequestNumber,+} from "../ThreadStatusIndicators";+import { resolveSnoozePresets, type SnoozePreset } from "../Sidebar.snooze";+import { ProjectFavicon, type ProjectFaviconProject } from "../ProjectFavicon";+import { ThreadSearchMatchExcerpt } from "../ThreadSearchMatch";+import { makeWorkspaceFileDropHandlers } from "../chat/workspaceFileDrop";+import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";+import { getTriggerDisplayModelLabel } from "../chat/providerIconUtils";+import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances";+import { useThreadRunningTerminalIds } from "../../state/terminalSessions";+import { InlineButton } from "../ui/button";+import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuTrigger } from "../ui/menu";+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";+import { MiddleTruncate } from "../ui/middle-truncate";+import { useThreadHasUnsentDraft } from "../../composerDraftStore";++// The fields thread rows show. Provider status pushes refresh `checkedAt`,+// status and auth on every provider; leaving those out keeps each+// environment's map, and every memoized row, stable across them.+export type SidebarProviderEntry = Pick<+ ProviderInstanceEntry,+ | "instanceId"+ | "driverKind"+ | "enabled"+ | "displayName"+ | "accentColor"+ | "acpRegistryAgentId"+ | "acpRegistryIconUrl"+ | "models"+>;+function compactSidebarTimeLabel(label: string): string {+ if (label === "just now") return "now";+ return label.endsWith(" ago") ? label.slice(0, -4) : label;+}++// Subscribes to the minute tick itself, so only the label re-renders each+// minute. The minute is passed as the clock so it is the formatter's input.+function RelativeTimeLabel(props: { timestamp: string | null }) {+ const nowMinute = useNowMinute();+ return props.timestamp === null+ ? null+ : compactSidebarTimeLabel(+ formatRelativeTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`)),+ );+}++function threadTimeTimestamp(thread: SidebarThreadSummary): string {+ return thread.latestUserMessageAt ?? thread.updatedAt;+}++function JumpHintBadge(props: { label: string }) {+ return (+ <span+ aria-hidden+ 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"+ >+ {props.label}+ </span>+ );+}++function WorkingDuration(props: { startedAt: string | null }) {+ const startedMs = props.startedAt !== null ? Date.parse(props.startedAt) : Number.NaN;+ if (Number.isNaN(startedMs)) return null;+ return <WorkingDurationLabel startedMs={startedMs} />;+}++// Self-ticking so only this span re-renders each second, not the whole row;+// the shared tick lands every working row's update in the same frame.+function WorkingDurationLabel(props: { startedMs: number }) {+ const nowMs = useNowSecond();+ return (+ <span className="tabular-nums">{formatWorkingDurationLabel(nowMs - props.startedMs)}</span>+ );+}++function terminalProcessLabel(count: number): string {+ return `${count} terminal ${count === 1 ? "process" : "processes"} running`;+}++function SidebarProviderStack(props: {+ thread: SidebarThreadSummary;+ providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;+}) {+ const stack = resolveThreadProviderStack(props.thread);+ const currentInstanceId = stack[stack.length - 1]!;+ const currentEntry = props.providerEntryByInstanceId.get(currentInstanceId) ?? null;+ if (currentEntry === null) return null;+ const showInstanceBadge = shouldShowInstanceBadge(+ currentEntry,+ props.providerEntryByInstanceId.values(),+ );+ const current = (+ <ProviderInstanceIcon+ driverKind={currentEntry.driverKind}+ displayName={currentEntry.displayName}+ accentColor={currentEntry.accentColor}+ acpRegistryAgentId={currentEntry.acpRegistryAgentId}+ acpRegistryIconUrl={currentEntry.acpRegistryIconUrl}+ showBadge={showInstanceBadge}+ size="compact"+ iconClassName="opacity-60"+ />+ );+ if (stack.length === 1) {+ return <span className="inline-flex shrink-0 items-center">{current}</span>;+ }+ return (+ <span className="inline-flex shrink-0 items-center gap-1.5">+ {stack.slice(0, -1).map((instanceId) => {+ const entry = props.providerEntryByInstanceId.get(instanceId);+ if (entry === undefined) return null;+ return (+ <ProviderInstanceIcon+ key={instanceId}+ driverKind={entry.driverKind}+ displayName={entry.displayName}+ acpRegistryAgentId={entry.acpRegistryAgentId}+ acpRegistryIconUrl={entry.acpRegistryIconUrl}+ iconClassName="size-3 opacity-35 grayscale"+ />+ );+ })}+ <span className="relative z-10 inline-flex items-center">{current}</span>+ </span>+ );+}++function SidebarThreadTooltip({+ thread,+ project,+ projectDisplayName,+ environmentLabel,+ environmentMachine,+ providerEntry,+ providerEntryByInstanceId,+ showInstanceBadge,+ modelInstanceId,+ modelLabel,+ branchMismatch,+ terminalStatus,+ terminalProcessCount,+}: {+ thread: SidebarThreadSummary;+ project: ProjectFaviconProject | null;+ projectDisplayName: string | null;+ environmentLabel: string | null;+ environmentMachine: EnvironmentMachineKind;+ providerEntry: SidebarProviderEntry | null;+ providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;+ showInstanceBadge: boolean;+ modelInstanceId: string;+ modelLabel: string;+ branchMismatch: {+ threadBranch: string;+ currentBranch: string;+ } | null;+ terminalStatus: TerminalStatusIndicator | null;+ terminalProcessCount: number;+}) {+ const driverKind = providerEntry?.driverKind ?? null;+ const previousProviderNames = thread.providerInstanceHistory+ .filter((instanceId) => instanceId !== modelInstanceId)+ .map((instanceId) => providerEntryByInstanceId.get(instanceId)?.displayName ?? instanceId);+ const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);+ return (+ <ThreadHoverCardPopup side="right" align="start" sideOffset={4}>+ <ThreadHoverCard+ title={thread.title}+ footer={+ supportsMultiplePullRequests && thread.pullRequests.length > 0 ? (+ <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground">+ <ThreadPullRequestsMiniList pullRequests={thread.pullRequests} />+ </div>+ ) : null+ }+ >+ {projectDisplayName ? (+ <div className="flex min-w-0 items-center gap-2">+ {project ? <ProjectFavicon project={project} className="size-3 shrink-0" /> : null}+ <div className="min-w-0 truncate text-foreground/75">{projectDisplayName}</div>+ </div>+ ) : null}+ {environmentLabel ? (+ <div className="flex min-w-0 items-center gap-2">+ <EnvironmentMachineIcon+ kind={environmentMachine}+ className="size-3 shrink-0 stroke-muted-foreground"+ />+ <div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div>+ </div>+ ) : null}+ {thread.branch ? (+ <div className="flex min-w-0 items-center gap-2">+ <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />+ <MiddleTruncate value={thread.branch} className="flex" />+ </div>+ ) : null}+ {branchMismatch ? (+ <div className="flex min-w-0 items-start gap-2 text-warning">+ <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />+ <div className="min-w-0 flex-1 wrap-break-word">+ You're currently checked out on another branch.+ </div>+ </div>+ ) : null}+ {driverKind ? (+ <div className="flex min-w-0 items-center gap-2">+ <ProviderInstanceIcon+ driverKind={driverKind}+ displayName={+ providerEntry?.displayName ?? thread.runtime?.providerName ?? modelInstanceId+ }+ accentColor={providerEntry?.accentColor}+ acpRegistryAgentId={providerEntry?.acpRegistryAgentId}+ acpRegistryIconUrl={providerEntry?.acpRegistryIconUrl}+ showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined}+ badgeContent="none"+ badgeClassName="h-2 min-w-2 px-0"+ iconClassName="size-3 shrink-0 grayscale opacity-60"+ />+ <div className="min-w-0 truncate text-foreground/75">+ {showInstanceBadge && providerEntry+ ? `${modelLabel} · ${providerEntry.displayName}`+ : modelLabel}+ </div>+ </div>+ ) : null}+ {previousProviderNames.length > 0 ? (+ <div className="flex min-w-0 items-center gap-2">+ <ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" />+ <div className="min-w-0 truncate text-foreground/75">+ Handed off from {previousProviderNames.join(", ")}+ </div>+ </div>+ ) : null}+ {terminalStatus ? (+ <div className="flex min-w-0 items-center gap-2">+ <TerminalIcon+ aria-hidden+ className={cn("size-3 shrink-0", terminalStatus.colorClass)}+ />+ <div className="min-w-0 truncate text-foreground/75">+ {terminalProcessLabel(terminalProcessCount)}+ </div>+ </div>+ ) : null}+ {thread.runtime?.lastError ? (+ <div+ className={cn(+ "flex min-w-0 items-center gap-2",+ thread.runtime.lastErrorClass === "usage_limit" ? "text-warning" : "text-error",+ )}+ >+ <CircleAlertIcon className="size-3 shrink-0 stroke-current" />+ <div className="min-w-0 truncate">+ {thread.runtime.lastErrorClass === "usage_limit"+ ? "Usage limit reached"+ : "Error occurred"}+ </div>+ </div>+ ) : null}+ </ThreadHoverCard>+ </ThreadHoverCardPopup>+ );+}++function SnoozeMenuButton(props: {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ onSnooze: (preset: Pick<SnoozePreset, "snoozedUntil">) => void;+ timestampFormat: TimestampFormat;+}) {+ const { open, onOpenChange, onSnooze, timestampFormat } = props;+ const presets = open ? resolveSnoozePresets(new Date(), timestampFormat) : [];+ return (+ <Menu open={open} onOpenChange={onOpenChange}>+ <Tooltip>+ <TooltipTrigger+ render={+ <MenuTrigger+ render={+ <button+ type="button"+ aria-label="Snooze thread"+ onClick={(event) => event.stopPropagation()}+ onDoubleClick={(event) => event.stopPropagation()}+ 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"+ />+ }+ />+ }+ >+ <ClockIcon className="size-3" />+ </TooltipTrigger>+ <TooltipPopup>Snooze thread</TooltipPopup>+ </Tooltip>+ <MenuPopup side="bottom" align="end">+ {presets.map((preset) => (+ <MenuItem+ key={preset.id}+ onClick={(event) => {+ event.stopPropagation();+ onSnooze(preset);+ }}+ >+ {preset.label}+ <MenuShortcut>{preset.whenLabel}</MenuShortcut>+ </MenuItem>+ ))}+ <MenuSeparator />+ <MenuItem+ onClick={async (event) => {+ event.stopPropagation();+ const choice = await requestCustomSnooze();+ if (choice) onSnooze(choice);+ }}+ >+ Custom…+ </MenuItem>+ </MenuPopup>+ </Menu>+ );+}++type SortableThreadRowBag = Pick<+ ReturnType<typeof useSortable>,+ "listeners" | "setNodeRef" | "transform" | "transition" | "isDragging"+>;++export const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8";+export const draftPenClassName = "size-3 shrink-0 text-warning-foreground";++// useSortable memoizes on its `disabled` object, so a fresh one per render+// re-renders every row and marker on each sidebar update.+export const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const;+const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const;++// Takes the row's props rather than a render function: a closure from the+// sidebar body is new on every sidebar render, which rebuilt the bag and+// re-rendered every memoized row with it.+export function SortableThreadRow(+ props: Omit<SidebarThreadRowProps, "sortable"> & {+ sortableId: string;+ sortableDisabled: boolean;+ contextDrag: boolean;+ },+) {+ const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props;+ const canOperateThread = useEnvironmentScope(+ rowProps.thread.environmentId,+ AuthOrchestrationOperateScope,+ );+ const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({+ id: sortableId,+ disabled:+ sortableDisabled || !canOperateThread+ ? SIDEBAR_SORTABLE_DRAG_DISABLED+ : SIDEBAR_SORTABLE_DRAG_ENABLED,+ animateLayoutChanges: animateSidebarLayoutChanges,+ });+ // dnd-kit memoizes each field but not the bag, so the memoized row would+ // rerender on every shell update without this.+ const bag = {+ listeners,+ setNodeRef,+ transform: contextDrag ? null : transform,+ transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,+ isDragging: isDragging && !contextDrag,+ };+ // Keyed by variant so a card/slim switch remounts the row.+ return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;+}+export type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";+const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {+ pin: (+ <>+ <PinIcon aria-hidden className="size-3" />+ Pin+ </>+ ),+ unpin: (+ <>+ <PinOffIcon aria-hidden className="size-3" />+ Unpin+ </>+ ),+ settle: (+ <>+ <CircleCheckIcon aria-hidden className="size-3" />+ Settle+ </>+ ),+ unsettle: (+ <>+ <Undo2Icon aria-hidden className="size-3" />+ Un-settle+ </>+ ),+ wake: (+ <>+ <AlarmClockOffIcon aria-hidden className="size-3" />+ Wake+ </>+ ),+};++type SidebarThreadRowProps = {+ thread: SidebarThreadSummary;+ variant: "card" | "slim";+ variantAction: SidebarSweepAction;+ settlementSupported: boolean;+ snoozeSupported: boolean;+ pinningSupported: boolean;+ isPinned: boolean;+ sortable?: SortableThreadRowBag | undefined;+ dropVerb: SidebarDropVerb | null;+ dragOverPinned: boolean;+ sweepAction: SidebarSweepAction | null;+ snoozeWakeLabelText: string | null;+ wokeAt: string | null;+ isActive: boolean;+ // Unlike isActive, never true for the ancestor standing in for an open+ // subagent: drafts and PR clicks care about which composer is on screen.+ isRouteThread: boolean;+ openPullRequestsInRightPanel: boolean;+ jumpLabel: string | null;+ currentEnvironmentId: string | null;+ environmentLabel: string | null;+ environmentMachine: EnvironmentMachineKind;+ scratchMachineLabel: string | null;+ project: EnvironmentProject | null;+ projectDisplayName: string | null;+ providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;+ timestampFormat: TimestampFormat;+ onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void;+ onThreadActivate: (threadRef: ScopedThreadRef) => void;+ onStartRename: (threadRef: ScopedThreadRef, title: string) => void;+ onRenameTitleChange: (title: string) => void;+ onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void;+ onCancelRename: () => void;+ isRenaming: boolean;+ renamingTitle: string;+ onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;+ onSettle: (threadRef: ScopedThreadRef) => void;+ onActionSweepStart: (+ threadRef: ScopedThreadRef,+ action: SidebarSweepAction,+ event: PointerEvent,+ ) => void;+ onUnsettle: (threadRef: ScopedThreadRef) => void;+ onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void;+ onUnsnooze: (threadRef: ScopedThreadRef) => void;+ onUnpin: (threadRef: ScopedThreadRef) => void;+ onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;+ onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined;+};++const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {+ const {+ isRenaming,+ onCancelRename,+ onCommitRename,+ onContextMenu,+ onAcknowledgeWoke,+ onFileDropThreads,+ onRenameTitleChange,+ onSettle,+ onActionSweepStart,+ onSnooze,+ onStartRename,+ onThreadActivate,+ onThreadClick,+ onUnsettle,+ onUnsnooze,+ onUnpin,+ openPullRequestsInRightPanel,+ renamingTitle,+ thread,+ variant,+ variantAction,+ } = props;+ const threadRef = scopeThreadRef(thread.environmentId, thread.id);+ const threadKey = scopedThreadKey(threadRef);+ const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);+ useEffect(() => {+ if (!canOperateThread && isRenaming) onCancelRename();+ }, [canOperateThread, isRenaming, onCancelRename]);+ const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(props.isActive);+ const isRegeneratingTitle = thread.titleRegeneration != null;+ const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);+ const lastVisitedAt = resolveThreadLastVisitedAt(thread.lastVisitedAt, localLastVisitedAt);+ const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));+ const openPrLink = useOpenPrLink();+ const runningTerminalIds = useThreadRunningTerminalIds({+ environmentId: thread.environmentId,+ threadId: thread.id,+ });+ const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);+ const terminalProcessCount = runningTerminalIds.length;+ const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread;+ const handleDiscardDraftClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ discardComposerDraft(threadRef);+ };++ const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;+ const linkedPullRequestStatus = useLinkedThreadPullRequest(+ thread.environmentId,+ thread.linkedPullRequest,+ leaseLiveStatus,+ thread.pullRequests,+ thread.branchPullRequest,+ );+ const gitStatus = useEnvironmentQuery(+ leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null+ ? vcsEnvironment.status({+ environmentId: thread.environmentId,+ input: { cwd: gitCwd, includeRemote: false },+ })+ : null,+ );+ const visibleGitStatus = useRetainedValue(+ JSON.stringify([thread.environmentId, gitCwd]),+ gitStatus.data,+ );+ const pr = linkedPullRequestStatus?.pr ?? null;+ const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);+ const currentLinkedPr = supportsMultiplePullRequests+ ? resolveThreadCurrentPullRequestLink(thread.pullRequests)+ : null;++ const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });+ const status = resolveSidebarThreadStatus(thread);+ const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt);+ const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt);+ const isWoke =+ wokeAtDate !== null &&+ (lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&+ thread.settledOverride !== "settled";+ const shouldRecede = shouldRecedeSidebarThread({+ status,+ isUnread,+ isWoke,+ isActive: props.isActive,+ isSelected,+ });+ const topStatus =+ status === "working"+ ? {+ label: thread.goal?.status === "active" ? "Goal" : "Working",+ icon: "working" as const,+ className: "text-info",+ }+ : status === "waiting"+ ? {+ label: "Waiting",+ icon: "waiting" as const,+ className: "text-muted-foreground",+ }+ : status === "approval"+ ? {+ label: "Approval",+ icon: "approval" as const,+ className: "text-warning-foreground",+ }+ : status === "input"+ ? {+ label: "Input",+ icon: "input" as const,+ className: "text-indigo-600 dark:text-indigo-300",+ }+ : status === "limited"+ ? {+ label: "Limited",+ icon: "failed" as const,+ className: "text-warning",+ }+ : status === "failed"+ ? {+ label: "Failed",+ icon: "failed" as const,+ className: "text-error",+ }+ : isWoke+ ? {+ label: "Woke",+ icon: "woke" as const,+ className: "text-warning",+ }+ : isUnread+ ? {+ label: "Done",+ icon: "done" as const,+ className: "text-success",+ }+ : null;+ const isWokeStatus = topStatus?.icon === "woke";++ const branchMismatch = resolveLocalCheckoutBranchMismatch({+ effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",+ activeWorktreePath: thread.worktreePath,+ activeThreadBranch: thread.branch,+ currentGitBranch: visibleGitStatus?.refName ?? null,+ });+ const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider);++ const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;+ const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;+ const showInstanceBadge =+ providerEntry !== null &&+ shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());+ const selectedModel = providerEntry?.models.find(+ (model) => model.slug === thread.modelSelection.model,+ );+ const modelLabel = selectedModel+ ? getTriggerDisplayModelLabel(selectedModel)+ : thread.modelSelection.model;++ const isRemote = thread.environmentId !== props.currentEnvironmentId;+ const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;++ const detailsTooltip = (+ <SidebarThreadTooltip+ thread={thread}+ project={props.project}+ projectDisplayName={props.projectDisplayName}+ environmentLabel={props.environmentLabel}+ environmentMachine={props.environmentMachine}+ providerEntry={providerEntry}+ providerEntryByInstanceId={props.providerEntryByInstanceId}+ showInstanceBadge={showInstanceBadge}+ modelInstanceId={modelInstanceId}+ modelLabel={modelLabel}+ branchMismatch={branchMismatch}+ terminalStatus={terminalStatus}+ terminalProcessCount={terminalProcessCount}+ />+ );++ const handleClick = (event: ReactMouseEvent) => {+ onThreadClick(event, threadRef);+ };+ const handleAcknowledgeWokeClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ if (props.wokeAt === null) return;+ onAcknowledgeWoke(threadRef, props.wokeAt);+ };+ const handleContextMenu = (event: ReactMouseEvent) => {+ event.preventDefault();+ onContextMenu(threadRef, { x: event.clientX, y: event.clientY });+ };+ const handleKeyDown = (event: ReactKeyboardEvent) => {+ if (event.target !== event.currentTarget) return;+ if (event.key !== "Enter" && event.key !== " ") return;+ event.preventDefault();+ onThreadActivate(threadRef);+ };+ const handleDoubleClick = (event: ReactMouseEvent) => {+ if (+ !readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) ||+ isRenaming ||+ event.metaKey ||+ event.ctrlKey ||+ event.shiftKey ||+ event.altKey+ ) {+ return;+ }+ if ((event.target as HTMLElement).closest("button, a, input")) return;+ event.preventDefault();+ onStartRename(threadRef, thread.title);+ };+ const [isFileDragOver, setIsFileDragOver] = useState(false);+ const fileDropHandlers = onFileDropThreads+ ? makeWorkspaceFileDropHandlers({+ setDragActive: setIsFileDragOver,+ addFiles: (files) => {+ onFileDropThreads(threadRef, files);+ },+ addFolders: () => {},+ })+ : null;+ useEffect(() => {+ if (!isFileDragOver) return;+ const clearFileDrag = () => setIsFileDragOver(false);+ window.addEventListener("dragend", clearFileDrag);+ return () => window.removeEventListener("dragend", clearFileDrag);+ }, [isFileDragOver]);+ const renameCommittedRef = useRef(false);+ useEffect(() => {+ if (isRenaming) renameCommittedRef.current = false;+ }, [isRenaming]);+ const handleRenameKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {+ event.stopPropagation();+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;+ if (event.key === "Enter") {+ event.preventDefault();+ renameCommittedRef.current = true;+ onCommitRename(threadRef, renamingTitle, thread.title);+ } else if (event.key === "Escape") {+ event.preventDefault();+ renameCommittedRef.current = true;+ onCancelRename();+ }+ };+ const handleRenameBlur = () => {+ if (!renameCommittedRef.current) {+ onCommitRename(threadRef, renamingTitle, thread.title);+ }+ };+ const handleSettleClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ onSettle(threadRef);+ };+ const handleActionPointerDown = (event: ReactPointerEvent) => {+ if (!event.isPrimary || event.button !== 0) return;+ event.stopPropagation();+ onActionSweepStart(threadRef, variantAction, event.nativeEvent);+ };+ const handleUnsettleClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ onUnsettle(threadRef);+ };+ const handleUnsnoozeClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ onUnsnooze(threadRef);+ };+ const handleUnpinClick = (event: ReactMouseEvent) => {+ event.preventDefault();+ event.stopPropagation();+ onUnpin(threadRef);+ };+ const handleSnoozePreset = (preset: Pick<SnoozePreset, "snoozedUntil">) => {+ onSnooze(threadRef, preset);+ };+ const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false);+ // The React Compiler caches render results on their inputs, so a clock read+ // here would stay frozen until `thread` changes and a queued-turn gate would+ // never reopen. The gate's clock is state, reset with the thread.+ const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({+ thread,+ now: new Date().toISOString(),+ }));+ if (snoozeGateClock.thread !== thread) {+ setSnoozeGateClock({ thread, now: new Date().toISOString() });+ }+ const snoozeGateNow = snoozeGateClock.now;+ const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow })+ ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS+ : Number.NaN;+ useEffect(() => {+ // A gate still closed past its expiry is held by runtime status, not time,+ // so no clock tick can open it.+ if (!Number.isFinite(snoozeGateExpiryMs) || snoozeGateExpiryMs <= Date.parse(snoozeGateNow)) {+ return;+ }+ const id = window.setTimeout(+ () => setSnoozeGateClock({ thread, now: new Date().toISOString() }),+ Math.min(Math.max(0, snoozeGateExpiryMs - Date.now()) + 50, 2_147_483_647),+ );+ return () => window.clearTimeout(id);+ }, [snoozeGateExpiryMs, snoozeGateNow, thread]);+ const showSnoozeButton =+ canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow });+ // Closing here, not just masking, keeps the menu from reopening when the button returns.+ if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false);+ const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton;+ const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {+ const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;+ if (!url) return;+ const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;+ const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);+ if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {+ onThreadActivate(threadRef);+ }+ };++ const rowSurfaceClassName = cn(+ "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",+ variantAction === "unsettle" && "[&:not(:hover):not(:focus-within)_*]:text-secondary-label/70",+ props.isActive+ ? "bg-sidebar-row-active text-sidebar-foreground"+ : isSelected || props.sweepAction !== null+ ? "bg-sidebar-row-selected text-sidebar-foreground"+ : hasUnsentDraft+ ? cn(draftSurfaceClassName, "text-sidebar-foreground")+ : shouldRecede+ ? "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"+ : "bg-transparent text-sidebar-foreground hover:bg-sidebar-row-hover",+ shouldRecede &&+ status === "working" &&+ "opacity-70 transition-opacity hover:opacity-100 focus-within:opacity-100 motion-reduce:transition-none",+ isFileDragOver && "ring-1 ring-inset ring-primary/70",+ isFileDragOver && !props.isActive && !isSelected && "bg-sidebar-row-hover",+ props.sortable?.isDragging &&+ "bg-sidebar bg-linear-to-b from-sidebar-row-active to-sidebar-row-active text-sidebar-foreground opacity-100 shadow-lg",+ );+ const sortable = props.sortable;+ const sortableRootProps = sortable+ ? {+ ref: sortable.setNodeRef,+ style: {+ transform: CSS.Translate.toString(sortable.transform),+ transition: sortable.transition,+ // A zero-height boundary also makes dnd-kit scale the source to+ // zero. Only projected peers use scaleY as a visibility sentinel.+ visibility:+ !sortable.isDragging && sortable.transform?.scaleY === 0+ ? ("hidden" as const)+ : undefined,+ },+ ...sortable.listeners,+ }+ : {};+ const destinationVerb = sortable?.isDragging+ ? props.dropVerb+ : props.sweepAction === "unsnooze"+ ? "wake"+ : props.sweepAction;+ const dragDestination =+ destinationVerb !== null ? (+ <span+ role="status"+ 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"+ >+ {dropVerbBadge[destinationVerb]}+ </span>+ ) : null;++ const accessibility = resolveSidebarRowAccessibility({+ title: thread.title,+ statusLabel: topStatus?.label ?? null,+ projectDisplayName: props.projectDisplayName,+ isActive: props.isActive,+ });++ const title =+ isRenaming && canOperateThread ? (+ <input+ autoFocus+ value={renamingTitle}+ aria-label="Thread title"+ onChange={(event) => onRenameTitleChange(event.target.value)}+ onFocus={(event) => event.currentTarget.select()}+ onKeyDown={handleRenameKeyDown}+ onBlur={handleRenameBlur}+ onClick={(event) => event.stopPropagation()}+ onDoubleClick={(event) => event.stopPropagation()}+ 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"+ />+ ) : (+ <span+ aria-hidden+ className={cn(+ "min-w-0 flex-1 text-sm transition-opacity motion-reduce:transition-none",+ shouldRecede ? "font-normal" : "font-medium",+ variant === "card"+ ? cn(+ "truncate",+ shouldRecede+ ? "text-secondary-label"+ : isUnread || isWoke || status === "input"+ ? "text-foreground"+ : status === "failed"+ ? "text-foreground/95"+ : "text-foreground/90",+ )+ : cn(+ "truncate group-focus-within/sidebar-row:text-foreground group-hover/sidebar-row:text-foreground",+ shouldRecede+ ? "text-secondary-label/70"+ : props.isActive || isWoke || status === "input"+ ? "text-foreground"+ : isUnread+ ? "text-muted-foreground"+ : "text-secondary-label/70",+ ),+ isRegeneratingTitle && "opacity-55",+ )}+ >+ {thread.title}+ </span>+ );+ const accessibleTitle = isRenaming ? null : <span className="sr-only">{thread.title}</span>;++ const prBadgeShape = supportsMultiplePullRequests+ ? resolveThreadPullRequestBadge(thread.pullRequests)+ : null;+ const handlePrListClick = () => {+ useRightPanelStore.getState().open(threadRef, "pull-requests");+ if (!props.isRouteThread) onThreadActivate(threadRef);+ };+ const prBadge =+ prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? (+ <ThreadPullRequestBadgeControl+ render={<InlineButton />}+ badge={prBadgeShape}+ pullRequests={thread.pullRequests}+ number={pr?.number ?? currentLinkedPr?.number}+ url={pr?.url ?? currentLinkedPr?.url}+ status={prStatus}+ onOpenList={handlePrListClick}+ onOpenPullRequest={handlePrClick}+ />+ ) : null;+ const terminalStatusIcon = (+ <ThreadTerminalStatusButton+ threadRef={threadRef}+ terminalIds={runningTerminalIds}+ onThreadActivate={onThreadActivate}+ />+ );+ const draftIndicator = hasUnsentDraft ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <span+ role="img"+ aria-label="Unsent draft"+ data-testid={`sidebar-draft-indicator-${thread.id}`}+ className="inline-flex shrink-0 items-center"+ />+ }+ >+ <SquarePenIcon aria-hidden className={draftPenClassName} />+ </TooltipTrigger>+ <TooltipPopup side="top">Unsent draft</TooltipPopup>+ </Tooltip>+ ) : null;+ const showPin =+ props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null));+ const pinIndicator = showPin ? (+ props.pinningSupported && canOperateThread && !sortable?.isDragging ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Unpin thread"+ onClick={handleUnpinClick}+ 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"+ />+ }+ >+ <PinIcon+ aria-hidden+ className="size-3 shrink-0 group-hover/unpin:hidden group-focus-visible/unpin:hidden"+ />+ <PinOffIcon+ aria-hidden+ className="hidden size-3 shrink-0 group-hover/unpin:block group-focus-visible/unpin:block"+ />+ </TooltipTrigger>+ <TooltipPopup>Unpin thread</TooltipPopup>+ </Tooltip>+ ) : (+ <PinIcon+ aria-label="Pinned"+ role="img"+ className="size-3 shrink-0 text-muted-foreground/65"+ />+ )+ ) : null;++ if (variant === "slim") {+ return (+ <li+ data-thread-item={threadKey}+ {...sortableRootProps}+ {...(fileDropHandlers ?? {})}+ className={cn(+ "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]",+ sortable?.isDragging && "relative z-20",+ )}+ >+ <Tooltip disabled={sortable?.isDragging}>+ <TooltipTrigger+ render={+ <div+ ref={rowRef}+ role="button"+ tabIndex={0}+ aria-label={accessibility.label}+ aria-current={accessibility.current}+ data-testid="sidebar-row-slim"+ aria-busy={isRegeneratingTitle || undefined}+ className={cn(rowSurfaceClassName, "flex h-9 items-center gap-2.5 px-2.5")}+ onClick={handleClick}+ onDoubleClick={handleDoubleClick}+ onKeyDown={handleKeyDown}+ onContextMenu={handleContextMenu}+ />+ }+ >+ {accessibleTitle}+ <span+ className={cn(+ "flex shrink-0 items-center transition-opacity",+ (!props.isActive || variantAction === "unsettle") &&+ "opacity-40 grayscale group-focus-within/sidebar-row:opacity-100 group-focus-within/sidebar-row:grayscale-0 group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",+ )}+ >+ {props.project ? <ProjectFavicon project={props.project} className="size-4" /> : null}+ </span>+ {draftIndicator}+ {title}+ {pinIndicator}+ {terminalStatusIcon}+ {isRegeneratingTitle ? (+ <span role="status" className="sr-only">+ Regenerating title+ </span>+ ) : null}+ {prBadge}+ {sortable?.isDragging ? (+ dragDestination+ ) : (+ <span+ className={cn(+ "relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end",+ props.sweepAction !== null && "hidden",+ )}+ >+ <span+ className={cn(+ "inline-flex justify-end tabular-nums text-secondary-label transition-opacity",+ !isWoke && "group-any-hover/sidebar-row:opacity-0",+ )}+ >+ {variantAction === "unsnooze" && props.snoozeWakeLabelText !== null ? (+ <span className="text-xs text-info-foreground tabular-nums">+ {props.snoozeWakeLabelText}+ </span>+ ) : isWoke ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Dismiss Woke notification"+ onClick={handleAcknowledgeWokeClick}+ 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"+ >+ <AlarmClockIcon aria-hidden className="size-3" />+ <span role="status">Woke</span>+ </button>+ }+ />+ <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>+ </Tooltip>+ ) : (+ <span className="text-xs">+ <RelativeTimeLabel+ timestamp={+ variantAction === "unsettle"+ ? resolveSettledThreadTimestamp(thread)+ : threadTimeTimestamp(thread)+ }+ />+ </span>+ )}+ </span>+ {variantAction === "unsnooze" ? (+ !props.snoozeSupported ? null : (+ <button+ type="button"+ aria-label="Wake thread now"+ onClick={handleUnsnoozeClick}+ onPointerDown={handleActionPointerDown}+ className={cn(+ "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",+ isWoke && "group-any-hover/sidebar-row:static",+ )}+ >+ <AlarmClockOffIcon className="mb-px size-3" />+ </button>+ )+ ) : !props.settlementSupported ? null : variantAction === "unsettle" ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Un-settle thread"+ onClick={handleUnsettleClick}+ onPointerDown={handleActionPointerDown}+ className={cn(+ "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",+ isWoke && "group-any-hover/sidebar-row:static",+ )}+ />+ }+ >+ <Undo2Icon className="mb-px size-3.5" />+ </TooltipTrigger>+ <TooltipPopup side="top">Un-settle thread</TooltipPopup>+ </Tooltip>+ ) : (+ <button+ type="button"+ aria-label="Settle thread"+ onClick={handleSettleClick}+ onPointerDown={handleActionPointerDown}+ className={cn(+ "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",+ isWoke && "group-any-hover/sidebar-row:static",+ )}+ >+ <CheckIcon className="size-3" />+ </button>+ )}+ </span>+ )}+ {props.sweepAction !== null ? dragDestination : null}+ {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}+ </TooltipTrigger>+ {detailsTooltip}+ </Tooltip>+ </li>+ );+ }++ const diff = latestRunDiff(thread);++ return (+ <li+ data-thread-item={threadKey}+ {...sortableRootProps}+ {...(fileDropHandlers ?? {})}+ className={cn(+ "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",+ sortable?.isDragging && "relative z-20",+ )}+ >+ <Tooltip disabled={snoozeMenuOpen || sortable?.isDragging}>+ <TooltipTrigger+ render={+ <div+ ref={rowRef}+ role="button"+ tabIndex={0}+ aria-label={accessibility.label}+ aria-current={accessibility.current}+ data-testid="sidebar-row-card"+ aria-busy={isRegeneratingTitle || undefined}+ className={rowSurfaceClassName}+ onClick={handleClick}+ onDoubleClick={handleDoubleClick}+ onKeyDown={handleKeyDown}+ onContextMenu={handleContextMenu}+ />+ }+ >+ {accessibleTitle}+ <div className="relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)">+ <div className="flex h-5 min-w-0 items-center gap-1.5">+ {draftIndicator}+ {props.project ? (+ <ProjectFavicon project={props.project} className="size-4 shrink-0" />+ ) : null}+ {/* Left of the status slot, the pin would slide when hover swaps the+ label for the wider row controls. */}+ {pinIndicator}+ {props.projectDisplayName ? (+ <span+ className={cn(+ "min-w-0 flex-1 truncate text-secondary-label text-xs",+ shouldRecede ? "font-normal" : "font-medium",+ )}+ >+ {props.projectDisplayName}+ </span>+ ) : (+ <span className="flex-1" />+ )}+ {sortable?.isDragging ? (+ dragDestination+ ) : (+ <span+ className={cn(+ "group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs",+ props.sweepAction !== null && "hidden",+ )}+ >+ <span+ className={cn(+ isWokeStatus+ ? "pointer-events-auto"+ : "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",+ "flex items-center self-center justify-self-end tabular-nums text-secondary-label transition-opacity",+ snoozeMenuOpen && "pointer-events-none absolute right-0 opacity-0",+ )}+ >+ {topStatus ? (+ isWokeStatus ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Dismiss Woke notification"+ onClick={handleAcknowledgeWokeClick}+ className={cn(+ "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",+ topStatus.className,+ )}+ >+ <AlarmClockIcon aria-hidden className="size-4 shrink-0" />+ <span role="status">{topStatus.label}</span>+ </button>+ }+ />+ <TooltipPopup side="top">Dismiss Woke notification</TooltipPopup>+ </Tooltip>+ ) : (+ <span+ className={cn(+ "inline-flex items-center gap-1 font-medium",+ topStatus.className,+ )}+ >+ {topStatus.icon === "working" ? (+ <CircleDashedIcon aria-hidden className="size-4 shrink-0" />+ ) : topStatus.icon === "waiting" ? (+ <CircleDotDashedIcon aria-hidden className="size-4 shrink-0" />+ ) : topStatus.icon === "input" ? (+ <MessageCircleQuestionIcon aria-hidden className="size-4 shrink-0" />+ ) : topStatus.icon === "approval" ? (+ <ShieldQuestionIcon aria-hidden className="size-4 shrink-0" />+ ) : topStatus.icon === "failed" ? (+ <CircleAlertIcon aria-hidden className="size-4 shrink-0" />+ ) : topStatus.icon === "done" ? (+ <CircleCheckIcon aria-hidden className="size-4 shrink-0" />+ ) : null}+ {/* The label alone is the live region: a role="status"+ wrapper around the ticking duration would make+ screen readers announce every second. */}+ <span role="status">{topStatus.label}</span>+ {status === "working" ? (+ <span aria-hidden>+ <WorkingDuration startedAt={resolveWorkingStartedAt(thread)} />+ </span>+ ) : status === "waiting" ? (+ <span aria-hidden>+ <WorkingDuration startedAt={thread.latestRun?.completedAt ?? null} />+ </span>+ ) : null}+ </span>+ )+ ) : (+ <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />+ )}+ </span>+ {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? (+ <span+ className={cn(+ // focus-visible, not focus-within: a mouse click leaves+ // the Settle button focused, and a plain focus-within+ // would keep the controls pinned over the status label+ // once the pointer moves away (e.g. after a failed+ // settle) instead of cross-fading back.+ "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",+ snoozeMenuOpen && "pointer-events-auto static opacity-100",+ )}+ >+ {hasUnsentDraft ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Discard draft"+ onClick={handleDiscardDraftClick}+ className="inline-flex cursor-pointer items-center rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground"+ />+ }+ >+ <XIcon className="size-3.5" />+ </TooltipTrigger>+ <TooltipPopup side="top">Discard draft</TooltipPopup>+ </Tooltip>+ ) : null}+ {showSnoozeButton ? (+ <SnoozeMenuButton+ open={snoozeMenuOpen}+ onOpenChange={setSnoozeMenuOpen}+ onSnooze={handleSnoozePreset}+ timestampFormat={props.timestampFormat}+ />+ ) : null}+ {props.settlementSupported ? (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Settle thread"+ onClick={handleSettleClick}+ onPointerDown={handleActionPointerDown}+ 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"+ />+ }+ >+ <CheckIcon className="size-3.5" />+ Settle+ </TooltipTrigger>+ <TooltipPopup>Settle thread</TooltipPopup>+ </Tooltip>+ ) : null}+ </span>+ ) : null}+ </span>+ )}+ {props.sweepAction !== null ? dragDestination : null}+ </div>+ <div className="mt-1 flex min-w-0">+ {title}+ {isRegeneratingTitle ? (+ <span role="status" className="sr-only">+ Regenerating title+ </span>+ ) : null}+ </div>+ <div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">+ {thread.branch ? (+ <>+ <ThreadWorktreeIndicator thread={thread} />+ <span className="flex min-w-0 flex-1 text-muted-foreground/40">+ <MiddleTruncate value={thread.branch} showTitle={false} />+ </span>+ </>+ ) : showsScratchMachine ? (+ <>+ <EnvironmentMachineIcon+ aria-hidden+ kind={props.environmentMachine}+ className="size-3 shrink-0 text-muted-foreground/40"+ />+ <span className="min-w-0 flex-1 truncate text-muted-foreground/40">+ {props.scratchMachineLabel}+ </span>+ </>+ ) : (+ <span className="flex-1" />+ )}+ {terminalStatusIcon}+ {prBadge}+ {diff ? (+ <span className="shrink-0 font-mono">+ <span className="text-diff-addition-foreground">+ +{formatDiffCount(diff.insertions)}+ </span>{" "}+ <span className="text-diff-deletion-foreground">+ −{formatDiffCount(diff.deletions)}+ </span>+ </span>+ ) : null}+ <span+ aria-hidden+ className="pointer-events-none ml-auto inline-flex shrink-0 items-center gap-1"+ >+ {isRemote && !showsScratchMachine ? (+ <span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70">+ <EnvironmentMachineIcon+ aria-hidden+ kind={props.environmentMachine}+ className="size-3.5"+ />+ </span>+ ) : null}+ <SidebarProviderStack+ thread={thread}+ providerEntryByInstanceId={props.providerEntryByInstanceId}+ />+ </span>+ </div>+ </div>+ {props.jumpLabel ? <JumpHintBadge label={props.jumpLabel} /> : null}+ </TooltipTrigger>+ {detailsTooltip}+ </Tooltip>+ </li>+ );+});++function latestRunDiff(+ thread: SidebarThreadSummary,+): { insertions: number; deletions: number } | null {+ void thread;+ return null;+}++export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {+ isSettled: boolean;+ thread: SidebarThreadSummary;+ project: EnvironmentProject | null;+ projectDisplayName: string | null;+ environmentLabel: string | null;+ environmentMachine: EnvironmentMachineKind;+ providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>;+ isHighlighted: boolean;+ isRouteActive: boolean;+ resultId: string;+ searchMatch: EnvironmentThreadSearchMatch | null;+ searchQuery: string;+ onHighlight: () => void;+ onSelect: () => void;+ onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;+}) {+ const { thread } = props;+ const accessibility = resolveSidebarRowAccessibility({+ title: thread.title,+ statusLabel: null,+ projectDisplayName: props.projectDisplayName,+ isActive: props.isRouteActive,+ });+ const threadRef = scopeThreadRef(thread.environmentId, thread.id);+ const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(+ props.isHighlighted || props.isRouteActive,+ );+ const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;+ const gitStatus = useEnvironmentQuery(+ leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null+ ? vcsEnvironment.status({+ environmentId: thread.environmentId,+ input: { cwd: gitCwd, includeRemote: false },+ })+ : null,+ );+ const visibleGitStatus = useRetainedValue(+ JSON.stringify([thread.environmentId, gitCwd]),+ gitStatus.data,+ );+ const branchMismatch = resolveLocalCheckoutBranchMismatch({+ effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",+ activeWorktreePath: thread.worktreePath,+ activeThreadBranch: thread.branch,+ currentGitBranch: visibleGitStatus?.refName ?? null,+ });+ const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;+ const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;+ const showInstanceBadge =+ providerEntry !== null &&+ shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());+ const selectedModel = providerEntry?.models.find(+ (model) => model.slug === thread.modelSelection.model,+ );+ const modelLabel = selectedModel+ ? getTriggerDisplayModelLabel(selectedModel)+ : thread.modelSelection.model;+ const runningTerminalIds = useThreadRunningTerminalIds({+ environmentId: thread.environmentId,+ threadId: thread.id,+ });+ const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);+ const [isFileDragOver, setIsFileDragOver] = useState(false);+ const onFileDropThreads = props.onFileDropThreads;+ const fileDropHandlers = makeWorkspaceFileDropHandlers({+ setDragActive: setIsFileDragOver,+ addFiles: (files) => {+ onFileDropThreads(threadRef, files);+ },+ addFolders: () => {},+ });+ useEffect(() => {+ if (!isFileDragOver) return;+ const clearFileDrag = () => setIsFileDragOver(false);+ window.addEventListener("dragend", clearFileDrag);+ return () => window.removeEventListener("dragend", clearFileDrag);+ }, [isFileDragOver]);+ return (+ <li role="presentation" className="list-none" {...fileDropHandlers}>+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ ref={rowRef}+ id={props.resultId}+ data-search-result-key={scopedThreadKey(threadRef)}+ type="button"+ role="option"+ tabIndex={-1}+ aria-selected={props.isHighlighted}+ aria-current={accessibility.current}+ aria-describedby={`${props.resultId}-pr`}+ aria-label={accessibility.label}+ onMouseMove={props.onHighlight}+ onClick={props.onSelect}+ className={cn(+ "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",+ props.isHighlighted || props.isRouteActive+ ? "bg-sidebar-row-active text-sidebar-foreground"+ : "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground",+ isFileDragOver && "ring-1 ring-inset ring-primary/70",+ isFileDragOver && !props.isRouteActive && "bg-sidebar-row-hover",+ )}+ />+ }+ >+ {props.project ? (+ <ProjectFavicon+ project={props.project}+ className={cn(+ "size-4 shrink-0 transition-opacity",+ props.isSettled &&+ !props.isRouteActive &&+ !props.isHighlighted &&+ "opacity-40 grayscale group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0",+ )}+ />+ ) : null}+ <span className="flex min-w-0 flex-1 flex-col">+ <span className="flex min-w-0 items-center gap-2.5">+ <span+ className={cn(+ "min-w-0 flex-1 truncate",+ props.isSettled+ ? "font-normal text-secondary-label/70 group-hover/sidebar-row:text-foreground"+ : "font-medium text-foreground",+ (props.isHighlighted || props.isRouteActive) && "text-foreground",+ thread.titleRegeneration != null && "opacity-55",+ )}+ >+ {thread.title}+ </span>+ <span id={`${props.resultId}-pr`} className="contents">+ <ThreadSearchPullRequestNumber+ thread={thread}+ query={props.searchQuery}+ enabled={leaseLiveStatus}+ settled={props.isSettled}+ />+ </span>+ <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums">+ <RelativeTimeLabel timestamp={threadTimeTimestamp(thread)} />+ </span>+ </span>+ {props.searchMatch ? (+ <ThreadSearchMatchExcerpt+ match={{+ source: props.searchMatch.source,+ snippet: props.searchMatch.snippet,+ query: props.searchQuery,+ }}+ />+ ) : null}+ </span>+ </TooltipTrigger>+ <SidebarThreadTooltip+ thread={thread}+ project={props.project}+ projectDisplayName={props.projectDisplayName}+ environmentLabel={props.environmentLabel}+ environmentMachine={props.environmentMachine}+ providerEntry={providerEntry}+ providerEntryByInstanceId={props.providerEntryByInstanceId}+ showInstanceBadge={showInstanceBadge}+ modelInstanceId={modelInstanceId}+ modelLabel={modelLabel}+ branchMismatch={branchMismatch}+ terminalStatus={terminalStatus}+ terminalProcessCount={runningTerminalIds.length}+ />+ </Tooltip>+ </li>+ );+});