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
270 lines âĸ 12.1 kB
JavaScript
/**
* Flutter Analysis Workflow
* Revolutionary AI-guided Flutter debugging workflow
* Automatically orchestrates comprehensive Flutter analysis
*/
import { WorkflowEngine } from './workflow-engine.js';
export class FlutterAnalysisWorkflow extends WorkflowEngine {
getTemplate() {
return {
name: 'Smart Flutter Analysis',
description: 'AI-guided comprehensive Flutter application analysis',
steps: this.getInitialSteps(),
adaptiveLogic: this.adaptiveLogic.bind(this),
generateSummary: this.generateSummary.bind(this)
};
}
getInitialSteps() {
return [
{
tool: 'flutter_health_check',
args: {},
condition: () => true // Always run health check first
},
{
tool: 'take_screenshot',
args: { fullPage: true },
condition: (results) => this.hasSession(results)
},
{
tool: 'get_console_logs',
args: { level: 'all', limit: 50 },
condition: (results) => this.hasSession(results)
},
{
tool: 'flutter_config',
args: {},
condition: () => true // Always get Flutter config
}
];
}
adaptiveLogic(results) {
const adaptedSteps = [];
// Analyze health check results to determine next steps
const healthResult = results.find(r => r.tool === 'flutter_health_check');
if (healthResult && healthResult.success) {
const healthData = this.extractHealthData(healthResult);
// If health score is low, add performance analysis
if (healthData.score < 80) {
adaptedSteps.push({
tool: 'flutter_performance',
args: {},
condition: () => true
});
adaptedSteps.push({
tool: 'flutter_web_issues',
args: {},
condition: () => true
});
}
// If accessibility issues detected, add accessibility tools
if (healthData.accessibility < 90) {
adaptedSteps.push({
tool: 'run_audit',
args: { categories: ['accessibility'] },
condition: (results) => this.hasSession(results)
});
}
}
// Analyze console logs for specific issues
const consoleResult = results.find(r => r.tool === 'get_console_logs');
if (consoleResult && consoleResult.success) {
const hasErrors = this.hasConsoleErrors(consoleResult);
if (hasErrors) {
// Add widget tree analysis for UI-related errors
adaptedSteps.push({
tool: 'flutter_widget_tree',
args: {},
condition: () => true
});
// Add memory leak detection for performance errors
adaptedSteps.push({
tool: 'flutter_memory_leaks',
args: {},
condition: () => true
});
}
}
return adaptedSteps;
}
generateSummary(results, context) {
const sections = this.formatResults('Smart Flutter Analysis', results, context);
// Add Flutter-specific analysis
sections.push('## đ¯ **Flutter Analysis Results**');
sections.push('');
// Analyze health check results
const healthResult = results.find(r => r.tool === 'flutter_health_check');
if (healthResult && healthResult.success) {
const healthData = this.extractHealthData(healthResult);
sections.push(`**Overall Health**: ${this.getHealthStatus(healthData.score)} (${healthData.score}/100)`);
sections.push(`**Flutter Version**: ${healthData.version || 'Unknown'}`);
sections.push(`**Renderer**: ${healthData.renderer || 'Auto-detected'}`);
sections.push('');
}
// Analyze console logs
const consoleResult = results.find(r => r.tool === 'get_console_logs');
if (consoleResult && consoleResult.success) {
const logSummary = this.analyzeConsoleLogs(consoleResult);
sections.push('### đ **Console Analysis**');
sections.push(`**Total Messages**: ${logSummary.total}`);
sections.push(`**â Errors**: ${logSummary.errors}`);
sections.push(`**â ī¸ Warnings**: ${logSummary.warnings}`);
sections.push(`**âšī¸ Info**: ${logSummary.info}`);
if (logSummary.criticalIssues.length > 0) {
sections.push('**Critical Issues**:');
logSummary.criticalIssues.forEach((issue) => {
sections.push(` - ${issue}`);
});
}
sections.push('');
}
// Add performance insights
const performanceResult = results.find(r => r.tool === 'flutter_performance');
if (performanceResult && performanceResult.success) {
sections.push('### ⥠**Performance Analysis**');
const perfData = this.extractPerformanceData(performanceResult);
sections.push(`**FPS**: ${perfData.fps || 'N/A'}`);
sections.push(`**Frame Build Time**: ${perfData.buildTime || 'N/A'}ms`);
sections.push(`**Memory Usage**: ${perfData.memory || 'N/A'}MB`);
sections.push('');
}
// Add intelligent recommendations
sections.push('## đ§ **AI Recommendations**');
const recommendations = this.generateRecommendations(results, context);
recommendations.forEach(rec => sections.push(`- ${rec}`));
sections.push('');
// Extract and add insights
const insights = this.extractInsights(results);
if (insights.length > 0) {
sections.push(...insights);
}
return sections.join('\n');
}
hasSession(results) {
// Check if we have a valid session for browser-based tools
return results.length === 0 || results.some(r => r.success);
}
extractHealthData(result) {
try {
const content = result.result?.content?.[0]?.text || '';
// Extract health score
const scoreMatch = content.match(/Health Score[:\s]*(\d+)/i);
const score = scoreMatch ? parseInt(scoreMatch[1]) : 100;
// Extract version
const versionMatch = content.match(/Flutter Version[:\s]*([^\n]*)/i);
const version = versionMatch ? versionMatch[1].trim() : null;
// Extract renderer
const rendererMatch = content.match(/Renderer[:\s]*([^\n]*)/i);
const renderer = rendererMatch ? rendererMatch[1].trim() : null;
return { score, version, renderer, accessibility: 90 };
}
catch {
return { score: 100, version: null, renderer: null, accessibility: 90 };
}
}
getHealthStatus(score) {
if (score >= 95)
return 'đĸ Excellent';
if (score >= 80)
return 'đĄ Good';
if (score >= 60)
return 'đ Needs Attention';
return 'đ´ Critical Issues';
}
hasConsoleErrors(result) {
try {
const content = result.result?.content?.[0]?.text || '';
return content.toLowerCase().includes('error') ||
content.toLowerCase().includes('exception') ||
content.toLowerCase().includes('failed');
}
catch {
return false;
}
}
analyzeConsoleLogs(result) {
try {
const content = result.result?.content?.[0]?.text || '';
const lines = content.split('\n');
const errors = lines.filter((line) => line.toLowerCase().includes('error')).length;
const warnings = lines.filter((line) => line.toLowerCase().includes('warning')).length;
const info = lines.filter((line) => line.toLowerCase().includes('info')).length;
const criticalIssues = [];
if (content.includes('Uncaught'))
criticalIssues.push('Uncaught exceptions detected');
if (content.includes('404'))
criticalIssues.push('Missing resources (404 errors)');
if (content.includes('CORS'))
criticalIssues.push('CORS policy violations');
return {
total: lines.length,
errors,
warnings,
info,
criticalIssues
};
}
catch {
return { total: 0, errors: 0, warnings: 0, info: 0, criticalIssues: [] };
}
}
extractPerformanceData(result) {
try {
const content = result.result?.content?.[0]?.text || '';
const fpsMatch = content.match(/FPS[:\s]*(\d+(?:\.\d+)?)/i);
const buildTimeMatch = content.match(/Build Time[:\s]*(\d+(?:\.\d+)?)/i);
const memoryMatch = content.match(/Memory[:\s]*(\d+(?:\.\d+)?)/i);
return {
fps: fpsMatch ? parseFloat(fpsMatch[1]) : null,
buildTime: buildTimeMatch ? parseFloat(buildTimeMatch[1]) : null,
memory: memoryMatch ? parseFloat(memoryMatch[1]) : null
};
}
catch {
return { fps: null, buildTime: null, memory: null };
}
}
generateRecommendations(results, context) {
const recommendations = [];
// Health-based recommendations
const healthResult = results.find(r => r.tool === 'flutter_health_check');
if (healthResult && healthResult.success) {
const healthData = this.extractHealthData(healthResult);
if (healthData.score < 80) {
recommendations.push('đ§ **Flutter Health**: Run `flutter doctor` to resolve configuration issues');
}
if (healthData.score < 60) {
recommendations.push('đ¨ **Critical**: Multiple Flutter issues detected - consider environment reset');
}
}
// Console-based recommendations
const consoleResult = results.find(r => r.tool === 'get_console_logs');
if (consoleResult && consoleResult.success) {
const logSummary = this.analyzeConsoleLogs(consoleResult);
if (logSummary.errors > 0) {
recommendations.push('đ **Console Errors**: Address JavaScript errors for better stability');
}
if (logSummary.criticalIssues.includes('Missing resources (404 errors)')) {
recommendations.push('đ **Missing Resources**: Check asset paths and manifest configuration');
}
}
// Performance-based recommendations
const performanceResult = results.find(r => r.tool === 'flutter_performance');
if (performanceResult && performanceResult.success) {
const perfData = this.extractPerformanceData(performanceResult);
if (perfData.fps && perfData.fps < 50) {
recommendations.push('⥠**Low FPS**: Optimize widget rebuilds and use const constructors');
}
if (perfData.buildTime && perfData.buildTime > 16) {
recommendations.push('đī¸ **Slow Builds**: Consider breaking down large widgets');
}
}
// Context-specific recommendations
if (context.intelligenceLevel === 'expert') {
recommendations.push('đ§ **Expert Mode**: Consider running `smart_tdd_workflow` for test coverage analysis');
recommendations.push('đ **Advanced**: Use `smart_performance_analysis` for deeper optimization');
}
return recommendations;
}
}
//# sourceMappingURL=flutter-analysis-workflow.js.map