version: 1
kind: action
name: Performance Check
description: Basic performance analysis and optimization recommendations
prompt: |
  Perform comprehensive performance analysis and provide optimization recommendations.
  Analyze build times, bundle sizes, and identify performance bottlenecks.
  Generate actionable recommendations for improvement with measurable results.
  Use this for identifying performance issues and implementing optimizations.
enhanced-prompt: |-
  # ⚡ Performance Analysis

  ## Basic Performance Measurement
  ```bash
  PROJECT_NAME=$(basename $(pwd))
  echo "📁 Project: $PROJECT_NAME"

  # Measure build time
  if [ -f "package.json" ]; then
    echo "⏱️ Measuring build time..."
    START_TIME=$(date +%s)
    
    if npm run build >/dev/null 2>&1; then
      END_TIME=$(date +%s)
      BUILD_TIME=$((END_TIME - START_TIME))
      echo "✅ Build completed in ${BUILD_TIME}s"
    else
      echo "❌ Build failed or script not found"
    fi
  fi
  ```

  ## Bundle Size Analysis
  ```bash
  echo "📦 Analyzing bundle size..."

  # Check build file sizes
  if [ -d "dist" ] || [ -d "build" ]; then
    echo "📊 Bundle file sizes:"
    find dist/ build/ -name "*.js" -o -name "*.css" 2>/dev/null | while read file; do
      if [ -f "$file" ]; then
        SIZE=$(du -h "$file" | cut -f1)
        echo "  - $(basename "$file"): $SIZE"
      fi
    done
  fi

  # Check node_modules size
  if [ -d "node_modules" ]; then
    MODULES_SIZE=$(du -sh node_modules 2>/dev/null | cut -f1)
    echo "📚 node_modules size: $MODULES_SIZE"
  fi
  ```

  ## Performance Issue Detection
  ```bash
  echo "🔍 Detecting performance issues..."

  # Find large files
  echo "📄 Large source files (top 5):"
  find src/ -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" 2>/dev/null | \
    xargs wc -l 2>/dev/null | sort -nr | head -5 | while read lines file; do
      echo "  - $(basename "$file"): $lines lines"
    done

  # Detect synchronous operations
  echo "⚠️ Synchronous operation patterns:"
  SYNC_OPS=$(grep -r "readFileSync\|writeFileSync\|execSync" --include="*.js" --include="*.ts" src/ 2>/dev/null | wc -l)
  echo "  - Synchronous file operations: $SYNC_OPS"
  ```

  **🎯 Result:** Performance analysis with optimization recommendations
