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 "./modelSelection.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 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
115 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
116 dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
117 Schema.withDecodingDefault(Effect.succeed([])),
118 ),
119 diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
120 environmentIdentificationMode: EnvironmentIdentificationMode.pipe(
121 Schema.withDecodingDefault(Effect.succeed(DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE)),
122 ),
123 glassOpacity: GlassOpacity.pipe(
124 Schema.withDecodingDefault(Effect.succeed(DEFAULT_GLASS_OPACITY)),
125 ),
126 enableCua: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
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 persistComposerContextStrip: Schema.Boolean.pipe(
147 Schema.withDecodingDefault(Effect.succeed(false)),
148 ),
149 // Model favorites. Historically keyed by provider kind, now
150 // widened to `ProviderInstanceId` so users can favorite a specific model
151 // on a custom provider instance (e.g. "Codex Personal · gpt-5") without
152 // the UI collapsing it into the same bucket as the default Codex. The
153 // widening is backward-compatible by construction: prior provider-kind
154 // strings satisfy the `ProviderInstanceId` slug schema, so previously
155 // persisted favorites decode unchanged and continue to point at the
156 // default instance for their kind (because `defaultInstanceIdForDriver(kind)`
157 // uses the same slug). The field name is kept as `provider` for storage
158 // stability; new call sites should treat the value as an instance id.
159 favorites: Schema.Array(
160 Schema.Struct({
161 provider: ProviderInstanceId,
162 model: TrimmedNonEmptyString,
163 }),
164 ).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
165 providerModelPreferences: Schema.Record(
166 ProviderInstanceId,
167 Schema.Struct({
168 hiddenModels: Schema.Array(Schema.String).pipe(
169 Schema.withDecodingDefault(Effect.succeed([])),
170 ),
171 modelOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
172 }),
173 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
174 // Legacy plan mode. The composer's Build/Plan toggle was removed from the
175 // default UI; this beta flag restores it (plus the /plan and /default slash
176 // commands) for users who still rely on the old workflow.
177 planModeEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
178 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
179 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
180 ),
181 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
182 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
183 ),
184 sidebarProjectGroupingOverrides: Schema.Record(
185 TrimmedNonEmptyString,
186 SidebarProjectGroupingMode,
187 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
188 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
189 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
190 ),
191 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
192 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
193 ),
194 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
195 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
196 ),
197 sidebarV2Enabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
198 // Whether `sidebarV2Enabled` reflects an explicit choice in Settings → Beta.
199 // Client settings persist as a whole blob, so every user who has ever touched
200 // any setting already has `sidebarV2Enabled: false` stored — without this bit
201 // there is no way to tell that apart from "left alone", and a channel-derived
202 // default could never reach them. Mirrors `updateChannelConfiguredByUser`.
203 sidebarV2ConfiguredByUser: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
204 timestampFormat: TimestampFormat.pipe(
205 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
206 ),
207 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
208});
209export type ClientSettings = typeof ClientSettingsSchema.Type;
210
211export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
212
213// ── Server Settings (server-authoritative) ────────────────────
214
215export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
216export type ThreadEnvMode = typeof ThreadEnvMode.Type;
217
218const makeBinaryPathSetting = (fallback: string) =>
219 TrimmedString.pipe(
220 Schema.decodeTo(
221 Schema.String,
222 SchemaTransformation.transformOrFail({
223 decode: (value) => Effect.succeed(value || fallback),
224 encode: (value) => Effect.succeed(value),
225 }),
226 ),
227 Schema.withDecodingDefault(Effect.succeed(fallback)),
228 );
229
230export type ProviderSettingsFormControl = "text" | "password" | "textarea" | "switch";
231
232export interface ProviderSettingsFormAnnotation {
233 readonly control?: ProviderSettingsFormControl | undefined;
234 readonly placeholder?: string | undefined;
235 readonly hidden?: boolean | undefined;
236 readonly clearWhenEmpty?: "omit" | "persist" | undefined;
237}
238
239export interface ProviderSettingsFormSchemaAnnotation {
240 readonly order?: readonly string[] | undefined;
241}
242
243declare module "effect/Schema" {
244 namespace Annotations {
245 interface Annotations {
246 readonly providerSettingsForm?: ProviderSettingsFormAnnotation | undefined;
247 readonly providerSettingsFormSchema?: ProviderSettingsFormSchemaAnnotation | undefined;
248 }
249 }
250}
251
252export type ProviderSettingsOrder<Fields extends Schema.Struct.Fields> = readonly Extract<
253 keyof Fields,
254 string
255>[];
256
257export function makeProviderSettingsSchema<const Fields extends Schema.Struct.Fields>(
258 fields: Fields,
259 options?: {
260 readonly order?: ProviderSettingsOrder<Fields> | undefined;
261 },
262): Schema.Struct<Fields> {
263 return Schema.Struct(fields).pipe(
264 Schema.annotate({
265 providerSettingsFormSchema:
266 options?.order === undefined ? undefined : { order: options.order },
267 }),
268 );
269}
270
271export const CodexSettings = makeProviderSettingsSchema(
272 {
273 enabled: Schema.Boolean.pipe(
274 Schema.withDecodingDefault(Effect.succeed(true)),
275 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
276 ),
277 binaryPath: makeBinaryPathSetting("codex").pipe(
278 Schema.annotateKey({
279 title: "Binary path",
280 description: "Path to the Codex binary used by this instance.",
281 providerSettingsForm: { placeholder: "codex", clearWhenEmpty: "omit" },
282 }),
283 ),
284 homePath: TrimmedString.pipe(
285 Schema.withDecodingDefault(Effect.succeed("")),
286 Schema.annotateKey({
287 title: "CODEX_HOME path",
288 description: "Custom Codex home and config directory.",
289 providerSettingsForm: {
290 placeholder: "~/.codex",
291 clearWhenEmpty: "omit",
292 },
293 }),
294 ),
295 shadowHomePath: TrimmedString.pipe(
296 Schema.withDecodingDefault(Effect.succeed("")),
297 Schema.annotateKey({
298 title: "Shadow home path",
299 description:
300 "Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
301 providerSettingsForm: {
302 placeholder: "~/.codex-t3/personal",
303 clearWhenEmpty: "omit",
304 },
305 }),
306 ),
307 launchArgs: TrimmedString.pipe(
308 Schema.withDecodingDefault(Effect.succeed("")),
309 Schema.annotateKey({
310 title: "Launch arguments",
311 description: "Additional CLI arguments passed to codex app-server on session start.",
312 }),
313 ),
314 customModels: Schema.Array(Schema.String).pipe(
315 Schema.withDecodingDefault(Effect.succeed([])),
316 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
317 ),
318 },
319 {
320 order: ["binaryPath", "homePath", "shadowHomePath", "launchArgs"],
321 },
322);
323export type CodexSettings = typeof CodexSettings.Type;
324
325export const ClaudeSettings = makeProviderSettingsSchema(
326 {
327 enabled: Schema.Boolean.pipe(
328 Schema.withDecodingDefault(Effect.succeed(true)),
329 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
330 ),
331 binaryPath: makeBinaryPathSetting("claude").pipe(
332 Schema.annotateKey({
333 title: "Binary path",
334 description: "Path to the Claude binary used by this instance.",
335 providerSettingsForm: { placeholder: "claude", clearWhenEmpty: "omit" },
336 }),
337 ),
338 homePath: TrimmedString.pipe(
339 Schema.withDecodingDefault(Effect.succeed("")),
340 Schema.annotateKey({
341 title: "CLAUDE_CONFIG_DIR path",
342 description:
343 "Custom Claude home and config directory. Keeps .claude.json and .claude separate.",
344 providerSettingsForm: { placeholder: "~/.claude", clearWhenEmpty: "omit" },
345 }),
346 ),
347 customModels: Schema.Array(Schema.String).pipe(
348 Schema.withDecodingDefault(Effect.succeed([])),
349 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
350 ),
351 launchArgs: Schema.String.pipe(
352 Schema.withDecodingDefault(Effect.succeed("")),
353 Schema.annotateKey({
354 title: "Launch arguments",
355 description: "Additional CLI arguments passed on session start.",
356 providerSettingsForm: {
357 placeholder: "e.g. --chrome",
358 clearWhenEmpty: "omit",
359 },
360 }),
361 ),
362 },
363 {
364 order: ["binaryPath", "homePath", "launchArgs"],
365 },
366);
367export type ClaudeSettings = typeof ClaudeSettings.Type;
368
369export const CursorSettings = makeProviderSettingsSchema(
370 {
371 enabled: Schema.Boolean.pipe(
372 Schema.withDecodingDefault(Effect.succeed(false)),
373 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
374 ),
375 customModels: Schema.Array(Schema.String).pipe(
376 Schema.withDecodingDefault(Effect.succeed([])),
377 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
378 ),
379 },
380 {
381 order: [],
382 },
383);
384export type CursorSettings = typeof CursorSettings.Type;
385
386export const GrokSettings = makeProviderSettingsSchema(
387 {
388 enabled: Schema.Boolean.pipe(
389 Schema.withDecodingDefault(Effect.succeed(true)),
390 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
391 ),
392 binaryPath: makeBinaryPathSetting("grok").pipe(
393 Schema.annotateKey({
394 title: "Binary path",
395 description: "Path to the Grok CLI binary.",
396 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
397 }),
398 ),
399 customModels: Schema.Array(Schema.String).pipe(
400 Schema.withDecodingDefault(Effect.succeed([])),
401 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
402 ),
403 },
404 {
405 order: ["binaryPath"],
406 },
407);
408export type GrokSettings = typeof GrokSettings.Type;
409
410export const AcpRegistryDistributionPreference = Schema.Literals(["auto", "binary", "npx", "uvx"]);
411export type AcpRegistryDistributionPreference = typeof AcpRegistryDistributionPreference.Type;
412
413export const AcpRegistrySettings = makeProviderSettingsSchema(
414 {
415 enabled: Schema.Boolean.pipe(
416 Schema.withDecodingDefault(Effect.succeed(true)),
417 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
418 ),
419 agentId: TrimmedString.pipe(
420 Schema.withDecodingDefault(Effect.succeed("")),
421 Schema.annotateKey({
422 title: "Registry agent ID",
423 description: "Agent identifier from the official ACP Registry, for example 'devin'.",
424 providerSettingsForm: { placeholder: "devin", clearWhenEmpty: "persist" },
425 }),
426 ),
427 commandPath: TrimmedString.pipe(
428 Schema.withDecodingDefault(Effect.succeed("")),
429 Schema.annotateKey({
430 title: "Executable override",
431 description:
432 "Optional local executable to use instead of installing the registry distribution. Registry arguments and environment are still applied.",
433 providerSettingsForm: { placeholder: "devin", clearWhenEmpty: "omit" },
434 }),
435 ),
436 authMethodId: TrimmedString.pipe(
437 Schema.withDecodingDefault(Effect.succeed("")),
438 Schema.annotateKey({
439 title: "Authentication method",
440 description:
441 "Optional ACP authentication method ID. By default, the first agent-managed method is selected.",
442 providerSettingsForm: { placeholder: "auto", clearWhenEmpty: "omit" },
443 }),
444 ),
445 distribution: AcpRegistryDistributionPreference.pipe(
446 Schema.withDecodingDefault(Effect.succeed("auto")),
447 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
448 ),
449 customModels: Schema.Array(Schema.String).pipe(
450 Schema.withDecodingDefault(Effect.succeed([])),
451 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
452 ),
453 },
454 {
455 order: ["agentId", "commandPath", "authMethodId"],
456 },
457);
458export type AcpRegistrySettings = typeof AcpRegistrySettings.Type;
459
460export const OpenCodeSettings = makeProviderSettingsSchema(
461 {
462 enabled: Schema.Boolean.pipe(
463 Schema.withDecodingDefault(Effect.succeed(true)),
464 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
465 ),
466 binaryPath: makeBinaryPathSetting("opencode").pipe(
467 Schema.annotateKey({
468 title: "Binary path",
469 description: "Path to the OpenCode binary.",
470 providerSettingsForm: {
471 placeholder: "opencode",
472 clearWhenEmpty: "omit",
473 },
474 }),
475 ),
476 serverUrl: TrimmedString.pipe(
477 Schema.withDecodingDefault(Effect.succeed("")),
478 Schema.annotateKey({
479 title: "Server URL",
480 description: "Leave blank to let T3 Code spawn the server when needed.",
481 providerSettingsForm: {
482 placeholder: "http://127.0.0.1:4096",
483 clearWhenEmpty: "omit",
484 },
485 }),
486 ),
487 serverPassword: TrimmedString.pipe(
488 Schema.withDecodingDefault(Effect.succeed("")),
489 Schema.annotateKey({
490 title: "Server password",
491 description: "Stored in plain text on disk.",
492 providerSettingsForm: {
493 control: "password",
494 placeholder: "Optional",
495 clearWhenEmpty: "omit",
496 },
497 }),
498 ),
499 customModels: Schema.Array(Schema.String).pipe(
500 Schema.withDecodingDefault(Effect.succeed([])),
501 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
502 ),
503 },
504 {
505 order: ["binaryPath", "serverUrl", "serverPassword"],
506 },
507);
508export type OpenCodeSettings = typeof OpenCodeSettings.Type;
509
510export const ObservabilitySettings = Schema.Struct({
511 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
512 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
513});
514export type ObservabilitySettings = typeof ObservabilitySettings.Type;
515
516export const SourceControlWritingStyleMode = Schema.Literals([
517 "repo_conventions",
518 "conventional_commits",
519 "custom",
520]);
521export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
522
523export const SourceControlWritingStyleSettings = Schema.Struct({
524 mode: SourceControlWritingStyleMode.pipe(
525 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
526 ),
527 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
528 followChangeRequestTemplates: Schema.Boolean.pipe(
529 Schema.withDecodingDefault(Effect.succeed(true)),
530 ),
531});
532export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
533
534export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
535export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
536
537export const BackgroundActivityProfile = Schema.Literals([
538 "balanced",
539 "performance",
540 "battery-saver",
541]);
542export type BackgroundActivityProfile = typeof BackgroundActivityProfile.Type;
543export const DEFAULT_BACKGROUND_ACTIVITY_PROFILE: BackgroundActivityProfile = "balanced";
544
545export const BackgroundActivityProfileSelection = Schema.Literals([
546 "balanced",
547 "performance",
548 "battery-saver",
549 "custom",
550]);
551export type BackgroundActivityProfileSelection = typeof BackgroundActivityProfileSelection.Type;
552
553export const BackgroundActivityOverrides = Schema.Struct({
554 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
555 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
556 hostPowerMonitorActiveInterval: Schema.optionalKey(Schema.DurationFromMillis),
557 hostPowerMonitorIdleInterval: Schema.optionalKey(Schema.DurationFromMillis),
558 idleClientTtl: Schema.optionalKey(Schema.DurationFromMillis),
559 pauseWhenHostLocked: Schema.optionalKey(Schema.Boolean),
560 pauseWhenHostLowPower: Schema.optionalKey(Schema.Boolean),
561 pauseWhenClientLowPower: Schema.optionalKey(Schema.Boolean),
562 pauseWhenOnBattery: Schema.optionalKey(Schema.Boolean),
563});
564export type BackgroundActivityOverrides = typeof BackgroundActivityOverrides.Type;
565
566export const BackgroundActivitySettings = Schema.Struct({
567 schemaVersion: Schema.Literal(1).pipe(Schema.withDecodingDefault(Effect.succeed(1 as const))),
568 profile: BackgroundActivityProfileSelection.pipe(
569 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
570 ),
571 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
572 overrides: BackgroundActivityOverrides.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
573}).pipe(Schema.withDecodingDefault(Effect.succeed({})));
574export type BackgroundActivitySettings = typeof BackgroundActivitySettings.Type;
575
576export const ServerSettings = Schema.Struct({
577 enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
578 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
579 backgroundActivity: BackgroundActivitySettings,
580 // Legacy flat fields retained for old settings files and old clients. New
581 // consumers should resolve `backgroundActivity` instead.
582 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
583 Schema.withDecodingDefault(
584 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
585 ),
586 ),
587 providerHealthRefreshInterval: Schema.DurationFromMillis.pipe(
588 Schema.withDecodingDefault(
589 Effect.succeed(Duration.toMillis(DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL)),
590 ),
591 ),
592 backgroundActivityProfile: BackgroundActivityProfile.pipe(
593 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
594 ),
595 defaultThreadEnvMode: ThreadEnvMode.pipe(
596 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
597 ),
598 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
599 Schema.withDecodingDefault(Effect.succeed(true)),
600 ),
601 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
602 textGenerationModelSelection: ModelSelection.pipe(
603 Schema.withDecodingDefault(
604 Effect.succeed({
605 instanceId: ProviderInstanceId.make("codex"),
606 model: DEFAULT_TEXT_GENERATION_MODEL,
607 options: [
608 {
609 id: "reasoningEffort",
610 value: DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
611 },
612 ],
613 }),
614 ),
615 ),
616 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
617 Schema.withDecodingDefault(Effect.succeed({})),
618 ),
619 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
620 Schema.withDecodingDefault(Effect.succeed(null)),
621 ),
622
623 // Legacy single-instance-per-driver settings. Continues to be the source
624 // of truth until `providerInstances` (below) lands per-driver migration
625 // shims and the server starts hydrating instances from it. Driver-specific
626 // schemas live here for the duration of the migration; once each driver
627 // owns its config in its own package, this struct shrinks to nothing and
628 // is removed entirely.
629 providers: Schema.Struct({
630 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
631 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
632 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
633 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
634 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
635 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
636 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
637 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
638 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
639 // (forks, downgrades, in-flight PR branches) round-trip without loss.
640 // See providerInstance.ts for the forward/backward compatibility invariant.
641 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
642 Schema.withDecodingDefault(Effect.succeed({})),
643 ),
644 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
645});
646export type ServerSettings = typeof ServerSettings.Type;
647
648export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
649
650export const ServerSettingsOperation = Schema.Literals([
651 "normalize",
652 "check-exists",
653 "read-file",
654 "read-secret",
655 "remove-secret",
656 "remove-stale-secret",
657 "write-secret",
658 "write-file",
659 "prepare-directory",
660]);
661export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
662
663export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
664 "ServerSettingsError",
665 {
666 settingsPath: Schema.String,
667 operation: ServerSettingsOperation,
668 providerInstanceId: Schema.optional(Schema.String),
669 environmentVariable: Schema.optional(Schema.String),
670 cause: Schema.Defect(),
671 },
672) {
673 override get message(): string {
674 const provider =
675 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
676 const variable =
677 this.environmentVariable === undefined
678 ? ""
679 : ` and environment variable ${this.environmentVariable}`;
680 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
681 }
682}
683
684// ── Unified type ─────────────────────────────────────────────────────
685
686export type UnifiedSettings = ServerSettings & ClientSettings;
687export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
688 ...DEFAULT_SERVER_SETTINGS,
689 ...DEFAULT_CLIENT_SETTINGS,
690};
691
692// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
693
694const ModelSelectionPatch = Schema.Struct({
695 instanceId: Schema.optionalKey(ProviderInstanceId),
696 model: Schema.optionalKey(TrimmedNonEmptyString),
697 options: Schema.optionalKey(ProviderOptionSelections),
698});
699
700const CodexSettingsPatch = Schema.Struct({
701 enabled: Schema.optionalKey(Schema.Boolean),
702 binaryPath: Schema.optionalKey(TrimmedString),
703 homePath: Schema.optionalKey(TrimmedString),
704 shadowHomePath: Schema.optionalKey(TrimmedString),
705 launchArgs: Schema.optionalKey(TrimmedString),
706 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
707});
708
709const ClaudeSettingsPatch = Schema.Struct({
710 enabled: Schema.optionalKey(Schema.Boolean),
711 binaryPath: Schema.optionalKey(TrimmedString),
712 homePath: Schema.optionalKey(TrimmedString),
713 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
714 launchArgs: Schema.optionalKey(TrimmedString),
715});
716
717const CursorSettingsPatch = Schema.Struct({
718 enabled: Schema.optionalKey(Schema.Boolean),
719 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
720});
721
722const GrokSettingsPatch = Schema.Struct({
723 enabled: Schema.optionalKey(Schema.Boolean),
724 binaryPath: Schema.optionalKey(TrimmedString),
725 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
726});
727
728const OpenCodeSettingsPatch = Schema.Struct({
729 enabled: Schema.optionalKey(Schema.Boolean),
730 binaryPath: Schema.optionalKey(TrimmedString),
731 serverUrl: Schema.optionalKey(TrimmedString),
732 serverPassword: Schema.optionalKey(TrimmedString),
733 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
734});
735
736export const ServerSettingsPatch = Schema.Struct({
737 // Server settings
738 enableAssistantStreaming: Schema.optionalKey(Schema.Boolean),
739 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
740 backgroundActivity: Schema.optionalKey(
741 Schema.Struct({
742 schemaVersion: Schema.optionalKey(Schema.Literal(1)),
743 profile: Schema.optionalKey(BackgroundActivityProfileSelection),
744 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
745 overrides: Schema.optionalKey(BackgroundActivityOverrides),
746 }),
747 ),
748 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
749 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
750 backgroundActivityProfile: Schema.optionalKey(BackgroundActivityProfile),
751 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
752 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
753 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
754 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
755 sourceControlWritingStyle: Schema.optionalKey(
756 Schema.Struct({
757 mode: Schema.optionalKey(SourceControlWritingStyleMode),
758 customInstructions: Schema.optionalKey(TrimmedString),
759 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
760 }),
761 ),
762 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
763 observability: Schema.optionalKey(
764 Schema.Struct({
765 otlpTracesUrl: Schema.optionalKey(TrimmedString),
766 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
767 }),
768 ),
769 providers: Schema.optionalKey(
770 Schema.Struct({
771 codex: Schema.optionalKey(CodexSettingsPatch),
772 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
773 cursor: Schema.optionalKey(CursorSettingsPatch),
774 grok: Schema.optionalKey(GrokSettingsPatch),
775 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
776 }),
777 ),
778 // Whole-map replacement for the new instance config. Patching individual
779 // entries is intentionally out of scope: the map is small, and partial
780 // patches risk leaving driver-specific config in a half-merged state.
781 // The web UI sends a fully-formed map every time it edits this field.
782 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
783});
784export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
785
786export const ClientSettingsPatch = Schema.Struct({
787 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
788 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
789 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
790 environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
791 enableCua: Schema.optionalKey(Schema.Boolean),
792 glassOpacity: Schema.optionalKey(GlassOpacity),
793 fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
794 fontSizePrompt: Schema.optionalKey(PromptFontSize),
795 fontSizeCode: Schema.optionalKey(CodeFontSize),
796 fontSizeTerminal: Schema.optionalKey(TerminalFontSize),
797 fontFamilyCode: Schema.optionalKey(FontFamilyPreference),
798 fontFamilyComposer: Schema.optionalKey(FontFamilyPreference),
799 fontFamilySans: Schema.optionalKey(FontFamilyPreference),
800 fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
801 fontSmoothing: Schema.optionalKey(Schema.Boolean),
802 persistComposerContextStrip: Schema.optionalKey(Schema.Boolean),
803 favorites: Schema.optionalKey(
804 Schema.Array(
805 Schema.Struct({
806 provider: ProviderInstanceId,
807 model: TrimmedNonEmptyString,
808 }),
809 ),
810 ),
811 providerModelPreferences: Schema.optionalKey(
812 Schema.Record(
813 ProviderInstanceId,
814 Schema.Struct({
815 hiddenModels: Schema.Array(Schema.String).pipe(
816 Schema.withDecodingDefault(Effect.succeed([])),
817 ),
818 modelOrder: Schema.Array(Schema.String).pipe(
819 Schema.withDecodingDefault(Effect.succeed([])),
820 ),
821 }),
822 ),
823 ),
824 planModeEnabled: Schema.optionalKey(Schema.Boolean),
825 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
826 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
827 sidebarProjectGroupingOverrides: Schema.optionalKey(
828 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
829 ),
830 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
831 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
832 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
833 sidebarV2Enabled: Schema.optionalKey(Schema.Boolean),
834 sidebarV2ConfiguredByUser: Schema.optionalKey(Schema.Boolean),
835 timestampFormat: Schema.optionalKey(TimestampFormat),
836 wordWrap: Schema.optionalKey(Schema.Boolean),
837});
838export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;