Merge pull request #334 from Gui-Yue/fix-skill-frontmatter-yaml

Fix skill frontmatter parsing
This commit is contained in:
gui-yue
2026-05-31 17:20:05 +08:00
committed by GitHub
3 changed files with 14 additions and 14 deletions

View File

@@ -23,11 +23,12 @@ Changes from s06:
Loop unchanged: load_skill auto-dispatches via TOOL_HANDLERS.
Run: python s07_skill_loading/code.py
Needs: pip install anthropic python-dotenv + ANTHROPIC_API_KEY in .env
Needs: pip install anthropic python-dotenv pyyaml + ANTHROPIC_API_KEY in .env
"""
import os, subprocess
from pathlib import Path
import yaml
try:
import readline
@@ -56,11 +57,10 @@ def _parse_frontmatter(text: str) -> tuple[dict, str]:
parts = text.split("---", 2)
if len(parts) < 3:
return {}, text
try:
meta = yaml.safe_load(parts[1]) or {}
except yaml.YAMLError:
meta = {}
for line in parts[1].strip().splitlines():
if ":" in line:
k, v = line.split(":", 1)
meta[k.strip()] = v.strip().strip('"').strip("'")
return meta, parts[2].strip()
# Build skill registry at startup (used for safe lookup in load_skill)

View File

@@ -3,7 +3,7 @@
s20: Comprehensive Agent — all teaching components in one loop.
Run: python s20_comprehensive/code.py
Need: pip install anthropic python-dotenv + .env with ANTHROPIC_API_KEY
Need: pip install anthropic python-dotenv pyyaml + .env with ANTHROPIC_API_KEY
This final chapter intentionally puts the earlier teaching mechanisms back
together: dispatch, permission, hooks, todo, subagent, skills, compaction,
@@ -15,6 +15,7 @@ import os, subprocess, json, time, random, threading, re
from pathlib import Path
from datetime import datetime
from dataclasses import dataclass, asdict, field
import yaml
try:
import readline
@@ -292,11 +293,10 @@ def _parse_frontmatter(text: str) -> tuple[dict, str]:
parts = text.split("---", 2)
if len(parts) < 3:
return {}, text
try:
meta = yaml.safe_load(parts[1]) or {}
except yaml.YAMLError:
meta = {}
for line in parts[1].strip().splitlines():
if ":" in line:
key, value = line.split(":", 1)
meta[key.strip()] = value.strip().strip('"').strip("'")
return meta, parts[2].strip()

File diff suppressed because one or more lines are too long