|
| 1 | +# aibug-gate |
| 2 | + |
| 3 | +A pre-commit / GitHub-Action quality gate whose lint rules are each **provenance-pinned to a real bug an AI code generator shipped**, with the upstream fix linked inline in every finding. |
| 4 | + |
| 5 | +The **moat is the corpus**: every rule is distilled from a real upstream PR (found and fixed in the wild), and the corpus grows as the [gift-PR fleet](https://github.com/patchwright/patchwright-ops) finds and fixes more real AI bugs. Each finding cites its evidence link so the reviewer can read the original bug, the original fix, and decide whether the same class is in flight in their own code. |
| 6 | + |
| 7 | +A finding without its evidence link is just another lint hit. With it, the rule is auditable. |
| 8 | + |
| 9 | +## Why this exists |
| 10 | + |
| 11 | +Off-the-shelf linters catch style. Type checkers catch type errors. Neither catches the *class* of bug that AI code generators ship reliably enough to be worth a named rule: `str.replace` used as a strip, `str.split(' ')` where `str.split()` was meant, an argparse flag that parses then silently vanishes, a `not A and B or C` precedence slip. Each of these is **provenance-pinned**: a real maintainer merged (or is reviewing) a real fix for it right now. `aibug-gate` is the discipline that turns those one-off fixes into reusable CI gates. |
| 12 | + |
| 13 | +## The 5 seed rules (v0.1) |
| 14 | + |
| 15 | +Each entry is pinned to a verified upstream fix. The `generator` field is framed honestly as "bug-class commonly shipped by AI generators" rather than attributing a specific bug to a specific tool — that inference is not proven, and `aibug-gate` does not fabricate attributions. |
| 16 | + |
| 17 | +| Code | Bug class | Severity | Upstream fix | Status | |
| 18 | +|------|-----------|----------|--------------|--------| |
| 19 | +| AB001 | `str.replace` as prefix/suffix strip (use `removeprefix`/`removesuffix`) | high | nephila/giturlparse#152 | merged | |
| 20 | +| AB002 | `str.split(' ')` keeps empty tokens (use `str.split()`) | medium | derek73/python-nameparser#164 | merged | |
| 21 | +| AB003 | Deep negative index `x[-k]` with no length guard → `IndexError` | medium | savoirfairelinux/num2words#661 | open | |
| 22 | +| AB004 | argparse option defined but its dest never read (flag silently ignored) | high | un33k/python-slugify#176 | open | |
| 23 | +| AB005 | `not A and B or C` precedence (`and` binds tighter than `or`) | low | alexanderlukanin13/coolname#34 | open | |
| 24 | + |
| 25 | +AB001/AB004 are default-tier (low false-positive); AB002/AB003/AB005 are pedantic (opt-in via `--pedantic`). |
| 26 | + |
| 27 | +## Install |
| 28 | + |
| 29 | +### As a CLI |
| 30 | + |
| 31 | +```bash |
| 32 | +pip install git+https://github.com/patchwright/aibug-gate@v0.1.0 |
| 33 | +aibug-gate --list-rules |
| 34 | +aibug-gate path/to/your/code # default tier |
| 35 | +aibug-gate --pedantic path/to/your/code # include opt-in rules |
| 36 | +``` |
| 37 | + |
| 38 | +### As a pre-commit hook |
| 39 | + |
| 40 | +In `.pre-commit-config.yaml`: |
| 41 | + |
| 42 | +```yaml |
| 43 | +repos: |
| 44 | + - repo: https://github.com/patchwright/aibug-gate |
| 45 | + rev: v0.1.0 |
| 46 | + hooks: |
| 47 | + - id: aibug-gate # pedantic tier (catches more, may be noisy) |
| 48 | + args: [--pedantic] |
| 49 | + # or, for the low-false-positive tier only: |
| 50 | + # - id: aibug-gate-default |
| 51 | +``` |
| 52 | + |
| 53 | +### As a GitHub Action |
| 54 | + |
| 55 | +```yaml |
| 56 | +- uses: patchwright/aibug-gate@v0.1.0 |
| 57 | + with: |
| 58 | + paths: src/ # files or dirs to scan (default: '.') |
| 59 | + pedantic: 'true' # include opt-in rules (default: 'false') |
| 60 | +``` |
| 61 | +
|
| 62 | +The action installs from its own checkout, so it works the same way on a tagged release. |
| 63 | +
|
| 64 | +## What a finding looks like |
| 65 | +
|
| 66 | +``` |
| 67 | +src/app.py:42:8: AB001 [high] .replace('/blob/', "") guarded by startswith('/blob/') removes every occurrence; use str.removeprefix('/blob/') |
| 68 | + Provenance: https://github.com/nephila/giturlparse/pull/152 (merged) — str.replace-as-strip (removeprefix/removesuffix mixup) |
| 69 | +``` |
| 70 | +
|
| 71 | +The two-line shape is deliberate: the fix link is on its own line so it survives copy-paste into a PR comment, a Slack thread, or a ticket. |
| 72 | +
|
| 73 | +## Honesty notes (v0.1) |
| 74 | +
|
| 75 | +- **5 seed rules.** The detection logic is ported from [wildlint](https://github.com/patchwright/wildlint)'s `WL001`-`WL005`, which have been hardened against false positives over multiple releases. Re-deriving them from scratch would discard that discipline. The codes are re-issued as `AB001`-`AB005` to match the corpus. |
| 76 | +- **No specific generator attribution.** The `generator` field is "bug-class commonly shipped by AI generators" — `aibug-gate` does not claim "Copilot shipped this exact bug" without verified evidence. Bugs are attributed to their real upstream maintainers and fixes, not to a specific LLM tool. |
| 77 | +- **Open vs merged status.** AB003, AB004, and AB005 pin to open PRs (the bug is verified on master; the fix is under review). The status is shown in every finding so the reviewer knows whether the fix has landed upstream. |
| 78 | +- **Fleet-growing corpus.** The corpus grows as the gift-PR fleet (patchwright-ops) finds and fixes more real bugs. Each new rule adds one `dataset.jsonl` entry + one checker class — the runner resolves the provenance automatically. |
| 79 | + |
| 80 | +## Contributing a rule |
| 81 | + |
| 82 | +A new rule is two artifacts: |
| 83 | + |
| 84 | +1. **One `dataset.jsonl` line** with `id`, `bug_class`, `upstream_fix_url`, `upstream_status`, `pattern`, `severity`, and `tier`. The upstream fix MUST be a real, verifiable PR. |
| 85 | +2. **One `checkers.py` class** with the matching `code`, exposing `check(tree, path, source) -> list[Finding]`. |
| 86 | + |
| 87 | +Add a positive fixture (mirroring the origin bug) and a negative fixture (legitimate code the rule must stay silent on) to `tests/test_rules.py`. The build-honesty discipline is load-bearing: a rule that does not bite on its origin bug, or that false-positives on clean code, does not ship. |
| 88 | + |
| 89 | +## License |
| 90 | + |
| 91 | +MIT. See [LICENSE](LICENSE). |
0 commit comments