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

settingsSearch.ts

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