Skip to content

fix(agents): Hermes modify directive + OpenClaw plugin packaging and activation - #4093

Open
RikETS wants to merge 3 commits into
rtk-ai:developfrom
SeddCo:fix/agent-load-and-modify-directive
Open

RikETS wants to merge 3 commits into
rtk-ai:developfrom
SeddCo:fix/agent-load-and-modify-directive

Conversation

@RikETS

@RikETS RikETS commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Two agent integrations could not actually run, and one used an undocumented hook path.

  • Hermes plugin returned a rewrite by mutating the tool payload in place. It works only because _pre_tool_block happens to return the same object it passed to the hook; Hermes' documented and tested contract is the {"action": "modify", "args": {...}} directive, which is also what the plugin ledger records. Returns the directive now; tests assert the directive and that the incoming args is untouched.
  • OpenClaw plugin never ran in a Gateway. openclaw plugins install ./openclaw is refused for a missing openclaw.extensions; after adding that it is refused again because package installs require compiled JS (a TypeScript entry only loads for --link source checkouts). Worse, with no activation block the Gateway never imports the plugin at all (since 2026.9.2 onStartup is no longer implicit) — while openclaw plugins list and openclaw plugins doctor still report it enabled and healthy. Adds a tsc build, points main/openclaw.extensions/files at dist/index.js, commits the built artifact, and declares activation.onStartup: true and the before_tool_call hook.
  • Docs updated for both (build step, activation requirement, and the allow-rule requirement below), and .gitignore learns node_modules/.

Worth knowing for anyone testing this: rtk rewrite takes its allow/ask/deny verdict from Claude Code Bash() permission rules. With no matching allow rule every rewritable command returns "ask", which the OpenClaw plugin turns into an approval request denied on timeout — an unattended agent stalls or blocks on nearly every command. That is documented in the README change, not altered here.

Test plan

  • python3 -m unittest discover -s hooks/hermes — 18 tests, 17 pass. The single failure is test_cargo_init_installs_importable_plugin_that_rewrites_with_fake_rtk, which shells out to cargo and cannot build on a host with cargo 1.75 (repo requires edition 2024); it fails identically before and after these commits.
  • cd openclaw && npm install && npm run build — emits dist/index.js cleanly.
  • Drove the built dist/index.js through a stub OpenClaw plugin API against a real rtk binary: git status → rtk git status (params rewritten, no approval once an allow rule exists), unsupported commands and non-exec tools untouched.
  • Installed the plugin into a real OpenClaw 2026.9.2 Gateway: the startup list goes from 17 to 18 plugins with rtk-rewrite in it (before the fix the same install produced 17 with no rtk-rewrite), and a live exec turn returned RTK's compact output with rtk gain recording the command.
  • cargo fmt --all && cargo clippy --all-targets && cargo test — not run here (no edition-2024 toolchain on this host); no Rust source is touched by this PR apart from .gitignore.
  • Manual testing: rtk <command> output inspected — unchanged by this PR.

Rik added 3 commits September 17, 2026 12:01
The Hermes plugin applied rewrites by mutating the caller's `args` dict in
place. That only happens to work: Hermes' `_pre_tool_block` returns the same
object it passed to the hook, so argument identity carries the change. The
documented and tested hook contract is different — a callback returns
`{"action": "modify", "args": {...}}` and Hermes shallow-merges it, which also
makes the rewrite visible to the plugin ledger.

Return that directive and leave the incoming payload untouched. Fail-open
behaviour and the exit-code handling are unchanged; the plugin tests now assert
the returned directive and that `args` is not mutated.
Two problems stopped the plugin from ever running in a Gateway:

1. `openclaw plugins install ./openclaw` is refused with "package.json missing
   openclaw.extensions", and fixing that surfaces a second refusal: package
   installs require compiled JavaScript (`expected ./dist/index.js`) — a
   TypeScript entry only loads for source checkouts via `--link`, which the
   Gateway does not pick up either.
2. With no `activation` block in the manifest, OpenClaw never imports the plugin
   at Gateway startup (since 2026.9.2 `onStartup` is no longer implicit), so the
   `before_tool_call` hook is never registered — while `openclaw plugins list`
   and `openclaw plugins doctor` both report the plugin as enabled and healthy.

Add a `tsc` build (`npm run build` -> `dist/index.js`), point `main`,
`openclaw.extensions` and the published `files` at it, emit the built artifact
so installing straight from the repo works, and declare
`activation.onStartup: true` plus the `before_tool_call` hook in the manifest.

Verified on OpenClaw 2026.9.2: the Gateway's startup plugin list goes from 17 to
18 entries with `rtk-rewrite` included after the change, and an `exec` turn
returns RTK's compact output with the command tracked by `rtk gain`.
The OpenClaw install steps were missing the build step, and neither the README
nor the supported-agents page mentioned that `activation.onStartup` is what makes
the Gateway import the plugin, or that `rtk rewrite` reads its allow/ask/deny
verdict from Claude Code `Bash()` permission rules — without matching allow rules
every rewrite becomes an approval request that is denied on timeout in an
unattended agent.

Also correct the Hermes section: the plugin returns a `modify` directive rather
than mutating the tool payload.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Rik seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working documentation Improvements or additions to documentation openclaw agents hermes labels Sep 17, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes two broken agent integrations: the Hermes rtk-rewrite plugin now returns Hermes' documented {"action": "modify", "args": {...}} directive instead of mutating the args dict in place, and the OpenClaw plugin is fixed to actually build/install/activate (adds tsc build emitting dist/index.js, points package manifest fields at the compiled output, commits the build artifact, and declares an activation.onStartup block so the Gateway registers the before_tool_call hook). Documentation for …

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

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

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 1 — CHANGES REQUESTED

Claim: the bundled OpenClaw plugin installs with openclaw plugins install ./openclaw and is loaded by the Gateway at startup; the Hermes plugin returns a modify directive.
Scope: accept if narrowed to "the OpenClaw plugin installs with openclaw plugins install ./openclaw and is loaded at Gateway startup". The Hermes commit (5d4fa42) is the change under review in #3833, opened earlier; please drop it from this PR so that discussion stays in one place.
Ran: OpenClaw 2026.8.35, 2026.9.2, 2026.9.6 and 2026.10.3, with plugin trees from develop (f16beca), #4373, this head (322aefb), this head merged onto develop, the merge with dist/ rebuilt from develop's index.ts, and the merge without activation. Each tree was installed by copy, by --link, and by develop's README manual copy (32 install rows). Then a real Gateway agent turn ran with a stub OpenAI-compatible model that issues one exec git status in a scratch repo, against a real rtk built from develop, with no Claude Code settings and with a Bash(git status) deny rule (25 rows). Invariants: every decision; non-default targets (4 releases × 3 install forms). Savings 79% (207 → 44 bytes on git status) vs the 20% floor (CONTRIBUTING.md).
Pins: 4 decisions; 3 mutated, 3 survived (activation, the compiled extensions entry, the dist/ content). The 4th, the manifest hooks field, has no observable effect: #4373's tree omits it and its hook fires on all four releases.
Matrix: executed this round; pin check: executed this round
CI @322aefbdf: the CI run is waiting for workflow approval, and no workflow builds or tests openclaw/ (#4588). This verdict rests on the matrix above.

Blocks merge (2, frozen at round 1)

  1. openclaw/package.json:24: committed build output drifts from its source (1 artifact, 1 source; nothing ties the two). Since this branch was cut, develop changed openclaw/index.ts in c6f484f, the #3908 fix: it passes RTK_REWRITE_HOST=openclaw, so a command that matches no Claude Code rule no longer raises an approval. The committed dist/index.js is byte-identical to tsc of the pre-#3908 file, and both main and openclaw.extensions point at it. So once this PR is merged onto develop, OpenClaw loads the old code.
    Evidence, merged tree, copy install, no Claude Code settings, agent turn exec git status:

    • On all four releases the tool returns {"status":"error","tool":"exec","error":"Plugin approval unavailable (no approval route)"} and the command does not run. This head on its own branch gives the same result.
    • The same tree with dist/ rebuilt from develop's index.ts returns * No commits yet on master\n?? a.txt\n?? b.txt on all four, and rtk gain records it.
    • With the deny rule, both block (RTK deny rule matched).

    Nothing keeps the two in step: no CI job, script or test reads openclaw/, and #4044 and #4372 (open) edit only index.ts. The new "Allow rules for headless agents" README section, and the matching sentence in supported-agents.md, document this pre-#3908 behaviour as expected. Git merges the README without a conflict, so after merge it says both that and develop's "does not prompt for a command that matched no rule" (lines 51-56 vs 90).
    A fix passes the rows above on the merged tree: an unmatched command gives RTK output with no approval, and a deny rule still blocks. It must also make it impossible for an index.ts change without a rebuild to reach users unnoticed. Which shape do you prefer?

    • (a) Keep dist/ committed and add a check that fails when it differs from tsc of index.ts. That needs a node step in CI, which nothing provides today (#4588).
    • (b) Stop committing dist/: gitignore it, build it from a prepare script, and keep the README build step.
      Either way, the allow-rules paragraphs go when you rebase.
  2. openclaw/openclaw.plugin.json:8: unpinned behaviour (startup activation, compiled entry). Evidence: removing activation, pointing openclaw.extensions back at ./index.ts and deleting dist/index.js together still passes 4953/4954 tests across 49 binaries. The one failure, go_test_help_is_not_replayed_through_the_injected_json, fails the same way unmutated. Each of these changes matters on a real Gateway:

    • Without activation, the plugin is missing from the Gateway's startup plugin list and raw git status runs, on all four releases, 2026.8.35 included.
    • With a ./index.ts entry, a copy install is refused: package install requires compiled runtime output for TypeScript entry ./index.ts.

    The test must read openclaw/openclaw.plugin.json and openclaw/package.json and assert activation.onStartup == true and that every openclaw.extensions entry is an existing .js file. Under (a), it must also assert that dist/ matches its source. Each of the three edits above must turn it red.

Optional (won't hold merge)

  • Following the README (npm install, npm run build, then a copy install) puts node_modules/ into ~/.openclaw/extensions/rtk-rewrite/: 25 MB of typescript and @types/node, on 2026.9.2 and 2026.10.3. files only filters npm pack, not a directory install.
  • The manifest hooks: ["before_tool_call"] can stay or go: it changes nothing on the four releases tried.

Relation to #4373

this PR #4373
openclaw plugins install ./openclaw (the documented form) installs and loads on all four releases refused on all four (TypeScript entry needs compiled output)
--link install installs and loads installs and loads; hook rewrites, deny blocks
code OpenClaw loads committed dist/ (stale once merged, item 1) index.ts directly, cannot drift
docs install, build, activation none

This PR is the one that makes the documented install work, and it covers both fields #4373 adds. Once it lands, #4373 has nothing left to add.

Checked and correct — no need to re-verify

  • activation.onStartup: true is required for the Gateway to import the plugin on 2026.8.35, 2026.9.2, 2026.9.6 and 2026.10.3. (The description says "since 2026.9.2"; 2026.8.35 needs it too.)
  • A compiled .js entry in openclaw.extensions is required for a copy install on all four releases; --link accepts index.ts.
  • --accept-capabilities is accepted by plugins install on all four releases.
  • The committed dist/index.js is exactly what tsc produces from this branch's own index.ts. The build is honest; it is the base that moved.
  • Rebuilt from develop's index.ts, the compiled plugin rewrites, records in rtk gain, and blocks on a deny rule.

Your questions

None asked.

Next

Drop the Hermes commit and rebase onto develop: .gitignore and supported-agents.md conflict. Take develop's OpenClaw permission text and drop the allow-rules paragraphs. Then fix item 1 in shape (a) or (b) and add the test in item 2.
The CLA also needs to be signed before this can merge: license/cla is still pending. The commits are authored as "Rik" with an email that is not linked to your GitHub account, so the CLA check cannot match them to you. Add that email to your account (or re-author the commits with one that is), then sign through the link in the license/cla check. After that, this merges.
Rounds: 1. Threads: 2 open (waiting on the author), 0 resolved this round.

Comment thread openclaw/package.json
],
"openclaw": {
"extensions": [
"./dist/index.js"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OpenClaw loads this file, and it is tsc of the index.ts this branch started from. develop has changed index.ts since (c6f484f, #3908). Merged onto develop, a copy install with no Claude Code settings turns an agent's exec git status into Plugin approval unavailable (no approval route) on OpenClaw 2026.8.35, 9.2, 9.6 and 10.3. With dist/ rebuilt from develop's index.ts, the same turn returns RTK's output. Nothing rebuilds or checks dist/. Details and the two possible shapes are in the review body, item 1.

"description": "Transparently rewrites shell commands to their RTK equivalents, cutting up to 90% of the bash output reaching the LLM context",
"homepage": "https://github.com/rtk-ai/rtk",
"license": "Apache-2.0",
"activation": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Without this block the Gateway never imports the plugin, on all four releases I tried. Removing it, pointing openclaw.extensions at ./index.ts and deleting dist/index.js all at once still passes the whole suite. A test that reads the two manifests and asserts activation.onStartup and a .js entry that exists would catch all three. See item 2.

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

Labels

agents bug Something isn't working documentation Improvements or additions to documentation hermes openclaw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants