§
    ÷žyjt  ã                  óP   — d Z ddlmZ ddlmZmZ e G d„ d¦  «        ¦   «         ZdS )u…  Per-attempt recovery bookkeeping for the conversation turn loop.

The inner retry loop in ``run_conversation`` (``while retry_count <
max_retries``) makes several distinct recovery attempts on a single model API
call: a credential-pool 429 retry, a per-provider OAuth refresh (codex,
anthropic, nous, copilot), a long-context compression restart, a length-
continuation restart, and a handful of format-recovery branches (thinking-
signature stripping, multimodal-tool-content stripping, llama.cpp grammar
fallback, image shrink, invalid-encrypted-content, 1M-beta header).

Each of those branches is guarded by a one-shot boolean so it fires at most
once per attempt. They used to be ~16 bare ``*_attempted`` / ``has_retried_*``
/ ``restart_with_*`` locals declared inline before the loop and threaded
through its 2,400-line body. ``TurnRetryState`` collapses them into one object
the loop mutates in place (``state.codex_auth_retry_attempted = True``), giving
the recovery bookkeeping a single named, testable home.

Loop-control variables (``retry_count``, ``max_retries``,
``max_compression_attempts``) intentionally stay as plain locals â€” they are the
``while`` mechanics, not recovery bookkeeping, and putting them on the object
would add indirection without clarifying anything.

This module is dependency-free so it can be unit-tested in isolation and
imported by the turn loop without an import cycle.
é    )Úannotations)Ú	dataclassÚfieldsc                  ó@  — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   dZ
ded	<   dZded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   d„ ZdS )ÚTurnRetryStateaq  One-shot recovery guards + restart signals for a single API-call attempt.

    A fresh instance is created for each iteration of the outer turn loop
    (once per ``api_call_count``). Each guard fires its recovery branch at most
    once; the ``restart_with_*`` signals are read by the loop after the attempt
    to decide whether to rebuild the request and retry.
    FÚboolÚcodex_auth_retry_attemptedÚanthropic_auth_retry_attemptedÚnous_auth_retry_attemptedÚ'nous_paid_entitlement_refresh_attemptedÚcopilot_auth_retry_attemptedÚ"copilot_stale_cred_retry_attemptedÚvertex_auth_retry_attemptedÚthinking_sig_retry_attemptedÚ)invalid_encrypted_content_retry_attemptedÚ(native_compaction_reject_retry_attemptedÚimage_shrink_retry_attemptedÚ'multimodal_tool_content_retry_attemptedÚoauth_1m_beta_retry_attemptedÚ!llama_cpp_grammar_retry_attemptedÚprimary_recovery_attemptedÚhas_retried_429Úauth_failover_attemptedÚ restart_with_compressed_messagesÚ restart_with_length_continuationÚrestart_with_rebuilt_messagesÚ restart_with_redirected_messagesc              #  ój   K  — t          | ¦  «        D ] }|j        t          | |j        ¦  «        fV — Œ!d S )N)r   ÚnameÚgetattr)ÚselfÚfs     ú</home/ragecks/.hermes/hermes-agent/agent/turn_retry_state.pyÚ__iter__zTurnRetryState.__iter__Z   sG   è è € å˜‘”ð 	0ð 	0ˆAØ”&�' $¨¬Ñ/Ô/Ð/Ð/Ð/Ð/Ð/ð	0ð 	0ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   Ú__annotations__r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   © r%   r#   r   r       s¸  € € € € € € ðð ð (-ÐÐ,Ð,Ð,Ñ,Ø+0Ð"Ð0Ð0Ð0Ñ0Ø&+ÐÐ+Ð+Ð+Ñ+Ø49Ð+Ð9Ð9Ð9Ñ9Ø).Ð Ð.Ð.Ð.Ñ.ð 05Ð&Ð4Ð4Ð4Ñ4Ø(-ÐÐ-Ð-Ð-Ñ-ð */Ð Ð.Ð.Ð.Ñ.Ø6;Ð-Ð;Ð;Ð;Ñ;Ø5:Ð,Ð:Ð:Ð:Ñ:Ø).Ð Ð.Ð.Ð.Ñ.Ø49Ð+Ð9Ð9Ð9Ñ9Ø*/Ð!Ð/Ð/Ð/Ñ/Ø.3Ð%Ð3Ð3Ð3Ñ3ð (-ÐÐ,Ð,Ð,Ñ,Ø!€OÐ!Ð!Ð!Ñ!ð %*ÐÐ)Ð)Ð)Ñ)ð .3Ð$Ð2Ð2Ð2Ñ2Ø-2Ð$Ð2Ð2Ð2Ñ2ð
 +0Ð!Ð/Ð/Ð/Ñ/ð .3Ð$Ð2Ð2Ð2Ñ2ð0ð 0ð 0ð 0ð 0r%   r   N)r)   Ú
__future__r   Údataclassesr   r   r   r+   r%   r#   ú<module>r.      sy   ððð ð4 #Ð "Ð "Ð "Ð "Ð "à )Ð )Ð )Ð )Ð )Ð )Ð )Ð )ð ð<0ð <0ð <0ð <0ð <0ñ <0ô <0ñ „ð<0ð <0ð <0r%   