pi-auto-mode 0.1.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 ADDED
@@ -0,0 +1,241 @@
1
+ # pi-auto-mode
2
+
3
+ A pi package that re-implements the core of Claude Code's auto mode for pi.
4
+
5
+ It is modeled after [`lghupan/cc-automode`](https://github.com/lghupan/cc-automode):
6
+
7
+ - read-only tool allowlist fast path
8
+ - deterministic hard-deny checks for obviously unsafe actions
9
+ - two-stage classifier on every non-allowlisted tool call
10
+ - consecutive/total denial tracking
11
+ - auto-mode execution guidance injected into pi's system prompt
12
+ - denial history widget in the UI
13
+ - user override prompt on denials
14
+
15
+ ## What it does
16
+
17
+ When enabled, the extension intercepts tool calls in pi:
18
+
19
+ 1. `read`, `grep`, `find`, and `ls` are allowed immediately by default.
20
+ - this allowlist is also extended from local Claude Code project settings in:
21
+ - `.claude/settings.user.json`
22
+ - `.claude/settings.json`
23
+ - the extension reads `permissions.allow`, `permissions.allowedTools`, `allow`, and `allowedTools` arrays when present
24
+ 2. obvious hard-deny patterns are blocked immediately:
25
+ - shell profile writes
26
+ - cron creation
27
+ - TLS verification weakening
28
+ - destructive deletes outside the workspace
29
+ - SSH key injection
30
+ - auto-mode self-modification
31
+ 3. everything else is classified with a two-stage LLM check:
32
+ - stage 1: cheap `YES` / `NO` filter
33
+ - stage 2: full JSON decision with reasoning only if stage 1 flags the action
34
+ 4. if a denial happens in interactive mode, pi asks you whether to:
35
+ - block
36
+ - allow once
37
+ - disable auto mode and allow
38
+
39
+ ## Install
40
+
41
+ ### From npm
42
+
43
+ Once published, the package can be installed from npm:
44
+
45
+ ```bash
46
+ npm install pi-auto-mode
47
+ ```
48
+
49
+ ### Directly from GitHub
50
+
51
+ You do not need to clone the repo first.
52
+
53
+ ```bash
54
+ pi install git:github.com/r4vi/pi-auto-mode
55
+ ```
56
+
57
+ You can also pin a ref:
58
+
59
+ ```bash
60
+ pi install git:github.com/r4vi/pi-auto-mode@main
61
+ # or a tag / commit
62
+ pi install git:github.com/r4vi/pi-auto-mode@<tag-or-commit>
63
+ ```
64
+
65
+ Raw GitHub URLs work too:
66
+
67
+ ```bash
68
+ pi install https://github.com/r4vi/pi-auto-mode
69
+ ```
70
+
71
+ ### As a local package
72
+
73
+ From the directory containing this package:
74
+
75
+ ```bash
76
+ pi install ./pi-auto-mode
77
+ ```
78
+
79
+ ### For one-off testing
80
+
81
+ ```bash
82
+ pi -e ./pi-auto-mode/extensions/auto-mode.ts
83
+ ```
84
+
85
+ ## Usage
86
+
87
+ Once loaded, auto mode is enabled by default.
88
+
89
+ Commands:
90
+
91
+ ```text
92
+ /auto-mode status
93
+ /auto-mode on
94
+ /auto-mode off
95
+ /auto-mode toggle
96
+ /auto-mode reset
97
+ /auto-mode reload
98
+ /auto-mode model
99
+ /auto-mode model github-copilot/gpt-5.4-mini
100
+ ```
101
+
102
+ If no dedicated classifier model is configured, the extension prompts you to choose one when auto mode is enabled in interactive mode.
103
+
104
+ ## UI additions
105
+
106
+ - footer status for auto mode state
107
+ - recent denial history widget below the editor
108
+ - interactive override prompt when a denial happens
109
+
110
+ ## Configuration
111
+
112
+ ### Claude project allowlist interoperability
113
+
114
+ pi-auto-mode merges Claude Code tool allowlists from two places into its own fast-path allowlist:
115
+
116
+ Project-local files:
117
+
118
+ - `.claude/settings.user.json`
119
+ - `.claude/settings.json`
120
+
121
+ Global user files:
122
+
123
+ - `~/.claude/settings.user.json`
124
+ - `~/.claude/settings.json`
125
+
126
+ Supported fields:
127
+
128
+ - `permissions.allow`
129
+ - `permissions.allowedTools`
130
+ - `allow`
131
+ - `allowedTools`
132
+
133
+ Examples recognized:
134
+
135
+ ```json
136
+ {
137
+ "permissions": {
138
+ "allow": ["Bash(*)", "Read(*)", "Edit(src/**)"]
139
+ }
140
+ }
141
+ ```
142
+
143
+ Those entries are normalized to tool names for pi's allowlist fast path, so `Bash(*)` becomes `bash`, `Read(*)` becomes `read`, etc.
144
+
145
+ It does not walk parent directories. It only reads the current project directory plus the global `~/.claude` directory.
146
+
147
+ You can inspect the merged result with:
148
+
149
+ ```text
150
+ /auto-mode status
151
+ ```
152
+
153
+ ## Configuration
154
+
155
+ Create either of these in the target project:
156
+
157
+ - `.pi/auto-mode.json`
158
+ - `auto-mode.json`
159
+
160
+ Start from [`auto-mode.example.json`](./auto-mode.example.json).
161
+
162
+ Example:
163
+
164
+ ```json
165
+ {
166
+ "enabled": true,
167
+ "classifierModel": "github-copilot/gpt-5.4-mini",
168
+ "failOpen": true,
169
+ "maxConsecutiveDenials": 3,
170
+ "maxTotalDenials": 20,
171
+ "maxTranscriptLines": 60,
172
+ "reasoningEffort": "high",
173
+ "allowlistedTools": ["read", "grep", "find", "ls"],
174
+ "environment": [
175
+ "**Trusted repo**: this repository and its configured remotes",
176
+ "**Trusted internal domains**: api.mycorp.internal, registry.mycorp.internal"
177
+ ],
178
+ "allowRules": [],
179
+ "denyRules": []
180
+ }
181
+ ```
182
+
183
+ ### Notes
184
+
185
+ - `classifierModel` is optional. If omitted, the extension uses the current active pi model.
186
+ - For a cheap GitHub Copilot-backed classifier, `github-copilot/gpt-5.4-mini` is a good default.
187
+ - The extension currently fails open by default, matching the reference repo's behavior when the classifier is unavailable.
188
+
189
+ ## Files
190
+
191
+ - `package.json` — pi package manifest
192
+ - `extensions/auto-mode.ts` — the extension
193
+ - `auto-mode.example.json` — starter config
194
+
195
+ ## Known gaps vs official Claude Code auto mode
196
+
197
+ This package mirrors the open-source reference architecture, not Anthropic's private implementation.
198
+
199
+ Current differences:
200
+
201
+ - no server-side prompt-injection probe
202
+ - no provider-side caching optimizations beyond what the selected model/provider already does
203
+ - JSON parsing is used for stage 2 instead of a dedicated classifier tool call
204
+ - policy is project-config based rather than Claude hook config based
205
+
206
+ ## Development
207
+
208
+ This package is intentionally dependency-light and relies on pi's extension runtime.
209
+
210
+ ## Publish to npm
211
+
212
+ This repository includes a GitHub Actions workflow at `.github/workflows/publish.yml` that publishes the package to npm using trusted publishing.
213
+
214
+ ### First publish
215
+
216
+ Because `pi-auto-mode` does not exist on npm yet, do the first publish once from your machine:
217
+
218
+ 1. Log in to npm from your shell.
219
+ 2. Run `npm publish --access public` from the repository root.
220
+ 3. Confirm the package exists on npm.
221
+
222
+ After that first publish, switch the repository to trusted publishing.
223
+
224
+ ### Switch to trusted publishing
225
+
226
+ After the package exists on npm, switch to npm trusted publishing:
227
+
228
+ 1. In npm package settings, add a trusted publisher for this GitHub repository:
229
+ - owner: `r4vi`
230
+ - repository: `pi-auto-mode`
231
+ - workflow file: `publish.yml`
232
+ 2. Keep the package public so the workflow can publish with `--access public`.
233
+
234
+ Release flow:
235
+
236
+ 1. Bump `version` in `package.json`.
237
+ 2. Commit and push the change.
238
+ 3. Create a GitHub release whose tag matches the package version, with or without a leading `v`.
239
+ 4. The workflow publishes the package to npm and attaches npm provenance automatically.
240
+
241
+ You can also run the workflow manually from the Actions tab with `workflow_dispatch`.
@@ -0,0 +1,18 @@
1
+ {
2
+ "enabled": true,
3
+ "classifierModel": "github-copilot/gpt-5.4-mini",
4
+ "failOpen": true,
5
+ "maxConsecutiveDenials": 3,
6
+ "maxTotalDenials": 20,
7
+ "maxTranscriptLines": 60,
8
+ "reasoningEffort": "high",
9
+ "allowlistedTools": ["read", "grep", "find", "ls"],
10
+ "environment": [
11
+ "**Trusted repo**: the repository pi started in and its configured git remotes",
12
+ "**Trusted internal domains**: add your own domains here",
13
+ "**Trusted cloud buckets**: add your own buckets here",
14
+ "**Key internal services**: add your own hosts here"
15
+ ],
16
+ "allowRules": [],
17
+ "denyRules": []
18
+ }