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-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Trae IDE setup handler
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TraeSetup extends BaseIdeSetup {
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
super('trae', 'Trae');
|
|
|
|
|
|
this.configDir = '.trae';
|
|
|
|
|
|
this.rulesDir = 'rules';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Setup Trae 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 .trae/rules directory
|
|
|
|
|
|
const traeDir = path.join(projectDir, this.configDir);
|
|
|
|
|
|
const rulesDir = path.join(traeDir, this.rulesDir);
|
|
|
|
|
|
|
|
|
|
|
|
await this.ensureDir(rulesDir);
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Clean up any existing BMAD files before reinstalling
|
|
|
|
|
|
await this.cleanup(projectDir);
|
|
|
|
|
|
|
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 || []);
|
|
|
|
|
|
|
|
|
|
|
|
// Get tasks, tools, and workflows (standalone only)
|
2025-10-26 19:38:38 -05:00
|
|
|
|
const tasks = await this.getTasks(bmadDir, true);
|
|
|
|
|
|
const tools = await this.getTools(bmadDir, true);
|
|
|
|
|
|
const workflows = await this.getWorkflows(bmadDir, true);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Process agents as rules with bmad- prefix
|
2025-10-26 19:38:38 -05:00
|
|
|
|
let agentCount = 0;
|
2025-11-09 20:24:56 -06:00
|
|
|
|
for (const artifact of agentArtifacts) {
|
|
|
|
|
|
const processedContent = await this.createAgentRule(artifact, bmadDir, projectDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Use bmad- prefix: bmad-agent-{module}-{name}.md
|
2025-11-09 20:24:56 -06:00
|
|
|
|
const targetPath = path.join(rulesDir, `bmad-agent-${artifact.module}-${artifact.name}.md`);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
await this.writeFile(targetPath, processedContent);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
agentCount++;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Process tasks as rules with bmad- prefix
|
2025-10-26 19:38:38 -05:00
|
|
|
|
let taskCount = 0;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
for (const task of tasks) {
|
|
|
|
|
|
const content = await this.readFile(task.path);
|
|
|
|
|
|
const processedContent = this.createTaskRule(task, content);
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Use bmad- prefix: bmad-task-{module}-{name}.md
|
|
|
|
|
|
const targetPath = path.join(rulesDir, `bmad-task-${task.module}-${task.name}.md`);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
await this.writeFile(targetPath, processedContent);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
taskCount++;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Process tools as rules with bmad- prefix
|
2025-10-26 19:38:38 -05:00
|
|
|
|
let toolCount = 0;
|
|
|
|
|
|
for (const tool of tools) {
|
|
|
|
|
|
const content = await this.readFile(tool.path);
|
|
|
|
|
|
const processedContent = this.createToolRule(tool, content);
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Use bmad- prefix: bmad-tool-{module}-{name}.md
|
|
|
|
|
|
const targetPath = path.join(rulesDir, `bmad-tool-${tool.module}-${tool.name}.md`);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
await this.writeFile(targetPath, processedContent);
|
|
|
|
|
|
toolCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Process workflows as rules with bmad- prefix
|
2025-10-26 19:38:38 -05:00
|
|
|
|
let workflowCount = 0;
|
|
|
|
|
|
for (const workflow of workflows) {
|
|
|
|
|
|
const content = await this.readFile(workflow.path);
|
|
|
|
|
|
const processedContent = this.createWorkflowRule(workflow, content);
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Use bmad- prefix: bmad-workflow-{module}-{name}.md
|
|
|
|
|
|
const targetPath = path.join(rulesDir, `bmad-workflow-${workflow.module}-${workflow.name}.md`);
|
2025-10-26 19:38:38 -05:00
|
|
|
|
await this.writeFile(targetPath, processedContent);
|
|
|
|
|
|
workflowCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const totalRules = agentCount + taskCount + toolCount + workflowCount;
|
|
|
|
|
|
|
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} agent rules created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${taskCount} task rules created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${toolCount} tool rules created`));
|
|
|
|
|
|
console.log(chalk.dim(` - ${workflowCount} workflow rules created`));
|
|
|
|
|
|
console.log(chalk.dim(` - Total: ${totalRules} rules`));
|
2025-09-28 23:17:07 -05:00
|
|
|
|
console.log(chalk.dim(` - Rules directory: ${path.relative(projectDir, rulesDir)}`));
|
|
|
|
|
|
console.log(chalk.dim(` - Agents can be activated with @{agent-name}`));
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
success: true,
|
2025-10-26 19:38:38 -05:00
|
|
|
|
rules: totalRules,
|
|
|
|
|
|
agents: agentCount,
|
|
|
|
|
|
tasks: taskCount,
|
|
|
|
|
|
tools: toolCount,
|
|
|
|
|
|
workflows: workflowCount,
|
2025-09-28 23:17:07 -05:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create rule content for an agent
|
|
|
|
|
|
*/
|
2025-11-09 20:24:56 -06:00
|
|
|
|
async createAgentRule(artifact, bmadDir, projectDir) {
|
|
|
|
|
|
// Strip frontmatter from launcher
|
|
|
|
|
|
const frontmatterRegex = /^---\s*\n[\s\S]*?\n---\s*\n/;
|
|
|
|
|
|
const contentWithoutFrontmatter = artifact.content.replace(frontmatterRegex, '').trim();
|
Major Enhancements:
- Installation path is now fully configurable, allowing users to specify custom installation directories during setup
- Default installation location changed to .bmad (hidden directory) for cleaner project root organization
Web Bundle Improvements:
- All web bundles (single agent and team) now include party mode support for multi-agent collaboration!
- Advanced elicitation capabilities integrated into standalone agents
- All bundles enhanced with party mode agent manifests
- Added default-party.csv files to bmm, bmgd, and cis module teams
- The default party file is what will be used with single agent bundles. teams can customize for different party configurations before web bundling through a setting in the team yaml file
- New web bundle outputs for all agents (analyst, architect, dev, pm, sm, tea, tech-writer, ux-designer, game-*, creative-squad)
Phase 4 Workflow Updates (In Progress):
- Initiated shift to separate phase 4 implementation artifacts from documentation
- Phase 4 implementation artifacts (stories, code review, sprint plan, context files) will move to dedicated location outside docs folder
- Installer questions and configuration added for artifact path selection
- Updated workflow.yaml files for code-review, sprint-planning, story-context, epic-tech-context, and retrospective workflows to support this, but still might require some udpates
Additional Changes:
- New agent and action command header models for standardization
- Enhanced web-bundle-activation-steps fragment
- Updated web-bundler.js to support new structure
- VS Code settings updated for new .bmad directory
- Party mode instructions and workflow enhanced for better orchestration
IDE Installer Updates:
- Show version number of installer in cli
- improved Installer UX
- Gemini TOML Improved to have clear loading instructions with @ commands
- All tools agent launcher mds improved to use a central file template critical indication isntead of hardcoding in 2 different locations.
2025-11-09 17:39:05 -06:00
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
// Extract metadata from launcher content
|
|
|
|
|
|
const titleMatch = artifact.content.match(/description:\s*"([^"]+)"/);
|
|
|
|
|
|
const title = titleMatch ? titleMatch[1] : this.formatTitle(artifact.name);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
// Calculate relative path for reference
|
2025-11-09 20:24:56 -06:00
|
|
|
|
const relativePath = path.relative(projectDir, artifact.sourcePath).replaceAll('\\', '/');
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
let ruleContent = `# ${title} Agent Rule
|
|
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
This rule is triggered when the user types \`@${artifact.name}\` and activates the ${title} agent persona.
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
## Agent Activation
|
|
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
${contentWithoutFrontmatter}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
|
|
## File Reference
|
|
|
|
|
|
|
2025-11-09 20:24:56 -06:00
|
|
|
|
The full agent definition is located at: \`${relativePath}\`
|
2025-09-28 23:17:07 -05:00
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return ruleContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create rule content for a task
|
|
|
|
|
|
*/
|
|
|
|
|
|
createTaskRule(task, content) {
|
|
|
|
|
|
// Extract task name from content
|
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 ruleContent = `# ${taskName} Task Rule
|
|
|
|
|
|
|
|
|
|
|
|
This rule defines the ${taskName} task workflow.
|
|
|
|
|
|
|
|
|
|
|
|
## Task Definition
|
|
|
|
|
|
|
|
|
|
|
|
When this task is triggered, execute the following workflow:
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
Reference this task with \`@task-${task.name}\` to execute the defined workflow.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${task.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return ruleContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-26 19:38:38 -05:00
|
|
|
|
/**
|
|
|
|
|
|
* Create rule content for a tool
|
|
|
|
|
|
*/
|
|
|
|
|
|
createToolRule(tool, content) {
|
|
|
|
|
|
// Extract tool name from content
|
|
|
|
|
|
const nameMatch = content.match(/name="([^"]+)"/);
|
|
|
|
|
|
const toolName = nameMatch ? nameMatch[1] : this.formatTitle(tool.name);
|
|
|
|
|
|
|
|
|
|
|
|
let ruleContent = `# ${toolName} Tool Rule
|
|
|
|
|
|
|
|
|
|
|
|
This rule defines the ${toolName} tool.
|
|
|
|
|
|
|
|
|
|
|
|
## Tool Definition
|
|
|
|
|
|
|
|
|
|
|
|
When this tool is triggered, execute the following:
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
Reference this tool with \`@tool-${tool.name}\` to execute it.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${tool.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return ruleContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create rule content for a workflow
|
|
|
|
|
|
*/
|
|
|
|
|
|
createWorkflowRule(workflow, content) {
|
|
|
|
|
|
let ruleContent = `# ${workflow.name} Workflow Rule
|
|
|
|
|
|
|
|
|
|
|
|
This rule defines the ${workflow.name} workflow.
|
|
|
|
|
|
|
|
|
|
|
|
## Workflow Description
|
|
|
|
|
|
|
|
|
|
|
|
${workflow.description || 'No description provided'}
|
|
|
|
|
|
|
|
|
|
|
|
## Workflow Definition
|
|
|
|
|
|
|
|
|
|
|
|
${content}
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
Reference this workflow with \`@workflow-${workflow.name}\` to execute the guided workflow.
|
|
|
|
|
|
|
|
|
|
|
|
## Module
|
|
|
|
|
|
|
|
|
|
|
|
Part of the BMAD ${workflow.module.toUpperCase()} module.
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
return ruleContent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-28 23:17:07 -05:00
|
|
|
|
/**
|
|
|
|
|
|
* Format agent/task name as title
|
|
|
|
|
|
*/
|
|
|
|
|
|
formatTitle(name) {
|
|
|
|
|
|
return name
|
|
|
|
|
|
.split('-')
|
|
|
|
|
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
|
|
|
|
.join(' ');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 17:18:53 -05:00
|
|
|
|
* Cleanup Trae configuration - surgically remove only BMAD files
|
2025-09-28 23:17:07 -05:00
|
|
|
|
*/
|
|
|
|
|
|
async cleanup(projectDir) {
|
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
const rulesPath = path.join(projectDir, this.configDir, this.rulesDir);
|
|
|
|
|
|
|
|
|
|
|
|
if (await fs.pathExists(rulesPath)) {
|
2025-10-28 17:18:53 -05:00
|
|
|
|
// Only remove files that start with bmad- prefix
|
2025-09-28 23:17:07 -05:00
|
|
|
|
const files = await fs.readdir(rulesPath);
|
|
|
|
|
|
let removed = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (const file of files) {
|
2025-10-28 17:18:53 -05:00
|
|
|
|
if (file.startsWith('bmad-') && file.endsWith('.md')) {
|
|
|
|
|
|
await fs.remove(path.join(rulesPath, file));
|
|
|
|
|
|
removed++;
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 17:18:53 -05:00
|
|
|
|
if (removed > 0) {
|
|
|
|
|
|
console.log(chalk.dim(` Cleaned up ${removed} existing BMAD rules`));
|
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-22 17:10:53 -06:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Install a custom agent launcher for Trae
|
|
|
|
|
|
* @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 traeDir = path.join(projectDir, this.configDir);
|
|
|
|
|
|
const rulesDir = path.join(traeDir, this.rulesDir);
|
|
|
|
|
|
|
|
|
|
|
|
// Create .trae/rules directory if it doesn't exist
|
|
|
|
|
|
await fs.ensureDir(rulesDir);
|
|
|
|
|
|
|
|
|
|
|
|
// 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 rule to activate ${agentName}
|
|
|
|
|
|
|
|
|
|
|
|
The agent will follow the persona and instructions from the main agent file.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
*Generated by BMAD Method*`;
|
|
|
|
|
|
|
|
|
|
|
|
const fileName = `bmad-agent-custom-${agentName.toLowerCase()}.md`;
|
|
|
|
|
|
const launcherPath = path.join(rulesDir, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
// Write the launcher file
|
|
|
|
|
|
await fs.writeFile(launcherPath, launcherContent, 'utf8');
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
ide: 'trae',
|
|
|
|
|
|
path: path.relative(projectDir, launcherPath),
|
|
|
|
|
|
command: agentName,
|
|
|
|
|
|
type: 'custom-agent-launcher',
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { TraeSetup };
|