()
| 10 | import { removeFromClaudeCode } from '../utils/mcp-remover.js' |
| 11 | |
| 12 | export function createRemoveCommand() { |
| 13 | const remove = new Command('remove') |
| 14 | .description('Remove subagents, commands, or MCP servers') |
| 15 | .option('-a, --agent <name>', 'remove a specific subagent') |
| 16 | .option('-c, --command <name>', 'remove a specific command') |
| 17 | .option('-m, --mcp <name>', 'remove a specific MCP server') |
| 18 | .option('-u, --user', 'force user-level removal (for subagents/commands)') |
| 19 | .option('-p, --project', 'force project-level removal (for subagents/commands)') |
| 20 | .option('-s, --scope <scope>', 'configuration scope for MCP servers: local, user, or project') |
| 21 | .option('-y, --yes', 'skip confirmation prompt') |
| 22 | .action(async (options) => { |
| 23 | try { |
| 24 | const configManager = ConfigManager.getInstance() |
| 25 | |
| 26 | // Handle explicit scope overrides |
| 27 | const forceUserLevel = options.user |
| 28 | const forceProjectLevel = options.project |
| 29 | |
| 30 | // Determine removal scope |
| 31 | let isProject: boolean |
| 32 | if (forceProjectLevel) { |
| 33 | // Check if project config exists when forcing project level |
| 34 | const projectConfig = configManager.getProjectConfig() |
| 35 | if (!projectConfig) { |
| 36 | logger.error('No project configuration found. Run "bwc init --project" first.') |
| 37 | process.exit(1) |
| 38 | } |
| 39 | isProject = true |
| 40 | logger.info('Removing from project configuration') |
| 41 | } else if (forceUserLevel) { |
| 42 | await configManager.loadUserConfig() |
| 43 | isProject = false |
| 44 | logger.info('Removing from user configuration') |
| 45 | } else { |
| 46 | // Default: use project if it exists |
| 47 | isProject = await configManager.isUsingProjectConfig() |
| 48 | if (isProject) { |
| 49 | logger.info('Removing from project configuration') |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if (options.agent) { |
| 54 | await removeSubagent(options.agent, configManager, options.yes, forceUserLevel, forceProjectLevel) |
| 55 | } else if (options.command) { |
| 56 | await removeCommand(options.command, configManager, options.yes, forceUserLevel, forceProjectLevel) |
| 57 | } else if (options.mcp) { |
| 58 | // Validate scope if provided |
| 59 | if (options.scope) { |
| 60 | const validScopes = ['local', 'user', 'project'] |
| 61 | if (!validScopes.includes(options.scope)) { |
| 62 | throw new Error(`Invalid scope: ${options.scope}. Must be one of: ${validScopes.join(', ')}`) |
| 63 | } |
| 64 | } |
| 65 | await removeMCPServer(options.mcp, configManager, options.yes, options.scope) |
| 66 | } else { |
| 67 | await interactiveRemove(configManager, forceUserLevel, forceProjectLevel) |
| 68 | } |
| 69 | } catch (error) { |
no test coverage detected