#!/bin/sh

HERE="$(cd "$(dirname "$0")" && pwd)"
PREK="/opt/homebrew/bin/prek"

# Check if the full path to prek is executable, otherwise fallback to PATH
if [ ! -x "$PREK" ]; then
    PREK="prek"
fi

# Detect if this is an interactive terminal session (human) or non-interactive (agent).
# Use the agent config (skips tests) for non-interactive sessions.
if [ -t 1 ]; then
    CONFIG_FLAG=""
else
    CONFIG_FLAG="-c .pre-commit-config-agent.yaml"
fi

exec "$PREK" hook-impl --hook-dir "$HERE" --script-version 4 --hook-type=pre-commit $CONFIG_FLAG -- "$@"
