Skip to content

Commit 4f8b767

Browse files
committed
Bug fix: non-truncated files didn't have closing fence. Changed fencing to xml based instead of trip-back-ticks
1 parent 62250ef commit 4f8b767

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
authors = [{ name = "Aman Rusia", email = "[email protected]" }]
33
name = "wcgw"
4-
version = "5.1.1"
4+
version = "5.1.2"
55
description = "Shell and coding agent for Claude and other mcp clients"
66
readme = "README.md"
77
requires-python = ">=3.11"

src/wcgw/client/tools.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

481481
def 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"\nNot 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

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)