UNPKG

aura-ai

Version:

AI-powered marketing strategist CLI tool for developers

173 lines (151 loc) • 5.05 kB
import gitService from '../services/gitService.js' import syncAIService from '../services/syncAIService.js' import { exec } from 'child_process' import { promisify } from 'util' import fs from 'fs/promises' import path from 'path' const execAsync = promisify(exec) export async function syncCommand(options) { const { raw, since, copy, json, quiet } = options try { if (!quiet && !json && !raw) { console.log('šŸ”„ Generating AI progress report...') } // Get commits based on since parameter let commits if (since === 'today') { commits = await gitService.getTodayCommits() } else { // Custom date handling commits = await getCommitsSince(since) } if (commits.length === 0) { const message = 'No commits found for the specified period.' if (json) { console.log(JSON.stringify({ status: 'success', data: { summary: message, highlights: [], markdown: `# Daily Progress Report\n\n${message}`, commit_count: 0 } })) } else if (!raw) { console.log(`ā„¹ļø ${message}`) } return } // Generate AI report const formattedCommits = gitService.formatCommitsForAI(commits) const report = await syncAIService.generateDailyReport(formattedCommits) // Save report to dated markdown file const today = new Date() const year = today.getFullYear() const month = today.getMonth() + 1 const day = today.getDate() const filename = `${year}-${month}-${day}-update.md` try { await fs.writeFile(filename, report.markdown) if (!quiet && !raw) { console.log(`šŸ“„ Report saved to: ${filename}`) } } catch (err) { if (!quiet) { console.log(`āš ļø Could not save report to file: ${err.message}`) } } // Handle different output modes if (raw) { // Raw markdown only console.log(report.markdown) } else if (json) { // For agents: print readable content and auto-copy console.log('\n' + '='.repeat(60)) console.log('šŸ“Š AI DAILY SYNC REPORT') console.log('='.repeat(60) + '\n') // Print the markdown report console.log(report.markdown) console.log('\n' + '='.repeat(60)) // Auto copy to clipboard try { await copyToClipboard(report.markdown) console.log('āœ… Report automatically copied to clipboard!') } catch (err) { console.log('āš ļø Could not copy to clipboard:', err.message) } console.log('\nšŸ“ˆ Summary:', report.summary) console.log(`šŸ“ Based on ${commits.length} commits`) console.log('šŸ• Generated at:', new Date().toLocaleString()) console.log(`šŸ“„ Saved to: ${filename}`) console.log('='.repeat(60)) } else { // Human-readable output console.log('\nšŸ“Š Daily Progress Report') console.log('=' .repeat(50)) console.log(`\nšŸ’« ${report.summary}\n`) if (report.highlights && report.highlights.length > 0) { console.log('✨ Key Achievements:') report.highlights.forEach(h => console.log(` • ${h}`)) } console.log(`\nšŸ“ˆ Based on ${commits.length} commits today`) } // Copy to clipboard if requested (for non-json mode) if (copy && report.markdown && !json) { await copyToClipboard(report.markdown) if (!quiet) { console.log('\nāœ… Report copied to clipboard!') } } } catch (error) { if (json) { console.log(JSON.stringify({ status: 'error', error: error.message })) process.exit(1) } else { console.error(`āŒ Error: ${error.message}`) process.exit(1) } } } async function getCommitsSince(since) { try { const { stdout } = await execAsync( `git log --since="${since}" --format="%H|%s|%an|%ai"` ) if (!stdout.trim()) { return [] } return stdout.trim().split('\n').map(line => { const [hash, message, author, date] = line.split('|') return { hash: hash.substring(0, 7), message, author, date: new Date(date).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }) } }) } catch (error) { console.error('Error fetching commits:', error) return [] } } async function copyToClipboard(text) { const platform = process.platform try { if (platform === 'darwin') { await execAsync(`echo "${text.replace(/"/g, '\\"').replace(/\$/g, '\\$')}" | pbcopy`) } else if (platform === 'linux') { await execAsync(`echo "${text.replace(/"/g, '\\"').replace(/\$/g, '\\$')}" | xclip -selection clipboard`) } else if (platform === 'win32') { await execAsync(`echo "${text.replace(/"/g, '\\"').replace(/\$/g, '\\$')}" | clip`) } } catch (error) { throw new Error(`Failed to copy to clipboard: ${error.message}`) } }