install-slash-commands.js•6.2 kB
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import os from 'os';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/**
* Install claude-agents-power slash commands to Claude Code
* This enables /agents:* commands in Claude Code interface
*/
class SlashCommandInstaller {
constructor() {
this.claudeDir = path.join(os.homedir(), '.claude');
this.commandsDir = path.join(this.claudeDir, 'commands');
this.sourceDir = path.join(__dirname, 'claude-slash-commands');
}
async install() {
console.log('🚀 Claude Agents Power - Slash Commands Installer\n');
try {
// Create directories if they don't exist
await this.ensureDirectories();
// Copy command files
await this.copyCommandFiles();
// Create main index file
await this.createIndexFile();
console.log('\n✅ Slash commands installed successfully!');
console.log('\nAvailable commands in Claude Code:');
console.log(' /agents:load - Load and display available agents');
console.log(' /agents:search - Search agents by skills or keywords');
console.log(' /agents:suggest - Get intelligent agent recommendations');
console.log(' /agents:version - Check system version and status');
console.log('\nUsage: Type any of these commands in Claude Code chat');
console.log('\n💡 Tip: Try "/agents:load" to see all available agents');
} catch (error) {
console.error('❌ Installation failed:', error.message);
process.exit(1);
}
}
async ensureDirectories() {
console.log('📁 Creating directories...');
if (!fs.existsSync(this.claudeDir)) {
fs.mkdirSync(this.claudeDir, { recursive: true });
console.log(` Created: ${this.claudeDir}`);
}
if (!fs.existsSync(this.commandsDir)) {
fs.mkdirSync(this.commandsDir, { recursive: true });
console.log(` Created: ${this.commandsDir}`);
}
}
async copyCommandFiles() {
console.log('📋 Installing slash commands...');
const commandFiles = fs.readdirSync(this.sourceDir);
for (const file of commandFiles) {
if (file.endsWith('.md')) {
const sourcePath = path.join(this.sourceDir, file);
const targetPath = path.join(this.commandsDir, file);
fs.copyFileSync(sourcePath, targetPath);
console.log(` Installed: ${file}`);
}
}
}
async createIndexFile() {
console.log('📝 Creating command index...');
const indexContent = `# Claude Agents Power - Slash Commands
This directory contains slash command definitions for claude-agents-power.
## Available Commands
### /agents:load
Load and display available Claude agents for your development team.
- Filter by language (en, ko, ja, zh)
- Filter by specific roles
- Show detailed descriptions
### /agents:search
Search for specific agents by skills, domain, or keywords.
- Intelligent fuzzy matching
- Multi-language support
- Relevance scoring
### /agents:suggest
Get intelligent agent recommendations based on your project context.
- Context-aware suggestions
- Phase-specific recommendations
- Team optimization
### /agents:version
Check claude-agents-power MCP server version and system status.
- System health checks
- Update notifications
- Troubleshooting info
## Installation
These commands are automatically installed when you run:
\`\`\`bash
npx claude-agents-power --install-slash-commands
\`\`\`
## Requirements
- claude-agents-power MCP server installed and configured
- Claude Desktop with MCP support
- Node.js 16+ for the MCP server
## Support
For issues or questions:
- GitHub: https://github.com/hongsw/claude-agents-power-mcp-server
- Create an issue if you encounter problems
## Version
Generated by claude-agents-power v${this.getVersion()}
Installed on: ${new Date().toISOString()}
---
💡 **Pro Tip**: Start with \`/agents:load\` to see all available agents, then use \`/agents:suggest\` to get recommendations for your project!
`;
const indexPath = path.join(this.commandsDir, 'README.md');
fs.writeFileSync(indexPath, indexContent);
console.log(' Created: README.md');
}
getVersion() {
try {
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
return packageJson.version;
} catch (error) {
return 'unknown';
}
}
async uninstall() {
console.log('🗑️ Uninstalling claude-agents-power slash commands...\n');
try {
if (fs.existsSync(this.commandsDir)) {
// Remove command files
const files = fs.readdirSync(this.commandsDir);
const agentCommandFiles = files.filter(file => file.startsWith('agents-') && file.endsWith('.md'));
for (const file of agentCommandFiles) {
const filePath = path.join(this.commandsDir, file);
fs.unlinkSync(filePath);
console.log(` Removed: ${file}`);
}
// Remove README if it exists
const readmePath = path.join(this.commandsDir, 'README.md');
if (fs.existsSync(readmePath)) {
fs.unlinkSync(readmePath);
console.log(' Removed: README.md');
}
console.log('\n✅ Slash commands uninstalled successfully!');
} else {
console.log('No slash commands found to uninstall.');
}
} catch (error) {
console.error('❌ Uninstallation failed:', error.message);
process.exit(1);
}
}
}
// CLI interface
const action = process.argv[2];
const installer = new SlashCommandInstaller();
switch (action) {
case 'install':
installer.install();
break;
case 'uninstall':
installer.uninstall();
break;
default:
console.log('Usage: node install-slash-commands.js [install|uninstall]');
console.log('');
console.log('Commands:');
console.log(' install Install slash commands to ~/.claude/commands/');
console.log(' uninstall Remove slash commands from ~/.claude/commands/');
process.exit(1);
}