|
| 1 | +# AGENT.md |
| 2 | + |
| 3 | +## PathSpec Ruby Development Guide |
| 4 | + |
| 5 | +This document provides instructions for AI agents working with the pathspec-ruby project. |
| 6 | + |
| 7 | +### Project Overview |
| 8 | + |
| 9 | +PathSpec Ruby is a gem that implements .gitignore-style pattern matching in Ruby. It provides both a library API and a CLI tool for testing if files match gitignore patterns. |
| 10 | + |
| 11 | +### Key Information |
| 12 | + |
| 13 | +- **Language**: Ruby (3.2-4.0.1 supported) |
| 14 | +- **Package Manager**: Bundler |
| 15 | +- **Environment Manager**: mise |
| 16 | +- **Test Framework**: RSpec |
| 17 | +- **Linting**: RuboCop 1.63.5 |
| 18 | +- **CI/CD**: GitHub Actions (multi-Ruby matrix testing) |
| 19 | + |
| 20 | +### Quick Setup |
| 21 | + |
| 22 | +```bash |
| 23 | +# Install mise (Ruby version manager) |
| 24 | +# macOS |
| 25 | +brew install mise |
| 26 | +# Other platforms: https://mise.jdx.dev/getting-started.html |
| 27 | + |
| 28 | +# Activate mise in shell |
| 29 | +eval "$(mise activate zsh)" # or bash, fish, etc. |
| 30 | + |
| 31 | +# Install Ruby and bundler versions defined in .tool-versions |
| 32 | +mise install |
| 33 | + |
| 34 | +# Install gem dependencies |
| 35 | +mise run install |
| 36 | +# or: bundle install |
| 37 | +``` |
| 38 | + |
| 39 | +### Essential Commands |
| 40 | + |
| 41 | +**Testing:** |
| 42 | +```bash |
| 43 | +# Run all tests (rubocop, unit tests, integration tests, docs) |
| 44 | +mise run test |
| 45 | +# or: bundle exec rake |
| 46 | + |
| 47 | +# Run only unit tests |
| 48 | +mise run test:unit |
| 49 | +# or: bundle exec rake spec |
| 50 | + |
| 51 | +# Run only integration tests (CLI tests) |
| 52 | +mise run test:integration |
| 53 | +# or: bundle exec rake spec_integration |
| 54 | + |
| 55 | +# Run all specs (unit + integration) |
| 56 | +mise run test:all |
| 57 | +# or: bundle exec rake spec_all |
| 58 | + |
| 59 | +# Run tests across all Ruby versions using Docker |
| 60 | +mise run test:matrix |
| 61 | +# or: bundle exec rake test_matrix |
| 62 | +``` |
| 63 | + |
| 64 | +**Code Quality:** |
| 65 | +```bash |
| 66 | +# Run RuboCop linter |
| 67 | +mise exec ruby@3.4.1 -- bundle exec rubocop |
| 68 | +# Or run via rake: |
| 69 | +bundle exec rake rubocop |
| 70 | + |
| 71 | +# Auto-fix RuboCop offenses |
| 72 | +bundle exec rubocop --autocorrect |
| 73 | +``` |
| 74 | + |
| 75 | +**Building:** |
| 76 | +```bash |
| 77 | +# Build the gem |
| 78 | +mise run build |
| 79 | +# or: gem build pathspec.gemspec |
| 80 | + |
| 81 | +# Install from source (development build) |
| 82 | +rake install |
| 83 | +``` |
| 84 | + |
| 85 | +**Documentation:** |
| 86 | +```bash |
| 87 | +# Generate man page and HTML docs |
| 88 | +bundle exec rake docs |
| 89 | +# Generates docs/index.html and docs/man/pathspec-rb.man.1 |
| 90 | +``` |
| 91 | + |
| 92 | +### Project Structure |
| 93 | + |
| 94 | +``` |
| 95 | +pathspec-ruby/ |
| 96 | +├── lib/pathspec/ # Core library code |
| 97 | +│ ├── pathspec.rb # Main PathSpec class |
| 98 | +│ └── patterns/ # Pattern matching implementations |
| 99 | +├── bin/pathspec-rb # CLI executable |
| 100 | +├── spec/ |
| 101 | +│ ├── unit/ # Unit tests for library code |
| 102 | +│ └── integration/ # Integration tests for CLI |
| 103 | +├── benchmarks/ # Performance benchmarks |
| 104 | +├── docs/ # Documentation and man page source |
| 105 | +├── Rakefile # Build tasks and test definitions |
| 106 | +├── .tool-versions # Ruby/bundler versions for mise |
| 107 | +└── pathspec.gemspec # Gem specification |
| 108 | +``` |
| 109 | + |
| 110 | +### Testing Strategy |
| 111 | + |
| 112 | +1. **Unit Tests** (`spec/unit/`): Test PathSpec class and pattern matching logic |
| 113 | +2. **Integration Tests** (`spec/integration/`): Test CLI functionality (`bin/pathspec-rb`) |
| 114 | +3. **Linting**: RuboCop enforces code style |
| 115 | +4. **Matrix Testing**: GitHub Actions tests across Ruby 3.2, 3.3, 3.4, and 4.0.1 |
| 116 | + |
| 117 | +### Common Issues & Solutions |
| 118 | + |
| 119 | +**Bundler Version Conflicts:** |
| 120 | +- The project uses specific Ruby and bundler versions defined in `.tool-versions` |
| 121 | +- Always use mise to ensure correct versions |
| 122 | +- If bundler version doesn't match `Gemfile.lock`, run: `mise run install` |
| 123 | + |
| 124 | +**RuboCop Failures:** |
| 125 | +- Method length limit is 69 lines |
| 126 | +- Use single quotes for strings without interpolation |
| 127 | +- Use `%w[]` for word arrays |
| 128 | +- Auto-fix with: `bundle exec rubocop --autocorrect` |
| 129 | +- For large data arrays, add: `# rubocop:disable Metrics/MethodLength` |
| 130 | + |
| 131 | +**CI Failures:** |
| 132 | +- Check GitHub Actions for matrix test failures |
| 133 | +- RuboCop failures are common cause |
| 134 | +- Integration test failures may indicate CLI issues |
| 135 | + |
| 136 | +### Development Workflow |
| 137 | + |
| 138 | +1. Make changes to library code in `lib/` |
| 139 | +2. Add/update tests in `spec/unit/` for library changes |
| 140 | +3. Add/update tests in `spec/integration/` for CLI changes |
| 141 | +4. Run `mise run test` to ensure everything passes |
| 142 | +5. Fix any RuboCop offenses |
| 143 | +6. Test across multiple Ruby versions with `mise run test:matrix` |
| 144 | +7. Commit changes with descriptive messages |
| 145 | + |
| 146 | +### Key Dependencies |
| 147 | + |
| 148 | +- **Runtime**: None (pure Ruby) |
| 149 | +- **Development**: |
| 150 | + - `rspec` (~> 3.10) - Testing |
| 151 | + - `rubocop` (~> 1.63.0) - Linting |
| 152 | + - `fakefs` (~> 2.5) - File system mocking for tests |
| 153 | + - `kramdown` (~> 2.3) - Documentation generation |
| 154 | + - `benchmark-ips` (~> 2.0) - Performance benchmarks |
| 155 | + |
| 156 | +### Release Process |
| 157 | + |
| 158 | +Maintainers can release via: |
| 159 | +1. Update version in `pathspec.gemspec` |
| 160 | +2. Update `CHANGELOG.md` |
| 161 | +3. Commit changes and tag/release via GitHub UI |
| 162 | +4. GitHub Actions will build and push to RubyGems |
| 163 | + |
| 164 | +### Performance Considerations |
| 165 | + |
| 166 | +- Benchmarks available in `benchmarks/pattern_scaling.rb` |
| 167 | +- Tests performance with varying pattern counts |
| 168 | +- Use `bundle exec ruby benchmarks/pattern_scaling.rb` to run |
| 169 | + |
| 170 | +### CLI Tool |
| 171 | + |
| 172 | +The `bin/pathspec-rb` executable provides: |
| 173 | +- `match` - Test if a single path matches patterns |
| 174 | +- `specs_match` - Show which patterns match a path |
| 175 | +- `tree` - List all matching files in directory tree |
| 176 | + |
| 177 | +Example usage: |
| 178 | +```bash |
| 179 | +bundle exec pathspec-rb -f .gitignore match "file.swp" |
| 180 | +bundle exec pathspec-rb -f .gitignore tree ./src |
| 181 | +``` |
0 commit comments