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