From 8b9cf23ec770bd1a9d2487ae65d45c0f343d7a44 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 30 Mar 2026 15:33:18 -0700 Subject: [PATCH] Sync settings descriptions with schema metadata - Centralize settings copy in schema annotations - Reuse schema descriptions in the settings UI - Refresh generated server settings schema output --- .../public/schemas/keybindings.schema.json | 5 +- .../schemas/server-settings.schema.json | 53 +++++--------- .../server-settings/0.0.15.schema.json | 15 ++-- .../components/settings/SettingsPanels.tsx | 70 ++++++++++++++++--- packages/contracts/src/settings.ts | 69 +++++++++--------- packages/shared/src/schemaJson.test.ts | 12 +++- packages/shared/src/schemaJson.ts | 25 +++++++ scripts/lib/server-settings-schema.test.ts | 7 +- 8 files changed, 162 insertions(+), 94 deletions(-) diff --git a/apps/marketing/public/schemas/keybindings.schema.json b/apps/marketing/public/schemas/keybindings.schema.json index 4d46fa49da..7f6c849d7f 100644 --- a/apps/marketing/public/schemas/keybindings.schema.json +++ b/apps/marketing/public/schemas/keybindings.schema.json @@ -56,10 +56,7 @@ "description": "Optional expression limiting when the shortcut is active." } }, - "required": [ - "key", - "command" - ], + "required": ["key", "command"], "additionalProperties": false, "description": "Single keybinding rule entry in `keybindings.json`." }, diff --git a/apps/marketing/public/schemas/server-settings.schema.json b/apps/marketing/public/schemas/server-settings.schema.json index a7a41c3211..f75aaaf878 100644 --- a/apps/marketing/public/schemas/server-settings.schema.json +++ b/apps/marketing/public/schemas/server-settings.schema.json @@ -18,23 +18,20 @@ "type": "null" } ], - "description": "Whether server-driven assistant responses should stream incrementally to clients when the active provider supports it." + "description": "Show token-by-token output while a response is in progress." }, "defaultThreadEnvMode": { "anyOf": [ { "type": "string", - "enum": [ - "local", - "worktree" - ], + "enum": ["local", "worktree"], "description": "Default execution environment to use when creating new threads." }, { "type": "null" } ], - "description": "Default execution environment to use when creating new threads." + "description": "Pick the default workspace mode for newly created draft threads." }, "textGenerationModelSelection": { "anyOf": [ @@ -45,9 +42,7 @@ "properties": { "provider": { "type": "string", - "enum": [ - "codex" - ], + "enum": ["codex"], "description": "The provider used for text generation." }, "model": { @@ -61,12 +56,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "xhigh", - "high", - "medium", - "low" - ] + "enum": ["xhigh", "high", "medium", "low"] }, { "type": "null" @@ -90,10 +80,7 @@ "description": "Optional Codex-specific tuning knobs for the selected model." } }, - "required": [ - "provider", - "model" - ], + "required": ["provider", "model"], "additionalProperties": false, "description": "Text generation model selection for the Codex provider." }, @@ -102,9 +89,7 @@ "properties": { "provider": { "type": "string", - "enum": [ - "claudeAgent" - ], + "enum": ["claudeAgent"], "description": "The provider used for text generation." }, "model": { @@ -129,13 +114,7 @@ "anyOf": [ { "type": "string", - "enum": [ - "low", - "medium", - "high", - "max", - "ultrathink" - ] + "enum": ["low", "medium", "high", "max", "ultrathink"] }, { "type": "null" @@ -170,10 +149,7 @@ "description": "Optional Claude-specific tuning knobs for the selected model." } }, - "required": [ - "provider", - "model" - ], + "required": ["provider", "model"], "additionalProperties": false, "description": "Text generation model selection for the Claude provider." } @@ -184,7 +160,7 @@ "type": "null" } ], - "description": "Default provider and model to use for server-side text generation features." + "description": "Configure the model used for generated commit messages, PR titles, and similar Git text." }, "providers": { "anyOf": [ @@ -217,7 +193,8 @@ { "type": "null" } - ] + ], + "description": "Path to the Codex binary" }, "homePath": { "anyOf": [ @@ -228,7 +205,8 @@ { "type": "null" } - ] + ], + "description": "Optional custom Codex home and config directory." }, "customModels": { "anyOf": [ @@ -281,7 +259,8 @@ { "type": "null" } - ] + ], + "description": "Path to the Claude binary" }, "customModels": { "anyOf": [ diff --git a/apps/marketing/public/schemas/server-settings/0.0.15.schema.json b/apps/marketing/public/schemas/server-settings/0.0.15.schema.json index 024a608598..f75aaaf878 100644 --- a/apps/marketing/public/schemas/server-settings/0.0.15.schema.json +++ b/apps/marketing/public/schemas/server-settings/0.0.15.schema.json @@ -18,7 +18,7 @@ "type": "null" } ], - "description": "Whether server-driven assistant responses should stream incrementally to clients when the active provider supports it." + "description": "Show token-by-token output while a response is in progress." }, "defaultThreadEnvMode": { "anyOf": [ @@ -31,7 +31,7 @@ "type": "null" } ], - "description": "Default execution environment to use when creating new threads." + "description": "Pick the default workspace mode for newly created draft threads." }, "textGenerationModelSelection": { "anyOf": [ @@ -160,7 +160,7 @@ "type": "null" } ], - "description": "Default provider and model to use for server-side text generation features." + "description": "Configure the model used for generated commit messages, PR titles, and similar Git text." }, "providers": { "anyOf": [ @@ -193,7 +193,8 @@ { "type": "null" } - ] + ], + "description": "Path to the Codex binary" }, "homePath": { "anyOf": [ @@ -204,7 +205,8 @@ { "type": "null" } - ] + ], + "description": "Optional custom Codex home and config directory." }, "customModels": { "anyOf": [ @@ -257,7 +259,8 @@ { "type": "null" } - ] + ], + "description": "Path to the Claude binary" }, "customModels": { "anyOf": [ diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index b7fde0c5f6..a600a2f688 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -12,14 +12,19 @@ import { import { useQuery, useQueryClient } from "@tanstack/react-query"; import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react"; import { + ClaudeSettings, + ClientSettingsSchema, + CodexSettings, PROVIDER_DISPLAY_NAMES, type ProviderKind, type ServerProvider, type ServerProviderModel, + ServerSettings, ThreadId, } from "@t3tools/contracts"; import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings"; import { normalizeModelSlug } from "@t3tools/shared/model"; +import { getSchemaDescription } from "@t3tools/shared/schemaJson"; import { Equal } from "effect"; import { APP_VERSION } from "../../branding"; import { @@ -81,6 +86,51 @@ const TIMESTAMP_FORMAT_LABELS = { "24-hour": "24-hour", } as const; +function requireSchemaDescription( + schema: Parameters[0], + label: string, +) { + const description = getSchemaDescription(schema); + if (!description) { + throw new Error(`Missing schema description for ${label}`); + } + return description; +} + +const SETTINGS_DESCRIPTIONS = { + timestampFormat: requireSchemaDescription( + ClientSettingsSchema.fields.timestampFormat, + "ClientSettings.timestampFormat", + ), + diffWordWrap: requireSchemaDescription( + ClientSettingsSchema.fields.diffWordWrap, + "ClientSettings.diffWordWrap", + ), + confirmThreadArchive: requireSchemaDescription( + ClientSettingsSchema.fields.confirmThreadArchive, + "ClientSettings.confirmThreadArchive", + ), + confirmThreadDelete: requireSchemaDescription( + ClientSettingsSchema.fields.confirmThreadDelete, + "ClientSettings.confirmThreadDelete", + ), + enableAssistantStreaming: requireSchemaDescription( + ServerSettings.fields.enableAssistantStreaming, + "ServerSettings.enableAssistantStreaming", + ), + defaultThreadEnvMode: requireSchemaDescription( + ServerSettings.fields.defaultThreadEnvMode, + "ServerSettings.defaultThreadEnvMode", + ), + textGenerationModelSelection: requireSchemaDescription( + ServerSettings.fields.textGenerationModelSelection, + "ServerSettings.textGenerationModelSelection", + ), + codexBinaryPath: requireSchemaDescription(CodexSettings.fields.binaryPath, "Codex.binaryPath"), + codexHomePath: requireSchemaDescription(CodexSettings.fields.homePath, "Codex.homePath"), + claudeBinaryPath: requireSchemaDescription(ClaudeSettings.fields.binaryPath, "Claude.binaryPath"), +} as const; + const EMPTY_SERVER_PROVIDERS: ReadonlyArray = []; type InstallProviderSettings = { @@ -98,16 +148,16 @@ const PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [ provider: "codex", title: "Codex", binaryPlaceholder: "Codex binary path", - binaryDescription: "Path to the Codex binary", + binaryDescription: SETTINGS_DESCRIPTIONS.codexBinaryPath, homePathKey: "codexHomePath", homePlaceholder: "CODEX_HOME", - homeDescription: "Optional custom Codex home and config directory.", + homeDescription: SETTINGS_DESCRIPTIONS.codexHomePath, }, { provider: "claudeAgent", title: "Claude", binaryPlaceholder: "Claude binary path", - binaryDescription: "Path to the Claude binary", + binaryDescription: SETTINGS_DESCRIPTIONS.claudeBinaryPath, }, ] as const; @@ -774,7 +824,7 @@ export function GeneralSettingsPanel() { + Schema.String.annotate({ description }).pipe( + Schema.decodeTo(TrimmedString, SchemaTransformation.passthrough()), + ); + export const ClientSettingsSchema = Schema.Struct({ - confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(() => false)), - confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(() => true)), - diffWordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(() => false)), - sidebarProjectSortOrder: SidebarProjectSortOrder.pipe( - Schema.withDecodingDefault(() => DEFAULT_SIDEBAR_PROJECT_SORT_ORDER), - ), - sidebarThreadSortOrder: SidebarThreadSortOrder.pipe( - Schema.withDecodingDefault(() => DEFAULT_SIDEBAR_THREAD_SORT_ORDER), - ), - timestampFormat: TimestampFormat.pipe(Schema.withDecodingDefault(() => DEFAULT_TIMESTAMP_FORMAT)), + confirmThreadArchive: Schema.Boolean.annotate({ + description: "Require a second click on the inline archive action before a thread is archived.", + }).pipe(Schema.withDecodingDefault(() => false)), + confirmThreadDelete: Schema.Boolean.annotate({ + description: "Ask before deleting a thread and its chat history.", + }).pipe(Schema.withDecodingDefault(() => true)), + diffWordWrap: Schema.Boolean.annotate({ + description: "Set the default wrap state when the diff panel opens.", + }).pipe(Schema.withDecodingDefault(() => false)), + sidebarProjectSortOrder: SidebarProjectSortOrder.annotate({ + description: "Choose how projects are ordered in the sidebar.", + }).pipe(Schema.withDecodingDefault(() => DEFAULT_SIDEBAR_PROJECT_SORT_ORDER)), + sidebarThreadSortOrder: SidebarThreadSortOrder.annotate({ + description: "Choose how threads are ordered inside the selected project.", + }).pipe(Schema.withDecodingDefault(() => DEFAULT_SIDEBAR_THREAD_SORT_ORDER)), + timestampFormat: TimestampFormat.annotate({ + description: "System default follows your browser or OS clock preference.", + }).pipe(Schema.withDecodingDefault(() => DEFAULT_TIMESTAMP_FORMAT)), +}).annotate({ + description: "Client-only settings persisted locally in the browser.", }); export type ClientSettings = typeof ClientSettingsSchema.Type; @@ -42,13 +57,12 @@ export const DEFAULT_CLIENT_SETTINGS: ClientSettings = Schema.decodeSync(ClientS // ── Server Settings (server-authoritative) ──────────────────── export const ThreadEnvMode = Schema.Literals(["local", "worktree"]).annotate({ - description: - "Default environment mode for new threads. 'local' runs in the current workspace, while 'worktree' runs in a managed git worktree.", + description: "Pick the default workspace mode for newly created draft threads.", }); export type ThreadEnvMode = typeof ThreadEnvMode.Type; -const makeBinaryPathSetting = (fallback: string) => - TrimmedString.pipe( +const makeBinaryPathSetting = (fallback: string, description: string) => + makeTrimmedStringSetting(description).pipe( Schema.decodeTo( Schema.String, SchemaTransformation.transformOrFail({ @@ -63,16 +77,10 @@ export const CodexSettings = Schema.Struct({ enabled: Schema.Boolean.annotate({ description: "Whether the Codex provider is enabled and available for selection.", }).pipe(Schema.withDecodingDefault(() => true)), - binaryPath: makeBinaryPathSetting("codex").pipe( - Schema.annotate({ - description: - "Path to the Codex executable. Leave blank to resolve the `codex` executable from PATH.", - }), + binaryPath: makeBinaryPathSetting("codex", "Path to the Codex binary"), + homePath: makeTrimmedStringSetting("Optional custom Codex home and config directory.").pipe( + Schema.withDecodingDefault(() => ""), ), - homePath: TrimmedString.annotate({ - description: - "Optional Codex home directory. Leave blank to use the default provider-managed location.", - }).pipe(Schema.withDecodingDefault(() => "")), customModels: Schema.Array(Schema.String) .annotate({ description: @@ -88,12 +96,7 @@ export const ClaudeSettings = Schema.Struct({ enabled: Schema.Boolean.annotate({ description: "Whether the Claude provider is enabled and available for selection.", }).pipe(Schema.withDecodingDefault(() => true)), - binaryPath: makeBinaryPathSetting("claude").pipe( - Schema.annotate({ - description: - "Path to the Claude executable. Leave blank to resolve the `claude` executable from PATH.", - }), - ), + binaryPath: makeBinaryPathSetting("claude", "Path to the Claude binary"), customModels: Schema.Array(Schema.String) .annotate({ description: @@ -107,14 +110,14 @@ export type ClaudeSettings = typeof ClaudeSettings.Type; export const ServerSettings = Schema.Struct({ enableAssistantStreaming: Schema.Boolean.annotate({ - description: - "Whether server-driven assistant responses should stream incrementally to clients when the active provider supports it.", + description: "Show token-by-token output while a response is in progress.", }).pipe(Schema.withDecodingDefault(() => false)), defaultThreadEnvMode: ThreadEnvMode.annotate({ - description: "Default execution environment to use when creating new threads.", + description: "Pick the default workspace mode for newly created draft threads.", }).pipe(Schema.withDecodingDefault(() => "local" as const satisfies ThreadEnvMode)), textGenerationModelSelection: ModelSelection.annotate({ - description: "Default provider and model to use for server-side text generation features.", + description: + "Configure the model used for generated commit messages, PR titles, and similar Git text.", }).pipe( Schema.withDecodingDefault(() => ({ provider: "codex" as const, diff --git a/packages/shared/src/schemaJson.test.ts b/packages/shared/src/schemaJson.test.ts index 1ed9a140c2..1b635f8938 100644 --- a/packages/shared/src/schemaJson.test.ts +++ b/packages/shared/src/schemaJson.test.ts @@ -1,6 +1,6 @@ import { assert, it } from "@effect/vitest"; import { Effect, Schema } from "effect"; -import { encodePrettyJsonEffect, toJsonSchemaObject } from "./schemaJson"; +import { encodePrettyJsonEffect, getSchemaDescription, toJsonSchemaObject } from "./schemaJson"; it.effect("encodePrettyJsonEffect writes indented JSON", () => Effect.gen(function* () { @@ -55,3 +55,13 @@ it.effect("toJsonSchemaObject hoists descriptions from wrapper nodes", () => assert.strictEqual(name.description, "Human-readable display name."); }), ); + +it.effect("getSchemaDescription reads hoisted descriptions from wrapped schemas", () => + Effect.sync(() => { + const enabled = Schema.Boolean.annotate({ + description: "Whether the feature is enabled.", + }).pipe(Schema.withDecodingDefault(() => false)); + + assert.strictEqual(getSchemaDescription(enabled), "Whether the feature is enabled."); + }), +); diff --git a/packages/shared/src/schemaJson.ts b/packages/shared/src/schemaJson.ts index 83c6d9807d..42869ed4b9 100644 --- a/packages/shared/src/schemaJson.ts +++ b/packages/shared/src/schemaJson.ts @@ -36,6 +36,8 @@ export const decodeUnknownJsonResult = (); + const PrettyJsonString = SchemaGetter.parseJson().compose( SchemaGetter.stringifyJson({ space: 2 }), ); @@ -100,6 +102,29 @@ export const toJsonSchemaObject = (schema: Schema.Top): unknown => { return hoistJsonSchemaDescriptions(document.schema); }; +export const getSchemaDescription = (schema: Schema.Top): string | undefined => { + if (schema && typeof schema === "object") { + const cached = schemaDescriptionCache.get(schema); + if (cached !== undefined || schemaDescriptionCache.has(schema)) { + return cached; + } + } + + const jsonSchema = toJsonSchemaObject(schema); + const description = + jsonSchema && typeof jsonSchema === "object" && !Array.isArray(jsonSchema) + ? typeof (jsonSchema as Record).description === "string" + ? ((jsonSchema as Record).description as string) + : undefined + : undefined; + + if (schema && typeof schema === "object") { + schemaDescriptionCache.set(schema, description); + } + + return description; +}; + /** * A `Getter` that parses a lenient JSON string (tolerating trailing commas * and JS-style comments) into an unknown value. diff --git a/scripts/lib/server-settings-schema.test.ts b/scripts/lib/server-settings-schema.test.ts index ca8069a0a6..8718661922 100644 --- a/scripts/lib/server-settings-schema.test.ts +++ b/scripts/lib/server-settings-schema.test.ts @@ -24,13 +24,14 @@ describe("buildServerSettingsJsonSchema", () => { type: "string", }, enableAssistantStreaming: { - description: expect.stringContaining("stream"), + description: "Show token-by-token output while a response is in progress.", }, defaultThreadEnvMode: { - description: expect.stringContaining("environment"), + description: "Pick the default workspace mode for newly created draft threads.", }, textGenerationModelSelection: { - description: expect.stringContaining("provider and model"), + description: + "Configure the model used for generated commit messages, PR titles, and similar Git text.", }, providers: { description: expect.stringContaining("Provider-specific"),