## 2 Scheme  
The basic scheme is shown in Figure 1. A slotted foil [27] is inserted in the last bunch compressor section of the PAL-XFEL linac. The foil spoils the electron beam emittance in the head and tail parts of the bunch and suppresses lasing there. Note that the slot is set relatively wide in our scheme because its function is not to shorten the pulse length as in the original proposal but to set a defined temporal window of lasing and define the lasing domain in the electron bunch [29]. The next is the ESASE [20] section that consists of an optical laser, a modulator, and a magnetic chicane for the density modulation of an unspoiled part of the electron beam at the end of a linac section (Figure 1a). In this ESASE section, the electron beam is energy-modulated in a strong magnetic field modulator via the interaction with a co-propagating laser. The shape of the optical cycles of the pulse is replicated in the energy distribution of the electron beam. Later, a magnetic chicane converts the energy modulation to a density modulation so that the flat current profile changes into a profile of current spikes. The electron beam with these current spikes is sent to an undulator (Figure 1b) for radiation generation. The SASE undulator is made by three undulator modules (UMs). The length of the undulator is kept short to avoid saturation and to keep the electron-beam energy spread at a minimum.  
Figure 1c represents a chicane-mirror system composed of four dipole magnets and a set of mirrors [36]. The magnetic chicane is used for delaying an electron beam and diluting the microbunching developed in an undulator. A set of reflecting mirrors is used to delay an X-ray pulse with respect to a particular electron spike in the electron beam. The X-ray pulses are delayed in such a way that the leading radiation spike (target pulse) acts as a seed to trailing current spikes (more description below along with Figure 2) [29]. Figure 1d shows the second, even shorter undulator (1 UM only) for a radiation amplification. This undulator is used to amplify the target pulse. For a good amplification, the radiation seed always needs a fresh electron spike. Figure 1e shows a small magnetic chicane followed by a small undulator section (1 UM only). A small chicane is used to create the delay of the electron beam by a laser wavelength \(\lambda_{\text{L}}\) to align the radiation spike to the next current spike. The same unit shown in Figure 1e is used several times in the downstream undulator  
for repeated electron beam delays and repeated amplifications of a target pulse to obtain an isolated TW-attosecond radiation pulse at the end.  
Figure 2 shows the working principle of the scheme. First, Figure 2a shows that a few current spikes with different magnitudes are generated by an optical laser's interaction with electron beam inside the modulator, followed by a density modulation in a magnetic chicane (see Figure 1a). The separation between the current spikes is in the order of the modulation laser wavelength \(\lambda_{\mathrm{L}}\). Figure 2b shows the current and radiation profile after the first stage of amplification (Figure 1b), and the same number of radiation spikes (a total of 9) are generated. Now, in Figure 2c, the 9 th radiation spike is selected as a target pulse and aligned with the tail current peak (1 st current peak) via a chicane-mirror system (Figure 1c). Figure 2d shows the current and radiation profile after 2 UM amplification. The electron beam is delayed by \(\lambda_{\mathrm{L}}\) to align the 2 nd current spike with the target radiation pulse for next amplification (Figure 1e). This procedure is repeated and the target pulse is aligned sequentially with all the current spikes to yield a solitary TW-attosecond radiation pulse, as shown in Figure 2e, at the undulator exit (Figure 1f).