For the threat part, you've got something like this set up in your .system file, right?
"aiHints":{
"threatRange":600,
"threatAmount":4,
"threatAngle":0,
"threatArc":360,
}
(This is pasted from the EMP system.)
The "target" that's passed in here is the ship that the AI is currently engaging, as far as facing, maneuvering, etc. Like for a human, that can be different from what the ship actually has targeted, which is mostly relevant for missiles.
If a system does require a target - like the Interdictor Array - take a look at:
InterdictorArrayStats.findTarget()
Basically, it checks for a shiptarget first, then ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET), then some other stuff.
AIFlags.MANEUVER_TARGET is where the core AI stores the "currently engaging" target, i.e. the ship it's intending to fight, which is separate from a shiptarget.