Open History to see the last commit
1import type { ContextMenuItem, PreviewSessionSnapshot, PullRequestState } from "@t3tools/contracts";
2import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
3import {
4 Bot,
5 FileDiff,
6 Files,
7 GitPullRequest,
8 Globe2,
9 Plus,
10 TerminalSquare,
11 X,
12} from "lucide-react";
13import {
14 type KeyboardEvent as ReactKeyboardEvent,
15 type MouseEvent as ReactMouseEvent,
16 type ReactElement,
17 type ReactNode,
18 useCallback,
19 useEffect,
20 useRef,
21 useState,
22} from "react";
23
24import { isElectron } from "~/env";
25import type { DesktopPreviewOverlay } from "~/previewStateStore";
26import type { RightPanelSurface } from "~/rightPanelStore";
27import { cn } from "~/lib/utils";
28import { readLocalApi } from "~/localApi";
29import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
30import { Kbd } from "~/components/ui/kbd";
31import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
32import { ScrollArea } from "~/components/ui/scroll-area";
33import { faviconUrlForOrigin } from "~/lib/favicon";
34import { useTheme } from "~/hooks/useTheme";
35import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
36
37import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
38import { FaviconImage } from "./preview/PreviewFaviconIcon";
39import { PierreEntryIcon } from "./chat/PierreEntryIcon";
40
41interface RightPanelTabsProps {
42 mode: PreviewPanelMode;
43 maximized?: boolean;
44 /** Forwarded to PreviewPanelShell so this surface persists its own width. */
45 widthStorageKey?: string;
46 /** Forwarded to PreviewPanelShell as the initial width before a user resize. */
47 defaultWidth?: number;
48 layoutControls?: ReactNode;
49 surfaces: readonly RightPanelSurface[];
50 activeSurfaceId: string | null;
51 pendingSurfaceIds: ReadonlySet<string>;
52 previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
53 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
54 terminalLabelsById: ReadonlyMap<string, string>;
55 onActivate: (surface: RightPanelSurface) => void;
56 onCloseSurface: (surface: RightPanelSurface) => void;
57 onCloseOtherSurfaces: (surface: RightPanelSurface) => void;
58 onCloseSurfacesToRight: (surface: RightPanelSurface) => void;
59 onCloseAllSurfaces: () => void;
60 onCopyFilePath: (relativePath: string) => void;
61 onAddBrowser: () => void;
62 onAddTerminal: () => void;
63 onAddDiff: () => void;
64 onAddFiles: () => void;
65 onAddPullRequest: () => void;
66 onAddAgents: () => void;
67 browserAvailable: boolean;
68 terminalAvailable: boolean;
69 diffAvailable: boolean;
70 filesAvailable: boolean;
71 pullRequestAvailable: boolean;
72 agentsAvailable: boolean;
73 pullRequestStatuses?: Readonly<Record<string, PullRequestTabStatus>>;
74 /** Running + waiting subagents; badges the Agents card in the empty state. */
75 liveAgentCount: number;
76 children: ReactNode;
77}
78
79export interface PullRequestTabStatus {
80 projectId: string;
81 repository: string;
82 number: number;
83 state: PullRequestState;
84 isDraft: boolean;
85}
86
87const SURFACE_DISABLED_REASONS = {
88 browser: "Browser previews are only available in the T3 Code desktop app.",
89 terminal: "Terminal surfaces are only available from a project thread.",
90 files: "Files are only available when a project is open.",
91 diff: "Diff is only available for server threads in Git repositories.",
92 pullRequest: "This thread's branch has no pull request yet.",
93 agents: "Agents are only available from a thread.",
94} as const;
95
96/** Overlays that must win over the launcher's letter shortcuts. */
97const LAUNCHER_SHORTCUT_BLOCKING_LAYERS = [
98 '[data-slot="dialog-popup"]',
99 '[data-slot="alert-dialog-popup"]',
100 '[data-slot="command-dialog-popup"]',
101 '[data-slot="menu-popup"]',
102 '[data-slot="select-popup"]',
103 '[data-slot="popover-popup"]',
104 '[data-slot="combobox-popup"]',
105 '[data-slot="autocomplete-popup"]',
106].join(",");
107
108/** One-line unavailability hints for the empty-state cards. */
109const SURFACE_UNAVAILABLE_HINTS = {
110 browser: "Only available in the desktop app.",
111 terminal: "Available when a project is open.",
112 files: "Available when a project is open.",
113 diff: "Available for Git repositories.",
114 pullRequest: "No pull request on this branch yet.",
115 agents: "Available from a thread.",
116} as const;
117
118type TabContextMenuAction = "copy-path" | "close" | "close-others" | "close-to-right" | "close-all";
119
120function DisabledReasonTooltip(props: { reason: string; trigger: ReactElement }) {
121 return (
122 <Tooltip>
123 <TooltipTrigger render={props.trigger} />
124 <TooltipPopup side="top">{props.reason}</TooltipPopup>
125 </Tooltip>
126 );
127}
128
129function SurfaceMenuItem(props: {
130 available: boolean;
131 disabledReason?: string;
132 onClick: () => void;
133 children: ReactNode;
134}) {
135 const item = (
136 <MenuItem
137 className={!props.available ? "data-disabled:pointer-events-auto" : undefined}
138 onClick={props.onClick}
139 disabled={!props.available}
140 >
141 {props.children}
142 </MenuItem>
143 );
144 if (props.available || !props.disabledReason) return item;
145 return <DisabledReasonTooltip reason={props.disabledReason} trigger={item} />;
146}
147
148/**
149 * Card launcher shown when the right panel has no surfaces. Keyboard-first
150 * without palette chrome: a surface's letter opens it directly from anywhere
151 * outside a typing context, and arrows plus Enter work while the launcher is
152 * focused. The highlight only appears on hover or arrow use. Unavailable
153 * surfaces stay visible with a one-line reason.
154 */
155function RightPanelEmptyState(props: {
156 onAddBrowser: () => void;
157 onAddTerminal: () => void;
158 onAddDiff: () => void;
159 onAddFiles: () => void;
160 onAddPullRequest: () => void;
161 onAddAgents: () => void;
162 browserAvailable: boolean;
163 terminalAvailable: boolean;
164 diffAvailable: boolean;
165 filesAvailable: boolean;
166 pullRequestAvailable: boolean;
167 agentsAvailable: boolean;
168 liveAgentCount: number;
169}) {
170 // -1 means no highlight: it only appears on hover or arrow use.
171 const [highlight, setHighlight] = useState(-1);
172
173 const actions = [
174 {
175 label: "Browser",
176 description: "Open a local app or URL.",
177 icon: Globe2,
178 shortcut: "B",
179 available: props.browserAvailable,
180 disabledReason: SURFACE_UNAVAILABLE_HINTS.browser,
181 onClick: props.onAddBrowser,
182 badgeCount: 0,
183 },
184 {
185 label: "Terminal",
186 description: "Start a shell in this workspace.",
187 icon: TerminalSquare,
188 shortcut: "T",
189 available: props.terminalAvailable,
190 disabledReason: SURFACE_UNAVAILABLE_HINTS.terminal,
191 onClick: props.onAddTerminal,
192 badgeCount: 0,
193 },
194 {
195 label: "Files",
196 description: "Browse and read workspace files.",
197 icon: Files,
198 shortcut: "F",
199 available: props.filesAvailable,
200 disabledReason: SURFACE_UNAVAILABLE_HINTS.files,
201 onClick: props.onAddFiles,
202 badgeCount: 0,
203 },
204 {
205 label: "Diff",
206 description: "Review changes in this thread.",
207 icon: FileDiff,
208 shortcut: "D",
209 available: props.diffAvailable,
210 disabledReason: SURFACE_UNAVAILABLE_HINTS.diff,
211 onClick: props.onAddDiff,
212 badgeCount: 0,
213 },
214 {
215 label: "Pull request",
216 description: "Open this branch's pull request.",
217 icon: GitPullRequest,
218 shortcut: "P",
219 available: props.pullRequestAvailable,
220 disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
221 onClick: props.onAddPullRequest,
222 badgeCount: 0,
223 },
224 {
225 label: "Agents",
226 description: "Follow subagents and workflows.",
227 icon: Bot,
228 shortcut: "A",
229 available: props.agentsAvailable,
230 disabledReason: SURFACE_UNAVAILABLE_HINTS.agents,
231 onClick: props.onAddAgents,
232 badgeCount: props.liveAgentCount,
233 },
234 ] as const;
235
236 type SurfaceAction = (typeof actions)[number];
237
238 const availableActions = actions.filter((action) => action.available);
239 const highlightIndex =
240 availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
241
242 // Letter shortcuts work while the launcher is visible, not only while it
243 // is focused; focus moves around too easily (stray clicks) to carry them.
244 // Capture phase so app-level key handlers cannot swallow the event first;
245 // typing contexts and already-handled events are left alone.
246 const shortcutActionsRef = useRef(availableActions);
247 useEffect(() => {
248 shortcutActionsRef.current = availableActions;
249 });
250 useEffect(() => {
251 const handler = (event: KeyboardEvent) => {
252 if (event.defaultPrevented || event.isComposing) return;
253 if (event.metaKey || event.ctrlKey || event.altKey) return;
254 if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
255 const target = event.target;
256 if (target instanceof HTMLElement) {
257 if (target.closest("input, textarea, select")) return;
258 // An empty contenteditable (the chat composer at rest) does not
259 // count as typing; letters only become text once a draft exists.
260 const editable = target.isContentEditable ? target : target.closest("[contenteditable]");
261 if (editable && (editable.textContent ?? "").trim().length > 0) return;
262 }
263 const action = shortcutActionsRef.current.find(
264 (candidate) => candidate.shortcut.toLowerCase() === event.key.toLowerCase(),
265 );
266 if (!action) return;
267 event.preventDefault();
268 event.stopPropagation();
269 action.onClick();
270 };
271 window.addEventListener("keydown", handler, true);
272 return () => window.removeEventListener("keydown", handler, true);
273 }, []);
274
275 const handleKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
276 if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return;
277 if (availableActions.length === 0) return;
278 if (event.key === "ArrowDown" || event.key === "ArrowRight") {
279 event.preventDefault();
280 setHighlight((highlightIndex + 1) % availableActions.length);
281 return;
282 }
283 if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
284 event.preventDefault();
285 setHighlight(
286 highlightIndex === -1
287 ? availableActions.length - 1
288 : (highlightIndex - 1 + availableActions.length) % availableActions.length,
289 );
290 return;
291 }
292 if (event.key === "Enter") {
293 // A focused card button owns its own activation; only open from the
294 // highlight when the container itself has focus.
295 if (event.target instanceof HTMLElement && event.target.closest("button")) return;
296 const action = availableActions[highlightIndex];
297 if (!action) return;
298 event.preventDefault();
299 action.onClick();
300 }
301 };
302
303 // Stable identity so React only runs this callback ref on mount/unmount;
304 // an inline arrow would re-attach and re-focus on every render.
305 const focusOnMount = useCallback((node: HTMLDivElement | null) => {
306 node?.focus();
307 }, []);
308
309 const isHighlighted = (action: SurfaceAction) =>
310 highlightIndex !== -1 && availableActions[highlightIndex] === action;
311
312 const actionIcon = (action: SurfaceAction, iconClassName = "size-4") => {
313 const Icon = action.icon;
314 return (
315 <span className="relative inline-flex shrink-0">
316 <Icon className={iconClassName} />
317 {action.badgeCount > 0 ? (
318 <span
319 aria-hidden
320 className="absolute -top-1.5 -right-2 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-info px-1 text-[9px] font-semibold tabular-nums text-white"
321 >
322 {action.badgeCount}
323 </span>
324 ) : null}
325 </span>
326 );
327 };
328
329 const cardShellClass =
330 "rounded-lg border border-border/80 bg-card dark:border-transparent dark:shadow-none dark:inset-ring-1 dark:inset-ring-white/5";
331 const highlightedCardClass = "bg-accent/60 dark:inset-ring-white/20";
332
333 return (
334 <div
335 ref={focusOnMount}
336 tabIndex={0}
337 onKeyDown={handleKeyDown}
338 aria-label="Open a surface"
339 data-surface-launcher-keys={availableActions.map((action) => action.shortcut).join("")}
340 className={cn(
341 "flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 pt-6 outline-none",
342 // The panel topbar sits above this container; matching bottom padding
343 // keeps the cards centered against the full panel, not the leftover.
344 "pb-[calc(var(--workspace-topbar-height)+--spacing(6))]",
345 )}
346 >
347 <div className="relative w-full max-w-lg">
348 <div className="absolute inset-x-0 bottom-full mb-5 text-center">
349 <h3 className="font-medium text-foreground text-sm">Open a surface</h3>
350 <p className="mt-1 text-muted-foreground text-xs">
351 Choose what to show in the right panel.
352 </p>
353 </div>
354 <div className="grid grid-cols-2 gap-2">
355 {actions.map((action) =>
356 action.available ? (
357 <button
358 key={action.label}
359 type="button"
360 onClick={action.onClick}
361 onMouseEnter={() => setHighlight(availableActions.indexOf(action))}
362 onMouseLeave={() =>
363 setHighlight((current) =>
364 current === availableActions.indexOf(action) ? -1 : current,
365 )
366 }
367 className={cn(
368 "relative flex w-full cursor-pointer flex-col items-start p-4 text-left transition hover:border-border hover:bg-accent/60",
369 cardShellClass,
370 isHighlighted(action) && highlightedCardClass,
371 )}
372 >
373 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
374 <span className="flex items-center gap-2 pe-8">
375 {actionIcon(action)}
376 <span className="font-medium text-sm">{action.label}</span>
377 </span>
378 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
379 {action.description}
380 </span>
381 </button>
382 ) : (
383 <div
384 key={action.label}
385 className={cn(
386 "relative flex w-full flex-col items-start p-4 opacity-40",
387 cardShellClass,
388 )}
389 >
390 <Kbd className="absolute top-3 right-3">{action.shortcut}</Kbd>
391 <span className="flex items-center gap-2 pe-8">
392 {actionIcon(action)}
393 <span className="font-medium text-sm">{action.label}</span>
394 </span>
395 <span className="mt-1.5 text-muted-foreground text-xs leading-relaxed">
396 {action.disabledReason}
397 </span>
398 </div>
399 ),
400 )}
401 </div>
402 </div>
403 </div>
404 );
405}
406
407function surfaceTitle(
408 surface: RightPanelSurface,
409 sessions: Readonly<Record<string, PreviewSessionSnapshot>>,
410 terminalLabelsById: ReadonlyMap<string, string>,
411): string {
412 switch (surface.kind) {
413 case "diff":
414 return "Diff";
415 case "files":
416 return "Files";
417 case "file":
418 return surface.relativePath.slice(surface.relativePath.lastIndexOf("/") + 1);
419 case "terminal":
420 return (
421 terminalLabelsById.get(surface.activeTerminalId) ??
422 getTerminalLabel(surface.activeTerminalId)
423 );
424 case "pull-request":
425 return `#${surface.number}`;
426 case "agents":
427 return "Agents";
428 case "preview": {
429 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
430 if (!snapshot || snapshot.navStatus._tag === "Idle") return "Browser";
431 if (snapshot.navStatus.title.trim().length > 0) return snapshot.navStatus.title;
432 try {
433 return new URL(snapshot.navStatus.url).host || "Browser";
434 } catch {
435 return "Browser";
436 }
437 }
438 }
439}
440
441function PreviewFavicon({ capturedUrl, url }: { capturedUrl: string | null; url: string | null }) {
442 const publicProviderUrl = faviconUrlForOrigin(url, 32);
443 return (
444 <FaviconImage
445 sources={[capturedUrl, publicProviderUrl]}
446 fallback={<Globe2 className="size-3 shrink-0" />}
447 className="size-3 shrink-0 rounded-sm object-contain"
448 />
449 );
450}
451
452function sameOrigin(left: string, right: string): boolean {
453 try {
454 return new URL(left).origin === new URL(right).origin;
455 } catch {
456 return false;
457 }
458}
459
460function SurfaceIcon({
461 surface,
462 sessions,
463 desktopByTabId,
464 theme,
465 pullRequestStatuses,
466}: {
467 surface: RightPanelSurface;
468 sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
469 desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
470 theme: "light" | "dark";
471 pullRequestStatuses: Readonly<Record<string, PullRequestTabStatus>> | undefined;
472}) {
473 switch (surface.kind) {
474 case "preview": {
475 const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
476 const url = !snapshot || snapshot.navStatus._tag === "Idle" ? null : snapshot.navStatus.url;
477 const favicon = snapshot ? (desktopByTabId[snapshot.tabId]?.favicon ?? null) : null;
478 const capturedUrl =
479 favicon && url && sameOrigin(favicon.pageUrl, url) ? favicon.dataUrl : null;
480 return <PreviewFavicon capturedUrl={capturedUrl} url={url} />;
481 }
482 case "diff":
483 return <FileDiff className="size-3 shrink-0" />;
484 case "files":
485 return <Files className="size-3 shrink-0" />;
486 case "file":
487 return (
488 <PierreEntryIcon
489 pathValue={surface.relativePath}
490 kind="file"
491 theme={theme}
492 className="size-3"
493 />
494 );
495 case "terminal":
496 return <TerminalSquare className="size-3 shrink-0" />;
497 case "pull-request": {
498 const status = pullRequestStatuses?.[surface.id] ?? null;
499 const toneClassName =
500 status?.state === "merged"
501 ? "text-violet-600 dark:text-violet-300/90"
502 : status?.state === "closed"
503 ? "text-red-600 dark:text-red-300/90"
504 : status?.isDraft
505 ? "text-zinc-500 dark:text-zinc-400/80"
506 : status?.state === "open"
507 ? "text-emerald-600 dark:text-emerald-300/90"
508 : "text-muted-foreground";
509 return <GitPullRequest className={cn("size-3 shrink-0", toneClassName)} />;
510 }
511 case "agents":
512 return <Bot className="size-3 shrink-0" />;
513 }
514}
515
516export function RightPanelTabs(props: RightPanelTabsProps) {
517 const ownsDesktopTitleBar = isElectron && props.mode === "inline";
518 const { resolvedTheme } = useTheme();
519 const tabListRef = useRef<HTMLDivElement>(null);
520
521 const handleTabContextMenu = useCallback(
522 async (event: ReactMouseEvent, surface: RightPanelSurface) => {
523 event.preventDefault();
524 event.stopPropagation();
525
526 const api = readLocalApi();
527 if (!api) return;
528
529 const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
530 if (surfaceIndex < 0) return;
531
532 const items: ContextMenuItem<TabContextMenuAction>[] = [];
533 if (surface.kind === "file") {
534 items.push({ id: "copy-path", label: "Copy path" });
535 }
536 items.push(
537 { id: "close", label: "Close" },
538 {
539 id: "close-others",
540 label: "Close others",
541 disabled: props.surfaces.length <= 1,
542 },
543 {
544 id: "close-to-right",
545 label: "Close to the right",
546 disabled: surfaceIndex >= props.surfaces.length - 1,
547 },
548 {
549 id: "close-all",
550 label: "Close all",
551 disabled: props.surfaces.length === 0,
552 },
553 );
554
555 const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
556 switch (action) {
557 case "copy-path":
558 if (surface.kind === "file") props.onCopyFilePath(surface.relativePath);
559 break;
560 case "close":
561 props.onCloseSurface(surface);
562 break;
563 case "close-others":
564 props.onCloseOtherSurfaces(surface);
565 break;
566 case "close-to-right":
567 props.onCloseSurfacesToRight(surface);
568 break;
569 case "close-all":
570 props.onCloseAllSurfaces();
571 break;
572 case null:
573 break;
574 }
575 },
576 [props],
577 );
578 const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
579 if (event.button !== 1) return;
580 event.preventDefault();
581 }, []);
582 const handleTabAuxClick = useCallback(
583 (event: ReactMouseEvent, surface: RightPanelSurface) => {
584 if (event.button !== 1) return;
585 event.preventDefault();
586 event.stopPropagation();
587 props.onCloseSurface(surface);
588 },
589 [props],
590 );
591
592 useEffect(() => {
593 const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
594 activeTab?.scrollIntoView({ block: "nearest", inline: "nearest" });
595 }, [props.activeSurfaceId]);
596
597 return (
598 <PreviewPanelShell
599 mode={props.mode}
600 {...(props.maximized !== undefined ? { maximized: props.maximized } : {})}
601 {...(props.widthStorageKey !== undefined ? { widthStorageKey: props.widthStorageKey } : {})}
602 {...(props.defaultWidth !== undefined ? { defaultWidth: props.defaultWidth } : {})}
603 >
604 <div
605 className={cn(
606 "workspace-topbar gap-1 pl-2",
607 // The sheet overlays from the viewport top, so its tab bar keeps
608 // the titlebar's height: a compact row re-centers the layout
609 // controls a few pixels higher and the cluster jumps on open.
610 props.mode === "inline" && !props.layoutControls ? "pr-28" : "pr-3",
611 ownsDesktopTitleBar && "wco:pr-[calc(var(--workspace-native-controls-inset)+6rem)]",
612 props.mode === "inline" && props.maximized && COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS,
613 )}
614 data-right-panel-tabbar
615 >
616 <ScrollArea
617 ref={tabListRef}
618 hideScrollbars
619 scrollFade
620 className={cn("min-w-0 flex-1 rounded-none", ownsDesktopTitleBar && "drag-region")}
621 data-right-panel-tab-list
622 >
623 <div className="flex h-full w-max min-w-full items-center gap-1">
624 {props.surfaces.map((surface) => {
625 const active = surface.id === props.activeSurfaceId;
626 const pending = props.pendingSurfaceIds.has(surface.id);
627 const title = surfaceTitle(surface, props.previewSessions, props.terminalLabelsById);
628 return (
629 <div
630 key={surface.id}
631 data-active-tab={active}
632 onMouseDown={handleTabMouseDown}
633 onAuxClick={(event) => handleTabAuxClick(event, surface)}
634 onContextMenu={(event) => void handleTabContextMenu(event, surface)}
635 className={cn(
636 "cursor-pointer group/tab flex h-6 max-w-36 shrink-0 items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
637 active
638 ? "bg-accent text-foreground"
639 : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
640 )}
641 >
642 <button
643 type="button"
644 className="cursor-pointer group/close relative flex size-4 shrink-0 items-center justify-center rounded-sm hover:bg-muted"
645 aria-label={`Close ${title}`}
646 onClick={() => props.onCloseSurface(surface)}
647 >
648 <span className="relative flex size-3 items-center justify-center group-hover/tab:hidden group-focus-visible/close:hidden">
649 <SurfaceIcon
650 surface={surface}
651 sessions={props.previewSessions}
652 desktopByTabId={props.desktopByTabId}
653 theme={resolvedTheme}
654 pullRequestStatuses={props.pullRequestStatuses}
655 />
656 {pending ? (
657 <span
658 className="absolute -right-0.5 -bottom-0.5 size-1.5 rounded-full bg-current"
659 aria-hidden
660 />
661 ) : null}
662 </span>
663 <X className="hidden size-3 group-hover/tab:block group-focus-visible/close:block" />
664 </button>
665 <Tooltip>
666 <TooltipTrigger
667 render={
668 <button
669 type="button"
670 className="cursor-pointer flex min-w-0 items-center"
671 onClick={() => props.onActivate(surface)}
672 >
673 <span className="truncate">{title}</span>
674 </button>
675 }
676 />
677 <TooltipPopup>{title}</TooltipPopup>
678 </Tooltip>
679 </div>
680 );
681 })}
682 {props.surfaces.length > 0 ? (
683 <Menu>
684 <MenuTrigger
685 className="cursor-pointer relative inline-flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground"
686 aria-label="Add panel surface"
687 >
688 <Plus className="size-3.5" />
689 </MenuTrigger>
690 <MenuPopup align="start" side="bottom" sideOffset={6} className="min-w-44">
691 <SurfaceMenuItem
692 available={props.browserAvailable}
693 disabledReason={SURFACE_DISABLED_REASONS.browser}
694 onClick={props.onAddBrowser}
695 >
696 <Globe2 />
697 Browser
698 </SurfaceMenuItem>
699 <SurfaceMenuItem
700 available={props.terminalAvailable}
701 disabledReason={SURFACE_DISABLED_REASONS.terminal}
702 onClick={props.onAddTerminal}
703 >
704 <TerminalSquare />
705 Terminal
706 </SurfaceMenuItem>
707 <SurfaceMenuItem
708 available={props.filesAvailable}
709 disabledReason={SURFACE_DISABLED_REASONS.files}
710 onClick={props.onAddFiles}
711 >
712 <Files />
713 Files
714 </SurfaceMenuItem>
715 <SurfaceMenuItem
716 available={props.diffAvailable}
717 disabledReason={SURFACE_DISABLED_REASONS.diff}
718 onClick={props.onAddDiff}
719 >
720 <FileDiff />
721 Diff
722 </SurfaceMenuItem>
723 <SurfaceMenuItem
724 available={props.pullRequestAvailable}
725 disabledReason={SURFACE_DISABLED_REASONS.pullRequest}
726 onClick={props.onAddPullRequest}
727 >
728 <GitPullRequest />
729 Pull request
730 </SurfaceMenuItem>
731 <SurfaceMenuItem
732 available={props.agentsAvailable}
733 disabledReason={SURFACE_DISABLED_REASONS.agents}
734 onClick={props.onAddAgents}
735 >
736 <Bot />
737 Agents
738 </SurfaceMenuItem>
739 </MenuPopup>
740 </Menu>
741 ) : null}
742 </div>
743 </ScrollArea>
744 {props.layoutControls}
745 </div>
746 <div className="flex min-h-0 flex-1 flex-col" data-right-panel-surface-content>
747 {props.activeSurfaceId === null ? (
748 <RightPanelEmptyState
749 onAddBrowser={props.onAddBrowser}
750 onAddTerminal={props.onAddTerminal}
751 onAddDiff={props.onAddDiff}
752 onAddFiles={props.onAddFiles}
753 onAddPullRequest={props.onAddPullRequest}
754 onAddAgents={props.onAddAgents}
755 browserAvailable={props.browserAvailable}
756 terminalAvailable={props.terminalAvailable}
757 diffAvailable={props.diffAvailable}
758 filesAvailable={props.filesAvailable}
759 pullRequestAvailable={props.pullRequestAvailable}
760 agentsAvailable={props.agentsAvailable}
761 liveAgentCount={props.liveAgentCount}
762 />
763 ) : (
764 props.children
765 )}
766 </div>
767 </PreviewPanelShell>
768 );
769}