mars-schema 0.34.0

Pure schema reader and editor for Mars agent packages
Documentation
# mars-schema

Package data reading, validation, translation and editing without host I/O; the binary
owns filesystem, network, orchestration, consumer config and target lowering. Keep the
crate usable on `wasm32-unknown-unknown`: the CLI and JavaScript callers share its types
and rules, so never add a binary-side copy.

## Reading and preparation

- Route authored definitions through the shared reader. Schema-v1 authored fields are
  strict; foreign definitions go through translation and `set_aside_rejected_keys`
  so an uneditable dependency can still install. Preserve valid entries in `LoweredField`,
  `skill::LOWERED_KEYS`, and network host lists; losing a deny entry can widen permissions.
  Record lost deny/ask tools, disallowed tools, deny hosts and restriction fields as
  `field.restriction-lost` changes, exposed by `Prepared::lost_restrictions`.
- An Agent with no frontmatter is `frontmatter.missing` only where the file is schema 1: `read` and `prepare` of a `schema = 1` package go through `read_authored`. Installed trees and foreign layouts use `read_definition`, because their body-only Agents were valid when written. A consumer's `.mars-src/` and a manifest-less `mars-native` tree are classified `Schema1`, so they are checked like a package.
- Reading leaves a schema-v1 file as written; preparation rewrites only foreign
  definitions. Do not change a dependency's `requires-mars` during preparation: it gates
  whether the dependency can be read.
- A `mars.toml` without `[package]` is consumer configuration, not a package manifest.
  `PrepareContext::Project` reads the project root as a `Package`, or, for consumer
  configuration, `.mars-src` as `AuthoredLocal`. A `[package]` with no `schema` is an error
  (`manifest.schema-missing`), not a package to upgrade.
- Prepare before applying consumer filters and renames. Check skill body links against
  the actual installed layout after those choices: preparation cannot know whether a
  target from another package will be installed. Use `selection::select` and its
  `SelectionResult` for Agents, skills and bootstrap documents so callers agree.
- Read consumer dependency entries strictly. A package dependency's conflicting
  filters or `plugin` plus `dialect` warn instead, so a dependent can still sync.
- Preserve `.git` and `node_modules` in Mars skill payloads even though foreign
  skill imports exclude them: installed Mars packages depend on that behavior.
- Report wrong-transport MCP server fields as ignored rather than failing the parse,
  so a usable server can still install.

## Checking

`check.rs` is what `mars check` and the WASM `check` report about a package's own files. A rule about an Agent, a skill or `mars.toml` goes there, never in `src/cli/check.rs`. It reports what is true of the package wherever it runs: what a harness target can't express, or an older Mars can't read (the `requires-mars` floor, hooks, lost-in-lowering fields), stays in the binary. Grade a finding by what the author loses: `Error` it won't load or install, `Warning` something written won't take effect, `Info` nothing written is lost. For each path the result is `prepare`'s findings plus the check's own, so dropping the check's codes must leave what `prepare` returns for the path; both runners hold that. A new code is a fixture under `fixtures/check/` and a row in the code lists of both runners.

## Compatibility

- Dependency `version` and `requires-mars` / `requires-meridian` use different
  grammars: bare `0.20` is a caret range for a dependency and a minimum for a
  requirement. Keep their parsers distinct.
- `version::keeps_lock` keeps a lock under `PreferLockThenLatest` when every
  semver constraint allows it, it is not excluded, and no request asks for latest,
  without checking whether its tag still exists upstream. This lets a locked
  install replay without listing tags. Every constraint must hold at the chosen ref;
  incompatible pins and a pin beside a range fail.
- Preserve the published read, edit, preparation, selection and hook output shapes,
  including authored spellings and ordered values, across Rust and WASM. The fixtures
  under `fixtures/` exercise both implementations; review changes to expected output
  as contract changes. Keep `serde_json/preserve_order` off: feature unification
  would change the binary's JSON output. Use `OrderedValue` for authored order.
- Keep frontmatter size and nesting limits: YAML scanning grows quadratically with
  nesting, so a size limit alone does not bound parse time. Keep semantic parsing and
  structural scanning distinct when changing YAML handling.

## Config keys

`keys.rs` is the table of gated keys (`GATED`): a key an older Mars ignores or misreads, with
the release that first read it. It lists keys Mars reads today and when they arrived, nothing
about keys it no longer reads. A new gated key is a row and nowhere else; say on the row's
comment what the older Mars does with the key.

A file's version floor is `keys::floor` over the keys it uses, and every caller gets those from
`keys::used(document, Document)`, which walks a parsed `mars.toml`. The uses that live in other
files are the caller's to add as `Used::hook` and `Used::profile_rule` (`check::package_floor`
does, and `mars check` and `mars version` both call it); the consumer reader
(`config/read.rs`) calls `used` with `Document::Consumer`. A gated row is `Gate::Present` (the
key's presence) or `Gate::Rules` (each rule whose action restricts: `deny` and `ask`, not
`allow`). A consumer floor is reported only above `MIN_MARS_VERSION_SINCE`, since a Mars older
than that ignores `min_mars_version`.

What a reader does with a key it has no field for depends on the table, nothing else:

- A table of entries (`[settings.tools]`, a profile's `tools`, `[dependencies]`): the key is an
  entry, and a key or value that is not a valid one is an error at its line.
- A table of fields (`[settings]`, `[agents.<name>]`, `[package]`, frontmatter): the key is not
  read and stays in the file. It is one `Info`, `field.unknown`, built by
  `diagnostic::unknown_field`, with the text `unknown_key_message` builds. Don't add a code, a
  level or a text for a particular key; the one exception is `retired.rs`, below.
- A table that refuses what it does not define (a model-policy `override`, a project's
  `hook.toml`): an error that lists the keys it takes.

A value of a key Mars reads stays closed: an unknown value is an error listing what is allowed.

`retired.rs` is the one table of keys Mars moved off: (scope, key, anchor on
`docs/config/retired-keys.md`). A reader that meets one emits `field.retired` as a Warning, because
the user loses what it set, often a restriction (`disallowed-tools`, `permission`,
`network_deny`). Delete the module and each key falls back to `field.unknown`, except a
`harness-overrides.flow` block, which becomes a `harness.unknown` Warning and stays a passthrough. Add a key to it
only with the page's entry that says how to fix it. It covers keys of tables of fields and the
`harness-overrides` namespaces; a model-policy `override` refuses what it does not define, so
its retired keys stay an error that lists the keys it takes. A retired key is not a value: a
value of a key Mars reads (`approval: yolo`) is an ordinary invalid value. The spellings of the
Agent deny list (`tool_policy::DISALLOWED_SPELLINGS`) are also read by the translators, so
they live there and `retired.rs` takes the Agent and Skill tool-policy rows from them and from
`skill::tool_keys()`. The other code that names a key from
outside is a translator from another format (`claude/`, `harness_overrides`, `set_aside`).