summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason Quense <[email protected]>2026-04-16 22:38:21 -0400
committerGitHub <[email protected]>2026-04-16 21:38:21 -0500
commit7b3bb9a76181c478553b9319b734354f988cdac3 (patch)
tree58aefcae2d5578de7251c8bcea68a3d8825c6228
parentdc38f22bd8fcb77347759069f7082d15d1c95f29 (diff)
downloadopencode-7b3bb9a76181c478553b9319b734354f988cdac3.tar.gz
opencode-7b3bb9a76181c478553b9319b734354f988cdac3.zip
fix: preserve plugin tool metadata in execute result (#22827)
Co-authored-by: jquense <[email protected]> Co-authored-by: Aiden Cline <[email protected]>
-rw-r--r--packages/opencode/src/tool/registry.ts9
-rw-r--r--packages/plugin/src/tool.ts4
2 files changed, 9 insertions, 4 deletions
diff --git a/packages/opencode/src/tool/registry.ts b/packages/opencode/src/tool/registry.ts
index a8ab4c27e..34e6b4e36 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 b568d0371..3105bf534 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<Args extends z.ZodRawShape>(input: {
description: string
args: Args
- execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
+ execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>
}) {
return input
}