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