opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(tui): subscribe to global events for bidirectional Web sync

Open MichaelC001 opened this issue 4 days ago • 0 comments

Use Case

Many users primarily work with TUI at their desk, but occasionally need to continue working from a mobile device or browser when away from the computer.

Current behavior: When you send messages from Web UI while away, returning to TUI shows no updates - you need to restart TUI to see the messages sent from Web.

Expected behavior: TUI should receive and display messages sent from Web UI in real-time, allowing seamless transition between TUI and Web workflows.

This is a practical scenario:

  1. Work on TUI at desk
  2. Step away, continue conversation via Web UI on phone/tablet
  3. Return to desk, TUI immediately shows all messages from Web session
  4. Continue working on TUI without missing any context

Problem

  • TUI → Web: ✅ syncs in real-time
  • Web → TUI: ❌ requires TUI restart to see messages

Root Cause

TUI subscribes to /event endpoint (instance-level Bus), while Web UI publishes events to GlobalBus via /global/event.

Solution

Change TUI to subscribe to /global/event endpoint instead of /event.

Trade-off

TUI will receive events from all directories (if server manages multiple projects). However:

  1. TUI only renders matching sessionID - no incorrect data displayed
  2. Single-project usage (most common) has no impact
  3. Directory filtering can be added client-side if needed

Changes

Minimal change - only 1 file, ~10 lines:

  • packages/opencode/src/cli/cmd/tui/context/sdk.tsx
    • Import GlobalEvent type
    • Change sdk.event.subscribe() to sdk.global.event()
    • Extract payload from GlobalEvent.payload

Testing

Verified bidirectional sync works:

  1. Start TUI with opencode
  2. Open Web UI at http://localhost:<port>
  3. Send message from Web UI → TUI shows it ✅
  4. Send message from TUI → Web UI shows it ✅

MichaelC001 avatar Jan 03 '26 06:01 MichaelC001