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}
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}
43
44/**
45 * Section labels in sidebar order. The sidebar nav and the search-result
46 * subtitles both render from this record, so each label exists once.
47 */
48export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
49 "/settings/general": "General",
50 "/settings/appearance": "Appearance",
51 "/settings/keybindings": "Keybindings",
52 "/settings/providers": "Providers",
53 "/settings/integrations": "Integrations",
54 "/settings/scheduled-tasks": "Schedule Tasks",
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: "environment-identification",
99 title: "Environment identification",
100 to: "/settings/appearance",
101 searchTerms: ["dev nightly artwork pill label hide none"],
102 // The setting is stage-dependent, so its parent section is the stable destination.
103 targetId: "appearance",
104 },
105 {
106 id: "interface-font",
107 title: "Interface font",
108 to: "/settings/appearance",
109 searchTerms: ["typography family size system sans"],
110 },
111 {
112 id: "prompt-font",
113 title: "Prompt font",
114 to: "/settings/appearance",
115 searchTerms: ["typography family size composer input"],
116 },
117 {
118 id: "code-font",
119 title: "Code font",
120 to: "/settings/appearance",
121 searchTerms: ["typography family size monospace code blocks diffs file previews"],
122 },
123 {
124 id: "terminal-font",
125 title: "Terminal font",
126 to: "/settings/appearance",
127 searchTerms: ["typography family size monospace output"],
128 },
129 {
130 id: "font-smoothing",
131 title: "Font smoothing",
132 to: "/settings/appearance",
133 searchTerms: ["typography text grayscale anti aliasing macos thin"],
134 macOnly: true,
135 },
136 {
137 id: "word-wrap",
138 title: "Word wrap",
139 to: "/settings/appearance",
140 searchTerms: ["long lines code blocks tables diffs file previews"],
141 },
142 {
143 id: "composer-context",
144 title: "Composer context",
145 to: "/settings/appearance",
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 },
159 {
160 id: "auto-settle-merged-threads",
161 title: "Auto-settle merged threads",
162 to: "/settings/general",
163 searchTerms: ["pull request merge closed automatically sidebar"],
164 },
165 {
166 id: "days-before-auto-settle",
167 title: "Days of inactivity before auto-settle",
168 to: "/settings/general",
169 targetId: "auto-settle-inactive-threads",
170 searchTerms: ["thread timeout activity sidebar"],
171 },
172 {
173 id: "time-format",
174 title: "Time format",
175 to: "/settings/general",
176 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
177 },
178 {
179 id: "hide-whitespace-changes",
180 title: "Hide whitespace changes",
181 to: "/settings/general",
182 searchTerms: ["diff ignore spaces edits default"],
183 },
184 {
185 id: "skills-in-slash-menu",
186 title: "Show skills in slash menu",
187 to: "/settings/general",
188 searchTerms: ["command menu dollar $ slash /"],
189 },
190 {
191 id: "provider-update-checks",
192 title: "Provider update checks",
193 to: "/settings/general",
194 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
195 },
196 {
197 id: "background-activity",
198 title: "Background activity",
199 to: "/settings/general",
200 searchTerms: [
201 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
202 ],
203 },
204 {
205 id: "new-threads",
206 title: "New threads",
207 to: "/settings/general",
208 searchTerms: ["default workspace mode draft local worktree"],
209 },
210 {
211 id: "start-from-origin",
212 title: "Start from origin",
213 to: "/settings/general",
214 targetId: "new-threads",
215 searchTerms: ["new worktrees latest matching remote branch local"],
216 },
217 {
218 id: "add-project-starts-in",
219 title: "Add project starts in",
220 to: "/settings/general",
221 searchTerms: ["base directory folder browser path home"],
222 },
223 {
224 id: "unpin-confirmation",
225 title: "Unpin confirmation",
226 to: "/settings/general",
227 searchTerms: ["ask before thread pinned section"],
228 },
229 {
230 id: "archive-confirmation",
231 title: "Archive confirmation",
232 to: "/settings/general",
233 searchTerms: ["ask before thread second click inline action"],
234 },
235 {
236 id: "delete-confirmation",
237 title: "Delete confirmation",
238 to: "/settings/general",
239 searchTerms: ["ask before thread chat history"],
240 },
241 {
242 id: "quit-confirmation",
243 title: "Hold to quit",
244 to: "/settings/general",
245 searchTerms: ["confirmation shortcut desktop app exit"],
246 desktopOnly: true,
247 },
248 {
249 id: "text-generation-model",
250 title: "Text generation model",
251 to: "/settings/general",
252 searchTerms: ["generated thread titles source control content default provider"],
253 },
254 {
255 id: "diagnostics",
256 title: "Diagnostics",
257 to: "/settings/general",
258 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
259 },
260 {
261 id: "legacy-plan-mode",
262 title: "Plan mode (legacy)",
263 to: "/settings/general",
264 searchTerms: ["build plan composer old"],
265 },
266 {
267 id: "legacy-token-streaming",
268 title: "Stream token by token (legacy)",
269 to: "/settings/general",
270 searchTerms: ["response output old compatibility"],
271 },
272 {
273 id: "legacy-sidebar",
274 title: "Sidebar (legacy)",
275 to: "/settings/general",
276 searchTerms: ["project thread tree old flat list"],
277 },
278 {
279 id: "keybindings",
280 title: "Keybindings",
281 to: "/settings/keybindings",
282 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
283 },
284 {
285 id: "providers",
286 title: "Providers",
287 to: "/settings/providers",
288 searchTerms: [
289 "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",
290 ],
291 },
292 {
293 id: "provider-health-check-interval",
294 title: "Health check interval",
295 to: "/settings/providers",
296 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
297 providerSettingsOnly: true,
298 },
299 {
300 id: "agent-browser-access",
301 title: "Agent browser access",
302 to: "/settings/integrations",
303 searchTerms: ["allow open drive preview tools sessions"],
304 },
305 {
306 id: "browser-default-viewport",
307 title: "Default browser viewport",
308 to: "/settings/integrations",
309 searchTerms: ["preview size width height device desktop mobile rotate"],
310 },
311 {
312 id: "browser-default-zoom",
313 title: "Default browser zoom",
314 to: "/settings/integrations",
315 searchTerms: ["preview page scale tabs percent"],
316 },
317 {
318 id: "browser-default-appearance",
319 title: "Default browser appearance",
320 to: "/settings/integrations",
321 searchTerms: ["preview color scheme light dark system os"],
322 },
323 {
324 id: "browser-recording-frame-rate",
325 title: "Browser recording frame rate",
326 to: "/settings/integrations",
327 },
328 {
329 id: "browser-auto-show-floating-preview",
330 title: "Auto-show floating preview",
331 to: "/settings/integrations",
332 searchTerms: ["agent opens browser pop into view hide"],
333 },
334 {
335 id: "source-control",
336 title: "Source control",
337 to: "/settings/source-control",
338 searchTerms: [
339 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
340 ],
341 },
342 {
343 id: "git-fetch-interval",
344 title: "Git fetch interval",
345 to: "/settings/source-control",
346 searchTerms: [
347 "automatic remote branch refresh background credentials security keys seconds off",
348 ],
349 primaryOnly: true,
350 },
351 {
352 id: "source-control-writing-style",
353 title: "Source control writing style",
354 to: "/settings/source-control",
355 searchTerms: [
356 "repository conventions conventional commits custom instructions change descriptions request titles",
357 ],
358 primaryOnly: true,
359 },
360 {
361 id: "follow-change-request-templates",
362 title: "Follow change request templates",
363 to: "/settings/source-control",
364 searchTerms: ["repository pr pull request description structure"],
365 primaryOnly: true,
366 },
367 {
368 id: "source-control-writer-model",
369 title: "Source control writer model",
370 to: "/settings/source-control",
371 searchTerms: [
372 "override generated commit change request pr titles descriptions branch bookmark",
373 ],
374 primaryOnly: true,
375 },
376 {
377 id: "network-access",
378 title: "Network access",
379 to: "/settings/connections",
380 targetId: "connections-environment",
381 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
382 localBackendManagementOnly: true,
383 },
384 {
385 id: "tailscale-https",
386 title: "Tailscale HTTPS",
387 to: "/settings/connections",
388 targetId: "connections-environment",
389 searchTerms: ["serve magicdns endpoint remote secure network"],
390 desktopOnly: true,
391 localBackendManagementOnly: true,
392 },
393 {
394 id: "wsl-backend",
395 title: "WSL backend",
396 to: "/settings/connections",
397 searchTerms: [
398 "windows subsystem linux distro second server projects stop windows backend restart",
399 ],
400 desktopOnly: true,
401 windowsOnly: true,
402 localBackendManagementOnly: true,
403 wslAvailableOnly: true,
404 },
405 {
406 id: "t3-connect",
407 title: "T3 Connect",
408 to: "/settings/connections",
409 targetId: "connections-environment",
410 searchTerms: ["managed tunnel cloud other devices remote"],
411 desktopOnly: true,
412 cloudOnly: true,
413 },
414 {
415 id: "publish-agent-activity",
416 title: "Publish agent activity",
417 to: "/settings/connections",
418 targetId: "connections-environment",
419 searchTerms: ["mobile push notifications live activities cloud tunnel"],
420 cloudOnly: true,
421 },
422 {
423 id: "connections-environment",
424 title: "This environment",
425 to: "/settings/connections",
426 searchTerms: [
427 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
428 ],
429 },
430 {
431 id: "remote-environments",
432 title: "Remote environments",
433 to: "/settings/connections",
434 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
435 },
436 {
437 id: "archive",
438 title: "Archived threads",
439 to: "/settings/archived",
440 searchTerms: ["restore reopen deleted history projects"],
441 },
442] as const satisfies ReadonlyArray<SettingsSearchItem>;
443
444export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
445
446const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
447
448/**
449 * `id` and `title` props for the element a search item anchors to. Panels
450 * spread (or pick from) this instead of restating the strings, so the catalog
451 * and the rendered settings cannot drift apart.
452 */
453export function searchableSetting(id: SettingsSearchItemId): {
454 readonly id: string;
455 readonly title: string;
456} {
457 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
458 return { id: anchorId, title };
459}
460
461export function filterAvailableSettingsSearchItems(
462 availability: SettingsSearchAvailability,
463): ReadonlyArray<SettingsSearchItem> {
464 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
465 return items.filter(
466 (item) =>
467 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
468 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
469 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
470 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
471 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible),
472 );
473}
474
475export function searchSettings(
476 query: string,
477 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
478): ReadonlyArray<SettingsSearchItem> {
479 const normalizedQuery = normalizeSearchText(query);
480 if (normalizedQuery.length === 0) return [];
481 const queryTokens = normalizedQuery.split(" ");
482 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
483
484 return items
485 .flatMap((item, index) => {
486 if (!isElectron && item.desktopOnly === true) return [];
487 if (item.macOnly && !isMacPlatform(platform)) return [];
488 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
489
490 const title = normalizeSearchText(item.title);
491 const fields = [
492 title,
493 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
494 ...(item.searchTerms ?? []).map(normalizeSearchText),
495 ];
496 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
497
498 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
499 const rank =
500 title === normalizedQuery
501 ? 5
502 : title.startsWith(normalizedQuery)
503 ? 4
504 : title.includes(normalizedQuery)
505 ? 3
506 : queryTokens.every((token) => title.includes(token))
507 ? 2
508 : exactPhraseField >= 0
509 ? 1
510 : 0;
511 return [{ item, index, rank }];
512 })
513 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
514 .map(({ item }) => item);
515}