Phase 3: add parseSkillBlocksFromText — skill-block scan per SPEC §6.2.
Mirror agent-session parseSkillBlock regex for detecting expanded skill blocks in user messages. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,8 +1,31 @@
|
|||||||
/** Raw `/skill:name` at start of user input (SPEC §6.2 #1). */
|
/** Raw `/skill:name` at start of user input (SPEC §6.2 #1). */
|
||||||
const SLASH_SKILL_RE = /^\/skill:([a-z0-9-]+)/;
|
const SLASH_SKILL_RE = /^\/skill:([a-z0-9-]+)/;
|
||||||
|
|
||||||
|
/** mirror agent-session `parseSkillBlock` — global scan (SPEC §6.2 #2). */
|
||||||
|
const SKILL_BLOCK_RE =
|
||||||
|
/<skill name="([^"]+)" location="([^"]+)">\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. */
|
/** Returns skill name when text is a slash skill command, else null. */
|
||||||
export function detectSlashSkill(text: string): string | null {
|
export function detectSlashSkill(text: string): string | null {
|
||||||
const match = SLASH_SKILL_RE.exec(text);
|
const match = SLASH_SKILL_RE.exec(text);
|
||||||
return match?.[1] ?? null;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user