-
Notifications
You must be signed in to change notification settings - Fork 2.9k
cargo doc --output-format=markdown: generate agent-ready API docs from Cargo.lock #16720
Copy link
Copy link
Open
Labels
C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-docS-blocked-externalStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fixStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fixS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-docS-blocked-externalStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fixStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fixS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Problem
AI coding agents (GitHub Copilot, Claude, Cursor, etc.) reason from training-data
snapshots of API documentation. That data goes stale fast. An agent working in your
project may reference a
serdeortokioAPI from a version months older than whatis pinned in your
Cargo.lock, producing code that does not compile.Vercel measured this concretely: providing agents with version-matched documentation
raised task pass rate from 53% to 100% (https://vercel.com/blog/agents-md-outperforms-skills-in-our-agent-evals).
The key insight is that agents perform dramatically better when given the exact API
surface of the exact versions you have pinned, not a best-guess from training data.
Today there is no first-party way to generate that documentation. Users must either:
AGENTS.md/CLAUDE.mdentries by handThis is a gap at the ecosystem level. Every Rust project using AI agents has this
problem, and
cargo docis the natural place to solve it — it already knows theexact crate graph, versions, and source.
Proposed Solution
Add
--output-format=markdowntocargo doc(andcargo rustdoc), gated behind-Zunstable-optionsinitially.Running:
produces
target/doc/markdown/containing:.mdfile per documented crate (e.g.serde.md,tokio.md)index.mdlisting every crate, its pinned version, and a short descriptionThe implementation lives entirely in Cargo — no changes to rustdoc are needed.
We reuse the existing
--output-format=jsonrustdoc output as an intermediateand post-process it into Markdown in a new
ops/cargo_markdown_doc.rspass,following the same pattern already established by
-Zrustdoc-mergeable-info.Key design points:
serde_jsonis already a dependency of Cargo — no new dependencies are addedserdestructs mirroring therustdoc JSON schema, driven by
format_versionfor compatibility checking.jsonis not newer than its.md, rendering is skippedUserIntent::Doc { json: bool }is replaced withoutput_mode: DocOutputModeenum (
Html | Json | Markdown), cleaning up an existing boolean smell--openopenstarget/doc/markdown/index.md(workspace)in the index so agents know whatthey can modify vs. what is an external dependency
The generated
index.mdincludes a ready-to-paste snippet forAGENTS.md/CLAUDE.mdpointing agents at the version-exact docs.Stabilization path: land unstable, gather feedback from the agent tooling
community on output format, stabilize once settled.
This is a natural extension of what
rustdoc --output-format=jsonalreadyprovides — optimized for language model reading patterns rather than downstream
tooling, and integrated into the standard
cargo docworkflow every Rustdeveloper already uses.
Notes
No response