From 2d6dac9dd54c7e116d5e6ef1a9990e239e04b800 Mon Sep 17 00:00:00 2001 From: Peter Denham Date: Mon, 23 Feb 2026 17:51:33 -0500 Subject: [PATCH] write.ts coerce JSON objects to strings --- packages/opencode/src/tool/write.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/tool/write.ts b/packages/opencode/src/tool/write.ts index 8c1e53ccaf3a..017838110947 100644 --- a/packages/opencode/src/tool/write.ts +++ b/packages/opencode/src/tool/write.ts @@ -19,7 +19,12 @@ const MAX_PROJECT_DIAGNOSTICS_FILES = 5 export const WriteTool = Tool.define("write", { description: DESCRIPTION, parameters: z.object({ - content: z.string().describe("The content to write to the file"), + content: z + .preprocess( + (v) => (typeof v === "object" && v !== null ? JSON.stringify(v, null, 2) : v), + z.string(), + ) + .describe("The content to write to the file"), filePath: z.string().describe("The absolute path to the file to write (must be absolute, not relative)"), }), async execute(params, ctx) {