This commit is contained in:
Yang Haoran 2026-06-27 04:37:03 +08:00 committed by GitHub
commit 37dbffca9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()