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 { TrimmedNonEmptyString, TrimmedString } from "./baseSchemas.ts";
6import {
7 DEFAULT_TEXT_GENERATION_MODEL,
8 DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
9 ProviderOptionSelections,
10} from "./model.ts";
11import { ModelSelection } from "./orchestration.ts";
12import { ProviderInstanceConfig, ProviderInstanceId } from "./providerInstance.ts";
13
14// ── Client Settings (local-only) ───────────────────────────────
15
16export const TimestampFormat = Schema.Literals(["locale", "12-hour", "24-hour"]);
17export type TimestampFormat = typeof TimestampFormat.Type;
18export const DEFAULT_TIMESTAMP_FORMAT: TimestampFormat = "locale";
19
20export const SidebarProjectSortOrder = Schema.Literals(["updated_at", "created_at", "manual"]);
21export type SidebarProjectSortOrder = typeof SidebarProjectSortOrder.Type;
22export const DEFAULT_SIDEBAR_PROJECT_SORT_ORDER: SidebarProjectSortOrder = "updated_at";
23
24export const SidebarThreadSortOrder = Schema.Literals(["updated_at", "created_at"]);
25export type SidebarThreadSortOrder = typeof SidebarThreadSortOrder.Type;
26export const DEFAULT_SIDEBAR_THREAD_SORT_ORDER: SidebarThreadSortOrder = "updated_at";
27
28export const SidebarProjectGroupingMode = Schema.Literals([
29 "repository",
30 "repository_path",
31 "separate",
32]);
33export type SidebarProjectGroupingMode = typeof SidebarProjectGroupingMode.Type;
34export const DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE: SidebarProjectGroupingMode = "repository";
35export const MIN_SIDEBAR_THREAD_PREVIEW_COUNT = 1;
36export const MAX_SIDEBAR_THREAD_PREVIEW_COUNT = 15;
37export const SidebarThreadPreviewCount = Schema.Int.check(
38 Schema.isBetween({
39 minimum: MIN_SIDEBAR_THREAD_PREVIEW_COUNT,
40 maximum: MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
41 }),
42);
43export type SidebarThreadPreviewCount = typeof SidebarThreadPreviewCount.Type;
44export const DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT: SidebarThreadPreviewCount = 6;
45export const MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 1;
46export const MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 90;
47export const SidebarAutoSettleAfterDays = Schema.Number.check(
48 Schema.isBetween({
49 minimum: MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
50 maximum: MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
51 }),
52);
53export type SidebarAutoSettleAfterDays = typeof SidebarAutoSettleAfterDays.Type;
54export const DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS: SidebarAutoSettleAfterDays = 3;
55export const MIN_GLASS_OPACITY = 40;
56export const MAX_GLASS_OPACITY = 100;
57export const GlassOpacity = Schema.Int.check(
58 Schema.isBetween({
59 minimum: MIN_GLASS_OPACITY,
60 maximum: MAX_GLASS_OPACITY,
61 }),
62);
63export type GlassOpacity = typeof GlassOpacity.Type;
64export const DEFAULT_GLASS_OPACITY: GlassOpacity = 80;
65/**
66 * Font size preferences, in CSS pixels. The ranges are deliberately narrow:
67 * the interface size scales every rem-based dimension in the app, so the
68 * bounds keep layouts intact rather than offering unusable extremes.
69 */
70export const MIN_INTERFACE_FONT_SIZE = 12;
71export const MAX_INTERFACE_FONT_SIZE = 20;
72export const InterfaceFontSize = Schema.Int.check(
73 Schema.isBetween({ minimum: MIN_INTERFACE_FONT_SIZE, maximum: MAX_INTERFACE_FONT_SIZE }),
74);
75export type InterfaceFontSize = typeof InterfaceFontSize.Type;
76export const DEFAULT_INTERFACE_FONT_SIZE: InterfaceFontSize = 16;
77
78export const MIN_PROMPT_FONT_SIZE = 12;
79export const MAX_PROMPT_FONT_SIZE = 20;
80export const PromptFontSize = Schema.Int.check(
81 Schema.isBetween({ minimum: MIN_PROMPT_FONT_SIZE, maximum: MAX_PROMPT_FONT_SIZE }),
82);
83export type PromptFontSize = typeof PromptFontSize.Type;
84export const DEFAULT_PROMPT_FONT_SIZE: PromptFontSize = 14;
85
86export const MIN_CODE_FONT_SIZE = 10;
87export const MAX_CODE_FONT_SIZE = 18;
88export const CodeFontSize = Schema.Int.check(
89 Schema.isBetween({ minimum: MIN_CODE_FONT_SIZE, maximum: MAX_CODE_FONT_SIZE }),
90);
91export type CodeFontSize = typeof CodeFontSize.Type;
92export const DEFAULT_CODE_FONT_SIZE: CodeFontSize = 13;
93
94export const MIN_TERMINAL_FONT_SIZE = 8;
95export const MAX_TERMINAL_FONT_SIZE = 20;
96export const TerminalFontSize = Schema.Int.check(
97 Schema.isBetween({ minimum: MIN_TERMINAL_FONT_SIZE, maximum: MAX_TERMINAL_FONT_SIZE }),
98);
99export type TerminalFontSize = typeof TerminalFontSize.Type;
100export const DEFAULT_TERMINAL_FONT_SIZE: TerminalFontSize = 12;
101
102export const EnvironmentIdentificationMode = Schema.Literals(["artwork", "pill", "none"]);
103export type EnvironmentIdentificationMode = typeof EnvironmentIdentificationMode.Type;
104export const DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE: EnvironmentIdentificationMode = "artwork";
105
106/**
107 * A user-chosen font family (a single name or a comma-separated list). Empty
108 * means "use the app default"; clients compose their own fallback stacks.
109 */
110export const FontFamilyPreference = Schema.String.check(Schema.isMaxLength(200));
111export type FontFamilyPreference = typeof FontFamilyPreference.Type;
112
113export const ClientSettingsSchema = Schema.Struct({
114 autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
115 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
116 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
117 dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
118 Schema.withDecodingDefault(Effect.succeed([])),
119 ),
120 diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
121 environmentIdentificationMode: EnvironmentIdentificationMode.pipe(
122 Schema.withDecodingDefault(Effect.succeed(DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE)),
123 ),
124 glassOpacity: GlassOpacity.pipe(
125 Schema.withDecodingDefault(Effect.succeed(DEFAULT_GLASS_OPACITY)),
126 ),
127 fontSizeInterface: InterfaceFontSize.pipe(
128 Schema.withDecodingDefault(Effect.succeed(DEFAULT_INTERFACE_FONT_SIZE)),
129 ),
130 fontSizePrompt: PromptFontSize.pipe(
131 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROMPT_FONT_SIZE)),
132 ),
133 fontSizeCode: CodeFontSize.pipe(
134 Schema.withDecodingDefault(Effect.succeed(DEFAULT_CODE_FONT_SIZE)),
135 ),
136 fontSizeTerminal: TerminalFontSize.pipe(
137 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TERMINAL_FONT_SIZE)),
138 ),
139 fontFamilyCode: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
140 fontFamilyComposer: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
141 fontFamilySans: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
142 fontFamilyTerminal: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
143 // Grayscale `-webkit-font-smoothing: antialiased` (thinner strokes);
144 // disabling restores the platform's heavier default. No effect off macOS.
145 fontSmoothing: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
146 // Model favorites. Historically keyed by provider kind, now
147 // widened to `ProviderInstanceId` so users can favorite a specific model
148 // on a custom provider instance (e.g. "Codex Personal · gpt-5") without
149 // the UI collapsing it into the same bucket as the default Codex. The
150 // widening is backward-compatible by construction: prior provider-kind
151 // strings satisfy the `ProviderInstanceId` slug schema, so previously
152 // persisted favorites decode unchanged and continue to point at the
153 // default instance for their kind (because `defaultInstanceIdForDriver(kind)`
154 // uses the same slug). The field name is kept as `provider` for storage
155 // stability; new call sites should treat the value as an instance id.
156 favorites: Schema.Array(
157 Schema.Struct({
158 provider: ProviderInstanceId,
159 model: TrimmedNonEmptyString,
160 }),
161 ).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
162 providerModelPreferences: Schema.Record(
163 ProviderInstanceId,
164 Schema.Struct({
165 hiddenModels: Schema.Array(Schema.String).pipe(
166 Schema.withDecodingDefault(Effect.succeed([])),
167 ),
168 modelOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
169 }),
170 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
171 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
172 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
173 ),
174 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
175 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
176 ),
177 sidebarProjectGroupingOverrides: Schema.Record(
178 TrimmedNonEmptyString,
179 SidebarProjectGroupingMode,
180 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
181 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
182 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
183 ),
184 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
185 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
186 ),
187 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
188 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
189 ),
190 sidebarV2Enabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
191 // Whether `sidebarV2Enabled` reflects an explicit choice in Settings → Beta.
192 // Client settings persist as a whole blob, so every user who has ever touched
193 // any setting already has `sidebarV2Enabled: false` stored — without this bit
194 // there is no way to tell that apart from "left alone", and a channel-derived
195 // default could never reach them. Mirrors `updateChannelConfiguredByUser`.
196 sidebarV2ConfiguredByUser: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
197 timestampFormat: TimestampFormat.pipe(
198 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
199 ),
200 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
201});
202export type ClientSettings = typeof ClientSettingsSchema.Type;
203
204export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
205
206// ── Server Settings (server-authoritative) ────────────────────
207
208export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
209export type ThreadEnvMode = typeof ThreadEnvMode.Type;
210
211const makeBinaryPathSetting = (fallback: string) =>
212 TrimmedString.pipe(
213 Schema.decodeTo(
214 Schema.String,
215 SchemaTransformation.transformOrFail({
216 decode: (value) => Effect.succeed(value || fallback),
217 encode: (value) => Effect.succeed(value),
218 }),
219 ),
220 Schema.withDecodingDefault(Effect.succeed(fallback)),
221 );
222
223export type ProviderSettingsFormControl = "text" | "password" | "textarea" | "switch";
224
225export interface ProviderSettingsFormAnnotation {
226 readonly control?: ProviderSettingsFormControl | undefined;
227 readonly placeholder?: string | undefined;
228 readonly hidden?: boolean | undefined;
229 readonly clearWhenEmpty?: "omit" | "persist" | undefined;
230}
231
232export interface ProviderSettingsFormSchemaAnnotation {
233 readonly order?: readonly string[] | undefined;
234}
235
236declare module "effect/Schema" {
237 namespace Annotations {
238 interface Annotations {
239 readonly providerSettingsForm?: ProviderSettingsFormAnnotation | undefined;
240 readonly providerSettingsFormSchema?: ProviderSettingsFormSchemaAnnotation | undefined;
241 }
242 }
243}
244
245export type ProviderSettingsOrder<Fields extends Schema.Struct.Fields> = readonly Extract<
246 keyof Fields,
247 string
248>[];
249
250export function makeProviderSettingsSchema<const Fields extends Schema.Struct.Fields>(
251 fields: Fields,
252 options?: {
253 readonly order?: ProviderSettingsOrder<Fields> | undefined;
254 },
255): Schema.Struct<Fields> {
256 return Schema.Struct(fields).pipe(
257 Schema.annotate({
258 providerSettingsFormSchema:
259 options?.order === undefined ? undefined : { order: options.order },
260 }),
261 );
262}
263
264export const CodexSettings = makeProviderSettingsSchema(
265 {
266 enabled: Schema.Boolean.pipe(
267 Schema.withDecodingDefault(Effect.succeed(true)),
268 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
269 ),
270 binaryPath: makeBinaryPathSetting("codex").pipe(
271 Schema.annotateKey({
272 title: "Binary path",
273 description: "Path to the Codex binary used by this instance.",
274 providerSettingsForm: { placeholder: "codex", clearWhenEmpty: "omit" },
275 }),
276 ),
277 homePath: TrimmedString.pipe(
278 Schema.withDecodingDefault(Effect.succeed("")),
279 Schema.annotateKey({
280 title: "CODEX_HOME path",
281 description: "Custom Codex home and config directory.",
282 providerSettingsForm: {
283 placeholder: "~/.codex",
284 clearWhenEmpty: "omit",
285 },
286 }),
287 ),
288 shadowHomePath: TrimmedString.pipe(
289 Schema.withDecodingDefault(Effect.succeed("")),
290 Schema.annotateKey({
291 title: "Shadow home path",
292 description:
293 "Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
294 providerSettingsForm: {
295 placeholder: "~/.codex-t3/personal",
296 clearWhenEmpty: "omit",
297 },
298 }),
299 ),
300 launchArgs: TrimmedString.pipe(
301 Schema.withDecodingDefault(Effect.succeed("")),
302 Schema.annotateKey({
303 title: "Launch arguments",
304 description: "Additional CLI arguments passed to codex app-server on session start.",
305 }),
306 ),
307 customModels: Schema.Array(Schema.String).pipe(
308 Schema.withDecodingDefault(Effect.succeed([])),
309 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
310 ),
311 },
312 {
313 order: ["binaryPath", "homePath", "shadowHomePath", "launchArgs"],
314 },
315);
316export type CodexSettings = typeof CodexSettings.Type;
317
318export const ClaudeSettings = makeProviderSettingsSchema(
319 {
320 enabled: Schema.Boolean.pipe(
321 Schema.withDecodingDefault(Effect.succeed(true)),
322 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
323 ),
324 binaryPath: makeBinaryPathSetting("claude").pipe(
325 Schema.annotateKey({
326 title: "Binary path",
327 description: "Path to the Claude binary used by this instance.",
328 providerSettingsForm: { placeholder: "claude", clearWhenEmpty: "omit" },
329 }),
330 ),
331 homePath: TrimmedString.pipe(
332 Schema.withDecodingDefault(Effect.succeed("")),
333 Schema.annotateKey({
334 title: "CLAUDE_CONFIG_DIR path",
335 description:
336 "Custom Claude home and config directory. Keeps .claude.json and .claude separate.",
337 providerSettingsForm: { placeholder: "~/.claude", clearWhenEmpty: "omit" },
338 }),
339 ),
340 customModels: Schema.Array(Schema.String).pipe(
341 Schema.withDecodingDefault(Effect.succeed([])),
342 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
343 ),
344 launchArgs: Schema.String.pipe(
345 Schema.withDecodingDefault(Effect.succeed("")),
346 Schema.annotateKey({
347 title: "Launch arguments",
348 description: "Additional CLI arguments passed on session start.",
349 providerSettingsForm: {
350 placeholder: "e.g. --chrome",
351 clearWhenEmpty: "omit",
352 },
353 }),
354 ),
355 },
356 {
357 order: ["binaryPath", "homePath", "launchArgs"],
358 },
359);
360export type ClaudeSettings = typeof ClaudeSettings.Type;
361
362export const CursorSettings = makeProviderSettingsSchema(
363 {
364 enabled: Schema.Boolean.pipe(
365 Schema.withDecodingDefault(Effect.succeed(false)),
366 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
367 ),
368 binaryPath: makeBinaryPathSetting("cursor-agent").pipe(
369 Schema.annotateKey({
370 title: "Binary path",
371 description: "Path to the Cursor agent binary.",
372 providerSettingsForm: { placeholder: "cursor-agent", clearWhenEmpty: "omit" },
373 }),
374 ),
375 apiEndpoint: TrimmedString.pipe(
376 Schema.withDecodingDefault(Effect.succeed("")),
377 Schema.annotateKey({
378 title: "API endpoint",
379 description: "Override the Cursor API endpoint for this instance.",
380 providerSettingsForm: {
381 placeholder: "https://...",
382 clearWhenEmpty: "omit",
383 },
384 }),
385 ),
386 customModels: Schema.Array(Schema.String).pipe(
387 Schema.withDecodingDefault(Effect.succeed([])),
388 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
389 ),
390 },
391 {
392 order: ["binaryPath", "apiEndpoint"],
393 },
394);
395export type CursorSettings = typeof CursorSettings.Type;
396
397export const GrokSettings = makeProviderSettingsSchema(
398 {
399 enabled: Schema.Boolean.pipe(
400 Schema.withDecodingDefault(Effect.succeed(true)),
401 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
402 ),
403 binaryPath: makeBinaryPathSetting("grok").pipe(
404 Schema.annotateKey({
405 title: "Binary path",
406 description: "Path to the Grok CLI binary.",
407 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
408 }),
409 ),
410 customModels: Schema.Array(Schema.String).pipe(
411 Schema.withDecodingDefault(Effect.succeed([])),
412 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
413 ),
414 },
415 {
416 order: ["binaryPath"],
417 },
418);
419export type GrokSettings = typeof GrokSettings.Type;
420
421export const OpenCodeSettings = makeProviderSettingsSchema(
422 {
423 enabled: Schema.Boolean.pipe(
424 Schema.withDecodingDefault(Effect.succeed(true)),
425 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
426 ),
427 binaryPath: makeBinaryPathSetting("opencode").pipe(
428 Schema.annotateKey({
429 title: "Binary path",
430 description: "Path to the OpenCode binary.",
431 providerSettingsForm: {
432 placeholder: "opencode",
433 clearWhenEmpty: "omit",
434 },
435 }),
436 ),
437 serverUrl: TrimmedString.pipe(
438 Schema.withDecodingDefault(Effect.succeed("")),
439 Schema.annotateKey({
440 title: "Server URL",
441 description: "Leave blank to let T3 Code spawn the server when needed.",
442 providerSettingsForm: {
443 placeholder: "http://127.0.0.1:4096",
444 clearWhenEmpty: "omit",
445 },
446 }),
447 ),
448 serverPassword: TrimmedString.pipe(
449 Schema.withDecodingDefault(Effect.succeed("")),
450 Schema.annotateKey({
451 title: "Server password",
452 description: "Stored in plain text on disk.",
453 providerSettingsForm: {
454 control: "password",
455 placeholder: "Optional",
456 clearWhenEmpty: "omit",
457 },
458 }),
459 ),
460 customModels: Schema.Array(Schema.String).pipe(
461 Schema.withDecodingDefault(Effect.succeed([])),
462 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
463 ),
464 },
465 {
466 order: ["binaryPath", "serverUrl", "serverPassword"],
467 },
468);
469export type OpenCodeSettings = typeof OpenCodeSettings.Type;
470
471export const ObservabilitySettings = Schema.Struct({
472 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
473 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
474});
475export type ObservabilitySettings = typeof ObservabilitySettings.Type;
476
477export const SourceControlWritingStyleMode = Schema.Literals([
478 "repo_conventions",
479 "conventional_commits",
480 "custom",
481]);
482export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
483
484export const SourceControlWritingStyleSettings = Schema.Struct({
485 mode: SourceControlWritingStyleMode.pipe(
486 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
487 ),
488 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
489 followChangeRequestTemplates: Schema.Boolean.pipe(
490 Schema.withDecodingDefault(Effect.succeed(true)),
491 ),
492});
493export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
494
495export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
496export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
497
498export const BackgroundActivityProfile = Schema.Literals([
499 "balanced",
500 "performance",
501 "battery-saver",
502]);
503export type BackgroundActivityProfile = typeof BackgroundActivityProfile.Type;
504export const DEFAULT_BACKGROUND_ACTIVITY_PROFILE: BackgroundActivityProfile = "balanced";
505
506export const BackgroundActivityProfileSelection = Schema.Literals([
507 "balanced",
508 "performance",
509 "battery-saver",
510 "custom",
511]);
512export type BackgroundActivityProfileSelection = typeof BackgroundActivityProfileSelection.Type;
513
514export const BackgroundActivityOverrides = Schema.Struct({
515 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
516 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
517 hostPowerMonitorActiveInterval: Schema.optionalKey(Schema.DurationFromMillis),
518 hostPowerMonitorIdleInterval: Schema.optionalKey(Schema.DurationFromMillis),
519 idleClientTtl: Schema.optionalKey(Schema.DurationFromMillis),
520 pauseWhenHostLocked: Schema.optionalKey(Schema.Boolean),
521 pauseWhenHostLowPower: Schema.optionalKey(Schema.Boolean),
522 pauseWhenClientLowPower: Schema.optionalKey(Schema.Boolean),
523 pauseWhenOnBattery: Schema.optionalKey(Schema.Boolean),
524});
525export type BackgroundActivityOverrides = typeof BackgroundActivityOverrides.Type;
526
527export const BackgroundActivitySettings = Schema.Struct({
528 schemaVersion: Schema.Literal(1).pipe(Schema.withDecodingDefault(Effect.succeed(1 as const))),
529 profile: BackgroundActivityProfileSelection.pipe(
530 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
531 ),
532 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
533 overrides: BackgroundActivityOverrides.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
534}).pipe(Schema.withDecodingDefault(Effect.succeed({})));
535export type BackgroundActivitySettings = typeof BackgroundActivitySettings.Type;
536
537export const ServerSettings = Schema.Struct({
538 enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
539 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
540 backgroundActivity: BackgroundActivitySettings,
541 // Legacy flat fields retained for old settings files and old clients. New
542 // consumers should resolve `backgroundActivity` instead.
543 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
544 Schema.withDecodingDefault(
545 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
546 ),
547 ),
548 providerHealthRefreshInterval: Schema.DurationFromMillis.pipe(
549 Schema.withDecodingDefault(
550 Effect.succeed(Duration.toMillis(DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL)),
551 ),
552 ),
553 backgroundActivityProfile: BackgroundActivityProfile.pipe(
554 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
555 ),
556 defaultThreadEnvMode: ThreadEnvMode.pipe(
557 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
558 ),
559 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
560 Schema.withDecodingDefault(Effect.succeed(true)),
561 ),
562 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
563 textGenerationModelSelection: ModelSelection.pipe(
564 Schema.withDecodingDefault(
565 Effect.succeed({
566 instanceId: ProviderInstanceId.make("codex"),
567 model: DEFAULT_TEXT_GENERATION_MODEL,
568 options: [
569 {
570 id: "reasoningEffort",
571 value: DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
572 },
573 ],
574 }),
575 ),
576 ),
577 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
578 Schema.withDecodingDefault(Effect.succeed({})),
579 ),
580 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
581 Schema.withDecodingDefault(Effect.succeed(null)),
582 ),
583
584 // Legacy single-instance-per-driver settings. Continues to be the source
585 // of truth until `providerInstances` (below) lands per-driver migration
586 // shims and the server starts hydrating instances from it. Driver-specific
587 // schemas live here for the duration of the migration; once each driver
588 // owns its config in its own package, this struct shrinks to nothing and
589 // is removed entirely.
590 providers: Schema.Struct({
591 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
592 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
593 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
594 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
595 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
596 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
597 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
598 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
599 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
600 // (forks, downgrades, in-flight PR branches) round-trip without loss.
601 // See providerInstance.ts for the forward/backward compatibility invariant.
602 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
603 Schema.withDecodingDefault(Effect.succeed({})),
604 ),
605 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
606});
607export type ServerSettings = typeof ServerSettings.Type;
608
609export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
610
611export const ServerSettingsOperation = Schema.Literals([
612 "normalize",
613 "check-exists",
614 "read-file",
615 "read-secret",
616 "remove-secret",
617 "remove-stale-secret",
618 "write-secret",
619 "write-file",
620 "prepare-directory",
621]);
622export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
623
624export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
625 "ServerSettingsError",
626 {
627 settingsPath: Schema.String,
628 operation: ServerSettingsOperation,
629 providerInstanceId: Schema.optional(Schema.String),
630 environmentVariable: Schema.optional(Schema.String),
631 cause: Schema.Defect(),
632 },
633) {
634 override get message(): string {
635 const provider =
636 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
637 const variable =
638 this.environmentVariable === undefined
639 ? ""
640 : ` and environment variable ${this.environmentVariable}`;
641 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
642 }
643}
644
645// ── Unified type ─────────────────────────────────────────────────────
646
647export type UnifiedSettings = ServerSettings & ClientSettings;
648export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
649 ...DEFAULT_SERVER_SETTINGS,
650 ...DEFAULT_CLIENT_SETTINGS,
651};
652
653// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
654
655const ModelSelectionPatch = Schema.Struct({
656 instanceId: Schema.optionalKey(ProviderInstanceId),
657 model: Schema.optionalKey(TrimmedNonEmptyString),
658 options: Schema.optionalKey(ProviderOptionSelections),
659});
660
661const CodexSettingsPatch = Schema.Struct({
662 enabled: Schema.optionalKey(Schema.Boolean),
663 binaryPath: Schema.optionalKey(TrimmedString),
664 homePath: Schema.optionalKey(TrimmedString),
665 shadowHomePath: Schema.optionalKey(TrimmedString),
666 launchArgs: Schema.optionalKey(TrimmedString),
667 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
668});
669
670const ClaudeSettingsPatch = Schema.Struct({
671 enabled: Schema.optionalKey(Schema.Boolean),
672 binaryPath: Schema.optionalKey(TrimmedString),
673 homePath: Schema.optionalKey(TrimmedString),
674 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
675 launchArgs: Schema.optionalKey(TrimmedString),
676});
677
678const CursorSettingsPatch = Schema.Struct({
679 enabled: Schema.optionalKey(Schema.Boolean),
680 binaryPath: Schema.optionalKey(TrimmedString),
681 apiEndpoint: Schema.optionalKey(TrimmedString),
682 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
683});
684
685const GrokSettingsPatch = Schema.Struct({
686 enabled: Schema.optionalKey(Schema.Boolean),
687 binaryPath: Schema.optionalKey(TrimmedString),
688 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
689});
690
691const OpenCodeSettingsPatch = Schema.Struct({
692 enabled: Schema.optionalKey(Schema.Boolean),
693 binaryPath: Schema.optionalKey(TrimmedString),
694 serverUrl: Schema.optionalKey(TrimmedString),
695 serverPassword: Schema.optionalKey(TrimmedString),
696 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
697});
698
699export const ServerSettingsPatch = Schema.Struct({
700 // Server settings
701 enableAssistantStreaming: Schema.optionalKey(Schema.Boolean),
702 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
703 backgroundActivity: Schema.optionalKey(
704 Schema.Struct({
705 schemaVersion: Schema.optionalKey(Schema.Literal(1)),
706 profile: Schema.optionalKey(BackgroundActivityProfileSelection),
707 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
708 overrides: Schema.optionalKey(BackgroundActivityOverrides),
709 }),
710 ),
711 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
712 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
713 backgroundActivityProfile: Schema.optionalKey(BackgroundActivityProfile),
714 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
715 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
716 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
717 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
718 sourceControlWritingStyle: Schema.optionalKey(
719 Schema.Struct({
720 mode: Schema.optionalKey(SourceControlWritingStyleMode),
721 customInstructions: Schema.optionalKey(TrimmedString),
722 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
723 }),
724 ),
725 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
726 observability: Schema.optionalKey(
727 Schema.Struct({
728 otlpTracesUrl: Schema.optionalKey(TrimmedString),
729 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
730 }),
731 ),
732 providers: Schema.optionalKey(
733 Schema.Struct({
734 codex: Schema.optionalKey(CodexSettingsPatch),
735 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
736 cursor: Schema.optionalKey(CursorSettingsPatch),
737 grok: Schema.optionalKey(GrokSettingsPatch),
738 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
739 }),
740 ),
741 // Whole-map replacement for the new instance config. Patching individual
742 // entries is intentionally out of scope: the map is small, and partial
743 // patches risk leaving driver-specific config in a half-merged state.
744 // The web UI sends a fully-formed map every time it edits this field.
745 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
746});
747export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
748
749export const ClientSettingsPatch = Schema.Struct({
750 autoOpenPlanSidebar: Schema.optionalKey(Schema.Boolean),
751 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
752 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
753 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
754 environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
755 glassOpacity: Schema.optionalKey(GlassOpacity),
756 fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
757 fontSizePrompt: Schema.optionalKey(PromptFontSize),
758 fontSizeCode: Schema.optionalKey(CodeFontSize),
759 fontSizeTerminal: Schema.optionalKey(TerminalFontSize),
760 fontFamilyCode: Schema.optionalKey(FontFamilyPreference),
761 fontFamilyComposer: Schema.optionalKey(FontFamilyPreference),
762 fontFamilySans: Schema.optionalKey(FontFamilyPreference),
763 fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
764 fontSmoothing: Schema.optionalKey(Schema.Boolean),
765 favorites: Schema.optionalKey(
766 Schema.Array(
767 Schema.Struct({
768 provider: ProviderInstanceId,
769 model: TrimmedNonEmptyString,
770 }),
771 ),
772 ),
773 providerModelPreferences: Schema.optionalKey(
774 Schema.Record(
775 ProviderInstanceId,
776 Schema.Struct({
777 hiddenModels: Schema.Array(Schema.String).pipe(
778 Schema.withDecodingDefault(Effect.succeed([])),
779 ),
780 modelOrder: Schema.Array(Schema.String).pipe(
781 Schema.withDecodingDefault(Effect.succeed([])),
782 ),
783 }),
784 ),
785 ),
786 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
787 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
788 sidebarProjectGroupingOverrides: Schema.optionalKey(
789 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
790 ),
791 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
792 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
793 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
794 sidebarV2Enabled: Schema.optionalKey(Schema.Boolean),
795 sidebarV2ConfiguredByUser: Schema.optionalKey(Schema.Boolean),
796 timestampFormat: Schema.optionalKey(TimestampFormat),
797 wordWrap: Schema.optionalKey(Schema.Boolean),
798});
799export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;