Skip to content

The agent that grows with you

feat(plugin-catalog): screenshots and readme entry fields for the plugin pages

teknium110c273813dbd
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.py
index c9861506dd3..d4ee875ab2d 100644
--- a/hermes_cli/plugin_catalog.py
+++ b/hermes_cli/plugin_catalog.py
@@ -82,6 +82,8 @@ class PluginCatalogEntry:
docs_url: str = ""
version: str = "" # human label for the pinned sha ("1.4.0"); cosmetic, never parsed
image: str = "" # https image URL on a GitHub host; shown on catalog cards
+ screenshots: List[str] = field(default_factory=list) # GitHub-hosted https URLs; gallery on /docs/plugins/<name>
+ readme: bool = False # docs site renders the README from the pinned commit on the entry's page
platforms: List[str] = field(default_factory=list) # empty = all OSes
capabilities: CatalogCapabilities = field(default_factory=CatalogCapabilities)
@@ -97,6 +99,7 @@ class PluginCatalogEntry:
"maintainer": self.maintainer, "tier": self.tier, "category": self.category,
"requires_hermes": self.requires_hermes,
"subdir": self.subdir, "docs_url": self.docs_url, "version": self.version, "image": self.image,
+ "screenshots": list(self.screenshots), "readme": self.readme,
"platforms": list(self.platforms),
"capabilities": {
"provides_tools": list(caps.provides_tools), "provides_hooks": list(caps.provides_hooks),
@@ -147,13 +150,16 @@ def entry_from_mapping(data: Any, label: str) -> Optional[PluginCatalogEntry]:
if image and not is_allowed_image_url(image):
logger.warning("Plugin catalog: %s: ignoring image %r (must be https on a GitHub host)", label, image)
image = ""
+ screenshots = [s for s in _str_list(data.get("screenshots")) if is_allowed_image_url(s)]
+ if len(screenshots) != len(_str_list(data.get("screenshots"))):
+ logger.warning("Plugin catalog: %s: ignoring screenshots off GitHub hosts", label)
return PluginCatalogEntry(
name=name, repo=repo, sha=sha,
description=str(data.get("description") or "").strip(),
maintainer=str(data.get("maintainer") or "").strip(), tier=tier, category=category,
requires_hermes=str(data.get("requires_hermes") or "").strip(),
subdir=str(data.get("subdir") or "").strip(), docs_url=str(data.get("docs_url") or "").strip(),
- version=version, image=image,
+ version=version, image=image, screenshots=screenshots, readme=data.get("readme") is True,
platforms=_str_list(data.get("platforms")),
capabilities=CatalogCapabilities(
provides_tools=_str_list(caps.get("provides_tools")), provides_hooks=_str_list(caps.get("provides_hooks")),
diff --git a/scripts/validate_plugin_catalog.py b/scripts/validate_plugin_catalog.py
index 0ced5791b69..a4fa0233af8 100644
--- a/scripts/validate_plugin_catalog.py
+++ b/scripts/validate_plugin_catalog.py
@@ -66,15 +66,21 @@ KNOWN_KEYS = {
"docs_url",
"version",
"image",
+ "screenshots",
+ "readme",
"platforms",
"capabilities",
}
-# Cosmetic labels attached to the pin. ``version`` is never parsed; ``image`` may only point
-# at GitHub so the Desktop catalog browser never fetches from third-party hosts and a raw URL
-# pinned to the entry's commit stays as immutable as the sha.
+# Cosmetic labels attached to the pin. ``version`` is never parsed; ``image`` and ``screenshots``
+# may only point at GitHub so the Desktop catalog browser and the docs site never fetch from
+# third-party hosts and a raw URL pinned to the entry's commit stays as immutable as the sha.
VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}$")
IMAGE_HOSTS = ("raw.githubusercontent.com", "github.com")
IMAGE_HOST_SUFFIX = ".githubusercontent.com"
+MAX_SCREENSHOTS = 6
+# ``readme: true`` makes the docs site render the README from the pinned commit; the build knows
+# the raw-file URL scheme of these forges only.
+README_REPO_HOSTS = ("github.com", "gitlab.com")
REQUIRED_KEYS = ("name", "repo", "sha", "description", "maintainer")
# One comparator clause of a requires_hermes spec, e.g. ">=0.19" or "!=1.2.3".
@@ -91,6 +97,28 @@ def _is_nonempty_str(value: object) -> bool:
return isinstance(value, str) and value.strip() != ""
+def _repo_host(repo: object) -> str:
+ return (urlsplit(repo).hostname or "").lower() if isinstance(repo, str) else ""
+
+
+def _check_page_fields(data: dict, errors: list[str]) -> None:
+ """``screenshots`` and ``readme`` feed the entry's page at /docs/plugins/<name>; both optional."""
+ shots = data.get("screenshots")
+ if shots is not None:
+ if not isinstance(shots, list) or not all(isinstance(s, str) and _is_allowed_image_url(s) for s in shots):
+ errors.append(
+ f"screenshots must be a list of https URLs on {list(IMAGE_HOSTS)} or *{IMAGE_HOST_SUFFIX}"
+ )
+ elif len(shots) > MAX_SCREENSHOTS:
+ errors.append(f"screenshots lists {len(shots)} URLs; at most {MAX_SCREENSHOTS} are shown")
+ readme = data.get("readme")
+ if readme is not None:
+ if not isinstance(readme, bool):
+ errors.append(f"readme must be true or false, got {readme!r}")
+ elif readme and _repo_host(data.get("repo")) not in README_REPO_HOSTS:
+ errors.append(f"readme: true needs a repo on {list(README_REPO_HOSTS)} (the site fetches it from the pinned commit)")
+
+
def _check_requires_hermes(spec: object, errors: list[str]) -> None:
if not isinstance(spec, str):
errors.append(f"requires_hermes must be a string, got {type(spec).__name__}")
@@ -157,6 +185,8 @@ def validate_entry(data: object) -> tuple[list[str], list[str]]:
if image is not None and (not isinstance(image, str) or not _is_allowed_image_url(image)):
errors.append(f"image {image!r} must be an https URL on {list(IMAGE_HOSTS)} or *{IMAGE_HOST_SUFFIX}")
+ _check_page_fields(data, errors)
+
platforms = data.get("platforms", [])
if platforms is None:
platforms = []
diff --git a/tests/hermes_cli/test_plugin_catalog.py b/tests/hermes_cli/test_plugin_catalog.py
index 6224893ca3d..38a7bc15cdb 100644
--- a/tests/hermes_cli/test_plugin_catalog.py
+++ b/tests/hermes_cli/test_plugin_catalog.py
@@ -55,6 +55,16 @@ def test_version_and_image_are_cosmetic_and_offhost_images_are_dropped(tmp_path)
assert entries["labelled"].to_dict()["version"] == "1.4.0"
+def test_screenshots_and_readme_are_parsed_and_default_off(tmp_path):
+ shot = "https://raw.githubusercontent.com/owner/repo/38fe0fb53eff98d477f807432e965429e665ca33/docs/1.png"
+ (tmp_path / "a.yaml").write_text(yaml.safe_dump(_entry("paged", screenshots=[shot, "https://evil.example/x.png"], readme=True)))
+ (tmp_path / "b.yaml").write_text(yaml.safe_dump(_entry("plain", readme="yes")))
+ entries = {e.name: e for e in pc.load_catalog(tmp_path)}
+ assert entries["paged"].screenshots == [shot] and entries["paged"].readme is True
+ assert entries["plain"].screenshots == [] and entries["plain"].readme is False
+ assert entries["paged"].to_dict()["screenshots"] == [shot] and entries["paged"].to_dict()["readme"] is True
+
+
def test_invalid_entries_are_skipped_not_raised(tmp_path):
(tmp_path / "a.yaml").write_text(yaml.safe_dump(_entry("ok")))
(tmp_path / "b.yaml").write_text(yaml.safe_dump(_entry("short-sha", sha="abc123")))
diff --git a/tests/scripts/test_validate_plugin_catalog.py b/tests/scripts/test_validate_plugin_catalog.py
index 057a2c45f80..64510570988 100644
--- a/tests/scripts/test_validate_plugin_catalog.py
+++ b/tests/scripts/test_validate_plugin_catalog.py
@@ -106,6 +106,19 @@ def test_version_and_image_are_validated_when_present(tmp_path):
assert run_validator(str(path)).returncode == 0
+def test_screenshots_and_readme_are_validated_when_present(tmp_path):
+ """Page fields: screenshots follow the image host rule and are capped; readme is a bool and needs a
+ forge the site can fetch raw files from at the pinned commit."""
+ shot = "https://raw.githubusercontent.com/owner/repo/38fe0fb53eff98d477f807432e965429e665ca33/docs/1.png"
+ _expect_error(tmp_path, {"screenshots": [shot, "https://cdn.example.com/2.png"]}, "screenshots")
+ _expect_error(tmp_path, {"screenshots": shot}, "screenshots")
+ _expect_error(tmp_path, {"screenshots": [shot] * 7}, "at most 6")
+ _expect_error(tmp_path, {"readme": "yes"}, "readme")
+ _expect_error(tmp_path, {"readme": True, "repo": "https://codeberg.org/owner/repo"}, "readme: true needs")
+ path = write_entry(tmp_path, {**VALID_ENTRY, "screenshots": [shot, shot], "readme": True}, "ok.yaml")
+ assert run_validator(str(path)).returncode == 0
+
+
def test_bad_name_fails(tmp_path):
_expect_error(tmp_path, {"name": "Bad Name!"}, "name")
diff --git a/tests/website/test_extract_plugins.py b/tests/website/test_extract_plugins.py
index bc59e0c5215..8dd0a32a02e 100644
--- a/tests/website/test_extract_plugins.py
+++ b/tests/website/test_extract_plugins.py
@@ -144,6 +144,30 @@ def test_version_and_image_are_emitted_and_offhost_image_is_dropped_not_fatal(mo
assert entries["offhost"]["image"] == "" and entries["offhost"]["version"] == "1.4.0"
+def test_page_fields_screenshots_readme_url_and_maintainer_slug(mod, tmp_path):
+ """Detail-page inputs: screenshots follow the image host rule (off-host dropped, never fatal), readme
+ resolves to the raw README at the PINNED sha (GitHub and GitLab, subdir-aware) and is off for other
+ forges, and the maintainer slug is what /docs/plugins/by/<slug> is generated from."""
+ catalog = tmp_path / "plugin-catalog"
+ catalog.mkdir()
+ shot = "https://raw.githubusercontent.com/owner/repo/38fe0fb53eff98d477f807432e965429e665ca33/docs/1.png"
+ _write_entry(catalog, "gh", screenshots=[shot, "https://cdn.example.com/x.png"], readme=True, subdir="catalog",
+ maintainer="Nous Research")
+ _write_entry(catalog, "gl", repo="https://gitlab.com/group/proj", readme=True)
+ _write_entry(catalog, "other", repo="https://codeberg.org/o/r", readme=True)
+ _write_entry(catalog, "plain")
+
+ entries = {e["name"]: e for e in mod.load_catalog_entries(catalog)}
+ assert entries["gh"]["screenshots"] == [shot]
+ assert entries["gh"]["readme"] is True
+ assert entries["gh"]["readmeUrl"] == (
+ "https://raw.githubusercontent.com/example/gh/38fe0fb53eff98d477f807432e965429e665ca33/catalog/README.md")
+ assert entries["gh"]["maintainerSlug"] == "nous-research"
+ assert entries["gl"]["readmeUrl"] == "https://gitlab.com/group/proj/-/raw/38fe0fb53eff98d477f807432e965429e665ca33/README.md"
+ assert entries["other"]["readme"] is False and entries["other"]["readmeUrl"] == ""
+ assert entries["plain"]["readme"] is False and entries["plain"]["screenshots"] == [] and entries["plain"]["maintainerSlug"] == "example"
+
+
# --------------------------------------------------------------------------
# Full run: outputs + graceful degradation
# --------------------------------------------------------------------------
diff --git a/website/scripts/extract-plugins.py b/website/scripts/extract-plugins.py
index aa1337d7802..6d8c88dc7a1 100644
--- a/website/scripts/extract-plugins.py
+++ b/website/scripts/extract-plugins.py
@@ -51,6 +51,10 @@ SHA_RE = re.compile(r"^[0-9a-f]{40}$")
VERSION_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}$")
IMAGE_HOSTS = ("raw.githubusercontent.com", "github.com")
IMAGE_HOST_SUFFIX = ".githubusercontent.com"
+MAX_SCREENSHOTS = 6
+# Forges whose raw-file URL scheme the site knows; ``readme: true`` on any other host is ignored.
+_FORGE_REPO_RE = re.compile(r"^https://(github\.com|gitlab\.com)/([^/\s]+)/([^/\s#?]+?)(?:\.git)?/?$")
+_SLUG_RE = re.compile(r"[^a-z0-9._-]+")
def _log(msg: str) -> None:
@@ -72,6 +76,30 @@ def _cosmetic(value, accept, file_name: str, entry: str, key: str) -> str:
return text
+def maintainer_slug(maintainer: str) -> str:
+ """URL segment for the author page (/docs/plugins/by/<slug>); shared by every entry of one maintainer."""
+ return _SLUG_RE.sub("-", maintainer.strip().lower()).strip("-") or "unknown"
+
+
+def readme_url(repo: str, sha: str, subdir: str) -> str:
+ """Raw README.md URL at the pinned commit for GitHub/GitLab repos; "" when the forge is unknown."""
+ m = _FORGE_REPO_RE.match(repo)
+ if not m:
+ return ""
+ host, owner, name = m.groups()
+ path = f"{subdir.strip('/')}/README.md" if subdir.strip("/") else "README.md"
+ if host == "github.com":
+ return f"https://raw.githubusercontent.com/{owner}/{name}/{sha}/{path}"
+ return f"https://gitlab.com/{owner}/{name}/-/raw/{sha}/{path}"
+
+
+def _screenshots(raw, file_name: str, entry: str) -> list[str]:
+ shots = [s for s in _str_list(raw) if _is_allowed_image_url(s)]
+ if len(shots) != len(_str_list(raw)):
+ _log(f"{file_name} ({entry}): dropping screenshots off GitHub hosts")
+ return shots[:MAX_SCREENSHOTS]
+
+
def _str_list(value) -> list[str]:
if isinstance(value, str):
return [value] if value.strip() else []
@@ -214,6 +242,7 @@ def load_catalog_entries(catalog_dir: Path, stars: dict[str, int] | None = None,
_log(f"{path.name} ({name}): unknown category {category!r}, treating as general")
category = "general"
+ subdir = str(raw.get("subdir") or "").strip()
entries.append({
"name": name,
"description": str(raw.get("description") or "").strip(),
@@ -223,13 +252,17 @@ def load_catalog_entries(catalog_dir: Path, stars: dict[str, int] | None = None,
"tier": tier,
"category": category,
"maintainer": str(raw.get("maintainer") or "").strip(),
- "subdir": str(raw.get("subdir") or "").strip(),
+ "subdir": subdir,
"requiresHermes": str(raw.get("requires_hermes") or "").strip(),
"platforms": _str_list(raw.get("platforms")),
"capabilities": _normalize_capabilities(raw.get("capabilities")),
"docsUrl": str(raw.get("docs_url") or "").strip(),
"version": _cosmetic(raw.get("version"), VERSION_RE.match, path.name, name, "version"),
"image": _cosmetic(raw.get("image"), _is_allowed_image_url, path.name, name, "image"),
+ "screenshots": _screenshots(raw.get("screenshots"), path.name, name),
+ "readme": raw.get("readme") is True and bool(readme_url(repo, sha, subdir)),
+ "readmeUrl": readme_url(repo, sha, subdir) if raw.get("readme") is True else "",
+ "maintainerSlug": maintainer_slug(str(raw.get("maintainer") or "")),
"installCommand": f"hermes plugins install {name}",
"stars": _repo_stars(repo, stars),
"addedAt": dates.get(path.name, {}).get("addedAt"),