Cleanup time!

This commit is contained in:
teknium1 2026-02-20 23:23:32 -08:00
parent 9a19fe1f50
commit 70dd3a16dc
38 changed files with 150 additions and 351 deletions

View file

@ -30,6 +30,7 @@ import httpx
import yaml
from hermes_cli.config import get_hermes_home, get_config_path
from hermes_constants import OPENROUTER_BASE_URL
try:
import fcntl
@ -865,7 +866,7 @@ def _reset_config_provider() -> Path:
if isinstance(model, dict):
model["provider"] = "auto"
if "base_url" in model:
model["base_url"] = "https://openrouter.ai/api/v1"
model["base_url"] = OPENROUTER_BASE_URL
config_path.write_text(yaml.safe_dump(config, sort_keys=False))
return config_path

22
hermes_cli/colors.py Normal file
View file

@ -0,0 +1,22 @@
"""Shared ANSI color utilities for Hermes CLI modules."""
import sys
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
"""Apply color codes to text (only when output is a TTY)."""
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET

View file

@ -20,22 +20,7 @@ from typing import Dict, Any, Optional, List, Tuple
import yaml
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
# =============================================================================

View file

@ -4,29 +4,14 @@ Cron subcommand for hermes CLI.
Handles: hermes cron [list|daemon|tick]
"""
import json
import sys
import time
from pathlib import Path
from datetime import datetime
PROJECT_ROOT = Path(__file__).parent.parent.resolve()
sys.path.insert(0, str(PROJECT_ROOT))
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
def cron_list(show_all: bool = False):

View file

@ -23,20 +23,8 @@ if _env_path.exists():
# Also try project .env as fallback
load_dotenv(PROJECT_ROOT / ".env", override=False)
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
from hermes_constants import OPENROUTER_MODELS_URL
def check_ok(text: str, detail: str = ""):
print(f" {color('', Colors.GREEN)} {text}" + (f" {color(detail, Colors.DIM)}" if detail else ""))
@ -314,7 +302,7 @@ def run_doctor(args):
try:
import httpx
response = httpx.get(
"https://openrouter.ai/api/v1/models",
OPENROUTER_MODELS_URL,
headers={"Authorization": f"Bearer {openrouter_key}"},
timeout=10
)

View file

@ -40,6 +40,7 @@ if env_path.exists():
load_dotenv(dotenv_path=env_path)
from hermes_cli import __version__
from hermes_constants import OPENROUTER_BASE_URL
def cmd_chat(args):
@ -241,7 +242,7 @@ def _model_flow_openrouter(config, current_model=""):
model = cfg.get("model")
if isinstance(model, dict):
model["provider"] = "openrouter"
model["base_url"] = "https://openrouter.ai/api/v1"
model["base_url"] = OPENROUTER_BASE_URL
save_config(cfg)
deactivate_provider()
print(f"Default model set to: {selected} (via OpenRouter)")

View file

@ -8,9 +8,6 @@ Usage:
hermes pairing clear-pending # Clear all expired/pending codes
"""
import sys
def pairing_command(args):
"""Handle hermes pairing subcommands."""
from gateway.pairing import PairingStore

View file

@ -26,23 +26,7 @@ from hermes_cli.config import (
ensure_hermes_home, DEFAULT_CONFIG
)
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
"""Apply color codes to text."""
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
def print_header(title: str):
"""Print a section header."""

View file

@ -12,7 +12,6 @@ handler are thin wrappers that parse args and delegate.
import json
import shutil
import sys
from pathlib import Path
from typing import Optional

View file

@ -11,20 +11,8 @@ from pathlib import Path
PROJECT_ROOT = Path(__file__).parent.parent.resolve()
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
from hermes_constants import OPENROUTER_MODELS_URL
def check_mark(ok: bool) -> str:
if ok:
@ -232,7 +220,7 @@ def show_status(args):
jobs = data.get("jobs", [])
enabled_jobs = [j for j in jobs if j.get("enabled", True)]
print(f" Jobs: {len(enabled_jobs)} active, {len(jobs)} total")
except:
except Exception:
print(f" Jobs: (error reading jobs file)")
else:
print(f" Jobs: 0")
@ -250,7 +238,7 @@ def show_status(args):
with open(sessions_file) as f:
data = json.load(f)
print(f" Active: {len(data)} session(s)")
except:
except Exception:
print(f" Active: (error reading sessions file)")
else:
print(f" Active: 0")
@ -268,7 +256,7 @@ def show_status(args):
try:
import httpx
response = httpx.get(
"https://openrouter.ai/api/v1/models",
OPENROUTER_MODELS_URL,
headers={"Authorization": f"Bearer {openrouter_key}"},
timeout=10
)
@ -288,7 +276,7 @@ def show_status(args):
port_in_use = result == 0
# This is informational, not necessarily bad
print(f" Port 18789: {'in use' if port_in_use else 'available'}")
except:
except OSError:
pass
print()

View file

@ -13,23 +13,7 @@ import subprocess
from pathlib import Path
from typing import Optional
# ANSI colors
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
def color(text: str, *codes) -> str:
"""Apply color codes to text (only in TTY)."""
if not sys.stdout.isatty():
return text
return "".join(codes) + text + Colors.RESET
from hermes_cli.colors import Colors, color
def log_info(msg: str):
print(f"{color('', Colors.CYAN)} {msg}")