From 42a14840282691942cae5e3f0db45b2ecb3bf48c Mon Sep 17 00:00:00 2001 From: Joe Danziger Date: Sun, 11 May 2025 16:09:42 -0400 Subject: [PATCH] add confirmation for rules removal --- scripts/modules/commands.js | 11 +++++++++++ scripts/modules/ui.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/modules/commands.js b/scripts/modules/commands.js index 45839ee4..45389f58 100644 --- a/scripts/modules/commands.js +++ b/scripts/modules/commands.js @@ -519,6 +519,17 @@ function registerCommands(programInstance) { .flatMap((b) => b.split(',').map((s) => s.trim())) .filter(Boolean); + if (action === 'remove') { + const ui = await import('./ui.js'); + const confirmed = await ui.confirmRulesRemove(expandedBrands); + if (!confirmed) { + console.log(chalk.yellow('Aborted: No rules were removed.')); + return; + } + } + + // (removed duplicate projectDir, brands check, and expandedBrands parsing) + const removalResults = []; for (const brand of expandedBrands) { diff --git a/scripts/modules/ui.js b/scripts/modules/ui.js index 975a9055..d9440622 100644 --- a/scripts/modules/ui.js +++ b/scripts/modules/ui.js @@ -1725,6 +1725,36 @@ IMPORTANT: Make sure to include an analysis for EVERY task listed above, with th `; } +/** + * Confirm removing brand rules (destructive operation) + * @param {string[]} brands - Array of brand names to remove + * @returns {Promise} - Promise resolving to true if user confirms, false otherwise + */ +async function confirmRulesRemove(brands) { + const brandList = brands + .map((b) => b.charAt(0).toUpperCase() + b.slice(1)) + .join(', '); + console.log( + boxen( + chalk.yellow( + `WARNING: This will permanently delete all rules and configuration for: ${brandList}. +This will remove the entire .[brand] directory for each selected brand.\n\nAre you sure you want to proceed?` + ), + { padding: 1, borderColor: 'yellow', borderStyle: 'round' } + ) + ); + const inquirer = await import('inquirer'); + const { confirm } = await inquirer.default.prompt([ + { + type: 'confirm', + name: 'confirm', + message: 'Type y to confirm, or n to abort:', + default: false + } + ]); + return confirm; +} + /** * Confirm overwriting existing tasks.json file * @param {string} tasksPath - Path to the tasks.json file @@ -1991,5 +2021,6 @@ export { confirmTaskOverwrite, displayApiKeyStatus, displayModelConfiguration, - displayAvailableModels + displayAvailableModels, + confirmRulesRemove };