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

settingsSearch.ts

650 lines20.0 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: "new-threads",
253 title: "New threads",
254 to: "/settings/projects",
255 searchTerms: ["default workspace mode draft local worktree"],
256 },
257 {
258 id: "start-from-origin",
259 title: "Start from origin",
260 to: "/settings/general",
261 searchTerms: ["new worktrees latest matching remote branch local"],
262 },
263 {
264 id: "add-project-starts-in",
265 title: "Add project starts in",
266 to: "/settings/general",
267 searchTerms: ["base directory folder browser path home"],
268 },
269 {
270 id: "unpin-confirmation",
271 title: "Unpin confirmation",
272 to: "/settings/general",
273 searchTerms: ["ask before thread pinned section"],
274 },
275 {
276 id: "archive-confirmation",
277 title: "Archive confirmation",
278 to: "/settings/general",
279 searchTerms: ["ask before thread second click inline action"],
280 },
281 {
282 id: "delete-confirmation",
283 title: "Delete confirmation",
284 to: "/settings/general",
285 searchTerms: ["ask before thread chat history"],
286 },
287 {
288 id: "quit-confirmation",
289 title: "Quit shortcut",
290 to: "/settings/general",
291 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
292 desktopOnly: true,
293 },
294 {
295 id: "text-generation-model",
296 title: "Text generation model",
297 to: "/settings/general",
298 searchTerms: ["generated thread titles source control content default provider"],
299 },
300 {
301 id: "diagnostics",
302 title: "Diagnostics",
303 to: "/settings/general",
304 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
305 },
306 {
307 id: "legacy-plan-mode",
308 title: "Plan mode (legacy)",
309 to: "/settings/general",
310 searchTerms: ["build plan composer old"],
311 },
312 {
313 id: "legacy-context-window-indicator",
314 title: "Context window indicator (legacy)",
315 to: "/settings/general",
316 searchTerms: ["composer meter usage tokens circle old"],
317 },
318 {
319 id: "legacy-token-streaming",
320 title: "Stream token by token (legacy)",
321 to: "/settings/general",
322 searchTerms: ["response output old compatibility"],
323 },
324 {
325 id: "legacy-sidebar",
326 title: "Sidebar (legacy)",
327 to: "/settings/general",
328 searchTerms: ["project thread tree old flat list"],
329 },
330 {
331 id: "keybindings",
332 title: "Keybindings",
333 to: "/settings/keybindings",
334 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
335 },
336 {
337 id: "snap-shot-enabled",
338 title: "SnapShots",
339 searchTerms: ["window capture screenshot"],
340 to: "/settings/snap-shot",
341 },
342 {
343 id: "snap-shot-accessibility",
344 title: "Include app text",
345 to: "/settings/snap-shot",
346 targetId: "snap-shot-enabled",
347 searchTerms: [
348 "capture accessibility data text UI structure elements privacy omit agent context",
349 ],
350 },
351 {
352 id: "snap-shot-shortcut",
353 title: "Capture shortcut",
354 to: "/settings/snap-shot",
355 targetId: "snap-shot-enabled",
356 },
357 {
358 id: "snap-shot-sound",
359 title: "Capture sound",
360 to: "/settings/snap-shot",
361 targetId: "snap-shot-enabled",
362 },
363 {
364 id: "snap-shot-flash",
365 title: "Capture flash",
366 to: "/settings/snap-shot",
367 targetId: "snap-shot-enabled",
368 },
369 {
370 id: "snap-shot-animations",
371 title: "Capture animations",
372 to: "/settings/snap-shot",
373 targetId: "snap-shot-enabled",
374 },
375 {
376 id: "providers",
377 title: "Providers",
378 to: "/settings/providers",
379 searchTerms: [
380 "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",
381 ],
382 },
383 {
384 id: "usage-providers",
385 title: "Usage providers",
386 to: "/settings/providers",
387 searchTerms: [
388 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
389 ],
390 providerSettingsOnly: true,
391 },
392 {
393 id: "provider-health-check-interval",
394 title: "Health check interval",
395 to: "/settings/providers",
396 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
397 providerSettingsOnly: true,
398 },
399 {
400 id: "agent-browser-access",
401 title: "Agent browser access",
402 to: "/settings/projects",
403 searchTerms: ["allow open drive preview tools sessions"],
404 },
405 {
406 id: "browser-profiles",
407 title: "Browser profiles",
408 to: "/settings/integrations",
409 targetId: "browser",
410 },
411 {
412 id: "browser-default-profile",
413 title: "Default browser profile",
414 to: "/settings/integrations",
415 targetId: "browser-profiles",
416 },
417 {
418 id: "browser-default-viewport",
419 title: "Default browser viewport",
420 to: "/settings/integrations",
421 searchTerms: ["preview size width height device desktop mobile rotate"],
422 },
423 {
424 id: "browser-default-zoom",
425 title: "Default browser zoom",
426 to: "/settings/integrations",
427 searchTerms: ["preview page scale tabs percent"],
428 },
429 {
430 id: "browser-default-appearance",
431 title: "Default browser appearance",
432 to: "/settings/integrations",
433 searchTerms: ["preview color scheme light dark system os"],
434 },
435 {
436 id: "browser-recording-frame-rate",
437 title: "Browser recording frame rate",
438 to: "/settings/integrations",
439 },
440 {
441 id: "browser-link-target",
442 title: "Open links in",
443 to: "/settings/integrations",
444 searchTerms: ["links default browser in-app browser external open"],
445 },
446 {
447 id: "browser-auto-show-floating-preview",
448 title: "Auto-show floating preview",
449 to: "/settings/integrations",
450 searchTerms: ["agent opens browser pop into view hide"],
451 },
452 {
453 id: "source-control",
454 title: "Source control",
455 to: "/settings/source-control",
456 searchTerms: [
457 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
458 ],
459 },
460 {
461 id: "git-fetch-interval",
462 title: "Git fetch interval",
463 to: "/settings/source-control",
464 searchTerms: [
465 "automatic remote branch refresh background credentials security keys seconds off",
466 ],
467 primaryOnly: true,
468 },
469 {
470 id: "source-control-writing-style",
471 title: "Source control writing style",
472 to: "/settings/source-control",
473 searchTerms: [
474 "repository conventions conventional commits custom instructions change descriptions request titles",
475 ],
476 primaryOnly: true,
477 },
478 {
479 id: "follow-change-request-templates",
480 title: "Follow change request templates",
481 to: "/settings/source-control",
482 searchTerms: ["repository pr pull request description structure"],
483 primaryOnly: true,
484 },
485 {
486 id: "source-control-writer-model",
487 title: "Source control writer model",
488 to: "/settings/source-control",
489 searchTerms: [
490 "override generated commit change request pr titles descriptions branch bookmark",
491 ],
492 primaryOnly: true,
493 },
494 {
495 id: "environment-icon",
496 title: "Environment icon",
497 to: "/settings/connections",
498 targetId: "connections-environment",
499 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
500 localBackendManagementOnly: true,
501 },
502 {
503 id: "network-access",
504 title: "Network access",
505 to: "/settings/connections",
506 targetId: "connections-environment",
507 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
508 localBackendManagementOnly: true,
509 },
510 {
511 id: "tailscale-https",
512 title: "Tailscale HTTPS",
513 to: "/settings/connections",
514 targetId: "connections-environment",
515 searchTerms: ["serve magicdns endpoint remote secure network"],
516 desktopOnly: true,
517 localBackendManagementOnly: true,
518 },
519 {
520 id: "wsl-backend",
521 title: "WSL backend",
522 to: "/settings/connections",
523 searchTerms: [
524 "windows subsystem linux distro second server projects stop windows backend restart",
525 ],
526 desktopOnly: true,
527 windowsOnly: true,
528 localBackendManagementOnly: true,
529 wslAvailableOnly: true,
530 },
531 {
532 id: "t3-connect",
533 title: "T3 Connect",
534 to: "/settings/connections",
535 targetId: "connections-environment",
536 searchTerms: ["managed tunnel cloud other devices remote"],
537 desktopOnly: true,
538 cloudOnly: true,
539 },
540 {
541 id: "publish-agent-activity",
542 title: "Publish agent activity",
543 to: "/settings/connections",
544 targetId: "connections-environment",
545 searchTerms: ["mobile push notifications live activities cloud tunnel"],
546 cloudOnly: true,
547 },
548 {
549 id: "connections-environment",
550 title: "This environment",
551 to: "/settings/connections",
552 searchTerms: [
553 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
554 ],
555 },
556 {
557 id: "remote-environments",
558 title: "Remote environments",
559 to: "/settings/connections",
560 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
561 },
562 {
563 id: "load-balancing",
564 title: "Load balancing",
565 to: "/settings/connections",
566 searchTerms: [
567 "automatic machine environment resources cpu memory capacity preference weight shared projects",
568 ],
569 },
570 {
571 id: "archive",
572 title: "Archived threads",
573 to: "/settings/archived",
574 searchTerms: ["restore reopen deleted history projects"],
575 },
576] as const satisfies ReadonlyArray<SettingsSearchItem>;
577​
578export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
579​
580const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
581​
582/**
583 * `id` and `title` props for the element a search item anchors to. Panels
584 * spread (or pick from) this instead of restating the strings, so the catalog
585 * and the rendered settings cannot drift apart.
586 */
587export function searchableSetting(id: SettingsSearchItemId): {
588 readonly id: string;
589 readonly title: string;
590} {
591 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
592 return { id: anchorId, title };
594​
595export function filterAvailableSettingsSearchItems(
596 availability: SettingsSearchAvailability,
597): ReadonlyArray<SettingsSearchItem> {
598 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
599 return items.filter(
600 (item) =>
601 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
602 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
603 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
604 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
605 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
606 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
607 );
609​
610export function searchSettings(
611 query: string,
612 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
613): ReadonlyArray<SettingsSearchItem> {
614 const normalizedQuery = normalizeSearchText(query);
615 if (normalizedQuery.length === 0) return [];
616 const queryTokens = normalizedQuery.split(" ");
617 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
618​
619 return items
620 .flatMap((item, index) => {
621 if (!isElectron && item.desktopOnly === true) return [];
622 if (item.macOnly && !isMacPlatform(platform)) return [];
623 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
624​
625 const title = normalizeSearchText(item.title);
626 const fields = [
627 title,
628 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
629 ...(item.searchTerms ?? []).map(normalizeSearchText),
630 ];
631 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
632​
633 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
634 const rank =
635 title === normalizedQuery
636 ? 5
637 : title.startsWith(normalizedQuery)
638 ? 4
639 : title.includes(normalizedQuery)
640 ? 3
641 : queryTokens.every((token) => title.includes(token))
642 ? 2
643 : exactPhraseField >= 0
644 ? 1
645 : 0;
646 return [{ item, index, rank }];
647 })
648 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
649 .map(({ item }) => item);