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
Purpose
Server-side client for plugin bus. Plugins import BusClient, read port file, publish messages via HTTP POST.
Scope
BusClient class
Discovery
~/.cache/opencode/plugin-bus/port.json→ extract portPublish
http://127.0.0.1:{port}/publish{ channel, payload }Files
Acceptance