Open History to see the last commit
1import { isElectron } from "~/env";
2import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
3
4export type SettingsPath =
5 | "/settings/projects"
6 | "/settings/general"
7 | "/settings/appearance"
8 | "/settings/keybindings"
9 | "/settings/providers"
10 | "/settings/integrations"
11 | "/settings/source-control"
12 | "/settings/connections"
13 | "/settings/archived";
14
15export interface SettingsSearchItem {
16 readonly id: string;
17 readonly title: string;
18 readonly to: SettingsPath;
19 readonly targetId?: string;
20 /** Descriptions, option labels, and aliases people may remember instead of the title. */
21 readonly searchTerms?: ReadonlyArray<string>;
22 // Its row only renders in the desktop app, so a browser result would land on
23 // an anchor that isn't there.
24 readonly desktopOnly?: boolean;
25 readonly macOnly?: boolean;
26 // Its row only renders on Windows desktop, so other desktop platforms must
27 // not expose a result that points to a missing anchor.
28 readonly windowsOnly?: boolean;
29 readonly cloudOnly?: boolean;
30 readonly primaryOnly?: boolean;
31 readonly providerSettingsOnly?: boolean;
32 readonly localBackendManagementOnly?: boolean;
33 readonly wslAvailableOnly?: boolean;
34 readonly requiresThreadAutoSettlement?: boolean;
35}
36
37export interface SettingsSearchAvailability {
38 readonly hasCloudPublicConfig: boolean;
39 readonly hasPrimaryEnvironment: boolean;
40 readonly hasProviderSettingsEnvironment: boolean;
41 readonly canManageLocalBackend: boolean;
42 readonly isWslSettingsRowVisible: boolean;
43 readonly hasThreadAutoSettlement: boolean;
44}
45
46/**
47 * Section labels in sidebar order. The sidebar nav and the search-result
48 * subtitles both render from this record, so each label exists once.
49 */
50export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
51 "/settings/general": "General",
52 "/settings/appearance": "Appearance",
53 "/settings/projects": "Projects",
54 "/settings/keybindings": "Keybindings",
55 "/settings/providers": "Providers",
56 "/settings/integrations": "Integrations",
57 "/settings/source-control": "Source Control",
58 "/settings/connections": "Connections",
59 "/settings/archived": "Archive",
60};
61
62/**
63 * Searchable settings and stable destinations, in result order. Rows with a
64 * dedicated anchor render their id and title via `searchableSetting`; items
65 * that may not be mounted point at their nearest stable section instead.
66 */
67export const SETTINGS_SEARCH_ITEMS = [
68 {
69 id: "project-defaults",
70 title: "Project defaults and overrides",
71 to: "/settings/projects",
72 searchTerms: [
73 "model workspace browser machines projects inheritance automatic pull checkout grouping actions scripts",
74 ],
75 },
76 {
77 id: "color-scheme",
78 title: "Color scheme",
79 to: "/settings/appearance",
80 searchTerms: ["appearance light dark system mode"],
81 // The scheme tiles sit at the top of the Appearance section.
82 targetId: "appearance",
83 },
84 {
85 id: "theme",
86 title: "Themes",
87 to: "/settings/appearance",
88 searchTerms: ["appearance colors palette custom import"],
89 // Theme cards live directly under the scheme tiles; the section is the
90 // stable scroll destination for both.
91 targetId: "appearance",
92 },
93 {
94 // Prefixed because the slider control already owns the `appearance-contrast` id.
95 id: "setting-appearance-contrast",
96 title: "Contrast",
97 to: "/settings/appearance",
98 searchTerms: ["colors borders interface"],
99 },
100 {
101 // Prefixed because the slider control already owns the `glass-opacity` id.
102 id: "setting-glass-opacity",
103 title: "Glass opacity",
104 to: "/settings/appearance",
105 searchTerms: ["transparent transparency solid menus dialogs composer"],
106 },
107 {
108 id: "panel-animations",
109 title: "Panel animations",
110 to: "/settings/appearance",
111 },
112 {
113 id: "environment-identification",
114 title: "Environment identification",
115 to: "/settings/appearance",
116 searchTerms: ["dev nightly artwork pill label hide none"],
117 // The setting is stage-dependent, so its parent section is the stable destination.
118 targetId: "appearance-interface",
119 },
120 {
121 id: "interface-font",
122 title: "Interface font",
123 to: "/settings/appearance",
124 searchTerms: ["typography family size system sans"],
125 },
126 {
127 id: "prompt-font",
128 title: "Prompt font",
129 to: "/settings/appearance",
130 searchTerms: ["typography family size composer input"],
131 },
132 {
133 id: "code-font",
134 title: "Code font",
135 to: "/settings/appearance",
136 searchTerms: ["typography family size monospace code blocks diffs file previews"],
137 },
138 {
139 id: "terminal-font",
140 title: "Terminal font",
141 to: "/settings/appearance",
142 searchTerms: ["typography family size monospace output"],
143 },
144 {
145 id: "font-smoothing",
146 title: "Font smoothing",
147 to: "/settings/appearance",
148 searchTerms: ["typography text grayscale anti aliasing macos thin"],
149 macOnly: true,
150 },
151 {
152 id: "word-wrap",
153 title: "Word wrap",
154 to: "/settings/appearance",
155 searchTerms: ["long lines code blocks tables diffs file previews"],
156 },
157 {
158 id: "project-grouping",
159 title: "Project grouping",
160 to: "/settings/general",
161 searchTerms: ["combine matching repositories environments sidebar"],
162 },
163 {
164 id: "auto-settle-inactive-threads",
165 title: "Auto-settle inactive threads",
166 to: "/settings/general",
167 searchTerms: ["sidebar inactivity days no activity automatically"],
168 requiresThreadAutoSettlement: true,
169 },
170 {
171 id: "auto-settle-merged-threads",
172 title: "Auto-settle merged threads",
173 to: "/settings/general",
174 searchTerms: ["pull request merge closed automatically sidebar"],
175 requiresThreadAutoSettlement: true,
176 },
177 {
178 id: "days-before-auto-settle",
179 title: "Days of inactivity before auto-settle",
180 to: "/settings/general",
181 targetId: "auto-settle-inactive-threads",
182 searchTerms: ["thread timeout activity sidebar"],
183 requiresThreadAutoSettlement: true,
184 },
185 {
186 id: "time-format",
187 title: "Time format",
188 to: "/settings/general",
189 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
190 },
191 {
192 id: "hide-whitespace-changes",
193 title: "Hide whitespace changes",
194 to: "/settings/general",
195 searchTerms: ["diff ignore spaces edits default"],
196 },
197 {
198 id: "diff-layout",
199 title: "Diff layout",
200 to: "/settings/general",
201 searchTerms: ["stacked split side by side unified inline view"],
202 },
203 {
204 id: "proactive-panels",
205 title: "Proactive panels",
206 to: "/settings/general",
207 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
208 },
209 {
210 id: "skills-in-slash-menu",
211 title: "Show skills in slash menu",
212 to: "/settings/general",
213 searchTerms: ["command menu dollar $ slash /"],
214 },
215 {
216 id: "composer-collapse",
217 title: "Collapse composer on scroll",
218 to: "/settings/general",
219 searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
220 },
221 {
222 id: "provider-update-checks",
223 title: "Provider update checks",
224 to: "/settings/general",
225 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
226 },
227 {
228 id: "continue-threads-after-server-update",
229 title: "Continue threads after restarts",
230 to: "/settings/general",
231 searchTerms: [
232 "resume running active interrupted work restart reboot machine crash desktop update automatically",
233 ],
234 },
235 {
236 id: "background-activity",
237 title: "Background activity",
238 to: "/settings/general",
239 searchTerms: [
240 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
241 ],
242 },
243 {
244 id: "new-threads",
245 title: "New threads",
246 to: "/settings/projects",
247 searchTerms: ["default workspace mode draft local worktree"],
248 },
249 {
250 id: "start-from-origin",
251 title: "Start from origin",
252 to: "/settings/general",
253 searchTerms: ["new worktrees latest matching remote branch local"],
254 },
255 {
256 id: "add-project-starts-in",
257 title: "Add project starts in",
258 to: "/settings/general",
259 searchTerms: ["base directory folder browser path home"],
260 },
261 {
262 id: "unpin-confirmation",
263 title: "Unpin confirmation",
264 to: "/settings/general",
265 searchTerms: ["ask before thread pinned section"],
266 },
267 {
268 id: "archive-confirmation",
269 title: "Archive confirmation",
270 to: "/settings/general",
271 searchTerms: ["ask before thread second click inline action"],
272 },
273 {
274 id: "delete-confirmation",
275 title: "Delete confirmation",
276 to: "/settings/general",
277 searchTerms: ["ask before thread chat history"],
278 },
279 {
280 id: "quit-confirmation",
281 title: "Quit shortcut",
282 to: "/settings/general",
283 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
284 desktopOnly: true,
285 },
286 {
287 id: "text-generation-model",
288 title: "Text generation model",
289 to: "/settings/general",
290 searchTerms: ["generated thread titles source control content default provider"],
291 },
292 {
293 id: "diagnostics",
294 title: "Diagnostics",
295 to: "/settings/general",
296 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
297 },
298 {
299 id: "legacy-plan-mode",
300 title: "Plan mode (legacy)",
301 to: "/settings/general",
302 searchTerms: ["build plan composer old"],
303 },
304 {
305 id: "legacy-context-window-indicator",
306 title: "Context window indicator (legacy)",
307 to: "/settings/general",
308 searchTerms: ["composer meter usage tokens circle old"],
309 },
310 {
311 id: "legacy-token-streaming",
312 title: "Stream token by token (legacy)",
313 to: "/settings/general",
314 searchTerms: ["response output old compatibility"],
315 },
316 {
317 id: "legacy-sidebar",
318 title: "Sidebar (legacy)",
319 to: "/settings/general",
320 searchTerms: ["project thread tree old flat list"],
321 },
322 {
323 id: "keybindings",
324 title: "Keybindings",
325 to: "/settings/keybindings",
326 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
327 },
328 {
329 id: "providers",
330 title: "Providers",
331 to: "/settings/providers",
332 searchTerms: [
333 "agents cli codex claude cursor grok opencode antigravity google sign in sign out install subscription instances authentication api key models configuration binary path config directory endpoint arguments environment variables display name accent color custom favorite hidden auto compact",
334 ],
335 },
336 {
337 id: "usage-providers",
338 title: "Usage providers",
339 to: "/settings/providers",
340 searchTerms: [
341 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
342 ],
343 providerSettingsOnly: true,
344 },
345 {
346 id: "provider-health-check-interval",
347 title: "Health check interval",
348 to: "/settings/providers",
349 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
350 providerSettingsOnly: true,
351 },
352 {
353 id: "agent-browser-access",
354 title: "Agent browser access",
355 to: "/settings/projects",
356 searchTerms: ["allow open drive preview tools sessions"],
357 },
358 {
359 id: "browser-profiles",
360 title: "Browser profiles",
361 to: "/settings/integrations",
362 targetId: "browser",
363 },
364 {
365 id: "browser-default-profile",
366 title: "Default browser profile",
367 to: "/settings/integrations",
368 targetId: "browser-profiles",
369 },
370 {
371 id: "browser-default-viewport",
372 title: "Default browser viewport",
373 to: "/settings/integrations",
374 searchTerms: ["preview size width height device desktop mobile rotate"],
375 },
376 {
377 id: "browser-default-zoom",
378 title: "Default browser zoom",
379 to: "/settings/integrations",
380 searchTerms: ["preview page scale tabs percent"],
381 },
382 {
383 id: "browser-default-appearance",
384 title: "Default browser appearance",
385 to: "/settings/integrations",
386 searchTerms: ["preview color scheme light dark system os"],
387 },
388 {
389 id: "browser-recording-frame-rate",
390 title: "Browser recording frame rate",
391 to: "/settings/integrations",
392 },
393 {
394 id: "browser-link-target",
395 title: "Open links in",
396 to: "/settings/integrations",
397 searchTerms: ["links default browser in-app browser external open"],
398 },
399 {
400 id: "browser-auto-show-floating-preview",
401 title: "Auto-show floating preview",
402 to: "/settings/integrations",
403 searchTerms: ["agent opens browser pop into view hide"],
404 },
405 {
406 id: "source-control",
407 title: "Source control",
408 to: "/settings/source-control",
409 searchTerms: [
410 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
411 ],
412 },
413 {
414 id: "git-fetch-interval",
415 title: "Git fetch interval",
416 to: "/settings/source-control",
417 searchTerms: [
418 "automatic remote branch refresh background credentials security keys seconds off",
419 ],
420 primaryOnly: true,
421 },
422 {
423 id: "source-control-writing-style",
424 title: "Source control writing style",
425 to: "/settings/source-control",
426 searchTerms: [
427 "repository conventions conventional commits custom instructions change descriptions request titles",
428 ],
429 primaryOnly: true,
430 },
431 {
432 id: "follow-change-request-templates",
433 title: "Follow change request templates",
434 to: "/settings/source-control",
435 searchTerms: ["repository pr pull request description structure"],
436 primaryOnly: true,
437 },
438 {
439 id: "source-control-writer-model",
440 title: "Source control writer model",
441 to: "/settings/source-control",
442 searchTerms: [
443 "override generated commit change request pr titles descriptions branch bookmark",
444 ],
445 primaryOnly: true,
446 },
447 {
448 id: "environment-icon",
449 title: "Environment icon",
450 to: "/settings/connections",
451 targetId: "connections-environment",
452 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
453 localBackendManagementOnly: true,
454 },
455 {
456 id: "network-access",
457 title: "Network access",
458 to: "/settings/connections",
459 targetId: "connections-environment",
460 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
461 localBackendManagementOnly: true,
462 },
463 {
464 id: "tailscale-https",
465 title: "Tailscale HTTPS",
466 to: "/settings/connections",
467 targetId: "connections-environment",
468 searchTerms: ["serve magicdns endpoint remote secure network"],
469 desktopOnly: true,
470 localBackendManagementOnly: true,
471 },
472 {
473 id: "wsl-backend",
474 title: "WSL backend",
475 to: "/settings/connections",
476 searchTerms: [
477 "windows subsystem linux distro second server projects stop windows backend restart",
478 ],
479 desktopOnly: true,
480 windowsOnly: true,
481 localBackendManagementOnly: true,
482 wslAvailableOnly: true,
483 },
484 {
485 id: "t3-connect",
486 title: "T3 Connect",
487 to: "/settings/connections",
488 targetId: "connections-environment",
489 searchTerms: ["managed tunnel cloud other devices remote"],
490 desktopOnly: true,
491 cloudOnly: true,
492 },
493 {
494 id: "publish-agent-activity",
495 title: "Publish agent activity",
496 to: "/settings/connections",
497 targetId: "connections-environment",
498 searchTerms: ["mobile push notifications live activities cloud tunnel"],
499 cloudOnly: true,
500 },
501 {
502 id: "connections-environment",
503 title: "This environment",
504 to: "/settings/connections",
505 searchTerms: [
506 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
507 ],
508 },
509 {
510 id: "remote-environments",
511 title: "Remote environments",
512 to: "/settings/connections",
513 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
514 },
515 {
516 id: "load-balancing",
517 title: "Load balancing",
518 to: "/settings/connections",
519 searchTerms: [
520 "automatic machine environment resources cpu memory capacity preference weight shared projects",
521 ],
522 },
523 {
524 id: "archive",
525 title: "Archived threads",
526 to: "/settings/archived",
527 searchTerms: ["restore reopen deleted history projects"],
528 },
529] as const satisfies ReadonlyArray<SettingsSearchItem>;
530
531export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
532
533const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
534
535/**
536 * `id` and `title` props for the element a search item anchors to. Panels
537 * spread (or pick from) this instead of restating the strings, so the catalog
538 * and the rendered settings cannot drift apart.
539 */
540export function searchableSetting(id: SettingsSearchItemId): {
541 readonly id: string;
542 readonly title: string;
543} {
544 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
545 return { id: anchorId, title };
546}
547
548export function filterAvailableSettingsSearchItems(
549 availability: SettingsSearchAvailability,
550): ReadonlyArray<SettingsSearchItem> {
551 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
552 return items.filter(
553 (item) =>
554 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
555 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
556 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
557 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
558 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
559 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
560 );
561}
562
563export function searchSettings(
564 query: string,
565 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
566): ReadonlyArray<SettingsSearchItem> {
567 const normalizedQuery = normalizeSearchText(query);
568 if (normalizedQuery.length === 0) return [];
569 const queryTokens = normalizedQuery.split(" ");
570 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
571
572 return items
573 .flatMap((item, index) => {
574 if (!isElectron && item.desktopOnly === true) return [];
575 if (item.macOnly && !isMacPlatform(platform)) return [];
576 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
577
578 const title = normalizeSearchText(item.title);
579 const fields = [
580 title,
581 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
582 ...(item.searchTerms ?? []).map(normalizeSearchText),
583 ];
584 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
585
586 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
587 const rank =
588 title === normalizedQuery
589 ? 5
590 : title.startsWith(normalizedQuery)
591 ? 4
592 : title.includes(normalizedQuery)
593 ? 3
594 : queryTokens.every((token) => title.includes(token))
595 ? 2
596 : exactPhraseField >= 0
597 ? 1
598 : 0;
599 return [{ item, index, rank }];
600 })
601 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
602 .map(({ item }) => item);
603}