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