update semantics and terminology from 'brand rules' to 'rules profiles'
This commit is contained in:
@@ -5,7 +5,8 @@ import {
|
||||
// isSilentMode // Not used directly here
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import os from 'os'; // Import os module for home directory check
|
||||
import { BRAND_NAMES } from '../../../../src/utils/rule-transformer.js';
|
||||
import { RULES_PROFILES } from '../../../../src/constants/profiles.js';
|
||||
import { convertAllRulesToProfileRules } from '../../../../src/utils/rule-transformer.js';
|
||||
|
||||
/**
|
||||
* Direct function wrapper for initializing a project.
|
||||
@@ -75,8 +76,10 @@ export async function initializeProjectDirect(args, log, context = {}) {
|
||||
options.rules = args.rules;
|
||||
log.info(`Including rules: ${args.rules.join(', ')}`);
|
||||
} else {
|
||||
options.rules = BRAND_NAMES;
|
||||
log.info(`No rules specified, defaulting to: ${BRAND_NAMES.join(', ')}`);
|
||||
options.rules = RULES_PROFILES;
|
||||
log.info(
|
||||
`No rules profiles specified, defaulting to: ${RULES_PROFILES.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
log.info(`Initializing project with options: ${JSON.stringify(options)}`);
|
||||
|
||||
@@ -8,12 +8,12 @@ import {
|
||||
disableSilentMode
|
||||
} from '../../../../scripts/modules/utils.js';
|
||||
import {
|
||||
removeBrandRules,
|
||||
convertAllRulesToBrandRules,
|
||||
BRAND_NAMES,
|
||||
isValidBrand,
|
||||
getBrandProfile
|
||||
convertAllRulesToProfileRules,
|
||||
removeProfileRules,
|
||||
getRulesProfile,
|
||||
isValidProfile
|
||||
} from '../../../../src/utils/rule-transformer.js';
|
||||
import { RULES_PROFILES } from '../../../../src/constants/profiles.js';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
@@ -21,7 +21,7 @@ import fs from 'fs';
|
||||
* Direct function wrapper for adding or removing rules.
|
||||
* @param {Object} args - Command arguments
|
||||
* @param {"add"|"remove"} args.action - Action to perform: add or remove rules
|
||||
* @param {string[]} args.rules - List of rules to add or remove
|
||||
* @param {string[]} args.profiles - List of profiles to add or remove
|
||||
* @param {string} args.projectRoot - Absolute path to the project root
|
||||
* @param {boolean} [args.yes=true] - Run non-interactively
|
||||
* @param {Object} log - Logger object
|
||||
@@ -31,18 +31,18 @@ import fs from 'fs';
|
||||
export async function rulesDirect(args, log, context = {}) {
|
||||
enableSilentMode();
|
||||
try {
|
||||
const { action, rules, projectRoot, yes } = args;
|
||||
const { action, profiles, projectRoot, yes } = args;
|
||||
if (
|
||||
!action ||
|
||||
!Array.isArray(rules) ||
|
||||
rules.length === 0 ||
|
||||
!Array.isArray(profiles) ||
|
||||
profiles.length === 0 ||
|
||||
!projectRoot
|
||||
) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: 'MISSING_ARGUMENT',
|
||||
message: 'action, rules, and projectRoot are required.'
|
||||
message: 'action, profiles, and projectRoot are required.'
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -51,25 +51,25 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
const addResults = [];
|
||||
|
||||
if (action === 'remove') {
|
||||
for (const brand of rules) {
|
||||
if (!isValidBrand(brand)) {
|
||||
for (const profile of profiles) {
|
||||
if (!isValidProfile(profile)) {
|
||||
removalResults.push({
|
||||
brandName: brand,
|
||||
profileName: profile,
|
||||
success: false,
|
||||
error: `The requested rules for '${brand}' are unavailable. Supported rules are: ${BRAND_NAMES.join(', ')}.`
|
||||
error: `The requested rules profile for '${profile}' is unavailable. Supported profiles are: ${RULES_PROFILES.join(', ')}.`
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const profile = getBrandProfile(brand);
|
||||
const result = removeBrandRules(projectRoot, profile);
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
const result = removeProfileRules(projectRoot, profileConfig);
|
||||
removalResults.push(result);
|
||||
}
|
||||
const successes = removalResults
|
||||
.filter((r) => r.success)
|
||||
.map((r) => r.brandName);
|
||||
.map((r) => r.profileName);
|
||||
const skipped = removalResults
|
||||
.filter((r) => r.skipped)
|
||||
.map((r) => r.brandName);
|
||||
.map((r) => r.profileName);
|
||||
const errors = removalResults.filter(
|
||||
(r) => r.error && !r.success && !r.skipped
|
||||
);
|
||||
@@ -83,7 +83,7 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
summary += errors
|
||||
.map((r) => `Error removing ${r.brandName}: ${r.error}`)
|
||||
.map((r) => `Error removing ${r.profileName}: ${r.error}`)
|
||||
.join(' ');
|
||||
}
|
||||
disableSilentMode();
|
||||
@@ -92,43 +92,42 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
data: { summary, results: removalResults }
|
||||
};
|
||||
} else if (action === 'add') {
|
||||
for (const brand of rules) {
|
||||
if (!isValidBrand(brand)) {
|
||||
for (const profile of profiles) {
|
||||
if (!isValidProfile(profile)) {
|
||||
addResults.push({
|
||||
brandName: brand,
|
||||
profileName: profile,
|
||||
success: false,
|
||||
error: `Profile not found: static import missing for '${brand}'. Valid brands: ${BRAND_NAMES.join(', ')}`
|
||||
error: `Profile not found: static import missing for '${profile}'. Valid profiles: ${RULES_PROFILES.join(', ')}`
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const profile = getBrandProfile(brand);
|
||||
const { success, failed } = convertAllRulesToBrandRules(
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
const { success, failed } = convertAllRulesToProfileRules(
|
||||
projectRoot,
|
||||
profile
|
||||
profileConfig
|
||||
);
|
||||
|
||||
// Determine paths
|
||||
const rulesDir = profile.rulesDir;
|
||||
const brandRulesDir = path.join(projectRoot, rulesDir);
|
||||
const brandDir = profile.brandDir;
|
||||
const mcpConfig = profile.mcpConfig !== false;
|
||||
const mcpConfigName = profile.mcpConfigName || 'mcp.json';
|
||||
const mcpPath = path.join(projectRoot, brandDir, mcpConfigName);
|
||||
const rulesDir = profileConfig.rulesDir;
|
||||
const profileRulesDir = path.join(projectRoot, rulesDir);
|
||||
const profileDir = profileConfig.profileDir;
|
||||
const mcpConfig = profileConfig.mcpConfig !== false;
|
||||
const mcpPath = path.join(projectRoot, profileConfig.mcpConfigPath);
|
||||
|
||||
// Check what was created
|
||||
const mcpConfigCreated = mcpConfig ? fs.existsSync(mcpPath) : undefined;
|
||||
const rulesDirCreated = fs.existsSync(brandRulesDir);
|
||||
const brandFolderCreated = fs.existsSync(
|
||||
path.join(projectRoot, brandDir)
|
||||
const rulesDirCreated = fs.existsSync(profileRulesDir);
|
||||
const profileFolderCreated = fs.existsSync(
|
||||
path.join(projectRoot, profileDir)
|
||||
);
|
||||
|
||||
const error =
|
||||
failed > 0 ? `${failed} rule files failed to convert.` : null;
|
||||
const resultObj = {
|
||||
brandName: brand,
|
||||
profileName: profile,
|
||||
mcpConfigCreated,
|
||||
rulesDirCreated,
|
||||
brandFolderCreated,
|
||||
profileFolderCreated,
|
||||
skipped: false,
|
||||
error,
|
||||
success:
|
||||
@@ -142,7 +141,7 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
|
||||
const successes = addResults
|
||||
.filter((r) => r.success)
|
||||
.map((r) => r.brandName);
|
||||
.map((r) => r.profileName);
|
||||
const errors = addResults.filter((r) => r.error && !r.success);
|
||||
|
||||
let summary = '';
|
||||
@@ -151,7 +150,7 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
summary += errors
|
||||
.map((r) => ` Error adding ${r.brandName}: ${r.error}`)
|
||||
.map((r) => ` Error adding ${r.profileName}: ${r.error}`)
|
||||
.join(' ');
|
||||
}
|
||||
disableSilentMode();
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
withNormalizedProjectRoot
|
||||
} from './utils.js';
|
||||
import { initializeProjectDirect } from '../core/task-master-core.js';
|
||||
import { BRAND_RULE_OPTIONS } from '../../../src/constants/rules.js';
|
||||
import { RULES_PROFILES } from '../../../src/constants/profiles.js';
|
||||
|
||||
export function registerInitializeProjectTool(server) {
|
||||
server.addTool({
|
||||
@@ -38,10 +38,10 @@ export function registerInitializeProjectTool(server) {
|
||||
'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.'
|
||||
),
|
||||
rules: z
|
||||
.array(z.enum(BRAND_RULE_OPTIONS))
|
||||
.array(z.enum(RULES_PROFILES))
|
||||
.optional()
|
||||
.describe(
|
||||
`List of rules to include at initialization. If omitted, defaults to all available brand rules. Available options: ${BRAND_RULE_OPTIONS.join(', ')}`
|
||||
`List of rules profiles to include at initialization. If omitted, defaults to all available profiles. Available options: ${RULES_PROFILES.join(', ')}`
|
||||
)
|
||||
}),
|
||||
execute: withNormalizedProjectRoot(async (args, context) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
withNormalizedProjectRoot
|
||||
} from './utils.js';
|
||||
import { rulesDirect } from '../core/direct-functions/rules.js';
|
||||
import { BRAND_RULE_OPTIONS } from '../../../src/constants/rules.js';
|
||||
import { RULES_PROFILES } from '../../../src/constants/profiles.js';
|
||||
|
||||
/**
|
||||
* Register the rules tool with the MCP server
|
||||
@@ -20,16 +20,16 @@ export function registerRulesTool(server) {
|
||||
server.addTool({
|
||||
name: 'rules',
|
||||
description:
|
||||
'Add or remove rules and MCP config from the project (mirrors CLI rules add/remove).',
|
||||
'Add or remove rules profiles from the project.',
|
||||
parameters: z.object({
|
||||
action: z
|
||||
.enum(['add', 'remove'])
|
||||
.describe('Whether to add or remove rules.'),
|
||||
rules: z
|
||||
.array(z.enum(BRAND_RULE_OPTIONS))
|
||||
.describe('Whether to add or remove rules profiles.'),
|
||||
profiles: z
|
||||
.array(z.enum(RULES_PROFILES))
|
||||
.min(1)
|
||||
.describe(
|
||||
`List of rules to add or remove. Available options: ${BRAND_RULE_OPTIONS.join(', ')}`
|
||||
`List of rules profiles to add or remove (e.g., [\"cursor\", \"roo\"]). Available options: ${RULES_PROFILES.join(', ')}`
|
||||
),
|
||||
projectRoot: z
|
||||
.string()
|
||||
@@ -40,7 +40,7 @@ export function registerRulesTool(server) {
|
||||
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(
|
||||
`[rules tool] Executing action: ${args.action} for rules: ${args.rules.join(', ')} in ${args.projectRoot}`
|
||||
`[rules tool] Executing action: ${args.action} for profiles: ${args.profiles.join(', ')} in ${args.projectRoot}`
|
||||
);
|
||||
const result = await rulesDirect(args, log, { session });
|
||||
return handleApiResult(result, log);
|
||||
|
||||
Reference in New Issue
Block a user