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 "./orchestration.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;
61
62export const ClientSettingsSchema = Schema.Struct({
63 autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
64 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
65 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
66 dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
67 Schema.withDecodingDefault(Effect.succeed([])),
68 ),
69 diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
70 glassOpacity: GlassOpacity.pipe(
71 Schema.withDecodingDefault(Effect.succeed(DEFAULT_GLASS_OPACITY)),
72 ),
73 // Model favorites. Historically keyed by provider kind, now
74 // widened to `ProviderInstanceId` so users can favorite a specific model
75 // on a custom provider instance (e.g. "Codex Personal · gpt-5") without
76 // the UI collapsing it into the same bucket as the default Codex. The
77 // widening is backward-compatible by construction: prior provider-kind
78 // strings satisfy the `ProviderInstanceId` slug schema, so previously
79 // persisted favorites decode unchanged and continue to point at the
80 // default instance for their kind (because `defaultInstanceIdForDriver(kind)`
81 // uses the same slug). The field name is kept as `provider` for storage
82 // stability; new call sites should treat the value as an instance id.
83 favorites: Schema.Array(
84 Schema.Struct({
85 provider: ProviderInstanceId,
86 model: TrimmedNonEmptyString,
87 }),
88 ).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
89 providerModelPreferences: Schema.Record(
90 ProviderInstanceId,
91 Schema.Struct({
92 hiddenModels: Schema.Array(Schema.String).pipe(
93 Schema.withDecodingDefault(Effect.succeed([])),
94 ),
95 modelOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
96 }),
97 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
98 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
99 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
100 ),
101 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
102 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
103 ),
104 sidebarProjectGroupingOverrides: Schema.Record(
105 TrimmedNonEmptyString,
106 SidebarProjectGroupingMode,
107 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
108 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
109 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
110 ),
111 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
112 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
113 ),
114 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
115 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
116 ),
117 sidebarV2Enabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
118 timestampFormat: TimestampFormat.pipe(
119 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
120 ),
121 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
122});
123export type ClientSettings = typeof ClientSettingsSchema.Type;
124
125export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
126
127// ── Server Settings (server-authoritative) ────────────────────
128
129export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
130export type ThreadEnvMode = typeof ThreadEnvMode.Type;
131
132const makeBinaryPathSetting = (fallback: string) =>
133 TrimmedString.pipe(
134 Schema.decodeTo(
135 Schema.String,
136 SchemaTransformation.transformOrFail({
137 decode: (value) => Effect.succeed(value || fallback),
138 encode: (value) => Effect.succeed(value),
139 }),
140 ),
141 Schema.withDecodingDefault(Effect.succeed(fallback)),
142 );
143
144export type ProviderSettingsFormControl = "text" | "password" | "textarea" | "switch";
145
146export interface ProviderSettingsFormAnnotation {
147 readonly control?: ProviderSettingsFormControl | undefined;
148 readonly placeholder?: string | undefined;
149 readonly hidden?: boolean | undefined;
150 readonly clearWhenEmpty?: "omit" | "persist" | undefined;
151}
152
153export interface ProviderSettingsFormSchemaAnnotation {
154 readonly order?: readonly string[] | undefined;
155}
156
157declare module "effect/Schema" {
158 namespace Annotations {
159 interface Annotations {
160 readonly providerSettingsForm?: ProviderSettingsFormAnnotation | undefined;
161 readonly providerSettingsFormSchema?: ProviderSettingsFormSchemaAnnotation | undefined;
162 }
163 }
164}
165
166export type ProviderSettingsOrder<Fields extends Schema.Struct.Fields> = readonly Extract<
167 keyof Fields,
168 string
169>[];
170
171export function makeProviderSettingsSchema<const Fields extends Schema.Struct.Fields>(
172 fields: Fields,
173 options?: {
174 readonly order?: ProviderSettingsOrder<Fields> | undefined;
175 },
176): Schema.Struct<Fields> {
177 return Schema.Struct(fields).pipe(
178 Schema.annotate({
179 providerSettingsFormSchema:
180 options?.order === undefined ? undefined : { order: options.order },
181 }),
182 );
183}
184
185export const CodexSettings = makeProviderSettingsSchema(
186 {
187 enabled: Schema.Boolean.pipe(
188 Schema.withDecodingDefault(Effect.succeed(true)),
189 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
190 ),
191 binaryPath: makeBinaryPathSetting("codex").pipe(
192 Schema.annotateKey({
193 title: "Binary path",
194 description: "Path to the Codex binary used by this instance.",
195 providerSettingsForm: { placeholder: "codex", clearWhenEmpty: "omit" },
196 }),
197 ),
198 homePath: TrimmedString.pipe(
199 Schema.withDecodingDefault(Effect.succeed("")),
200 Schema.annotateKey({
201 title: "CODEX_HOME path",
202 description: "Custom Codex home and config directory.",
203 providerSettingsForm: {
204 placeholder: "~/.codex",
205 clearWhenEmpty: "omit",
206 },
207 }),
208 ),
209 shadowHomePath: TrimmedString.pipe(
210 Schema.withDecodingDefault(Effect.succeed("")),
211 Schema.annotateKey({
212 title: "Shadow home path",
213 description:
214 "Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
215 providerSettingsForm: {
216 placeholder: "~/.codex-t3/personal",
217 clearWhenEmpty: "omit",
218 },
219 }),
220 ),
221 launchArgs: TrimmedString.pipe(
222 Schema.withDecodingDefault(Effect.succeed("")),
223 Schema.annotateKey({
224 title: "Launch arguments",
225 description: "Additional CLI arguments passed to codex app-server on session start.",
226 }),
227 ),
228 customModels: Schema.Array(Schema.String).pipe(
229 Schema.withDecodingDefault(Effect.succeed([])),
230 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
231 ),
232 },
233 {
234 order: ["binaryPath", "homePath", "shadowHomePath", "launchArgs"],
235 },
236);
237export type CodexSettings = typeof CodexSettings.Type;
238
239export const ClaudeSettings = makeProviderSettingsSchema(
240 {
241 enabled: Schema.Boolean.pipe(
242 Schema.withDecodingDefault(Effect.succeed(true)),
243 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
244 ),
245 binaryPath: makeBinaryPathSetting("claude").pipe(
246 Schema.annotateKey({
247 title: "Binary path",
248 description: "Path to the Claude binary used by this instance.",
249 providerSettingsForm: { placeholder: "claude", clearWhenEmpty: "omit" },
250 }),
251 ),
252 homePath: TrimmedString.pipe(
253 Schema.withDecodingDefault(Effect.succeed("")),
254 Schema.annotateKey({
255 title: "CLAUDE_CONFIG_DIR path",
256 description:
257 "Custom Claude home and config directory. Keeps .claude.json and .claude separate.",
258 providerSettingsForm: { placeholder: "~/.claude", clearWhenEmpty: "omit" },
259 }),
260 ),
261 customModels: Schema.Array(Schema.String).pipe(
262 Schema.withDecodingDefault(Effect.succeed([])),
263 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
264 ),
265 launchArgs: Schema.String.pipe(
266 Schema.withDecodingDefault(Effect.succeed("")),
267 Schema.annotateKey({
268 title: "Launch arguments",
269 description: "Additional CLI arguments passed on session start.",
270 providerSettingsForm: {
271 placeholder: "e.g. --chrome",
272 clearWhenEmpty: "omit",
273 },
274 }),
275 ),
276 },
277 {
278 order: ["binaryPath", "homePath", "launchArgs"],
279 },
280);
281export type ClaudeSettings = typeof ClaudeSettings.Type;
282
283export const CursorSettings = makeProviderSettingsSchema(
284 {
285 enabled: Schema.Boolean.pipe(
286 Schema.withDecodingDefault(Effect.succeed(false)),
287 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
288 ),
289 binaryPath: makeBinaryPathSetting("cursor-agent").pipe(
290 Schema.annotateKey({
291 title: "Binary path",
292 description: "Path to the Cursor agent binary.",
293 providerSettingsForm: { placeholder: "cursor-agent", clearWhenEmpty: "omit" },
294 }),
295 ),
296 apiEndpoint: TrimmedString.pipe(
297 Schema.withDecodingDefault(Effect.succeed("")),
298 Schema.annotateKey({
299 title: "API endpoint",
300 description: "Override the Cursor API endpoint for this instance.",
301 providerSettingsForm: {
302 placeholder: "https://...",
303 clearWhenEmpty: "omit",
304 },
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", "apiEndpoint"],
314 },
315);
316export type CursorSettings = typeof CursorSettings.Type;
317
318export const GrokSettings = makeProviderSettingsSchema(
319 {
320 enabled: Schema.Boolean.pipe(
321 Schema.withDecodingDefault(Effect.succeed(true)),
322 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
323 ),
324 binaryPath: makeBinaryPathSetting("grok").pipe(
325 Schema.annotateKey({
326 title: "Binary path",
327 description: "Path to the Grok CLI binary.",
328 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
329 }),
330 ),
331 customModels: Schema.Array(Schema.String).pipe(
332 Schema.withDecodingDefault(Effect.succeed([])),
333 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
334 ),
335 },
336 {
337 order: ["binaryPath"],
338 },
339);
340export type GrokSettings = typeof GrokSettings.Type;
341
342export const OpenCodeSettings = makeProviderSettingsSchema(
343 {
344 enabled: Schema.Boolean.pipe(
345 Schema.withDecodingDefault(Effect.succeed(true)),
346 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
347 ),
348 binaryPath: makeBinaryPathSetting("opencode").pipe(
349 Schema.annotateKey({
350 title: "Binary path",
351 description: "Path to the OpenCode binary.",
352 providerSettingsForm: {
353 placeholder: "opencode",
354 clearWhenEmpty: "omit",
355 },
356 }),
357 ),
358 serverUrl: TrimmedString.pipe(
359 Schema.withDecodingDefault(Effect.succeed("")),
360 Schema.annotateKey({
361 title: "Server URL",
362 description: "Leave blank to let T3 Code spawn the server when needed.",
363 providerSettingsForm: {
364 placeholder: "http://127.0.0.1:4096",
365 clearWhenEmpty: "omit",
366 },
367 }),
368 ),
369 serverPassword: TrimmedString.pipe(
370 Schema.withDecodingDefault(Effect.succeed("")),
371 Schema.annotateKey({
372 title: "Server password",
373 description: "Stored in plain text on disk.",
374 providerSettingsForm: {
375 control: "password",
376 placeholder: "Optional",
377 clearWhenEmpty: "omit",
378 },
379 }),
380 ),
381 customModels: Schema.Array(Schema.String).pipe(
382 Schema.withDecodingDefault(Effect.succeed([])),
383 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
384 ),
385 },
386 {
387 order: ["binaryPath", "serverUrl", "serverPassword"],
388 },
389);
390export type OpenCodeSettings = typeof OpenCodeSettings.Type;
391
392export const ObservabilitySettings = Schema.Struct({
393 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
394 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
395});
396export type ObservabilitySettings = typeof ObservabilitySettings.Type;
397
398export const SourceControlWritingStyleMode = Schema.Literals([
399 "repo_conventions",
400 "conventional_commits",
401 "custom",
402]);
403export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
404
405export const SourceControlWritingStyleSettings = Schema.Struct({
406 mode: SourceControlWritingStyleMode.pipe(
407 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
408 ),
409 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
410 followChangeRequestTemplates: Schema.Boolean.pipe(
411 Schema.withDecodingDefault(Effect.succeed(true)),
412 ),
413});
414export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
415
416export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
417
418export const ServerSettings = Schema.Struct({
419 enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
420 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
421 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
422 Schema.withDecodingDefault(
423 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
424 ),
425 ),
426 defaultThreadEnvMode: ThreadEnvMode.pipe(
427 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
428 ),
429 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
430 Schema.withDecodingDefault(Effect.succeed(true)),
431 ),
432 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
433 textGenerationModelSelection: ModelSelection.pipe(
434 Schema.withDecodingDefault(
435 Effect.succeed({
436 instanceId: ProviderInstanceId.make("codex"),
437 model: DEFAULT_TEXT_GENERATION_MODEL,
438 }),
439 ),
440 ),
441 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
442 Schema.withDecodingDefault(Effect.succeed({})),
443 ),
444 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
445 Schema.withDecodingDefault(Effect.succeed(null)),
446 ),
447
448 // Legacy single-instance-per-driver settings. Continues to be the source
449 // of truth until `providerInstances` (below) lands per-driver migration
450 // shims and the server starts hydrating instances from it. Driver-specific
451 // schemas live here for the duration of the migration; once each driver
452 // owns its config in its own package, this struct shrinks to nothing and
453 // is removed entirely.
454 providers: Schema.Struct({
455 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
456 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
457 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
458 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
459 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
460 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
461 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
462 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
463 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
464 // (forks, downgrades, in-flight PR branches) round-trip without loss.
465 // See providerInstance.ts for the forward/backward compatibility invariant.
466 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
467 Schema.withDecodingDefault(Effect.succeed({})),
468 ),
469 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
470});
471export type ServerSettings = typeof ServerSettings.Type;
472
473export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
474
475export const ServerSettingsOperation = Schema.Literals([
476 "normalize",
477 "check-exists",
478 "read-file",
479 "read-secret",
480 "remove-secret",
481 "remove-stale-secret",
482 "write-secret",
483 "write-file",
484 "prepare-directory",
485]);
486export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
487
488export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
489 "ServerSettingsError",
490 {
491 settingsPath: Schema.String,
492 operation: ServerSettingsOperation,
493 providerInstanceId: Schema.optional(Schema.String),
494 environmentVariable: Schema.optional(Schema.String),
495 cause: Schema.Defect(),
496 },
497) {
498 override get message(): string {
499 const provider =
500 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
501 const variable =
502 this.environmentVariable === undefined
503 ? ""
504 : ` and environment variable ${this.environmentVariable}`;
505 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
506 }
507}
508
509// ── Unified type ─────────────────────────────────────────────────────
510
511export type UnifiedSettings = ServerSettings & ClientSettings;
512export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
513 ...DEFAULT_SERVER_SETTINGS,
514 ...DEFAULT_CLIENT_SETTINGS,
515};
516
517// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
518
519const ModelSelectionPatch = Schema.Struct({
520 instanceId: Schema.optionalKey(ProviderInstanceId),
521 model: Schema.optionalKey(TrimmedNonEmptyString),
522 options: Schema.optionalKey(ProviderOptionSelections),
523});
524
525const CodexSettingsPatch = Schema.Struct({
526 enabled: Schema.optionalKey(Schema.Boolean),
527 binaryPath: Schema.optionalKey(TrimmedString),
528 homePath: Schema.optionalKey(TrimmedString),
529 shadowHomePath: Schema.optionalKey(TrimmedString),
530 launchArgs: Schema.optionalKey(TrimmedString),
531 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
532});
533
534const ClaudeSettingsPatch = Schema.Struct({
535 enabled: Schema.optionalKey(Schema.Boolean),
536 binaryPath: Schema.optionalKey(TrimmedString),
537 homePath: Schema.optionalKey(TrimmedString),
538 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
539 launchArgs: Schema.optionalKey(TrimmedString),
540});
541
542const CursorSettingsPatch = Schema.Struct({
543 enabled: Schema.optionalKey(Schema.Boolean),
544 binaryPath: Schema.optionalKey(TrimmedString),
545 apiEndpoint: Schema.optionalKey(TrimmedString),
546 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
547});
548
549const GrokSettingsPatch = Schema.Struct({
550 enabled: Schema.optionalKey(Schema.Boolean),
551 binaryPath: Schema.optionalKey(TrimmedString),
552 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
553});
554
555const OpenCodeSettingsPatch = Schema.Struct({
556 enabled: Schema.optionalKey(Schema.Boolean),
557 binaryPath: Schema.optionalKey(TrimmedString),
558 serverUrl: Schema.optionalKey(TrimmedString),
559 serverPassword: Schema.optionalKey(TrimmedString),
560 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
561});
562
563export const ServerSettingsPatch = Schema.Struct({
564 // Server settings
565 enableAssistantStreaming: Schema.optionalKey(Schema.Boolean),
566 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
567 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
568 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
569 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
570 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
571 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
572 sourceControlWritingStyle: Schema.optionalKey(
573 Schema.Struct({
574 mode: Schema.optionalKey(SourceControlWritingStyleMode),
575 customInstructions: Schema.optionalKey(TrimmedString),
576 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
577 }),
578 ),
579 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
580 observability: Schema.optionalKey(
581 Schema.Struct({
582 otlpTracesUrl: Schema.optionalKey(TrimmedString),
583 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
584 }),
585 ),
586 providers: Schema.optionalKey(
587 Schema.Struct({
588 codex: Schema.optionalKey(CodexSettingsPatch),
589 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
590 cursor: Schema.optionalKey(CursorSettingsPatch),
591 grok: Schema.optionalKey(GrokSettingsPatch),
592 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
593 }),
594 ),
595 // Whole-map replacement for the new instance config. Patching individual
596 // entries is intentionally out of scope: the map is small, and partial
597 // patches risk leaving driver-specific config in a half-merged state.
598 // The web UI sends a fully-formed map every time it edits this field.
599 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
600});
601export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
602
603export const ClientSettingsPatch = Schema.Struct({
604 autoOpenPlanSidebar: Schema.optionalKey(Schema.Boolean),
605 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
606 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
607 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
608 glassOpacity: Schema.optionalKey(GlassOpacity),
609 favorites: Schema.optionalKey(
610 Schema.Array(
611 Schema.Struct({
612 provider: ProviderInstanceId,
613 model: TrimmedNonEmptyString,
614 }),
615 ),
616 ),
617 providerModelPreferences: Schema.optionalKey(
618 Schema.Record(
619 ProviderInstanceId,
620 Schema.Struct({
621 hiddenModels: Schema.Array(Schema.String).pipe(
622 Schema.withDecodingDefault(Effect.succeed([])),
623 ),
624 modelOrder: Schema.Array(Schema.String).pipe(
625 Schema.withDecodingDefault(Effect.succeed([])),
626 ),
627 }),
628 ),
629 ),
630 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
631 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
632 sidebarProjectGroupingOverrides: Schema.optionalKey(
633 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
634 ),
635 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
636 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
637 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
638 sidebarV2Enabled: Schema.optionalKey(Schema.Boolean),
639 timestampFormat: Schema.optionalKey(TimestampFormat),
640 wordWrap: Schema.optionalKey(Schema.Boolean),
641});
642export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;