fix logging and MCP response messages
This commit is contained in:
@@ -7,7 +7,15 @@ import {
|
|||||||
enableSilentMode,
|
enableSilentMode,
|
||||||
disableSilentMode
|
disableSilentMode
|
||||||
} from '../../../../scripts/modules/utils.js';
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import { removeBrandRules, convertAllRulesToBrandRules, BRAND_NAMES, isValidBrand, getBrandProfile } from '../../../../scripts/modules/rule-transformer.js';
|
import {
|
||||||
|
removeBrandRules,
|
||||||
|
convertAllRulesToBrandRules,
|
||||||
|
BRAND_NAMES,
|
||||||
|
isValidBrand,
|
||||||
|
getBrandProfile
|
||||||
|
} from '../../../../scripts/modules/rule-transformer.js';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for adding or removing brand rules.
|
* Direct function wrapper for adding or removing brand rules.
|
||||||
@@ -45,16 +53,26 @@ export async function rulesDirect(args, log, context = {}) {
|
|||||||
if (action === 'remove') {
|
if (action === 'remove') {
|
||||||
for (const brand of rules) {
|
for (const brand of rules) {
|
||||||
if (!isValidBrand(brand)) {
|
if (!isValidBrand(brand)) {
|
||||||
removalResults.push({ brandName: brand, success: false, error: `Profile not found: static import missing for '${brand}'. Valid brands: ${BRAND_NAMES.join(', ')}` });
|
removalResults.push({
|
||||||
|
brandName: brand,
|
||||||
|
success: false,
|
||||||
|
error: `Profile not found: static import missing for '${brand}'. Valid brands: ${BRAND_NAMES.join(', ')}`
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const profile = getBrandProfile(brand);
|
const profile = getBrandProfile(brand);
|
||||||
const result = removeBrandRules(projectRoot, profile);
|
const result = removeBrandRules(projectRoot, profile);
|
||||||
removalResults.push(result);
|
removalResults.push(result);
|
||||||
}
|
}
|
||||||
const successes = removalResults.filter(r => r.success).map(r => r.brandName);
|
const successes = removalResults
|
||||||
const skipped = removalResults.filter(r => r.skipped).map(r => r.brandName);
|
.filter((r) => r.success)
|
||||||
const errors = removalResults.filter(r => r.error && !r.success && !r.skipped);
|
.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
|
||||||
|
);
|
||||||
|
|
||||||
let summary = '';
|
let summary = '';
|
||||||
if (successes.length > 0) {
|
if (successes.length > 0) {
|
||||||
@@ -64,22 +82,75 @@ export async function rulesDirect(args, log, context = {}) {
|
|||||||
summary += `Skipped (default or protected): ${skipped.join(', ')}.`;
|
summary += `Skipped (default or protected): ${skipped.join(', ')}.`;
|
||||||
}
|
}
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
summary += errors.map(r => `Error removing ${r.brandName}: ${r.error}`).join(' ');
|
summary += errors
|
||||||
|
.map((r) => `Error removing ${r.brandName}: ${r.error}`)
|
||||||
|
.join(' ');
|
||||||
}
|
}
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
return { success: errors.length === 0, data: { summary, results: removalResults } };
|
return {
|
||||||
|
success: errors.length === 0,
|
||||||
|
data: { summary, results: removalResults }
|
||||||
|
};
|
||||||
} else if (action === 'add') {
|
} else if (action === 'add') {
|
||||||
for (const brand of rules) {
|
for (const brand of rules) {
|
||||||
if (!isValidBrand(brand)) {
|
if (!isValidBrand(brand)) {
|
||||||
addResults.push({ brandName: brand, success: false, error: `Profile not found: static import missing for '${brand}'. Valid brands: ${BRAND_NAMES.join(', ')}` });
|
addResults.push({
|
||||||
|
brandName: brand,
|
||||||
|
success: false,
|
||||||
|
error: `Profile not found: static import missing for '${brand}'. Valid brands: ${BRAND_NAMES.join(', ')}`
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const profile = getBrandProfile(brand);
|
const profile = getBrandProfile(brand);
|
||||||
const result = convertAllRulesToBrandRules(projectRoot, profile);
|
const { success, failed } = convertAllRulesToBrandRules(
|
||||||
addResults.push({ brandName: brand, ...result });
|
projectRoot,
|
||||||
|
profile
|
||||||
|
);
|
||||||
|
|
||||||
|
// Determine paths
|
||||||
|
const rulesDir = profile.rulesDir;
|
||||||
|
const brandRulesDir = path.join(projectRoot, rulesDir);
|
||||||
|
const brandDir = path.dirname(brandRulesDir);
|
||||||
|
const mcpPath = path.join(brandDir, 'mcp.json');
|
||||||
|
|
||||||
|
// Check what was created
|
||||||
|
const mcpConfigCreated = fs.existsSync(mcpPath);
|
||||||
|
const rulesDirCreated = fs.existsSync(brandRulesDir);
|
||||||
|
const brandFolderCreated = fs.existsSync(brandDir);
|
||||||
|
|
||||||
|
const error =
|
||||||
|
failed > 0 ? `${failed} rule files failed to convert.` : null;
|
||||||
|
const resultObj = {
|
||||||
|
brandName: brand,
|
||||||
|
mcpConfigCreated,
|
||||||
|
rulesDirCreated,
|
||||||
|
brandFolderCreated,
|
||||||
|
skipped: false,
|
||||||
|
error,
|
||||||
|
success: mcpConfigCreated && rulesDirCreated && success > 0 && !error
|
||||||
|
};
|
||||||
|
addResults.push(resultObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
const successes = addResults
|
||||||
|
.filter((r) => r.success)
|
||||||
|
.map((r) => r.brandName);
|
||||||
|
const errors = addResults.filter((r) => r.error && !r.success);
|
||||||
|
|
||||||
|
let summary = '';
|
||||||
|
if (successes.length > 0) {
|
||||||
|
summary += `Successfully added rules: ${successes.join(', ')}.`;
|
||||||
|
}
|
||||||
|
if (errors.length > 0) {
|
||||||
|
summary += errors
|
||||||
|
.map((r) => ` Error adding ${r.brandName}: ${r.error}`)
|
||||||
|
.join(' ');
|
||||||
}
|
}
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
return { success: true, data: { results: addResults } };
|
return {
|
||||||
|
success: errors.length === 0,
|
||||||
|
data: { summary, results: addResults }
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -73,7 +73,13 @@ import {
|
|||||||
getApiKeyStatusReport
|
getApiKeyStatusReport
|
||||||
} from './task-manager/models.js';
|
} from './task-manager/models.js';
|
||||||
import { findProjectRoot } from './utils.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.
|
* Runs the interactive setup process for model configuration.
|
||||||
@@ -517,22 +523,30 @@ function registerCommands(programInstance) {
|
|||||||
|
|
||||||
for (const brand of expandedBrands) {
|
for (const brand of expandedBrands) {
|
||||||
if (!isValidBrand(brand)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
const profile = getBrandProfile(brand);
|
const profile = getBrandProfile(brand);
|
||||||
|
|
||||||
if (action === 'add') {
|
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') {
|
if (typeof profile.onAddBrandRules === 'function') {
|
||||||
profile.onAddBrandRules(projectDir);
|
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') {
|
} else if (action === 'remove') {
|
||||||
|
console.log(chalk.blue(`Removing rules for brand: ${brand}...`));
|
||||||
const result = removeBrandRules(projectDir, profile);
|
const result = removeBrandRules(projectDir, profile);
|
||||||
removalResults.push(result);
|
removalResults.push(result);
|
||||||
if (typeof profile.onRemoveBrandRules === 'function') {
|
console.log(chalk.blue(`Completed removal for brand: ${brand}`));
|
||||||
profile.onRemoveBrandRules(projectDir);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.error('Unknown action. Use "add" or "remove".');
|
console.error('Unknown action. Use "add" or "remove".');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -541,18 +555,30 @@ function registerCommands(programInstance) {
|
|||||||
|
|
||||||
// Print summary for removals
|
// Print summary for removals
|
||||||
if (action === 'remove') {
|
if (action === 'remove') {
|
||||||
const successes = removalResults.filter(r => r.success).map(r => r.brandName);
|
const successes = removalResults
|
||||||
const skipped = removalResults.filter(r => r.skipped).map(r => r.brandName);
|
.filter((r) => r.success)
|
||||||
const errors = removalResults.filter(r => r.error && !r.success && !r.skipped);
|
.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) {
|
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) {
|
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) {
|
if (errors.length > 0) {
|
||||||
errors.forEach(r => {
|
errors.forEach((r) => {
|
||||||
console.log(chalk.red(`Error removing ${r.brandName}: ${r.error}`));
|
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));
|
fs.writeFileSync(mcpPath, JSON.stringify(newMCPConfig, null, 4));
|
||||||
log('success', 'Created MCP configuration file');
|
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;
|
const { conversionConfig, brandName, globalReplacements } = profile;
|
||||||
try {
|
try {
|
||||||
log(
|
log(
|
||||||
'info',
|
'debug',
|
||||||
`Converting Cursor rule ${path.basename(sourcePath)} to ${brandName} rule ${path.basename(targetPath)}`
|
`Converting Cursor rule ${path.basename(sourcePath)} to ${brandName} rule ${path.basename(targetPath)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ function convertRuleToBrandRule(sourcePath, targetPath, profile) {
|
|||||||
// Write transformed content
|
// Write transformed content
|
||||||
fs.writeFileSync(targetPath, transformedContent);
|
fs.writeFileSync(targetPath, transformedContent);
|
||||||
log(
|
log(
|
||||||
'success',
|
'debug',
|
||||||
`Successfully converted ${path.basename(sourcePath)} to ${path.basename(targetPath)}`
|
`Successfully converted ${path.basename(sourcePath)} to ${path.basename(targetPath)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ function convertAllRulesToBrandRules(projectDir, profile) {
|
|||||||
// Ensure brand rules directory exists
|
// Ensure brand rules directory exists
|
||||||
if (!fs.existsSync(brandRulesDir)) {
|
if (!fs.existsSync(brandRulesDir)) {
|
||||||
fs.mkdirSync(brandRulesDir, { recursive: true });
|
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
|
// Also create MCP configuration in the brand directory
|
||||||
const brandDir = path.dirname(brandRulesDir);
|
const brandDir = path.dirname(brandRulesDir);
|
||||||
setupMCPConfiguration(brandDir);
|
setupMCPConfiguration(brandDir);
|
||||||
@@ -233,7 +233,7 @@ function convertAllRulesToBrandRules(projectDir, profile) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'info',
|
'debug',
|
||||||
`Rule conversion complete: ${success} successful, ${failed} failed`
|
`Rule conversion complete: ${success} successful, ${failed} failed`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -274,43 +274,57 @@ function removeBrandRules(projectDir, profile) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMessage = `Failed to remove MCP configuration at ${mcpPath}: ${e.message}`;
|
const errorMessage = `Failed to remove MCP configuration at ${mcpPath}: ${e.message}`;
|
||||||
log('warn', errorMessage);
|
log('warn', errorMessage);
|
||||||
result.error = result.error ? `${result.error}; ${errorMessage}` : errorMessage;
|
result.error = result.error
|
||||||
|
? `${result.error}; ${errorMessage}`
|
||||||
|
: errorMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brandName.toLowerCase() === 'cursor') {
|
// Remove rules directory
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(brandRulesDir)) {
|
if (fs.existsSync(brandRulesDir)) {
|
||||||
try {
|
try {
|
||||||
fs.rmSync(brandRulesDir, { recursive: true, force: true });
|
fs.rmSync(brandRulesDir, { recursive: true, force: true });
|
||||||
result.rulesDirRemoved = true;
|
result.rulesDirRemoved = true;
|
||||||
|
} catch (e) {
|
||||||
|
const errorMessage = `Failed to remove rules directory at ${brandRulesDir}: ${e.message}`;
|
||||||
|
log('warn', errorMessage);
|
||||||
|
result.error = result.error
|
||||||
|
? `${result.error}; ${errorMessage}`
|
||||||
|
: errorMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
// Remove brand folder if empty
|
||||||
fs.existsSync(brandDir) &&
|
if (fs.existsSync(brandDir) && fs.readdirSync(brandDir).length === 0) {
|
||||||
path.basename(brandDir) !== '.cursor' &&
|
try {
|
||||||
fs.readdirSync(brandDir).length === 0
|
|
||||||
) {
|
|
||||||
fs.rmdirSync(brandDir);
|
fs.rmdirSync(brandDir);
|
||||||
result.brandFolderRemoved = true;
|
result.brandFolderRemoved = true;
|
||||||
}
|
|
||||||
result.success = true; // Mark overall success if rules dir was removed
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMessage = `Failed to remove rules directory ${brandRulesDir} or brand folder ${brandDir}: ${e.message}`;
|
const errorMessage = `Failed to remove empty brand folder at ${brandDir}: ${e.message}`;
|
||||||
log('error', errorMessage); // Log as error since this is a primary operation failing
|
log('warn', errorMessage);
|
||||||
result.error = result.error ? `${result.error}; ${errorMessage}` : 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { isSilentMode } from '../modules/utils.js';
|
import { isSilentMode, log } from '../modules/utils.js';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
@@ -127,7 +127,6 @@ export function onAddBrandRules(targetDir) {
|
|||||||
const sourceDir = path.resolve(__dirname, '../../assets/roocode');
|
const sourceDir = path.resolve(__dirname, '../../assets/roocode');
|
||||||
copyRecursiveSync(sourceDir, targetDir);
|
copyRecursiveSync(sourceDir, targetDir);
|
||||||
|
|
||||||
// Enhanced error checking and logging for .roomodes and rules-*mode* files
|
|
||||||
const rooModesDir = path.join(sourceDir, '.roo');
|
const rooModesDir = path.join(sourceDir, '.roo');
|
||||||
const rooModes = ['architect', 'ask', 'boomerang', 'code', 'debug', 'test'];
|
const rooModes = ['architect', 'ask', 'boomerang', 'code', 'debug', 'test'];
|
||||||
|
|
||||||
@@ -137,30 +136,28 @@ export function onAddBrandRules(targetDir) {
|
|||||||
if (fs.existsSync(roomodesSrc)) {
|
if (fs.existsSync(roomodesSrc)) {
|
||||||
try {
|
try {
|
||||||
fs.copyFileSync(roomodesSrc, roomodesDest);
|
fs.copyFileSync(roomodesSrc, roomodesDest);
|
||||||
if (!isSilentMode()) console.log(`[Roo] Copied .roomodes to ${roomodesDest}`);
|
log('debug', `[Roo] Copied .roomodes to ${roomodesDest}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!isSilentMode()) console.warn(`[Roo] Failed to copy .roomodes: ${err.message}`);
|
log('debug', `[Roo] Failed to copy .roomodes: ${err.message}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isSilentMode()) console.warn(`[Roo] .roomodes not found at ${roomodesSrc}`);
|
log('debug', `[Roo] .roomodes not found at ${roomodesSrc}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy each <mode>-rules file into the corresponding .roo/rules-<mode>/ folder
|
|
||||||
for (const mode of rooModes) {
|
for (const mode of rooModes) {
|
||||||
const src = path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`);
|
const src = path.join(rooModesDir, `rules-${mode}`, `${mode}-rules`);
|
||||||
const dest = path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`);
|
const dest = path.join(targetDir, '.roo', `rules-${mode}`, `${mode}-rules`);
|
||||||
if (fs.existsSync(src)) {
|
if (fs.existsSync(src)) {
|
||||||
try {
|
try {
|
||||||
// Ensure destination directory exists
|
|
||||||
const destDir = path.dirname(dest);
|
const destDir = path.dirname(dest);
|
||||||
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
||||||
fs.copyFileSync(src, dest);
|
fs.copyFileSync(src, dest);
|
||||||
if (!isSilentMode()) console.log(`[Roo] Copied ${src} to ${dest}`);
|
log('debug', `[Roo] Copied ${src} to ${dest}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!isSilentMode()) console.warn(`[Roo] Failed to copy ${src} to ${dest}: ${err.message}`);
|
log('debug', `[Roo] Failed to copy ${src} to ${dest}: ${err.message}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isSilentMode()) console.warn(`[Roo] Roo rule file not found for mode '${mode}': ${src}`);
|
log('debug', `[Roo] Roo rule file not found for mode '${mode}': ${src}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,36 +180,41 @@ function copyRecursiveSync(src, dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function onRemoveBrandRules(targetDir) {
|
export function onRemoveBrandRules(targetDir) {
|
||||||
const sourceDir = path.resolve(__dirname, '../../assets/roocode');
|
log('debug', `[Roo] onRemoveBrandRules called for ${targetDir}`);
|
||||||
// Remove all files/folders that exist in assets/roocode from the project root
|
const roomodesPath = path.join(targetDir, '.roomodes');
|
||||||
removeRecursiveSync(sourceDir, targetDir);
|
if (fs.existsSync(roomodesPath)) {
|
||||||
|
try {
|
||||||
|
fs.rmSync(roomodesPath, { force: true });
|
||||||
|
log('debug', `[Roo] Removed .roomodes from ${targetDir}`);
|
||||||
|
} catch (err) {
|
||||||
|
log('debug', `[Roo] Failed to remove .roomodes: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// After removing, check if .roo exists and is empty; if so, remove it
|
|
||||||
const rooDir = path.join(targetDir, '.roo');
|
const rooDir = path.join(targetDir, '.roo');
|
||||||
if (fs.existsSync(rooDir) && isDirectoryEmpty(rooDir)) {
|
if (fs.existsSync(rooDir)) {
|
||||||
fs.rmSync(rooDir, { recursive: true, force: true });
|
fs.readdirSync(rooDir).forEach((entry) => {
|
||||||
|
if (entry.startsWith('rules-')) {
|
||||||
|
const modeDir = path.join(rooDir, entry);
|
||||||
|
try {
|
||||||
|
fs.rmSync(modeDir, { recursive: true, force: true });
|
||||||
|
log('debug', `[Roo] Removed ${modeDir}`);
|
||||||
|
} catch (err) {
|
||||||
|
log('debug', `[Roo] Failed to remove ${modeDir}: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeRecursiveSync(src, destRoot) {
|
|
||||||
if (!fs.existsSync(src)) return;
|
|
||||||
const stats = fs.statSync(src);
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
const destDir = path.join(destRoot, path.basename(src));
|
|
||||||
if (fs.existsSync(destDir)) {
|
|
||||||
fs.rmSync(destDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
// Also walk subfolders in src to remove nested structure
|
|
||||||
fs.readdirSync(src).forEach((child) => {
|
|
||||||
removeRecursiveSync(path.join(src, child), destRoot);
|
|
||||||
});
|
});
|
||||||
} else {
|
if (fs.readdirSync(rooDir).length === 0) {
|
||||||
const destFile = path.join(destRoot, path.basename(src));
|
try {
|
||||||
if (fs.existsSync(destFile)) {
|
fs.rmSync(rooDir, { recursive: true, force: true });
|
||||||
fs.rmSync(destFile, { force: true });
|
log('debug', `[Roo] Removed empty .roo directory`);
|
||||||
|
} catch (err) {
|
||||||
|
log('debug', `[Roo] Failed to remove .roo directory: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log('debug', `[Roo] onRemoveBrandRules completed for ${targetDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
function isDirectoryEmpty(dirPath) {
|
function isDirectoryEmpty(dirPath) {
|
||||||
return fs.readdirSync(dirPath).length === 0;
|
return fs.readdirSync(dirPath).length === 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user