@@ -251,55 +251,71 @@ def execute_bash(
251251 )
252252
253253 SHELL .sendline (command )
254- elif bash_arg .send_specials :
255- console .print (f"Sending special sequence: { bash_arg .send_specials } " )
256- for char in bash_arg .send_specials :
257- if char == "Key-up" :
258- SHELL .send ("\033 [A" )
259- elif char == "Key-down" :
260- SHELL .send ("\033 [B" )
261- elif char == "Key-left" :
262- SHELL .send ("\033 [D" )
263- elif char == "Key-right" :
264- SHELL .send ("\033 [C" )
265- elif char == "Enter" :
266- SHELL .send ("\n " )
267- elif char == "Ctrl-c" :
268- SHELL .sendintr ()
269- is_interrupt = True
270- elif char == "Ctrl-d" :
271- SHELL .sendintr ()
272- is_interrupt = True
273- elif char == "Ctrl-z" :
274- SHELL .send ("\x1a " )
275- else :
276- raise Exception (f"Unknown special character: { char } " )
277- elif bash_arg .send_ascii :
278- console .print (f"Sending ASCII sequence: { bash_arg .send_ascii } " )
279- for ascii_char in bash_arg .send_ascii :
280- SHELL .send (chr (ascii_char ))
281- if ascii_char == 3 :
282- is_interrupt = True
254+
283255 else :
284- if bash_arg .send_text is None :
256+ if (
257+ sum (
258+ [
259+ int (bool (bash_arg .send_text )),
260+ int (bool (bash_arg .send_specials )),
261+ int (bool (bash_arg .send_ascii )),
262+ ]
263+ )
264+ != 1
265+ ):
285266 return (
286- "Failure: at least one of send_text, send_specials or send_ascii should be provided" ,
267+ "Failure: exactly one of send_text, send_specials or send_ascii should be provided" ,
287268 0.0 ,
288269 )
270+ if bash_arg .send_specials :
271+ console .print (f"Sending special sequence: { bash_arg .send_specials } " )
272+ for char in bash_arg .send_specials :
273+ if char == "Key-up" :
274+ SHELL .send ("\033 [A" )
275+ elif char == "Key-down" :
276+ SHELL .send ("\033 [B" )
277+ elif char == "Key-left" :
278+ SHELL .send ("\033 [D" )
279+ elif char == "Key-right" :
280+ SHELL .send ("\033 [C" )
281+ elif char == "Enter" :
282+ SHELL .send ("\n " )
283+ elif char == "Ctrl-c" :
284+ SHELL .sendintr ()
285+ is_interrupt = True
286+ elif char == "Ctrl-d" :
287+ SHELL .sendintr ()
288+ is_interrupt = True
289+ elif char == "Ctrl-z" :
290+ SHELL .send ("\x1a " )
291+ else :
292+ raise Exception (f"Unknown special character: { char } " )
293+ elif bash_arg .send_ascii :
294+ console .print (f"Sending ASCII sequence: { bash_arg .send_ascii } " )
295+ for ascii_char in bash_arg .send_ascii :
296+ SHELL .send (chr (ascii_char ))
297+ if ascii_char == 3 :
298+ is_interrupt = True
299+ else :
300+ if bash_arg .send_text is None :
301+ return (
302+ "Failure: at least one of send_text, send_specials or send_ascii should be provided" ,
303+ 0.0 ,
304+ )
289305
290- updated_repl_mode = update_repl_prompt (bash_arg .send_text )
291- if updated_repl_mode :
292- BASH_STATE = "repl"
293- response = (
294- "Prompt updated, you can execute REPL lines using BashCommand now"
295- )
296- console .print (response )
297- return (
298- response ,
299- 0 ,
300- )
301- console .print (f"Interact text: { bash_arg .send_text } " )
302- SHELL .sendline (bash_arg .send_text )
306+ updated_repl_mode = update_repl_prompt (bash_arg .send_text )
307+ if updated_repl_mode :
308+ BASH_STATE = "repl"
309+ response = (
310+ "Prompt updated, you can execute REPL lines using BashCommand now"
311+ )
312+ console .print (response )
313+ return (
314+ response ,
315+ 0 ,
316+ )
317+ console .print (f"Interact text: { bash_arg .send_text } " )
318+ SHELL .sendline (bash_arg .send_text )
303319
304320 BASH_STATE = "repl"
305321
@@ -520,6 +536,12 @@ def do_diff_edit(fedit: FileEdit) -> str:
520536 apply_diff_to = f .read ()
521537
522538 lines = fedit .file_edit_using_search_replace_blocks .split ("\n " )
539+
540+ if not lines or not re .match (r"^<<<<<<+\s*SEARCH\s*$" , lines [0 ]):
541+ raise Exception (
542+ "Error: first line should be `<<<<<< SEARCH` to start a search-replace block"
543+ )
544+
523545 n_lines = len (lines )
524546 i = 0
525547 replacement_count = 0
0 commit comments