feat: register plugin middleware declaratively - #11
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Plugins can now declare behavior-changing Hermes middleware through the same lifecycle registration used for commands, tools, hooks, and skills. The public contract covers all four current request and execution phases, remains forward-compatible with future string kinds, and preserves the existing tool-only
register_allpath.Request middleware can replace the effective tool or model payload before Hermes continues. Execution middleware wraps the real call through Hermes' single-use
next_call, while the kit rejects async callbacks and duplicate phase declarations before registration and keeps payloads out of its instrumentation logs.Validation
make testpasses all 66 tests, including registration, privacy-safe failure logging, duplicate preflight, and the real hermes-agent middleware helpers for all four phases.make buildproduces the 0.5.0 source distribution and wheel.New concepts
Observer hooks versus middleware
Hooks report what happened, while middleware participates in what happens. A request callback can replace the payload that downstream policy and execution see; an execution callback controls when and how the real operation is invoked.
flowchart LR A["Original request"] --> B["Request middleware"] B --> C["Hooks, guardrails, and approvals"] C --> D["Execution middleware"] D --> E["Real tool or model call"] E --> DThis separation keeps observation passive and makes behavioral changes explicit. Use hooks for telemetry or contextual side effects; use middleware only when the plugin must rewrite an input, wrap execution, or transform a result. An execution callback must never call
next_calltwice because that would repeat the underlying operation.