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