@yann-perrin/guard0.1.2
Security rules for Pi agent
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
Guard
Guard is a security extension for Pi that provides fine-grained control over the actions the agent can perform. It allows you to define security rules to whitelist or blacklist specific tool calls, such as bash commands or file operations (edit, write).
Features
- Tool Interception: Automatically monitors
bash,edit, andwritetool calls. - Dual-Layer Security:
- Global Rules: Apply to all projects (stored in
~/.pi/guard_rules.json). - Project-Local Rules: Apply only to the current project (stored in
.pi/guard_rules.json).
- Global Rules: Apply to all projects (stored in
- Interactive Approval: When an unlisted action is requested, Pi will prompt you to:
- Allow once.
- Block once (with an optional reason).
- Whitelist locally.
- Blacklist locally (with an optional reason).
- Wildcard Support: Use
*in your rules to match patterns (e.g.,bash:rm -rf *). - Rule Management: Use the built-in
/guardcommand to edit, delete, or move rules between local and global scopes.
How it Works
Guard creates a "rule key" for every intercepted tool call using the format:
toolName:sanitizedActionValue
- For
bash: TheactionValueis the command string (sanitized to remove newlines). - For
editandwrite: TheactionValueis the file path. - For other tools: The
actionValueis a JSON representation of the input.
Security Policy Logic
Guard follows a strict hierarchy to resolve rules and conflicts:
- Precedence of Scope: Local rules take precedence over Global rules. If a rule is found in your project's
.pi/guard_rules.json, the global configuration is not consulted. - Precedence of Action: Within a single configuration level (Local or Global), Whitelist rules take precedence over Blacklist rules. If an action matches both a whitelist pattern and a blacklist pattern, it will be allowed.
In summary, the decision process is:
Check Local Whitelist -> Check Local Blacklist -> Check Global Whitelist -> Check Global Blacklist -> Prompt for Approval.
Example Rules
| Tool | Action | Rule Key (for guard_rules.json) |
Description |
|---|---|---|---|
bash |
ls -la |
bash:ls -la |
Exact match for ls -la |
bash |
rm -rf /tmp/test |
bash:rm -rf /tmp/test* |
Matches any rm in /tmp/test |
write |
/etc/hosts |
write:/etc/hosts |
Protects a specific file |
edit |
src/main.ts |
edit:src/main.ts |
Whitelists editing a specific file |
Installation
Option 1: As a Pi Package (Recommended)
Since this repository is structured as a Pi package, you can install it directly using the Pi CLI.
Local installation:
pi install ./path/to/guard
Global installation (via npm):
pi install npm:@yann-perrin/guard
This method ensures that dependencies are handled correctly and the package is managed via Pi's internal settings.
Option 2: Single File (Quickest)
If you just want to run the script without managing it as a package, you can copy the guard.ts file directly into your extensions directory:
- Global:
~/.pi/agent/extensions/guard.ts - Local:
.pi/extensions/guard.ts
After installation, restart Pi or run /reload.
Usage
During a Session
When the agent attempts a protected action that isn't in your whitelist/blacklist, you will see a prompt:
Security: bash
The agent wants to: rm -rf /important/dir
?
> Allow Once
> Block Once
> Whitelist (Local)
> Blacklist (Local)
Managing Rules
Use the /guard command to manage your security policy:
/guard
This will open an interactive menu allowing you to:
- Select a list: Choose between Local/Global Whitelists/Blacklists.
- Edit a rule: Change the pattern (supporting
*wildcards). - Delete a rule: Remove a rule from the list.
- Toggle Local/Global: Move a rule from your project-local config to your global config, or vice versa.
License
Copyright (c) 2026 Yann Perrin
This project is licensed under the MIT License - see the LICENSE file for details.