The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAtomMount } from "@effect/atom-react"; |
| 2 | import { asLaunchingThread } from "@t3tools/client-runtime/state/thread-inbox"; |
| 3 | import { ThreadHoverCard, ThreadHoverCardPopup } from "../ThreadHoverCard"; |
| 4 | import { ThreadTerminalStatusButton } from "../ThreadStatusIndicators"; |
| 5 | import { discardComposerDraft } from "../../lib/discardComposerDraft"; |
| 6 | import { contextMenuSourceOf } from "../../contextMenuSource"; |
| 7 | import { requestCustomSnooze } from "../CustomSnoozeDialog"; |
| 8 | import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests"; |
| 9 | import { useDeadlinePassed } from "~/hooks/useDeadline"; |
| 10 | import { resolveThreadCurrentPullRequestLink } from "@t3tools/client-runtime/thread-pull-requests"; |
| 11 | import { useDraggable } from "@dnd-kit/core"; |
| 12 | import { useSortable } from "@dnd-kit/sortable"; |
| 13 | import { CSS } from "@dnd-kit/utilities"; |
| 14 | import { |
| 15 | canSnooze, |
| 16 | hasQueuedTurnStart, |
| 17 | QUEUED_TURN_START_GRACE_MS, |
| 18 | } from "@t3tools/client-runtime/state/thread-settled"; |
| 19 | import { formatDiffCount } from "@t3tools/client-runtime/diff-count"; |
| 20 | import { |
| 21 | resolveSettledThreadTimestamp, |
| 22 | resolveThreadActivityTimestamp, |
| 23 | } from "@t3tools/client-runtime/state/thread-sort"; |
| 24 | import { type EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search"; |
| 25 | import { |
| 26 | formatWorkingDurationLabel, |
| 27 | resolveThreadProviderStack, |
| 28 | } from "@t3tools/client-runtime/state/models"; |
| 29 | import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment"; |
| 30 | import { toServerClock } from "@t3tools/client-runtime/clock"; |
| 31 | import { |
| 32 | AuthOrchestrationOperateScope, |
| 33 | type ContextMenuSource, |
| 34 | type EnvironmentId, |
| 35 | type EnvironmentMachineKind, |
| 36 | type ScopedThreadRef, |
| 37 | } from "@t3tools/contracts"; |
| 38 | |
| 39 | import type { TimestampFormat } from "@t3tools/contracts/settings"; |
| 40 | import { |
| 41 | AlarmClockIcon, |
| 42 | AlarmClockOffIcon, |
| 43 | ArrowRightLeftIcon, |
| 44 | CheckIcon, |
| 45 | CircleAlertIcon, |
| 46 | CircleCheckIcon, |
| 47 | CircleDashedIcon, |
| 48 | CircleDotDashedIcon, |
| 49 | ClockIcon, |
| 50 | GitBranchIcon, |
| 51 | MessageCircleQuestionIcon, |
| 52 | PinIcon, |
| 53 | PinOffIcon, |
| 54 | ShieldQuestionIcon, |
| 55 | SquarePenIcon, |
| 56 | TerminalIcon, |
| 57 | Undo2Icon, |
| 58 | UserRoundIcon, |
| 59 | XIcon, |
| 60 | } from "lucide-react"; |
| 61 | import { |
| 62 | memo, |
| 63 | useRef, |
| 64 | useState, |
| 65 | type KeyboardEvent as ReactKeyboardEvent, |
| 66 | type MouseEvent as ReactMouseEvent, |
| 67 | type PointerEvent as ReactPointerEvent, |
| 68 | type ReactNode, |
| 69 | } from "react"; |
| 70 | import { msg, T, useGT, useMessages, Var } from "gt-react"; |
| 71 | |
| 72 | import type { MessageResolver } from "../../i18n/messages"; |
| 73 | |
| 74 | import { useRightPanelStore } from "../../rightPanelStore"; |
| 75 | import { useOpenPrLink } from "../../lib/openPullRequestLink"; |
| 76 | import { useUiStateStore } from "../../uiStateStore"; |
| 77 | import { useThreadSelectionStore } from "../../threadSelectionStore"; |
| 78 | import { useNowMinute } from "../../hooks/useNowMinute"; |
| 79 | import { useNowSecond } from "../../hooks/useNowSecond"; |
| 80 | import { vcsEnvironment, vcsBranchRevalidation } from "../../state/vcs"; |
| 81 | import { useSidebarLinkedIssueState } from "../../state/issues"; |
| 82 | import { useEnvironmentQuery } from "../../state/query"; |
| 83 | import { readEnvironmentScope, useEnvironmentScope } from "../../state/session"; |
| 84 | import { formatRelativeTime, parseTimestampDate } from "../../timestampFormat"; |
| 85 | import type { SidebarThreadSummary } from "../../types"; |
| 86 | import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell"; |
| 87 | import { cn } from "~/lib/utils"; |
| 88 | import { textDirection } from "~/textDirection"; |
| 89 | import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; |
| 90 | import { |
| 91 | animateSidebarLayoutChanges, |
| 92 | hasUnseenCompletion, |
| 93 | resolveSidebarRowAccessibility, |
| 94 | type SidebarDropVerb, |
| 95 | resolveSidebarRowStatus, |
| 96 | resolveThreadLastVisitedAt, |
| 97 | shouldRecedeSidebarThread, |
| 98 | resolveWorkingStartedAt, |
| 99 | useRetainedValue, |
| 100 | withoutRemovedCheckout, |
| 101 | useSidebarRowSubscriptionLease, |
| 102 | setFileDragActive, |
| 103 | } from "../Sidebar.logic"; |
| 104 | import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic"; |
| 105 | import { |
| 106 | ThreadPullRequestBadgeControl, |
| 107 | ThreadPullRequestsMiniList, |
| 108 | ThreadWorktreeIndicator, |
| 109 | prStatusIndicator, |
| 110 | resolveThreadPullRequestBadge, |
| 111 | terminalStatusFromRunningIds, |
| 112 | type TerminalStatusIndicator, |
| 113 | useLinkedThreadPullRequest, |
| 114 | ThreadSearchPullRequestNumber, |
| 115 | } from "../ThreadStatusIndicators"; |
| 116 | import { pickSnoozePreset, resolveSnoozePresets, type SnoozePreset } from "../Sidebar.snooze"; |
| 117 | import { useThreadShell } from "../../state/entities"; |
| 118 | import { ProjectFavicon, type ProjectFaviconProject } from "../ProjectFavicon"; |
| 119 | import { ThreadSearchMatchExcerpt } from "../ThreadSearchMatch"; |
| 120 | import { makeWorkspaceFileDropHandlers } from "../chat/workspaceFileDrop"; |
| 121 | import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon"; |
| 122 | import { getTriggerDisplayModelName } from "../chat/providerIconUtils"; |
| 123 | import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances"; |
| 124 | import { useThreadRunningTerminalIds } from "../../state/terminalSessions"; |
| 125 | import { InlineButton } from "../ui/button"; |
| 126 | import { Kbd } from "../ui/kbd"; |
| 127 | import { Menu, MenuItem, MenuItemDetail, MenuPopup, MenuSeparator, MenuTrigger } from "../ui/menu"; |
| 128 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 129 | import { MiddleTruncate } from "../ui/middle-truncate"; |
| 130 | import { ActivityShimmerOverlay } from "../chat/TimelineRowParts"; |
| 131 | import { observeVisibleAnimation } from "~/lib/visibleAnimation"; |
| 132 | import { useThreadHasUnsentDraft } from "../../composerDraftStore"; |
| 133 | import { ThreadDetailsIssueRows } from "../chat/ThreadDetailsIssueRows"; |
| 134 | import { IssueGlyph, issueStatePresentation } from "../issue/issuePresentation"; |
| 135 | |
| 136 | // The fields thread rows show. Provider status pushes refresh `checkedAt`, |
| 137 | // status and auth on every provider; leaving those out keeps each |
| 138 | // environment's map, and every memoized row, stable across them. |
| 139 | export type SidebarProviderEntry = Pick< |
| 140 | ProviderInstanceEntry, |
| 141 | | "instanceId" |
| 142 | | "driverKind" |
| 143 | | "enabled" |
| 144 | | "displayName" |
| 145 | | "accentColor" |
| 146 | | "acpRegistryAgentId" |
| 147 | | "acpRegistryIconUrl" |
| 148 | | "models" |
| 149 | >; |
| 150 | function compactSidebarTimeLabel(timestamp: string, nowMs: number, resolve: MessageResolver) { |
| 151 | const parts = formatRelativeTime(timestamp, nowMs, resolve); |
| 152 | if (parts === null) return ""; |
| 153 | return parts.suffix === null ? resolve(msg("now", { $context: "relative time" })) : parts.value; |
| 154 | } |
| 155 | |
| 156 | // Subscribes to the minute tick itself, so only the label re-renders each |
| 157 | // minute. The minute is passed as the clock so it is the formatter's input. |
| 158 | function RelativeTimeLabel(props: { timestamp: string | null }) { |
| 159 | const nowMinute = useNowMinute(); |
| 160 | const m = useMessages(); |
| 161 | return props.timestamp === null |
| 162 | ? null |
| 163 | : compactSidebarTimeLabel(props.timestamp, Date.parse(`${nowMinute}:00.000Z`), m); |
| 164 | } |
| 165 | |
| 166 | function JumpHintBadge(props: { label: string }) { |
| 167 | return ( |
| 168 | <Kbd aria-hidden data-jump-hint> |
| 169 | {props.label} |
| 170 | </Kbd> |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | const JUMP_HINT_SLOT_CLASS_NAME = |
| 175 | "[&>:not([data-jump-hint])]:invisible [&>:not([data-jump-hint])]:absolute"; |
| 176 | |
| 177 | function WorkingDuration(props: { environmentId: EnvironmentId; startedAt: string | null }) { |
| 178 | const startedMs = props.startedAt !== null ? Date.parse(props.startedAt) : Number.NaN; |
| 179 | if (Number.isNaN(startedMs)) return null; |
| 180 | return <WorkingDurationLabel environmentId={props.environmentId} startedMs={startedMs} />; |
| 181 | } |
| 182 | |
| 183 | // Self-ticking so only this span re-renders each second, not the whole row; |
| 184 | // the shared tick lands every working row's update in the same frame. |
| 185 | function WorkingDurationLabel(props: { environmentId: EnvironmentId; startedMs: number }) { |
| 186 | const nowMs = useNowSecond(); |
| 187 | const messages = useMessages(); |
| 188 | return ( |
| 189 | <span className="tabular-nums"> |
| 190 | {formatWorkingDurationLabel( |
| 191 | toServerClock(props.environmentId, nowMs) - props.startedMs, |
| 192 | messages, |
| 193 | )} |
| 194 | </span> |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | function terminalProcessLabel(count: number, resolve: MessageResolver): string { |
| 199 | return resolve( |
| 200 | msg( |
| 201 | "{count, plural, one {{count} terminal process running} other {{count} terminal processes running}}", |
| 202 | { count }, |
| 203 | ), |
| 204 | ); |
| 205 | } |
| 206 | |
| 207 | function SidebarProviderStack(props: { |
| 208 | thread: SidebarThreadSummary; |
| 209 | providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>; |
| 210 | }) { |
| 211 | const stack = resolveThreadProviderStack(props.thread); |
| 212 | const currentInstanceId = stack[stack.length - 1]!; |
| 213 | const currentEntry = props.providerEntryByInstanceId.get(currentInstanceId) ?? null; |
| 214 | if (currentEntry === null) return null; |
| 215 | const showInstanceBadge = shouldShowInstanceBadge( |
| 216 | currentEntry, |
| 217 | props.providerEntryByInstanceId.values(), |
| 218 | ); |
| 219 | const current = ( |
| 220 | <ProviderInstanceIcon |
| 221 | driverKind={currentEntry.driverKind} |
| 222 | displayName={currentEntry.displayName} |
| 223 | accentColor={currentEntry.accentColor} |
| 224 | acpRegistryAgentId={currentEntry.acpRegistryAgentId} |
| 225 | acpRegistryIconUrl={currentEntry.acpRegistryIconUrl} |
| 226 | showBadge={showInstanceBadge} |
| 227 | size="compact" |
| 228 | iconClassName="opacity-60" |
| 229 | /> |
| 230 | ); |
| 231 | if (stack.length === 1) { |
| 232 | return <span className="inline-flex shrink-0 items-center">{current}</span>; |
| 233 | } |
| 234 | return ( |
| 235 | <span className="inline-flex shrink-0 items-center gap-1.5"> |
| 236 | {stack.slice(0, -1).map((instanceId) => { |
| 237 | const entry = props.providerEntryByInstanceId.get(instanceId); |
| 238 | if (entry === undefined) return null; |
| 239 | return ( |
| 240 | <ProviderInstanceIcon |
| 241 | key={instanceId} |
| 242 | driverKind={entry.driverKind} |
| 243 | displayName={entry.displayName} |
| 244 | acpRegistryAgentId={entry.acpRegistryAgentId} |
| 245 | acpRegistryIconUrl={entry.acpRegistryIconUrl} |
| 246 | iconClassName="size-3 opacity-35 grayscale" |
| 247 | /> |
| 248 | ); |
| 249 | })} |
| 250 | <span className="relative z-10 inline-flex items-center">{current}</span> |
| 251 | </span> |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | function SidebarThreadTooltip({ |
| 256 | thread, |
| 257 | project, |
| 258 | projectDisplayName, |
| 259 | environmentLabel, |
| 260 | environmentMachine, |
| 261 | providerEntry, |
| 262 | providerEntryByInstanceId, |
| 263 | showInstanceBadge, |
| 264 | modelInstanceId, |
| 265 | modelLabel, |
| 266 | branchMismatch, |
| 267 | terminalStatus, |
| 268 | terminalProcessCount, |
| 269 | }: { |
| 270 | thread: SidebarThreadSummary; |
| 271 | project: ProjectFaviconProject | null; |
| 272 | projectDisplayName: string | null; |
| 273 | environmentLabel: string | null; |
| 274 | environmentMachine: EnvironmentMachineKind; |
| 275 | providerEntry: SidebarProviderEntry | null; |
| 276 | providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>; |
| 277 | showInstanceBadge: boolean; |
| 278 | modelInstanceId: string; |
| 279 | modelLabel: string; |
| 280 | branchMismatch: { |
| 281 | threadBranch: string; |
| 282 | currentBranch: string; |
| 283 | } | null; |
| 284 | terminalStatus: TerminalStatusIndicator | null; |
| 285 | terminalProcessCount: number; |
| 286 | }) { |
| 287 | const driverKind = providerEntry?.driverKind ?? null; |
| 288 | const previousProviderNames = thread.providerInstanceHistory |
| 289 | .filter((instanceId) => instanceId !== modelInstanceId) |
| 290 | .map((instanceId) => providerEntryByInstanceId.get(instanceId)?.displayName ?? instanceId); |
| 291 | const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId); |
| 292 | const gt = useGT(); |
| 293 | const m = useMessages(); |
| 294 | return ( |
| 295 | <ThreadHoverCardPopup side="right" align="start" sideOffset={4}> |
| 296 | <ThreadHoverCard |
| 297 | title={thread.title} |
| 298 | footer={ |
| 299 | supportsMultiplePullRequests && thread.pullRequests.length > 0 ? ( |
| 300 | <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground"> |
| 301 | <ThreadPullRequestsMiniList pullRequests={thread.pullRequests} /> |
| 302 | </div> |
| 303 | ) : null |
| 304 | } |
| 305 | > |
| 306 | {projectDisplayName ? ( |
| 307 | <div className="flex min-w-0 items-center gap-2"> |
| 308 | {project ? <ProjectFavicon project={project} className="size-3 shrink-0" /> : null} |
| 309 | <div className="min-w-0 truncate text-foreground/75">{projectDisplayName}</div> |
| 310 | </div> |
| 311 | ) : null} |
| 312 | {environmentLabel ? ( |
| 313 | <div className="flex min-w-0 items-center gap-2"> |
| 314 | <EnvironmentMachineIcon |
| 315 | kind={environmentMachine} |
| 316 | className="size-3 shrink-0 stroke-muted-foreground" |
| 317 | /> |
| 318 | <div className="min-w-0 truncate text-foreground/75">{environmentLabel}</div> |
| 319 | </div> |
| 320 | ) : null} |
| 321 | {thread.branch ? ( |
| 322 | <div className="flex min-w-0 items-center gap-2"> |
| 323 | <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" /> |
| 324 | <MiddleTruncate value={thread.branch} className="flex" /> |
| 325 | </div> |
| 326 | ) : null} |
| 327 | {branchMismatch ? ( |
| 328 | <div className="flex min-w-0 items-start gap-2 text-warning"> |
| 329 | <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" /> |
| 330 | <div className="min-w-0 flex-1 wrap-break-word"> |
| 331 | <T>You're currently checked out on another branch.</T> |
| 332 | </div> |
| 333 | </div> |
| 334 | ) : null} |
| 335 | {driverKind ? ( |
| 336 | <div className="flex min-w-0 items-center gap-2"> |
| 337 | <ProviderInstanceIcon |
| 338 | driverKind={driverKind} |
| 339 | displayName={ |
| 340 | providerEntry?.displayName ?? thread.runtime?.providerName ?? modelInstanceId |
| 341 | } |
| 342 | accentColor={providerEntry?.accentColor} |
| 343 | acpRegistryAgentId={providerEntry?.acpRegistryAgentId} |
| 344 | acpRegistryIconUrl={providerEntry?.acpRegistryIconUrl} |
| 345 | showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined} |
| 346 | badgeContent="none" |
| 347 | badgeClassName="h-2 min-w-2 px-0" |
| 348 | iconClassName="size-3 shrink-0 opacity-60" |
| 349 | /> |
| 350 | <div className="min-w-0 truncate text-foreground/75"> |
| 351 | {showInstanceBadge && providerEntry |
| 352 | ? `${modelLabel} · ${providerEntry.displayName}` |
| 353 | : modelLabel} |
| 354 | </div> |
| 355 | </div> |
| 356 | ) : null} |
| 357 | {previousProviderNames.length > 0 ? ( |
| 358 | <div className="flex min-w-0 items-center gap-2"> |
| 359 | <ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" /> |
| 360 | <div className="min-w-0 truncate text-foreground/75"> |
| 361 | <T> |
| 362 | Handed off from <Var>{previousProviderNames.join(", ")}</Var> |
| 363 | </T> |
| 364 | </div> |
| 365 | </div> |
| 366 | ) : null} |
| 367 | {terminalStatus ? ( |
| 368 | <div className="flex min-w-0 items-center gap-2"> |
| 369 | <TerminalIcon |
| 370 | aria-hidden |
| 371 | className={cn("size-3 shrink-0", terminalStatus.colorClass)} |
| 372 | /> |
| 373 | <div className="min-w-0 truncate text-foreground/75"> |
| 374 | {terminalProcessLabel(terminalProcessCount, m)} |
| 375 | </div> |
| 376 | </div> |
| 377 | ) : null} |
| 378 | {thread.runtime?.lastError ? ( |
| 379 | <div |
| 380 | className={cn( |
| 381 | "flex min-w-0 items-center gap-2", |
| 382 | thread.runtime.lastErrorClass === "usage_limit" ? "text-warning" : "text-error", |
| 383 | )} |
| 384 | > |
| 385 | <CircleAlertIcon className="size-3 shrink-0 stroke-current" /> |
| 386 | <div className="min-w-0 truncate"> |
| 387 | {thread.runtime.lastErrorClass === "usage_limit" |
| 388 | ? gt("Usage limit reached") |
| 389 | : gt("Error occurred")} |
| 390 | </div> |
| 391 | </div> |
| 392 | ) : null} |
| 393 | </ThreadHoverCard> |
| 394 | </ThreadHoverCardPopup> |
| 395 | ); |
| 396 | } |
| 397 | |
| 398 | function SnoozeMenuButton(props: { |
| 399 | open: boolean; |
| 400 | onOpenChange: (open: boolean) => void; |
| 401 | onSnooze: (preset: Pick<SnoozePreset, "snoozedUntil">) => void; |
| 402 | timestampFormat: TimestampFormat; |
| 403 | environmentId: EnvironmentId; |
| 404 | }) { |
| 405 | const { open, onOpenChange, onSnooze, timestampFormat, environmentId } = props; |
| 406 | const gt = useGT(); |
| 407 | const messages = useMessages(); |
| 408 | const presets = open |
| 409 | ? // oxlint-disable-next-line react/purity -- Presets are resolved only while the menu is open, so each opening reads a fresh time. |
| 410 | resolveSnoozePresets(new Date(), timestampFormat, environmentId, messages) |
| 411 | : []; |
| 412 | return ( |
| 413 | <Menu open={open} onOpenChange={onOpenChange}> |
| 414 | <Tooltip> |
| 415 | <TooltipTrigger |
| 416 | render={ |
| 417 | <MenuTrigger |
| 418 | render={ |
| 419 | <button |
| 420 | type="button" |
| 421 | aria-label={gt("Snooze thread")} |
| 422 | onClick={(event) => event.stopPropagation()} |
| 423 | onDoubleClick={(event) => event.stopPropagation()} |
| 424 | 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" |
| 425 | /> |
| 426 | } |
| 427 | /> |
| 428 | } |
| 429 | > |
| 430 | <ClockIcon className="size-3" /> |
| 431 | </TooltipTrigger> |
| 432 | <TooltipPopup> |
| 433 | <T>Snooze thread</T> |
| 434 | </TooltipPopup> |
| 435 | </Tooltip> |
| 436 | <MenuPopup side="bottom" align="end"> |
| 437 | {presets.map((preset) => ( |
| 438 | <MenuItem |
| 439 | key={preset.id} |
| 440 | onClick={(event) => { |
| 441 | event.stopPropagation(); |
| 442 | const picked = pickSnoozePreset(presets, preset.id, timestampFormat, environmentId); |
| 443 | if (picked) onSnooze(picked); |
| 444 | }} |
| 445 | > |
| 446 | {preset.label} |
| 447 | <MenuItemDetail>{preset.whenLabel}</MenuItemDetail> |
| 448 | </MenuItem> |
| 449 | ))} |
| 450 | {presets.length > 0 ? <MenuSeparator /> : null} |
| 451 | <MenuItem |
| 452 | onClick={async (event) => { |
| 453 | event.stopPropagation(); |
| 454 | const choice = await requestCustomSnooze(); |
| 455 | if (choice) onSnooze(choice); |
| 456 | }} |
| 457 | > |
| 458 | <T>Custom…</T> |
| 459 | </MenuItem> |
| 460 | </MenuPopup> |
| 461 | </Menu> |
| 462 | ); |
| 463 | } |
| 464 | |
| 465 | type SortableThreadRowBag = Pick< |
| 466 | ReturnType<typeof useSortable>, |
| 467 | "listeners" | "setNodeRef" | "transform" | "transition" | "isDragging" |
| 468 | >; |
| 469 | |
| 470 | export const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8"; |
| 471 | export const draftPenClassName = "size-3 shrink-0 text-warning-foreground"; |
| 472 | |
| 473 | // useSortable memoizes on its `disabled` object, so a fresh one per render |
| 474 | // re-renders every row and marker on each sidebar update. |
| 475 | export const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable: true } as const; |
| 476 | const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable: false } as const; |
| 477 | |
| 478 | // Takes the row's props rather than a render function: a closure from the |
| 479 | // sidebar body is new on every sidebar render, which rebuilt the bag and |
| 480 | // re-rendered every memoized row with it. |
| 481 | export function SortableThreadRow( |
| 482 | props: Omit<SidebarThreadRowProps, "sortable"> & { |
| 483 | sortableId: string; |
| 484 | sortableDisabled: boolean; |
| 485 | contextDrag: boolean; |
| 486 | }, |
| 487 | ) { |
| 488 | const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props; |
| 489 | const canOperateThread = useEnvironmentScope( |
| 490 | rowProps.thread.environmentId, |
| 491 | AuthOrchestrationOperateScope, |
| 492 | ); |
| 493 | const { listeners, setNodeRef, transform, transition, isDragging } = useSortable({ |
| 494 | id: sortableId, |
| 495 | disabled: |
| 496 | sortableDisabled || !canOperateThread |
| 497 | ? SIDEBAR_SORTABLE_DRAG_DISABLED |
| 498 | : SIDEBAR_SORTABLE_DRAG_ENABLED, |
| 499 | animateLayoutChanges: animateSidebarLayoutChanges, |
| 500 | }); |
| 501 | // dnd-kit memoizes each field but not the bag, so the memoized row would |
| 502 | // rerender on every shell update without this. |
| 503 | const bag = { |
| 504 | listeners, |
| 505 | setNodeRef, |
| 506 | transform: contextDrag ? null : transform, |
| 507 | transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition, |
| 508 | isDragging: isDragging && !contextDrag, |
| 509 | }; |
| 510 | // The sidebar arranges rows from quiet shells, which hold still while a |
| 511 | // thread streams; reading the live shell here re-renders only this row. |
| 512 | const liveThread = useThreadShell( |
| 513 | scopeThreadRef(rowProps.thread.environmentId, rowProps.thread.id), |
| 514 | ); |
| 515 | // A runtime on the arranged copy but not the run-less live shell is the list's launch overlay. |
| 516 | const thread = |
| 517 | liveThread === null |
| 518 | ? rowProps.thread |
| 519 | : rowProps.thread.runtime !== null |
| 520 | ? asLaunchingThread(liveThread) |
| 521 | : liveThread; |
| 522 | // Keyed by variant so a card/slim switch remounts the row. |
| 523 | return <SidebarThreadRow key={rowProps.variant} {...rowProps} thread={thread} sortable={bag} />; |
| 524 | } |
| 525 | export type SidebarSweepAction = "settle" | "unsettle" | "unsnooze"; |
| 526 | const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = { |
| 527 | pin: ( |
| 528 | <> |
| 529 | <PinIcon aria-hidden className="size-3" /> |
| 530 | <T>Pin</T> |
| 531 | </> |
| 532 | ), |
| 533 | unpin: ( |
| 534 | <> |
| 535 | <PinOffIcon aria-hidden className="size-3" /> |
| 536 | <T>Unpin</T> |
| 537 | </> |
| 538 | ), |
| 539 | settle: ( |
| 540 | <> |
| 541 | <CircleCheckIcon aria-hidden className="size-3" /> |
| 542 | <T>Settle</T> |
| 543 | </> |
| 544 | ), |
| 545 | unsettle: ( |
| 546 | <> |
| 547 | <Undo2Icon aria-hidden className="size-3" /> |
| 548 | <T>Un-settle</T> |
| 549 | </> |
| 550 | ), |
| 551 | wake: ( |
| 552 | <> |
| 553 | <AlarmClockOffIcon aria-hidden className="size-3" /> |
| 554 | <T>Wake</T> |
| 555 | </> |
| 556 | ), |
| 557 | }; |
| 558 | |
| 559 | const TOP_STATUS_ICONS = { |
| 560 | working: CircleDashedIcon, |
| 561 | waiting: CircleDotDashedIcon, |
| 562 | input: MessageCircleQuestionIcon, |
| 563 | request: UserRoundIcon, |
| 564 | approval: ShieldQuestionIcon, |
| 565 | failed: CircleAlertIcon, |
| 566 | done: CircleCheckIcon, |
| 567 | woke: AlarmClockIcon, |
| 568 | } as const; |
| 569 | |
| 570 | function TopStatusIcon(props: { icon: keyof typeof TOP_STATUS_ICONS; className: string }) { |
| 571 | const Icon = TOP_STATUS_ICONS[props.icon]; |
| 572 | return <Icon aria-hidden className={cn("shrink-0", props.className)} />; |
| 573 | } |
| 574 | |
| 575 | type SidebarThreadRowProps = { |
| 576 | thread: SidebarThreadSummary; |
| 577 | // "folder" is a one-line row inside a boring sidebar project folder; |
| 578 | // "folder-multiline" adds the card's branch and PR line under it. |
| 579 | variant: "card" | "slim" | "folder" | "folder-multiline"; |
| 580 | navigationParent?: string | undefined; |
| 581 | variantAction: SidebarSweepAction; |
| 582 | settlementSupported: boolean; |
| 583 | snoozeSupported: boolean; |
| 584 | pinningSupported: boolean; |
| 585 | isPinned: boolean; |
| 586 | sortable?: SortableThreadRowBag | undefined; |
| 587 | dropVerb: SidebarDropVerb | null; |
| 588 | dragOverPinned: boolean; |
| 589 | sweepAction: SidebarSweepAction | null; |
| 590 | snoozeWakeLabelText: string | null; |
| 591 | wokeAt: string | null; |
| 592 | isActive: boolean; |
| 593 | // Set on the active row only; scrolls it into view when a reveal is owed. |
| 594 | revealRef?: ((row: HTMLElement, threadKey: string) => (() => void) | undefined) | undefined; |
| 595 | // Unlike isActive, never true for the ancestor standing in for an open |
| 596 | // subagent: drafts and PR clicks care about which composer is on screen. |
| 597 | isRouteThread: boolean; |
| 598 | // Read at click time; a prop would re-render every row on entering or leaving a thread route. |
| 599 | readOpensPullRequestsInRightPanel: () => boolean; |
| 600 | jumpLabel: string | null; |
| 601 | currentEnvironmentId: string | null; |
| 602 | environmentLabel: string | null; |
| 603 | environmentMachine: EnvironmentMachineKind; |
| 604 | scratchMachineLabel: string | null; |
| 605 | project: EnvironmentProject | null; |
| 606 | projectDisplayName: string | null; |
| 607 | providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>; |
| 608 | timestampFormat: TimestampFormat; |
| 609 | onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void; |
| 610 | onThreadActivate: (threadRef: ScopedThreadRef) => void; |
| 611 | onStartRename: (threadRef: ScopedThreadRef, title: string) => void; |
| 612 | onRenameTitleChange: (title: string) => void; |
| 613 | onCommitRename: (threadRef: ScopedThreadRef, title: string) => void; |
| 614 | onCancelRename: () => void; |
| 615 | isRenaming: boolean; |
| 616 | renamingTitle: string; |
| 617 | onContextMenu: ( |
| 618 | threadRef: ScopedThreadRef, |
| 619 | position: { x: number; y: number }, |
| 620 | source: ContextMenuSource, |
| 621 | ) => void; |
| 622 | onSettle: (threadRef: ScopedThreadRef) => void; |
| 623 | onActionSweepStart: ( |
| 624 | threadRef: ScopedThreadRef, |
| 625 | action: SidebarSweepAction, |
| 626 | event: PointerEvent, |
| 627 | ) => void; |
| 628 | onUnsettle: (threadRef: ScopedThreadRef) => void; |
| 629 | onSnooze: (threadRef: ScopedThreadRef, preset: Pick<SnoozePreset, "snoozedUntil">) => void; |
| 630 | onUnsnooze: (threadRef: ScopedThreadRef) => void; |
| 631 | onUnpin: (threadRef: ScopedThreadRef) => void; |
| 632 | onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void; |
| 633 | onFileDropThreads?: ((threadRef: ScopedThreadRef, files: File[]) => void) | undefined; |
| 634 | }; |
| 635 | |
| 636 | // Mounted only while renaming, so each rename starts uncommitted. |
| 637 | function ThreadRenameInput(props: { |
| 638 | title: string; |
| 639 | onTitleChange: (title: string) => void; |
| 640 | onCommit: () => void; |
| 641 | onCancel: () => void; |
| 642 | }) { |
| 643 | // Enter and Escape blur the input as it unmounts; that blur must not commit again. |
| 644 | const settledRef = useRef(false); |
| 645 | const gt = useGT(); |
| 646 | const handleKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => { |
| 647 | event.stopPropagation(); |
| 648 | if (event.nativeEvent.isComposing || event.keyCode === 229) return; |
| 649 | if (event.key === "Enter") { |
| 650 | event.preventDefault(); |
| 651 | settledRef.current = true; |
| 652 | props.onCommit(); |
| 653 | } else if (event.key === "Escape") { |
| 654 | event.preventDefault(); |
| 655 | settledRef.current = true; |
| 656 | props.onCancel(); |
| 657 | } |
| 658 | }; |
| 659 | return ( |
| 660 | <input |
| 661 | autoFocus |
| 662 | value={props.title} |
| 663 | dir="auto" |
| 664 | aria-label={gt("Thread title")} |
| 665 | onChange={(event) => props.onTitleChange(event.target.value)} |
| 666 | onFocus={(event) => event.currentTarget.select()} |
| 667 | onKeyDown={handleKeyDown} |
| 668 | onBlur={() => { |
| 669 | if (!settledRef.current) props.onCommit(); |
| 670 | }} |
| 671 | onClick={(event) => event.stopPropagation()} |
| 672 | onDoubleClick={(event) => event.stopPropagation()} |
| 673 | className="-mx-1 min-w-0 flex-1 rounded-sm bg-card px-1 text-sm font-medium text-card-foreground outline-none ring-1 ring-inset ring-input focus:ring-foreground" |
| 674 | /> |
| 675 | ); |
| 676 | } |
| 677 | |
| 678 | const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) { |
| 679 | const gt = useGT(); |
| 680 | const messages = useMessages(); |
| 681 | const { |
| 682 | isRenaming, |
| 683 | onCancelRename, |
| 684 | onCommitRename, |
| 685 | onContextMenu, |
| 686 | onAcknowledgeWoke, |
| 687 | onFileDropThreads, |
| 688 | onRenameTitleChange, |
| 689 | onSettle, |
| 690 | onActionSweepStart, |
| 691 | onSnooze, |
| 692 | onStartRename, |
| 693 | onThreadActivate, |
| 694 | onThreadClick, |
| 695 | onUnsettle, |
| 696 | onUnsnooze, |
| 697 | onUnpin, |
| 698 | readOpensPullRequestsInRightPanel, |
| 699 | renamingTitle, |
| 700 | thread, |
| 701 | variant, |
| 702 | variantAction, |
| 703 | } = props; |
| 704 | const threadRef = scopeThreadRef(thread.environmentId, thread.id); |
| 705 | const threadKey = scopedThreadKey(threadRef); |
| 706 | const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope); |
| 707 | const { leaseLiveStatus, rowRef: leaseRowRef } = useSidebarRowSubscriptionLease(props.isActive); |
| 708 | const { revealRef } = props; |
| 709 | const rowRef = (row: HTMLElement | null) => { |
| 710 | const stopReveal = row === null ? undefined : revealRef?.(row, threadKey); |
| 711 | const releaseLease = leaseRowRef(row); |
| 712 | if (!stopReveal) return releaseLease; |
| 713 | return () => { |
| 714 | stopReveal(); |
| 715 | releaseLease?.(); |
| 716 | }; |
| 717 | }; |
| 718 | const isRegeneratingTitle = thread.titleRegeneration != null; |
| 719 | const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]); |
| 720 | const lastVisitedAt = resolveThreadLastVisitedAt(thread.lastVisitedAt, localLastVisitedAt); |
| 721 | const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey)); |
| 722 | const openPrLink = useOpenPrLink(); |
| 723 | const runningTerminalIds = useThreadRunningTerminalIds({ |
| 724 | environmentId: thread.environmentId, |
| 725 | threadId: thread.id, |
| 726 | }); |
| 727 | const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds, messages); |
| 728 | const terminalProcessCount = runningTerminalIds.length; |
| 729 | const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread; |
| 730 | const handleDiscardDraftClick = (event: ReactMouseEvent) => { |
| 731 | event.preventDefault(); |
| 732 | event.stopPropagation(); |
| 733 | discardComposerDraft(threadRef); |
| 734 | }; |
| 735 | |
| 736 | const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null; |
| 737 | const linkedPullRequestStatus = useLinkedThreadPullRequest( |
| 738 | thread.environmentId, |
| 739 | thread.linkedPullRequest, |
| 740 | leaseLiveStatus, |
| 741 | thread.pullRequests, |
| 742 | thread.branchPullRequest, |
| 743 | ); |
| 744 | const branchTarget = |
| 745 | leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null |
| 746 | ? { environmentId: thread.environmentId, cwd: gitCwd } |
| 747 | : null; |
| 748 | const gitStatus = useEnvironmentQuery( |
| 749 | branchTarget === null |
| 750 | ? null |
| 751 | : vcsEnvironment.branch({ |
| 752 | environmentId: branchTarget.environmentId, |
| 753 | input: { cwd: branchTarget.cwd }, |
| 754 | }), |
| 755 | ); |
| 756 | useAtomMount(vcsBranchRevalidation(branchTarget)); |
| 757 | const visibleGitStatus = useRetainedValue( |
| 758 | JSON.stringify([thread.environmentId, gitCwd]), |
| 759 | gitStatus.data, |
| 760 | ); |
| 761 | const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus); |
| 762 | const pr = linkedPullRequestStatus?.pr ?? null; |
| 763 | const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId); |
| 764 | const currentLinkedPr = supportsMultiplePullRequests |
| 765 | ? resolveThreadCurrentPullRequestLink(thread.pullRequests) |
| 766 | : null; |
| 767 | |
| 768 | const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt }); |
| 769 | const status = resolveSidebarRowStatus({ ...thread, lastVisitedAt }); |
| 770 | const lastVisitedDate = lastVisitedAt === undefined ? null : parseTimestampDate(lastVisitedAt); |
| 771 | const wokeAtDate = props.wokeAt === null ? null : parseTimestampDate(props.wokeAt); |
| 772 | const isWoke = |
| 773 | wokeAtDate !== null && |
| 774 | (lastVisitedDate === null || lastVisitedDate < wokeAtDate) && |
| 775 | thread.settledOverride !== "settled"; |
| 776 | const shouldRecede = shouldRecedeSidebarThread({ |
| 777 | status, |
| 778 | isUnread, |
| 779 | isWoke, |
| 780 | isActive: props.isActive, |
| 781 | isSelected, |
| 782 | }); |
| 783 | const topStatus = |
| 784 | status === "preparing" || status === "working" |
| 785 | ? { |
| 786 | label: |
| 787 | status === "preparing" |
| 788 | ? gt("Setting up") |
| 789 | : thread.goal?.status === "active" |
| 790 | ? gt("Goal", { $context: "thread status: working on a goal" }) |
| 791 | : gt("Working", { $context: "thread status" }), |
| 792 | icon: "working" as const, |
| 793 | className: "text-info-foreground", |
| 794 | } |
| 795 | : status === "waiting" |
| 796 | ? { |
| 797 | label: gt("Waiting", { $context: "thread status" }), |
| 798 | icon: "waiting" as const, |
| 799 | className: "text-muted-foreground", |
| 800 | } |
| 801 | : status === "approval" |
| 802 | ? { |
| 803 | label: gt("Approval", { $context: "thread status: needs approval" }), |
| 804 | icon: "approval" as const, |
| 805 | className: "text-warning-foreground", |
| 806 | } |
| 807 | : status === "input" |
| 808 | ? { |
| 809 | label: gt("Input", { $context: "thread status: needs user input" }), |
| 810 | icon: "input" as const, |
| 811 | className: "text-indigo-600 dark:text-indigo-300", |
| 812 | } |
| 813 | : status === "request" |
| 814 | ? { |
| 815 | label: gt("Request", { $context: "thread status: guest request" }), |
| 816 | icon: "request" as const, |
| 817 | className: "text-guest-foreground", |
| 818 | } |
| 819 | : status === "limited" |
| 820 | ? { |
| 821 | label: gt("Limited", { $context: "thread status: usage limited" }), |
| 822 | icon: "failed" as const, |
| 823 | className: "text-warning-foreground", |
| 824 | } |
| 825 | : status === "failed" |
| 826 | ? { |
| 827 | label: gt("Failed", { $context: "thread status" }), |
| 828 | icon: "failed" as const, |
| 829 | className: "text-error-foreground", |
| 830 | } |
| 831 | : isWoke |
| 832 | ? { |
| 833 | label: gt("Woke", { $context: "thread status: woke from snooze" }), |
| 834 | icon: "woke" as const, |
| 835 | className: "text-warning-foreground", |
| 836 | } |
| 837 | : isUnread |
| 838 | ? { |
| 839 | label: gt("Done", { $context: "thread status" }), |
| 840 | icon: "done" as const, |
| 841 | className: "text-success-foreground", |
| 842 | } |
| 843 | : null; |
| 844 | const isWokeStatus = topStatus?.icon === "woke"; |
| 845 | |
| 846 | const branchMismatch = resolveLocalCheckoutBranchMismatch({ |
| 847 | effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree", |
| 848 | activeWorktreePath: thread.worktreePath, |
| 849 | activeThreadBranch: thread.branch, |
| 850 | currentGitBranch: visibleGitStatus?.refName ?? null, |
| 851 | }); |
| 852 | const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider, messages); |
| 853 | |
| 854 | const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId; |
| 855 | const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null; |
| 856 | const showInstanceBadge = |
| 857 | providerEntry !== null && |
| 858 | shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values()); |
| 859 | const selectedModel = providerEntry?.models.find( |
| 860 | (model) => model.slug === thread.modelSelection.model, |
| 861 | ); |
| 862 | const modelLabel = selectedModel |
| 863 | ? getTriggerDisplayModelName(selectedModel, providerEntry?.driverKind) |
| 864 | : thread.modelSelection.model; |
| 865 | |
| 866 | const isRemote = thread.environmentId !== props.currentEnvironmentId; |
| 867 | const showsScratchMachine = !checkoutThread.branch && props.scratchMachineLabel !== null; |
| 868 | |
| 869 | const detailsTooltip = ( |
| 870 | <SidebarThreadTooltip |
| 871 | thread={checkoutThread} |
| 872 | project={props.project} |
| 873 | projectDisplayName={props.projectDisplayName} |
| 874 | environmentLabel={props.environmentLabel} |
| 875 | environmentMachine={props.environmentMachine} |
| 876 | providerEntry={providerEntry} |
| 877 | providerEntryByInstanceId={props.providerEntryByInstanceId} |
| 878 | showInstanceBadge={showInstanceBadge} |
| 879 | modelInstanceId={modelInstanceId} |
| 880 | modelLabel={modelLabel} |
| 881 | branchMismatch={branchMismatch} |
| 882 | terminalStatus={terminalStatus} |
| 883 | terminalProcessCount={terminalProcessCount} |
| 884 | /> |
| 885 | ); |
| 886 | |
| 887 | const handleClick = (event: ReactMouseEvent) => { |
| 888 | onThreadClick(event, threadRef); |
| 889 | }; |
| 890 | const handleAcknowledgeWokeClick = (event: ReactMouseEvent) => { |
| 891 | event.preventDefault(); |
| 892 | event.stopPropagation(); |
| 893 | if (props.wokeAt === null) return; |
| 894 | onAcknowledgeWoke(threadRef, props.wokeAt); |
| 895 | }; |
| 896 | const handleContextMenu = (event: ReactMouseEvent) => { |
| 897 | event.preventDefault(); |
| 898 | onContextMenu(threadRef, { x: event.clientX, y: event.clientY }, contextMenuSourceOf(event)); |
| 899 | }; |
| 900 | const handleKeyDown = (event: ReactKeyboardEvent) => { |
| 901 | if (event.target !== event.currentTarget) return; |
| 902 | if ( |
| 903 | event.key === "F2" && |
| 904 | !isRenaming && |
| 905 | readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) |
| 906 | ) { |
| 907 | event.preventDefault(); |
| 908 | onStartRename(threadRef, thread.title); |
| 909 | return; |
| 910 | } |
| 911 | if (event.key !== "Enter" && event.key !== " ") return; |
| 912 | event.preventDefault(); |
| 913 | onThreadActivate(threadRef); |
| 914 | }; |
| 915 | const handleDoubleClick = (event: ReactMouseEvent) => { |
| 916 | if ( |
| 917 | !readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope) || |
| 918 | isRenaming || |
| 919 | event.metaKey || |
| 920 | event.ctrlKey || |
| 921 | event.shiftKey || |
| 922 | event.altKey |
| 923 | ) { |
| 924 | return; |
| 925 | } |
| 926 | if ((event.target as HTMLElement).closest("button, a, input")) return; |
| 927 | event.preventDefault(); |
| 928 | onStartRename(threadRef, thread.title); |
| 929 | }; |
| 930 | const [isFileDragOver, setIsFileDragOver] = useState(false); |
| 931 | const fileDropHandlers = onFileDropThreads |
| 932 | ? makeWorkspaceFileDropHandlers({ |
| 933 | setDragActive: (active) => setFileDragActive(setIsFileDragOver, active), |
| 934 | addFiles: (files) => { |
| 935 | onFileDropThreads(threadRef, files); |
| 936 | }, |
| 937 | addFolders: () => {}, |
| 938 | }) |
| 939 | : null; |
| 940 | const handleSettleClick = (event: ReactMouseEvent) => { |
| 941 | event.preventDefault(); |
| 942 | event.stopPropagation(); |
| 943 | onSettle(threadRef); |
| 944 | }; |
| 945 | const handleActionPointerDown = (event: ReactPointerEvent) => { |
| 946 | if (!event.isPrimary || event.button !== 0) return; |
| 947 | event.stopPropagation(); |
| 948 | onActionSweepStart(threadRef, variantAction, event.nativeEvent); |
| 949 | }; |
| 950 | const handleUnsettleClick = (event: ReactMouseEvent) => { |
| 951 | event.preventDefault(); |
| 952 | event.stopPropagation(); |
| 953 | onUnsettle(threadRef); |
| 954 | }; |
| 955 | const handleUnsnoozeClick = (event: ReactMouseEvent) => { |
| 956 | event.preventDefault(); |
| 957 | event.stopPropagation(); |
| 958 | onUnsnooze(threadRef); |
| 959 | }; |
| 960 | const handleUnpinClick = (event: ReactMouseEvent) => { |
| 961 | event.preventDefault(); |
| 962 | event.stopPropagation(); |
| 963 | onUnpin(threadRef); |
| 964 | }; |
| 965 | const handleSnoozePreset = (preset: Pick<SnoozePreset, "snoozedUntil">) => { |
| 966 | onSnooze(threadRef, preset); |
| 967 | }; |
| 968 | const [snoozeMenuOpenRaw, setSnoozeMenuOpen] = useState(false); |
| 969 | // The React Compiler caches render results on their inputs, so a clock read |
| 970 | // here would stay frozen until `thread` changes and a queued-turn gate would |
| 971 | // never reopen. The gate's clock is state, reset with the thread. |
| 972 | const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({ |
| 973 | thread, |
| 974 | now: new Date().toISOString(), |
| 975 | })); |
| 976 | if (snoozeGateClock.thread !== thread) { |
| 977 | // oxlint-disable-next-line react/purity -- Reseeds the snooze gate clock only in the render-phase adjustment that runs when the thread changes. |
| 978 | setSnoozeGateClock({ thread, now: new Date().toISOString() }); |
| 979 | } |
| 980 | const snoozeGateNow = snoozeGateClock.now; |
| 981 | const snoozeGateExpiryMs = hasQueuedTurnStart(thread, { now: snoozeGateNow }) |
| 982 | ? Date.parse(thread.latestUserMessageAt ?? "") + QUEUED_TURN_START_GRACE_MS |
| 983 | : Number.NaN; |
| 984 | // A gate still closed past its expiry is held by runtime status, not time, |
| 985 | // so no clock tick can open it. |
| 986 | const snoozeGateOpensAt = |
| 987 | Number.isFinite(snoozeGateExpiryMs) && snoozeGateExpiryMs > Date.parse(snoozeGateNow) |
| 988 | ? snoozeGateExpiryMs + 50 |
| 989 | : null; |
| 990 | const snoozeGateOpened = useDeadlinePassed(snoozeGateOpensAt); |
| 991 | if (snoozeGateOpened && snoozeGateOpensAt !== null) { |
| 992 | setSnoozeGateClock({ thread, now: new Date(snoozeGateOpensAt).toISOString() }); |
| 993 | } |
| 994 | const showSnoozeButton = |
| 995 | canOperateThread && props.snoozeSupported && canSnooze(thread, { now: snoozeGateNow }); |
| 996 | // Closing here, not just masking, keeps the menu from reopening when the button returns. |
| 997 | if (snoozeMenuOpenRaw && !showSnoozeButton) setSnoozeMenuOpen(false); |
| 998 | const snoozeMenuOpen = snoozeMenuOpenRaw && showSnoozeButton; |
| 999 | const jumpHintLabel = snoozeMenuOpen ? null : props.jumpLabel; |
| 1000 | const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => { |
| 1001 | const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url; |
| 1002 | if (!url) return; |
| 1003 | const showInRightPanel = targetUrl !== undefined || readOpensPullRequestsInRightPanel(); |
| 1004 | const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined); |
| 1005 | if (openedInRightPanel && showInRightPanel && !props.isRouteThread) { |
| 1006 | onThreadActivate(threadRef); |
| 1007 | } |
| 1008 | }; |
| 1009 | |
| 1010 | const rowSurfaceClassName = cn( |
| 1011 | "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", |
| 1012 | variantAction === "unsettle" && |
| 1013 | !props.isActive && |
| 1014 | "[&:not(:hover):not(:focus-within)_*:not(.live-activity-focus_*)]:text-secondary-label", |
| 1015 | props.isActive |
| 1016 | ? "bg-sidebar-row-active text-sidebar-foreground light:ring-1 light:ring-inset light:ring-sidebar-border/70" |
| 1017 | : isSelected || props.sweepAction !== null |
| 1018 | ? "bg-sidebar-row-selected text-sidebar-foreground light:ring-1 light:ring-inset light:ring-sidebar-border/70" |
| 1019 | : hasUnsentDraft |
| 1020 | ? cn(draftSurfaceClassName, "text-sidebar-foreground") |
| 1021 | : shouldRecede |
| 1022 | ? "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground" |
| 1023 | : "bg-transparent text-sidebar-foreground hover:bg-sidebar-row-hover", |
| 1024 | shouldRecede && |
| 1025 | (status === "preparing" || status === "working") && |
| 1026 | "opacity-70 transition-opacity hover:opacity-100 focus-within:opacity-100 motion-reduce:transition-none", |
| 1027 | isFileDragOver && "ring-1 ring-inset ring-primary/70", |
| 1028 | isFileDragOver && !props.isActive && !isSelected && "bg-sidebar-row-hover", |
| 1029 | props.sortable?.isDragging && |
| 1030 | "bg-sidebar bg-linear-to-b from-sidebar-row-active to-sidebar-row-active text-sidebar-foreground opacity-100 shadow-lg", |
| 1031 | ); |
| 1032 | const sortable = props.sortable; |
| 1033 | const sortableRootProps = sortable |
| 1034 | ? { |
| 1035 | ref: sortable.setNodeRef, |
| 1036 | style: { |
| 1037 | transform: CSS.Translate.toString(sortable.transform), |
| 1038 | transition: sortable.transition, |
| 1039 | // A zero-height boundary also makes dnd-kit scale the source to |
| 1040 | // zero. Only projected peers use scaleY as a visibility sentinel. |
| 1041 | visibility: |
| 1042 | !sortable.isDragging && sortable.transform?.scaleY === 0 |
| 1043 | ? ("hidden" as const) |
| 1044 | : undefined, |
| 1045 | }, |
| 1046 | ...sortable.listeners, |
| 1047 | } |
| 1048 | : {}; |
| 1049 | const destinationVerb = sortable?.isDragging |
| 1050 | ? props.dropVerb |
| 1051 | : props.sweepAction === "unsnooze" |
| 1052 | ? "wake" |
| 1053 | : props.sweepAction; |
| 1054 | const dragDestination = |
| 1055 | destinationVerb !== null ? ( |
| 1056 | <span |
| 1057 | role="status" |
| 1058 | 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" |
| 1059 | > |
| 1060 | {dropVerbBadge[destinationVerb]} |
| 1061 | </span> |
| 1062 | ) : null; |
| 1063 | |
| 1064 | const accessibility = resolveSidebarRowAccessibility({ |
| 1065 | title: thread.title, |
| 1066 | statusLabel: topStatus?.label ?? null, |
| 1067 | projectDisplayName: props.projectDisplayName, |
| 1068 | isActive: props.isActive, |
| 1069 | }); |
| 1070 | |
| 1071 | const title = isRenaming ? ( |
| 1072 | <ThreadRenameInput |
| 1073 | title={renamingTitle} |
| 1074 | onTitleChange={onRenameTitleChange} |
| 1075 | onCommit={() => onCommitRename(threadRef, renamingTitle)} |
| 1076 | onCancel={onCancelRename} |
| 1077 | /> |
| 1078 | ) : ( |
| 1079 | <span |
| 1080 | ref={isRegeneratingTitle ? observeVisibleAnimation : undefined} |
| 1081 | className={cn( |
| 1082 | "min-w-0 flex-1 text-start text-sm transition-opacity motion-reduce:transition-none", |
| 1083 | shouldRecede ? "font-normal" : "font-medium", |
| 1084 | isRegeneratingTitle |
| 1085 | ? "relative truncate text-muted-foreground" |
| 1086 | : variant !== "slim" |
| 1087 | ? cn( |
| 1088 | "truncate", |
| 1089 | shouldRecede |
| 1090 | ? "text-foreground/75 group-hover/sidebar-row:text-foreground group-focus-visible/sidebar-row:text-foreground" |
| 1091 | : status === "failed" && !isUnread && !isWoke |
| 1092 | ? "text-foreground/95" |
| 1093 | : "text-foreground", |
| 1094 | ) |
| 1095 | : cn( |
| 1096 | "truncate group-focus-within/sidebar-row:text-foreground group-hover/sidebar-row:text-foreground", |
| 1097 | shouldRecede |
| 1098 | ? "text-secondary-label" |
| 1099 | : props.isActive || isWoke || status === "input" || status === "request" |
| 1100 | ? "text-foreground" |
| 1101 | : isUnread |
| 1102 | ? "text-muted-foreground" |
| 1103 | : "text-secondary-label/70", |
| 1104 | ), |
| 1105 | )} |
| 1106 | dir={textDirection(thread.title)} |
| 1107 | > |
| 1108 | {thread.title} |
| 1109 | {isRegeneratingTitle ? ( |
| 1110 | <ActivityShimmerOverlay className="truncate">{thread.title}</ActivityShimmerOverlay> |
| 1111 | ) : null} |
| 1112 | </span> |
| 1113 | ); |
| 1114 | |
| 1115 | const prBadgeShape = supportsMultiplePullRequests |
| 1116 | ? resolveThreadPullRequestBadge(thread.pullRequests) |
| 1117 | : null; |
| 1118 | const openLinkedItems = () => { |
| 1119 | useRightPanelStore.getState().open(threadRef, "pull-requests"); |
| 1120 | if (!props.isRouteThread) onThreadActivate(threadRef); |
| 1121 | }; |
| 1122 | const prBadge = |
| 1123 | prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? ( |
| 1124 | <ThreadPullRequestBadgeControl |
| 1125 | render={<InlineButton />} |
| 1126 | badge={prBadgeShape} |
| 1127 | pullRequests={thread.pullRequests} |
| 1128 | number={pr?.number ?? currentLinkedPr?.number} |
| 1129 | url={pr?.url ?? currentLinkedPr?.url} |
| 1130 | status={prStatus} |
| 1131 | onOpenList={openLinkedItems} |
| 1132 | onOpenPullRequest={handlePrClick} |
| 1133 | /> |
| 1134 | ) : null; |
| 1135 | const firstIssue = thread.issues?.[0]; |
| 1136 | const issueCount = thread.issues?.length ?? 0; |
| 1137 | const issueState = useSidebarLinkedIssueState( |
| 1138 | thread.environmentId, |
| 1139 | leaseLiveStatus ? thread.issues : undefined, |
| 1140 | ); |
| 1141 | const issueStatus = issueState === null ? null : issueStatePresentation(issueState); |
| 1142 | const IssueIcon = issueStatus?.Icon ?? IssueGlyph.issue; |
| 1143 | const issueLabel = |
| 1144 | issueCount === 1 && firstIssue |
| 1145 | ? issueStatus |
| 1146 | ? gt("Issue {key}: {title}, {state}", { |
| 1147 | key: firstIssue.displayKey, |
| 1148 | title: firstIssue.title, |
| 1149 | state: issueStatus.label, |
| 1150 | }) |
| 1151 | : gt("Issue {key}: {title}", { key: firstIssue.displayKey, title: firstIssue.title }) |
| 1152 | : gt("{count, plural, one {{count} linked issue} other {{count} linked issues}}", { |
| 1153 | count: issueCount, |
| 1154 | }); |
| 1155 | const issueBadge = firstIssue ? ( |
| 1156 | <Tooltip> |
| 1157 | <TooltipTrigger |
| 1158 | render={ |
| 1159 | <InlineButton |
| 1160 | tone="muted" |
| 1161 | aria-label={issueLabel} |
| 1162 | onPointerDown={(event) => event.stopPropagation()} |
| 1163 | onClick={(event) => { |
| 1164 | event.stopPropagation(); |
| 1165 | openLinkedItems(); |
| 1166 | }} |
| 1167 | /> |
| 1168 | } |
| 1169 | > |
| 1170 | <IssueIcon aria-hidden className={cn("size-3 shrink-0", issueStatus?.toneClassName)} /> |
| 1171 | <span className="max-w-16 truncate text-xs font-normal text-secondary-label tabular-nums"> |
| 1172 | {issueCount === 1 ? firstIssue.displayKey : issueCount} |
| 1173 | </span> |
| 1174 | </TooltipTrigger> |
| 1175 | <TooltipPopup |
| 1176 | side="top" |
| 1177 | sideOffset={0} |
| 1178 | variant="glass" |
| 1179 | className="pointer-events-auto w-80 max-w-[calc(100vw-2rem)] text-left whitespace-normal" |
| 1180 | onContextMenu={(event) => event.stopPropagation()} |
| 1181 | > |
| 1182 | <div className="-mx-1 max-h-[calc(var(--available-height)-0.5rem-2px)] overflow-y-auto overscroll-contain"> |
| 1183 | <ThreadDetailsIssueRows |
| 1184 | links={thread.issues ?? []} |
| 1185 | threadRef={threadRef} |
| 1186 | compact={false} |
| 1187 | mountScope="sidebar-tooltip" |
| 1188 | onOpen={() => { |
| 1189 | if (!props.isRouteThread) onThreadActivate(threadRef); |
| 1190 | }} |
| 1191 | /> |
| 1192 | </div> |
| 1193 | </TooltipPopup> |
| 1194 | </Tooltip> |
| 1195 | ) : null; |
| 1196 | const terminalStatusIcon = ( |
| 1197 | <ThreadTerminalStatusButton |
| 1198 | threadRef={threadRef} |
| 1199 | terminalIds={runningTerminalIds} |
| 1200 | onThreadActivate={onThreadActivate} |
| 1201 | /> |
| 1202 | ); |
| 1203 | const draftIndicator = hasUnsentDraft ? ( |
| 1204 | <Tooltip> |
| 1205 | <TooltipTrigger |
| 1206 | render={ |
| 1207 | <span |
| 1208 | role="img" |
| 1209 | aria-label={gt("Unsent draft")} |
| 1210 | data-testid={`sidebar-draft-indicator-${thread.id}`} |
| 1211 | className="inline-flex shrink-0 items-center" |
| 1212 | /> |
| 1213 | } |
| 1214 | > |
| 1215 | <SquarePenIcon aria-hidden className={draftPenClassName} /> |
| 1216 | </TooltipTrigger> |
| 1217 | <TooltipPopup side="top"> |
| 1218 | <T>Unsent draft</T> |
| 1219 | </TooltipPopup> |
| 1220 | </Tooltip> |
| 1221 | ) : null; |
| 1222 | const showPin = |
| 1223 | props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null)); |
| 1224 | const pinIndicator = showPin ? ( |
| 1225 | props.pinningSupported && canOperateThread && !sortable?.isDragging ? ( |
| 1226 | <Tooltip> |
| 1227 | <TooltipTrigger |
| 1228 | render={ |
| 1229 | <button |
| 1230 | type="button" |
| 1231 | aria-label={gt("Unpin thread")} |
| 1232 | onClick={handleUnpinClick} |
| 1233 | 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" |
| 1234 | /> |
| 1235 | } |
| 1236 | > |
| 1237 | <PinIcon |
| 1238 | aria-hidden |
| 1239 | className="size-3 shrink-0 group-hover/unpin:hidden group-focus-visible/unpin:hidden" |
| 1240 | /> |
| 1241 | <PinOffIcon |
| 1242 | aria-hidden |
| 1243 | className="hidden size-3 shrink-0 group-hover/unpin:block group-focus-visible/unpin:block" |
| 1244 | /> |
| 1245 | </TooltipTrigger> |
| 1246 | <TooltipPopup> |
| 1247 | <T>Unpin thread</T> |
| 1248 | </TooltipPopup> |
| 1249 | </Tooltip> |
| 1250 | ) : ( |
| 1251 | <PinIcon |
| 1252 | aria-label={gt("Pinned")} |
| 1253 | role="img" |
| 1254 | className="size-3 shrink-0 text-muted-foreground/65" |
| 1255 | /> |
| 1256 | ) |
| 1257 | ) : null; |
| 1258 | |
| 1259 | const remoteMachineIcon = |
| 1260 | isRemote && !showsScratchMachine ? ( |
| 1261 | <span className="inline-flex shrink-0 items-center text-sidebar-muted-foreground/70"> |
| 1262 | <EnvironmentMachineIcon aria-hidden kind={props.environmentMachine} className="size-3.5" /> |
| 1263 | </span> |
| 1264 | ) : null; |
| 1265 | const diff = latestRunDiff(thread); |
| 1266 | // Only the trailing icons would remain, so the row moves them to the title line instead. |
| 1267 | const metaLineEmpty = |
| 1268 | !checkoutThread.branch && |
| 1269 | !showsScratchMachine && |
| 1270 | prBadge === null && |
| 1271 | issueBadge === null && |
| 1272 | diff === null && |
| 1273 | runningTerminalIds.length === 0; |
| 1274 | const metaLine = metaLineEmpty ? null : ( |
| 1275 | <div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs"> |
| 1276 | {checkoutThread.branch ? ( |
| 1277 | <> |
| 1278 | <ThreadWorktreeIndicator thread={checkoutThread} /> |
| 1279 | <span className="flex min-w-0 flex-1"> |
| 1280 | <MiddleTruncate value={checkoutThread.branch} showTitle={false} /> |
| 1281 | </span> |
| 1282 | </> |
| 1283 | ) : showsScratchMachine ? ( |
| 1284 | <> |
| 1285 | <EnvironmentMachineIcon |
| 1286 | aria-hidden |
| 1287 | kind={props.environmentMachine} |
| 1288 | className="size-3 shrink-0" |
| 1289 | /> |
| 1290 | <span className="min-w-0 flex-1 truncate">{props.scratchMachineLabel}</span> |
| 1291 | </> |
| 1292 | ) : ( |
| 1293 | <span className="flex-1" /> |
| 1294 | )} |
| 1295 | {terminalStatusIcon} |
| 1296 | {prBadge} |
| 1297 | {issueBadge} |
| 1298 | {diff ? ( |
| 1299 | <span className="shrink-0 font-mono"> |
| 1300 | <span className="text-diff-addition-foreground">+{formatDiffCount(diff.insertions)}</span>{" "} |
| 1301 | <span className="text-diff-deletion-foreground">−{formatDiffCount(diff.deletions)}</span> |
| 1302 | </span> |
| 1303 | ) : null} |
| 1304 | <span |
| 1305 | aria-hidden |
| 1306 | className="pointer-events-none ml-auto inline-flex shrink-0 items-center gap-1" |
| 1307 | > |
| 1308 | {remoteMachineIcon} |
| 1309 | <SidebarProviderStack |
| 1310 | thread={thread} |
| 1311 | providerEntryByInstanceId={props.providerEntryByInstanceId} |
| 1312 | /> |
| 1313 | </span> |
| 1314 | </div> |
| 1315 | ); |
| 1316 | const titleLineIcons = metaLineEmpty ? ( |
| 1317 | <span aria-hidden className="inline-flex shrink-0 items-center gap-1"> |
| 1318 | {remoteMachineIcon} |
| 1319 | <SidebarProviderStack |
| 1320 | thread={thread} |
| 1321 | providerEntryByInstanceId={props.providerEntryByInstanceId} |
| 1322 | /> |
| 1323 | </span> |
| 1324 | ) : null; |
| 1325 | |
| 1326 | if (variant !== "card") { |
| 1327 | const multiline = variant === "folder-multiline"; |
| 1328 | const inFolder = variant === "folder" || multiline; |
| 1329 | return ( |
| 1330 | <li |
| 1331 | data-thread-item={threadKey} |
| 1332 | {...sortableRootProps} |
| 1333 | {...(fileDropHandlers ?? {})} |
| 1334 | className={cn( |
| 1335 | "list-none [content-visibility:auto] [contain-intrinsic-size:auto_--spacing(9)]", |
| 1336 | metaLine !== null && multiline && "[contain-intrinsic-size:auto_--spacing(13.5)]", |
| 1337 | sortable?.isDragging && "relative z-20", |
| 1338 | )} |
| 1339 | > |
| 1340 | <Tooltip disabled={isRenaming || sortable?.isDragging}> |
| 1341 | <TooltipTrigger |
| 1342 | render={ |
| 1343 | <div |
| 1344 | ref={rowRef} |
| 1345 | role="button" |
| 1346 | tabIndex={0} |
| 1347 | data-sidebar-row={threadKey} |
| 1348 | data-sidebar-parent={props.navigationParent} |
| 1349 | aria-label={accessibility.label} |
| 1350 | aria-current={accessibility.current} |
| 1351 | data-testid={inFolder ? "sidebar-row-folder" : "sidebar-row-slim"} |
| 1352 | aria-busy={isRegeneratingTitle || undefined} |
| 1353 | className={cn( |
| 1354 | rowSurfaceClassName, |
| 1355 | multiline |
| 1356 | ? "flex flex-col justify-center px-2.5 py-1.5" |
| 1357 | : "flex h-9 items-center gap-2.5 px-2.5", |
| 1358 | // Lines titles up with the folder name, past its chevron and icon. |
| 1359 | inFolder && "ps-9", |
| 1360 | )} |
| 1361 | onClick={handleClick} |
| 1362 | onDoubleClick={handleDoubleClick} |
| 1363 | onKeyDown={handleKeyDown} |
| 1364 | onContextMenu={handleContextMenu} |
| 1365 | /> |
| 1366 | } |
| 1367 | > |
| 1368 | {/* `contents` keeps one-line rows a single flex row. */} |
| 1369 | <div className={multiline ? "flex h-6 min-w-0 items-center gap-2.5" : "contents"}> |
| 1370 | {inFolder ? null : ( |
| 1371 | <span |
| 1372 | className={cn( |
| 1373 | "flex shrink-0 items-center transition-opacity", |
| 1374 | (!props.isActive || variantAction === "unsettle") && |
| 1375 | "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", |
| 1376 | )} |
| 1377 | > |
| 1378 | {props.project ? ( |
| 1379 | <ProjectFavicon project={props.project} className="size-4" /> |
| 1380 | ) : null} |
| 1381 | </span> |
| 1382 | )} |
| 1383 | {draftIndicator} |
| 1384 | {title} |
| 1385 | {multiline ? titleLineIcons : null} |
| 1386 | {pinIndicator} |
| 1387 | {multiline ? null : terminalStatusIcon} |
| 1388 | {multiline ? null : issueBadge} |
| 1389 | {isRegeneratingTitle ? ( |
| 1390 | <span role="status" className="sr-only"> |
| 1391 | <T>Regenerating title</T> |
| 1392 | </span> |
| 1393 | ) : null} |
| 1394 | {sortable?.isDragging ? ( |
| 1395 | dragDestination |
| 1396 | ) : ( |
| 1397 | <span |
| 1398 | className={cn( |
| 1399 | "relative ml-auto flex h-6 min-w-8 shrink-0 items-center justify-end", |
| 1400 | props.sweepAction !== null && "hidden", |
| 1401 | jumpHintLabel && JUMP_HINT_SLOT_CLASS_NAME, |
| 1402 | )} |
| 1403 | > |
| 1404 | <span |
| 1405 | className={cn( |
| 1406 | "inline-flex justify-end tabular-nums text-secondary-label transition-opacity", |
| 1407 | !isWoke && "group-any-hover/sidebar-row:opacity-0", |
| 1408 | )} |
| 1409 | > |
| 1410 | {variantAction === "unsnooze" && props.snoozeWakeLabelText !== null ? ( |
| 1411 | <span className="inline-flex items-center gap-1 text-xs text-info-foreground tabular-nums"> |
| 1412 | {/* The clock tells a wake time from an age at a glance. */} |
| 1413 | <AlarmClockIcon aria-hidden className="size-3" /> |
| 1414 | {props.snoozeWakeLabelText} |
| 1415 | </span> |
| 1416 | ) : (inFolder ? isWokeStatus : isWoke) ? ( |
| 1417 | <Tooltip> |
| 1418 | <TooltipTrigger |
| 1419 | render={ |
| 1420 | <button |
| 1421 | type="button" |
| 1422 | aria-label={gt("Dismiss Woke notification")} |
| 1423 | onClick={handleAcknowledgeWokeClick} |
| 1424 | 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" |
| 1425 | > |
| 1426 | <AlarmClockIcon aria-hidden className="size-3" /> |
| 1427 | <span role="status"> |
| 1428 | <T context="thread status: woke from snooze">Woke</T> |
| 1429 | </span> |
| 1430 | </button> |
| 1431 | } |
| 1432 | /> |
| 1433 | <TooltipPopup side="top"> |
| 1434 | <T>Dismiss Woke notification</T> |
| 1435 | </TooltipPopup> |
| 1436 | </Tooltip> |
| 1437 | ) : inFolder && topStatus ? ( |
| 1438 | // Folder rows have no status line, so the status takes the time slot. |
| 1439 | <span |
| 1440 | className={cn( |
| 1441 | "inline-flex items-center gap-1 text-xs font-medium", |
| 1442 | topStatus.className, |
| 1443 | )} |
| 1444 | > |
| 1445 | <TopStatusIcon icon={topStatus.icon} className="size-3" /> |
| 1446 | {topStatus.label} |
| 1447 | </span> |
| 1448 | ) : ( |
| 1449 | <span className="text-xs"> |
| 1450 | <RelativeTimeLabel |
| 1451 | timestamp={ |
| 1452 | variantAction === "unsettle" |
| 1453 | ? resolveSettledThreadTimestamp(thread) |
| 1454 | : resolveThreadActivityTimestamp(thread) |
| 1455 | } |
| 1456 | /> |
| 1457 | </span> |
| 1458 | )} |
| 1459 | </span> |
| 1460 | {variantAction === "unsnooze" ? ( |
| 1461 | !props.snoozeSupported ? null : ( |
| 1462 | <button |
| 1463 | type="button" |
| 1464 | aria-label={gt("Wake thread now")} |
| 1465 | onClick={handleUnsnoozeClick} |
| 1466 | onPointerDown={handleActionPointerDown} |
| 1467 | className={cn( |
| 1468 | "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", |
| 1469 | isWoke && "group-any-hover/sidebar-row:static", |
| 1470 | )} |
| 1471 | > |
| 1472 | <AlarmClockOffIcon className="mb-px size-3" /> |
| 1473 | </button> |
| 1474 | ) |
| 1475 | ) : !props.settlementSupported ? null : variantAction === "unsettle" ? ( |
| 1476 | <Tooltip> |
| 1477 | <TooltipTrigger |
| 1478 | render={ |
| 1479 | <button |
| 1480 | type="button" |
| 1481 | aria-label={gt("Un-settle thread")} |
| 1482 | onClick={handleUnsettleClick} |
| 1483 | onPointerDown={handleActionPointerDown} |
| 1484 | className={cn( |
| 1485 | "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", |
| 1486 | isWoke && "group-any-hover/sidebar-row:static", |
| 1487 | )} |
| 1488 | /> |
| 1489 | } |
| 1490 | > |
| 1491 | <Undo2Icon className="mb-px size-3.5" /> |
| 1492 | </TooltipTrigger> |
| 1493 | <TooltipPopup side="top"> |
| 1494 | <T>Un-settle thread</T> |
| 1495 | </TooltipPopup> |
| 1496 | </Tooltip> |
| 1497 | ) : ( |
| 1498 | <Tooltip> |
| 1499 | <TooltipTrigger |
| 1500 | render={ |
| 1501 | <button |
| 1502 | type="button" |
| 1503 | aria-label={gt("Settle thread")} |
| 1504 | onClick={handleSettleClick} |
| 1505 | onPointerDown={handleActionPointerDown} |
| 1506 | className={cn( |
| 1507 | "pointer-events-none absolute inset-y-0 right-0 -mr-2 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", |
| 1508 | isWoke && "group-any-hover/sidebar-row:static", |
| 1509 | )} |
| 1510 | /> |
| 1511 | } |
| 1512 | > |
| 1513 | <CheckIcon className="size-3" /> |
| 1514 | </TooltipTrigger> |
| 1515 | <TooltipPopup side="top"> |
| 1516 | <T>Settle thread</T> |
| 1517 | </TooltipPopup> |
| 1518 | </Tooltip> |
| 1519 | )} |
| 1520 | {jumpHintLabel ? <JumpHintBadge label={jumpHintLabel} /> : null} |
| 1521 | </span> |
| 1522 | )} |
| 1523 | {props.sweepAction !== null ? dragDestination : null} |
| 1524 | </div> |
| 1525 | {multiline ? metaLine : null} |
| 1526 | </TooltipTrigger> |
| 1527 | {detailsTooltip} |
| 1528 | </Tooltip> |
| 1529 | </li> |
| 1530 | ); |
| 1531 | } |
| 1532 | |
| 1533 | return ( |
| 1534 | <li |
| 1535 | data-thread-item={threadKey} |
| 1536 | {...sortableRootProps} |
| 1537 | {...(fileDropHandlers ?? {})} |
| 1538 | // The hints are the rendered heights inside py-0.5. Revealing the open thread measures rows |
| 1539 | // that have not rendered yet, so a hint off by a pixel lands it a pixel short per row above. |
| 1540 | className={cn( |
| 1541 | "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]", |
| 1542 | metaLineEmpty && "[contain-intrinsic-size:auto_60px]", |
| 1543 | sortable?.isDragging && "relative z-20", |
| 1544 | )} |
| 1545 | > |
| 1546 | <Tooltip disabled={isRenaming || snoozeMenuOpen || sortable?.isDragging}> |
| 1547 | <TooltipTrigger |
| 1548 | render={ |
| 1549 | <div |
| 1550 | ref={rowRef} |
| 1551 | role="button" |
| 1552 | tabIndex={0} |
| 1553 | data-sidebar-row={threadKey} |
| 1554 | data-sidebar-parent={props.navigationParent} |
| 1555 | aria-label={accessibility.label} |
| 1556 | aria-current={accessibility.current} |
| 1557 | data-testid="sidebar-row-card" |
| 1558 | aria-busy={isRegeneratingTitle || undefined} |
| 1559 | className={rowSurfaceClassName} |
| 1560 | onClick={handleClick} |
| 1561 | onDoubleClick={handleDoubleClick} |
| 1562 | onKeyDown={handleKeyDown} |
| 1563 | onContextMenu={handleContextMenu} |
| 1564 | /> |
| 1565 | } |
| 1566 | > |
| 1567 | <div |
| 1568 | className={cn( |
| 1569 | "relative z-10 h-[4.875rem] px-(--sidebar-row-content-inset) py-(--sidebar-content-inset)", |
| 1570 | metaLineEmpty && "h-auto", |
| 1571 | )} |
| 1572 | > |
| 1573 | <div className="flex h-5 min-w-0 items-center gap-1.5"> |
| 1574 | {draftIndicator} |
| 1575 | {props.project ? ( |
| 1576 | <ProjectFavicon project={props.project} className="size-4 shrink-0" /> |
| 1577 | ) : null} |
| 1578 | {/* Left of the status slot, the pin would slide when hover swaps the |
| 1579 | label for the wider row controls. */} |
| 1580 | {pinIndicator} |
| 1581 | {props.projectDisplayName ? ( |
| 1582 | <span |
| 1583 | className={cn("min-w-0 flex-1 truncate font-normal text-secondary-label text-xs")} |
| 1584 | > |
| 1585 | {props.projectDisplayName} |
| 1586 | </span> |
| 1587 | ) : ( |
| 1588 | <span className="flex-1" /> |
| 1589 | )} |
| 1590 | {sortable?.isDragging ? ( |
| 1591 | dragDestination |
| 1592 | ) : ( |
| 1593 | <span |
| 1594 | className={cn( |
| 1595 | "group/sidebar-status-slot relative ml-auto flex h-5 min-w-8 shrink-0 items-stretch justify-end text-xs", |
| 1596 | props.sweepAction !== null && "hidden", |
| 1597 | jumpHintLabel && JUMP_HINT_SLOT_CLASS_NAME, |
| 1598 | )} |
| 1599 | > |
| 1600 | <span |
| 1601 | className={cn( |
| 1602 | isWokeStatus |
| 1603 | ? "pointer-events-auto" |
| 1604 | : "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", |
| 1605 | "flex items-center self-center justify-self-end tabular-nums text-secondary-label", |
| 1606 | snoozeMenuOpen && "pointer-events-none absolute right-0 opacity-0", |
| 1607 | )} |
| 1608 | > |
| 1609 | {topStatus ? ( |
| 1610 | isWokeStatus ? ( |
| 1611 | <Tooltip> |
| 1612 | <TooltipTrigger |
| 1613 | render={ |
| 1614 | <button |
| 1615 | type="button" |
| 1616 | aria-label={gt("Dismiss Woke notification")} |
| 1617 | onClick={handleAcknowledgeWokeClick} |
| 1618 | className={cn( |
| 1619 | "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", |
| 1620 | topStatus.className, |
| 1621 | )} |
| 1622 | > |
| 1623 | <AlarmClockIcon aria-hidden className="size-4 shrink-0" /> |
| 1624 | <span role="status">{topStatus.label}</span> |
| 1625 | </button> |
| 1626 | } |
| 1627 | /> |
| 1628 | <TooltipPopup side="top"> |
| 1629 | <T>Dismiss Woke notification</T> |
| 1630 | </TooltipPopup> |
| 1631 | </Tooltip> |
| 1632 | ) : ( |
| 1633 | <span |
| 1634 | className={cn( |
| 1635 | "inline-flex items-center gap-1 font-medium", |
| 1636 | topStatus.className, |
| 1637 | )} |
| 1638 | > |
| 1639 | <TopStatusIcon icon={topStatus.icon} className="size-4" /> |
| 1640 | {/* Not a live region: a collapsed sidebar is inert, so |
| 1641 | BackgroundThreadAnnouncer and the open thread's |
| 1642 | timeline speak status changes instead. */} |
| 1643 | {topStatus.label} |
| 1644 | {status === "preparing" || status === "working" ? ( |
| 1645 | <span aria-hidden> |
| 1646 | <WorkingDuration |
| 1647 | environmentId={thread.environmentId} |
| 1648 | startedAt={resolveWorkingStartedAt(thread)} |
| 1649 | /> |
| 1650 | </span> |
| 1651 | ) : status === "waiting" ? ( |
| 1652 | <span aria-hidden> |
| 1653 | <WorkingDuration |
| 1654 | environmentId={thread.environmentId} |
| 1655 | startedAt={thread.latestRun?.completedAt ?? null} |
| 1656 | /> |
| 1657 | </span> |
| 1658 | ) : null} |
| 1659 | </span> |
| 1660 | ) |
| 1661 | ) : ( |
| 1662 | <RelativeTimeLabel timestamp={resolveThreadActivityTimestamp(thread)} /> |
| 1663 | )} |
| 1664 | </span> |
| 1665 | {props.settlementSupported || showSnoozeButton || hasUnsentDraft ? ( |
| 1666 | <span |
| 1667 | className={cn( |
| 1668 | // Mouse clicks leave Settle focused; focus-within would pin controls over |
| 1669 | // the status label after the pointer leaves. Use focus-visible instead. |
| 1670 | "pointer-events-none absolute inset-y-0 right-0 flex items-stretch opacity-0 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", |
| 1671 | snoozeMenuOpen && "pointer-events-auto static opacity-100", |
| 1672 | )} |
| 1673 | > |
| 1674 | {hasUnsentDraft ? ( |
| 1675 | <Tooltip> |
| 1676 | <TooltipTrigger |
| 1677 | render={ |
| 1678 | <button |
| 1679 | type="button" |
| 1680 | aria-label={gt("Discard draft")} |
| 1681 | onClick={handleDiscardDraftClick} |
| 1682 | className="inline-flex cursor-pointer items-center rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground" |
| 1683 | /> |
| 1684 | } |
| 1685 | > |
| 1686 | <XIcon className="size-3.5" /> |
| 1687 | </TooltipTrigger> |
| 1688 | <TooltipPopup side="top"> |
| 1689 | <T>Discard draft</T> |
| 1690 | </TooltipPopup> |
| 1691 | </Tooltip> |
| 1692 | ) : null} |
| 1693 | {showSnoozeButton ? ( |
| 1694 | <SnoozeMenuButton |
| 1695 | open={snoozeMenuOpen} |
| 1696 | onOpenChange={setSnoozeMenuOpen} |
| 1697 | onSnooze={handleSnoozePreset} |
| 1698 | timestampFormat={props.timestampFormat} |
| 1699 | environmentId={thread.environmentId} |
| 1700 | /> |
| 1701 | ) : null} |
| 1702 | {props.settlementSupported ? ( |
| 1703 | <Tooltip> |
| 1704 | <TooltipTrigger |
| 1705 | render={ |
| 1706 | <button |
| 1707 | type="button" |
| 1708 | aria-label={gt("Settle thread")} |
| 1709 | onClick={handleSettleClick} |
| 1710 | onPointerDown={handleActionPointerDown} |
| 1711 | 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" |
| 1712 | /> |
| 1713 | } |
| 1714 | > |
| 1715 | <CheckIcon className="size-3.5" /> |
| 1716 | <T>Settle</T> |
| 1717 | </TooltipTrigger> |
| 1718 | <TooltipPopup> |
| 1719 | <T>Settle thread</T> |
| 1720 | </TooltipPopup> |
| 1721 | </Tooltip> |
| 1722 | ) : null} |
| 1723 | </span> |
| 1724 | ) : null} |
| 1725 | {jumpHintLabel ? <JumpHintBadge label={jumpHintLabel} /> : null} |
| 1726 | </span> |
| 1727 | )} |
| 1728 | {props.sweepAction !== null ? dragDestination : null} |
| 1729 | </div> |
| 1730 | <div className="mt-1 flex min-w-0 items-center gap-1.5"> |
| 1731 | {title} |
| 1732 | {isRegeneratingTitle ? ( |
| 1733 | <span role="status" className="sr-only"> |
| 1734 | <T>Regenerating title</T> |
| 1735 | </span> |
| 1736 | ) : null} |
| 1737 | {titleLineIcons} |
| 1738 | </div> |
| 1739 | {metaLine} |
| 1740 | </div> |
| 1741 | </TooltipTrigger> |
| 1742 | {detailsTooltip} |
| 1743 | </Tooltip> |
| 1744 | </li> |
| 1745 | ); |
| 1746 | }); |
| 1747 | |
| 1748 | function latestRunDiff( |
| 1749 | thread: SidebarThreadSummary, |
| 1750 | ): { insertions: number; deletions: number } | null { |
| 1751 | void thread; |
| 1752 | return null; |
| 1753 | } |
| 1754 | |
| 1755 | // Attached only to the highlighted result, so React calls it each time the |
| 1756 | // highlight lands on a different row: a new query, late rows replacing the first |
| 1757 | // result, or arrow keys moving past the scrolled edge. |
| 1758 | const scrollHighlightedResultIntoView = (node: HTMLLIElement | null) => { |
| 1759 | node?.scrollIntoView({ block: "nearest" }); |
| 1760 | }; |
| 1761 | |
| 1762 | export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: { |
| 1763 | isSettled: boolean; |
| 1764 | thread: SidebarThreadSummary; |
| 1765 | project: EnvironmentProject | null; |
| 1766 | projectDisplayName: string | null; |
| 1767 | environmentLabel: string | null; |
| 1768 | environmentMachine: EnvironmentMachineKind; |
| 1769 | providerEntryByInstanceId: ReadonlyMap<string, SidebarProviderEntry>; |
| 1770 | isHighlighted: boolean; |
| 1771 | isRouteActive: boolean; |
| 1772 | resultId: string; |
| 1773 | searchMatch: EnvironmentThreadSearchMatch | null; |
| 1774 | searchQuery: string; |
| 1775 | /** The query `searchMatch` was found for, which lags `searchQuery` while a search runs. */ |
| 1776 | searchMatchQuery?: string; |
| 1777 | onHighlight: () => void; |
| 1778 | onSelect: () => void; |
| 1779 | onContextMenu: ( |
| 1780 | threadRef: ScopedThreadRef, |
| 1781 | position: { x: number; y: number }, |
| 1782 | source: ContextMenuSource, |
| 1783 | ) => void; |
| 1784 | onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void; |
| 1785 | }) { |
| 1786 | const messages = useMessages(); |
| 1787 | const thread = |
| 1788 | useThreadShell(scopeThreadRef(props.thread.environmentId, props.thread.id)) ?? props.thread; |
| 1789 | const accessibility = resolveSidebarRowAccessibility({ |
| 1790 | title: thread.title, |
| 1791 | statusLabel: null, |
| 1792 | projectDisplayName: props.projectDisplayName, |
| 1793 | isActive: props.isRouteActive, |
| 1794 | }); |
| 1795 | const threadRef = scopeThreadRef(thread.environmentId, thread.id); |
| 1796 | // Results only drag out as chat context; the row keeps its own listbox attributes. |
| 1797 | const { listeners: dragListeners, setNodeRef: setDragNodeRef } = useDraggable({ |
| 1798 | id: scopedThreadKey(threadRef), |
| 1799 | }); |
| 1800 | const { leaseLiveStatus, rowRef: leaseRowRef } = useSidebarRowSubscriptionLease( |
| 1801 | props.isHighlighted || props.isRouteActive, |
| 1802 | ); |
| 1803 | const isRegeneratingTitle = thread.titleRegeneration != null; |
| 1804 | const rowRef = (row: HTMLElement | null) => { |
| 1805 | setDragNodeRef(row); |
| 1806 | return leaseRowRef(row); |
| 1807 | }; |
| 1808 | const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null; |
| 1809 | const branchTarget = |
| 1810 | leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null |
| 1811 | ? { environmentId: thread.environmentId, cwd: gitCwd } |
| 1812 | : null; |
| 1813 | const gitStatus = useEnvironmentQuery( |
| 1814 | branchTarget === null |
| 1815 | ? null |
| 1816 | : vcsEnvironment.branch({ |
| 1817 | environmentId: branchTarget.environmentId, |
| 1818 | input: { cwd: branchTarget.cwd }, |
| 1819 | }), |
| 1820 | ); |
| 1821 | useAtomMount(vcsBranchRevalidation(branchTarget)); |
| 1822 | const visibleGitStatus = useRetainedValue( |
| 1823 | JSON.stringify([thread.environmentId, gitCwd]), |
| 1824 | gitStatus.data, |
| 1825 | ); |
| 1826 | const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus); |
| 1827 | const branchMismatch = resolveLocalCheckoutBranchMismatch({ |
| 1828 | effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree", |
| 1829 | activeWorktreePath: thread.worktreePath, |
| 1830 | activeThreadBranch: thread.branch, |
| 1831 | currentGitBranch: visibleGitStatus?.refName ?? null, |
| 1832 | }); |
| 1833 | const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId; |
| 1834 | const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null; |
| 1835 | const showInstanceBadge = |
| 1836 | providerEntry !== null && |
| 1837 | shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values()); |
| 1838 | const selectedModel = providerEntry?.models.find( |
| 1839 | (model) => model.slug === thread.modelSelection.model, |
| 1840 | ); |
| 1841 | const modelLabel = selectedModel |
| 1842 | ? getTriggerDisplayModelName(selectedModel, providerEntry?.driverKind) |
| 1843 | : thread.modelSelection.model; |
| 1844 | const runningTerminalIds = useThreadRunningTerminalIds({ |
| 1845 | environmentId: thread.environmentId, |
| 1846 | threadId: thread.id, |
| 1847 | }); |
| 1848 | const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds, messages); |
| 1849 | const [isFileDragOver, setIsFileDragOver] = useState(false); |
| 1850 | const onFileDropThreads = props.onFileDropThreads; |
| 1851 | const fileDropHandlers = makeWorkspaceFileDropHandlers({ |
| 1852 | setDragActive: (active) => setFileDragActive(setIsFileDragOver, active), |
| 1853 | addFiles: (files) => { |
| 1854 | onFileDropThreads(threadRef, files); |
| 1855 | }, |
| 1856 | addFolders: () => {}, |
| 1857 | }); |
| 1858 | return ( |
| 1859 | <li |
| 1860 | ref={props.isHighlighted ? scrollHighlightedResultIntoView : undefined} |
| 1861 | role="presentation" |
| 1862 | className="list-none" |
| 1863 | {...fileDropHandlers} |
| 1864 | > |
| 1865 | <Tooltip> |
| 1866 | <TooltipTrigger |
| 1867 | render={ |
| 1868 | <button |
| 1869 | ref={rowRef} |
| 1870 | id={props.resultId} |
| 1871 | type="button" |
| 1872 | role="option" |
| 1873 | tabIndex={-1} |
| 1874 | aria-selected={props.isHighlighted} |
| 1875 | aria-current={accessibility.current} |
| 1876 | aria-describedby={`${props.resultId}-pr`} |
| 1877 | aria-label={accessibility.label} |
| 1878 | {...dragListeners} |
| 1879 | onMouseMove={props.onHighlight} |
| 1880 | // Focus stays in the search box, as for Enter. A focused result would lose focus as |
| 1881 | // the results close, and its recovery scrolls the list away from the opened thread. |
| 1882 | // dnd-kit ignores a prevented press, so the drag listener runs first. |
| 1883 | onPointerDown={(event) => { |
| 1884 | dragListeners?.onPointerDown?.(event); |
| 1885 | event.preventDefault(); |
| 1886 | }} |
| 1887 | onClick={props.onSelect} |
| 1888 | onContextMenu={(event) => { |
| 1889 | event.preventDefault(); |
| 1890 | props.onContextMenu( |
| 1891 | threadRef, |
| 1892 | { x: event.clientX, y: event.clientY }, |
| 1893 | contextMenuSourceOf(event), |
| 1894 | ); |
| 1895 | }} |
| 1896 | className={cn( |
| 1897 | "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", |
| 1898 | props.isHighlighted || props.isRouteActive |
| 1899 | ? "bg-sidebar-row-active text-sidebar-foreground" |
| 1900 | : "text-sidebar-muted-foreground/75 hover:bg-sidebar-row-hover hover:text-sidebar-foreground", |
| 1901 | isFileDragOver && "ring-1 ring-inset ring-primary/70", |
| 1902 | isFileDragOver && !props.isRouteActive && "bg-sidebar-row-hover", |
| 1903 | )} |
| 1904 | /> |
| 1905 | } |
| 1906 | > |
| 1907 | {props.project ? ( |
| 1908 | <ProjectFavicon |
| 1909 | project={props.project} |
| 1910 | className={cn( |
| 1911 | "size-4 shrink-0 transition-opacity", |
| 1912 | props.isSettled && |
| 1913 | !props.isRouteActive && |
| 1914 | !props.isHighlighted && |
| 1915 | "opacity-40 grayscale group-hover/sidebar-row:opacity-100 group-hover/sidebar-row:grayscale-0", |
| 1916 | )} |
| 1917 | /> |
| 1918 | ) : null} |
| 1919 | <span className="flex min-w-0 flex-1 flex-col"> |
| 1920 | <span className="flex min-w-0 items-center gap-2.5"> |
| 1921 | <span |
| 1922 | ref={isRegeneratingTitle ? observeVisibleAnimation : undefined} |
| 1923 | className={cn( |
| 1924 | "min-w-0 flex-1 truncate", |
| 1925 | props.isSettled ? "font-normal" : "font-medium", |
| 1926 | isRegeneratingTitle |
| 1927 | ? "relative text-muted-foreground" |
| 1928 | : props.isSettled && !props.isHighlighted && !props.isRouteActive |
| 1929 | ? "text-secondary-label/70 group-hover/sidebar-row:text-foreground" |
| 1930 | : "text-foreground", |
| 1931 | )} |
| 1932 | > |
| 1933 | {thread.title} |
| 1934 | {isRegeneratingTitle ? ( |
| 1935 | <ActivityShimmerOverlay className="truncate"> |
| 1936 | {thread.title} |
| 1937 | </ActivityShimmerOverlay> |
| 1938 | ) : null} |
| 1939 | </span> |
| 1940 | <span id={`${props.resultId}-pr`} className="contents"> |
| 1941 | <ThreadSearchPullRequestNumber |
| 1942 | thread={thread} |
| 1943 | query={props.searchQuery} |
| 1944 | enabled={leaseLiveStatus} |
| 1945 | settled={props.isSettled} |
| 1946 | /> |
| 1947 | </span> |
| 1948 | <span className="w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums"> |
| 1949 | <RelativeTimeLabel timestamp={resolveThreadActivityTimestamp(thread)} /> |
| 1950 | </span> |
| 1951 | </span> |
| 1952 | {props.searchMatch ? ( |
| 1953 | <ThreadSearchMatchExcerpt |
| 1954 | match={{ |
| 1955 | source: props.searchMatch.source, |
| 1956 | snippet: props.searchMatch.snippet, |
| 1957 | query: props.searchMatchQuery ?? props.searchQuery, |
| 1958 | }} |
| 1959 | /> |
| 1960 | ) : null} |
| 1961 | </span> |
| 1962 | </TooltipTrigger> |
| 1963 | <SidebarThreadTooltip |
| 1964 | thread={checkoutThread} |
| 1965 | project={props.project} |
| 1966 | projectDisplayName={props.projectDisplayName} |
| 1967 | environmentLabel={props.environmentLabel} |
| 1968 | environmentMachine={props.environmentMachine} |
| 1969 | providerEntry={providerEntry} |
| 1970 | providerEntryByInstanceId={props.providerEntryByInstanceId} |
| 1971 | showInstanceBadge={showInstanceBadge} |
| 1972 | modelInstanceId={modelInstanceId} |
| 1973 | modelLabel={modelLabel} |
| 1974 | branchMismatch={branchMismatch} |
| 1975 | terminalStatus={terminalStatus} |
| 1976 | terminalProcessCount={runningTerminalIds.length} |
| 1977 | /> |
| 1978 | </Tooltip> |
| 1979 | </li> |
| 1980 | ); |
| 1981 | }); |