agent-cache-guard-mcp
by paul1064
README.md
# agent-cache-guard
**Zero-proxy LLM FinOps prompt-cache linter, session-distilled least-privilege allowlist generator, SHA-256 `READ_ONLY_LOCKDOWN` audit chain, context/ZIP leak scanner, and interactive MCP App.**
Silent prompt-cache invalidation (timestamps in `CLAUDE.md`/`GEMINI.md`, shuffled JSON tool keys, `1h` TTL after `5m`, Bedrock top-level `cache_control`, or `>20`-block lookback gaps) inflates LLM input bills **2× to 10×**. Meanwhile, wildcard `.claude/settings.json` rules and uninspected `.zip`/context exports expose agent sandboxes to prompt injection and credential leaks.
`agent-cache-guard` solves both locally and in CI with **zero npm dependencies** (Node.js ≥ 20 standard library only) and **zero traffic proxying**.
---
## Quickstart
### 1. Install as Agent Skills (`skills.sh` compatible)
Works across **Claude Code, Antigravity, Cursor, Codex, and Windsurf**:
```bash
npx skills add paul1064/agent-cache-guard
```
Included skills under [`skills/`](./skills):
- **`prompt-cache-check`** — Lints Claude 5/5.5/Fable/Mythos, Bedrock & Gemini payloads, diffs consecutive turns (`tools` → `system` → `messages`), scans `GEMINI.md`/`AGENTS.md`/`CLAUDE.md`/`SKILL.md` for volatile prefixes, and computes realized `usage` hit rates & savings.
- **`permission-allowlist`** — Distills strictly read-only `.claude/settings.json` allowlists from JSONL session transcripts and rejects wildcard mutations or shell chaining.
- **`sandbox-self-heal`** — Audits `environment.yaml` `allowed_hosts`, blocks token-in-URL leaks, checks RAM headroom, and cleans orphaned `.ck.tmp` / `.check.patch` artifacts.
- **`lockdown-audit-chain`** — O(1) SHA-256 tamper-evident audit ledger, constant-time token check, shell-segment classifier, and `READ_ONLY_LOCKDOWN` circuit breaker.
- **`unified-memory-sync`** — Pure-Node `.zip` Central-Directory & `.html` scanner catching API keys, Luhn payment cards, IBANs, local paths, and EN/DE prompt-injection directives, plus deterministic dated fact conflict resolution.
### 2. Run the Unified CLI
```bash
# Run full 0-100 FinOps & Security scorecard on any repository
node ./bin/agent-cache-guard.mjs audit-all .
# Lint a Messages API payload & compute ROI from usage logs
node ./bin/agent-cache-guard.mjs cache request skills/prompt-cache-check/examples/request-good.json
node ./bin/agent-cache-guard.mjs cache usage skills/prompt-cache-check/examples/usage.jsonl --model claude-opus-5-5 --min-hit 0.7
# Distill a safe read-only .claude/settings.json from session transcripts
node ./bin/agent-cache-guard.mjs allowlist generate skills/permission-allowlist/examples/sample-transcript.jsonl
# Test a shell command against emergency READ_ONLY_LOCKDOWN
node ./bin/agent-cache-guard.mjs lockdown check-cmd "git status && rm -rf /" --lockdown
```
### 3. Add as a GitHub Action PR Gate
```yaml
- name: Agent Cache & Security Guard
uses: paul1064/agent-cache-guard@v1
with:
target-dir: "."
usage-file: "./logs/usage.jsonl"
model: "claude-sonnet-5-5"
min-hit-rate: "0.75"
```
### 4. Connect the MCP Server & Interactive Waterfall UI (`@modelcontextprotocol/ext-apps`)
`agent-cache-guard-mcp` runs over stdio and serves `ui://agent-cache-guard/waterfall.html` (`text/html;profile=mcp-app`)—rendering an interactive **Prefix Cache Waterfall (`tools` → `system` → `messages`)**, **Monthly LLM FinOps ROI Estimator**, and **`READ_ONLY_LOCKDOWN` Command Simulator** directly inside Antigravity, Claude Desktop, VS Code Copilot, and Goose.
```json
{
"mcpServers": {
"agent-cache-guard": {
"command": "node",
"args": ["./src/mcp-server.mjs"]
}
}
}
```
| MCP Tool | Purpose |
|---|---|
| `acg_cache_audit` | Lints/diffs requests, audits rule files, calculates `usage` hit rates, and launches the interactive Waterfall & Savings MCP App (`aux_pane` + `global` entrypoints). |
| `acg_allowlist_audit` | Audits `.claude/settings.json` or generates read-only allowlists from transcript lines. |
| `acg_context_leak_scan` | Scans text, folders, `.html`, and `.zip` archives for credentials, Luhn cards, IBANs & prompt injections. |
| `acg_lockdown_guard` | Evaluates shell chains under `READ_ONLY_LOCKDOWN` and appends/verifies SHA-256 hash-chain audit entries. |
| `acg_sandbox_probe` | Probes sandbox `environment.yaml` / `vault.yaml` hygiene and cleans stale `.tmp` artifacts. |
---
## Architecture
```mermaid
flowchart LR
A["Rules & Payloads (CLAUDE.md / JSON / JSONL)"] --> B["Prompt-Cache-Check (pcc.mjs)"]
C["Session Transcripts & Settings"] --> D["Permission-Allowlist + Lockdown Chain"]
E["Context Folders & .zip Archives"] --> F["Unified-Memory-Sync + Sandbox Probe"]
B --> G["CLI / GitHub Action / MCP Server"]
D --> G
F --> G
G --> H["Interactive MCP App (ui://agent-cache-guard/waterfall.html)"]
```
---
## Pro Packs, Playbooks & B2B FinOps Audits
Need production org policy packs, multi-agent workflow playbooks, or a hands-on FinOps & security architecture review? Grab the official companions on Gumroad:
| Tier | What You Get | Price | Link |
|---|---|---|---|
| **Antigravity Duo** | *Antigravity für Einsteiger + Yodas* — step-by-step multi-agent setup, byte-identical prompt-cache hygiene & swarm workflows. | **€24** | [Get Antigravity Duo →](https://nobis23.gumroad.com) |
| **FinOps Pro Pack** | Multi-repo GitHub Action PR comment scorecards, Bedrock/Vertex org policy templates, 1h-vs-5m TTL calculators & strict MCP allowlist presets. | **€39** | [Get FinOps Pro →](https://nobis23.gumroad.com) |
| **1:1 B2B FinOps & Security Audit** | Hands-on prefix-cache architecture refactor (80–95% cached input target), least-privilege MCP lockdown, and cryptographic SHA-256 audit ledger integration. | **€990** | [Book B2B Audit →](https://nobis23.gumroad.com) |
Storefront & bundle catalog: **[https://nobis23.gumroad.com](https://nobis23.gumroad.com)** · Main Hub & 15 Kitchen Books: **[https://nobis23-werkstatt.netlify.app/](https://nobis23-werkstatt.netlify.app/)** ([`#buecher`](https://nobis23-werkstatt.netlify.app/#buecher) · [`#forge`](https://nobis23-werkstatt.netlify.app/#forge)) · Live Interactive Hub: **[THE WONDER ENGINE](https://wonder-engine.paul-live.workers.dev/)**
---
## Development & Verification
```bash
node --test
node ./bin/agent-cache-guard.mjs audit-all .
```
## License
MIT © [paul1064](https://github.com/paul1064)