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

    Session Diff

    opencode-session-diff·v0.1.1·Git 与版本控制

    OpenCode sidebar panel listing the current session's file changes (±line counts)

    GitHub 星标

    0

    月装机量

    365

    近 7 天 365

    综合评分

    35.7

    生态多维模型

    最近提交

    4 小时前

    2026-10-21

    快速安装与配置

    opencode.json

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

    opencode.json

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

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

    Not an official OpenCode / SST product. This is a community plugin, not affiliated with or endorsed by OpenCode.

    English | 简体中文

    npm version license

    Changes sidebar panel for OpenCode — see every file the current session touched, at a glance.

    A TUI plugin for OpenCode that adds a Changes section to the session sidebar. It lists every file the current session modified, added, or deleted, with ± line counts, highlights the file being edited right now, and click-through to the built-in diff viewer.

    ▼ Changes (4)                              +154 −18
    • src/agent/loop.ts                        +28 −9
    • src/tools/fs.ts                          +110 −3
    • test/loop.test.ts                        +13
    • src/legacy/runner.ts                     −6
    

    Features

    • Session-scoped: exactly what this conversation changed — powered by the server's session.diff snapshot, not a client-side guess.
    • Added / modified / deleted with per-file +additions −deletions counters, right-aligned.
    • Live-edit highlight: the file being edited turns warning-colored for a few seconds (session.tool.* events; filesystem watcher as fallback).
    • Click to review: opens the official diff viewer, already scoped to this session's changes.
    • Events, not polling: refreshes on round completion and /undo; no timers in the background.
    • Theme-aware: all colors come from the host theme (dark/light/custom).
    • Zero config.

    Install

    opencode plugin add opencode-session-diff@latest
    

    Recommended host setting so the diff viewer opens on the session's own changes rather than the git branch:

    // ~/.config/opencode/cli.json
    {
      "diffs": { "source": "turn" }
    }
    

    The sidebar shows when space allows (session.sidebar: "auto"). Toggle it with Ctrl+X then B.

    Usage

    Action Result
    Click the Changes title Collapse / expand the section
    Click a file row Open the diff viewer (session source)
    Ctrl+P → Toggle collapse (Changes group) Same collapse, keyboard-only

    Collapse state is persisted per TUI instance.

    Requirements

    • OpenCode ≥ 2.0.x (V2 plugin API, @opencode/plugin/tui)
    • A git repository is not required; the panel is driven by the session snapshot

    How it works

    1. The plugin registers a sidebar.content-anchored claim (after the content boundary, below other sections, above the footer) with @opencode/plugin's ui.slot.
    2. It fetches client.session.diff({ sessionID }) and classifies each FileDiff.Info by its authoritative status (added / deleted / modified), falling back to ± counts if status is absent.
    3. Refreshes are debounced 500 ms and triggered by session.execution.succeeded, session.idle, and session.revert.* events.
    4. The host paints only the synchronous snapshot returned by the slot render, so any state change re-registers the claim (documented in docs/DEVELOPMENT.md).

    Limitations

    • The official diff viewer cannot focus a single file from the API; clicking opens the whole session diff (navigate files with n / p inside it).
    • The plugin is TUI-only (V2). It ships a no-op server stub because the host loader requires one.

    Development

    bun install
    bun run build      # dist/index.js + dist/tui.js (host deps stay external)
    bun test           # 34 unit tests
    bun run typecheck
    

    Deeper notes, verified API contracts, and edge cases live in docs/DEVELOPMENT.md.

    License

    MIT

    同类生态推荐