feat: add forProject() + useProjectBus + deriveProjectId — project-scoped bus v0.6.7#16
Conversation
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 Recent review infoRun configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Files ignored due to path filters (6)
Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughWalkthrough
ChangesProject-scoped bus channels and useProjectBus hook
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Tip: You can configure your own custom pre-merge checks in the settings. Finishing TouchesGenerate docstrings
Generate unit tests (beta)
Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Nitpick comments (1)
src/tui.ts (1)
24-31: 💤 Low valueConsider using
forProjectsemantically inuseProjectBus.The implementation delegates to
useServiceBus, which internally callsforSession(sid)to scope the channel. While this produces the correct channel prefix (sinceforSessionandforProjectare functionally identical), it is semantically misleading: a project-scoped hook is using session-scoped internals.If
useServiceBuswere refactored to accept a genericscopeIdparameter and a scoping strategy (or if a paralleluseProjectBusInternalexisted that usesforProject), the code would be clearer. For now, this works correctly but may cause confusion during maintenance.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.ts` around lines 24 - 31, The `useProjectBus` function delegates to `useServiceBus`, which internally uses `forSession` for scoping, creating a semantic mismatch because a project-scoped hook is using session-scoped internals. To improve clarity during maintenance, refactor to make the scoping semantics explicit: either modify `useServiceBus` to accept a scoping strategy parameter that allows `useProjectBus` to pass `forProject` directly, or create a separate `useProjectBusInternal` function that uses `forProject` instead of relying on `useServiceBus` which uses `forSession`. This will ensure the code's semantics clearly reflect its intent, even though the current implementation produces functionally correct results.
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.
Inline comments:
In `@ISSUES.md`:
- Around line 88-109: The ISSUES.md document contains a contradiction where line
117 states that Issue `#3` was fixed so that BusTui.connect() throws on missing
bus with useServiceBus as the recommended path, but the code example in lines
95-109 shows a different pattern where BusTui.connect() returns a reconnecting
instance instead of throwing. Either replace the code example to match the
actual throw-on-fail behavior that was implemented in commit ccde741, add a
clarifying note that the example shows an alternative approach rather than what
was actually fixed, or remove the code example entirely and simply reference
useServiceBus as the recommended solution to resolve this inconsistency.
- Around line 124-130: The ISSUES.md table shows lifecycle patterns for Issues
`#1` (TUI reconnect with port re-discovery via BusTui.scheduleReconnect()) and `#3`
(TUI avoiding MemoryBusTui dead-end via BusTui.connect()) marked as "❌ missing"
in lines 128-129, but these same issues are documented as "✅ FIXED" elsewhere in
the document (lines 44 and 117). Additionally, the document states that the
useServiceBus hook was extracted to centralize these lifecycle patterns. Update
the table rows for the TUI reconnect and MemoryBusTui patterns to reflect their
actual completion status (mark as done or clarify that they are now implemented
within the useServiceBus hook) rather than leaving them marked as missing.
---
Nitpick comments:
In `@src/tui.ts`:
- Around line 24-31: The `useProjectBus` function delegates to `useServiceBus`,
which internally uses `forSession` for scoping, creating a semantic mismatch
because a project-scoped hook is using session-scoped internals. To improve
clarity during maintenance, refactor to make the scoping semantics explicit:
either modify `useServiceBus` to accept a scoping strategy parameter that allows
`useProjectBus` to pass `forProject` directly, or create a separate
`useProjectBusInternal` function that uses `forProject` instead of relying on
`useServiceBus` which uses `forSession`. This will ensure the code's semantics
clearly reflect its intent, even though the current implementation produces
functionally correct results.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Review info
Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b86cce3f-ffb7-4db3-b5a8-54dcc4198cf1
Files ignored due to path filters (12)
dist/bus-client.d.tsis excluded by!**/dist/**dist/bus-tui.d.tsis excluded by!**/dist/**dist/derive-project-id.d.tsis excluded by!**/dist/**dist/index.d.tsis excluded by!**/dist/**dist/index.jsis excluded by!**/dist/**dist/index.js.mapis excluded by!**/dist/**,!**/*.mapdist/project-id.d.tsis excluded by!**/dist/**dist/tui-components/progress-bar.jsxis excluded by!**/dist/**dist/tui-hooks.d.tsis excluded by!**/dist/**dist/tui.d.tsis excluded by!**/dist/**dist/tui.jsis excluded by!**/dist/**dist/tui.js.mapis excluded by!**/dist/**,!**/*.map
Files selected for processing (10)
ISSUES.mdpackage.jsonscripts/build.tssrc/bus-client.tssrc/bus-tui.tssrc/derive-project-id.tssrc/index.tssrc/tui-hooks.tssrc/tui.tstest/integration.test.ts
There was a problem hiding this comment.
2 issues found and verified against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Closes #13 Removes the automatic fallback to MemoryBusTui when the Go bus is not reachable. Callers that want in-process mode can now instantiate 'new MemoryBusTui()' explicitly. This prevents silent subscription failures where a TUI subscribes to a pattern via MemoryBusTui, never sees any messages (because the server-side plugin publishes via the real Go bus), and the user has no idea why. After this change: - BusTui.connect() throws a clear error if the Go bus is unreachable - MemoryBusTui is still exported for callers that want it explicitly - Both consumers (brain, tbguard) already have try/catch or .catch handlers, so they degrade gracefully and log a warning - Tests are not affected (integration test runs the real Go bus; scoped-close test also runs the real Go bus) Updates MemoryBusTui JSDoc to note opt-in usage and the integration test header comment to reflect the new contract.
Add unmount guard and reconnect-with-backoff to useServiceBus hook. Prevents leaks when a TUI component unmounts while BusTui.connect() is still in-flight (the resulting handle is closed immediately). On connect failure, retries every 5s instead of silently giving up. Ref: #13
…move BusCallback cast
Closes #15 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b95c06f to
1ee98f2
Compare
|
Re: cubic-dev-ai P2 — ✅ Confirmed valid. Here's the failure chain:
Fix: Call Will PR this as a follow-up to #16. |
|
Re: coderabbitai & cubic-dev-ai — ✅ Valid. Lines 128-129 mark Issues #1 and #3 as "❌ missing" in the lifecycle patterns table, but:
The table hasn't been updated since the fixes landed. Will update both rows to reflect completion status. Also applies to the code example mismatch at lines 95-109 which shows the old |
|
Re: coderabbitai nitpick — Noted. The current implementation delegates I'll keep this as-is for now because:
Filed as a low-priority cleanup item for the next wave. |
Summary
forProject(id)toBusClientandBusTui(and their scoped variants) — completes the planned scope triad alongsideforServiceandforSessionuseProjectBushook,deriveProjectId(FNV-1a hash), BusTui/MemoryBusTui exports, ping-retry fix, cancellation-safe connectCloses #15
Test plan
forProjectchains correctly:bus.forService("brain").forProject(id).publish("status", ...)→ channelbrain/{id}/statususeProjectBus("brain", directory, "status", cb)subscribes and receives messages on project channel🤖 Generated with Claude Code
Summary by cubic
Adds project-scoped bus channels via
forProject(),useProjectBus, andderiveProjectIdso plugins can route messages per project. Also removes the TUI’s silent fallback:BusTui.connect()now throws if the Go bus is unavailable; opt in toMemoryBusTuifor in-process mode (v0.7.1).New Features
BusClient/BusTui:forProject(id)prefixes channels with{projectId}/and composes withforService/forSession.useProjectBus(service, directory, channel, cb)+deriveProjectId(directory)(FNV-1a); addsuseServiceBuswith cancellation-safe connect, cleanup, and retry.MemoryBusTui,useServiceBus,deriveProjectId; ignoredist/in.gitignore.Migration
BusTui.connect()now throws when the Go bus isn’t reachable; usenew MemoryBusTui()for in-process mode or wrap in try/catch to handle degraded behavior.Written for commit 1ee98f2. Summary will update on new commits.
Summary by CodeRabbit
New Features
Chores