(baseMenu: string | null | undefined, lines: readonly string[])
| 31 | } |
| 32 | |
| 33 | export function appendSkillMenuLines(baseMenu: string | null | undefined, lines: readonly string[]): string | null { |
| 34 | const visibleLines = normalizeSkillMenuLines(lines) |
| 35 | if (visibleLines.length === 0) return baseMenu ?? null |
| 36 | if (!baseMenu) return buildSkillMenuText(visibleLines) |
| 37 | |
| 38 | const insertion = `\n${visibleLines.join('\n')}` |
| 39 | if (!baseMenu.includes(SKILL_MENU_CLOSING_BLOCK)) { |
| 40 | return `${baseMenu}${insertion}` |
| 41 | } |
| 42 | |
| 43 | return baseMenu.replace(SKILL_MENU_CLOSING_BLOCK, `${insertion}${SKILL_MENU_CLOSING_BLOCK}`) |
| 44 | } |
| 45 | |
| 46 | function normalizeSkillMenuLines(lines: readonly string[]): string[] { |
| 47 | return lines.map((line) => line.trim()).filter(Boolean) |
no test coverage detected