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

settingsSearch.ts

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