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