Skip to content

Commit b90443d

Browse files
Revert "feat(tui): mount plugin-lib StatusPanel/StatusLine via slot bridge (v0.12.3, #260)" (#263)
This reverts commit 6c4f645.
1 parent 6c4f645 commit b90443d

11 files changed

Lines changed: 424 additions & 169 deletions

File tree

‎HISTORY.md‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# Changelog
22

3-
## v1.10.0 (2026-11-29)
4-
5-
### Changed
6-
7-
- Bumped `@four-bytes/opencode-plugin-lib` to v0.12.2 and switched back to the shared `StatusPanel` (home) / `StatusLine` (sidebar). Both are mounted through `useSlotStatusBridge(api.renderer)` inside renderer-mounted components, so the retained status signal lives in the host's root and every update requests the next frame (#260, plugin-lib #76).
8-
- `reportStatus` now carries the build-time version on every report, so the panel shows `brain <version>` itself; the `ready`/`success` summaries fall back to the single word `ready`.
9-
- Dropped the `tsconfig.tui.json` `paths` override — plugin-lib v0.12.1+ ships compiled `dist/tui-components` plus `.d.ts`.
10-
- Removed brain's own status row; the shared components replace it.
11-
123
## v1.9.0 (2026-11-29)
134

145
### Changed

‎bun.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@four-bytes/four-opencode-brain",
3-
"version": "1.10.0",
3+
"version": "1.9.0",
44
"description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base",
55
"license": "Apache-2.0",
66
"type": "module",
@@ -16,7 +16,7 @@
1616
"four-bytes"
1717
],
1818
"dependencies": {
19-
"@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.12.3",
19+
"@four-bytes/opencode-plugin-lib": "github:four-bytes/four-opencode-plugin-lib#v0.12.0",
2020
"@opencode-ai/plugin": "1.16.2",
2121
"@opentui/core": "0.4.5",
2222
"@opentui/solid": "0.4.5",

‎scripts/build.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const sharedFile = "dist/shared.js";
4141
const sharedSource = await Bun.file(sharedFile).text();
4242
if (!sharedSource.includes("__BRAIN_BUILD_VERSION__")) {
4343
throw new Error(
44-
"dist/shared.js is missing __BRAIN_BUILD_VERSION__ — did src/shared.ts change?",
44+
"dist/shared.js is missing __BRAIN_BUILD_VERSION__ — did src/tui.tsx stop importing ./shared?",
4545
);
4646
}
4747
await Bun.write(sharedFile, `const __BRAIN_BUILD_VERSION__ = ${versionLiteral};\n${sharedSource}`);

‎src/shared.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
*
66
* scripts/build.ts injects the package.json version into both bundles: the
77
* server through Bun's `define`, the TUI through a prelude in dist/shared.js.
8-
* A shipped build therefore never reads package.json; VERSION is forwarded
9-
* through `reportStatus` (the `version` field) and rendered by the shared
10-
* plugin-lib `StatusPanel`.
8+
* A shipped build therefore never reads package.json, and the TUI row can show
9+
* the version from its very first frame.
1110
*
1211
* Dev and test runs see the "dev" fallback because no bundler step ran.
1312
*/

‎src/status.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ function statusKey(input: ReportStatusInput): string {
6363
input.detail,
6464
input.progress?.current,
6565
input.progress?.total,
66-
input.version,
6766
]);
6867
}
6968

70-
function defaultSummary(state: StatusState): string {
69+
function defaultSummary(state: StatusState, version: string): string {
70+
const ready = version ? `v${version} ready` : "ready";
7171
switch (state) {
7272
case "busy":
7373
return "working…";
7474
case "success":
75-
return "ready";
75+
return ready;
7676
case "warning":
7777
return "warning";
7878
case "error":
7979
return "error occurred";
8080
default:
81-
return "ready";
81+
return ready;
8282
}
8383
}
8484

@@ -101,13 +101,12 @@ export function toReportStatus(
101101
): ReportStatusInput {
102102
const mapped: PluginStatusState =
103103
state === "success" || state === "ready" ? "ok" : state === "warning" ? "warn" : state;
104-
const summary = opts?.text?.trim() || defaultSummary(state);
104+
const summary = opts?.text?.trim() || defaultSummary(state, version);
105105
const input: ReportStatusInput = { plugin: PLUGIN_ID, state: mapped, summary };
106106
if (state === "busy") {
107107
const progress = normalizeProgress(opts);
108108
if (progress) input.progress = progress;
109109
}
110-
if (version) input.version = version;
111110
return input;
112111
}
113112

@@ -134,7 +133,7 @@ function publishStatus(input: ReportStatusInput): void {
134133
/** Initialize the reported version and publish an immediate, non-transient state. */
135134
export function initVersion(v: string): void {
136135
_version = v;
137-
publishStatus(toReportStatus("ready"));
136+
publishStatus(toReportStatus("ready", { text: `v${v} ready` }));
138137
}
139138

140139
export function setSessionId(id: string): void {

‎src/tui.tsx‎

Lines changed: 150 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,169 @@
11
/** @jsxImportSource @opentui/solid */
22

3+
import { createSignal, Show } from "solid-js";
34
import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui";
4-
import { useSlotStatusBridge } from "@four-bytes/opencode-plugin-lib/tui";
5-
import { StatusLine, StatusPanel } from "@four-bytes/opencode-plugin-lib/tui-components";
6-
7-
// Slot-safe status surface (#260, plugin-lib v0.12.2).
8-
// useSlotStatusBridge must run inside a component the slot renderer mounts —
9-
// never in the slot renderer function itself and never in a detached createRoot.
10-
// It keeps the retained status signal in the renderer-owned root and asks the
11-
// host for the next frame after every update.
12-
13-
function HomeStatus(props: { api: TuiPluginApi }) {
14-
const bridge = useSlotStatusBridge(props.api.renderer);
15-
return <StatusPanel statuses={bridge.statuses} />;
5+
import type { RGBA } from "@opentui/core";
6+
import { useServiceBus } from "@four-bytes/opencode-plugin-lib/tui";
7+
import { ProgressBar, Spinner } from "@four-bytes/opencode-plugin-lib/tui-components";
8+
import type { PluginStatus } from "@four-bytes/opencode-plugin-lib/tui";
9+
import { VERSION } from "./shared";
10+
11+
/** Pure mapping from the shared plugin status payload to the row's view state. */
12+
export interface StatusView {
13+
statusText: string;
14+
current: number;
15+
total: number;
16+
tone: "success" | "warning" | "error";
17+
busy: boolean;
18+
hasError: boolean;
19+
}
20+
21+
/** True for the plugin-lib clear payload (`{ plugin, cleared: true, ts }`). */
22+
export function isStatusCleared(raw: unknown): boolean {
23+
return !!raw && typeof raw === "object" && (raw as { cleared?: unknown }).cleared === true;
1624
}
1725

18-
function SidebarStatus(props: { api: TuiPluginApi }) {
19-
const bridge = useSlotStatusBridge(props.api.renderer);
20-
return <StatusLine statuses={bridge.statuses} />;
26+
export function statusView(data: PluginStatus): StatusView {
27+
const progress = data.progress;
28+
const current =
29+
typeof progress?.current === "number" && Number.isFinite(progress.current) ? progress.current : 0;
30+
const total =
31+
typeof progress?.total === "number" && Number.isFinite(progress.total) && progress.total > 0
32+
? progress.total
33+
: 0;
34+
if (data.state === "error") {
35+
return { statusText: data.summary || "error occurred", current: 0, total: 0, tone: "error", busy: false, hasError: true };
36+
}
37+
if (data.state === "busy") {
38+
return { statusText: data.summary || "working…", current, total, tone: "warning", busy: true, hasError: false };
39+
}
40+
if (data.state === "warn") {
41+
return { statusText: data.summary || "warning", current: 0, total: 0, tone: "warning", busy: false, hasError: false };
42+
}
43+
return { statusText: data.summary || "ready", current: 0, total: 0, tone: "success", busy: false, hasError: false };
2144
}
2245

46+
function BrainStatusBar(props: { variant: "sidebar" | "home"; api: TuiPluginApi }) {
47+
const [statusText, setStatusText] = createSignal("connecting…");
48+
const [current, setCurrent] = createSignal(0);
49+
const [total, setTotal] = createSignal(0);
50+
const [fg, setFg] = createSignal<string | RGBA>("");
51+
const [busy, setBusy] = createSignal(false);
52+
const [hasError, setHasError] = createSignal(false);
53+
const [hasStatus, setHasStatus] = createSignal(false);
54+
55+
const theme = () => props.api.theme.current;
56+
// Push-only bus: "connecting" means no status has arrived yet. The old HTTP
57+
// poll fallback is gone, so wall-clock staleness would wrongly mask a final
58+
// ok/warn/error summary. The version is a build-time constant, so the row
59+
// shows it before the first publish and when no publish ever arrives.
60+
const connecting = () => !hasStatus();
61+
const showProgress = () => busy() && current() > 0 && total() > 0;
62+
63+
const handleStatus = (data: unknown) => {
64+
if (isStatusCleared(data)) {
65+
setHasStatus(false);
66+
setStatusText("connecting…");
67+
setCurrent(0);
68+
setTotal(0);
69+
setBusy(false);
70+
setHasError(false);
71+
setFg("");
72+
return;
73+
}
74+
try {
75+
const view = statusView(data as PluginStatus);
76+
setHasStatus(true);
77+
setHasError(view.hasError);
78+
setBusy(view.busy);
79+
setStatusText(view.statusText);
80+
setCurrent(view.current);
81+
setTotal(view.total);
82+
setFg(view.tone === "error" ? theme().error : view.tone === "warning" ? theme().warning : theme().success);
83+
} catch {
84+
setBusy(false);
85+
setStatusText("error occurred");
86+
setFg(theme().error);
87+
setHasError(true);
88+
}
89+
};
90+
91+
// Brain publishes on the shared plugin-lib status channel `status/plugin/brain`.
92+
// The callback writes Solid signals owned by this mounted component, so the host
93+
// renderer repaints the row on every update — the pre-PR behaviour.
94+
useServiceBus("status", () => "plugin", "brain", (payload) => {
95+
handleStatus(payload);
96+
});
97+
98+
const indicatorColor = () => (connecting() ? theme().error : hasError() ? theme().error : fg());
99+
const textColor = () => (connecting() ? theme().error : theme().textMuted);
100+
101+
// Single ProgressBar render site shared by both variants. Keeping the bar in
102+
// one declaration makes a second (orphan) mount in either variant impossible.
103+
const StatusProgress = (p: { barWidth: number }) => (
104+
<ProgressBar
105+
current={current()}
106+
total={total()}
107+
showLabel={false}
108+
width="auto"
109+
barWidth={p.barWidth}
110+
fillBg="#aaa"
111+
fillFg="#000"
112+
/>
113+
);
114+
115+
return (
116+
<box width="100%">
117+
<Show when={props.variant === "sidebar"}>
118+
<box width="100%" flexDirection="column">
119+
<box flexDirection="row">
120+
<text fg={theme().text}><b>Brain</b></text>
121+
<text fg={theme().textMuted}> 🧠 {VERSION}</text>
122+
</box>
123+
<box width="100%" flexDirection="row" justifyContent="space-between">
124+
<box flexDirection="row" flexShrink={1}>
125+
{busy() ? <Spinner fg={fg()} /> : <text fg={indicatorColor()}>•</text>}
126+
<text fg={textColor()}> {connecting() ? "connecting…" : statusText()}</text>
127+
<Show when={showProgress()}>
128+
<text fg={theme().textMuted}> {current()}/{total()}</text>
129+
</Show>
130+
</box>
131+
<Show when={showProgress()}>
132+
<box flexShrink={0}>
133+
<StatusProgress barWidth={12} />
134+
</box>
135+
</Show>
136+
</box>
137+
</box>
138+
</Show>
139+
<Show when={props.variant === "home"}>
140+
<box width="100%" flexDirection="row" justifyContent="center">
141+
<text fg={theme().textMuted}>🧠 {VERSION} </text>
142+
{busy() ? <Spinner fg={fg()} /> : <text fg={indicatorColor()}>•</text>}
143+
<text fg={textColor()}> {connecting() ? "connecting…" : statusText()}</text>
144+
<Show when={showProgress()}>
145+
<text fg={theme().textMuted}> </text>
146+
<StatusProgress barWidth={10} />
147+
</Show>
148+
</box>
149+
</Show>
150+
</box>
151+
);
152+
}
153+
154+
export { BrainStatusBar };
155+
23156
const tui: TuiPlugin = (api) => {
24157
api.slots.register({
25158
order: 60,
26159
slots: {
27-
sidebar_content: () => <SidebarStatus api={api} />,
28-
home_bottom: () => <HomeStatus api={api} />,
160+
sidebar_content: () => <BrainStatusBar api={api} variant="sidebar" />,
161+
home_bottom: () => <BrainStatusBar api={api} variant="home" />,
29162
},
30163
});
31164
return Promise.resolve();
32165
};
33166

34-
export { HomeStatus, SidebarStatus };
35167
export default {
36168
id: "four-opencode-brain",
37169
tui,

0 commit comments

Comments
 (0)