pi-auto-reviewer 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +89 -66
  2. package/auto-reviewer.ts +1001 -691
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,77 +1,100 @@
1
- # pi-auto-reviewer
2
-
3
- Automatically review bash commands that your pi agent wants to execute - akin to Codex "Auto-review" and Claude Code "auto mode".
4
-
5
- ## How it works
6
-
7
- Every bash command the agent wants to run goes through three tiers:
8
-
9
- | Tier | Action | Examples |
10
- |------|--------|----------|
11
- | **1. Auto-permitted** | Runs immediately | `ls`, `cd`, `grep`, `git status`, `npm list`, `echo` |
12
- | **2. Auto-blocked** | Refused immediately | `rm -rf`, `sudo`, `chmod 777`, `git push --force`, `shutdown` |
13
- | **3. Needs review** | Sent to a reviewer LLM | `git commit`, `npm install`, `curl`, `mv`, `sed -i`, `cp` |
14
-
15
- When a command falls into **Tier 3**, a subagent LLM reviews the command with project context and decides ALLOW or BLOCK.
16
-
17
- ## Install
18
-
19
- ### All projects (global)
20
-
21
- ```bash
22
- cp auto-reviewer.ts ~/.pi/agent/extensions/
23
- ```
24
-
25
- ### Via npm
26
-
27
- ```bash
28
- pi install npm:pi-auto-reviewer
29
- ```
30
-
31
- ### Single project
32
-
33
- Copy the extension into your project:
34
-
35
- ```bash
36
- cp auto-reviewer.ts .pi/extensions/
37
- ```
38
-
39
- Pi auto-discovers extensions in `.pi/extensions/` when the project is trusted.
40
-
41
- ### Single session
42
-
43
- ```bash
44
- pi -e ./auto-reviewer.ts
45
- ```
46
-
47
- ## Usage
48
-
49
- Once installed, it works automatically - no configuration required. Every bash command the agent tries to run will be reviewed.
50
-
51
- ### What to expect
52
-
53
- - **Safe commands** (Tier 1) run without any visible delay.
54
- - **Dangerous commands** (Tier 2) are blocked with a notification explaining why.
55
- - **Everything else** (Tier 3) pauses briefly while the reviewer LLM decides. You'll see a status message: `Reviewing: <command>...`
56
-
57
- - If **allowed**: the command runs and you see `Auto-reviewer: ✓ <reason>`
58
- - If **blocked**: the command is refused and you see `Auto-reviewer: ✗ <reason>`
59
- - If the reviewer **fails** (timeout, error): you're prompted interactively to allow or deny manually.
60
-
1
+ # pi-auto-reviewer
2
+
3
+ Automatically review shell commands (PowerShell or bash) that your pi agent wants to execute — akin to Codex "Auto-review" and Claude Code "auto mode".
4
+
5
+ ## How it works
6
+
7
+ Every shell command (PowerShell or bash) the agent wants to run is analyzed and routed through tiers:
8
+
9
+ | Tier | Action | Examples |
10
+ |------|--------|----------|
11
+ | **1. Auto-permitted** | Runs immediately | `ls`, `cd`, `grep`, `git status`, `npm list`, `echo` |
12
+ | **2. Auto-blocked** | Refused immediately | `rm -rf /`, `sudo`, `chmod 777`, `dd if=...`, `mkfs.*`, `shutdown`, `Start-Process -Verb RunAs` |
13
+ | **3. Reviewed by LLM** | Sent to a reviewer subagent | `git branch -D`, `git worktree remove`, `git push +refspec`, `git push --force`, `git reset --hard`, `rm -rf <dir>`, `Remove-Item -Recurse` |
14
+
15
+ When a command is reviewed, the subagent LLM receives the command plus detected **command behaviors** (e.g. "force-push", "branch-delete") and project context, then decides ALLOW or BLOCK.
16
+
17
+ ### Behavior-based detection
18
+
19
+ Instead of relying only on regex, the extension parses commands for specific risky behaviors:
20
+
21
+ | Behavior | What triggers it |
22
+ |----------|------------------|
23
+ | `force-push` | `git push --force`, `--force-with-lease`, `--force-if-includes`, or a `+refspec` |
24
+ | `branch-delete` | `git branch -d`, `-D`, or `--delete` |
25
+ | `worktree-remove` | `git worktree remove` |
26
+ | `hard-reset` | `git reset --hard` |
27
+ | `git-clean` | `git clean -f`, `-x`, `-d` (not dry-run) |
28
+ | `recursive-delete` | `rm -r`, `rm -rf` |
29
+ | `remote-shell` | `curl \| sh`, `wget \| bash`, etc. |
30
+ | `powershell-recursive-delete` | `Remove-Item -Recurse`, `del`, `rmdir /s` |
31
+ | `privilege-escalation` | `sudo`, `Start-Process -Verb RunAs` |
32
+ | `broad-chmod` | `chmod 777` |
33
+ | `disk-destructive` | `dd if=...`, `mkfs.*`, `diskpart`, `format` |
34
+ | `system-shutdown` | `shutdown`, `reboot`, `halt`, `poweroff`, `Stop-Computer` |
35
+
36
+ These behaviors are included in the reviewer prompt so the LLM can make an informed decision rather than being tricked by syntax variations like `git push origin +branch`.
37
+
38
+ ## Install
39
+
40
+ ### All projects (global)
41
+
42
+ ```bash
43
+ cp auto-reviewer.ts ~/.pi/agent/extensions/
44
+ ```
45
+
46
+ ### Via npm
47
+
48
+ ```bash
49
+ pi install npm:pi-auto-reviewer
50
+ ```
51
+
52
+ ### Single project
53
+
54
+ Copy the extension into your project:
55
+
56
+ ```bash
57
+ cp auto-reviewer.ts .pi/extensions/
58
+ ```
59
+
60
+ Pi auto-discovers extensions in `.pi/extensions/` when the project is trusted.
61
+
62
+ ### Single session
63
+
64
+ ```bash
65
+ pi -e ./auto-reviewer.ts
66
+ ```
67
+
68
+ On native Windows PowerShell, use the matching PowerShell copy commands and extension directory paths for your Pi install. The command rules include common PowerShell read-only commands such as `Get-Location`, `Get-ChildItem`, `Get-Content`, and `Test-Path`, plus Windows destructive/elevation patterns such as `Remove-Item -Recurse`, `cmd /c rmdir /s`, and `Start-Process -Verb RunAs`.
69
+
70
+ ## Usage
71
+
72
+ Once installed, it works automatically — no configuration required. Every shell command the agent tries to run will be reviewed.
73
+
74
+ ### What to expect
75
+
76
+ - **Safe commands** (Tier 1) run without any visible delay.
77
+ - **System-catastrophic commands** (Tier 2) are blocked with a notification explaining why.
78
+ - **Destructive or unknown commands** (Tier 3) pause while the reviewer LLM decides (up to 60s per attempt, with one automatic retry on failure). You'll see a status message: `Reviewing: <command>...`
79
+
80
+ - If **allowed**: the command runs and you see `Auto-reviewer: ✓ <reason>`
81
+ - If **blocked**: the command is refused and you see `Auto-reviewer: ✗ <reason>`
82
+ - If the reviewer **fails** on both attempts (timeout, error): in interactive mode you're prompted to allow or deny manually; in non-interactive mode the command is blocked.
83
+
61
84
  ### Non-interactive mode
62
85
 
63
- In print mode (`pi -p`) or JSON mode, Tier 3 commands are blocked by default since there's no UI to fall back on.
86
+ In print mode (`pi -p`) or JSON mode, reviewed commands are still sent to the reviewer LLM. If review fails (timeout, error), the command is blocked because there is no UI to fall back on.
64
87
 
65
88
  ## Configuration
66
89
 
67
- By default, Tier 3 review uses your normal pi inference provider and model. You can route reviewer calls to a specific provider and model with environment variables:
90
+ By default, reviewed commands use your normal pi inference provider and model. You can route reviewer calls to a specific provider and model with environment variables:
68
91
 
69
92
  | Variable | Purpose |
70
93
  |----------|---------|
71
94
  | `PI_REVIEWER_PROVIDER` | Inference provider for the reviewer subprocess, for example `opencode-go` |
72
95
  | `PI_REVIEWER_MODEL` | Model for the reviewer subprocess, for example `deepseek-v4-flash` |
73
96
 
74
- Set both variables together:
97
+ Set both provider/model variables together:
75
98
 
76
99
  ```bash
77
100
  export PI_REVIEWER_PROVIDER=opencode-go
@@ -79,10 +102,10 @@ export PI_REVIEWER_MODEL=deepseek-v4-flash
79
102
  pi
80
103
  ```
81
104
 
82
- `export` only affects the current shell session. To keep these settings across new terminals, add the two `export` lines to your shell startup file, for example `~/.bashrc` on many Linux and WSL setups. Other shells use different files, such as `~/.zshrc` for zsh.
105
+ `export` only affects the current shell session. To keep these settings across new terminals, add the `export` lines to your shell startup file, for example `~/.bashrc` on many Linux and WSL setups. Other shells use different files, such as `~/.zshrc` for zsh.
83
106
 
84
- If either variable is missing or empty, the reviewer uses pi's configured default provider and model. This avoids accidentally selecting a model name from the wrong provider when the same model id is available in more than one place.
107
+ If either `PI_REVIEWER_PROVIDER` or `PI_REVIEWER_MODEL` is missing or empty, the reviewer uses pi's configured default provider and model. This avoids accidentally selecting a model name from the wrong provider when the same model id is available in more than one place.
85
108
 
86
109
  ## Customizing review rules
87
110
 
88
- Edit `AUTO_PERMITTED` and `AUTO_BLOCKED` arrays in `auto-reviewer.ts` to add or remove patterns. Edit `buildReviewPrompt()` to change how the reviewer LLM decides.
111
+ Edit `AUTO_PERMITTED` and `AUTO_BLOCKED` arrays in `auto-reviewer.ts` to add or remove patterns. Edit `buildReviewPrompt()` and the behavior analyzer (`analyzeCommand` and helpers) to change how commands are classified and what the reviewer LLM sees.