Parse a SKILL.md file, returning (name, description, full_content).
(skill_path: Path)
| 5 | |
| 6 | |
| 7 | def parse_skill_md(skill_path: Path) -> tuple[str, str, str]: |
| 8 | """Parse a SKILL.md file, returning (name, description, full_content).""" |
| 9 | content = (skill_path / "SKILL.md").read_text() |
| 10 | lines = content.split("\n") |
| 11 | |
| 12 | if lines[0].strip() != "---": |
| 13 | raise ValueError("SKILL.md missing frontmatter (no opening ---)") |
| 14 | |
| 15 | end_idx = None |
| 16 | for i, line in enumerate(lines[1:], start=1): |
| 17 | if line.strip() == "---": |
| 18 | end_idx = i |
| 19 | break |
| 20 | |
| 21 | if end_idx is None: |
| 22 | raise ValueError("SKILL.md missing frontmatter (no closing ---)") |
| 23 | |
| 24 | name = "" |
| 25 | description = "" |
| 26 | frontmatter_lines = lines[1:end_idx] |
| 27 | i = 0 |
| 28 | while i < len(frontmatter_lines): |
| 29 | line = frontmatter_lines[i] |
| 30 | if line.startswith("name:"): |
| 31 | name = line[len("name:"):].strip().strip('"').strip("'") |
| 32 | elif line.startswith("description:"): |
| 33 | value = line[len("description:"):].strip() |
| 34 | # Handle YAML multiline indicators (>, |, >-, |-) |
| 35 | if value in (">", "|", ">-", "|-"): |
| 36 | continuation_lines: list[str] = [] |
| 37 | i += 1 |
| 38 | while i < len(frontmatter_lines) and (frontmatter_lines[i].startswith(" ") or frontmatter_lines[i].startswith("\t")): |
| 39 | continuation_lines.append(frontmatter_lines[i].strip()) |
| 40 | i += 1 |
| 41 | description = " ".join(continuation_lines) |
| 42 | continue |
| 43 | else: |
| 44 | description = value.strip('"').strip("'") |
| 45 | i += 1 |
| 46 | |
| 47 | return name, description, content |