more tools

This commit is contained in:
Dax Raad
2025-06-04 13:33:25 -04:00
parent 90d85e6393
commit fb88705bdc
7 changed files with 126 additions and 24 deletions

View File

@@ -0,0 +1,37 @@
import { z } from "zod"
import { Tool } from "./tool"
import { EditTool } from "./edit"
import DESCRIPTION from "./multiedit.txt"
export const MultiEditTool = Tool.define({
id: "opencode.multiedit",
description: DESCRIPTION,
parameters: z.object({
filePath: z.string().describe("The absolute path to the file to modify"),
edits: z
.array(EditTool.parameters)
.describe("Array of edit operations to perform sequentially on the file"),
}),
async execute(params, ctx) {
const results = []
for (const [, edit] of params.edits.entries()) {
const result = await EditTool.execute(
{
filePath: params.filePath,
oldString: edit.oldString,
newString: edit.newString,
replaceAll: edit.replaceAll,
},
ctx,
)
results.push(result)
}
return {
metadata: {
results: results.map((r) => r.metadata),
},
output: results.at(-1)!.output,
}
},
})