xonecas.io
64875
Mc

mini-coder / commit 2c789b5

fix: normalize quoted home paths for file tools

xonecas2026-03-14 2c789b5b248dad17fe505bd03527d6fa2be76252 parent f48a636

2 files changed

src/agent/tools.test.ts+5−0
@@ -136,4 +136,9 @@ describe("resolvePath", () => {
136136 const { filePath } = resolvePath("/my/cwd", "foo/bar");
137137 expect(filePath).toBe("/my/cwd/foo/bar");
138138 });
139+
140+ test("normalizes quoted and padded path input", () => {
141+ const { filePath } = resolvePath("/my/cwd", ' "~/foo/bar" ');
142+ expect(filePath).toBe(join(homedir(), "foo/bar"));
143+ });
139144 });
src/tools/shared.ts+19−4
@@ -1,13 +1,28 @@
11 import { homedir } from "node:os";
22 import { join, relative } from "node:path";
33
4+function stripMatchingQuotes(value: string): string {
5+ if (value.length < 2) return value;
6+ const first = value[0];
7+ const last = value[value.length - 1];
8+ if ((first === '"' || first === "'") && first === last) {
9+ return value.slice(1, -1);
10+ }
11+ return value;
12+}
13+
14+function normalizePathInput(pathInput: string): string {
15+ return stripMatchingQuotes(pathInput.trim());
16+}
17+
418 export function resolvePath(cwdInput: string | undefined, pathInput: string) {
519 const cwd = cwdInput ?? process.cwd();
6- const expanded = pathInput.startsWith("~/")
7- ? join(homedir(), pathInput.slice(2))
8- : pathInput === "~"
20+ const normalizedInput = normalizePathInput(pathInput);
21+ const expanded = normalizedInput.startsWith("~/")
22+ ? join(homedir(), normalizedInput.slice(2))
23+ : normalizedInput === "~"
924 ? homedir()
10- : pathInput;
25+ : normalizedInput;
1126 const filePath = expanded.startsWith("/") ? expanded : join(cwd, expanded);
1227
1328 const relPath = relative(cwd, filePath);