Refresh changed Hermes tool search catalogs

This commit is contained in:
Mikei386
2026-08-25 15:38:06 +02:00
parent a984ce1892
commit 137b2e915c
+35 -12
View File
@@ -14,9 +14,9 @@ modify an unknown future implementation.
from pathlib import Path
TARGET = Path("/opt/hermes/gateway/platforms/api_server.py")
ANCHOR = " agent = AIAgent(**agent_kwargs)\n"
PATCHED = """ # Athena workaround for upstream issue #69746: the API platform
API_TARGET = Path("/opt/hermes/gateway/platforms/api_server.py")
API_ANCHOR = " agent = AIAgent(**agent_kwargs)\n"
API_PATCHED = """ # Athena workaround for upstream issue #69746: the API platform
# otherwise snapshots tools before the live MCP registry is attached.
agent = AIAgent(**agent_kwargs)
try:
@@ -30,15 +30,38 @@ PATCHED = """ # Athena workaround for upstream issue #69746: the API plat
)
"""
REFRESH_TARGET = Path("/opt/hermes/tools/mcp_tool.py")
REFRESH_ANCHOR = """ if new_names == current:
# No change → leave the live snapshot untouched (no churn), but
"""
REFRESH_PATCHED = """ if (
new_names == current
and new_defs == (getattr(agent, "tools", None) or [])
):
# Names and schemas are unchanged. Comparing schemas is required
# for the tool_search bridge, whose three public names stay fixed
# while its embedded deferred-tool catalog changes (#72560).
"""
source = TARGET.read_text(encoding="utf-8")
if PATCHED in source:
print("Hermes API MCP refresh patch already present")
elif source.count(ANCHOR) == 1:
TARGET.write_text(source.replace(ANCHOR, PATCHED, 1), encoding="utf-8")
print("Applied Hermes API MCP refresh patch")
else:
def apply_patch(target: Path, anchor: str, replacement: str, label: str) -> None:
source = target.read_text(encoding="utf-8")
if replacement in source:
print(f"Hermes {label} patch already present")
elif source.count(anchor) == 1:
target.write_text(source.replace(anchor, replacement, 1), encoding="utf-8")
print(f"Applied Hermes {label} patch")
else:
raise SystemExit(
"HERMES_START_REFUSED: upstream api_server.py changed; "
"review the MCP refresh patch before upgrading"
f"HERMES_START_REFUSED: upstream {target.name} changed; "
f"review the {label} patch before upgrading"
)
apply_patch(API_TARGET, API_ANCHOR, API_PATCHED, "API MCP refresh")
apply_patch(
REFRESH_TARGET,
REFRESH_ANCHOR,
REFRESH_PATCHED,
"tool-search catalog refresh",
)