#!/usr/bin/env bash # Without arguments this runs as a PreToolUse hook: it reads the event from stdin and exits 2 to block. # With a command argument it checks that command and also rejects absolute paths outside the # workspace (second argument, default: the working directory). # Pattern checks are a guard rail against accidents, not a security boundary. set -uo pipefail script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=resolve-python.sh . "$script_dir/resolve-python.sh" hook_arguments=() # Codex hook commands pass -Shell ; that is still hook mode. if [ "${1:-}" = -Shell ] && [ $# -eq 2 ]; then hook_arguments=(--shell "$2") shift 2 fi if [ $# -gt 0 ]; then resolve_python || { python_missing_message >&2; exit 1; } printf '%s' "$1" | run_python "$script_dir/command-safety.py" --command - --workspace "${2:-$PWD}" exit $? fi # Registered hooks fail open without Python; doctor reports that case. resolve_python || exit 0 run_python "$script_dir/command-safety.py" --hook ${hook_arguments[@]+"${hook_arguments[@]}"}