pi-auto-reviewer 1.3.0 → 2.0.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
 
@@ -79,9 +79,9 @@ 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
- - Reviewer failed twice: interactive mode prompts you manually; non-interactive mode (`pi -p`, JSON mode) blocks the command.
84
+ - Reviewer failed twice: see *Handling a failed review*. By default (`agent` mode), the command is skipped and the agent continues with guidance. In `block` (with `onReviewFailure: "ask"`) and `manual` mode, interactive sessions ask **Block** / **Allow once**, with Block as the default choice.
85
85
 
86
86
  Each review attempt writes the command and full reviewer output to the OS temporary directory under `pi-reviewer-debug/` (`/tmp/pi-reviewer-debug/` on typical Linux systems). The newest 20 files are kept. Jev failures log the error message rather than provider error bodies.
87
87
 
@@ -108,6 +108,116 @@ 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
+ ### Handling a denied command
112
+
113
+ Set `autoReviewer.onDeny` in user or trusted project settings:
114
+
115
+ ```json
116
+ { "autoReviewer": { "onDeny": "block" } }
117
+ ```
118
+
119
+ Or set `PI_REVIEWER_ON_DENY=block` for one launch. The modes are:
120
+
121
+ | Value | After the reviewer rejects a command |
122
+ | --- | --- |
123
+ | `agent` (default) | Return the error so the agent continues with guidance. |
124
+ | `block` | Stop the agent's turn; the command does not run. |
125
+ | `manual` | Ask the operator; Block stops the turn. Without a UI, or on cancellation, keep it blocked and stop the turn. |
126
+
127
+ No denied command executes in `block` or `agent` mode. In `manual` mode,
128
+ only an explicit **Allow once** permits that invocation. **Block** is the
129
+ first choice, so Enter stops the turn. Hard blocks cannot be overridden by
130
+ these settings. A failed review follows *Handling a failed review*.
131
+
132
+ The setting resolves independently of the provider/model pair:
133
+ environment → trusted project → user → `agent`. An invalid value selects
134
+ `agent`. Untrusted project settings are ignored. Use a launch-scoped
135
+ environment variable to limit this choice to a sandbox session.
136
+
137
+ `agent` mode does not grant permission to evade a refusal. The agent may
138
+ gather new evidence or choose a permitted alternative; retrying the denied
139
+ operation requires resolving the concern with evidence or explicit user
140
+ authorization. Do not replace a rejected command with another way of
141
+ performing the same unauthorized operation.
142
+
143
+ In `agent` mode, Pi receives the tool error and decides its next step. In
144
+ `block` and `manual` mode, a stopped command ends the turn. Pi stops the
145
+ turn only when every tool call in that model response asks to stop. If a
146
+ parallel call ran normally, the model gets one more step, sees this error,
147
+ and the next stopped call ends the turn. **Allow once** runs that one
148
+ command and the turn continues.
149
+
150
+ The reviewer emits `pi-auto-reviewer:denial` on `pi.events` only when the
151
+ mode is `agent` and the command stayed stopped. The payload is `sessionId`,
152
+ `toolCallId`, `handling: "agent"`, and `cause`. `cause: "denied"` means the
153
+ reviewer refused the command. `cause: "failed"` means the reviewer did not
154
+ answer; that is not a safety judgment. Earlier versions emitted this event
155
+ for every stopped command and had no `cause`. A continuation extension must
156
+ match both IDs. Manual **Block**, `block` mode, and **Allow once** emit no
157
+ denial event. Hard blocks do not emit recovery metadata.
158
+
159
+ ### Handling a failed review
160
+
161
+ Set `autoReviewer.onReviewFailure` when a review cannot get an answer
162
+ (network error, timeout, or a bad response). It does not apply to a refusal.
163
+
164
+ ```json
165
+ { "autoReviewer": { "onReviewFailure": "ask" } }
166
+ ```
167
+
168
+ Or set `PI_REVIEWER_ON_REVIEW_FAILURE` for one launch. `ask` is the default.
169
+ `follow-onDeny` uses the same stop-or-continue choice as `onDeny`. An invalid
170
+ value selects `ask`. Precedence is environment → trusted project → user →
171
+ `ask`. Untrusted project settings are ignored. The setting only changes
172
+ `block` mode: `manual` always asks, and `agent` never does.
173
+
174
+ | `onDeny` | Reviewer refuses | Reviewer fails, `ask` (default) | Reviewer fails, `follow-onDeny` |
175
+ | --- | --- | --- | --- |
176
+ | `agent` (default) | Agent continues, with refusal guidance. Event `cause: "denied"`. | Agent continues, with failure guidance. Event `cause: "failed"`. | Same as `ask`. |
177
+ | `block` | Turn stops. | Interactive session asks **Block** / **Allow once**. Block stops the turn. | Turn stops. |
178
+ | `manual` | Interactive session asks. Block stops the turn. | Interactive session asks. Block stops the turn. | Interactive session asks. Block stops the turn. |
179
+
180
+ Without a UI, `block` and `manual` stop the turn, and `agent` lets the agent
181
+ continue. A cancelled or closed dialog counts as Block. If the turn is already
182
+ aborted, no dialog is shown and the command stays stopped. **Allow once** runs
183
+ that one command.
184
+
185
+ ### Allow notifications
186
+
187
+ Allow notifications are enabled by default. To opt into quiet mode, set
188
+ `autoReviewer.notifyOnAllow` to `false` in the user or trusted project settings:
189
+
190
+ ```json
191
+ { "autoReviewer": { "notifyOnAllow": false } }
192
+ ```
193
+
194
+ Or set `PI_REVIEWER_NOTIFY_ON_ALLOW=false` (or `0`). Use `true` (or `1`) to
195
+ explicitly enable notifications. Precedence is environment → trusted project
196
+ → user → enabled by default. Other environment values are ignored. Untrusted
197
+ project settings cannot silence notifications. Blocks and failed reviews still
198
+ notify in quiet mode. Review costs are still recorded and emitted; allow charge
199
+ notifications are hidden in quiet mode.
200
+
201
+ ### Automatic permission checks
202
+
203
+ Tier 1 accepts literal commands with checked arguments, pipelines whose stages
204
+ all pass those checks, and stdout/stderr redirects to each other, closure, or
205
+ an exact `/dev/null` target. Command chaining, backgrounding, newlines,
206
+ expansions, unquoted globbing, and unsupported syntax or options require review.
207
+ Unknown command forms, including other shell dialects, also require review.
208
+ Previously permitted container/package-manager commands and PowerShell forms
209
+ now require review because their arguments are not validated here. Git repository
210
+ commands also require review: configuration can run helpers even for `git status`.
211
+ Git context collection disables filesystem-monitor hooks and optional index
212
+ writes, and skips submodule inspection.
213
+ Ripgrep requires `--no-config` as its first argument, followed by checked options,
214
+ to prevent configured preprocessors. Python's `-v` executes input and requires
215
+ review; `--version` and `-V` can run immediately.
216
+ `env` with a command, `find` execution/write/delete actions, `sort` output or
217
+ compression options, and `uniq` with an output operand always require review.
218
+ Repeated tier-3 commands receive a fresh review; approvals are not cached.
219
+
220
+
111
221
  ### Use Jev instead of an LLM
112
222
 
113
223
  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.
@@ -161,11 +271,11 @@ The presets use TypeSafe’s [`/v1/systemone`](https://docs.typesafe.ai/api) and
161
271
 
162
272
  All reviewer options follow the provider/model pair’s precedence: env → trusted project → user. Include `backend` in that same layer. A complete environment pair replaces settings-file options; incomplete pairs and untrusted project settings are ignored. Omit `backend` or set it to `"pi"` to use the LLM reviewer; unknown backend names fail review.
163
273
 
164
- Tiers 1 and 2 are unchanged. Jev validates the choice, confidence, and probability distribution; malformed, inconsistent, or tied answers fail review. There is no additional confidence threshold. The existing 60-second deadline, one retry, and manual-prompt/noninteractive-block fallback apply.
274
+ Tiers 1 and 2 are unchanged. Jev validates the choice, confidence, and probability distribution; malformed, inconsistent, or tied answers fail review. There is no additional confidence threshold. The existing 60-second deadline and one retry apply. A failed review then follows *Handling a failed review*.
165
275
 
166
276
  ## Customizing rules
167
277
 
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.
278
+ 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
279
 
170
280
  ---
171
281
 
@@ -173,7 +283,7 @@ The `autoReviewer` settings support is based on [PR #2](https://github.com/vinze
173
283
 
174
284
  ## OpenRouter review costs
175
285
 
176
- Review results show the provider-confirmed charge, for example
286
+ With allow notifications enabled, review results show the provider-confirmed charge, for example
177
287
  `Auto-reviewer: ✓ Read-only check · OpenRouter $0.003072`. Billing lookups run in the
178
288
  background. The result shows pending costs first when needed, followed by an
179
289
  updated notification once OpenRouter reports them. Billing never changes the