// tools/warp_grep/agent/parser.ts
function parseReadLines(linesStr) {
  const ranges = [];
  for (const rangeStr of linesStr.split(",")) {
    const trimmed = rangeStr.trim();
    if (!trimmed) continue;
    const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
    if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
      ranges.push([parts[0], parts[1]]);
    } else if (Number.isFinite(parts[0])) {
      ranges.push([parts[0], parts[0]]);
    }
  }
  if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
  if (ranges.length > 1) return { lines: ranges };
  return {};
}
function parseFinishFiles(filesStr) {
  const files = [];
  for (const line of filesStr.trim().split(/\s+/)) {
    const trimmed = line.trim();
    if (!trimmed) continue;
    const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
    const colonIdx = trimmed.indexOf(":", searchFrom);
    if (colonIdx === -1) {
      files.push({ path: trimmed, lines: "*" });
      continue;
    }
    const filePath = trimmed.slice(0, colonIdx);
    const rangesPart = trimmed.slice(colonIdx + 1);
    if (!rangesPart.trim() || rangesPart.trim() === "*") {
      files.push({ path: filePath, lines: "*" });
      continue;
    }
    const ranges = [];
    for (const rangeStr of rangesPart.split(",")) {
      const rt = rangeStr.trim();
      if (!rt) continue;
      const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
      if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
        ranges.push([parts[0], parts[1]]);
      } else if (Number.isFinite(parts[0])) {
        ranges.push([parts[0], parts[0]]);
      }
    }
    files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
  }
  return files;
}
function extractPathFromCommand(command) {
  const tokens = command.trim().split(/\s+/);
  const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
  return pathTokens[0] || ".";
}

export {
  parseReadLines,
  parseFinishFiles,
  extractPathFromCommand
};
//# sourceMappingURL=chunk-FBRNUWEB.js.map