Repository navigation
feat(schema): publish V2 config schema and accept V1 and V2 at /config.json - #54832
opencode-agent[bot] wants to merge 1 commit into
Conversation
…g.json Generate the strict V2 opencode.json schema from Config.Info and serve it at /v2/config.json. Regenerate the root /config.json from the V2 schema merged with a frozen snapshot of the last V1 schema, so V1, V2, and mixed configs validate. A CI staleness check keeps it in sync.
There was a problem hiding this comment.
The change works as described. I regenerated both schemas: the committed /config.json matches the generator output, check:generated passes, and config-v1.json is identical to the previous /config.json. With Ajv (draft 2020-12), pure V1 and mixed V1/V2 files (including mixed mcp) pass /config.json and fail /v2/config.json. Native V2 files pass both. Unknown keys and V1 fields inside a V2 agent entry are rejected by both. packages/schema typechecks.
Public API impact (published config schemas, no runtime change):
- Added:
https://opencode.ai/v2/config.json, a strict V2 schema generated fromConfig.Info. - Changed:
https://opencode.ai/config.jsonmoves from strict V1 to a V1+V2 union. V1-only keys are markeddeprecated, keys whose V1 and V2 shapes differ accept either shape, and V1$defsare renamed toV1.*. This is backwards compatible for configs: everything the old schema accepted still passes. Anything that referenced the old$defs/<Name>paths directly would need to use$defs/V1.<Name>.
One concern, inline: the root of the V2 schema is a bare $ref, the shape #41014 reports editors fail to apply.
Fixes #53398
Fixes #54764
Fixes #48812
Fixes #50724
Fixes #43748
Fixes #46248
Related: #41014, #52177, #53744
| const v2 = { | ||
| $schema: "https://json-schema.org/draft/2020-12/schema", | ||
| $id: "https://opencode.ai/v2/config.json", | ||
| ...generated.schema, |
There was a problem hiding this comment.
This keeps generated.schema as is, so the root of /v2/config.json is a bare {"$ref": "#/$defs/Config.InfoEncoded"}. #41014 reports that the standard JSON language server (VS Code and neovim jsonls) doesn't apply schemas shaped like that, so users could get no completion or validation from the URL the docs now recommend. The compat document already avoids this by writing the root object out flat. Could the V2 document inline generated.definitions[definitionName(generated.schema.$ref)] at the root in the same way?
Summary
https://opencode.ai/config.jsonstill serves the old V1 schema withadditionalProperties: false, so editors flag valid V2 keys (permissions,plugins,agents,providers,snapshots,websearch, …) as errors. Nothing serves a V2 schema foropencode.json(/v2/config.jsonreturns 404)./v2/config.json(new): strict V2 schema generated fromConfig.Infoduring theservices/wwwbuild. Gitignored, likecli.json./config.json(console app): now generated, not hand-maintained. It merges the V2 schema withpackages/schema/script/config-v1.json, a frozen snapshot of the last V1 schema (the previous contents of this file):deprecated: trueanyOf), so each value must be entirely V1 or entirely V2, which is how Core loads itmcp,compactionandexperimentalmerge their members, matching Core's documented nested mixing$defsare namespaced asV1.*so they can't collide with V2 definitionscheck:generatedinservices/www(already run in CI) now fails if the committed/config.jsonis out of date.opencodeskill now use/v2/config.json. The migration guide explains that/config.jsonaccepts V1, V2 and mixed files, and says to switch to the V2 URL once a file is fully converted. V1 docs (packages/web) are unchanged.Replaces #51804, which only added the V2 schema.
Validation
Checked with Ajv (draft 2020-12):
$schemaJSON examples in the V2 docs pass both the V2 schema and/config.json./config.json, so V1 files don't regress./config.jsonbut fail/v2/config.json. Mixedmcp(serversplus legacy entries) and mixedcompaction/experimentalpass/config.json. Unknown keys, invalid enum values, and V1 fields inside a V2 agent entry are rejected by both.bun run typecheckinpackages/schema.bun run generate,bun run check:generated(also confirmed it fails on a stale file),bun typecheck, andbun run build(Node 22) inservices/www. Checked thatdist/client/v2/config.jsoncontains the V2 schema and$id.Known gap
Most V2 field descriptions are missing from the generated schema. The shared
optional(...)helper puts.annotate({ description })on the decoded side, and JSON Schema generation uses the encoded side. Where a V2 key matches the V1 shape, the V1 description is kept. Fixing the helper is a separate change.Requested by: @neriousy (Filip via Slack)
Added by the opencode bot (AI-generated).
Fixes #53398
Fixes #54764
Fixes #48812
Fixes #50724
Fixes #43748
Fixes #46248
Related: #41014, #52177, #53744
Public API: adds the https://opencode.ai/v2/config.json schema; https://opencode.ai/config.json now accepts V1, V2 and mixed configs (backwards compatible)