feat(themes): hermes skin set — deterministic one-color tweak, bg untouched

Changing a single color kept wrecking the rest because the agent hand-authored a
new skin (often from `default`, which has no `background`, resetting the terminal
to black). Add `hermes skin set <key> <hex>`: edits the ACTIVE skin's one key in
place (a built-in is forked into an editable copy carrying its full palette), so
everything else — background included — is preserved. Plus `skin use` / `skin
list`. The skill now points tweaks at this command instead of hand-authoring.
This commit is contained in:
Brooklyn Nicholson 2026-07-21 19:58:54 -05:00
parent 2a4e5fac1a
commit 4f4f938aef
5 changed files with 217 additions and 12 deletions

View file

@ -422,6 +422,7 @@ from hermes_cli.subcommands.debug import build_debug_parser
from hermes_cli.subcommands.backup import build_backup_parser
from hermes_cli.subcommands.import_cmd import build_import_cmd_parser
from hermes_cli.subcommands.config import build_config_parser
from hermes_cli.subcommands.skin import build_skin_parser
from hermes_cli.subcommands.console import build_console_parser
from hermes_cli.subcommands.version import build_version_parser
from hermes_cli.subcommands.update import build_update_parser
@ -4557,6 +4558,13 @@ def cmd_config(args):
config_command(args)
def cmd_skin(args):
"""Skin management (list / use / set)."""
from hermes_cli.skin_cmd import skin_command
skin_command(args)
def cmd_backup(args):
"""Back up Hermes home directory to a zip file."""
if getattr(args, "quick", False):
@ -13936,6 +13944,11 @@ def main():
# =========================================================================
build_config_parser(subparsers, cmd_config=cmd_config)
# =========================================================================
# skin command (parser built in hermes_cli/subcommands/skin.py)
# =========================================================================
build_skin_parser(subparsers, cmd_skin=cmd_skin)
# =========================================================================
# console command (parser built in hermes_cli/subcommands/console.py)
# =========================================================================

105
hermes_cli/skin_cmd.py Normal file
View file

@ -0,0 +1,105 @@
"""``hermes skin`` — list, switch, and tweak skins from the CLI.
``set`` is the load-bearing verb: it changes ONE color of the ACTIVE skin **in
place**, so tweaking (say) the tool marker never disturbs the rest of the look —
background included. Editing the file bumps its mtime; the gateway's skin watcher
repaints every live surface within ~a second. A built-in skin (no file) is forked
into an editable copy that carries its full palette, so the current look is
preserved and only the one key changes.
"""
from __future__ import annotations
import argparse
import re
import sys
from pathlib import Path
from hermes_constants import display_hermes_home, get_hermes_home
_HEX_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
def _skins_dir() -> Path:
return get_hermes_home() / "skins"
def _active_skin() -> str:
from hermes_cli.config import load_config
display = (load_config() or {}).get("display") or {}
return str(display.get("skin") or "default")
def _use(name: str) -> None:
"""Activate a skin (persists display.skin via the shared config writer)."""
from hermes_cli.config import config_command
config_command(argparse.Namespace(config_command="set", key="display.skin", value=name, force=True))
def _skin_set(key: str, value: str, skin: str | None) -> int:
import yaml
if not _HEX_RE.match(value):
print(f"✗ {value!r} is not a #rrggbb hex color", file=sys.stderr)
return 1
name = skin or _active_skin()
path = _skins_dir() / f"{name}.yaml"
if path.exists():
data = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
target = name
else:
# Built-in (or missing): fork into an editable copy that keeps its full
# palette, under a fresh name so the built-in stays intact for revert.
from hermes_cli.skin_engine import load_skin
resolved = load_skin(name)
target = f"{name}-custom"
path = _skins_dir() / f"{target}.yaml"
data = {
"name": target,
"description": f"{name} + custom {key}",
"colors": dict(resolved.colors),
"branding": dict(resolved.branding),
"tool_prefix": resolved.tool_prefix,
}
if not isinstance(data.get("colors"), dict):
data["colors"] = {}
data["colors"][key] = value
data.setdefault("name", target)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(yaml.safe_dump(data, sort_keys=False, allow_unicode=True), encoding="utf-8")
if target != name:
_use(target)
print(f"✓ {key} = {value} in {display_hermes_home()}/skins/{target}.yaml (live within ~1s)")
return 0
def _skin_list() -> int:
from hermes_cli.skin_engine import list_skins
active = _active_skin()
for s in list_skins():
mark = "*" if s["name"] == active else " "
print(f"{mark} {s['name']:<16} {s.get('source', ''):<8} {s.get('description', '')}")
return 0
def skin_command(args) -> None:
"""Dispatch ``hermes skin <verb>``."""
verb = getattr(args, "skin_command", None)
if verb == "set":
sys.exit(_skin_set(args.key, args.value, getattr(args, "skin", None)))
elif verb == "use":
_use(args.name)
print(f"✓ active skin → {args.name} (live within ~1s)")
else: # list / default
sys.exit(_skin_list())

View file

@ -0,0 +1,30 @@
"""``hermes skin`` subcommand parser."""
from __future__ import annotations
from typing import Callable
def build_skin_parser(subparsers, *, cmd_skin: Callable) -> None:
"""Attach the ``skin`` subcommand to ``subparsers``."""
skin_parser = subparsers.add_parser(
"skin",
help="List, switch, and tweak skins",
description="Manage Hermes skins. `set` tweaks one color of the active skin in place.",
)
skin_subparsers = skin_parser.add_subparsers(dest="skin_command")
skin_subparsers.add_parser("list", help="List available skins")
skin_use = skin_subparsers.add_parser("use", help="Switch the active skin")
skin_use.add_argument("name", help="Skin name")
# skin set — change ONE color of the active skin in place (bg untouched).
skin_set = skin_subparsers.add_parser(
"set", help="Set one color of the active skin (e.g. `skin set ui_tool '#00FFFF'`)"
)
skin_set.add_argument("key", help="Color key (e.g. ui_tool, ui_accent, background)")
skin_set.add_argument("value", help="Hex color (#rrggbb)")
skin_set.add_argument("--skin", help="Target a specific skin instead of the active one")
skin_parser.set_defaults(func=cmd_skin)

View file

@ -93,19 +93,19 @@ so to recolor *only* tool calls (the classic "change the gold `●`") set `ui_to
## Tweak the active look (change one thing)
When the user wants to adjust the CURRENT look ("make the tool `●` cyan", "warmer
background"), **edit the active skin in place** — do NOT create a new skin from
`default`, which drops the current palette (background included).
background"), use the one deterministic command — it edits the ACTIVE skin's ONE
key in place, so everything else (background included) is untouched:
1. Find the active skin: `hermes config get display.skin`.
2. **If a file exists** at `<hermes-home>/skins/<active>.yaml`: `patch` ONLY the
key(s) you're changing (e.g. add/replace `ui_tool: "#00FFFF"`), leaving every
other line untouched. Saving bumps the file's mtime; the watcher repaints live
— no `config set` needed, name unchanged.
3. **If the active skin is a built-in** (no file — e.g. `default`, `mono`): fork
it once, carrying its FULL palette into a new user skin, then change the one
key and `hermes config set display.skin <newname>`. Copy `templates/skin.yaml`
and match the built-in's colors; never start from a bare `default` fork that
omits `background`.
```
hermes skin set <key> <hex> # e.g. hermes skin set ui_tool "#00FFFF"
```
It edits the active skin's file (a built-in is forked into an editable copy that
keeps its full palette), the watcher repaints live, and nothing else moves. Do
NOT hand-write a new skin from `default` for a tweak — that drops the current
palette and resets the background. `hermes skin set background "#08201f"` changes
only the background; `hermes skin use <name>` / `hermes skin list` switch and
enumerate.
## Pitfalls

View file

@ -0,0 +1,57 @@
"""`hermes skin set` — deterministic single-color tweak of the active skin.
The whole point is that changing one token never disturbs the rest of the look
(background especially), which hand-authoring kept getting wrong.
"""
import yaml
from hermes_cli import skin_cmd
from hermes_constants import get_hermes_home
def _skins():
d = get_hermes_home() / "skins"
d.mkdir(parents=True, exist_ok=True)
return d
def _activate(name: str) -> None:
(get_hermes_home() / "config.yaml").write_text(f"display:\n skin: {name}\n", encoding="utf-8")
def test_set_edits_active_user_skin_in_place_preserving_everything_else():
(_skins() / "oasis.yaml").write_text(
'name: oasis\ncolors:\n background: "#08201f"\n banner_title: "#f2dfb3"\n', encoding="utf-8"
)
_activate("oasis")
assert skin_cmd._skin_set("ui_tool", "#00FFFF", None) == 0
data = yaml.safe_load((_skins() / "oasis.yaml").read_text())
assert data["colors"]["ui_tool"] == "#00FFFF"
assert data["colors"]["background"] == "#08201f" # untouched — the whole point
assert data["colors"]["banner_title"] == "#f2dfb3"
assert data["name"] == "oasis" # no rename, no fork
assert not (_skins() / "oasis-custom.yaml").exists()
def test_set_forks_a_builtin_without_inventing_a_background():
_activate("default") # a built-in — no file
assert skin_cmd._skin_set("ui_tool", "#00FFFF", None) == 0
fork = _skins() / "default-custom.yaml"
assert fork.exists()
data = yaml.safe_load(fork.read_text())
assert data["colors"]["ui_tool"] == "#00FFFF"
# default has no background, so the fork must not invent one (terminal stays put).
assert "background" not in data["colors"]
# full palette carried over, and it became active.
assert data["colors"].get("banner_title")
assert (get_hermes_home() / "config.yaml").read_text().find("default-custom") != -1
def test_set_rejects_non_hex():
_activate("default")
assert skin_cmd._skin_set("ui_tool", "teal", None) == 1