mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-27 13:40:37 +00:00
* fix(skills): align skill-creator validation with the runtime schema quick_validate.py rejected skills the runtime accepts and accepted skills the runtime drops: - Read SKILL.md with utf-8-sig so a BOM-prefixed file (Windows editors) is not reported as missing frontmatter. - Allow the DeerFlow frontmatter fields (argument-hint, required-secrets, secrets-autonomous, version, author) that the runtime schema accepts. - Reject empty name/description, which the loader drops. - Validate required-secrets/secrets-autonomous shapes like the runtime validator, so a malformed declaration fails before packaging. Tests cover each case in backend/tests/test_skill_creator_quick_validate.py. * fix(skills): close the remaining skill-creator parity gaps - Read SKILL.md with utf-8-sig in utils.parse_skill_md too, so a BOM file that quick_validate now accepts does not fail in run_eval/run_loop/ improve_description. - Stringify YAML keys before the unexpected-key check, so mixed non-string keys report cleanly instead of raising TypeError in sorted(). - Accept trailing whitespace on the frontmatter delimiters, matching the runtime parser. Each case has a regression test that fails on the previous commit. * fix(skills): validate allowed-tools and stop over-rejecting compatibility The reviewer found two remaining parity gaps: - allowed-tools was not validated, while the runtime parser rejects non-string list items, empty tool names, unmatched closing parentheses and unclosed quotes. Mirror those shape rules. - compatibility was rejected for non-string or >500-char values, but the runtime validator never inspects it. Drop the check so this script does not reject skills the runtime accepts. Each case has a regression test that fails on the previous commit. * fix(skills): reject unclosed parenthesized allowed-tools patterns The runtime parser raises when the scan ends with depth > 0; the quick_validate loop only checked for an unmatched closing parenthesis. Add the depth check and move the unclosed-pattern case to the rejected tests.
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""Shared utilities for skill-creator scripts."""
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
def parse_skill_md(skill_path: Path) -> tuple[str, str, str]:
|
|
"""Parse a SKILL.md file, returning (name, description, full_content)."""
|
|
# utf-8-sig strips the BOM that Windows editors prepend, matching the
|
|
# runtime parser and quick_validate.py.
|
|
content = (skill_path / "SKILL.md").read_text(encoding="utf-8-sig")
|
|
lines = content.split("\n")
|
|
|
|
if lines[0].strip() != "---":
|
|
raise ValueError("SKILL.md missing frontmatter (no opening ---)")
|
|
|
|
end_idx = None
|
|
for i, line in enumerate(lines[1:], start=1):
|
|
if line.strip() == "---":
|
|
end_idx = i
|
|
break
|
|
|
|
if end_idx is None:
|
|
raise ValueError("SKILL.md missing frontmatter (no closing ---)")
|
|
|
|
name = ""
|
|
description = ""
|
|
frontmatter_lines = lines[1:end_idx]
|
|
i = 0
|
|
while i < len(frontmatter_lines):
|
|
line = frontmatter_lines[i]
|
|
if line.startswith("name:"):
|
|
name = line[len("name:"):].strip().strip('"').strip("'")
|
|
elif line.startswith("description:"):
|
|
value = line[len("description:"):].strip()
|
|
# Handle YAML multiline indicators (>, |, >-, |-)
|
|
if value in (">", "|", ">-", "|-"):
|
|
continuation_lines: list[str] = []
|
|
i += 1
|
|
while i < len(frontmatter_lines) and (frontmatter_lines[i].startswith(" ") or frontmatter_lines[i].startswith("\t")):
|
|
continuation_lines.append(frontmatter_lines[i].strip())
|
|
i += 1
|
|
description = " ".join(continuation_lines)
|
|
continue
|
|
else:
|
|
description = value.strip('"').strip("'")
|
|
i += 1
|
|
|
|
return name, description, content
|