Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settingsSearch.ts

1,009 lines31.9 KB

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/source-control"
23 | "/settings/storage"
24 | "/settings/connections"
25 | "/settings/archived";
26​
27/**
28 * Where a setting can be edited. Device-local rows have no scope: they render
29 * at every selection. `project-defaults` rows accept project overrides, so
30 * they are reachable from any server-backed selection.
31 */
32export type SettingsSearchScope =
33 | "environment"
34 | "environment-defaults"
35 | "project-defaults"
36 | "project"
37 | "checkout"
38 | "connections";
39​
40export interface SettingsSearchItem {
41 readonly id: string;
42 readonly title: string;
43 readonly to: SettingsPath;
44 readonly targetId?: string;
45 /** Descriptions, option labels, and aliases people may remember instead of the title. */
46 readonly searchTerms?: ReadonlyArray<string>;
47 readonly scope?: SettingsSearchScope;
48 // Its row only renders in the desktop app, so a browser result would land on
49 // an anchor that isn't there.
50 readonly desktopOnly?: boolean;
51 readonly macOnly?: boolean;
52 // Its row only renders on Windows desktop, so other desktop platforms must
53 // not expose a result that points to a missing anchor.
54 readonly windowsOnly?: boolean;
55 readonly cloudOnly?: boolean;
56 readonly environmentOnly?: boolean;
57 readonly providerSettingsOnly?: boolean;
58 readonly macProviderSettingsOnly?: 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;
69​
70export interface SettingsSearchAvailability {
71 readonly localEnvironmentDisabled?: boolean;
72 readonly hasCloudPublicConfig: boolean;
73 readonly hasEnvironment: boolean;
74 readonly hasProviderSettingsEnvironment: boolean;
75 readonly hasMacProviderSettingsEnvironment: boolean;
76 readonly canManageLocalBackend: boolean;
77 readonly isWslSettingsRowVisible: boolean;
78 readonly hasThreadAutoSettlement: boolean;
80​
81/**
82 * Section labels in sidebar order. The sidebar nav and the search-result
83 * subtitles both render from this record, so each label exists once.
84 */
85export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
86 "/settings/projects": "Project",
87 "/settings/general": "General",
88 "/settings/appearance": "Appearance",
89 "/settings/keybindings": "Keybindings",
90 "/settings/snap-shot": "SnapShots",
91 "/settings/providers": "Providers",
92 "/settings/integrations": "Integrations",
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;
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: "project-grouping",
266 title: "Project grouping",
267 to: "/settings/general",
268 searchTerms: ["combine matching repositories environments sidebar"],
269 },
270 {
271 id: "auto-settle-inactive-threads",
272 title: "Auto-settle inactive threads",
273 to: "/settings/general",
274 searchTerms: ["sidebar inactivity days no activity automatically"],
275 requiresThreadAutoSettlement: true,
276 scope: "project-defaults",
277 },
278 {
279 id: "auto-settle-merged-threads",
280 title: "Auto-settle merged threads",
281 to: "/settings/general",
282 searchTerms: ["pull request merge closed automatically sidebar"],
283 requiresThreadAutoSettlement: true,
284 scope: "project-defaults",
285 },
286 {
287 id: "days-before-auto-settle",
288 title: "Days of inactivity before auto-settle",
289 to: "/settings/general",
290 targetId: "auto-settle-inactive-threads",
291 searchTerms: ["thread timeout activity sidebar"],
292 requiresThreadAutoSettlement: true,
293 scope: "project-defaults",
294 },
295 {
296 id: "thread-notifications",
297 title: "Thread notifications",
298 to: "/settings/general",
299 searchTerms: ["notification sound alert completion input approval desktop"],
300 },
301 {
302 id: "in-app-notifications",
303 title: "In-app notifications",
304 to: "/settings/general",
305 searchTerms: ["notification toast popup completion input approval failure"],
306 },
307 {
308 id: "time-format",
309 title: "Time format",
310 to: "/settings/general",
311 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
312 },
313 {
314 id: "response-streaming",
315 title: "Response streaming",
316 to: "/settings/general",
317 scope: "project-defaults",
318 searchTerms: ["output token paragraph buffered wait turn legacy"],
319 },
320 {
321 id: "hide-whitespace-changes",
322 title: "Hide whitespace changes",
323 to: "/settings/general",
324 searchTerms: ["diff ignore spaces edits default"],
325 },
326 {
327 id: "default-diff-file-state",
328 title: "Default diff file state",
329 to: "/settings/general",
330 searchTerms: ["collapsed expanded collapse expand files pull request pr code tab"],
331 },
332 {
333 id: "diff-layout",
334 title: "Diff layout",
335 to: "/settings/general",
336 searchTerms: ["stacked split side by side unified inline view"],
337 },
338 {
339 id: "proactive-panels",
340 title: "Proactive panels",
341 to: "/settings/general",
342 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
343 },
344 {
345 id: "skills-in-slash-menu",
346 title: "Show skills in slash menu",
347 to: "/settings/general",
348 searchTerms: ["command menu dollar $ slash /"],
349 },
350 {
351 id: "composer-rich-text",
352 title: "Rich text composer",
353 to: "/settings/general",
354 searchTerms: ["composer rich text tiptap bold italic markdown styled wysiwyg"],
355 },
356 {
357 id: "composer-collapse",
358 title: "Collapse composer on scroll",
359 to: "/settings/general",
360 searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
361 },
362 {
363 id: "send-shortcut",
364 title: "Send shortcut",
365 to: "/settings/general",
366 searchTerms: ["enter return command ctrl multiline prompt new line composer"],
367 },
368 {
369 id: "follow-up-behavior",
370 title: "Follow-up behavior",
371 to: "/settings/general",
372 searchTerms: ["queue steer running turn send default behavior composer"],
373 },
374 {
375 id: "provider-update-checks",
376 title: "Provider update checks",
377 to: "/settings/general",
378 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
379 scope: "environment-defaults",
380 },
381 {
382 id: "continue-threads-after-server-update",
383 title: "Continue threads after restarts",
384 to: "/settings/general",
385 scope: "project-defaults",
386 searchTerms: [
387 "resume running active interrupted work restart reboot machine crash desktop update automatically",
388 ],
389 },
390 {
391 id: "background-activity",
392 title: "Background activity",
393 to: "/settings/general",
394 scope: "environment-defaults",
395 searchTerms: [
396 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
397 ],
398 },
399 {
400 id: "new-threads",
401 title: "New threads",
402 to: "/settings/general",
403 scope: "project-defaults",
404 searchTerms: ["default workspace mode draft local worktree"],
405 },
406 {
407 id: "worktree-submodules",
408 title: "Submodules",
409 to: "/settings/general",
410 scope: "project-defaults",
411 searchTerms: ["git submodule init recursive top-level none worktree t3.json"],
412 },
413 {
414 id: "start-from-origin",
415 title: "Start from origin",
416 to: "/settings/general",
417 scope: "project-defaults",
418 searchTerms: ["new worktrees latest matching remote branch local"],
419 },
420 {
421 id: "add-project-starts-in",
422 title: "Add project starts in",
423 to: "/settings/general",
424 scope: "environment-defaults",
425 searchTerms: ["base directory folder browser path home"],
426 },
427 {
428 id: "unpin-confirmation",
429 title: "Unpin confirmation",
430 to: "/settings/general",
431 searchTerms: ["ask before thread pinned section"],
432 },
433 {
434 id: "archive-confirmation",
435 title: "Archive confirmation",
436 to: "/settings/general",
437 searchTerms: ["ask before thread second click inline action"],
438 },
439 {
440 id: "delete-confirmation",
441 title: "Delete confirmation",
442 to: "/settings/general",
443 searchTerms: ["ask before thread chat history"],
444 },
445 {
446 id: "quit-confirmation",
447 title: "Quit shortcut",
448 to: "/settings/general",
449 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
450 desktopOnly: true,
451 },
452 {
453 id: "text-generation-model",
454 title: "Text generation model",
455 to: "/settings/general",
456 scope: "project-defaults",
457 searchTerms: ["generated thread titles source control content default provider"],
458 },
459 {
460 id: "diagnostics",
461 title: "Diagnostics",
462 to: "/settings/general",
463 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
464 },
465 {
466 id: "open-source-licenses",
467 title: "Open source licenses",
468 to: "/settings/general",
469 },
470 {
471 id: "legacy-plan-mode",
472 title: "Plan mode (legacy)",
473 to: "/settings/general",
474 searchTerms: ["build plan composer old"],
475 },
476 {
477 id: "legacy-context-window-indicator",
478 title: "Context window indicator (legacy)",
479 to: "/settings/general",
480 searchTerms: ["composer meter usage tokens circle old"],
481 },
482 {
483 id: "legacy-sidebar",
484 title: "Sidebar (legacy)",
485 to: "/settings/general",
486 searchTerms: ["project thread tree old flat list"],
487 },
488 {
489 id: "keybindings",
490 title: "Keybindings",
491 to: "/settings/keybindings",
492 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
493 },
494 ...KEYBINDING_SEARCH_ITEMS,
495 {
496 id: "snap-shot-enabled",
497 title: "SnapShots",
498 searchTerms: ["window capture screenshot"],
499 to: "/settings/snap-shot",
500 },
501 {
502 id: "snap-shot-accessibility",
503 title: "Include app text",
504 to: "/settings/snap-shot",
505 targetId: "snap-shot-enabled",
506 searchTerms: [
507 "capture accessibility data text UI structure elements privacy omit agent context",
508 ],
509 },
510 {
511 id: "snap-shot-shortcut",
512 title: "Capture shortcut",
513 to: "/settings/snap-shot",
514 targetId: "snap-shot-enabled",
515 },
516 {
517 id: "snap-shot-sound",
518 title: "Capture sound",
519 to: "/settings/snap-shot",
520 targetId: "snap-shot-enabled",
521 },
522 {
523 id: "snap-shot-flash",
524 title: "Capture flash",
525 to: "/settings/snap-shot",
526 targetId: "snap-shot-enabled",
527 },
528 {
529 id: "snap-shot-animations",
530 title: "Capture animations",
531 to: "/settings/snap-shot",
532 targetId: "snap-shot-enabled",
533 },
534 {
535 id: "providers",
536 title: "Providers",
537 to: "/settings/providers",
538 searchTerms: [
539 "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",
540 ],
541 },
542 {
543 id: "usage-providers",
544 title: "Usage providers",
545 to: "/settings/providers",
546 searchTerms: [
547 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
548 ],
549 providerSettingsOnly: true,
550 },
551 {
552 id: "cursor-keychain-usage",
553 title: "Cursor account usage",
554 to: "/settings/providers",
555 searchTerms: ["cursor macOS keychain usage tokens cost limits permission"],
556 providerSettingsOnly: true,
557 macProviderSettingsOnly: true,
558 },
559 {
560 id: "provider-health-check-interval",
561 title: "Health check interval",
562 to: "/settings/providers",
563 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
564 providerSettingsOnly: true,
565 },
566 {
567 id: "agent-browser-access",
568 title: "Agent browser access",
569 to: "/settings/integrations",
570 scope: "project-defaults",
571 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
572 },
573 {
574 id: "device-hosts",
575 title: "Device hosts",
576 to: "/settings/integrations",
577 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
578 },
579 {
580 id: "agent-device-access",
581 title: "Agent device access",
582 to: "/settings/integrations",
583 targetId: "devices",
584 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
585 },
586 {
587 id: "device-hub",
588 title: "Device hub",
589 to: "/settings/integrations",
590 targetId: "devices",
591 searchTerms: ["simulator emulator ios android install start"],
592 },
593 {
594 id: "device-platform-support",
595 title: "Simulator support",
596 to: "/settings/integrations",
597 targetId: "devices",
598 searchTerms: ["xcode android studio sdk avd runtime"],
599 },
600 {
601 id: "browser-profiles",
602 title: "Browser profiles",
603 to: "/settings/integrations",
604 targetId: "browser",
605 },
606 {
607 id: "browser-default-profile",
608 title: "Default browser profile",
609 to: "/settings/integrations",
610 targetId: "browser-profiles",
611 },
612 {
613 id: "browser-default-viewport",
614 title: "Default browser viewport",
615 to: "/settings/integrations",
616 searchTerms: ["preview size width height device desktop mobile rotate"],
617 },
618 {
619 id: "browser-default-zoom",
620 title: "Default browser zoom",
621 to: "/settings/integrations",
622 searchTerms: ["preview page scale tabs percent"],
623 },
624 {
625 id: "browser-default-appearance",
626 title: "Default browser appearance",
627 to: "/settings/integrations",
628 searchTerms: ["preview color scheme light dark system os"],
629 },
630 {
631 id: "browser-recording-frame-rate",
632 title: "Browser recording frame rate",
633 to: "/settings/integrations",
634 },
635 {
636 id: "browser-recording-key-presses",
637 title: "Show key presses in recordings",
638 to: "/settings/integrations",
639 searchTerms: ["browser preview keyboard shortcuts keystrokes overlay capture"],
640 },
641 {
642 id: "browser-recording-mouse-presses",
643 title: "Show mouse presses in recordings",
644 to: "/settings/integrations",
645 searchTerms: ["browser preview clicks buttons drag overlay capture"],
646 },
647 {
648 id: "browser-link-target",
649 title: "Open links in",
650 to: "/settings/integrations",
651 searchTerms: ["links default browser in-app browser external open"],
652 },
653 {
654 id: "browser-auto-show-floating-preview",
655 title: "Auto-show floating preview",
656 to: "/settings/integrations",
657 searchTerms: ["agent opens browser device simulator pop into view hide"],
658 },
659 {
660 id: "automatic-pull",
661 title: "Automatically pull",
662 to: "/settings/source-control",
663 scope: "project-defaults",
664 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
665 },
666 {
667 id: "pull-request-merge-method",
668 title: "Default merge method",
669 to: "/settings/source-control",
670 scope: "project-defaults",
671 searchTerms: ["pull request merge squash rebase last selected"],
672 },
673 {
674 id: "source-control",
675 title: "Source control",
676 to: "/settings/source-control",
677 scope: "environment-defaults",
678 searchTerms: [
679 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
680 ],
681 },
682 {
683 id: "git-fetch-interval",
684 title: "Git fetch interval",
685 to: "/settings/source-control",
686 searchTerms: [
687 "automatic remote branch refresh background credentials security keys seconds off",
688 ],
689 environmentOnly: true,
690 scope: "environment-defaults",
691 },
692 {
693 id: "source-control-writing-style",
694 title: "Source control writing style",
695 to: "/settings/source-control",
696 searchTerms: [
697 "repository conventions conventional commits custom instructions change descriptions request titles",
698 ],
699 environmentOnly: true,
700 },
701 {
702 id: "follow-change-request-templates",
703 title: "Follow change request templates",
704 to: "/settings/source-control",
705 searchTerms: ["repository pr pull request description structure"],
706 environmentOnly: true,
707 },
708 {
709 id: "source-control-writer-model",
710 title: "Source control writer model",
711 to: "/settings/source-control",
712 searchTerms: [
713 "override generated commit change request pr titles descriptions branch bookmark",
714 ],
715 environmentOnly: true,
716 scope: "project-defaults",
717 },
718 {
719 id: "project-actions",
720 title: "Actions",
721 to: "/settings/projects",
722 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
723 },
724 {
725 id: "environment-icon",
726 title: "Environment icon",
727 to: "/settings/connections",
728 targetId: "connections-environment",
729 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
730 localBackendManagementOnly: true,
731 },
732 {
733 id: "local-environment",
734 title: "Local environment",
735 to: "/settings/connections",
736 targetId: "connections-environment",
737 searchTerms: ["turn off on disable enable local server agents remote only restart"],
738 desktopOnly: true,
739 },
740 {
741 id: "network-access",
742 title: "Network access",
743 to: "/settings/connections",
744 targetId: "connections-environment",
745 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
746 localBackendManagementOnly: true,
747 },
748 {
749 id: "tailscale-https",
750 title: "Tailscale HTTPS",
751 to: "/settings/connections",
752 targetId: "connections-environment",
753 searchTerms: ["serve magicdns endpoint remote secure network"],
754 desktopOnly: true,
755 localBackendManagementOnly: true,
756 },
757 {
758 id: "wsl-backend",
759 title: "WSL backend",
760 to: "/settings/connections",
761 searchTerms: [
762 "windows subsystem linux distro second server projects stop windows backend restart",
763 ],
764 desktopOnly: true,
765 windowsOnly: true,
766 localBackendManagementOnly: true,
767 wslAvailableOnly: true,
768 },
769 {
770 id: "t3-connect",
771 localEnvironmentOnly: true,
772 title: "T3 Connect",
773 to: "/settings/connections",
774 targetId: "connections-environment",
775 searchTerms: ["managed tunnel cloud other devices remote"],
776 desktopOnly: true,
777 cloudOnly: true,
778 },
779 {
780 id: "publish-agent-activity",
781 localEnvironmentOnly: true,
782 title: "Publish agent activity",
783 to: "/settings/connections",
784 targetId: "connections-environment",
785 searchTerms: ["mobile push notifications live activities cloud tunnel"],
786 cloudOnly: true,
787 },
788 {
789 id: "connections-environment",
790 title: "This machine",
791 to: "/settings/connections",
792 searchTerms: [
793 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
794 ],
795 },
796 {
797 id: "remote-environments",
798 title: "Environments",
799 to: "/settings/connections",
800 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
801 },
802 {
803 id: "load-balancing",
804 title: "Load balancing",
805 to: "/settings/connections",
806 searchTerms: [
807 "automatic machine environment resources cpu memory capacity preference weight shared projects",
808 ],
809 },
810 {
811 id: "github-routing",
812 title: "GitHub sharing",
813 to: "/settings/connections",
814 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
815 },
816 {
817 id: "archive",
818 title: "Archived threads",
819 to: "/settings/archived",
820 searchTerms: ["restore reopen deleted history projects"],
821 },
822] as const satisfies ReadonlyArray<SettingsSearchItem>;
823​
824export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
825​
826const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
827​
828const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
829 "/settings/projects": "project",
830 "/settings/general": null,
831 "/settings/appearance": null,
832 "/settings/snap-shot": null,
833 // Keybindings fan out to the selection; Providers shows the representative
834 // environment at any selection. Neither needs a particular scope to render.
835 "/settings/keybindings": null,
836 "/settings/providers": null,
837 "/settings/integrations": null,
838 "/settings/source-control": "environment-defaults",
839 "/settings/storage": "project-defaults",
840 "/settings/connections": "connections",
841 "/settings/archived": "project-defaults",
842};
843​
844/** Search keeps the selected target. A missing row can explain its owning scope instead. */
845export function getSettingsSearchTargetScope(targetId: string) {
846 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
847 const item =
848 items.find((candidate) => candidate.id === targetId) ??
849 items.find((candidate) => candidate.targetId === targetId);
850 return item
851 ? {
852 title: item.title,
853 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
854 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
855 }
856 : null;
858​
859interface AutoSettlementSearchEnvironment {
860 readonly environmentId: EnvironmentId;
861 readonly connection: { readonly phase: EnvironmentConnectionPhase };
862 readonly serverConfig: {
863 readonly environment: {
864 readonly capabilities: { readonly threadAutoSettlement?: boolean };
865 };
866 } | null;
868​
869/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
870export function getThreadAutoSettlementSearchAvailability(
871 environments: readonly AutoSettlementSearchEnvironment[],
872 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
873) {
874 const connected = environments.filter(
875 (environment) =>
876 environment.connection.phase === "connected" && environment.serverConfig !== null,
877 );
878 const eligibleEnvironmentIds = connected
879 .filter(
880 (environment) =>
881 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
882 )
883 .map((environment) => environment.environmentId);
884 const selected = connected.filter((environment) =>
885 scope?.environmentIds.includes(environment.environmentId),
886 );
887 return {
888 eligibleEnvironmentIds,
889 isTargetAvailable:
890 scope !== undefined &&
891 scope.kind !== "unavailable" &&
892 selected.length > 0 &&
893 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
894 };
896​
897export function isSettingsSearchScopeAvailable(
898 requiredScope: SettingsSearchScope | null,
899 scopeKind: ResolvedSettingsScope["kind"],
900): boolean {
901 switch (requiredScope) {
902 case null:
903 case "connections":
904 return true;
905 case "environment":
906 case "checkout":
907 return requiredScope === scopeKind;
908 case "project":
909 return scopeKind === "project" || scopeKind === "checkout";
910 case "environment-defaults":
911 return scopeKind === "environment" || scopeKind === "all";
912 case "project-defaults":
913 return (
914 scopeKind === "environment" ||
915 scopeKind === "all" ||
916 scopeKind === "project" ||
917 scopeKind === "checkout"
918 );
919 }
921​
922function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
923 const target = validateSettingsScopeSearch({ ...search });
924 if (target.checkout && !target.project) return "unavailable";
925 if (target.project) return target.checkout ? "checkout" : "project";
926 return target.machine ? "environment" : "all";
928​
929export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
930 const kind = settingsScopeKindFromSearch(search);
931 return kind === "project" || kind === "checkout";
933​
934/**
935 * `id` and `title` props for the element a search item anchors to. Panels
936 * spread (or pick from) this instead of restating the strings, so the catalog
937 * and the rendered settings cannot drift apart.
938 */
939export function searchableSetting(id: SettingsSearchItemId): {
940 readonly id: string;
941 readonly title: string;
942} {
943 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
944 return { id: anchorId, title };
946​
947export function filterAvailableSettingsSearchItems(
948 availability: SettingsSearchAvailability,
949): ReadonlyArray<SettingsSearchItem> {
950 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
951 return items.filter(
952 (item) =>
953 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
954 (!item.environmentOnly || availability.hasEnvironment) &&
955 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
956 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
957 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
958 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
959 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
960 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
961 );
963​
964export function searchSettings(
965 query: string,
966 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
967): ReadonlyArray<SettingsSearchItem> {
968 const normalizedQuery = normalizeSearchText(query);
969 if (normalizedQuery.length === 0) return [];
970 const queryTokens = normalizedQuery.split(" ");
971 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
972​
973 return items
974 .flatMap((item, index) => {
975 if (!isElectron && item.desktopOnly === true) return [];
976 if (item.macOnly && !isMacPlatform(platform)) return [];
977 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
978​
979 const title = normalizeSearchText(item.title);
980 const fields = [
981 title,
982 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
983 ...(item.searchTerms ?? []).map(normalizeSearchText),
984 ];
985 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
986​
987 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
988 const rank =
989 title === normalizedQuery
990 ? 5
991 : title.startsWith(normalizedQuery)
992 ? 4
993 : title.includes(normalizedQuery)
994 ? 3
995 : queryTokens.every((token) => title.includes(token))
996 ? 2
997 : exactPhraseField >= 0
998 ? 1
999 : 0;
1000 return [{ item, index, rank }];
1001 })
1002 .toSorted(
1003 (left, right) =>
1004 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1005 right.rank - left.rank ||
1006 left.index - right.index,
1008 .map(({ item }) => item);