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)
Goal
Add
forService(name)andforSession(id)scope helpers to bothBusClient(server) andBusTui(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 letsbus.forSession("ses_abc").publish("status", payload)resolve totbg/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.tsforService(name: string): BusClientandforSession(id: string): BusClienttoBusClient.ScopedBusClientclass that wraps aBusClientand prepends a prefix topublish. DelegateshealthCheck,activePort. Re-scopes via nestedforService/forSession.src/bus-tui.tsforService(name: string): BusTuiandforSession(id: string): BusTuitoBusTui.ScopedBusTuiclass that wraps aBusTuiand prepends a prefix to bothsubscribeandpublish. Delegatesclose. Re-scopes via nestedforService/forSession.Acceptance
bun run buildsucceedsforService("tbg").forSession("ses_abc").publish("status", x)resolves channeltbg/ses_abc/statusforSession("ses_abc").subscribe("status", cb)matchestbg/ses_abc/status(with appropriate wildcard semantics)forService/forSessionstack prefixesOut of scope
developer-minitier)