+
    iHàjâ  ã                  óš   € R t ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIH	t	 ]P                  ! R4      tR R ltR R	 ltR
RRRRR/R R lltR# )a•  Codex app-server compaction: the route ``compress_context`` takes for Codex-owned threads.

Split from ``agent/conversation_compression.py`` (facade size cap), which imports it at module level;
this module must never import the facade at module level (import cycle), so it late-imports the
facade's shared helpers inside functions. It logs under the facade's logger name so log consumers keep
one source.
)ÚannotationsN)ÚAnyÚOptional©Ú _emit_bypassed_attempt_telemetryzagent.conversation_compressionc               ó    € V ^8„  d   QhRRRR/# )é   Úagentr   ÚreturnÚfloat© )Úformats   "ÚI/home/ubuntu/.hermes/hermes-agent/agent/conversation_compression_codex.pyÚ__annotate__r      s   € ÷ ñ °ð ¸ñ ó    c                ód  € \        V RR4      p\        VRR4      p\        V4      '       g   R#  V! RR7      p T'       d/   \        R\        TP                  R	4      ;'       g    R4      4      # R#   \         d    \        P	                  RRR7        R# i ; i  \        \        3 d     R# i ; i)
zGSeconds left on this session's compaction-failure cooldown (0 = clear).Úcontext_compressorNÚ'get_active_compression_failure_cooldowng        T)Úrefreshz'codex compaction cooldown lookup failed©Úexc_infoÚremaining_seconds)
ÚgetattrÚcallableÚ	ExceptionÚloggerÚdebugÚmaxr   ÚgetÚ	TypeErrorÚ
ValueError)r	   Ú
compressorÚgetterÚstates   &   r   Ú$_codex_compaction_cooldown_remainingr$      s«   € ä˜Ð 4°dÓ;€JÜ�ZÐ!JÈDÓQ€FÜ�F×ÒÙðÙ˜tÔ$ˆðßINŒs�3œ˜eŸi™iÐ(;Ó<×CÐCÀÓDÓEÐWÐTWÐWøô	 ô Ü�‰Ð>ÈˆÔNÚðûô
 ”zÐ"ô Úðús4   ¯	A1 ¹B Á"B Á$
B Á/B Á1"BÂBÂB/Â.B/c               ó$   € V ^8„  d   QhRRRRRR/# )r   r	   r   ÚerrorÚstrr
   ÚNoner   )r   s   "r   r   r   %   s!   € ÷ ;ñ ;¨Cð ;¸ð ;Àñ ;r   c                óæ   € ^ RI Hp ^ RIHp \	        V RR4      p\	        VRR4      p\        V4      '       g   R# V! RRR7      ;_uu_ 4        V! W!4       RRR4       R#   + '       g   i     R# ; i)	zÌArm the shared compression-failure cooldown after a failed codex compaction.
The codex path returns the transcript unchanged, so without a cooldown the still-over-threshold session
would retry every turn.)Ú!_SUMMARY_FAILURE_COOLDOWN_SECONDS)Ú_swallowr   NÚ$_record_compression_failure_cooldownz(codex compaction cooldown persist failedTr   )Úagent.context_compressorr*   Úagent.conversation_compressionr+   r   r   )r	   r&   r*   r+   r!   Úrecorders   &&    r   Ú _record_codex_compaction_failurer0   %   s^   € õ KÝ7Ü˜Ð 4°dÓ;€JÜ�zÐ#IÈ4ÓP€HÜ�H×ÒÙÙ	Ð<Àt×	LÖ	LÙÐ2Ô:÷ 
M×	L×	LÒ	Lús   Á	AÁA0	Úapprox_tokensÚtask_idÚdefaultÚforceFc               ó<   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r   r	   r   ÚmessagesÚlistÚsystem_messageúOptional[str]r1   zOptional[int]r2   r'   r4   ÚboolÚ
started_atr   Úattempt_seedzdict[str, Any]r
   ztuple[list, str]r   )r   s   "r   r   r   3   sa   € ÷ U%ñ U%ØðU%ØðU%Ø0=ðU%ØQ^ðU%àðU%à%)ðU%à?DðU%àTbðU%ð ñU%r   c          
     óh  a aaa€ ^ RI HpHp	Hp
HpHpHp R6R V VVV3R lllp\        S RR4      ;'       g    RpS'       d   SR MRp\        \        S R	R
4      ;'       g    R
4      P                  4       pVR79  d   R
pR;p;ppV'       g   VR8w  d   RV R2RRV 2pppM%V'       g   \        S 4      pV^ 8”  d   RVR R2pRRpp\        S RR4      pVf   Vf   RRRpppVe6   \        P                  RVV\        V4      V4       V! VV4       W! S V4      3# \        P                  RV\        V4      V4       \        P                  ! \         4      ;_uu_ 4        S P#                  V4       RRR4       V	! S RR7      P%                  4       p VP'                  4       p\1        \        TRR 4      ;'       g    \        TR!R4      4      pTP+                  T'       d   RMR"4       \        TR#R 4      '       dC   \        P                  ! \         4      ;_uu_ 4        TP3                  4        RRR4       RS n        T'       d‡   \        P                  ! \         4      ;_uu_ 4        S P7                  R$TP8                   24       RRR4       \;        S \        \        TR!R4      ;'       g    R%4      4       T! R&R'4       Y! S T4      3# T! R(RR)7      ;_uu_ 4        ^ R*IHpH p T! S TSRR+7       \C        S PD                  R,4      '       d   T! S TTR-7       RRR4       T! TS PF                  ;'       g    R.R/7       \        P                  R0T\        TR1R4      ;'       g    R.\        TR2R4      ;'       g    R.4       T! S T4      pT! R3RR4R57       T
! S 4       TT3#   + '       g   i     EL9; i  \(         d7   pTP+                  R4       T! RR\-        T4      P.                   24       h Rp?ii ; i  + '       g   i     ELÔ; i  + '       g   i     EL�; i  + '       g   i     EL; i)8a  Route compaction to Codex app-server for Codex-owned threads.
Rewriting the local transcript would not shrink the Codex thread, so Codex compacts its own thread and
Hermes' transcript is left unchanged. Every exit, raising ones included, logs one attempt record.)ÚCOMPACTION_STATUSÚ_CompressionActivityHeartbeatÚ_emit_compaction_doneÚ_existing_system_promptÚ_reset_read_dedup_cachesr+   Únonec               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úcommit_statusr'   Úfailure_classr9   Úmethodr
   r(   r   )r   s   "r   r   Ú<_compress_context_via_codex_app_server.<locals>.__annotate__?   s)   € ÷ 
ñ 
˜sð 
°=ð 
È#ð 
Ð[_ñ 
r   c                ó,   <€ \        SSWSR VSR7       R# )Úcodex_app_server)rE   rF   r1   ÚrouterG   r<   Nr   )rE   rF   rG   r	   r1   r<   r;   s   &&&€€€€r   Ú_recordÚ7_compress_context_via_codex_app_server.<locals>._record?   s   ø€ Ü(Ø�:¨]ÐgtØ$¨VÀ,÷	
r   Ú
session_idNÚ,ÚunknownÚ codex_app_server_auto_compactionÚnativeÚhermeszmode=z force=falseÚskippedÚcodex_auto_zfailure cooldown active for z.0fÚsÚblockedzblocked:cooldownÚ_codex_sessionzno active codex threadÚcodex_no_threadzKcodex app-server compaction skipped: %s (session=%s messages=%d tokens=~%s)zFcodex app-server compaction started: session=%s messages=%d tokens=~%sT)Úemit_client_statuszcontext compression failedÚabortedz
exception:ÚinterruptedFr&   zcontext compression completedÚshould_retireu(   âš  Codex app-server compaction failed: zcompaction interruptedÚfailedÚcodex_compaction_failedz#codex compaction bookkeeping failedr   )Ú#_record_codex_app_server_compactionÚ_record_codex_app_server_usage)r1   r4   Úupdate_from_response)r6   Ú )rN   z>codex app-server compaction done: session=%s thread=%s turn=%sÚ	thread_idÚturn_idÚ	committedÚprovider)rG   )rC   >   ÚoffrS   rR   )$r.   r>   r?   r@   rA   rB   r+   r   r'   Úlowerr$   r   ÚinfoÚlenÚ
contextlibÚsuppressr   Ú_emit_statusÚstartÚcompact_threadÚBaseExceptionÚstopÚtypeÚ__name__r:   ÚcloserX   Ú_emit_warningr&   r0   Úagent.codex_runtimer`   ra   Úhasattrr   rN   )r	   r6   r8   r1   r2   r4   r;   r<   r>   r?   r@   rA   rB   r+   rL   Ú_sidÚ_tokensÚ	auto_modeÚskip_reasonÚskip_statusÚ
skip_classÚ_cooldown_remainingÚcodex_sessionÚ_activity_heartbeatÚresultÚexcr^   r`   ra   Úexisting_prompts   f&&d$$dd                      r   Ú&_compress_context_via_codex_app_serverr…   3   sÜ  û€ ÷÷ ÷

õ 
ô �5˜,¨Ó-×7Ð7°€Dß&3�˜qÑ!¸€GÜ”G˜EÐ#EÀxÓP×\Ð\ÐT\Ó]×cÑcÓe€IØÐ3Ô3Øˆ	Ø-1Ð1€KÐ1�+ 
ß�Y (Ô*Ø16°y°kÀÐ/NÐPYÐ]hÐirÐhsÐ[t *�[ˆ *ßô CÀ5ÓIÐØ Ô"Ø8Ð9LÈSÐ8QÐQRÐSˆKØ&/Ð1C˜ˆKÜ˜EÐ#3°TÓ:€MØÒ˜}Ò4Ø/GÈÐTe *�[ˆØÒÜ�‰ØYÐ[fÐhlÜ�‹M˜7ô	
ñ 	�˜ZÔ(ØÐ0°¸ÓGÐGÐGÜ
‡K�KÐXÐZ^Ô`cÐdlÓ`mÐovÔwÜ	×	Ò	œY×	'Õ	'Ø×ÑÐ,Ô-÷ 
(á7¸ÐRVÔW×]Ñ]Ó_ÐðØ×-Ñ-Ó/ˆô ”'˜& -°Ó7×YÐY¼7À6È7ÐTXÓ;YÓZ€FØ×Ñ¿VÑ9ÐIhÔiÜˆv�¨×.Ò.Ü× Ò ¤×+Õ+Ø×ÑÔ!÷ ,à#ˆÔßÜ× Ò ¤×+Õ+Ø×ÑÐ"JÈ6Ï<É<È.Ð YÔZ÷ ,ô 	)¨´´G¸FÀGÈTÓ4R×4nÐ4nÐVnÓ0oÔpÙ�Ð3Ô4ØÐ0°¸ÓGÐGÐGÙ	Ð7À$×	GÖ	GßkÙ+¨E°6ÈÐ^bÕcô �5×+Ñ+Ð-C×DÒDÙ*¨5°&À8ÕL÷ 
Hñ ˜W°×1AÑ1A×1GÐ1GÀRÕHÜ
‡K�KØHÈ$Ü�˜ TÓ*×0Ð0¨b´'¸&À)ÈTÓ2R×2XÐ2XÐVXôñ .¨e°^ÓD€OÙˆK˜ jÕ1ñ ˜%Ô Ø�_Ð$Ð$÷S 
(×	'Ð	'ûô
 ô Ø× Ñ Ð!=Ô>á�	˜Z¬¨S«	×(:Ñ(:Ð';Ð<Ô=Øûð	ú÷ ,×+Ð+ú÷ ,×+Ð+ú÷ 
H×	GÐ	GúsH   ÅN ÆN4 ÈO8É&PË<P Î N1	Î4O5Î?1O0Ï0O5Ï8P		ÐP	Ð P1	)Ú__doc__Ú
__future__r   rl   ÚloggingÚtypingr   r   Ú(agent.conversation_compression_telemetryr   Ú	getLoggerr   r$   r0   r…   r   r   r   Ú<module>rŒ      s]   ðñõ #ã Û ß  å Uà	×	Ò	Ð;Ó	<€õõ";ðU%ØaeðU%àðU%à,1÷U%ñ U%r   