Open History to see the last commit
1import { HOSTED_APP_CHANNEL } from "~/branding";
2import { isElectron } from "~/env";
3import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
4import { STATIC_KEYBINDING_COMMANDS, type KeybindingCommand } from "@t3tools/contracts";
5import type { EnvironmentId } from "@t3tools/contracts";
6import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
7import {
8 sourceControlClients,
9 type SourceControlDefinition,
10} from "@t3tools/client-runtime/source-control-clients";
11import { DEFAULT_KEYBINDINGS } from "@t3tools/shared/keybindings";
12import { commandLabel } from "./KeybindingsSettings.logic";
13import {
14 validateSettingsScopeSearch,
15 type ResolvedSettingsScope,
16 type SettingsScopeSearch,
17} from "./settingsScope";
18
19export type SettingsPath =
20 | "/settings/projects"
21 | "/settings/general"
22 | "/settings/diagnostics"
23 | "/settings/appearance"
24 | "/settings/keybindings"
25 | "/settings/snap-shot"
26 | "/settings/providers"
27 | "/settings/integrations"
28 | "/settings/scheduled-tasks"
29 | "/settings/source-control"
30 | "/settings/storage"
31 | "/settings/connections"
32 | "/settings/beta"
33 | "/settings/archived";
34
35export type SettingsSearchScope =
36 | "environment"
37 | "environment-defaults"
38 | "project-defaults"
39 | "project"
40 | "checkout"
41 | "connections";
42
43export interface SettingsSearchItem {
44 readonly id: string;
45 readonly title: string;
46 readonly to: SettingsPath;
47 readonly targetId?: string;
48 readonly searchTerms?: ReadonlyArray<string>;
49 readonly scope?: SettingsSearchScope;
50 readonly desktopOnly?: boolean;
51 readonly macOnly?: boolean;
52 readonly windowsOnly?: boolean;
53 readonly releaseChannelOnly?: boolean;
54 readonly cloudOnly?: boolean;
55 readonly environmentOnly?: boolean;
56 readonly providerSettingsOnly?: boolean;
57 readonly macProviderSettingsOnly?: boolean;
58 readonly localBackendManagementOnly?: boolean;
59 readonly localEnvironmentOnly?: boolean;
60 readonly wslAvailableOnly?: boolean;
61 readonly managedTunnelOnly?: boolean;
62 readonly secondary?: boolean;
63 readonly requiresThreadAutoSettlement?: boolean;
64}
65
66export interface SettingsSearchAvailability {
67 readonly localEnvironmentDisabled?: boolean;
68 readonly hasCloudPublicConfig: boolean;
69 readonly hasEnvironment: boolean;
70 readonly hasProviderSettingsEnvironment: boolean;
71 readonly hasMacProviderSettingsEnvironment: boolean;
72 readonly canManageLocalBackend: boolean;
73 readonly isWslSettingsRowVisible: boolean;
74 readonly hasThreadAutoSettlement: boolean;
75 readonly managedTunnelActive?: boolean;
76}
77
78export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
79 "/settings/diagnostics": "Diagnostics",
80 "/settings/projects": "Project",
81 "/settings/general": "General",
82 "/settings/appearance": "Appearance",
83 "/settings/keybindings": "Keybindings",
84 "/settings/snap-shot": "SnapShots",
85 "/settings/providers": "Providers",
86 "/settings/integrations": "Integrations",
87 "/settings/scheduled-tasks": "Scheduled Tasks",
88 "/settings/source-control": "Source Control",
89 "/settings/storage": "Storage",
90 "/settings/connections": "Connections",
91 "/settings/beta": "Beta",
92 "/settings/archived": "Archive",
93};
94
95export function keybindingSearchAnchorId<Command extends KeybindingCommand>(command: Command) {
96 return `keybinding-${command}` as const;
97}
98
99const KEYBINDING_SEARCH_ITEMS = STATIC_KEYBINDING_COMMANDS.toSorted((left, right) =>
100 commandLabel(left).localeCompare(commandLabel(right)),
101).map((command) => {
102 const defaultKeys = DEFAULT_KEYBINDINGS.filter((binding) => binding.command === command).map(
103 (binding) => binding.key,
104 );
105 return {
106 id: keybindingSearchAnchorId(command),
107 title: commandLabel(command),
108 to: "/settings/keybindings" as const,
109 searchTerms: [command, ...defaultKeys],
110 secondary: true,
111 ...(defaultKeys.length === 0 ? { targetId: "keybindings" } : {}),
112 };
113});
114
115export function sourceControlHostSettingsSearchId(kind: string) {
116 return `source-control-host-${kind}` as const;
117}
118
119/** Each host's own settings: its accounts and token, or the fields of its settings form. */
120export function sourceControlHostSearchItems(
121 definitions: ReadonlyArray<SourceControlDefinition>,
122): ReadonlyArray<
123 SettingsSearchItem & { readonly id: ReturnType<typeof sourceControlHostSettingsSearchId> }
124> {
125 return definitions.flatMap((definition) => {
126 if (!definition.settings) return [];
127 const names = [definition.label, ...(definition.searchKeywords ?? [])].join(" ");
128 const { credentials } = definition;
129 return [
130 {
131 id: sourceControlHostSettingsSearchId(definition.kind),
132 title: credentials
133 ? `${definition.label} accounts and token`
134 : `${definition.label} credentials`,
135 to: "/settings/source-control" as const,
136 searchTerms: [
137 credentials
138 ? `${names} ${credentials.cliName} account login user host switch multiple accounts disable sign in token personal access token pat api key credential`
139 : `${names} ${Object.keys(definition.settings.fields).join(" ")} token credentials sign in`,
140 ],
141 environmentOnly: true,
142 scope: "environment-defaults" as const,
143 },
144 ];
145 });
146}
147
148/** For settings that apply to every host. */
149const SOURCE_CONTROL_HOST_LABELS = sourceControlClients.definitions
150 .map((definition) => definition.label)
151 .join(" ");
152const SOURCE_CONTROL_HOST_TERMS = sourceControlClients.definitions
153 .flatMap((definition) => [definition.label, ...(definition.searchKeywords ?? [])])
154 .join(" ");
155
156export const SETTINGS_SEARCH_ITEMS = [
157 {
158 id: "storage-worktree-keep-when",
159 targetId: "storage-worktrees",
160 title: "Keep worktrees with local changes",
161 to: "/settings/storage",
162 scope: "project-defaults",
163 searchTerms: [
164 "any local files uncommitted changes edited tracked files ignored env build output cleanup",
165 ],
166 },
167 {
168 id: "storage-delete-now",
169 title: "Delete now",
170 to: "/settings/storage",
171 scope: "environment-defaults",
172 searchTerms: ["storage cleanup run now results report removed kept failed"],
173 },
174 {
175 id: "storage-worktrees",
176 title: "Worktree cleanup",
177 to: "/settings/storage",
178 scope: "project-defaults",
179 searchTerms: [
180 "disk storage delete deleted archived threads old inactive merged unchanged worktrees retention days project inherit off custom",
181 ],
182 },
183 {
184 id: "storage-worktrees-location",
185 title: "Worktree location",
186 to: "/settings/storage",
187 scope: "environment-defaults",
188 searchTerms: ["worktree location folder directory path drive external disk"],
189 },
190 {
191 id: "storage-artifacts",
192 title: "Artifacts and logs",
193 to: "/settings/storage",
194 scope: "environment-defaults",
195 searchTerms: ["disk storage browser screenshots captures rotated logs cleanup retention"],
196 },
197 {
198 id: "project-defaults",
199 title: "Project defaults and overrides",
200 to: "/settings/general",
201 scope: "project-defaults",
202 searchTerms: ["model workspace environments projects inheritance checkout"],
203 },
204 {
205 id: "project-overview",
206 title: "Project overview",
207 to: "/settings/projects",
208 searchTerms: ["name icon emoji image checkout remove delete"],
209 },
210 {
211 id: "default-model",
212 title: "Default model",
213 to: "/settings/general",
214 scope: "project-defaults",
215 searchTerms: ["new thread project provider reasoning effort"],
216 },
217 {
218 id: "default-permissions",
219 title: "Permissions",
220 to: "/settings/general",
221 scope: "project-defaults",
222 searchTerms: [
223 "new thread default runtime mode supervised approvals auto accept edits full access",
224 ],
225 },
226 {
227 id: "color-scheme",
228 title: "Color scheme",
229 to: "/settings/appearance",
230 searchTerms: ["appearance light dark system mode"],
231 targetId: "appearance",
232 },
233 {
234 id: "theme",
235 title: "Themes",
236 to: "/settings/appearance",
237 searchTerms: ["appearance colors palette custom import"],
238 targetId: "appearance",
239 },
240 {
241 // Prefixed because the slider control already owns the `appearance-contrast` id.
242 id: "setting-appearance-contrast",
243 title: "Contrast",
244 to: "/settings/appearance",
245 searchTerms: ["colors borders interface"],
246 },
247 {
248 // Prefixed because the slider control already owns the `glass-opacity` id.
249 id: "setting-glass-opacity",
250 title: "Glass opacity",
251 to: "/settings/appearance",
252 searchTerms: ["transparent transparency solid menus dialogs composer"],
253 },
254 {
255 id: "diff-color-scheme",
256 title: "Diff colors",
257 to: "/settings/appearance",
258 searchTerms: ["red green blue orange additions deletions changes counts palette colorblind"],
259 },
260 {
261 id: "chat-width",
262 title: "Chat width",
263 to: "/settings/appearance",
264 searchTerms: ["wide full width column layout messages composer monitor"],
265 },
266 {
267 id: "math-rendering",
268 title: "Render math",
269 to: "/settings/appearance",
270 searchTerms: ["latex tex katex equations formulas markdown"],
271 },
272 {
273 id: "panel-animations",
274 title: "Panel animations",
275 to: "/settings/appearance",
276 },
277 {
278 id: "environment-identification",
279 title: "Environment identification",
280 to: "/settings/appearance",
281 searchTerms: ["dev nightly artwork pill label hide none"],
282 targetId: "appearance-interface",
283 },
284 {
285 id: "interface-font",
286 title: "Interface font",
287 to: "/settings/appearance",
288 searchTerms: ["typography family size system sans"],
289 },
290 {
291 id: "prompt-font",
292 title: "Prompt font",
293 to: "/settings/appearance",
294 searchTerms: ["typography family size composer input"],
295 },
296 {
297 id: "code-font",
298 title: "Code font",
299 to: "/settings/appearance",
300 searchTerms: ["typography family size monospace code blocks diffs file previews"],
301 },
302 {
303 id: "terminal-font",
304 title: "Terminal font",
305 to: "/settings/appearance",
306 searchTerms: ["typography family size monospace output"],
307 },
308 {
309 id: "font-smoothing",
310 title: "Font smoothing",
311 to: "/settings/appearance",
312 searchTerms: ["typography text grayscale anti aliasing macos thin"],
313 macOnly: true,
314 },
315 {
316 id: "word-wrap",
317 title: "Word wrap",
318 to: "/settings/appearance",
319 searchTerms: ["long lines code blocks tables diffs file previews"],
320 },
321 {
322 id: "composer-context",
323 title: "Composer context",
324 to: "/settings/appearance",
325 },
326 {
327 id: "project-grouping",
328 title: "Project grouping",
329 to: "/settings/general",
330 searchTerms: ["combine matching repositories environments sidebar"],
331 },
332 {
333 id: "project-order",
334 title: "Project order",
335 to: "/settings/general",
336 searchTerms: ["sort projects sidebar manual created recent"],
337 },
338 {
339 id: "snooze-limited-threads",
340 title: "Snooze limited threads",
341 to: "/settings/general",
342 searchTerms: ["usage quota rate limit reset wake recover continue"],
343 },
344 {
345 id: "auto-resume-limited-threads",
346 title: "Auto-resume limited threads",
347 to: "/settings/general",
348 searchTerms: ["usage quota rate limit reset recover continue"],
349 },
350 {
351 id: "working-shelf",
352 title: "Working section",
353 to: "/settings/beta",
354 searchTerms: ["beta hide fold running monitoring threads inbox sidebar shelf"],
355 },
356 {
357 id: "guest-links",
358 title: "Guest links",
359 to: "/settings/beta",
360 scope: "environment",
361 searchTerms: ["beta share guest invite link teammate watch t3 connect tunnel"],
362 },
363 {
364 id: "auto-settle-inactive-threads",
365 title: "Auto-settle inactive threads",
366 to: "/settings/general",
367 searchTerms: ["sidebar inactivity days no activity automatically"],
368 requiresThreadAutoSettlement: true,
369 scope: "project-defaults",
370 },
371 {
372 id: "compact-idle-threads",
373 title: "Compact idle threads",
374 to: "/settings/general",
375 scope: "environment-defaults",
376 searchTerms: ["claude context compaction idle cache tokens usage summary resume"],
377 },
378 {
379 id: "auto-settle-merged-threads",
380 title: "Auto-settle merged threads",
381 to: "/settings/general",
382 searchTerms: ["pull request merge closed automatically sidebar"],
383 requiresThreadAutoSettlement: true,
384 scope: "project-defaults",
385 },
386 {
387 id: "days-before-auto-settle",
388 title: "Days of inactivity before auto-settle",
389 to: "/settings/general",
390 targetId: "auto-settle-inactive-threads",
391 searchTerms: ["thread timeout activity sidebar"],
392 requiresThreadAutoSettlement: true,
393 scope: "project-defaults",
394 },
395 {
396 id: "thread-notifications",
397 title: "Thread notifications",
398 to: "/settings/general",
399 searchTerms: ["notification sound alert completion input approval desktop"],
400 },
401 {
402 id: "in-app-notifications",
403 title: "In-app notifications",
404 to: "/settings/general",
405 searchTerms: ["notification toast popup completion input approval failure"],
406 },
407 {
408 id: "time-format",
409 title: "Time format",
410 to: "/settings/general",
411 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
412 },
413 {
414 id: "response-streaming",
415 title: "Response streaming",
416 to: "/settings/general",
417 scope: "project-defaults",
418 searchTerms: ["output token paragraph buffered wait turn legacy"],
419 },
420 {
421 id: "hide-whitespace-changes",
422 title: "Hide whitespace changes",
423 to: "/settings/general",
424 searchTerms: ["diff ignore spaces edits default"],
425 },
426 {
427 id: "default-diff-file-state",
428 title: "Default diff file state",
429 to: "/settings/general",
430 searchTerms: ["collapsed expanded collapse expand files pull request pr code tab"],
431 },
432 {
433 id: "diff-layout",
434 title: "Diff layout",
435 to: "/settings/general",
436 searchTerms: ["stacked split side by side unified inline view"],
437 },
438 {
439 id: "proactive-panels",
440 title: "Proactive panels",
441 to: "/settings/general",
442 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
443 },
444 {
445 id: "skills-in-slash-menu",
446 title: "Show skills in slash menu",
447 to: "/settings/general",
448 searchTerms: ["command menu dollar $ slash /"],
449 },
450 {
451 id: "composer-rich-text",
452 title: "Rich text composer",
453 to: "/settings/general",
454 searchTerms: ["composer rich text tiptap bold italic markdown styled wysiwyg"],
455 },
456 {
457 id: "composer-collapse",
458 title: "Collapse composer on scroll",
459 to: "/settings/general",
460 searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
461 },
462 {
463 id: "send-shortcut",
464 title: "Send shortcut",
465 to: "/settings/general",
466 searchTerms: ["enter return command ctrl multiline prompt new line composer"],
467 },
468 {
469 id: "follow-up-behavior",
470 title: "Follow-up behavior",
471 to: "/settings/general",
472 searchTerms: ["queue steer running turn send default behavior composer"],
473 },
474 {
475 id: "provider-update-checks",
476 title: "Provider update checks",
477 to: "/settings/general",
478 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
479 scope: "environment-defaults",
480 },
481 {
482 id: "continue-threads-after-server-update",
483 title: "Continue threads after restarts",
484 to: "/settings/general",
485 scope: "project-defaults",
486 searchTerms: [
487 "resume running active interrupted work restart reboot machine crash desktop update automatically",
488 ],
489 },
490 {
491 id: "background-activity",
492 title: "Background activity",
493 to: "/settings/general",
494 scope: "environment-defaults",
495 searchTerms: [
496 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
497 ],
498 },
499 {
500 id: "new-threads",
501 title: "New threads",
502 to: "/settings/general",
503 scope: "project-defaults",
504 searchTerms: ["default workspace mode draft local worktree"],
505 },
506 {
507 id: "worktree-submodules",
508 title: "Submodules",
509 to: "/settings/general",
510 scope: "project-defaults",
511 searchTerms: ["git submodule init recursive top-level none worktree t3.json"],
512 },
513 {
514 id: "start-from-origin",
515 title: "Start from remote",
516 to: "/settings/general",
517 scope: "project-defaults",
518 searchTerms: ["new worktrees start remote origin latest fetched branch local"],
519 },
520 {
521 id: "add-project-starts-in",
522 title: "Add project starts in",
523 to: "/settings/general",
524 scope: "environment-defaults",
525 searchTerms: ["base directory folder browser path home"],
526 },
527 {
528 id: "unpin-confirmation",
529 title: "Unpin confirmation",
530 to: "/settings/general",
531 searchTerms: ["ask before thread pinned section"],
532 },
533 {
534 id: "archive-confirmation",
535 title: "Archive confirmation",
536 to: "/settings/general",
537 searchTerms: ["ask before thread second click inline action"],
538 },
539 {
540 id: "delete-confirmation",
541 title: "Delete confirmation",
542 to: "/settings/general",
543 searchTerms: ["ask before thread chat history"],
544 },
545 {
546 id: "quit-confirmation",
547 title: "Quit shortcut",
548 to: "/settings/general",
549 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
550 desktopOnly: true,
551 },
552 {
553 id: "text-generation-model",
554 title: "Text generation model",
555 to: "/settings/general",
556 scope: "project-defaults",
557 searchTerms: ["generated thread titles source control content default provider"],
558 },
559 {
560 id: "thread-title-instructions",
561 title: "Thread title instructions",
562 to: "/settings/general",
563 scope: "project-defaults",
564 searchTerms: ["generated thread titles prompt custom style naming rename regenerate"],
565 },
566 {
567 id: "app-version",
568 title: "Version",
569 to: "/settings/general",
570 searchTerms: ["about check for updates download install upgrade release"],
571 },
572 {
573 id: "update-track",
574 title: "Update track",
575 to: "/settings/general",
576 searchTerms: ["release channel stable latest nightly prerelease"],
577 releaseChannelOnly: true,
578 },
579 {
580 id: "cli-command",
581 title: "t3 command",
582 to: "/settings/general",
583 searchTerms: ["cli terminal shell path install command line"],
584 desktopOnly: true,
585 },
586 {
587 id: "mobile-app",
588 title: "Mobile app",
589 to: "/settings/general",
590 searchTerms: ["phone tablet iPhone iPad iOS Android App Store Google Play QR"],
591 },
592 {
593 id: "privacy-policy",
594 title: "Privacy policy",
595 to: "/settings/general",
596 searchTerms: ["telemetry analytics usage data tracking legal opt out"],
597 },
598 {
599 id: "telemetry-export",
600 title: "OpenTelemetry export",
601 to: "/settings/diagnostics",
602 targetId: "telemetry-export",
603 scope: "environment",
604 searchTerms: ["OTel OTLP telemetry export endpoints logs traces metrics Grafana"],
605 },
606 {
607 id: "diagnostics",
608 title: "Diagnostics",
609 to: "/settings/general",
610 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
611 },
612 {
613 id: "open-source-licenses",
614 title: "Open source licenses",
615 to: "/settings/general",
616 },
617 {
618 id: "legacy-plan-mode",
619 title: "Plan mode (legacy)",
620 to: "/settings/general",
621 searchTerms: ["build plan composer old"],
622 },
623 {
624 id: "legacy-context-window-indicator",
625 title: "Context window indicator (legacy)",
626 to: "/settings/general",
627 searchTerms: ["composer meter usage tokens circle old"],
628 },
629 {
630 id: "legacy-sidebar",
631 title: "Sidebar (legacy)",
632 to: "/settings/general",
633 searchTerms: ["project thread tree old flat list"],
634 },
635 {
636 id: "keybindings",
637 title: "Keybindings",
638 to: "/settings/keybindings",
639 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
640 },
641 ...KEYBINDING_SEARCH_ITEMS,
642 {
643 id: "snap-shot-enabled",
644 title: "SnapShots",
645 searchTerms: ["window capture screenshot"],
646 to: "/settings/snap-shot",
647 },
648 {
649 id: "snap-shot-accessibility",
650 title: "Include app text",
651 to: "/settings/snap-shot",
652 targetId: "snap-shot-enabled",
653 searchTerms: [
654 "capture accessibility data text UI structure elements privacy omit agent context",
655 ],
656 },
657 {
658 id: "snap-shot-shortcut",
659 title: "Capture shortcut",
660 to: "/settings/snap-shot",
661 targetId: "snap-shot-enabled",
662 },
663 {
664 id: "snap-shot-sound",
665 title: "Capture sound",
666 to: "/settings/snap-shot",
667 targetId: "snap-shot-enabled",
668 },
669 {
670 id: "snap-shot-flash",
671 title: "Capture flash",
672 to: "/settings/snap-shot",
673 targetId: "snap-shot-enabled",
674 },
675 {
676 id: "snap-shot-animations",
677 title: "Capture animations",
678 to: "/settings/snap-shot",
679 targetId: "snap-shot-enabled",
680 },
681 {
682 id: "providers",
683 title: "Providers",
684 to: "/settings/providers",
685 searchTerms: [
686 "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",
687 ],
688 },
689 {
690 id: "usage-providers",
691 title: "Usage providers",
692 to: "/settings/providers",
693 searchTerms: [
694 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
695 ],
696 providerSettingsOnly: true,
697 },
698 {
699 id: "cursor-keychain-usage",
700 title: "Cursor account usage",
701 to: "/settings/providers",
702 searchTerms: ["cursor macOS keychain usage tokens cost limits permission"],
703 providerSettingsOnly: true,
704 macProviderSettingsOnly: true,
705 },
706 {
707 id: "provider-health-check-interval",
708 title: "Health check interval",
709 to: "/settings/providers",
710 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
711 providerSettingsOnly: true,
712 },
713 {
714 id: "agent-browser-access",
715 title: "Agent browser access",
716 to: "/settings/integrations",
717 scope: "project-defaults",
718 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
719 },
720 {
721 id: "device-hosts",
722 title: "Device hosts",
723 to: "/settings/integrations",
724 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
725 },
726 {
727 id: "agent-device-access",
728 title: "Agent device access",
729 to: "/settings/integrations",
730 targetId: "devices",
731 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
732 },
733 {
734 id: "device-hub",
735 title: "Device hub",
736 to: "/settings/integrations",
737 targetId: "devices",
738 searchTerms: ["simulator emulator ios android install start"],
739 },
740 {
741 id: "device-platform-support",
742 title: "Simulator support",
743 to: "/settings/integrations",
744 targetId: "devices",
745 searchTerms: ["xcode android studio sdk avd runtime"],
746 },
747 {
748 id: "browser-profiles",
749 title: "Browser profiles",
750 to: "/settings/integrations",
751 targetId: "browser",
752 },
753 {
754 id: "browser-default-profile",
755 title: "Default browser profile",
756 to: "/settings/integrations",
757 targetId: "browser-profiles",
758 },
759 {
760 id: "browser-default-viewport",
761 title: "Default browser viewport",
762 to: "/settings/integrations",
763 searchTerms: ["preview size width height device desktop mobile rotate"],
764 },
765 {
766 id: "browser-default-zoom",
767 title: "Default browser zoom",
768 to: "/settings/integrations",
769 searchTerms: ["preview page scale tabs percent"],
770 },
771 {
772 id: "browser-default-appearance",
773 title: "Default browser appearance",
774 to: "/settings/integrations",
775 searchTerms: ["preview color scheme light dark system os"],
776 },
777 {
778 id: "browser-recording-frame-rate",
779 title: "Browser recording frame rate",
780 to: "/settings/integrations",
781 },
782 {
783 id: "browser-recording-key-presses",
784 title: "Show key presses in recordings",
785 to: "/settings/integrations",
786 searchTerms: ["browser preview keyboard shortcuts keystrokes overlay capture"],
787 },
788 {
789 id: "browser-recording-mouse-presses",
790 title: "Show mouse presses in recordings",
791 to: "/settings/integrations",
792 searchTerms: ["browser preview clicks buttons drag overlay capture"],
793 },
794 {
795 id: "browser-link-target",
796 title: "Open links in",
797 to: "/settings/integrations",
798 searchTerms: ["links default browser in-app browser external open"],
799 },
800 {
801 id: "browser-search-engine",
802 title: "Search engine",
803 to: "/settings/integrations",
804 searchTerms: ["address bar duckduckgo google bing brave kagi ecosia custom"],
805 },
806 {
807 id: "pull-request-links-open-in-app",
808 title: "Open pull requests in T3 Code",
809 to: "/settings/integrations",
810 searchTerms: [
811 `pr links ${SOURCE_CONTROL_HOST_LABELS} browser external click default pull request view panel`,
812 ],
813 },
814 {
815 id: "browser-auto-show-floating-preview",
816 title: "Auto-show floating preview",
817 to: "/settings/integrations",
818 searchTerms: ["agent opens browser device simulator pop into view hide"],
819 },
820 {
821 id: "automatic-pull",
822 title: "Automatically pull",
823 to: "/settings/source-control",
824 scope: "project-defaults",
825 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
826 },
827 {
828 id: "remove-agent-credits-on-merge",
829 title: "Remove agent credits when merging",
830 to: "/settings/source-control",
831 scope: "project-defaults",
832 searchTerms: [
833 `pull request ${SOURCE_CONTROL_HOST_LABELS} squash co-authored-by attribution claude codex generated`,
834 ],
835 },
836 {
837 id: "pull-request-merge-method",
838 title: "Default merge method",
839 to: "/settings/source-control",
840 scope: "project-defaults",
841 searchTerms: ["pull request merge squash rebase last selected"],
842 },
843 {
844 id: "source-control",
845 title: "Source control",
846 to: "/settings/source-control",
847 scope: "environment-defaults",
848 searchTerms: [
849 `version control git ${SOURCE_CONTROL_HOST_TERMS} hosting integrations credentials scan server environment`,
850 ],
851 },
852 {
853 id: "git-fetch-interval",
854 title: "Git fetch interval",
855 to: "/settings/source-control",
856 searchTerms: [
857 "automatic remote branch refresh background credentials security keys seconds off",
858 ],
859 environmentOnly: true,
860 scope: "environment-defaults",
861 },
862 {
863 id: "worktree-branch-naming",
864 title: "Worktree branch naming",
865 to: "/settings/source-control",
866 searchTerms: ["static semantic prefix custom prompt instructions feat fix refactor chore"],
867 environmentOnly: true,
868 scope: "project-defaults",
869 },
870 ...sourceControlHostSearchItems(sourceControlClients.definitions),
871 {
872 id: "source-control-writing-style",
873 title: "Source control writing style",
874 to: "/settings/source-control",
875 searchTerms: [
876 "repository conventions conventional commits custom instructions change descriptions request titles",
877 ],
878 environmentOnly: true,
879 },
880 {
881 id: "follow-change-request-templates",
882 title: "Follow change request templates",
883 to: "/settings/source-control",
884 searchTerms: ["repository pr pull request description structure"],
885 environmentOnly: true,
886 },
887 {
888 id: "source-control-writer-model",
889 title: "Source control writer model",
890 to: "/settings/source-control",
891 searchTerms: [
892 "override generated commit change request pr titles descriptions branch bookmark",
893 ],
894 environmentOnly: true,
895 scope: "project-defaults",
896 },
897 {
898 id: "review-guides",
899 title: "Review guides (beta)",
900 to: "/settings/source-control",
901 searchTerms: ["pull request pr guided review guide tour beta experimental"],
902 environmentOnly: true,
903 },
904 {
905 id: "review-guide-model",
906 title: "Review guide model",
907 to: "/settings/source-control",
908 // Hidden until review guides are on, so a search lands on the switch that shows it.
909 targetId: "review-guides",
910 searchTerms: ["pull request pr guided review guide brief maintainer"],
911 environmentOnly: true,
912 scope: "project-defaults",
913 },
914 {
915 id: "review-guide-instructions",
916 title: "Review guide instructions",
917 to: "/settings/source-control",
918 targetId: "review-guides",
919 searchTerms: ["pull request pr guided review guide preferences taste prompt custom"],
920 environmentOnly: true,
921 scope: "project-defaults",
922 },
923 {
924 id: "project-actions",
925 title: "Actions",
926 to: "/settings/projects",
927 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
928 },
929 {
930 id: "environment-icon",
931 title: "Environment icon",
932 to: "/settings/connections",
933 targetId: "connections-environment",
934 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
935 },
936 {
937 id: "local-environment",
938 title: "Local environment",
939 to: "/settings/connections",
940 targetId: "connections-environment",
941 searchTerms: ["turn off on disable enable local server agents remote only restart"],
942 desktopOnly: true,
943 },
944 {
945 id: "network-access",
946 title: "Network access",
947 to: "/settings/connections",
948 targetId: "connections-environment",
949 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
950 localBackendManagementOnly: true,
951 },
952 {
953 id: "tailscale-https",
954 title: "Tailscale HTTPS",
955 to: "/settings/connections",
956 targetId: "connections-environment",
957 searchTerms: ["serve magicdns endpoint remote secure network"],
958 desktopOnly: true,
959 localBackendManagementOnly: true,
960 },
961 {
962 id: "wsl-backend",
963 title: "WSL backend",
964 to: "/settings/connections",
965 searchTerms: [
966 "windows subsystem linux distro second server projects stop windows backend restart",
967 ],
968 desktopOnly: true,
969 windowsOnly: true,
970 localBackendManagementOnly: true,
971 wslAvailableOnly: true,
972 },
973 {
974 id: "t3-connect",
975 localEnvironmentOnly: true,
976 title: "T3 Connect",
977 to: "/settings/connections",
978 targetId: "connections-environment",
979 searchTerms: ["managed tunnel cloud other devices remote"],
980 desktopOnly: true,
981 cloudOnly: true,
982 },
983 {
984 id: "hold-webhooks-while-offline",
985 localEnvironmentOnly: true,
986 title: "Hold webhooks while offline",
987 to: "/settings/connections",
988 targetId: "connections-environment",
989 searchTerms: ["webhook automations offline queue mailbox t3 connect"],
990 cloudOnly: true,
991 managedTunnelOnly: true,
992 },
993 {
994 id: "publish-agent-activity",
995 localEnvironmentOnly: true,
996 title: "Publish agent activity",
997 to: "/settings/connections",
998 targetId: "connections-environment",
999 searchTerms: ["mobile push notifications live activities cloud tunnel"],
1000 cloudOnly: true,
1001 },
1002 {
1003 id: "connections-environment",
1004 title: "This machine",
1005 to: "/settings/connections",
1006 searchTerms: [
1007 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
1008 ],
1009 },
1010 {
1011 id: "remote-environments",
1012 title: "Environments",
1013 to: "/settings/connections",
1014 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
1015 },
1016 {
1017 id: "load-balancing",
1018 title: "Load balancing",
1019 to: "/settings/connections",
1020 searchTerms: [
1021 "automatic machine environment resources cpu memory capacity preference weight shared projects",
1022 ],
1023 },
1024 {
1025 id: "pull-request-routing",
1026 title: "Pull request sharing",
1027 to: "/settings/connections",
1028 searchTerms: [
1029 `pull request routing trusted environments shared credentials permissions read actions source control ${SOURCE_CONTROL_HOST_LABELS}`,
1030 ],
1031 },
1032 {
1033 id: "archive",
1034 title: "Archived threads",
1035 to: "/settings/archived",
1036 searchTerms: ["restore reopen deleted history projects"],
1037 },
1038] as const satisfies ReadonlyArray<SettingsSearchItem>;
1039
1040export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
1041
1042const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
1043
1044const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
1045 "/settings/diagnostics": "environment",
1046 "/settings/projects": "project",
1047 "/settings/general": null,
1048 "/settings/appearance": null,
1049 "/settings/snap-shot": null,
1050 "/settings/keybindings": null,
1051 "/settings/providers": null,
1052 "/settings/integrations": null,
1053 "/settings/source-control": "environment-defaults",
1054 "/settings/storage": "project-defaults",
1055 "/settings/connections": "connections",
1056 "/settings/scheduled-tasks": null,
1057 "/settings/beta": null,
1058 "/settings/archived": "project-defaults",
1059};
1060
1061export function getSettingsSearchTargetScope(targetId: string) {
1062 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
1063 const item =
1064 items.find((candidate) => candidate.id === targetId) ??
1065 items.find((candidate) => candidate.targetId === targetId);
1066 return item
1067 ? {
1068 title: item.title,
1069 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
1070 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
1071 }
1072 : null;
1073}
1074
1075interface AutoSettlementSearchEnvironment {
1076 readonly environmentId: EnvironmentId;
1077 readonly connection: { readonly phase: EnvironmentConnectionPhase };
1078 readonly serverConfig: {
1079 readonly environment: {
1080 readonly capabilities: { readonly threadAutoSettlement?: boolean };
1081 };
1082 } | null;
1083}
1084
1085export function getThreadAutoSettlementSearchAvailability(
1086 environments: readonly AutoSettlementSearchEnvironment[],
1087 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
1088) {
1089 const connected = environments.filter(
1090 (environment) =>
1091 environment.connection.phase === "connected" && environment.serverConfig !== null,
1092 );
1093 const eligibleEnvironmentIds = connected
1094 .filter(
1095 (environment) =>
1096 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
1097 )
1098 .map((environment) => environment.environmentId);
1099 const selected = connected.filter((environment) =>
1100 scope?.environmentIds.includes(environment.environmentId),
1101 );
1102 return {
1103 eligibleEnvironmentIds,
1104 isTargetAvailable:
1105 scope !== undefined &&
1106 scope.kind !== "unavailable" &&
1107 selected.length > 0 &&
1108 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
1109 };
1110}
1111
1112export function isSettingsSearchScopeAvailable(
1113 requiredScope: SettingsSearchScope | null,
1114 scopeKind: ResolvedSettingsScope["kind"],
1115): boolean {
1116 switch (requiredScope) {
1117 case null:
1118 case "connections":
1119 return true;
1120 case "environment":
1121 case "checkout":
1122 return requiredScope === scopeKind;
1123 case "project":
1124 return scopeKind === "project" || scopeKind === "checkout";
1125 case "environment-defaults":
1126 return scopeKind === "environment" || scopeKind === "all";
1127 case "project-defaults":
1128 return (
1129 scopeKind === "environment" ||
1130 scopeKind === "all" ||
1131 scopeKind === "project" ||
1132 scopeKind === "checkout"
1133 );
1134 }
1135}
1136
1137function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
1138 const target = validateSettingsScopeSearch({ ...search });
1139 if (target.checkout && !target.project) return "unavailable";
1140 if (target.project) return target.checkout ? "checkout" : "project";
1141 return target.machine ? "environment" : "all";
1142}
1143
1144export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
1145 const kind = settingsScopeKindFromSearch(search);
1146 return kind === "project" || kind === "checkout";
1147}
1148
1149export function searchableSetting(id: SettingsSearchItemId): {
1150 readonly id: string;
1151 readonly title: string;
1152} {
1153 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
1154 return { id: anchorId, title };
1155}
1156
1157export function filterAvailableSettingsSearchItems(
1158 availability: SettingsSearchAvailability,
1159): ReadonlyArray<SettingsSearchItem> {
1160 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
1161 return items.filter(
1162 (item) =>
1163 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
1164 (!item.environmentOnly || availability.hasEnvironment) &&
1165 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
1166 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
1167 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
1168 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
1169 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
1170 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement) &&
1171 (!item.managedTunnelOnly || availability.managedTunnelActive === true),
1172 );
1173}
1174
1175/** The settings that exist on this platform and app channel. */
1176export function settingsForThisPlatform(
1177 items: ReadonlyArray<SettingsSearchItem>,
1178): ReadonlyArray<SettingsSearchItem> {
1179 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
1180 return items.filter(
1181 (item) =>
1182 (isElectron || item.desktopOnly !== true) &&
1183 (!item.releaseChannelOnly || isElectron || HOSTED_APP_CHANNEL !== null) &&
1184 (!item.macOnly || isMacPlatform(platform)) &&
1185 (!item.windowsOnly || isWindowsPlatform(platform)),
1186 );
1187}
1188
1189export function searchSettings(
1190 query: string,
1191 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
1192): ReadonlyArray<SettingsSearchItem> {
1193 const normalizedQuery = normalizeSearchText(query);
1194 if (normalizedQuery.length === 0) return [];
1195 const queryTokens = normalizedQuery.split(" ");
1196
1197 return settingsForThisPlatform(items)
1198 .flatMap((item, index) => {
1199 const title = normalizeSearchText(item.title);
1200 const fields = [
1201 title,
1202 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1203 ...(item.searchTerms ?? []).map(normalizeSearchText),
1204 ];
1205 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1206
1207 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1208 const rank =
1209 title === normalizedQuery
1210 ? 5
1211 : title.startsWith(normalizedQuery)
1212 ? 4
1213 : title.includes(normalizedQuery)
1214 ? 3
1215 : queryTokens.every((token) => title.includes(token))
1216 ? 2
1217 : exactPhraseField >= 0
1218 ? 1
1219 : 0;
1220 return [{ item, index, rank }];
1221 })
1222 .toSorted(
1223 (left, right) =>
1224 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1225 right.rank - left.rank ||
1226 left.index - right.index,
1227 )
1228 .map(({ item }) => item);
1229}