This repository is a Rust project. When working here, prefer small, correct, well-tested changes that match existing patterns over broad refactors.
- Read the touched module and nearby tests before editing.
- Keep diffs focused on the task.
- Do not rename public types, functions, modules, features, or CLI flags unless the task requires it.
- Preserve backward compatibility unless explicitly asked to break it.
- Prefer the smallest safe change that solves the problem completely.
- When behavior changes, add or update tests in the same change.
- Target idiomatic stable Rust unless the repository already requires nightly.
- Prefer clarity over cleverness.
- Use the standard library before adding dependencies.
- Avoid unnecessary cloning, allocation, and dynamic dispatch.
- Propagate errors with structured types; avoid
unwrap()andexpect()in production code. - Use
unwrap()only in tests, fixtures, or when a panic is explicitly intended and documented. - Favor iterators, enums, traits, and ownership-aware APIs when they improve readability.
- Keep functions short and single-purpose.
- Document non-obvious invariants, safety assumptions, and performance-sensitive code.
- Avoid
unsafeunless it is essential. - If
unsafeis required:- keep the unsafe block as small as possible
- explain the safety invariants in comments
- add tests that exercise the assumptions
- Do not introduce
unsafeas a micro-optimization without evidence.
- Match the async runtime already used by the project.
- Do not block inside async code.
- Be explicit about cancellation, timeouts, and backpressure where relevant.
- For concurrent code, prefer simple synchronization and minimize lock scope.
- Watch for
Send/Synccorrectness and accidental contention.
- Do not add new crates unless necessary.
- Reuse existing crates already in the repo when reasonable.
- If adding a dependency is required:
- choose a well-maintained crate
- enable the fewest features needed
- explain briefly why it is needed in the final summary
- Keep module layout consistent with the existing crate structure.
- Put unit tests close to the code they cover when that is already the local convention.
- Use integration tests for public behavior, CLI behavior, or cross-module flows.
- Do not create new top-level modules or crates unless the task clearly benefits from it.
Before finishing, run the smallest relevant checks first, then broaden if needed.
-
Run formatting:
cargo fmt --all
-
Run linting:
cargo clippy --all-targets --all-features -- -D warnings
-
Run tests:
cargo test --all-features
-
If this is a workspace and the change is isolated, prefer:
cargo test -p <crate_name>cargo clippy -p <crate_name> --all-targets --all-features -- -D warnings
-
If benchmarks or docs are relevant:
cargo test --doccargo bench
- Do not claim code works unless the relevant checks pass.
- If you cannot run a command, say so explicitly and explain why.
Before completing work, verify:
- the code builds
- formatting is clean
- clippy passes without adding blanket
allowattributes - tests cover the changed behavior
- error handling is explicit and useful
- no obvious performance regressions were introduced
- no secrets, tokens, or local paths were added
- public API changes are intentional and documented
- Prefer fixing root causes over patching symptoms.
- Preserve existing logging and tracing style.
- Do not add noisy logs.
- For hot paths, avoid incidental allocations and repeated work.
- For parsers and protocol code, include edge-case tests.
- For serde types, preserve wire compatibility unless explicitly asked otherwise.
- For CLI changes, update help text, examples, and tests if applicable.
- Update Rustdoc, README snippets, or examples when behavior changes.
- Add concise comments for tricky logic, but do not comment obvious code.
- Include usage examples for public APIs when that would help future readers.
When reporting back, include:
- What changed
- Why it changed
- What commands were run
- What passed or failed
- Any follow-up risks or assumptions
- If this repo defines local conventions in
README.md,CONTRIBUTING.md, workspace manifests, or crate-level docs, follow those over generic Rust preferences. - If a more specific
AGENTS.mdexists in a subdirectory, its instructions override this file for files in that subtree.