#!/usr/bin/env bash
set -e

REPO_NAME="SkillForge"
REPO_URL="https://huggingface.co/spaces/lensetek/skillforge.git"
CAPACITY="AI Sub-Agent & Skill Customization Workspace"
PUBLISHER="Lensetek International, LLC."

echo "===================================================================="
echo "      $REPO_NAME - UNIVERSAL INSTALLER WIZARD"
echo "      Publisher: $PUBLISHER"
echo "===================================================================="
echo "Repository : $REPO_URL"
echo "Capacity   : $CAPACITY"
echo "Scope      : Global Installation for All AI Agents"
echo "Security   : 100% Open-Source Text Script (Safe, Zero Binaries)"
echo "--------------------------------------------------------------------"
echo ""

echo "[1/3] Checking Node.js runtime environment..."
if command -v node >/dev/null 2>&1; then
    NODE_VER=$(node -v 2>/dev/null || echo "")
    echo "      [OK] Node.js is installed ($NODE_VER)."
else
    echo "      [!] Node.js not detected."
    echo "      Please install Node.js LTS from https://nodejs.org or via your package manager."
    exit 1
fi

echo ""
echo "[2/3] Installing SkillForge Agent Skills GLOBALLY via NPX..."
echo "      Command: npx --yes skills add -g \"$REPO_URL\" -y"
echo ""
npx --yes skills add -g "$REPO_URL" -y

echo ""
echo "===================================================================="
echo "[SUCCESS] SkillForge Suite installed GLOBALLY!"
echo "All AI Agents (Freebuff, OpenCode, Antigravity, Claude Code, Cursor,"
echo "Windsurf, Codex, ChatGPT) now recognize all skills across all your"
echo "local workspaces and projects!"
echo "===================================================================="
echo ""

echo "[3/3] OPTIONAL: RECOMMENDED AI DESKTOP AGENT CLIENTS"
echo "Explore modern desktop AI clients to run these skills:"
echo "  - Freebuff Desktop: https://freebuff.com"
echo "  - OpenCode Desktop: https://opencode.ai/download"
echo ""
read -p "Would you like to open OpenCode Desktop download page? [y/N]: " choice
choice=${choice:-N}
if [[ "$choice" =~ ^[Yy]$ ]]; then
    if command -v xdg-open >/dev/null 2>&1; then
        xdg-open "https://opencode.ai/download"
    elif command -v open >/dev/null 2>&1; then
        open "https://opencode.ai/download"
    else
        echo "Please visit: https://opencode.ai/download"
    fi
fi

echo ""
echo "Setup complete! Enjoy SkillForge."
echo "Published by $PUBLISHER (https://lensetek.com)"
