Skip to content

Commit f4d892d

Browse files
fix: handle Git Bash path mapping on windows (#4380)
1 parent 10b3702 commit f4d892d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/opencode/src/tool/bash.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ export const BashTool = Tool.define("bash", {
8989
.text()
9090
.then((x) => x.trim())
9191
log.info("resolved path", { arg, resolved })
92-
if (resolved && !Filesystem.contains(Instance.directory, resolved)) {
93-
throw new Error(
94-
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
95-
)
92+
if (resolved) {
93+
// Git Bash on Windows returns Unix-style paths like /c/Users/...
94+
const normalized =
95+
process.platform === "win32" && resolved.match(/^\/[a-z]\//)
96+
? resolved.replace(/^\/([a-z])\//, (_, drive) => `${drive.toUpperCase()}:\\`).replace(/\//g, "\\")
97+
: resolved
98+
99+
if (!Filesystem.contains(Instance.directory, normalized)) {
100+
throw new Error(
101+
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
102+
)
103+
}
96104
}
97105
}
98106
}

0 commit comments

Comments
 (0)