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
384 lines (372 loc) • 16.2 kB
JavaScript
/**
* Sub-Agent Coordinator Handler
*
* Provides intelligent delegation to Claude Code sub-agents for AI-Debug workflows
* while preserving main conversation context.
*/
export class SubAgentCoordinator {
tools = [
{
name: 'delegate_to_debug_agent',
description: 'Intelligently delegate AI-Debug tasks to specialized sub-agents to preserve main conversation context. Automatically selects the best agent based on task type and returns concise results.',
inputSchema: {
type: 'object',
properties: {
task: {
type: 'string',
description: 'Description of the debugging task to perform'
},
url: {
type: 'string',
description: 'URL to debug (if applicable)'
},
sessionId: {
type: 'string',
description: 'Existing session ID to continue (optional)'
},
priority: {
type: 'string',
enum: ['low', 'medium', 'high', 'critical'],
description: 'Task priority level',
default: 'medium'
},
contextPreservation: {
type: 'boolean',
description: 'Whether to maximize context preservation (recommended: true)',
default: true
}
},
required: ['task']
}
},
{
name: 'plan_debug_workflow',
description: 'Plan a multi-phase debugging workflow with intelligent sub-agent delegation. Shows which agents will be used and estimated context savings.',
inputSchema: {
type: 'object',
properties: {
goal: {
type: 'string',
description: 'Overall debugging goal or problem description'
},
complexity: {
type: 'string',
enum: ['simple', 'moderate', 'complex', 'comprehensive'],
description: 'Expected complexity level',
default: 'moderate'
},
timeConstraint: {
type: 'string',
enum: ['urgent', 'normal', 'thorough'],
description: 'Time constraint for debugging',
default: 'normal'
}
},
required: ['goal']
}
},
{
name: 'get_agent_status',
description: 'Check status of all debugging sub-agents and their current workloads. Useful for understanding what agents are available and their specializations.',
inputSchema: {
type: 'object',
properties: {
includeCapabilities: {
type: 'boolean',
description: 'Include detailed agent capabilities in response',
default: false
}
}
}
}
];
async handle(toolName, args, sessions) {
switch (toolName) {
case 'delegate_to_debug_agent':
return this.delegateToAgent(args, sessions);
case 'plan_debug_workflow':
return this.planWorkflow(args);
case 'get_agent_status':
return this.getAgentStatus(args);
default:
throw new Error(`Unknown tool: ${toolName}`);
}
}
async delegateToAgent(args, sessions) {
const { task, url, sessionId, priority, contextPreservation } = args;
// Analyze task to determine best agent
const selectedAgent = this.selectOptimalAgent(task);
// Prepare delegation context
const delegationContext = {
task,
url,
sessionId,
priority,
selectedAgent: selectedAgent.agent,
estimatedContextSavings: selectedAgent.contextSavings,
timestamp: new Date().toISOString()
};
return {
content: [{
type: 'text',
text: `🤖 **AI-Debug Sub-Agent Delegation**
**Task**: ${task}
**Selected Agent**: ${selectedAgent.agent}
**Reason**: ${selectedAgent.description}
**Estimated Time**: ${selectedAgent.estimatedTime}
**Context Savings**: ${selectedAgent.contextSavings}
**Next Steps**:
1. The ${selectedAgent.agent} will handle all detailed debugging
2. You'll receive a concise summary when complete
3. Main conversation context preserved for strategic discussion
**To Continue**: The sub-agent will automatically start working with AI-Debug tools. No further action needed from you.
${contextPreservation ? '💡 **Context Preservation Mode**: All verbose debugging output will stay in the sub-agent\'s context.' : ''}`
}]
};
}
selectOptimalAgent(task) {
const taskLower = task.toLowerCase();
// Performance-related keywords
if (taskLower.includes('slow') || taskLower.includes('performance') ||
taskLower.includes('optimize') || taskLower.includes('speed') ||
taskLower.includes('bundle') || taskLower.includes('loading')) {
return {
phase: 'performance',
agent: 'performance-analysis-agent',
description: 'Specialized in performance profiling and optimization analysis',
estimatedTime: '5-10 minutes',
contextSavings: '~2000 tokens (detailed metrics kept in sub-agent)'
};
}
// Accessibility-related keywords
if (taskLower.includes('accessibility') || taskLower.includes('a11y') ||
taskLower.includes('wcag') || taskLower.includes('screen reader') ||
taskLower.includes('keyboard') || taskLower.includes('contrast')) {
return {
phase: 'accessibility',
agent: 'accessibility-audit-agent',
description: 'Expert in WCAG compliance and accessibility testing',
estimatedTime: '5-8 minutes',
contextSavings: '~1500 tokens (violation details kept in sub-agent)'
};
}
// Error-related keywords
if (taskLower.includes('error') || taskLower.includes('bug') ||
taskLower.includes('crash') || taskLower.includes('fail') ||
taskLower.includes('broken') || taskLower.includes('exception')) {
return {
phase: 'error-investigation',
agent: 'error-investigation-agent',
description: 'Specialized in error detection and root cause analysis',
estimatedTime: '3-7 minutes',
contextSavings: '~1800 tokens (error logs kept in sub-agent)'
};
}
// Validation/testing keywords
if (taskLower.includes('test') || taskLower.includes('validate') ||
taskLower.includes('check') || taskLower.includes('verify') ||
taskLower.includes('confirm') || taskLower.includes('regression')) {
return {
phase: 'validation',
agent: 'validation-testing-agent',
description: 'Expert in comprehensive testing and validation workflows',
estimatedTime: '4-8 minutes',
contextSavings: '~1200 tokens (test results kept in sub-agent)'
};
}
// Default to discovery agent for general debugging
return {
phase: 'discovery',
agent: 'debug-discovery-agent',
description: 'Handles initial debugging discovery and assessment',
estimatedTime: '3-5 minutes',
contextSavings: '~1000 tokens (setup details kept in sub-agent)'
};
}
async planWorkflow(args) {
const { goal, complexity, timeConstraint } = args;
// Plan workflow based on goal and complexity
const workflow = this.generateWorkflowPlan(goal, complexity, timeConstraint);
const totalTime = workflow.reduce((acc, phase) => {
const time = parseInt(phase.estimatedTime.split('-')[1]);
return acc + time;
}, 0);
const totalContextSavings = workflow.reduce((acc, phase) => {
const savings = parseInt(phase.contextSavings.match(/~(\d+)/)?.[1] || '0');
return acc + savings;
}, 0);
return {
content: [{
type: 'text',
text: `📋 **Debug Workflow Plan**
**Goal**: ${goal}
**Complexity**: ${complexity}
**Time Constraint**: ${timeConstraint}
**Planned Phases**:
${workflow.map((phase, index) => `
${index + 1}. **${phase.phase}** (${phase.agent})
- ${phase.description}
- Time: ${phase.estimatedTime}
- Context Savings: ${phase.contextSavings}
`).join('')}
**Summary**:
- **Total Estimated Time**: ${totalTime} minutes
- **Total Context Savings**: ~${totalContextSavings} tokens
- **Phases**: ${workflow.length}
- **Main Thread Impact**: Minimal (just phase summaries)
**To Execute**: Use \`delegate_to_debug_agent\` for each phase, or start with the first phase now.`
}]
};
}
generateWorkflowPlan(goal, complexity, timeConstraint) {
const goalLower = goal.toLowerCase();
const workflow = [];
// Always start with discovery for complex workflows
if (complexity === 'complex' || complexity === 'comprehensive') {
workflow.push({
phase: 'discovery',
agent: 'debug-discovery-agent',
description: 'Initial assessment and issue identification',
estimatedTime: '3-5 minutes',
contextSavings: '~1000 tokens'
});
}
// Add specific phases based on goal
if (goalLower.includes('performance') || goalLower.includes('slow')) {
workflow.push({
phase: 'performance',
agent: 'performance-analysis-agent',
description: 'Performance profiling and optimization analysis',
estimatedTime: '5-10 minutes',
contextSavings: '~2000 tokens'
});
}
if (goalLower.includes('accessibility') || goalLower.includes('a11y')) {
workflow.push({
phase: 'accessibility',
agent: 'accessibility-audit-agent',
description: 'Comprehensive accessibility compliance audit',
estimatedTime: '5-8 minutes',
contextSavings: '~1500 tokens'
});
}
if (goalLower.includes('error') || goalLower.includes('bug')) {
workflow.push({
phase: 'error-investigation',
agent: 'error-investigation-agent',
description: 'Error detection and root cause analysis',
estimatedTime: '3-7 minutes',
contextSavings: '~1800 tokens'
});
}
// Always end with validation for thorough workflows
if (timeConstraint === 'thorough' || complexity === 'comprehensive') {
workflow.push({
phase: 'validation',
agent: 'validation-testing-agent',
description: 'Final validation and quality assurance',
estimatedTime: '4-8 minutes',
contextSavings: '~1200 tokens'
});
}
// Fallback for simple workflows
if (workflow.length === 0) {
workflow.push(this.selectOptimalAgent(goal));
}
return workflow;
}
async getAgentStatus(args) {
const { includeCapabilities } = args;
const agents = [
{
name: 'debug-discovery-agent',
status: 'available',
specialization: 'Initial debugging setup and assessment',
averageTime: '3-5 minutes',
contextSavings: '~1000 tokens',
capabilities: includeCapabilities ? [
'Browser setup and URL injection',
'Initial screenshot capture',
'Console error collection',
'Basic audit and assessment',
'Framework detection'
] : undefined
},
{
name: 'performance-analysis-agent',
status: 'available',
specialization: 'Performance profiling and optimization',
averageTime: '5-10 minutes',
contextSavings: '~2000 tokens',
capabilities: includeCapabilities ? [
'Core Web Vitals analysis',
'Bundle size analysis',
'Runtime performance profiling',
'Memory usage tracking',
'Optimization recommendations'
] : undefined
},
{
name: 'accessibility-audit-agent',
status: 'available',
specialization: 'WCAG compliance and accessibility testing',
averageTime: '5-8 minutes',
contextSavings: '~1500 tokens',
capabilities: includeCapabilities ? [
'WCAG A/AA/AAA compliance testing',
'Keyboard navigation testing',
'Screen reader compatibility',
'Color contrast analysis',
'Semantic HTML validation'
] : undefined
},
{
name: 'error-investigation-agent',
status: 'available',
specialization: 'Error detection and root cause analysis',
averageTime: '3-7 minutes',
contextSavings: '~1800 tokens',
capabilities: includeCapabilities ? [
'JavaScript error analysis',
'Network failure investigation',
'Stack trace analysis',
'Error reproduction workflows',
'Root cause identification'
] : undefined
},
{
name: 'validation-testing-agent',
status: 'available',
specialization: 'Post-fix validation and regression testing',
averageTime: '4-8 minutes',
contextSavings: '~1200 tokens',
capabilities: includeCapabilities ? [
'Visual regression detection',
'Quality gate validation',
'Cross-browser testing',
'User flow verification',
'Performance impact assessment'
] : undefined
}
];
return {
content: [{
type: 'text',
text: `🤖 **AI-Debug Sub-Agent Status**
**Available Agents**: ${agents.length}
**Total Context Savings Potential**: ~${agents.reduce((acc, agent) => acc + parseInt(agent.contextSavings.match(/~(\d+)/)?.[1] || '0'), 0)} tokens
${agents.map(agent => `
**${agent.name}**
- Status: ${agent.status}
- Specialization: ${agent.specialization}
- Average Time: ${agent.averageTime}
- Context Savings: ${agent.contextSavings}
${agent.capabilities ? `- Capabilities: ${agent.capabilities.join(', ')}` : ''}
`).join('')}
**Usage**: Use \`delegate_to_debug_agent\` with your task description, and the system will automatically select the optimal agent.
**Benefit**: Keep your main conversation focused on high-level strategy while agents handle detailed debugging in their own contexts.`
}]
};
}
}
//# sourceMappingURL=sub-agent-coordinator.js.map