UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

215 lines 8.28 kB
/** * Lazy-loaded third-party dependencies * Each dependency is loaded only when first needed */ import { LazyLoader } from './lazy-loader.js'; // Playwright lazy loading export const lazyPlaywright = LazyLoader.createLazyModule('playwright', async () => { const startTime = Date.now(); const playwright = await import('playwright'); console.log(`⏱️ Playwright loaded in ${Date.now() - startTime}ms`); return playwright; }); // Browser instance lazy loading with pooling class BrowserPool { static instance = null; static contextPool = []; static maxContexts = 5; static async getBrowser() { if (!this.instance) { const playwright = await lazyPlaywright.load(); console.log('🌐 Launching browser instance...'); this.instance = await playwright.chromium.launch({ headless: true, args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--no-first-run', '--no-zygote', '--disable-gpu' ] }); } return this.instance; } static async getContext() { // Reuse existing context if available if (this.contextPool.length > 0) { return this.contextPool.pop(); } const browser = await this.getBrowser(); return browser.newContext({ viewport: { width: 1280, height: 720 }, userAgent: 'Mozilla/5.0 (AI-Debug-Local-MCP) AppleWebKit/537.36' }); } static async releaseContext(context) { try { // Clear cookies and storage await context.clearCookies(); await context.clearPermissions(); // Return to pool if under limit if (this.contextPool.length < this.maxContexts) { this.contextPool.push(context); } else { await context.close(); } } catch (error) { console.error('Error releasing context:', error); try { await context.close(); } catch { } } } static async cleanup() { // Close all contexts for (const context of this.contextPool) { try { await context.close(); } catch { } } this.contextPool = []; // Close browser if (this.instance) { try { await this.instance.close(); } catch { } this.instance = null; } } } export const lazyBrowser = { getBrowser: () => BrowserPool.getBrowser(), getContext: () => BrowserPool.getContext(), releaseContext: (context) => BrowserPool.releaseContext(context), cleanup: () => BrowserPool.cleanup(), getPlaywright: () => lazyPlaywright.load() }; // Tidewave lazy loading export const lazyTidewave = LazyLoader.createLazyModule('tidewave', async () => { const { TidewaveIntegration } = await import('../tidewave-integration.js'); return new TidewaveIntegration(); }); // Framework-specific engines lazy loading export const lazyNextJsEngine = LazyLoader.createLazyModule('nextjs-engine', async () => { const { NextJSDebugEngine } = await import('../nextjs-debug-engine.js'); return NextJSDebugEngine; }); export const lazyFlutterEngine = LazyLoader.createLazyModule('flutter-engine', async () => { const { FlutterDebugEngine } = await import('../flutter-debug-engine.js'); return FlutterDebugEngine; }); export const lazyPythonEngine = LazyLoader.createLazyModule('python-engine', async () => { const { PythonBackendEngine } = await import('../python-backend-engine.js'); return PythonBackendEngine; }); export const lazyDatabaseEngine = LazyLoader.createLazyModule('database-engine', async () => { const { DatabaseTraceEngine } = await import('../database-trace-engine.js'); return DatabaseTraceEngine; }); export const lazyRailsEngine = LazyLoader.createLazyModule('rails-engine', async () => { const { ServerFrameworkDebugEngine } = await import('../server-framework-debug-engine.js'); return ServerFrameworkDebugEngine; }); export const lazyMetaFrameworkEngine = LazyLoader.createLazyModule('meta-framework-engine', async () => { const { MetaFrameworkDebugEngine } = await import('../meta-framework-debug-engine-modular.js'); return MetaFrameworkDebugEngine; }); export const lazyGraphQLEngine = LazyLoader.createLazyModule('graphql-engine', async () => { const { GraphQLHandler } = await import('../handlers/graphql/graphql-handler.js'); return GraphQLHandler; }); // Test and TDD engines export const lazyTDDEngine = LazyLoader.createLazyModule('tdd-engine', async () => { const { TDDDebugEngine } = await import('../tdd-debug-engine.js'); return TDDDebugEngine; }); // AI and analysis engines export const lazyAITestEngine = LazyLoader.createLazyModule('ai-test-engine', async () => { const { TestGeneratorAI } = await import('../test-generator-ai.js'); return new TestGeneratorAI(); }); export const lazyEvolutionEngine = LazyLoader.createLazyModule('evolution-engine', async () => { const { TestEvolutionEngine } = await import('../test-evolution-engine.js'); return new TestEvolutionEngine(); }); // Performance and profiling engines export const lazyPerformanceProfiler = LazyLoader.createLazyModule('performance-profiler', async () => { const { PerformanceProfiler } = await import('../performance-profiler.js'); return new PerformanceProfiler(); }); // Audit and validation engines export const lazyAuditEngine = LazyLoader.createLazyModule('audit-engine', async () => { const { AuditEngine } = await import('../audit-engine.js'); return new AuditEngine(); }); // Visual regression engine export const lazyVisualEngine = LazyLoader.createLazyModule('visual-engine', async () => { const { VisualValidationEngine } = await import('../utils/visual-validation-engine.js'); return new VisualValidationEngine(); }); // Fault injection engine export const lazyFaultInjectionEngine = LazyLoader.createLazyModule('fault-injection-engine', async () => { const { FaultInjectionEngine } = await import('../fault-injection-engine.js'); return new FaultInjectionEngine(); }); /** * Map of all lazy-loadable modules */ export const LAZY_MODULES = { 'playwright': lazyPlaywright, 'tidewave': lazyTidewave, 'nextjs-engine': lazyNextJsEngine, 'flutter-engine': lazyFlutterEngine, 'python-engine': lazyPythonEngine, 'database-engine': lazyDatabaseEngine, 'rails-engine': lazyRailsEngine, 'meta-framework-engine': lazyMetaFrameworkEngine, 'graphql-engine': lazyGraphQLEngine, 'tdd-engine': lazyTDDEngine, 'ai-test-engine': lazyAITestEngine, 'evolution-engine': lazyEvolutionEngine, 'performance-profiler': lazyPerformanceProfiler, 'audit-engine': lazyAuditEngine, 'visual-engine': lazyVisualEngine, 'fault-injection-engine': lazyFaultInjectionEngine }; /** * Load dependencies required for a specific tool */ export async function loadToolDependencies(toolName) { const { getComprehensiveToolDependencies } = await import('./comprehensive-tool-dependencies.js'); const deps = getComprehensiveToolDependencies(toolName); const loadedModules = new Map(); for (const dep of deps) { const lazyModule = LAZY_MODULES[dep]; if (lazyModule) { try { const module = await lazyModule.load(); loadedModules.set(dep, module); } catch (error) { console.error(`Failed to load ${dep} for ${toolName}:`, error); } } } return loadedModules; } /** * Cleanup all lazy-loaded resources */ export async function cleanupLazyDependencies() { console.log('🧹 Cleaning up lazy-loaded dependencies...'); // Cleanup browser pool await lazyBrowser.cleanup(); // Unload all modules LazyLoader.unloadAll(); } //# sourceMappingURL=lazy-dependencies.js.map