fix: handle Git Bash path mapping on windows (#4380)

pull/4403/head
Keath Milligan 2025-11-17 01:06:44 -06:00 committed by GitHub
parent 10b3702938
commit f4d892d4e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 4 deletions

View File

@ -89,10 +89,18 @@ export const BashTool = Tool.define("bash", {
.text() .text()
.then((x) => x.trim()) .then((x) => x.trim())
log.info("resolved path", { arg, resolved }) log.info("resolved path", { arg, resolved })
if (resolved && !Filesystem.contains(Instance.directory, resolved)) { if (resolved) {
throw new Error( // Git Bash on Windows returns Unix-style paths like /c/Users/...
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`, const normalized =
) process.platform === "win32" && resolved.match(/^\/[a-z]\//)
? resolved.replace(/^\/([a-z])\//, (_, drive) => `${drive.toUpperCase()}:\\`).replace(/\//g, "\\")
: resolved
if (!Filesystem.contains(Instance.directory, normalized)) {
throw new Error(
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
)
}
} }
} }
} }