+
    jHàj™)  ã                  ó`  € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	 ^ RI
t
^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIHtHtHtHt ]P@                  ! ]!4      t"Rt#]R	]#/R
 R ll4       t$R R lt%R R lt&R R lt'R R lt(R R lt)RR/R R llt*R R lt+R R lt,R# )zHStdlib-only recovery and lifetime protection for dependency generations.)ÚannotationsN)ÚCallable)ÚcontextmanagerÚsuppress©ÚPath)Údependency_home_rootÚinstall_state_dirÚruntime_facts_path)Údurable_write_bytesÚfile_digestÚlock_fdÚread_bytes_or_noneg      $@Útimeoutc               ó    € V ^8„  d   QhRRRR/# )é   Úprojectr   r   zfloat | None© )Úformats   "Ú=/home/ubuntu/.hermes/hermes-agent/hermes_cli/runtime_state.pyÚ__annotate__r   (   s   € ÷ ñ ˜$ð ¨Lñ ó    c             #  óÖ  "  € \        V 4      pVP                  RRR7       \        P                  ! VR,          \        P                  \        P
                  ,          R4      p \        VRVR7      '       g;   \        P                  RWR,          4       Rx €  \        P                  ! V4       R# Rx € \        P                  ! V4       R#   \        P                  ! T4       i ; i5i)	uq  Hold the per-install dependency lock; yields True when held, False when the wait expired.

Callers decide what a lost race means: readers skip the work the lock guards and carry on
(``activate_dependencies`` still selects and leases the committed generation), writers that
cannot be skipped pass ``timeout=None`` â€” an install the user asked for is theirs to wait on.
T)ÚparentsÚexist_okz.install.locké€  )Úwaitr   z@dependency lock still held after %ss; continuing without it (%s)FN)
r	   ÚmkdirÚosÚopenÚO_CREATÚO_RDWRÚ_lockÚLOGÚwarningÚclose)r   r   ÚstateÚfds   &$  r   Úruntime_lockr(   '   s¤   é € ô ˜gÓ&€EØ	‡K�K˜ t€KÔ,Ü	�Š�˜Õ(¬"¯*©*´r·y±yÕ*@À%Ó	H€Bð	Ü�R˜d¨G×4Ó4Ü�K‰KØRØ Õ0ô2ð ŠKØô 	�Š�Žð Š
ä
�Š�ŽøŒ�Š��üs*   ‚A!C)Á$5C ÂC)Â2C Â6C)ÃC&Ã&C)c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r   r   ÚrowÚdictÚjournalÚreturnÚNoner   )r   s   "r   r   r   >   s(   € ÷ ñ ¨ð °Dð À4ð ÈDñ r   c                ó‚  a€ ^ RI Hp V3R lR 4       w  rEp\        4       P                  4       pVP                  4       P	                  V4      '       do   VP
                  P                  R8w  gT   VP
                  VP
                  8w  g9   VP                  P                  R4      '       d   WdP
                  R,          8w  d   \        R4      hSP                  R4      ;'       g    \        \        V 4      4      SR,          8g  pV'       d!   VP                  4       '       d	   V! V4       EMSR	,          e    \        P                  ! SR	,          RR7      MR
p	\        V4      p
\        P                  ! SR,          RR7      pW©V39  d   \        R4      hVP                  4       '       d6   VP                  4       '       d	   V! V4       \         P"                  ! WT4       M-SR,          '       g   VP                  4       '       d	   V! V4       V	f   VP%                  RR7       M\'        Wi4       VP%                  4        R
# )é    )Úrmtree_forcec              3  óH   <"  € T F  p\        SV,          4      x € K  	  R # 5i©Nr   )Ú.0Úkeyr*   s   & €r   Ú	<genexpr>Ú._recover_plugin_publication.<locals>.<genexpr>A   s   øé € Ð[Ñ:Z°3¤ S¨¥X§ Ó:Zùs   ƒ"Úpluginsz
.previous-z.install-metadata.jsonz*plugin publication paths escape their homeÚ	committedÚfacts_beforeÚmetadata_beforeNT©ÚvalidateÚmetadata_afterzJplugin metadata changed after publication; preserve it for manual recoveryÚtarget_existed©Ú
missing_ok)ÚtargetÚbackupÚmetadata)Úhermes_cli.fs_utilsr1   r   ÚresolveÚis_relative_toÚparentÚnameÚ
startswithÚ
ValueErrorÚgetÚ_digestr
   ÚexistsÚbase64Ú	b64decodeÚ_bytesr   ÚreplaceÚunlinkÚ_atomic_bytes)r   r*   r,   r1   rB   rC   rD   Úhomer9   ÚoldÚcurrentÚnews   &f&         r   Ú_recover_plugin_publicationrY   >   sŸ  ø€ Ý0ä[Ñ:ZÓ[Ñ€F�HÜÓ!×)Ñ)Ó+€DØ�N‰NÓ×+Ñ+¨D×1Ò1°V·]±]×5GÑ5GÈ9Ô5TØ�}‰} §¡Ô-°V·[±[×5KÑ5KÈL×5YÒ5YØŸ=™=Ð+CÕCÔCÜÐEÓFÐFØ—‘˜Ó$×cÐc¬Ô0BÀ7Ó0KÓ(LÐPSÐTbÕPcÑ(c€IßØ�=‰=�?Š?Ù˜Ô ùàILÐM^ÕI_ÒIkŒf×Ò˜sÐ#4Õ5ÀÕEÐquˆÜ˜Ó"ˆÜ×Ò˜sÐ#3Õ4¸tÔDˆØ ˜*Ô$ÜÐiÓjÐjØ�=‰=�?Š?Ø�}‰}�ŠÙ˜VÔ$Ü�JŠJ�vÕ&ØÐ%×&Ô&¨6¯=©=¯?ª?Ù˜Ô ØŠ;Ø�O‰O tˆOÕ,ä˜(Ô(Ø‡N�NÖr   c               ó    € V ^8„  d   QhRRRR/# ©r   r   r   r-   r.   r   )r   s   "r   r   r   ^   s   € ÷ !`ñ !` ð !`¨$ñ !`r   c                óf  € \        V 4      R,          p\        V4      pVf   R#  \        P                  ! V4      pVP	                  R4      R8X  d   \        WV4       R# RV9   d
   VR,          MV.p. pV Fº  p\        VR,          4      pVP                  R8w  g<   VP                  4       P                  \        4       P                  4       4      '       g   \        R4      hVR	,          e    \        P                  ! VR	,          R
R7      MRpVP                  WxVP	                  R4      34       K¼  	  VP	                  R4      '       g¢   \        \!        V 4      4      VR,          8X  d‚   V FL  w  rxp	Ve%   \"        P$                  ! V4      P'                  4       MRp
\        V4      W©39  g   KC  \        R4      h	  V F)  w  rxpVf   VP)                  R
R7       K  \+        Wx4       K+  	  VP)                  4        R#   \        \,        \.        \0        3 d   p\3        RT RT 24      ThRp?ii ; i)zGRecover while holding runtime_lock, before activation or another write.úpublication.jsonNÚkindÚpluginÚconfigsÚconfigzconfig.yamlz#config path is outside Hermes stateÚpreviousTr<   Úconfig_afterr9   r:   zGconfig changed after publication began; preserve it for manual recoveryr@   z'cannot recover dependency publication: z: )r	   rQ   ÚjsonÚloadsrL   rY   r   rI   rF   rG   r   rK   rO   rP   ÚappendrM   r
   ÚhashlibÚsha256Ú	hexdigestrS   rT   ÚKeyErrorÚ	TypeErrorÚOSErrorÚRuntimeError)r   r,   Údatar*   Úentriesr`   Úentryra   rb   ÚafterÚpriorÚ_afterÚexcs   &            r   Úrecover_publicationru   ^   sã  € ä Ó(Ð+=Õ=€GÜ�'‹?€DØ‚|Ùð`Ü�jŠj˜ÓˆØ�7‰7�6‹?˜hÔ&Ü'¨°gÔ>Ùà$-°Ô$4�#�i–.¸3¸%ˆØˆÛˆEÜ˜% �/Ó*ˆFØ�{‰{˜mÔ+°6·>±>Ó3C×3RÑ3RÔSgÓSi×SqÑSqÓSs×3tÒ3tÜ Ð!FÓGÐGØMRÐS]ÕM^ÒMj”v×'Ò'¨¨jÕ(9ÀDÕIÐptˆHØ�N‰N˜F¨e¯i©i¸Ó.GÐHÖIñ ð �w‰w�{×#Ò#¬Ô0BÀ7Ó0KÓ(LÐPSÐTbÕPcÔ(cÛ+2Ñ'� %Ø@HÒ@TœŸš xÓ0×:Ñ:Ô<ÐZ^�Ü˜6“?¨5¨.Ö8Ü$Ð%nÓoÐoñ ,3ó
 -4Ñ(� &ØÒ#Ø—M‘M¨T�MÖ2ä! &Ö3ñ	 -4ð
 	�‰ÖøÜœ¤)¬WÐ5ô `ÜÐDÀWÀIÈRÐPSÈuÐUÓVÐ\_Ð_ûð`ús,   ¥8G> ÁC+G> ÅA G> Æ0AG> Ç>H0ÈH+È+H0c               ó    € V ^8„  d   QhRRRR/# r[   r   )r   s   "r   r   r   ‚   s   € ÷ !ñ ! ð !¨ñ !r   c                óî   € \        V 4      R,          p\        P                  ! VP                  4       4      pRVR&   \	        V\        P
                  ! V4      P                  4       4       \        V 4       R# )zHPersist a commit even when code/config changed without a new generation.r]   Tr9   N)r	   rd   re   Ú
read_bytesrT   ÚdumpsÚencoderu   )r   r,   r*   s   &  r   Úfinish_publicationr{   ‚   sV   € ä Ó(Ð+=Õ=€GÜ
�*Š*�W×'Ñ'Ó)Ó
*€CØ€CˆÑÜ�'œ4Ÿ:š: c›?×1Ñ1Ó3Ô4Ü˜Ö r   c               ó    € V ^8„  d   QhRRRR/# )r   Úenvironmentr   r-   úCallable[[], None]r   )r   s   "r   r   r   ‹   s   € ÷ /ñ / $ð /Ð+=ñ /r   c                ó,   € \        V P                  4      # )aR  Hold a kernel lock until process exit; the returned callable releases it early.

Call under ``runtime_lock`` at boot. Without the lock (``runtime_lock`` timed out) the
caller must re-read the selection after leasing: an installer may have moved it in between,
and an unselected, unleased generation is exactly what the collector removes.
)Úlease_directoryrH   )r}   s   &r   Úlease_generationr�   ‹   s   € ô ˜;×-Ñ-Ó.Ð.r   c               ó    € V ^8„  d   QhRRRR/# )r   Ú
generationr   r-   r~   r   )r   s   "r   r   r   •   s   € ÷  ñ   ð  Ð);ñ  r   c                óŽ  aaa€ V R,          P                  4       '       g   R # V R,          pVP                  RR7       \        V4        V\        P                  ! 4       P
                  ,          o\        P                  ! S\        P                  \        P                  ,          \        P                  ,          R4      o \        SRR7       SP                  4       '       d   M\        P                  ! S4       K´  R TTT3R	 llo\        P                   ! S4       S#   \         d    \        P                  ! S4       h i ; i)
zEPin a lease-managed generation directory for this process's lifetime.ú.lease-managedc                 ó   € R # r3   r   r   r   r   Ú<lambda>Ú!lease_directory.<locals>.<lambda>˜   s   € ‘tr   ú.leasesT)r   r   ©r   c               ó   € V ^8„  d   QhRR/# )r   r-   r.   r   )r   s   "r   r   Ú%lease_directory.<locals>.__annotate__¬   s   € ÷ ñ �Tñ r   c                 óè   <€ \         P                  ! S4       \        P                  ! S 4       \	        \
        4      ;_uu_ 4        SP                  4        R R R 4       R #   + '       g   i     R # ; ir3   )ÚatexitÚ
unregisterr   r%   r   rl   rS   )r'   ÚleaseÚreleases   €€€r   r‘   Ú lease_directory.<locals>.release¬   sA   ø€ Ü×Ò˜'Ô"Ü
�Š�Œô ”g×ÕØ�L‰LŒN÷ ××Òús   ÁA Á A1	)Úis_filer   Ú_prune_unlocked_leasesÚuuidÚuuid4Úhexr   r   r    ÚO_EXCLr!   r"   ÚBaseExceptionr%   rN   rŽ   Úregister)rƒ   Úleasesr'   r�   r‘   s   & @@@r   r€   r€   •   så   ú€ àÐ)Õ)×2Ñ2×4Ò4ÙÐØ˜)Õ#€FØ
‡L�L˜$€LÔÜ˜6Ô"Ø
ØœŸš›×)Ñ)Õ)ˆÜ�WŠW�UœBŸJ™J¬¯©Õ2´R·Y±YÕ>ÀÓFˆð	Ü�"˜4Õ ð �<‰<�>Š>ØÜ
�Š�Ž÷ò ô ‡O‚O�GÔØ€Nøô) ô 	Ü�HŠH�RŒLØð	ús   ÃD! Ä!#EÚmin_age_secondsi€Q c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   rœ   Úfloatr-   z
list[Path]r   )r   s   "r   r   r   ¸   s!   € ÷ ñ  ð ¸5ð ÈZñ r   c               ól  € ^ RI Hp . p\        V 4      pVP                  4       '       g   V# \	        V 4      ;_uu_ 4       pV'       g   VuuRRR4       # \        V 4       V! V 4      P                  P                  4       pVR,          pVP                  4       '       g   VuuRRR4       # VP                  4        FÚ  pVP                  4       '       g,   VP                  4       '       d   VP                  4       V8X  d   KF  VR,          p	V	P                  4       '       d:   \        P                  ! 4       V	P                  4       P                  ,
          V8  d   K   \        V4      '       d   K³  \         P"                  ! V4       VP%                  V4       KÜ  	  RRR4       V#   + '       g   i     T# ; i)zERemove unselected lease-managed generations after their readers exit.)Úselected_venvNÚenvironmentsr…   )Úpm.environmentsr    r	   rN   r(   ru   rH   rF   Úis_dirÚiterdirÚ
is_symlinkr“   ÚtimeÚstatÚst_mtimeÚleases_heldÚshutilÚrmtreerf   )
r   rœ   r    ÚremovedÚrootÚheldÚselectedÚgenerationsrƒ   Úmarkers
   &$        r   Úcollect_generationsr²   ¸   sD  € å-Ø€GÜ˜WÓ%€DØ�;‰;�=Š=ØˆÜ	�g×	Ô	 $ßØ÷ 
Ò	ô 	˜GÔ$Ù  Ó)×0Ñ0×8Ñ8Ó:ˆØ˜^Õ+ˆØ×!Ñ!×#Ò#Ø÷ 
Ò	ð &×-Ñ-Ö/ˆJØ×$Ñ$×&Ò&¨j×.?Ñ.?×.AÒ.AÀZ×EWÑEWÓEYÐ]eÔEeÙØÐ"2Õ2ˆFØ—>‘>×#Ò#¤t§y¢y£{°V·[±[³]×5KÑ5KÕ'KÈoÔ']ÙÜ˜z×*Ô*Ü—’˜jÔ)Ø—‘˜zÖ*ñ 0÷ 
ð" €N÷# 
Ö	ð" €Nús+   ¿
F"ÁAF"Â*>F"Ã)5F"ÄA	F"Å-+F"Æ"F3	c               ó    € V ^8„  d   QhRRRR/# )r   rƒ   r   r-   Úboolr   )r   s   "r   r   r   Ó   s   € ÷ :ñ :˜Dð : Tñ :r   c                ó&   € \        V R,          4      # )zHTrue while any process still holds a lease taken by ``lease_directory``.r‰   )r”   )rƒ   s   &r   r©   r©   Ó   s   € ä! *¨yÕ"8Ó9Ð9r   c               ó    € V ^8„  d   QhRRRR/# )r   r›   r   r-   r´   r   )r   s   "r   r   r   Ø   s   € ÷ ñ  4ð ¨Dñ r   c                óÞ  € RpV P                  R4       F†  p \        P                  ! V\        P                  4      p \        TRR7      '       g   RpM0\        \
        4      ;_uu_ 4        TP                  4        RRR4       \        P                  ! T4       Kˆ  	  V#   \         d     Kš  \
         d    Rp K©  i ; i  + '       g   i     LM; i  \        P                  ! T4       i ; i)aÀ  Remove abandoned lease files and report whether any live lock remains.

Kernel locks disappear even when ``execv``, ``os._exit`` or a crash bypasses
``atexit``. Cleaning those unlocked files whenever a reader arrives bounds leaks in
the selected generation too, which generation GC intentionally never visits.

Fail closed: a lease this user cannot open (root-owned 0o600 from a ``sudo hermes`` on the
same checkout) is held, never a boot failure.
FÚ*TrŠ   N)
Úglobr   r   r!   ÚFileNotFoundErrorrl   r"   r   rS   r%   )r›   r®   r�   r'   s   &   r   r”   r”   Ø   s´   € ð €DØ—‘˜SÖ!ˆð	Ü—’˜¤§	¡	Ó*ˆBð	Ü˜ %×(Ó(Ø‘äœg×&Õ&Ø—L‘L”N÷ 'ô �HŠH�RŽLñ "ð  €Køô !ô 	ÚÜô 	ØˆDÚð	ú÷ '×&ûô �HŠH�R�Lús@   ˜%B ¾-CÁ+CÁ<CÂ B>Â.B>Â7B>Â=B>ÃCÃCÃC,)-Ú__doc__Ú
__future__r   rŽ   rO   Úcollections.abcr   Ú
contextlibr   r   rg   rd   Úloggingr   Úpathlibr   rª   r¦   r•   r¢   r   r	   r
   Úpm.filesystemr   rT   r   rM   r   r"   r   rQ   Ú	getLoggerÚ__name__r#   ÚINSTALL_LOCK_TIMEOUT_SECONDSr(   rY   ru   r{   r�   r€   r²   r©   r”   r   r   r   Ú<module>rÅ      s¨   ðÙ NÝ "ã Û Ý $ß /Û Û Û Û 	Ý Û Û Û ç WÑ W÷ó ð ×Ò˜Ó!€ð  $Ð ð ðÐ;Wö ó ðõ,õ@!`õH!õ/õ ðFÀ5÷ õ6:÷
r   