@@ -1,6 +1,7 @@
11 import { join, relative } from "node:path";
22 import { z } from "zod";
33 import type { ToolDef } from "../llm-api/types.ts";
4+import { loadGitignore } from "./ignore.ts";
45
56 const GlobSchema = z.object({
67 pattern: z
@@ -27,27 +28,26 @@ export const globTool: ToolDef<GlobInput, GlobOutput> = {
2728 schema: GlobSchema,
2829 execute: async (input) => {
2930 const cwd = input.cwd ?? process.cwd();
30- const defaultIgnore = [
31- "node_modules/**",
32- ".git/**",
33- "dist/**",
34- "*.db",
35- "*.db-shm",
36- "*.db-wal",
37- ];
31+ const defaultIgnore = [".git/**", "node_modules/**"];
3832 const ignorePatterns = [...defaultIgnore, ...(input.ignore ?? [])];
3933
34+ const ignoreGlobs = ignorePatterns.map((pat) => new Bun.Glob(pat));
35+
36+ const ig = await loadGitignore(cwd);
37+
4038 const glob = new Bun.Glob(input.pattern);
4139 const matches: Array<{ path: string; mtime: number }> = [];
4240
43- for await (const file of glob.scan({ cwd, onlyFiles: true })) {
44- // Check ignore patterns
45- const ignored = ignorePatterns.some((pat) => {
46- const ig = new Bun.Glob(pat);
47- return ig.match(file);
48- });
49- if (ignored) continue;
41+ for await (const file of glob.scan({ cwd, onlyFiles: true, dot: true })) {
42+ // Check if ignored by .gitignore
43+ if (ig?.ignores(file)) continue;
5044
45+ // Check explicit ignore patterns
46+ const firstSegment = file.split("/")[0] ?? "";
47+ const ignored = ignoreGlobs.some(
48+ (g) => g.match(file) || g.match(firstSegment),
49+ );
50+ if (ignored) continue;
5151 try {
5252 const fullPath = join(cwd, file);
5353 const stat = (await Bun.file(fullPath).stat?.()) ?? null;