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

settings.ts

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