const xml2js = require('xml2js'); const fs = require('fs-extra'); const path = require('node:path'); const { getProjectRoot, getSourcePath } = require('./project-root'); const { YamlXmlBuilder } = require('./yaml-xml-builder'); /** * XML utility functions for BMAD installer * Now supports both legacy XML agents and new YAML-based agents */ class XmlHandler { constructor() { this.parser = new xml2js.Parser({ preserveChildrenOrder: true, explicitChildren: true, explicitArray: false, trim: false, normalizeTags: false, attrkey: '$', charkey: '_', }); this.builder = new xml2js.Builder({ renderOpts: { pretty: true, indent: ' ', newline: '\n', }, xmldec: { version: '1.0', encoding: 'utf8', standalone: false, }, headless: true, // Don't add XML declaration attrkey: '$', charkey: '_', }); this.yamlBuilder = new YamlXmlBuilder(); } /** * Load and parse the activation template * @returns {Object} Parsed activation block */ async loadActivationTemplate() { console.error('Failed to load activation template:', error); } /** * Inject activation block into agent XML content * @param {string} agentContent - The agent file content * @param {Object} metadata - Metadata containing module and name * @returns {string} Modified content with activation block */ async injectActivation(agentContent, metadata = {}) { try { // Check if already has activation if (agentContent.includes(' { if (line.trim() === '') return line; if (line.startsWith('