diffbrief
v0.1.0
Published
Turn large (often AI-generated) pull requests into a risk-ranked review brief. Flags auth changes, destructive migrations, secrets, risky dependencies and removed tests, collapses noise, and tells reviewers what to read first. Terminal, Markdown, JSON and
Maintainers
Readme
diffbrief
Turn a large pull request into a risk-ranked review brief. Know what to read first.
AI agents can write 1,500 lines in an afternoon. Nobody can review that line by line. diffbrief reads your branch's diff and tells reviewers where the risk is: auth changes, destructive migrations, leaked secrets, risky dependencies, removed tests. It collapses the noise (lockfiles, generated code, formatting).
$ npx diffbrief
diffbrief · main...HEAD · 47 files · +1,912 −388 · Risk: HIGH
HIGH Review first (2)
db/migrations/0042_cleanup.sql +3 −0 · data · new
✖ Destructive schema or data change (hard to undo) line 1
src/routes/admin.ts +1 −1 · api
✖ Removed an auth, permission or rate-limit check removed at old line 1
MEDIUM Check carefully (2)
package.json +2 −1 · deps
▲ New dependency: left-pad-ultra@^1.0.0 line 4
▲ Major version change: express ^4.19.0 → ^5.0.0 line 3
src/utils/format.test.ts +0 −1 · tests
▲ 1 test case removed
LOW Quick look (12)
src/utils/format.ts +1 −0 · source
• TODO / FIXME added line 2
…
Collapsed 31: 22 lockfiles/generated · 6 formatting-only · 3 docs- Works offline. Rules-based, no API keys, no code leaves your machine.
- Knows what matters. 20+ rules for security, data, dependencies and tests, plus path-based risk categories.
- Cuts noise. Lockfiles, build output, snapshots and whitespace-only changes are collapsed.
- Fits your workflow. Terminal, Markdown (for PR comments), JSON, and GitHub Actions annotations with a job summary.
- Zero dependencies. Only needs
git.
Install
npx diffbrief # run once
npm i -D diffbrief # or add to your projectRequires Node.js 20+ and git.
Usage
npx diffbrief # current branch vs main (or master)
npx diffbrief --base develop # compare against another branch
npx diffbrief --working # include uncommitted changes
npx diffbrief --format markdown --output brief.md
npx diffbrief --fail-on high # exit 1 if anything is high risk
npx diffbrief --ignore "src/generated/**"Options
| Flag | Config key | Default | Description |
|---|---|---|---|
| --base <ref> | base | main, master, origin/main, origin/master | Branch or commit to compare against. diffbrief uses the merge base, like a PR |
| --head <ref> | — | HEAD | Branch or commit to review |
| --working | — | false | Include uncommitted changes |
| --format <type> | format | terminal | terminal, markdown, json or github |
| --output <file> | — | stdout | Write the brief to a file |
| --fail-on <level> | failOn | never | Exit 1 when overall risk is at least high, medium or low |
| --ignore <glob> | ignore | [] | Collapse matching files. Repeatable |
| --cwd <dir> | — | . | Repository directory |
Config file
diffbrief.config.json in the repository root:
{
"base": "develop",
"failOn": "high",
"ignore": ["src/generated/**", "fixtures/**"],
"rules": [
{
"id": "no-legacy-client",
"pattern": "legacyPaymentsClient",
"level": "medium",
"message": "Uses the legacy payments client",
"files": "src/**"
}
]
}Custom rules match each changed line against pattern (a regular expression, case-insensitive by default). Set "on": "removed" to match removed lines.
GitHub Actions
name: diffbrief
on: pull_request
jobs:
brief:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # diffbrief needs the base branch history
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npx diffbrief --base origin/${{ github.base_ref }} --format githubHigh findings appear as errors and medium findings as warnings on the changed lines, and the full brief is added to the job summary.
To post the brief as a PR comment:
- run: npx diffbrief --base origin/${{ github.base_ref }} --format markdown --output brief.md
- run: gh pr comment ${{ github.event.number }} --body-file brief.md --edit-last || gh pr comment ${{ github.event.number }} --body-file brief.md
env:
GH_TOKEN: ${{ github.token }}What it checks
Risk by path
| Category | Examples | Level |
|---|---|---|
| security | auth/, session, jwt, permissions, csrf | medium |
| data | migrations/, *.sql, schema.prisma, models/ | medium |
| config | .github/workflows/, Dockerfile, .env*, Terraform, tsconfig.json | medium |
| api | routes/, controllers/, handlers/, *.graphql, OpenAPI | low |
| source | everything else | low |
| tests, docs | collapsed unless something is wrong | — |
| generated | lockfiles, dist/, *.min.js, snapshots | collapsed |
Files over 400 changed lines get a "consider splitting" note.
Rules on changed lines
| Level | Rules |
|---|---|
| High | private keys, real API keys (AWS, GitHub, Stripe, Slack, Google, npm, Anthropic, OpenAI), TLS verification disabled, DROP / TRUNCATE / destructive migrations, eval / new Function, removed auth or rate-limit checks, dependencies from git/URL, install scripts added |
| Medium | hard-coded credentials, shell execution, SQL built with string interpolation, raw HTML (dangerouslySetInnerHTML, innerHTML, v-html), CORS open to any origin, auth switched off, MD5/SHA-1, Math.random() in security code, .only in tests, test cases or test files removed, new runtime dependencies, major version changes |
| Low | new dev dependencies, skipped tests, @ts-ignore / eslint-disable, console.log / debugger, TODO / FIXME |
"Removed auth check" only fires when more checks were removed than added in that file, so moving a check around does not trigger it.
Programmatic API
import { createBrief, formatBrief } from "diffbrief";
const brief = createBrief({ base: "main", ignore: ["src/gen/**"] });
console.log(brief.risk); // "high" | "medium" | "low" | "none"
for (const file of brief.files) {
console.log(file.level, file.path, file.findings.map((f) => f.message));
}
console.log(formatBrief(brief, "markdown"));Also exported: analyzeDiff(files, options) (pure, no git), parseUnifiedDiff(text), classify(path), BUILTIN_RULES.
Roadmap
- Optional LLM summaries of each risky file (bring your own API key).
- Built-in sticky PR comment.
License
MIT
