Skip to content

Commit f5eb281

Browse files
fix(status): make StatusPanel/StatusLine slot-safe (#76) (#77)
Drop the onMount render-guard claim that re-triggered the opencode 1.19.6 slot render and looped. Components now take a status accessor and repaint in place; useSlotStatusBridge(api.renderer) keeps the signal renderer-owned and calls requestRender(). reportStatus gains an optional version, retained per plugin and shown by StatusPanel. Docs add a slot mounting example; tests cover mount-once, repaint, no-loop and version. Regenerated dist/.
1 parent 2b50b0f commit f5eb281

25 files changed

Lines changed: 710 additions & 441 deletions

‎HISTORY.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
Entries from 0.12.0 onwards. Earlier releases are documented in the git history.
44

5+
## [0.12.2] - 2026-11-29
6+
7+
### Fixed
8+
- `StatusPanel` / `StatusLine` are slot-safe for the opencode 1.19.6+ TUI slot
9+
renderer: the `onMount` render-guard claim (which invalidated the slot and
10+
caused a mount loop — 10,850 mounts in 713 ms in brain) is gone. The
11+
components have no mount side effects and accept a status accessor, so a
12+
status change reconciles the rows in place instead of remounting.
13+
- Slot repaint path: `useSlotStatusBridge(api.renderer)` keeps the status signal
14+
in a renderer-owned component, applies retained bus payloads and calls
15+
`api.renderer.requestRender()` after each update. `createSlotStatusBridge()`
16+
is the bus-free core. Hooks in a detached `createRoot` never subscribe, so the
17+
README now documents mounting via a component and gives a slot example.
18+
19+
### Added
20+
- `reportStatus({ ..., version })`: the plugin version is set once per plugin,
21+
retained with every later status, and shown by `StatusPanel`
22+
(`<symbol> <plugin> <version>: <summary>`). `StatusLine` omits it.
23+
- Tests: slot-hosted panel mounts exactly once and repaints on status change,
24+
several mounting plugins cause no loop, and the version is shown.
25+
526
## [0.12.1] - 2026-11-28
627

728
### Fixed

‎README.md‎

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ await status.reportStatus({
9999
plugin: "mail",
100100
state: "busy", // "ok" | "warn" | "error" | "busy"
101101
summary: "Syncing inbox",
102+
version: "1.8.23", // shown by StatusPanel, retained on later statuses
102103
detail: "UIDVALIDITY changed", // JSONL log only
103104
progress: { current: 3, total: 10 },
104105
});
@@ -116,31 +117,66 @@ await status.clearStatus("mail");
116117
`publish(channel, payload)`) and `logger`; the module-level `reportStatus` /
117118
`clearStatus` exports use a lazily created default reporter.
118119

119-
### TUI: `usePluginStatuses` + `StatusPanel` / `StatusLine`
120+
`version` is set once per plugin (pass your package version, a build-time
121+
constant). The reporter remembers it and attaches it to every later status, so
122+
`StatusPanel` can always show `plugin version` information. It is optional and
123+
`StatusLine` omits it.
124+
125+
### TUI: `StatusPanel` / `StatusLine` in slots
126+
127+
`StatusPanel` and `StatusLine` are slot-safe for the opencode 1.19.6+ TUI slot
128+
renderer: they have no `onMount` side effects and never write a signal during
129+
mount, so mounting them cannot re-trigger the slot. Pass a **status accessor**
130+
(not a snapshot array) and they repaint in place when it changes.
131+
132+
Reactive state must live in a component mounted by the slot renderer. Hooks
133+
called in the slot renderer function itself or in a detached `createRoot` never
134+
subscribe in opencode 1.19.6, and a plugin-owned signal there behaves like a
135+
snapshot.
120136

121137
```tsx
122-
import { usePluginStatuses } from "@four-bytes/opencode-plugin-lib/tui";
123-
import { StatusPanel, StatusLine } from "@four-bytes/opencode-plugin-lib/tui-components";
138+
import { useSlotStatusBridge } from "@four-bytes/opencode-plugin-lib/tui";
139+
import {
140+
StatusPanel,
141+
StatusLine,
142+
} from "@four-bytes/opencode-plugin-lib/tui-components";
124143
import { createToast } from "@four-bytes/opencode-plugin-lib";
125144

145+
// A component, not the slot renderer, owns the status signal and the bus
146+
// subscription. `api.renderer` is the host re-render handle.
147+
const HomeStatus = (props: { api: any }) => {
148+
const bridge = useSlotStatusBridge(props.api.renderer);
149+
return <StatusPanel statuses={bridge.statuses} title="Plugins" />;
150+
};
151+
152+
const SidebarStatus = (props: { api: any }) => {
153+
const bridge = useSlotStatusBridge(props.api.renderer);
154+
return <StatusLine statuses={bridge.statuses} />;
155+
};
156+
126157
const tui = (api) => {
158+
// warn/error toasts are separate from the panel components.
127159
const toast = createToast(api, "Status");
128-
const statuses = usePluginStatuses({ toast }); // warn/error toast once
129160
api.slots.register({
130161
slots: {
131-
home_bottom: () => <StatusPanel statuses={statuses()} />,
132-
sidebar_content: () => <StatusLine statuses={statuses()} />,
162+
home_bottom: () => <HomeStatus api={api} />,
163+
sidebar_content: () => <SidebarStatus api={api} />,
133164
},
134165
});
135166
};
136167
```
137168

138-
- `StatusPanel`: one line per plugin — `<symbol> <plugin>: <summary>` with `✓` ok,
139-
`⚠` warn, `✗` error, `⟳` busy, plus an optional progress label and bar.
140-
- `StatusLine`: sidebar variant, same format (including the progress label) but only
141-
`warn` / `error` / `busy`.
142-
- Only one mounted `StatusPanel` and one mounted `StatusLine` render — each has its own
143-
global render guard (a denied instance re-claims when the owner unmounts).
169+
- `useSlotStatusBridge(api.renderer)` returns a renderer-owned status signal
170+
(`bridge.statuses`), applies retained status payloads and calls
171+
`api.renderer.requestRender()` after every update. `createSlotStatusBridge()`
172+
is the bus-free core for custom wiring and tests.
173+
- `StatusPanel`: one line per plugin — `<symbol> <plugin> [<version>]: <summary>`
174+
with `✓` ok, `⚠` warn, `✗` error, `⟳` busy, plus an optional progress label
175+
and bar.
176+
- `StatusLine`: sidebar variant, same format (including the progress label) but
177+
only `warn` / `error` / `busy`; it omits the version.
178+
- A plain array still works for static/test rendering, but it is a one-shot
179+
snapshot — it will not repaint.
144180
- `warn` / `error` statuses toast once per distinct `plugin + state + summary`. An `ok`
145181
status (or `clearStatus`) forgets them, so a later failure with the same summary
146182
toasts again; `ok` / `busy` never toast.

‎dist/index.js‎

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

‎dist/status-hook.d.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,34 @@ export declare function createStatusController(toast?: StatusToast): StatusContr
2222
export declare function usePluginStatuses(opts?: {
2323
toast?: StatusToast;
2424
}): () => PluginStatus[];
25+
/** Minimal structural shape of `api.renderer` (avoids an @opentui/core dep). */
26+
export interface SlotRendererLike {
27+
requestRender?: () => void;
28+
}
29+
export interface SlotStatusBridge {
30+
/** Reactive, retained, severity-sorted statuses. Pass it to a component. */
31+
statuses: () => PluginStatus[];
32+
/** Apply one bus payload (status or cleared). */
33+
apply: (payload: unknown) => void;
34+
/** Drop all retained state (used when the transport is replaced). */
35+
reset: () => void;
36+
}
37+
/**
38+
* The reactive core of the slot bridge, split out so it is testable without a
39+
* bus. Create it inside a renderer-owned component, not in a detached root.
40+
*/
41+
export declare function createSlotStatusBridge(renderer?: SlotRendererLike): SlotStatusBridge;
42+
/**
43+
* Slot-safe status bridge. Call ONCE inside a component mounted by the slot
44+
* renderer:
45+
*
46+
* const Home = () => {
47+
* const bridge = useSlotStatusBridge(api.renderer);
48+
* return <StatusPanel statuses={bridge.statuses} />;
49+
* };
50+
* api.slots.register({ slots: { home_bottom: () => <Home /> } });
51+
*
52+
* Never call it in the slot renderer function itself or in a detached
53+
* `createRoot` — its effects would not be owned by the host renderer.
54+
*/
55+
export declare function useSlotStatusBridge(renderer?: SlotRendererLike): SlotStatusBridge;

‎dist/status-view.d.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import type { PluginStatus, PluginStatusState, StatusProgress } from "./status.js";
2+
/**
3+
* A plain array is a one-shot snapshot. An accessor (a signal, or the `statuses`
4+
* accessor returned by `useSlotStatusBridge`) is read inside the component's
5+
* memo, so updates reconcile in place and repaint a TUI slot.
6+
*/
7+
export type StatusSource = readonly PluginStatus[] | (() => readonly PluginStatus[]);
8+
export declare function readStatuses(source: StatusSource): readonly PluginStatus[];
29
export declare const STATUS_SYMBOLS: Record<PluginStatusState, string>;
310
export declare function statusSymbol(state: PluginStatusState): string;
411
export interface StatusTheme {
@@ -15,7 +22,7 @@ export declare function hasProgress(progress?: StatusProgress): progress is Stat
1522
export declare function formatProgress(progress: StatusProgress): string;
1623
export declare function isStatusLineVisible(state: PluginStatusState): boolean;
1724
export declare function compareStatuses(a: PluginStatus, b: PluginStatus): number;
18-
export declare function sortStatuses(statuses: PluginStatus[]): PluginStatus[];
25+
export declare function sortStatuses(statuses: readonly PluginStatus[]): PluginStatus[];
1926
export interface StatusRowProgress {
2027
current: number;
2128
total: number;
@@ -26,10 +33,11 @@ export interface StatusRow {
2633
state: PluginStatusState;
2734
symbol: string;
2835
summary: string;
36+
version?: string;
2937
progress?: StatusRowProgress;
3038
}
3139
export declare function buildStatusRow(status: PluginStatus): StatusRow;
32-
export declare function buildStatusRows(statuses: PluginStatus[], opts?: {
40+
export declare function buildStatusRows(statuses: readonly PluginStatus[], opts?: {
3341
lineOnly?: boolean;
3442
}): StatusRow[];
3543
export declare function renderStatusRowText(row: StatusRow): string;

‎dist/status.d.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export interface ReportStatusInput {
88
plugin: string;
99
state: PluginStatusState;
1010
summary: string;
11+
/**
12+
* Plugin package version (build-time constant, e.g. "1.8.23"). Set once per
13+
* plugin: the reporter remembers it and attaches it to every later status.
14+
*/
15+
version?: string;
1116
detail?: string;
1217
progress?: StatusProgress;
1318
}
@@ -16,6 +21,7 @@ export interface PluginStatus {
1621
plugin: string;
1722
state: PluginStatusState;
1823
summary: string;
24+
version?: string;
1925
progress?: StatusProgress;
2026
ts: number;
2127
}

‎dist/tui-components/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export { StatusPanel } from "./status-panel.js";
88
export type { StatusPanelProps } from "./status-panel.js";
99
export { StatusLine } from "./status-line.js";
1010
export type { StatusLineProps } from "./status-line.js";
11+
export type { StatusSource } from "../status-view.js";

0 commit comments

Comments
 (0)