#!/usr/bin/env node /** * Debug script to test expansion pack detection in installer */ const installer = require('./tools/installer/lib/installer'); const path = require('path'); const fs = require('fs').promises; const yaml = require('js-yaml'); async function debugExpansionDetection() { try { console.log('=== Debug: Expansion Pack Detection ===\n'); // Test 1: Direct resource locator expansion pack detection console.log('1. Testing resource locator getExpansionPacks():'); const expansionPacks = await installer.getAvailableExpansionPacks(); console.log(` Found ${expansionPacks.length} expansion packs:`); for (const pack of expansionPacks) { console.log(` - ${pack.id}: ${pack.name} v${pack.version}`); console.log(` Short title: ${pack.shortTitle}`); console.log(` Path: ${pack.path}`); console.log(''); } // Test 2: Test installation state detection (simulating what happens in promptInstallation) console.log('2. Testing installation state detection for test directory:'); const testDir = path.resolve('./test-install'); const state = await installer.detectInstallationState(testDir); console.log(` State type: ${state.type}`); console.log(` Existing expansion packs: ${Object.keys(state.expansionPacks || {}).length}`); // Test 3: Simulate the choices building logic from bmad.js lines 156-204 console.log('3. Simulating installer choices building logic:'); // Load core config to get short-title const coreConfigPath = path.join(__dirname, 'bmad-core', 'core-config.yaml'); const coreConfig = yaml.load(await fs.readFile(coreConfigPath, 'utf8')); const coreShortTitle = coreConfig['short-title'] || 'BMad Agile Core System'; const version = require('./package.json').version; const choices = []; // Add BMad core option const bmadOptionText = `${coreShortTitle} (v${version}) .bmad-core`; choices.push({ name: bmadOptionText, value: 'bmad-core', checked: true }); // Add expansion pack options for (const pack of expansionPacks) { const packOptionText = `${pack.shortTitle} (v${pack.version}) .${pack.id}`; choices.push({ name: packOptionText, value: pack.id, checked: false }); } console.log(' Installer menu choices that would be shown:'); for (const choice of choices) { const checkmark = choice.checked ? '☑' : '☐'; console.log(` ${checkmark} ${choice.name}`); } console.log('\n=== Summary ==='); console.log(`✅ Expansion pack detection: WORKING`); console.log(`✅ Resource locator: WORKING`); console.log(`✅ Installer menu building: WORKING`); console.log(`\nThe installer SHOULD be showing expansion pack options.`); console.log(`If they're not appearing, the issue might be:`) console.log(`- User running an old cached version`); console.log(`- Running from wrong directory`); console.log(`- Environmental/terminal display issues`); } catch (error) { console.error('❌ Error during debug:', error.message); console.error(error.stack); } } debugExpansionDetection();