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 server updates",
222 to: "/settings/general",
223 searchTerms: ["resume running active work restart desktop update automatically"],
224 },
225 {
226 id: "background-activity",
227 title: "Background activity",
228 to: "/settings/general",
229 searchTerms: [
230 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
231 ],
232 },
233 {
234 id: "new-threads",
235 title: "New threads",
236 to: "/settings/general",
237 searchTerms: ["default workspace mode draft local worktree"],
238 },
239 {
240 id: "start-from-origin",
241 title: "Start from origin",
242 to: "/settings/general",
243 targetId: "new-threads",
244 searchTerms: ["new worktrees latest matching remote branch local"],
245 },
246 {
247 id: "add-project-starts-in",
248 title: "Add project starts in",
249 to: "/settings/general",
250 searchTerms: ["base directory folder browser path home"],
251 },
252 {
253 id: "unpin-confirmation",
254 title: "Unpin confirmation",
255 to: "/settings/general",
256 searchTerms: ["ask before thread pinned section"],
257 },
258 {
259 id: "archive-confirmation",
260 title: "Archive confirmation",
261 to: "/settings/general",
262 searchTerms: ["ask before thread second click inline action"],
263 },
264 {
265 id: "delete-confirmation",
266 title: "Delete confirmation",
267 to: "/settings/general",
268 searchTerms: ["ask before thread chat history"],
269 },
270 {
271 id: "quit-confirmation",
272 title: "Quit shortcut",
273 to: "/settings/general",
274 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
275 desktopOnly: true,
276 },
277 {
278 id: "text-generation-model",
279 title: "Text generation model",
280 to: "/settings/general",
281 searchTerms: ["generated thread titles source control content default provider"],
282 },
283 {
284 id: "diagnostics",
285 title: "Diagnostics",
286 to: "/settings/general",
287 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
288 },
289 {
290 id: "legacy-plan-mode",
291 title: "Plan mode (legacy)",
292 to: "/settings/general",
293 searchTerms: ["build plan composer old"],
294 },
295 {
296 id: "legacy-context-window-indicator",
297 title: "Context window indicator (legacy)",
298 to: "/settings/general",
299 searchTerms: ["composer meter usage tokens circle old"],
300 },
301 {
302 id: "legacy-token-streaming",
303 title: "Stream token by token (legacy)",
304 to: "/settings/general",
305 searchTerms: ["response output old compatibility"],
306 },
307 {
308 id: "legacy-sidebar",
309 title: "Sidebar (legacy)",
310 to: "/settings/general",
311 searchTerms: ["project thread tree old flat list"],
312 },
313 {
314 id: "keybindings",
315 title: "Keybindings",
316 to: "/settings/keybindings",
317 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
318 },
319 {
320 id: "providers",
321 title: "Providers",
322 to: "/settings/providers",
323 searchTerms: [
324 "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",
325 ],
326 },
327 {
328 id: "usage-providers",
329 title: "Usage providers",
330 to: "/settings/providers",
331 searchTerms: [
332 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
333 ],
334 providerSettingsOnly: true,
335 },
336 {
337 id: "provider-health-check-interval",
338 title: "Health check interval",
339 to: "/settings/providers",
340 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
341 providerSettingsOnly: true,
342 },
343 {
344 id: "agent-browser-access",
345 title: "Agent browser access",
346 to: "/settings/integrations",
347 searchTerms: ["allow open drive preview tools sessions"],
348 },
349 {
350 id: "browser-profiles",
351 title: "Browser profiles",
352 to: "/settings/integrations",
353 targetId: "browser",
354 },
355 {
356 id: "browser-default-profile",
357 title: "Default browser profile",
358 to: "/settings/integrations",
359 targetId: "browser-profiles",
360 },
361 {
362 id: "browser-default-viewport",
363 title: "Default browser viewport",
364 to: "/settings/integrations",
365 searchTerms: ["preview size width height device desktop mobile rotate"],
366 },
367 {
368 id: "browser-default-zoom",
369 title: "Default browser zoom",
370 to: "/settings/integrations",
371 searchTerms: ["preview page scale tabs percent"],
372 },
373 {
374 id: "browser-default-appearance",
375 title: "Default browser appearance",
376 to: "/settings/integrations",
377 searchTerms: ["preview color scheme light dark system os"],
378 },
379 {
380 id: "browser-recording-frame-rate",
381 title: "Browser recording frame rate",
382 to: "/settings/integrations",
383 },
384 {
385 id: "browser-link-target",
386 title: "Open links in",
387 to: "/settings/integrations",
388 searchTerms: ["links default browser in-app browser external open"],
389 },
390 {
391 id: "browser-auto-show-floating-preview",
392 title: "Auto-show floating preview",
393 to: "/settings/integrations",
394 searchTerms: ["agent opens browser pop into view hide"],
395 },
396 {
397 id: "source-control",
398 title: "Source control",
399 to: "/settings/source-control",
400 searchTerms: [
401 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
402 ],
403 },
404 {
405 id: "git-fetch-interval",
406 title: "Git fetch interval",
407 to: "/settings/source-control",
408 searchTerms: [
409 "automatic remote branch refresh background credentials security keys seconds off",
410 ],
411 primaryOnly: true,
412 },
413 {
414 id: "source-control-writing-style",
415 title: "Source control writing style",
416 to: "/settings/source-control",
417 searchTerms: [
418 "repository conventions conventional commits custom instructions change descriptions request titles",
419 ],
420 primaryOnly: true,
421 },
422 {
423 id: "follow-change-request-templates",
424 title: "Follow change request templates",
425 to: "/settings/source-control",
426 searchTerms: ["repository pr pull request description structure"],
427 primaryOnly: true,
428 },
429 {
430 id: "source-control-writer-model",
431 title: "Source control writer model",
432 to: "/settings/source-control",
433 searchTerms: [
434 "override generated commit change request pr titles descriptions branch bookmark",
435 ],
436 primaryOnly: true,
437 },
438 {
439 id: "environment-icon",
440 title: "Environment icon",
441 to: "/settings/connections",
442 targetId: "connections-environment",
443 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
444 localBackendManagementOnly: true,
445 },
446 {
447 id: "network-access",
448 title: "Network access",
449 to: "/settings/connections",
450 targetId: "connections-environment",
451 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
452 localBackendManagementOnly: true,
453 },
454 {
455 id: "tailscale-https",
456 title: "Tailscale HTTPS",
457 to: "/settings/connections",
458 targetId: "connections-environment",
459 searchTerms: ["serve magicdns endpoint remote secure network"],
460 desktopOnly: true,
461 localBackendManagementOnly: true,
462 },
463 {
464 id: "wsl-backend",
465 title: "WSL backend",
466 to: "/settings/connections",
467 searchTerms: [
468 "windows subsystem linux distro second server projects stop windows backend restart",
469 ],
470 desktopOnly: true,
471 windowsOnly: true,
472 localBackendManagementOnly: true,
473 wslAvailableOnly: true,
474 },
475 {
476 id: "t3-connect",
477 title: "T3 Connect",
478 to: "/settings/connections",
479 targetId: "connections-environment",
480 searchTerms: ["managed tunnel cloud other devices remote"],
481 desktopOnly: true,
482 cloudOnly: true,
483 },
484 {
485 id: "publish-agent-activity",
486 title: "Publish agent activity",
487 to: "/settings/connections",
488 targetId: "connections-environment",
489 searchTerms: ["mobile push notifications live activities cloud tunnel"],
490 cloudOnly: true,
491 },
492 {
493 id: "connections-environment",
494 title: "This environment",
495 to: "/settings/connections",
496 searchTerms: [
497 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
498 ],
499 },
500 {
501 id: "remote-environments",
502 title: "Remote environments",
503 to: "/settings/connections",
504 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
505 },
506 {
507 id: "archive",
508 title: "Archived threads",
509 to: "/settings/archived",
510 searchTerms: ["restore reopen deleted history projects"],
511 },
512] as const satisfies ReadonlyArray<SettingsSearchItem>;
513
514export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
515
516const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
517
518/**
519 * `id` and `title` props for the element a search item anchors to. Panels
520 * spread (or pick from) this instead of restating the strings, so the catalog
521 * and the rendered settings cannot drift apart.
522 */
523export function searchableSetting(id: SettingsSearchItemId): {
524 readonly id: string;
525 readonly title: string;
526} {
527 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
528 return { id: anchorId, title };
529}
530
531export function filterAvailableSettingsSearchItems(
532 availability: SettingsSearchAvailability,
533): ReadonlyArray<SettingsSearchItem> {
534 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
535 return items.filter(
536 (item) =>
537 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
538 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
539 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
540 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
541 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
542 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
543 );
544}
545
546export function searchSettings(
547 query: string,
548 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
549): ReadonlyArray<SettingsSearchItem> {
550 const normalizedQuery = normalizeSearchText(query);
551 if (normalizedQuery.length === 0) return [];
552 const queryTokens = normalizedQuery.split(" ");
553 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
554
555 return items
556 .flatMap((item, index) => {
557 if (!isElectron && item.desktopOnly === true) return [];
558 if (item.macOnly && !isMacPlatform(platform)) return [];
559 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
560
561 const title = normalizeSearchText(item.title);
562 const fields = [
563 title,
564 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
565 ...(item.searchTerms ?? []).map(normalizeSearchText),
566 ];
567 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
568
569 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
570 const rank =
571 title === normalizedQuery
572 ? 5
573 : title.startsWith(normalizedQuery)
574 ? 4
575 : title.includes(normalizedQuery)
576 ? 3
577 : queryTokens.every((token) => title.includes(token))
578 ? 2
579 : exactPhraseField >= 0
580 ? 1
581 : 0;
582 return [{ item, index, rank }];
583 })
584 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
585 .map(({ item }) => item);
586}