
    	D,j                        d dl Z 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m	Z	 d dl
mZ d dlZd dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZmZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z, ddl-m-Z-  G d de.          Z/ G d d          Z0d Z1d Z2d Z3d Z4e5dk    r e4            Z6 ej7        e6           dS dS )    N)OrderedDict)
expanduserPath)Image	ImageGrab)
CompletionPathCompleter)Document)modelspromptsvoice)pipe_editor)format_settings)Helpinstall_help_extraCommandCompletionException)litellm)ANY_GIT_ERROR)run_cmd)Scraperinstall_playwright)is_image_file   )dumpc                       e Zd ZddZdS )SwitchCoderNc                 "    || _         || _        d S N)kwargsplaceholder)selfr"   r!   s      ]/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/aider/commands.py__init__zSwitchCoder.__init__   s    &    r    )__name__
__module____qualname__r%    r&   r$   r   r      s(        ' ' ' ' ' 'r&   r   c                      e Zd ZdZdZd Z	 	 	 	 	 	 	 	 	 dNdZd Zd Zd Z	d	 Z
d
 Zd ZdOdZd Zd Zd Zd Zd Zd Zd ZdPdZdPdZdQdZd Zd Zd Zd Zd Zd Zd ZdRdZdRd Z d! Z!d" Z"d# Z#d$ Z$d% Z%d& Z&dRd'Z'd( Z(d) Z)dOd*Z*d+ Z+d, Z,d- Z-d. Z.d/ Z/d0 Z0d1 Z1d2 Z2d3 Z3d4 Z4d5 Z5d6 Z6d7 Z7dPd8Z8d9 Z9d: Z:d; Z;d< Z<d= Z=d> Z>d? Z?d@ Z@dA ZAdB ZBdC ZCdD ZDdE ZEdF ZFdG ZGdH ZHdRdIZIdRdJZJdK ZKdL ZLdPdMZMdS )SCommandsNc                     t          | j        d | j        | j        | j        | j        | j        | j        | j        	  	        S )N)voice_language
verify_sslargsparserverboseeditororiginal_read_only_fnames)	r,   ior.   r/   r0   r1   r2   r3   r4   r#   s    r$   clonezCommands.clone(   sF    G.;L;&*&D

 

 

 
	
r&   TFc                     || _         || _        || _        || _        |	| _        || _        |dk    rd }|| _        || _        || _        d | _	        |
| _
        t          |pg           | _        d S )Nauto)r5   coderr1   r0   r2   r/   r.   voice_formatvoice_input_devicehelpr3   setr4   )r#   r5   r:   r.   r<   r;   r/   r0   r1   r2   r3   r4   s               r$   r%   zCommands.__init__5   s     
	$V##!N,("4	 *--F-L")M)M&&&r&   c                    |                                 }|sHd                    | j                                                  }| j                            |           dS t          j        || j        j        j	        j
        | j        j        j        j
                  }t          j        | j        |           | j        j        j        }| j        j        }|}||k    r|j        }t          ||          )z"Switch the Main Model to a new LLM
Neditor_model
weak_model)
main_modeledit_format)stripjoinr:   get_announcementsr5   tool_outputr   ModelrD   rB   namerC   sanity_check_modelsrE   r   )r#   r0   
model_nameannouncementsmodelold_model_edit_formatcurrent_edit_formatnew_edit_formats           r$   	cmd_modelzCommands.cmd_modelW   s     ZZ\\
 	 IIdj&B&B&D&DEEMG...F.;@z,7<
 
 

 	"47E222 !%
 5 A"j4-"777#/OUHHHHr&   c                     |                                 }t          j        | j        j        j        || j        j        j        j                  }t          j        | j        |           t          |          )z$Switch the Editor Model to a new LLMrA   rD   )
rF   r   rJ   r:   rD   rK   rC   rL   r5   r   r#   r0   rM   rO   s       r$   cmd_editor_modelzCommands.cmd_editor_modelr   sk     ZZ\\
J!&#z,7<
 
 

 	"47E222U++++r&   c                     |                                 }t          j        | j        j        j        | j        j        j        j        |          }t          j        | j        |           t          |          )z"Switch the Weak Model to a new LLMrA   rU   )
rF   r   rJ   r:   rD   rK   rB   rL   r5   r   rV   s       r$   cmd_weak_modelzCommands.cmd_weak_model~   sk     ZZ\\
J!&.;@!
 
 

 	"47E222U++++r&   c                 4   ddl m} |                                }t          t	          d |j        D                                 }t          g d          }||vr||vr|r| j                            d| d           n| j                            d           t          d |
                                D                       }|                                D ])\  }}| j                            d	|d
| d|            *| j                            d           |                                D ]-\  }}||vr$| j                            d	|d
| d|            .dS d}	|}
|dk    r| j        j        j        }
d}	n|dk    rd}	t          |
|	          )zSwitch to a new chat moder   )codersc              3      K   | ]W}t          |d d          |j        |j        r2|j                                                            d          d         ndfV  XdS )rE   Nr@   r   zNo description)getattrrE   __doc__rF   split).0r:   s     r$   	<genexpr>z)Commands.cmd_chat_mode.<locals>.<genexpr>   s        
 5-66%<AM_EM''))//55a88O_     r&   ))r=   z9Get help about using aider (usage, config, troubleshoot).)askz9Ask questions about your code without making any changes.)codez:Ask for changes to your code (using the best edit format).)	architectzPWork with an architect model to design code changes, and an editor to make them.)contextz:Automatically identify which files will need to be edited.zChat mode "z" should be one of these:
z"Chat mode should be one of these:
c              3   4   K   | ]}t          |          V  d S r    len)r`   formats     r$   ra   z)Commands.cmd_chat_mode.<locals>.<genexpr>   s(      #S#SFCKK#S#S#S#S#S#Sr&   z- <z : z
Or a valid edit format:
NTrc   Frb   )rE   summarize_from_coder)aiderr[   rF   r   sorted__all__r5   
tool_errorrI   maxkeysitemsr:   rD   rE   r   )r#   r0   r[   efvalid_formatsshow_formatsmax_format_lengthri   descriptionrk   rE   s              r$   cmd_chat_modezCommands.cmd_chat_mode   s/    	!     ZZ\\#  
 $^    	
 	
 #  
 
& ]""r'='= K""#P#P#P#PQQQQ##$IJJJ ##S#Sm>P>P>R>R#S#S#S S S'3'9'9';'; X X###$V$V2C$V$V$V$V$V$VWWWWG =>>>'4':':'<'< \ \#--G''(ZV(Z6G(Z(Z(Z(Z[(Z(Z[[[F#<<*/;K#(  5[[#( #!5
 
 
 	
r&   c                 B    t           j                                        }|S r    )r   
model_costrq   )r#   r   s     r$   completions_modelzCommands.completions_model   s    #((**r&   c                     |                                 }|rt          j        | j        |           dS | j                            d           dS )z#Search the list of available modelsz2Please provide a partial model name to search for.N)rF   r   print_matching_modelsr5   rI   r#   r0   s     r$   
cmd_modelszCommands.cmd_models   sR     zz|| 	V($77777G TUUUUUr&   c                    |                                 }|s| j                            d           dS | j                            d| d           | j        sqt          | j        dd          }|rd}n0t          | j                  }|s| j                            d           t          | j        j        || j
                  | _        | j                            |          pd	}d
| d|z   }|r|S | j                            d           | j        xj        t          d|          t          dd          gz  c_        dS )z;Scrape a webpage, convert to markdown and send in a messagezPlease provide a URL to scrape.Nz	Scraping ...disable_playwrightFz Unable to initialize playwright.)print_errorplaywright_availabler/    zHere is the content of z:

z... added to chat.userrolecontent	assistantOk.)rF   r5   ro   rI   scraperr]   r0   r   tool_warningr   r/   scraper:   cur_messagesdict)r#   r0   return_contenturlr   resr   s          r$   cmd_webzCommands.cmd_web   sq    jjll 	G@AAAF0000111| 	!(4H%!P!P! M(11 MG(()KLLL" G.%(?  DL ,%%c**0b6C666@ 	N0111
fg...k5111$
 	
r&   c                     |d         dv S )Nr   z/!r*   )r#   inps     r$   
is_commandzCommands.is_command   s    1v~r&   c                     |                     d          sJ |dd          }|                    dd          }t          | d| d           }|S )N/r   -_completions_raw_)
startswithreplacer]   )r#   cmdraw_completers      r$   get_raw_completionszCommands.get_raw_completions  sZ    ~~c"""""!""gkk#s##&>&>&>EEr&   c                     |                     d          sJ |dd          }|                    dd          }t          | d| d           }|sd S t           |                      S )Nr   r   r   r   completions_)r   r   r]   rm   )r#   r   funs      r$   get_completionszCommands.get_completions
  ss    ~~c"""""!""gkk#s##d0300$77 	Fccee}}r&   c                     g }t          |           D ]P}|                    d          s|dd          }|                    dd          }|                    d|z              Q|S )Ncmd_   r   r   r   )dirr   r   append)r#   commandsattrr   s       r$   get_commandszCommands.get_commands  sq    II 	' 	'D??6** qrr(C++c3''COOC#I&&&&r&   c                 &   |                     dd          }d| }t          | |d           }|s | j                            d| d           d S 	  ||          S # t          $ r+}| j                            d| d|            Y d }~d S d }~ww xY w)Nr   r   r   zError: Command z not found.zUnable to complete : )r   r]   r5   rI   r   ro   )r#   cmd_namer0   cmd_method_name
cmd_methoderrs         r$   do_runzCommands.do_run  s    ##C--+++T?D99
 	G G( G G GHHHF	H:d### 	H 	H 	HGFXFFFFGGGGGGGGG	Hs   
A 
B% BBc                    |                                                                 }|sd S |d         |t          |d                   d                                           }|                                 }fd|D             }||fS )Nr   c                 >    g | ]}|                               |S r*   )r   )r`   r   
first_words     r$   
<listcomp>z.Commands.matching_commands.<locals>.<listcomp>5  s*    WWWSCNN:<V<VWSWWWr&   )rF   r_   rh   r   )r#   r   wordsrest_inpall_commandsmatching_commandsr   s         @r$   r   zCommands.matching_commands,  s    		!!## 	F1X
s58}}'--//((**WWWWLWWW *h66r&   c                    |                     d          r8| j                            d           |                     d|dd                    S |                     |          }|d S |\  }}}t          |          dk    rC|d         dd          }| j                            d|            |                     ||          S ||v r=|dd          }| j                            d|            |                     ||          S t          |          dk    r2| j                            dd                    |                      d S | j                            d	|            d S )
N!command_runrunr   r   command_zAmbiguous command: z, zInvalid command: )	r   r:   eventr   r   rh   r5   ro   rG   )r#   r   r   r   r   r   commands          r$   r   zCommands.run8  s   >># 	/J]+++;;uc!""g...$$S));F25/:x !!Q&&'*122.GJ111222;;w111,,, nGJ111222;;w111"##a''GSTYY?P5Q5QSSTTTTTG?:??@@@@@r&   c                     	 |                      |           dS # t          $ r(}| j                            d|            Y d}~dS d}~ww xY w)zHCommit edits to the repo made outside the chat (commit message optional)zUnable to complete commit: N)raw_cmd_commitr   r5   ro   r#   r0   r   s      r$   
cmd_commitzCommands.cmd_commitQ  sv    	D%%%%% 	D 	D 	DGBSBBCCCCCCCCC	D    
AAAc                 F   | j         j        s| j                            d           d S | j         j                                        s| j                            d           d S |r|                                nd }| j         j                            || j                    d S )NNo git repository found.zNo more changes to commit.)messager:   )r:   repor5   ro   is_dirtyr   rF   commit)r#   r0   commit_messages      r$   r   zCommands.raw_cmd_commitX  s    z 	G9:::Fz'')) 	G  !=>>>F)-74
~TZHHHHHr&   r   c                      j         j        s j                            d           dS |s j                                         }|s* j         j        r j         j                                        }|s j                            d           dS  fd|D             }d}|D ]X}	  j         j                            |          }n[# t          $ rN} j                            d|             j        
                    t          |                     Y d}~wd}~ww xY w|s j        
                    |            j                            d| dd	          s j         j                                        r! j         j        r                     d
           |s j                             g g d          }|                    |           |                    |           t'                      |_        Z|rA j         j                                        r% j         j        r                     d
           dS dS dS dS )z=Lint and fix in-chat files or all dirty files if none in chatr   NzNo dirty files to lint.c                 D    g | ]}j                             |          S r*   )r:   abs_root_path)r`   fnamer#   s     r$   r   z%Commands.cmd_lint.<locals>.<listcomp>v  s)    FFFe$***511FFFr&   zUnable to lint zFix lint errors in ?y)defaultr   )r   done_messagesfnames)r:   r   r5   ro   get_inchat_relative_filesget_dirty_filesr   linterlintFileNotFoundErrorrI   strconfirm_askr   dirty_commitsr   r7   add_rel_fnamer   r>   
abs_fnamesauto_commits)r#   r0   r   
lint_coderr   errorsr   s   `      r$   cmd_lintzCommands.cmd_lintd  s    z 	G9:::F 	<Z99;;F  	7$*/ 	7Z_4466F 	G  !:;;;FFFFFvFFF
 	* 	*E*//66$   ""#<U#<#<===##CHH---
  G'''7&&'EU'E'E'Es&SS  z'')) $dj.F $### !Z--!#"$	 .  
 $$U+++NN6"""$'EEJ!! 	 $*/2244 	 9P 	 OOB	  	  	  	  	  	 s   %C
DADDc                 b    |                                   | j                            d           dS )zClear the chat historyzAll chat history cleared.N)_clear_chat_historyr5   rI   r~   s     r$   	cmd_clearzCommands.cmd_clear  s3     	  """788888r&   c                 L   t                      | j        _        | j        rlt                      }| j        j        D ]C}| j                            |          }|| j        v s	|| j        v r|                    |           D|| j        _        d S t                      | j        _        d S r    )r>   r:   r   r4   abs_read_only_fnamesget_rel_fnameadd)r#   to_keep	abs_fname	rel_fnames       r$   _drop_all_fileszCommands._drop_all_files  s     #
 ) 	4eeG!Z< + +	 J44Y??	!??? D$BBBKK	***.5DJ+++.1eeDJ+++r&   c                 6    g | j         _        g | j         _        d S r    )r:   r   r   r6   s    r$   r   zCommands._clear_chat_history  s    #%
 "$
r&   c                     |                                   |                                  | j                            d           dS )z)Drop all files and clear the chat historyz+All files dropped and chat history cleared.N)r   r   r5   rI   r~   s     r$   	cmd_resetzCommands.cmd_reset  sC      """IJJJJJr&   c                 ,   g }| j                                          | j                             | j         j        j                  }|d| j                             | j         j        j                  z   z  }t          d|          t          d| j                             | j         j        j                            g}| j         j                            |          }|	                    |ddf           | j         j
        | j         j        z   }|r7| j         j                            |          }|	                    |ddf           t          | j                                                   t          | j         j                  z
  }| j         j        rc| j         j                            | j         j        |          }|r7| j         j                            |          }|	                    |dd	f           d
}g }	| j         j        D ]}
| j                             |
          }| j                            |
          }t)          |          r | j         j                            |
          }n-| d| d|z   dz   }| j         j                            |          }|		                    || df           | j         j        D ]}
| j                             |
          }| j                            |
          }|Wt)          |          sH| d| d|z   dz   }| j         j                            |          }|		                    || ddf           |	                                 |                    |	           | j                            d| j         j        j         d           | j                                         dd}fd}t7          d |D                       }d|z  }d}d}|D ]~\  }}}||z  }|| j         j        j                            d          pdz  }||z  }|                    |          }| j                            d|dd ||           d| d|            | j                            d|z   dz   z             | j                            d|dd ||           d           | j         j        j                            d          pd}|sdS ||z
  }|dk    r)| j                            |  ||           d            nW|dk    r)| j                            |  ||           d!           n(| j                            |  ||           d"           | j                            |  ||           d#           dS )$z?Report on the number of tokens used by the current chat contextr@   systemr   zsystem messagesr   zchat historyzuse /clear to clearzrepository mapzuse --map-tokens to resizez```z{fence}
z/drop to removeNz (read-only)z%Approximate context window usage for z, in tokens:   	   c                 d    t          t          |           d                                        S )N,)ri   intrjust)vwidths    r$   fmtz Commands.cmd_tokens.<locals>.fmt  s'    #a&&#&&,,U333r&   c              3   @   K   | ]}t          |d                    V  dS )r   Nrg   )r`   rows     r$   ra   z&Commands.cmd_tokens.<locals>.<genexpr>  s,      33CF333333r&    r   g        input_cost_per_token$z7.4f=r   z tokens totalmax_input_tokensi   z# tokens remaining in context windowzG tokens remaining in context window (use /drop or /clear to make space)zG tokens remaining, window exhausted (use /drop or /clear to make space)z tokens max context window size) r:   choose_fencefmt_system_promptgpt_promptsmain_systemsystem_reminderr   rD   token_countr   r   r   r>   get_all_abs_filesr   repo_mapget_repo_mapr   r5   	read_textr   token_count_for_imager   sortextendrI   rK   rp   infogetljustro   )r#   r0   r   main_sysmsgstokensother_filesrepo_contentfencefile_resr   relative_fnamer   
cost_widthr   	col_widthcost_padtotal
total_costtkmsgtipcostlimit	remainingr   s                            @r$   
cmd_tokenszCommands.cmd_tokens  s/    
!!! ://
0F0RSSD4:77
8N8^____h111
44TZ5K5[\\  
 &22488

F-r2333 z'$**AA 	HZ*66t<<FJJ0EFGGG $*668899C
@U<V<VV: 	U:.;;DJ<QS^__L U.::<HH

F$46RSTTTZ* 		N 		NE!Z55e<<Ng''..G^,, D.DDUKK ,88u8887B[P.::7CCOOV%8:KLMMMM Z4 	^ 	^E!Z55e<<Ng''..G"=+H+H"+88u8887B[P.::7CCN)H)H)HJ[ \]]]

8\DJ4I4N\\\	
 	
 	
 	
	4 	4 	4 	4 	4 33s33333	#
 	G 	GLBSRKE.3778NOOTSTUD$J))I&&CG ED E E EB E E# E E E EFFFFC5:#5#9:;;;K
KKK##e**KKKLLL
%*../ABBGa 	FEM	tG8 `SS^^ ` ` `aaaa]]G )SS^^ ) ) )   
 G )SS^^ ) ) )   	xTUTTTUUUUUr&   c                     	 |                      |           dS # t          $ r(}| j                            d|            Y d}~dS d}~ww xY w)z0Undo the last git commit if it was done by aiderzUnable to complete undo: N)raw_cmd_undor   r5   ro   r   s      r$   cmd_undozCommands.cmd_undo)  v    	Bd##### 	B 	B 	BG@3@@AAAAAAAAA	Br   c                 	   | j         j        s| j                            d           d S | j         j                                        }|r|j        s| j                            d           d S | j         j                            d          }| j         j                            d                                          }|	                                pdgd         }|| j         j
        vr6| j                            d           | j                            d	           d S t          |j                  d
k    r%| j                            d|j         d           d S |j        d         }d |                    |          D             }|D ]}| j         j        j                            |          r!| j                            d| d            d S 	 |j        |          W# t"          $ r# | j                            d| d           Y  d S w xY w| j         j        j        j                            d          }| j         j        j        j        j        }		 | j         j        j        j                            d|	           }
d}n# t,          $ r d}Y nw xY w|r"||
k    r| j                            d           d S t/                      }t/                      }|D ]g}	 | j         j        j        j                            d|           |                    |           C# t,          $ r |                    |           Y dw xY w|r| j                            d| d           | j                            d           |D ]}| j                            d|             | j                            d           |D ]}| j                            d|             d S | j         j        j        j                            dd           | j                            d| d|            | j         j                            d          }| j         j                            d                                          }|	                                pdgd         }| j                            d| d|            | j         j        j        rt:          j        S d S ) Nr   z8This is the first commit in the repository. Cannot undo.T)shortz	(unknown)r   r   z;The last commit was not made by aider in this chat session.zXYou could try `/git reset --hard HEAD^` but be aware that this is a destructive command!r   zThe last commit z$ has more than 1 parent, can't undo.c                     g | ]	}|j         
S r*   )a_path)r`   items     r$   r   z)Commands.raw_cmd_undo.<locals>.<listcomp>L  s    $[$[$[TT[$[$[$[r&   )pathz	The file z; has uncommitted changes. Please stash them before undoing.zF was not in the repository in the previous commit. Cannot undo safely.HEADzorigin/FzOThe last commit has already been pushed to the origin. Undoing is not possible.zHEAD~1zError restoring z, aborting undo.zRestored files:  zUnable to restore files:z--softz	Removed: r  z	Now at:  )r:   r   r5   ro   get_head_commitparentsget_head_commit_shaget_head_commit_messagerF   
splitlinesaider_commit_hashesrI   rh   hexshadiffr   treeKeyErrorgit	rev_parseactive_branchrK   r   r>   checkoutr   resetrD   send_undo_replyr   undo_command_reply)r#   r0   last_commitlast_commit_hashlast_commit_messageprev_commitchanged_files_last_commitr   
local_headcurrent_branchremote_head
has_originrestored
unrestored	file_pathfilecurrent_head_hashcurrent_head_messages                     r$   r,  zCommands.raw_cmd_undo0  s]   z 	G9:::Fjo5577 	+"5 	GYZZZF:?>>T>JJ"joEEkRRXXZZ2==??GB4K4:#AAAG\]]]G   F{"##a''G[;#5[[[   F!)!,$[$[[=M=Mk=Z=Z$[$[$[!. 	 	Ez#,,%,88 ""bbbb    '''   ""$ $ $ $    Z_)-77??
-;@	*/.2<<=W~=W=WXXKJJ 	 	 	JJJ	  	[((""!    55UU
2 	* 	*I*
$(11(IFFFY''''  * * *y)))))*  	GM)MMMNNNG 1222  1 1##KKK0000G :;;;" 1 1##KKK0000F 	
 &&x:::P(8PP;NPPQQQ !JO??d?KK#zFF{SSYY[[ 4 ? ? A A IbT1MR(9RR<PRRSSS: 0 	.--	. 	.s6   G  (HH.J JJ?LL=<L=c                     	 |                      |           dS # t          $ r(}| j                            d|            Y d}~dS d}~ww xY w)z2Display the diff of changes since the last messagezUnable to complete diff: N)raw_cmd_diffr   r5   ro   r   s      r$   cmd_diffzCommands.cmd_diff  r.  r   c                    | j         j        s| j                            d           d S | j         j                                        }|| j                            d           d S t          | j         j                  dk     r|dz   }n| j         j        d         }|r||k    r| j                            d           d S | j                            d|d d          d	           | j         j	        rt          d
|            d S | j         j                            | j         j	        |d          }| j                            |           d S )Nr   z<Unable to get current commit. The repository might be empty.   ^z-No changes to display since the last message.zDiff since    r   z	git diff r5  )r:   r   r5   ro   r9  rh   commit_before_messager   rI   prettyr   diff_commitsprint)r#   r0   current_headr_  r>  s        r$   rX  zCommands.raw_cmd_diff  s_   z 	G9:::Fz::<<G]^^^Ftz/00144$03$6!!$(J$DR$H!$ 	(=(M(MG  !PQQQFH*?*CHHHIII: 	7 577888Fz++J!
 
 	dr&   c                 "    d|v r
d|vrd| d}|S )Nr  "r*   )r#   r   s     r$   quote_fnamezCommands.quote_fname  s'    %<<Cu,, LLLEr&   c           
   #   n   K   |j         }|                                d         }t          |t          |                    } fd}t	          |dd          }t          |           }g }	|                    ||          D ]U}
                     ||
j        z             }|	                    t          |||
j
        |
j        |
j                             V                                 }|D ]+}
||
v r%|	                    t          |
||
                     ,t          |	d	 
          }|D ]}
|
V  d S )N)cursor_positionc                  :     j         j        r j         j        gnd S r    )r:   rootr6   s   r$   	get_pathsz5Commands.completions_raw_read_only.<locals>.get_paths  s    (,
ADJO$$TAr&   FT)rl  only_directoriesr   )textstart_positiondisplaystyleselected_style)rn  ro  rp  c                     | j         S r    )rn  )cs    r$   <lambda>z4Commands.completions_raw_read_only.<locals>.<lambda>  s    16 r&   )key)text_before_cursorr_   r   rh   r
   r   rf  rn  r   r	   rp  rq  rr  completions_addrm   )r#   documentcomplete_eventrn  after_commandnew_documentrl  path_completeradjusted_start_positionall_completions
completionquoted_textadd_completionssorted_completionss   `             r$   completions_raw_read_onlyz"Commands.completions_raw_read_only  s     * 

R(  s=?Q?QRRR	B 	B 	B 	B 	B '"
 
 
 $'}#5#5"5  )88~VV 
	 
	J**=:?+JKKK""$#:&.$*#-#<      ..00) 	 	J
**&&''> *     $O9I9IJJJ - 	 	J	 	r&   c                      t           j                                                  }|t           j                                                  z
  } fd|D             }|S )Nc                 :    g | ]}                     |          S r*   rf  r`   fnr#   s     r$   r   z,Commands.completions_add.<locals>.<listcomp>  s'    666"!!"%%666r&   )r>   r:   get_all_relative_filesr   )r#   filess   ` r$   rx  zCommands.completions_add  s\    DJ557788DJ@@BBCCC6666666r&   c                     |                                 sg S 	 t          j                            |          rt	          |          g}nT	 t          t	           j        j                                      |                    }n# t          t          f$ r g }Y nw xY wn9# t          $ r,} j                            d| d|            g }Y d }~nd }~ww xY wg }|D ]}|t          |          z  } fd|D             } j        j        r, j        j                                        fd|D             }t          t#          t$          |                    }|S )NzError matching r   c                     g | ]@}|                     j        j                  !|                    j        j                  AS r*   )is_relative_tor:   rk  relative_tor  s     r$   r   z2Commands.glob_filtered_to_repo.<locals>.<listcomp>  sQ     
 
 
  11
NN4:?++
 
 
r&   c                 6    g | ]}t          |          v |S r*   )r   )r`   r  	git_filess     r$   r   z2Commands.glob_filtered_to_repo.<locals>.<listcomp>  s)    PPPB3r77i;O;OR;O;O;Or&   )rF   osr4  isabsr   listr:   rk  glob
IndexErrorAttributeError
ValueErrorr5   ro   expand_subdirr   get_tracked_filesmapr   )r#   patternraw_matched_filesr   matched_filesr  r   r  s   `      @r$   glob_filtered_to_repozCommands.glob_filtered_to_repo  s   }} 	I	#w}}W%% +%)']]O!!+(,T$*/-B-B-G-G-P-P(Q(Q%%"N3 + + +(*%%%+ 	# 	# 	#GAAACAABBB "	# # 	/ 	/B]2...MM
 
 
 
#
 
 
 :? 	Q
99;;IPPPP-PPPM3sM**++
s;   0B 9B B BB BB 
C)"CCc                 
   t                      }t          |          }|D ]}t          |                                          rt          |          }nt          | j        j                  |z  }| j        j        r>| j        j                            |          r| j        	                    d| d           |
                                rM|                                r#|                    t          |                     t          j        dd|          }|                     |          }|r|                    |           )dt          |          v sdt          |          v r| j                            d|            j|
                                r]|                                rI| j        j        r=| j                            d| d	           | j                            d
|            | j                            d| d| d          r	 |j                            dd           |                                 |                    t          |                     Q# t2          $ r+}| j                            d| d|            Y d}~d}~ww xY wt5          |          D ]}| j                            |          }	|	                    | j        j                  s:t;          |          s+| j                            d|	 d| j        j                    v| j        j        rJ| j        j                            |          r+| j        j        s| j                            d| d           |	| j        j         v r| j                            | d           |	| j        j!        v r| j        j        r}| j        j        "                    |          r^| j        j!        #                    |	           | j        j                             |	           | j                            d| d           | j                            d| d           t;          |          rV| j        j$        j%        &                    d          s2| j                            d| d| j        j$        j'         d           | j        (                    |	          }
|
| j                            d|            O| j        j                             |	           | j        )                    |	          }| j                            d | d!           | j        *                                 dS )"zEAdd files to the chat so aider can edit them or review them in detailz	Skipping z& due to aiderignore or --subtree-only.z([\*\?\[\]])z[\1]*r   z;No match, and cannot create file with wildcard characters: z
Directory z is not in git.z"You can add to git with: /git add zNo files matched 'z'. Do you want to create T)r8  exist_okzError creating file r   NzCan not add z, which is not within z
Can't add z which is in gitignorez+ is already in the chat as an editable fileMoved z- from read-only to editable files in the chatzCannot add z# as it's not part of the repositorysupports_visionCannot add image file  as the  does not support images.zUnable to read Added z to the chat)+r>   parse_quoted_filenamesr   is_absoluter:   rk  r   ignored_filer5   r   existsis_filer   r   resubr  updatero   is_dirrI   r   parentmkdirtouchOSErrorrm   r   r   r   git_ignored_fileadd_gitignore_filesr   r   path_in_reporemoverD   r  r  rK   r  r   check_added_files)r#   r0   all_matched_files	filenameswordr   r  ematched_fileabs_file_pathr   s              r$   cmd_addzCommands.cmd_add  s     EE*400	 '	L '	LDDzz%%'' 5T

TZ_--4z 4:?#?#?#F#F $$%^%^%^%^___||~~ >==?? %))#e**555vow== 66t<<M !((777c%jj  C3u::$5$5""YRWYY   ||~~ %,,.. TZ_ ""#F#F#F#FGGG##$P$P$PQQQw""#_#_#_W\#_#_#_`` LLL&&td&CCCKKMMM%))#e**5555 L L LG&&'Je'J'Jq'J'JKKKKKKKKLL ##455 /	3 /	3L J44\BBM ++DJO<< ]S_E`E` ""Y=YY
YY    
JO44\BB 
6
 ""#T#T#T#TUUU
 555""l#_#_#_```$*"AAA:? 	tz'C'CL'Q'Q 	J3::=IIIJ)--m<<<G''\\\\    G&&WlWWW    !.. tz7L7Q7U7U%8 8  G&&R R R J16R R R   '++M::?G&&'G'G'GHHHHJ)--m<<< J44]CCEG''(D(D(D(DEEEJ002222_/	3 /	3s   AI11
J&; J!!J&c                       j                                         } fd j         j        D             }||z   } fd|D             }|S )Nc                 D    g | ]}j                             |          S r*   r:   r   r  s     r$   r   z-Commands.completions_drop.<locals>.<listcomp>  s)    bbbB4:33B77bbbr&   c                 :    g | ]}                     |          S r*   r  r  s     r$   r   z-Commands.completions_drop.<locals>.<listcomp>  s'    >>>bT%%b))>>>r&   )r:   r   r   )r#   r  read_only_files	all_filess   `   r$   completions_dropzCommands.completions_drop  s]    
4466bbbb$*BabbbO+	>>>>I>>>	r&   c                    
 |                                 sR j        r j                            d           n j                            d                                             dS t          |          }|D ]}t          j                            |          
g } j	        j
        D ]}
|v r|                    |           	 t          j                            
          }t          j                            ||          r|                    |           r# t          t          f$ r Y w xY w|D ]?} j	        j
                            |            j                            d| d           @t#          
fddD                       r                     
          }n
 fd j	        j        D             }|s|                    
           |D ]g} j	                            |          }	|	 j	        j        v r= j	        j                            |	            j                            d	| d           hdS )
z;Remove files from the chat session to free up context spacezKDropping all files from the chat session except originally read-only files.z)Dropping all files from the chat session.NzRemoved read-only file z from the chatc              3       K   | ]}|v V  	d S r    r*   )r`   rt  expanded_words     r$   ra   z$Commands.cmd_drop.<locals>.<genexpr>  s(      66!1%666666r&   z*?[]c                 L    g | ] }|v j                             |          !S r*   r  )r`   fr  r#   s     r$   r   z%Commands.cmd_drop.<locals>.<listcomp>  s<     ! ! !45R_cdRdRdDJ,,Q//RdRdRdr&   zRemoved )rF   r4   r5   rI   r   r  r  r4  r   r:   r   r   abspathsamefiler   r  r  anyr  r   r   )r#   r0   r  r  read_only_matchedr  abs_wordr  r  r   r  s   `         @r$   cmd_dropzCommands.cmd_drop  s    zz|| 	- Q##a    ##$OPPP  """F*400	 '	Q '	QDG..t44M !#Z4   A%%%,,Q///!w}==Hw''!44 4)00333)73   H !2 \ \
/66|DDD##$Zl$Z$Z$Z[[[[ 6666v66666  $ : := I I! ! ! ! !9=9N! ! ! ! 4$$]333 - Q Q J44\BB	
 555J)00;;;G''(O<(O(O(OPPP	QG'	Q '	Qs   ADD0/D0c           
         d}	 d|z   }t          t          j        j                  }d|d<   t          j        |t          j        t          j        d|d| j        j        d          }|j	        }n4# t          $ r'}| j                            d|            Y d}~nd}~ww xY w|dS | j                            |           dS )	z-Run a git command (output excluded from chat)Nzgit true
GIT_EDITORTr   )stdoutstderrrn  envshellencodingr   zError running /git command: )r   
subprocessr  environr   PIPESTDOUTr5   r  r  	Exceptionro   rI   )r#   r0   combined_outputr  resultr  s         r$   cmd_gitzCommands.cmd_git  s    	CD=Dz},--C &C^!!() 	 	 	F %mOO 	C 	C 	CGAaAABBBBBBBB	C "FO,,,,,s   A)A. .
B8BBc                 @   |s| j         j        r| j         j        }|sdS t          |          sHt          |          t          urt          t          |                    |                     |d          S  |            }|sdS | j        	                    |           |S )zHRun a shell command and add the output to the chat on non-zero exit codeNT)
r:   test_cmdcallabletyper   r  reprcmd_runr5   rI   )r#   r0   r   s      r$   cmd_testzCommands.cmd_test  s     	'
+ 	':&D 	F~~ 	,Dzz$$ d,,,<<d+++ 	FF###r&   c                    t          || j        | j        j        | j        j                  \  }}|dS | j        j                            |          }|dz  }|r|dk    }n| j                            d|dd          }|rt          |
                                                                          }|dk    rd	nd
}	| j                            d| d|	 d           t          j                            ||          }
| j        xj        t#          d|
          t#          dd          gz  c_        |r|dk    r|
S |r|dk    rd| j        _        dS )zHRun a shell command and optionally add the output to the chat (alias: !))r2   error_printcwdNi  r   zAdd z.1fz'k tokens of command output to the chat?r   linelinesr  r  z of output to the chat.)r   outputr   r   r   r   zWhat's wrong? Fix)r   r2   r5   ro   r:   rk  rD   r  r   rh   rF   r;  rI   r   
run_outputri   r   r   r"   )r#   r0   add_on_nonzero_exitexit_statusr  r  k_tokensr   	num_linesline_pluralr%  s              r$   r  zCommands.cmd_run  s   '.$,DG4FDJO(
 (
 (
$_ "F j+77HH% 	d"CC'%%&bX&b&b&b&bccC 	:O1133>>@@AAI$-NN&&KG Y Y Y[ Y Y YZZZ$++& ,  C
 J##&#...+u555( ##
 # :{a'7'7
 :))&9# tr&   c                 d    | j                             dd           t          j                     dS )Exit the applicationexitz/exit)reasonN)r:   r   sysr  r~   s     r$   cmd_exitzCommands.cmd_exit  s,    
000




r&   c                 0    |                      |           dS )r  N)r  r~   s     r$   cmd_quitzCommands.cmd_quit  s    dr&   c                 (   | j                                         }g }g }g }|D ]U}| j                             |          }|| j         j        v r|                    |           @|                    |           V| j         j        D ]1}| j                             |          }|                    |           2|s |s|s| j                            d           dS |r| j                            d           |D ]}| j                            d|             |r| j                            d           |D ]}| j                            d|             |r| j                            d           |D ]}| j                            d|             dS )zHList all known files and indicate which are included in the chat sessionz/
No files in chat, git repo, or read-only list.NzRepo files not in the chat:
r6  z
Read-only files:
z
Files in chat:
)	r:   r  r   r   r   r   r   r5   rI   )	r#   r0   r  r  
chat_filesr  rT  r  rel_file_paths	            r$   cmd_lszCommands.cmd_ls  s    
1133
 	) 	)D J44T::M
 555!!$''''""4(((( "Z< 	2 	2M J44]CCM""=1111 	+ 	o 	G RSSSF 	AG ?@@@ 	- 	-DGT,,,, 	8G 6777# 	- 	-DGT,,,, 	6G 4555 	- 	-DGT,,,,	- 	-r&   c                 0   t          |                                           }t          d |D                       }dt          |          z   dz   }|D ]}d|dd                               dd          }t          | |d           }|                    |          }|r'|j        }| j        	                    | d	|            s| j        	                    | d
           | j        	                                 | j        	                    d           d S )Nc              3   4   K   | ]}t          |          V  d S r    rg   )r`   r   s     r$   ra   z&Commands.basic_help.<locals>.<genexpr>G  s(      //s#c((//////r&   z{cmd:}r   r   r   r   )r   r  z No description available.z?Use `/help <question>` to ask questions about how to use aider.)
rm   r   rp   r   r   r]   ri   r^   r5   rI   )r#   r   padr   r   r   rw   s          r$   
basic_helpzCommands.basic_helpE  s1   $++--..//h/////C 3& 	H 	HC.SW..66sC@@O ==J***%%C H(0##s$:$:[$:$:;;;;##s$F$F$FGGGG]^^^^^r&   c                    |                                 s|                                  dS | j                            d           ddlm} | j        sEt          | j                  }|s| j        	                    d           dS t                      | _        |                    | j        | j        dddd	
          }| j                            |          }|dz  }|d                    | j                                                  dz   z  }|                    |d           | j        j        r#| j        j        j        }| j        j        j        }nd}d	}t'          | j        j        d|||d          )zAsk questions about aiderNzinteractive helpr   Coderz&Unable to initialize interactive help.r=   Fi   r   )r5   
from_coderrE   rk   
map_tokensmap_mul_no_fileszE
# Announcement lines from when this session of aider was launched:

r@   )preproc)rE   rk   r  r  r  show_announcements)rF   r  r:   r   aider.coders.base_coderr
  r=   r   r5   ro   r   createrb   rG   rH   r   r  max_map_tokensr  r   rE   )r#   r0   r
  r   r:   user_msgr  r  s           r$   cmd_helpzCommands.cmd_helpU  s    zz|| 	OOF
+,,,111111y 	$TW--C ""#KLLLDIwz!&  
 
 9==&&  	 	DIIdj::<<==DD		(E	***: 	!,;J#z2CJ 
.!&!-$
 
 
 	
r&   c                     t                      r    r   r6   s    r$   completions_askzCommands.completions_ask      (***r&   c                     t                      r    r   r6   s    r$   completions_codezCommands.completions_code  r  r&   c                     t                      r    r   r6   s    r$   completions_architectzCommands.completions_architect  r  r&   c                     t                      r    r   r6   s    r$   completions_contextzCommands.completions_context  r  r&   c                 .    |                      |d          S )ziAsk questions about the code base without editing any files. If no prompt provided, switches to ask mode.rb   _generic_chat_commandr~   s     r$   cmd_askzCommands.cmd_ask  s    ))$666r&   c                 L    |                      || j        j        j                  S )zKAsk for changes to your code. If no prompt provided, switches to code mode.)r   r:   rD   rE   r~   s     r$   cmd_codezCommands.cmd_code  s     ))$
0E0QRRRr&   c                 .    |                      |d          S )zoEnter architect/editor mode using 2 different models. If no prompt provided, switches to architect/editor mode.rd   r  r~   s     r$   cmd_architectzCommands.cmd_architect  s    ))$<<<r&   c                 Z    |                      |d|                                pd          S )zdEnter context mode to see surrounding code context. If no prompt provided, switches to context mode.re   N)r"   )r   rF   r~   s     r$   cmd_contextzCommands.cmd_context  s+    ))$	tzz||G[W[)\\\r&   c                    |                                 s|                     |          S ddlm} |                    | j        | j        |d          }|}|                    |           t          | j        j	        d|d|          )Nr   r	  F)r5   r  rE   rk   )rE   rk   r  r  r"   )
rF   rx   r  r
  r  r5   r:   r   r   rE   )r#   r0   rE   r"   r
  r:   r  s          r$   r   zCommands._generic_chat_command  s    zz|| 	3%%k222111111wz#!&	  
 
 		( 
.!&$#
 
 
 	
r&   c                    d}t          |                                           }|D ]S}d|dd                              dd          }t          | |d          }|r|j        }|d| d| d	z  }J|d| d
z  }T|dz  }|S )z(Show help about all commands in markdownz-
|Command|Description|
|:------|:----------|
r   r   Nr   r   z| **z** | z |
z** | |
r@   )rm   r   r   r]   r^   )r#   r   r   r   r   r   rw   s          r$   get_help_mdzCommands.get_help_md  s     $++--.. 	, 	,C.SW..66sC@@O ==J ,(09c999999+c++++t
r&   c                    | j         sdt          j        vr| j                            d           dS 	 t          j        | j        pd| j                  | _         n0# t           j        $ r | j                            d           Y dS w xY w	 | j         	                    d| j
                  }n:# t          j        $ r(}| j                            d|            Y d}~dS d}~ww xY w|r|| j        _        dS dS )	z!Record and transcribe voice inputOPENAI_API_KEYz1To use /voice you must provide an OpenAI API key.Nwav)audio_formatdevice_namezJUnable to import `sounddevice` and/or `soundfile`, is portaudio installed?)languagez$Unable to use OpenAI whisper model: )r   r  r  r5   ro   Voicer;   r<   SoundDeviceErrorrecord_and_transcriber.   r   OpenAIErrorr"   )r#   r0   rn  r   s       r$   	cmd_voicezCommands.cmd_voice  sB    z 	rz11""#VWWW"[!%!2!;eI`  

 )   ""`   		:33D4CV3WWDD" 	 	 	GKcKKLLLFFFFF	  	'"&DG	' 	's)   'A )BB!B. .C%=C  C%c                    	 t          j                    }t          |t          j                  r|                                rX|                                }t
          j                            |          d                                         }|dv r|}n| d}nd}t          j
                    }t
          j                            ||          }|                                                    d          rdnd}|                    ||           t          |                                          t!          fd| j        j        D             d          }	|	r<| j        j                            |	           | j                            d	|	            | j        j                            t/                               | j                            d
            | j                                         dS t3          j                    }
|
r| j                            |
           |
S | j                            d           dS # t8          $ r(}| j                            d|            Y d}~dS d}~ww xY w)zbPaste image/text from the clipboard into the chat.        Optionally provide a name for the image.r   )z.jpgz.jpeg.pngr7  zclipboard_image.pngPNGJPEGc              3   V   K   | ]#}t          |          j        j        k    |V  $d S r    )r   rK   )r`   r  r  s     r$   ra   z%Commands.cmd_paste.<locals>.<genexpr>  s8      \\1aI[9[9[Q9[9[9[9[\\r&   Nz%Replaced existing image in the chat: z#Added clipboard image to the chat: z,No image or text content found in clipboard.z$Error processing clipboard content: )r   grabclipboard
isinstancer   rF   r  r4  splitextlowertempfilemkdtemprG   endswithsaver   resolvenextr:   r   r  r5   rI   r   r   r  	pyperclippastero   r  )r#   r0   imagefilenameextbasenametemp_dirtemp_file_pathimage_formatexisting_filern  r  r  s               @r$   	cmd_pastezCommands.cmd_paste  s{   -	K+--E%-- ::<< 5#zz||H'**844Q7==??C777#+&.#4#4#44H#+--!#h!A!A(0(8(8(A(A&(I(IUuuv

><888 $^ 4 4 < < > > !%\\\\
 5\\\^b! ! ! aJ)00???G''(_P](_(_```
%))#m*<*<===##$Y-$Y$YZZZ
,,... ?$$D ##D)))GMNNNF 	K 	K 	KGIaIIJJJJJJJJJ	Ks$   G7I	 <0I	 -I	 	
I;I66I;c                    |                                 st          | j        j                  D ]x}| j        j                            |           | j        j                            |           | j                            |          }| j        	                    d| d           ydS t          |          }g }|D ]}t          |          }t          |          }|                                }	|	st          | j        j                  |z  }g }
|                                r|g}
nZ|	rd t!          j        |          D             }
n9t          t          | j        j                                      |                    }
|
s| j                            d|            |                    |
           t'          |          D ]}| j                            |          }t*          j                            |          r|                     ||           Rt*          j                            |          r|                     ||           | j                            d|            dS )zSAdd files to the chat that are for reference only, or turn added files to read-onlyz
Converted z to read-onlyNc                 ,    g | ]}t          |          S r*   r   )r`   ps     r$   r   z*Commands.cmd_read_only.<locals>.<listcomp><  s    LLL1tAwwLLLr&   zNo matches found for: zNot a file or directory: )rF   r  r:   r   r  r   r   r   r5   rI   r  r   r   r  rk  r  r  ro   r  rm   r   r  r4  isfile_add_read_only_fileisdir_add_read_only_directory)r#   r0   r   r   r  	all_pathsr  expanded_patternpath_objis_absmatchesr4  abs_paths                r$   cmd_read_onlyzCommands.cmd_read_only  s   zz|| 	dj344 K K
%,,U333
/33E::: J44U;;	##$I$I$I$IJJJJF*400		 ! 	* 	*G)'22,--H))++F <
008;G   	Q#*  QLL	:J0K0KLLLGG #4
#8#8#=#=>N#O#OPPG *""#EG#E#EFFFF  )))) 9%% 	K 	KDz//55Hw~~h'' K((48888x(( K--h====""#Ix#I#IJJJJ	K 	Kr&   c                 |   t          |          rV| j        j        j                            d          s2| j                            d| d| j        j        j         d           d S || j        j        v r| j                            | d           d S || j        j	        v r^| j        j	        
                    |           | j        j                            |           | j                            d| d           d S | j        j                            |           | j                            d| d	           d S )
Nr  r  r  r  z+ is already in the chat as a read-only filer  z- from editable to read-only files in the chatr   to read-only files.)r   r:   rD   r  r  r5   ro   rK   r   r   r  r   rI   )r#   r\  original_names      r$   rT  zCommands._add_read_only_fileP  sm   '' 	
0E0J0N0NO`0a0a 	GJ J JJ).J J J   Ftz666G-\\\]]]F...J!((222J+//999GUUUU     J+//999G L L L LMMMMMr&   c                    d}t          j        |          D ]k\  }}}|D ]b}t           j                            ||          }|| j        j        vr2|| j        j        vr$| j        j                            |           |dz  }cl|dk    r#| j        	                    d| d| d           d S | j        	                    d| d           d S )Nr   r   r  z files from directory r_  z"No new files added from directory .)
r  walkr4  rG   r:   r   r   r   r5   rI   )	r#   r\  r`  added_filesrk  r   r  rT  rS  s	            r$   rV  z!Commands._add_read_only_directorye  s    gh// 	% 	%ND!U % %GLLt44	TZ%:::!)HHHJ377	BBB1$K% ??G___M___     G U] U U UVVVVVr&   c                     | j                                         }|r| j                            |           dS | j                            d           dS )z$Print out the current repository mapzNo repository map available.Nr:   r  r5   rI   r#   r0   r  s      r$   cmd_mapzCommands.cmd_mapx  sW    :**,, 	@G)))))G >?????r&   c                 x    | j                             d          }|r| j                            d           dS dS )z%Force a refresh of the repository mapT)force_refreshz5The repo map has been refreshed, use /map to view it.Nrf  rg  s      r$   cmd_map_refreshzCommands.cmd_map_refresh  sL    :***>> 	YG WXXXXX	Y 	Yr&   c                    t          | j        | j                  }d                    | j                                                  }g }d| j        j        fdt          | j        j        dd          fdt          | j        j        dd          fg}|D ]\  }}|st          |di           pi }|s|                    | d	|j	         d
           t          |                                          D ] \  }	}
|                    d|	 d|
            !|                    d           d                    |          }| d| }|r|d|z   z  }| j                            |           dS )zPrint out the current settingsr@   z
Main modelzEditor modelrB   Nz
Weak modelrC   r  z (z):r6  r   r   )r   r1   r0   rG   r:   rH   rD   r]   r   rK   rm   rr   r5   rI   )r#   r0   settingsrN   model_sectionsactive_modelslabelrO   r  kr   model_metadatar  s                r$   cmd_settingszCommands.cmd_settings  s   "4;	::		$*">">"@"@AA 4:01WTZ%:NDQQR74:#8,MMN

 * 		& 		&LE5 5&"--3D !!U"<"<ej"<"<"<===tzz||,, 5 51%%m1mmmm4444!!"%%%%>22!//X// 	,d^++FF#####r&   c                 .    |                      ||          S r    r  r#   ry  rz  s      r$   completions_raw_loadzCommands.completions_raw_load      --hGGGr&   c                     |                                 s| j                            d           dS 	 t          |                                 d| j        j        d          5 }|                                }ddd           n# 1 swxY w Y   n^# t          $ r! | j                            d|            Y dS t          $ r(}| j                            d|            Y d}~dS d}~ww xY w|D ]}|                                 }|r|                    d          r.| j        	                    d	|            	 | 
                    |           b# t          $ r! | j                            d
| d           Y w xY wdS )z%Load and execute commands from a filez6Please provide a filename containing commands to load.Nrr   )r  r   zFile not found: zError reading file: #z
Executing: z	Command 'z2' is only supported in interactive mode, skipping.)rF   r5   ro   openr  	readlinesr   r  r   rI   r   r   )r#   r0   r  r   r  r   s         r$   cmd_loadzCommands.cmd_load  s   zz|| 	GWXXXF	djjllC$'2B9UUU )YZ;;==) ) ) ) ) ) ) ) ) ) ) ) ) ) )  	 	 	G8$88999FF 	 	 	G9a99:::FFFFF	  	 	C))++C #..-- G 5 5 5666   ""WWWW    	 	sS   /B !B6B BB 	B
B 'C)8	C)C$$C):E(E;:E;c                 .    |                      ||          S r    ru  rv  s      r$   completions_raw_savezCommands.completions_raw_save  rx  r&   c                    |                                 s| j                            d           dS 	 t          |                                 d| j        j                  5 }|                    d           t          | j        j                  D ]5}| j        	                    |          }|                    d| d           6t          | j        j
                  D ]{}t          |                              | j        j                  r4| j        	                    |          }|                    d| d           b|                    d| d           |	 ddd           n# 1 swxY w Y   | j                            d	|                                             dS # t          $ r(}| j                            d
|            Y d}~dS d}~ww xY w)zMSave commands to a file that can reconstruct the current chat session's filesz2Please provide a filename to save the commands to.Nw)r  z/drop
z/add       r@   z/read-only zSaved commands to zError saving commands to file: )rF   r5   ro   r|  r  writerm   r:   r   r   r   r   r  rk  rI   r  )r#   r0   r  r   r   r  s         r$   cmd_savezCommands.cmd_save  s)   zz|| 	GSTTTF	FdjjllC$'2BCCC 9q	"""#DJ$9:: 9 9E $
 8 8 ? ?IGG7)7778888 $DJ$CDD 9 9EE{{11$*/BB 9$(J$<$<U$C$C	 ;i ; ; ;<<<< 7e 7 7 7888899 9 9 9 9 9 9 9 9 9 9 9 9 9 9  G CTZZ\\ C CDDDDD 	F 	F 	FGDDDEEEEEEEEE	Fs<   .F#  C:E'F# 'E++F# .E+/2F# #
G-GGc                 8    | j                                          dS )z>Toggle multiline mode (swaps behavior of Enter and Meta+Enter)N)r5   toggle_multiline_moder~   s     r$   cmd_multiline_modezCommands.cmd_multiline_mode  s    %%'''''r&   c                    | j         j        | j         j        z   }d t          |          D             }|s| j                            d           dS |d         d         }	 t          j        |           t          |          dk    r|dd         dz   n|}| j        	                    d|            dS # t          j
        $ rO}| j                            d	t          |                      | j        	                    d
           Y d}~dS d}~wt          $ r5}| j                            dt          |                      Y d}~dS d}~ww xY w)z0Copy the last assistant message to the clipboardc                 *    g | ]}|d          dk    |S )r   r   r*   )r`   r%  s     r$   r   z%Commands.cmd_copy.<locals>.<listcomp>  s'    bbbcs6{VaGaGacGaGaGar&   z$No assistant messages found to copy.Nr   r   2   r   z5Copied last assistant message to clipboard. Preview: Failed to copy to clipboard: CYou may need to install xclip or xsel on Linux, or pbcopy on macOS.9An unexpected error occurred while copying to clipboard: )r:   r   r   reversedr5   ro   rE  copyrh   rI   PyperclipExceptionr   r  )r#   r0   all_messagesassistant_messageslast_assistant_messagepreviewr  s          r$   cmd_copyzCommands.cmd_copy  s   z/$*2IIbbXl-C-Cbbb! 	GEFFFF!3A!6y!A	eN1222 -..33 'ss+e33+ 
 G aX_ a abbbbb+ 	 	 	GGs1vvGGHHHGU          	e 	e 	eGc[^_`[a[accddddddddd	es&    AB5 5EADE*EEc                     ddl m} d                    | j                                                  }|}|                                r|                                }nd} |||d           dS )z*Report a problem by opening a GitHub Issuer   )report_github_issuer@   NF)titleconfirm)aider.reportr  rG   r:   rH   rF   )r#   r0   r  rN   
issue_textr  s         r$   
cmd_reportzCommands.cmd_report  sz    444444		$*">">"@"@AA"
::<< 	JJLLEEEJeUCCCCCCr&   c                     t          |d| j                  }|                                r.| j                            |                                           dS dS )z Open an editor to write a promptmd)suffixr3   N)r   r3   rF   r5   set_placeholderrstrip)r#   initial_content
user_inputs      r$   
cmd_editorzCommands.cmd_editor  s`     !dkRRR
 	9G##J$5$5$7$788888	9 	9r&   c                 ,    |                      |          S )z3Alias for /editor: Open an editor to write a prompt)r  r~   s     r$   cmd_editzCommands.cmd_edit  s    t$$$r&   c                    | j         j        }|                                si|                                }|| j                            d           n6|                                }| j                            d|dd| d           dS |                                }|                    |           |dk    r| j                            d           nJ|                                }|                                }| j                            d	|dd| d           | j                                         d
                    | j         	                                          }| j                            |           dS )zJSet the thinking token budget, eg: 8096, 8k, 10.5k, 0.5M, or 0 to disable.Nz&Thinking tokens are not currently set.zCurrent thinking token budget: r   z	 tokens (z).0zThinking tokens disabled.zSet thinking token budget to r@   )
r:   rD   rF   get_thinking_tokensr5   rI   get_raw_thinking_tokensset_thinking_tokensrG   rH   )r#   r0   rO   formatted_budgetbudgetvaluerN   s          r$   cmd_think_tokenszCommands.cmd_think_tokens  s   
%zz|| 
	$88::'##$LMMMM6688##]f]]]IY]]]   F

!!%((( C<<G ;<<<<$88::2244FGWWWWCSWWW   	 		$*">">"@"@AAM*****r&   c                 X   | j         j        }|                                sP|                                }|| j                            d           n| j                            d|            dS |                                }|                    |           |                                }| j                            d|            | j                                         d                    | j                                                   }| j                            |           dS )zUSet the reasoning effort level (values: number or low/medium/high depending on model)Nz&Reasoning effort is not currently set.zCurrent reasoning effort: zSet reasoning effort to r@   )	r:   rD   rF   get_reasoning_effortr5   rI   set_reasoning_effortrG   rH   )r#   r0   rO   reasoning_valuer  rN   s         r$   cmd_reasoning_effortzCommands.cmd_reasoning_effort=  s   
%zz|| 	#88::O&##$LMMMM##$R$R$RSSSF

""5)))4466HHHIII 		$*">">"@"@AAM*****r&   c                    | j                                         }d}|j        |j        |j        fD ]f}|D ]a}|d         dk    r|d         }t          |t                    r-|D ])}|                    d          dk    r||d         dz   z  }*Y||dz   z  }bg|pd}|d| d	z  }	 t          j	        |           | j
                            d
           dS # t          j        $ rO}| j
                            dt          |                      | j
                            d           Y d}~dS d}~wt          $ r5}| j
                            dt          |                      Y d}~dS d}~ww xY w)zJCopy the current chat context as markdown, suitable to paste into a web UIr   r   r   r   r  rn  z

z
Just tell me how to edit the files to make the changes.
Don't give me back entire files.
Just show me the edits I need to make.

r@   z!Copied code context to clipboard.r  r  Nr  )r:   format_chat_chunksr   readonly_filesr   r<  r  r  rE  r  r5   rI   r  ro   r   r  )	r#   r0   chunksmarkdownmessagesr%  r   partr  s	            r$   cmd_copy_contextzCommands.cmd_copy_contextT  s    ..00  f&;V=NO 	1 	1H 1 1v;&((i. gt,, 1 ' > >88F++v55$Vv(==H> & 00HH1 zr 
    			eN8$$$G CDDDDD+ 	 	 	GGs1vvGGHHHGU          	e 	e 	eGc[^_`[a[accddddddddd	es%   %.C E0$AD..E0;*E++E0)	NNNTNNFNN)Fr    )r   N)r   )Nr'   r(   r)   r   r   r7   r%   rS   rW   rY   rx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r*  r-  r,  rY  rX  rf  r  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r'  r   r*  r5  rO  r]  rT  rV  rh  rk  rs  rw  r~  r  r  r  r  r  r  r  r  r  r  r*   r&   r$   r,   r,   $   s9       EG
 
 
" "& N  N  N  NDI I I6
, 
, 
,
, 
, 
,A
 A
 A
F  V V V"
 "
 "
 "
H      	 	 	H H H
7 
7 
7A A A2D D D D
I 
I 
I 
I5  5  5  5 n9 9 94 4 4$% % %K K KjV jV jVXB B B_. _. _.BB B B B   B  
7 7 7r       D^3 ^3 ^3@  5Q 5Q 5Q 5Qn- - -4  (( ( ( (T  
  %- %- %-N_ _ _ 1
 1
 1
f+ + ++ + ++ + ++ + +7 7 7S S S= = =] ] ]
 
 
 
4  (' ' '40K 0K 0Kd0K 0K 0KdN N N*W W W&@ @ @Y Y Y$ $ $<H H H  :H H HF F F6( ( (e e e6D D D9 9 9 9% % % %!+ !+ !+F+ + +.*e *e *e *e *e *er&   r,   c              #      K   |                                  r| V  d S |                                 r0|                     d          D ]}|                                 r|V  d S d S )Nr  )r  r  rglob)rS  rT  s     r$   r  r    s        OOC(( 	 	D||~~ 


 	 	r&   c                 H    t          j        d|           }d |D             }|S )Nz\"(.+?)\"|(\S+)c                      g | ]}|D ]}||S r*   r*   )r`   sublistrK   s      r$   r   z*parse_quoted_filenames.<locals>.<listcomp>  s*    KKK'7KK4dKKKKKr&   )r  findall)r0   r  s     r$   r  r    s-    
-t44IKKYKKKIr&   c                  J    t          d d                                           } | S r    )r,   r*  r  s    r$   r*  r*    s"    	$			)	)	+	+BIr&   c                  @    t                      } t          |            d S r    )r*  rb  r  s    r$   mainr    s    	B	"IIIIIr&   __main__)8r  r  r  r  r  r?  collectionsr   os.pathr   pathlibr   rE  PILr   r   prompt_toolkit.completionr	   r
   prompt_toolkit.documentr   rl   r   r   r   aider.editorr   aider.format_settingsr   
aider.helpr   r   aider.ior   	aider.llmr   
aider.repor   aider.run_cmdr   aider.scraper   r   aider.utilsr   r   r  r   r,   r  r  r*  r  r'   statusr  r*   r&   r$   <module>r     sw    				 				     



  # # # # # #                                 ? ? ? ? ? ? ? ? , , , , , , ( ( ( ( ( ( ( ( ( ( $ $ $ $ $ $ 1 1 1 1 1 1 / / / / / / / / / / / / / /       $ $ $ $ $ $ ! ! ! ! ! ! 4 4 4 4 4 4 4 4 % % % % % %      ' ' ' ' ') ' ' 'Ze Ze Ze Ze Ze Ze Ze Zez2      
  
 zTVVFCHV r&   