#!/bin/sh
# Whitesmith agent kit installer (2026-11-30-04dab86a)
# Review: https://whitesmith.ru/agent-kit/install.sh · Manual: download the tarball, untar, follow README.md
set -e

KIT_HOME="${WSF_AGENT_KIT_HOME:-$HOME/.whitesmith-agent-kit}"
BASE="${WSF_AGENT_KIT_URL:-https://whitesmith.ru/agent-kit}"

command -v curl >/dev/null 2>&1 || { echo "error: curl is required"; exit 1; }
command -v node >/dev/null 2>&1 || { echo "error: Node.js >= 20 is required"; exit 1; }

echo "==> Downloading Whitesmith agent kit from $BASE"
mkdir -p "$KIT_HOME"
curl -fsSL "$BASE/whitesmith-agent-kit.tar.gz" -o "$KIT_HOME/kit.tar.gz"
tar -xzf "$KIT_HOME/kit.tar.gz" -C "$KIT_HOME"
rm -f "$KIT_HOME/kit.tar.gz"

echo "==> Installing dependencies (this installs Playwright + Chromium)"
cd "$KIT_HOME"
npm install --omit=dev --no-fund --no-audit
npx playwright install chromium

echo "==> Linking skills into agent skill directories"
for dir in "$HOME/.pi/agent/skills" "$HOME/.claude/skills"; do
  mkdir -p "$dir"
  for skill in static-site-dev catalog-family-ops; do
    ln -sfn "$KIT_HOME/skills/$skill" "$dir/$skill"
    echo "    linked -> $dir/$skill"
  done
done

echo ""
echo "Done. Kit home: $KIT_HOME"
echo "Next steps:"
echo "  1. Create an MCP token: https://whitesmith.ru/dashboard/settings/mcp-tokens"
echo "  2. Configure your agent: https://whitesmith.ru/mcp"
echo "  3. Ask your agent to work on a static site (static-site-dev skill) or to
     configure the commerce catalog / product families (catalog-family-ops)."
