|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +LlmClassifier - Ruby gem for building LLM-powered classifiers with a clean DSL. Supports multiple LLM backends (ruby_llm, OpenAI, Anthropic) and optional Rails integration. |
| 4 | + |
| 5 | +- Ruby >= 3.2, RSpec, RuboCop, Zeitwerk autoloading |
| 6 | +- No Rails dependency in core; Rails integration is opt-in via `lib/llm_classifier/rails/` |
| 7 | +- CI tests against Ruby 3.4 and 4.0 |
| 8 | + |
| 9 | +## Development with Docker |
| 10 | + |
| 11 | +Ruby is not installed on the host. Use Docker to run tests and linting: |
| 12 | + |
| 13 | +```bash |
| 14 | +# Run tests and rubocop (Ruby 3.4) |
| 15 | +docker.exe run --rm -v "$(wslpath -w "$(pwd)"):/app" -w /app ruby:3.4-slim \ |
| 16 | + bash -c "apt-get update -qq && apt-get install -y -qq build-essential git 2>/dev/null && \ |
| 17 | + gem install bundler --no-document && bundle install --quiet && \ |
| 18 | + bundle exec rspec && bundle exec rubocop" |
| 19 | + |
| 20 | +# Rubocop only |
| 21 | +docker.exe run --rm -v "$(wslpath -w "$(pwd)"):/app" -w /app ruby:3.4-slim \ |
| 22 | + bash -c "apt-get update -qq && apt-get install -y -qq build-essential git 2>/dev/null && \ |
| 23 | + gem install bundler --no-document && bundle install --quiet && \ |
| 24 | + bundle exec rubocop" |
| 25 | + |
| 26 | +# Single spec file |
| 27 | +docker.exe run --rm -v "$(wslpath -w "$(pwd)"):/app" -w /app ruby:3.4-slim \ |
| 28 | + bash -c "apt-get update -qq && apt-get install -y -qq build-essential git 2>/dev/null && \ |
| 29 | + gem install bundler --no-document && bundle install --quiet && \ |
| 30 | + bundle exec rspec spec/llm_classifier/classifier_spec.rb" |
| 31 | +``` |
| 32 | + |
| 33 | +Docker Desktop must be running on Windows. The `docker.exe` command is used because Docker runs via WSL2 integration. The `-v` flag bind-mounts the project so edits on host are immediately visible. |
| 34 | + |
| 35 | +A `.devcontainer/` setup also exists for VS Code Dev Containers. |
| 36 | + |
| 37 | +## Quick Commands (inside Docker) |
| 38 | + |
| 39 | +```bash |
| 40 | +bundle exec rspec # all tests |
| 41 | +bundle exec rspec spec/llm_classifier/classifier_spec.rb # single file |
| 42 | +bundle exec rubocop # all files |
| 43 | +bundle exec rubocop -a # auto-correct |
| 44 | +gem build llm_classifier.gemspec # build gem |
| 45 | +``` |
| 46 | + |
| 47 | +## Project Structure |
| 48 | + |
| 49 | +All sibling projects are located in `/home/axium/projects/`. The `prospector` gem depends on `llm_classifier`. |
| 50 | + |
| 51 | +## Code Standards |
| 52 | + |
| 53 | +- Double-quoted strings (enforced by RuboCop) |
| 54 | +- Max line length: 120 characters |
| 55 | +- Max method length: 20 lines |
| 56 | +- RSpec example max: 15 lines, max 6 expectations per example |
| 57 | +- `Style/HashExcept` disabled (requires ActiveSupport) |
| 58 | +- `Metrics/ClassLength` exempted for `classifier.rb` and `content_fetchers/web.rb` |
| 59 | + |
| 60 | +## Git Workflow |
| 61 | + |
| 62 | +- Never push directly to main. Always create a feature branch and PR. |
| 63 | +- Run the full test suite and rubocop before creating a PR. |
| 64 | +- Version bumps in `lib/llm_classifier/version.rb` go in the feature PR, not separately. |
| 65 | + |
| 66 | +## Key Classes |
| 67 | + |
| 68 | +- `LlmClassifier::Classifier` - Core DSL and classification pipeline |
| 69 | +- `LlmClassifier::Result` - Value object returned from every classification |
| 70 | +- `LlmClassifier::Knowledge` - Domain knowledge DSL container (`method_missing`-based) |
| 71 | +- `LlmClassifier::Configuration` - Global config (adapter, model, API keys) |
| 72 | +- `LlmClassifier::Adapters::Base` - Abstract adapter interface |
| 73 | +- `LlmClassifier::ContentFetchers::Web` - HTTP fetcher with SSRF protection |
| 74 | +- `LlmClassifier::Rails::Concerns::Classifiable` - ActiveRecord integration |
| 75 | + |
| 76 | +## Component Documentation |
| 77 | + |
| 78 | +- [lib/llm_classifier/adapters/CLAUDE.md](lib/llm_classifier/adapters/CLAUDE.md) - LLM adapter contract and implementations |
| 79 | +- [lib/llm_classifier/content_fetchers/CLAUDE.md](lib/llm_classifier/content_fetchers/CLAUDE.md) - Content fetchers and SSRF protection |
| 80 | +- [lib/llm_classifier/rails/CLAUDE.md](lib/llm_classifier/rails/CLAUDE.md) - Rails integration (Zeitwerk-excluded) |
| 81 | +- [spec/CLAUDE.md](spec/CLAUDE.md) - Testing conventions |
0 commit comments