add interactive rules setup

This commit is contained in:
Joe Danziger
2025-05-12 19:03:17 -04:00
parent 83c984caf0
commit aee88ffda6
6 changed files with 134 additions and 18 deletions

View File

@@ -80,6 +80,7 @@ import {
isValidBrand,
getBrandProfile
} from './rule-transformer.js';
import { runInteractiveRulesSetup } from './rules-setup.js';
/**
* Runs the interactive setup process for model configuration.
@@ -511,6 +512,43 @@ function registerCommands(programInstance) {
.action(async (action, brands, options) => {
const projectDir = process.cwd();
/**
* 'task-master rules setup' action:
*
* Launches an interactive prompt to select which brand rules to apply to the current project.
* This does NOT perform project initialization or ask about shell aliases—only rules selection.
*
* Example usage:
* $ task-master rules setup
*
* Useful for updating/enforcing rules after project creation, or switching brands.
*
* The list of brands is always up-to-date with the available profiles.
*/
if (action === 'setup') {
// Run interactive rules setup ONLY (no project init)
const selectedBrandRules = await runInteractiveRulesSetup();
for (const brand of selectedBrandRules) {
if (!isValidBrand(brand)) {
console.warn(
`Rules profile for brand "${brand}" not found. Valid brands: ${BRAND_NAMES.join(', ')}. Skipping.`
);
continue;
}
const profile = getBrandProfile(brand);
const addResult = convertAllRulesToBrandRules(projectDir, profile);
if (typeof profile.onAddBrandRules === 'function') {
profile.onAddBrandRules(projectDir);
}
console.log(
chalk.green(
`Summary for ${brand}: ${addResult.success} rules added, ${addResult.failed} failed.`
)
);
}
return;
}
if (!brands || brands.length === 0) {
console.error(
'Please specify at least one brand (e.g., windsurf, roo).'

View File

@@ -0,0 +1,47 @@
import readline from 'readline';
import inquirer from 'inquirer';
import chalk from 'chalk';
import { BRAND_PROFILES, BRAND_NAMES } from './rule-transformer.js';
// Dynamically generate availableBrandRules from BRAND_NAMES and brand profiles
const availableBrandRules = BRAND_NAMES.map((name) => {
const displayName =
BRAND_PROFILES[name]?.brandName ||
name.charAt(0).toUpperCase() + name.slice(1);
return {
name: name === 'cursor' ? `${displayName} (default)` : displayName,
value: name
};
});
/**
* Runs the interactive rules setup flow (brand rules selection only)
* @returns {Promise<string[]>} The selected brand rules
*/
/**
* Launches an interactive prompt for selecting which brand rules to include in your project.
*
* This function dynamically lists all available brands (from BRAND_PROFILES) and presents them as checkboxes.
* The user must select at least one brand (default: cursor). The result is an array of selected brand names.
*
* Used by both project initialization (init) and the CLI 'task-master rules setup' command to ensure DRY, consistent UX.
*
* @returns {Promise<string[]>} Array of selected brand rule names (e.g., ['cursor', 'windsurf'])
*/
export async function runInteractiveRulesSetup() {
console.log(
chalk.cyan(
'\nRules help enforce best practices and conventions for Task Master.'
)
);
const brandRulesQuestion = {
type: 'checkbox',
name: 'brandRules',
message: 'Which IDEs would you like rules included for?',
choices: availableBrandRules,
default: ['cursor'],
validate: (input) => input.length > 0 || 'You must select at least one.'
};
const { brandRules } = await inquirer.prompt([brandRulesQuestion]);
return brandRules;
}