Repository navigation
feat(plugin): let tool.execute.before short-circuit with a result - #32679
Closed
OddballGreg wants to merge 1 commit into
Closed
OddballGreg wants to merge 1 commit into
OddballGreg wants to merge 1 commit into
Conversation
Extend the tool.execute.before hook output with an optional result string. When a plugin sets it, the tool is not executed and the supplied string is returned as the tool output instead; the tool.execute.after hook still runs on the substituted result. Wired through both the native and MCP tool paths in SessionTools.resolve. Backwards compatible: hooks that don't set result behave exactly as before. Enables cache/memory plugins to answer a tool call they already hold the result for (e.g. returning an indexed summary instead of doing a read), which today is impossible: tool.execute.before can only mutate args, tool.execute.after runs after the work happened, and permission.ask only denies with an error. Refs anomalyco#5148.
1 task done
Contributor
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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.
Issue for this PR
Refs #5148
Type of change
What does this PR do?
It lets a plugin short-circuit a tool call from
tool.execute.beforeby supplying the result itself.tool.execute.beforecurrently only exposes{ args }, so a plugin can rewrite arguments but cannot prevent the tool from running. InSessionTools.resolvethe runtime always calls the tool after the hook (the native path around L92 and the MCP path around L135).tool.execute.aftercan rewrite the output, but only after the work already happened, andpermission.askcan deny a call but returns an error rather than a usable result.This adds an optional
result?: stringto the before-hook output. If a plugin sets it, the tool is not executed and that string is returned as the tool output instead;tool.execute.afterstill runs on the substituted result. It is wired through both the native and MCP tool paths. Hooks that do not setresultbehave exactly as before, so it is backwards compatible.The motivating case is a cache/memory plugin that already holds the answer for a
read/grepand wants to return it instead of doing the read. This is the minimal "early termination" slice of the broader middleware pipeline discussed in #5148 (a prior attempt, #18689, implemented a larger version but was auto-closed before review). TheHooksinterface is hand-written inpackages/plugin, so no SDK regeneration applies.How did you verify your code works?
bun run typecheckpasses for both theopencodeandpluginpackages (no errors in the changed files),prettier --checkis clean, andoxlintreports no errors on the two files. I did not add an automated test: theSessionTools.resolveplugin-hook path has no existing unit-test harness and a full session/plugin integration test would be disproportionate to the change, so I verified by typechecking and tracing both branches. Happy to add coverage if you can point me at the right harness.Screenshots / recordings
Not a UI change.
Checklist