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

settings.ts

1,187 lines51.0 KB

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 using 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 // Desktop resting composer. Each trigger that settles an existing thread's
323 // composer into its single-line layout can be turned off on its own.
324 composerCollapseOnBlur: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
325 composerCollapseOnScroll: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
326 proactivePanelsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
327 showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
328 // Legacy sidebar (the original per-project tree). Deliberately a fresh key
329 // (was `sidebarV2Enabled` + `sidebarV2ConfiguredByUser`): decoding drops the
330 // old keys, so everyone, including prior beta opt-outs, resets to the new
331 // default sidebar.
332 legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
333 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
334 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
335 ),
336 sidebarProjectGroupingOverrides: Schema.Record(
337 TrimmedNonEmptyString,
338 SidebarProjectGroupingMode,
339 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
340 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
341 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
342 ),
343 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
344 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
345 ),
346 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
347 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
348 ),
349 timestampFormat: TimestampFormat.pipe(
350 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
351 ),
352 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
353});
354export type ClientSettings = typeof ClientSettingsSchema.Type;
355​
356export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
357​
358// ── Server Settings (server-authoritative) ────────────────────
359​
360const makeBinaryPathSetting = (fallback: string) =>
361 TrimmedString.pipe(
362 Schema.decodeTo(
363 Schema.String,
364 SchemaTransformation.transformOrFail({
365 decode: (value) => Effect.succeed(value || fallback),
366 encode: (value) => Effect.succeed(value),
367 }),
368 ),
369 Schema.withDecodingDefault(Effect.succeed(fallback)),
370 );
371​
372export type ProviderSettingsFormControl = "text" | "password" | "textarea" | "switch" | "select";
373​
374export interface ProviderSettingsFormOption {
375 readonly value: string;
376 readonly label: string;
378​
379export interface ProviderSettingsFormAnnotation {
380 readonly control?: ProviderSettingsFormControl | undefined;
381 readonly placeholder?: string | undefined;
382 readonly hidden?: boolean | undefined;
383 readonly clearWhenEmpty?: "omit" | "persist" | undefined;
384 /** Choices for a `select` control. The first entry is the default. */
385 readonly options?: ReadonlyArray<ProviderSettingsFormOption> | undefined;
387​
388export interface ProviderSettingsFormSchemaAnnotation {
389 readonly order?: readonly string[] | undefined;
391​
392declare module "effect/Schema" {
393 namespace Annotations {
394 interface Annotations {
395 readonly providerSettingsForm?: ProviderSettingsFormAnnotation | undefined;
396 readonly providerSettingsFormSchema?: ProviderSettingsFormSchemaAnnotation | undefined;
397 }
398 }
400​
401export type ProviderSettingsOrder<Fields extends Schema.Struct.Fields> = readonly Extract<
402 keyof Fields,
403 string
404>[];
405​
406export function makeProviderSettingsSchema<const Fields extends Schema.Struct.Fields>(
407 fields: Fields,
408 options?: {
409 readonly order?: ProviderSettingsOrder<Fields> | undefined;
410 },
411): Schema.Struct<Fields> {
412 return Schema.Struct(fields).pipe(
413 Schema.annotate({
414 providerSettingsFormSchema:
415 options?.order === undefined ? undefined : { order: options.order },
416 }),
417 );
419​
420export const CodexSettings = makeProviderSettingsSchema(
421 {
422 enabled: Schema.Boolean.pipe(
423 Schema.withDecodingDefault(Effect.succeed(true)),
424 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
425 ),
426 binaryPath: makeBinaryPathSetting("codex").pipe(
427 Schema.annotateKey({
428 title: "Binary path",
429 description: "Path to the Codex binary used by this instance.",
430 providerSettingsForm: { placeholder: "codex", clearWhenEmpty: "omit" },
431 }),
432 ),
433 homePath: TrimmedString.pipe(
434 Schema.withDecodingDefault(Effect.succeed("")),
435 Schema.annotateKey({
436 title: "CODEX_HOME path",
437 description: "Custom Codex home and config directory.",
438 providerSettingsForm: {
439 placeholder: "~/.codex",
440 clearWhenEmpty: "omit",
441 },
442 }),
443 ),
444 shadowHomePath: TrimmedString.pipe(
445 Schema.withDecodingDefault(Effect.succeed("")),
446 Schema.annotateKey({
447 title: "Shadow home path",
448 description:
449 "Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
450 providerSettingsForm: {
451 placeholder: "~/.codex-t3/personal",
452 clearWhenEmpty: "omit",
453 },
454 }),
455 ),
456 launchArgs: TrimmedString.pipe(
457 Schema.withDecodingDefault(Effect.succeed("")),
458 Schema.annotateKey({
459 title: "Launch arguments",
460 description: "Additional CLI arguments passed to codex app-server on session start.",
461 }),
462 ),
463 customModels: Schema.Array(Schema.String).pipe(
464 Schema.withDecodingDefault(Effect.succeed([])),
465 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
466 ),
467 },
468 {
469 order: ["binaryPath", "homePath", "shadowHomePath", "launchArgs"],
470 },
471);
472export type CodexSettings = typeof CodexSettings.Type;
473​
474// Empty, or an integer from 100,000 to 1,000,000. Shared by the full
475// Claude settings schema and its patch so an out-of-range value fails at
476// the update that introduced it.
477const CLAUDE_AUTO_COMPACT_WINDOW_PATTERN = /^(?:|[1-9]\d{5}|1000000)$/;
478​
479export const ClaudeSettings = makeProviderSettingsSchema(
480 {
481 enabled: Schema.Boolean.pipe(
482 Schema.withDecodingDefault(Effect.succeed(true)),
483 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
484 ),
485 binaryPath: makeBinaryPathSetting("claude").pipe(
486 Schema.annotateKey({
487 title: "Binary path",
488 description: "Path to the Claude binary used by this instance.",
489 providerSettingsForm: { placeholder: "claude", clearWhenEmpty: "omit" },
490 }),
491 ),
492 homePath: TrimmedString.pipe(
493 Schema.withDecodingDefault(Effect.succeed("")),
494 Schema.annotateKey({
495 title: "CLAUDE_CONFIG_DIR path",
496 description:
497 "Custom Claude home and config directory. Keeps .claude.json and .claude separate.",
498 providerSettingsForm: { placeholder: "~/.claude", clearWhenEmpty: "omit" },
499 }),
500 ),
501 customModels: Schema.Array(Schema.String).pipe(
502 Schema.withDecodingDefault(Effect.succeed([])),
503 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
504 ),
505 launchArgs: Schema.String.pipe(
506 Schema.withDecodingDefault(Effect.succeed("")),
507 Schema.annotateKey({
508 title: "Launch arguments",
509 description: "Additional CLI arguments passed on session start.",
510 providerSettingsForm: {
511 placeholder: "e.g. --chrome",
512 clearWhenEmpty: "omit",
513 },
514 }),
515 ),
516 autoCompactWindow: TrimmedString.check(
517 Schema.isPattern(CLAUDE_AUTO_COMPACT_WINDOW_PATTERN),
518 ).pipe(
519 Schema.withDecodingDefault(Effect.succeed("")),
520 Schema.annotateKey({
521 title: "Auto-compact after",
522 description:
523 "Compact after 100,000 to 1,000,000 tokens. Leave empty to use Claude's default.",
524 providerSettingsForm: {
525 placeholder: "e.g. 300000",
526 clearWhenEmpty: "omit",
527 },
528 }),
529 ),
530 },
531 {
532 order: ["binaryPath", "homePath", "autoCompactWindow", "launchArgs"],
533 },
534);
535export type ClaudeSettings = typeof ClaudeSettings.Type;
536​
537export const CursorSettings = makeProviderSettingsSchema(
538 {
539 // Off by default like Grok and OpenCode. Users opt in from Settings.
540 enabled: Schema.Boolean.pipe(
541 Schema.withDecodingDefault(Effect.succeed(false)),
542 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
543 ),
544 binaryPath: makeBinaryPathSetting("cursor-agent").pipe(
545 Schema.annotateKey({
546 title: "Binary path",
547 description: "Path to the Cursor agent binary.",
548 providerSettingsForm: { placeholder: "cursor-agent", clearWhenEmpty: "omit" },
549 }),
550 ),
551 apiEndpoint: TrimmedString.pipe(
552 Schema.withDecodingDefault(Effect.succeed("")),
553 Schema.annotateKey({
554 title: "API endpoint",
555 description: "Override the Cursor API endpoint for this instance.",
556 providerSettingsForm: {
557 placeholder: "https://...",
558 clearWhenEmpty: "omit",
559 },
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", "apiEndpoint"],
569 },
570);
571export type CursorSettings = typeof CursorSettings.Type;
572​
573export const GrokSettings = makeProviderSettingsSchema(
574 {
575 // Off by default (like Cursor and OpenCode): the binding is not yet
576 // stable 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("grok").pipe(
582 Schema.annotateKey({
583 title: "Binary path",
584 description: "Path to the Grok CLI binary.",
585 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
586 }),
587 ),
588 customModels: Schema.Array(Schema.String).pipe(
589 Schema.withDecodingDefault(Effect.succeed([])),
590 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
591 ),
592 },
593 {
594 order: ["binaryPath"],
595 },
596);
597export type GrokSettings = typeof GrokSettings.Type;
598​
599/**
600 * Antigravity ACP auth methods. Personal and Enterprise open a Google sign-in
601 * in the browser. The API key and Agent Platform methods take credentials from
602 * the instance config and never open a browser.
603 */
604export const ANTIGRAVITY_AUTH_METHODS = [
605 { value: "oauth-personal", label: "Google account" },
606 { value: "oauth-business", label: "Gemini Enterprise" },
607 { value: "gemini-api-key", label: "Gemini API key" },
608 { value: "agent-platform", label: "Agent Platform (Vertex AI)" },
609] as const satisfies ReadonlyArray<ProviderSettingsFormOption>;
610export const AntigravityAuthMethod = Schema.Literals(
611 ANTIGRAVITY_AUTH_METHODS.map((method) => method.value),
612);
613export type AntigravityAuthMethod = typeof AntigravityAuthMethod.Type;
614​
615export const AntigravitySettings = makeProviderSettingsSchema(
616 {
617 enabled: Schema.Boolean.pipe(
618 Schema.withDecodingDefault(Effect.succeed(false)),
619 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
620 ),
621 authMethod: AntigravityAuthMethod.pipe(
622 Schema.withDecodingDefault(Effect.succeed("oauth-personal" as const)),
623 Schema.annotateKey({
624 title: "Sign-in method",
625 description:
626 "Google account uses your Antigravity subscription. Gemini Enterprise needs a GCP project and location. API key and Agent Platform bill the credential you enter.",
627 providerSettingsForm: {
628 control: "select",
629 options: ANTIGRAVITY_AUTH_METHODS,
630 clearWhenEmpty: "omit",
631 },
632 }),
633 ),
634 apiKey: TrimmedString.pipe(
635 Schema.withDecodingDefault(Effect.succeed("")),
636 Schema.annotateKey({
637 title: "API key",
638 description:
639 "Gemini API key, or a Vertex AI express key for Agent Platform. Stored in plain text on this environment.",
640 providerSettingsForm: {
641 control: "password",
642 placeholder: "Optional",
643 clearWhenEmpty: "omit",
644 },
645 }),
646 ),
647 gcpProject: TrimmedString.pipe(
648 Schema.withDecodingDefault(Effect.succeed("")),
649 Schema.annotateKey({
650 title: "GCP project",
651 description:
652 "Required for Gemini Enterprise. Agent Platform uses it when no API key is set.",
653 providerSettingsForm: { placeholder: "my-project-id", clearWhenEmpty: "omit" },
654 }),
655 ),
656 gcpLocation: TrimmedString.pipe(
657 Schema.withDecodingDefault(Effect.succeed("")),
658 Schema.annotateKey({
659 title: "GCP location",
660 description: "Region for Gemini Enterprise or Agent Platform, such as us-central1.",
661 providerSettingsForm: { placeholder: "us-central1", clearWhenEmpty: "omit" },
662 }),
663 ),
664 binaryPath: TrimmedString.pipe(
665 Schema.withDecodingDefault(Effect.succeed("")),
666 Schema.annotateKey({
667 title: "Binary path",
668 description:
669 "Optional path to the official Antigravity ACP executable. Leave empty for automatic selection.",
670 providerSettingsForm: { placeholder: "Automatic", clearWhenEmpty: "persist" },
671 }),
672 ),
673 customModels: Schema.Array(Schema.String).pipe(
674 Schema.withDecodingDefault(Effect.succeed([])),
675 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
676 ),
677 },
678 { order: ["authMethod", "apiKey", "gcpProject", "gcpLocation", "binaryPath"] },
679);
680export type AntigravitySettings = typeof AntigravitySettings.Type;
681​
682export const OpenCodeSettings = makeProviderSettingsSchema(
683 {
684 // Off by default (like Cursor and Grok): the binding is not yet stable
685 // enough to probe on every install. Users opt in from Settings.
686 enabled: Schema.Boolean.pipe(
687 Schema.withDecodingDefault(Effect.succeed(false)),
688 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
689 ),
690 binaryPath: makeBinaryPathSetting("opencode").pipe(
691 Schema.annotateKey({
692 title: "Binary path",
693 description: "Path to the OpenCode binary.",
694 providerSettingsForm: {
695 placeholder: "opencode",
696 clearWhenEmpty: "omit",
697 },
698 }),
699 ),
700 serverUrl: TrimmedString.pipe(
701 Schema.withDecodingDefault(Effect.succeed("")),
702 Schema.annotateKey({
703 title: "Server URL",
704 description: "Leave blank to let T3 Code spawn the server when needed.",
705 providerSettingsForm: {
706 placeholder: "http://127.0.0.1:4096",
707 clearWhenEmpty: "omit",
708 },
709 }),
710 ),
711 serverPassword: TrimmedString.pipe(
712 Schema.withDecodingDefault(Effect.succeed("")),
713 Schema.annotateKey({
714 title: "Server password",
715 description: "Stored in plain text on disk.",
716 providerSettingsForm: {
717 control: "password",
718 placeholder: "Optional",
719 clearWhenEmpty: "omit",
720 },
721 }),
722 ),
723 customModels: Schema.Array(Schema.String).pipe(
724 Schema.withDecodingDefault(Effect.succeed([])),
725 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
726 ),
727 },
728 {
729 order: ["binaryPath", "serverUrl", "serverPassword"],
730 },
731);
732export type OpenCodeSettings = typeof OpenCodeSettings.Type;
733​
734export const ObservabilitySettings = Schema.Struct({
735 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
736 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
737});
738export type ObservabilitySettings = typeof ObservabilitySettings.Type;
739​
740export const SourceControlWritingStyleMode = Schema.Literals([
741 "repo_conventions",
742 "conventional_commits",
743 "custom",
744]);
745export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
746​
747export const SourceControlWritingStyleSettings = Schema.Struct({
748 mode: SourceControlWritingStyleMode.pipe(
749 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
750 ),
751 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
752 followChangeRequestTemplates: Schema.Boolean.pipe(
753 Schema.withDecodingDefault(Effect.succeed(true)),
754 ),
755});
756export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
757​
758export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
759export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
760​
761export const BackgroundActivityProfile = Schema.Literals([
762 "balanced",
763 "performance",
764 "battery-saver",
765]);
766export type BackgroundActivityProfile = typeof BackgroundActivityProfile.Type;
767export const DEFAULT_BACKGROUND_ACTIVITY_PROFILE: BackgroundActivityProfile = "balanced";
768​
769export const BackgroundActivityProfileSelection = Schema.Literals([
770 "balanced",
771 "performance",
772 "battery-saver",
773 "custom",
774]);
775export type BackgroundActivityProfileSelection = typeof BackgroundActivityProfileSelection.Type;
776​
777export const BackgroundActivityOverrides = Schema.Struct({
778 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
779 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
780 hostPowerMonitorActiveInterval: Schema.optionalKey(Schema.DurationFromMillis),
781 hostPowerMonitorIdleInterval: Schema.optionalKey(Schema.DurationFromMillis),
782 idleClientTtl: Schema.optionalKey(Schema.DurationFromMillis),
783 pauseWhenHostLocked: Schema.optionalKey(Schema.Boolean),
784 pauseWhenHostLowPower: Schema.optionalKey(Schema.Boolean),
785 pauseWhenClientLowPower: Schema.optionalKey(Schema.Boolean),
786 pauseWhenOnBattery: Schema.optionalKey(Schema.Boolean),
787});
788export type BackgroundActivityOverrides = typeof BackgroundActivityOverrides.Type;
789​
790export const BackgroundActivitySettings = Schema.Struct({
791 schemaVersion: Schema.Literal(1).pipe(Schema.withDecodingDefault(Effect.succeed(1 as const))),
792 profile: BackgroundActivityProfileSelection.pipe(
793 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
794 ),
795 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
796 overrides: BackgroundActivityOverrides.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
797}).pipe(Schema.withDecodingDefault(Effect.succeed({})));
798export type BackgroundActivitySettings = typeof BackgroundActivitySettings.Type;
799​
800export const ServerSettings = Schema.Struct({
801 // Legacy token-by-token assistant output. Deliberately a fresh key (was
802 // `enableAssistantStreaming`): decoding drops the old key, so everyone,
803 // including prior opt-ins, resets to the buffered default.
804 enableLegacyTokenStreaming: Schema.Boolean.pipe(
805 Schema.withDecodingDefault(Effect.succeed(false)),
806 ),
807 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
808 /**
809 * Whether agents may drive the in-app preview browser. Turning this off
810 * withholds the MCP credential, so the `t3-code` server (and with it every
811 * `preview_*` tool) is never attached to a provider session, and the prompt
812 * text describing those tools is dropped along with them. The user's own
813 * browser panel is unaffected — this gates agent access only.
814 *
815 * Server-authoritative rather than client-local: tool injection and prompt
816 * construction both happen on the server, and the answer must not differ
817 * between a desktop window and a phone attached to the same server.
818 */
819 enableAgentBrowserAccess: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
820 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
821 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
822 ),
823 sidebarAutoSettleOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
824 backgroundActivity: BackgroundActivitySettings,
825 // Legacy flat fields retained for old settings files and old clients. New
826 // consumers should resolve `backgroundActivity` instead.
827 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
828 Schema.withDecodingDefault(
829 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
830 ),
831 ),
832 providerHealthRefreshInterval: Schema.DurationFromMillis.pipe(
833 Schema.withDecodingDefault(
834 Effect.succeed(Duration.toMillis(DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL)),
835 ),
836 ),
837 backgroundActivityProfile: BackgroundActivityProfile.pipe(
838 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
839 ),
840 defaultTheme: DefaultThemePreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
841 /**
842 * When the environment's theme was last set, so clients can tell a re-set
843 * of the same value from one they already applied: `t3 theme set` must act
844 * even when it names the theme it named before. Empty on environments
845 * provisioned by builds that predate it, where clients fall back to
846 * applying once per value.
847 */
848 defaultThemeSetAt: Schema.String.check(Schema.isMaxLength(64)).pipe(
849 Schema.withDecodingDefault(Effect.succeed("")),
850 ),
851 /**
852 * The icon clients draw for this environment. Null means "use what the
853 * server detected" (`environment.platform.machine`), falling back to a
854 * generic server. Lives on the server, not the client, so every device
855 * sees the same machine. A kind picked on a newer server decodes as null
856 * here rather than failing the whole settings snapshot for an older client.
857 */
858 environmentIcon: ForwardCompatibleNullable(EnvironmentMachineKind).pipe(
859 Schema.withDecodingDefault(Effect.succeed(null)),
860 ),
861 defaultThreadEnvMode: ThreadEnvMode.pipe(
862 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
863 ),
864 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
865 Schema.withDecodingDefault(Effect.succeed(true)),
866 ),
867 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
868 textGenerationModelSelection: ModelSelection.pipe(
869 Schema.withDecodingDefault(
870 Effect.succeed({
871 instanceId: ProviderInstanceId.make("codex"),
872 model: DEFAULT_TEXT_GENERATION_MODEL,
873 options: [
874 {
875 id: "reasoningEffort",
876 value: DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
877 },
878 ],
879 }),
880 ),
881 ),
882 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
883 Schema.withDecodingDefault(Effect.succeed({})),
884 ),
885 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
886 Schema.withDecodingDefault(Effect.succeed(null)),
887 ),
888​
889 // Legacy single-instance-per-driver settings. Continues to be the source
890 // of truth until `providerInstances` (below) lands per-driver migration
891 // shims and the server starts hydrating instances from it. Driver-specific
892 // schemas live here for the duration of the migration; once each driver
893 // owns its config in its own package, this struct shrinks to nothing and
894 // is removed entirely.
895 providers: Schema.Struct({
896 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
897 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
898 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
899 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
900 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
901 antigravity: AntigravitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
902 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
903 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
904 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
905 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
906 // (forks, downgrades, in-flight PR branches) round-trip without loss.
907 // See providerInstance.ts for the forward/backward compatibility invariant.
908 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
909 Schema.withDecodingDefault(Effect.succeed({})),
910 ),
911 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
912});
913export type ServerSettings = typeof ServerSettings.Type;
914​
915export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
916​
917/**
918 * Read the legacy `enabled` flag embedded in a provider instance config
919 * blob. The envelope-level `ProviderInstanceConfig.enabled` is the single
920 * flag going forward; this reader exists for legacy `providers.<kind>`
921 * blobs and old settings files that still carry the flag in-config.
922 */
923export const providerInstanceConfigEnabledFlag = (config: unknown): boolean | undefined => {
924 if (config === null || typeof config !== "object" || Array.isArray(config)) {
925 return undefined;
926 }
927 const enabled = (config as { readonly enabled?: unknown }).enabled;
928 return typeof enabled === "boolean" ? enabled : undefined;
929};
930​
931/**
932 * Default enabled state for a built-in driver when neither the envelope nor
933 * the config blob carries a flag. Derived from the driver's settings schema
934 * through `DEFAULT_SERVER_SETTINGS`, so the schema's decoding default stays
935 * the single source of truth. Unknown (fork) drivers default to enabled.
936 */
937export const defaultEnabledForDriver = (driver: ProviderDriverKind): boolean => {
938 const legacyDefaults = DEFAULT_SERVER_SETTINGS.providers as Record<
939 string,
940 { readonly enabled?: boolean } | undefined
941 >;
942 return legacyDefaults[driver]?.enabled ?? true;
943};
944​
945/**
946 * Resolve whether a configured provider instance is enabled. An explicit
947 * false on either the envelope or the in-config flag wins (most
948 * restrictive), so a user's disable is never silently undone by the other
949 * flag. Otherwise: envelope, then config, then the driver's default.
950 */
951export const resolveProviderInstanceEnabled = (
952 instance: Pick<ProviderInstanceConfig, "driver" | "enabled" | "config">,
953): boolean => {
954 const configEnabled = providerInstanceConfigEnabledFlag(instance.config);
955 if (instance.enabled === false || configEnabled === false) {
956 return false;
957 }
958 return instance.enabled ?? configEnabled ?? defaultEnabledForDriver(instance.driver);
959};
960​
961export const ServerSettingsOperation = Schema.Literals([
962 "normalize",
963 "check-exists",
964 "read-file",
965 "read-provider-history",
966 "read-secret",
967 "remove-secret",
968 "remove-stale-secret",
969 "write-secret",
970 "write-file",
971 "prepare-directory",
972]);
973export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
974​
975export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
976 "ServerSettingsError",
977 {
978 settingsPath: Schema.String,
979 operation: ServerSettingsOperation,
980 providerInstanceId: Schema.optional(Schema.String),
981 environmentVariable: Schema.optional(Schema.String),
982 cause: Schema.Defect(),
983 },
984) {
985 override get message(): string {
986 const provider =
987 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
988 const variable =
989 this.environmentVariable === undefined
990 ? ""
991 : ` and environment variable ${this.environmentVariable}`;
992 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
993 }
995​
996// ── Unified type ─────────────────────────────────────────────────────
997​
998export type UnifiedSettings = ServerSettings & ClientSettings;
999export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
1000 ...DEFAULT_SERVER_SETTINGS,
1001 ...DEFAULT_CLIENT_SETTINGS,
1003​
1004// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
1005​
1006const ModelSelectionPatch = Schema.Struct({
1007 instanceId: Schema.optionalKey(ProviderInstanceId),
1008 model: Schema.optionalKey(TrimmedNonEmptyString),
1009 options: Schema.optionalKey(ProviderOptionSelections),
1010});
1011​
1012const CodexSettingsPatch = Schema.Struct({
1013 enabled: Schema.optionalKey(Schema.Boolean),
1014 binaryPath: Schema.optionalKey(TrimmedString),
1015 homePath: Schema.optionalKey(TrimmedString),
1016 shadowHomePath: Schema.optionalKey(TrimmedString),
1017 launchArgs: Schema.optionalKey(TrimmedString),
1018 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1019});
1020​
1021const ClaudeSettingsPatch = Schema.Struct({
1022 enabled: Schema.optionalKey(Schema.Boolean),
1023 binaryPath: Schema.optionalKey(TrimmedString),
1024 homePath: Schema.optionalKey(TrimmedString),
1025 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1026 launchArgs: Schema.optionalKey(TrimmedString),
1027 // Validated at the patch boundary so a typo fails the one update with a
1028 // schema error instead of a generic whole-settings failure.
1029 autoCompactWindow: Schema.optionalKey(
1030 TrimmedString.check(Schema.isPattern(CLAUDE_AUTO_COMPACT_WINDOW_PATTERN)),
1031 ),
1032});
1033​
1034const CursorSettingsPatch = Schema.Struct({
1035 enabled: Schema.optionalKey(Schema.Boolean),
1036 binaryPath: Schema.optionalKey(TrimmedString),
1037 apiEndpoint: Schema.optionalKey(TrimmedString),
1038 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1039});
1040​
1041const GrokSettingsPatch = Schema.Struct({
1042 enabled: Schema.optionalKey(Schema.Boolean),
1043 binaryPath: Schema.optionalKey(TrimmedString),
1044 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1045});
1046​
1047const AntigravitySettingsPatch = Schema.Struct({
1048 enabled: Schema.optionalKey(Schema.Boolean),
1049 authMethod: Schema.optionalKey(AntigravityAuthMethod),
1050 apiKey: Schema.optionalKey(TrimmedString),
1051 gcpProject: Schema.optionalKey(TrimmedString),
1052 gcpLocation: Schema.optionalKey(TrimmedString),
1053 binaryPath: Schema.optionalKey(TrimmedString),
1054 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1055});
1056​
1057const OpenCodeSettingsPatch = Schema.Struct({
1058 enabled: Schema.optionalKey(Schema.Boolean),
1059 binaryPath: Schema.optionalKey(TrimmedString),
1060 serverUrl: Schema.optionalKey(TrimmedString),
1061 serverPassword: Schema.optionalKey(TrimmedString),
1062 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
1063});
1064​
1065export const ServerSettingsPatch = Schema.Struct({
1066 // Server settings
1067 enableLegacyTokenStreaming: Schema.optionalKey(Schema.Boolean),
1068 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
1069 enableAgentBrowserAccess: Schema.optionalKey(Schema.Boolean),
1070 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
1071 sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
1072 backgroundActivity: Schema.optionalKey(
1073 Schema.Struct({
1074 schemaVersion: Schema.optionalKey(Schema.Literal(1)),
1075 profile: Schema.optionalKey(BackgroundActivityProfileSelection),
1076 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
1077 overrides: Schema.optionalKey(BackgroundActivityOverrides),
1078 }),
1079 ),
1080 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
1081 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
1082 backgroundActivityProfile: Schema.optionalKey(BackgroundActivityProfile),
1083 environmentIcon: Schema.optionalKey(Schema.NullOr(EnvironmentMachineKind)),
1084 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
1085 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
1086 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
1087 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
1088 sourceControlWritingStyle: Schema.optionalKey(
1089 Schema.Struct({
1090 mode: Schema.optionalKey(SourceControlWritingStyleMode),
1091 customInstructions: Schema.optionalKey(TrimmedString),
1092 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
1093 }),
1094 ),
1095 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
1096 observability: Schema.optionalKey(
1097 Schema.Struct({
1098 otlpTracesUrl: Schema.optionalKey(TrimmedString),
1099 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
1100 }),
1101 ),
1102 providers: Schema.optionalKey(
1103 Schema.Struct({
1104 codex: Schema.optionalKey(CodexSettingsPatch),
1105 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
1106 cursor: Schema.optionalKey(CursorSettingsPatch),
1107 grok: Schema.optionalKey(GrokSettingsPatch),
1108 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
1109 antigravity: Schema.optionalKey(AntigravitySettingsPatch),
1110 }),
1111 ),
1112 // Whole-map replacement for the new instance config. Patching individual
1113 // entries is intentionally out of scope: the map is small, and partial
1114 // patches risk leaving driver-specific config in a half-merged state.
1115 // The web UI sends a fully-formed map every time it edits this field.
1116 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
1117});
1118export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
1119​
1120export const ClientSettingsPatch = Schema.Struct({
1121 appearanceContrast: Schema.optionalKey(AppearanceContrast),
1122 panelAnimationDurationMs: Schema.optionalKey(PanelAnimationDurationMs),
1123 browserDefaultViewport: Schema.optionalKey(PreviewViewportSetting),
1124 browserDefaultZoomFactor: Schema.optionalKey(PreviewZoomFactor),
1125 browserDefaultAppearance: Schema.optionalKey(PreviewAppearancePreference),
1126 browserRecordingFrameRate: Schema.optionalKey(BrowserRecordingFrameRate),
1127 browserLinkTarget: Schema.optionalKey(BrowserLinkTarget),
1128 browserAutoShowFloatingPreview: Schema.optionalKey(Schema.Boolean),
1129 browserProfiles: Schema.optionalKey(Schema.Array(BrowserProfile)),
1130 browserDefaultProfileId: Schema.optionalKey(BrowserProfileId),
1131 confirmQuit: Schema.optionalKey(QuitConfirmationMode),
1132 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
1133 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
1134 confirmThreadUnpin: Schema.optionalKey(Schema.Boolean),
1135 continueThreadsAfterServerUpdate: Schema.optionalKey(Schema.Boolean),
1136 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
1137 diffLayout: Schema.optionalKey(DiffLayout),
1138 environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
1139 glassOpacity: Schema.optionalKey(GlassOpacity),
1140 fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
1141 fontSizePrompt: Schema.optionalKey(PromptFontSize),
1142 fontSizeCode: Schema.optionalKey(CodeFontSize),
1143 fontSizeTerminal: Schema.optionalKey(TerminalFontSize),
1144 fontFamilyCode: Schema.optionalKey(FontFamilyPreference),
1145 fontFamilyComposer: Schema.optionalKey(FontFamilyPreference),
1146 fontFamilySans: Schema.optionalKey(FontFamilyPreference),
1147 fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
1148 fontSmoothing: Schema.optionalKey(Schema.Boolean),
1149 favorites: Schema.optionalKey(
1150 Schema.Array(
1151 Schema.Struct({
1152 provider: ProviderInstanceId,
1153 model: TrimmedNonEmptyString,
1154 }),
1155 ),
1156 ),
1157 providerModelPreferences: Schema.optionalKey(
1158 Schema.Record(
1159 ProviderInstanceId,
1160 Schema.Struct({
1161 hiddenModels: Schema.Array(Schema.String).pipe(
1162 Schema.withDecodingDefault(Effect.succeed([])),
1163 ),
1164 modelOrder: Schema.Array(Schema.String).pipe(
1165 Schema.withDecodingDefault(Effect.succeed([])),
1166 ),
1167 }),
1168 ),
1169 ),
1170 planModeEnabled: Schema.optionalKey(Schema.Boolean),
1171 contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),
1172 composerCollapseOnBlur: Schema.optionalKey(Schema.Boolean),
1173 composerCollapseOnScroll: Schema.optionalKey(Schema.Boolean),
1174 proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean),
1175 showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
1176 legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
1177 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
1178 sidebarProjectGroupingOverrides: Schema.optionalKey(
1179 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
1180 ),
1181 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
1182 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
1183 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
1184 timestampFormat: Schema.optionalKey(TimestampFormat),
1185 wordWrap: Schema.optionalKey(Schema.Boolean),
1186});
1187export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;