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