Roo-Code/src/hooks/hookEngine.ts
2026-02-21 18:18:39 +03:00

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)
}