Your PI Coding Agent just touched 50 files and 1,200 lines. Do you merge?
pi-diff-risk is a PI Coding Agent extension. After every agent turn, it scans your project for file changes, assigns a risk label to each file, and renders the result as a color-coded directory tree in a bottom panel.
Colored tree demos, a live risk-score calculator, and three side-by-side scenarios — everything on one page.
In the era of vibe coding, a single agent turn can modify dozens of files. You can't reasonably review every change line-by-line — but shipping blindly is terrifying. What if it rewrote the auth logic? Dropped a critical config? Stuffed 2,000 lines into a single file with zero test coverage?
You don't need to review everything. You need triage: a way to instantly see which changes demand your attention, and which ones you can confidently skip.
pi-diff-risk is that triage layer. It needs no git repo, no GitHub, no setup. Just launch PI in your project directory and it takes care of the rest.
agent_started agent works agent_settled
│ │ │
▼ ▼ ▼
takeSnapshot() agent modifies files takeSnapshot()
│ │ │
│ prevSnapshot │ currSnapshot
│ │ │
└──────────────────────┴───────────────────────┘
│
detectChanges()
│
buildFsFileContext()
│
scoreFile()
│
buildReport()
│
appendEntry() → bottom card
Recursively scans the project directory, recording every file's size and mtime. For text files ≤200KB, saves full content for later line-level diffing. Skips node_modules, .git, dist, __pycache__, images, and binaries automatically.
Compares two snapshots by path. New files → added. Changed size/mtime → modified. Missing from new snapshot → deleted. For modified files, computes line-level +N/-M using LCS (Longest Common Subsequence).
Three signals, weighted and multiplied by a file-type coefficient → 0-100 risk score:
| Signal | Weight | What it detects |
|---|---|---|
| sensitivity | 0.40 | Path + diff content matching 8 sensitive categories: auth, secrets, crypto, payments, migrations, infra, CI, deps |
| test-gap | 0.35 | Source file changed without a corresponding test file in the same changeset. Test files and docs are exempt |
| diff-size | 0.25 | Change size: ≥500 lines = 1.0 / ≥200 = 0.7 / ≥80 = 0.4 / ≥20 = 0.15 / <20 = 0 |
File-type multiplier: .ts/.py/.go = 1.0, .json/.yaml = 0.7, .md = 0.2, etc.
Thresholds: ≥65 red (HIGH) | ≥35 yellow (MED) | <35 green (LOW)
Legend: █ red HIGH | █ yellow MED | █ green LOW | gray unchanged
Agent touched a few Astro components and config files. All low risk — ship it.
Agent modified authentication logic but didn't touch any tests. Two files flagged medium risk.
Agent rewrote a 600-line payments module with no test coverage. Flagged red.
# Launch PI in any project directory
cd /path/to/your/project
piInside PI:
- Auto mode (on by default): risk card appears after every agent turn
- Manual trigger:
/fsrisk - Turn off:
/fsrisk off - Turn on:
/fsrisk on
Status bar shows 📋 auto on when auto mode is active.
Config file: ~/.pi/agent/pi-diff-risk.json
{
"auto": true,
"thresholds": { "review": 35, "block": 65 },
"weights": {
"sensitivity": 0.40,
"testGap": 0.35,
"churn": 0,
"diffSize": 0.25,
"ownership": 0
}
}Raise thresholds.block to reduce false positives, or lower thresholds.review to bring more changes into your attention zone.
- Churn and ownership signals require git commit history; unavailable in pure filesystem mode (weights fixed at 0)
- No output on the very first agent turn (needs
agent_startedto take the initial snapshot first) - Files ≥200KB skip content diffing; only
size/mtimecompared - Line-level diff precision is lower than
git diff(LCS estimate, not patch-level)
- Risk scoring methodology: inspired by augur (CorvidLabs), adapting its 8-signal system for filesystem-only operation
- Built as a PI Coding Agent extension
MIT


