#!/bin/bash
# ctxbaton skill installer
# Installs the CLI globally and wires up the Stop hook for automatic snapshots.
#
# Usage: bash install.sh

set -euo pipefail

SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PROJECT_DIR="$(dirname "$SKILL_DIR")"

echo "Installing ctxbaton..."

# Install CLI globally
if command -v uv &>/dev/null; then
  uv tool install --editable "$PROJECT_DIR"
else
  echo "Error: uv is required. Install from https://docs.astral.sh/uv/" >&2
  exit 1
fi

# Install Stop hook
ctxbaton hooks install

# Copy skill to Claude Code skills directory
CLAUDE_SKILLS="$HOME/.claude/skills/ctxbaton"
mkdir -p "$CLAUDE_SKILLS"
cp -r "$SKILL_DIR/." "$CLAUDE_SKILLS/"
echo "✓ Skill installed → $CLAUDE_SKILLS"

echo ""
echo "Done. ctxbaton is active."
echo "  Run 'ctxbaton context' to verify."
echo "  Use '/ctxbaton' in Claude Code to load project context."
