The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(skills): skip wrong-provider taps and give the provider-filter idiom one owner
kshitijk4poor69d181011bfe
diff --git a/hermes_cli/skills_hub.py b/hermes_cli/skills_hub.pyindex 6cb135aa785..4f67f4882d9 100644--- a/hermes_cli/skills_hub.py+++ b/hermes_cli/skills_hub.py@@ -424,8 +424,8 @@ def do_browse(page: int = 1, page_size: int = 20, source: str = "all",return# Provider filter (nvidia/openai/...) narrows GitHub-tap skills by their per-tap# ``extra.provider`` label (the runtime index stores them all under source="github").- from tools.skills_hub_github import _PROVIDER_FILTER_VALUES, _filter_results_by_provider- if source.strip().lower() in _PROVIDER_FILTER_VALUES:+ from tools.skills_hub_github import _filter_results_by_provider, _provider_filter_of+ if _provider_filter_of(source):all_results = _filter_results_by_provider(all_results, source)if not all_results:c.print(f"[dim]No skills found for provider '{source}'.[/]\n")@@ -437,6 +437,7 @@ def do_browse(page: int = 1, page_size: int = 20, source: str = "all",def browse_skills(page: int = 1, page_size: int = 20, source: str = "all") -> dict:"""Paginated hub browse for programmatic callers (e.g. TUI gateway)."""+ from tools.skills_hub_github import _filter_results_by_provider, _provider_filter_offrom tools.skills_hub_search import parallel_search_sourcespage_size = max(1, min(page_size, 100))# The shared parallel walker carries the index-aware source-skip logic — querying@@ -444,6 +445,10 @@ def browse_skills(page: int = 1, page_size: int = 20, source: str = "all") -> diall_results, _counts, _timed_out = parallel_search_sources(_sources(), query="", per_source_limits=_BROWSE_API_LIMITS,source_filter=source, overall_timeout=30)+ # Same provider rule as do_browse: sources that cannot filter per-tap (official,+ # url, ...) are only cut on the merged set.+ if _provider_filter_of(source):+ all_results = _filter_results_by_provider(all_results, source)if not all_results:return {"items": [], "page": 1, "total_pages": 1, "total": 0}deduped, page_items, page, total_pages, _start = _rank_and_page(all_results, page, page_size)diff --git a/tests/hermes_cli/test_skills_provider_filter.py b/tests/hermes_cli/test_skills_provider_filter.pyindex 251dc0dc3e3..0dfd2533ba9 100644--- a/tests/hermes_cli/test_skills_provider_filter.py+++ b/tests/hermes_cli/test_skills_provider_filter.py@@ -7,11 +7,10 @@ import pytestfrom hermes_cli import skills_hub as cli_hubfrom hermes_cli.subcommands.skills import build_skills_parser-from tools.skills_hub import _index_cache_dir-from tools.skills_hub_github import GitHubAuth, GitHubSource+from tools.skills_hub_github import GitHubAuth, GitHubSource, _tap_cache_keyfrom tools.skills_hub_models import SkillMeta, _cache_metasfrom tools.skills_hub_official import HermesIndexSource-from tools.skills_hub_search import parallel_search_sources+from tools.skills_hub_search import _hermes_index_cache_file, parallel_search_sources@pytest.fixture(params=["index", "github"])@@ -29,15 +28,14 @@ def catalog(request, monkeypatch):wanted = [entry("NVIDIA/skills", "NVIDIA", f"gpu-target-{i}") for i in range(3)]auth = GitHubAuth()if request.param == "index":- path = _index_cache_dir() / "hermes-index.json"+ path = _hermes_index_cache_file()path.parent.mkdir(parents=True, exist_ok=True)path.write_text(json.dumps({"skills": [vars(m) for m in others + wanted]}), encoding="utf-8")source = HermesIndexSource(auth)else:source = GitHubSource(auth)for tap in source.taps:- key = f"{tap['repo']}_{tap['path']}_{tap.get('bucket') or ''}"- key = key.replace("/", "_").replace(" ", "_")+ key = _tap_cache_key(tap["repo"], tap.get("path", ""), tap.get("bucket"))entries = []if tap["repo"] == "openai/skills":entries = othersdiff --git a/tools/skills_hub_github.py b/tools/skills_hub_github.pyindex d7649976f50..54999a57ac1 100644--- a/tools/skills_hub_github.py+++ b/tools/skills_hub_github.py@@ -52,6 +52,17 @@ def _filter_results_by_provider(results: List[SkillMeta], provider: str) -> Listreturn [r for r in results if str((r.extra or {}).get("provider", "")).lower() == want]+def _provider_filter_of(source_filter: str) -> str:+ """Normalized provider filter when ``--source`` names one (nvidia/openai/...), else ``""``."""+ value = source_filter.strip().lower()+ return value if value in _PROVIDER_FILTER_VALUES else ""+++def _tap_cache_key(repo: str, path: str, bucket: Optional[str] = None) -> str:+ """Disk-cache key for one tap's skill listing (tests seed that cache through it too)."""+ return f"{repo}_{path}_{bucket or ''}".replace("/", "_").replace(" ", "_")++def _is_rate_limit_response(resp: httpx.Response) -> bool:"""403 with exhausted quota, or any 429."""return resp.status_code == 429 or (@@ -225,18 +236,22 @@ class GitHubSource(SkillSource):return "trusted" if len(parts) >= 2 and f"{parts[0]}/{parts[1]}" in TRUSTED_REPOS else "community"def search(self, query: str, limit: int = 10, *, provider_filter: str = "") -> List[SkillMeta]:- """Substring-match taps, filter by provider, then dedupe and limit results."""+ """Substring-match taps, skip taps outside a provider filter, then dedupe by identifier+ preferring higher trust and limit."""results: List[SkillMeta] = []query_lower = query.lower()+ want = provider_filter.strip().lower()for tap in self.taps:+ # The tap repo fixes every result's provider, so wrong-provider taps can be+ # skipped before their enumeration cost (cache reads or GitHub API calls).+ if want and (github_provider_for(tap["repo"]) or "").lower() != want:+ continuetry:for skill in self._list_skills_in_repo(tap["repo"], tap.get("path", ""), tap.get("bucket")):if _matches_query(query_lower, skill.name, skill.description, skill.tags):results.append(skill)except Exception as e:logger.debug("Failed to search %s: %s", tap['repo'], e)- if provider_filter:- results = _filter_results_by_provider(results, provider_filter)return _dedupe_by_trust(results)[:limit]def fetch(self, identifier: str) -> Optional[SkillBundle]:@@ -342,7 +357,7 @@ class GitHubSource(SkillSource):"""List skill directories in a GitHub repo path, using cached index. ``bucket`` labels everyskill from a tap whose repo ships no ``skills.sh.json`` grouping, so several repos can share onehub category (e.g. "science"); a sidecar grouping still wins when present."""- cache_key = f"{repo}_{path}_{bucket or ''}".replace("/", "_").replace(" ", "_")+ cache_key = _tap_cache_key(repo, path, bucket)cached = _cached_metas(cache_key)if cached is not None:return cacheddiff --git a/tools/skills_hub_official.py b/tools/skills_hub_official.pyindex 3f5d7044cf7..752e900032c 100644--- a/tools/skills_hub_official.py+++ b/tools/skills_hub_official.py@@ -26,6 +26,11 @@ def _clean_rel_parts(path: str) -> Optional[List[str]]:return None if not parts or ".." in parts else parts+def _entry_provider(entry: dict) -> str:+ """Normalized ``extra.provider`` label of a raw index entry."""+ return str((entry.get("extra") or {}).get("provider", "")).lower()++class OptionalSkillSource(SkillSource):"""Skills from the repo's ``optional-skills/`` directory: official (Nous-maintained) but notactivated by default — absent from the system prompt and not copied to ~/.hermes/skills/ at@@ -320,10 +325,7 @@ class HermesIndexSource(SkillSource):skills = self._skills()if provider_filter:want = provider_filter.strip().lower()- skills = [- s for s in skills- if str((s.get("extra") or {}).get("provider", "")).lower() == want- ]+ skills = [s for s in skills if _entry_provider(s) == want]if not skills:return []if not query.strip():@@ -332,7 +334,7 @@ class HermesIndexSource(SkillSource):scored: List[Tuple[int, int, dict]] = []for i, s in enumerate(skills):name = str(s.get("name", "")).lower()- provider = str((s.get("extra") or {}).get("provider", "")).lower()+ provider = _entry_provider(s)haystack = " ".join([name, str(s.get("description", "")).lower(), " ".join(str(t).lower() for t in s.get("tags", [])),str(s.get("identifier", "")).lower(), provider,diff --git a/tools/skills_hub_search.py b/tools/skills_hub_search.pyindex 2a0c8de7c3e..8e879fb274c 100644--- a/tools/skills_hub_search.py+++ b/tools/skills_hub_search.py@@ -14,7 +14,7 @@ import jsonfrom pathlib import Pathfrom typing import Any, Dict, List, Optional, Tuplefrom tools.skills_hub_clawhub import ClawHubSource-from tools.skills_hub_github import GitHubAuth, GitHubSource, _PROVIDER_FILTER_VALUES, _filter_results_by_provider+from tools.skills_hub_github import GitHubAuth, GitHubSource, _filter_results_by_provider, _provider_filter_offrom tools.skills_hub_models import SkillMeta, SkillSource, TRUST_RANK, _dedupe_by_trustfrom tools.skills_hub_official import HermesIndexSource, OptionalSkillSourcefrom tools.skills_hub_skillssh import SkillsShSource@@ -126,7 +126,7 @@ def _select_active_sources(sources: List[SkillSource], source_filter: str) -> Liare filtered again. "official" is always queried alongside an explicitsource filter."""- effective = "all" if source_filter.strip().lower() in _PROVIDER_FILTER_VALUES else source_filter+ effective = "all" if _provider_filter_of(source_filter) else source_filterindex_available = effective == "all" and any(src.source_id() == "hermes-index" and getattr(src, "is_available", False) for src in sources)@@ -154,9 +154,7 @@ def parallel_search_sources(per_source_limits = per_source_limits or {}active = _select_active_sources(sources, source_filter)- provider_filter = source_filter.strip().lower()- if provider_filter not in _PROVIDER_FILTER_VALUES:- provider_filter = ""+ provider_filter = _provider_filter_of(source_filter)all_results: List[SkillMeta] = []source_counts: Dict[str, int] = {}timed_out_ids: List[str] = []@@ -198,7 +196,7 @@ def unified_search(query: str, sources: List[SkillSource],"""Search all sources (in parallel) and merge results."""all_results, _, _ = parallel_search_sources(sources, query=query, source_filter=source_filter, overall_timeout=30)# Provider filters target ``extra.provider`` on the merged set, not a source id.- if source_filter.strip().lower() in _PROVIDER_FILTER_VALUES:+ if _provider_filter_of(source_filter):all_results = _filter_results_by_provider(all_results, source_filter)deduped = _dedupe_by_trust(all_results)# Stable-sort by trust before truncating so the limit cut never drops a