You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idea: replace edit tool input string with formatted code to gaslight the model to think it generated formatted code and have less edit failures #2529
Currently when the LLM edits a file opencode will format the result and pass the formatted code in the tool output
This is nice because the code is always formatted after every tool call, the problem is that the LLM still thinks the edit it generated was the one applied. So subsequent edits will easily fail because the model will pass a non formatted search string for edits.
This could be done by modifying the messages in the next request to format the tool inputs. This way the LLM will think it generated formatted code the first time and not get confused. This will probably help with following edits too because the LLM will follow the same formatting style.
This could decrease a bit tokens caching but should not be a big problem given only the last tool is modified so you only lose a bit of cached tokens, the ones for the edit tool input.
Possible implementation
The simplest method would be to insert random string comments at start and end of the snippet, then use them later to extract the formatted string from the formatted file and save the formatted file discarding the random string separators.
Another way is to use the AST of TreeSitter and compute an Id for the token on the start and end positions of the tool input. Then find the same token with the same id in the formatted code, find the position and return that portion of the string. For computing the id you can concatenate each parent node type and content up until the token on the start and end positions.
changed the title [-]Idea: replace edit tool input string with formatted code to gaslight the model to think it generated formatted code and have less edit edit failures[/-][+]Idea: replace edit tool input string with formatted code to gaslight the model to think it generated formatted code and have less edit failures[/+]on Sep 10, 2025
Activity
github-actions commentedon Sep 10, 2025
This issue might be a duplicate of existing issues. Please check:
BlockAnchorReplacerfor better edit tool #2433: Discusses problems with the BlockAnchorReplacer causing edit tool failures and syntax errors due to incorrect string replacementsFeel free to ignore if none of these address your specific case.
rekram1-node commentedon Sep 10, 2025
interesting
[-]Idea: replace edit tool input string with formatted code to gaslight the model to think it generated formatted code and have less edit edit failures[/-][+]Idea: replace edit tool input string with formatted code to gaslight the model to think it generated formatted code and have less edit failures[/+]remorses commentedon Sep 10, 2025
This can be done with ai sdk prepareStep. would you like a PR?
rekram1-node commentedon Sep 10, 2025
it's up to Dax if he wants the implementation or not (not me) but you can try your hand at a PR
remorses commentedon Sep 10, 2025
Working on a PR right now for this @thdxr
remorses commentedon Sep 10, 2025
Edit: we are so back. I found a way to implement this using a diff algorithm
Thinking more about this issue I don't thing it's a good idea
Problems
For the time being #2535 is a better solution to this problem
rekram1-node commentedon Dec 28, 2025
[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!