Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Duration from "effect/Duration";
3import * as Schema from "effect/Schema";
4import * as SchemaTransformation from "effect/SchemaTransformation";
5import { ForwardCompatibleNullable, TrimmedNonEmptyString, TrimmedString } from "./baseSchemas.ts";
6import { EnvironmentMachineKind, ThreadEnvMode } from "./environment.ts";
7import {
8 DEFAULT_TEXT_GENERATION_MODEL,
9 DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
10 ProviderOptionSelections,
11} from "./model.ts";
12import { ModelSelection } from "./orchestration.ts";
13import { BrowserProfile, BrowserProfileId, DEFAULT_BROWSER_PROFILE_ID } from "./browserProfile.ts";
14import {
15 DEFAULT_PREVIEW_APPEARANCE,
16 DEFAULT_PREVIEW_ZOOM_FACTOR,
17 FILL_PREVIEW_VIEWPORT,
18 PreviewAppearancePreference,
19 PreviewViewportSetting,
20 PreviewZoomFactor,
21} from "./preview.ts";
22import {
23 ProviderInstanceConfig,
24 ProviderInstanceId,
25 type ProviderDriverKind,
26} from "./providerInstance.ts";
27
28// ── Client Settings (local-only) ───────────────────────────────
29
30export const TimestampFormat = Schema.Literals(["locale", "12-hour", "24-hour"]);
31export type TimestampFormat = typeof TimestampFormat.Type;
32export const DEFAULT_TIMESTAMP_FORMAT: TimestampFormat = "locale";
33
34export const DiffLayout = Schema.Literals(["stacked", "split"]);
35export type DiffLayout = typeof DiffLayout.Type;
36export const DEFAULT_DIFF_LAYOUT: DiffLayout = "stacked";
37
38export const SidebarProjectSortOrder = Schema.Literals(["updated_at", "created_at", "manual"]);
39export type SidebarProjectSortOrder = typeof SidebarProjectSortOrder.Type;
40export const DEFAULT_SIDEBAR_PROJECT_SORT_ORDER: SidebarProjectSortOrder = "updated_at";
41
42export const SidebarThreadSortOrder = Schema.Literals(["updated_at", "created_at"]);
43export type SidebarThreadSortOrder = typeof SidebarThreadSortOrder.Type;
44export const DEFAULT_SIDEBAR_THREAD_SORT_ORDER: SidebarThreadSortOrder = "updated_at";
45
46export const SidebarProjectGroupingMode = Schema.Literals([
47 "repository",
48 "repository_path",
49 "separate",
50]);
51export type SidebarProjectGroupingMode = typeof SidebarProjectGroupingMode.Type;
52export const DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE: SidebarProjectGroupingMode = "repository";
53export const MIN_SIDEBAR_THREAD_PREVIEW_COUNT = 1;
54export const MAX_SIDEBAR_THREAD_PREVIEW_COUNT = 15;
55export const SidebarThreadPreviewCount = Schema.Int.check(
56 Schema.isBetween({
57 minimum: MIN_SIDEBAR_THREAD_PREVIEW_COUNT,
58 maximum: MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
59 }),
60);
61export type SidebarThreadPreviewCount = typeof SidebarThreadPreviewCount.Type;
62export const DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT: SidebarThreadPreviewCount = 6;
63export const MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 1;
64export const MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 90;
65export const SidebarAutoSettleAfterDays = Schema.Number.check(
66 Schema.isBetween({
67 minimum: MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
68 maximum: MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
69 }),
70);
71export type SidebarAutoSettleAfterDays = typeof SidebarAutoSettleAfterDays.Type;
72export const DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS: SidebarAutoSettleAfterDays = 3;
73export const MIN_GLASS_OPACITY = 40;
74export const MAX_GLASS_OPACITY = 100;
75export const GlassOpacity = Schema.Int.check(
76 Schema.isBetween({
77 minimum: MIN_GLASS_OPACITY,
78 maximum: MAX_GLASS_OPACITY,
79 }),
80);
81export type GlassOpacity = typeof GlassOpacity.Type;
82export const DEFAULT_GLASS_OPACITY: GlassOpacity = 80;
83
84export const MIN_APPEARANCE_CONTRAST = 50;
85export const MAX_APPEARANCE_CONTRAST = 200;
86export const AppearanceContrast = Schema.Int.check(
87 Schema.isBetween({ minimum: MIN_APPEARANCE_CONTRAST, maximum: MAX_APPEARANCE_CONTRAST }),
88);
89export type AppearanceContrast = typeof AppearanceContrast.Type;
90export const DEFAULT_APPEARANCE_CONTRAST: AppearanceContrast = 100;
91export const MIN_PANEL_ANIMATION_DURATION_MS = 0;
92export const MAX_PANEL_ANIMATION_DURATION_MS = 400;
93export const PanelAnimationDurationMs = Schema.Int.check(
94 Schema.isBetween({
95 minimum: MIN_PANEL_ANIMATION_DURATION_MS,
96 maximum: MAX_PANEL_ANIMATION_DURATION_MS,
97 }),
98);
99export type PanelAnimationDurationMs = typeof PanelAnimationDurationMs.Type;
100export const DEFAULT_PANEL_ANIMATION_DURATION_MS: PanelAnimationDurationMs = 0;
101/**
102 * Font size preferences, in CSS pixels. The ranges are deliberately narrow:
103 * the interface size scales every rem-based dimension in the app, so the
104 * bounds keep layouts intact rather than offering unusable extremes.
105 */
106export const MIN_INTERFACE_FONT_SIZE = 12;
107export const MAX_INTERFACE_FONT_SIZE = 20;
108export const InterfaceFontSize = Schema.Int.check(
109 Schema.isBetween({ minimum: MIN_INTERFACE_FONT_SIZE, maximum: MAX_INTERFACE_FONT_SIZE }),
110);
111export type InterfaceFontSize = typeof InterfaceFontSize.Type;
112export const DEFAULT_INTERFACE_FONT_SIZE: InterfaceFontSize = 16;
113
114export const MIN_PROMPT_FONT_SIZE = 12;
115export const MAX_PROMPT_FONT_SIZE = 20;
116export const PromptFontSize = Schema.Int.check(
117 Schema.isBetween({ minimum: MIN_PROMPT_FONT_SIZE, maximum: MAX_PROMPT_FONT_SIZE }),
118);
119export type PromptFontSize = typeof PromptFontSize.Type;
120export const DEFAULT_PROMPT_FONT_SIZE: PromptFontSize = 14;
121
122export const MIN_CODE_FONT_SIZE = 10;
123export const MAX_CODE_FONT_SIZE = 18;
124export const CodeFontSize = Schema.Int.check(
125 Schema.isBetween({ minimum: MIN_CODE_FONT_SIZE, maximum: MAX_CODE_FONT_SIZE }),
126);
127export type CodeFontSize = typeof CodeFontSize.Type;
128export const DEFAULT_CODE_FONT_SIZE: CodeFontSize = 13;
129
130export const MIN_TERMINAL_FONT_SIZE = 8;
131export const MAX_TERMINAL_FONT_SIZE = 20;
132export const TerminalFontSize = Schema.Int.check(
133 Schema.isBetween({ minimum: MIN_TERMINAL_FONT_SIZE, maximum: MAX_TERMINAL_FONT_SIZE }),
134);
135export type TerminalFontSize = typeof TerminalFontSize.Type;
136export const DEFAULT_TERMINAL_FONT_SIZE: TerminalFontSize = 12;
137
138export const EnvironmentIdentificationMode = Schema.Literals(["artwork", "pill", "none"]);
139export type EnvironmentIdentificationMode = typeof EnvironmentIdentificationMode.Type;
140export const DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE: EnvironmentIdentificationMode = "artwork";
141
142export const QuitConfirmationMode = Schema.Literals(["direct", "hold", "double-click"]);
143export type QuitConfirmationMode = typeof QuitConfirmationMode.Type;
144export const DEFAULT_QUIT_CONFIRMATION_MODE: QuitConfirmationMode = "hold";
145
146const LegacyConfirmQuit = Schema.Boolean.pipe(
147 Schema.decodeTo(
148 QuitConfirmationMode,
149 SchemaTransformation.transform({
150 decode: (confirmQuit): QuitConfirmationMode => (confirmQuit ? "hold" : "direct"),
151 encode: (mode) => mode === "hold",
152 }),
153 ),
154);
155
156const QuitConfirmationModeSetting = Schema.Union([QuitConfirmationMode, LegacyConfirmQuit]);
157
158/**
159 * A user-chosen font family (a single name or a comma-separated list). Empty
160 * means "use the app default"; clients compose their own fallback stacks.
161 */
162export const FontFamilyPreference = Schema.String.check(Schema.isMaxLength(200));
163export type FontFamilyPreference = typeof FontFamilyPreference.Type;
164
165/**
166 * The environment's theme, set with `t3 theme set <id>`. Each client applies
167 * it once per value — live when connected, on its next connect otherwise — so
168 * setting it switches every client, while a theme a user picks in Settings
169 * afterwards sticks until the next set. Empty means "no environment theme",
170 * which is also how it is cleared.
171 */
172export const DefaultThemePreference = Schema.String.check(Schema.isMaxLength(64));
173// Deliberately absent from ServerSettingsPatch: `t3 theme set` checks that an
174// id is syntactically valid and actually resolvable, and a generic RPC patch
175// would let a client write a theme no client can resolve, bypassing both.
176export type DefaultThemePreference = typeof DefaultThemePreference.Type;
177
178/**
179 * Defaults for the in-app preview browser, applied whenever a tab is opened
180 * without an explicit viewport/zoom/appearance — by the user opening a browser
181 * tab, or by an agent calling `preview_open` with no size. Recording quality is
182 * client-local for the same reason: the Chromium guest being captured belongs
183 * to the desktop app.
184 */
185export const DEFAULT_BROWSER_VIEWPORT: PreviewViewportSetting = FILL_PREVIEW_VIEWPORT;
186export const DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW = true;
187export const BROWSER_RECORDING_FRAME_RATES = [30, 60] as const;
188export const BrowserRecordingFrameRate = Schema.Literals(BROWSER_RECORDING_FRAME_RATES);
189export type BrowserRecordingFrameRate = typeof BrowserRecordingFrameRate.Type;
190export const DEFAULT_BROWSER_RECORDING_FRAME_RATE: BrowserRecordingFrameRate = 30;
191/**
192 * Where a clicked link goes: the OS default browser, or a tab in the in-app
193 * browser beside the thread. "system" is the default because that is what
194 * every link did before the setting existed.
195 */
196export const BrowserLinkTarget = Schema.Literals(["system", "app"]);
197export type BrowserLinkTarget = typeof BrowserLinkTarget.Type;
198export const DEFAULT_BROWSER_LINK_TARGET: BrowserLinkTarget = "system";
199
200export const ClientSettingsSchema = Schema.Struct({
201 appearanceContrast: AppearanceContrast.pipe(
202 Schema.withDecodingDefault(Effect.succeed(DEFAULT_APPEARANCE_CONTRAST)),
203 ),
204 // Panel motion defaults to zero because width and height transitions cause
205 // layout work on every frame, which is noticeable on lower-power clients.
206 panelAnimationDurationMs: PanelAnimationDurationMs.pipe(
207 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PANEL_ANIMATION_DURATION_MS)),
208 ),
209 browserDefaultViewport: PreviewViewportSetting.pipe(
210 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_VIEWPORT)),
211 ),
212 browserDefaultZoomFactor: PreviewZoomFactor.pipe(
213 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PREVIEW_ZOOM_FACTOR)),
214 ),
215 browserDefaultAppearance: PreviewAppearancePreference.pipe(
216 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PREVIEW_APPEARANCE)),
217 ),
218 browserRecordingFrameRate: BrowserRecordingFrameRate.pipe(
219 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_RECORDING_FRAME_RATE)),
220 ),
221 /**
222 * Where links clicked in a thread (chat markdown, terminal output) open.
223 * Only the desktop app has an in-app browser, so other clients ignore "app".
224 */
225 browserLinkTarget: BrowserLinkTarget.pipe(
226 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_LINK_TARGET)),
227 ),
228 /**
229 * Whether an agent opening a preview pops the floating mini player into
230 * view. Only applies when the agent didn't ask either way — an explicit
231 * `open`/`show` on `preview_open` still wins, since that is the agent
232 * deliberately showing or hiding its work.
233 */
234 browserAutoShowFloatingPreview: Schema.Boolean.pipe(
235 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW)),
236 ),
237 /**
238 * User-created browser profiles. The built-in Default and Incognito profiles
239 * are synthesized by `resolveBrowserProfiles`, not stored here, so they
240 * cannot be renamed away or deleted.
241 */
242 browserProfiles: Schema.Array(BrowserProfile).pipe(
243 Schema.withDecodingDefault(Effect.succeed([])),
244 ),
245 /** Profile new tabs open under. Falls back to Default if it no longer exists. */
246 browserDefaultProfileId: BrowserProfileId.pipe(
247 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_PROFILE_ID)),
248 ),
249 // Desktop-only. Boolean values from older settings files decode to their
250 // equivalent mode and encode back as the canonical string value.
251 confirmQuit: QuitConfirmationModeSetting.pipe(
252 Schema.withDecodingDefault(Effect.succeed(DEFAULT_QUIT_CONFIRMATION_MODE)),
253 ),
254 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
255 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
256 confirmThreadUnpin: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
257 continueThreadsAfterServerUpdate: Schema.Boolean.pipe(
258 Schema.withDecodingDefault(Effect.succeed(false)),
259 ),
260 dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
261 Schema.withDecodingDefault(Effect.succeed([])),
262 ),
263 diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
264 diffLayout: DiffLayout.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_DIFF_LAYOUT))),
265 environmentIdentificationMode: EnvironmentIdentificationMode.pipe(
266 Schema.withDecodingDefault(Effect.succeed(DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE)),
267 ),
268 glassOpacity: GlassOpacity.pipe(
269 Schema.withDecodingDefault(Effect.succeed(DEFAULT_GLASS_OPACITY)),
270 ),
271 fontSizeInterface: InterfaceFontSize.pipe(
272 Schema.withDecodingDefault(Effect.succeed(DEFAULT_INTERFACE_FONT_SIZE)),
273 ),
274 fontSizePrompt: PromptFontSize.pipe(
275 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROMPT_FONT_SIZE)),
276 ),
277 fontSizeCode: CodeFontSize.pipe(
278 Schema.withDecodingDefault(Effect.succeed(DEFAULT_CODE_FONT_SIZE)),
279 ),
280 fontSizeTerminal: TerminalFontSize.pipe(
281 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TERMINAL_FONT_SIZE)),
282 ),
283 fontFamilyCode: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
284 fontFamilyComposer: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
285 fontFamilySans: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
286 fontFamilyTerminal: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
287 // Grayscale `-webkit-font-smoothing: antialiased` (thinner strokes);
288 // disabling restores the platform's heavier default. No effect off macOS.
289 fontSmoothing: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
290 // Model favorites. Historically keyed by provider kind, now
291 // widened to `ProviderInstanceId` so users can favorite a specific model
292 // on a custom provider instance (e.g. "Codex Personal · gpt-5") without
293 // the UI collapsing it into the same bucket as the default Codex. The
294 // widening is backward-compatible by construction: prior provider-kind
295 // strings satisfy the `ProviderInstanceId` slug schema, so previously
296 // persisted favorites decode unchanged and continue to point at the
297 // default instance for their kind (because `defaultInstanceIdForDriver(kind)`
298 // uses the same slug). The field name is kept as `provider` for storage
299 // stability; new call sites should treat the value as an instance id.
300 favorites: Schema.Array(
301 Schema.Struct({
302 provider: ProviderInstanceId,
303 model: TrimmedNonEmptyString,
304 }),
305 ).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
306 providerModelPreferences: Schema.Record(
307 ProviderInstanceId,
308 Schema.Struct({
309 hiddenModels: Schema.Array(Schema.String).pipe(
310 Schema.withDecodingDefault(Effect.succeed([])),
311 ),
312 modelOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
313 }),
314 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
315 // Legacy plan mode. The composer's Build/Plan toggle was removed from the
316 // default UI; this beta flag restores it (plus the /plan and /default slash
317 // commands) for users who still rely on the old workflow.
318 planModeEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
319 // Legacy context window meter. The composer hides it by default; users who
320 // still want the old usage indicator can restore it from Settings.
321 contextWindowMeterEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
322 proactivePanelsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
323 showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
324 // Legacy sidebar (the original per-project tree). Deliberately a fresh key
325 // (was `sidebarV2Enabled` + `sidebarV2ConfiguredByUser`): decoding drops the
326 // old keys, so everyone, including prior beta opt-outs, resets to the new
327 // default sidebar.
328 legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
329 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
330 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
331 ),
332 sidebarProjectGroupingOverrides: Schema.Record(
333 TrimmedNonEmptyString,
334 SidebarProjectGroupingMode,
335 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
336 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
337 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
338 ),
339 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
340 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
341 ),
342 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
343 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
344 ),
345 timestampFormat: TimestampFormat.pipe(
346 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
347 ),
348 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
349});
350export type ClientSettings = typeof ClientSettingsSchema.Type;
351
352export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
353
354// ── Server Settings (server-authoritative) ────────────────────
355
356const makeBinaryPathSetting = (fallback: string) =>
357 TrimmedString.pipe(
358 Schema.decodeTo(
359 Schema.String,
360 SchemaTransformation.transformOrFail({
361 decode: (value) => Effect.succeed(value || fallback),
362 encode: (value) => Effect.succeed(value),
363 }),
364 ),
365 Schema.withDecodingDefault(Effect.succeed(fallback)),
366 );
367
368export type ProviderSettingsFormControl = "text" | "password" | "textarea" | "switch";
369
370export interface ProviderSettingsFormAnnotation {
371 readonly control?: ProviderSettingsFormControl | undefined;
372 readonly placeholder?: string | undefined;
373 readonly hidden?: boolean | undefined;
374 readonly clearWhenEmpty?: "omit" | "persist" | undefined;
375}
376
377export interface ProviderSettingsFormSchemaAnnotation {
378 readonly order?: readonly string[] | undefined;
379}
380
381declare module "effect/Schema" {
382 namespace Annotations {
383 interface Annotations {
384 readonly providerSettingsForm?: ProviderSettingsFormAnnotation | undefined;
385 readonly providerSettingsFormSchema?: ProviderSettingsFormSchemaAnnotation | undefined;
386 }
387 }
388}
389
390export type ProviderSettingsOrder<Fields extends Schema.Struct.Fields> = readonly Extract<
391 keyof Fields,
392 string
393>[];
394
395export function makeProviderSettingsSchema<const Fields extends Schema.Struct.Fields>(
396 fields: Fields,
397 options?: {
398 readonly order?: ProviderSettingsOrder<Fields> | undefined;
399 },
400): Schema.Struct<Fields> {
401 return Schema.Struct(fields).pipe(
402 Schema.annotate({
403 providerSettingsFormSchema:
404 options?.order === undefined ? undefined : { order: options.order },
405 }),
406 );
407}
408
409export const CodexSettings = makeProviderSettingsSchema(
410 {
411 enabled: Schema.Boolean.pipe(
412 Schema.withDecodingDefault(Effect.succeed(true)),
413 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
414 ),
415 binaryPath: makeBinaryPathSetting("codex").pipe(
416 Schema.annotateKey({
417 title: "Binary path",
418 description: "Path to the Codex binary used by this instance.",
419 providerSettingsForm: { placeholder: "codex", clearWhenEmpty: "omit" },
420 }),
421 ),
422 homePath: TrimmedString.pipe(
423 Schema.withDecodingDefault(Effect.succeed("")),
424 Schema.annotateKey({
425 title: "CODEX_HOME path",
426 description: "Custom Codex home and config directory.",
427 providerSettingsForm: {
428 placeholder: "~/.codex",
429 clearWhenEmpty: "omit",
430 },
431 }),
432 ),
433 shadowHomePath: TrimmedString.pipe(
434 Schema.withDecodingDefault(Effect.succeed("")),
435 Schema.annotateKey({
436 title: "Shadow home path",
437 description:
438 "Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
439 providerSettingsForm: {
440 placeholder: "~/.codex-t3/personal",
441 clearWhenEmpty: "omit",
442 },
443 }),
444 ),
445 launchArgs: TrimmedString.pipe(
446 Schema.withDecodingDefault(Effect.succeed("")),
447 Schema.annotateKey({
448 title: "Launch arguments",
449 description: "Additional CLI arguments passed to codex app-server on session start.",
450 }),
451 ),
452 customModels: Schema.Array(Schema.String).pipe(
453 Schema.withDecodingDefault(Effect.succeed([])),
454 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
455 ),
456 },
457 {
458 order: ["binaryPath", "homePath", "shadowHomePath", "launchArgs"],
459 },
460);
461export type CodexSettings = typeof CodexSettings.Type;
462
463// Empty, or an integer from 100,000 to 1,000,000. Shared by the full
464// Claude settings schema and its patch so an out-of-range value fails at
465// the update that introduced it.
466const CLAUDE_AUTO_COMPACT_WINDOW_PATTERN = /^(?:|[1-9]\d{5}|1000000)$/;
467
468export const ClaudeSettings = makeProviderSettingsSchema(
469 {
470 enabled: Schema.Boolean.pipe(
471 Schema.withDecodingDefault(Effect.succeed(true)),
472 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
473 ),
474 binaryPath: makeBinaryPathSetting("claude").pipe(
475 Schema.annotateKey({
476 title: "Binary path",
477 description: "Path to the Claude binary used by this instance.",
478 providerSettingsForm: { placeholder: "claude", clearWhenEmpty: "omit" },
479 }),
480 ),
481 homePath: TrimmedString.pipe(
482 Schema.withDecodingDefault(Effect.succeed("")),
483 Schema.annotateKey({
484 title: "CLAUDE_CONFIG_DIR path",
485 description:
486 "Custom Claude home and config directory. Keeps .claude.json and .claude separate.",
487 providerSettingsForm: { placeholder: "~/.claude", clearWhenEmpty: "omit" },
488 }),
489 ),
490 customModels: Schema.Array(Schema.String).pipe(
491 Schema.withDecodingDefault(Effect.succeed([])),
492 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
493 ),
494 launchArgs: Schema.String.pipe(
495 Schema.withDecodingDefault(Effect.succeed("")),
496 Schema.annotateKey({
497 title: "Launch arguments",
498 description: "Additional CLI arguments passed on session start.",
499 providerSettingsForm: {
500 placeholder: "e.g. --chrome",
501 clearWhenEmpty: "omit",
502 },
503 }),
504 ),
505 autoCompactWindow: TrimmedString.check(
506 Schema.isPattern(CLAUDE_AUTO_COMPACT_WINDOW_PATTERN),
507 ).pipe(
508 Schema.withDecodingDefault(Effect.succeed("")),
509 Schema.annotateKey({
510 title: "Auto-compact after",
511 description:
512 "Compact after 100,000 to 1,000,000 tokens. Leave empty to use Claude's default.",
513 providerSettingsForm: {
514 placeholder: "e.g. 300000",
515 clearWhenEmpty: "omit",
516 },
517 }),
518 ),
519 },
520 {
521 order: ["binaryPath", "homePath", "autoCompactWindow", "launchArgs"],
522 },
523);
524export type ClaudeSettings = typeof ClaudeSettings.Type;
525
526export const CursorSettings = makeProviderSettingsSchema(
527 {
528 // Off by default like Grok and OpenCode. Users opt in from Settings.
529 enabled: Schema.Boolean.pipe(
530 Schema.withDecodingDefault(Effect.succeed(false)),
531 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
532 ),
533 binaryPath: makeBinaryPathSetting("cursor-agent").pipe(
534 Schema.annotateKey({
535 title: "Binary path",
536 description: "Path to the Cursor agent binary.",
537 providerSettingsForm: { placeholder: "cursor-agent", clearWhenEmpty: "omit" },
538 }),
539 ),
540 apiEndpoint: TrimmedString.pipe(
541 Schema.withDecodingDefault(Effect.succeed("")),
542 Schema.annotateKey({
543 title: "API endpoint",
544 description: "Override the Cursor API endpoint for this instance.",
545 providerSettingsForm: {
546 placeholder: "https://...",
547 clearWhenEmpty: "omit",
548 },
549 }),
550 ),
551 customModels: Schema.Array(Schema.String).pipe(
552 Schema.withDecodingDefault(Effect.succeed([])),
553 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
554 ),
555 },
556 {
557 order: ["binaryPath", "apiEndpoint"],
558 },
559);
560export type CursorSettings = typeof CursorSettings.Type;
561
562export const GrokSettings = makeProviderSettingsSchema(
563 {
564 // Off by default (like Cursor and OpenCode): the binding is not yet
565 // stable enough to probe on every install. Users opt in from Settings.
566 enabled: Schema.Boolean.pipe(
567 Schema.withDecodingDefault(Effect.succeed(false)),
568 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
569 ),
570 binaryPath: makeBinaryPathSetting("grok").pipe(
571 Schema.annotateKey({
572 title: "Binary path",
573 description: "Path to the Grok CLI binary.",
574 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
575 }),
576 ),
577 customModels: Schema.Array(Schema.String).pipe(
578 Schema.withDecodingDefault(Effect.succeed([])),
579 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
580 ),
581 },
582 {
583 order: ["binaryPath"],
584 },
585);
586export type GrokSettings = typeof GrokSettings.Type;
587
588export const OpenCodeSettings = makeProviderSettingsSchema(
589 {
590 // Off by default (like Cursor and Grok): the binding is not yet stable
591 // enough to probe on every install. Users opt in from Settings.
592 enabled: Schema.Boolean.pipe(
593 Schema.withDecodingDefault(Effect.succeed(false)),
594 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
595 ),
596 binaryPath: makeBinaryPathSetting("opencode").pipe(
597 Schema.annotateKey({
598 title: "Binary path",
599 description: "Path to the OpenCode binary.",
600 providerSettingsForm: {
601 placeholder: "opencode",
602 clearWhenEmpty: "omit",
603 },
604 }),
605 ),
606 serverUrl: TrimmedString.pipe(
607 Schema.withDecodingDefault(Effect.succeed("")),
608 Schema.annotateKey({
609 title: "Server URL",
610 description: "Leave blank to let T3 Code spawn the server when needed.",
611 providerSettingsForm: {
612 placeholder: "http://127.0.0.1:4096",
613 clearWhenEmpty: "omit",
614 },
615 }),
616 ),
617 serverPassword: TrimmedString.pipe(
618 Schema.withDecodingDefault(Effect.succeed("")),
619 Schema.annotateKey({
620 title: "Server password",
621 description: "Stored in plain text on disk.",
622 providerSettingsForm: {
623 control: "password",
624 placeholder: "Optional",
625 clearWhenEmpty: "omit",
626 },
627 }),
628 ),
629 customModels: Schema.Array(Schema.String).pipe(
630 Schema.withDecodingDefault(Effect.succeed([])),
631 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
632 ),
633 },
634 {
635 order: ["binaryPath", "serverUrl", "serverPassword"],
636 },
637);
638export type OpenCodeSettings = typeof OpenCodeSettings.Type;
639
640export const ObservabilitySettings = Schema.Struct({
641 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
642 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
643});
644export type ObservabilitySettings = typeof ObservabilitySettings.Type;
645
646export const SourceControlWritingStyleMode = Schema.Literals([
647 "repo_conventions",
648 "conventional_commits",
649 "custom",
650]);
651export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
652
653export const SourceControlWritingStyleSettings = Schema.Struct({
654 mode: SourceControlWritingStyleMode.pipe(
655 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
656 ),
657 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
658 followChangeRequestTemplates: Schema.Boolean.pipe(
659 Schema.withDecodingDefault(Effect.succeed(true)),
660 ),
661});
662export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
663
664export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
665export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
666
667export const BackgroundActivityProfile = Schema.Literals([
668 "balanced",
669 "performance",
670 "battery-saver",
671]);
672export type BackgroundActivityProfile = typeof BackgroundActivityProfile.Type;
673export const DEFAULT_BACKGROUND_ACTIVITY_PROFILE: BackgroundActivityProfile = "balanced";
674
675export const BackgroundActivityProfileSelection = Schema.Literals([
676 "balanced",
677 "performance",
678 "battery-saver",
679 "custom",
680]);
681export type BackgroundActivityProfileSelection = typeof BackgroundActivityProfileSelection.Type;
682
683export const BackgroundActivityOverrides = Schema.Struct({
684 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
685 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
686 hostPowerMonitorActiveInterval: Schema.optionalKey(Schema.DurationFromMillis),
687 hostPowerMonitorIdleInterval: Schema.optionalKey(Schema.DurationFromMillis),
688 idleClientTtl: Schema.optionalKey(Schema.DurationFromMillis),
689 pauseWhenHostLocked: Schema.optionalKey(Schema.Boolean),
690 pauseWhenHostLowPower: Schema.optionalKey(Schema.Boolean),
691 pauseWhenClientLowPower: Schema.optionalKey(Schema.Boolean),
692 pauseWhenOnBattery: Schema.optionalKey(Schema.Boolean),
693});
694export type BackgroundActivityOverrides = typeof BackgroundActivityOverrides.Type;
695
696export const BackgroundActivitySettings = Schema.Struct({
697 schemaVersion: Schema.Literal(1).pipe(Schema.withDecodingDefault(Effect.succeed(1 as const))),
698 profile: BackgroundActivityProfileSelection.pipe(
699 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
700 ),
701 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
702 overrides: BackgroundActivityOverrides.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
703}).pipe(Schema.withDecodingDefault(Effect.succeed({})));
704export type BackgroundActivitySettings = typeof BackgroundActivitySettings.Type;
705
706export const ServerSettings = Schema.Struct({
707 // Legacy token-by-token assistant output. Deliberately a fresh key (was
708 // `enableAssistantStreaming`): decoding drops the old key, so everyone,
709 // including prior opt-ins, resets to the buffered default.
710 enableLegacyTokenStreaming: Schema.Boolean.pipe(
711 Schema.withDecodingDefault(Effect.succeed(false)),
712 ),
713 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
714 /**
715 * Whether agents may drive the in-app preview browser. Turning this off
716 * withholds the MCP credential, so the `t3-code` server (and with it every
717 * `preview_*` tool) is never attached to a provider session, and the prompt
718 * text describing those tools is dropped along with them. The user's own
719 * browser panel is unaffected — this gates agent access only.
720 *
721 * Server-authoritative rather than client-local: tool injection and prompt
722 * construction both happen on the server, and the answer must not differ
723 * between a desktop window and a phone attached to the same server.
724 */
725 enableAgentBrowserAccess: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
726 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
727 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
728 ),
729 sidebarAutoSettleOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
730 backgroundActivity: BackgroundActivitySettings,
731 // Legacy flat fields retained for old settings files and old clients. New
732 // consumers should resolve `backgroundActivity` instead.
733 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
734 Schema.withDecodingDefault(
735 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
736 ),
737 ),
738 providerHealthRefreshInterval: Schema.DurationFromMillis.pipe(
739 Schema.withDecodingDefault(
740 Effect.succeed(Duration.toMillis(DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL)),
741 ),
742 ),
743 backgroundActivityProfile: BackgroundActivityProfile.pipe(
744 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
745 ),
746 defaultTheme: DefaultThemePreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
747 /**
748 * When the environment's theme was last set, so clients can tell a re-set
749 * of the same value from one they already applied: `t3 theme set` must act
750 * even when it names the theme it named before. Empty on environments
751 * provisioned by builds that predate it, where clients fall back to
752 * applying once per value.
753 */
754 defaultThemeSetAt: Schema.String.check(Schema.isMaxLength(64)).pipe(
755 Schema.withDecodingDefault(Effect.succeed("")),
756 ),
757 /**
758 * The icon clients draw for this environment. Null means "use what the
759 * server detected" (`environment.platform.machine`), falling back to a
760 * generic server. Lives on the server, not the client, so every device
761 * sees the same machine. A kind picked on a newer server decodes as null
762 * here rather than failing the whole settings snapshot for an older client.
763 */
764 environmentIcon: ForwardCompatibleNullable(EnvironmentMachineKind).pipe(
765 Schema.withDecodingDefault(Effect.succeed(null)),
766 ),
767 defaultThreadEnvMode: ThreadEnvMode.pipe(
768 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
769 ),
770 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
771 Schema.withDecodingDefault(Effect.succeed(true)),
772 ),
773 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
774 textGenerationModelSelection: ModelSelection.pipe(
775 Schema.withDecodingDefault(
776 Effect.succeed({
777 instanceId: ProviderInstanceId.make("codex"),
778 model: DEFAULT_TEXT_GENERATION_MODEL,
779 options: [
780 {
781 id: "reasoningEffort",
782 value: DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
783 },
784 ],
785 }),
786 ),
787 ),
788 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
789 Schema.withDecodingDefault(Effect.succeed({})),
790 ),
791 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
792 Schema.withDecodingDefault(Effect.succeed(null)),
793 ),
794
795 // Legacy single-instance-per-driver settings. Continues to be the source
796 // of truth until `providerInstances` (below) lands per-driver migration
797 // shims and the server starts hydrating instances from it. Driver-specific
798 // schemas live here for the duration of the migration; once each driver
799 // owns its config in its own package, this struct shrinks to nothing and
800 // is removed entirely.
801 providers: Schema.Struct({
802 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
803 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
804 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
805 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
806 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
807 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
808 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
809 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
810 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
811 // (forks, downgrades, in-flight PR branches) round-trip without loss.
812 // See providerInstance.ts for the forward/backward compatibility invariant.
813 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
814 Schema.withDecodingDefault(Effect.succeed({})),
815 ),
816 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
817});
818export type ServerSettings = typeof ServerSettings.Type;
819
820export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
821
822/**
823 * Read the legacy `enabled` flag embedded in a provider instance config
824 * blob. The envelope-level `ProviderInstanceConfig.enabled` is the single
825 * flag going forward; this reader exists for legacy `providers.<kind>`
826 * blobs and old settings files that still carry the flag in-config.
827 */
828export const providerInstanceConfigEnabledFlag = (config: unknown): boolean | undefined => {
829 if (config === null || typeof config !== "object" || Array.isArray(config)) {
830 return undefined;
831 }
832 const enabled = (config as { readonly enabled?: unknown }).enabled;
833 return typeof enabled === "boolean" ? enabled : undefined;
834};
835
836/**
837 * Default enabled state for a built-in driver when neither the envelope nor
838 * the config blob carries a flag. Derived from the driver's settings schema
839 * through `DEFAULT_SERVER_SETTINGS`, so the schema's decoding default stays
840 * the single source of truth. Unknown (fork) drivers default to enabled.
841 */
842export const defaultEnabledForDriver = (driver: ProviderDriverKind): boolean => {
843 const legacyDefaults = DEFAULT_SERVER_SETTINGS.providers as Record<
844 string,
845 { readonly enabled?: boolean } | undefined
846 >;
847 return legacyDefaults[driver]?.enabled ?? true;
848};
849
850/**
851 * Resolve whether a configured provider instance is enabled. An explicit
852 * false on either the envelope or the in-config flag wins (most
853 * restrictive), so a user's disable is never silently undone by the other
854 * flag. Otherwise: envelope, then config, then the driver's default.
855 */
856export const resolveProviderInstanceEnabled = (
857 instance: Pick<ProviderInstanceConfig, "driver" | "enabled" | "config">,
858): boolean => {
859 const configEnabled = providerInstanceConfigEnabledFlag(instance.config);
860 if (instance.enabled === false || configEnabled === false) {
861 return false;
862 }
863 return instance.enabled ?? configEnabled ?? defaultEnabledForDriver(instance.driver);
864};
865
866export const ServerSettingsOperation = Schema.Literals([
867 "normalize",
868 "check-exists",
869 "read-file",
870 "read-provider-history",
871 "read-secret",
872 "remove-secret",
873 "remove-stale-secret",
874 "write-secret",
875 "write-file",
876 "prepare-directory",
877]);
878export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
879
880export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
881 "ServerSettingsError",
882 {
883 settingsPath: Schema.String,
884 operation: ServerSettingsOperation,
885 providerInstanceId: Schema.optional(Schema.String),
886 environmentVariable: Schema.optional(Schema.String),
887 cause: Schema.Defect(),
888 },
889) {
890 override get message(): string {
891 const provider =
892 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
893 const variable =
894 this.environmentVariable === undefined
895 ? ""
896 : ` and environment variable ${this.environmentVariable}`;
897 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
898 }
899}
900
901// ── Unified type ─────────────────────────────────────────────────────
902
903export type UnifiedSettings = ServerSettings & ClientSettings;
904export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
905 ...DEFAULT_SERVER_SETTINGS,
906 ...DEFAULT_CLIENT_SETTINGS,
907};
908
909// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
910
911const ModelSelectionPatch = Schema.Struct({
912 instanceId: Schema.optionalKey(ProviderInstanceId),
913 model: Schema.optionalKey(TrimmedNonEmptyString),
914 options: Schema.optionalKey(ProviderOptionSelections),
915});
916
917const CodexSettingsPatch = Schema.Struct({
918 enabled: Schema.optionalKey(Schema.Boolean),
919 binaryPath: Schema.optionalKey(TrimmedString),
920 homePath: Schema.optionalKey(TrimmedString),
921 shadowHomePath: Schema.optionalKey(TrimmedString),
922 launchArgs: Schema.optionalKey(TrimmedString),
923 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
924});
925
926const ClaudeSettingsPatch = Schema.Struct({
927 enabled: Schema.optionalKey(Schema.Boolean),
928 binaryPath: Schema.optionalKey(TrimmedString),
929 homePath: Schema.optionalKey(TrimmedString),
930 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
931 launchArgs: Schema.optionalKey(TrimmedString),
932 // Validated at the patch boundary so a typo fails the one update with a
933 // schema error instead of a generic whole-settings failure.
934 autoCompactWindow: Schema.optionalKey(
935 TrimmedString.check(Schema.isPattern(CLAUDE_AUTO_COMPACT_WINDOW_PATTERN)),
936 ),
937});
938
939const CursorSettingsPatch = Schema.Struct({
940 enabled: Schema.optionalKey(Schema.Boolean),
941 binaryPath: Schema.optionalKey(TrimmedString),
942 apiEndpoint: Schema.optionalKey(TrimmedString),
943 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
944});
945
946const GrokSettingsPatch = Schema.Struct({
947 enabled: Schema.optionalKey(Schema.Boolean),
948 binaryPath: Schema.optionalKey(TrimmedString),
949 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
950});
951
952const OpenCodeSettingsPatch = Schema.Struct({
953 enabled: Schema.optionalKey(Schema.Boolean),
954 binaryPath: Schema.optionalKey(TrimmedString),
955 serverUrl: Schema.optionalKey(TrimmedString),
956 serverPassword: Schema.optionalKey(TrimmedString),
957 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
958});
959
960export const ServerSettingsPatch = Schema.Struct({
961 // Server settings
962 enableLegacyTokenStreaming: Schema.optionalKey(Schema.Boolean),
963 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
964 enableAgentBrowserAccess: Schema.optionalKey(Schema.Boolean),
965 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
966 sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
967 backgroundActivity: Schema.optionalKey(
968 Schema.Struct({
969 schemaVersion: Schema.optionalKey(Schema.Literal(1)),
970 profile: Schema.optionalKey(BackgroundActivityProfileSelection),
971 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
972 overrides: Schema.optionalKey(BackgroundActivityOverrides),
973 }),
974 ),
975 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
976 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
977 backgroundActivityProfile: Schema.optionalKey(BackgroundActivityProfile),
978 environmentIcon: Schema.optionalKey(Schema.NullOr(EnvironmentMachineKind)),
979 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
980 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
981 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
982 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
983 sourceControlWritingStyle: Schema.optionalKey(
984 Schema.Struct({
985 mode: Schema.optionalKey(SourceControlWritingStyleMode),
986 customInstructions: Schema.optionalKey(TrimmedString),
987 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
988 }),
989 ),
990 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
991 observability: Schema.optionalKey(
992 Schema.Struct({
993 otlpTracesUrl: Schema.optionalKey(TrimmedString),
994 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
995 }),
996 ),
997 providers: Schema.optionalKey(
998 Schema.Struct({
999 codex: Schema.optionalKey(CodexSettingsPatch),
1000 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
1001 cursor: Schema.optionalKey(CursorSettingsPatch),
1002 grok: Schema.optionalKey(GrokSettingsPatch),
1003 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
1004 }),
1005 ),
1006 // Whole-map replacement for the new instance config. Patching individual
1007 // entries is intentionally out of scope: the map is small, and partial
1008 // patches risk leaving driver-specific config in a half-merged state.
1009 // The web UI sends a fully-formed map every time it edits this field.
1010 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
1011});
1012export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
1013
1014export const ClientSettingsPatch = Schema.Struct({
1015 appearanceContrast: Schema.optionalKey(AppearanceContrast),
1016 panelAnimationDurationMs: Schema.optionalKey(PanelAnimationDurationMs),
1017 browserDefaultViewport: Schema.optionalKey(PreviewViewportSetting),
1018 browserDefaultZoomFactor: Schema.optionalKey(PreviewZoomFactor),
1019 browserDefaultAppearance: Schema.optionalKey(PreviewAppearancePreference),
1020 browserRecordingFrameRate: Schema.optionalKey(BrowserRecordingFrameRate),
1021 browserLinkTarget: Schema.optionalKey(BrowserLinkTarget),
1022 browserAutoShowFloatingPreview: Schema.optionalKey(Schema.Boolean),
1023 browserProfiles: Schema.optionalKey(Schema.Array(BrowserProfile)),
1024 browserDefaultProfileId: Schema.optionalKey(BrowserProfileId),
1025 confirmQuit: Schema.optionalKey(QuitConfirmationMode),
1026 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
1027 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
1028 confirmThreadUnpin: Schema.optionalKey(Schema.Boolean),
1029 continueThreadsAfterServerUpdate: Schema.optionalKey(Schema.Boolean),
1030 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
1031 diffLayout: Schema.optionalKey(DiffLayout),
1032 environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
1033 glassOpacity: Schema.optionalKey(GlassOpacity),
1034 fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
1035 fontSizePrompt: Schema.optionalKey(PromptFontSize),
1036 fontSizeCode: Schema.optionalKey(CodeFontSize),
1037 fontSizeTerminal: Schema.optionalKey(TerminalFontSize),
1038 fontFamilyCode: Schema.optionalKey(FontFamilyPreference),
1039 fontFamilyComposer: Schema.optionalKey(FontFamilyPreference),
1040 fontFamilySans: Schema.optionalKey(FontFamilyPreference),
1041 fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
1042 fontSmoothing: Schema.optionalKey(Schema.Boolean),
1043 favorites: Schema.optionalKey(
1044 Schema.Array(
1045 Schema.Struct({
1046 provider: ProviderInstanceId,
1047 model: TrimmedNonEmptyString,
1048 }),
1049 ),
1050 ),
1051 providerModelPreferences: Schema.optionalKey(
1052 Schema.Record(
1053 ProviderInstanceId,
1054 Schema.Struct({
1055 hiddenModels: Schema.Array(Schema.String).pipe(
1056 Schema.withDecodingDefault(Effect.succeed([])),
1057 ),
1058 modelOrder: Schema.Array(Schema.String).pipe(
1059 Schema.withDecodingDefault(Effect.succeed([])),
1060 ),
1061 }),
1062 ),
1063 ),
1064 planModeEnabled: Schema.optionalKey(Schema.Boolean),
1065 contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),
1066 proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean),
1067 showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
1068 legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
1069 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
1070 sidebarProjectGroupingOverrides: Schema.optionalKey(
1071 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
1072 ),
1073 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
1074 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
1075 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
1076 timestampFormat: Schema.optionalKey(TimestampFormat),
1077 wordWrap: Schema.optionalKey(Schema.Boolean),
1078});
1079export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;