Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadCommandSubtitle.tsx

115 lines4.1 KB

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​
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>;
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 />;
35​
36export function ThreadCommandSubtitle(props: {
37 project: ProjectFaviconProject | null;
38 projectTitle: string | null;
39 environmentLabel?: string | null;
40 branch: string | null;
41 worktreePath: string | null;
42 isCurrent: boolean;
43 driverKind?: ProviderDriverKind | null;
44 providerDisplayName?: string | null;
45 acpRegistryAgentId?: string | undefined;
46 acpRegistryIconUrl?: string | undefined;
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 <span className="min-w-0 truncate">{branchLabel}</span>
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 acpRegistryAgentId={props.acpRegistryAgentId}
101 acpRegistryIconUrl={props.acpRegistryIconUrl}
102 iconClassName="size-3 shrink-0 opacity-70"
103 />
104 </>
105 ) : null}
106​
107 {props.isCurrent ? (
108 <>
109 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
110 <span className="shrink-0">Current thread</span>
111 </>
112 ) : null}
113 </span>
114 );