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