#!/usr/bin/env python3 """Launcher systemd pour JARVIS v3 — récupère la clé Hermes puis démarre le bot.""" import os import json import subprocess import sys def get_hermes_key(): """Récupère la clé API Hermes depuis Infisical.""" key = os.environ.get("HERMES_API_KEY", "") or os.environ.get("HERMES_ALEXA_KEY", "") if key: return key try: creds = json.load(open("/opt/infisical/admin-credentials.json")) r = subprocess.run( ["/home/openclaw/.local/lib/node_modules/@infisical/cli/bin/infisical", "secrets", "get", "API_SERVER_KEY", "--domain", "https://secret.dracodev.net", "--projectId", "192c1eed-6666-41ee-80df-a4636a2da0ad", "--env", "prod", "--path", "/hermes-claw", "--plain", "--token", creds["token"]], capture_output=True, text=True, timeout=15) if r.returncode == 0 and r.stdout.strip(): return r.stdout.strip() except Exception as e: print(f"[launcher] Infisical: {e}", file=sys.stderr) # Fallback: lire depuis workspace/.env try: with open(os.path.expanduser("~/workspace/.env")) as f: for line in f: if line.startswith("HERMES_ALEXA_KEY="): return line.split("=", 1)[1].strip() if line.startswith("API_SERVER_KEY="): return line.split("=", 1)[1].strip() except Exception: pass return "" if __name__ == "__main__": key = get_hermes_key() if not key: print("[launcher] ERREUR: Impossible de récupérer la clé Hermes", file=sys.stderr) sys.exit(1) os.environ["HERMES_API_KEY"] = key os.environ["JARVIS_PORT"] = os.environ.get("JARVIS_PORT", "7081") # Lance bot_direct.py bot_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bot_direct.py") python = os.path.join(os.path.dirname(os.path.abspath(__file__)), "venv", "bin", "python") os.execv(python, [python, bot_path])