diff --git a/backend/services/maintenance.py b/backend/services/maintenance.py index 7782e60..7749fa9 100644 --- a/backend/services/maintenance.py +++ b/backend/services/maintenance.py @@ -15,7 +15,6 @@ from datetime import datetime import httpx import psutil -from config import HERMES_AGENT_REPO from services import catalog, discover, jobengine, llamaswap, system # System-Dienste (root, via sudo -n NOPASSWD) vs. User-Dienste (systemctl --user). @@ -89,42 +88,34 @@ def _engine_update_available() -> bool: _comp_cache = {"ts": 0.0, "data": []} -def _gh_latest(repo: str) -> dict | None: - """Neuestes GitHub-Release {tag, published} oder None.""" - try: - rel = httpx.get(f"https://api.github.com/repos/{repo}/releases/latest", - timeout=6, headers={"User-Agent": "MissionControl2"}).json() - return {"tag": str(rel.get("tag_name", "")), "published": rel.get("published_at")} - except Exception: - return None - - -def _commit_ts(path: str) -> int | None: - try: - p = subprocess.run(["git", "-C", os.path.expanduser(path), "log", "-1", "--format=%ct"], - capture_output=True, text=True, timeout=8) - return int(p.stdout.strip()) if p.returncode == 0 and p.stdout.strip() else None - except Exception: - return None - - def _hermes_agent_update() -> dict: - """Hermes-Agent: neuestes Release vs. installiertes git-Commit-Datum.""" + """Hermes-Agent wird aus **git** aktualisiert (CLI `hermes update` = git pull origin ). + Darum HEAD vs. origin/ prüfen (fetch + behind-count) — NICHT GitHub-Releases: die + werden selten getaggt, main läuft ihnen voraus → sonst zeigt das UI nie ein Update an.""" info = {"key": "hermes_agent", "name": "Hermes Agent", "current": None, "latest": None, "update": False, "reachable": None} git = system.find_hermes_agent_git() - if git: - info["current"] = git.get("hash") - gh = _gh_latest(HERMES_AGENT_REPO) - if gh: - info["latest"] = gh["tag"] - ts = _commit_ts(git["path"]) if (git and git.get("path")) else None - if gh["published"] and ts: - try: - pub = datetime.fromisoformat(gh["published"].replace("Z", "+00:00")).timestamp() - info["update"] = pub > ts + 86400 # Release > installiertes Commit (+1 Tag Toleranz) - except Exception: - pass + if not git or not git.get("path"): + return info + path = git["path"] + info["current"] = git.get("hash") + try: + branch = (subprocess.run(["git", "-C", path, "rev-parse", "--abbrev-ref", "HEAD"], + capture_output=True, text=True, timeout=8).stdout.strip() or "main") + fetch = subprocess.run(["git", "-C", path, "fetch", "-q", "origin", branch], + capture_output=True, text=True, timeout=25) + info["reachable"] = (fetch.returncode == 0) + if fetch.returncode == 0: + cnt = subprocess.run(["git", "-C", path, "rev-list", "--count", f"HEAD..origin/{branch}"], + capture_output=True, text=True, timeout=8) + behind = int(cnt.stdout.strip() or "0") if cnt.returncode == 0 else 0 + info["behind"] = behind + info["update"] = behind > 0 + oh = subprocess.run(["git", "-C", path, "rev-parse", "--short", f"origin/{branch}"], + capture_output=True, text=True, timeout=8).stdout.strip() + info["latest"] = (f"{oh} ({behind} neu)" if behind else (oh or info["current"])) + except Exception: + info["reachable"] = False return info