"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// tools/warp_grep/agent/parser.ts
var parser_exports = {};
__export(parser_exports, {
  extractPathFromCommand: () => extractPathFromCommand,
  parseFinishFiles: () => parseFinishFiles,
  parseReadLines: () => parseReadLines
});
module.exports = __toCommonJS(parser_exports);
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] || ".";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  extractPathFromCommand,
  parseFinishFiles,
  parseReadLines
});
//# sourceMappingURL=parser.cjs.map