fix(opencode): Improve "Read" tool output to aid subsequent uses of the "Edit" tool#12030
fix(opencode): Improve "Read" tool output to aid subsequent uses of the "Edit" tool#12030albertov wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Below is the conclusion at which Haiku 4.5 at copilot-github analysed codebase to figure out.
The Root ProblemThe edit tool has a critical design flaw in how it instructs agents to handle the line number prefix from the The Documentation IssueIn The problem: This instruction is extremely difficult for agents to follow because:
The Implementation Shows WhyLooking at the for (const replacer of [
SimpleReplacer,
LineTrimmedReplacer,
BlockAnchorReplacer,
WhitespaceNormalizedReplacer, // ← Handles whitespace issues
IndentationFlexibleReplacer, // ← Handles indentation issues
EscapeNormalizedReplacer,
TrimmedBoundaryReplacer,
ContextAwareReplacer,
MultiOccurrenceReplacer,
])Even with these fallback strategies:
These exist precisely because agents struggle with whitespace/indentation. The tool was designed with these fallbacks as a band-aid, acknowledging the fundamental problem. Why Agents Struggle
SolutionThe edit tool documentation should be updated to provide explicit visual guidance, such as:
|
What does this PR do?
This PR helps models (tested with Haiku 4.5) use the "Edit" tool more effectively with regards to leading whitespace after reading context given by the "Read" tool. Fixes #10656
How did you verify your code works?
I tasked agents with writing Haskell (white-space sensitive) and they improved considerably their success rate (to consistently perfect edits) when using the Edit tool as to not introduce leading-whitespace related errors