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