I would guess that it won't work well. KStars autofocus depends on detecting "stars" and minimizing their size. It is not using contrast-detection (nor phase detection). Best to auto-focus on stars somewhere else, then move to the moon.
This would be a fantastic feature, especially for imaging the moon during daylight or twilight when stars are unavailable.
Because this is unavailable in Ekos, I routinely switch to TheSkyX *just for autofocus* and then switch back to Ekos. TheSkyX "@Focus3" uses a gradient (contrast)-based focus metric that produces razor-sharp results by focusing on the Moon. @Focus3's gradient-based method also works very well on star fields or even single stars.
Implementing this in Ekos would require an alternative focus metric but (in my naive expectation) no new code or logic for moving the focuser, computing the curve, solving for the optimum position, etc.
"Sharpness" metrics are well-studied because it's the basis for autofocus in conventional photography. Daytime photography (eg, in your phone) can't use star sizes. The kind of focus metric required for Ekos to autofocus on the Moon is in fact the metric used by virtually all autofocus logic in the world.
The math is well defined and there are gradient libraries available in many languages to make it fast and reliable.
Scott, I totally agree that a contrast-detection metric would be a very nice addition to Ekos. It is something I've been mulling over for quite a while. I was coming at it as a benefit for out-of-focus images (when things are too out-of-focus so that star-detection is unreliable, then Ekos auto-focus currently breaks down), but yes, it would be great for imaging the Moon as well. I can't promise a timeline for this, it would take some time to experiment and get right. In my previous research on it, I found sources suggesting a simply a standard-deviation of pixel values would work (perhaps computed in several regions in the image), and another suggestion of convolving Sobel Operators on the image. I believe you are right that one would change the image quality metric (from HFR to contrast), but leave the algorithmic logic intact.
FWIW, (minor point) I believe most modern autofocus schemes use phase-detection algorithms (which are much quicker because they compute which direction the focus should move and by how much) but that requires a hardware component we wouldn't have. However a contrast detection scheme should be OK for Ekos.
I honestly am not sure what's in the gradient autodocus scheme. The Linear and Linear 1-Pass schemes depend on star detection, so won't work on images without stars.