diff --git a/s07_skill_loading/README.en.md b/s07_skill_loading/README.en.md index 35399ddb..115462c7 100644 --- a/s07_skill_loading/README.en.md +++ b/s07_skill_loading/README.en.md @@ -70,8 +70,8 @@ def _scan_skills(): if manifest.exists(): raw = manifest.read_text() meta, body = _parse_frontmatter(raw) - name = meta.get("name", d.name) - desc = meta.get("description", raw.split("\n")[0].lstrip("#").strip()) + name = meta.get("name") or d.name + desc = meta.get("description") or body.split("\n", 1)[0].lstrip("#").strip() SKILL_REGISTRY[name] = {"name": name, "description": desc, "content": raw} _scan_skills() # runs once at startup diff --git a/s07_skill_loading/README.ja.md b/s07_skill_loading/README.ja.md index 7e12baa8..f3c1f19e 100644 --- a/s07_skill_loading/README.ja.md +++ b/s07_skill_loading/README.ja.md @@ -70,8 +70,8 @@ def _scan_skills(): if manifest.exists(): raw = manifest.read_text() meta, body = _parse_frontmatter(raw) - name = meta.get("name", d.name) - desc = meta.get("description", raw.split("\n")[0].lstrip("#").strip()) + name = meta.get("name") or d.name + desc = meta.get("description") or body.split("\n", 1)[0].lstrip("#").strip() SKILL_REGISTRY[name] = {"name": name, "description": desc, "content": raw} _scan_skills() # runs once at startup diff --git a/s07_skill_loading/README.md b/s07_skill_loading/README.md index 8b53c764..db6a72de 100644 --- a/s07_skill_loading/README.md +++ b/s07_skill_loading/README.md @@ -70,8 +70,8 @@ def _scan_skills(): if manifest.exists(): raw = manifest.read_text() meta, body = _parse_frontmatter(raw) - name = meta.get("name", d.name) - desc = meta.get("description", raw.split("\n")[0].lstrip("#").strip()) + name = meta.get("name") or d.name + desc = meta.get("description") or body.split("\n", 1)[0].lstrip("#").strip() SKILL_REGISTRY[name] = {"name": name, "description": desc, "content": raw} _scan_skills() # runs once at startup diff --git a/s07_skill_loading/code.py b/s07_skill_loading/code.py index b4506fc5..28b2af46 100644 --- a/s07_skill_loading/code.py +++ b/s07_skill_loading/code.py @@ -52,16 +52,26 @@ CURRENT_TODOS: list[dict] = [] # s07: Skill catalog scan (used by build_system below) def _parse_frontmatter(text: str) -> tuple[dict, str]: """Parse YAML frontmatter from SKILL.md. Returns (meta, body).""" - if not text.startswith("---"): + if not (text.startswith("---\n") or text.startswith("---\r\n")): return {}, text - parts = text.split("---", 2) - if len(parts) < 3: + + lines = text.splitlines(keepends=True) + closing_index = None + for index, line in enumerate(lines[1:], start=1): + if line.strip() == "---": + closing_index = index + break + if closing_index is None: return {}, text + + frontmatter = "".join(lines[1:closing_index]) + body = "".join(lines[closing_index + 1 :]).strip() try: - meta = yaml.safe_load(parts[1]) or {} + loaded = yaml.safe_load(frontmatter) or {} except yaml.YAMLError: - meta = {} - return meta, parts[2].strip() + loaded = {} + meta = loaded if isinstance(loaded, dict) else {} + return meta, body # Build skill registry at startup (used for safe lookup in load_skill) SKILL_REGISTRY: dict[str, dict] = {} @@ -77,8 +87,8 @@ def _scan_skills(): if manifest.exists(): raw = manifest.read_text() meta, body = _parse_frontmatter(raw) - name = meta.get("name", d.name) - desc = meta.get("description", raw.split("\n")[0].lstrip("#").strip()) + name = meta.get("name") or d.name + desc = meta.get("description") or body.split("\n", 1)[0].lstrip("#").strip() SKILL_REGISTRY[name] = {"name": name, "description": desc, "content": raw} _scan_skills()