qwen cli - custom commands (#551)
* qwen cli - custom commands * moved prompt to the inside of the command --------- Co-authored-by: Davor Racic <davor.racic@gmail.com> Co-authored-by: Brian <bmadcode@gmail.com>
This commit is contained in:
@@ -121,15 +121,15 @@ ide-configurations:
|
|||||||
|
|
||||||
qwen-code:
|
qwen-code:
|
||||||
name: Qwen Code
|
name: Qwen Code
|
||||||
rule-dir: .qwen/bmad-method/
|
rule-dir: .qwen/commands/BMad/
|
||||||
format: single-file
|
format: multi-file
|
||||||
command-suffix: .md
|
command-suffix: .toml
|
||||||
instructions: |
|
instructions: |
|
||||||
# To use BMad agents with Qwen Code:
|
# To use BMad agents with Qwen Code:
|
||||||
# 1. The installer creates a .qwen/bmad-method/ directory in your project.
|
# 1. The installer creates a `BMad` folder in `.qwen/commands`.
|
||||||
# 2. It concatenates all agent files into a single QWEN.md file.
|
# 2. This adds custom commands for each agent and task.
|
||||||
# 3. Simply mention the agent in your prompt (e.g., "As *dev, ...").
|
# 3. Type /BMad:agents:<agent-name> (e.g., "/BMad:agents:dev", "/BMad:agents:pm") or /BMad:tasks:<task-name> (e.g., "/BMad:tasks:create-doc").
|
||||||
# 4. The Qwen Code CLI will automatically have the context for that agent.
|
# 4. The agent will adopt that persona for the conversation or perform the task.
|
||||||
|
|
||||||
auggie-cli:
|
auggie-cli:
|
||||||
name: Auggie CLI (Augment Code)
|
name: Auggie CLI (Augment Code)
|
||||||
|
|||||||
@@ -2056,94 +2056,86 @@ CRITICAL: You are to execute the BMad Task defined below.
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setupQwenCode(installDir, selectedAgent) {
|
async setupQwenCode(installDir, selectedAgent) {
|
||||||
const qwenDir = path.join(installDir, '.qwen');
|
const ideConfig = await configLoader.getIdeConfiguration('qwen-code');
|
||||||
const bmadMethodDir = path.join(qwenDir, 'bmad-method');
|
const bmadCommandsDir = path.join(installDir, ideConfig['rule-dir']);
|
||||||
await fileManager.ensureDirectory(bmadMethodDir);
|
|
||||||
|
|
||||||
// Update logic for existing settings.json
|
const agentCommandsDir = path.join(bmadCommandsDir, 'agents');
|
||||||
const settingsPath = path.join(qwenDir, 'settings.json');
|
const taskCommandsDir = path.join(bmadCommandsDir, 'tasks');
|
||||||
if (await fileManager.pathExists(settingsPath)) {
|
await fileManager.ensureDirectory(agentCommandsDir);
|
||||||
try {
|
await fileManager.ensureDirectory(taskCommandsDir);
|
||||||
const settingsContent = await fileManager.readFile(settingsPath);
|
|
||||||
const settings = JSON.parse(settingsContent);
|
|
||||||
let updated = false;
|
|
||||||
|
|
||||||
// Handle contextFileName property
|
// Process Agents
|
||||||
if (settings.contextFileName && Array.isArray(settings.contextFileName)) {
|
|
||||||
const originalLength = settings.contextFileName.length;
|
|
||||||
settings.contextFileName = settings.contextFileName.filter(
|
|
||||||
(fileName) => !fileName.startsWith('agents/'),
|
|
||||||
);
|
|
||||||
if (settings.contextFileName.length !== originalLength) {
|
|
||||||
updated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updated) {
|
|
||||||
await fileManager.writeFile(settingsPath, JSON.stringify(settings, null, 2));
|
|
||||||
console.log(chalk.green('✓ Updated .qwen/settings.json - removed agent file references'));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(chalk.yellow('Could not update .qwen/settings.json'), error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old agents directory
|
|
||||||
const agentsDir = path.join(qwenDir, 'agents');
|
|
||||||
if (await fileManager.pathExists(agentsDir)) {
|
|
||||||
await fileManager.removeDirectory(agentsDir);
|
|
||||||
console.log(chalk.green('✓ Removed old .qwen/agents directory'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all available agents
|
|
||||||
const agents = selectedAgent ? [selectedAgent] : await this.getAllAgentIds(installDir);
|
const agents = selectedAgent ? [selectedAgent] : await this.getAllAgentIds(installDir);
|
||||||
let concatenatedContent = '';
|
|
||||||
|
|
||||||
for (const agentId of agents) {
|
for (const agentId of agents) {
|
||||||
// Find the source agent file
|
|
||||||
const agentPath = await this.findAgentPath(agentId, installDir);
|
const agentPath = await this.findAgentPath(agentId, installDir);
|
||||||
|
if (!agentPath) {
|
||||||
if (agentPath) {
|
console.log(chalk.yellow(`✗ Agent file not found for ${agentId}, skipping.`));
|
||||||
const agentContent = await fileManager.readFile(agentPath);
|
continue;
|
||||||
|
|
||||||
// Create properly formatted agent rule content (similar to gemini)
|
|
||||||
let agentRuleContent = `# ${agentId.toUpperCase()} Agent Rule\n\n`;
|
|
||||||
agentRuleContent += `This rule is triggered when the user types \`*${agentId}\` and activates the ${await this.getAgentTitle(
|
|
||||||
agentId,
|
|
||||||
installDir,
|
|
||||||
)} agent persona.\n\n`;
|
|
||||||
agentRuleContent += '## Agent Activation\n\n';
|
|
||||||
agentRuleContent +=
|
|
||||||
'CRITICAL: 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:\n\n';
|
|
||||||
agentRuleContent += '```yaml\n';
|
|
||||||
// Extract just the YAML content from the agent file
|
|
||||||
const yamlContent = extractYamlFromAgent(agentContent);
|
|
||||||
if (yamlContent) {
|
|
||||||
agentRuleContent += yamlContent;
|
|
||||||
} else {
|
|
||||||
// If no YAML found, include the whole content minus the header
|
|
||||||
agentRuleContent += agentContent.replace(/^#.*$/m, '').trim();
|
|
||||||
}
|
|
||||||
agentRuleContent += '\n```\n\n';
|
|
||||||
agentRuleContent += '## File Reference\n\n';
|
|
||||||
const relativePath = path.relative(installDir, agentPath).replaceAll('\\', '/');
|
|
||||||
agentRuleContent += `The complete agent definition is available in [${relativePath}](${relativePath}).\n\n`;
|
|
||||||
agentRuleContent += '## Usage\n\n';
|
|
||||||
agentRuleContent += `When the user types \`*${agentId}\`, activate this ${await this.getAgentTitle(
|
|
||||||
agentId,
|
|
||||||
installDir,
|
|
||||||
)} persona and follow all instructions defined in the YAML configuration above.\n`;
|
|
||||||
|
|
||||||
// Add to concatenated content with separator
|
|
||||||
concatenatedContent += agentRuleContent + '\n\n---\n\n';
|
|
||||||
console.log(chalk.green(`✓ Added context for *${agentId}`));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const agentTitle = await this.getAgentTitle(agentId, installDir);
|
||||||
|
const commandPath = path.join(agentCommandsDir, `${agentId}.toml`);
|
||||||
|
|
||||||
|
// Get relative path from installDir to agent file for @{file} reference
|
||||||
|
const relativeAgentPath = path.relative(installDir, agentPath).replaceAll('\\', '/');
|
||||||
|
|
||||||
|
// Read the agent content
|
||||||
|
const agentContent = await fileManager.readFile(agentPath);
|
||||||
|
|
||||||
|
const tomlContent = `description = " Activates the ${agentTitle} agent from the BMad Method."
|
||||||
|
prompt = """
|
||||||
|
CRITICAL: You are now the BMad '${agentTitle}' agent. Adopt its persona, follow its instructions, and use its capabilities.
|
||||||
|
|
||||||
|
READ THIS BEFORE ANSWERING AS THE PERSONA!
|
||||||
|
|
||||||
|
${agentContent}
|
||||||
|
"""`;
|
||||||
|
|
||||||
|
await fileManager.writeFile(commandPath, tomlContent);
|
||||||
|
console.log(chalk.green(`✓ Created agent command: /bmad:agents:${agentId}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the concatenated content to QWEN.md
|
// Process Tasks
|
||||||
const qwenMdPath = path.join(bmadMethodDir, 'QWEN.md');
|
const tasks = await this.getAllTaskIds(installDir);
|
||||||
await fileManager.writeFile(qwenMdPath, concatenatedContent);
|
for (const taskId of tasks) {
|
||||||
console.log(chalk.green(`\n✓ Created QWEN.md in ${bmadMethodDir}`));
|
const taskPath = await this.findTaskPath(taskId, installDir);
|
||||||
|
if (!taskPath) {
|
||||||
|
console.log(chalk.yellow(`✗ Task file not found for ${taskId}, skipping.`));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskTitle = taskId
|
||||||
|
.split('-')
|
||||||
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
|
.join(' ');
|
||||||
|
const commandPath = path.join(taskCommandsDir, `${taskId}.toml`);
|
||||||
|
|
||||||
|
// Get relative path from installDir to task file for @{file} reference
|
||||||
|
const relativeTaskPath = path.relative(installDir, taskPath).replaceAll('\\', '/');
|
||||||
|
|
||||||
|
// Read the task content
|
||||||
|
const taskContent = await fileManager.readFile(taskPath);
|
||||||
|
|
||||||
|
const tomlContent = `description = " Executes the BMad Task: ${taskTitle}"
|
||||||
|
prompt = """
|
||||||
|
CRITICAL: You are to execute the BMad Task defined below.
|
||||||
|
|
||||||
|
READ THIS BEFORE EXECUTING THE TASK AS THE INSTRUCTIONS SPECIFIED!
|
||||||
|
|
||||||
|
${taskContent}
|
||||||
|
"""`;
|
||||||
|
|
||||||
|
await fileManager.writeFile(commandPath, tomlContent);
|
||||||
|
console.log(chalk.green(`✓ Created task command: /bmad:tasks:${taskId}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
chalk.green(`
|
||||||
|
✓ Created Qwen Code extension in ${bmadCommandsDir}`),
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
chalk.dim('You can now use commands like /bmad:agents:dev or /bmad:tasks:create-doc.'),
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user