  Long-duration gamma-ray bursts (GRBs) are thought to come from the
core-collapse of Wolf-Rayet stars. Whereas their stellar masses $M_*$ have a
rather narrow distribution, the population of GRBs is very diverse, with
gamma-ray luminosities $L_\gamma$ spanning several orders of magnitude. This
suggests the existence of a "hidden" stellar variable whose burst-to-burst
variation leads to a spread in $L_\gamma$. Whatever this hidden variable is,
its variation should not noticeably affect the shape of GRB lightcurves, which
display a constant luminosity (in a time-average sense) followed by a sharp
drop at the end of the burst seen with Swift/XRT. We argue that such a hidden
variable is progenitor star's large-scale magnetic flux. Shortly after the core
collapse, most of stellar magnetic flux accumulates near the black hole (BH)
and remains there. The flux extracts BH rotational energy and powers jets of
roughly a constant luminosity, $L_j$. However, once BH mass accretion rate
$\dot M$ falls below $\sim L_j/c^2$, the flux becomes dynamically important and
diffuses outwards, with the jet luminosity set by the rapidly declining mass
accretion rate, $L_j\sim \dot M c^2$. This provides a potential explanation for
the sharp end of GRBs and the universal shape of their lightcurves. During the
GRB, gas infall translates spatial variation of stellar magnetic flux into
temporal variation of $L_j$. We make use of the deviations from constancy in
$L_j$ to perform stellar magnetic flux "tomography". Using this method, we
infer the presence of magnetised tori in the outer layers of progenitor stars
for GRB 920513 and GRB 940210.
