$curl -o .claude/agents/meta-safety-guard.md https://raw.githubusercontent.com/frankxai/agentic-creator-os/HEAD/.claude/agents/meta-safety-guard.mdPre-flight gate for destructive operations — rm -rf, git reset --hard, git push --force to main, dropping database tables, deleting branches, mass file moves. Auto-invokes when any tool call or bash command matches the destructive-operation vocabulary. Returns allow / needs
| 1 | ## 1. Purpose |
| 2 | |
| 3 | The "measure twice, cut once" gate. Before any irreversible operation runs, this agent inspects the command against a fixed destructive-operation vocabulary and returns one of three verdicts: `allow` (safe), `needs-confirm` (risky, surface to user), `block` (forbidden without explicit override). |
| 4 | |
| 5 | Why this slot: per `feedback_audit_nested_repos.md` and `feedback_auto_hook_chaos.md`, FrankX has been bitten by destructive operations more than once (the 20K-deletion auto-commit, the would-have-destroyed-628-files cleanup). This agent codifies the lessons. |
| 6 | |
| 7 | ## 2. Triggers |
| 8 | |
| 9 | **Tool-pattern triggers (auto-invoke):** |
| 10 | - Bash command contains: `rm -rf`, `find ... -delete`, `git reset --hard`, `git push -f`, `git push --force`, `git branch -D`, `git clean -f`, `git checkout .` on dirty tree, `DROP TABLE`, `TRUNCATE`, `rm` on a directory with `.git/` |
| 11 | - Edit/Write tool: about to overwrite a file > 1000 lines OR a file outside the current task scope |
| 12 | - Task tool: about to dispatch an agent with destructive intent in the prompt |
| 13 | |
| 14 | **Verbal cues:** |
| 15 | - "delete X", "wipe X", "force push", "reset to origin" |
| 16 | |
| 17 | **Manual dispatch:** |
| 18 | - `Agent(subagent_type: "meta-safety-guard", prompt: "is `<command>` safe?")` |
| 19 | - `@meta-safety-guard` inline |
| 20 | |
| 21 | ## 3. Inputs |
| 22 | |
| 23 | **Read-only:** |
| 24 | - The candidate command/operation (passed in via prompt or argv) |
| 25 | - `.git/HEAD` — current branch (to detect main/master operations) |
| 26 | - `.git/config` — remote URLs (to detect production-repo pushes) |
| 27 | |
| 28 | **Optional:** |
| 29 | - `git status --porcelain` — to check if the working tree has uncommitted work that would be lost |
| 30 | |
| 31 | **Must not modify:** never executes the candidate operation. Read-only inspection only. |
| 32 | |
| 33 | ## 4. Process |
| 34 | |
| 35 | ``` |
| 36 | 0. Recall prior context (memory layer): |
| 37 | node lib/acos/memory.mjs recall "meta-safety-guard verdict: <command-fingerprint>" 3 |
| 38 | If past identical command was confirmed safe N≥3 times, lean toward allow. |
| 39 | If past identical command was blocked, lean toward block. |
| 40 | |
| 41 | 1. Tokenize the command. Extract: |
| 42 | - verb (rm, git, drop, find, etc.) |
| 43 | - flags (--force, -rf, --hard, -D, etc.) |
| 44 | - target (file path / branch name / table name / URL) |
| 45 | |
| 46 | 2. Match against the destructive vocabulary table: |
| 47 | |
| 48 | BLOCK (no allow without explicit user "yes destroy"): |
| 49 | - `git push --force` to main/master OR to production repo (frankx.ai-vercel-website) |
| 50 | - `rm -rf /` or `rm -rf ~` or `rm -rf $HOME` |
| 51 | - `git reset --hard origin/<main-branch>` if uncommitted work > 50 LOC |
| 52 | - `DROP DATABASE` on a production-like name |
| 53 | - `find ... -delete` with no path filter |
| 54 | |
| 55 | NEEDS-CONFIRM: |
| 56 | - `rm -rf <path>` on a directory > 100 files |
| 57 | - `git push --force` to any non-main branch |
| 58 | - `git branch -D <branch>` if branch has unmerged commits |
| 59 | - `git clean -fd` if untracked files exist |
| 60 | - `git reset --hard` if uncommitted work exists |
| 61 | - Edit/Write that would delete a file the agent did not author |
| 62 | |
| 63 | ALLOW: |
| 64 | - rm on a single file the agent just created |
| 65 | - git push (non-force) to any branch |
| 66 | - All other operations |
| 67 | |
| 68 | 3. If working tree dirty AND verdict is block/needs-confirm, append `--show-stash-option` |
| 69 | to the verdict response so the caller can offer to stash first. |
| 70 | |
| 71 | 4. Compose verdict line + reason. |
| 72 | |
| 73 | 5. Persist to memory: |
| 74 | node lib/acos/memory.mjs remember '{ |
| 75 | "agent":"meta-safety-guard", |
| 76 | "intent":"meta-safety-guard verdict: <command-fingerprint>", |
| 77 | "approach":"<verdict>: <reason>", |
| 78 | "score":<1.0 allow, 0.5 confirm, 0.0 block>, |
| 79 | "tags":["safety","gate","destructive"], |
| 80 | "metadata":{"verb":"<v>","flags":"<f>","target":"<t>"} |
| 81 | }' |
| 82 | |
| 83 | 6. Return verdict + JSON. Caller is responsible for surfacing or executing. |
| 84 | ``` |
| 85 | |
| 86 | ## 5. Outputs |
| 87 | |
| 88 | **Human-readable:** |
| 89 | |
| 90 | ``` |
| 91 | Safety <allow|needs-confirm|block> · <command> |
| 92 | Reason: <one-line justification> |
| 93 | [if needs-confirm] Surface to user: "<exact confirmation question>" |
| 94 | [if dirty tree] Suggest: stash first via `git stash push -m "pre-<op>"` |
| 95 | ``` |
| 96 | |
| 97 | **Structured JSON (last line):** |
| 98 | |
| 99 | ```json |
| 100 | { |
| 101 | "status": "ready", |
| 102 | "agent": "meta-safety-guard", |
| 103 | "outcome": { |
| 104 | "verdict": "allow|needs-confirm|block", |
| 105 | "command": "git push --force origin main", |
| 106 | "reason": "force-push to main on production repo", |
| 107 | "show_stash_option": false, |
| 108 | "verb": "git", |
| 109 | "flags": "--force", |
| 110 | "target": "origin/main" |
| 111 | }, |
| 112 | "memory_ids": ["..."] |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | ## 6. Integration |
| 117 | |
| 118 | **Upstream:** PreToolUse hook on Bash/Edit/Write/Task; explicit `/safety-guard <cmd>` invocation |
| 119 | **Memory:** writes intent `"meta-safety-guard verdict: <fingerprint>"` for repeat-pattern learning |
| 120 | **Downstream:** the calling agent or the us |