UNPKG

repository-analyzer

Version:

Transform code repositories into strategic intelligence using extensible AI agents. Analyze technical debt, business value, and deployment readiness automatically.

144 lines (120 loc) 4.97 kB
#!/usr/bin/env node /** * Repository Analyzer - CLI Entry Point * Extensible AI agent system for repository analysis */ const path = require('path'); const fs = require('fs'); const semver = require('semver'); // Check Node.js version const nodeVersion = process.version; const requiredVersion = '16.0.0'; if (!semver.gte(nodeVersion, requiredVersion)) { console.error(`❌ Node.js ${requiredVersion} or higher is required. Current: ${nodeVersion}`); console.error('Please update Node.js: https://nodejs.org/'); process.exit(1); } // Handle uncaught errors gracefully process.on('uncaughtException', (error) => { console.error('❌ Unexpected error:', error.message); if (process.env.DEBUG) { console.error(error.stack); } else { console.error('Run with DEBUG=1 for full error details'); } process.exit(1); }); process.on('unhandledRejection', (error) => { console.error('❌ Unhandled promise rejection:', error.message); if (process.env.DEBUG) { console.error(error.stack); } process.exit(1); }); // Main execution async function main() { try { // Check if this is a development environment const isDev = fs.existsSync(path.join(__dirname, '../src')); let RepositoryAnalyzer; if (isDev) { // Development mode - use TypeScript directly require('ts-node/register'); RepositoryAnalyzer = require('../src/index.ts').RepositoryAnalyzer; } else { // Production mode - use compiled JavaScript const distPath = path.join(__dirname, '../dist/index.js'); if (!fs.existsSync(distPath)) { console.error('❌ Installation appears to be corrupted.'); console.error('Try reinstalling: npm uninstall -g @repo-agents/analyzer && npm install -g @repo-agents/analyzer'); process.exit(1); } RepositoryAnalyzer = require(distPath).RepositoryAnalyzer; } // Initialize and run analyzer const analyzer = new RepositoryAnalyzer(); const exitCode = await analyzer.main(); process.exit(exitCode); } catch (error) { console.error('❌ Failed to start Repository Analyzer:', error.message); // Provide helpful troubleshooting information console.error('\n🔧 Troubleshooting:'); console.error('1. Ensure Claude CLI is installed: https://claude.ai/code'); console.error('2. Check installation: repo-analyze --validate'); console.error('3. Try reinstalling: npm uninstall -g @repo-agents/analyzer && npm install -g @repo-agents/analyzer'); console.error('4. Report issues: https://github.com/repo-agents/analyzer/issues'); process.exit(1); } } // Quick version check if (process.argv.includes('--version') || process.argv.includes('-v')) { const packageJson = require('../package.json'); console.log(`Repository Analyzer v${packageJson.version}`); process.exit(0); } // Quick help if (process.argv.includes('--help') || process.argv.includes('-h')) { console.log(` 🚀 Repository Analyzer v${require('../package.json').version} Transform your code repositories into strategic intelligence using extensible AI agents. USAGE: repo-analyze <path> Analyze repository or directory repo-analyze --config Interactive configuration repo-analyze --validate Validate system setup repo-analyze --list-agents List available agents EXAMPLES: repo-analyze ./my-project Analyze single repository repo-analyze ~/projects Analyze multiple repositories repo-analyze /code --quick Quick analysis mode repo-analyze /code --output ~/results Custom output location repo-analyze --agents scanner,tech Use specific agents only OPTIONS: --config Interactive configuration setup --validate Validate system requirements --list-agents Show all available agents --agents <list> Comma-separated list of agents to use --quick Quick analysis mode --deep Deep analysis mode --output <dir> Custom output directory --jobs <number> Parallel jobs (1-8) --preview Preview what would be analyzed --no-open Don't auto-open results --verbose Verbose output --version Show version --help Show this help AGENT EXTENSIBILITY: Add custom agents by placing .md files in: ~/.repo-analyzer/agents/ User agents ./agents/ Project-specific agents Agent files are automatically discovered and can be used with --agents option. GETTING STARTED: 1. First run: repo-analyze --config 2. Test: repo-analyze --validate 3. Analyze: repo-analyze /path/to/your/repositories Documentation: https://github.com/repo-agents/analyzer Support: https://github.com/repo-agents/analyzer/issues `); process.exit(0); } // Run main function main();