add auto formatting and experimental hooks feature

This commit is contained in:
Dax Raad
2025-06-26 22:12:23 -04:00
parent a4f32d602b
commit f8b78f08b4
8 changed files with 269 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ import { createTwoFilesPatch } from "diff"
import { Permission } from "../permission"
import DESCRIPTION from "./edit.txt"
import { App } from "../app/app"
import { Format } from "../format"
export const EditTool = Tool.define({
id: "edit",
@@ -59,6 +60,7 @@ export const EditTool = Tool.define({
if (params.oldString === "") {
contentNew = params.newString
await Bun.write(filepath, params.newString)
await Format.run(filepath)
return
}
@@ -77,6 +79,7 @@ export const EditTool = Tool.define({
params.replaceAll,
)
await file.write(contentNew)
await Format.run(filepath)
})()
const diff = trimDiff(
@@ -473,7 +476,7 @@ export function replace(
if (oldString === newString) {
throw new Error("oldString and newString must be different")
}
for (const replacer of [
SimpleReplacer,
LineTrimmedReplacer,

View File

@@ -6,6 +6,7 @@ import { LSP } from "../lsp"
import { Permission } from "../permission"
import DESCRIPTION from "./write.txt"
import { App } from "../app/app"
import { Format } from "../format"
export const WriteTool = Tool.define({
id: "write",
@@ -42,6 +43,7 @@ export const WriteTool = Tool.define({
})
await Bun.write(filepath, params.content)
await Format.run(filepath)
FileTimes.read(ctx.sessionID, filepath)
let output = ""