AI coding agents can edit files, run shell commands, and touch infrastructure. One bad rm -rf, force-push, or docker compose down -v can wipe hours of work or production data.
| 1 | # Contributing to agent-guard |
| 2 | |
| 3 | Thanks for helping make agent-guard safer and clearer. |
| 4 | |
| 5 | ## Development setup |
| 6 | |
| 7 | ```bash |
| 8 | python -m venv .venv |
| 9 | source .venv/bin/activate # Windows: .venv\Scripts\activate |
| 10 | pip install -e ".[dev]" |
| 11 | ``` |
| 12 | |
| 13 | ## Testing |
| 14 | |
| 15 | ```bash |
| 16 | pytest |
| 17 | pytest --cov=agent_guard --cov-report=term-missing |
| 18 | ``` |
| 19 | |
| 20 | Coverage target: **>90%**. |
| 21 | |
| 22 | Never execute destructive commands in tests. Mock `subprocess.run` for `run` / BLOCK paths. Prefer harmless commands such as `python -c "print('hello')"`. |
| 23 | |
| 24 | ## Linting and types |
| 25 | |
| 26 | ```bash |
| 27 | ruff check . |
| 28 | mypy src |
| 29 | ``` |
| 30 | |
| 31 | ## Adding rules |
| 32 | |
| 33 | 1. Implement in `src/agent_guard/rules/` |
| 34 | 2. Register with `@register_rule` |
| 35 | 3. Keep analysis **static** — no network, no Docker/git execution, no DB connections |
| 36 | 4. Never log or return raw secrets — use `redactor.redact` |
| 37 | 5. Add focused tests in `tests/rules/` |
| 38 | 6. Keep decisions deterministic |
| 39 | |
| 40 | ## Security-sensitive changes |
| 41 | |
| 42 | Treat changes to parser, `run` execution, redaction, and path resolution as security-critical: |
| 43 | |
| 44 | - `check` must **never** execute user input |
| 45 | - `run` must evaluate **before** `subprocess.run` |
| 46 | - Prefer `shell=False` |
| 47 | - BLOCK must not be bypassable by `--allow-risk` |
| 48 | - Document parser limitations honestly |
| 49 | |
| 50 | ## Pull requests |
| 51 | |
| 52 | - Keep PRs focused and small when possible |
| 53 | - Include tests for new behavior |
| 54 | - Update README / examples if user-facing |
| 55 | - Ensure CI (pytest, ruff, mypy) passes on your branch |