From dfcacfebd9e97283aeb6268efb1b68e7000e892f Mon Sep 17 00:00:00 2001 From: Filip <34747899+neriousy@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:27:07 +0000 Subject: [PATCH] fix(acp): complete edits whose patch header cannot be parsed --- packages/cli/src/acp/permission.ts | 2 +- packages/cli/test/acp/prompt.test.ts | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/acp/permission.ts b/packages/cli/src/acp/permission.ts index 4c33430ad3e..4dfcce4c56c 100644 --- a/packages/cli/src/acp/permission.ts +++ b/packages/cli/src/acp/permission.ts @@ -94,7 +94,7 @@ export const withCompletedDiffs = Effect.fnUntraced(function* ( const path = absolutePath(file.file, cwd) const newText = file.status === "deleted" ? "" : yield* Effect.tryPromise(() => Bun.file(path).text()) if (file.status === "added") return [diff(path, null, newText)] - const recorded = parsePatch(file.patch)[0] + const recorded = (yield* Effect.try(() => parsePatch(file.patch)))[0] if (!recorded) return [] const oldText = yield* Effect.try(() => applyPatch(newText, reversePatch(recorded))) if (oldText !== false) return [diff(path, oldText, newText)] diff --git a/packages/cli/test/acp/prompt.test.ts b/packages/cli/test/acp/prompt.test.ts index 85e65511a31..fa74fe7e506 100644 --- a/packages/cli/test/acp/prompt.test.ts +++ b/packages/cli/test/acp/prompt.test.ts @@ -251,6 +251,35 @@ describe("acp prompt turns over the wire", () => { }) }) + // Windows file names cannot contain a newline. + const testOutsideWindows = process.platform === "win32" ? test.skip : test + testOutsideWindows("completes an edit whose file name breaks the patch header", async () => { + await using dir = await tmpdir() + const name = "notes.txt\nx" + await Bun.write(path.resolve(dir.path, name), "world\n") + await using acp = await startWire({ + onPrompt: ({ sessionID, id }) => + turn( + sessionID, + id, + toolStarted(sessionID, "call_edit", "edit"), + toolCalled(sessionID, "call_edit", { path: name, oldString: "hello", newString: "world" }), + toolSucceeded(sessionID, "call_edit", { files: [fileDiff(name, "hello\n", "world\n")] }, "edited"), + ), + }) + await acp.initialize() + const session = await acp.newSession(dir.path) + + const result = await acp.prompt(session.sessionId, "edit the file") + + expect(result.stopReason).toBe("end_turn") + expect( + turnUpdates(acp.updates).find( + (item) => item.update.sessionUpdate === "tool_call_update" && item.update.status === "completed", + )?.update, + ).toMatchObject({ content: [{ type: "content", content: { type: "text", text: "edited" } }] }) + }) + test("routes slash commands and compact through their session endpoints", async () => { await using acp = await startWire() acp.server.catalog.commands = [reviewCommand, { name: "compact", description: "Server compact" }]