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

settingsSearch.ts

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