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