Suggestion: redesign Insert_edit_into_file tool #3031
Replies: 2 comments 9 replies
-
|
I should clarify, is this a change you would be interested in accepting? |
Beta Was this translation helpful? Give feedback.
-
|
Hey @ElliottLester. Firstly thanks for such a great, well-thought out and detailed post. One of the hardest things that I've encountered since starting CodeCompanion was that of reliably editing files from within the chat buffer. It's been quite a journey. #2219 was the source of the current tool and introduced a ton of improvements compared to where we were previously. Probably the biggest challenge of all with the tool is that it has to be LLM agnostic. For OpenAI, Anthropic, and Google models, this hasn't been a problem, but in local, lower-parameter models, it's been incredibly challenging, as you correctly pointed out. Now Opencode's implementation is of particular interest to me because they too are faced with the same constraints that CodeCompanion is. On that basis, I think it would be very interesting to take a look at a revised tool. Probably the only criticism I have of the Be more than happy to collaborate with you on this as a PR. It's not something that I expect we would sort quickly, but many hands make light work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I love this plugin and the workflow it provides, I have been using local models via llama.cpp, I have noticed that smaller models(gemma-4-31B) seem to have trouble using the Insert_edit_into_file.
I wanted to check if this was an issue with llama.cpp or the model, so I used opencode as a comparison and was surprised to find that their apply_patch tool had much higher success rate with the same model on the same server.
While Insert_edit_into_file is simple client side, it is fragile and the tool call is complicated and lacks support for multiple simultaneous operations move/delete operations.
Standard Git patches are better but fail often because LLMs hallucinate line numbers in hunk headers (@@ -l,s +l,s @@).
So Opencode uses a custom patch format solves this by replacing arithmetic (line counts) with pattern recognition (markers and context), which seems to be less error prone.
Example Tool Call Comparison
Scenario: Change console.log("Hi") to console.log("Hello World") in src/main.ts.
Current Approach (insert_edit_into_file):
{ "filepath": "src/main.ts", "explanation": "Update greeting message", "mode": "append", "dryRun": false, "edits": [ { "oldText": " console.log(\"Hi\")", "newText": " console.log(\"Hello World\")", "replaceAll": false } ] }Proposed Approach (apply_patch):
{ "patchText": "*** Begin Patch\n*** Update File: src/main.ts\n@@ context\n- console.log(\"Hi\")\n+ console.log(\"Hello World\")\n*** End Patch" }the implementation for this tool can be found here apply_patch.ts
Beta Was this translation helpful? Give feedback.
All reactions