@@ -475,7 +475,7 @@ def get_context_for_errors(
475475 ntokens = len (default_enc .encoder (context ))
476476 if ntokens > max_tokens :
477477 return "Please re-read the file to understand the context"
478- return f"Here's relevant snippet from the file where the syntax errors occured:\n ``` \n { context } \n ``` "
478+ return f"Here's relevant snippet from the file where the syntax errors occured:\n <snippet> \n { context } \n </snippet> "
479479
480480
481481def write_file (
@@ -556,7 +556,7 @@ def write_file(
556556 return (
557557 (
558558 msg
559- + f"Here's the existing file:\n ``` \n { file_content_str } \n { final_message } \n ``` "
559+ + f"Here's the existing file:\n <wcgw:file> \n { file_content_str } \n { final_message } \n </wcgw:file> "
560560 ),
561561 {path_ : file_ranges },
562562 )
@@ -578,7 +578,7 @@ def write_file(
578578 return (
579579 (
580580 msg
581- + f"Here's the existing file:\n ``` \n { file_content_str } \n ``` \n { final_message } "
581+ + f"Here's the existing file:\n <wcgw:file> \n { file_content_str } \n </wcgw:file> \n { final_message } "
582582 ),
583583 {path_ : file_ranges },
584584 )
@@ -1164,25 +1164,27 @@ def read_files(
11641164 continue
11651165
11661166 if coding_max_tokens :
1167- coding_max_tokens = coding_max_tokens - tokens
1167+ coding_max_tokens = max ( 0 , coding_max_tokens - tokens )
11681168 if noncoding_max_tokens :
1169- noncoding_max_tokens = noncoding_max_tokens - tokens
1169+ noncoding_max_tokens = max ( 0 , noncoding_max_tokens - tokens )
11701170
11711171 range_formatted = range_format (start_line_num , end_line_num )
1172- message += f" \n { file } { range_formatted } \n ``` \n { content } \n "
1172+ message += f' \n <wcgw:file path=" { file } { range_formatted } "> \n { content } \n '
11731173
1174- # Check if we've hit either token limit
1174+ if not truncated :
1175+ message += "</wcgw:file>"
1176+
1177+ # Check if we've hit both token limit
11751178 if (
11761179 truncated
11771180 or (coding_max_tokens is not None and coding_max_tokens <= 0 )
1178- or (noncoding_max_tokens is not None and noncoding_max_tokens <= 0 )
1181+ and (noncoding_max_tokens is not None and noncoding_max_tokens <= 0 )
11791182 ):
11801183 not_reading = file_paths [i + 1 :]
11811184 if not_reading :
11821185 message += f"\n Not reading the rest of the files: { ', ' .join (not_reading )} due to token limit, please call again"
11831186 break
1184- else :
1185- message += "```"
1187+
11861188 return message , file_ranges_dict , truncated
11871189
11881190
0 commit comments