Skip to content

feat(schema): publish V2 config schema and accept V1 and V2 at /config.json - #54832

Closed
opencode-agent[bot] wants to merge 1 commit into
devfrom
config-schema-compat
Closed

opencode-agent[bot] wants to merge 1 commit into
devfrom
config-schema-compat

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

https://opencode.ai/config.json still serves the old V1 schema with additionalProperties: false, so editors flag valid V2 keys (permissions, plugins, agents, providers, snapshots, websearch, …) as errors. Nothing serves a V2 schema for opencode.json (/v2/config.json returns 404).

  • /v2/config.json (new): strict V2 schema generated from Config.Info during the services/www build. Gitignored, like cli.json.
  • /config.json (console app): now generated, not hand-maintained. It merges the V2 schema with packages/schema/script/config-v1.json, a frozen snapshot of the last V1 schema (the previous contents of this file):
    • keys are merged one by one; keys only V1 accepts are marked deprecated: true
    • a key whose V1 and V2 shapes differ accepts either shape (anyOf), so each value must be entirely V1 or entirely V2, which is how Core loads it
    • mcp, compaction and experimental merge their members, matching Core's documented nested mixing
    • V1 $defs are namespaced as V1.* so they can't collide with V2 definitions
  • Staleness check: check:generated in services/www (already run in CI) now fails if the committed /config.json is out of date.
  • Docs: V2 docs examples and the built-in opencode skill now use /v2/config.json. The migration guide explains that /config.json accepts 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):

  • All 68 $schema JSON examples in the V2 docs pass both the V2 schema and /config.json.
  • All 156 V1 docs examples that the old schema accepted also pass the new /config.json, so V1 files don't regress.
  • Pure V1 and mixed V1/V2 top-level configs pass /config.json but fail /v2/config.json. Mixed mcp (servers plus legacy entries) and mixed compaction/experimental pass /config.json. Unknown keys, invalid enum values, and V1 fields inside a V2 agent entry are rejected by both.
  • bun run typecheck in packages/schema.
  • bun run generate, bun run check:generated (also confirmed it fails on a stale file), bun typecheck, and bun run build (Node 22) in services/www. Checked that dist/client/v2/config.json contains 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)

…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.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from Config.Info.
  • Changed: https://opencode.ai/config.json moves from strict V1 to a V1+V2 union. V1-only keys are marked deprecated, keys whose V1 and V2 shapes differ accept either shape, and V1 $defs are renamed to V1.*. 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,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment