Skip to content

The agent that grows with you

fix: curated catalog fields a published doc does not carry come from the checkout

alt-glitch8f5ff1cd2913
diff --git a/hermes_cli/plugin_catalog.py b/hermes_cli/plugin_catalog.py
index e9a89cb8baa..5ffe653b7fd 100644
--- a/hermes_cli/plugin_catalog.py
+++ b/hermes_cli/plugin_catalog.py
@@ -14,6 +14,7 @@ in-tree copy silently.
from __future__ import annotations
+import dataclasses
import json
import logging
import re
@@ -406,12 +407,11 @@ def _live_generated_time(data: Dict[str, Any]) -> Optional[float]:
def _prefer_in_tree_entry(tree: PluginCatalogEntry, live: PluginCatalogEntry, tree_is_newer: Optional[bool]) -> bool:
- """For one entry present in both sources that differs (a new pin, or new metadata such as ``title`` or
- ``onboarding`` at the same pin): the newer catalog wins. Newer is
+ """For one entry present in both sources with a different pin: the newer catalog wins. Newer is
decided by the checkout's catalog commit time vs the doc's ``generated_at`` when both resolve;
otherwise by the entries' ``version`` labels when both parse; otherwise the live doc wins (a release
install's in-tree copy is frozen at release time)."""
- if tree == live:
+ if tree.sha == live.sha:
return False
if tree_is_newer is not None:
return tree_is_newer
@@ -425,8 +425,8 @@ def _prefer_in_tree_entry(tree: PluginCatalogEntry, live: PluginCatalogEntry, tr
def load_catalog_live() -> List[PluginCatalogEntry]:
- """Entries from the live (or cached) catalog, else the in-tree catalog. When both name an entry and
- disagree the NEWER source supplies it — right after ``hermes update`` bumps an in-tree pin,
+ """Entries from the live (or cached) catalog, else the in-tree catalog. When both name an entry at
+ different pins the NEWER source supplies it — right after ``hermes update`` bumps an in-tree pin,
a cache fetched before the bump must not re-install the old one (see :func:`_prefer_in_tree_entry`)."""
data = fetch_live_catalog()
if data is None:
@@ -438,10 +438,26 @@ def load_catalog_live() -> List[PluginCatalogEntry]:
in_tree = {e.name: e for e in load_catalog()}
live_t, tree_t = _live_generated_time(data), in_tree_catalog_time()
tree_is_newer = (tree_t > live_t) if (live_t is not None and tree_t is not None) else None
- return [in_tree[e.name] if e.name in in_tree and _prefer_in_tree_entry(in_tree[e.name], e, tree_is_newer) else e
+ raw_by_name = {str(raw.get("name")): raw for raw in data["entries"] if isinstance(raw, dict)}
+ return [in_tree[e.name] if e.name in in_tree and _prefer_in_tree_entry(in_tree[e.name], e, tree_is_newer)
+ else _with_curated_fields(e, in_tree.get(e.name), raw_by_name.get(e.name) or {})
for e in entries]
+# Curated display fields a published doc older than the field does not carry. ``generated_at`` is the
+# docs build time, not the content time, so a rebuild of an older catalog outranks a checkout that added
+# the field; a doc that has the key (even ``false``) decides.
+_CURATED_FIELDS = ("onboarding", "title")
+
+
+def _with_curated_fields(live: PluginCatalogEntry, tree: Optional[PluginCatalogEntry], raw: Dict[str, Any]
+ ) -> PluginCatalogEntry:
+ if tree is None or tree.sha != live.sha:
+ return live
+ missing = {key: getattr(tree, key) for key in _CURATED_FIELDS if key not in raw}
+ return dataclasses.replace(live, **missing) if missing else live
+
+
def live_removed_list() -> List[RemovedEntry]:
data = fetch_live_catalog()
return _removed_from_list(data.get("removed")) if data else []
diff --git a/tests/hermes_cli/test_plugin_catalog.py b/tests/hermes_cli/test_plugin_catalog.py
index df806958b80..f8bab07e2b6 100644
--- a/tests/hermes_cli/test_plugin_catalog.py
+++ b/tests/hermes_cli/test_plugin_catalog.py
@@ -167,3 +167,18 @@ def test_live_cache_write_never_truncates_the_previous_copy(tmp_path, monkeypatc
pc.fetch_live_catalog(force=True) # the failed write is swallowed like any other fetch failure
assert cache.read_text() == previous
assert not list(cache.parent.glob("*.tmp*")) # no leftover temp file either
+
+
+def test_curated_fields_the_published_doc_lacks_come_from_the_checkout(tmp_path, monkeypatch):
+ """The docs build stamps generated_at at build time, so a doc rebuilt from an older catalog is "newer"
+ than a checkout that just added `onboarding`. At the same pin, a curated field the doc does not carry
+ comes from the checkout; a doc that carries it (even false) decides, and a different pin never merges."""
+ live = [_entry("same"), {**_entry("says-no"), "onboarding": False}, _entry("repinned", sha="b" * 40)]
+ _fresh_cache(tmp_path, monkeypatch, {"generated_at": "2026-09-22T10:00:00Z", "entries": live, "removed": []})
+ tree = [pc.entry_from_mapping({**_entry(n), "onboarding": True, "title": "T"}, n) for n in ("same", "says-no", "repinned")]
+ monkeypatch.setattr(pc, "load_catalog", lambda catalog_dir=None: tree)
+ monkeypatch.setattr(pc, "in_tree_catalog_time", lambda: 0.0) # checkout older than the doc
+ by_name = {e.name: e for e in pc.load_catalog_live()}
+ assert (by_name["same"].onboarding, by_name["same"].title) == (True, "T")
+ assert by_name["says-no"].onboarding is False and by_name["says-no"].title == "T"
+ assert by_name["repinned"].onboarding is False and by_name["repinned"].sha == "b" * 40