Regarding detection: here's a video of how Omnia's Undo works, starting at the relevant part:
https://youtu.be/53RZq0y0edM?t=202
I realize this is proprietary work of somebody else, and I'm not asking Hans to straight up rip it off. This is just to give an idea of how one could approach the situation. I hope I'm not breaking forum rules. This is just interesting to me.
First it's a 5-band expander for each channel based on the existing dynamics; this translates into an expansion ratio. Then it's the expander thresholds based on peak detection at a fixed offset from the current peak of each band. This seems to be done before declipping, but multiband gain is applied afterward? (I don't know if that last part matters at all, just summarizing the video.)
Also I'm sure Hans knows all this already, having contributed to Undo.