{"version":3,"file":"agent-session-skills.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-skills.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CASrE;AAED,kEAAkE;AAClE,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,IAAI,GAAG,MAAM,CAmBrH","sourcesContent":["/**\n * Skill-block parsing and inline skill-command expansion for AgentSession.\n *\n * `parseSkillBlock` recognizes the `<skill …>` envelope embedded in user\n * messages; `expandSkillCommand` turns a `/skill:name args` invocation into that\n * envelope by reading the skill file. Both are pure aside from the file read,\n * which reports failures through the supplied error callback.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { stripFrontmatter } from \"../utils/frontmatter.js\";\nimport type { Skill } from \"./skills.js\";\n\n/** Parsed skill block from a user message */\nexport interface ParsedSkillBlock {\n\tname: string;\n\tlocation: string;\n\tcontent: string;\n\tuserMessage: string | undefined;\n}\n\n/**\n * Parse a skill block from message text.\n * Returns null if the text doesn't contain a skill block.\n */\nexport function parseSkillBlock(text: string): ParsedSkillBlock | null {\n\tconst match = text.match(/^<skill name=\"([^\"]+)\" location=\"([^\"]+)\">\\n([\\s\\S]*?)\\n<\\/skill>(?:\\n\\n([\\s\\S]+))?$/);\n\tif (!match) return null;\n\treturn {\n\t\tname: match[1],\n\t\tlocation: match[2],\n\t\tcontent: match[3],\n\t\tuserMessage: match[4]?.trim() || undefined,\n\t};\n}\n\n/** Error reported while reading a skill file during expansion. */\nexport interface SkillExpansionError {\n\tfilePath: string;\n\terror: string;\n}\n\n/**\n * Expand a skill command (`/skill:name args`) to its full skill-block content.\n * Returns the expanded text, or the original text when it is not a skill command\n * or the named skill is unknown. File-read failures are surfaced via `onError`\n * and leave the original text unchanged.\n */\nexport function expandSkillCommand(text: string, skills: Skill[], onError: (err: SkillExpansionError) => void): string {\n\tif (!text.startsWith(\"/skill:\")) return text;\n\n\tconst spaceIndex = text.indexOf(\" \");\n\tconst skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);\n\tconst args = spaceIndex === -1 ? \"\" : text.slice(spaceIndex + 1).trim();\n\n\tconst skill = skills.find((s) => s.name === skillName);\n\tif (!skill) return text; // Unknown skill, pass through\n\n\ttry {\n\t\tconst content = readFileSync(skill.filePath, \"utf-8\");\n\t\tconst body = stripFrontmatter(content).trim();\n\t\tconst skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${skill.baseDir}.\\n\\n${body}\\n</skill>`;\n\t\treturn args ? `${skillBlock}\\n\\n${args}` : skillBlock;\n\t} catch (err) {\n\t\tonError({ filePath: skill.filePath, error: err instanceof Error ? err.message : String(err) });\n\t\treturn text; // Return original on error\n\t}\n}\n"]}