// src/cli/commands/trace-event-normalizer.ts
function normalizeTraceEvents(events) {
  const out = [];
  let currentIteration = 0;
  for (const raw of events) {
    const type = String(raw.type ?? "");
    const data = getEventData(raw);
    const explicitIteration = asNumber(raw.iteration) ?? asNumber(data.iteration);
    if (type === "iteration:start") {
      currentIteration = explicitIteration ?? Math.max(1, currentIteration + 1);
    }
    const iteration = explicitIteration ?? currentIteration;
    out.push({ raw, type, data, iteration });
  }
  return out;
}
function getEventData(event) {
  const data = event.data;
  if (data && typeof data === "object") {
    return data;
  }
  return {};
}
function asNumber(value) {
  if (typeof value === "number" && Number.isFinite(value)) {
    return value;
  }
  if (typeof value === "string") {
    const n = Number(value);
    if (Number.isFinite(n)) {
      return n;
    }
  }
  return void 0;
}

export { asNumber, getEventData, normalizeTraceEvents };
//# sourceMappingURL=trace-event-normalizer.js.map
//# sourceMappingURL=trace-event-normalizer.js.map