@devries-cameron20 / t3code-1 / commits / ddd36a53a5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(acp): file changes show the patch of every diff in a tool call (#28631)

Abhishek B R committed Nov 4, 2026 at 05:15 UTC ddd36a53a59f24799a81f2b8e0a497ef81a4819a
2 files changed +87 -8
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+65
@@ -342,6 +342,71 @@ describe("acpToolCallDiffPatch", () => {
342 "",
343 ].join("\n"),
344 );
345 + assert.equal(
346 + acpToolCallDiffPatch([
347 + {
348 + type: "diff",
349 + changes: [{ operation: "modify", path: "/repo/a.ts" }],
350 + patch: {
351 + format: "git_patch",
352 + text: "diff --git a/repo/a.ts b/repo/a.ts\n@@ -1 +1 @@\n-a\n+A\n",
353 + },
354 + },
355 + {
356 + type: "diff",
357 + changes: [{ operation: "modify", path: "/repo/b.ts" }],
358 + patch: {
359 + format: "git_patch",
360 + text: "diff --git a/repo/b.ts b/repo/b.ts\n@@ -1 +1 @@\n-b\n+B\n",
361 + },
362 + },
363 + { type: "diff", path: "/repo/c.ts", oldText: "c\n", newText: "C\n" },
364 + ]),
365 + [
366 + "diff --git a/repo/a.ts b/repo/a.ts",
367 + "@@ -1 +1 @@",
368 + "-a",
369 + "+A",
370 + "",
371 + "diff --git a/repo/b.ts b/repo/b.ts",
372 + "@@ -1 +1 @@",
373 + "-b",
374 + "+B",
375 + "",
376 + 'diff --git "a//repo/c.ts" "b//repo/c.ts"',
377 + "--- /repo/c.ts",
378 + "+++ /repo/c.ts",
379 + "@@ -1,1 +1,1 @@",
380 + "-c",
381 + "+C",
382 + "",
383 + ].join("\n"),
384 + );
385 + assert.equal(
386 + acpToolCallDiffPatch([
387 + { type: "diff", path: "/repo/new.txt", oldText: null, newText: "hello\n" },
388 + {
389 + type: "diff",
390 + changes: [{ operation: "modify", path: "/repo/a.ts" }],
391 + patch: { format: "git_patch", text: "@@ -1 +1 @@\n-a\n+A\n" },
392 + },
393 + ]),
394 + [
395 + 'diff --git "a//repo/new.txt" "b//repo/new.txt"',
396 + "--- /dev/null",
397 + "+++ /repo/new.txt",
398 + "@@ -0,0 +1,1 @@",
399 + "+hello",
400 + "",
401 + 'diff --git "a//repo/a.ts" "b//repo/a.ts"',
402 + '--- "a//repo/a.ts"',
403 + '+++ "b//repo/a.ts"',
404 + "@@ -1 +1 @@",
405 + "-a",
406 + "+A",
407 + "",
408 + ].join("\n"),
409 + );
410 });
411 });
412
packages/provider-acp/src/server/adapter.ts
+22 -8
@@ -1095,7 +1095,7 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
1095 const diff = unknownRecord(entry);
1096 return diff?.type === "diff" ? [diff] : [];
1097 });
1098 - for (const diff of diffs) {
1098 + const patches = diffs.flatMap((diff): ReadonlyArray<{ text: string; path?: string }> => {
1099 const patch = unknownRecord(diff.patch);
1100 if (typeof patch?.text === "string") {
1101 const change =
@@ -1111,15 +1111,17 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
1111 const before = change.operation === "add" ? "/dev/null" : JSON.stringify(`a/${oldPath}`);
1112 const after =
1113 change.operation === "delete" ? "/dev/null" : JSON.stringify(`b/${change.path}`);
1114 - return `diff --git ${JSON.stringify(`a/${oldPath}`)} ${JSON.stringify(`b/${change.path}`)}\n--- ${before}\n+++ ${after}\n${patch.text.trimStart()}`;
1114 + return [
1115 + {
1116 + text: `diff --git ${JSON.stringify(`a/${oldPath}`)} ${JSON.stringify(`b/${change.path}`)}\n--- ${before}\n+++ ${after}\n${patch.text.trimStart()}`,
1117 + },
1118 + ];
1119 }
1116 - return patch.text;
1120 + return [{ text: patch.text }];
1121 }
1118 - }
1119 - const v1Patches = diffs.flatMap((diff) => {
1122 if (typeof diff.path !== "string" || typeof diff.newText !== "string") return [];
1123 const oldText = typeof diff.oldText === "string" ? diff.oldText : undefined;
1122 - const patch = structuredPatch(
1124 + const structured = structuredPatch(
1125 oldText === undefined ? "/dev/null" : diff.path,
1126 diff.path,
1127 oldText ?? "",
@@ -1131,9 +1133,21 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
1133 maxEditLength: oldText && diff.newText ? ACP_V1_DIFF_MAX_EDITS : Number.POSITIVE_INFINITY,
1134 },
1135 );
1134 - return patch === undefined || patch.hunks.length === 0 ? [] : [patch];
1136 + return structured === undefined || structured.hunks.length === 0
1137 + ? []
1138 + : [{ text: formatPatch(structured, FILE_HEADERS_ONLY), path: diff.path }];
1139 });
1136 - return v1Patches.length === 0 ? undefined : formatPatch(v1Patches, FILE_HEADERS_ONLY);
1140 + // Diff parsers split at Git headers once one exists, so every section then needs its own.
1141 + const hasGitHeader = patches.some(({ text }) => /^diff --git /m.test(text));
1142 + return patches.length === 0
1143 + ? undefined
1144 + : patches
1145 + .map(({ text, path }) =>
1146 + hasGitHeader && path !== undefined
1147 + ? `diff --git ${JSON.stringify(`a/${path}`)} ${JSON.stringify(`b/${path}`)}\n${text}`
1148 + : text,
1149 + )
1150 + .join("\n");
1151 }
1152
1153 function pathFromToolCall(toolCall: AcpToolCallState): string | undefined {