Skip to content

Commit 4d5ea20

Browse files
authored
Merge pull request #14 from d3cker/codex/bot-runtime-sidebar
feat: show live bot runtime status in TUI sidebar
2 parents 53422e1 + 1cec886 commit 4d5ea20

22 files changed

Lines changed: 2191 additions & 25 deletions

‎AGENTS.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ steps, project setup, headless operation, and removal.
2828
| [docs/architecture.md](docs/architecture.md) | Component responsibilities, a short issue-to-PR overview, configuration ownership, scheduler ownership, and shared state. | Start here to understand how the system is divided before locating implementation code. |
2929
| [docs/bot-workflow.md](docs/bot-workflow.md) | Eight Mermaid diagrams and detailed implementation notes: startup and polling; discovery and routing; task phases; sessions and questions; media helpers; verification and publication; feedback, merging, and tab closure; status, retries, and recovery. Includes links to the source for each area. | Use for exact execution order, state transitions, checkpoint behavior, failure paths, and tracing a bot task from issue to merged PR. |
3030
| [docs/configuration.md](docs/configuration.md) | The standard `.opencode/automation.json` format, defaults, setup flags, configuration tracking across Git branches, authors, triggers, checks, base branches, model capabilities, media helpers, custom prompts, signatures, and auto-merge settings. | Use when adding or changing user-facing configuration, defaults, or setup examples. |
31-
| [docs/runtime.md](docs/runtime.md) | User-visible behavior while the bot runs: GitHub questions and permission replies, branch selection, media inputs, prompt loading, follow-up comments, session tabs, and routine management commands. | Use when changing issue conversations, session continuation, runtime tools, or TUI behavior. |
31+
| [docs/runtime.md](docs/runtime.md) | User-visible behavior while the bot runs: GitHub questions and permission replies, branch selection, media inputs, prompt loading, follow-up comments, session tabs, runtime sidebar/status freshness, and routine management commands. | Use when changing issue conversations, session continuation, runtime tools, or TUI behavior. |
3232
| [docs/advanced.md](docs/advanced.md) | Separate scheduler/dispatcher setup, multiple repositories, custom RPC jobs, full options, timeouts, management and retry commands, persistence, reconciliation, locks, and known limits. | Use for low-level configuration, operational troubleshooting, recovery, or ownership/concurrency changes. |
3333
| [docs/installation.md](docs/installation.md) | Loader registration, config-directory precedence, prerequisites, source installation, project-local installation, upgrade conflicts, testing on another machine, and migration limits. | Use when working on packaging, installers, registration, upgrades, or deployment troubleshooting. |
3434
| [docs/releases.md](docs/releases.md) | Feature-to-devel and devel-to-release PR checks, automatic patch versions, manual npm version/tag releases, exact changelog notes, publication recovery, README commits on release, automatic release-to-devel synchronization, and promotion PRs into protected main. | Use for CI triggers, versioning, packaging, GitHub Release publication, branch permissions, or recovery after a failed release. |
@@ -68,7 +68,9 @@ the installation block without making remote writes. Keep its markers intact.
6868
runtime installation, and communication with the owner. `src/prompt.ts` loads
6969
instructions; `prompts/bot.md` contains the bundled bot instructions.
7070
- `src/tui.ts`, `src/ui.ts`, and `src/activity.ts` implement terminal integration
71-
and task activity. `src/rpc.ts` defines RPC contracts; `src/manage.ts` exposes
71+
and task activity. `src/sidebar.ts` renders the runtime panel;
72+
`src/runtime-panel.ts` owns polling, freshness and presentation;
73+
`src/monitor.ts` defines read-only monitoring schemas. `src/rpc.ts` defines RPC contracts; `src/manage.ts` exposes
7274
management operations.
7375
- `src/setup.ts`, `src/wizard.ts`, `src/install.ts`, and `scripts/` cover setup and
7476
installation. `examples/` contains configuration examples; `test/` contains

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ include the full version, for example `## 0.7.0-beta.1`.
2424

2525
### Added
2626

27+
- Add a live BOT RUNTIME sidebar and `/botstatus` report with dispatcher operations,
28+
scheduler scans/retries, queue counts and selected-task details. Keep stale and
29+
unavailable readings explicit; monitor through read-only owner-scoped RPC.
30+
- Validate native sidebar rendering, reactive updates and narrow layouts as part
31+
of the standard check command using pinned TUI/Bun development dependencies.
32+
2733
- `/restartworkflow` and the matching CLI/RPC command resume a stopped task from
2834
its saved stage, preserving worktrees, sessions, PRs, and feedback. Checkpoint
2935
continuation requests across restarts without bypassing checks or permissions.

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ installations are not removed by `npm uninstall --global`.
249249
- **Merging:** approve the bot's PR or post a configured merge phrase. The author
250250
must be allowed and have repository write access. Set `autoMerge.enabled` to
251251
`false` to disable this. `signature` controls the signature on new bot messages.
252+
- **Runtime status:** the right sidebar's **BOT RUNTIME** panel shows dispatcher
253+
work, GitHub discovery, scheduled scans, queue counts and the selected task.
254+
`/botstatus` opens a full text report. Status refreshes every five seconds;
255+
unavailable or stale readings are marked explicitly. See
256+
[runtime panel details](docs/runtime.md#runtime-status-sidebar).
252257
- **Progress:** use `/bot` in the TUI, or the CLI's `status`, `scan`, `pause`, and
253258
`resume` commands from the target repository. Closing a PR closes its bot tabs
254259
while retaining session history. Authorized issue comments can continue work

‎docs/advanced.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ and unrecognized running-session errors produce errors. Recovery does not run a
105105
scan, resume a paused scheduler, or restart the service.
106106
Unlike `retry`, recovery can be queued while a different task is working.
107107

108+
### Read-only runtime monitoring
109+
110+
`automation.github.monitor` accepts `{}` and returns the owner directory,
111+
worker operation, optional active task key, scanning flag, last scan start/finish,
112+
optional redacted scan error, and enriched activity snapshots. It does not trigger
113+
work or write the queue. Worker operations are `idle`, `reconciling`, `executing`,
114+
`merging`, `maintenance`, or `stopped`; these are live diagnostics, not task phases.
115+
Scan finish means an attempt ended, including failed attempts; inspect `scanError`.
116+
Timing resets when the dispatcher is recreated.
117+
118+
`automation.scheduler.status` supplies job `running`, `paused`, `nextAt`, failure
119+
count, error and last start/finish. The sidebar and `/botstatus` combine these APIs.
120+
Each poll has a four-second bound; failures retain marked stale data. The existing
121+
`activity` RPC/events still drive tab notifications and their ten-second fallback.
122+
Full task history remains available through `status`; see the
123+
[runtime sidebar](runtime.md#runtime-status-sidebar) for display and selection rules.
124+
108125
## Persistence and reconciliation
109126

110127
The queue stores analysis decisions and clarification dialogue, comment ID, session ID, phase, pinned base branch,

‎docs/architecture.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ loads a generic scheduler, a GitHub dispatcher, and a terminal UI component.
1414
- **Terminal UI:** subscribes to activity events and polls for missed updates.
1515
Opens background tabs, closes task tabs after PR closure while retaining
1616
session history, and exposes `/bot` and `/restartworkflow` task selectors.
17+
A read-only runtime sidebar and `/botstatus` combine live dispatcher diagnostics,
18+
scheduler state and task snapshots, marking stale or unavailable data.
1719

1820
## Workflow
1921

@@ -61,3 +63,10 @@ session continues and the replacement owner reconciles its saved identity.
6163

6264
See [advanced configuration](advanced.md) for retry commands, limits, and RPC
6365
settings, and the [README](../README.md) for installation and user-facing behavior.
66+
67+
Runtime monitoring is observational: `automation.github.monitor` exposes the
68+
owner's current worker operation, active task, scan timing/error, and enriched
69+
activity snapshots. Scheduler status retains its existing RPC. The TUI polls both
70+
independently every five seconds through the connected client; it does not infer
71+
worker activity from queue status alone. These live diagnostics do not add durable
72+
workflow phases or replace the existing ownership keepalive.

‎docs/bot-workflow.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ flowchart TD
5050
Stop[Owner reload or shutdown] --> Cleanup[Stop timers and local waits, settle writes, dispose RPC, release locks]
5151
Cleanup --> Preserve[Preserve durable queue and healthy worktree execution]
5252
Preserve --> Load
53+
View[Runtime sidebar or botstatus] -.-> Monitor[Read dispatcher monitor and scheduler status every five seconds]
54+
Monitor -.-> RPC
55+
Monitor -.-> State
56+
Monitor --> Fresh{Both readings available and fresh?}
57+
Fresh -->|Yes| Display[Show live operations, queue and selected task]
58+
Fresh -->|No| Stale[Mark unavailable or retained stale readings]
5359
```
5460

5561
- Easy configuration puts state under the shared Git directory at
@@ -469,6 +475,11 @@ flowchart TD
469475
UI --> Busy{Associated tab busy?}
470476
Busy -->|Yes| Defer[Retry closure on a later snapshot]
471477
Busy -->|No| Tabs[Close known task and helper tabs once, preserve sessions and worktrees]
478+
Status[Independent monitor polling every five seconds] --> Sidebar[Append BOT RUNTIME to existing sidebar]
479+
Selected[Selected session changes] --> Sidebar
480+
Sidebar --> Details[Show owner operations and matching task, or active task fallback]
481+
Status --> Missing[On failure retain last readings and mark stale]
482+
Missing --> Sidebar
472483
```
473484

474485
Merge eligibility requires `done`, a tracked nonclosed PR, a saved commit, no
@@ -519,7 +530,17 @@ worktrees. A manually reopened tab is not repeatedly closed in the same TUI inst
519530

520531
Sources: [dispatcher.ts — workOnce, mergeOnce, scanOnce](../src/dispatcher.ts),
521532
[approval.ts](../src/approval.ts), [github.ts — mergeApproved](../src/github.ts),
522-
[ui.ts](../src/ui.ts), [activity.ts](../src/activity.ts).
533+
[ui.ts](../src/ui.ts), [activity.ts](../src/activity.ts),
534+
[sidebar.ts](../src/sidebar.ts), [runtime-panel.ts](../src/runtime-panel.ts).
535+
536+
The runtime sidebar has an independent five-second observation loop with a
537+
four-second request bound and one-second local countdown updates. It combines
538+
`automation.github.monitor` with scheduler `status`; requests never advance a
539+
phase. It reports actual in-process worker/scan activity rather than deriving it
540+
from `ready`. Last successful readings remain visible with stale warnings after
541+
errors or 15 seconds without fresh data. `/botstatus` exposes a text report even
542+
without a sidebar. See [runtime panel details](runtime.md#runtime-status-sidebar)
543+
for task selection, cache observations and display limits.
523544

524545
## 8. Status, retries, and recovery
525546

‎docs/installation.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ registers the server/UI loaders, and runs the wizard. Existing configuration and
9595
queues are preserved on upgrades. Do not combine global and project-local copies.
9696
No package is published to npm; `private: true` blocks accidental publication.
9797

98+
## TUI rendering and source validation
99+
100+
The runtime sidebar uses the host's OpenTUI/Solid APIs and semantic theme tokens.
101+
The package declares OpenTUI and Solid peer dependencies; server entrypoint imports
102+
stay independent of renderer initialization. A sidebar update requires both the
103+
owner plugin's monitor RPC and an updated/reopened TUI. An older or unavailable
104+
owner is shown as unavailable rather than silently idle. The integration follows
105+
the [OpenCode CLI plugin API](https://opencode.ai/v2/docs/build/plugins/cli/).
106+
107+
For development, `npm ci` installs pinned renderer, theme and Bun test dependencies.
108+
`npm run check` includes `npm run test:tui`, which renders the actual sidebar using
109+
Bun's native OpenTUI support and checks live updates, stale readings, tab selection
110+
and a narrow layout. Bun is needed for this native renderer test, not for the
111+
Node-based management CLI. Package validation still imports the server and TUI
112+
entrypoints in an isolated Node installation without initializing a renderer.
113+
98114
## Testing and migration
99115

100116
Use a separate test repository when testing on another machine. Independent

‎docs/releases.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ modify its files with the Contents API, or bypass its protection rules.
1010
| Event | Result |
1111
| --- | --- |
1212
| Commit/push on a feature branch without an open PR | No CI run and no package build. |
13-
| Open, reopen, or update a PR targeting `devel` or `release` | Full CI on Node 22 and 24, including build and isolated package installation. |
13+
| Open, reopen, or update a PR targeting `devel` or `release` | Full CI on Node 22 and 24, including native TUI rendering with the pinned Bun test dependency, build and isolated package installation. |
1414
| Merge a feature PR into `devel` | Accumulate changes without publication. |
1515
| Merge a same-repository `devel` → `release` PR | Automatic patch version, tag, publication, README commit on `release`, main promotion PR, and automatic merge back into `devel`. |
1616
| Close a PR without merging | No publication. |

‎docs/runtime.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,56 @@ Pausing stops scheduled scans; it does not cancel accepted tasks or active sessi
216216
Do not run independent bots on two machines against the same issues: they do not
217217
share queue ownership across machines.
218218

219+
## Runtime status sidebar
220+
221+
The **BOT RUNTIME** section is appended to the existing right sidebar, preserving
222+
OpenCode's context information. Open the TUI in the configured primary owner
223+
checkout. Switching task tabs changes the task details while the scheduler and
224+
dispatcher rows continue to describe that owner project.
225+
226+
The panel shows:
227+
228+
- Dispatcher activity: idle, reconciling state, executing a task's actual phase,
229+
checking merges, maintenance, or stopped. An active task key is shown separately.
230+
- GitHub discovery: scanning, the time the last scan finished, and any scan error.
231+
- Scheduler jobs: running, paused, next run time or retry delay, and errors.
232+
Pausing polling can coexist with an already-running scan or task.
233+
- Queue counts: ready/retry-wait excluding the active task, waiting for replies, blocked/failed and published
234+
tasks, excluding closed/merged PRs. Scheduled does not mean a model is executing.
235+
- Task details: issue, phase, round, observed main-session status, task/base branches,
236+
model, queued feedback, allocated media helper count for the current session,
237+
failed attempts, recovery request, PR state and any task/merge error.
238+
- Separate freshness information for dispatcher and scheduler readings.
239+
240+
Task selection prefers the displayed session (including saved earlier-round and
241+
helper IDs), then the dispatcher's active task, then an open waiting/blocked task,
242+
then scheduled work, then the last known task. Main-session running/idle comes
243+
from the TUI's session cache when that session is available; otherwise the panel
244+
says `not observed`. Media counts do not claim that those helpers are running and
245+
do not count native implementation subagents.
246+
247+
Read-only snapshots refresh on startup and every five seconds, with a four-second
248+
request deadline and no overlapping refreshes. Countdown labels update locally
249+
every second. No model is prompted and polling does not restart jobs or repair
250+
queue state. A failed request retains the last successful snapshot with a stale
251+
warning; readings older than 15 seconds are also marked stale. Dispatcher and
252+
scheduler failures are independent, so a partial failure keeps the other component
253+
visible. Initial/unavailable data is never presented as a healthy idle service.
254+
255+
Use `/botstatus` for a text report, including every known task and scheduler job,
256+
when the sidebar is hidden or more detail is needed. The sidebar shows up to three
257+
scheduler jobs and truncates long labels/errors. `/bot` opens task sessions;
258+
`/restartworkflow` remains the separate explicit recovery action.
259+
260+
The TUI and owner plugin must both contain the monitor API. With an older server,
261+
an unloaded/unconfigured owner, a direct worktree-only launch, or a failed RPC,
262+
the panel reports unavailable status. Load the configured owner and update both
263+
sides as needed; reopen TUI clients after installation. Monitoring uses the
264+
connected OpenCode client, so it also works with a remote service when the correct
265+
owner location and updated plugin are available there. Live worker/scan diagnostics
266+
reset when the owner is recreated; task checkpoints and scheduler history remain
267+
durable as before.
268+
219269
## Interrupted sessions and workflow recovery
220270

221271
If you manually continue a timed-out or interrupted bot session in the TUI,

0 commit comments

Comments
 (0)