From 4efc4f476261d1fd1fd129c4e477bcbdae54f735 Mon Sep 17 00:00:00 2001 From: uroma Date: Thu, 22 Jan 2026 15:41:59 +0000 Subject: [PATCH] Fix: Convert all shell scripts from CRLF to LF Fixed Windows line endings (CRLF) in all shell scripts to Unix format (LF): - supercharge.sh (main installation script) - agents/*.sh (all agent management scripts) - hooks/*.sh (all hook scripts) - skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh All scripts now pass bash syntax validation. --- agents/claude-setup-manager.sh | 658 ++--- agents/export-claude-customizations.sh | 424 +-- agents/install-claude-customizations.sh | 792 +++--- agents/interactive-install-claude.sh | 2340 ++++++++--------- agents/verify-claude-setup.sh | 434 +-- .../scripts/wordpress_safe_update.sh | 164 +- supercharge.sh | 880 +++---- 7 files changed, 2846 insertions(+), 2846 deletions(-) diff --git a/agents/claude-setup-manager.sh b/agents/claude-setup-manager.sh index 5c697bf..0758786 100755 --- a/agents/claude-setup-manager.sh +++ b/agents/claude-setup-manager.sh @@ -1,329 +1,329 @@ -#!/usr/bin/env bash -################################################################################ -# Claude Code Customizations - Master Control Script -# Provides an interactive menu for all setup operations -################################################################################ - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -CYAN='\033[0;36m' -BOLD='\033[1m' -NC='\033[0m' - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Script paths -INSTALL_SCRIPT="$SCRIPT_DIR/install-claude-customizations.sh" -EXPORT_SCRIPT="$SCRIPT_DIR/export-claude-customizations.sh" -PACKAGE_SCRIPT="$SCRIPT_DIR/create-complete-package.sh" -VERIFY_SCRIPT="$SCRIPT_DIR/verify-claude-setup.sh" - -# Helper functions -print_header() { - clear - echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════╗${NC}" - echo -e "${CYAN}║${NC} ${BOLD}Claude Code Customizations - Setup Manager${NC} ${CYAN}║${NC}" - echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════╝${NC}" - echo "" -} - -print_menu() { - print_header - echo -e "${BOLD}Main Menu:${NC}" - echo "" - echo -e " ${GREEN}1${NC}) 📦 Create Complete Package (recommended for distribution)" - echo -e " ${GREEN}2${NC}) 📥 Install Customizations (on new machine)" - echo -e " ${GREEN}3${NC}) 📤 Export Customizations (backup/transfer)" - echo -e " ${GREEN}4${NC}) ✅ Verify Installation" - echo -e " ${GREEN}5${NC}) 📋 Show Package Contents" - echo -e " ${GREEN}6${NC}) 📖 View Documentation" - echo -e " ${GREEN}7${NC}) 🧹 Clean Backup Files" - echo "" - echo -e " ${YELLOW}0${NC}) 🚪 Exit" - echo "" - echo -ne "${CYAN}Select an option: ${NC}" -} - -check_script() { - local script="$1" - local name="$2" - - if [ ! -f "$script" ]; then - echo -e "${RED}✗ Error: $name not found at $script${NC}" - return 1 - fi - - if [ ! -x "$script" ]; then - echo -e "${YELLOW}⚠ Making $name executable...${NC}" - chmod +x "$script" - fi - - return 0 -} - -create_package() { - print_header - echo -e "${BOLD}Create Complete Package${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "This will create a complete package with all agents, plugins," - echo "and configurations ready for distribution." - echo "" - read -p "Continue? (y/N): " confirm - - if [[ ! "$confirm" =~ ^[Yy]$ ]]; then - return - fi - - if check_script "$PACKAGE_SCRIPT" "Package Script"; then - echo "" - bash "$PACKAGE_SCRIPT" - fi - - echo "" - read -p "Press Enter to continue..." -} - -install_customizations() { - print_header - echo -e "${BOLD}Install Customizations${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "This will install Claude Code customizations on this machine." - echo "" - echo "Note: If you're creating a complete package, use option 1 instead." - echo "" - - if check_script "$INSTALL_SCRIPT" "Install Script"; then - echo "" - bash "$INSTALL_SCRIPT" - fi - - echo "" - read -p "Press Enter to continue..." -} - -export_customizations() { - print_header - echo -e "${BOLD}Export Customizations${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "This will export your current customizations to a package" - echo "for backup or transfer to another machine." - echo "" - read -p "Continue? (y/N): " confirm - - if [[ ! "$confirm" =~ ^[Yy]$ ]]; then - return - fi - - if check_script "$EXPORT_SCRIPT" "Export Script"; then - echo "" - bash "$EXPORT_SCRIPT" - fi - - echo "" - read -p "Press Enter to continue..." -} - -verify_installation() { - print_header - - if check_script "$VERIFY_SCRIPT" "Verify Script"; then - bash "$VERIFY_SCRIPT" - fi - - echo "" - read -p "Press Enter to continue..." -} - -show_contents() { - print_header - echo -e "${BOLD}Package Contents${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - CLAUDE_DIR="$HOME/.claude" - - if [ ! -d "$CLAUDE_DIR" ]; then - echo -e "${RED}No Claude Code directory found at $CLAUDE_DIR${NC}" - echo "" - read -p "Press Enter to continue..." - return - fi - - echo -e "${CYAN}Agent Categories:${NC}" - for category in engineering marketing product studio-operations project-management testing design bonus; do - if [ -d "$CLAUDE_DIR/agents/$category" ]; then - count=$(ls -1 "$CLAUDE_DIR/agents/$category"/*.md 2>/dev/null | wc -l) - if [ $count -gt 0 ]; then - printf " %-25s %2d agents\n" "$category" "$count" - fi - fi - done - - echo "" - echo -e "${CYAN}Configuration Files:${NC}" - echo " settings.json" - echo " settings.local.json" - echo " plugins/installed_plugins.json" - - echo "" - echo -e "${CYAN}MCP Tools:${NC}" - echo " • zai-mcp-server (vision analysis)" - echo " • web-search-prime" - echo " • web-reader" - echo " • zread (GitHub)" - - echo "" - echo -e "${CYAN}Skills:${NC}" - echo " • glm-plan-bug:case-feedback" - echo " • glm-plan-usage:usage-query" - - echo "" - read -p "Press Enter to continue..." -} - -view_documentation() { - print_header - echo -e "${BOLD}Documentation${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - DOCS=( - "SCRIPTS-GUIDE.md:Script usage guide" - "CLAUDE-CUSTOMIZATIONS-README.md:Complete feature documentation" - ) - - echo "Available documentation:" - echo "" - - for doc in "${DOCS[@]}"; do - file="${doc%%:*}" - desc="${doc##*:}" - if [ -f "$SCRIPT_DIR/$file" ]; then - echo -e " ${GREEN}✓${NC} $file" - echo " $desc" - else - echo -e " ${RED}✗${NC} $file (not found)" - fi - done - - echo "" - echo "Would you like to view a document?" - echo " 1) SCRIPTS-GUIDE.md" - echo " 2) CLAUDE-CUSTOMIZATIONS-README.md" - echo " 0) Back" - echo "" - read -p "Select: " doc_choice - - case $doc_choice in - 1) - if [ -f "$SCRIPT_DIR/SCRIPTS-GUIDE.md" ]; then - less "$SCRIPT_DIR/SCRIPTS-GUIDE.md" - fi - ;; - 2) - if [ -f "$SCRIPT_DIR/CLAUDE-CUSTOMIZATIONS-README.md" ]; then - less "$SCRIPT_DIR/CLAUDE-CUSTOMIZATIONS-README.md" - fi - ;; - esac -} - -clean_backups() { - print_header - echo -e "${BOLD}Clean Backup Files${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - # Find backup directories - BACKUPS=$(find "$HOME" -maxdepth 1 -name ".claude-backup-*" -type d 2>/dev/null) - PACKAGES=$(find "$HOME" -maxdepth 1 -name "claude-customizations-*.tar.gz" -type f 2>/dev/null) - EXPORT_DIRS=$(find "$HOME" -maxdepth 1 -name "claude-*-export" -type d 2>/dev/null) - - BACKUP_COUNT=$(echo "$BACKUPS" | grep -c "^" || echo 0) - PACKAGE_COUNT=$(echo "$PACKAGES" | grep -c "^" || echo 0) - EXPORT_COUNT=$(echo "$EXPORT_DIRS" | grep -c "^" || echo 0) - - echo "Found:" - echo " • $BACKUP_COUNT backup directories" - echo " • $PACKAGE_COUNT package archives" - echo " • $EXPORT_COUNT export directories" - echo "" - - if [ $((BACKUP_COUNT + PACKAGE_COUNT + EXPORT_COUNT)) -eq 0 ]; then - echo -e "${GREEN}No backup files to clean${NC}" - echo "" - read -p "Press Enter to continue..." - return - fi - - read -p "Clean all backup files? (y/N): " confirm - - if [[ ! "$confirm" =~ ^[Yy]$ ]]; then - return - fi - - echo "" - echo "Cleaning..." - - if [ -n "$BACKUPS" ]; then - echo "$BACKUPS" | while read -r backup; do - echo " Removing: $backup" - rm -rf "$backup" - done - fi - - if [ -n "$PACKAGES" ]; then - echo "$PACKAGES" | while read -r package; do - echo " Removing: $package" - rm -f "$package" - done - fi - - if [ -n "$EXPORT_DIRS" ]; then - echo "$EXPORT_DIRS" | while read -r export_dir; do - echo " Removing: $export_dir" - rm -rf "$export_dir" - done - fi - - echo "" - echo -e "${GREEN}✓ Cleanup complete${NC}" - echo "" - read -p "Press Enter to continue..." -} - -# Main loop -main() { - while true; do - print_menu - read -r choice - echo "" - - case $choice in - 1) create_package ;; - 2) install_customizations ;; - 3) export_customizations ;; - 4) verify_installation ;; - 5) show_contents ;; - 6) view_documentation ;; - 7) clean_backups ;; - 0) - echo "Goodbye!" - exit 0 - ;; - *) - echo -e "${RED}Invalid option. Please try again.${NC}" - sleep 1 - ;; - esac - done -} - -# Run main function -main +#!/usr/bin/env bash +################################################################################ +# Claude Code Customizations - Master Control Script +# Provides an interactive menu for all setup operations +################################################################################ + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +BOLD='\033[1m' +NC='\033[0m' + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Script paths +INSTALL_SCRIPT="$SCRIPT_DIR/install-claude-customizations.sh" +EXPORT_SCRIPT="$SCRIPT_DIR/export-claude-customizations.sh" +PACKAGE_SCRIPT="$SCRIPT_DIR/create-complete-package.sh" +VERIFY_SCRIPT="$SCRIPT_DIR/verify-claude-setup.sh" + +# Helper functions +print_header() { + clear + echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════╗${NC}" + echo -e "${CYAN}║${NC} ${BOLD}Claude Code Customizations - Setup Manager${NC} ${CYAN}║${NC}" + echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════╝${NC}" + echo "" +} + +print_menu() { + print_header + echo -e "${BOLD}Main Menu:${NC}" + echo "" + echo -e " ${GREEN}1${NC}) 📦 Create Complete Package (recommended for distribution)" + echo -e " ${GREEN}2${NC}) 📥 Install Customizations (on new machine)" + echo -e " ${GREEN}3${NC}) 📤 Export Customizations (backup/transfer)" + echo -e " ${GREEN}4${NC}) ✅ Verify Installation" + echo -e " ${GREEN}5${NC}) 📋 Show Package Contents" + echo -e " ${GREEN}6${NC}) 📖 View Documentation" + echo -e " ${GREEN}7${NC}) 🧹 Clean Backup Files" + echo "" + echo -e " ${YELLOW}0${NC}) 🚪 Exit" + echo "" + echo -ne "${CYAN}Select an option: ${NC}" +} + +check_script() { + local script="$1" + local name="$2" + + if [ ! -f "$script" ]; then + echo -e "${RED}✗ Error: $name not found at $script${NC}" + return 1 + fi + + if [ ! -x "$script" ]; then + echo -e "${YELLOW}⚠ Making $name executable...${NC}" + chmod +x "$script" + fi + + return 0 +} + +create_package() { + print_header + echo -e "${BOLD}Create Complete Package${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "This will create a complete package with all agents, plugins," + echo "and configurations ready for distribution." + echo "" + read -p "Continue? (y/N): " confirm + + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + return + fi + + if check_script "$PACKAGE_SCRIPT" "Package Script"; then + echo "" + bash "$PACKAGE_SCRIPT" + fi + + echo "" + read -p "Press Enter to continue..." +} + +install_customizations() { + print_header + echo -e "${BOLD}Install Customizations${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "This will install Claude Code customizations on this machine." + echo "" + echo "Note: If you're creating a complete package, use option 1 instead." + echo "" + + if check_script "$INSTALL_SCRIPT" "Install Script"; then + echo "" + bash "$INSTALL_SCRIPT" + fi + + echo "" + read -p "Press Enter to continue..." +} + +export_customizations() { + print_header + echo -e "${BOLD}Export Customizations${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "This will export your current customizations to a package" + echo "for backup or transfer to another machine." + echo "" + read -p "Continue? (y/N): " confirm + + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + return + fi + + if check_script "$EXPORT_SCRIPT" "Export Script"; then + echo "" + bash "$EXPORT_SCRIPT" + fi + + echo "" + read -p "Press Enter to continue..." +} + +verify_installation() { + print_header + + if check_script "$VERIFY_SCRIPT" "Verify Script"; then + bash "$VERIFY_SCRIPT" + fi + + echo "" + read -p "Press Enter to continue..." +} + +show_contents() { + print_header + echo -e "${BOLD}Package Contents${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + CLAUDE_DIR="$HOME/.claude" + + if [ ! -d "$CLAUDE_DIR" ]; then + echo -e "${RED}No Claude Code directory found at $CLAUDE_DIR${NC}" + echo "" + read -p "Press Enter to continue..." + return + fi + + echo -e "${CYAN}Agent Categories:${NC}" + for category in engineering marketing product studio-operations project-management testing design bonus; do + if [ -d "$CLAUDE_DIR/agents/$category" ]; then + count=$(ls -1 "$CLAUDE_DIR/agents/$category"/*.md 2>/dev/null | wc -l) + if [ $count -gt 0 ]; then + printf " %-25s %2d agents\n" "$category" "$count" + fi + fi + done + + echo "" + echo -e "${CYAN}Configuration Files:${NC}" + echo " settings.json" + echo " settings.local.json" + echo " plugins/installed_plugins.json" + + echo "" + echo -e "${CYAN}MCP Tools:${NC}" + echo " • zai-mcp-server (vision analysis)" + echo " • web-search-prime" + echo " • web-reader" + echo " • zread (GitHub)" + + echo "" + echo -e "${CYAN}Skills:${NC}" + echo " • glm-plan-bug:case-feedback" + echo " • glm-plan-usage:usage-query" + + echo "" + read -p "Press Enter to continue..." +} + +view_documentation() { + print_header + echo -e "${BOLD}Documentation${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + DOCS=( + "SCRIPTS-GUIDE.md:Script usage guide" + "CLAUDE-CUSTOMIZATIONS-README.md:Complete feature documentation" + ) + + echo "Available documentation:" + echo "" + + for doc in "${DOCS[@]}"; do + file="${doc%%:*}" + desc="${doc##*:}" + if [ -f "$SCRIPT_DIR/$file" ]; then + echo -e " ${GREEN}✓${NC} $file" + echo " $desc" + else + echo -e " ${RED}✗${NC} $file (not found)" + fi + done + + echo "" + echo "Would you like to view a document?" + echo " 1) SCRIPTS-GUIDE.md" + echo " 2) CLAUDE-CUSTOMIZATIONS-README.md" + echo " 0) Back" + echo "" + read -p "Select: " doc_choice + + case $doc_choice in + 1) + if [ -f "$SCRIPT_DIR/SCRIPTS-GUIDE.md" ]; then + less "$SCRIPT_DIR/SCRIPTS-GUIDE.md" + fi + ;; + 2) + if [ -f "$SCRIPT_DIR/CLAUDE-CUSTOMIZATIONS-README.md" ]; then + less "$SCRIPT_DIR/CLAUDE-CUSTOMIZATIONS-README.md" + fi + ;; + esac +} + +clean_backups() { + print_header + echo -e "${BOLD}Clean Backup Files${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + # Find backup directories + BACKUPS=$(find "$HOME" -maxdepth 1 -name ".claude-backup-*" -type d 2>/dev/null) + PACKAGES=$(find "$HOME" -maxdepth 1 -name "claude-customizations-*.tar.gz" -type f 2>/dev/null) + EXPORT_DIRS=$(find "$HOME" -maxdepth 1 -name "claude-*-export" -type d 2>/dev/null) + + BACKUP_COUNT=$(echo "$BACKUPS" | grep -c "^" || echo 0) + PACKAGE_COUNT=$(echo "$PACKAGES" | grep -c "^" || echo 0) + EXPORT_COUNT=$(echo "$EXPORT_DIRS" | grep -c "^" || echo 0) + + echo "Found:" + echo " • $BACKUP_COUNT backup directories" + echo " • $PACKAGE_COUNT package archives" + echo " • $EXPORT_COUNT export directories" + echo "" + + if [ $((BACKUP_COUNT + PACKAGE_COUNT + EXPORT_COUNT)) -eq 0 ]; then + echo -e "${GREEN}No backup files to clean${NC}" + echo "" + read -p "Press Enter to continue..." + return + fi + + read -p "Clean all backup files? (y/N): " confirm + + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + return + fi + + echo "" + echo "Cleaning..." + + if [ -n "$BACKUPS" ]; then + echo "$BACKUPS" | while read -r backup; do + echo " Removing: $backup" + rm -rf "$backup" + done + fi + + if [ -n "$PACKAGES" ]; then + echo "$PACKAGES" | while read -r package; do + echo " Removing: $package" + rm -f "$package" + done + fi + + if [ -n "$EXPORT_DIRS" ]; then + echo "$EXPORT_DIRS" | while read -r export_dir; do + echo " Removing: $export_dir" + rm -rf "$export_dir" + done + fi + + echo "" + echo -e "${GREEN}✓ Cleanup complete${NC}" + echo "" + read -p "Press Enter to continue..." +} + +# Main loop +main() { + while true; do + print_menu + read -r choice + echo "" + + case $choice in + 1) create_package ;; + 2) install_customizations ;; + 3) export_customizations ;; + 4) verify_installation ;; + 5) show_contents ;; + 6) view_documentation ;; + 7) clean_backups ;; + 0) + echo "Goodbye!" + exit 0 + ;; + *) + echo -e "${RED}Invalid option. Please try again.${NC}" + sleep 1 + ;; + esac + done +} + +# Run main function +main diff --git a/agents/export-claude-customizations.sh b/agents/export-claude-customizations.sh index f1e80ee..fbc2650 100755 --- a/agents/export-claude-customizations.sh +++ b/agents/export-claude-customizations.sh @@ -1,212 +1,212 @@ -#!/usr/bin/env bash -################################################################################ -# Claude Code Customizations Exporter -# This script packages all customizations for transfer to another machine -################################################################################ - -set -e - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' - -# Configuration -CLAUDE_DIR="$HOME/.claude" -EXPORT_DIR="$HOME/claude-customizations-export" -EXPORT_FILE="$HOME/claude-customizations-$(date +%Y%m%d_%H%M%S).tar.gz" - -log_info() { - echo -e "${BLUE}[INFO]${NC} $1" -} - -log_success() { - echo -e "${GREEN}[SUCCESS]${NC} $1" -} - -log_warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -# Create export directory -log_info "Creating export directory..." -rm -rf "$EXPORT_DIR" -mkdir -p "$EXPORT_DIR" - -# Export agents -log_info "Exporting custom agents..." -mkdir -p "$EXPORT_DIR/agents" -cp -r "$CLAUDE_DIR/agents/"* "$EXPORT_DIR/agents/" 2>/dev/null || true - -# Export plugins configuration -log_info "Exporting plugins configuration..." -mkdir -p "$EXPORT_DIR/plugins" -cp -r "$CLAUDE_DIR/plugins/cache/"* "$EXPORT_DIR/plugins/" 2>/dev/null || true -cp "$CLAUDE_DIR/plugins/installed_plugins.json" "$EXPORT_DIR/plugins/" 2>/dev/null || true -cp "$CLAUDE_DIR/plugins/known_marketplaces.json" "$EXPORT_DIR/plugins/" 2>/dev/null || true - -# Export settings (without sensitive data) -log_info "Exporting settings..." -mkdir -p "$EXPORT_DIR/config" - -# Export settings.local.json (permissions) -cp "$CLAUDE_DIR/settings.local.json" "$EXPORT_DIR/config/" 2>/dev/null || true - -# Create settings template (without actual API token) -cat > "$EXPORT_DIR/config/settings-template.json" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "YOUR_API_TOKEN_HERE", - "ANTHROPIC_BASE_URL": "https://api.anthropic.com", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" - }, - "enabledPlugins": { - "glm-plan-bug@zai-coding-plugins": true, - "glm-plan-usage@zai-coding-plugins": true - } -} -EOF - -# Export hooks if present -log_info "Exporting hooks..." -if [ -d "$CLAUDE_DIR/hooks" ] && [ "$(ls -A $CLAUDE_DIR/hooks)" ]; then - mkdir -p "$EXPORT_DIR/hooks" - cp -r "$CLAUDE_DIR/hooks/"* "$EXPORT_DIR/hooks/" -fi - -# Create README -log_info "Creating documentation..." -cat > "$EXPORT_DIR/README.md" << 'EOF' -# Claude Code Customizations Package - -This package contains all customizations for Claude Code including custom agents, MCP tools configuration, and plugins. - -## Contents - -- `agents/` - Custom agent definitions organized by category -- `plugins/` - Plugin configurations -- `config/` - Settings files -- `hooks/` - Custom hooks (if any) - -## Installation - -### Quick Install - -Run the automated installer: - -```bash -bash install-claude-customizations.sh -``` - -### Manual Install - -1. **Copy agents:** - ```bash - cp -r agents/* ~/.claude/agents/ - ``` - -2. **Copy plugins:** - ```bash - cp -r plugins/* ~/.claude/plugins/ - ``` - -3. **Configure settings:** - ```bash - cp config/settings.local.json ~/.claude/ - # Edit ~/.claude/settings.json and add your API token - ``` - -4. **Install MCP tools:** - ```bash - npm install -g @z_ai/mcp-server @z_ai/coding-helper - ``` - -5. **Restart Claude Code** - -## Agent Categories - -- **Engineering** - AI engineer, backend architect, frontend developer, DevOps, mobile app builder -- **Marketing** - TikTok strategist, growth hacker, content creator -- **Product** - Sprint prioritizer, feedback synthesizer, trend researcher -- **Studio Operations** - Studio producer, project shipper, analytics, finance -- **Project Management** - Experiment tracker, studio coach -- **Testing** - Test writer/fixer, API tester, performance benchmarker -- **Design** - UI designer, UX researcher, brand guardian, whimsy injector -- **Bonus** - Joker, studio coach - -## MCP Tools Included - -- **zai-mcp-server** - Vision analysis (images, videos, UI screenshots, error diagnosis) -- **web-search-prime** - Enhanced web search with domain filtering -- **web-reader** - Fetch URLs and convert to markdown -- **zread** - GitHub repository reader - -## Skills - -- `glm-plan-bug:case-feedback` - Submit bug/issue feedback -- `glm-plan-usage:usage-query` - Query account usage statistics - -## Customization - -Edit agent `.md` files in `~/.claude/agents/` to customize agent behavior. - -## Support - -For issues or questions, refer to the original source machine or Claude Code documentation. -EOF - -# Create manifest -log_info "Creating package manifest..." -cat > "$EXPORT_DIR/MANIFEST.json" << EOF -{ - "package": "claude-code-customizations", - "version": "1.0.0", - "exported_at": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", - "contents": { - "agents": "$(ls -1 "$EXPORT_DIR/agents" | wc -l) categories", - "plugins": "$(ls -1 "$EXPORT_DIR/plugins" 2>/dev/null | wc -l) items", - "config_files": "$(ls -1 "$EXPORT_DIR/config" | wc -l) files" - }, - "mcp_tools": [ - "zai-mcp-server (vision)", - "web-search-prime", - "web-reader", - "zread" - ], - "skills": [ - "glm-plan-bug:case-feedback", - "glm-plan-usage:usage-query" - ] -} -EOF - -# Create tarball -log_info "Creating compressed archive..." -tar -czf "$EXPORT_FILE" -C "$HOME" "$(basename "$EXPORT_DIR")" - -# Get file size -FILE_SIZE=$(du -h "$EXPORT_FILE" | cut -f1) - -log_success "═══════════════════════════════════════════════════════════" -log_success "Export completed successfully!" -log_success "═══════════════════════════════════════════════════════════" -echo "" -log_info "Export location: $EXPORT_FILE" -log_info "Package size: $FILE_SIZE" -log_info "Unpacked directory: $EXPORT_DIR" -echo "" -log_info "To transfer to another machine:" -echo " 1. Copy the archive: scp $EXPORT_FILE user@target:~/" -echo " 2. Extract: tar -xzf $(basename "$EXPORT_FILE")" -echo " 3. Run: cd $(basename "$EXPORT_DIR") && bash install-claude-customizations.sh" -echo "" - -# Ask if user wants to keep unpacked directory -read -p "Keep unpacked export directory? (y/N): " keep_unpacked -if [[ ! "$keep_unpacked" =~ ^[Yy]$ ]]; then - rm -rf "$EXPORT_DIR" - log_info "Unpacked directory removed" -fi +#!/usr/bin/env bash +################################################################################ +# Claude Code Customizations Exporter +# This script packages all customizations for transfer to another machine +################################################################################ + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +# Configuration +CLAUDE_DIR="$HOME/.claude" +EXPORT_DIR="$HOME/claude-customizations-export" +EXPORT_FILE="$HOME/claude-customizations-$(date +%Y%m%d_%H%M%S).tar.gz" + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +# Create export directory +log_info "Creating export directory..." +rm -rf "$EXPORT_DIR" +mkdir -p "$EXPORT_DIR" + +# Export agents +log_info "Exporting custom agents..." +mkdir -p "$EXPORT_DIR/agents" +cp -r "$CLAUDE_DIR/agents/"* "$EXPORT_DIR/agents/" 2>/dev/null || true + +# Export plugins configuration +log_info "Exporting plugins configuration..." +mkdir -p "$EXPORT_DIR/plugins" +cp -r "$CLAUDE_DIR/plugins/cache/"* "$EXPORT_DIR/plugins/" 2>/dev/null || true +cp "$CLAUDE_DIR/plugins/installed_plugins.json" "$EXPORT_DIR/plugins/" 2>/dev/null || true +cp "$CLAUDE_DIR/plugins/known_marketplaces.json" "$EXPORT_DIR/plugins/" 2>/dev/null || true + +# Export settings (without sensitive data) +log_info "Exporting settings..." +mkdir -p "$EXPORT_DIR/config" + +# Export settings.local.json (permissions) +cp "$CLAUDE_DIR/settings.local.json" "$EXPORT_DIR/config/" 2>/dev/null || true + +# Create settings template (without actual API token) +cat > "$EXPORT_DIR/config/settings-template.json" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "YOUR_API_TOKEN_HERE", + "ANTHROPIC_BASE_URL": "https://api.anthropic.com", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" + }, + "enabledPlugins": { + "glm-plan-bug@zai-coding-plugins": true, + "glm-plan-usage@zai-coding-plugins": true + } +} +EOF + +# Export hooks if present +log_info "Exporting hooks..." +if [ -d "$CLAUDE_DIR/hooks" ] && [ "$(ls -A $CLAUDE_DIR/hooks)" ]; then + mkdir -p "$EXPORT_DIR/hooks" + cp -r "$CLAUDE_DIR/hooks/"* "$EXPORT_DIR/hooks/" +fi + +# Create README +log_info "Creating documentation..." +cat > "$EXPORT_DIR/README.md" << 'EOF' +# Claude Code Customizations Package + +This package contains all customizations for Claude Code including custom agents, MCP tools configuration, and plugins. + +## Contents + +- `agents/` - Custom agent definitions organized by category +- `plugins/` - Plugin configurations +- `config/` - Settings files +- `hooks/` - Custom hooks (if any) + +## Installation + +### Quick Install + +Run the automated installer: + +```bash +bash install-claude-customizations.sh +``` + +### Manual Install + +1. **Copy agents:** + ```bash + cp -r agents/* ~/.claude/agents/ + ``` + +2. **Copy plugins:** + ```bash + cp -r plugins/* ~/.claude/plugins/ + ``` + +3. **Configure settings:** + ```bash + cp config/settings.local.json ~/.claude/ + # Edit ~/.claude/settings.json and add your API token + ``` + +4. **Install MCP tools:** + ```bash + npm install -g @z_ai/mcp-server @z_ai/coding-helper + ``` + +5. **Restart Claude Code** + +## Agent Categories + +- **Engineering** - AI engineer, backend architect, frontend developer, DevOps, mobile app builder +- **Marketing** - TikTok strategist, growth hacker, content creator +- **Product** - Sprint prioritizer, feedback synthesizer, trend researcher +- **Studio Operations** - Studio producer, project shipper, analytics, finance +- **Project Management** - Experiment tracker, studio coach +- **Testing** - Test writer/fixer, API tester, performance benchmarker +- **Design** - UI designer, UX researcher, brand guardian, whimsy injector +- **Bonus** - Joker, studio coach + +## MCP Tools Included + +- **zai-mcp-server** - Vision analysis (images, videos, UI screenshots, error diagnosis) +- **web-search-prime** - Enhanced web search with domain filtering +- **web-reader** - Fetch URLs and convert to markdown +- **zread** - GitHub repository reader + +## Skills + +- `glm-plan-bug:case-feedback` - Submit bug/issue feedback +- `glm-plan-usage:usage-query` - Query account usage statistics + +## Customization + +Edit agent `.md` files in `~/.claude/agents/` to customize agent behavior. + +## Support + +For issues or questions, refer to the original source machine or Claude Code documentation. +EOF + +# Create manifest +log_info "Creating package manifest..." +cat > "$EXPORT_DIR/MANIFEST.json" << EOF +{ + "package": "claude-code-customizations", + "version": "1.0.0", + "exported_at": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", + "contents": { + "agents": "$(ls -1 "$EXPORT_DIR/agents" | wc -l) categories", + "plugins": "$(ls -1 "$EXPORT_DIR/plugins" 2>/dev/null | wc -l) items", + "config_files": "$(ls -1 "$EXPORT_DIR/config" | wc -l) files" + }, + "mcp_tools": [ + "zai-mcp-server (vision)", + "web-search-prime", + "web-reader", + "zread" + ], + "skills": [ + "glm-plan-bug:case-feedback", + "glm-plan-usage:usage-query" + ] +} +EOF + +# Create tarball +log_info "Creating compressed archive..." +tar -czf "$EXPORT_FILE" -C "$HOME" "$(basename "$EXPORT_DIR")" + +# Get file size +FILE_SIZE=$(du -h "$EXPORT_FILE" | cut -f1) + +log_success "═══════════════════════════════════════════════════════════" +log_success "Export completed successfully!" +log_success "═══════════════════════════════════════════════════════════" +echo "" +log_info "Export location: $EXPORT_FILE" +log_info "Package size: $FILE_SIZE" +log_info "Unpacked directory: $EXPORT_DIR" +echo "" +log_info "To transfer to another machine:" +echo " 1. Copy the archive: scp $EXPORT_FILE user@target:~/" +echo " 2. Extract: tar -xzf $(basename "$EXPORT_FILE")" +echo " 3. Run: cd $(basename "$EXPORT_DIR") && bash install-claude-customizations.sh" +echo "" + +# Ask if user wants to keep unpacked directory +read -p "Keep unpacked export directory? (y/N): " keep_unpacked +if [[ ! "$keep_unpacked" =~ ^[Yy]$ ]]; then + rm -rf "$EXPORT_DIR" + log_info "Unpacked directory removed" +fi diff --git a/agents/install-claude-customizations.sh b/agents/install-claude-customizations.sh index 4d36901..202e65a 100755 --- a/agents/install-claude-customizations.sh +++ b/agents/install-claude-customizations.sh @@ -1,396 +1,396 @@ -#!/usr/bin/env bash -################################################################################ -# Claude Code Customizations Installer -# This script automates the setup of custom agents, MCP tools, and plugins -# for Claude Code on a new machine. -################################################################################ - -set -e # Exit on error - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Configuration -CLAUDE_DIR="$HOME/.claude" -AGENTS_DIR="$CLAUDE_DIR/agents" -PLUGINS_DIR="$CLAUDE_DIR/plugins" -BACKUP_DIR="$HOME/.claude-backup-$(date +%Y%m%d_%H%M%S)" - -################################################################################ -# Helper Functions -################################################################################ - -log_info() { - echo -e "${BLUE}[INFO]${NC} $1" -} - -log_success() { - echo -e "${GREEN}[SUCCESS]${NC} $1" -} - -log_warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -log_error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -check_command() { - if ! command -v $1 &> /dev/null; then - log_error "$1 is not installed. Please install it first." - exit 1 - fi -} - -backup_file() { - local file="$1" - if [ -f "$file" ]; then - mkdir -p "$BACKUP_DIR" - cp "$file" "$BACKUP_DIR/" - log_info "Backed up $file to $BACKUP_DIR" - fi -} - -################################################################################ -# Prerequisites Check -################################################################################ - -check_prerequisites() { - log_info "Checking prerequisites..." - - check_command "node" - check_command "npm" - check_command "python3" - check_command "curl" - - # Check Node.js version (need 14+) - NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) - if [ "$NODE_VERSION" -lt 14 ]; then - log_error "Node.js version 14 or higher required. Current: $(node -v)" - exit 1 - fi - - log_success "Prerequisites check passed" -} - -################################################################################ -# Directory Structure Setup -################################################################################ - -setup_directories() { - log_info "Setting up directory structure..." - - mkdir -p "$AGENTS_DIR"/{engineering,marketing,product,studio-operations,project-management,testing,design,bonus} - - mkdir -p "$PLUGINS_DIR"/{cache,marketplaces} - mkdir -p "$CLAUDE_DIR"/{hooks,debug,file-history,paste-cache,projects,session-env,shell-snapshots,todos} - - log_success "Directory structure created" -} - -################################################################################ -# Settings Configuration -################################################################################ - -setup_settings() { - log_info "Configuring Claude Code settings..." - - local settings_file="$CLAUDE_DIR/settings.json" - - backup_file "$settings_file" - - # Prompt for API credentials - read -p "Enter your ANTHROPIC_AUTH_TOKEN (or press Enter to skip): " API_TOKEN - read -p "Enter your ANTHROPIC_BASE_URL (default: https://api.anthropic.com): " API_BASE - API_BASE=${API_BASE:-https://api.anthropic.com} - - # Create settings.json - cat > "$settings_file" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "${API_TOKEN}", - "ANTHROPIC_BASE_URL": "${API_BASE}", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" - }, - "enabledPlugins": { - "glm-plan-bug@zai-coding-plugins": true, - "glm-plan-usage@zai-coding-plugins": true - } -} -EOF - - # Create local settings for permissions - local local_settings="$CLAUDE_DIR/settings.local.json" - backup_file "$local_settings" - - cat > "$local_settings" << EOF -{ - "permissions": { - "allow": [ - "Bash(npm install:*)", - "Bash(npm run content:*)", - "Bash(npm run build:*)", - "Bash(grep:*)", - "Bash(find:*)", - "Bash(for:*)", - "Bash(do sed:*)", - "Bash(done)", - "Bash(python3:*)", - "Bash(while read f)", - "Bash(do echo \\"\\$f%-* \\$f\\")", - "Bash(ls:*)", - "Bash(node:*)", - "Bash(pm2 delete:*)", - "Bash(pm2 start npm:*)", - "Bash(pm2 save:*)" - ] - } -} -EOF - - log_success "Settings configured" -} - -################################################################################ -# MCP Services Installation -################################################################################ - -install_mcp_services() { - log_info "Installing MCP services..." - - # Install @z_ai/mcp-server globally for vision tools - log_info "Installing @z_ai/mcp-server (vision analysis tools)..." - npm install -g @z_ai/mcp-server 2>/dev/null || { - log_warning "Global install failed, trying with npx..." - # It's okay if this fails, the tools will use npx - } - - # Install @z_ai/coding-helper for MCP management - log_info "Installing @z_ai/coding-helper..." - npm install -g @z_ai/coding-helper 2>/dev/null || { - log_warning "Global install failed, will use npx" - } - - log_success "MCP services installation completed" -} - -################################################################################ -# Agent Definitions -################################################################################ - -install_agents() { - log_info "Installing custom agents..." - - # Note: In a production setup, these would be downloaded from a repository - # For now, we'll create placeholder agent definitions - # The actual agent content should be copied from the source machine - - log_info "Agent directory structure created at $AGENTS_DIR" - log_warning "NOTE: You need to copy the actual agent .md files from the source machine" - log_info "Run: scp -r user@source:~/.claude/agents/* $AGENTS_DIR/" - - log_success "Agent structure ready" -} - -################################################################################ -# Plugins Installation -################################################################################ - -install_plugins() { - log_info "Installing Claude Code plugins..." - - # Initialize plugin registry - local installed_plugins="$PLUGINS_DIR/installed_plugins.json" - local known_marketplaces="$PLUGINS_DIR/known_marketplaces.json" - - backup_file "$installed_plugins" - backup_file "$known_marketplaces" - - cat > "$known_marketplaces" << EOF -{ - "marketplaces": { - "https://github.com/anthropics/claude-plugins": { - "displayName": "Official Claude Plugins", - "contact": "support@anthropic.com" - } - } -} -EOF - - # Install GLM plugins via npx - log_info "Installing GLM Coding Plan plugins..." - - # Create plugin cache structure - mkdir -p "$PLUGINS_DIR/cache/zai-coding-plugins"/{glm-plan-bug,glm-plan-usage} - - # Note: Actual plugin installation happens via the @z_ai/coding-helper - # which should already be installed - - cat > "$installed_plugins" << EOF -{ - "version": 2, - "plugins": { - "glm-plan-bug@zai-coding-plugins": [ - { - "scope": "user", - "installPath": "$PLUGINS_DIR/cache/zai-coding-plugins/glm-plan-bug/0.0.1", - "version": "0.0.1", - "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", - "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" - } - ], - "glm-plan-usage@zai-coding-plugins": [ - { - "scope": "user", - "installPath": "$PLUGINS_DIR/cache/zai-coding-plugins/glm-plan-usage/0.0.1", - "version": "0.0.1", - "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", - "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" - } - ] - } -} -EOF - - log_success "Plugins configured" -} - -################################################################################ -# Download Agents from Repository -################################################################################ - -download_agent_definitions() { - log_info "Preparing to download agent definitions..." - - # Create a temporary script to download agents - # In production, this would download from a git repository or CDN - - cat > /tmp/download_agents.sh << 'DOWNLOAD_SCRIPT' -#!/bin/bash -# This script would download agent definitions from a central repository -# For now, it creates a template structure - -AGENT_CATEGORIES=("engineering" "marketing" "product" "studio-operations" "project-management" "testing" "design" "bonus") - -for category in "${AGENT_CATEGORIES[@]}"; do - echo "Category: $category" - # Agents would be downloaded here -done -DOWNLOAD_SCRIPT - - chmod +x /tmp/download_agents.sh - - log_info "Agent download script created at /tmp/download_agents.sh" - log_warning "You need to provide the actual agent definitions" -} - -################################################################################ -# Verification -################################################################################ - -verify_installation() { - log_info "Verifying installation..." - - local errors=0 - - # Check directories - [ -d "$CLAUDE_DIR" ] || { log_error "Claude directory missing"; errors=$((errors+1)); } - [ -d "$AGENTS_DIR" ] || { log_error "Agents directory missing"; errors=$((errors+1)); } - [ -d "$PLUGINS_DIR" ] || { log_error "Plugins directory missing"; errors=$((errors+1)); } - - # Check files - [ -f "$CLAUDE_DIR/settings.json" ] || { log_error "settings.json missing"; errors=$((errors+1)); } - [ -f "$CLAUDE_DIR/settings.local.json" ] || { log_error "settings.local.json missing"; errors=$((errors+1)); } - [ -f "$PLUGINS_DIR/installed_plugins.json" ] || { log_error "installed_plugins.json missing"; errors=$((errors+1)); } - - # Check MCP availability - if command -v npx &> /dev/null; then - log_success "npx available for MCP tools" - else - log_error "npx not available" - errors=$((errors+1)) - fi - - if [ $errors -eq 0 ]; then - log_success "Installation verification passed" - return 0 - else - log_error "Installation verification failed with $errors errors" - return 1 - fi -} - -################################################################################ -# Main Installation Flow -################################################################################ - -main() { - echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" - echo -e "${BLUE}║ Claude Code Customizations - Automated Installer ║${NC}" - echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" - echo "" - - # Parse command line arguments - SKIP_AGENTS_COPY=false - while [[ $# -gt 0 ]]; do - case $1 in - --skip-agents) - SKIP_AGENTS_COPY=true - shift - ;; - --help) - echo "Usage: $0 [OPTIONS]" - echo "" - echo "Options:" - echo " --skip-agents Skip copying agent files (if already present)" - echo " --help Show this help message" - echo "" - exit 0 - ;; - *) - log_error "Unknown option: $1" - echo "Use --help for usage information" - exit 1 - ;; - esac - done - - # Run installation steps - check_prerequisites - setup_directories - setup_settings - install_mcp_services - install_agents - install_plugins - - # Verify installation - if verify_installation; then - echo "" - log_success "═══════════════════════════════════════════════════════════" - log_success "Installation completed successfully!" - log_success "═══════════════════════════════════════════════════════════" - echo "" - log_info "Next steps:" - echo " 1. Copy agent definitions from source machine:" - echo " scp -r user@source:~/.claude/agents/* $AGENTS_DIR/" - echo "" - echo " 2. Restart Claude Code to load all customizations" - echo "" - echo " 3. Verify MCP tools are working by starting a new session" - echo "" - echo "Backup location: $BACKUP_DIR" - echo "" - else - log_error "Installation failed. Please check the errors above." - exit 1 - fi -} - -# Run main function -main "$@" +#!/usr/bin/env bash +################################################################################ +# Claude Code Customizations Installer +# This script automates the setup of custom agents, MCP tools, and plugins +# for Claude Code on a new machine. +################################################################################ + +set -e # Exit on error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Configuration +CLAUDE_DIR="$HOME/.claude" +AGENTS_DIR="$CLAUDE_DIR/agents" +PLUGINS_DIR="$CLAUDE_DIR/plugins" +BACKUP_DIR="$HOME/.claude-backup-$(date +%Y%m%d_%H%M%S)" + +################################################################################ +# Helper Functions +################################################################################ + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +check_command() { + if ! command -v $1 &> /dev/null; then + log_error "$1 is not installed. Please install it first." + exit 1 + fi +} + +backup_file() { + local file="$1" + if [ -f "$file" ]; then + mkdir -p "$BACKUP_DIR" + cp "$file" "$BACKUP_DIR/" + log_info "Backed up $file to $BACKUP_DIR" + fi +} + +################################################################################ +# Prerequisites Check +################################################################################ + +check_prerequisites() { + log_info "Checking prerequisites..." + + check_command "node" + check_command "npm" + check_command "python3" + check_command "curl" + + # Check Node.js version (need 14+) + NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) + if [ "$NODE_VERSION" -lt 14 ]; then + log_error "Node.js version 14 or higher required. Current: $(node -v)" + exit 1 + fi + + log_success "Prerequisites check passed" +} + +################################################################################ +# Directory Structure Setup +################################################################################ + +setup_directories() { + log_info "Setting up directory structure..." + + mkdir -p "$AGENTS_DIR"/{engineering,marketing,product,studio-operations,project-management,testing,design,bonus} + + mkdir -p "$PLUGINS_DIR"/{cache,marketplaces} + mkdir -p "$CLAUDE_DIR"/{hooks,debug,file-history,paste-cache,projects,session-env,shell-snapshots,todos} + + log_success "Directory structure created" +} + +################################################################################ +# Settings Configuration +################################################################################ + +setup_settings() { + log_info "Configuring Claude Code settings..." + + local settings_file="$CLAUDE_DIR/settings.json" + + backup_file "$settings_file" + + # Prompt for API credentials + read -p "Enter your ANTHROPIC_AUTH_TOKEN (or press Enter to skip): " API_TOKEN + read -p "Enter your ANTHROPIC_BASE_URL (default: https://api.anthropic.com): " API_BASE + API_BASE=${API_BASE:-https://api.anthropic.com} + + # Create settings.json + cat > "$settings_file" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "${API_TOKEN}", + "ANTHROPIC_BASE_URL": "${API_BASE}", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" + }, + "enabledPlugins": { + "glm-plan-bug@zai-coding-plugins": true, + "glm-plan-usage@zai-coding-plugins": true + } +} +EOF + + # Create local settings for permissions + local local_settings="$CLAUDE_DIR/settings.local.json" + backup_file "$local_settings" + + cat > "$local_settings" << EOF +{ + "permissions": { + "allow": [ + "Bash(npm install:*)", + "Bash(npm run content:*)", + "Bash(npm run build:*)", + "Bash(grep:*)", + "Bash(find:*)", + "Bash(for:*)", + "Bash(do sed:*)", + "Bash(done)", + "Bash(python3:*)", + "Bash(while read f)", + "Bash(do echo \\"\\$f%-* \\$f\\")", + "Bash(ls:*)", + "Bash(node:*)", + "Bash(pm2 delete:*)", + "Bash(pm2 start npm:*)", + "Bash(pm2 save:*)" + ] + } +} +EOF + + log_success "Settings configured" +} + +################################################################################ +# MCP Services Installation +################################################################################ + +install_mcp_services() { + log_info "Installing MCP services..." + + # Install @z_ai/mcp-server globally for vision tools + log_info "Installing @z_ai/mcp-server (vision analysis tools)..." + npm install -g @z_ai/mcp-server 2>/dev/null || { + log_warning "Global install failed, trying with npx..." + # It's okay if this fails, the tools will use npx + } + + # Install @z_ai/coding-helper for MCP management + log_info "Installing @z_ai/coding-helper..." + npm install -g @z_ai/coding-helper 2>/dev/null || { + log_warning "Global install failed, will use npx" + } + + log_success "MCP services installation completed" +} + +################################################################################ +# Agent Definitions +################################################################################ + +install_agents() { + log_info "Installing custom agents..." + + # Note: In a production setup, these would be downloaded from a repository + # For now, we'll create placeholder agent definitions + # The actual agent content should be copied from the source machine + + log_info "Agent directory structure created at $AGENTS_DIR" + log_warning "NOTE: You need to copy the actual agent .md files from the source machine" + log_info "Run: scp -r user@source:~/.claude/agents/* $AGENTS_DIR/" + + log_success "Agent structure ready" +} + +################################################################################ +# Plugins Installation +################################################################################ + +install_plugins() { + log_info "Installing Claude Code plugins..." + + # Initialize plugin registry + local installed_plugins="$PLUGINS_DIR/installed_plugins.json" + local known_marketplaces="$PLUGINS_DIR/known_marketplaces.json" + + backup_file "$installed_plugins" + backup_file "$known_marketplaces" + + cat > "$known_marketplaces" << EOF +{ + "marketplaces": { + "https://github.com/anthropics/claude-plugins": { + "displayName": "Official Claude Plugins", + "contact": "support@anthropic.com" + } + } +} +EOF + + # Install GLM plugins via npx + log_info "Installing GLM Coding Plan plugins..." + + # Create plugin cache structure + mkdir -p "$PLUGINS_DIR/cache/zai-coding-plugins"/{glm-plan-bug,glm-plan-usage} + + # Note: Actual plugin installation happens via the @z_ai/coding-helper + # which should already be installed + + cat > "$installed_plugins" << EOF +{ + "version": 2, + "plugins": { + "glm-plan-bug@zai-coding-plugins": [ + { + "scope": "user", + "installPath": "$PLUGINS_DIR/cache/zai-coding-plugins/glm-plan-bug/0.0.1", + "version": "0.0.1", + "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", + "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" + } + ], + "glm-plan-usage@zai-coding-plugins": [ + { + "scope": "user", + "installPath": "$PLUGINS_DIR/cache/zai-coding-plugins/glm-plan-usage/0.0.1", + "version": "0.0.1", + "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", + "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" + } + ] + } +} +EOF + + log_success "Plugins configured" +} + +################################################################################ +# Download Agents from Repository +################################################################################ + +download_agent_definitions() { + log_info "Preparing to download agent definitions..." + + # Create a temporary script to download agents + # In production, this would download from a git repository or CDN + + cat > /tmp/download_agents.sh << 'DOWNLOAD_SCRIPT' +#!/bin/bash +# This script would download agent definitions from a central repository +# For now, it creates a template structure + +AGENT_CATEGORIES=("engineering" "marketing" "product" "studio-operations" "project-management" "testing" "design" "bonus") + +for category in "${AGENT_CATEGORIES[@]}"; do + echo "Category: $category" + # Agents would be downloaded here +done +DOWNLOAD_SCRIPT + + chmod +x /tmp/download_agents.sh + + log_info "Agent download script created at /tmp/download_agents.sh" + log_warning "You need to provide the actual agent definitions" +} + +################################################################################ +# Verification +################################################################################ + +verify_installation() { + log_info "Verifying installation..." + + local errors=0 + + # Check directories + [ -d "$CLAUDE_DIR" ] || { log_error "Claude directory missing"; errors=$((errors+1)); } + [ -d "$AGENTS_DIR" ] || { log_error "Agents directory missing"; errors=$((errors+1)); } + [ -d "$PLUGINS_DIR" ] || { log_error "Plugins directory missing"; errors=$((errors+1)); } + + # Check files + [ -f "$CLAUDE_DIR/settings.json" ] || { log_error "settings.json missing"; errors=$((errors+1)); } + [ -f "$CLAUDE_DIR/settings.local.json" ] || { log_error "settings.local.json missing"; errors=$((errors+1)); } + [ -f "$PLUGINS_DIR/installed_plugins.json" ] || { log_error "installed_plugins.json missing"; errors=$((errors+1)); } + + # Check MCP availability + if command -v npx &> /dev/null; then + log_success "npx available for MCP tools" + else + log_error "npx not available" + errors=$((errors+1)) + fi + + if [ $errors -eq 0 ]; then + log_success "Installation verification passed" + return 0 + else + log_error "Installation verification failed with $errors errors" + return 1 + fi +} + +################################################################################ +# Main Installation Flow +################################################################################ + +main() { + echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" + echo -e "${BLUE}║ Claude Code Customizations - Automated Installer ║${NC}" + echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" + echo "" + + # Parse command line arguments + SKIP_AGENTS_COPY=false + while [[ $# -gt 0 ]]; do + case $1 in + --skip-agents) + SKIP_AGENTS_COPY=true + shift + ;; + --help) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --skip-agents Skip copying agent files (if already present)" + echo " --help Show this help message" + echo "" + exit 0 + ;; + *) + log_error "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac + done + + # Run installation steps + check_prerequisites + setup_directories + setup_settings + install_mcp_services + install_agents + install_plugins + + # Verify installation + if verify_installation; then + echo "" + log_success "═══════════════════════════════════════════════════════════" + log_success "Installation completed successfully!" + log_success "═══════════════════════════════════════════════════════════" + echo "" + log_info "Next steps:" + echo " 1. Copy agent definitions from source machine:" + echo " scp -r user@source:~/.claude/agents/* $AGENTS_DIR/" + echo "" + echo " 2. Restart Claude Code to load all customizations" + echo "" + echo " 3. Verify MCP tools are working by starting a new session" + echo "" + echo "Backup location: $BACKUP_DIR" + echo "" + else + log_error "Installation failed. Please check the errors above." + exit 1 + fi +} + +# Run main function +main "$@" diff --git a/agents/interactive-install-claude.sh b/agents/interactive-install-claude.sh index 46d5d59..d305173 100755 --- a/agents/interactive-install-claude.sh +++ b/agents/interactive-install-claude.sh @@ -1,1170 +1,1170 @@ -#!/usr/bin/env bash -################################################################################ -# Claude Code Customizations - Interactive Installer -# Step-by-step installation with user choices for each component -################################################################################ - -set -e - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -CYAN='\033[0;36m' -BOLD='\033[1m' -NC='\033[0m' - -# Configuration -CLAUDE_DIR="$HOME/.claude" -BACKUP_DIR="$HOME/.claude-backup-$(date +%Y%m%d_%H%M%S)" -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# User choices -USE_ZAI_MODELS=false -INSTALL_AGENTS=true -INSTALL_ENGINEERING=true -INSTALL_MARKETING=true -INSTALL_PRODUCT=true -INSTALL_STUDIO_OPS=true -INSTALL_PROJECT_MGMT=true -INSTALL_TESTING=true -INSTALL_DESIGN=true -INSTALL_BONUS=true -INSTALL_MCP_TOOLS=true -INSTALL_VISION_TOOLS=true -INSTALL_WEB_TOOLS=true -INSTALL_GITHUB_TOOLS=true -INSTALL_TLDR=true -INSTALL_PLUGINS=true -INSTALL_HOOKS=true -LAUNCH_CLAUDE=false - -# Counters -SELECTED_AGENTS=0 -SELECTED_MCP_TOOLS=0 - -################################################################################ -# Helper Functions -################################################################################ - -log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } -log_success() { echo -e "${GREEN}[✓]${NC} $1"; } -log_warning() { echo -e "${YELLOW}[!]${NC} $1"; } -log_error() { echo -e "${RED}[✗]${NC} $1"; } - -print_header() { - clear - echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════╗${NC}" - echo -e "${CYAN}║${NC} ${BOLD}Claude Code Customizations - Interactive Installer${NC} ${CYAN}║${NC}" - echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════╝${NC}" - echo "" -} - -confirm() { - local prompt="$1" - local default="$2" - - if [ "$default" = "Y" ]; then - prompt="$prompt [Y/n]: " - else - prompt="$prompt [y/N]: " - fi - - read -p "$prompt" response - - if [ -z "$response" ]; then - if [ "$default" = "Y" ]; then - return 0 - else - return 1 - fi - fi - - [[ "$response" =~ ^[Yy]$ ]] -} - -select_multiple() { - local title="$1" - shift - local options=("$@") - - echo "" - echo -e "${BOLD}$title${NC}" - echo "─────────────────────────────────────────────────────────────" - echo "" - - local i=1 - for opt in "${options[@]}"; do - echo " $i) $opt" - i=$((i+1)) - done - echo " a) All" - echo " n) None" - echo "" - - while true; do - read -p "Select options (comma-separated, a=n): " selection - - if [[ "$selection" =~ ^[Aa]$ ]]; then - return 0 # All - elif [[ "$selection" =~ ^[Nn]$ ]]; then - return 1 # None - else - return 0 # Has selections - fi - done -} - -################################################################################ -# Welcome Screen -################################################################################ - -show_welcome() { - print_header - echo -e "${BOLD}Welcome to Claude Code Customizations Installer!${NC}" - echo "" - echo "This installer will guide you through setting up a customized" - echo "Claude Code environment with:" - echo "" - echo " • 40+ specialized agents for development, marketing, and operations" - echo " • MCP tools for vision analysis, web search, and GitHub integration" - echo " • Custom skills and plugins" - echo " • Optimized workflows for rapid 6-day development cycles" - echo "" - echo -e "${YELLOW}Note:${NC} You can choose what to install at each step." - echo "" - - if ! confirm "Continue with installation?" "Y"; then - echo "Installation cancelled." - exit 0 - fi -} - -################################################################################ -# Model Selection -################################################################################ - -select_model() { - print_header - echo -e "${BOLD}Step 1: Model Selection${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "Choose which API models to use with Claude Code:" - echo "" - echo -e " ${GREEN}1${NC}) ${BOLD}Anthropic Claude Models${NC} (official)" - echo " • claude-sonnet-4.5, claude-opus-4.5, etc." - echo " • Direct Anthropic API" - echo " • Base URL: https://api.anthropic.com" - echo "" - echo -e " ${CYAN}2${NC}) ${BOLD}Z.AI / GLM Coding Plan Models${NC}" - echo " • Same Claude models via Z.AI platform" - echo " • Additional features: usage tracking, feedback, promotions" - echo " • Base URL: https://api.z.ai/api/anthropic" - echo " • Includes: 旺仔牛奶 rewards program" - echo "" - read -p "Select model provider [1/2]: " model_choice - - case $model_choice in - 2) - USE_ZAI_MODELS=true - log_success "Selected: Z.AI / GLM Coding Plan Models" - ;; - *) - USE_ZAI_MODELS=false - log_success "Selected: Anthropic Claude Models (official)" - ;; - esac - - echo "" -} - -################################################################################ -# Agent Selection -################################################################################ - -select_agents() { - print_header - echo -e "${BOLD}Step 2: Agent Categories${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "Custom agents provide specialized assistance for different tasks." - echo "Select which categories to install:" - echo "" - - if confirm "Install Engineering agents? (AI engineer, frontend/backend dev, DevOps, mobile, rapid prototyper, test writer)" "Y"; then - INSTALL_ENGINEERING=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 7)) - else - INSTALL_ENGINEERING=false - fi - - if confirm "Install Marketing agents? (TikTok strategist, growth hacker, content creator, Instagram/Reddit/Twitter)" "Y"; then - INSTALL_MARKETING=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 7)) - else - INSTALL_MARKETING=false - fi - - if confirm "Install Product agents? (Sprint prioritizer, feedback synthesizer, trend researcher)" "Y"; then - INSTALL_PRODUCT=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 3)) - else - INSTALL_PRODUCT=false - fi - - if confirm "Install Studio Operations agents? (Studio producer, project shipper, analytics, finance, legal, support, coach)" "Y"; then - INSTALL_STUDIO_OPS=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 8)) - else - INSTALL_STUDIO_OPS=false - fi - - if confirm "Install Project Management agents? (Experiment tracker, studio producer, project shipper)" "Y"; then - INSTALL_PROJECT_MGMT=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 3)) - else - INSTALL_PROJECT_MGMT=false - fi - - if confirm "Install Testing agents? (Test writer/fixer, API tester, performance benchmarker, workflow optimizer)" "Y"; then - INSTALL_TESTING=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 5)) - else - INSTALL_TESTING=false - fi - - if confirm "Install Design agents? (UI/UX designer, brand guardian, visual storyteller, whimsy injector)" "Y"; then - INSTALL_DESIGN=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 5)) - else - INSTALL_DESIGN=false - fi - - if confirm "Install Bonus agents? (Joker, studio coach)" "Y"; then - INSTALL_BONUS=true - SELECTED_AGENTS=$((SELECTED_AGENTS + 2)) - else - INSTALL_BONUS=false - fi - - if [ $SELECTED_AGENTS -eq 0 ]; then - log_warning "No agents selected - you can add them later manually" - else - log_success "Selected $SELECTED_AGENTS agents across multiple categories" - fi - - echo "" -} - -################################################################################ -# MCP Tools Selection -################################################################################ - -select_mcp_tools() { - print_header - echo -e "${BOLD}Step 3: MCP Tools${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "MCP (Model Context Protocol) tools provide advanced capabilities." - echo "Select which tools to install:" - echo "" - - if confirm "Install Vision Analysis tools? (images, videos, UI screenshots, error diagnosis, data visualization, diagrams)" "Y"; then - INSTALL_VISION_TOOLS=true - SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 8)) - else - INSTALL_VISION_TOOLS=false - fi - - if confirm "Install Web Search tool? (enhanced search with domain filtering, time-based results)" "Y"; then - INSTALL_WEB_TOOLS=true - SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 1)) - else - INSTALL_WEB_TOOLS=false - fi - - if confirm "Install Web Reader tool? (fetch URLs, convert to markdown)" "Y"; then - INSTALL_WEB_TOOLS=true - SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 1)) - fi - - if confirm "Install GitHub Reader tool? (read repos, search docs/issues/commits)" "Y"; then - INSTALL_GITHUB_TOOLS=true - SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 3)) - else - INSTALL_GITHUB_TOOLS=false - fi - - if command -v python3 &> /dev/null && command -v pip3 &> /dev/null; then - if confirm "Install TLDR Code Analysis? (95% token reduction, semantic search, program slicing - requires Python)" "Y"; then - INSTALL_TLDR=true - SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 18)) - else - INSTALL_TLDR=false - fi - else - log_warning "Python/pip3 not found - skipping TLDR Code Analysis" - INSTALL_TLDR=false - fi - - if [ $SELECTED_MCP_TOOLS -eq 0 ]; then - log_warning "No MCP tools selected" - else - log_success "Selected $SELECTED_MCP_TOOLS MCP tools" - fi - - INSTALL_MCP_TOOLS=true - echo "" -} - -################################################################################ -# Plugins Selection -################################################################################ - -select_plugins() { - print_header - echo -e "${BOLD}Step 4: Plugins & Skills${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "Plugins extend Claude Code with additional features:" - echo "" - echo " • glm-plan-bug: Submit bug/issue feedback to Z.AI" - echo " • glm-plan-usage: Query your GLM Coding Plan usage statistics" - echo "" - - if confirm "Install Z.AI plugins?" "Y"; then - INSTALL_PLUGINS=true - log_success "Plugins selected" - else - INSTALL_PLUGINS=false - log_warning "Plugins skipped" - fi - - echo "" -} - -################################################################################ -# Hooks Selection -################################################################################ - -select_hooks() { - print_header - echo -e "${BOLD}Step 5: Hooks${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - echo "Hooks are scripts that run automatically on specific events." - echo "Do you want to copy existing hooks from the package?" - echo "" - - if confirm "Install hooks?" "N"; then - INSTALL_HOOKS=true - log_success "Hooks selected" - else - INSTALL_HOOKS=false - log_warning "Hooks skipped" - fi - - echo "" -} - -################################################################################ -# Prerequisites Check -################################################################################ - -check_prerequisites() { - print_header - echo -e "${BOLD}Step 6: Prerequisites Check${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - local errors=0 - - # Check Node.js - if command -v node &> /dev/null; then - NODE_VERSION=$(node -v) - log_success "Node.js installed: $NODE_VERSION" - else - log_error "Node.js not found" - errors=$((errors+1)) - fi - - # Check npm - if command -v npm &> /dev/null; then - NPM_VERSION=$(npm -v) - log_success "npm installed: $NPM_VERSION" - else - log_error "npm not found" - errors=$((errors+1)) - fi - - # Check python3 - if command -v python3 &> /dev/null; then - PYTHON_VERSION=$(python3 --version) - log_success "Python installed: $PYTHON_VERSION" - else - log_warning "Python3 not found (optional)" - fi - - # Check npx - if command -v npx &> /dev/null; then - log_success "npx available" - else - log_warning "npx not found (will be installed with npm)" - fi - - echo "" - - if [ $errors -gt 0 ]; then - log_error "Some prerequisites are missing. Please install them and try again." - echo "" - echo "Install Node.js: https://nodejs.org/" - echo "Or use nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash" - echo "" - exit 1 - fi - - log_success "Prerequisites check passed" - echo "" - sleep 1 -} - -################################################################################ -# Claude Code Installation -################################################################################ - -install_claude_code() { - print_header - echo -e "${BOLD}Step 7: Claude Code Installation${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - # Check if Claude Code is installed - if command -v claude-code &> /dev/null; then - log_success "Claude Code is already installed" - claude-code --version 2>/dev/null || log_info "Version: unknown" - echo "" - return - fi - - echo -e "${YELLOW}Claude Code is not installed on this system.${NC}" - echo "" - echo "Claude Code is Anthropic's official CLI for Claude." - echo "You need it to use these customizations." - echo "" - echo "Installation options:" - echo "" - echo -e " ${GREEN}1${NC}) ${BOLD}Install via npm (recommended)${NC}" - echo " • Requires Node.js 14+" - echo " • Command: npm install -g @anthropic-ai/claude-code" - echo " • Fastest method" - echo "" - echo -e " ${GREEN}2${NC}) ${BOLD}Install via curl (alternative)${NC}" - echo " • Downloads standalone binary" - echo " • No Node.js required" - echo "" - echo -e " ${GREEN}3${NC}) ${BOLD}Manual installation${NC}" - echo " • Visit: https://claude.ai/download" - echo " • Choose your platform" - echo "" - echo -e " ${YELLOW}0${NC}) Skip installation" - echo "" - read -p "Select installation method [1/2/3/0]: " install_choice - - case $install_choice in - 1) - echo "" - log_info "Installing Claude Code via npm..." - echo "" - - if command -v npm &> /dev/null; then - npm install -g @anthropic-ai/claude-code - - if command -v claude-code &> /dev/null; then - log_success "Claude Code installed successfully!" - echo "" - claude-code --version 2>/dev/null || true - else - log_error "Installation failed. Please try manual installation." - fi - else - log_error "npm not found. Please install Node.js first." - echo "Visit: https://nodejs.org/" - fi - ;; - 2) - echo "" - log_info "Installing Claude Code via curl..." - echo "" - - if command -v curl &> /dev/null; then - # Detect OS and architecture - OS="$(uname -s)" - ARCH="$(uname -m)" - - case "$OS" in - Linux) - if [ "$ARCH" = "x86_64" ]; then - curl -L https://claude.ai/download/claude-code-linux -o /tmp/claude-code - sudo mv /tmp/claude-code /usr/local/bin/claude-code - sudo chmod +x /usr/local/bin/claude-code - log_success "Claude Code installed!" - else - log_error "Unsupported architecture: $ARCH" - fi - ;; - Darwin) - if [ "$ARCH" = "arm64" ]; then - curl -L https://claude.ai/download/claude-code-mac-arm -o /tmp/claude-code - else - curl -L https://claude.ai/download/claude-code-mac -o /tmp/claude-code - fi - sudo mv /tmp/claude-code /usr/local/bin/claude-code - sudo chmod +x /usr/local/bin/claude-code - log_success "Claude Code installed!" - ;; - *) - log_error "Unsupported OS: $OS" - ;; - esac - else - log_error "curl not found. Please install curl or use npm method." - fi - ;; - 3) - echo "" - log_info "Please visit https://claude.ai/download to install Claude Code manually" - echo "" - echo "After installation, run this script again." - echo "" - exit 0 - ;; - 0) - log_warning "Skipping Claude Code installation" - log_warning "You will need to install it manually to use these customizations" - ;; - *) - log_error "Invalid choice" - ;; - esac - - echo "" - sleep 2 -} - -################################################################################ -# Backup Existing Configuration -################################################################################ - -backup_config() { - if [ -d "$CLAUDE_DIR" ]; then - print_header - echo -e "${BOLD}Step 8: Backup${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - log_info "Existing Claude Code configuration found" - log_info "Creating backup at: $BACKUP_DIR" - echo "" - - cp -r "$CLAUDE_DIR" "$BACKUP_DIR" - log_success "Backup created successfully" - echo "" - sleep 1 - fi -} - -################################################################################ -# Installation -################################################################################ - -create_directories() { - log_info "Creating directory structure..." - - mkdir -p "$CLAUDE_DIR"/{agents,plugins/cache,plugins/marketplaces,hooks,debug,file-history,paste-cache,projects,session-env,shell-snapshots,todos} - - if [ "$INSTALL_ENGINEERING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/engineering"; fi - if [ "$INSTALL_MARKETING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/marketing"; fi - if [ "$INSTALL_PRODUCT" = true ]; then mkdir -p "$CLAUDE_DIR/agents/product"; fi - if [ "$INSTALL_STUDIO_OPS" = true ]; then mkdir -p "$CLAUDE_DIR/agents/studio-operations"; fi - if [ "$INSTALL_PROJECT_MGMT" = true ]; then mkdir -p "$CLAUDE_DIR/agents/project-management"; fi - if [ "$INSTALL_TESTING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/testing"; fi - if [ "$INSTALL_DESIGN" = true ]; then mkdir -p "$CLAUDE_DIR/agents/design"; fi - if [ "$INSTALL_BONUS" = true ]; then mkdir -p "$CLAUDE_DIR/agents/bonus"; fi - - log_success "Directories created" -} - -install_agents() { - if [ $SELECTED_AGENTS -eq 0 ]; then - return - fi - - log_info "Installing agents..." - - local source_agents="$SCRIPT_DIR/claude-complete-package/agents" - - if [ ! -d "$source_agents" ]; then - log_warning "Agent source directory not found at $source_agents" - log_warning "Please ensure you're running this from the correct location" - return - fi - - if [ "$INSTALL_ENGINEERING" = true ]; then - cp -r "$source_agents/engineering/"*.md "$CLAUDE_DIR/agents/engineering/" 2>/dev/null || true - fi - - if [ "$INSTALL_MARKETING" = true ]; then - cp -r "$source_agents/marketing/"*.md "$CLAUDE_DIR/agents/marketing/" 2>/dev/null || true - fi - - if [ "$INSTALL_PRODUCT" = true ]; then - cp -r "$source_agents/product/"*.md "$CLAUDE_DIR/agents/product/" 2>/dev/null || true - fi - - if [ "$INSTALL_STUDIO_OPS" = true ]; then - cp -r "$source_agents/studio-operations/"*.md "$CLAUDE_DIR/agents/studio-operations/" 2>/dev/null || true - fi - - if [ "$INSTALL_PROJECT_MGMT" = true ]; then - cp -r "$source_agents/project-management/"*.md "$CLAUDE_DIR/agents/project-management/" 2>/dev/null || true - fi - - if [ "$INSTALL_TESTING" = true ]; then - cp -r "$source_agents/testing/"*.md "$CLAUDE_DIR/agents/testing/" 2>/dev/null || true - fi - - if [ "$INSTALL_DESIGN" = true ]; then - cp -r "$source_agents/design/"*.md "$CLAUDE_DIR/agents/design/" 2>/dev/null || true - fi - - # Install ui-ux-pro-max agent (additional design agent) - if [ "$INSTALL_DESIGN" = true ]; then - log_info "Installing ui-ux-pro-max design agent..." - # Check if ui-ux-pro-max exists in the repository - if [ -f "$SCRIPT_DIR/agents/design/ui-ux-pro-max.md" ]; then - cp "$SCRIPT_DIR/agents/design/ui-ux-pro-max.md" "$CLAUDE_DIR/agents/design/" 2>/dev/null || true - log_success "ui-ux-pro-max agent installed" - else - # Download from repository - log_info "Downloading ui-ux-pro-max agent from repository..." - wget -q -O "$CLAUDE_DIR/agents/design/ui-ux-pro-max.md" \ - "https://raw.githubusercontent.com/github.rommark.dev/admin/claude-code-glm-suite/main/agents/design/ui-ux-pro-max.md" 2>/dev/null || { - log_warning "Failed to download ui-ux-pro-max agent" - } - fi - fi - - if [ "$INSTALL_BONUS" = true ]; then - cp -r "$source_agents/bonus/"*.md "$CLAUDE_DIR/agents/bonus/" 2>/dev/null || true - fi - - log_success "Agents installed: $SELECTED_AGENTS" -} - -install_settings() { - log_info "Configuring settings..." - - local settings_file="$CLAUDE_DIR/settings.json" - - # Determine API base URL and help text - if [ "$USE_ZAI_MODELS" = true ]; then - API_BASE="https://api.z.ai/api/anthropic" - API_NAME="Z.AI / GLM Coding Plan" - API_HELP="Get your API key from: https://z.ai/ (Official docs: https://docs.z.ai/devpack/tool/claude)" - API_TOKEN_NAME="Z.AI API Key" - else - API_BASE="https://api.anthropic.com" - API_NAME="Anthropic Claude" - API_HELP="Get your API key from: https://console.anthropic.com/" - API_TOKEN_NAME="Anthropic API Key" - fi - - echo "" - echo -e "${CYAN}API Configuration${NC}" - echo "─────────────────────────────────────────────────────────────" - echo " Provider: $API_NAME" - echo " Base URL: $API_BASE" - echo "" - echo -e "${YELLOW}$API_HELP${NC}" - echo "" - - # Check if settings.json exists - if [ -f "$settings_file" ]; then - log_warning "settings.json already exists" - if confirm "Keep existing API token?" "Y"; then - log_info "Preserving existing configuration" - else - echo "" - read -p "Enter your $API_TOKEN_NAME: " API_TOKEN - while [ -z "$API_TOKEN" ]; do - echo -e "${RED}API token cannot be empty${NC}" - read -p "Enter your $API_TOKEN_NAME: " API_TOKEN - done - - # Update existing file - if [ "$USE_ZAI_MODELS" = true ]; then - cat > "$settings_file" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", - "ANTHROPIC_BASE_URL": "$API_BASE", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", - "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", - "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", - "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7" - }, - "enabledPlugins": {} -} -EOF - else - cat > "$settings_file" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", - "ANTHROPIC_BASE_URL": "$API_BASE", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" - }, - "enabledPlugins": {} -} -EOF - fi - log_success "API token updated" - fi - else - read -p "Enter your $API_TOKEN_NAME: " API_TOKEN - while [ -z "$API_TOKEN" ]; do - echo -e "${RED}API token cannot be empty${NC}" - read -p "Enter your $API_TOKEN_NAME: " API_TOKEN - done - - if [ "$USE_ZAI_MODELS" = true ]; then - cat > "$settings_file" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", - "ANTHROPIC_BASE_URL": "$API_BASE", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", - "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", - "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", - "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7" - }, - "enabledPlugins": {} -} -EOF - else - cat > "$settings_file" << EOF -{ - "env": { - "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", - "ANTHROPIC_BASE_URL": "$API_BASE", - "API_TIMEOUT_MS": "3000000", - "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" - }, - "enabledPlugins": {} -} -EOF - fi - log_success "API token configured" - fi - - # Add plugins to enabledPlugins if selected - if [ "$INSTALL_PLUGINS" = true ]; then - if [ "$USE_ZAI_MODELS" = true ]; then - # Add Z.AI plugins - if command -v jq &> /dev/null; then - temp=$(mktemp) - jq '.enabledPlugins += {"glm-plan-bug@zai-coding-plugins": true, "glm-plan-usage@zai-coding-plugins": true}' "$settings_file" > "$temp" - mv "$temp" "$settings_file" - log_success "Z.AI plugins enabled" - else - log_warning "jq not found, plugins not added to settings" - fi - fi - fi - - log_success "Settings configured for $API_NAME" - - # Version verification and Z.AI documentation reference - if [ "$USE_ZAI_MODELS" = true ]; then - echo "" - echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}" - echo -e "${BOLD}Z.AI GLM Configuration${NC}" - echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}" - echo "" - echo -e "${GREEN}✓ GLM Models Configured:${NC}" - echo " • glm-4.5-air (Haiku equivalent - fast, efficient)" - echo " • glm-4.7 (Sonnet/Opus equivalent - high quality)" - echo "" - echo -e "${YELLOW}📖 Official Documentation:${NC}" - echo " https://docs.z.ai/devpack/tool/claude" - echo "" - echo -e "${YELLOW}🔍 Verify Installation:${NC}" - echo " 1. Check version: ${CYAN}claude --version${NC} (recommended: 2.0.14+)" - echo " 2. Start Claude: ${CYAN}claude${NC}" - echo " 3. Check status: ${CYAN}/status${NC} (when prompted)" - echo "" - echo -e "${YELLOW}🔧 Troubleshooting:${NC}" - echo " • Close all Claude Code windows and reopen" - echo " • Or delete ~/.claude/settings.json and reconfigure" - echo " • Verify JSON format is correct (no missing/extra commas)" - echo "" - fi -} - -install_local_settings() { - log_info "Configuring permissions..." - - local local_settings="$CLAUDE_DIR/settings.local.json" - - cat > "$local_settings" << 'EOF' -{ - "permissions": { - "allow": [ - "Bash(npm install:*)", - "Bash(npm run content:*)", - "Bash(npm run build:*)", - "Bash(grep:*)", - "Bash(find:*)", - "Bash(for:*)", - "Bash(do sed:*)", - "Bash(done)", - "Bash(python3:*)", - "Bash(while read f)", - "Bash(do echo \"$f%-* $f\")", - "Bash(ls:*)", - "Bash(node:*)", - "Bash(pm2 delete:*)", - "Bash(pm2 start npm:*)", - "Bash(pm2 save:*)" - ] - } -} -EOF - - log_success "Permissions configured" -} - -install_mcp_config() { - if [ "$INSTALL_MCP_TOOLS" = false ] && [ "$INSTALL_TLDR" = false ]; then - return - fi - - log_info "Creating MCP server configuration..." - - local mcp_config="$CLAUDE_DIR/claude_desktop_config.json" - local config_needed=false - - # Check if any MCP tools need configuration - if [ "$INSTALL_VISION_TOOLS" = true ] || [ "$INSTALL_WEB_TOOLS" = true ] || [ "$INSTALL_GITHUB_TOOLS" = true ] || [ "$INSTALL_TLDR" = true ]; then - config_needed=true - fi - - if [ "$config_needed" = false ]; then - return - fi - - # Start building MCP config - local mcp_servers="{" - - # Add vision tools - if [ "$INSTALL_VISION_TOOLS" = true ]; then - mcp_servers="${mcp_servers} - \"zai-vision\": { - \"command\": \"npx\", - \"args\": [\"@z_ai/mcp-server\"] - }," - fi - - # Add web search tool - if [ "$INSTALL_WEB_TOOLS" = true ]; then - mcp_servers="${mcp_servers} - \"web-search-prime\": { - \"command\": \"npx\", - \"args\": [\"@z_ai/coding-helper\"], - \"env\": { - \"TOOL\": \"web-search-prime\" - } - }, - \"web-reader\": { - \"command\": \"npx\", - \"args\": [\"@z_ai/coding-helper\"], - \"env\": { - \"TOOL\": \"web-reader\" - } - }," - fi - - # Add GitHub tool - if [ "$INSTALL_GITHUB_TOOLS" = true ]; then - mcp_servers="${mcp_servers} - \"github-reader\": { - \"command\": \"npx\", - \"args\": [\"@z_ai/coding-helper\"], - \"env\": { - \"TOOL\": \"github-reader\" - } - }," - fi - - # Add TLDR (remove trailing comma before closing) - if [ "$INSTALL_TLDR" = true ]; then - # Remove trailing comma from previous entry if exists - mcp_servers="${mcp_servers%,}" - mcp_servers="${mcp_servers} - , - \"tldr\": { - \"command\": \"tldr-mcp\", - \"args\": [\"--project\", \".\"] - }" - fi - - # Remove trailing comma if exists - mcp_servers="${mcp_servers%,}" - - # Close JSON - mcp_servers="${mcp_servers} -}" - - # Write config file - cat > "$mcp_config" << EOF -{ - "mcpServers": $(echo "$mcp_servers") -} -EOF - - log_success "MCP server configuration created" -} - -install_mcp_tools() { - if [ "$INSTALL_MCP_TOOLS" = false ]; then - return - fi - - log_info "Installing MCP tools..." - - # Install @z_ai/mcp-server if vision tools selected - if [ "$INSTALL_VISION_TOOLS" = true ]; then - if command -v npm &> /dev/null; then - npm install -g @z_ai/mcp-server 2>/dev/null || { - log_warning "Global install failed, will use npx" - } - log_success "Vision MCP tools installed" - fi - fi - - # Install @z_ai/coding-helper for web/GitHub tools - if [ "$INSTALL_WEB_TOOLS" = true ] || [ "$INSTALL_GITHUB_TOOLS" = true ]; then - npm install -g @z_ai/coding-helper 2>/dev/null || { - log_warning "Global install failed, will use npx" - } - log_success "Web/GitHub MCP tools installed" - fi - - # Install llm-tldr for code analysis - if [ "$INSTALL_TLDR" = true ]; then - if command -v pip3 &> /dev/null; then - pip3 install llm-tldr 2>/dev/null || { - log_warning "pip3 install failed, trying pip" - pip install llm-tldr 2>/dev/null || { - log_error "Failed to install llm-tldr" - log_info "Install manually: pip install llm-tldr" - } - } - log_success "TLDR code analysis installed" - - # Initialize TLDR for current directory if it's a git repo - if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then - log_info "Initializing TLDR for current directory..." - tldr warm . 2>/dev/null || { - log_warning "TLDR initialization failed - run 'tldr warm .' manually" - } - log_success "TLDR initialized for codebase" - fi - else - log_warning "pip3 not found - skipping TLDR installation" - fi - fi - - log_success "MCP tools configured: $SELECTED_MCP_TOOLS" -} - -install_plugins() { - if [ "$INSTALL_PLUGINS" = false ]; then - return - fi - - log_info "Installing plugins..." - - # Create plugin registry - mkdir -p "$CLAUDE_DIR/plugins/cache/zai-coding-plugins"/{glm-plan-bug,glm-plan-usage} - - local installed_plugins="$CLAUDE_DIR/plugins/installed_plugins.json" - - if [ "$USE_ZAI_MODELS" = true ]; then - cat > "$installed_plugins" << EOF -{ - "version": 2, - "plugins": { - "glm-plan-bug@zai-coding-plugins": [ - { - "scope": "user", - "installPath": "$CLAUDE_DIR/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1", - "version": "0.0.1", - "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", - "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" - } - ], - "glm-plan-usage@zai-coding-plugins": [ - { - "scope": "user", - "installPath": "$CLAUDE_DIR/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1", - "version": "0.0.1", - "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", - "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" - } - ] - } -} -EOF - fi - - log_success "Plugins installed" -} - -install_hooks() { - if [ "$INSTALL_HOOKS" = false ]; then - return - fi - - local source_hooks="$SCRIPT_DIR/claude-complete-package/hooks" - - if [ -d "$source_hooks" ] && [ "$(ls -A $source_hooks 2>/dev/null)" ]; then - log_info "Installing hooks..." - cp -r "$source_hooks/"* "$CLAUDE_DIR/hooks/" 2>/dev/null || true - log_success "Hooks installed" - fi -} - -perform_installation() { - print_header - echo -e "${BOLD}Step 9: Installation${NC}" - echo "═══════════════════════════════════════════════════════════" - echo "" - - create_directories - install_agents - install_settings - install_local_settings - install_mcp_config - install_mcp_tools - install_plugins - install_hooks - - echo "" - log_success "Installation completed!" - echo "" - sleep 1 -} - -################################################################################ -# Summary & Launch -################################################################################ - -show_summary() { - print_header - echo -e "${BOLD}Installation Summary${NC}" - echo "╔══════════════════════════════════════════════════════════════════╗${NC}" - echo "║ ║" - echo "║ Configuration: ║" - - if [ "$USE_ZAI_MODELS" = true ]; then - echo "║ • Model Provider: ${CYAN}Z.AI / GLM Coding Plan${NC} ║" - else - echo "║ • Model Provider: ${GREEN}Anthropic Claude (Official)${NC} ║" - fi - - echo "║ ║" - echo "║ Installed Components: ║" - - if [ $SELECTED_AGENTS -gt 0 ]; then - echo "║ • Agents: ${GREEN}$SELECTED_AGENTS custom agents${NC} ║" - fi - - if [ $SELECTED_MCP_TOOLS -gt 0 ]; then - echo "║ • MCP Tools: ${CYAN}$SELECTED_MCP_TOOLS tools${NC} ║" - fi - - if [ "$INSTALL_PLUGINS" = true ]; then - echo "║ • Plugins: ${GREEN}Z.AI plugins enabled${NC} ║" - fi - - if [ "$INSTALL_HOOKS" = true ]; then - echo "║ • Hooks: ${GREEN}Installed${NC} ║" - fi - - echo "║ ║" - echo "╚══════════════════════════════════════════════════════════════════╝" - echo "" -} - -launch_claude_code() { - echo "" - echo -e "${BOLD}Launch Claude Code?${NC}" - echo "" - echo "You can launch Claude Code now to start using your customizations." - echo "" - - if confirm "Launch Claude Code now?" "N"; then - echo "" - log_info "Launching Claude Code..." - echo "" - - # Try to launch claude-code - if command -v claude-code &> /dev/null; then - exec claude-code - elif command -v code &> /dev/null; then - log_info "Trying VS Code command..." - code - else - log_warning "Claude Code command not found" - echo "" - echo "Please launch Claude Code manually:" - echo " • From applications menu" - echo " • Or run: claude-code" - echo " • Or run: code" - fi - else - echo "" - log_info "You can launch Claude Code later with: claude-code" - fi -} - -################################################################################ -# Main Installation Flow -################################################################################ - -main() { - show_welcome - select_model - select_agents - select_mcp_tools - select_plugins - select_hooks - check_prerequisites - install_claude_code - backup_config - perform_installation - show_summary - - if [ -n "$BACKUP_DIR" ] && [ -d "$BACKUP_DIR" ]; then - log_info "Backup saved to: $BACKUP_DIR" - fi - - launch_claude_code -} - -# Run main -main "$@" +#!/usr/bin/env bash +################################################################################ +# Claude Code Customizations - Interactive Installer +# Step-by-step installation with user choices for each component +################################################################################ + +set -e + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +BOLD='\033[1m' +NC='\033[0m' + +# Configuration +CLAUDE_DIR="$HOME/.claude" +BACKUP_DIR="$HOME/.claude-backup-$(date +%Y%m%d_%H%M%S)" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# User choices +USE_ZAI_MODELS=false +INSTALL_AGENTS=true +INSTALL_ENGINEERING=true +INSTALL_MARKETING=true +INSTALL_PRODUCT=true +INSTALL_STUDIO_OPS=true +INSTALL_PROJECT_MGMT=true +INSTALL_TESTING=true +INSTALL_DESIGN=true +INSTALL_BONUS=true +INSTALL_MCP_TOOLS=true +INSTALL_VISION_TOOLS=true +INSTALL_WEB_TOOLS=true +INSTALL_GITHUB_TOOLS=true +INSTALL_TLDR=true +INSTALL_PLUGINS=true +INSTALL_HOOKS=true +LAUNCH_CLAUDE=false + +# Counters +SELECTED_AGENTS=0 +SELECTED_MCP_TOOLS=0 + +################################################################################ +# Helper Functions +################################################################################ + +log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } +log_success() { echo -e "${GREEN}[✓]${NC} $1"; } +log_warning() { echo -e "${YELLOW}[!]${NC} $1"; } +log_error() { echo -e "${RED}[✗]${NC} $1"; } + +print_header() { + clear + echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════╗${NC}" + echo -e "${CYAN}║${NC} ${BOLD}Claude Code Customizations - Interactive Installer${NC} ${CYAN}║${NC}" + echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════╝${NC}" + echo "" +} + +confirm() { + local prompt="$1" + local default="$2" + + if [ "$default" = "Y" ]; then + prompt="$prompt [Y/n]: " + else + prompt="$prompt [y/N]: " + fi + + read -p "$prompt" response + + if [ -z "$response" ]; then + if [ "$default" = "Y" ]; then + return 0 + else + return 1 + fi + fi + + [[ "$response" =~ ^[Yy]$ ]] +} + +select_multiple() { + local title="$1" + shift + local options=("$@") + + echo "" + echo -e "${BOLD}$title${NC}" + echo "─────────────────────────────────────────────────────────────" + echo "" + + local i=1 + for opt in "${options[@]}"; do + echo " $i) $opt" + i=$((i+1)) + done + echo " a) All" + echo " n) None" + echo "" + + while true; do + read -p "Select options (comma-separated, a=n): " selection + + if [[ "$selection" =~ ^[Aa]$ ]]; then + return 0 # All + elif [[ "$selection" =~ ^[Nn]$ ]]; then + return 1 # None + else + return 0 # Has selections + fi + done +} + +################################################################################ +# Welcome Screen +################################################################################ + +show_welcome() { + print_header + echo -e "${BOLD}Welcome to Claude Code Customizations Installer!${NC}" + echo "" + echo "This installer will guide you through setting up a customized" + echo "Claude Code environment with:" + echo "" + echo " • 40+ specialized agents for development, marketing, and operations" + echo " • MCP tools for vision analysis, web search, and GitHub integration" + echo " • Custom skills and plugins" + echo " • Optimized workflows for rapid 6-day development cycles" + echo "" + echo -e "${YELLOW}Note:${NC} You can choose what to install at each step." + echo "" + + if ! confirm "Continue with installation?" "Y"; then + echo "Installation cancelled." + exit 0 + fi +} + +################################################################################ +# Model Selection +################################################################################ + +select_model() { + print_header + echo -e "${BOLD}Step 1: Model Selection${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "Choose which API models to use with Claude Code:" + echo "" + echo -e " ${GREEN}1${NC}) ${BOLD}Anthropic Claude Models${NC} (official)" + echo " • claude-sonnet-4.5, claude-opus-4.5, etc." + echo " • Direct Anthropic API" + echo " • Base URL: https://api.anthropic.com" + echo "" + echo -e " ${CYAN}2${NC}) ${BOLD}Z.AI / GLM Coding Plan Models${NC}" + echo " • Same Claude models via Z.AI platform" + echo " • Additional features: usage tracking, feedback, promotions" + echo " • Base URL: https://api.z.ai/api/anthropic" + echo " • Includes: 旺仔牛奶 rewards program" + echo "" + read -p "Select model provider [1/2]: " model_choice + + case $model_choice in + 2) + USE_ZAI_MODELS=true + log_success "Selected: Z.AI / GLM Coding Plan Models" + ;; + *) + USE_ZAI_MODELS=false + log_success "Selected: Anthropic Claude Models (official)" + ;; + esac + + echo "" +} + +################################################################################ +# Agent Selection +################################################################################ + +select_agents() { + print_header + echo -e "${BOLD}Step 2: Agent Categories${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "Custom agents provide specialized assistance for different tasks." + echo "Select which categories to install:" + echo "" + + if confirm "Install Engineering agents? (AI engineer, frontend/backend dev, DevOps, mobile, rapid prototyper, test writer)" "Y"; then + INSTALL_ENGINEERING=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 7)) + else + INSTALL_ENGINEERING=false + fi + + if confirm "Install Marketing agents? (TikTok strategist, growth hacker, content creator, Instagram/Reddit/Twitter)" "Y"; then + INSTALL_MARKETING=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 7)) + else + INSTALL_MARKETING=false + fi + + if confirm "Install Product agents? (Sprint prioritizer, feedback synthesizer, trend researcher)" "Y"; then + INSTALL_PRODUCT=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 3)) + else + INSTALL_PRODUCT=false + fi + + if confirm "Install Studio Operations agents? (Studio producer, project shipper, analytics, finance, legal, support, coach)" "Y"; then + INSTALL_STUDIO_OPS=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 8)) + else + INSTALL_STUDIO_OPS=false + fi + + if confirm "Install Project Management agents? (Experiment tracker, studio producer, project shipper)" "Y"; then + INSTALL_PROJECT_MGMT=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 3)) + else + INSTALL_PROJECT_MGMT=false + fi + + if confirm "Install Testing agents? (Test writer/fixer, API tester, performance benchmarker, workflow optimizer)" "Y"; then + INSTALL_TESTING=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 5)) + else + INSTALL_TESTING=false + fi + + if confirm "Install Design agents? (UI/UX designer, brand guardian, visual storyteller, whimsy injector)" "Y"; then + INSTALL_DESIGN=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 5)) + else + INSTALL_DESIGN=false + fi + + if confirm "Install Bonus agents? (Joker, studio coach)" "Y"; then + INSTALL_BONUS=true + SELECTED_AGENTS=$((SELECTED_AGENTS + 2)) + else + INSTALL_BONUS=false + fi + + if [ $SELECTED_AGENTS -eq 0 ]; then + log_warning "No agents selected - you can add them later manually" + else + log_success "Selected $SELECTED_AGENTS agents across multiple categories" + fi + + echo "" +} + +################################################################################ +# MCP Tools Selection +################################################################################ + +select_mcp_tools() { + print_header + echo -e "${BOLD}Step 3: MCP Tools${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "MCP (Model Context Protocol) tools provide advanced capabilities." + echo "Select which tools to install:" + echo "" + + if confirm "Install Vision Analysis tools? (images, videos, UI screenshots, error diagnosis, data visualization, diagrams)" "Y"; then + INSTALL_VISION_TOOLS=true + SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 8)) + else + INSTALL_VISION_TOOLS=false + fi + + if confirm "Install Web Search tool? (enhanced search with domain filtering, time-based results)" "Y"; then + INSTALL_WEB_TOOLS=true + SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 1)) + else + INSTALL_WEB_TOOLS=false + fi + + if confirm "Install Web Reader tool? (fetch URLs, convert to markdown)" "Y"; then + INSTALL_WEB_TOOLS=true + SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 1)) + fi + + if confirm "Install GitHub Reader tool? (read repos, search docs/issues/commits)" "Y"; then + INSTALL_GITHUB_TOOLS=true + SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 3)) + else + INSTALL_GITHUB_TOOLS=false + fi + + if command -v python3 &> /dev/null && command -v pip3 &> /dev/null; then + if confirm "Install TLDR Code Analysis? (95% token reduction, semantic search, program slicing - requires Python)" "Y"; then + INSTALL_TLDR=true + SELECTED_MCP_TOOLS=$((SELECTED_MCP_TOOLS + 18)) + else + INSTALL_TLDR=false + fi + else + log_warning "Python/pip3 not found - skipping TLDR Code Analysis" + INSTALL_TLDR=false + fi + + if [ $SELECTED_MCP_TOOLS -eq 0 ]; then + log_warning "No MCP tools selected" + else + log_success "Selected $SELECTED_MCP_TOOLS MCP tools" + fi + + INSTALL_MCP_TOOLS=true + echo "" +} + +################################################################################ +# Plugins Selection +################################################################################ + +select_plugins() { + print_header + echo -e "${BOLD}Step 4: Plugins & Skills${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "Plugins extend Claude Code with additional features:" + echo "" + echo " • glm-plan-bug: Submit bug/issue feedback to Z.AI" + echo " • glm-plan-usage: Query your GLM Coding Plan usage statistics" + echo "" + + if confirm "Install Z.AI plugins?" "Y"; then + INSTALL_PLUGINS=true + log_success "Plugins selected" + else + INSTALL_PLUGINS=false + log_warning "Plugins skipped" + fi + + echo "" +} + +################################################################################ +# Hooks Selection +################################################################################ + +select_hooks() { + print_header + echo -e "${BOLD}Step 5: Hooks${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + echo "Hooks are scripts that run automatically on specific events." + echo "Do you want to copy existing hooks from the package?" + echo "" + + if confirm "Install hooks?" "N"; then + INSTALL_HOOKS=true + log_success "Hooks selected" + else + INSTALL_HOOKS=false + log_warning "Hooks skipped" + fi + + echo "" +} + +################################################################################ +# Prerequisites Check +################################################################################ + +check_prerequisites() { + print_header + echo -e "${BOLD}Step 6: Prerequisites Check${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + local errors=0 + + # Check Node.js + if command -v node &> /dev/null; then + NODE_VERSION=$(node -v) + log_success "Node.js installed: $NODE_VERSION" + else + log_error "Node.js not found" + errors=$((errors+1)) + fi + + # Check npm + if command -v npm &> /dev/null; then + NPM_VERSION=$(npm -v) + log_success "npm installed: $NPM_VERSION" + else + log_error "npm not found" + errors=$((errors+1)) + fi + + # Check python3 + if command -v python3 &> /dev/null; then + PYTHON_VERSION=$(python3 --version) + log_success "Python installed: $PYTHON_VERSION" + else + log_warning "Python3 not found (optional)" + fi + + # Check npx + if command -v npx &> /dev/null; then + log_success "npx available" + else + log_warning "npx not found (will be installed with npm)" + fi + + echo "" + + if [ $errors -gt 0 ]; then + log_error "Some prerequisites are missing. Please install them and try again." + echo "" + echo "Install Node.js: https://nodejs.org/" + echo "Or use nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash" + echo "" + exit 1 + fi + + log_success "Prerequisites check passed" + echo "" + sleep 1 +} + +################################################################################ +# Claude Code Installation +################################################################################ + +install_claude_code() { + print_header + echo -e "${BOLD}Step 7: Claude Code Installation${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + # Check if Claude Code is installed + if command -v claude-code &> /dev/null; then + log_success "Claude Code is already installed" + claude-code --version 2>/dev/null || log_info "Version: unknown" + echo "" + return + fi + + echo -e "${YELLOW}Claude Code is not installed on this system.${NC}" + echo "" + echo "Claude Code is Anthropic's official CLI for Claude." + echo "You need it to use these customizations." + echo "" + echo "Installation options:" + echo "" + echo -e " ${GREEN}1${NC}) ${BOLD}Install via npm (recommended)${NC}" + echo " • Requires Node.js 14+" + echo " • Command: npm install -g @anthropic-ai/claude-code" + echo " • Fastest method" + echo "" + echo -e " ${GREEN}2${NC}) ${BOLD}Install via curl (alternative)${NC}" + echo " • Downloads standalone binary" + echo " • No Node.js required" + echo "" + echo -e " ${GREEN}3${NC}) ${BOLD}Manual installation${NC}" + echo " • Visit: https://claude.ai/download" + echo " • Choose your platform" + echo "" + echo -e " ${YELLOW}0${NC}) Skip installation" + echo "" + read -p "Select installation method [1/2/3/0]: " install_choice + + case $install_choice in + 1) + echo "" + log_info "Installing Claude Code via npm..." + echo "" + + if command -v npm &> /dev/null; then + npm install -g @anthropic-ai/claude-code + + if command -v claude-code &> /dev/null; then + log_success "Claude Code installed successfully!" + echo "" + claude-code --version 2>/dev/null || true + else + log_error "Installation failed. Please try manual installation." + fi + else + log_error "npm not found. Please install Node.js first." + echo "Visit: https://nodejs.org/" + fi + ;; + 2) + echo "" + log_info "Installing Claude Code via curl..." + echo "" + + if command -v curl &> /dev/null; then + # Detect OS and architecture + OS="$(uname -s)" + ARCH="$(uname -m)" + + case "$OS" in + Linux) + if [ "$ARCH" = "x86_64" ]; then + curl -L https://claude.ai/download/claude-code-linux -o /tmp/claude-code + sudo mv /tmp/claude-code /usr/local/bin/claude-code + sudo chmod +x /usr/local/bin/claude-code + log_success "Claude Code installed!" + else + log_error "Unsupported architecture: $ARCH" + fi + ;; + Darwin) + if [ "$ARCH" = "arm64" ]; then + curl -L https://claude.ai/download/claude-code-mac-arm -o /tmp/claude-code + else + curl -L https://claude.ai/download/claude-code-mac -o /tmp/claude-code + fi + sudo mv /tmp/claude-code /usr/local/bin/claude-code + sudo chmod +x /usr/local/bin/claude-code + log_success "Claude Code installed!" + ;; + *) + log_error "Unsupported OS: $OS" + ;; + esac + else + log_error "curl not found. Please install curl or use npm method." + fi + ;; + 3) + echo "" + log_info "Please visit https://claude.ai/download to install Claude Code manually" + echo "" + echo "After installation, run this script again." + echo "" + exit 0 + ;; + 0) + log_warning "Skipping Claude Code installation" + log_warning "You will need to install it manually to use these customizations" + ;; + *) + log_error "Invalid choice" + ;; + esac + + echo "" + sleep 2 +} + +################################################################################ +# Backup Existing Configuration +################################################################################ + +backup_config() { + if [ -d "$CLAUDE_DIR" ]; then + print_header + echo -e "${BOLD}Step 8: Backup${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + log_info "Existing Claude Code configuration found" + log_info "Creating backup at: $BACKUP_DIR" + echo "" + + cp -r "$CLAUDE_DIR" "$BACKUP_DIR" + log_success "Backup created successfully" + echo "" + sleep 1 + fi +} + +################################################################################ +# Installation +################################################################################ + +create_directories() { + log_info "Creating directory structure..." + + mkdir -p "$CLAUDE_DIR"/{agents,plugins/cache,plugins/marketplaces,hooks,debug,file-history,paste-cache,projects,session-env,shell-snapshots,todos} + + if [ "$INSTALL_ENGINEERING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/engineering"; fi + if [ "$INSTALL_MARKETING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/marketing"; fi + if [ "$INSTALL_PRODUCT" = true ]; then mkdir -p "$CLAUDE_DIR/agents/product"; fi + if [ "$INSTALL_STUDIO_OPS" = true ]; then mkdir -p "$CLAUDE_DIR/agents/studio-operations"; fi + if [ "$INSTALL_PROJECT_MGMT" = true ]; then mkdir -p "$CLAUDE_DIR/agents/project-management"; fi + if [ "$INSTALL_TESTING" = true ]; then mkdir -p "$CLAUDE_DIR/agents/testing"; fi + if [ "$INSTALL_DESIGN" = true ]; then mkdir -p "$CLAUDE_DIR/agents/design"; fi + if [ "$INSTALL_BONUS" = true ]; then mkdir -p "$CLAUDE_DIR/agents/bonus"; fi + + log_success "Directories created" +} + +install_agents() { + if [ $SELECTED_AGENTS -eq 0 ]; then + return + fi + + log_info "Installing agents..." + + local source_agents="$SCRIPT_DIR/claude-complete-package/agents" + + if [ ! -d "$source_agents" ]; then + log_warning "Agent source directory not found at $source_agents" + log_warning "Please ensure you're running this from the correct location" + return + fi + + if [ "$INSTALL_ENGINEERING" = true ]; then + cp -r "$source_agents/engineering/"*.md "$CLAUDE_DIR/agents/engineering/" 2>/dev/null || true + fi + + if [ "$INSTALL_MARKETING" = true ]; then + cp -r "$source_agents/marketing/"*.md "$CLAUDE_DIR/agents/marketing/" 2>/dev/null || true + fi + + if [ "$INSTALL_PRODUCT" = true ]; then + cp -r "$source_agents/product/"*.md "$CLAUDE_DIR/agents/product/" 2>/dev/null || true + fi + + if [ "$INSTALL_STUDIO_OPS" = true ]; then + cp -r "$source_agents/studio-operations/"*.md "$CLAUDE_DIR/agents/studio-operations/" 2>/dev/null || true + fi + + if [ "$INSTALL_PROJECT_MGMT" = true ]; then + cp -r "$source_agents/project-management/"*.md "$CLAUDE_DIR/agents/project-management/" 2>/dev/null || true + fi + + if [ "$INSTALL_TESTING" = true ]; then + cp -r "$source_agents/testing/"*.md "$CLAUDE_DIR/agents/testing/" 2>/dev/null || true + fi + + if [ "$INSTALL_DESIGN" = true ]; then + cp -r "$source_agents/design/"*.md "$CLAUDE_DIR/agents/design/" 2>/dev/null || true + fi + + # Install ui-ux-pro-max agent (additional design agent) + if [ "$INSTALL_DESIGN" = true ]; then + log_info "Installing ui-ux-pro-max design agent..." + # Check if ui-ux-pro-max exists in the repository + if [ -f "$SCRIPT_DIR/agents/design/ui-ux-pro-max.md" ]; then + cp "$SCRIPT_DIR/agents/design/ui-ux-pro-max.md" "$CLAUDE_DIR/agents/design/" 2>/dev/null || true + log_success "ui-ux-pro-max agent installed" + else + # Download from repository + log_info "Downloading ui-ux-pro-max agent from repository..." + wget -q -O "$CLAUDE_DIR/agents/design/ui-ux-pro-max.md" \ + "https://raw.githubusercontent.com/github.rommark.dev/admin/claude-code-glm-suite/main/agents/design/ui-ux-pro-max.md" 2>/dev/null || { + log_warning "Failed to download ui-ux-pro-max agent" + } + fi + fi + + if [ "$INSTALL_BONUS" = true ]; then + cp -r "$source_agents/bonus/"*.md "$CLAUDE_DIR/agents/bonus/" 2>/dev/null || true + fi + + log_success "Agents installed: $SELECTED_AGENTS" +} + +install_settings() { + log_info "Configuring settings..." + + local settings_file="$CLAUDE_DIR/settings.json" + + # Determine API base URL and help text + if [ "$USE_ZAI_MODELS" = true ]; then + API_BASE="https://api.z.ai/api/anthropic" + API_NAME="Z.AI / GLM Coding Plan" + API_HELP="Get your API key from: https://z.ai/ (Official docs: https://docs.z.ai/devpack/tool/claude)" + API_TOKEN_NAME="Z.AI API Key" + else + API_BASE="https://api.anthropic.com" + API_NAME="Anthropic Claude" + API_HELP="Get your API key from: https://console.anthropic.com/" + API_TOKEN_NAME="Anthropic API Key" + fi + + echo "" + echo -e "${CYAN}API Configuration${NC}" + echo "─────────────────────────────────────────────────────────────" + echo " Provider: $API_NAME" + echo " Base URL: $API_BASE" + echo "" + echo -e "${YELLOW}$API_HELP${NC}" + echo "" + + # Check if settings.json exists + if [ -f "$settings_file" ]; then + log_warning "settings.json already exists" + if confirm "Keep existing API token?" "Y"; then + log_info "Preserving existing configuration" + else + echo "" + read -p "Enter your $API_TOKEN_NAME: " API_TOKEN + while [ -z "$API_TOKEN" ]; do + echo -e "${RED}API token cannot be empty${NC}" + read -p "Enter your $API_TOKEN_NAME: " API_TOKEN + done + + # Update existing file + if [ "$USE_ZAI_MODELS" = true ]; then + cat > "$settings_file" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", + "ANTHROPIC_BASE_URL": "$API_BASE", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", + "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", + "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", + "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7" + }, + "enabledPlugins": {} +} +EOF + else + cat > "$settings_file" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", + "ANTHROPIC_BASE_URL": "$API_BASE", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" + }, + "enabledPlugins": {} +} +EOF + fi + log_success "API token updated" + fi + else + read -p "Enter your $API_TOKEN_NAME: " API_TOKEN + while [ -z "$API_TOKEN" ]; do + echo -e "${RED}API token cannot be empty${NC}" + read -p "Enter your $API_TOKEN_NAME: " API_TOKEN + done + + if [ "$USE_ZAI_MODELS" = true ]; then + cat > "$settings_file" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", + "ANTHROPIC_BASE_URL": "$API_BASE", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", + "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air", + "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7", + "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7" + }, + "enabledPlugins": {} +} +EOF + else + cat > "$settings_file" << EOF +{ + "env": { + "ANTHROPIC_AUTH_TOKEN": "$API_TOKEN", + "ANTHROPIC_BASE_URL": "$API_BASE", + "API_TIMEOUT_MS": "3000000", + "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" + }, + "enabledPlugins": {} +} +EOF + fi + log_success "API token configured" + fi + + # Add plugins to enabledPlugins if selected + if [ "$INSTALL_PLUGINS" = true ]; then + if [ "$USE_ZAI_MODELS" = true ]; then + # Add Z.AI plugins + if command -v jq &> /dev/null; then + temp=$(mktemp) + jq '.enabledPlugins += {"glm-plan-bug@zai-coding-plugins": true, "glm-plan-usage@zai-coding-plugins": true}' "$settings_file" > "$temp" + mv "$temp" "$settings_file" + log_success "Z.AI plugins enabled" + else + log_warning "jq not found, plugins not added to settings" + fi + fi + fi + + log_success "Settings configured for $API_NAME" + + # Version verification and Z.AI documentation reference + if [ "$USE_ZAI_MODELS" = true ]; then + echo "" + echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}" + echo -e "${BOLD}Z.AI GLM Configuration${NC}" + echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}" + echo "" + echo -e "${GREEN}✓ GLM Models Configured:${NC}" + echo " • glm-4.5-air (Haiku equivalent - fast, efficient)" + echo " • glm-4.7 (Sonnet/Opus equivalent - high quality)" + echo "" + echo -e "${YELLOW}📖 Official Documentation:${NC}" + echo " https://docs.z.ai/devpack/tool/claude" + echo "" + echo -e "${YELLOW}🔍 Verify Installation:${NC}" + echo " 1. Check version: ${CYAN}claude --version${NC} (recommended: 2.0.14+)" + echo " 2. Start Claude: ${CYAN}claude${NC}" + echo " 3. Check status: ${CYAN}/status${NC} (when prompted)" + echo "" + echo -e "${YELLOW}🔧 Troubleshooting:${NC}" + echo " • Close all Claude Code windows and reopen" + echo " • Or delete ~/.claude/settings.json and reconfigure" + echo " • Verify JSON format is correct (no missing/extra commas)" + echo "" + fi +} + +install_local_settings() { + log_info "Configuring permissions..." + + local local_settings="$CLAUDE_DIR/settings.local.json" + + cat > "$local_settings" << 'EOF' +{ + "permissions": { + "allow": [ + "Bash(npm install:*)", + "Bash(npm run content:*)", + "Bash(npm run build:*)", + "Bash(grep:*)", + "Bash(find:*)", + "Bash(for:*)", + "Bash(do sed:*)", + "Bash(done)", + "Bash(python3:*)", + "Bash(while read f)", + "Bash(do echo \"$f%-* $f\")", + "Bash(ls:*)", + "Bash(node:*)", + "Bash(pm2 delete:*)", + "Bash(pm2 start npm:*)", + "Bash(pm2 save:*)" + ] + } +} +EOF + + log_success "Permissions configured" +} + +install_mcp_config() { + if [ "$INSTALL_MCP_TOOLS" = false ] && [ "$INSTALL_TLDR" = false ]; then + return + fi + + log_info "Creating MCP server configuration..." + + local mcp_config="$CLAUDE_DIR/claude_desktop_config.json" + local config_needed=false + + # Check if any MCP tools need configuration + if [ "$INSTALL_VISION_TOOLS" = true ] || [ "$INSTALL_WEB_TOOLS" = true ] || [ "$INSTALL_GITHUB_TOOLS" = true ] || [ "$INSTALL_TLDR" = true ]; then + config_needed=true + fi + + if [ "$config_needed" = false ]; then + return + fi + + # Start building MCP config + local mcp_servers="{" + + # Add vision tools + if [ "$INSTALL_VISION_TOOLS" = true ]; then + mcp_servers="${mcp_servers} + \"zai-vision\": { + \"command\": \"npx\", + \"args\": [\"@z_ai/mcp-server\"] + }," + fi + + # Add web search tool + if [ "$INSTALL_WEB_TOOLS" = true ]; then + mcp_servers="${mcp_servers} + \"web-search-prime\": { + \"command\": \"npx\", + \"args\": [\"@z_ai/coding-helper\"], + \"env\": { + \"TOOL\": \"web-search-prime\" + } + }, + \"web-reader\": { + \"command\": \"npx\", + \"args\": [\"@z_ai/coding-helper\"], + \"env\": { + \"TOOL\": \"web-reader\" + } + }," + fi + + # Add GitHub tool + if [ "$INSTALL_GITHUB_TOOLS" = true ]; then + mcp_servers="${mcp_servers} + \"github-reader\": { + \"command\": \"npx\", + \"args\": [\"@z_ai/coding-helper\"], + \"env\": { + \"TOOL\": \"github-reader\" + } + }," + fi + + # Add TLDR (remove trailing comma before closing) + if [ "$INSTALL_TLDR" = true ]; then + # Remove trailing comma from previous entry if exists + mcp_servers="${mcp_servers%,}" + mcp_servers="${mcp_servers} + , + \"tldr\": { + \"command\": \"tldr-mcp\", + \"args\": [\"--project\", \".\"] + }" + fi + + # Remove trailing comma if exists + mcp_servers="${mcp_servers%,}" + + # Close JSON + mcp_servers="${mcp_servers} +}" + + # Write config file + cat > "$mcp_config" << EOF +{ + "mcpServers": $(echo "$mcp_servers") +} +EOF + + log_success "MCP server configuration created" +} + +install_mcp_tools() { + if [ "$INSTALL_MCP_TOOLS" = false ]; then + return + fi + + log_info "Installing MCP tools..." + + # Install @z_ai/mcp-server if vision tools selected + if [ "$INSTALL_VISION_TOOLS" = true ]; then + if command -v npm &> /dev/null; then + npm install -g @z_ai/mcp-server 2>/dev/null || { + log_warning "Global install failed, will use npx" + } + log_success "Vision MCP tools installed" + fi + fi + + # Install @z_ai/coding-helper for web/GitHub tools + if [ "$INSTALL_WEB_TOOLS" = true ] || [ "$INSTALL_GITHUB_TOOLS" = true ]; then + npm install -g @z_ai/coding-helper 2>/dev/null || { + log_warning "Global install failed, will use npx" + } + log_success "Web/GitHub MCP tools installed" + fi + + # Install llm-tldr for code analysis + if [ "$INSTALL_TLDR" = true ]; then + if command -v pip3 &> /dev/null; then + pip3 install llm-tldr 2>/dev/null || { + log_warning "pip3 install failed, trying pip" + pip install llm-tldr 2>/dev/null || { + log_error "Failed to install llm-tldr" + log_info "Install manually: pip install llm-tldr" + } + } + log_success "TLDR code analysis installed" + + # Initialize TLDR for current directory if it's a git repo + if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then + log_info "Initializing TLDR for current directory..." + tldr warm . 2>/dev/null || { + log_warning "TLDR initialization failed - run 'tldr warm .' manually" + } + log_success "TLDR initialized for codebase" + fi + else + log_warning "pip3 not found - skipping TLDR installation" + fi + fi + + log_success "MCP tools configured: $SELECTED_MCP_TOOLS" +} + +install_plugins() { + if [ "$INSTALL_PLUGINS" = false ]; then + return + fi + + log_info "Installing plugins..." + + # Create plugin registry + mkdir -p "$CLAUDE_DIR/plugins/cache/zai-coding-plugins"/{glm-plan-bug,glm-plan-usage} + + local installed_plugins="$CLAUDE_DIR/plugins/installed_plugins.json" + + if [ "$USE_ZAI_MODELS" = true ]; then + cat > "$installed_plugins" << EOF +{ + "version": 2, + "plugins": { + "glm-plan-bug@zai-coding-plugins": [ + { + "scope": "user", + "installPath": "$CLAUDE_DIR/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1", + "version": "0.0.1", + "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", + "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" + } + ], + "glm-plan-usage@zai-coding-plugins": [ + { + "scope": "user", + "installPath": "$CLAUDE_DIR/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1", + "version": "0.0.1", + "installedAt": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)", + "lastUpdated": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" + } + ] + } +} +EOF + fi + + log_success "Plugins installed" +} + +install_hooks() { + if [ "$INSTALL_HOOKS" = false ]; then + return + fi + + local source_hooks="$SCRIPT_DIR/claude-complete-package/hooks" + + if [ -d "$source_hooks" ] && [ "$(ls -A $source_hooks 2>/dev/null)" ]; then + log_info "Installing hooks..." + cp -r "$source_hooks/"* "$CLAUDE_DIR/hooks/" 2>/dev/null || true + log_success "Hooks installed" + fi +} + +perform_installation() { + print_header + echo -e "${BOLD}Step 9: Installation${NC}" + echo "═══════════════════════════════════════════════════════════" + echo "" + + create_directories + install_agents + install_settings + install_local_settings + install_mcp_config + install_mcp_tools + install_plugins + install_hooks + + echo "" + log_success "Installation completed!" + echo "" + sleep 1 +} + +################################################################################ +# Summary & Launch +################################################################################ + +show_summary() { + print_header + echo -e "${BOLD}Installation Summary${NC}" + echo "╔══════════════════════════════════════════════════════════════════╗${NC}" + echo "║ ║" + echo "║ Configuration: ║" + + if [ "$USE_ZAI_MODELS" = true ]; then + echo "║ • Model Provider: ${CYAN}Z.AI / GLM Coding Plan${NC} ║" + else + echo "║ • Model Provider: ${GREEN}Anthropic Claude (Official)${NC} ║" + fi + + echo "║ ║" + echo "║ Installed Components: ║" + + if [ $SELECTED_AGENTS -gt 0 ]; then + echo "║ • Agents: ${GREEN}$SELECTED_AGENTS custom agents${NC} ║" + fi + + if [ $SELECTED_MCP_TOOLS -gt 0 ]; then + echo "║ • MCP Tools: ${CYAN}$SELECTED_MCP_TOOLS tools${NC} ║" + fi + + if [ "$INSTALL_PLUGINS" = true ]; then + echo "║ • Plugins: ${GREEN}Z.AI plugins enabled${NC} ║" + fi + + if [ "$INSTALL_HOOKS" = true ]; then + echo "║ • Hooks: ${GREEN}Installed${NC} ║" + fi + + echo "║ ║" + echo "╚══════════════════════════════════════════════════════════════════╝" + echo "" +} + +launch_claude_code() { + echo "" + echo -e "${BOLD}Launch Claude Code?${NC}" + echo "" + echo "You can launch Claude Code now to start using your customizations." + echo "" + + if confirm "Launch Claude Code now?" "N"; then + echo "" + log_info "Launching Claude Code..." + echo "" + + # Try to launch claude-code + if command -v claude-code &> /dev/null; then + exec claude-code + elif command -v code &> /dev/null; then + log_info "Trying VS Code command..." + code + else + log_warning "Claude Code command not found" + echo "" + echo "Please launch Claude Code manually:" + echo " • From applications menu" + echo " • Or run: claude-code" + echo " • Or run: code" + fi + else + echo "" + log_info "You can launch Claude Code later with: claude-code" + fi +} + +################################################################################ +# Main Installation Flow +################################################################################ + +main() { + show_welcome + select_model + select_agents + select_mcp_tools + select_plugins + select_hooks + check_prerequisites + install_claude_code + backup_config + perform_installation + show_summary + + if [ -n "$BACKUP_DIR" ] && [ -d "$BACKUP_DIR" ]; then + log_info "Backup saved to: $BACKUP_DIR" + fi + + launch_claude_code +} + +# Run main +main "$@" diff --git a/agents/verify-claude-setup.sh b/agents/verify-claude-setup.sh index 79d05d3..9077040 100755 --- a/agents/verify-claude-setup.sh +++ b/agents/verify-claude-setup.sh @@ -1,217 +1,217 @@ -#!/usr/bin/env bash -################################################################################ -# Claude Code Setup Verification Script -# Checks if all customizations are properly installed -################################################################################ - -set -e - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' - -CLAUDE_DIR="$HOME/.claude" -AGENTS_DIR="$CLAUDE_DIR/agents" -PLUGINS_DIR="$CLAUDE_DIR/plugins" - -PASSED=0 -FAILED=0 -WARNINGS=0 - -check_pass() { - echo -e "${GREEN}✓${NC} $1" - PASSED=$((PASSED+1)) -} - -check_fail() { - echo -e "${RED}✗${NC} $1" - FAILED=$((FAILED+1)) -} - -check_warn() { - echo -e "${YELLOW}⚠${NC} $1" - WARNINGS=$((WARNINGS+1)) -} - -check_info() { - echo -e "${BLUE}ℹ${NC} $1" -} - -echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" -echo -e "${BLUE}║ Claude Code Customizations - Verification ║${NC}" -echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" -echo "" - -# 1. Check directory structure -echo "═══════════════════════════════════════════════════════════" -echo "Directory Structure" -echo "═══════════════════════════════════════════════════════════" - -[ -d "$CLAUDE_DIR" ] && check_pass "Claude directory exists" || check_fail "Claude directory missing" -[ -d "$AGENTS_DIR" ] && check_pass "Agents directory exists" || check_fail "Agents directory missing" -[ -d "$PLUGINS_DIR" ] && check_pass "Plugins directory exists" || check_fail "Plugins directory missing" - -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Agent Categories" -echo "═══════════════════════════════════════════════════════════" - -CATEGORIES=("engineering" "marketing" "product" "studio-operations" "project-management" "testing" "design" "bonus") -AGENT_COUNT=0 - -for category in "${CATEGORIES[@]}"; do - if [ -d "$AGENTS_DIR/$category" ]; then - count=$(ls -1 "$AGENTS_DIR/$category"/*.md 2>/dev/null | wc -l) - if [ $count -gt 0 ]; then - echo -e "${GREEN}✓${NC} $category: $count agents" - AGENT_COUNT=$((AGENT_COUNT + count)) - else - check_warn "$category: directory exists but no agents" - fi - else - check_fail "$category: directory missing" - fi -done - -echo "" -check_info "Total agents: $AGENT_COUNT" - -# 2. Check configuration files -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Configuration Files" -echo "═══════════════════════════════════════════════════════════" - -[ -f "$CLAUDE_DIR/settings.json" ] && check_pass "settings.json exists" || check_fail "settings.json missing" -[ -f "$CLAUDE_DIR/settings.local.json" ] && check_pass "settings.local.json exists" || check_fail "settings.local.json missing" -[ -f "$PLUGINS_DIR/installed_plugins.json" ] && check_pass "installed_plugins.json exists" || check_fail "installed_plugins.json missing" -[ -f "$PLUGINS_DIR/known_marketplaces.json" ] && check_pass "known_marketplaces.json exists" || check_fail "known_marketplaces.json missing" - -# 3. Check MCP tools -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "MCP Tools" -echo "═══════════════════════════════════════════════════════════" - -if command -v npx &> /dev/null; then - check_pass "npx available" - - # Check if @z_ai/mcp-server can be accessed - if npx -y @z_ai/mcp-server --help &> /dev/null; then - check_pass "@z_ai/mcp-server accessible" - else - check_warn "@z_ai/mcp-server not directly accessible (may download on first use)" - fi - - # Check if @z_ai/coding-helper can be accessed - if npx -y @z_ai/coding-helper --help &> /dev/null; then - check_pass "@z_ai/coding-helper accessible" - else - check_warn "@z_ai/coding-helper not directly accessible (may download on first use)" - fi -else - check_fail "npx not available - MCP tools may not work" -fi - -# 4. Check plugins -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Plugins" -echo "═══════════════════════════════════════════════════════════" - -if [ -f "$PLUGINS_DIR/installed_plugins.json" ]; then - # Check if GLM plugins are registered - if grep -q "glm-plan-bug" "$PLUGINS_DIR/installed_plugins.json" 2>/dev/null; then - check_pass "glm-plan-bug plugin registered" - else - check_warn "glm-plan-bug plugin not registered" - fi - - if grep -q "glm-plan-usage" "$PLUGINS_DIR/installed_plugins.json" 2>/dev/null; then - check_pass "glm-plan-usage plugin registered" - else - check_warn "glm-plan-usage plugin not registered" - fi -fi - -# 5. Sample agent check -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Agent Content Verification" -echo "═══════════════════════════════════════════════════════════" - -CRITICAL_AGENTS=( - "engineering/test-writer-fixer.md" - "engineering/frontend-developer.md" - "marketing/tiktok-strategist.md" - "product/sprint-prioritizer.md" - "studio-operations/studio-producer.md" - "project-management/project-shipper.md" - "design/whimsy-injector.md" -) - -for agent in "${CRITICAL_AGENTS[@]}"; do - if [ -f "$AGENTS_DIR/$agent" ]; then - # Check file has content - if [ -s "$AGENTS_DIR/$agent" ]; then - check_pass "$agent exists and has content" - else - check_warn "$agent exists but is empty" - fi - else - check_warn "$agent missing" - fi -done - -# 6. Settings validation -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Settings Validation" -echo "═══════════════════════════════════════════════════════════" - -if [ -f "$CLAUDE_DIR/settings.json" ]; then - # Check if JSON is valid - if python3 -m json.tool "$CLAUDE_DIR/settings.json" &> /dev/null; then - check_pass "settings.json is valid JSON" - - # Check for API token placeholder - if grep -q "YOUR_API_TOKEN_HERE\|YOUR_TOKEN_HERE" "$CLAUDE_DIR/settings.json" 2>/dev/null; then - check_warn "API token not configured (still placeholder)" - else - if grep -q "ANTHROPIC_AUTH_TOKEN" "$CLAUDE_DIR/settings.json" 2>/dev/null; then - check_pass "ANTHROPIC_AUTH_TOKEN is set" - fi - fi - else - check_fail "settings.json is not valid JSON" - fi -fi - -# 7. Summary -echo "" -echo "═══════════════════════════════════════════════════════════" -echo "Summary" -echo "═══════════════════════════════════════════════════════════" - -if [ $FAILED -eq 0 ]; then - echo -e "${GREEN}✓ All critical checks passed!${NC}" - echo "" - echo "Passed: $PASSED" - echo "Warnings: $WARNINGS" - echo "Failed: $FAILED" - echo "" - echo -e "${GREEN}Your Claude Code setup is ready to use!${NC}" - exit 0 -else - echo -e "${RED}✗ Some checks failed${NC}" - echo "" - echo "Passed: $PASSED" - echo "Warnings: $WARNINGS" - echo "Failed: $FAILED" - echo "" - echo "Please fix the failed checks above." - exit 1 -fi +#!/usr/bin/env bash +################################################################################ +# Claude Code Setup Verification Script +# Checks if all customizations are properly installed +################################################################################ + +set -e + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +CLAUDE_DIR="$HOME/.claude" +AGENTS_DIR="$CLAUDE_DIR/agents" +PLUGINS_DIR="$CLAUDE_DIR/plugins" + +PASSED=0 +FAILED=0 +WARNINGS=0 + +check_pass() { + echo -e "${GREEN}✓${NC} $1" + PASSED=$((PASSED+1)) +} + +check_fail() { + echo -e "${RED}✗${NC} $1" + FAILED=$((FAILED+1)) +} + +check_warn() { + echo -e "${YELLOW}⚠${NC} $1" + WARNINGS=$((WARNINGS+1)) +} + +check_info() { + echo -e "${BLUE}ℹ${NC} $1" +} + +echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ Claude Code Customizations - Verification ║${NC}" +echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" +echo "" + +# 1. Check directory structure +echo "═══════════════════════════════════════════════════════════" +echo "Directory Structure" +echo "═══════════════════════════════════════════════════════════" + +[ -d "$CLAUDE_DIR" ] && check_pass "Claude directory exists" || check_fail "Claude directory missing" +[ -d "$AGENTS_DIR" ] && check_pass "Agents directory exists" || check_fail "Agents directory missing" +[ -d "$PLUGINS_DIR" ] && check_pass "Plugins directory exists" || check_fail "Plugins directory missing" + +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Agent Categories" +echo "═══════════════════════════════════════════════════════════" + +CATEGORIES=("engineering" "marketing" "product" "studio-operations" "project-management" "testing" "design" "bonus") +AGENT_COUNT=0 + +for category in "${CATEGORIES[@]}"; do + if [ -d "$AGENTS_DIR/$category" ]; then + count=$(ls -1 "$AGENTS_DIR/$category"/*.md 2>/dev/null | wc -l) + if [ $count -gt 0 ]; then + echo -e "${GREEN}✓${NC} $category: $count agents" + AGENT_COUNT=$((AGENT_COUNT + count)) + else + check_warn "$category: directory exists but no agents" + fi + else + check_fail "$category: directory missing" + fi +done + +echo "" +check_info "Total agents: $AGENT_COUNT" + +# 2. Check configuration files +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Configuration Files" +echo "═══════════════════════════════════════════════════════════" + +[ -f "$CLAUDE_DIR/settings.json" ] && check_pass "settings.json exists" || check_fail "settings.json missing" +[ -f "$CLAUDE_DIR/settings.local.json" ] && check_pass "settings.local.json exists" || check_fail "settings.local.json missing" +[ -f "$PLUGINS_DIR/installed_plugins.json" ] && check_pass "installed_plugins.json exists" || check_fail "installed_plugins.json missing" +[ -f "$PLUGINS_DIR/known_marketplaces.json" ] && check_pass "known_marketplaces.json exists" || check_fail "known_marketplaces.json missing" + +# 3. Check MCP tools +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "MCP Tools" +echo "═══════════════════════════════════════════════════════════" + +if command -v npx &> /dev/null; then + check_pass "npx available" + + # Check if @z_ai/mcp-server can be accessed + if npx -y @z_ai/mcp-server --help &> /dev/null; then + check_pass "@z_ai/mcp-server accessible" + else + check_warn "@z_ai/mcp-server not directly accessible (may download on first use)" + fi + + # Check if @z_ai/coding-helper can be accessed + if npx -y @z_ai/coding-helper --help &> /dev/null; then + check_pass "@z_ai/coding-helper accessible" + else + check_warn "@z_ai/coding-helper not directly accessible (may download on first use)" + fi +else + check_fail "npx not available - MCP tools may not work" +fi + +# 4. Check plugins +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Plugins" +echo "═══════════════════════════════════════════════════════════" + +if [ -f "$PLUGINS_DIR/installed_plugins.json" ]; then + # Check if GLM plugins are registered + if grep -q "glm-plan-bug" "$PLUGINS_DIR/installed_plugins.json" 2>/dev/null; then + check_pass "glm-plan-bug plugin registered" + else + check_warn "glm-plan-bug plugin not registered" + fi + + if grep -q "glm-plan-usage" "$PLUGINS_DIR/installed_plugins.json" 2>/dev/null; then + check_pass "glm-plan-usage plugin registered" + else + check_warn "glm-plan-usage plugin not registered" + fi +fi + +# 5. Sample agent check +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Agent Content Verification" +echo "═══════════════════════════════════════════════════════════" + +CRITICAL_AGENTS=( + "engineering/test-writer-fixer.md" + "engineering/frontend-developer.md" + "marketing/tiktok-strategist.md" + "product/sprint-prioritizer.md" + "studio-operations/studio-producer.md" + "project-management/project-shipper.md" + "design/whimsy-injector.md" +) + +for agent in "${CRITICAL_AGENTS[@]}"; do + if [ -f "$AGENTS_DIR/$agent" ]; then + # Check file has content + if [ -s "$AGENTS_DIR/$agent" ]; then + check_pass "$agent exists and has content" + else + check_warn "$agent exists but is empty" + fi + else + check_warn "$agent missing" + fi +done + +# 6. Settings validation +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Settings Validation" +echo "═══════════════════════════════════════════════════════════" + +if [ -f "$CLAUDE_DIR/settings.json" ]; then + # Check if JSON is valid + if python3 -m json.tool "$CLAUDE_DIR/settings.json" &> /dev/null; then + check_pass "settings.json is valid JSON" + + # Check for API token placeholder + if grep -q "YOUR_API_TOKEN_HERE\|YOUR_TOKEN_HERE" "$CLAUDE_DIR/settings.json" 2>/dev/null; then + check_warn "API token not configured (still placeholder)" + else + if grep -q "ANTHROPIC_AUTH_TOKEN" "$CLAUDE_DIR/settings.json" 2>/dev/null; then + check_pass "ANTHROPIC_AUTH_TOKEN is set" + fi + fi + else + check_fail "settings.json is not valid JSON" + fi +fi + +# 7. Summary +echo "" +echo "═══════════════════════════════════════════════════════════" +echo "Summary" +echo "═══════════════════════════════════════════════════════════" + +if [ $FAILED -eq 0 ]; then + echo -e "${GREEN}✓ All critical checks passed!${NC}" + echo "" + echo "Passed: $PASSED" + echo "Warnings: $WARNINGS" + echo "Failed: $FAILED" + echo "" + echo -e "${GREEN}Your Claude Code setup is ready to use!${NC}" + exit 0 +else + echo -e "${RED}✗ Some checks failed${NC}" + echo "" + echo "Passed: $PASSED" + echo "Warnings: $WARNINGS" + echo "Failed: $FAILED" + echo "" + echo "Please fix the failed checks above." + exit 1 +fi diff --git a/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh b/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh index d1e71aa..bdf3a1b 100755 --- a/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh +++ b/skills/ui-ux-pro-max/scripts/wordpress_safe_update.sh @@ -1,82 +1,82 @@ -#!/bin/bash - -# WordPress Safe Content Update Script -# Prevents encoding issues when updating WordPress post content -# Usage: ./wordpress_safe_update.sh - -set -euo pipefail - -# Configuration -DB_NAME="wordpress" -DB_USER="root" -TABLE_PREFIX="wp_" - -# Check arguments -if [ $# -ne 2 ]; then - echo "Usage: $0 " - echo "Example: $0 112 /tmp/article_content.html" - exit 1 -fi - -POST_ID="$1" -HTML_FILE="$2" - -# Verify file exists -if [ ! -f "$HTML_FILE" ]; then - echo "Error: File not found: $HTML_FILE" - exit 1 -fi - -# Verify file is readable -if [ ! -r "$HTML_FILE" ]; then - echo "Error: File is not readable: $HTML_FILE" - exit 1 -fi - -# Check file encoding -FILE_ENCODING=$(file -b --mime-encoding "$HTML_FILE") -if [[ ! "$FILE_ENCODING" =~ utf-8 ]]; then - echo "Warning: File encoding is $FILE_ENCODING, expected utf-8" - echo "Converting to UTF-8..." - iconv -f UTF-8 -t UTF-8 "$HTML_FILE" > "${HTML_FILE}.utf8" - mv "${HTML_FILE}.utf8" "$HTML_FILE" -fi - -# Verify no literal escape sequences -if grep -q '\\n' "$HTML_FILE"; then - echo "Error: File contains literal \\n escape sequences" - echo "Please fix the file before updating WordPress" - exit 1 -fi - -# Backup current content -echo "Backing up current content..." -sudo mysql "${DB_NAME}" --skip-column-names --raw \ - -e "SELECT post_content FROM ${TABLE_PREFIX}posts WHERE ID = ${POST_ID};" \ - > "/tmp/wp_post_${POST_ID}_backup_$(date +%Y%m%d_%H%M%S).html" - -# Update post content -echo "Updating post ID ${POST_ID}..." -sudo mysql "${DB_NAME}" \ - -e "UPDATE ${TABLE_PREFIX}posts SET post_content = LOAD_FILE('${HTML_FILE}') WHERE ID = ${POST_ID};" - -# Verify update -RESULT=$(sudo mysql "${DB_NAME}" --skip-column-names --raw \ - -e "SELECT post_content FROM ${TABLE_PREFIX}posts WHERE ID = ${POST_ID};" \ - | head -20) - -if echo "$RESULT" | grep -q ' + +set -euo pipefail + +# Configuration +DB_NAME="wordpress" +DB_USER="root" +TABLE_PREFIX="wp_" + +# Check arguments +if [ $# -ne 2 ]; then + echo "Usage: $0 " + echo "Example: $0 112 /tmp/article_content.html" + exit 1 +fi + +POST_ID="$1" +HTML_FILE="$2" + +# Verify file exists +if [ ! -f "$HTML_FILE" ]; then + echo "Error: File not found: $HTML_FILE" + exit 1 +fi + +# Verify file is readable +if [ ! -r "$HTML_FILE" ]; then + echo "Error: File is not readable: $HTML_FILE" + exit 1 +fi + +# Check file encoding +FILE_ENCODING=$(file -b --mime-encoding "$HTML_FILE") +if [[ ! "$FILE_ENCODING" =~ utf-8 ]]; then + echo "Warning: File encoding is $FILE_ENCODING, expected utf-8" + echo "Converting to UTF-8..." + iconv -f UTF-8 -t UTF-8 "$HTML_FILE" > "${HTML_FILE}.utf8" + mv "${HTML_FILE}.utf8" "$HTML_FILE" +fi + +# Verify no literal escape sequences +if grep -q '\\n' "$HTML_FILE"; then + echo "Error: File contains literal \\n escape sequences" + echo "Please fix the file before updating WordPress" + exit 1 +fi + +# Backup current content +echo "Backing up current content..." +sudo mysql "${DB_NAME}" --skip-column-names --raw \ + -e "SELECT post_content FROM ${TABLE_PREFIX}posts WHERE ID = ${POST_ID};" \ + > "/tmp/wp_post_${POST_ID}_backup_$(date +%Y%m%d_%H%M%S).html" + +# Update post content +echo "Updating post ID ${POST_ID}..." +sudo mysql "${DB_NAME}" \ + -e "UPDATE ${TABLE_PREFIX}posts SET post_content = LOAD_FILE('${HTML_FILE}') WHERE ID = ${POST_ID};" + +# Verify update +RESULT=$(sudo mysql "${DB_NAME}" --skip-column-names --raw \ + -e "SELECT post_content FROM ${TABLE_PREFIX}posts WHERE ID = ${POST_ID};" \ + | head -20) + +if echo "$RESULT" | grep -q '${NC} ${BOLD}$1${NC}" -} - -print_banner() { - echo -e "${CYAN}${BOLD}" - cat << "EOF" -╔═══════════════════════════════════════════════════════════════╗ -║ ║ -║ ███████╗██╗ █████╗ ██████╗ ║ -║ ██╔════╝██║ ██╔══██╗██╔════╝ ║ -║ ███████╗██║ ███████║██║ ███╗ ║ -║ ╚════██║██║ ██╔══██║██║ ██║ ║ -║ ███████║███████╗██║ ██║╚██████╔╝ ║ -║ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ║ -║ ║ -║ ███████╗██╗ ██╗███████╗███╗ ██╗ ║ -║ ██╔════╝╚██╗██╔╝██╔════╝████╗ ██║ ║ -║ █████╗ ╚███╔╝ █████╗ ██╔██╗ ██║ ║ -║ ██╔══╝ ██╔██╗ ██╔══╝ ██║╚██╗██║ ║ -║ ███████╗██║██╗██║███████╗██║ ╚████║ ║ -║ ╚══════╝╚═╝╚═╝╚═╝╚══════╝╚═╝ ╚═══╝ ║ -║ ║ -║ Ultimate Installation Script ║ -║ ║ -╚═══════════════════════════════════════════════════════════════╝ -EOF - echo -e "${NC}" -} - -check_claude_code() { - log_step "Checking for Claude Code installation..." - - if ! command -v claude &> /dev/null; then - log_error "Claude Code CLI not found!" - echo "Please install Claude Code first: https://claude.com/claude-code" - exit 1 - fi - - log_success "Claude Code found: $(claude --version 2>/dev/null || echo 'installed')" -} - -backup_existing_config() { - log_step "Backing up existing configuration..." - - if [ -d "$CLAUDE_DIR" ]; then - mkdir -p "$BACKUP_DIR" - cp -r "$CLAUDE_DIR" "$BACKUP_DIR/" - log_success "Backup created at: $BACKUP_DIR" - else - log_info "No existing configuration to backup" - fi -} - -install_dependencies() { - if [ "$SKIP_DEPS" = true ]; then - log_warn "Skipping dependency installation" - return - fi - - log_step "Checking and installing dependencies..." - - # Check Python 3 - if ! command -v python3 &> /dev/null; then - log_warn "Python 3 not found. Some features may not work." - else - log_success "Python 3 found: $(python3 --version)" - fi - - # Check Node.js - if ! command -v node &> /dev/null; then - log_warn "Node.js not found. Some features may not work." - else - log_success "Node.js found: $(node --version)" - fi - - # Check Git - if ! command -v git &> /dev/null; then - log_error "Git not found. Please install Git first." - exit 1 - else - log_success "Git found: $(git --version)" - fi - - # Install Ralph Orchestrator if not present - if ! command -v ralph &> /dev/null; then - log_info "Installing Ralph Orchestrator..." - if command -v pip3 &> /dev/null; then - pip3 install ralph-orchestrator 2>/dev/null || log_warn "Failed to install Ralph Orchestrator" - else - log_warn "pip3 not found. Skipping Ralph Orchestrator installation." - fi - else - log_success "Ralph Orchestrator found" - fi -} - -install_skills() { - log_step "Installing custom skills..." - - mkdir -p "$CLAUDE_DIR/skills" - - # Copy all skills - if [ -d "$SCRIPT_DIR/skills" ]; then - cp -r "$SCRIPT_DIR/skills/"* "$CLAUDE_DIR/skills/" 2>/dev/null || true - local skill_count=$(find "$SCRIPT_DIR/skills" -name "SKILL.md" | wc -l) - log_success "Installed $skill_count custom skills" - else - log_warn "Skills directory not found" - fi -} - -install_agents() { - log_step "Installing agent management system..." - - mkdir -p "$CLAUDE_DIR/agents" - - if [ -d "$SCRIPT_DIR/agents" ]; then - cp -r "$SCRIPT_DIR/agents/"* "$CLAUDE_DIR/agents/" 2>/dev/null || true - log_success "Agent management system installed" - - # Make scripts executable - find "$CLAUDE_DIR/agents" -name "*.sh" -exec chmod +x {} \; - else - log_warn "Agents directory not found" - fi -} - -install_hooks() { - log_step "Installing custom hooks..." - - mkdir -p "$CLAUDE_DIR/hooks" - - if [ -d "$SCRIPT_DIR/hooks" ]; then - cp -r "$SCRIPT_DIR/hooks/"* "$CLAUDE_DIR/hooks/" 2>/dev/null || true - - # Make hook scripts executable - find "$CLAUDE_DIR/hooks" -name "*.sh" -exec chmod +x {} \; - - log_success "Custom hooks installed" - else - log_warn "Hooks directory not found" - fi - - # Install hooks.json if it doesn't exist - if [ -f "$SCRIPT_DIR/templates/hooks.json" ] && [ ! -f "$CLAUDE_DIR/hooks.json" ]; then - cp "$SCRIPT_DIR/templates/hooks.json" "$CLAUDE_DIR/hooks.json" - log_success "Hooks configuration installed" - fi -} - -install_commands() { - log_step "Installing custom commands..." - - mkdir -p "$CLAUDE_DIR/commands" - - if [ -d "$SCRIPT_DIR/commands" ]; then - cp -r "$SCRIPT_DIR/commands/"* "$CLAUDE_DIR/commands/" 2>/dev/null || true - local cmd_count=$(ls -1 "$SCRIPT_DIR/commands" 2>/dev/null | wc -l) - log_success "Installed $cmd_count custom commands" - else - log_warn "Commands directory not found" - fi -} - -install_plugins() { - log_step "Installing plugin references..." - - mkdir -p "$CLAUDE_DIR/plugins" - - if [ -d "$SCRIPT_DIR/plugins" ]; then - cp -r "$SCRIPT_DIR/plugins/"* "$CLAUDE_DIR/plugins/" 2>/dev/null || true - local plugin_count=$(find "$SCRIPT_DIR/plugins" -type d -mindepth 1 | wc -l) - log_success "Installed $plugin_count plugin references" - else - log_warn "Plugins directory not found" - fi -} - -install_binaries() { - log_step "Installing custom binaries..." - - mkdir -p "$HOME/.local/bin" - - if [ -f "$SCRIPT_DIR/bin/ralphloop" ]; then - cp "$SCRIPT_DIR/bin/ralphloop" "$HOME/.local/bin/" - chmod +x "$HOME/.local/bin/ralphloop" - - # Add to PATH if not already there - if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then - echo "" >> "$HOME/.bashrc" - echo "# SuperCharge Claude Code - Add local bin to PATH" >> "$HOME/.bashrc" - echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc" - log_info "Added ~/.local/bin to PATH in .bashrc" - fi - - log_success "RalphLoop wrapper installed" - else - log_warn "RalphLoop binary not found" - fi -} - -install_scripts() { - log_step "Installing utility scripts..." - - mkdir -p "$CLAUDE_DIR/scripts" - - if [ -d "$SCRIPT_DIR/scripts" ]; then - cp -r "$SCRIPT_DIR/scripts/"* "$CLAUDE_DIR/scripts/" 2>/dev/null || true - - # Make scripts executable - find "$CLAUDE_DIR/scripts" -name "*.sh" -exec chmod +x {} \; - - log_success "Utility scripts installed" - else - log_warn "Scripts directory not found" - fi -} - -install_config_templates() { - log_step "Installing configuration templates..." - - if [ -d "$SCRIPT_DIR/templates" ]; then - # Install config.json if not exists - if [ -f "$SCRIPT_DIR/templates/config.json" ] && [ ! -f "$CLAUDE_DIR/config.json" ]; then - cp "$SCRIPT_DIR/templates/config.json" "$CLAUDE_DIR/config.json" - log_success "config.json installed" - fi - - # Merge settings.json - if [ -f "$SCRIPT_DIR/templates/settings.json" ]; then - if [ -f "$CLAUDE_DIR/settings.json" ]; then - # Merge existing settings with template - local temp_file=$(mktemp) - python3 -c " -import json -import sys - -try: - with open('$CLAUDE_DIR/settings.json', 'r') as f: - existing = json.load(f) -except: - existing = {} - -try: - with open('$SCRIPT_DIR/templates/settings.json', 'r') as f: - template = json.load(f) -except: - template = {} - -# Merge: template values take precedence for keys that exist in template -for key in template: - if key != 'permissions': # Don't override permissions - existing[key] = template[key] - -with open('$temp_file', 'w') as f: - json.dump(existing, f, indent=2) -" 2>/dev/null || cp "$SCRIPT_DIR/templates/settings.json" "$temp_file" - mv "$temp_file" "$CLAUDE_DIR/settings.json" - else - cp "$SCRIPT_DIR/templates/settings.json" "$CLAUDE_DIR/settings.json" - fi - log_success "settings.json configured" - fi - - # Install settings.local.json if not exists - if [ -f "$SCRIPT_DIR/templates/settings.local.json" ] && [ ! -f "$CLAUDE_DIR/settings.local.json" ]; then - cp "$SCRIPT_DIR/templates/settings.local.json" "$CLAUDE_DIR/settings.local.json" - log_success "settings.local.json installed" - fi - fi -} - -sync_agents() { - log_step "Syncing agents from repository..." - - if [ -f "$CLAUDE_DIR/scripts/sync-agents.sh" ]; then - bash "$CLAUDE_DIR/scripts/sync-agents.sh" 2>/dev/null || log_warn "Agent sync completed with warnings" - log_success "Agent sync completed" - else - log_warn "sync-agents.sh not found" - fi -} - -print_summary() { - echo "" - echo -e "${GREEN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${NC}" - echo -e "${GREEN}${BOLD}║ INSTALLATION COMPLETE! ║${NC}" - echo -e "${GREEN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${NC}" - echo "" - echo -e "${BOLD}Your Claude Code installation is now SUPERCHARGED!${NC}" - echo "" - echo -e "${CYAN}Installed Features:${NC}" - echo -e " ${GREEN}✓${NC} 30+ Custom Skills (cognitive, development, UI/UX)" - echo -e " ${GREEN}✓${NC} RalphLoop Autonomous Agent Integration" - echo -e " ${GREEN}✓${NC} Multi-AI Consultation (Qwen)" - echo -e " ${GREEN}✓${NC} Agent Management System" - echo -e " ${GREEN}✓${NC} Custom Hooks & Commands" - echo -e " ${GREEN}✓${NC} Plugin Marketplace Setup" - echo "" - echo -e "${CYAN}New Commands Available:${NC}" - echo -e " ${YELLOW}/ralph${NC} - Autonomous \"Tackle Until Solved\" agent" - echo -e " ${YELLOW}/brainstorm${NC} - Multi-AI brainstorming session" - echo -e " ${YELLOW}/write-plan${NC} - Create implementation plans" - echo -e " ${YELLOW}/execute-plan${NC} - Execute written plans" - echo "" - echo -e "${CYAN}Quick Start:${NC}" - echo -e " 1. Restart your terminal or run: ${YELLOW}source ~/.bashrc${NC}" - echo -e " 2. Run Claude Code: ${YELLOW}claude${NC}" - echo -e " 3. Try: ${YELLOW}/ralph \"Design a microservices architecture\"${NC}" - echo "" - echo -e "${CYAN}Configuration:${NC}" - echo -e " Config dir: ${YELLOW}$CLAUDE_DIR${NC}" - echo -e " Backup: ${YELLOW}$BACKUP_DIR${NC}" - echo "" - echo -e "${CYAN}Optional Configuration:${NC}" - echo -e " ${YELLOW}export RALPH_AGENT=claude${NC} # Set Ralph agent" - echo -e " ${YELLOW}export RALPH_MAX_ITERATIONS=100${NC} # Set max iterations" - echo -e " ${YELLOW}export QWEN_CONSULT_MODE=always${NC} # Qwen consultation mode" - echo "" - echo -e "${GREEN}${BOLD}Enjoy your supercharged Claude Code experience!${NC}" - echo "" -} - -################################################################################ -# Main Installation -################################################################################ - -main() { - print_banner - - # Parse arguments - while [[ $# -gt 0 ]]; do - case $1 in - --skip-deps) - SKIP_DEPS=true - shift - ;; - --dev-mode) - DEV_MODE=true - set -x - shift - ;; - -h|--help) - echo "Usage: $0 [options]" - echo " --skip-deps Skip dependency installation" - echo " --dev-mode Development mode (verbose output)" - exit 0 - ;; - *) - log_error "Unknown option: $1" - exit 1 - ;; - esac - done - - # Run installation steps - check_claude_code - backup_existing_config - install_dependencies - install_skills - install_agents - install_hooks - install_commands - install_plugins - install_binaries - install_scripts - install_config_templates - sync_agents - - print_summary -} - -# Run main function -main "$@" +#!/bin/bash +################################################################################ +# SuperCharge Claude Code - Ultimate Installation Script +################################################################################ +# This script transforms any Claude Code installation into a supercharged +# version with all customizations, skills, agents, plugins, and integrations. +# +# Features: +# - 30+ Custom Skills (cognitive, development, UI/UX, brainstorming) +# - RalphLoop autonomous agent integration +# - Multi-AI consultation (Qwen integration) +# - Agent management system with sync capabilities +# - Custom hooks for session management +# - MCP servers integration +# - Plugin marketplace setup +# +# Usage: ./supercharge.sh [options] +# --skip-deps Skip dependency installation +# --dev-mode Development mode (verbose output) +################################################################################ + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +BOLD='\033[1m' +NC='\033[0m' # No Color + +# Script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Claude config directory +CLAUDE_DIR="${HOME}/.claude" + +# Backup directory +BACKUP_DIR="${HOME}/.claude-backup-$(date +%Y%m%d_%H%M%S)" + +# Flags +SKIP_DEPS=false +DEV_MODE=false + +################################################################################ +# Helper Functions +################################################################################ + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +log_step() { + echo -e "${CYAN}${BOLD}==>${NC} ${BOLD}$1${NC}" +} + +print_banner() { + echo -e "${CYAN}${BOLD}" + cat << "EOF" +╔═══════════════════════════════════════════════════════════════╗ +║ ║ +║ ███████╗██╗ █████╗ ██████╗ ║ +║ ██╔════╝██║ ██╔══██╗██╔════╝ ║ +║ ███████╗██║ ███████║██║ ███╗ ║ +║ ╚════██║██║ ██╔══██║██║ ██║ ║ +║ ███████║███████╗██║ ██║╚██████╔╝ ║ +║ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ║ +║ ║ +║ ███████╗██╗ ██╗███████╗███╗ ██╗ ║ +║ ██╔════╝╚██╗██╔╝██╔════╝████╗ ██║ ║ +║ █████╗ ╚███╔╝ █████╗ ██╔██╗ ██║ ║ +║ ██╔══╝ ██╔██╗ ██╔══╝ ██║╚██╗██║ ║ +║ ███████╗██║██╗██║███████╗██║ ╚████║ ║ +║ ╚══════╝╚═╝╚═╝╚═╝╚══════╝╚═╝ ╚═══╝ ║ +║ ║ +║ Ultimate Installation Script ║ +║ ║ +╚═══════════════════════════════════════════════════════════════╝ +EOF + echo -e "${NC}" +} + +check_claude_code() { + log_step "Checking for Claude Code installation..." + + if ! command -v claude &> /dev/null; then + log_error "Claude Code CLI not found!" + echo "Please install Claude Code first: https://claude.com/claude-code" + exit 1 + fi + + log_success "Claude Code found: $(claude --version 2>/dev/null || echo 'installed')" +} + +backup_existing_config() { + log_step "Backing up existing configuration..." + + if [ -d "$CLAUDE_DIR" ]; then + mkdir -p "$BACKUP_DIR" + cp -r "$CLAUDE_DIR" "$BACKUP_DIR/" + log_success "Backup created at: $BACKUP_DIR" + else + log_info "No existing configuration to backup" + fi +} + +install_dependencies() { + if [ "$SKIP_DEPS" = true ]; then + log_warn "Skipping dependency installation" + return + fi + + log_step "Checking and installing dependencies..." + + # Check Python 3 + if ! command -v python3 &> /dev/null; then + log_warn "Python 3 not found. Some features may not work." + else + log_success "Python 3 found: $(python3 --version)" + fi + + # Check Node.js + if ! command -v node &> /dev/null; then + log_warn "Node.js not found. Some features may not work." + else + log_success "Node.js found: $(node --version)" + fi + + # Check Git + if ! command -v git &> /dev/null; then + log_error "Git not found. Please install Git first." + exit 1 + else + log_success "Git found: $(git --version)" + fi + + # Install Ralph Orchestrator if not present + if ! command -v ralph &> /dev/null; then + log_info "Installing Ralph Orchestrator..." + if command -v pip3 &> /dev/null; then + pip3 install ralph-orchestrator 2>/dev/null || log_warn "Failed to install Ralph Orchestrator" + else + log_warn "pip3 not found. Skipping Ralph Orchestrator installation." + fi + else + log_success "Ralph Orchestrator found" + fi +} + +install_skills() { + log_step "Installing custom skills..." + + mkdir -p "$CLAUDE_DIR/skills" + + # Copy all skills + if [ -d "$SCRIPT_DIR/skills" ]; then + cp -r "$SCRIPT_DIR/skills/"* "$CLAUDE_DIR/skills/" 2>/dev/null || true + local skill_count=$(find "$SCRIPT_DIR/skills" -name "SKILL.md" | wc -l) + log_success "Installed $skill_count custom skills" + else + log_warn "Skills directory not found" + fi +} + +install_agents() { + log_step "Installing agent management system..." + + mkdir -p "$CLAUDE_DIR/agents" + + if [ -d "$SCRIPT_DIR/agents" ]; then + cp -r "$SCRIPT_DIR/agents/"* "$CLAUDE_DIR/agents/" 2>/dev/null || true + log_success "Agent management system installed" + + # Make scripts executable + find "$CLAUDE_DIR/agents" -name "*.sh" -exec chmod +x {} \; + else + log_warn "Agents directory not found" + fi +} + +install_hooks() { + log_step "Installing custom hooks..." + + mkdir -p "$CLAUDE_DIR/hooks" + + if [ -d "$SCRIPT_DIR/hooks" ]; then + cp -r "$SCRIPT_DIR/hooks/"* "$CLAUDE_DIR/hooks/" 2>/dev/null || true + + # Make hook scripts executable + find "$CLAUDE_DIR/hooks" -name "*.sh" -exec chmod +x {} \; + + log_success "Custom hooks installed" + else + log_warn "Hooks directory not found" + fi + + # Install hooks.json if it doesn't exist + if [ -f "$SCRIPT_DIR/templates/hooks.json" ] && [ ! -f "$CLAUDE_DIR/hooks.json" ]; then + cp "$SCRIPT_DIR/templates/hooks.json" "$CLAUDE_DIR/hooks.json" + log_success "Hooks configuration installed" + fi +} + +install_commands() { + log_step "Installing custom commands..." + + mkdir -p "$CLAUDE_DIR/commands" + + if [ -d "$SCRIPT_DIR/commands" ]; then + cp -r "$SCRIPT_DIR/commands/"* "$CLAUDE_DIR/commands/" 2>/dev/null || true + local cmd_count=$(ls -1 "$SCRIPT_DIR/commands" 2>/dev/null | wc -l) + log_success "Installed $cmd_count custom commands" + else + log_warn "Commands directory not found" + fi +} + +install_plugins() { + log_step "Installing plugin references..." + + mkdir -p "$CLAUDE_DIR/plugins" + + if [ -d "$SCRIPT_DIR/plugins" ]; then + cp -r "$SCRIPT_DIR/plugins/"* "$CLAUDE_DIR/plugins/" 2>/dev/null || true + local plugin_count=$(find "$SCRIPT_DIR/plugins" -type d -mindepth 1 | wc -l) + log_success "Installed $plugin_count plugin references" + else + log_warn "Plugins directory not found" + fi +} + +install_binaries() { + log_step "Installing custom binaries..." + + mkdir -p "$HOME/.local/bin" + + if [ -f "$SCRIPT_DIR/bin/ralphloop" ]; then + cp "$SCRIPT_DIR/bin/ralphloop" "$HOME/.local/bin/" + chmod +x "$HOME/.local/bin/ralphloop" + + # Add to PATH if not already there + if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then + echo "" >> "$HOME/.bashrc" + echo "# SuperCharge Claude Code - Add local bin to PATH" >> "$HOME/.bashrc" + echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc" + log_info "Added ~/.local/bin to PATH in .bashrc" + fi + + log_success "RalphLoop wrapper installed" + else + log_warn "RalphLoop binary not found" + fi +} + +install_scripts() { + log_step "Installing utility scripts..." + + mkdir -p "$CLAUDE_DIR/scripts" + + if [ -d "$SCRIPT_DIR/scripts" ]; then + cp -r "$SCRIPT_DIR/scripts/"* "$CLAUDE_DIR/scripts/" 2>/dev/null || true + + # Make scripts executable + find "$CLAUDE_DIR/scripts" -name "*.sh" -exec chmod +x {} \; + + log_success "Utility scripts installed" + else + log_warn "Scripts directory not found" + fi +} + +install_config_templates() { + log_step "Installing configuration templates..." + + if [ -d "$SCRIPT_DIR/templates" ]; then + # Install config.json if not exists + if [ -f "$SCRIPT_DIR/templates/config.json" ] && [ ! -f "$CLAUDE_DIR/config.json" ]; then + cp "$SCRIPT_DIR/templates/config.json" "$CLAUDE_DIR/config.json" + log_success "config.json installed" + fi + + # Merge settings.json + if [ -f "$SCRIPT_DIR/templates/settings.json" ]; then + if [ -f "$CLAUDE_DIR/settings.json" ]; then + # Merge existing settings with template + local temp_file=$(mktemp) + python3 -c " +import json +import sys + +try: + with open('$CLAUDE_DIR/settings.json', 'r') as f: + existing = json.load(f) +except: + existing = {} + +try: + with open('$SCRIPT_DIR/templates/settings.json', 'r') as f: + template = json.load(f) +except: + template = {} + +# Merge: template values take precedence for keys that exist in template +for key in template: + if key != 'permissions': # Don't override permissions + existing[key] = template[key] + +with open('$temp_file', 'w') as f: + json.dump(existing, f, indent=2) +" 2>/dev/null || cp "$SCRIPT_DIR/templates/settings.json" "$temp_file" + mv "$temp_file" "$CLAUDE_DIR/settings.json" + else + cp "$SCRIPT_DIR/templates/settings.json" "$CLAUDE_DIR/settings.json" + fi + log_success "settings.json configured" + fi + + # Install settings.local.json if not exists + if [ -f "$SCRIPT_DIR/templates/settings.local.json" ] && [ ! -f "$CLAUDE_DIR/settings.local.json" ]; then + cp "$SCRIPT_DIR/templates/settings.local.json" "$CLAUDE_DIR/settings.local.json" + log_success "settings.local.json installed" + fi + fi +} + +sync_agents() { + log_step "Syncing agents from repository..." + + if [ -f "$CLAUDE_DIR/scripts/sync-agents.sh" ]; then + bash "$CLAUDE_DIR/scripts/sync-agents.sh" 2>/dev/null || log_warn "Agent sync completed with warnings" + log_success "Agent sync completed" + else + log_warn "sync-agents.sh not found" + fi +} + +print_summary() { + echo "" + echo -e "${GREEN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${NC}" + echo -e "${GREEN}${BOLD}║ INSTALLATION COMPLETE! ║${NC}" + echo -e "${GREEN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${NC}" + echo "" + echo -e "${BOLD}Your Claude Code installation is now SUPERCHARGED!${NC}" + echo "" + echo -e "${CYAN}Installed Features:${NC}" + echo -e " ${GREEN}✓${NC} 30+ Custom Skills (cognitive, development, UI/UX)" + echo -e " ${GREEN}✓${NC} RalphLoop Autonomous Agent Integration" + echo -e " ${GREEN}✓${NC} Multi-AI Consultation (Qwen)" + echo -e " ${GREEN}✓${NC} Agent Management System" + echo -e " ${GREEN}✓${NC} Custom Hooks & Commands" + echo -e " ${GREEN}✓${NC} Plugin Marketplace Setup" + echo "" + echo -e "${CYAN}New Commands Available:${NC}" + echo -e " ${YELLOW}/ralph${NC} - Autonomous \"Tackle Until Solved\" agent" + echo -e " ${YELLOW}/brainstorm${NC} - Multi-AI brainstorming session" + echo -e " ${YELLOW}/write-plan${NC} - Create implementation plans" + echo -e " ${YELLOW}/execute-plan${NC} - Execute written plans" + echo "" + echo -e "${CYAN}Quick Start:${NC}" + echo -e " 1. Restart your terminal or run: ${YELLOW}source ~/.bashrc${NC}" + echo -e " 2. Run Claude Code: ${YELLOW}claude${NC}" + echo -e " 3. Try: ${YELLOW}/ralph \"Design a microservices architecture\"${NC}" + echo "" + echo -e "${CYAN}Configuration:${NC}" + echo -e " Config dir: ${YELLOW}$CLAUDE_DIR${NC}" + echo -e " Backup: ${YELLOW}$BACKUP_DIR${NC}" + echo "" + echo -e "${CYAN}Optional Configuration:${NC}" + echo -e " ${YELLOW}export RALPH_AGENT=claude${NC} # Set Ralph agent" + echo -e " ${YELLOW}export RALPH_MAX_ITERATIONS=100${NC} # Set max iterations" + echo -e " ${YELLOW}export QWEN_CONSULT_MODE=always${NC} # Qwen consultation mode" + echo "" + echo -e "${GREEN}${BOLD}Enjoy your supercharged Claude Code experience!${NC}" + echo "" +} + +################################################################################ +# Main Installation +################################################################################ + +main() { + print_banner + + # Parse arguments + while [[ $# -gt 0 ]]; do + case $1 in + --skip-deps) + SKIP_DEPS=true + shift + ;; + --dev-mode) + DEV_MODE=true + set -x + shift + ;; + -h|--help) + echo "Usage: $0 [options]" + echo " --skip-deps Skip dependency installation" + echo " --dev-mode Development mode (verbose output)" + exit 0 + ;; + *) + log_error "Unknown option: $1" + exit 1 + ;; + esac + done + + # Run installation steps + check_claude_code + backup_existing_config + install_dependencies + install_skills + install_agents + install_hooks + install_commands + install_plugins + install_binaries + install_scripts + install_config_templates + sync_agents + + print_summary +} + +# Run main function +main "$@"