@acemarke/diffloupe 0.3.0 → 0.4.0

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.
package/README.md CHANGED
@@ -141,6 +141,11 @@ diffloupe runs
141
141
  | `--full` | On a re-review, review every changed file instead of only the files changed since the last run |
142
142
  | `--headless` | Run without a server and print a summary to stdout |
143
143
  | `--markdown` | With `--headless`, print the full review markdown instead of the summary |
144
+ | `--github` | PR targets only. Review for posting to GitHub: see [Running in CI](#running-in-ci) |
145
+ | `--head <sha>` | PR targets only. Review this commit instead of the PR's current head. It must be a full 40-character SHA in the PR's history |
146
+ | `--out <dir>` | With `--headless`, copy the review output and `result.json` into this directory |
147
+ | `--json` | With `--headless`, print only the `result.json` object to stdout |
148
+ | `--fail-on <severity>` | With `--headless`, exit 3 if a finding posted in this round is at this severity or above: `blocker`, `should-fix`, `nice-to-have`, `question` |
144
149
 
145
150
  Untracked files over 1 MB are skipped and listed in the run.
146
151
 
@@ -186,7 +191,95 @@ Runs are stored under `$XDG_DATA_HOME/diffloupe/runs/<id>/` (`~/.local/share/dif
186
191
 
187
192
  ### `diffloupe doctor`
188
193
 
189
- Checks Bun, git, OpenCode, tilth and `gh`; prints the model for each stage and where it came from, and the source of each provider credential; and shows how much disk the data directory uses. Exits non-zero if a review could not run. `--config <file>` includes a per-repo settings file in the model lookup.
194
+ Checks Bun, git, OpenCode, tilth and `gh`; prints the model for each stage and where it came from, and the source of each provider credential; and shows how much disk the data directory uses. Exits non-zero if a review could not run. `--config <file>` includes a per-repo settings file in the model lookup. `--strict` also exits non-zero on warnings, such as `gh` not being logged in or a model with no known cost. `--json` prints the checks as a JSON array of `{ name, status, detail }`.
195
+
196
+ ## Running in CI
197
+
198
+ `diffloupe review '#<n>' --headless --github --head <sha> --out <dir>` reviews a pull request for a bot that posts the result. DiffLoupe itself does not post anything: it writes the GitHub API payloads, and a later step sends them.
199
+
200
+ `--github` changes how a re-review finds the earlier rounds:
201
+
202
+ - Earlier rounds come only from the PR's comments on GitHub, through `gh`. Runs saved on the CI machine are not used for carried-over findings, so a cached data directory cannot make the bot reply to comments that are not on the PR.
203
+ - Every round reviews the whole PR. The summary comment is rewritten on each push and holds the findings, so a round that only looked at the changed files would drop the open findings on the other files from it.
204
+ - A `gh` failure while reading the PR description or its comments fails the run instead of reviewing without them.
205
+ - The run writes `payloads.json` with the summary comment, the inline review and the replies.
206
+ - The summary comment gets a "Copy all findings as Markdown" fold. If it would push the comment over GitHub's size limit, the comment links to the `findings.md` file in the run's artifact instead.
207
+
208
+ `--head` pins the review to the commit the workflow was triggered for, so a push during the run does not change what gets reviewed.
209
+
210
+ ### Exit codes
211
+
212
+ | Code | Meaning |
213
+ |------|---------|
214
+ | 0 | The review finished, or was skipped because the change has no code files |
215
+ | 1 | The run failed, including a `gh` failure under `--github` |
216
+ | 2 | The run could not start: a bad flag, target, model or credential |
217
+ | 3 | `--fail-on` was given and a finding posted in this round is at or above that severity |
218
+ | 130 | The run was cancelled |
219
+
220
+ ### `result.json`
221
+
222
+ Written to `--out` for every finished, failed, cancelled or skipped run, and printed by `--json`:
223
+
224
+ ```json
225
+ {
226
+ "id": "backend-pr42-0123abcdef45-20261021183000",
227
+ "status": "complete",
228
+ "reviewed": true,
229
+ "skipReason": null,
230
+ "pr": 42,
231
+ "base": "<sha>",
232
+ "head": "<sha>",
233
+ "runDir": "/home/runner/.local/share/diffloupe/runs/backend-pr42-0123abcdef45-20261021183000",
234
+ "outDir": "review-out",
235
+ "payloads": "review-out/payloads.json",
236
+ "artifactName": "ai-code-review-42-0123abcde",
237
+ "costUsd": 1.62,
238
+ "wallMs": 412000,
239
+ "budgetStopped": false,
240
+ "skippedSlices": 0,
241
+ "findings": {
242
+ "total": 7,
243
+ "posted": 6,
244
+ "bySeverity": { "blocker": 0, "should-fix": 2, "nice-to-have": 3, "question": 1 }
245
+ },
246
+ "round": 2,
247
+ "incremental": false,
248
+ "version": "0.4.0"
249
+ }
250
+ ```
251
+
252
+ `status` is `complete`, `failed`, `cancelled` or `skipped`. `skipReason` is `no-code-files` for a skipped run. `payloads` is `null` when there is nothing to post. `findings.posted` counts the findings in the comments; `total` adds the ones over the comment cap, and `bySeverity` counts only posted findings. `artifactName` is the name the summary comment links to, so upload `--out` under that name.
253
+
254
+ `--out` also holds `review.md`, `payloads.json`, `findings.md`, `record.json`, `units.json`, `byClass.json`, `run.json` and the detail report `<run id>.detail.md`. Files a run did not produce are left out.
255
+
256
+ ### Failing the check on findings
257
+
258
+ Use a separate gate job instead of `--fail-on` when the comments are posted by a later job. The review job then fails only when the review breaks, and the gate job, which is the required check, fails only on findings:
259
+
260
+ ```yaml
261
+ gate:
262
+ needs: [review, post]
263
+ if: ${{ !cancelled() }}
264
+ runs-on: ubuntu-latest
265
+ steps:
266
+ - uses: actions/download-artifact@v4
267
+ if: ${{ needs.review.outputs.artifact != '' }}
268
+ with:
269
+ name: ${{ needs.review.outputs.artifact }}
270
+ path: review
271
+ - run: |
272
+ [ "${{ needs.review.result }}" = "success" ] || exit 0
273
+ [ -f review/result.json ] || exit 0
274
+ blockers=$(jq '.findings.bySeverity.blocker // 0' review/result.json)
275
+ [ "$blockers" -eq 0 ] || { echo "::error::$blockers blocker finding(s)"; exit 1; }
276
+ ```
277
+
278
+ This passes when the review job fails, so an outage does not block merges; change the first `exit 0` to `exit 1` for the opposite. Gate on `blocker` only: findings vary between runs, and a lower threshold blocks merges on false positives. `--fail-on` suits a single job or a local script. It exits 3 after writing `--out`, and ignores findings over the comment cap.
279
+
280
+ Both the gate job and `--fail-on` count only the findings posted in this round. On a re-review, a finding already posted in an earlier round is not posted again, so a later push can pass the check while an earlier blocker is still unfixed. To block merges until every finding is dealt with, turn on "Require conversation resolution before merging" in the branch protection rules instead. It blocks on any unresolved inline comment, from the bot or a person, at any severity.
281
+
282
+ Run `diffloupe doctor --strict` before the review to fail fast on a missing tool or credential.
190
283
 
191
284
  ## Configuration
192
285