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