It wouldn't be complicated, all you'd need would be a virtual unit datatype that is spawned when a unit leaves detection*, moves at a constant velocity and is destroyed after a set amount of time, redirect all attack orders from there and redirect them again if a new detection happens* wihin a range that depends on the unit's max speed.
*= A potential problem may be detecting such an event. If not present yet maybe a flag that tells whether a unit was detected by a player the last frame and if it changes that creates an event chcked by all virtual units nearby?
how difficult would it be have an external program that could give a specific set of build instructions to a selected unit? like, select a bot and then inject with directions to build a grid of windmills?
About as difficult as adding a groupAI that does the same?