Open History to see the last commit
1import type { ProviderDriverKind } from "@t3tools/contracts";
2import { FolderGit2Icon, FolderIcon, GitBranchIcon } from "lucide-react";
3import { ProjectFavicon, type ProjectFaviconProject } from "./ProjectFavicon";
4import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
5import { cn } from "~/lib/utils";
6
7import { MiddleTruncate } from "./ui/middle-truncate";
8
9/**
10 * Flip this while reviewing command-palette thread subtitles.
11 * - favicon-workspace-harness: favicon + Folder/FolderGit2 + branch + harness (default)
12 * - favicon-workspace: same without harness
13 * - favicon-branch-harness: GitBranch for local, FolderGit2 for worktrees, + harness
14 */
15export type ThreadCommandSubtitleVariant =
16 | "favicon-workspace-harness"
17 | "favicon-workspace"
18 | "favicon-branch-harness";
19
20const THREAD_COMMAND_SUBTITLE_VARIANT: ThreadCommandSubtitleVariant = "favicon-workspace-harness";
21
22export const COMMAND_PALETTE_META_ICON_CLASS = "size-3 shrink-0 text-muted-foreground/70";
23
24export function CommandPaletteMetaDot() {
25 return <span className="shrink-0 text-muted-foreground/50">·</span>;
26}
27
28function WorkspaceIcon(props: { variant: ThreadCommandSubtitleVariant; isWorktree: boolean }) {
29 if (props.isWorktree) {
30 return <FolderGit2Icon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
31 }
32 if (props.variant === "favicon-branch-harness") {
33 return <GitBranchIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
34 }
35 return <FolderIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
36}
37
38export function ThreadCommandSubtitle(props: {
39 project: ProjectFaviconProject | null;
40 projectTitle: string | null;
41 environmentLabel?: string | null;
42 branch: string | null;
43 worktreePath: string | null;
44 isCurrent: boolean;
45 driverKind?: ProviderDriverKind | null;
46 providerDisplayName?: string | null;
47 variant?: ThreadCommandSubtitleVariant;
48 className?: string;
49}) {
50 const variant = props.variant ?? THREAD_COMMAND_SUBTITLE_VARIANT;
51 const isWorktree = props.worktreePath != null && props.worktreePath.trim().length > 0;
52 const showHarness =
53 variant !== "favicon-workspace" && props.driverKind != null && props.providerDisplayName;
54
55 const projectLabel = props.projectTitle?.trim() || null;
56 const branchLabel = props.branch?.trim() || null;
57
58 if (!projectLabel && !branchLabel && !props.isCurrent && !showHarness) {
59 return null;
60 }
61
62 return (
63 <span
64 className={cn(
65 "inline-flex min-w-0 max-w-full items-center gap-1 text-xs text-muted-foreground/70",
66 props.className,
67 )}
68 >
69 {projectLabel ? (
70 <span className="inline-flex min-w-0 items-center gap-1">
71 {props.project ? (
72 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
73 ) : null}
74 <span className="min-w-0 truncate">{projectLabel}</span>
75 {props.environmentLabel ? (
76 <>
77 <CommandPaletteMetaDot />
78 <span className="shrink-0">{props.environmentLabel}</span>
79 </>
80 ) : null}
81 </span>
82 ) : null}
83
84 {branchLabel ? (
85 <>
86 {projectLabel ? <CommandPaletteMetaDot /> : null}
87 <span className="inline-flex min-w-0 items-center gap-1">
88 <WorkspaceIcon variant={variant} isWorktree={isWorktree} />
89 <MiddleTruncate value={branchLabel} />
90 </span>
91 </>
92 ) : null}
93
94 {showHarness && props.driverKind ? (
95 <>
96 {projectLabel || branchLabel ? <CommandPaletteMetaDot /> : null}
97 <ProviderInstanceIcon
98 driverKind={props.driverKind}
99 displayName={props.providerDisplayName ?? props.driverKind}
100 iconClassName="size-3 shrink-0 opacity-70"
101 />
102 </>
103 ) : null}
104
105 {props.isCurrent ? (
106 <>
107 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
108 <span className="shrink-0">Current thread</span>
109 </>
110 ) : null}
111 </span>
112 );
113}