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