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

    Truncate Lsp Diagnostics

    opencode-truncate-lsp-diagnostics·v0.3.1·代码智能

    OpenCode plugin that hides previously-seen LSP diagnostics and caps new ones per edit, spilling the full list to a file so edits stay readable.

    GitHub 星标

    0

    月装机量

    58

    近 7 天 17

    综合评分

    29.0

    生态多维模型

    最近提交

    1 个月前

    2026-08-26

    快速安装与配置

    opencode.json

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

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-truncate-lsp-diagnostics@0.3.1"]
    }

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

    An OpenCode plugin that trims the LSP diagnostics block that write, edit, and apply_patch append after every edit.

    Why this exists

    After each edit, OpenCode's edit tools append the current LSP errors to the tool output. In a project with many outstanding errors this block is large, and most of it is residual errors the model already knows about and did not introduce.

    OpenCode's own TUI, and most frontends, already collapse or fold long tool output themselves. This plugin is for the ones that do not — for example Zed, which renders tool output raw and leaves it expanded by default.

    image

    What it does

    1. Session baseline — diagnostics already reported in a previous round are filtered out, so the model only sees newly introduced errors.
    2. Cap + spill — if the remaining new diagnostics still exceed a configurable count, only the first few are shown inline and the full list is written to a temp file the model is told to read.

    Limits

    • The token savings are small. If all you want is to cut tool-output tokens, this plugin is probably not worth installing — tools like magic-context already truncate tool calls and do it more thoroughly.
    • Hiding known diagnostics should give the model less noise, but this has not been benchmarked and the expected benefit is modest.

    Install

    Add the plugin to your opencode.json (or opencode.jsonc):

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-truncate-lsp-diagnostics"]
    }
    

    Then restart OpenCode.

    Configuration

    Pass options as a tuple:

    {
      "plugin": [
        [
          "opencode-truncate-lsp-diagnostics",
          { "cap": 3 }
        ]
      ]
    }
    
    Option Type Default Description
    cap number 3 Max new diagnostics to show inline. 0 spills every new diagnostic to a file.
    tools string[] ["write", "edit", "apply_patch"] Tool ids whose output is inspected.
    tmpDir string OS temp dir Directory where spill files are written.

    Example

    First edit to a file with 5 pre-existing errors, with cap: 2:

    Wrote file successfully.
    
    LSP errors detected in this file, please fix:
    <diagnostics file="/path/to/file.ts">
    ERROR [171:32] 'Promise' only refers to a type...
    ERROR [197:20] 'Promise' only refers to a type...
    </diagnostics>
    (3 additional new LSP diagnostics written to /tmp/opencode-lsp-diagnostics-<session>-<ts>.txt; read it for the full list)
    

    Second edit, where the model fixed two errors but introduced one new one:

    Edit applied successfully.
    
    LSP errors detected in this file, please fix:
    <diagnostics file="/path/to/file.ts">
    ERROR [600:10] Cannot find name 'newSymbol'.
    </diagnostics>
    (3 previously-seen LSP diagnostics omitted)
    

    How it works

    The plugin registers a tool.execute.after hook and rewrites output.output in place. A module-level baseline counts each diagnostic identity (severity + message) per file; the [line:col] location is ignored, so a diagnostic that only shifted lines is still recognized as seen. A message whose count increases from one round to the next has that many new occurrences.

    Note: the tool.execute.after hook returns Promise<void>, so the plugin mutates output.output rather than returning a new string. This relies on OpenCode passing the same output object through to the model — current behavior (verified against OpenCode 1.18.21), but not part of the documented contract.

    Development

    bun install
    bun run build    # compile to dist/
    bun test         # run unit tests
    

    License

    MIT

    同类生态推荐