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

settingsSearch.ts

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