Skip to content

feat: route BusClient warnings to app.log + toast on fallback #153#154

Closed
four-bytes-robby wants to merge 1 commit into
mainfrom
feat/153-busclient-applog-toast
Closed

feat: route BusClient warnings to app.log + toast on fallback #153#154
four-bytes-robby wants to merge 1 commit into
mainfrom
feat/153-busclient-applog-toast

Conversation

@four-bytes-robby

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

Copy link
Copy Markdown
Member

Closes #153

Changes

  • getBus() passes onWarn callback to BusClient.connect() — routes warnings to app.log
  • Detects MemoryBusClient fallback (activePort === 0) and shows a toast
  • .catch() handler upgraded from warn to error level + toast

Depends on

  • @four-bytes/opencode-plugin-lib v0.7.0 (merged, not yet published — using local path)

Summary by cubic

Routes BusClient warnings to app.log and shows toasts when the bus falls back to memory or fails to connect. Improves visibility and guides users to install the local bus.

  • New Features

    • Forward BusClient.connect() warnings to app.log.
    • Show a warning toast when the bus falls back to in-memory; suggest installing four-local-bus.
    • On connection failure, log at error level and show an error toast; reset the internal connection promise to allow retry.
  • Dependencies

    • Move to @four-bytes/opencode-plugin-lib v0.7.0 via local file: path until published.
    • Bump package version to 1.7.8.

Written for commit 0b9492b. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved connection error handling with clearer error messages and user notifications.
    • Added warning notifications when cross-process communication is unavailable.
  • Chores

    • Version bump to 1.7.8.
    • Updated dependency reference.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Walkthrough

getBus() in src/status.ts is updated to pass an onWarn callback to BusClient.connect, show a TUI warning toast when the bus falls back to in-memory mode (activePort === 0), log and display a truncated error toast on connection failure, reset _busPromise to allow reconnect, and rethrow the error. package.json bumps the version to 1.7.8 and switches @four-bytes/opencode-plugin-lib to a local file reference.

Changes

BusClient warning routing and local dependency reference

Layer / File(s) Summary
Package version bump and local dep reference
package.json
Version incremented from 1.7.7 to 1.7.8; @four-bytes/opencode-plugin-lib source changed from github:four-bytes/four-opencode-plugin-lib#v0.6.1 to file:../four-opencode-plugin-lib.
getBus() onWarn, fallback toast, and error handling
src/status.ts
BusClient.connect now receives an onWarn callback that forwards warnings through the plugin client logger. On success, activePort === 0 triggers a warning toast. On failure, an error is logged, a toast with the error string truncated to 80 characters is shown, _busPromise is reset to null, and the error is rethrown.

Estimated code review effort

3 (Moderate) | ~15 minutes

Possibly related issues

Possibly related PRs

  • four-bytes/four-opencode-brain#150: Modifies the same getBus() connection error and warning handling paths in src/status.ts, routing bus failures through _client?.app?.log.
Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: routing BusClient warnings to app.log and showing a toast on fallback, with reference to issue #153.
Description check ✅ Passed The description provides a clear overview of changes, addresses the related issue #153, and follows the template structure with adequate detail about implementation and dependencies.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #153: passes onWarn callback to BusClient.connect() routing to app.log, detects MemoryBusClient fallback via activePort === 0, shows toast notification, and upgrades error handling with toast feedback.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #153: version bump aligns with feature delivery, dependency change supports the required library version, and src/status.ts modifications implement the specified warning and fallback handling.

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/153-busclient-applog-toast
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/153-busclient-applog-toast

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.

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 `@package.json`:
- Line 18: The `"`@four-bytes/opencode-plugin-lib`":
"file:../four-opencode-plugin-lib"` dependency in package.json uses a local file
reference that will break when the package is published to npm. Either configure
the project to use a workspace setup that conditionally resolves this for
development while maintaining a valid publishable dependency for releases, or
replace the file: reference with a proper semver version number or git reference
to `@four-bytes/opencode-plugin-lib` that is installable for npm consumers.
Additionally, ensure that bun.lock is regenerated after resolving the dependency
to reflect the publishable state.
🪄 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: 724976ea-b499-44e7-a529-06c1f1c690cd

Commits

Reviewing files that changed from the base of the PR and between a676f50 and 0b9492b.

Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
Files selected for processing (2)
  • package.json
  • src/status.ts

Comment thread package.json
],
"dependencies": {
"@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.6.1",
"@four-bytes/opencode-plugin-lib": "file:../four-opencode-plugin-lib",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether the repo documents/enforces sibling checkout for local file deps
# and whether package managers will need ../four-opencode-plugin-lib to exist.

set -euo pipefail

echo "== package.json dependency =="
cat package.json | sed -n '1,140p' | rg -n '"`@four-bytes/opencode-plugin-lib`"|\"name\"|\"version\"'

echo
echo "== docs/scripts mentioning four-opencode-plugin-lib sibling checkout =="
rg -n -C2 'four-opencode-plugin-lib|file:\.\./four-opencode-plugin-lib|git submodule|workspace|monorepo' README.md docs/ .github/ scripts/ 2>/dev/null || true

echo
echo "== lockfiles (if present) containing local file reference =="
fd -HI '(^|/)(bun\.lockb|bun\.lock|package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$' | while read -r f; do
  echo "-- $f"
  rg -n 'four-opencode-plugin-lib|file:\.\./four-opencode-plugin-lib' "$f" || true
done

Repository: four-bytes/four-opencode-brain

Length of output: 277


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== package.json content (lines 1-50) =="
head -50 package.json

echo ""
echo "== Package name and version =="
cat package.json | grep -E '"name"|"version"'

echo ""
echo "== All dependencies mentioning four-opencode-plugin-lib =="
cat package.json | grep -n 'four-opencode-plugin-lib'

Repository: four-bytes/four-opencode-brain

Length of output: 1877


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== README or documentation mentioning sibling checkout or monorepo =="
for file in README.md README.rst CONTRIBUTING.md SETUP.md docs/SETUP.md; do
  if [ -f "$file" ]; then
    echo "-- Found: $file"
    cat "$file" | head -100
  fi
done

echo ""
echo "== Check if ../four-opencode-plugin-lib is documented =="
rg 'four-opencode-plugin-lib|sibling|monorepo|workspace' --type md --type txt 2>/dev/null || echo "No matches found"

Repository: four-bytes/four-opencode-brain

Length of output: 8546


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Lockfiles present in repo =="
fd -HI '\.(lock|lockb|yaml)$' | grep -E '(package-lock|pnpm-lock|yarn\.lock|bun\.lock|bun\.lockb)' || echo "No lockfiles found"

echo ""
echo "== Directory structure - check for sibling four-opencode-plugin-lib =="
ls -la ../ 2>/dev/null | grep four-opencode || echo "Cannot list parent directory"

Repository: four-bytes/four-opencode-brain

Length of output: 216


Resolve local file: dependency before publishing to npm.

"@four-bytes/opencode-plugin-lib": "file:../four-opencode-plugin-lib" at line 18 makes this published npm package uninstallable by consumers. Installation instructions in README.md and docs/SETUP.md do not document the required sibling checkout; users and CI runners following the documentation will fail with missing module errors. The bun.lock file locks this broken state.

For development: gate the file: dependency behind a dev-only condition or workspace setup. For releases: replace with a publishable semver/git ref to @four-bytes/opencode-plugin-lib, or build/publish it separately.

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 `@package.json` at line 18, The `"`@four-bytes/opencode-plugin-lib`":
"file:../four-opencode-plugin-lib"` dependency in package.json uses a local file
reference that will break when the package is published to npm. Either configure
the project to use a workspace setup that conditionally resolves this for
development while maintaining a valid publishable dependency for releases, or
replace the file: reference with a proper semver version number or git reference
to `@four-bytes/opencode-plugin-lib` that is installable for npm consumers.
Additionally, ensure that bun.lock is regenerated after resolving the dependency
to reflect the publishable state.

@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.

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="package.json">

<violation number="1" location="package.json:18">
P1: The `file:../four-opencode-plugin-lib` reference will make this package uninstallable for any consumer or CI runner that doesn't have the sibling directory checked out. If this merges and gets published to npm, all installations will fail with a missing module error. Replace with a publishable semver or git ref (e.g., `github:four-bytes/four-opencode-plugin-lib#v0.7.0`) before merging, or gate it behind a workspace/dev-only mechanism.</violation>
</file>

<file name="src/status.ts">

<violation number="1" location="src/status.ts:94">
P2: Bus-connect failure toast is unthrottled and can spam on repeated status writes during outages. Gate this toast (once per window/once per outage) before showing it.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread package.json
],
"dependencies": {
"@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.6.1",
"@four-bytes/opencode-plugin-lib": "file:../four-opencode-plugin-lib",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: The file:../four-opencode-plugin-lib reference will make this package uninstallable for any consumer or CI runner that doesn't have the sibling directory checked out. If this merges and gets published to npm, all installations will fail with a missing module error. Replace with a publishable semver or git ref (e.g., github:four-bytes/four-opencode-plugin-lib#v0.7.0) before merging, or gate it behind a workspace/dev-only mechanism.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At package.json, line 18:

<comment>The `file:../four-opencode-plugin-lib` reference will make this package uninstallable for any consumer or CI runner that doesn't have the sibling directory checked out. If this merges and gets published to npm, all installations will fail with a missing module error. Replace with a publishable semver or git ref (e.g., `github:four-bytes/four-opencode-plugin-lib#v0.7.0`) before merging, or gate it behind a workspace/dev-only mechanism.</comment>

<file context>
@@ -15,7 +15,7 @@
   ],
   "dependencies": {
-    "@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.6.1",
+    "@four-bytes/opencode-plugin-lib": "file:../four-opencode-plugin-lib",
     "@opencode-ai/plugin": "1.16.2",
     "@opentui/core": "0.3.2",
</file context>
Suggested change
"@four-bytes/opencode-plugin-lib": "file:../four-opencode-plugin-lib",
"@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.7.0",

Comment thread src/status.ts
return bus;
}).catch((err) => {
_client?.app?.log({ body: { service: "brain", level: "error", message: "BusClient connect failed", extra: { error: String(err) } } }).catch(() => {});
_client?.tui?.showToast({ body: { title: "Brain 🧠", message: "Bus connection failed: " + String(err).slice(0, 80), variant: "error", duration: 7000 } });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Bus-connect failure toast is unthrottled and can spam on repeated status writes during outages. Gate this toast (once per window/once per outage) before showing it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/status.ts, line 94:

<comment>Bus-connect failure toast is unthrottled and can spam on repeated status writes during outages. Gate this toast (once per window/once per outage) before showing it.</comment>

<file context>
@@ -79,9 +79,20 @@ export function initStatus(client: PluginInput["client"], directory: string): vo
+      return bus;
+    }).catch((err) => {
+      _client?.app?.log({ body: { service: "brain", level: "error", message: "BusClient connect failed", extra: { error: String(err) } } }).catch(() => {});
+      _client?.tui?.showToast({ body: { title: "Brain 🧠", message: "Bus connection failed: " + String(err).slice(0, 80), variant: "error", duration: 7000 } });
+      _busPromise = null;
       throw err;
</file context>

@four-bytes-robby

Copy link
Copy Markdown
Member Author

Superseded — combined with #151 + #152 into a unified startup/bus fix.

@four-bytes-robby four-bytes-robby deleted the feat/153-busclient-applog-toast branch June 15, 2026 15:15
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.

Route BusClient fallback warnings to app.log + toast instead of console.warn

1 participant