
    	D,jk#                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dlm	Z	 d dl
mZ h dZ G d d          Z G d d	e          Z G d
 de          ZddZd Zd Zd ZddZddZddZd Zd Zd Zd Zd ZddZd ZdS )    N)Path)dump)Spinner>   .bmp.gif.jpg.pdf.png.jpeg.tiff.webpc                   ,    e Zd Zd Zd Zd Zd Zd ZdS )IgnorantTemporaryDirectoryc                     t           j        dk    rt          j        d          | _        d S t          j                    | _        d S )N)   
   T)ignore_cleanup_errors)sysversion_infotempfileTemporaryDirectorytemp_dirselfs    Z/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/aider/utils.py__init__z#IgnorantTemporaryDirectory.__init__   s=    w&&$7dSSSDMMM$799DMMM    c                 4    | j                                         S N)r   	__enter__r   s    r   r    z$IgnorantTemporaryDirectory.__enter__   s    }&&(((r   c                 .    |                                   d S r   )cleanup)r   exc_typeexc_valexc_tbs       r   __exit__z#IgnorantTemporaryDirectory.__exit__   s    r   c                 v    	 | j                                          d S # t          t          t          f$ r Y d S w xY wr   )r   r"   OSErrorPermissionErrorRecursionErrorr   s    r   r"   z"IgnorantTemporaryDirectory.cleanup   sJ    	M!!#####.9 	 	 	DD	s    88c                 ,    t          | j        |          S r   )getattrr   )r   items     r   __getattr__z&IgnorantTemporaryDirectory.__getattr__#   s    t}d+++r   N)__name__
__module____qualname__r   r    r&   r"   r.    r   r   r   r      s_        : : :) ) )    , , , , ,r   r   c                   2     e Zd Z fdZ fdZ fdZ xZS )ChdirTemporaryDirectoryc                     	 t          j                    | _        n# t          $ r
 d | _        Y nw xY wt	                                                       d S r   )osgetcwdcwdFileNotFoundErrorsuperr   )r   	__class__s    r   r   z ChdirTemporaryDirectory.__init__(   s[    	y{{DHH  	 	 	DHHH	 	s    00c                     t                                                      }t          j        t	          | j        j                                                             |S r   )r:   r    r6   chdirr   r   nameresolve)r   resr;   s     r   r    z!ChdirTemporaryDirectory.__enter__0   sF    gg!!
dm())1133444
r   c                     | j         r+	 t          j        | j                    n# t          $ r Y nw xY wt	                                          |||           d S r   )r8   r6   r=   r9   r:   r&   r   r#   r$   r%   r;   s       r   r&   z ChdirTemporaryDirectory.__exit__5   si    8 	""""$   7F33333s   $ 
11)r/   r0   r1   r   r    r&   __classcell__r;   s   @r   r4   r4   '   sj                
4 4 4 4 4 4 4 4 4r   r4   c                   (     e Zd Z fdZ fdZ xZS )GitTemporaryDirectoryc                 p    t                                                      }t          |          | _        |S r   )r:   r    	make_reporepo)r   dnamer;   s     r   r    zGitTemporaryDirectory.__enter__?   s,    !!##e$$	r   c                 R    | ` t                                          |||           d S r   )rI   r:   r&   rB   s       r   r&   zGitTemporaryDirectory.__exit__D   s*    I7F33333r   )r/   r0   r1   r    r&   rC   rD   s   @r   rF   rF   >   sQ            
4 4 4 4 4 4 4 4 4r   rF   c                 6   dd l }| sd} |j                            |           }|                                                    ddd                                           |                                                    ddd                                           |S )Nr   .userr>   z	Test Useremailztestuser@example.com)gitRepoinitconfig_writer	set_valuerelease)pathrP   rI   s      r   rH   rH   I   s    JJJ 8==D""66;??GGIII""674JKKSSUUUKr   c                 b     t                      t           fdt          D                       S )z
    Check if the given file name has an image file extension.

    :param file_name: The name of the file to check.
    :return: True if the file is an image, False otherwise.
    c              3   B   K   | ]}                     |          V  d S r   )endswith).0ext	file_names     r   	<genexpr>z is_image_file.<locals>.<genexpr>]   s1      CC3y!!#&&CCCCCCr   )stranyIMAGE_EXTENSIONS)r\   s   `r   is_image_filera   U   s4     IICCCC2BCCCCCCr   c                 b    t          |                                           } t          |           S )zEGives an abs path, which safely returns a full (not 8.3) windows path)r   r?   r^   )r@   s    r   safe_abs_pathrc   `   s$    
s))



Cs88Or   c                     g }|                                 D ]}|                    |  d|            d                    |          S )N 
)
splitlinesappendjoin)rolecontentformatted_lineslines       r   format_contentrn   f   sY    O""$$ 1 1$////000099_%%%r   c                    g }|r,|                     |                                 dd            | D ]}|                     d           |d                                         }|                    d          }t          |t                    r|D ]}t          |t
                    r|                                D ]q\  }}t          |t
                    r:d|v r6|                     | d|                                 d|d                     T|                     | d| d|            r|                     | d|            n8t          |t                    r#|                     t          ||                     |                    d	          }	|	r|                     | d
|	            d
                    |          S )Nre   z2**************************************************z-------rj   rk   urlz URL: z: function_callz Function Call: rf   )rh   upperget
isinstancelistdictitems
capitalizer^   rn   ri   )
messagestitleoutputmsgrj   rk   r-   keyvaluerq   s
             r   format_messagesr   m   s   F 53333444 D Di   6{  ""'')$$gt$$ 	9 4 4dD)) 4&*jjll D D
U%eT22 Du~~"MMT*Z*ZCNN4D4D*Z*ZERWL*Z*Z[[[["MMT*B*BC*B*B5*B*BCCCC	D MMT"2"2D"2"233334 %% 	9MM.w7788800 	DMMTBB=BBCCC99Vr   c                 j    t          | |          }t          |           |rt          |           d S d S r   )r   printr   )ry   rz   	functionsformatted_outputs       r   show_messagesr      sB    &x77	
 Y r   Fc                 r  	 g 	g }g }g }|                      d          }	fd}|D ]}|                    d          r|                    d          r: |d|           g } |d|           g }|                    |dd                     g|                    d	          r< |d|           g } |d
|           g }|dd          }|                    |            |d|           g } |d
|           g }|                    |            |d|            |d|           |sd 	D             		S )NT)keependsc                     d                     |          }|                                r&                    t          | |                     d S d S )N )rj   rk   )ri   striprh   rv   )rj   linesry   s     r   
append_msgz/split_chat_history_markdown.<locals>.append_msg   sQ    ;;== 	<OODdE:::;;;;;	< 	<r   z# z> 	assistantrN      z#### tool   c                 *    g | ]}|d          dk    |S )rj   r   r2   )rZ   ms     r   
<listcomp>z/split_chat_history_markdown.<locals>.<listcomp>   s&    ???!1V9+>+>A+>+>+>r   )rg   
startswithrh   )
textinclude_toolrN   r   r   r   r   rm   rk   ry   s
            @r   split_chat_history_markdownr      s   HDIDOOTO**E< < < < <
   ??4   	??4   	J{I...IJvt$$$DKKQRR!!! ??7## 	J{I...IJvt$$$D122hGKK   
64   
64   J{I&&&Jvt @??x???Or   c                 6    t           j        ddddddg}|| z  }|S )N-mpipinstall	--upgradez--upgrade-strategyzonly-if-needed)r   
executable)argscmds     r   get_pip_installr      s0    C 4KCJr   c           
      H   t                       t          dt          |                      t          j        dddg}	 t	          j        |dd           n# t          $ r Y nw xY w	 g }t	          j        | t          j        t          j	        dddt          j
        j        d	
          }t          d          }	 |j
                            d          }|sn*|                    |           |                                 G|                                 |                                }d                    |          }|dk    r!t          d           t                       d|fS n.# t          j        $ r}t          d|            Y d }~nd }~ww xY wt          d           d|fS )NzInstalling:r   	ensurepipr   TF)capture_outputcheck   replace)stdoutstderrr   bufsizeuniversal_newlinesencodingerrorszInstalling...r   r   zInstallation complete.z
Error running pip install: z
Installation failed.
)r   printable_shell_commandr   r   
subprocessrun	ExceptionPopenPIPESTDOUTr   r   r   readrh   stependwaitri   CalledProcessError)r   ensurepip_cmdr{   processspinnercharreturn_codees           r   run_installr      s   	GGG	-055666 ^T;DM}TGGGGG    3"?$#Z(	
 	
 	
 /**	>&&q))D MM$LLNNN	 	llnn!*+++GGG< 
 ( 3 3 31a11222222223 

$%%%&=s*   A 
A"!A"&C;E# #F2F		Fc                    	 t          |           dk    r?t          t          j                            t          |           d                             S | r9t          t          j                            t          |                               S n# t          $ r Y nw xY w	 t          t          j                              S # t          $ r Y dS w xY w)Nr   r   rM   )
lenrc   r6   rV   dirnameru   
commonpathr(   r7   r9   )
abs_fnamess    r   find_common_rootr     s    z??a j1A1A!1D!E!EFFF 	G !3!3D4D4D!E!EFFF	G   RY[[)))   sss*   AB :B 
BB!C 
CCc                 \    | dk     r|  S | dk     r	| dz  ddS t          | dz             dS )Ni  i'  z.1fk)round)counts    r   format_tokensr     sM    t||z	$,%%%%%%%((((r   c                     t          |           } 	 | j                            dd           |                                  dS # t          $ r Y dS w xY w)NT)parentsexist_okF)r   parentmkdirtouchr(   )fnames    r   
touch_filer     sa    KKE4$777t   uus   0A 
AAc                 2   |r/	 t          |           dS # t          t          t          f$ r Y nw xY wt	          |          }|r|                     |           |rXt          j                    dk    rA|                     d           t                       t          t          |                     d S |                     ddt          |                    sd S t          |          \  }}|r\|sdS 	 t          |           dS # t          t          t          f$ r,}|                     t          |                     Y d }~nd }~ww xY w|                     |           t                       t          d           t          t          |                     d S )NTWindowszRun this command to update:zRun pip install?y)defaultsubjectz2Install failed, try running this command manually:)
__import__ImportErrorModuleNotFoundErrorRuntimeErrorr   tool_warningplatformsystemtool_outputr   r   confirm_askr   
tool_errorr^   )	iomodulepromptpip_install_cmdself_updater   successr{   errs	            r   check_pip_install_extrar   '  s    	v40,? 	 	 	D	 /
*
*C  
 x((I55
4555%c**+++>>,cCZ[^C_C_>`` !#&&OGV  	4	v40,? 	 	 	MM#c((###DDDD	 MM&	GGG	
>???	
!#
&
&'''''s$    //2D E"EEc                 *    t          j        |           S )z
    Convert a list of command arguments to a properly shell-escaped string.

    Args:
        cmd_list (list): List of command arguments.

    Returns:
        str: Shell-escaped command string.
    )oslexri   )cmd_lists    r   r   r   O  s     :hr   r   )NN)F)r6   r   r   r   r   pathlibr   r   
aider.dumpr   aider.waitingr   r`   r   r4   rF   rH   ra   rc   rn   r   r   r   r   r   r   r   r   r   r   r2   r   r   <module>r      s   				      



               ! ! ! ! ! !VVV , , , , , , , ,.4 4 4 4 48 4 4 4.4 4 4 4 43 4 4 4	 	 	 	D D D  & & &   8   0 0 0 0f  / / /d   ) ) )  %( %( %( %(P
  
  
  
  
 r   