跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    qiming-zhao

    Tps

    opencode-tps-plugin·v0.1.1·界面与主题

    Real-time AI generation speed and token throughput monitor for OpenCode

    GitHub 星标

    0

    月装机量

    349

    近 7 天 11

    综合评分

    34.8

    生态多维模型

    最近提交

    21 天前

    2026-09-14

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-tps-plugin@0.1.1"]
    }

    OpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    中文文档

    Real-time AI generation speed and token throughput monitor for OpenCode. Displays live tokens-per-second (TPS) metrics directly in the OpenCode TUI status bar while the model generates output.

    Screenshot

    OpenCode TUI showing the TPS monitor

    Illustrative output from an OpenCode session; values vary by model and session.

    Features

    • Real-time TPS display — instant speed, rolling average, token count, and elapsed time in the prompt status bar
    • Color-coded speed indicators — green (fast), yellow (medium), red (slow) based on configurable thresholds
    • Tool execution awareness — shows "TOOL" indicator during tool calls, automatically deducts tool wait time from generation speed calculation
    • Sub-agent tracking — traces parent-child session relationships and rolls up metrics to root session
    • EMA smoothing — exponential moving average with adaptive half-life to suppress noisy spikes
    • CJK-aware token estimation — treats each CJK character as 1 token for more accurate counting
    • Multiple estimation algorithms — general (chars/4), program (chars/3), prose (words/0.75)
    • Flexible configuration — JSON config files, environment variables, or code overrides

    Installation

    npm install opencode-tps-plugin
    

    Add the plugin to your tui.json:

    {
      "plugin": [
        // ... your existing plugins
        "opencode-tps-plugin"
      ]
    }
    

    How It Works

    The plugin renders a ThroughputGauge component in the session_prompt_right slot using SolidJS. It listens to message.part.delta, message.part.updated, message.updated, and session.idle events to track token generation in real time, showing live TPS, average speed, total tokens, and elapsed time with color theming.

    Configuration

    Configuration is resolved in the following priority order (highest wins):

    1. Code overrides (passed programmatically)
    2. Environment variables (TPS_PLUGIN_*)
    3. User config: ~/.config/opencode/tps-plugin.json
    4. Project config: .opencode/tps-plugin.json
    5. Built-in defaults

    Note: display toggles (showAvg, showRate, showTokens, showTimer) are JSON/defaults only and have no environment variable override.

    Config File Example

    {
      "enabled": true,
      "refreshIntervalMs": 50,
      "samplingWindowMs": 1000,
      "showAvg": true,
      "showRate": true,
      "showTokens": true,
      "showTimer": true,
      "tokenMode": "general",
      "useColors": true,
      "slowRate": 10,
      "fastRate": 50
    }
    

    Environment Variables

    Variable Description Default
    TPS_PLUGIN_ENABLED Enable/disable the plugin true
    TPS_PLUGIN_REFRESH_INTERVAL_MS Minimum ms between UI updates 50
    TPS_PLUGIN_SAMPLING_WINDOW_MS Sliding window for speed calculation 1000
    TPS_PLUGIN_TOKEN_MODE Token estimation mode (general, program, prose) general
    TPS_PLUGIN_USE_COLORS Enable speed-based color coding true
    TPS_PLUGIN_SLOW_RATE TPS below this is red 10
    TPS_PLUGIN_FAST_RATE TPS above this is green 50

    Requirements

    Development

    # Install dependencies
    bun install
    
    # Type check
    bun run typecheck
    
    # Build
    bun run build
    

    License

    MIT

    同类生态推荐