From e2eff19a321b50e5f81eae711a8e6e3c3dc4f5bf Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 18 Apr 2026 13:02:29 -0400 Subject: [PATCH] refactor(tool): reuse edit entry schema in multiedit --- packages/opencode/src/tool/edit.ts | 8 ++++++-- packages/opencode/src/tool/multiedit.ts | 16 +++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.ts index 36feb3d414..b833c88fe2 100644 --- a/packages/opencode/src/tool/edit.ts +++ b/packages/opencode/src/tool/edit.ts @@ -31,8 +31,7 @@ function convertToLineEnding(text: string, ending: "\n" | "\r\n"): string { return text.replaceAll("\n", "\r\n") } -export const Parameters = Schema.Struct({ - filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }), +export const Entry = Schema.Struct({ oldString: Schema.String.annotate({ description: "The text to replace" }), newString: Schema.String.annotate({ description: "The text to replace it with (must be different from oldString)", @@ -42,6 +41,11 @@ export const Parameters = Schema.Struct({ }), }) +export const Parameters = Schema.Struct({ + filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }), + ...Entry.fields, +}) + export const EditTool = Tool.define( "edit", Effect.gen(function* () { diff --git a/packages/opencode/src/tool/multiedit.ts b/packages/opencode/src/tool/multiedit.ts index 3c0986fd55..c6df816462 100644 --- a/packages/opencode/src/tool/multiedit.ts +++ b/packages/opencode/src/tool/multiedit.ts @@ -1,6 +1,6 @@ import { Effect, Schema } from "effect" import * as Tool from "./tool" -import { EditTool } from "./edit" +import * as Edit from "./edit" import DESCRIPTION from "./multiedit.txt" import path from "path" import { Instance } from "../project/instance" @@ -8,24 +8,14 @@ import { Instance } from "../project/instance" export const Parameters = Schema.Struct({ filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }), edits: Schema.mutable( - Schema.Array( - Schema.Struct({ - oldString: Schema.String.annotate({ description: "The text to replace" }), - newString: Schema.String.annotate({ - description: "The text to replace it with (must be different from oldString)", - }), - replaceAll: Schema.optional(Schema.Boolean).annotate({ - description: "Replace all occurrences of oldString (default false)", - }), - }), - ), + Schema.Array(Edit.Entry), ).annotate({ description: "Array of edit operations to perform sequentially on the file" }), }) export const MultiEditTool = Tool.define( "multiedit", Effect.gen(function* () { - const editInfo = yield* EditTool + const editInfo = yield* Edit.EditTool const edit = yield* editInfo.init() return {