Skip to content

feat: migrate to scoped bus API (forService/forSession) - #41

Merged
four-bytes-robby merged 1 commit into
mainfrom
feat/scoped-bus-migration
Jun 14, 2026
Merged

feat: migrate to scoped bus API (forService/forSession)#41
four-bytes-robby merged 1 commit into
mainfrom
feat/scoped-bus-migration

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 14, 2026

Copy link
Copy Markdown
Member

Replaces manual channel string building with scoped bus API.


Summary by cubic

Migrated publishing and subscriptions to the scoped bus API (forService/forSession) to replace manual topic strings. This standardizes channel construction and reduces routing mistakes.

  • Refactors
    • src/bus-publisher.ts: publish moved from tbg/${sessionID}/status to bus.forService("tbg").forSession(sessionID).publish("status", ...).
    • src/tui.tsx: subscribe moved from tbg/${session_id}/status to bus.forService("tbg").forSession(props.session_id).subscribe("status", ...).

Written for commit 5f660a4. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Refactor
    • Enhanced internal event communication patterns using modern API conventions for improved consistency and maintainability across the application.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Walkthrough

Both BusPublisher.publish() and TokenMeterView replace manual topic string construction (tbg/${id}/status) with the chained fluent selector API (forService("tbg").forSession(id).publish/subscribe("status", ...)). All payload contents, status logic, and cleanup behavior are unchanged.

Changes

Fluent bus selector migration

Layer / File(s) Summary
Migrate publish and subscribe to fluent API
src/bus-publisher.ts, src/tui.tsx
BusPublisher.publish() switches from the topic string tbg/${sessionID}/status to forService("tbg").forSession(sessionID).publish("status", ...), and TokenMeterView switches its BusTui subscription from the equivalent topic string to forService("tbg").forSession(session_id).subscribe("status", ...).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating from manual topic string construction to using the scoped bus API (forService/forSession methods).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Tip: You can configure your own custom pre-merge checks in the settings.

Finishing Touches
Generate docstrings
  • Create stacked PR
  • Commit on current branch
Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/scoped-bus-migration
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/scoped-bus-migration

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tui.tsx (1)

31-37: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove as any type assertion - violates strict type safety guideline.

Line 31 uses as any, which explicitly violates the coding guideline: "No any type usage in TypeScript code; maintain strict type safety". The payload type should match the published structure from src/bus-publisher.ts (lines 43-49).

Proposed fix with proper typing
+interface StatusPayload {
+  sessionID: string;
+  cumulative: number;
+  softLimit: number;
+  hardLimit: number;
+  percentage: number;
+  status: string;
+}
+
 bus.forService("tbg").forSession(props.session_id).subscribe("status", (msg) => {
-  const p = msg.payload as any;
+  const p = msg.payload as StatusPayload;
   if (typeof p.cumulative === "number") {
     setTokens(p.cumulative);
   }
   if (typeof p.hardLimit === "number") {
     setLimit(p.hardLimit);
   }
 });
Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tui.tsx` around lines 31 - 37, Remove the `as any` type assertion on
msg.payload at line 31 and replace it with the proper TypeScript type imported
from src/bus-publisher.ts that defines the payload structure. The correct type
should properly define the cumulative and hardLimit properties being accessed in
the subsequent typeof checks, eliminating the need for type narrowing and
maintaining strict type safety throughout the assignment to variable p.

Source: Coding guidelines

Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/tui.tsx`:
- Around line 31-37: Remove the `as any` type assertion on msg.payload at line
31 and replace it with the proper TypeScript type imported from
src/bus-publisher.ts that defines the payload structure. The correct type should
properly define the cumulative and hardLimit properties being accessed in the
subsequent typeof checks, eliminating the need for type narrowing and
maintaining strict type safety throughout the assignment to variable p.

Review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0626c877-bbca-498d-b9f7-7750a79e21a1

Commits

Reviewing files that changed from the base of the PR and between da91fea and 5f660a4.

Files selected for processing (2)
  • src/bus-publisher.ts
  • src/tui.tsx

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@four-bytes-robby
four-bytes-robby merged commit db751cd into main Jun 14, 2026
5 checks passed
@four-bytes-robby
four-bytes-robby deleted the feat/scoped-bus-migration branch June 14, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant