diff --git a/src/tools/fs/glob.ts b/src/tools/fs/glob.ts index 7a730cfca..a0d9ad67b 100644 --- a/src/tools/fs/glob.ts +++ b/src/tools/fs/glob.ts @@ -51,7 +51,8 @@ export async function globFiles( } if (!e.isFile() && !e.isSymbolicLink()) continue; const rel = displayRel(ctx.rootDir, full); - if (!isMatch(rel)) continue; + const matchRel = displayRel(startAbs, full); + if (!isMatch(matchRel)) continue; let mtimeMs = 0; if (sortBy === "mtime") { try { diff --git a/tests/filesystem-tools.test.ts b/tests/filesystem-tools.test.ts index 29c941826..f6acf2120 100644 --- a/tests/filesystem-tools.test.ts +++ b/tests/filesystem-tools.test.ts @@ -1309,6 +1309,33 @@ describe("filesystem tools (built-in, sandbox-enforced)", () => { expect(lines.length).toBe(3); expect(lines[lines.length - 1]).toMatch(/3 more matches/); }); + + it("matches relative to a custom path base directory", async () => { + const out = await tools.dispatch("glob", JSON.stringify({ path: "src", pattern: "*.ts" })); + expect(out).toContain("src/index.ts"); + expect(out).not.toContain("(no matches)"); + }); + + it("matches relative to an absolute path argument", async () => { + const absDir = join(root, "absdir"); + await fs.mkdir(absDir, { recursive: true }); + await fs.writeFile(join(absDir, "testfile.ts"), "export const a = 1;"); + const out = await tools.dispatch("glob", JSON.stringify({ path: absDir, pattern: "*.ts" })); + expect(out).toContain("absdir/testfile.ts"); + expect(out).not.toContain("(no matches)"); + }); + + it("matches relative to dot path '.' and does not recurse unless requested", async () => { + await fs.writeFile(join(root, "top.ts"), "x"); + await fs.mkdir(join(root, "sub"), { recursive: true }); + await fs.writeFile(join(root, "sub", "a.ts"), "y"); + + const out = await tools.dispatch("glob", JSON.stringify({ path: ".", pattern: "*.ts" })); + const lines = out.split("\n").filter((l) => l.trim()); + expect(lines).toContain("top.ts"); + expect(lines).not.toContain("sub/a.ts"); + expect(lines).not.toContain("src/index.ts"); + }); }); describe("search_content — context lines (-A/-B/-C semantics)", () => {