@@ -8,15 +8,14 @@ export * as WriteTool from "./write"
88
99import type { Context as PluginContext } from "@opencode-ai/plugin/effect/plugin"
1010import { ToolFailure } from "@opencode-ai/ai"
11- import { FileDiff } from "@opencode-ai/schema/file-diff"
1211import { Effect , Schema } from "effect"
13- import { createTwoFilesPatch , diffLines } from "diff"
1412import { Bom } from "@opencode-ai/util/bom"
1513import { FSUtil } from "@opencode-ai/util/fs-util"
1614import { FileMutation } from "../../file-mutation"
1715import { Formatter } from "../../formatter"
1816import { LocationMutation } from "../../location-mutation"
1917import { Permission } from "../../permission"
18+ import { fileDiff } from "./file-diff"
2019
2120export const name = "write"
2221
@@ -83,19 +82,12 @@ export const Plugin = {
8382 Effect . catchReason ( "PlatformError" , "NotFound" , ( ) => Effect . succeed ( undefined ) ) ,
8483 )
8584 const next = Bom . split ( input . content )
86- const counts = diffLines ( current ?. text ?? "" , next . text ) . reduce (
87- ( result , item ) => ( {
88- additions : result . additions + ( item . added ? ( item . count ?? 0 ) : 0 ) ,
89- deletions : result . deletions + ( item . removed ? ( item . count ?? 0 ) : 0 ) ,
90- } ) ,
91- { additions : 0 , deletions : 0 } ,
85+ const preview = fileDiff (
86+ target . resource ,
87+ current ?. text ?? "" ,
88+ next . text ,
89+ current ? "modified" : "added" ,
9290 )
93- const preview : typeof FileDiff . Info . Type = {
94- file : target . resource ,
95- patch : createTwoFilesPatch ( target . resource , target . resource , current ?. text ?? "" , next . text ) ,
96- status : current ? "modified" : "added" ,
97- ...counts ,
98- }
9991 yield * permission . assert ( {
10092 action : "edit" ,
10193 resources : [ target . resource ] ,
0 commit comments