fences are obfuscated so aider can modify itself

This commit is contained in:
Paul Gauthier 2023-06-25 20:55:10 -07:00
parent d4d327e6d9
commit 58690da8b4
2 changed files with 21 additions and 19 deletions

View file

@ -31,6 +31,10 @@ class ExhaustedContextWindow(Exception):
pass
def wrap_fence(name):
return f"<{name}>", f"</{name}>"
class Coder:
abs_fnames = None
repo = None
@ -40,16 +44,6 @@ class Coder:
functions = None
total_cost = 0.0
fences = [
("```", "```"),
("<source>", "</source>"),
("<code>", "</code>"),
("<pre>", "</pre>"),
("<codeblock>", "</codeblock>"),
("<sourcecode>", "</sourcecode>"),
]
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)