From 9538c2171f4b12912b5db132402d4a589fa3780e Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Fri, 28 Aug 2026 17:11:55 -0400 Subject: [PATCH] refactor(core): derive config recognition fields (#45701) --- packages/core/src/config/normalize.ts | 11 +++----- packages/core/src/config/plugin/agent.ts | 14 +--------- packages/core/src/v1/config/agent.ts | 19 +------------- packages/core/test/config/agent.test.ts | 26 +++++++++++++++++++ .../core/test/config/normalization.test.ts | 14 ++++++++++ 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/packages/core/src/config/normalize.ts b/packages/core/src/config/normalize.ts index 110b63f1060..15767d0edf5 100644 --- a/packages/core/src/config/normalize.ts +++ b/packages/core/src/config/normalize.ts @@ -292,18 +292,13 @@ function normalizeMcpTimeout( invalid(path, diagnostics) return } - const recognized = ["startup", "catalog", "execution"].filter((key) => own(value, key)) + const recognized = Object.entries(ConfigMCP.Timeout.fields).filter(([key]) => own(value, key)) if (Object.keys(value).length && !recognized.length) { invalid(path, diagnostics) return } - recognized.forEach((key) => { - const leaf = decodeEncoded( - ConfigMCP.Timeout.fields[key as keyof typeof ConfigMCP.Timeout.fields], - value[key], - [...path, key], - diagnostics, - ) + recognized.forEach(([key, field]) => { + const leaf = decodeEncoded(field, value[key], [...path, key], diagnostics) if (leaf === undefined) return overlay(timeout, key, leaf, [...path, key], diagnostics) }) diff --git a/packages/core/src/config/plugin/agent.ts b/packages/core/src/config/plugin/agent.ts index 78445e68b98..facfff811b9 100644 --- a/packages/core/src/config/plugin/agent.ts +++ b/packages/core/src/config/plugin/agent.ts @@ -32,19 +32,7 @@ type PathAction = | typeof ReadTool.name | typeof EditTool.name const pathActions = ["external_directory", "read", "edit"] as const satisfies readonly PathAction[] -const agentKeys = new Set([ - "model", - "variant", - "request", - "system", - "description", - "mode", - "hidden", - "color", - "steps", - "disabled", - "permissions", -]) +const agentKeys = new Set(["variant", ...Object.keys(ConfigAgent.Info.fields)]) export const Plugin = define({ id: "opencode.config.agent", diff --git a/packages/core/src/v1/config/agent.ts b/packages/core/src/v1/config/agent.ts index 4c731ae4b0f..f8e959cfa21 100644 --- a/packages/core/src/v1/config/agent.ts +++ b/packages/core/src/v1/config/agent.ts @@ -40,24 +40,7 @@ const AgentSchema = Schema.StructWithRest( [Schema.Record(Schema.String, Schema.Any)], ) -const KNOWN_KEYS = new Set([ - "name", - "model", - "variant", - "prompt", - "description", - "temperature", - "top_p", - "mode", - "hidden", - "color", - "steps", - "maxSteps", - "options", - "permission", - "disable", - "tools", -]) +const KNOWN_KEYS = new Set(["name", ...Object.keys(AgentSchema.schema.fields)]) const normalize = (agent: Schema.Schema.Type): Schema.Schema.Type => { const options: Record = { ...agent.options } diff --git a/packages/core/test/config/agent.test.ts b/packages/core/test/config/agent.test.ts index 19c22f69eb3..2df2cd93d35 100644 --- a/packages/core/test/config/agent.test.ts +++ b/packages/core/test/config/agent.test.ts @@ -15,6 +15,7 @@ import { Permission } from "@opencode-ai/core/permission" import { AgentPlugin } from "@opencode-ai/core/plugin/agent" import { AbsolutePath } from "@opencode-ai/core/schema" import { ConfigMigrateV1 } from "@opencode-ai/core/v1/config/migrate" +import { ConfigAgentV1 } from "@opencode-ai/core/v1/config/agent" import { advance, drain } from "../lib/clock" import { tmpdir } from "../fixture/tmpdir" import { testEffect } from "../lib/effect" @@ -34,6 +35,30 @@ test("rejects named agent color tokens", () => { expect(() => decode({ agents: { reviewer: { color: "warning" } } })).toThrow() }) +test("keeps schema fields and name out of legacy agent options", () => { + const agent = Schema.decodeUnknownSync(ConfigAgentV1.Info)({ + name: "reviewer", + model: "test/model", + variant: "high", + temperature: 0.5, + top_p: 0.9, + prompt: "Review carefully.", + tools: { edit: false }, + disable: false, + description: "Reviews changes", + mode: "subagent", + hidden: true, + options: { existing: true }, + color: "#112233", + steps: 10, + maxSteps: 20, + permission: { read: "allow" }, + custom: "preserved", + }) + + expect(agent.options).toEqual({ existing: true, custom: "preserved" }) +}) + describe("ConfigAgentPlugin.Plugin", () => { it.effect("matches POSIX paths against home-relative permissions", () => Effect.gen(function* () { @@ -351,6 +376,7 @@ Review carefully.`, await fs.writeFile( path.join(tmp.path, "agents", "native.md"), `--- +variant: high request: headers: x-agent: native diff --git a/packages/core/test/config/normalization.test.ts b/packages/core/test/config/normalization.test.ts index e1ce6c8201d..4bc2c1bd5ca 100644 --- a/packages/core/test/config/normalization.test.ts +++ b/packages/core/test/config/normalization.test.ts @@ -362,6 +362,20 @@ describe("ConfigNormalize", () => { ]) }) + test("normalizes MCP timeout fields in schema order with per-leaf recovery", () => { + const result = normalized({ mcp: { timeout: { execution: 3000, startup: "invalid", catalog: 2000 } } }) + + expect(result.encoded.mcp).toEqual({ timeout: { catalog: 2000, execution: 3000 } }) + expect(result.diagnostics.map((item) => [item.kind, item.path])).toEqual([ + ["invalid", ["mcp", "timeout", "startup"]], + ]) + expect(normalized({ mcp: { timeout: {} } }).encoded.mcp).toBeUndefined() + + const unknown = normalized({ mcp: { timeout: { unknown: 1000 } } }) + expect(unknown.encoded.mcp).toBeUndefined() + expect(unknown.diagnostics.map((item) => [item.kind, item.path])).toEqual([["invalid", ["mcp", "timeout"]]]) + }) + test("merges bounded compaction leaves and omits unsupported leaves", () => { const result = normalized({ compaction: {