Skip to content

Conversation

@elithrar
Copy link
Contributor

@elithrar elithrar commented Jan 4, 2026

Fixes #6830 and #6833 by adding ctx.log() for custom tools to avoid console.log output leaking to stdout.

problem:

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 and client.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.

@elithrar elithrar marked this pull request as draft January 4, 2026 18:39
@elithrar elithrar marked this pull request as ready for review January 4, 2026 18:49
- adds log() method to ToolContext in both plugin and internal Tool.Context
- implements log() using Log.create() in tool execution contexts
- updates plugin docs to show ctx.log() for custom tools
- removes console.log example that leaks to stdout
- fixes anomalyco#6830 anomalyco#6833
@elithrar elithrar force-pushed the feat/tool-context-logging branch from 41cf39c to 11a79c4 Compare January 4, 2026 18:50
@elithrar elithrar changed the title feat: add ctx.log() for custom tools and plugins feat: add ctx.log() for custom tools Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tui output corrupted when using plugins

1 participant