@acemarke/diffloupe 0.2.1 → 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
@@ -15,12 +15,16 @@ It is also a plain diff viewer. `diffloupe diff` shows the same grouped diff in
15
15
  ## How a review works
16
16
 
17
17
  1. **Group.** The changed files are grouped into review units from links in the code: a name defined in one file and used in another, a test and its source, an import, a shared directory. Generated and lock files are skipped. Docs are listed but not reviewed in depth.
18
- 2. **Review.** Each unit gets its own reviewer agent, which reads the surrounding code with [tilth](https://github.com/jahala/tilth) and reports findings with evidence. Up to six run at once.
18
+ 2. **Review.** A small model first reads the whole diff and drafts what the change is for, so each reviewer knows what the parts it cannot see are doing. Each unit then gets its own reviewer agent, which reads the surrounding code with [tilth](https://github.com/jahala/tilth) and reports findings with evidence. Up to six run at once.
19
19
  3. **Coordinate.** A coordinator merges and deduplicates the findings, drops the ones it cannot verify, and checks the change against its stated intent: the PR description, `--intent`, or the commit messages.
20
20
  4. **Walk through.** A walkthrough pass orders the change into chapters and stops, with a "start here" list.
21
21
 
22
22
  Each review is saved as a run that you can list and reopen. Reviewing the same target again links the new run to the previous one: findings that were fixed are listed as fixed, and ones still open are carried forward instead of being reported again.
23
23
 
24
+ A re-review (round 2 and later) only sends the files that changed since the previous run's head to the reviewers. Each of them sees the full diff plus what changed since the last review, and is told to focus on the new lines. The cap on new findings drops from 10 to 5. Grouping and the walkthrough still cover the whole change. If more than half the files changed, or the previous head is no longer available, the round falls back to a full review. `--full` forces one. From round 4 on, the CLI warns that later rounds mostly find smaller problems.
25
+
26
+ Findings about code the change did not add or modify are tagged **pre-existing**. They have their own cap of 3, so they never push findings on the new code out of the review. They are listed after the other findings, do not count toward merge risk, and are shown muted in the web UI.
27
+
24
28
  ## The web UI
25
29
 
26
30
  - **Summary** at the top, laid out like a GitHub review comment: merge risk and production risk, finding counts, findings grouped by file with links to their lines, whether the change matches its stated intent, what to focus on, and where to start.
@@ -40,7 +44,7 @@ Each review is saved as a run that you can list and reopen. Reviewing the same t
40
44
  |------|-------|
41
45
  | [Bun](https://bun.sh) 1.3 or later | Runs the CLI and the server. |
42
46
  | `git` | |
43
- | [OpenCode](https://opencode.ai) 2.x | Runs every agent (`npm i -g opencode-ai`). Tested with 2.0.26. DiffLoupe writes its own OpenCode config for each run, so your agents, plugins and MCP servers are not used. Your default model and your `providers` block are. |
47
+ | [OpenCode](https://opencode.ai) 2.x | Runs every agent (`npm i -g @opencode/cli`; the older `opencode-ai` package is 1.x). Tested with 2.0.26. DiffLoupe writes its own OpenCode config for each run, so your agents, plugins and MCP servers are not used. Your default model and your `providers` block are. |
44
48
  | [tilth](https://github.com/jahala/tilth) | Code reading tools for the reviewers (`cargo install tilth`). Tested with 0.9.0. |
45
49
  | [`gh`](https://cli.github.com) | Only for pull requests. Run `gh auth login` first. |
46
50
  | A model provider credential | See [Credentials](#credentials). |
@@ -49,7 +53,7 @@ Each review is saved as a run that you can list and reopen. Reviewing the same t
49
53
 
50
54
  Run `diffloupe doctor` to check all of this, along with which models a review will use and where each credential comes from.
51
55
 
52
- **Cost.** With the built-in defaults (Claude Opus 5.5 for the reviewers and the coordinator, Claude Sonnet 5.5 for the walkthrough and group naming), real runs so far cost about $0.10 for a one-file commit, about $1 for a small PR, and $4–5 for a large one. If your OpenCode config sets a default model, DiffLoupe uses it for every stage instead, which changes the cost. Use `--max-cost` or `maxCostUsd` to set a limit. The run page and `diffloupe runs` show what each run cost. Models whose provider reports no price show "cost not reported", and `--max-cost` cannot be enforced for them.
56
+ **Cost.** With the built-in defaults (Claude Opus 5.5 for the reviewers and the coordinator, Claude Sonnet 5.5 for the walkthrough and group naming, Claude Haiku 5.5 for the intent draft at about $0.01), real runs so far cost about $0.10 for a one-file commit, about $1 for a small PR, and $4–5 for a large one. If your OpenCode config sets a default model, DiffLoupe uses it for every stage instead, which changes the cost. Use `--max-cost` or `maxCostUsd` to set a limit. The run page and `diffloupe runs` show what each run cost. Models whose provider reports no price show "cost not reported", and `--max-cost` cannot be enforced for them.
53
57
 
54
58
  **Platforms.** Developed and tested on Linux and WSL2. On WSL the server binds `127.0.0.1` and the Windows browser reaches it through `localhost`. macOS should work but has not been tried. Native Windows is not supported; use WSL.
55
59
 
@@ -126,16 +130,22 @@ diffloupe runs
126
130
  |--------|-------------|
127
131
  | `-C, --repo <path>` | Repository to review (default: current directory) |
128
132
  | `--base <ref>` | For `staged`/`worktree`: diff against `merge-base(<ref>, HEAD)` instead of HEAD |
129
- | `-i, --intent <text>` | Describe the intent of the changes |
133
+ | `-i, --intent <text>` | What the change should do. Every reviewer sees it labelled as yours, next to the PR description |
130
134
  | `--intent-file <path>` | Read the intent from a file |
131
- | `--model <stage=id>` | Model for a stage: `review`, `coordinator`, `walkthrough` (repeatable) |
135
+ | `--model <stage=id>` | Model for a stage: `review`, `coordinator`, `walkthrough`, `intent` (repeatable) |
132
136
  | `--effort <level>` | Reasoning effort: `low`, `medium`, `high` |
133
137
  | `--config <file>` | Per-repo review settings (see below) |
134
138
  | `--max-cost <usd>` | Stop starting new review slices once spending reaches this amount. Slices already running finish, so the total can go over: by up to six slices at $3 each, plus the coordinator and walkthrough. |
135
139
  | `--host <host>`, `--port <port>` | Server address (default `127.0.0.1:4517`, or the next free port) |
136
140
  | `--open` | Open the run in a browser. On WSL this opens the Windows browser. |
141
+ | `--full` | On a re-review, review every changed file instead of only the files changed since the last run |
137
142
  | `--headless` | Run without a server and print a summary to stdout |
138
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` |
139
149
 
140
150
  Untracked files over 1 MB are skipped and listed in the run.
141
151
 
@@ -173,6 +183,7 @@ Runs the server until you stop it. `-C` sets the repository that runs use by def
173
183
  | `diffloupe runs [--kind review\|diff] [--json]` | List saved runs, newest first |
174
184
  | `diffloupe runs show <id> [--json]` | Show a run: groups with their files and findings, walkthrough stops, totals |
175
185
  | `diffloupe runs show <id> --markdown [--over-cap]` | Print the findings as markdown, the same text as Copy all in the UI |
186
+ | `diffloupe runs stats [--repo <path\|owner/name>] [--since 30d] [--by-version] [--json]` | For each chain of re-reviews of the same target: findings raised, carried and fixed per round, findings dismissed and still open, cost per fixed finding, and totals (resolution rate for findings on the change, mean rounds, share of chains past three rounds). `--by-version` splits the counts by the hash of the review prompts and of the repo's instructions, which each run records |
176
187
  | `diffloupe runs rm <id>` | Delete a run, its artifacts, its scratch files and the git refs that pin its commits |
177
188
  | `diffloupe runs prune [--older-than 30d] [--keep 20] [--kind review\|diff] [--yes]` | Delete runs older than the cutoff, except the newest `--keep`, plus scratch files no run owns. Lists what it would delete unless `--yes` is given |
178
189
 
@@ -180,7 +191,95 @@ Runs are stored under `$XDG_DATA_HOME/diffloupe/runs/<id>/` (`~/.local/share/dif
180
191
 
181
192
  ### `diffloupe doctor`
182
193
 
183
- 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.
184
283
 
185
284
  ## Configuration
186
285
 
@@ -207,7 +306,13 @@ Checks Bun, git, OpenCode, tilth and `gh`; prints the model for each stage and w
207
306
  "models": { "review": "...", "coordinator": "...", "walkthrough": "..." },
208
307
  "effort": "medium",
209
308
  "surfaces": { "deploy": ["^infra/"], "tooling": ["^docs/"] },
210
- "extraExcludes": ["vendor/openssl/"]
309
+ "extraExcludes": ["vendor/openssl/"],
310
+ "instructions": [
311
+ "## What failure looks like here",
312
+ "A change that breaks runs already saved on disk.",
313
+ "## Don't report",
314
+ "Styling in src/web/."
315
+ ]
211
316
  }
212
317
  ```
213
318
 
@@ -218,6 +323,7 @@ Every field is optional.
218
323
  | Reviewer model | `models.review` | `models.review` | `--model review=<id>` | `REVIEW_MODEL` | OpenCode default model, else `anthropic/claude-opus-5-5` |
219
324
  | Coordinator model | `models.coordinator` | `models.coordinator` | `--model coordinator=<id>` | `REVIEW_MODEL_MERGE` | OpenCode default model, else `anthropic/claude-opus-5-5` |
220
325
  | Walkthrough model | `models.walkthrough` | `models.walkthrough` | `--model walkthrough=<id>` | `REVIEW_MODEL_WALK` | OpenCode default model, else `anthropic/claude-sonnet-5-5` |
326
+ | Intent draft model | `models.intent` | `models.intent` | `--model intent=<id>` | `REVIEW_MODEL_INTENT` | `anthropic/claude-haiku-5-5` when the walkthrough model is Anthropic, else the walkthrough model |
221
327
  | Provider for bare model ids | `provider` | `provider` | | `REVIEW_PROVIDER` | `anthropic` |
222
328
  | Effort | `effort` | `effort` | `--effort` | `REVIEW_EFFORT`, `REVIEW_EFFORT_AUX` | `medium` for built-in default models only |
223
329
  | Use the OpenCode default model | `opencode.useDefaultModel` | | | | `true` |
@@ -231,6 +337,8 @@ Every field is optional.
231
337
 
232
338
  `surfaces` are regex sources matched against repo-relative paths. They decide which findings count toward "prod risk": anything not matched as deploy or tooling counts as product code. `extraExcludes` are path substrings left out of the code map.
233
339
 
340
+ `instructions` is free text given to every reviewer and the coordinator, either one string or an array of lines. Keep it short and about what the code can't tell a reviewer: what counts as breaking in this repo, invariants that are easy to break and invisible in a diff, and what not to report. Where it conflicts with the built-in review guidance, it wins.
341
+
234
342
  ### Credentials
235
343
 
236
344
  Each review agent runs OpenCode with its own data directory, so DiffLoupe has to hand it a credential for every provider the chosen models use. For each provider, the first of these that exists is used: