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

332 lines • 14.5 kB
/** * V2 Project-Aware Lazy Loading Strategy * Intelligently loads only tools relevant to the detected project framework * Saves 5-8MB memory while maintaining zero workflow delay for stateless HTTP server */ /** * V2 Framework-to-Tools Mapping * Optimized for stateless HTTP architecture */ export const V2_FRAMEWORK_TOOL_MAPPING = { // Flutter Web Projects 'flutter-web': { framework: 'flutter-web', immediateTools: [ // Core debugging essentials (always needed) 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // Flutter-specific tools (user's primary workflow) 'flutter_config', 'flutter_diagnostics', 'flutter_widget_tree', 'flutter_quantum_interact', 'flutter_quantum_analyze', // Universal debugging tools 'simulate_user_action', 'monitor_realtime', 'get_console_logs', 'get_performance_metrics', // Sub-agent delegation (V2 feature) 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // NextJS tools (irrelevant for Flutter) 'nextjs_page_info', 'nextjs_config', 'nextjs_app_router_info', // Backend framework tools 'phoenix_live_dashboard', 'elixir_inspect_process', 'python_trace_request', 'django_debug_orm', // Meta-framework tools 'remix_debug_loaders', 'astro_debug_islands' ], estimatedMemorySavingsMB: 8, reasoning: 'V2: Flutter projects need Flutter-specific debugging + universal tools. Backend/other frontend tools stay lazy.' }, // NextJS Projects 'nextjs': { framework: 'nextjs', immediateTools: [ // Core debugging essentials 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // NextJS-specific tools 'nextjs_page_info', 'nextjs_config', 'nextjs_app_router_info', 'nextjs_detect_issues', 'nextjs_bundle_analyze', // React tools (NextJS is React-based) 'react_inspect_components', 'react_debug_state', // Universal debugging tools 'simulate_user_action', 'monitor_realtime', // Performance tools (critical for NextJS) 'performance_baseline', 'performance_profile', 'analyze_bundles', // Sub-agent delegation 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // Flutter tools (different frontend framework) 'flutter_config', 'flutter_diagnostics', 'flutter_widget_tree', // Backend framework tools 'phoenix_live_dashboard', 'elixir_inspect_process', 'python_trace_request', 'django_debug_orm', // Vue/Angular tools 'vue_debug_reactivity', 'angular_debug_change_detection' ], estimatedMemorySavingsMB: 7, reasoning: 'V2: NextJS projects need React + NextJS tools + performance analysis. Other frameworks stay lazy.' }, // Phoenix LiveView + live_svelte Projects 'phoenix-liveview-svelte': { framework: 'phoenix-liveview-svelte', immediateTools: [ // Core debugging essentials 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // Phoenix/LiveView tools 'debug_liveview_connection', 'phoenix_live_dashboard', 'phoenix_analyze_router', 'phoenix_analyze_events', // Elixir tools 'elixir_inspect_process', 'ecto_trace_queries', // Svelte-specific tools 'svelte_debug_stores', 'svelte_analyze_reactivity', 'svelte_component_tree', 'svelte_debug_events', // LiveView-Svelte integration tools 'liveview_svelte_bridge', 'debug_hook_lifecycle', 'trace_prop_flow', 'debug_event_propagation', // Universal debugging tools 'simulate_user_action', 'monitor_realtime', 'get_console_logs', 'get_performance_metrics', // Sub-agent delegation 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // Other frontend framework tools 'flutter_config', 'flutter_diagnostics', 'nextjs_page_info', 'nextjs_config', 'react_inspect_components', 'vue_debug_reactivity', 'angular_debug_change_detection', // Backend tools for other languages 'python_trace_request', 'django_debug_orm', 'rails_debug_middleware' ], estimatedMemorySavingsMB: 6, reasoning: 'V2: LiveView + Svelte hybrid needs both Phoenix backend tools and Svelte frontend tools, plus integration debugging.' }, // Phoenix LiveView Projects (without Svelte) 'phoenix-liveview': { framework: 'phoenix-liveview', immediateTools: [ // Core debugging essentials 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // Phoenix/LiveView tools 'debug_liveview_connection', 'phoenix_live_dashboard', 'phoenix_analyze_router', 'phoenix_analyze_events', // Elixir tools 'elixir_inspect_process', 'ecto_trace_queries', // Universal debugging tools 'simulate_user_action', 'monitor_realtime', // Sub-agent delegation 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // Frontend framework tools (Phoenix handles UI via LiveView) 'flutter_config', 'nextjs_page_info', 'react_inspect_components', 'vue_debug_reactivity', 'angular_debug_change_detection', // Python backend tools 'python_trace_request', 'django_debug_orm', // Meta-framework tools 'remix_debug_loaders', 'astro_debug_islands' ], estimatedMemorySavingsMB: 6, reasoning: 'V2: Phoenix projects need Elixir + LiveView tools. Frontend frameworks stay lazy.' }, // React Projects (standalone) 'react': { framework: 'react', immediateTools: [ // Core debugging essentials 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // React tools 'react_inspect_components', 'react_debug_state', 'react_dev_tools', // Universal debugging 'simulate_user_action', 'monitor_realtime', 'get_console_logs', 'get_performance_metrics', // Sub-agent delegation 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // Other frontend frameworks 'flutter_config', 'vue_debug_reactivity', 'angular_debug_change_detection', // Backend frameworks 'phoenix_live_dashboard', 'python_trace_request', // Meta-frameworks (unless specifically NextJS) 'nextjs_app_router_info', 'remix_debug_loaders' ], estimatedMemorySavingsMB: 5, reasoning: 'V2: React projects need React tools + universal debugging. Other frameworks stay lazy.' }, // Svelte Projects 'svelte': { framework: 'svelte', immediateTools: [ // Core debugging essentials 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // Svelte-specific tools 'svelte_debug_stores', 'svelte_analyze_reactivity', 'svelte_component_tree', 'svelte_debug_events', 'svelte_inspect_bindings', 'svelte_debug_lifecycle', // Universal frontend tools 'simulate_user_action', 'monitor_realtime', 'get_console_logs', 'get_performance_metrics', 'analyze_bundles', 'performance_profile', // Sub-agent delegation 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // Other framework tools 'flutter_config', 'nextjs_page_info', 'react_inspect_components', 'vue_debug_reactivity', 'angular_debug_change_detection', // Backend tools 'phoenix_live_dashboard', 'elixir_inspect_process', 'python_trace_request', 'rails_debug_middleware' ], estimatedMemorySavingsMB: 7, reasoning: 'V2: Svelte projects need Svelte-specific reactive debugging + universal frontend tools.' }, // Default/Unknown Projects 'unknown': { framework: 'unknown', immediateTools: [ // Core debugging essentials only 'inject_debugging', 'take_screenshot', 'run_audit', 'get_debug_report', 'list_tools', // Universal debugging tools 'simulate_user_action', 'monitor_realtime', 'get_console_logs', 'get_performance_metrics', // Sub-agent delegation (always useful) 'delegate_to_debug_agent', 'smart_debug', 'auto_audit' ], lazyTools: [ // All framework-specific tools stay lazy until needed 'flutter_config', 'nextjs_page_info', 'phoenix_live_dashboard', 'react_inspect_components', 'vue_debug_reactivity', 'python_trace_request', 'django_debug_orm' ], estimatedMemorySavingsMB: 10, reasoning: 'V2: Unknown projects get only core tools. All framework-specific tools stay lazy for maximum memory savings.' } }; /** * V2 Project-Aware Loading Strategy Manager * Optimized for stateless HTTP server architecture */ export class V2ProjectAwareLoadingStrategy { detectedFramework; currentStrategy; /** * Analyze framework detection result and determine loading strategy */ determineStrategy(frameworkResult) { const framework = frameworkResult.framework; this.detectedFramework = framework; // Get strategy for detected framework let strategy = V2_FRAMEWORK_TOOL_MAPPING[framework]; if (!strategy) { // Handle framework variations if (framework.includes('nextjs') || framework.includes('next.js')) { strategy = V2_FRAMEWORK_TOOL_MAPPING['nextjs']; } else if (framework.includes('react')) { strategy = V2_FRAMEWORK_TOOL_MAPPING['react']; } else if (framework.includes('flutter')) { strategy = V2_FRAMEWORK_TOOL_MAPPING['flutter-web']; } else if (framework.includes('phoenix')) { // Handle phoenix variations if (framework === 'phoenix-liveview-svelte') { strategy = V2_FRAMEWORK_TOOL_MAPPING['phoenix-liveview-svelte']; } else if (framework === 'phoenix-liveview') { strategy = V2_FRAMEWORK_TOOL_MAPPING['phoenix-liveview']; } else { strategy = V2_FRAMEWORK_TOOL_MAPPING['phoenix-liveview']; } } else if (framework.includes('svelte')) { strategy = V2_FRAMEWORK_TOOL_MAPPING['svelte']; } else if (framework.includes('elixir')) { strategy = V2_FRAMEWORK_TOOL_MAPPING['phoenix-liveview']; } else { // Default to unknown strategy for maximum memory savings strategy = V2_FRAMEWORK_TOOL_MAPPING['unknown']; } } this.currentStrategy = strategy; return strategy; } /** * Get current loading strategy */ getCurrentStrategy() { return this.currentStrategy; } /** * Check if a tool should be immediately loaded for current project */ shouldLoadImmediately(toolName) { if (!this.currentStrategy) { // No framework detected yet - load core tools only const coreTools = ['inject_debugging', 'take_screenshot', 'run_audit', 'list_tools']; return coreTools.includes(toolName); } return this.currentStrategy.immediateTools.includes(toolName); } /** * Get memory optimization info */ getOptimizationInfo() { if (!this.currentStrategy) { return { framework: 'unknown', immediateToolsCount: 0, lazyToolsCount: 0, estimatedSavingsMB: 0 }; } return { framework: this.currentStrategy.framework, immediateToolsCount: this.currentStrategy.immediateTools.length, lazyToolsCount: this.currentStrategy.lazyTools.length, estimatedSavingsMB: this.currentStrategy.estimatedMemorySavingsMB }; } } /** * V2 Adaptive Strategy (simplified for stateless architecture) */ export class V2AdaptiveProjectAwareStrategy extends V2ProjectAwareLoadingStrategy { memoryPressureThreshold = 512; // MB /** * Adapt strategy based on current memory usage */ adaptToMemoryPressure(currentMemoryMB) { const baseStrategy = this.getCurrentStrategy(); if (!baseStrategy) { return V2_FRAMEWORK_TOOL_MAPPING['unknown']; } // If under memory pressure, reduce immediate tools if (currentMemoryMB > this.memoryPressureThreshold) { const adaptedStrategy = { ...baseStrategy, immediateTools: baseStrategy.immediateTools.filter(tool => // Keep only essential core tools under memory pressure ['inject_debugging', 'take_screenshot', 'run_audit', 'list_tools'].includes(tool)), reasoning: `${baseStrategy.reasoning} [ADAPTED: Memory pressure detected - reduced to core tools only]`, estimatedMemorySavingsMB: baseStrategy.estimatedMemorySavingsMB + 3 }; console.error(`🧠 V2 Memory pressure adaptation: Reduced immediate tools from ${baseStrategy.immediateTools.length} to ${adaptedStrategy.immediateTools.length}`); return adaptedStrategy; } return baseStrategy; } } //# sourceMappingURL=project-aware-loading-strategy.js.map