rust-2026-template
AGENTS.md15 starsChanged 5 months agoMITView on GitHub
2026 Best Practice Rust Template - This is the single canonical instruction file for all AI agents. Tool-specific files (CLAUDE.md, GEMINI.md, etc.) are thin adapters that point here. The skills index is auto-generated from skill frontmatter. Do not edit the table below manually. Regenerate after adding/modifying skills: Skill symlinks are managed automatically. After cloning, run: CLI-specific directories read from .agents/skills/ via symlinks: - .claude/skills/ → Claude Code - .qwen/skills/ → Qwen Code - .gemini/, .opencode/, .windsurf/ → Read directly The…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository29 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- anti-ai-slopSkill
- architecture-diagramSkill
- atomic-commitSkill
- build-rustSkill
- codacySkill
- crates-io-name-checkSkill
- dora-reportSkill
- goap-agentSkill
- harnessSkill
- issue-triageSkill
- lint-rustSkill
- metrics-reporterSkill
- privacy-firstSkill
- release-rustSkill
- reviewing-pull-requestsSkill
- secret-lintSkill
- self-fix-loopSkill
- skill-creatorSkill
- skill-evaluatorSkill
- stacked-prsSkill
- task-decompositionSkill
- test-rustSkill
- tokio-performanceSkill
- triz-analysisSkill
- triz-solverSkill
- verify-actionsSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
19 rules. About 0 are common, 4 are distinctive, and 15 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
15
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 77
Async: Use tokio when you need a runtime.
- Very specific: line 82
Diagnostics & PR Context Behavior: When do-harness is absent, use ./scripts/doctor.sh and ./scripts/quality-gates.sh.
- Very specific: line 85
Workspace documentation tests: Run cargo test --workspace --doc --all-features so restricted Cargo default-members cannot hide doctests in …
- Very specific: line 89
Safe Loading: Use file.take(limit) and is_file() check before reading.
- Very specific: line 92
Secrets: Never hardcode; use environment variables or .env.
- Very specific: line 93
Template Portability: Never hardcode project name, repo URL, or author across source files.
- Very specific: line 97
Docs: All public items must have /// doc comments.
- Distinctive: line 98
TDD: Add or update tests before implementing logic.
- Very specific: line 99
Snapshots: Treat snapshot changes as behavior changes.
- Very specific: line 100
Search: Always use --exclude-dir=target (and .git) in search commands.
- Very specific: line 101
Context: Run bash scripts/generate-llms-txt.sh after significant arch changes.
- Very specific: line 106
Discover: Read code patterns, module structure, and .agents/ci/ci-summary.md.
- Distinctive: line 108
Test-First: Add or update tests before logic implementation.
- Distinctive: line 109
Implement: Write code adhering to conventions.
- Very specific: line 110
Quality Check: Run ./scripts/quality-gates.sh.
- Distinctive: line 111
Commit: Use conventional commit format.
- Very specific: line 121
After completing any task, write a JSON event file to .agents/events/YYYY/MM/DD/.
- Very specific: line 128
If a release-failure issue is open:
- Very specific: line 129
Create a hotfix/ branch and apply the minimal fix.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Agent Coding Contract
2026 Best Practice Rust Template - This is the single canonical instruction file for all AI agents. Tool-specific files (
CLAUDE.md,GEMINI.md, etc.) are thin adapters that point here.
Quick Reference
| Task | Command |
| Build | cargo build --workspace |
| Quality | ./scripts/quality-gates.sh |
| Tests | cargo nextest run --workspace |
| Setup | ./scripts/bootstrap.sh |
| Diagnostics | ./scripts/doctor.sh |
Project Structure
.agents/skills/: Executable task knowledge and canonical workflows..agents/skills/harness/: Harness engineering — sensor response protocol and self-correction.crates/: Workspace members (libraries and applications).scripts/: Development, quality, and release automation.plans/adr/: Architecture Decision Records..githooks/: Pre-commit quality enforcement.AGENTS.md: THIS FILE (Canonical Project Contract).
Agent Skills (.agents/skills/)
The skills index is auto-generated from skill frontmatter. Do not edit the table below manually.
Regenerate after adding/modifying skills:
bash scripts/generate-skills-md.sh<!-- AUTO-GENERATED: see .agents/SKILLS.md for full table -->Consult .agents/SKILLS.md for the complete skills index, or read individual skill docs at .agents/skills/<name>/SKILL.md.
Multi-Agent Support
Skill symlinks are managed automatically. After cloning, run:
./scripts/bootstrap.sh # One-command setup
./scripts/doctor.sh # Environment diagnosticsCLI-specific directories read from .agents/skills/ via symlinks:
.claude/skills/→ Claude Code.qwen/skills/→ Qwen Code.gemini/,.opencode/,.windsurf/→ Read directly
Session Bootstrap
The repository includes a SessionStart hook to auto-inject project context at the start of an agent session. This helps agents orient themselves quickly without manual discovery.
- Hook:
hooks/session-start.sh - Config:
docflow.json - Integration: Registered in
.claude/settings.jsonfor Claude.
Cross-Repo Context
Derived repositories should check .agents/context/ for shared conventions and related repository links.
.agents/context/external-repos.json: Links to related repos and their agent context URLs.agents/context/shared-conventions.md: Cross-repo coding conventions (commit format, branch naming, PR requirements)
Merge precedence: Local repo instructions > imported context > template defaults.
Coding Conventions
Rust & Concurrency
- Edition: Rust 2024 (MSRV 1.88). Edition 2024 requires ≥1.85; 1.88 is intentional for broader codespace/toolchain compatibility. Do not bump MSRV unless required by a dependency. https://doc.rust-lang.org/edition-guide/rust-2024/index.html
- Versions:
VERSION/ workspace0.0.0is the adopter app version (start here). Template meta-releases (e.g. v0.3.x) live only in.template/CHANGELOG-TEMPLATE.md— do not sync them intoVERSION. - Safety:
#![forbid(unsafe_code)]at workspace and crate roots. - Errors:
thiserrorfor libraries,anyhowfor binaries. Nounwrap()in libs. - Async: Use
tokiowhen you need a runtime. CLI apps that use async: prefer#[tokio::main(flavor = "current_thread")]. Syncmainis fine when no async is required (sample-app). - Async Safety & Execution: Choose execution models based on workload characteristics: keep short bounded CPU work on Tokio worker threads, offload genuinely blocking operations or long CPU work to
spawn_blockingor dedicated worker pools, default to bounded concurrency/channels for backpressure, and keep lock scopes minimal (never across.await). Reference.agents/skills/tokio-performance/SKILL.mdfor Tokio architecture choices. - Tracing: Minimize CLI tracing metadata (thread IDs/names) unless high-concurrency.
- Quality SSOT:
./scripts/quality-gates.sh(thextaskengine) is the single source of truth for all project quality tiers, Cargo compilation, lints, tests, and security checks. - Harness & Tool Ownership:
xtaskowns project quality checks and telemetry (.agents/ci/quality-run.json).do-harnessis an optional agent tool (scripts/setup-harness.sh) used for agent diagnostics (do-harness doctor) and PR readiness (do-harness pr review,do-harness pr ready).do-harness.tomldelegates quality verification to./scripts/quality-gates.shwithout running duplicate Cargo/clippy/test passes. Never treat one tool's green status as proof that the other tool's checks ran. - Diagnostics & PR Context Behavior: When
do-harnessis absent, use./scripts/doctor.shand./scripts/quality-gates.sh. If no PR context orghCLI is available,do-harness pr review/do-harness pr readyreport missing PR context gracefully. Uncommitted working tree changes or stale evidence require a fresh./scripts/quality-gates.shrun. - Verification tiers: Which checks run for each lifecycle trigger (pull request / protected branch / scheduled / release) is configured in
config/xtask.json(tiersmap:pull-request,protected-branch,scheduled,release) — not in workflow YAML. Override per run viaxtask quality run --tier <name>or$XTASK_TIER. Legacy namesfast-prandfull-gate/allare aliases forpull-requestandprotected-branch. - When-changed check selection:
xtask quality run --changed-from <ref>uses declarativewhen_changedglob mappings inconfig/xtask.json(e.g.crates/**/*.rs-> Rust checks,scripts/**/*.sh-> ShellCheck). Usextask quality explain --changed-from <ref>to inspect selected vs skipped checks and matched patterns. Unreadable git state fails closed by selecting all checks and recordingfallback_used: true. - Workspace documentation tests: Run
cargo test --workspace --doc --all-featuresso restricted Cargodefault-memberscannot hide doctests in other members.
Security & Configuration
- Hardening: Enforce
#[serde(deny_unknown_fields)]on config structs. - Safe Loading: Use
file.take(limit)andis_file()check before reading. - Validation: Sanitize strings (
is_control()) and enforce bounds on numeric fields. - Dependencies: Declare versions in
[workspace.dependencies]with caret ranges (e.g."1"≡^1). Library/template crates should ignoreCargo.lock(rely onCargo.tomlconstraints); binary applications should commit it for reproducible builds. Audit withcargo treeanddeny.toml. Prefer lockfile pins over exact=requirements in manifests. https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html - Secrets: Never hardcode; use environment variables or
.env. - Template Portability: Never hardcode project name, repo URL, or author across source files. All project-specific values must derive from
Cargo.tomlat runtime or be rewriteable viascripts/init-template.sh. Avoid magic number thresholds — define named constants.
Quality & Workflow
- File Size: Max 500 LOC per source file.
- Docs: All public items must have
///doc comments. - TDD: Add or update tests before implementing logic.
- Snapshots: Treat snapshot changes as behavior changes. Inspect them with
cargo insta reviewand accept only intentional, deterministic output changes; never update snapshots just to clear a failing test. - Search: Always use
--exclude-dir=target(and.git) in search commands. - Context: Run
bash scripts/generate-llms-txt.shafter significant arch changes. - Commits: Strictly use lowercase for the subject line (e.g.,
fix(scope): add ...notfix(scope): Add ...). Sentence-case or start-case will fail CI.
Change Workflow
- Discover: Read code patterns, module structure, and
.agents/ci/ci-summary.md. - Plan: Identify affected files and required test coverage.
- Test-First: Add or update tests before logic implementation.
- Implement: Write code adhering to conventions.
- Quality Check: Run
./scripts/quality-gates.sh. - Commit: Use conventional commit format.
Stacked PRs (Optional)
For large features with 3+ distinct concerns, stacked PRs are available via gh stack.
This is OPTIONAL — default to single-PR atomic commits. See .agents/skills/stacked-prs/SKILL.md.
Requires GitHub and gh CLI. Install: gh extension install github/gh-stack
Agentic Metrics Reporting
After completing any task, write a JSON event file to .agents/events/YYYY/MM/DD/.
This event-based pattern is also used for CI benchmarks in benchmarks/events/ to prevent merge conflicts.
See .agents/skills/metrics-reporter/ for the schema and event writing procedures.
Set human_interventions > 0 if a human corrected your code or provided rework instructions.
Release Failures (Priority 1)
If a release-failure issue is open:
- Create a
hotfix/branch and apply the minimal fix. - Open a PR with the
hotfixlabel. - Close the issue with:
Recovered at: <TIMESTAMP>. FDRT: <HOURS>.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

