Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | # Contributing to why-failed |
| 2 | |
| 3 | Thanks for helping improve local, deterministic error explanations. |
| 4 | |
| 5 | ## 1. Setup |
| 6 | |
| 7 | Requires Python 3.11+. |
| 8 | |
| 9 | ```bash |
| 10 | python -m venv .venv |
| 11 | # Windows: |
| 12 | .venv\Scripts\activate |
| 13 | # macOS / Linux: |
| 14 | source .venv/bin/activate |
| 15 | |
| 16 | pip install -e ".[dev]" |
| 17 | ``` |
| 18 | |
| 19 | ## 2. Running tests |
| 20 | |
| 21 | ```bash |
| 22 | pytest |
| 23 | pytest --cov=why_failed --cov-report=term-missing |
| 24 | ruff check . |
| 25 | mypy src |
| 26 | ``` |
| 27 | |
| 28 | ## 3. Adding a rule |
| 29 | |
| 30 | 1. Open the tool module under `src/why_failed/rules/` (e.g. `git.py`). |
| 31 | 2. Append a `Rule(...)` to the module's `RULES` list. |
| 32 | 3. Prefer unique required signals to avoid false positives. |
| 33 | 4. Keep `why` / `checks` / `fixes` short and actionable. |
| 34 | 5. Add a test in `tests/rules/test_<tool>.py`. |
| 35 | |
| 36 | ### Example rule |
| 37 | |
| 38 | ```python |
| 39 | Rule( |
| 40 | id="redis.connection_refused", |
| 41 | tool="redis", |
| 42 | title="Redis connection failed", |
| 43 | why="The application tried to connect to Redis, but the connection was refused.", |
| 44 | checks=( |
| 45 | "Is Redis running?", |
| 46 | "Is port 6379 listening?", |
| 47 | "Is REDIS_URL correct?", |
| 48 | ), |
| 49 | fixes=( |
| 50 | "docker compose up -d redis", |
| 51 | ), |
| 52 | patterns=( |
| 53 | Pattern("ECONNREFUSED", kind="exact", required=True), |
| 54 | Pattern("6379", kind="exact", required=True), |
| 55 | ), |
| 56 | confidence="high", |
| 57 | secondary=("redis",), |
| 58 | ) |
| 59 | ``` |
| 60 | |
| 61 | ### Pattern kinds |
| 62 | |
| 63 | | Kind | Default score | Use for | |
| 64 | | ---- | ------------: | ------- | |
| 65 | | `exact` | 5 | Unique literal fragments | |
| 66 | | `regex` | 3 | Structured codes / variants | |
| 67 | | `tool` | 2 | Tool name signal | |
| 68 | | `generic` | 1 | Weak supporting context | |
| 69 | |
| 70 | Mark decisive signals with `required=True`. |
| 71 | |
| 72 | ## 4. Testing a rule |
| 73 | |
| 74 | ```bash |
| 75 | why-failed "your error text here" |
| 76 | why-failed --verbose "your error text here" |
| 77 | why-failed --json "your error text here" |
| 78 | pytest tests/rules/test_redis.py -q |
| 79 | ``` |
| 80 | |
| 81 | ## 5. Code style |
| 82 | |
| 83 | - Python 3.11+ typing |
| 84 | - Ruff for lint |
| 85 | - mypy strict for `src/` |
| 86 | - No network calls, no command execution, no `eval` / `exec` |
| 87 | - Deterministic matching only (no randomness) |
| 88 | |
| 89 | ## 6. Pull requests |
| 90 | |
| 91 | - Keep PRs focused (one feature or rule family) |
| 92 | - Include tests for new rules |
| 93 | - Update examples/docs when UX changes |
| 94 | - Do not add LLM/API dependencies to the default path |