+
    Ki                         R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHt ^ RI	t	]
! 0 Rm4      tRR R lltRR R lltR	^/R
 R lltRRRRRR/R R lltR# )z*Shared utility functions for hermes-agent.N)Path)AnyUnionFc                <    V ^8  d   QhR\         R\        R\        /# )   valuedefaultreturn)r   bool)formats   ""/home/ubuntu/hermes-agent/utils.py__annotate__r      s!      3  $     c                    V f   V# \        V \        4      '       d   V # \        V \        4      '       d&   V P                  4       P	                  4       \
        9   # \        V 4      # )zDCoerce bool-ish values using the project's shared truthy string set.)
isinstancer
   strstriplowerTRUTHY_STRINGS)r   r   s   &&r   is_truthy_valuer      sO    }%%{{}""$66;r   c                <    V ^8  d   QhR\         R\         R\        /# )r   namer   r	   )r   r
   )r   s   "r   r   r      s&     D D# D DT Dr   c                D    \        \        P                  ! W4      RR7      # )zBReturn True when an environment variable is set to a truthy value.F)r   )r   osgetenv)r   r   s   &&r   env_var_enabledr      s    299T3UCCr   indentc          
      n    V ^8  d   QhR\         \        \        3,          R\        R\        R\        RR/# )r   pathdatar   dump_kwargsr	   N)r   r   r   r   int)r   s   "r   r   r      sC     / /
T	
/
/ 	/
 / 
/r   c          	        \        V 4      p V P                  P                  RRR7       \        P                  ! \        V P                  4      RV P                   R2RR7      w  rE \        P                  ! VRRR	7      ;_uu_ 4       p\        P                  ! VV3R
VRR/VB  VP                  4        \        P                  ! VP                  4       4       RRR4       \        P                  ! WP4       R#   + '       g   i     L(; i  \         d+     \        P                   ! T4       h   \"         d     h i ; ii ; i)a  Write JSON data to a file atomically.

Uses temp file + fsync + os.replace to ensure the target file is never
left in a partially-written state. If the process crashes mid-write,
the previous version of the file remains intact.

Args:
    path: Target file path (will be created or overwritten).
    data: JSON-serializable data to write.
    indent: JSON indentation (default 2).
    **dump_kwargs: Additional keyword args forwarded to json.dump(), such
        as default=str for non-native types.
Tparentsexist_ok._.tmpdirprefixsuffixwutf-8encodingr   ensure_asciiFN)r   parentmkdirtempfilemkstempr   stemr   fdopenjsondumpflushfsyncfilenoreplaceBaseExceptionunlinkOSError)r   r   r   r    fdtmp_pathfs   &&$,   r   atomic_json_writerD      s   ( :DKKdT2##499+QLB
YYr311QII  #	
  GGIHHQXXZ  2 	

8" 21  	IIh 	  		sI   &!D AC8D 8D	D E D.-E .D<9E ;D<<E default_flow_style	sort_keysextra_contentc                    V ^8  d   QhR\         \        \        3,          R\        R\        R\        R\        R,          RR/# )r   r   r   rE   rF   rG   Nr	   )r   r   r   r   r
   )r   s   "r   r   r   Q   sQ     - -
T	
-
- 	-
 - :- 
-r   c          	        \        V 4      p V P                  P                  RRR7       \        P                  ! \        V P                  4      RV P                   R2RR7      w  rV \        P                  ! VRRR	7      ;_uu_ 4       p\        P                  ! WW#R
7       V'       d   VP                  V4       VP                  4        \        P                  ! VP                  4       4       RRR4       \        P                  ! W`4       R#   + '       g   i     L(; i  \          d+     \        P"                  ! T4       h   \$         d     h i ; ii ; i)aB  Write YAML data to a file atomically.

Uses temp file + fsync + os.replace to ensure the target file is never
left in a partially-written state.  If the process crashes mid-write,
the previous version of the file remains intact.

Args:
    path: Target file path (will be created or overwritten).
    data: YAML-serializable data to write.
    default_flow_style: YAML flow style (default False).
    sort_keys: Whether to sort dict keys (default False).
    extra_content: Optional string to append after the YAML dump
        (e.g. commented-out sections for user reference).
Tr#   r&   r'   r(   r)   r-   r.   r/   )rE   rF   N)r   r2   r3   r4   r5   r   r6   r   r7   yamlr9   writer:   r;   r<   r=   r>   r?   r@   )r   r   rE   rF   rG   rA   rB   rC   s   &&$$$   r   atomic_yaml_writerL   Q   s   , :DKKdT2##499+QLB
YYr311QIId2DZ&GGIHHQXXZ  2 	

8" 21  	IIh 	  		sI   &!D  A&D-D  D	D   E,EEEEEE>   1onyestrue)F) )__doc__r8   r   r4   pathlibr   typingr   r   rJ   	frozensetr   r   r   rD   rL    r   r   <module>rW      sj    0  	     56D
/ 	/d-  %	-
 - !%- -r   