The diagram isn't the clearest I've ever seen, but they are taking x as the distance
upwards from the equilibrium point, which means
x¨ must also be measured in the
upwards direction.
But since
x¨=−agx, when x is positive,
x¨ is negative so acts in the other direction.
The extension is a-x because x=0 corresponds to the equilibrium position (when the extension is a).
Notes: To show SHM, you pretty much always want to define x relative to the equilibrium position (so x = 0 at equilibrium).
The
direction you choose for x doesn't really matter (*), but you need to be consistent (so
x˙,x¨ are taken in the same direction).
(*) unless the question actually defines it to be in a certain direction, then you need to humor the examiner.