Skip to content

feat: add native OpenCode 2 Loop sidebar - #165

Closed
zhek wants to merge 4 commits into
ByBrawe:mainfrom
zhek:feat/opencode2-native-sidebar
Closed

zhek wants to merge 4 commits into
ByBrawe:mainfrom
zhek:feat/opencode2-native-sidebar

Conversation

@zhek

@zhek zhek commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

What

Adds a native OpenCode 2 sidebar that renders Loop status into sidebar.content, mirroring the dedicated Goal panel. Scheduling stays server-owned; the TUI process only paints the text it is handed.

image

Why a separate ./tui entry

ui.slot exists only in the TUI plugin context, not the server one, so this needs its own entry point. Status reaches the panel through a read-only bybrawe-opencode-loop-status/read RPC rather than shared state.

Design notes

  • Dependency-free contract. The shared contract is a plain frozen object, not Rpc.define, because Loop ships committed single-file bundles and importing @opencode/plugin/rpc would inline @opencode/schema with its effect/zod/ai-sdk graph. The host types registration structurally, so a plain object satisfies it.
  • Honest reporting. "due" and "waiting for idle" are rendered separately, overdue runnable jobs are flagged, and persisted stop reasons are printed so a quiet panel can be correlated with loop.log. No completion percentage, throughput estimate or dispatch promise — Loop has no completion metric of its own.
  • Fail-open. Unlike Goal, which throws when the slot API is missing, a host that cannot serve the panel logs v2-status-rpc-unavailable and keeps scheduling. Losing the scheduler to a missing cosmetic surface is the wrong trade.
  • Location-bound reads. Only sessions whose location and workspace match the serving instance are answered; control characters are stripped and late or mismatched responses are fenced.

Tests

  • scripts/tui-status-test.mjs — formatter semantics, bounded panel size, request coalescing, cross-session and oversized response rejection, RPC input validation, location binding, idempotent disposal.
  • scripts/native-tui-render-smoke.mjs — renders the published ./tui entry through real OpenTUI primitives and asserts visible characters plus reactive session switching. Requires Bun, because OpenTUI's native FFI is unreachable from plain Node. .github/workflows/native-sidebar.yml runs it on Linux and Windows.

npm test, npm run check and npm run test:tui-native pass locally.

Reviewer note

Committed src/server.js and src/native.js were regenerated with npm run build:plugin (Bun 1.4.2). A different bundle diff produced by another Bun version is expected and is not a source change.

ByBrawe commented Oct 8, 2026

Copy link
Copy Markdown
Owner

V2 review against the current main and the OpenCode 2 plugin API:

The server-owned read-only RPC + separate ./tui entry is the right general architecture. Please update this PR before merging:

  1. Rebase onto current main and regenerate all three committed bundles with the repository's pinned Bun toolchain. Since your fork head was created, main gained the corrupt-state fail-closed fix (a6bf64e) and release/test corrections. The PR changes src/native.js and src/server.js, so importing the old bundles must not reintroduce the empty-jobs corruption fallback or override release fixes.
  2. The new TUI imports @opentui/solid and solid-js, but package.json does not declare these as peer dependencies. Please document/declare the runtime peer contract (compare dedicated Goal's @opentui/core, @opentui/solid, solid-js peers) and prove a clean published-package consumer can resolve @bybrawe/opencode-loop/tui, not just the developer checkout.
  3. CI on this external PR currently reports action_required, not successful native render tests. It needs a trusted Windows/Linux test:tui-native run plus the existing native V2 lifecycle/coexistence and bundle gates before merging.
  4. Ensure missing ui.slot/RPC only removes the cosmetic panel, never changes Loop job admission, and verify remote/different-worktree session response rejection.

Leaving the PR open pending those checks; this is not a rejection of the sidebar idea.

@zhek
zhek force-pushed the feat/opencode2-native-sidebar branch 2 times, most recently from a835c6f to 791f08b Compare October 10, 2026 16:37
@zhek

zhek commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (39e91ff) and pushed three follow-up commits.

  1. src/index.js, src/server.js and src/native.js were regenerated with Bun 1.4.2, the version pinned in native-v2-ci.yml. The corrupt-state fail-closed guard from a6bf64e is present in all three, so the old archive does not bring back the empty-jobs fallback.

  2. @opentui/core, @opentui/solid and solid-js are declared as optional peers, matching Goal:

"peerDependencies": {
  "@opencode-ai/plugin": ">=1.4.0 <2",
  "@opentui/core": ">=0.5.14 <0.6",
  "@opentui/solid": ">=0.5.14 <0.6",
  "solid-js": ">=1.9.0 <2"
}

c9e5c30 adds the verification: pack the tarball, install it into a clean consumer, and assert that every export target ships, ./rpc resolves with no imports, the peers stay optional, and the committed bundles do not inline them. It runs under the existing package:smoke step in native-v2-ci.yml, so no new workflow step was needed.

  1. All eight workflows on this PR are at action_required, including the pre-existing CI, Native V2 CI and Bundle Gate. That points at the outside-collaborator approval setting rather than the new native-sidebar.yml. Could you approve the pending runs? Native Loop Sidebar carries test:tui-native on Linux and Windows.

  2. ade9bde adds both checks. A session that resolves but lives in another worktree or workspace is refused instead of served. A throwing ctx.rpc.register still completes setup, keeps /loop registered and persists the job.

791f08b is not part of the review: it drops default exports that nothing imports, leaving them on entry points only.

One change you may want to overrule: I replaced the Unreleased (main only) placeholder with a plain ## Unreleased, because that qualifier stops being true once a contributed change lands there. I will restore it if you would rather keep that section as your staging area.

zhek added 4 commits October 14, 2026 19:41
Add a native OpenCode 2 sidebar that renders Loop status into `sidebar.content` over a read-only `bybrawe-opencode-loop-status/read` RPC, mirroring the dedicated Goal panel.
@zhek
zhek force-pushed the feat/opencode2-native-sidebar branch from 791f08b to aac4a93 Compare October 14, 2026 19:50
@zhek

zhek commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased again: main moved to 0.6.8 with the exFAT lock fallback, which left this PR dirty.

Now rebased onto 50ccb99, with src/index.js, src/server.js and src/native.js regenerated by Bun 1.4.2. The wx lock-claim fallback from 104d96a and the fail-closed invalid_owner guard are both present in all three bundles, so the release work is intact.

The short hashes from my previous comment are stale:

  • da5dcaf — packaging proof
  • 0ef6320 — panel and admission checks
  • aac4a93 — default-export cleanup

The workflows are still at action_required. Could you approve the pending runs when you get a chance?

ByBrawe commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Maintainer triage 2026-10-27: this is a valuable read-only TUI status projection (native ./tui, RPC, ownership scoping). However the PR is currently mergeable_state=dirty against current main and changes 17 files, +5700/-2590, including generated bundles/package lock, so please rebase and regenerate with the pinned Bun/toolchain before merge. New OpenCode 2.1.4 @opencode/plugin uses OpenTUI 0.7.0 while the existing Goal sidebar has old 0.5.x peers: test the real native TUI render and cleanup on 2.1.4, with Windows and macOS, and avoid any Goal lifecycle mutation from a status read. See Loop #185 and Goal #284. GUI Desktop plugin slot is NOT equivalent to the TUI slot.

ByBrawe commented Oct 27, 2026

Copy link
Copy Markdown
Owner

@zhek, thank you for this thoughtful contribution! 🙌 The native OpenCode 2 Loop sidebar is a genuinely useful improvement alongside the dedicated Goal status panel. In particular, the separate ./tui entry, read-only location-scoped RPC, honest due/waiting/stopped reporting and fail-open treatment of an unavailable cosmetic surface are exactly the direction we want for Loop + Goal UX.

We want to include this feature, not leave it indefinitely unreviewed. Main has moved through Loop 0.6.9 release preparations and native OpenCode 2.1.4 canaries since this branch was last rebased. I'm integrating the sidebar against the current code while preserving the critical release, corrupt-state and scheduler ownership safeguards; the generated 2.0-era bundles and peer assumptions cannot simply be merged wholesale. I will keep your authorship and link to this PR in the integration work. We also need real native OpenTUI render/teardown on Windows, Linux and the current 2.1.x API, plus a clean consumer package test. Thank you again for putting the implementation and tests together!

ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…s sidebar (#165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…solation (#165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…cross Win/Linux (#165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…separately testing 0.7 (#165)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
…nd dispose independently (#165 #284)

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>
ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026

ByBrawe commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Progress update — the integration is real now: maintainer integration PR #190 ports your sidebar source, read-only location-scoped RPC, formatter/controller, real OpenTUI render smoke and clean consumer tests onto current Loop main. It preserves your attribution (Co-authored-by: zhek and explicit README/CHANGELOG credit) and regenerates the native bundles using pinned Bun 1.4.2 without taking old generated artifacts over new 0.6.9 fixes. Native Loop status tests pass; Windows/Linux OpenTUI 0.5.14 and 0.7.0 matrix is active. I also added a test rendering both Loop and the independently published Goal 1.3.49 sidebar inside the same renderer, including session switching and independent disposal. Thank you again for pushing the idea and the quality of the initial implementation. Keeping your PR open until the replacement has verified CI; this is integration, not rejection.

ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
Integrate the contributor's read-only server RPC, separate native TUI slot, status formatting, bounded polling, safe disposal and shared Loop+Goal rendering. Preserve the current Loop 0.6.9 runtime, with 9/9 CI workflow suites green including pinned OpenCode 2.1.4 on Linux/macOS and OpenTUI 0.5/0.7 on Windows/Linux.

Fix disk amplification from repeated corrupt-state polling using a read-only peekState, correctly count stopped jobs, sanitize job names/watch paths/pause reasons, and show native pauseReason. Add regressions for every automated review finding.

Credit for original design and implementation: zhek, PR #165.

Co-authored-by: zhek <35113171+zhek@users.noreply.github.com>

ByBrawe commented Oct 27, 2026

Copy link
Copy Markdown
Owner

@zhek — thank you again for the original native Loop sidebar design, implementation and tests! 🎉 The integration is now merged into main as PR #190, squash commit 76ec521. We retained your author credit in the merge commit (Co-authored-by: zhek), source commits, README and CHANGELOG. The resulting feature uses your independent ./tui slot and read-only location-bound RPC, plus expanded Loop+Goal co-render and OpenTUI 0.5.14/0.7.0 Windows/Linux CI. All 9 CI suites passed; we also fixed the four subsequent automated review findings, notably the corruption-backup-on-poll risk.

Closing this original PR as superseded by the merged contribution, not because the idea was rejected. The feature will be published in a future version after 0.6.9 (which has already shipped). Remote/split-cache TUI auto-discovery remains tracked in #191 / upstream #55084. We appreciate the contribution and would welcome follow-up improvements.

@ByBrawe ByBrawe closed this Oct 27, 2026
ByBrawe added a commit that referenced this pull request Oct 27, 2026
All four clean strict npm installs and real Bun OpenTUI co-render lanes passed: Windows/Linux on exact OpenCode 2.0.18+OpenTUI 0.5.14 and 2.1.4+0.7.0, with both independent Loop/Goal candidate tarballs. No --legacy-peer-deps or source node_modules links. Keeps current published versions unchanged; #191 real CLI plugin auto-discovery and Goal npm peer-compatible release remain open before announcing 0.6.10.

Credit original Loop sidebar feature to @zhek (#165 #190).
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.

2 participants