fix: sidebar always subscribes to brain/status for ingest progress#148
Conversation
|
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 (1)
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 (3)
WalkthroughWalkthroughStatus publishing is refactored to scope updates to sessions via ChangesEnd-to-end session-scoped status lifecycle
CLI infrastructure and documentation updates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 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: 1
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 `@src/tui.tsx`:
- Around line 87-91: The session subscription logic is currently in an onMount
hook which only runs once during component initialization, causing it to skip
the session subscription if props.sessionId is undefined at that time and never
recheck when it becomes available later. Move the bus and unsubSession variables
to component scope, import createEffect from "solid-js", and replace the
session-scoped subscription conditional block (the if statement checking
props.sessionId that calls scoped.forSession and handleStatus) with a
createEffect that reactively watches both bus and props.sessionId as
dependencies, re-establishing the subscription whenever either changes, while
ensuring proper cleanup of the previous unsubSession when the effect re-runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
There was a problem hiding this comment.
Nitpick comments (1)
src/four-opencode-brain.ts (1)
653-676: 💤 Low valueConsider adding initial busy status for consistency.
Unlike
brain_search(line 314) which callsupdateStatus("busy", { text: "searching..." })at the start,brain_kb_searchdoes not set a busy indicator before executing the search. This results in inconsistent UX where one search operation shows a status indicator and the other does not.Suggested fix
execute: async (args, toolCtx) => { return withSessionId(toolCtx.sessionID, async () => { + updateStatus("busy", { text: "searching knowledge..." }); const db = initBrainDatabase(); try {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/four-opencode-brain.ts` around lines 653 - 676, Add an initial busy status indicator to the brain_kb_search tool's execute function to match the UX pattern used in brain_search. Call updateStatus("busy", { text: "searching..." }) at the start of the execute function (after initBrainDatabase but before the try block), and ensure the status is reset to "ready" not just in the catch block for errors but also after successful completion, possibly by moving the updateStatus("ready") call to the finally block to guarantee it runs in both success and failure paths.
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.
Nitpick comments:
In `@src/four-opencode-brain.ts`:
- Around line 653-676: Add an initial busy status indicator to the
brain_kb_search tool's execute function to match the UX pattern used in
brain_search. Call updateStatus("busy", { text: "searching..." }) at the start
of the execute function (after initBrainDatabase but before the try block), and
ensure the status is reset to "ready" not just in the catch block for errors but
also after successful completion, possibly by moving the updateStatus("ready")
call to the finally block to guarantee it runs in both success and failure
paths.
Review info
Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5f3e23c8-2b1a-4b02-bc29-1bdd2d3af697
Files selected for processing (2)
src/four-opencode-brain.tssrc/status.ts
Enables `bun link` to install brain-cli globally (~/.bun/bin/brain-cli). Makes the brain accessible from Claude Code, Cursor, and any AI tool via Bash — not just opencode's native plugin tool calls.
…ion subscription onMount fires once — if sessionId is undefined at mount time (sidebar exists before any session), the early return prevents the subscription from ever being set up. When the session is later created, props.sessionId changes reactively but onMount does not re-run, so the TUI never receives bus events. Fix: split into two parts: - onMount: establishes the BusTui connection exactly once per component instance - createEffect: reactively subscribes/resubscribes whenever busTui() or props.sessionId changes; onCleanup inside the effect tears down stale subscriptions before each re-run This ensures the sidebar status bar connects correctly even when it mounts before a session exists (the typical case).
Sidebar now subscribes to both unscoped (brain/status) and scoped (brain/{sessionID}) channels so ingest progress is visible before session ID is set.
Summary by cubic
Scope brain status updates to the active session on both publish and subscribe, defer auto‑ingest until a session exists, and re‑publish status when a session attaches so progress appears in the right session (including continue mode). Also expose a
brain-clibinary for global use.Bug Fixes
useServiceBusfrom@four-bytes/opencode-plugin-lib@v0.6.1to subscribe toforService("brain").forSession(sessionId)and re‑subscribe whensessionIdchanges; passessessionIdinto sidebar andhome_bottom; cleans up automatically.withSessionId; defers auto‑ingest tosession.createdand runs once inside the session; skips bus publish when nosessionId; re‑publishes current state onsetSessionIdso continue mode receives status.New Features
brain-cliin thebinfield so it can be installed globally (e.g.,bun link) and used from the shell.Written for commit 77dbb88. Summary will update on new commits.
Summary by CodeRabbit
brain-cliexecutable entry point.