CodingOpen SourceFreeActiveMachine-verified· beginner · ~5 min setup

Pi: The Safe Diff Reviewer

A code reviewer that reads your staged diff and structurally cannot modify it.

by Shilpa Mitra· verified 12d ago· v1.0.0

Run this workflow

CI-verified, 4/4 fixtures passing.

Intended Use

Anyone who wants an AI second-pair-of-eyes on a diff in a pre-commit hook or CI step, where a tool allowlist (not a polite prompt) guarantees the reviewer can't touch the code.

Not for

  • Letting the agent fix issues (this run is read-only by design)
  • Anyone unwilling to bring their own model key/subscription

The Stack

Tested Against

pi@0.74git@2.30+node@20.x

Side effects & data flow

Network
your model provider, only in the non-CI review step
Writes
no filesystem writes
Credentials
model API key/subscription, for the review step only

Data privacy

  • your model provider, only in the non-CI review step your staged diff (retention: per that provider's API policy)

Prerequisites

  • Pi (MIT): `npm install -g --ignore-scripts @earendil-works/pi-coding-agent`
  • A model key/subscription — Pi auto-detects the provider (e.g. `export ANTHROPIC_API_KEY=…`), only needed to run the review
  • git (the diff source)

Steps

  1. 1

    Scaffold a staged diff and prove the allowlist is read-only

    CI installs Pi, builds a repo with a real staged change, and asserts the exact allowlist from the workflow (`read,grep,find,ls`) genuinely excludes write/edit/bash — the structural guarantee that makes the reviewer safe, not a prompt asking nicely.

    export PI_CODING_AGENT_DIR="$PWD/.pi"
    pi --version >/dev/null || { echo "pi missing"; exit 1; }
    git init -q && git config user.email ci@flowstacks.xyz && git config user.name ci
    printf 'def add(a, b):\n    return a+b\n' > calc.py && git add calc.py && git commit -qm init
    printf 'def add(a, b):\n    return a + b\n' > calc.py && git add calc.py
    test -n "$(git diff --staged)" && echo "staged diff: non-empty"
    ALLOW="read,grep,find,ls"
    if echo "$ALLOW" | grep -qE '(^|,)(write|edit|bash)(,|$)'; then echo "ALLOWLIST NOT READ-ONLY"; exit 1; fi
    echo "allowlist read-only: $ALLOW (write,edit,bash excluded)"
    pi --help 2>&1 | grep -q -- "--tools" && echo "pi supports --tools allowlist"
  2. 2

    Run the review (the model step, not checked by CI)

    Pipe the diff in: `git diff --staged | pi --tools read,grep,find,ls -p "Review this diff for bugs, security issues, and missing tests. Be concise."`. The allowlist means write/edit/bash are off, so it physically can't change your code. The review itself calls a model, so CI doesn't run it.

Eval, 4 fixtures

Last passed: verified 12d ago
  • staged-diffcontainstimeout 60s · max $0

    Expected: staged diff: non-empty

  • read-onlycontainstimeout 60s · max $0

    Expected: allowlist read-only: read,grep,find,ls (write,edit,bash excluded)

  • pi-toolscontainstimeout 60s · max $0

    Expected: pi supports --tools allowlist

  • clean-exitexit_codetimeout 60s · max $0

    Expected: 0

Results

The instant-win, drop-it-in-a-pre-commit-hook pick from the WebAfterAI guide.

Liked this workflow?

Get new verified workflows in WebAfterAI, three issues a week (Tue, Thu, Sat).