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