Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settingsSearch.ts

1,101 lines34.9 KB

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