The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): clip index descriptions at any whitespace, not only spaces
Tekniumb66ab2bb7b47
diff --git a/agent/skill_utils.py b/agent/skill_utils.pyindex c12ed03c174..f24faec3d4e 100644--- a/agent/skill_utils.py+++ b/agent/skill_utils.py@@ -840,6 +840,8 @@ def resolve_skill_config_values(config_vars: list[dict[str, Any]]) -> dict[str,# description over it and tests/skills/test_authoring_standards.py holds shipped skills to it, so only legacy or# hand-edited skills ever reach clip_skill_description().SKILL_PROMPT_DESC_LIMIT = 60+_LAST_WHITESPACE_RE = re.compile(r"\s\S*$")+_CLIP_TRAIL_RE = re.compile(r"[\s.,;:\-\u2013\u2014(/]+$")def _normalize_skill_description(frontmatter: dict[str, Any]) -> str:@@ -852,11 +854,11 @@ def clip_skill_description(desc: str) -> str:"""*desc* fitted to SKILL_PROMPT_DESC_LIMIT, cut at a word boundary so the index never shows a half word."""if len(desc) <= SKILL_PROMPT_DESC_LIMIT:return desc- head = desc[:SKILL_PROMPT_DESC_LIMIT - 2] # one char past the budget: a space there means the last word is whole- cut = head.rfind(" ")- if cut <= 0: # a single word longer than the budget has no boundary to cut at+ head = desc[:SKILL_PROMPT_DESC_LIMIT - 2] # one char past the budget: whitespace there means the last word is whole+ boundary = _LAST_WHITESPACE_RE.search(head) # any whitespace (tab, NBSP, ...) separates words, not just " "+ if not boundary or boundary.start() == 0: # a single word longer than the budget has no boundary to cut atreturn desc[:SKILL_PROMPT_DESC_LIMIT - 3] + "..."- return head[:cut].rstrip(" .,;:-\u2013\u2014(/") + "..."+ return _CLIP_TRAIL_RE.sub("", head[:boundary.start()]) + "..."def extract_skill_description(frontmatter: dict[str, Any]) -> str:diff --git a/tests/agent/test_skills_index_format.py b/tests/agent/test_skills_index_format.pyindex 9e35e8d5014..3d0748ec579 100644--- a/tests/agent/test_skills_index_format.py+++ b/tests/agent/test_skills_index_format.py@@ -4,7 +4,7 @@ import reimport pytestfrom agent.prompt_builder import build_skills_system_prompt, clear_skills_system_prompt_cache-from agent.skill_utils import SKILL_PROMPT_DESC_LIMIT+from agent.skill_utils import SKILL_PROMPT_DESC_LIMIT, clip_skill_descriptionfrom agent.skills_index_delta import index_entriesLONG = "Use when cutting, publishing, or abandoning a hermes-agent release and its notes."@@ -47,3 +47,11 @@ def test_index_rows_carry_each_name_once_and_never_a_half_word(monkeypatch, tmp_assert LONG.startswith(kept) and LONG[len(kept)] in " ," # cut lands between words# The turn-delta parser reads flattened rows like nested ones.assert set(index_entries(prompt)) == {"ascii-art", "pixel-art", "computer-use", "hermes-release"}++[email protected]("sep", ["\t", "\u00a0"], ids=["tab", "nbsp"])+def test_clip_cuts_at_any_whitespace_never_inside_a_word(sep):+ desc = f"alpha{sep}" + f"bravo{sep}" * 12+ shown = clip_skill_description(desc)+ assert len(shown) <= SKILL_PROMPT_DESC_LIMIT and shown.endswith("...")+ assert set(shown[:-3].split(sep)) == {"alpha", "bravo"} # whole words only, no "bra..."