```
/** A chart with its twin rows squashed together. */
export function squashRows(chart: Record<string, unknown>): Record<string, unknown> {
  const signals = chart.signals as string[];
  if (!signals || signals.length === 0) {
    throw new Error('Signals list is empty or contains no strings.');
  }
  if (new Set(signals).size !== signals.length) {
    throw new Error('Signal list contains duplicates.');
  }

  const rows = chart.rows as any[];
  if (!rows || rows.length === 0) {
    throw new Error('No rows provided.');
  }

  const groupOf = new Map<string, number>();
  const chosen: any[] = [];
  const seen = new Map<string, number>();

  for (const row of rows) {
    if (!row.label || typeof row.label !== 'string' || row.label.trim() === '') {
      throw new Error('Row label must be a non-empty string.');
    }
    if (!row.mark || typeof row.mark !== 'string' || row.mark.trim() === '') {
      throw new Error('Row mark must be a non-empty string.');
    }
    if (new Set(row.next).size !== row.next.length) {
      throw new Error('Next list must have no duplicate labels.');
    }

    const key = row.mark + "|" + row.next.join(",");
    if (!seen.has(key)) {
      seen.set(key, chosen.length);
      chosen.push(row);
    }
    groupOf.set(row.label, seen.get(key) as number);
  }

  const folded = chosen.map((row, at) => ({
    at,
    mark: row.mark,
    next: row.next.map((label: string) => groupOf.get(label)),
  }));

  return { entry: groupOf.get(chart.head as string), rows: folded };
}
```