"""Helpers for rendering gateway message timestamps exactly once. Gateway messages need timestamps in the LLM context for temporal awareness, but persisted message content should stay clean so replay does not accumulate ``[timestamp] [timestamp] ...`` prefixes across turns. """ from __future__ import annotations import re from datetime import datetime from typing import Any, Optional, Tuple # Current gateway format: [Tue 2026-04-28 13:40:53 CEST] _HUMAN_TIMESTAMP_RE = re.compile( r"^\[(?P[A-Z][a-z]{2}) " r"(?P\d{4}-\d{2}-\d{2}) " r"(?P