feat(plugin): add tool.execute.error hook#10028
feat(plugin): add tool.execute.error hook#10028kynnyhsap wants to merge 3 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: The search results only show PR #10028 (the current PR itself) and other unrelated PRs about bash tool schema, memory leaks, Prometheus metrics, and shell resolution. No duplicate PRs found |
Manual TestingCreate a test plugin at import { type Plugin, tool } from "@opencode-ai/plugin"
export const TestErrorHookPlugin: Plugin = async (ctx) => {
return {
// Tool that always fails
tool: {
failing_tool: tool({
description: "A tool that always throws an error for testing",
args: {
message: tool.schema.string().describe("Error message to throw"),
},
async execute(args) {
throw new Error(`Intentional error: ${args.message}`)
},
}),
},
// Error hook to catch and handle errors
"tool.execute.error": async (input, output) => {
// Test 1: Modify the error message
if (input.tool === "failing_tool" && input.args.message === "modify-me") {
output.error = new Error("Modified error: The original error was intercepted and changed!")
}
// Test 2: Recover from error by returning a result
if (input.tool === "failing_tool" && input.args.message === "recover-me") {
output.result = {
title: "Recovered from error",
output: "The error was caught and handled gracefully by the plugin!",
metadata: { recovered: true },
}
}
},
}
}Test Prompts
|
8618735 to
4f38092
Compare
Add a new plugin hook that is triggered when a tool execution throws an error. This allows plugins to: - Log/track tool errors - Modify the error message before it's thrown - Recover from errors by providing a fallback result The hook receives the tool name, session ID, call ID, args, and a mutable output object containing the error. Plugins can set output.result to return a successful result instead of throwing the error.
4f38092 to
27fbad7
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Add a new plugin hook that fires when tool execution throws an error, allowing plugins to log, modify, or recover from errors.
Fixes #10027
What Changed
Added
tool.execute.errorhook to the plugin system. The hook receives:input: tool name, session ID, call ID, and argsoutput: mutable object witherrorand optionalresultPlugins can either modify the error or provide a fallback result.
Example Usage
How I Verified