bmad-method 6.3.1-next.3 → 6.3.1-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,117 +107,6 @@ class Manifest {
107
107
  return null;
108
108
  }
109
109
 
110
- /**
111
- * Update existing manifest
112
- * @param {string} bmadDir - Path to bmad directory
113
- * @param {Object} updates - Fields to update
114
- * @param {Array} installedFiles - Updated list of installed files
115
- */
116
- async update(bmadDir, updates, installedFiles = null) {
117
- const yaml = require('yaml');
118
- const manifest = (await this._readRaw(bmadDir)) || {
119
- installation: {},
120
- modules: [],
121
- ides: [],
122
- };
123
-
124
- // Handle module updates
125
- if (updates.modules) {
126
- // If modules is being updated, we need to preserve detailed module info
127
- const existingDetailed = manifest.modules || [];
128
- const incomingNames = updates.modules;
129
-
130
- // Build updated modules array
131
- const updatedModules = [];
132
- for (const name of incomingNames) {
133
- const existing = existingDetailed.find((m) => m.name === name);
134
- if (existing) {
135
- // Preserve existing details, update lastUpdated if this module is being updated
136
- updatedModules.push({
137
- ...existing,
138
- lastUpdated: new Date().toISOString(),
139
- });
140
- } else {
141
- // New module - add with minimal details
142
- updatedModules.push({
143
- name,
144
- version: null,
145
- installDate: new Date().toISOString(),
146
- lastUpdated: new Date().toISOString(),
147
- source: 'unknown',
148
- });
149
- }
150
- }
151
-
152
- manifest.modules = updatedModules;
153
- }
154
-
155
- // Merge other updates
156
- if (updates.version) {
157
- manifest.installation.version = updates.version;
158
- }
159
- if (updates.installDate) {
160
- manifest.installation.installDate = updates.installDate;
161
- }
162
- manifest.installation.lastUpdated = new Date().toISOString();
163
-
164
- if (updates.ides) {
165
- manifest.ides = updates.ides;
166
- }
167
-
168
- // Handle per-module version updates
169
- if (updates.moduleVersions) {
170
- for (const [moduleName, versionInfo] of Object.entries(updates.moduleVersions)) {
171
- const moduleIndex = manifest.modules.findIndex((m) => m.name === moduleName);
172
- if (moduleIndex !== -1) {
173
- manifest.modules[moduleIndex] = {
174
- ...manifest.modules[moduleIndex],
175
- ...versionInfo,
176
- lastUpdated: new Date().toISOString(),
177
- };
178
- }
179
- }
180
- }
181
-
182
- // Handle adding a new module with version info
183
- if (updates.addModule) {
184
- const { name, version, source, npmPackage, repoUrl, localPath } = updates.addModule;
185
- const existing = manifest.modules.find((m) => m.name === name);
186
- if (!existing) {
187
- const entry = {
188
- name,
189
- version: version || null,
190
- installDate: new Date().toISOString(),
191
- lastUpdated: new Date().toISOString(),
192
- source: source || 'external',
193
- npmPackage: npmPackage || null,
194
- repoUrl: repoUrl || null,
195
- };
196
- if (localPath) entry.localPath = localPath;
197
- manifest.modules.push(entry);
198
- }
199
- }
200
-
201
- const manifestPath = path.join(bmadDir, '_config', 'manifest.yaml');
202
- await fs.ensureDir(path.dirname(manifestPath));
203
-
204
- // Clean the manifest data to remove any non-serializable values
205
- const cleanManifestData = structuredClone(manifest);
206
-
207
- const yamlContent = yaml.stringify(cleanManifestData, {
208
- indent: 2,
209
- lineWidth: 0,
210
- sortKeys: false,
211
- });
212
-
213
- // Ensure POSIX-compliant final newline
214
- const content = yamlContent.endsWith('\n') ? yamlContent : yamlContent + '\n';
215
- await fs.writeFile(manifestPath, content, 'utf8');
216
-
217
- // Return the flattened format for compatibility
218
- return this._flattenManifest(manifest);
219
- }
220
-
221
110
  /**
222
111
  * Read raw manifest data without flattening
223
112
  * @param {string} bmadDir - Path to bmad directory
@@ -310,62 +199,6 @@ class Manifest {
310
199
  await this._writeRaw(bmadDir, manifest);
311
200
  }
312
201
 
313
- /**
314
- * Remove a module from the manifest
315
- * @param {string} bmadDir - Path to bmad directory
316
- * @param {string} moduleName - Module name to remove
317
- */
318
- async removeModule(bmadDir, moduleName) {
319
- const manifest = await this._readRaw(bmadDir);
320
- if (!manifest || !manifest.modules) {
321
- return;
322
- }
323
-
324
- const index = manifest.modules.findIndex((m) => m.name === moduleName);
325
- if (index !== -1) {
326
- manifest.modules.splice(index, 1);
327
- await this._writeRaw(bmadDir, manifest);
328
- }
329
- }
330
-
331
- /**
332
- * Update a single module's version info
333
- * @param {string} bmadDir - Path to bmad directory
334
- * @param {string} moduleName - Module name
335
- * @param {Object} versionInfo - Version info to update
336
- */
337
- async updateModuleVersion(bmadDir, moduleName, versionInfo) {
338
- const manifest = await this._readRaw(bmadDir);
339
- if (!manifest || !manifest.modules) {
340
- return;
341
- }
342
-
343
- const index = manifest.modules.findIndex((m) => m.name === moduleName);
344
- if (index !== -1) {
345
- manifest.modules[index] = {
346
- ...manifest.modules[index],
347
- ...versionInfo,
348
- lastUpdated: new Date().toISOString(),
349
- };
350
- await this._writeRaw(bmadDir, manifest);
351
- }
352
- }
353
-
354
- /**
355
- * Get version info for a specific module
356
- * @param {string} bmadDir - Path to bmad directory
357
- * @param {string} moduleName - Module name
358
- * @returns {Object|null} Module version info or null
359
- */
360
- async getModuleVersion(bmadDir, moduleName) {
361
- const manifest = await this._readRaw(bmadDir);
362
- if (!manifest || !manifest.modules) {
363
- return null;
364
- }
365
-
366
- return manifest.modules.find((m) => m.name === moduleName) || null;
367
- }
368
-
369
202
  /**
370
203
  * Get all modules with their version info
371
204
  * @param {string} bmadDir - Path to bmad directory
@@ -403,27 +236,6 @@ class Manifest {
403
236
  await fs.writeFile(manifestPath, content, 'utf8');
404
237
  }
405
238
 
406
- /**
407
- * Add an IDE configuration to the manifest
408
- * @param {string} bmadDir - Path to bmad directory
409
- * @param {string} ideName - IDE name to add
410
- */
411
- async addIde(bmadDir, ideName) {
412
- const manifest = await this.read(bmadDir);
413
- if (!manifest) {
414
- throw new Error('No manifest found');
415
- }
416
-
417
- if (!manifest.ides) {
418
- manifest.ides = [];
419
- }
420
-
421
- if (!manifest.ides.includes(ideName)) {
422
- manifest.ides.push(ideName);
423
- await this.update(bmadDir, { ides: manifest.ides });
424
- }
425
- }
426
-
427
239
  /**
428
240
  * Calculate SHA256 hash of a file
429
241
  * @param {string} filePath - Path to file
@@ -438,354 +250,6 @@ class Manifest {
438
250
  }
439
251
  }
440
252
 
441
- /**
442
- * Parse installed files to extract metadata
443
- * @param {Array} installedFiles - List of installed file paths
444
- * @param {string} bmadDir - Path to bmad directory for relative paths
445
- * @returns {Array} Array of file metadata objects
446
- */
447
- async parseInstalledFiles(installedFiles, bmadDir) {
448
- const fileMetadata = [];
449
-
450
- for (const filePath of installedFiles) {
451
- const fileExt = path.extname(filePath).toLowerCase();
452
- // Make path relative to parent of bmad directory, starting with 'bmad/'
453
- const relativePath = 'bmad' + filePath.replace(bmadDir, '').replaceAll('\\', '/');
454
-
455
- // Calculate file hash
456
- const hash = await this.calculateFileHash(filePath);
457
-
458
- // Handle markdown files - extract XML metadata if present
459
- if (fileExt === '.md') {
460
- try {
461
- if (await fs.pathExists(filePath)) {
462
- const content = await fs.readFile(filePath, 'utf8');
463
- const metadata = this.extractXmlNodeAttributes(content, filePath, relativePath);
464
-
465
- if (metadata) {
466
- // Has XML metadata
467
- metadata.hash = hash;
468
- fileMetadata.push(metadata);
469
- } else {
470
- // No XML metadata - still track the file
471
- fileMetadata.push({
472
- file: relativePath,
473
- type: 'md',
474
- name: path.basename(filePath, fileExt),
475
- title: null,
476
- hash: hash,
477
- });
478
- }
479
- }
480
- } catch (error) {
481
- await prompts.log.warn(`Could not parse ${filePath}: ${error.message}`);
482
- }
483
- }
484
- // Handle other file types (CSV, JSON, YAML, etc.)
485
- else {
486
- fileMetadata.push({
487
- file: relativePath,
488
- type: fileExt.slice(1), // Remove the dot
489
- name: path.basename(filePath, fileExt),
490
- title: null,
491
- hash: hash,
492
- });
493
- }
494
- }
495
-
496
- return fileMetadata;
497
- }
498
-
499
- /**
500
- * Extract XML node attributes from MD file content
501
- * @param {string} content - File content
502
- * @param {string} filePath - File path for context
503
- * @param {string} relativePath - Relative path starting with 'bmad/'
504
- * @returns {Object|null} Extracted metadata or null
505
- */
506
- extractXmlNodeAttributes(content, filePath, relativePath) {
507
- // Look for XML blocks in code fences
508
- const xmlBlockMatch = content.match(/```xml\s*([\s\S]*?)```/);
509
- if (!xmlBlockMatch) {
510
- return null;
511
- }
512
-
513
- const xmlContent = xmlBlockMatch[1];
514
-
515
- // Extract root XML node (agent, task, template, etc.)
516
- const rootNodeMatch = xmlContent.match(/<(\w+)([^>]*)>/);
517
- if (!rootNodeMatch) {
518
- return null;
519
- }
520
-
521
- const nodeType = rootNodeMatch[1];
522
- const attributes = rootNodeMatch[2];
523
-
524
- // Extract name and title attributes (id not needed since we have path)
525
- const nameMatch = attributes.match(/name="([^"]*)"/);
526
- const titleMatch = attributes.match(/title="([^"]*)"/);
527
-
528
- return {
529
- file: relativePath,
530
- type: nodeType,
531
- name: nameMatch ? nameMatch[1] : null,
532
- title: titleMatch ? titleMatch[1] : null,
533
- };
534
- }
535
-
536
- /**
537
- * Generate CSV manifest content
538
- * @param {Object} data - Manifest data
539
- * @param {Array} fileMetadata - File metadata array
540
- * @param {Object} moduleConfigs - Module configuration data
541
- * @returns {string} CSV content
542
- */
543
- generateManifestCsv(data, fileMetadata, moduleConfigs = {}) {
544
- const timestamp = new Date().toISOString();
545
- let csv = [];
546
-
547
- // Header section
548
- csv.push(
549
- '# BMAD Manifest',
550
- `# Generated: ${timestamp}`,
551
- '',
552
- '## Installation Info',
553
- 'Property,Value',
554
- `Version,${data.version}`,
555
- `InstallDate,${data.installDate || timestamp}`,
556
- `LastUpdated,${data.lastUpdated || timestamp}`,
557
- );
558
- if (data.language) {
559
- csv.push(`Language,${data.language}`);
560
- }
561
- csv.push('');
562
-
563
- // Modules section
564
- if (data.modules && data.modules.length > 0) {
565
- csv.push('## Modules', 'Name,Version,ShortTitle');
566
- for (const moduleName of data.modules) {
567
- const config = moduleConfigs[moduleName] || {};
568
- csv.push([moduleName, config.version || '', config['short-title'] || ''].map((v) => this.escapeCsv(v)).join(','));
569
- }
570
- csv.push('');
571
- }
572
-
573
- // IDEs section
574
- if (data.ides && data.ides.length > 0) {
575
- csv.push('## IDEs', 'IDE');
576
- for (const ide of data.ides) {
577
- csv.push(this.escapeCsv(ide));
578
- }
579
- csv.push('');
580
- }
581
-
582
- // Files section - NO LONGER USED
583
- // Files are now tracked in files-manifest.csv by ManifestGenerator
584
-
585
- return csv.join('\n');
586
- }
587
-
588
- /**
589
- * Parse CSV manifest content back to object
590
- * @param {string} csvContent - CSV content to parse
591
- * @returns {Object} Parsed manifest data
592
- */
593
- parseManifestCsv(csvContent) {
594
- const result = {
595
- modules: [],
596
- ides: [],
597
- files: [],
598
- };
599
-
600
- const lines = csvContent.split('\n');
601
- let section = '';
602
-
603
- for (const line_ of lines) {
604
- const line = line_.trim();
605
-
606
- // Skip empty lines and comments
607
- if (!line || line.startsWith('#')) {
608
- // Check for section headers
609
- if (line.startsWith('## ')) {
610
- section = line.slice(3).toLowerCase();
611
- }
612
- continue;
613
- }
614
-
615
- // Parse based on current section
616
- switch (section) {
617
- case 'installation info': {
618
- // Skip header row
619
- if (line === 'Property,Value') continue;
620
-
621
- const [property, ...valueParts] = line.split(',');
622
- const value = this.unescapeCsv(valueParts.join(','));
623
-
624
- switch (property) {
625
- // Path no longer stored in manifest
626
- case 'Version': {
627
- result.version = value;
628
- break;
629
- }
630
- case 'InstallDate': {
631
- result.installDate = value;
632
- break;
633
- }
634
- case 'LastUpdated': {
635
- result.lastUpdated = value;
636
- break;
637
- }
638
- case 'Language': {
639
- result.language = value;
640
- break;
641
- }
642
- }
643
-
644
- break;
645
- }
646
- case 'modules': {
647
- // Skip header row
648
- if (line === 'Name,Version,ShortTitle') continue;
649
-
650
- const parts = this.parseCsvLine(line);
651
- if (parts[0]) {
652
- result.modules.push(parts[0]);
653
- }
654
-
655
- break;
656
- }
657
- case 'ides': {
658
- // Skip header row
659
- if (line === 'IDE') continue;
660
-
661
- result.ides.push(this.unescapeCsv(line));
662
-
663
- break;
664
- }
665
- case 'files': {
666
- // Skip header rows (support both old and new format)
667
- if (line === 'Type,Path,Name,Title' || line === 'Type,Path,Name,Title,Hash') continue;
668
-
669
- const parts = this.parseCsvLine(line);
670
- if (parts.length >= 2) {
671
- result.files.push({
672
- type: parts[0] || '',
673
- file: parts[1] || '',
674
- name: parts[2] || null,
675
- title: parts[3] || null,
676
- hash: parts[4] || null, // Hash column (may not exist in old manifests)
677
- });
678
- }
679
-
680
- break;
681
- }
682
- // No default
683
- }
684
- }
685
-
686
- return result;
687
- }
688
-
689
- /**
690
- * Parse a CSV line handling quotes and commas
691
- * @param {string} line - CSV line to parse
692
- * @returns {Array} Array of values
693
- */
694
- parseCsvLine(line) {
695
- const result = [];
696
- let current = '';
697
- let inQuotes = false;
698
-
699
- for (let i = 0; i < line.length; i++) {
700
- const char = line[i];
701
-
702
- if (char === '"') {
703
- if (inQuotes && line[i + 1] === '"') {
704
- // Escaped quote
705
- current += '"';
706
- i++;
707
- } else {
708
- // Toggle quote state
709
- inQuotes = !inQuotes;
710
- }
711
- } else if (char === ',' && !inQuotes) {
712
- // Field separator
713
- result.push(this.unescapeCsv(current));
714
- current = '';
715
- } else {
716
- current += char;
717
- }
718
- }
719
-
720
- // Add the last field
721
- result.push(this.unescapeCsv(current));
722
-
723
- return result;
724
- }
725
-
726
- /**
727
- * Escape CSV special characters
728
- * @param {string} text - Text to escape
729
- * @returns {string} Escaped text
730
- */
731
- escapeCsv(text) {
732
- if (!text) return '';
733
- const str = String(text);
734
-
735
- // If contains comma, newline, or quote, wrap in quotes and escape quotes
736
- if (str.includes(',') || str.includes('\n') || str.includes('"')) {
737
- return '"' + str.replaceAll('"', '""') + '"';
738
- }
739
-
740
- return str;
741
- }
742
-
743
- /**
744
- * Unescape CSV field
745
- * @param {string} text - Text to unescape
746
- * @returns {string} Unescaped text
747
- */
748
- unescapeCsv(text) {
749
- if (!text) return '';
750
-
751
- // Remove surrounding quotes if present
752
- if (text.startsWith('"') && text.endsWith('"')) {
753
- text = text.slice(1, -1);
754
- // Unescape doubled quotes
755
- text = text.replaceAll('""', '"');
756
- }
757
-
758
- return text;
759
- }
760
-
761
- /**
762
- * Load module configuration files
763
- * @param {Array} modules - List of module names
764
- * @returns {Object} Module configurations indexed by name
765
- */
766
- async loadModuleConfigs(modules) {
767
- const configs = {};
768
-
769
- for (const moduleName of modules) {
770
- // Handle core module differently - it's in src/core-skills not src/modules/core
771
- const configPath =
772
- moduleName === 'core'
773
- ? path.join(process.cwd(), 'src', 'core-skills', 'config.yaml')
774
- : path.join(process.cwd(), 'src', 'modules', moduleName, 'config.yaml');
775
-
776
- try {
777
- if (await fs.pathExists(configPath)) {
778
- const yaml = require('yaml');
779
- const content = await fs.readFile(configPath, 'utf8');
780
- configs[moduleName] = yaml.parse(content);
781
- }
782
- } catch (error) {
783
- await prompts.log.warn(`Could not load config for module ${moduleName}: ${error.message}`);
784
- }
785
- }
786
-
787
- return configs;
788
- }
789
253
  /**
790
254
  * Get module version info from source
791
255
  * @param {string} moduleName - Module name/code
@@ -986,47 +450,6 @@ class Manifest {
986
450
 
987
451
  return updates;
988
452
  }
989
-
990
- /**
991
- * Compare two semantic versions
992
- * @param {string} v1 - First version
993
- * @param {string} v2 - Second version
994
- * @returns {number} -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2
995
- */
996
- compareVersions(v1, v2) {
997
- if (!v1 || !v2) return 0;
998
-
999
- const normalize = (v) => {
1000
- // Remove leading 'v' if present
1001
- v = v.replace(/^v/, '');
1002
- // Handle prerelease tags
1003
- const parts = v.split('-');
1004
- const main = parts[0].split('.');
1005
- const prerelease = parts[1];
1006
- return { main, prerelease };
1007
- };
1008
-
1009
- const n1 = normalize(v1);
1010
- const n2 = normalize(v2);
1011
-
1012
- // Compare main version parts
1013
- for (let i = 0; i < 3; i++) {
1014
- const num1 = parseInt(n1.main[i] || '0', 10);
1015
- const num2 = parseInt(n2.main[i] || '0', 10);
1016
- if (num1 !== num2) {
1017
- return num1 < num2 ? -1 : 1;
1018
- }
1019
- }
1020
-
1021
- // If main versions are equal, compare prerelease
1022
- if (n1.prerelease && n2.prerelease) {
1023
- return n1.prerelease < n2.prerelease ? -1 : n1.prerelease > n2.prerelease ? 1 : 0;
1024
- }
1025
- if (n1.prerelease) return -1; // Prerelease is older than stable
1026
- if (n2.prerelease) return 1; // Stable is newer than prerelease
1027
-
1028
- return 0;
1029
- }
1030
453
  }
1031
454
 
1032
455
  module.exports = { Manifest };