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

settingsSearch.ts

1,026 lines32.3 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/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;
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;
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;
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: "worktree-submodules",
425 title: "Submodules",
426 to: "/settings/general",
427 scope: "project-defaults",
428 searchTerms: ["git submodule init recursive top-level none worktree t3.json"],
429 },
430 {
431 id: "start-from-origin",
432 title: "Start from origin",
433 to: "/settings/general",
434 scope: "project-defaults",
435 searchTerms: ["new worktrees latest matching remote branch local"],
436 },
437 {
438 id: "add-project-starts-in",
439 title: "Add project starts in",
440 to: "/settings/general",
441 scope: "environment-defaults",
442 searchTerms: ["base directory folder browser path home"],
443 },
444 {
445 id: "unpin-confirmation",
446 title: "Unpin confirmation",
447 to: "/settings/general",
448 searchTerms: ["ask before thread pinned section"],
449 },
450 {
451 id: "archive-confirmation",
452 title: "Archive confirmation",
453 to: "/settings/general",
454 searchTerms: ["ask before thread second click inline action"],
455 },
456 {
457 id: "delete-confirmation",
458 title: "Delete confirmation",
459 to: "/settings/general",
460 searchTerms: ["ask before thread chat history"],
461 },
462 {
463 id: "quit-confirmation",
464 title: "Quit shortcut",
465 to: "/settings/general",
466 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
467 desktopOnly: true,
468 },
469 {
470 id: "text-generation-model",
471 title: "Text generation model",
472 to: "/settings/general",
473 scope: "project-defaults",
474 searchTerms: ["generated thread titles source control content default provider"],
475 },
476 {
477 id: "diagnostics",
478 title: "Diagnostics",
479 to: "/settings/general",
480 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
481 },
482 {
483 id: "open-source-licenses",
484 title: "Open source licenses",
485 to: "/settings/general",
486 },
487 {
488 id: "legacy-plan-mode",
489 title: "Plan mode (legacy)",
490 to: "/settings/general",
491 searchTerms: ["build plan composer old"],
492 },
493 {
494 id: "legacy-context-window-indicator",
495 title: "Context window indicator (legacy)",
496 to: "/settings/general",
497 searchTerms: ["composer meter usage tokens circle old"],
498 },
499 {
500 id: "legacy-sidebar",
501 title: "Sidebar (legacy)",
502 to: "/settings/general",
503 searchTerms: ["project thread tree old flat list"],
504 },
505 {
506 id: "keybindings",
507 title: "Keybindings",
508 to: "/settings/keybindings",
509 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
510 },
511 ...KEYBINDING_SEARCH_ITEMS,
512 {
513 id: "snap-shot-enabled",
514 title: "SnapShots",
515 searchTerms: ["window capture screenshot"],
516 to: "/settings/snap-shot",
517 },
518 {
519 id: "snap-shot-accessibility",
520 title: "Include app text",
521 to: "/settings/snap-shot",
522 targetId: "snap-shot-enabled",
523 searchTerms: [
524 "capture accessibility data text UI structure elements privacy omit agent context",
525 ],
526 },
527 {
528 id: "snap-shot-shortcut",
529 title: "Capture shortcut",
530 to: "/settings/snap-shot",
531 targetId: "snap-shot-enabled",
532 },
533 {
534 id: "snap-shot-sound",
535 title: "Capture sound",
536 to: "/settings/snap-shot",
537 targetId: "snap-shot-enabled",
538 },
539 {
540 id: "snap-shot-flash",
541 title: "Capture flash",
542 to: "/settings/snap-shot",
543 targetId: "snap-shot-enabled",
544 },
545 {
546 id: "snap-shot-animations",
547 title: "Capture animations",
548 to: "/settings/snap-shot",
549 targetId: "snap-shot-enabled",
550 },
551 {
552 id: "providers",
553 title: "Providers",
554 to: "/settings/providers",
555 searchTerms: [
556 "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",
557 ],
558 },
559 {
560 id: "usage-providers",
561 title: "Usage providers",
562 to: "/settings/providers",
563 searchTerms: [
564 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
565 ],
566 providerSettingsOnly: true,
567 },
568 {
569 id: "provider-health-check-interval",
570 title: "Health check interval",
571 to: "/settings/providers",
572 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
573 providerSettingsOnly: true,
574 },
575 {
576 id: "agent-browser-access",
577 title: "Agent browser access",
578 to: "/settings/integrations",
579 scope: "project-defaults",
580 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
581 },
582 {
583 id: "device-hosts",
584 title: "Device hosts",
585 to: "/settings/integrations",
586 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
587 },
588 {
589 id: "agent-device-access",
590 title: "Agent device access",
591 to: "/settings/integrations",
592 targetId: "devices",
593 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
594 },
595 {
596 id: "device-hub",
597 title: "Device hub",
598 to: "/settings/integrations",
599 targetId: "devices",
600 searchTerms: ["simulator emulator ios android install start"],
601 },
602 {
603 id: "device-platform-support",
604 title: "Simulator support",
605 to: "/settings/integrations",
606 targetId: "devices",
607 searchTerms: ["xcode android studio sdk avd runtime"],
608 },
609 {
610 id: "browser-profiles",
611 title: "Browser profiles",
612 to: "/settings/integrations",
613 targetId: "browser",
614 },
615 {
616 id: "browser-default-profile",
617 title: "Default browser profile",
618 to: "/settings/integrations",
619 targetId: "browser-profiles",
620 },
621 {
622 id: "browser-default-viewport",
623 title: "Default browser viewport",
624 to: "/settings/integrations",
625 searchTerms: ["preview size width height device desktop mobile rotate"],
626 },
627 {
628 id: "browser-default-zoom",
629 title: "Default browser zoom",
630 to: "/settings/integrations",
631 searchTerms: ["preview page scale tabs percent"],
632 },
633 {
634 id: "browser-default-appearance",
635 title: "Default browser appearance",
636 to: "/settings/integrations",
637 searchTerms: ["preview color scheme light dark system os"],
638 },
639 {
640 id: "browser-recording-frame-rate",
641 title: "Browser recording frame rate",
642 to: "/settings/integrations",
643 },
644 {
645 id: "browser-recording-key-presses",
646 title: "Show key presses in recordings",
647 to: "/settings/integrations",
648 searchTerms: ["browser preview keyboard shortcuts keystrokes overlay capture"],
649 },
650 {
651 id: "browser-recording-mouse-presses",
652 title: "Show mouse presses in recordings",
653 to: "/settings/integrations",
654 searchTerms: ["browser preview clicks buttons drag overlay capture"],
655 },
656 {
657 id: "browser-link-target",
658 title: "Open links in",
659 to: "/settings/integrations",
660 searchTerms: ["links default browser in-app browser external open"],
661 },
662 {
663 id: "browser-auto-show-floating-preview",
664 title: "Auto-show floating preview",
665 to: "/settings/integrations",
666 searchTerms: ["agent opens browser device simulator pop into view hide"],
667 },
668 {
669 id: "automatic-pull",
670 title: "Automatically pull",
671 to: "/settings/source-control",
672 scope: "project-defaults",
673 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
674 },
675 {
676 id: "pull-request-merge-method",
677 title: "Default merge method",
678 to: "/settings/source-control",
679 scope: "project-defaults",
680 searchTerms: ["pull request merge squash rebase last selected"],
681 },
682 {
683 id: "source-control",
684 title: "Source control",
685 to: "/settings/source-control",
686 scope: "environment-defaults",
687 searchTerms: [
688 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
689 ],
690 },
691 {
692 id: "git-fetch-interval",
693 title: "Git fetch interval",
694 to: "/settings/source-control",
695 searchTerms: [
696 "automatic remote branch refresh background credentials security keys seconds off",
697 ],
698 environmentOnly: true,
699 scope: "environment-defaults",
700 },
701 {
702 id: "worktree-branch-naming",
703 title: "Worktree branch naming",
704 to: "/settings/source-control",
705 searchTerms: ["static semantic prefix custom prompt instructions feat fix refactor chore"],
706 environmentOnly: true,
707 scope: "project-defaults",
708 },
709 {
710 id: "source-control-writing-style",
711 title: "Source control writing style",
712 to: "/settings/source-control",
713 searchTerms: [
714 "repository conventions conventional commits custom instructions change descriptions request titles",
715 ],
716 environmentOnly: true,
717 },
718 {
719 id: "follow-change-request-templates",
720 title: "Follow change request templates",
721 to: "/settings/source-control",
722 searchTerms: ["repository pr pull request description structure"],
723 environmentOnly: true,
724 },
725 {
726 id: "source-control-writer-model",
727 title: "Source control writer model",
728 to: "/settings/source-control",
729 searchTerms: [
730 "override generated commit change request pr titles descriptions branch bookmark",
731 ],
732 environmentOnly: true,
733 scope: "project-defaults",
734 },
735 {
736 id: "project-actions",
737 title: "Actions",
738 to: "/settings/projects",
739 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
740 },
741 {
742 id: "environment-icon",
743 title: "Environment icon",
744 to: "/settings/connections",
745 targetId: "connections-environment",
746 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
747 localBackendManagementOnly: true,
748 },
749 {
750 id: "local-environment",
751 title: "Local environment",
752 to: "/settings/connections",
753 targetId: "connections-environment",
754 searchTerms: ["turn off on disable enable local server agents remote only restart"],
755 desktopOnly: true,
756 },
757 {
758 id: "network-access",
759 title: "Network access",
760 to: "/settings/connections",
761 targetId: "connections-environment",
762 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
763 localBackendManagementOnly: true,
764 },
765 {
766 id: "tailscale-https",
767 title: "Tailscale HTTPS",
768 to: "/settings/connections",
769 targetId: "connections-environment",
770 searchTerms: ["serve magicdns endpoint remote secure network"],
771 desktopOnly: true,
772 localBackendManagementOnly: true,
773 },
774 {
775 id: "wsl-backend",
776 title: "WSL backend",
777 to: "/settings/connections",
778 searchTerms: [
779 "windows subsystem linux distro second server projects stop windows backend restart",
780 ],
781 desktopOnly: true,
782 windowsOnly: true,
783 localBackendManagementOnly: true,
784 wslAvailableOnly: true,
785 },
786 {
787 id: "t3-connect",
788 localEnvironmentOnly: true,
789 title: "T3 Connect",
790 to: "/settings/connections",
791 targetId: "connections-environment",
792 searchTerms: ["managed tunnel cloud other devices remote"],
793 desktopOnly: true,
794 cloudOnly: true,
795 },
796 {
797 id: "publish-agent-activity",
798 localEnvironmentOnly: true,
799 title: "Publish agent activity",
800 to: "/settings/connections",
801 targetId: "connections-environment",
802 searchTerms: ["mobile push notifications live activities cloud tunnel"],
803 cloudOnly: true,
804 },
805 {
806 id: "connections-environment",
807 title: "This machine",
808 to: "/settings/connections",
809 searchTerms: [
810 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
811 ],
812 },
813 {
814 id: "remote-environments",
815 title: "Environments",
816 to: "/settings/connections",
817 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
818 },
819 {
820 id: "load-balancing",
821 title: "Load balancing",
822 to: "/settings/connections",
823 searchTerms: [
824 "automatic machine environment resources cpu memory capacity preference weight shared projects",
825 ],
826 },
827 {
828 id: "github-routing",
829 title: "GitHub sharing",
830 to: "/settings/connections",
831 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
832 },
833 {
834 id: "archive",
835 title: "Archived threads",
836 to: "/settings/archived",
837 searchTerms: ["restore reopen deleted history projects"],
838 },
839] as const satisfies ReadonlyArray<SettingsSearchItem>;
840​
841export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
842​
843const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
844​
845const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
846 "/settings/projects": "project",
847 "/settings/general": null,
848 "/settings/appearance": null,
849 "/settings/snap-shot": null,
850 // Keybindings fan out to the selection; Providers shows the representative
851 // environment at any selection. Neither needs a particular scope to render.
852 "/settings/keybindings": null,
853 "/settings/providers": null,
854 "/settings/integrations": null,
855 "/settings/source-control": "environment-defaults",
856 "/settings/storage": "project-defaults",
857 "/settings/connections": "connections",
858 "/settings/scheduled-tasks": null,
859 "/settings/archived": "project-defaults",
860};
861​
862/** Search keeps the selected target. A missing row can explain its owning scope instead. */
863export function getSettingsSearchTargetScope(targetId: string) {
864 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
865 const item =
866 items.find((candidate) => candidate.id === targetId) ??
867 items.find((candidate) => candidate.targetId === targetId);
868 return item
869 ? {
870 title: item.title,
871 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
872 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
873 }
874 : null;
876​
877interface AutoSettlementSearchEnvironment {
878 readonly environmentId: EnvironmentId;
879 readonly connection: { readonly phase: EnvironmentConnectionPhase };
880 readonly serverConfig: {
881 readonly environment: {
882 readonly capabilities: { readonly threadAutoSettlement?: boolean };
883 };
884 } | null;
886​
887/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
888export function getThreadAutoSettlementSearchAvailability(
889 environments: readonly AutoSettlementSearchEnvironment[],
890 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
891) {
892 const connected = environments.filter(
893 (environment) =>
894 environment.connection.phase === "connected" && environment.serverConfig !== null,
895 );
896 const eligibleEnvironmentIds = connected
897 .filter(
898 (environment) =>
899 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
900 )
901 .map((environment) => environment.environmentId);
902 const selected = connected.filter((environment) =>
903 scope?.environmentIds.includes(environment.environmentId),
904 );
905 return {
906 eligibleEnvironmentIds,
907 isTargetAvailable:
908 scope !== undefined &&
909 scope.kind !== "unavailable" &&
910 selected.length > 0 &&
911 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
912 };
914​
915export function isSettingsSearchScopeAvailable(
916 requiredScope: SettingsSearchScope | null,
917 scopeKind: ResolvedSettingsScope["kind"],
918): boolean {
919 switch (requiredScope) {
920 case null:
921 case "connections":
922 return true;
923 case "environment":
924 case "checkout":
925 return requiredScope === scopeKind;
926 case "project":
927 return scopeKind === "project" || scopeKind === "checkout";
928 case "environment-defaults":
929 return scopeKind === "environment" || scopeKind === "all";
930 case "project-defaults":
931 return (
932 scopeKind === "environment" ||
933 scopeKind === "all" ||
934 scopeKind === "project" ||
935 scopeKind === "checkout"
936 );
937 }
939​
940function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
941 const target = validateSettingsScopeSearch({ ...search });
942 if (target.checkout && !target.project) return "unavailable";
943 if (target.project) return target.checkout ? "checkout" : "project";
944 return target.machine ? "environment" : "all";
946​
947export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
948 const kind = settingsScopeKindFromSearch(search);
949 return kind === "project" || kind === "checkout";
951​
952/**
953 * `id` and `title` props for the element a search item anchors to. Panels
954 * spread (or pick from) this instead of restating the strings, so the catalog
955 * and the rendered settings cannot drift apart.
956 */
957export function searchableSetting(id: SettingsSearchItemId): {
958 readonly id: string;
959 readonly title: string;
960} {
961 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
962 return { id: anchorId, title };
964​
965export function filterAvailableSettingsSearchItems(
966 availability: SettingsSearchAvailability,
967): ReadonlyArray<SettingsSearchItem> {
968 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
969 return items.filter(
970 (item) =>
971 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
972 (!item.environmentOnly || availability.hasEnvironment) &&
973 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
974 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
975 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
976 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
977 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
978 );
980​
981export function searchSettings(
982 query: string,
983 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
984): ReadonlyArray<SettingsSearchItem> {
985 const normalizedQuery = normalizeSearchText(query);
986 if (normalizedQuery.length === 0) return [];
987 const queryTokens = normalizedQuery.split(" ");
988 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
989​
990 return items
991 .flatMap((item, index) => {
992 if (!isElectron && item.desktopOnly === true) return [];
993 if (item.macOnly && !isMacPlatform(platform)) return [];
994 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
995​
996 const title = normalizeSearchText(item.title);
997 const fields = [
998 title,
999 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1000 ...(item.searchTerms ?? []).map(normalizeSearchText),
1001 ];
1002 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1003​
1004 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1005 const rank =
1006 title === normalizedQuery
1007 ? 5
1008 : title.startsWith(normalizedQuery)
1009 ? 4
1010 : title.includes(normalizedQuery)
1011 ? 3
1012 : queryTokens.every((token) => title.includes(token))
1013 ? 2
1014 : exactPhraseField >= 0
1015 ? 1
1016 : 0;
1017 return [{ item, index, rank }];
1018 })
1019 .toSorted(
1020 (left, right) =>
1021 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1022 right.rank - left.rank ||
1023 left.index - right.index,
1025 .map(({ item }) => item);