#!/bin/bash
# PreToolUse guard: the code-reviewer subagent may only run read-only commands.
INPUT=$(cat)
AGENT=$(echo "$INPUT" | jq -r '.agent_type // empty')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
[ "$AGENT" = "code-reviewer" ] || exit 0       # not the reviewer: other rules decide
if echo "$CMD" | grep -qE '[;&|<>`]|\$\(|--output'; then
  echo "Blocked: one read-only command, no chaining or output files" >&2; exit 2
fi
if echo "$CMD" | grep -qE '^(git (diff|log|show|status)|npm test)( |$)'; then
  exit 0                                      # allowlist
fi
echo "Blocked: code-reviewer is read-only" >&2
exit 2
