import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);

// src/project-root.ts
import fs from "node:fs";
import path from "node:path";
function hasGitBoundary(directory) {
  const gitPath = path.join(directory, ".git");
  try {
    const stat = fs.statSync(gitPath);
    return stat.isDirectory() || stat.isFile();
  } catch {
    return false;
  }
}
function resolveCliProjectRoot(cwd) {
  const resolvedCwd = path.resolve(cwd || process.cwd());
  const filesystemRoot = path.parse(resolvedCwd).root;
  let current = resolvedCwd;
  while (true) {
    if (hasGitBoundary(current)) {
      return current;
    }
    if (current === filesystemRoot) {
      return resolvedCwd;
    }
    const parent = path.dirname(current);
    if (parent === current) {
      return resolvedCwd;
    }
    current = parent;
  }
}

export {
  resolveCliProjectRoot
};
