mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-13 03:58:14 +00:00
26 lines
637 B
TypeScript
26 lines
637 B
TypeScript
import { preWriteHook } from "./preHook"
|
|
import { postWriteHook } from "./postHook"
|
|
import fs from "fs"
|
|
|
|
// Wrap the write_file tool
|
|
export async function writeFileWithHooks(
|
|
filePath: string,
|
|
content: string,
|
|
intentId: string,
|
|
sessionId: string,
|
|
contributorModel: string,
|
|
) {
|
|
// PREHOOK: validate intent + scope
|
|
const intent = preWriteHook(filePath, intentId)
|
|
|
|
// backup old file for AST diff
|
|
if (fs.existsSync(filePath)) {
|
|
fs.copyFileSync(filePath, filePath + ".bak")
|
|
}
|
|
|
|
// ACTUAL WRITE
|
|
fs.writeFileSync(filePath, content, "utf-8")
|
|
|
|
// POSTHOOK: trace log
|
|
postWriteHook(filePath, intent, sessionId, contributorModel)
|
|
}
|