fix: centralized yamlExtraction function and all now fix character issues for windows

This commit is contained in:
Brian Madison
2025-07-02 21:08:43 -05:00
parent 405954ad92
commit e2985d6093
27 changed files with 74 additions and 78240 deletions

View File

@@ -1,6 +1,7 @@
const fs = require('fs').promises;
const path = require('path');
const yaml = require('js-yaml');
const { extractYamlFromAgent } = require('./yaml-utils');
class DependencyResolver {
constructor(rootDir) {
@@ -14,17 +15,12 @@ class DependencyResolver {
const agentPath = path.join(this.bmadCore, 'agents', `${agentId}.md`);
const agentContent = await fs.readFile(agentPath, 'utf8');
// Extract YAML from markdown content
const yamlMatch = agentContent.replace(/\r/g, "").match(/```ya?ml\n([\s\S]*?)\n```/);
if (!yamlMatch) {
// Extract YAML from markdown content with command cleaning
const yamlContent = extractYamlFromAgent(agentContent, true);
if (!yamlContent) {
throw new Error(`No YAML configuration found in agent ${agentId}`);
}
// Clean up the YAML to handle command descriptions after dashes
let yamlContent = yamlMatch[1];
// Fix commands section: convert "- command - description" to just "- command"
yamlContent = yamlContent.replace(/^(\s*-)(\s*"[^"]+")(\s*-\s*.*)$/gm, '$1$2');
const agentConfig = yaml.load(yamlContent);
const dependencies = {

29
tools/lib/yaml-utils.js Normal file
View File

@@ -0,0 +1,29 @@
/**
* Utility functions for YAML extraction from agent files
*/
/**
* Extract YAML content from agent markdown files
* @param {string} agentContent - The full content of the agent file
* @param {boolean} cleanCommands - Whether to clean command descriptions (default: false)
* @returns {string|null} - The extracted YAML content or null if not found
*/
function extractYamlFromAgent(agentContent, cleanCommands = false) {
// Remove carriage returns and match YAML block
const yamlMatch = agentContent.replace(/\r/g, "").match(/```ya?ml\n([\s\S]*?)\n```/);
if (!yamlMatch) return null;
let yamlContent = yamlMatch[1].trim();
// Clean up command descriptions if requested
// Converts "- command - description" to just "- command"
if (cleanCommands) {
yamlContent = yamlContent.replace(/^(\s*-)(\s*"[^"]+")(\s*-\s*.*)$/gm, '$1$2');
}
return yamlContent;
}
module.exports = {
extractYamlFromAgent
};