summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwid4t <[email protected]>2026-01-11 10:46:53 +0700
committerGitHub <[email protected]>2026-01-10 21:46:53 -0600
commit44fa3d5392d1a4c4cda65395be309d5420ee17ed (patch)
tree76673b55fc6b937aa2a2d67c7c8b4a7f79d5ead6
parenta457828a67548288276f120de2fd5bf4e60baed9 (diff)
downloadopencode-44fa3d5392d1a4c4cda65395be309d5420ee17ed.tar.gz
opencode-44fa3d5392d1a4c4cda65395be309d5420ee17ed.zip
feat(acp): track file modified (#7723)
Co-authored-by: Aiden Cline <[email protected]>
-rw-r--r--packages/opencode/src/acp/agent.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/opencode/src/acp/agent.ts b/packages/opencode/src/acp/agent.ts
index 6d8a64b7d..ebd65bb26 100644
--- a/packages/opencode/src/acp/agent.ts
+++ b/packages/opencode/src/acp/agent.ts
@@ -30,6 +30,7 @@ import { Todo } from "@/session/todo"
import { z } from "zod"
import { LoadAPIKeyError } from "ai"
import type { OpencodeClient, SessionMessageResponse } from "@opencode-ai/sdk/v2"
+import { applyPatch } from "diff"
export namespace ACP {
const log = Log.create({ service: "acp-agent" })
@@ -105,6 +106,22 @@ export namespace ACP {
})
return
}
+ if (res.outcome.optionId !== "reject" && permission.permission == "edit") {
+ const metadata = permission.metadata || {}
+ const filepath = typeof metadata["filepath"] === "string" ? metadata["filepath"] : ""
+ const diff = typeof metadata["diff"] === "string" ? metadata["diff"] : ""
+
+ const content = await Bun.file(filepath).text()
+ const newContent = getNewContent(content, diff)
+
+ if (newContent) {
+ this.connection.writeTextFile({
+ sessionId: sessionId,
+ path: filepath,
+ content: newContent,
+ })
+ }
+ }
await this.config.sdk.permission.reply({
requestID: permission.id,
reply: res.outcome.optionId as "once" | "always" | "reject",
@@ -1095,4 +1112,13 @@ export namespace ACP {
}
}
}
+
+ function getNewContent(fileOriginal: string, unifiedDiff: string): string | undefined {
+ const result = applyPatch(fileOriginal, unifiedDiff)
+ if (result === false) {
+ log.error("Failed to apply unified diff (context mismatch)")
+ return undefined
+ }
+ return result
+ }
}