Skip to content

[P17b] Implement BusTui — WebSocket subscriber for TUI plugins #2

Description

@four-bytes-robby

Purpose

TUI-side client for plugin bus. TUI components import BusTui, connect WebSocket, subscribe to channels with callbacks.

Scope

BusTui class

class BusTui {
  static async connect(): Promise<BusTui>
  subscribe(pattern: string, callback: (msg: BusMessage) => void): () => void
  async publish(channel: string, payload: unknown): Promise<void>
  close(): void
}

WebSocket connection

  • Connect to ws://127.0.0.1:{port}/subscribe?channels={patterns}
  • Parse JSON messages: { channel, payload }
  • Re-subscribe on reconnect (accumulate patterns)

Auto-reconnect

  • On disconnect: retry with exponential backoff (1s, 2s, 4s, max 30s)
  • Re-read port file on reconnect (port may have changed)
  • Fire onConnect/onDisconnect callbacks

Bidirectional

  • publish() sends message back to bus via WebSocket JSON message
  • Bus routes to other subscribers

Files

  • src/bus-tui.ts
  • src/discovery.ts (shared module)

Acceptance

  • Unit tests with mock WebSocket server
  • Integration test: connect to Go bus, subscribe, publish from server side, verify callback fires

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions