I did a search in my command viewer for a command and all I could find are UI ones which would require you make a selection first - one called uiRepairAtPointer(). There was also a command called uiRepairBuilding() which I am not sure how that works - maybe say as first command. Regarding positioning the pointer it is messy and difficult - in past done so with some clever camera cuts.
Regarding how the ai does it it seems to create a plan with the cPlanRepair constant. There might be a able to create a repair plan and execute it on the fly for a unit but I am not entirely sure how to do that. Some ai scripters might know how you would do this - probably require setting a blank ai on the player beforehand and appropriate context plyer set first.
[This message has been edited by nottud (edited 03-26-2021 @ 09:34 AM).]