+
    lHàj6  ã                  óœ   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 Rt
R R lt ! R R]4      tR	 R
 ltR R ltR R lt. ROtR# )a  In-process write primitives for the local POSIX backend.

``write_file`` asked the backend shell three questions per write (pre-write probe, atomic write,
sha256 verification): three ``bash`` spawns, ~100 ms on a warm host before any real work.  On the
local POSIX backend the file is on this host, so ``ShellFileOperations`` answers them here instead,
under the same gate as the native read path (``_native_read_enabled``; ``HERMES_NATIVE_FILE_READ=0``
turns both off).  Semantics mirror the shell scripts they replace; anything they cannot answer
(a FIFO, a device, an unexpected error) returns None and the caller takes the shell path.
)ÚannotationsN)ÚOptionals   ï»¿c               ó    € V ^8„  d   QhRRRR/# )é   ÚpathÚstrÚreturnzOptional[int]© )Úformats   "ÚA/home/ubuntu/.hermes/hermes-agent/tools/file_operations_native.pyÚ__annotate__r      s   € ÷ 
ñ 
˜ð 
 ñ 
ó    c           	     óX  €  \         P                  ! V \         P                  \        \         R^ 4      ,          4      p\
        P                  ! \         P                  ! T4      P                  4      '       g"   \         P                  ! T4       \        T 4      hT#   \         d     R# i ; i)z·fd of ``path`` when it is a regular file; None when missing; raises ``_NotRegular`` otherwise.
One lookup with O_NONBLOCK, judged by fstat: a FIFO swapped in never blocks this thread.Ú
O_NONBLOCKN)ÚosÚopenÚO_RDONLYÚgetattrÚFileNotFoundErrorÚstatÚS_ISREGÚfstatÚst_modeÚcloseÚ_NotRegular)r   Úfds   & r   Ú_open_regularr      sw   € ðÜ�WŠW�Tœ2Ÿ;™;¬´°\À1Ó)EÕEÓFˆô �<Š<œŸš ›×,Ñ,×-Ò-Ü
�Š�ŒÜ˜$ÓÐØ€Iøô ô Úðús   ‚;B ÂB)Â(B)c                  ó   € ] tR t^#tRtR# )r   r	   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r	   r   r   r   r   #   s   † Ûr   r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   Ú	want_textÚboolr   z&Optional[tuple[bool, Optional[bytes]]]r	   )r
   s   "r   r   r   '   s"   € ÷ ,ñ ,�ð , ð ,Ð)Oñ ,r   c                ó*  €  \        V 4      pVf   R# \        VR4      ;_uu_ 4       pV'       d   VP                  4       MVP                  R4      pRRR4       XP	                  \
        4      T3#   + '       g   i     L'; i  \         d     R# i ; i)zÅ``(has_bom, body)`` for a write target: ``body`` is the whole file when ``want_text`` else its
first 4 KB (the line-ending sample); ``(False, None)`` when the file is missing; None = ask the shell.NÚrbi   )FN)r   r   ÚreadÚOSErrorÚ
startswithÚ	_UTF8_BOM)r   r$   r   ÚfhÚdatas   &&   r   Úprober.   '   st   € ðÜ˜4Ó ˆØŠ:ØÐÜ�"�d�^Œ^˜rß )�2—7‘7”9¨r¯w©w°t«}ˆD÷ ð �?‰?œ9Ó% tÐ+Ð+÷	 �^ûäô Úðús3   ‚B “B §*A0ÁB Á0B 	Á;B Â B ÂBÂBc               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r-   Úbytesr   úOptional[str]r	   )r
   s   "r   r   r   5   s!   € ÷ %ñ %�sð % %ð %¨Mñ %r   c           	     ó¼  € \         P                  P                  V 4      '       d    \         P                  P                  V 4      MT p\         P                  P	                  V4      ;'       g    Rp \         P
                  ! VRR7        \        P                  ! \         P                  ! V4      P                  4      p\         P                  P                  VR\        P                  ! ^4       24      p\         P                  ! T\         P                  \         P                  ,          \         P                   ,          \#        \         R^ 4      ,          Vf   RMR4      p Te    \         P*                  ! Yd4       \        TR
4      ;_uu_ 4       pTP-                  T4       RRR4       \         P.                  ! YR4       R#   \         d    Rp ELi ; i  \$         d:   pTP&                  ;'       g    T R	TP(                  ;'       g    T 2u Rp?# Rp?ii ; i  \$         d     L®i ; i  + '       g   i     L”; i  \$         d�   p\0        P2                  ! \$        4      ;_uu_ 4        \         P4                  ! T4       RRR4       M  + '       g   i     M; iTP&                  ;'       g    T R	TP(                  ;'       g    T 2u Rp?# Rp?ii ; i)aÝ  Replace ``path`` with ``data`` atomically; None on success, else an error message.

Same contract as the shell script: a symlink target is written through (the link survives),
parent directories are created, the temp file lives in the target's directory so the rename is
atomic, an existing target's mode is kept and a new one gets the umask default (``O_CREAT`` with
0o666 applies the process umask itself), and the temp is removed on every failure.

The temp holds its final mode before the first byte lands: an existing target's temp is created
0o600 and ``fchmod``-ed to the target's mode, so a private file's new contents are never readable
through a wider temp (the shell script's ``mktemp`` 0600 temp gave the same guarantee).Ú.T)Úexist_okNz.hermes-tmp.Ú	O_CLOEXECi¶  i€  z: Úwb)r   r   ÚislinkÚrealpathÚdirnameÚmakedirsr   ÚS_IMODEr   r   ÚjoinÚsecretsÚ	token_hexr   ÚO_WRONLYÚO_CREATÚO_EXCLr   r)   ÚstrerrorÚfilenameÚfchmodÚwriteÚreplaceÚ
contextlibÚsuppressÚunlink)	r   r-   ÚtargetÚparentÚmodeÚtmpr   Úer,   s	   &&       r   Úatomic_writerO   5   sý  € ô (*§w¡w§~¡~°d×';Ò';ŒR�W‰W×Ñ˜dÔ#À€FÜ�W‰W�_‰_˜VÓ$×+Ð+¨€Fð
<Ü
�Š�F TÕ*ð	Ü"&§,¢,¬r¯wªw°v«×/FÑ/FÓ"GˆDô �g‰g�l‰l˜6 \´'×2CÒ2CÀAÓ2FÐ1GÐ#HÓIˆÜ�WŠW�Sœ"Ÿ+™+¬¯
©
Õ2´R·Y±YÕ>ÄÌÈ[ÐZ[ÓA\Õ\Ø"šl‘U°ó7ˆð<ØÒðÜ—	’	˜"Ô#ô �"�d�^Œ^˜rØ�H‰H�TŒN÷ ä
�
Š
�3Ôñ
 øô) !ô 	Ø‹Dð	ûô
 ô <Ø—*‘*—/�/ Ð" " Q§Z¡Z×%9Ð%9°6Ð$:Ð;Õ;ûð<ûô ô Ùðúç�^ûô ô <Ü× Ò ¤×)Õ)Ü�IŠI�cŒN÷ *×)×)Ð)úà—*‘*—/�/ Ð" " Q§Z¡Z×%9Ð%9°6Ð$:Ð;Õ;ûð<úsÇ   Á1G Â
4G Â>B#G Å"I Å'H Å=I ÆH/Æ#I ÇGÇG ÇGÇG ÇHÇ")HÈHÈHÈHÈH,È)I È+H,È,I È/H?	È:I ÉKÉ"KÉ/JÊ	KÊJÊKÊ5KËKËKËKc               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   r1   r	   )r
   s   "r   r   r   ]   s   € ÷ ñ �Cð ˜Mñ r   c                ód  a€  \        V 4      pVf   R# \        P                  ! 4       p\        VR4      ;_uu_ 4       o\	        V3R lR4       F  pVP                  V4       K  	  RRR4       VP                  4       #   + '       g   i     TP                  4       # ; i  \         d     R# i ; i)zQHex sha256 of the regular file at ``path``; None when it cannot be read natively.Nr'   c                 ó&   <€ S P                  R4      # )é   i   )r(   )r,   s   €r   Ú<lambda>Úsha256_of.<locals>.<lambda>e   s   ø€  b§g¡g¨gÔ&6r   r   )r   ÚhashlibÚsha256r   ÚiterÚupdater)   Ú	hexdigest)r   r   ÚdigestÚchunkr,   s   &   @r   Ú	sha256_ofr]   ]   s“   ø€ ð	Ü˜4Ó ˆØŠ:ÙÜ—’Ó!ˆÜ�"�d�^Œ^˜rÜÔ6¸Ö<�Ø—‘˜eÖ$ñ =÷ ð
 ×ÑÓÐ÷ Ž^ð
 ×ÑÓÐûô ô Úðús3   ƒB  ”)B  ½)A>Á&B  Á>B	Â	B  ÂB  Â B/Â.B/)rO   r.   r]   )Ú__doc__Ú
__future__r   rG   rV   r   r=   r   Útypingr   r+   r   r)   r   r.   rO   r]   Ú__all__r	   r   r   Ú<module>rb      sN   ðñõ #ã Û Û 	Û Û Ý à€	õ
ô	�'ô 	õ,õ%õPò 1‚r   