summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-10-28 14:08:10 -0400
committerDax Raad <[email protected]>2025-10-28 14:08:10 -0400
commitc1515316f54f129aa7f504d1cee79476c194c797 (patch)
treeed69904a9f5cb410501e855ec8a10ab09079be6e
parentb66e7b6fce07ff9a225dd225fc198b16718a1239 (diff)
downloadopencode-c1515316f54f129aa7f504d1cee79476c194c797.tar.gz
opencode-c1515316f54f129aa7f504d1cee79476c194c797.zip
core: fix additions and deletions counting in edit tool filediff
-rw-r--r--packages/opencode/src/tool/edit.ts16
1 files changed, 15 insertions, 1 deletions
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.ts
index a8e6fc3b6..7429c44b8 100644
--- a/packages/opencode/src/tool/edit.ts
+++ b/packages/opencode/src/tool/edit.ts
@@ -7,7 +7,7 @@ import z from "zod"
import * as path from "path"
import { Tool } from "./tool"
import { LSP } from "../lsp"
-import { createTwoFilesPatch } from "diff"
+import { createTwoFilesPatch, diffLines } from "diff"
import { Permission } from "../permission"
import DESCRIPTION from "./edit.txt"
import { File } from "../file"
@@ -16,6 +16,7 @@ import { FileTime } from "../file/time"
import { Filesystem } from "../util/filesystem"
import { Instance } from "../project/instance"
import { Agent } from "../agent/agent"
+import { Snapshot } from "@/snapshot"
export const EditTool = Tool.define("edit", {
description: DESCRIPTION,
@@ -114,10 +115,23 @@ export const EditTool = Tool.define("edit", {
}
}
+ const filediff: Snapshot.FileDiff = {
+ file: filePath,
+ before: contentOld,
+ after: contentNew,
+ additions: 0,
+ deletions: 0,
+ }
+ for (const change of diffLines(contentOld, contentNew)) {
+ if (change.added) filediff.additions += change.count || 0
+ if (change.removed) filediff.deletions += change.count || 0
+ }
+
return {
metadata: {
diagnostics,
diff,
+ filediff,
},
title: `${path.relative(Instance.worktree, filePath)}`,
output,