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 @@ -467,6 +467,27 @@ export namespace ACP {
await this.processMessage({ info: msg.info, parts: [part] })
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 @@ -536,7 +557,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 @@ -78,6 +78,7 @@ export namespace File {
"file.edited",
z.object({
file: z.string(),
sessionID: z.string().optional(),
}),
),
}
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 @@ -220,7 +220,7 @@ export const ApplyPatchTool = Tool.define("apply_patch", {

if (edited) {
await Format.file(edited)
Bus.publish(File.Event.Edited, { file: edited })
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 @@ -73,7 +73,7 @@ export const EditTool = Tool.define("edit", {
})
await Filesystem.write(filePath, params.newString)
await Format.file(filePath)
Bus.publish(File.Event.Edited, { file: filePath })
Bus.publish(File.Event.Edited, { file: filePath, sessionID: ctx.sessionID })
await Bus.publish(FileWatcher.Event.Updated, {
file: filePath,
event: existed ? "change" : "add",
Expand Down Expand Up @@ -109,7 +109,7 @@ export const EditTool = Tool.define("edit", {

await Filesystem.write(filePath, contentNew)
await Format.file(filePath)
Bus.publish(File.Event.Edited, { file: filePath })
Bus.publish(File.Event.Edited, { file: filePath, sessionID: ctx.sessionID })
await 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 @@ -44,7 +44,7 @@ export const WriteTool = Tool.define("write", {

await Filesystem.write(filepath, params.content)
await Format.file(filepath)
Bus.publish(File.Event.Edited, { file: filepath })
Bus.publish(File.Event.Edited, { file: filepath, sessionID: ctx.sessionID })
await 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 @@ -219,6 +219,7 @@ export type EventFileEdited = {
type: "file.edited"
properties: {
file: string
sessionID?: string
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7682,6 +7682,9 @@
"properties": {
"file": {
"type": "string"
},
"sessionID": {
"type": "string"
}
},
"required": ["file"]
Expand Down
Loading