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

318 lines 16.4 kB
import { resolveToolAlias } from '../utils/tool-aliases.js'; import { createLazyHandler } from './lazy-handler-wrapper.js'; import { createProjectAwareLazyHandler, ProjectAwareLoadingCoordinator } from '../utils/project-aware-lazy-handler-wrapper.js'; import { requiresExternalDependencies } from '../utils/comprehensive-tool-dependencies.js'; // Import new feedback-driven handlers import { DebugWorkflowAdvisor } from './debug-workflow-advisor.js'; import { PythonBackendHandler } from './python/python-backend-handler.js'; import { FlutterSessionStabilityHandler } from './flutter-session-stability-handler.js'; import { FlutterTDDIntegrationHandler } from './flutter-tdd-integration-handler.js'; import { FlutterTDDEnhancedHandler } from './flutter-tdd-enhanced-handler.js'; import { EnhancedUserExperienceHandler } from './enhanced-user-experience-handler.js'; import { CodeQualityIntegrationHandler } from './code-quality-integration-handler.js'; import { DebuggingIntelligenceHandler } from './debugging-intelligence-handler.js'; import { TddWorkflowHandler } from './tdd-workflow-handler.js'; import { SessionPersistenceHandler } from './session-persistence-handler.js'; import { PhoenixLiveViewEnhancedHandler } from './phoenix-liveview-enhanced-handler.js'; import { TDDCycleIntegrationHandler } from './tdd-cycle-integration-handler.js'; import { PhoenixTDDIntegrationHandler } from './phoenix-tdd-integration-handler.js'; import { SmartWorkflowOrchestrationHandler } from './smart-workflow-orchestration-handler.js'; import { BackendIntegrationHandler } from './backend-integration-handler.js'; import { CapabilityDiscoveryHandler } from './capability-discovery-handler.js'; import { VimIntegrationHandler } from './vim-integration-handler.js'; import { CCVimGoHandler } from './cc-vim-go-handler.js'; import { GoDebuggingHandler } from './go-debugging-handler.js'; import { RustDebuggingHandler } from './rust-debugging-handler.js'; import { LuaDebuggingHandler } from './lua-debugging-handler.js'; import { UniversalWorkflowHandler } from './universal-workflow-handler.js'; import { AdvancedFormInteractionHandler } from './advanced-form-interaction-handler.js'; /** * Registry for managing tool handlers in a modular architecture */ export class HandlerRegistry { handlers = []; toolToHandlerMap = new Map(); toolsMap = new Map(); lazyLoadingEnabled = true; projectAwareLoadingEnabled = true; /** * Register a new handler and its tools */ registerHandler(handler) { // Check for duplicate tools for (const tool of handler.tools) { if (this.toolToHandlerMap.has(tool.name)) { throw new Error(`Tool ${tool.name} is already registered`); } } // Wrap handler with project-aware lazy loading if it has tools requiring external dependencies let wrappedHandler = handler; if (this.lazyLoadingEnabled && this.handlerRequiresDependencies(handler)) { if (this.projectAwareLoadingEnabled) { console.log(`🎯 Wrapping handler with project-aware lazy loading: ${handler.constructor.name}`); const projectAwareWrapper = createProjectAwareLazyHandler(handler); ProjectAwareLoadingCoordinator.registerWrapper(handler.constructor.name, projectAwareWrapper); wrappedHandler = projectAwareWrapper; } else { console.log(`🔄 Wrapping handler with lazy loading: ${handler.constructor.name}`); wrappedHandler = createLazyHandler(handler); } } // Register the handler and map its tools this.handlers.push(wrappedHandler); for (const tool of handler.tools) { this.toolToHandlerMap.set(tool.name, wrappedHandler); this.toolsMap.set(tool.name, tool); } } /** * Check if any tools in a handler require external dependencies */ handlerRequiresDependencies(handler) { return handler.tools.some(tool => requiresExternalDependencies(tool.name)); } /** * Get all registered tools */ getAllTools() { return Array.from(this.toolsMap.values()); } /** * Get a specific tool by name (supports aliases) */ getTool(toolName) { // First try direct lookup let tool = this.toolsMap.get(toolName); // If not found, try resolving alias if (!tool) { const canonicalName = resolveToolAlias(toolName); tool = this.toolsMap.get(canonicalName); } return tool; } /** * Check if a tool exists (supports aliases) */ hasTool(toolName) { // Try direct lookup first if (this.toolsMap.has(toolName)) { return true; } // Try alias resolution const canonicalName = resolveToolAlias(toolName); return this.toolsMap.has(canonicalName); } /** * Handle a tool request by routing to the appropriate handler (supports aliases) */ async handleTool(toolName, args, sessions) { // Try direct lookup first let handler = this.toolToHandlerMap.get(toolName); let resolvedToolName = toolName; // If not found, try resolving alias if (!handler) { resolvedToolName = resolveToolAlias(toolName); handler = this.toolToHandlerMap.get(resolvedToolName); } if (!handler) { throw new Error(`No handler found for tool: ${toolName} (resolved to: ${resolvedToolName})`); } return handler.handle(resolvedToolName, args, sessions); } /** * Initialize all handlers that have an initialize method */ async initializeAll() { const initPromises = this.handlers .filter(handler => typeof handler.initialize === 'function') .map(handler => handler.initialize()); await Promise.all(initPromises); } /** * Get handler for a specific tool (useful for testing) */ getHandlerForTool(toolName) { return this.toolToHandlerMap.get(toolName); } /** * Set lazy loading enabled/disabled */ setLazyLoadingEnabled(enabled) { this.lazyLoadingEnabled = enabled; console.log(`🔧 Lazy loading ${enabled ? 'enabled' : 'disabled'}`); } /** * Get lazy loading statistics */ getLazyLoadingStats() { const lazyHandlers = this.handlers.filter(h => h.constructor.name === 'LazyHandlerWrapper').length; const toolsWithDeps = []; for (const [toolName] of this.toolsMap) { if (requiresExternalDependencies(toolName)) { toolsWithDeps.push(toolName); } } return { enabled: this.lazyLoadingEnabled, lazyHandlers, totalHandlers: this.handlers.length, toolsWithDependencies: toolsWithDeps }; } /** * Get count of registered handlers */ getHandlerCount() { return this.handlers.length; } /** * Get count of registered tools */ getToolCount() { return this.toolsMap.size; } /** * Register all feedback-driven handlers * Addresses comprehensive user feedback from Phoenix LiveView, Flutter, and Python projects * Enhanced with TDD support based on Cycle 22 user breakthrough */ static async createWithFeedbackHandlers() { const registry = new HandlerRegistry(); try { // Register Debug Workflow Advisor (addresses AI model verification vs debugging gap) // Enhanced with TDD-specific tools: suggest_tdd_implementation_steps, validate_test_driven_architecture, analyze_test_failure_patterns const workflowAdvisor = new DebugWorkflowAdvisor(); registry.registerHandler(workflowAdvisor); // Register Flutter TDD Integration Handler (addresses Cycle 22 TDD debugging success) // Provides 6 TDD-specific tools for Flutter test-driven development const flutterTddHandler = new FlutterTDDIntegrationHandler(); registry.registerHandler(flutterTddHandler); // Register Python Backend Handler (addresses full-stack debugging request) const pythonEngine = await import('../python-backend-engine.js').then(m => new m.PythonBackendEngine()); const pythonHandler = new PythonBackendHandler(pythonEngine); registry.registerHandler(pythonHandler); // Register Flutter Session Stability Handler (addresses session stability issues) const flutterStabilityHandler = new FlutterSessionStabilityHandler(); registry.registerHandler(flutterStabilityHandler); // Register Enhanced User Experience Handler (addresses real-world feedback improvements) const enhancedUXHandler = new EnhancedUserExperienceHandler(); registry.registerHandler(enhancedUXHandler); // Register Code Quality Integration Handler (addresses Code Quality Sprint feedback) const codeQualityHandler = new CodeQualityIntegrationHandler(); registry.registerHandler(codeQualityHandler); // Register Debugging Intelligence Handler (addresses choice paralysis with 226 tools) const debuggingIntelligenceHandler = new DebuggingIntelligenceHandler(); registry.registerHandler(debuggingIntelligenceHandler); // Register TDD Workflow Handler (addresses Cycle 28 real-world TDD feedback) const tddWorkflowHandler = new TddWorkflowHandler(); registry.registerHandler(tddWorkflowHandler); // Register Session Persistence Handler (addresses Cycle 3 session failure feedback) const sessionPersistenceHandler = new SessionPersistenceHandler(); registry.registerHandler(sessionPersistenceHandler); // Register Phoenix LiveView Enhanced Handler (addresses Cycles 50-51 Phoenix refactoring feedback) const phoenixLiveViewEnhancedHandler = new PhoenixLiveViewEnhancedHandler(); registry.registerHandler(phoenixLiveViewEnhancedHandler); // Register TDD Cycle Integration Handler (addresses Post-Cycle 31 TDD revolutionary enhancement feedback) const tddCycleIntegrationHandler = new TDDCycleIntegrationHandler(); registry.registerHandler(tddCycleIntegrationHandler); // Register Phoenix TDD Integration Handler (revolutionary TDD for Elixir/Phoenix/LiveView ecosystem) const phoenixTddIntegrationHandler = new PhoenixTDDIntegrationHandler(); registry.registerHandler(phoenixTddIntegrationHandler); // Register Flutter TDD Enhanced Handler (revolutionary TDD for Dart/Flutter ecosystem) const flutterTddEnhancedHandler = new FlutterTDDEnhancedHandler(); registry.registerHandler(flutterTddEnhancedHandler); // Register Smart Workflow Orchestration Handler (revolutionary AI-guided workflow automation - #1 priority Cycle 30 feedback) const smartWorkflowOrchestrationHandler = new SmartWorkflowOrchestrationHandler(); registry.registerHandler(smartWorkflowOrchestrationHandler); // Register Backend Integration Handler (REVOLUTIONARY: Multi-ecosystem backend testing - JS/TS, Python, Elixir, Ruby) const backendIntegrationHandler = new BackendIntegrationHandler(); registry.registerHandler(backendIntegrationHandler); // Register Capability Discovery Handler (REVOLUTIONARY: AI capability discovery for immediate understanding) const capabilityDiscoveryHandler = new CapabilityDiscoveryHandler(); registry.registerHandler(capabilityDiscoveryHandler); // Register Vim Integration Handler (SPECIALIZED: Vim/Neovim debugging tools for cc-vim project) const vimIntegrationHandler = new VimIntegrationHandler(); registry.registerHandler(vimIntegrationHandler); // Register CC-Vim Go Handler (SPECIALIZED: Go bridge debugging tools for cc-vim Go implementation) const ccVimGoHandler = new CCVimGoHandler(); registry.registerHandler(ccVimGoHandler); // Register Go Debugging Handler (COMPREHENSIVE: Full Go development toolchain debugging) const goDebuggingHandler = new GoDebuggingHandler(); registry.registerHandler(goDebuggingHandler); // Register Rust Debugging Handler (COMPREHENSIVE: Full Rust development toolchain debugging) const rustDebuggingHandler = new RustDebuggingHandler(); registry.registerHandler(rustDebuggingHandler); // Register Lua Debugging Handler (COMPREHENSIVE: Full Lua development toolchain debugging) const luaDebuggingHandler = new LuaDebuggingHandler(); registry.registerHandler(luaDebuggingHandler); // Register Universal Workflow Handler (REVOLUTIONARY: Multi-step user journey orchestration) try { const universalWorkflowHandler = new UniversalWorkflowHandler(); console.log(`🔧 Registering Universal Workflow Handler with ${universalWorkflowHandler.getTools().length} tools`); registry.registerHandler(universalWorkflowHandler); console.log('✅ Universal Workflow Handler registered successfully'); } catch (error) { console.error('❌ Failed to register Universal Workflow Handler:', error.message); } // Register Advanced Form Interaction Handler (REVOLUTIONARY: Complex form and dynamic element handling) try { const advancedFormHandler = new AdvancedFormInteractionHandler(); console.log(`🔧 Registering Advanced Form Handler with ${advancedFormHandler.getTools().length} tools`); registry.registerHandler(advancedFormHandler); console.log('✅ Advanced Form Handler registered successfully'); } catch (error) { console.error('❌ Failed to register Advanced Form Handler:', error.message); } // Memory-efficient feedback summary console.log(`✅ Feedback-driven handlers registered: +${registry.getHandlerCount()} handlers, +${registry.getToolCount()} tools`); console.log(`🎯 Revolutionary enhancements: TDD Integration, Phoenix LiveView, Flutter Enhanced, Smart Workflows, Backend Integration`); console.log(`🚀 Multi-ecosystem support: JavaScript/TypeScript, Python, Elixir/Phoenix, Ruby, Dart/Flutter, Go, Rust, Lua`); } catch (error) { console.error('Failed to register feedback-driven handlers:', error); // Continue with basic registry even if advanced handlers fail } return registry; } /** * Enhanced tool validation with dependency checking * Integrates with ToolDependencyManager for better user experience */ async validateToolWithDependencies(toolName, sessionState) { // Check if tool exists if (!this.hasTool(toolName)) { return { isValid: false, validationMessage: `Tool '${toolName}' not found`, suggestions: ['Check available tools with list_tools()', 'Verify tool name spelling'] }; } // Enhanced validation would integrate with ToolDependencyManager here // For now, return basic validation return { isValid: true, validationMessage: `Tool '${toolName}' is available`, suggestions: [] }; } /** * Get enhanced error information for tool failures */ async getEnhancedErrorInfo(toolName, error, sessionId) { // This would integrate with EnhancedErrorHandler return { errorType: 'Tool Execution Error', rootCause: error.message, actionableSteps: [ 'Check tool prerequisites', 'Verify session is active', 'Review tool documentation' ], relatedTools: [] }; } } //# sourceMappingURL=handler-registry.js.map