@aliou/pi-guardrails 0.11.2 → 0.12.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 +72 -167
- package/extensions/guardrails/commands/examples/index.ts +520 -0
- package/extensions/guardrails/commands/onboarding/config.ts +54 -0
- package/{src/commands/onboarding-command.ts → extensions/guardrails/commands/onboarding/index.ts} +5 -31
- package/extensions/guardrails/commands/settings/add-rule-wizard.ts +267 -0
- package/extensions/guardrails/commands/settings/examples.ts +399 -0
- package/extensions/guardrails/commands/settings/index.ts +596 -0
- package/extensions/guardrails/commands/settings/path-list-editor.ts +158 -0
- package/extensions/guardrails/commands/settings/scope-picker-submenu.ts +69 -0
- package/extensions/guardrails/commands/settings/utils.ts +108 -0
- package/extensions/guardrails/components/onboarding-choice-step.ts +140 -0
- package/extensions/guardrails/components/onboarding-finish-step.ts +50 -0
- package/extensions/guardrails/components/onboarding-intro-step.ts +30 -0
- package/extensions/guardrails/components/onboarding-types.ts +10 -0
- package/extensions/guardrails/components/onboarding-wizard.ts +116 -0
- package/{src → extensions/guardrails}/components/pattern-editor.ts +11 -10
- package/extensions/guardrails/index.ts +106 -0
- package/extensions/guardrails/rules.test.ts +107 -0
- package/extensions/guardrails/rules.ts +119 -0
- package/extensions/guardrails/targets.test.ts +44 -0
- package/extensions/guardrails/targets.ts +66 -0
- package/extensions/path-access/grants.test.ts +47 -0
- package/extensions/path-access/grants.ts +68 -0
- package/extensions/path-access/index.ts +143 -0
- package/extensions/path-access/prompt.ts +196 -0
- package/extensions/path-access/rules.test.ts +46 -0
- package/extensions/path-access/rules.ts +37 -0
- package/extensions/path-access/targets.test.ts +40 -0
- package/extensions/path-access/targets.ts +19 -0
- package/extensions/permission-gate/grants.ts +21 -0
- package/extensions/permission-gate/index.ts +122 -0
- package/extensions/permission-gate/prompt.ts +222 -0
- package/extensions/permission-gate/rules.test.ts +132 -0
- package/extensions/permission-gate/rules.ts +72 -0
- package/package.json +18 -20
- package/schema.json +286 -0
- package/src/core/check.test.ts +169 -0
- package/src/core/check.ts +38 -0
- package/src/{hooks/permission-gate/dangerous-commands.test.ts → core/commands/dangerous.test.ts} +134 -2
- package/src/{hooks/permission-gate/dangerous-commands.ts → core/commands/dangerous.ts} +119 -1
- package/src/core/commands/index.ts +15 -0
- package/src/core/index.ts +13 -0
- package/src/{utils/path-access.test.ts → core/paths/access.test.ts} +1 -5
- package/src/core/paths/index.ts +14 -0
- package/src/{utils → core/shell}/command-args.test.ts +31 -20
- package/src/core/shell/index.ts +2 -0
- package/src/core/types.ts +55 -0
- package/src/shared/config/defaults.ts +118 -0
- package/src/shared/config/index.ts +17 -0
- package/src/shared/config/loader.ts +64 -0
- package/src/shared/config/migration/001-v0-format-upgrade.ts +107 -0
- package/src/shared/config/migration/002-strip-toolchain-fields.ts +39 -0
- package/src/shared/config/migration/003-strip-command-explainer-fields.ts +42 -0
- package/src/shared/config/migration/004-env-files-to-policies.ts +87 -0
- package/src/shared/config/migration/005-normalize-allowed-paths.ts +43 -0
- package/src/shared/config/migration/006-apply-builtin-defaults.ts +19 -0
- package/src/shared/config/migration/007-mark-onboarding-done.ts +25 -0
- package/src/shared/config/migration/index.ts +44 -0
- package/src/shared/config/migration/version.ts +7 -0
- package/src/shared/config/types.ts +141 -0
- package/src/shared/events.ts +100 -0
- package/src/shared/index.ts +6 -0
- package/src/shared/matching.test.ts +86 -0
- package/src/{utils → shared}/matching.ts +4 -4
- package/src/{utils → shared/paths}/bash-paths.test.ts +11 -2
- package/src/{utils → shared/paths}/bash-paths.ts +4 -4
- package/src/shared/paths/index.ts +1 -0
- package/src/shared/warnings.ts +17 -0
- package/docs/defaults.md +0 -140
- package/docs/examples.md +0 -170
- package/src/commands/onboarding.ts +0 -390
- package/src/commands/settings-command.ts +0 -1616
- package/src/config.ts +0 -392
- package/src/hooks/index.ts +0 -11
- package/src/hooks/path-access.ts +0 -395
- package/src/hooks/permission-gate/index.test.ts +0 -332
- package/src/hooks/permission-gate/index.ts +0 -595
- package/src/hooks/policies.ts +0 -322
- package/src/index.ts +0 -96
- package/src/lib/executor.ts +0 -280
- package/src/lib/index.ts +0 -16
- package/src/lib/model-resolver.ts +0 -47
- package/src/lib/timing.ts +0 -42
- package/src/lib/types.ts +0 -115
- package/src/utils/events.ts +0 -32
- package/src/utils/migration.test.ts +0 -58
- package/src/utils/migration.ts +0 -340
- package/src/utils/warnings.ts +0 -7
- /package/src/{utils/path-access.ts → core/paths/access.ts} +0 -0
- /package/src/{utils → core/paths}/path.test.ts +0 -0
- /package/src/{utils → core/paths}/path.ts +0 -0
- /package/src/{utils/shell-utils.ts → core/shell/ast.ts} +0 -0
- /package/src/{utils → core/shell}/command-args.ts +0 -0
- /package/src/{utils/glob-expander.ts → shared/glob.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
# Guardrails
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Guardrails adds safety checks to Pi so agents are less likely to read secrets, write protected files, access paths outside the workspace, or run dangerous shell commands by accident.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This package installs three Pi extensions:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **guardrails** for file protection policies, settings, onboarding, and examples.
|
|
10
|
+
- **path-access** for controlling access outside the current workspace.
|
|
11
|
+
- **permission-gate** for confirming or blocking risky shell commands.
|
|
10
12
|
|
|
11
13
|
## Install
|
|
12
14
|
|
|
@@ -14,185 +16,112 @@ Security hooks for Pi to reduce accidental destructive actions and secret-file a
|
|
|
14
16
|
pi install npm:@aliou/pi-guardrails
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
## First run
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
After installing, run the onboarding command to choose a starting setup:
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
/guardrails:onboarding
|
|
21
25
|
```
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+

|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
- [Example presets](docs/examples.md) — pre-configured presets available in settings
|
|
29
|
+
You can change everything later with:
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
```text
|
|
32
|
+
/guardrails:settings
|
|
33
|
+
```
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
- **permission-gate**: detects dangerous bash commands and asks for confirmation.
|
|
32
|
-
- **path-access**: restricts tool access to the current working directory with allow/ask/block modes.
|
|
33
|
-
- **optional command explainer**: can call a small LLM to explain a dangerous command inline in the confirmation dialog.
|
|
35
|
+
## Included extensions
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
### guardrails
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
The `guardrails` extension owns file protection policies and the user-facing commands.
|
|
38
40
|
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Priority: `memory > local > global > defaults`.
|
|
44
|
-
|
|
45
|
-
Use `/guardrails:settings` to edit config interactively.
|
|
46
|
-
|
|
47
|
-
## Current schema
|
|
48
|
-
|
|
49
|
-
```json
|
|
50
|
-
{
|
|
51
|
-
"enabled": true,
|
|
52
|
-
"features": {
|
|
53
|
-
"policies": true,
|
|
54
|
-
"permissionGate": true,
|
|
55
|
-
"pathAccess": false
|
|
56
|
-
},
|
|
57
|
-
"pathAccess": {
|
|
58
|
-
"mode": "ask",
|
|
59
|
-
"allowedPaths": []
|
|
60
|
-
},
|
|
61
|
-
"policies": {
|
|
62
|
-
"rules": [
|
|
63
|
-
{
|
|
64
|
-
"id": "secret-files",
|
|
65
|
-
"description": "Files containing secrets",
|
|
66
|
-
"patterns": [
|
|
67
|
-
{ "pattern": ".env" },
|
|
68
|
-
{ "pattern": ".env.local" },
|
|
69
|
-
{ "pattern": ".env.production" },
|
|
70
|
-
{ "pattern": ".env.prod" },
|
|
71
|
-
{ "pattern": ".dev.vars" }
|
|
72
|
-
],
|
|
73
|
-
"allowedPatterns": [
|
|
74
|
-
{ "pattern": ".env.example" },
|
|
75
|
-
{ "pattern": ".env.sample" },
|
|
76
|
-
{ "pattern": ".env.test" },
|
|
77
|
-
{ "pattern": "*.example.env" },
|
|
78
|
-
{ "pattern": "*.sample.env" },
|
|
79
|
-
{ "pattern": "*.test.env" }
|
|
80
|
-
],
|
|
81
|
-
"protection": "noAccess",
|
|
82
|
-
"onlyIfExists": true
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
},
|
|
86
|
-
"permissionGate": {
|
|
87
|
-
"patterns": [
|
|
88
|
-
{ "pattern": "rm -rf", "description": "recursive force delete" },
|
|
89
|
-
{ "pattern": "sudo", "description": "superuser command" }
|
|
90
|
-
],
|
|
91
|
-
"customPatterns": [],
|
|
92
|
-
"requireConfirmation": true,
|
|
93
|
-
"allowedPatterns": [],
|
|
94
|
-
"autoDenyPatterns": [],
|
|
95
|
-
"explainCommands": false,
|
|
96
|
-
"explainModel": null,
|
|
97
|
-
"explainTimeout": 5000
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
```
|
|
41
|
+
Use it to protect files like `.env`, private keys, local credentials, generated logs, database dumps, or any project-specific path you do not want Pi to read or modify without clear intent.
|
|
42
|
+
|
|
43
|
+

|
|
101
44
|
|
|
102
|
-
|
|
45
|
+
Useful commands:
|
|
103
46
|
|
|
104
|
-
|
|
47
|
+
```text
|
|
48
|
+
/guardrails:settings
|
|
49
|
+
/guardrails:onboarding
|
|
50
|
+
/guardrails:examples
|
|
51
|
+
```
|
|
105
52
|
|
|
106
|
-
|
|
53
|
+
### path-access
|
|
107
54
|
|
|
108
|
-
|
|
109
|
-
- `patterns`: files to match (glob by default, regex if `regex: true`). Glob semantics: patterns containing `/` match the full relative path; patterns without `/` match basename only.
|
|
110
|
-
- `allowedPatterns`: exceptions.
|
|
111
|
-
- `protection`:
|
|
112
|
-
- `noAccess`: block `read`, `write`, `edit`, `bash`, `grep`, `find`, `ls`
|
|
113
|
-
- `readOnly`: block `write`, `edit`, `bash`
|
|
114
|
-
- `none`: explicit no protection
|
|
115
|
-
- `onlyIfExists` (default true)
|
|
116
|
-
- `blockMessage` with `{file}` placeholder
|
|
117
|
-
- `enabled` (default true)
|
|
55
|
+
The `path-access` extension checks tool calls that target paths outside the current working directory.
|
|
118
56
|
|
|
119
|
-
|
|
120
|
-
`noAccess > readOnly > none`.
|
|
57
|
+
It can allow, block, or ask before Pi accesses files elsewhere on your machine. In ask mode, you can allow one file or a directory once, for the session, or always.
|
|
121
58
|
|
|
122
|
-
|
|
59
|
+

|
|
123
60
|
|
|
124
|
-
|
|
61
|
+
### permission-gate
|
|
125
62
|
|
|
126
|
-
|
|
127
|
-
/guardrails:add-policy
|
|
128
|
-
```
|
|
63
|
+
The `permission-gate` extension detects dangerous bash commands before they run.
|
|
129
64
|
|
|
130
|
-
|
|
65
|
+
It catches built-in risky patterns like recursive deletes, privileged commands, disk formatting, broad permission changes, and configured custom patterns. You can allow once, allow for the session, deny, or configure auto-deny rules.
|
|
131
66
|
|
|
132
|
-
|
|
67
|
+

|
|
133
68
|
|
|
134
|
-
|
|
69
|
+
## Configuration
|
|
135
70
|
|
|
136
|
-
|
|
137
|
-
- **ask**: prompt with options to grant access (file or directory, for session or always)
|
|
138
|
-
- **block**: deny all outside access
|
|
71
|
+
Most configuration should happen through the interactive settings UI:
|
|
139
72
|
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
"features": { "pathAccess": true },
|
|
143
|
-
"pathAccess": {
|
|
144
|
-
"mode": "ask",
|
|
145
|
-
"allowedPaths": ["~/code/shared-libs/", "~/.config/myapp"]
|
|
146
|
-
}
|
|
147
|
-
}
|
|
73
|
+
```text
|
|
74
|
+
/guardrails:settings
|
|
148
75
|
```
|
|
149
76
|
|
|
150
|
-
|
|
77
|
+
Advanced users can edit the settings file directly:
|
|
151
78
|
|
|
152
|
-
|
|
153
|
-
-
|
|
154
|
-
- Bash path extraction is best-effort (AST-based heuristics).
|
|
155
|
-
- In non-interactive mode, `ask` mode degrades to `block`.
|
|
79
|
+
- Global: `~/.pi/agent/extensions/guardrails.json`
|
|
80
|
+
- Project: `.pi/extensions/guardrails.json`
|
|
156
81
|
|
|
157
|
-
|
|
82
|
+
Guardrails writes a `$schema` field to saved settings files, so modern editors provide autocomplete and validation. The generated schema is committed at [`schema.json`](schema.json).
|
|
158
83
|
|
|
159
|
-
|
|
84
|
+
## Examples
|
|
160
85
|
|
|
161
|
-
|
|
86
|
+
Use the examples command to add common policy and command presets without replacing your existing config:
|
|
162
87
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
- `mkfs.`
|
|
167
|
-
- `chmod -R 777`
|
|
168
|
-
- `chown -R`
|
|
88
|
+
```text
|
|
89
|
+
/guardrails:examples
|
|
90
|
+
```
|
|
169
91
|
|
|
170
|
-
|
|
92
|
+

|
|
171
93
|
|
|
172
|
-
|
|
94
|
+
The available presets live in [`extensions/guardrails/commands/settings/examples.ts`](extensions/guardrails/commands/settings/examples.ts).
|
|
173
95
|
|
|
174
|
-
|
|
96
|
+
## Similar but different
|
|
175
97
|
|
|
176
|
-
|
|
98
|
+
Pi is designed to make agent safety extensible. Guardrails focuses on deterministic, configurable file policies, outside-workspace path access, and dangerous-command prompts. Other packages tend to fall into two useful groups.
|
|
177
99
|
|
|
178
|
-
|
|
179
|
-
- `permissionGate.explainModel` (`provider/model-id`)
|
|
180
|
-
- `permissionGate.explainTimeout` (ms)
|
|
100
|
+
### Make one yourself!
|
|
181
101
|
|
|
182
|
-
|
|
102
|
+
If Guardrails or the alternatives below do not fit your needs, you can also make your own. Start from the [Pi permission gate example](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/examples/extensions/permission-gate.ts), then ask Pi to customize it for your workflow.
|
|
183
103
|
|
|
184
|
-
|
|
104
|
+
### Permission and policy gates
|
|
185
105
|
|
|
186
|
-
|
|
106
|
+
These packages add checks around tool calls before they run. They are closest to Guardrails when you want policy enforcement without changing where Pi executes.
|
|
187
107
|
|
|
188
|
-
-
|
|
189
|
-
-
|
|
108
|
+
- [@gotgenes/pi-permission-system](https://pi.dev/packages/%40gotgenes/pi-permission-system): broad permission enforcement for Pi tool calls.
|
|
109
|
+
- [@vtstech/pi-security](https://pi.dev/packages/%40vtstech/pi-security): command, path, network, mode, and audit controls.
|
|
110
|
+
- [pi-control](https://github.com/mcowger/pi-control/blob/main/README.md): location-scoped, action-based policies for tool calls, with allow, log, ask, and deny outcomes before execution.
|
|
111
|
+
- [@casualjim/pi-heimdall](https://pi.dev/packages/%40casualjim/pi-heimdall): secret exposure guards, command policies, protected `.env` files, and a sandbox guard.
|
|
112
|
+
- [pi-file-permissions](https://pi.dev/packages/pi-file-permissions): file-level permissions for read, write, edit, find, grep, and ls tools.
|
|
113
|
+
- [pi-secret-guard](https://pi.dev/packages/pi-secret-guard): focused protection against committing or pushing secrets to git.
|
|
190
114
|
|
|
191
|
-
|
|
115
|
+
### Sandboxes and containment
|
|
192
116
|
|
|
193
|
-
|
|
117
|
+
These packages reduce blast radius by running Pi, subagents, or tool calls inside a constrained environment. They can be a better fit when you want isolation first and prompts second.
|
|
194
118
|
|
|
195
|
-
-
|
|
119
|
+
- [Pi + Gondolin sandbox example](https://github.com/earendil-works/gondolin/blob/main/host/examples/pi-gondolin.ts): upstream example that runs Pi tools inside a Gondolin micro-VM.
|
|
120
|
+
- [pi-sandbox](https://pi.dev/packages/pi-sandbox): OS-level sandboxing for bash, with allow/deny checks and prompts for file tools.
|
|
121
|
+
- [pi-container-sandbox](https://pi.dev/packages/pi-container-sandbox): runs read, write, edit, bash, and user bash operations inside a Docker or Apple container session.
|
|
122
|
+
- [@alexanderfortin/pi-freestyle-sandbox](https://pi.dev/packages/%40alexanderfortin/pi-freestyle-sandbox): runs sandboxed subagents in Freestyle cloud VMs.
|
|
123
|
+
- [@the-agency/vmpi](https://pi.dev/packages/%40the-agency/vmpi): runs Pi inside a QEMU microVM with limited filesystem and network access.
|
|
124
|
+
- [pi-claude-sandbox](https://pi.dev/packages/pi-claude-sandbox): Claude-style OS sandboxing with interactive permission prompts.
|
|
196
125
|
|
|
197
126
|
## Development
|
|
198
127
|
|
|
@@ -202,30 +131,6 @@ pnpm test:watch # Run tests in watch mode
|
|
|
202
131
|
pnpm typecheck # Type check
|
|
203
132
|
pnpm lint # Lint
|
|
204
133
|
pnpm format # Format
|
|
134
|
+
pnpm gen:schema # Regenerate schema.json
|
|
135
|
+
pnpm check:schema # Verify schema.json is current
|
|
205
136
|
```
|
|
206
|
-
|
|
207
|
-
## Events
|
|
208
|
-
|
|
209
|
-
Guardrails emits events for other extensions:
|
|
210
|
-
|
|
211
|
-
### `guardrails:blocked`
|
|
212
|
-
|
|
213
|
-
```ts
|
|
214
|
-
interface GuardrailsBlockedEvent {
|
|
215
|
-
feature: "policies" | "permissionGate" | "pathAccess";
|
|
216
|
-
toolName: string;
|
|
217
|
-
input: Record<string, unknown>;
|
|
218
|
-
reason: string;
|
|
219
|
-
userDenied?: boolean;
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
### `guardrails:dangerous`
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
interface GuardrailsDangerousEvent {
|
|
227
|
-
command: string;
|
|
228
|
-
description: string;
|
|
229
|
-
pattern: string;
|
|
230
|
-
}
|
|
231
|
-
```
|