fix(tui): subscribe to global events for bidirectional Web sync
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:
- Work on TUI at desk
- Step away, continue conversation via Web UI on phone/tablet
- Return to desk, TUI immediately shows all messages from Web session
- 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:
- TUI only renders matching sessionID - no incorrect data displayed
- Single-project usage (most common) has no impact
- 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
GlobalEventtype - Change
sdk.event.subscribe()tosdk.global.event() - Extract payload from
GlobalEvent.payload
- Import
Testing
Verified bidirectional sync works:
- Start TUI with
opencode - Open Web UI at
http://localhost:<port> - Send message from Web UI → TUI shows it ✅
- Send message from TUI → Web UI shows it ✅