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

settingsSearch.ts

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