Skip to content

feat: add Hermes agent plugin for RTK command rewriting - #1006

Closed
ogallotti wants to merge 1 commit into
rtk-ai:developfrom
ogallotti:feat/hermes-plugin
Closed

ogallotti wants to merge 1 commit into
rtk-ai:developfrom
ogallotti:feat/hermes-plugin

Conversation

@ogallotti

Copy link
Copy Markdown

Summary

Add a Python plugin for Hermes (AI coding agent by Nous Research) that transparently rewrites terminal commands to RTK equivalents via the pre_tool_call lifecycle hook, achieving 60-90% LLM token savings.

This follows the same pattern as the OpenClaw plugin (#358).

Plugin structure

hermes/
├── __init__.py              # Thin delegate to `rtk rewrite` (~75 lines)
├── plugin.yaml              # Manifest declaring pre_tool_call hook
├── README.md                # Installation, architecture, usage docs
└── test_rtk_plugin.py       # 26 tests (binary detection, rewrite, hooks, edge cases)

How it works

Hermes has a Python plugin system with lifecycle hooks. Plugins live in ~/.hermes/plugins/<name>/ and contain a plugin.yaml manifest + __init__.py with a register(ctx) function.

This plugin:

  1. Checks if rtk is in $PATH (cached, checked once)
  2. Registers a pre_tool_call hook
  3. On each terminal tool call, delegates to rtk rewrite <command>
  4. Mutates args["command"] in-place if a rewrite is available
# Core flow (simplified)
def _pre_tool_call(*, tool_name, args, task_id, **_kwargs):
    if tool_name != "terminal":
        return
    command = args.get("command")
    rewritten = subprocess.run(["rtk", "rewrite", command], ...).stdout.strip()
    if rewritten and rewritten != command:
        args["command"] = rewritten

Design principles

  • Thin delegate: all rewrite logic in rtk rewrite (Rust registry)
  • Graceful degradation: never blocks command execution
  • In-place mutation: Hermes passes a mutable dict, no return value needed
  • 2-second timeout on rtk rewrite subprocess
  • Zero dependencies: uses only Python stdlib (subprocess, shutil, logging)

Installation

mkdir -p ~/.hermes/plugins/rtk-rewrite
cp hermes/__init__.py hermes/plugin.yaml ~/.hermes/plugins/rtk-rewrite/

Tests

26 tests covering: binary detection, rewrite logic, hook behavior, edge cases (timeouts, crashes, non-terminal tools), and full integration flow.

$ python -m pytest hermes/test_rtk_plugin.py -v
26 passed in 0.03s

Changes to existing files

  • hooks/README.md: Added Hermes to supported agents table, directory listing, integration tiers, and JSON format docs

Checklist

  • Plugin follows thin-delegate pattern (same as openclaw/)
  • Graceful degradation (exit 0 on all error paths)
  • Tests pass (26/26)
  • README with installation instructions
  • hooks/README.md updated
  • Compatible with Python 3.9+

@CLAassistant

CLAassistant commented Apr 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Add a Python plugin for Hermes (AI coding agent) that transparently
rewrites terminal commands to RTK equivalents via the pre_tool_call
lifecycle hook, achieving 60-90% LLM token savings.

Plugin structure follows Hermes conventions:
- hermes/plugin.yaml — manifest declaring pre_tool_call hook
- hermes/__init__.py — thin delegate to `rtk rewrite`
- hermes/README.md — installation, architecture, usage docs
- hermes/test_rtk_plugin.py — 26 tests covering all paths

Design principles (same as openclaw/ plugin):
- Thin delegate: all rewrite logic lives in `rtk rewrite`
- Graceful degradation: never blocks command execution
- In-place mutation of args dict (no return value needed)
- 2-second timeout on rtk rewrite subprocess

Also updates hooks/README.md to include Hermes in the supported
agents table, directory listing, integration tiers, and JSON
format documentation.

@sheng-jie sheng-jie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Using the built-in rewrite command from RTK effectively enables the transformation of native commands.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for this, @ogallotti! Hermes support has since landed in RTK via #1614 — there's now a hooks/hermes/rtk-rewrite/ plugin (same pre_tool_call delegation to rtk rewrite) plus rtk init --agent hermes for automated setup.

Since the integration is already in place, closing this as superseded. Really appreciate the contribution — please don't hesitate to open new PRs for other agents or filters!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants