Просмотр исходного кода

fix(acp): send partial completed tool updates (#34091)

Shoubhit Dash 2 месяцев назад
Родитель
Сommit
1de7368580
2 измененных файлов с 82 добавлено и 4 удалено
  1. 1 4
      packages/opencode/src/acp/tool.ts
  2. 81 0
      packages/opencode/test/acp/tool.test.ts

+ 1 - 4
packages/opencode/src/acp/tool.ts

@@ -192,11 +192,8 @@ export function completedToolUpdate(input: {
   return {
     toolCallId: input.toolCallId,
     status: "completed",
-    kind: toToolKind(input.toolName),
-    title: toolTitle(input.toolName, input.state.input, input.state.title),
-    locations: toLocations(input.toolName, input.state.input, input.cwd),
+    ...(input.state.title ? { title: input.state.title } : {}),
     content: completedToolContent(input.toolName, input.state),
-    rawInput: rawInput(input.toolName, input.state.input, input.cwd),
     rawOutput: completedToolRawOutput(input.state),
   }
 }

+ 81 - 0
packages/opencode/test/acp/tool.test.ts

@@ -2,9 +2,11 @@ import { resolve } from "path"
 import { describe, expect, test } from "bun:test"
 import {
   completedToolContent,
+  completedToolUpdate,
   completedToolRawOutput,
   extractImageAttachments,
   imageContents,
+  pendingToolCall,
   shellOutputSnapshot,
   toLocations,
   toToolKind,
@@ -111,6 +113,85 @@ describe("acp tool conversion", () => {
     ])
   })
 
+  test("sends completed tool calls as partial updates", () => {
+    expect(
+      pendingToolCall({
+        toolCallId: "tool-1",
+        toolName: "edit",
+        state: {
+          input: {
+            filePath: "/tmp/file.ts",
+            oldString: "before",
+            newString: "after",
+          },
+        },
+      }),
+    ).toMatchObject({
+      kind: "edit",
+      locations: [{ path: "/tmp/file.ts" }],
+      rawInput: {
+        filePath: "/tmp/file.ts",
+        oldString: "before",
+        newString: "after",
+      },
+    })
+
+    expect(
+      completedToolUpdate({
+        toolCallId: "tool-1",
+        toolName: "edit",
+        state: {
+          status: "completed",
+          input: {
+            filePath: "/tmp/file.ts",
+            oldString: "before",
+            newString: "after",
+          },
+          output: "Edit applied successfully.",
+        },
+      }),
+    ).toEqual({
+      toolCallId: "tool-1",
+      status: "completed",
+      content: [
+        {
+          type: "content",
+          content: { type: "text", text: "Edit applied successfully." },
+        },
+        {
+          type: "diff",
+          path: "/tmp/file.ts",
+          oldText: "before",
+          newText: "after",
+        },
+      ],
+      rawOutput: {
+        output: "Edit applied successfully.",
+      },
+    })
+
+    expect(
+      completedToolUpdate({
+        toolCallId: "tool-1",
+        toolName: "edit",
+        state: {
+          status: "completed",
+          input: {
+            filePath: "/tmp/file.ts",
+            oldString: "before",
+            newString: "after",
+          },
+          title: "file.ts",
+          output: "Edit applied successfully.",
+        },
+      }),
+    ).toMatchObject({
+      toolCallId: "tool-1",
+      status: "completed",
+      title: "file.ts",
+    })
+  })
+
   test("uses clean read display text for completed content", () => {
     const output = [
       "<path>/tmp/file.ts</path>",