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