agentleFS
d-oitd-oit/rust-2026-template/AGENTS.md

rust-2026-template

AGENTS.md11 starsChanged 6 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

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

18 rules. About 0 are common, 4 are distinctive, and 14 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.

  • 14

    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
  1. Very specific:

    Async: Use tokio when you need a runtime.

    line 77
  2. Very specific:

    Quality SSOT: Prefer ./scripts/quality-gates.sh before push.

    line 80
  3. Very specific:

    Safe Loading: Use file.take(limit) and is_file() check before reading.

    line 86
  4. Very specific:

    Secrets: Never hardcode; use environment variables or .env.

    line 89
  5. Very specific:

    Template Portability: Never hardcode project name, repo URL, or author across source files.

    line 90
  6. Very specific:

    Docs: All public items must have /// doc comments.

    line 94
  7. Distinctive:

    TDD: Add or update tests before implementing logic.

    line 95
  8. Very specific:

    Snapshots: Treat snapshot changes as behavior changes.

    line 96
  9. Very specific:

    Search: Always use --exclude-dir=target (and .git) in search commands.

    line 97
  10. Very specific:

    Context: Run bash scripts/generate-llms-txt.sh after significant arch changes.

    line 98
  11. Very specific:

    Discover: Read code patterns, module structure, and .agents/ci/ci-summary.md.

    line 103
  12. Distinctive:

    Test-First: Add or update tests before logic implementation.

    line 105
  13. Distinctive:

    Implement: Write code adhering to conventions.

    line 106
  14. Very specific:

    Quality Check: Run ./scripts/quality-gates.sh.

    line 107
  15. Distinctive:

    Commit: Use conventional commit format.

    line 108
  16. Very specific:

    After completing any task, write a JSON event file to .agents/events/YYYY/MM/DD/.

    line 118
  17. Very specific:

    If a release-failure issue is open:

    line 125
  18. Very specific:

    Create a hotfix/ branch and apply the minimal fix.

    line 126

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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

TaskCommand
Buildcargo build --workspace
Quality./scripts/quality-gates.sh
Testscargo 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 diagnostics

CLI-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.json for 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 / workspace 0.0.0 is 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 into VERSION.
  • Safety: #![forbid(unsafe_code)] at workspace and crate roots.
  • Errors: thiserror for libraries, anyhow for binaries. No unwrap() in libs.
  • Async: Use tokio when you need a runtime. CLI apps that use async: prefer #[tokio::main(flavor = "current_thread")]. Sync main is 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_blocking or dedicated worker pools, default to bounded concurrency/channels for backpressure, and keep lock scopes minimal (never across .await). Reference .agents/skills/tokio-performance/SKILL.md for Tokio architecture choices.
  • Tracing: Minimize CLI tracing metadata (thread IDs/names) unless high-concurrency.
  • Quality SSOT: Prefer ./scripts/quality-gates.sh before push. cargo run -p xtask quality-gates delegates to that script.
  • Verification tiers: Which checks run for each lifecycle trigger (pull request / protected branch / scheduled / release) is configured in config/xtask.json (tiers map: pull-request, protected-branch, scheduled, release) — not in workflow YAML. Override per run via xtask quality run --tier <name> or $XTASK_TIER. Legacy names fast-pr and full-gate/all are aliases for pull-request and protected-branch.
  • When-changed check selection: xtask quality run --changed-from <ref> uses declarative when_changed glob mappings in config/xtask.json (e.g. crates/**/*.rs -> Rust checks, scripts/**/*.sh -> ShellCheck). Use xtask quality explain --changed-from <ref> to inspect selected vs skipped checks and matched patterns. Unreadable git state fails closed by selecting all checks and recording fallback_used: true.

Security & Configuration

  • Hardening: Enforce #[serde(deny_unknown_fields)] on config structs.
  • Safe Loading: Use file.take(limit) and is_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 ignore Cargo.lock (rely on Cargo.toml constraints); binary applications should commit it for reproducible builds. Audit with cargo tree and deny.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.toml at runtime or be rewriteable via scripts/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 review and 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.sh after significant arch changes.
  • Commits: Strictly use lowercase for the subject line (e.g., fix(scope): add ... not fix(scope): Add ...). Sentence-case or start-case will fail CI.

Change Workflow

  1. Discover: Read code patterns, module structure, and .agents/ci/ci-summary.md.
  2. Plan: Identify affected files and required test coverage.
  3. Test-First: Add or update tests before logic implementation.
  4. Implement: Write code adhering to conventions.
  5. Quality Check: Run ./scripts/quality-gates.sh.
  6. 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:

  1. Create a hotfix/ branch and apply the minimal fix.
  2. Open a PR with the hotfix label.
  3. Close the issue with: Recovered at: <TIMESTAMP>. FDRT: <HOURS>.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.