#!/usr/bin/env bash
# Pre-push hook: run regression check on changed skills only.
# Install: cp .githooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push

set -euo pipefail

# Find skills changed in this push
changed_skills=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '^skills/' | cut -d/ -f2 | sort -u || true)

if [[ -z "$changed_skills" ]]; then
  exit 0
fi

echo "🔍 Running regression check for changed skills: $changed_skills"

for skill in $changed_skills; do
  if [[ ! -f "skills/$skill/evals/evals.json" ]]; then
    echo "❌ Missing evals/evals.json for skill: $skill"
    echo "   Every skill must have evals before it can be pushed."
    exit 1
  fi
  python scripts/run_evals.py "$skill" --check-regression
done

echo "✅ All checks passed."
