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

settingsSearch.ts

859 lines26.8 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: "legacy-plan-mode",
360 title: "Plan mode (legacy)",
361 to: "/settings/general",
362 searchTerms: ["build plan composer old"],
363 },
364 {
365 id: "legacy-context-window-indicator",
366 title: "Context window indicator (legacy)",
367 to: "/settings/general",
368 searchTerms: ["composer meter usage tokens circle old"],
369 },
370 {
371 id: "legacy-token-streaming",
372 title: "Stream token by token (legacy)",
373 to: "/settings/general",
374 scope: "project-defaults",
375 searchTerms: ["response output old compatibility"],
376 },
377 {
378 id: "legacy-sidebar",
379 title: "Sidebar (legacy)",
380 to: "/settings/general",
381 searchTerms: ["project thread tree old flat list"],
382 },
383 {
384 id: "keybindings",
385 title: "Keybindings",
386 to: "/settings/keybindings",
387 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
388 },
389 {
390 id: "snap-shot-enabled",
391 title: "SnapShots",
392 searchTerms: ["window capture screenshot"],
393 to: "/settings/snap-shot",
394 },
395 {
396 id: "snap-shot-accessibility",
397 title: "Include app text",
398 to: "/settings/snap-shot",
399 targetId: "snap-shot-enabled",
400 searchTerms: [
401 "capture accessibility data text UI structure elements privacy omit agent context",
402 ],
403 },
404 {
405 id: "snap-shot-shortcut",
406 title: "Capture shortcut",
407 to: "/settings/snap-shot",
408 targetId: "snap-shot-enabled",
409 },
410 {
411 id: "snap-shot-sound",
412 title: "Capture sound",
413 to: "/settings/snap-shot",
414 targetId: "snap-shot-enabled",
415 },
416 {
417 id: "snap-shot-flash",
418 title: "Capture flash",
419 to: "/settings/snap-shot",
420 targetId: "snap-shot-enabled",
421 },
422 {
423 id: "snap-shot-animations",
424 title: "Capture animations",
425 to: "/settings/snap-shot",
426 targetId: "snap-shot-enabled",
427 },
428 {
429 id: "providers",
430 title: "Providers",
431 to: "/settings/providers",
432 searchTerms: [
433 "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",
434 ],
435 },
436 {
437 id: "usage-providers",
438 title: "Usage providers",
439 to: "/settings/providers",
440 searchTerms: [
441 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
442 ],
443 providerSettingsOnly: true,
444 },
445 {
446 id: "provider-health-check-interval",
447 title: "Health check interval",
448 to: "/settings/providers",
449 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
450 providerSettingsOnly: true,
451 },
452 {
453 id: "agent-browser-access",
454 title: "Agent browser access",
455 to: "/settings/integrations",
456 scope: "project-defaults",
457 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
458 },
459 {
460 id: "device-hosts",
461 title: "Device hosts",
462 to: "/settings/integrations",
463 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
464 },
465 {
466 id: "agent-device-access",
467 title: "Agent device access",
468 to: "/settings/integrations",
469 targetId: "devices",
470 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
471 },
472 {
473 id: "device-hub",
474 title: "Device hub",
475 to: "/settings/integrations",
476 targetId: "devices",
477 searchTerms: ["simulator emulator ios android install start"],
478 },
479 {
480 id: "device-platform-support",
481 title: "Simulator support",
482 to: "/settings/integrations",
483 targetId: "devices",
484 searchTerms: ["xcode android studio sdk avd runtime"],
485 },
486 {
487 id: "browser-profiles",
488 title: "Browser profiles",
489 to: "/settings/integrations",
490 targetId: "browser",
491 },
492 {
493 id: "browser-default-profile",
494 title: "Default browser profile",
495 to: "/settings/integrations",
496 targetId: "browser-profiles",
497 },
498 {
499 id: "browser-default-viewport",
500 title: "Default browser viewport",
501 to: "/settings/integrations",
502 searchTerms: ["preview size width height device desktop mobile rotate"],
503 },
504 {
505 id: "browser-default-zoom",
506 title: "Default browser zoom",
507 to: "/settings/integrations",
508 searchTerms: ["preview page scale tabs percent"],
509 },
510 {
511 id: "browser-default-appearance",
512 title: "Default browser appearance",
513 to: "/settings/integrations",
514 searchTerms: ["preview color scheme light dark system os"],
515 },
516 {
517 id: "browser-recording-frame-rate",
518 title: "Browser recording frame rate",
519 to: "/settings/integrations",
520 },
521 {
522 id: "browser-link-target",
523 title: "Open links in",
524 to: "/settings/integrations",
525 searchTerms: ["links default browser in-app browser external open"],
526 },
527 {
528 id: "browser-auto-show-floating-preview",
529 title: "Auto-show floating preview",
530 to: "/settings/integrations",
531 searchTerms: ["agent opens browser device simulator pop into view hide"],
532 },
533 {
534 id: "automatic-pull",
535 title: "Automatically pull",
536 to: "/settings/source-control",
537 scope: "project-defaults",
538 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
539 },
540 {
541 id: "pull-request-merge-method",
542 title: "Default merge method",
543 to: "/settings/source-control",
544 scope: "project-defaults",
545 searchTerms: ["pull request merge squash rebase last selected"],
546 },
547 {
548 id: "source-control",
549 title: "Source control",
550 to: "/settings/source-control",
551 scope: "environment-defaults",
552 searchTerms: [
553 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
554 ],
555 },
556 {
557 id: "git-fetch-interval",
558 title: "Git fetch interval",
559 to: "/settings/source-control",
560 searchTerms: [
561 "automatic remote branch refresh background credentials security keys seconds off",
562 ],
563 environmentOnly: true,
564 scope: "environment-defaults",
565 },
566 {
567 id: "source-control-writing-style",
568 title: "Source control writing style",
569 to: "/settings/source-control",
570 searchTerms: [
571 "repository conventions conventional commits custom instructions change descriptions request titles",
572 ],
573 environmentOnly: true,
574 },
575 {
576 id: "follow-change-request-templates",
577 title: "Follow change request templates",
578 to: "/settings/source-control",
579 searchTerms: ["repository pr pull request description structure"],
580 environmentOnly: true,
581 },
582 {
583 id: "source-control-writer-model",
584 title: "Source control writer model",
585 to: "/settings/source-control",
586 searchTerms: [
587 "override generated commit change request pr titles descriptions branch bookmark",
588 ],
589 environmentOnly: true,
590 scope: "project-defaults",
591 },
592 {
593 id: "project-actions",
594 title: "Actions",
595 to: "/settings/projects",
596 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
597 },
598 {
599 id: "environment-icon",
600 title: "Environment icon",
601 to: "/settings/connections",
602 targetId: "connections-environment",
603 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
604 localBackendManagementOnly: true,
605 },
606 {
607 id: "network-access",
608 title: "Network access",
609 to: "/settings/connections",
610 targetId: "connections-environment",
611 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
612 localBackendManagementOnly: true,
613 },
614 {
615 id: "tailscale-https",
616 title: "Tailscale HTTPS",
617 to: "/settings/connections",
618 targetId: "connections-environment",
619 searchTerms: ["serve magicdns endpoint remote secure network"],
620 desktopOnly: true,
621 localBackendManagementOnly: true,
622 },
623 {
624 id: "wsl-backend",
625 title: "WSL backend",
626 to: "/settings/connections",
627 searchTerms: [
628 "windows subsystem linux distro second server projects stop windows backend restart",
629 ],
630 desktopOnly: true,
631 windowsOnly: true,
632 localBackendManagementOnly: true,
633 wslAvailableOnly: true,
634 },
635 {
636 id: "t3-connect",
637 title: "T3 Connect",
638 to: "/settings/connections",
639 targetId: "connections-environment",
640 searchTerms: ["managed tunnel cloud other devices remote"],
641 desktopOnly: true,
642 cloudOnly: true,
643 },
644 {
645 id: "publish-agent-activity",
646 title: "Publish agent activity",
647 to: "/settings/connections",
648 targetId: "connections-environment",
649 searchTerms: ["mobile push notifications live activities cloud tunnel"],
650 cloudOnly: true,
651 },
652 {
653 id: "connections-environment",
654 title: "This environment",
655 to: "/settings/connections",
656 searchTerms: [
657 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
658 ],
659 },
660 {
661 id: "remote-environments",
662 title: "Remote environments",
663 to: "/settings/connections",
664 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
665 },
666 {
667 id: "load-balancing",
668 title: "Load balancing",
669 to: "/settings/connections",
670 searchTerms: [
671 "automatic machine environment resources cpu memory capacity preference weight shared projects",
672 ],
673 },
674 {
675 id: "archive",
676 title: "Archived threads",
677 to: "/settings/archived",
678 searchTerms: ["restore reopen deleted history projects"],
679 },
680] as const satisfies ReadonlyArray<SettingsSearchItem>;
681​
682export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
683​
684const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
685​
686const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
687 "/settings/projects": "project",
688 "/settings/general": null,
689 "/settings/appearance": null,
690 "/settings/snap-shot": null,
691 // Keybindings fan out to the selection; Providers shows the representative
692 // environment at any selection. Neither needs a particular scope to render.
693 "/settings/keybindings": null,
694 "/settings/providers": null,
695 "/settings/integrations": null,
696 "/settings/source-control": "environment-defaults",
697 "/settings/connections": "connections",
698 "/settings/archived": "project-defaults",
699};
700​
701/** Search keeps the selected target. A missing row can explain its owning scope instead. */
702export function getSettingsSearchTargetScope(targetId: string) {
703 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
704 const item =
705 items.find((candidate) => candidate.id === targetId) ??
706 items.find((candidate) => candidate.targetId === targetId);
707 return item
708 ? {
709 title: item.title,
710 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
711 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
712 }
713 : null;
715​
716interface AutoSettlementSearchEnvironment {
717 readonly environmentId: EnvironmentId;
718 readonly connection: { readonly phase: EnvironmentConnectionPhase };
719 readonly serverConfig: {
720 readonly environment: {
721 readonly capabilities: { readonly threadAutoSettlement?: boolean };
722 };
723 } | null;
725​
726/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
727export function getThreadAutoSettlementSearchAvailability(
728 environments: readonly AutoSettlementSearchEnvironment[],
729 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
730) {
731 const connected = environments.filter(
732 (environment) =>
733 environment.connection.phase === "connected" && environment.serverConfig !== null,
734 );
735 const eligibleEnvironmentIds = connected
736 .filter(
737 (environment) =>
738 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
739 )
740 .map((environment) => environment.environmentId);
741 const selected = connected.filter((environment) =>
742 scope?.environmentIds.includes(environment.environmentId),
743 );
744 return {
745 eligibleEnvironmentIds,
746 isTargetAvailable:
747 scope !== undefined &&
748 scope.kind !== "unavailable" &&
749 selected.length > 0 &&
750 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
751 };
753​
754export function isSettingsSearchScopeAvailable(
755 requiredScope: SettingsSearchScope | null,
756 scopeKind: ResolvedSettingsScope["kind"],
757): boolean {
758 switch (requiredScope) {
759 case null:
760 case "connections":
761 return true;
762 case "environment":
763 case "checkout":
764 return requiredScope === scopeKind;
765 case "project":
766 return scopeKind === "project" || scopeKind === "checkout";
767 case "environment-defaults":
768 return scopeKind === "environment" || scopeKind === "all";
769 case "project-defaults":
770 return (
771 scopeKind === "environment" ||
772 scopeKind === "all" ||
773 scopeKind === "project" ||
774 scopeKind === "checkout"
775 );
776 }
778​
779function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
780 const target = validateSettingsScopeSearch({ ...search });
781 if (target.checkout && !target.project) return "unavailable";
782 if (target.project) return target.checkout ? "checkout" : "project";
783 return target.machine ? "environment" : "all";
785​
786export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
787 const kind = settingsScopeKindFromSearch(search);
788 return kind === "project" || kind === "checkout";
790​
791/**
792 * `id` and `title` props for the element a search item anchors to. Panels
793 * spread (or pick from) this instead of restating the strings, so the catalog
794 * and the rendered settings cannot drift apart.
795 */
796export function searchableSetting(id: SettingsSearchItemId): {
797 readonly id: string;
798 readonly title: string;
799} {
800 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
801 return { id: anchorId, title };
803​
804export function filterAvailableSettingsSearchItems(
805 availability: SettingsSearchAvailability,
806): ReadonlyArray<SettingsSearchItem> {
807 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
808 return items.filter(
809 (item) =>
810 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
811 (!item.environmentOnly || availability.hasEnvironment) &&
812 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
813 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
814 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
815 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
816 );
818​
819export function searchSettings(
820 query: string,
821 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
822): ReadonlyArray<SettingsSearchItem> {
823 const normalizedQuery = normalizeSearchText(query);
824 if (normalizedQuery.length === 0) return [];
825 const queryTokens = normalizedQuery.split(" ");
826 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
827​
828 return items
829 .flatMap((item, index) => {
830 if (!isElectron && item.desktopOnly === true) return [];
831 if (item.macOnly && !isMacPlatform(platform)) return [];
832 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
833​
834 const title = normalizeSearchText(item.title);
835 const fields = [
836 title,
837 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
838 ...(item.searchTerms ?? []).map(normalizeSearchText),
839 ];
840 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
841​
842 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
843 const rank =
844 title === normalizedQuery
845 ? 5
846 : title.startsWith(normalizedQuery)
847 ? 4
848 : title.includes(normalizedQuery)
849 ? 3
850 : queryTokens.every((token) => title.includes(token))
851 ? 2
852 : exactPhraseField >= 0
853 ? 1
854 : 0;
855 return [{ item, index, rank }];
856 })
857 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
858 .map(({ item }) => item);