# Skip hook in CI (e.g., GitHub Actions / semantic-release)
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
  echo "Skipping pre-push in CI"
  exit 0
fi

# Fail on first error
set -e

# Run type check, lint and prettier check before pushing
pnpm run test:type-check
pnpm run lint
pnpm run format:check

# Generate LLM-friendly docs surface and ensure it's committed
echo "Generating llms.txt…"
pnpm run llms:gen

# If llms.txt differs from HEAD (staged or unstaged), abort so it can be committed
if ! git diff --quiet HEAD -- llms.txt; then
  printf "\nllms.txt was updated by the generator.\n"
  echo "Please add and commit llms.txt, then push again."
  exit 1
fi
