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
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-11-06 22:52:02 +11:00
parent fe5abb47ba
commit cf993b2eaa
+22
View File
@@ -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;
}