diff --git a/packages/core/src/tool/plugin/edit.ts b/packages/core/src/tool/plugin/edit.ts index e0f629bda43..8f711689fa8 100644 --- a/packages/core/src/tool/plugin/edit.ts +++ b/packages/core/src/tool/plugin/edit.ts @@ -8,7 +8,6 @@ export * as EditTool from "./edit.js" import type { Context } from "@opencode/plugin/effect/plugin" import { ToolFailure } from "@opencode/ai/effect" -import { FileDiff } from "@opencode/schema/file-diff" import { Effect, Schema } from "effect" import { toolFailure } from "../runtime.js" import { Environment } from "../../environment/index.js" @@ -33,10 +32,7 @@ export const Input = Schema.Struct({ }), }) -export const Output = Schema.Struct({ - files: Schema.Array(FileDiff.Info), - replacements: Schema.Number, -}) +export const Output = Schema.String export type Output = typeof Output.Type const crlf = "\r\n" @@ -348,16 +344,11 @@ export const Plugin = { const formatted = result.formatted ?? (yield* FileMutation.readText(environment.files, target.absolute)).text return { - files: [fileDiff(result.resource, source, formatted)], - replacements, - } satisfies Output + output: `Edited ${result.resource} (${replacements} replacement${replacements === 1 ? "" : "s"})`, + metadata: { files: [fileDiff(result.resource, source, formatted)] }, + } }).pipe( fileMutation.withLock([FileAccess.resolvePath(location.directory, input.path)]), - Effect.map((output) => ({ - output, - content: `Edited ${output.files[0]?.file} (${output.replacements} replacement${output.replacements === 1 ? "" : "s"})`, - metadata: { files: output.files }, - })), Effect.mapError(toolFailure(`Unable to edit ${input.path}`)), ) }, diff --git a/packages/core/test/tool-edit.test.ts b/packages/core/test/tool-edit.test.ts index 94df3fb25a3..4a9a94a7adc 100644 --- a/packages/core/test/tool-edit.test.ts +++ b/packages/core/test/tool-edit.test.ts @@ -125,7 +125,10 @@ describe("EditTool", () => { Effect.andThen( withTool(tmp.path, edit, (registry) => Effect.gen(function* () { - expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toEqual(["edit", "execute"]) + expect(yield* toolDefinitions(registry)).toMatchObject([ + { name: "edit", outputSchema: { type: "string" } }, + { name: "execute" }, + ]) expect( (yield* toolDefinitions(registry, [{ action: "edit", resource: "*", effect: "deny" }])).map( (tool) => tool.name, @@ -143,12 +146,8 @@ describe("EditTool", () => { text: "Edited hello.txt (1 replacement)", }, ]) - // Compact UI metadata carries the file diffs the TUI renders. + expect(settled.output).toBe("Edited hello.txt (1 replacement)") expect(settled.metadata).toMatchObject({ - files: [{ file: "hello.txt", status: "modified", additions: 1, deletions: 1 }], - }) - expect(settled.output).toEqual({ - replacements: 1, files: [ { file: "hello.txt", @@ -201,7 +200,6 @@ describe("EditTool", () => { ) expect(settled.status).toBe("completed") if (settled.status !== "completed") return - expect(settled.output.files[0]?.patch).toContain("-before\n+AFTER") expect(settled.metadata?.files?.[0]?.patch).toContain("-before\n+AFTER") expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("AFTER\n") }), @@ -524,7 +522,7 @@ describe("EditTool", () => { Effect.gen(function* () { expect(settled.status).toBe("completed") if (settled.status !== "completed") return - expect(settled.output).toMatchObject({ replacements: 3 }) + expect(settled.output).toBe("Edited all.txt (3 replacements)") expect(settled.content).toEqual([{ type: "text", text: "Edited all.txt (3 replacements)" }]) expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("after after after") expect(edit.writes).toHaveLength(1) @@ -601,7 +599,7 @@ describe("EditTool", () => { registry, call({ path: "overlap.txt", oldString: "a\na", newString: "x", replaceAll: true }), ) - expect(replaced).toMatchObject({ status: "completed", output: { replacements: 1 } }) + expect(replaced).toMatchObject({ status: "completed", output: "Edited overlap.txt (1 replacement)" }) yield* executeTool(registry, call({ path: "windows.txt", oldString: "a\nb", newString: "x" })) }), ), @@ -739,7 +737,7 @@ describe("EditTool", () => { Effect.gen(function* () { expect( yield* executeTool(registry, call({ path: "strip.sh", oldString: "\r", newString: "", replaceAll: true })), - ).toMatchObject({ status: "completed", output: { replacements: 2 } }) + ).toMatchObject({ status: "completed", output: "Edited strip.sh (2 replacements)" }) expect( yield* executeTool(registry, call({ path: "whole.sh", oldString: "x\r\ny\r\n", newString: "x\ny\n" })), ).toMatchObject({ status: "completed" }) @@ -841,7 +839,7 @@ describe("EditTool", () => { ), Effect.andThen((result) => Effect.gen(function* () { - expect(result).toMatchObject({ status: "completed", output: { replacements: 1 } }) + expect(result).toMatchObject({ status: "completed", output: "Edited concurrent.txt (1 replacement)" }) expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("after\n") expect(edit.writes).toEqual([target]) }),