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

settings.ts

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