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

settingsSearch.ts

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