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

settingsSearch.ts

508 lines15.9 KB

1import { isElectron } from "~/env";
2import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
3​
4export type SettingsPath =
5 | "/settings/general"
6 | "/settings/appearance"
7 | "/settings/keybindings"
8 | "/settings/providers"
9 | "/settings/integrations"
10 | "/settings/source-control"
11 | "/settings/connections"
12 | "/settings/archived";
13​
14export interface SettingsSearchItem {
15 readonly id: string;
16 readonly title: string;
17 readonly to: SettingsPath;
18 readonly targetId?: string;
19 /** Descriptions, option labels, and aliases people may remember instead of the title. */
20 readonly searchTerms?: ReadonlyArray<string>;
21 // Its row only renders in the desktop app, so a browser result would land on
22 // an anchor that isn't there.
23 readonly desktopOnly?: boolean;
24 readonly macOnly?: boolean;
25 // Its row only renders on Windows desktop, so other desktop platforms must
26 // not expose a result that points to a missing anchor.
27 readonly windowsOnly?: boolean;
28 readonly cloudOnly?: boolean;
29 readonly primaryOnly?: boolean;
30 readonly providerSettingsOnly?: boolean;
31 readonly localBackendManagementOnly?: boolean;
32 readonly wslAvailableOnly?: boolean;
34​
35export interface SettingsSearchAvailability {
36 readonly hasCloudPublicConfig: boolean;
37 readonly hasPrimaryEnvironment: boolean;
38 readonly hasProviderSettingsEnvironment: boolean;
39 readonly canManageLocalBackend: boolean;
40 readonly isWslSettingsRowVisible: boolean;
42​
43/**
44 * Section labels in sidebar order. The sidebar nav and the search-result
45 * subtitles both render from this record, so each label exists once.
46 */
47export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
48 "/settings/general": "General",
49 "/settings/appearance": "Appearance",
50 "/settings/keybindings": "Keybindings",
51 "/settings/providers": "Providers",
52 "/settings/integrations": "Integrations",
53 "/settings/source-control": "Source Control",
54 "/settings/connections": "Connections",
55 "/settings/archived": "Archive",
56};
57​
58/**
59 * Searchable settings and stable destinations, in result order. Rows with a
60 * dedicated anchor render their id and title via `searchableSetting`; items
61 * that may not be mounted point at their nearest stable section instead.
62 */
63export const SETTINGS_SEARCH_ITEMS = [
64 {
65 id: "color-scheme",
66 title: "Color scheme",
67 to: "/settings/appearance",
68 searchTerms: ["appearance light dark system mode"],
69 // The scheme tiles sit at the top of the Appearance section.
70 targetId: "appearance",
71 },
72 {
73 id: "theme",
74 title: "Themes",
75 to: "/settings/appearance",
76 searchTerms: ["appearance colors palette custom import"],
77 // Theme cards live directly under the scheme tiles; the section is the
78 // stable scroll destination for both.
79 targetId: "appearance",
80 },
81 {
82 // Prefixed because the slider control already owns the `appearance-contrast` id.
83 id: "setting-appearance-contrast",
84 title: "Contrast",
85 to: "/settings/appearance",
86 searchTerms: ["colors borders interface"],
87 },
88 {
89 // Prefixed because the slider control already owns the `glass-opacity` id.
90 id: "setting-glass-opacity",
91 title: "Glass opacity",
92 to: "/settings/appearance",
93 searchTerms: ["transparent transparency solid menus dialogs composer"],
94 },
95 {
96 id: "environment-identification",
97 title: "Environment identification",
98 to: "/settings/appearance",
99 searchTerms: ["dev nightly artwork pill label hide none"],
100 // The setting is stage-dependent, so its parent section is the stable destination.
101 targetId: "appearance",
102 },
103 {
104 id: "interface-font",
105 title: "Interface font",
106 to: "/settings/appearance",
107 searchTerms: ["typography family size system sans"],
108 },
109 {
110 id: "prompt-font",
111 title: "Prompt font",
112 to: "/settings/appearance",
113 searchTerms: ["typography family size composer input"],
114 },
115 {
116 id: "code-font",
117 title: "Code font",
118 to: "/settings/appearance",
119 searchTerms: ["typography family size monospace code blocks diffs file previews"],
120 },
121 {
122 id: "terminal-font",
123 title: "Terminal font",
124 to: "/settings/appearance",
125 searchTerms: ["typography family size monospace output"],
126 },
127 {
128 id: "font-smoothing",
129 title: "Font smoothing",
130 to: "/settings/appearance",
131 searchTerms: ["typography text grayscale anti aliasing macos thin"],
132 macOnly: true,
133 },
134 {
135 id: "word-wrap",
136 title: "Word wrap",
137 to: "/settings/appearance",
138 searchTerms: ["long lines code blocks tables diffs file previews"],
139 },
140 {
141 id: "project-grouping",
142 title: "Project grouping",
143 to: "/settings/general",
144 searchTerms: ["combine matching repositories environments sidebar"],
145 },
146 {
147 id: "auto-settle-inactive-threads",
148 title: "Auto-settle inactive threads",
149 to: "/settings/general",
150 searchTerms: ["sidebar inactivity days no activity automatically"],
151 },
152 {
153 id: "auto-settle-merged-threads",
154 title: "Auto-settle merged threads",
155 to: "/settings/general",
156 searchTerms: ["pull request merge closed automatically sidebar"],
157 },
158 {
159 id: "days-before-auto-settle",
160 title: "Days of inactivity before auto-settle",
161 to: "/settings/general",
162 targetId: "auto-settle-inactive-threads",
163 searchTerms: ["thread timeout activity sidebar"],
164 },
165 {
166 id: "time-format",
167 title: "Time format",
168 to: "/settings/general",
169 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
170 },
171 {
172 id: "hide-whitespace-changes",
173 title: "Hide whitespace changes",
174 to: "/settings/general",
175 searchTerms: ["diff ignore spaces edits default"],
176 },
177 {
178 id: "skills-in-slash-menu",
179 title: "Show skills in slash menu",
180 to: "/settings/general",
181 searchTerms: ["command menu dollar $ slash /"],
182 },
183 {
184 id: "provider-update-checks",
185 title: "Provider update checks",
186 to: "/settings/general",
187 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
188 },
189 {
190 id: "background-activity",
191 title: "Background activity",
192 to: "/settings/general",
193 searchTerms: [
194 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
195 ],
196 },
197 {
198 id: "new-threads",
199 title: "New threads",
200 to: "/settings/general",
201 searchTerms: ["default workspace mode draft local worktree"],
202 },
203 {
204 id: "start-from-origin",
205 title: "Start from origin",
206 to: "/settings/general",
207 targetId: "new-threads",
208 searchTerms: ["new worktrees latest matching remote branch local"],
209 },
210 {
211 id: "add-project-starts-in",
212 title: "Add project starts in",
213 to: "/settings/general",
214 searchTerms: ["base directory folder browser path home"],
215 },
216 {
217 id: "unpin-confirmation",
218 title: "Unpin confirmation",
219 to: "/settings/general",
220 searchTerms: ["ask before thread pinned section"],
221 },
222 {
223 id: "archive-confirmation",
224 title: "Archive confirmation",
225 to: "/settings/general",
226 searchTerms: ["ask before thread second click inline action"],
227 },
228 {
229 id: "delete-confirmation",
230 title: "Delete confirmation",
231 to: "/settings/general",
232 searchTerms: ["ask before thread chat history"],
233 },
234 {
235 id: "quit-confirmation",
236 title: "Hold to quit",
237 to: "/settings/general",
238 searchTerms: ["confirmation shortcut desktop app exit"],
239 desktopOnly: true,
240 },
241 {
242 id: "text-generation-model",
243 title: "Text generation model",
244 to: "/settings/general",
245 searchTerms: ["generated thread titles source control content default provider"],
246 },
247 {
248 id: "diagnostics",
249 title: "Diagnostics",
250 to: "/settings/general",
251 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
252 },
253 {
254 id: "legacy-plan-mode",
255 title: "Plan mode (legacy)",
256 to: "/settings/general",
257 searchTerms: ["build plan composer old"],
258 },
259 {
260 id: "legacy-token-streaming",
261 title: "Stream token by token (legacy)",
262 to: "/settings/general",
263 searchTerms: ["response output old compatibility"],
264 },
265 {
266 id: "legacy-sidebar",
267 title: "Sidebar (legacy)",
268 to: "/settings/general",
269 searchTerms: ["project thread tree old flat list"],
270 },
271 {
272 id: "keybindings",
273 title: "Keybindings",
274 to: "/settings/keybindings",
275 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
276 },
277 {
278 id: "providers",
279 title: "Providers",
280 to: "/settings/providers",
281 searchTerms: [
282 "agents cli codex claude cursor grok opencode instances authentication api key models configuration binary path config directory endpoint arguments environment variables display name accent color custom favorite hidden auto compact",
283 ],
284 },
285 {
286 id: "provider-health-check-interval",
287 title: "Health check interval",
288 to: "/settings/providers",
289 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
290 providerSettingsOnly: true,
291 },
292 {
293 id: "agent-browser-access",
294 title: "Agent browser access",
295 to: "/settings/integrations",
296 searchTerms: ["allow open drive preview tools sessions"],
297 },
298 {
299 id: "browser-default-viewport",
300 title: "Default browser viewport",
301 to: "/settings/integrations",
302 searchTerms: ["preview size width height device desktop mobile rotate"],
303 },
304 {
305 id: "browser-default-zoom",
306 title: "Default browser zoom",
307 to: "/settings/integrations",
308 searchTerms: ["preview page scale tabs percent"],
309 },
310 {
311 id: "browser-default-appearance",
312 title: "Default browser appearance",
313 to: "/settings/integrations",
314 searchTerms: ["preview color scheme light dark system os"],
315 },
316 {
317 id: "browser-recording-frame-rate",
318 title: "Browser recording frame rate",
319 to: "/settings/integrations",
320 },
321 {
322 id: "browser-auto-show-floating-preview",
323 title: "Auto-show floating preview",
324 to: "/settings/integrations",
325 searchTerms: ["agent opens browser pop into view hide"],
326 },
327 {
328 id: "source-control",
329 title: "Source control",
330 to: "/settings/source-control",
331 searchTerms: [
332 "version control git github gitlab bitbucket azure devops hosting integrations credentials scan server environment",
333 ],
334 },
335 {
336 id: "git-fetch-interval",
337 title: "Git fetch interval",
338 to: "/settings/source-control",
339 searchTerms: [
340 "automatic remote branch refresh background credentials security keys seconds off",
341 ],
342 primaryOnly: true,
343 },
344 {
345 id: "source-control-writing-style",
346 title: "Source control writing style",
347 to: "/settings/source-control",
348 searchTerms: [
349 "repository conventions conventional commits custom instructions change descriptions request titles",
350 ],
351 primaryOnly: true,
352 },
353 {
354 id: "follow-change-request-templates",
355 title: "Follow change request templates",
356 to: "/settings/source-control",
357 searchTerms: ["repository pr pull request description structure"],
358 primaryOnly: true,
359 },
360 {
361 id: "source-control-writer-model",
362 title: "Source control writer model",
363 to: "/settings/source-control",
364 searchTerms: [
365 "override generated commit change request pr titles descriptions branch bookmark",
366 ],
367 primaryOnly: true,
368 },
369 {
370 id: "network-access",
371 title: "Network access",
372 to: "/settings/connections",
373 targetId: "connections-environment",
374 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
375 localBackendManagementOnly: true,
376 },
377 {
378 id: "tailscale-https",
379 title: "Tailscale HTTPS",
380 to: "/settings/connections",
381 targetId: "connections-environment",
382 searchTerms: ["serve magicdns endpoint remote secure network"],
383 desktopOnly: true,
384 localBackendManagementOnly: true,
385 },
386 {
387 id: "wsl-backend",
388 title: "WSL backend",
389 to: "/settings/connections",
390 searchTerms: [
391 "windows subsystem linux distro second server projects stop windows backend restart",
392 ],
393 desktopOnly: true,
394 windowsOnly: true,
395 localBackendManagementOnly: true,
396 wslAvailableOnly: true,
397 },
398 {
399 id: "t3-connect",
400 title: "T3 Connect",
401 to: "/settings/connections",
402 targetId: "connections-environment",
403 searchTerms: ["managed tunnel cloud other devices remote"],
404 desktopOnly: true,
405 cloudOnly: true,
406 },
407 {
408 id: "publish-agent-activity",
409 title: "Publish agent activity",
410 to: "/settings/connections",
411 targetId: "connections-environment",
412 searchTerms: ["mobile push notifications live activities cloud tunnel"],
413 cloudOnly: true,
414 },
415 {
416 id: "connections-environment",
417 title: "This environment",
418 to: "/settings/connections",
419 searchTerms: [
420 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
421 ],
422 },
423 {
424 id: "remote-environments",
425 title: "Remote environments",
426 to: "/settings/connections",
427 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
428 },
429 {
430 id: "archive",
431 title: "Archived threads",
432 to: "/settings/archived",
433 searchTerms: ["restore reopen deleted history projects"],
434 },
435] as const satisfies ReadonlyArray<SettingsSearchItem>;
436​
437export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
438​
439const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
440​
441/**
442 * `id` and `title` props for the element a search item anchors to. Panels
443 * spread (or pick from) this instead of restating the strings, so the catalog
444 * and the rendered settings cannot drift apart.
445 */
446export function searchableSetting(id: SettingsSearchItemId): {
447 readonly id: string;
448 readonly title: string;
449} {
450 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
451 return { id: anchorId, title };
453​
454export function filterAvailableSettingsSearchItems(
455 availability: SettingsSearchAvailability,
456): ReadonlyArray<SettingsSearchItem> {
457 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
458 return items.filter(
459 (item) =>
460 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
461 (!item.primaryOnly || availability.hasPrimaryEnvironment) &&
462 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
463 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
464 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible),
465 );
467​
468export function searchSettings(
469 query: string,
470 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
471): ReadonlyArray<SettingsSearchItem> {
472 const normalizedQuery = normalizeSearchText(query);
473 if (normalizedQuery.length === 0) return [];
474 const queryTokens = normalizedQuery.split(" ");
475 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
476​
477 return items
478 .flatMap((item, index) => {
479 if (!isElectron && item.desktopOnly === true) return [];
480 if (item.macOnly && !isMacPlatform(platform)) return [];
481 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
482​
483 const title = normalizeSearchText(item.title);
484 const fields = [
485 title,
486 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
487 ...(item.searchTerms ?? []).map(normalizeSearchText),
488 ];
489 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
490​
491 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
492 const rank =
493 title === normalizedQuery
494 ? 5
495 : title.startsWith(normalizedQuery)
496 ? 4
497 : title.includes(normalizedQuery)
498 ? 3
499 : queryTokens.every((token) => title.includes(token))
500 ? 2
501 : exactPhraseField >= 0
502 ? 1
503 : 0;
504 return [{ item, index, rank }];
505 })
506 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
507 .map(({ item }) => item);