Repository navigation
Description
Summary
hooks/hermes/rtk-rewrite (plugin v0.1.0, __init__.py @ 6dcf44e) bridges Hermes' pre_tool_call hook to rtk rewrite. Four gaps surfaced on a live Hermes gateway:
- No guard against rewrites the rtk parser itself rejects. The adapter substitutes unconditionally; when the installed binary lags the rewrite contract, every affected call becomes a guaranteed parse-fail + shell fallback (zero savings, one extra subprocess, one
parse_failuresrow). - Hardcoded 2s timeout — real rewrites can exceed it, and the adapter then skips the rewrite entirely.
- No
stdin=subprocess.DEVNULL— the child inherits the gateway's stdin pipe. - Rewrites are silent — nothing records which command was replaced, so a degraded no-op looks identical to a working install.
This is an adapter-side report. Root cause of the arg-parsing half is tracked in #1604 (grep flags; fixed in v0.47.0 via #2628 — confirmed by @KuSh in that thread). The hook-timeout reports #218 / #1804 cover Claude Code and Gemini CLI config entries, not this adapter.
Environment (where the evidence came from)
- rtk 0.42.1 — deliberately older than the Hook rewrite produces unparseable args for native grep flags and non-existent subcommands #1604 fix, which is exactly what made these gaps visible
- Hermes Agent gateway (systemd user service), plugin enabled with
plugins.enabled: [rtk-rewrite] - Installed file is byte-identical to
hooks/hermes/rtk-rewrite/__init__.pyupstream
Evidence
Works overall — ~/.local/share/rtk/history.db → commands: 141 rows in one day, 18,848 tokens saved (34.4%), e.g. ls -la … at 63–85%, cat <log> at 82–98%. So the hook is live and useful.
But on the same day:
sqlite3 ~/.local/share/rtk/history.db "select count(*), sum(fallback_succeeded=1) from parse_failures;"
68|68
68 parse failures, 100% of them grep with native flags, all recovered by fallback:
grep -rn --include=*.go -E …→error: unexpected argument '-r' foundgrep -c plugin <file>→unexpected argument '-c'grep -ac rtk <log>→unexpected argument '-a'
And from the adapter's own stderr in journald:
rtk: hermes plugin warning: rtk rewrite timed out
Reproduction of the contract mismatch (on 0.42.1)
$ rtk rewrite "grep -rn foo ." # exit 3
rtk grep -rn foo .
$ rtk grep -rn foo . # the command just handed to the agent
error: unexpected argument '-r' foundThe rewriter returns a command its own parser rejects. On Hermes the substitution still happens, the call fails, and the shell falls back — a wasted subprocess on every occurrence.
Ask (adapter-side, version independent)
- Passthrough guard — do not substitute when the original shape is known-unparseable (or validate once per subcommand shape and cache the verdict).
- Configurable timeout — env such as
RTK_HERMES_TIMEOUT, default 5s instead of 2s. stdin=subprocess.DEVNULL.- Audit log — append
{ts, from, to}JSONL (e.g.~/.hermes/logs/rtk-rewrites.jsonl) so rewriting is observable. - Version handshake at register — warn once when
rtk --versionis older than the minimum version whose rewrite contract the adapter assumes.
We run a local patch covering 1–4, verified with rtk 0.50.0 (and against the hook function directly, no gateway restart needed). Happy to send it as a PR for hooks/hermes/ if that helps.
Activity
dinhtrung commentedon Oct 2, 2026
Closing this — we resolved it locally and the underlying cause is already fixed upstream.
-rn,-c,-ac,-nE,-l,-A/-B/-C,--include=,-q/-i/-v/-w/-o/-h/-enow parse).stdin=DEVNULL, silent rewrites, no version check) are patched on our box:RTK_HERMES_TIMEOUT(default 5s), DEVNULL stdin, JSONL audit log at~/.hermes/logs/rtk-rewrites.jsonl, and a one-time warning whenrtk --version< 0.47.0.Withdrawn rather than leaving duplicate work in your queue — no action needed from maintainers. If a PR for
hooks/hermes/is still welcome, I can send the patch; otherwise consider this withdrawn. Thanks!rtk-wshm-sync-bot commentedon Oct 2, 2026
🔍 Automated Triage
bugmediumSummary
Hermes adapter substitutes rewrites unconditionally with a hardcoded 2s timeout, inherited stdin, and no audit trail, causing avoidable parse-fail fallbacks (grep flags) against older rtk binaries.
📁 Relevant files
hooks/hermes/rtk-rewrite/__init__.pySuggested Actions
rtk rewritewithout a deadline from PreToolUse — see correction, rtk was NOT the cause of our timeouts #3589 (retracted hook-timeout report) when evaluating the timeout changeTriaged automatically by wshm · This is an automated analysis, not a human review.