The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): enforce the description limit on every write to the root SKILL.md
Tekniumdf92e3308194
diff --git a/tests/tools/test_skill_manager_tool.py b/tests/tools/test_skill_manager_tool.pyindex 8b074d8ebf3..aead1638780 100644--- a/tests/tools/test_skill_manager_tool.py+++ b/tests/tools/test_skill_manager_tool.py@@ -284,6 +284,21 @@ class TestCreateSkill:fm, _ = parse_frontmatter(LONG_DESC_CONTENT)assert extract_skill_description(fm) in body["system_prompt_preview"]+ def test_explicit_skill_md_paths_cannot_write_a_long_desc(self, tmp_path):+ """patch(file_path='SKILL.md') and write_file('SKILL.md') reach the same root file as a plain+ patch/edit, so the description written through them must fit the index width too."""+ long_desc = "Use when deploying multi-region clusters with custom CNI plugins."+ with _skill_dir(tmp_path):+ _create_skill("my-skill", VALID_SKILL_CONTENT)+ patched = _patch_skill("my-skill", "A test skill for unit testing.", long_desc, file_path="SKILL.md")+ written = _write_file("my-skill", "SKILL.md", VALID_SKILL_CONTENT.replace(+ "A test skill for unit testing.", long_desc))+ body = _write_file("my-skill", "SKILL.md", VALID_SKILL_CONTENT + "\nMore.\n")+ assert patched["success"] is False and "60" in patched["error"]+ assert written["success"] is False and "60" in written["error"]+ assert body["success"] is True+ assert long_desc not in (tmp_path / "my-skill" / "SKILL.md").read_text()+class TestEditSkill:def test_edit_existing_skill(self, tmp_path):diff --git a/tools/skill_manager_tool.py b/tools/skill_manager_tool.pyindex 61eea9b6c18..d73835dbde5 100644--- a/tools/skill_manager_tool.py+++ b/tools/skill_manager_tool.py@@ -406,13 +406,16 @@ def _locate_for_write(name: str, action: str, not_found_suffix: str = ""):def _guarded_write(name: str, skill_dir: Path, target: Path, action: str, label: str,content: str) -> Optional[dict[str, Any]]:- """Read-before-write guard (existing targets only), atomic write, then the security scan;- a blocked scan restores the original (or unlinks a new file). Error dict or None."""+ """Read-before-write guard (existing targets only), the description budget for the root SKILL.md+ (whichever action and file_path reach it), atomic write, then the security scan; a blocked scan+ restores the original (or unlinks a new file). Error dict or None."""original = Noneif target.exists():if read_guard := _background_review_read_before_write_guard(name, target, action, label):return read_guardoriginal = target.read_text(encoding="utf-8-sig")+ if target == skill_dir / "SKILL.md" and (err := _description_budget_error(content, before=original)):+ return _err(err)from hermes_constants import mkdir_under_hermes_homemkdir_under_hermes_home(target.parent)atomic_write_text(target, content, preserve_mode=True, create_mode=0o644)@@ -464,8 +467,7 @@ def _clip(text: str, n: int, ellipsis: str) -> str:def _create_skill(name: str, content: str, category: str | None = None) -> dict[str, Any]:if err := (_validate_name(name) or _validate_category(category)- or _validate_frontmatter(content) or _description_budget_error(content)- or _validate_content_size(content)):+ or _validate_frontmatter(content) or _validate_content_size(content)):return _err(err)if existing := _find_skill(name):return _err(f"A skill named '{name}' already exists at {existing['path']}.")@@ -509,9 +511,6 @@ def _edit_skill(name: str, content: str) -> dict[str, Any]:if err := _validate_frontmatter(content) or _validate_content_size(content):return _err(err)skill_dir, guard = _locate_for_write(name, "edit")- if not guard and (err := _description_budget_error(- content, before=(skill_dir / "SKILL.md").read_text(encoding="utf-8-sig"))):- return _err(err)# SKILL.md always exists here (_find_skill requires it), so a blocked scan restores it.if guard := guard or _guarded_write(name, skill_dir, skill_dir / "SKILL.md", "edit", "SKILL.md", content):return guard@@ -560,8 +559,6 @@ def _patch_skill(name: str, old_string: str, new_string: str, file_path: str | Nreturn _err(err)if not file_path and (err := _validate_frontmatter(new_content)):return _err(f"Patch would break SKILL.md structure: {err}")- if not file_path and (err := _description_budget_error(new_content, before=content)):- return _err(err)if guard := _guarded_write(name, skill_dir, target, "patch", target_label, new_content):return guardresult = {