compressHistory() {
        const compressedStack = [];
        let currentGroup = null;

        for (const command of this.undoStack) {
            if (currentGroup && currentGroup.canMerge(command)) {
                currentGroup = currentGroup.merge(command);
            } else {
                if (currentGroup) compressedStack.push(currentGroup);
                currentGroup = command;
            }
        }

        if (currentGroup) compressedStack.push(currentGroup);
        this.undoStack = compressedStack;
    }
Compresses the undo history by merging compatible commands.

@description
This method goes through the undo stack and attempts to merge adjacent commands
that are compatible (as determined by their canMerge method). This can help reduce
memory usage and simplify the undo/redo history.

@example
undoRedoManager.compressHistory();