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
667 lines • 32 kB
JavaScript
/**
* Project-Aware Lazy Loading Strategy
* Intelligently loads only tools relevant to the detected project framework
* Saves 5-8MB memory while maintaining zero workflow delay
*/
/**
* Framework-to-Tools Mapping
* Maps detected frameworks to their essential tool sets
*/
export const FRAMEWORK_TOOL_MAPPING = {
// Flutter Web Projects
'flutter-web': {
framework: 'flutter-web',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Flutter-specific tools (user's primary workflow)
'flutter_config', 'flutter_diagnostics', 'flutter_widget_tree',
'flutter_inspect_widget', 'flutter_quantum_interact', 'flutter_quantum_analyze',
'flutter_enable_accessibility', 'flutter_quantum_find',
// Universal debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// NextJS tools (irrelevant for Flutter)
'nextjs_page_info', 'nextjs_config', 'nextjs_app_router_info', 'nextjs_bundle_analyze',
// Phoenix/Elixir tools (backend framework, not needed for Flutter frontend)
'debug_liveview_connection', 'phoenix_live_dashboard', 'elixir_inspect_process',
// Python backend tools (different stack)
'python_trace_request', 'django_debug_orm', 'flask_debug_routes',
// Meta-framework tools (not Flutter)
'remix_debug_loaders', 'astro_debug_islands', 'nuxt_debug_nitro'
],
estimatedMemorySavingsMB: 7,
reasoning: 'Flutter projects need Flutter-specific debugging + universal tools. NextJS/Phoenix/Python tools are irrelevant and can stay lazy.'
},
// NextJS Projects
'nextjs': {
framework: 'nextjs',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// NextJS-specific tools (user's primary workflow)
'nextjs_page_info', 'nextjs_config', 'nextjs_app_router_info', 'nextjs_detect_issues',
'nextjs_bundle_analyze', 'nextjs_server_components', 'nextjs_perf_score',
// React tools (NextJS is React-based)
'react_inspect_components', 'react_debug_state',
// Universal debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime',
// Performance tools (critical for NextJS)
'performance_baseline', 'performance_profile', 'analyze_bundles'
],
lazyTools: [
// Flutter tools (different frontend framework)
'flutter_config', 'flutter_diagnostics', 'flutter_widget_tree', 'flutter_quantum_interact',
// Phoenix/Elixir tools (backend framework)
'debug_liveview_connection', 'phoenix_live_dashboard', 'elixir_inspect_process',
// Vue/Angular tools (different frontend frameworks)
'vue_debug_reactivity', 'angular_debug_change_detection'
],
estimatedMemorySavingsMB: 6,
reasoning: 'NextJS projects need React + NextJS tools + performance analysis. Flutter/Phoenix tools are irrelevant.'
},
// Phoenix LiveView Projects
'phoenix': {
framework: 'phoenix',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Phoenix/LiveView tools (user's primary workflow)
'debug_liveview_connection', 'phoenix_live_dashboard', 'phoenix_analyze_router',
'phoenix_analyze_events', 'phoenix_conn_inspector', 'phoenix_inspect_endpoint_config',
// Elixir tools (Phoenix is Elixir-based)
'elixir_inspect_process', 'ecto_trace_queries',
// Universal debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// Frontend framework tools (Phoenix handles UI via LiveView)
'flutter_config', 'flutter_diagnostics', 'nextjs_page_info', 'nextjs_config',
'react_inspect_components', 'vue_debug_reactivity', 'angular_debug_change_detection',
// Python backend tools (different backend stack)
'python_trace_request', 'django_debug_orm', 'flask_debug_routes',
// Meta-framework tools (Phoenix is the framework)
'remix_debug_loaders', 'astro_debug_islands', 'nuxt_debug_nitro'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Phoenix projects need Elixir/LiveView tools. Frontend framework tools are less relevant since Phoenix handles UI.'
},
// Pure Elixir Projects (without Phoenix web framework)
'elixir': {
framework: 'elixir',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Pure Elixir tools (non-web applications)
'elixir_inspect_process', 'elixir_trace_processes', 'elixir_attach_to_beam',
'elixir_profile_memory', 'elixir_debug_genserver', 'elixir_monitor_supervisor',
// Ecto tools (if using database)
'ecto_trace_queries', 'ecto_debug_queries', 'ecto_analyze_slow_queries',
// OTP debugging tools
'otp_trace_messages', 'otp_debug_supervision_tree', 'otp_analyze_crashes',
// Universal debugging tools (for any HTTP endpoints)
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// Web framework tools (pure Elixir may not have web interface)
'take_screenshot', 'simulate_user_action', 'run_audit',
'debug_liveview_connection', 'phoenix_live_dashboard',
// Frontend framework tools (not relevant for backend-only Elixir)
'flutter_config', 'nextjs_page_info', 'react_inspect_components',
// Other backend frameworks
'python_trace_request', 'django_debug_orm', 'rails_debug_activerecord'
],
estimatedMemorySavingsMB: 6,
reasoning: 'Pure Elixir projects need BEAM VM and OTP debugging tools. Web-specific tools stay lazy unless HTTP interface detected.'
},
// Elixir with Phoenix (but not LiveView)
'phoenix-traditional': {
framework: 'phoenix-traditional',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Phoenix tools (traditional server-rendered or API)
'phoenix_analyze_router', 'phoenix_analyze_events', 'phoenix_conn_inspector',
'phoenix_inspect_endpoint_config', 'phoenix_profile_plugs', 'phoenix_debug_channels',
// Elixir tools
'elixir_inspect_process', 'elixir_trace_processes', 'ecto_trace_queries',
// Web debugging tools (has web interface)
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// LiveView-specific tools (not using LiveView)
'debug_liveview_connection',
// Frontend frameworks (Phoenix serves HTML, not SPA)
'flutter_config', 'nextjs_page_info', 'react_inspect_components',
'vue_debug_reactivity', 'angular_debug_change_detection',
// Other backend frameworks
'python_trace_request', 'django_debug_orm', 'rails_debug_activerecord'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Traditional Phoenix needs Phoenix + Elixir tools but not LiveView-specific ones. Frontend frameworks irrelevant.'
},
// Nerves/Embedded Elixir Projects
'nerves': {
framework: 'nerves',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Embedded Elixir tools
'elixir_inspect_process', 'elixir_trace_processes', 'elixir_attach_to_beam',
'nerves_debug_hardware', 'nerves_inspect_gpio', 'nerves_monitor_sensors',
'nerves_debug_firmware', 'nerves_analyze_boot_sequence',
// OTP debugging (critical for embedded systems)
'otp_trace_messages', 'otp_debug_supervision_tree', 'otp_analyze_crashes',
// Performance tools (resource-constrained environment)
'get_performance_metrics', 'elixir_profile_memory'
],
lazyTools: [
// All web-related tools (embedded systems rarely have web interfaces)
'take_screenshot', 'simulate_user_action', 'run_audit',
'debug_liveview_connection', 'phoenix_live_dashboard',
'flutter_config', 'nextjs_page_info', 'python_trace_request',
// Database tools (embedded systems often use local storage)
'ecto_trace_queries', 'django_debug_orm'
],
estimatedMemorySavingsMB: 7,
reasoning: 'Nerves/embedded Elixir needs BEAM VM and hardware debugging. Web tools irrelevant for embedded systems.'
},
// Meta-frameworks (Remix, Astro, Nuxt, SvelteKit)
'remix': {
framework: 'remix',
immediateTools: [
'inject_debugging', 'close_session', 'list_tools',
'remix_debug_loaders', 'react_inspect_components', 'react_debug_state',
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'performance_baseline', 'monitor_realtime'
],
lazyTools: [
'flutter_config', 'nextjs_page_info', 'vue_debug_reactivity',
'debug_liveview_connection', 'python_trace_request'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Remix needs React + Remix-specific tools. Other framework tools are irrelevant.'
},
'astro': {
framework: 'astro',
immediateTools: [
'inject_debugging', 'close_session', 'list_tools',
'astro_debug_islands', 'take_screenshot', 'simulate_user_action',
'run_audit', 'get_console_logs', 'performance_baseline', 'monitor_realtime'
],
lazyTools: [
'flutter_config', 'nextjs_page_info', 'react_inspect_components',
'debug_liveview_connection', 'python_trace_request'
],
estimatedMemorySavingsMB: 6,
reasoning: 'Astro needs island debugging + universal tools. Framework-specific tools are lazy.'
},
// Full-stack projects (multiple frameworks detected)
'full-stack-nextjs-python': {
framework: 'full-stack-nextjs-python',
immediateTools: [
'inject_debugging', 'close_session', 'list_tools',
// Frontend: NextJS + React
'nextjs_page_info', 'nextjs_config', 'react_inspect_components',
// Backend: Python
'python_trace_request', 'django_debug_orm', 'flask_debug_routes',
// Universal tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
'flutter_config', 'debug_liveview_connection', 'vue_debug_reactivity'
],
estimatedMemorySavingsMB: 4,
reasoning: 'Full-stack needs both frontend and backend tools for the detected stack.'
},
// Plain JavaScript (vanilla JS, no frameworks)
'javascript': {
framework: 'javascript',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// JavaScript-specific debugging
'get_console_logs', 'get_errors', 'debug_javascript_execution',
'trace_javascript_performance', 'analyze_dom_manipulation',
'debug_event_listeners', 'inspect_global_variables',
// Browser debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_performance_metrics', 'monitor_realtime',
// Code quality tools
'analyze_code_complexity', 'detect_memory_leaks', 'profile_javascript'
],
lazyTools: [
// All framework-specific tools
'flutter_config', 'nextjs_page_info', 'react_inspect_components',
'vue_debug_reactivity', 'angular_debug_change_detection',
'debug_liveview_connection', 'python_trace_request', 'django_debug_orm'
],
estimatedMemorySavingsMB: 7,
reasoning: 'Plain JavaScript needs core browser debugging and JS-specific tools. Framework tools irrelevant.'
},
// Node.js Backend Applications
'nodejs': {
framework: 'nodejs',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Node.js-specific debugging
'nodejs_inspect_process', 'nodejs_debug_modules', 'nodejs_trace_async',
'nodejs_profile_memory', 'nodejs_analyze_event_loop', 'nodejs_debug_streams',
'nodejs_inspect_dependencies', 'nodejs_debug_worker_threads',
// Performance and monitoring
'get_performance_metrics', 'monitor_realtime', 'get_console_logs',
'nodejs_heap_snapshot', 'nodejs_cpu_profile',
// API debugging (if has HTTP endpoints)
'trace_http_requests', 'debug_api_endpoints', 'analyze_request_response'
],
lazyTools: [
// Frontend-specific tools (Node.js is backend)
'take_screenshot', 'simulate_user_action', 'run_audit',
'flutter_config', 'react_inspect_components', 'vue_debug_reactivity',
// Other backend frameworks
'python_trace_request', 'debug_liveview_connection', 'rails_debug_activerecord'
],
estimatedMemorySavingsMB: 6,
reasoning: 'Node.js backend needs process debugging and performance tools. Frontend tools irrelevant unless serving web UI.'
},
// Express.js Applications
'express': {
framework: 'express',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Express.js-specific debugging
'express_debug_routes', 'express_trace_middleware', 'express_debug_sessions',
'express_analyze_performance', 'express_debug_static_files',
// Node.js tools (Express is Node.js-based)
'nodejs_inspect_process', 'nodejs_trace_async', 'nodejs_profile_memory',
// HTTP debugging
'trace_http_requests', 'debug_api_endpoints', 'analyze_request_response',
'get_performance_metrics', 'monitor_realtime', 'get_console_logs'
],
lazyTools: [
// Frontend tools (Express serves APIs, frontend separate)
'take_screenshot', 'simulate_user_action', 'run_audit',
'react_inspect_components', 'vue_debug_reactivity',
// Other frameworks
'flutter_config', 'debug_liveview_connection', 'python_trace_request'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Express.js needs Node.js + HTTP debugging tools. Frontend tools lazy unless serving static files.'
},
// Python Applications
'python': {
framework: 'python',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Python-specific debugging
'python_trace_request', 'python_debug_imports', 'python_profile_memory',
'python_analyze_performance', 'python_debug_threads', 'python_inspect_objects',
'python_trace_exceptions', 'python_debug_async',
// Performance monitoring
'get_performance_metrics', 'monitor_realtime', 'get_console_logs',
// HTTP debugging (if web app)
'trace_http_requests', 'debug_api_endpoints'
],
lazyTools: [
// Frontend tools (Python is typically backend)
'take_screenshot', 'simulate_user_action', 'run_audit',
'react_inspect_components', 'flutter_config',
// Specific framework tools (use generic Python tools instead)
'django_debug_orm', 'flask_debug_routes', 'fastapi_debug_deps',
// Other backend frameworks
'nodejs_inspect_process', 'debug_liveview_connection'
],
estimatedMemorySavingsMB: 6,
reasoning: 'Generic Python needs core Python debugging tools. Framework-specific and frontend tools lazy.'
},
// Django Applications
'django': {
framework: 'django',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Django-specific debugging
'django_debug_orm', 'django_trace_queries', 'django_debug_views',
'django_analyze_middleware', 'django_debug_templates', 'django_inspect_context',
'django_debug_forms', 'django_analyze_cache', 'django_debug_signals',
// Python tools (Django is Python-based)
'python_trace_request', 'python_profile_memory', 'python_trace_exceptions',
// Web debugging tools (Django has web interface)
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// Other Python frameworks
'flask_debug_routes', 'fastapi_debug_deps',
// Frontend frameworks (Django templates handle UI)
'react_inspect_components', 'vue_debug_reactivity', 'flutter_config',
// Other backend frameworks
'nodejs_inspect_process', 'debug_liveview_connection'
],
estimatedMemorySavingsMB: 4,
reasoning: 'Django needs Django + Python + web debugging tools. Other framework tools irrelevant.'
},
// Flask Applications
'flask': {
framework: 'flask',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Flask-specific debugging
'flask_debug_routes', 'flask_debug_templates', 'flask_analyze_performance',
'flask_debug_sessions', 'flask_inspect_context', 'flask_debug_blueprints',
// Python tools (Flask is Python-based)
'python_trace_request', 'python_profile_memory', 'python_trace_exceptions',
// Web debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// Other Python frameworks
'django_debug_orm', 'fastapi_debug_deps',
// Frontend frameworks
'react_inspect_components', 'vue_debug_reactivity', 'flutter_config',
// Other backend frameworks
'nodejs_inspect_process', 'debug_liveview_connection'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Flask needs Flask + Python + web debugging tools. Other framework tools irrelevant.'
},
// FastAPI Applications
'fastapi': {
framework: 'fastapi',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// FastAPI-specific debugging
'fastapi_debug_deps', 'fastapi_trace_async', 'fastapi_debug_models',
'fastapi_analyze_performance', 'fastapi_debug_validation',
'fastapi_inspect_openapi', 'fastapi_debug_background_tasks',
// Python tools (FastAPI is Python-based)
'python_trace_request', 'python_profile_memory', 'python_debug_async',
// API debugging tools
'debug_api_endpoints', 'trace_http_requests', 'analyze_request_response',
'get_performance_metrics', 'monitor_realtime', 'get_console_logs'
],
lazyTools: [
// Frontend tools (FastAPI is API-only)
'take_screenshot', 'simulate_user_action', 'run_audit',
'react_inspect_components', 'vue_debug_reactivity', 'flutter_config',
// Other frameworks
'django_debug_orm', 'flask_debug_routes', 'nodejs_inspect_process'
],
estimatedMemorySavingsMB: 6,
reasoning: 'FastAPI needs FastAPI + Python + API debugging tools. Frontend tools irrelevant for API-only service.'
},
// Ruby on Rails Applications
'rails': {
framework: 'rails',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Rails-specific debugging
'rails_debug_activerecord', 'rails_trace_middleware', 'rails_debug_views',
'rails_analyze_routes', 'rails_debug_controllers', 'rails_inspect_cache',
'rails_debug_jobs', 'rails_analyze_performance',
// Ruby tools (Rails is Ruby-based)
'ruby_profile_memory', 'ruby_trace_exceptions', 'ruby_debug_threads',
// Web debugging tools (Rails has web interface)
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// Other backend frameworks
'python_trace_request', 'nodejs_inspect_process', 'debug_liveview_connection',
// Frontend frameworks (Rails handles UI)
'react_inspect_components', 'vue_debug_reactivity', 'flutter_config'
],
estimatedMemorySavingsMB: 5,
reasoning: 'Rails needs Rails + Ruby + web debugging tools. Other framework tools irrelevant.'
},
// Static Site Generators (Jekyll, Hugo, etc.)
'static': {
framework: 'static',
immediateTools: [
// Core debugging essentials
'inject_debugging', 'close_session', 'list_tools',
// Static site debugging
'analyze_static_assets', 'debug_build_process', 'validate_links',
'analyze_seo_metadata', 'debug_performance_static',
// Web debugging tools
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime',
// Performance tools (critical for static sites)
'performance_baseline', 'performance_profile', 'analyze_bundles'
],
lazyTools: [
// All dynamic framework tools
'react_inspect_components', 'vue_debug_reactivity', 'flutter_config',
'debug_liveview_connection', 'python_trace_request', 'nodejs_inspect_process'
],
estimatedMemorySavingsMB: 7,
reasoning: 'Static sites need web performance and build debugging. Dynamic framework tools irrelevant.'
},
// Unknown/Generic projects (fallback)
'unknown': {
framework: 'unknown',
immediateTools: [
// Core essentials only
'inject_debugging', 'close_session', 'list_tools',
// Universal debugging tools (work with any framework)
'take_screenshot', 'simulate_user_action', 'run_audit',
'get_console_logs', 'get_performance_metrics', 'monitor_realtime'
],
lazyTools: [
// All framework-specific tools stay lazy until needed
'flutter_config', 'nextjs_page_info', 'debug_liveview_connection',
'python_trace_request', 'react_inspect_components', 'vue_debug_reactivity',
'nodejs_inspect_process', 'django_debug_orm', 'rails_debug_activerecord'
],
estimatedMemorySavingsMB: 8,
reasoning: 'Unknown projects get universal tools immediately, all framework-specific tools lazy for maximum memory savings.'
}
};
/**
* Project-Aware Loading Strategy Manager
* Determines optimal loading strategy based on detected framework
*/
export class ProjectAwareLoadingStrategy {
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 = FRAMEWORK_TOOL_MAPPING[framework];
if (!strategy) {
// Handle meta-frameworks and variations
if (framework.includes('remix'))
strategy = FRAMEWORK_TOOL_MAPPING['remix'];
else if (framework.includes('astro'))
strategy = FRAMEWORK_TOOL_MAPPING['astro'];
else if (framework.includes('nuxt'))
strategy = FRAMEWORK_TOOL_MAPPING['remix']; // Similar to Remix
else if (framework.includes('nextjs'))
strategy = FRAMEWORK_TOOL_MAPPING['nextjs'];
// Enhanced Elixir ecosystem detection
else if (framework.includes('phoenix')) {
// Distinguish between Phoenix LiveView and traditional Phoenix
if (framework.includes('liveview') || framework === 'phoenix') {
strategy = FRAMEWORK_TOOL_MAPPING['phoenix'];
}
else {
strategy = FRAMEWORK_TOOL_MAPPING['phoenix-traditional'];
}
}
else if (framework.includes('elixir')) {
// Check for specific Elixir contexts
if (framework.includes('nerves') || framework.includes('embedded')) {
strategy = FRAMEWORK_TOOL_MAPPING['nerves'];
}
else if (framework.includes('phoenix')) {
strategy = FRAMEWORK_TOOL_MAPPING['phoenix-traditional'];
}
else {
strategy = FRAMEWORK_TOOL_MAPPING['elixir']; // Pure Elixir
}
}
else if (framework.includes('nerves'))
strategy = FRAMEWORK_TOOL_MAPPING['nerves'];
// Backend language/framework detection
else if (framework.includes('nodejs') || framework.includes('node')) {
if (framework.includes('express')) {
strategy = FRAMEWORK_TOOL_MAPPING['express'];
}
else {
strategy = FRAMEWORK_TOOL_MAPPING['nodejs'];
}
}
else if (framework.includes('python')) {
if (framework.includes('django')) {
strategy = FRAMEWORK_TOOL_MAPPING['django'];
}
else if (framework.includes('flask')) {
strategy = FRAMEWORK_TOOL_MAPPING['flask'];
}
else if (framework.includes('fastapi')) {
strategy = FRAMEWORK_TOOL_MAPPING['fastapi'];
}
else {
strategy = FRAMEWORK_TOOL_MAPPING['python'];
}
}
else if (framework.includes('django'))
strategy = FRAMEWORK_TOOL_MAPPING['django'];
else if (framework.includes('flask'))
strategy = FRAMEWORK_TOOL_MAPPING['flask'];
else if (framework.includes('fastapi'))
strategy = FRAMEWORK_TOOL_MAPPING['fastapi'];
else if (framework.includes('express'))
strategy = FRAMEWORK_TOOL_MAPPING['express'];
else if (framework.includes('rails') || framework.includes('ruby'))
strategy = FRAMEWORK_TOOL_MAPPING['rails'];
// Frontend-only detection
else if (framework.includes('javascript') && !framework.includes('node')) {
strategy = FRAMEWORK_TOOL_MAPPING['javascript'];
}
else if (framework.includes('static') || framework.includes('jekyll') || framework.includes('hugo')) {
strategy = FRAMEWORK_TOOL_MAPPING['static'];
}
// Fallback for unknown frameworks
else
strategy = FRAMEWORK_TOOL_MAPPING['unknown'];
}
this.currentStrategy = strategy;
return strategy;
}
/**
* Get current loading strategy
*/
getCurrentStrategy() {
return this.currentStrategy;
}
/**
* Check if a tool should be loaded immediately for the current project
*/
shouldLoadImmediately(toolName) {
if (!this.currentStrategy)
return false;
return this.currentStrategy.immediateTools.includes(toolName);
}
/**
* Check if a tool should stay lazy for the current project
*/
shouldStayLazy(toolName) {
if (!this.currentStrategy)
return true;
return this.currentStrategy.lazyTools.includes(toolName);
}
/**
* Get estimated memory savings for current strategy
*/
getEstimatedMemorySavings() {
return this.currentStrategy?.estimatedMemorySavingsMB || 0;
}
/**
* Get strategy reasoning for current project
*/
getStrategyReasoning() {
return this.currentStrategy?.reasoning || 'No strategy determined yet';
}
/**
* Get loading statistics
*/
getLoadingStats() {
if (!this.currentStrategy) {
return {
framework: 'unknown',
immediateToolCount: 0,
lazyToolCount: 0,
memorySavingsMB: 0,
reasoning: 'No framework detected yet'
};
}
return {
framework: this.currentStrategy.framework,
immediateToolCount: this.currentStrategy.immediateTools.length,
lazyToolCount: this.currentStrategy.lazyTools.length,
memorySavingsMB: this.currentStrategy.estimatedMemorySavingsMB,
reasoning: this.currentStrategy.reasoning
};
}
}
/**
* Enhanced loading decision with usage patterns
* Can be extended to learn from actual usage and optimize over time
*/
export class AdaptiveProjectAwareStrategy extends ProjectAwareLoadingStrategy {
usageStats = new Map();
/**
* Track tool usage to improve future loading decisions
*/
trackToolUsage(toolName) {
const currentCount = this.usageStats.get(toolName) || 0;
this.usageStats.set(toolName, currentCount + 1);
}
/**
* Get tools that should be promoted to immediate loading based on usage
*/
getUsageBasedPromotions() {
const threshold = 3; // Tools used 3+ times get promoted
const promotions = [];
for (const [tool, count] of this.usageStats.entries()) {
if (count >= threshold && this.shouldStayLazy(tool)) {
promotions.push(tool);
}
}
return promotions;
}
/**
* Adapt strategy based on actual usage patterns
*/
adaptStrategy() {
const currentStrategy = this.getCurrentStrategy();
if (!currentStrategy)
return;
const promotions = this.getUsageBasedPromotions();
if (promotions.length > 0) {
// Move frequently used tools from lazy to immediate
currentStrategy.immediateTools.push(...promotions);
currentStrategy.lazyTools = currentStrategy.lazyTools.filter(tool => !promotions.includes(tool));
console.log(`📈 Adapted loading strategy: promoted ${promotions.length} tools based on usage`);
}
}
}
//# sourceMappingURL=project-aware-loading-strategy.js.map