Text this: MAGE: Safeguarding LLM Agents against Long-Horizon Threats via Shadow Memory