Skip to content

fix: plugin produces no output due to bindMethod failing on class instances (on opencode 1.4.7)#1

Open
raphaelfavier wants to merge 1 commit into
intellectronica:mainfrom
raphaelfavier:fix/fix-pluging-not-firing-with-opencode-1.4.7
Open

fix: plugin produces no output due to bindMethod failing on class instances (on opencode 1.4.7)#1
raphaelfavier wants to merge 1 commit into
intellectronica:mainfrom
raphaelfavier:fix/fix-pluging-not-firing-with-opencode-1.4.7

Conversation

@raphaelfavier
Copy link
Copy Markdown

@raphaelfavier raphaelfavier commented Apr 17, 2026

Problem

The plugin initialises correctly but never writes any files. The root cause is that fetchSessionSnapshot uses bindMethod() to extract get, messages, todo, and diff from ctx.client.session. Because the OpenCode client exposes these as class instance methods (on the prototype, not as own enumerable properties), bindMethod() returns null for all of them. The null-check guard then throws:

Session API unavailable on plugin context

This error is swallowed silently because logEvent has the same bug. It also uses bindMethod to find client.app.log, gets null back, and falls through without logging anything.

Diagnosed via a live debugging session (OpenCode 1.4.7).

Fix

Replace all bindMethod call sites that access client APIs with direct typed casts (ctx.client as { session: { get: ..., ... } }), calling methods directly. A try/catch fallback is used in logEvent to preserve the console fallback behaviour.

Three sites changed:

  • fetchSessionSnapshot — direct typed cast + call methods on the cast
  • logEvent — direct typed cast inside try/catch, fall through to console on failure
  • debug init block — typeof checks on the typed cast instead of bindMethod

No behaviour changes beyond fixing the broken API calls.

OpenCode's plugin context exposes client APIs as class instances, whose
methods are not enumerable own properties. bindMethod() walks own
properties and returns null for such methods, causing fetchSessionSnapshot
to throw 'Session API unavailable' and logEvent to silently skip logging.

Replace all three bindMethod call sites with direct typed casts:
- fetchSessionSnapshot: cast ctx.client to a typed interface and call
  session.get / .messages / .todo / .diff directly
- logEvent: cast ctx.client.app and call .log() inside a try/catch,
  falling back to console.error on failure
- debug init block: typeof checks on the typed cast instead of bindMethod

Diagnosed and confirmed via a live debugging session where the plugin
produced no output despite initialising correctly.
@raphaelfavier raphaelfavier changed the title fix: plugin doesn't work with opencode 1.4.7 fix: plugin produces no output due to bindMethod failing on class instances (on opencode 1.4.7) Apr 17, 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.

1 participant