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 { ThreadEnvMode } from "./environment.ts";
7import {
8 DEFAULT_TEXT_GENERATION_MODEL,
9 DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
10 ProviderOptionSelections,
11} from "./model.ts";
12import { ModelSelection } from "./orchestration.ts";
13import { ProviderInstanceConfig, ProviderInstanceId } from "./providerInstance.ts";
14
15// ── Client Settings (local-only) ───────────────────────────────
16
17export const TimestampFormat = Schema.Literals(["locale", "12-hour", "24-hour"]);
18export type TimestampFormat = typeof TimestampFormat.Type;
19export const DEFAULT_TIMESTAMP_FORMAT: TimestampFormat = "locale";
20
21export const SidebarProjectSortOrder = Schema.Literals(["updated_at", "created_at", "manual"]);
22export type SidebarProjectSortOrder = typeof SidebarProjectSortOrder.Type;
23export const DEFAULT_SIDEBAR_PROJECT_SORT_ORDER: SidebarProjectSortOrder = "updated_at";
24
25export const SidebarThreadSortOrder = Schema.Literals(["updated_at", "created_at"]);
26export type SidebarThreadSortOrder = typeof SidebarThreadSortOrder.Type;
27export const DEFAULT_SIDEBAR_THREAD_SORT_ORDER: SidebarThreadSortOrder = "updated_at";
28
29export const SidebarProjectGroupingMode = Schema.Literals([
30 "repository",
31 "repository_path",
32 "separate",
33]);
34export type SidebarProjectGroupingMode = typeof SidebarProjectGroupingMode.Type;
35export const DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE: SidebarProjectGroupingMode = "repository";
36export const MIN_SIDEBAR_THREAD_PREVIEW_COUNT = 1;
37export const MAX_SIDEBAR_THREAD_PREVIEW_COUNT = 15;
38export const SidebarThreadPreviewCount = Schema.Int.check(
39 Schema.isBetween({
40 minimum: MIN_SIDEBAR_THREAD_PREVIEW_COUNT,
41 maximum: MAX_SIDEBAR_THREAD_PREVIEW_COUNT,
42 }),
43);
44export type SidebarThreadPreviewCount = typeof SidebarThreadPreviewCount.Type;
45export const DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT: SidebarThreadPreviewCount = 6;
46export const MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 1;
47export const MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 90;
48export const SidebarAutoSettleAfterDays = Schema.Number.check(
49 Schema.isBetween({
50 minimum: MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
51 maximum: MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
52 }),
53);
54export type SidebarAutoSettleAfterDays = typeof SidebarAutoSettleAfterDays.Type;
55export const DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS: SidebarAutoSettleAfterDays = 3;
56export const MIN_GLASS_OPACITY = 40;
57export const MAX_GLASS_OPACITY = 100;
58export const GlassOpacity = Schema.Int.check(
59 Schema.isBetween({
60 minimum: MIN_GLASS_OPACITY,
61 maximum: MAX_GLASS_OPACITY,
62 }),
63);
64export type GlassOpacity = typeof GlassOpacity.Type;
65export const DEFAULT_GLASS_OPACITY: GlassOpacity = 80;
66/**
67 * Font size preferences, in CSS pixels. The ranges are deliberately narrow:
68 * the interface size scales every rem-based dimension in the app, so the
69 * bounds keep layouts intact rather than offering unusable extremes.
70 */
71export const MIN_INTERFACE_FONT_SIZE = 12;
72export const MAX_INTERFACE_FONT_SIZE = 20;
73export const InterfaceFontSize = Schema.Int.check(
74 Schema.isBetween({ minimum: MIN_INTERFACE_FONT_SIZE, maximum: MAX_INTERFACE_FONT_SIZE }),
75);
76export type InterfaceFontSize = typeof InterfaceFontSize.Type;
77export const DEFAULT_INTERFACE_FONT_SIZE: InterfaceFontSize = 16;
78
79export const MIN_PROMPT_FONT_SIZE = 12;
80export const MAX_PROMPT_FONT_SIZE = 20;
81export const PromptFontSize = Schema.Int.check(
82 Schema.isBetween({ minimum: MIN_PROMPT_FONT_SIZE, maximum: MAX_PROMPT_FONT_SIZE }),
83);
84export type PromptFontSize = typeof PromptFontSize.Type;
85export const DEFAULT_PROMPT_FONT_SIZE: PromptFontSize = 14;
86
87export const MIN_CODE_FONT_SIZE = 10;
88export const MAX_CODE_FONT_SIZE = 18;
89export const CodeFontSize = Schema.Int.check(
90 Schema.isBetween({ minimum: MIN_CODE_FONT_SIZE, maximum: MAX_CODE_FONT_SIZE }),
91);
92export type CodeFontSize = typeof CodeFontSize.Type;
93export const DEFAULT_CODE_FONT_SIZE: CodeFontSize = 13;
94
95export const MIN_TERMINAL_FONT_SIZE = 8;
96export const MAX_TERMINAL_FONT_SIZE = 20;
97export const TerminalFontSize = Schema.Int.check(
98 Schema.isBetween({ minimum: MIN_TERMINAL_FONT_SIZE, maximum: MAX_TERMINAL_FONT_SIZE }),
99);
100export type TerminalFontSize = typeof TerminalFontSize.Type;
101export const DEFAULT_TERMINAL_FONT_SIZE: TerminalFontSize = 12;
102
103export const EnvironmentIdentificationMode = Schema.Literals(["artwork", "pill", "none"]);
104export type EnvironmentIdentificationMode = typeof EnvironmentIdentificationMode.Type;
105export const DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE: EnvironmentIdentificationMode = "artwork";
106
107/**
108 * A user-chosen font family (a single name or a comma-separated list). Empty
109 * means "use the app default"; clients compose their own fallback stacks.
110 */
111export const FontFamilyPreference = Schema.String.check(Schema.isMaxLength(200));
112export type FontFamilyPreference = typeof FontFamilyPreference.Type;
113
114export const ClientSettingsSchema = Schema.Struct({
115 // Desktop-only: require holding the quit shortcut (Cmd/Ctrl+Q) before the
116 // app quits; a quick tap only shows a hint. Browser clients ignore it.
117 confirmQuit: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
118 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
119 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
120 dismissedProviderUpdateNotificationKeys: Schema.Array(TrimmedNonEmptyString).pipe(
121 Schema.withDecodingDefault(Effect.succeed([])),
122 ),
123 diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
124 environmentIdentificationMode: EnvironmentIdentificationMode.pipe(
125 Schema.withDecodingDefault(Effect.succeed(DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE)),
126 ),
127 glassOpacity: GlassOpacity.pipe(
128 Schema.withDecodingDefault(Effect.succeed(DEFAULT_GLASS_OPACITY)),
129 ),
130 fontSizeInterface: InterfaceFontSize.pipe(
131 Schema.withDecodingDefault(Effect.succeed(DEFAULT_INTERFACE_FONT_SIZE)),
132 ),
133 fontSizePrompt: PromptFontSize.pipe(
134 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROMPT_FONT_SIZE)),
135 ),
136 fontSizeCode: CodeFontSize.pipe(
137 Schema.withDecodingDefault(Effect.succeed(DEFAULT_CODE_FONT_SIZE)),
138 ),
139 fontSizeTerminal: TerminalFontSize.pipe(
140 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TERMINAL_FONT_SIZE)),
141 ),
142 fontFamilyCode: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
143 fontFamilyComposer: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
144 fontFamilySans: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
145 fontFamilyTerminal: FontFamilyPreference.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
146 // Grayscale `-webkit-font-smoothing: antialiased` (thinner strokes);
147 // disabling restores the platform's heavier default. No effect off macOS.
148 fontSmoothing: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
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 // Legacy sidebar (the original per-project tree). Deliberately a fresh key
179 // (was `sidebarV2Enabled` + `sidebarV2ConfiguredByUser`): decoding drops the
180 // old keys, so everyone, including prior beta opt-outs, resets to the new
181 // default sidebar.
182 legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
183 sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
184 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
185 ),
186 sidebarAutoSettleOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
187 sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
188 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
189 ),
190 sidebarProjectGroupingOverrides: Schema.Record(
191 TrimmedNonEmptyString,
192 SidebarProjectGroupingMode,
193 ).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
194 sidebarProjectSortOrder: SidebarProjectSortOrder.pipe(
195 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)),
196 ),
197 sidebarThreadSortOrder: SidebarThreadSortOrder.pipe(
198 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_SORT_ORDER)),
199 ),
200 sidebarThreadPreviewCount: SidebarThreadPreviewCount.pipe(
201 Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT)),
202 ),
203 timestampFormat: TimestampFormat.pipe(
204 Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
205 ),
206 wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
207});
208export type ClientSettings = typeof ClientSettingsSchema.Type;
209
210export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientSettingsSchema)({});
211
212// ── Server Settings (server-authoritative) ────────────────────
213
214// Moved to environment.ts so orchestration contracts can use it without an
215// import cycle; re-exported here for compatibility with deep imports.
216export { ThreadEnvMode } from "./environment.ts";
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 binaryPath: makeBinaryPathSetting("cursor-agent").pipe(
376 Schema.annotateKey({
377 title: "Binary path",
378 description: "Path to the Cursor agent binary.",
379 providerSettingsForm: { placeholder: "cursor-agent", clearWhenEmpty: "omit" },
380 }),
381 ),
382 apiEndpoint: TrimmedString.pipe(
383 Schema.withDecodingDefault(Effect.succeed("")),
384 Schema.annotateKey({
385 title: "API endpoint",
386 description: "Override the Cursor API endpoint for this instance.",
387 providerSettingsForm: {
388 placeholder: "https://...",
389 clearWhenEmpty: "omit",
390 },
391 }),
392 ),
393 customModels: Schema.Array(Schema.String).pipe(
394 Schema.withDecodingDefault(Effect.succeed([])),
395 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
396 ),
397 },
398 {
399 order: ["binaryPath", "apiEndpoint"],
400 },
401);
402export type CursorSettings = typeof CursorSettings.Type;
403
404export const GrokSettings = makeProviderSettingsSchema(
405 {
406 enabled: Schema.Boolean.pipe(
407 Schema.withDecodingDefault(Effect.succeed(true)),
408 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
409 ),
410 binaryPath: makeBinaryPathSetting("grok").pipe(
411 Schema.annotateKey({
412 title: "Binary path",
413 description: "Path to the Grok CLI binary.",
414 providerSettingsForm: { placeholder: "grok", clearWhenEmpty: "omit" },
415 }),
416 ),
417 customModels: Schema.Array(Schema.String).pipe(
418 Schema.withDecodingDefault(Effect.succeed([])),
419 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
420 ),
421 },
422 {
423 order: ["binaryPath"],
424 },
425);
426export type GrokSettings = typeof GrokSettings.Type;
427
428export const OpenCodeSettings = makeProviderSettingsSchema(
429 {
430 enabled: Schema.Boolean.pipe(
431 Schema.withDecodingDefault(Effect.succeed(true)),
432 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
433 ),
434 binaryPath: makeBinaryPathSetting("opencode").pipe(
435 Schema.annotateKey({
436 title: "Binary path",
437 description: "Path to the OpenCode binary.",
438 providerSettingsForm: {
439 placeholder: "opencode",
440 clearWhenEmpty: "omit",
441 },
442 }),
443 ),
444 serverUrl: TrimmedString.pipe(
445 Schema.withDecodingDefault(Effect.succeed("")),
446 Schema.annotateKey({
447 title: "Server URL",
448 description: "Leave blank to let T3 Code spawn the server when needed.",
449 providerSettingsForm: {
450 placeholder: "http://127.0.0.1:4096",
451 clearWhenEmpty: "omit",
452 },
453 }),
454 ),
455 serverPassword: TrimmedString.pipe(
456 Schema.withDecodingDefault(Effect.succeed("")),
457 Schema.annotateKey({
458 title: "Server password",
459 description: "Stored in plain text on disk.",
460 providerSettingsForm: {
461 control: "password",
462 placeholder: "Optional",
463 clearWhenEmpty: "omit",
464 },
465 }),
466 ),
467 customModels: Schema.Array(Schema.String).pipe(
468 Schema.withDecodingDefault(Effect.succeed([])),
469 Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
470 ),
471 },
472 {
473 order: ["binaryPath", "serverUrl", "serverPassword"],
474 },
475);
476export type OpenCodeSettings = typeof OpenCodeSettings.Type;
477
478export const ObservabilitySettings = Schema.Struct({
479 otlpTracesUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
480 otlpMetricsUrl: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
481});
482export type ObservabilitySettings = typeof ObservabilitySettings.Type;
483
484export const SourceControlWritingStyleMode = Schema.Literals([
485 "repo_conventions",
486 "conventional_commits",
487 "custom",
488]);
489export type SourceControlWritingStyleMode = typeof SourceControlWritingStyleMode.Type;
490
491export const SourceControlWritingStyleSettings = Schema.Struct({
492 mode: SourceControlWritingStyleMode.pipe(
493 Schema.withDecodingDefault(Effect.succeed("repo_conventions" as const)),
494 ),
495 customInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
496 followChangeRequestTemplates: Schema.Boolean.pipe(
497 Schema.withDecodingDefault(Effect.succeed(true)),
498 ),
499});
500export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
501
502export const DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL = Duration.seconds(30);
503export const DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL = Duration.minutes(5);
504
505export const BackgroundActivityProfile = Schema.Literals([
506 "balanced",
507 "performance",
508 "battery-saver",
509]);
510export type BackgroundActivityProfile = typeof BackgroundActivityProfile.Type;
511export const DEFAULT_BACKGROUND_ACTIVITY_PROFILE: BackgroundActivityProfile = "balanced";
512
513export const BackgroundActivityProfileSelection = Schema.Literals([
514 "balanced",
515 "performance",
516 "battery-saver",
517 "custom",
518]);
519export type BackgroundActivityProfileSelection = typeof BackgroundActivityProfileSelection.Type;
520
521export const BackgroundActivityOverrides = Schema.Struct({
522 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
523 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
524 hostPowerMonitorActiveInterval: Schema.optionalKey(Schema.DurationFromMillis),
525 hostPowerMonitorIdleInterval: Schema.optionalKey(Schema.DurationFromMillis),
526 idleClientTtl: Schema.optionalKey(Schema.DurationFromMillis),
527 pauseWhenHostLocked: Schema.optionalKey(Schema.Boolean),
528 pauseWhenHostLowPower: Schema.optionalKey(Schema.Boolean),
529 pauseWhenClientLowPower: Schema.optionalKey(Schema.Boolean),
530 pauseWhenOnBattery: Schema.optionalKey(Schema.Boolean),
531});
532export type BackgroundActivityOverrides = typeof BackgroundActivityOverrides.Type;
533
534export const BackgroundActivitySettings = Schema.Struct({
535 schemaVersion: Schema.Literal(1).pipe(Schema.withDecodingDefault(Effect.succeed(1 as const))),
536 profile: BackgroundActivityProfileSelection.pipe(
537 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
538 ),
539 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
540 overrides: BackgroundActivityOverrides.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
541}).pipe(Schema.withDecodingDefault(Effect.succeed({})));
542export type BackgroundActivitySettings = typeof BackgroundActivitySettings.Type;
543
544export const ServerSettings = Schema.Struct({
545 // Legacy token-by-token assistant output. Deliberately a fresh key (was
546 // `enableAssistantStreaming`): decoding drops the old key, so everyone,
547 // including prior opt-ins, resets to the buffered default.
548 enableLegacyTokenStreaming: Schema.Boolean.pipe(
549 Schema.withDecodingDefault(Effect.succeed(false)),
550 ),
551 enableProviderUpdateChecks: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
552 backgroundActivity: BackgroundActivitySettings,
553 // Legacy flat fields retained for old settings files and old clients. New
554 // consumers should resolve `backgroundActivity` instead.
555 automaticGitFetchInterval: Schema.DurationFromMillis.pipe(
556 Schema.withDecodingDefault(
557 Effect.succeed(Duration.toMillis(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
558 ),
559 ),
560 providerHealthRefreshInterval: Schema.DurationFromMillis.pipe(
561 Schema.withDecodingDefault(
562 Effect.succeed(Duration.toMillis(DEFAULT_PROVIDER_HEALTH_REFRESH_INTERVAL)),
563 ),
564 ),
565 backgroundActivityProfile: BackgroundActivityProfile.pipe(
566 Schema.withDecodingDefault(Effect.succeed(DEFAULT_BACKGROUND_ACTIVITY_PROFILE)),
567 ),
568 defaultThreadEnvMode: ThreadEnvMode.pipe(
569 Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),
570 ),
571 newWorktreesStartFromOrigin: Schema.Boolean.pipe(
572 Schema.withDecodingDefault(Effect.succeed(true)),
573 ),
574 addProjectBaseDirectory: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
575 textGenerationModelSelection: ModelSelection.pipe(
576 Schema.withDecodingDefault(
577 Effect.succeed({
578 instanceId: ProviderInstanceId.make("codex"),
579 model: DEFAULT_TEXT_GENERATION_MODEL,
580 options: [
581 {
582 id: "reasoningEffort",
583 value: DEFAULT_TEXT_GENERATION_REASONING_EFFORT,
584 },
585 ],
586 }),
587 ),
588 ),
589 sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
590 Schema.withDecodingDefault(Effect.succeed({})),
591 ),
592 sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
593 Schema.withDecodingDefault(Effect.succeed(null)),
594 ),
595
596 // Legacy single-instance-per-driver settings. Continues to be the source
597 // of truth until `providerInstances` (below) lands per-driver migration
598 // shims and the server starts hydrating instances from it. Driver-specific
599 // schemas live here for the duration of the migration; once each driver
600 // owns its config in its own package, this struct shrinks to nothing and
601 // is removed entirely.
602 providers: Schema.Struct({
603 codex: CodexSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
604 claudeAgent: ClaudeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
605 cursor: CursorSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
606 grok: GrokSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
607 opencode: OpenCodeSettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
608 }).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
609 // New driver-agnostic instance map. Keyed by `ProviderInstanceId`; values
610 // are `ProviderInstanceConfig` envelopes. The driver-specific config blob
611 // is `Schema.Unknown` at this layer so envelopes with unknown drivers
612 // (forks, downgrades, in-flight PR branches) round-trip without loss.
613 // See providerInstance.ts for the forward/backward compatibility invariant.
614 providerInstances: Schema.Record(ProviderInstanceId, ProviderInstanceConfig).pipe(
615 Schema.withDecodingDefault(Effect.succeed({})),
616 ),
617 observability: ObservabilitySettings.pipe(Schema.withDecodingDefault(Effect.succeed({}))),
618});
619export type ServerSettings = typeof ServerSettings.Type;
620
621export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
622
623export const ServerSettingsOperation = Schema.Literals([
624 "normalize",
625 "check-exists",
626 "read-file",
627 "read-secret",
628 "remove-secret",
629 "remove-stale-secret",
630 "write-secret",
631 "write-file",
632 "prepare-directory",
633]);
634export type ServerSettingsOperation = typeof ServerSettingsOperation.Type;
635
636export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
637 "ServerSettingsError",
638 {
639 settingsPath: Schema.String,
640 operation: ServerSettingsOperation,
641 providerInstanceId: Schema.optional(Schema.String),
642 environmentVariable: Schema.optional(Schema.String),
643 cause: Schema.Defect(),
644 },
645) {
646 override get message(): string {
647 const provider =
648 this.providerInstanceId === undefined ? "" : ` for provider ${this.providerInstanceId}`;
649 const variable =
650 this.environmentVariable === undefined
651 ? ""
652 : ` and environment variable ${this.environmentVariable}`;
653 return `Server settings ${this.operation} failed${provider}${variable} at ${this.settingsPath}.`;
654 }
655}
656
657// ── Unified type ─────────────────────────────────────────────────────
658
659export type UnifiedSettings = ServerSettings & ClientSettings;
660export const DEFAULT_UNIFIED_SETTINGS: UnifiedSettings = {
661 ...DEFAULT_SERVER_SETTINGS,
662 ...DEFAULT_CLIENT_SETTINGS,
663};
664
665// ── Server Settings Patch (replace with a Schema.deepPartial if available) ──────────────────────────────────────────
666
667const ModelSelectionPatch = Schema.Struct({
668 instanceId: Schema.optionalKey(ProviderInstanceId),
669 model: Schema.optionalKey(TrimmedNonEmptyString),
670 options: Schema.optionalKey(ProviderOptionSelections),
671});
672
673const CodexSettingsPatch = Schema.Struct({
674 enabled: Schema.optionalKey(Schema.Boolean),
675 binaryPath: Schema.optionalKey(TrimmedString),
676 homePath: Schema.optionalKey(TrimmedString),
677 shadowHomePath: Schema.optionalKey(TrimmedString),
678 launchArgs: Schema.optionalKey(TrimmedString),
679 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
680});
681
682const ClaudeSettingsPatch = Schema.Struct({
683 enabled: Schema.optionalKey(Schema.Boolean),
684 binaryPath: Schema.optionalKey(TrimmedString),
685 homePath: Schema.optionalKey(TrimmedString),
686 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
687 launchArgs: Schema.optionalKey(TrimmedString),
688});
689
690const CursorSettingsPatch = Schema.Struct({
691 enabled: Schema.optionalKey(Schema.Boolean),
692 binaryPath: Schema.optionalKey(TrimmedString),
693 apiEndpoint: Schema.optionalKey(TrimmedString),
694 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
695});
696
697const GrokSettingsPatch = Schema.Struct({
698 enabled: Schema.optionalKey(Schema.Boolean),
699 binaryPath: Schema.optionalKey(TrimmedString),
700 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
701});
702
703const OpenCodeSettingsPatch = Schema.Struct({
704 enabled: Schema.optionalKey(Schema.Boolean),
705 binaryPath: Schema.optionalKey(TrimmedString),
706 serverUrl: Schema.optionalKey(TrimmedString),
707 serverPassword: Schema.optionalKey(TrimmedString),
708 customModels: Schema.optionalKey(Schema.Array(Schema.String)),
709});
710
711export const ServerSettingsPatch = Schema.Struct({
712 // Server settings
713 enableLegacyTokenStreaming: Schema.optionalKey(Schema.Boolean),
714 enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
715 backgroundActivity: Schema.optionalKey(
716 Schema.Struct({
717 schemaVersion: Schema.optionalKey(Schema.Literal(1)),
718 profile: Schema.optionalKey(BackgroundActivityProfileSelection),
719 baseProfile: Schema.optionalKey(BackgroundActivityProfile),
720 overrides: Schema.optionalKey(BackgroundActivityOverrides),
721 }),
722 ),
723 automaticGitFetchInterval: Schema.optionalKey(Schema.DurationFromMillis),
724 providerHealthRefreshInterval: Schema.optionalKey(Schema.DurationFromMillis),
725 backgroundActivityProfile: Schema.optionalKey(BackgroundActivityProfile),
726 defaultThreadEnvMode: Schema.optionalKey(ThreadEnvMode),
727 newWorktreesStartFromOrigin: Schema.optionalKey(Schema.Boolean),
728 addProjectBaseDirectory: Schema.optionalKey(TrimmedString),
729 textGenerationModelSelection: Schema.optionalKey(ModelSelectionPatch),
730 sourceControlWritingStyle: Schema.optionalKey(
731 Schema.Struct({
732 mode: Schema.optionalKey(SourceControlWritingStyleMode),
733 customInstructions: Schema.optionalKey(TrimmedString),
734 followChangeRequestTemplates: Schema.optionalKey(Schema.Boolean),
735 }),
736 ),
737 sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
738 observability: Schema.optionalKey(
739 Schema.Struct({
740 otlpTracesUrl: Schema.optionalKey(TrimmedString),
741 otlpMetricsUrl: Schema.optionalKey(TrimmedString),
742 }),
743 ),
744 providers: Schema.optionalKey(
745 Schema.Struct({
746 codex: Schema.optionalKey(CodexSettingsPatch),
747 claudeAgent: Schema.optionalKey(ClaudeSettingsPatch),
748 cursor: Schema.optionalKey(CursorSettingsPatch),
749 grok: Schema.optionalKey(GrokSettingsPatch),
750 opencode: Schema.optionalKey(OpenCodeSettingsPatch),
751 }),
752 ),
753 // Whole-map replacement for the new instance config. Patching individual
754 // entries is intentionally out of scope: the map is small, and partial
755 // patches risk leaving driver-specific config in a half-merged state.
756 // The web UI sends a fully-formed map every time it edits this field.
757 providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),
758});
759export type ServerSettingsPatch = typeof ServerSettingsPatch.Type;
760
761export const ClientSettingsPatch = Schema.Struct({
762 confirmQuit: Schema.optionalKey(Schema.Boolean),
763 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
764 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
765 diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
766 environmentIdentificationMode: Schema.optionalKey(EnvironmentIdentificationMode),
767 glassOpacity: Schema.optionalKey(GlassOpacity),
768 fontSizeInterface: Schema.optionalKey(InterfaceFontSize),
769 fontSizePrompt: Schema.optionalKey(PromptFontSize),
770 fontSizeCode: Schema.optionalKey(CodeFontSize),
771 fontSizeTerminal: Schema.optionalKey(TerminalFontSize),
772 fontFamilyCode: Schema.optionalKey(FontFamilyPreference),
773 fontFamilyComposer: Schema.optionalKey(FontFamilyPreference),
774 fontFamilySans: Schema.optionalKey(FontFamilyPreference),
775 fontFamilyTerminal: Schema.optionalKey(FontFamilyPreference),
776 fontSmoothing: Schema.optionalKey(Schema.Boolean),
777 favorites: Schema.optionalKey(
778 Schema.Array(
779 Schema.Struct({
780 provider: ProviderInstanceId,
781 model: TrimmedNonEmptyString,
782 }),
783 ),
784 ),
785 providerModelPreferences: Schema.optionalKey(
786 Schema.Record(
787 ProviderInstanceId,
788 Schema.Struct({
789 hiddenModels: Schema.Array(Schema.String).pipe(
790 Schema.withDecodingDefault(Effect.succeed([])),
791 ),
792 modelOrder: Schema.Array(Schema.String).pipe(
793 Schema.withDecodingDefault(Effect.succeed([])),
794 ),
795 }),
796 ),
797 ),
798 planModeEnabled: Schema.optionalKey(Schema.Boolean),
799 legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),
800 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
801 sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
802 sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
803 sidebarProjectGroupingOverrides: Schema.optionalKey(
804 Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
805 ),
806 sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
807 sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
808 sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
809 timestampFormat: Schema.optionalKey(TimestampFormat),
810 wordWrap: Schema.optionalKey(Schema.Boolean),
811});
812export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;