opencode
opencode copied to clipboard
feat: add ctx.log() for custom tools
Fixes #6830 and #6833 by adding ctx.log() for custom tools to avoid console.log output leaking to stdout.
problem:
- Custom plugins had
ctx.client.app.logavailable to them, but custom tools did not - there was no logger exposed to tools (making it hard to debug) - the docs still guided console.log (missed this in #6833)
solution:
- Added
ctx.log(level, message, extra)to ToolContext for custom tool implementations - Logs using OpenCode's internal
Log.create()API (appropriate since tools execute in-process) - Logger instances created once per context to avoid overhead
- Updated plugin docs to show
ctx.log()for custom tools andclient.app.log()for plugin initialization - Clarified that console.log leaks to stdout
I also had to update test sites for built-in tools to plumb log through into the ToolContext, hence the larger number of changed files here.
Custom tools now have structured logging that writes to OpenCode's log files instead of polluting terminal output.