fix logging and MCP response messages
This commit is contained in:
@@ -73,7 +73,13 @@ import {
|
||||
getApiKeyStatusReport
|
||||
} from './task-manager/models.js';
|
||||
import { findProjectRoot } from './utils.js';
|
||||
import { convertAllRulesToBrandRules, removeBrandRules, BRAND_NAMES, isValidBrand, getBrandProfile } from './rule-transformer.js';
|
||||
import {
|
||||
convertAllRulesToBrandRules,
|
||||
removeBrandRules,
|
||||
BRAND_NAMES,
|
||||
isValidBrand,
|
||||
getBrandProfile
|
||||
} from './rule-transformer.js';
|
||||
|
||||
/**
|
||||
* Runs the interactive setup process for model configuration.
|
||||
@@ -517,22 +523,30 @@ function registerCommands(programInstance) {
|
||||
|
||||
for (const brand of expandedBrands) {
|
||||
if (!isValidBrand(brand)) {
|
||||
console.warn(`Rules profile for brand "${brand}" not found. Valid brands: ${BRAND_NAMES.join(', ')}. Skipping.`);
|
||||
console.warn(
|
||||
`Rules profile for brand "${brand}" not found. Valid brands: ${BRAND_NAMES.join(', ')}. Skipping.`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const profile = getBrandProfile(brand);
|
||||
|
||||
if (action === 'add') {
|
||||
convertAllRulesToBrandRules(projectDir, profile);
|
||||
console.log(chalk.blue(`Adding rules for brand: ${brand}...`));
|
||||
const addResult = convertAllRulesToBrandRules(projectDir, profile);
|
||||
if (typeof profile.onAddBrandRules === 'function') {
|
||||
profile.onAddBrandRules(projectDir);
|
||||
}
|
||||
console.log(chalk.blue(`Completed adding rules for brand: ${brand}`));
|
||||
console.log(
|
||||
chalk.green(
|
||||
`Summary for ${brand}: ${addResult.success} rules added, ${addResult.failed} failed.`
|
||||
)
|
||||
);
|
||||
} else if (action === 'remove') {
|
||||
console.log(chalk.blue(`Removing rules for brand: ${brand}...`));
|
||||
const result = removeBrandRules(projectDir, profile);
|
||||
removalResults.push(result);
|
||||
if (typeof profile.onRemoveBrandRules === 'function') {
|
||||
profile.onRemoveBrandRules(projectDir);
|
||||
}
|
||||
console.log(chalk.blue(`Completed removal for brand: ${brand}`));
|
||||
} else {
|
||||
console.error('Unknown action. Use "add" or "remove".');
|
||||
process.exit(1);
|
||||
@@ -541,18 +555,30 @@ function registerCommands(programInstance) {
|
||||
|
||||
// Print summary for removals
|
||||
if (action === 'remove') {
|
||||
const successes = removalResults.filter(r => r.success).map(r => r.brandName);
|
||||
const skipped = removalResults.filter(r => r.skipped).map(r => r.brandName);
|
||||
const errors = removalResults.filter(r => r.error && !r.success && !r.skipped);
|
||||
const successes = removalResults
|
||||
.filter((r) => r.success)
|
||||
.map((r) => r.brandName);
|
||||
const skipped = removalResults
|
||||
.filter((r) => r.skipped)
|
||||
.map((r) => r.brandName);
|
||||
const errors = removalResults.filter(
|
||||
(r) => r.error && !r.success && !r.skipped
|
||||
);
|
||||
|
||||
if (successes.length > 0) {
|
||||
console.log(chalk.green(`Successfully removed rules: ${successes.join(', ')}`));
|
||||
console.log(
|
||||
chalk.green(`Successfully removed rules: ${successes.join(', ')}`)
|
||||
);
|
||||
}
|
||||
if (skipped.length > 0) {
|
||||
console.log(chalk.yellow(`Skipped (default or protected): ${skipped.join(', ')}`));
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
`Skipped (default or protected): ${skipped.join(', ')}`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
errors.forEach(r => {
|
||||
errors.forEach((r) => {
|
||||
console.log(chalk.red(`Error removing ${r.brandName}: ${r.error}`));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -96,5 +96,4 @@ export function setupMCPConfiguration(configDir) {
|
||||
fs.writeFileSync(mcpPath, JSON.stringify(newMCPConfig, null, 4));
|
||||
log('success', 'Created MCP configuration file');
|
||||
}
|
||||
log('info', 'MCP server will use the installed task-master-ai package');
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ function convertRuleToBrandRule(sourcePath, targetPath, profile) {
|
||||
const { conversionConfig, brandName, globalReplacements } = profile;
|
||||
try {
|
||||
log(
|
||||
'info',
|
||||
'debug',
|
||||
`Converting Cursor rule ${path.basename(sourcePath)} to ${brandName} rule ${path.basename(targetPath)}`
|
||||
);
|
||||
|
||||
@@ -173,7 +173,7 @@ function convertRuleToBrandRule(sourcePath, targetPath, profile) {
|
||||
// Write transformed content
|
||||
fs.writeFileSync(targetPath, transformedContent);
|
||||
log(
|
||||
'success',
|
||||
'debug',
|
||||
`Successfully converted ${path.basename(sourcePath)} to ${path.basename(targetPath)}`
|
||||
);
|
||||
|
||||
@@ -204,7 +204,7 @@ function convertAllRulesToBrandRules(projectDir, profile) {
|
||||
// Ensure brand rules directory exists
|
||||
if (!fs.existsSync(brandRulesDir)) {
|
||||
fs.mkdirSync(brandRulesDir, { recursive: true });
|
||||
log('info', `Created ${brandName} rules directory: ${brandRulesDir}`);
|
||||
log('debug', `Created ${brandName} rules directory: ${brandRulesDir}`);
|
||||
// Also create MCP configuration in the brand directory
|
||||
const brandDir = path.dirname(brandRulesDir);
|
||||
setupMCPConfiguration(brandDir);
|
||||
@@ -233,7 +233,7 @@ function convertAllRulesToBrandRules(projectDir, profile) {
|
||||
});
|
||||
|
||||
log(
|
||||
'info',
|
||||
'debug',
|
||||
`Rule conversion complete: ${success} successful, ${failed} failed`
|
||||
);
|
||||
|
||||
@@ -274,43 +274,57 @@ function removeBrandRules(projectDir, profile) {
|
||||
} catch (e) {
|
||||
const errorMessage = `Failed to remove MCP configuration at ${mcpPath}: ${e.message}`;
|
||||
log('warn', errorMessage);
|
||||
result.error = result.error ? `${result.error}; ${errorMessage}` : errorMessage;
|
||||
result.error = result.error
|
||||
? `${result.error}; ${errorMessage}`
|
||||
: errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
if (brandName.toLowerCase() === 'cursor') {
|
||||
const skipMessage = 'Cannot remove default Cursor rules directory. Skipping.';
|
||||
log('warn', skipMessage);
|
||||
result.skipped = true;
|
||||
result.error = skipMessage;
|
||||
return result; // Early exit for cursor brand
|
||||
}
|
||||
|
||||
// Remove rules directory
|
||||
if (fs.existsSync(brandRulesDir)) {
|
||||
try {
|
||||
fs.rmSync(brandRulesDir, { recursive: true, force: true });
|
||||
result.rulesDirRemoved = true;
|
||||
|
||||
if (
|
||||
fs.existsSync(brandDir) &&
|
||||
path.basename(brandDir) !== '.cursor' &&
|
||||
fs.readdirSync(brandDir).length === 0
|
||||
) {
|
||||
fs.rmdirSync(brandDir);
|
||||
result.brandFolderRemoved = true;
|
||||
}
|
||||
result.success = true; // Mark overall success if rules dir was removed
|
||||
} catch (e) {
|
||||
const errorMessage = `Failed to remove rules directory ${brandRulesDir} or brand folder ${brandDir}: ${e.message}`;
|
||||
log('error', errorMessage); // Log as error since this is a primary operation failing
|
||||
result.error = result.error ? `${result.error}; ${errorMessage}` : errorMessage;
|
||||
const errorMessage = `Failed to remove rules directory at ${brandRulesDir}: ${e.message}`;
|
||||
log('warn', errorMessage);
|
||||
result.error = result.error
|
||||
? `${result.error}; ${errorMessage}`
|
||||
: errorMessage;
|
||||
}
|
||||
} else {
|
||||
const warnMessage = `Rules directory not found: ${brandRulesDir}`;
|
||||
log('warn', warnMessage);
|
||||
result.error = result.error ? `${result.error}; ${warnMessage}` : warnMessage;
|
||||
// success remains false as the primary target (rulesDir) was not found
|
||||
}
|
||||
|
||||
// Remove brand folder if empty
|
||||
if (fs.existsSync(brandDir) && fs.readdirSync(brandDir).length === 0) {
|
||||
try {
|
||||
fs.rmdirSync(brandDir);
|
||||
result.brandFolderRemoved = true;
|
||||
} catch (e) {
|
||||
const errorMessage = `Failed to remove empty brand folder at ${brandDir}: ${e.message}`;
|
||||
log('warn', errorMessage);
|
||||
result.error = result.error
|
||||
? `${result.error}; ${errorMessage}`
|
||||
: errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
// Call onRemoveBrandRules hook if present
|
||||
if (typeof profile.onRemoveBrandRules === 'function') {
|
||||
try {
|
||||
profile.onRemoveBrandRules(projectDir);
|
||||
} catch (e) {
|
||||
const errorMessage = `Error in onRemoveBrandRules for ${brandName}: ${e.message}`;
|
||||
log('warn', errorMessage);
|
||||
result.error = result.error
|
||||
? `${result.error}; ${errorMessage}`
|
||||
: errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
result.success =
|
||||
result.mcpConfigRemoved ||
|
||||
result.rulesDirRemoved ||
|
||||
result.brandFolderRemoved;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user