|
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | +import { checkbox } from '@inquirer/prompts'; |
| 5 | +import chalk from 'chalk'; |
| 6 | +import { parseFrontmatter } from '../lib/frontmatter.js'; |
| 7 | +import { writeFile } from '../lib/writer.js'; |
| 8 | + |
| 9 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 10 | +const TEMPLATES_DIR = path.join(__dirname, '..', 'templates'); |
| 11 | + |
| 12 | +const CHECKS = [ |
| 13 | + { file: 'code-review.md', name: 'Code Review', description: 'Reviews code quality and patterns' }, |
| 14 | + { file: 'security.md', name: 'Security', description: 'Scans for OWASP vulnerabilities, hardcoded secrets' }, |
| 15 | + { file: 'test-coverage.md', name: 'Test Coverage', description: 'Ensures new code has tests' }, |
| 16 | + { file: 'pr-description.md', name: 'PR Description', description: 'Validates PR descriptions' }, |
| 17 | +]; |
| 18 | + |
| 19 | +const AGENTS = [ |
| 20 | + { file: 'all-green.md', name: 'All Green', description: 'Fix checks, resolve conflicts, address reviews, merge' }, |
| 21 | + { file: 'fix-issue.md', name: 'Fix Issue', description: 'Takes a GitHub issue and creates a fix PR' }, |
| 22 | + { file: 'triage-issues.md', name: 'Triage Issues', description: 'Auto-label and respond to new issues' }, |
| 23 | +]; |
| 24 | + |
| 25 | +export function createCommand(program) { |
| 26 | + program |
| 27 | + .command('create', { isDefault: true }) |
| 28 | + .description('Interactively scaffold .continue/checks and .continue/agents') |
| 29 | + .option('--dir <path>', 'Target directory', process.cwd()) |
| 30 | + .action(async (opts) => { |
| 31 | + console.log(); |
| 32 | + console.log(chalk.bold(' Continue Software Factory')); |
| 33 | + console.log(); |
| 34 | + |
| 35 | + const categories = await checkbox({ |
| 36 | + message: 'What would you like to set up?', |
| 37 | + choices: [ |
| 38 | + { name: 'Checks (run automatically on PRs)', value: 'checks', checked: true }, |
| 39 | + { name: 'Agents (triggered by events or on-demand)', value: 'agents', checked: true }, |
| 40 | + ], |
| 41 | + }); |
| 42 | + |
| 43 | + if (categories.length === 0) { |
| 44 | + console.log(chalk.yellow('\n Nothing selected. Exiting.\n')); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + let selectedChecks = []; |
| 49 | + let selectedAgents = []; |
| 50 | + |
| 51 | + if (categories.includes('checks')) { |
| 52 | + selectedChecks = await checkbox({ |
| 53 | + message: 'Select checks:', |
| 54 | + choices: CHECKS.map((c) => ({ |
| 55 | + name: `${c.name} — ${c.description}`, |
| 56 | + value: c.file, |
| 57 | + checked: false, |
| 58 | + })), |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + if (categories.includes('agents')) { |
| 63 | + selectedAgents = await checkbox({ |
| 64 | + message: 'Select agents:', |
| 65 | + choices: AGENTS.map((a) => ({ |
| 66 | + name: `${a.name} — ${a.description}`, |
| 67 | + value: a.file, |
| 68 | + checked: false, |
| 69 | + })), |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + const total = selectedChecks.length + selectedAgents.length; |
| 74 | + if (total === 0) { |
| 75 | + console.log(chalk.yellow('\n No files selected. Exiting.\n')); |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + console.log(); |
| 80 | + |
| 81 | + let written = 0; |
| 82 | + |
| 83 | + for (const file of selectedChecks) { |
| 84 | + const src = path.join(TEMPLATES_DIR, 'checks', file); |
| 85 | + const dest = path.join(opts.dir, '.continue', 'checks', file); |
| 86 | + const content = fs.readFileSync(src, 'utf-8'); |
| 87 | + if (await writeFile(dest, content)) { |
| 88 | + written++; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + for (const file of selectedAgents) { |
| 93 | + const src = path.join(TEMPLATES_DIR, 'agents', file); |
| 94 | + const dest = path.join(opts.dir, '.continue', 'agents', file); |
| 95 | + const content = fs.readFileSync(src, 'utf-8'); |
| 96 | + if (await writeFile(dest, content)) { |
| 97 | + written++; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + console.log(chalk.bold(`\n Done! ${written} file${written === 1 ? '' : 's'} created.\n`)); |
| 102 | + }); |
| 103 | +} |
0 commit comments