fix(mcp): corpus_status sorts Published dates chronologically

corpus_status compared HPE "Published" values ("July 2026") as plain
strings, so "March 2026" outranked "July 2026" for the most-recent date
and the most-recently-edited ordering. Parse to (year, month) for both.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SXZ3ZdHEP75P9YmyFM7W3k
This commit is contained in:
2026-09-23 09:35:29 -04:00
co-authored by Claude Opus 5.5
parent 8e2b678464
commit 683956f60d
+17 -2
View File
@@ -810,6 +810,21 @@ def weekly_digest(
return "\n".join(lines)
def _pub_sort_key(pub: str) -> tuple[int, int]:
"""Sortable (year, month) for an HPE "Published" value like "July 2026".
Plain string comparison ranks "March 2026" above "July 2026".
Unparseable values sort last.
"""
for fmt in ("%B %Y", "%b %Y", "%B %d, %Y", "%Y-%m-%d"):
try:
d = _dt.datetime.strptime(pub.strip(), fmt)
return (d.year, d.month)
except ValueError:
continue
return (0, 0)
@mcp.tool()
def corpus_status() -> str:
"""Freshness + size of the knowledge base.
@@ -831,7 +846,7 @@ def corpus_status() -> str:
for slug, b in cat.items():
pub = (b.get("dates") or {}).get("Published")
if pub:
if latest_pub is None or pub > latest_pub:
if latest_pub is None or _pub_sort_key(pub) > _pub_sort_key(latest_pub):
latest_pub = pub
per_bundle.append((slug, pub))
if latest_pub:
@@ -850,7 +865,7 @@ def corpus_status() -> str:
"",
]
if per_bundle:
per_bundle.sort(key=lambda kv: kv[1], reverse=True)
per_bundle.sort(key=lambda kv: _pub_sort_key(kv[1]), reverse=True)
lines.append("## Most-recently-edited bundles (by HPE)")
for slug, when in per_bundle[:5]:
b = cat.get(slug, {})