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