Here are a few comments:
There are at least a few ways that software does autofocus. None of them that I am aware of focus the way that you would do it manually. In other words, they don't adjust focus until it looks right and then stop.
One method is used by FocusMax (and possibly others). It works by sampling a number of focuser distances and compares it to the width of a star. It does this repeatedly to characterize the focuser's behavior with that optics. When it comes time to actually focus, the software actually determines focus by sampling an out of focus star. It uses the pre-computed characterization to move from that out of focus position, to correct focus.
Another method is used by SGP (and possibly others). It works by starting at an out of focus position, and then moves through focus, sampling the aggregate width of all the stars in the field periodically. After it's moved to a position out of focus on the other side, it computes where the ideal focus would be and then moves directly there.
As you may note, both of these schemes finish up by moving from an out-of-focus position, to a calculated best focus position. The methods vary, but they have that in common. Because of this, a focuser without good repeatability is next to useless for automatic focus (and I have tried it; it's not fun).
To answer the question about filters, there are two ways of dealing with them, and all of the software that I've used supports it. You have a choice of always focusing through the filter you are using, or you can always focus through the same filter (ie. the luminance filter) and then using a predetermined offset to apply to the filter you are going to use. To determine the offsets, you do a one-time operation where you do many focus runs through each filter to determine the number of focus counts that each uses. From that, you can do simple subtraction from whichever filter you want to use as the reference. Again, without repeatability, this doesn't work.
Finally, I strongly suggest that you get really good at manual focus, so that it's second nature, before trying to automate it to work when you are not there. I give the same advice for automating any part of imaging.
I hope that this helps to fill in the explanation.