import {
  DEFAULT_SKIP_DIRS,
  init_dist
} from "./chunk-BMM3GXV6.js";
import "./chunk-KFQGP6VL.js";

// src/mcp/utils/glob-helper.ts
init_dist();
import * as fs from "fs/promises";
import * as path from "path";
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".go", ".py"]);
function globToRegex(pattern) {
  const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7\xA7").replace(/\*/g, "[^/]*").replace(/§§/g, ".*");
  return new RegExp(escaped);
}
function isExcluded(relativePath, excludeRegexes) {
  for (const regex of excludeRegexes) {
    if (regex.test(relativePath)) return true;
  }
  return false;
}
async function walkDir(rootDir, excludeRegexes, files) {
  const queue = [rootDir];
  while (queue.length > 0) {
    const dir = queue.pop();
    let entries;
    try {
      entries = await fs.readdir(dir, { withFileTypes: true });
    } catch {
      continue;
    }
    for (const entry of entries) {
      const fullPath = path.join(dir, entry.name);
      const relativePath = path.relative(rootDir, fullPath).replaceAll("\\", "/");
      if (entry.isDirectory()) {
        if (DEFAULT_SKIP_DIRS.has(entry.name)) continue;
        if (isExcluded(relativePath + "/", excludeRegexes)) continue;
        queue.push(fullPath);
      } else if (entry.isFile()) {
        const ext = path.extname(entry.name);
        if (!SOURCE_EXTENSIONS.has(ext)) continue;
        if (isExcluded(relativePath, excludeRegexes)) continue;
        files.push(fullPath);
      }
    }
  }
}
async function globFiles(rootDir, exclude) {
  const patterns = exclude ?? [
    "**/node_modules/**",
    "**/dist/**",
    "**/*.test.ts",
    "**/fixtures/**"
  ];
  const excludeRegexes = patterns.map(globToRegex);
  const files = [];
  await walkDir(rootDir, excludeRegexes, files);
  return files;
}
export {
  globFiles
};
