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

settingsSearch.ts

1,148 lines36.4 KB

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