UNPKG

incize

Version:

AI Commit Copilot for Power Developers

338 lines (337 loc) 16.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CLIOutputRenderer = void 0; const chalk_1 = __importDefault(require("chalk")); class CLIOutputRenderer { brandColor = chalk_1.default.hex('#6366f1'); // Indigo accentColor = chalk_1.default.hex('#8b5cf6'); // Purple successColor = chalk_1.default.hex('#10b981'); // Emerald warningColor = chalk_1.default.hex('#f59e0b'); // Amber errorColor = chalk_1.default.hex('#ef4444'); // Red infoColor = chalk_1.default.hex('#3b82f6'); // Blue /** * Render complete Incize output with modern design */ renderOutput(output) { this.renderHeader(); this.renderCommitInfo(output.commit); this.renderDiffSummary(output.diff); this.renderAnalysis(output.analysis); this.renderFooter(); } /** * Render modern header with Incize branding */ renderHeader() { console.log('\n'); console.log(this.brandColor.bold(' ⚡ Incize Analysis')); console.log(this.brandColor(' AI-Powered Commit Intelligence')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(''); } /** * Render commit information with modern styling */ renderCommitInfo(commit) { console.log(this.infoColor.bold(' 📋 Commit Context')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); const commitHash = commit.hash.substring(0, 8); const date = new Date(commit.date).toLocaleString(); console.log(` ${chalk_1.default.gray('Hash:')} ${this.brandColor(commitHash)}`); console.log(` ${chalk_1.default.gray('Author:')} ${this.accentColor(commit.author)}`); console.log(` ${chalk_1.default.gray('Branch:')} ${this.successColor(commit.branch)}`); console.log(` ${chalk_1.default.gray('Message:')} ${chalk_1.default.yellow(commit.message)}`); console.log(` ${chalk_1.default.gray('Date:')} ${chalk_1.default.gray(date)}`); console.log(''); } /** * Render diff summary with intelligent metrics */ renderDiffSummary(diff) { console.log(this.infoColor.bold(' 📊 Change Metrics')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); const { additions, deletions, totalChanges } = diff.summary; const fileCount = diff.files.length; // Calculate change intensity const intensity = totalChanges > 100 ? 'High' : totalChanges > 50 ? 'Medium' : 'Low'; const intensityColor = totalChanges > 100 ? this.warningColor : totalChanges > 50 ? this.infoColor : this.successColor; console.log(` ${chalk_1.default.gray('Files Changed:')} ${this.brandColor(fileCount)}`); console.log(` ${chalk_1.default.gray('Lines Added:')} ${this.successColor(`+${additions}`)}`); console.log(` ${chalk_1.default.gray('Lines Removed:')} ${this.errorColor(`-${deletions}`)}`); console.log(` ${chalk_1.default.gray('Total Changes:')} ${this.accentColor(totalChanges)}`); console.log(` ${chalk_1.default.gray('Change Intensity:')} ${intensityColor(intensity)}`); if (diff.files.length > 0) { const languages = [...new Set(diff.files.map(f => f.language).filter(Boolean))]; if (languages.length > 0) { console.log(` ${chalk_1.default.gray('Languages:')} ${this.accentColor(languages.join(', '))}`); } } console.log(''); } /** * Render AI analysis with modern, intelligent design */ renderAnalysis(analysis) { console.log(this.brandColor.bold(' 🤖 AI Intelligence')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); // Summary with smart formatting console.log(this.infoColor.bold(' 📋 Analysis Summary')); console.log(` ${this.formatSummary(analysis.summary)}\n`); // Risk Assessment with modern visualization this.renderRiskAssessment(analysis); // Smart Suggestions if (analysis.suggestions.length > 0) { console.log(this.successColor.bold(' 💡 Smart Recommendations')); analysis.suggestions.forEach((suggestion) => { const icon = this.getSuggestionIcon(suggestion); console.log(` ${icon} ${suggestion}`); }); console.log(''); } // Changelog with modern styling if (analysis.changelog) { console.log(this.accentColor.bold(' 📝 Generated Changelog')); console.log(` ${chalk_1.default.gray('┌─')} ${analysis.changelog}`); console.log(` ${chalk_1.default.gray('└─')} ${chalk_1.default.gray('Ready for release notes')}\n`); } // Test Suggestions with modern design if (analysis.testSuggestions.length > 0) { console.log(this.warningColor.bold(' 🧪 Test Coverage Suggestions')); analysis.testSuggestions.forEach((test) => { console.log(` ${chalk_1.default.gray('├─')} ${test}`); }); console.log(` ${chalk_1.default.gray('└─')} ${chalk_1.default.gray('Consider implementing these tests')}\n`); } // Confidence with modern visualization this.renderConfidence(analysis.confidence); } /** * Format summary with intelligent line breaks */ formatSummary(summary) { if (summary.length > 80) { const words = summary.split(' '); let lines = []; let currentLine = ''; for (const word of words) { if ((currentLine + word).length > 60) { lines.push(currentLine.trim()); currentLine = word + ' '; } else { currentLine += word + ' '; } } lines.push(currentLine.trim()); return lines.map((line, index) => index === 0 ? line : ' ' + line).join('\n '); } return summary; } /** * Render risk assessment with modern design */ renderRiskAssessment(analysis) { const { riskScore, riskLevel } = analysis; console.log(this.warningColor.bold(' ⚠️ Risk Assessment')); // Risk score with color-coded bar const riskBar = this.createModernRiskBar(riskScore); const riskColor = this.getRiskColor(riskLevel); console.log(` ${chalk_1.default.gray('Score:')} ${riskColor(`${riskScore}/100`)}`); console.log(` ${chalk_1.default.gray('Level:')} ${riskColor(riskLevel.toUpperCase())}`); console.log(` ${chalk_1.default.gray('Bar:')} ${riskBar}\n`); } /** * Create modern risk bar with gradient effect */ createModernRiskBar(score) { const barLength = 20; const filledLength = Math.round((score / 100) * barLength); const emptyLength = barLength - filledLength; const filledBar = '█'.repeat(filledLength); const emptyBar = '░'.repeat(emptyLength); const riskColor = score > 80 ? this.errorColor : score > 60 ? this.warningColor : score > 40 ? this.infoColor : this.successColor; return riskColor(filledBar) + chalk_1.default.gray(emptyBar); } /** * Get risk color based on level */ getRiskColor(level) { switch (level.toLowerCase()) { case 'critical': return this.errorColor; case 'high': return this.warningColor; case 'medium': return this.infoColor; case 'low': return this.successColor; default: return chalk_1.default.white; } } /** * Get suggestion icon based on content */ getSuggestionIcon(suggestion) { const lower = suggestion.toLowerCase(); if (lower.includes('security') || lower.includes('auth')) return '🔐'; if (lower.includes('performance')) return '⚡'; if (lower.includes('test')) return '🧪'; if (lower.includes('docs')) return '📝'; if (lower.includes('fix')) return '🐛'; if (lower.includes('refactor')) return '♻️'; return '💡'; } /** * Render confidence with modern design */ renderConfidence(confidence) { console.log(this.accentColor.bold(' 🎯 AI Confidence')); const confidenceBar = this.createModernConfidenceBar(confidence); const confidenceColor = confidence > 0.8 ? this.successColor : confidence > 0.6 ? this.infoColor : confidence > 0.4 ? this.warningColor : this.errorColor; console.log(` ${chalk_1.default.gray('Level:')} ${confidenceColor(`${Math.round(confidence * 100)}%`)}`); console.log(` ${chalk_1.default.gray('Bar:')} ${confidenceBar}\n`); } /** * Create modern confidence bar */ createModernConfidenceBar(confidence) { const barLength = 20; const filledLength = Math.round(confidence * barLength); const emptyLength = barLength - filledLength; const filledBar = '█'.repeat(filledLength); const emptyBar = '░'.repeat(emptyLength); const confidenceColor = confidence > 0.8 ? this.successColor : confidence > 0.6 ? this.infoColor : confidence > 0.4 ? this.warningColor : this.errorColor; return confidenceColor(filledBar) + chalk_1.default.gray(emptyBar); } /** * Render modern footer */ renderFooter() { console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(this.brandColor.bold(' ⚡ Incize v0.2.0')); console.log(chalk_1.default.gray(' AI-Powered Commit Intelligence for Power Developers')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(''); } /** * Render error with modern design */ renderError(message, details) { console.log('\n'); console.log(this.errorColor.bold(' ❌ Error')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(` ${message}`); if (details) { console.log(` ${chalk_1.default.gray('Details:')} ${details}`); } console.log(''); } /** * Render warning with modern design */ renderWarning(message) { console.log('\n'); console.log(this.warningColor.bold(' ⚠️ Warning')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(` ${message}\n`); } /** * Render success with modern design */ renderSuccess(message) { console.log('\n'); console.log(this.successColor.bold(' ✅ Success')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(` ${message}\n`); } /** * Render info with modern design */ renderInfo(message) { console.log(` ${this.infoColor('ℹ️')} ${message}`); } /** * Render loading with modern design */ renderLoading(message) { console.log(` ${this.brandColor('⏳')} ${message}`); } /** * Render JSON output */ renderJSON(output) { console.log(JSON.stringify(output, null, 2)); } /** * Render Markdown output */ renderMarkdown(output) { console.log('# Incize Analysis Report\n'); console.log(`**Commit:** ${output.commit.hash.substring(0, 8)}`); console.log(`**Author:** ${output.commit.author}`); console.log(`**Branch:** ${output.commit.branch}\n`); console.log('## Risk Assessment\n'); console.log(`- **Score:** ${output.analysis.riskScore}/100`); console.log(`- **Level:** ${output.analysis.riskLevel}\n`); console.log('## Summary\n'); console.log(output.analysis.summary); } /** * Render authentication status with modern design */ renderAuthStatus(authStatus) { console.log('\n'); console.log(this.brandColor.bold(' 🔐 Authentication Status')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); if (authStatus.authenticated && authStatus.user) { console.log(` ${chalk_1.default.gray('Status:')} ${this.successColor('✓ Authenticated')}`); console.log(` ${chalk_1.default.gray('User ID:')} ${this.brandColor(authStatus.user.userId)}`); console.log(` ${chalk_1.default.gray('Tier:')} ${this.accentColor(authStatus.user.subscriptionTier)}`); console.log(` ${chalk_1.default.gray('Last Login:')} ${chalk_1.default.gray(new Date(authStatus.user.lastLogin).toLocaleString())}`); } else { console.log(` ${chalk_1.default.gray('Status:')} ${this.errorColor('✗ Not authenticated')}`); console.log(` ${chalk_1.default.gray('Action:')} ${this.infoColor('Run `incize auth login` to authenticate')}`); } console.log(''); } /** * Render user information after successful login */ renderUserInfo(user) { console.log('\n'); console.log(this.successColor.bold(' 👤 User Information')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(` ${chalk_1.default.gray('User ID:')} ${this.brandColor(user.userId)}`); console.log(` ${chalk_1.default.gray('Subscription:')} ${this.accentColor(user.subscriptionTier)}`); console.log(` ${chalk_1.default.gray('Preferences:')} ${this.infoColor('Default model: ' + user.preferences.default_model)}`); console.log(` ${chalk_1.default.gray('Risk Threshold:')} ${this.warningColor(user.preferences.risk_threshold + '/100')}`); console.log(''); } /** * Render authentication help */ renderAuthHelp() { console.log('\n'); console.log(this.infoColor.bold(' 🔐 Authentication Commands')); console.log(chalk_1.default.gray(' ──────────────────────────────────────────────────────────')); console.log(` ${this.brandColor('incize auth login')} ${chalk_1.default.gray('Authenticate with your account')}`); console.log(` ${this.brandColor('incize auth logout')} ${chalk_1.default.gray('Logout from your account')}`); console.log(` ${this.brandColor('incize auth status')} ${chalk_1.default.gray('Check authentication status')}`); console.log(` ${this.brandColor('incize auth help')} ${chalk_1.default.gray('Show this help message')}`); console.log(''); } } exports.CLIOutputRenderer = CLIOutputRenderer;