diff --git a/src/detect.ts b/src/detect.ts index a7401d6..cbaa480 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -1,8 +1,31 @@ /** Raw `/skill:name` at start of user input (SPEC §6.2 #1). */ const SLASH_SKILL_RE = /^\/skill:([a-z0-9-]+)/; +/** mirror agent-session `parseSkillBlock` — global scan (SPEC §6.2 #2). */ +const SKILL_BLOCK_RE = + /\n([\s\S]*?)\n<\/skill>/g; + +export interface ParsedSkillBlock { + name: string; + location: string; + content: string; +} + /** Returns skill name when text is a slash skill command, else null. */ export function detectSlashSkill(text: string): string | null { const match = SLASH_SKILL_RE.exec(text); return match?.[1] ?? null; } + +/** All skill blocks in message text (empty when none). */ +export function parseSkillBlocksFromText(text: string): ParsedSkillBlock[] { + const blocks: ParsedSkillBlock[] = []; + for (const match of text.matchAll(SKILL_BLOCK_RE)) { + blocks.push({ + name: match[1], + location: match[2], + content: match[3], + }); + } + return blocks; +}