Skip to content

Commit f6b38b3

Browse files
committed
Match Taiga's concise response format for str_replace_editor tool
- str_replace now returns concise success message without dumping file content - create command returns simple success message without showing file content - view command unchanged (still shows full content as that's its purpose) - Updated all tests to match new response format - Reduces token usage and matches expected Taiga behavior
1 parent bc04836 commit f6b38b3

File tree

4 files changed

+108
-43
lines changed

4 files changed

+108
-43
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Str Replace Editor - Concise Response Format
2+
3+
## Summary
4+
5+
Updated the `str_replace_editor` tool in ClaudeMCPTools to match Taiga's concise response format. The tool no longer dumps the full file content in responses, making it cleaner and more efficient for LLM agents to use.
6+
7+
## Changes Made
8+
9+
### 1. **String Replacement Response**
10+
11+
**Before:**
12+
```
13+
Replaced 2 occurrence(s) in file.txt
14+
15+
>>> 5 Updated line here
16+
6 Context line
17+
7 Another line
18+
19+
>>> 12 Another updated line
20+
13 More context
21+
```
22+
23+
**After:**
24+
```
25+
The file file.txt has been edited successfully. Made 2 replacements.
26+
```
27+
28+
Or for single replacement:
29+
```
30+
The file file.txt has been edited successfully.
31+
```
32+
33+
### 2. **Create File Response**
34+
35+
**Before:**
36+
```
37+
Created file: test.txt
38+
39+
1 Line 1
40+
2 Line 2
41+
3 Line 3
42+
```
43+
44+
**After:**
45+
```
46+
File created successfully at test.txt
47+
```
48+
49+
### 3. **View Command Unchanged**
50+
51+
The `view` command still returns the full file content with line numbers, as this is its primary purpose and the agent expects to see the content.
52+
53+
## Benefits
54+
55+
1. **Cleaner Output**: Responses are concise and to the point
56+
2. **Less Token Usage**: Avoids repeating content the agent already knows
57+
3. **Matches Taiga**: Consistent with the response format agents expect from Taiga
58+
4. **Faster Processing**: Less text to parse and process
59+
60+
## Testing
61+
62+
- Updated all test cases to match new response format
63+
- All 136 tests pass
64+
- Created test script `test_str_replace_responses.jl` to verify behavior
65+
66+
## Usage Example
67+
68+
```julia
69+
using ClaudeMCPTools
70+
71+
tool = StrReplaceEditorTool()
72+
73+
# Create a file
74+
result = execute(tool, Dict(
75+
"command" => "create",
76+
"path" => "example.txt",
77+
"file_text" => "Hello World"
78+
))
79+
# Returns: "File created successfully at example.txt"
80+
81+
# Edit the file
82+
result = execute(tool, Dict(
83+
"command" => "str_replace",
84+
"path" => "example.txt",
85+
"old_str" => "World",
86+
"new_str" => "Julia"
87+
))
88+
# Returns: "The file example.txt has been edited successfully."
89+
```
90+
91+
This change makes the tool more efficient and user-friendly for LLM agents.

src/tools/str_replace_editor.jl

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -217,33 +217,13 @@ function execute(tool::StrReplaceEditorTool, params::Dict)
217217
end
218218
end
219219

220-
# Show the result with line numbers
221-
lines = split(new_content, '\n')
222-
223-
# Find lines that were changed
224-
changed_lines = Int[]
225-
for (i, line) in enumerate(lines)
226-
if occursin(new_str, line)
227-
push!(changed_lines, i)
228-
end
229-
end
230-
231-
# Show context around changed lines
232-
result_lines = String[]
233-
for line_num in changed_lines
234-
start_line = max(1, line_num - 2)
235-
end_line = min(length(lines), line_num + 2)
236-
237-
for i in start_line:end_line
238-
prefix = i == line_num ? ">>> " : " "
239-
push!(result_lines, "$prefix$i\t$(lines[i])")
240-
end
241-
push!(result_lines, "")
220+
# Return concise message like Taiga
221+
if occurrences == 1
222+
message = "The file $path has been edited successfully."
223+
else
224+
message = "The file $path has been edited successfully. Made $occurrences replacements."
242225
end
243-
244-
result = join(result_lines, "\n")
245-
message = "Replaced $occurrences occurrence(s) in $path\n\n$result"
246-
226+
247227
return create_content_response(message, is_error=false)
248228

249229
elseif command == "create"
@@ -279,13 +259,10 @@ function execute(tool::StrReplaceEditorTool, params::Dict)
279259
end
280260
end
281261

282-
# Show created file with line numbers
283-
lines = split(file_text, '\n')
284-
numbered_lines = [string(i, "\t", line) for (i, line) in enumerate(lines)]
285-
content = join(numbered_lines, "\n")
286-
287-
message = "Created file: $path\n\n$content"
288-
262+
# Return concise message like Taiga
263+
num_lines = count(c -> c == '\n', file_text) + 1
264+
message = "File created successfully at $path"
265+
289266
return create_content_response(message, is_error=false)
290267

291268
else

test/test_str_replace_editor.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
@test haskey(result, "content")
2626
text = result["content"][1]["text"]
27-
@test occursin("Created file", text)
28-
@test occursin("1\tLine 1", text)
29-
@test occursin("2\tLine 2", text)
30-
@test occursin("3\tLine 3", text)
27+
@test occursin("File created successfully", text)
28+
@test occursin("test.txt", text)
3129

3230
# Verify file was actually created
3331
@test isfile(joinpath(tmpdir, "test.txt"))
@@ -75,9 +73,8 @@
7573

7674
@test haskey(result, "content")
7775
text = result["content"][1]["text"]
78-
@test occursin("Replaced 2 occurrence(s)", text)
79-
@test occursin("Hi World", text)
80-
@test occursin("Hi again", text)
76+
@test occursin("edited successfully", text)
77+
@test occursin("2 replacements", text)
8178

8279
# Verify file was modified
8380
content = read(test_file, String)
@@ -105,7 +102,7 @@
105102
))
106103

107104
@test haskey(result, "content")
108-
@test occursin("Created file", result["content"][1]["text"])
105+
@test occursin("File created successfully", result["content"][1]["text"])
109106

110107
# Verify file and directories were created
111108
@test isdir(joinpath(tmpdir, "subdir"))

test/test_view_range.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"view_range" => [1, 2] # Should be ignored
108108
))
109109
@test !result["isError"]
110-
@test occursin("Replaced 1 occurrence", result["content"][1]["text"])
110+
@test occursin("edited successfully", result["content"][1]["text"])
111111

112112
# view_range should be ignored for create
113113
result = execute(tool, Dict(
@@ -117,7 +117,7 @@
117117
"view_range" => [1, 2] # Should be ignored
118118
))
119119
@test !result["isError"]
120-
@test occursin("Created file", result["content"][1]["text"])
120+
@test occursin("File created successfully", result["content"][1]["text"])
121121
end
122122

123123
# Clean up

0 commit comments

Comments
 (0)