Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tools/fs/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions tests/filesystem-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)", () => {
Expand Down