One possible coding of the automatic escort role:
All purely-civilian fleets in the system are sorted by total build+cargo cost. Sorting happens each time a fleet is created or destroyed, appears in or disappears from the system, arrives at a body or another fleet (move to, join - both count), or begins loading or unloading a cargo capable of being valued, or begins a move order. This is the list of "escortables". As you will appreciate, sorting will need to be reasonably efficient (but, honestly, modern code on non-crap hardware will have no issues).
All escortables are marked eligible or ineligible.
Escortables orbiting a body, even one with military protection, do not, for this reason alone, lose their eligibility. This is advisable for several reasons, of which one is the need not to yank escorts away from valuable fleets only temporarily docked and which will immediately thereafter venture back into dangerous space.
Instead, escortables lose their eligibility if they are docked at such a body or in the same place as such a fleet, and have no follow-up movement orders.
The list of escortables is not re-sorted when ships are added to or taken away from a fleet, but the presence of military ships within a fleet at the time of a re-sort marks it as ineligible until the next re-sort.
All fleets in the system with unfulfilled auto-escort missions are scanned each time the list of escortables is sorted. They are sorted by military power (the calculation of which is not specified here). In order from highest to lowest power, they scan the escortable list, weighting by travel time and escortable value, picking the escortable with highest weight.
(Calculation of opportunities to "swap jobs" is omitted here.)
What does travel time mean? Any escortable has a present position, an estimated time before it moves (possibly zero), and a calculable path of its next expected movement. The math problem here is to draw an intercept line from the present position of the potential escort, to the future position of the escortable fleet at some future time. I may be mistaken, but I think Aurora already knows how to do this(?). Time to intercept is calculated. If greater than the time that the next movement order completes, this escortable fleet is not a suitable target for escorting by this escort. If the calculated distance to intercept, or the distance to the next destination, is greater than some percentage of the escort's remaining fuel range, this potential escortable is likewise ignored.
Otherwise, intercept time acts as a reduction of the value of choosing this particular escortable.
A fleet actively escorting will stop doing so for one of several reasons:
The escortable leaves the system, or is destroyed.
The escortable arrives at a destination, and some other escortable has sufficiently higher weighted escort value (here also, a "swap jobs" code would be groovy).
The escortable now has one or more military ships included.
Or, for whatever other reason, it is removed from the list of escortables.
Any fleet with an auto-escort mission is marked as being in one or more of several states:
1. Currently escorting.
2. Moving to intercept next escortable.
3. Refueling, and so forth (auto-fuel, auto-supply, auto-sustain-self).
4. No eligible escortables.
5. No eligible escortables within range.
5. Unable to escort (lacking fuel, supplies, movement capability, missiles, etc.).
6. Unable to escort (needs repair, and cannot move to a repair yard).
Again, several of these states are non-exclusive.
Note that some of this code would be of great benefit to a fleet marked as a response force, looking for battles to auto-respond to. Or, if such code already exists, then it can be profitably generalised to auto-escort missions.