Hermes 自定义功能开发
hermes-upgrade-safe-customizations
在升级安全的用户空间中构建 Hermes 自定义功能,而非修补 Hermes 核心文件。
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 5
- Forks
- 4
01 前言 Front Matter
- name
- hermes-upgrade-safe-customizations
- author
- Hermes Agent
- license
- MIT
- version
- 1.0.0
- description
- Build Hermes custom features in upgrade-safe user space instead of patching core Hermes files.
03 SKILL.md 正文
Hermes upgrade-safe customizations
Use this whenever a user wants Hermes behavior changed but does not want the change to be lost on Hermes upgrade.
Core rule
Do not modify Hermes core repo files for user-specific features unless the user explicitly wants an upstream code change.
Prefer extension points under ~/.hermes/:
~/.hermes/hooks/for gateway/runtime patching at startup~/.hermes/plugins/for reusable plugin modules withplugin.yaml~/.hermes/skills/for prompt-level workflows- config in
~/.hermes/config.yaml
Decision framework
- Prompt behavior only?
- Use a skill.
- Tooling or reusable Python integration?
- Use a plugin in
~/.hermes/plugins/.
- Use a plugin in
- Gateway event interception / startup monkey-patch / message routing?
- Use a hook in
~/.hermes/hooks/.
- Use a hook in
- Broad product improvement intended to survive as upstream code?
- Only then consider changing Hermes core.
Hook pattern for upgrade-safe gateway extensions
Use hooks when you need to alter gateway behavior without editing gateway/run.py.
Layout
~/.hermes/hooks/<hook-name>/
HOOK.yaml
handler.py
README.md
Minimal HOOK.yaml
name: my-hook
description: My upgrade-safe Hermes gateway extension
events:
- gateway:startup
Handler pattern
- Load at
gateway:startup - Import
gateway.run - Save original method(s)
- Monkey-patch
GatewayRunnermethods - Keep patch idempotent with a module-global
_PATCHEDflag
Skeleton:
_PATCHED = False
_ORIGINAL_HANDLE_MESSAGE = None
async def _patched_handle_message(self, event):
# custom intercept here
return await _ORIGINAL_HANDLE_MESSAGE(self, event)
def _apply_patch():
global _PATCHED, _ORIGINAL_HANDLE_MESSAGE
if _PATCHED:
return
import gateway.run as gateway_run
_ORIGINAL_HANDLE_MESSAGE = gateway_run.GatewayRunner._handle_message
gateway_run.GatewayRunner._handle_message = _patched_handle_message
_PATCHED = True
async def handle(event_type, context):
if event_type == "gateway:startup":
_apply_patch()
Pi passthrough example pattern
For thread-local interactive Pi bridging:
- patch
GatewayRunner._handle_message - intercept
/pi ...commands before normal agent handling - maintain module-global bridge state keyed by gateway session key
- spawn Pi with
tools.process_registry.process_registry.spawn(..., use_pty=True) - relay output by polling process output in an asyncio task
- intercept
/STOPand send"\x1b"viawrite_stdin - forward all other thread messages with
submit_stdin
Verification checklist
- Confirm no core Hermes files were modified.
git diff -- gateway/run.py gateway/platforms/base.py hermes_cli/commands.py - Syntax-check the external hook/plugin.
python -m py_compile ~/.hermes/hooks/<hook-name>/handler.py - Restart gateway so the hook loads.
- Run a focused behavioral test against the external extension.
- Add a
README.mdin the hook/plugin directory describing behavior and location.
Pitfalls
- Hooks load on gateway startup, so changes usually require a gateway restart.
- Keep monkey-patches idempotent; gateway startup paths may run more than once in tests/restarts.
- Store long-lived custom state in the external module, not Hermes core objects.
- If importing a hook manually in tests, insert the module into
sys.modulesbefore execution when needed. - Prompt-level skills cannot disable Hermes interpretation of incoming messages; transport-layer passthrough needs a hook/plugin.
Preferred response to user requests
If the user asks for a custom Hermes feature and cares about persistence across upgrades, state the plan explicitly:
- implement externally under
~/.hermes/... - avoid modifying Hermes core
- document restart/activation requirements
04 同仓库更多 Skills
网页抓取受阻恢复
blocked-page-recovery
当抓取失败时使用:403/429 状态码、付费墙(paywall)、WAF、机器人验证墙(bot wall)。
软件实施计划编写
writing-plans
在创建或更新可执行的软件计划时使用。除非用户明确要求将计划注册到 Doct,否则请将计划保留为本地文件。
测试驱动开发
test-driven-development
TDD:强制执行「红-绿-重构」(RED-GREEN-REFACTOR)循环,先写测试再写代码。
系统化根因调试
systematic-debugging
四阶段根因调试:先理解缺陷,再着手修复。
技术预研验证
spike
在正式构建前,通过一次性(可丢弃的)实验来验证某个想法。
代码变更并行清理精简
simplify-code
并行使用 3 个智能体(agent)对近期代码变更进行清理精简。