Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const layer = Layer.effect(
yield* Effect.promise(() => resolveLoadedPlugins(data, options.path))
if (!data.$schema) {
data.$schema = "https://opencode.ai/config.json"
const updated = text.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
const updated = patchJsonc(text, { $schema: "https://opencode.ai/config.json" })
yield* fs.writeFileString(options.path, updated).pipe(Effect.catch(() => Effect.void))
}
return data
Expand Down
13 changes: 13 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,19 @@ it.instance("preserves env variables when adding $schema to config", () =>
),
)

it.instance("writes valid JSON when adding $schema to a config with no other keys", () =>
Effect.gen(function* () {
const test = yield* TestInstance
// Empty object without $schema: auto-add must not leave a trailing comma (invalid strict JSON).
yield* FSUtil.use.writeWithDirs(path.join(test.directory, "opencode.json"), "{}")
yield* Config.use.get()

const content = yield* FSUtil.use.readFileString(path.join(test.directory, "opencode.json"))
expect(() => JSON.parse(content)).not.toThrow()
expect(JSON.parse(content).$schema).toBe("https://opencode.ai/config.json")
}),
)

it.instance("handles file inclusion substitution", () =>
Effect.gen(function* () {
const test = yield* TestInstance
Expand Down
Loading