feat(codex): activate with custom prompts instead of AGENTS.md (#679)

This commit is contained in:
Alex Verkhovsky
2025-10-05 15:52:48 -07:00
committed by GitHub
parent 33d893bef2
commit c49f4b2e9b
9 changed files with 599 additions and 614 deletions

View File

@@ -0,0 +1,112 @@
const path = require('node:path');
const fs = require('fs-extra');
/**
* Helpers for gathering BMAD agents/tasks from the installed tree.
* Shared by installers that need Claude-style exports.
*/
async function getAgentsFromBmad(bmadDir, selectedModules = []) {
const agents = [];
if (await fs.pathExists(path.join(bmadDir, 'core', 'agents'))) {
const coreAgents = await getAgentsFromDir(path.join(bmadDir, 'core', 'agents'), 'core');
agents.push(...coreAgents);
}
for (const moduleName of selectedModules) {
const agentsPath = path.join(bmadDir, moduleName, 'agents');
if (await fs.pathExists(agentsPath)) {
const moduleAgents = await getAgentsFromDir(agentsPath, moduleName);
agents.push(...moduleAgents);
}
}
return agents;
}
async function getTasksFromBmad(bmadDir, selectedModules = []) {
const tasks = [];
if (await fs.pathExists(path.join(bmadDir, 'core', 'tasks'))) {
const coreTasks = await getTasksFromDir(path.join(bmadDir, 'core', 'tasks'), 'core');
tasks.push(...coreTasks);
}
for (const moduleName of selectedModules) {
const tasksPath = path.join(bmadDir, moduleName, 'tasks');
if (await fs.pathExists(tasksPath)) {
const moduleTasks = await getTasksFromDir(tasksPath, moduleName);
tasks.push(...moduleTasks);
}
}
return tasks;
}
async function getAgentsFromDir(dirPath, moduleName) {
const agents = [];
if (!(await fs.pathExists(dirPath))) {
return agents;
}
const files = await fs.readdir(dirPath);
for (const file of files) {
if (!file.endsWith('.md')) {
continue;
}
if (file.includes('.customize.')) {
continue;
}
const filePath = path.join(dirPath, file);
const content = await fs.readFile(filePath, 'utf8');
if (content.includes('localskip="true"')) {
continue;
}
agents.push({
path: filePath,
name: file.replace('.md', ''),
module: moduleName,
});
}
return agents;
}
async function getTasksFromDir(dirPath, moduleName) {
const tasks = [];
if (!(await fs.pathExists(dirPath))) {
return tasks;
}
const files = await fs.readdir(dirPath);
for (const file of files) {
if (!file.endsWith('.md')) {
continue;
}
tasks.push({
path: path.join(dirPath, file),
name: file.replace('.md', ''),
module: moduleName,
});
}
return tasks;
}
module.exports = {
getAgentsFromBmad,
getTasksFromBmad,
getAgentsFromDir,
getTasksFromDir,
};

View File

@@ -0,0 +1,133 @@
const path = require('node:path');
const fs = require('fs-extra');
const yaml = require('js-yaml');
const { glob } = require('glob');
const { getSourcePath } = require('../../../../lib/project-root');
async function loadModuleInjectionConfig(handler, moduleName) {
const sourceModulesPath = getSourcePath('modules');
const handlerBaseDir = path.join(sourceModulesPath, moduleName, 'sub-modules', handler);
const configPath = path.join(handlerBaseDir, 'injections.yaml');
if (!(await fs.pathExists(configPath))) {
return null;
}
const configContent = await fs.readFile(configPath, 'utf8');
const config = yaml.load(configContent) || {};
return {
config,
handlerBaseDir,
configPath,
};
}
function shouldApplyInjection(injection, subagentChoices) {
if (!subagentChoices || subagentChoices.install === 'none') {
return false;
}
if (subagentChoices.install === 'all') {
return true;
}
if (subagentChoices.install === 'selective') {
const selected = subagentChoices.selected || [];
if (injection.requires === 'any' && selected.length > 0) {
return true;
}
if (injection.requires) {
const required = `${injection.requires}.md`;
return selected.includes(required);
}
if (injection.point) {
const selectedNames = selected.map((file) => file.replace('.md', ''));
return selectedNames.some((name) => injection.point.includes(name));
}
}
return false;
}
function filterAgentInstructions(content, selectedFiles) {
if (!selectedFiles || selectedFiles.length === 0) {
return '';
}
const selectedAgents = selectedFiles.map((file) => file.replace('.md', ''));
const lines = content.split('\n');
const filteredLines = [];
for (const line of lines) {
if (line.includes('<llm') || line.includes('</llm>')) {
filteredLines.push(line);
} else if (line.includes('subagent')) {
let shouldInclude = false;
for (const agent of selectedAgents) {
if (line.includes(agent)) {
shouldInclude = true;
break;
}
}
if (shouldInclude) {
filteredLines.push(line);
}
} else if (line.includes('When creating PRDs') || line.includes('ACTIVELY delegate')) {
filteredLines.push(line);
}
}
if (filteredLines.length > 2) {
return filteredLines.join('\n');
}
return '';
}
async function resolveSubagentFiles(handlerBaseDir, subagentConfig, subagentChoices) {
if (!subagentConfig || !subagentConfig.files) {
return [];
}
if (!subagentChoices || subagentChoices.install === 'none') {
return [];
}
let filesToCopy = subagentConfig.files;
if (subagentChoices.install === 'selective') {
filesToCopy = subagentChoices.selected || [];
}
const sourceDir = path.join(handlerBaseDir, subagentConfig.source || '');
const resolved = [];
for (const file of filesToCopy) {
const pattern = path.join(sourceDir, '**', file);
const matches = await glob(pattern);
if (matches.length > 0) {
const absolutePath = matches[0];
resolved.push({
file,
absolutePath,
relativePath: path.relative(sourceDir, absolutePath),
sourceDir,
});
}
}
return resolved;
}
module.exports = {
loadModuleInjectionConfig,
shouldApplyInjection,
filterAgentInstructions,
resolveSubagentFiles,
};