fix(acp): complete edits whose patch header cannot be parsed

This commit is contained in:
Filip
2026-11-05 21:27:07 +00:00
Unverified
parent 80bf7f7b0d
commit dfcacfebd9
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -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)]
+29
View File
@@ -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" }]