UNPKG

repository-analyzer

Version:

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

141 lines (115 loc) • 4.65 kB
#!/usr/bin/env node /** * Post-install setup script for Repository Analyzer * Creates user directories and validates environment */ const fs = require('fs-extra'); const path = require('path'); const { execSync } = require('child_process'); const chalk = require('chalk'); async function setup() { console.log(chalk.blue('šŸš€ Setting up Repository Analyzer...\n')); try { // Create user config directory const homeDir = process.env.HOME || process.env.USERPROFILE; if (homeDir) { const configDir = path.join(homeDir, '.repo-analyzer'); const agentsDir = path.join(configDir, 'agents'); await fs.ensureDir(configDir); await fs.ensureDir(agentsDir); console.log(chalk.green('āœ… Created user config directory:')); console.log(chalk.gray(` ${configDir}`)); // Create sample custom agent template const sampleAgentPath = path.join(agentsDir, 'sample-custom-agent.md.template'); if (!await fs.pathExists(sampleAgentPath)) { const sampleAgent = `# Custom Agent Template <!-- id: my-custom-agent --> <!-- name: My Custom Agent --> <!-- description: A sample custom agent for demonstration --> <!-- order: 100 --> <!-- dependencies: scanner --> <!-- outputs: custom_output.json --> ## Role You are a custom analysis agent that demonstrates the extensibility of the Repository Analyzer system. ## Task Analyze the repository and extract custom insights based on your specific requirements. ## Input Variables - \`REPO_PATH\`: Path to the repository - \`SCANNER_OUTPUT\`: Output from the scanner agent (JSON) - \`REPO_INFO\`: Repository information (JSON) ## Output Format Return structured JSON: \`\`\`json { "custom_analysis": { "insight_1": "value", "insight_2": "value" }, "recommendations": ["recommendation1", "recommendation2"], "confidence_score": 0.85 } \`\`\` ## Instructions 1. Analyze the repository structure and content 2. Extract insights specific to your analysis domain 3. Provide actionable recommendations 4. Rate your confidence in the analysis (0.0-1.0) ## Example Analysis Based on the repository structure, identify patterns specific to your domain of expertise. `; await fs.writeFile(sampleAgentPath, sampleAgent); console.log(chalk.blue('šŸ“„ Created sample custom agent template')); } } // Check for Claude CLI console.log(chalk.blue('\nšŸ” Checking dependencies...')); try { execSync('claude --version', { stdio: 'ignore' }); console.log(chalk.green('āœ… Claude CLI detected')); } catch (error) { console.log(chalk.yellow('āš ļø Claude CLI not found')); console.log(chalk.gray(' Install from: https://claude.ai/code')); console.log(chalk.gray(' This is required for the analyzer to work')); } // Check Node.js version const nodeVersion = process.version; const requiredVersion = '16.0.0'; const semver = require('semver'); if (semver.gte(nodeVersion, requiredVersion)) { console.log(chalk.green(`āœ… Node.js ${nodeVersion} (compatible)`)); } else { console.log(chalk.red(`āŒ Node.js ${requiredVersion}+ required (current: ${nodeVersion})`)); } // Test write permissions try { const testFile = path.join(process.cwd(), '.test-write-permissions'); await fs.writeFile(testFile, 'test'); await fs.remove(testFile); console.log(chalk.green('āœ… Write permissions OK')); } catch (error) { console.log(chalk.yellow('āš ļø Limited write permissions')); } console.log(chalk.green('\nšŸŽ‰ Setup complete!')); console.log(chalk.blue('\nQuick start:')); console.log(chalk.gray(' repo-analyze --help # Show help')); console.log(chalk.gray(' repo-analyze --validate # Test setup')); console.log(chalk.gray(' repo-analyze --list-agents # Show agents')); console.log(chalk.gray(' repo-analyze /path/to/your/repository # Analyze')); if (homeDir) { console.log(chalk.blue('\nCustomization:')); console.log(chalk.gray(` Add custom agents to: ${path.join(homeDir, '.repo-analyzer', 'agents')}`)); console.log(chalk.gray(' Use the template file as a starting point')); } } catch (error) { console.error(chalk.red('āŒ Setup failed:'), error.message); process.exit(1); } } // Only run setup if called directly (not during testing) if (require.main === module) { setup().catch(error => { console.error(chalk.red('Setup error:'), error.message); process.exit(1); }); } module.exports = setup;