31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""skill_refs — .claude/skills 참조 무결성 공유 헬퍼 (P3). doctor·lint_refs 소비."""
|
|
import glob
|
|
import os
|
|
|
|
import yaml
|
|
|
|
|
|
def known_skill_names(root):
|
|
""".claude/skills/**/SKILL.md 스캔 → 알려진 skill 이름 집합(frontmatter name + 디렉터리명)."""
|
|
names = set()
|
|
base = os.path.join(root, ".claude", "skills")
|
|
for p in glob.glob(os.path.join(base, "**", "SKILL.md"), recursive=True):
|
|
names.add(os.path.basename(os.path.dirname(p)))
|
|
try:
|
|
fm = yaml.safe_load(open(p).read().split("---\n")[1]) or {}
|
|
if isinstance(fm, dict) and fm.get("name"):
|
|
names.add(str(fm["name"]))
|
|
except Exception: # noqa: BLE001 — 깨진 frontmatter는 디렉터리명으로만 등록
|
|
pass
|
|
return names
|
|
|
|
|
|
def parse_skills(val):
|
|
"""agent frontmatter의 skills: 값 → 이름 리스트. list/문자열('[a, b]') 모두 허용."""
|
|
if not val:
|
|
return []
|
|
if isinstance(val, list):
|
|
return [str(x).strip() for x in val if str(x).strip()]
|
|
return [s.strip() for s in str(val).strip("[]").split(",") if s.strip()]
|