From a0b1e49113470061d1581560c3e44c79a056d92a Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 13:32:59 +0800 Subject: [PATCH] agy-cli 0.1.13: an image before a live tool_result counts as the user steering (klarkxy #965) An image the user sends with no text before a live tool_result now marks the turn as steered, so it is replayed and the image stays off the MCP result. Reviewed head 7852e288 (on c27ba5f7), landed onto main 7869318d with the version moved to 0.1.13 (0.1.7 was taken by the time it landed). Run at the reviewed head: WSL2 bun test packages/agy-cli 8 of 8, check.mjs ok; Windows 7 pass, 1 fail, the same smoke red as main (#973). Broken by hand: without `userSteered = true` in inspectToolTurn's image branch, the new compat test goes red (11 pass, 1 fail) and smoke.mjs exits 1. Run at this commit (WSL2 Ubuntu 24.04, Bun 1.4.2, temp HOME): bun test packages/agy-cli 8 of 8 pass; bun scripts/check.mjs agy-cli ok. Not tried: macOS (mote refused ssh), a real agy. Closes #965 Co-authored-by: klarkxy --- packages/agy-cli/index.mjs | 6 +++- packages/agy-cli/package.json | 2 +- packages/agy-cli/test/compat.mjs | 30 ++++++++++++++++++++ packages/agy-cli/test/smoke.mjs | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index dd58004..69af664 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -3497,7 +3497,11 @@ function inspectToolTurn(results, body) { } if (block?.type === "image") { if (!seenResult) { - throw new UnsupportedContent("text beside a live tool_result; send it after the tool response completes") + // Same replay path as ordinary text before a live tool_result. + // Keep the image on the request body so the new prompt can carry it; + // never splice it into an MCP function response that has no result yet. + userSteered = true + continue } out = appendResultPart(out, resultIndex, parseUserImage(block)) continue diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index ff10136..fa194d6 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.12", + "version": "0.1.13", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/compat.mjs b/packages/agy-cli/test/compat.mjs index d58671a..7c13da8 100644 --- a/packages/agy-cli/test/compat.mjs +++ b/packages/agy-cli/test/compat.mjs @@ -62,6 +62,36 @@ test("ordinary user text beside live tool results steers a replay without becomi } }) +test("text plus an image before a live tool_result steers a replay and keeps the image off the MCP result", () => { + const call = result("call_read", "Read", "file contents") + const instruction = { type: "text", text: "look at this" } + const body = bodyFor([instruction, image, call.block]) + const inspected = inspectToolTurn([call], body) + assert.equal(inspected.userSteered, true) + assert.deepEqual(inspected.results[0].result.content, call.result.content, + "images before a result must not be spliced into the MCP function response") + const parts = renderInitialPromptParts(body, null, true) + const replay = parts.map(part => part.text || "").join("") + assert.ok(replay.includes("look at this")) + assert.ok(replay.includes("file contents")) + assert.ok(parts.some(part => part.type === "image" && part.data === image.source.data), + "the replay must carry the original image bytes") +}) + +test("an image alone before a live tool_result steers a replay and keeps the image off the MCP result", () => { + const call = result("call_read", "Read", "file contents") + const body = bodyFor([image, call.block]) + const inspected = inspectToolTurn([call], body) + assert.equal(inspected.userSteered, true, "an image with no preceding text must still set userSteered") + assert.deepEqual(inspected.results[0].result.content, call.result.content, + "images before a result must not be spliced into the MCP function response") + const parts = renderInitialPromptParts(body, null, true) + assert.ok(parts.some(part => part.type === "image" && part.data === image.source.data), + "the replay must carry the original image bytes") + assert.ok(parts.map(part => part.text || "").join("").includes("file contents"), + "the replay must retain the real tool result") +}) + test("a partial ID rename maps by full history without discarding the live ID anchor", () => { const original = [ { type: "tool_use", id: "original_a", name: "Read", input: { path: "a" } }, diff --git a/packages/agy-cli/test/smoke.mjs b/packages/agy-cli/test/smoke.mjs index c4f8f29..5370434 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -2055,6 +2055,54 @@ for (const location of ["inline", "system", "developer", "user"]) { `status=${mixedResponse.status}`) } + // Text plus an image before a live tool_result must also replay (not 400). + { + const imgFirst = { model, messages: [{ role: "user", content: "ESCCALL mixed image before result" }], tools: [echoTool] } + const imgEvents = (await readSSE(await callFetch(imgFirst))).events + const imgOld = inits().at(-1).convId + const imgSecond = continuation(imgFirst, imgEvents, "MIXED_IMAGE_RESULT") + const resultBlock = imgSecond.messages.at(-1).content[0] + imgSecond.messages.at(-1).content = [ + { type: "text", text: "look at this" }, + { type: "image", source: { type: "base64", media_type: "image/png", data: "cmVwbGF5aW1hZ2U=" } }, + resultBlock, + ] + const imgRes = await callFetch(imgSecond) + const imgFinal = imgRes.status === 200 ? (await readSSE(imgRes)).events : [] + if (imgRes.status !== 200) await imgRes.text() + const imgReplay = lastOf("user") + check("text plus an image before a live tool_result is replayed as a user prompt", + imgRes.status === 200 && stopOf(imgFinal) === "end_turn" && + imgReplay.convId !== imgOld && + imgReplay.text.includes("look at this") && + imgReplay.text.includes("MIXED_IMAGE_RESULT") && + imgReplay.content.some(part => part.type === "image" && part.data === "cmVwbGF5aW1hZ2U="), + `status=${imgRes.status}`) + } + + // An image with no text before a live tool_result must also set userSteered. + { + const imgFirst = { model, messages: [{ role: "user", content: "ESCCALL image only before result" }], tools: [echoTool] } + const imgEvents = (await readSSE(await callFetch(imgFirst))).events + const imgOld = inits().at(-1).convId + const imgSecond = continuation(imgFirst, imgEvents, "ONLY_IMAGE_RESULT") + const resultBlock = imgSecond.messages.at(-1).content[0] + imgSecond.messages.at(-1).content = [ + { type: "image", source: { type: "base64", media_type: "image/png", data: "b25seWltYWdl" } }, + resultBlock, + ] + const imgRes = await callFetch(imgSecond) + const imgFinal = imgRes.status === 200 ? (await readSSE(imgRes)).events : [] + if (imgRes.status !== 200) await imgRes.text() + const imgReplay = lastOf("user") + check("an image alone before a live tool_result is replayed as a user prompt", + imgRes.status === 200 && stopOf(imgFinal) === "end_turn" && + imgReplay.convId !== imgOld && + imgReplay.text.includes("ONLY_IMAGE_RESULT") && + imgReplay.content.some(part => part.type === "image" && part.data === "b25seWltYWdl"), + `status=${imgRes.status}`) + } + // User rejects tool call in TUI and enters a new prompt merged into the same user message by Claude Code aLe(). const rFirst = { model, messages: [{ role: "user", content: "ESCCALL user rejected tool" }], tools: [echoTool] } const rEvents = (await readSSE(await callFetch(rFirst))).events