// src/actions/dead/findWorkspaceFile.ts
import fs from "node:fs";
import path from "node:path";
function findCodeWorkspaceFile(startDir) {
  let dir = path.resolve(startDir);
  while (true) {
    let entries;
    try {
      entries = fs.readdirSync(dir);
    } catch {
      entries = [];
    }
    const candidates = entries.filter((name) => name.endsWith(".code-workspace"));
    if (candidates.length > 0) {
      candidates.sort((a, b) => a.localeCompare(b));
      const [first, ...rest] = candidates;
      return {
        alternates: rest.length > 0 ? rest.map((name) => path.join(dir, name)) : void 0,
        path: path.join(dir, first)
      };
    }
    const parent = path.dirname(dir);
    if (parent === dir) return void 0;
    dir = parent;
  }
}
function resolveCodeWorkspaceFile(explicit, startDir) {
  if (explicit) {
    const absolute = path.isAbsolute(explicit) ? explicit : path.resolve(startDir, explicit);
    if (!fs.existsSync(absolute)) return void 0;
    return { path: absolute };
  }
  return findCodeWorkspaceFile(startDir);
}
export {
  findCodeWorkspaceFile,
  resolveCodeWorkspaceFile
};
//# sourceMappingURL=findWorkspaceFile.mjs.map
