I'll look into this when I get time (three CTDs to look at and rework of path caching first though I'm afraid)
I changed the AI in C2C to react to lots of unit losses by prioritising XP buildings ahead of more units, but so far that's as far as changes in that area have gone. This is probably best addressed more from the not-making-stupid-attacks perspective than the not-building-units side I suspect.
As I noted in a previous post, the rogue line seems to be tagged with support for UNITAI_SPY, which causes it to sometimes be built for use as a spy. This might be the case here in which case it will do utterly dumb things (IMO) thinking it can behave as a spy would (which can cause attacks when it isn't really trying to attack).
I asked previously if anyone knew why this line had been given that AI type support, but go no response. I guess I should just remove it, since nobody has volunteered a reason why it is there...