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

settingsSearch.ts

960 lines30.3 KB

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