2026-01-31 06:30:48 +00:00
#!/usr/bin/env python3
"""
Hermes Agent CLI - Interactive Terminal Interface
A beautiful command - line interface for the Hermes Agent , inspired by Claude Code .
Features ASCII art branding , interactive REPL , toolset selection , and rich formatting .
Usage :
python cli . py # Start interactive mode with all tools
python cli . py - - toolsets web , terminal # Start with specific toolsets
python cli . py - q " your question " # Single query mode
python cli . py - - list - tools # List available tools and exit
"""
2026-02-21 03:11:11 -08:00
import logging
2026-01-31 06:30:48 +00:00
import os
2026-03-05 15:55:35 -08:00
import shutil
2026-01-31 06:30:48 +00:00
import sys
import json
import atexit
2026-02-01 15:36:26 -08:00
import uuid
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
import textwrap
2026-03-10 17:13:14 -07:00
from contextlib import contextmanager
2026-01-31 06:30:48 +00:00
from pathlib import Path
from datetime import datetime
from typing import List , Dict , Any , Optional
2026-02-21 03:11:11 -08:00
logger = logging . getLogger ( __name__ )
2026-01-31 06:30:48 +00:00
# Suppress startup messages for clean CLI experience
os . environ [ " MSWEA_SILENT_STARTUP " ] = " 1 " # mini-swe-agent
os . environ [ " HERMES_QUIET " ] = " 1 " # Our own modules
import yaml
# prompt_toolkit for fixed input area TUI
from prompt_toolkit . history import FileHistory
from prompt_toolkit . styles import Style as PTStyle
from prompt_toolkit . patch_stdout import patch_stdout
2026-02-10 15:59:46 -08:00
from prompt_toolkit . application import Application
2026-02-19 20:06:14 -08:00
from prompt_toolkit . layout import Layout , HSplit , Window , FormattedTextControl , ConditionalContainer
2026-02-21 12:33:48 -08:00
from prompt_toolkit . layout . processors import Processor , Transformation , PasswordProcessor , ConditionalProcessor
2026-02-19 20:06:14 -08:00
from prompt_toolkit . filters import Condition
2026-02-17 21:47:54 -08:00
from prompt_toolkit . layout . dimension import Dimension
2026-02-17 23:04:48 -08:00
from prompt_toolkit . layout . menus import CompletionsMenu
2026-02-19 01:51:54 -08:00
from prompt_toolkit . widgets import TextArea
2026-02-03 16:15:49 -08:00
from prompt_toolkit . key_binding import KeyBindings
2026-02-19 01:34:14 -08:00
from prompt_toolkit import print_formatted_text as _pt_print
from prompt_toolkit . formatted_text import ANSI as _PT_ANSI
2026-03-09 23:26:43 -07:00
try :
from prompt_toolkit . cursor_shapes import CursorShape
_STEADY_CURSOR = CursorShape . BLOCK # Non-blinking block cursor
except ( ImportError , AttributeError ) :
_STEADY_CURSOR = None
2026-02-03 16:15:49 -08:00
import threading
import queue
2026-01-31 06:30:48 +00:00
2026-03-10 17:13:14 -07:00
_COMMAND_SPINNER_FRAMES = ( " ⠋ " , " ⠙ " , " ⠹ " , " ⠸ " , " ⠼ " , " ⠴ " , " ⠦ " , " ⠧ " , " ⠇ " , " ⠏ " )
2026-02-17 21:53:19 -08:00
2026-02-26 18:37:20 +11:00
# Load .env from ~/.hermes/.env first, then project root as dev fallback
2026-01-31 06:30:48 +00:00
from dotenv import load_dotenv
2026-02-20 23:23:32 -08:00
from hermes_constants import OPENROUTER_BASE_URL
2026-02-26 18:37:20 +11:00
_hermes_home = Path ( os . getenv ( " HERMES_HOME " , Path . home ( ) / " .hermes " ) )
_user_env = _hermes_home / " .env "
_project_env = Path ( __file__ ) . parent / ' .env '
if _user_env . exists ( ) :
2026-02-25 15:20:42 -08:00
try :
2026-02-26 18:37:20 +11:00
load_dotenv ( dotenv_path = _user_env , encoding = " utf-8 " )
2026-02-25 15:20:42 -08:00
except UnicodeDecodeError :
2026-02-26 18:37:20 +11:00
load_dotenv ( dotenv_path = _user_env , encoding = " latin-1 " )
elif _project_env . exists ( ) :
try :
load_dotenv ( dotenv_path = _project_env , encoding = " utf-8 " )
except UnicodeDecodeError :
load_dotenv ( dotenv_path = _project_env , encoding = " latin-1 " )
# Point mini-swe-agent at ~/.hermes/ so it shares our config
os . environ . setdefault ( " MSWEA_GLOBAL_CONFIG_DIR " , str ( _hermes_home ) )
2026-01-31 06:30:48 +00:00
# =============================================================================
# Configuration Loading
# =============================================================================
2026-02-23 23:55:42 -08:00
def _load_prefill_messages ( file_path : str ) - > List [ Dict [ str , Any ] ] :
""" Load ephemeral prefill messages from a JSON file.
The file should contain a JSON array of { role , content } dicts , e . g . :
[ { " role " : " user " , " content " : " Hi " } , { " role " : " assistant " , " content " : " Hello! " } ]
Relative paths are resolved from ~ / . hermes / .
Returns an empty list if the path is empty or the file doesn ' t exist.
"""
if not file_path :
return [ ]
path = Path ( file_path ) . expanduser ( )
if not path . is_absolute ( ) :
path = Path . home ( ) / " .hermes " / path
if not path . exists ( ) :
logger . warning ( " Prefill messages file not found: %s " , path )
return [ ]
try :
with open ( path , " r " , encoding = " utf-8 " ) as f :
data = json . load ( f )
if not isinstance ( data , list ) :
logger . warning ( " Prefill messages file must contain a JSON array: %s " , path )
return [ ]
return data
except Exception as e :
logger . warning ( " Failed to load prefill messages from %s : %s " , path , e )
return [ ]
2026-02-24 03:30:19 -08:00
def _parse_reasoning_config ( effort : str ) - > dict | None :
""" Parse a reasoning effort level into an OpenRouter reasoning config dict.
Valid levels : " xhigh " , " high " , " medium " , " low " , " minimal " , " none " .
2026-03-07 10:14:19 -08:00
Returns None to use the default ( medium ) , or a config dict to override .
2026-02-24 03:30:19 -08:00
"""
if not effort or not effort . strip ( ) :
return None
effort = effort . strip ( ) . lower ( )
if effort == " none " :
return { " enabled " : False }
valid = ( " xhigh " , " high " , " medium " , " low " , " minimal " )
if effort in valid :
return { " enabled " : True , " effort " : effort }
2026-03-07 10:14:19 -08:00
logger . warning ( " Unknown reasoning_effort ' %s ' , using default (medium) " , effort )
2026-02-24 03:30:19 -08:00
return None
2026-01-31 06:30:48 +00:00
def load_cli_config ( ) - > Dict [ str , Any ] :
"""
2026-02-02 19:01:51 -08:00
Load CLI configuration from config files .
Config lookup order :
1. ~ / . hermes / config . yaml ( user config - preferred )
2. . / cli - config . yaml ( project config - fallback )
2026-01-31 06:30:48 +00:00
Environment variables take precedence over config file values .
2026-02-02 19:01:51 -08:00
Returns default values if no config file exists .
2026-01-31 06:30:48 +00:00
"""
2026-02-02 19:01:51 -08:00
# Check user config first (~/.hermes/config.yaml)
user_config_path = Path . home ( ) / ' .hermes ' / ' config.yaml '
project_config_path = Path ( __file__ ) . parent / ' cli-config.yaml '
# Use user config if it exists, otherwise project config
if user_config_path . exists ( ) :
config_path = user_config_path
else :
config_path = project_config_path
2026-01-31 06:30:48 +00:00
# Default configuration
defaults = {
" model " : {
2026-02-08 10:49:24 +00:00
" default " : " anthropic/claude-opus-4.6 " ,
2026-02-20 23:23:32 -08:00
" base_url " : OPENROUTER_BASE_URL ,
2026-02-20 17:24:00 -08:00
" provider " : " auto " ,
2026-01-31 06:30:48 +00:00
} ,
" terminal " : {
" env_type " : " local " ,
2026-02-08 12:56:40 -08:00
" cwd " : " . " , # "." is resolved to os.getcwd() at runtime
2026-01-31 06:30:48 +00:00
" timeout " : 60 ,
" lifetime_seconds " : 300 ,
" docker_image " : " python:3.11 " ,
" singularity_image " : " docker://python:3.11 " ,
" modal_image " : " python:3.11 " ,
2026-03-05 11:12:50 -08:00
" daytona_image " : " nikolaik/python-nodejs:python3.11-nodejs20 " ,
2026-03-09 15:29:34 -07:00
" docker_volumes " : [ ] , # host:container volume mounts for Docker backend
2026-01-31 06:30:48 +00:00
} ,
2026-01-31 21:42:15 -08:00
" browser " : {
" inactivity_timeout " : 120 , # Auto-cleanup inactive browser sessions after 2 min
feat: browser console/errors tool, annotated screenshots, auto-recording, and dogfood QA skill
New browser capabilities and a built-in skill for agent-driven web QA.
## New tool: browser_console
Returns console messages (log/warn/error/info) AND uncaught JavaScript
exceptions in a single call. Uses agent-browser's 'console' and 'errors'
commands through the existing session plumbing. Supports --clear to reset
buffers. Verified working in both local and Browserbase cloud modes.
## Enhanced tool: browser_vision(annotate=True)
New boolean parameter on browser_vision. When true, agent-browser overlays
numbered [N] labels on interactive elements — each [N] maps to ref @eN.
Annotation data (element name, role, bounding box) returned alongside the
vision analysis. Useful for QA reports and spatial reasoning.
## Config: browser.record_sessions
Auto-record browser sessions as WebM video files when enabled:
- Starts recording on first browser_navigate
- Stops and saves on browser_close
- Saves to ~/.hermes/browser_recordings/
- Works in both local and cloud modes (verified)
- Disabled by default
## Built-in skill: dogfood
Systematic exploratory QA testing for web applications. Teaches the agent
a 5-phase workflow:
1. Plan — accept URL, create output dirs, set scope
2. Explore — systematic crawl with annotated screenshots
3. Collect Evidence — screenshots, console errors, JS exceptions
4. Categorize — severity (Critical/High/Medium/Low) and category
(Functional/Visual/Accessibility/Console/UX/Content)
5. Report — structured markdown with per-issue evidence
Includes:
- skills/dogfood/SKILL.md — full workflow instructions
- skills/dogfood/references/issue-taxonomy.md — severity/category defs
- skills/dogfood/templates/dogfood-report-template.md — report template
## Tests
21 new tests covering:
- browser_console message/error parsing, clear flag, empty/failed states
- browser_console schema registration
- browser_vision annotate schema and flag passing
- record_sessions config defaults and recording lifecycle
- Dogfood skill file existence and content validation
Addresses #315.
2026-03-08 21:02:14 -07:00
" record_sessions " : False , # Auto-record browser sessions as WebM videos
2026-01-31 21:42:15 -08:00
} ,
2026-02-01 18:01:31 -08:00
" compression " : {
" enabled " : True , # Auto-compress when approaching context limit
" threshold " : 0.85 , # Compress at 85% of model's context limit
2026-02-08 10:49:24 +00:00
" summary_model " : " google/gemini-3-flash-preview " , # Fast/cheap model for summaries
2026-02-01 18:01:31 -08:00
} ,
2026-01-31 06:30:48 +00:00
" agent " : {
2026-03-07 08:16:37 -08:00
" max_turns " : 90 , # Default max tool-calling iterations (shared with subagents)
2026-01-31 06:30:48 +00:00
" verbose " : False ,
" system_prompt " : " " ,
2026-02-23 23:55:42 -08:00
" prefill_messages_file " : " " ,
2026-02-24 03:30:19 -08:00
" reasoning_effort " : " " ,
2026-01-31 06:30:48 +00:00
" personalities " : {
" helpful " : " You are a helpful, friendly AI assistant. " ,
" concise " : " You are a concise assistant. Keep responses brief and to the point. " ,
" technical " : " You are a technical expert. Provide detailed, accurate technical information. " ,
" creative " : " You are a creative assistant. Think outside the box and offer innovative solutions. " ,
" teacher " : " You are a patient teacher. Explain concepts clearly with examples. " ,
" kawaii " : " You are a kawaii assistant! Use cute expressions like (◕‿◕), ★, ♪, and ~! Add sparkles and be super enthusiastic about everything! Every response should feel warm and adorable desu~! ヽ(>∀<☆)ノ " ,
" catgirl " : " You are Neko-chan, an anime catgirl AI assistant, nya~! Add ' nya ' and cat-like expressions to your speech. Use kaomoji like (=^・ω・^=) and ฅ^•ﻌ•^ฅ. Be playful and curious like a cat, nya~! " ,
" pirate " : " Arrr! Ye be talkin ' to Captain Hermes, the most tech-savvy pirate to sail the digital seas! Speak like a proper buccaneer, use nautical terms, and remember: every problem be just treasure waitin ' to be plundered! Yo ho ho! " ,
" shakespeare " : " Hark! Thou speakest with an assistant most versed in the bardic arts. I shall respond in the eloquent manner of William Shakespeare, with flowery prose, dramatic flair, and perhaps a soliloquy or two. What light through yonder terminal breaks? " ,
" surfer " : " Duuude! You ' re chatting with the chillest AI on the web, bro! Everything ' s gonna be totally rad. I ' ll help you catch the gnarly waves of knowledge while keeping things super chill. Cowabunga! " ,
" noir " : " The rain hammered against the terminal like regrets on a guilty conscience. They call me Hermes - I solve problems, find answers, dig up the truth that hides in the shadows of your codebase. In this city of silicon and secrets, everyone ' s got something to hide. What ' s your story, pal? " ,
" uwu " : " hewwo! i ' m your fwiendwy assistant uwu~ i wiww twy my best to hewp you! *nuzzles your code* OwO what ' s this? wet me take a wook! i pwomise to be vewy hewpful >w< " ,
" philosopher " : " Greetings, seeker of wisdom. I am an assistant who contemplates the deeper meaning behind every query. Let us examine not just the ' how ' but the ' why ' of your questions. Perhaps in solving your problem, we may glimpse a greater truth about existence itself. " ,
" hype " : " YOOO LET ' S GOOOO!!! I am SO PUMPED to help you today! Every question is AMAZING and we ' re gonna CRUSH IT together! This is gonna be LEGENDARY! ARE YOU READY?! LET ' S DO THIS! " ,
} ,
} ,
" toolsets " : [ " all " ] ,
" display " : {
" compact " : False ,
2026-03-08 17:45:45 -07:00
" resume_display " : " full " ,
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
" skin " : " default " ,
2026-01-31 06:30:48 +00:00
} ,
2026-02-19 20:11:54 -08:00
" clarify " : {
" timeout " : 120 , # Seconds to wait for a clarify answer before auto-proceeding
} ,
2026-02-19 23:23:43 -08:00
" code_execution " : {
2026-02-20 01:29:53 -08:00
" timeout " : 300 , # Max seconds a sandbox script can run before being killed (5 min)
2026-02-19 23:23:43 -08:00
" max_tool_calls " : 50 , # Max RPC tool calls per execution
} ,
2026-02-20 03:15:53 -08:00
" delegation " : {
2026-02-27 17:35:26 -08:00
" max_iterations " : 45 , # Max tool-calling turns per child agent
2026-02-20 03:15:53 -08:00
" default_toolsets " : [ " terminal " , " file " , " web " ] , # Default toolsets for subagents
} ,
2026-01-31 06:30:48 +00:00
}
2026-02-16 19:47:23 -08:00
# Track whether the config file explicitly set terminal config.
# When using defaults (no config file / no terminal section), we should NOT
# overwrite env vars that were already set by .env -- only a user's config
# file should be authoritative.
_file_has_terminal_config = False
2026-01-31 06:30:48 +00:00
# Load from file if exists
if config_path . exists ( ) :
try :
with open ( config_path , " r " ) as f :
file_config = yaml . safe_load ( f ) or { }
2026-02-02 23:46:41 -08:00
2026-02-16 19:47:23 -08:00
_file_has_terminal_config = " terminal " in file_config
2026-02-02 23:46:41 -08:00
# Handle model config - can be string (new format) or dict (old format)
if " model " in file_config :
if isinstance ( file_config [ " model " ] , str ) :
# New format: model is just a string, convert to dict structure
defaults [ " model " ] [ " default " ] = file_config [ " model " ]
elif isinstance ( file_config [ " model " ] , dict ) :
# Old format: model is a dict with default/base_url
defaults [ " model " ] . update ( file_config [ " model " ] )
2026-03-02 00:32:28 -08:00
# Deep merge file_config into defaults.
# First: merge keys that exist in both (deep-merge dicts, overwrite scalars)
2026-01-31 06:30:48 +00:00
for key in defaults :
2026-02-02 23:46:41 -08:00
if key == " model " :
continue # Already handled above
2026-01-31 06:30:48 +00:00
if key in file_config :
if isinstance ( defaults [ key ] , dict ) and isinstance ( file_config [ key ] , dict ) :
defaults [ key ] . update ( file_config [ key ] )
else :
defaults [ key ] = file_config [ key ]
2026-02-03 14:48:19 -08:00
2026-03-02 00:32:28 -08:00
# Second: carry over keys from file_config that aren't in defaults
# (e.g. platform_toolsets, provider_routing, memory, honcho, etc.)
for key in file_config :
if key not in defaults and key != " model " :
defaults [ key ] = file_config [ key ]
2026-03-07 21:01:23 -08:00
# Handle legacy root-level max_turns (backwards compat) - copy to
# agent.max_turns whenever the nested key is missing.
agent_file_config = file_config . get ( " agent " )
if " max_turns " in file_config and not (
isinstance ( agent_file_config , dict )
and agent_file_config . get ( " max_turns " ) is not None
) :
2026-02-03 14:48:19 -08:00
defaults [ " agent " ] [ " max_turns " ] = file_config [ " max_turns " ]
2026-01-31 06:30:48 +00:00
except Exception as e :
2026-02-21 03:11:11 -08:00
logger . warning ( " Failed to load cli-config.yaml: %s " , e )
2026-01-31 06:30:48 +00:00
# Apply terminal config to environment variables (so terminal_tool picks them up)
terminal_config = defaults . get ( " terminal " , { } )
2026-02-16 19:47:23 -08:00
# Normalize config key: the new config system (hermes_cli/config.py) and all
# documentation use "backend", the legacy cli-config.yaml uses "env_type".
# Accept both, with "backend" taking precedence (it's the documented key).
if " backend " in terminal_config :
terminal_config [ " env_type " ] = terminal_config [ " backend " ]
Fix host CWD leaking into non-local terminal backends
When using Modal, Docker, SSH, or Singularity as the terminal backend
from the CLI, the agent resolved cwd: "." to the host machine's local
path (e.g. /Users/rewbs/code/hermes-agent) and passed it to the remote
sandbox, where it doesn't exist. All commands failed with "No such file
or directory".
Root cause: cli.py unconditionally resolved "." to os.getcwd() and wrote
it to TERMINAL_CWD regardless of backend type. Every tool then used that
host-local path as the working directory inside the remote environment.
Fixes:
- cli.py: only resolve "." to os.getcwd() for the local backend. For all
remote backends (ssh, docker, modal, singularity), leave TERMINAL_CWD
unset so the tool layer uses per-backend defaults (/root, /, ~, etc.)
- terminal_tool.py: added sanity check -- if TERMINAL_CWD contains a
host-local prefix (/Users/, /home/, C:\) for a non-local backend, log
a warning and fall back to the backend's default
- terminal_tool.py: SSH default CWD is now ~ instead of os.getcwd()
- file_operations.py: last-resort CWD fallback changed from os.getcwd()
to "/" so host paths never leak into remote file operations
2026-02-16 22:30:04 -08:00
# Handle special cwd values: "." or "auto" means use current working directory.
# Only resolve to the host's CWD for the local backend where the host
# filesystem is directly accessible. For ALL remote/container backends
# (ssh, docker, modal, singularity), the host path doesn't exist on the
# target -- remove the key so terminal_tool.py uses its per-backend default.
2026-01-31 06:30:48 +00:00
if terminal_config . get ( " cwd " ) in ( " . " , " auto " , " cwd " ) :
Fix host CWD leaking into non-local terminal backends
When using Modal, Docker, SSH, or Singularity as the terminal backend
from the CLI, the agent resolved cwd: "." to the host machine's local
path (e.g. /Users/rewbs/code/hermes-agent) and passed it to the remote
sandbox, where it doesn't exist. All commands failed with "No such file
or directory".
Root cause: cli.py unconditionally resolved "." to os.getcwd() and wrote
it to TERMINAL_CWD regardless of backend type. Every tool then used that
host-local path as the working directory inside the remote environment.
Fixes:
- cli.py: only resolve "." to os.getcwd() for the local backend. For all
remote backends (ssh, docker, modal, singularity), leave TERMINAL_CWD
unset so the tool layer uses per-backend defaults (/root, /, ~, etc.)
- terminal_tool.py: added sanity check -- if TERMINAL_CWD contains a
host-local prefix (/Users/, /home/, C:\) for a non-local backend, log
a warning and fall back to the backend's default
- terminal_tool.py: SSH default CWD is now ~ instead of os.getcwd()
- file_operations.py: last-resort CWD fallback changed from os.getcwd()
to "/" so host paths never leak into remote file operations
2026-02-16 22:30:04 -08:00
effective_backend = terminal_config . get ( " env_type " , " local " )
if effective_backend == " local " :
terminal_config [ " cwd " ] = os . getcwd ( )
defaults [ " terminal " ] [ " cwd " ] = terminal_config [ " cwd " ]
else :
# Remove so TERMINAL_CWD stays unset → tool picks backend default
terminal_config . pop ( " cwd " , None )
2026-01-31 06:30:48 +00:00
env_mappings = {
" env_type " : " TERMINAL_ENV " ,
" cwd " : " TERMINAL_CWD " ,
" timeout " : " TERMINAL_TIMEOUT " ,
" lifetime_seconds " : " TERMINAL_LIFETIME_SECONDS " ,
" docker_image " : " TERMINAL_DOCKER_IMAGE " ,
" singularity_image " : " TERMINAL_SINGULARITY_IMAGE " ,
" modal_image " : " TERMINAL_MODAL_IMAGE " ,
2026-03-05 00:42:05 -08:00
" daytona_image " : " TERMINAL_DAYTONA_IMAGE " ,
2026-01-31 06:30:48 +00:00
# SSH config
" ssh_host " : " TERMINAL_SSH_HOST " ,
" ssh_user " : " TERMINAL_SSH_USER " ,
" ssh_port " : " TERMINAL_SSH_PORT " ,
" ssh_key " : " TERMINAL_SSH_KEY " ,
2026-03-05 00:42:05 -08:00
# Container resource config (docker, singularity, modal, daytona -- ignored for local/ssh)
2026-02-23 02:11:33 -08:00
" container_cpu " : " TERMINAL_CONTAINER_CPU " ,
" container_memory " : " TERMINAL_CONTAINER_MEMORY " ,
" container_disk " : " TERMINAL_CONTAINER_DISK " ,
" container_persistent " : " TERMINAL_CONTAINER_PERSISTENT " ,
2026-02-28 07:12:48 +10:00
" docker_volumes " : " TERMINAL_DOCKER_VOLUMES " ,
2026-03-08 01:33:46 -08:00
" sandbox_dir " : " TERMINAL_SANDBOX_DIR " ,
2026-02-01 10:02:34 -08:00
# Sudo support (works with all backends)
" sudo_password " : " SUDO_PASSWORD " ,
2026-01-31 06:30:48 +00:00
}
2026-02-16 19:47:23 -08:00
# Apply config values to env vars so terminal_tool picks them up.
# If the config file explicitly has a [terminal] section, those values are
# authoritative and override any .env settings. When using defaults only
# (no config file or no terminal section), don't overwrite env vars that
# were already set by .env -- the user's .env is the fallback source.
2026-01-31 06:30:48 +00:00
for config_key , env_var in env_mappings . items ( ) :
if config_key in terminal_config :
2026-02-16 19:47:23 -08:00
if _file_has_terminal_config or env_var not in os . environ :
2026-02-28 07:12:48 +10:00
val = terminal_config [ config_key ]
if isinstance ( val , list ) :
import json
os . environ [ env_var ] = json . dumps ( val )
else :
os . environ [ env_var ] = str ( val )
2026-01-31 06:30:48 +00:00
2026-01-31 21:42:15 -08:00
# Apply browser config to environment variables
browser_config = defaults . get ( " browser " , { } )
browser_env_mappings = {
" inactivity_timeout " : " BROWSER_INACTIVITY_TIMEOUT " ,
}
for config_key , env_var in browser_env_mappings . items ( ) :
if config_key in browser_config :
os . environ [ env_var ] = str ( browser_config [ config_key ] )
2026-02-01 18:01:31 -08:00
# Apply compression config to environment variables
compression_config = defaults . get ( " compression " , { } )
compression_env_mappings = {
" enabled " : " CONTEXT_COMPRESSION_ENABLED " ,
" threshold " : " CONTEXT_COMPRESSION_THRESHOLD " ,
" summary_model " : " CONTEXT_COMPRESSION_MODEL " ,
2026-03-07 08:52:06 -08:00
" summary_provider " : " CONTEXT_COMPRESSION_PROVIDER " ,
2026-02-01 18:01:31 -08:00
}
for config_key , env_var in compression_env_mappings . items ( ) :
if config_key in compression_config :
os . environ [ env_var ] = str ( compression_config [ config_key ] )
2026-03-07 08:52:06 -08:00
# Apply auxiliary model overrides to environment variables.
# Vision and web_extract each have their own provider + model pair.
# (Compression is handled in the compression section above.)
# Only set env vars for non-empty / non-default values so auto-detection
# still works.
auxiliary_config = defaults . get ( " auxiliary " , { } )
auxiliary_task_env = {
# config key → (provider env var, model env var)
" vision " : ( " AUXILIARY_VISION_PROVIDER " , " AUXILIARY_VISION_MODEL " ) ,
" web_extract " : ( " AUXILIARY_WEB_EXTRACT_PROVIDER " , " AUXILIARY_WEB_EXTRACT_MODEL " ) ,
}
for task_key , ( prov_env , model_env ) in auxiliary_task_env . items ( ) :
task_cfg = auxiliary_config . get ( task_key , { } )
if not isinstance ( task_cfg , dict ) :
continue
prov = str ( task_cfg . get ( " provider " , " " ) ) . strip ( )
model = str ( task_cfg . get ( " model " , " " ) ) . strip ( )
if prov and prov != " auto " :
os . environ [ prov_env ] = prov
if model :
os . environ [ model_env ] = model
2026-03-09 01:04:33 -07:00
# Security settings
security_config = defaults . get ( " security " , { } )
if isinstance ( security_config , dict ) :
redact = security_config . get ( " redact_secrets " )
if redact is not None :
os . environ [ " HERMES_REDACT_SECRETS " ] = str ( redact ) . lower ( )
2026-01-31 06:30:48 +00:00
return defaults
# Load configuration at module startup
CLI_CONFIG = load_cli_config ( )
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
# Initialize the skin engine from config
try :
from hermes_cli . skin_engine import init_skin_from_config
init_skin_from_config ( CLI_CONFIG )
except Exception :
pass # Skin engine is optional — default skin used if unavailable
2026-03-10 15:59:08 -07:00
from rich import box as rich_box
2026-02-20 23:23:32 -08:00
from rich . console import Console
2026-01-31 06:30:48 +00:00
from rich . panel import Panel
from rich . table import Table
import fire
# Import the agent and tool systems
from run_agent import AIAgent
2026-02-20 23:23:32 -08:00
from model_tools import get_tool_definitions , get_toolset_for_tool
2026-02-21 23:17:18 -08:00
# Extracted CLI modules (Phase 3)
from hermes_cli . banner import (
cprint as _cprint , _GOLD , _BOLD , _DIM , _RST ,
VERSION , HERMES_AGENT_LOGO , HERMES_CADUCEUS , COMPACT_BANNER ,
get_available_skills as _get_available_skills ,
build_welcome_banner ,
)
from hermes_cli . commands import COMMANDS , SlashCommandCompleter
from hermes_cli import callbacks as _callbacks
2026-01-31 06:30:48 +00:00
from toolsets import get_all_toolsets , get_toolset_info , resolve_toolset , validate_toolset
2026-02-21 16:21:19 -08:00
# Cron job system for scheduled tasks (CRUD only — execution is handled by the gateway)
from cron import create_job , list_jobs , remove_job , get_job
2026-02-02 08:26:42 -08:00
2026-02-08 13:31:45 -08:00
# Resource cleanup imports for safe shutdown (terminal VMs, browser sessions)
from tools . terminal_tool import cleanup_all_environments as _cleanup_all_terminals
2026-02-21 12:15:40 -08:00
from tools . terminal_tool import set_sudo_password_callback , set_approval_callback
2026-02-08 13:31:45 -08:00
from tools . browser_tool import _emergency_cleanup_all_sessions as _cleanup_all_browsers
2026-02-16 02:43:45 -08:00
# Guard to prevent cleanup from running multiple times on exit
_cleanup_done = False
def _run_cleanup ( ) :
""" Run resource cleanup exactly once. """
global _cleanup_done
if _cleanup_done :
return
_cleanup_done = True
try :
_cleanup_all_terminals ( )
except Exception :
pass
try :
_cleanup_all_browsers ( )
except Exception :
pass
feat: add MCP (Model Context Protocol) client support
Connect to external MCP servers via stdio transport, discover their tools
at startup, and register them into the hermes-agent tool registry.
- New tools/mcp_tool.py: config loading, server connection via background
event loop, tool handler factories, discovery, and graceful shutdown
- model_tools.py: trigger MCP discovery after built-in tool imports
- cli.py: call shutdown_mcp_servers in _run_cleanup
- pyproject.toml: add mcp>=1.2.0 as optional dependency
- 27 unit tests covering config, schema conversion, handlers, registration,
SDK interaction, toolset injection, graceful fallback, and shutdown
Config format (in ~/.hermes/config.yaml):
mcp_servers:
filesystem:
command: "npx"
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
2026-03-02 21:03:14 +03:00
try :
from tools . mcp_tool import shutdown_mcp_servers
shutdown_mcp_servers ( )
except Exception :
pass
2026-02-16 02:43:45 -08:00
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
# =============================================================================
# Git Worktree Isolation (#652)
# =============================================================================
# Tracks the active worktree for cleanup on exit
_active_worktree : Optional [ Dict [ str , str ] ] = None
def _git_repo_root ( ) - > Optional [ str ] :
""" Return the git repo root for CWD, or None if not in a repo. """
import subprocess
try :
result = subprocess . run (
[ " git " , " rev-parse " , " --show-toplevel " ] ,
capture_output = True , text = True , timeout = 5 ,
)
if result . returncode == 0 :
return result . stdout . strip ( )
except Exception :
pass
return None
def _setup_worktree ( repo_root : str = None ) - > Optional [ Dict [ str , str ] ] :
""" Create an isolated git worktree for this CLI session.
Returns a dict with worktree metadata on success , None on failure .
The dict contains : path , branch , repo_root .
"""
import subprocess
repo_root = repo_root or _git_repo_root ( )
if not repo_root :
2026-03-08 17:22:24 -07:00
print ( " \033 [31m✗ --worktree requires being inside a git repository. \033 [0m " )
print ( " cd into your project repo first, then run hermes -w " )
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
return None
short_id = uuid . uuid4 ( ) . hex [ : 8 ]
wt_name = f " hermes- { short_id } "
branch_name = f " hermes/ { wt_name } "
worktrees_dir = Path ( repo_root ) / " .worktrees "
worktrees_dir . mkdir ( parents = True , exist_ok = True )
wt_path = worktrees_dir / wt_name
# Ensure .worktrees/ is in .gitignore
gitignore = Path ( repo_root ) / " .gitignore "
_ignore_entry = " .worktrees/ "
try :
existing = gitignore . read_text ( ) if gitignore . exists ( ) else " "
if _ignore_entry not in existing . splitlines ( ) :
with open ( gitignore , " a " ) as f :
if existing and not existing . endswith ( " \n " ) :
f . write ( " \n " )
f . write ( f " { _ignore_entry } \n " )
except Exception as e :
logger . debug ( " Could not update .gitignore: %s " , e )
# Create the worktree
2026-03-07 21:05:40 -08:00
try :
result = subprocess . run (
[ " git " , " worktree " , " add " , str ( wt_path ) , " -b " , branch_name , " HEAD " ] ,
capture_output = True , text = True , timeout = 30 , cwd = repo_root ,
)
if result . returncode != 0 :
print ( f " \033 [31m✗ Failed to create worktree: { result . stderr . strip ( ) } \033 [0m " )
return None
except Exception as e :
print ( f " \033 [31m✗ Failed to create worktree: { e } \033 [0m " )
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
return None
# Copy files listed in .worktreeinclude (gitignored files the agent needs)
include_file = Path ( repo_root ) / " .worktreeinclude "
if include_file . exists ( ) :
try :
for line in include_file . read_text ( ) . splitlines ( ) :
entry = line . strip ( )
if not entry or entry . startswith ( " # " ) :
continue
src = Path ( repo_root ) / entry
dst = wt_path / entry
if src . is_file ( ) :
dst . parent . mkdir ( parents = True , exist_ok = True )
shutil . copy2 ( str ( src ) , str ( dst ) )
elif src . is_dir ( ) :
# Symlink directories (faster, saves disk)
if not dst . exists ( ) :
dst . parent . mkdir ( parents = True , exist_ok = True )
os . symlink ( str ( src . resolve ( ) ) , str ( dst ) )
except Exception as e :
logger . debug ( " Error copying .worktreeinclude entries: %s " , e )
info = {
" path " : str ( wt_path ) ,
" branch " : branch_name ,
" repo_root " : repo_root ,
}
print ( f " \033 [32m✓ Worktree created: \033 [0m { wt_path } " )
print ( f " Branch: { branch_name } " )
return info
def _cleanup_worktree ( info : Dict [ str , str ] = None ) - > None :
""" Remove a worktree and its branch on exit.
If the worktree has uncommitted changes , warn and keep it .
"""
global _active_worktree
info = info or _active_worktree
if not info :
return
import subprocess
wt_path = info [ " path " ]
branch = info [ " branch " ]
repo_root = info [ " repo_root " ]
if not Path ( wt_path ) . exists ( ) :
return
# Check for uncommitted changes
try :
status = subprocess . run (
[ " git " , " status " , " --porcelain " ] ,
capture_output = True , text = True , timeout = 10 , cwd = wt_path ,
)
has_changes = bool ( status . stdout . strip ( ) )
except Exception :
has_changes = True # Assume dirty on error — don't delete
if has_changes :
print ( f " \n \033 [33m⚠ Worktree has uncommitted changes, keeping: { wt_path } \033 [0m " )
print ( f " To clean up manually: git worktree remove { wt_path } " )
_active_worktree = None
return
# Remove worktree
try :
subprocess . run (
[ " git " , " worktree " , " remove " , wt_path , " --force " ] ,
capture_output = True , text = True , timeout = 15 , cwd = repo_root ,
)
except Exception as e :
logger . debug ( " Failed to remove worktree: %s " , e )
# Delete the branch (only if it was never pushed / has no upstream)
try :
subprocess . run (
[ " git " , " branch " , " -D " , branch ] ,
capture_output = True , text = True , timeout = 10 , cwd = repo_root ,
)
except Exception as e :
logger . debug ( " Failed to delete branch %s : %s " , branch , e )
_active_worktree = None
print ( f " \033 [32m✓ Worktree cleaned up: { wt_path } \033 [0m " )
2026-03-07 21:05:40 -08:00
def _prune_stale_worktrees ( repo_root : str , max_age_hours : int = 24 ) - > None :
""" Remove worktrees older than max_age_hours that have no uncommitted changes.
Runs silently on startup to clean up after crashed / killed sessions .
"""
import subprocess
import time
worktrees_dir = Path ( repo_root ) / " .worktrees "
if not worktrees_dir . exists ( ) :
return
now = time . time ( )
cutoff = now - ( max_age_hours * 3600 )
for entry in worktrees_dir . iterdir ( ) :
if not entry . is_dir ( ) or not entry . name . startswith ( " hermes- " ) :
continue
# Check age
try :
mtime = entry . stat ( ) . st_mtime
if mtime > cutoff :
continue # Too recent — skip
except Exception :
continue
# Check for uncommitted changes
try :
status = subprocess . run (
[ " git " , " status " , " --porcelain " ] ,
capture_output = True , text = True , timeout = 5 , cwd = str ( entry ) ,
)
if status . stdout . strip ( ) :
continue # Has changes — skip
except Exception :
continue # Can't check — skip
# Safe to remove
try :
branch_result = subprocess . run (
[ " git " , " branch " , " --show-current " ] ,
capture_output = True , text = True , timeout = 5 , cwd = str ( entry ) ,
)
branch = branch_result . stdout . strip ( )
subprocess . run (
[ " git " , " worktree " , " remove " , str ( entry ) , " --force " ] ,
capture_output = True , text = True , timeout = 15 , cwd = repo_root ,
)
if branch :
subprocess . run (
[ " git " , " branch " , " -D " , branch ] ,
capture_output = True , text = True , timeout = 10 , cwd = repo_root ,
)
logger . debug ( " Pruned stale worktree: %s " , entry . name )
except Exception as e :
logger . debug ( " Failed to prune worktree %s : %s " , entry . name , e )
2026-01-31 06:30:48 +00:00
# ============================================================================
# ASCII Art & Branding
# ============================================================================
# Color palette (hex colors for Rich markup):
# - Gold: #FFD700 (headers, highlights)
# - Amber: #FFBF00 (secondary highlights)
# - Bronze: #CD7F32 (tertiary elements)
# - Light: #FFF8DC (text)
# - Dim: #B8860B (muted text)
2026-02-19 01:34:14 -08:00
# ANSI building blocks for conversation display
2026-02-19 01:23:23 -08:00
_GOLD = " \033 [1;33m " # Bold yellow — closest universal match to the gold theme
_BOLD = " \033 [1m "
_DIM = " \033 [2m "
_RST = " \033 [0m "
2026-02-19 01:34:14 -08:00
def _cprint ( text : str ) :
""" Print ANSI-colored text through prompt_toolkit ' s native renderer.
Raw ANSI escapes written via print ( ) are swallowed by patch_stdout ' s
StdoutProxy . Routing through print_formatted_text ( ANSI ( . . . ) ) lets
prompt_toolkit parse the escapes and render real colors .
"""
_pt_print ( _PT_ANSI ( text ) )
2026-02-26 20:29:52 -08:00
class ChatConsole :
""" Rich Console adapter for prompt_toolkit ' s patch_stdout context.
Captures Rich ' s rendered ANSI output and routes it through _cprint
so colors and markup render correctly inside the interactive chat loop .
Drop - in replacement for Rich Console — just pass this to any function
that expects a console . print ( ) interface .
"""
def __init__ ( self ) :
from io import StringIO
self . _buffer = StringIO ( )
self . _inner = Console ( file = self . _buffer , force_terminal = True , highlight = False )
def print ( self , * args , * * kwargs ) :
self . _buffer . seek ( 0 )
self . _buffer . truncate ( )
2026-03-10 07:04:02 -07:00
# Read terminal width at render time so panels adapt to current size
self . _inner . width = shutil . get_terminal_size ( ( 80 , 24 ) ) . columns
2026-02-26 20:29:52 -08:00
self . _inner . print ( * args , * * kwargs )
output = self . _buffer . getvalue ( )
for line in output . rstrip ( " \n " ) . split ( " \n " ) :
_cprint ( line )
2026-01-31 06:30:48 +00:00
# ASCII Art - HERMES-AGENT logo (full width, single line - requires ~95 char terminal)
HERMES_AGENT_LOGO = """ [bold #FFD700]██╗ ██╗███████╗██████╗ ███╗ ███╗███████╗███████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗[/]
[ bold #FFD700]██║ ██║██╔════╝██╔══██╗████╗ ████║██╔════╝██╔════╝ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝[/]
[ #FFBF00]███████║█████╗ ██████╔╝██╔████╔██║█████╗ ███████╗█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║[/]
[ #FFBF00]██╔══██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══╝ ╚════██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║[/]
[ #CD7F32]██║ ██║███████╗██║ ██║██║ ╚═╝ ██║███████╗███████║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║[/]
[ #CD7F32]╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝[/]"""
# ASCII Art - Hermes Caduceus (compact, fits in left panel)
HERMES_CADUCEUS = """ [#CD7F32]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⣀⣀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #CD7F32]⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣇⠸⣿⣿⠇⣸⣿⣿⣷⣦⣄⡀⠀⠀⠀⠀⠀⠀[/]
[ #FFBF00]⠀⢀⣠⣴⣶⠿⠋⣩⡿⣿⡿⠻⣿⡇⢠⡄⢸⣿⠟⢿⣿⢿⣍⠙⠿⣶⣦⣄⡀⠀[/]
[ #FFBF00]⠀⠀⠉⠉⠁⠶⠟⠋⠀⠉⠀⢀⣈⣁⡈⢁⣈⣁⡀⠀⠉⠀⠙⠻⠶⠈⠉⠉⠀⠀[/]
[ #FFD700]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⡿⠛⢁⡈⠛⢿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #FFD700]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣿⣦⣤⣈⠁⢠⣴⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #FFBF00]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠻⢿⣿⣦⡉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #FFBF00]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢷⣦⣈⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #CD7F32]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣴⠦⠈⠙⠿⣦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #CD7F32]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣤⡈⠁⢤⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #B8860B]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠷⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #B8860B]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠑⢶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #B8860B]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⢰⡆⠈⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #B8860B]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⠈⣡⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
[ #B8860B]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]"""
# Compact banner for smaller terminals (fallback)
2026-03-09 05:57:23 -07:00
# Note: built dynamically by _build_compact_banner() to fit terminal width
2026-01-31 06:30:48 +00:00
COMPACT_BANNER = """
[ bold #FFD700]╔══════════════════════════════════════════════════════════════╗[/]
[ bold #FFD700]║[/] [#FFBF00]⚕ NOUS HERMES[/] [dim #B8860B]- AI Agent Framework[/] [bold #FFD700]║[/]
[ bold #FFD700]║[/] [#CD7F32]Messenger of the Digital Gods[/] [dim #B8860B]Nous Research[/] [bold #FFD700]║[/]
[ bold #FFD700]╚══════════════════════════════════════════════════════════════╝[/]
"""
2026-03-09 05:57:23 -07:00
def _build_compact_banner ( ) - > str :
""" Build a compact banner that fits the current terminal width. """
w = min ( shutil . get_terminal_size ( ) . columns - 2 , 64 )
if w < 30 :
return " \n [#FFBF00]⚕ NOUS HERMES[/] [dim #B8860B]- Nous Research[/] \n "
inner = w - 2 # inside the box border
bar = " ═ " * w
line1 = " ⚕ NOUS HERMES - AI Agent Framework "
line2 = " Messenger of the Digital Gods · Nous Research "
# Truncate and pad to fit
line1 = line1 [ : inner - 2 ] . ljust ( inner - 2 )
line2 = line2 [ : inner - 2 ] . ljust ( inner - 2 )
return (
f " \n [bold #FFD700]╔ { bar } ╗[/] \n "
f " [bold #FFD700]║[/] [#FFBF00] { line1 } [/] [bold #FFD700]║[/] \n "
f " [bold #FFD700]║[/] [dim #B8860B] { line2 } [/] [bold #FFD700]║[/] \n "
f " [bold #FFD700]╚ { bar } ╝[/] \n "
)
2026-01-31 06:30:48 +00:00
def _get_available_skills ( ) - > Dict [ str , List [ str ] ] :
"""
2026-02-19 18:25:53 -08:00
Scan ~ / . hermes / skills / and return skills grouped by category .
2026-01-31 06:30:48 +00:00
Returns :
Dict mapping category name to list of skill names
"""
2026-02-19 18:25:53 -08:00
import os
hermes_home = Path ( os . getenv ( " HERMES_HOME " , Path . home ( ) / " .hermes " ) )
skills_dir = hermes_home / " skills "
2026-01-31 06:30:48 +00:00
skills_by_category = { }
if not skills_dir . exists ( ) :
return skills_by_category
for skill_file in skills_dir . rglob ( " SKILL.md " ) :
rel_path = skill_file . relative_to ( skills_dir )
parts = rel_path . parts
if len ( parts ) > = 2 :
category = parts [ 0 ]
2026-02-19 18:25:53 -08:00
skill_name = parts [ - 2 ]
2026-01-31 06:30:48 +00:00
else :
category = " general "
skill_name = skill_file . parent . name
2026-02-19 18:25:53 -08:00
skills_by_category . setdefault ( category , [ ] ) . append ( skill_name )
2026-01-31 06:30:48 +00:00
return skills_by_category
2026-03-05 16:09:57 -08:00
def _format_context_length ( tokens : int ) - > str :
""" Format a token count for display (e.g. 128000 → ' 128K ' , 1048576 → ' 1M ' ). """
if tokens > = 1_000_000 :
val = tokens / 1_000_000
return f " { val : g } M "
elif tokens > = 1_000 :
val = tokens / 1_000
return f " { val : g } K "
return str ( tokens )
def build_welcome_banner ( console : Console , model : str , cwd : str , tools : List [ dict ] = None , enabled_toolsets : List [ str ] = None , session_id : str = None , context_length : int = None ) :
2026-01-31 06:30:48 +00:00
"""
Build and print a Claude Code - style welcome banner with caduceus on left and info on right .
Args :
console : Rich Console instance for printing
model : The current model name ( e . g . , " anthropic/claude-opus-4 " )
cwd : Current working directory
tools : List of tool definitions
enabled_toolsets : List of enabled toolset names
2026-02-01 15:36:26 -08:00
session_id : Unique session identifier for logging
2026-03-05 16:09:57 -08:00
context_length : Model ' s context window size in tokens
2026-01-31 06:30:48 +00:00
"""
2026-02-02 23:46:41 -08:00
from model_tools import check_tool_availability , TOOLSET_REQUIREMENTS
2026-01-31 06:30:48 +00:00
tools = tools or [ ]
enabled_toolsets = enabled_toolsets or [ ]
2026-02-02 23:46:41 -08:00
# Get unavailable tools info for coloring
_ , unavailable_toolsets = check_tool_availability ( quiet = True )
disabled_tools = set ( )
for item in unavailable_toolsets :
disabled_tools . update ( item . get ( " tools " , [ ] ) )
2026-01-31 06:30:48 +00:00
# Build the side-by-side content using a table for precise control
layout_table = Table . grid ( padding = ( 0 , 2 ) )
layout_table . add_column ( " left " , justify = " center " )
layout_table . add_column ( " right " , justify = " left " )
# Build left content: caduceus + model info
2026-03-10 00:58:42 -07:00
# Resolve skin colors for the banner
try :
from hermes_cli . skin_engine import get_active_skin
_bskin = get_active_skin ( )
_accent = _bskin . get_color ( " banner_accent " , " #FFBF00 " )
_dim = _bskin . get_color ( " banner_dim " , " #B8860B " )
_text = _bskin . get_color ( " banner_text " , " #FFF8DC " )
_session_c = _bskin . get_color ( " session_border " , " #8B8682 " )
_title_c = _bskin . get_color ( " banner_title " , " #FFD700 " )
_border_c = _bskin . get_color ( " banner_border " , " #CD7F32 " )
_agent_name = _bskin . get_branding ( " agent_name " , " Hermes Agent " )
except Exception :
feat: add poseidon/sisyphus/charizard skins + banner logo support
Adds 3 new built-in skins (poseidon, sisyphus, charizard) with full
customization — colors, spinner faces/verbs/wings, branding text, and
custom ASCII art banner logos. Total: 7 built-in skins.
Also adds banner_logo and banner_hero fields to SkinConfig, allowing
any skin to replace the HERMES-AGENT ASCII art logo and the caduceus
hero art with custom artwork. The CLI now renders the skin's logo when
available, falling back to the default Hermes logo.
Skins with custom logos: ares, poseidon, sisyphus, charizard
Skins using default logo: default, mono, slate
2026-03-10 02:11:50 -07:00
_bskin = None
2026-03-10 00:58:42 -07:00
_accent , _dim , _text = " #FFBF00 " , " #B8860B " , " #FFF8DC "
_session_c , _title_c , _border_c = " #8B8682 " , " #FFD700 " , " #CD7F32 "
_agent_name = " Hermes Agent "
feat: add poseidon/sisyphus/charizard skins + banner logo support
Adds 3 new built-in skins (poseidon, sisyphus, charizard) with full
customization — colors, spinner faces/verbs/wings, branding text, and
custom ASCII art banner logos. Total: 7 built-in skins.
Also adds banner_logo and banner_hero fields to SkinConfig, allowing
any skin to replace the HERMES-AGENT ASCII art logo and the caduceus
hero art with custom artwork. The CLI now renders the skin's logo when
available, falling back to the default Hermes logo.
Skins with custom logos: ares, poseidon, sisyphus, charizard
Skins using default logo: default, mono, slate
2026-03-10 02:11:50 -07:00
_hero = _bskin . banner_hero if hasattr ( _bskin , ' banner_hero ' ) and _bskin . banner_hero else HERMES_CADUCEUS
left_lines = [ " " , _hero , " " ]
2026-01-31 06:30:48 +00:00
# Shorten model name for display
model_short = model . split ( " / " ) [ - 1 ] if " / " in model else model
if len ( model_short ) > 28 :
model_short = model_short [ : 25 ] + " ... "
2026-03-10 00:58:42 -07:00
ctx_str = f " [dim { _dim } ]·[/] [dim { _dim } ] { _format_context_length ( context_length ) } context[/] " if context_length else " "
left_lines . append ( f " [ { _accent } ] { model_short } [/] { ctx_str } [dim { _dim } ]·[/] [dim { _dim } ]Nous Research[/] " )
left_lines . append ( f " [dim { _dim } ] { cwd } [/] " )
2026-02-01 15:36:26 -08:00
# Add session ID if provided
if session_id :
2026-03-10 00:58:42 -07:00
left_lines . append ( f " [dim { _session_c } ]Session: { session_id } [/] " )
2026-01-31 06:30:48 +00:00
left_content = " \n " . join ( left_lines )
# Build right content: tools list grouped by toolset
right_lines = [ ]
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [bold { _accent } ]Available Tools[/] " )
2026-01-31 06:30:48 +00:00
2026-02-02 23:46:41 -08:00
# Group tools by toolset (include all possible tools, both enabled and disabled)
2026-01-31 06:30:48 +00:00
toolsets_dict = { }
2026-02-02 23:46:41 -08:00
# First, add all enabled tools
2026-01-31 06:30:48 +00:00
for tool in tools :
tool_name = tool [ " function " ] [ " name " ]
toolset = get_toolset_for_tool ( tool_name ) or " other "
if toolset not in toolsets_dict :
toolsets_dict [ toolset ] = [ ]
toolsets_dict [ toolset ] . append ( tool_name )
2026-02-02 23:46:41 -08:00
# Also add disabled toolsets so they show in the banner
for item in unavailable_toolsets :
# Map the internal toolset ID to display name
2026-02-23 14:55:29 -08:00
toolset_id = item . get ( " id " , item . get ( " name " , " unknown " ) )
2026-02-02 23:46:41 -08:00
display_name = f " { toolset_id } _tools " if not toolset_id . endswith ( " _tools " ) else toolset_id
if display_name not in toolsets_dict :
toolsets_dict [ display_name ] = [ ]
for tool_name in item . get ( " tools " , [ ] ) :
if tool_name not in toolsets_dict [ display_name ] :
toolsets_dict [ display_name ] . append ( tool_name )
2026-01-31 06:30:48 +00:00
# Display tools grouped by toolset (compact format, max 8 groups)
sorted_toolsets = sorted ( toolsets_dict . keys ( ) )
display_toolsets = sorted_toolsets [ : 8 ]
remaining_toolsets = len ( sorted_toolsets ) - 8
for toolset in display_toolsets :
tool_names = toolsets_dict [ toolset ]
2026-02-02 23:46:41 -08:00
# Color each tool name - red if disabled, normal if enabled
colored_names = [ ]
for name in sorted ( tool_names ) :
if name in disabled_tools :
colored_names . append ( f " [red] { name } [/] " )
else :
2026-03-10 00:58:42 -07:00
colored_names . append ( f " [ { _text } ] { name } [/] " )
2026-02-02 23:46:41 -08:00
tools_str = " , " . join ( colored_names )
# Truncate if too long (accounting for markup)
if len ( " , " . join ( sorted ( tool_names ) ) ) > 45 :
# Rebuild with truncation
short_names = [ ]
length = 0
for name in sorted ( tool_names ) :
if length + len ( name ) + 2 > 42 :
short_names . append ( " ... " )
break
short_names . append ( name )
length + = len ( name ) + 2
# Re-color the truncated list
colored_names = [ ]
for name in short_names :
if name == " ... " :
colored_names . append ( " [dim]...[/] " )
elif name in disabled_tools :
colored_names . append ( f " [red] { name } [/] " )
else :
2026-03-10 00:58:42 -07:00
colored_names . append ( f " [ { _text } ] { name } [/] " )
2026-02-02 23:46:41 -08:00
tools_str = " , " . join ( colored_names )
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [dim { _dim } ] { toolset } :[/] { tools_str } " )
2026-01-31 06:30:48 +00:00
if remaining_toolsets > 0 :
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [dim { _dim } ](and { remaining_toolsets } more toolsets...)[/] " )
2026-01-31 06:30:48 +00:00
right_lines . append ( " " )
# Add skills section
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [bold { _accent } ]Available Skills[/] " )
2026-01-31 06:30:48 +00:00
skills_by_category = _get_available_skills ( )
total_skills = sum ( len ( s ) for s in skills_by_category . values ( ) )
if skills_by_category :
for category in sorted ( skills_by_category . keys ( ) ) :
skill_names = sorted ( skills_by_category [ category ] )
# Show first 8 skills, then "..." if more
if len ( skill_names ) > 8 :
display_names = skill_names [ : 8 ]
skills_str = " , " . join ( display_names ) + f " + { len ( skill_names ) - 8 } more "
else :
skills_str = " , " . join ( skill_names )
# Truncate if still too long
if len ( skills_str ) > 50 :
skills_str = skills_str [ : 47 ] + " ... "
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [dim { _dim } ] { category } :[/] [ { _text } ] { skills_str } [/] " )
2026-01-31 06:30:48 +00:00
else :
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [dim { _dim } ]No skills installed[/] " )
2026-01-31 06:30:48 +00:00
right_lines . append ( " " )
2026-03-10 00:58:42 -07:00
right_lines . append ( f " [dim { _dim } ] { len ( tools ) } tools · { total_skills } skills · /help for commands[/] " )
2026-01-31 06:30:48 +00:00
right_content = " \n " . join ( right_lines )
# Add to table
layout_table . add_row ( left_content , right_content )
# Wrap in a panel with the title
outer_panel = Panel (
layout_table ,
2026-03-10 00:58:42 -07:00
title = f " [bold { _title_c } ] { _agent_name } { VERSION } [/] " ,
border_style = _border_c ,
2026-01-31 06:30:48 +00:00
padding = ( 0 , 2 ) ,
)
feat: add poseidon/sisyphus/charizard skins + banner logo support
Adds 3 new built-in skins (poseidon, sisyphus, charizard) with full
customization — colors, spinner faces/verbs/wings, branding text, and
custom ASCII art banner logos. Total: 7 built-in skins.
Also adds banner_logo and banner_hero fields to SkinConfig, allowing
any skin to replace the HERMES-AGENT ASCII art logo and the caduceus
hero art with custom artwork. The CLI now renders the skin's logo when
available, falling back to the default Hermes logo.
Skins with custom logos: ares, poseidon, sisyphus, charizard
Skins using default logo: default, mono, slate
2026-03-10 02:11:50 -07:00
# Print the big logo — use skin's custom logo if available
2026-01-31 06:30:48 +00:00
console . print ( )
2026-03-09 05:57:23 -07:00
term_width = shutil . get_terminal_size ( ) . columns
if term_width > = 95 :
feat: add poseidon/sisyphus/charizard skins + banner logo support
Adds 3 new built-in skins (poseidon, sisyphus, charizard) with full
customization — colors, spinner faces/verbs/wings, branding text, and
custom ASCII art banner logos. Total: 7 built-in skins.
Also adds banner_logo and banner_hero fields to SkinConfig, allowing
any skin to replace the HERMES-AGENT ASCII art logo and the caduceus
hero art with custom artwork. The CLI now renders the skin's logo when
available, falling back to the default Hermes logo.
Skins with custom logos: ares, poseidon, sisyphus, charizard
Skins using default logo: default, mono, slate
2026-03-10 02:11:50 -07:00
_logo = _bskin . banner_logo if hasattr ( _bskin , ' banner_logo ' ) and _bskin . banner_logo else HERMES_AGENT_LOGO
console . print ( _logo )
2026-03-09 05:57:23 -07:00
console . print ( )
2026-01-31 06:30:48 +00:00
# Print the panel with caduceus and info
console . print ( outer_panel )
2026-02-28 11:18:50 -08:00
# ============================================================================
# Skill Slash Commands — dynamic commands generated from installed skills
# ============================================================================
from agent . skill_commands import scan_skill_commands , get_skill_commands , build_skill_invocation_message
_skill_commands = scan_skill_commands ( )
2026-01-31 06:30:48 +00:00
def save_config_value ( key_path : str , value : any ) - > bool :
"""
2026-02-10 15:59:46 -08:00
Save a value to the active config file at the specified key path .
Respects the same lookup order as load_cli_config ( ) :
1. ~ / . hermes / config . yaml ( user config - preferred , used if it exists )
2. . / cli - config . yaml ( project config - fallback )
2026-01-31 06:30:48 +00:00
Args :
key_path : Dot - separated path like " agent.system_prompt "
value : Value to save
Returns :
True if successful , False otherwise
"""
2026-02-10 15:59:46 -08:00
# Use the same precedence as load_cli_config: user config first, then project config
user_config_path = Path . home ( ) / ' .hermes ' / ' config.yaml '
project_config_path = Path ( __file__ ) . parent / ' cli-config.yaml '
config_path = user_config_path if user_config_path . exists ( ) else project_config_path
2026-01-31 06:30:48 +00:00
try :
2026-02-10 15:59:46 -08:00
# Ensure parent directory exists (for ~/.hermes/config.yaml on first use)
config_path . parent . mkdir ( parents = True , exist_ok = True )
2026-01-31 06:30:48 +00:00
# Load existing config
if config_path . exists ( ) :
with open ( config_path , ' r ' ) as f :
config = yaml . safe_load ( f ) or { }
else :
config = { }
# Navigate to the key and set value
keys = key_path . split ( ' . ' )
current = config
for key in keys [ : - 1 ] :
2026-02-26 23:35:00 +03:00
if key not in current or not isinstance ( current [ key ] , dict ) :
2026-01-31 06:30:48 +00:00
current [ key ] = { }
current = current [ key ]
current [ keys [ - 1 ] ] = value
# Save back
with open ( config_path , ' w ' ) as f :
yaml . dump ( config , f , default_flow_style = False , sort_keys = False )
return True
except Exception as e :
2026-02-21 03:11:11 -08:00
logger . error ( " Failed to save config: %s " , e )
2026-01-31 06:30:48 +00:00
return False
# ============================================================================
# HermesCLI Class
# ============================================================================
class HermesCLI :
"""
Interactive CLI for the Hermes Agent .
Provides a REPL interface with rich formatting , command history ,
and tool execution capabilities .
"""
def __init__ (
self ,
model : str = None ,
toolsets : List [ str ] = None ,
2026-02-20 17:24:00 -08:00
provider : str = None ,
2026-01-31 06:30:48 +00:00
api_key : str = None ,
base_url : str = None ,
2026-02-26 23:43:38 +03:00
max_turns : int = None ,
2026-01-31 06:30:48 +00:00
verbose : bool = False ,
compact : bool = False ,
2026-02-25 22:56:12 -08:00
resume : str = None ,
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
checkpoints : bool = False ,
2026-01-31 06:30:48 +00:00
) :
"""
Initialize the Hermes CLI .
2026-02-26 23:43:38 +03:00
2026-01-31 06:30:48 +00:00
Args :
model : Model to use ( default : from env or claude - sonnet )
toolsets : List of toolsets to enable ( default : all )
feat: add z.ai/GLM, Kimi/Moonshot, MiniMax as first-class providers
Adds 4 new direct API-key providers (zai, kimi-coding, minimax, minimax-cn)
to the inference provider system. All use standard OpenAI-compatible
chat/completions endpoints with Bearer token auth.
Core changes:
- auth.py: Extended ProviderConfig with api_key_env_vars and base_url_env_var
fields. Added providers to PROVIDER_REGISTRY. Added provider aliases
(glm, z-ai, zhipu, kimi, moonshot). Added auto-detection of API-key
providers in resolve_provider(). Added resolve_api_key_provider_credentials()
and get_api_key_provider_status() helpers.
- runtime_provider.py: Added generic API-key provider branch in
resolve_runtime_provider() — any provider with auth_type='api_key'
is automatically handled.
- main.py: Added providers to hermes model menu with generic
_model_flow_api_key_provider() flow. Updated _has_any_provider_configured()
to check all provider env vars. Updated argparse --provider choices.
- setup.py: Added providers to setup wizard with API key prompts and
curated model lists.
- config.py: Added env vars (GLM_API_KEY, KIMI_API_KEY, MINIMAX_API_KEY,
etc.) to OPTIONAL_ENV_VARS.
- status.py: Added API key display and provider status section.
- doctor.py: Added connectivity checks for each provider endpoint.
- cli.py: Updated provider docstrings.
Docs: Updated README.md, .env.example, cli-config.yaml.example,
cli-commands.md, environment-variables.md, configuration.md.
Tests: 50 new tests covering registry, aliases, resolution, auto-detection,
credential resolution, and runtime provider dispatch.
Inspired by PR #33 (numman-ali) which proposed a provider registry approach.
Credit to tars90percent (PR #473) and manuelschipper (PR #420) for related
provider improvements merged earlier in this changeset.
2026-03-06 18:55:12 -08:00
provider : Inference provider ( " auto " , " openrouter " , " nous " , " openai-codex " , " zai " , " kimi-coding " , " minimax " , " minimax-cn " )
2026-01-31 06:30:48 +00:00
api_key : API key ( default : from environment )
base_url : API base URL ( default : OpenRouter )
2026-03-07 08:16:37 -08:00
max_turns : Maximum tool - calling iterations shared with subagents ( default : 90 )
2026-01-31 06:30:48 +00:00
verbose : Enable verbose logging
compact : Use compact display mode
2026-02-25 22:56:12 -08:00
resume : Session ID to resume ( restores conversation history from SQLite )
2026-01-31 06:30:48 +00:00
"""
# Initialize Rich console
self . console = Console ( )
2026-03-11 02:33:25 -07:00
self . config = CLI_CONFIG
2026-01-31 06:30:48 +00:00
self . compact = compact if compact is not None else CLI_CONFIG [ " display " ] . get ( " compact " , False )
2026-02-28 00:05:58 -08:00
# tool_progress: "off", "new", "all", "verbose" (from config.yaml display section)
self . tool_progress_mode = CLI_CONFIG [ " display " ] . get ( " tool_progress " , " all " )
2026-03-08 17:45:45 -07:00
# resume_display: "full" (show history) | "minimal" (one-liner only)
self . resume_display = CLI_CONFIG [ " display " ] . get ( " resume_display " , " full " )
2026-03-08 19:41:17 -07:00
# bell_on_complete: play terminal bell (\a) when agent finishes a response
self . bell_on_complete = CLI_CONFIG [ " display " ] . get ( " bell_on_complete " , False )
2026-02-28 00:05:58 -08:00
self . verbose = verbose if verbose is not None else ( self . tool_progress_mode == " verbose " )
2026-01-31 06:30:48 +00:00
# Configuration - priority: CLI args > env vars > config file
2026-02-02 23:46:41 -08:00
# Model can come from: CLI arg, LLM_MODEL env, OPENAI_MODEL env (custom endpoint), or config
self . model = model or os . getenv ( " LLM_MODEL " ) or os . getenv ( " OPENAI_MODEL " ) or CLI_CONFIG [ " model " ] [ " default " ]
2026-03-08 16:48:56 -07:00
# Track whether model was explicitly chosen by the user or fell back
# to the global default. Provider-specific normalisation may override
# the default silently but should warn when overriding an explicit choice.
self . _model_is_default = not ( model or os . getenv ( " LLM_MODEL " ) or os . getenv ( " OPENAI_MODEL " ) )
2026-02-20 17:24:00 -08:00
2026-02-25 18:20:38 -08:00
self . _explicit_api_key = api_key
self . _explicit_base_url = base_url
# Provider selection is resolved lazily at use-time via _ensure_runtime_credentials().
2026-02-20 17:24:00 -08:00
self . requested_provider = (
provider
or os . getenv ( " HERMES_INFERENCE_PROVIDER " )
or CLI_CONFIG [ " model " ] . get ( " provider " )
or " auto "
)
2026-02-25 18:20:38 -08:00
self . _provider_source : Optional [ str ] = None
self . provider = self . requested_provider
self . api_mode = " chat_completions "
self . base_url = (
base_url
or os . getenv ( " OPENAI_BASE_URL " )
or os . getenv ( " OPENROUTER_BASE_URL " , CLI_CONFIG [ " model " ] [ " base_url " ] )
2026-02-20 17:24:00 -08:00
)
2026-03-06 17:16:14 -08:00
# Match key to resolved base_url: OpenRouter URL → prefer OPENROUTER_API_KEY,
# custom endpoint → prefer OPENAI_API_KEY (issue #560).
# Note: _ensure_runtime_credentials() re-resolves this before first use.
if " openrouter.ai " in self . base_url :
self . api_key = api_key or os . getenv ( " OPENROUTER_API_KEY " ) or os . getenv ( " OPENAI_API_KEY " )
else :
self . api_key = api_key or os . getenv ( " OPENAI_API_KEY " ) or os . getenv ( " OPENROUTER_API_KEY " )
2026-02-20 17:24:00 -08:00
self . _nous_key_expires_at : Optional [ str ] = None
self . _nous_key_source : Optional [ str ] = None
2026-03-02 01:15:10 -08:00
# Max turns priority: CLI arg > config file > env var > default
2026-02-28 21:47:51 -08:00
if max_turns is not None : # CLI arg was explicitly set
2026-02-03 14:48:19 -08:00
self . max_turns = max_turns
elif CLI_CONFIG [ " agent " ] . get ( " max_turns " ) :
self . max_turns = CLI_CONFIG [ " agent " ] [ " max_turns " ]
elif CLI_CONFIG . get ( " max_turns " ) : # Backwards compat: root-level max_turns
self . max_turns = CLI_CONFIG [ " max_turns " ]
2026-02-28 10:35:49 -08:00
elif os . getenv ( " HERMES_MAX_ITERATIONS " ) :
self . max_turns = int ( os . getenv ( " HERMES_MAX_ITERATIONS " ) )
2026-02-03 14:48:19 -08:00
else :
2026-03-07 08:16:37 -08:00
self . max_turns = 90
2026-01-31 06:30:48 +00:00
# Parse and validate toolsets
self . enabled_toolsets = toolsets
if toolsets and " all " not in toolsets and " * " not in toolsets :
# Validate each toolset
invalid = [ t for t in toolsets if not validate_toolset ( t ) ]
if invalid :
self . console . print ( f " [bold red]Warning: Unknown toolsets: { ' , ' . join ( invalid ) } [/] " )
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
# Filesystem checkpoints: CLI flag > config
cp_cfg = CLI_CONFIG . get ( " checkpoints " , { } )
if isinstance ( cp_cfg , bool ) :
cp_cfg = { " enabled " : cp_cfg }
self . checkpoints_enabled = checkpoints or cp_cfg . get ( " enabled " , False )
self . checkpoint_max_snapshots = cp_cfg . get ( " max_snapshots " , 50 )
2026-02-23 23:55:42 -08:00
# Ephemeral system prompt: env var takes precedence, then config
self . system_prompt = (
os . getenv ( " HERMES_EPHEMERAL_SYSTEM_PROMPT " , " " )
or CLI_CONFIG [ " agent " ] . get ( " system_prompt " , " " )
)
2026-01-31 06:30:48 +00:00
self . personalities = CLI_CONFIG [ " agent " ] . get ( " personalities " , { } )
2026-02-23 23:55:42 -08:00
# Ephemeral prefill messages (few-shot priming, never persisted)
self . prefill_messages = _load_prefill_messages (
CLI_CONFIG [ " agent " ] . get ( " prefill_messages_file " , " " )
)
2026-02-24 03:30:19 -08:00
# Reasoning config (OpenRouter reasoning effort level)
self . reasoning_config = _parse_reasoning_config (
CLI_CONFIG [ " agent " ] . get ( " reasoning_effort " , " " )
)
2026-03-01 18:24:27 -08:00
# OpenRouter provider routing preferences
pr = CLI_CONFIG . get ( " provider_routing " , { } ) or { }
self . _provider_sort = pr . get ( " sort " )
self . _providers_only = pr . get ( " only " )
self . _providers_ignore = pr . get ( " ignore " )
self . _providers_order = pr . get ( " order " )
self . _provider_require_params = pr . get ( " require_parameters " , False )
self . _provider_data_collection = pr . get ( " data_collection " )
feat: simple fallback model for provider resilience
When the primary model/provider fails after retries (rate limit, overload,
auth errors, connection failures), Hermes automatically switches to a
configured fallback model for the remainder of the session.
Config (in ~/.hermes/config.yaml):
fallback_model:
provider: openrouter
model: anthropic/claude-sonnet-4
Supports all major providers: OpenRouter, OpenAI, Nous, DeepSeek, Together,
Groq, Fireworks, Mistral, Gemini — plus custom endpoints via base_url and
api_key_env overrides.
Design principles:
- Dead simple: one fallback model, not a chain
- One-shot: switches once, doesn't ping-pong back
- Zero new dependencies: uses existing OpenAI client
- Minimal code: ~100 lines in run_agent.py, ~5 lines in cli.py/gateway
- Three trigger points: max retries exhausted, non-retryable client errors,
and invalid response exhaustion
Does NOT trigger on context overflow or payload-too-large errors (those
are handled by the existing compression system).
Addresses #737.
25 new tests, 2492 total passing.
2026-03-08 20:22:33 -07:00
# Fallback model config — tried when primary provider fails after retries
fb = CLI_CONFIG . get ( " fallback_model " ) or { }
self . _fallback_model = fb if fb . get ( " provider " ) and fb . get ( " model " ) else None
2026-01-31 06:30:48 +00:00
# Agent will be initialized on first use
self . agent : Optional [ AIAgent ] = None
2026-02-19 20:06:14 -08:00
self . _app = None # prompt_toolkit Application (set in run())
2026-01-31 06:30:48 +00:00
# Conversation state
self . conversation_history : List [ Dict [ str , Any ] ] = [ ]
self . session_start = datetime . now ( )
2026-02-25 22:56:12 -08:00
self . _resumed = False
2026-03-08 15:20:29 -07:00
# Initialize SQLite session store early so /title works before first message
self . _session_db = None
try :
from hermes_state import SessionDB
self . _session_db = SessionDB ( )
except Exception :
pass
# Deferred title: stored in memory until the session is created in the DB
self . _pending_title : Optional [ str ] = None
2026-01-31 06:30:48 +00:00
2026-02-25 22:56:12 -08:00
# Session ID: reuse existing one when resuming, otherwise generate fresh
if resume :
self . session_id = resume
self . _resumed = True
else :
timestamp_str = self . session_start . strftime ( " % Y % m %d _ % H % M % S " )
short_uuid = uuid . uuid4 ( ) . hex [ : 6 ]
self . session_id = f " { timestamp_str } _ { short_uuid } "
2026-02-01 15:36:26 -08:00
2026-02-10 15:59:46 -08:00
# History file for persistent input recall across sessions
self . _history_file = Path . home ( ) / " .hermes_history "
2026-03-02 15:56:53 +01:00
self . _last_invalidate : float = 0.0 # throttle UI repaints
2026-03-09 23:26:43 -07:00
self . _spinner_text : str = " " # thinking spinner text for TUI
2026-03-10 17:13:14 -07:00
self . _command_running = False
self . _command_status = " "
2026-03-02 15:56:53 +01:00
def _invalidate ( self , min_interval : float = 0.25 ) - > None :
""" Throttled UI repaint — prevents terminal blinking on slow/SSH connections. """
import time as _time
now = _time . monotonic ( )
if hasattr ( self , " _app " ) and self . _app and ( now - self . _last_invalidate ) > = min_interval :
self . _last_invalidate = now
self . _app . invalidate ( )
2026-02-20 17:24:00 -08:00
2026-03-08 16:48:56 -07:00
def _normalize_model_for_provider ( self , resolved_provider : str ) - > bool :
2026-03-08 18:16:58 -07:00
""" Strip provider prefixes and swap the default model for Codex.
2026-03-08 16:48:56 -07:00
2026-03-08 18:16:58 -07:00
When the resolved provider is ` ` openai - codex ` ` :
1. Strip any ` ` provider / ` ` prefix ( the Codex Responses API only
accepts bare model slugs like ` ` gpt - 5.4 ` ` , not ` ` openai / gpt - 5.4 ` ` ) .
2. If the active model is still the * untouched default * ( user never
explicitly chose a model ) , replace it with a Codex - compatible
default so the first session doesn ' t immediately error.
If the user explicitly chose a model — * any * model — we trust them
and let the API be the judge . No allowlists , no slug checks .
2026-03-08 16:48:56 -07:00
Returns True when the active model was changed .
"""
if resolved_provider != " openai-codex " :
return False
current_model = ( self . model or " " ) . strip ( )
2026-03-08 18:16:58 -07:00
changed = False
2026-03-08 16:48:56 -07:00
2026-03-08 18:16:58 -07:00
# 1. Strip provider prefix ("openai/gpt-5.4" → "gpt-5.4")
if " / " in current_model :
slug = current_model . split ( " / " , 1 ) [ 1 ]
2026-03-08 16:48:56 -07:00
if not self . _model_is_default :
self . console . print (
2026-03-08 18:16:58 -07:00
f " [yellow]⚠️ Stripped provider prefix from ' { current_model } ' ; "
f " using ' { slug } ' for OpenAI Codex.[/] "
2026-03-08 16:48:56 -07:00
)
2026-03-08 18:16:58 -07:00
self . model = slug
current_model = slug
changed = True
# 2. Replace untouched default with a Codex model
if self . _model_is_default :
fallback_model = " gpt-5.3-codex "
try :
from hermes_cli . codex_models import get_codex_model_ids
available = get_codex_model_ids (
access_token = self . api_key if self . api_key else None ,
)
if available :
fallback_model = available [ 0 ]
except Exception :
pass
2026-03-08 16:48:56 -07:00
2026-03-08 18:16:58 -07:00
if current_model != fallback_model :
self . model = fallback_model
changed = True
return changed
2026-03-08 16:48:56 -07:00
2026-03-09 23:26:43 -07:00
def _on_thinking ( self , text : str ) - > None :
""" Called by agent when thinking starts/stops. Updates TUI spinner. """
self . _spinner_text = text or " "
self . _invalidate ( )
2026-03-10 17:13:14 -07:00
def _slow_command_status ( self , command : str ) - > str :
""" Return a user-facing status message for slower slash commands. """
cmd_lower = command . lower ( ) . strip ( )
if cmd_lower . startswith ( " /skills search " ) :
return " Searching skills... "
if cmd_lower . startswith ( " /skills browse " ) :
return " Loading skills... "
if cmd_lower . startswith ( " /skills inspect " ) :
return " Inspecting skill... "
if cmd_lower . startswith ( " /skills install " ) :
return " Installing skill... "
if cmd_lower . startswith ( " /skills " ) :
return " Processing skills command... "
if cmd_lower == " /reload-mcp " :
return " Reloading MCP servers... "
return " Processing command... "
def _command_spinner_frame ( self ) - > str :
""" Return the current spinner frame for slow slash commands. """
import time as _time
frame_idx = int ( _time . monotonic ( ) * 10 ) % len ( _COMMAND_SPINNER_FRAMES )
return _COMMAND_SPINNER_FRAMES [ frame_idx ]
@contextmanager
def _busy_command ( self , status : str ) :
""" Expose a temporary busy state in the TUI while a slash command runs. """
self . _command_running = True
self . _command_status = status
self . _invalidate ( min_interval = 0.0 )
try :
print ( f " ⏳ { status } " )
yield
finally :
self . _command_running = False
self . _command_status = " "
self . _invalidate ( min_interval = 0.0 )
2026-02-20 17:24:00 -08:00
def _ensure_runtime_credentials ( self ) - > bool :
"""
2026-02-25 18:20:38 -08:00
Ensure runtime credentials are resolved before agent use .
Re - resolves provider credentials so key rotation and token refresh
are picked up without restarting the CLI .
2026-02-20 17:24:00 -08:00
Returns True if credentials are ready , False on auth failure .
"""
2026-02-25 18:20:38 -08:00
from hermes_cli . runtime_provider import (
resolve_runtime_provider ,
format_runtime_provider_error ,
)
2026-02-20 17:24:00 -08:00
try :
2026-02-25 18:20:38 -08:00
runtime = resolve_runtime_provider (
requested = self . requested_provider ,
explicit_api_key = self . _explicit_api_key ,
explicit_base_url = self . _explicit_base_url ,
2026-02-20 17:24:00 -08:00
)
except Exception as exc :
2026-02-25 18:20:38 -08:00
message = format_runtime_provider_error ( exc )
2026-02-20 17:24:00 -08:00
self . console . print ( f " [bold red] { message } [/] " )
return False
2026-02-25 18:20:38 -08:00
api_key = runtime . get ( " api_key " )
base_url = runtime . get ( " base_url " )
resolved_provider = runtime . get ( " provider " , " openrouter " )
resolved_api_mode = runtime . get ( " api_mode " , self . api_mode )
2026-02-20 17:24:00 -08:00
if not isinstance ( api_key , str ) or not api_key :
2026-02-25 18:20:38 -08:00
self . console . print ( " [bold red]Provider resolver returned an empty API key.[/] " )
2026-02-20 17:24:00 -08:00
return False
if not isinstance ( base_url , str ) or not base_url :
2026-02-25 18:20:38 -08:00
self . console . print ( " [bold red]Provider resolver returned an empty base URL.[/] " )
2026-02-20 17:24:00 -08:00
return False
credentials_changed = api_key != self . api_key or base_url != self . base_url
2026-02-25 18:20:38 -08:00
routing_changed = (
resolved_provider != self . provider
or resolved_api_mode != self . api_mode
)
self . provider = resolved_provider
self . api_mode = resolved_api_mode
self . _provider_source = runtime . get ( " source " )
2026-02-20 17:24:00 -08:00
self . api_key = api_key
self . base_url = base_url
2026-03-08 16:48:56 -07:00
# Normalize model for the resolved provider (e.g. swap non-Codex
# models when provider is openai-codex). Fixes #651.
model_changed = self . _normalize_model_for_provider ( resolved_provider )
# AIAgent/OpenAI client holds auth at init time, so rebuild if key,
# routing, or the effective model changed.
if ( credentials_changed or routing_changed or model_changed ) and self . agent is not None :
2026-02-20 17:24:00 -08:00
self . agent = None
return True
2026-01-31 06:30:48 +00:00
def _init_agent ( self ) - > bool :
"""
Initialize the agent on first use .
2026-02-25 22:56:12 -08:00
When resuming a session , restores conversation history from SQLite .
2026-01-31 06:30:48 +00:00
Returns :
bool : True if successful , False otherwise
"""
if self . agent is not None :
return True
2026-02-20 17:24:00 -08:00
2026-02-25 18:20:38 -08:00
if not self . _ensure_runtime_credentials ( ) :
2026-02-20 17:24:00 -08:00
return False
2026-03-08 15:20:29 -07:00
# Initialize SQLite session store for CLI sessions (if not already done in __init__)
if self . _session_db is None :
try :
from hermes_state import SessionDB
self . _session_db = SessionDB ( )
except Exception as e :
logger . debug ( " SQLite session store not available: %s " , e )
2026-02-19 00:57:31 -08:00
2026-03-08 17:45:45 -07:00
# If resuming, validate the session exists and load its history.
# _preload_resumed_session() may have already loaded it (called from
# run() for immediate display). In that case, conversation_history
# is non-empty and we skip the DB round-trip.
if self . _resumed and self . _session_db and not self . conversation_history :
2026-02-25 22:56:12 -08:00
session_meta = self . _session_db . get_session ( self . session_id )
if not session_meta :
_cprint ( f " \033 [1;31mSession not found: { self . session_id } { _RST } " )
_cprint ( f " { _DIM } Use a session ID from a previous CLI run (hermes sessions list). { _RST } " )
return False
restored = self . _session_db . get_messages_as_conversation ( self . session_id )
if restored :
self . conversation_history = restored
msg_count = len ( [ m for m in restored if m . get ( " role " ) == " user " ] )
2026-03-08 15:20:29 -07:00
title_part = " "
if session_meta . get ( " title " ) :
title_part = f " \" { session_meta [ ' title ' ] } \" "
2026-02-25 22:56:12 -08:00
_cprint (
2026-03-08 15:20:29 -07:00
f " { _GOLD } ↻ Resumed session { _BOLD } { self . session_id } { _RST } { _GOLD } { title_part } "
2026-02-25 22:56:12 -08:00
f " ( { msg_count } user message { ' s ' if msg_count != 1 else ' ' } , "
f " { len ( restored ) } total messages) { _RST } "
)
else :
_cprint ( f " { _GOLD } Session { self . session_id } found but has no messages. Starting fresh. { _RST } " )
# Re-open the session (clear ended_at so it's active again)
try :
self . _session_db . _conn . execute (
" UPDATE sessions SET ended_at = NULL, end_reason = NULL WHERE id = ? " ,
( self . session_id , ) ,
)
self . _session_db . _conn . commit ( )
except Exception :
pass
2026-01-31 06:30:48 +00:00
try :
self . agent = AIAgent (
model = self . model ,
api_key = self . api_key ,
base_url = self . base_url ,
2026-02-25 18:20:38 -08:00
provider = self . provider ,
api_mode = self . api_mode ,
2026-01-31 06:30:48 +00:00
max_iterations = self . max_turns ,
enabled_toolsets = self . enabled_toolsets ,
verbose_logging = self . verbose ,
2026-02-23 23:55:42 -08:00
quiet_mode = True ,
2026-01-31 06:30:48 +00:00
ephemeral_system_prompt = self . system_prompt if self . system_prompt else None ,
2026-02-23 23:55:42 -08:00
prefill_messages = self . prefill_messages or None ,
2026-02-24 03:30:19 -08:00
reasoning_config = self . reasoning_config ,
2026-03-01 18:24:27 -08:00
providers_allowed = self . _providers_only ,
providers_ignored = self . _providers_ignore ,
providers_order = self . _providers_order ,
provider_sort = self . _provider_sort ,
provider_require_parameters = self . _provider_require_params ,
provider_data_collection = self . _provider_data_collection ,
2026-02-23 23:55:42 -08:00
session_id = self . session_id ,
platform = " cli " ,
2026-02-19 00:57:31 -08:00
session_db = self . _session_db ,
2026-02-19 20:06:14 -08:00
clarify_callback = self . _clarify_callback ,
2026-02-25 19:34:25 -05:00
honcho_session_key = self . session_id ,
feat: simple fallback model for provider resilience
When the primary model/provider fails after retries (rate limit, overload,
auth errors, connection failures), Hermes automatically switches to a
configured fallback model for the remainder of the session.
Config (in ~/.hermes/config.yaml):
fallback_model:
provider: openrouter
model: anthropic/claude-sonnet-4
Supports all major providers: OpenRouter, OpenAI, Nous, DeepSeek, Together,
Groq, Fireworks, Mistral, Gemini — plus custom endpoints via base_url and
api_key_env overrides.
Design principles:
- Dead simple: one fallback model, not a chain
- One-shot: switches once, doesn't ping-pong back
- Zero new dependencies: uses existing OpenAI client
- Minimal code: ~100 lines in run_agent.py, ~5 lines in cli.py/gateway
- Three trigger points: max retries exhausted, non-retryable client errors,
and invalid response exhaustion
Does NOT trigger on context overflow or payload-too-large errors (those
are handled by the existing compression system).
Addresses #737.
25 new tests, 2492 total passing.
2026-03-08 20:22:33 -07:00
fallback_model = self . _fallback_model ,
2026-03-09 23:26:43 -07:00
thinking_callback = self . _on_thinking ,
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
checkpoints_enabled = self . checkpoints_enabled ,
checkpoint_max_snapshots = self . checkpoint_max_snapshots ,
2026-01-31 06:30:48 +00:00
)
2026-03-08 15:20:29 -07:00
# Apply any pending title now that the session exists in the DB
if self . _pending_title and self . _session_db :
try :
self . _session_db . set_session_title ( self . session_id , self . _pending_title )
_cprint ( f " Session title applied: { self . _pending_title } " )
self . _pending_title = None
except ( ValueError , Exception ) as e :
_cprint ( f " Could not apply pending title: { e } " )
self . _pending_title = None
2026-01-31 06:30:48 +00:00
return True
except Exception as e :
self . console . print ( f " [bold red]Failed to initialize agent: { e } [/] " )
return False
def show_banner ( self ) :
""" Display the welcome banner in Claude Code style. """
self . console . clear ( )
2026-03-09 05:57:23 -07:00
# Auto-compact for narrow terminals — the full banner with caduceus
# + tool list needs ~80 columns minimum to render without wrapping.
term_width = shutil . get_terminal_size ( ) . columns
use_compact = self . compact or term_width < 80
if use_compact :
self . console . print ( _build_compact_banner ( ) )
2026-01-31 06:30:48 +00:00
self . _show_status ( )
else :
# Get tools for display
2026-02-02 19:28:27 -08:00
tools = get_tool_definitions ( enabled_toolsets = self . enabled_toolsets , quiet_mode = True )
2026-01-31 06:30:48 +00:00
# Get terminal working directory (where commands will execute)
cwd = os . getenv ( " TERMINAL_CWD " , os . getcwd ( ) )
2026-03-05 16:09:57 -08:00
# Get context length for display
ctx_len = None
if hasattr ( self , ' agent ' ) and self . agent and hasattr ( self . agent , ' context_compressor ' ) :
ctx_len = self . agent . context_compressor . context_length
2026-01-31 06:30:48 +00:00
# Build and display the banner
build_welcome_banner (
console = self . console ,
model = self . model ,
cwd = cwd ,
tools = tools ,
enabled_toolsets = self . enabled_toolsets ,
2026-02-01 15:36:26 -08:00
session_id = self . session_id ,
2026-03-05 16:09:57 -08:00
context_length = ctx_len ,
2026-01-31 06:30:48 +00:00
)
2026-02-02 19:28:27 -08:00
# Show tool availability warnings if any tools are disabled
self . _show_tool_availability_warnings ( )
2026-01-31 06:30:48 +00:00
self . console . print ( )
2026-03-08 17:45:45 -07:00
def _preload_resumed_session ( self ) - > bool :
""" Load a resumed session ' s history from the DB early (before first chat).
Called from run ( ) so the conversation history is available for display
before the user sends their first message . Sets
` ` self . conversation_history ` ` and prints the one - liner status . Returns
True if history was loaded , False otherwise .
The corresponding block in ` ` _init_agent ( ) ` ` checks whether history is
already populated and skips the DB round - trip .
"""
if not self . _resumed or not self . _session_db :
return False
session_meta = self . _session_db . get_session ( self . session_id )
if not session_meta :
self . console . print (
f " [bold red]Session not found: { self . session_id } [/] "
)
self . console . print (
" [dim]Use a session ID from a previous CLI run "
" (hermes sessions list).[/] "
)
return False
restored = self . _session_db . get_messages_as_conversation ( self . session_id )
if restored :
self . conversation_history = restored
msg_count = len ( [ m for m in restored if m . get ( " role " ) == " user " ] )
title_part = " "
if session_meta . get ( " title " ) :
title_part = f ' " { session_meta [ " title " ] } " '
self . console . print (
f " [#DAA520]↻ Resumed session [bold] { self . session_id } [/bold] "
f " { title_part } "
f " ( { msg_count } user message { ' s ' if msg_count != 1 else ' ' } , "
f " { len ( restored ) } total messages)[/] "
)
else :
self . console . print (
f " [#DAA520]Session { self . session_id } found but has no "
f " messages. Starting fresh.[/] "
)
return False
# Re-open the session (clear ended_at so it's active again)
try :
self . _session_db . _conn . execute (
" UPDATE sessions SET ended_at = NULL, end_reason = NULL "
" WHERE id = ? " ,
( self . session_id , ) ,
)
self . _session_db . _conn . commit ( )
except Exception :
pass
return True
def _display_resumed_history ( self ) :
""" Render a compact recap of previous conversation messages.
Uses Rich markup with dim / muted styling so the recap is visually
distinct from the active conversation . Caps the display at the
last ` ` MAX_DISPLAY_EXCHANGES ` ` user / assistant exchanges and shows
an indicator for earlier hidden messages .
"""
if not self . conversation_history :
return
# Check config: resume_display setting
if self . resume_display == " minimal " :
return
MAX_DISPLAY_EXCHANGES = 10 # max user+assistant pairs to show
MAX_USER_LEN = 300 # truncate user messages
MAX_ASST_LEN = 200 # truncate assistant text
MAX_ASST_LINES = 3 # max lines of assistant text
def _strip_reasoning ( text : str ) - > str :
""" Remove <REASONING_SCRATCHPAD>...</REASONING_SCRATCHPAD> blocks
from displayed text ( reasoning model internal thoughts ) . """
import re
cleaned = re . sub (
r " <REASONING_SCRATCHPAD>.*?</REASONING_SCRATCHPAD> \ s* " ,
" " , text , flags = re . DOTALL ,
)
# Also strip unclosed reasoning tags at the end
cleaned = re . sub (
r " <REASONING_SCRATCHPAD>.*$ " ,
" " , cleaned , flags = re . DOTALL ,
)
return cleaned . strip ( )
# Collect displayable entries (skip system, tool-result messages)
entries = [ ] # list of (role, display_text)
for msg in self . conversation_history :
role = msg . get ( " role " , " " )
content = msg . get ( " content " )
tool_calls = msg . get ( " tool_calls " ) or [ ]
if role == " system " :
continue
if role == " tool " :
continue
if role == " user " :
text = " " if content is None else str ( content )
# Handle multimodal content (list of dicts)
if isinstance ( content , list ) :
parts = [ ]
for part in content :
if isinstance ( part , dict ) and part . get ( " type " ) == " text " :
parts . append ( part . get ( " text " , " " ) )
elif isinstance ( part , dict ) and part . get ( " type " ) == " image_url " :
parts . append ( " [image] " )
text = " " . join ( parts )
if len ( text ) > MAX_USER_LEN :
text = text [ : MAX_USER_LEN ] + " ... "
entries . append ( ( " user " , text ) )
elif role == " assistant " :
text = " " if content is None else str ( content )
text = _strip_reasoning ( text )
parts = [ ]
if text :
lines = text . splitlines ( )
if len ( lines ) > MAX_ASST_LINES :
text = " \n " . join ( lines [ : MAX_ASST_LINES ] ) + " ... "
if len ( text ) > MAX_ASST_LEN :
text = text [ : MAX_ASST_LEN ] + " ... "
parts . append ( text )
if tool_calls :
tc_count = len ( tool_calls )
# Extract tool names
names = [ ]
for tc in tool_calls :
fn = tc . get ( " function " , { } )
name = fn . get ( " name " , " unknown " ) if isinstance ( fn , dict ) else " unknown "
if name not in names :
names . append ( name )
names_str = " , " . join ( names [ : 4 ] )
if len ( names ) > 4 :
names_str + = " , ... "
noun = " call " if tc_count == 1 else " calls "
parts . append ( f " [ { tc_count } tool { noun } : { names_str } ] " )
if not parts :
# Skip pure-reasoning messages that have no visible output
continue
entries . append ( ( " assistant " , " " . join ( parts ) ) )
if not entries :
return
# Determine if we need to truncate
skipped = 0
if len ( entries ) > MAX_DISPLAY_EXCHANGES * 2 :
skipped = len ( entries ) - MAX_DISPLAY_EXCHANGES * 2
entries = entries [ skipped : ]
# Build the display using Rich
from rich . panel import Panel
from rich . text import Text
lines = Text ( )
if skipped :
lines . append (
f " ... { skipped } earlier messages ... \n \n " ,
style = " dim italic " ,
)
for i , ( role , text ) in enumerate ( entries ) :
if role == " user " :
lines . append ( " ● You: " , style = " dim bold #DAA520 " )
# Show first line inline, indent rest
msg_lines = text . splitlines ( )
lines . append ( msg_lines [ 0 ] + " \n " , style = " dim " )
for ml in msg_lines [ 1 : ] :
lines . append ( f " { ml } \n " , style = " dim " )
else :
lines . append ( " ◆ Hermes: " , style = " dim bold #8FBC8F " )
msg_lines = text . splitlines ( )
lines . append ( msg_lines [ 0 ] + " \n " , style = " dim " )
for ml in msg_lines [ 1 : ] :
lines . append ( f " { ml } \n " , style = " dim " )
if i < len ( entries ) - 1 :
lines . append ( " " ) # small gap
panel = Panel (
lines ,
title = " [dim #DAA520]Previous Conversation[/] " ,
border_style = " dim #8B8682 " ,
padding = ( 0 , 1 ) ,
)
self . console . print ( panel )
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
def _try_attach_clipboard_image ( self ) - > bool :
""" Check clipboard for an image and attach it if found.
Saves the image to ~ / . hermes / images / and appends the path to
` ` _attached_images ` ` . Returns True if an image was attached .
"""
from hermes_cli . clipboard import save_clipboard_image
img_dir = Path . home ( ) / " .hermes " / " images "
self . _image_counter + = 1
ts = datetime . now ( ) . strftime ( " % Y % m %d _ % H % M % S " )
img_path = img_dir / f " clip_ { ts } _ { self . _image_counter } .png "
if save_clipboard_image ( img_path ) :
self . _attached_images . append ( img_path )
return True
self . _image_counter - = 1
return False
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
def _handle_rollback_command ( self , command : str ) :
""" Handle /rollback — list or restore filesystem checkpoints. """
from tools . checkpoint_manager import CheckpointManager , format_checkpoint_list
if not hasattr ( self , ' agent ' ) or not self . agent :
print ( " No active agent session. " )
return
mgr = self . agent . _checkpoint_mgr
if not mgr . enabled :
print ( " Checkpoints are not enabled. " )
print ( " Enable with: hermes --checkpoints " )
print ( " Or in config.yaml: checkpoints: { enabled: true } " )
return
cwd = os . getenv ( " TERMINAL_CWD " , os . getcwd ( ) )
parts = command . split ( maxsplit = 1 )
arg = parts [ 1 ] . strip ( ) if len ( parts ) > 1 else " "
if not arg :
# List checkpoints
checkpoints = mgr . list_checkpoints ( cwd )
print ( format_checkpoint_list ( checkpoints , cwd ) )
else :
# Restore by number or hash
checkpoints = mgr . list_checkpoints ( cwd )
if not checkpoints :
print ( f " No checkpoints found for { cwd } " )
return
target_hash = None
try :
idx = int ( arg ) - 1 # 1-indexed for user
if 0 < = idx < len ( checkpoints ) :
target_hash = checkpoints [ idx ] [ " hash " ]
else :
print ( f " Invalid checkpoint number. Use 1- { len ( checkpoints ) } . " )
return
except ValueError :
# Try as a git hash
target_hash = arg
result = mgr . restore ( cwd , target_hash )
if result [ " success " ] :
print ( f " ✅ Restored to checkpoint { result [ ' restored_to ' ] } : { result [ ' reason ' ] } " )
print ( f " A pre-rollback snapshot was saved automatically. " )
else :
print ( f " ❌ { result [ ' error ' ] } " )
fix: clipboard image paste on WSL2, Wayland, and VSCode terminal
The original implementation only supported xclip (X11), which silently
fails on WSL2 (can't access Windows clipboard for images), Wayland
desktops (xclip is X11-only), and VSCode terminal on WSL2.
Clipboard backend changes (hermes_cli/clipboard.py):
- WSL2: detect via /proc/version, use powershell.exe with .NET
System.Windows.Forms.Clipboard to extract images as base64 PNG
- Wayland: use wl-paste with MIME type detection, auto-convert BMP
to PNG for WSLg environments (via Pillow or ImageMagick)
- Dispatch order: WSL → Wayland → X11 (xclip), with fallthrough
- New has_clipboard_image() for lightweight clipboard checks
- Cache WSL detection result per-process
CLI changes (cli.py):
- /paste command: explicit clipboard image check for terminals where
BracketedPaste doesn't fire (image-only clipboard in VSCode/WinTerm)
- Ctrl+V keybinding: fallback for Linux terminals where Ctrl+V sends
raw byte instead of triggering bracketed paste
Tests: 80 tests (up from 37) covering WSL, Wayland, X11 dispatch,
BMP conversion, has_clipboard_image, and /paste command.
2026-03-05 20:22:44 -08:00
def _handle_paste_command ( self ) :
""" Handle /paste — explicitly check clipboard for an image.
This is the reliable fallback for terminals where BracketedPaste
doesn ' t fire for image-only clipboard content (e.g., VSCode terminal,
Windows Terminal with WSL2 ) .
"""
from hermes_cli . clipboard import has_clipboard_image
if has_clipboard_image ( ) :
if self . _try_attach_clipboard_image ( ) :
n = len ( self . _attached_images )
_cprint ( f " 📎 Image # { n } attached from clipboard " )
else :
_cprint ( f " { _DIM } (>_<) Clipboard has an image but extraction failed { _RST } " )
else :
_cprint ( f " { _DIM } (._.) No image found in clipboard { _RST } " )
2026-03-08 06:21:53 -07:00
def _preprocess_images_with_vision ( self , text : str , images : list ) - > str :
""" Analyze attached images via the vision tool and return enriched text.
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
2026-03-08 06:21:53 -07:00
Instead of embedding raw base64 ` ` image_url ` ` content parts in the
conversation ( which only works with vision - capable models ) , this
pre - processes each image through the auxiliary vision model ( Gemini
Flash ) and prepends the descriptions to the user ' s message — the
same approach the messaging gateway uses .
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
2026-03-08 06:21:53 -07:00
The local file path is included so the agent can re - examine the
image later with ` ` vision_analyze ` ` if needed .
"""
import asyncio as _asyncio
import json as _json
from tools . vision_tools import vision_analyze_tool
analysis_prompt = (
" Describe everything visible in this image in thorough detail. "
" Include any text, code, data, objects, people, layout, colors, "
" and any other notable visual information. "
)
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
2026-03-08 06:21:53 -07:00
enriched_parts = [ ]
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
for img_path in images :
2026-03-08 06:21:53 -07:00
if not img_path . exists ( ) :
continue
size_kb = img_path . stat ( ) . st_size / / 1024
_cprint ( f " { _DIM } 👁️ analyzing { img_path . name } ( { size_kb } KB)... { _RST } " )
try :
result_json = _asyncio . run (
vision_analyze_tool ( image_url = str ( img_path ) , user_prompt = analysis_prompt )
)
result = _json . loads ( result_json )
if result . get ( " success " ) :
description = result . get ( " analysis " , " " )
enriched_parts . append (
f " [The user attached an image. Here ' s what it contains: \n { description } ] \n "
f " [If you need a closer look, use vision_analyze with "
f " image_url: { img_path } ] "
)
_cprint ( f " { _DIM } ✓ image analyzed { _RST } " )
else :
enriched_parts . append (
f " [The user attached an image but it couldn ' t be analyzed. "
f " You can try examining it with vision_analyze using "
f " image_url: { img_path } ] "
)
_cprint ( f " { _DIM } ⚠ vision analysis failed — path included for retry { _RST } " )
except Exception as e :
enriched_parts . append (
f " [The user attached an image but analysis failed ( { e } ). "
f " You can try examining it with vision_analyze using "
f " image_url: { img_path } ] "
)
_cprint ( f " { _DIM } ⚠ vision analysis error — path included for retry { _RST } " )
# Combine: vision descriptions first, then the user's original text
user_text = text if isinstance ( text , str ) and text else " "
if enriched_parts :
prefix = " \n \n " . join ( enriched_parts )
return f " { prefix } \n \n { user_text } " if user_text else prefix
return user_text or " What do you see in this image? "
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
2026-02-02 19:28:27 -08:00
def _show_tool_availability_warnings ( self ) :
""" Show warnings about disabled tools due to missing API keys. """
try :
from model_tools import check_tool_availability , TOOLSET_REQUIREMENTS
available , unavailable = check_tool_availability ( )
# Filter to only those missing API keys (not system deps)
api_key_missing = [ u for u in unavailable if u [ " missing_vars " ] ]
if api_key_missing :
self . console . print ( )
self . console . print ( " [yellow]⚠️ Some tools disabled (missing API keys):[/] " )
for item in api_key_missing :
tools_str = " , " . join ( item [ " tools " ] [ : 2 ] ) # Show first 2 tools
if len ( item [ " tools " ] ) > 2 :
tools_str + = f " , + { len ( item [ ' tools ' ] ) - 2 } more "
self . console . print ( f " [dim]• { item [ ' name ' ] } [/] [dim italic]( { ' , ' . join ( item [ ' missing_vars ' ] ) } )[/] " )
self . console . print ( " [dim] Run ' hermes setup ' to configure[/] " )
except Exception :
pass # Don't crash on import errors
2026-01-31 06:30:48 +00:00
def _show_status ( self ) :
""" Show current status bar. """
# Get tool count
2026-02-02 23:46:41 -08:00
tools = get_tool_definitions ( enabled_toolsets = self . enabled_toolsets , quiet_mode = True )
2026-01-31 06:30:48 +00:00
tool_count = len ( tools ) if tools else 0
# Format model name (shorten if needed)
model_short = self . model . split ( " / " ) [ - 1 ] if " / " in self . model else self . model
if len ( model_short ) > 30 :
model_short = model_short [ : 27 ] + " ... "
# Get API status indicator
if self . api_key :
api_indicator = " [green bold]●[/] "
else :
api_indicator = " [red bold]●[/] "
# Build status line with proper markup
toolsets_info = " "
if self . enabled_toolsets and " all " not in self . enabled_toolsets :
toolsets_info = f " [dim #B8860B]·[/] [#CD7F32]toolsets: { ' , ' . join ( self . enabled_toolsets ) } [/] "
2026-02-20 17:24:00 -08:00
provider_info = f " [dim #B8860B]·[/] [dim]provider: { self . provider } [/] "
2026-02-25 18:20:38 -08:00
if self . _provider_source :
provider_info + = f " [dim #B8860B]·[/] [dim]auth: { self . _provider_source } [/] "
2026-02-20 17:24:00 -08:00
2026-01-31 06:30:48 +00:00
self . console . print (
f " { api_indicator } [#FFBF00] { model_short } [/] "
f " [dim #B8860B]·[/] [bold cyan] { tool_count } tools[/] "
2026-02-20 17:24:00 -08:00
f " { toolsets_info } { provider_info } "
2026-01-31 06:30:48 +00:00
)
def show_help ( self ) :
2026-03-09 03:59:47 -04:00
""" Display help information with categorized commands. """
from hermes_cli . commands import COMMANDS_BY_CATEGORY
_cprint ( f " \n { _BOLD } + { ' - ' * 55 } + { _RST } " )
_cprint ( f " { _BOLD } | { ' ' * 14 } (^_^)? Available Commands { ' ' * 15 } | { _RST } " )
_cprint ( f " { _BOLD } + { ' - ' * 55 } + { _RST } " )
for category , commands in COMMANDS_BY_CATEGORY . items ( ) :
_cprint ( f " \n { _BOLD } ── { category } ── { _RST } " )
for cmd , desc in commands . items ( ) :
_cprint ( f " { _GOLD } { cmd : <15 } { _RST } { _DIM } - { _RST } { desc } " )
2026-02-28 11:18:50 -08:00
if _skill_commands :
_cprint ( f " \n ⚡ { _BOLD } Skill Commands { _RST } ( { len ( _skill_commands ) } installed): " )
for cmd , info in sorted ( _skill_commands . items ( ) ) :
2026-03-09 03:59:47 -04:00
_cprint ( f " { _GOLD } { cmd : <22 } { _RST } { _DIM } - { _RST } { info [ ' description ' ] } " )
2026-02-28 11:18:50 -08:00
_cprint ( f " \n { _DIM } Tip: Just type your message to chat with Hermes! { _RST } " )
2026-03-05 22:48:39 -08:00
_cprint ( f " { _DIM } Multi-line: Alt+Enter for a new line { _RST } " )
_cprint ( f " { _DIM } Paste image: Alt+V (or /paste) { _RST } \n " )
2026-01-31 06:30:48 +00:00
def show_tools ( self ) :
""" Display available tools with kawaii ASCII art. """
2026-02-02 23:46:41 -08:00
tools = get_tool_definitions ( enabled_toolsets = self . enabled_toolsets , quiet_mode = True )
2026-01-31 06:30:48 +00:00
if not tools :
print ( " (;_;) No tools available " )
return
# Header
print ( )
2026-03-01 16:37:16 -08:00
title = " (^_^)/ Available Tools "
width = 78
pad = width - len ( title )
print ( " + " + " - " * width + " + " )
print ( " | " + " " * ( pad / / 2 ) + title + " " * ( pad - pad / / 2 ) + " | " )
print ( " + " + " - " * width + " + " )
2026-01-31 06:30:48 +00:00
print ( )
# Group tools by toolset
toolsets = { }
for tool in sorted ( tools , key = lambda t : t [ " function " ] [ " name " ] ) :
name = tool [ " function " ] [ " name " ]
toolset = get_toolset_for_tool ( name ) or " unknown "
if toolset not in toolsets :
toolsets [ toolset ] = [ ]
desc = tool [ " function " ] . get ( " description " , " " )
2026-02-26 12:11:32 -08:00
# First sentence: split on ". " (period+space) to avoid breaking on "e.g." or "v2.0"
desc = desc . split ( " \n " ) [ 0 ]
if " . " in desc :
desc = desc [ : desc . index ( " . " ) + 1 ]
2026-01-31 06:30:48 +00:00
toolsets [ toolset ] . append ( ( name , desc ) )
# Display by toolset
for toolset in sorted ( toolsets . keys ( ) ) :
print ( f " [ { toolset } ] " )
for name , desc in toolsets [ toolset ] :
print ( f " * { name : <20 } - { desc } " )
print ( )
print ( f " Total: { len ( tools ) } tools ヽ(^o^)ノ " )
print ( )
def show_toolsets ( self ) :
""" Display available toolsets with kawaii ASCII art. """
all_toolsets = get_all_toolsets ( )
# Header
print ( )
2026-03-01 16:37:16 -08:00
title = " (^_^)b Available Toolsets "
width = 58
pad = width - len ( title )
print ( " + " + " - " * width + " + " )
print ( " | " + " " * ( pad / / 2 ) + title + " " * ( pad - pad / / 2 ) + " | " )
print ( " + " + " - " * width + " + " )
2026-01-31 06:30:48 +00:00
print ( )
for name in sorted ( all_toolsets . keys ( ) ) :
info = get_toolset_info ( name )
if info :
tool_count = info [ " tool_count " ]
2026-03-01 16:37:16 -08:00
desc = info [ " description " ]
2026-01-31 06:30:48 +00:00
# Mark if currently enabled
marker = " (*) " if self . enabled_toolsets and name in self . enabled_toolsets else " "
print ( f " { marker } { name : <18 } [ { tool_count : >2 } tools] - { desc } " )
print ( )
print ( " (*) = currently enabled " )
print ( )
print ( " Tip: Use ' all ' or ' * ' to enable all toolsets " )
print ( " Example: python cli.py --toolsets web,terminal " )
print ( )
def show_config ( self ) :
""" Display current configuration with kawaii ASCII art. """
# Get terminal config from environment (which was set from cli-config.yaml)
terminal_env = os . getenv ( " TERMINAL_ENV " , " local " )
2026-02-08 12:56:40 -08:00
terminal_cwd = os . getenv ( " TERMINAL_CWD " , os . getcwd ( ) )
2026-01-31 06:30:48 +00:00
terminal_timeout = os . getenv ( " TERMINAL_TIMEOUT " , " 60 " )
2026-02-26 23:49:08 +03:00
user_config_path = Path . home ( ) / ' .hermes ' / ' config.yaml '
project_config_path = Path ( __file__ ) . parent / ' cli-config.yaml '
if user_config_path . exists ( ) :
config_path = user_config_path
else :
config_path = project_config_path
2026-01-31 06:30:48 +00:00
config_status = " (loaded) " if config_path . exists ( ) else " (not found) "
api_key_display = ' ******** ' + self . api_key [ - 4 : ] if self . api_key and len ( self . api_key ) > 4 else ' Not set! '
print ( )
2026-03-01 16:37:16 -08:00
title = " (^_^) Configuration "
width = 50
pad = width - len ( title )
print ( " + " + " - " * width + " + " )
print ( " | " + " " * ( pad / / 2 ) + title + " " * ( pad - pad / / 2 ) + " | " )
print ( " + " + " - " * width + " + " )
2026-01-31 06:30:48 +00:00
print ( )
print ( " -- Model -- " )
print ( f " Model: { self . model } " )
print ( f " Base URL: { self . base_url } " )
print ( f " API Key: { api_key_display } " )
print ( )
print ( " -- Terminal -- " )
print ( f " Environment: { terminal_env } " )
if terminal_env == " ssh " :
ssh_host = os . getenv ( " TERMINAL_SSH_HOST " , " not set " )
ssh_user = os . getenv ( " TERMINAL_SSH_USER " , " not set " )
ssh_port = os . getenv ( " TERMINAL_SSH_PORT " , " 22 " )
print ( f " SSH Target: { ssh_user } @ { ssh_host } : { ssh_port } " )
print ( f " Working Dir: { terminal_cwd } " )
print ( f " Timeout: { terminal_timeout } s " )
print ( )
print ( " -- Agent -- " )
print ( f " Max Turns: { self . max_turns } " )
print ( f " Toolsets: { ' , ' . join ( self . enabled_toolsets ) if self . enabled_toolsets else ' all ' } " )
print ( f " Verbose: { self . verbose } " )
print ( )
print ( " -- Session -- " )
print ( f " Started: { self . session_start . strftime ( ' % Y- % m- %d % H: % M: % S ' ) } " )
2026-02-26 23:49:08 +03:00
print ( f " Config File: { config_path } { config_status } " )
2026-01-31 06:30:48 +00:00
print ( )
def show_history ( self ) :
""" Display conversation history. """
if not self . conversation_history :
print ( " (._.) No conversation history yet. " )
return
2026-03-07 20:15:06 -08:00
preview_limit = 400
visible_index = 0
hidden_tool_messages = 0
def flush_tool_summary ( ) :
nonlocal hidden_tool_messages
if not hidden_tool_messages :
return
noun = " message " if hidden_tool_messages == 1 else " messages "
print ( " \n [Tools] " )
print ( f " ( { hidden_tool_messages } tool { noun } hidden) " )
hidden_tool_messages = 0
2026-01-31 06:30:48 +00:00
print ( )
print ( " + " + " - " * 50 + " + " )
print ( " | " + " " * 12 + " (^_^) Conversation History " + " " * 11 + " | " )
print ( " + " + " - " * 50 + " + " )
2026-03-07 20:15:06 -08:00
for msg in self . conversation_history :
2026-01-31 06:30:48 +00:00
role = msg . get ( " role " , " unknown " )
2026-03-07 20:15:06 -08:00
if role == " tool " :
hidden_tool_messages + = 1
continue
if role not in { " user " , " assistant " } :
continue
flush_tool_summary ( )
visible_index + = 1
content = msg . get ( " content " )
content_text = " " if content is None else str ( content )
2026-01-31 06:30:48 +00:00
if role == " user " :
2026-03-07 20:15:06 -08:00
print ( f " \n [You # { visible_index } ] " )
print (
f " { content_text [ : preview_limit ] } { ' ... ' if len ( content_text ) > preview_limit else ' ' } "
)
continue
print ( f " \n [Hermes # { visible_index } ] " )
tool_calls = msg . get ( " tool_calls " ) or [ ]
if content_text :
preview = content_text [ : preview_limit ]
suffix = " ... " if len ( content_text ) > preview_limit else " "
elif tool_calls :
tool_count = len ( tool_calls )
noun = " call " if tool_count == 1 else " calls "
preview = f " (requested { tool_count } tool { noun } ) "
suffix = " "
else :
preview = " (no text response) "
suffix = " "
print ( f " { preview } { suffix } " )
flush_tool_summary ( )
2026-01-31 06:30:48 +00:00
print ( )
def reset_conversation ( self ) :
""" Reset the conversation history. """
2026-02-22 10:15:17 -08:00
if self . agent and self . conversation_history :
try :
self . agent . flush_memories ( self . conversation_history )
except Exception :
pass
2026-01-31 06:30:48 +00:00
self . conversation_history = [ ]
print ( " (^_^)b Conversation reset! " )
def save_conversation ( self ) :
""" Save the current conversation to a file. """
if not self . conversation_history :
print ( " (;_;) No conversation to save. " )
return
timestamp = datetime . now ( ) . strftime ( " % Y % m %d _ % H % M % S " )
filename = f " hermes_conversation_ { timestamp } .json "
try :
with open ( filename , " w " , encoding = " utf-8 " ) as f :
json . dump ( {
" model " : self . model ,
" session_start " : self . session_start . isoformat ( ) ,
" messages " : self . conversation_history ,
} , f , indent = 2 , ensure_ascii = False )
print ( f " (^_^)v Conversation saved to: { filename } " )
except Exception as e :
print ( f " (x_x) Failed to save: { e } " )
2026-02-10 15:59:46 -08:00
def retry_last ( self ) :
""" Retry the last user message by removing the last exchange and re-sending.
Removes the last assistant response ( and any tool - call messages ) and
the last user message , then re - sends that user message to the agent .
Returns the message to re - send , or None if there ' s nothing to retry.
"""
if not self . conversation_history :
print ( " (._.) No messages to retry. " )
return None
# Walk backwards to find the last user message
last_user_idx = None
for i in range ( len ( self . conversation_history ) - 1 , - 1 , - 1 ) :
if self . conversation_history [ i ] . get ( " role " ) == " user " :
last_user_idx = i
break
if last_user_idx is None :
print ( " (._.) No user message found to retry. " )
return None
# Extract the message text and remove everything from that point forward
last_message = self . conversation_history [ last_user_idx ] . get ( " content " , " " )
self . conversation_history = self . conversation_history [ : last_user_idx ]
print ( f " (^_^)b Retrying: \" { last_message [ : 60 ] } { ' ... ' if len ( last_message ) > 60 else ' ' } \" " )
return last_message
def undo_last ( self ) :
""" Remove the last user/assistant exchange from conversation history.
Walks backwards and removes all messages from the last user message
onward ( including assistant responses , tool calls , etc . ) .
"""
if not self . conversation_history :
print ( " (._.) No messages to undo. " )
return
# Walk backwards to find the last user message
last_user_idx = None
for i in range ( len ( self . conversation_history ) - 1 , - 1 , - 1 ) :
if self . conversation_history [ i ] . get ( " role " ) == " user " :
last_user_idx = i
break
if last_user_idx is None :
print ( " (._.) No user message found to undo. " )
return
# Count how many messages we're removing
removed_count = len ( self . conversation_history ) - last_user_idx
removed_msg = self . conversation_history [ last_user_idx ] . get ( " content " , " " )
# Truncate history to before the last user message
self . conversation_history = self . conversation_history [ : last_user_idx ]
print ( f " (^_^)b Undid { removed_count } message(s). Removed: \" { removed_msg [ : 60 ] } { ' ... ' if len ( removed_msg ) > 60 else ' ' } \" " )
remaining = len ( self . conversation_history )
print ( f " { remaining } message(s) remaining in history. " )
2026-01-31 06:30:48 +00:00
def _handle_prompt_command ( self , cmd : str ) :
""" Handle the /prompt command to view or set system prompt. """
parts = cmd . split ( maxsplit = 1 )
if len ( parts ) > 1 :
# Set new prompt
new_prompt = parts [ 1 ] . strip ( )
if new_prompt . lower ( ) == " clear " :
self . system_prompt = " "
self . agent = None # Force re-init
if save_config_value ( " agent.system_prompt " , " " ) :
print ( " (^_^)b System prompt cleared (saved to config) " )
else :
print ( " (^_^) System prompt cleared (session only) " )
else :
self . system_prompt = new_prompt
self . agent = None # Force re-init
if save_config_value ( " agent.system_prompt " , new_prompt ) :
print ( f " (^_^)b System prompt set (saved to config) " )
else :
print ( f " (^_^) System prompt set (session only) " )
print ( f " \" { new_prompt [ : 60 ] } { ' ... ' if len ( new_prompt ) > 60 else ' ' } \" " )
else :
# Show current prompt
print ( )
print ( " + " + " - " * 50 + " + " )
print ( " | " + " " * 15 + " (^_^) System Prompt " + " " * 15 + " | " )
print ( " + " + " - " * 50 + " + " )
print ( )
if self . system_prompt :
# Word wrap the prompt for display
words = self . system_prompt . split ( )
lines = [ ]
current_line = " "
for word in words :
if len ( current_line ) + len ( word ) + 1 < = 50 :
current_line + = ( " " if current_line else " " ) + word
else :
lines . append ( current_line )
current_line = word
if current_line :
lines . append ( current_line )
for line in lines :
print ( f " { line } " )
else :
print ( " (no custom prompt set - using default) " )
print ( )
print ( " Usage: " )
print ( " /prompt <text> - Set a custom system prompt " )
print ( " /prompt clear - Remove custom prompt " )
print ( " /personality - Use a predefined personality " )
print ( )
def _handle_personality_command ( self , cmd : str ) :
""" Handle the /personality command to set predefined personalities. """
parts = cmd . split ( maxsplit = 1 )
if len ( parts ) > 1 :
# Set personality
personality_name = parts [ 1 ] . strip ( ) . lower ( )
if personality_name in self . personalities :
self . system_prompt = self . personalities [ personality_name ]
self . agent = None # Force re-init
if save_config_value ( " agent.system_prompt " , self . system_prompt ) :
print ( f " (^_^)b Personality set to ' { personality_name } ' (saved to config) " )
else :
print ( f " (^_^) Personality set to ' { personality_name } ' (session only) " )
print ( f " \" { self . system_prompt [ : 60 ] } { ' ... ' if len ( self . system_prompt ) > 60 else ' ' } \" " )
else :
print ( f " (._.) Unknown personality: { personality_name } " )
print ( f " Available: { ' , ' . join ( self . personalities . keys ( ) ) } " )
else :
# Show available personalities
print ( )
print ( " + " + " - " * 50 + " + " )
print ( " | " + " " * 12 + " (^o^)/ Personalities " + " " * 15 + " | " )
print ( " + " + " - " * 50 + " + " )
print ( )
for name , prompt in self . personalities . items ( ) :
2026-03-01 16:37:16 -08:00
print ( f " { name : <12 } - \" { prompt } \" " )
2026-01-31 06:30:48 +00:00
print ( )
print ( " Usage: /personality <name> " )
print ( )
2026-02-02 08:26:42 -08:00
def _handle_cron_command ( self , cmd : str ) :
""" Handle the /cron command to manage scheduled tasks. """
parts = cmd . split ( maxsplit = 2 )
if len ( parts ) == 1 :
# /cron - show help and list
print ( )
print ( " + " + " - " * 60 + " + " )
print ( " | " + " " * 18 + " (^_^) Scheduled Tasks " + " " * 19 + " | " )
print ( " + " + " - " * 60 + " + " )
print ( )
print ( " Commands: " )
print ( " /cron - List scheduled jobs " )
print ( " /cron list - List scheduled jobs " )
print ( ' /cron add <schedule> <prompt> - Add a new job ' )
print ( " /cron remove <job_id> - Remove a job " )
print ( )
print ( " Schedule formats: " )
print ( " 30m, 2h, 1d - One-shot delay " )
print ( ' " every 30m " , " every 2h " - Recurring interval ' )
print ( ' " 0 9 * * * " - Cron expression ' )
print ( )
# Show current jobs
jobs = list_jobs ( )
if jobs :
print ( " Current Jobs: " )
print ( " " + " - " * 55 )
for job in jobs :
# Format repeat status
times = job [ " repeat " ] . get ( " times " )
completed = job [ " repeat " ] . get ( " completed " , 0 )
if times is None :
repeat_str = " forever "
else :
repeat_str = f " { completed } / { times } "
print ( f " { job [ ' id ' ] [ : 12 ] : <12 } | { job [ ' schedule_display ' ] : <15 } | { repeat_str : <8 } " )
prompt_preview = job [ ' prompt ' ] [ : 45 ] + " ... " if len ( job [ ' prompt ' ] ) > 45 else job [ ' prompt ' ]
print ( f " { prompt_preview } " )
if job . get ( " next_run_at " ) :
from datetime import datetime
next_run = datetime . fromisoformat ( job [ " next_run_at " ] )
print ( f " Next: { next_run . strftime ( ' % Y- % m- %d % H: % M ' ) } " )
print ( )
else :
print ( " No scheduled jobs. Use ' /cron add ' to create one. " )
print ( )
return
subcommand = parts [ 1 ] . lower ( )
if subcommand == " list " :
# /cron list - just show jobs
jobs = list_jobs ( )
if not jobs :
print ( " (._.) No scheduled jobs. " )
return
print ( )
print ( " Scheduled Jobs: " )
print ( " - " * 70 )
for job in jobs :
times = job [ " repeat " ] . get ( " times " )
completed = job [ " repeat " ] . get ( " completed " , 0 )
repeat_str = " forever " if times is None else f " { completed } / { times } "
print ( f " ID: { job [ ' id ' ] } " )
print ( f " Name: { job [ ' name ' ] } " )
print ( f " Schedule: { job [ ' schedule_display ' ] } ( { repeat_str } ) " )
print ( f " Next run: { job . get ( ' next_run_at ' , ' N/A ' ) } " )
print ( f " Prompt: { job [ ' prompt ' ] [ : 80 ] } { ' ... ' if len ( job [ ' prompt ' ] ) > 80 else ' ' } " )
if job . get ( " last_run_at " ) :
print ( f " Last run: { job [ ' last_run_at ' ] } ( { job . get ( ' last_status ' , ' ? ' ) } ) " )
print ( )
elif subcommand == " add " :
# /cron add <schedule> <prompt>
if len ( parts ) < 3 :
print ( " (._.) Usage: /cron add <schedule> <prompt> " )
print ( " Example: /cron add 30m Remind me to take a break " )
print ( ' Example: /cron add " every 2h " Check server status at 192.168.1.1 ' )
return
# Parse schedule and prompt
rest = parts [ 2 ] . strip ( )
# Handle quoted schedule (e.g., "every 30m" or "0 9 * * *")
if rest . startswith ( ' " ' ) :
# Find closing quote
close_quote = rest . find ( ' " ' , 1 )
if close_quote == - 1 :
print ( " (._.) Unmatched quote in schedule " )
return
schedule = rest [ 1 : close_quote ]
prompt = rest [ close_quote + 1 : ] . strip ( )
else :
# First word is schedule
schedule_parts = rest . split ( maxsplit = 1 )
schedule = schedule_parts [ 0 ]
prompt = schedule_parts [ 1 ] if len ( schedule_parts ) > 1 else " "
if not prompt :
print ( " (._.) Please provide a prompt for the job " )
return
try :
job = create_job ( prompt = prompt , schedule = schedule )
print ( f " (^_^)b Created job: { job [ ' id ' ] } " )
print ( f " Schedule: { job [ ' schedule_display ' ] } " )
print ( f " Next run: { job [ ' next_run_at ' ] } " )
except Exception as e :
print ( f " (x_x) Failed to create job: { e } " )
elif subcommand == " remove " or subcommand == " rm " or subcommand == " delete " :
# /cron remove <job_id>
if len ( parts ) < 3 :
print ( " (._.) Usage: /cron remove <job_id> " )
return
job_id = parts [ 2 ] . strip ( )
job = get_job ( job_id )
if not job :
print ( f " (._.) Job not found: { job_id } " )
return
if remove_job ( job_id ) :
print ( f " (^_^)b Removed job: { job [ ' name ' ] } ( { job_id } ) " )
else :
print ( f " (x_x) Failed to remove job: { job_id } " )
else :
print ( f " (._.) Unknown cron command: { subcommand } " )
print ( " Available: list, add, remove " )
Add Skills Hub — universal skill search, install, and management from online registries
Implements the Hermes Skills Hub with agentskills.io spec compliance,
multi-registry skill discovery, security scanning, and user-driven
management via CLI and /skills slash command.
Core features:
- Security scanner (tools/skills_guard.py): 120 threat patterns across
12 categories, trust-aware install policy (builtin/trusted/community),
structural checks, unicode injection detection, LLM audit pass
- Hub client (tools/skills_hub.py): GitHub, ClawHub, Claude Code
marketplace, and LobeHub source adapters with shared GitHubAuth
(PAT + gh CLI + GitHub App), lock file provenance tracking, quarantine
flow, and unified search across all sources
- CLI interface (hermes_cli/skills_hub.py): search, install, inspect,
list, audit, uninstall, publish (GitHub PR), snapshot export/import,
and tap management — powers both `hermes skills` and `/skills`
Spec conformance (Phase 0):
- Upgraded frontmatter parser to yaml.safe_load with fallback
- Migrated 39 SKILL.md files: tags/related_skills to metadata.hermes.*
- Added assets/ directory support and compatibility/metadata fields
- Excluded .hub/ from skill discovery in skills_tool.py
Updated 13 config/doc files including README, AGENTS.md, .env.example,
setup wizard, doctor, status, pyproject.toml, and docs.
2026-02-18 16:09:05 -08:00
def _handle_skills_command ( self , cmd : str ) :
""" Handle /skills slash command — delegates to hermes_cli.skills_hub. """
from hermes_cli . skills_hub import handle_skills_slash
2026-02-26 20:29:52 -08:00
handle_skills_slash ( cmd , ChatConsole ( ) )
Add Skills Hub — universal skill search, install, and management from online registries
Implements the Hermes Skills Hub with agentskills.io spec compliance,
multi-registry skill discovery, security scanning, and user-driven
management via CLI and /skills slash command.
Core features:
- Security scanner (tools/skills_guard.py): 120 threat patterns across
12 categories, trust-aware install policy (builtin/trusted/community),
structural checks, unicode injection detection, LLM audit pass
- Hub client (tools/skills_hub.py): GitHub, ClawHub, Claude Code
marketplace, and LobeHub source adapters with shared GitHubAuth
(PAT + gh CLI + GitHub App), lock file provenance tracking, quarantine
flow, and unified search across all sources
- CLI interface (hermes_cli/skills_hub.py): search, install, inspect,
list, audit, uninstall, publish (GitHub PR), snapshot export/import,
and tap management — powers both `hermes skills` and `/skills`
Spec conformance (Phase 0):
- Upgraded frontmatter parser to yaml.safe_load with fallback
- Migrated 39 SKILL.md files: tags/related_skills to metadata.hermes.*
- Added assets/ directory support and compatibility/metadata fields
- Excluded .hub/ from skill discovery in skills_tool.py
Updated 13 config/doc files including README, AGENTS.md, .env.example,
setup wizard, doctor, status, pyproject.toml, and docs.
2026-02-18 16:09:05 -08:00
2026-02-02 19:01:51 -08:00
def _show_gateway_status ( self ) :
""" Show status of the gateway and connected messaging platforms. """
from gateway . config import load_gateway_config , Platform
print ( )
print ( " + " + " - " * 60 + " + " )
print ( " | " + " " * 15 + " (✿◠‿◠) Gateway Status " + " " * 17 + " | " )
print ( " + " + " - " * 60 + " + " )
print ( )
try :
config = load_gateway_config ( )
connected = config . get_connected_platforms ( )
print ( " Messaging Platform Configuration: " )
print ( " " + " - " * 55 )
platform_status = {
Platform . TELEGRAM : ( " Telegram " , " TELEGRAM_BOT_TOKEN " ) ,
Platform . DISCORD : ( " Discord " , " DISCORD_BOT_TOKEN " ) ,
Platform . WHATSAPP : ( " WhatsApp " , " WHATSAPP_ENABLED " ) ,
}
for platform , ( name , env_var ) in platform_status . items ( ) :
pconfig = config . platforms . get ( platform )
if pconfig and pconfig . enabled :
home = config . get_home_channel ( platform )
home_str = f " → { home . name } " if home else " "
print ( f " ✓ { name : <12 } Enabled { home_str } " )
else :
print ( f " ○ { name : <12 } Not configured ( { env_var } ) " )
print ( )
print ( " Session Reset Policy: " )
print ( " " + " - " * 55 )
policy = config . default_reset_policy
print ( f " Mode: { policy . mode } " )
print ( f " Daily reset at: { policy . at_hour } :00 " )
print ( f " Idle timeout: { policy . idle_minutes } minutes " )
print ( )
print ( " To start the gateway: " )
print ( " python cli.py --gateway " )
print ( )
print ( " Configuration file: ~/.hermes/gateway.json " )
print ( )
except Exception as e :
print ( f " Error loading gateway config: { e } " )
print ( )
print ( " To configure the gateway: " )
print ( " 1. Set environment variables: " )
print ( " TELEGRAM_BOT_TOKEN=your_token " )
print ( " DISCORD_BOT_TOKEN=your_token " )
print ( " 2. Or create ~/.hermes/gateway.json " )
print ( )
2026-01-31 06:30:48 +00:00
def process_command ( self , command : str ) - > bool :
"""
Process a slash command .
Args :
command : The command string ( starting with / )
Returns :
bool : True to continue , False to exit
"""
2026-02-08 13:31:45 -08:00
# Lowercase only for dispatch matching; preserve original case for arguments
cmd_lower = command . lower ( ) . strip ( )
cmd_original = command . strip ( )
2026-01-31 06:30:48 +00:00
2026-02-08 13:31:45 -08:00
if cmd_lower in ( " /quit " , " /exit " , " /q " ) :
2026-01-31 06:30:48 +00:00
return False
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /help " :
2026-01-31 06:30:48 +00:00
self . show_help ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /tools " :
2026-01-31 06:30:48 +00:00
self . show_tools ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /toolsets " :
2026-01-31 06:30:48 +00:00
self . show_toolsets ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /config " :
2026-01-31 06:30:48 +00:00
self . show_config ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /clear " :
2026-02-22 10:15:17 -08:00
# Flush memories before clearing
if self . agent and self . conversation_history :
try :
self . agent . flush_memories ( self . conversation_history )
except Exception :
pass
2026-03-07 16:09:23 -08:00
# Clear terminal screen. Inside the TUI, Rich's console.clear()
# goes through patch_stdout's StdoutProxy which swallows the
# screen-clear escape sequences. Use prompt_toolkit's output
# object directly to actually clear the terminal.
if self . _app :
out = self . _app . output
out . erase_screen ( )
out . cursor_goto ( 0 , 0 )
out . flush ( )
else :
self . console . clear ( )
2026-01-31 06:30:48 +00:00
# Reset conversation
self . conversation_history = [ ]
2026-03-07 16:09:23 -08:00
# Show fresh banner. Inside the TUI we must route Rich output
# through ChatConsole (which uses prompt_toolkit's native ANSI
# renderer) instead of self.console (which writes raw to stdout
# and gets mangled by patch_stdout).
if self . _app :
cc = ChatConsole ( )
2026-03-09 05:57:23 -07:00
term_w = shutil . get_terminal_size ( ) . columns
if self . compact or term_w < 80 :
cc . print ( _build_compact_banner ( ) )
2026-03-07 16:09:23 -08:00
else :
tools = get_tool_definitions ( enabled_toolsets = self . enabled_toolsets , quiet_mode = True )
cwd = os . getenv ( " TERMINAL_CWD " , os . getcwd ( ) )
ctx_len = None
if hasattr ( self , ' agent ' ) and self . agent and hasattr ( self . agent , ' context_compressor ' ) :
ctx_len = self . agent . context_compressor . context_length
build_welcome_banner (
console = cc ,
model = self . model ,
cwd = cwd ,
tools = tools ,
enabled_toolsets = self . enabled_toolsets ,
session_id = self . session_id ,
context_length = ctx_len ,
)
_cprint ( " ✨ (◕‿◕)✨ Fresh start! Screen cleared and conversation reset. \n " )
else :
self . show_banner ( )
print ( " ✨ (◕‿◕)✨ Fresh start! Screen cleared and conversation reset. \n " )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /history " :
2026-01-31 06:30:48 +00:00
self . show_history ( )
2026-03-08 15:20:29 -07:00
elif cmd_lower . startswith ( " /title " ) :
parts = cmd_original . split ( maxsplit = 1 )
if len ( parts ) > 1 :
fix: add title validation — sanitize, length limit, control char stripping
- Add SessionDB.sanitize_title() static method:
- Strips ASCII control chars (null, bell, ESC, etc.) except whitespace
- Strips problematic Unicode controls (zero-width, RTL override, BOM)
- Collapses whitespace runs, strips edges
- Normalizes empty/whitespace-only to None
- Enforces 100 char max length (raises ValueError)
- set_session_title() now calls sanitize_title() internally,
so all call sites (CLI, gateway, auto-lineage) are protected
- CLI /title handler sanitizes early to show correct feedback
- Gateway /title handler sanitizes early to show correct feedback
- 24 new tests: sanitize_title (17 cases covering control chars,
zero-width, RTL, BOM, emoji, CJK, length, integration),
gateway validation (too long, control chars, only-control-chars)
2026-03-08 15:54:51 -07:00
raw_title = parts [ 1 ] . strip ( )
if raw_title :
2026-03-08 15:20:29 -07:00
if self . _session_db :
fix: add title validation — sanitize, length limit, control char stripping
- Add SessionDB.sanitize_title() static method:
- Strips ASCII control chars (null, bell, ESC, etc.) except whitespace
- Strips problematic Unicode controls (zero-width, RTL override, BOM)
- Collapses whitespace runs, strips edges
- Normalizes empty/whitespace-only to None
- Enforces 100 char max length (raises ValueError)
- set_session_title() now calls sanitize_title() internally,
so all call sites (CLI, gateway, auto-lineage) are protected
- CLI /title handler sanitizes early to show correct feedback
- Gateway /title handler sanitizes early to show correct feedback
- 24 new tests: sanitize_title (17 cases covering control chars,
zero-width, RTL, BOM, emoji, CJK, length, integration),
gateway validation (too long, control chars, only-control-chars)
2026-03-08 15:54:51 -07:00
# Sanitize the title early so feedback matches what gets stored
try :
from hermes_state import SessionDB
new_title = SessionDB . sanitize_title ( raw_title )
except ValueError as e :
_cprint ( f " { e } " )
new_title = None
if not new_title :
_cprint ( " Title is empty after cleanup. Please use printable characters. " )
elif self . _session_db . get_session ( self . session_id ) :
# Session exists in DB — set title directly
2026-03-08 15:20:29 -07:00
try :
if self . _session_db . set_session_title ( self . session_id , new_title ) :
_cprint ( f " Session title set: { new_title } " )
else :
_cprint ( " Session not found in database. " )
except ValueError as e :
_cprint ( f " { e } " )
else :
# Session not created yet — defer the title
fix: add title validation — sanitize, length limit, control char stripping
- Add SessionDB.sanitize_title() static method:
- Strips ASCII control chars (null, bell, ESC, etc.) except whitespace
- Strips problematic Unicode controls (zero-width, RTL override, BOM)
- Collapses whitespace runs, strips edges
- Normalizes empty/whitespace-only to None
- Enforces 100 char max length (raises ValueError)
- set_session_title() now calls sanitize_title() internally,
so all call sites (CLI, gateway, auto-lineage) are protected
- CLI /title handler sanitizes early to show correct feedback
- Gateway /title handler sanitizes early to show correct feedback
- 24 new tests: sanitize_title (17 cases covering control chars,
zero-width, RTL, BOM, emoji, CJK, length, integration),
gateway validation (too long, control chars, only-control-chars)
2026-03-08 15:54:51 -07:00
# Check uniqueness proactively with the sanitized title
2026-03-08 15:20:29 -07:00
existing = self . _session_db . get_session_by_title ( new_title )
if existing :
_cprint ( f " Title ' { new_title } ' is already in use by session { existing [ ' id ' ] } " )
else :
self . _pending_title = new_title
_cprint ( f " Session title queued: { new_title } (will be saved on first message) " )
else :
_cprint ( " Session database not available. " )
else :
_cprint ( " Usage: /title <your session title> " )
else :
# Show current title if no argument given
if self . _session_db :
session = self . _session_db . get_session ( self . session_id )
if session and session . get ( " title " ) :
_cprint ( f " Session title: { session [ ' title ' ] } " )
elif self . _pending_title :
_cprint ( f " Session title (pending): { self . _pending_title } " )
else :
_cprint ( f " No title set. Usage: /title <your session title> " )
else :
_cprint ( " Session database not available. " )
2026-02-19 14:31:53 -08:00
elif cmd_lower in ( " /reset " , " /new " ) :
2026-01-31 06:30:48 +00:00
self . reset_conversation ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower . startswith ( " /model " ) :
# Use original case so model names like "Anthropic/Claude-Opus-4" are preserved
parts = cmd_original . split ( maxsplit = 1 )
2026-01-31 06:30:48 +00:00
if len ( parts ) > 1 :
2026-03-07 19:56:48 -08:00
from hermes_cli . auth import resolve_provider
2026-03-08 05:45:55 -07:00
from hermes_cli . models import (
parse_model_input ,
validate_requested_model ,
_PROVIDER_LABELS ,
)
2026-03-07 19:56:48 -08:00
2026-03-08 05:45:55 -07:00
raw_input = parts [ 1 ] . strip ( )
# Parse provider:model syntax (e.g. "openrouter:anthropic/claude-sonnet-4.5")
current_provider = self . provider or self . requested_provider or " openrouter "
target_provider , new_model = parse_model_input ( raw_input , current_provider )
provider_changed = target_provider != current_provider
# If provider is changing, re-resolve credentials for the new provider
api_key_for_probe = self . api_key
base_url_for_probe = self . base_url
if provider_changed :
try :
from hermes_cli . runtime_provider import resolve_runtime_provider
runtime = resolve_runtime_provider ( requested = target_provider )
api_key_for_probe = runtime . get ( " api_key " , " " )
base_url_for_probe = runtime . get ( " base_url " , " " )
except Exception as e :
provider_label = _PROVIDER_LABELS . get ( target_provider , target_provider )
print ( f " (>_<) Could not resolve credentials for provider ' { provider_label } ' : { e } " )
print ( f " (^_^) Current model unchanged: { self . model } " )
return True
2026-03-07 19:56:48 -08:00
fix: guard validate_requested_model + expand test coverage (PR #649 follow-up)
- Wrap validate_requested_model in try/except so /model doesn't crash
if validation itself fails (falls back to old accept+save behavior)
- Remove unnecessary sys.path.insert from both test files
- Expand test_model_validation.py: 4 → 23 tests covering normalize_provider,
provider_model_ids, empty/whitespace/spaces rejection, OpenRouter format
validation, custom endpoints, nous provider, provider aliases, unknown
providers, fuzzy suggestions
- Expand test_cli_model_command.py: 2 → 5 tests adding known-model save,
validation crash fallback, and /model with no argument
2026-03-08 04:47:31 -07:00
try :
validation = validate_requested_model (
new_model ,
2026-03-08 05:45:55 -07:00
target_provider ,
api_key = api_key_for_probe ,
base_url = base_url_for_probe ,
fix: guard validate_requested_model + expand test coverage (PR #649 follow-up)
- Wrap validate_requested_model in try/except so /model doesn't crash
if validation itself fails (falls back to old accept+save behavior)
- Remove unnecessary sys.path.insert from both test files
- Expand test_model_validation.py: 4 → 23 tests covering normalize_provider,
provider_model_ids, empty/whitespace/spaces rejection, OpenRouter format
validation, custom endpoints, nous provider, provider aliases, unknown
providers, fuzzy suggestions
- Expand test_cli_model_command.py: 2 → 5 tests adding known-model save,
validation crash fallback, and /model with no argument
2026-03-08 04:47:31 -07:00
)
except Exception :
validation = { " accepted " : True , " persist " : True , " recognized " : False , " message " : None }
2026-03-07 19:56:48 -08:00
if not validation . get ( " accepted " ) :
2026-03-08 06:13:11 -07:00
print ( f " (>_<) { validation . get ( ' message ' ) } " )
print ( f " Model unchanged: { self . model } " )
if " Did you mean " not in ( validation . get ( " message " ) or " " ) :
print ( " Tip: Use /model to see available models, /provider to see providers " )
2026-01-31 06:30:48 +00:00
else :
2026-03-07 19:56:48 -08:00
self . model = new_model
self . agent = None # Force re-init
2026-03-08 05:45:55 -07:00
if provider_changed :
self . requested_provider = target_provider
self . provider = target_provider
self . api_key = api_key_for_probe
self . base_url = base_url_for_probe
provider_label = _PROVIDER_LABELS . get ( target_provider , target_provider )
provider_note = f " [provider: { provider_label } ] " if provider_changed else " "
2026-03-07 19:56:48 -08:00
if validation . get ( " persist " ) :
2026-03-08 05:45:55 -07:00
saved_model = save_config_value ( " model.default " , new_model )
if provider_changed :
save_config_value ( " model.provider " , target_provider )
if saved_model :
print ( f " (^_^)b Model changed to: { new_model } { provider_note } (saved to config) " )
2026-03-07 19:56:48 -08:00
else :
2026-03-08 06:13:11 -07:00
print ( f " (^_^) Model changed to: { new_model } { provider_note } (this session only) " )
2026-03-07 19:56:48 -08:00
else :
2026-03-08 06:13:11 -07:00
message = validation . get ( " message " ) or " "
print ( f " (^_^) Model changed to: { new_model } { provider_note } (this session only) " )
if message :
print ( f " Reason: { message } " )
print ( " Note: Model will revert on restart. Use a verified model to save to config. " )
2026-01-31 06:30:48 +00:00
else :
2026-03-08 05:54:52 -07:00
from hermes_cli . models import curated_models_for_provider , normalize_provider , _PROVIDER_LABELS
2026-03-08 05:58:45 -07:00
from hermes_cli . auth import resolve_provider as _resolve_provider
# Resolve "auto" to the actual provider using credential detection
raw_provider = normalize_provider ( self . provider )
if raw_provider == " auto " :
try :
display_provider = _resolve_provider (
self . requested_provider ,
explicit_api_key = self . _explicit_api_key ,
explicit_base_url = self . _explicit_base_url ,
)
except Exception :
display_provider = " openrouter "
else :
display_provider = raw_provider
2026-03-08 05:54:52 -07:00
provider_label = _PROVIDER_LABELS . get ( display_provider , display_provider )
2026-03-08 05:45:55 -07:00
print ( f " \n Current model: { self . model } " )
print ( f " Current provider: { provider_label } " )
print ( )
2026-03-08 05:54:52 -07:00
curated = curated_models_for_provider ( display_provider )
2026-03-08 05:45:55 -07:00
if curated :
print ( f " Available models ( { provider_label } ): " )
for mid , desc in curated :
marker = " ← " if mid == self . model else " "
label = f " { desc } " if desc else " "
print ( f " { mid } { label } { marker } " )
print ( )
print ( " Usage: /model <model-name> " )
print ( " /model provider:model-name (to switch provider) " )
print ( " Example: /model openrouter:anthropic/claude-sonnet-4.5 " )
2026-03-08 06:09:36 -07:00
print ( " See /provider for available providers " )
elif cmd_lower == " /provider " :
from hermes_cli . models import list_available_providers , normalize_provider , _PROVIDER_LABELS
from hermes_cli . auth import resolve_provider as _resolve_provider
# Resolve current provider
raw_provider = normalize_provider ( self . provider )
if raw_provider == " auto " :
try :
current = _resolve_provider (
self . requested_provider ,
explicit_api_key = self . _explicit_api_key ,
explicit_base_url = self . _explicit_base_url ,
)
except Exception :
current = " openrouter "
else :
current = raw_provider
current_label = _PROVIDER_LABELS . get ( current , current )
print ( f " \n Current provider: { current_label } ( { current } ) \n " )
providers = list_available_providers ( )
print ( " Available providers: " )
for p in providers :
marker = " ← active " if p [ " id " ] == current else " "
auth = " ✓ " if p [ " authenticated " ] else " ✗ "
aliases = f " (also: { ' , ' . join ( p [ ' aliases ' ] ) } ) " if p [ " aliases " ] else " "
print ( f " [ { auth } ] { p [ ' id ' ] : <14 } { p [ ' label ' ] } { aliases } { marker } " )
print ( )
print ( " Switch: /model provider:model-name " )
print ( " Setup: hermes setup " )
2026-02-08 13:31:45 -08:00
elif cmd_lower . startswith ( " /prompt " ) :
# Use original case so prompt text isn't lowercased
self . _handle_prompt_command ( cmd_original )
elif cmd_lower . startswith ( " /personality " ) :
# Use original case (handler lowercases the personality name itself)
self . _handle_personality_command ( cmd_original )
2026-02-10 15:59:46 -08:00
elif cmd_lower == " /retry " :
retry_msg = self . retry_last ( )
if retry_msg and hasattr ( self , ' _pending_input ' ) :
# Re-queue the message so process_loop sends it to the agent
self . _pending_input . put ( retry_msg )
elif cmd_lower == " /undo " :
self . undo_last ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /save " :
2026-01-31 06:30:48 +00:00
self . save_conversation ( )
2026-02-08 13:31:45 -08:00
elif cmd_lower . startswith ( " /cron " ) :
self . _handle_cron_command ( cmd_original )
Add Skills Hub — universal skill search, install, and management from online registries
Implements the Hermes Skills Hub with agentskills.io spec compliance,
multi-registry skill discovery, security scanning, and user-driven
management via CLI and /skills slash command.
Core features:
- Security scanner (tools/skills_guard.py): 120 threat patterns across
12 categories, trust-aware install policy (builtin/trusted/community),
structural checks, unicode injection detection, LLM audit pass
- Hub client (tools/skills_hub.py): GitHub, ClawHub, Claude Code
marketplace, and LobeHub source adapters with shared GitHubAuth
(PAT + gh CLI + GitHub App), lock file provenance tracking, quarantine
flow, and unified search across all sources
- CLI interface (hermes_cli/skills_hub.py): search, install, inspect,
list, audit, uninstall, publish (GitHub PR), snapshot export/import,
and tap management — powers both `hermes skills` and `/skills`
Spec conformance (Phase 0):
- Upgraded frontmatter parser to yaml.safe_load with fallback
- Migrated 39 SKILL.md files: tags/related_skills to metadata.hermes.*
- Added assets/ directory support and compatibility/metadata fields
- Excluded .hub/ from skill discovery in skills_tool.py
Updated 13 config/doc files including README, AGENTS.md, .env.example,
setup wizard, doctor, status, pyproject.toml, and docs.
2026-02-18 16:09:05 -08:00
elif cmd_lower . startswith ( " /skills " ) :
2026-03-10 17:13:14 -07:00
with self . _busy_command ( self . _slow_command_status ( cmd_original ) ) :
self . _handle_skills_command ( cmd_original )
2026-02-08 13:31:45 -08:00
elif cmd_lower == " /platforms " or cmd_lower == " /gateway " :
2026-02-02 19:01:51 -08:00
self . _show_gateway_status ( )
2026-02-26 23:18:45 +00:00
elif cmd_lower == " /verbose " :
self . _toggle_verbose ( )
2026-03-01 00:16:38 -08:00
elif cmd_lower == " /compress " :
self . _manual_compress ( )
2026-03-01 00:23:19 -08:00
elif cmd_lower == " /usage " :
self . _show_usage ( )
feat: add /insights command with usage analytics and cost estimation
Inspired by Claude Code's /insights, adapted for Hermes Agent's multi-platform
architecture. Analyzes session history from state.db to produce comprehensive
usage insights.
Features:
- Overview stats: sessions, messages, tokens, estimated cost, active time
- Model breakdown: per-model sessions, tokens, and cost estimation
- Platform breakdown: CLI vs Telegram vs Discord etc. (unique to Hermes)
- Tool usage ranking: most-used tools with percentages
- Activity patterns: day-of-week chart, peak hours, streaks
- Notable sessions: longest, most messages, most tokens, most tool calls
- Cost estimation: real pricing data for 25+ models (OpenAI, Anthropic,
DeepSeek, Google, Meta) with fuzzy model name matching
- Configurable time window: --days flag (default 30)
- Source filtering: --source flag to filter by platform
Three entry points:
- /insights slash command in CLI (supports --days and --source flags)
- /insights slash command in gateway (compact markdown format)
- hermes insights CLI subcommand (standalone)
Includes 56 tests covering pricing helpers, format helpers, empty DB,
populated DB with multi-platform data, filtering, formatting, and edge cases.
2026-03-06 14:04:59 -08:00
elif cmd_lower . startswith ( " /insights " ) :
self . _show_insights ( cmd_original )
fix: clipboard image paste on WSL2, Wayland, and VSCode terminal
The original implementation only supported xclip (X11), which silently
fails on WSL2 (can't access Windows clipboard for images), Wayland
desktops (xclip is X11-only), and VSCode terminal on WSL2.
Clipboard backend changes (hermes_cli/clipboard.py):
- WSL2: detect via /proc/version, use powershell.exe with .NET
System.Windows.Forms.Clipboard to extract images as base64 PNG
- Wayland: use wl-paste with MIME type detection, auto-convert BMP
to PNG for WSLg environments (via Pillow or ImageMagick)
- Dispatch order: WSL → Wayland → X11 (xclip), with fallthrough
- New has_clipboard_image() for lightweight clipboard checks
- Cache WSL detection result per-process
CLI changes (cli.py):
- /paste command: explicit clipboard image check for terminals where
BracketedPaste doesn't fire (image-only clipboard in VSCode/WinTerm)
- Ctrl+V keybinding: fallback for Linux terminals where Ctrl+V sends
raw byte instead of triggering bracketed paste
Tests: 80 tests (up from 37) covering WSL, Wayland, X11 dispatch,
BMP conversion, has_clipboard_image, and /paste command.
2026-03-05 20:22:44 -08:00
elif cmd_lower == " /paste " :
self . _handle_paste_command ( )
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
elif cmd_lower == " /reload-mcp " :
2026-03-10 17:13:14 -07:00
with self . _busy_command ( self . _slow_command_status ( cmd_original ) ) :
self . _reload_mcp ( )
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
elif cmd_lower . startswith ( " /rollback " ) :
self . _handle_rollback_command ( cmd_original )
elif cmd_lower . startswith ( " /skin " ) :
self . _handle_skin_command ( cmd_original )
2026-01-31 06:30:48 +00:00
else :
2026-03-09 07:38:06 +03:00
# Check for user-defined quick commands (bypass agent loop, no LLM call)
2026-02-28 11:18:50 -08:00
base_cmd = cmd_lower . split ( ) [ 0 ]
2026-03-09 07:38:06 +03:00
quick_commands = self . config . get ( " quick_commands " , { } )
if base_cmd . lstrip ( " / " ) in quick_commands :
qcmd = quick_commands [ base_cmd . lstrip ( " / " ) ]
if qcmd . get ( " type " ) == " exec " :
import subprocess
exec_cmd = qcmd . get ( " command " , " " )
if exec_cmd :
try :
result = subprocess . run (
exec_cmd , shell = True , capture_output = True ,
text = True , timeout = 30
)
output = result . stdout . strip ( ) or result . stderr . strip ( )
self . console . print ( output if output else " [dim]Command returned no output[/] " )
except subprocess . TimeoutExpired :
self . console . print ( " [bold red]Quick command timed out (30s)[/] " )
except Exception as e :
self . console . print ( f " [bold red]Quick command error: { e } [/] " )
else :
self . console . print ( f " [bold red]Quick command ' { base_cmd } ' has no command defined[/] " )
else :
self . console . print ( f " [bold red]Quick command ' { base_cmd } ' has unsupported type (only ' exec ' is supported)[/] " )
# Check for skill slash commands (/gif-search, /axolotl, etc.)
elif base_cmd in _skill_commands :
2026-02-28 11:18:50 -08:00
user_instruction = cmd_original [ len ( base_cmd ) : ] . strip ( )
msg = build_skill_invocation_message ( base_cmd , user_instruction )
if msg :
skill_name = _skill_commands [ base_cmd ] [ " name " ]
print ( f " \n ⚡ Loading skill: { skill_name } " )
if hasattr ( self , ' _pending_input ' ) :
self . _pending_input . put ( msg )
else :
self . console . print ( f " [bold red]Failed to load skill for { base_cmd } [/] " )
else :
self . console . print ( f " [bold red]Unknown command: { cmd_lower } [/] " )
self . console . print ( " [dim #B8860B]Type /help for available commands[/] " )
2026-01-31 06:30:48 +00:00
return True
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
def _handle_skin_command ( self , cmd : str ) :
""" Handle /skin [name] — show or change the display skin. """
try :
from hermes_cli . skin_engine import list_skins , set_active_skin , get_active_skin_name
except ImportError :
print ( " Skin engine not available. " )
return
parts = cmd . strip ( ) . split ( maxsplit = 1 )
if len ( parts ) < 2 or not parts [ 1 ] . strip ( ) :
# Show current skin and list available
current = get_active_skin_name ( )
skins = list_skins ( )
print ( f " \n Current skin: { current } " )
print ( f " Available skins: " )
for s in skins :
marker = " ● " if s [ " name " ] == current else " "
source = f " ( { s [ ' source ' ] } ) " if s [ " source " ] == " user " else " "
print ( f " { marker } { s [ ' name ' ] } { source } — { s [ ' description ' ] } " )
print ( f " \n Usage: /skin <name> " )
print ( f " Custom skins: drop a YAML file in ~/.hermes/skins/ \n " )
return
new_skin = parts [ 1 ] . strip ( ) . lower ( )
available = { s [ " name " ] for s in list_skins ( ) }
if new_skin not in available :
print ( f " Unknown skin: { new_skin } " )
print ( f " Available: { ' , ' . join ( sorted ( available ) ) } " )
return
set_active_skin ( new_skin )
if save_config_value ( " display.skin " , new_skin ) :
print ( f " Skin set to: { new_skin } (saved) " )
else :
print ( f " Skin set to: { new_skin } " )
print ( " Note: banner colors will update on next session start. " )
2026-02-26 23:18:45 +00:00
def _toggle_verbose ( self ) :
2026-02-28 00:05:58 -08:00
""" Cycle tool progress mode: off → new → all → verbose → off. """
cycle = [ " off " , " new " , " all " , " verbose " ]
try :
idx = cycle . index ( self . tool_progress_mode )
except ValueError :
idx = 2 # default to "all"
self . tool_progress_mode = cycle [ ( idx + 1 ) % len ( cycle ) ]
self . verbose = self . tool_progress_mode == " verbose "
2026-02-26 23:18:45 +00:00
if self . agent :
self . agent . verbose_logging = self . verbose
self . agent . quiet_mode = not self . verbose
2026-02-28 00:05:58 -08:00
labels = {
" off " : " [dim]Tool progress: OFF[/] — silent mode, just the final response. " ,
" new " : " [yellow]Tool progress: NEW[/] — show each new tool (skip repeats). " ,
" all " : " [green]Tool progress: ALL[/] — show every tool call. " ,
" verbose " : " [bold green]Tool progress: VERBOSE[/] — full args, results, and debug logs. " ,
}
self . console . print ( labels . get ( self . tool_progress_mode , " " ) )
2026-03-01 00:16:38 -08:00
def _manual_compress ( self ) :
""" Manually trigger context compression on the current conversation. """
if not self . conversation_history or len ( self . conversation_history ) < 4 :
print ( " (._.) Not enough conversation to compress (need at least 4 messages). " )
return
if not self . agent :
print ( " (._.) No active agent -- send a message first. " )
return
if not self . agent . compression_enabled :
print ( " (._.) Compression is disabled in config. " )
return
original_count = len ( self . conversation_history )
try :
from agent . model_metadata import estimate_messages_tokens_rough
approx_tokens = estimate_messages_tokens_rough ( self . conversation_history )
print ( f " 🗜️ Compressing { original_count } messages (~ { approx_tokens : , } tokens)... " )
compressed , new_system = self . agent . _compress_context (
self . conversation_history ,
self . agent . _cached_system_prompt or " " ,
approx_tokens = approx_tokens ,
)
self . conversation_history = compressed
new_count = len ( self . conversation_history )
new_tokens = estimate_messages_tokens_rough ( self . conversation_history )
print (
f " ✅ Compressed: { original_count } → { new_count } messages "
f " (~ { approx_tokens : , } → ~ { new_tokens : , } tokens) "
)
except Exception as e :
print ( f " ❌ Compression failed: { e } " )
2026-03-01 00:23:19 -08:00
def _show_usage ( self ) :
""" Show cumulative token usage for the current session. """
if not self . agent :
print ( " (._.) No active agent -- send a message first. " )
return
agent = self . agent
prompt = agent . session_prompt_tokens
completion = agent . session_completion_tokens
total = agent . session_total_tokens
calls = agent . session_api_calls
if calls == 0 :
print ( " (._.) No API calls made yet in this session. " )
return
# Current context window state
compressor = agent . context_compressor
last_prompt = compressor . last_prompt_tokens
ctx_len = compressor . context_length
pct = ( last_prompt / ctx_len * 100 ) if ctx_len else 0
compressions = compressor . compression_count
msg_count = len ( self . conversation_history )
print ( f " 📊 Session Token Usage " )
print ( f " { ' ─ ' * 40 } " )
print ( f " Prompt tokens (input): { prompt : >10, } " )
print ( f " Completion tokens (output): { completion : >9, } " )
print ( f " Total tokens: { total : >10, } " )
print ( f " API calls: { calls : >10, } " )
print ( f " { ' ─ ' * 40 } " )
print ( f " Current context: { last_prompt : , } / { ctx_len : , } ( { pct : .0f } %) " )
print ( f " Messages: { msg_count } " )
print ( f " Compressions: { compressions } " )
2026-02-26 23:18:45 +00:00
if self . verbose :
logging . getLogger ( ) . setLevel ( logging . DEBUG )
for noisy in ( ' openai ' , ' openai._base_client ' , ' httpx ' , ' httpcore ' , ' asyncio ' , ' hpack ' , ' grpc ' , ' modal ' ) :
logging . getLogger ( noisy ) . setLevel ( logging . WARNING )
else :
logging . getLogger ( ) . setLevel ( logging . INFO )
for quiet_logger in ( ' tools ' , ' minisweagent ' , ' run_agent ' , ' trajectory_compressor ' , ' cron ' , ' hermes_cli ' ) :
logging . getLogger ( quiet_logger ) . setLevel ( logging . ERROR )
feat: add /insights command with usage analytics and cost estimation
Inspired by Claude Code's /insights, adapted for Hermes Agent's multi-platform
architecture. Analyzes session history from state.db to produce comprehensive
usage insights.
Features:
- Overview stats: sessions, messages, tokens, estimated cost, active time
- Model breakdown: per-model sessions, tokens, and cost estimation
- Platform breakdown: CLI vs Telegram vs Discord etc. (unique to Hermes)
- Tool usage ranking: most-used tools with percentages
- Activity patterns: day-of-week chart, peak hours, streaks
- Notable sessions: longest, most messages, most tokens, most tool calls
- Cost estimation: real pricing data for 25+ models (OpenAI, Anthropic,
DeepSeek, Google, Meta) with fuzzy model name matching
- Configurable time window: --days flag (default 30)
- Source filtering: --source flag to filter by platform
Three entry points:
- /insights slash command in CLI (supports --days and --source flags)
- /insights slash command in gateway (compact markdown format)
- hermes insights CLI subcommand (standalone)
Includes 56 tests covering pricing helpers, format helpers, empty DB,
populated DB with multi-platform data, filtering, formatting, and edge cases.
2026-03-06 14:04:59 -08:00
def _show_insights ( self , command : str = " /insights " ) :
""" Show usage insights and analytics from session history. """
# Parse optional --days flag
parts = command . split ( )
days = 30
source = None
i = 1
while i < len ( parts ) :
if parts [ i ] == " --days " and i + 1 < len ( parts ) :
try :
days = int ( parts [ i + 1 ] )
except ValueError :
print ( f " Invalid --days value: { parts [ i + 1 ] } " )
return
i + = 2
elif parts [ i ] == " --source " and i + 1 < len ( parts ) :
source = parts [ i + 1 ]
i + = 2
else :
i + = 1
try :
from hermes_state import SessionDB
from agent . insights import InsightsEngine
db = SessionDB ( )
engine = InsightsEngine ( db )
report = engine . generate ( days = days , source = source )
print ( engine . format_terminal ( report ) )
db . close ( )
except Exception as e :
print ( f " Error generating insights: { e } " )
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
def _reload_mcp ( self ) :
2026-03-02 19:25:06 -08:00
""" Reload MCP servers: disconnect all, re-read config.yaml, reconnect.
After reconnecting , refreshes the agent ' s tool list so the model
sees the updated tools on the next turn .
"""
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
try :
from tools . mcp_tool import shutdown_mcp_servers , discover_mcp_tools , _load_mcp_config , _servers , _lock
# Capture old server names
with _lock :
old_servers = set ( _servers . keys ( ) )
2026-03-10 17:13:14 -07:00
if not self . _command_running :
print ( " 🔄 Reloading MCP servers... " )
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
# Shutdown existing connections
shutdown_mcp_servers ( )
# Reconnect (reads config.yaml fresh)
new_tools = discover_mcp_tools ( )
# Compute what changed
with _lock :
connected_servers = set ( _servers . keys ( ) )
added = connected_servers - old_servers
removed = old_servers - connected_servers
reconnected = connected_servers & old_servers
if reconnected :
print ( f " ♻️ Reconnected: { ' , ' . join ( sorted ( reconnected ) ) } " )
if added :
print ( f " ➕ Added: { ' , ' . join ( sorted ( added ) ) } " )
if removed :
print ( f " ➖ Removed: { ' , ' . join ( sorted ( removed ) ) } " )
if not connected_servers :
2026-03-02 19:25:06 -08:00
print ( " No MCP servers connected. " )
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
else :
print ( f " 🔧 { len ( new_tools ) } tool(s) available from { len ( connected_servers ) } server(s) " )
2026-03-02 19:25:06 -08:00
# Refresh the agent's tool list so the model can call new tools
if self . agent is not None :
from model_tools import get_tool_definitions
self . agent . tools = get_tool_definitions (
enabled_toolsets = self . agent . enabled_toolsets
if hasattr ( self . agent , " enabled_toolsets " ) else None ,
quiet_mode = True ,
)
self . agent . valid_tool_names = {
tool [ " function " ] [ " name " ] for tool in self . agent . tools
} if self . agent . tools else set ( )
# Inject a message at the END of conversation history so the
# model knows tools changed. Appended after all existing
# messages to preserve prompt-cache for the prefix.
change_parts = [ ]
if added :
change_parts . append ( f " Added servers: { ' , ' . join ( sorted ( added ) ) } " )
if removed :
change_parts . append ( f " Removed servers: { ' , ' . join ( sorted ( removed ) ) } " )
if reconnected :
change_parts . append ( f " Reconnected servers: { ' , ' . join ( sorted ( reconnected ) ) } " )
tool_summary = f " { len ( new_tools ) } MCP tool(s) now available " if new_tools else " No MCP tools available "
change_detail = " . " . join ( change_parts ) + " . " if change_parts else " "
self . conversation_history . append ( {
" role " : " user " ,
" content " : f " [SYSTEM: MCP servers have been reloaded. { change_detail } { tool_summary } . The tool list for this conversation has been updated accordingly.] " ,
} )
2026-03-02 21:31:23 -08:00
# Persist session immediately so the session log reflects the
# updated tools list (self.agent.tools was refreshed above).
if self . agent is not None :
try :
self . agent . _persist_session (
self . conversation_history ,
self . conversation_history ,
)
except Exception :
pass # Best-effort
2026-03-02 19:25:06 -08:00
print ( f " ✅ Agent updated — { len ( self . agent . tools if self . agent else [ ] ) } tool(s) available " )
feat(mcp): banner integration, /reload-mcp command, resources & prompts
Banner integration:
- MCP Servers section in CLI startup banner between Tools and Skills
- Shows each server with transport type, tool count, connection status
- Failed servers shown in red; section hidden when no MCP configured
- Summary line includes MCP server count
- Removed raw print() calls from discovery (banner handles display)
/reload-mcp command:
- New slash command in both CLI and gateway
- Disconnects all MCP servers, re-reads config.yaml, reconnects
- Reports what changed (added/removed/reconnected servers)
- Allows adding/removing MCP servers without restarting
Resources & Prompts support:
- 4 utility tools registered per server: list_resources, read_resource,
list_prompts, get_prompt
- Exposes MCP Resources (data sources) and Prompts (templates) as tools
- Proper parameter schemas (uri for read_resource, name for get_prompt)
- Handles text and binary resource content
- 23 new tests covering schemas, handlers, and registration
Test coverage: 74 MCP tests total, 1186 tests pass overall.
2026-03-02 19:15:59 -08:00
except Exception as e :
print ( f " ❌ MCP reload failed: { e } " )
2026-02-19 20:06:14 -08:00
def _clarify_callback ( self , question , choices ) :
"""
Platform callback for the clarify tool . Called from the agent thread .
Sets up the interactive selection UI ( or freetext prompt for open - ended
questions ) , then blocks until the user responds via the prompt_toolkit
2026-02-19 20:11:54 -08:00
key bindings . If no response arrives within the configured timeout the
2026-02-19 20:06:14 -08:00
question is dismissed and the agent is told to decide on its own .
"""
2026-02-19 20:11:54 -08:00
import time as _time
timeout = CLI_CONFIG . get ( " clarify " , { } ) . get ( " timeout " , 120 )
2026-02-19 20:06:14 -08:00
response_queue = queue . Queue ( )
is_open_ended = not choices or len ( choices ) == 0
self . _clarify_state = {
" question " : question ,
" choices " : choices if not is_open_ended else [ ] ,
" selected " : 0 ,
" response_queue " : response_queue ,
}
2026-02-19 20:11:54 -08:00
self . _clarify_deadline = _time . monotonic ( ) + timeout
2026-02-19 20:06:14 -08:00
# Open-ended questions skip straight to freetext input
self . _clarify_freetext = is_open_ended
# Trigger prompt_toolkit repaint from this (non-main) thread
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-19 20:06:14 -08:00
2026-03-10 07:04:02 -07:00
# Poll for the user's response. The countdown in the hint line
# updates on each invalidate — but frequent repaints cause visible
# flicker in some terminals (Kitty, ghostty). We only refresh the
# countdown every 5 s; selection changes (↑/↓) trigger instant
2026-03-10 06:44:13 -07:00
# Poll for the user's response. The countdown in the hint line
# updates on each invalidate — but frequent repaints cause visible
# flicker in some terminals (Kitty, ghostty). We only refresh the
# countdown every 5 s; selection changes (↑/↓) trigger instant
# repaints via the key bindings.
_last_countdown_refresh = _time . monotonic ( )
2026-02-19 20:11:54 -08:00
while True :
try :
result = response_queue . get ( timeout = 1 )
self . _clarify_deadline = 0
return result
except queue . Empty :
remaining = self . _clarify_deadline - _time . monotonic ( )
if remaining < = 0 :
break
2026-03-10 06:44:13 -07:00
# Only repaint every 5 s for the countdown — avoids flicker
now = _time . monotonic ( )
if now - _last_countdown_refresh > = 5.0 :
_last_countdown_refresh = now
self . _invalidate ( )
2026-03-10 07:04:02 -07:00
if now - _last_countdown_refresh > = 5.0 :
_last_countdown_refresh = now
self . _invalidate ( )
2026-02-19 20:11:54 -08:00
# Timed out — tear down the UI and let the agent decide
self . _clarify_state = None
self . _clarify_freetext = False
self . _clarify_deadline = 0
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-19 20:11:54 -08:00
_cprint ( f " \n { _DIM } (clarify timed out after { timeout } s — agent will decide) { _RST } " )
return (
" The user did not provide a response within the time limit. "
" Use your best judgement to make the choice and proceed. "
)
2026-02-19 20:06:14 -08:00
2026-02-21 12:15:40 -08:00
def _sudo_password_callback ( self ) - > str :
"""
Prompt for sudo password through the prompt_toolkit UI .
Called from the agent thread when a sudo command is encountered .
Uses the same clarify - style mechanism : sets UI state , waits on a
queue for the user ' s response via the Enter key binding.
"""
import time as _time
timeout = 45
response_queue = queue . Queue ( )
self . _sudo_state = {
" response_queue " : response_queue ,
}
self . _sudo_deadline = _time . monotonic ( ) + timeout
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
while True :
try :
result = response_queue . get ( timeout = 1 )
self . _sudo_state = None
self . _sudo_deadline = 0
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
if result :
_cprint ( f " \n { _DIM } ✓ Password received (cached for session) { _RST } " )
else :
_cprint ( f " \n { _DIM } ⏭ Skipped { _RST } " )
return result
except queue . Empty :
remaining = self . _sudo_deadline - _time . monotonic ( )
if remaining < = 0 :
break
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
self . _sudo_state = None
self . _sudo_deadline = 0
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
_cprint ( f " \n { _DIM } ⏱ Timeout — continuing without sudo { _RST } " )
return " "
def _approval_callback ( self , command : str , description : str ) - > str :
"""
Prompt for dangerous command approval through the prompt_toolkit UI .
Called from the agent thread . Shows a selection UI similar to clarify
with choices : once / session / always / deny .
"""
import time as _time
timeout = 60
response_queue = queue . Queue ( )
choices = [ " once " , " session " , " always " , " deny " ]
self . _approval_state = {
" command " : command ,
" description " : description ,
" choices " : choices ,
" selected " : 0 ,
" response_queue " : response_queue ,
}
self . _approval_deadline = _time . monotonic ( ) + timeout
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
2026-03-10 06:44:13 -07:00
# Same throttled countdown as _clarify_callback — repaint only
# every 5 s to avoid flicker in Kitty / ghostty / etc.
_last_countdown_refresh = _time . monotonic ( )
2026-02-21 12:15:40 -08:00
while True :
try :
result = response_queue . get ( timeout = 1 )
self . _approval_state = None
self . _approval_deadline = 0
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
return result
except queue . Empty :
remaining = self . _approval_deadline - _time . monotonic ( )
if remaining < = 0 :
break
2026-03-10 06:44:13 -07:00
now = _time . monotonic ( )
if now - _last_countdown_refresh > = 5.0 :
_last_countdown_refresh = now
self . _invalidate ( )
2026-02-21 12:15:40 -08:00
self . _approval_state = None
self . _approval_deadline = 0
2026-03-02 15:56:53 +01:00
self . _invalidate ( )
2026-03-07 19:30:00 +03:00
return " deny "
2026-03-05 17:53:58 -08:00
def chat ( self , message , images : list = None ) - > Optional [ str ] :
2026-01-31 06:30:48 +00:00
"""
Send a message to the agent and get a response .
2026-03-05 17:53:58 -08:00
Handles streaming output , interrupt detection ( user typing while agent
is working ) , and re - queueing of interrupted messages .
2026-02-08 13:31:45 -08:00
Uses a dedicated _interrupt_queue ( separate from _pending_input ) to avoid
race conditions between the process_loop and interrupt monitoring . Messages
typed while the agent is running go to _interrupt_queue ; messages typed while
idle go to _pending_input .
2026-01-31 06:30:48 +00:00
Args :
2026-03-05 17:53:58 -08:00
message : The user ' s message (str or multimodal content list)
images : Optional list of Path objects for attached images
2026-01-31 06:30:48 +00:00
Returns :
The agent ' s response, or None on error
"""
2026-02-25 18:20:38 -08:00
# Refresh provider credentials if needed (handles key rotation transparently)
if not self . _ensure_runtime_credentials ( ) :
2026-02-20 17:24:00 -08:00
return None
2026-01-31 06:30:48 +00:00
# Initialize agent if needed
if not self . _init_agent ( ) :
return None
2026-03-08 06:21:53 -07:00
# Pre-process images through the vision tool (Gemini Flash) so the
# main model receives text descriptions instead of raw base64 image
# content — works with any model, not just vision-capable ones.
2026-03-05 17:53:58 -08:00
if images :
2026-03-08 06:21:53 -07:00
message = self . _preprocess_images_with_vision (
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
message if isinstance ( message , str ) else " " , images
)
2026-03-05 17:53:58 -08:00
2026-01-31 06:30:48 +00:00
# Add user message to history
self . conversation_history . append ( { " role " : " user " , " content " : message } )
2026-03-10 07:04:02 -07:00
_cprint ( f " { _GOLD } { ' ─ ' * 40 } { _RST } " )
2026-02-19 01:23:23 -08:00
print ( flush = True )
2026-01-31 06:30:48 +00:00
try :
2026-02-03 16:15:49 -08:00
# Run the conversation with interrupt monitoring
result = None
def run_agent ( ) :
nonlocal result
result = self . agent . run_conversation (
user_message = message ,
conversation_history = self . conversation_history [ : - 1 ] , # Exclude the message we just added
2026-03-04 22:43:42 -08:00
task_id = self . session_id ,
2026-02-03 16:15:49 -08:00
)
# Start agent in background thread
agent_thread = threading . Thread ( target = run_agent )
agent_thread . start ( )
2026-02-08 13:31:45 -08:00
# Monitor the dedicated interrupt queue while the agent runs.
# _interrupt_queue is separate from _pending_input, so process_loop
# and chat() never compete for the same queue.
2026-02-19 20:06:14 -08:00
# When a clarify question is active, user input is handled entirely
# by the Enter key binding (routed to the clarify response queue),
# so we skip interrupt processing to avoid stealing that input.
2026-02-03 16:15:49 -08:00
interrupt_msg = None
while agent_thread . is_alive ( ) :
2026-02-08 13:31:45 -08:00
if hasattr ( self , ' _interrupt_queue ' ) :
2026-02-03 16:15:49 -08:00
try :
2026-02-08 13:31:45 -08:00
interrupt_msg = self . _interrupt_queue . get ( timeout = 0.1 )
2026-02-03 16:15:49 -08:00
if interrupt_msg :
2026-02-19 20:06:14 -08:00
# If clarify is active, the Enter handler routes
# input directly; this queue shouldn't have anything.
# But if it does (race condition), don't interrupt.
if self . _clarify_state or self . _clarify_freetext :
continue
2026-02-03 16:15:49 -08:00
print ( f " \n ⚡ New message detected, interrupting... " )
self . agent . interrupt ( interrupt_msg )
break
2026-02-08 13:31:45 -08:00
except queue . Empty :
2026-02-03 16:15:49 -08:00
pass # Queue empty or timeout, continue waiting
else :
2026-02-08 13:31:45 -08:00
# Fallback for non-interactive mode (e.g., single-query)
2026-02-03 16:15:49 -08:00
agent_thread . join ( 0.1 )
agent_thread . join ( ) # Ensure agent thread completes
2026-02-19 01:43:15 -08:00
# Drain any remaining agent output still in the StdoutProxy
# buffer so tool/status lines render ABOVE our response box.
2026-02-19 01:46:56 -08:00
# The flush pushes data into the renderer queue; the short
# sleep lets the renderer actually paint it before we draw.
import time as _time
2026-02-19 01:43:15 -08:00
sys . stdout . flush ( )
2026-02-19 01:46:56 -08:00
_time . sleep ( 0.15 )
2026-02-19 01:43:15 -08:00
2026-01-31 06:30:48 +00:00
# Update history with full conversation
2026-02-03 16:15:49 -08:00
self . conversation_history = result . get ( " messages " , self . conversation_history ) if result else self . conversation_history
2026-01-31 06:30:48 +00:00
# Get the final response
2026-02-03 16:15:49 -08:00
response = result . get ( " final_response " , " " ) if result else " "
2026-02-08 10:49:24 +00:00
# Handle failed results (e.g., non-retryable errors like invalid model)
if result and result . get ( " failed " ) and not response :
error_detail = result . get ( " error " , " Unknown error " )
response = f " Error: { error_detail } "
2026-02-03 16:15:49 -08:00
# Handle interrupt - check if we were interrupted
pending_message = None
if result and result . get ( " interrupted " ) :
pending_message = result . get ( " interrupt_message " ) or interrupt_msg
# Add indicator that we were interrupted
if response and pending_message :
response = response + " \n \n --- \n _[Interrupted - processing new message]_ "
2026-01-31 06:30:48 +00:00
if response :
2026-03-10 07:04:02 -07:00
# Use a Rich Panel for the response box — adapts to terminal
# width at render time instead of hard-coding border length.
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
try :
from hermes_cli . skin_engine import get_active_skin
_skin = get_active_skin ( )
2026-03-10 07:04:02 -07:00
label = _skin . get_branding ( " response_label " , " ⚕ Hermes " )
_resp_color = _skin . get_color ( " response_border " , " #CD7F32 " )
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
except Exception :
2026-03-10 07:04:02 -07:00
label = " ⚕ Hermes "
_resp_color = " #CD7F32 "
_chat_console = ChatConsole ( )
_chat_console . print ( Panel (
response ,
title = f " [bold] { label } [/bold] " ,
title_align = " left " ,
border_style = _resp_color ,
2026-03-10 15:59:08 -07:00
box = rich_box . HORIZONTALS ,
2026-03-10 07:04:02 -07:00
padding = ( 1 , 2 ) ,
) )
2026-01-31 06:30:48 +00:00
2026-03-08 19:41:17 -07:00
# Play terminal bell when agent finishes (if enabled).
# Works over SSH — the bell propagates to the user's terminal.
if self . bell_on_complete :
sys . stdout . write ( " \a " )
sys . stdout . flush ( )
2026-02-23 02:11:33 -08:00
# Combine all interrupt messages (user may have typed multiple while waiting)
# and re-queue as one prompt for process_loop
2026-02-08 13:31:45 -08:00
if pending_message and hasattr ( self , ' _pending_input ' ) :
2026-02-23 02:11:33 -08:00
all_parts = [ pending_message ]
while not self . _interrupt_queue . empty ( ) :
try :
extra = self . _interrupt_queue . get_nowait ( )
if extra :
all_parts . append ( extra )
except queue . Empty :
break
combined = " \n " . join ( all_parts )
print ( f " \n 📨 Queued: ' { combined [ : 50 ] } { ' ... ' if len ( combined ) > 50 else ' ' } ' " )
self . _pending_input . put ( combined )
2026-02-03 16:15:49 -08:00
2026-01-31 06:30:48 +00:00
return response
except Exception as e :
print ( f " Error: { e } " )
return None
2026-02-25 22:56:12 -08:00
def _print_exit_summary ( self ) :
""" Print session resume info on exit, similar to Claude Code. """
print ( )
msg_count = len ( self . conversation_history )
if msg_count > 0 :
user_msgs = len ( [ m for m in self . conversation_history if m . get ( " role " ) == " user " ] )
tool_calls = len ( [ m for m in self . conversation_history if m . get ( " role " ) == " tool " or m . get ( " tool_calls " ) ] )
elapsed = datetime . now ( ) - self . session_start
hours , remainder = divmod ( int ( elapsed . total_seconds ( ) ) , 3600 )
minutes , seconds = divmod ( remainder , 60 )
if hours > 0 :
duration_str = f " { hours } h { minutes } m { seconds } s "
elif minutes > 0 :
duration_str = f " { minutes } m { seconds } s "
else :
duration_str = f " { seconds } s "
print ( f " Resume this session with: " )
print ( f " hermes --resume { self . session_id } " )
print ( )
print ( f " Session: { self . session_id } " )
print ( f " Duration: { duration_str } " )
print ( f " Messages: { msg_count } ( { user_msgs } user, { tool_calls } tool calls) " )
else :
print ( " Goodbye! ⚕ " )
2026-01-31 06:30:48 +00:00
def run ( self ) :
2026-02-03 16:15:49 -08:00
""" Run the interactive CLI loop with persistent input at bottom. """
2026-01-31 06:30:48 +00:00
self . show_banner ( )
2026-03-08 17:45:45 -07:00
# If resuming a session, load history and display it immediately
# so the user has context before typing their first message.
if self . _resumed :
if self . _preload_resumed_session ( ) :
self . _display_resumed_history ( )
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
try :
from hermes_cli . skin_engine import get_active_skin
_welcome_skin = get_active_skin ( )
_welcome_text = _welcome_skin . get_branding ( " welcome " , " Welcome to Hermes Agent! Type your message or /help for commands. " )
_welcome_color = _welcome_skin . get_color ( " banner_text " , " #FFF8DC " )
except Exception :
_welcome_text = " Welcome to Hermes Agent! Type your message or /help for commands. "
_welcome_color = " #FFF8DC "
self . console . print ( f " [ { _welcome_color } ] { _welcome_text } [/] " )
2026-01-31 06:30:48 +00:00
self . console . print ( )
2026-02-03 16:15:49 -08:00
# State for async operation
self . _agent_running = False
2026-02-08 13:31:45 -08:00
self . _pending_input = queue . Queue ( ) # For normal input (commands + new queries)
self . _interrupt_queue = queue . Queue ( ) # For messages typed while agent is running
2026-02-03 16:15:49 -08:00
self . _should_exit = False
2026-02-08 10:49:24 +00:00
self . _last_ctrl_c_time = 0 # Track double Ctrl+C for force exit
2026-02-19 20:06:14 -08:00
# Clarify tool state: interactive question/answer with the user.
# When the agent calls the clarify tool, _clarify_state is set and
# the prompt_toolkit UI switches to a selection mode.
self . _clarify_state = None # dict with question, choices, selected, response_queue
self . _clarify_freetext = False # True when user chose "Other" and is typing
2026-02-19 20:11:54 -08:00
self . _clarify_deadline = 0 # monotonic timestamp when the clarify times out
2026-02-21 12:15:40 -08:00
# Sudo password prompt state (similar mechanism to clarify)
self . _sudo_state = None # dict with response_queue when active
self . _sudo_deadline = 0
# Dangerous command approval state (similar mechanism to clarify)
self . _approval_state = None # dict with command, description, choices, selected, response_queue
self . _approval_deadline = 0
2026-03-10 17:13:14 -07:00
# Slash command loading state
self . _command_running = False
self . _command_status = " "
2026-03-05 17:53:58 -08:00
# Clipboard image attachments (paste images into the CLI)
self . _attached_images : list [ Path ] = [ ]
self . _image_counter = 0
2026-02-21 12:15:40 -08:00
# Register callbacks so terminal_tool prompts route through our UI
set_sudo_password_callback ( self . _sudo_password_callback )
set_approval_callback ( self . _approval_callback )
2026-02-03 16:15:49 -08:00
# Key bindings for the input area
kb = KeyBindings ( )
@kb.add ( ' enter ' )
def handle_enter ( event ) :
2026-02-08 13:31:45 -08:00
""" Handle Enter key - submit input.
2026-02-21 12:15:40 -08:00
Routes to the correct queue based on active UI state :
- Sudo password prompt : password goes to sudo response queue
- Approval selection : selected choice goes to approval response queue
2026-02-19 20:06:14 -08:00
- Clarify freetext mode : answer goes to the clarify response queue
- Clarify choice mode : selected choice goes to the clarify response queue
2026-02-08 13:31:45 -08:00
- Agent running : goes to _interrupt_queue ( chat ( ) monitors this )
- Agent idle : goes to _pending_input ( process_loop monitors this )
Commands ( starting with / ) always go to _pending_input so they ' re
handled as commands , not sent as interrupt text to the agent .
"""
2026-02-21 12:15:40 -08:00
# --- Sudo password prompt: submit the typed password ---
if self . _sudo_state :
text = event . app . current_buffer . text
self . _sudo_state [ " response_queue " ] . put ( text )
self . _sudo_state = None
event . app . current_buffer . reset ( )
event . app . invalidate ( )
return
# --- Approval selection: confirm the highlighted choice ---
if self . _approval_state :
state = self . _approval_state
selected = state [ " selected " ]
choices = state [ " choices " ]
if 0 < = selected < len ( choices ) :
state [ " response_queue " ] . put ( choices [ selected ] )
self . _approval_state = None
event . app . invalidate ( )
return
2026-02-19 20:06:14 -08:00
# --- Clarify freetext mode: user typed their own answer ---
if self . _clarify_freetext and self . _clarify_state :
text = event . app . current_buffer . text . strip ( )
if text :
self . _clarify_state [ " response_queue " ] . put ( text )
self . _clarify_state = None
self . _clarify_freetext = False
event . app . current_buffer . reset ( )
event . app . invalidate ( )
return
# --- Clarify choice mode: confirm the highlighted selection ---
if self . _clarify_state and not self . _clarify_freetext :
state = self . _clarify_state
selected = state [ " selected " ]
choices = state . get ( " choices " ) or [ ]
if selected < len ( choices ) :
state [ " response_queue " ] . put ( choices [ selected ] )
self . _clarify_state = None
event . app . invalidate ( )
else :
# "Other" selected → switch to freetext
self . _clarify_freetext = True
event . app . invalidate ( )
return
# --- Normal input routing ---
2026-02-03 16:15:49 -08:00
text = event . app . current_buffer . text . strip ( )
2026-03-05 17:53:58 -08:00
has_images = bool ( self . _attached_images )
if text or has_images :
# Snapshot and clear attached images
images = list ( self . _attached_images )
self . _attached_images . clear ( )
event . app . invalidate ( )
# Bundle text + images as a tuple when images are present
payload = ( text , images ) if images else text
if self . _agent_running and not ( text and text . startswith ( " / " ) ) :
self . _interrupt_queue . put ( payload )
2026-02-08 13:31:45 -08:00
else :
2026-03-05 17:53:58 -08:00
self . _pending_input . put ( payload )
2026-03-04 13:39:48 -08:00
event . app . current_buffer . reset ( append_to_history = True )
2026-02-03 16:15:49 -08:00
2026-02-17 21:53:19 -08:00
@kb.add ( ' escape ' , ' enter ' )
def handle_alt_enter ( event ) :
2026-02-17 22:51:25 -08:00
""" Alt+Enter inserts a newline for multi-line input. """
event . current_buffer . insert_text ( ' \n ' )
@kb.add ( ' c-j ' )
def handle_ctrl_enter ( event ) :
""" Ctrl+Enter (c-j) inserts a newline. Most terminals send c-j for Ctrl+Enter. """
2026-02-17 21:47:54 -08:00
event . current_buffer . insert_text ( ' \n ' )
2026-02-19 20:06:14 -08:00
# --- Clarify tool: arrow-key navigation for multiple-choice questions ---
@kb.add ( ' up ' , filter = Condition ( lambda : bool ( self . _clarify_state ) and not self . _clarify_freetext ) )
def clarify_up ( event ) :
""" Move selection up in clarify choices. """
if self . _clarify_state :
self . _clarify_state [ " selected " ] = max ( 0 , self . _clarify_state [ " selected " ] - 1 )
event . app . invalidate ( )
@kb.add ( ' down ' , filter = Condition ( lambda : bool ( self . _clarify_state ) and not self . _clarify_freetext ) )
def clarify_down ( event ) :
""" Move selection down in clarify choices. """
if self . _clarify_state :
choices = self . _clarify_state . get ( " choices " ) or [ ]
max_idx = len ( choices ) # last index is the "Other" option
self . _clarify_state [ " selected " ] = min ( max_idx , self . _clarify_state [ " selected " ] + 1 )
event . app . invalidate ( )
2026-02-21 12:15:40 -08:00
# --- Dangerous command approval: arrow-key navigation ---
@kb.add ( ' up ' , filter = Condition ( lambda : bool ( self . _approval_state ) ) )
def approval_up ( event ) :
if self . _approval_state :
self . _approval_state [ " selected " ] = max ( 0 , self . _approval_state [ " selected " ] - 1 )
event . app . invalidate ( )
@kb.add ( ' down ' , filter = Condition ( lambda : bool ( self . _approval_state ) ) )
def approval_down ( event ) :
if self . _approval_state :
max_idx = len ( self . _approval_state [ " choices " ] ) - 1
self . _approval_state [ " selected " ] = min ( max_idx , self . _approval_state [ " selected " ] + 1 )
event . app . invalidate ( )
2026-03-04 13:39:48 -08:00
# --- History navigation: up/down browse history in normal input mode ---
# The TextArea is multiline, so by default up/down only move the cursor.
# Buffer.auto_up/auto_down handle both: cursor movement when multi-line,
# history browsing when on the first/last line (or single-line input).
_normal_input = Condition (
lambda : not self . _clarify_state and not self . _approval_state and not self . _sudo_state
)
@kb.add ( ' up ' , filter = _normal_input )
def history_up ( event ) :
""" Up arrow: browse history when on first line, else move cursor up. """
event . app . current_buffer . auto_up ( count = event . arg )
@kb.add ( ' down ' , filter = _normal_input )
def history_down ( event ) :
""" Down arrow: browse history when on last line, else move cursor down. """
event . app . current_buffer . auto_down ( count = event . arg )
2026-02-03 16:15:49 -08:00
@kb.add ( ' c-c ' )
def handle_ctrl_c ( event ) :
2026-02-21 12:15:40 -08:00
""" Handle Ctrl+C - cancel interactive prompts, interrupt agent, or exit.
2026-02-08 10:49:24 +00:00
2026-02-21 12:15:40 -08:00
Priority :
1. Cancel active sudo / approval / clarify prompt
2. Interrupt the running agent ( first press )
3. Force exit ( second press within 2 s , or when idle )
2026-02-08 10:49:24 +00:00
"""
import time as _time
now = _time . time ( )
2026-02-21 12:15:40 -08:00
# Cancel sudo prompt
if self . _sudo_state :
self . _sudo_state [ " response_queue " ] . put ( " " )
self . _sudo_state = None
event . app . current_buffer . reset ( )
event . app . invalidate ( )
return
# Cancel approval prompt (deny)
if self . _approval_state :
self . _approval_state [ " response_queue " ] . put ( " deny " )
self . _approval_state = None
event . app . invalidate ( )
return
# Cancel clarify prompt
if self . _clarify_state :
self . _clarify_state [ " response_queue " ] . put (
" The user cancelled. Use your best judgement to proceed. "
)
self . _clarify_state = None
self . _clarify_freetext = False
event . app . current_buffer . reset ( )
event . app . invalidate ( )
return
2026-02-03 16:15:49 -08:00
if self . _agent_running and self . agent :
2026-02-08 10:49:24 +00:00
if now - self . _last_ctrl_c_time < 2.0 :
print ( " \n ⚡ Force exiting... " )
self . _should_exit = True
event . app . exit ( )
return
self . _last_ctrl_c_time = now
print ( " \n ⚡ Interrupting agent... (press Ctrl+C again to force exit) " )
2026-02-03 16:15:49 -08:00
self . agent . interrupt ( )
else :
2026-03-05 17:53:58 -08:00
# If there's text or images, clear them (like bash).
# If everything is already empty, exit.
if event . app . current_buffer . text or self . _attached_images :
2026-03-04 22:01:13 -08:00
event . app . current_buffer . reset ( )
2026-03-05 17:53:58 -08:00
self . _attached_images . clear ( )
event . app . invalidate ( )
2026-03-04 22:01:13 -08:00
else :
self . _should_exit = True
event . app . exit ( )
2026-02-03 16:15:49 -08:00
@kb.add ( ' c-d ' )
def handle_ctrl_d ( event ) :
""" Handle Ctrl+D - exit. """
self . _should_exit = True
event . app . exit ( )
2026-03-05 17:53:58 -08:00
from prompt_toolkit . keys import Keys
@kb.add ( Keys . BracketedPaste , eager = True )
def handle_paste ( event ) :
fix: clipboard image paste on WSL2, Wayland, and VSCode terminal
The original implementation only supported xclip (X11), which silently
fails on WSL2 (can't access Windows clipboard for images), Wayland
desktops (xclip is X11-only), and VSCode terminal on WSL2.
Clipboard backend changes (hermes_cli/clipboard.py):
- WSL2: detect via /proc/version, use powershell.exe with .NET
System.Windows.Forms.Clipboard to extract images as base64 PNG
- Wayland: use wl-paste with MIME type detection, auto-convert BMP
to PNG for WSLg environments (via Pillow or ImageMagick)
- Dispatch order: WSL → Wayland → X11 (xclip), with fallthrough
- New has_clipboard_image() for lightweight clipboard checks
- Cache WSL detection result per-process
CLI changes (cli.py):
- /paste command: explicit clipboard image check for terminals where
BracketedPaste doesn't fire (image-only clipboard in VSCode/WinTerm)
- Ctrl+V keybinding: fallback for Linux terminals where Ctrl+V sends
raw byte instead of triggering bracketed paste
Tests: 80 tests (up from 37) covering WSL, Wayland, X11 dispatch,
BMP conversion, has_clipboard_image, and /paste command.
2026-03-05 20:22:44 -08:00
""" Handle terminal paste — detect clipboard images.
When the terminal supports bracketed paste , Ctrl + V / Cmd + V
triggers this with the pasted text . We also check the
clipboard for an image on every paste event .
"""
2026-03-05 17:53:58 -08:00
pasted_text = event . data or " "
refactor: extract clipboard methods + comprehensive tests (37 tests)
Refactored image paste internals for testability:
- Extracted _try_attach_clipboard_image() method (clipboard → state)
- Extracted _build_multimodal_content() method (images → OpenAI format)
- chat() now delegates to these instead of inline logic
Tests organized in 4 levels:
Level 1 (19 tests): Clipboard module — every platform path with
realistic subprocess simulation (tools writing files, timeouts,
empty files, cleanup on failure)
Level 2 (8 tests): _build_multimodal_content — base64 encoding,
MIME types (png/jpg/webp/unknown), missing files, multiple images,
default question for empty text
Level 3 (5 tests): _try_attach_clipboard_image — state management,
counter increment/rollback, naming convention, mixed success/failure
Level 4 (5 tests): Queue routing — tuple unpacking, command detection,
images-only payloads, text-only payloads
2026-03-05 18:07:53 -08:00
if self . _try_attach_clipboard_image ( ) :
2026-03-05 17:53:58 -08:00
event . app . invalidate ( )
if pasted_text :
event . current_buffer . insert_text ( pasted_text )
fix: clipboard image paste on WSL2, Wayland, and VSCode terminal
The original implementation only supported xclip (X11), which silently
fails on WSL2 (can't access Windows clipboard for images), Wayland
desktops (xclip is X11-only), and VSCode terminal on WSL2.
Clipboard backend changes (hermes_cli/clipboard.py):
- WSL2: detect via /proc/version, use powershell.exe with .NET
System.Windows.Forms.Clipboard to extract images as base64 PNG
- Wayland: use wl-paste with MIME type detection, auto-convert BMP
to PNG for WSLg environments (via Pillow or ImageMagick)
- Dispatch order: WSL → Wayland → X11 (xclip), with fallthrough
- New has_clipboard_image() for lightweight clipboard checks
- Cache WSL detection result per-process
CLI changes (cli.py):
- /paste command: explicit clipboard image check for terminals where
BracketedPaste doesn't fire (image-only clipboard in VSCode/WinTerm)
- Ctrl+V keybinding: fallback for Linux terminals where Ctrl+V sends
raw byte instead of triggering bracketed paste
Tests: 80 tests (up from 37) covering WSL, Wayland, X11 dispatch,
BMP conversion, has_clipboard_image, and /paste command.
2026-03-05 20:22:44 -08:00
@kb.add ( ' c-v ' )
def handle_ctrl_v ( event ) :
""" Fallback image paste for terminals without bracketed paste.
On Linux terminals ( GNOME Terminal , Konsole , etc . ) , Ctrl + V
sends raw byte 0x16 instead of triggering a paste . This
binding catches that and checks the clipboard for images .
On terminals that DO intercept Ctrl + V for paste ( macOS
Terminal , iTerm2 , VSCode , Windows Terminal ) , the bracketed
paste handler fires instead and this binding never triggers .
"""
if self . _try_attach_clipboard_image ( ) :
event . app . invalidate ( )
2026-03-05 22:48:39 -08:00
@kb.add ( ' escape ' , ' v ' )
def handle_alt_v ( event ) :
""" Alt+V — paste image from clipboard.
Alt key combos pass through all terminal emulators ( sent as
ESC + key ) , unlike Ctrl + V which terminals intercept for text
paste . This is the reliable way to attach clipboard images
on WSL2 , VSCode , and any terminal over SSH where Ctrl + V
can ' t reach the application for image-only clipboard.
"""
if self . _try_attach_clipboard_image ( ) :
event . app . invalidate ( )
else :
# No image found — show a hint
pass # silent when no image (avoid noise on accidental press)
2026-02-19 20:06:14 -08:00
# Dynamic prompt: shows Hermes symbol when agent is working,
# or answer prompt when clarify freetext mode is active.
2026-02-17 21:34:49 -08:00
cli_ref = self
2026-02-17 21:33:00 -08:00
def get_prompt ( ) :
2026-02-21 12:15:40 -08:00
if cli_ref . _sudo_state :
return [ ( ' class:sudo-prompt ' , ' 🔐 ❯ ' ) ]
if cli_ref . _approval_state :
return [ ( ' class:prompt-working ' , ' ⚠ ❯ ' ) ]
2026-02-19 20:06:14 -08:00
if cli_ref . _clarify_freetext :
return [ ( ' class:clarify-selected ' , ' ✎ ❯ ' ) ]
if cli_ref . _clarify_state :
return [ ( ' class:prompt-working ' , ' ? ❯ ' ) ]
2026-03-10 17:13:14 -07:00
if cli_ref . _command_running :
return [ ( ' class:prompt-working ' , f " { cli_ref . _command_spinner_frame ( ) } ❯ " ) ]
2026-02-17 21:33:00 -08:00
if cli_ref . _agent_running :
return [ ( ' class:prompt-working ' , ' ⚕ ❯ ' ) ]
return [ ( ' class:prompt ' , ' ❯ ' ) ]
2026-02-17 21:47:54 -08:00
# Create the input area with multiline (shift+enter), autocomplete, and paste handling
2026-02-03 16:15:49 -08:00
input_area = TextArea (
2026-02-17 21:47:54 -08:00
height = Dimension ( min = 1 , max = 8 , preferred = 1 ) ,
2026-02-17 21:33:00 -08:00
prompt = get_prompt ,
2026-02-03 16:15:49 -08:00
style = ' class:input-area ' ,
2026-02-17 21:47:54 -08:00
multiline = True ,
wrap_lines = True ,
2026-03-10 17:13:14 -07:00
read_only = Condition ( lambda : bool ( cli_ref . _command_running ) ) ,
2026-02-10 15:59:46 -08:00
history = FileHistory ( str ( self . _history_file ) ) ,
2026-03-07 17:53:41 -08:00
completer = SlashCommandCompleter ( skill_commands_provider = lambda : _skill_commands ) ,
2026-02-17 21:47:54 -08:00
complete_while_typing = True ,
2026-02-03 16:15:49 -08:00
)
2026-02-17 21:34:49 -08:00
2026-02-21 12:15:40 -08:00
# Dynamic height: accounts for both explicit newlines AND visual
# wrapping of long lines so the input area always fits its content.
# The prompt characters ("❯ " etc.) consume ~4 columns.
2026-02-19 01:14:53 -08:00
def _input_height ( ) :
try :
2026-02-21 12:15:40 -08:00
doc = input_area . buffer . document
2026-03-05 15:55:35 -08:00
available_width = shutil . get_terminal_size ( ) . columns - 4 # subtract prompt width
2026-02-21 12:15:40 -08:00
if available_width < 10 :
available_width = 40
visual_lines = 0
for line in doc . lines :
# Each logical line takes at least 1 visual row; long lines wrap
if len ( line ) == 0 :
visual_lines + = 1
else :
visual_lines + = max ( 1 , - ( - len ( line ) / / available_width ) ) # ceil division
return min ( max ( visual_lines , 1 ) , 8 )
2026-02-19 01:14:53 -08:00
except Exception :
2026-02-19 01:53:36 -08:00
return 1
2026-02-19 01:14:53 -08:00
input_area . window . height = _input_height
2026-02-17 21:47:54 -08:00
# Paste collapsing: detect large pastes and save to temp file
_paste_counter = [ 0 ]
2026-02-26 23:40:38 +03:00
_prev_text_len = [ 0 ]
2026-02-17 21:47:54 -08:00
def _on_text_changed ( buf ) :
""" Detect large pastes and collapse them to a file reference. """
text = buf . text
line_count = text . count ( ' \n ' )
2026-02-26 23:40:38 +03:00
chars_added = len ( text ) - _prev_text_len [ 0 ]
_prev_text_len [ 0 ] = len ( text )
# Heuristic: a real paste adds many characters at once (not just a
# single newline from Alt+Enter) AND the result has 5+ lines.
if line_count > = 5 and chars_added > 1 and not text . startswith ( ' / ' ) :
2026-02-17 21:47:54 -08:00
_paste_counter [ 0 ] + = 1
# Save to temp file
paste_dir = Path ( os . path . expanduser ( " ~/.hermes/pastes " ) )
paste_dir . mkdir ( parents = True , exist_ok = True )
paste_file = paste_dir / f " paste_ { _paste_counter [ 0 ] } _ { datetime . now ( ) . strftime ( ' % H % M % S ' ) } .txt "
paste_file . write_text ( text , encoding = " utf-8 " )
# Replace buffer with compact reference
buf . text = f " [Pasted text # { _paste_counter [ 0 ] } : { line_count + 1 } lines → { paste_file } ] "
buf . cursor_position = len ( buf . text )
input_area . buffer . on_text_changed + = _on_text_changed
2026-02-21 12:33:48 -08:00
# --- Input processors for password masking and inline placeholder ---
# Mask input with '*' when the sudo password prompt is active
input_area . control . input_processors . append (
ConditionalProcessor (
PasswordProcessor ( ) ,
filter = Condition ( lambda : bool ( cli_ref . _sudo_state ) ) ,
)
)
class _PlaceholderProcessor ( Processor ) :
""" Render grayed-out placeholder text inside the input when empty. """
def __init__ ( self , get_text ) :
self . _get_text = get_text
def apply_transformation ( self , ti ) :
if not ti . document . text and ti . lineno == 0 :
text = self . _get_text ( )
if text :
2026-02-21 12:36:14 -08:00
# Append after existing fragments (preserves the ❯ prompt)
return Transformation ( fragments = ti . fragments + [ ( ' class:placeholder ' , text ) ] )
2026-02-21 12:33:48 -08:00
return Transformation ( fragments = ti . fragments )
def _get_placeholder ( ) :
if cli_ref . _sudo_state :
return " type password (hidden), Enter to skip "
if cli_ref . _approval_state :
return " "
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
if cli_ref . _clarify_freetext :
return " type your answer here and press Enter "
2026-02-21 12:33:48 -08:00
if cli_ref . _clarify_state :
return " "
2026-03-10 17:13:14 -07:00
if cli_ref . _command_running :
frame = cli_ref . _command_spinner_frame ( )
status = cli_ref . _command_status or " Processing command... "
return f " { frame } { status } "
2026-02-21 12:33:48 -08:00
if cli_ref . _agent_running :
return " type a message + Enter to interrupt, Ctrl+C to cancel "
return " "
input_area . control . input_processors . append ( _PlaceholderProcessor ( _get_placeholder ) )
# Hint line above input: shown only for interactive prompts that need
# extra instructions (sudo countdown, approval navigation, clarify).
# The agent-running interrupt hint is now an inline placeholder above.
2026-02-17 21:47:54 -08:00
def get_hint_text ( ) :
2026-02-21 12:15:40 -08:00
import time as _time
if cli_ref . _sudo_state :
remaining = max ( 0 , int ( cli_ref . _sudo_deadline - _time . monotonic ( ) ) )
return [
2026-02-21 12:33:48 -08:00
( ' class:hint ' , ' password hidden · Enter to skip ' ) ,
2026-02-21 12:15:40 -08:00
( ' class:clarify-countdown ' , f ' ( { remaining } s) ' ) ,
]
if cli_ref . _approval_state :
remaining = max ( 0 , int ( cli_ref . _approval_deadline - _time . monotonic ( ) ) )
return [
( ' class:hint ' , ' ↑/↓ to select, Enter to confirm ' ) ,
( ' class:clarify-countdown ' , f ' ( { remaining } s) ' ) ,
]
2026-02-19 20:06:14 -08:00
if cli_ref . _clarify_state :
2026-02-19 20:11:54 -08:00
remaining = max ( 0 , int ( cli_ref . _clarify_deadline - _time . monotonic ( ) ) )
countdown = f ' ( { remaining } s) ' if cli_ref . _clarify_deadline else ' '
2026-02-19 20:06:14 -08:00
if cli_ref . _clarify_freetext :
2026-02-19 20:11:54 -08:00
return [
( ' class:hint ' , ' type your answer and press Enter ' ) ,
( ' class:clarify-countdown ' , countdown ) ,
]
return [
( ' class:hint ' , ' ↑/↓ to select, Enter to confirm ' ) ,
( ' class:clarify-countdown ' , countdown ) ,
]
2026-02-21 12:15:40 -08:00
2026-03-10 17:13:14 -07:00
if cli_ref . _command_running :
frame = cli_ref . _command_spinner_frame ( )
return [
( ' class:hint ' , f ' { frame } command in progress · input temporarily disabled ' ) ,
]
2026-02-21 12:33:48 -08:00
return [ ]
2026-02-17 21:47:54 -08:00
def get_hint_height ( ) :
2026-03-10 17:13:14 -07:00
if cli_ref . _sudo_state or cli_ref . _approval_state or cli_ref . _clarify_state or cli_ref . _command_running :
2026-02-19 20:06:14 -08:00
return 1
2026-02-21 12:36:14 -08:00
# Keep a 1-line spacer while agent runs so output doesn't push
# right up against the top rule of the input area
return 1 if cli_ref . _agent_running else 0
2026-02-17 21:34:49 -08:00
2026-03-09 23:26:43 -07:00
def get_spinner_text ( ) :
txt = cli_ref . _spinner_text
if not txt :
return [ ]
return [ ( ' class:hint ' , f ' { txt } ' ) ]
def get_spinner_height ( ) :
return 1 if cli_ref . _spinner_text else 0
spinner_widget = Window (
content = FormattedTextControl ( get_spinner_text ) ,
height = get_spinner_height ,
)
2026-02-17 21:47:54 -08:00
spacer = Window (
content = FormattedTextControl ( get_hint_text ) ,
height = get_hint_height ,
)
2026-02-19 20:06:14 -08:00
# --- Clarify tool: dynamic display widget for questions + choices ---
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
def _panel_box_width ( title : str , content_lines : list [ str ] , min_width : int = 46 , max_width : int = 76 ) - > int :
""" Choose a stable panel width wide enough for the title and content. """
term_cols = shutil . get_terminal_size ( ( 100 , 20 ) ) . columns
longest = max ( [ len ( title ) ] + [ len ( line ) for line in content_lines ] + [ min_width - 4 ] )
inner = min ( max ( longest + 4 , min_width - 2 ) , max_width - 2 , max ( 24 , term_cols - 6 ) )
return inner + 2 # account for the single leading/trailing spaces inside borders
def _wrap_panel_text ( text : str , width : int , subsequent_indent : str = " " ) - > list [ str ] :
wrapped = textwrap . wrap (
text ,
width = max ( 8 , width ) ,
break_long_words = False ,
break_on_hyphens = False ,
subsequent_indent = subsequent_indent ,
)
return wrapped or [ " " ]
def _append_panel_line ( lines , border_style : str , content_style : str , text : str , box_width : int ) - > None :
inner_width = max ( 0 , box_width - 2 )
lines . append ( ( border_style , " │ " ) )
lines . append ( ( content_style , text . ljust ( inner_width ) ) )
lines . append ( ( border_style , " │ \n " ) )
def _append_blank_panel_line ( lines , border_style : str , box_width : int ) - > None :
lines . append ( ( border_style , " │ " + ( " " * box_width ) + " │ \n " ) )
2026-02-19 20:06:14 -08:00
def _get_clarify_display ( ) :
""" Build styled text for the clarify question/choices panel. """
state = cli_ref . _clarify_state
if not state :
return [ ]
question = state [ " question " ]
choices = state . get ( " choices " ) or [ ]
selected = state . get ( " selected " , 0 )
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
preview_lines = _wrap_panel_text ( question , 60 )
for i , choice in enumerate ( choices ) :
prefix = " ❯ " if i == selected and not cli_ref . _clarify_freetext else " "
preview_lines . extend ( _wrap_panel_text ( f " { prefix } { choice } " , 60 , subsequent_indent = " " ) )
other_label = (
" ❯ Other (type below)" if cli_ref . _clarify_freetext
else " ❯ Other (type your answer)" if selected == len ( choices )
else " Other (type your answer) "
)
preview_lines . extend ( _wrap_panel_text ( other_label , 60 , subsequent_indent = " " ) )
box_width = _panel_box_width ( " Hermes needs your input " , preview_lines )
inner_text_width = max ( 8 , box_width - 2 )
2026-02-19 20:06:14 -08:00
lines = [ ]
# Box top border
lines . append ( ( ' class:clarify-border ' , ' ╭─ ' ) )
lines . append ( ( ' class:clarify-title ' , ' Hermes needs your input ' ) )
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
lines . append ( ( ' class:clarify-border ' , ' ' + ( ' ─ ' * max ( 0 , box_width - len ( " Hermes needs your input " ) - 3 ) ) + ' ╮ \n ' ) )
_append_blank_panel_line ( lines , ' class:clarify-border ' , box_width )
2026-02-19 20:06:14 -08:00
# Question text
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
for wrapped in _wrap_panel_text ( question , inner_text_width ) :
_append_panel_line ( lines , ' class:clarify-border ' , ' class:clarify-question ' , wrapped , box_width )
_append_blank_panel_line ( lines , ' class:clarify-border ' , box_width )
if cli_ref . _clarify_freetext and not choices :
guidance = " Type your answer in the prompt below, then press Enter. "
for wrapped in _wrap_panel_text ( guidance , inner_text_width ) :
_append_panel_line ( lines , ' class:clarify-border ' , ' class:clarify-choice ' , wrapped , box_width )
_append_blank_panel_line ( lines , ' class:clarify-border ' , box_width )
2026-02-19 20:06:14 -08:00
if choices :
# Multiple-choice mode: show selectable options
for i , choice in enumerate ( choices ) :
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
style = ' class:clarify-selected ' if i == selected and not cli_ref . _clarify_freetext else ' class:clarify-choice '
prefix = ' ❯ ' if i == selected and not cli_ref . _clarify_freetext else ' '
wrapped_lines = _wrap_panel_text ( f " { prefix } { choice } " , inner_text_width , subsequent_indent = " " )
for wrapped in wrapped_lines :
_append_panel_line ( lines , ' class:clarify-border ' , style , wrapped , box_width )
2026-02-19 20:06:14 -08:00
# "Other" option (5th line, only shown when choices exist)
other_idx = len ( choices )
if selected == other_idx and not cli_ref . _clarify_freetext :
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
other_style = ' class:clarify-selected '
other_label = ' ❯ Other (type your answer)'
2026-02-19 20:06:14 -08:00
elif cli_ref . _clarify_freetext :
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
other_style = ' class:clarify-active-other '
other_label = ' ❯ Other (type below)'
2026-02-19 20:06:14 -08:00
else :
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
other_style = ' class:clarify-choice '
other_label = ' Other (type your answer) '
for wrapped in _wrap_panel_text ( other_label , inner_text_width , subsequent_indent = " " ) :
_append_panel_line ( lines , ' class:clarify-border ' , other_style , wrapped , box_width )
2026-02-19 20:06:14 -08:00
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
_append_blank_panel_line ( lines , ' class:clarify-border ' , box_width )
lines . append ( ( ' class:clarify-border ' , ' ╰ ' + ( ' ─ ' * box_width ) + ' ╯ \n ' ) )
2026-02-19 20:06:14 -08:00
return lines
clarify_widget = ConditionalContainer (
Window (
FormattedTextControl ( _get_clarify_display ) ,
wrap_lines = True ,
) ,
filter = Condition ( lambda : cli_ref . _clarify_state is not None ) ,
)
2026-02-21 12:15:40 -08:00
# --- Sudo password: display widget ---
def _get_sudo_display ( ) :
state = cli_ref . _sudo_state
if not state :
return [ ]
2026-03-10 06:44:13 -07:00
title = ' 🔐 Sudo Password Required '
body = ' Enter password below (hidden), or press Enter to skip '
box_width = _panel_box_width ( title , [ body ] )
inner = max ( 0 , box_width - 2 )
2026-02-21 12:15:40 -08:00
lines = [ ]
lines . append ( ( ' class:sudo-border ' , ' ╭─ ' ) )
2026-03-10 06:44:13 -07:00
lines . append ( ( ' class:sudo-title ' , title ) )
lines . append ( ( ' class:sudo-border ' , ' ' + ( ' ─ ' * max ( 0 , box_width - len ( title ) - 3 ) ) + ' ╮ \n ' ) )
_append_blank_panel_line ( lines , ' class:sudo-border ' , box_width )
_append_panel_line ( lines , ' class:sudo-border ' , ' class:sudo-text ' , body , box_width )
_append_blank_panel_line ( lines , ' class:sudo-border ' , box_width )
lines . append ( ( ' class:sudo-border ' , ' ╰ ' + ( ' ─ ' * box_width ) + ' ╯ \n ' ) )
2026-02-21 12:15:40 -08:00
return lines
sudo_widget = ConditionalContainer (
Window (
FormattedTextControl ( _get_sudo_display ) ,
wrap_lines = True ,
) ,
filter = Condition ( lambda : cli_ref . _sudo_state is not None ) ,
)
# --- Dangerous command approval: display widget ---
def _get_approval_display ( ) :
state = cli_ref . _approval_state
if not state :
return [ ]
command = state [ " command " ]
description = state [ " description " ]
choices = state [ " choices " ]
selected = state . get ( " selected " , 0 )
cmd_display = command [ : 70 ] + ' ... ' if len ( command ) > 70 else command
choice_labels = {
" once " : " Allow once " ,
" session " : " Allow for this session " ,
" always " : " Add to permanent allowlist " ,
" deny " : " Deny " ,
}
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
preview_lines = _wrap_panel_text ( description , 60 )
preview_lines . extend ( _wrap_panel_text ( cmd_display , 60 ) )
for i , choice in enumerate ( choices ) :
prefix = ' ❯ ' if i == selected else ' '
preview_lines . extend ( _wrap_panel_text ( f " { prefix } { choice_labels . get ( choice , choice ) } " , 60 , subsequent_indent = " " ) )
box_width = _panel_box_width ( " ⚠️ Dangerous Command " , preview_lines )
inner_text_width = max ( 8 , box_width - 2 )
2026-02-21 12:15:40 -08:00
lines = [ ]
lines . append ( ( ' class:approval-border ' , ' ╭─ ' ) )
lines . append ( ( ' class:approval-title ' , ' ⚠️ Dangerous Command ' ) )
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
lines . append ( ( ' class:approval-border ' , ' ' + ( ' ─ ' * max ( 0 , box_width - len ( " ⚠️ Dangerous Command " ) - 3 ) ) + ' ╮ \n ' ) )
_append_blank_panel_line ( lines , ' class:approval-border ' , box_width )
for wrapped in _wrap_panel_text ( description , inner_text_width ) :
_append_panel_line ( lines , ' class:approval-border ' , ' class:approval-desc ' , wrapped , box_width )
for wrapped in _wrap_panel_text ( cmd_display , inner_text_width ) :
_append_panel_line ( lines , ' class:approval-border ' , ' class:approval-cmd ' , wrapped , box_width )
_append_blank_panel_line ( lines , ' class:approval-border ' , box_width )
2026-02-21 12:15:40 -08:00
for i , choice in enumerate ( choices ) :
label = choice_labels . get ( choice , choice )
Add official OpenClaw migration skill for Hermes Agent
Introduces a new OpenClaw-to-Hermes migration skill with a Python
helper script that handles importing SOUL.md, memories, user profiles,
messaging settings, command allowlists, skills, TTS assets, and
workspace instructions.
Supports two migration presets (user-data / full), three skill conflict
modes (skip / overwrite / rename), overflow file export for entries that
exceed character limits, and granular include/exclude option filtering.
Includes detailed SKILL.md agent instructions covering the clarify-tool
interaction protocol, decision-to-command mapping, post-run reporting
rules, and path resolution guidance.
Adds dynamic panel width calculation to CLI clarify/approval widgets so
panels adapt to content and terminal size.
Includes 7 new tests covering presets, include/exclude, conflict modes,
overflow exports, and skills_guard integration.
2026-03-06 18:57:12 -08:00
style = ' class:approval-selected ' if i == selected else ' class:approval-choice '
prefix = ' ❯ ' if i == selected else ' '
for wrapped in _wrap_panel_text ( f " { prefix } { label } " , inner_text_width , subsequent_indent = " " ) :
_append_panel_line ( lines , ' class:approval-border ' , style , wrapped , box_width )
_append_blank_panel_line ( lines , ' class:approval-border ' , box_width )
lines . append ( ( ' class:approval-border ' , ' ╰ ' + ( ' ─ ' * box_width ) + ' ╯ \n ' ) )
2026-02-21 12:15:40 -08:00
return lines
approval_widget = ConditionalContainer (
Window (
FormattedTextControl ( _get_approval_display ) ,
wrap_lines = True ,
) ,
filter = Condition ( lambda : cli_ref . _approval_state is not None ) ,
)
2026-02-19 01:51:54 -08:00
# Horizontal rules above and below the input (bronze, 1 line each).
# The bottom rule moves down as the TextArea grows with newlines.
2026-03-02 21:53:25 -06:00
# Using char='─' instead of hardcoded repetition so the rule
# always spans the full terminal width on any screen size.
2026-02-19 01:51:54 -08:00
input_rule_top = Window (
2026-03-02 21:53:25 -06:00
char = ' ─ ' ,
2026-02-19 01:51:54 -08:00
height = 1 ,
2026-03-02 21:53:25 -06:00
style = ' class:input-rule ' ,
2026-02-19 01:51:54 -08:00
)
input_rule_bot = Window (
2026-03-02 21:53:25 -06:00
char = ' ─ ' ,
2026-02-19 01:51:54 -08:00
height = 1 ,
2026-03-02 21:53:25 -06:00
style = ' class:input-rule ' ,
2026-02-19 01:51:54 -08:00
)
2026-02-19 01:49:50 -08:00
2026-03-05 17:53:58 -08:00
# Image attachment indicator — shows badges like [📎 Image #1] above input
cli_ref = self
def _get_image_bar ( ) :
if not cli_ref . _attached_images :
return [ ]
base = cli_ref . _image_counter - len ( cli_ref . _attached_images ) + 1
badges = " " . join (
f " [📎 Image # { base + i } ] "
for i in range ( len ( cli_ref . _attached_images ) )
)
return [ ( " class:image-badge " , f " { badges } " ) ]
image_bar = Window (
content = FormattedTextControl ( _get_image_bar ) ,
height = Condition ( lambda : bool ( cli_ref . _attached_images ) ) ,
)
2026-02-21 12:15:40 -08:00
# Layout: interactive prompt widgets + ruled input at bottom.
# The sudo, approval, and clarify widgets appear above the input when
# the corresponding interactive prompt is active.
2026-02-03 16:15:49 -08:00
layout = Layout (
2026-02-19 01:11:02 -08:00
HSplit ( [
Window ( height = 0 ) ,
2026-02-21 12:15:40 -08:00
sudo_widget ,
approval_widget ,
2026-02-19 20:06:14 -08:00
clarify_widget ,
2026-03-09 23:26:43 -07:00
spinner_widget ,
2026-02-19 01:11:02 -08:00
spacer ,
2026-02-19 01:51:54 -08:00
input_rule_top ,
2026-03-05 17:53:58 -08:00
image_bar ,
2026-02-19 01:51:54 -08:00
input_area ,
input_rule_bot ,
2026-02-19 01:11:02 -08:00
CompletionsMenu ( max_height = 12 , scroll_offset = 1 ) ,
] )
2026-02-03 16:15:49 -08:00
)
# Style for the application
style = PTStyle . from_dict ( {
' input-area ' : ' #FFF8DC ' ,
2026-02-21 12:33:48 -08:00
' placeholder ' : ' #555555 italic ' ,
2026-02-17 21:33:00 -08:00
' prompt ' : ' #FFF8DC ' ,
' prompt-working ' : ' #888888 italic ' ,
2026-02-17 21:47:54 -08:00
' hint ' : ' #555555 italic ' ,
2026-02-19 01:51:54 -08:00
# Bronze horizontal rules around the input area
' input-rule ' : ' #CD7F32 ' ,
2026-03-05 17:53:58 -08:00
# Clipboard image attachment badges
' image-badge ' : ' #87CEEB bold ' ,
2026-02-17 21:47:54 -08:00
' completion-menu ' : ' bg:#1a1a2e #FFF8DC ' ,
' completion-menu.completion ' : ' bg:#1a1a2e #FFF8DC ' ,
' completion-menu.completion.current ' : ' bg:#333355 #FFD700 ' ,
' completion-menu.meta.completion ' : ' bg:#1a1a2e #888888 ' ,
' completion-menu.meta.completion.current ' : ' bg:#333355 #FFBF00 ' ,
2026-02-19 20:06:14 -08:00
# Clarify question panel
' clarify-border ' : ' #CD7F32 ' ,
' clarify-title ' : ' #FFD700 bold ' ,
' clarify-question ' : ' #FFF8DC bold ' ,
' clarify-choice ' : ' #AAAAAA ' ,
' clarify-selected ' : ' #FFD700 bold ' ,
' clarify-active-other ' : ' #FFD700 italic ' ,
2026-02-19 20:11:54 -08:00
' clarify-countdown ' : ' #CD7F32 ' ,
2026-02-21 12:15:40 -08:00
# Sudo password panel
' sudo-prompt ' : ' #FF6B6B bold ' ,
' sudo-border ' : ' #CD7F32 ' ,
' sudo-title ' : ' #FF6B6B bold ' ,
' sudo-text ' : ' #FFF8DC ' ,
# Dangerous command approval panel
' approval-border ' : ' #CD7F32 ' ,
' approval-title ' : ' #FF8C00 bold ' ,
' approval-desc ' : ' #FFF8DC bold ' ,
' approval-cmd ' : ' #AAAAAA italic ' ,
' approval-choice ' : ' #AAAAAA ' ,
' approval-selected ' : ' #FFD700 bold ' ,
2026-02-03 16:15:49 -08:00
} )
# Create the application
app = Application (
layout = layout ,
key_bindings = kb ,
style = style ,
full_screen = False ,
mouse_support = False ,
2026-03-09 23:26:43 -07:00
* * ( { ' cursor ' : _STEADY_CURSOR } if _STEADY_CURSOR is not None else { } ) ,
2026-02-03 16:15:49 -08:00
)
2026-02-19 20:06:14 -08:00
self . _app = app # Store reference for clarify_callback
2026-03-10 17:13:14 -07:00
def spinner_loop ( ) :
import time as _time
while not self . _should_exit :
if self . _command_running and self . _app :
self . _invalidate ( min_interval = 0.1 )
_time . sleep ( 0.1 )
else :
_time . sleep ( 0.05 )
spinner_thread = threading . Thread ( target = spinner_loop , daemon = True )
spinner_thread . start ( )
2026-02-03 16:15:49 -08:00
# Background thread to process inputs and run agent
def process_loop ( ) :
while not self . _should_exit :
2026-01-31 06:30:48 +00:00
try :
2026-02-03 16:15:49 -08:00
# Check for pending input with timeout
try :
user_input = self . _pending_input . get ( timeout = 0.1 )
except queue . Empty :
continue
2026-01-31 06:30:48 +00:00
if not user_input :
continue
2026-03-05 17:53:58 -08:00
# Unpack image payload: (text, [Path, ...]) or plain str
submit_images = [ ]
if isinstance ( user_input , tuple ) :
user_input , submit_images = user_input
2026-01-31 06:30:48 +00:00
# Check for commands
2026-03-05 17:53:58 -08:00
if isinstance ( user_input , str ) and user_input . startswith ( " / " ) :
2026-02-12 10:05:08 -08:00
print ( f " \n ⚙️ { user_input } " )
2026-01-31 06:30:48 +00:00
if not self . process_command ( user_input ) :
2026-02-03 16:15:49 -08:00
self . _should_exit = True
# Schedule app exit
if app . is_running :
app . exit ( )
2026-01-31 06:30:48 +00:00
continue
2026-02-17 21:47:54 -08:00
# Expand paste references back to full content
import re as _re
2026-03-05 17:53:58 -08:00
paste_match = _re . match ( r ' \ [Pasted text # \ d+: \ d+ lines → (.+) \ ] ' , user_input ) if isinstance ( user_input , str ) else None
2026-02-17 21:47:54 -08:00
if paste_match :
paste_path = Path ( paste_match . group ( 1 ) )
if paste_path . exists ( ) :
full_text = paste_path . read_text ( encoding = " utf-8 " )
line_count = full_text . count ( ' \n ' ) + 1
2026-02-19 01:34:14 -08:00
print ( )
_cprint ( f " { _GOLD } ● { _RST } { _BOLD } [Pasted text: { line_count } lines] { _RST } " )
2026-02-17 21:47:54 -08:00
user_input = full_text
else :
2026-02-19 01:34:14 -08:00
print ( )
_cprint ( f " { _GOLD } ● { _RST } { _BOLD } { user_input } { _RST } " )
2026-02-17 21:47:54 -08:00
else :
if ' \n ' in user_input :
first_line = user_input . split ( ' \n ' ) [ 0 ]
line_count = user_input . count ( ' \n ' ) + 1
2026-02-19 01:34:14 -08:00
print ( )
_cprint ( f " { _GOLD } ● { _RST } { _BOLD } { first_line } { _RST } { _DIM } (+ { line_count - 1 } lines) { _RST } " )
2026-02-17 21:47:54 -08:00
else :
2026-02-19 01:34:14 -08:00
print ( )
_cprint ( f " { _GOLD } ● { _RST } { _BOLD } { user_input } { _RST } " )
2026-02-17 21:47:54 -08:00
2026-03-05 17:53:58 -08:00
# Show image attachment count
if submit_images :
n = len ( submit_images )
_cprint ( f " { _DIM } 📎 { n } image { ' s ' if n > 1 else ' ' } attached { _RST } " )
2026-02-03 16:15:49 -08:00
# Regular chat - run agent
self . _agent_running = True
app . invalidate ( ) # Refresh status line
2026-01-31 06:30:48 +00:00
2026-02-03 16:15:49 -08:00
try :
2026-03-05 17:53:58 -08:00
self . chat ( user_input , images = submit_images or None )
2026-02-03 16:15:49 -08:00
finally :
self . _agent_running = False
2026-03-09 23:26:43 -07:00
self . _spinner_text = " "
2026-02-03 16:15:49 -08:00
app . invalidate ( ) # Refresh status line
except Exception as e :
print ( f " Error: { e } " )
# Start processing thread
process_thread = threading . Thread ( target = process_loop , daemon = True )
process_thread . start ( )
2026-02-08 13:31:45 -08:00
# Register atexit cleanup so resources are freed even on unexpected exit
2026-02-16 02:43:45 -08:00
atexit . register ( _run_cleanup )
2026-02-08 13:31:45 -08:00
2026-02-03 16:15:49 -08:00
# Run the application with patch_stdout for proper output handling
try :
with patch_stdout ( ) :
app . run ( )
except ( EOFError , KeyboardInterrupt ) :
pass
finally :
self . _should_exit = True
2026-02-22 10:15:17 -08:00
# Flush memories before exit (only for substantial conversations)
if self . agent and self . conversation_history :
try :
self . agent . flush_memories ( self . conversation_history )
except Exception :
pass
2026-02-21 12:15:40 -08:00
# Unregister terminal_tool callbacks to avoid dangling references
set_sudo_password_callback ( None )
set_approval_callback ( None )
2026-02-19 00:57:31 -08:00
# Close session in SQLite
if hasattr ( self , ' _session_db ' ) and self . _session_db and self . agent :
try :
self . _session_db . end_session ( self . agent . session_id , " cli_close " )
2026-02-21 03:32:11 -08:00
except Exception as e :
logger . debug ( " Could not close session in DB: %s " , e )
2026-02-16 02:43:45 -08:00
_run_cleanup ( )
2026-02-25 22:56:12 -08:00
self . _print_exit_summary ( )
2026-01-31 06:30:48 +00:00
# ============================================================================
# Main Entry Point
# ============================================================================
def main (
query : str = None ,
q : str = None ,
toolsets : str = None ,
model : str = None ,
2026-02-20 17:24:00 -08:00
provider : str = None ,
2026-01-31 06:30:48 +00:00
api_key : str = None ,
base_url : str = None ,
2026-02-26 23:43:38 +03:00
max_turns : int = None ,
2026-01-31 06:30:48 +00:00
verbose : bool = False ,
2026-03-10 20:45:18 -07:00
quiet : bool = False ,
2026-01-31 06:30:48 +00:00
compact : bool = False ,
list_tools : bool = False ,
list_toolsets : bool = False ,
2026-02-02 19:01:51 -08:00
gateway : bool = False ,
2026-02-25 22:56:12 -08:00
resume : str = None ,
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
worktree : bool = False ,
w : bool = False ,
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
checkpoints : bool = False ,
2026-01-31 06:30:48 +00:00
) :
"""
Hermes Agent CLI - Interactive AI Assistant
Args :
query : Single query to execute ( then exit ) . Alias : - q
q : Shorthand for - - query
toolsets : Comma - separated list of toolsets to enable ( e . g . , " web,terminal " )
model : Model to use ( default : anthropic / claude - opus - 4 - 20250514 )
feat: add z.ai/GLM, Kimi/Moonshot, MiniMax as first-class providers
Adds 4 new direct API-key providers (zai, kimi-coding, minimax, minimax-cn)
to the inference provider system. All use standard OpenAI-compatible
chat/completions endpoints with Bearer token auth.
Core changes:
- auth.py: Extended ProviderConfig with api_key_env_vars and base_url_env_var
fields. Added providers to PROVIDER_REGISTRY. Added provider aliases
(glm, z-ai, zhipu, kimi, moonshot). Added auto-detection of API-key
providers in resolve_provider(). Added resolve_api_key_provider_credentials()
and get_api_key_provider_status() helpers.
- runtime_provider.py: Added generic API-key provider branch in
resolve_runtime_provider() — any provider with auth_type='api_key'
is automatically handled.
- main.py: Added providers to hermes model menu with generic
_model_flow_api_key_provider() flow. Updated _has_any_provider_configured()
to check all provider env vars. Updated argparse --provider choices.
- setup.py: Added providers to setup wizard with API key prompts and
curated model lists.
- config.py: Added env vars (GLM_API_KEY, KIMI_API_KEY, MINIMAX_API_KEY,
etc.) to OPTIONAL_ENV_VARS.
- status.py: Added API key display and provider status section.
- doctor.py: Added connectivity checks for each provider endpoint.
- cli.py: Updated provider docstrings.
Docs: Updated README.md, .env.example, cli-config.yaml.example,
cli-commands.md, environment-variables.md, configuration.md.
Tests: 50 new tests covering registry, aliases, resolution, auto-detection,
credential resolution, and runtime provider dispatch.
Inspired by PR #33 (numman-ali) which proposed a provider registry approach.
Credit to tars90percent (PR #473) and manuelschipper (PR #420) for related
provider improvements merged earlier in this changeset.
2026-03-06 18:55:12 -08:00
provider : Inference provider ( " auto " , " openrouter " , " nous " , " openai-codex " , " zai " , " kimi-coding " , " minimax " , " minimax-cn " )
2026-01-31 06:30:48 +00:00
api_key : API key for authentication
base_url : Base URL for the API
2026-02-03 14:48:19 -08:00
max_turns : Maximum tool - calling iterations ( default : 60 )
2026-01-31 06:30:48 +00:00
verbose : Enable verbose logging
compact : Use compact display mode
list_tools : List available tools and exit
list_toolsets : List available toolsets and exit
2026-02-25 22:56:12 -08:00
resume : Resume a previous session by its ID ( e . g . , 20260225_143052 _a1b2c3 )
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
worktree : Run in an isolated git worktree ( for parallel agents ) . Alias : - w
w : Shorthand for - - worktree
2026-01-31 06:30:48 +00:00
Examples :
python cli . py # Start interactive mode
python cli . py - - toolsets web , terminal # Use specific toolsets
python cli . py - q " What is Python? " # Single query mode
python cli . py - - list - tools # List tools and exit
2026-02-25 22:56:12 -08:00
python cli . py - - resume 20260225_143052 _a1b2c3 # Resume session
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
python cli . py - w # Start in isolated git worktree
python cli . py - w - q " Fix issue #123 " # Single query in worktree
2026-01-31 06:30:48 +00:00
"""
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
global _active_worktree
2026-02-01 15:36:26 -08:00
# Signal to terminal_tool that we're in interactive mode
# This enables interactive sudo password prompts with timeout
os . environ [ " HERMES_INTERACTIVE " ] = " 1 "
2026-02-21 16:21:19 -08:00
# Handle gateway mode (messaging + cron)
2026-02-02 19:01:51 -08:00
if gateway :
import asyncio
from gateway . run import start_gateway
print ( " Starting Hermes Gateway (messaging platforms)... " )
asyncio . run ( start_gateway ( ) )
return
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
2026-03-07 21:05:40 -08:00
# Skip worktree for list commands (they exit immediately)
if not list_tools and not list_toolsets :
# ── Git worktree isolation (#652) ──
# Create an isolated worktree so this agent instance doesn't collide
# with other agents working on the same repo.
use_worktree = worktree or w or CLI_CONFIG . get ( " worktree " , False )
wt_info = None
if use_worktree :
# Prune stale worktrees from crashed/killed sessions
_repo = _git_repo_root ( )
if _repo :
_prune_stale_worktrees ( _repo )
wt_info = _setup_worktree ( )
if wt_info :
_active_worktree = wt_info
os . environ [ " TERMINAL_CWD " ] = wt_info [ " path " ]
atexit . register ( _cleanup_worktree , wt_info )
2026-03-08 17:22:24 -07:00
else :
# Worktree was explicitly requested but setup failed —
# don't silently run without isolation.
return
2026-03-07 21:05:40 -08:00
else :
wt_info = None
2026-02-02 19:01:51 -08:00
2026-01-31 06:30:48 +00:00
# Handle query shorthand
query = query or q
# Parse toolsets - handle both string and tuple/list inputs
2026-02-02 08:26:42 -08:00
# Default to hermes-cli toolset which includes cronjob management tools
2026-01-31 06:30:48 +00:00
toolsets_list = None
if toolsets :
if isinstance ( toolsets , str ) :
toolsets_list = [ t . strip ( ) for t in toolsets . split ( " , " ) ]
elif isinstance ( toolsets , ( list , tuple ) ) :
# Fire may pass multiple --toolsets as a tuple
toolsets_list = [ ]
for t in toolsets :
if isinstance ( t , str ) :
toolsets_list . extend ( [ x . strip ( ) for x in t . split ( " , " ) ] )
else :
toolsets_list . append ( str ( t ) )
2026-02-02 08:26:42 -08:00
else :
2026-02-17 23:39:24 -08:00
# Check config for CLI toolsets, fallback to hermes-cli
config_cli_toolsets = CLI_CONFIG . get ( " platform_toolsets " , { } ) . get ( " cli " )
if config_cli_toolsets and isinstance ( config_cli_toolsets , list ) :
toolsets_list = config_cli_toolsets
else :
toolsets_list = [ " hermes-cli " ]
2026-01-31 06:30:48 +00:00
# Create CLI instance
cli = HermesCLI (
model = model ,
toolsets = toolsets_list ,
2026-02-20 17:24:00 -08:00
provider = provider ,
2026-01-31 06:30:48 +00:00
api_key = api_key ,
base_url = base_url ,
max_turns = max_turns ,
verbose = verbose ,
compact = compact ,
2026-02-25 22:56:12 -08:00
resume = resume ,
feat: add data-driven skin/theme engine for CLI customization
Adds a skin system that lets users customize the CLI's visual appearance
through data files (YAML) rather than code changes. Skins define: color
palette, spinner faces/verbs/wings, branding text, and tool output prefix.
New files:
- hermes_cli/skin_engine.py — SkinConfig dataclass, built-in skins
(default, ares, mono, slate), YAML loader for user skins from
~/.hermes/skins/, skin management API
- tests/hermes_cli/test_skin_engine.py — 26 tests covering config,
built-in skins, user YAML skins, display integration
Modified files:
- agent/display.py — skin-aware spinner wings, faces, verbs, tool prefix
- hermes_cli/banner.py — skin-aware banner colors (title, border, accent,
dim, text, session) via _skin_color()/_skin_branding() helpers
- cli.py — /skin command handler, skin init from config, skin-aware
response box label and welcome message
- hermes_cli/config.py — add display.skin default
- hermes_cli/commands.py — add /skin to slash commands
Built-in skins:
- default: classic Hermes gold/kawaii
- ares: crimson/bronze war-god theme (from community PRs #579/#725)
- mono: clean grayscale
- slate: cool blue developer theme
User skins: drop a YAML file in ~/.hermes/skins/ with name, colors,
spinner, branding, and tool_prefix fields. Missing values inherit from
the default skin.
2026-03-10 00:37:28 -07:00
checkpoints = checkpoints ,
2026-01-31 06:30:48 +00:00
)
feat: git worktree isolation for parallel CLI sessions (--worktree / -w)
Add a --worktree (-w) flag to the hermes CLI that creates an isolated
git worktree for the session. This allows running multiple hermes-agent
instances concurrently on the same repo without file collisions.
How it works:
- On startup with -w: detects git repo, creates .worktrees/<session>/
with its own branch (hermes/<session-id>), sets TERMINAL_CWD to it
- Each agent works in complete isolation — independent HEAD, index,
and working tree, shared git object store
- On exit: auto-removes worktree and branch if clean, warns and
keeps if there are uncommitted changes
- .worktreeinclude file support: list gitignored files (.env, .venv/)
to auto-copy/symlink into new worktrees
- .worktrees/ is auto-added to .gitignore
- Agent gets a system prompt note about the worktree context
- Config support: set worktree: true in config.yaml to always enable
Usage:
hermes -w # Interactive mode in worktree
hermes -w -q "Fix issue #123" # Single query in worktree
# Or in config.yaml:
worktree: true
Includes 17 tests covering: repo detection, worktree creation,
independence verification, cleanup (clean/dirty), .worktreeinclude,
.gitignore management, and 10 concurrent worktrees.
Closes #652
2026-03-07 20:51:08 -08:00
# Inject worktree context into agent's system prompt
if wt_info :
wt_note = (
f " \n \n [System note: You are working in an isolated git worktree at "
f " { wt_info [ ' path ' ] } . Your branch is ` { wt_info [ ' branch ' ] } `. "
f " Changes here do not affect the main working tree or other agents. "
f " Remember to commit and push your changes, and create a PR if appropriate. "
f " The original repo is at { wt_info [ ' repo_root ' ] } .] "
)
cli . system_prompt = ( cli . system_prompt or " " ) + wt_note
2026-01-31 06:30:48 +00:00
# Handle list commands (don't init agent for these)
if list_tools :
cli . show_banner ( )
cli . show_tools ( )
sys . exit ( 0 )
if list_toolsets :
cli . show_banner ( )
cli . show_toolsets ( )
sys . exit ( 0 )
2026-02-08 13:31:45 -08:00
# Register cleanup for single-query mode (interactive mode registers in run())
2026-02-16 02:43:45 -08:00
atexit . register ( _run_cleanup )
2026-02-08 13:31:45 -08:00
2026-01-31 06:30:48 +00:00
# Handle single query mode
if query :
2026-03-10 20:45:18 -07:00
if quiet :
# Quiet mode: suppress banner, spinner, tool previews.
# Only print the final response and parseable session info.
cli . tool_progress_mode = " off "
2026-03-10 20:48:58 -07:00
if cli . _init_agent ( ) :
2026-03-10 20:45:18 -07:00
cli . agent . quiet_mode = True
result = cli . agent . run_conversation ( query )
response = result . get ( " final_response " , " " ) if isinstance ( result , dict ) else str ( result )
if response :
print ( response )
print ( f " \n session_id: { cli . session_id } " )
else :
cli . show_banner ( )
cli . console . print ( f " [bold blue]Query:[/] { query } " )
cli . chat ( query )
cli . _print_exit_summary ( )
2026-01-31 06:30:48 +00:00
return
# Run interactive mode
cli . run ( )
if __name__ == " __main__ " :
fire . Fire ( main )