2025-09-28 23:17:07 -05:00
|
|
|
const path = require('node:path');
|
2025-10-28 23:16:48 -05:00
|
|
|
const fs = require('fs-extra');
|
2025-09-28 23:17:07 -05:00
|
|
|
const chalk = require('chalk');
|
2025-10-28 23:16:48 -05:00
|
|
|
const { BaseIdeSetup } = require('./_base-ide');
|
|
|
|
|
const { WorkflowCommandGenerator } = require('./workflow-command-generator');
|
|
|
|
|
const { getAgentsFromBmad, getTasksFromBmad } = require('./shared/bmad-artifacts');
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cline IDE setup handler
|
2025-10-28 23:16:48 -05:00
|
|
|
* Installs BMAD artifacts to .clinerules/workflows with flattened naming
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
|
|
|
|
class ClineSetup extends BaseIdeSetup {
|
|
|
|
|
constructor() {
|
2025-10-28 23:16:48 -05:00
|
|
|
super('cline', 'Cline', true); // preferred IDE
|
2025-09-28 23:17:07 -05:00
|
|
|
this.configDir = '.clinerules';
|
2025-10-28 23:16:48 -05:00
|
|
|
this.workflowsDir = 'workflows';
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup Cline 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}...`));
|
|
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Create .clinerules/workflows directory
|
|
|
|
|
const clineDir = path.join(projectDir, this.configDir);
|
|
|
|
|
const workflowsDir = path.join(clineDir, this.workflowsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
await this.ensureDir(workflowsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Clear old BMAD files
|
|
|
|
|
await this.clearOldBmadFiles(workflowsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Collect all artifacts
|
|
|
|
|
const { artifacts, counts } = await this.collectClineArtifacts(projectDir, bmadDir, options);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Write flattened files
|
|
|
|
|
const written = await this.flattenAndWriteArtifacts(artifacts, workflowsDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
console.log(chalk.green(`✓ ${this.name} configured:`));
|
|
|
|
|
console.log(chalk.dim(` - ${counts.agents} agents installed`));
|
|
|
|
|
console.log(chalk.dim(` - ${counts.tasks} tasks installed`));
|
|
|
|
|
console.log(chalk.dim(` - ${counts.workflows} workflow commands installed`));
|
|
|
|
|
if (counts.workflowLaunchers > 0) {
|
|
|
|
|
console.log(chalk.dim(` - ${counts.workflowLaunchers} workflow launchers installed`));
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
2025-10-28 23:16:48 -05:00
|
|
|
console.log(chalk.dim(` - ${written} files written to ${path.relative(projectDir, workflowsDir)}`));
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Usage instructions
|
|
|
|
|
console.log(chalk.yellow('\n ⚠️ How to Use Cline Workflows'));
|
|
|
|
|
console.log(chalk.cyan(' BMAD workflows are available as slash commands in Cline'));
|
|
|
|
|
console.log(chalk.dim(' Usage:'));
|
|
|
|
|
console.log(chalk.dim(' - Type / to see available commands'));
|
|
|
|
|
console.log(chalk.dim(' - All BMAD items start with "bmad-"'));
|
|
|
|
|
console.log(chalk.dim(' - Example: /bmad-bmm-agents-pm'));
|
2025-09-28 23:17:07 -05:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
2025-10-28 23:16:48 -05:00
|
|
|
agents: counts.agents,
|
|
|
|
|
tasks: counts.tasks,
|
|
|
|
|
workflows: counts.workflows,
|
|
|
|
|
workflowLaunchers: counts.workflowLaunchers,
|
|
|
|
|
written,
|
2025-09-28 23:17:07 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Detect Cline installation by checking for .clinerules/workflows directory
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
async detect(projectDir) {
|
|
|
|
|
const workflowsDir = path.join(projectDir, this.configDir, this.workflowsDir);
|
|
|
|
|
|
|
|
|
|
if (!(await fs.pathExists(workflowsDir))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
const entries = await fs.readdir(workflowsDir);
|
|
|
|
|
return entries.some((entry) => entry.startsWith('bmad-'));
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Collect all artifacts for Cline export
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
async collectClineArtifacts(projectDir, bmadDir, options = {}) {
|
|
|
|
|
const selectedModules = options.selectedModules || [];
|
|
|
|
|
const artifacts = [];
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Get agents
|
|
|
|
|
const agents = await getAgentsFromBmad(bmadDir, selectedModules);
|
|
|
|
|
for (const agent of agents) {
|
|
|
|
|
const content = await this.readAndProcessWithProject(
|
|
|
|
|
agent.path,
|
|
|
|
|
{
|
|
|
|
|
module: agent.module,
|
|
|
|
|
name: agent.name,
|
|
|
|
|
},
|
|
|
|
|
projectDir,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
artifacts.push({
|
|
|
|
|
type: 'agent',
|
|
|
|
|
module: agent.module,
|
|
|
|
|
sourcePath: agent.path,
|
|
|
|
|
relativePath: path.join(agent.module, 'agents', `${agent.name}.md`),
|
|
|
|
|
content,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
// Get tasks
|
|
|
|
|
const tasks = await getTasksFromBmad(bmadDir, selectedModules);
|
|
|
|
|
for (const task of tasks) {
|
|
|
|
|
const content = await this.readAndProcessWithProject(
|
|
|
|
|
task.path,
|
|
|
|
|
{
|
|
|
|
|
module: task.module,
|
|
|
|
|
name: task.name,
|
|
|
|
|
},
|
|
|
|
|
projectDir,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
artifacts.push({
|
|
|
|
|
type: 'task',
|
|
|
|
|
module: task.module,
|
|
|
|
|
sourcePath: task.path,
|
|
|
|
|
relativePath: path.join(task.module, 'tasks', `${task.name}.md`),
|
|
|
|
|
content,
|
|
|
|
|
});
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
2025-10-28 23:16:48 -05:00
|
|
|
|
|
|
|
|
// Get workflows
|
|
|
|
|
const workflowGenerator = new WorkflowCommandGenerator();
|
|
|
|
|
const { artifacts: workflowArtifacts, counts: workflowCounts } = await workflowGenerator.collectWorkflowArtifacts(bmadDir);
|
|
|
|
|
artifacts.push(...workflowArtifacts);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
artifacts,
|
|
|
|
|
counts: {
|
|
|
|
|
agents: agents.length,
|
|
|
|
|
tasks: tasks.length,
|
|
|
|
|
workflows: workflowCounts.commands,
|
|
|
|
|
workflowLaunchers: workflowCounts.launchers,
|
|
|
|
|
},
|
|
|
|
|
};
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Flatten file path to bmad-module-type-name.md format
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
flattenFilename(relativePath) {
|
|
|
|
|
const sanitized = relativePath.replaceAll(/[\\/]/g, '-');
|
|
|
|
|
return `bmad-${sanitized}`;
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Write all artifacts with flattened names
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
async flattenAndWriteArtifacts(artifacts, destDir) {
|
|
|
|
|
let written = 0;
|
|
|
|
|
|
|
|
|
|
for (const artifact of artifacts) {
|
|
|
|
|
const flattenedName = this.flattenFilename(artifact.relativePath);
|
|
|
|
|
const targetPath = path.join(destDir, flattenedName);
|
|
|
|
|
await fs.writeFile(targetPath, artifact.content);
|
|
|
|
|
written++;
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
return written;
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Clear old BMAD files from the workflows directory
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
async clearOldBmadFiles(destDir) {
|
|
|
|
|
if (!(await fs.pathExists(destDir))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
const entries = await fs.readdir(destDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
for (const entry of entries) {
|
|
|
|
|
if (!entry.startsWith('bmad-')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
const entryPath = path.join(destDir, entry);
|
|
|
|
|
const stat = await fs.stat(entryPath);
|
|
|
|
|
if (stat.isFile()) {
|
|
|
|
|
await fs.remove(entryPath);
|
|
|
|
|
} else if (stat.isDirectory()) {
|
|
|
|
|
await fs.remove(entryPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-28 23:16:48 -05:00
|
|
|
* Read and process file with project-specific paths
|
2025-09-28 23:17:07 -05:00
|
|
|
*/
|
2025-10-28 23:16:48 -05:00
|
|
|
async readAndProcessWithProject(filePath, metadata, projectDir) {
|
|
|
|
|
const content = await fs.readFile(filePath, 'utf8');
|
|
|
|
|
return super.processContent(content, metadata, projectDir);
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cleanup Cline configuration
|
|
|
|
|
*/
|
|
|
|
|
async cleanup(projectDir) {
|
2025-10-28 23:16:48 -05:00
|
|
|
const workflowsDir = path.join(projectDir, this.configDir, this.workflowsDir);
|
|
|
|
|
await this.clearOldBmadFiles(workflowsDir);
|
|
|
|
|
console.log(chalk.dim(`Removed ${this.name} BMAD configuration`));
|
|
|
|
|
}
|
2025-09-28 23:17:07 -05:00
|
|
|
|
2025-10-28 23:16:48 -05:00
|
|
|
/**
|
|
|
|
|
* Utility: Ensure directory exists
|
|
|
|
|
*/
|
|
|
|
|
async ensureDir(dirPath) {
|
|
|
|
|
await fs.ensureDir(dirPath);
|
2025-09-28 23:17:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { ClineSetup };
|