pr-sentinel-ai 0.2.3__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jalal
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,4 @@
1
+ # Keep the test suite out of the sdist: tests ship with the repository,
2
+ # not with the published package.
3
+ prune tests
4
+ global-exclude *.py[cod]
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.4
2
+ Name: pr-sentinel-ai
3
+ Version: 0.2.3
4
+ Summary: AI-powered pull request review bot: GitHub Action and CLI
5
+ Author-email: Jalal <vadofespanili@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/vadofespanili-cyber/pr-sentinel
8
+ Project-URL: Repository, https://github.com/vadofespanili-cyber/pr-sentinel
9
+ Project-URL: Issues, https://github.com/vadofespanili-cyber/pr-sentinel/issues
10
+ Project-URL: Changelog, https://github.com/vadofespanili-cyber/pr-sentinel/releases
11
+ Keywords: github,code-review,ai,pull-request
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Quality Assurance
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Requires-Dist: ruff; extra == "dev"
27
+ Requires-Dist: mypy; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # pr-sentinel
31
+
32
+ [![CI](https://github.com/vadofespanili-cyber/pr-sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/vadofespanili-cyber/pr-sentinel/actions/workflows/ci.yml)
33
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
34
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
35
+
36
+ AI-powered pull request review bot — as a GitHub Action and a CLI.
37
+
38
+ pr-sentinel reviews a pull request's diff with an AI model (via a
39
+ Responses-compatible API) and deterministic static checks. It finds bugs,
40
+ security issues and performance problems, posts a summary comment, adds
41
+ line-level review comments, and can also run fully locally on a patch file.
42
+
43
+ ![pr-sentinel inline review comment on an experimental PR](https://raw.githubusercontent.com/vadofespanili-cyber/pr-sentinel/main/docs/screenshots/pr5-inline-comment.png)
44
+
45
+ *Live review on an experimental PR: the AI reviewer caught an off-by-one
46
+ bug on line 16 that the deterministic static checks could not see.*
47
+
48
+ ## See it in action
49
+
50
+ The same review as a summary comment on the pull request — one
51
+ high-severity finding, in a table:
52
+
53
+ ![pr-sentinel summary comment on an experimental PR](https://raw.githubusercontent.com/vadofespanili-cyber/pr-sentinel/main/docs/screenshots/pr5-summary-comment.png)
54
+
55
+ Both screenshots come from a real review of an experimental PR that
56
+ intentionally contained two logic bugs; the reviewer caught one of them
57
+ (the off-by-one above) and missed the other (an unbounded in-memory
58
+ cache).
59
+
60
+ ## Why pr-sentinel?
61
+
62
+ Code review is the bottleneck of open-source maintenance. Maintainers
63
+ drown in pull requests: every PR needs a careful read, but reviewers are
64
+ few and their time is the scarcest resource in the ecosystem. Small
65
+ projects wait days for a first review; large ones merge risky code
66
+ because nobody had time to look closely.
67
+
68
+ pr-sentinel gives every pull request a first review within seconds —
69
+ catching leaked secrets, dangerous calls and obvious bugs before a human
70
+ spends time on the diff, so maintainers can focus their review on
71
+ design and correctness instead of hunting for mistakes. It never merges,
72
+ closes or changes code; it only comments, and the human always decides.
73
+
74
+ - **Two layers:** fast static checks (leaked secrets, `eval`/`exec`,
75
+ `shell=True`, `pickle`, huge files) plus an AI reviewer for the things
76
+ regexes cannot see.
77
+ - **Zero-dependency core:** the package uses only the Python standard
78
+ library. No extra packages to install, audit or keep up to date.
79
+ - **Works anywhere:** GitHub Action for automatic reviews, CLI for local
80
+ use and CI systems other than GitHub Actions.
81
+ - **Safe by default:** API keys come from environment variables only, never
82
+ from config files or the command line. Secret values are never echoed in
83
+ findings or logs.
84
+
85
+ ## Quick start — GitHub Action
86
+
87
+ ```yaml
88
+ # .github/workflows/pr-review.yml
89
+ name: PR review
90
+ on:
91
+ pull_request:
92
+ types: [opened, synchronize]
93
+
94
+ permissions:
95
+ pull-requests: write
96
+ contents: read
97
+
98
+ jobs:
99
+ review:
100
+ runs-on: ubuntu-latest
101
+ steps:
102
+ - uses: actions/checkout@v4
103
+ - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
104
+ with:
105
+ api_key: ${{ secrets.PR_SENTINEL_API_KEY }}
106
+ ```
107
+
108
+ `PR_SENTINEL_API_KEY` must be a key for a Responses-compatible model
109
+ provider. The action posts one summary comment and line-level comments on
110
+ the pull request. It never merges, closes or changes code — it only
111
+ comments. The summary comment is updated in place when new commits are
112
+ pushed (it carries a hidden marker), so re-pushes do not spam the PR
113
+ with a new summary each time.
114
+
115
+ A full example is in [examples/github-workflow.yml](examples/github-workflow.yml).
116
+
117
+ ## Quick start — CLI
118
+
119
+ ```bash
120
+ pip install pr-sentinel-ai
121
+ export PR_SENTINEL_API_KEY="sk-..."
122
+ export GITHUB_TOKEN="ghp_..."
123
+
124
+ # Review a pull request and post the review on GitHub
125
+ pr-sentinel review --repo octocat/hello-world --pr 42
126
+
127
+ # Review a local patch file without touching GitHub
128
+ pr-sentinel review-diff --file changes.patch
129
+
130
+ # Preview without posting anything
131
+ pr-sentinel review --repo octocat/hello-world --pr 42 --dry-run
132
+
133
+ # Validate a config file
134
+ pr-sentinel check-config --config .pr-sentinel.yaml
135
+ ```
136
+
137
+ The CLI exits `0` on success, `2` on config or usage errors and `3` on
138
+ API errors. By default, findings never change the exit code: a PR with
139
+ findings still exits `0`, so the review never fails your build. Set
140
+ `fail_on_severity` (or `--fail-on-severity`) to make findings at or
141
+ above a severity fail the run with exit `1` — see
142
+ [CI gate and SARIF](#ci-gate-and-sarif-output) below.
143
+
144
+ ## Configuration
145
+
146
+ Optional file `.pr-sentinel.yaml` (or `.pr-sentinel.yml`) in the working
147
+ directory, or `--config PATH`. An example is in
148
+ [examples/pr-sentinel.example.yaml](examples/pr-sentinel.example.yaml).
149
+
150
+ ```yaml
151
+ model: gpt-5 # model name sent to the Responses API
152
+ severity_threshold: medium # lowest severity to report: critical|high|medium|low
153
+ fail_on_severity: high # optional CI gate: exit 1 if a reported finding is this severe or worse (default: no gate; "none" also disables it)
154
+ ignore_paths: # fnmatch globs, e.g. "vendor/**", "*.min.js"
155
+ - "docs/**"
156
+ max_files: 50 # review at most this many files per PR
157
+ max_diff_chars: 100000 # truncate larger diffs with a warning
158
+ mode: inline # inline = summary + line comments, summary = summary only
159
+ max_inline_comments: 20 # cap on line-level comments
160
+ api_base_url: https://api.openai.com/v1
161
+ ```
162
+
163
+ | Setting | Default |
164
+ | --- | --- |
165
+ | `model` | `gpt-5` |
166
+ | `severity_threshold` | `medium` |
167
+ | `fail_on_severity` | `None` (no gate) |
168
+ | `ignore_paths` | `[]` |
169
+ | `max_files` | `50` |
170
+ | `max_diff_chars` | `100000` |
171
+ | `mode` | `inline` |
172
+ | `max_inline_comments` | `20` |
173
+ | `api_base_url` | `https://api.openai.com/v1` |
174
+
175
+ Environment variables:
176
+
177
+ | Variable | Purpose |
178
+ | --- | --- |
179
+ | `PR_SENTINEL_API_KEY` | API key for the model provider (required for AI review; without it only static checks run) |
180
+ | `GITHUB_TOKEN` | GitHub token with pull-request read/write access (required for `review`) |
181
+
182
+ ## CI gate and SARIF output
183
+
184
+ ### Failing the build on severe findings
185
+
186
+ Set `fail_on_severity` in the config file, or pass
187
+ `--fail-on-severity` to `review` / `review-diff` (the flag wins over
188
+ the config file), or set the `fail_on_severity` Action input. Valid
189
+ values: `critical`, `high`, `medium`, `low`; `none` (or leaving it
190
+ unset) disables the gate. When the gate is on, the run exits `1` if any
191
+ *reported* finding — after `severity_threshold` and `ignore_paths`
192
+ filtering — meets or exceeds the threshold; otherwise it exits `0`.
193
+ The review is always posted and `--json-out` / `--sarif-out` are always
194
+ written before the gate exits `1`, so CI still has the full report.
195
+
196
+ Note the interaction with `severity_threshold`: the gate only sees
197
+ findings that were reported, so with the default threshold `medium` a
198
+ `fail_on_severity: low` gate can never fire on low findings — lower
199
+ `severity_threshold` too if you want low findings to fail the build.
200
+
201
+ ### SARIF output
202
+
203
+ `--sarif-out PATH` (on both `review` and `review-diff`, or the
204
+ `sarif_out` Action input) writes the findings as SARIF 2.1.0, so they
205
+ show up in GitHub code scanning. Upload it in a later step:
206
+
207
+ ```yaml
208
+ - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
209
+ with:
210
+ api_key: ${{ secrets.PR_SENTINEL_API_KEY }}
211
+ sarif_out: pr-sentinel.sarif
212
+ - uses: github/codeql-action/upload-sarif@v3
213
+ with:
214
+ sarif_file: pr-sentinel.sarif
215
+ ```
216
+
217
+ The upload step needs the `security-events: write` permission. The
218
+ SARIF file is written relative to the workspace, so the upload step can
219
+ read it. Rule ids are the finding's stable rule slug (for example
220
+ `leaked-openai-key`, or `ai-review` for AI findings); severities map to
221
+ SARIF levels `error` (`critical`/`high`), `warning` (`medium`) and
222
+ `note` (`low`). Finding messages never contain raw secret values.
223
+
224
+ ### The summary comment
225
+
226
+ The summary is posted as a single issue comment carrying a hidden
227
+ `<!-- pr-sentinel:summary -->` marker. When new commits are pushed,
228
+ pr-sentinel finds that comment and updates it in place instead of
229
+ posting another one. In `inline` mode the line comments are posted as
230
+ a review only when there is at least one inline comment to post, with
231
+ a brief body pointing at the summary comment. A review with no
232
+ findings updates the summary comment to "No findings" instead of
233
+ leaving a stale findings table behind. When the Action runs, the
234
+ summary also shows the reviewed commit (`Reviewed commit:
235
+ <short-sha>`) at the bottom, so readers can see at a glance which
236
+ commit the review covers.
237
+
238
+ ## Example output
239
+
240
+ Reviewing the sample patch in [examples/sample-pr.diff](examples/sample-pr.diff)
241
+ produces this summary (the full JSON is in
242
+ [examples/sample-findings.json](examples/sample-findings.json)):
243
+
244
+ ```markdown
245
+ # pr-sentinel review
246
+
247
+ Found 4 findings: 1 critical, 1 high, 1 medium, 1 low.
248
+
249
+ | Severity | File | Line | Message |
250
+ | --- | --- | --- | --- |
251
+ | critical | app.py | 3 | Possible OpenAI API key in added code. |
252
+ | high | app.py | 4 | Use of eval() on added code. |
253
+ | medium | app.py | 6 | Nested loops run 1,000,000 iterations to build a list. |
254
+ | low | app.py | 6 | Magic number 1000 is used without explanation. |
255
+
256
+ > **Note:** These findings are AI-generated suggestions. Please verify them before acting on them.
257
+
258
+ ---
259
+ Reviewed by pr-sentinel
260
+ ```
261
+
262
+ Each finding also becomes a line-level comment at the exact diff position,
263
+ for example `**critical · security** — Possible OpenAI API key in added
264
+ code.` with a suggested fix.
265
+
266
+ ## How it works
267
+
268
+ 1. **Fetch the diff** — from the GitHub API (`review`) or a local patch
269
+ file (`review-diff`).
270
+ 2. **Parse** — the unified diff is parsed into files, hunks and numbered
271
+ lines; each added line is mapped to its GitHub diff position so inline
272
+ comments land on the right line.
273
+ 3. **Static checks** — deterministic, no-AI checks over added lines only:
274
+ leaked secrets, dangerous calls, oversized files.
275
+ 4. **AI review** — the diff is split into chunks that fit the model's
276
+ context and each chunk is reviewed through the Responses API. The model
277
+ must return a JSON array of findings; anything unparseable is rejected.
278
+ 5. **Filter and report** — findings below the severity threshold or in
279
+ ignored paths are dropped, then a Markdown summary and inline comments
280
+ are posted (or printed in `--dry-run` / `review-diff` mode).
281
+
282
+ See [docs/architecture.md](docs/architecture.md) for the module map and
283
+ design decisions.
284
+
285
+ ## Limitations (honest)
286
+
287
+ - **Findings are suggestions, not verdicts.** The AI reviewer can miss real
288
+ bugs and can flag code that is fine. Always verify before acting.
289
+ - **No code is executed.** pr-sentinel reads diffs only; it cannot run
290
+ tests, reproduce a bug or prove a finding.
291
+ - **Function-level scope.** The reviewer sees one diff chunk at a time, so
292
+ it cannot reliably reason about cross-file architecture or whole-repo
293
+ invariants.
294
+ - **Static checks are single-line regexes.** Multi-line patterns (for
295
+ example `yaml.load(` split across lines) are not detected, and the
296
+ generic credential pattern can fire on harmless test values. A full
297
+ AST-based analysis was deliberately not added: the reviewer only sees
298
+ the diff, not full file contents, so AST on partial content would
299
+ still miss cases.
300
+ - **Model-dependent.** Review quality depends on the model and on the diff
301
+ fitting into context; very large PRs are limited at `max_diff_chars`:
302
+ whole trailing files/hunks are dropped (never cut mid-hunk), with a
303
+ warning.
304
+ - **Retries.** Transient failures (HTTP 429/5xx, network errors) are
305
+ retried up to 3 attempts with exponential backoff, honoring a
306
+ Retry-After header; a persistent failure falls back to static checks
307
+ only, with a warning.
308
+ - **English prompts.** Review prompts and messages are in English in
309
+ v0.1.0.
310
+
311
+ ## Releases
312
+
313
+ Versioned releases live on the
314
+ [Releases page](https://github.com/vadofespanili-cyber/pr-sentinel/releases).
315
+ The current release is **v0.2.3** — see the
316
+ [Changelog](CHANGELOG.md) and the
317
+ [release notes](docs/release-notes-v0.2.3.md) for what it includes.
318
+ v0.1.2 was driven by an independent external review (Google Gemini 4
319
+ Neon); the full review is in
320
+ [docs/reviews/gemini-2026-11-22.md](docs/reviews/gemini-2026-11-22.md).
321
+
322
+ ## Development
323
+
324
+ ```bash
325
+ python -m venv .venv && .venv/bin/pip install -e ".[dev]"
326
+ .venv/bin/python -m pytest -q
327
+ .venv/bin/ruff check src tests
328
+ .venv/bin/ruff format --check src tests
329
+ ```
330
+
331
+ Python 3.10+; the package itself has no runtime dependencies. See
332
+ [CONTRIBUTING.md](CONTRIBUTING.md).
333
+
334
+ ## Security
335
+
336
+ Report vulnerabilities as described in [SECURITY.md](SECURITY.md). Never
337
+ put real API keys or tokens in issues, pull requests or test files.
338
+
339
+ ## License
340
+
341
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,312 @@
1
+ # pr-sentinel
2
+
3
+ [![CI](https://github.com/vadofespanili-cyber/pr-sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/vadofespanili-cyber/pr-sentinel/actions/workflows/ci.yml)
4
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
6
+
7
+ AI-powered pull request review bot — as a GitHub Action and a CLI.
8
+
9
+ pr-sentinel reviews a pull request's diff with an AI model (via a
10
+ Responses-compatible API) and deterministic static checks. It finds bugs,
11
+ security issues and performance problems, posts a summary comment, adds
12
+ line-level review comments, and can also run fully locally on a patch file.
13
+
14
+ ![pr-sentinel inline review comment on an experimental PR](https://raw.githubusercontent.com/vadofespanili-cyber/pr-sentinel/main/docs/screenshots/pr5-inline-comment.png)
15
+
16
+ *Live review on an experimental PR: the AI reviewer caught an off-by-one
17
+ bug on line 16 that the deterministic static checks could not see.*
18
+
19
+ ## See it in action
20
+
21
+ The same review as a summary comment on the pull request — one
22
+ high-severity finding, in a table:
23
+
24
+ ![pr-sentinel summary comment on an experimental PR](https://raw.githubusercontent.com/vadofespanili-cyber/pr-sentinel/main/docs/screenshots/pr5-summary-comment.png)
25
+
26
+ Both screenshots come from a real review of an experimental PR that
27
+ intentionally contained two logic bugs; the reviewer caught one of them
28
+ (the off-by-one above) and missed the other (an unbounded in-memory
29
+ cache).
30
+
31
+ ## Why pr-sentinel?
32
+
33
+ Code review is the bottleneck of open-source maintenance. Maintainers
34
+ drown in pull requests: every PR needs a careful read, but reviewers are
35
+ few and their time is the scarcest resource in the ecosystem. Small
36
+ projects wait days for a first review; large ones merge risky code
37
+ because nobody had time to look closely.
38
+
39
+ pr-sentinel gives every pull request a first review within seconds —
40
+ catching leaked secrets, dangerous calls and obvious bugs before a human
41
+ spends time on the diff, so maintainers can focus their review on
42
+ design and correctness instead of hunting for mistakes. It never merges,
43
+ closes or changes code; it only comments, and the human always decides.
44
+
45
+ - **Two layers:** fast static checks (leaked secrets, `eval`/`exec`,
46
+ `shell=True`, `pickle`, huge files) plus an AI reviewer for the things
47
+ regexes cannot see.
48
+ - **Zero-dependency core:** the package uses only the Python standard
49
+ library. No extra packages to install, audit or keep up to date.
50
+ - **Works anywhere:** GitHub Action for automatic reviews, CLI for local
51
+ use and CI systems other than GitHub Actions.
52
+ - **Safe by default:** API keys come from environment variables only, never
53
+ from config files or the command line. Secret values are never echoed in
54
+ findings or logs.
55
+
56
+ ## Quick start — GitHub Action
57
+
58
+ ```yaml
59
+ # .github/workflows/pr-review.yml
60
+ name: PR review
61
+ on:
62
+ pull_request:
63
+ types: [opened, synchronize]
64
+
65
+ permissions:
66
+ pull-requests: write
67
+ contents: read
68
+
69
+ jobs:
70
+ review:
71
+ runs-on: ubuntu-latest
72
+ steps:
73
+ - uses: actions/checkout@v4
74
+ - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
75
+ with:
76
+ api_key: ${{ secrets.PR_SENTINEL_API_KEY }}
77
+ ```
78
+
79
+ `PR_SENTINEL_API_KEY` must be a key for a Responses-compatible model
80
+ provider. The action posts one summary comment and line-level comments on
81
+ the pull request. It never merges, closes or changes code — it only
82
+ comments. The summary comment is updated in place when new commits are
83
+ pushed (it carries a hidden marker), so re-pushes do not spam the PR
84
+ with a new summary each time.
85
+
86
+ A full example is in [examples/github-workflow.yml](examples/github-workflow.yml).
87
+
88
+ ## Quick start — CLI
89
+
90
+ ```bash
91
+ pip install pr-sentinel-ai
92
+ export PR_SENTINEL_API_KEY="sk-..."
93
+ export GITHUB_TOKEN="ghp_..."
94
+
95
+ # Review a pull request and post the review on GitHub
96
+ pr-sentinel review --repo octocat/hello-world --pr 42
97
+
98
+ # Review a local patch file without touching GitHub
99
+ pr-sentinel review-diff --file changes.patch
100
+
101
+ # Preview without posting anything
102
+ pr-sentinel review --repo octocat/hello-world --pr 42 --dry-run
103
+
104
+ # Validate a config file
105
+ pr-sentinel check-config --config .pr-sentinel.yaml
106
+ ```
107
+
108
+ The CLI exits `0` on success, `2` on config or usage errors and `3` on
109
+ API errors. By default, findings never change the exit code: a PR with
110
+ findings still exits `0`, so the review never fails your build. Set
111
+ `fail_on_severity` (or `--fail-on-severity`) to make findings at or
112
+ above a severity fail the run with exit `1` — see
113
+ [CI gate and SARIF](#ci-gate-and-sarif-output) below.
114
+
115
+ ## Configuration
116
+
117
+ Optional file `.pr-sentinel.yaml` (or `.pr-sentinel.yml`) in the working
118
+ directory, or `--config PATH`. An example is in
119
+ [examples/pr-sentinel.example.yaml](examples/pr-sentinel.example.yaml).
120
+
121
+ ```yaml
122
+ model: gpt-5 # model name sent to the Responses API
123
+ severity_threshold: medium # lowest severity to report: critical|high|medium|low
124
+ fail_on_severity: high # optional CI gate: exit 1 if a reported finding is this severe or worse (default: no gate; "none" also disables it)
125
+ ignore_paths: # fnmatch globs, e.g. "vendor/**", "*.min.js"
126
+ - "docs/**"
127
+ max_files: 50 # review at most this many files per PR
128
+ max_diff_chars: 100000 # truncate larger diffs with a warning
129
+ mode: inline # inline = summary + line comments, summary = summary only
130
+ max_inline_comments: 20 # cap on line-level comments
131
+ api_base_url: https://api.openai.com/v1
132
+ ```
133
+
134
+ | Setting | Default |
135
+ | --- | --- |
136
+ | `model` | `gpt-5` |
137
+ | `severity_threshold` | `medium` |
138
+ | `fail_on_severity` | `None` (no gate) |
139
+ | `ignore_paths` | `[]` |
140
+ | `max_files` | `50` |
141
+ | `max_diff_chars` | `100000` |
142
+ | `mode` | `inline` |
143
+ | `max_inline_comments` | `20` |
144
+ | `api_base_url` | `https://api.openai.com/v1` |
145
+
146
+ Environment variables:
147
+
148
+ | Variable | Purpose |
149
+ | --- | --- |
150
+ | `PR_SENTINEL_API_KEY` | API key for the model provider (required for AI review; without it only static checks run) |
151
+ | `GITHUB_TOKEN` | GitHub token with pull-request read/write access (required for `review`) |
152
+
153
+ ## CI gate and SARIF output
154
+
155
+ ### Failing the build on severe findings
156
+
157
+ Set `fail_on_severity` in the config file, or pass
158
+ `--fail-on-severity` to `review` / `review-diff` (the flag wins over
159
+ the config file), or set the `fail_on_severity` Action input. Valid
160
+ values: `critical`, `high`, `medium`, `low`; `none` (or leaving it
161
+ unset) disables the gate. When the gate is on, the run exits `1` if any
162
+ *reported* finding — after `severity_threshold` and `ignore_paths`
163
+ filtering — meets or exceeds the threshold; otherwise it exits `0`.
164
+ The review is always posted and `--json-out` / `--sarif-out` are always
165
+ written before the gate exits `1`, so CI still has the full report.
166
+
167
+ Note the interaction with `severity_threshold`: the gate only sees
168
+ findings that were reported, so with the default threshold `medium` a
169
+ `fail_on_severity: low` gate can never fire on low findings — lower
170
+ `severity_threshold` too if you want low findings to fail the build.
171
+
172
+ ### SARIF output
173
+
174
+ `--sarif-out PATH` (on both `review` and `review-diff`, or the
175
+ `sarif_out` Action input) writes the findings as SARIF 2.1.0, so they
176
+ show up in GitHub code scanning. Upload it in a later step:
177
+
178
+ ```yaml
179
+ - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
180
+ with:
181
+ api_key: ${{ secrets.PR_SENTINEL_API_KEY }}
182
+ sarif_out: pr-sentinel.sarif
183
+ - uses: github/codeql-action/upload-sarif@v3
184
+ with:
185
+ sarif_file: pr-sentinel.sarif
186
+ ```
187
+
188
+ The upload step needs the `security-events: write` permission. The
189
+ SARIF file is written relative to the workspace, so the upload step can
190
+ read it. Rule ids are the finding's stable rule slug (for example
191
+ `leaked-openai-key`, or `ai-review` for AI findings); severities map to
192
+ SARIF levels `error` (`critical`/`high`), `warning` (`medium`) and
193
+ `note` (`low`). Finding messages never contain raw secret values.
194
+
195
+ ### The summary comment
196
+
197
+ The summary is posted as a single issue comment carrying a hidden
198
+ `<!-- pr-sentinel:summary -->` marker. When new commits are pushed,
199
+ pr-sentinel finds that comment and updates it in place instead of
200
+ posting another one. In `inline` mode the line comments are posted as
201
+ a review only when there is at least one inline comment to post, with
202
+ a brief body pointing at the summary comment. A review with no
203
+ findings updates the summary comment to "No findings" instead of
204
+ leaving a stale findings table behind. When the Action runs, the
205
+ summary also shows the reviewed commit (`Reviewed commit:
206
+ <short-sha>`) at the bottom, so readers can see at a glance which
207
+ commit the review covers.
208
+
209
+ ## Example output
210
+
211
+ Reviewing the sample patch in [examples/sample-pr.diff](examples/sample-pr.diff)
212
+ produces this summary (the full JSON is in
213
+ [examples/sample-findings.json](examples/sample-findings.json)):
214
+
215
+ ```markdown
216
+ # pr-sentinel review
217
+
218
+ Found 4 findings: 1 critical, 1 high, 1 medium, 1 low.
219
+
220
+ | Severity | File | Line | Message |
221
+ | --- | --- | --- | --- |
222
+ | critical | app.py | 3 | Possible OpenAI API key in added code. |
223
+ | high | app.py | 4 | Use of eval() on added code. |
224
+ | medium | app.py | 6 | Nested loops run 1,000,000 iterations to build a list. |
225
+ | low | app.py | 6 | Magic number 1000 is used without explanation. |
226
+
227
+ > **Note:** These findings are AI-generated suggestions. Please verify them before acting on them.
228
+
229
+ ---
230
+ Reviewed by pr-sentinel
231
+ ```
232
+
233
+ Each finding also becomes a line-level comment at the exact diff position,
234
+ for example `**critical · security** — Possible OpenAI API key in added
235
+ code.` with a suggested fix.
236
+
237
+ ## How it works
238
+
239
+ 1. **Fetch the diff** — from the GitHub API (`review`) or a local patch
240
+ file (`review-diff`).
241
+ 2. **Parse** — the unified diff is parsed into files, hunks and numbered
242
+ lines; each added line is mapped to its GitHub diff position so inline
243
+ comments land on the right line.
244
+ 3. **Static checks** — deterministic, no-AI checks over added lines only:
245
+ leaked secrets, dangerous calls, oversized files.
246
+ 4. **AI review** — the diff is split into chunks that fit the model's
247
+ context and each chunk is reviewed through the Responses API. The model
248
+ must return a JSON array of findings; anything unparseable is rejected.
249
+ 5. **Filter and report** — findings below the severity threshold or in
250
+ ignored paths are dropped, then a Markdown summary and inline comments
251
+ are posted (or printed in `--dry-run` / `review-diff` mode).
252
+
253
+ See [docs/architecture.md](docs/architecture.md) for the module map and
254
+ design decisions.
255
+
256
+ ## Limitations (honest)
257
+
258
+ - **Findings are suggestions, not verdicts.** The AI reviewer can miss real
259
+ bugs and can flag code that is fine. Always verify before acting.
260
+ - **No code is executed.** pr-sentinel reads diffs only; it cannot run
261
+ tests, reproduce a bug or prove a finding.
262
+ - **Function-level scope.** The reviewer sees one diff chunk at a time, so
263
+ it cannot reliably reason about cross-file architecture or whole-repo
264
+ invariants.
265
+ - **Static checks are single-line regexes.** Multi-line patterns (for
266
+ example `yaml.load(` split across lines) are not detected, and the
267
+ generic credential pattern can fire on harmless test values. A full
268
+ AST-based analysis was deliberately not added: the reviewer only sees
269
+ the diff, not full file contents, so AST on partial content would
270
+ still miss cases.
271
+ - **Model-dependent.** Review quality depends on the model and on the diff
272
+ fitting into context; very large PRs are limited at `max_diff_chars`:
273
+ whole trailing files/hunks are dropped (never cut mid-hunk), with a
274
+ warning.
275
+ - **Retries.** Transient failures (HTTP 429/5xx, network errors) are
276
+ retried up to 3 attempts with exponential backoff, honoring a
277
+ Retry-After header; a persistent failure falls back to static checks
278
+ only, with a warning.
279
+ - **English prompts.** Review prompts and messages are in English in
280
+ v0.1.0.
281
+
282
+ ## Releases
283
+
284
+ Versioned releases live on the
285
+ [Releases page](https://github.com/vadofespanili-cyber/pr-sentinel/releases).
286
+ The current release is **v0.2.3** — see the
287
+ [Changelog](CHANGELOG.md) and the
288
+ [release notes](docs/release-notes-v0.2.3.md) for what it includes.
289
+ v0.1.2 was driven by an independent external review (Google Gemini 4
290
+ Neon); the full review is in
291
+ [docs/reviews/gemini-2026-11-22.md](docs/reviews/gemini-2026-11-22.md).
292
+
293
+ ## Development
294
+
295
+ ```bash
296
+ python -m venv .venv && .venv/bin/pip install -e ".[dev]"
297
+ .venv/bin/python -m pytest -q
298
+ .venv/bin/ruff check src tests
299
+ .venv/bin/ruff format --check src tests
300
+ ```
301
+
302
+ Python 3.10+; the package itself has no runtime dependencies. See
303
+ [CONTRIBUTING.md](CONTRIBUTING.md).
304
+
305
+ ## Security
306
+
307
+ Report vulnerabilities as described in [SECURITY.md](SECURITY.md). Never
308
+ put real API keys or tokens in issues, pull requests or test files.
309
+
310
+ ## License
311
+
312
+ MIT — see [LICENSE](LICENSE).