Skip to content

The agent that grows with you

refactor(skills_hub): compact enrich_owners, zip walk, skills.sh extractors, install guards

Teknium5c1b26f01f5b
diff --git a/tools/skills_hub_clawhub.py b/tools/skills_hub_clawhub.py
index 28fbbf6af3e..3f63ac38db7 100644
--- a/tools/skills_hub_clawhub.py
+++ b/tools/skills_hub_clawhub.py
@@ -473,12 +473,8 @@ class ClawHubSource(GuardedFetchMixin, SkillSource):
if not needs_enrichment:
return 0
- enriched = 0
- consecutive_failures = 0
+ enriched = consecutive_failures = processed = 0
max_consecutive_failures = 50
- processed = 0
- import threading
- lock = threading.Lock()
from concurrent.futures import ThreadPoolExecutor, as_completed
with ThreadPoolExecutor(max_workers=max_workers) as pool:
@@ -490,15 +486,14 @@ class ClawHubSource(GuardedFetchMixin, SkillSource):
handle = future.result()
except Exception:
handle = None
- with lock:
- if handle:
- if not meta.extra:
- meta.extra = {}
- meta.extra["owner"] = handle
- enriched += 1
- consecutive_failures = 0
- else:
- consecutive_failures += 1
+ if handle:
+ if not meta.extra:
+ meta.extra = {}
+ meta.extra["owner"] = handle
+ enriched += 1
+ consecutive_failures = 0
+ else:
+ consecutive_failures += 1
if processed % 1000 == 0:
logger.info(
@@ -506,18 +501,17 @@ class ClawHubSource(GuardedFetchMixin, SkillSource):
processed, len(needs_enrichment), enriched,
)
- with lock:
- if consecutive_failures >= max_consecutive_failures:
- logger.warning(
- "ClawHub owner enrichment: %d consecutive failures — "
- "aborting early (%d/%d processed, %d enriched). "
- "The ClawHub API may be down or rate-limited.",
- max_consecutive_failures, processed,
- len(needs_enrichment), enriched,
- )
- for f in futures:
- f.cancel()
- break
+ if consecutive_failures >= max_consecutive_failures:
+ logger.warning(
+ "ClawHub owner enrichment: %d consecutive failures — "
+ "aborting early (%d/%d processed, %d enriched). "
+ "The ClawHub API may be down or rate-limited.",
+ max_consecutive_failures, processed,
+ len(needs_enrichment), enriched,
+ )
+ for f in futures:
+ f.cancel()
+ break
return enriched
@@ -595,8 +589,6 @@ class ClawHubSource(GuardedFetchMixin, SkillSource):
files[name] = zf.read(info.filename).decode("utf-8")
except (UnicodeDecodeError, KeyError):
logger.debug("Skipping non-text file in ZIP: %s", name)
- continue
-
return files
except zipfile.BadZipFile:
diff --git a/tools/skills_hub_install.py b/tools/skills_hub_install.py
index de878170e06..351788a6f76 100644
--- a/tools/skills_hub_install.py
+++ b/tools/skills_hub_install.py
@@ -177,33 +177,28 @@ def install_from_quarantine(
if install_dir.exists():
shutil.rmtree(install_dir)
- skill_md = quarantine_path / "SKILL.md"
- if skill_md.exists():
- try:
- skill_size = skill_md.stat().st_size
- if skill_size > 100_000:
- logger.warning(
- "Skill '%s' has a large SKILL.md (%s chars). "
- "Large skills consume significant context when loaded. "
- "Consider asking the author to split it into smaller files.",
- safe_skill_name,
- f"{skill_size:,}",
- )
- except OSError:
- pass
+ try:
+ skill_size = (quarantine_path / "SKILL.md").stat().st_size
+ except OSError:
+ skill_size = 0
+ if skill_size > 100_000:
+ logger.warning(
+ "Skill '%s' has a large SKILL.md (%s chars). "
+ "Large skills consume significant context when loaded. "
+ "Consider asking the author to split it into smaller files.",
+ safe_skill_name,
+ f"{skill_size:,}",
+ )
# A symlink in the bundle would copy its target into skills/ and leak it
# to the agent on the next skill_view.
for entry in quarantine_path.rglob("*"):
- if not _is_path_redirect(entry):
- continue
- try:
- rel = entry.relative_to(quarantine_resolved)
- except ValueError:
- rel = entry
- raise ValueError(
- f"Installed skill contains symlinks, which is not allowed: {rel}"
- )
+ if _is_path_redirect(entry):
+ try:
+ rel = entry.relative_to(quarantine_resolved)
+ except ValueError:
+ rel = entry
+ raise ValueError(f"Installed skill contains symlinks, which is not allowed: {rel}")
install_dir.parent.mkdir(parents=True, exist_ok=True)
shutil.move(str(quarantine_path), str(install_dir))
@@ -230,14 +225,9 @@ def install_from_quarantine(
try:
from tools.skill_usage import record_installed
-
record_installed(safe_skill_name)
except Exception:
- logger.debug(
- "Unable to record skill install lifecycle for %s",
- safe_skill_name,
- exc_info=True,
- )
+ logger.debug("Unable to record skill install lifecycle for %s", safe_skill_name, exc_info=True)
return install_dir
@@ -325,9 +315,7 @@ def check_for_skill_updates(
row = {"name": entry.get("name", ""), "identifier": identifier, "source": source_name}
bundle = None
- for src in sources:
- if not _source_matches(src, source_name):
- continue
+ for src in filter(lambda s: _source_matches(s, source_name), sources):
try:
bundle = src.fetch(identifier)
except Exception:
diff --git a/tools/skills_hub_skillssh.py b/tools/skills_hub_skillssh.py
index 3c34060b601..436fc892ef9 100644
--- a/tools/skills_hub_skillssh.py
+++ b/tools/skills_hub_skillssh.py
@@ -370,42 +370,26 @@ class SkillsShSource(SkillSource):
base = plain.split("/")[-1]
sanitized = re.sub(r'[^a-z0-9/_-]+', '-', plain).strip('-')
- sanitized_base = sanitized.split("/")[-1] if sanitized else ""
- slash_tail_clean = base.lstrip('@').split('/')[-1]
-
+ tail = base.lstrip('@')
variants = {
- plain,
- plain.replace("_", "-"),
- plain.replace("/", "-"),
- base,
- base.replace("_", "-"),
- sanitized,
- sanitized.replace("/", "-") if sanitized else "",
- sanitized_base,
- slash_tail_clean,
- slash_tail_clean.replace("_", "-"),
+ plain, plain.replace("_", "-"), plain.replace("/", "-"),
+ base, base.replace("_", "-"),
+ sanitized, sanitized.replace("/", "-"), sanitized.split("/")[-1],
+ tail, tail.replace("_", "-"),
}
return {v for v in variants if v}
@staticmethod
def _extract_repo_slug(repo_value: str) -> Optional[str]:
- repo_value = repo_value.strip()
- if repo_value.startswith("https://github.com/"):
- repo_value = repo_value[len("https://github.com/"):]
+ repo_value = repo_value.strip().removeprefix("https://github.com/")
parts = repo_value.strip("/").split("/")
- if len(parts) >= 2:
- return f"{parts[0]}/{parts[1]}"
- return None
+ return f"{parts[0]}/{parts[1]}" if len(parts) >= 2 else None
@staticmethod
def _extract_first_match(pattern: re.Pattern, text: str) -> Optional[str]:
match = pattern.search(text)
- if not match:
- return None
- value = next((group for group in match.groups() if group), None)
- if value is None:
- return None
- return _strip_html(value).strip() or None
+ value = next((group for group in match.groups() if group), None) if match else None
+ return (_strip_html(value).strip() or None) if value is not None else None
def _detail_to_metadata(self, canonical: str, detail: Optional[dict]) -> Dict[str, Any]:
parts = canonical.split("/", 2)
@@ -438,10 +422,8 @@ class SkillsShSource(SkillSource):
@classmethod
def _normalize_identifier(cls, identifier: str) -> str:
- for prefix in cls._ID_PREFIX_ALIASES:
- if identifier.startswith(prefix):
- return identifier[len(prefix):]
- return identifier
+ prefix = next((p for p in cls._ID_PREFIX_ALIASES if identifier.startswith(p)), "")
+ return identifier[len(prefix):]
@classmethod
def _candidate_identifiers(cls, identifier: str) -> List[str]: