Skip to content

feat(config): ship an editor schema for config.toml and models.json - #370

Merged
liuedcson merged 3 commits into
mainfrom
feat/config-schema
Nov 26, 2026
Merged

liuedcson merged 3 commits into
mainfrom
feat/config-schema

Conversation

@liuedcson

@liuedcson liuedcson commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

config.toml and models.json now have an editor schema generated from the same
TypeBox definitions their loaders use, plus one command to print it:

  • step config schema [config|models] [--out <file>]

The key definitions are the single source: settings-schema.ts declares each
settings table once, the TypeScript types derive from it with Static<>, and the
JSON Schema is rendered from the same objects.

Why

Nothing could tell a user whether a configuration file was right before starting
a session. The runtime is deliberately forgiving: an unknown key is carried along
and never read, an out-of-range value falls back to its default with one line of
startup output, and an unrecognized enum falls back silently. All three look the
same from the outside — the file says one thing and the session does another —
and the only way to find the accepted keys was to read the source, which is what
the reported workflow was doing against the compiled binary.

Behavior

Schema generation. packages/coding-agent/schema/ holds the committed
config.schema.json and models.schema.json; both are rendered again at runtime
and written beside the global config.toml, whose first line is
#:schema ./config.schema.json. Nothing is fetched over the network and no URL
is published, so an editor validates against the build that wrote the file.

A project .stepcode/config.toml gets no copy: the repository owns that
directory, files there would show up in git status, and a relative path from it
cannot reach the global one. The directive is added when a global config is
written for another reason, never as a write of its own — a launch refreshes the
schema copies and leaves the user's file untouched.

models.json keeps two shapes. Its schema is also the loader's validator, so
it stays open to unknown fields: a newer Step may add one and an older binary
must still load the file. The editor gets a closed copy rendered from the same
tree, so a misspelled baseUrl is visible where it is written. A test proves the
two copies differ by nothing but that flag, and that a declared record such as
samplingParams stays open.

pnpm run check:config-schema renders both again and fails when the committed
copy is stale.

Documentation corrected against the code

The shipped settings page opened by naming a ~/.stepcode/agent/settings.json
the product has not read for several releases, so anyone following it wrote a
file nothing opens. It also documented compaction.triggerRatio as 0.85 (the
constant is 0.9), compaction.contextProjection as clm-v1 (the default is
off), models.json and auth.json one directory too deep, a broken provider
as skipped when the whole file is rejected, and the npm install directory and
resource base directory one level too high.

The theme schema links in themes.md and in five built-in themes pointed at
repository paths that return 404. They now point at the copy shipped beside the
themes.

Drift guards

The generated file is compared as text by check:config-schema, which catches a
changed key but not a changed number. The tests add:

  • every documented default against the constant the loader reads;
  • every alias the settings manager honors, so an editor cannot reject a file the
    product still reads;
  • every field the MCP loader reads, extracted from its source;
  • a file the product writes against the schema it ships;
  • every TOML example in the configuration docs, parsed and validated;
  • both directions of the type contract (a schema that loses a member was
    previously undetected — the assertion was written so that it could never fail);
  • a static import-graph budget for cli/args.ts, so the config subsystem cannot
    be pulled back onto the startup path. That happened once on this branch: it
    took startup from 25 to 148 modules and ~500ms before anything ran.

Size

45 files, +7436 / −840. Of that, 4339 lines are generated JSON (both schemas plus
the theme schema, 790 of which replace a hand-written file); about 3100 lines are
hand-written, of which roughly 900 are tests.

Validation

  • pnpm run check passes, including the new check:config-schema.
  • ./test.sh passes: 5632 passed / 59 skipped in packages/coding-agent, 762 in
    apps/cli, no failures in any package.

Follow-up

A separate PR adds step config check, which answers the other half of the
reported problem — "I configured it, why did nothing change" — by validating the
files against this schema before a session starts. It builds on this branch and
will be rebased onto main once this merges.

Writing a setting in `config.toml` or `models.json` had no way to be checked
before starting a session: an unknown key was carried along and ignored, and
an out-of-range value fell back to its default with one line of output. The
only way to learn the accepted keys was to read the source, which is what the
reported workflow was doing against the compiled binary.

The key definitions are now the single source: `settings-schema.ts` declares
each settings table once as TypeBox, the TypeScript types are derived from it
with `Static<>`, and the JSON Schema is rendered from the same objects. The
`models.json` shape and the theme shape follow the same pattern, so an editor
validates against the definitions the loaders actually use.

The schemas are generated into `schema/`, rendered again at runtime, and
written beside the global `config.toml`, which points at its copy with
`#:schema ./config.schema.json`. Nothing is fetched over the network and no
URL is published: an editor validates against the same build that wrote the
file, so a schema change is an ordinary code change. A project file gets no
copy -- the repository owns that directory, and a relative path from there
cannot reach the global one. The directive is added when a global config is
written for another reason, never as a write of its own, so a launch does not
touch the user's file.

`models.json` keeps its loader schema open to unknown fields, because a newer
Step may add one and an older binary must still load the file. The editor
gets a closed copy rendered from the same tree; a test proves the two differ
by nothing but that flag, and that a declared record stays open.

`step config schema [config|models] [--out <file>]` prints either schema.

The documentation carried several claims that contradicted the code: the
settings page opened by naming a `settings.json` the product has not read for
several releases, `compaction.triggerRatio` was 0.85 against a constant of
0.9, `models.json` and `auth.json` were documented one directory too deep, and
the theme schema links pointed at repository paths that return 404. Each is
corrected against the code, and the examples are now validated by a test.

`pnpm run check:config-schema` renders both schemas again and fails when the
committed copy is stale. The tests add what that comparison cannot see: every
documented default against the constant the loader reads, every alias the
settings manager honors, every field the MCP loader reads, a file the product
writes against its own schema, and a static import-graph budget for the CLI
entry so the config subsystem cannot be pulled back onto the startup path.
@liuedcson liuedcson changed the title feat(config): ship an editor schema for config.toml and models.json, and check files against it feat(config): ship an editor schema for config.toml and models.json Nov 26, 2026
`config check` ships in a follow-up branch, but its name had leaked into this
one: the `--help` summary, two schema descriptions, and two comments. A branch
that describes a command it does not provide is the same class of problem this
work exists to fix, so the references are removed rather than left for the other
branch to overwrite.
`migrateSettings` rewrites `[skills] customDirectories` into the array of the
same name plus `enableSkillCommands`, so a file that still uses the table loads
correctly. The schema only allowed the array, which made the editor reject a
file the loader reads — the same disagreement the other three legacy keys were
already listed to avoid.

`skills` now accepts either shape, with a test that both validate and a row in
the migration table.
@liuedcson
liuedcson merged commit 01adb40 into main Nov 26, 2026
2 checks passed
@liuedcson
liuedcson deleted the feat/config-schema branch November 26, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant