Skip to content

The agent that grows with you

fix(tools): resolve skills.sh skills whose SKILL.md sits at the repo root

KeyArgof8d479b69ba9
diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py
index 1a7393f040e..ebb85794a8c 100644
--- a/tests/tools/test_skills_hub.py
+++ b/tests/tools/test_skills_hub.py
@@ -388,6 +388,92 @@ class TestFindSkillInRepoTree:
assert result is None
+class TestRepoRootSkillLayout:
+ """Regression for #115028: skills.sh repos whose SKILL.md sits at the repo ROOT (no skill
+ directory, e.g. orzcls/win-disk-cleaner) are listed by search but could not be resolved by
+ inspect/install — the discovery root scan skipped non-directory entries by construction and
+ no identifier form expressed "the skill directory IS the repo root"."""
+
+ IDENTIFIER = "skills-sh/orzcls/win-disk-cleaner/win-disk-cleaner"
+ REPO = "orzcls/win-disk-cleaner"
+ SKILL_MD = (
+ "---\nname: win-disk-cleaner\ndescription: Clean a Windows disk safely.\n---\n\n"
+ "# Win Disk Cleaner\n\nSee references/free_tools.md\n"
+ )
+ ROOT_TREE = [
+ {"path": "LICENSE", "type": "blob"},
+ {"path": "README.md", "type": "blob"},
+ {"path": "SKILL.md", "type": "blob"},
+ {"path": "references/free_tools.md", "type": "blob"},
+ ]
+
+ def _source(self):
+ auth = MagicMock(spec=GitHubAuth)
+ auth.get_headers.return_value = {"Accept": "application/vnd.github.v3+json"}
+ return SkillsShSource(auth=auth)
+
+ def _github_stub(self, tree):
+ """Minimal GitHub API: repo info, one git tree, and root-level file contents only —
+ every candidate ``<repo>/<base>/<skill>/SKILL.md`` path 404s, as in the real repo."""
+ def _side_effect(url, **kwargs):
+ resp = MagicMock()
+ resp.status_code = 404
+ if url.rstrip("/").endswith(self.REPO):
+ resp.status_code, resp.json = 200, (lambda: {"default_branch": "main"})
+ elif "/git/trees/main" in url:
+ resp.status_code = 200
+ resp.json = lambda: {"sha": "b" * 40, "truncated": False, "tree": tree}
+ elif url.endswith("/contents/SKILL.md"):
+ resp.status_code, resp.content = 200, self.SKILL_MD.encode()
+ elif url.endswith("/contents/references/free_tools.md"):
+ resp.status_code, resp.content = 200, b"# Free tools\n"
+ elif url.endswith("/contents/LICENSE") or url.endswith("/contents/README.md"):
+ # Every blob in the pinned tree must fetch, or the bundle is "incomplete" and
+ # deliberately left unpinned (empty revision) for the next update check to fill.
+ resp.status_code, resp.content = 200, b"root-level file\n"
+ return resp
+ return _side_effect
+
+ @patch("tools.skills_hub._write_index_cache")
+ @patch("tools.skills_hub._read_index_cache", return_value=None)
+ @patch("tools.skills_hub.httpx.get")
+ def test_inspect_resolves_skill_md_at_repo_root(self, mock_get, _mock_read_cache, _mock_write_cache):
+ mock_get.side_effect = self._github_stub(self.ROOT_TREE)
+
+ meta = self._source().inspect(self.IDENTIFIER)
+
+ assert meta is not None
+ assert meta.name == "win-disk-cleaner"
+ assert meta.repo == self.REPO
+ assert meta.identifier == self.IDENTIFIER
+
+ @patch("tools.skills_hub._write_index_cache")
+ @patch("tools.skills_hub._read_index_cache", return_value=None)
+ @patch("tools.skills_hub.httpx.get")
+ def test_fetch_resolves_and_names_bundle_for_repo_root_skill(self, mock_get, _mock_read_cache, _mock_write_cache):
+ mock_get.side_effect = self._github_stub(self.ROOT_TREE)
+
+ bundle = self._source().fetch(self.IDENTIFIER)
+
+ assert bundle is not None
+ # Repo-root skill has no directory to name itself after; fall back to the repo name.
+ assert bundle.name == "win-disk-cleaner"
+ assert bundle.files["SKILL.md"] == self.SKILL_MD
+ # Support files sit directly under the repo root, so the root is the skill directory.
+ assert bundle.files["references/free_tools.md"] == b"# Free tools\n"
+ assert bundle.identifier == self.IDENTIFIER
+ assert bundle.metadata["source_url"] == f"https://github.com/{self.REPO}/tree/{'b' * 40}"
+
+ @patch("tools.skills_hub._write_index_cache")
+ @patch("tools.skills_hub._read_index_cache", return_value=None)
+ @patch("tools.skills_hub.httpx.get")
+ def test_root_layout_does_not_resolve_as_a_multi_skill_repo(self, mock_get, _mock_read_cache, _mock_write_cache):
+ """A repo with a root SKILL.md AND another skill dir is not a root-layout single skill."""
+ mock_get.side_effect = self._github_stub(self.ROOT_TREE + [{"path": "skills/other/SKILL.md", "type": "blob"}])
+
+ assert self._source().inspect(self.IDENTIFIER) is None
+
+
class TestWellKnownSkillSource:
@pytest.fixture(autouse=True)
def _allow_public_skill_fetches(self, monkeypatch):
diff --git a/tools/skills_hub_github.py b/tools/skills_hub_github.py
index f2dc945a1b9..67e8b780316 100644
--- a/tools/skills_hub_github.py
+++ b/tools/skills_hub_github.py
@@ -161,6 +161,13 @@ def _split_repo_id(identifier: str) -> Optional[Tuple[str, str]]:
return (f"{parts[0]}/{parts[1]}", parts[2]) if len(parts) >= 3 else None
+def _skill_file_path(skill_path: str, filename: str = "SKILL.md") -> str:
+ """Path of ``filename`` inside a skill directory. An empty ``skill_path`` means the skill
+ directory IS the repo root — the single-skill layout some skills.sh repos use (``SKILL.md``
+ and its ``references/``/``scripts/`` next to ``README.md``)."""
+ return f"{skill_path}/{filename}" if skill_path else filename
+
+
def _skip_bundle_file(rel_path: str) -> bool:
"""Dotfiles, bytecode and __pycache__ never ship in a bundle."""
base = rel_path.rsplit("/", 1)[-1]
@@ -265,7 +272,7 @@ class GitHubSource(SkillSource):
# than the tree the paths were validated against (TOCTOU). Idempotent + cached.
tree = self._get_repo_tree(repo)
pinned_ref = self._tree_revisions.get(repo)
- skill_md = self._fetch_file_content(repo, f"{skill_dir}/SKILL.md", ref=pinned_ref)
+ skill_md = self._fetch_file_content(repo, _skill_file_path(skill_dir), ref=pinned_ref)
if skill_md is None:
return None
referenced = _referenced_support_paths(skill_md)
@@ -281,11 +288,12 @@ class GitHubSource(SkillSource):
revision = (pinned_ref or tree[0]) if complete else ""
else:
for rel_path in referenced:
- self._add_support_file(repo, f"{skill_dir}/{rel_path}", rel_path, files, rel_path)
+ self._add_support_file(repo, _skill_file_path(skill_dir, rel_path), rel_path, files, rel_path)
revision = ""
- url = f"https://github.com/{repo}/" + (f"tree/{revision}/{skill_path}" if revision else skill_path)
+ url = (f"https://github.com/{repo}/tree/{revision}" + (f"/{skill_path}" if skill_path else "")
+ if revision else f"https://github.com/{repo}/{skill_path}")
return SkillBundle(
- name=skill_dir.split("/")[-1], files=files, source="github", identifier=identifier,
+ name=skill_dir.split("/")[-1] or repo.split("/")[-1], files=files, source="github", identifier=identifier,
trust_level=self.trust_level_for(identifier), metadata={"source_url": url, "source_revision": revision},
)
@@ -318,8 +326,9 @@ class GitHubSource(SkillSource):
Returns None (bundle rejected) on an unsafe path or a SKILL.md-linked path that exists in the
tree as a symlink/non-blob — that shape is an escape attempt. A linked path that is simply absent
is a dangling link (repo-only dev tool, prose over-match): warn and install without it. Returns
- False when a blob fetch failed (installed with a gap the next update check must be able to fill)."""
- prefix = f"{skill_path}/"
+ False when a blob fetch failed (installed with a gap the next update check must be able to fill).
+ An empty ``skill_path`` is the repo-root skill layout, so the whole repo root is its directory."""
+ prefix = f"{skill_path}/" if skill_path else ""
symlinked: set = set()
complete = True
for rel_path, item_path, regular in _tree_members(entries, prefix):
@@ -354,14 +363,15 @@ class GitHubSource(SkillSource):
if (split := _split_repo_id(identifier)) is None:
return None
repo, skill_path = split[0], split[1].rstrip("/")
- content = self._fetch_file_content(repo, f"{skill_path}/SKILL.md")
+ content = self._fetch_file_content(repo, _skill_file_path(skill_path))
if not content:
return None
fm = _parse_frontmatter(content)
tags = _hermes_tags(fm) or (fm["tags"] if isinstance(fm.get("tags"), list) else [])
provider = github_provider_for(repo)
return SkillMeta(
- name=fm.get("name", skill_path.split("/")[-1]), description=str(fm.get("description", "")),
+ name=fm.get("name", skill_path.split("/")[-1] or repo.split("/")[-1]),
+ description=str(fm.get("description", "")),
source="github", identifier=identifier, trust_level=self.trust_level_for(identifier),
repo=repo, path=skill_path, tags=[str(t) for t in tags],
extra={"provider": provider} if provider else {},
@@ -494,6 +504,21 @@ class GitHubSource(SkillSource):
return f"{repo}/{path[: -len('/SKILL.md')]}"
return 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
+ directory) — e.g. ``orzcls/win-disk-cleaner``. The empty path segment (``owner/repo/``)
+ denotes the skill directory being the repo root. Only repos with EXACTLY ONE SKILL.md in
+ the whole tree qualify, so a categorized multi-skill repo never resolves here."""
+ tree = self._get_repo_tree(repo)
+ if tree is None:
+ return None
+ skill_mds = [
+ entry.get("path", "") for entry in tree[1]
+ if entry.get("type") == "blob" and entry.get("mode") != "120000"
+ and (entry.get("path", "") == "SKILL.md" or entry.get("path", "").endswith("/SKILL.md"))
+ ]
+ return f"{repo}/" if skill_mds == ["SKILL.md"] else None
+
def _fetch_file_content(self, repo: str, path: str, ref: Optional[str] = None) -> Optional[str]:
"""Fetch a single text file from GitHub (None on miss or non-UTF-8)."""
content = self._fetch_file_bytes(repo, path, ref=ref)
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py
index 7a3fe96f3f5..a630f06ff53 100644
--- a/tools/skills_hub_skillssh.py
+++ b/tools/skills_hub_skillssh.py
@@ -259,7 +259,8 @@ class SkillsShSource(SkillSource):
# One recursive tree lookup before brute-forcing every top-level dir
# (avoids request bursts on categorized repos like borghei/claude-skills).
found = (next((f for f in map(_match_in, self._STANDARD_BASE_PATHS) if f), None)
- or self.github._find_skill_in_repo_tree(repo, skill_token))
+ or self.github._find_skill_in_repo_tree(repo, skill_token)
+ or self.github._find_repo_root_skill(repo))
if found:
return found