Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.

Commit 6cb8a31

Browse files
patchwrightruvnet
andcommitted
feat: aibug-gate scaffold + 5 seed provenance rules + CI hooks
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. The moat is the corpus: it grows as the gift-PR fleet finds+fixes more real AI bugs. v0.1 ships 5 seed rules (AB001-AB005), ported from wildlint's WL001-005 detection logic (already hardened against FPs) and re-pinned to a fresh dataset.jsonl. Each entry carries id, bug_class, symptom, generator, upstream_fix_url, upstream_status, pattern, severity, tier. Seed corpus (verified upstream origins): AB001 str.replace-as-strip giturlparse#152 merged AB002 str.split(' ') vs split() nameparser#164 merged AB003 unguarded x[-k] index num2words#661 open AB004 argparse dest never read slugify#176 open AB005 not A and B or C precedence coolname#34 open Runner inlines the upstream_fix_url into every finding (two-line format so the link survives copy-paste). Honesty: generator field framed as 'bug-class commonly shipped by AI generators' -- no specific tool attribution without verified evidence. Tests: 20 pass (each rule bites on its origin-bug fixture; negatives stay silent; corpus integrity gate; finding-inlines-URL gate). Self-scan: 0 findings on own source (both tiers). Co-Authored-By: claude-flow <ruv@ruv.net>
0 parents  commit 6cb8a31

15 files changed

Lines changed: 1399 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.9", "3.13"]
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install
20+
run: pip install -e . pytest
21+
- name: Tests
22+
run: python -m pytest -q
23+
- name: Smoke (python -m)
24+
run: python -m aibug_gate --version
25+
- name: Self-scan (default tier — must pass clean on own source)
26+
run: python -m aibug_gate src/aibug_gate tests
27+
- name: List rules (exercises corpus load)
28+
run: python -m aibug_gate --list-rules
29+
30+
action:
31+
# Verify the GitHub Action wrapper actually installs+runs from a clean checkout.
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Run aibug-gate action against its own source
36+
uses: ./
37+
with:
38+
paths: src/aibug_gate
39+
pedantic: 'true'
40+
continue-on-error: true # findings exit non-zero; we just want install+run to succeed

‎.gitignore‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*.egg-info/
5+
*.egg
6+
build/
7+
dist/
8+
.eggs/
9+
10+
# Virtualenvs
11+
.venv/
12+
venv/
13+
.virtualenv/
14+
15+
# Tool caches
16+
.mypy_cache/
17+
.pytest_cache/
18+
.ruff_cache/
19+
.benchmarks/
20+
21+
# uv
22+
# (uv.lock IS committed — it records the resolved dependency set for reproducible installs)

‎.pre-commit-hooks.yaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- id: aibug-gate
2+
name: aibug-gate
3+
description: >-
4+
Quality gate whose lint rules are each provenance-pinned to a real bug an AI
5+
code generator shipped, with the upstream fix linked inline in every finding.
6+
The corpus grows as the gift-PR fleet finds+fixes more real AI bugs.
7+
entry: aibug-gate
8+
language: python
9+
language_options:
10+
python_version: python3
11+
types: [python]
12+
args: [--pedantic]
13+
- id: aibug-gate-default
14+
name: aibug-gate (default tier only)
15+
description: >-
16+
aibug-gate with only the default (low-false-positive) tier enabled. Use this
17+
if the pedantic tier is too noisy for your repo.
18+
entry: aibug-gate
19+
language: python
20+
language_options:
21+
python_version: python3
22+
types: [python]

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 patchwright
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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).

‎action.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: aibug-gate
2+
description: >-
3+
Pre-commit/CI quality gate whose lint rules are each provenance-pinned to a
4+
real bug an AI code generator shipped, with the upstream fix linked inline in
5+
every finding. The corpus grows as the gift-PR fleet finds+fixes more bugs.
6+
author: patchwright
7+
branding:
8+
icon: shield
9+
color: red
10+
11+
inputs:
12+
paths:
13+
description: Files or directories to scan (space-separated).
14+
required: false
15+
default: '.'
16+
pedantic:
17+
description: Include opt-in (pedantic) rules in addition to defaults.
18+
required: false
19+
default: 'false'
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.13'
28+
- name: Install aibug-gate
29+
shell: bash
30+
working-directory: ${{ github.action_path }}
31+
run: pip install .
32+
- name: Run aibug-gate
33+
shell: bash
34+
run: |
35+
PEDANTIC=""
36+
if [ "${{ inputs.pedantic }}" = "true" ]; then
37+
PEDANTIC="--pedantic"
38+
fi
39+
aibug-gate $PEDANTIC ${{ inputs.paths }}

‎pyproject.toml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[build-system]
2+
requires = ["setuptools>=61"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "aibug-gate"
7+
version = "0.1.0"
8+
description = "Pre-commit / CI quality gate whose lint rules are each provenance-pinned to a real bug an AI code generator shipped, with the upstream fix linked. The corpus grows as the gift-PR fleet finds+fixes more real AI bugs."
9+
readme = "README.md"
10+
requires-python = ">=3.9"
11+
license = { text = "MIT" }
12+
keywords = ["lint", "linter", "ai", "copilot", "cursor", "claude-code", "static-analysis", "pre-commit", "github-action", "provenance"]
13+
classifiers = [
14+
"Development Status :: 3 - Alpha",
15+
"Intended Audience :: Developers",
16+
"Environment :: Console",
17+
"License :: OSI Approved :: MIT License",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
24+
"Topic :: Software Development :: Quality Assurance",
25+
]
26+
dependencies = []
27+
28+
[project.urls]
29+
Homepage = "https://github.com/patchwright/aibug-gate"
30+
Issues = "https://github.com/patchwright/aibug-gate/issues"
31+
32+
[project.scripts]
33+
aibug-gate = "aibug_gate.runner:main"
34+
35+
[tool.setuptools.packages.find]
36+
where = ["src"]
37+
38+
[tool.setuptools.package-data]
39+
aibug_gate = ["dataset.jsonl"]

‎src/aibug_gate/__init__.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""aibug-gate: provenance-pinned quality gate for AI-generated code.
2+
3+
Each lint rule is pinned to a real bug an AI code generator shipped, with the
4+
upstream fix linked inline in every finding. The corpus grows as the gift-PR
5+
fleet finds and fixes more real bugs.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
__version__ = "0.1.0"
11+
12+
from .runner import main # noqa: E402 (re-exported for console_scripts)
13+
14+
__all__ = ["main", "__version__"]

‎src/aibug_gate/__main__.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Allow ``python -m aibug_gate``."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
7+
from .runner import main
8+
9+
if __name__ == "__main__":
10+
sys.exit(main())

0 commit comments

Comments
 (0)