Write Tool includes metadata in output and created filecontent
Description
Sometimes the write tools includes some of the metadata in its console & write output.
Happens when a completely new file is created.
-> Wrote .agent/Research/txt_record_quote_handling.md
...
somefile.yaml
- Go `%q` verb: Adds Go-style quoting</content>
<parameter name="filePath">.agent/Research/txt_record_quote_handling.md
already had a short discord chat with @rekram1-node.
OpenCode version
1.0.144
Steps to reproduce
Does not always happen.
Ask the AI Agent to produce a long and detailed report in a markdown style.
Screenshot and/or share link
Operating System
macos 26, fedora 43 gnome
Terminal
ghostty
I think the issue happens because params.content sometimes contains metadata blocks. A very small fix is to sanitize the content before writing:
await Bun.write(filepath, typeof params.content === "string" ? params.content : "");
can i go ahead with this fix @rwese @rekram1-node
I am uncertain, this would be a band-aid, but the cause is that the write-tool is receiving this wrongly. 🤷
But it is pretty annoying, i run into this couple of times a day.
What is the correct/long-term fix instead of the band-aid workaround?
can someone share the session they replicate this in?
opencode export > session.json
Here are found session exports, to find the offending tool calls using ripgrep rg '\/content>\\n<par', pattern works for vim too.
i created a script to help me parse through my sessions:
uv run https://raw.githubusercontent.com/rwese/opencode_session_analyzer/main/oc_session_analyzer.py --export
here are the found results.