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: "cli-command",
508 title: "t3 command",
509 to: "/settings/general",
510 searchTerms: ["cli terminal shell path install command line"],
511 desktopOnly: true,
512 },
513 {
514 id: "privacy-policy",
515 title: "Privacy policy",
516 to: "/settings/general",
517 searchTerms: ["telemetry analytics usage data tracking legal opt out"],
518 },
519 {
520 id: "diagnostics",
521 title: "Diagnostics",
522 to: "/settings/general",
523 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
524 },
525 {
526 id: "open-source-licenses",
527 title: "Open source licenses",
528 to: "/settings/general",
529 },
530 {
531 id: "legacy-plan-mode",
532 title: "Plan mode (legacy)",
533 to: "/settings/general",
534 searchTerms: ["build plan composer old"],
535 },
536 {
537 id: "legacy-context-window-indicator",
538 title: "Context window indicator (legacy)",
539 to: "/settings/general",
540 searchTerms: ["composer meter usage tokens circle old"],
541 },
542 {
543 id: "legacy-sidebar",
544 title: "Sidebar (legacy)",
545 to: "/settings/general",
546 searchTerms: ["project thread tree old flat list"],
547 },
548 {
549 id: "keybindings",
550 title: "Keybindings",
551 to: "/settings/keybindings",
552 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
553 },
554 ...KEYBINDING_SEARCH_ITEMS,
555 {
556 id: "snap-shot-enabled",
557 title: "SnapShots",
558 searchTerms: ["window capture screenshot"],
559 to: "/settings/snap-shot",
560 },
561 {
562 id: "snap-shot-accessibility",
563 title: "Include app text",
564 to: "/settings/snap-shot",
565 targetId: "snap-shot-enabled",
566 searchTerms: [
567 "capture accessibility data text UI structure elements privacy omit agent context",
568 ],
569 },
570 {
571 id: "snap-shot-shortcut",
572 title: "Capture shortcut",
573 to: "/settings/snap-shot",
574 targetId: "snap-shot-enabled",
575 },
576 {
577 id: "snap-shot-sound",
578 title: "Capture sound",
579 to: "/settings/snap-shot",
580 targetId: "snap-shot-enabled",
581 },
582 {
583 id: "snap-shot-flash",
584 title: "Capture flash",
585 to: "/settings/snap-shot",
586 targetId: "snap-shot-enabled",
587 },
588 {
589 id: "snap-shot-animations",
590 title: "Capture animations",
591 to: "/settings/snap-shot",
592 targetId: "snap-shot-enabled",
593 },
594 {
595 id: "providers",
596 title: "Providers",
597 to: "/settings/providers",
598 searchTerms: [
599 "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",
600 ],
601 },
602 {
603 id: "usage-providers",
604 title: "Usage providers",
605 to: "/settings/providers",
606 searchTerms: [
607 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
608 ],
609 providerSettingsOnly: true,
610 },
611 {
612 id: "cursor-keychain-usage",
613 title: "Cursor account usage",
614 to: "/settings/providers",
615 searchTerms: ["cursor macOS keychain usage tokens cost limits permission"],
616 providerSettingsOnly: true,
617 macProviderSettingsOnly: true,
618 },
619 {
620 id: "provider-health-check-interval",
621 title: "Health check interval",
622 to: "/settings/providers",
623 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
624 providerSettingsOnly: true,
625 },
626 {
627 id: "agent-browser-access",
628 title: "Agent browser access",
629 to: "/settings/integrations",
630 scope: "project-defaults",
631 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
632 },
633 {
634 id: "device-hosts",
635 title: "Device hosts",
636 to: "/settings/integrations",
637 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
638 },
639 {
640 id: "agent-device-access",
641 title: "Agent device access",
642 to: "/settings/integrations",
643 targetId: "devices",
644 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
645 },
646 {
647 id: "device-hub",
648 title: "Device hub",
649 to: "/settings/integrations",
650 targetId: "devices",
651 searchTerms: ["simulator emulator ios android install start"],
652 },
653 {
654 id: "device-platform-support",
655 title: "Simulator support",
656 to: "/settings/integrations",
657 targetId: "devices",
658 searchTerms: ["xcode android studio sdk avd runtime"],
659 },
660 {
661 id: "browser-profiles",
662 title: "Browser profiles",
663 to: "/settings/integrations",
664 targetId: "browser",
665 },
666 {
667 id: "browser-default-profile",
668 title: "Default browser profile",
669 to: "/settings/integrations",
670 targetId: "browser-profiles",
671 },
672 {
673 id: "browser-default-viewport",
674 title: "Default browser viewport",
675 to: "/settings/integrations",
676 searchTerms: ["preview size width height device desktop mobile rotate"],
677 },
678 {
679 id: "browser-default-zoom",
680 title: "Default browser zoom",
681 to: "/settings/integrations",
682 searchTerms: ["preview page scale tabs percent"],
683 },
684 {
685 id: "browser-default-appearance",
686 title: "Default browser appearance",
687 to: "/settings/integrations",
688 searchTerms: ["preview color scheme light dark system os"],
689 },
690 {
691 id: "browser-recording-frame-rate",
692 title: "Browser recording frame rate",
693 to: "/settings/integrations",
694 },
695 {
696 id: "browser-recording-key-presses",
697 title: "Show key presses in recordings",
698 to: "/settings/integrations",
699 searchTerms: ["browser preview keyboard shortcuts keystrokes overlay capture"],
700 },
701 {
702 id: "browser-recording-mouse-presses",
703 title: "Show mouse presses in recordings",
704 to: "/settings/integrations",
705 searchTerms: ["browser preview clicks buttons drag overlay capture"],
706 },
707 {
708 id: "browser-link-target",
709 title: "Open links in",
710 to: "/settings/integrations",
711 searchTerms: ["links default browser in-app browser external open"],
712 },
713 {
714 id: "browser-auto-show-floating-preview",
715 title: "Auto-show floating preview",
716 to: "/settings/integrations",
717 searchTerms: ["agent opens browser device simulator pop into view hide"],
718 },
719 {
720 id: "automatic-pull",
721 title: "Automatically pull",
722 to: "/settings/source-control",
723 scope: "project-defaults",
724 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
725 },
726 {
727 id: "remove-agent-credits-on-merge",
728 title: "Remove agent credits when merging",
729 to: "/settings/source-control",
730 scope: "project-defaults",
731 searchTerms: ["pull request github squash co-authored-by attribution claude codex generated"],
732 },
733 {
734 id: "pull-request-merge-method",
735 title: "Default merge method",
736 to: "/settings/source-control",
737 scope: "project-defaults",
738 searchTerms: ["pull request merge squash rebase last selected"],
739 },
740 {
741 id: "github-project-account",
742 title: "GitHub account",
743 to: "/settings/source-control",
744 scope: "project",
745 searchTerms: ["github gh account login user work personal multiple accounts project"],
746 },
747 {
748 id: "source-control",
749 title: "Source control",
750 to: "/settings/source-control",
751 scope: "environment-defaults",
752 searchTerms: [
753 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
754 ],
755 },
756 {
757 id: "git-fetch-interval",
758 title: "Git fetch interval",
759 to: "/settings/source-control",
760 searchTerms: [
761 "automatic remote branch refresh background credentials security keys seconds off",
762 ],
763 environmentOnly: true,
764 scope: "environment-defaults",
765 },
766 {
767 id: "worktree-branch-naming",
768 title: "Worktree branch naming",
769 to: "/settings/source-control",
770 searchTerms: ["static semantic prefix custom prompt instructions feat fix refactor chore"],
771 environmentOnly: true,
772 scope: "project-defaults",
773 },
774 {
775 id: "github-accounts",
776 title: "GitHub accounts and token",
777 to: "/settings/source-control",
778 searchTerms: [
779 "github gh account login user host enterprise ghes switch multiple accounts disable sign in token personal access token pat api key credential",
780 ],
781 environmentOnly: true,
782 scope: "environment-defaults",
783 },
784 {
785 id: "bitbucket-credentials",
786 title: "Bitbucket credentials",
787 to: "/settings/source-control",
788 searchTerms: ["bitbucket atlassian access token api token email credentials sign in"],
789 environmentOnly: true,
790 scope: "environment-defaults",
791 },
792 {
793 id: "source-control-writing-style",
794 title: "Source control writing style",
795 to: "/settings/source-control",
796 searchTerms: [
797 "repository conventions conventional commits custom instructions change descriptions request titles",
798 ],
799 environmentOnly: true,
800 },
801 {
802 id: "follow-change-request-templates",
803 title: "Follow change request templates",
804 to: "/settings/source-control",
805 searchTerms: ["repository pr pull request description structure"],
806 environmentOnly: true,
807 },
808 {
809 id: "source-control-writer-model",
810 title: "Source control writer model",
811 to: "/settings/source-control",
812 searchTerms: [
813 "override generated commit change request pr titles descriptions branch bookmark",
814 ],
815 environmentOnly: true,
816 scope: "project-defaults",
817 },
818 {
819 id: "project-actions",
820 title: "Actions",
821 to: "/settings/projects",
822 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
823 },
824 {
825 id: "environment-icon",
826 title: "Environment icon",
827 to: "/settings/connections",
828 targetId: "connections-environment",
829 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
830 },
831 {
832 id: "local-environment",
833 title: "Local environment",
834 to: "/settings/connections",
835 targetId: "connections-environment",
836 searchTerms: ["turn off on disable enable local server agents remote only restart"],
837 desktopOnly: true,
838 },
839 {
840 id: "network-access",
841 title: "Network access",
842 to: "/settings/connections",
843 targetId: "connections-environment",
844 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
845 localBackendManagementOnly: true,
846 },
847 {
848 id: "tailscale-https",
849 title: "Tailscale HTTPS",
850 to: "/settings/connections",
851 targetId: "connections-environment",
852 searchTerms: ["serve magicdns endpoint remote secure network"],
853 desktopOnly: true,
854 localBackendManagementOnly: true,
855 },
856 {
857 id: "wsl-backend",
858 title: "WSL backend",
859 to: "/settings/connections",
860 searchTerms: [
861 "windows subsystem linux distro second server projects stop windows backend restart",
862 ],
863 desktopOnly: true,
864 windowsOnly: true,
865 localBackendManagementOnly: true,
866 wslAvailableOnly: true,
867 },
868 {
869 id: "t3-connect",
870 localEnvironmentOnly: true,
871 title: "T3 Connect",
872 to: "/settings/connections",
873 targetId: "connections-environment",
874 searchTerms: ["managed tunnel cloud other devices remote"],
875 desktopOnly: true,
876 cloudOnly: true,
877 },
878 {
879 id: "hold-webhooks-while-offline",
880 localEnvironmentOnly: true,
881 title: "Hold webhooks while offline",
882 to: "/settings/connections",
883 targetId: "connections-environment",
884 searchTerms: ["webhook automations offline queue mailbox t3 connect"],
885 cloudOnly: true,
886 managedTunnelOnly: true,
887 },
888 {
889 id: "publish-agent-activity",
890 localEnvironmentOnly: true,
891 title: "Publish agent activity",
892 to: "/settings/connections",
893 targetId: "connections-environment",
894 searchTerms: ["mobile push notifications live activities cloud tunnel"],
895 cloudOnly: true,
896 },
897 {
898 id: "connections-environment",
899 title: "This machine",
900 to: "/settings/connections",
901 searchTerms: [
902 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
903 ],
904 },
905 {
906 id: "remote-environments",
907 title: "Environments",
908 to: "/settings/connections",
909 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
910 },
911 {
912 id: "load-balancing",
913 title: "Load balancing",
914 to: "/settings/connections",
915 searchTerms: [
916 "automatic machine environment resources cpu memory capacity preference weight shared projects",
917 ],
918 },
919 {
920 id: "github-routing",
921 title: "GitHub sharing",
922 to: "/settings/connections",
923 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
924 },
925 {
926 id: "archive",
927 title: "Archived threads",
928 to: "/settings/archived",
929 searchTerms: ["restore reopen deleted history projects"],
930 },
931] as const satisfies ReadonlyArray<SettingsSearchItem>;
932
933export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
934
935const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
936
937const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
938 "/settings/projects": "project",
939 "/settings/general": null,
940 "/settings/appearance": null,
941 "/settings/snap-shot": null,
942 // Keybindings fan out to the selection; Providers shows the representative
943 // environment at any selection. Neither needs a particular scope to render.
944 "/settings/keybindings": null,
945 "/settings/providers": null,
946 "/settings/integrations": null,
947 "/settings/source-control": "environment-defaults",
948 "/settings/storage": "project-defaults",
949 "/settings/connections": "connections",
950 "/settings/scheduled-tasks": null,
951 "/settings/archived": "project-defaults",
952};
953
954/** Search keeps the selected target. A missing row can explain its owning scope instead. */
955export function getSettingsSearchTargetScope(targetId: string) {
956 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
957 const item =
958 items.find((candidate) => candidate.id === targetId) ??
959 items.find((candidate) => candidate.targetId === targetId);
960 return item
961 ? {
962 title: item.title,
963 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
964 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
965 }
966 : null;
967}
968
969interface AutoSettlementSearchEnvironment {
970 readonly environmentId: EnvironmentId;
971 readonly connection: { readonly phase: EnvironmentConnectionPhase };
972 readonly serverConfig: {
973 readonly environment: {
974 readonly capabilities: { readonly threadAutoSettlement?: boolean };
975 };
976 } | null;
977}
978
979/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
980export function getThreadAutoSettlementSearchAvailability(
981 environments: readonly AutoSettlementSearchEnvironment[],
982 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
983) {
984 const connected = environments.filter(
985 (environment) =>
986 environment.connection.phase === "connected" && environment.serverConfig !== null,
987 );
988 const eligibleEnvironmentIds = connected
989 .filter(
990 (environment) =>
991 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
992 )
993 .map((environment) => environment.environmentId);
994 const selected = connected.filter((environment) =>
995 scope?.environmentIds.includes(environment.environmentId),
996 );
997 return {
998 eligibleEnvironmentIds,
999 isTargetAvailable:
1000 scope !== undefined &&
1001 scope.kind !== "unavailable" &&
1002 selected.length > 0 &&
1003 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
1004 };
1005}
1006
1007export function isSettingsSearchScopeAvailable(
1008 requiredScope: SettingsSearchScope | null,
1009 scopeKind: ResolvedSettingsScope["kind"],
1010): boolean {
1011 switch (requiredScope) {
1012 case null:
1013 case "connections":
1014 return true;
1015 case "environment":
1016 case "checkout":
1017 return requiredScope === scopeKind;
1018 case "project":
1019 return scopeKind === "project" || scopeKind === "checkout";
1020 case "environment-defaults":
1021 return scopeKind === "environment" || scopeKind === "all";
1022 case "project-defaults":
1023 return (
1024 scopeKind === "environment" ||
1025 scopeKind === "all" ||
1026 scopeKind === "project" ||
1027 scopeKind === "checkout"
1028 );
1029 }
1030}
1031
1032function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
1033 const target = validateSettingsScopeSearch({ ...search });
1034 if (target.checkout && !target.project) return "unavailable";
1035 if (target.project) return target.checkout ? "checkout" : "project";
1036 return target.machine ? "environment" : "all";
1037}
1038
1039export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
1040 const kind = settingsScopeKindFromSearch(search);
1041 return kind === "project" || kind === "checkout";
1042}
1043
1044/**
1045 * `id` and `title` props for the element a search item anchors to. Panels
1046 * spread (or pick from) this instead of restating the strings, so the catalog
1047 * and the rendered settings cannot drift apart.
1048 */
1049export function searchableSetting(id: SettingsSearchItemId): {
1050 readonly id: string;
1051 readonly title: string;
1052} {
1053 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
1054 return { id: anchorId, title };
1055}
1056
1057export function filterAvailableSettingsSearchItems(
1058 availability: SettingsSearchAvailability,
1059): ReadonlyArray<SettingsSearchItem> {
1060 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
1061 return items.filter(
1062 (item) =>
1063 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
1064 (!item.environmentOnly || availability.hasEnvironment) &&
1065 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
1066 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
1067 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
1068 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
1069 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
1070 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement) &&
1071 (!item.managedTunnelOnly || availability.managedTunnelActive === true),
1072 );
1073}
1074
1075export function searchSettings(
1076 query: string,
1077 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
1078): ReadonlyArray<SettingsSearchItem> {
1079 const normalizedQuery = normalizeSearchText(query);
1080 if (normalizedQuery.length === 0) return [];
1081 const queryTokens = normalizedQuery.split(" ");
1082 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
1083
1084 return items
1085 .flatMap((item, index) => {
1086 if (!isElectron && item.desktopOnly === true) return [];
1087 if (item.macOnly && !isMacPlatform(platform)) return [];
1088 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
1089
1090 const title = normalizeSearchText(item.title);
1091 const fields = [
1092 title,
1093 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1094 ...(item.searchTerms ?? []).map(normalizeSearchText),
1095 ];
1096 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1097
1098 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1099 const rank =
1100 title === normalizedQuery
1101 ? 5
1102 : title.startsWith(normalizedQuery)
1103 ? 4
1104 : title.includes(normalizedQuery)
1105 ? 3
1106 : queryTokens.every((token) => title.includes(token))
1107 ? 2
1108 : exactPhraseField >= 0
1109 ? 1
1110 : 0;
1111 return [{ item, index, rank }];
1112 })
1113 .toSorted(
1114 (left, right) =>
1115 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1116 right.rank - left.rank ||
1117 left.index - right.index,
1118 )
1119 .map(({ item }) => item);
1120}