From 58690da8b4228644fd51fcdca4b4fa7540e2f27b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 25 Jun 2023 20:55:10 -0700 Subject: [PATCH] fences are obfuscated so aider can modify itself --- aider/coders/base_coder.py | 35 +++++++++++++++++++---------------- aider/diffs.py | 5 ++--- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 3f5fa5dde..da998bfcb 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -31,6 +31,10 @@ class ExhaustedContextWindow(Exception): pass +def wrap_fence(name): + return f"<{name}>", f"" + + class Coder: abs_fnames = None repo = None @@ -40,16 +44,6 @@ class Coder: functions = None total_cost = 0.0 - fences = [ - ("```", "```"), - ("", ""), - ("", ""), - ("
", "
"), - ("", ""), - ("", ""), - ] - fence = fences[0] - @classmethod def create( self, @@ -249,6 +243,17 @@ class Coder: self.repo = repo + # fences are obfuscated so aider can modify this file! + fences = [ + ("``" + "`", "``" + "`"), + wrap_fence("source"), + wrap_fence("code"), + wrap_fence("pre"), + wrap_fence("codeblock"), + wrap_fence("sourcecode"), + ] + fence = fences[0] + def choose_fence(self): all_content = "" for fname in self.abs_fnames: @@ -256,14 +261,12 @@ class Coder: all_content = all_content.splitlines() + good = False for fence_open, fence_close in self.fences: + if fence_open in all_content or fence_close in all_content: + continue good = True - for line in all_content: - if line.startswith(fence_open) or line.startswith(fence_close): - good = False - break - if good: - break + break if good: self.fence = (fence_open, fence_close) diff --git a/aider/diffs.py b/aider/diffs.py index 4de55b924..730e43e1b 100644 --- a/aider/diffs.py +++ b/aider/diffs.py @@ -47,8 +47,8 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None): partially complete update. """ - dump(lines_orig) - dump(lines_updated) + # dump(lines_orig) + # dump(lines_updated) assert_newlines(lines_orig) assert_newlines(lines_orig) @@ -100,7 +100,6 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None): # print(diff) - dump(repr(show)) return show