mdx-rust
A Rust-native safe-change system for codebases.
mdx-rust points at Rust code, finds scoped hardening opportunities, validates
changes in isolation, checks project policy and behavior evals when supplied,
and only lands edits that pass Rust gates. It still supports agent optimization,
but v0.4 is aimed at ordinary Rust crates and service backends too.
The CLI is the supported product surface. The library crates are published for
installation and inspection, but their APIs remain unstable before 1.0.
Current Scope
mdx-rust is an early public beta. It is useful for experimentation and
dogfooding on Rust agent crates, but it is intentionally conservative. In
plain terms: v0.4 is good at review-first, safety-gated hardening of scoped
Rust modules, simple policy mapping, deterministic behavior evals, and the
existing agent prompt/fallback optimizer. It is not a general autonomous
refactoring engine yet.
Today it supports:
- Rust-aware source analysis with
synandtree-sitter-rust. - Process-based agent invocation with lifecycle traces.
- Prompt and AST-guarded fallback-behavior improvement strategies.
- Review-first scoped Rust hardening for normal modules through
improve. - Structured markdown policy parsing and policy-to-finding matches.
- Workspace behavior evals through
.mdx-rust/evals.json. - Optional behavior eval gates for
improve --eval-spec. - Repo doctor risk summaries with prioritized next actions.
- Bounded hardening transactions with all touched files snapshotted and rolled back on final validation failure.
- Isolated validation with
cargo checkandcargo clippy -- -D warnings. - Net-positive scoring, final real-tree validation, and rollback on failure.
- Versioned audit packets for accepted optimizer changes and hardening reports for scoped module improvements.
- JSON Schema derivations for agent-facing records such as candidates, hooks, traces, eval datasets, audit packets, and validation command records.
- Human CLI output plus machine-parseable
--jsonoutput. - Deterministic static audit checks for risky agent surfaces.
Not yet supported:
- Arbitrary multi-file accepted edits outside the hardening transaction model.
- General autonomous refactoring.
- Stable library APIs.
- Coverage, mutation testing, or full semantic behavior proofs.
- External hook runners.
- Multi-language optimization.
Safety Model
The acceptance contract is the center of the project:
- Build a targeted
ProposedEditfor one file. - Run pre-edit and pre-command hooks.
- Apply the edit in an isolated workspace.
- Run
cargo checkandcargo clippy -- -D warningswith timeouts. - Score the patched isolated workspace.
- Require a strictly positive score delta.
- Run pre-accept hooks.
- Land the already validated edit on the real tree.
- Run final validation on the real tree.
- Roll back if final validation fails or times out.
- Count the change as accepted only after landing and final validation pass.
The full non-bypass contract lives in SAFETY_INVARIANTS.md.
The implementation also uses typed rejection records and internal stage wrappers so accepted changes cannot be represented the same way as proposed or rejected candidates.
The hardening path for ordinary Rust modules is review-first by default:
mdx-rust improve validates candidate changes in an isolated workspace and
requires --apply before touching the real tree. In v0.4, passing
--eval-spec also requires the behavior commands in that spec to pass in the
isolated workspace and again after final application.
Quick Start
Install the CLI:
Try the built-in example from a checkout:
For your own Rust agent:
Artifacts are written under .mdx-rust/agents/<name>/.
For an ordinary Rust crate or backend module:
Hardening artifacts are written under .mdx-rust/hardening/.
Behavior eval specs execute local commands from your repository. Treat them as
trusted project code, review changes to them like test scripts, and prefer
deterministic commands such as cargo test, golden CLI checks, or service
contract smoke tests.
Key Commands
Every command intended for automation supports --json.
Audit Packets And Hardening Reports
Accepted changes produce versioned JSON audit packets in the experiment
directory. The optimizer 0.2 schema records:
- Agent name and iteration.
- Single-file edit scope contract.
- Accepted diff and diff hash.
- Dataset version and hash.
- Policy path and hash when available.
- Scorer id and version.
- Diagnosis model metadata and whether a live model was used.
- Hook decisions.
- Isolated and final validation command outcomes.
- Baseline, patched, delta, and holdout scores.
- Rollback status if rollback was attempted.
See docs/provenance.md for the schema contract.
v0.4 hardening runs produce versioned JSON reports under
.mdx-rust/hardening/ with findings, proposed changes, validation outcomes,
transaction status, rollback status, policy matches, behavior eval outcomes,
and workspace metadata.
Print the current JSON Schemas with:
API Stability
mdx-rust, mdx-rust-core, and mdx-rust-analysis are all published so the
CLI can be installed from crates.io.
For 0.4.x:
- The
mdx-rustCLI is supported. - The
mdx-rust-coreandmdx-rust-analysisAPIs are unstable. - Public library types may change before
1.0. - The intended facade is documented on docs.rs, but direct module usage is not a stability promise.
Project Docs
- SAFETY_INVARIANTS.md - acceptance loop and non-bypass rules.
- docs/architecture.md - module and lifecycle overview.
- docs/provenance.md - audit packet schema.
- docs/release-readiness.md - release gates and manual checks.
- ROADMAP.md - current scope and next work.
- CONTRIBUTING.md - development and safety expectations.
Contributor Rails
This repo uses a Justfile as the canonical local command surface:
These commands mirror the public CI expectations and keep coding agents from guessing which checks matter.
Status
v0.4.0 is in development as the first behavior and policy-driven hardening
release for ordinary Rust modules.
License
MIT