Skip to content

feat(hermes): add Hermes Agent support via rtk init --agent hermes - #1614

Merged
aeppling merged 2 commits into
rtk-ai:developfrom
Kayphoon:feat/hermes-integration
May 11, 2026
Merged

aeppling merged 2 commits into
rtk-ai:developfrom
Kayphoon:feat/hermes-integration

Conversation

@Kayphoon

@Kayphoon Kayphoon commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add first-class RTK support for Hermes Agent through rtk init --agent hermes
  • Install a Python plugin that rewrites Hermes terminal tool commands to RTK equivalents before execution
  • Rewrite decisions stay centralized in Rust via rtk rewrite

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test
  • python3 -m unittest discover -s hooks/hermes -p '*test*.py' (18 tests passed)
  • Manual: rtk init --agent hermes → verified git status rewrites to rtk git status

@pszymkowiak pszymkowiak added effort-medium 1-2 jours, quelques fichiers enhancement New feature or request labels Apr 29, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

✨ Type feature
🟢 Risk low

Summary

Adds first-class Hermes Agent support to RTK via rtk init --agent hermes. This installs a Python plugin that intercepts Hermes terminal tool calls and delegates command rewriting to rtk rewrite in Rust. The PR includes the plugin code, plugin manifest, comprehensive tests, and documentation updates across README and supported-agents guide.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@SimZhou

SimZhou commented May 7, 2026

Copy link
Copy Markdown

This commit looks good, should it be merged, so that we can use rtk in hermes agent?

@aeppling

aeppling commented May 7, 2026

Copy link
Copy Markdown
Contributor

Hey @Kayphoon ,

Thanks for this new integrations, here are some first sight review to ensure conformity with codebase and proper integration.

1. Move plugin files to hooks/hermes/

  • Move hermes/rtk-rewrite/init.py → hooks/hermes/rtk-rewrite/init.py
  • Move hermes/rtk-rewrite/plugin.yaml → hooks/hermes/rtk-rewrite/plugin.yaml
  • Move hermes/README.md → hooks/hermes/README.md
  • Move hermes/tests/ → hooks/hermes/tests/
  • Update include_str! paths in src/hooks/init.rs (../../hermes/ → ../../hooks/hermes/)
  • Delete hermes/ at repo root

2. Add uninstall support

  • Add uninstall_hermes() function in init.rs: remove ~/.hermes/plugins/rtk-rewrite/, revert config.yaml (remove rtk-rewrite from plugins.enabled)
  • Wire it into the uninstall() dispatcher (match on AgentTarget::Hermes)

3. Add discover integration

  • Register Hermes in src/discover/ so rtk discover can detect ~/.hermes/plugins/rtk-rewrite/ presence and report status

4. Improve Python plugin error reporting

  • Replace silent except Exception: return with:
    except Exception as e:
    import sys
    print(f"rtk: hermes plugin warning: {e}", file=sys.stderr)
    return
  • Adopt _check_rtk() pattern from PR feat: add Hermes agent plugin for RTK command rewriting #1006: don't register the hook at all if rtk is not in PATH (avoids subprocess failures on every call)

4. Hermes config parsing

Custom YAML config patching without a YAML library. Works for standard configs but has no test coverage for inline list formats (enabled: [a, b]). Worth adding edge case tests to confirm robustness.

We prefer not adding a dependencies, but worth reviewing this part to ensure no futur issue with more complexe configurations.

Summary

Thanks for this PR, there is other opened PR for Hermes, i'm in favor of this one, awaiting for your answer for further review

@Kayphoon
Kayphoon force-pushed the feat/hermes-integration branch 6 times, most recently from 464ff48 to ccd974e Compare May 8, 2026 15:48
@Kayphoon

Kayphoon commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Hey @Kayphoon ,

Thanks for this new integrations, here are some first sight review to ensure conformity with codebase and proper integration.

1. Move plugin files to hooks/hermes/

  • Move hermes/rtk-rewrite/init.py → hooks/hermes/rtk-rewrite/init.py
  • Move hermes/rtk-rewrite/plugin.yaml → hooks/hermes/rtk-rewrite/plugin.yaml
  • Move hermes/README.md → hooks/hermes/README.md
  • Move hermes/tests/ → hooks/hermes/tests/
  • Update include_str! paths in src/hooks/init.rs (../../hermes/ → ../../hooks/hermes/)
  • Delete hermes/ at repo root

2. Add uninstall support

  • Add uninstall_hermes() function in init.rs: remove ~/.hermes/plugins/rtk-rewrite/, revert config.yaml (remove rtk-rewrite from plugins.enabled)
  • Wire it into the uninstall() dispatcher (match on AgentTarget::Hermes)

3. Add discover integration

  • Register Hermes in src/discover/ so rtk discover can detect ~/.hermes/plugins/rtk-rewrite/ presence and report status

4. Improve Python plugin error reporting

  • Replace silent except Exception: return with:
    except Exception as e:
    import sys
    print(f"rtk: hermes plugin warning: {e}", file=sys.stderr)
    return
  • Adopt _check_rtk() pattern from PR feat: add Hermes agent plugin for RTK command rewriting #1006: don't register the hook at all if rtk is not in PATH (avoids subprocess failures on every call)

4. Hermes config parsing

Custom YAML config patching without a YAML library. Works for standard configs but has no test coverage for inline list formats (enabled: [a, b]). Worth adding edge case tests to confirm robustness.

We prefer not adding a dependencies, but worth reviewing this part to ensure no futur issue with more complexe configurations.

Summary

Thanks for this PR, there is other opened PR for Hermes, i'm in favor of this one, awaiting for your answer for further review

Hey @aeppling,
Thanks a lot for the thorough review and the kind words on this integration. I've addressed all five points on ccd974e; here's a quick rundown so you can re-review:

  1. Plugin files moved to hooks/hermes/
    All Hermes files now live under hooks/hermes/ (rtk-rewrite/init.py, rtk-rewrite/plugin.yaml, README.md, tests/). The root hermes/ directory has been deleted, and the include_str! paths in src/hooks/init.rs were updated to ../../hooks/hermes/.... Repository copy vs. runtime install path (~/.hermes/plugins/rtk-rewrite/) are now clearly separated in the README.
  2. Uninstall support
    Added uninstall_hermes() in src/hooks/init.rs: it removes ~/.hermes/plugins/rtk-rewrite/ and strips rtk-rewrite from plugins.enabled in config.yaml (idempotent, preserves other entries). It's wired into the uninstall dispatcher through AgentTarget::Hermes, so rtk init --agent hermes --uninstall just works. Two tests cover the happy path and the idempotent / missing-file case.
  3. Discover integration
    rtk discover now reports Hermes status via a new AgentIntegrationStatus struct in src/discover/report.rs, exposed in both text output and the JSON agent_status field. One small tweak vs. the suggestion: detection checks the plugin manifest file (~/.hermes/plugins/rtk-rewrite/plugin.yaml) rather than just the directory, so a stale or empty directory doesn't get reported as "installed". Four tests cover the detection and the two output formats.
  4. Python plugin error reporting
    The bare except Exception: return is gone — it now calls a _warn(...) helper that writes to sys.stderr with an rtk: hermes plugin warning: prefix. I also adopted the _check_rtk() pattern from feat: add Hermes agent plugin for RTK command rewriting #1006: the hook is not registered at all when rtk is missing from PATH, and the "rtk not found" warning is printed once (via a _rtk_missing_warned flag) instead of on every pre_tool_call. Non-zero rtk rewrite exit codes now also surface a warning with stderr context (exit 1/2 stay silent since they're expected pass-through codes).
  5. Hermes config parsing
    Kept the no-dependency textual approach and expanded test coverage around inline list formats specifically. There are now 6 inline-list tests plus matching block-list coverage:
  • test_hermes_config_patch_inline_enabled_is_idempotent
  • test_hermes_config_patch_inline_enabled_without_final_newline_is_idempotent
  • test_hermes_config_unpatch_inline_enabled_without_rtk_preserves_missing_final_newline
  • test_hermes_config_unpatch_inline_enabled_preserves_unrelated_entries
  • test_hermes_config_unpatch_inline_enabled_final_line_without_newline
  • test_hermes_config_unpatch_removes_duplicate_inline_rtk_rewrite
    While writing these I also caught and fixed two real line-ending bugs: block-style patches were concatenating - rtk-rewrite onto a preceding item when the file had no trailing newline, and the inline path was unconditionally appending \n on no-op unpatches. Both are fixed via a small yaml_line_ending() helper that preserves the original line terminator (\n, \r\n, or none).

Full local verification on ccd974e: cargo fmt --all --check, cargo clippy --all-targets -- -D warnings, cargo test --all (1848 passed, 0 failed), and python3 -m unittest discover -s hooks/hermes (18 passed). Happy to address any follow-up comments — thanks again for taking the time.

@cresslank

Copy link
Copy Markdown

Thanks for this. I spot-checked the latest PR head and found one config-patching issue to address before merge.

Hermes serializes configs w/ PyYAML's default indentationless sequence style. So plugins.enabled:\n - ... is not the only valid/expected shape, eg this is valid:

plugins:
 disabled:
 - google_meet
 - spotify                                                                                                                                                                                                                                    
 enabled:
 - disk-cleanup                                                                                                                                                                                                                     

Running rtk init --agent hermes against that valid config currently reports success but writes invalid YAML:

plugins:
 disabled:
 - google_meet
 - spotify                                                                                                                                                                                                                                    
 enabled:
   - rtk-rewrite
 - disk-cleanup                                                                                                                                                                                                                     

Hermes then fails to load the config with while parsing a block mapping expected <block end>, but found '-'

This also affects idempotency and uninstall: an existing same-indent - rtk-rewrite is not recognized as part of plugins.enabled, so rerunning init can duplicate/break the entry, and uninstall can leave invalid YAML like enabled: [] followed by same-indent list items.

Separate from that, I’d also recommend honoring HERMES_HOME before falling back to ~/.hermes, since Hermes profiles set HERMES_HOME before plugin loading.

@aeppling aeppling self-assigned this May 10, 2026
@Kayphoon
Kayphoon force-pushed the feat/hermes-integration branch 3 times, most recently from 82bd6c2 to 2a80c74 Compare May 10, 2026 11:16
@Kayphoon

Copy link
Copy Markdown
Contributor Author

Thanks for this. I spot-checked the latest PR head and found one config-patching issue to address before merge.

Hermes serializes configs w/ PyYAML's default indentationless sequence style. So plugins.enabled:\n - ... is not the only valid/expected shape, eg this is valid:

plugins:
 disabled:
 - google_meet
 - spotify                                                                                                                                                                                                                                    
 enabled:
 - disk-cleanup                                                                                                                                                                                                                     

Running rtk init --agent hermes against that valid config currently reports success but writes invalid YAML:

plugins:
 disabled:
 - google_meet
 - spotify                                                                                                                                                                                                                                    
 enabled:
   - rtk-rewrite
 - disk-cleanup                                                                                                                                                                                                                     

Hermes then fails to load the config with while parsing a block mapping expected <block end>, but found '-'

This also affects idempotency and uninstall: an existing same-indent - rtk-rewrite is not recognized as part of plugins.enabled, so rerunning init can duplicate/break the entry, and uninstall can leave invalid YAML like enabled: [] followed by same-indent list items.

Separate from that, I’d also recommend honoring HERMES_HOME before falling back to ~/.hermes, since Hermes profiles set HERMES_HOME before plugin loading.

Thanks for catching this. I updated the Hermes config patching to handle PyYAML's indentationless sequence style for plugins.enabled.
The latest PR head now preserves same-indent plugins.enabled lists, keeps rtk init --agent hermes idempotent when rtk-rewrite is already present, and removes rtk-rewrite on uninstall without leaving dangling list items or invalid YAML. I also added HERMES_HOME support so Hermes profiles are honored before falling back to ~/.hermes.
I added regression coverage for patching, repeated patching, uninstall cleanup, collapse-to-empty behavior, and install/uninstall integration with the same-indent config shape. I verified formatting, Rust tests, and the Hermes Python test suite; after rebasing onto latest develop, the PR is mergeable again and remains a single commit.

@aeppling

aeppling commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Hey @Kayphoon

I've been testing Hermes with this RTK configuration, work well and saving tokens !

But i've come across some config errors while using, did not broke anything, but got some warning from Hermes agent when running.

I did nothing special just installed and ran "rtk init --agent hermes -g"

Invalid YAML when plugins.enabled uses the compact list layout. Hermes writes config.yaml with PyYAML, whose default dump puts list items flush with the key:

   plugins:
     enabled:
     - foo

init.rs inserts the new entry at a hardcoded key_indent + 2, producing:

   plugins:
     enabled:
       - rtk-rewrite   # 4 spaces
     - foo             # 2 spaces  -> PyYAML: "expected <block end>, but found '-'"

@Kayphoon
Kayphoon force-pushed the feat/hermes-integration branch from 2a80c74 to 8796d56 Compare May 11, 2026 15:34
@Kayphoon

Kayphoon commented May 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @Kayphoon

I've been testing Hermes with this RTK configuration, work well and saving tokens !

But i've come across some config errors while using, did not broke anything, but got some warning from Hermes agent when running.

I did nothing special just installed and ran "rtk init --agent hermes -g"

Invalid YAML when plugins.enabled uses the compact list layout. Hermes writes config.yaml with PyYAML, whose default dump puts list items flush with the key:

   plugins:
     enabled:
     - foo

init.rs inserts the new entry at a hardcoded key_indent + 2, producing:

   plugins:
     enabled:
       - rtk-rewrite   # 4 spaces
     - foo             # 2 spaces  -> PyYAML: "expected <block end>, but found '-'"

Hey @aeppling, thanks for giving it a real spin on Hermes and the clear repro.
You're right that Hermes' PyYAML dump uses the compact layout:

plugins:
  enabled:
  - foo

The latest PR head handles this shape. Instead of a hardcoded key_indent + 2, the block-style patch path now detects the existing list item's indent and reuses it, so inserting rtk-rewrite preserves Hermes' PyYAML layout:

plugins:
  enabled:
  - foo
  - rtk-rewrite

I added an exact regression test for your repro input (test_hermes_config_patch_pyyaml_default_compact_enabled_list) on top of the existing PyYAML same-indent and missing-enabled coverage. Install is idempotent in that layout (no duplicate rtk-rewrite), and uninstall removes only rtk-rewrite while preserving other plugins and the surrounding indentation.
I also verified end-to-end against a temp HERMES_HOME with your exact config shape:

plugins:
  enabled:
  - foo

After rtk init --agent hermes:

plugins:
  enabled:
  - foo
  - rtk-rewrite

After rtk init --agent hermes --uninstall:

plugins:
  enabled:
  - foo

No Hermes warnings on load in that run. Separately, I added a nosemgrep: filesystem-deletion justification on the Hermes uninstall remove_dir_all to match the existing pattern used elsewhere in init.rs and unblock the security scan. Let me know if you'd like me to reproduce any other Hermes-generated config shape.

@Kayphoon

Copy link
Copy Markdown
Contributor Author

@aeppling
Quick heads up on CI: the current failure is in cargo fmt --all -- --check against src/hooks/hook_cmd.rs, around the strip_leading_bom test. That file isn't touched by this PR, so it looks like a rustfmt drift on the base branch rather than something from the Hermes changes.
Happy to either include a one-line formatting cleanup here to unblock the pipeline, or hold off if you'd rather handle it on develop directly. Just let me know what you prefer.

@aeppling

Copy link
Copy Markdown
Contributor

Hey @Kayphoon , you can cleanup here thanks :)

then LGTM !

@Kayphoon
Kayphoon force-pushed the feat/hermes-integration branch from 8796d56 to f7c4bf6 Compare May 11, 2026 16:32
@Kayphoon

Copy link
Copy Markdown
Contributor Author

Hey @Kayphoon , you can cleanup here thanks :)

then LGTM !

Hey @aeppling, truly appreciate the thorough review on this one. The latest head is rebased on develop, with the rustfmt cleanup in its own style(hooks): format BOM helper assertion commit — isolated from the Hermes work, no behavior change. Locally green on cargo fmt --all -- --check, cargo clippy --all-targets, cargo test --all, and the Hermes Python tests. I'm genuinely excited about this one — it's ready for merge from my side. Happy to squash or adjust if you prefer. Thanks again!

@aeppling

Copy link
Copy Markdown
Contributor

Thanks !

Will be available in next release :)
Should land during the week.

@aeppling
aeppling merged commit 55f998d into rtk-ai:develop May 11, 2026
11 checks passed
@aeppling aeppling mentioned this pull request May 11, 2026
thedavemarshall added a commit to thedavemarshall/rtk that referenced this pull request May 13, 2026
…ion cleanup

uninstall_omp now returns Result<()> and owns the user-facing summary, while
uninstall_omp_at returns Result<Vec<String>> silently — matching the split
established by uninstall_hermes_at and uninstall_codex_at (PR rtk-ai#1614). Removes
the discarded return value at the caller and the duplicated println! channel
inside _at.

Also: complete dependency injection in resolve_omp_agent_dir_from_env so
the PI_CONFIG_DIR branch is unit-testable; drop the misleading underscore
prefix on rtkMissingWarned (TS convention reserves _ for unused bindings);
restore the blank line between tests in discover::report.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort-medium 1-2 jours, quelques fichiers enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants