Skip to content

[P17b] Implement BusClient — server-side HTTP publisher #1

@four-bytes-robby

Description

@four-bytes-robby

Purpose

Server-side client for plugin bus. Plugins import BusClient, read port file, publish messages via HTTP POST.

Scope

BusClient class

class BusClient {
  static async connect(): Promise<BusClient>
  async publish(channel: string, payload: unknown): Promise<void>
  async healthCheck(): Promise<boolean>
  get port(): number
}

Discovery

  • Read ~/.cache/opencode/plugin-bus/port.json → extract port
  • Retry up to 3s if file doesn't exist yet (bus starting up)
  • Cache port in memory

Publish

  • HTTP POST to http://127.0.0.1:{port}/publish
  • JSON body: { channel, payload }
  • Timeout: 5s
  • Error handling: throw on non-200, log warning on timeout

Files

  • src/bus-client.ts
  • src/discovery.ts (shared with BusTui)

Acceptance

  • Unit tests with mock HTTP server
  • Integration test: real Go bus, publish message, verify received

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions