chore(cli): remove broken build caching (#1042)

The agent build caching never worked - BUILD-META comments were
never written to output files, so every build acted like --force.

Since building all 29 agents takes ~300ms, caching provided no
meaningful benefit. Removed ~190 lines of dead code including
checkIfNeedsRebuild, checkBuildStatus, buildMetadataComment,
and the --force flag.

Co-authored-by: Brian <bmadcode@gmail.com>
This commit is contained in:
Alex Verkhovsky 2025-12-06 10:38:56 -08:00 committed by GitHub
parent e979b47fe5
commit a0442d4fb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 199 deletions

View File

@ -28,9 +28,8 @@ module.exports = {
command: 'build [agent]',
description: 'Build agent XML files from YAML sources',
options: [
['-a, --all', 'Rebuild all agents'],
['-a, --all', 'Build all agents'],
['-d, --directory <path>', 'Project directory', '.'],
['--force', 'Force rebuild even if up to date'],
],
action: async (agentName, options) => {
try {
@ -54,13 +53,15 @@ module.exports = {
if (options.all) {
// Build all agents
await buildAllAgents(projectDir, options.force);
await buildAllAgents(projectDir);
} else if (agentName) {
// Build specific agent
await buildAgent(projectDir, agentName, options.force);
await buildAgent(projectDir, agentName);
} else {
// No agent specified, check what needs rebuilding
await checkBuildStatus(projectDir);
// No agent specified, list available agents
console.log(chalk.yellow('No agent specified. Use --all to build all agents or specify an agent name.'));
console.log(chalk.dim('\nAvailable agents:'));
await listAvailableAgents(projectDir);
}
process.exit(0);
@ -77,7 +78,7 @@ module.exports = {
/**
* Build a specific agent
*/
async function buildAgent(projectDir, agentName, force = false) {
async function buildAgent(projectDir, agentName) {
// First check standalone agents in bmad/agents/{agentname}/
const standaloneAgentDir = path.join(projectDir, 'bmad', 'agents', agentName);
let standaloneYamlPath = path.join(standaloneAgentDir, `${agentName}.agent.yaml`);
@ -95,15 +96,6 @@ async function buildAgent(projectDir, agentName, force = false) {
const yamlFileName = path.basename(standaloneYamlPath, '.agent.yaml');
const outputPath = path.join(standaloneAgentDir, `${yamlFileName}.md`);
// Check if rebuild needed
if (!force && (await fs.pathExists(outputPath))) {
const needsRebuild = await checkIfNeedsRebuild(standaloneYamlPath, outputPath, projectDir, agentName);
if (!needsRebuild) {
console.log(chalk.dim(` ${agentName}: already up to date`));
return;
}
}
// Build the standalone agent
console.log(chalk.cyan(` Building standalone agent ${agentName}...`));
@ -130,15 +122,6 @@ async function buildAgent(projectDir, agentName, force = false) {
if (await fs.pathExists(agentYamlPath)) {
found = true;
// Check if rebuild needed
if (!force && (await fs.pathExists(outputPath))) {
const needsRebuild = await checkIfNeedsRebuild(agentYamlPath, outputPath, projectDir, agentName);
if (!needsRebuild) {
console.log(chalk.dim(` ${agentName}: already up to date`));
return;
}
}
// Build the agent
console.log(chalk.cyan(` Building ${agentName}...`));
@ -162,9 +145,8 @@ async function buildAgent(projectDir, agentName, force = false) {
/**
* Build all agents
*/
async function buildAllAgents(projectDir, force = false) {
async function buildAllAgents(projectDir) {
let builtCount = 0;
let skippedCount = 0;
// First, build standalone agents in bmad/agents/
const standaloneAgentsDir = path.join(projectDir, 'bmad', 'agents');
@ -193,16 +175,6 @@ async function buildAllAgents(projectDir, force = false) {
const agentName = path.basename(agentFile, '.agent.yaml');
const outputPath = path.join(agentDir, `${agentName}.md`);
// Check if rebuild needed
if (!force && (await fs.pathExists(outputPath))) {
const needsRebuild = await checkIfNeedsRebuild(agentYamlPath, outputPath, projectDir, agentName);
if (!needsRebuild) {
console.log(chalk.dim(` ${agentName}: up to date`));
skippedCount++;
continue;
}
}
console.log(chalk.cyan(` Building standalone agent ${agentName}...`));
const customizePath = path.join(projectDir, 'bmad', '_cfg', 'agents', `${agentName}.customize.yaml`);
@ -239,16 +211,6 @@ async function buildAllAgents(projectDir, force = false) {
const agentYamlPath = path.join(agentsDir, file);
const outputPath = path.join(agentsDir, `${agentName}.md`);
// Check if rebuild needed
if (!force && (await fs.pathExists(outputPath))) {
const needsRebuild = await checkIfNeedsRebuild(agentYamlPath, outputPath, projectDir, agentName);
if (!needsRebuild) {
console.log(chalk.dim(` ${agentName}: up to date`));
skippedCount++;
continue;
}
}
console.log(chalk.cyan(` Building ${agentName}...`));
const customizePath = path.join(projectDir, '.claude', '_cfg', 'agents', `${agentName}.customize.yaml`);
@ -263,143 +225,6 @@ async function buildAllAgents(projectDir, force = false) {
}
console.log(chalk.green(`\n✓ Built ${builtCount} agent(s)`));
if (skippedCount > 0) {
console.log(chalk.dim(` Skipped ${skippedCount} (already up to date)`));
}
}
/**
* Check what needs rebuilding
*/
async function checkBuildStatus(projectDir) {
const needsRebuild = [];
const upToDate = [];
// Check standalone agents in bmad/agents/
const standaloneAgentsDir = path.join(projectDir, 'bmad', 'agents');
if (await fs.pathExists(standaloneAgentsDir)) {
const agentDirs = await fs.readdir(standaloneAgentsDir);
for (const agentDirName of agentDirs) {
const agentDir = path.join(standaloneAgentsDir, agentDirName);
// Skip if not a directory
const stat = await fs.stat(agentDir);
if (!stat.isDirectory()) {
continue;
}
// Find any .agent.yaml file in the directory
const files = await fs.readdir(agentDir);
const agentFile = files.find((f) => f.endsWith('.agent.yaml'));
if (!agentFile) {
continue;
}
const agentYamlPath = path.join(agentDir, agentFile);
const agentName = path.basename(agentFile, '.agent.yaml');
const outputPath = path.join(agentDir, `${agentName}.md`);
if (!(await fs.pathExists(outputPath))) {
needsRebuild.push(`${agentName} (standalone)`);
} else if (await checkIfNeedsRebuild(agentYamlPath, outputPath, projectDir, agentName)) {
needsRebuild.push(`${agentName} (standalone)`);
} else {
upToDate.push(`${agentName} (standalone)`);
}
}
}
// Check module agents in .claude/commands/bmad/
const bmadCommandsDir = path.join(projectDir, '.claude', 'commands', 'bmad');
if (await fs.pathExists(bmadCommandsDir)) {
const modules = await fs.readdir(bmadCommandsDir);
for (const module of modules) {
const agentsDir = path.join(bmadCommandsDir, module, 'agents');
if (!(await fs.pathExists(agentsDir))) {
continue;
}
const files = await fs.readdir(agentsDir);
for (const file of files) {
if (!file.endsWith('.agent.yaml')) {
continue;
}
const agentName = file.replace('.agent.yaml', '');
const agentYamlPath = path.join(agentsDir, file);
const outputPath = path.join(agentsDir, `${agentName}.md`);
if (!(await fs.pathExists(outputPath))) {
needsRebuild.push(`${agentName} (${module})`);
} else if (await checkIfNeedsRebuild(agentYamlPath, outputPath, projectDir, agentName)) {
needsRebuild.push(`${agentName} (${module})`);
} else {
upToDate.push(`${agentName} (${module})`);
}
}
}
}
if (needsRebuild.length === 0) {
console.log(chalk.green('✓ All agents are up to date'));
} else {
console.log(chalk.yellow(`${needsRebuild.length} agent(s) need rebuilding:`));
for (const agent of needsRebuild) {
console.log(chalk.dim(` - ${agent}`));
}
console.log(chalk.dim('\nRun "bmad build --all" to rebuild all agents'));
}
if (upToDate.length > 0) {
console.log(chalk.dim(`\n${upToDate.length} agent(s) up to date`));
}
}
/**
* Check if an agent needs rebuilding by comparing hashes
*/
async function checkIfNeedsRebuild(yamlPath, outputPath, projectDir, agentName) {
// Read the output file to check its metadata
const outputContent = await fs.readFile(outputPath, 'utf8');
// Extract hash from BUILD-META comment
const metaMatch = outputContent.match(/source:.*\(hash: ([a-f0-9]+)\)/);
if (!metaMatch) {
// No metadata, needs rebuild
return true;
}
const storedHash = metaMatch[1];
// Calculate current hash
const currentHash = await builder.calculateFileHash(yamlPath);
if (storedHash !== currentHash) {
return true;
}
// Check customize file if it exists
const customizePath = path.join(projectDir, '.claude', '_cfg', 'agents', `${agentName}.customize.yaml`);
if (await fs.pathExists(customizePath)) {
const customizeMetaMatch = outputContent.match(/customize:.*\(hash: ([a-f0-9]+)\)/);
if (!customizeMetaMatch) {
return true;
}
const storedCustomizeHash = customizeMetaMatch[1];
const currentCustomizeHash = await builder.calculateFileHash(customizePath);
if (storedCustomizeHash !== currentCustomizeHash) {
return true;
}
}
return false;
}
/**

View File

@ -232,21 +232,6 @@ class YamlXmlBuilder {
return xml;
}
/**
* Build metadata comment
*/
buildMetadataComment(metadata) {
const lines = ['<!-- BUILD-META', ` source: ${metadata.sourceFile || 'unknown'} (hash: ${metadata.sourceHash || 'unknown'})`];
if (metadata.customizeFile) {
lines.push(` customize: ${metadata.customizeFile} (hash: ${metadata.customizeHash || 'unknown'})`);
}
lines.push(` built: ${new Date().toISOString()}`, ` builder-version: ${metadata.builderVersion || '1.0.0'}`, '-->\n');
return lines.join('\n');
}
/**
* Build persona XML section
*/