Skip to content
Closed
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion packages/opencode/src/acp/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,27 @@ export namespace ACP {

return
}
case "file.edited":
const props = event.properties
const session = this.sessionManager.tryGet(props.sessionID)
if (!session) return
const sessionId = session.id

if (this.config.clientCapabilities?.fs?.writeTextFile) {
const filepath = event.properties.file
try {
const content = await Bun.file(filepath).text()
await this.connection.writeTextFile({
sessionId,
path: filepath,
content,
})
log.info("synced file edit to ACP client", { filepath, sessionId})
} catch (err) {
log.error("failed to sync file edit to ACP client", { error: err, filepath, sessionId })
}
}
break

case "message.part.delta": {
const props = event.properties
Expand Down Expand Up @@ -530,7 +551,9 @@ export namespace ACP {
}

async initialize(params: InitializeRequest): Promise<InitializeResponse> {
log.info("initialize", { protocolVersion: params.protocolVersion })
log.info("initialize", { protocolVersion: params.protocolVersion, clientCapabilities: params.clientCapabilities })

this.config.clientCapabilities = params.clientCapabilities

const authMethod: AuthMethod = {
description: "Run `opencode auth login` in the terminal",
Expand Down
3 changes: 2 additions & 1 deletion packages/opencode/src/acp/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { McpServer } from "@agentclientprotocol/sdk"
import type { McpServer, ClientCapabilities } from "@agentclientprotocol/sdk"
import type { OpencodeClient } from "@opencode-ai/sdk/v2"
import type { ProviderID, ModelID } from "../provider/schema"

Expand All @@ -21,4 +21,5 @@ export interface ACPConfig {
providerID: ProviderID
modelID: ModelID
}
clientCapabilities?: ClientCapabilities
}
1 change: 1 addition & 0 deletions packages/opencode/src/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export namespace File {
"file.edited",
z.object({
file: z.string(),
sessionID: z.string(),
}),
),
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/tool/apply_patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const ApplyPatchTool = Tool.define(

if (edited) {
yield* format.file(edited)
yield* bus.publish(File.Event.Edited, { file: edited })
yield* bus.publish(File.Event.Edited, { file: edited, sessionID: ctx.sessionID })
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/tool/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const EditTool = Tool.define(
})
yield* afs.writeWithDirs(filePath, params.newString)
yield* format.file(filePath)
yield* bus.publish(File.Event.Edited, { file: filePath })
yield* bus.publish(File.Event.Edited, { file: filePath, sessionID: ctx.sessionID })
yield* bus.publish(FileWatcher.Event.Updated, {
file: filePath,
event: existed ? "change" : "add",
Expand Down Expand Up @@ -129,7 +129,7 @@ export const EditTool = Tool.define(

yield* afs.writeWithDirs(filePath, contentNew)
yield* format.file(filePath)
yield* bus.publish(File.Event.Edited, { file: filePath })
yield* bus.publish(File.Event.Edited, { file: filePath, sessionID: ctx.sessionID })
yield* bus.publish(FileWatcher.Event.Updated, {
file: filePath,
event: "change",
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/tool/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const WriteTool = Tool.define(

yield* fs.writeWithDirs(filepath, params.content)
yield* format.file(filepath)
yield* bus.publish(File.Event.Edited, { file: filepath })
yield* bus.publish(File.Event.Edited, { file: filepath, sessionID: ctx.sessionID })
yield* bus.publish(FileWatcher.Event.Updated, {
file: filepath,
event: exists ? "change" : "add",
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/js/src/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export type EventFileEdited = {
type: "file.edited"
properties: {
file: string
sessionID?: string
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type EventFileEdited = {
type: "file.edited"
properties: {
file: string
sessionID: string
}
}

Expand Down
Loading