pr-preflight 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. pr_preflight-0.1.0/.github/workflows/ci.yml +51 -0
  2. pr_preflight-0.1.0/.github/workflows/publish.yml +40 -0
  3. pr_preflight-0.1.0/.gitignore +6 -0
  4. pr_preflight-0.1.0/LICENSE +21 -0
  5. pr_preflight-0.1.0/PKG-INFO +170 -0
  6. pr_preflight-0.1.0/README.md +151 -0
  7. pr_preflight-0.1.0/corpus/dev.txt +25 -0
  8. pr_preflight-0.1.0/corpus/evaluate.py +111 -0
  9. pr_preflight-0.1.0/corpus/fetch.py +55 -0
  10. pr_preflight-0.1.0/corpus/labels/BerriAI__litellm.json +78 -0
  11. pr_preflight-0.1.0/corpus/labels/UKGovernmentBEIS__inspect_ai.json +74 -0
  12. pr_preflight-0.1.0/corpus/labels/apache__airflow.json +80 -0
  13. pr_preflight-0.1.0/corpus/labels/astral-sh__ruff.json +65 -0
  14. pr_preflight-0.1.0/corpus/labels/astral-sh__uv.json +26 -0
  15. pr_preflight-0.1.0/corpus/labels/cilium__cilium.json +75 -0
  16. pr_preflight-0.1.0/corpus/labels/curl__curl.json +12 -0
  17. pr_preflight-0.1.0/corpus/labels/denoland__deno.json +51 -0
  18. pr_preflight-0.1.0/corpus/labels/django__django.json +63 -0
  19. pr_preflight-0.1.0/corpus/labels/electron__electron.json +49 -0
  20. pr_preflight-0.1.0/corpus/labels/eslint__eslint.json +83 -0
  21. pr_preflight-0.1.0/corpus/labels/facebook__react.json +35 -0
  22. pr_preflight-0.1.0/corpus/labels/fastapi__fastapi.json +4 -0
  23. pr_preflight-0.1.0/corpus/labels/ggml-org__llama.cpp.json +87 -0
  24. pr_preflight-0.1.0/corpus/labels/ghostty-org__ghostty.json +45 -0
  25. pr_preflight-0.1.0/corpus/labels/go-gitea__gitea.json +74 -0
  26. pr_preflight-0.1.0/corpus/labels/godotengine__godot.json +61 -0
  27. pr_preflight-0.1.0/corpus/labels/grafana__grafana.json +81 -0
  28. pr_preflight-0.1.0/corpus/labels/home-assistant__core.json +60 -0
  29. pr_preflight-0.1.0/corpus/labels/huggingface__transformers.json +58 -0
  30. pr_preflight-0.1.0/corpus/labels/kubernetes__kubernetes.json +75 -0
  31. pr_preflight-0.1.0/corpus/labels/langchain-ai__langchain.json +85 -0
  32. pr_preflight-0.1.0/corpus/labels/matplotlib__matplotlib.json +58 -0
  33. pr_preflight-0.1.0/corpus/labels/microsoft__vscode.json +19 -0
  34. pr_preflight-0.1.0/corpus/labels/ml-explore__mlx-lm.json +57 -0
  35. pr_preflight-0.1.0/corpus/labels/moby__moby.json +93 -0
  36. pr_preflight-0.1.0/corpus/labels/neovim__neovim.json +56 -0
  37. pr_preflight-0.1.0/corpus/labels/nltk__nltk.json +35 -0
  38. pr_preflight-0.1.0/corpus/labels/nodejs__node.json +71 -0
  39. pr_preflight-0.1.0/corpus/labels/numpy__numpy.json +45 -0
  40. pr_preflight-0.1.0/corpus/labels/ollama__ollama.json +28 -0
  41. pr_preflight-0.1.0/corpus/labels/oven-sh__bun.json +28 -0
  42. pr_preflight-0.1.0/corpus/labels/pandas-dev__pandas.json +69 -0
  43. pr_preflight-0.1.0/corpus/labels/prettier__prettier.json +58 -0
  44. pr_preflight-0.1.0/corpus/labels/pydantic__pydantic.json +53 -0
  45. pr_preflight-0.1.0/corpus/labels/python__cpython.json +35 -0
  46. pr_preflight-0.1.0/corpus/labels/pytorch__pytorch.json +88 -0
  47. pr_preflight-0.1.0/corpus/labels/rust-lang__rust.json +53 -0
  48. pr_preflight-0.1.0/corpus/labels/scikit-learn__scikit-learn.json +42 -0
  49. pr_preflight-0.1.0/corpus/labels/servo__servo.json +19 -0
  50. pr_preflight-0.1.0/corpus/labels/stanfordnlp__dspy.json +71 -0
  51. pr_preflight-0.1.0/corpus/labels/sveltejs__svelte.json +63 -0
  52. pr_preflight-0.1.0/corpus/labels/sympy__sympy.json +70 -0
  53. pr_preflight-0.1.0/corpus/labels/tauri-apps__tauri.json +62 -0
  54. pr_preflight-0.1.0/corpus/labels/trinodb__trino.json +56 -0
  55. pr_preflight-0.1.0/corpus/labels/typescript-eslint__typescript-eslint.json +42 -0
  56. pr_preflight-0.1.0/corpus/labels/vercel__next.js.json +76 -0
  57. pr_preflight-0.1.0/corpus/labels/vllm-project__vllm.json +58 -0
  58. pr_preflight-0.1.0/corpus/labels/vuejs__core.json +63 -0
  59. pr_preflight-0.1.0/corpus/labels/zed-industries__zed.json +84 -0
  60. pr_preflight-0.1.0/corpus/repos.txt +50 -0
  61. pr_preflight-0.1.0/corpus/snapshot.json +464 -0
  62. pr_preflight-0.1.0/corpus/test.txt +25 -0
  63. pr_preflight-0.1.0/docs/rules.md +33 -0
  64. pr_preflight-0.1.0/pyproject.toml +39 -0
  65. pr_preflight-0.1.0/src/pr_preflight/__init__.py +3 -0
  66. pr_preflight-0.1.0/src/pr_preflight/checks.py +298 -0
  67. pr_preflight-0.1.0/src/pr_preflight/cli.py +180 -0
  68. pr_preflight-0.1.0/src/pr_preflight/context.py +152 -0
  69. pr_preflight-0.1.0/src/pr_preflight/llm.py +198 -0
  70. pr_preflight-0.1.0/src/pr_preflight/report.py +77 -0
  71. pr_preflight-0.1.0/src/pr_preflight/rules.py +480 -0
  72. pr_preflight-0.1.0/src/pr_preflight/sources.py +138 -0
  73. pr_preflight-0.1.0/tests/test_pr_preflight.py +147 -0
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ${{ matrix.os }}
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os: [ubuntu-latest]
18
+ python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
19
+ include:
20
+ - os: macos-latest
21
+ python: "3.13"
22
+ - os: windows-latest
23
+ python: "3.13"
24
+ steps:
25
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26
+ with:
27
+ persist-credentials: false
28
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
29
+ with:
30
+ python-version: ${{ matrix.python }}
31
+ - run: pip install -e . pytest ruff
32
+ - run: ruff check . && ruff format --check .
33
+ if: matrix.os == 'ubuntu-latest'
34
+ - run: pytest -q
35
+
36
+ corpus:
37
+ # Scores the pattern extractor against the 50 hand-labeled repositories,
38
+ # read at the commits pinned in corpus/snapshot.json.
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
42
+ with:
43
+ persist-credentials: false
44
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
45
+ with:
46
+ python-version: "3.13"
47
+ - run: pip install -e .
48
+ - run: python corpus/fetch.py
49
+ env:
50
+ GH_TOKEN: ${{ github.token }}
51
+ - run: python corpus/evaluate.py all --min-f1 0.80
@@ -0,0 +1,40 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ with:
17
+ persist-credentials: false
18
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
19
+ with:
20
+ python-version: "3.13"
21
+ - run: pip install build && python -m build
22
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
23
+ with:
24
+ name: dist
25
+ path: dist/
26
+
27
+ publish:
28
+ needs: build
29
+ runs-on: ubuntu-latest
30
+ environment:
31
+ name: pypi
32
+ url: https://pypi.org/project/pr-preflight/
33
+ permissions:
34
+ id-token: write
35
+ steps:
36
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ .cache/
3
+ __pycache__/
4
+ *.egg-info/
5
+ dist/
6
+ build/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dip Pansuriya
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.
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.5
2
+ Name: pr-preflight
3
+ Version: 0.1.0
4
+ Summary: Check a repository's contribution rules (CONTRIBUTING, AGENTS.md, PR templates) before you open a pull request.
5
+ Project-URL: Homepage, https://github.com/DipPansuriya/pr-preflight
6
+ Project-URL: Issues, https://github.com/DipPansuriya/pr-preflight/issues
7
+ Author: Dip Pansuriya
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: agents,ai-policy,contributing,github,mcp,pull-request
11
+ Classifier: Environment :: Console
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Version Control :: Git
14
+ Requires-Python: >=3.10
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8; extra == 'dev'
17
+ Requires-Dist: ruff>=0.6; extra == 'dev'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pr-preflight
21
+
22
+ **Check a repository's contribution rules before you open a pull request.**
23
+
24
+ More and more projects publish rules for contributors: disclose AI use, open an issue
25
+ first, sign the CLA, use Conventional Commits, fill in the template. AI agents now
26
+ have their own rules too, in `AGENTS.md`. These rules are spread across
27
+ `CONTRIBUTING.md`, `AI_POLICY.md`, `AGENTS.md` and PR templates, and they differ
28
+ from project to project. Most contributors find out they missed one only after a
29
+ maintainer closes the PR.
30
+
31
+ `pr-preflight` reads those files, turns them into a short list of rules with the
32
+ exact line each comes from, and checks your branch or PR against them.
33
+
34
+ ```console
35
+ $ pr-preflight rules ml-explore/mlx-lm
36
+ ml-explore/mlx-lm: 6 contribution rules
37
+
38
+ required Disclose AI tool use
39
+ └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was
40
+ produced, and must explicitly disclose the manner in which AI was employed."
41
+ required AI agents may not act on their own
42
+ └ AGENTS.md:10 "- Do NOT write PR descriptions and commit messages for the user"
43
+ ...
44
+ ```
45
+
46
+ ```console
47
+ $ cd mlx-lm && pr-preflight check --pr 2116 --ai
48
+ pr-preflight · ml-explore/mlx-lm · tool-choice-none → main (1 commits, 2 files)
49
+
50
+ ✖ Disclose AI tool use [required]
51
+ The PR description doesn't mention AI use.
52
+ └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was produced, and
53
+ must explicitly disclose the manner in which AI was employed."
54
+ ? Understand and review any AI-assisted change yourself [required]
55
+ Confirm this yourself.
56
+ ...
57
+ ✔ Include tests [recommended]
58
+ Touches 1 test file(s).
59
+ ✔ Fill in the PR template [recommended]
60
+ All template sections are present.
61
+
62
+ 1 blocking · 0 warnings · 3 to confirm yourself · 2 passed
63
+ ```
64
+
65
+ Every rule cites a file, line and verbatim quote, so you can verify it yourself.
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pipx install pr-preflight # or: pip install pr-preflight
71
+ ```
72
+
73
+ Python 3.10+. No runtime dependencies. `gh` (logged in) or `GH_TOKEN` is used for
74
+ GitHub API access when available.
75
+
76
+ ## Usage
77
+
78
+ ```bash
79
+ # List the rules of any GitHub repository (or a local path)
80
+ pr-preflight rules ghostty-org/ghostty
81
+
82
+ # Inside your clone, on your feature branch: check commits, files and a planned PR
83
+ pr-preflight check --title "fix: handle empty input" --body-file pr.md --ai
84
+
85
+ # Check a PR that is already open
86
+ pr-preflight check --pr 1234
87
+
88
+ # You are an AI agent: also apply rules written for agents
89
+ pr-preflight check --agent
90
+
91
+ # Machine-readable output (exit code 1 if a required rule fails)
92
+ pr-preflight check --json
93
+ ```
94
+
95
+ `check` finds the target repository from your `upstream` remote (else `origin`),
96
+ reads its policy files from the default branch, and compares them with the commits
97
+ and files on your branch since the merge-base. Each rule gets **pass**, **fail**,
98
+ **warn** or **manual** (something only you can confirm, such as a signed CLA).
99
+
100
+ ### Optional LLM extraction
101
+
102
+ Pattern matching is the default. With `--llm`, an OpenAI-compatible model also reads
103
+ the documents. It can only pick numbered paragraphs from the files, so it cannot
104
+ invent quotes. Local models work:
105
+
106
+ ```bash
107
+ # Ollama
108
+ PR_PREFLIGHT_LLM_MODEL=qwen3:14b pr-preflight rules astral-sh/uv --llm
109
+
110
+ # mlx-lm server
111
+ PR_PREFLIGHT_LLM_URL=http://localhost:8080/v1 \
112
+ PR_PREFLIGHT_LLM_MODEL=mlx-community/Qwen3-14B-4bit pr-preflight rules astral-sh/uv --llm
113
+ ```
114
+
115
+ Responses are cached in `~/.cache/pr-preflight/llm/`.
116
+
117
+ ## What it detects
118
+
119
+ 18 rule types: AI ban, AI disclosure, AI accountability, agent restrictions,
120
+ issue first, issue approval, CLA, DCO, commit format, PR title format, tests,
121
+ changelog, docs, PR template, local checks, focused PRs, target branch and commit
122
+ hygiene. See [docs/rules.md](docs/rules.md).
123
+
124
+ ## How accurate is it?
125
+
126
+ Measured on 50 popular repositories (pytorch, react, rust, kubernetes, ghostty, uv,
127
+ pandas, ...). Their policy files are pinned to exact commits in
128
+ [`corpus/snapshot.json`](corpus/snapshot.json). Each repository's rules were labeled
129
+ by hand with verbatim quotes, independently from the extractor
130
+ ([`corpus/labels/`](corpus/labels)). The repositories are split into a **dev** half,
131
+ used for tuning, and a **test** half that was not looked at while tuning.
132
+
133
+ Rule detection on the held-out test half:
134
+
135
+ | Mode | Precision | Recall | F1 |
136
+ | --- | ---: | ---: | ---: |
137
+ | Patterns (default) | 0.74 | 0.81 | **0.77** |
138
+ | `--llm` (patterns + Qwen3-14B 4-bit) | 0.65 | 0.88 | 0.75 |
139
+ | LLM only (not exposed) | 0.70 | 0.69 | 0.70 |
140
+
141
+ The default is the most balanced. `--llm` finds more of the real rules but also
142
+ reports more that are not there. Rule *levels* (required vs recommended) match the
143
+ labels about 60% of the time; treat them as a hint and read the quote.
144
+
145
+ Precision means a reported rule really exists. Recall means an existing rule was
146
+ found. Errors are listed with `-v`. Reproduce:
147
+
148
+ ```bash
149
+ python corpus/fetch.py # downloads the pinned files
150
+ python corpus/evaluate.py test -v
151
+ ```
152
+
153
+ ## Limits
154
+
155
+ - It reports what documents say. It does not prove a PR is acceptable, and a
156
+ passing check is not a promise that maintainers will merge it.
157
+ - Some facts are not visible from outside, such as whether you signed a CLA. Those
158
+ checks are reported as **manual**.
159
+ - Rules that only live in issue comments, wikis or CI configuration are not seen.
160
+
161
+ ## Development
162
+
163
+ ```bash
164
+ python -m venv .venv && .venv/bin/pip install -e '.[dev]'
165
+ .venv/bin/pytest && .venv/bin/ruff check .
166
+ ```
167
+
168
+ ## License
169
+
170
+ MIT
@@ -0,0 +1,151 @@
1
+ # pr-preflight
2
+
3
+ **Check a repository's contribution rules before you open a pull request.**
4
+
5
+ More and more projects publish rules for contributors: disclose AI use, open an issue
6
+ first, sign the CLA, use Conventional Commits, fill in the template. AI agents now
7
+ have their own rules too, in `AGENTS.md`. These rules are spread across
8
+ `CONTRIBUTING.md`, `AI_POLICY.md`, `AGENTS.md` and PR templates, and they differ
9
+ from project to project. Most contributors find out they missed one only after a
10
+ maintainer closes the PR.
11
+
12
+ `pr-preflight` reads those files, turns them into a short list of rules with the
13
+ exact line each comes from, and checks your branch or PR against them.
14
+
15
+ ```console
16
+ $ pr-preflight rules ml-explore/mlx-lm
17
+ ml-explore/mlx-lm: 6 contribution rules
18
+
19
+ required Disclose AI tool use
20
+ └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was
21
+ produced, and must explicitly disclose the manner in which AI was employed."
22
+ required AI agents may not act on their own
23
+ └ AGENTS.md:10 "- Do NOT write PR descriptions and commit messages for the user"
24
+ ...
25
+ ```
26
+
27
+ ```console
28
+ $ cd mlx-lm && pr-preflight check --pr 2116 --ai
29
+ pr-preflight · ml-explore/mlx-lm · tool-choice-none → main (1 commits, 2 files)
30
+
31
+ ✖ Disclose AI tool use [required]
32
+ The PR description doesn't mention AI use.
33
+ └ CONTRIBUTING.md:8 "You are 100% responsible for every line, however it was produced, and
34
+ must explicitly disclose the manner in which AI was employed."
35
+ ? Understand and review any AI-assisted change yourself [required]
36
+ Confirm this yourself.
37
+ ...
38
+ ✔ Include tests [recommended]
39
+ Touches 1 test file(s).
40
+ ✔ Fill in the PR template [recommended]
41
+ All template sections are present.
42
+
43
+ 1 blocking · 0 warnings · 3 to confirm yourself · 2 passed
44
+ ```
45
+
46
+ Every rule cites a file, line and verbatim quote, so you can verify it yourself.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ pipx install pr-preflight # or: pip install pr-preflight
52
+ ```
53
+
54
+ Python 3.10+. No runtime dependencies. `gh` (logged in) or `GH_TOKEN` is used for
55
+ GitHub API access when available.
56
+
57
+ ## Usage
58
+
59
+ ```bash
60
+ # List the rules of any GitHub repository (or a local path)
61
+ pr-preflight rules ghostty-org/ghostty
62
+
63
+ # Inside your clone, on your feature branch: check commits, files and a planned PR
64
+ pr-preflight check --title "fix: handle empty input" --body-file pr.md --ai
65
+
66
+ # Check a PR that is already open
67
+ pr-preflight check --pr 1234
68
+
69
+ # You are an AI agent: also apply rules written for agents
70
+ pr-preflight check --agent
71
+
72
+ # Machine-readable output (exit code 1 if a required rule fails)
73
+ pr-preflight check --json
74
+ ```
75
+
76
+ `check` finds the target repository from your `upstream` remote (else `origin`),
77
+ reads its policy files from the default branch, and compares them with the commits
78
+ and files on your branch since the merge-base. Each rule gets **pass**, **fail**,
79
+ **warn** or **manual** (something only you can confirm, such as a signed CLA).
80
+
81
+ ### Optional LLM extraction
82
+
83
+ Pattern matching is the default. With `--llm`, an OpenAI-compatible model also reads
84
+ the documents. It can only pick numbered paragraphs from the files, so it cannot
85
+ invent quotes. Local models work:
86
+
87
+ ```bash
88
+ # Ollama
89
+ PR_PREFLIGHT_LLM_MODEL=qwen3:14b pr-preflight rules astral-sh/uv --llm
90
+
91
+ # mlx-lm server
92
+ PR_PREFLIGHT_LLM_URL=http://localhost:8080/v1 \
93
+ PR_PREFLIGHT_LLM_MODEL=mlx-community/Qwen3-14B-4bit pr-preflight rules astral-sh/uv --llm
94
+ ```
95
+
96
+ Responses are cached in `~/.cache/pr-preflight/llm/`.
97
+
98
+ ## What it detects
99
+
100
+ 18 rule types: AI ban, AI disclosure, AI accountability, agent restrictions,
101
+ issue first, issue approval, CLA, DCO, commit format, PR title format, tests,
102
+ changelog, docs, PR template, local checks, focused PRs, target branch and commit
103
+ hygiene. See [docs/rules.md](docs/rules.md).
104
+
105
+ ## How accurate is it?
106
+
107
+ Measured on 50 popular repositories (pytorch, react, rust, kubernetes, ghostty, uv,
108
+ pandas, ...). Their policy files are pinned to exact commits in
109
+ [`corpus/snapshot.json`](corpus/snapshot.json). Each repository's rules were labeled
110
+ by hand with verbatim quotes, independently from the extractor
111
+ ([`corpus/labels/`](corpus/labels)). The repositories are split into a **dev** half,
112
+ used for tuning, and a **test** half that was not looked at while tuning.
113
+
114
+ Rule detection on the held-out test half:
115
+
116
+ | Mode | Precision | Recall | F1 |
117
+ | --- | ---: | ---: | ---: |
118
+ | Patterns (default) | 0.74 | 0.81 | **0.77** |
119
+ | `--llm` (patterns + Qwen3-14B 4-bit) | 0.65 | 0.88 | 0.75 |
120
+ | LLM only (not exposed) | 0.70 | 0.69 | 0.70 |
121
+
122
+ The default is the most balanced. `--llm` finds more of the real rules but also
123
+ reports more that are not there. Rule *levels* (required vs recommended) match the
124
+ labels about 60% of the time; treat them as a hint and read the quote.
125
+
126
+ Precision means a reported rule really exists. Recall means an existing rule was
127
+ found. Errors are listed with `-v`. Reproduce:
128
+
129
+ ```bash
130
+ python corpus/fetch.py # downloads the pinned files
131
+ python corpus/evaluate.py test -v
132
+ ```
133
+
134
+ ## Limits
135
+
136
+ - It reports what documents say. It does not prove a PR is acceptable, and a
137
+ passing check is not a promise that maintainers will merge it.
138
+ - Some facts are not visible from outside, such as whether you signed a CLA. Those
139
+ checks are reported as **manual**.
140
+ - Rules that only live in issue comments, wikis or CI configuration are not seen.
141
+
142
+ ## Development
143
+
144
+ ```bash
145
+ python -m venv .venv && .venv/bin/pip install -e '.[dev]'
146
+ .venv/bin/pytest && .venv/bin/ruff check .
147
+ ```
148
+
149
+ ## License
150
+
151
+ MIT
@@ -0,0 +1,25 @@
1
+ ml-explore/mlx-lm
2
+ ghostty-org/ghostty
3
+ servo/servo
4
+ python/cpython
5
+ pytorch/pytorch
6
+ langchain-ai/langchain
7
+ ollama/ollama
8
+ astral-sh/uv
9
+ fastapi/fastapi
10
+ facebook/react
11
+ nodejs/node
12
+ rust-lang/rust
13
+ oven-sh/bun
14
+ sveltejs/svelte
15
+ typescript-eslint/typescript-eslint
16
+ prettier/prettier
17
+ pandas-dev/pandas
18
+ matplotlib/matplotlib
19
+ stanfordnlp/dspy
20
+ trinodb/trino
21
+ home-assistant/core
22
+ neovim/neovim
23
+ go-gitea/gitea
24
+ cilium/cilium
25
+ electron/electron
@@ -0,0 +1,111 @@
1
+ """Score rule extraction against hand-made labels.
2
+
3
+ Usage: python corpus/evaluate.py [dev|test|all] [--extractor pattern|llm|hybrid] [-v]
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import argparse
9
+ import json
10
+ from collections import Counter
11
+ from pathlib import Path
12
+
13
+ from pr_preflight.rules import RULE_IDS, extract
14
+ from pr_preflight.sources import Document
15
+
16
+ ROOT = Path(__file__).resolve().parent.parent
17
+ CACHE = ROOT / ".cache" / "corpus"
18
+ LABELS = ROOT / "corpus" / "labels"
19
+
20
+
21
+ def load_docs(repo: str) -> list[Document]:
22
+ folder = CACHE / repo.replace("/", "__")
23
+ manifest = json.loads((folder / "manifest.json").read_text())
24
+ return [Document(p, (folder / p).read_text()) for p in manifest["files"]]
25
+
26
+
27
+ def repos(split: str) -> list[str]:
28
+ names = {"dev": "dev.txt", "test": "test.txt", "all": "repos.txt"}[split]
29
+ return (ROOT / "corpus" / names).read_text().split()
30
+
31
+
32
+ def run_extractor(name: str, docs: list[Document]):
33
+ if name == "llm":
34
+ from pr_preflight.llm import extract_llm
35
+
36
+ return extract_llm(docs)
37
+ if name == "hybrid":
38
+ from pr_preflight.cli import load_rules
39
+
40
+ return load_rules(docs, use_llm=True)
41
+ return extract(docs)
42
+
43
+
44
+ def main() -> int:
45
+ ap = argparse.ArgumentParser()
46
+ ap.add_argument("split", nargs="?", default="dev", choices=["dev", "test", "all"])
47
+ ap.add_argument(
48
+ "--extractor", default="pattern", choices=["pattern", "llm", "hybrid"]
49
+ )
50
+ ap.add_argument("-v", "--verbose", action="store_true")
51
+ ap.add_argument("--min-f1", type=float, help="Exit 1 if micro F1 is lower.")
52
+ args = ap.parse_args()
53
+
54
+ tp, fp, fn = Counter(), Counter(), Counter()
55
+ level_ok = level_total = 0
56
+ for repo in repos(args.split):
57
+ label_file = LABELS / f"{repo.replace('/', '__')}.json"
58
+ if not label_file.exists():
59
+ print(f"skip {repo}: no labels")
60
+ continue
61
+ gold = {r["id"]: r for r in json.loads(label_file.read_text())["rules"]}
62
+ found = {r.id: r for r in run_extractor(args.extractor, load_docs(repo))}
63
+ for rid in RULE_IDS:
64
+ g, f = rid in gold, rid in found
65
+ if g and f:
66
+ tp[rid] += 1
67
+ level_total += 1
68
+ level_ok += gold[rid]["level"] == found[rid].level
69
+ elif f:
70
+ fp[rid] += 1
71
+ if args.verbose:
72
+ print(
73
+ f"FP {repo:36} {rid:18} {found[rid].file}:"
74
+ f"{found[rid].line} {found[rid].quote[:110]}"
75
+ )
76
+ elif g:
77
+ fn[rid] += 1
78
+ if args.verbose:
79
+ print(
80
+ f"FN {repo:36} {rid:18} {gold[rid]['file']}: "
81
+ f"{gold[rid]['quote'][:110]}"
82
+ )
83
+
84
+ def prf(t, p, n):
85
+ prec = t / (t + p) if t + p else 1.0
86
+ rec = t / (t + n) if t + n else 1.0
87
+ f1 = 2 * prec * rec / (prec + rec) if prec + rec else 0.0
88
+ return prec, rec, f1
89
+
90
+ print(f"\n{'rule':20} {'tp':>3} {'fp':>3} {'fn':>3} prec recall f1")
91
+ for rid in RULE_IDS:
92
+ p, r, f = prf(tp[rid], fp[rid], fn[rid])
93
+ print(
94
+ f"{rid:20} {tp[rid]:3} {fp[rid]:3} {fn[rid]:3} {p:.2f} {r:.2f} {f:.2f}"
95
+ )
96
+ T, P, N = sum(tp.values()), sum(fp.values()), sum(fn.values())
97
+ p, r, f = prf(T, P, N)
98
+ print(f"{'TOTAL (micro)':20} {T:3} {P:3} {N:3} {p:.2f} {r:.2f} {f:.2f}")
99
+ if level_total:
100
+ print(
101
+ f"level agreement on true positives: {level_ok}/{level_total} "
102
+ f"({level_ok / level_total:.0%})"
103
+ )
104
+ if args.min_f1 is not None and f < args.min_f1:
105
+ print(f"F1 {f:.2f} is below --min-f1 {args.min_f1}")
106
+ return 1
107
+ return 0
108
+
109
+
110
+ if __name__ == "__main__":
111
+ raise SystemExit(main())
@@ -0,0 +1,55 @@
1
+ """Download the corpus policy documents into .cache/corpus.
2
+
3
+ Documents are read at the commits pinned in corpus/snapshot.json so the
4
+ hand-made labels stay valid. `--update` re-pins every repo to its current
5
+ default branch (labels must then be reviewed).
6
+ """
7
+
8
+ import json
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from pr_preflight.sources import GitHub
13
+
14
+ ROOT = Path(__file__).resolve().parent.parent
15
+ CACHE = ROOT / ".cache" / "corpus"
16
+ SNAPSHOT = ROOT / "corpus" / "snapshot.json"
17
+
18
+
19
+ def main() -> int:
20
+ gh = GitHub()
21
+ update = "--update" in sys.argv
22
+ snapshot = (
23
+ {} if update or not SNAPSHOT.exists() else json.loads(SNAPSHOT.read_text())
24
+ )
25
+ repos = (ROOT / "corpus/repos.txt").read_text().split()
26
+ for repo in repos:
27
+ target = CACHE / repo.replace("/", "__")
28
+ manifest_file = target / "manifest.json"
29
+ pinned = snapshot.get(repo)
30
+ if manifest_file.exists() and not update:
31
+ manifest = json.loads(manifest_file.read_text())
32
+ if pinned is None or manifest["sha"] == pinned["sha"]:
33
+ snapshot.setdefault(repo, manifest)
34
+ continue
35
+ if pinned:
36
+ sha, files = pinned["sha"], pinned["files"]
37
+ docs = [(p, gh._read(repo, p, sha)) for p in files]
38
+ else:
39
+ sha = gh.get(f"repos/{repo}/commits/{gh.default_branch(repo)}")["sha"]
40
+ docs = [(d.path, d.text) for d in gh.documents(repo, sha)]
41
+ target.mkdir(parents=True, exist_ok=True)
42
+ for path, text in docs:
43
+ out = target / path
44
+ out.parent.mkdir(parents=True, exist_ok=True)
45
+ out.write_text(text or "")
46
+ manifest = {"repo": repo, "sha": sha, "files": [p for p, _ in docs]}
47
+ manifest_file.write_text(json.dumps(manifest, indent=2))
48
+ snapshot[repo] = manifest
49
+ print(f"{repo:40} {len(docs)} docs @ {sha[:10]}")
50
+ SNAPSHOT.write_text(json.dumps({r: snapshot[r] for r in repos}, indent=1) + "\n")
51
+ return 0
52
+
53
+
54
+ if __name__ == "__main__":
55
+ raise SystemExit(main())