mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-06-21 04:33:36 +08:00
Merge pull request #334 from Gui-Yue/fix-skill-frontmatter-yaml
Fix skill frontmatter parsing
This commit is contained in:
@@ -23,11 +23,12 @@ Changes from s06:
|
|||||||
Loop unchanged: load_skill auto-dispatches via TOOL_HANDLERS.
|
Loop unchanged: load_skill auto-dispatches via TOOL_HANDLERS.
|
||||||
|
|
||||||
Run: python s07_skill_loading/code.py
|
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
|
import os, subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import yaml
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import readline
|
import readline
|
||||||
@@ -56,11 +57,10 @@ def _parse_frontmatter(text: str) -> tuple[dict, str]:
|
|||||||
parts = text.split("---", 2)
|
parts = text.split("---", 2)
|
||||||
if len(parts) < 3:
|
if len(parts) < 3:
|
||||||
return {}, text
|
return {}, text
|
||||||
meta = {}
|
try:
|
||||||
for line in parts[1].strip().splitlines():
|
meta = yaml.safe_load(parts[1]) or {}
|
||||||
if ":" in line:
|
except yaml.YAMLError:
|
||||||
k, v = line.split(":", 1)
|
meta = {}
|
||||||
meta[k.strip()] = v.strip().strip('"').strip("'")
|
|
||||||
return meta, parts[2].strip()
|
return meta, parts[2].strip()
|
||||||
|
|
||||||
# Build skill registry at startup (used for safe lookup in load_skill)
|
# Build skill registry at startup (used for safe lookup in load_skill)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
s20: Comprehensive Agent — all teaching components in one loop.
|
s20: Comprehensive Agent — all teaching components in one loop.
|
||||||
|
|
||||||
Run: python s20_comprehensive/code.py
|
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
|
This final chapter intentionally puts the earlier teaching mechanisms back
|
||||||
together: dispatch, permission, hooks, todo, subagent, skills, compaction,
|
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 pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dataclasses import dataclass, asdict, field
|
from dataclasses import dataclass, asdict, field
|
||||||
|
import yaml
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import readline
|
import readline
|
||||||
@@ -292,11 +293,10 @@ def _parse_frontmatter(text: str) -> tuple[dict, str]:
|
|||||||
parts = text.split("---", 2)
|
parts = text.split("---", 2)
|
||||||
if len(parts) < 3:
|
if len(parts) < 3:
|
||||||
return {}, text
|
return {}, text
|
||||||
meta = {}
|
try:
|
||||||
for line in parts[1].strip().splitlines():
|
meta = yaml.safe_load(parts[1]) or {}
|
||||||
if ":" in line:
|
except yaml.YAMLError:
|
||||||
key, value = line.split(":", 1)
|
meta = {}
|
||||||
meta[key.strip()] = value.strip().strip('"').strip("'")
|
|
||||||
return meta, parts[2].strip()
|
return meta, parts[2].strip()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user