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",
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: "provider-health-check-interval",
329 title: "Health check interval",
330 to: "/settings/providers",
331 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
332 providerSettingsOnly: true,
333 },
334 {
335 id: "agent-browser-access",
336 title: "Agent browser access",
337 to: "/settings/integrations",
338 searchTerms: ["allow open drive preview tools sessions"],
339 },
340 {
341 id: "browser-profiles",
342 title: "Browser profiles",
343 to: "/settings/integrations",
344 targetId: "browser",
345 },
346 {
347 id: "browser-default-profile",
348 title: "Default browser profile",
349 to: "/settings/integrations",
350 targetId: "browser-profiles",
351 },
352 {
353 id: "browser-default-viewport",
354 title: "Default browser viewport",
355 to: "/settings/integrations",
356 searchTerms: ["preview size width height device desktop mobile rotate"],
357 },
358 {
359 id: "browser-default-zoom",
360 title: "Default browser zoom",
361 to: "/settings/integrations",
362 searchTerms: ["preview page scale tabs percent"],
363 },
364 {
365 id: "browser-default-appearance",
366 title: "Default browser appearance",
367 to: "/settings/integrations",
368 searchTerms: ["preview color scheme light dark system os"],
369 },
370 {
371 id: "browser-recording-frame-rate",
372 title: "Browser recording frame rate",
373 to: "/settings/integrations",
374 },
375 {
376 id: "browser-link-target",
377 title: "Open links in",
378 to: "/settings/integrations",
379 searchTerms: ["links default browser in-app browser external open"],
380 },
381 {
382 id: "browser-auto-show-floating-preview",
383 title: "Auto-show floating preview",
384 to: "/settings/integrations",
385 searchTerms: ["agent opens browser pop into view hide"],
386 },
387 {
388 id: "source-control",
389 title: "Source control",
390 to: "/settings/source-control",
391 searchTerms: [
392 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
393 ],
394 },
395 {
396 id: "git-fetch-interval",
397 title: "Git fetch interval",
398 to: "/settings/source-control",
399 searchTerms: [
400 "automatic remote branch refresh background credentials security keys seconds off",
401 ],
402 primaryOnly: true,
403 },
404 {
405 id: "source-control-writing-style",
406 title: "Source control writing style",
407 to: "/settings/source-control",
408 searchTerms: [
409 "repository conventions conventional commits custom instructions change descriptions request titles",
410 ],
411 primaryOnly: true,
412 },
413 {
414 id: "follow-change-request-templates",
415 title: "Follow change request templates",
416 to: "/settings/source-control",
417 searchTerms: ["repository pr pull request description structure"],
418 primaryOnly: true,
419 },
420 {
421 id: "source-control-writer-model",
422 title: "Source control writer model",
423 to: "/settings/source-control",
424 searchTerms: [
425 "override generated commit change request pr titles descriptions branch bookmark",
426 ],
427 primaryOnly: true,
428 },
429 {
430 id: "environment-icon",
431 title: "Environment icon",
432 to: "/settings/connections",
433 targetId: "connections-environment",
434 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
435 localBackendManagementOnly: true,
436 },
437 {
438 id: "network-access",
439 title: "Network access",
440 to: "/settings/connections",
441 targetId: "connections-environment",
442 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
443 localBackendManagementOnly: true,
444 },
445 {
446 id: "tailscale-https",
447 title: "Tailscale HTTPS",
448 to: "/settings/connections",
449 targetId: "connections-environment",
450 searchTerms: ["serve magicdns endpoint remote secure network"],
451 desktopOnly: true,
452 localBackendManagementOnly: true,
453 },
454 {
455 id: "wsl-backend",
456 title: "WSL backend",
457 to: "/settings/connections",
458 searchTerms: [
459 "windows subsystem linux distro second server projects stop windows backend restart",
460 ],
461 desktopOnly: true,
462 windowsOnly: true,
463 localBackendManagementOnly: true,
464 wslAvailableOnly: true,
465 },
466 {
467 id: "t3-connect",
468 title: "T3 Connect",
469 to: "/settings/connections",
470 targetId: "connections-environment",
471 searchTerms: ["managed tunnel cloud other devices remote"],
472 desktopOnly: true,
473 cloudOnly: true,
474 },
475 {
476 id: "publish-agent-activity",
477 title: "Publish agent activity",
478 to: "/settings/connections",
479 targetId: "connections-environment",
480 searchTerms: ["mobile push notifications live activities cloud tunnel"],
481 cloudOnly: true,
482 },
483 {
484 id: "connections-environment",
485 title: "This environment",
486 to: "/settings/connections",
487 searchTerms: [
488 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
489 ],
490 },
491 {
492 id: "remote-environments",
493 title: "Remote environments",
494 to: "/settings/connections",
495 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
496 },
497 {
498 id: "archive",
499 title: "Archived threads",
500 to: "/settings/archived",
501 searchTerms: ["restore reopen deleted history projects"],
502 },
503] as const satisfies ReadonlyArray<SettingsSearchItem>;
504
505export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
506
507const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
508
509/**
510 * `id` and `title` props for the element a search item anchors to. Panels
511 * spread (or pick from) this instead of restating the strings, so the catalog
512 * and the rendered settings cannot drift apart.
513 */
514export function searchableSetting(id: SettingsSearchItemId): {
515 readonly id: string;
516 readonly title: string;
517} {
518 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
519 return { id: anchorId, title };
520}
521
522export function filterAvailableSettingsSearchItems(
523 availability: SettingsSearchAvailability,
524): ReadonlyArray<SettingsSearchItem> {
525 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
526 return items.filter(
527 (item) =>
528 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
529 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
530 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
531 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
532 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
533 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
534 );
535}
536
537export function searchSettings(
538 query: string,
539 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
540): ReadonlyArray<SettingsSearchItem> {
541 const normalizedQuery = normalizeSearchText(query);
542 if (normalizedQuery.length === 0) return [];
543 const queryTokens = normalizedQuery.split(" ");
544 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
545
546 return items
547 .flatMap((item, index) => {
548 if (!isElectron && item.desktopOnly === true) return [];
549 if (item.macOnly && !isMacPlatform(platform)) return [];
550 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
551
552 const title = normalizeSearchText(item.title);
553 const fields = [
554 title,
555 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
556 ...(item.searchTerms ?? []).map(normalizeSearchText),
557 ];
558 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
559
560 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
561 const rank =
562 title === normalizedQuery
563 ? 5
564 : title.startsWith(normalizedQuery)
565 ? 4
566 : title.includes(normalizedQuery)
567 ? 3
568 : queryTokens.every((token) => title.includes(token))
569 ? 2
570 : exactPhraseField >= 0
571 ? 1
572 : 0;
573 return [{ item, index, rank }];
574 })
575 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
576 .map(({ item }) => item);
577}