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

ThreadCommandSubtitle.tsx

108 lines3.9 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 branch: string | null;
40 worktreePath: string | null;
41 isCurrent: boolean;
42 driverKind?: ProviderDriverKind | null;
43 providerDisplayName?: string | null;
44 acpRegistryAgentId?: string | undefined;
45 acpRegistryIconUrl?: string | undefined;
46 variant?: ThreadCommandSubtitleVariant;
47 className?: string;
48}) {
49 const variant = props.variant ?? THREAD_COMMAND_SUBTITLE_VARIANT;
50 const isWorktree = props.worktreePath != null && props.worktreePath.trim().length > 0;
51 const showHarness =
52 variant !== "favicon-workspace" && props.driverKind != null && props.providerDisplayName;
53​
54 const projectLabel = props.projectTitle?.trim() || null;
55 const branchLabel = props.branch?.trim() || null;
56​
57 if (!projectLabel && !branchLabel && !props.isCurrent && !showHarness) {
58 return null;
59 }
60​
61 return (
62 <span
63 className={cn(
64 "inline-flex min-w-0 max-w-full items-center gap-1 text-xs text-muted-foreground/70",
65 props.className,
66 )}
67 >
68 {projectLabel ? (
69 <span className="inline-flex min-w-0 items-center gap-1">
70 {props.project ? (
71 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
72 ) : null}
73 <span className="min-w-0 truncate">{projectLabel}</span>
74 </span>
75 ) : null}
76​
77 {branchLabel ? (
78 <>
79 {projectLabel ? <CommandPaletteMetaDot /> : null}
80 <span className="inline-flex min-w-0 items-center gap-1">
81 <WorkspaceIcon variant={variant} isWorktree={isWorktree} />
82 <span className="min-w-0 truncate">{branchLabel}</span>
83 </span>
84 </>
85 ) : null}
86​
87 {showHarness && props.driverKind ? (
88 <>
89 {projectLabel || branchLabel ? <CommandPaletteMetaDot /> : null}
90 <ProviderInstanceIcon
91 driverKind={props.driverKind}
92 displayName={props.providerDisplayName ?? props.driverKind}
93 acpRegistryAgentId={props.acpRegistryAgentId}
94 acpRegistryIconUrl={props.acpRegistryIconUrl}
95 iconClassName="size-3 shrink-0 opacity-70"
96 />
97 </>
98 ) : null}
99​
100 {props.isCurrent ? (
101 <>
102 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
103 <span className="shrink-0">Current thread</span>
104 </>
105 ) : null}
106 </span>
107 );