Skip to content

Commit fe7ca34

Browse files
authored
Drop Config Info Zod static (anomalyco#26933)
1 parent cc95197 commit fe7ca34

4 files changed

Lines changed: 7 additions & 25 deletions

File tree

packages/opencode/script/schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { z } from "zod"
44
import { Config } from "@/config/config"
5+
import { zodObject } from "@opencode-ai/core/effect-zod"
56
import { TuiConfig } from "../src/cli/cmd/tui/config/tui"
67

78
function generate(schema: z.ZodType) {
@@ -55,7 +56,7 @@ const configFile = process.argv[2]
5556
const tuiFile = process.argv[3]
5657

5758
console.log(configFile)
58-
await Bun.write(configFile, JSON.stringify(generate(Config.Info.zod), null, 2))
59+
await Bun.write(configFile, JSON.stringify(generate(zodObject(Config.Info).strict().meta({ ref: "Config" })), null, 2))
5960

6061
if (tuiFile) {
6162
console.log(tuiFile)

packages/opencode/src/config/config.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import { InstanceState } from "@/effect/instance-state"
2222
import { Context, Duration, Effect, Exit, Fiber, Layer, Option, Schema } from "effect"
2323
import { EffectFlock } from "@opencode-ai/core/util/effect-flock"
2424
import { containsPath } from "../project/instance-context"
25-
import { zod } from "@opencode-ai/core/effect-zod"
26-
import { NonNegativeInt, PositiveInt, withStatics, type DeepMutable } from "@opencode-ai/core/schema"
25+
import { NonNegativeInt, PositiveInt, type DeepMutable } from "@opencode-ai/core/schema"
2726
import { ConfigAgent } from "./agent"
2827
import { ConfigAttachment } from "./attachment"
2928
import { ConfigCommand } from "./command"
@@ -112,23 +111,13 @@ async function resolveLoadedPlugins<T extends { plugin?: ConfigPlugin.Spec[] }>(
112111
return config
113112
}
114113

115-
export const Server = ConfigServer.Server.zod
116-
export const Layout = ConfigLayout.Layout.zod
117114
export type Layout = ConfigLayout.Layout
118115

119116
const LogLevelRef = Schema.Literals(["DEBUG", "INFO", "WARN", "ERROR"]).annotate({
120117
identifier: "LogLevel",
121118
description: "Log level",
122119
})
123120

124-
// The Effect Schema is the canonical source of truth. The `.zod` compatibility
125-
// surface is derived from it so plugin/SDK Zod consumers keep working without
126-
// a parallel hand-maintained Zod definition.
127-
//
128-
// The walker emits `z.object({...})` which is non-strict by default. Config
129-
// historically uses `.strict()` (additionalProperties: false in openapi.json),
130-
// so layer that on after derivation. Re-apply the Config ref afterward
131-
// since `.strict()` strips the walker's meta annotation.
132121
export const Info = Schema.Struct({
133122
$schema: Schema.optional(Schema.String).annotate({
134123
description: "JSON schema reference for configuration validation",
@@ -301,15 +290,7 @@ export const Info = Schema.Struct({
301290
}),
302291
}),
303292
),
304-
})
305-
.annotate({ identifier: "Config" })
306-
.pipe(
307-
withStatics((s) => ({
308-
zod: (zod(s) as unknown as z.ZodObject<any>).strict().meta({ ref: "Config" }) as unknown as z.ZodType<
309-
DeepMutable<Schema.Schema.Type<typeof s>>
310-
>,
311-
})),
312-
)
293+
}).annotate({ identifier: "Config" })
313294

314295
// Uses the shared `DeepMutable` from `@opencode-ai/core/schema`. See the definition
315296
// there for why the local variant is needed over `Types.DeepMutable` from

packages/opencode/test/config/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ test("updates global config and omits empty shell key in jsonc", async () => {
251251

252252
const file = path.join(tmp.path, "opencode.jsonc")
253253
const writtenConfig = await Filesystem.readText(file)
254-
const parsed = ConfigParse.schema(Config.Info.zod, ConfigParse.jsonc(writtenConfig, file), file)
254+
const parsed = ConfigParse.effectSchema(Config.Info, ConfigParse.jsonc(writtenConfig, file), file)
255255
expect(writtenConfig).not.toContain('"shell"')
256256
expect(parsed.shell).toBeUndefined()
257257
expect(parsed.model).toBe("test/model")

packages/opencode/test/session/compaction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, describe, expect, mock, test } from "bun:test"
22
import { APICallError } from "ai"
3-
import { Cause, Deferred, Effect, Exit, Fiber, Layer } from "effect"
3+
import { Cause, Deferred, Effect, Exit, Fiber, Layer, Schema } from "effect"
44
import * as Stream from "effect/Stream"
55
import { Bus } from "../../src/bus"
66
import { Config } from "@/config/config"
@@ -211,7 +211,7 @@ function layer(result: "continue" | "compact") {
211211
}
212212

213213
function cfg(compaction?: Config.Info["compaction"]) {
214-
const base = Config.Info.zod.parse({})
214+
const base = Schema.decodeUnknownSync(Config.Info)({}) as Config.Info
215215
return TestConfig.layer({
216216
get: () => Effect.succeed({ ...base, compaction }),
217217
})

0 commit comments

Comments
 (0)