shali10/hermes-patches
About
🛠️ Hermes Agent 体验增强补丁与扩展插件 | Non-intrusive patches for Hermes Agent (Token metrics, CJK native tables, menu localization, DB guards)
AI & Machine LearningMeasured star growth
- in 24h
- -1
- in 7 days
- -1
- in 15 days
- -2
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README_EN.md
Original🛠️ Hermes Patches
Non-intrusive Turnkey Production Enhancement Patches for Hermes Agent
Supercharge your Hermes Agent deployment with exact token telemetry & cache hit metering, Telegram native Markdown pipe table bypass, localized bot command menu, SQLite production concurrency auto-healing, gateway streaming control & rate-limit shield, deep thinking cleaner, 4096 safe message chunking, terminal working directory auto-recovery, zero-config initialization, and seamless auto-restart.
English | 简体中文 | 📝 Changelog | 🏷️ Releases
🧭 Quick Navigation: ✨ Features · 🔍 Showcase · 🚀 Installation · 📦 Patches · ❓ FAQ · 📝 Changelog · ↩️ Uninstall
✨ Features & Comparison
| Module | Upstream Vanilla | With hermes-patches (v1.5.0) ✨ |
|---|---|---|
| 📊 Token Telemetry | Minimal model & percentage only (gpt-4o · 7%) |
Full telemetry: Prompt total, cache hits & hit rate (%), output tokens, context %, and execution latency with formatted integers. |
| 📑 Telegram Pipe Tables | Markdown tables often degraded to plain unordered lists | 100% bypass for native pipe tables, rendering modern rich text tables on desktop & mobile Telegram clients. |
| 🇨🇳 Telegram Menu i18n | English default descriptions only | Localized command descriptions for clearer command quick-actions. |
| 🛡️ SQLite Durability | Prone to database is locked or FOREIGN KEY crashes during high concurrency |
Automatic busy_timeout=5000 contention queue + foreign key session auto-healing. |
| ⚡ Approval Optimization | Low-severity static analysis warnings interrupt execution | Automatic pass-through for non-blocking LOW/INFO scanner warnings. |
| 🚫 Streaming Control & 429 Shield | Rapid editMessageText causes UI flickering and triggers Telegram 429 Flood Limits |
Honors global display.streaming: false, delivering complete clean responses in one final delivery without rate-limits. |
| 🧠 Deep Thinking Cleaner | Reasoning models spam large <think> blocks in CLI and leak partial drafts |
Full suppression of thinking tags (<think>, <thought>, <antml:thought> & unclosed blocks), leaving only clean responses. |
| ✂️ 4096 Smart Message Split | Truncating 4096+ chars breaks code fences or causes can't parse entities |
Splits at natural paragraph boundaries (\n\n), automatically closing and reopening code fences & tables. |
| 📁 Terminal CWD Recovery | Explicit deleted workdir leads to terminal crash (exit 126) |
Automatically resolves and falls back to safe local ancestor directory. |
| 🧱 State DB Anti-Destruction Guard | Autonomous cleanup can accidentally delete state.db, wiping all session history |
Unconditional action-level hardline floor: Blocks rm / truncate / > / find-delete targeting live state.db, while safely permitting .bak cleanups and read operations. |
| ⚙️ Zero-Config Out-of-the-Box | Requires manual config tweaks to show footers | Automatically initializes ~/.hermes/config.yaml with all telemetry metrics pre-configured. |
| 🔄 Seamless Auto-Restart | Users have to manually find processes and restart | Automatically reloads and restarts hermes-gateway service, effective immediately in 1 step. |
| 🚀 Upgrade-Immune Guard | Hermes source updates overwrite local patches | systemd ExecStartPre supervision hook, automatically re-applying patches on restart. |
🔍 Showcase
1. 📊 Full Runtime Footer Telemetry
Vanilla Default:
LongCat-2.0 · 7%With hermes-patches:
🤖 gemini-3.7-flash-high | 🧠 Prompt总量: 45,210 | 💾 缓存命中: 40,000 (88%) | 📤 输出: 280 | 🎯 上下文: 4% | ⏱️ 耗时: 3.2s
2. 📑 Native Telegram Markdown Pipe Table Rendering
💡 Recommended Ecosystem Synergy: Pair with shali10/tg-rich-render for adaptive CJK/Emoji width compensation, mobile-friendly card layouts, and zero-jagged table borders!
3. 🚫 Quiet Streaming & Telegram 429 Shield
Setting display.streaming: false in ~/.hermes/config.yaml cleanly disables interim edits:
- Zero Message Flickers: Waits for completion and delivers full, high-fidelity Markdown formatting.
- No Telegram 429 Errors: Eliminates the risk of Telegram
Flood control exceeded. Retry in N seconds.
4. 🧠 Deep Thinking & Reasoning Suppression
For DeepSeek-R1, QwQ, Claude 3.7 Thinking, or Gemini Thinking models:
- CLI Mode: Mutes the verbose thinking box popup by default.
- Messaging Mode: Strips
<think>,<thought>,<thinking>,<reflection>,<antml:thought>, and unclosed partial reasoning blocks.
🏗️ Architecture & How It Works
hermes-patches uses safe code injection validated by Python's bytecode compiler coupled with systemd startup supervision:
┌──────────────────────────────┐
│ Hermes Gateway Service │
└──────────────┬───────────────┘
│
(systemd ExecStartPre)
▼
┌──────────────────────────────┐
│ hermes-patches Engine │
│ • Inspects source files │
│ • py_compile syntax test │
│ • Auto-updates config.yaml │
│ • Cleans stale __pycache__ │
│ • Idempotent atomic update │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Hermes Agent Ready │
│ [Tokens | Tables | DB Heal │
│ Quiet Stream | Clean Think │
│ Smart Split | Zero Config] │
└──────────────────────────────┘
🛡️ Safety Mechanisms
- 🔬 Atomic Bytecode Pre-compilation: Modifications undergo strict
py_compile.compile(..., doraise=True)checks in isolated temporary files before atomicos.replace. - 🔄 Instant Rollback: Backups (
.bak) are preserved automatically. Use--uninstallto restore stock upstream code. - ♻️ 100% Idempotent: Safe to run repeatedly; existing signatures are skipped cleanly.
- 🧹 Bytecode Invalidation: Purges stale
__pycache__and.pycfiles on completion.
🚀 Installation
Option A: Standard Python Package (Recommended / Global CLI)
Now available as a standard Python package with global console executable:
# 1. Install via pip
pip install hermes-patches
# 2. Open interactive management menu anywhere
hermes-patches
# 3. Or apply all patches non-interactively with auto-config & restart
hermes-patches --all --auto-config --restart
💡 Run instantly without installing (pipx):
pipx run hermes-patches --help
Option B: Turnkey One-Liner Script
Run directly on the server hosting Hermes Agent:
curl -fsSL https://raw.githubusercontent.com/shali10/hermes-patches/main/install.sh | bash
✨ What happens automatically:
- 🔍 Adaptive Probing: Detects active Hermes install path across running processes, systemd, shebangs & virtualenvs.
- 💉 Injects All Patches: Applies and verifies all 9 enhancement modules.
- ⚙️ Auto-Configures: Updates
~/.hermes/config.yamlto ensure footers & parameters are enabled.- 🧹 Cache Purging: Cleans all stale
.pycand__pycache__bytecode directories.- 🚀 Systemd Hook: Installs
ExecStartPreauto-healing guard.- 🔄 Smooth Restart: Restarts
hermes-gatewayservice automatically — instant effect without manual effort!
Option C: Interactive Menu (Multi-Select & Live Status Probing)
git clone https://github.com/shali10/hermes-patches.git
cd hermes-patches
bash install.sh
# Or directly run via Python package:
hermes-patches
💡 Highlights:
- Live Status Probing: Instantly shows
[APPLIED ✓]or[PENDING -]for each patch item in the console;- Direct In-Place Multi-Selection: No secondary submenus! Directly enter multiple indices (e.g.
2 3 7or2,3,7) or ranges (2-5) in the main prompt to install immediately with auto-restart.
Option D: Advanced CLI Flags
# 1. Probe live patch status across target directory
hermes-patches --status
# (Or output structured JSON)
hermes-patches --status --json
# 2. Preview changes (Dry Run)
hermes-patches --dry-run -v
# 3. Select specific patches by ID, numeric index, or range
hermes-patches --only 2 3 7 --auto-config --restart
hermes-patches --only 2-5 nostream --auto-config --restart
# 4. Apply all except menu localization
hermes-patches --skip menu --auto-config --restart
📦 Patch Registry
| Patch ID | Aliases | Target Files | Description |
|---|---|---|---|
footer |
runtime-footer, token, stats |
gateway/runtime_footer.pygateway/run_turn_persistence.pygateway/run_turn_runner.py |
Renders Prompt totals, cache read tokens, outputs, latency, and context %. |
menu |
telegram-menu, menu-zh, i18n |
hermes_cli/commands.pyhermes_cli/commands_platforms.py |
Localizes Telegram bot /start, /new, /status... command descriptions and /help. |
smart-split |
split, chunking, telegram-split |
gateway/platforms/base_chunking.pygateway/platforms/base.py |
Splits 4096+ char messages at paragraph breaks (\n\n) without stranding a heading, and repairs code fences. |
quote-blocks |
quote, blockquote, expandable-quote |
plugins/platforms/telegram/telegram_markdown.py |
Converts a run of quoted lines as one blockquote: blank quoted lines stay inside, >text without a space counts, trailing || marks the fold. |
Numbers are the
--only/--skipindices (1–4, matching the interactive menu).db,clean-think,terminal-cwdandstate-guardwere removed in v2.0.0: upstream v0.23.3+ covers them natively (persistence/refactor,think_scrubberCJK tags,_usable_cwdfallback,HERMES_PROTECTED_SUBPATHSguard). Use av1.xtag if you still need the old behavior on an older tree.
❓ FAQ & Troubleshooting
Q1: Why wasn't the footer appearing previously after a reboot?
- Resolved in v1.3.0+: The installer now automatically initializes
~/.hermes/config.yamlwithdisplay.runtime_footer.enabled: trueand all metric fields. - Manual check: Run
hermes config get display.runtime_footeror send/footer onin Telegram.
Q2: Why are bot commands still in English in Telegram?
- Telegram caches bot command lists locally. Send a message to the bot or fully close/kill the Telegram client and restart it to refresh the cache.
Q3: How to apply patches in Docker containers?
docker exec -it <container_name> bash -c "curl -fsSL https://raw.githubusercontent.com/shali10/hermes-patches/main/install.sh | bash"
docker restart <container_name>
📝 Changelog
| Version | Date | Highlights | Details |
|---|---|---|---|
v1.6.1 |
2026-09-08 | 🔄 Continuous interactive console session loop (Enter to return / 0 to exit) + Live status refresh | View 📄 |
v1.6.0 |
2026-09-08 | 🎛️ Interactive in-place multi-select installation (indices/ranges) + Live patch status display (--status) |
View 📄 |
v1.5.0 |
2026-09-07 | 🧱 SQLite state.db action-anchored anti-destruction floor (state-guard) + Neo-Brutalist showcase banner |
View 📄 |
v1.4.0 |
2026-09-02 | ⚡ Multi-vendor cache parsing + adaptive prefix derivation + terminal-cwd patch + PyPI packaging | View 📄 |
v1.3.8 |
2026-08-29 | 🎯 Dual-path token resolution + true Prompt Total (Input+Cache) & KV cache hit rate alignment | View 📄 |
v1.3.0 |
2026-08-29 | 🚀 Turnkey zero-config init + automatic service restart + multi-stage path probe + bytecode purging | View 📄 |
v1.2.0 |
2026-08-29 | Added quiet streaming (429 shield), deep thinking cleaner, 4096 smart chunker, interactive menu & FAQ | View 📄 |
v1.1.0 |
2026-08-29 | Added --only / --skip modular selection, Tirith low-risk bypass, bilingual docs & CI |
View 📄 |
v1.0.0 |
2026-08-29 | Initial release: Full token telemetry, Telegram pipe tables, menu i18n, SQLite durability | View 📄 |
↩️ Uninstall & Rollback
bash install.sh --uninstall
🌟 Community & Acknowledgement
Special thanks to the LINUX DO community for continuous technical discussions, production debugging insights, and support!
📄 License
Licensed under the MIT License.
Explore related projects
Loading…