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

settingsSearch.ts

644 lines19.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/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: "panel-animations",
111 title: "Panel animations",
112 to: "/settings/appearance",
113 },
114 {
115 id: "environment-identification",
116 title: "Environment identification",
117 to: "/settings/appearance",
118 searchTerms: ["dev nightly artwork pill label hide none"],
119 // The setting is stage-dependent, so its parent section is the stable destination.
120 targetId: "appearance-interface",
121 },
122 {
123 id: "interface-font",
124 title: "Interface font",
125 to: "/settings/appearance",
126 searchTerms: ["typography family size system sans"],
127 },
128 {
129 id: "prompt-font",
130 title: "Prompt font",
131 to: "/settings/appearance",
132 searchTerms: ["typography family size composer input"],
133 },
134 {
135 id: "code-font",
136 title: "Code font",
137 to: "/settings/appearance",
138 searchTerms: ["typography family size monospace code blocks diffs file previews"],
139 },
140 {
141 id: "terminal-font",
142 title: "Terminal font",
143 to: "/settings/appearance",
144 searchTerms: ["typography family size monospace output"],
145 },
146 {
147 id: "font-smoothing",
148 title: "Font smoothing",
149 to: "/settings/appearance",
150 searchTerms: ["typography text grayscale anti aliasing macos thin"],
151 macOnly: true,
152 },
153 {
154 id: "word-wrap",
155 title: "Word wrap",
156 to: "/settings/appearance",
157 searchTerms: ["long lines code blocks tables diffs file previews"],
158 },
159 {
160 id: "project-grouping",
161 title: "Project grouping",
162 to: "/settings/general",
163 searchTerms: ["combine matching repositories environments sidebar"],
164 },
165 {
166 id: "auto-settle-inactive-threads",
167 title: "Auto-settle inactive threads",
168 to: "/settings/general",
169 searchTerms: ["sidebar inactivity days no activity automatically"],
170 requiresThreadAutoSettlement: true,
171 },
172 {
173 id: "auto-settle-merged-threads",
174 title: "Auto-settle merged threads",
175 to: "/settings/general",
176 searchTerms: ["pull request merge closed automatically sidebar"],
177 requiresThreadAutoSettlement: true,
178 },
179 {
180 id: "days-before-auto-settle",
181 title: "Days of inactivity before auto-settle",
182 to: "/settings/general",
183 targetId: "auto-settle-inactive-threads",
184 searchTerms: ["thread timeout activity sidebar"],
185 requiresThreadAutoSettlement: true,
186 },
187 {
188 id: "time-format",
189 title: "Time format",
190 to: "/settings/general",
191 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
192 },
193 {
194 id: "hide-whitespace-changes",
195 title: "Hide whitespace changes",
196 to: "/settings/general",
197 searchTerms: ["diff ignore spaces edits default"],
198 },
199 {
200 id: "diff-layout",
201 title: "Diff layout",
202 to: "/settings/general",
203 searchTerms: ["stacked split side by side unified inline view"],
204 },
205 {
206 id: "proactive-panels",
207 title: "Proactive panels",
208 to: "/settings/general",
209 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
210 },
211 {
212 id: "skills-in-slash-menu",
213 title: "Show skills in slash menu",
214 to: "/settings/general",
215 searchTerms: ["command menu dollar $ slash /"],
216 },
217 {
218 id: "composer-collapse",
219 title: "Collapse composer on scroll",
220 to: "/settings/general",
221 searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
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: "snap-shot-enabled",
332 title: "SnapShots",
333 searchTerms: ["window capture screenshot"],
334 to: "/settings/snap-shot",
335 },
336 {
337 id: "snap-shot-accessibility",
338 title: "Include app text",
339 to: "/settings/snap-shot",
340 targetId: "snap-shot-enabled",
341 searchTerms: [
342 "capture accessibility data text UI structure elements privacy omit agent context",
343 ],
344 },
345 {
346 id: "snap-shot-shortcut",
347 title: "Capture shortcut",
348 to: "/settings/snap-shot",
349 targetId: "snap-shot-enabled",
350 },
351 {
352 id: "snap-shot-sound",
353 title: "Capture sound",
354 to: "/settings/snap-shot",
355 targetId: "snap-shot-enabled",
356 },
357 {
358 id: "snap-shot-flash",
359 title: "Capture flash",
360 to: "/settings/snap-shot",
361 targetId: "snap-shot-enabled",
362 },
363 {
364 id: "snap-shot-animations",
365 title: "Capture animations",
366 to: "/settings/snap-shot",
367 targetId: "snap-shot-enabled",
368 },
369 {
370 id: "providers",
371 title: "Providers",
372 to: "/settings/providers",
373 searchTerms: [
374 "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",
375 ],
376 },
377 {
378 id: "usage-providers",
379 title: "Usage providers",
380 to: "/settings/providers",
381 searchTerms: [
382 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
383 ],
384 providerSettingsOnly: true,
385 },
386 {
387 id: "provider-health-check-interval",
388 title: "Health check interval",
389 to: "/settings/providers",
390 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
391 providerSettingsOnly: true,
392 },
393 {
394 id: "agent-browser-access",
395 title: "Agent browser access",
396 to: "/settings/projects",
397 searchTerms: ["allow open drive preview tools sessions"],
398 },
399 {
400 id: "browser-profiles",
401 title: "Browser profiles",
402 to: "/settings/integrations",
403 targetId: "browser",
404 },
405 {
406 id: "browser-default-profile",
407 title: "Default browser profile",
408 to: "/settings/integrations",
409 targetId: "browser-profiles",
410 },
411 {
412 id: "browser-default-viewport",
413 title: "Default browser viewport",
414 to: "/settings/integrations",
415 searchTerms: ["preview size width height device desktop mobile rotate"],
416 },
417 {
418 id: "browser-default-zoom",
419 title: "Default browser zoom",
420 to: "/settings/integrations",
421 searchTerms: ["preview page scale tabs percent"],
422 },
423 {
424 id: "browser-default-appearance",
425 title: "Default browser appearance",
426 to: "/settings/integrations",
427 searchTerms: ["preview color scheme light dark system os"],
428 },
429 {
430 id: "browser-recording-frame-rate",
431 title: "Browser recording frame rate",
432 to: "/settings/integrations",
433 },
434 {
435 id: "browser-link-target",
436 title: "Open links in",
437 to: "/settings/integrations",
438 searchTerms: ["links default browser in-app browser external open"],
439 },
440 {
441 id: "browser-auto-show-floating-preview",
442 title: "Auto-show floating preview",
443 to: "/settings/integrations",
444 searchTerms: ["agent opens browser pop into view hide"],
445 },
446 {
447 id: "source-control",
448 title: "Source control",
449 to: "/settings/source-control",
450 searchTerms: [
451 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
452 ],
453 },
454 {
455 id: "git-fetch-interval",
456 title: "Git fetch interval",
457 to: "/settings/source-control",
458 searchTerms: [
459 "automatic remote branch refresh background credentials security keys seconds off",
460 ],
461 primaryOnly: true,
462 },
463 {
464 id: "source-control-writing-style",
465 title: "Source control writing style",
466 to: "/settings/source-control",
467 searchTerms: [
468 "repository conventions conventional commits custom instructions change descriptions request titles",
469 ],
470 primaryOnly: true,
471 },
472 {
473 id: "follow-change-request-templates",
474 title: "Follow change request templates",
475 to: "/settings/source-control",
476 searchTerms: ["repository pr pull request description structure"],
477 primaryOnly: true,
478 },
479 {
480 id: "source-control-writer-model",
481 title: "Source control writer model",
482 to: "/settings/source-control",
483 searchTerms: [
484 "override generated commit change request pr titles descriptions branch bookmark",
485 ],
486 primaryOnly: true,
487 },
488 {
489 id: "environment-icon",
490 title: "Environment icon",
491 to: "/settings/connections",
492 targetId: "connections-environment",
493 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
494 localBackendManagementOnly: true,
495 },
496 {
497 id: "network-access",
498 title: "Network access",
499 to: "/settings/connections",
500 targetId: "connections-environment",
501 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
502 localBackendManagementOnly: true,
503 },
504 {
505 id: "tailscale-https",
506 title: "Tailscale HTTPS",
507 to: "/settings/connections",
508 targetId: "connections-environment",
509 searchTerms: ["serve magicdns endpoint remote secure network"],
510 desktopOnly: true,
511 localBackendManagementOnly: true,
512 },
513 {
514 id: "wsl-backend",
515 title: "WSL backend",
516 to: "/settings/connections",
517 searchTerms: [
518 "windows subsystem linux distro second server projects stop windows backend restart",
519 ],
520 desktopOnly: true,
521 windowsOnly: true,
522 localBackendManagementOnly: true,
523 wslAvailableOnly: true,
524 },
525 {
526 id: "t3-connect",
527 title: "T3 Connect",
528 to: "/settings/connections",
529 targetId: "connections-environment",
530 searchTerms: ["managed tunnel cloud other devices remote"],
531 desktopOnly: true,
532 cloudOnly: true,
533 },
534 {
535 id: "publish-agent-activity",
536 title: "Publish agent activity",
537 to: "/settings/connections",
538 targetId: "connections-environment",
539 searchTerms: ["mobile push notifications live activities cloud tunnel"],
540 cloudOnly: true,
541 },
542 {
543 id: "connections-environment",
544 title: "This environment",
545 to: "/settings/connections",
546 searchTerms: [
547 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
548 ],
549 },
550 {
551 id: "remote-environments",
552 title: "Remote environments",
553 to: "/settings/connections",
554 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
555 },
556 {
557 id: "load-balancing",
558 title: "Load balancing",
559 to: "/settings/connections",
560 searchTerms: [
561 "automatic machine environment resources cpu memory capacity preference weight shared projects",
562 ],
563 },
564 {
565 id: "archive",
566 title: "Archived threads",
567 to: "/settings/archived",
568 searchTerms: ["restore reopen deleted history projects"],
569 },
570] as const satisfies ReadonlyArray<SettingsSearchItem>;
571​
572export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
573​
574const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
575​
576/**
577 * `id` and `title` props for the element a search item anchors to. Panels
578 * spread (or pick from) this instead of restating the strings, so the catalog
579 * and the rendered settings cannot drift apart.
580 */
581export function searchableSetting(id: SettingsSearchItemId): {
582 readonly id: string;
583 readonly title: string;
584} {
585 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
586 return { id: anchorId, title };
588​
589export function filterAvailableSettingsSearchItems(
590 availability: SettingsSearchAvailability,
591): ReadonlyArray<SettingsSearchItem> {
592 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
593 return items.filter(
594 (item) =>
595 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
596 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
597 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
598 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
599 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
600 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
601 );
603​
604export function searchSettings(
605 query: string,
606 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
607): ReadonlyArray<SettingsSearchItem> {
608 const normalizedQuery = normalizeSearchText(query);
609 if (normalizedQuery.length === 0) return [];
610 const queryTokens = normalizedQuery.split(" ");
611 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
612​
613 return items
614 .flatMap((item, index) => {
615 if (!isElectron && item.desktopOnly === true) return [];
616 if (item.macOnly && !isMacPlatform(platform)) return [];
617 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
618​
619 const title = normalizeSearchText(item.title);
620 const fields = [
621 title,
622 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
623 ...(item.searchTerms ?? []).map(normalizeSearchText),
624 ];
625 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
626​
627 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
628 const rank =
629 title === normalizedQuery
630 ? 5
631 : title.startsWith(normalizedQuery)
632 ? 4
633 : title.includes(normalizedQuery)
634 ? 3
635 : queryTokens.every((token) => title.includes(token))
636 ? 2
637 : exactPhraseField >= 0
638 ? 1
639 : 0;
640 return [{ item, index, rank }];
641 })
642 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
643 .map(({ item }) => item);