import os import subprocess def ask_hermes(text): hermes_cli = os.getenv("HERMES_CLI", "/root/.local/bin/hermes") try: result = subprocess.run( [ hermes_cli, "--oneshot", text ], capture_output=True, text=True, timeout=180, check=True ) return result.stdout.strip() except subprocess.TimeoutExpired: raise RuntimeError( "Hermes n'a pas répondu dans le délai imparti." ) except subprocess.CalledProcessError as e: stderr = (e.stderr or "").strip() stdout = (e.stdout or "").strip() raise RuntimeError( f"Hermes a échoué (code {e.returncode}): " f"{stderr or stdout or 'aucun détail'}" )