+
    „WÝjƒ  ã                  ó6   € R t ^ RIHt ^ RIHt  ! R R4      tR# )a¶  The ``api_content`` sidecar backfill writers for SessionDB (#124102 FILE_LINES split).

Split out of :mod:`hermes_state_messages`: the two row-addressed sidecar UPDATEs the turn prologue
uses when the current turn's user row was materialized before the sidecar could be composed. Bound
into ``SessionDB`` via this mixin, so every existing ``session_db.set_message_api_content(...)``
call site and test patch seam keeps working unchanged.
)Úannotations)ÚAnyc                  ó2   € ] tR t^tRtR R ltR R ltRtR# )ÚSessionApiContentMixinz;``SessionDB`` mixin: the ``api_content`` sidecar backfills.c               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Ú
session_idÚstrÚcontentr   Úapi_contentÚreturnÚint© )Úformats   "ÚLC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_state_api_content.pyÚ__annotate__Ú#SessionApiContentMixin.__annotate__   s0   € ÷ Yñ Y°cð YÀCð YÐVYð YÐ^añ Yó    c                ó`   € ^ RI Hp V P                  RV! V4      WP                  V4      34      # )uò  Backfill the ``api_content`` sidecar onto the newest ACTIVE user row (0/1 rows). Preflight compaction
inserts that row BEFORE the sidecar exists and the later persist identity-skips compacted dicts;
without this a reload reopens the prompt-cache divergence. ``content`` match guards a racing rewrite.

POSITIONAL, and only safe when the caller already knows the newest
active user row IS the message it stamped. The content match is NOT
sufficient on its own: repeated identical user turns ("ok", "y",
"continue") make an OLDER row compare equal, so calling this before
the current turn's row exists overwrites the previous turn's sidecar
with this turn's bytes â€” durable wrong-bytes replay, a worse cache
break than the missing sidecar. When the caller holds the durable row
id (``_row_id``, synced onto the live dict by
``sync_flushed_message_markers`` and stamped by
:meth:`_insert_message_rows`), use :meth:`set_message_api_content`
instead â€” it addresses the exact row and cannot land on a neighbour.
©Ú_scrub_surrogatesz¨UPDATE messages SET api_content = ? WHERE id = (SELECT id FROM messages WHERE session_id = ? AND role = 'user' AND active = 1 ORDER BY id DESC LIMIT 1) AND content IS ?)Úhermes_state_messagesr   Ú_write_rowcountÚ_encode_content)Úselfr   r
   r   r   s   &&&& r   Úset_latest_user_api_contentÚ2SessionApiContentMixin.set_latest_user_api_content   s;   € õ" 	<Ø×#Ñ#ð!ñ ˜{Ó+¨Z×9MÑ9MÈgÓ9VÐWó	Yð 	Yr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r   r	   Úrow_idr   r
   r   r   r   r   )r   s   "r   r   r   )   s;   € ÷ añ aØðaØ'*ðaØ58ðaØGJðaà	ñar   c           	     óÜ   € ^ RI Hp V'       d4   \        V\        4      '       g   \        V\        4      '       d   V^ 8:  d   ^ # V P                  RV! V4      W!V P                  V4      34      # )aý  Backfill the ``api_content`` sidecar onto ONE known durable row.

Row-addressed counterpart to :meth:`set_latest_user_api_content`: the
caller passes the ``_row_id`` the write path stamped on the live
message dict, so the update cannot drift onto a neighbouring row that
merely carries the same text.

Used by the turn prologue whenever the current turn's user row was
already materialized before the sidecar could be composed (in-place
preflight compaction, a close/early flush that raced the prologue).
The crash persist then marker-skips that message, so this is the only
way the stamped bytes reach the store.

``active = 1`` and the ``content`` match stay as defensive guards: a
row the compaction archived, or one a racing rewrite changed, is left
untouched.
r   zuUPDATE messages SET api_content = ? WHERE id = ? AND session_id = ? AND role = 'user' AND active = 1 AND content IS ?)r   r   Ú
isinstanceÚboolr   r   r   )r   r   r   r
   r   r   s   &&&&& r   Úset_message_api_contentÚ.SessionApiContentMixin.set_message_api_content)   se   € õ( 	<ßœZ¨´×5Ò5¼ZÈÔPS×=TÒ=TÐX^ÐbcÔXcÙØ×#Ñ#ð@á˜{Ó+¨VÀ×AUÑAUÐV]ÓA^Ð_óað 	ar   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r"   Ú__static_attributes__r   r   r   r   r      s   † ÙEõY÷0añ ar   r   N)r(   Ú
__future__r   Útypingr   r   r   r   r   Ú<module>r,      s   ðñõ #å ÷5aó 5ar   