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

settingsSearch.ts

913 lines28.5 KB

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