|
| 1 | +# Copilot Instructions for posixutils-rs |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +posixutils-rs is a suite of Rust-native core command line utilities (cp, mv, awk, make, vi, etc.) using POSIX.2024 as the baseline specification. The goal is to create clean, race-free userland utilities that are POSIX compliant, maximizing compatibility with existing shell scripts while minimizing bloat. |
| 6 | + |
| 7 | +## Core Principles |
| 8 | + |
| 9 | +1. **POSIX Compliance First**: The primary specification is POSIX.2024. Implement features according to POSIX specification before considering GNU/BSD extensions. |
| 10 | +2. **Minimalism**: Avoid bloat. Only implement widely-used GNU/BSD extensions, not obscure rarely-used options. |
| 11 | +3. **Clean Rust Code**: Each utility should look like a standard Rust CLI program with minimal dependencies. |
| 12 | +4. **Race-Free**: Design utilities to be race-free in concurrent environments. |
| 13 | + |
| 14 | +## Development Guidelines |
| 15 | + |
| 16 | +### Code Style |
| 17 | + |
| 18 | +1. **Always run `cargo fmt`** - This is required and enforced in CI. |
| 19 | +2. **No warnings**: Code must compile without warnings. Never use `#[allow(dead_code)]`. |
| 20 | + - If code is unused, delete it |
| 21 | + - If code is only used in tests, use `#[cfg(test)]` |
| 22 | +3. **Readability over cleverness**: Code should be readable by unfamiliar developers. Avoid dense, uncommented code. |
| 23 | +4. **Write small functions**: Break up large functions. The compiler can inline as needed. |
| 24 | +5. **Priority order**: Correctness, readability, performance (in that order). |
| 25 | + |
| 26 | +### Dependencies |
| 27 | + |
| 28 | +1. **Prefer "std only"**: Minimize external crate dependencies. |
| 29 | +2. **Use tiny crates**: When external crates are needed, prefer tiny, single-purpose crates like `tempfile`. |
| 30 | +3. **Avoid mega-crates**: Do not introduce large dependency trees. |
| 31 | +4. **Standard dependencies**: The project commonly uses: |
| 32 | + - `clap` for command-line parsing |
| 33 | + - `libc` for system calls |
| 34 | + - `regex` for pattern matching |
| 35 | + - `chrono` for date/time handling |
| 36 | + - `plib` (internal) for common utilities |
| 37 | + |
| 38 | +### Testing |
| 39 | + |
| 40 | +1. **Test pattern**: |
| 41 | + - Pre-generate input data files |
| 42 | + - Run system OS utility on input data, generating known-good output |
| 43 | + - Store input and output in-tree as known-good data |
| 44 | + - Write TestPlan that executes our utility using static input/output data |
| 45 | +2. **Use plib's TestPlan framework** for integration tests. |
| 46 | +3. **Quick tests only in `cargo test`**: Longer tests or tests requiring root should use feature flags like `posixutils_test_all` or `requires_root`. |
| 47 | +4. **All commits should pass tests**: Keep `git bisect` working. |
| 48 | + |
| 49 | +### Building and Testing Commands |
| 50 | + |
| 51 | +- **Build**: `cargo build --release` |
| 52 | +- **Test all** (long, 15+ minutes): `cargo test --release` |
| 53 | +- **Test one module**: `cargo test --release -p posixutils-SOMECRATE` |
| 54 | +- **Test with all features**: `cargo test --release --features posixutils_test_all` |
| 55 | +- **Format check**: `cargo fmt --all -- --check` |
| 56 | + |
| 57 | +### Project Structure |
| 58 | + |
| 59 | +- Each utility is typically in its own crate under a category directory (e.g., `text/`, `fs/`, `process/`) |
| 60 | +- `plib/` contains shared library code and the TestPlan framework |
| 61 | +- `ftw/` contains race-free file tree walking functionality |
| 62 | +- Integration test harness should ONLY contain `mod` statements |
| 63 | +- Test logic goes in `$module/tests/$category/mod.rs` files |
| 64 | + |
| 65 | +### Utility Lifecycle Stages |
| 66 | + |
| 67 | +When working on utilities, be aware of their maturity stage: |
| 68 | +1. **Rough draft**: Core algorithm implemented, bugs may exist |
| 69 | +2. **Feature complete**: Complete per POSIX specification |
| 70 | +3. **Test coverage**: Integration tests complete and passing 100% |
| 71 | +4. **Code coverage**: 100% automated code coverage |
| 72 | +5. **Translated**: All strings internationalized |
| 73 | +6. **Audited**: Externally reviewed for correctness and security |
| 74 | + |
| 75 | +### Commit Guidelines |
| 76 | + |
| 77 | +1. Separate logical changes into separate commits (bug fixes vs. new features) |
| 78 | +2. All commits should pass tests |
| 79 | +3. All PRs must pass tests before merging |
| 80 | +4. All code must be **copyright clean**: freshly written or from compatible open source licenses |
| 81 | + |
| 82 | +### Error Handling and Internationalization |
| 83 | + |
| 84 | +- Support internationalization for error messages |
| 85 | +- Use `gettext-rs` for i18n when appropriate |
| 86 | +- Handle common OS errors with user-friendly messages |
| 87 | + |
| 88 | +### Platform Support |
| 89 | + |
| 90 | +- Primary targets: Linux and macOS |
| 91 | +- The project should work on Unix-like systems |
| 92 | +- Consider platform-specific features when necessary, but keep code portable |
| 93 | + |
| 94 | +## What NOT to Do |
| 95 | + |
| 96 | +1. **Don't add GNU-specific bloat**: Only add GNU features that users cannot live without. |
| 97 | +2. **Don't break POSIX compliance**: Always verify changes maintain POSIX compliance. |
| 98 | +3. **Don't introduce race conditions**: Use race-free patterns, especially with file operations. |
| 99 | +4. **Don't add commented-out code**: Delete unused code instead. |
| 100 | +5. **Don't add dependencies casually**: Each new dependency should be justified and minimal. |
| 101 | + |
| 102 | +## When Implementing New Features |
| 103 | + |
| 104 | +1. Check the POSIX.2024 specification first |
| 105 | +2. Review the existing utility's stage of maturity |
| 106 | +3. Follow the code style of similar utilities in the project |
| 107 | +4. Add integration tests following the TestPlan pattern |
| 108 | +5. Ensure `cargo fmt` and `cargo test --release` pass |
| 109 | +6. Consider whether the feature aligns with project minimalism goals |
| 110 | + |
| 111 | +## References |
| 112 | + |
| 113 | +- POSIX specification: https://pubs.opengroup.org/onlinepubs/9699919799/ |
| 114 | +- Minimum Rust version: 1.84.0 |
| 115 | +- License: MIT |
0 commit comments