From 83eee20b2c36deee7cfe1e21a94d7f3a39ac6fcb Mon Sep 17 00:00:00 2001 From: keligrubb Date: Sat, 21 Feb 2026 22:19:21 -0500 Subject: [PATCH] add testing suite --- .gitignore | 6 +- README.md | 13 + dungeonGenerator.js | 1186 -------- eslint.config.js | 23 +- index.js | 8 +- package-lock.json | 2444 +++++++++++++++-- package.json | 14 +- src/contentFixes.js | 290 ++ src/dungeonBuild.js | 106 + src/dungeonGenerator.js | 323 +++ dungeonTemplate.js => src/dungeonTemplate.js | 154 +- generatePDF.js => src/generatePDF.js | 0 imageGenerator.js => src/imageGenerator.js | 0 ollamaClient.js => src/ollamaClient.js | 36 +- src/parsing.js | 234 ++ src/textUtils.js | 10 + src/validation.js | 120 + test/integration.test.js | 91 - test/integration/dungeonGeneration.test.js | 92 + .../dungeonGenerator.generateDungeon.test.js | 178 ++ test/unit/dungeonGenerator.test.js | 1088 ++++++++ test/unit/dungeonTemplate.test.js | 227 ++ test/unit/ollamaClient.test.js | 263 ++ vitest.config.js | 29 + vitest.integration.config.js | 10 + 25 files changed, 5317 insertions(+), 1628 deletions(-) delete mode 100644 dungeonGenerator.js create mode 100644 src/contentFixes.js create mode 100644 src/dungeonBuild.js create mode 100644 src/dungeonGenerator.js rename dungeonTemplate.js => src/dungeonTemplate.js (66%) rename generatePDF.js => src/generatePDF.js (100%) rename imageGenerator.js => src/imageGenerator.js (100%) rename ollamaClient.js => src/ollamaClient.js (79%) create mode 100644 src/parsing.js create mode 100644 src/textUtils.js create mode 100644 src/validation.js delete mode 100644 test/integration.test.js create mode 100644 test/integration/dungeonGeneration.test.js create mode 100644 test/unit/dungeonGenerator.generateDungeon.test.js create mode 100644 test/unit/dungeonGenerator.test.js create mode 100644 test/unit/dungeonTemplate.test.js create mode 100644 test/unit/ollamaClient.test.js create mode 100644 vitest.config.js create mode 100644 vitest.integration.config.js diff --git a/.gitignore b/.gitignore index 739719a..d1ff82f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ *.pdf *.png .env -node_modules/** +node_modules/ + +# Coverage and test artifacts +coverage/ # macOS dotfiles .DS_Store @@ -11,4 +14,5 @@ node_modules/** .Trashes .AppleDouble .LSOverride + .env.example diff --git a/README.md b/README.md index 055a3f1..eba9503 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,19 @@ Optional: update the map path in `index.js` if you have a local dungeon map. --- +## Project structure + +- **`index.js`** – Entry point: loads env, initializes the Ollama model, runs dungeon generation, image generation, and PDF output. +- **`src/`** – Application modules: + - `dungeonGenerator.js` – LLM-backed dungeon content generation and validation. + - `dungeonTemplate.js` – HTML template and layout for the PDF. + - `ollamaClient.js` – Ollama/Open WebUI API client and text cleaning. + - `imageGenerator.js` – Map image generation (Ollama + optional ComfyUI). + - `generatePDF.js` – Puppeteer-based PDF generation from the template. +- **`test/`** – Unit tests (`test/unit/`) and integration tests (`test/integration/`). + +--- + ## Example Output * `the-tomb-of-shadows.pdf` diff --git a/dungeonGenerator.js b/dungeonGenerator.js deleted file mode 100644 index c0dec7e..0000000 --- a/dungeonGenerator.js +++ /dev/null @@ -1,1186 +0,0 @@ -import { callOllama } from "./ollamaClient.js"; - -// Utility: strip markdown artifacts and clean up extra whitespace -function cleanText(str) { - if (!str) return ""; - return str - .replace(/^#+\s*/gm, "") - .replace(/\*\*(.*?)\*\*/g, "$1") // Removes bolding - .replace(/[*_`]/g, "") // Removes other markdown - .replace(/\s+/g, " ") - .trim(); -} - -function parseList(raw) { - if (!raw) return []; - - // Match all numbered items using a regex that captures the content - // This handles both "1. Title" and "1) Title" formats, and works even if multiple titles are on one line - // The regex captures everything after the number until the next number pattern or end of string - // Using [\s\S] to match any character including newlines, but stop at the next number pattern - const NUMBERED_ITEM_REGEX = /\d+[).]\s+([\s\S]+?)(?=\s*\d+[).]\s+|$)/g; - - const items = Array.from(raw.matchAll(NUMBERED_ITEM_REGEX)) - .map(match => match[1].trim()) - .filter(Boolean) - .map(cleanText) - .filter(Boolean); - - // Fallback: if regex didn't work, try the old method - return items.length > 0 - ? items - : raw - .split(/\n?\d+[).]\s+/) - .map(line => cleanText(line)) - .filter(Boolean); -} - -function parseObjects(raw, type = "rooms") { - const cleanedRaw = raw.replace(/Intermediate Rooms:/i, "").replace(/Climax Room:/i, "").trim(); - const mapper = (entry) => { - if (type === "encounters") { - // For encounters, format is "Encounter Name: Location Name: details" - const parts = entry.split(/:/); - if (parts.length >= 3) { - const name = parts[0].trim(); - // Skip placeholder names - if (name.toLowerCase().includes('location name') || name.toLowerCase().includes('encounter name')) { - return null; - } - return { - name: name, - details: parts.slice(1).join(":").trim() - }; - } else if (parts.length === 2) { - const name = parts[0].trim(); - if (name.toLowerCase().includes('location name') || name.toLowerCase().includes('encounter name')) { - return null; - } - return { - name: name, - details: parts[1].trim() - }; - } - return null; - } - // For other types, use original logic - if (type === "treasure") { - const parts = entry.split(/[—]/); - if (parts.length >= 2) { - const cleanName = parts[0].trim(); - if (cleanName.toLowerCase().includes('treasure name') || cleanName.toLowerCase().includes('actual ')) { - return null; - } - let desc = parts.slice(1).join(' ').trim(); - desc = desc.replace(/^description\s*:?\s*/i, '').trim(); - return { name: cleanName, description: desc }; - } - } - const [name, ...descParts] = entry.split(/[-–—:]/); - const cleanName = name.trim(); - // Skip placeholder names - if (cleanName.toLowerCase().includes('location name') || - cleanName.toLowerCase().includes('npc name') || - cleanName.toLowerCase().includes('treasure name') || - cleanName.toLowerCase().includes('actual ')) { - return null; - } - let desc = descParts.join(" ").trim(); - if (type === "npcs") desc = desc.replace(/^description\s*:?\s*/i, '').trim(); - const obj = { name: cleanName }; - if (type === "rooms") return { ...obj, description: desc }; - if (type === "npcs") return { ...obj, trait: desc }; - if (type === "treasure") return { ...obj, description: desc }; - return null; - }; - return cleanedRaw.split(/\n?\d+[).]\s+/).map(cleanText).filter(Boolean).map(mapper).filter(Boolean); -} - -const parseEncounterText = (text, idx) => { - // Handle "Encounter N Name Room Name Details" format - const encounterMatch = text.match(/Encounter\s+(\d+)\s+(.+?)\s+(?:Room Name|Location)\s+(.+?)\s+Details\s+(.+)/i); - if (encounterMatch) { - const [, , name, location, details] = encounterMatch; - return { name: name.trim(), details: `${location.trim()}: ${details.trim()}` }; - } - // Handle "Encounter N Name: Location: Details" format - const colonFormat = text.match(/Encounter\s+\d+\s+(.+?):\s*(.+?):\s*(.+)/i); - if (colonFormat) { - const [, name, location, details] = colonFormat; - return { name: name.trim(), details: `${location.trim()}: ${details.trim()}` }; - } - const match = text.match(/^(\d+)\s+(.+?)(?::\s*(.+))?$/); - if (match) { - const [, , name, details] = match; - return name && details ? { name: name.trim(), details: details.trim() } : null; - } - const colonSplit = text.split(/[:]/); - if (colonSplit.length > 1) { - return { - name: colonSplit[0].replace(/^\d+\s+|Encounter\s+\d+\s+/i, "").trim(), - details: colonSplit.slice(1).join(":").trim() - }; - } - const nameMatch = text.match(/^\d+\s+([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)/); - if (nameMatch) { - return { - name: nameMatch[1], - details: text.replace(/^\d+\s+[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\s*/, "").trim() - }; - } - return { name: `Encounter ${idx + 1}`, details: text.replace(/^\d+\s+|Encounter\s+\d+\s+/i, "").trim() }; -}; - -const splitCombinedEncounters = (encounters) => { - if (encounters.length === 0) return []; - const shouldSplit = encounters.length === 1 && (encounters[0].name === "1" || encounters[0].details?.match(/\d+\s+[A-Z]/) || encounters[0].details?.includes('Encounter')); - if (!shouldSplit) return encounters; - console.warn("Encounters appear combined, attempting to split..."); - const combinedText = encounters[0].details || ""; - const split = combinedText.split(/(?=Encounter\s+\d+|\d+\s+[A-Z][a-z])/i).filter(Boolean); - return (split.length > 1 || (split.length === 1 && combinedText.length > 100)) - ? split.map((text, idx) => parseEncounterText(text, idx)).filter(e => e?.name && e?.details?.length > 10) - : encounters; -}; - -const splitCombinedNPCs = (npcs) => { - const shouldSplit = npcs.length === 1 && npcs[0].trait?.length > 80; - if (!shouldSplit) return npcs; - console.warn("NPCs appear combined, attempting to split..."); - const split = npcs[0].trait.split(/(?=[A-Z][a-z]+\s+[A-Z][a-z]+\s*:)/).filter(Boolean); - return split.length > 1 - ? split.map(text => { - const [name, ...traitParts] = text.split(/[:]/); - return { name: name.trim(), trait: traitParts.join(":").trim() }; - }).filter(n => n.name && n.trait?.length > 10) - : npcs; -}; - -const parseTreasureText = (text, idx, splitTreasures) => { - if (idx === splitTreasures.length - 1 && text.length < 40) { - return { name: splitTreasures[idx - 1]?.split(/\s+/).slice(-2).join(" ") || `Treasure ${idx}`, description: text }; - } - const dashSplit = text.split(/[—]/); - if (dashSplit.length === 2) return { name: dashSplit[0].trim(), description: dashSplit[1].trim() }; - if (text.length < 30 && /^[A-Z]/.test(text)) return { name: text.trim(), description: "" }; - return null; -}; - -const splitCombinedTreasures = (treasure) => { - const shouldSplit = treasure.length === 1 && treasure[0].description?.length > 60; - if (!shouldSplit) return treasure; - console.warn("Treasures appear combined, attempting to split..."); - const split = treasure[0].description.split(/\s+—\s+/).filter(Boolean); - if (split.length <= 1) return treasure; - const parsed = split.map((text, idx) => parseTreasureText(text, idx, split)).filter(t => t?.name && t?.description); - if (parsed.length > 0) return parsed; - const nameDescPairs = treasure[0].description.match(/([A-Z][^—]+?)\s+—\s+([^—]+?)(?=\s+[A-Z][^—]+\s+—|$)/g); - return nameDescPairs - ? nameDescPairs.map(pair => { - const match = pair.match(/([^—]+)\s+—\s+(.+)/); - return match ? { name: match[1].trim(), description: match[2].trim() } : null; - }).filter(t => t) - : treasure; -}; - -function extractCanonicalNames(dungeonData) { - const names = { - npcs: [], - rooms: [], - factions: [] - }; - - // Extract NPC names - if (dungeonData.npcs) { - dungeonData.npcs.forEach(npc => { - if (npc.name) names.npcs.push(npc.name.trim()); - }); - } - - // Extract room names - if (dungeonData.rooms) { - dungeonData.rooms.forEach(room => { - if (room.name) names.rooms.push(room.name.trim()); - }); - } - - // Extract faction names from core concepts (if available) - if (dungeonData.coreConcepts) { - const factionMatch = dungeonData.coreConcepts.match(/Primary Faction[:\s]+([^.]+)/i); - if (factionMatch) { - names.factions.push(factionMatch[1].trim()); - } - } - - return names; -} - -function validateNameConsistency(dungeonData) { - const canonicalNames = extractCanonicalNames(dungeonData); - const fixes = []; - - // Fix NPC names in all text fields - ensure consistency across all references - canonicalNames.npcs.forEach(canonicalName => { - // Check and fix in flavor text - if (dungeonData.flavor) { - const original = dungeonData.flavor; - // Use canonical name as the source of truth - dungeonData.flavor = dungeonData.flavor.replace(new RegExp(canonicalName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), canonicalName); - if (original !== dungeonData.flavor) { - fixes.push(`Fixed NPC name in flavor text: ${canonicalName}`); - } - } - - // Check and fix in hooks - if (dungeonData.hooksRumors) { - dungeonData.hooksRumors = dungeonData.hooksRumors.map(hook => { - const original = hook; - const fixed = hook.replace(new RegExp(canonicalName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), canonicalName); - if (original !== fixed) { - fixes.push(`Fixed NPC name in hook: ${canonicalName}`); - } - return fixed; - }); - } - - // Check and fix in encounters - if (dungeonData.encounters) { - dungeonData.encounters.forEach(encounter => { - if (encounter.details) { - const original = encounter.details; - encounter.details = encounter.details.replace(new RegExp(canonicalName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), canonicalName); - if (original !== encounter.details) { - fixes.push(`Fixed NPC name in encounter: ${canonicalName}`); - } - } - }); - } - - // Check and fix in plot resolutions - if (dungeonData.plotResolutions) { - dungeonData.plotResolutions = dungeonData.plotResolutions.map(resolution => { - const original = resolution; - const fixed = resolution.replace(new RegExp(canonicalName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), canonicalName); - if (original !== fixed) { - fixes.push(`Fixed NPC name in plot resolution: ${canonicalName}`); - } - return fixed; - }); - } - }); - - // Fix room names in encounters and other text - canonicalNames.rooms.forEach(canonicalRoom => { - if (dungeonData.encounters) { - dungeonData.encounters.forEach(encounter => { - if (encounter.details) { - const original = encounter.details; - encounter.details = encounter.details.replace(new RegExp(canonicalRoom.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), canonicalRoom); - if (original !== encounter.details) { - fixes.push(`Fixed room name in encounter: ${canonicalRoom}`); - } - } - }); - } - }); - - return fixes; -} - -function standardizeEncounterLocations(encounters, rooms) { - if (!encounters || !rooms) return { encounters, fixes: [] }; - - const roomNames = rooms.map(r => r.name.trim()); - const fixes = []; - const fixedEncounters = encounters.map(encounter => { - if (!encounter.details) return encounter; - - let details = encounter.details.trim(); - const original = details; - - // Check if details start with a room name - for (const roomName of roomNames) { - // Check for room name at start (with or without colon) - const roomNameRegex = new RegExp(`^${roomName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*:?\\s*`, 'i'); - if (roomNameRegex.test(details)) { - // Already has location, ensure format is "Location: Description" - if (!details.match(new RegExp(`^${roomName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}:`, 'i'))) { - details = details.replace(roomNameRegex, `${roomName}: `); - fixes.push(`Standardized location format for encounter: ${encounter.name}`); - } - break; - } - } - - if (original !== details) { - encounter.details = details; - } - - return encounter; - }); - - return { encounters: fixedEncounters, fixes }; -} - -// Content validation functions -function validateContentCompleteness(dungeonData) { - const issues = []; - const checks = [ - ['title', 0, 'Missing title'], - ['flavor', 20, 'Flavor text too short'], - ['hooksRumors', 4, 'Expected at least 4 hooks'], - ['rooms', 5, 'Expected at least 5 rooms'], - ['encounters', 6, 'Expected at least 6 encounters'], - ['npcs', 4, 'Expected at least 4 NPCs'], - ['treasure', 4, 'Expected at least 4 treasures'], - ['randomEvents', 6, 'Expected 6 random events'], - ['plotResolutions', 4, 'Expected at least 4 plot resolutions'] - ]; - - checks.forEach(([key, min, msg]) => { - const val = dungeonData[key]; - if (!val || (Array.isArray(val) ? val.length < min : val.trim().length < min)) { - issues.push(`${msg}${Array.isArray(val) ? `, got ${val?.length || 0}` : ''}`); - } - }); - - // Check descriptions - dungeonData.rooms?.forEach((r, i) => { - if (!r.description || r.description.trim().length < 20) { - issues.push(`Room ${i + 1} (${r.name}) description too short`); - } - }); - dungeonData.encounters?.forEach((e, i) => { - if (!e.details || e.details.trim().length < 30) { - issues.push(`Encounter ${i + 1} (${e.name}) details too short`); - } - }); - dungeonData.npcs?.forEach((n, i) => { - if (!n.trait || n.trait.trim().length < 30) { - issues.push(`NPC ${i + 1} (${n.name}) description too short`); - } - }); - - return issues; -} - -function validateContentQuality(dungeonData) { - const issues = []; - const vagueWords = /\b(some|various|several|many|few|things|stuff|items|objects)\b/gi; - - const checkVague = (text, ctx) => { - if (!text) return; - const matches = text.match(vagueWords); - if (matches?.length > 2) { - issues.push(`${ctx} contains vague language: "${matches.slice(0, 3).join('", "')}"`); - } - }; - - checkVague(dungeonData.flavor, 'Flavor text'); - dungeonData.rooms?.forEach(r => checkVague(r.description, `Room "${r.name}"`)); - dungeonData.encounters?.forEach(e => checkVague(e.details, `Encounter "${e.name}"`)); - dungeonData.npcs?.forEach(n => checkVague(n.trait, `NPC "${n.name}"`)); - dungeonData.rooms?.forEach(r => { - if (r.description?.length < 50) { - issues.push(`Room "${r.name}" description too short`); - } - }); - - return issues; -} - -function validateContentStructure(dungeonData) { - const issues = []; - - dungeonData.rooms?.forEach((r, i) => { - if (!r.name?.trim()) issues.push(`Room ${i + 1} missing name`); - if (r.name?.split(/\s+/).length > 6) issues.push(`Room "${r.name}" name too long`); - }); - - dungeonData.encounters?.forEach((e, i) => { - if (!e.name?.trim()) issues.push(`Encounter ${i + 1} missing name`); - if (e.name?.split(/\s+/).length > 6) issues.push(`Encounter "${e.name}" name too long`); - if (e.details && !e.details.match(/^[^:]+:\s/)) { - issues.push(`Encounter "${e.name}" details missing location prefix`); - } - }); - - dungeonData.npcs?.forEach((n, i) => { - if (!n.name?.trim()) issues.push(`NPC ${i + 1} missing name`); - if (n.name?.split(/\s+/).length > 4) issues.push(`NPC "${n.name}" name too long`); - }); - - return issues; -} - -function validateNarrativeCoherence(dungeonData) { - const issues = []; - const factionMatch = dungeonData.coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i); - const factionName = factionMatch?.[1]?.trim(); - - if (dungeonData.encounters && dungeonData.rooms) { - const roomNames = dungeonData.rooms.map(r => r.name.trim().toLowerCase()); - dungeonData.encounters.forEach(e => { - const locMatch = e.details?.match(/^([^:]+):/); - if (locMatch) { - const locName = locMatch[1].trim().toLowerCase(); - if (!roomNames.some(rn => locName.includes(rn) || rn.includes(locName))) { - issues.push(`Encounter "${e.name}" references unknown location "${locMatch[1]}"`); - } - } - }); - } - - if (factionName) { - const factionLower = factionName.toLowerCase(); - let refs = 0; - dungeonData.npcs?.forEach(n => { - if (n.trait?.toLowerCase().includes(factionLower)) refs++; - }); - dungeonData.encounters?.forEach(e => { - if (e.details?.toLowerCase().includes(factionLower)) refs++; - }); - if (refs < 2) { - issues.push(`Faction "${factionName}" poorly integrated (${refs} references)`); - } - } - - return issues; -} - -function fixStructureIssues(dungeonData) { - const fixes = []; - - // Fix missing or invalid room names - if (dungeonData.rooms) { - dungeonData.rooms.forEach((room, i) => { - if (!room.name || !room.name.trim()) { - // Extract name from description if possible - const desc = room.description || ''; - const nameMatch = desc.match(/^([A-Z][^.!?]{5,30}?)(?:\s|\.|:)/); - if (nameMatch) { - room.name = nameMatch[1].trim(); - fixes.push(`Extracted room name from description: "${room.name}"`); - } else { - room.name = `Room ${i + 1}`; - fixes.push(`Added default name for room ${i + 1}`); - } - } - // Truncate overly long room names - const words = room.name.split(/\s+/); - if (words.length > 6) { - const original = room.name; - room.name = words.slice(0, 6).join(' '); - fixes.push(`Truncated room name: "${original}" -> "${room.name}"`); - } - }); - } - - // Fix missing or invalid encounter names - if (dungeonData.encounters) { - dungeonData.encounters.forEach((encounter, i) => { - if (!encounter.name || !encounter.name.trim()) { - // Extract name from details if possible - const details = encounter.details || ''; - const nameMatch = details.match(/^([^:]+):\s*(.+)$/); - if (nameMatch) { - encounter.name = nameMatch[1].trim(); - encounter.details = nameMatch[2].trim(); - fixes.push(`Extracted encounter name from details: "${encounter.name}"`); - } else { - encounter.name = `Encounter ${i + 1}`; - fixes.push(`Added default name for encounter ${i + 1}`); - } - } - // Truncate overly long encounter names - const words = encounter.name.split(/\s+/); - if (words.length > 6) { - const original = encounter.name; - encounter.name = words.slice(0, 6).join(' '); - fixes.push(`Truncated encounter name: "${original}" -> "${encounter.name}"`); - } - }); - } - - // Fix missing or invalid NPC names - if (dungeonData.npcs) { - dungeonData.npcs.forEach((npc, i) => { - if (!npc.name || !npc.name.trim()) { - // Extract name from trait if possible - const trait = npc.trait || ''; - const nameMatch = trait.match(/^([A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,2})(?:\s|:)/); - if (nameMatch) { - npc.name = nameMatch[1].trim(); - fixes.push(`Extracted NPC name from trait: "${npc.name}"`); - } else { - npc.name = `NPC ${i + 1}`; - fixes.push(`Added default name for NPC ${i + 1}`); - } - } - // Truncate overly long NPC names - const words = npc.name.split(/\s+/); - if (words.length > 4) { - const original = npc.name; - npc.name = words.slice(0, 4).join(' '); - fixes.push(`Truncated NPC name: "${original}" -> "${npc.name}"`); - } - }); - } - - return fixes; -} - -function fixMissingContent(dungeonData) { - const fixes = []; - - // Pad NPCs if needed - if (!dungeonData.npcs || dungeonData.npcs.length < 4) { - if (!dungeonData.npcs) dungeonData.npcs = []; - const factionName = dungeonData.coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction'; - while (dungeonData.npcs.length < 4) { - dungeonData.npcs.push({ - name: `NPC ${dungeonData.npcs.length + 1}`, - trait: `A member of ${factionName.toLowerCase()} with unknown motives.` - }); - fixes.push(`Added fallback NPC ${dungeonData.npcs.length}`); - } - } - - // Pad encounters if needed - if (!dungeonData.encounters || dungeonData.encounters.length < 6) { - if (!dungeonData.encounters) dungeonData.encounters = []; - if (dungeonData.encounters.length > 0 && dungeonData.rooms && dungeonData.rooms.length > 0) { - const dynamicElement = dungeonData.coreConcepts?.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; - const conflict = dungeonData.coreConcepts?.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a threat'; - while (dungeonData.encounters.length < 6) { - const roomIndex = dungeonData.encounters.length % dungeonData.rooms.length; - const roomName = dungeonData.rooms[roomIndex]?.name || 'Unknown Location'; - const fallbackNames = [ - `${roomName} Guardian`, - `${roomName} Threat`, - `${roomName} Challenge`, - `${dynamicElement.split(' ')[0]} Manifestation`, - `${conflict.split(' ')[0]} Encounter`, - `${roomName} Hazard` - ]; - dungeonData.encounters.push({ - name: fallbackNames[dungeonData.encounters.length % fallbackNames.length], - details: `${roomName}: An encounter related to ${dynamicElement.toLowerCase()} occurs here.` - }); - fixes.push(`Added fallback encounter: "${dungeonData.encounters[dungeonData.encounters.length - 1].name}"`); - } - } - } - - // Pad treasure if needed - if (!dungeonData.treasure || dungeonData.treasure.length < 4) { - if (!dungeonData.treasure) dungeonData.treasure = []; - while (dungeonData.treasure.length < 4) { - dungeonData.treasure.push({ - name: `Treasure ${dungeonData.treasure.length + 1}`, - description: `A mysterious item found in the dungeon.` - }); - fixes.push(`Added fallback treasure ${dungeonData.treasure.length}`); - } - } - - // Pad random events if needed - if (!dungeonData.randomEvents || dungeonData.randomEvents.length < 6) { - if (!dungeonData.randomEvents) dungeonData.randomEvents = []; - if (dungeonData.randomEvents.length > 0 && dungeonData.coreConcepts) { - const dynamicElement = dungeonData.coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; - const conflict = dungeonData.coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat'; - const fallbackEvents = [ - { name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` }, - { name: 'Conflict Manifestation', description: `A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.` }, - { name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` }, - { name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` }, - { name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` }, - { name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` } - ]; - while (dungeonData.randomEvents.length < 6) { - dungeonData.randomEvents.push(fallbackEvents[dungeonData.randomEvents.length % fallbackEvents.length]); - fixes.push(`Added fallback random event: "${dungeonData.randomEvents[dungeonData.randomEvents.length - 1].name}"`); - } - } - } - - // Pad plot resolutions if needed - if (!dungeonData.plotResolutions || dungeonData.plotResolutions.length < 4) { - if (!dungeonData.plotResolutions) dungeonData.plotResolutions = []; - while (dungeonData.plotResolutions.length < 4) { - dungeonData.plotResolutions.push(`The adventurers could resolve the central conflict through decisive action.`); - fixes.push(`Added fallback plot resolution ${dungeonData.plotResolutions.length}`); - } - } - - return fixes; -} - -function fixNarrativeCoherence(dungeonData) { - const fixes = []; - - // Fix encounters referencing unknown locations - if (dungeonData.encounters && dungeonData.rooms) { - const roomNames = dungeonData.rooms.map(r => r.name.trim().toLowerCase()); - dungeonData.encounters.forEach(encounter => { - if (!encounter.details) return; - const locationMatch = encounter.details.match(/^([^:]+):/); - if (locationMatch) { - const locName = locationMatch[1].trim().toLowerCase(); - // Check if location matches any room name (fuzzy match) - const matches = roomNames.some(rn => - locName === rn || - locName.includes(rn) || - rn.includes(locName) || - locName.split(/\s+/).some(word => rn.includes(word)) - ); - if (!matches && roomNames.length > 0) { - // Assign to a random room - const roomIdx = Math.floor(Math.random() * roomNames.length); - const roomName = dungeonData.rooms[roomIdx].name; - encounter.details = encounter.details.replace(/^[^:]+:\s*/, `${roomName}: `); - fixes.push(`Fixed unknown location in encounter "${encounter.name}" to "${roomName}"`); - } - } - }); - } - - return fixes; -} - -function validateAndFixContent(dungeonData) { - const allFixes = []; - const allIssues = []; - - // Validate name consistency - const nameFixes = validateNameConsistency(dungeonData); - allFixes.push(...nameFixes); - - // Fix structure issues (missing names, too long names) - const structureFixes = fixStructureIssues(dungeonData); - allFixes.push(...structureFixes); - - // Standardize encounter locations and add missing ones - if (dungeonData.encounters && dungeonData.rooms) { - const roomNames = dungeonData.rooms.map(r => r.name.trim()); - dungeonData.encounters.forEach((encounter, idx) => { - if (!encounter.details) return; - // If encounter doesn't start with a location, assign one - if (!encounter.details.match(/^[^:]+:\s/)) { - // Assign to a random room, or cycle through rooms - const roomIdx = idx % roomNames.length; - const roomName = roomNames[roomIdx]; - encounter.details = `${roomName}: ${encounter.details}`; - allFixes.push(`Added location "${roomName}" to encounter "${encounter.name}"`); - } - }); - const locationResult = standardizeEncounterLocations(dungeonData.encounters, dungeonData.rooms); - dungeonData.encounters = locationResult.encounters; - allFixes.push(...locationResult.fixes); - } - - // Fix narrative coherence issues - const coherenceFixes = fixNarrativeCoherence(dungeonData); - allFixes.push(...coherenceFixes); - - // Fix missing content (pad arrays) - const contentFixes = fixMissingContent(dungeonData); - allFixes.push(...contentFixes); - - // Run content validation (for reporting remaining issues) - const completenessIssues = validateContentCompleteness(dungeonData); - const qualityIssues = validateContentQuality(dungeonData); - const structureIssues = validateContentStructure(dungeonData); - const coherenceIssues = validateNarrativeCoherence(dungeonData); - - allIssues.push(...completenessIssues, ...qualityIssues, ...structureIssues, ...coherenceIssues); - - if (allFixes.length > 0) { - console.log("\n[Validation] Applied fixes:"); - allFixes.forEach(fix => console.log(` - ${fix}`)); - } - - if (allIssues.length > 0) { - console.log("\n[Validation] Content quality issues found (not auto-fixable):"); - allIssues.forEach(issue => console.warn(` ⚠ ${issue}`)); - } else { - console.log("\n[Validation] Content quality checks passed"); - } - - return dungeonData; -} - -export async function generateDungeon() { - // Step 1: Titles - const generatedTitles = await callOllama( - `Generate 50 short, punchy dungeon titles (max 5 words each), numbered as a plain text list. - Each title should come from a different style or theme. Make the set varied and evocative. For example: - - - OSR / classic tabletop: gritty, mysterious, old-school - - Mörk Borg: dark, apocalyptic, foreboding - - Pulpy fantasy: adventurous, dramatic, larger-than-life - - Mildly sci-fi: alien, technological, strange - - Weird fantasy: uncanny, surreal, unsettling - - Whimsical: fun, quirky, playful - - CRITICAL: Ensure all spelling is correct. Double-check all words before outputting. - Avoid repeating materials or adjectives. Absolutely do not use the words "Obsidian" or "Clockwork" in any title. Do not include explanations, markdown, or preambles. Do not include the style or theme in parenthesis. Only the 50 numbered titles.`, - undefined, 5, "Step 1: Titles" - ); - console.log("Generated Titles:", generatedTitles); - const titlesList = parseList(generatedTitles); - const title = titlesList[Math.floor(Math.random() * titlesList.length)]; - console.log("Selected title:", title); - - // Step 2: Core Concepts - const coreConceptsRaw = await callOllama( - `For a dungeon titled "${title}", generate three core concepts: a central conflict, a primary faction, and a major environmental hazard or dynamic element. -Output as a numbered list with bolded headings. Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output. -Example: -1. **Central Conflict:** The dungeon's power source is failing, causing reality to warp. -2. **Primary Faction:** A group of rival cultists trying to seize control of the power source. -3. **Dynamic Element:** Zones of temporal distortion that cause random, brief time shifts.`, - undefined, 5, "Step 2: Core Concepts" - ); - const coreConcepts = coreConceptsRaw; - console.log("Core Concepts:", coreConcepts); - - // Step 3: Flavor Text & Hooks - const flavorHooksRaw = await callOllama( - `Based on the title "${title}" and these core concepts: -${coreConcepts} -Write a single evocative paragraph describing the location. Maximum 2 sentences. Maximum 50-60 words. Then, generate 4-5 short adventure hooks or rumors. -The hooks should reference the central conflict, faction, and dynamic element. Hooks should suggest different approaches (stealth, diplomacy, force, exploration) and create anticipation. - -EXAMPLE OF GOOD HOOK: -"A merchant's cart was found abandoned near the entrance, its cargo of rare herbs scattered. The merchant's journal mentions strange lights in the depths and a warning about 'the watchers'." - -CRITICAL: Hooks must be concise to fit in a single column on a one-page dungeon layout. Each hook must be 25-30 words maximum. Be specific with details, not vague. -CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns and technical terms. -Output two sections labeled "Description:" and "Hooks & Rumors:". Use a numbered list for the hooks. Plain text only. Do not use em-dashes (—) anywhere in the output. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, - undefined, 5, "Step 3: Flavor & Hooks" - ); - const [flavorSection, hooksSection] = flavorHooksRaw.split(/Hooks & Rumors[:\n]/i); - let flavor = cleanText(flavorSection.replace(/Description[:\n]*/i, "")); - const words = flavor.split(/\s+/); - if (words.length > 60) flavor = words.slice(0, 60).join(' ') + '...'; - let hooksRumors = parseList(hooksSection || ""); - hooksRumors = hooksRumors.map(h => h.replace(/^[^:]+:\s*/, '').trim()); - console.log("Flavor Text:", flavor); - console.log("Hooks & Rumors:", hooksRumors); - - // Step 4: Key Rooms - const keyRoomsRaw = await callOllama( - `Based on the title "${title}", description "${flavor}", and these core concepts: -${coreConcepts} -Generate two key rooms that define the dungeon's narrative arc. -CRITICAL: These rooms need rich environmental and tactical details with multiple interaction possibilities. - -EXAMPLE OF GOOD ROOM DESCRIPTION: -"Chamber of Echoes: Flickering torchlight casts dancing shadows across moss-covered walls. A constant dripping echoes from stalactites overhead, and the air smells of damp earth and ozone. Three stone pillars provide cover, while a raised dais in the center offers high ground. A rusted lever on the west wall controls a hidden portcullis. The floor is slick with moisture, making movement difficult." - -1. Entrance Room: Give it a name (max 5 words) and a description (25-35 words) that MUST include: - - Immediate observable features and environmental details (lighting, sounds, smells, textures, temperature, visibility) - - Interactable elements that players can use (levers, objects, portals, mechanisms, environmental hazards) - - Tactical considerations (cover, elevation, movement restrictions, line of sight) - - Sets the tone and introduces the environmental hazard/dynamic element - -2. Climax Room: Give it a name (max 5 words) and a description (25-35 words) that MUST include: - - Connection to the primary faction and the central conflict - - Rich environmental and tactical details - - Multiple approach options or solutions - - Tactical considerations and environmental factors that affect gameplay - -EXACT FORMAT REQUIRED - each room on its own numbered line: -1. Room Name: Description text here. -2. Room Name: Description text here. - -CRITICAL: Ensure all spelling is correct. Double-check all words before outputting. -CRITICAL: Be specific and concrete. Avoid vague words like "some", "various", "several" without details. -Output ONLY the two numbered items, one per line. Use colons (:) to separate room names from descriptions, not em-dashes. Do not use em-dashes (—) anywhere. Do not combine items. Do not use bolded headings. Do not include any intro or other text. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, - undefined, 5, "Step 4: Key Rooms" - ); - const [entranceSection, climaxSection] = keyRoomsRaw.split(/\n?2[).] /); // Split on "2. " to separate the two rooms - const entranceRoom = parseObjects(entranceSection, "rooms")[0]; - const climaxRoom = parseObjects(`1. ${climaxSection}`, "rooms")[0]; // Prepend "1. " to make parsing consistent - - // Fix placeholder names by extracting from description - const fixRoomName = (room) => { - if (!room) return room; - if (room.name && (room.name.toLowerCase().includes('room name') || room.name.toLowerCase() === 'room name')) { - // Extract room name from description (first 2-4 words before "Description" or similar) - const desc = room.description || ''; - const nameMatch = desc.match(/^([^:]+?)(?:\s+Description|\s*:)/i) || desc.match(/^([A-Z][^.!?]{5,40}?)(?:\s+is\s|\.)/); - if (nameMatch) { - room.name = nameMatch[1].trim().replace(/^(The|A|An)\s+/i, '').trim(); - room.description = desc.replace(new RegExp(`^${nameMatch[1]}\\s*(Description|:)?\\s*`, 'i'), '').trim(); - } else { - // Fallback: use first few words of description - const words = desc.split(/\s+/).slice(0, 4).join(' '); - room.name = words.replace(/^(The|A|An)\s+/i, '').trim(); - } - } - return room; - }; - - if (entranceRoom) fixRoomName(entranceRoom); - if (climaxRoom) fixRoomName(climaxRoom); - - console.log("Entrance Room:", entranceRoom); - console.log("Climax Room:", climaxRoom); - - // Step 5: Main Content (Locations, Encounters, NPCs, Treasures, Random Events) - const mainContentRaw = await callOllama( - `Based on the following dungeon elements and the need for narrative flow: -Title: "${title}" -Description: "${flavor}" -Core Concepts: -${coreConcepts} -Entrance Room: ${JSON.stringify(entranceRoom)} -Climax Room: ${JSON.stringify(climaxRoom)} - -Generate the rest of the dungeon's content to fill the space between the entrance and the climax. CRITICAL: All content must fit on a single one-page dungeon layout with three columns. Keep descriptions rich and evocative with tactical/environmental details. - -- **Strictly 3 Locations (EXACTLY 3, no more, no less):** Each with a name (max 6 words) and a description (25-35 words). Each room MUST include: - - Rich environmental features that affect gameplay (lighting, sounds, smells, textures, temperature, visibility) - - Interactable elements that players can use (levers, objects, portals, mechanisms, environmental hazards) - - Multiple approaches or solutions to challenges in the room - - Tactical considerations (cover, elevation, movement restrictions, line of sight) - - Hidden aspects discoverable through interaction or investigation - Format as "Name: description" using colons, NOT em-dashes. - -EXAMPLE LOCATION: -"Whispering Gallery: Dim phosphorescent fungi line the walls, casting an eerie green glow. The air hums with a low-frequency vibration that makes conversation difficult. Two collapsed pillars create natural cover, while a narrow ledge 10 feet up offers a sniper position. A hidden pressure plate near the entrance triggers a portcullis trap." - -- **Strictly 6 Encounters:** Numbered 1-6 (for d6 rolling). Name (max 6 words) and details (2 sentences MAX, approximately 25-40 words). Each encounter MUST: - - Start with the room/location name followed by a colon, then the details (e.g., "Location Name: Details text") - - The location name must match one of the actual room names from this dungeon - - Include environmental hazards/opportunities (cover, elevation, traps, interactable objects, terrain features) - - Include tactical considerations (positioning, line of sight, escape routes, bottlenecks, high ground) - - Offer multiple resolution options (combat, negotiation, stealth, puzzle-solving, environmental manipulation, timing-based solutions) - - Include consequences and outcomes tied to player choices - - Integrate with the environmental dynamic element from core concepts - - At least two encounters must be directly tied to the primary faction - Format as "Name: Location Name: details" using colons, NOT em-dashes. CRITICAL: Always start encounter details with the location name and a colon. - -EXAMPLE ENCOUNTER: -"Guardian Golem: Chamber of Echoes: The golem activates when the lever is pulled, blocking the exit. It's vulnerable to water damage from the dripping stalactites. Players can use the pillars for cover or try to disable it by breaking the rune on its back. If defeated peacefully, it reveals a hidden passage." - -- **Strictly 4-5 NPCs:** Proper name (max 4 words) and a description (50-65 words). Each NPC MUST include: - - Clear motivation or goal - - Relationship to primary faction - - How they can help or hinder the party - - Quirks or memorable traits - - Multiple interaction possibilities (negotiation, intimidation, help, betrayal) - - One NPC should be a key figure tied to the central conflict - - One should be a member of the primary faction, one should be a potential ally, one should be a rival - Format as "Name: description" using colons, NOT em-dashes. - -EXAMPLE NPC: -"Kaelen the Warden: A former guard who was left behind when the faction retreated. He knows the secret passages but demands the party help him escape. He's paranoid and checks over his shoulder constantly. Can be bribed with food or convinced through shared stories of betrayal. Will turn on the party if he thinks they're working with the faction." - -- **Strictly 4-5 Treasures:** Name (max 5 words) and a description (30-40 words). Each treasure MUST: - - Include a clear danger or side-effect - - Be connected to a specific encounter, NPC, or room - - Have story significance beyond just value - - Have potential for creative use beyond obvious purpose - - Some should be cursed, have activation requirements, or serve dual purposes - Format as "Name — Description" using em-dash. - -EXAMPLE TREASURE: -"Whispering Blade — This dagger amplifies the wielder's voice to a deafening roar when drawn. Found in the Guardian Golem's chamber, it was used to command the construct. The blade is cursed: each use permanently reduces the wielder's hearing. Can be used to shatter glass or stun enemies, but the curse cannot be removed." - -- **Strictly 1 Random Events Table:** A d6 table (EXACTLY 6 entries, no more, no less) with random events/wandering encounters. Each entry MUST: - - Have a short, evocative event name (max 4 words) - - Provide interesting complications or opportunities (not just combat) - - Tie to the core concepts and dynamic element - - Add replayability and surprise - - Description should be 15-20 words maximum - - Be UNIQUE and DIFFERENT from each other (no duplicates or generic placeholders) - - Be SPECIFIC to this dungeon's theme, conflict, and dynamic element - Format as numbered 1-6 list under "Random Events:" label. Each event must be formatted as "Event Name: Description text" using colons, NOT em-dashes. - -CRITICAL: Each item must be on its own numbered line. DO NOT combine multiple items into a single numbered entry. - -EXACT FORMAT REQUIRED (DO NOT use placeholder names like "Location Name", "NPC Name", or "Treasure Name" - use actual creative names): -Locations: -1. Actual Room Name: Description text. -2. Actual Room Name: Description text. -3. Actual Room Name: Description text. - -Encounters: -1. Actual Encounter Name: Actual Room Name: Details text. -2. Actual Encounter Name: Actual Room Name: Details text. -3. Actual Encounter Name: Actual Room Name: Details text. -4. Actual Encounter Name: Actual Room Name: Details text. -5. Actual Encounter Name: Actual Room Name: Details text. -6. Actual Encounter Name: Actual Room Name: Details text. - -NPCs: -1. Actual Character Name: Description text. -2. Actual Character Name: Description text. -3. Actual Character Name: Description text. -4. Actual Character Name: Description text. - -Treasures: -1. Actual Item Name — Description text. -2. Actual Item Name — Description text. -3. Actual Item Name — Description text. -4. Actual Item Name — Description text. - -Random Events: -1. Event Name: Event description. -2. Event Name: Event description. -3. Event Name: Event description. -4. Event Name: Event description. -5. Event Name: Event description. -6. Event Name: Event description. - -CRITICAL: Every name must be unique and creative. Never use generic placeholders like "Location Name", "NPC Name", "Encounter Name", or "Treasure Name". Use actual descriptive names that fit the dungeon's theme. - -CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns, character names, and location names. Verify consistency of names across all sections. - -CRITICAL: Location name matching - When writing encounters, the location name in the encounter details MUST exactly match one of the room names you've created (Entrance Room, Climax Room, or one of the 3 Locations). Double-check that every encounter location matches an actual room name. - -CRITICAL: Avoid vague language - Do not use words like "some", "various", "several", "many", "few", "things", "stuff", "items", or "objects" without specific details. Be concrete and specific in all descriptions. - -CRITICAL: All names required - Every room, encounter, NPC, and treasure MUST have a name. Do not leave names blank or use placeholders. If you cannot think of a name, create one based on the dungeon's theme. - -CRITICAL: You MUST output exactly five separate sections with these exact labels on their own lines: -"Locations:" -"Encounters:" -"NPCs:" -"Treasures:" -"Random Events:" - -Each section must start with its label on its own line, followed by numbered items. Do NOT combine sections. Do NOT embed encounters in location descriptions. Each item must be on its own numbered line. Do not use any bolding, preambles, or extra text. Do not use em-dashes (—) in encounters or NPCs, only use colons for those sections. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, - undefined, 5, "Step 5: Main Content" - ); - let [intermediateRoomsSection, encountersSection, npcsSection, treasureSection, randomEventsSection] = mainContentRaw.split(/Encounters:|NPCs:|Treasures?:|Random Events:/i); - - // Ensure random events section is properly extracted (handle case where label might be missing) - if (!randomEventsSection && mainContentRaw.toLowerCase().includes('random')) { - const randomMatch = mainContentRaw.match(/Random Events?[:\s]*\n?([^]*?)(?=Locations?:|Encounters?:|NPCs?:|Treasures?:|$)/i); - if (randomMatch) { - randomEventsSection = randomMatch[1]; - } - } - - // Ensure NPCs section is properly extracted - if (!npcsSection && mainContentRaw.toLowerCase().includes('npc')) { - const npcMatch = mainContentRaw.match(/NPCs?[:\s]*\n?([^]*?)(?=Treasures?:|Random Events?:|Locations?:|Encounters?:|$)/i); - if (npcMatch) { - npcsSection = npcMatch[1]; - } - } - - // If sections are missing, try to extract from combined output - if (!encountersSection && intermediateRoomsSection.includes('Encounter')) { - const encounterMatches = intermediateRoomsSection.match(/Encounter\s+\d+[^]*?(?=Encounter\s+\d+|NPCs?:|Treasures?:|Random Events?:|Location \d+|$)/gi); - if (encounterMatches && encounterMatches.length > 0) { - encountersSection = encounterMatches.map((m, i) => { - // Convert "Encounter N Name Room Name Location Details" to "N. Name: Location: Details" - const match = m.match(/Encounter\s+(\d+)\s+(.+?)\s+(?:Room Name|Location)\s+(.+?)\s+Details\s+(.+)/i); - if (match) { - const [, num, name, location, details] = match; - return `${num}. ${name.trim()}: ${location.trim()}: ${details.trim().substring(0, 200)}`; - } - // Try format without "Room Name" - const simpleMatch = m.match(/Encounter\s+(\d+)\s+(.+?)\s+([A-Z][^:]+?)\s+Details\s+(.+)/i); - if (simpleMatch) { - const [, num, name, location, details] = simpleMatch; - return `${num}. ${name.trim()}: ${location.trim()}: ${details.trim().substring(0, 200)}`; - } - return `${i + 1}. ${m.trim()}`; - }).join('\n'); - intermediateRoomsSection = intermediateRoomsSection.replace(/Encounter\s+\d+[^]*?(?=Encounter\s+\d+|NPCs?:|Treasures?:|Random Events?:|Location \d+|$)/gi, ''); - } - } - - const intermediateRooms = parseObjects(intermediateRoomsSection.replace(/Locations:/i, ""), "rooms"); - // Limit to exactly 3 intermediate rooms to ensure total of 5 rooms (entrance + 3 intermediate + climax) - const limitedIntermediateRooms = intermediateRooms.slice(0, 3); - if (intermediateRooms.length > 3) { - console.warn(`Expected exactly 3 intermediate locations but got ${intermediateRooms.length}, limiting to first 3`); - } - - // Deduplicate rooms by name (case-insensitive), keeping first occurrence - const allRooms = [entranceRoom, ...limitedIntermediateRooms, climaxRoom].filter(Boolean); - const seenNames = new Set(); - const rooms = allRooms.filter(room => { - if (!room || !room.name) return false; - const nameLower = room.name.toLowerCase().trim(); - if (seenNames.has(nameLower)) { - console.warn(`Duplicate room name detected: "${room.name}", skipping duplicate`); - return false; - } - seenNames.add(nameLower); - return true; - }); - let encounters = splitCombinedEncounters(parseObjects(encountersSection || "", "encounters")); - let npcs = parseObjects(npcsSection || "", "npcs"); - const treasure = parseObjects(treasureSection || "", "treasure"); - - // Pad NPCs to at least 4 if needed (only if we have some NPCs already) - if (npcs.length > 0 && npcs.length < 4) { - const factionName = coreConcepts.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction'; - while (npcs.length < 4) { - npcs.push({ - name: `NPC ${npcs.length + 1}`, - trait: `A member of ${factionName.toLowerCase()} with unknown motives.` - }); - } - } - - // Pad encounters to exactly 6 (only pad if we have at least 1 real encounter) - if (encounters.length > 0 && encounters.length < 6) { - const dynamicElement = coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; - const conflict = coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a threat'; - while (encounters.length < 6) { - const roomIndex = encounters.length % rooms.length; - const roomName = rooms[roomIndex]?.name || 'Unknown Location'; - // Use more descriptive fallback names based on room and theme - const fallbackNames = [ - `${roomName} Guardian`, - `${roomName} Threat`, - `${roomName} Challenge`, - `${dynamicElement.split(' ')[0]} Manifestation`, - `${conflict.split(' ')[0]} Encounter`, - `${roomName} Hazard` - ]; - encounters.push({ - name: fallbackNames[encounters.length % fallbackNames.length], - details: `An encounter related to ${dynamicElement.toLowerCase()} occurs here.` - }); - } - } else if (encounters.length === 0) { - // If no encounters at all, create 6 basic ones - const dynamicElement = coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; - for (let i = 0; i < 6; i++) { - const roomIndex = i % rooms.length; - const roomName = rooms[roomIndex]?.name || 'Unknown Location'; - encounters.push({ - name: `${roomName} Encounter`, - details: `An encounter related to ${dynamicElement.toLowerCase()} occurs here.` - }); - } - } - let randomEvents = parseList(randomEventsSection || ""); - // Parse events into objects with name and description - randomEvents = randomEvents - .filter(e => - e && - e.toLowerCase() !== 'a random event occurs' && - e.toLowerCase() !== 'a random event occurs.' && - !e.toLowerCase().includes('placeholder') && - e.length > 10 - ) - .map((e, index) => { - // Strip numbered prefixes like "Event 1:", "Random Event:", etc. - let cleaned = e.replace(/^(Event\s+\d+[:\s]+|Random\s+Event[:\s]+|Random\s+Events?[:\s]+)/i, '').trim(); - - // Parse "Event Name: Description" format - const colonMatch = cleaned.match(/^([^:]+):\s*(.+)$/); - if (colonMatch) { - const name = colonMatch[1].trim(); - const description = colonMatch[2].trim(); - // Skip if name looks like a placeholder - if (name.toLowerCase().includes('event name') || name.toLowerCase().includes('placeholder')) { - return null; - } - return { name, description }; - } - - // Fallback: if no colon, use first few words as name - const words = cleaned.split(/\s+/); - if (words.length > 3) { - return { - name: words.slice(0, 2).join(' '), - description: words.slice(2).join(' ') - }; - } - - // Last resort: use as description with generic name - return { name: `Event ${index + 1}`, description: cleaned }; - }) - .filter(Boolean); // Remove null entries - randomEvents = randomEvents.slice(0, 6); - - // Generate context-aware fallbacks if needed (only if we have some events already) - if (randomEvents.length > 0 && randomEvents.length < 6) { - const dynamicElement = coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; - const conflict = coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat'; - const fallbackEvents = [ - { name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` }, - { name: 'Conflict Manifestation', description: `A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.` }, - { name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` }, - { name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` }, - { name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` }, - { name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` } - ]; - while (randomEvents.length < 6) { - randomEvents.push(fallbackEvents[randomEvents.length % fallbackEvents.length]); - } - } - - [[encounters, 6, 'encounters'], [npcs, 4, 'NPCs'], [treasure, 4, 'treasures'], [randomEvents, 6, 'random events']] - .filter(([arr, expected]) => arr.length < expected && arr.length > 0) - .forEach(([arr, expected, name]) => console.warn(`Expected at least ${expected} ${name} but got ${arr.length}`)); - console.log("Rooms:", rooms); - console.log("Encounters:", encounters); - console.log("NPCs:", npcs); - console.log("Treasure:", treasure); - console.log("Random Events:", randomEvents); - - // Step 6: Player Choices and Consequences - const npcNamesList = npcs.map(n => n.name).join(", "); - const factionName = coreConcepts.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || "the primary faction"; - - const plotResolutionsRaw = await callOllama( - `Based on all of the following elements, suggest 4-5 possible, non-conflicting story climaxes or plot resolutions for adventurers exploring this location. Each resolution must provide a meaningful choice with a tangible consequence, directly related to the Central Conflict, the Primary Faction, or the NPCs. - -Dungeon Elements: -${JSON.stringify({ title, flavor, hooksRumors, rooms, encounters, treasure, npcs, coreConcepts }, null, 2)} - -CRITICAL: This content must fit in a single column on a one-page dungeon layout. Keep descriptions meaningful but concise. -Start each item with phrases like "The adventurers could" or "The adventurers might". Do not use "PCs" or "player characters" - always use "adventurers" instead. - -EXAMPLE PLOT RESOLUTION: -"The adventurers could ally with the primary faction, gaining access to their resources but becoming enemies of the rival group. This choice unlocks new areas but closes off diplomatic solutions with other NPCs." - -IMPORTANT: When referencing NPCs, use these exact names with correct spelling: ${npcNamesList}. When referencing the faction, use: ${factionName}. Ensure all names are spelled consistently and correctly. -CRITICAL: Double-check all spelling before outputting. Verify all proper nouns match exactly as provided above. - -Each resolution MUST: -- Offer meaningful choice with clear consequences -- Integrate NPCs, faction dynamics, and player actions -- Include failure states or unexpected outcomes as options -- Reflect different approaches players might take -Keep each item to 1-2 sentences MAX (approximately 15-25 words). Be extremely concise. Output as a numbered list, plain text only. Do not use em-dashes (—) anywhere in the output. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, - undefined, 5, "Step 6: Plot Resolutions" - ); - const plotResolutions = parseList(plotResolutionsRaw); - console.log("Plot Resolutions:", plotResolutions); - - // Step 7: Validation and Content Fixing - console.log("\n[Validation] Running content validation and fixes..."); - const dungeonData = { - title, - flavor, - map: "map.png", - hooksRumors, - rooms, - encounters, - treasure, - npcs, - plotResolutions, - randomEvents, - coreConcepts - }; - - const validatedData = validateAndFixContent(dungeonData); - - console.log("\nDungeon generation complete!"); - return validatedData; -} diff --git a/eslint.config.js b/eslint.config.js index c510269..d7dcab6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,5 +3,26 @@ import globals from "globals"; import { defineConfig } from "eslint/config"; export default defineConfig([ - { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, + { + files: ["**/*.{js,mjs,cjs}"], + plugins: { js }, + extends: ["js/recommended"], + languageOptions: { globals: globals.node }, + rules: { + "no-unused-vars": ["error", { varsIgnorePattern: "^_" }], + }, + }, + { + files: ["test/**/*.js"], + languageOptions: { + globals: { + ...globals.node, + describe: "readonly", + it: "readonly", + test: "readonly", + expect: "readonly", + vi: "readonly", + }, + }, + }, ]); diff --git a/index.js b/index.js index 65c7b61..7843de4 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ import "dotenv/config"; -import { generateDungeon } from "./dungeonGenerator.js"; -import { generateDungeonImages } from "./imageGenerator.js"; -import { generatePDF } from "./generatePDF.js"; -import { OLLAMA_MODEL, initializeModel } from "./ollamaClient.js"; +import { generateDungeon } from "./src/dungeonGenerator.js"; +import { generateDungeonImages } from "./src/imageGenerator.js"; +import { generatePDF } from "./src/generatePDF.js"; +import { OLLAMA_MODEL, initializeModel } from "./src/ollamaClient.js"; // Utility to create a filesystem-safe filename from the dungeon title function slugify(text) { diff --git a/package-lock.json b/package-lock.json index 7bae609..3cac6d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,18 +14,21 @@ "sharp": "^0.34.3" }, "devDependencies": { - "@eslint/js": "^9.34.0", - "eslint": "^9.34.0", - "globals": "^17.0.0" + "@eslint/js": "^10.0.0", + "@vitest/coverage-v8": "^4.0.18", + "c8": "^10.1.3", + "eslint": "^10.0.0", + "globals": "^17.0.0", + "vitest": "^4.0.18" } }, "node_modules/@babel/code-frame": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", - "integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==", + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz", + "integrity": "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==", "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.27.1", + "@babel/helper-validator-identifier": "^7.28.5", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" }, @@ -33,6 +36,16 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/helper-string-parser": { + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", + "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/helper-validator-identifier": { "version": "7.28.5", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.28.5.tgz", @@ -42,6 +55,46 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/parser": { + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.0.tgz", + "integrity": "sha512-IyDgFV5GeDUVX4YdF/3CPULtVGSXXMLh1xVIgdCgxApktqnQV0r7/8Nqthg+8YLGaAtdyIlo2qIdZrbCv4+7ww==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.0" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz", + "integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.27.1", + "@babel/helper-validator-identifier": "^7.28.5" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@bcoe/v8-coverage": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz", + "integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@emnapi/runtime": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.8.1.tgz", @@ -52,6 +105,448 @@ "tslib": "^2.4.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.3.tgz", + "integrity": "sha512-9fJMTNFTWZMh5qwrBItuziu834eOCUcEqymSH7pY+zoMVEZg3gcPuBNxH1EvfVYe9h0x/Ptw8KBzv7qxb7l8dg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.3.tgz", + "integrity": "sha512-i5D1hPY7GIQmXlXhs2w8AWHhenb00+GxjxRncS2ZM7YNVGNfaMxgzSGuO8o8SJzRc/oZwU2bcScvVERk03QhzA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.3.tgz", + "integrity": "sha512-YdghPYUmj/FX2SYKJ0OZxf+iaKgMsKHVPF1MAq/P8WirnSpCStzKJFjOjzsW0QQ7oIAiccHdcqjbHmJxRb/dmg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.3.tgz", + "integrity": "sha512-IN/0BNTkHtk8lkOM8JWAYFg4ORxBkZQf9zXiEOfERX/CzxW3Vg1ewAhU7QSWQpVIzTW+b8Xy+lGzdYXV6UZObQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.3.tgz", + "integrity": "sha512-Re491k7ByTVRy0t3EKWajdLIr0gz2kKKfzafkth4Q8A5n1xTHrkqZgLLjFEHVD+AXdUGgQMq+Godfq45mGpCKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.3.tgz", + "integrity": "sha512-vHk/hA7/1AckjGzRqi6wbo+jaShzRowYip6rt6q7VYEDX4LEy1pZfDpdxCBnGtl+A5zq8iXDcyuxwtv3hNtHFg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.3.tgz", + "integrity": "sha512-ipTYM2fjt3kQAYOvo6vcxJx3nBYAzPjgTCk7QEgZG8AUO3ydUhvelmhrbOheMnGOlaSFUoHXB6un+A7q4ygY9w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.3.tgz", + "integrity": "sha512-dDk0X87T7mI6U3K9VjWtHOXqwAMJBNN2r7bejDsc+j03SEjtD9HrOl8gVFByeM0aJksoUuUVU9TBaZa2rgj0oA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.3.tgz", + "integrity": "sha512-s6nPv2QkSupJwLYyfS+gwdirm0ukyTFNl3KTgZEAiJDd+iHZcbTPPcWCcRYH+WlNbwChgH2QkE9NSlNrMT8Gfw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.3.tgz", + "integrity": "sha512-sZOuFz/xWnZ4KH3YfFrKCf1WyPZHakVzTiqji3WDc0BCl2kBwiJLCXpzLzUBLgmp4veFZdvN5ChW4Eq/8Fc2Fg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.3.tgz", + "integrity": "sha512-yGlQYjdxtLdh0a3jHjuwOrxQjOZYD/C9PfdbgJJF3TIZWnm/tMd/RcNiLngiu4iwcBAOezdnSLAwQDPqTmtTYg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.3.tgz", + "integrity": "sha512-WO60Sn8ly3gtzhyjATDgieJNet/KqsDlX5nRC5Y3oTFcS1l0KWba+SEa9Ja1GfDqSF1z6hif/SkpQJbL63cgOA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.3.tgz", + "integrity": "sha512-APsymYA6sGcZ4pD6k+UxbDjOFSvPWyZhjaiPyl/f79xKxwTnrn5QUnXR5prvetuaSMsb4jgeHewIDCIWljrSxw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.3.tgz", + "integrity": "sha512-eizBnTeBefojtDb9nSh4vvVQ3V9Qf9Df01PfawPcRzJH4gFSgrObw+LveUyDoKU3kxi5+9RJTCWlj4FjYXVPEA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.3.tgz", + "integrity": "sha512-3Emwh0r5wmfm3ssTWRQSyVhbOHvqegUDRd0WhmXKX2mkHJe1SFCMJhagUleMq+Uci34wLSipf8Lagt4LlpRFWQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.3.tgz", + "integrity": "sha512-pBHUx9LzXWBc7MFIEEL0yD/ZVtNgLytvx60gES28GcWMqil8ElCYR4kvbV2BDqsHOvVDRrOxGySBM9Fcv744hw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.3.tgz", + "integrity": "sha512-Czi8yzXUWIQYAtL/2y6vogER8pvcsOsk5cpwL4Gk5nJqH5UZiVByIY8Eorm5R13gq+DQKYg0+JyQoytLQas4dA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.3.tgz", + "integrity": "sha512-sDpk0RgmTCR/5HguIZa9n9u+HVKf40fbEUt+iTzSnCaGvY9kFP0YKBWZtJaraonFnqef5SlJ8/TiPAxzyS+UoA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.3.tgz", + "integrity": "sha512-P14lFKJl/DdaE00LItAukUdZO5iqNH7+PjoBm+fLQjtxfcfFE20Xf5CrLsmZdq5LFFZzb5JMZ9grUwvtVYzjiA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.3.tgz", + "integrity": "sha512-AIcMP77AvirGbRl/UZFTq5hjXK+2wC7qFRGoHSDrZ5v5b8DK/GYpXW3CPRL53NkvDqb9D+alBiC/dV0Fb7eJcw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.3.tgz", + "integrity": "sha512-DnW2sRrBzA+YnE70LKqnM3P+z8vehfJWHXECbwBmH/CU51z6FiqTQTHFenPlHmo3a8UgpLyH3PT+87OViOh1AQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.3.tgz", + "integrity": "sha512-NinAEgr/etERPTsZJ7aEZQvvg/A6IsZG/LgZy+81wON2huV7SrK3e63dU0XhyZP4RKGyTm7aOgmQk0bGp0fy2g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.3.tgz", + "integrity": "sha512-PanZ+nEz+eWoBJ8/f8HKxTTD172SKwdXebZ0ndd953gt1HRBbhMsaNqjTyYLGLPdoWHy4zLU7bDVJztF5f3BHA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.3.tgz", + "integrity": "sha512-B2t59lWWYrbRDw/tjiWOuzSsFh1Y/E95ofKz7rIVYSQkUYBjfSgf6oeYPNWHToFRr2zx52JKApIcAS/D5TUBnA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.3.tgz", + "integrity": "sha512-QLKSFeXNS8+tHW7tZpMtjlNb7HKau0QDpwm49u0vUp9y1WOF+PEzkU84y9GqYaAVW8aH8f3GcBck26jh54cX4Q==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.3.tgz", + "integrity": "sha512-4uJGhsxuptu3OcpVAzli+/gWusVGwZZHTlS63hh++ehExkVT8SgiEf7/uC/PclrPPkLhZqGgCTjd0VWLo6xMqA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.9.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.1.tgz", @@ -95,118 +590,89 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.1.tgz", - "integrity": "sha512-aw1gNayWpdI/jSYVgzN5pL0cfzU02GT3NBpeT/DXbx1/1x7ZKxFPd9bwrzygx/qiwIQiJ1sw/zD8qY/kRvlGHA==", + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.2.tgz", + "integrity": "sha512-YF+fE6LV4v5MGWRGj7G404/OZzGNepVF8fxk7jqmqo3lrza7a0uUcDnROGRBG1WFC1omYUS/Wp1f42i0M+3Q3A==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/object-schema": "^2.1.7", + "@eslint/object-schema": "^3.0.2", "debug": "^4.3.1", - "minimatch": "^3.1.2" + "minimatch": "^10.2.1" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/config-helpers": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.4.2.tgz", - "integrity": "sha512-gBrxN88gOIf3R7ja5K9slwNayVcZgK6SOUORm2uBzTeIEfeVaIhOpCtTox3P6R7o2jLFwLFTLnC7kU/RGcYEgw==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.5.2.tgz", + "integrity": "sha512-a5MxrdDXEvqnIq+LisyCX6tQMPF/dSJpCfBgBauY+pNZ28yCtSsTvyTYrMhaI+LK26bVyCJfJkT0u8KIj2i1dQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/core": "^0.17.0" + "@eslint/core": "^1.1.0" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/core": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.17.0.tgz", - "integrity": "sha512-yL/sLrpmtDaFEiUj1osRP4TI2MDz1AddJL+jZ7KSqvBuliN4xqYY54IfdN8qD8Toa6g1iloph1fxQNkjOxrrpQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-1.1.0.tgz", + "integrity": "sha512-/nr9K9wkr3P1EzFTdFdMoLuo1PmIxjmwvPozwoSodjNBdefGujXQUF93u1DDZpEaTuDvMsIQddsd35BwtrW9Xw==", "dev": true, "license": "Apache-2.0", "dependencies": { "@types/json-schema": "^7.0.15" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - } - }, - "node_modules/@eslint/eslintrc": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.3.tgz", - "integrity": "sha512-Kr+LPIUVKz2qkx1HAMH8q1q6azbqBAsXJUxBl/ODDuVPX45Z9DfwB8tPjTi6nNZ8BuM3nbJxC5zCAg5elnBUTQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "ajv": "^6.12.4", - "debug": "^4.3.2", - "espree": "^10.0.1", - "globals": "^14.0.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.1", - "minimatch": "^3.1.2", - "strip-json-comments": "^3.1.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/js": { - "version": "9.39.2", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.2.tgz", - "integrity": "sha512-q1mjIoW1VX4IvSocvM/vbTiveKC4k9eLrajNEuSsmjymSDEbpGddtpfOoN7YGAqBK3NG+uqo8ia4PDTt8buCYA==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", + "integrity": "sha512-zeR9k5pd4gxjZ0abRoIaxdc7I3nDktoXZk2qOv9gCNWx3mVwEn32VRhyLaRsDiJjTs0xq/T8mfPtyuXu7GWBcA==", "dev": true, "license": "MIT", "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "eslint": "^10.0.0" + }, + "peerDependenciesMeta": { + "eslint": { + "optional": true + } } }, "node_modules/@eslint/object-schema": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.7.tgz", - "integrity": "sha512-VtAOaymWVfZcmZbp6E2mympDIHvyjXs/12LqWYjVw6qjrfF+VK+fyG33kChz3nnK+SU5/NeHOqrTEHS8sXO3OA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.2.tgz", + "integrity": "sha512-HOy56KJt48Bx8KmJ+XGQNSUMT/6dZee/M54XyUyuvTvPXJmsERRvBchsUVx1UMe1WwIH49XLAczNC7V2INsuUw==", "dev": true, "license": "Apache-2.0", "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/plugin-kit": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.4.1.tgz", - "integrity": "sha512-43/qtrDUokr7LJqoF2c3+RInu/t4zfrpYdoSDfYyhg52rwLV6TnOvdG4fXm7IkSB3wErkcmJS9iEhjVtOSEjjA==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.6.0.tgz", + "integrity": "sha512-bIZEUzOI1jkhviX2cp5vNyXQc6olzb2ohewQubuYlMXZ2Q/XjBO0x0XhGPvc9fjSIiUN0vw+0hq53BJ4eQSJKQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/core": "^0.17.0", + "@eslint/core": "^1.1.0", "levn": "^0.4.1" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@humanfs/core": { @@ -726,17 +1192,169 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz", + "integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz", + "integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz", + "integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@puppeteer/browsers": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.11.0.tgz", - "integrity": "sha512-n6oQX6mYkG8TRPuPXmbPidkUbsSRalhmaaVAQxvH1IkQy63cwsH+kOjB3e4cpCDHg0aSvsiX9bQ4s2VB6mGWUQ==", + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.13.0.tgz", + "integrity": "sha512-46BZJYJjc/WwmKjsvDFykHtXrtomsCIrwYQPOP7VfMJoZY2bsDF9oROBABR3paDjDcmkUye1Pb1BqdcdiipaWA==", "license": "Apache-2.0", "dependencies": { "debug": "^4.4.3", "extract-zip": "^2.0.1", "progress": "^2.0.3", "proxy-agent": "^6.5.0", - "semver": "^7.7.3", + "semver": "^7.7.4", "tar-fs": "^3.1.1", "yargs": "^17.7.2" }, @@ -747,12 +1365,394 @@ "node": ">=18" } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.58.0.tgz", + "integrity": "sha512-mr0tmS/4FoVk1cnaeN244A/wjvGDNItZKR8hRhnmCzygyRXYtKF5jVDSIILR1U97CTzAYmbgIj/Dukg62ggG5w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.58.0.tgz", + "integrity": "sha512-+s++dbp+/RTte62mQD9wLSbiMTV+xr/PeRJEc/sFZFSBRlHPNPVaf5FXlzAL77Mr8FtSfQqCN+I598M8U41ccQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.58.0.tgz", + "integrity": "sha512-MFWBwTcYs0jZbINQBXHfSrpSQJq3IUOakcKPzfeSznONop14Pxuqa0Kg19GD0rNBMPQI2tFtu3UzapZpH0Uc1Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.58.0.tgz", + "integrity": "sha512-yiKJY7pj9c9JwzuKYLFaDZw5gma3fI9bkPEIyofvVfsPqjCWPglSHdpdwXpKGvDeYDms3Qal8qGMEHZ1M/4Udg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.58.0.tgz", + "integrity": "sha512-x97kCoBh5MOevpn/CNK9W1x8BEzO238541BGWBc315uOlN0AD/ifZ1msg+ZQB05Ux+VF6EcYqpiagfLJ8U3LvQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.58.0.tgz", + "integrity": "sha512-Aa8jPoZ6IQAG2eIrcXPpjRcMjROMFxCt1UYPZZtCxRV68WkuSigYtQ/7Zwrcr2IvtNJo7T2JfDXyMLxq5L4Jlg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.58.0.tgz", + "integrity": "sha512-Ob8YgT5kD/lSIYW2Rcngs5kNB/44Q2RzBSPz9brf2WEtcGR7/f/E9HeHn1wYaAwKBni+bdXEwgHvUd0x12lQSA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.58.0.tgz", + "integrity": "sha512-K+RI5oP1ceqoadvNt1FecL17Qtw/n9BgRSzxif3rTL2QlIu88ccvY+Y9nnHe/cmT5zbH9+bpiJuG1mGHRVwF4Q==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.58.0.tgz", + "integrity": "sha512-T+17JAsCKUjmbopcKepJjHWHXSjeW7O5PL7lEFaeQmiVyw4kkc5/lyYKzrv6ElWRX/MrEWfPiJWqbTvfIvjM1Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.58.0.tgz", + "integrity": "sha512-cCePktb9+6R9itIJdeCFF9txPU7pQeEHB5AbHu/MKsfH/k70ZtOeq1k4YAtBv9Z7mmKI5/wOLYjQ+B9QdxR6LA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.58.0.tgz", + "integrity": "sha512-iekUaLkfliAsDl4/xSdoCJ1gnnIXvoNz85C8U8+ZxknM5pBStfZjeXgB8lXobDQvvPRCN8FPmmuTtH+z95HTmg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.58.0.tgz", + "integrity": "sha512-68ofRgJNl/jYJbxFjCKE7IwhbfxOl1muPN4KbIqAIe32lm22KmU7E8OPvyy68HTNkI2iV/c8y2kSPSm2mW/Q9Q==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.58.0.tgz", + "integrity": "sha512-dpz8vT0i+JqUKuSNPCP5SYyIV2Lh0sNL1+FhM7eLC457d5B9/BC3kDPp5BBftMmTNsBarcPcoz5UGSsnCiw4XQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.58.0.tgz", + "integrity": "sha512-4gdkkf9UJ7tafnweBCR/mk4jf3Jfl0cKX9Np80t5i78kjIH0ZdezUv/JDI2VtruE5lunfACqftJ8dIMGN4oHew==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.58.0.tgz", + "integrity": "sha512-YFS4vPnOkDTD/JriUeeZurFYoJhPf9GQQEF/v4lltp3mVcBmnsAdjEWhr2cjUCZzZNzxCG0HZOvJU44UGHSdzw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.58.0.tgz", + "integrity": "sha512-x2xgZlFne+QVNKV8b4wwaCS8pwq3y14zedZ5DqLzjdRITvreBk//4Knbcvm7+lWmms9V9qFp60MtUd0/t/PXPw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.58.0.tgz", + "integrity": "sha512-jIhrujyn4UnWF8S+DHSkAkDEO3hLX0cjzxJZPLF80xFyzyUIYgSMRcYQ3+uqEoyDD2beGq7Dj7edi8OnJcS/hg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.58.0.tgz", + "integrity": "sha512-+410Srdoh78MKSJxTQ+hZ/Mx+ajd6RjjPwBPNd0R3J9FtL6ZA0GqiiyNjCO9In0IzZkCNrpGymSfn+kgyPQocg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.58.0.tgz", + "integrity": "sha512-ZjMyby5SICi227y1MTR3VYBpFTdZs823Rs/hpakufleBoufoOIB6jtm9FEoxn/cgO7l6PM2rCEl5Kre5vX0QrQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.58.0.tgz", + "integrity": "sha512-ds4iwfYkSQ0k1nb8LTcyXw//ToHOnNTJtceySpL3fa7tc/AsE+UpUFphW126A6fKBGJD5dhRvg8zw1rvoGFxmw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.58.0.tgz", + "integrity": "sha512-fd/zpJniln4ICdPkjWFhZYeY/bpnaN9pGa6ko+5WD38I0tTqk9lXMgXZg09MNdhpARngmxiCg0B0XUamNw/5BQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.58.0.tgz", + "integrity": "sha512-YpG8dUOip7DCz3nr/JUfPbIUo+2d/dy++5bFzgi4ugOGBIox+qMbbqt/JoORwvI/C9Kn2tz6+Bieoqd5+B1CjA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.58.0.tgz", + "integrity": "sha512-b9DI8jpFQVh4hIXFr0/+N/TzLdpBIoPzjt0Rt4xJbW3mzguV3mduR9cNgiuFcuL/TeORejJhCWiAXe3E/6PxWA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.58.0.tgz", + "integrity": "sha512-CSrVpmoRJFN06LL9xhkitkwUcTZtIotYAF5p6XOR2zW0Zz5mzb3IPpcoPhB02frzMHFNo1reQ9xSF5fFm3hUsQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.58.0.tgz", + "integrity": "sha512-QFsBgQNTnh5K0t/sBsjJLq24YVqEIVkGpfN2VHsnN90soZyhaiA9UUHufcctVNL4ypJY0wrwad0wslx2KJQ1/w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "dev": true, + "license": "MIT" + }, "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==", "license": "MIT" }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/esrecurse": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", + "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -760,6 +1760,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/istanbul-lib-coverage": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -768,13 +1775,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.0.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.6.tgz", - "integrity": "sha512-NNu0sjyNxpoiW3YuVFfNz7mxSQ+S4X2G28uqg2s+CzoqoQjLPsWSbsFFyztIAqt2vb8kfEAsJNepMGPTxFDx3Q==", + "version": "25.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.3.0.tgz", + "integrity": "sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A==", "license": "MIT", "optional": true, "dependencies": { - "undici-types": "~7.16.0" + "undici-types": "~7.18.0" } }, "node_modules/@types/yauzl": { @@ -787,10 +1794,152 @@ "@types/node": "*" } }, + "node_modules/@vitest/coverage-v8": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.0.18.tgz", + "integrity": "sha512-7i+N2i0+ME+2JFZhfuz7Tg/FqKtilHjGyGvoHYQ6iLV0zahbsJ9sljC9OcFcPDbhYKCet+sG8SsVqlyGvPflZg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@bcoe/v8-coverage": "^1.0.2", + "@vitest/utils": "4.0.18", + "ast-v8-to-istanbul": "^0.3.10", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.2.0", + "magicast": "^0.5.1", + "obug": "^2.1.1", + "std-env": "^3.10.0", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/browser": "4.0.18", + "vitest": "4.0.18" + }, + "peerDependenciesMeta": { + "@vitest/browser": { + "optional": true + } + } + }, + "node_modules/@vitest/expect": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.18.tgz", + "integrity": "sha512-8sCWUyckXXYvx4opfzVY03EOiYVxyNrHS5QxX3DAIi5dpJAAkyJezHCP77VMX4HKA2LDT/Jpfo8i2r5BE3GnQQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.0.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.0.18", + "@vitest/utils": "4.0.18", + "chai": "^6.2.1", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.18.tgz", + "integrity": "sha512-HhVd0MDnzzsgevnOWCBj5Otnzobjy5wLBe4EdeeFGv8luMsGcYqDuFRMcttKWZA5vVO8RFjexVovXvAM4JoJDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.0.18", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0-0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.18.tgz", + "integrity": "sha512-P24GK3GulZWC5tz87ux0m8OADrQIUVDPIjjj65vBXYG17ZeU3qD7r+MNZ1RNv4l8CGU2vtTRqixrOi9fYk/yKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.18.tgz", + "integrity": "sha512-rpk9y12PGa22Jg6g5M3UVVnTS7+zycIGk9ZNGN+m6tZHKQb7jrP7/77WfZy13Y/EUDd52NDsLRQhYKtv7XfPQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.0.18", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.18.tgz", + "integrity": "sha512-PCiV0rcl7jKQjbgYqjtakly6T1uwv/5BQ9SwBLekVg/EaYeQFPiXcgrC2Y7vDMA8dM1SUEAEV82kgSQIlXNMvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.0.18", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.18.tgz", + "integrity": "sha512-cbQt3PTSD7P2OARdVW3qWER5EGq7PHlvE+QfzSC0lbwO+xnt7+XH06ZzFjFRgzUX//JmpxrCu92VdwvEPlWSNw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.18.tgz", + "integrity": "sha512-msMRKLMVLWygpK3u2Hybgi4MNjcYJvwTb0Ru09+fOyCXIgT5raYP041DRRdiJiI3k/2U6SEbAETB3YtBrUkCFA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.0.18", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/acorn": { - "version": "8.15.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", - "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", "bin": { @@ -820,9 +1969,9 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", + "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "license": "MIT", "dependencies": { @@ -866,6 +2015,16 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "license": "Python-2.0" }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/ast-types": { "version": "0.13.4", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", @@ -878,10 +2037,29 @@ "node": ">=4" } }, + "node_modules/ast-v8-to-istanbul": { + "version": "0.3.11", + "resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-0.3.11.tgz", + "integrity": "sha512-Qya9fkoofMjCBNVdWINMjB5KZvkYfaO9/anwkWnjxibpWUxo5iHl2sOdP7/uAqaRuUYuoo8rDwnbaaKVFxoUvw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.31", + "estree-walker": "^3.0.3", + "js-tokens": "^10.0.0" + } + }, + "node_modules/ast-v8-to-istanbul/node_modules/js-tokens": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz", + "integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/b4a": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.7.3.tgz", - "integrity": "sha512-5Q2mfq2WfGuFp3uS//0s6baOJLMoVduPYVeNmDYxu5OUA1/cBfvr2RIS7vi62LdNj/urk1hfmj867I3qt6uZ7Q==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.8.0.tgz", + "integrity": "sha512-qRuSmNSkGQaHwNbM7J78Wwy+ghLEYF1zNrSeMxj4Kgw6y33O3mXcQ6Ie9fRvfU/YnxWkOchPXbaLb73TkIsfdg==", "license": "Apache-2.0", "peerDependencies": { "react-native-b4a": "*" @@ -893,11 +2071,14 @@ } }, "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.3.tgz", + "integrity": "sha512-1pHv8LX9CpKut1Zp4EXey7Z8OfH11ONNH6Dhi2WDUt31VVZFXZzKwXcysBgqSumFCmR+0dqjMK5v5JiFHzi0+g==", "dev": true, - "license": "MIT" + "license": "MIT", + "engines": { + "node": "20 || >=22" + } }, "node_modules/bare-events": { "version": "2.8.2", @@ -914,9 +2095,9 @@ } }, "node_modules/bare-fs": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.5.2.tgz", - "integrity": "sha512-veTnRzkb6aPHOvSKIOy60KzURfBdUflr5VReI+NSaPL6xf+XLdONQgZgpYvUuZLVQ8dCqxpBAudaOM1+KpAUxw==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.5.4.tgz", + "integrity": "sha512-POK4oplfA7P7gqvetNmCs4CNtm9fNsx+IAh7jH7GgU0OJdge2rso0R20TNWVq6VoWcCvsTdlNDaleLHGaKx8CA==", "license": "Apache-2.0", "optional": true, "dependencies": { @@ -959,13 +2140,14 @@ } }, "node_modules/bare-stream": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.7.0.tgz", - "integrity": "sha512-oyXQNicV1y8nc2aKffH+BUHFRXmx6VrPzlnaEvMhram0nPBrKcEdcyBg5r08D0i8VxngHFAiVyn1QKXpSG0B8A==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.8.0.tgz", + "integrity": "sha512-reUN0M2sHRqCdG4lUK3Fw8w98eeUIZHL5c3H7Mbhk2yVBL+oofgaIp0ieLfD5QXwPCypBpmEEKU2WZKzbAk8GA==", "license": "Apache-2.0", "optional": true, "dependencies": { - "streamx": "^2.21.0" + "streamx": "^2.21.0", + "teex": "^1.0.1" }, "peerDependencies": { "bare-buffer": "*", @@ -1000,14 +2182,16 @@ } }, "node_modules/brace-expansion": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", - "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.2.tgz", + "integrity": "sha512-Pdk8c9poy+YhOgVWw1JNN22/HcivgKWwpxKq04M/jTmHyCZn12WPJebZxdjSa5TmBqISrUSgNYU3eRORljfCCw==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" } }, "node_modules/buffer-crc32": { @@ -1019,6 +2203,40 @@ "node": "*" } }, + "node_modules/c8": { + "version": "10.1.3", + "resolved": "https://registry.npmjs.org/c8/-/c8-10.1.3.tgz", + "integrity": "sha512-LvcyrOAaOnrrlMpW22n690PUvxiq4Uf9WMhQwNJ9vgagkL/ph1+D4uvjvDA5XCbykrc0sx+ay6pVi9YZ1GnhyA==", + "dev": true, + "license": "ISC", + "dependencies": { + "@bcoe/v8-coverage": "^1.0.1", + "@istanbuljs/schema": "^0.1.3", + "find-up": "^5.0.0", + "foreground-child": "^3.1.1", + "istanbul-lib-coverage": "^3.2.0", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.1.6", + "test-exclude": "^7.0.1", + "v8-to-istanbul": "^9.0.0", + "yargs": "^17.7.2", + "yargs-parser": "^21.1.1" + }, + "bin": { + "c8": "bin/c8.js" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "monocart-coverage-reports": "^2" + }, + "peerDependenciesMeta": { + "monocart-coverage-reports": { + "optional": true + } + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -1028,27 +2246,20 @@ "node": ">=6" } }, - "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "node_modules/chai": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz", + "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", "dev": true, "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "node": ">=18" } }, "node_modules/chromium-bidi": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-12.0.1.tgz", - "integrity": "sha512-fGg+6jr0xjQhzpy5N4ErZxQ4wF7KLEvhGZXD6EgvZKDhu7iOhZXnZhcDxPJDcwTcrD48NPzOCo84RP2lv3Z+Cg==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-14.0.0.tgz", + "integrity": "sha512-9gYlLtS6tStdRWzrtXaTMnqcM4dudNegMXJxkR0I/CXObHalYeYcAMPrL19eroNZHtJ8DQmu1E+ZNOYu/IXMXw==", "license": "Apache-2.0", "dependencies": { "mitt": "^3.0.1", @@ -1090,10 +2301,10 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true, "license": "MIT" }, @@ -1195,15 +2406,15 @@ } }, "node_modules/devtools-protocol": { - "version": "0.0.1534754", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1534754.tgz", - "integrity": "sha512-26T91cV5dbOYnXdJi5qQHoTtUoNEqwkHcAyu/IKtjIAxiEqPMrDiRkDOPWVsGfNZGmlQVHQbZRSjD8sxagWVsQ==", + "version": "0.0.1566079", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1566079.tgz", + "integrity": "sha512-MJfAEA1UfVhSs7fbSQOG4czavUp1ajfg6prlAN0+cmfa2zNjaIbvq8VneP7do1WAQQIvgNJWSMeP6UyI90gIlQ==", "license": "BSD-3-Clause" }, "node_modules/dotenv": { - "version": "17.2.3", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz", - "integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==", + "version": "17.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.3.1.tgz", + "integrity": "sha512-IO8C/dzEb6O3F9/twg6ZLXz164a2fhTnEWb95H23Dm4OuN+92NmEAlTrupP9VW6Jm3sO26tQlqyvyi4CsnY9GA==", "license": "BSD-2-Clause", "engines": { "node": ">=12" @@ -1212,6 +2423,13 @@ "url": "https://dotenvx.com" } }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true, + "license": "MIT" + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -1245,6 +2463,55 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-module-lexer": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", + "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", + "dev": true, + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.3.tgz", + "integrity": "sha512-8VwMnyGCONIs6cWue2IdpHxHnAjzxnw2Zr7MkVxB2vjmQ2ivqGFb4LEG3SMnv0Gb2F/G/2yA8zUaiL1gywDCCg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.3", + "@esbuild/android-arm": "0.27.3", + "@esbuild/android-arm64": "0.27.3", + "@esbuild/android-x64": "0.27.3", + "@esbuild/darwin-arm64": "0.27.3", + "@esbuild/darwin-x64": "0.27.3", + "@esbuild/freebsd-arm64": "0.27.3", + "@esbuild/freebsd-x64": "0.27.3", + "@esbuild/linux-arm": "0.27.3", + "@esbuild/linux-arm64": "0.27.3", + "@esbuild/linux-ia32": "0.27.3", + "@esbuild/linux-loong64": "0.27.3", + "@esbuild/linux-mips64el": "0.27.3", + "@esbuild/linux-ppc64": "0.27.3", + "@esbuild/linux-riscv64": "0.27.3", + "@esbuild/linux-s390x": "0.27.3", + "@esbuild/linux-x64": "0.27.3", + "@esbuild/netbsd-arm64": "0.27.3", + "@esbuild/netbsd-x64": "0.27.3", + "@esbuild/openbsd-arm64": "0.27.3", + "@esbuild/openbsd-x64": "0.27.3", + "@esbuild/openharmony-arm64": "0.27.3", + "@esbuild/sunos-x64": "0.27.3", + "@esbuild/win32-arm64": "0.27.3", + "@esbuild/win32-ia32": "0.27.3", + "@esbuild/win32-x64": "0.27.3" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -1289,33 +2556,30 @@ } }, "node_modules/eslint": { - "version": "9.39.2", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.2.tgz", - "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.1.tgz", + "integrity": "sha512-20MV9SUdeN6Jd84xESsKhRly+/vxI+hwvpBMA93s+9dAcjdCuCojn4IqUGS3lvVaqjVYGYHSRMCpeFtF2rQYxQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", - "@eslint-community/regexpp": "^4.12.1", - "@eslint/config-array": "^0.21.1", - "@eslint/config-helpers": "^0.4.2", - "@eslint/core": "^0.17.0", - "@eslint/eslintrc": "^3.3.1", - "@eslint/js": "9.39.2", - "@eslint/plugin-kit": "^0.4.1", + "@eslint-community/regexpp": "^4.12.2", + "@eslint/config-array": "^0.23.2", + "@eslint/config-helpers": "^0.5.2", + "@eslint/core": "^1.1.0", + "@eslint/plugin-kit": "^0.6.0", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.12.4", - "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.4.0", - "eslint-visitor-keys": "^4.2.1", - "espree": "^10.4.0", - "esquery": "^1.5.0", + "eslint-scope": "^9.1.1", + "eslint-visitor-keys": "^5.0.1", + "espree": "^11.1.1", + "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", @@ -1325,8 +2589,7 @@ "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", - "lodash.merge": "^4.6.2", - "minimatch": "^3.1.2", + "minimatch": "^10.2.1", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, @@ -1334,7 +2597,7 @@ "eslint": "bin/eslint.js" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://eslint.org/donate" @@ -1349,48 +2612,50 @@ } }, "node_modules/eslint-scope": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", - "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.1.tgz", + "integrity": "sha512-GaUN0sWim5qc8KVErfPBWmc31LEsOkrUJbvJZV+xuL3u2phMUK4HIvXlWAakfC8W4nzlK+chPEAkYOYb5ZScIw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { + "@types/esrecurse": "^4.3.1", + "@types/estree": "^1.0.8", "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/eslint-visitor-keys": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", - "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", + "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true, "license": "Apache-2.0", "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/espree": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", - "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-11.1.1.tgz", + "integrity": "sha512-AVHPqQoZYc+RUM4/3Ly5udlZY/U4LS8pIG05jEjWM2lQMU/oaZ7qshzAl2YP1tfNmXfftH3ohurfwNAug+MnsQ==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.15.0", + "acorn": "^8.16.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.2.1" + "eslint-visitor-keys": "^5.0.1" }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" @@ -1444,6 +2709,16 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -1462,6 +2737,16 @@ "bare-events": "^2.7.0" } }, + "node_modules/expect-type": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", + "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/extract-zip": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", @@ -1518,6 +2803,24 @@ "pend": "~1.2.0" } }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", @@ -1569,6 +2872,38 @@ "dev": true, "license": "ISC" }, + "node_modules/foreground-child": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", + "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", + "dev": true, + "license": "ISC", + "dependencies": { + "cross-spawn": "^7.0.6", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1607,6 +2942,28 @@ "node": ">= 14" } }, + "node_modules/glob": { + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", + "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", + "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -1620,10 +2977,43 @@ "node": ">=10.13.0" } }, + "node_modules/glob/node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/glob/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/globals": { - "version": "17.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-17.0.0.tgz", - "integrity": "sha512-gv5BeD2EssA793rlFWVPMMCqefTlpusw6/2TbAVMy0FzcG8wKJn4O+NqJ4+XWmmwrayJgw5TzrmWjFgmz1XPqw==", + "version": "17.3.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.3.0.tgz", + "integrity": "sha512-yMqGUQVVCkD4tqjOJf3TnrvaaHDMYp4VlUSObbkIiuCPe/ofdMBFIAcBbCSRFWOnos6qRiTVStDwqPLUclaxIw==", "dev": true, "license": "MIT", "engines": { @@ -1643,6 +3033,13 @@ "node": ">=8" } }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true, + "license": "MIT" + }, "node_modules/http-proxy-agent": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", @@ -1759,6 +3156,61 @@ "dev": true, "license": "ISC" }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.2.0.tgz", + "integrity": "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/jackspeak": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", + "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1850,13 +3302,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true, - "license": "MIT" - }, "node_modules/lru-cache": { "version": "7.18.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", @@ -1866,17 +3311,68 @@ "node": ">=12" } }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", "dev": true, - "license": "ISC", + "license": "MIT", "dependencies": { - "brace-expansion": "^1.1.7" + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/magicast": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.2.tgz", + "integrity": "sha512-E3ZJh4J3S9KfwdjZhe2afj6R9lGIN5Pher1pF39UGrXRqq/VDaGVIGN13BjHd2u8B61hArAGOnso7nBOouW3TQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.0", + "@babel/types": "^7.29.0", + "source-map-js": "^1.2.1" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" }, "engines": { - "node": "*" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimatch": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.2.tgz", + "integrity": "sha512-+G4CpNBxa5MprY+04MbgOw1v7So6n5JY166pFi9KfYwT78fxScCeSNQSNzp6dpPSW2rONOps6Ocam1wFhCgoVw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/minipass": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz", + "integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=16 || 14 >=14.17" } }, "node_modules/mitt": { @@ -1891,6 +3387,25 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/nanoid": { + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", + "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -1907,6 +3422,17 @@ "node": ">= 0.4.0" } }, + "node_modules/obug": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz", + "integrity": "sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT" + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1998,6 +3524,13 @@ "node": ">= 14" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -2048,6 +3581,37 @@ "node": ">=8" } }, + "node_modules/path-scurry": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -2060,6 +3624,48 @@ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "license": "ISC" }, + "node_modules/picomatch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", + "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.6", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", + "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.11", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -2125,17 +3731,17 @@ } }, "node_modules/puppeteer": { - "version": "24.34.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.34.0.tgz", - "integrity": "sha512-Sdpl/zsYOsagZ4ICoZJPGZw8d9gZmK5DcxVal11dXi/1/t2eIXHjCf5NfmhDg5XnG9Nye+yo/LqMzIxie2rHTw==", + "version": "24.37.5", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.37.5.tgz", + "integrity": "sha512-3PAOIQLceyEmn1Fi76GkGO2EVxztv5OtdlB1m8hMUZL3f8KDHnlvXbvCXv+Ls7KzF1R0KdKBqLuT/Hhrok12hQ==", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@puppeteer/browsers": "2.11.0", - "chromium-bidi": "12.0.1", + "@puppeteer/browsers": "2.13.0", + "chromium-bidi": "14.0.0", "cosmiconfig": "^9.0.0", - "devtools-protocol": "0.0.1534754", - "puppeteer-core": "24.34.0", + "devtools-protocol": "0.0.1566079", + "puppeteer-core": "24.37.5", "typed-query-selector": "^2.12.0" }, "bin": { @@ -2146,18 +3752,18 @@ } }, "node_modules/puppeteer-core": { - "version": "24.34.0", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.34.0.tgz", - "integrity": "sha512-24evawO+mUGW4mvS2a2ivwLdX3gk8zRLZr9HP+7+VT2vBQnm0oh9jJEZmUE3ePJhRkYlZ93i7OMpdcoi2qNCLg==", + "version": "24.37.5", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.37.5.tgz", + "integrity": "sha512-ybL7iE78YPN4T6J+sPLO7r0lSByp/0NN6PvfBEql219cOnttoTFzCWKiBOjstXSqi/OKpwae623DWAsL7cn2MQ==", "license": "Apache-2.0", "dependencies": { - "@puppeteer/browsers": "2.11.0", - "chromium-bidi": "12.0.1", + "@puppeteer/browsers": "2.13.0", + "chromium-bidi": "14.0.0", "debug": "^4.4.3", - "devtools-protocol": "0.0.1534754", + "devtools-protocol": "0.0.1566079", "typed-query-selector": "^2.12.0", - "webdriver-bidi-protocol": "0.3.10", - "ws": "^8.18.3" + "webdriver-bidi-protocol": "0.4.1", + "ws": "^8.19.0" }, "engines": { "node": ">=18" @@ -2181,10 +3787,55 @@ "node": ">=4" } }, + "node_modules/rollup": { + "version": "4.58.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.58.0.tgz", + "integrity": "sha512-wbT0mBmWbIvvq8NeEYWWvevvxnOyhKChir47S66WCxw1SXqhw7ssIYejnQEVt7XYQpsj2y8F9PM+Cr3SNEa0gw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.8" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.58.0", + "@rollup/rollup-android-arm64": "4.58.0", + "@rollup/rollup-darwin-arm64": "4.58.0", + "@rollup/rollup-darwin-x64": "4.58.0", + "@rollup/rollup-freebsd-arm64": "4.58.0", + "@rollup/rollup-freebsd-x64": "4.58.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.58.0", + "@rollup/rollup-linux-arm-musleabihf": "4.58.0", + "@rollup/rollup-linux-arm64-gnu": "4.58.0", + "@rollup/rollup-linux-arm64-musl": "4.58.0", + "@rollup/rollup-linux-loong64-gnu": "4.58.0", + "@rollup/rollup-linux-loong64-musl": "4.58.0", + "@rollup/rollup-linux-ppc64-gnu": "4.58.0", + "@rollup/rollup-linux-ppc64-musl": "4.58.0", + "@rollup/rollup-linux-riscv64-gnu": "4.58.0", + "@rollup/rollup-linux-riscv64-musl": "4.58.0", + "@rollup/rollup-linux-s390x-gnu": "4.58.0", + "@rollup/rollup-linux-x64-gnu": "4.58.0", + "@rollup/rollup-linux-x64-musl": "4.58.0", + "@rollup/rollup-openbsd-x64": "4.58.0", + "@rollup/rollup-openharmony-arm64": "4.58.0", + "@rollup/rollup-win32-arm64-msvc": "4.58.0", + "@rollup/rollup-win32-ia32-msvc": "4.58.0", + "@rollup/rollup-win32-x64-gnu": "4.58.0", + "@rollup/rollup-win32-x64-msvc": "4.58.0", + "fsevents": "~2.3.2" + } + }, "node_modules/semver": { - "version": "7.7.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", - "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -2260,6 +3911,26 @@ "node": ">=8" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -2308,6 +3979,30 @@ "node": ">=0.10.0" } }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", + "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", + "dev": true, + "license": "MIT" + }, "node_modules/streamx": { "version": "2.23.0", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.23.0.tgz", @@ -2333,6 +4028,22 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -2345,17 +4056,18 @@ "node": ">=8" } }, - "node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, "engines": { "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/supports-color": { @@ -2396,15 +4108,117 @@ "streamx": "^2.15.0" } }, + "node_modules/teex": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz", + "integrity": "sha512-eYE6iEI62Ni1H8oIa7KlDU6uQBtqr4Eajni3wX7rpfXD8ysFx8z0+dri+KWEPWpBsxXfxu58x/0jvTVT1ekOSg==", + "license": "MIT", + "optional": true, + "dependencies": { + "streamx": "^2.12.5" + } + }, + "node_modules/test-exclude": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.1.tgz", + "integrity": "sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==", + "dev": true, + "license": "ISC", + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^10.4.1", + "minimatch": "^9.0.4" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/test-exclude/node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/test-exclude/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/test-exclude/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/text-decoder": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.3.tgz", - "integrity": "sha512-3/o9z3X0X0fTupwsYvR03pJ/DjWuqqrfwBgTQzdWDiQSm9KitAyz/9WqsT2JQW7KV2m+bC2ol/zqpW37NHxLaA==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz", + "integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==", "license": "Apache-2.0", "dependencies": { "b4a": "^1.6.4" } }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.2.tgz", + "integrity": "sha512-W/KYk+NFhkmsYpuHq5JykngiOCnxeVL8v8dFnqxSD8qEEdRfXk1SDM6JzNqcERbcGYj9tMrDQBYV9cjgnunFIg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", + "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.3" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyrainbow": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.0.3.tgz", + "integrity": "sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -2431,9 +4245,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "7.16.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", - "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", "license": "MIT", "optional": true }, @@ -2447,10 +4261,178 @@ "punycode": "^2.1.0" } }, + "node_modules/v8-to-istanbul": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", + "integrity": "sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==", + "dev": true, + "license": "ISC", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.12", + "@types/istanbul-lib-coverage": "^2.0.1", + "convert-source-map": "^2.0.0" + }, + "engines": { + "node": ">=10.12.0" + } + }, + "node_modules/vite": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz", + "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.27.0", + "fdir": "^6.5.0", + "picomatch": "^4.0.3", + "postcss": "^8.5.6", + "rollup": "^4.43.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "lightningcss": "^1.21.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.18.tgz", + "integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.0.18", + "@vitest/mocker": "4.0.18", + "@vitest/pretty-format": "4.0.18", + "@vitest/runner": "4.0.18", + "@vitest/snapshot": "4.0.18", + "@vitest/spy": "4.0.18", + "@vitest/utils": "4.0.18", + "es-module-lexer": "^1.7.0", + "expect-type": "^1.2.2", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^3.10.0", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.0.3", + "vite": "^6.0.0 || ^7.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.0.18", + "@vitest/browser-preview": "4.0.18", + "@vitest/browser-webdriverio": "4.0.18", + "@vitest/ui": "4.0.18", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, "node_modules/webdriver-bidi-protocol": { - "version": "0.3.10", - "resolved": "https://registry.npmjs.org/webdriver-bidi-protocol/-/webdriver-bidi-protocol-0.3.10.tgz", - "integrity": "sha512-5LAE43jAVLOhB/QqX4bwSiv0Hg1HBfMmOuwBSXHdvg4GMGu9Y0lIq7p4R/yySu6w74WmaR4GM4H9t2IwLW7hgw==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/webdriver-bidi-protocol/-/webdriver-bidi-protocol-0.4.1.tgz", + "integrity": "sha512-ARrjNjtWRRs2w4Tk7nqrf2gBI0QXWuOmMCx2hU+1jUt6d00MjMxURrhxhGbrsoiZKJrhTSTzbIrc554iKI10qw==", "license": "Apache-2.0" }, "node_modules/which": { @@ -2469,6 +4451,23 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -2496,6 +4495,25 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index ead3789..488c451 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "main": "index.js", "type": "module", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "test:integration": "node --test test/integration.test.js", + "test": "vitest run", + "test:unit": "vitest run --exclude '**/integration/**'", + "test:coverage": "vitest run --coverage --exclude '**/integration/**'", + "test:integration": "vitest run --config vitest.integration.config.js", "lint": "eslint .", "start": "node index.js" }, @@ -18,8 +20,10 @@ "sharp": "^0.34.3" }, "devDependencies": { - "@eslint/js": "^9.34.0", - "eslint": "^9.34.0", - "globals": "^17.0.0" + "@eslint/js": "^10.0.0", + "@vitest/coverage-v8": "^4.0.18", + "eslint": "^10.0.0", + "globals": "^17.0.0", + "vitest": "^4.0.18" } } diff --git a/src/contentFixes.js b/src/contentFixes.js new file mode 100644 index 0000000..58479cf --- /dev/null +++ b/src/contentFixes.js @@ -0,0 +1,290 @@ +import { + extractCanonicalNames, + validateContentCompleteness, + validateContentQuality, + validateContentStructure, + validateNarrativeCoherence, +} from "./validation.js"; + +export function validateNameConsistency(dungeonData) { + const canonicalNames = extractCanonicalNames(dungeonData); + const fixes = []; + const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + canonicalNames.npcs.forEach(canonicalName => { + if (dungeonData.flavor) { + const original = dungeonData.flavor; + dungeonData.flavor = dungeonData.flavor.replace(new RegExp(escapeRe(canonicalName), 'gi'), canonicalName); + if (original !== dungeonData.flavor) fixes.push(`Fixed NPC name in flavor text: ${canonicalName}`); + } + if (dungeonData.hooksRumors) { + dungeonData.hooksRumors = dungeonData.hooksRumors.map(hook => { + const original = hook; + const fixed = hook.replace(new RegExp(escapeRe(canonicalName), 'gi'), canonicalName); + if (original !== fixed) fixes.push(`Fixed NPC name in hook: ${canonicalName}`); + return fixed; + }); + } + if (dungeonData.encounters) { + dungeonData.encounters.forEach(encounter => { + if (encounter.details) { + const original = encounter.details; + encounter.details = encounter.details.replace(new RegExp(escapeRe(canonicalName), 'gi'), canonicalName); + if (original !== encounter.details) fixes.push(`Fixed NPC name in encounter: ${canonicalName}`); + } + }); + } + if (dungeonData.plotResolutions) { + dungeonData.plotResolutions = dungeonData.plotResolutions.map(resolution => { + const original = resolution; + const fixed = resolution.replace(new RegExp(escapeRe(canonicalName), 'gi'), canonicalName); + if (original !== fixed) fixes.push(`Fixed NPC name in plot resolution: ${canonicalName}`); + return fixed; + }); + } + }); + + canonicalNames.rooms.forEach(canonicalRoom => { + if (dungeonData.encounters) { + dungeonData.encounters.forEach(encounter => { + if (encounter.details) { + const original = encounter.details; + encounter.details = encounter.details.replace(new RegExp(escapeRe(canonicalRoom), 'gi'), canonicalRoom); + if (original !== encounter.details) fixes.push(`Fixed room name in encounter: ${canonicalRoom}`); + } + }); + } + }); + return fixes; +} + +export function standardizeEncounterLocations(encounters, rooms) { + if (!encounters || !rooms) return { encounters, fixes: [] }; + const roomNames = rooms.map(r => r.name.trim()); + const fixes = []; + const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const fixedEncounters = encounters.map(encounter => { + if (!encounter.details) return encounter; + const standardized = roomNames.reduce((details, roomName) => { + const roomNameRegex = new RegExp(`^${escapeRe(roomName)}\\s*:?\\s*`, 'i'); + if (!roomNameRegex.test(details)) return details; + const hasColon = details.match(new RegExp(`^${escapeRe(roomName)}:`, 'i')); + if (hasColon) return details; + fixes.push(`Standardized location format for encounter: ${encounter.name}`); + return details.replace(roomNameRegex, `${roomName}: `); + }, encounter.details.trim()); + return standardized !== encounter.details ? { ...encounter, details: standardized } : encounter; + }); + return { encounters: fixedEncounters, fixes }; +} + +export function fixStructureIssues(dungeonData) { + const fixes = []; + if (dungeonData.rooms) { + dungeonData.rooms.forEach((room, i) => { + if (!room.name || !room.name.trim()) { + const desc = room.description || ''; + const nameMatch = desc.match(/^([A-Z][^.!?]{5,30}?)(?:\s|\.|:)/); + if (nameMatch) { + room.name = nameMatch[1].trim(); + fixes.push(`Extracted room name from description: "${room.name}"`); + } else { + room.name = `Room ${i + 1}`; + fixes.push(`Added default name for room ${i + 1}`); + } + } + const words = room.name.split(/\s+/); + if (words.length > 6) { + const original = room.name; + room.name = words.slice(0, 6).join(' '); + fixes.push(`Truncated room name: "${original}" -> "${room.name}"`); + } + }); + } + if (dungeonData.encounters) { + dungeonData.encounters.forEach((encounter, i) => { + if (!encounter.name || !encounter.name.trim()) { + const details = encounter.details || ''; + const nameMatch = details.match(/^([^:]+):\s*(.+)$/); + if (nameMatch) { + encounter.name = nameMatch[1].trim(); + encounter.details = nameMatch[2].trim(); + fixes.push(`Extracted encounter name from details: "${encounter.name}"`); + } else { + encounter.name = `Encounter ${i + 1}`; + fixes.push(`Added default name for encounter ${i + 1}`); + } + } + const words = encounter.name.split(/\s+/); + if (words.length > 6) { + const original = encounter.name; + encounter.name = words.slice(0, 6).join(' '); + fixes.push(`Truncated encounter name: "${original}" -> "${encounter.name}"`); + } + }); + } + if (dungeonData.npcs) { + dungeonData.npcs.forEach((npc, i) => { + if (!npc.name || !npc.name.trim()) { + const trait = npc.trait || ''; + const nameMatch = trait.match(/^([A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,2})(?:\s|:)/); + if (nameMatch) { + npc.name = nameMatch[1].trim(); + fixes.push(`Extracted NPC name from trait: "${npc.name}"`); + } else { + npc.name = `NPC ${i + 1}`; + fixes.push(`Added default name for NPC ${i + 1}`); + } + } + const words = npc.name.split(/\s+/); + if (words.length > 4) { + const original = npc.name; + npc.name = words.slice(0, 4).join(' '); + fixes.push(`Truncated NPC name: "${original}" -> "${npc.name}"`); + } + }); + } + return fixes; +} + +export function fixMissingContent(dungeonData) { + const fixes = []; + if (!dungeonData.npcs || dungeonData.npcs.length < 4) { + if (!dungeonData.npcs) dungeonData.npcs = []; + const factionName = dungeonData.coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction'; + while (dungeonData.npcs.length < 4) { + dungeonData.npcs.push({ + name: `NPC ${dungeonData.npcs.length + 1}`, + trait: `A member of ${factionName.toLowerCase()} with unknown motives.` + }); + fixes.push(`Added fallback NPC ${dungeonData.npcs.length}`); + } + } + if (!dungeonData.encounters || dungeonData.encounters.length < 6) { + if (!dungeonData.encounters) dungeonData.encounters = []; + if (dungeonData.encounters.length > 0 && dungeonData.rooms?.length > 0) { + const dynamicElement = dungeonData.coreConcepts?.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; + const conflict = dungeonData.coreConcepts?.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a threat'; + while (dungeonData.encounters.length < 6) { + const roomIndex = dungeonData.encounters.length % dungeonData.rooms.length; + const roomName = dungeonData.rooms[roomIndex]?.name || 'Unknown Location'; + const fallbackNames = [ + `${roomName} Guardian`, `${roomName} Threat`, `${roomName} Challenge`, + `${dynamicElement.split(' ')[0]} Manifestation`, `${conflict.split(' ')[0]} Encounter`, `${roomName} Hazard` + ]; + dungeonData.encounters.push({ + name: fallbackNames[dungeonData.encounters.length % fallbackNames.length], + details: `${roomName}: An encounter related to ${dynamicElement.toLowerCase()} occurs here.` + }); + fixes.push(`Added fallback encounter: "${dungeonData.encounters[dungeonData.encounters.length - 1].name}"`); + } + } + } + if (!dungeonData.treasure || dungeonData.treasure.length < 4) { + if (!dungeonData.treasure) dungeonData.treasure = []; + while (dungeonData.treasure.length < 4) { + dungeonData.treasure.push({ + name: `Treasure ${dungeonData.treasure.length + 1}`, + description: `A mysterious item found in the dungeon.` + }); + fixes.push(`Added fallback treasure ${dungeonData.treasure.length}`); + } + } + if (!dungeonData.randomEvents || dungeonData.randomEvents.length < 6) { + if (!dungeonData.randomEvents) dungeonData.randomEvents = []; + if (dungeonData.randomEvents.length > 0 && dungeonData.coreConcepts) { + const dynamicElement = dungeonData.coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; + const conflict = dungeonData.coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat'; + const fallbackEvents = [ + { name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` }, + { name: 'Conflict Manifestation', description: `A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.` }, + { name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` }, + { name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` }, + { name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` }, + { name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` } + ]; + while (dungeonData.randomEvents.length < 6) { + dungeonData.randomEvents.push(fallbackEvents[dungeonData.randomEvents.length % fallbackEvents.length]); + fixes.push(`Added fallback random event: "${dungeonData.randomEvents[dungeonData.randomEvents.length - 1].name}"`); + } + } + } + if (!dungeonData.plotResolutions || dungeonData.plotResolutions.length < 4) { + if (!dungeonData.plotResolutions) dungeonData.plotResolutions = []; + while (dungeonData.plotResolutions.length < 4) { + dungeonData.plotResolutions.push(`The adventurers could resolve the central conflict through decisive action.`); + fixes.push(`Added fallback plot resolution ${dungeonData.plotResolutions.length}`); + } + } + return fixes; +} + +export function fixNarrativeCoherence(dungeonData) { + const fixes = []; + if (dungeonData.encounters && dungeonData.rooms) { + const roomNames = dungeonData.rooms.map(r => r.name.trim().toLowerCase()); + dungeonData.encounters.forEach(encounter => { + if (!encounter.details) return; + const locationMatch = encounter.details.match(/^([^:]+):/); + if (locationMatch) { + const locName = locationMatch[1].trim().toLowerCase(); + const matches = roomNames.some(rn => + locName === rn || locName.includes(rn) || rn.includes(locName) || + locName.split(/\s+/).some(word => rn.includes(word)) + ); + if (!matches && roomNames.length > 0) { + const roomIdx = Math.floor(Math.random() * roomNames.length); + const roomName = dungeonData.rooms[roomIdx].name; + encounter.details = encounter.details.replace(/^[^:]+:\s*/, `${roomName}: `); + fixes.push(`Fixed unknown location in encounter "${encounter.name}" to "${roomName}"`); + } + } + }); + } + return fixes; +} + +export function validateAndFixContent(dungeonData) { + const allFixes = []; + const nameFixes = validateNameConsistency(dungeonData); + allFixes.push(...nameFixes); + const structureFixes = fixStructureIssues(dungeonData); + allFixes.push(...structureFixes); + if (dungeonData.encounters && dungeonData.rooms) { + const roomNames = dungeonData.rooms.map(r => r.name.trim()); + dungeonData.encounters.forEach((encounter, idx) => { + if (!encounter.details) return; + if (!encounter.details.match(/^[^:]+:\s/)) { + const roomIdx = idx % roomNames.length; + const roomName = roomNames[roomIdx]; + encounter.details = `${roomName}: ${encounter.details}`; + allFixes.push(`Added location "${roomName}" to encounter "${encounter.name}"`); + } + }); + const locationResult = standardizeEncounterLocations(dungeonData.encounters, dungeonData.rooms); + dungeonData.encounters = locationResult.encounters; + allFixes.push(...locationResult.fixes); + } + const coherenceFixes = fixNarrativeCoherence(dungeonData); + allFixes.push(...coherenceFixes); + const contentFixes = fixMissingContent(dungeonData); + allFixes.push(...contentFixes); + + const allIssues = [ + ...validateContentCompleteness(dungeonData), + ...validateContentQuality(dungeonData), + ...validateContentStructure(dungeonData), + ...validateNarrativeCoherence(dungeonData), + ]; + if (allFixes.length > 0) { + console.log("\n[Validation] Applied fixes:"); + allFixes.forEach(fix => console.log(` - ${fix}`)); + } + if (allIssues.length > 0) { + console.log("\n[Validation] Content quality issues found (not auto-fixable):"); + allIssues.forEach(issue => console.warn(` ⚠ ${issue}`)); + } else { + console.log("\n[Validation] Content quality checks passed"); + } + return dungeonData; +} diff --git a/src/dungeonBuild.js b/src/dungeonBuild.js new file mode 100644 index 0000000..2f43271 --- /dev/null +++ b/src/dungeonBuild.js @@ -0,0 +1,106 @@ +export function deduplicateRoomsByName(rooms) { + if (!rooms || rooms.length === 0) return []; + const seenNames = new Set(); + return rooms.filter(room => { + if (!room || !room.name) return false; + const nameLower = room.name.toLowerCase().trim(); + if (seenNames.has(nameLower)) { + console.warn(`Duplicate room name detected: "${room.name}", skipping duplicate`); + return false; + } + seenNames.add(nameLower); + return true; + }); +} + +export function padNpcsToMinimum(parsedNpcs, coreConcepts, minCount = 4) { + const factionName = coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction'; + if (!parsedNpcs || parsedNpcs.length >= minCount || parsedNpcs.length === 0) return parsedNpcs || []; + const list = [...parsedNpcs]; + while (list.length < minCount) { + list.push({ + name: `NPC ${list.length + 1}`, + trait: `A member of ${factionName.toLowerCase()} with unknown motives.` + }); + } + return list; +} + +export function buildEncountersList(parsedEncounters, rooms, coreConcepts) { + const dynamicElement = coreConcepts?.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; + const conflict = coreConcepts?.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a threat'; + const fallbackNames = (roomName) => [ + `${roomName} Guardian`, + `${roomName} Threat`, + `${roomName} Challenge`, + `${dynamicElement.split(' ')[0]} Manifestation`, + `${conflict.split(' ')[0]} Encounter`, + `${roomName} Hazard` + ]; + + if (parsedEncounters.length > 0 && parsedEncounters.length < 6) { + return [ + ...parsedEncounters, + ...Array.from({ length: 6 - parsedEncounters.length }, (_, i) => { + const roomIndex = (parsedEncounters.length + i) % rooms.length; + const roomName = rooms[roomIndex]?.name || 'Unknown Location'; + return { + name: fallbackNames(roomName)[(parsedEncounters.length + i) % 6], + details: `An encounter related to ${dynamicElement.toLowerCase()} occurs here.` + }; + }) + ]; + } + if (parsedEncounters.length === 0) { + return Array.from({ length: 6 }, (_, i) => { + const roomName = rooms[i % rooms.length]?.name || 'Unknown Location'; + return { name: `${roomName} Encounter`, details: `An encounter related to ${dynamicElement.toLowerCase()} occurs here.` }; + }); + } + return parsedEncounters; +} + +export function mergeRandomEventsWithFallbacks(parsedEvents, coreConcepts, maxCount = 6) { + const dynamicElement = coreConcepts?.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences'; + const conflict = (coreConcepts?.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat').toLowerCase(); + const fallbackEvents = [ + { name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` }, + { name: 'Conflict Manifestation', description: `A sign of ${conflict} appears, requiring immediate attention.` }, + { name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` }, + { name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` }, + { name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` }, + { name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` } + ]; + const truncated = (parsedEvents || []).slice(0, maxCount); + if (truncated.length > 0 && truncated.length < maxCount) { + return [ + ...truncated, + ...Array.from({ length: maxCount - truncated.length }, (_, i) => + fallbackEvents[(truncated.length + i) % fallbackEvents.length]) + ]; + } + return truncated; +} + +export function limitIntermediateRooms(rooms, maxCount = 3) { + if (rooms.length > maxCount) { + console.warn(`Expected exactly ${maxCount} intermediate locations but got ${rooms.length}, limiting to first ${maxCount}`); + } + return rooms.slice(0, maxCount); +} + +export function fixRoomPlaceholderName(room) { + if (!room) return room; + if (room.name && (room.name.toLowerCase().includes('room name') || room.name.toLowerCase() === 'room name')) { + const desc = room.description || ''; + const nameMatch = desc.match(/^([^:]+?)(?:\s+Description|\s*:)/i) || desc.match(/^([A-Z][^.!?]{5,40}?)(?:\s+is\s|\.)/); + if (nameMatch) { + room.name = nameMatch[1].trim().replace(/^(The|A|An)\s+/i, '').trim(); + room.description = desc.replace(new RegExp(`^${nameMatch[1]}\\s*(Description|:)?\\s*`, 'i'), '').trim(); + } else { + const words = desc.split(/\s+/).slice(0, 4).join(' '); + room.name = words.replace(/^(The|A|An)\s+/i, '').trim(); + } + } + return room; +} diff --git a/src/dungeonGenerator.js b/src/dungeonGenerator.js new file mode 100644 index 0000000..7bda426 --- /dev/null +++ b/src/dungeonGenerator.js @@ -0,0 +1,323 @@ +import { callOllama } from "./ollamaClient.js"; +import { cleanText } from "./textUtils.js"; +import { + parseList, + parseObjects, + parseMainContentSections, + parseRandomEventsRaw, + splitCombinedEncounters, +} from "./parsing.js"; +import { + deduplicateRoomsByName, + padNpcsToMinimum, + buildEncountersList, + mergeRandomEventsWithFallbacks, + limitIntermediateRooms, + fixRoomPlaceholderName, +} from "./dungeonBuild.js"; +import { validateAndFixContent } from "./contentFixes.js"; + +export async function generateDungeon() { + // Step 1: Titles + const generatedTitles = await callOllama( + `Generate 50 short, punchy dungeon titles (max 5 words each), numbered as a plain text list. + Each title should come from a different style or theme. Make the set varied and evocative. For example: + + - OSR / classic tabletop: gritty, mysterious, old-school + - Mörk Borg: dark, apocalyptic, foreboding + - Pulpy fantasy: adventurous, dramatic, larger-than-life + - Mildly sci-fi: alien, technological, strange + - Weird fantasy: uncanny, surreal, unsettling + - Whimsical: fun, quirky, playful + + CRITICAL: Ensure all spelling is correct. Double-check all words before outputting. + Avoid repeating materials or adjectives. Absolutely do not use the words "Obsidian" or "Clockwork" in any title. Do not include explanations, markdown, or preambles. Do not include the style or theme in parenthesis. Only the 50 numbered titles. Do not include the theme in the name of the title (no parenthesis).`, + undefined, 5, "Step 1: Titles" + ); + console.log("Generated Titles:", generatedTitles); + const titlesList = parseList(generatedTitles); + const title = titlesList[Math.floor(Math.random() * titlesList.length)]; + console.log("Selected title:", title); + + // Step 2: Core Concepts + const coreConceptsRaw = await callOllama( + `For a dungeon titled "${title}", generate three core concepts: a central conflict, a primary faction, and a major environmental hazard or dynamic element. +Output as a numbered list with bolded headings. Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output. +Example: +1. **Central Conflict:** The dungeon's power source is failing, causing reality to warp. +2. **Primary Faction:** A group of rival cultists trying to seize control of the power source. +3. **Dynamic Element:** Zones of temporal distortion that cause random, brief time shifts.`, + undefined, 5, "Step 2: Core Concepts" + ); + const coreConcepts = coreConceptsRaw; + console.log("Core Concepts:", coreConcepts); + + // Step 3: Flavor Text & Hooks + const flavorHooksRaw = await callOllama( + `Based on the title "${title}" and these core concepts: +${coreConcepts} +Write a single evocative paragraph describing the location. Maximum 2 sentences. Maximum 50-60 words. Then, generate 4-5 short adventure hooks or rumors. +The hooks should reference the central conflict, faction, and dynamic element. Hooks should suggest different approaches (stealth, diplomacy, force, exploration) and create anticipation. + +EXAMPLE OF GOOD HOOK: +"A merchant's cart was found abandoned near the entrance, its cargo of rare herbs scattered. The merchant's journal mentions strange lights in the depths and a warning about 'the watchers'." + +CRITICAL: Hooks must be concise to fit in a single column on a one-page dungeon layout. Each hook must be 25-30 words maximum. Be specific with details, not vague. +CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns and technical terms. +Output two sections labeled "Description:" and "Hooks & Rumors:". Use a numbered list for the hooks. Plain text only. Do not use em-dashes (—) anywhere in the output. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, + undefined, 5, "Step 3: Flavor & Hooks" + ); + const [flavorSection, hooksSection] = flavorHooksRaw.split(/Hooks & Rumors[:\n]/i); + const rawFlavor = cleanText(flavorSection.replace(/Description[:\n]*/i, "")); + const flavorWords = rawFlavor.split(/\s+/); + const flavor = flavorWords.length > 60 ? flavorWords.slice(0, 60).join(' ') + '...' : rawFlavor; + const hooksRumors = parseList(hooksSection || "").map(h => h.replace(/^[^:]+:\s*/, '').trim()); + console.log("Flavor Text:", flavor); + console.log("Hooks & Rumors:", hooksRumors); + + // Step 4: Key Rooms + const keyRoomsRaw = await callOllama( + `Based on the title "${title}", description "${flavor}", and these core concepts: +${coreConcepts} +Generate two key rooms that define the dungeon's narrative arc. +CRITICAL: These rooms need rich environmental and tactical details with multiple interaction possibilities. + +EXAMPLE OF GOOD ROOM DESCRIPTION: +"Chamber of Echoes: Flickering torchlight casts dancing shadows across moss-covered walls. A constant dripping echoes from stalactites overhead, and the air smells of damp earth and ozone. Three stone pillars provide cover, while a raised dais in the center offers high ground. A rusted lever on the west wall controls a hidden portcullis. The floor is slick with moisture, making movement difficult." + +1. Entrance Room: Give it a name (max 5 words) and a description (25-35 words) that MUST include: + - Immediate observable features and environmental details (lighting, sounds, smells, textures, temperature, visibility) + - Interactable elements that players can use (levers, objects, portals, mechanisms, environmental hazards) + - Tactical considerations (cover, elevation, movement restrictions, line of sight) + - Sets the tone and introduces the environmental hazard/dynamic element + +2. Climax Room: Give it a name (max 5 words) and a description (25-35 words) that MUST include: + - Connection to the primary faction and the central conflict + - Rich environmental and tactical details + - Multiple approach options or solutions + - Tactical considerations and environmental factors that affect gameplay + +EXACT FORMAT REQUIRED - each room on its own numbered line: +1. Room Name: Description text here. +2. Room Name: Description text here. + +CRITICAL: Ensure all spelling is correct. Double-check all words before outputting. +CRITICAL: Be specific and concrete. Avoid vague words like "some", "various", "several" without details. +Output ONLY the two numbered items, one per line. Use colons (:) to separate room names from descriptions, not em-dashes. Do not use em-dashes (—) anywhere. Do not combine items. Do not use bolded headings. Do not include any intro or other text. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, + undefined, 5, "Step 4: Key Rooms" + ); + const [entranceSection, climaxSection] = keyRoomsRaw.split(/\n?2[).] /); + const entranceRoom = parseObjects(entranceSection, "rooms")[0]; + const climaxRoom = parseObjects(`1. ${climaxSection}`, "rooms")[0]; + + if (entranceRoom) fixRoomPlaceholderName(entranceRoom); + if (climaxRoom) fixRoomPlaceholderName(climaxRoom); + + console.log("Entrance Room:", entranceRoom); + console.log("Climax Room:", climaxRoom); + + // Step 5: Main Content (Locations, Encounters, NPCs, Treasures, Random Events) + const mainContentRaw = await callOllama( + `Based on the following dungeon elements and the need for narrative flow: +Title: "${title}" +Description: "${flavor}" +Core Concepts: +${coreConcepts} +Entrance Room: ${JSON.stringify(entranceRoom)} +Climax Room: ${JSON.stringify(climaxRoom)} + +Generate the rest of the dungeon's content to fill the space between the entrance and the climax. CRITICAL: All content must fit on a single one-page dungeon layout with three columns. Keep descriptions rich and evocative with tactical/environmental details. + +- **Strictly 3 Locations (EXACTLY 3, no more, no less):** Each with a name (max 6 words) and a description (25-35 words). Each room MUST include: + - Rich environmental features that affect gameplay (lighting, sounds, smells, textures, temperature, visibility) + - Interactable elements that players can use (levers, objects, portals, mechanisms, environmental hazards) + - Multiple approaches or solutions to challenges in the room + - Tactical considerations (cover, elevation, movement restrictions, line of sight) + - Hidden aspects discoverable through interaction or investigation + Format as "Name: description" using colons, NOT em-dashes. + +EXAMPLE LOCATION: +"Whispering Gallery: Dim phosphorescent fungi line the walls, casting an eerie green glow. The air hums with a low-frequency vibration that makes conversation difficult. Two collapsed pillars create natural cover, while a narrow ledge 10 feet up offers a sniper position. A hidden pressure plate near the entrance triggers a portcullis trap." + +- **Strictly 6 Encounters:** Numbered 1-6 (for d6 rolling). Name (max 6 words) and details (2 sentences MAX, approximately 25-40 words). Each encounter MUST: + - Start with the room/location name followed by a colon, then the details (e.g., "Location Name: Details text") + - The location name must match one of the actual room names from this dungeon + - Include environmental hazards/opportunities (cover, elevation, traps, interactable objects, terrain features) + - Include tactical considerations (positioning, line of sight, escape routes, bottlenecks, high ground) + - Offer multiple resolution options (combat, negotiation, stealth, puzzle-solving, environmental manipulation, timing-based solutions) + - Include consequences and outcomes tied to player choices + - Integrate with the environmental dynamic element from core concepts + - At least two encounters must be directly tied to the primary faction + Format as "Name: Location Name: details" using colons, NOT em-dashes. CRITICAL: Always start encounter details with the location name and a colon. + +EXAMPLE ENCOUNTER: +"Guardian Golem: Chamber of Echoes: The golem activates when the lever is pulled, blocking the exit. It's vulnerable to water damage from the dripping stalactites. Players can use the pillars for cover or try to disable it by breaking the rune on its back. If defeated peacefully, it reveals a hidden passage." + +- **Strictly 4-5 NPCs:** Proper name (max 4 words) and a description (50-65 words). Each NPC MUST include: + - Clear motivation or goal + - Relationship to primary faction + - How they can help or hinder the party + - Quirks or memorable traits + - Multiple interaction possibilities (negotiation, intimidation, help, betrayal) + - One NPC should be a key figure tied to the central conflict + - One should be a member of the primary faction, one should be a potential ally, one should be a rival + Format as "Name: description" using colons, NOT em-dashes. + +EXAMPLE NPC: +"Kaelen the Warden: A former guard who was left behind when the faction retreated. He knows the secret passages but demands the party help him escape. He's paranoid and checks over his shoulder constantly. Can be bribed with food or convinced through shared stories of betrayal. Will turn on the party if he thinks they're working with the faction." + +- **Strictly 4-5 Treasures:** Name (max 5 words) and a description (30-40 words). Each treasure MUST: + - Include a clear danger or side-effect + - Be connected to a specific encounter, NPC, or room + - Have story significance beyond just value + - Have potential for creative use beyond obvious purpose + - Some should be cursed, have activation requirements, or serve dual purposes + Format as "Name — Description" using em-dash. + +EXAMPLE TREASURE: +"Whispering Blade — This dagger amplifies the wielder's voice to a deafening roar when drawn. Found in the Guardian Golem's chamber, it was used to command the construct. The blade is cursed: each use permanently reduces the wielder's hearing. Can be used to shatter glass or stun enemies, but the curse cannot be removed." + +- **Strictly 1 Random Events Table:** A d6 table (EXACTLY 6 entries, no more, no less) with random events/wandering encounters. Each entry MUST: + - Have a short, evocative event name (max 4 words) + - Provide interesting complications or opportunities (not just combat) + - Tie to the core concepts and dynamic element + - Add replayability and surprise + - Description should be 15-20 words maximum + - Be UNIQUE and DIFFERENT from each other (no duplicates or generic placeholders) + - Be SPECIFIC to this dungeon's theme, conflict, and dynamic element + Format as numbered 1-6 list under "Random Events:" label. Each event must be formatted as "Event Name: Description text" using colons, NOT em-dashes. + +CRITICAL: Each item must be on its own numbered line. DO NOT combine multiple items into a single numbered entry. + +EXACT FORMAT REQUIRED (DO NOT use placeholder names like "Location Name", "NPC Name", or "Treasure Name" - use actual creative names): +Locations: +1. Actual Room Name: Description text. +2. Actual Room Name: Description text. +3. Actual Room Name: Description text. + +Encounters: +1. Actual Encounter Name: Actual Room Name: Details text. +2. Actual Encounter Name: Actual Room Name: Details text. +3. Actual Encounter Name: Actual Room Name: Details text. +4. Actual Encounter Name: Actual Room Name: Details text. +5. Actual Encounter Name: Actual Room Name: Details text. +6. Actual Encounter Name: Actual Room Name: Details text. + +NPCs: +1. Actual Character Name: Description text. +2. Actual Character Name: Description text. +3. Actual Character Name: Description text. +4. Actual Character Name: Description text. + +Treasures: +1. Actual Item Name — Description text. +2. Actual Item Name — Description text. +3. Actual Item Name — Description text. +4. Actual Item Name — Description text. + +Random Events: +1. Event Name: Event description. +2. Event Name: Event description. +3. Event Name: Event description. +4. Event Name: Event description. +5. Event Name: Event description. +6. Event Name: Event description. + +CRITICAL: Every name must be unique and creative. Never use generic placeholders like "Location Name", "NPC Name", "Encounter Name", or "Treasure Name". Use actual descriptive names that fit the dungeon's theme. + +CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns, character names, and location names. Verify consistency of names across all sections. + +CRITICAL: Location name matching - When writing encounters, the location name in the encounter details MUST exactly match one of the room names you've created (Entrance Room, Climax Room, or one of the 3 Locations). Double-check that every encounter location matches an actual room name. + +CRITICAL: Avoid vague language - Do not use words like "some", "various", "several", "many", "few", "things", "stuff", "items", or "objects" without specific details. Be concrete and specific in all descriptions. + +CRITICAL: All names required - Every room, encounter, NPC, and treasure MUST have a name. Do not leave names blank or use placeholders. If you cannot think of a name, create one based on the dungeon's theme. + +CRITICAL: You MUST output exactly five separate sections with these exact labels on their own lines: +"Locations:" +"Encounters:" +"NPCs:" +"Treasures:" +"Random Events:" + +Each section must start with its label on its own line, followed by numbered items. Do NOT combine sections. Do NOT embed encounters in location descriptions. Each item must be on its own numbered line. Do not use any bolding, preambles, or extra text. Do not use em-dashes (—) in encounters or NPCs, only use colons for those sections. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, + undefined, 5, "Step 5: Main Content" + ); + const { intermediateRoomsSection, encountersSection, npcsSection, treasureSection, randomEventsSection } = + parseMainContentSections(mainContentRaw); + + const intermediateRooms = parseObjects(intermediateRoomsSection.replace(/Locations:/i, ""), "rooms"); + const limitedIntermediateRooms = limitIntermediateRooms(intermediateRooms, 3); + + const allRooms = [entranceRoom, ...limitedIntermediateRooms, climaxRoom].filter(Boolean); + const rooms = deduplicateRoomsByName(allRooms); + const parsedEncounters = splitCombinedEncounters(parseObjects(encountersSection || "", "encounters")); + const parsedNpcs = parseObjects(npcsSection || "", "npcs"); + const treasure = parseObjects(treasureSection || "", "treasure"); + + const npcs = padNpcsToMinimum(parsedNpcs, coreConcepts, 4); + const encounters = buildEncountersList(parsedEncounters, rooms, coreConcepts); + + const randomEventsFilteredMapped = parseRandomEventsRaw(randomEventsSection || ""); + const randomEvents = mergeRandomEventsWithFallbacks(randomEventsFilteredMapped, coreConcepts, 6); + + [[encounters, 6, 'encounters'], [npcs, 4, 'NPCs'], [treasure, 4, 'treasures'], [randomEvents, 6, 'random events']] + .filter(([arr, expected]) => arr.length < expected && arr.length > 0) + .forEach(([arr, expected, name]) => console.warn(`Expected at least ${expected} ${name} but got ${arr.length}`)); + console.log("Rooms:", rooms); + console.log("Encounters:", encounters); + console.log("NPCs:", npcs); + console.log("Treasure:", treasure); + console.log("Random Events:", randomEvents); + + // Step 6: Player Choices and Consequences + const factionName = coreConcepts.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction'; + const npcNamesList = npcs.map(n => n.name).join(", "); + + const plotResolutionsRaw = await callOllama( + `Based on all of the following elements, suggest 4-5 possible, non-conflicting story climaxes or plot resolutions for adventurers exploring this location. Each resolution must provide a meaningful choice with a tangible consequence, directly related to the Central Conflict, the Primary Faction, or the NPCs. + +Dungeon Elements: +${JSON.stringify({ title, flavor, hooksRumors, rooms, encounters, treasure, npcs, coreConcepts }, null, 2)} + +CRITICAL: This content must fit in a single column on a one-page dungeon layout. Keep descriptions meaningful but concise. +Start each item with phrases like "The adventurers could" or "The adventurers might". Do not use "PCs" or "player characters" - always use "adventurers" instead. + +EXAMPLE PLOT RESOLUTION: +"The adventurers could ally with the primary faction, gaining access to their resources but becoming enemies of the rival group. This choice unlocks new areas but closes off diplomatic solutions with other NPCs." + +IMPORTANT: When referencing NPCs, use these exact names with correct spelling: ${npcNamesList}. When referencing the faction, use: ${factionName}. Ensure all names are spelled consistently and correctly. +CRITICAL: Double-check all spelling before outputting. Verify all proper nouns match exactly as provided above. + +Each resolution MUST: +- Offer meaningful choice with clear consequences +- Integrate NPCs, faction dynamics, and player actions +- Include failure states or unexpected outcomes as options +- Reflect different approaches players might take +Keep each item to 1-2 sentences MAX (approximately 15-25 words). Be extremely concise. Output as a numbered list, plain text only. Do not use em-dashes (—) anywhere in the output. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`, + undefined, 5, "Step 6: Plot Resolutions" + ); + const plotResolutions = parseList(plotResolutionsRaw); + console.log("Plot Resolutions:", plotResolutions); + + // Step 7: Validation and Content Fixing + console.log("\n[Validation] Running content validation and fixes..."); + const dungeonData = { + title, + flavor, + map: "map.png", + hooksRumors, + rooms, + encounters, + treasure, + npcs, + plotResolutions, + randomEvents, + coreConcepts + }; + + const validatedData = validateAndFixContent(dungeonData); + + console.log("\nDungeon generation complete!"); + return validatedData; +} diff --git a/dungeonTemplate.js b/src/dungeonTemplate.js similarity index 66% rename from dungeonTemplate.js rename to src/dungeonTemplate.js index 128c39f..45273d5 100644 --- a/dungeonTemplate.js +++ b/src/dungeonTemplate.js @@ -2,7 +2,7 @@ function pickRandom(arr) { return arr[Math.floor(Math.random() * arr.length)]; } -function escapeHtml(text) { +export function escapeHtml(text) { if (!text) return ''; const map = { '&': '&', @@ -14,6 +14,37 @@ function escapeHtml(text) { return String(text).replace(/[&<>"']/g, m => map[m]); } +/** Truncate to at most maxSentences, then optionally by maxChars; return immutable result. */ +export function truncateText(text, maxSentences, maxChars) { + const t = text || ''; + const sentences = t.match(/[^.!?]+[.!?]+/g) || [t]; + const afterSentences = sentences.length > maxSentences + ? sentences.slice(0, maxSentences).join(' ').trim() + : t; + if (afterSentences.length <= maxChars) return afterSentences; + const trimmed = afterSentences.substring(0, maxChars - 3).trim(); + const lastPeriod = trimmed.lastIndexOf('.'); + return (lastPeriod > maxChars * 0.8 ? trimmed.substring(0, lastPeriod + 1) : trimmed + '...'); +} + +/** Parse event (object or string) into { name, description } with optional truncation. */ +export function parseEventForDisplay(event, index) { + const pair = typeof event === 'object' && event?.name != null && event?.description != null + ? { name: event.name, description: event.description } + : typeof event === 'string' + ? (() => { + const colonMatch = event.match(/^([^:]+):\s*(.+)$/); + if (colonMatch) return { name: colonMatch[1].trim(), description: colonMatch[2].trim() }; + const words = event.split(/\s+/); + return words.length > 3 + ? { name: words.slice(0, 2).join(' '), description: words.slice(2).join(' ') } + : { name: `Event ${index + 1}`, description: event }; + })() + : { name: `Event ${index + 1}`, description: String(event || '') }; + const description = truncateText(pair.description, 999, 200); + return { name: pair.name, description }; +} + export function dungeonTemplate(data) { const bodyFonts = [ "'Lora', serif", @@ -255,43 +286,7 @@ export function dungeonTemplate(data) { ${data.randomEvents.map((event, index) => { - // Handle both object format {name, description} and string format - let eventName = ''; - let eventDesc = ''; - if (typeof event === 'object' && event.name && event.description) { - eventName = event.name; - eventDesc = event.description; - } else if (typeof event === 'string') { - // Try to parse "Event Name: Description" format - const colonMatch = event.match(/^([^:]+):\s*(.+)$/); - if (colonMatch) { - eventName = colonMatch[1].trim(); - eventDesc = colonMatch[2].trim(); - } else { - // Fallback: use first few words as name, rest as description - const words = event.split(/\s+/); - if (words.length > 3) { - eventName = words.slice(0, 2).join(' '); - eventDesc = words.slice(2).join(' '); - } else { - eventName = `Event ${index + 1}`; - eventDesc = event; - } - } - } else { - eventName = `Event ${index + 1}`; - eventDesc = String(event || ''); - } - // Truncate description to prevent overflow (similar to encounters) - if (eventDesc.length > 200) { - eventDesc = eventDesc.substring(0, 197).trim(); - const lastPeriod = eventDesc.lastIndexOf('.'); - if (lastPeriod > 150) { - eventDesc = eventDesc.substring(0, lastPeriod + 1); - } else { - eventDesc += '...'; - } - } + const { name: eventName, description: eventDesc } = parseEventForDisplay(event, index); return ` @@ -309,22 +304,7 @@ export function dungeonTemplate(data) {

Locations

${data.rooms.map(room => { - let desc = room.description || ''; - // Truncate to 1 sentence max to prevent overflow - const sentences = desc.match(/[^.!?]+[.!?]+/g) || [desc]; - if (sentences.length > 1) { - desc = sentences.slice(0, 1).join(' ').trim(); - } - // Also limit by character count (~100 chars for tighter fit) - if (desc.length > 100) { - desc = desc.substring(0, 97).trim(); - const lastPeriod = desc.lastIndexOf('.'); - if (lastPeriod > 70) { - desc = desc.substring(0, lastPeriod + 1); - } else { - desc += '...'; - } - } + const desc = truncateText(room.description || '', 1, 100); return `

${escapeHtml(room.name)}

@@ -343,38 +323,21 @@ export function dungeonTemplate(data) {
${index + 1}
${data.encounters.map((encounter, index) => { - // Truncate details to 4 sentences max to prevent overflow - let details = encounter.details || ''; - // Remove encounter name if it appears at start - if (details.toLowerCase().startsWith(encounter.name.toLowerCase())) { - details = details.substring(encounter.name.length).replace(/^:\s*/, '').trim(); - } - // Remove location prefix if present (format: "Location Name: description") - // Handle multiple colons - strip the first one that looks like a location - const locationMatch = details.match(/^([^:]+):\s*(.+)$/); - if (locationMatch) { - const potentialLocation = locationMatch[1].trim(); - // If it looks like a location name (capitalized, not too long), remove it - if (potentialLocation.length > 3 && potentialLocation.length < 50 && /^[A-Z]/.test(potentialLocation)) { - details = locationMatch[2].trim(); - } - } - // Split into sentences and keep only first 4 - const sentences = details.match(/[^.!?]+[.!?]+/g) || [details]; - if (sentences.length > 4) { - details = sentences.slice(0, 4).join(' ').trim(); - } - // Also limit by character count as fallback (max ~350 chars) - if (details.length > 350) { - details = details.substring(0, 347).trim(); - // Try to end at a sentence boundary - const lastPeriod = details.lastIndexOf('.'); - if (lastPeriod > 280) { - details = details.substring(0, lastPeriod + 1); - } else { - details += '...'; - } - } + const raw = (encounter.details || '').trim(); + const withoutName = raw.toLowerCase().startsWith(encounter.name.toLowerCase()) + ? raw.substring(encounter.name.length).replace(/^:\s*/, '').trim() + : raw; + const locationMatch = withoutName.match(/^([^:]+):\s*(.+)$/); + const withoutLocation = locationMatch + ? (() => { + const potential = locationMatch[1].trim(); + if (potential.length > 3 && potential.length < 50 && /^[A-Z]/.test(potential)) { + return locationMatch[2].trim(); + } + return withoutName; + })() + : withoutName; + const details = truncateText(withoutLocation, 4, 350); return ` @@ -432,24 +395,7 @@ export function dungeonTemplate(data) {

Plot Resolutions

${data.plotResolutions.map(resolution => { - // Truncate to 1 sentence max to prevent overflow (more aggressive) - let text = resolution || ''; - // Split into sentences and keep only first 1 - const sentences = text.match(/[^.!?]+[.!?]+/g) || [text]; - if (sentences.length > 1) { - text = sentences.slice(0, 1).join(' ').trim(); - } - // Also limit by character count as fallback (max ~120 chars for tighter fit) - if (text.length > 120) { - text = text.substring(0, 117).trim(); - // Try to end at a sentence boundary - const lastPeriod = text.lastIndexOf('.'); - if (lastPeriod > 90) { - text = text.substring(0, lastPeriod + 1); - } else { - text += '...'; - } - } + const text = truncateText(resolution || '', 1, 120); return `
${escapeHtml(text)} diff --git a/generatePDF.js b/src/generatePDF.js similarity index 100% rename from generatePDF.js rename to src/generatePDF.js diff --git a/imageGenerator.js b/src/imageGenerator.js similarity index 100% rename from imageGenerator.js rename to src/imageGenerator.js diff --git a/ollamaClient.js b/src/ollamaClient.js similarity index 79% rename from ollamaClient.js rename to src/ollamaClient.js index 9bbaa17..5a9e282 100644 --- a/ollamaClient.js +++ b/src/ollamaClient.js @@ -1,15 +1,17 @@ +import { cleanText } from "./textUtils.js"; + const OLLAMA_API_URL = process.env.OLLAMA_API_URL; -const OLLAMA_API_KEY = process.env.OLLAMA_API_KEY; export let OLLAMA_MODEL = process.env.OLLAMA_MODEL || "gemma3:latest"; export async function initializeModel() { if (process.env.OLLAMA_MODEL) return; try { - const isOpenWebUI = OLLAMA_API_URL?.includes("/api/chat/completions"); - const baseUrl = OLLAMA_API_URL?.replace(/\/api\/.*$/, ""); + const apiUrl = process.env.OLLAMA_API_URL; + const isOpenWebUI = apiUrl?.includes("/api/chat/completions"); + const baseUrl = apiUrl?.replace(/\/api\/.*$/, ""); const url = isOpenWebUI ? `${baseUrl}/api/v1/models` : `${baseUrl}/api/tags`; - const headers = isOpenWebUI && OLLAMA_API_KEY - ? { "Authorization": `Bearer ${OLLAMA_API_KEY}` } + const headers = isOpenWebUI && process.env.OLLAMA_API_KEY + ? { "Authorization": `Bearer ${process.env.OLLAMA_API_KEY}` } : {}; const res = await fetch(url, { headers }); if (res.ok) { @@ -27,16 +29,9 @@ export async function initializeModel() { } } -function cleanText(str) { - return str - .replace(/^#+\s*/gm, "") - .replace(/\*\*(.*?)\*\*/g, "$1") - .replace(/[*_`]/g, "") - .replace(/\s+/g, " ") - .trim(); -} +export { cleanText }; -function inferApiType(url) { +export function inferApiType(url) { if (!url) return "ollama-generate"; if (url.includes("/api/chat/completions")) return "open-webui"; if (url.includes("/api/chat")) return "ollama-chat"; @@ -64,8 +59,8 @@ async function callOllamaBase(prompt, model, retries, stepName, apiType) { ); const headers = { "Content-Type": "application/json" }; - if (isUsingOpenWebUI && OLLAMA_API_KEY) { - headers["Authorization"] = `Bearer ${OLLAMA_API_KEY}`; + if (isUsingOpenWebUI && process.env.OLLAMA_API_KEY) { + headers["Authorization"] = `Bearer ${process.env.OLLAMA_API_KEY}`; } const body = isUsingOpenWebUI || isUsingOllamaChat @@ -79,13 +74,8 @@ async function callOllamaBase(prompt, model, retries, stepName, apiType) { }); if (!response.ok) { - let errorDetails = ""; - try { - const errorData = await response.text(); - errorDetails = errorData ? `: ${errorData}` : ""; - } catch { - // Ignore errors reading error response - } + const errorData = await response.text().catch(() => null); + const errorDetails = errorData ? `: ${errorData}` : ""; throw new Error( `Ollama request failed: ${response.status} ${response.statusText}${errorDetails}`, ); diff --git a/src/parsing.js b/src/parsing.js new file mode 100644 index 0000000..79e7e3a --- /dev/null +++ b/src/parsing.js @@ -0,0 +1,234 @@ +import { cleanText } from "./textUtils.js"; + +export function parseList(raw) { + if (!raw) return []; + const NUMBERED_ITEM_REGEX = /\d+[).]\s+([\s\S]+?)(?=\s*\d+[).]\s+|$)/g; + const items = Array.from(raw.matchAll(NUMBERED_ITEM_REGEX)) + .map(match => match[1].trim()) + .filter(Boolean) + .map(cleanText) + .filter(Boolean); + return items.length > 0 + ? items + : raw + .split(/\n?\d+[).]\s+/) + .map(line => cleanText(line)) + .filter(Boolean); +} + +export function parseObjects(raw, type = "rooms") { + const cleanedRaw = raw.replace(/Intermediate Rooms:/i, "").replace(/Climax Room:/i, "").trim(); + const mapper = (entry) => { + if (type === "encounters") { + const parts = entry.split(/:/); + if (parts.length >= 3) { + const name = parts[0].trim(); + if (name.toLowerCase().includes('location name') || name.toLowerCase().includes('encounter name')) return null; + return { name, details: parts.slice(1).join(":").trim() }; + } + if (parts.length === 2) { + const name = parts[0].trim(); + if (name.toLowerCase().includes('location name') || name.toLowerCase().includes('encounter name')) return null; + return { name, details: parts[1].trim() }; + } + return null; + } + if (type === "treasure") { + const parts = entry.split(/[—]/); + if (parts.length >= 2) { + const cleanName = parts[0].trim(); + if (cleanName.toLowerCase().includes('treasure name') || cleanName.toLowerCase().includes('actual ')) return null; + const desc = parts.slice(1).join(' ').trim().replace(/^description\s*:?\s*/i, '').trim(); + return { name: cleanName, description: desc }; + } + } + const [name, ...descParts] = entry.split(/[-–—:]/); + const cleanName = name.trim(); + if (cleanName.toLowerCase().includes('location name') || + cleanName.toLowerCase().includes('npc name') || + cleanName.toLowerCase().includes('treasure name') || + cleanName.toLowerCase().includes('actual ')) return null; + const desc = type === "npcs" + ? descParts.join(" ").trim().replace(/^description\s*:?\s*/i, '').trim() + : descParts.join(" ").trim(); + const obj = { name: cleanName }; + if (type === "rooms") return { ...obj, description: desc }; + if (type === "npcs") return { ...obj, trait: desc }; + if (type === "treasure") return { ...obj, description: desc }; + return null; + }; + return cleanedRaw.split(/\n?\d+[).]\s+/).map(cleanText).filter(Boolean).map(mapper).filter(Boolean); +} + +export const parseEncounterText = (text, idx) => { + const encounterMatch = text.match(/Encounter\s+(\d+)\s+(.+?)\s+(?:Room Name|Location)\s+(.+?)\s+Details\s+(.+)/i); + if (encounterMatch) { + const [, , name, location, details] = encounterMatch; + return { name: name.trim(), details: `${location.trim()}: ${details.trim()}` }; + } + const colonFormat = text.match(/Encounter\s+\d+\s+(.+?):\s*(.+?):\s*(.+)/i); + if (colonFormat) { + const [, name, location, details] = colonFormat; + return { name: name.trim(), details: `${location.trim()}: ${details.trim()}` }; + } + const match = text.match(/^(\d+)\s+(.+?)(?::\s*(.+))?$/); + if (match) { + const [, , name, details] = match; + return name && details ? { name: name.trim(), details: details.trim() } : null; + } + const colonSplit = text.split(/[:]/); + if (colonSplit.length > 1) { + return { + name: colonSplit[0].replace(/^\d+\s+|Encounter\s+\d+\s+/i, "").trim(), + details: colonSplit.slice(1).join(":").trim() + }; + } + const nameMatch = text.match(/^\d+\s+([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)/); + if (nameMatch) { + return { + name: nameMatch[1], + details: text.replace(/^\d+\s+[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\s*/, "").trim() + }; + } + return { name: `Encounter ${idx + 1}`, details: text.replace(/^\d+\s+|Encounter\s+\d+\s+/i, "").trim() }; +}; + +export const splitCombinedEncounters = (encounters) => { + if (encounters.length === 0) return []; + const shouldSplit = encounters.length === 1 && (encounters[0].name === "1" || encounters[0].details?.match(/\d+\s+[A-Z]/) || encounters[0].details?.includes('Encounter')); + if (!shouldSplit) return encounters; + console.warn("Encounters appear combined, attempting to split..."); + const combinedText = encounters[0].details || ""; + const split = combinedText.split(/(?=Encounter\s+\d+|\d+\s+[A-Z][a-z])/i).filter(Boolean); + return (split.length > 1 || (split.length === 1 && combinedText.length > 100)) + ? split.map((text, idx) => parseEncounterText(text, idx)).filter(e => e?.name && e?.details?.length > 10) + : encounters; +}; + +function _splitCombinedNPCs(npcs) { + const shouldSplit = npcs.length === 1 && npcs[0].trait?.length > 80; + if (!shouldSplit) return npcs; + console.warn("NPCs appear combined, attempting to split..."); + const split = npcs[0].trait.split(/(?=[A-Z][a-z]+\s+[A-Z][a-z]+\s*:)/).filter(Boolean); + return split.length > 1 + ? split.map(text => { + const [name, ...traitParts] = text.split(/[:]/); + return { name: name.trim(), trait: traitParts.join(":").trim() }; + }).filter(n => n.name && n.trait?.length > 10) + : npcs; +} + +function parseTreasureText(text, idx, splitTreasures) { + if (idx === splitTreasures.length - 1 && text.length < 40) { + return { name: splitTreasures[idx - 1]?.split(/\s+/).slice(-2).join(" ") || `Treasure ${idx}`, description: text }; + } + const dashSplit = text.split(/[—]/); + if (dashSplit.length === 2) return { name: dashSplit[0].trim(), description: dashSplit[1].trim() }; + if (text.length < 30 && /^[A-Z]/.test(text)) return { name: text.trim(), description: "" }; + return null; +} + +function _splitCombinedTreasures(treasure) { + const shouldSplit = treasure.length === 1 && treasure[0].description?.length > 60; + if (!shouldSplit) return treasure; + console.warn("Treasures appear combined, attempting to split..."); + const split = treasure[0].description.split(/\s+—\s+/).filter(Boolean); + if (split.length <= 1) return treasure; + const parsed = split.map((text, idx) => parseTreasureText(text, idx, split)).filter(t => t?.name && t?.description); + if (parsed.length > 0) return parsed; + const nameDescPairs = treasure[0].description.match(/([A-Z][^—]+?)\s+—\s+([^—]+?)(?=\s+[A-Z][^—]+\s+—|$)/g); + return nameDescPairs + ? nameDescPairs.map(pair => { + const match = pair.match(/([^—]+)\s+—\s+(.+)/); + return match ? { name: match[1].trim(), description: match[2].trim() } : null; + }).filter(t => t) + : treasure; +} + +export function parseRandomEventsRaw(rawSection) { + const parsed = parseList(rawSection || ""); + return parsed + .filter(e => + e && + e.toLowerCase() !== 'a random event occurs' && + e.toLowerCase() !== 'a random event occurs.' && + !e.toLowerCase().includes('placeholder') && + e.length > 10 + ) + .map((e, index) => { + const cleaned = e.replace(/^(Event\s+\d+[:\s]+|Random\s+Event[:\s]+|Random\s+Events?[:\s]+)/i, '').trim(); + const colonMatch = cleaned.match(/^([^:]+):\s*(.+)$/); + if (colonMatch) { + const name = colonMatch[1].trim(); + const description = colonMatch[2].trim(); + if (name.toLowerCase().includes('event name') || name.toLowerCase().includes('placeholder')) return null; + return { name, description }; + } + const words = cleaned.split(/\s+/); + if (words.length > 3) { + return { name: words.slice(0, 2).join(' '), description: words.slice(2).join(' ') }; + } + return { name: `Event ${index + 1}`, description: cleaned }; + }) + .filter(Boolean); +} + +export function parseMainContentSections(mainContentRaw) { + const initialSplit = mainContentRaw.split(/Encounters:|NPCs:|Treasures?:|Random Events:/i); + const withRandom = (!initialSplit[4] && mainContentRaw.toLowerCase().includes('random')) + ? (() => { + const randomMatch = mainContentRaw.match(/Random Events?[:\s]*\n?([^]*?)(?=Locations?:|Encounters?:|NPCs?:|Treasures?:|$)/i); + return randomMatch ? [...initialSplit.slice(0, 4), randomMatch[1]] : initialSplit; + })() + : initialSplit; + const withNpcs = (!withRandom[2] && mainContentRaw.toLowerCase().includes('npc')) + ? (() => { + const npcMatch = mainContentRaw.match(/NPCs?[:\s]*\n?([^]*?)(?=Treasures?:|Random Events?:|Locations?:|Encounters?:|$)/i); + return npcMatch ? [withRandom[0], withRandom[1], npcMatch[1], withRandom[3], withRandom[4]] : withRandom; + })() + : withRandom; + + const inter = withNpcs[0]; + const enc = (withNpcs[1] || '').trim(); + if (enc || !inter.includes('Encounter')) { + return { + intermediateRoomsSection: inter, + encountersSection: enc, + npcsSection: withNpcs[2], + treasureSection: withNpcs[3], + randomEventsSection: withNpcs[4], + }; + } + const encounterMatches = inter.match(/Encounter\s+\d+[^]*?(?=Encounter\s+\d+|NPCs?:|Treasures?:|Random Events?:|Location \d+|$)/gi); + if (!encounterMatches || encounterMatches.length === 0) { + return { + intermediateRoomsSection: inter, + encountersSection: enc, + npcsSection: withNpcs[2], + treasureSection: withNpcs[3], + randomEventsSection: withNpcs[4], + }; + } + const encountersSection = encounterMatches.map((m, i) => { + const match = m.match(/Encounter\s+(\d+)\s+(.+?)\s+(?:Room Name|Location)\s+(.+?)\s+Details\s+(.+)/i); + if (match) { + const [, num, name, location, details] = match; + return `${num}. ${name.trim()}: ${location.trim()}: ${details.trim().substring(0, 200)}`; + } + const simpleMatch = m.match(/Encounter\s+(\d+)\s+(.+?)\s+([A-Z][^:]+?)\s+Details\s+(.+)/i); + if (simpleMatch) { + const [, num, name, location, details] = simpleMatch; + return `${num}. ${name.trim()}: ${location.trim()}: ${details.trim().substring(0, 200)}`; + } + return `${i + 1}. ${m.trim()}`; + }).join('\n'); + const intermediateRoomsSection = inter.replace(/Encounter\s+\d+[^]*?(?=Encounter\s+\d+|NPCs?:|Treasures?:|Random Events?:|Location \d+|$)/gi, ''); + return { + intermediateRoomsSection, + encountersSection, + npcsSection: withNpcs[2], + treasureSection: withNpcs[3], + randomEventsSection: withNpcs[4], + }; +} + diff --git a/src/textUtils.js b/src/textUtils.js new file mode 100644 index 0000000..7ae4398 --- /dev/null +++ b/src/textUtils.js @@ -0,0 +1,10 @@ +/** Strip markdown artifacts and normalize whitespace. Pure, no side effects. */ +export function cleanText(str) { + if (!str) return ""; + return str + .replace(/^#+\s*/gm, "") + .replace(/\*\*(.*?)\*\*/g, "$1") + .replace(/[*_`]/g, "") + .replace(/\s+/g, " ") + .trim(); +} diff --git a/src/validation.js b/src/validation.js new file mode 100644 index 0000000..00c914a --- /dev/null +++ b/src/validation.js @@ -0,0 +1,120 @@ +export function extractCanonicalNames(dungeonData) { + const names = { npcs: [], rooms: [], factions: [] }; + if (dungeonData.npcs) { + dungeonData.npcs.forEach(npc => { if (npc.name) names.npcs.push(npc.name.trim()); }); + } + if (dungeonData.rooms) { + dungeonData.rooms.forEach(room => { if (room.name) names.rooms.push(room.name.trim()); }); + } + if (dungeonData.coreConcepts) { + const factionMatch = dungeonData.coreConcepts.match(/Primary Faction[:\s]+([^.]+)/i); + if (factionMatch) names.factions.push(factionMatch[1].trim()); + } + return names; +} + +export function validateContentCompleteness(dungeonData) { + const issues = []; + const checks = [ + ['title', 0, 'Missing title'], + ['flavor', 20, 'Flavor text too short'], + ['hooksRumors', 4, 'Expected at least 4 hooks'], + ['rooms', 5, 'Expected at least 5 rooms'], + ['encounters', 6, 'Expected at least 6 encounters'], + ['npcs', 4, 'Expected at least 4 NPCs'], + ['treasure', 4, 'Expected at least 4 treasures'], + ['randomEvents', 6, 'Expected 6 random events'], + ['plotResolutions', 4, 'Expected at least 4 plot resolutions'] + ]; + checks.forEach(([key, min, msg]) => { + const val = dungeonData[key]; + if (!val || (Array.isArray(val) ? val.length < min : val.trim().length < min)) { + issues.push(`${msg}${Array.isArray(val) ? `, got ${val?.length || 0}` : ''}`); + } + }); + dungeonData.rooms?.forEach((r, i) => { + if (!r.description || r.description.trim().length < 20) { + issues.push(`Room ${i + 1} (${r.name}) description too short`); + } + }); + dungeonData.encounters?.forEach((e, i) => { + if (!e.details || e.details.trim().length < 30) { + issues.push(`Encounter ${i + 1} (${e.name}) details too short`); + } + }); + dungeonData.npcs?.forEach((n, i) => { + if (!n.trait || n.trait.trim().length < 30) { + issues.push(`NPC ${i + 1} (${n.name}) description too short`); + } + }); + return issues; +} + +export function validateContentQuality(dungeonData) { + const issues = []; + const vagueWords = /\b(some|various|several|many|few|things|stuff|items|objects)\b/gi; + const checkVague = (text, ctx) => { + if (!text) return; + const matches = text.match(vagueWords); + if (matches?.length > 2) { + issues.push(`${ctx} contains vague language: "${matches.slice(0, 3).join('", "')}"`); + } + }; + checkVague(dungeonData.flavor, 'Flavor text'); + dungeonData.rooms?.forEach(r => checkVague(r.description, `Room "${r.name}"`)); + dungeonData.encounters?.forEach(e => checkVague(e.details, `Encounter "${e.name}"`)); + dungeonData.npcs?.forEach(n => checkVague(n.trait, `NPC "${n.name}"`)); + dungeonData.rooms?.forEach(r => { + if (r.description?.length < 50) { + issues.push(`Room "${r.name}" description too short`); + } + }); + return issues; +} + +export function validateContentStructure(dungeonData) { + const issues = []; + dungeonData.rooms?.forEach((r, i) => { + if (!r.name?.trim()) issues.push(`Room ${i + 1} missing name`); + if (r.name?.split(/\s+/).length > 6) issues.push(`Room "${r.name}" name too long`); + }); + dungeonData.encounters?.forEach((e, i) => { + if (!e.name?.trim()) issues.push(`Encounter ${i + 1} missing name`); + if (e.name?.split(/\s+/).length > 6) issues.push(`Encounter "${e.name}" name too long`); + if (e.details && !e.details.match(/^[^:]+:\s/)) { + issues.push(`Encounter "${e.name}" details missing location prefix`); + } + }); + dungeonData.npcs?.forEach((n, i) => { + if (!n.name?.trim()) issues.push(`NPC ${i + 1} missing name`); + if (n.name?.split(/\s+/).length > 4) issues.push(`NPC "${n.name}" name too long`); + }); + return issues; +} + +export function validateNarrativeCoherence(dungeonData) { + const issues = []; + const factionMatch = dungeonData.coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i); + const factionName = factionMatch?.[1]?.trim(); + if (dungeonData.encounters && dungeonData.rooms) { + const roomNames = dungeonData.rooms.map(r => r.name.trim().toLowerCase()); + dungeonData.encounters.forEach(e => { + const locMatch = e.details?.match(/^([^:]+):/); + if (locMatch) { + const locName = locMatch[1].trim().toLowerCase(); + if (!roomNames.some(rn => locName.includes(rn) || rn.includes(locName))) { + issues.push(`Encounter "${e.name}" references unknown location "${locMatch[1]}"`); + } + } + }); + } + if (factionName) { + const factionLower = factionName.toLowerCase(); + const refs = (dungeonData.npcs?.filter(n => n.trait?.toLowerCase().includes(factionLower)).length ?? 0) + + (dungeonData.encounters?.filter(e => e.details?.toLowerCase().includes(factionLower)).length ?? 0); + if (refs < 2) { + issues.push(`Faction "${factionName}" poorly integrated (${refs} references)`); + } + } + return issues; +} diff --git a/test/integration.test.js b/test/integration.test.js deleted file mode 100644 index 0cf56fb..0000000 --- a/test/integration.test.js +++ /dev/null @@ -1,91 +0,0 @@ -import { test } from "node:test"; -import assert from "node:assert"; -import { generateDungeon } from "../dungeonGenerator.js"; -import { generatePDF } from "../generatePDF.js"; -import fs from "fs/promises"; -import path from "path"; - -const OLLAMA_API_URL = process.env.OLLAMA_API_URL; - -test("Integration tests", { skip: !OLLAMA_API_URL }, async (t) => { - let dungeonData; - - await t.test("Generate dungeon", async () => { - dungeonData = await generateDungeon(); - assert(dungeonData, "Dungeon data should be generated"); - }); - - await t.test("Title is 2-4 words, no colons", () => { - assert(dungeonData.title, "Title should exist"); - const words = dungeonData.title.split(/\s+/); - assert(words.length >= 2 && words.length <= 4, `Title should be 2-4 words, got ${words.length}: "${dungeonData.title}"`); - assert(!dungeonData.title.includes(":"), `Title should not contain colons: "${dungeonData.title}"`); - }); - - await t.test("Flavor text is ≤60 words", () => { - assert(dungeonData.flavor, "Flavor text should exist"); - const words = dungeonData.flavor.split(/\s+/); - assert(words.length <= 60, `Flavor text should be ≤60 words, got ${words.length}`); - }); - - await t.test("Hooks have no title prefixes", () => { - assert(dungeonData.hooksRumors, "Hooks should exist"); - dungeonData.hooksRumors.forEach((hook, i) => { - assert(!hook.match(/^[^:]+:\s/), `Hook ${i + 1} should not have title prefix: "${hook}"`); - }); - }); - - await t.test("Exactly 6 random events", () => { - assert(dungeonData.randomEvents, "Random events should exist"); - assert.strictEqual(dungeonData.randomEvents.length, 6, `Should have exactly 6 random events, got ${dungeonData.randomEvents.length}`); - }); - - await t.test("Encounter details don't include encounter name", () => { - assert(dungeonData.encounters, "Encounters should exist"); - dungeonData.encounters.forEach((encounter) => { - if (encounter.details) { - const detailsLower = encounter.details.toLowerCase(); - const nameLower = encounter.name.toLowerCase(); - assert(!detailsLower.startsWith(nameLower), `Encounter "${encounter.name}" details should not start with encounter name: "${encounter.details}"`); - } - }); - }); - - await t.test("Treasure uses em-dash format, no 'description' text", () => { - assert(dungeonData.treasure, "Treasure should exist"); - dungeonData.treasure.forEach((item, i) => { - if (typeof item === "object" && item.description) { - assert(!item.description.toLowerCase().startsWith("description"), `Treasure ${i + 1} description should not start with 'description': "${item.description}"`); - } - }); - }); - - await t.test("NPCs have no 'description' text", () => { - assert(dungeonData.npcs, "NPCs should exist"); - dungeonData.npcs.forEach((npc, i) => { - if (npc.trait) { - assert(!npc.trait.toLowerCase().startsWith("description"), `NPC ${i + 1} trait should not start with 'description': "${npc.trait}"`); - } - }); - }); - - await t.test("PDF fits on one page", async () => { - const testPdfPath = path.join(process.cwd(), "test-output.pdf"); - try { - await generatePDF(dungeonData, testPdfPath); - const pdfBuffer = await fs.readFile(testPdfPath); - // Check PDF page count by counting "%%EOF" markers (rough estimate) - const pdfText = pdfBuffer.toString("binary"); - const pageCount = (pdfText.match(/\/Type\s*\/Page[^s]/g) || []).length; - // Should be 1 page for content, or 2 if map exists - const expectedPages = dungeonData.map ? 2 : 1; - assert(pageCount <= expectedPages, `PDF should have ≤${expectedPages} page(s), got ${pageCount}`); - } finally { - try { - await fs.unlink(testPdfPath); - } catch { - // Ignore cleanup errors - } - } - }); -}); diff --git a/test/integration/dungeonGeneration.test.js b/test/integration/dungeonGeneration.test.js new file mode 100644 index 0000000..9615921 --- /dev/null +++ b/test/integration/dungeonGeneration.test.js @@ -0,0 +1,92 @@ +import { describe, it, expect, beforeAll } from "vitest"; +import { generateDungeon } from "../../src/dungeonGenerator.js"; +import { generatePDF } from "../../src/generatePDF.js"; +import fs from "fs/promises"; +import path from "path"; + +const hasOllama = !!process.env.OLLAMA_API_URL; + +describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", () => { + let dungeonData; + + beforeAll(async () => { + dungeonData = await generateDungeon(); + }, 120000); + + it("generates dungeon data", () => { + expect(dungeonData).toBeDefined(); + }); + + it("title is 2-4 words, no colons", () => { + expect(dungeonData.title).toBeTruthy(); + const words = dungeonData.title.split(/\s+/); + expect(words.length).toBeGreaterThanOrEqual(2); + expect(words.length).toBeLessThanOrEqual(4); + expect(dungeonData.title).not.toContain(":"); + }); + + it("flavor text is ≤60 words", () => { + expect(dungeonData.flavor).toBeTruthy(); + const words = dungeonData.flavor.split(/\s+/); + expect(words.length).toBeLessThanOrEqual(60); + }); + + it("hooks have no title prefixes", () => { + expect(dungeonData.hooksRumors).toBeDefined(); + dungeonData.hooksRumors.forEach((hook) => { + expect(hook).not.toMatch(/^[^:]+:\s/); + }); + }); + + it("has exactly 6 random events", () => { + expect(dungeonData.randomEvents).toBeDefined(); + expect(dungeonData.randomEvents.length).toBe(6); + }); + + it("encounter details do not start with encounter name", () => { + expect(dungeonData.encounters).toBeDefined(); + dungeonData.encounters.forEach((encounter) => { + if (encounter.details) { + const detailsLower = encounter.details.toLowerCase(); + const nameLower = encounter.name.toLowerCase(); + expect(detailsLower.startsWith(nameLower)).toBe(false); + } + }); + }); + + it("treasure descriptions do not start with 'description'", () => { + expect(dungeonData.treasure).toBeDefined(); + dungeonData.treasure.forEach((item) => { + if (typeof item === "object" && item.description) { + expect(item.description.toLowerCase().startsWith("description")).toBe(false); + } + }); + }); + + it("NPC traits do not start with 'description'", () => { + expect(dungeonData.npcs).toBeDefined(); + dungeonData.npcs.forEach((npc) => { + if (npc.trait) { + expect(npc.trait.toLowerCase().startsWith("description")).toBe(false); + } + }); + }); + + it("PDF fits on one page", async () => { + const testPdfPath = path.join(process.cwd(), "test-output.pdf"); + try { + await generatePDF(dungeonData, testPdfPath); + const pdfBuffer = await fs.readFile(testPdfPath); + const pdfText = pdfBuffer.toString("binary"); + const pageCount = (pdfText.match(/\/Type\s*\/Page[^s]/g) || []).length; + const expectedPages = dungeonData.map ? 2 : 1; + expect(pageCount).toBeLessThanOrEqual(expectedPages); + } finally { + try { + await fs.unlink(testPdfPath); + } catch { + // Ignore cleanup errors + } + } + }, 60000); +}); diff --git a/test/unit/dungeonGenerator.generateDungeon.test.js b/test/unit/dungeonGenerator.generateDungeon.test.js new file mode 100644 index 0000000..2b86e77 --- /dev/null +++ b/test/unit/dungeonGenerator.generateDungeon.test.js @@ -0,0 +1,178 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; + +vi.mock("../../src/ollamaClient.js", () => ({ callOllama: vi.fn() })); + +const { callOllama } = await import("../../src/ollamaClient.js"); +const { generateDungeon } = await import("../../src/dungeonGenerator.js"); + +describe("generateDungeon (mocked Ollama)", () => { + beforeEach(() => { + vi.mocked(callOllama) + .mockResolvedValueOnce( + "1. Dark Hall\n2. Lost Mines\n3. Shadow Keep" + ) + .mockResolvedValueOnce( + "Central Conflict: The power source fails. Primary Faction: The Guard. Dynamic Element: Temporal rifts." + ) + .mockResolvedValueOnce( + "Description:\nA dark place under the earth.\nHooks & Rumors:\n1. A merchant vanished near the entrance.\n2. Strange lights in the depths.\n3. The Guard seeks the artifact.\n4. Rifts cause brief time skips." + ) + .mockResolvedValueOnce( + "1. Entrance Hall: A dark entrance with torches and damp walls. Pillars offer cover. The air smells of earth.\n2. Climax Chamber: The final room where the power source pulses. The Guard holds the artifact. Multiple approaches possible." + ) + .mockResolvedValueOnce( + `Locations: +1. Corridor: A long corridor with flickering lights. +2. Chamber: A side chamber with debris. +3. Shrine: A small shrine to the old gods. + +Encounters: +1. Patrol: Hall: Guard patrol passes through. +2. Rift: Corridor: A temporal rift causes disorientation. +3. Ambush: Chamber: Bandits lie in wait. +4. Guardian: Shrine: A warden challenges intruders. +5. Boss: Climax Chamber: The leader defends the artifact. +6. Trap: Corridor: A pressure plate triggers darts. + +NPCs: +1. Captain: Leader of the Guard, stern and duty-bound. +2. Scout: Young scout, curious about the rifts. +3. Priest: Keeper of the shrine, knows old lore. +4. Merchant: Survivor who lost his cargo. + +Treasures: +1. Artifact: The power source core. +2. Journal: Captain's log with tactical notes. +3. Key: Opens the climax chamber. +4. Gem: A glowing temporal crystal. + +Random Events: +1. Rift Shift: Time skips forward one hour. +2. Guard Patrol: A patrol approaches. +3. Echo: Voices from the past echo. +4. Light Flicker: Lights go out for a moment. +5. Distant Cry: Someone calls for help. +6. Dust Fall: Ceiling dust falls, revealing a hidden symbol.` + ) + .mockResolvedValueOnce( + "1. The adventurers could ally with the Guard and secure the artifact.\n2. They might destroy the source and end the rifts.\n3. They could bargain with the faction for passage.\n4. They might flee and seal the entrance." + ); + }); + + it("returns dungeon data with all required fields", async () => { + const result = await generateDungeon(); + expect(result).toBeDefined(); + expect(result.title).toBeTruthy(); + expect(result.flavor).toBeTruthy(); + expect(result.hooksRumors).toBeDefined(); + expect(Array.isArray(result.rooms)).toBe(true); + expect(Array.isArray(result.encounters)).toBe(true); + expect(Array.isArray(result.npcs)).toBe(true); + expect(Array.isArray(result.treasure)).toBe(true); + expect(Array.isArray(result.randomEvents)).toBe(true); + expect(Array.isArray(result.plotResolutions)).toBe(true); + }, 10000); + +}); + +describe("generateDungeon with fewer items (mocked Ollama)", () => { + beforeEach(() => { + vi.mocked(callOllama) + .mockResolvedValueOnce("1. Dark Hall\n2. Lost Mines") + .mockResolvedValueOnce("Central Conflict: War. Primary Faction: Guard. Dynamic Element: Magic.") + .mockResolvedValueOnce("Description: A place.\nHooks & Rumors:\n1. One.\n2. Two.\n3. Three.\n4. Four.") + .mockResolvedValueOnce("1. Entrance: First room.\n2. Climax: Final room.") + .mockResolvedValueOnce( + `Locations: +1. Corridor: A corridor. +2. Chamber: A chamber. + +Encounters: +1. Patrol: Corridor: A patrol. +2. Ambush: Chamber: Bandits. + +NPCs: +1. Captain: Leader. +2. Scout: Scout. + +Treasures: +1. Gold: Coins. +2. Gem: A gem. + +Random Events: +1. Rift Shift: Time skips. +2. Guard Patrol: Patrol approaches.` + ) + .mockResolvedValueOnce("1. The adventurers could win.\n2. They might flee."); + }); + + it("pads random events and encounters when step 5 returns fewer than 6", async () => { + const result = await generateDungeon(); + expect(result.randomEvents.length).toBe(6); + expect(result.encounters.length).toBe(6); + expect(result.npcs.length).toBeGreaterThanOrEqual(4); + }, 10000); + + it("builds six encounters from scratch when step 5 returns none", async () => { + vi.mocked(callOllama) + .mockResolvedValueOnce("1. Dark Hall\n2. Lost Mines") + .mockResolvedValueOnce("Central Conflict: War. Primary Faction: Guard. Dynamic Element: Magic.") + .mockResolvedValueOnce("Description: A place.\nHooks & Rumors:\n1. One.\n2. Two.\n3. Three.\n4. Four.") + .mockResolvedValueOnce("1. Entrance: First room.\n2. Climax: Final room.") + .mockResolvedValueOnce( + `Locations: +1. Corridor: A corridor. +2. Chamber: A chamber. + +Encounters: + +NPCs: +1. Captain: Leader. + +Treasures: +1. Gold: Coins. + +Random Events: +1. Rift: Time skips.` + ) + .mockResolvedValueOnce("1. The adventurers could win."); + const result = await generateDungeon(); + expect(result.encounters.length).toBe(6); + expect(result.encounters.every((e) => e.name && e.details)).toBe(true); + }, 10000); + + it("handles random events with no colon and short text (fallback name)", async () => { + vi.mocked(callOllama) + .mockResolvedValueOnce("1. Dark Hall\n2. Lost Mines") + .mockResolvedValueOnce("Central Conflict: War. Primary Faction: Guard. Dynamic Element: Magic.") + .mockResolvedValueOnce("Description: A place.\nHooks & Rumors:\n1. One.\n2. Two.\n3. Three.\n4. Four.") + .mockResolvedValueOnce("1. Entrance: First room.\n2. Climax: Final room.") + .mockResolvedValueOnce( + `Locations: +1. Corridor: A corridor. +2. Chamber: A chamber. + +Encounters: +1. Patrol: Corridor: A patrol. +2. Ambush: Chamber: Bandits. + +NPCs: +1. Captain: Leader. +2. Scout: Scout. + +Treasures: +1. Gold: Coins. +2. Gem: A gem. + +Random Events: +1. One two three +2. Event Name: Placeholder event +3. Rift Shift Time Skips Forward One Hour +4. Rift Shift: Time skips forward one hour.` + ) + .mockResolvedValueOnce("1. The adventurers could win.\n2. They might flee."); + const result = await generateDungeon(); + expect(result.randomEvents.length).toBe(6); + expect(result.randomEvents.some((e) => e.name && e.description)).toBe(true); + }, 10000); +}); diff --git a/test/unit/dungeonGenerator.test.js b/test/unit/dungeonGenerator.test.js new file mode 100644 index 0000000..37f90a7 --- /dev/null +++ b/test/unit/dungeonGenerator.test.js @@ -0,0 +1,1088 @@ +import { describe, it, expect, vi } from "vitest"; +import { cleanText } from "../../src/textUtils.js"; +import { + parseList, + parseObjects, + parseEncounterText, + splitCombinedEncounters, + parseRandomEventsRaw, + parseMainContentSections, +} from "../../src/parsing.js"; +import { + validateContentCompleteness, + validateContentQuality, + validateContentStructure, + validateNarrativeCoherence, + extractCanonicalNames, +} from "../../src/validation.js"; +import { + validateAndFixContent, + fixStructureIssues, + fixMissingContent, + fixNarrativeCoherence, + validateNameConsistency, + standardizeEncounterLocations, +} from "../../src/contentFixes.js"; +import { + deduplicateRoomsByName, + padNpcsToMinimum, + buildEncountersList, + mergeRandomEventsWithFallbacks, + fixRoomPlaceholderName, + limitIntermediateRooms, +} from "../../src/dungeonBuild.js"; + +describe("cleanText", () => { + it("returns empty string for empty input", () => { + expect(cleanText("")).toBe(""); + expect(cleanText(null)).toBe(""); + }); + + it("strips markdown and normalizes spaces", () => { + expect(cleanText("# Head")).toBe("Head"); + expect(cleanText("**bold**")).toBe("bold"); + expect(cleanText(" a b ")).toBe("a b"); + }); +}); + +describe("parseRandomEventsRaw", () => { + it("parses Event Name: Description format", () => { + const raw = "1. Rift Shift: Time skips forward."; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Rift Shift"); + expect(got[0].description).toContain("Time skips"); + }); + + it("returns null for placeholder name in colon format", () => { + const raw = "1. Event Name: Placeholder event"; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(0); + }); + + it("returns null when name contains 'placeholder' (colon format)", () => { + const raw = "1. My placeholder idea: Something happens."; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(0); + }); + + it("uses first two words as name when no colon and more than 3 words", () => { + const raw = "1. Rift Shift Time Skips Forward"; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Rift Shift"); + expect(got[0].description).toContain("Time Skips"); + }); + + it("uses Event N and full text when no colon and 3 or fewer words", () => { + const raw = "1. One two three"; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Event 1"); + expect(got[0].description).toBe("One two three"); + }); + + it("filters out short and placeholder-like entries", () => { + const raw = "1. Short\n2. A random event occurs.\n3. Real Event: A real description here."; + const got = parseRandomEventsRaw(raw); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Real Event"); + }); +}); + +describe("parseMainContentSections", () => { + it("returns five sections when content has all labels", () => { + const raw = "Locations:\n1. Hall: A hall.\n\nEncounters:\n1. Goblin: Hall: Attacks.\n\nNPCs:\n1. Guard: Stern.\n\nTreasures:\n1. Gold — coins.\n\nRandom Events:\n1. Event: Desc."; + const got = parseMainContentSections(raw); + expect(got.intermediateRoomsSection).toContain("Locations"); + expect(got.encountersSection).toContain("Goblin"); + expect(got.npcsSection).toContain("Guard"); + expect(got.treasureSection).toContain("Gold"); + expect(got.randomEventsSection).toContain("Event"); + }); + + it("fills random section via regex when initial split has no fourth segment", () => { + const raw = "Encounters:\n\nNPCs:\n\nTreasures:\n\nRandom Events:\n1. Rift: Time skips."; + const got = parseMainContentSections(raw); + expect(got.randomEventsSection).toContain("Rift"); + }); + + it("returns initialSplit when random is in content but Random Events regex does not match", () => { + const raw = "Encounters:\n\nNPCs:\n\nTreasures:\n\nrandom stuff"; + const got = parseMainContentSections(raw); + expect(got.randomEventsSection).toBeUndefined(); + }); + + it("extracts encounters from first block when encounters section empty but block contains Encounter N", () => { + const raw = "Locations:\n1. Corridor: A corridor.\nEncounter 1 Goblin Room Name Hall Details In the hall.\n\nEncounters:\n\nNPCs:\n1. Captain: Leader.\n\nTreasures:\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toMatch(/Goblin.*Hall/); + expect(got.intermediateRoomsSection).not.toMatch(/Encounter 1/); + }); + + it("returns encountersSection as-is when first block has no Encounter text", () => { + const raw = "Locations:\n1. Hall: A hall.\n\nEncounters:\n1. Goblin: Hall: Attacks.\n\nNPCs:\n1. Guard: Stern."; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toContain("Goblin"); + expect(got.intermediateRoomsSection).toContain("Hall"); + }); + + it("returns early when inter includes Encounter but regex match is null", () => { + const raw = "Locations:\n1. Hall: A hall.\nEncounter foo\n\nEncounters:\n\nNPCs:\n1. Guard: Stern.\n\nTreasures:\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toBe(""); + expect(got.intermediateRoomsSection).toContain("Encounter foo"); + }); + + it("uses npcMatch when third segment is empty but content has npc", () => { + const raw = "Encounters:\n\nNPCs:\n\nTreasures:\n1. Gold.\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.npcsSection).toBeDefined(); + expect(got.treasureSection).toContain("Gold"); + }); + + it("uses npcMatch when NPCs: immediately followed by Treasures: (empty segment)", () => { + const raw = "Encounters:\n\nNPCs:Treasures:\n1. Gold.\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.npcsSection).toBe(""); + expect(got.treasureSection).toContain("Gold"); + }); + + it("returns withRandom when npc in content but npcMatch regex does not match", () => { + const raw = "Encounters:\n\nenpcTreasures:\n\n"; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toBe("enpc"); + expect(got.npcsSection).toBe("\n\n"); + }); + + it("extracts encounter using simpleMatch when no Room Name/Location in block", () => { + const raw = "Locations:\n1. Corridor: A corridor.\nEncounter 1 Goblin Grand Hall Details In the hall.\n\nEncounters:\n\nNPCs:\n1. Captain: Leader.\n\nTreasures:\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toMatch(/Goblin|Grand Hall/); + }); + + it("uses fallback format when encounter block matches neither match nor simpleMatch", () => { + const raw = "Locations:\n1. Corridor: A corridor.\nEncounter 1 No details format here.\n\nEncounters:\n\nNPCs:\n1. Captain: Leader.\n\nTreasures:\n\nRandom Events:\n"; + const got = parseMainContentSections(raw); + expect(got.encountersSection).toMatch(/^1\./); + }); +}); + +describe("deduplicateRoomsByName", () => { + it("returns empty for empty or null input", () => { + expect(deduplicateRoomsByName([])).toEqual([]); + expect(deduplicateRoomsByName(null)).toEqual([]); + }); + + it("keeps first occurrence when names duplicate (case-insensitive)", () => { + const rooms = [ + { name: "Hall", description: "First" }, + { name: "hall", description: "Second" }, + { name: "HALL", description: "Third" }, + ]; + const got = deduplicateRoomsByName(rooms); + expect(got).toHaveLength(1); + expect(got[0].description).toBe("First"); + }); + + it("filters out rooms with no name", () => { + const rooms = [ + { name: "Hall", description: "x" }, + { name: "", description: "y" }, + { name: null, description: "z" }, + ]; + const got = deduplicateRoomsByName(rooms); + expect(got).toHaveLength(1); + }); +}); + +describe("padNpcsToMinimum", () => { + it("returns input when length >= minCount", () => { + const npcs = [{ name: "A", trait: "x" }, { name: "B", trait: "y" }, { name: "C", trait: "z" }, { name: "D", trait: "w" }]; + expect(padNpcsToMinimum(npcs, "Primary Faction: Guard.", 4)).toEqual(npcs); + }); + + it("pads to minCount using faction from coreConcepts", () => { + const npcs = [{ name: "Captain", trait: "Leader." }]; + const got = padNpcsToMinimum(npcs, "Primary Faction: The Guard.", 4); + expect(got).toHaveLength(4); + expect(got[1].name).toBe("NPC 2"); + expect(got[1].trait).toContain("guard"); + }); + + it("returns empty array when parsedNpcs null and minCount 4", () => { + const got = padNpcsToMinimum(null, "Primary Faction: Guard.", 4); + expect(got).toEqual([]); + }); + + it("uses default faction text when coreConcepts has no Primary Faction", () => { + const npcs = [{ name: "A", trait: "x" }]; + const got = padNpcsToMinimum(npcs, "Central Conflict: War.", 3); + expect(got).toHaveLength(3); + expect(got[1].trait).toContain("primary faction"); + }); +}); + +describe("buildEncountersList", () => { + const rooms = [{ name: "Hall", description: "x" }, { name: "Corridor", description: "y" }]; + const coreConcepts = "Dynamic Element: Magic. Central Conflict: War."; + + it("returns 6 new encounters when parsedEncounters is empty", () => { + const got = buildEncountersList([], rooms, coreConcepts); + expect(got).toHaveLength(6); + expect(got[0].name).toMatch(/Encounter$/); + expect(got[0].details).toContain("magic"); + }); + + it("pads when 0 < length < 6", () => { + const parsed = [ + { name: "Patrol", details: "Hall: A patrol." }, + { name: "Ambush", details: "Corridor: Bandits." }, + ]; + const got = buildEncountersList(parsed, rooms, coreConcepts); + expect(got).toHaveLength(6); + expect(got[0].name).toBe("Patrol"); + expect(got[2].details).toContain("magic"); + }); + + it("returns input when length >= 6", () => { + const parsed = Array.from({ length: 6 }, (_, i) => ({ name: `E${i + 1}`, details: `Hall: Details ${i}.` })); + const got = buildEncountersList(parsed, rooms, coreConcepts); + expect(got).toHaveLength(6); + expect(got[0].name).toBe("E1"); + }); + + it("uses Unknown Location when rooms array is empty", () => { + const got = buildEncountersList([], [], coreConcepts); + expect(got).toHaveLength(6); + expect(got[0].name).toContain("Unknown Location"); + }); + + it("uses default dynamicElement and conflict when coreConcepts is null", () => { + const got = buildEncountersList([], [{ name: "Hall" }], null); + expect(got).toHaveLength(6); + expect(got[0].details).toContain("strange"); + }); +}); + +describe("mergeRandomEventsWithFallbacks", () => { + const coreConcepts = "Central Conflict: War. Dynamic Element: Magic."; + + it("returns empty when parsedEvents empty (no fill)", () => { + const got = mergeRandomEventsWithFallbacks([], coreConcepts, 6); + expect(got).toHaveLength(0); + }); + + it("merges when 0 < length < maxCount", () => { + const parsed = [ + { name: "Rift", description: "Time skips." }, + { name: "Patrol", description: "Guard approaches." }, + ]; + const got = mergeRandomEventsWithFallbacks(parsed, coreConcepts, 6); + expect(got).toHaveLength(6); + expect(got[0].name).toBe("Rift"); + expect(got[2].name).toBe("Dungeon Shift"); + }); + + it("returns truncated list when length >= maxCount", () => { + const parsed = Array.from({ length: 6 }, (_, i) => ({ name: `E${i + 1}`, description: "x" })); + const got = mergeRandomEventsWithFallbacks(parsed, coreConcepts, 6); + expect(got).toHaveLength(6); + expect(got[0].name).toBe("E1"); + }); + + it("uses default conflict when coreConcepts is null", () => { + const parsed = [{ name: "E1", description: "x" }]; + const got = mergeRandomEventsWithFallbacks(parsed, null, 6); + expect(got).toHaveLength(6); + expect(got[1].name).toBe("Conflict Manifestation"); + }); +}); + +describe("limitIntermediateRooms", () => { + it("returns slice when length > maxCount and warns", () => { + const rooms = [ + { name: "A", description: "x" }, + { name: "B", description: "y" }, + { name: "C", description: "z" }, + { name: "D", description: "w" }, + ]; + const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); + const got = limitIntermediateRooms(rooms, 3); + expect(got).toHaveLength(3); + expect(got[0].name).toBe("A"); + expect(warn).toHaveBeenCalledWith(expect.stringContaining("Expected exactly 3 intermediate")); + warn.mockRestore(); + }); + + it("returns all when length <= maxCount", () => { + const rooms = [{ name: "A", description: "x" }, { name: "B", description: "y" }]; + const got = limitIntermediateRooms(rooms, 3); + expect(got).toHaveLength(2); + }); +}); + +describe("fixRoomPlaceholderName", () => { + it("returns room unchanged when name is not placeholder", () => { + const room = { name: "Grand Hall", description: "A big hall." }; + fixRoomPlaceholderName(room); + expect(room.name).toBe("Grand Hall"); + }); + + it("extracts name from description when name is Room Name and description has Name: prefix", () => { + const room = { name: "Room Name", description: "Whispering Gallery: Dim light." }; + fixRoomPlaceholderName(room); + expect(room.name).toBe("Whispering Gallery"); + expect(room.description).toContain("Dim"); + }); + + it("extracts name and updates description when first regex matches (colon)", () => { + const room = { name: "Room Name", description: "Grand Hall: Big space." }; + fixRoomPlaceholderName(room); + expect(room.name).toBe("Grand Hall"); + expect(room.description).toBe("Big space."); + }); + + it("extracts name when second regex matches (is)", () => { + const room = { name: "Room Name", description: "The Chamber is dark." }; + fixRoomPlaceholderName(room); + expect(room.name).toBe("Chamber"); + }); + + it("uses fallback first words when no nameMatch", () => { + const room = { name: "room name", description: "No match here at all" }; + fixRoomPlaceholderName(room); + expect(room.name).toBe("No match here at"); + }); + + it("returns null for null input", () => { + expect(fixRoomPlaceholderName(null)).toBeNull(); + }); +}); + +describe("parseList", () => { + it("returns empty array for empty input", () => { + expect(parseList("")).toEqual([]); + expect(parseList(null)).toEqual([]); + }); + + it("parses single numbered item", () => { + expect(parseList("1. First item")).toEqual(["First item"]); + }); + + it("uses fallback split when regex does not match", () => { + const raw = "1) Only paren style"; + const got = parseList(raw); + expect(got.length).toBeGreaterThanOrEqual(1); + }); + + it("parses multiple numbered items", () => { + const raw = "1. One\n2. Two\n3. Three"; + expect(parseList(raw)).toEqual(["One", "Two", "Three"]); + }); + + it("handles fallback format", () => { + const raw = "1) Item A"; + expect(parseList(raw).length).toBeGreaterThanOrEqual(1); + }); +}); + +describe("parseObjects", () => { + it("parses rooms with name and description", () => { + const raw = "1. Room Name - A dark room."; + const got = parseObjects(raw, "rooms"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Room Name"); + expect(got[0].description).toContain("dark"); + }); + + it("filters placeholder names for rooms", () => { + const raw = "1. Location Name - desc"; + expect(parseObjects(raw, "rooms")).toHaveLength(0); + }); + + it("parses encounters with name and details", () => { + const raw = "1. Goblin: Hall: Attacks."; + const got = parseObjects(raw, "encounters"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Goblin"); + expect(got[0].details).toContain("Hall"); + }); + + it("parses treasure with em-dash", () => { + const raw = "1. Gold — Shiny coins."; + const got = parseObjects(raw, "treasure"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Gold"); + expect(got[0].description).toContain("Shiny"); + }); + + it("parses treasure with hyphen (generic path)", () => { + const raw = "1. Silver - A pile of silver."; + const got = parseObjects(raw, "treasure"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Silver"); + expect(got[0].description).toContain("pile"); + }); + + it("parses npcs with trait", () => { + const raw = "1. Guard: A stern guard."; + const got = parseObjects(raw, "npcs"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Guard"); + expect(got[0].trait).toContain("stern"); + }); + + it("filters encounter placeholder names (Location Name / Encounter Name)", () => { + const rawWithPlaceholder = "1. Location Name: Hall: Some details here for the encounter."; + const got = parseObjects(rawWithPlaceholder, "encounters"); + expect(got).toHaveLength(0); + const rawEncName = "1. Encounter Name: Room: Details."; + expect(parseObjects(rawEncName, "encounters")).toHaveLength(0); + }); + + it("parses encounter with two-part format (Name: details)", () => { + const raw = "1. Goblin: Attacks in the hall."; + const got = parseObjects(raw, "encounters"); + expect(got).toHaveLength(1); + expect(got[0].name).toBe("Goblin"); + expect(got[0].details).toContain("Attacks"); + }); + + it("filters out encounter with only one part (no colon)", () => { + const raw = "1. OnlyOnePart"; + const got = parseObjects(raw, "encounters"); + expect(got).toHaveLength(0); + }); + + it("filters treasure with placeholder name", () => { + const raw = "1. Treasure Name — A shiny thing."; + expect(parseObjects(raw, "treasure")).toHaveLength(0); + }); + + it("filters room with NPC Name placeholder", () => { + const raw = "1. NPC Name - A person."; + expect(parseObjects(raw, "rooms")).toHaveLength(0); + }); +}); + +describe("parseEncounterText", () => { + it("parses Encounter N Name Room Name Details format", () => { + const text = "Encounter 1 Goblin Room Name Hall Details In the hall."; + const got = parseEncounterText(text, 0); + expect(got).not.toBeNull(); + expect(got.name).toBe("Goblin"); + expect(got.details).toContain("Hall"); + }); + + it("parses Encounter N Name: Location: Details format", () => { + const got = parseEncounterText("Encounter 1 Boss: Grand Hall: The boss waits here.", 0); + expect(got).not.toBeNull(); + expect(got.name).toBe("Boss"); + expect(got.details).toMatch(/Grand Hall.*boss/); + }); + + it("parses simple N Name: details format", () => { + const got = parseEncounterText("1. Boss: The boss appears.", 0); + expect(got).not.toBeNull(); + expect(got.name).toContain("Boss"); + expect(got.details).toContain("appears"); + }); + + it("parses via colonSplit when text has colon but no leading number format", () => { + const got = parseEncounterText("Goblin: Hall: Attacks here.", 0); + expect(got).not.toBeNull(); + expect(got.name).toBe("Goblin"); + expect(got.details).toContain("Hall"); + }); + + it("returns fallback name and trimmed details when no other format matches", () => { + const got = parseEncounterText("1. xyz short", 2); + expect(got.name).toBe("Encounter 3"); + expect(got.details).toBeTruthy(); + }); +}); + +describe("splitCombinedEncounters", () => { + it("returns empty for empty array", () => { + expect(splitCombinedEncounters([])).toEqual([]); + }); + + it("returns same array when not combined", () => { + const list = [{ name: "E1", details: "Short." }]; + expect(splitCombinedEncounters(list)).toEqual(list); + }); + + it("returns encounter unchanged when details are missing", () => { + const encounters = [{ name: "E1" }]; + const rooms = [{ name: "Hall" }]; + const { encounters: out } = standardizeEncounterLocations(encounters, rooms); + expect(out[0]).toEqual(encounters[0]); + }); + + it("splits when single encounter has combined text", () => { + const combined = "Encounter 1 A Hall Details First. Encounter 2 B Room Details Second."; + const list = [{ name: "1", details: combined }]; + const got = splitCombinedEncounters(list); + expect(got.length).toBeGreaterThanOrEqual(1); + }); + + it("splits when single encounter details contain number and capital (combined)", () => { + const list = [{ name: "E1", details: "Hall: First part. 2 Second Encounter in room." }]; + const got = splitCombinedEncounters(list); + expect(got.length).toBeGreaterThanOrEqual(1); + }); +}); + +describe("standardizeEncounterLocations", () => { + it("returns input when encounters or rooms missing", () => { + const enc = [{ name: "E1", details: "x" }]; + expect(standardizeEncounterLocations(null, [])).toEqual({ encounters: null, fixes: [] }); + expect(standardizeEncounterLocations(enc, null)).toEqual({ encounters: enc, fixes: [] }); + }); + + it("adds colon after room name when missing", () => { + const encounters = [{ name: "E1", details: "Hall something" }]; + const rooms = [{ name: "Hall" }]; + const { encounters: out, fixes } = standardizeEncounterLocations(encounters, rooms); + expect(out[0].details).toMatch(/Hall:\s/); + expect(fixes.length).toBeGreaterThanOrEqual(0); + }); + + it("leaves details unchanged when location already has colon", () => { + const encounters = [{ name: "E1", details: "Hall: already has colon." }]; + const rooms = [{ name: "Hall" }]; + const { encounters: out, fixes } = standardizeEncounterLocations(encounters, rooms); + expect(out[0].details).toBe("Hall: already has colon."); + expect(fixes).toHaveLength(0); + }); + + it("leaves details unchanged when no room match", () => { + const encounters = [{ name: "E1", details: "Unknown: text" }]; + const rooms = [{ name: "Hall" }]; + const { encounters: out } = standardizeEncounterLocations(encounters, rooms); + expect(out[0].details).toBe("Unknown: text"); + }); + + it("applies standardization when second room name matches details prefix", () => { + const encounters = [{ name: "E1", details: "Corridor something" }]; + const rooms = [{ name: "Hall" }, { name: "Corridor" }]; + const { encounters: out } = standardizeEncounterLocations(encounters, rooms); + expect(out[0].details).toMatch(/Corridor:\s/); + }); +}); + +describe("validateContentCompleteness", () => { + it("reports missing title", () => { + const issues = validateContentCompleteness({ flavor: "x".repeat(30) }); + expect(issues.some((i) => i.toLowerCase().includes("title"))).toBe(true); + }); + + it("reports short flavor", () => { + const issues = validateContentCompleteness({ title: "X", flavor: "short" }); + expect(issues.some((i) => i.toLowerCase().includes("flavor"))).toBe(true); + }); + + it("reports few hooks", () => { + const issues = validateContentCompleteness({ + title: "X", + flavor: "a ".repeat(15), + hooksRumors: ["one"], + }); + expect(issues.some((i) => i.toLowerCase().includes("hook"))).toBe(true); + }); + + it("reports when plotResolutions array is too short", () => { + const issues = validateContentCompleteness({ + title: "T", + flavor: "a ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + rooms: [], + encounters: [], + npcs: [], + plotResolutions: ["one"], + }); + expect(issues.some((i) => i.toLowerCase().includes("plot") || i.includes("resolution"))).toBe(true); + }); + + it("returns empty for valid full data", () => { + const roomDesc = "A room with enough description length here."; + const data = { + title: "Test", + flavor: "A ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + rooms: Array.from({ length: 5 }, (_, i) => ({ name: `R${i + 1}`, description: roomDesc })), + encounters: Array.from({ length: 6 }, (_, i) => ({ name: `E${i + 1}`, details: `R1: Encounter details long enough.` })), + npcs: Array.from({ length: 4 }, (_, i) => ({ name: `N${i + 1}`, trait: "Trait with enough length for validation." })), + treasure: Array.from({ length: 4 }, (_, i) => ({ name: `T${i + 1}`, description: "x" })), + randomEvents: Array.from({ length: 6 }, (_, i) => ({ name: `Ev${i + 1}`, description: "y" })), + plotResolutions: ["p1", "p2", "p3", "p4"], + }; + const issues = validateContentCompleteness(data); + expect(issues.length).toBe(0); + }); + + it("does not push room description issues when rooms is undefined", () => { + const issues = validateContentCompleteness({ + title: "T", + flavor: "A ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + }); + expect(issues.some((i) => i.includes("Room") && i.includes("description"))).toBe(false); + }); + + it("reports room description too short", () => { + const data = { + title: "T", + flavor: "A ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + rooms: [{ name: "R1", description: "Short." }], + encounters: [], + npcs: [], + }; + const issues = validateContentCompleteness(data); + expect(issues.some((i) => i.includes("description too short"))).toBe(true); + }); + + it("reports encounter details too short", () => { + const data = { + title: "T", + flavor: "A ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + rooms: [], + encounters: [{ name: "E1", details: "Short." }], + npcs: [], + }; + const issues = validateContentCompleteness(data); + expect(issues.some((i) => i.includes("details too short"))).toBe(true); + }); + + it("reports NPC trait too short", () => { + const data = { + title: "T", + flavor: "A ".repeat(15), + hooksRumors: ["a", "b", "c", "d"], + rooms: [], + encounters: [], + npcs: [{ name: "N1", trait: "Short." }], + }; + const issues = validateContentCompleteness(data); + expect(issues.some((i) => i.includes("description too short"))).toBe(true); + }); +}); + +describe("validateContentQuality", () => { + it("reports vague language when too many vague words", () => { + const data = { + flavor: "Some various several things stuff items here.", + }; + const issues = validateContentQuality(data); + expect(issues.some((i) => i.includes("vague language"))).toBe(true); + }); + + it("reports short room description", () => { + const data = { + rooms: [{ name: "R1", description: "Short." }], + }; + const issues = validateContentQuality(data); + expect(issues.some((i) => i.includes("too short"))).toBe(true); + }); + + it("skips vague check when text is missing", () => { + const data = { rooms: [{ name: "R1" }] }; + const issues = validateContentQuality(data); + expect(issues.filter((i) => i.includes("vague"))).toHaveLength(0); + }); +}); + +describe("validateContentStructure", () => { + it("reports missing room name", () => { + const data = { rooms: [{ name: "", description: "x" }] }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("Room") && i.includes("name"))).toBe(true); + }); + + it("reports room name too long", () => { + const data = { + rooms: [{ name: "One Two Three Four Five Six Seven", description: "A room." }], + }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("name too long"))).toBe(true); + }); + + it("reports encounter missing location prefix", () => { + const data = { + encounters: [{ name: "E1", details: "no colon prefix" }], + }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("location"))).toBe(true); + }); + + it("reports encounter name too long", () => { + const data = { + encounters: [{ name: "A B C D E F G", details: "Hall: details" }], + }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("name too long"))).toBe(true); + }); + + it("reports no location-prefix issue when details have Location: prefix", () => { + const data = { + encounters: [{ name: "E1", details: "Hall: proper prefix." }], + }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("location"))).toBe(false); + }); + + it("reports NPC name too long", () => { + const data = { + npcs: [{ name: "Alice Bob Carol Dave Eve", trait: "Long trait here." }], + }; + const issues = validateContentStructure(data); + expect(issues.some((i) => i.includes("name too long"))).toBe(true); + }); +}); + +describe("validateNarrativeCoherence", () => { + it("reports unknown location in encounter details", () => { + const data = { + rooms: [{ name: "Hall" }], + encounters: [{ name: "E1", details: "UnknownPlace: text" }], + }; + const issues = validateNarrativeCoherence(data); + expect(issues.some((i) => i.includes("unknown location"))).toBe(true); + }); + + it("reports poorly integrated faction when few refs", () => { + const data = { + coreConcepts: "Primary Faction: The Guard.", + npcs: [{ name: "N1", trait: "unrelated" }], + encounters: [{ name: "E1", details: "Hall: no faction" }], + }; + const issues = validateNarrativeCoherence(data); + expect(issues.some((i) => i.includes("Faction"))).toBe(true); + }); + + it("reports no issue when faction has enough refs", () => { + const data = { + coreConcepts: "Primary Faction: The Guard.", + rooms: [{ name: "Hall" }], + npcs: [{ name: "N1", trait: "Member of the Guard." }], + encounters: [ + { name: "E1", details: "Hall: The Guard patrols here." }, + { name: "E2", details: "Hall: Guard reinforcements." }, + ], + }; + const issues = validateNarrativeCoherence(data); + expect(issues.filter((i) => i.includes("Faction"))).toHaveLength(0); + }); + + it("reports no issue when coreConcepts has no Primary Faction", () => { + const data = { + coreConcepts: "Central Conflict: War.", + rooms: [{ name: "Hall" }], + encounters: [{ name: "E1", details: "Hall: text" }], + }; + const issues = validateNarrativeCoherence(data); + expect(issues).toHaveLength(0); + }); +}); + +describe("extractCanonicalNames", () => { + it("extracts npc and room names", () => { + const data = { + npcs: [{ name: "Alice" }], + rooms: [{ name: "Hall" }], + coreConcepts: "Primary Faction: The Guard.", + }; + const names = extractCanonicalNames(data); + expect(names.npcs).toContain("Alice"); + expect(names.rooms).toContain("Hall"); + expect(names.factions).toContain("The Guard"); + }); + + it("returns empty factions when coreConcepts has no Primary Faction", () => { + const data = { coreConcepts: "Central Conflict: War. Dynamic Element: Magic." }; + const names = extractCanonicalNames(data); + expect(names.factions).toHaveLength(0); + }); +}); + +describe("validateNameConsistency", () => { + it("fixes NPC name in flavor and hooks when inconsistent", () => { + const data = { + flavor: "The alice is here.", + hooksRumors: ["alice said something."], + encounters: [{ name: "E1", details: "Hall: alice appears." }], + plotResolutions: ["alice wins."], + npcs: [{ name: "Alice" }], + rooms: [{ name: "Hall" }], + }; + const fixes = validateNameConsistency(data); + expect(data.flavor).toContain("Alice"); + expect(fixes.some((f) => f.includes("Flavor") || f.includes("flavor"))).toBe(true); + }); + + it("fixes room name in encounter details when inconsistent", () => { + const data = { + encounters: [{ name: "E1", details: "main hall: something." }], + rooms: [{ name: "Main Hall", description: "x" }], + }; + const fixes = validateNameConsistency(data); + expect(data.encounters[0].details).toContain("Main Hall"); + expect(fixes.some((f) => f.includes("room") || f.includes("Room"))).toBe(true); + }); +}); + +describe("fixStructureIssues", () => { + it("adds default room name when description has no extractable name", () => { + const data = { + rooms: [{ name: "", description: "x" }], + }; + const fixes = fixStructureIssues(data); + expect(data.rooms[0].name).toBe("Room 1"); + expect(fixes.some((f) => f.includes("Added default name for room"))).toBe(true); + }); + + it("adds default encounter name when details have no colon", () => { + const data = { + encounters: [{ name: "", details: "no colon here" }], + }; + const fixes = fixStructureIssues(data); + expect(data.encounters[0].name).toBe("Encounter 1"); + expect(fixes.some((f) => f.includes("Added default name for encounter"))).toBe(true); + }); + + it("extracts encounter name from details when details have Name: Rest", () => { + const data = { + encounters: [{ name: "", details: "Goblin King: Attacks from the shadows." }], + }; + const fixes = fixStructureIssues(data); + expect(data.encounters[0].name).toBe("Goblin King"); + expect(data.encounters[0].details).toContain("Attacks"); + expect(fixes.some((f) => f.includes("Extracted encounter name"))).toBe(true); + }); + + it("adds default NPC name when trait has no extractable name", () => { + const data = { + npcs: [{ name: "", trait: "no capital word at start" }], + }; + const fixes = fixStructureIssues(data); + expect(data.npcs[0].name).toBe("NPC 1"); + expect(fixes.some((f) => f.includes("Added default name for NPC"))).toBe(true); + }); + + it("extracts NPC name from trait when trait starts with Capital Name", () => { + const data = { + npcs: [{ name: "", trait: "Captain Smith: leads the guard." }], + }; + const fixes = fixStructureIssues(data); + expect(data.npcs[0].name).toBe("Captain Smith"); + expect(fixes.some((f) => f.includes("Extracted NPC name"))).toBe(true); + }); + + it("truncates room name over 6 words", () => { + const data = { + rooms: [{ name: "A B C D E F G H", description: "Room." }], + }; + const fixes = fixStructureIssues(data); + expect(data.rooms[0].name).toBe("A B C D E F"); + expect(fixes.some((f) => f.includes("Truncated room name"))).toBe(true); + }); + + it("truncates encounter name over 6 words", () => { + const data = { + encounters: [{ name: "A B C D E F G", details: "Hall: x" }], + }; + const fixes = fixStructureIssues(data); + expect(data.encounters[0].name).toBe("A B C D E F"); + expect(fixes.some((f) => f.includes("Truncated encounter name"))).toBe(true); + }); + + it("truncates NPC name over 4 words", () => { + const data = { + npcs: [{ name: "A B C D E", trait: "Trait." }], + }; + const fixes = fixStructureIssues(data); + expect(data.npcs[0].name).toBe("A B C D"); + expect(fixes.some((f) => f.includes("Truncated NPC name"))).toBe(true); + }); +}); + +describe("fixMissingContent", () => { + it("pads encounters using rooms when encounters exist but under 6", () => { + const data = { + rooms: [{ name: "Hall", description: "A hall." }], + encounters: [{ name: "E1", details: "Hall: first." }], + coreConcepts: "Dynamic Element: Magic. Central Conflict: War.", + }; + const fixes = fixMissingContent(data); + expect(data.encounters.length).toBe(6); + expect(fixes.some((f) => f.includes("fallback") || f.includes("Added"))).toBe(true); + }); + + it("pads NPCs to 4 when missing", () => { + const data = { npcs: [], coreConcepts: "Primary Faction: Guard." }; + const fixes = fixMissingContent(data); + expect(data.npcs.length).toBe(4); + expect(fixes.length).toBeGreaterThan(0); + }); + + it("pads treasure to 4 when missing", () => { + const data = { treasure: [] }; + const fixes = fixMissingContent(data); + expect(data.treasure.length).toBe(4); + expect(fixes.some((f) => f.includes("treasure"))).toBe(true); + }); + + it("pads random events to 6 when some exist and coreConcepts set", () => { + const data = { + randomEvents: [{ name: "E1", description: "One." }], + coreConcepts: "Dynamic Element: Magic. Central Conflict: War.", + }; + const fixes = fixMissingContent(data); + expect(data.randomEvents.length).toBe(6); + expect(fixes.some((f) => f.includes("random event"))).toBe(true); + }); + + it("pads plot resolutions to 4 when missing", () => { + const data = { plotResolutions: [] }; + const fixes = fixMissingContent(data); + expect(data.plotResolutions.length).toBe(4); + expect(fixes.some((f) => f.includes("plot resolution"))).toBe(true); + }); + + it("does not add random event fallbacks when randomEvents is empty", () => { + const data = { randomEvents: [], coreConcepts: "Dynamic Element: Magic." }; + fixMissingContent(data); + expect(data.randomEvents.length).toBe(0); + }); +}); + +describe("fixNarrativeCoherence", () => { + it("fixes encounter with unknown location by assigning a room", () => { + const data = { + rooms: [{ name: "Hall", description: "A hall." }], + encounters: [{ name: "E1", details: "UnknownPlace: something happens." }], + }; + const fixes = fixNarrativeCoherence(data); + expect(data.encounters[0].details).toMatch(/^Hall:\s/); + expect(fixes.some((f) => f.includes("Fixed unknown location"))).toBe(true); + }); + + it("leaves encounter unchanged when location matches a room name", () => { + const data = { + rooms: [{ name: "Hall", description: "A hall." }], + encounters: [{ name: "E1", details: "Hall: something." }], + }; + const fixes = fixNarrativeCoherence(data); + expect(data.encounters[0].details).toBe("Hall: something."); + expect(fixes).toHaveLength(0); + }); + + it("does not assign room when rooms array is empty", () => { + const data = { + rooms: [], + encounters: [{ name: "E1", details: "Unknown: text." }], + }; + const fixes = fixNarrativeCoherence(data); + expect(data.encounters[0].details).toBe("Unknown: text."); + expect(fixes).toHaveLength(0); + }); +}); + +describe("validateAndFixContent", () => { + it("applies fixes and returns dungeonData", () => { + const dungeonData = { + title: "Test", + flavor: "A ".repeat(20), + hooksRumors: ["a", "b", "c", "d"], + rooms: [ + { name: "", description: "Grand Hall. A big room." }, + { name: "Room2", description: "Second." }, + ], + encounters: [ + { name: "", details: "Something happens." }, + ], + npcs: [], + treasure: [], + randomEvents: [], + plotResolutions: ["One."], + coreConcepts: "Primary Faction: Guard. Dynamic Element: Magic.", + }; + const result = validateAndFixContent(dungeonData); + expect(result).toBeDefined(); + expect(result.title).toBe("Test"); + expect(dungeonData.rooms[0].name).toBeTruthy(); + expect(dungeonData.encounters[0].name).toBeTruthy(); + }); + + it("adds location to encounter when details lack location prefix", () => { + const dungeonData = { + title: "Test", + flavor: "A ".repeat(20), + hooksRumors: ["a", "b", "c", "d"], + rooms: [{ name: "Hall", description: "A hall." }], + encounters: [{ name: "E1", details: "no colon prefix" }], + npcs: [], + coreConcepts: "Primary Faction: Guard.", + }; + const result = validateAndFixContent(dungeonData); + expect(dungeonData.encounters[0].details).toMatch(/^Hall:\s/); + expect(result).toBeDefined(); + }); + + it("skips encounter when details are missing", () => { + const dungeonData = { + title: "Test", + flavor: "A ".repeat(20), + hooksRumors: ["a", "b", "c", "d"], + rooms: [{ name: "Hall", description: "A hall." }], + encounters: [{ name: "E1" }], + npcs: [], + coreConcepts: "Primary Faction: Guard.", + }; + const result = validateAndFixContent(dungeonData); + expect(result.encounters[0].details).toBeUndefined(); + }); + + it("logs Content quality checks passed when no issues remain", () => { + const longDesc = "A room with enough descriptive text to pass length checks here."; + const longDetails = "Hall: Encounter details that are long enough for validation."; + const longTrait = "An NPC with a trait long enough to pass validation here."; + const dungeonData = { + title: "Valid Dungeon", + flavor: "A dungeon with enough flavor text to pass the minimum length.", + hooksRumors: ["a", "b", "c", "d"], + rooms: [ + { name: "Hall", description: longDesc }, + { name: "Room2", description: longDesc }, + { name: "Room3", description: longDesc }, + { name: "Room4", description: longDesc }, + { name: "Room5", description: longDesc }, + ], + encounters: [ + { name: "E1", details: longDetails }, + { name: "E2", details: longDetails }, + { name: "E3", details: longDetails }, + { name: "E4", details: longDetails }, + { name: "E5", details: longDetails }, + { name: "E6", details: longDetails }, + ], + npcs: [ + { name: "Guard", trait: longTrait + " Guard faction." }, + { name: "Captain", trait: longTrait + " Guard faction." }, + { name: "N3", trait: longTrait }, + { name: "N4", trait: longTrait }, + ], + treasure: [{ name: "T1", description: "d" }, { name: "T2", description: "d" }, { name: "T3", description: "d" }, { name: "T4", description: "d" }], + randomEvents: Array(6).fill({ name: "Event", description: "Desc" }), + plotResolutions: ["P1", "P2", "P3", "P4"], + coreConcepts: "Primary Faction: Guard. Dynamic Element: Magic.", + }; + const logSpy = vi.spyOn(console, "log").mockImplementation(() => {}); + validateAndFixContent(dungeonData); + expect(logSpy).toHaveBeenCalledWith("\n[Validation] Content quality checks passed"); + logSpy.mockRestore(); + }); +}); diff --git a/test/unit/dungeonTemplate.test.js b/test/unit/dungeonTemplate.test.js new file mode 100644 index 0000000..1667fc5 --- /dev/null +++ b/test/unit/dungeonTemplate.test.js @@ -0,0 +1,227 @@ +import { describe, it, expect } from "vitest"; +import { + escapeHtml, + truncateText, + parseEventForDisplay, + dungeonTemplate, +} from "../../src/dungeonTemplate.js"; + +describe("escapeHtml", () => { + it("returns empty string for empty input", () => { + expect(escapeHtml("")).toBe(""); + }); + + it("returns empty string for null/undefined-like", () => { + expect(escapeHtml(null)).toBe(""); + expect(escapeHtml(undefined)).toBe(""); + }); + + it("escapes & < > \" '", () => { + expect(escapeHtml("&")).toBe("&"); + expect(escapeHtml("<")).toBe("<"); + expect(escapeHtml(">")).toBe(">"); + expect(escapeHtml('"')).toBe("""); + expect(escapeHtml("'")).toBe("'"); + expect(escapeHtml('')).toBe( + "<script>&"'</script>" + ); + }); + + it("leaves normal text unchanged", () => { + expect(escapeHtml("Hello World")).toBe("Hello World"); + }); +}); + +describe("truncateText", () => { + it("returns empty for empty input", () => { + expect(truncateText("", 1, 100)).toBe(""); + }); + + it("returns text when within sentence and char limits", () => { + const one = "One sentence."; + expect(truncateText(one, 1, 100)).toBe(one); + }); + + it("truncates to maxSentences", () => { + const three = "First. Second. Third."; + expect(truncateText(three, 1, 500)).toBe("First."); + expect(truncateText(three, 2, 500)).toContain("First."); + expect(truncateText(three, 2, 500)).toContain("Second."); + }); + + it("truncates by maxChars and ends at sentence boundary when possible", () => { + const long = "A short bit. Then a much longer sentence that goes past the limit we set."; + const out = truncateText(long, 99, 30); + expect(out.length).toBeLessThanOrEqual(33); + expect(out === "A short bit." || out.endsWith("...")).toBe(true); + }); + + it("appends ... when no sentence boundary near end", () => { + const noPeriod = "No period here and more text"; + expect(truncateText(noPeriod, 1, 15)).toMatch(/\.\.\.$/); + }); +}); + +describe("parseEventForDisplay", () => { + it("returns object name and description when given object", () => { + const event = { name: "Event A", description: "Something happened." }; + const got = parseEventForDisplay(event, 0); + expect(got.name).toBe("Event A"); + expect(got.description).toContain("Something"); + }); + + it('parses "Name: Description" string', () => { + const got = parseEventForDisplay("Fire: The room catches fire.", 0); + expect(got.name).toBe("Fire"); + expect(got.description).toContain("catches fire"); + }); + + it("splits string without colon into first two words as name, rest as description", () => { + const got = parseEventForDisplay("One Two Three Four", 0); + expect(got.name).toBe("One Two"); + expect(got.description).toBe("Three Four"); + }); + + it("uses fallback Event N and full string for short string", () => { + const got = parseEventForDisplay("Hi", 2); + expect(got.name).toBe("Event 3"); + expect(got.description).toBe("Hi"); + }); + + it("handles non-string non-object with index", () => { + const got = parseEventForDisplay(null, 1); + expect(got.name).toBe("Event 2"); + expect(got.description).toBe(""); + }); +}); + +describe("dungeonTemplate", () => { + it("produces HTML with title and main sections for minimal data", () => { + const data = { + title: "Test Dungeon", + flavor: "A dark place.", + hooksRumors: ["Hook one.", "Hook two."], + rooms: [{ name: "Room 1", description: "A room." }], + encounters: [{ name: "Encounter 1", details: "Hall: Something happens." }], + npcs: [{ name: "NPC 1", trait: "A guard." }], + treasure: [{ name: "Gold", description: "Shiny." }], + randomEvents: [{ name: "Event 1", description: "Something." }], + plotResolutions: ["Resolution one."], + }; + const html = dungeonTemplate(data); + expect(html).toContain("Test Dungeon"); + expect(html).toContain("A dark place."); + expect(html).toContain("Room 1"); + expect(html).toContain("Encounter 1"); + expect(html).toContain("NPC 1"); + expect(html).toContain("Gold"); + expect(html).toContain("Event 1"); + expect(html).toContain("Resolution one."); + expect(html).toContain(""); + }); + + it("includes map page when data.map is data URL", () => { + const data = { + title: "With Map", + flavor: "Flavor.", + map: "data:image/png;base64,abc123", + hooksRumors: ["H1"], + rooms: [], + encounters: [], + npcs: [], + treasure: [], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("map-page"); + expect(html).toContain("data:image/png;base64,abc123"); + }); + + it("omits flavor paragraph when flavor is empty", () => { + const data = { + title: "No Flavor", + flavor: "", + hooksRumors: ["H1"], + rooms: [], + encounters: [], + npcs: [], + treasure: [], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("No Flavor"); + expect(html).not.toMatch(/

/); + }); + + it("renders treasure as string Name — Desc", () => { + const data = { + title: "T", + flavor: "F", + hooksRumors: [], + rooms: [], + encounters: [], + npcs: [], + treasure: ["Gold — Shiny coins."], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("Gold"); + expect(html).toContain("Shiny coins"); + }); + + it("renders NPC as string Name: Trait", () => { + const data = { + title: "T", + flavor: "F", + hooksRumors: [], + rooms: [], + encounters: [], + npcs: ["Guard: A stern guard."], + treasure: [], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("Guard"); + expect(html).toContain("stern guard"); + }); + + it("strips location prefix from encounter details when it looks like a location name", () => { + const data = { + title: "T", + flavor: "F", + hooksRumors: [], + rooms: [{ name: "Grand Hall", description: "Big." }], + encounters: [ + { name: "E1", details: "Grand Hall: The fight happens here in the hall." }, + ], + npcs: [], + treasure: [], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("The fight happens here"); + }); + + it("renders encounter details without name when details start with encounter name", () => { + const data = { + title: "T", + flavor: "F", + hooksRumors: [], + rooms: [], + encounters: [ + { name: "Goblin Attack", details: "Goblin Attack: They strike." }, + ], + npcs: [], + treasure: [], + randomEvents: [], + plotResolutions: [], + }; + const html = dungeonTemplate(data); + expect(html).toContain("They strike"); + }); +}); diff --git a/test/unit/ollamaClient.test.js b/test/unit/ollamaClient.test.js new file mode 100644 index 0000000..eca3408 --- /dev/null +++ b/test/unit/ollamaClient.test.js @@ -0,0 +1,263 @@ +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import { + cleanText, + inferApiType, + callOllama, + callOllamaExplicit, + initializeModel, + OLLAMA_MODEL, +} from "../../src/ollamaClient.js"; + +describe("cleanText", () => { + it("strips markdown headers", () => { + expect(cleanText("# Title")).toBe("Title"); + expect(cleanText("## Sub")).toBe("Sub"); + }); + + it("replaces bold with plain text", () => { + expect(cleanText("**bold**")).toBe("bold"); + }); + + it("removes asterisks and underscores", () => { + expect(cleanText("*a* _b_")).toBe("a b"); + }); + + it("collapses whitespace to single spaces and trims", () => { + expect(cleanText(" a b \n c ")).toBe("a b c"); + }); +}); + +describe("inferApiType", () => { + it("returns ollama-generate for null/undefined/empty string", () => { + expect(inferApiType(null)).toBe("ollama-generate"); + expect(inferApiType(undefined)).toBe("ollama-generate"); + expect(inferApiType("")).toBe("ollama-generate"); + }); + + it("returns open-webui for URL with /api/chat/completions", () => { + expect(inferApiType("http://host/api/chat/completions")).toBe("open-webui"); + }); + + it("returns ollama-chat for URL with /api/chat", () => { + expect(inferApiType("http://host/api/chat")).toBe("ollama-chat"); + }); + + it("returns ollama-generate for plain base URL", () => { + expect(inferApiType("http://localhost:11434")).toBe("ollama-generate"); + }); +}); + +describe("callOllama (mocked fetch)", () => { + const originalFetch = globalThis.fetch; + const originalEnv = process.env.OLLAMA_API_URL; + + beforeEach(() => { + process.env.OLLAMA_API_URL = "http://localhost:11434"; + globalThis.fetch = vi.fn(); + }); + + afterEach(() => { + process.env.OLLAMA_API_URL = originalEnv; + globalThis.fetch = originalFetch; + }); + + it("returns cleaned text from ollama-generate response", async () => { + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({ response: "**Hello** world" }), + }); + const result = await callOllama("Hi", undefined, 1, "test"); + expect(result).toBe("Hello world"); + }); + + it("throws on non-ok response", async () => { + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: false, + status: 500, + statusText: "Error", + text: () => Promise.resolve("server error"), + }); + await expect(callOllama("Hi", undefined, 1, "test")).rejects.toThrow("Ollama request failed"); + }); + + it("throws on non-ok response when response.text() rejects", async () => { + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: false, + status: 502, + statusText: "Bad Gateway", + text: () => Promise.reject(new Error("body read error")), + }); + await expect(callOllama("Hi", undefined, 1, "test")).rejects.toThrow("Ollama request failed"); + }); + + it("retries on failure then succeeds", async () => { + vi.mocked(globalThis.fetch) + .mockRejectedValueOnce(new Error("network error")) + .mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({ response: "Retry ok" }), + }); + const result = await callOllama("Hi", undefined, 2, "test"); + expect(result).toBe("Retry ok"); + expect(globalThis.fetch).toHaveBeenCalledTimes(2); + }); +}); + +describe("callOllamaExplicit (mocked fetch)", () => { + const originalFetch = globalThis.fetch; + const originalUrl = process.env.OLLAMA_API_URL; + const originalKey = process.env.OLLAMA_API_KEY; + + beforeEach(() => { + globalThis.fetch = vi.fn(); + }); + + afterEach(() => { + process.env.OLLAMA_API_URL = originalUrl; + process.env.OLLAMA_API_KEY = originalKey; + globalThis.fetch = originalFetch; + }); + + it("returns content from open-webui response shape", async () => { + process.env.OLLAMA_API_URL = "http://host/api/chat/completions"; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => + Promise.resolve({ + choices: [{ message: { content: "**Open** answer" } }], + }), + }); + const result = await callOllamaExplicit( + "Hi", + "model", + 1, + "test", + "open-webui" + ); + expect(result).toBe("Open answer"); + }); + + it("sends Authorization header when open-webui and OLLAMA_API_KEY set", async () => { + process.env.OLLAMA_API_URL = "http://host/api/chat/completions"; + process.env.OLLAMA_API_KEY = "secret-key"; + process.env.OLLAMA_MODEL = ""; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => + Promise.resolve({ + choices: [{ message: { content: "ok" } }], + }), + }); + await callOllamaExplicit("Hi", "model", 1, "test", "open-webui"); + const [, opts] = vi.mocked(globalThis.fetch).mock.calls[0]; + expect(opts?.headers?.Authorization).toBe("Bearer secret-key"); + }); + + it("returns content from ollama-chat response shape", async () => { + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => + Promise.resolve({ message: { content: "Chat **reply**" } }), + }); + const result = await callOllamaExplicit( + "Hi", + "model", + 1, + "test", + "ollama-chat" + ); + expect(result).toBe("Chat reply"); + }); + + it("throws when response has no content", async () => { + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({}), + }); + await expect( + callOllamaExplicit("Hi", "model", 1, "test", "ollama-generate") + ).rejects.toThrow("No response from Ollama"); + }); +}); + +describe("initializeModel (mocked fetch)", () => { + const originalFetch = globalThis.fetch; + const originalEnv = process.env.OLLAMA_API_URL; + const originalOllamaModel = process.env.OLLAMA_MODEL; + + beforeEach(() => { + process.env.OLLAMA_API_URL = "http://localhost:11434"; + process.env.OLLAMA_MODEL = ""; + globalThis.fetch = vi.fn(); + }); + + afterEach(() => { + process.env.OLLAMA_API_URL = originalEnv; + process.env.OLLAMA_MODEL = originalOllamaModel; + globalThis.fetch = originalFetch; + }); + + it("does not fetch when OLLAMA_MODEL is set", async () => { + process.env.OLLAMA_MODEL = "existing-model"; + await initializeModel(); + expect(globalThis.fetch).not.toHaveBeenCalled(); + }); + + it("leaves OLLAMA_MODEL unchanged when fetch returns not ok", async () => { + process.env.OLLAMA_MODEL = ""; + const before = OLLAMA_MODEL; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: false, + status: 404, + json: () => Promise.resolve({}), + }); + await initializeModel(); + expect(OLLAMA_MODEL).toBe(before); + }); + + it("fetches /api/tags when OLLAMA_MODEL not set", async () => { + process.env.OLLAMA_MODEL = ""; + process.env.OLLAMA_API_URL = "http://localhost:11434"; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({ models: [{ name: "test-model" }] }), + }); + await initializeModel(); + expect(globalThis.fetch).toHaveBeenCalled(); + const [url, opts] = vi.mocked(globalThis.fetch).mock.calls[0]; + expect(String(url)).toMatch(/\/api\/tags$/); + expect(opts?.method || "GET").toBe("GET"); + }); + + it("fetches /api/v1/models when URL has open-webui path and sets model from data.data id", async () => { + process.env.OLLAMA_MODEL = ""; + process.env.OLLAMA_API_URL = "http://host/api/chat/completions"; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({ data: [{ id: "webui-model" }] }), + }); + await initializeModel(); + const [url] = vi.mocked(globalThis.fetch).mock.calls[0]; + expect(String(url)).toMatch(/\/api\/v1\/models$/); + expect(OLLAMA_MODEL).toBe("webui-model"); + }); + + it("sets model from data.data[0].name when id missing", async () => { + process.env.OLLAMA_MODEL = ""; + process.env.OLLAMA_API_URL = "http://host/api/chat/completions"; + vi.mocked(globalThis.fetch).mockResolvedValueOnce({ + ok: true, + json: () => Promise.resolve({ data: [{ name: "webui-model-name" }] }), + }); + await initializeModel(); + expect(OLLAMA_MODEL).toBe("webui-model-name"); + }); + + it("catches fetch failure and warns", async () => { + vi.mocked(globalThis.fetch).mockRejectedValueOnce(new Error("network")); + const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); + await initializeModel(); + expect(warn).toHaveBeenCalledWith(expect.stringContaining("Could not fetch default model")); + warn.mockRestore(); + }); +}); diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 0000000..25eb77b --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,29 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/node_modules/**", "**/integration/**", "**/integration.test.js"], + environment: "node", + }, + coverage: { + provider: "v8", + reporter: ["text", "text-summary"], + include: [ + "src/textUtils.js", + "src/parsing.js", + "src/validation.js", + "src/dungeonBuild.js", + "src/contentFixes.js", + "src/dungeonGenerator.js", + "src/dungeonTemplate.js", + "src/ollamaClient.js", + ], + exclude: ["test/**", "**/*.config.js", "index.js"], + thresholds: { + statements: 85, + branches: 85, + functions: 85, + lines: 85, + }, + }, +}); diff --git a/vitest.integration.config.js b/vitest.integration.config.js new file mode 100644 index 0000000..2773520 --- /dev/null +++ b/vitest.integration.config.js @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + include: ["test/integration/**/*.test.js"], + exclude: ["**/node_modules/**"], + environment: "node", + testTimeout: 120000, + }, +});

${index + 1}