UNPKG

@hivetechs/hive-ai

Version:

Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API

236 lines (203 loc) • 7.69 kB
#!/usr/bin/env node /** * Smart Post-Install Setup for Hive AI * * Automatically configures MCP integration for all supported IDEs when users install/update * the package, ensuring they always get the latest HTTP+SSE streaming MCP tools. * * Supported IDEs: Claude Code, VS Code, Cursor, Windsurf */ import { execSync } from 'child_process'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { readFileSync } from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); class PostInstallSetup { constructor() { this.isGlobalInstall = this.detectGlobalInstall(); this.detectedIDEs = this.detectSupportedIDEs(); } /** * Detect if this is a global npm install */ detectGlobalInstall() { try { // Check if we're in global node_modules if (__dirname.includes('node_modules/@hivetechs/hive-ai') && (__dirname.includes('/usr/local/lib/node_modules') || __dirname.includes('/opt/homebrew/lib/node_modules') || __dirname.includes('AppData/Roaming/npm/node_modules'))) { return true; } // Alternative: check npm prefix const npmPrefix = execSync('npm prefix -g', { encoding: 'utf8', stdio: 'pipe' }).trim(); return __dirname.includes(npmPrefix); } catch (e) { // Default to local install if detection fails return false; } } /** * Detect all supported IDEs that are installed */ detectSupportedIDEs() { const IDEs = { 'claude-code': { name: 'Claude Code', command: 'claude --version' }, 'vscode': { name: 'VS Code', command: 'code --version' }, 'cursor': { name: 'Cursor', command: 'cursor --version' }, 'windsurf': { name: 'Windsurf', command: 'windsurf --version' } }; const detected = {}; let totalDetected = 0; for (const [ideKey, ideInfo] of Object.entries(IDEs)) { try { execSync(ideInfo.command, { stdio: 'pipe' }); detected[ideKey] = ideInfo.name; totalDetected++; } catch (e) { // IDE not installed or not in PATH } } return { detected, totalDetected }; } /** * Show welcome message */ showWelcomeMessage() { // Read version dynamically from package.json const packagePath = join(__dirname, '..', 'package.json'); let version = '1.18.7'; // fallback try { const pkg = JSON.parse(readFileSync(packagePath, 'utf8')); version = pkg.version; } catch (e) { // Use fallback version } // Build IDE status message let ideStatus = ''; if (this.detectedIDEs.totalDetected > 0) { const ideList = Object.values(this.detectedIDEs.detected).join(', '); ideStatus = `āœ… Detected ${this.detectedIDEs.totalDetected} IDE(s): ${ideList} šŸ”„ HTTP+SSE MCP configurations updated automatically!`; } else { ideStatus = `āš ļø No supported IDEs found šŸ’” Install Claude Code, VS Code, Cursor, or Windsurf to use MCP tools`; } console.log(` šŸ Hive.AI v${version} installed! šŸš€ MULTI-IDE INTEGRATION WITH HTTP+SSE STREAMING: ${ideStatus} ✨ New in v${version} - Real-time Streaming & 18 MCP Tools: • Infrastructure as Code (config apply/export/validate/template) • Environment Management (dev/staging/production) • Model Management (320+ models from 55+ providers) • Expert Templates (coding/research/creative presets) • Cost Management (budget optimization) • Backup & Recovery (database protection) • Health Monitoring (system diagnostics) • Performance Analytics (bottleneck analysis) • Business Intelligence (executive reports) • System Management (status/profiles/intelligence) 🌊 STREAMING FEATURES: • Real-time consensus output (no more collapsed +1223 lines) • Live progress updates during AI processing • Server-Sent Events (SSE) for instant feedback • Compatible with all modern IDEs šŸ“‹ Quick Start: 1. Setup: hive setup 2. Start MCP: hive mcp-server start 3. Open your IDE and try: "hive run consensus on React best practices" šŸ”— Links: • License: https://hivetechs.io/pricing • OpenRouter: https://openrouter.ai/keys • Docs: https://hivetechs.io/docs `); } /** * Check for running MCP server processes that need to be restarted * Now detects both old stdio processes and new HTTP+SSE servers */ checkRunningMCPProcesses() { try { // Check for old stdio MCP server processes const stdioResult = execSync('ps aux | grep -v grep | grep hive-mcp-server', { encoding: 'utf8', stdio: 'pipe' }); // Check for HTTP+SSE MCP server on default port 3000 const httpResult = execSync('lsof -ti:3000 2>/dev/null || echo ""', { encoding: 'utf8', stdio: 'pipe' }); // Check for Node.js processes running our HTTP MCP server const nodeResult = execSync('ps aux | grep -v grep | grep "node.*hive.*mcp"', { encoding: 'utf8', stdio: 'pipe' }); const hasStdioProcess = stdioResult.trim().length > 0; const hasHttpProcess = httpResult.trim().length > 0; const hasNodeProcess = nodeResult.trim().length > 0; return hasStdioProcess || hasHttpProcess || hasNodeProcess; } catch (e) { // No running processes found return false; } } /** * Automatically configure MCP integration for all detected IDEs */ async updateIDEConfigurations() { if (!this.isGlobalInstall || this.detectedIDEs.totalDetected === 0) { return; } try { console.log('šŸ”„ Configuring HTTP+SSE MCP integration for detected IDEs...'); // Find the hive CLI path const hivePath = join(__dirname, '..', 'dist', 'cli.js'); // Run the universal IDE setup command silently execSync(`node "${hivePath}" setup-ide --silent`, { stdio: ['pipe', 'pipe', 'pipe'], timeout: 30000 }); const ideList = Object.values(this.detectedIDEs.detected).join(', '); console.log(`āœ… HTTP+SSE MCP configuration updated for: ${ideList}`); // Check for running MCP processes that need to be managed const hasRunningMCP = this.checkRunningMCPProcesses(); if (hasRunningMCP) { console.log('āš ļø IMPORTANT: Old MCP processes detected!'); console.log('šŸ”„ To enable HTTP+SSE streaming and latest features:'); console.log(' 1. Stop old MCP processes: hive mcp-server stop'); console.log(' 2. Start new HTTP server: hive mcp-server start'); console.log(' 3. Restart your IDE(s)'); console.log('šŸ’” This enables real-time streaming consensus output!'); } else { console.log('šŸš€ Next steps:'); console.log(' 1. Start MCP server: hive mcp-server start'); console.log(' 2. Restart your IDE(s) to load HTTP+SSE configuration'); console.log('šŸ’” Enjoy real-time streaming with all 18 MCP tools!'); } } catch (error) { // Silently fail - don't interrupt the install process console.log('šŸ’” Run "hive setup-ide" to configure multi-IDE integration'); } } /** * Main setup process */ async run() { try { this.showWelcomeMessage(); await this.updateIDEConfigurations(); } catch (error) { // Never fail the install process console.log('šŸ’” Installation complete! Run "hive setup" to get started.'); } } } // Run the setup const setup = new PostInstallSetup(); setup.run().catch(() => { // Ensure npm install never fails due to our post-install script process.exit(0); });