Ë
    âß²jÕ  ã            
       ó¸   — d Z ddlZddlmZ  G d„ de«      Zdedee   fd„Zd	ee   d
edee   fd„Zdede	de	d
eddf
d„Z
d
edeedf   dee   ddfd„Zdefd„Zy)zLDirectory initialization and storage diagnostics for the active Hermes home.é    N)ÚPathc                   ó   — e Zd ZdZy)ÚHomeInitializationErrorz?The home skeleton is unavailable, not an invalid YAML document.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú;/home/ubuntu/.hermes/hermes-agent/hermes_cli/config_home.pyr   r      s   „ ÚIr   r   ÚpathÚreturnc                 ó~   — g t        | j                  «      ¢| ‘­D �cg c]  }|j                  «       sŒ|‘Œ c}S c c}w )N)ÚreversedÚparentsÚ
is_symlink)r   Úparts     r   Ú_directory_linksr      s2   € Ø<œx¨¯©Ó5Ð<°tÑ<ÖR�TÀÇÁÕ@QŠDÒRÐRùÒRs   �:³:ÚlinksÚhomec                 óT   — | D �cg c]  }||k(  s||j                   v sŒ|‘Œ c}S c c}w )a  Keep only the links that make the operator the owner of the home's permissions.

    That boundary is the home itself and anything under it. A link *above* the home
    (macOS ``/tmp`` -> ``/private/tmp``, ``/var`` -> ``/private/var``, or any aliased parent
    the user happens to live in) says nothing about who owns :data:`home`, and treating it as
    an operator-owned link left a fresh home and its ``cron``/``sessions``/``logs``/``memories``
    subdirectories at the default ``0o755`` instead of ``0o700``.
    )r   )r   r   Úlinks      r   Ú_operator_owned_linksr      s)   € ð #ÖK�T d¨d¢l°d¸d¿l¹lÒ6JŠDÒKÐKùÒKs   …%ž%ÚcreateÚsecurec                ó¢  — ddl m} d}	 t        | «      }dj                  d„ |D «       «      }|D ]   }|j	                  «       rŒt        d|› �«      ‚ |r| j                  dd¬«       n| j	                  «       st        d	| › �«      ‚|rt        ||«      s	 || «       y y y # t        $ r&}t        d
| › d|› d�|rd|› d�ndz   dz   «      |‚d }~ww xY w)Nr   )Ú_secure_dirÚ z; c              3   óF   K  — | ]  }|› d |j                  «       › �–— Œ y­w)z -> N)Úreadlink)Ú.0r   s     r   ú	<genexpr>z$_ensure_directory.<locals>.<genexpr>!   s"   è ø€ ÒL¸d˜d˜V 4¨¯©«Ð'8Ô9ÑLùs   ‚!zDirectory link is unavailable: T)r   Úexist_okz#Required directory does not exist: z#Cannot initialize Hermes directory ú: z. zDirectory links: zÁCheck the directory/link target, mount availability and access permissions; restore the mount or repair the link before retrying. Hermes has not replaced the link or created its missing target.)
Úhermes_cli.configr   r   ÚjoinÚis_dirÚFileNotFoundErrorÚmkdirr   ÚOSErrorr   )	r   r   r   r   r   Údetailr   r   Úexcs	            r   Ú_ensure_directoryr-      sþ   € Ý-à€FðÜ  Ó&ˆØ—‘ÑLÀeÔLÓLˆàò 	RˆDØ—;‘;•=Ü'Ð*IÈ$ÈÐ(PÓQÐQð	Rñ Ø�J‰J˜t¨dˆJÕ3Ø—‘”Ü#Ð&IÈ$ÈÐ$PÓQÐQáÔ/°°tÔ<Ù˜Õð =ˆ6øäò Ü%Ø1°$°°r¸#¸¸bÐAÙ17Ð" 6 (¨"Ñ-¸RñAðNñNó
ð ð	ûðús   Š8B ÁAB Â	CÂ(!C	Ã	CÚsubdirs.Úensuredc                 ó  — ddl m}m}  |«       }|rt        j                  d«      nd }	 t        | | | | ¬«       |rdn|}|D ]  }t        | |z  | | | ¬«       Œ |rt        | dz  dz  dd	| ¬«       	  || «       	 |�t        j                  |«       	 |j                  t        | «      t        | j                  «       «      f«       y # t        $ r}	t        d
| › d|	› d�«      |	‚d }	~	ww xY w# |�t        j                  |«       w w xY w)Nr   )Ú_ensure_default_soul_mdÚ
is_managedé   )r   r   r   )ÚcronÚsessionsÚlogsÚmemoriesr6   ÚcuratorTFzCannot initialize Hermes home r$   z4. Check storage availability and access permissions.)r%   r1   r2   ÚosÚumaskr-   r*   r   ÚupdateÚstrÚresolve)
r   r.   r/   r1   r2   ÚmanagedÚ	old_umaskÚrequiredÚsubdirr,   s
             r   Úinitialize_homerB   7   s  € ßEá‹l€GÙ#*”—‘˜”°€Ið Ü˜$¨7 {¸w¸;ÈTÕRÙ?FÑ;ÈGˆØò 	`ˆFÜ˜d V™m¸°KÈGÈÐZ^Ö_ð	`áÜ˜d V™m¨iÑ7ÀÈUÐY]Õ^ð	Ù# DÕ)ð Ð Ü�H‰H�YÕð ‡N�N”C˜“Iœs 4§<¡<£>Ó2Ð3Õ4øô ò 	Ü)Ø0°°°b¸¸ð >Eð Eóð ðûð	ûð Ð Ü�H‰H�YÕð !ús*   ªA	C- Á4C	 Ã		C*ÃC%Ã%C*Ã*C- Ã-Dr,   c                 óh   — ddl m} t        | t        t        f«      r |dd| › �d«      S  |ddd«      S )Nr   )ÚConfigIssueÚerrorzHermes storage is unavailable: zXCheck the reported path, link target, mount and permissions; keep config.yaml unchanged.zCould not load config.yamlz+Run 'hermes setup' to create a valid config)r%   rD   Ú
isinstancer   r*   )r,   rD   s     r   Úconfig_load_issuerG   R   sE   € Ý-ä�#Ô/´Ð9Ô:ÙØÐ6°s°eÐ<Øfó
ð 	
ñ �wÐ <Ð>kÓlÐlr   )r	   r9   Úpathlibr   ÚRuntimeErrorr   Úlistr   r   Úboolr-   Útupler<   ÚsetrB   Ú	ExceptionrG   r
   r   r   ú<module>rO      sÁ   ðÙ Rã 	Ý ôJ˜lô JðS˜4ð S D¨¡Jó Sð	L  d¡ð 	L°4ð 	L¸DÀ¹Jó 	Lð˜Dð ¨Tð ¸4ð Àtð ÐPTó ð85˜$ð 5¨¨s°C¨x©ð 5À3ÀsÁ8ð 5ÐPTó 5ð6m˜9ô mr   