Skip to content

Commit 919168d

Browse files
feat: reportStatus API + StatusPanel/StatusLine (#71) (#72)
* feat(status): add retained reportStatus API and TUI status components (#71) * chore: rebuild dist for #71 * fix(status): address review findings (#71) - statusChannel: percent-encode plugin ids so a/b and a_b cannot collide - publisher: do not pin the process-local fallback; retry after a delay - serialize publishes per reporter so concurrent calls keep order - clamp progress and collapse summary whitespace in StatusStore - toast key: JSON tuple, bounded registry, re-arm on ok, remember on success - render guard: notify on release so denied instances re-claim - memoryBus: per-subscription wrapper, snapshot iteration, isolate throws - StatusPanel/StatusLine: re-claim on release, panel row-only rerender, progress label in StatusLine, bar fill matches the row colour - tui-components barrel: stop exporting internal status-view helpers - README: fallback caveat, TUI createToast form, accurate guard/toast docs - tests: components, hook controller, memory bus, concurrency, rejections
1 parent b7c1281 commit 919168d

45 files changed

Lines changed: 3061 additions & 81 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎HISTORY.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change History
2+
3+
Entries from 0.12.0 onwards. Earlier releases are documented in the git history.
4+
5+
## [0.12.0] - 2026-11-28
6+
7+
### Added
8+
- `reportStatus({ plugin, state, summary, detail?, progress? })` and `clearStatus(plugin)`
9+
(`createStatusReporter` for injected bus/logger). States: `ok`, `warn`, `error`, `busy`.
10+
- Retained publishing on `status/plugin/<plugin>` over the plugin bus; in-memory fallback
11+
with wildcard + retained replay. `detail` goes to the JSONL logger only.
12+
- `StatusPanel` (home: one line per plugin, symbol, summary, optional progress bar) and
13+
`StatusLine` (sidebar: only warn/error/busy) TUI components.
14+
- `usePluginStatuses` TUI hook; single-render guard for both components; warn/error toast
15+
once after the TUI attaches.
16+
- `createToast` now also accepts a TUI plugin api (`api.ui.toast`).

‎README.md‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@ const _serverPlugin = async (input: PluginInput) => {
2626

2727
## API
2828

29-
### `createToast(client, defaultTitle)`
29+
### `createToast(clientOrApi, defaultTitle)`
3030

31-
Creates a toast function bound to a plugin client. Silently swallows all errors — never breaks plugin operation on UI failure.
31+
Creates a toast function bound to a plugin. Accepts either a server plugin client
32+
(`client.tui.showToast`) or a TUI plugin api (`api.ui.toast`). Silently swallows all
33+
errors — never breaks plugin operation on UI failure. An empty title falls back to
34+
`defaultTitle`.
35+
36+
```ts
37+
// server plugin
38+
const toast = createToast(input.client, "My Plugin 🚀");
39+
40+
// TUI plugin
41+
const toast = createToast(api, "My Plugin 🚀");
42+
```
3243

3344
Returns: `(message: string, variant?: "info" | "success" | "warning" | "error", title?: string) => void`
3445

@@ -66,6 +77,74 @@ Interval mode is just `{ intervalMs }` (limit 1) — at most one call per key pe
6677
`count(key, windowMs)` prunes stale entries as a side effect, so call it with the same
6778
window as the governing `allow` rule (or a larger one).
6879

80+
### `reportStatus(input)` / `clearStatus(plugin)`
81+
82+
Publishes a **retained** plugin status over the plugin bus (`status/plugin/<plugin>`),
83+
so a TUI that attaches later still sees the current state. Falls back to the in-memory
84+
bus when the Go bus is unavailable — that fallback is **process-local**, so a TUI in a
85+
different process only sees statuses once the real bus is reachable. `detail` is written
86+
to the JSONL logger only — the API never writes to stdout/stderr. Publishing never throws.
87+
88+
```ts
89+
import {
90+
createStatusReporter,
91+
createJsonlLogger,
92+
} from "@four-bytes/opencode-plugin-lib";
93+
94+
const status = createStatusReporter({
95+
logger: createJsonlLogger("my-plugin"),
96+
});
97+
98+
await status.reportStatus({
99+
plugin: "mail",
100+
state: "busy", // "ok" | "warn" | "error" | "busy"
101+
summary: "Syncing inbox",
102+
detail: "UIDVALIDITY changed", // JSONL log only
103+
progress: { current: 3, total: 10 },
104+
});
105+
106+
await status.reportStatus({
107+
plugin: "mail",
108+
state: "ok",
109+
summary: "Inbox synced",
110+
});
111+
112+
await status.clearStatus("mail");
113+
```
114+
115+
`createStatusReporter` accepts an optional `publisher` (anything with
116+
`publish(channel, payload)`) and `logger`; the module-level `reportStatus` /
117+
`clearStatus` exports use a lazily created default reporter.
118+
119+
### TUI: `usePluginStatuses` + `StatusPanel` / `StatusLine`
120+
121+
```tsx
122+
import { usePluginStatuses } from "@four-bytes/opencode-plugin-lib/tui";
123+
import { StatusPanel, StatusLine } from "@four-bytes/opencode-plugin-lib/tui-components";
124+
import { createToast } from "@four-bytes/opencode-plugin-lib";
125+
126+
const tui = (api) => {
127+
const toast = createToast(api, "Status");
128+
const statuses = usePluginStatuses({ toast }); // warn/error toast once
129+
api.slots.register({
130+
slots: {
131+
home_bottom: () => <StatusPanel statuses={statuses()} />,
132+
sidebar_content: () => <StatusLine statuses={statuses()} />,
133+
},
134+
});
135+
};
136+
```
137+
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).
144+
- `warn` / `error` statuses toast once per distinct `plugin + state + summary`. An `ok`
145+
status (or `clearStatus`) forgets them, so a later failure with the same summary
146+
toasts again; `ok` / `busy` never toast.
147+
69148
## License
70149

71150
Apache-2.0

‎dist/bus-tui.d.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export declare class BusTui {
5959
* no longer falls back to this class automatically.
6060
*
6161
* No WebSocket connection needed — messages flow through the shared
62-
* in-process EventBus. Wildcard patterns are NOT supported; use the
63-
* real Go bus for cross-process IPC and wildcard matching.
62+
* in-process MemoryBus, which supports `+` wildcards and retained replay.
63+
* Cross-process IPC still requires the real Go bus.
6464
*/
6565
export declare class MemoryBusTui extends BusTui {
6666
private memorySubs;

‎dist/index.d.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { createToast } from "./toast";
2-
export type { ToastVariant } from "./toast";
2+
export type { ToastVariant, ToastTarget } from "./toast";
33
export { createJsonlLogger } from "./logger";
44
export type { DebugEvent, JsonlLogger } from "./logger";
55
export { createThrottle } from "./throttle";
@@ -10,3 +10,7 @@ export type { BusEnvelope, BusHealth, PortInfo, BusCallback, Unsubscribe } from
1010
export { BusClient } from "./bus-client.js";
1111
export { memoryBus } from "./memory-bus.js";
1212
export { deriveProjectId } from "./derive-project-id.js";
13+
export { createStatusReporter, reportStatus, clearStatus, statusChannel, STATUS_CHANNEL_PREFIX, } from "./status.js";
14+
export type { PluginStatus, PluginStatusState, StatusProgress, ReportStatusInput, StatusCleared, StatusPayload, StatusPublisher, StatusReporter, StatusReporterOptions, } from "./status.js";
15+
export { StatusStore } from "./status-store.js";
16+
export type { StatusUpdate } from "./status-store.js";

0 commit comments

Comments
 (0)