From cac34297d6e6bbf16231003c742f44339bfd02b3 Mon Sep 17 00:00:00 2001 From: Senko Rasic Date: Sun, 10 Dec 2023 12:15:12 +0100 Subject: [PATCH] Various fixes * fix Windows file path escaping in file modifications * be explicit about the log code page (also helps for Windows) * improve file overwrite message --- pilot/helpers/AgentConvo.py | 7 +++---- pilot/helpers/Project.py | 2 +- pilot/logger/logger.py | 6 +++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pilot/helpers/AgentConvo.py b/pilot/helpers/AgentConvo.py index 47b2045c..303ef337 100644 --- a/pilot/helpers/AgentConvo.py +++ b/pilot/helpers/AgentConvo.py @@ -212,14 +212,13 @@ class AgentConvo: return s def replace_file_content(self, message, file_path, new_content): - escaped_file_path = re.escape(file_path) - - pattern = rf'\*\*{escaped_file_path}\*\*:\n```\n(.*?)\n```' + pattern = rf'\*\*{re.escape(file_path)}\*\*:\n```\n(.*?)\n```' # Escape special characters in new_content for the sake of regex replacement new_content_escaped = self.escape_specials(new_content) + file_path_escaped = self.escape_specials(file_path) - new_section_content = f'**{file_path}**\n```\n{new_content_escaped}\n```' + new_section_content = f'**{file_path_escaped}**\n```\n{new_content_escaped}\n```' updated_message, num_replacements = re.subn(pattern, new_section_content, message, flags=re.DOTALL) diff --git a/pilot/helpers/Project.py b/pilot/helpers/Project.py index 6c51790c..47fc96aa 100644 --- a/pilot/helpers/Project.py +++ b/pilot/helpers/Project.py @@ -121,7 +121,7 @@ class Project: print('yes/no', type='button') should_overwrite_files = styled_text( self, - f'Do you want to overwrite the dev step {self.args["skip_until_dev_step"]} code with system changes? Type y/n', + "Can I overwrite any changes that you might have made to the project since last running GPT Pilot (y/n)?", ignore_user_input_count=True ) diff --git a/pilot/logger/logger.py b/pilot/logger/logger.py index ecc47d68..8e339949 100644 --- a/pilot/logger/logger.py +++ b/pilot/logger/logger.py @@ -8,7 +8,11 @@ def setup_logger(): log_format = "%(asctime)s [%(filename)s:%(lineno)s - %(funcName)20s() ] %(levelname)s: %(message)s" # Create a log handler for file output - file_handler = logging.FileHandler(filename=os.path.join(os.path.dirname(__file__), 'debug.log'), mode='w') + file_handler = logging.FileHandler( + filename=os.path.join(os.path.dirname(__file__), 'debug.log'), + mode='w', + encoding='utf-8', + ) # Apply the custom format to the handler formatter = logging.Formatter(log_format)