+
    jHàjr  ã                  óÖ   a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ]P                  ! ]4      t]! 4       tR]R&   R	 R
 ltR R ltR R ltR R ltR R ltR# )aQ  ``cron/bot_chat_pending``: Bot Chat outputs whose target owner was not running yet.

``defer`` parks one (a cross-profile target whose gateway is down or still starting), and
the retired CLI lane left records of the same shape behind. Each still-``queued`` record is handed,
under its own id, to the target profile's live owner through the canonical
``tools.bot_live_delivery.deliver_to_live_owner`` door (idempotent per id). Records are
never deleted: they keep their final status as evidence, exactly as the old drain did.
A ``claimed`` record was an uncertain CLI turn and is never resent.
)ÚannotationsN)ÚPath)Úmake_user_dir)Úget_hermes_home)Úatomic_json_writez	set[Path]Ú_warnedc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )é   ÚkeyÚstrÚjobÚdictÚcontentÚhomer   Úfor_failureÚboolÚreturnÚNone© )Úformats   "Ú9/home/ubuntu/.hermes/hermes-agent/cron/bot_chat_legacy.pyÚ__annotate__r      s?   € ÷ 	kñ 	kˆsð 	k˜ð 	k¨ð 	k°4ð 	kÈð 	kÐRVñ 	kó    c               óp  € ^ RI p\        4       P                  4       R,          R,          p\        VRRRR7       W` R2,          pVP	                  4       '       gW   \        T\        T RR Uu/ uF  qˆV9   g   K  W�V,          bK  	  upV\        V4      WEP                  4       R	7      RR
R7       R# R# u upi )zYPark one never-admitted output under its delivery id; a later tick hands it to the owner.NÚcronÚbot_chat_pendingTiÀ  )ÚparentsÚexist_okÚmodez.jsonÚqueued)ÚidÚstatusr   r   r   r   Úsequenceé€  ©Ú	fsync_dirr   )r    Úname)	Útimer   Úresolver   Úexistsr   r   r   Útime_ns)	r
   r   r   r   r   r'   ÚrootÚpathÚks	   &&&&$    r   Údeferr.      sž   € ãÜÓ×$Ñ$Ó&¨Õ/Ð2DÕD€DÜ�$ ¨t¸%Õ@Ø�E˜�-Õ€DØ�;‰;�=Š=Ü˜$¤Ø˜8¹^Ó)X¹^¸ÐTWÉx¬)¨!°­Vª)¹^Ñ)XÐbiÜ�T“¨¿l¹l»nô!NàY]Ðdi÷	kñ ùâ)Xs   Á,B3Á9B3c               ó    € V ^8„  d   QhRRRR/# )r	   r+   r   r   zlist[tuple[Path, dict]]r   )r   s   "r   r   r   $   s   € ÷ Vñ V�$ð VÐ2ñ Vr   c                ó  € . pV P                  R 4       FŒ  p \        P                  ! VP                  RR7      4      p\	        V\
        4      '       g"   \        R\        V4      P                   24      h TP                  R4      R8X  g   Kz  TP                  Y#34       KŽ  	  \!        VR R	7      #   \        \        3 dB   pT\        9  d,   \        P                  T4       \        P                  RY$4        Rp?Kë  Rp?ii ; i)
z*.jsonz	utf-8-sig)Úencodingzexpected a JSON object, got zAUnreadable legacy Bot Chat pending record %s kept as evidence: %sNr!   r   c                óZ   € V ^,          P                  R^ 4      V ^ ,          P                  3# )é   r"   )Úgetr&   )Úitems   &r   Ú<lambda>Ú_queued.<locals>.<lambda>2   s    € ¨4°­7¯;©;°zÀ1Ó+EÀtÈAÅwÇ|Á|Ñ*Tr   )r
   )ÚglobÚjsonÚloadsÚ	read_textÚ
isinstancer   Ú
ValueErrorÚtypeÚ__name__ÚOSErrorr   ÚaddÚloggerÚerrorr4   ÚappendÚsorted)r+   Úfoundr,   ÚrecordÚexcs   &    r   Ú_queuedrI   $   s×   € Ø€EØ—	‘	˜(Ö#ˆð	Ü—Z’Z §¡¸ Ó DÓEˆFÜ˜f¤d×+Ò+Ü Ð#?ÄÀVÃ×@UÑ@UÐ?VÐ!WÓXÐXð ,ð �:‰:�hÓ 8Ö+Ø�L‰L˜$˜Ö(ñ $ô �%ÑTÔUÐUøô œÐ$ô 	Øœ7Ô"Ü—‘˜DÔ!Ü—‘Ð`ÐbfÔlÝûð		ús   ˜AB2Â2DÃ6C?Ã?Dc               ó    € V ^8„  d   QhRRRR/# )r	   rG   r   r   r   r   )r   s   "r   r   r   5   s   € ÷ ñ �tð  ñ r   c                óJ  € R Uu. uFC  p\        V P                  V4      \        4      '       d   V P                  V4      '       d   KA  VNKE  	  ppV'       d   RRP                  V4       R2# \        V P                  R4      ;'       g    / \        4      '       g   R# R# u upi )zQWhy *record* can never be handed off (empty when its required fields are usable).z*malformed legacy bot-chat record (missing z, z); not deliveredr   zFmalformed legacy bot-chat record (job is not an object); not deliveredÚ )r    r   r   )r<   r4   r   Újoinr   )rG   r
   Úmissings   &  r   Ú
_malformedrO   5   s‰   € á7ó OÑ7�sÜ  §¡¨C£´#×6Ò6¸f¿j¹jÈ¿o÷ ˆsÑ7€Gð OçØ;¸D¿I¹IÀgÓ<NÐ;OÐO_Ð`Ð`Ü�f—j‘j Ó'×-Ð-¨2¬t×4Ò4ÙWÙùòOs   …>B ÁB c               ó$   € V ^8„  d   QhRRRRRR/# )r	   r,   r   rG   r   r   r   r   )r   s   "r   r   r   @   s!   € ÷ %ñ %�4ð % ð %¨$ñ %r   c           	     ó  € ^ RI HpHp ^ RIHp ^ RIHp ^ RIHpH	p \        V4      ;p'       d   VP                  RVR7       R# \        VR,          4      P                  4       p	\        VP                  R	4      4      p
V	R
,          P!                  4       '       g   VP                  RRV	 2R7       R# V
'       d1   V! W%! V	R,          4      4      '       g   VP                  RRR7       R#  V! V	4      pTf   R#  T! Y›T! TP                  R4      ;'       g    / TR,          4      TR,          T
'       d   RMRR7      p\5        T\6        4      '       d   TP                  R4      MRpTP                  RRTR7       R#   \"         d     R# i ; i  \$         dc   p\&        P)                  T \*        9   d   \,        P.                  M\,        P0                  RYRR7       \*        P3                  T 4        Rp?R# Rp?ii ; i)zKDecide one queued record in place; False leaves it queued for a later tick.)ÚBOT_CHAT_POLICY_PLATFORMÚbot_chat_message)Úwarning_notifications_enabled)Úload_user_config_effective)Údeliver_to_live_ownerÚfind_canonical_live_ownerÚ	ambiguous)r!   rC   Tr   r   zstate.dbz+bot-chat delivery target no longer exists: zconfig.yamlÚ
suppressedNFr   r   r    Ú
diagnosticÚresult)Údelivery_idÚnotification_categoryz8Legacy Bot Chat pending record %s not handed off yet: %s©Úexc_infor!   Útransferred)r!   rC   Úreceipt_status)Úcron.scheduler_deliveryrR   rS   Úgateway.warning_notificationsrT   Úhermes_cli.config_effectiverU   Útools.bot_live_deliveryrV   rW   rO   Úupdater   r(   r   r4   Úis_filer=   Ú	ExceptionrB   Úlogr   ÚloggingÚDEBUGÚWARNINGrA   r<   r   )r,   rG   rR   rS   rT   rU   rV   rW   Úreasonr   r   ÚownerÚreceiptrH   ra   s   &&             r   Ú_disposerp   @   s¹  € çRÝKÝFßXä˜FÓ#Ð#€vÖ#Ø�‰˜[°ˆÔ7ÙÜ��v•Ó×'Ñ'Ó)€DÜ�v—z‘z -Ó0Ó1€KØ�:Õ×&Ñ&×(Ò(Ø�‰˜[Ð2]Ð^bÐ]cÐ0dˆÔeñ0 ÷/ 
Ñ:Ø$Ð&@ÀÈÕAUÓ&V÷Xò Xà�‰˜\°ˆÔ6ñ* ð'	Ù-¨dÓ3ˆEð Š=Ùð
	Ù+ØÑ-¨f¯j©j¸Ó.?×.EÐ.EÀ2ÀvÈiÕGXÓYØ" 4�L×P[ÁÐaiôkˆGô 3=¸WÄd×2KÒ2K˜Ÿ™ XÔ.ÐQUˆØ�‰˜]°$À~ˆÔVÙøô# ô 	Úð	ûô ô 	ô �J‰J¨´¬”w—}’}¼W¿_¹_ØQÐSWÐgkð ô mä�K‰K˜ÔÝûð	ús7   Ã-E? Ã<F ÄF Ä7	F Å?FÆFÆG>ÆAG9Ç9G>c               ó   € V ^8„  d   QhRR/# )r	   r   r   r   )r   s   "r   r   r   h   s   € ÷ \ñ \˜dñ \r   c            
     ó  € \        4       P                  4       R,          R,          p V P                  4       '       g   R# \        V 4       FO  w  r \	        W4      '       g   K  \        WRRR7       \        P                  R	TP                  TR
,          4       KQ  	  R#   \         dc   p\        P                  T\        9   d   \        P                  M\        P                  RYRR7       \        P                  T4        Rp?K½  Rp?ii ; i)a  Admit queued legacy records to their live owner; an absent owner leaves them for a later tick.

Each record is isolated: a malformed one is kept as ``ambiguous`` evidence and an
unexpected failure leaves only that record queued, so one bad file never stops cron.
r   r   NTr#   r$   z1Legacy Bot Chat pending record %s left queued: %sr^   z'Legacy Bot Chat pending record %s -> %sr!   )r   r(   Úis_dirrI   rp   r   rh   rB   ri   r   rj   rk   rl   rA   Úinfor&   )r+   r,   rG   rH   s       r   Údrain_legacy_pendingru   h   sÇ   € ô Ó×$Ñ$Ó&¨Õ/Ð2DÕD€DØ�;‰;�=Š=ÙÜ ž‰ˆð	Ü˜D×)Ò)ÙÜ˜d°dÀÕGô 	�‰Ð=¸t¿y¹yÈ&ÐQYÕJZÖ[ó &øô
 ô 	Ü�J‰J¨´¬”w—}’}¼W¿_¹_ØJÈDÐ`dð ô fä�K‰K˜ÔÝûð		ús   ÁBÁ#BÂDÂ*ADÄD)Ú__conditional_annotations__Ú__doc__Ú
__future__r   r9   rj   Úpathlibr   Úhermes_dir_aclr   Úhermes_constantsr   Úutilsr   Ú	getLoggerr?   rB   Úsetr   Ú__annotations__r.   rI   rO   rp   ru   )rv   s   @r   Ú<module>r€      s[   øðôõ #ã Û Ý Ý (å ,Ý #à	×	Ò	˜8Ó	$€Ù“U€ˆÓ õ	kõVõ"õ%÷P\r   