Precise spectral control in the hard X-ray regime remains a long-standing challenge that limits applications in atomic-scale science and ultrafast spectroscopy. We present an actively mode-locked cavity-based X-ray free-electron laser that achieves deterministic spectral programmability with phase-locked pulse trains and comb-like spectra, by coherently modulating the electron-beam energy. Three-dimensional time-dependent simulations predict 700 total energy, 30 peak power, and frequency-comb spacing of 1. 55 set by the modulation frequency. We further develop selective single-line amplification via undulator tapering and absolute frequency positioning through modulation-laser tuning with better than 2 10^-5 relative precision. Importantly, stable mode-locked operation persists under >80\% peak-to-peak cavity-reflectivity variations, substantially relaxing requirements on X-ray optics. These results establish active mode locking as a practical route to fully coherent, spectrally agile hard X-ray sources and enable new opportunities in time-resolved core-level spectroscopy, X-ray quantum optics, and precision metrology.
Huang et al. (Wed,) studied this question.