Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions packages/opencode/src/acp/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ export namespace ACP {
.then(async () => {
const directory = session.cwd

let diffContent: ToolCallContent | undefined
if (permission.permission === "edit") {
const metadata = permission.metadata || {}
const filepath = typeof metadata["filepath"] === "string" ? metadata["filepath"] : ""
const diff = typeof metadata["diff"] === "string" ? metadata["diff"] : ""
if (filepath && diff) {
const oldText = (await Filesystem.exists(filepath)) ? await Filesystem.readText(filepath) : ""
const newText = getNewContent(oldText, diff) ?? ""
diffContent = { type: "diff", path: filepath, oldText, newText }
}
}

const res = await this.connection
.requestPermission({
sessionId: permission.sessionID,
Expand All @@ -200,6 +212,7 @@ export namespace ACP {
rawInput: permission.metadata,
kind: toToolKind(permission.permission),
locations: toLocations(permission.permission, permission.metadata),
...(diffContent && { content: [diffContent] })
},
options: this.permissionOptions,
})
Expand Down Expand Up @@ -227,20 +240,12 @@ 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 Filesystem.exists(filepath)) ? await Filesystem.readText(filepath) : ""
const newContent = getNewContent(content, diff)

if (newContent) {
this.connection.writeTextFile({
sessionId: session.id,
path: filepath,
content: newContent,
})
}
if (res.outcome.optionId !== "reject" && diffContent?.type == "diff" && diffContent.newText) {
this.connection.writeTextFile({
sessionId: session.id,
path: diffContent.path,
content: diffContent.newText,
})
}

await this.sdk.permission.reply({
Expand Down
Loading