Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settings.ts

805 lines33.2 KB

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