ask instead of throwing tool error if file is outside cwd

This commit is contained in:
Aiden Cline
2025-11-05 16:09:36 -06:00
parent c59ec71918
commit d425723249
4 changed files with 53 additions and 4 deletions

View File

@@ -20,7 +20,19 @@ export const WriteTool = Tool.define("write", {
async execute(params, ctx) {
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
if (!Filesystem.contains(Instance.directory, filepath)) {
throw new Error(`File ${filepath} is not in the current working directory`)
const parentDir = path.dirname(filepath)
await Permission.ask({
type: "external-directory",
pattern: parentDir,
sessionID: ctx.sessionID,
messageID: ctx.messageID,
callID: ctx.callID,
title: `Write file outside working directory: ${filepath}`,
metadata: {
filepath,
parentDir,
},
})
}
const file = Bun.file(filepath)