memorix icon indicating copy to clipboard operation
memorix copied to clipboard

OpenCode plugin: console.log spam corrupts TUI display

Open RaviTharuma opened this issue 8 months ago • 2 comments

Bug

The generated OpenCode plugin (memorix installHooks('opencode', ...)) contains console.log calls that write directly to OpenCode's TUI stdout, corrupting the terminal display.

Affected code

The generated .opencode/plugins/memorix.js has three console.log calls:

// Line 11 — on plugin load
console.log('[memorix] plugin loaded, directory:', directory);

// Line 22 — on every hook fire (fires on EVERY tool call + session event)
console.log('[memorix] hook fired:', payload.hook_event_name);

// Line 24 — on hook errors
console.log('[memorix] hook error:', err?.message ?? err);

Why this is a problem

In OpenCode, console.log from plugins goes directly to stdout, bypassing the TUI's log-level system (logLevel config). This means every single tool execution, session event, and idle ping dumps [memorix] hook fired: tool.execute.after etc. into the chat display, making it unreadable.

Additionally, the > /dev/null 2>&1 redirect used in some versions doesn't work in Bun's $ shell template — it throws expected a command or assignment but got: "Redirect", which then triggers the error handler's console.error, creating even more spam.

Screenshots

[memorix] hook fired: session.idle
[memorix] hook fired: tool.execute.after
[memorix] hook error: expected a command or assignment but got: "Redirect"
[memorix] hook error: expected a command or assignment but got: "Redirect"
[memorix] hook error: expected a command or assignment but got: "Redirect"

Suggested fix

  1. Remove all console.log/console.error calls from the generated plugin
  2. Use .quiet() instead of > /dev/null 2>&1 for Bun's shell (.quiet() is the Bun-native way to suppress output)
  3. Silently ignore hook errors (or route through client.app.log if available)

Environment

  • OpenCode 1.3.0
  • memorix (latest via mcpm)
  • macOS 15.5

RaviTharuma avatar Mar 25 '26 12:03 RaviTharuma

Thanks for reporting this — the underlying problem was real for older generated OpenCode plugin installs. Current main / v1.0.5 already uses the silent plugin template (.quiet().nothrow(), no console.log/console.error, no shell redirect spam), and we also shipped stale-install detection so memorix hooks status can flag outdated OpenCode plugin files and prompt a reinstall. In other words: the noisy template is fixed, and old installs are now detectable. Closing this as resolved in v1.0.5.

AVIDS2 avatar Mar 25 '26 15:03 AVIDS2

Nice! Just updated it

RaviTharuma avatar Mar 25 '26 15:03 RaviTharuma