feat: add skill draft workflow

This commit is contained in:
2026-07-27 14:03:19 +08:00
parent 8b82539f6f
commit 86cd1fa36d
14 changed files with 535 additions and 100 deletions
+65
View File
@@ -102,3 +102,68 @@ def validate_skill_name(name: str) -> None:
)
if name == "_template":
raise SystemExit("不能使用保留名 _template")
_PLACEHOLDER_PATTERNS = (
(r"^name:\s*skill-name\s*$", "skill-name"),
(r"^#\s+Skill 名称\s*$", "Skill 名称"),
(r"简要描述 skill 做什么、何时触发", "简要描述 skill 做什么"),
(r"^-\s*触发场景 1\s*$", "触发场景 1"),
(r"^\d+\.\s*第一步\s*$", "第一步"),
)
def validate_skill_dir(skill_dir: Path, expected_name: str) -> list[str]:
"""返回 skill 目录中的校验问题;空列表表示通过。"""
issues: list[str] = []
skill_md = skill_dir / "SKILL.md"
if not skill_md.is_file():
return ["缺少 SKILL.md"]
text = skill_md.read_text(encoding="utf-8")
if not text.strip():
return ["SKILL.md 为空"]
if not text.startswith("---\n"):
return ["SKILL.md 缺少 YAML frontmatter"]
end = text.find("\n---", 4)
if end == -1:
return ["SKILL.md frontmatter 未闭合"]
frontmatter = text[4:end]
keys = re.findall(r"^([A-Za-z0-9_-]+):", frontmatter, re.MULTILINE)
unexpected = sorted(set(keys) - {"name", "description"})
missing = sorted({"name", "description"} - set(keys))
if missing:
issues.append(f"frontmatter 缺少字段: {', '.join(missing)}")
if unexpected:
issues.append(f"frontmatter 只允许 name、description,发现: {', '.join(unexpected)}")
meta = read_skill_meta(skill_dir)
if meta.get("name") != expected_name:
issues.append(
f"目录名与 frontmatter name 不一致: {expected_name} != {meta.get('name', '(缺失)')}"
)
description = meta.get("description", "").strip()
if not description:
issues.append("description 不能为空")
found_placeholders = [
label
for pattern, label in _PLACEHOLDER_PATTERNS
if re.search(pattern, text, re.MULTILINE | re.IGNORECASE)
]
if found_placeholders:
issues.append(f"存在模板占位内容: {', '.join(found_placeholders)}")
link_pattern = re.compile(r"!?\[[^\]]*\]\(([^)]+)\)")
for target in link_pattern.findall(text):
target = target.strip().split("#", 1)[0]
if not target or "://" in target or target.startswith(("mailto:", "/")):
continue
if not (skill_dir / target).resolve().is_file():
issues.append(f"引用文件不存在: {target}")
for draft_file in ("brief.yaml",):
if (skill_dir / draft_file).exists():
issues.append(f"正式 skill 不应包含草稿文件: {draft_file}")
return issues