Skip to content

OpenCode plugin: richer event mapping (blocked state, file tracking, session lifecycle) #188

Closed

Description

@zutur

Summary

The OpenCode plugin (plugin/wmux.js) currently handles session.idle, session.error, message.part.updated, and tool events. OpenCode exposes additional events that would improve the sidebar experience — most notably showing "Needs you" when the agent is waiting for user input.

Proposed event mappings

Blocked/unblocked state

OpenCode fires question.asked and permission.asked when the agent needs user input (e.g. a permission prompt or a multi-choice question). When the user responds, question.replied / permission.replied follow.

These map naturally to report-agent --blocked / --unblocked:

event: async ({ event }) => {
  // ... existing handlers ...
  if (event.type === "question.asked" || event.type === "permission.asked") {
    wmux(["report-agent", "--surface", surface, "--blocked", "Waiting for user input"]);
  } else if (event.type === "question.replied" || event.type === "permission.replied") {
    wmux(["report-agent", "--surface", surface, "--unblocked"]);
  }
}

Without this, the sidebar stays on "Running" while the agent is actually idle and waiting — the user has no way to tell which pane needs attention without switching to it.

Other events worth considering

OpenCode also fires events that have no equivalent in Claude Code hooks but could be useful:

OpenCode event Potential wmux action Notes
session.created agent-activity --active New session started
session.compacted informational Context window was compacted
file.edited hook --event PostToolUse --tool Edit + file path File change tracking for diff view
command.executed informational User ran a slash command

These are lower priority than the blocked/unblocked state, which has the most direct user-facing impact.

Context

Related to #187 — once process.execPath is fixed so that execFile calls actually work, these event mappings become the next improvement for OpenCode support.

Activity

  1. amirlehmam commented on Aug 22, 2026

    @amirlehmam
    Owner

    Shipped in v1.9.0, together with #187 — you were right that the two were joined at the hip, so there was no point mapping more events onto a transport that never fired.

    Blocked / unblocked — implemented as you proposed:

    OpenCode event wmux
    question.asked, permission.asked, permission.requested report-agent --blocked <reason>
    question.replied, permission.replied (+ .answered) report-agent --unblocked

    The reason is pulled out of the event payload where there is one (title, text, a nested question/permission), capped at 200 chars, with a generic fallback otherwise — so the sidebar reads "Run migration?" rather than "Waiting for user input" when OpenCode gives it something to work with.

    Two deliberate deviations, both about the failure mode rather than the happy path:

    The ask events are matched exactly, not by prefix. permission.updated fires on both sides of the exchange in some builds, and a mis-classified one leaves a pane reading "Needs you" for the rest of the session — which is worse than no indicator, because it makes the whole sidebar untrustworthy.

    There is a self-heal. The unblock depends on OpenCode emitting a matching *.replied. If a build renames it, or the user answers in some way that fires nothing, we'd be stuck. So any evidence of the agent working — a streamed token, a tool call — also clears blocked, since an agent producing output is definitively not waiting on a human.

    Conversely, session.idle does not unblock. A pane parked on a permission prompt is idle by definition, and clearing there would erase "Needs you" the instant it appeared. (Same principle as answer-agent in #128: answering never clears the blocked flag either — only the agent's own confirmation does, or a mis-declared keystroke silently stops a stuck pane from asking for help.)

    Also from your table:

    • session.created → agent-activity --active.
    • file.edited → hook --event PostToolUse --tool Edit, which feeds the diff view the same way Claude Code's PostToolUse hook does. Note it can't carry the path yet — wmux hook takes --event / --tool / --agent and nothing else. Worth a follow-up if per-file tracking would be useful to you; say the word and I'll open one.
    • session.compacted and command.executed I left out for now — informational, and I'd rather not have the sidebar emit events with no visible consequence.

    Thanks for both reports — two real bugs in the OpenCode path in one sitting, and the level of detail (down to the exact argv OpenCode ends up receiving) is what made them a same-day fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions