import {
  createGitForPath
} from "./chunk-2UFQ3A3C.js";

// ../core/dist/stamp-tracking.js
import path from "path";
function toPosixPath(value) {
  return value.split(path.sep).join("/");
}
function stampIdFromFilePath(filePath) {
  const normalized = filePath.replace(/\\/g, "/");
  const fileName = path.posix.basename(normalized);
  if (!fileName.startsWith("WU-") || !fileName.endsWith(".done")) {
    return null;
  }
  return fileName.slice(0, -".done".length);
}
async function listTrackedWUStampIds({ projectRoot, stampsDir, gitRaw }) {
  try {
    const raw = gitRaw ?? ((args) => createGitForPath(projectRoot).raw(args));
    const stampsDirRelative = path.isAbsolute(stampsDir) ? path.relative(projectRoot, stampsDir) : stampsDir;
    const pathspec = `${toPosixPath(stampsDirRelative)}/WU-*.done`;
    const output = await raw(["ls-files", "--", pathspec]);
    const tracked = /* @__PURE__ */ new Set();
    for (const line of output.split("\n")) {
      const value = line.trim();
      if (!value)
        continue;
      const id = stampIdFromFilePath(value);
      if (id)
        tracked.add(id);
    }
    return tracked;
  } catch {
    return null;
  }
}

export {
  listTrackedWUStampIds
};
