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 Claude threads (beta)",
342 to: "/settings/general",
343 scope: "environment-defaults",
344 searchTerms: ["context compaction idle cache tokens usage summary beta experimental"],
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: "app-version",
529 title: "Version",
530 to: "/settings/general",
531 searchTerms: ["about check for updates download install upgrade release"],
532 },
533 {
534 id: "update-track",
535 title: "Update track",
536 to: "/settings/general",
537 searchTerms: ["release channel stable latest nightly prerelease"],
538 releaseChannelOnly: true,
539 },
540 {
541 id: "cli-command",
542 title: "t3 command",
543 to: "/settings/general",
544 searchTerms: ["cli terminal shell path install command line"],
545 desktopOnly: true,
546 },
547 {
548 id: "mobile-app",
549 title: "Mobile app",
550 to: "/settings/general",
551 searchTerms: ["phone tablet iPhone iPad iOS Android App Store Google Play QR"],
552 },
553 {
554 id: "privacy-policy",
555 title: "Privacy policy",
556 to: "/settings/general",
557 searchTerms: ["telemetry analytics usage data tracking legal opt out"],
558 },
559 {
560 id: "telemetry-export",
561 title: "OpenTelemetry export",
562 to: "/settings/diagnostics",
563 targetId: "telemetry-export",
564 scope: "environment",
565 searchTerms: ["OTel OTLP telemetry export endpoints logs traces metrics Grafana"],
566 },
567 {
568 id: "diagnostics",
569 title: "Diagnostics",
570 to: "/settings/general",
571 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
572 },
573 {
574 id: "open-source-licenses",
575 title: "Open source licenses",
576 to: "/settings/general",
577 },
578 {
579 id: "legacy-plan-mode",
580 title: "Plan mode (legacy)",
581 to: "/settings/general",
582 searchTerms: ["build plan composer old"],
583 },
584 {
585 id: "legacy-context-window-indicator",
586 title: "Context window indicator (legacy)",
587 to: "/settings/general",
588 searchTerms: ["composer meter usage tokens circle old"],
589 },
590 {
591 id: "legacy-sidebar",
592 title: "Sidebar (legacy)",
593 to: "/settings/general",
594 searchTerms: ["project thread tree old flat list"],
595 },
596 {
597 id: "keybindings",
598 title: "Keybindings",
599 to: "/settings/keybindings",
600 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
601 },
602 ...KEYBINDING_SEARCH_ITEMS,
603 {
604 id: "snap-shot-enabled",
605 title: "SnapShots",
606 searchTerms: ["window capture screenshot"],
607 to: "/settings/snap-shot",
608 },
609 {
610 id: "snap-shot-accessibility",
611 title: "Include app text",
612 to: "/settings/snap-shot",
613 targetId: "snap-shot-enabled",
614 searchTerms: [
615 "capture accessibility data text UI structure elements privacy omit agent context",
616 ],
617 },
618 {
619 id: "snap-shot-shortcut",
620 title: "Capture shortcut",
621 to: "/settings/snap-shot",
622 targetId: "snap-shot-enabled",
623 },
624 {
625 id: "snap-shot-sound",
626 title: "Capture sound",
627 to: "/settings/snap-shot",
628 targetId: "snap-shot-enabled",
629 },
630 {
631 id: "snap-shot-flash",
632 title: "Capture flash",
633 to: "/settings/snap-shot",
634 targetId: "snap-shot-enabled",
635 },
636 {
637 id: "snap-shot-animations",
638 title: "Capture animations",
639 to: "/settings/snap-shot",
640 targetId: "snap-shot-enabled",
641 },
642 {
643 id: "providers",
644 title: "Providers",
645 to: "/settings/providers",
646 searchTerms: [
647 "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",
648 ],
649 },
650 {
651 id: "usage-providers",
652 title: "Usage providers",
653 to: "/settings/providers",
654 searchTerms: [
655 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
656 ],
657 providerSettingsOnly: true,
658 },
659 {
660 id: "cursor-keychain-usage",
661 title: "Cursor account usage",
662 to: "/settings/providers",
663 searchTerms: ["cursor macOS keychain usage tokens cost limits permission"],
664 providerSettingsOnly: true,
665 macProviderSettingsOnly: true,
666 },
667 {
668 id: "provider-health-check-interval",
669 title: "Health check interval",
670 to: "/settings/providers",
671 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
672 providerSettingsOnly: true,
673 },
674 {
675 id: "agent-browser-access",
676 title: "Agent browser access",
677 to: "/settings/integrations",
678 scope: "project-defaults",
679 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
680 },
681 {
682 id: "device-hosts",
683 title: "Device hosts",
684 to: "/settings/integrations",
685 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
686 },
687 {
688 id: "agent-device-access",
689 title: "Agent device access",
690 to: "/settings/integrations",
691 targetId: "devices",
692 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
693 },
694 {
695 id: "device-hub",
696 title: "Device hub",
697 to: "/settings/integrations",
698 targetId: "devices",
699 searchTerms: ["simulator emulator ios android install start"],
700 },
701 {
702 id: "device-platform-support",
703 title: "Simulator support",
704 to: "/settings/integrations",
705 targetId: "devices",
706 searchTerms: ["xcode android studio sdk avd runtime"],
707 },
708 {
709 id: "browser-profiles",
710 title: "Browser profiles",
711 to: "/settings/integrations",
712 targetId: "browser",
713 },
714 {
715 id: "browser-default-profile",
716 title: "Default browser profile",
717 to: "/settings/integrations",
718 targetId: "browser-profiles",
719 },
720 {
721 id: "browser-default-viewport",
722 title: "Default browser viewport",
723 to: "/settings/integrations",
724 searchTerms: ["preview size width height device desktop mobile rotate"],
725 },
726 {
727 id: "browser-default-zoom",
728 title: "Default browser zoom",
729 to: "/settings/integrations",
730 searchTerms: ["preview page scale tabs percent"],
731 },
732 {
733 id: "browser-default-appearance",
734 title: "Default browser appearance",
735 to: "/settings/integrations",
736 searchTerms: ["preview color scheme light dark system os"],
737 },
738 {
739 id: "browser-recording-frame-rate",
740 title: "Browser recording frame rate",
741 to: "/settings/integrations",
742 },
743 {
744 id: "browser-recording-key-presses",
745 title: "Show key presses in recordings",
746 to: "/settings/integrations",
747 searchTerms: ["browser preview keyboard shortcuts keystrokes overlay capture"],
748 },
749 {
750 id: "browser-recording-mouse-presses",
751 title: "Show mouse presses in recordings",
752 to: "/settings/integrations",
753 searchTerms: ["browser preview clicks buttons drag overlay capture"],
754 },
755 {
756 id: "browser-link-target",
757 title: "Open links in",
758 to: "/settings/integrations",
759 searchTerms: ["links default browser in-app browser external open"],
760 },
761 {
762 id: "browser-search-engine",
763 title: "Search engine",
764 to: "/settings/integrations",
765 searchTerms: ["address bar duckduckgo google bing brave kagi ecosia custom"],
766 },
767 {
768 id: "pull-request-links-open-in-app",
769 title: "Open pull requests in T3 Code",
770 to: "/settings/integrations",
771 searchTerms: ["pr links github browser external click default pull request view panel"],
772 },
773 {
774 id: "browser-auto-show-floating-preview",
775 title: "Auto-show floating preview",
776 to: "/settings/integrations",
777 searchTerms: ["agent opens browser device simulator pop into view hide"],
778 },
779 {
780 id: "automatic-pull",
781 title: "Automatically pull",
782 to: "/settings/source-control",
783 scope: "project-defaults",
784 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
785 },
786 {
787 id: "remove-agent-credits-on-merge",
788 title: "Remove agent credits when merging",
789 to: "/settings/source-control",
790 scope: "project-defaults",
791 searchTerms: ["pull request github squash co-authored-by attribution claude codex generated"],
792 },
793 {
794 id: "pull-request-merge-method",
795 title: "Default merge method",
796 to: "/settings/source-control",
797 scope: "project-defaults",
798 searchTerms: ["pull request merge squash rebase last selected"],
799 },
800 {
801 id: "source-control",
802 title: "Source control",
803 to: "/settings/source-control",
804 scope: "environment-defaults",
805 searchTerms: [
806 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
807 ],
808 },
809 {
810 id: "git-fetch-interval",
811 title: "Git fetch interval",
812 to: "/settings/source-control",
813 searchTerms: [
814 "automatic remote branch refresh background credentials security keys seconds off",
815 ],
816 environmentOnly: true,
817 scope: "environment-defaults",
818 },
819 {
820 id: "worktree-branch-naming",
821 title: "Worktree branch naming",
822 to: "/settings/source-control",
823 searchTerms: ["static semantic prefix custom prompt instructions feat fix refactor chore"],
824 environmentOnly: true,
825 scope: "project-defaults",
826 },
827 {
828 id: "github-accounts",
829 title: "GitHub accounts and token",
830 to: "/settings/source-control",
831 searchTerms: [
832 "github gh account login user host enterprise ghes switch multiple accounts disable sign in token personal access token pat api key credential",
833 ],
834 environmentOnly: true,
835 scope: "environment-defaults",
836 },
837 ...SOURCE_CONTROL_HOST_SEARCH_ITEMS,
838 {
839 id: "source-control-writing-style",
840 title: "Source control writing style",
841 to: "/settings/source-control",
842 searchTerms: [
843 "repository conventions conventional commits custom instructions change descriptions request titles",
844 ],
845 environmentOnly: true,
846 },
847 {
848 id: "follow-change-request-templates",
849 title: "Follow change request templates",
850 to: "/settings/source-control",
851 searchTerms: ["repository pr pull request description structure"],
852 environmentOnly: true,
853 },
854 {
855 id: "source-control-writer-model",
856 title: "Source control writer model",
857 to: "/settings/source-control",
858 searchTerms: [
859 "override generated commit change request pr titles descriptions branch bookmark",
860 ],
861 environmentOnly: true,
862 scope: "project-defaults",
863 },
864 {
865 id: "review-guides",
866 title: "Review guides (beta)",
867 to: "/settings/source-control",
868 searchTerms: ["pull request pr guided review guide tour beta experimental"],
869 environmentOnly: true,
870 },
871 {
872 id: "review-guide-model",
873 title: "Review guide model",
874 to: "/settings/source-control",
875 // Hidden until review guides are on, so a search lands on the switch that shows it.
876 targetId: "review-guides",
877 searchTerms: ["pull request pr guided review guide brief maintainer"],
878 environmentOnly: true,
879 scope: "project-defaults",
880 },
881 {
882 id: "review-guide-instructions",
883 title: "Review guide instructions",
884 to: "/settings/source-control",
885 targetId: "review-guides",
886 searchTerms: ["pull request pr guided review guide preferences taste prompt custom"],
887 environmentOnly: true,
888 scope: "project-defaults",
889 },
890 {
891 id: "project-actions",
892 title: "Actions",
893 to: "/settings/projects",
894 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
895 },
896 {
897 id: "environment-icon",
898 title: "Environment icon",
899 to: "/settings/connections",
900 targetId: "connections-environment",
901 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
902 },
903 {
904 id: "local-environment",
905 title: "Local environment",
906 to: "/settings/connections",
907 targetId: "connections-environment",
908 searchTerms: ["turn off on disable enable local server agents remote only restart"],
909 desktopOnly: true,
910 },
911 {
912 id: "network-access",
913 title: "Network access",
914 to: "/settings/connections",
915 targetId: "connections-environment",
916 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
917 localBackendManagementOnly: true,
918 },
919 {
920 id: "tailscale-https",
921 title: "Tailscale HTTPS",
922 to: "/settings/connections",
923 targetId: "connections-environment",
924 searchTerms: ["serve magicdns endpoint remote secure network"],
925 desktopOnly: true,
926 localBackendManagementOnly: true,
927 },
928 {
929 id: "wsl-backend",
930 title: "WSL backend",
931 to: "/settings/connections",
932 searchTerms: [
933 "windows subsystem linux distro second server projects stop windows backend restart",
934 ],
935 desktopOnly: true,
936 windowsOnly: true,
937 localBackendManagementOnly: true,
938 wslAvailableOnly: true,
939 },
940 {
941 id: "t3-connect",
942 localEnvironmentOnly: true,
943 title: "T3 Connect",
944 to: "/settings/connections",
945 targetId: "connections-environment",
946 searchTerms: ["managed tunnel cloud other devices remote"],
947 desktopOnly: true,
948 cloudOnly: true,
949 },
950 {
951 id: "hold-webhooks-while-offline",
952 localEnvironmentOnly: true,
953 title: "Hold webhooks while offline",
954 to: "/settings/connections",
955 targetId: "connections-environment",
956 searchTerms: ["webhook automations offline queue mailbox t3 connect"],
957 cloudOnly: true,
958 managedTunnelOnly: true,
959 },
960 {
961 id: "publish-agent-activity",
962 localEnvironmentOnly: true,
963 title: "Publish agent activity",
964 to: "/settings/connections",
965 targetId: "connections-environment",
966 searchTerms: ["mobile push notifications live activities cloud tunnel"],
967 cloudOnly: true,
968 },
969 {
970 id: "connections-environment",
971 title: "This machine",
972 to: "/settings/connections",
973 searchTerms: [
974 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
975 ],
976 },
977 {
978 id: "remote-environments",
979 title: "Environments",
980 to: "/settings/connections",
981 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
982 },
983 {
984 id: "load-balancing",
985 title: "Load balancing",
986 to: "/settings/connections",
987 searchTerms: [
988 "automatic machine environment resources cpu memory capacity preference weight shared projects",
989 ],
990 },
991 {
992 id: "github-routing",
993 title: "GitHub sharing",
994 to: "/settings/connections",
995 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
996 },
997 {
998 id: "archive",
999 title: "Archived threads",
1000 to: "/settings/archived",
1001 searchTerms: ["restore reopen deleted history projects"],
1002 },
1003] as const satisfies ReadonlyArray<SettingsSearchItem>;
1004
1005export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
1006
1007const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
1008
1009const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
1010 "/settings/diagnostics": "environment",
1011 "/settings/projects": "project",
1012 "/settings/general": null,
1013 "/settings/appearance": null,
1014 "/settings/snap-shot": null,
1015 "/settings/keybindings": null,
1016 "/settings/providers": null,
1017 "/settings/integrations": null,
1018 "/settings/source-control": "environment-defaults",
1019 "/settings/storage": "project-defaults",
1020 "/settings/connections": "connections",
1021 "/settings/scheduled-tasks": null,
1022 "/settings/archived": "project-defaults",
1023};
1024
1025export function getSettingsSearchTargetScope(targetId: string) {
1026 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
1027 const item =
1028 items.find((candidate) => candidate.id === targetId) ??
1029 items.find((candidate) => candidate.targetId === targetId);
1030 return item
1031 ? {
1032 title: item.title,
1033 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
1034 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
1035 }
1036 : null;
1037}
1038
1039interface AutoSettlementSearchEnvironment {
1040 readonly environmentId: EnvironmentId;
1041 readonly connection: { readonly phase: EnvironmentConnectionPhase };
1042 readonly serverConfig: {
1043 readonly environment: {
1044 readonly capabilities: { readonly threadAutoSettlement?: boolean };
1045 };
1046 } | null;
1047}
1048
1049export function getThreadAutoSettlementSearchAvailability(
1050 environments: readonly AutoSettlementSearchEnvironment[],
1051 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
1052) {
1053 const connected = environments.filter(
1054 (environment) =>
1055 environment.connection.phase === "connected" && environment.serverConfig !== null,
1056 );
1057 const eligibleEnvironmentIds = connected
1058 .filter(
1059 (environment) =>
1060 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
1061 )
1062 .map((environment) => environment.environmentId);
1063 const selected = connected.filter((environment) =>
1064 scope?.environmentIds.includes(environment.environmentId),
1065 );
1066 return {
1067 eligibleEnvironmentIds,
1068 isTargetAvailable:
1069 scope !== undefined &&
1070 scope.kind !== "unavailable" &&
1071 selected.length > 0 &&
1072 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
1073 };
1074}
1075
1076export function isSettingsSearchScopeAvailable(
1077 requiredScope: SettingsSearchScope | null,
1078 scopeKind: ResolvedSettingsScope["kind"],
1079): boolean {
1080 switch (requiredScope) {
1081 case null:
1082 case "connections":
1083 return true;
1084 case "environment":
1085 case "checkout":
1086 return requiredScope === scopeKind;
1087 case "project":
1088 return scopeKind === "project" || scopeKind === "checkout";
1089 case "environment-defaults":
1090 return scopeKind === "environment" || scopeKind === "all";
1091 case "project-defaults":
1092 return (
1093 scopeKind === "environment" ||
1094 scopeKind === "all" ||
1095 scopeKind === "project" ||
1096 scopeKind === "checkout"
1097 );
1098 }
1099}
1100
1101function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
1102 const target = validateSettingsScopeSearch({ ...search });
1103 if (target.checkout && !target.project) return "unavailable";
1104 if (target.project) return target.checkout ? "checkout" : "project";
1105 return target.machine ? "environment" : "all";
1106}
1107
1108export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
1109 const kind = settingsScopeKindFromSearch(search);
1110 return kind === "project" || kind === "checkout";
1111}
1112
1113export function searchableSetting(id: SettingsSearchItemId): {
1114 readonly id: string;
1115 readonly title: string;
1116} {
1117 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
1118 return { id: anchorId, title };
1119}
1120
1121export function filterAvailableSettingsSearchItems(
1122 availability: SettingsSearchAvailability,
1123): ReadonlyArray<SettingsSearchItem> {
1124 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
1125 return items.filter(
1126 (item) =>
1127 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
1128 (!item.environmentOnly || availability.hasEnvironment) &&
1129 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
1130 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
1131 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
1132 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
1133 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
1134 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement) &&
1135 (!item.managedTunnelOnly || availability.managedTunnelActive === true),
1136 );
1137}
1138
1139export function searchSettings(
1140 query: string,
1141 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
1142): ReadonlyArray<SettingsSearchItem> {
1143 const normalizedQuery = normalizeSearchText(query);
1144 if (normalizedQuery.length === 0) return [];
1145 const queryTokens = normalizedQuery.split(" ");
1146 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
1147
1148 return items
1149 .flatMap((item, index) => {
1150 if (!isElectron && item.desktopOnly === true) return [];
1151 if (item.releaseChannelOnly && !isElectron && HOSTED_APP_CHANNEL === null) return [];
1152 if (item.macOnly && !isMacPlatform(platform)) return [];
1153 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
1154
1155 const title = normalizeSearchText(item.title);
1156 const fields = [
1157 title,
1158 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1159 ...(item.searchTerms ?? []).map(normalizeSearchText),
1160 ];
1161 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1162
1163 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1164 const rank =
1165 title === normalizedQuery
1166 ? 5
1167 : title.startsWith(normalizedQuery)
1168 ? 4
1169 : title.includes(normalizedQuery)
1170 ? 3
1171 : queryTokens.every((token) => title.includes(token))
1172 ? 2
1173 : exactPhraseField >= 0
1174 ? 1
1175 : 0;
1176 return [{ item, index, rank }];
1177 })
1178 .toSorted(
1179 (left, right) =>
1180 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1181 right.rank - left.rank ||
1182 left.index - right.index,
1183 )
1184 .map(({ item }) => item);
1185}