feat(web): project favicon and workspace icons in command subtitles (#6330)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
2eb099fdc8
commit
ac1264e2ca
5 files changed
+192
-5
No files matched your search
@@ -264,6 +264,20 @@ describe("buildThreadActionItems", () => {
|
||||
expect(item?.description).toBe("T3 Code · #feat/search");
|
||||
});
|
||||
|
||||
it("prefers renderDescription when provided", () => {
|
||||
const [item] = buildThreadActionItems({
|
||||
threads: [makeThread({ branch: "feat/search", worktreePath: "/tmp/wt" })],
|
||||
projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
|
||||
sortOrder: "updated_at",
|
||||
icon: null,
|
||||
renderDescription: (thread, { projectTitle }) =>
|
||||
`${projectTitle}:${thread.branch}:${thread.worktreePath ? "wt" : "local"}`,
|
||||
runThread: async (_thread) => undefined,
|
||||
});
|
||||
|
||||
expect(item?.description).toBe("T3 Code:feat/search:wt");
|
||||
});
|
||||
|
||||
it("filters archived threads out of thread search items", () => {
|
||||
const items = buildThreadActionItems({
|
||||
threads: [
|
||||
|
||||
@@ -154,7 +154,16 @@ export function buildProjectActionItems(input: {
|
||||
|
||||
export type BuildThreadActionItemsThread = Pick<
|
||||
SidebarThreadSummary,
|
||||
"archivedAt" | "branch" | "createdAt" | "environmentId" | "id" | "projectId" | "title"
|
||||
| "archivedAt"
|
||||
| "branch"
|
||||
| "createdAt"
|
||||
| "environmentId"
|
||||
| "id"
|
||||
| "modelSelection"
|
||||
| "projectId"
|
||||
| "session"
|
||||
| "title"
|
||||
| "worktreePath"
|
||||
> & {
|
||||
updatedAt: string;
|
||||
latestUserMessageAt?: string | null;
|
||||
@@ -170,6 +179,8 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
|
||||
renderLeadingContent?: (thread: TThread) => ReactNode;
|
||||
/** Optional content rendered inline after the title text per-thread. */
|
||||
renderTrailingContent?: (thread: TThread) => ReactNode;
|
||||
/** Optional rich description (e.g. favicon + workspace icons). Falls back to text. */
|
||||
renderDescription?: (thread: TThread, meta: { projectTitle: string | undefined }) => ReactNode;
|
||||
getContentMatch?: (thread: TThread) => CommandPaletteThreadContentMatch | undefined;
|
||||
runThread: (thread: Pick<SidebarThreadSummary, "environmentId" | "id">) => Promise<void>;
|
||||
limit?: number;
|
||||
@@ -198,6 +209,9 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
|
||||
const leadingContent = input.renderLeadingContent?.(thread);
|
||||
const trailingContent = input.renderTrailingContent?.(thread);
|
||||
const contentMatch = input.getContentMatch?.(thread);
|
||||
const description = input.renderDescription
|
||||
? input.renderDescription(thread, { projectTitle })
|
||||
: descriptionParts.join(` · `);
|
||||
|
||||
return Object.assign(
|
||||
{
|
||||
@@ -210,7 +224,7 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
|
||||
contentMatch?.snippet ?? ``,
|
||||
],
|
||||
title: thread.title,
|
||||
description: descriptionParts.join(` · `),
|
||||
description,
|
||||
timestamp: formatRelativeTimeLabel(
|
||||
thread.latestUserMessageAt ?? thread.updatedAt ?? thread.createdAt,
|
||||
),
|
||||
|
||||
@@ -124,9 +124,14 @@ import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { ProjectFilePicker } from "./files/ProjectFilePicker";
|
||||
import { ProjectContentSearchDialog } from "./search/ProjectContentSearchDialog";
|
||||
import { toggleThemeEditorForTheme } from "./settings/themeEditorStore";
|
||||
import { ThreadCommandSubtitle } from "./ThreadCommandSubtitle";
|
||||
import { ThreadRowLeadingStatus, ThreadRowTrailingStatus } from "./ThreadStatusIndicators";
|
||||
import { primaryServerKeybindingsAtom, primaryServerProvidersAtom } from "../state/server";
|
||||
import { resolveDefaultProviderModelSelection } from "../providerInstances";
|
||||
import {
|
||||
deriveProviderInstanceEntries,
|
||||
resolveDefaultProviderModelSelection,
|
||||
type ProviderInstanceEntry,
|
||||
} from "../providerInstances";
|
||||
import { resolveShortcutCommand, threadJumpIndexFromCommand } from "../keybindings";
|
||||
import { CommandDialog, CommandDialogPopup } from "./ui/command";
|
||||
import { Button } from "./ui/button";
|
||||
@@ -584,6 +589,18 @@ function OpenCommandPaletteDialog(props: {
|
||||
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
|
||||
const { theme, themeHalves, resolvedTheme } = useTheme();
|
||||
const providers = useAtomValue(primaryServerProvidersAtom);
|
||||
const providerEntryByEnvironmentAndInstanceId = useMemo(() => {
|
||||
const map = new Map<string, ProviderInstanceEntry>();
|
||||
for (const environment of environments) {
|
||||
const environmentProviders =
|
||||
environment.serverConfig?.providers ??
|
||||
(environment.environmentId === primaryEnvironmentId ? providers : []);
|
||||
for (const entry of deriveProviderInstanceEntries(environmentProviders)) {
|
||||
map.set(`${environment.environmentId}:${entry.instanceId}`, entry);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}, [environments, primaryEnvironmentId, providers]);
|
||||
const [viewStack, setViewStack] = useState<CommandPaletteView[]>([]);
|
||||
const currentView = viewStack.at(-1) ?? null;
|
||||
const environmentIds = useMemo(
|
||||
@@ -816,6 +833,10 @@ function OpenCommandPaletteDialog(props: {
|
||||
new Map<ProjectId, string>(projects.map((project) => [project.id, project.workspaceRoot])),
|
||||
[projects],
|
||||
);
|
||||
const projectFaviconPathById = useMemo(
|
||||
() => new Map(projects.map((project) => [project.id, project.faviconPath ?? null] as const)),
|
||||
[projects],
|
||||
);
|
||||
const projectTitleById = useMemo(
|
||||
() => new Map<ProjectId, string>(projects.map((project) => [project.id, project.title])),
|
||||
[projects],
|
||||
@@ -1000,6 +1021,29 @@ function OpenCommandPaletteDialog(props: {
|
||||
icon: <MessageSquareIcon className={ITEM_ICON_CLASS} />,
|
||||
renderLeadingContent: (thread) => <ThreadRowLeadingStatus thread={thread} />,
|
||||
renderTrailingContent: (thread) => <ThreadRowTrailingStatus thread={thread} />,
|
||||
renderDescription: (thread, { projectTitle }) => {
|
||||
const modelInstanceId =
|
||||
thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;
|
||||
const providerEntry =
|
||||
providerEntryByEnvironmentAndInstanceId.get(
|
||||
`${thread.environmentId}:${modelInstanceId}`,
|
||||
) ?? null;
|
||||
return (
|
||||
<ThreadCommandSubtitle
|
||||
environmentId={thread.environmentId}
|
||||
projectCwd={projectCwdById.get(thread.projectId) ?? null}
|
||||
projectFaviconPath={projectFaviconPathById.get(thread.projectId) ?? null}
|
||||
projectTitle={projectTitle ?? null}
|
||||
branch={thread.branch}
|
||||
worktreePath={thread.worktreePath}
|
||||
isCurrent={thread.id === activeThreadId}
|
||||
driverKind={providerEntry?.driverKind ?? null}
|
||||
providerDisplayName={
|
||||
thread.session?.providerName ?? providerEntry?.displayName ?? modelInstanceId
|
||||
}
|
||||
/>
|
||||
);
|
||||
},
|
||||
getContentMatch: (thread) => {
|
||||
const match = threadContentMatchByKey.get(
|
||||
threadSearchMatchKey({
|
||||
@@ -1026,7 +1070,10 @@ function OpenCommandPaletteDialog(props: {
|
||||
activeThreadId,
|
||||
clientSettings.sidebarThreadSortOrder,
|
||||
navigate,
|
||||
projectCwdById,
|
||||
projectFaviconPathById,
|
||||
projectTitleById,
|
||||
providerEntryByEnvironmentAndInstanceId,
|
||||
threadContentMatchByKey,
|
||||
threadSearchQuery,
|
||||
threads,
|
||||
|
||||
@@ -142,7 +142,7 @@ function DisabledCommandPaletteResultRow(props: {
|
||||
<ThreadContentMatch match={props.item.threadContentMatch} />
|
||||
) : null}
|
||||
{props.item.description ? (
|
||||
<span className="truncate text-muted-foreground/70 text-xs">
|
||||
<span className="min-w-0 text-muted-foreground/70 text-xs">
|
||||
{props.item.description}
|
||||
</span>
|
||||
) : null}
|
||||
@@ -193,7 +193,7 @@ function CommandPaletteResultRow(props: {
|
||||
<ThreadContentMatch match={props.item.threadContentMatch} />
|
||||
) : null}
|
||||
{props.item.description ? (
|
||||
<span className="truncate text-muted-foreground/70 text-xs">
|
||||
<span className="min-w-0 text-muted-foreground/70 text-xs">
|
||||
{props.item.description}
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import type { EnvironmentId, ProviderDriverKind } from "@t3tools/contracts";
|
||||
import { FolderGit2Icon, FolderIcon, GitBranchIcon } from "lucide-react";
|
||||
import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
/**
|
||||
* Flip this while reviewing command-palette thread subtitles.
|
||||
* - favicon-workspace-harness: favicon + Folder/FolderGit2 + branch + harness (default)
|
||||
* - favicon-workspace: same without harness
|
||||
* - favicon-branch-harness: GitBranch for local, FolderGit2 for worktrees, + harness
|
||||
*/
|
||||
export type ThreadCommandSubtitleVariant =
|
||||
| "favicon-workspace-harness"
|
||||
| "favicon-workspace"
|
||||
| "favicon-branch-harness";
|
||||
|
||||
export const THREAD_COMMAND_SUBTITLE_VARIANT: ThreadCommandSubtitleVariant =
|
||||
"favicon-workspace-harness";
|
||||
|
||||
const META_ICON_CLASS = "size-3 shrink-0 text-muted-foreground/70";
|
||||
|
||||
function Dot() {
|
||||
return <span className="shrink-0 text-muted-foreground/50">·</span>;
|
||||
}
|
||||
|
||||
function WorkspaceIcon(props: { variant: ThreadCommandSubtitleVariant; isWorktree: boolean }) {
|
||||
if (props.isWorktree) {
|
||||
return <FolderGit2Icon className={META_ICON_CLASS} aria-hidden />;
|
||||
}
|
||||
if (props.variant === "favicon-branch-harness") {
|
||||
return <GitBranchIcon className={META_ICON_CLASS} aria-hidden />;
|
||||
}
|
||||
return <FolderIcon className={META_ICON_CLASS} aria-hidden />;
|
||||
}
|
||||
|
||||
export function ThreadCommandSubtitle(props: {
|
||||
environmentId: EnvironmentId;
|
||||
projectCwd: string | null;
|
||||
projectFaviconPath?: string | null;
|
||||
projectTitle: string | null;
|
||||
branch: string | null;
|
||||
worktreePath: string | null;
|
||||
isCurrent: boolean;
|
||||
driverKind?: ProviderDriverKind | null;
|
||||
providerDisplayName?: string | null;
|
||||
variant?: ThreadCommandSubtitleVariant;
|
||||
className?: string;
|
||||
}) {
|
||||
const variant = props.variant ?? THREAD_COMMAND_SUBTITLE_VARIANT;
|
||||
const isWorktree = props.worktreePath != null && props.worktreePath.trim().length > 0;
|
||||
const showHarness =
|
||||
variant !== "favicon-workspace" && props.driverKind != null && props.providerDisplayName;
|
||||
|
||||
const projectLabel = props.projectTitle?.trim() || null;
|
||||
const branchLabel = props.branch?.trim() || null;
|
||||
|
||||
if (!projectLabel && !branchLabel && !props.isCurrent && !showHarness) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex min-w-0 max-w-full items-center gap-1 text-xs text-muted-foreground/70",
|
||||
props.className,
|
||||
)}
|
||||
>
|
||||
{projectLabel ? (
|
||||
<span className="inline-flex min-w-0 items-center gap-1">
|
||||
{props.projectCwd ? (
|
||||
<ProjectFavicon
|
||||
environmentId={props.environmentId}
|
||||
cwd={props.projectCwd}
|
||||
faviconPath={props.projectFaviconPath}
|
||||
className="size-3 shrink-0"
|
||||
/>
|
||||
) : null}
|
||||
<span className="min-w-0 truncate">{projectLabel}</span>
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
{branchLabel ? (
|
||||
<>
|
||||
{projectLabel ? <Dot /> : null}
|
||||
<span className="inline-flex min-w-0 items-center gap-1">
|
||||
<WorkspaceIcon variant={variant} isWorktree={isWorktree} />
|
||||
<span className="min-w-0 truncate">{branchLabel}</span>
|
||||
</span>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{showHarness && props.driverKind ? (
|
||||
<>
|
||||
{projectLabel || branchLabel ? <Dot /> : null}
|
||||
<ProviderInstanceIcon
|
||||
driverKind={props.driverKind}
|
||||
displayName={props.providerDisplayName ?? props.driverKind}
|
||||
iconClassName="size-3 shrink-0 opacity-70"
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{props.isCurrent ? (
|
||||
<>
|
||||
{projectLabel || branchLabel || showHarness ? <Dot /> : null}
|
||||
<span className="shrink-0">Current thread</span>
|
||||
</>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user