skin_engine.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. """Hermes skin/theme engine — the theme SDK for every surface."""
  2. import logging
  3. from dataclasses import dataclass, field
  4. from pathlib import Path
  5. from typing import Any, Dict, List, Optional, Tuple
  6. from hermes_constants import get_hermes_home
  7. logger = logging.getLogger(__name__)
  8. @dataclass
  9. class SkinConfig:
  10. """Complete skin configuration."""
  11. name: str
  12. description: str = ""
  13. colors: dict[str, str] = field(default_factory=dict)
  14. # Paired palettes for the opposite background polarity (mirrors the desktop app's
  15. # colors/darkColors pairing): a light terminal prefers `light_colors` (falling back to
  16. # `colors`), and vice versa for `dark_colors`.
  17. light_colors: dict[str, str] = field(default_factory=dict)
  18. dark_colors: dict[str, str] = field(default_factory=dict)
  19. spinner: dict[str, Any] = field(default_factory=dict)
  20. branding: dict[str, str] = field(default_factory=dict)
  21. tool_prefix: str = "┊"
  22. tool_emojis: dict[str, str] = field(default_factory=dict) # per-tool emoji overrides
  23. banner_logo: str = "" # Rich-markup ASCII art logo (replaces HERMES_AGENT_LOGO)
  24. banner_hero: str = "" # Rich-markup hero art (replaces HERMES_CADUCEUS)
  25. custom_css: str = "" # Raw CSS injected as a <style> tag on the desktop GUI (32 KiB cap)
  26. def get_color(self, key: str, fallback: str = "") -> str:
  27. return self.colors.get(key, fallback)
  28. def get_branding(self, key: str, fallback: str = "") -> str:
  29. return self.branding.get(key, fallback)
  30. def get_spinner_wings(self) -> list[tuple[str, str]]:
  31. """Spinner wing pairs, or empty list if none."""
  32. return [(str(pair[0]), str(pair[1])) for pair in self.spinner.get("wings", [])
  33. if isinstance(pair, (list, tuple)) and len(pair) == 2]
  34. def _branding(who: str, symbol: str, goodbye: str, prompt: str = "", help_header: str = "") -> dict[str, str]:
  35. """Branding block for a "<who> Agent" persona keyed by its glyph."""
  36. return {
  37. "agent_name": f"{who} Agent",
  38. "welcome": f"Welcome to {who} Agent! Type your message or /help for commands.",
  39. "goodbye": goodbye, "response_label": f" {symbol} {who} ", "prompt_symbol": prompt or symbol,
  40. "help_header": help_header or f"({symbol}) Available Commands"}
  41. def _wings(*glyphs) -> list[list[str]]:
  42. """Spinner wing pairs `⟪g` / `g⟫`; a (left, right) tuple gives asymmetric glyphs."""
  43. return [[f"⟪{g[0] if isinstance(g, tuple) else g}", f"{g[1] if isinstance(g, tuple) else g}⟫"]
  44. for g in glyphs]
  45. # Branding shared by every Hermes-named built-in (mono/daylight override help_header).
  46. _HERMES_BRANDING: dict[str, str] = _branding(
  47. "Hermes", "☤", "Goodbye! ☤", prompt="❯", help_header="(^_^)? Available Commands")
  48. _BUILTIN_SKINS: dict[str, dict[str, Any]] = {
  49. "default": {
  50. "name": "default", "description": "Classic Hermes — gold and kawaii",
  51. # Dark-authored; values match the TUI's DARK_THEME so both render the same gold.
  52. "colors": {
  53. "banner_border": "#CD7F32", "banner_title": "#FFD700", "banner_accent": "#FFBF00",
  54. "banner_dim": "#B8860B", "banner_text": "#FFF8DC", "ui_accent": "#FFBF00",
  55. "ui_label": "#DAA520", "ui_ok": "#4caf50", "ui_error": "#ef5350", "ui_warn": "#ffa726",
  56. "prompt": "#FFF8DC", "input_rule": "#CD7F32", "response_border": "#FFD700",
  57. "status_bar_bg": "#1a1a2e", "status_bar_text": "#C0C0C0",
  58. "status_bar_strong": "#FFD700", "status_bar_dim": "#8A7A4A",
  59. "status_bar_good": "#8FBC8F", "status_bar_warn": "#FFD700", "status_bar_bad": "#FF8C00",
  60. "status_bar_critical": "#FF6B6B", "session_label": "#DAA520",
  61. "session_border": "#8B8682", "completion_menu_bg": "#1a1a2e",
  62. "completion_menu_current_bg": "#333355", "selection_bg": "#3a3a55",
  63. "shell_dollar": "#4dabf7", "voice_status_bg": "#1a1a2e"},
  64. # Light overlay (merged onto `colors`). Goldenrod ladder: on white the vivid
  65. # #FFD700/#FFBF00 read as glare and WCAG-darkened mustard (#867000) as mud; the
  66. # statusbar's goldenrod family (#B8860B/#DAA520) keeps the hue, tames saturation.
  67. # Hierarchy on white: ink body 8.9:1 > fade 5.2 > label 3.7 > muted 3.3 > title 2.7 >
  68. # headers 2.4. Fills (*_bg) flip the dark navy surfaces to light polarity.
  69. "light_colors": {
  70. "banner_title": "#C8961E", "banner_accent": "#D89B04", "banner_dim": "#B8860B",
  71. "banner_text": "#5C4718", "ui_accent": "#D89B04", "ui_label": "#A97E10",
  72. "ui_ok": "#2E7D32", "ui_error": "#C62828", "ui_warn": "#D97706", "prompt": "#5C4718",
  73. "response_border": "#C8961E", "session_label": "#A97E10", "status_bar_text": "#6F6F6F",
  74. "status_bar_strong": "#C8961E", "status_bar_dim": "#9A8A5A",
  75. "status_bar_good": "#2E7D32", "status_bar_warn": "#C8961E", "status_bar_bad": "#C2410C",
  76. "status_bar_critical": "#B91C1C", "shell_dollar": "#1E6FC0",
  77. "completion_menu_bg": "#F5F5F5", "completion_menu_current_bg": "#E0D1BF",
  78. "selection_bg": "#D4E4F7", "status_bar_bg": "#F5F5F5", "voice_status_bg": "#F5F5F5"},
  79. "spinner": {}, # empty = hardcoded defaults in display.py
  80. "branding": _HERMES_BRANDING,
  81. "tool_prefix": "┊"},
  82. "ares": {
  83. "name": "ares", "description": "War-god theme — crimson and bronze",
  84. "colors": {
  85. "banner_border": "#A93333", "banner_title": "#C7A96B", "banner_accent": "#DD4A3A",
  86. "banner_dim": "#905151", "banner_text": "#F1E6CF", "ui_accent": "#DD4A3A",
  87. "ui_label": "#C7A96B", "ui_ok": "#4caf50", "ui_error": "#ef5350", "ui_warn": "#ffa726",
  88. "prompt": "#F1E6CF", "input_rule": "#A93333", "response_border": "#C7A96B",
  89. "status_bar_bg": "#2A1212", "status_bar_text": "#F1E6CF",
  90. "status_bar_strong": "#C7A96B", "status_bar_dim": "#756054",
  91. "status_bar_good": "#7BC96F", "status_bar_warn": "#C7A96B", "status_bar_bad": "#DD4A3A",
  92. "status_bar_critical": "#EF5350", "session_label": "#C7A96B",
  93. "session_border": "#6E584B", "completion_menu_bg": "#2A1212",
  94. "completion_menu_current_bg": "#5C221D", "selection_bg": "#692620",
  95. "shell_dollar": "#DD4A3A", "voice_status_bg": "#2A1212"},
  96. "spinner": {
  97. "waiting_faces": ["(⚔)", "(⛨)", "(▲)", "(<>)", "(/)"],
  98. "thinking_faces": ["(⚔)", "(⛨)", "(▲)", "(⌁)", "(<>)"],
  99. "thinking_verbs": [
  100. "forging", "marching", "sizing the field", "holding the line",
  101. "hammering plans", "tempering steel", "plotting impact", "raising the shield"],
  102. "wings": _wings("⚔", "▲", ("╸", "╺"), "⛨")},
  103. "branding": _branding("Ares", "⚔", "Farewell, warrior! ⚔"),
  104. "tool_prefix": "╎",
  105. "banner_logo": """[bold #A3261F] █████╗ ██████╗ ███████╗███████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗[/]
  106. [bold #B73122]██╔══██╗██╔══██╗██╔════╝██╔════╝ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝[/]
  107. [#C93C24]███████║██████╔╝█████╗ ███████╗█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║[/]
  108. [#D84A28]██╔══██║██╔══██╗██╔══╝ ╚════██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║[/]
  109. [#E15A2D]██║ ██║██║ ██║███████╗███████║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║[/]
  110. [#EB6C32]╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝[/]""",
  111. "banner_hero": """[#9F1C1C]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  112. [#9F1C1C]⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⠟⠻⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  113. [#C7A96B]⠀⠀⠀⠀⠀⠀⠀⣠⣾⡿⠋⠀⠀⠀⠙⢿⣷⣄⠀⠀⠀⠀⠀⠀⠀[/]
  114. [#C7A96B]⠀⠀⠀⠀⠀⢀⣾⡿⠋⠀⠀⢠⡄⠀⠀⠙⢿⣷⡀⠀⠀⠀⠀⠀[/]
  115. [#DD4A3A]⠀⠀⠀⠀⣰⣿⠟⠀⠀⠀⣰⣿⣿⣆⠀⠀⠀⠻⣿⣆⠀⠀⠀⠀[/]
  116. [#DD4A3A]⠀⠀⠀⢰⣿⠏⠀⠀⢀⣾⡿⠉⢿⣷⡀⠀⠀⠹⣿⡆⠀⠀⠀[/]
  117. [#9F1C1C]⠀⠀⠀⣿⡟⠀⠀⣠⣿⠟⠀⠀⠀⠻⣿⣄⠀⠀⢻⣿⠀⠀⠀[/]
  118. [#9F1C1C]⠀⠀⠀⣿⡇⠀⠀⠙⠋⠀⠀⚔⠀⠀⠙⠋⠀⠀⢸⣿⠀⠀⠀[/]
  119. [#6B1717]⠀⠀⠀⢿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⡿⠀⠀⠀[/]
  120. [#6B1717]⠀⠀⠀⠘⢿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⡿⠃⠀⠀⠀[/]
  121. [#C7A96B]⠀⠀⠀⠀⠈⠻⣿⣷⣦⣤⣀⣀⣤⣤⣶⣿⠿⠋⠀⠀⠀⠀[/]
  122. [#C7A96B]⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⠿⠿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀[/]
  123. [#DD4A3A]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚔⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  124. [dim #6B1717]⠀⠀⠀⠀⠀⠀⠀⠀war god online⠀⠀⠀⠀⠀⠀⠀⠀[/]""",
  125. },
  126. "mono": {
  127. "name": "mono", "description": "Monochrome — clean grayscale",
  128. "colors": {
  129. "banner_border": "#5E5E5E", "banner_title": "#e6edf3", "banner_accent": "#aaaaaa",
  130. "banner_dim": "#606060", "banner_text": "#c9d1d9", "ui_accent": "#aaaaaa",
  131. "ui_label": "#888888", "ui_ok": "#888888", "ui_error": "#cccccc", "ui_warn": "#999999",
  132. "prompt": "#c9d1d9", "input_rule": "#606060", "response_border": "#aaaaaa",
  133. "status_bar_bg": "#1F1F1F", "status_bar_text": "#C9D1D9",
  134. "status_bar_strong": "#E6EDF3", "status_bar_dim": "#777777",
  135. "status_bar_good": "#B5B5B5", "status_bar_warn": "#AAAAAA", "status_bar_bad": "#D0D0D0",
  136. "status_bar_critical": "#F0F0F0", "session_label": "#888888",
  137. "session_border": "#5E5E5E", "completion_menu_bg": "#1F1F1F",
  138. "completion_menu_current_bg": "#464646", "selection_bg": "#505050",
  139. "shell_dollar": "#aaaaaa", "voice_status_bg": "#1F1F1F"},
  140. "spinner": {},
  141. "branding": {**_HERMES_BRANDING, "help_header": "[?] Available Commands"},
  142. "tool_prefix": "┊"},
  143. "slate": {
  144. "name": "slate", "description": "Cool blue — developer-focused",
  145. "colors": {
  146. "banner_border": "#4169e1", "banner_title": "#7eb8f6", "banner_accent": "#8EA8FF",
  147. "banner_dim": "#545E6B", "banner_text": "#c9d1d9", "ui_accent": "#7eb8f6",
  148. "ui_label": "#8EA8FF", "ui_ok": "#63D0A6", "ui_error": "#F7A072", "ui_warn": "#e6a855",
  149. "prompt": "#c9d1d9", "input_rule": "#4169e1", "response_border": "#7eb8f6",
  150. "status_bar_bg": "#151C2F", "status_bar_text": "#C9D1D9",
  151. "status_bar_strong": "#7EB8F6", "status_bar_dim": "#5D6672",
  152. "status_bar_good": "#63D0A6", "status_bar_warn": "#E6A855", "status_bar_bad": "#F7A072",
  153. "status_bar_critical": "#FF7A7A", "session_label": "#7eb8f6",
  154. "session_border": "#545E6B", "completion_menu_bg": "#151C2F",
  155. "completion_menu_current_bg": "#324867", "selection_bg": "#3A5375",
  156. "shell_dollar": "#7eb8f6", "voice_status_bg": "#151C2F"},
  157. "spinner": {}, "branding": _HERMES_BRANDING, "tool_prefix": "┊"},
  158. "daylight": {
  159. "name": "daylight",
  160. "description": "Light theme for bright terminals with dark text and cool blue accents",
  161. "colors": {
  162. "banner_border": "#2563EB", "banner_title": "#0F172A", "banner_accent": "#1D4ED8",
  163. "banner_dim": "#475569", "banner_text": "#111827", "ui_accent": "#2563EB",
  164. "ui_label": "#0F766E", "ui_ok": "#15803D", "ui_error": "#B91C1C", "ui_warn": "#B45309",
  165. "prompt": "#111827", "input_rule": "#6E94BE", "response_border": "#2563EB",
  166. "status_bar_bg": "#E5EDF8", "status_bar_text": "#111827",
  167. "status_bar_strong": "#2563EB", "status_bar_dim": "#838890",
  168. "status_bar_good": "#15803D", "status_bar_warn": "#B45309", "status_bar_bad": "#B45309",
  169. "status_bar_critical": "#B91C1C", "session_label": "#1D4ED8",
  170. "session_border": "#64748B", "completion_menu_bg": "#F8FAFC",
  171. "completion_menu_current_bg": "#DBEAFE", "completion_menu_meta_bg": "#EEF2FF",
  172. "completion_menu_meta_current_bg": "#BFDBFE", "selection_bg": "#D3E0FB",
  173. "shell_dollar": "#2563EB", "voice_status_bg": "#E5EDF8"},
  174. "spinner": {},
  175. "branding": {**_HERMES_BRANDING, "help_header": "[?] Available Commands"},
  176. "tool_prefix": "│"},
  177. "warm-lightmode": {
  178. "name": "warm-lightmode",
  179. "description": "Warm light mode — dark brown/gold text for light terminal backgrounds",
  180. "colors": {
  181. "banner_border": "#8B6914", "banner_title": "#5C3D11", "banner_accent": "#8B4513",
  182. "banner_dim": "#8B7355", "banner_text": "#2C1810", "ui_accent": "#8B4513",
  183. "ui_label": "#5C3D11", "ui_ok": "#2E7D32", "ui_error": "#C62828", "ui_warn": "#E65100",
  184. "prompt": "#2C1810", "input_rule": "#8B6914", "response_border": "#8B6914",
  185. "status_bar_bg": "#F5F0E8", "status_bar_text": "#2C1810",
  186. "status_bar_strong": "#8B4513", "status_bar_dim": "#8A8F98",
  187. "status_bar_good": "#2E7D32", "status_bar_warn": "#E65100", "status_bar_bad": "#DA4D00",
  188. "status_bar_critical": "#C62828", "session_label": "#5C3D11",
  189. "session_border": "#A0845C", "completion_menu_bg": "#F5EFE0",
  190. "completion_menu_current_bg": "#E8DCC8", "completion_menu_meta_bg": "#F0E8D8",
  191. "completion_menu_meta_current_bg": "#DFCFB0", "selection_bg": "#E8DAD0",
  192. "shell_dollar": "#8B4513", "voice_status_bg": "#F5F0E8"},
  193. "spinner": {}, "branding": _HERMES_BRANDING, "tool_prefix": "┊"},
  194. "poseidon": {
  195. "name": "poseidon", "description": "Ocean-god theme — deep blue and seafoam",
  196. "colors": {
  197. "banner_border": "#2A6FB9", "banner_title": "#A9DFFF", "banner_accent": "#5DB8F5",
  198. "banner_dim": "#44638F", "banner_text": "#EAF7FF", "ui_accent": "#5DB8F5",
  199. "ui_label": "#A9DFFF", "ui_ok": "#4caf50", "ui_error": "#ef5350", "ui_warn": "#ffa726",
  200. "prompt": "#EAF7FF", "input_rule": "#2A6FB9", "response_border": "#5DB8F5",
  201. "status_bar_bg": "#0F2440", "status_bar_text": "#EAF7FF",
  202. "status_bar_strong": "#A9DFFF", "status_bar_dim": "#52708A",
  203. "status_bar_good": "#6ED7B0", "status_bar_warn": "#5DB8F5", "status_bar_bad": "#3576BC",
  204. "status_bar_critical": "#D94F4F", "session_label": "#A9DFFF",
  205. "session_border": "#496884", "completion_menu_bg": "#0F2440",
  206. "completion_menu_current_bg": "#254D73", "selection_bg": "#2A587F",
  207. "shell_dollar": "#5DB8F5", "voice_status_bg": "#0F2440"},
  208. "spinner": {
  209. "waiting_faces": ["(≈)", "(Ψ)", "(∿)", "(◌)", "(◠)"],
  210. "thinking_faces": ["(Ψ)", "(∿)", "(≈)", "(⌁)", "(◌)"],
  211. "thinking_verbs": [
  212. "charting currents", "sounding the depth", "reading foam lines",
  213. "steering the trident", "tracking undertow", "plotting sea lanes",
  214. "calling the swell", "measuring pressure"],
  215. "wings": _wings("≈", "Ψ", "∿", "◌")},
  216. "branding": _branding("Poseidon", "Ψ", "Fair winds! Ψ"),
  217. "tool_prefix": "│",
  218. "banner_logo": """[bold #B8E8FF]██████╗ ██████╗ ███████╗███████╗██╗██████╗ ██████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗[/]
  219. [bold #97D6FF]██╔══██╗██╔═══██╗██╔════╝██╔════╝██║██╔══██╗██╔═══██╗████╗ ██║ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝[/]
  220. [#75C1F6]██████╔╝██║ ██║███████╗█████╗ ██║██║ ██║██║ ██║██╔██╗ ██║█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║[/]
  221. [#4FA2E0]██╔═══╝ ██║ ██║╚════██║██╔══╝ ██║██║ ██║██║ ██║██║╚██╗██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║[/]
  222. [#2E7CC7]██║ ╚██████╔╝███████║███████╗██║██████╔╝╚██████╔╝██║ ╚████║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║[/]
  223. [#1B4F95]╚═╝ ╚═════╝ ╚══════╝╚══════╝╚═╝╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝[/]""",
  224. "banner_hero": """[#2A6FB9]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  225. [#5DB8F5]⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  226. [#5DB8F5]⠀⠀⠀⠀⠀⠀⠀⢠⣿⠏⠀Ψ⠀⠹⣿⡄⠀⠀⠀⠀⠀⠀⠀[/]
  227. [#A9DFFF]⠀⠀⠀⠀⠀⠀⠀⣿⡟⠀⠀⠀⠀⠀⢻⣿⠀⠀⠀⠀⠀⠀⠀[/]
  228. [#A9DFFF]⠀⠀⠀≈≈≈≈≈⣿⡇⠀⠀⠀⠀⠀⢸⣿≈≈≈≈≈⠀⠀⠀[/]
  229. [#5DB8F5]⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀[/]
  230. [#2A6FB9]⠀⠀⠀⠀⠀⠀⠀⢿⣧⠀⠀⠀⠀⠀⣼⡿⠀⠀⠀⠀⠀⠀⠀[/]
  231. [#2A6FB9]⠀⠀⠀⠀⠀⠀⠀⠘⢿⣷⣄⣀⣠⣾⡿⠃⠀⠀⠀⠀⠀⠀⠀[/]
  232. [#153C73]⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀[/]
  233. [#153C73]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  234. [#5DB8F5]⠀⠀⠀⠀⠀≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈⠀⠀⠀⠀⠀[/]
  235. [#A9DFFF]⠀⠀⠀⠀⠀⠀≈≈≈≈≈≈≈≈≈≈≈≈≈⠀⠀⠀⠀⠀⠀[/]
  236. [dim #153C73]⠀⠀⠀⠀⠀⠀⠀deep waters hold⠀⠀⠀⠀⠀⠀⠀[/]""",
  237. },
  238. "sisyphus": {
  239. "name": "sisyphus", "description": "Sisyphean theme — austere grayscale with persistence",
  240. "colors": {
  241. "banner_border": "#B7B7B7", "banner_title": "#F5F5F5", "banner_accent": "#E7E7E7",
  242. "banner_dim": "#5C5C5C", "banner_text": "#D3D3D3", "ui_accent": "#E7E7E7",
  243. "ui_label": "#D3D3D3", "ui_ok": "#919191", "ui_error": "#E7E7E7", "ui_warn": "#B7B7B7",
  244. "prompt": "#F5F5F5", "input_rule": "#656565", "response_border": "#B7B7B7",
  245. "status_bar_bg": "#202020", "status_bar_text": "#D3D3D3",
  246. "status_bar_strong": "#F5F5F5", "status_bar_dim": "#6D6D6D",
  247. "status_bar_good": "#B7B7B7", "status_bar_warn": "#D3D3D3", "status_bar_bad": "#E7E7E7",
  248. "status_bar_critical": "#F5F5F5", "session_label": "#919191",
  249. "session_border": "#656565", "completion_menu_bg": "#202020",
  250. "completion_menu_current_bg": "#585858", "selection_bg": "#666666",
  251. "shell_dollar": "#E7E7E7", "voice_status_bg": "#202020"},
  252. "spinner": {
  253. "waiting_faces": ["(◉)", "(◌)", "(◬)", "(⬤)", "(::)"],
  254. "thinking_faces": ["(◉)", "(◬)", "(◌)", "(○)", "(●)"],
  255. "thinking_verbs": [
  256. "finding traction", "measuring the grade", "resetting the boulder",
  257. "counting the ascent", "testing leverage", "setting the shoulder",
  258. "pushing uphill", "enduring the loop"],
  259. "wings": _wings("◉", "◬", "◌", "⬤")},
  260. "branding": _branding("Sisyphus", "◉", "The boulder waits. ◉"),
  261. "tool_prefix": "│",
  262. "banner_logo": """[bold #F5F5F5]███████╗██╗███████╗██╗ ██╗██████╗ ██╗ ██╗██╗ ██╗███████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗[/]
  263. [bold #E7E7E7]██╔════╝██║██╔════╝╚██╗ ██╔╝██╔══██╗██║ ██║██║ ██║██╔════╝ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝[/]
  264. [#D7D7D7]███████╗██║███████╗ ╚████╔╝ ██████╔╝███████║██║ ██║███████╗█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║[/]
  265. [#BFBFBF]╚════██║██║╚════██║ ╚██╔╝ ██╔═══╝ ██╔══██║██║ ██║╚════██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║[/]
  266. [#8F8F8F]███████║██║███████║ ██║ ██║ ██║ ██║╚██████╔╝███████║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║[/]
  267. [#626262]╚══════╝╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝[/]""",
  268. "banner_hero": """[#B7B7B7]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  269. [#D3D3D3]⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀[/]
  270. [#E7E7E7]⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀[/]
  271. [#F5F5F5]⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀[/]
  272. [#E7E7E7]⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀[/]
  273. [#D3D3D3]⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀[/]
  274. [#B7B7B7]⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⠿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  275. [#919191]⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  276. [#656565]⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  277. [#656565]⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  278. [#4A4A4A]⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  279. [#4A4A4A]⠀⠀⠀⠀⠀⣀⣴⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀⠀[/]
  280. [#656565]⠀⠀⠀━━━━━━━━━━━━━━━━━━━━━━━⠀⠀⠀[/]
  281. [dim #4A4A4A]⠀⠀⠀⠀⠀⠀⠀⠀⠀the boulder⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]""",
  282. },
  283. "charizard": {
  284. "name": "charizard", "description": "Volcanic theme — burnt orange and ember",
  285. "colors": {
  286. "banner_border": "#C75B1D", "banner_title": "#FFD39A", "banner_accent": "#F29C38",
  287. "banner_dim": "#C58A45", "banner_text": "#FFF0D4", "ui_accent": "#F29C38",
  288. "ui_label": "#FFD39A", "ui_ok": "#4caf50", "ui_error": "#ef5350", "ui_warn": "#ffa726",
  289. "prompt": "#FFF0D4", "input_rule": "#C75B1D", "response_border": "#F29C38",
  290. "status_bar_bg": "#2B160E", "status_bar_text": "#FFF0D4",
  291. "status_bar_strong": "#FFD39A", "status_bar_dim": "#826144",
  292. "status_bar_good": "#6BCB77", "status_bar_warn": "#F29C38", "status_bar_bad": "#E2832B",
  293. "status_bar_critical": "#EF5350", "session_label": "#FFD39A",
  294. "session_border": "#7B593A", "completion_menu_bg": "#0B0503",
  295. "completion_menu_current_bg": "#4A1B07", "completion_menu_meta_bg": "#120806",
  296. "completion_menu_meta_current_bg": "#5A260D", "selection_bg": "#5A260D",
  297. "shell_dollar": "#F29C38", "voice_status_bg": "#2B160E"},
  298. "spinner": {
  299. "waiting_faces": ["(✦)", "(▲)", "(◇)", "(<>)", "(🔥)"],
  300. "thinking_faces": ["(✦)", "(▲)", "(◇)", "(⌁)", "(🔥)"],
  301. "thinking_verbs": [
  302. "banking into the draft", "measuring burn", "reading the updraft",
  303. "tracking ember fall", "setting wing angle", "holding the flame core",
  304. "plotting a hot landing", "coiling for lift"],
  305. "wings": _wings("✦", "▲", "◌", "◇")},
  306. "branding": _branding("Charizard", "✦", "Flame out! ✦"),
  307. "tool_prefix": "│",
  308. "banner_logo": """[bold #FFF0D4] ██████╗██╗ ██╗ █████╗ ██████╗ ██╗███████╗ █████╗ ██████╗ ██████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗[/]
  309. [bold #FFD39A]██╔════╝██║ ██║██╔══██╗██╔══██╗██║╚══███╔╝██╔══██╗██╔══██╗██╔══██╗ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝[/]
  310. [#F29C38]██║ ███████║███████║██████╔╝██║ ███╔╝ ███████║██████╔╝██║ ██║█████╗███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║[/]
  311. [#E2832B]██║ ██╔══██║██╔══██║██╔══██╗██║ ███╔╝ ██╔══██║██╔══██╗██║ ██║╚════╝██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║[/]
  312. [#C75B1D]╚██████╗██║ ██║██║ ██║██║ ██║██║███████╗██║ ██║██║ ██║██████╔╝ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║[/]
  313. [#7A3511] ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝[/]""",
  314. "banner_hero": """[#FFD39A]⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠶⠶⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  315. [#F29C38]⠀⠀⠀⠀⠀⠀⣴⠟⠁⠀⠀⠀⠀⠈⠻⣦⠀⠀⠀⠀⠀⠀[/]
  316. [#F29C38]⠀⠀⠀⠀⠀⣼⠏⠀⠀⠀✦⠀⠀⠀⠀⠹⣧⠀⠀⠀⠀⠀[/]
  317. [#E2832B]⠀⠀⠀⠀⢰⡟⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢻⡆⠀⠀⠀⠀[/]
  318. [#E2832B]⠀⠀⣠⡾⠛⠁⣠⣾⠟⠉⠀⠉⠻⣷⣄⠀⠈⠛⢷⣄⠀⠀[/]
  319. [#C75B1D]⠀⣼⠟⠀⢀⣾⠟⠁⠀⠀⠀⠀⠀⠈⠻⣷⡀⠀⠻⣧⠀[/]
  320. [#C75B1D]⢸⡟⠀⠀⣿⡟⠀⠀⠀🔥⠀⠀⠀⠀⢻⣿⠀⠀⢻⡇[/]
  321. [#7A3511]⠀⠻⣦⡀⠘⢿⣧⡀⠀⠀⠀⠀⠀⢀⣼⡿⠃⢀⣴⠟⠀[/]
  322. [#7A3511]⠀⠀⠈⠻⣦⣀⠙⢿⣷⣤⣤⣤⣾⡿⠋⣀⣴⠟⠁⠀⠀[/]
  323. [#C75B1D]⠀⠀⠀⠀⠈⠙⠛⠶⠤⠭⠭⠤⠶⠛⠋⠁⠀⠀⠀⠀[/]
  324. [#F29C38]⠀⠀⠀⠀⠀⠀⠀⠀⣰⡿⢿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀[/]
  325. [#F29C38]⠀⠀⠀⠀⠀⠀⠀⣼⡟⠀⠀⢻⣧⠀⠀⠀⠀⠀⠀⠀⠀[/]
  326. [dim #7A3511]⠀⠀⠀⠀⠀⠀⠀tail flame lit⠀⠀⠀⠀⠀⠀⠀⠀[/]""",
  327. }}
  328. _active_skin: Optional[SkinConfig] = None
  329. _active_skin_name: str = "default"
  330. # Routed multiplex profiles: (name, skin) per home key. ``display.skin`` and ``<home>/skins/*.yaml``
  331. # are per profile, and the relay display name / TUI skin payload are read under each profile's
  332. # override — one module slot would be last-writer-wins across profiles. Unscoped keeps the module slot.
  333. _active_skin_by_home: dict[str, tuple[str, SkinConfig]] = {}
  334. def _routed_home_key() -> Optional[str]:
  335. from hermes_constants import get_hermes_home_override, hermes_home_key
  336. return None if get_hermes_home_override() is None else hermes_home_key()
  337. def _profile_config() -> dict:
  338. try:
  339. from hermes_cli.config import load_config_readonly
  340. return load_config_readonly() or {}
  341. except Exception:
  342. return {}
  343. def _skins_dir() -> Path:
  344. return get_hermes_home() / "skins"
  345. def _load_skin_from_yaml(path: Path) -> Optional[dict[str, Any]]:
  346. """Load a skin definition from a YAML file; None on any failure."""
  347. try:
  348. import hermes_yaml as yaml
  349. with open(path, "r", encoding="utf-8-sig") as f:
  350. data = yaml.safe_load(f)
  351. if isinstance(data, dict) and "name" in data:
  352. return data
  353. except Exception as e:
  354. logger.debug("Failed to load skin from %s: %s", path, e)
  355. return None
  356. def _build_skin_config(data: dict[str, Any]) -> SkinConfig:
  357. """Build a SkinConfig from a raw dict (built-in or loaded from YAML)."""
  358. default = _BUILTIN_SKINS["default"]
  359. skin_name = str(data.get("name", "unknown"))
  360. def section(key: str) -> dict[str, Any]:
  361. value = data.get(key)
  362. if isinstance(value, dict):
  363. return value
  364. if value is not None:
  365. logger.warning("Skin '%s' has invalid '%s' section type (%s); ignoring section",
  366. skin_name, key, type(value).__name__)
  367. return {}
  368. def merged(key: str) -> dict[str, Any]:
  369. return {**default.get(key, {}), **section(key)}
  370. # Paired palettes are NOT merged over the default skin's blocks: an empty block means
  371. # "no hand-tuned variant for that polarity" and consumers (the TUI) fall back to `colors`
  372. # + automatic adaptation, which beats the default's gold light palette under a crimson skin.
  373. return SkinConfig(
  374. name=skin_name, description=data.get("description", ""), colors=merged("colors"),
  375. light_colors=section("light_colors"), dark_colors=section("dark_colors"),
  376. spinner=merged("spinner"), branding=merged("branding"),
  377. tool_prefix=data.get("tool_prefix", default.get("tool_prefix", "┊")),
  378. tool_emojis=section("tool_emojis"), banner_logo=data.get("banner_logo", ""),
  379. banner_hero=data.get("banner_hero", ""),
  380. custom_css=str(data.get("customCSS", "")).strip()[:32768])
  381. def list_skins() -> list[dict[str, str]]:
  382. """List all available skins (built-in + user-installed); user skins never shadow built-ins."""
  383. result = [{"name": name, "description": data.get("description", ""), "source": "builtin"}
  384. for name, data in _BUILTIN_SKINS.items()]
  385. skins_path = _skins_dir()
  386. for f in sorted(skins_path.glob("*.yaml")) if skins_path.is_dir() else ():
  387. data = _load_skin_from_yaml(f)
  388. if data and not any(s["name"] == data.get("name", f.stem) for s in result):
  389. result.append({"name": data.get("name", f.stem), "description": data.get("description", ""),
  390. "source": "user"})
  391. return result
  392. def load_skin(name: str) -> SkinConfig:
  393. """Load a skin by name: user skins first, then built-in, then default."""
  394. user_file = _skins_dir() / f"{name}.yaml"
  395. data = _load_skin_from_yaml(user_file) if user_file.is_file() else None
  396. if not data and name not in _BUILTIN_SKINS:
  397. logger.warning("Skin '%s' not found, using default", name)
  398. return _build_skin_config(data or _BUILTIN_SKINS.get(name) or _BUILTIN_SKINS["default"])
  399. def get_active_skin() -> SkinConfig:
  400. """Currently active skin config (cached)."""
  401. global _active_skin
  402. home_key = _routed_home_key()
  403. if home_key is not None:
  404. entry = _active_skin_by_home.get(home_key)
  405. if entry is None:
  406. # Cold routed profile: its own ``display.skin`` (nobody ran init_skin_from_config for it).
  407. init_skin_from_config(_profile_config())
  408. entry = _active_skin_by_home[home_key]
  409. return entry[1]
  410. if _active_skin is None:
  411. _active_skin = load_skin(_active_skin_name)
  412. return _active_skin
  413. def set_active_skin(name: str) -> SkinConfig:
  414. """Switch the active skin. Returns the new SkinConfig."""
  415. global _active_skin, _active_skin_name
  416. skin = load_skin(name)
  417. home_key = _routed_home_key()
  418. if home_key is not None:
  419. _active_skin_by_home[home_key] = (name, skin)
  420. return skin
  421. _active_skin_name = name
  422. _active_skin = skin
  423. return _active_skin
  424. def get_active_skin_name() -> str:
  425. home_key = _routed_home_key()
  426. if home_key is not None:
  427. entry = _active_skin_by_home.get(home_key)
  428. return entry[0] if entry else "default"
  429. return _active_skin_name
  430. def init_skin_from_config(config: dict) -> None:
  431. """Initialize the active skin from CLI config at startup."""
  432. display = config.get("display") or {}
  433. skin_name = display.get("skin", "default") if isinstance(display, dict) else "default"
  434. set_active_skin(skin_name.strip() if isinstance(skin_name, str) and skin_name.strip() else "default")
  435. def _active_branding(key: str, fallback: str) -> str:
  436. try:
  437. return get_active_skin().get_branding(key, fallback)
  438. except Exception:
  439. return fallback
  440. def get_active_prompt_symbol(fallback: str = "❯") -> str:
  441. """Interactive prompt symbol (skins store a bare token) plus a single trailing space."""
  442. cleaned = (_active_branding("prompt_symbol", fallback) or fallback).strip()
  443. return f"{cleaned or fallback.strip()} "
  444. def get_active_help_header(fallback: str = "(^_^)? Available Commands") -> str:
  445. return _active_branding("help_header", fallback)
  446. def get_active_goodbye(fallback: str = "Goodbye! ☤") -> str:
  447. return _active_branding("goodbye", fallback)
  448. # Palette resolution order for prompt_toolkit styles: (name, skin color key, fallback). A
  449. # fallback starting with "@" names an earlier entry (so a missing key inherits its remapped value).
  450. _STYLE_PALETTE = (
  451. ("prompt", "prompt", ""), ("input_rule", "input_rule", "#CD7F32"),
  452. ("title", "banner_title", "#FFD700"), ("text", "banner_text", "#FFF8DC"),
  453. ("dim", "banner_dim", "#555555"), ("label", "ui_label", "@title"), ("warn", "ui_warn", "#FF8C00"),
  454. ("error", "ui_error", "#FF6B6B"), ("status_bg", "status_bar_bg", "#1a1a2e"),
  455. ("status_text", "status_bar_text", "@text"), ("status_strong", "status_bar_strong", "@title"),
  456. ("status_dim", "status_bar_dim", "@dim"), ("ok", "ui_ok", "#8FBC8F"),
  457. ("status_good", "status_bar_good", "@ok"), ("status_warn", "status_bar_warn", "@warn"),
  458. ("accent", "banner_accent", "@warn"), ("status_bad", "status_bar_bad", "@accent"),
  459. ("status_critical", "status_bar_critical", "@error"), ("voice_bg", "voice_status_bg", "@status_bg"),
  460. ("menu_bg", "completion_menu_bg", "#1a1a2e"), ("menu_current_bg", "completion_menu_current_bg", "#333355"),
  461. ("menu_meta_bg", "completion_menu_meta_bg", "@menu_bg"),
  462. ("menu_meta_current_bg", "completion_menu_meta_current_bg", "@menu_current_bg"))
  463. # prompt_toolkit style class -> format template over the resolved palette names.
  464. _STYLE_TEMPLATES = {
  465. "input-area": "", # terminal default fg/bg — `prompt` styles the symbol, NOT typed text
  466. "placeholder": "{dim} italic", "prompt": "{prompt}", "prompt-working": "{dim} italic",
  467. "hint": "{dim} italic",
  468. "status-bar": "bg:{status_bg} {status_text}", "status-bar-strong": "bg:{status_bg} {status_strong} bold",
  469. "status-bar-session-title": "bg:{badge_bg} {badge_fg} bold",
  470. "status-bar-dim": "bg:{status_bg} {status_dim}", "status-bar-good": "bg:{status_bg} {status_good} bold",
  471. "status-bar-warn": "bg:{status_bg} {status_warn} bold", "status-bar-bad": "bg:{status_bg} {status_bad} bold",
  472. "status-bar-critical": "bg:{status_bg} {status_critical} bold",
  473. "subagent-dock": "bg:{status_bg} {status_text}",
  474. "subagent-dock.heading": "bg:{status_bg} {status_strong} bold",
  475. "subagent-dock.selected": "bg:{menu_current_bg} {text} bold",
  476. "input-rule": "{input_rule}", "image-badge": "{label} bold",
  477. "completion-menu": "bg:{menu_bg} {text}", "completion-menu.completion": "bg:{menu_bg} {text}",
  478. "completion-menu.completion.current": "bg:{menu_current_bg} {title}",
  479. "completion-menu.meta.completion": "bg:{menu_meta_bg} {dim}",
  480. "completion-menu.meta.completion.current": "bg:{menu_meta_current_bg} {label}",
  481. "clarify-border": "{input_rule}", "clarify-title": "{title} bold", "clarify-question": "{text} bold",
  482. "clarify-choice": "{dim}", "clarify-selected": "{title} bold", "clarify-active-other": "{title} italic",
  483. "clarify-countdown": "{input_rule}",
  484. "sudo-prompt": "{error} bold", "sudo-border": "{input_rule}", "sudo-title": "{error} bold",
  485. "sudo-text": "{text}",
  486. "approval-border": "{input_rule}", "approval-title": "{warn} bold", "approval-desc": "{text} bold",
  487. "approval-cmd": "{dim} italic", "approval-choice": "{dim}", "approval-selected": "{title} bold",
  488. "voice-status": "bg:{voice_bg} {label}", "voice-status-recording": "bg:{voice_bg} {error} bold"}
  489. def get_prompt_toolkit_style_overrides() -> dict[str, str]:
  490. """Return prompt_toolkit style overrides derived from the active skin."""
  491. try:
  492. skin = get_active_skin()
  493. except Exception:
  494. return {}
  495. # `prompt` is unset by default so typed text inherits the terminal's foreground (readable
  496. # on light and dark schemes); skins opt into a colored prompt symbol via `prompt` in YAML.
  497. # Every read goes through skin.get_color (cli.py wraps it for light-mode remapping).
  498. palette: dict[str, str] = {}
  499. for name, key, fallback in _STYLE_PALETTE:
  500. palette[name] = skin.get_color(key, palette[fallback[1:]] if fallback.startswith("@") else fallback)
  501. # This badge paints both sides; foreground-only light remapping destroys its contrast.
  502. palette["badge_bg"] = skin.colors.get(
  503. "status_bar_strong", skin.colors.get("banner_title", "#FFD700"))
  504. palette["badge_fg"] = skin.colors.get("status_bar_bg", "#1a1a2e")
  505. return {cls: tpl.format(**palette) for cls, tpl in _STYLE_TEMPLATES.items()}