Ë
    áß²j³  ã                  ó¸   — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZ dZdZ G d	„ d
ee«      Zdd„Zdd„Zdd„Zdd„Zddddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zy)a1  Shared session activity observation contract: timestamp + bounded description/provenance, observation
only (notification, timeout, kill and retry policy live elsewhere). Provenance is a small closed enum of
*noun* sources; the default agent clock stamps ``unknown`` unless a writer passes ``provenance=``.é    )ÚannotationsN)Úsuppress)ÚEnum)ÚAnyÚMappingÚOptionaléx   g      N@c                  ó$   — e Zd ZdZdZdZdZdZdZy)ÚActivityProvenancez3Where a durable/in-memory activity stamp came from.Úunknownzagent.compressionzagent.compression_timeoutzagent.compression_cooldownzagent.compression_turnholdN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚUNKNOWNÚAGENT_COMPRESSIONÚAGENT_COMPRESSION_TIMEOUTÚAGENT_COMPRESSION_COOLDOWNÚAGENT_COMPRESSION_TURNHOLD© ó    ú;/home/ubuntu/.hermes/hermes-agent/agent/session_activity.pyr   r      s$   „ Ù=à€Gð ,ÐØ ;ÐØ!=ÐØ!=Ñr   r   c                óp   — | xs dj                  «       }t        |«      t        k  r|S |dt        dz
   dz   S )z?Clamp free-form activity text to the shared description budget.Ú Né   u   â€¦)ÚstripÚlenÚACTIVITY_DESCRIPTION_MAX)ÚdescriptionÚtexts     r   Úbound_activity_descriptionr!   !   sA   € àÒ˜2×$Ñ$Ó&€DÜ�t“9Ô 8Ò8ˆ4Ðj¸dÐCaÔE]Ð`aÑEaÐ>bÐejÑ>jÐjr   c                ó    — t        | t        «      r| S 	 t        | xs dj                  «       «      S # t        $ r t        j                  cY S w xY w)zBReturn a known provenance, or ``UNKNOWN`` when unset/unrecognized.r   )Ú
isinstancer   r   Ú
ValueErrorr   )Ú
provenances    r   Únormalize_activity_provenancer&   '   sL   € ä�*Ô0Ô1ØÐð*Ü! :Ò#3°×":Ñ":Ó"<Ó=Ð=øÜò *Ü!×)Ñ)Ò)ð*ús   ”1 ±AÁAc                ó¤   — 	 t        |«      }|t        j                  k\  rd| › �S d| › d|› �S # t        t        f$ r t        j                  }Y ŒAw xY w)a3  ``iteration N/M`` for user-facing status lines, or ``iteration N`` when the cap is unbounded.

    ``AIAgent.max_iterations`` defaults to ``sys.maxsize`` (unlimited), so printing the pair verbatim
    shows ``iteration 3/9223372036854775807`` in busy acks, heartbeats and timeout diagnostics (#102806).
    z
iteration ú/)ÚintÚ	TypeErrorr$   ÚsysÚmaxsize)Úapi_call_countÚmax_iterationsÚcaps      r   Úformat_iteration_progressr0   1   s`   € ðÜ�.Ó!ˆð Œc�k‰kÒØ˜NÐ+Ð,Ð,Ø˜Ð' q¨¨Ð.Ð.øô	 ”zÐ"ò Ü�k‰kŠðús   ‚- ­AÁAc                óZ   — t        t        «      5  d| _        ddd«       y# 1 sw Y   yxY w)z€Clear the persist rate-limit so the next stamp writes through (terminal compression labels must not stick on mid-compress text).g        N)r   Ú	ExceptionÚ#_session_activity_last_persist_mono)Úagents    r   Ú%reset_session_activity_persist_windowr5   @   s'   € ä	”)Ó	ñ 8Ø47ˆÔ1÷8÷ 8ñ 8ús   �!¡*)Úlast_activity_provenanceÚnowÚextrac           	     óæ   — | �t        | «      nd}t        |�|nt        j                  «       «      }t        |«      }t        |«      j                  }||||�t        ||z
  d«      nd||||dœ|xs i ¥S )zABuild the shared activity snapshot (plus optional caller extras).Nr   )Úlast_activity_atÚlast_activity_descriptionr6   Úseconds_since_activityÚlast_activity_tsÚlast_activity_descr   r%   )ÚfloatÚtimer!   r&   ÚvalueÚround)	r:   r;   r6   r7   r8   ÚwhenÚclockÚdescÚprovs	            r   Úbuild_activity_snapshotrG   F   s‰   € ð '7Ð&BŒ5Ð!Ô"È€DÜ˜˜‘#¬d¯i©i«kÓ:€EÜ%Ð&?Ó@€DÜ(Ð)AÓB×HÑH€Dà Ø%)Ø$(Ø<@Ð<L¤%¨°©°aÔ"8ÐRVà ¸ÈTÐaeñð Š;�Bðð r   )r   úOptional[str]ÚreturnÚstr)r%   ú"Optional[ActivityProvenance | str]rI   r   )r-   r   r.   r   rI   rJ   )r4   r   rI   ÚNone)r:   úOptional[float]r;   rH   r6   rK   r7   rM   r8   zOptional[Mapping[str, Any]]rI   zdict[str, Any])r   Ú
__future__r   r+   r@   Ú
contextlibr   Úenumr   Útypingr   r   r   r   Ú/SESSION_ACTIVITY_HEARTBEAT_MIN_INTERVAL_SECONDSrJ   r   r!   r&   r0   r5   rG   r   r   r   ú<module>rS      s    ðñfõ #ã 
Û Ý Ý ß )Ñ )àÐ ð
 37Ð /ô	>˜˜dô 	>ókó*ó/ó8ð DHØØ)-ñà%ðð  -ðð Að	ð
 
ðð 'ðð ôr   