agents now are not duplicated and isntead cli commmands load from installed agent files

This commit is contained in:
Brian Madison
2025-11-09 20:24:56 -06:00
parent 7eb52520fa
commit f49a4731e7
18 changed files with 388 additions and 292 deletions

View File

@@ -1,6 +1,7 @@
const path = require('node:path');
const { BaseIdeSetup } = require('./_base-ide');
const chalk = require('chalk');
const { AgentCommandGenerator } = require('./shared/agent-command-generator');
/**
* Trae IDE setup handler
@@ -30,20 +31,22 @@ class TraeSetup extends BaseIdeSetup {
// Clean up any existing BMAD files before reinstalling
await this.cleanup(projectDir);
// Get agents, tasks, tools, and workflows (standalone only)
const agents = await this.getAgents(bmadDir);
// 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)
const tasks = await this.getTasks(bmadDir, true);
const tools = await this.getTools(bmadDir, true);
const workflows = await this.getWorkflows(bmadDir, true);
// Process agents as rules with bmad- prefix
let agentCount = 0;
for (const agent of agents) {
const content = await this.readFile(agent.path);
const processedContent = await this.createAgentRule(agent, content, bmadDir, projectDir);
for (const artifact of agentArtifacts) {
const processedContent = await this.createAgentRule(artifact, bmadDir, projectDir);
// Use bmad- prefix: bmad-agent-{module}-{name}.md
const targetPath = path.join(rulesDir, `bmad-agent-${agent.module}-${agent.name}.md`);
const targetPath = path.join(rulesDir, `bmad-agent-${artifact.module}-${artifact.name}.md`);
await this.writeFile(targetPath, processedContent);
agentCount++;
}
@@ -108,46 +111,29 @@ class TraeSetup extends BaseIdeSetup {
/**
* Create rule content for an agent
*/
async createAgentRule(agent, content, bmadDir, projectDir) {
// Extract metadata from agent content
const titleMatch = content.match(/title="([^"]+)"/);
const title = titleMatch ? titleMatch[1] : this.formatTitle(agent.name);
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();
const iconMatch = content.match(/icon="([^"]+)"/);
const icon = iconMatch ? iconMatch[1] : '🤖';
// Get the activation header from central template
const activationHeader = await this.getAgentCommandHeader();
// Extract YAML content if available
const yamlMatch = content.match(/```ya?ml\r?\n([\s\S]*?)```/);
const yamlContent = yamlMatch ? yamlMatch[1] : content;
// Extract metadata from launcher content
const titleMatch = artifact.content.match(/description:\s*"([^"]+)"/);
const title = titleMatch ? titleMatch[1] : this.formatTitle(artifact.name);
// Calculate relative path for reference
const relativePath = path.relative(projectDir, agent.path).replaceAll('\\', '/');
const relativePath = path.relative(projectDir, artifact.sourcePath).replaceAll('\\', '/');
let ruleContent = `# ${title} Agent Rule
This rule is triggered when the user types \`@${agent.name}\` and activates the ${title} agent persona.
This rule is triggered when the user types \`@${artifact.name}\` and activates the ${title} agent persona.
## Agent Activation
${activationHeader}
Read the full YAML, start activation to alter your state of being, follow startup section instructions, stay in this being until told to exit this mode:
\`\`\`yaml
${yamlContent}
\`\`\`
${contentWithoutFrontmatter}
## File Reference
The complete agent definition is available in [${relativePath}](${relativePath}).
## Usage
When the user types \`@${agent.name}\`, activate this ${title} persona and follow all instructions defined in the YAML configuration above.
The full agent definition is located at: \`${relativePath}\`
`;
return ruleContent;