#!/bin/sh

# script/lint: Validate Agent Skills definitions with skills-ref,
# then lint and format Python scripts with ruff.

set -e

cd "$(dirname "$0")/.."

[ -z "$DEBUG" ] || set -x

SKILL_PATH="${1:-skills/replicate}"

echo "==> Validating Agent Skills in $SKILL_PATH"

if command -v uv >/dev/null 2>&1; then
  uvx --from skills-ref agentskills validate "$SKILL_PATH"
else
  PYTHON_BIN="${PYTHON_BIN:-python3}"
  if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
    if command -v python >/dev/null 2>&1; then
      PYTHON_BIN=python
    else
      echo "python not found. Install Python 3 or uv to run skills-ref." >&2
      exit 1
    fi
  fi
  "$PYTHON_BIN" -m skills_ref validate "$SKILL_PATH"
fi

echo "==> Linting Python (ruff check)"
uvx ruff check script/test_snippets.py

echo "==> Formatting Python (ruff format --check)"
uvx ruff format --check script/test_snippets.py
