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