redline

Docs

redline has one engine and four ways in: this web app, a CLI that writes a static review site, a JSON API, and files made for agents. All of them run the same 137 rules.

Start a review

On the home page, do any of these:

  • Paste a pull request link, or several, one per line. Your browser reads the diff and the changed files from GitHub.
  • Drag a pull request link from a GitHub tab onto the page.
  • Drop .diff or .patch files anywhere on the page, or use Choose files. Each file becomes one change.
  • Paste a diff, such as the output of git diff main...HEAD.

Public repositories need nothing else. For a private repository, or when GitHub rate-limits you (60 requests an hour without a token), open the token field and paste a token with read access. Append .diff to any pull request URL to download a diff you can drop instead.

A diff alone gets the diff views. Whole files, which GitHub links provide, also unlock the whole-file view.

Reading a review

  • Changes lists each change with its flag count and a reviewed check. The open change shows its files with a bar for how dense the flags are.
  • Whole shows every file in full. Added lines are tinted green. Removed lines sit where they were as collapsed was rows that open on click. Unchanged stretches fold away.
  • Split shows old and new side by side. Diff shows hunks only.
  • The rail on the right edge maps the whole change. Green marks are added lines and red marks are flags; a full-width red mark is high severity. Click or drag it to jump.
  • Comments sit under the line they flag, one card per line. The bulb opens why it matters, the fix and a flagged-versus-better example. The eye hides that rule everywhere. The cross dismisses one finding, with a reason.
  • Findings lists every comment for the change, with filters by severity and rule. Existing also shows flags on lines the change did not touch.
  • Rules shows one rule at a time across every change.

Severity: high is a likely bug or hole, medium is a problem worth fixing in this change, low is a smell worth a look.

Reviewed marks, dismissals, filters and the theme live in this browser only.

Keyboard

j / kNext or previous finding
n / pNext or previous change
vWhole, split, diff
cInline comments on or off
fFindings panel
oShow flags on untouched lines
xMark the change reviewed
dDismiss the current finding
eExport
rRules view
tTheme
?All keys

Exports

Export takes the findings you can see, after filters and dismissals, for this change or every change.

  • Agent prompt: each finding with its file and line, the problem, why it matters, the fix and the code, under a review template.
  • Markdown: a report grouped by file, with your dismissals and their reasons.
  • GitHub review: a JSON payload for the pull request review API. Comments land on lines inside the diff; findings outside it go in the review body. redline never posts it. You run gh api repos/OWNER/REPO/pulls/N/reviews --input review.json.

Prompt templates

TemplateWhat it asks the agent to do
Fix these findingsFix the review findings below.…
Fix, then add a checkFix each finding below, then write the check that would have caught it: a lint rule, a test, or a type that makes the bad version impossible. Prefer one check that covers the whole…
Sweep one defect classThe findings below are instances of a few defect classes. For each class, find every instance in the codebase (not just these), fix them in one uniform pass, and list what you chan…
Adversarial Staff+ auditAct as a Staff+ engineer and security researcher doing an adversarial review. Ground rules: no filler or lint, trace across boundaries, verify before claiming, back every claim wit…
First-principles challengeStudy this project until you understand its purpose, requirements and constraints. Then imagine the code never existed. Could the same or better behavior come from far less complex…
Reduce architectural entropyGoal: reduce architectural entropy. Targets: one source of truth per fact, one canonical implementation per job, deep modules with small interfaces, high cohesion and low coupling,…
Untangle the codebaseUntangle this code: remove leaky abstractions, copy-pasted blocks, temporary workarounds that became permanent, and wrappers that only forward calls. Every change keeps behavior id…
Property tests and invariantsTurn every bug we have fixed into a property test. Find the implicit invariants in this code, then either prove each one or find a counterexample.
Find implicit state machinesFind every implicit state machine in this app: status strings, boolean pairs, flags that only make sense together. Make each one explicit (states, transitions, one place that owns …
Hot-path performance passDo a performance pass on the hot paths:…
End-to-end proofPrefer end-to-end tests as the way to prove these fixes. Write the E2E check first, watch it fail, then fix. At the end, produce a verifiable, repeatable artifact (a log, a screens…

CLI

The CLI needs Python 3.11 or later and git, and nothing else.

pip install git+https://github.com/Kevin-Liu-01/redline

Review pull requests or branches

redline build --config redline.config.json
open out/index.html

build reads each pull request with gh, diffs it as base...head so a PR in a stack shows only its own commits, and writes a static site to out/. It opens from disk with no server.

Gate CI or an agent loop

redline check $(git diff --name-only main...HEAD) --fail-on high

check reads whole files and prints path:line:col: severity rule: message. It exits 1 when any finding reaches --fail-on (high, medium, low or never).

redline rules                    # list every rule
redline rules --format json      # the same as /rules.json
redline rules --format markdown

Config

The CLI reads redline.config.json. Keep it out of version control when it names private repos or words. Every field:

{
  "title": "redline",
  "repo": "../my-app",
  "github": "my-org/my-app",
  "fetch": true,
  "out": "out",
  "groups": [
    { "name": "Auth stack", "prs": [412, 413, 415] },
    { "name": "Local work", "ranges": [{ "title": "Search rewrite", "base": "main", "head": "search-v2" }] },
    { "name": "Experiments", "folders": [{ "title": "Two copies", "before": "./old", "after": "./new" }] }
  ],
  "words": [{ "id": "client-name", "words": ["Globex", "Initech"], "severity": "high" }],
  "rules": {
    "disable": ["em-dash"],
    "severity": { "todo-marker": "medium" },
    "options": { "long-function": { "max_lines": 80 }, "deep-nesting": { "max_depth": 4 } },
    "custom": [{ "id": "no-lodash", "pattern": "from [\"']lodash[\"']", "where": "any", "why": "…", "fix": "…" }],
    "plugins": ["team_rules.py"]
  }
}
repo, githubThe local checkout and its GitHub name, for prs groups.
groups[].prsPull request numbers, read with gh. Closed ones are skipped.
groups[].rangesAny two git refs, diffed as base...head.
groups[].foldersTwo folders on disk, compared like a commit.
rules.disable, rules.onlyTurn rules off, or run only some.
rules.severityChange a rule's severity.
rules.optionsThresholds: long-function.max_lines (60), deep-nesting.max_depth (4), many-params.max_params (5), long-file.max_lines (600), duplicate-block.min_lines (6).

Your own rules

  • Word lists flag names that must never ship, such as client or project names. Matching ignores case unless you set case_sensitive.
  • Patterns are regexes with an explanation. where picks what the regex sees: code (strings and comments blanked), comment, string, text (comments and strings) or any.
  • Plugins are Python files with a RULES list, for checks that need structure. The API never loads plugins.
from redline.rules import Pattern, Rule

RULES = [
    Rule(
        id="no-moment", title="moment.js import", severity="low", category="custom",
        why="moment is large and in maintenance mode.", fix="Use Intl or Temporal.",
        bad='import moment from "moment";', good="new Intl.DateTimeFormat(locale)",
        research="custom-rules",
        patterns=(Pattern(r"from ['\"]moment['\"]", where="any"),),
        hits=('import m from "moment";',), clean=('import { format } from "date-fns";',),
    ),
]

API

POST https://redline.kevinliu.studio/api/analyze with JSON. It is open, keeps nothing, allows any origin, and accepts up to 20 changes and 3 MB of diff per change.

{
  "changes": [{
    "diff": "diff --git a/src/x.ts b/src/x.ts ...",          // required
    "title": "Add retries",                                    // optional
    "files": { "src/x.ts": { "new": "whole new file", "old": "whole old file" } },  // optional
    "base": "main", "head": "feature", "url": "https://github.com/o/r/pull/1", "number": 1, "key": "head sha"
  }],
  "rules": { "disable": ["em-dash"], "severity": { "todo-marker": "high" }, "options": {} }
}

The response is what the viewer loads:

{
  "manifest": { "rules": [...], "templates": [...], "groups": [{ "name": "Your changes", "items": [{ "id", "title", "counts", "sev", ... }] }] },
  "details": [{
    "id": "my-branch",
    "files": [{
      "path": "src/search.ts", "status": "modified", "lang": "ts", "add": 27, "del": 2,
      "lines": [...] | null,          // the whole new file when you sent it
      "hunks": [[oldStart, newStart, "section", ["+added", "-removed", " context"]]],
      "findings": [["sql-injection", 9, 9, [[24, 71]], "Builds SQL by pasting values…", 1]]
                 //  rule            line end spans      message                       added by this change
    }]
  }]
}

For example, from a branch:

curl -s https://redline.kevinliu.studio/api/analyze \
  -H 'content-type: application/json' \
  -d "$(jq -n --arg diff "$(git diff main...HEAD)" '{changes: [{title: "My branch", diff: $diff}]}')" \
  | jq '.details[0].files[] | {path, findings: [.findings[] | {rule: .[0], line: .[1], message: .[4]}]}'

Errors come back as {"error": "..."} with status 400 or 413.

Agents

  • /llms.txt describes redline and links every rule, for models that read the web.
  • /rules.json is every rule as data: id, severity, languages, why, fix, flagged and clean examples, sources.
  • Each rule page is a stable link an agent can cite when it explains a finding.
  • The API and redline check give agents a review step they can run after every edit.
  • The agent prompt export turns findings into a task, under the templates above.

Privacy

Pull request links are read by your browser, straight from GitHub. The diff and files go to /api/analyze, which analyzes them in memory, returns the findings and stores nothing. The review is kept in this browser's IndexedDB so a reload keeps it. A GitHub token stays in this tab's session storage and is sent only to api.github.com. For code that must not leave your machine, use the CLI.

Fork and self-host

  • Fork the repository or download it. Everything is MIT, the fonts are OFL and the icons are MIT.
  • The web app is Next.js with a Python function. Import the repository into Vercel and it deploys as is: vercel.json wires api/analyze.py to the engine.
  • Locally, run pnpm api for the Python API and pnpm dev for the app.
  • For no server at all, use the CLI: redline build writes a folder you can host anywhere or open from disk.

How it stays fast

  • Every page except the review is static: the rule pages and these docs are built once.
  • The review screen is plain JavaScript, about 50 KB, with no framework. It renders folded files and draws the rail from a cached layer, so scrolling only moves a box.
  • Rules run in one pass per file with masked views of code, strings and comments, so a 50-file pull request analyzes in well under a second.
  • Fonts are subset to Latin and code symbols, about 80 KB each.

Add a rule

A built-in rule is a Rule in src/redline/rules/. It carries its title, the inline message, why, fix, a flagged and a better example, and its own test cases. pytest runs every case. A new rule also needs a row with sources in docs/research.md. Then run python scripts/sync_research.py, redline rules --format markdown > docs/rules.md and python scripts/sync_web.py, which also feed these pages.