Skip to content
Shell
3.2 KB
Raw Blame
#!/bin/bash
# Playwright Agent Coordinator - Installation Script
# Built at ID8Labs - https://id8labs.com
#
# This script installs the Playwright Agent Coordination System
# for multi-agent browser pool management.

set -e

echo "🎭 Playwright Agent Coordinator Installer"
echo "=========================================="
echo ""

INSTALL_DIR="$HOME/.claude/playwright-coordinator"

# Check if already installed
if [ -d "$INSTALL_DIR" ] && [ -f "$INSTALL_DIR/coordinator.ts" ]; then
    echo "βœ“ Already installed at $INSTALL_DIR"
    echo ""
    read -p "Reinstall/update? (y/N): " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "Aborted."
        exit 0
    fi
fi

echo "πŸ“¦ Installing to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"

# Check for Node.js
if ! command -v node &> /dev/null; then
    echo "❌ Node.js is required but not installed."
    echo "   Install from: https://nodejs.org/"
    exit 1
fi

echo "βœ“ Node.js found: $(node --version)"

# Install dependencies
echo "πŸ“₯ Installing dependencies..."
cd "$INSTALL_DIR"

if [ ! -f "package.json" ]; then
    cat > package.json << 'PKGJSON'
{
  "name": "playwright-coordinator",
  "version": "1.0.0",
  "description": "Multi-agent Playwright browser pool coordinator",
  "type": "module",
  "scripts": {
    "build": "tsc",
    "cli": "npx ts-node cli.ts"
  },
  "dependencies": {
    "@modelcontextprotocol/sdk": "^1.0.0",
    "typescript": "^5.0.0",
    "ts-node": "^10.9.0"
  }
}
PKGJSON
fi

npm install --silent 2>/dev/null || npm install

# Initialize state if needed
if [ ! -f "state.json" ]; then
    echo "πŸ“ Initializing pool state..."
    cat > state.json << 'STATEJSON'
{
  "contexts": {
    "context_1": { "status": "available" },
    "context_2": { "status": "available" },
    "context_3": { "status": "available" },
    "context_4": { "status": "available" },
    "context_5": { "status": "available" },
    "context_6": { "status": "available" }
  },
  "waitQueue": [],
  "shareRequests": [],
  "lastCleanup": null
}
STATEJSON
fi

# Make hooks executable
if [ -d "hooks" ]; then
    chmod +x hooks/*.sh 2>/dev/null || true
fi

# Build MCP server
if [ -d "mcp-server" ] && [ -f "mcp-server/src/index.ts" ]; then
    echo "πŸ”¨ Building MCP server..."
    cd mcp-server
    npm install --silent 2>/dev/null || npm install
    npm run build 2>/dev/null || npx tsc
    cd ..
fi

echo ""
echo "βœ… Installation complete!"
echo ""
echo "πŸ“‹ Next steps:"
echo ""
echo "1. Add to ~/.mcp.json:"
echo '   "playwright-coordinator": {'
echo '     "command": "node",'
echo '     "args": ["'$INSTALL_DIR'/mcp-server/dist/index.js"]'
echo '   }'
echo ""
echo "2. Add hooks to ~/.claude/settings.local.json:"
echo '   "PreToolUse": [{'
echo '     "matcher": "mcp__playwright-server__*",'
echo '     "hooks": [{ "type": "command", "command": "'$INSTALL_DIR'/hooks/pre-playwright.sh" }]'
echo '   }],'
echo '   "PostToolUse": [{'
echo '     "matcher": "mcp__playwright-server__*",'
echo '     "hooks": [{ "type": "command", "command": "'$INSTALL_DIR'/hooks/post-playwright.sh" }]'
echo '   }]'
echo ""
echo "3. Restart Claude Code"
echo ""
echo "πŸ“– Docs: $INSTALL_DIR/ETIQUETTE.md"
echo "πŸ”§ Test: Use playwright_pool_status MCP tool"
echo ""
echo "Built at ID8Labs - We don't ask for permission to solve our problems."