|
| 1 | +import inquirer from 'inquirer'; |
| 2 | +import { CheckpointConfig, CustomMilestone } from '../../types'; |
| 3 | +import { getDefaultCheckpointTriggers } from '../../generators/checkpointCommands'; |
| 4 | + |
| 5 | +export async function checkpointConfig(projectType: string): Promise<CheckpointConfig | undefined> { |
| 6 | + console.log('\n🛑 Checkpoint System Configuration:\n'); |
| 7 | + |
| 8 | + const { enableCheckpoints } = await inquirer.prompt([ |
| 9 | + { |
| 10 | + type: 'confirm', |
| 11 | + name: 'enableCheckpoints', |
| 12 | + message: 'Enable Human-in-the-Loop checkpoint system?', |
| 13 | + default: false, |
| 14 | + }, |
| 15 | + ]); |
| 16 | + |
| 17 | + if (!enableCheckpoints) { |
| 18 | + return undefined; |
| 19 | + } |
| 20 | + |
| 21 | + console.log('\n The checkpoint system will pause development at critical milestones'); |
| 22 | + console.log(' and request human verification before proceeding.\n'); |
| 23 | + |
| 24 | + const { triggerTypes } = await inquirer.prompt([ |
| 25 | + { |
| 26 | + type: 'checkbox', |
| 27 | + name: 'triggerTypes', |
| 28 | + message: 'Which types of milestones should trigger checkpoints?', |
| 29 | + choices: [ |
| 30 | + { |
| 31 | + name: 'Database connections and schema changes', |
| 32 | + value: 'database-connection', |
| 33 | + checked: true, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'Authentication and security implementations', |
| 37 | + value: 'authentication-setup', |
| 38 | + checked: true, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'API endpoints that modify data', |
| 42 | + value: 'api-endpoints', |
| 43 | + checked: true, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: 'External service integrations', |
| 47 | + value: 'integration-setup', |
| 48 | + checked: false, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: 'Production deployment configurations', |
| 52 | + value: 'production-deployment', |
| 53 | + checked: true, |
| 54 | + }, |
| 55 | + ...(projectType === 'fullstack' || projectType === 'api' |
| 56 | + ? [ |
| 57 | + { |
| 58 | + name: 'Data migrations and transformations', |
| 59 | + value: 'data-migration', |
| 60 | + checked: true, |
| 61 | + }, |
| 62 | + ] |
| 63 | + : []), |
| 64 | + ], |
| 65 | + }, |
| 66 | + ]); |
| 67 | + |
| 68 | + const { customMilestones } = await inquirer.prompt([ |
| 69 | + { |
| 70 | + type: 'confirm', |
| 71 | + name: 'customMilestones', |
| 72 | + message: 'Add custom project-specific milestones?', |
| 73 | + default: false, |
| 74 | + }, |
| 75 | + ]); |
| 76 | + |
| 77 | + // Get default triggers and filter by selected types |
| 78 | + const allTriggers = getDefaultCheckpointTriggers(projectType); |
| 79 | + const selectedTriggers = allTriggers.filter((trigger) => triggerTypes.includes(trigger.id)); |
| 80 | + |
| 81 | + const config: CheckpointConfig = { |
| 82 | + enabled: true, |
| 83 | + triggers: selectedTriggers, |
| 84 | + }; |
| 85 | + |
| 86 | + // Add custom milestones if requested |
| 87 | + if (customMilestones) { |
| 88 | + config.customMilestones = await collectCustomMilestones(); |
| 89 | + } |
| 90 | + |
| 91 | + return config; |
| 92 | +} |
| 93 | + |
| 94 | +async function collectCustomMilestones(): Promise<CustomMilestone[]> { |
| 95 | + const milestones: CustomMilestone[] = []; |
| 96 | + |
| 97 | + console.log('\n Define custom milestones for your project:'); |
| 98 | + |
| 99 | + let addMore = true; |
| 100 | + while (addMore) { |
| 101 | + const milestone = await inquirer.prompt([ |
| 102 | + { |
| 103 | + type: 'input', |
| 104 | + name: 'name', |
| 105 | + message: 'Milestone name:', |
| 106 | + validate: (input) => input.length > 0 || 'Please enter a milestone name', |
| 107 | + }, |
| 108 | + { |
| 109 | + type: 'input', |
| 110 | + name: 'description', |
| 111 | + message: 'Description:', |
| 112 | + validate: (input) => input.length > 0 || 'Please enter a description', |
| 113 | + }, |
| 114 | + { |
| 115 | + type: 'input', |
| 116 | + name: 'testInstructions', |
| 117 | + message: 'Test instructions (comma-separated):', |
| 118 | + filter: (input) => |
| 119 | + input |
| 120 | + .split(',') |
| 121 | + .map((s: string) => s.trim()) |
| 122 | + .filter((s: string) => s.length > 0), |
| 123 | + }, |
| 124 | + { |
| 125 | + type: 'confirm', |
| 126 | + name: 'blocksUntilApproved', |
| 127 | + message: 'Should this milestone BLOCK development until approved?', |
| 128 | + default: true, |
| 129 | + }, |
| 130 | + ]); |
| 131 | + |
| 132 | + const verificationPoints = [ |
| 133 | + `${milestone.name} functionality works as expected`, |
| 134 | + 'No breaking changes introduced', |
| 135 | + 'Performance is acceptable', |
| 136 | + ]; |
| 137 | + |
| 138 | + const fullMilestone = { |
| 139 | + ...milestone, |
| 140 | + verificationPoints, |
| 141 | + }; |
| 142 | + |
| 143 | + milestones.push(fullMilestone); |
| 144 | + |
| 145 | + const { continueAdding } = await inquirer.prompt([ |
| 146 | + { |
| 147 | + type: 'confirm', |
| 148 | + name: 'continueAdding', |
| 149 | + message: 'Add another custom milestone?', |
| 150 | + default: false, |
| 151 | + }, |
| 152 | + ]); |
| 153 | + |
| 154 | + addMore = continueAdding; |
| 155 | + } |
| 156 | + |
| 157 | + return milestones; |
| 158 | +} |
| 159 | + |
| 160 | +export function generateCheckpointSummary(config: CheckpointConfig): string { |
| 161 | + if (!config.enabled) { |
| 162 | + return 'Checkpoint system: Disabled'; |
| 163 | + } |
| 164 | + |
| 165 | + const triggerCount = config.triggers.length; |
| 166 | + const customCount = config.customMilestones?.length || 0; |
| 167 | + const criticalTriggers = config.triggers.filter((t) => t.category === 'critical').length; |
| 168 | + |
| 169 | + return `Checkpoint system: Enabled |
| 170 | + - ${triggerCount} automatic triggers (${criticalTriggers} critical) |
| 171 | + - ${customCount} custom milestones |
| 172 | + - Human verification required at key development points`; |
| 173 | +} |
0 commit comments