install-plugins.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #!/usr/bin/env bash
  2. # ============================================================
  3. # Claude Code — Plugin installer
  4. # Run this after a fresh clone to reinstall all plugins
  5. # and their prerequisites on a new machine.
  6. #
  7. # Supports: Linux (apt/dnf/pacman), macOS (brew)
  8. # ============================================================
  9. set -euo pipefail
  10. RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
  11. ok() { echo -e "${GREEN}✓${NC} $1"; }
  12. warn() { echo -e "${YELLOW}⚠${NC} $1"; }
  13. info() { echo -e "${BLUE}→${NC} $1"; }
  14. err() { echo -e "${RED}✗${NC} $1"; }
  15. REPO="$(cd "$(dirname "$0")" && pwd)"
  16. # Log to file for post-mortem debugging (terminal output unchanged)
  17. LOG_FILE="$REPO/install-$(date +%Y%m%d-%H%M%S).log"
  18. if touch "$LOG_FILE" 2>/dev/null; then
  19. exec > >(tee -a "$LOG_FILE") 2>&1
  20. info "Logging to $LOG_FILE"
  21. else
  22. warn "Cannot write log to $REPO — continuing without log file"
  23. fi
  24. # Load shared detection library
  25. # shellcheck source=lib/detect-plugins.sh
  26. source "$REPO/lib/detect-plugins.sh"
  27. # Read pinned version from plugins.lock.json
  28. # Usage: pinned_version "rtk" → prints version string or "latest"
  29. pinned_version() {
  30. local key="$1"
  31. if [ -f "$REPO/plugins.lock.json" ] && command -v python3 &>/dev/null; then
  32. python3 -c "
  33. import json, sys
  34. with open('$REPO/plugins.lock.json') as f:
  35. d = json.load(f)
  36. v = d.get('$key', {}).get('version', 'latest')
  37. print(v)
  38. " 2>/dev/null || echo "latest"
  39. else
  40. echo "latest"
  41. fi
  42. }
  43. # ============================================================
  44. # DETECT OS
  45. # ============================================================
  46. OS="unknown"
  47. PKG=""
  48. if [[ "$OSTYPE" == "darwin"* ]]; then
  49. OS="macos"
  50. elif command -v apt-get &>/dev/null; then
  51. OS="linux-apt"; PKG="apt-get"
  52. elif command -v dnf &>/dev/null; then
  53. OS="linux-dnf"; PKG="dnf"
  54. elif command -v pacman &>/dev/null; then
  55. OS="linux-pacman"; PKG="pacman"
  56. fi
  57. echo ""
  58. echo "╔══════════════════════════════════════════════════════════╗"
  59. echo "║ Claude Code — Plugin & Tool Installer ║"
  60. echo "╚══════════════════════════════════════════════════════════╝"
  61. echo ""
  62. info "OS: $OS | Repo: $REPO"
  63. echo ""
  64. # ============================================================
  65. # STEP 1 — PREREQUISITES
  66. # ============================================================
  67. echo "── Step 1: Prerequisites ───────────────────────────────────"
  68. echo ""
  69. # --- git ---
  70. if command -v git &>/dev/null; then
  71. ok "git $(git --version | awk '{print $3}')"
  72. else
  73. info "Installing git..."
  74. case $OS in
  75. macos) brew install git ;;
  76. linux-apt) sudo apt-get install -y git ;;
  77. linux-dnf) sudo dnf install -y git ;;
  78. linux-pacman) sudo pacman -S --noconfirm git ;;
  79. *) err "Cannot auto-install git on $OS — install manually"; exit 1 ;;
  80. esac
  81. ok "git installed"
  82. fi
  83. # --- Node.js (>=18) ---
  84. NODE_OK=false
  85. if command -v node &>/dev/null; then
  86. NODE_VER=$(node --version | sed 's/v//' | cut -d. -f1)
  87. if [ "$NODE_VER" -ge 22 ]; then
  88. ok "Node.js $(node --version)"; NODE_OK=true
  89. else
  90. warn "Node.js $(node --version) is too old (need >=22 — GSD v2 requires it)"
  91. fi
  92. fi
  93. if [ "$NODE_OK" = false ]; then
  94. info "Installing Node.js 22 LTS..."
  95. case $OS in
  96. macos)
  97. brew install node@22
  98. export PATH="/opt/homebrew/opt/node@22/bin:$PATH"
  99. ;;
  100. linux-apt)
  101. curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
  102. sudo apt-get install -y nodejs
  103. ;;
  104. linux-dnf)
  105. curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
  106. sudo dnf install -y nodejs
  107. ;;
  108. linux-pacman)
  109. sudo pacman -S --noconfirm nodejs npm
  110. ;;
  111. *) warn "Cannot auto-install Node.js on $OS — install from https://nodejs.org" ;;
  112. esac
  113. command -v node &>/dev/null && ok "Node.js $(node --version)" || err "Node.js install failed"
  114. fi
  115. # --- Rust + Cargo (for RTK) ---
  116. if command -v cargo &>/dev/null; then
  117. ok "Rust/Cargo $(cargo --version | awk '{print $2}')"
  118. else
  119. info "Installing Rust (rustup)..."
  120. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
  121. source "$HOME/.cargo/env"
  122. ok "Rust installed: $(cargo --version)"
  123. fi
  124. # --- Python 3 ---
  125. if command -v python3 &>/dev/null; then
  126. ok "Python $(python3 --version)"
  127. else
  128. info "Installing Python 3..."
  129. case $OS in
  130. macos) brew install python3 ;;
  131. linux-apt) sudo apt-get install -y python3 ;;
  132. linux-dnf) sudo dnf install -y python3 ;;
  133. linux-pacman) sudo pacman -S --noconfirm python ;;
  134. *) warn "Cannot auto-install Python on $OS" ;;
  135. esac
  136. fi
  137. # --- Claude Code CLI ---
  138. if command -v claude &>/dev/null; then
  139. ok "Claude Code $(claude --version 2>/dev/null | head -1)"
  140. else
  141. err "Claude Code not installed. Install from https://code.claude.com then re-run."
  142. exit 1
  143. fi
  144. echo ""
  145. # ============================================================
  146. # STEP 2 — GSTACK SUBMODULE
  147. # ============================================================
  148. echo "── Step 2: GStack submodule ─────────────────────────────────"
  149. echo ""
  150. # Note: GStack is managed as a git submodule in this repo.
  151. # It lives at skills-external/gstack/ and is symlinked to ~/.claude/skills/gstack/
  152. # by link.sh. Never clone it separately — use the submodule.
  153. #
  154. # First-time setup:
  155. # git submodule update --init --recursive
  156. # Update to latest:
  157. # git submodule update --remote skills-external/gstack
  158. # cd skills-external/gstack && ./setup
  159. # git add skills-external/gstack && git commit -m "chore: update gstack"
  160. GSTACK_DIR="$REPO/skills-external/gstack"
  161. if [ ! -d "$GSTACK_DIR/.git" ] && [ ! -f "$GSTACK_DIR/.git" ]; then
  162. info "Initializing GStack submodule..."
  163. cd "$REPO"
  164. git submodule update --init --recursive
  165. cd - > /dev/null
  166. fi
  167. if [ -d "$GSTACK_DIR" ]; then
  168. # --- bun (required by GStack ./setup) ---
  169. if ! command -v bun &>/dev/null; then
  170. info "Installing bun (required by GStack)..."
  171. BUN_VERSION="1.3.10"
  172. tmpfile=$(mktemp)
  173. curl -fsSL "https://bun.sh/install" -o "$tmpfile"
  174. BUN_VERSION="$BUN_VERSION" bash "$tmpfile" && rm -f "$tmpfile"
  175. export PATH="$HOME/.bun/bin:$PATH"
  176. command -v bun &>/dev/null && ok "bun $(bun --version)" || err "bun install failed"
  177. else
  178. ok "bun $(bun --version)"
  179. fi
  180. info "Running GStack setup..."
  181. if [ -x "$GSTACK_DIR/setup" ]; then
  182. if (cd "$GSTACK_DIR" && ./setup); then
  183. : # setup succeeded
  184. else
  185. warn "GStack ./setup failed — check output above"
  186. fi
  187. else
  188. warn "GStack ./setup not found or not executable — skipping"
  189. fi
  190. # Symlinks are handled by link.sh — verify it was run
  191. if [ -L "$HOME/.claude/skills/gstack" ]; then
  192. ok "GStack ready (submodule initialized, symlink OK)"
  193. else
  194. warn "GStack submodule ready but not symlinked — run: bash link.sh"
  195. fi
  196. else
  197. warn "GStack submodule directory not found after init — check .gitmodules"
  198. fi
  199. echo ""
  200. # ============================================================
  201. # STEP 3 — RTK
  202. # ============================================================
  203. echo "── Step 3: RTK — Rust Token Killer ─────────────────────────"
  204. echo ""
  205. if command -v rtk &>/dev/null; then
  206. ok "rtk already installed ($(rtk --version 2>/dev/null | head -1))"
  207. else
  208. RTK_VER=$(pinned_version "rtk")
  209. if [ "$RTK_VER" != "latest" ]; then
  210. info "Installing RTK $RTK_VER (pinned in plugins.lock.json)..."
  211. cargo install --git https://github.com/rtk-ai/rtk --tag "$RTK_VER"
  212. else
  213. info "Installing RTK (latest — consider pinning in plugins.lock.json)..."
  214. cargo install --git https://github.com/rtk-ai/rtk
  215. fi
  216. fi
  217. # Only init if not already configured (avoids overwriting custom RTK config)
  218. if ! grep -q "rtk" "$HOME/.claude/settings.json" 2>/dev/null; then
  219. info "Configuring RTK PreToolUse hook (global)..."
  220. rtk init -g --auto-patch
  221. ok "RTK configured"
  222. else
  223. ok "RTK hook already present in settings.json — skipping init"
  224. fi
  225. echo ""
  226. # ============================================================
  227. # STEP 4 — GSD v2
  228. # ============================================================
  229. # GSD v2 (gsd-pi) is a standalone CLI built on the Pi SDK.
  230. # It is NOT a Claude Code plugin — it runs as an external process ('gsd' command).
  231. # Usage: run 'gsd' in your terminal from a project directory.
  232. # Slash commands (/gsd auto, /gsd status, etc.) are internal to a GSD session.
  233. echo "── Step 4: GSD v2 — gsd-pi ─────────────────────────────────"
  234. echo ""
  235. if command -v gsd &>/dev/null; then
  236. ok "gsd already installed ($(gsd --version 2>/dev/null | head -1 || echo 'installed'))"
  237. else
  238. GSD_VER=$(pinned_version "gsd")
  239. if [ "$GSD_VER" != "latest" ]; then
  240. info "Installing gsd-pi@${GSD_VER} (pinned in plugins.lock.json)..."
  241. npm install -g "gsd-pi@${GSD_VER}"
  242. else
  243. info "Installing gsd-pi@latest (consider pinning in plugins.lock.json)..."
  244. npm install -g gsd-pi
  245. fi
  246. command -v gsd &>/dev/null && ok "GSD v2 installed ($(gsd --version 2>/dev/null | head -1))" \
  247. || err "GSD v2 install failed — check npm output above"
  248. fi
  249. echo ""
  250. # ============================================================
  251. # STEP 5 — RUFLO MCP (manual — requires npm install + MCP config)
  252. # ============================================================
  253. # Ruflo is an enterprise multi-agent orchestration MCP server (formerly claude-flow).
  254. # 310+ MCP tools, 100+ agent types, WASM kernel, self-learning architecture.
  255. # Use only for projects requiring complex multi-agent coordination.
  256. # Default install ~340MB. Minimal: npm install -g ruflo@latest --omit=optional (~15s)
  257. echo "── Step 5: Ruflo MCP ────────────────────────────────────────"
  258. echo ""
  259. if detect_ruflo; then
  260. ok "Ruflo MCP already configured"
  261. else
  262. info "Installing Ruflo MCP (minimal, --omit=optional ~40MB)..."
  263. if npm install -g ruflo@latest --omit=optional; then
  264. ok "ruflo npm package installed"
  265. info "Registering Ruflo as MCP server..."
  266. if claude mcp add --scope user ruflo -- npx ruflo mcp start 2>/dev/null; then
  267. ok "Ruflo MCP registered"
  268. else
  269. warn "Ruflo MCP registration failed or already registered"
  270. echo " Run manually: claude mcp add --scope user ruflo -- npx ruflo mcp start"
  271. fi
  272. else
  273. err "Ruflo npm install failed"
  274. echo " Fallback — run the official installer:"
  275. echo " curl -fsSL https://cdn.jsdelivr.net/gh/ruvnet/ruflo@main/scripts/install.sh | bash -s -- --full"
  276. fi
  277. fi
  278. # ============================================================
  279. # STEP 6 — MARKETPLACE PLUGINS (user scope, explicit)
  280. # ============================================================
  281. # All claude plugin install commands use --scope user to ensure
  282. # they install to ~/.claude/plugins/ regardless of working directory.
  283. echo "── Step 6: Marketplace plugins (scope: user) ────────────────"
  284. echo ""
  285. install_plugin() {
  286. local name="$1"
  287. local source="$2"
  288. if claude plugin list 2>/dev/null | grep -qi "$name"; then
  289. ok "$name (already installed)"
  290. return
  291. fi
  292. info "Installing $name..."
  293. if claude plugin install --scope user "$name@$source" 2>/dev/null; then
  294. ok "$name"
  295. else
  296. err "$name — FAILED (run manually: claude plugin install --scope user $name@$source)"
  297. fi
  298. }
  299. # Official Anthropic (always on)
  300. # Add the official marketplace so CC knows the source; no-op if already registered or built-in
  301. info "Adding official Anthropic plugins marketplace..."
  302. claude plugin marketplace add anthropic/claude-plugins-official 2>/dev/null || true
  303. install_plugin "security-guidance" "claude-plugins-official"
  304. install_plugin "frontend-design" "claude-plugins-official"
  305. install_plugin "skill-creator" "claude-plugins-official"
  306. install_plugin "pr-review-toolkit" "claude-plugins-official"
  307. echo ""
  308. # Superpowers (always on)
  309. info "Adding Superpowers marketplace..."
  310. claude plugin marketplace add obra/superpowers-marketplace 2>/dev/null || true
  311. install_plugin "superpowers" "superpowers-marketplace"
  312. echo ""
  313. # UI/UX Pro Max (toggle)
  314. info "Adding UI/UX Pro Max marketplace..."
  315. claude plugin marketplace add nextlevelbuilder/ui-ux-pro-max-skill 2>/dev/null || true
  316. install_plugin "ui-ux-pro-max" "ui-ux-pro-max-skill"
  317. echo ""
  318. # ============================================================
  319. # STEP 6 — CONTEXT7 MCP (manual — requires API key)
  320. # ============================================================
  321. echo "── Step 7: Context7 MCP ─────────────────────────────────────"
  322. echo ""
  323. if claude mcp list 2>/dev/null | grep -q "context7"; then
  324. ok "Context7 MCP already configured"
  325. else
  326. warn "Context7 requires a free API key — cannot auto-install"
  327. echo ""
  328. echo " Steps:"
  329. echo " 1. Get a free key at https://upstash.com"
  330. echo " 2. Run:"
  331. echo " claude mcp add --scope user context7 -- \\"
  332. echo " npx -y @upstash/context7-mcp --api-key YOUR_KEY"
  333. echo ""
  334. fi
  335. # ============================================================
  336. # SUMMARY
  337. # ============================================================
  338. echo ""
  339. echo "╔══════════════════════════════════════════════════════════╗"
  340. echo "║ Install Summary ║"
  341. echo "╚══════════════════════════════════════════════════════════╝"
  342. echo ""
  343. echo " ALWAYS ON (installed at user scope):"
  344. echo " ✅ security-guidance — PreToolUse security hook (0 tokens)"
  345. echo " ✅ rtk — token compression hook (0 tokens)"
  346. echo " ✅ superpowers — brainstorm/plan/implement/debug workflow"
  347. echo ""
  348. echo " TOGGLE (installed but start OFF — /plugin-check recommends when needed):"
  349. echo " 🔄 gstack — ~/.claude/skills/gstack/ (→ submodule)"
  350. echo " 🔄 gsd v2 — standalone CLI 'gsd' (gsd-pi, not a Claude Code plugin)"
  351. echo " 🔄 skill-creator — create skills from conversation (~100 tokens)"
  352. echo " 🔄 pr-review-toolkit — /pr-review-toolkit:review-pr (~300 tokens)"
  353. echo " 🔄 frontend-design — user scope (~200 tokens)"
  354. echo " 🔄 ui-ux-pro-max — user scope (~400 tokens)"
  355. echo " 🔄 context7 MCP — see Step 7 above (~200 tokens)"
  356. echo " 🔄 ruflo MCP — see Step 5 above (~500-1500 tokens, enterprise only)"
  357. echo ""
  358. echo " All plugins installed at: user scope (~/.claude/plugins/)"
  359. echo " GStack at: ~/.claude/skills/gstack/ (symlink → submodule)"
  360. echo ""
  361. echo " → Restart Claude Code — plugins load automatically"
  362. echo ""