Open History to see the last commit
1import { isElectron } from "~/env";
2import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
3import { STATIC_KEYBINDING_COMMANDS, type KeybindingCommand } from "@t3tools/contracts";
4import type { EnvironmentId } from "@t3tools/contracts";
5import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
6import { DEFAULT_KEYBINDINGS } from "@t3tools/shared/keybindings";
7import { commandLabel } from "./KeybindingsSettings.logic";
8import {
9 validateSettingsScopeSearch,
10 type ResolvedSettingsScope,
11 type SettingsScopeSearch,
12} from "./settingsScope";
13
14export type SettingsPath =
15 | "/settings/projects"
16 | "/settings/general"
17 | "/settings/appearance"
18 | "/settings/keybindings"
19 | "/settings/snap-shot"
20 | "/settings/providers"
21 | "/settings/integrations"
22 | "/settings/scheduled-tasks"
23 | "/settings/source-control"
24 | "/settings/storage"
25 | "/settings/connections"
26 | "/settings/archived";
27
28/**
29 * Where a setting can be edited. Device-local rows have no scope: they render
30 * at every selection. `project-defaults` rows accept project overrides, so
31 * they are reachable from any server-backed selection.
32 */
33export type SettingsSearchScope =
34 | "environment"
35 | "environment-defaults"
36 | "project-defaults"
37 | "project"
38 | "checkout"
39 | "connections";
40
41export interface SettingsSearchItem {
42 readonly id: string;
43 readonly title: string;
44 readonly to: SettingsPath;
45 readonly targetId?: string;
46 /** Descriptions, option labels, and aliases people may remember instead of the title. */
47 readonly searchTerms?: ReadonlyArray<string>;
48 readonly scope?: SettingsSearchScope;
49 // Its row only renders in the desktop app, so a browser result would land on
50 // an anchor that isn't there.
51 readonly desktopOnly?: boolean;
52 readonly macOnly?: boolean;
53 // Its row only renders on Windows desktop, so other desktop platforms must
54 // not expose a result that points to a missing anchor.
55 readonly windowsOnly?: boolean;
56 readonly cloudOnly?: boolean;
57 readonly environmentOnly?: boolean;
58 readonly providerSettingsOnly?: boolean;
59 readonly 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;
69}
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;
80}
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;
104}
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: "source-control-writing-style",
727 title: "Source control writing style",
728 to: "/settings/source-control",
729 searchTerms: [
730 "repository conventions conventional commits custom instructions change descriptions request titles",
731 ],
732 environmentOnly: true,
733 },
734 {
735 id: "follow-change-request-templates",
736 title: "Follow change request templates",
737 to: "/settings/source-control",
738 searchTerms: ["repository pr pull request description structure"],
739 environmentOnly: true,
740 },
741 {
742 id: "source-control-writer-model",
743 title: "Source control writer model",
744 to: "/settings/source-control",
745 searchTerms: [
746 "override generated commit change request pr titles descriptions branch bookmark",
747 ],
748 environmentOnly: true,
749 scope: "project-defaults",
750 },
751 {
752 id: "project-actions",
753 title: "Actions",
754 to: "/settings/projects",
755 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
756 },
757 {
758 id: "environment-icon",
759 title: "Environment icon",
760 to: "/settings/connections",
761 targetId: "connections-environment",
762 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
763 localBackendManagementOnly: true,
764 },
765 {
766 id: "local-environment",
767 title: "Local environment",
768 to: "/settings/connections",
769 targetId: "connections-environment",
770 searchTerms: ["turn off on disable enable local server agents remote only restart"],
771 desktopOnly: true,
772 },
773 {
774 id: "network-access",
775 title: "Network access",
776 to: "/settings/connections",
777 targetId: "connections-environment",
778 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
779 localBackendManagementOnly: true,
780 },
781 {
782 id: "tailscale-https",
783 title: "Tailscale HTTPS",
784 to: "/settings/connections",
785 targetId: "connections-environment",
786 searchTerms: ["serve magicdns endpoint remote secure network"],
787 desktopOnly: true,
788 localBackendManagementOnly: true,
789 },
790 {
791 id: "wsl-backend",
792 title: "WSL backend",
793 to: "/settings/connections",
794 searchTerms: [
795 "windows subsystem linux distro second server projects stop windows backend restart",
796 ],
797 desktopOnly: true,
798 windowsOnly: true,
799 localBackendManagementOnly: true,
800 wslAvailableOnly: true,
801 },
802 {
803 id: "t3-connect",
804 localEnvironmentOnly: true,
805 title: "T3 Connect",
806 to: "/settings/connections",
807 targetId: "connections-environment",
808 searchTerms: ["managed tunnel cloud other devices remote"],
809 desktopOnly: true,
810 cloudOnly: true,
811 },
812 {
813 id: "publish-agent-activity",
814 localEnvironmentOnly: true,
815 title: "Publish agent activity",
816 to: "/settings/connections",
817 targetId: "connections-environment",
818 searchTerms: ["mobile push notifications live activities cloud tunnel"],
819 cloudOnly: true,
820 },
821 {
822 id: "connections-environment",
823 title: "This machine",
824 to: "/settings/connections",
825 searchTerms: [
826 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
827 ],
828 },
829 {
830 id: "remote-environments",
831 title: "Environments",
832 to: "/settings/connections",
833 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
834 },
835 {
836 id: "load-balancing",
837 title: "Load balancing",
838 to: "/settings/connections",
839 searchTerms: [
840 "automatic machine environment resources cpu memory capacity preference weight shared projects",
841 ],
842 },
843 {
844 id: "github-routing",
845 title: "GitHub sharing",
846 to: "/settings/connections",
847 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
848 },
849 {
850 id: "archive",
851 title: "Archived threads",
852 to: "/settings/archived",
853 searchTerms: ["restore reopen deleted history projects"],
854 },
855] as const satisfies ReadonlyArray<SettingsSearchItem>;
856
857export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
858
859const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
860
861const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
862 "/settings/projects": "project",
863 "/settings/general": null,
864 "/settings/appearance": null,
865 "/settings/snap-shot": null,
866 // Keybindings fan out to the selection; Providers shows the representative
867 // environment at any selection. Neither needs a particular scope to render.
868 "/settings/keybindings": null,
869 "/settings/providers": null,
870 "/settings/integrations": null,
871 "/settings/source-control": "environment-defaults",
872 "/settings/storage": "project-defaults",
873 "/settings/connections": "connections",
874 "/settings/scheduled-tasks": null,
875 "/settings/archived": "project-defaults",
876};
877
878/** Search keeps the selected target. A missing row can explain its owning scope instead. */
879export function getSettingsSearchTargetScope(targetId: string) {
880 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
881 const item =
882 items.find((candidate) => candidate.id === targetId) ??
883 items.find((candidate) => candidate.targetId === targetId);
884 return item
885 ? {
886 title: item.title,
887 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
888 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
889 }
890 : null;
891}
892
893interface AutoSettlementSearchEnvironment {
894 readonly environmentId: EnvironmentId;
895 readonly connection: { readonly phase: EnvironmentConnectionPhase };
896 readonly serverConfig: {
897 readonly environment: {
898 readonly capabilities: { readonly threadAutoSettlement?: boolean };
899 };
900 } | null;
901}
902
903/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
904export function getThreadAutoSettlementSearchAvailability(
905 environments: readonly AutoSettlementSearchEnvironment[],
906 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
907) {
908 const connected = environments.filter(
909 (environment) =>
910 environment.connection.phase === "connected" && environment.serverConfig !== null,
911 );
912 const eligibleEnvironmentIds = connected
913 .filter(
914 (environment) =>
915 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
916 )
917 .map((environment) => environment.environmentId);
918 const selected = connected.filter((environment) =>
919 scope?.environmentIds.includes(environment.environmentId),
920 );
921 return {
922 eligibleEnvironmentIds,
923 isTargetAvailable:
924 scope !== undefined &&
925 scope.kind !== "unavailable" &&
926 selected.length > 0 &&
927 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
928 };
929}
930
931export function isSettingsSearchScopeAvailable(
932 requiredScope: SettingsSearchScope | null,
933 scopeKind: ResolvedSettingsScope["kind"],
934): boolean {
935 switch (requiredScope) {
936 case null:
937 case "connections":
938 return true;
939 case "environment":
940 case "checkout":
941 return requiredScope === scopeKind;
942 case "project":
943 return scopeKind === "project" || scopeKind === "checkout";
944 case "environment-defaults":
945 return scopeKind === "environment" || scopeKind === "all";
946 case "project-defaults":
947 return (
948 scopeKind === "environment" ||
949 scopeKind === "all" ||
950 scopeKind === "project" ||
951 scopeKind === "checkout"
952 );
953 }
954}
955
956function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
957 const target = validateSettingsScopeSearch({ ...search });
958 if (target.checkout && !target.project) return "unavailable";
959 if (target.project) return target.checkout ? "checkout" : "project";
960 return target.machine ? "environment" : "all";
961}
962
963export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
964 const kind = settingsScopeKindFromSearch(search);
965 return kind === "project" || kind === "checkout";
966}
967
968/**
969 * `id` and `title` props for the element a search item anchors to. Panels
970 * spread (or pick from) this instead of restating the strings, so the catalog
971 * and the rendered settings cannot drift apart.
972 */
973export function searchableSetting(id: SettingsSearchItemId): {
974 readonly id: string;
975 readonly title: string;
976} {
977 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
978 return { id: anchorId, title };
979}
980
981export function filterAvailableSettingsSearchItems(
982 availability: SettingsSearchAvailability,
983): ReadonlyArray<SettingsSearchItem> {
984 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
985 return items.filter(
986 (item) =>
987 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
988 (!item.environmentOnly || availability.hasEnvironment) &&
989 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
990 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
991 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
992 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
993 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
994 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
995 );
996}
997
998export function searchSettings(
999 query: string,
1000 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
1001): ReadonlyArray<SettingsSearchItem> {
1002 const normalizedQuery = normalizeSearchText(query);
1003 if (normalizedQuery.length === 0) return [];
1004 const queryTokens = normalizedQuery.split(" ");
1005 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
1006
1007 return items
1008 .flatMap((item, index) => {
1009 if (!isElectron && item.desktopOnly === true) return [];
1010 if (item.macOnly && !isMacPlatform(platform)) return [];
1011 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
1012
1013 const title = normalizeSearchText(item.title);
1014 const fields = [
1015 title,
1016 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1017 ...(item.searchTerms ?? []).map(normalizeSearchText),
1018 ];
1019 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1020
1021 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1022 const rank =
1023 title === normalizedQuery
1024 ? 5
1025 : title.startsWith(normalizedQuery)
1026 ? 4
1027 : title.includes(normalizedQuery)
1028 ? 3
1029 : queryTokens.every((token) => title.includes(token))
1030 ? 2
1031 : exactPhraseField >= 0
1032 ? 1
1033 : 0;
1034 return [{ item, index, rank }];
1035 })
1036 .toSorted(
1037 (left, right) =>
1038 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1039 right.rank - left.rank ||
1040 left.index - right.index,
1041 )
1042 .map(({ item }) => item);
1043}