rtk-ai/rtk

feat(hook): add OpenCode TUI stats panel with rtk init installation

Open

#1 925 ouverte le 16 mai 2026

Voir sur GitHub
 (1 commentaire) (4 réactions) (0 assignés)Rust (2 914 forks)batch import
area:cliarea:uienhancementhelp wantedpriority:low

Métriques du dépôt

Stars
 (48 085 stars)
Métriques de merge PR
 (Merge moyen 11j 1h) (45 PRs mergées en 30 j)

Description

Description

RTK already has an OpenCode core plugin (rtk init -g --opencode) that hooks into tool execution to rewrite commands. What's missing is visibility into the token savings — users currently have to run rtk gain manually to see how much they're saving. This feature adds a TUI stats panel for OpenCode that shows real-time token savings in the IDE sidebar, installed automatically alongside the core plugin.

Proposed behavior

TUI plugin (rtk-stats.tsx)

A sidebar widget (sidebar_content slot, order: 40) showing:

  • Header: RTK version with GitHub release check (✓/⚠)
  • Stats (expandable): total commands, input/output tokens, tokens saved (green), average savings rate
  • Efficiency meter: visual progress bar (████████░░░░ 96.4%)
  • Refresh: every 30 minutes (background info, not real-time monitor)
  • Per-project badge: shows project name when project-scoped stats exist
  • Graceful degradation: if RTK is not installed, shows "RTK not present" — never crashes the UI

Installation (rtk init -g --opencode)

The existing rtk init -g --opencode command should install both:

  1. ~/.config/opencode/plugins/rtk.ts (core plugin — auto-rewrite) — already exists
  2. ~/.config/opencode/tui-plugins/rtk-stats.tsx (TUI stats panel) — new
  3. Auto-patch ~/.config/opencode/tui.json to register the TUI plugin — new Properties:
  • Idempotent: re-running the command is a no-op if content is unchanged
  • Graceful: if tui.json is missing → creates it; if malformed → rebuilds it
  • Atomic writes via NamedTempFile + .persist()

Data sources

  • rtk gain -f json — overall stats
  • rtk gain --project -f json — project-scoped stats (when applicable)
  • rtk gain --quota — quota information (text parsed)
  • GitHub releases API — version check

Files changed

File Change
hooks/opencode/rtk-stats.tsx New — TUI stats panel (SolidJS + OpenTUI)
src/hooks/init.rs Add TUI plugin installation + tui.json patching
src/hooks/constants.rs Add TUI_PLUGIN_SUBDIR, OPENCODE_TUI_PLUGIN_FILE, TUI_JSON
src/main.rs No changes needed (reuses --opencode flag)

Estimated token savings

The panel itself doesn't save tokens (it's visual), but it surfaces the savings data that RTK already collects, making users more aware of the value. Reduces friction by removing the need to run rtk gain manually.

Implementation status

Already implemented and tested on a fork. Ready for review.

Environment

  • RTK version: 0.28.x+
  • OpenCode: any version with TUI plugin support

Guide contributeur