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
421 lines ⢠17.6 kB
JavaScript
/**
* Intelligent Workflow Sequencer
* Provides framework-specific debugging workflows and intelligent tool sequencing
* Based on real-world feedback for React, Next.js, and API debugging scenarios
*/
export class IntelligentWorkflowSequencer {
static instance;
workflows = new Map();
static getInstance() {
if (!IntelligentWorkflowSequencer.instance) {
IntelligentWorkflowSequencer.instance = new IntelligentWorkflowSequencer();
}
return IntelligentWorkflowSequencer.instance;
}
constructor() {
this.initializeWorkflows();
}
/**
* Get recommended workflow based on context and detected framework
*/
getRecommendedWorkflow(context) {
const workflowKey = `${context.framework}_${context.scenario}`;
return this.workflows.get(workflowKey) || this.getGenericWorkflow(context);
}
/**
* Generate intelligent workflow suggestions based on framework detection
*/
generateWorkflowSuggestion(context) {
const workflow = this.getRecommendedWorkflow(context);
if (!workflow) {
return "I'll help you debug this application. Let me start with basic diagnostics.";
}
let suggestion = `šÆ **${workflow.name}**\n\n`;
suggestion += `${workflow.description}\n\n`;
suggestion += `š **Recommended Debugging Sequence:**\n`;
workflow.steps.forEach((step, index) => {
const stepNum = index + 1;
suggestion += `${stepNum}. **${step.tool}** - ${step.description}\n`;
});
suggestion += `\nā±ļø **Estimated Duration:** ${workflow.estimatedDuration}\n`;
suggestion += `\nā
**Success Criteria:**\n`;
workflow.successCriteria.forEach(criteria => {
suggestion += `⢠${criteria}\n`;
});
if (workflow.commonIssues.length > 0) {
suggestion += `\nā ļø **Common Issues to Watch For:**\n`;
workflow.commonIssues.forEach(issue => {
suggestion += `⢠${issue}\n`;
});
}
suggestion += `\nShall I execute this debugging workflow?`;
return suggestion;
}
/**
* Initialize pre-defined workflows based on real-world usage patterns
*/
initializeWorkflows() {
// React Initial Debugging Workflow
this.workflows.set('react_initial_debug', {
name: 'React Application Initial Debug',
description: 'Comprehensive first-time debugging for React applications with component analysis',
framework: 'react',
scenario: 'initial_debug',
estimatedDuration: '3-5 minutes',
steps: [
{
tool: 'take_screenshot',
description: 'Capture baseline visual state of the application',
args: { fullPage: true }
},
{
tool: 'get_console_logs',
description: 'Check for React errors, warnings, and component issues',
},
{
tool: 'get_network_activity',
description: 'Analyze API calls and resource loading',
},
{
tool: 'get_performance_metrics',
description: 'Measure React component rendering performance',
},
{
tool: 'get_dom_snapshot',
description: 'Inspect React component tree and props',
}
],
successCriteria: [
'No console errors related to React components',
'All API endpoints responding correctly',
'Performance metrics within acceptable ranges',
'Visual elements rendering as expected'
],
commonIssues: [
'Hydration mismatches in SSR applications',
'Missing key props causing re-render issues',
'Infinite loops in useEffect hooks',
'State management problems with Context or Redux'
]
});
// Next.js API Integration Workflow
this.workflows.set('nextjs_api_integration', {
name: 'Next.js API Integration Debug',
description: 'Debug Next.js applications with focus on API routes and SSR/CSR behavior',
framework: 'nextjs',
scenario: 'api_integration',
estimatedDuration: '4-6 minutes',
steps: [
{
tool: 'take_screenshot',
description: 'Baseline screenshot for comparison',
},
{
tool: 'get_console_logs',
description: 'Check for hydration errors and Next.js warnings',
},
{
tool: 'get_network_activity',
description: 'Analyze API route calls and external API requests',
},
{
tool: 'simulate_user_action',
description: 'Test critical user interactions that trigger API calls',
args: { action: 'click', target: 'form submit buttons' }
},
{
tool: 'monitor_realtime',
description: 'Watch for real-time API responses and state changes',
args: { duration: 30 }
}
],
successCriteria: [
'API routes responding with correct status codes',
'No hydration mismatches between SSR and CSR',
'Form submissions working correctly',
'Real-time data updates functioning'
],
commonIssues: [
'CORS issues with external APIs',
'API route authentication problems',
'Hydration errors due to server/client state mismatch',
'Middleware configuration issues'
]
});
// Performance Analysis Workflow
this.workflows.set('react_performance_analysis', {
name: 'React Performance Deep Dive',
description: 'Comprehensive performance analysis for React applications',
framework: 'react',
scenario: 'performance_analysis',
estimatedDuration: '5-8 minutes',
steps: [
{
tool: 'get_performance_metrics',
description: 'Establish performance baseline',
},
{
tool: 'take_screenshot',
description: 'Visual confirmation of loaded state',
},
{
tool: 'simulate_user_action',
description: 'Test performance-critical user interactions',
args: { action: 'navigation and form interactions' }
},
{
tool: 'get_performance_metrics',
description: 'Compare performance after interactions',
},
{
tool: 'get_network_activity',
description: 'Analyze resource loading and API performance',
},
{
tool: 'monitor_realtime',
description: 'Watch for memory leaks and performance degradation',
args: { duration: 60 }
}
],
successCriteria: [
'LCP (Largest Contentful Paint) < 2.5s',
'FID (First Input Delay) < 100ms',
'CLS (Cumulative Layout Shift) < 0.1',
'No memory leaks detected',
'Bundle size optimizations identified'
],
commonIssues: [
'Large bundle sizes due to unnecessary imports',
'Unoptimized images causing slow LCP',
'Missing React.memo causing unnecessary re-renders',
'Memory leaks in event listeners or subscriptions'
]
});
// FastAPI Error Investigation Workflow
this.workflows.set('fastapi_error_investigation', {
name: 'FastAPI Error Investigation',
description: 'Debug FastAPI backend issues and API endpoint problems',
framework: 'fastapi',
scenario: 'error_investigation',
estimatedDuration: '3-5 minutes',
steps: [
{
tool: 'get_network_activity',
description: 'Analyze failed API requests and response codes',
},
{
tool: 'get_console_logs',
description: 'Check frontend errors related to API calls',
},
{
tool: 'simulate_user_action',
description: 'Reproduce the error scenario step by step',
args: { action: 'trigger API calls' }
},
{
tool: 'get_network_activity',
description: 'Capture detailed error responses and headers',
},
{
tool: 'get_debug_report',
description: 'Generate comprehensive error analysis report',
}
],
successCriteria: [
'API endpoints returning expected status codes',
'Error responses include helpful error messages',
'CORS headers configured correctly',
'Authentication/authorization working properly'
],
commonIssues: [
'CORS middleware not configured for frontend domain',
'Missing or incorrect authentication headers',
'Database connection issues',
'Validation errors not properly returned to frontend'
]
});
// Genetic Analysis Specific Workflow (Based on real session)
this.workflows.set('react_user_flow_test', {
name: 'Medical/Genetic Analysis User Flow Test',
description: 'Test complete user workflows for medical/genetic analysis applications',
framework: 'react',
scenario: 'user_flow_test',
estimatedDuration: '6-10 minutes',
steps: [
{
tool: 'take_screenshot',
description: 'Capture initial application state',
},
{
tool: 'get_console_logs',
description: 'Check for any initial errors or warnings',
},
{
tool: 'simulate_user_action',
description: 'Test file upload functionality',
args: { action: 'file upload simulation' }
},
{
tool: 'monitor_realtime',
description: 'Monitor upload progress and processing',
args: { duration: 45 }
},
{
tool: 'get_network_activity',
description: 'Verify backend communication and data processing',
},
{
tool: 'simulate_user_action',
description: 'Navigate through analysis results',
args: { action: 'result navigation' }
},
{
tool: 'take_screenshot',
description: 'Capture final results state',
args: { fullPage: true }
},
{
tool: 'get_performance_metrics',
description: 'Measure overall workflow performance',
}
],
successCriteria: [
'File upload completes successfully',
'Backend processing shows progress indicators',
'Analysis results display correctly',
'No sensitive data exposed in logs',
'Performance remains good throughout workflow'
],
commonIssues: [
'File upload size limits causing failures',
'Processing timeouts for large datasets',
'Memory issues with large genetic data files',
'Security issues with file handling'
]
});
}
/**
* Get generic workflow when specific framework workflow isn't available
*/
getGenericWorkflow(context) {
return {
name: 'Generic Application Debug',
description: 'Standard debugging approach for any web application',
framework: context.framework || 'unknown',
scenario: context.scenario,
estimatedDuration: '3-5 minutes',
steps: [
{
tool: 'take_screenshot',
description: 'Capture current application state',
},
{
tool: 'get_console_logs',
description: 'Check for JavaScript errors and warnings',
},
{
tool: 'get_network_activity',
description: 'Analyze network requests and responses',
},
{
tool: 'get_performance_metrics',
description: 'Measure application performance',
}
],
successCriteria: [
'No critical JavaScript errors',
'Network requests completing successfully',
'Acceptable performance metrics'
],
commonIssues: [
'JavaScript runtime errors',
'Network connectivity issues',
'Performance bottlenecks'
]
};
}
/**
* Detect framework from URL patterns and page content
*/
detectFramework(url, pageContent) {
// Framework detection logic based on URL patterns and page content
if (url.includes('next') || (pageContent && pageContent.includes('__NEXT_DATA__'))) {
return 'nextjs';
}
if (pageContent && (pageContent.includes('react') || pageContent.includes('ReactDOM'))) {
return 'react';
}
if (url.includes('uvicorn') || (pageContent && pageContent.includes('FastAPI')) || url.includes(':8000')) {
return 'fastapi';
}
return 'unknown';
}
/**
* Execute workflow step by step with intelligent error handling
*/
async executeWorkflow(workflow, executeToolFn) {
const results = [];
for (const step of workflow.steps) {
try {
console.log(`š Executing: ${step.tool} - ${step.description}`);
const result = await executeToolFn(step.tool, step.args);
results.push({
step: step.tool,
description: step.description,
result,
success: true
});
}
catch (error) {
console.error(`ā Step failed: ${step.tool}`, error);
results.push({
step: step.tool,
description: step.description,
error: error instanceof Error ? error.message : String(error),
success: false
});
// Continue with optional steps, stop on critical failures
if (!step.optional) {
console.log(`ā ļø Critical step failed, stopping workflow`);
break;
}
}
}
return results;
}
/**
* Generate workflow summary and recommendations
*/
generateWorkflowSummary(workflow, results) {
const successful = results.filter(r => r.success).length;
const total = results.length;
let summary = `š **Workflow Summary: ${workflow.name}**\n\n`;
summary += `ā
Completed: ${successful}/${total} steps\n\n`;
summary += `š **Step Results:**\n`;
results.forEach(result => {
const icon = result.success ? 'ā
' : 'ā';
summary += `${icon} ${result.step}: ${result.description}\n`;
if (!result.success) {
summary += ` Error: ${result.error}\n`;
}
});
// Check against success criteria
summary += `\nšÆ **Success Criteria Check:**\n`;
workflow.successCriteria.forEach(criteria => {
summary += `⢠${criteria} - Requires manual verification\n`;
});
// Provide next steps
if (successful === total) {
summary += `\nš **All steps completed successfully!** Your application appears to be functioning well.`;
}
else {
summary += `\nš§ **Next Steps:**\n`;
summary += `⢠Review failed steps and error messages\n`;
summary += `⢠Check common issues for this framework\n`;
summary += `⢠Consider running specific diagnostic tools for failed areas\n`;
}
return summary;
}
}
export default IntelligentWorkflowSequencer;
//# sourceMappingURL=intelligent-workflow-sequencer.js.map