/** Shared skill-tag collapse utilities */ const SKILL_TAG_RE = /^-?\s*/; /** Collapse skill tags in an array of lines — dedup by name, drop all content inside block */ export const collapseSkillLines = (lines: string[]): string[] => { const result: string[] = []; const seenSkills = new Set(); let insideSkill = false; for (const line of lines) { const skillMatch = line.match(SKILL_TAG_RE); if (skillMatch) { insideSkill = true; const name = skillMatch[1]; if (!seenSkills.has(name)) { seenSkills.add(name); result.push(`[skill: ${name}]`); } continue; } if (insideSkill) { if (SKILL_CLOSE_RE.test(line)) insideSkill = false; continue; } result.push(line); } return result; }; /** Collapse ... blocks in raw text */ const SKILL_BLOCK_RE = /]*>[\s\S]*?(?:<\/skill>|$)/g; export const collapseSkillText = (text: string): string => text.replace(SKILL_BLOCK_RE, (_, name) => `[skill: ${name}]`);