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