pi-auto-reviewer 1.2.0 → 1.4.0

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.
package/README.md CHANGED
@@ -12,7 +12,7 @@ Every shell command is routed into one of three tiers:
12
12
 
13
13
  | Tier | Action | Examples |
14
14
  |------|--------|----------|
15
- | **1. Auto-permitted** | Runs immediately | `ls`, `grep`, `git status`, `npm list` |
15
+ | **1. Auto-permitted** | Runs immediately | `ls`, `grep`, `sort in.txt`, `git --version` |
16
16
  | **2. Auto-blocked** | Refused immediately | `rm -rf /`, `sudo`, `chmod 777`, `mkfs.*`, `shutdown` |
17
17
  | **3. Model-reviewed** | Sent to the configured reviewer | `git push --force`, `git reset --hard`, `rm -rf <dir>`, `Remove-Item -Recurse` |
18
18
 
@@ -47,7 +47,7 @@ These behaviors are included in the reviewer prompt:
47
47
  Global (all projects):
48
48
 
49
49
  ```bash
50
- cp auto-reviewer.ts review-tool.ts jev-decisions.ts ~/.pi/agent/extensions/pi-auto-reviewer/
50
+ cp auto-reviewer.ts review-tool.ts jev-decisions.ts reviewer-cost.ts ~/.pi/agent/extensions/pi-auto-reviewer/
51
51
  ```
52
52
 
53
53
  Via npm:
@@ -59,7 +59,7 @@ pi install npm:pi-auto-reviewer
59
59
  Single project:
60
60
 
61
61
  ```bash
62
- cp auto-reviewer.ts review-tool.ts jev-decisions.ts .pi/extensions/
62
+ cp auto-reviewer.ts review-tool.ts jev-decisions.ts reviewer-cost.ts .pi/extensions/
63
63
  ```
64
64
 
65
65
  Pi loads extensions from `.pi/extensions/` only after the project is trusted.
@@ -70,7 +70,7 @@ Single session:
70
70
  pi -e ./auto-reviewer.ts
71
71
  ```
72
72
 
73
- All three `.ts` files must sit side by side. `jev-decisions.ts` provides the Jev HTTP driver. For the pi backend, `review-tool.ts` provides the structured decision channel; without it the reviewer falls back to text parsing only. On Windows PowerShell, use the matching copy commands and extension paths.
73
+ All four `.ts` files must sit side by side. `jev-decisions.ts` provides the Jev HTTP driver. For the pi backend, `review-tool.ts` provides the structured decision channel; without it the reviewer falls back to text parsing only. On Windows PowerShell, use the matching copy commands and extension paths.
74
74
 
75
75
  ## Usage
76
76
 
@@ -79,7 +79,7 @@ Works automatically, no configuration required.
79
79
  - Tier 1 runs without visible delay.
80
80
  - Tier 2 is blocked with a notification explaining why.
81
81
  - Tier 3 handles destructive or unknown commands and pauses with `Reviewing: <command>...` (up to 60s per attempt, one automatic retry).
82
- - Allowed: command runs, `Auto-reviewer: ✓ <reason>`
82
+ - Allowed: command runs, `Auto-reviewer: ✓ <reason>` (set `notifyOnAllow` to `false` for quiet mode)
83
83
  - Blocked: command refused, `Auto-reviewer: ✗ <reason>`
84
84
  - Reviewer failed twice: interactive mode prompts you manually; non-interactive mode (`pi -p`, JSON mode) blocks the command.
85
85
 
@@ -108,6 +108,42 @@ Or persistently via `autoReviewer` in `~/.pi/agent/settings.json` (user) or `.pi
108
108
  Provider and model resolve as a pair (env → trusted project → user → pi default); a layer specifying only one of the two is ignored entirely.
109
109
 
110
110
 
111
+ ### Allow notifications
112
+
113
+ Allow notifications are enabled by default. To opt into quiet mode, set
114
+ `autoReviewer.notifyOnAllow` to `false` in the user or trusted project settings:
115
+
116
+ ```json
117
+ { "autoReviewer": { "notifyOnAllow": false } }
118
+ ```
119
+
120
+ Or set `PI_REVIEWER_NOTIFY_ON_ALLOW=false` (or `0`). Use `true` (or `1`) to
121
+ explicitly enable notifications. Precedence is environment → trusted project
122
+ → user → enabled by default. Other environment values are ignored. Untrusted
123
+ project settings cannot silence notifications. Blocks and failed reviews still
124
+ notify in quiet mode. Review costs are still recorded and emitted; allow charge
125
+ notifications are hidden in quiet mode.
126
+
127
+ ### Automatic permission checks
128
+
129
+ Tier 1 accepts literal commands with checked arguments, pipelines whose stages
130
+ all pass those checks, and stdout/stderr redirects to each other, closure, or
131
+ an exact `/dev/null` target. Command chaining, backgrounding, newlines,
132
+ expansions, unquoted globbing, and unsupported syntax or options require review.
133
+ Unknown command forms, including other shell dialects, also require review.
134
+ Previously permitted container/package-manager commands and PowerShell forms
135
+ now require review because their arguments are not validated here. Git repository
136
+ commands also require review: configuration can run helpers even for `git status`.
137
+ Git context collection disables filesystem-monitor hooks and optional index
138
+ writes, and skips submodule inspection.
139
+ Ripgrep requires `--no-config` as its first argument, followed by checked options,
140
+ to prevent configured preprocessors. Python's `-v` executes input and requires
141
+ review; `--version` and `-V` can run immediately.
142
+ `env` with a command, `find` execution/write/delete actions, `sort` output or
143
+ compression options, and `uniq` with an output operand always require review.
144
+ Repeated tier-3 commands receive a fresh review; approvals are not cached.
145
+
146
+
111
147
  ### Use Jev instead of an LLM
112
148
 
113
149
  The LLM reviewer remains the default. Set `backend` to `"jev"` to send tier-3 commands to Jev’s Decisions API. Jev uses the same review rules and context, then returns a typed `allow` or `block` choice. The displayed reason is a fixed description of that choice, rather than a generated explanation.
@@ -165,8 +201,57 @@ Tiers 1 and 2 are unchanged. Jev validates the choice, confidence, and probabili
165
201
 
166
202
  ## Customizing rules
167
203
 
168
- Edit `auto-reviewer.ts`: `AUTO_PERMITTED` / `AUTO_BLOCKED` for tier patterns, `defeatsAutoPermit()` and `SECRET_ENV_VAR` for what forces review, `analyzeCommand` and `buildReviewPrompt()` for behavior detection and the reviewer prompt.
204
+ Edit `auto-reviewer.ts`: `READ_ONLY_OPTIONS`, `readOnlyCommand()`, and `readOnlyStages()` for automatic permission checks, `AUTO_BLOCKED` for hard blocks, `analyzeCommand` and `buildReviewPrompt()` for behavior detection and the reviewer prompt.
169
205
 
170
206
  ---
171
207
 
172
208
  The `autoReviewer` settings support is based on [PR #2](https://github.com/vinzenzu/pi-auto-reviewer/pull/2) by [JiChenSSG](https://github.com/JiChenSSG).
209
+
210
+ ## OpenRouter review costs
211
+
212
+ With allow notifications enabled, review results show the provider-confirmed charge, for example
213
+ `Auto-reviewer: ✓ Read-only check · OpenRouter $0.003072`. Billing lookups run in the
214
+ background. The result shows pending costs first when needed, followed by an
215
+ updated notification once OpenRouter reports them. Billing never changes the
216
+ allow/block decision or delays command execution. Confirmed review charges also
217
+ enter pi's native cost totals and breakdown through persisted, cost-only usage
218
+ entries. This works without any other extension and leaves token counts intact.
219
+ Billing currently supports OpenRouter only. Reviews through other providers
220
+ show no cost label and emit no OpenRouter billing events.
221
+
222
+ Tested only with pi 0.87.1.
223
+
224
+ Uses pi's saved OpenRouter credential. The pi backend looks up generation charges;
225
+ the Jev backend uses OpenRouter's returned `usage.cost`, including billed attempts
226
+ with invalid verdicts, without a second lookup when that charge is available.
227
+ Each generation is counted once, including
228
+ failed review attempts and IDs observed before a subprocess was killed. Missing
229
+ IDs, credentials or billing records stay visibly unavailable. Lookups retry six
230
+ times, with a five-second timeout and at most three concurrent lookups per review.
231
+ If a process exits before billing settles, its saved pending IDs can be
232
+ reconciled by a cost-extension consumer on resume. No spending cap is added.
233
+
234
+ Public integration: subscribe to `pi-auto-reviewer:cost` through `pi.events.on`.
235
+ Payload type `ReviewerCostEvent` is exported from `reviewer-cost.ts`:
236
+
237
+ ```typescript
238
+ {
239
+ parentSessionId: string; // accounting owner, not an OpenRouter routing setting
240
+ reviewId: string; // shell tool-call ID
241
+ provider: "openrouter";
242
+ responseId: string;
243
+ model?: string;
244
+ status: "pending" | "confirmed" | "unavailable";
245
+ costUSD?: number; // present only when confirmed; zero is valid
246
+ }
247
+ ```
248
+
249
+ The same payload is persisted in custom entries named `pi-auto-reviewer-cost`,
250
+ outside the model context. Consumers should deduplicate by response ID and use
251
+ the confirmed `costUSD`; they do not need to issue a second billing lookup.
252
+ The package has no dependency on a particular cost extension or local path.
253
+ This feature does not change reviewer session IDs or provider routing.
254
+
255
+ For source tests, use Node.js 24, run `npm install` to resolve the pi peer
256
+ dependency, then `npm test`. Tests use fake credentials and mocked provider
257
+ responses, plus a local HTTP fixture; they do not issue paid model requests.