#!/usr/bin/env bash
set -euo pipefail

# gh-commit: AI-powered scoped git commits (Crush for scopes and messages)
# Install: gh extension install prdlk/gh-commit
# Requires: uv (https://docs.astral.sh/uv) and the Crush CLI
#           (https://github.com/charmbracelet/crush)

EXTENSION_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="${EXTENSION_DIR}/smartcommit.py"

if ! command -v uv &>/dev/null; then
  echo "error: 'uv' is required but not installed"
  echo "install: curl -LsSf https://astral.sh/uv/install.sh | sh"
  exit 1
fi

if [[ -z "${GH_COMMIT_CRUSH_CMD:-}" ]] && ! command -v crush &>/dev/null; then
  echo "warning: 'crush' not found — gh-commit uses 'crush run' for scopes and commit messages."
  echo "install Crush (https://github.com/charmbracelet/crush), or set GH_COMMIT_CRUSH_CMD."
fi

exec uv run --script "${SCRIPT}" "$@"
