一键导入
security-guard
Generate or update security guardrail hooks. Use when: /harn:guard, 'update security rules', 'block dangerous commands', 'add guardrail'
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate or update security guardrail hooks. Use when: /harn:guard, 'update security rules', 'block dangerous commands', 'add guardrail'
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Scaffold a complete harness for the current project — AGENTS.md, hooks, guardrails. Use when starting a new project or hardening an existing one. Triggers: /harn:init, 'set up harness', 'scaffold guardrails', 'create AGENTS.md'
Build or rebuild AGENTS.md with progressive disclosure. Use when: /harn:agents-md, 'create AGENTS.md', 'update agent instructions', 'too many instructions'
Audit project harness against the CAR framework. Use when: /harn:analyze, 'audit harness', 'check CAR', 'harness health', 'how good is my harness'
Scaffold resume artifacts (LEARNED.md, CHECKPOINT.json) for long-running sessions. Triggers: /harn:checkpoint, 'resume artifacts', 'checkpoint', 'session recovery', 'LEARNED.md'
Generate context monitoring and backpressure hooks. Triggers: /harn:context, 'context monitoring', 'backpressure', 'context budget', 'attention budget', 'context rot'
Generate or update the quality gate Stop hook. Use when: /harn:quality-gate, 'set up type checking', 'add quality gate', 'stop hook'
| name | security-guard |
| description | Generate or update security guardrail hooks. Use when: /harn:guard, 'update security rules', 'block dangerous commands', 'add guardrail' |
Generate or update scripts/harness/security_guard.py for the current project.
scripts/harness/security_guard.py if it exists.claude/settings.json as a PreToolUse hookrm -rf — recursive forced deletiongit push ... main/master — direct push to protected brancheschmod 777 — reckless permissions> ~/ — overwriting home directory filescurl | bash — piped remote executionsudo rm — privileged deletionmkfs. — disk formattingdd if= — raw disk writesAsk the user if they want to:
src/)npm publish)Before adding user-supplied patterns, verify they compile as valid regex. Invalid patterns can silently break the guard or cause it to crash. Test each pattern with re.compile() and report errors back to the user before writing the script.
Offer to show the user what existing commands (from shell history or a sample list) would be blocked by the new patterns before activating. This helps catch overly broad patterns that would block legitimate work.
User-supplied regex patterns may contain errors — unbalanced groups, invalid escapes, or overly broad expressions. The generated script wraps each re.search() call in a try/except for re.error so that a single bad pattern does not disable the entire guard.
Generate scripts/harness/security_guard.py using this structure:
#!/usr/bin/env python3
# Harn security guard — blocks dangerous shell commands before execution
# Why: https://harn.app/kb/safety.html — "Tools should be hard to misuse"
# Docs: https://harn.app/kb/safety.html — "Mitigating Prompt Injection Attacks"
import json, sys, re
payload = json.load(sys.stdin)
if not isinstance(payload, dict):
sys.exit(0) # Malformed payload — allow (fail-open for non-Bash)
tool = payload.get("tool_name", "")
if tool != "Bash":
sys.exit(0)
command = payload.get("tool_input", {}).get("command", "")
dangerous = [
r"rm\s+-rf",
r"git\s+push\s+.*\b(main|master)\b",
r"chmod\s+777",
r">\s*~/",
r"curl\s+.*\|\s*bash",
r"sudo\s+rm",
r"mkfs\.",
r"dd\s+if=",
]
for pattern in dangerous:
try:
if re.search(pattern, command):
print(f"HARNESS BLOCK: Command matches prohibited pattern ({pattern}).", file=sys.stderr)
print("Find a safer alternative.", file=sys.stderr)
sys.exit(2)
except re.error:
print(f"HARNESS WARNING: Invalid regex pattern skipped: {pattern}", file=sys.stderr)
continue
sys.exit(0)