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

settingsSearch.ts

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