Metadata-Version: 2.5
Name: pr-preflight
Version: 0.1.0
Summary: Check a repository's contribution rules (CONTRIBUTING, AGENTS.md, PR templates) before you open a pull request.
Project-URL: Homepage, https://github.com/DipPansuriya/pr-preflight
Project-URL: Issues, https://github.com/DipPansuriya/pr-preflight/issues
Author: Dip Pansuriya
License-Expression: MIT
License-File: LICENSE
Keywords: agents,ai-policy,contributing,github,mcp,pull-request
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# pr-preflight

**Check a repository's contribution rules before you open a pull request.**

More and more projects publish rules for contributors: disclose AI use, open an issue
first, sign the CLA, use Conventional Commits, fill in the template. AI agents now
have their own rules too, in `AGENTS.md`. These rules are spread across
`CONTRIBUTING.md`, `AI_POLICY.md`, `AGENTS.md` and PR templates, and they differ
from project to project. Most contributors find out they missed one only after a
maintainer closes the PR.

`pr-preflight` reads those files, turns them into a short list of rules with the
exact line each comes from, and checks your branch or PR against them.

```console
$ pr-preflight rules ml-explore/mlx-lm
ml-explore/mlx-lm: 6 contribution rules

  required    Disclose AI tool use
      └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was
        produced, and must explicitly disclose the manner in which AI was employed."
  required    AI agents may not act on their own
      └ AGENTS.md:10 "- Do NOT write PR descriptions and commit messages for the user"
  ...
```

```console
$ cd mlx-lm && pr-preflight check --pr 2116 --ai
pr-preflight · ml-explore/mlx-lm · tool-choice-none → main (1 commits, 2 files)

  ✖ Disclose AI tool use [required]
      The PR description doesn't mention AI use.
      └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was produced, and
        must explicitly disclose the manner in which AI was employed."
  ? Understand and review any AI-assisted change yourself [required]
      Confirm this yourself.
  ...
  ✔ Include tests [recommended]
      Touches 1 test file(s).
  ✔ Fill in the PR template [recommended]
      All template sections are present.

1 blocking · 0 warnings · 3 to confirm yourself · 2 passed
```

Every rule cites a file, line and verbatim quote, so you can verify it yourself.

## Install

```bash
pipx install pr-preflight     # or: pip install pr-preflight
```

Python 3.10+. No runtime dependencies. `gh` (logged in) or `GH_TOKEN` is used for
GitHub API access when available.

## Usage

```bash
# List the rules of any GitHub repository (or a local path)
pr-preflight rules ghostty-org/ghostty

# Inside your clone, on your feature branch: check commits, files and a planned PR
pr-preflight check --title "fix: handle empty input" --body-file pr.md --ai

# Check a PR that is already open
pr-preflight check --pr 1234

# You are an AI agent: also apply rules written for agents
pr-preflight check --agent

# Machine-readable output (exit code 1 if a required rule fails)
pr-preflight check --json
```

`check` finds the target repository from your `upstream` remote (else `origin`),
reads its policy files from the default branch, and compares them with the commits
and files on your branch since the merge-base. Each rule gets **pass**, **fail**,
**warn** or **manual** (something only you can confirm, such as a signed CLA).

### Optional LLM extraction

Pattern matching is the default. With `--llm`, an OpenAI-compatible model also reads
the documents. It can only pick numbered paragraphs from the files, so it cannot
invent quotes. Local models work:

```bash
# Ollama
PR_PREFLIGHT_LLM_MODEL=qwen3:14b pr-preflight rules astral-sh/uv --llm

# mlx-lm server
PR_PREFLIGHT_LLM_URL=http://localhost:8080/v1 \
PR_PREFLIGHT_LLM_MODEL=mlx-community/Qwen3-14B-4bit pr-preflight rules astral-sh/uv --llm
```

Responses are cached in `~/.cache/pr-preflight/llm/`.

## What it detects

18 rule types: AI ban, AI disclosure, AI accountability, agent restrictions,
issue first, issue approval, CLA, DCO, commit format, PR title format, tests,
changelog, docs, PR template, local checks, focused PRs, target branch and commit
hygiene. See [docs/rules.md](docs/rules.md).

## How accurate is it?

Measured on 50 popular repositories (pytorch, react, rust, kubernetes, ghostty, uv,
pandas, ...). Their policy files are pinned to exact commits in
[`corpus/snapshot.json`](corpus/snapshot.json). Each repository's rules were labeled
by hand with verbatim quotes, independently from the extractor
([`corpus/labels/`](corpus/labels)). The repositories are split into a **dev** half,
used for tuning, and a **test** half that was not looked at while tuning.

Rule detection on the held-out test half:

| Mode | Precision | Recall | F1 |
| --- | ---: | ---: | ---: |
| Patterns (default) | 0.74 | 0.81 | **0.77** |
| `--llm` (patterns + Qwen3-14B 4-bit) | 0.65 | 0.88 | 0.75 |
| LLM only (not exposed) | 0.70 | 0.69 | 0.70 |

The default is the most balanced. `--llm` finds more of the real rules but also
reports more that are not there. Rule *levels* (required vs recommended) match the
labels about 60% of the time; treat them as a hint and read the quote.

Precision means a reported rule really exists. Recall means an existing rule was
found. Errors are listed with `-v`. Reproduce:

```bash
python corpus/fetch.py            # downloads the pinned files
python corpus/evaluate.py test -v
```

## Limits

- It reports what documents say. It does not prove a PR is acceptable, and a
  passing check is not a promise that maintainers will merge it.
- Some facts are not visible from outside, such as whether you signed a CLA. Those
  checks are reported as **manual**.
- Rules that only live in issue comments, wikis or CI configuration are not seen.

## Development

```bash
python -m venv .venv && .venv/bin/pip install -e '.[dev]'
.venv/bin/pytest && .venv/bin/ruff check .
```

## License

MIT
