2025-09-28 23:17:07 -05:00
|
|
|
|
const path = require('node:path');
|
2025-11-23 08:50:36 -06:00
|
|
|
|
const fs = require('fs-extra');
|
2025-09-28 23:17:07 -05:00
|
|
|
|
const { BaseIdeSetup } = require('./_base-ide');
|
|
|
|
|
|
const chalk = require('chalk');
|
2025-11-09 20:24:56 -06:00
|
|
|
|
const { AgentCommandGenerator } = require('./shared/agent-command-generator');
|
2025-12-03 22:44:13 -06:00
|
|
|
|
const { WorkflowCommandGenerator } = require('./shared/workflow-command-generator');
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Crush IDE setup handler
|
|
|
|
|
|
* Creates commands in .crush/commands/ directory structure
|
|
|
|
|
|
*/
|
|
|
|
|
|
class CrushSetup extends BaseIdeSetup {
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
super('crush', 'Crush');
|
|
|
|
|
|
this.configDir = '.crush';
|
|
|
|
|
|
this.commandsDir = 'commands';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Setup Crush IDE configuration
|
|
|
|
|
|
* @param {string} projectDir - Project directory
|
|
|
|
|
|
* @param {string} bmadDir - BMAD installation directory
|
|
|
|
|
|
* @param {Object} options - Setup options
|
|
|
|
|
|
*/
|
|
|
|
|
|
async setup(projectDir, bmadDir, options = {}) {
|
|
|
|
|
|
console.log(chalk.cyan(`Setting up ${this.name}...`));
|
|
|
|
|
|
|
|
|
|
|
|
// Create .crush/commands/bmad directory structure
|
|
|
|
|
|
const crushDir = path.join(projectDir, this.configDir);
|
|
|
|
|
|
const commandsDir = path.join(crushDir, this.commandsDir, 'bmad');
|
|
|
|
|
|
|
2025-10-26 19:38:38 -05:00
|
|
|
|
await this.ensureDir(commandsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
// Generate agent launchers
|
|
|
|
|
|
const agentGen = new AgentCommandGenerator(this.bmadFolderName);
|
|
|
|
|
|
const { artifacts: agentArtifacts } = await agentGen.collectAgentArtifacts(bmadDir, options.selectedModules || []);
|
|
|
|
|
|
|
2025-12-03 22:44:13 -06:00
|
|
|
|
// Get tasks, tools, and workflows (ALL workflows now generate commands)
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const tasks = await this.getTasks(bmadDir, true);
|
|
|
|
|
|
const tools = await this.getTools(bmadDir, true);
|
2025-12-03 22:44:13 -06:00
|
|
|
|
|
|
|
|
|
|
// Get ALL workflows using the new workflow command generator
|
|
|
|
|
|
const workflowGenerator = new WorkflowCommandGenerator(this.bmadFolderName);
|
|
|
|
|
|
const { artifacts: workflowArtifacts, counts: workflowCounts } = await workflowGenerator.collectWorkflowArtifacts(bmadDir);
|
|
|
|
|
|
|
|
|
|
|
|
// Convert workflow artifacts to expected format for organizeByModule
|
|
|
|
|
|
const workflows = workflowArtifacts
|
|
|
|
|
|
.filter((artifact) => artifact.type === 'workflow-command')
|
|
|
|
|
|
.map((artifact) => ({
|
|
|
|
|
|
module: artifact.module,
|
|
|
|
|
|
name: path.basename(artifact.relativePath, '.md'),
|
|
|
|
|
|
path: artifact.sourcePath,
|
|
|
|
|
|
content: artifact.content,
|
|
|
|
|
|
}));
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
2025-10-26 19:38:38 -05:00
|
|
|
|
// Organize by module
|
2025-11-09 20:24:56 -06:00
|
|
|
|
const agentCount = await this.organizeByModule(commandsDir, agentArtifacts, tasks, tools, workflows, projectDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
console.log(chalk.green(`✓ ${this.name} configured:`));
|
2025-10-26 19:38:38 -05:00
|
|
|
|
console.log(chalk.dim(` - ${agentCount.agents} agent commands created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${agentCount.tasks} task commands created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${agentCount.tools} tool commands created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${agentCount.workflows} workflow commands created`));
|
2025-09-28 23:17:07 -05:00
|
|
|
|
console.log(chalk.dim(` - Commands directory: ${path.relative(projectDir, commandsDir)}`));
|
|
|
|
|
|
console.log(chalk.dim('\n Commands can be accessed via Crush command palette'));
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
success: true,
|
2025-10-26 19:38:38 -05:00
|
|
|
|
...agentCount,
|
2025-09-28 23:17:07 -05:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Organize commands by module
|
|
|
|
|
|
*/
|
2025-11-09 20:24:56 -06:00
|
|
|
|
async organizeByModule(commandsDir, agentArtifacts, tasks, tools, workflows, projectDir) {
|
2025-09-28 23:17:07 -05:00
|
|
|
|
// Get unique modules
|
|
|
|
|
|
const modules = new Set();
|
2025-11-09 20:24:56 -06:00
|
|
|
|
for (const artifact of agentArtifacts) modules.add(artifact.module);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
for (const task of tasks) modules.add(task.module);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
for (const tool of tools) modules.add(tool.module);
|
|
|
|
|
|
for (const workflow of workflows) modules.add(workflow.module);
|
|
|
|
|
|
|
|
|
|
|
|
let agentCount = 0;
|
|
|
|
|
|
let taskCount = 0;
|
|
|
|
|
|
let toolCount = 0;
|
|
|
|
|
|
let workflowCount = 0;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
// Create module directories
|
|
|
|
|
|
for (const module of modules) {
|
|
|
|
|
|
const moduleDir = path.join(commandsDir, module);
|
|
|
|
|
|
const moduleAgentsDir = path.join(moduleDir, 'agents');
|
|
|
|
|
|
const moduleTasksDir = path.join(moduleDir, 'tasks');
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const moduleToolsDir = path.join(moduleDir, 'tools');
|
|
|
|
|
|
const moduleWorkflowsDir = path.join(moduleDir, 'workflows');
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
await this.ensureDir(moduleAgentsDir);
|
|
|
|
|
|
await this.ensureDir(moduleTasksDir);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
await this.ensureDir(moduleToolsDir);
|
|
|
|
|
|
await this.ensureDir(moduleWorkflowsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
// Write module-specific agent launchers
|
|
|
|
|
|
const moduleAgents = agentArtifacts.filter((a) => a.module === module);
|
|
|
|
|
|
for (const artifact of moduleAgents) {
|
|
|
|
|
|
const targetPath = path.join(moduleAgentsDir, `${artifact.name}.md`);
|
|
|
|
|
|
await this.writeFile(targetPath, artifact.content);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
agentCount++;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Copy module-specific tasks
|
|
|
|
|
|
const moduleTasks = tasks.filter((t) => t.module === module);
|
|
|
|
|
|
for (const task of moduleTasks) {
|
|
|
|
|
|
const content = await this.readFile(task.path);
|
|
|
|
|
|
const commandContent = this.createTaskCommand(task, content);
|
|
|
|
|
|
const targetPath = path.join(moduleTasksDir, `${task.name}.md`);
|
|
|
|
|
|
await this.writeFile(targetPath, commandContent);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
taskCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Copy module-specific tools
|
|
|
|
|
|
const moduleTools = tools.filter((t) => t.module === module);
|
|
|
|
|
|
for (const tool of moduleTools) {
|
|
|
|
|
|
const content = await this.readFile(tool.path);
|
|
|
|
|
|
const commandContent = this.createToolCommand(tool, content);
|
|
|
|
|
|
const targetPath = path.join(moduleToolsDir, `${tool.name}.md`);
|
|
|
|
|
|
await this.writeFile(targetPath, commandContent);
|
|
|
|
|
|
toolCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-03 22:44:13 -06:00
|
|
|
|
// Copy module-specific workflow commands (already generated)
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const moduleWorkflows = workflows.filter((w) => w.module === module);
|
|
|
|
|
|
for (const workflow of moduleWorkflows) {
|
2025-12-03 22:44:13 -06:00
|
|
|
|
// Use the pre-generated workflow command content
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const targetPath = path.join(moduleWorkflowsDir, `${workflow.name}.md`);
|
2025-12-03 22:44:13 -06:00
|
|
|
|
await this.writeFile(targetPath, workflow.content);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
workflowCount++;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-26 19:38:38 -05:00
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
agents: agentCount,
|
|
|
|
|
|
tasks: taskCount,
|
|
|
|
|
|
tools: toolCount,
|
|
|
|
|
|
workflows: workflowCount,
|
|
|
|
|
|
};
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create task command content
|
|
|
|
|
|
*/
|
|
|
|
|
|
createTaskCommand(task, content) {
|
|
|
|
|
|
// Extract task name
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const nameMatch = content.match(/name="([^"]+)"/);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
const taskName = nameMatch ? nameMatch[1] : this.formatTitle(task.name);
|
|
|
|
|
|
|
|
|
|
|
|
let commandContent = `# /task-${task.name} Command
|
|
|
|
|
|
|
|
|
|
|
|
When this command is used, execute the following task:
|
|
|
|
|
|
|
|
|
|
|
|
## ${taskName} Task
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Command Usage
|
|
|
|
|
|
|
|
|
|
|
|
This command executes the ${taskName} task from the BMAD ${task.module.toUpperCase()} module.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${task.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return commandContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-26 19:38:38 -05:00
|
|
|
|
/**
|
|
|
|
|
|
* Create tool command content
|
|
|
|
|
|
*/
|
|
|
|
|
|
createToolCommand(tool, content) {
|
|
|
|
|
|
// Extract tool name
|
|
|
|
|
|
const nameMatch = content.match(/name="([^"]+)"/);
|
|
|
|
|
|
const toolName = nameMatch ? nameMatch[1] : this.formatTitle(tool.name);
|
|
|
|
|
|
|
|
|
|
|
|
let commandContent = `# /tool-${tool.name} Command
|
|
|
|
|
|
|
|
|
|
|
|
When this command is used, execute the following tool:
|
|
|
|
|
|
|
|
|
|
|
|
## ${toolName} Tool
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Command Usage
|
|
|
|
|
|
|
|
|
|
|
|
This command executes the ${toolName} tool from the BMAD ${tool.module.toUpperCase()} module.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${tool.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return commandContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create workflow command content
|
|
|
|
|
|
*/
|
|
|
|
|
|
createWorkflowCommand(workflow, content) {
|
|
|
|
|
|
const workflowName = workflow.name ? this.formatTitle(workflow.name) : 'Workflow';
|
|
|
|
|
|
|
|
|
|
|
|
let commandContent = `# /${workflow.name} Command
|
|
|
|
|
|
|
|
|
|
|
|
When this command is used, execute the following workflow:
|
|
|
|
|
|
|
|
|
|
|
|
## ${workflowName} Workflow
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Command Usage
|
|
|
|
|
|
|
|
|
|
|
|
This command executes the ${workflowName} workflow from the BMAD ${workflow.module.toUpperCase()} module.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${workflow.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return commandContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-28 23:17:07 -05:00
|
|
|
|
/**
|
|
|
|
|
|
* Format name as title
|
|
|
|
|
|
*/
|
|
|
|
|
|
formatTitle(name) {
|
|
|
|
|
|
return name
|
|
|
|
|
|
.split('-')
|
|
|
|
|
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
|
|
|
|
.join(' ');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Cleanup Crush configuration
|
|
|
|
|
|
*/
|
|
|
|
|
|
async cleanup(projectDir) {
|
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
const bmadCommandsDir = path.join(projectDir, this.configDir, this.commandsDir, 'bmad');
|
|
|
|
|
|
|
|
|
|
|
|
if (await fs.pathExists(bmadCommandsDir)) {
|
|
|
|
|
|
await fs.remove(bmadCommandsDir);
|
|
|
|
|
|
console.log(chalk.dim(`Removed BMAD commands from Crush`));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-22 16:55:37 -06:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Install a custom agent launcher for Crush
|
|
|
|
|
|
* @param {string} projectDir - Project directory
|
|
|
|
|
|
* @param {string} agentName - Agent name (e.g., "fred-commit-poet")
|
|
|
|
|
|
* @param {string} agentPath - Path to compiled agent (relative to project root)
|
|
|
|
|
|
* @param {Object} metadata - Agent metadata
|
|
|
|
|
|
* @returns {Object} Installation result
|
|
|
|
|
|
*/
|
|
|
|
|
|
async installCustomAgentLauncher(projectDir, agentName, agentPath, metadata) {
|
|
|
|
|
|
const crushDir = path.join(projectDir, this.configDir);
|
|
|
|
|
|
const bmadCommandsDir = path.join(crushDir, this.commandsDir, 'bmad');
|
|
|
|
|
|
|
|
|
|
|
|
// Create .crush/commands/bmad directory if it doesn't exist
|
|
|
|
|
|
await fs.ensureDir(bmadCommandsDir);
|
|
|
|
|
|
|
|
|
|
|
|
// Create custom agent launcher
|
|
|
|
|
|
const launcherContent = `# ${agentName} Custom Agent
|
|
|
|
|
|
|
|
|
|
|
|
**⚠️ IMPORTANT**: Run @${agentPath} first to load the complete agent!
|
|
|
|
|
|
|
|
|
|
|
|
This is a launcher for the custom BMAD agent "${agentName}".
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
1. First run: \`${agentPath}\` to load the complete agent
|
|
|
|
|
|
2. Then use this command to activate ${agentName}
|
|
|
|
|
|
|
|
|
|
|
|
The agent will follow the persona and instructions from the main agent file.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
*Generated by BMAD Method*`;
|
|
|
|
|
|
|
|
|
|
|
|
const fileName = `custom-${agentName.toLowerCase()}.md`;
|
|
|
|
|
|
const launcherPath = path.join(bmadCommandsDir, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
// Write the launcher file
|
|
|
|
|
|
await fs.writeFile(launcherPath, launcherContent, 'utf8');
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
ide: 'crush',
|
|
|
|
|
|
path: path.relative(projectDir, launcherPath),
|
|
|
|
|
|
command: agentName,
|
|
|
|
|
|
type: 'custom-agent-launcher',
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { CrushSetup };
|