The JWST team actually put out a relevant blog post just a couple days ago, on November 8th: Monitoring Webb’s Mirrors for Optimal Optics. The whole post is technically fascinating and worth reading, but I've excerpted what seemed most relevant. I believe all the quotes below are by Dr. Marcio B. Meléndez, "principal astronomical optics scientist for Webb at the Space Telescope Science Institute," presented in the blog post as one long quotation.
Math and careful grinding (and polishing, which is really just fancy grinding isn't it) were involved in the production of the mirror segments, but there are ongoing activities to keep the telescope focusing by steering the mirror array:
Aiming it at something really far away (stars)
Though the precise alignment of the telescope was completed in early 2022 during commissioning, it does not stay that way naturally due to various factors such as temperature variations and so-called ‘tilt’ events, so a lifelong maintenance program is required. The wavefront sensing team responsible for keeping Webb’s mirrors in order has been monitoring, investigating, trending, and occasionally moving its primary mirror segments during science operations. These activities are carried out from Webb’s Mission Operations Center, located at the Space Telescope Science Institute in Baltimore.
This telescope monitoring program consists of a series of observations that use special optical sensing equipment inside the Near Infrared Camera instrument (NIRCam), with a set of lenses that intentionally defocus the images of stars by a known amount. These defocused star images contain measurable features that enable the team to derive the alignment of the telescope, using a process called phase retrieval to determine what we call the ‘wavefront error.’ The telescope monitoring observations are currently scheduled every other day, interspersed among Webb’s science observations, with short runtimes of about 20 minutes. All telescope monitoring observations are publicly available via the MAST archive. Observatory users and other interested investigators can also view and model the optical quality using specialized tools.
Looking directly at the mirror array using onboard sensors (this is actually continued directly from the quote above in the following paragraph from the source)
The maintenance program also takes a ‘selfie’ using a specialized ‘pupil imaging’ lens, designed to take images of the mirror segments and not of the sky, four times a year. These pupil images are used to assess the health of the primary mirrors. During each observation the team measures Webb’s pointing stability or ‘jitter,’ which has remained six times better than design requirements. The Fine Guidance Sensor is used to command a small onboard steerable mirror to lock onto a target, while moving in orbit, without deviating more than the thickness of a human hair, seen at a distance of seven miles (11 kilometers).
The performance is pretty amazing.
The optical requirement for Webb was set to 150 nanometers of wavefront error, coming from a combination of uncorrectable surface figure imperfections and correctable telescope misalignments. The current uncorrectable errors are very low, at about 65 nanometers[.]
The telescope mirror control updates were required to be less frequent than every two weeks. ... Since the beginning of science operations, we have applied over 25 corrective moves. ... On Oct. 3, a mirror correction was performed, after a record of 186 days since the previous mirror control update.