Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
fix(validate): read block-scalar descriptions so the 1024-char cap applies (#302)
Mattia Pastrello2296b08c073f
diff --git a/tests/test_validate_skill.py b/tests/test_validate_skill.pyindex 2390d36..d157c2d 100644--- a/tests/test_validate_skill.py+++ b/tests/test_validate_skill.py@@ -238,3 +238,40 @@ def test_opencode_lens_does_not_impose_description_soft_limit(tmp_path):errors, warns = validate_skill.audit(str(p), lens="opencode")assert errors == []assert not [warning for warning in warns if "description:" in warning]+++def _block_skill(indicator, body_lines):+ body = "\n".join(" " + ln for ln in body_lines)+ return f"---\nname: my-skill\ndescription: {indicator}\n{body}\nlicense: MIT\n---\n\n# Body\n"++[email protected]("indicator", ["|", ">", "|-", ">-", "|+"])+def test_block_scalar_description_over_cap_is_rejected(tmp_path, indicator):+ # The value of `description: |` is the indented block, not the indicator:+ # reading only "|" made a 1,300-char description pass as 1 char long.+ p = tmp_path / "SKILL.md"+ p.write_text(_block_skill(indicator, ["word " * 20] * 13), encoding="utf-8")+ errors, _ = validate_skill.audit(str(p))+ assert any(e.startswith("description:") and "> 1024" in e for e in errors), errors++[email protected]("indicator", ["|", ">"])+def test_block_scalar_description_under_cap_is_accepted(tmp_path, indicator):+ p = tmp_path / "SKILL.md"+ p.write_text(_block_skill(indicator, ["A short test skill", "on two lines."]), encoding="utf-8")+ errors, _ = validate_skill.audit(str(p))+ assert errors == []+++def test_block_scalar_value_is_read_from_the_indented_lines():+ fm = "name: my-skill\ndescription: >\n first line\n second line\n\n new paragraph\nlicense: MIT\n"+ assert validate_skill.get_scalar(fm, "description") == "first line second line\nnew paragraph"+ fm = "name: my-skill\ndescription: |\n first line\n second line\nlicense: MIT\n"+ assert validate_skill.get_scalar(fm, "description") == "first line\nsecond line"+++def test_empty_block_scalar_description_is_missing(tmp_path):+ p = tmp_path / "SKILL.md"+ p.write_text("---\nname: my-skill\ndescription: |\nlicense: MIT\n---\n\n# Body\n", encoding="utf-8")+ errors, _ = validate_skill.audit(str(p))+ assert "description: missing (required)" in errorsdiff --git a/tools/validate_skill.py b/tools/validate_skill.pyindex b623535..1db04dd 100644--- a/tools/validate_skill.py+++ b/tools/validate_skill.py@@ -160,9 +160,33 @@ def parse_frontmatter(text):return text[3:end].lstrip("\n"), text[end + 4:]+_BLOCK_SCALAR = re.compile(r"^([|>])[+-]?[0-9]?[+-]?$")++def get_scalar(fm, key):- m = re.search(rf"^{re.escape(key)}:\s*(.*)$", fm, re.MULTILINE)- return m.group(1).strip().strip('"').strip("'") if m else None+ m = re.search(rf"^{re.escape(key)}:[ \t]*(.*)$", fm, re.MULTILINE)+ if not m:+ return None+ value = m.group(1).strip()+ block = _BLOCK_SCALAR.match(value)+ if not block:+ return value.strip('"').strip("'")+ # Block scalar (`key: |` or `key: >`): the value is the indented lines that+ # follow, not the indicator. Reading only the indicator made every block+ # description look one character long, so the 1024-char cap never fired.+ lines = []+ for ln in fm[m.end():].splitlines()[1:]:+ if ln.strip() and not ln[:1].isspace():+ break+ lines.append(ln)+ while lines and not lines[-1].strip():+ lines.pop()+ indent = min((len(ln) - len(ln.lstrip()) for ln in lines if ln.strip()), default=0)+ lines = [ln[indent:] for ln in lines]+ if block.group(1) == "|":+ return "\n".join(lines)+ # Folded (`>`): lines join with a space, blank lines become line breaks.+ return "\n".join(" ".join(p.split("\n")) for p in "\n".join(lines).split("\n\n"))def get_list_items(fm, key):