• Ends the most recent console group started with startGroup(). Handles reference counting for deduplicated groups - only closes when last reference ends. Safe to call when no group is active (no-op).

    Returns void

    export function endGroup(): void {
    if (groupStack.length === 0) return;

    const top = groupStack.at(-1);
    if (!top) return;

    if (top.count > 1) {
    top.count--;
    return;
    }

    // This is the last reference for this group; close it if we opened it.
    if (top.opened) {
    try {
    console.groupEnd();
    } catch {
    // ignore
    }
    }

    groupStack.pop();
    }