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

223 lines • 8.68 kB
/** * Tool Access Strategy - Progressive disclosure of tools based on context * * Solves the problem of: * - 200+ tools overwhelming the main agent * - Sub-agents lacking transparency * - Need for verification of claims */ export class ToolAccessStrategy { // Essential tools always available for verification static ESSENTIAL_TOOLS = [ 'take_screenshot', // Visual ground truth 'get_console_logs', // Error detection 'check_element_exists', // DOM verification 'get_current_url', // Navigation state 'get_page_title', // Page identity 'execute_javascript', // Custom verification 'get_debug_state' // Overall state ]; // Tool categories for selective access static TOOL_CATEGORIES = { interaction: [ 'click_element', 'type_text', 'select_option', 'submit_form', 'navigate_to' ], inspection: [ 'get_dom_snapshot', 'get_element_properties', 'get_computed_styles', 'get_element_text', 'find_elements' ], performance: [ 'get_performance_metrics', 'measure_paint_timing', 'analyze_bundle_size', 'profile_memory_usage' ], network: [ 'get_network_requests', 'mock_api_response', 'inspect_request_headers', 'analyze_api_calls' ], accessibility: [ 'run_accessibility_check', 'check_color_contrast', 'validate_aria_labels', 'test_keyboard_navigation' ], testing: [ 'generate_test_case', 'run_visual_regression', 'validate_form_state', 'check_responsive_design' ] }; /** * Get tools based on access level and context */ static getToolsForContext(context) { switch (context.level) { case 'orchestrator': return { level: 'orchestrator', tools: [ 'debug_orchestrator', 'performance_orchestrator', 'test_orchestrator', 'architecture_orchestrator', 'fix_orchestrator', 'qa_orchestrator', 'hybrid_orchestrator' // NEW ], description: 'High-level orchestrators only' }; case 'essential': return { level: 'essential', tools: [ ...this.ESSENTIAL_TOOLS, 'hybrid_orchestrator' // Always include hybrid for verification ], description: 'Essential verification tools + orchestrators' }; case 'category': const categoryTools = new Set(this.ESSENTIAL_TOOLS); // Add requested categories if (context.categories) { context.categories.forEach(cat => { const tools = this.TOOL_CATEGORIES[cat] || []; tools.forEach((tool) => categoryTools.add(tool)); }); } // Always include orchestrators for delegation categoryTools.add('hybrid_orchestrator'); categoryTools.add('debug_orchestrator'); return { level: 'category', tools: Array.from(categoryTools), description: `Category-specific tools: ${context.categories?.join(', ')}` }; case 'full': // Only in extreme cases - all 200+ tools return { level: 'full', tools: ['*'], // Special marker for all tools description: 'Full tool access (warning: may overwhelm)' }; default: // Default to orchestrator level return this.getToolsForContext({ level: 'orchestrator' }); } } /** * Intelligent tool suggestion based on task analysis */ static suggestToolsForTask(task) { const suggestedTools = new Set(); const lowerTask = task.toLowerCase(); // Always include hybrid orchestrator for verification tasks if (this.needsVerification(lowerTask)) { suggestedTools.add('hybrid_orchestrator'); } // Add essential tools for common verification needs if (lowerTask.includes('error') || lowerTask.includes('console')) { suggestedTools.add('get_console_logs'); } if (lowerTask.includes('see') || lowerTask.includes('visual') || lowerTask.includes('screenshot')) { suggestedTools.add('take_screenshot'); } if (lowerTask.includes('exist') || lowerTask.includes('present') || lowerTask.includes('visible')) { suggestedTools.add('check_element_exists'); } // Add category-specific tools Object.entries(this.TOOL_CATEGORIES).forEach(([category, tools]) => { if (this.taskMatchesCategory(lowerTask, category)) { // Add first 2-3 tools from category to avoid overwhelming tools.slice(0, 3).forEach(tool => suggestedTools.add(tool)); } }); // Always include at least one orchestrator if (suggestedTools.size === 0) { suggestedTools.add('debug_orchestrator'); } return Array.from(suggestedTools); } static needsVerification(task) { const verificationKeywords = [ 'verify', 'check', 'confirm', 'ensure', 'actually', 'really', 'truly', 'indeed', 'make sure', 'validate' ]; return verificationKeywords.some(kw => task.includes(kw)); } static taskMatchesCategory(task, category) { const categoryKeywords = { interaction: ['click', 'type', 'select', 'submit', 'interact'], inspection: ['inspect', 'examine', 'analyze', 'look at', 'check state'], performance: ['slow', 'performance', 'speed', 'optimize', 'lag'], network: ['api', 'request', 'network', 'fetch', 'xhr'], accessibility: ['a11y', 'accessibility', 'aria', 'screen reader'], testing: ['test', 'regression', 'validate', 'assertion'] }; const keywords = categoryKeywords[category] || []; return keywords.some((kw) => task.includes(kw)); } } /** * Dynamic tool loading based on confidence */ export class DynamicToolLoader { static confidenceThresholds = { high: 0.8, // Sub-agent results trusted medium: 0.5, // Need some verification low: 0.3 // Need extensive verification }; /** * Determine tool access level based on confidence in sub-agents */ static determineAccessLevel(context) { const { subAgentConfidence, taskComplexity, previousFailures } = context; // More failures = need more direct access if (previousFailures > 2) { return 'category'; // Give category-level access } // Low confidence = need verification tools if (subAgentConfidence < this.confidenceThresholds.medium) { return 'essential'; } // Complex tasks with medium confidence = category access if (taskComplexity === 'complex' && subAgentConfidence < this.confidenceThresholds.high) { return 'category'; } // High confidence = orchestrators only return 'orchestrator'; } /** * Progressive tool revelation based on need */ static getProgressiveTools(stage) { const stages = [ // Stage 1: Orchestrators only ['debug_orchestrator', 'hybrid_orchestrator'], // Stage 2: Add essential verification [...ToolAccessStrategy.ESSENTIAL_TOOLS], // Stage 3: Add interaction tools [...ToolAccessStrategy.TOOL_CATEGORIES.interaction], // Stage 4: Add inspection tools [...ToolAccessStrategy.TOOL_CATEGORIES.inspection], // Stage 5: Full access ['*'] ]; const tools = new Set(); for (let i = 0; i <= Math.min(stage, stages.length - 1); i++) { stages[i].forEach(tool => tools.add(tool)); } return Array.from(tools); } } //# sourceMappingURL=tool-access-strategy.js.map