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
220 lines • 8.96 kB
JavaScript
/**
* Debug Orchestrator - High-level debugging coordination
*
* This is the main entry point for all debugging tasks.
* It analyzes the user's request and delegates to appropriate sub-agents.
*/
export class DebugOrchestrator {
subAgents = {
frontend: 'frontend_debug_agent',
backend: 'backend_debug_agent',
performance: 'performance_debug_agent',
error: 'error_investigation_agent',
visual: 'visual_analysis_agent'
};
async orchestrate(task) {
console.error('🎯 Debug Orchestrator: Analyzing task...');
// 1. Analyze what kind of debugging is needed
const analysis = this.analyzeTask(task);
// 2. Create execution plan
const plan = this.createExecutionPlan(analysis);
// 3. Execute plan with sub-agents
const results = await this.executePlan(plan);
// 4. Synthesize results into actionable summary
return this.synthesizeResults(results);
}
analyzeTask(task) {
const keywords = (task.description || task.task || '').toLowerCase();
const analysis = {
primaryDomain: 'unknown',
subDomains: [],
confidence: 0,
suggestedAgents: []
};
// Detect primary debugging domain
if (keywords.includes('slow') || keywords.includes('performance')) {
analysis.primaryDomain = 'performance';
analysis.suggestedAgents.push(this.subAgents.performance);
}
else if (keywords.includes('error') || keywords.includes('crash') || keywords.includes('bug')) {
analysis.primaryDomain = 'error';
analysis.suggestedAgents.push(this.subAgents.error);
}
else if (keywords.includes('look') || keywords.includes('visual') || keywords.includes('ui')) {
analysis.primaryDomain = 'visual';
analysis.suggestedAgents.push(this.subAgents.visual);
}
else if (keywords.includes('api') || keywords.includes('backend') || keywords.includes('server')) {
analysis.primaryDomain = 'backend';
analysis.suggestedAgents.push(this.subAgents.backend);
}
else {
analysis.primaryDomain = 'frontend';
analysis.suggestedAgents.push(this.subAgents.frontend);
}
// Detect secondary domains
if (task.url) {
analysis.subDomains.push('web-based');
if (!analysis.suggestedAgents.includes(this.subAgents.frontend)) {
analysis.suggestedAgents.push(this.subAgents.frontend);
}
}
if (task.errorMessage) {
analysis.subDomains.push('has-errors');
if (!analysis.suggestedAgents.includes(this.subAgents.error)) {
analysis.suggestedAgents.push(this.subAgents.error);
}
}
analysis.confidence = analysis.suggestedAgents.length > 0 ? 0.8 : 0.3;
return analysis;
}
createExecutionPlan(analysis) {
const plan = {
steps: [],
parallel: false,
estimatedDuration: 0
};
// Always start with basic diagnostics
plan.steps.push({
agent: this.subAgents.frontend,
action: 'initial_diagnosis',
params: {
captureScreenshot: true,
checkConsole: true,
detectFramework: true
}
});
// Add domain-specific steps
switch (analysis.primaryDomain) {
case 'performance':
plan.steps.push({
agent: this.subAgents.performance,
action: 'full_performance_audit',
params: {
metrics: ['LCP', 'FCP', 'CLS', 'TTI'],
profile: true,
suggestions: true
}
});
break;
case 'error':
plan.steps.push({
agent: this.subAgents.error,
action: 'investigate_errors',
params: {
captureStack: true,
traceOrigin: true,
suggestFixes: true
}
});
break;
case 'visual':
plan.steps.push({
agent: this.subAgents.visual,
action: 'visual_analysis',
params: {
captureFullPage: true,
detectIssues: true,
compareToBaseline: false
}
});
break;
}
// Estimate duration
plan.estimatedDuration = plan.steps.length * 5; // 5 seconds per step
return plan;
}
async executePlan(plan) {
const results = [];
for (const step of plan.steps) {
console.log(` → Delegating to ${step.agent} for ${step.action}...`);
// In real implementation, this would call actual sub-agents
// For now, we'll create a mock result
const result = {
agent: step.agent,
action: step.action,
success: true,
summary: `Completed ${step.action} successfully`,
data: {
// This would contain actual debugging data
findings: [],
metrics: {},
suggestions: []
},
duration: Math.random() * 3000 + 1000 // 1-4 seconds
};
results.push(result);
// If critical error found, might need to pivot strategy
if (step.action === 'initial_diagnosis' && result.data.criticalError) {
console.error(' ⚠️ Critical error detected, adjusting plan...');
// Modify remaining steps based on findings
}
}
return results;
}
synthesizeResults(results) {
// Aggregate findings from all sub-agents
const allFindings = results.flatMap(r => r.data.findings || []);
const allSuggestions = results.flatMap(r => r.data.suggestions || []);
// Create concise summary
const summary = this.createSummary(results);
// Determine next steps
const nextSteps = this.determineNextSteps(allFindings);
return {
success: results.every(r => r.success),
summary,
findings: {
critical: allFindings.filter(f => f.severity === 'critical'),
warnings: allFindings.filter(f => f.severity === 'warning'),
info: allFindings.filter(f => f.severity === 'info')
},
suggestions: allSuggestions,
nextSteps,
metadata: {
duration: results.reduce((sum, r) => sum + r.duration, 0),
agentsUsed: results.map(r => r.agent),
confidence: this.calculateConfidence(results)
}
};
}
createSummary(results) {
const summaryParts = [];
// Get key findings from each agent
for (const result of results) {
if (result.data.findings && result.data.findings.length > 0) {
const agentName = result.agent.replace('_agent', '').replace('_', ' ');
summaryParts.push(`${agentName}: ${result.summary}`);
}
}
if (summaryParts.length === 0) {
return "No significant issues found. Application appears to be functioning normally.";
}
return summaryParts.join(' | ');
}
determineNextSteps(findings) {
const steps = [];
// Prioritize based on severity
const criticalCount = findings.filter(f => f.severity === 'critical').length;
const warningCount = findings.filter(f => f.severity === 'warning').length;
if (criticalCount > 0) {
steps.push('Fix critical issues immediately');
steps.push('Run fix_orchestrator to apply automated fixes');
}
if (warningCount > 0) {
steps.push('Review warnings and plan fixes');
steps.push('Run test_orchestrator after fixes');
}
if (steps.length === 0) {
steps.push('Consider running performance_orchestrator for optimization');
steps.push('Set up monitoring to prevent future issues');
}
return steps;
}
calculateConfidence(results) {
// Calculate overall confidence based on sub-agent results
const successRate = results.filter(r => r.success).length / results.length;
const hasFindings = results.some(r => r.data.findings && r.data.findings.length > 0);
return successRate * (hasFindings ? 0.9 : 0.7);
}
}
//# sourceMappingURL=debug-orchestrator.js.map