The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): the command palette's project items and pure helpers live in their own files (#22699)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 21, 2026 at 01:13 UTC
0b7c902df77db32f575c12a9ffc1579b27513fee
3 files changed
+228
-196
apps/web/src/components/CommandPalette.logic.ts
+94
@@ -1,9 +1,19 @@
1
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
2
import type { CommandPaletteLinkedThreads } from "../commandPaletteBus";
3
+import {
4
+ addProjectRemoteSourceLabel,
5
+ addProjectRemoteSourcePathHint,
6
+ buildAddProjectRemoteSourceReadiness,
7
+ type AddProjectRemoteSource,
8
+ type AddProjectRemoteSourceReadiness,
9
+} from "@t3tools/client-runtime/operations/projects";
10
import {
11
type EnvironmentId,
12
+ type EnvironmentMachineKind,
13
type FilesystemBrowseEntry,
14
type KeybindingCommand,
15
+ type SourceControlDiscoveryResult,
16
+ type SourceControlRepositoryInfo,
17
THREAD_JUMP_KEYBINDING_COMMANDS,
18
} from "@t3tools/contracts";
19
import { filterFilesystemBrowseEntries } from "@t3tools/client-runtime/state/filesystem";
@@ -657,3 +667,87 @@ export function getCommandPaletteInputPlaceholder(mode: CommandPaletteMode): str
667
return "Enter path (e.g. ~/projects/my-app)";
668
}
669
}
670
+
671
+export function getEnvironmentBrowsePlatform(os: string | null | undefined): string {
672
+ if (os === "windows") {
673
+ return "Win32";
674
+ }
675
+ if (os === "darwin") {
676
+ return "MacIntel";
677
+ }
678
+ if (os === "linux") {
679
+ return "Linux";
680
+ }
681
+ return typeof navigator === "undefined" ? "" : navigator.platform;
682
+}
683
+
684
+export interface AddProjectEnvironmentOption {
685
+ readonly environmentId: EnvironmentId;
686
+ readonly label: string;
687
+ readonly machine: EnvironmentMachineKind;
688
+ readonly isPrimary: boolean;
689
+ readonly isConnected: boolean;
690
+ readonly status: string;
691
+}
692
+
693
+export type AddProjectCloneFlow =
694
+ | {
695
+ readonly step: "repository";
696
+ readonly environmentId: EnvironmentId;
697
+ readonly source: AddProjectRemoteSource;
698
+ }
699
+ | {
700
+ readonly step: "confirm";
701
+ readonly environmentId: EnvironmentId;
702
+ readonly source: AddProjectRemoteSource;
703
+ readonly repositoryInput: string;
704
+ readonly repository: SourceControlRepositoryInfo | null;
705
+ readonly remoteUrl: string;
706
+ };
707
+
708
+export function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): string | null {
709
+ if (!flow) return null;
710
+ if (flow.step === "confirm") return null;
711
+ if (flow.source === "url") {
712
+ return "Enter Git clone URL";
713
+ }
714
+ return `Enter ${addProjectRemoteSourceLabel(flow.source)} repository (${addProjectRemoteSourcePathHint(flow.source)})`;
715
+}
716
+
717
+export function buildPaletteRemoteSourceReadiness(
718
+ discovery: SourceControlDiscoveryResult | null,
719
+): AddProjectRemoteSourceReadiness {
720
+ const readiness = buildAddProjectRemoteSourceReadiness(discovery);
721
+ return (source) => {
722
+ const entry = readiness(source);
723
+ return entry.hint === null
724
+ ? entry
725
+ : {
726
+ ...entry,
727
+ hint: entry.hint.replace(
728
+ "Open Source Control settings",
729
+ "Open Settings -> Source Control",
730
+ ),
731
+ };
732
+ };
733
+}
734
+
735
+export function errorMessage(error: unknown): string {
736
+ if (error instanceof Error && error.message.trim().length > 0) {
737
+ return error.message;
738
+ }
739
+ return "An error occurred.";
740
+}
741
+
742
+const OVERLAY_MODE_BY_COMMAND = {
743
+ "commandPalette.toggle": "command",
744
+ "filePicker.toggle": "files",
745
+ "projectSearch.toggle": "content",
746
+} as const satisfies Partial<Record<string, SearchOverlayMode>>;
747
+
748
+export function overlayModeForCommand(command: string | null): SearchOverlayMode | null {
749
+ if (command === null) return null;
750
+ return command in OVERLAY_MODE_BY_COMMAND
751
+ ? OVERLAY_MODE_BY_COMMAND[command as keyof typeof OVERLAY_MODE_BY_COMMAND]
752
+ : null;
753
+}
apps/web/src/components/CommandPalette.tsx
+17
-196
@@ -17,7 +17,6 @@ import {
17
addProjectRemoteSourceLabel,
18
addProjectRemoteSourcePathHint,
19
addProjectRemoteSourceProvider,
20
- buildAddProjectRemoteSourceReadiness,
20
sortAddProjectProviderSources,
21
type AddProjectRemoteSource,
22
type AddProjectRemoteSourceReadiness,
@@ -42,11 +41,8 @@ import {
41
AuthFilesystemReadScope,
42
type DesktopWslState,
43
type EnvironmentId,
45
- type EnvironmentMachineKind,
44
type FilesystemBrowseResult,
47
- type SourceControlDiscoveryResult,
45
SourceControlProviderKind,
49
- type SourceControlRepositoryInfo,
46
PRIMARY_LOCAL_ENVIRONMENT_ID,
47
resolveEnvironmentMachineKind,
48
} from "@t3tools/contracts";
@@ -159,8 +155,6 @@ import {
155
ADDON_ICON_CLASS,
156
browseInputEndPaddingClass,
157
buildBrowseGroups,
162
- buildCommandPaletteProjectMetadata,
163
- buildProjectActionItems,
158
buildRootGroups,
159
buildLinkedThreadActionItems,
160
buildCommandPaletteRows,
@@ -180,6 +174,13 @@ import {
174
RECENT_THREAD_LIMIT,
175
reduceCommandPaletteUiState,
176
createCommandPaletteSearchState,
177
+ type AddProjectCloneFlow,
178
+ type AddProjectEnvironmentOption,
179
+ buildPaletteRemoteSourceReadiness,
180
+ errorMessage,
181
+ getEnvironmentBrowsePlatform,
182
+ overlayModeForCommand,
183
+ remoteProjectInputPlaceholder,
184
reduceCommandPaletteSearchState,
185
type SearchOverlayMode,
186
} from "./CommandPalette.logic";
@@ -191,6 +192,10 @@ import {
192
useProjectLookups,
193
useSortedProjectGroups,
194
} from "./CommandPaletteLookups";
195
+import {
196
+ buildNewThreadInProjectItems,
197
+ buildProjectSearchItems,
198
+} from "./CommandPaletteProjectItems";
199
import { useCommandPaletteThreadItems } from "./CommandPaletteThreadItems";
200
import {
201
APPEARANCE_OPTIONS,
@@ -205,13 +210,11 @@ import {
210
import { sourceControlIcon } from "~/sourceControlPresentation";
211
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
212
import { Checkbox } from "./ui/checkbox";
208
-import { ProjectFavicon } from "./ProjectFavicon";
213
import { ProjectFilePicker } from "./files/ProjectFilePicker";
214
import { openLinkPullRequestDialog } from "./pullRequest/LinkPullRequestDialog";
215
import { ProjectContentSearchDialog } from "./search/ProjectContentSearchDialog";
216
import { toggleThemeEditorForTheme } from "./settings/themeEditorStore";
217
import { searchSettings, SETTINGS_SECTION_LABELS } from "./settings/settingsSearch";
214
-import { COMMAND_PALETTE_META_ICON_CLASS, CommandPaletteMetaDot } from "./ThreadCommandSubtitle";
218
import { primaryServerKeybindingsAtom } from "../state/server";
219
import { resolveShortcutCommand, threadJumpIndexFromCommand } from "../keybindings";
220
import { CommandDialog, CommandDialogPopup, CommandFooterAction } from "./ui/command";
@@ -223,50 +226,12 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
226
import { ComposerHandleContext, useComposerHandleContext } from "../composerHandleContext";
227
import type { ChatComposerHandle } from "./chat/ChatComposer";
228
import { buildSidebarProjectPickerEntries } from "../sidebarProjectGrouping";
226
-import type { Project } from "../types";
229
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
230
import { readPullRequestListPreferences } from "~/components/pullRequest/pullRequestListPreferences";
231
import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
232
233
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
234
233
-function getEnvironmentBrowsePlatform(os: string | null | undefined): string {
234
- if (os === "windows") {
235
- return "Win32";
236
- }
237
- if (os === "darwin") {
238
- return "MacIntel";
239
- }
240
- if (os === "linux") {
241
- return "Linux";
242
- }
243
- return typeof navigator === "undefined" ? "" : navigator.platform;
244
-}
245
-
246
-interface AddProjectEnvironmentOption {
247
- readonly environmentId: EnvironmentId;
248
- readonly label: string;
249
- readonly machine: EnvironmentMachineKind;
250
- readonly isPrimary: boolean;
251
- readonly isConnected: boolean;
252
- readonly status: string;
253
-}
254
-
255
-type AddProjectCloneFlow =
256
- | {
257
- readonly step: "repository";
258
- readonly environmentId: EnvironmentId;
259
- readonly source: AddProjectRemoteSource;
260
- }
261
- | {
262
- readonly step: "confirm";
263
- readonly environmentId: EnvironmentId;
264
- readonly source: AddProjectRemoteSource;
265
- readonly repositoryInput: string;
266
- readonly repository: SourceControlRepositoryInfo | null;
267
- readonly remoteUrl: string;
268
- };
269
-
235
function remoteProjectSourceIcon(source: AddProjectRemoteSource, className: string): ReactNode {
236
if (source === "url") return <LinkIcon className={className} />;
237
const Icon = sourceControlIcon(sourceControlClients.get(source));
@@ -281,57 +246,6 @@ function sourceControlHostIcon(
246
return <Icon className={className} />;
247
}
248
284
-function projectFaviconIcon(project: Project): ReactNode {
285
- return <ProjectFavicon project={project} className={ITEM_ICON_CLASS} />;
286
-}
287
-
288
-function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): string | null {
289
- if (!flow) return null;
290
- if (flow.step === "confirm") return null;
291
- if (flow.source === "url") {
292
- return "Enter Git clone URL";
293
- }
294
- return `Enter ${addProjectRemoteSourceLabel(flow.source)} repository (${addProjectRemoteSourcePathHint(flow.source)})`;
295
-}
296
-
297
-function buildPaletteRemoteSourceReadiness(
298
- discovery: SourceControlDiscoveryResult | null,
299
-): AddProjectRemoteSourceReadiness {
300
- const readiness = buildAddProjectRemoteSourceReadiness(discovery);
301
- return (source) => {
302
- const entry = readiness(source);
303
- return entry.hint === null
304
- ? entry
305
- : {
306
- ...entry,
307
- hint: entry.hint.replace(
308
- "Open Source Control settings",
309
- "Open Settings -> Source Control",
310
- ),
311
- };
312
- };
313
-}
314
-
315
-function errorMessage(error: unknown): string {
316
- if (error instanceof Error && error.message.trim().length > 0) {
317
- return error.message;
318
- }
319
- return "An error occurred.";
320
-}
321
-
322
-const OVERLAY_MODE_BY_COMMAND = {
323
- "commandPalette.toggle": "command",
324
- "filePicker.toggle": "files",
325
- "projectSearch.toggle": "content",
326
-} as const satisfies Partial<Record<string, SearchOverlayMode>>;
327
-
328
-function overlayModeForCommand(command: string | null): SearchOverlayMode | null {
329
- if (command === null) return null;
330
- return command in OVERLAY_MODE_BY_COMMAND
331
- ? OVERLAY_MODE_BY_COMMAND[command as keyof typeof OVERLAY_MODE_BY_COMMAND]
332
- : null;
333
-}
334
-
249
export function CommandPalette({ children }: { children: ReactNode }) {
250
const navigate = useNavigate();
251
const [state, dispatch] = useReducer(reduceCommandPaletteUiState, {
@@ -940,39 +854,10 @@ function OpenCommandPaletteDialog(props: {
854
await handleNewThread(scopeProjectRef(project.environmentId, project.id));
855
};
856
943
- const projectSearchItems = buildProjectActionItems({
857
+ const projectSearchItems = buildProjectSearchItems({
858
projects: pickerProjects,
945
- valuePrefix: "project",
946
- searchTerms: (project) => {
947
- const members = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`)
948
- ?.memberProjects ?? [project];
949
- return buildCommandPaletteProjectMetadata({
950
- projects: members,
951
- locationByEnvironmentId: projectEnvironmentLocationById,
952
- }).searchTerms;
953
- },
954
- renderDescription: (project) => {
955
- const members = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`)
956
- ?.memberProjects ?? [project];
957
- const metadata = buildCommandPaletteProjectMetadata({
958
- projects: members,
959
- locationByEnvironmentId: projectEnvironmentLocationById,
960
- });
961
- const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
962
- kind: "remote" as const,
963
- label: "Remote",
964
- machine: "server" as const,
965
- };
966
- return (
967
- <ProjectSearchDescription
968
- environmentLabels={metadata.environmentLabels}
969
- grouped={members.length > 1}
970
- location={location}
971
- workspaceRoot={project.workspaceRoot}
972
- />
973
- );
974
- },
975
- icon: projectFaviconIcon,
859
+ projectGroupByTargetKey,
860
+ locationByEnvironmentId: projectEnvironmentLocationById,
861
runProject: openProjectFromSearch,
862
});
863
@@ -980,42 +865,10 @@ function OpenCommandPaletteDialog(props: {
865
const isScratch = (project: CommandPaletteProject) =>
866
isScratchProject(project, scratchWorkspaceRootFor(project.environmentId));
867
const projectItems = enumerateCommandPaletteItems(
983
- buildProjectActionItems({
868
+ buildNewThreadInProjectItems({
869
projects: pickerProjects.filter((project) => !isScratch(project)),
985
- valuePrefix: "new-thread-in",
986
- searchTerms: (project) => {
987
- const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
988
- const location = projectEnvironmentLocationById.get(project.environmentId);
989
- return [
990
- ...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
991
- []),
992
- ...(location ? [location.label] : []),
993
- ];
994
- },
995
- renderDescription: (project) => {
996
- const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
997
- kind: "remote",
998
- label: "Remote",
999
- machine: "server" as const,
1000
- };
1001
- return (
1002
- <span className="flex min-w-0 items-center gap-1">
1003
- <span className="inline-flex min-w-0 items-center gap-1">
1004
- {location.kind === "remote" ? (
1005
- <EnvironmentMachineIcon
1006
- aria-hidden
1007
- kind={location.machine}
1008
- className={COMMAND_PALETTE_META_ICON_CLASS}
1009
- />
1010
- ) : null}
1011
- <span className="truncate">{location.label}</span>
1012
- </span>
1013
- <CommandPaletteMetaDot />
1014
- <span className="truncate">{project.workspaceRoot}</span>
1015
- </span>
1016
- );
1017
- },
1018
- icon: projectFaviconIcon,
870
+ projectGroupByTargetKey,
871
+ locationByEnvironmentId: projectEnvironmentLocationById,
872
runProject: async (project) => {
873
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
874
const contextualRefBelongsToGroup =
@@ -3021,35 +2874,3 @@ function OpenCommandPaletteDialog(props: {
2874
</CommandPaletteContent>
2875
);
2876
}
3024
-
3025
-function ProjectSearchDescription(props: {
3026
- readonly environmentLabels: ReadonlyArray<string>;
3027
- readonly grouped: boolean;
3028
- readonly location: {
3029
- readonly kind: "local" | "remote";
3030
- readonly label: string;
3031
- readonly machine: EnvironmentMachineKind;
3032
- };
3033
- readonly workspaceRoot: string;
3034
-}) {
3035
- if (!props.grouped) {
3036
- return (
3037
- <span className="flex min-w-0 items-center gap-1">
3038
- <span className="inline-flex min-w-0 items-center gap-1">
3039
- {props.location.kind === "remote" ? (
3040
- <EnvironmentMachineIcon
3041
- aria-hidden
3042
- kind={props.location.machine}
3043
- className={COMMAND_PALETTE_META_ICON_CLASS}
3044
- />
3045
- ) : null}
3046
- <span className="truncate">{props.location.label}</span>
3047
- </span>
3048
- <CommandPaletteMetaDot />
3049
- <span className="truncate">{props.workspaceRoot}</span>
3050
- </span>
3051
- );
3052
- }
3053
-
3054
- return <span className="truncate">{props.environmentLabels.join(" · ")}</span>;
3055
-}
apps/web/src/components/CommandPaletteProjectItems.tsx
new
+117
@@ -0,0 +1,117 @@
1
+import type { EnvironmentId, EnvironmentMachineKind } from "@t3tools/contracts";
2
+
3
+import type { SidebarProjectSnapshot } from "../sidebarProjectGrouping";
4
+import type { Project } from "../types";
5
+import {
6
+ buildCommandPaletteProjectMetadata,
7
+ buildProjectActionItems,
8
+ type CommandPaletteProject,
9
+ ITEM_ICON_CLASS,
10
+} from "./CommandPalette.logic";
11
+import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
12
+import { ProjectFavicon } from "./ProjectFavicon";
13
+import { COMMAND_PALETTE_META_ICON_CLASS, CommandPaletteMetaDot } from "./ThreadCommandSubtitle";
14
+
15
+export interface CommandPaletteProjectLocation {
16
+ readonly kind: "local" | "remote";
17
+ readonly label: string;
18
+ readonly machine: EnvironmentMachineKind;
19
+}
20
+
21
+const UNKNOWN_PROJECT_LOCATION: CommandPaletteProjectLocation = {
22
+ kind: "remote",
23
+ label: "Remote",
24
+ machine: "server",
25
+};
26
+
27
+interface ProjectItemsInput {
28
+ readonly projects: ReadonlyArray<CommandPaletteProject>;
29
+ readonly projectGroupByTargetKey: ReadonlyMap<string, SidebarProjectSnapshot>;
30
+ readonly locationByEnvironmentId: ReadonlyMap<EnvironmentId, CommandPaletteProjectLocation>;
31
+ readonly runProject: (project: CommandPaletteProject) => Promise<void>;
32
+}
33
+
34
+function projectFaviconIcon(project: Project) {
35
+ return <ProjectFavicon project={project} className={ITEM_ICON_CLASS} />;
36
+}
37
+
38
+/** Projects as root search results; a grouped project matches on every member. */
39
+export function buildProjectSearchItems(input: ProjectItemsInput) {
40
+ const membersOf = (project: CommandPaletteProject) =>
41
+ input.projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`)?.memberProjects ?? [
42
+ project,
43
+ ];
44
+ return buildProjectActionItems({
45
+ projects: input.projects,
46
+ valuePrefix: "project",
47
+ searchTerms: (project) =>
48
+ buildCommandPaletteProjectMetadata({
49
+ projects: membersOf(project),
50
+ locationByEnvironmentId: input.locationByEnvironmentId,
51
+ }).searchTerms,
52
+ renderDescription: (project) => {
53
+ const members = membersOf(project);
54
+ const metadata = buildCommandPaletteProjectMetadata({
55
+ projects: members,
56
+ locationByEnvironmentId: input.locationByEnvironmentId,
57
+ });
58
+ return members.length > 1 ? (
59
+ <span className="truncate">{metadata.environmentLabels.join(" · ")}</span>
60
+ ) : (
61
+ <ProjectLocationDescription
62
+ location={input.locationByEnvironmentId.get(project.environmentId)}
63
+ workspaceRoot={project.workspaceRoot}
64
+ />
65
+ );
66
+ },
67
+ icon: projectFaviconIcon,
68
+ runProject: input.runProject,
69
+ });
70
+}
71
+
72
+/** Projects as targets of the "New thread in..." submenu. */
73
+export function buildNewThreadInProjectItems(input: ProjectItemsInput) {
74
+ return buildProjectActionItems({
75
+ projects: input.projects,
76
+ valuePrefix: "new-thread-in",
77
+ searchTerms: (project) => {
78
+ const group = input.projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
79
+ const location = input.locationByEnvironmentId.get(project.environmentId);
80
+ return [
81
+ ...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? []),
82
+ ...(location ? [location.label] : []),
83
+ ];
84
+ },
85
+ renderDescription: (project) => (
86
+ <ProjectLocationDescription
87
+ location={input.locationByEnvironmentId.get(project.environmentId)}
88
+ workspaceRoot={project.workspaceRoot}
89
+ />
90
+ ),
91
+ icon: projectFaviconIcon,
92
+ runProject: input.runProject,
93
+ });
94
+}
95
+
96
+function ProjectLocationDescription(props: {
97
+ readonly location: CommandPaletteProjectLocation | undefined;
98
+ readonly workspaceRoot: string;
99
+}) {
100
+ const location = props.location ?? UNKNOWN_PROJECT_LOCATION;
101
+ return (
102
+ <span className="flex min-w-0 items-center gap-1">
103
+ <span className="inline-flex min-w-0 items-center gap-1">
104
+ {location.kind === "remote" ? (
105
+ <EnvironmentMachineIcon
106
+ aria-hidden
107
+ kind={location.machine}
108
+ className={COMMAND_PALETTE_META_ICON_CLASS}
109
+ />
110
+ ) : null}
111
+ <span className="truncate">{location.label}</span>
112
+ </span>
113
+ <CommandPaletteMetaDot />
114
+ <span className="truncate">{props.workspaceRoot}</span>
115
+ </span>
116
+ );
117
+}