|
| 1 | +# AGENTS |
| 2 | + |
| 3 | +This repository is a Rust CLI forked from Bonnie with a `bx` binary. This file is for agentic coding tools. |
| 4 | + |
| 5 | +## Quick Orientation |
| 6 | +- Primary task runner is Bonnie; project scripts live in `bonnie.toml`. |
| 7 | +- Source lives in `src/` with binaries under `src/bin/main.rs`. |
| 8 | +- Tests are Rust unit + integration tests under `src/` and `tests/`. |
| 9 | + |
| 10 | +## Build, Lint, Test |
| 11 | + |
| 12 | +### Bonnie (preferred) |
| 13 | +`bonnie.toml` defines convenience scripts. Use `bx <script>`: |
| 14 | + |
| 15 | +- `bx build` -> `cargo build` |
| 16 | +- `bx test` -> `cargo watch -x "test"` |
| 17 | +- `bx check` -> `cargo check && cargo fmt -- --check && cargo clippy && cargo test` |
| 18 | +- `bx dev -- <args>` -> `cd src && cargo run --bin bx -- <args>` |
| 19 | + |
| 20 | +### Direct Cargo |
| 21 | +- Build: `cargo build` |
| 22 | +- Run binary: `cargo run --bin bx -- <args>` |
| 23 | +- Run all tests: `cargo test` |
| 24 | +- Format: `cargo fmt` |
| 25 | +- Format check (CI style): `cargo fmt -- --check` |
| 26 | +- Lint: `cargo clippy` |
| 27 | +- Full validation (CI): `cargo check && cargo fmt -- --check && cargo clippy && cargo test` |
| 28 | + |
| 29 | +### Single Test / Targeted Tests |
| 30 | +Cargo test filters use substring match by default (exact match requires `--exact`). |
| 31 | + |
| 32 | +- Single test by name: `cargo test test_name` |
| 33 | +- Exact test path: `cargo test -- --exact module::test_name` |
| 34 | +- Integration test file: `cargo test --test caching` |
| 35 | +- Unit tests only: `cargo test --lib` |
| 36 | +- Show output: `cargo test -- --nocapture` |
| 37 | +- Single-threaded: `cargo test -- --test-threads=1` |
| 38 | + |
| 39 | +Common integration tests: |
| 40 | +- `cargo test --test caching` |
| 41 | +- `cargo test --test known_cases` |
| 42 | + |
| 43 | +### CI/CD Build Commands |
| 44 | +From `.github/workflows/*.yml`: |
| 45 | + |
| 46 | +- CI: `cargo check && cargo fmt -- --check && cargo clippy && cargo test` |
| 47 | +- Release builds: `cargo build --release --locked` |
| 48 | +- Musl release builds: `cargo build --release --target x86_64-unknown-linux-musl --locked` |
| 49 | + |
| 50 | +## Code Style Guidelines |
| 51 | + |
| 52 | +### Formatting |
| 53 | +- `.editorconfig` enforces: 4-space indent, LF endings, UTF-8, trim trailing whitespace, final newline. |
| 54 | +- No `rustfmt.toml`; use default `rustfmt` rules. |
| 55 | +- Prefer `cargo fmt` before commits; CI enforces `cargo fmt -- --check`. |
| 56 | + |
| 57 | +### Imports |
| 58 | +Pattern in `src/*.rs`: |
| 59 | + |
| 60 | +- Group imports by origin (external crates, std, internal crate). |
| 61 | +- Use `use crate::...` for internal modules. |
| 62 | +- Combine related imports with braces (`use serde::{Deserialize, Serialize};`). |
| 63 | +- Alias with `as` for clarity (`use std::process::Command as OsCommand;`). |
| 64 | + |
| 65 | +### Naming |
| 66 | +Follow Rust conventions (consistent with existing code): |
| 67 | + |
| 68 | +- Modules, functions, variables: `snake_case`. |
| 69 | +- Types, traits, enums: `PascalCase`. |
| 70 | +- Constants/statics: `SCREAMING_SNAKE_CASE`. |
| 71 | +- Type aliases: `PascalCase`. |
| 72 | + |
| 73 | +### Error Handling |
| 74 | +Established pattern is `Result<T, String>` and user-facing error messages. |
| 75 | + |
| 76 | +- Prefer returning `Result<_, String>` from fallible functions. |
| 77 | +- Use `?` to propagate when possible, `match` for custom messages. |
| 78 | +- Error strings should be descriptive and include guidance when possible. |
| 79 | +- Only use `unwrap()` when the logic guarantees safety and the code documents why. |
| 80 | + |
| 81 | +### API/Type Patterns |
| 82 | +- Favor `impl std::io::Write` to pass output sinks for testability. |
| 83 | +- Use `Option<T>` for optional config, `Result<T, String>` for fallible paths. |
| 84 | +- Use `serde` derives (`Deserialize`, `Serialize`) where needed. |
| 85 | + |
| 86 | +### Comments and Documentation |
| 87 | +- CONTRIBUTING requires comments and updates to help/README when behavior changes. |
| 88 | +- Use `//` comments; keep them focused on intent and non-obvious logic. |
| 89 | + |
| 90 | +## Testing Conventions |
| 91 | +- Integration tests live in `tests/*.rs`. |
| 92 | +- Unit tests exist in source files (e.g., `src/version.rs`). |
| 93 | +- Tests often use helpers/macros to assert exit codes and output. |
| 94 | +- Prefer `std::io::Write` buffers in tests to avoid side effects. |
| 95 | + |
| 96 | +## Commit/Release Notes (if needed) |
| 97 | +- Conventional Commits are used for releases (see `.versionrc.json`). |
| 98 | +- CI expects clean formatting + clippy (same as `bx check`). |
| 99 | + |
| 100 | +## Cursor/Copilot Rules |
| 101 | +- No `.cursor/rules/`, `.cursorrules`, or `.github/copilot-instructions.md` found. |
| 102 | + |
| 103 | +## References |
| 104 | +- `bonnie.toml`: canonical dev commands for this repo. |
| 105 | +- `.github/workflows/ci.yml`: CI validation pipeline. |
| 106 | +- `.editorconfig`: formatting rules. |
0 commit comments