#!/usr/bin/env python3 """CLI helper to list, get, and switch Hermes agent profiles for VoiceAgent.""" import os import re import shutil import subprocess import sys from pathlib import Path # Add VoiceAgent1 project root to sys.path project_root = Path(__file__).resolve().parent.parent if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) from hermes_llm import find_hermes_cli def _get_hermes_cli() -> str: cli = find_hermes_cli() if not cli: raise RuntimeError("Hermes CLI binary not found in PATH or standard paths") return cli def list_profiles() -> str: cli = _get_hermes_cli() res = subprocess.run([cli, "profile", "list"], capture_output=True, text=True) if res.returncode != 0: return f"Error listing profiles: {res.stderr.strip()}" return res.stdout.strip() def get_current_profile() -> str: cli = _get_hermes_cli() res = subprocess.run([cli, "profile", "list"], capture_output=True, text=True) if res.returncode == 0: for line in res.stdout.splitlines(): line_clean = line.strip() if line_clean.startswith("◆") or line_clean.startswith("*"): parts = line_clean.lstrip("◆* ").split() if parts: return parts[0] return "default" def set_profile(profile_name: str) -> tuple[bool, str]: target = profile_name.strip().lstrip("◆* ") if not target: return False, "No profile name specified." cli = _get_hermes_cli() res = subprocess.run([cli, "profile", "use", target], capture_output=True, text=True) if res.returncode == 0: output_msg = res.stdout.strip() or f"Switched to Hermes profile '{target}'." try: import web_server web_server.broadcast_event("status_change", {"profile": target}) except Exception: pass return True, output_msg else: err_msg = res.stderr.strip() or res.stdout.strip() or f"Failed to set profile '{target}'." return False, err_msg def main(): if len(sys.argv) < 2 or sys.argv[1] in ("list", "ls", "--list"): print(list_profiles()) return action = sys.argv[1].lower() if action in ("get", "current", "show"): print(f"Active Hermes Profile: {get_current_profile()}") return if action in ("set", "use", "change") and len(sys.argv) >= 3: target = sys.argv[2] ok, msg = set_profile(target) print(msg) else: # Treat single argument as target profile target = sys.argv[1] ok, msg = set_profile(target) print(msg) if __name__ == "__main__": main()