Skip to content

Commit fe35524

Browse files
authored
refactor(core): return the edit summary as a string (anomalyco#63635)
1 parent 2f8a867 commit fe35524

2 files changed

Lines changed: 13 additions & 24 deletions

File tree

‎packages/core/src/tool/plugin/edit.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export * as EditTool from "./edit.js"
88

99
import type { Context } from "@opencode/plugin/effect/plugin"
1010
import { ToolFailure } from "@opencode/ai/effect"
11-
import { FileDiff } from "@opencode/schema/file-diff"
1211
import { Effect, Schema } from "effect"
1312
import { toolFailure } from "../runtime.js"
1413
import { Environment } from "../../environment/index.js"
@@ -33,10 +32,7 @@ export const Input = Schema.Struct({
3332
}),
3433
})
3534

36-
export const Output = Schema.Struct({
37-
files: Schema.Array(FileDiff.Info),
38-
replacements: Schema.Number,
39-
})
35+
export const Output = Schema.String
4036
export type Output = typeof Output.Type
4137

4238
const crlf = "\r\n"
@@ -348,16 +344,11 @@ export const Plugin = {
348344
const formatted =
349345
result.formatted ?? (yield* FileMutation.readText(environment.files, target.absolute)).text
350346
return {
351-
files: [fileDiff(result.resource, source, formatted)],
352-
replacements,
353-
} satisfies Output
347+
output: `Edited ${result.resource} (${replacements} replacement${replacements === 1 ? "" : "s"})`,
348+
metadata: { files: [fileDiff(result.resource, source, formatted)] },
349+
}
354350
}).pipe(
355351
fileMutation.withLock([FileAccess.resolvePath(location.directory, input.path)]),
356-
Effect.map((output) => ({
357-
output,
358-
content: `Edited ${output.files[0]?.file} (${output.replacements} replacement${output.replacements === 1 ? "" : "s"})`,
359-
metadata: { files: output.files },
360-
})),
361352
Effect.mapError(toolFailure(`Unable to edit ${input.path}`)),
362353
)
363354
},

‎packages/core/test/tool-edit.test.ts‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ describe("EditTool", () => {
125125
Effect.andThen(
126126
withTool(tmp.path, edit, (registry) =>
127127
Effect.gen(function* () {
128-
expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toEqual(["edit", "execute"])
128+
expect(yield* toolDefinitions(registry)).toMatchObject([
129+
{ name: "edit", outputSchema: { type: "string" } },
130+
{ name: "execute" },
131+
])
129132
expect(
130133
(yield* toolDefinitions(registry, [{ action: "edit", resource: "*", effect: "deny" }])).map(
131134
(tool) => tool.name,
@@ -143,12 +146,8 @@ describe("EditTool", () => {
143146
text: "Edited hello.txt (1 replacement)",
144147
},
145148
])
146-
// Compact UI metadata carries the file diffs the TUI renders.
149+
expect(settled.output).toBe("Edited hello.txt (1 replacement)")
147150
expect(settled.metadata).toMatchObject({
148-
files: [{ file: "hello.txt", status: "modified", additions: 1, deletions: 1 }],
149-
})
150-
expect(settled.output).toEqual({
151-
replacements: 1,
152151
files: [
153152
{
154153
file: "hello.txt",
@@ -201,7 +200,6 @@ describe("EditTool", () => {
201200
)
202201
expect(settled.status).toBe("completed")
203202
if (settled.status !== "completed") return
204-
expect(settled.output.files[0]?.patch).toContain("-before\n+AFTER")
205203
expect(settled.metadata?.files?.[0]?.patch).toContain("-before\n+AFTER")
206204
expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("AFTER\n")
207205
}),
@@ -524,7 +522,7 @@ describe("EditTool", () => {
524522
Effect.gen(function* () {
525523
expect(settled.status).toBe("completed")
526524
if (settled.status !== "completed") return
527-
expect(settled.output).toMatchObject({ replacements: 3 })
525+
expect(settled.output).toBe("Edited all.txt (3 replacements)")
528526
expect(settled.content).toEqual([{ type: "text", text: "Edited all.txt (3 replacements)" }])
529527
expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("after after after")
530528
expect(edit.writes).toHaveLength(1)
@@ -601,7 +599,7 @@ describe("EditTool", () => {
601599
registry,
602600
call({ path: "overlap.txt", oldString: "a\na", newString: "x", replaceAll: true }),
603601
)
604-
expect(replaced).toMatchObject({ status: "completed", output: { replacements: 1 } })
602+
expect(replaced).toMatchObject({ status: "completed", output: "Edited overlap.txt (1 replacement)" })
605603
yield* executeTool(registry, call({ path: "windows.txt", oldString: "a\nb", newString: "x" }))
606604
}),
607605
),
@@ -739,7 +737,7 @@ describe("EditTool", () => {
739737
Effect.gen(function* () {
740738
expect(
741739
yield* executeTool(registry, call({ path: "strip.sh", oldString: "\r", newString: "", replaceAll: true })),
742-
).toMatchObject({ status: "completed", output: { replacements: 2 } })
740+
).toMatchObject({ status: "completed", output: "Edited strip.sh (2 replacements)" })
743741
expect(
744742
yield* executeTool(registry, call({ path: "whole.sh", oldString: "x\r\ny\r\n", newString: "x\ny\n" })),
745743
).toMatchObject({ status: "completed" })
@@ -841,7 +839,7 @@ describe("EditTool", () => {
841839
),
842840
Effect.andThen((result) =>
843841
Effect.gen(function* () {
844-
expect(result).toMatchObject({ status: "completed", output: { replacements: 1 } })
842+
expect(result).toMatchObject({ status: "completed", output: "Edited concurrent.txt (1 replacement)" })
845843
expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("after\n")
846844
expect(edit.writes).toEqual([target])
847845
}),

0 commit comments

Comments
 (0)