Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settingsSearch.ts

605 lines18.8 KB

1import { isElectron } from "~/env";
2import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
3​
4export type SettingsPath =
5 | "/settings/projects"
6 | "/settings/general"
7 | "/settings/appearance"
8 | "/settings/keybindings"
9 | "/settings/providers"
10 | "/settings/integrations"
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 readonly requiresThreadAutoSettlement?: boolean;
36​
37export interface SettingsSearchAvailability {
38 readonly hasCloudPublicConfig: boolean;
39 readonly hasPrimaryEnvironment: boolean;
40 readonly hasProviderSettingsEnvironment: boolean;
41 readonly canManageLocalBackend: boolean;
42 readonly isWslSettingsRowVisible: boolean;
43 readonly hasThreadAutoSettlement: boolean;
45​
46/**
47 * Section labels in sidebar order. The sidebar nav and the search-result
48 * subtitles both render from this record, so each label exists once.
49 */
50export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
51 "/settings/general": "General",
52 "/settings/appearance": "Appearance",
53 "/settings/projects": "Projects",
54 "/settings/keybindings": "Keybindings",
55 "/settings/providers": "Providers",
56 "/settings/integrations": "Integrations",
57 "/settings/source-control": "Source Control",
58 "/settings/connections": "Connections",
59 "/settings/archived": "Archive",
60};
61​
62/**
63 * Searchable settings and stable destinations, in result order. Rows with a
64 * dedicated anchor render their id and title via `searchableSetting`; items
65 * that may not be mounted point at their nearest stable section instead.
66 */
67export const SETTINGS_SEARCH_ITEMS = [
68 {
69 id: "project-defaults",
70 title: "Project defaults and overrides",
71 to: "/settings/projects",
72 searchTerms: [
73 "model workspace browser machines projects inheritance automatic pull checkout grouping actions scripts",
74 ],
75 },
76 {
77 id: "color-scheme",
78 title: "Color scheme",
79 to: "/settings/appearance",
80 searchTerms: ["appearance light dark system mode"],
81 // The scheme tiles sit at the top of the Appearance section.
82 targetId: "appearance",
83 },
84 {
85 id: "theme",
86 title: "Themes",
87 to: "/settings/appearance",
88 searchTerms: ["appearance colors palette custom import"],
89 // Theme cards live directly under the scheme tiles; the section is the
90 // stable scroll destination for both.
91 targetId: "appearance",
92 },
93 {
94 // Prefixed because the slider control already owns the `appearance-contrast` id.
95 id: "setting-appearance-contrast",
96 title: "Contrast",
97 to: "/settings/appearance",
98 searchTerms: ["colors borders interface"],
99 },
100 {
101 // Prefixed because the slider control already owns the `glass-opacity` id.
102 id: "setting-glass-opacity",
103 title: "Glass opacity",
104 to: "/settings/appearance",
105 searchTerms: ["transparent transparency solid menus dialogs composer"],
106 },
107 {
108 id: "panel-animations",
109 title: "Panel animations",
110 to: "/settings/appearance",
111 },
112 {
113 id: "environment-identification",
114 title: "Environment identification",
115 to: "/settings/appearance",
116 searchTerms: ["dev nightly artwork pill label hide none"],
117 // The setting is stage-dependent, so its parent section is the stable destination.
118 targetId: "appearance-interface",
119 },
120 {
121 id: "interface-font",
122 title: "Interface font",
123 to: "/settings/appearance",
124 searchTerms: ["typography family size system sans"],
125 },
126 {
127 id: "prompt-font",
128 title: "Prompt font",
129 to: "/settings/appearance",
130 searchTerms: ["typography family size composer input"],
131 },
132 {
133 id: "code-font",
134 title: "Code font",
135 to: "/settings/appearance",
136 searchTerms: ["typography family size monospace code blocks diffs file previews"],
137 },
138 {
139 id: "terminal-font",
140 title: "Terminal font",
141 to: "/settings/appearance",
142 searchTerms: ["typography family size monospace output"],
143 },
144 {
145 id: "font-smoothing",
146 title: "Font smoothing",
147 to: "/settings/appearance",
148 searchTerms: ["typography text grayscale anti aliasing macos thin"],
149 macOnly: true,
150 },
151 {
152 id: "word-wrap",
153 title: "Word wrap",
154 to: "/settings/appearance",
155 searchTerms: ["long lines code blocks tables diffs file previews"],
156 },
157 {
158 id: "project-grouping",
159 title: "Project grouping",
160 to: "/settings/general",
161 searchTerms: ["combine matching repositories environments sidebar"],
162 },
163 {
164 id: "auto-settle-inactive-threads",
165 title: "Auto-settle inactive threads",
166 to: "/settings/general",
167 searchTerms: ["sidebar inactivity days no activity automatically"],
168 requiresThreadAutoSettlement: true,
169 },
170 {
171 id: "auto-settle-merged-threads",
172 title: "Auto-settle merged threads",
173 to: "/settings/general",
174 searchTerms: ["pull request merge closed automatically sidebar"],
175 requiresThreadAutoSettlement: true,
176 },
177 {
178 id: "days-before-auto-settle",
179 title: "Days of inactivity before auto-settle",
180 to: "/settings/general",
181 targetId: "auto-settle-inactive-threads",
182 searchTerms: ["thread timeout activity sidebar"],
183 requiresThreadAutoSettlement: true,
184 },
185 {
186 id: "time-format",
187 title: "Time format",
188 to: "/settings/general",
189 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
190 },
191 {
192 id: "hide-whitespace-changes",
193 title: "Hide whitespace changes",
194 to: "/settings/general",
195 searchTerms: ["diff ignore spaces edits default"],
196 },
197 {
198 id: "diff-layout",
199 title: "Diff layout",
200 to: "/settings/general",
201 searchTerms: ["stacked split side by side unified inline view"],
202 },
203 {
204 id: "proactive-panels",
205 title: "Proactive panels",
206 to: "/settings/general",
207 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
208 },
209 {
210 id: "skills-in-slash-menu",
211 title: "Show skills in slash menu",
212 to: "/settings/general",
213 searchTerms: ["command menu dollar $ slash /"],
214 },
215 {
216 id: "composer-collapse",
217 title: "Collapse composer",
218 to: "/settings/general",
219 searchTerms: [
220 "composer rest resting unfocus blur focus click away scroll wheel conversation timeline shrink minimize",
221 ],
222 },
223 {
224 id: "provider-update-checks",
225 title: "Provider update checks",
226 to: "/settings/general",
227 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
228 },
229 {
230 id: "continue-threads-after-server-update",
231 title: "Continue threads after restarts",
232 to: "/settings/general",
233 searchTerms: [
234 "resume running active interrupted work restart reboot machine crash desktop update automatically",
235 ],
236 },
237 {
238 id: "background-activity",
239 title: "Background activity",
240 to: "/settings/general",
241 searchTerms: [
242 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
243 ],
244 },
245 {
246 id: "new-threads",
247 title: "New threads",
248 to: "/settings/projects",
249 searchTerms: ["default workspace mode draft local worktree"],
250 },
251 {
252 id: "start-from-origin",
253 title: "Start from origin",
254 to: "/settings/general",
255 searchTerms: ["new worktrees latest matching remote branch local"],
256 },
257 {
258 id: "add-project-starts-in",
259 title: "Add project starts in",
260 to: "/settings/general",
261 searchTerms: ["base directory folder browser path home"],
262 },
263 {
264 id: "unpin-confirmation",
265 title: "Unpin confirmation",
266 to: "/settings/general",
267 searchTerms: ["ask before thread pinned section"],
268 },
269 {
270 id: "archive-confirmation",
271 title: "Archive confirmation",
272 to: "/settings/general",
273 searchTerms: ["ask before thread second click inline action"],
274 },
275 {
276 id: "delete-confirmation",
277 title: "Delete confirmation",
278 to: "/settings/general",
279 searchTerms: ["ask before thread chat history"],
280 },
281 {
282 id: "quit-confirmation",
283 title: "Quit shortcut",
284 to: "/settings/general",
285 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
286 desktopOnly: true,
287 },
288 {
289 id: "text-generation-model",
290 title: "Text generation model",
291 to: "/settings/general",
292 searchTerms: ["generated thread titles source control content default provider"],
293 },
294 {
295 id: "diagnostics",
296 title: "Diagnostics",
297 to: "/settings/general",
298 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
299 },
300 {
301 id: "legacy-plan-mode",
302 title: "Plan mode (legacy)",
303 to: "/settings/general",
304 searchTerms: ["build plan composer old"],
305 },
306 {
307 id: "legacy-context-window-indicator",
308 title: "Context window indicator (legacy)",
309 to: "/settings/general",
310 searchTerms: ["composer meter usage tokens circle old"],
311 },
312 {
313 id: "legacy-token-streaming",
314 title: "Stream token by token (legacy)",
315 to: "/settings/general",
316 searchTerms: ["response output old compatibility"],
317 },
318 {
319 id: "legacy-sidebar",
320 title: "Sidebar (legacy)",
321 to: "/settings/general",
322 searchTerms: ["project thread tree old flat list"],
323 },
324 {
325 id: "keybindings",
326 title: "Keybindings",
327 to: "/settings/keybindings",
328 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
329 },
330 {
331 id: "providers",
332 title: "Providers",
333 to: "/settings/providers",
334 searchTerms: [
335 "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",
336 ],
337 },
338 {
339 id: "usage-providers",
340 title: "Usage providers",
341 to: "/settings/providers",
342 searchTerms: [
343 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
344 ],
345 providerSettingsOnly: true,
346 },
347 {
348 id: "provider-health-check-interval",
349 title: "Health check interval",
350 to: "/settings/providers",
351 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
352 providerSettingsOnly: true,
353 },
354 {
355 id: "agent-browser-access",
356 title: "Agent browser access",
357 to: "/settings/projects",
358 searchTerms: ["allow open drive preview tools sessions"],
359 },
360 {
361 id: "browser-profiles",
362 title: "Browser profiles",
363 to: "/settings/integrations",
364 targetId: "browser",
365 },
366 {
367 id: "browser-default-profile",
368 title: "Default browser profile",
369 to: "/settings/integrations",
370 targetId: "browser-profiles",
371 },
372 {
373 id: "browser-default-viewport",
374 title: "Default browser viewport",
375 to: "/settings/integrations",
376 searchTerms: ["preview size width height device desktop mobile rotate"],
377 },
378 {
379 id: "browser-default-zoom",
380 title: "Default browser zoom",
381 to: "/settings/integrations",
382 searchTerms: ["preview page scale tabs percent"],
383 },
384 {
385 id: "browser-default-appearance",
386 title: "Default browser appearance",
387 to: "/settings/integrations",
388 searchTerms: ["preview color scheme light dark system os"],
389 },
390 {
391 id: "browser-recording-frame-rate",
392 title: "Browser recording frame rate",
393 to: "/settings/integrations",
394 },
395 {
396 id: "browser-link-target",
397 title: "Open links in",
398 to: "/settings/integrations",
399 searchTerms: ["links default browser in-app browser external open"],
400 },
401 {
402 id: "browser-auto-show-floating-preview",
403 title: "Auto-show floating preview",
404 to: "/settings/integrations",
405 searchTerms: ["agent opens browser pop into view hide"],
406 },
407 {
408 id: "source-control",
409 title: "Source control",
410 to: "/settings/source-control",
411 searchTerms: [
412 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
413 ],
414 },
415 {
416 id: "git-fetch-interval",
417 title: "Git fetch interval",
418 to: "/settings/source-control",
419 searchTerms: [
420 "automatic remote branch refresh background credentials security keys seconds off",
421 ],
422 primaryOnly: true,
423 },
424 {
425 id: "source-control-writing-style",
426 title: "Source control writing style",
427 to: "/settings/source-control",
428 searchTerms: [
429 "repository conventions conventional commits custom instructions change descriptions request titles",
430 ],
431 primaryOnly: true,
432 },
433 {
434 id: "follow-change-request-templates",
435 title: "Follow change request templates",
436 to: "/settings/source-control",
437 searchTerms: ["repository pr pull request description structure"],
438 primaryOnly: true,
439 },
440 {
441 id: "source-control-writer-model",
442 title: "Source control writer model",
443 to: "/settings/source-control",
444 searchTerms: [
445 "override generated commit change request pr titles descriptions branch bookmark",
446 ],
447 primaryOnly: true,
448 },
449 {
450 id: "environment-icon",
451 title: "Environment icon",
452 to: "/settings/connections",
453 targetId: "connections-environment",
454 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
455 localBackendManagementOnly: true,
456 },
457 {
458 id: "network-access",
459 title: "Network access",
460 to: "/settings/connections",
461 targetId: "connections-environment",
462 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
463 localBackendManagementOnly: true,
464 },
465 {
466 id: "tailscale-https",
467 title: "Tailscale HTTPS",
468 to: "/settings/connections",
469 targetId: "connections-environment",
470 searchTerms: ["serve magicdns endpoint remote secure network"],
471 desktopOnly: true,
472 localBackendManagementOnly: true,
473 },
474 {
475 id: "wsl-backend",
476 title: "WSL backend",
477 to: "/settings/connections",
478 searchTerms: [
479 "windows subsystem linux distro second server projects stop windows backend restart",
480 ],
481 desktopOnly: true,
482 windowsOnly: true,
483 localBackendManagementOnly: true,
484 wslAvailableOnly: true,
485 },
486 {
487 id: "t3-connect",
488 title: "T3 Connect",
489 to: "/settings/connections",
490 targetId: "connections-environment",
491 searchTerms: ["managed tunnel cloud other devices remote"],
492 desktopOnly: true,
493 cloudOnly: true,
494 },
495 {
496 id: "publish-agent-activity",
497 title: "Publish agent activity",
498 to: "/settings/connections",
499 targetId: "connections-environment",
500 searchTerms: ["mobile push notifications live activities cloud tunnel"],
501 cloudOnly: true,
502 },
503 {
504 id: "connections-environment",
505 title: "This environment",
506 to: "/settings/connections",
507 searchTerms: [
508 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
509 ],
510 },
511 {
512 id: "remote-environments",
513 title: "Remote environments",
514 to: "/settings/connections",
515 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
516 },
517 {
518 id: "load-balancing",
519 title: "Load balancing",
520 to: "/settings/connections",
521 searchTerms: [
522 "automatic machine environment resources cpu memory capacity preference weight shared projects",
523 ],
524 },
525 {
526 id: "archive",
527 title: "Archived threads",
528 to: "/settings/archived",
529 searchTerms: ["restore reopen deleted history projects"],
530 },
531] as const satisfies ReadonlyArray<SettingsSearchItem>;
532​
533export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
534​
535const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
536​
537/**
538 * `id` and `title` props for the element a search item anchors to. Panels
539 * spread (or pick from) this instead of restating the strings, so the catalog
540 * and the rendered settings cannot drift apart.
541 */
542export function searchableSetting(id: SettingsSearchItemId): {
543 readonly id: string;
544 readonly title: string;
545} {
546 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
547 return { id: anchorId, title };
549​
550export function filterAvailableSettingsSearchItems(
551 availability: SettingsSearchAvailability,
552): ReadonlyArray<SettingsSearchItem> {
553 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
554 return items.filter(
555 (item) =>
556 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
557 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
558 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
559 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
560 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
561 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
562 );
564​
565export function searchSettings(
566 query: string,
567 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
568): ReadonlyArray<SettingsSearchItem> {
569 const normalizedQuery = normalizeSearchText(query);
570 if (normalizedQuery.length === 0) return [];
571 const queryTokens = normalizedQuery.split(" ");
572 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
573​
574 return items
575 .flatMap((item, index) => {
576 if (!isElectron && item.desktopOnly === true) return [];
577 if (item.macOnly && !isMacPlatform(platform)) return [];
578 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
579​
580 const title = normalizeSearchText(item.title);
581 const fields = [
582 title,
583 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
584 ...(item.searchTerms ?? []).map(normalizeSearchText),
585 ];
586 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
587​
588 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
589 const rank =
590 title === normalizedQuery
591 ? 5
592 : title.startsWith(normalizedQuery)
593 ? 4
594 : title.includes(normalizedQuery)
595 ? 3
596 : queryTokens.every((token) => title.includes(token))
597 ? 2
598 : exactPhraseField >= 0
599 ? 1
600 : 0;
601 return [{ item, index, rank }];
602 })
603 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
604 .map(({ item }) => item);