|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Agentic Code Standards CLI |
| 5 | + * Interactive installer for AI coding agent standards |
| 6 | + */ |
| 7 | + |
| 8 | +const fs = require('fs'); |
| 9 | +const path = require('path'); |
| 10 | +const readline = require('readline'); |
| 11 | + |
| 12 | +const rl = readline.createInterface({ |
| 13 | + input: process.stdin, |
| 14 | + output: process.stdout |
| 15 | +}); |
| 16 | + |
| 17 | +// ANSI colors |
| 18 | +const colors = { |
| 19 | + reset: '\x1b[0m', |
| 20 | + bright: '\x1b[1m', |
| 21 | + cyan: '\x1b[36m', |
| 22 | + green: '\x1b[32m', |
| 23 | + yellow: '\x1b[33m', |
| 24 | + blue: '\x1b[34m', |
| 25 | + red: '\x1b[31m' |
| 26 | +}; |
| 27 | + |
| 28 | +function log(message, color = 'reset') { |
| 29 | + console.log(`${colors[color]}${message}${colors.reset}`); |
| 30 | +} |
| 31 | + |
| 32 | +function header() { |
| 33 | + console.log(''); |
| 34 | + log('🤖 Agentic Code Standards', 'cyan'); |
| 35 | + log('━'.repeat(60), 'cyan'); |
| 36 | + log('Production-ready standards for AI coding agents', 'bright'); |
| 37 | + console.log(''); |
| 38 | +} |
| 39 | + |
| 40 | +function detectAITool() { |
| 41 | + const cwd = process.cwd(); |
| 42 | + |
| 43 | + if (fs.existsSync(path.join(cwd, '.cursorrules'))) return 'cursor'; |
| 44 | + if (fs.existsSync(path.join(cwd, '.windsurfrules'))) return 'windsurf'; |
| 45 | + if (fs.existsSync(path.join(cwd, '.agent'))) return 'antigravity'; |
| 46 | + if (fs.existsSync(path.join(cwd, '.github', 'copilot-instructions.md'))) return 'copilot'; |
| 47 | + |
| 48 | + return null; |
| 49 | +} |
| 50 | + |
| 51 | +function question(prompt) { |
| 52 | + return new Promise((resolve) => { |
| 53 | + rl.question(`${colors.bright}${prompt}${colors.reset} `, resolve); |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +async function selectProfile() { |
| 58 | + console.log(''); |
| 59 | + log('📋 Choose your profile:', 'blue'); |
| 60 | + console.log(''); |
| 61 | + log(' 1. Minimal Essential rules only (great for getting started)'); |
| 62 | + log(' 2. Standard Recommended baseline ⭐ (most popular)'); |
| 63 | + log(' 3. Strict All rules enforced (maximum code quality)'); |
| 64 | + log(' 4. Accessibility WCAG 2.1+ focused (a11y priority)'); |
| 65 | + console.log(''); |
| 66 | + |
| 67 | + const answer = await question('Enter number (1-4) [default: 2]:'); |
| 68 | + const choice = answer.trim() || '2'; |
| 69 | + |
| 70 | + const profiles = { |
| 71 | + '1': 'minimal', |
| 72 | + '2': 'standard', |
| 73 | + '3': 'strict', |
| 74 | + '4': 'accessibility' |
| 75 | + }; |
| 76 | + |
| 77 | + return profiles[choice] || 'standard'; |
| 78 | +} |
| 79 | + |
| 80 | +async function selectTool() { |
| 81 | + const detected = detectAITool(); |
| 82 | + |
| 83 | + if (detected) { |
| 84 | + console.log(''); |
| 85 | + log(`✅ Detected: ${detected.charAt(0).toUpperCase() + detected.slice(1)}`, 'green'); |
| 86 | + const answer = await question(`Continue with ${detected}? (Y/n):`); |
| 87 | + if (!answer.trim() || answer.toLowerCase() === 'y') { |
| 88 | + return detected; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + console.log(''); |
| 93 | + log('🛠️ Select your AI coding tool:', 'blue'); |
| 94 | + console.log(''); |
| 95 | + log(' 1. Cursor (.cursorrules)'); |
| 96 | + log(' 2. Windsurf (.windsurfrules)'); |
| 97 | + log(' 3. Antigravity (.agent/rules/)'); |
| 98 | + log(' 4. GitHub Copilot (.github/copilot-instructions.md)'); |
| 99 | + log(' 5. Universal Works with most tools ⭐'); |
| 100 | + console.log(''); |
| 101 | + |
| 102 | + const answer = await question('Enter number (1-5) [default: 5]:'); |
| 103 | + const choice = answer.trim() || '5'; |
| 104 | + |
| 105 | + const tools = { |
| 106 | + '1': 'cursor', |
| 107 | + '2': 'windsurf', |
| 108 | + '3': 'antigravity', |
| 109 | + '4': 'copilot', |
| 110 | + '5': 'universal' |
| 111 | + }; |
| 112 | + |
| 113 | + return tools[choice] || 'universal'; |
| 114 | +} |
| 115 | + |
| 116 | +function copyTemplate(profile, tool) { |
| 117 | + const templatesDir = path.join(__dirname, '..', 'templates'); |
| 118 | + const cwd = process.cwd(); |
| 119 | + |
| 120 | + try { |
| 121 | + if (tool === 'antigravity') { |
| 122 | + // Copy Antigravity .agent/rules/ structure |
| 123 | + const sourceDir = path.join(templatesDir, 'antigravity', profile, '.agent', 'rules'); |
| 124 | + const targetDir = path.join(cwd, '.agent', 'rules'); |
| 125 | + |
| 126 | + if (!fs.existsSync(targetDir)) { |
| 127 | + fs.mkdirSync(targetDir, { recursive: true }); |
| 128 | + } |
| 129 | + |
| 130 | + const files = fs.readdirSync(sourceDir); |
| 131 | + files.forEach(file => { |
| 132 | + fs.copyFileSync( |
| 133 | + path.join(sourceDir, file), |
| 134 | + path.join(targetDir, file) |
| 135 | + ); |
| 136 | + }); |
| 137 | + |
| 138 | + console.log(''); |
| 139 | + log(`✨ Created .agent/rules/ with ${profile} profile`, 'green'); |
| 140 | + log(` Files: ${files.join(', ')}`, 'cyan'); |
| 141 | + |
| 142 | + } else if (tool === 'copilot') { |
| 143 | + const sourceFile = path.join(templatesDir, profile, '.cursorrules'); |
| 144 | + const targetDir = path.join(cwd, '.github'); |
| 145 | + const targetFile = path.join(targetDir, 'copilot-instructions.md'); |
| 146 | + |
| 147 | + if (!fs.existsSync(targetDir)) { |
| 148 | + fs.mkdirSync(targetDir, { recursive: true }); |
| 149 | + } |
| 150 | + |
| 151 | + fs.copyFileSync(sourceFile, targetFile); |
| 152 | + |
| 153 | + console.log(''); |
| 154 | + log(`✨ Created .github/copilot-instructions.md with ${profile} profile`, 'green'); |
| 155 | + |
| 156 | + } else { |
| 157 | + const sourceFile = path.join(templatesDir, profile, '.cursorrules'); |
| 158 | + let targetFile; |
| 159 | + |
| 160 | + if (tool === 'windsurf') { |
| 161 | + targetFile = path.join(cwd, '.windsurfrules'); |
| 162 | + } else { |
| 163 | + targetFile = path.join(cwd, '.cursorrules'); |
| 164 | + } |
| 165 | + |
| 166 | + fs.copyFileSync(sourceFile, targetFile); |
| 167 | + |
| 168 | + console.log(''); |
| 169 | + log(`✨ Created ${path.basename(targetFile)} with ${profile} profile`, 'green'); |
| 170 | + } |
| 171 | + |
| 172 | + return true; |
| 173 | + } catch (error) { |
| 174 | + console.log(''); |
| 175 | + log(`❌ Error: ${error.message}`, 'red'); |
| 176 | + return false; |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +function showNextSteps(tool, profile) { |
| 181 | + console.log(''); |
| 182 | + log('🎉 Setup complete!', 'green'); |
| 183 | + console.log(''); |
| 184 | + log('Next steps:', 'bright'); |
| 185 | + log(' 1. Review your rules file(s)'); |
| 186 | + log(' 2. Customize for your project needs'); |
| 187 | + log(' 3. Start coding with your AI agent!'); |
| 188 | + console.log(''); |
| 189 | + |
| 190 | + log('📚 Documentation:', 'blue'); |
| 191 | + log(' https://github.com/yourusername/agentic-code-standards'); |
| 192 | + console.log(''); |
| 193 | + |
| 194 | + if (tool === 'antigravity') { |
| 195 | + log('💡 Tip: Antigravity auto-loads rules from .agent/rules/', 'yellow'); |
| 196 | + } else if (tool === 'copilot') { |
| 197 | + log('💡 Tip: Copilot reads instructions from .github/copilot-instructions.md', 'yellow'); |
| 198 | + } else { |
| 199 | + log('💡 Tip: Your AI agent will automatically use these rules', 'yellow'); |
| 200 | + } |
| 201 | + |
| 202 | + console.log(''); |
| 203 | + log('⭐ Star us on GitHub if this helped!', 'cyan'); |
| 204 | + console.log(''); |
| 205 | +} |
| 206 | + |
| 207 | +async function main() { |
| 208 | + try { |
| 209 | + header(); |
| 210 | + |
| 211 | + const profile = await selectProfile(); |
| 212 | + const tool = await selectTool(); |
| 213 | + |
| 214 | + console.log(''); |
| 215 | + log('⚙️ Installing...', 'cyan'); |
| 216 | + |
| 217 | + const success = copyTemplate(profile, tool); |
| 218 | + |
| 219 | + if (success) { |
| 220 | + showNextSteps(tool, profile); |
| 221 | + } |
| 222 | + |
| 223 | + rl.close(); |
| 224 | + process.exit(success ? 0 : 1); |
| 225 | + |
| 226 | + } catch (error) { |
| 227 | + console.log(''); |
| 228 | + log(`❌ Error: ${error.message}`, 'red'); |
| 229 | + log('Please report this issue on GitHub', 'yellow'); |
| 230 | + rl.close(); |
| 231 | + process.exit(1); |
| 232 | + } |
| 233 | +} |
| 234 | + |
| 235 | +// Handle command line args |
| 236 | +const args = process.argv.slice(2); |
| 237 | + |
| 238 | +if (args.length === 0 || args[0] === 'init') { |
| 239 | + main(); |
| 240 | +} else if (args[0] === '--version' || args[0] === '-v') { |
| 241 | + const packageJson = require('../package.json'); |
| 242 | + console.log(packageJson.version); |
| 243 | + process.exit(0); |
| 244 | +} else if (args[0] === '--help' || args[0] === '-h') { |
| 245 | + console.log(''); |
| 246 | + log('Usage: npx agentic-code-standards [command]', 'cyan'); |
| 247 | + console.log(''); |
| 248 | + log('Commands:'); |
| 249 | + log(' init Initialize standards (default)'); |
| 250 | + log(' --version, -v Show version'); |
| 251 | + log(' --help, -h Show this help'); |
| 252 | + console.log(''); |
| 253 | + process.exit(0); |
| 254 | +} else { |
| 255 | + log('Unknown command. Use --help for usage information.', 'red'); |
| 256 | + process.exit(1); |
| 257 | +} |
0 commit comments