Skip to content

Commit 03df3ca

Browse files
committed
fix(acp): file changes show the patch of every diff in a tool call
acpToolCallDiffPatch returned on the first diff entry with patch text, so later entries in the same tool call were dropped from diffStr while structuredFileChanges still listed their files. Render every entry in order.
1 parent 8760d06 commit 03df3ca

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,45 @@ describe("acpToolCallDiffPatch", () => {
272272
"",
273273
].join("\n"),
274274
);
275+
assert.equal(
276+
acpToolCallDiffPatch([
277+
{
278+
type: "diff",
279+
changes: [{ operation: "modify", path: "/repo/a.ts" }],
280+
patch: {
281+
format: "git_patch",
282+
text: "diff --git a/repo/a.ts b/repo/a.ts\n@@ -1 +1 @@\n-a\n+A\n",
283+
},
284+
},
285+
{
286+
type: "diff",
287+
changes: [{ operation: "modify", path: "/repo/b.ts" }],
288+
patch: {
289+
format: "git_patch",
290+
text: "diff --git a/repo/b.ts b/repo/b.ts\n@@ -1 +1 @@\n-b\n+B\n",
291+
},
292+
},
293+
{ type: "diff", path: "/repo/c.ts", oldText: "c\n", newText: "C\n" },
294+
]),
295+
[
296+
"diff --git a/repo/a.ts b/repo/a.ts",
297+
"@@ -1 +1 @@",
298+
"-a",
299+
"+A",
300+
"",
301+
"diff --git a/repo/b.ts b/repo/b.ts",
302+
"@@ -1 +1 @@",
303+
"-b",
304+
"+B",
305+
"",
306+
"--- /repo/c.ts",
307+
"+++ /repo/c.ts",
308+
"@@ -1,1 +1,1 @@",
309+
"-c",
310+
"+C",
311+
"",
312+
].join("\n"),
313+
);
275314
});
276315
});
277316

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
908908
const diff = unknownRecord(entry);
909909
return diff?.type === "diff" ? [diff] : [];
910910
});
911-
for (const diff of diffs) {
911+
const patches = diffs.flatMap((diff) => {
912912
const patch = unknownRecord(diff.patch);
913913
if (typeof patch?.text === "string") {
914914
const change =
@@ -924,15 +924,15 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
924924
const before = change.operation === "add" ? "/dev/null" : JSON.stringify(`a/${oldPath}`);
925925
const after =
926926
change.operation === "delete" ? "/dev/null" : JSON.stringify(`b/${change.path}`);
927-
return `diff --git ${JSON.stringify(`a/${oldPath}`)} ${JSON.stringify(`b/${change.path}`)}\n--- ${before}\n+++ ${after}\n${patch.text.trimStart()}`;
927+
return [
928+
`diff --git ${JSON.stringify(`a/${oldPath}`)} ${JSON.stringify(`b/${change.path}`)}\n--- ${before}\n+++ ${after}\n${patch.text.trimStart()}`,
929+
];
928930
}
929-
return patch.text;
931+
return [patch.text];
930932
}
931-
}
932-
const v1Patches = diffs.flatMap((diff) => {
933933
if (typeof diff.path !== "string" || typeof diff.newText !== "string") return [];
934934
const oldText = typeof diff.oldText === "string" ? diff.oldText : undefined;
935-
const patch = structuredPatch(
935+
const structured = structuredPatch(
936936
oldText === undefined ? "/dev/null" : diff.path,
937937
diff.path,
938938
oldText ?? "",
@@ -944,9 +944,11 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
944944
maxEditLength: oldText && diff.newText ? ACP_V1_DIFF_MAX_EDITS : Number.POSITIVE_INFINITY,
945945
},
946946
);
947-
return patch === undefined || patch.hunks.length === 0 ? [] : [patch];
947+
return structured === undefined || structured.hunks.length === 0
948+
? []
949+
: [formatPatch(structured, FILE_HEADERS_ONLY)];
948950
});
949-
return v1Patches.length === 0 ? undefined : formatPatch(v1Patches, FILE_HEADERS_ONLY);
951+
return patches.length === 0 ? undefined : patches.join("\n");
950952
}
951953

952954
function pathFromToolCall(toolCall: AcpToolCallState): string | undefined {

0 commit comments

Comments
 (0)