Truncate Lsp Diagnostics
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.
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"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-truncate-lsp-diagnostics@0.3.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-truncate-lsp-diagnosticsOpenCode 启动时会通过内嵌运行时自动加载 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.
What it does
- Session baseline — diagnostics already reported in a previous round are filtered out, so the model only sees newly introduced errors.
- 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.afterhook returnsPromise<void>, so the plugin mutatesoutput.outputrather 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
同类生态推荐
Ralph Rlm
@doeixd/opencode-ralph-rlm
Ralph RLM v0.2: OpenCode supervisor provider + loop engine + worker plugin
Intent Gate
opencode-intent-gate
TypeSafe Jev-powered intent gate for OpenCode: makes the agent confirm intent before diving into underspecified requests.
Goal
@prevalentware/opencode-goal-plugin
OpenCode goal plugin that adds Codex-style long-running goal mode, /goal commands, persistence, and TUI status for AI coding agents.