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

settingsSearch.ts

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