From 7b3bb9a76181c478553b9319b734354f988cdac3 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Thu, 16 Apr 2026 22:38:21 -0400 Subject: [PATCH] fix: preserve plugin tool metadata in execute result (#22827) Co-authored-by: jquense Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> --- packages/opencode/src/tool/registry.ts | 9 ++++++--- packages/plugin/src/tool.ts | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/tool/registry.ts b/packages/opencode/src/tool/registry.ts index a8ab4c27ea..34e6b4e364 100644 --- a/packages/opencode/src/tool/registry.ts +++ b/packages/opencode/src/tool/registry.ts @@ -135,14 +135,17 @@ export const layer: Layer.Layer< worktree: ctx.worktree, } const result = yield* Effect.promise(() => def.execute(args as any, pluginCtx)) + const output = typeof result === "string" ? result : result.output + const metadata = typeof result === "string" ? {} : (result.metadata ?? {}) const info = yield* agent.get(toolCtx.agent) - const out = yield* truncate.output(result, {}, info) + const out = yield* truncate.output(output, {}, info) return { title: "", - output: out.truncated ? out.content : result, + output: out.truncated ? out.content : output, metadata: { + ...metadata, truncated: out.truncated, - outputPath: out.truncated ? out.outputPath : undefined, + ...(out.truncated && { outputPath: out.outputPath }), }, } }), diff --git a/packages/plugin/src/tool.ts b/packages/plugin/src/tool.ts index b568d03713..3105bf534b 100644 --- a/packages/plugin/src/tool.ts +++ b/packages/plugin/src/tool.ts @@ -27,10 +27,12 @@ type AskInput = { metadata: { [key: string]: any } } +export type ToolResult = string | { output: string; metadata?: { [key: string]: any } } + export function tool(input: { description: string args: Args - execute(args: z.infer>, context: ToolContext): Promise + execute(args: z.infer>, context: ToolContext): Promise }) { return input }