fix(mcp): corpus_status sorts Published dates chronologically (#14)
Co-authored-by: claude <[email protected]>
This commit was merged in pull request #14.
This commit is contained in:
+17
-2
@@ -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, {})
|
||||
|
||||
Reference in New Issue
Block a user