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

settingsSearch.ts

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