Skip to content

[FEAT] Add session-aware forService/forSession scoped bus API #8

@four-bytes-robby

Description

@four-bytes-robby

Goal

Add forService(name) and forSession(id) scope helpers to both BusClient (server) and BusTui (TUI) so plugins can publish/subscribe under a prefixed channel namespace without repeating the prefix string at every call site.

Context

Plugins currently repeat channel prefixes everywhere (tbg/ses_abc/status, brain/embed, etc.). A scoped sub-client pattern lets bus.forSession("ses_abc").publish("status", payload) resolve to tbg/ses_abc/status, reducing typos and improving discoverability of which channels belong to which service/session.

Scope

Two files, two scopes each:

src/bus-client.ts

  • Add forService(name: string): BusClient and forSession(id: string): BusClient to BusClient.
  • Introduce a private ScopedBusClient class that wraps a BusClient and prepends a prefix to publish. Delegates healthCheck, activePort. Re-scopes via nested forService/forSession.

src/bus-tui.ts

  • Add forService(name: string): BusTui and forSession(id: string): BusTui to BusTui.
  • Introduce a private ScopedBusTui class that wraps a BusTui and prepends a prefix to both subscribe and publish. Delegates close. Re-scopes via nested forService/forSession.

Acceptance

  • bun run build succeeds
  • forService("tbg").forSession("ses_abc").publish("status", x) resolves channel tbg/ses_abc/status
  • forSession("ses_abc").subscribe("status", cb) matches tbg/ses_abc/status (with appropriate wildcard semantics)
  • Scoped clients compose: nested forService / forSession stack prefixes

Out of scope

  • Refactoring existing call sites to use the new API (separate issue)
  • Tests (separate issue; developer-mini tier)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    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