Skip to content

The agent that grows with you

fix(skills): one install name per skills.sh skill; never swap a gone GitHub path for another skill

Teknium429f9660180e
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index ac04afba21e..f1bfa6d221d 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -369,21 +369,6 @@ class TestFindSkillInRepoTree:
result = self._source()._find_skill_in_repo_tree("davila7/claude-code-templates", "senior-backend")
assert result == "davila7/claude-code-templates/cli-tool/components/skills/development/senior-backend"
- @patch("tools.skills_hub.httpx.get")
- def test_finds_single_generic_skills_directory_when_slug_is_stale(self, mock_get):
- tree_entries = [
- {"path": "README.md", "type": "blob"},
- {"path": "skills/SKILL.md", "type": "blob"},
- ]
- mock_get.side_effect = [
- MagicMock(status_code=200, json=lambda: {"default_branch": "main"}),
- MagicMock(status_code=200, json=lambda: {"tree": tree_entries}),
- ]
-
- result = self._source()._find_skill_in_repo_tree("tencent/wechatreading", "weread-skills")
-
- assert result == "tencent/wechatreading/skills"
-
@patch("tools.skills_hub.httpx.get")
def test_returns_none_when_repo_api_fails(self, mock_get):
mock_get.return_value = MagicMock(status_code=404)
@@ -999,32 +984,6 @@ class TestHermesIndexSearch:
assert "NVIDIA/skills/skills/accelerated-computing-cudf" in ids
assert "clawhub/unrelated" not in ids
- def test_fetch_resolves_generic_skill_directory_from_index_slug(self, monkeypatch):
- """Index rows with a slug path still fetch skills stored under ``skills/``."""
- src = _make_index_source([{
- "name": "weread-skills",
- "description": "WeChat Reading skills",
- "source": "skills.sh",
- "identifier": "skills-sh/tencent/wechatreading/weread-skills",
- "repo": "tencent/wechatreading",
- "path": "weread-skills",
- }])
- github = MagicMock()
- github._find_skill_in_repo_tree.return_value = "tencent/wechatreading/skills"
- github._find_repo_root_skill.return_value = None
- github.fetch.side_effect = [None, SkillBundle(
- name="skills", files={"SKILL.md": "---\nname: weread-skills\n---\n"},
- source="github", identifier="tencent/wechatreading/skills", trust_level="community",
- )]
- monkeypatch.setattr(src, "_get_github", lambda: github)
-
- bundle = src.fetch("skills-sh/tencent/wechatreading/weread-skills")
-
- assert bundle is not None
- assert bundle.identifier == "skills-sh/tencent/wechatreading/weread-skills"
- assert bundle.name == "weread-skills" # installs under the slug, not as "skills/"
- github._find_skill_in_repo_tree.assert_called_once_with("tencent/wechatreading", "weread-skills")
-
class TestProviderFilter:
def test_filter_results_by_provider_narrows_exactly(self):
from tools.skills_hub_github import _filter_results_by_provider
diff --git a/tests/tools/test_skills_hub_generic_dir.py b/tests/tools/test_skills_hub_generic_dir.py
new file mode 100644
index 00000000000..26a1f3fd1c7
--- /dev/null
+++ b/tests/tools/test_skills_hub_generic_dir.py
@@ -0,0 +1,68 @@
+"""Skills hub: a skills.sh skill kept in a generic dir (``skills/SKILL.md``) resolves and installs under its slug."""
+
+from unittest.mock import MagicMock, patch
+
+from tools.skills_hub_github import GitHubAuth, GitHubSource
+from tools.skills_hub_models import SkillBundle
+from tools.skills_hub_official import HermesIndexSource
+from tools.skills_hub_skillssh import SkillsShSource
+
+ROW = {"name": "weread-skills", "description": "WeChat Reading skills", "source": "skills.sh",
+ "identifier": "skills-sh/tencent/wechatreading/weread-skills",
+ "repo": "tencent/wechatreading", "path": "weread-skills"}
+
+
+def _generic_bundle(*_):
+ return SkillBundle(name="skills", files={"SKILL.md": "---\nname: weread-skills\n---\n"},
+ source="github", identifier="tencent/wechatreading/skills", trust_level="community")
+
+
+def _index_source(row, github, monkeypatch):
+ src = HermesIndexSource(auth=GitHubAuth())
+ src._index, src._loaded = {"skills": [row]}, True
+ monkeypatch.setattr(src, "_get_github", lambda: github)
+ return src
+
+
+@patch("tools.skills_hub.httpx.get")
+def test_finds_single_generic_skills_directory_when_slug_is_stale(mock_get):
+ """A lone ``skills/SKILL.md`` answers for a stale slug; a lone NAMED skill (``skills/bar``) never does."""
+ auth = MagicMock(spec=GitHubAuth)
+ auth.get_headers.return_value = {"Accept": "application/vnd.github.v3+json"}
+ for lone, expected in (("skills/SKILL.md", "tencent/wechatreading/skills"), ("skills/bar/SKILL.md", None)):
+ tree_entries = [{"path": "README.md", "type": "blob"}, {"path": lone, "type": "blob"}]
+ mock_get.side_effect = [
+ MagicMock(status_code=200, json=lambda: {"default_branch": "main"}),
+ MagicMock(status_code=200, json=lambda t=tree_entries: {"tree": t}),
+ ]
+
+ assert GitHubSource(auth=auth)._find_skill_in_repo_tree("tencent/wechatreading", "weread-skills") == expected
+
+
+def test_fetch_resolves_generic_skill_directory_from_index_slug(monkeypatch):
+ """A skills.sh skill under a generic ``skills/`` dir installs as its slug, whether the index fell
+ back to the tree, resolved it, or skills.sh fetched it directly; a gone GitHub path stays gone."""
+ github = MagicMock()
+ github._find_skill_in_repo_tree.return_value = "tencent/wechatreading/skills"
+ github._find_repo_root_skill.return_value = None
+ for extra, fetched in (({}, [None, _generic_bundle()]),
+ ({"resolved_github_id": "tencent/wechatreading/skills"}, [_generic_bundle()])):
+ github.fetch.side_effect = fetched
+
+ bundle = _index_source({**ROW, **extra}, github, monkeypatch).fetch(ROW["identifier"])
+
+ assert (bundle.name, bundle.identifier) == ("weread-skills", ROW["identifier"]) # one lock name
+ github._find_skill_in_repo_tree.assert_called_once_with("tencent/wechatreading", "weread-skills")
+
+ skills_sh = SkillsShSource(auth=MagicMock(spec=GitHubAuth))
+ monkeypatch.setattr(skills_sh, "_fetch_detail_page", lambda _id: None)
+ monkeypatch.setattr(skills_sh, "_candidate_identifiers", lambda _id: [])
+ monkeypatch.setattr(skills_sh, "_discover_identifier", lambda *_a, **_k: "tencent/wechatreading/skills")
+ monkeypatch.setattr(skills_sh.github, "fetch", _generic_bundle)
+ assert skills_sh.fetch(ROW["identifier"]).name == "weread-skills"
+
+ github.reset_mock()
+ github.fetch.side_effect = [None]
+ gone = {**ROW, "source": "github", "identifier": "tencent/wechatreading/gone", "path": "gone"}
+ assert _index_source(gone, github, monkeypatch).fetch(gone["identifier"]) is None # no other skill relabeled
+ github._find_skill_in_repo_tree.assert_not_called()
diff --git a/tools/skills_hub_github.py b/tools/skills_hub_github.py
index b828f5bc047..b5078749e33 100644
--- a/tools/skills_hub_github.py
+++ b/tools/skills_hub_github.py
@@ -533,10 +533,9 @@ class GitHubSource(SkillSource):
if path.endswith(skill_md_suffix) or path == skill_md_suffix[1:]:
return f"{repo}/{path[: -len('/SKILL.md')]}"
skill_dirs.append(path[: -len("SKILL.md")].rstrip("/"))
- # A single-skill repo may keep it in a generically named dir (``skills/SKILL.md``) that no
- # slug matches; with only one SKILL.md in the tree there is nothing else it could mean
- # (a lone root SKILL.md is left to ``_find_repo_root_skill``).
- return f"{repo}/{skill_dirs[0]}" if len(skill_dirs) == 1 and skill_dirs[0] else None
+ # A single-skill repo may keep it in a generic dir (``skills/SKILL.md``) no slug matches; a lone
+ # NAMED dir (``skills/bar``) is another skill, and a lone root SKILL.md is ``_find_repo_root_skill``'s.
+ return f"{repo}/{skill_dirs[0]}" if skill_dirs in (["skills"], [".agents/skills"], [".claude/skills"]) else None
def _find_repo_root_skill(self, repo: str) -> Optional[str]:
"""Identifier for a single-skill repo whose ``SKILL.md`` sits at the repo ROOT (no skill
diff --git a/tools/skills_hub_official.py b/tools/skills_hub_official.py
index dac544f2f05..1a35fbaacc3 100644
--- a/tools/skills_hub_official.py
+++ b/tools/skills_hub_official.py
@@ -356,7 +356,8 @@ class HermesIndexSource(SkillSource):
if not entry:
return None
repo, path = entry.get("repo", ""), entry.get("path", "")
- github = self._get_github()
+ github, slug = self._get_github(), path.rstrip("/").rsplit("/", 1)[-1]
+ skills_sh = entry.get("source") in {"skills.sh", "skills-sh"}
candidates = [entry.get("resolved_github_id")] + ([f"{repo}/{path}"] if repo and path else [])
for github_id in filter(None, candidates):
if bundle := github.fetch(github_id):
@@ -364,12 +365,14 @@ class HermesIndexSource(SkillSource):
else:
# skills.sh rows carry the slug as ``path``; when no build resolved it, find the skill in
# the repo tree (a slug-named dir, a lone generic ``skills/``, or the repo root) instead
- # of reporting a live skill as a stale entry (#130129).
- slug = path.rstrip("/").rsplit("/", 1)[-1]
- found = repo and slug and (github._find_skill_in_repo_tree(repo, slug) or github._find_repo_root_skill(repo))
+ # of reporting a live skill as a stale entry (#130129). A concrete GitHub path that is
+ # gone stays gone: never substitute whatever skill remains in that repo.
+ found = skills_sh and repo and slug and (
+ github._find_skill_in_repo_tree(repo, slug) or github._find_repo_root_skill(repo))
if not (found and (bundle := github.fetch(found))):
return None
- bundle.name = slug # not "skills" / the repo name: the slug the user asked for
+ if skills_sh and bundle.name == "skills": # same name resolved or not, never a shared "skills/"
+ bundle.name = slug
bundle.source = entry.get("source", "hermes-index")
bundle.identifier = identifier
return bundle
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py
index a630f06ff53..220a8164355 100644
--- a/tools/skills_hub_skillssh.py
+++ b/tools/skills_hub_skillssh.py
@@ -101,6 +101,8 @@ class SkillsShSource(SkillSource):
bundle = self.github.fetch(github_id) if github_id else None
if bundle:
bundle.source, bundle.identifier = "skills.sh", self._wrap_identifier(canonical)
+ if bundle.name == "skills": # a generic dir: install under the slug, as the index does
+ bundle.name = canonical.rstrip("/").rsplit("/", 1)[-1]
bundle.metadata.update(self._detail_to_metadata(canonical, detail))
return bundle or None