feat: Add support for executing shell commands in apply_edits

This commit is contained in:
Paul Gauthier (aider) 2024-08-20 13:31:14 -07:00
parent c4855c84da
commit 5f4d6bc4a5

View file

@ -30,23 +30,34 @@ class EditBlockCoder(Coder):
failed = [] failed = []
passed = [] passed = []
for edit in edits: for edit in edits:
path, original, updated = edit if isinstance(edit, str):
full_path = self.abs_root_path(path) # This is a shell command
content = self.io.read_text(full_path) self.io.tool_output(f"Shell command: {edit}")
new_content = do_replace(full_path, content, original, updated, self.fence) if self.io.confirm_ask("Do you want to run this command?"):
if not new_content: # Here you would add logic to run the shell command
# try patching any of the other files in the chat self.io.tool_output("Command execution placeholder")
for full_path in self.abs_fnames: passed.append(edit)
content = self.io.read_text(full_path) else:
new_content = do_replace(full_path, content, original, updated, self.fence) self.io.tool_output("Command execution skipped.")
if new_content: failed.append(edit)
break
if new_content:
self.io.write_text(full_path, new_content)
passed.append(edit)
else: else:
failed.append(edit) path, original, updated = edit
full_path = self.abs_root_path(path)
content = self.io.read_text(full_path)
new_content = do_replace(full_path, content, original, updated, self.fence)
if not new_content:
# try patching any of the other files in the chat
for full_path in self.abs_fnames:
content = self.io.read_text(full_path)
new_content = do_replace(full_path, content, original, updated, self.fence)
if new_content:
break
if new_content:
self.io.write_text(full_path, new_content)
passed.append(edit)
else:
failed.append(edit)
if not failed: if not failed:
return return