Open History to see the last commit
1import type { EnvironmentId, ProviderDriverKind } from "@t3tools/contracts";
2import { FolderGit2Icon, FolderIcon, GitBranchIcon } from "lucide-react";
3import { ProjectFavicon } from "./ProjectFavicon";
4import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
5import { cn } from "~/lib/utils";
6
7/**
8 * Flip this while reviewing command-palette thread subtitles.
9 * - favicon-workspace-harness: favicon + Folder/FolderGit2 + branch + harness (default)
10 * - favicon-workspace: same without harness
11 * - favicon-branch-harness: GitBranch for local, FolderGit2 for worktrees, + harness
12 */
13export type ThreadCommandSubtitleVariant =
14 | "favicon-workspace-harness"
15 | "favicon-workspace"
16 | "favicon-branch-harness";
17
18const THREAD_COMMAND_SUBTITLE_VARIANT: ThreadCommandSubtitleVariant = "favicon-workspace-harness";
19
20export const COMMAND_PALETTE_META_ICON_CLASS = "size-3 shrink-0 text-muted-foreground/70";
21
22export function CommandPaletteMetaDot() {
23 return <span className="shrink-0 text-muted-foreground/50">·</span>;
24}
25
26function WorkspaceIcon(props: { variant: ThreadCommandSubtitleVariant; isWorktree: boolean }) {
27 if (props.isWorktree) {
28 return <FolderGit2Icon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
29 }
30 if (props.variant === "favicon-branch-harness") {
31 return <GitBranchIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
32 }
33 return <FolderIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
34}
35
36export function ThreadCommandSubtitle(props: {
37 environmentId: EnvironmentId;
38 projectCwd: string | null;
39 projectFaviconPath?: string | null;
40 projectIcon?: import("@t3tools/contracts").ProjectIconOverride | null;
41 projectTitle: 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.projectCwd ? (
72 <ProjectFavicon
73 environmentId={props.environmentId}
74 cwd={props.projectCwd}
75 projectName={projectLabel}
76 faviconPath={props.projectFaviconPath}
77 projectIcon={props.projectIcon}
78 className="size-3 shrink-0"
79 />
80 ) : null}
81 <span className="min-w-0 truncate">{projectLabel}</span>
82 </span>
83 ) : null}
84
85 {branchLabel ? (
86 <>
87 {projectLabel ? <CommandPaletteMetaDot /> : null}
88 <span className="inline-flex min-w-0 items-center gap-1">
89 <WorkspaceIcon variant={variant} isWorktree={isWorktree} />
90 <span className="min-w-0 truncate">{branchLabel}</span>
91 </span>
92 </>
93 ) : null}
94
95 {showHarness && props.driverKind ? (
96 <>
97 {projectLabel || branchLabel ? <CommandPaletteMetaDot /> : null}
98 <ProviderInstanceIcon
99 driverKind={props.driverKind}
100 displayName={props.providerDisplayName ?? props.driverKind}
101 iconClassName="size-3 shrink-0 opacity-70"
102 />
103 </>
104 ) : null}
105
106 {props.isCurrent ? (
107 <>
108 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
109 <span className="shrink-0">Current thread</span>
110 </>
111 ) : null}
112 </span>
113 );
114}