fix(opencode): show v2 patch edits as edit diffs (#5696)

OpenCode 2 reports GPT models' apply_patch tool calls under the name
patch. The OpenCode tool-call parser only recognized apply_patch, so
these calls fell through to an unknown tool card with the raw patch
text. Map patch payloads the same way as apply_patch.

Closes #5643

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
paseo-bot[bot]
2026-09-29 19:15:39 +02:00
committed by GitHub
parent 4b45bc9fc1
commit 5764863f63
2 changed files with 32 additions and 0 deletions
@@ -312,6 +312,10 @@ const OpencodeKnownToolDetailSchema = z.union([
z.unknown(),
(input) => toEditToolDetail(input, null),
),
// OpenCode v2 reports apply_patch as `patch`.
toolDetailBranchByToolName("patch", OpencodeApplyPatchTextInputSchema, z.unknown(), (input) =>
toEditToolDetail(input, null),
),
toolDetailBranchByToolName(
"apply_diff",
OpencodeEditInputSchema,
@@ -387,6 +387,34 @@ describe("opencode tool-call mapper", () => {
});
});
it("maps OpenCode v2 patch payloads from GPT models into edit detail", () => {
const item = expectMapped(
mapOpencodeToolCall({
toolName: "patch",
callId: "opencode-v2-patch-1",
status: "completed",
input: {
patchText:
"*** Begin Patch\n*** Update File: patch.txt\n@@\n-north south\n+NORTH south\n*** End Patch",
},
output: "Success. Updated the following files:\nM patch.txt",
}),
);
expect(item.detail).toEqual({
type: "edit",
filePath: "patch.txt",
unifiedDiff: [
"diff --git a/patch.txt b/patch.txt",
"--- a/patch.txt",
"+++ b/patch.txt",
"@@",
"-north south",
"+NORTH south",
].join("\n"),
});
});
it("maps unknown tools to unknown detail with raw payloads", () => {
const item = expectMapped(
mapOpencodeToolCall({