import "./chunk-KFQGP6VL.js";

// src/mcp/utils/glob-helper.ts
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;
}
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".next", ".nuxt", "__pycache__"]);
async function walkDir(dir, rootDir, excludeRegexes, files) {
  let entries;
  try {
    entries = await fs.readdir(dir, { withFileTypes: true });
  } catch {
    return;
  }
  for (const entry of entries) {
    const fullPath = path.join(dir, entry.name);
    const relativePath = path.relative(rootDir, fullPath).replaceAll("\\", "/");
    if (entry.isDirectory()) {
      if (SKIP_DIRS.has(entry.name)) continue;
      if (isExcluded(relativePath + "/", excludeRegexes)) continue;
      await walkDir(fullPath, rootDir, excludeRegexes, files);
    } 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, rootDir, excludeRegexes, files);
  return files;
}
export {
  globFiles
};
