#!/bin/sh

# script/lint: Validate Agent Skills definitions with skills-ref.
# skills-ref is the reference CLI for the Agent Skills spec (agentskills.io).
# It provides the `agentskills` executable with a `validate` subcommand.
# Uses uvx if available for a clean, isolated install of the validator.
# Falls back to a local Python module install if uv is not present.

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"
  exit 0
fi

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"
