@@ -19,6 +19,7 @@ class SkillMetadata:
1919 name : str
2020 description : str
2121 location : Path
22+ body : str
2223 metadata : dict [str , Any ] | None = None
2324 source : str = "unknown"
2425
@@ -49,19 +50,6 @@ def discover_skills(workspace_path: Path) -> list[SkillMetadata]:
4950 return sorted (by_name .values (), key = lambda item : item .name .casefold ())
5051
5152
52- def load_skill_body (name : str , workspace_path : Path ) -> str | None :
53- """Load full SKILL.md body for one skill name."""
54-
55- lowered = name .casefold ()
56- for skill in discover_skills (workspace_path ):
57- if skill .name .casefold () == lowered :
58- try :
59- return skill .location .read_text (encoding = "utf-8" )
60- except OSError :
61- return None
62- return None
63-
64-
6553def _read_skill (skill_dir : Path , * , source : str ) -> SkillMetadata | None :
6654 skill_file = skill_dir / SKILL_FILE_NAME
6755 if not skill_file .is_file ():
@@ -72,33 +60,36 @@ def _read_skill(skill_dir: Path, *, source: str) -> SkillMetadata | None:
7260 except OSError :
7361 return None
7462
75- metadata = _parse_frontmatter (content )
63+ metadata , body = _parse_frontmatter (content )
7664 name = str (metadata .get ("name" ) or skill_dir .name ).strip ()
7765 description = str (metadata .get ("description" ) or "No description provided." ).strip ()
7866 meta = cast (dict [str , Any ], metadata .get ("metadata" ))
7967
8068 if not name :
8169 return None
8270
83- return SkillMetadata (name = name , description = description , location = skill_file .resolve (), source = source , metadata = meta )
71+ return SkillMetadata (
72+ name = name , description = description , location = skill_file .resolve (), source = source , metadata = meta , body = body
73+ )
8474
8575
86- def _parse_frontmatter (content : str ) -> dict [str , object ]:
76+ def _parse_frontmatter (content : str ) -> tuple [ dict [str , object ], str ]:
8777 lines = content .splitlines ()
8878 if not lines or lines [0 ].strip () != "---" :
89- return {}
79+ return {}, content
9080
9181 for idx , line in enumerate (lines [1 :], start = 1 ):
9282 if line .strip () == "---" :
9383 payload = "\n " .join (lines [1 :idx ])
9484 try :
9585 parsed = yaml .safe_load (payload )
9686 except yaml .YAMLError :
97- return {}
87+ parsed = {}
88+ body = "\n " .join (lines [idx + 1 :])
9889 if isinstance (parsed , dict ):
99- return {str (key ).lower (): value for key , value in parsed .items ()}
100- return {}
101- return {}
90+ return {str (key ).lower (): value for key , value in parsed .items ()}, body
91+ return {}, body
92+ return {}, content
10293
10394
10495def _builtin_skills_root () -> Path :
0 commit comments