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

settingsSearch.ts

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