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