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/scheduled-tasks"
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/keybindings": "Keybindings",
54 "/settings/providers": "Providers",
55 "/settings/integrations": "Integrations",
56 "/settings/scheduled-tasks": "Schedule Tasks",
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: "color-scheme",
70 title: "Color scheme",
71 to: "/settings/appearance",
72 searchTerms: ["appearance light dark system mode"],
73 // The scheme tiles sit at the top of the Appearance section.
74 targetId: "appearance",
75 },
76 {
77 id: "theme",
78 title: "Themes",
79 to: "/settings/appearance",
80 searchTerms: ["appearance colors palette custom import"],
81 // Theme cards live directly under the scheme tiles; the section is the
82 // stable scroll destination for both.
83 targetId: "appearance",
84 },
85 {
86 // Prefixed because the slider control already owns the `appearance-contrast` id.
87 id: "setting-appearance-contrast",
88 title: "Contrast",
89 to: "/settings/appearance",
90 searchTerms: ["colors borders interface"],
91 },
92 {
93 // Prefixed because the slider control already owns the `glass-opacity` id.
94 id: "setting-glass-opacity",
95 title: "Glass opacity",
96 to: "/settings/appearance",
97 searchTerms: ["transparent transparency solid menus dialogs composer"],
98 },
99 {
100 id: "panel-animations",
101 title: "Panel animations",
102 to: "/settings/appearance",
103 },
104 {
105 id: "environment-identification",
106 title: "Environment identification",
107 to: "/settings/appearance",
108 searchTerms: ["dev nightly artwork pill label hide none"],
109 // The setting is stage-dependent, so its parent section is the stable destination.
110 targetId: "appearance-interface",
111 },
112 {
113 id: "interface-font",
114 title: "Interface font",
115 to: "/settings/appearance",
116 searchTerms: ["typography family size system sans"],
117 },
118 {
119 id: "prompt-font",
120 title: "Prompt font",
121 to: "/settings/appearance",
122 searchTerms: ["typography family size composer input"],
123 },
124 {
125 id: "code-font",
126 title: "Code font",
127 to: "/settings/appearance",
128 searchTerms: ["typography family size monospace code blocks diffs file previews"],
129 },
130 {
131 id: "terminal-font",
132 title: "Terminal font",
133 to: "/settings/appearance",
134 searchTerms: ["typography family size monospace output"],
135 },
136 {
137 id: "font-smoothing",
138 title: "Font smoothing",
139 to: "/settings/appearance",
140 searchTerms: ["typography text grayscale anti aliasing macos thin"],
141 macOnly: true,
142 },
143 {
144 id: "word-wrap",
145 title: "Word wrap",
146 to: "/settings/appearance",
147 searchTerms: ["long lines code blocks tables diffs file previews"],
148 },
149 {
150 id: "composer-context",
151 title: "Composer context",
152 to: "/settings/appearance",
153 },
154 {
155 id: "project-grouping",
156 title: "Project grouping",
157 to: "/settings/general",
158 searchTerms: ["combine matching repositories environments sidebar"],
159 },
160 {
161 id: "auto-settle-inactive-threads",
162 title: "Auto-settle inactive threads",
163 to: "/settings/general",
164 searchTerms: ["sidebar inactivity days no activity automatically"],
165 requiresThreadAutoSettlement: true,
166 },
167 {
168 id: "auto-settle-merged-threads",
169 title: "Auto-settle merged threads",
170 to: "/settings/general",
171 searchTerms: ["pull request merge closed automatically sidebar"],
172 requiresThreadAutoSettlement: true,
173 },
174 {
175 id: "days-before-auto-settle",
176 title: "Days of inactivity before auto-settle",
177 to: "/settings/general",
178 targetId: "auto-settle-inactive-threads",
179 searchTerms: ["thread timeout activity sidebar"],
180 requiresThreadAutoSettlement: true,
181 },
182 {
183 id: "time-format",
184 title: "Time format",
185 to: "/settings/general",
186 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
187 },
188 {
189 id: "hide-whitespace-changes",
190 title: "Hide whitespace changes",
191 to: "/settings/general",
192 searchTerms: ["diff ignore spaces edits default"],
193 },
194 {
195 id: "diff-layout",
196 title: "Diff layout",
197 to: "/settings/general",
198 searchTerms: ["stacked split side by side unified inline view"],
199 },
200 {
201 id: "proactive-panels",
202 title: "Proactive panels",
203 to: "/settings/general",
204 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
205 },
206 {
207 id: "skills-in-slash-menu",
208 title: "Show skills in slash menu",
209 to: "/settings/general",
210 searchTerms: ["command menu dollar $ slash /"],
211 },
212 {
213 id: "composer-collapse",
214 title: "Collapse composer",
215 to: "/settings/general",
216 searchTerms: [
217 "composer rest resting unfocus blur focus click away scroll wheel conversation timeline shrink minimize",
218 ],
219 },
220 {
221 id: "provider-update-checks",
222 title: "Provider update checks",
223 to: "/settings/general",
224 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
225 },
226 {
227 id: "continue-threads-after-server-update",
228 title: "Continue threads after restarts",
229 to: "/settings/general",
230 searchTerms: [
231 "resume running active interrupted work restart reboot machine crash desktop update automatically",
232 ],
233 },
234 {
235 id: "background-activity",
236 title: "Background activity",
237 to: "/settings/general",
238 searchTerms: [
239 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
240 ],
241 },
242 {
243 id: "new-threads",
244 title: "New threads",
245 to: "/settings/general",
246 searchTerms: ["default workspace mode draft local worktree"],
247 },
248 {
249 id: "start-from-origin",
250 title: "Start from origin",
251 to: "/settings/general",
252 targetId: "new-threads",
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/integrations",
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: "archive",
517 title: "Archived threads",
518 to: "/settings/archived",
519 searchTerms: ["restore reopen deleted history projects"],
520 },
521] as const satisfies ReadonlyArray<SettingsSearchItem>;
522
523export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
524
525const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
526
527/**
528 * `id` and `title` props for the element a search item anchors to. Panels
529 * spread (or pick from) this instead of restating the strings, so the catalog
530 * and the rendered settings cannot drift apart.
531 */
532export function searchableSetting(id: SettingsSearchItemId): {
533 readonly id: string;
534 readonly title: string;
535} {
536 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
537 return { id: anchorId, title };
538}
539
540export function filterAvailableSettingsSearchItems(
541 availability: SettingsSearchAvailability,
542): ReadonlyArray<SettingsSearchItem> {
543 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
544 return items.filter(
545 (item) =>
546 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
547 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
548 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
549 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
550 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
551 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
552 );
553}
554
555export function searchSettings(
556 query: string,
557 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
558): ReadonlyArray<SettingsSearchItem> {
559 const normalizedQuery = normalizeSearchText(query);
560 if (normalizedQuery.length === 0) return [];
561 const queryTokens = normalizedQuery.split(" ");
562 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
563
564 return items
565 .flatMap((item, index) => {
566 if (!isElectron && item.desktopOnly === true) return [];
567 if (item.macOnly && !isMacPlatform(platform)) return [];
568 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
569
570 const title = normalizeSearchText(item.title);
571 const fields = [
572 title,
573 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
574 ...(item.searchTerms ?? []).map(normalizeSearchText),
575 ];
576 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
577
578 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
579 const rank =
580 title === normalizedQuery
581 ? 5
582 : title.startsWith(normalizedQuery)
583 ? 4
584 : title.includes(normalizedQuery)
585 ? 3
586 : queryTokens.every((token) => title.includes(token))
587 ? 2
588 : exactPhraseField >= 0
589 ? 1
590 : 0;
591 return [{ item, index, rank }];
592 })
593 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
594 .map(({ item }) => item);
595}