Compare commits

...
Author SHA1 Message Date
Kit Langton 44c09180c4 refactor(core): derive config recognition fields 2026-08-27 15:29:59 -04:00
5 changed files with 45 additions and 39 deletions
+3 -8
View File
@@ -291,18 +291,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)
})
+1 -13
View File
@@ -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",
+1 -18
View File
@@ -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<typeof AgentSchema>): Schema.Schema.Type<typeof AgentSchema> => {
const options: Record<string, unknown> = { ...agent.options }
+26
View File
@@ -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* () {
@@ -354,6 +379,7 @@ Review carefully.`,
await fs.writeFile(
path.join(tmp.path, "agents", "native.md"),
`---
variant: high
request:
headers:
x-agent: native
@@ -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: {