Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📋 pi-diff-risk

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.

中文版本 →


The Problem

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.

How It Works

agent_started          agent works           agent_settled
    │                      │                       │
    ▼                      ▼                       ▼
takeSnapshot()     agent modifies files     takeSnapshot()
    │                      │                       │
    │  prevSnapshot        │                   currSnapshot
    │                      │                       │
    └──────────────────────┴───────────────────────┘
                           │
                      detectChanges()
                           │
                     buildFsFileContext()
                           │
                        scoreFile()
                           │
                      buildReport()
                           │
                    appendEntry() → bottom card

Snapshots

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.

Change Detection

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).

Risk Scoring

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)

Examples

Legend: █ red HIGH█ yellow MED█ green LOWgray unchanged

Routine feature branch — all clear

Agent touched a few Astro components and config files. All low risk — ship it.

Example 1: routine feature branch - LOW risk

Auth module changed, tests missing — needs a look

Agent modified authentication logic but didn't touch any tests. Two files flagged medium risk.

Example 2: auth module changed, tests missing - MED risk

Full refactor, massive diff — high risk

Agent rewrote a 600-line payments module with no test coverage. Flagged red.

Example 3: full refactor, massive diff - HIGH risk

Usage

# Launch PI in any project directory
cd /path/to/your/project
pi

Inside 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.

Configuration

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.

Limitations

  • 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_started to take the initial snapshot first)
  • Files ≥200KB skip content diffing; only size/mtime compared
  • Line-level diff precision is lower than git diff (LCS estimate, not patch-level)

Credits

  • Risk scoring methodology: inspired by augur (CorvidLabs), adapting its 8-signal system for filesystem-only operation
  • Built as a PI Coding Agent extension

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages