The pipeline flows: discover → extract → index → query
- Discovery (
rules/discovery.py): Scans a repo for rules files (CLAUDE.md, .cursorrules, etc.) organized by priority tiers defined inconfig.toml. - Extraction (
rules/extractor.py): Sends file contents to an LLM via tool use to extract structured rules. Large files are chunked usingchonkie(markdown-aware chunking). - Indexing (
rules/index.py): Deduplicates rules (text similarity), detects conflicts (contradictory severity), and builds aRuleIndex. - Query (
rules/query.py): Filters rules by task, language, scope, severity. Formats output as table, JSON, or prompt. - Eval (
rules/eval.py): Uses an LLM judge to score extraction quality (precision, recall, F1).
discover_rules_files(repo_path)→list[RuleFile], dict[str, str](files + contents)extract_rules_from_files(rule_files, contents)→list[ProcessedFile]build_index(repo_path, processed_files)→RuleIndexquery_rules(index, task=, lang=, ...)→list[Rule]
- Add the command function in
cli.pywith@app.command(name="command-name") - Use
typer.Argument/typer.Optionfor parameters - Use
console(Rich) for output, notprint() - Add tests using
typer.testing.CliRunnerintests/test_<name>.py - Update the bundled skill files if the command should be user-facing:
src/rules_agent/skill/SKILL.md(bundled package copy)skills/repo-rules/SKILL.md(plugin copy).claude/skills/repo-rules/SKILL.md(local dev copy, usesuv run)
Edit src/rules_agent/config.toml to add new file patterns or tiers. The config is loaded via pydantic-settings at module import time.
- Tests live in
tests/test_*.py, one file per module - Mock all LLM/API calls — tests must run offline
- Use
tmp_pathfixture for filesystem tests - Use
typer.testing.CliRunnerfor CLI integration tests - Run
make test(which runsuv run pytest tests -v)
typer+rich— CLI framework and terminal outputpydanticv2 — data models and validationopenai— OpenAI SDK client (works with any OpenAI-compatible API: Ollama, Anthropic, OpenAI, etc.)chonkie— markdown-aware text chunkinggitCLI — git operations (blob SHA computation viagit ls-tree)pydantic-settings— configuration management (TOML + env var loading)python-dotenv— loads.envfile at startup for API keys
Uses uv for dependency management and ruff for formatting/linting:
uv sync # install deps
make lint # ruff format --check + ruff check
make test # uv run pytest tests -v
make build # uv build (wheel + sdist)Provider settings live in .env (gitignored, loaded automatically via python-dotenv and uv run). Copy .env.example to get started. Override any setting via RULES_AGENT_ prefixed env vars or edit src/rules_agent/config.toml directly.