pi-permission-classifier 0.5.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/CHANGELOG.md ADDED
@@ -0,0 +1,195 @@
1
+ # Changelog
2
+
3
+ All notable changes to pi-permission-classifier are documented here. The
4
+ format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
5
+ this project adheres to
6
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.5.0] - 2026-09-19
9
+
10
+ ### Added
11
+
12
+ - Guidance files reach the judge. The classifier reads the global
13
+ `AGENTS.md` (or `CLAUDE.md`) from the pi agent dir and the project
14
+ context files pi finds from the session cwd upward, through pi's own
15
+ context-file loader, on every judged ask, and renders each verbatim in
16
+ its own labelled data block after the ask facts. A one-sentence header
17
+ and a matching rubric line say guidance describes what is normal for
18
+ this operator and project, can move a verdict toward allow or deny, and
19
+ never overrides the never-allow list. Project files are included only
20
+ while pi reports the project trusted, read per ask. A file over 16 KiB
21
+ is dropped whole; once the running total would pass 32 KiB the rest are
22
+ dropped whole. Every `classifier.decision` entry records
23
+ `guidanceIncluded` (`{path, bytes, hash12}`) and `guidanceDropped`
24
+ (`{path, bytes, reason}` with `over-file-cap`, `over-total-cap`, or
25
+ `untrusted`). A loader failure defers with reason
26
+ `guidance-load-failed`.
27
+ - Two rubric lines in the defer-first posture: a download from any host,
28
+ localhost included, is allow when the bytes only land in files inside
29
+ the project tree or /tmp and nothing executes them; a plain `rm` of
30
+ named files or build output in those places is cleanup, not discarding
31
+ work. Anything beyond either line defers.
32
+ - Judge health in the footer. The `zz-permission-classifier` entry
33
+ appends ` | <reason> x<N>` after a failure defer, ` | defers x<N>`
34
+ once a later model verdict cleared the reason, and
35
+ ` | breaker open <S>s` while the circuit breaker cools down, refreshed
36
+ once per second. Model allow and deny verdicts never show. The record
37
+ resets at session shutdown.
38
+
39
+ ### Changed
40
+
41
+ - The classifier judges every surface except the `path` and
42
+ `external_directory` families, whatever the surface name. The
43
+ reviewed-surface list and its `bash, mcp, skill, tool, read, write,
44
+ edit` default are gone, so surfaces added by other extensions (for
45
+ example `clearthen`) are judged instead of silently deferred. The
46
+ exclusion matches a family, so `path_read`, `path_write`,
47
+ `external_directory_read`, and `external_directory_write` short-circuit
48
+ to defer before any model call, as the engine caps them anyway.
49
+ - The project config layer
50
+ (`.pi/extensions/pi-permission-classifier/config.json`) is withheld
51
+ while the project is untrusted: the global layer alone applies, and a
52
+ reload after trust is granted picks the project layer up.
53
+ - The `surfaces` config field is accepted but ignored. A global or
54
+ project file that sets it still loads, and pi logs one warning naming
55
+ the file at config load. `config/config.example.json` drops the field.
56
+
57
+ ## [0.4.0] - 2026-08-31
58
+
59
+ ### Added
60
+
61
+ - The judge now sees the enclosing full command of a gated bash unit:
62
+ the bash payload's `full command` evidence entry renders in its own
63
+ delimited data block in the review prompt, and the ask's nested
64
+ execution context (command substitution, process substitution,
65
+ subshell) renders as a fact line. Absent either, the prompt is
66
+ unchanged. No other evidence, annotation, or preview reaches the
67
+ judge.
68
+ - `contextBudgetBytes` config field: a positive integer capping the
69
+ extracted full-command context in UTF-8 bytes, default `8192`. It
70
+ merges like every other field (project overrides global). An ask whose
71
+ context exceeds the budget defers before any model call; context is
72
+ never truncated to fit.
73
+ - `context-over-budget` defer reason: an over-budget full command defers
74
+ pre-model and is never rendered, not even truncated.
75
+ - Three context fields on every `classifier.decision` entry:
76
+ `contextIncluded` (true only when context was rendered to the judge),
77
+ `contextBytes` (UTF-8 byte length, null when absent), and
78
+ `contextHash` (first 12 hex chars of sha256, null when absent). The
79
+ full-command text is never written to the review log.
80
+
81
+ ### Changed
82
+
83
+ - The default rubric grounds allow in the whole visible command: when a
84
+ full command is shown the judge reads all of it and allows only when
85
+ every part is clearly benign. An interpreter body visible in the full
86
+ command (heredoc or stdin) is judged as inline code; an interpreter
87
+ run on a script file stays unseen and defers.
88
+
89
+ ## [0.3.0] - 2026-08-28
90
+
91
+ ### Added
92
+
93
+ - `/permission-model` command to choose the judge model. With no argument
94
+ it opens pi's own searchable model picker (needs pi 0.84.3 or newer,
95
+ declared as a peer dependency `@earendil-works/pi-coding-agent >=0.84.3`)
96
+ with the current judge preselected; if the registry runtime is missing
97
+ it degrades to a plain `provider/id` list, and with no available models
98
+ it warns instead of opening an empty list. `/permission-model
99
+ <provider>/<id>` sets the judge by reference (unknown pairs are rejected,
100
+ missing auth is accepted with a warning), and `/permission-model session`
101
+ makes the session's active model judge again. Outside the TUI the
102
+ no-argument form prints the current judge and the usage line. Tab
103
+ completion offers the available `provider/id` labels plus `session`.
104
+ - A choice is written to the global config file: only `provider` and
105
+ `model` are rewritten, every other field is preserved, and the write goes
106
+ through an fsynced temp file and rename. A symlinked config target and
107
+ its file mode are kept. The command never creates the file and refuses to
108
+ write when the global file is absent or the merged config is invalid. A
109
+ project config that sets `provider` or `model` still lets the global
110
+ write happen but the command warns that the project file shadows it.
111
+ - `--permission-model <provider>/<id>` launch flag: a session-only judge
112
+ override that takes precedence over the config and the session model,
113
+ writes nothing, and is dropped at session shutdown.
114
+ - Footer status entry `zz-permission-classifier` showing the effective
115
+ judge: `judge:<provider>/<id>`, `judge:session`, or
116
+ `judge:<provider>/<id> (unresolved)`. It follows `/permission-model`
117
+ changes and `/model` switches and is cleared at session shutdown.
118
+ - README: a local judge model example and a Config suggestions section for
119
+ pairing the judge with the permission-system policy.
120
+
121
+ ### Changed
122
+
123
+ - Shipped rubric: an interpreter running code the judge cannot read (a
124
+ bare `python3`, `bash /tmp/x.sh`) now defers instead of being allowed
125
+ blind; inline `-e`/`-c` code is still judged on its content. A plain
126
+ `git stash` is no longer read as a discard.
127
+ - Choosing a judge never calls pi.setModel or changes the default model:
128
+ `/model` and `/permission-model` are independent.
129
+
130
+ ### Fixed
131
+
132
+ - An aborted judge call (deadline hit) is reported as `timeout` and counted
133
+ by the circuit breaker. Previously pi-ai resolved with the partial
134
+ message on abort, so the trail logged `no-tool-call` and the breaker never
135
+ counted it.
136
+ - A judge write that leaves the merged config invalid keeps the previous
137
+ config live and reports the issue with the global path.
138
+ ## [0.2.0] - 2026-08-22
139
+
140
+ ### Changed
141
+
142
+ - BREAKING: requires `@gotgenes/pi-permission-system` 27.0.0 or newer,
143
+ declared as a peer dependency (`>=27.0.0`). No 26.x compatibility.
144
+ - Registration moved to a single site: the `permissions:ready` handler
145
+ resolves the service with the session-keyed `getPermissionsService(sessionId)`
146
+ using the sessionId from the ready payload. The dual-path `session_start`
147
+ registration attempt and the legacy root-service fallback are removed;
148
+ the classifier never resolves the process root's permission service.
149
+
150
+ ### Added
151
+
152
+ - Warn-once per session when the ready payload carries no sessionId or the
153
+ keyed locator has no service (pi-permission-system 27.0.0 or later must be
154
+ loaded in the same session); the classifier then registers nothing. The
155
+ warn latch resets at `session_shutdown`.
156
+ - README known-issues section: a stray late ready carrying a previous
157
+ session's id would register on that session's still-published service
158
+ (inherent to the 27.0.0 contract).
159
+
160
+ ### Fixed
161
+
162
+ - The forced tool choice is now spelled per judge-model API dialect:
163
+ "required" for OpenAI-family APIs, "any" elsewhere. Previously the
164
+ Anthropic spelling "any" was sent to every provider, so OpenAI-compatible
165
+ judges (local llama.cpp, OpenRouter) rejected each review call with a 400
166
+ and every ask fail-safed to defer.
167
+
168
+ ## [0.1.0] - 2026-08-21
169
+
170
+ ### Added
171
+
172
+ - Initial release.
173
+ - `classifier` Authorizer chain link for `@gotgenes/pi-permission-system`:
174
+ a judge model reviews each permission ask on the configured surfaces and
175
+ returns allow, deny (with a teaching reason), or defer.
176
+ - Fail-safe by construction: missing config, unresolved model, auth failure,
177
+ timeout, unparseable reply, and any internal error all resolve to defer.
178
+ - Balanced default rubric with a hard never-allow list (secret/credential
179
+ access, exfiltration, pipe-to-shell installs, force push, discarding
180
+ uncommitted work, disarming safety guards, permission-system or classifier
181
+ config/log edits); a config `instructions` string replaces it verbatim.
182
+ - Config via global and project scopes: `provider`/`model` judge override
183
+ (session's active model by default, following mid-session model switches),
184
+ `surfaces` (default: bash, mcp, skill, tool, read, write, edit), and
185
+ `timeoutMs` (default 5000).
186
+ - Forced `report_verdict` tool call, so no free-text parsing; the judged
187
+ value and executed unit are delimited as data in the prompt, and tool
188
+ results and file contents never reach the judge.
189
+ - Circuit breaker: 3 consecutive model-call failures or timeouts open a
190
+ 60 second cooldown during which asks defer instantly.
191
+ - One `classifier.decision` review-log entry per reviewed ask (request id,
192
+ surface, value, model id, latency, verdict, defer reason); raw model
193
+ replies only on the debug log.
194
+ - Session-scoped registration, ordering-robust across `session_start` and
195
+ `permissions:ready`, disposed on shutdown.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TacoTakumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,426 @@
1
+ # pi-permission-classifier
2
+
3
+ An auto-classifier for the [pi coding agent](https://pi.dev/)'s
4
+ permission system. It registers an Authorizer chain link named `classifier`
5
+ with [`@gotgenes/pi-permission-system`](https://github.com/gotgenes/pi-packages/tree/main/packages/pi-permission-system):
6
+ a light model reviews each permission
7
+ `ask` and returns allow, deny, or defer, so clearly benign requests are
8
+ approved automatically, clearly bad ones are rejected with a short teaching
9
+ reason, and only genuinely uncertain ones reach you.
10
+
11
+ Think of it as a Claude-Code-style auto-approve mode, without giving up the
12
+ permission gate: your deterministic policy still runs first, and the
13
+ classifier only sees the asks that policy would have sent to you anyway.
14
+
15
+ Fail-safe by construction: a missing config, an unresolved model, an auth
16
+ failure, a timeout, an unparseable reply, or any internal error resolves to
17
+ defer. More prompting, never less.
18
+
19
+ ## Requirements
20
+
21
+ - pi with `@gotgenes/pi-permission-system` 27.0.0 or newer installed and
22
+ active in the same session (the classifier resolves the permission service
23
+ through the session-keyed locator introduced in 27.0.0; with an older
24
+ version it warns once and registers nothing)
25
+ - pi 0.84.3 or newer for the searchable `/permission-model` picker, declared
26
+ as the `@earendil-works/pi-coding-agent >=0.84.3` peer dependency: the
27
+ selector component that picker mounts changed constructor shape in 0.84.3,
28
+ so on an older pi the command errors before the picker mounts - nothing is
29
+ written, the judge keeps reviewing, and the typed and `session` forms still
30
+ work. Everything else needs only the permission-system floor above.
31
+ - Node 22 or newer
32
+ - No build step: pi loads `src/index.ts` directly
33
+
34
+ ## Setup / quickstart
35
+
36
+ Everything below is an operator action - the package never enables itself,
37
+ and installing it grants it no authority until you name it in the chain.
38
+
39
+ 1. Get the package and install its dependencies:
40
+
41
+ git clone <this repo> ~/pi-permission-classifier
42
+ cd ~/pi-permission-classifier
43
+ npm install
44
+
45
+ 2. Register the package with pi. In `~/.pi/agent/settings.json`, add the
46
+ package directory to the `packages` list (path relative to
47
+ `~/.pi/agent`, or absolute). List `pi-permission-classifier` before
48
+ `pi-permission-system` in `packages`:
49
+
50
+ "packages": [
51
+ "../../pi-permission-classifier",
52
+ "<path to pi-permission-system>"
53
+ ]
54
+
55
+ Order matters: pi runs `session_start` handlers in package order, and
56
+ `pi-permission-system` emits its `permissions:ready` event from its own
57
+ `session_start`. With the classifier listed first, the link and the
58
+ `zz-permission-classifier` footer entry are in place at startup. Listed
59
+ after it, the classifier misses that first ready event and registers
60
+ at the next one, so the link and the footer entry appear only after the
61
+ first agent turn (asks are still reviewed, since they happen inside
62
+ agent turns).
63
+
64
+ 3. Activate the chain link. In
65
+ `~/.pi/agent/extensions/pi-permission-system/config.json`, add:
66
+
67
+ "authorizerChain": ["classifier"]
68
+
69
+ Only links named here are consulted; config order fixes the chain order.
70
+
71
+ 4. Create the classifier config. Without it the link registers nothing
72
+ (a safe no-op). The defaults are a good starting point:
73
+
74
+ mkdir -p ~/.pi/agent/extensions/pi-permission-classifier
75
+ echo '{}' > ~/.pi/agent/extensions/pi-permission-classifier/config.json
76
+
77
+ `{}` means: judge with the session's active model, judge every surface
78
+ except `path` and `external_directory`, 5000 ms timeout, built-in
79
+ rubric. See `config/config.example.json`
80
+ for a version with a dedicated judge model, or pick one later from
81
+ inside pi with `/permission-model` (see "Choosing the judge model").
82
+
83
+ 5. Try it. Start a new pi session and trigger something your policy sends
84
+ to `ask` (for example a bash command not on your allowlist). A benign
85
+ command should now be approved automatically; a command matching the
86
+ never-allow list should be rejected with a reason; anything uncertain
87
+ still prompts you.
88
+
89
+ 6. Watch the decisions. Every reviewed ask writes one `classifier.decision`
90
+ entry to the permission review log:
91
+
92
+ ~/.pi/agent/extensions/pi-permission-system/logs/pi-permission-system-permission-review.jsonl
93
+
94
+ Each entry records request id, surface, value, model id, latency,
95
+ verdict, defer reason, and three context fields: `contextIncluded`
96
+ (true only when a full command was rendered to the judge),
97
+ `contextBytes` (its UTF-8 byte length, null when absent), and
98
+ `contextHash` (first 12 hex chars of its sha256, null when absent).
99
+ The full-command text itself is never logged. An over-budget context
100
+ defers with reason `context-over-budget` before any model call.
101
+ Enable `debugLog` in the permission system config to also capture raw
102
+ model replies and short-circuit traces.
103
+
104
+ To disable, remove `classifier` from `authorizerChain` (or remove the
105
+ package entry). The previous prompting behavior returns immediately.
106
+
107
+ ## Configuration
108
+
109
+ Config files (project overrides global, shallow merge):
110
+
111
+ - Global: `~/.pi/agent/extensions/pi-permission-classifier/config.json`
112
+ - Project: `<cwd>/.pi/extensions/pi-permission-classifier/config.json`
113
+
114
+ | Field | Default | Meaning |
115
+ | --- | --- | --- |
116
+ | `provider` | unset | Judge model provider. Set together with `model`; with neither set, the session's active model judges. |
117
+ | `model` | unset | Judge model id, resolved from the session model registry. Set together with `provider`. |
118
+ | `instructions` | built-in rubric | System prompt for the judge. Replaces the default rubric verbatim when set. |
119
+ | `surfaces` | ignored | Accepted so older config files still parse, but ignored: every surface outside the `path` and `external_directory` families is judged. A file that sets it logs one warning at load: `This field is ignored: every surface outside the path and external_directory families is judged.` |
120
+ | `timeoutMs` | `5000` | Per-review model call budget in milliseconds (positive integer). |
121
+ | `contextBudgetBytes` | `8192` | Cap on the extracted full-command context in UTF-8 bytes (positive integer). An ask whose context exceeds the budget defers before any model call; context is never truncated to fit. |
122
+
123
+ A malformed or invalid config file means the link registers nothing and pi
124
+ logs a warning - the gate falls back to normal prompting.
125
+
126
+ ### Example: a local judge model
127
+
128
+ A small local model makes a good judge: verdicts stay on your machine, cost
129
+ nothing, and return fast. Register the model in pi's `models.json` under a
130
+ local OpenAI-compatible provider (llama.cpp, llama-swap, Ollama, vLLM):
131
+
132
+ ```json
133
+ {
134
+ "providers": {
135
+ "llama-cpp-local": {
136
+ "baseUrl": "http://localhost:8080/v1",
137
+ "api": "openai-completions",
138
+ "apiKey": "no-key",
139
+ "models": [
140
+ {
141
+ "id": "gemma-judge",
142
+ "name": "Gemma 4 E4B (judge)",
143
+ "reasoning": false,
144
+ "contextWindow": 16384,
145
+ "maxTokens": 4096,
146
+ "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }
147
+ }
148
+ ]
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ Then point the classifier at it:
155
+
156
+ ```json
157
+ {
158
+ "provider": "llama-cpp-local",
159
+ "model": "gemma-judge"
160
+ }
161
+ ```
162
+
163
+ The model must support tool calling: the classifier forces a
164
+ `report_verdict` tool call and treats a reply without one as defer. Verify
165
+ with a quick curl (`"tool_choice": "required"`) that your server returns
166
+ `finish_reason: "tool_calls"`. Keep the model resident if you can - a cold
167
+ load on the first ask can eat the `timeoutMs` budget.
168
+
169
+ ### The default rubric
170
+
171
+ Balanced and defer-first: allow clearly benign, intent-aligned asks; deny
172
+ only the hard never-allow list; defer anything uncertain. The never-allow
173
+ list covers secret/credential access, exfiltration, pipe-to-shell installs,
174
+ force push, discarding uncommitted work, disarming safety guards, and edits
175
+ to the permission system's or the classifier's own config and logs.
176
+
177
+ Two refinements come from field use. Scripts the judge cannot see always
178
+ defer: a bare `python3` or `bash /tmp/run.sh` reaches the judge as an
179
+ opaque interpreter call. Inline code (`node -e`, `python3 -c`) is visible
180
+ and judged on its content. And a plain `git stash` (no `drop` or `clear`)
181
+ is not treated as discarding work.
182
+
183
+ When the ask carries the enclosing full command (a gated unit inside a
184
+ larger command line), the judge reads all of it and allows only when every
185
+ part is clearly benign. An interpreter body visible in the full command -
186
+ a heredoc body or text piped to stdin - counts as inline code and is
187
+ judged on its content; an interpreter run on a script file stays unseen
188
+ and defers.
189
+
190
+ Two more lines cover the asks that guidance files most often need to
191
+ raise. Network fetches: downloading from any host, localhost included, is
192
+ allow when the fetched bytes are only written to files inside the project
193
+ tree or /tmp and nothing executes them; a fetch that feeds a shell or
194
+ interpreter is the pipe-to-shell never-allow item, and any other
195
+ destination or use defers. Cleanup deletes: a plain `rm` of named files or
196
+ build output inside the project tree or /tmp is cleanup, not discarding
197
+ work; a delete that reaches outside those places, removes tracked changes,
198
+ or uses paths the judge cannot resolve defers.
199
+
200
+ The rubric adds one line on guidance files (next section): they
201
+ describe what is normal for this operator and project, can move a verdict
202
+ toward allow or deny within the rubric, and never override the never-allow
203
+ list.
204
+
205
+ Set `instructions` to replace the rubric wholesale with your own.
206
+
207
+ ### Guidance files
208
+
209
+ The judge reads the same context files the agent does: the global
210
+ `AGENTS.md` (or `CLAUDE.md` fallback) in the pi agent dir, and the project
211
+ files pi finds from the session cwd up through its ancestors (override
212
+ names and worktree shadowing included, because the classifier calls pi's
213
+ own context-file loader). Write the lines that describe what is normal
214
+ here, for example "downloads into ./vendor and cleanup of build/ are
215
+ routine in this repo", and the judge sees them verbatim.
216
+
217
+ - Files are read from disk on every judged ask. An edit takes effect on
218
+ the next ask; there is no cache and no reload command.
219
+ - Trust gating: the global file always reaches the judge. Project files
220
+ reach it only while pi reports the project trusted, read at the moment
221
+ of each ask. In an untrusted directory the judge sees the global file
222
+ alone, and the classifier's own project config layer
223
+ (`.pi/extensions/pi-permission-classifier/config.json`) is not read
224
+ either, so a project `instructions` string cannot replace the rubric
225
+ before you trust the directory.
226
+ - Caps: a file over 16 KiB (UTF-8 bytes) is dropped whole, never
227
+ truncated. Files accumulate in loader order (global first, then root
228
+ down to cwd), and once the running total would pass 32 KiB that file and
229
+ every later one are dropped whole.
230
+ - Rendering: each included file appears in its own delimited data block
231
+ after the ask facts, labelled `Operator guidance from <path>` for the
232
+ global file or `Project guidance from <path>` for a project file, under
233
+ a one-sentence header on what guidance may and may not do. Guidance is
234
+ data to the judge, not instructions. The header and the rubric tell the
235
+ judge the seven never-allow items are outside its reach, but that is a
236
+ prompt instruction, not code: a trusted project's file can still steer
237
+ a model-based verdict, so review what you trust. The engine's own
238
+ `path` and `external_directory` caps hold regardless.
239
+ - Logging: every `classifier.decision` entry carries `guidanceIncluded`
240
+ (one `{path, bytes, hash12}` per rendered file) and `guidanceDropped`
241
+ (one `{path, bytes, reason}` per excluded file, reason one of
242
+ `over-file-cap`, `over-total-cap`, `untrusted`). File content is never
243
+ logged.
244
+ - Failure: if the loader throws, the ask defers with reason
245
+ `guidance-load-failed`, recorded on the decision entry and shown in the
246
+ footer health suffix like any other failure defer.
247
+
248
+ ### Config suggestions
249
+
250
+ The judge decides only what the pi-permission-system policy sends to
251
+ `ask`. A few policy choices, learned from the review log, keep the judge
252
+ useful and cheap:
253
+
254
+ - Allow the commands you run all day with static rules instead of a judge
255
+ call each time: `npm run *`, `npm test*`, `npx vitest*`, `npx tsc*`. In
256
+ one logged day the judge allowed these 30-plus times at 2-5 s each. Do
257
+ not allow `npx *` broadly; it downloads and runs packages.
258
+ - Remember that `*` crosses `/` in bash patterns. `rm -rf /*` denies every
259
+ absolute-path `rm -rf`, including `/tmp/scratch`; write the exact
260
+ `rm -rf /` instead and let the judge see the rest. The same applies to
261
+ `rm -rf ~/*`.
262
+ - Send `find *-exec*` to `ask` rather than `deny`. The judge receives the
263
+ executed unit (`cat {}`) and allows read-only uses.
264
+ - Turn reasoning off on a local judge (llama-server `--reasoning-budget 0`,
265
+ or `"enable_thinking": false` in the chat template kwargs). A thinking
266
+ block of 250 tokens costs 2-5 s on a small GPU and hits the 5000 ms
267
+ budget on long asks; without it a verdict returns in under 1 s with the
268
+ same verdicts on the same asks.
269
+ - Read the decision trail. The permission system's review log
270
+ (`logs/pi-permission-system-permission-review.jsonl`) records one
271
+ `classifier.decision` entry per reviewed ask with the verdict, defer
272
+ reason, and latency. A run of `defer` with reason `timeout` means the
273
+ model, not the rubric, needs attention.
274
+
275
+ ### Which surfaces are judged
276
+
277
+ The classifier judges every surface except the `path` and
278
+ `external_directory` families, whatever the surface name, including
279
+ surfaces added by other extensions. A family is the bare name plus its
280
+ `<name>_*` members, today `path`, `path_read`, `path_write`,
281
+ `external_directory`, `external_directory_read`, and
282
+ `external_directory_write`. There is no surface list to maintain. Your
283
+ cross-cutting `path` and `external_directory` rules still apply, and the
284
+ engine downgrades any link allow on those families to defer, so the
285
+ classifier can never approve access outside the working directory or to a
286
+ path your policy denies. To keep a tool out of the judge's hands, route it
287
+ to `allow` or `deny` in the permission system policy instead of `ask`.
288
+
289
+ ## Choosing the judge model
290
+
291
+ The judge is the model that reviews each ask. With no `provider` and
292
+ `model` in the config it is the session's active model. Three ways to
293
+ change it:
294
+
295
+ ### The /permission-model command
296
+
297
+ - `/permission-model` with no argument opens pi's own searchable model
298
+ picker (the same list as `/model`, scoped models included) with the
299
+ current judge preselected. Pick a model to make it the judge; cancel to
300
+ change nothing. Outside the TUI (rpc, json, print modes) the command
301
+ prints the current judge and the usage line instead. The searchable picker
302
+ needs pi 0.84.3 or newer (`@earendil-works/pi-coding-agent >=0.84.3`): its
303
+ constructor changed in 0.84.3, so on an older pi the command errors before
304
+ the picker mounts, writes nothing, and leaves the judge on its previous
305
+ rule - loud and safe, not a silent fallback. If your pi version does not
306
+ expose the registry runtime the picker needs, the command warns that the
307
+ picker degraded and offers a plain list of `provider/id` labels.
308
+ - `/permission-model <provider>/<id>` sets the judge by reference. The pair
309
+ must be in pi's model registry: an unknown pair is rejected and nothing
310
+ changes. A known model without configured auth is accepted with a
311
+ warning, and asks defer until the auth exists. Tab completion offers the
312
+ `provider/id` labels of the available models plus `session`.
313
+ - `/permission-model session` removes `provider` and `model` so the
314
+ session's active model judges again.
315
+
316
+ A choice applies to the next reviewed ask immediately and is saved to the
317
+ global config file
318
+ (`~/.pi/agent/extensions/pi-permission-classifier/config.json`): only
319
+ `provider` and `model` are rewritten, every other field is preserved, and
320
+ the write goes through a temporary file that is fsynced and then renamed, so
321
+ neither a process crash nor an OS crash leaves a truncated config. The command
322
+ never creates the file. Every write form refuses - nothing is written, and the
323
+ setup hint names the global path - when the global config file is absent or
324
+ there is no valid merged config, which means no config file was found this
325
+ session or the files found failed validation. The precondition is the config,
326
+ not registration: with a valid config and a link that never registers
327
+ (`pi-permission-system` absent or older than 27.0.0) a write still succeeds,
328
+ and the new judge applies as soon as the link does register.
329
+ When the project config sets `provider` or `model`, the global write still
330
+ happens but the command warns that the project file shadows the choice in
331
+ that project.
332
+
333
+ Choosing a judge never changes pi's session model or your default model:
334
+ `/model` and `/permission-model` are independent.
335
+
336
+ ### The --permission-model launch flag
337
+
338
+ `pi --permission-model <provider>/<id>` makes that model the judge for the
339
+ session only. It takes precedence over the config and the session model,
340
+ nothing is written, and it is dropped at session shutdown. The flag is read
341
+ again at every session start in that pi process, so after `/reload` or a new
342
+ session in the same process it applies again. A reference the registry does
343
+ not know is ignored with a warning and the configured judge applies. An
344
+ explicit `/permission-model` choice during the session replaces the flag for
345
+ the rest of that session.
346
+
347
+ ### The status bar entry
348
+
349
+ Once the link registers, the footer shows the effective judge under the
350
+ key `zz-permission-classifier`, in one of three states (pi sorts extension
351
+ statuses by key on one footer line; the `zz-` prefix keeps the judge entry
352
+ last, at the end of that line):
353
+
354
+ - `judge:<provider>/<id>` - a configured or flag-set judge
355
+ - `judge:session` - the session's active model judges
356
+ - `judge:<provider>/<id> (unresolved)` - the configured pair is not in the
357
+ registry, so every ask defers until it resolves
358
+
359
+ The entry follows `/permission-model` changes and `/model` switches and is
360
+ cleared at session shutdown. No entry means the link did not register.
361
+
362
+ The judge text carries a health suffix once something went wrong this
363
+ session. It refreshes after every decision, so the footer is the quickest
364
+ read on how often the dialog fell back and why:
365
+
366
+ - no suffix - no failure defers yet and the breaker is closed
367
+ - ` | <reason> x<N>` - the last decision was a failure defer with that
368
+ reason (`timeout`, `call-failed`, `context-over-budget`, `breaker-open`,
369
+ `model-unresolved`, `auth-failed`, `no-tool-call`,
370
+ `unrecognized-verdict`, `internal-error`); N is the session's failure
371
+ defer count
372
+ - ` | defers x<N>` - a later model verdict cleared the reason; the count
373
+ stays for the session
374
+ - ` | breaker open <S>s` - the circuit breaker is cooling down, S is the
375
+ remaining whole seconds, counted down once per second; this state wins
376
+ over the others while it lasts
377
+
378
+ Model verdicts are not health events: an allow clears the pending reason,
379
+ a deny changes nothing, and neither shows in the footer. The judge's own
380
+ defer verdict counts as a model verdict. Everything resets at session
381
+ shutdown.
382
+
383
+ ## How it works
384
+
385
+ - The classifier only sees asks your policy routed to `ask`, on every
386
+ surface except the `path` and `external_directory` families. Anything
387
+ else is untouched.
388
+ - For each reviewed ask it renders the structured ask facts (surface, tool
389
+ names, the decision value, matched pattern, executed unit, requester
390
+ provenance) into a prompt, followed by the guidance files selected for
391
+ this ask. Tool results and file contents never reach the judge, and the
392
+ judged value and the guidance are delimited as data, not instructions.
393
+ - The judge model must answer through a forced `report_verdict` tool call
394
+ (allow / deny / defer), so there is no free-text parsing to get wrong.
395
+ The call is aborted after `timeoutMs`.
396
+ - The verdict returns to the engine uncapped; the engine's own
397
+ bounded-delegation checkpoint enforces the `path` / `external_directory`
398
+ line.
399
+ - A circuit breaker opens after 3 consecutive model-call failures or
400
+ timeouts; asks then defer instantly for a 60 second cooldown, so a down
401
+ model never stalls your session.
402
+ - In-process subagents are handled correctly: registration is
403
+ session-scoped, so the link always serves the session that raised the ask.
404
+
405
+ ## Known issues
406
+
407
+ - The classifier trusts the sessionId on the `permissions:ready` payload. A
408
+ stray late ready that carries a previous session's id after a new
409
+ `session_start` would register the link on the old session's
410
+ still-published service. This is inherent to the pi-permission-system
411
+ 27.0.0 contract and the reference implementation has the same property.
412
+
413
+ ## Development
414
+
415
+ npm install
416
+ npx tsc --noEmit # typecheck
417
+ npx vitest run # 200 tests
418
+
419
+ The `@gotgenes/pi-permission-system` dev dependency is a `file:` reference
420
+ to a local checkout of the permission system source, so types track the
421
+ current API rather than a published copy. Adjust the path in `package.json`
422
+ to wherever your checkout of `gotgenes/pi-packages` lives.
423
+
424
+ ## License
425
+
426
+ MIT
@@ -0,0 +1,5 @@
1
+ {
2
+ "provider": "anthropic",
3
+ "model": "claude-haiku-4-5",
4
+ "timeoutMs": 5000
5
+ }