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: "source-control",
742 title: "Source control",
743 to: "/settings/source-control",
744 scope: "environment-defaults",
745 searchTerms: [
746 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
747 ],
748 },
749 {
750 id: "git-fetch-interval",
751 title: "Git fetch interval",
752 to: "/settings/source-control",
753 searchTerms: [
754 "automatic remote branch refresh background credentials security keys seconds off",
755 ],
756 environmentOnly: true,
757 scope: "environment-defaults",
758 },
759 {
760 id: "worktree-branch-naming",
761 title: "Worktree branch naming",
762 to: "/settings/source-control",
763 searchTerms: ["static semantic prefix custom prompt instructions feat fix refactor chore"],
764 environmentOnly: true,
765 scope: "project-defaults",
766 },
767 {
768 id: "github-accounts",
769 title: "GitHub accounts and token",
770 to: "/settings/source-control",
771 searchTerms: [
772 "github gh account login user host enterprise ghes switch multiple accounts disable sign in token personal access token pat api key credential",
773 ],
774 environmentOnly: true,
775 scope: "environment-defaults",
776 },
777 {
778 id: "bitbucket-credentials",
779 title: "Bitbucket credentials",
780 to: "/settings/source-control",
781 searchTerms: ["bitbucket atlassian access token api token email credentials sign in"],
782 environmentOnly: true,
783 scope: "environment-defaults",
784 },
785 {
786 id: "source-control-writing-style",
787 title: "Source control writing style",
788 to: "/settings/source-control",
789 searchTerms: [
790 "repository conventions conventional commits custom instructions change descriptions request titles",
791 ],
792 environmentOnly: true,
793 },
794 {
795 id: "follow-change-request-templates",
796 title: "Follow change request templates",
797 to: "/settings/source-control",
798 searchTerms: ["repository pr pull request description structure"],
799 environmentOnly: true,
800 },
801 {
802 id: "source-control-writer-model",
803 title: "Source control writer model",
804 to: "/settings/source-control",
805 searchTerms: [
806 "override generated commit change request pr titles descriptions branch bookmark",
807 ],
808 environmentOnly: true,
809 scope: "project-defaults",
810 },
811 {
812 id: "project-actions",
813 title: "Actions",
814 to: "/settings/projects",
815 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
816 },
817 {
818 id: "environment-icon",
819 title: "Environment icon",
820 to: "/settings/connections",
821 targetId: "connections-environment",
822 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
823 },
824 {
825 id: "local-environment",
826 title: "Local environment",
827 to: "/settings/connections",
828 targetId: "connections-environment",
829 searchTerms: ["turn off on disable enable local server agents remote only restart"],
830 desktopOnly: true,
831 },
832 {
833 id: "network-access",
834 title: "Network access",
835 to: "/settings/connections",
836 targetId: "connections-environment",
837 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
838 localBackendManagementOnly: true,
839 },
840 {
841 id: "tailscale-https",
842 title: "Tailscale HTTPS",
843 to: "/settings/connections",
844 targetId: "connections-environment",
845 searchTerms: ["serve magicdns endpoint remote secure network"],
846 desktopOnly: true,
847 localBackendManagementOnly: true,
848 },
849 {
850 id: "wsl-backend",
851 title: "WSL backend",
852 to: "/settings/connections",
853 searchTerms: [
854 "windows subsystem linux distro second server projects stop windows backend restart",
855 ],
856 desktopOnly: true,
857 windowsOnly: true,
858 localBackendManagementOnly: true,
859 wslAvailableOnly: true,
860 },
861 {
862 id: "t3-connect",
863 localEnvironmentOnly: true,
864 title: "T3 Connect",
865 to: "/settings/connections",
866 targetId: "connections-environment",
867 searchTerms: ["managed tunnel cloud other devices remote"],
868 desktopOnly: true,
869 cloudOnly: true,
870 },
871 {
872 id: "hold-webhooks-while-offline",
873 localEnvironmentOnly: true,
874 title: "Hold webhooks while offline",
875 to: "/settings/connections",
876 targetId: "connections-environment",
877 searchTerms: ["webhook automations offline queue mailbox t3 connect"],
878 cloudOnly: true,
879 managedTunnelOnly: true,
880 },
881 {
882 id: "publish-agent-activity",
883 localEnvironmentOnly: true,
884 title: "Publish agent activity",
885 to: "/settings/connections",
886 targetId: "connections-environment",
887 searchTerms: ["mobile push notifications live activities cloud tunnel"],
888 cloudOnly: true,
889 },
890 {
891 id: "connections-environment",
892 title: "This machine",
893 to: "/settings/connections",
894 searchTerms: [
895 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
896 ],
897 },
898 {
899 id: "remote-environments",
900 title: "Environments",
901 to: "/settings/connections",
902 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
903 },
904 {
905 id: "load-balancing",
906 title: "Load balancing",
907 to: "/settings/connections",
908 searchTerms: [
909 "automatic machine environment resources cpu memory capacity preference weight shared projects",
910 ],
911 },
912 {
913 id: "github-routing",
914 title: "GitHub sharing",
915 to: "/settings/connections",
916 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
917 },
918 {
919 id: "archive",
920 title: "Archived threads",
921 to: "/settings/archived",
922 searchTerms: ["restore reopen deleted history projects"],
923 },
924] as const satisfies ReadonlyArray<SettingsSearchItem>;
925
926export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
927
928const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
929
930const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
931 "/settings/projects": "project",
932 "/settings/general": null,
933 "/settings/appearance": null,
934 "/settings/snap-shot": null,
935 // Keybindings fan out to the selection; Providers shows the representative
936 // environment at any selection. Neither needs a particular scope to render.
937 "/settings/keybindings": null,
938 "/settings/providers": null,
939 "/settings/integrations": null,
940 "/settings/source-control": "environment-defaults",
941 "/settings/storage": "project-defaults",
942 "/settings/connections": "connections",
943 "/settings/scheduled-tasks": null,
944 "/settings/archived": "project-defaults",
945};
946
947/** Search keeps the selected target. A missing row can explain its owning scope instead. */
948export function getSettingsSearchTargetScope(targetId: string) {
949 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
950 const item =
951 items.find((candidate) => candidate.id === targetId) ??
952 items.find((candidate) => candidate.targetId === targetId);
953 return item
954 ? {
955 title: item.title,
956 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
957 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
958 }
959 : null;
960}
961
962interface AutoSettlementSearchEnvironment {
963 readonly environmentId: EnvironmentId;
964 readonly connection: { readonly phase: EnvironmentConnectionPhase };
965 readonly serverConfig: {
966 readonly environment: {
967 readonly capabilities: { readonly threadAutoSettlement?: boolean };
968 };
969 } | null;
970}
971
972/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
973export function getThreadAutoSettlementSearchAvailability(
974 environments: readonly AutoSettlementSearchEnvironment[],
975 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
976) {
977 const connected = environments.filter(
978 (environment) =>
979 environment.connection.phase === "connected" && environment.serverConfig !== null,
980 );
981 const eligibleEnvironmentIds = connected
982 .filter(
983 (environment) =>
984 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
985 )
986 .map((environment) => environment.environmentId);
987 const selected = connected.filter((environment) =>
988 scope?.environmentIds.includes(environment.environmentId),
989 );
990 return {
991 eligibleEnvironmentIds,
992 isTargetAvailable:
993 scope !== undefined &&
994 scope.kind !== "unavailable" &&
995 selected.length > 0 &&
996 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
997 };
998}
999
1000export function isSettingsSearchScopeAvailable(
1001 requiredScope: SettingsSearchScope | null,
1002 scopeKind: ResolvedSettingsScope["kind"],
1003): boolean {
1004 switch (requiredScope) {
1005 case null:
1006 case "connections":
1007 return true;
1008 case "environment":
1009 case "checkout":
1010 return requiredScope === scopeKind;
1011 case "project":
1012 return scopeKind === "project" || scopeKind === "checkout";
1013 case "environment-defaults":
1014 return scopeKind === "environment" || scopeKind === "all";
1015 case "project-defaults":
1016 return (
1017 scopeKind === "environment" ||
1018 scopeKind === "all" ||
1019 scopeKind === "project" ||
1020 scopeKind === "checkout"
1021 );
1022 }
1023}
1024
1025function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
1026 const target = validateSettingsScopeSearch({ ...search });
1027 if (target.checkout && !target.project) return "unavailable";
1028 if (target.project) return target.checkout ? "checkout" : "project";
1029 return target.machine ? "environment" : "all";
1030}
1031
1032export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
1033 const kind = settingsScopeKindFromSearch(search);
1034 return kind === "project" || kind === "checkout";
1035}
1036
1037/**
1038 * `id` and `title` props for the element a search item anchors to. Panels
1039 * spread (or pick from) this instead of restating the strings, so the catalog
1040 * and the rendered settings cannot drift apart.
1041 */
1042export function searchableSetting(id: SettingsSearchItemId): {
1043 readonly id: string;
1044 readonly title: string;
1045} {
1046 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
1047 return { id: anchorId, title };
1048}
1049
1050export function filterAvailableSettingsSearchItems(
1051 availability: SettingsSearchAvailability,
1052): ReadonlyArray<SettingsSearchItem> {
1053 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
1054 return items.filter(
1055 (item) =>
1056 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
1057 (!item.environmentOnly || availability.hasEnvironment) &&
1058 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
1059 (!item.macProviderSettingsOnly || availability.hasMacProviderSettingsEnvironment) &&
1060 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
1061 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
1062 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
1063 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement) &&
1064 (!item.managedTunnelOnly || availability.managedTunnelActive === true),
1065 );
1066}
1067
1068export function searchSettings(
1069 query: string,
1070 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
1071): ReadonlyArray<SettingsSearchItem> {
1072 const normalizedQuery = normalizeSearchText(query);
1073 if (normalizedQuery.length === 0) return [];
1074 const queryTokens = normalizedQuery.split(" ");
1075 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
1076
1077 return items
1078 .flatMap((item, index) => {
1079 if (!isElectron && item.desktopOnly === true) return [];
1080 if (item.macOnly && !isMacPlatform(platform)) return [];
1081 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
1082
1083 const title = normalizeSearchText(item.title);
1084 const fields = [
1085 title,
1086 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
1087 ...(item.searchTerms ?? []).map(normalizeSearchText),
1088 ];
1089 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
1090
1091 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
1092 const rank =
1093 title === normalizedQuery
1094 ? 5
1095 : title.startsWith(normalizedQuery)
1096 ? 4
1097 : title.includes(normalizedQuery)
1098 ? 3
1099 : queryTokens.every((token) => title.includes(token))
1100 ? 2
1101 : exactPhraseField >= 0
1102 ? 1
1103 : 0;
1104 return [{ item, index, rank }];
1105 })
1106 .toSorted(
1107 (left, right) =>
1108 Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
1109 right.rank - left.rank ||
1110 left.index - right.index,
1111 )
1112 .map(({ item }) => item);
1113}