@grwnd/pi-governance 1.5.1 → 1.7.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 +28 -256
- package/dist/extensions/index.cjs +1713 -38
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.js +1707 -35
- package/dist/extensions/index.js.map +1 -1
- package/dist/index.cjs +1613 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +1611 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h1 align="center">@grwnd/pi-governance</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
Governance, RBAC,
|
|
8
|
+
Governance, RBAC, DLP, and audit for Pi coding agents.
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
@@ -18,287 +18,59 @@
|
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## The Problem
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
AI coding agents have full access to your terminal, filesystem, and secrets. Without governance, an agent can run `rm -rf`, read `.env` files, or exfiltrate API keys through tool calls — with no audit trail.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
- **Bash command classification** — auto-block dangerous commands (`rm -rf`, `sudo`, `curl | sh`)
|
|
27
|
-
- **Path-level file gating** — restrict read/write to scoped directories
|
|
28
|
-
- **Data loss prevention** — detect and block/mask API keys, tokens, and PII before they reach the LLM
|
|
29
|
-
- **Human-in-the-loop approval** — require sign-off for sensitive operations
|
|
30
|
-
- **Audit logging** — structured JSONL logs of every governance decision
|
|
31
|
-
- **Prompt-level policy** — role-scoped system prompt templates
|
|
25
|
+
## The Solution
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
## Quick Start
|
|
36
|
-
|
|
37
|
-
### Install
|
|
27
|
+
`pi-governance` intercepts every tool call and enforces policy before execution.
|
|
38
28
|
|
|
39
29
|
```bash
|
|
40
30
|
pi install npm:@grwnd/pi-governance
|
|
41
31
|
```
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- All tools allowed
|
|
46
|
-
- Dangerous bash commands blocked
|
|
47
|
-
- Supervised mode (approval required for writes and bash)
|
|
48
|
-
- DLP disabled (opt-in)
|
|
49
|
-
- Audit logged to `~/.pi/agent/audit.jsonl`
|
|
50
|
-
|
|
51
|
-
### Configure
|
|
33
|
+
**What you get immediately:**
|
|
52
34
|
|
|
53
|
-
|
|
35
|
+
- **Bash blocking** — 60+ patterns classify commands as safe/dangerous/needs-review
|
|
36
|
+
- **DLP** — API keys blocked on input, PII masked on output
|
|
37
|
+
- **RBAC** — Role-based tool and path permissions
|
|
38
|
+
- **Audit** — Every decision logged as structured JSON
|
|
39
|
+
- **HITL** — Human approval for sensitive operations
|
|
40
|
+
- **Budgets** — Per-role tool invocation limits
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
auth:
|
|
57
|
-
provider: env
|
|
42
|
+
## Customize
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
engine: yaml
|
|
61
|
-
yaml:
|
|
62
|
-
rules_file: ./governance-rules.yaml
|
|
44
|
+
### Interactive wizard
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
timeout_seconds: 300
|
|
67
|
-
|
|
68
|
-
audit:
|
|
69
|
-
sinks:
|
|
70
|
-
- type: jsonl
|
|
71
|
-
path: ~/.pi/agent/audit.jsonl
|
|
46
|
+
```
|
|
47
|
+
/governance init
|
|
72
48
|
```
|
|
73
49
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Create `governance-rules.yaml`:
|
|
77
|
-
|
|
78
|
-
```yaml
|
|
79
|
-
roles:
|
|
80
|
-
analyst:
|
|
81
|
-
allowed_tools: [read]
|
|
82
|
-
blocked_tools: [write, edit, bash]
|
|
83
|
-
execution_mode: supervised
|
|
84
|
-
human_approval:
|
|
85
|
-
required_for: [all]
|
|
86
|
-
allowed_paths:
|
|
87
|
-
- '{{project_path}}/**'
|
|
88
|
-
blocked_paths:
|
|
89
|
-
- '**/secrets/**'
|
|
90
|
-
- '**/.env*'
|
|
91
|
-
|
|
92
|
-
project_lead:
|
|
93
|
-
allowed_tools: [read, write, edit, bash]
|
|
94
|
-
blocked_tools: []
|
|
95
|
-
execution_mode: supervised
|
|
96
|
-
human_approval:
|
|
97
|
-
required_for: [bash, write]
|
|
98
|
-
auto_approve: [read, edit]
|
|
99
|
-
allowed_paths:
|
|
100
|
-
- '{{project_path}}/**'
|
|
101
|
-
blocked_paths:
|
|
102
|
-
- '**/secrets/**'
|
|
50
|
+
Opens a browser-based wizard to configure roles, DLP, audit, and HITL. Generates YAML config files.
|
|
103
51
|
|
|
104
|
-
|
|
105
|
-
allowed_tools: [all]
|
|
106
|
-
blocked_tools: []
|
|
107
|
-
execution_mode: autonomous
|
|
108
|
-
human_approval:
|
|
109
|
-
required_for: []
|
|
110
|
-
allowed_paths: ['**']
|
|
111
|
-
blocked_paths: []
|
|
112
|
-
```
|
|
52
|
+
### Manual YAML
|
|
113
53
|
|
|
114
|
-
|
|
54
|
+
Create `.pi/governance.yaml` and `governance-rules.yaml` — see the [Configuration Reference](https://grwnd-ai.github.io/pi-governance/reference/config).
|
|
115
55
|
|
|
116
|
-
Set
|
|
56
|
+
### Set identity
|
|
117
57
|
|
|
118
58
|
```bash
|
|
119
|
-
export
|
|
120
|
-
export GRWND_ROLE=project_lead
|
|
121
|
-
export GRWND_ORG_UNIT=cornerstone_aec
|
|
122
|
-
|
|
59
|
+
export GRWND_ROLE=project_lead # analyst | project_lead | admin | auditor
|
|
123
60
|
pi
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Or use a local users file for team setups — see the [docs](https://grwnd-ai.github.io/pi-governance/).
|
|
127
|
-
|
|
128
|
-
### Check Status
|
|
129
|
-
|
|
130
|
-
Inside a governed Pi session:
|
|
131
|
-
|
|
132
|
-
```
|
|
133
61
|
/governance status
|
|
134
62
|
```
|
|
135
63
|
|
|
136
|
-
```
|
|
137
|
-
Governance active
|
|
138
|
-
User: alice
|
|
139
|
-
Role: project_lead
|
|
140
|
-
Org Unit: cornerstone_aec
|
|
141
|
-
Engine: yaml
|
|
142
|
-
Mode: supervised
|
|
143
|
-
Session: 3 tool calls, 0 denials
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Architecture
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
User message → Pi Agent Runtime
|
|
150
|
-
│
|
|
151
|
-
┌─────┴──────┐
|
|
152
|
-
│ onSessionStart │ ← Identity resolution
|
|
153
|
-
│ → load policy │ ← Select prompt template
|
|
154
|
-
└─────┬──────┘
|
|
155
|
-
│
|
|
156
|
-
┌─────┴──────────┐
|
|
157
|
-
│ onBeforeToolCall │ ← RBAC: tool allowed?
|
|
158
|
-
│ → classify bash │ ← Path check
|
|
159
|
-
│ → DLP scan │ ← Block/mask secrets & PII
|
|
160
|
-
│ → HITL approval │ ← Audit log
|
|
161
|
-
└─────┬──────────┘
|
|
162
|
-
│
|
|
163
|
-
allow │ deny
|
|
164
|
-
│ └→ Return denial message
|
|
165
|
-
│
|
|
166
|
-
┌─────┴──────────┐
|
|
167
|
-
│ onAfterToolCall │ ← DLP scan output
|
|
168
|
-
│ │ ← Audit result
|
|
169
|
-
└────────────────┘
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
## Data Loss Prevention
|
|
173
|
-
|
|
174
|
-
DLP prevents secrets and PII from leaking through tool calls to LLM providers. It scans both inputs (before execution) and outputs (before reaching the LLM).
|
|
175
|
-
|
|
176
|
-
```yaml
|
|
177
|
-
dlp:
|
|
178
|
-
enabled: true
|
|
179
|
-
mode: mask # audit | mask | block
|
|
180
|
-
on_input: block # block tool calls with secrets
|
|
181
|
-
on_output: mask # redact secrets in tool output
|
|
182
|
-
masking:
|
|
183
|
-
strategy: partial # partial | full | hash
|
|
184
|
-
show_chars: 4
|
|
185
|
-
severity_threshold: low
|
|
186
|
-
built_in:
|
|
187
|
-
secrets: true # AWS keys, GitHub PATs, JWTs, Stripe keys, ...
|
|
188
|
-
pii: true # SSN, credit cards, email, phone, IP
|
|
189
|
-
custom_patterns:
|
|
190
|
-
- name: internal_key
|
|
191
|
-
pattern: 'grwnd_[a-zA-Z0-9]{32}'
|
|
192
|
-
severity: critical
|
|
193
|
-
action: block
|
|
194
|
-
allowlist:
|
|
195
|
-
- pattern: '127\.0\.0\.1'
|
|
196
|
-
role_overrides:
|
|
197
|
-
admin:
|
|
198
|
-
enabled: false # admin skips DLP
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
DLP is **disabled by default** — zero behavioral change for existing users. See the full [DLP guide](https://grwnd-ai.github.io/pi-governance/guide/dlp) and [pattern reference](https://grwnd-ai.github.io/pi-governance/reference/dlp-patterns).
|
|
202
|
-
|
|
203
|
-
## Dual Policy Engine
|
|
204
|
-
|
|
205
|
-
Choose between two policy engines:
|
|
206
|
-
|
|
207
|
-
| Engine | Best for | Dependency |
|
|
208
|
-
| ------------------ | ---------------------------------------------- | ---------------- |
|
|
209
|
-
| **YAML** (default) | Simple setups, quick start | Zero — built-in |
|
|
210
|
-
| **Oso/Polar** | Complex RBAC, relational policies, inheritance | `oso` (optional) |
|
|
211
|
-
|
|
212
|
-
Switch engines in config:
|
|
213
|
-
|
|
214
|
-
```yaml
|
|
215
|
-
policy:
|
|
216
|
-
engine: oso
|
|
217
|
-
oso:
|
|
218
|
-
polar_files:
|
|
219
|
-
- ./policies/base.polar
|
|
220
|
-
- ./policies/tools.polar
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## OpenClaw
|
|
224
|
-
|
|
225
|
-
pi-governance works with [OpenClaw](https://github.com/Grwnd-AI) out of the box. OpenClaw runs on Pi, so installing pi-governance as a Pi extension automatically governs every tool call your OpenClaw agent makes — including MCP tools.
|
|
226
|
-
|
|
227
|
-
```
|
|
228
|
-
OpenClaw gateway (WhatsApp, Discord, Telegram, …)
|
|
229
|
-
└─ [optional] @grwnd/openclaw-governance plugin → channel identity
|
|
230
|
-
└─ Pi embedded runner
|
|
231
|
-
└─ @grwnd/pi-governance extension
|
|
232
|
-
├─ RBAC for MCP tools (create_report, upload_asset, …)
|
|
233
|
-
├─ bash command classification
|
|
234
|
-
├─ audit logging (JSONL + webhook)
|
|
235
|
-
└─ HITL approval flow
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Get up and running
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
# 1. Install the Pi governance extension
|
|
242
|
-
pi install npm:@grwnd/pi-governance
|
|
243
|
-
|
|
244
|
-
# 2. Install the OpenClaw identity bridge plugin
|
|
245
|
-
openclaw plugins install @grwnd/openclaw-governance
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
Create `openclaw-users.yaml` to map channel users to governance roles:
|
|
249
|
-
|
|
250
|
-
```yaml
|
|
251
|
-
users:
|
|
252
|
-
whatsapp:+15550123:
|
|
253
|
-
role: report_author
|
|
254
|
-
org_unit: field-ops
|
|
255
|
-
discord:428374928374:
|
|
256
|
-
role: analyst
|
|
257
|
-
slack:U04ABCD1234:
|
|
258
|
-
role: project_lead
|
|
259
|
-
org_unit: engineering
|
|
260
|
-
default:
|
|
261
|
-
role: analyst
|
|
262
|
-
org_unit: default
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
Put MCP tool names directly in your policy rules:
|
|
266
|
-
|
|
267
|
-
```yaml
|
|
268
|
-
# governance-rules.yaml
|
|
269
|
-
roles:
|
|
270
|
-
report_author:
|
|
271
|
-
allowed_tools:
|
|
272
|
-
- list_reports
|
|
273
|
-
- get_report
|
|
274
|
-
- create_report
|
|
275
|
-
- search_documents
|
|
276
|
-
- chat_with_report
|
|
277
|
-
- read
|
|
278
|
-
- grep
|
|
279
|
-
blocked_tools: [bash, write, edit, delete_template]
|
|
280
|
-
execution_mode: supervised
|
|
281
|
-
human_approval:
|
|
282
|
-
required_for: [create_report, upload_asset]
|
|
283
|
-
auto_approve: [list_reports, get_report, search_documents]
|
|
284
|
-
token_budget_daily: 500
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
When a WhatsApp user messages your OpenClaw agent, the identity bridge parses the session key, maps them to a role, and pi-governance enforces the policy — all automatically. Every MCP tool call is audited as structured JSON.
|
|
288
|
-
|
|
289
|
-
See the full [OpenClaw integration guide](https://grwnd-ai.github.io/pi-governance/guide/openclaw) for MCP tool reference tables, channel identity mapping, and common patterns.
|
|
290
|
-
|
|
291
64
|
## Documentation
|
|
292
65
|
|
|
293
|
-
Full
|
|
66
|
+
Full docs at **[grwnd-ai.github.io/pi-governance](https://grwnd-ai.github.io/pi-governance/)**.
|
|
294
67
|
|
|
295
|
-
- [
|
|
296
|
-
- [
|
|
297
|
-
- [
|
|
298
|
-
- [YAML Policies](https://grwnd-ai.github.io/pi-governance/guide/yaml-policies)
|
|
299
|
-
- [
|
|
300
|
-
- [
|
|
301
|
-
- [Configuration Reference](https://grwnd-ai.github.io/pi-governance/reference/config)
|
|
68
|
+
- [Why Governance?](https://grwnd-ai.github.io/pi-governance/guide/why) — What can go wrong without controls
|
|
69
|
+
- [Quick Start](https://grwnd-ai.github.io/pi-governance/guide/quickstart) — Install and configure
|
|
70
|
+
- [Common Scenarios](https://grwnd-ai.github.io/pi-governance/guide/scenarios) — Copy-paste configs
|
|
71
|
+
- [YAML Policies](https://grwnd-ai.github.io/pi-governance/guide/yaml-policies) — Full policy reference
|
|
72
|
+
- [DLP Guide](https://grwnd-ai.github.io/pi-governance/guide/dlp) — Data loss prevention
|
|
73
|
+
- [OpenClaw Integration](https://grwnd-ai.github.io/pi-governance/guide/openclaw) — MCP tool governance
|
|
302
74
|
|
|
303
75
|
## License
|
|
304
76
|
|