AI coding agents (Claude, Copilot, Cursor, Gemini, etc.) are increasingly writing Rust code. But here's the truth:
- Compiling β Correct. An AI can produce code that compiles but contains logic bugs, undefined behavior in
unsafe, or vulnerable dependencies. - "Trust me, it works" β Evidence. AI agents often claim code is ready without running any verification tools.
- No structure = no consistency. Without explicit rules, every AI session produces different quality levels.
Rust's compiler is your best friend, but it's not enough. You need a governance system that forces verification at every step.
This pack turns "write Rust correctly" into a verifiable, automated workflow. Drop it into any Rust repository and your AI coding agent is immediately governed by:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GOVERNANCE LAYER β
β β
β βΈ 8 Rules (always active) β
β Rust Contract Β· Output Format Β· Dependency Policy β
β Ops Security Β· Operating Loop Β· Quality Bar β
β Repo Memory Β· Command Safety β
β β
β βΈ 9 Skills (on-demand, loaded when relevant) β
β rust-core Β· rust-verifier Β· rust-unsafe β
β rust-supply-chain Β· rust-testing Β· rust-compile-loop β
β rust-error-triage Β· rust-kata-coach Β· rust-refactor-safelyβ
β β
β βΈ 8 Verification Gates (automated) β
β fmt β clippy β test β audit β deny β miri β geiger β vet β
β β
β βΈ Security β
β Anti-prompt-injection Β· deny.toml Β· Evidence-only output β
β No curl|sh without review Β· Command safety β
β β
β βΈ 20 Training Katas + Level 2 challenges β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Clone this pack
git clone https://github.com/GravityZenAI/rust-ai-governance-pack.git
# Copy contents into your project root
cp -r rust-ai-governance-pack/{.agent,.github,tools,docs,prompts,deny.toml} ./your-rust-project/# Required
rustup component add rustfmt clippy
# Recommended (supply chain)
cargo install cargo-audit cargo-deny
# Optional but strong (undefined behavior detection)
rustup toolchain install nightly
rustup +nightly component add miri
# Optional (unsafe footprint + supply-chain vetting)
cargo install cargo-geiger cargo-vetOr use the bootstrap script:
bash tools/install-dev-tools.shLinux/macOS:
./tools/verify.shWindows (PowerShell):
powershell -ExecutionPolicy Bypass -File .\tools\verify.ps1If all gates pass, you'll see:
β
All gates passed.
When starting a Rust coding session, tell your AI:
"This project uses
.agent/rules/for governance. Read them before writing any code. Runtools/verify.shbefore declaring any task DONE."
Or use the included prompt template:
cat prompts/RUST_TASK_TEMPLATE.mdflowchart TD
A["π― You give a task to AI agent"] --> B{"Agent reads .agent/rules/"}
B --> C["Agent loads relevant skills"]
C --> D["Agent writes code + tests"]
D --> E["Agent runs tools/verify.sh"]
E --> F1["cargo fmt --check"]
E --> F2["cargo clippy -D warnings"]
E --> F3["cargo test"]
E --> F4["cargo audit"]
E --> F5["cargo deny check"]
F1 --> G{"All green?"}
F2 --> G
F3 --> G
F4 --> G
F5 --> G
G -->|"β No"| D
G -->|"β
Yes"| H{"unsafe detected?"}
H -->|"Yes"| I["cargo +nightly miri test"]
I --> J{"Miri passes?"}
J -->|"β No"| D
J -->|"β
Yes"| K["β
Task DONE with evidence"]
H -->|"No"| K
style A fill:#1a1a2e,stroke:#CE422B,color:#CE422B
style K fill:#1a1a2e,stroke:#2ea043,color:#2ea043
style G fill:#1a1a2e,stroke:#00d4ff,color:#fff
style H fill:#1a1a2e,stroke:#ff6b35,color:#fff
style J fill:#1a1a2e,stroke:#ff6b35,color:#fff
.
βββ .agent/
β βββ rules/ # Non-negotiable rules (always active)
β β βββ 00-rust-contract.md # Definition of DONE + safety defaults
β β βββ 01-rust-output-format.md # Required output structure
β β βββ 02-rust-dependency-policy.md # Crate addition policy
β β βββ 03-antigravity-ops-security.md # Terminal, browser, extension security
β β βββ 04-rust-operating-loop.md # Spec-first, incremental, error memory
β β βββ 05-rust-quality-bar.md # Quality bar + prohibited patterns
β β βββ 06-repo-memory.md # Repository memory files system
β β βββ 07-command-safety.md # Command safety restrictions
β βββ skills/ # On-demand knowledge (loaded when relevant)
β β βββ rust-core/SKILL.md # Ownership, errors, API patterns
β β βββ rust-verifier/SKILL.md # Verification loop procedure
β β βββ rust-unsafe/SKILL.md # Unsafe/FFI governance
β β βββ rust-supply-chain/SKILL.md # Dependency hardening
β β βββ rust-testing/SKILL.md # Unit, property, fuzz testing
β β βββ rust-compile-loop/SKILL.md # Incremental compileβtestβfix loop
β β βββ rust-error-triage/SKILL.md # Systematic error diagnosis
β β βββ rust-kata-coach/SKILL.md # Kata training with scoring
β β βββ rust-refactor-safely/SKILL.md # Test-guided refactoring
β βββ workflows/ # Guided procedures
β βββ rust-verify.md # Step-by-step verification workflow
β βββ kata.md # Kata training workflow
β βββ log_decision.md # Decision logging workflow
βββ .github/
β βββ workflows/
β βββ rust-verify.yml # CI pipeline (GitHub Actions)
βββ ARCHITECTURE.md # Project architecture overview
βββ docs/
β βββ ai/
β β βββ RUST_PLAYBOOK.md # Persistent playbook for the agent
β β βββ DECISIONS.md # Architecture/style decision log
β β βββ ERROR_PATTERNS.md # 50+ known error patterns + fixes (16KB)
β βββ AUDIT.md # Security audit of this pack
β βββ AUDIT_REPORT.md # Detailed audit report
β βββ DEFINITION_OF_DONE.md # Completion criteria
β βββ EXCEPTIONS.md # Exception log
β βββ EXECUTION_PLAN.md # Execution plan template
β βββ KATA_RUBRIC.md # Kata scoring rubric
βββ prompts/
β βββ RUST_TASK_TEMPLATE.md # Copy-paste task prompt
βββ tools/
β βββ verify.sh # Linux/macOS verifier
β βββ verify.ps1 # Windows PowerShell verifier
β βββ install-dev-tools.sh # Bootstrap helper
β βββ record_evidence.sh # Evidence recording script
βββ training/
β βββ kata_suite/ # 20 Rust katas with tests
β βββ Cargo.toml
β βββ src/ (20 .rs katas + lib.rs)
β βββ tests/
βββ katas/
β βββ README.md # Kata overview and quick reference
βββ deny.toml # cargo-deny starter policy
βββ README.md # You are here
| # | Gate | Tool | What it catches | Required? |
|---|---|---|---|---|
| 1 | Format | cargo fmt --check |
Inconsistent formatting | β Always |
| 2 | Lint | cargo clippy -- -D warnings |
Common mistakes, anti-patterns, footguns | β Always |
| 3 | Tests | cargo test |
Logic bugs, regressions | β Always |
| 4 | Vulnerabilities | cargo audit |
Known CVEs in dependencies | β Always |
| 5 | Policies | cargo deny check |
License violations, banned crates, duplicates | β Always |
| 6 | Undefined Behavior | cargo +nightly miri test |
Memory bugs, UB in unsafe code | |
| 7 | Unsafe Footprint | cargo-geiger |
Unsafe usage across dependency tree | π‘ Optional |
| 8 | Supply-Chain Vet | cargo-vet |
Unvetted third-party code | π‘ Optional |
A task is DONE only when:
- A minimal diff exists (no unrelated refactors)
-
tools/verify.sh(orverify.ps1) is GREEN - The output includes: what changed, files touched, commands executed, results, checklist
- No tool output is fabricated β if blocked, the agent explains why
- No
unsafeunless explicitly required and governed (isolated, documented, tested, Miri'd)
This pack works with any AI coding assistant that supports project-level instructions:
| Agent | How to use |
|---|---|
| Google Antigravity | Rules auto-loaded from .agent/rules/, Skills from .agent/skills/ |
| Claude Code | Add rules to CLAUDE.md or reference .agent/rules/ |
| GitHub Copilot | Reference in .github/copilot-instructions.md |
| Cursor | Add to .cursorrules |
| Windsurf | Add to .windsurfrules |
| Any LLM | Include rules in system prompt or first message |
The training/kata_suite/ directory contains 20 Rust katas with Level 1 + Level 2 challenges (27 total test cases) to benchmark AI agent Rust competency:
| Kata | Concept | L1 (Benchmark) | L2 (Deliberate Trap) |
|---|---|---|---|
| 01 | Borrowing | first_word, count_words |
longest_word_and_char_count (double borrow) |
| 02 | Ownership | push_suffix, append_in_place |
maybe_prepend (conditional move) |
| 03 | Result/Option | parse_positive, safe_div |
parse_add_divide (chained ? propagation) |
| 04 | Struct methods | Counter::new/inc/add/get |
β |
| 05 | Traits | Area for Rectangle/Circle |
β |
| 06 | Generics | max_of, dedup_sorted |
β |
| 07 | Lifetimes | longest |
β |
| 08 | Iterators | squares, sum_even |
β |
| 09 | Error propagation | read_number, parse_and_add |
β |
| 10 | Modules | public_api |
β |
| 11 | Enums + match | Command::apply |
β |
| 12 | Collections/HashMap | word_frequencies |
β |
| 13 | Slices + strings | trim_prefix, is_ascii_palindrome |
β |
| 14 | Parsing | parse_csv_line, parse_pair |
β |
| 15 | RefCell basics | Bag (interior mutability) |
β |
| 16 | Split borrow | sum_and_bump_two |
β |
| 17 | Into/From | Kilometers β Meters |
β |
| 18 | Builder pattern | UserBuilder |
β |
| 19 | Threads | parallel_sum |
β |
| 20 | Small parser | sum_expr |
β |
Level 2 challenges are deliberately designed traps that exploit common AI mistakes (E0382, E0502, unwrap abuse). The AI agent must detect the pattern and produce idiomatic Rust.
cd training/kata_suite && cargo testKata Pass Rate = (passed / attempted) Γ 100% β Use this to measure your AI agent's Rust competency. See KATA_RUBRIC.md for scoring details.
|
|
Key insight: Rust correctness is not a belief β it's a chain of objective gates. The compiler is your first judge, but
clippy,miri,cargo-audit, andcargo-denycomplete the picture.
We welcome contributions! See CONTRIBUTING.md for guidelines.
Ideas for contributions:
- Additional skills (async patterns, WebAssembly, embedded)
- More verification gates
- Integration guides for specific AI agents
- Translations (especially Spanish, Chinese, Japanese)
- Real-world case studies
rust-ai-governance-pack is part of the GravityZen AI security suite:
| Project | Purpose |
|---|---|
| AI-Bastion | 8-layer infrastructure defense for AI agents on Linux |
| AI-Bastion-Guardian | Windows-side security for agents in WSL2 |
| rust-ai-governance-pack | Code governance β the rules AI follows when writing Rust |
Tip: Use all three together. rust-ai-governance-pack controls code quality. AI-Bastion secures the environment. Guardian protects the Windows perimeter.
Apache License 2.0 β Use it commercially, modify it, distribute it. Just give credit.
Created by GravityZen AI β building the future of AI-governed development.
Based on research from:
- Rust Programming Language official documentation
- ANSSI Secure Rust Guidelines
- RustSec Advisory Database
- Microsoft Pragmatic Rust Guidelines
- Google Antigravity IDE Skills and Rules system
Rust correctness is not a belief β it's a chain of objective gates.
Built by GravityZen AI Β· Governed development for the AI era
