@@ -1051,66 +1051,87 @@ def _handle_read_only_files(self, expanded_word, file_set, description=""):
10511051 file_set .remove (matched_file )
10521052 self .io .tool_output (f"Removed { description } file { matched_file } from the chat" )
10531053
1054- def cmd_drop (self , args = "" ):
1054+ async def cmd_drop (self , args = "" ):
10551055 "Remove files from the chat session to free up context space"
10561056
1057- if not args .strip ():
1058- if self .original_read_only_fnames :
1059- self .io .tool_output (
1060- "Dropping all files from the chat session except originally read-only files."
1061- )
1062- else :
1063- self .io .tool_output ("Dropping all files from the chat session." )
1064- self ._drop_all_files ()
1057+ try :
1058+ if not args .strip ():
1059+ if self .original_read_only_fnames :
1060+ self .io .tool_output (
1061+ "Dropping all files from the chat session except originally read-only"
1062+ " files."
1063+ )
1064+ else :
1065+ self .io .tool_output ("Dropping all files from the chat session." )
1066+ self ._drop_all_files ()
10651067
1066- # Recalculate context block tokens after dropping all files
1067- if hasattr (self .coder , "use_enhanced_context" ) and self .coder .use_enhanced_context :
1068- if hasattr (self .coder , "_calculate_context_block_tokens" ):
1069- self .coder ._calculate_context_block_tokens ()
1070- return
1068+ # Recalculate context block tokens after dropping all files
1069+ if hasattr (self .coder , "use_enhanced_context" ) and self .coder .use_enhanced_context :
1070+ if hasattr (self .coder , "_calculate_context_block_tokens" ):
1071+ self .coder ._calculate_context_block_tokens ()
10711072
1072- filenames = parse_quoted_filenames (args )
1073- files_changed = False
1073+ return
10741074
1075- for word in filenames :
1076- # Expand tilde in the path
1077- expanded_word = os .path .expanduser (word )
1075+ filenames = parse_quoted_filenames (args )
1076+ files_changed = False
10781077
1079- # Handle read-only files
1080- self ._handle_read_only_files (
1081- expanded_word , self .coder .abs_read_only_fnames , "read-only"
1082- )
1083- self ._handle_read_only_files (
1084- expanded_word , self .coder .abs_read_only_stubs_fnames , "read-only (stub)"
1085- )
1078+ for word in filenames :
1079+ # Expand tilde in the path
1080+ expanded_word = os .path .expanduser (word )
10861081
1087- # For editable files, use glob if word contains glob chars, otherwise use substring
1088- if any (c in expanded_word for c in "*?[]" ):
1089- matched_files = self .glob_filtered_to_repo (expanded_word )
1090- else :
1091- # Use substring matching like we do for read-only files
1092- matched_files = [
1093- self .coder .get_rel_fname (f ) for f in self .coder .abs_fnames if expanded_word in f
1094- ]
1082+ # Handle read-only files
1083+ self ._handle_read_only_files (
1084+ expanded_word , self .coder .abs_read_only_fnames , "read-only"
1085+ )
1086+ self ._handle_read_only_files (
1087+ expanded_word , self .coder .abs_read_only_stubs_fnames , "read-only (stub)"
1088+ )
10951089
1096- if not matched_files :
1097- matched_files .append (expanded_word )
1098-
1099- for matched_file in matched_files :
1100- abs_fname = self .coder .abs_root_path (matched_file )
1101- if abs_fname in self .coder .abs_fnames :
1102- self .coder .abs_fnames .remove (abs_fname )
1103- self .io .tool_output (f"Removed { matched_file } from the chat" )
1104- files_changed = True
1105-
1106- # Recalculate context block tokens if any files were changed and using agent mode
1107- if (
1108- files_changed
1109- and hasattr (self .coder , "use_enhanced_context" )
1110- and self .coder .use_enhanced_context
1111- ):
1112- if hasattr (self .coder , "_calculate_context_block_tokens" ):
1113- self .coder ._calculate_context_block_tokens ()
1090+ # For editable files, use glob if word contains glob chars, otherwise use substring
1091+ if any (c in expanded_word for c in "*?[]" ):
1092+ matched_files = self .glob_filtered_to_repo (expanded_word )
1093+ else :
1094+ # Use substring matching like we do for read-only files
1095+ matched_files = [
1096+ self .coder .get_rel_fname (f )
1097+ for f in self .coder .abs_fnames
1098+ if expanded_word in f
1099+ ]
1100+
1101+ if not matched_files :
1102+ matched_files .append (expanded_word )
1103+
1104+ for matched_file in matched_files :
1105+ abs_fname = self .coder .abs_root_path (matched_file )
1106+ if abs_fname in self .coder .abs_fnames :
1107+ self .coder .abs_fnames .remove (abs_fname )
1108+ self .io .tool_output (f"Removed { matched_file } from the chat" )
1109+ files_changed = True
1110+
1111+ # Recalculate context block tokens if any files were changed and using agent mode
1112+ if (
1113+ files_changed
1114+ and hasattr (self .coder , "use_enhanced_context" )
1115+ and self .coder .use_enhanced_context
1116+ ):
1117+ if hasattr (self .coder , "_calculate_context_block_tokens" ):
1118+ self .coder ._calculate_context_block_tokens ()
1119+ finally :
1120+ if self .coder .repo_map :
1121+ map_tokens = self .coder .repo_map .max_map_tokens
1122+ map_mul_no_files = self .coder .repo_map .map_mul_no_files
1123+ else :
1124+ map_tokens = 0
1125+ map_mul_no_files = 1
1126+
1127+ raise SwitchCoder (
1128+ edit_format = self .coder .edit_format ,
1129+ summarize_from_coder = False ,
1130+ from_coder = self .coder ,
1131+ map_tokens = map_tokens ,
1132+ map_mul_no_files = map_mul_no_files ,
1133+ show_announcements = False ,
1134+ )
11141135
11151136 def cmd_git (self , args ):
11161137 "Run a git command (output excluded from chat)"
0 commit comments