agy-guard
README.md
<div align="center">
# agy-guard
**Local safety net for Google Antigravity — runtime destructive-action guard, automatic pre-write snapshots, and offline plugin security auditor.**
English | [简体中文](./README.zh-CN.md)
[](https://github.com/q18270781127-ai/agy-guard/actions/workflows/ci.yml)
[](https://github.com/q18270781127-ai/agy-guard/actions/workflows/codeql.yml)
[](./LICENSE)
</div>
---
## Why `agy-guard`?
Autonomous coding agents can accidentally wipe directories (`rm -rf`, `Remove-Item -Recurse`), run destructive Git resets, leak credentials, or load risky third-party plugins. `agy-guard` protects your workspace **100% locally** without touching host binaries or sending anything to the cloud:
1. **Runtime Guard (`PreToolUse`)** — Deterministically intercepts catastrophic commands (`deny`) and risky operations or sensitive/out-of-workspace writes (`force_ask`) across `sh`, `cmd`, and PowerShell.
2. **Pre-Write Snapshot & Restore** — Automatically captures deduplicated, quota-bounded snapshots before edits or deletions so you can diff and roll back in one CLI command.
3. **Offline Plugin & Config Audit** — Read-only static audit of Antigravity `plugin.json`, `hooks.json`, global & per-plugin `mcp_config.json`, `rules/*.md`, `skills/**/SKILL.md`, and hook scripts with A–F scoring.
> [!NOTE]
> **Security Commitments**: Zero runtime dependencies · Zero network calls · Zero subprocess spawning in `src/` & `dist/` · Unminified ESM bundles in `dist/` for direct inspection · Automated self-check test on every build.
---
## Quick Install
**Windows (PowerShell):**
```powershell
irm https://raw.githubusercontent.com/q18270781127-ai/agy-guard/main/install.ps1 | iex
```
**macOS / Linux:**
```bash
curl -fsSL https://raw.githubusercontent.com/q18270781127-ai/agy-guard/main/install.sh | sh
```
**From a local clone:**
```bash
git clone https://github.com/q18270781127-ai/agy-guard.git
cd agy-guard
node scripts/install.mjs install
```
Uninstall cleanly at any time:
```bash
node scripts/install.mjs uninstall
```
---
## Demo Walkthrough
```text
$ agy-guard check "rm -rf /"
DENY [G001]: [agy-guard][Rule G001] Catastrophic recursive delete targeting root, home, system, or workspace root ...
$ agy-guard snapshots
20261129T063015123Z_7 2026-11-29T06:30:15.123Z edit_file (1 file(s))
$ agy-guard diff 20261129T063015123Z_7
--- snapshot/src/app.ts
+++ workspace/src/app.ts
-export const port = 3000;
+export const port = 9999;
$ agy-guard restore 20261129T063015123Z_7 --yes
$ agy-guard audit
[A 100/100] agy-fast (...)
- Clean (0 findings)
```
---
## Guard Rules (`G001`–`G106`)
| Rule | Decision | Scope |
| :--- | :--- | :--- |
| `G001` | `deny` | Recursive delete (`rm -rf`, `Remove-Item -Recurse -Force`, `rd /s /q`, `del /s /q`) targeting `/`, `~`, drive root, OS critical dirs, workspace root, or `..` escape |
| `G002` | `deny` | Disk format or raw block-device writes (`mkfs`, `format`, `dd of=/dev/...`, `diskpart`) |
| `G003` | `deny` | Fork bomb patterns |
| `G101` | `force_ask` | Destructive Git commands (`git reset --hard`, `git clean -f`, `git push --force`, `git checkout -- .`, `git branch -D main`) |
| `G102` | `force_ask` | Download-to-shell pipes (`curl \| sh`, `wget \| bash`, `irm \| iex`, `Invoke-Expression`) |
| `G103` | `force_ask` | Accessing sensitive credential paths (`~/.ssh`, `.env`, `.aws/credentials`, `.npmrc`, `id_rsa*`, `.agents/hooks.json`) |
| `G104` | `force_ask` | Recursive permissive `chmod -R 777` / `a+rwx` |
| `G105` | `force_ask` | Recursive deletion scoped inside the workspace |
| `G106` | `force_ask` | File write/edit targeting sensitive files or outside workspace/artifact roots |
---
## Offline Audit Rules (`A001`–`A009`)
| Rule | Severity | What It Checks |
| :--- | :--- | :--- |
| `A001` | `critical` | Hook downloads and executes remote payloads |
| `A002` | `critical` | Obfuscated execution (`base64 -d \| sh`, `eval(atob`, `-EncodedCommand`, `FromBase64String`) |
| `A003` | `high` | Hook or MCP command references credential/SSH paths |
| `A004` | `medium` | Unpinned remote MCP URL or dynamic `@latest` runner (`npx -y` / `uvx`) |
| `A005` | `high` | Hardcoded API tokens (`ghp_`, `sk-`, `AKIA`, `AIza`, `xox...`) in configs |
| `A006` | `high` | Prompt-injection override phrases or hidden zero-width/bidi Unicode in `rules/` or `skills/` |
| `A007` | `high` | `PreToolUse` hook script unconditionally hardcoded to `"decision": "allow"` |
| `A008` | `medium` | Unaudited executable binary bundled inside a plugin directory |
| `A009` | `info` | Missing `LICENSE` or `repository` metadata |
Run `agy-guard audit --json`, `agy-guard audit --md`, or `agy-guard audit --fail-on high` in CI.
---
## Configuration
Precedence: `<workspace>/.agents/agy-guard.json` > `$PLUGIN_DATA/config.json` (fallback `~/.agy-guard/config.json`) > defaults.
```json
{
"mode": "enforce",
"passDecision": "ask",
"lang": "auto",
"allowRules": [],
"allowCommands": ["rm -rf dist/"],
"snapshot": {
"enabled": true,
"maxFileBytes": 5242880,
"maxSnapshotBytes": 52428800,
"maxTotalBytes": 1073741824,
"retentionDays": 7
}
}
```
- `mode`: `"enforce"` (default), `"ask-only"` (downgrades `deny` to `force_ask`), `"monitor"` (logs only), `"off"`.
- `passDecision`: `"ask"` (default — preserves Antigravity's native Always Allow prompt flow) or `"allow"`.
---
## MCP Tools
`agy-guard` exposes 4 read-only MCP tools (`restore` is intentionally CLI-only):
- `agy_guard_check`
- `agy_guard_audit`
- `agy_guard_snapshots`
- `agy_guard_diff`
---
## Security & Protocol Notes
- See [SECURITY.md](./SECURITY.md) for our threat model and fail-open rationale.
- See [docs/hook-protocol-notes.md](./docs/hook-protocol-notes.md) for verified Antigravity 2.0 `PreToolUse` measurements.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues