From cf993b2eaafba2216002d8f6b5de4d295877c944 Mon Sep 17 00:00:00 2001 From: Lucas 'Paperboy' Rose-Winters Date: Thu, 6 Nov 2025 22:52:02 +1100 Subject: [PATCH] debug: add comprehensive logging to skills parser Add detailed console logging to trace how skills are being parsed and categorized. This will help diagnose why skills are ending up in "Uncategorized" instead of their proper categories. Debug logs added: - Log all lines extracted from skills section - Log when category headers are detected - Log when category arrays are created - Log when skills are added to categories vs uncategorized - Log ERROR when skill can't be added due to missing category array - Log final skills data structure with category counts Fallback behavior: - If skill can't be added to its category (category array doesn't exist), fall back to uncategorized with ERROR log To see logs: - Enable Debug Mode in RPG Companion settings - Check browser console during AI response parsing - Look for "[RPG Parser]" prefix Related: Skills categorization issue investigation --- src/systems/generation/parser.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/systems/generation/parser.js b/src/systems/generation/parser.js index f61ab4d..75891d3 100644 --- a/src/systems/generation/parser.js +++ b/src/systems/generation/parser.js @@ -174,14 +174,18 @@ function extractSkills(statsText) { // Split into lines and process const lines = skillsSection.split('\n').map(line => line.trim()).filter(line => line); + debugLog('[RPG Parser] Skills section lines:', lines); + let currentCategory = null; for (const line of lines) { // Check if this is a category header (ends with colon, no dash) if (line.endsWith(':') && !line.startsWith('-')) { currentCategory = line.slice(0, -1).trim(); + debugLog(`[RPG Parser] Found category header: "${currentCategory}"`); if (currentCategory !== 'Uncategorized' && !skillsData.categories[currentCategory]) { skillsData.categories[currentCategory] = []; + debugLog(`[RPG Parser] Created category array for: "${currentCategory}"`); } continue; } @@ -201,9 +205,15 @@ function extractSkills(statsText) { }; if (currentCategory === 'Uncategorized' || currentCategory === null) { + debugLog(`[RPG Parser] Adding "${skillName}" to uncategorized (currentCategory="${currentCategory}")`); skillsData.uncategorized.push(skill); } else if (currentCategory && skillsData.categories[currentCategory]) { + debugLog(`[RPG Parser] Adding "${skillName}" to category "${currentCategory}"`); skillsData.categories[currentCategory].push(skill); + } else { + debugLog(`[RPG Parser] ERROR: Could not add "${skillName}" - currentCategory="${currentCategory}", categoryExists=${!!skillsData.categories[currentCategory]}`); + // Fallback to uncategorized if category doesn't exist + skillsData.uncategorized.push(skill); } } else { // Fallback: Try text-based proficiency format: "- Skill Name (Proficient)" @@ -239,9 +249,15 @@ function extractSkills(statsText) { }; if (currentCategory === 'Uncategorized' || currentCategory === null) { + debugLog(`[RPG Parser] Adding "${skillName}" to uncategorized (currentCategory="${currentCategory}")`); skillsData.uncategorized.push(skill); } else if (currentCategory && skillsData.categories[currentCategory]) { + debugLog(`[RPG Parser] Adding "${skillName}" to category "${currentCategory}"`); skillsData.categories[currentCategory].push(skill); + } else { + debugLog(`[RPG Parser] ERROR: Could not add "${skillName}" - currentCategory="${currentCategory}", categoryExists=${!!skillsData.categories[currentCategory]}`); + // Fallback to uncategorized if category doesn't exist + skillsData.uncategorized.push(skill); } } } @@ -252,6 +268,12 @@ function extractSkills(statsText) { return null; } + debugLog('[RPG Parser] Final skills data:', { + categories: Object.keys(skillsData.categories), + categoryCounts: Object.entries(skillsData.categories).map(([cat, skills]) => `${cat}: ${skills.length}`), + uncategorizedCount: skillsData.uncategorized.length + }); + return skillsData; }