扩展仪表板
Hermes Web 仪表板(hermes dashboard)在设计上支持重新换肤和扩展,无需 fork 代码库。提供三个层次的扩展:
- 主题 — YAML 文件,用于重绘仪表板的调色板、排版、布局和各组件外观。将文件放入
~/.hermes/dashboard-themes/,它就会出现在主题切换器中。 - UI 插件 — 包含
manifest.json和 JavaScript 打包文件的目录,可注册标签页、替换内置页面、通过页面级插槽增强页面,或将组件注入命名的 Shell 插槽。 - 后端插件 — 插件目录内的 Python 文件,暴露一个 FastAPI
router;路由挂载在/api/plugins/<name>/下,供插件的 UI 调用。
这三者在运行时均为即插即用:无需克隆仓库,无需 npm run build,无需修改仪表板源代码。本页是三者的权威参考文档。
如果你只是使用仪表板,请参见 Web 仪表板。如果你想重新换肤终端 CLI(而非 Web 仪表板),请参见皮肤与主题——CLI 皮肤系统与仪表板主题无关。
主题和插件相互独立,但可协同工作。主题可以单独使用(只需一个 YAML 文件)。插件也可以单独使用(只需一个标签页)。两者结合可让你构建带有自定义 HUD 的完整视觉改造——内置的 strike-freedom-cockpit 演示正是如此。参见主题 + 插件组合演示。
目录
主题
主题是存储在 ~/.hermes/dashboard-themes/ 中的 YAML 文件。文件名无关紧要(系统使用主题的 name: 字段),但惯例是 <name>.yaml。所有字段均为可选——缺失的键会回退到内置的 default 主题,因此一个主题可以只有一个颜色。
快速开始——你的第一个主题
mkdir -p ~/.hermes/dashboard-themes
# ~/.hermes/dashboard-themes/neon.yaml
name: neon
label: Neon
description: Pure magenta on black
palette:
background: "#000000"
midground: "#ff00ff"
刷新仪表板。点击标题中的调色板图标,选择 Neon。背景变为黑色,文字和强调色变为品红色,所有派生颜色(card、border、muted、ring 等)都通过 CSS 的 color-mix() 从这两个颜色自动计算。
这就是整个上手流程:一个文件,两个颜色。以下所有内容都是可选的精细调整。
调色板、排版、布局
这三个块是主题的核心。每个都是独立的——覆盖其中一个,其他的保持不变。
调色板(3层)
调色板是三层颜色加上暖光晕颜色和噪点颗粒倍增器的三元组。仪表板的设计系统通过 CSS color-mix() 从这个三元组派生出所有 shadcn 兼容令牌(card、popover、muted、border、primary、destructive、ring 等)。覆盖三个颜色会级联影响整个 UI。
| 键 | 描述 |
|---|---|
palette.background | 最深的画布颜色——通常接近黑色。驱动页面背景和卡片填充。 |
palette.midground | 主要文字和强调色。大部分 UI 外观读取此值(前景文字、按钮轮廓、焦点环)。 |
palette.foreground | 顶层高亮色。默认主题将其设置为 alpha 为 0 的白色(不可见);想要顶部亮色强调的主题可以提高其 alpha 值。 |
palette.warmGlow | rgba(...) 字符串,用作 <Backdrop /> 的晕光颜色。 |
palette.noiseOpacity | 0–1.2 范围内的颗粒叠加层倍增器。越低越柔和,越高越粗糙。 |
每一层接受 {hex: "#RRGGBB", alpha: 0.0–1.0} 或裸十六进制字符串(alpha 默认为 1.0)。
palette:
background:
hex: "#05091a"
alpha: 1.0
midground: "#d8f0ff" # bare hex, alpha = 1.0
foreground:
hex: "#ffffff"
alpha: 0 # invisible top layer
warmGlow: "rgba(255, 199, 55, 0.24)"
noiseOpacity: 0.7
排版
| 键 | 类型 | 描述 |
|---|---|---|
fontSans | string | 正文字体族栈(应用于 html、body)。 |
fontMono | string | 代码块、<code>、.font-mono 工具类的字体族栈。 |
fontDisplay | string | 可选的标题/展示字体族栈。回退到 fontSans。 |
fontUrl | string | 可选的外部样式表 URL。在主题切换时作为 <link rel="stylesheet"> 注入 <head>。同一 URL 不会被注入两次。支持 Google Fonts、Bunny Fonts、自托管 @font-face 样式表——任何可链接的来源。 |
baseSize | string | 根字体大小——控制 rem 缩放。如 "14px"、"16px"。 |
lineHeight | string | 默认行高。如 "1.5"、"1.65"。 |
letterSpacing | string | 默认字母间距。如 "0"、"0.01em"、"-0.01em"。 |
typography:
fontSans: '"Orbitron", "Eurostile", "Impact", sans-serif'
fontMono: '"Share Tech Mono", ui-monospace, monospace'
fontDisplay: '"Orbitron", "Eurostile", sans-serif'
fontUrl: "https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700&family=Share+Tech+Mono&display=swap"
baseSize: "14px"
lineHeight: "1.5"
letterSpacing: "0.04em"
布局
| 键 | 值 | 描述 |
|---|---|---|
radius | 任意 CSS 长度("0"、"0.25rem"、"0.5rem"、"1rem" 等) | 圆角令牌。映射到 --radius 并级联到 --radius-sm/md/lg/xl——所有圆角元素一起调整。 |
density | compact | comfortable | spacious | 间距倍增器,作为 --spacing-mul CSS 变量应用。compact = 0.85×,comfortable = 1.0×(默认),spacious = 1.2×。缩放 Tailwind 的基础间距,因此 padding、gap 和 space-between 工具类都按比例调整。 |
layout:
radius: "0"
density: compact
布局变体
layoutVariant 选择整体 Shell 布局。缺失时默认为 "standard"。
| 变体 | 行为 |
|---|---|
standard | 单列,最大宽度 1600px(默认)。 |
cockpit | 左侧边栏轨道(260px)+ 主内容区。通过 sidebar 插槽由插件填充——参见 Shell 插槽。没有插件时轨道显示占位符。 |
tiled | 取消最大宽度限制,页面可使用完整视口宽度。 |
layoutVariant: cockpit
当前变体以 document.documentElement.dataset.layoutVariant 暴露,因此 customCSS 中的原始 CSS 可以通过 :root[data-layout-variant="cockpit"] ... 定位它。
主题资源(图像作为 CSS 变量)
随主题一起提供图像 URL。每个命名插槽都成为一个 CSS 变量(--theme-asset-<name>),内置 Shell 和任何插件都可以读取。bg 插槽自动连接到背景层;其他插槽面向插件。
assets:
bg: "https://example.com/hero-bg.jpg" # auto-wired into <Backdrop />
hero: "/my-images/strike-freedom.png" # for plugin sidebars
crest: "/my-images/crest.svg" # for header-left plugins
logo: "/my-images/logo.png"
sidebar: "/my-images/rail.png"
header: "/my-images/header-art.png"
custom:
scanLines: "/my-images/scanlines.png" # → --theme-asset-custom-scanLines
值可以是:
- 裸 URL——自动包裹在
url(...)中。 - 预包裹的
url(...)、linear-gradient(...)、radial-gradient(...)表达式——原样使用。 "none"——明确不使用。
每个资源还会以 --theme-asset-<name>-raw(未包裹的 URL)的形式发布,以防插件需要将其传递给 <img src> 而非 background-image。
插件可通过纯 CSS 或 JS 读取这些变量:
// In a plugin slot
const hero = getComputedStyle(document.documentElement)
.getPropertyValue("--theme-asset-hero").trim();
组件外观覆盖
componentStyles 无需编写 CSS 选择器即可重新设计各个 Shell 组件。每个桶的条目都成为 CSS 变量(--component-<bucket>-<kebab-property>),Shell 的共享组件会读取这些变量。因此 card: 覆盖适用于所有 <Card>,header: 适用于应用栏,等等。
componentStyles:
card:
clipPath: "polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px)"
background: "linear-gradient(180deg, rgba(10, 22, 52, 0.85), rgba(5, 9, 26, 0.92))"
boxShadow: "inset 0 0 0 1px rgba(64, 200, 255, 0.28)"
header:
background: "linear-gradient(180deg, rgba(16, 32, 72, 0.95), rgba(5, 9, 26, 0.9))"
tab:
clipPath: "polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%)"
sidebar: {}
backdrop: {}
footer: {}
progress: {}
badge: {}
page: {}
支持的桶:card、header、footer、sidebar、tab、progress、badge、backdrop、page。
属性名使用驼峰命名(clipPath),发布为短横线命名(clip-path)。值是纯 CSS 字符串——CSS 能接受的任何内容(clip-path、border-image、background、box-shadow、animation 等)。
颜色覆盖
大多数主题不需要此功能——3 层调色板可以派生出所有 shadcn 令牌。当你想要派生过程无法产生的特定强调色时才使用 colorOverrides(例如柔和主题的更柔和破坏性红色,或品牌特定的成功绿色)。
colorOverrides:
primary: "#ffce3a"
primaryForeground: "#05091a"
accent: "#3fd3ff"
ring: "#3fd3ff"
destructive: "#ff3a5e"
border: "rgba(64, 200, 255, 0.28)"
支持的键:card、cardForeground、popover、popoverForeground、primary、primaryForeground、secondary、secondaryForeground、muted、mutedForeground、accent、accentForeground、destructive、destructiveForeground、success、warning、border、input、ring。
每个键 1:1 映射到 --color-<kebab> CSS 变量(例如 primaryForeground → --color-primary-foreground)。此处设置的任何键仅对活跃主题生效,覆盖调色板级联——切换到其他主题时,覆盖被清除。
原始 customCSS
对于 componentStyles 无法表达的选择器级外观——伪元素、动画、媒体查询、主题范围覆盖——将原始 CSS 放入 customCSS:
customCSS: |
/* Scanline overlay — only visible when cockpit variant is active. */
:root[data-layout-variant="cockpit"] body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 100;
background: repeating-linear-gradient(to bottom,
transparent 0px, transparent 2px,
rgba(64, 200, 255, 0.035) 3px, rgba(64, 200, 255, 0.035) 4px);
mix-blend-mode: screen;
}
CSS 在主题应用时作为单个带范围的 <style data-hermes-theme-css> 标签注入,在主题切换时清除。每个主题上限 32 KiB。
内置主题
每个内置主题都有自己的调色板、排版和布局——切换时产生的变化不仅仅是颜色。
| 主题 | 调色板 | 排版 | 布局 |
|---|---|---|---|
Hermes Teal(default) | 深青绿 + 奶油色 | 系统字体栈,15px | 0.5rem 圆角,comfortable |
Hermes Teal (Large)(default-large) | 与 default 相同 | 系统字体栈,18px,行高 1.65 | 0.5rem 圆角,spacious |
Midnight(midnight) | 深蓝紫 | Inter + JetBrains Mono,14px | 0.75rem 圆角,comfortable |
Ember(ember) | 暖深红 + 古铜色 | Spectral(衬线)+ IBM Plex Mono,15px | 0.25rem 圆角,comfortable |
Mono(mono) | 灰度 | IBM Plex Sans + IBM Plex Mono,13px | 0 圆角,compact |
Cyberpunk(cyberpunk) | 黑底霓虹绿 | Share Tech Mono 通用,14px | 0 圆角,compact |
Rosé(rose) | 粉色 + 象牙色 | Fraunces(衬线)+ DM Mono,16px | 1rem 圆角,spacious |
引用 Google Fonts 的主题(除 Hermes Teal 外所有主题)按需加载样式表——第一次切换到它们时,会向 <head> 注入一个 <link> 标签。
完整主题 YAML 参考
所有配置项汇总在一个文件中——复制后删除不需要的部分:
# ~/.hermes/dashboard-themes/ocean.yaml
name: ocean
label: Ocean Deep
description: Deep sea blues with coral accents
# 3-layer palette (accepts {hex, alpha} or bare hex)
palette:
background:
hex: "#0a1628"
alpha: 1.0
midground:
hex: "#a8d0ff"
alpha: 1.0
foreground:
hex: "#ffffff"
alpha: 0.0
warmGlow: "rgba(255, 107, 107, 0.35)"
noiseOpacity: 0.7
typography:
fontSans: "Poppins, system-ui, sans-serif"
fontMono: "Fira Code, ui-monospace, monospace"
fontDisplay: "Poppins, system-ui, sans-serif" # optional
fontUrl: "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&family=Fira+Code:wght@400;500&display=swap"
baseSize: "15px"
lineHeight: "1.6"
letterSpacing: "-0.003em"
layout:
radius: "0.75rem"
density: comfortable
layoutVariant: standard # standard | cockpit | tiled
assets:
bg: "https://example.com/ocean-bg.jpg"
hero: "/my-images/kraken.png"
crest: "/my-images/anchor.svg"
logo: "/my-images/logo.png"
custom:
pattern: "/my-images/waves.svg"
componentStyles:
card:
boxShadow: "inset 0 0 0 1px rgba(168, 208, 255, 0.18)"
header:
background: "linear-gradient(180deg, rgba(10, 22, 40, 0.95), rgba(5, 9, 26, 0.9))"
colorOverrides:
destructive: "#ff6b6b"
ring: "#ff6b6b"
customCSS: |
/* Any additional selector-level tweaks */
创建文件后刷新仪表板。通过标题栏的调色板图标实时切换主题。选择会持久保存到 config.yaml 的 dashboard.theme 中,重新加载时恢复。
插件
仪表板插件是包含 manifest.json、预构建 JS 打包文件以及可选的 CSS 文件和带有 FastAPI 路由的 Python 文件的目录。插件与其他 Hermes 插件一起放置在 ~/.hermes/plugins/<name>/ 中——仪表板扩展是该插件目录内的 dashboard/ 子文件夹,因此单个插件可以从单次安装中同时扩展 CLI/网关和仪表板。
插件不打包 React 或 UI 组件。它们使用暴露在 window.__HERMES_PLUGIN_SDK__ 上的 Plugin SDK。这使插件打包文件保持精简(通常只有几 KB),并避免版本冲突。
快速开始——你的第一个插件
创建目录结构:
mkdir -p ~/.hermes/plugins/my-plugin/dashboard/dist
编写清单:
// ~/.hermes/plugins/my-plugin/dashboard/manifest.json
{
"name": "my-plugin",
"label": "My Plugin",
"icon": "Sparkles",
"version": "1.0.0",
"tab": {
"path": "/my-plugin",
"position": "after:skills"
},
"entry": "dist/index.js"
}
编写 JS 打包文件(普通 IIFE——无需构建步骤):
// ~/.hermes/plugins/my-plugin/dashboard/dist/index.js
(function () {
"use strict";
const SDK = window.__HERMES_PLUGIN_SDK__;
const { React } = SDK;
const { Card, CardHeader, CardTitle, CardContent } = SDK.components;
function MyPage() {
return React.createElement(Card, null,
React.createElement(CardHeader, null,
React.createElement(CardTitle, null, "My Plugin"),
),
React.createElement(CardContent, null,
React.createElement("p", { className: "text-sm text-muted-foreground" },
"Hello from my custom dashboard tab.",
),
),
);
}
window.__HERMES_PLUGINS__.register("my-plugin", MyPage);
})();
刷新仪表板——你的标签页出现在导航栏中,位于 Skills 之后。
如果你更喜欢 JSX,可使用任何打包工具(esbuild、Vite、rollup),将 React 设为外部依赖并输出 IIFE。唯一的硬性要求是最终文件是可通过 <script> 加载的单个 JS 文件。React 永远不会被打包进去;它来自 SDK.React。
目录结构
~/.hermes/plugins/my-plugin/
├── plugin.yaml # optional — existing CLI/gateway plugin manifest
├── __init__.py # optional — existing CLI/gateway hooks
└── dashboard/ # dashboard extension
├── manifest.json # required — tab config, icon, entry point
├── dist/
│ ├── index.js # required — pre-built JS bundle (IIFE)
│ └── style.css # optional — custom CSS
└── plugin_api.py # optional — backend API routes (FastAPI)
单个插件目录可承载三个正交扩展:
plugin.yaml+__init__.py— CLI/网关插件(参见插件页面)。dashboard/manifest.json+dashboard/dist/index.js— 仪表板 UI 插件。dashboard/plugin_api.py— 仪表板后端路由。
三者均非必需;仅包含你需要的层。
清单参考
{
"name": "my-plugin",
"label": "My Plugin",
"description": "What this plugin does",
"icon": "Sparkles",
"version": "1.0.0",
"tab": {
"path": "/my-plugin",
"position": "after:skills",
"override": "/",
"hidden": false
},
"slots": ["sidebar", "header-left"],
"entry": "dist/index.js",
"css": "dist/style.css",
"api": "plugin_api.py"
}
| 字段 | 必填 | 描述 |
|---|---|---|
name | 是 | 唯一插件标识符。小写,允许连字符。用于 URL 和注册。 |
label | 是 | 显示在导航标签页中的名称。 |
description | 否 | 简短描述(显示在仪表板管理界面中)。 |
icon | 否 | Lucide 图标名称。默认为 Puzzle。未知名称回退到 Puzzle。 |
version | 否 | 语义版本字符串。默认为 0.0.0。 |
tab.path | 是 | 标签页的 URL 路径(如 /my-plugin)。 |
tab.position | 否 | 标签页的插入位置。"end"(默认)、"after:<path>" 或 "before:<path>"——冒号后的值是目标标签页的路径段(无前导斜杠)。示例:"after:skills"、"before:config"。 |
tab.override | 否 | 设置为内置路由路径("/"、"/sessions"、"/config" 等)可替换该页面而非添加新标签页。参见替换内置页面。 |
tab.hidden | 否 | 为 true 时,注册组件和任何插槽,但不向导航添加标签页。用于纯插槽插件。参见纯插槽插件。 |
slots | 否 | 此插件填充的命名 Shell 插槽。仅作文档说明——实际注册通过 JS 打包文件的 registerSlot() 完成。在此列出插槽使发现界面更具信息性。 |
entry | 是 | 相对于 dashboard/ 的 JS 打包文件路径。默认为 dist/index.js。 |
css | 否 | 作为 <link> 标签注入的 CSS 文件路径。 |
api | 否 | 带有 FastAPI 路由的 Python 文件路径。挂载在 /api/plugins/<name>/。 |
可用图标
插件使用 Lucide 图标名称。仪表板按名称映射这些图标——未知名称静默回退到 Puzzle。
当前已映射:Activity、BarChart3、Clock、Code、Database、Eye、FileText、Globe、Heart、KeyRound、MessageSquare、Package、Puzzle、Settings、Shield、Sparkles、Star、Terminal、Wrench、Zap。
需要不同的图标?向 web/src/App.tsx 的 ICON_MAP 提交 PR——纯添加性变更。
Plugin SDK
插件所需的一切都在 window.__HERMES_PLUGIN_SDK__ 上。插件不应直接导入 React。
const SDK = window.__HERMES_PLUGIN_SDK__;
// React + hooks
SDK.React // the React instance
SDK.hooks.useState
SDK.hooks.useEffect
SDK.hooks.useCallback
SDK.hooks.useMemo
SDK.hooks.useRef
SDK.hooks.useContext
SDK.hooks.createContext
// UI components (shadcn/ui primitives)
SDK.components.Card
SDK.components.CardHeader
SDK.components.CardTitle
SDK.components.CardContent
SDK.components.Badge
SDK.components.Button
SDK.components.Input
SDK.components.Label
SDK.components.Select
SDK.components.SelectOption
SDK.components.Separator
SDK.components.Tabs
SDK.components.TabsList
SDK.components.TabsTrigger
SDK.components.PluginSlot // render a named slot (useful for nested plugin UIs)
// Hermes API client + raw fetcher
SDK.api // typed client — getStatus, getSessions, getConfig, ...
SDK.fetchJSON // raw fetch for custom endpoints (plugin-registered routes)
// Utilities
SDK.utils.cn // Tailwind class merger (clsx + twMerge)
SDK.utils.timeAgo // "5m ago" from unix timestamp
SDK.utils.isoTimeAgo // "5m ago" from ISO string
// Hooks
SDK.useI18n // i18n hook for multi-language plugins
调用插件的后端
SDK.fetchJSON("/api/plugins/my-plugin/data")
.then((data) => console.log(data))
.catch((err) => console.error("API call failed:", err));
fetchJSON 会注入会话认证令牌,将错误作为抛出的异常暴露,并自动解析 JSON。
调用内置 Hermes 端点
// Agent status
SDK.api.getStatus().then((s) => console.log("Version:", s.version));
// Recent sessions
SDK.api.getSessions(10).then((resp) => console.log(resp.sessions.length));
完整列表参见 Web 仪表板 → REST API。
Shell 插槽
插槽让插件将组件注入应用 Shell 的命名位置——驾驶舱侧边栏、标题、页脚、覆盖层——无需占用整个标签页。多个插件可以填充同一个插槽;它们按注册顺序堆叠渲染。
在插件打包文件内注册:
window.__HERMES_PLUGINS__.registerSlot("my-plugin", "sidebar", MySidebar);
window.__HERMES_PLUGINS__.registerSlot("my-plugin", "header-left", MyCrest);
插槽目录
Shell 级插槽(在应用外观的任何位置渲染):
| 插槽 | 位置 |
|---|---|
backdrop | 在 <Backdrop /> 层叠中,噪点层之上。 |
header-left | 顶栏中 Hermes 品牌之前。 |
header-right | 顶栏中主题/语言切换器之前。 |
header-banner | 导航栏下方的全宽横幅条。 |
sidebar | 驾驶舱侧边栏轨道——仅在 layoutVariant === "cockpit" 时渲染。 |
pre-main | 路由出口上方(在 <main> 内)。 |
post-main | 路由出口下方(在 <main> 内)。 |
footer-left | 页脚单元格内容(替换默认值)。 |
footer-right | 页脚单元格内容(替换默认值)。 |
overlay | 所有内容之上的固定定位层。适用于 customCSS 无法单独实现的外观(扫描线、晕光)。 |
页面级插槽(仅在命名的内置页面上渲染——使用这些插槽可向现有页面注入小部件、卡片或工具栏,而无需覆盖整个路由):
| 插槽 | 渲染位置 |
|---|---|
sessions:top / sessions:bottom | /sessions 页面的顶部/底部。 |
analytics:top / analytics:bottom | /analytics 页面的顶部/底部。 |
logs:top / logs:bottom | /logs 的顶部(过滤工具栏上方)/底部(日志查看器下方)。 |
cron:top / cron:bottom | /cron 页面的顶部/底部。 |
skills:top / skills:bottom | /skills 页面的顶部/底部。 |
config:top / config:bottom | /config 页面的顶部/底部。 |
env:top / env:bottom | /env(Keys)页面的顶部/底部。 |
docs:top / docs:bottom | /docs 的顶部(iframe 上方)/底部。 |
chat:top / chat:bottom | /chat 的顶部/底部(仅在启用嵌入式聊天时激活)。 |
示例——向 Sessions 页面顶部添加横幅卡片:
function PinnedSessionsBanner() {
return React.createElement(Card, null,
React.createElement(CardContent, { className: "py-2 text-xs" },
"Pinned note injected by my-plugin"),
);
}
window.__HERMES_PLUGINS__.registerSlot("my-plugin", "sessions:top", PinnedSessionsBanner);
将页面级插槽与 tab.hidden: true 结合使用,适用于仅增强现有页面而不需要自己的侧边栏标签页的插件。
Shell 只为以上列出的插槽渲染 <PluginSlot name="..." />。注册表接受其他名称用于嵌套插件 UI——插件可以通过 SDK.components.PluginSlot 暴露自己的插槽。
重新注册与 HMR
如果相同的 (plugin, slot) 对注册了两次,后一次调用会替换前一次——这与 React HMR 对插件重挂载行为的期望一致。
替换内置页面(tab.override)
将 tab.override 设置为内置路由路径会使插件组件替换该页面,而非添加新标签页。当主题想要自定义首页(/)但保留仪表板其余部分时非常有用。
{
"name": "my-home",
"label": "Home",
"tab": {
"path": "/my-home",
"override": "/",
"position": "end"
},
"entry": "dist/index.js"
}
设置 override 后:
- 原来在
/的页面组件从路由器中移除。 - 你的插件在
/渲染。 - 不为
tab.path添加导航标签页(替换才是重点)。
每个路径只能被一个插件覆盖。如果两个插件声明相同的覆盖,第一个获胜,第二个被忽略并在开发模式下给出警告。
如果你只需要向现有页面添加卡片或工具栏而不完全接管它,请改用页面级插槽。
增强内置页面(页面级插槽)
通过 tab.override 完全替换是重量级操作——你的插件现在拥有整个页面,包括我们未来对它的任何更新。大多数时候你只是想向现有页面添加横幅、卡片或工具栏。这正是页面级插槽的用途。
每个内置页面在其内容区域的顶部和底部暴露 <page>:top 和 <page>:bottom 插槽。你的插件通过调用 registerSlot() 填充其中一个——内置页面保持正常工作,你的组件在其旁边渲染。
可用插槽:sessions:*、analytics:*、logs:*、cron:*、skills:*、config:*、env:*、docs:*、chat:*(每个都有 :top 和 :bottom)。完整目录参见 Shell 插槽 → 插槽目录。
最简示例——在 Sessions 页面顶部固定横幅:
// ~/.hermes/plugins/session-notes/dashboard/manifest.json
{
"name": "session-notes",
"label": "Session Notes",
"tab": { "path": "/session-notes", "hidden": true },
"slots": ["sessions:top"],
"entry": "dist/index.js"
}
// ~/.hermes/plugins/session-notes/dashboard/dist/index.js
(function () {
const SDK = window.__HERMES_PLUGIN_SDK__;
const { React } = SDK;
const { Card, CardContent } = SDK.components;
function Banner() {
return React.createElement(Card, null,
React.createElement(CardContent, { className: "py-2 text-xs" },
"Remember to label important sessions before archiving."),
);
}
// Placeholder for the hidden tab.
window.__HERMES_PLUGINS__.register("session-notes", function () { return null; });
// The real work.
window.__HERMES_PLUGINS__.registerSlot("session-notes", "sessions:top", Banner);
})();
要点:
tab.hidden: true使插件不出现在侧边栏中——它没有独立页面。slots清单字段仅作文档说明。实际绑定通过 JS 打包文件的registerSlot()完成。- 多个插件可以声明相同的页面级插槽。它们按注册顺序堆叠渲染。
- 当没有插件注册时零占用:内置页面与之前完全相同地渲染。
内置的 example-dashboard 插件(hermes-example-plugins 中的)提供了一个向 sessions:top 注入横幅的实时演示——安装它可以端到端地看到该模式。
纯插槽插件(tab.hidden)
当 tab.hidden: true 时,插件注册其组件(用于直接 URL 访问)和任何插槽,但不向导航添加标签页。用于仅存在于插槽注入的插件——标题徽标、侧边栏 HUD、覆盖层。
{
"name": "header-crest",
"label": "Header Crest",
"tab": {
"path": "/header-crest",
"position": "end",
"hidden": true
},
"slots": ["header-left"],
"entry": "dist/index.js"
}
打包文件仍然调用带占位符组件的 register()(好习惯,以防有人直接访问 URL),然后调用 registerSlot() 完成实际工作。
后端 API 路由
插件可以通过在清单中设置 api 来注册 FastAPI 路由。创建文件并导出 router:
# ~/.hermes/plugins/my-plugin/dashboard/plugin_api.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/data")
async def get_data():
return {"items": ["one", "two", "three"]}
@router.post("/action")
async def do_action(body: dict):
return {"ok": True, "received": body}
路由挂载在 /api/plugins/<name>/ 下,因此以上变为:
GET /api/plugins/my-plugin/dataPOST /api/plugins/my-plugin/action
插件 API 路由绕过会话令牌认证,因为仪表板服务器默认绑定到 localhost。如果你运行不受信任的插件,不要用 --host 0.0.0.0 在公共接口上暴露仪表板——它们的路由也会变得可访问。
访问 Hermes 内部机制
后端路由在仪表板进程内运行,因此可以直接从 hermes-agent 代码库导入:
from fastapi import APIRouter
from hermes_state import SessionDB
from hermes_cli.config import load_config
router = APIRouter()
@router.get("/session-count")
async def session_count():
db = SessionDB()
try:
count = len(db.list_sessions(limit=9999))
return {"count": count}
finally:
db.close()
@router.get("/config-snapshot")
async def config_snapshot():
cfg = load_config()
return {"model": cfg.get("model", {})}
每个插件的自定义 CSS
如果你的插件需要 Tailwind 类和内联 style= 以外的样式,添加 CSS 文件并在清单中引用:
{
"css": "dist/style.css"
}
文件在插件加载时作为 <link> 标签注入。使用特定的类名避免与仪表板样式冲突,并引用仪表板的 CSS 变量以保持主题感知:
/* dist/style.css */
.my-plugin-chart {
border: 1px solid var(--color-border);
background: var(--color-card);
color: var(--color-card-foreground);
padding: 1rem;
}
.my-plugin-chart:hover {
border-color: var(--color-ring);
}
仪表板将每个 shadcn 令牌暴露为 --color-* 加上主题额外项(--theme-asset-*、--component-<bucket>-*、--radius、--spacing-mul)。引用这些,你的插件就会随活跃主题自动改变外观。
插件发现与重载
仪表板扫描三个目录查找 dashboard/manifest.json:
| 优先级 | 目录 | 来源标签 |
|---|---|---|
| 1(冲突时获胜) | ~/.hermes/plugins/<name>/dashboard/ | user |
| 2 | <repo>/plugins/memory/<name>/dashboard/ | bundled |
| 2 | <repo>/plugins/<name>/dashboard/ | bundled |
| 3 | ./.hermes/plugins/<name>/dashboard/ | project——仅在设置了 HERMES_ENABLE_PROJECT_PLUGINS 时 |
发现结果按仪表板进程缓存。添加新插件后,可以:
# Force a rescan without restart
curl http://127.0.0.1:9119/api/dashboard/plugins/rescan
……或重启 hermes dashboard。
插件加载生命周期
- 仪表板加载。
main.tsx在window.__HERMES_PLUGIN_SDK__上暴露 SDK,在window.__HERMES_PLUGINS__上暴露注册表。 App.tsx调用usePlugins()→ 获取GET /api/dashboard/plugins。- 对于每个清单:注入 CSS
<link>(如有声明),然后<script>标签加载 JS 打包文件。 - 插件的 IIFE 运行并调用
window.__HERMES_PLUGINS__.register(name, Component)——以及可选的.registerSlot(name, slot, Component)用于每个插槽。 - 仪表板将注册的组件与清单进行匹配,向导航添加标签页(除非
hidden),并将组件挂载为路由。
插件在脚本加载后最多有 2 秒 调用 register()。之后仪表板停止等待并完成初始渲染。如果插件稍后注册,它仍会出现——导航是响应式的。
如果插件脚本加载失败(404、语法错误、IIFE 执行期间的异常),仪表板向浏览器控制台记录警告并继续运行。
主题 + 插件组合演示
strike-freedom-cockpit 插件(配套仓库 hermes-example-plugins)是一个完整改造演示。它将主题 YAML 与纯插槽插件配对,无需 fork 仪表板就能生成驾驶舱风格的 HUD。
演示内容:
- 完整主题,使用调色板、排版、
fontUrl、layoutVariant: cockpit、assets、componentStyles(切角卡片、渐变背景)、colorOverrides和customCSS(扫描线叠加层)。 - 纯插槽插件(
tab.hidden: true),注册到三个插槽:sidebar——带有由SDK.api.getStatus()驱动的实时遥测条的 MS-STATUS 面板。header-left——从活跃主题读取--theme-asset-crest的派系徽标。footer-right——替换默认组织行的自定义标语。
- 插件通过 CSS 变量读取主题提供的图像,因此切换主题会更改英雄图/徽标,无需修改插件代码。
安装:
git clone https://github.com/NousResearch/hermes-example-plugins.git
# Theme
cp hermes-example-plugins/strike-freedom-cockpit/theme/strike-freedom.yaml \
~/.hermes/dashboard-themes/
# Plugin
cp -r hermes-example-plugins/strike-freedom-cockpit ~/.hermes/plugins/
打开仪表板,从主题切换器选择 Strike Freedom。驾驶舱侧边栏出现,标题中显示徽标,标语替换了页脚。切换回 Hermes Teal,插件保持安装状态但不可见(sidebar 插槽仅在 cockpit 布局变体下渲染)。
阅读插件源代码(配套仓库中的 strike-freedom-cockpit/dashboard/dist/index.js),了解它如何读取 CSS 变量、防范不支持插槽的旧版仪表板,以及如何从单个打包文件注册三个插槽。
API 参考
主题端点
| 端点 | 方法 | 描述 |
|---|---|---|
/api/dashboard/themes | GET | 列出可用主题 + 活跃名称。内置主题返回 {name, label, description};用户主题还包含带有完整规范化主题对象的 definition 字段。 |
/api/dashboard/theme | PUT | 设置活跃主题。请求体:{"name": "midnight"}。持久保存到 config.yaml 的 dashboard.theme 下。 |
插件端点
| 端点 | 方法 | 描述 |
|---|---|---|
/api/dashboard/plugins | GET | 列出已发现的插件(含清单,减去内部字段)。 |
/api/dashboard/plugins/rescan | GET | 强制重新扫描插件目录,无需重启。 |
/dashboard-plugins/<name>/<path> | GET | 从插件的 dashboard/ 目录提供静态资源。路径遍历被阻止。 |
/api/plugins/<name>/* | * | 插件注册的后端路由。 |
window 上的 SDK
| 全局变量 | 类型 | 提供者 |
|---|---|---|
window.__HERMES_PLUGIN_SDK__ | object | registry.ts——React、hooks、UI 组件、API 客户端、工具函数。 |
window.__HERMES_PLUGINS__.register(name, Component) | function | 注册插件的主组件。 |
window.__HERMES_PLUGINS__.registerSlot(name, slot, Component) | function | 注册到命名的 Shell 插槽。 |
故障排查
我的主题没有出现在选择器中。
检查文件是否在 ~/.hermes/dashboard-themes/ 中并以 .yaml 或 .yml 结尾。刷新页面。运行 curl http://127.0.0.1:9119/api/dashboard/themes——你的主题应该在响应中。如果 YAML 有解析错误,仪表板会在 ~/.hermes/logs/ 下的 errors.log 中记录日志。
我的插件标签页没有显示。
- 检查清单是否在
~/.hermes/plugins/<name>/dashboard/manifest.json(注意dashboard/子目录)。 curl http://127.0.0.1:9119/api/dashboard/plugins/rescan强制重新发现。- 打开浏览器开发工具 → Network——确认
manifest.json、index.js和任何 CSS 都加载成功,无 404。 - 打开浏览器开发工具 → Console——查找 IIFE 执行期间的错误或
window.__HERMES_PLUGINS__ is undefined(表明 SDK 未初始化,通常是更早的 React 渲染崩溃)。 - 验证你的打包文件以与
manifest.json:name相同的名称调用window.__HERMES_PLUGINS__.register(...)。
插槽注册的组件没有渲染。
sidebar 插槽仅在活跃主题具有 layoutVariant: cockpit 时渲染。其他插槽始终渲染。如果你注册的插槽没有命中,在 registerSlot 内添加 console.log 确认插件打包文件是否正常运行。
插件后端路由返回 404。
- 确认清单有
"api": "plugin_api.py"指向dashboard/内的现有文件。 - 重启
hermes dashboard——插件 API 路由在启动时挂载一次,不在 rescan 时挂载。 - 检查
plugin_api.py是否导出模块级router = APIRouter()。其他导出名称不会被识别。 - 查看
~/.hermes/logs/errors.log中的Failed to load plugin <name> API routes——导入错误会记录在那里。
主题切换时我的颜色覆盖消失了。
colorOverrides 的作用域是活跃主题,在主题切换时清除——这是设计如此。如果你想要持久保存的覆盖,将它们放在主题的 YAML 中,而非实时切换器中。
主题 customCSS 被截断了。
customCSS 块每个主题上限 32 KiB。将大型样式表拆分到多个主题中,或切换到通过其 css 字段注入完整样式表的插件(无大小限制)。
我想在 PyPI 上发布插件。
仪表板插件通过目录布局安装,而非 pip 入口点。目前最简洁的发布路径是用户克隆到 ~/.hermes/plugins/ 的 git 仓库。目前没有为仪表板插件设置基于 pip 的安装程序。