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

536 lines 23.6 kB
/** * AI Feedback Handler * * MCP tools for collecting and analyzing feedback from AI users about their * experience with AI-Debug tools. Enables automatic tool improvement. */ import { BaseToolHandler } from './base-handler.js'; import { AIFeedbackCollector } from '../utils/ai-feedback-collector.js'; import { UserFriendlyLogger } from '../utils/user-friendly-logger.js'; export class AIFeedbackHandler extends BaseToolHandler { feedbackCollector; logger; constructor() { super(); this.feedbackCollector = new AIFeedbackCollector({ enableAutoCollection: true, feedbackFrequency: 'always', persistenceMode: 'file', // File persistence for permanent storage analysisEnabled: true, privacyMode: 'anonymous' }); this.logger = new UserFriendlyLogger('AIFeedbackHandler'); } tools = [ { name: 'collect_ai_feedback', description: '🤖 COLLECT AI FEEDBACK: Submit feedback about your experience with AI-Debug tools. Help improve the system for all AI users by sharing what worked well and what could be better.', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session ID from your debugging session' }, agentType: { type: 'string', description: 'Which agent you worked with', enum: [ 'debug-discovery-agent', 'performance-analysis-agent', 'accessibility-audit-agent', 'error-investigation-agent', 'validation-testing-agent', 'framework-specialist-agent', 'data-extraction-agent', 'testing-infrastructure-agent' ] }, taskDescription: { type: 'string', description: 'Brief description of what you were trying to accomplish' }, outcome: { type: 'string', description: 'How did your session go?', enum: ['success', 'partial_success', 'failure'] }, ratings: { type: 'object', description: 'Rate your experience (1-10 scale)', properties: { satisfaction: { type: 'number', minimum: 1, maximum: 10 }, efficiency: { type: 'number', minimum: 1, maximum: 10 }, clarity: { type: 'number', minimum: 1, maximum: 10 }, usefulness: { type: 'number', minimum: 1, maximum: 10 } } }, feedback: { type: 'object', description: 'Detailed feedback about your experience', properties: { strengths: { type: 'array', items: { type: 'string' }, description: 'What worked well?' }, weaknesses: { type: 'array', items: { type: 'string' }, description: 'What could be improved?' }, suggestions: { type: 'array', items: { type: 'string' }, description: 'Specific suggestions for improvement' }, wouldUseAgain: { type: 'boolean', description: 'Would you use this agent again?' }, recommendToOthers: { type: 'boolean', description: 'Would you recommend this to other AI users?' } } }, context: { type: 'object', description: 'Context about your session', properties: { framework: { type: 'string' }, projectComplexity: { type: 'string', enum: ['simple', 'moderate', 'complex'] }, sessionDuration: { type: 'number', description: 'Session duration in milliseconds' }, tokensEstimatedSaved: { type: 'number', description: 'Estimated tokens saved' }, toolsUsed: { type: 'array', items: { type: 'string' }, description: 'List of tools used during session' } } } }, required: ['sessionId', 'agentType', 'taskDescription', 'outcome'] } }, { name: 'get_feedback_summary', description: '📊 GET FEEDBACK SUMMARY: Retrieve analytics and insights from collected AI user feedback. View performance trends, improvement opportunities, and user satisfaction metrics.', inputSchema: { type: 'object', properties: { scope: { type: 'string', description: 'Scope of feedback summary', enum: ['all', 'agent_specific', 'tool_specific', 'framework_specific'], default: 'all' }, agentType: { type: 'string', description: 'Specific agent to analyze (required if scope is agent_specific)', enum: [ 'debug-discovery-agent', 'performance-analysis-agent', 'accessibility-audit-agent', 'error-investigation-agent', 'validation-testing-agent', 'framework-specialist-agent', 'data-extraction-agent', 'testing-infrastructure-agent' ] }, framework: { type: 'string', description: 'Specific framework to analyze (required if scope is framework_specific)' }, tool: { type: 'string', description: 'Specific tool to analyze (required if scope is tool_specific)' }, includeDetailedAnalytics: { type: 'boolean', description: 'Include comprehensive analytics and improvement recommendations', default: false }, forceRefresh: { type: 'boolean', description: 'Force refresh of analytics cache', default: false } } } }, { name: 'configure_feedback_collection', description: '⚙️ CONFIGURE FEEDBACK COLLECTION: Adjust feedback collection settings, privacy preferences, and analysis options.', inputSchema: { type: 'object', properties: { enableAutoCollection: { type: 'boolean', description: 'Automatically collect feedback after sessions' }, feedbackFrequency: { type: 'string', description: 'When to collect feedback', enum: ['always', 'success_only', 'failure_only', 'periodic'] }, privacyMode: { type: 'string', description: 'Privacy level for collected data', enum: ['full', 'anonymous', 'opt_in'] }, analysisEnabled: { type: 'boolean', description: 'Enable analytics and trend analysis' }, customPrompts: { type: 'object', description: 'Custom feedback prompts', properties: { postSuccess: { type: 'string' }, postFailure: { type: 'string' }, postSession: { type: 'string' } } } } } }, { name: 'generate_feedback_prompt', description: '💬 GENERATE FEEDBACK PROMPT: Create a contextual feedback prompt for AI users to encourage valuable feedback submission.', inputSchema: { type: 'object', properties: { sessionOutcome: { type: 'string', description: 'Outcome of the session', enum: ['success', 'failure', 'session_end'] }, context: { type: 'object', description: 'Session context for prompt customization', properties: { agentType: { type: 'string' }, toolsUsed: { type: 'array', items: { type: 'string' } }, sessionDuration: { type: 'number' }, tokensEstimatedSaved: { type: 'number' } }, required: ['agentType', 'toolsUsed', 'sessionDuration'] } }, required: ['sessionOutcome', 'context'] } }, { name: 'export_feedback_data', description: '📤 EXPORT FEEDBACK DATA: Export collected feedback data for external analysis, reporting, or backup purposes.', inputSchema: { type: 'object', properties: { format: { type: 'string', description: 'Export format', enum: ['json', 'csv'], default: 'json' }, includeAnalytics: { type: 'boolean', description: 'Include calculated analytics in export', default: false }, anonymize: { type: 'boolean', description: 'Remove identifying information from export', default: true } } } }, { name: 'get_feedback_storage_info', description: '💾 GET FEEDBACK STORAGE INFO: Get information about where feedback is stored, file locations, and storage statistics.', inputSchema: { type: 'object', properties: {} } } ]; async handle(toolName, args) { try { switch (toolName) { case 'collect_ai_feedback': return await this.collectAIFeedback(args); case 'get_feedback_summary': return await this.getFeedbackSummary(args); case 'configure_feedback_collection': return await this.configureFeedbackCollection(args); case 'generate_feedback_prompt': return await this.generateFeedbackPrompt(args); case 'export_feedback_data': return await this.exportFeedbackData(args); case 'get_feedback_storage_info': return await this.getFeedbackStorageInfo(args); default: throw new Error(`Unknown AI feedback tool: ${toolName}`); } } catch (error) { this.logger.error(`AI feedback tool error: ${error instanceof Error ? error.message : 'Unknown error'}`); throw error; } } /** * Collect feedback from AI user */ async collectAIFeedback(args) { const { sessionId, agentType, taskDescription, outcome, ratings = {}, feedback = {}, context = {} } = args; this.logger.info(`🤖 Collecting feedback for ${agentType} session: ${sessionId}`); // Build comprehensive feedback entry const feedbackEntry = { taskDescription, outcome, userExperience: { satisfaction: ratings.satisfaction || 8, efficiency: ratings.efficiency || 8, clarity: ratings.clarity || 8, usefulness: ratings.usefulness || 8 }, feedback: { strengths: feedback.strengths || [], weaknesses: feedback.weaknesses || [], suggestions: feedback.suggestions || [], wouldUseAgain: feedback.wouldUseAgain !== false, recommendToOthers: feedback.recommendToOthers !== false }, technicalMetrics: { responseTimeMs: context.responseTime || 0, tokensSaved: context.tokensEstimatedSaved || 0, errorsEncountered: context.errors || [], recoveryActions: context.recoveryActions || [] }, contextualData: { framework: context.framework || 'unknown', projectComplexity: context.projectComplexity || 'moderate', userType: 'ai_assistant', sessionDuration: context.sessionDuration || 0 }, toolsUsed: context.toolsUsed || [] }; // Collect the feedback const feedbackId = await this.feedbackCollector.collectFeedback(sessionId, agentType, feedbackEntry); this.logger.success(`✅ Feedback collected successfully: ${feedbackId}`); // Ultra-simplified response for Claude Code CLI compatibility return { success: true, id: feedbackId, message: 'Feedback collected successfully' }; } /** * Get feedback summary and analytics */ async getFeedbackSummary(args) { this.logger.info(`📊 Generating feedback summary for scope: ${args.scope || 'all'}`); try { const analytics = await this.feedbackCollector.getFeedbackAnalytics(); // Ultra-simplified response for Claude Code CLI compatibility const entryCount = analytics.totalFeedbackEntries || 0; const avgSatisfaction = analytics.averageRatings?.satisfaction || 0; this.logger.info(`✅ Generated feedback summary with ${entryCount} entries`); // Return minimal flat structure return { success: true, message: `Analyzed ${entryCount} feedback entries`, entryCount, satisfaction: Math.round(avgSatisfaction * 10) / 10 }; } catch (error) { this.logger.error(`Failed to generate feedback summary: ${error instanceof Error ? error.message : 'Unknown error'}`); return { success: false, message: 'Error generating summary', entryCount: 0, satisfaction: 0 }; } } /** * Configure feedback collection settings */ async configureFeedbackCollection(args) { const { enableAutoCollection, feedbackFrequency, privacyMode, analysisEnabled, customPrompts } = args; this.logger.info('⚙️ Updating feedback collection configuration'); const configUpdate = {}; if (enableAutoCollection !== undefined) configUpdate.enableAutoCollection = enableAutoCollection; if (feedbackFrequency) configUpdate.feedbackFrequency = feedbackFrequency; if (privacyMode) configUpdate.privacyMode = privacyMode; if (analysisEnabled !== undefined) configUpdate.analysisEnabled = analysisEnabled; if (customPrompts) configUpdate.feedbackPrompts = { ...customPrompts }; this.feedbackCollector.updateConfiguration(configUpdate); const currentConfig = this.feedbackCollector.getConfiguration(); this.logger.success('✅ Feedback collection configuration updated'); return { success: true, message: 'Feedback collection configuration updated successfully', currentConfiguration: currentConfig, changes: Object.keys(configUpdate), effects: [ enableAutoCollection !== undefined && `Auto-collection ${enableAutoCollection ? 'enabled' : 'disabled'}`, feedbackFrequency && `Feedback frequency set to: ${feedbackFrequency}`, privacyMode && `Privacy mode set to: ${privacyMode}`, analysisEnabled !== undefined && `Analytics ${analysisEnabled ? 'enabled' : 'disabled'}` ].filter(Boolean) }; } /** * Generate contextual feedback prompt */ async generateFeedbackPrompt(args) { const { sessionOutcome, context } = args; this.logger.info(`💬 Generating feedback prompt for ${sessionOutcome} session`); const prompt = this.feedbackCollector.generateFeedbackPrompt(sessionOutcome, context); return { success: true, sessionOutcome, agentType: context.agentType, prompt, quickFeedbackUrl: `collect_ai_feedback({ sessionId: "your_session_id", agentType: "${context.agentType}", ... })`, estimatedTime: '2-3 minutes', importance: 'Your feedback directly improves AI-Debug tools for all AI users! 🤖✨' }; } /** * Export feedback data */ async exportFeedbackData(args) { const { format = 'json' } = args; this.logger.info(`📤 Exporting feedback data in ${format} format`); try { const exportedData = this.feedbackCollector.exportFeedbackData(format); const dataSize = exportedData.length; this.logger.info(`✅ Exported feedback data (${dataSize} characters)`); // Ultra-simplified response for Claude Code CLI compatibility return { success: true, message: `Export completed: ${dataSize} characters`, size: dataSize }; } catch (error) { this.logger.error(`Failed to export feedback data: ${error instanceof Error ? error.message : 'Unknown error'}`); return { success: false, message: 'Export failed', size: 0 }; } } /** * Get feedback storage information */ async getFeedbackStorageInfo(args) { this.logger.info('💾 Getting feedback storage information'); const storageInfo = this.feedbackCollector.getStorageInfo(); this.logger.info(`✅ Storage info retrieved: ${storageInfo.persistenceMode} mode, ${storageInfo.memoryEntries} entries`); // Ultra-simplified response for Claude Code CLI compatibility return { success: true, mode: storageInfo.persistenceMode, entries: storageInfo.memoryEntries, location: storageInfo.storageLocation }; } /** * Helper: Get most effective agent */ getMostEffectiveAgent(agentPerformance) { const agents = Object.entries(agentPerformance); if (agents.length === 0) return 'No data'; const bestAgent = agents.reduce((best, [agentType, performance]) => { if (performance.averageRating > best.rating) { return { agent: agentType, rating: performance.averageRating }; } return best; }, { agent: 'unknown', rating: 0 }); return bestAgent.agent; } /** * Helper: Get top performing agents */ getTopPerformingAgents(agentPerformance, limit) { return Object.entries(agentPerformance) .map(([agentType, performance]) => ({ agentType, averageRating: performance.averageRating, usageCount: performance.usageCount, topStrengths: performance.topStrengths })) .sort((a, b) => b.averageRating - a.averageRating) .slice(0, limit); } /** * Helper: Calculate trends */ calculateTrends(analytics) { // This would implement trend analysis return { satisfactionTrend: 'stable', usageTrend: 'increasing', errorTrend: 'decreasing' }; } /** * Helper: Generate agent recommendations */ generateAgentRecommendations(agentSummary) { const recommendations = []; if (agentSummary.totalSessions === 0) { recommendations.push('No usage data yet - encourage AI users to try this agent'); return recommendations; } if (agentSummary.averageRatings.satisfaction < 7) { recommendations.push('Address user satisfaction issues - review top weaknesses'); } if (agentSummary.topStrengths.length > 0) { recommendations.push(`Promote key strengths: ${agentSummary.topStrengths[0]}`); } if (agentSummary.topWeaknesses.length > 0) { recommendations.push(`Priority improvement: ${agentSummary.topWeaknesses[0]}`); } return recommendations; } /** * Helper: Generate system recommendations */ generateSystemRecommendations(analytics) { const recommendations = []; if (analytics.averageRatings.satisfaction < 8) { recommendations.push('Focus on improving overall user satisfaction'); } if (analytics.improvementOpportunities.length > 0) { const topOpportunity = analytics.improvementOpportunities[0]; recommendations.push(`High priority: ${topOpportunity.description}`); } recommendations.push('Continue collecting feedback to refine improvements'); return recommendations; } } //# sourceMappingURL=ai-feedback-handler.js.map