See how this task was implemented in the browser extension:
AdguardTeam/AdguardBrowserExtension#1452
We should do this on the server-side to avoid messing with the old AdGuard versions that don't understand this type of rules automatically.
Please note, that if the ##^ cannot be converted automatically for some reasons, it should be considered invalid.