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