Compare commits

..

No commits in common. "c0eccdaea8bafe5fe404c58725c1b215974ce1d3" and "ba589f6bdc55ad396d04ab636e0a6d01f4ad294f" have entirely different histories.

1 changed files with 78 additions and 27 deletions

View File

@ -2,11 +2,13 @@ const path = require('node:path');
const fs = require('fs-extra');
const os = require('node:os');
const chalk = require('chalk');
const yaml = require('yaml');
const { BaseIdeSetup } = require('./_base-ide');
const { WorkflowCommandGenerator } = require('./shared/workflow-command-generator');
const { AgentCommandGenerator } = require('./shared/agent-command-generator');
const { TaskToolCommandGenerator } = require('./shared/task-tool-command-generator');
const { customAgentDashName } = require('./shared/path-utils');
const { getTasksFromBmad } = require('./shared/bmad-artifacts');
const { toDashPath, customAgentDashName } = require('./shared/path-utils');
const prompts = require('../../../lib/prompts');
/**
@ -90,16 +92,56 @@ class CodexSetup extends BaseIdeSetup {
const { artifacts: agentArtifacts } = await agentGen.collectAgentArtifacts(bmadDir, options.selectedModules || []);
const agentCount = await agentGen.writeDashArtifacts(destDir, agentArtifacts);
const tasks = await getTasksFromBmad(bmadDir, options.selectedModules || []);
const taskArtifacts = [];
for (const task of tasks) {
const content = await this.readAndProcessWithProject(
task.path,
{
module: task.module,
name: task.name,
},
projectDir,
);
let displayName = task.name;
let description;
let declaredName = task.name;
const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/);
if (frontmatterMatch) {
try {
const frontmatter = yaml.parse(frontmatterMatch[1]);
if (frontmatter && typeof frontmatter === 'object') {
declaredName = frontmatter.name || declaredName;
displayName = frontmatter.displayName || frontmatter.name || displayName;
description = frontmatter.description || description;
}
} catch {
// Ignore frontmatter parse errors
}
}
const taskPath = path.posix.join(this.bmadFolderName, task.module, 'tasks', `${task.name}.md`);
taskArtifacts.push({
type: 'task',
module: task.module,
name: declaredName,
displayName,
description,
path: taskPath,
sourcePath: task.path,
relativePath: path.join(task.module, 'tasks', `${task.name}.md`),
content,
});
}
const workflowGenerator = new WorkflowCommandGenerator(this.bmadFolderName);
const { artifacts: workflowArtifacts } = await workflowGenerator.collectWorkflowArtifacts(bmadDir);
const workflowCount = await workflowGenerator.writeDashArtifacts(destDir, workflowArtifacts);
// Also write tasks using manifest-driven generator
// Also write tasks using underscore format
const ttGen = new TaskToolCommandGenerator();
const taskToolResult = await ttGen.generateDashTaskToolCommands(projectDir, bmadDir, destDir);
const tasksWritten = taskToolResult.generated || 0;
counts.tasks = taskToolResult.tasks || 0;
counts.tools = taskToolResult.tools || 0;
const tasksWritten = await ttGen.writeDashArtifacts(destDir, taskArtifacts);
const written = agentCount + workflowCount + tasksWritten;
@ -107,7 +149,6 @@ class CodexSetup extends BaseIdeSetup {
console.log(chalk.dim(` - Mode: CLI`));
console.log(chalk.dim(` - ${counts.agents} agents exported`));
console.log(chalk.dim(` - ${counts.tasks} tasks exported`));
console.log(chalk.dim(` - ${counts.tools} tools exported`));
console.log(chalk.dim(` - ${counts.workflows} workflow commands exported`));
if (counts.workflowLaunchers > 0) {
console.log(chalk.dim(` - ${counts.workflowLaunchers} workflow launchers exported`));
@ -184,13 +225,17 @@ class CodexSetup extends BaseIdeSetup {
});
}
const taskToolGen = new TaskToolCommandGenerator();
const taskManifest = await taskToolGen.loadTaskManifest(bmadDir);
const toolManifest = await taskToolGen.loadToolManifest(bmadDir);
const standaloneTasks = taskManifest ? taskManifest.filter((task) => task.standalone === 'true' || task.standalone === true) : [];
const standaloneTools = toolManifest ? toolManifest.filter((tool) => tool.standalone === 'true' || tool.standalone === true) : [];
for (const task of standaloneTasks) {
const content = taskToolGen.generateCommandContent(task, 'task');
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,
@ -200,17 +245,6 @@ class CodexSetup extends BaseIdeSetup {
});
}
for (const tool of standaloneTools) {
const content = taskToolGen.generateCommandContent(tool, 'tool');
artifacts.push({
type: 'tool',
module: tool.module,
sourcePath: tool.path,
relativePath: path.join(tool.module, 'tools', `${tool.name}.md`),
content,
});
}
const workflowGenerator = new WorkflowCommandGenerator(this.bmadFolderName);
const { artifacts: workflowArtifacts, counts: workflowCounts } = await workflowGenerator.collectWorkflowArtifacts(bmadDir);
artifacts.push(...workflowArtifacts);
@ -219,8 +253,7 @@ class CodexSetup extends BaseIdeSetup {
artifacts,
counts: {
agents: agentArtifacts.length,
tasks: standaloneTasks.length,
tools: standaloneTools.length,
tasks: tasks.length,
workflows: workflowCounts.commands,
workflowLaunchers: workflowCounts.launchers,
},
@ -234,6 +267,19 @@ class CodexSetup extends BaseIdeSetup {
return path.join(os.homedir(), '.codex', 'prompts');
}
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++;
}
return written;
}
async clearOldBmadFiles(destDir) {
if (!(await fs.pathExists(destDir))) {
return;
@ -276,6 +322,11 @@ class CodexSetup extends BaseIdeSetup {
}
}
async readAndProcessWithProject(filePath, metadata, projectDir) {
const content = await fs.readFile(filePath, 'utf8');
return super.processContent(content, metadata, projectDir);
}
/**
* Get instructions for global installation
* @returns {string} Instructions text