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

settingsSearch.ts

979 lines30.9 KB

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