- Главная
- Плагины
- Сеансы и сообщения
- dsh-tool-result-trimmer
dsh-tool-result-trimmer
jaylor-wang/dsh-tool-result-trimmer
Eager, tail-heavy, line-aware tool result trimmer plugin: hooks into post-execution pipeline to trim oversized command outputs with smart semantic reducers and ANSI stripping.
Установка
dsh plugin --profile web add github:jaylor-wang/dsh-tool-result-trimmerREADME
dsh-tool-result-trimmer
dsh-tool-result-trimmer is a lightweight, zero-dependency Cordis plugin designed for DeepSeek Harness (DSH). It hooks into the tool execution pipeline to eagerly trim oversized tool outputs (such as massive compiler errors, verbose test outputs, or long command logs) before they pollute the conversation session log and LLM context.
Why dsh-tool-result-trimmer?
Traditional context optimization tools (like compaction pruners) act passively: they let massive tool outputs enter the session log and LLM memory first, and only attempt to prune or replace nodes when context compaction is triggered. This causes UI freezing, session log bloat, and compaction thrashing.
dsh-tool-result-trimmer solves this with an eager pipeline approach:
- Eager Trimming (Zero Log Bloat):
Hooks directly into DSH's official
tools/post-executewaterfall pipeline. Oversized results are trimmed before they are committed to session storage or context windows. - Tail-Heavy Budgeting:
Most command failures, build errors, and test assertions display critical failure information and exit codes at the tail of the output. By default,
dsh-tool-result-trimmerpreserves 1,500 characters at the head (arguments, initial states) and 5,000 characters at the tail (stack traces, exit codes). - Command-Aware Semantic Reducers (Strict Fail-Open):
Pre-processes verbose command outputs before mechanical trimming without risking data loss:
- Git Reducer: Collapses clean
git statusto a single line; strips repetitive(use "git add...")guidance on dirty worktrees while preserving 100% of modified file lists; strips noisyindexhash lines ingit diff. - Package Manager Reducer: Scrubs progress spinners, peer deprecation notices, update announcements, and funding prompts in
npm,pnpm,yarn, andpip, cleanly preserving package audits and vulnerability diagnostics. - Test Reducer: When all test suites pass cleanly (
node --test,vitest,pytest,cargo test), collapses pages of individual passed ticks into a clean 1-line summary. Strictly fails open on any test failure or non-zero exit code, preserving every stack trace and assertion error.
- Git Reducer: Collapses clean
- Line-Aware Snapping:
Never cuts arbitrarily at character offsets. Instead, it snaps boundaries to adjacent newlines (
\n). Code lines, JSON structures, and error messages remain syntactically complete without broken words or surrogate corruption. - ANSI Escape Sequence Stripping:
Automatically identifies and scrubs terminal ANSI color codes (
\x1b[31m), cursor controls, and line clearing sequences (\x1b[2K,\x1b[1G), eliminating token waste and noisy artifacts to keep terminal output crystal clear for LLMs. - Zero-Side-Effect Safeguards:
- File Read Protection: Automatically bypasses
readandread_imagetools to avoid disrupting file inspection with line-number references. - Rich Block Preservation: Non-text blocks (e.g., images) are preserved completely untouched.
- Escape Hatch (Bypass): Immediate pass-through via inline directives (
# no-trim) or environment flags (DSH_TRIM_BYPASS=1).
- File Read Protection: Automatically bypasses
Installation
Via DSH Plugin CLI (Recommended)
dsh plugin --profile web add dsh-tool-result-trimmer
Via npm / pnpm
npm install dsh-tool-result-trimmer
# or
pnpm add dsh-tool-result-trimmer
Configuration
Add the plugin to your cordis.patch.yml or agent preset:
- name: dsh-tool-result-trimmer
config:
enabled: true
stripAnsi: true # Strip terminal ANSI escape codes (default: true)
thresholdChars: 10000 # Trigger trimming when output exceeds 10,000 chars
headChars: 1500 # Characters retained at the head
tailChars: 5000 # Characters retained at the tail
excludeTools: # Tools excluded from trimming
- read
- read_image
overrides: # Per-tool custom budgets and flags
bash:
thresholdChars: 15000
headChars: 2000
tailChars: 8000
git:
enabled: false # Completely disable trimming for git
semanticReducers: # Command-aware semantic reducers control
enabled: true # Enable semantic reduction (default: true)
git: true # Git status & diff refinement
packageManager: true # npm / pnpm / yarn / pip noise filtering
test: true # Clean test suite folding with strict Fail-Open
Options
| Field | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Whether the trimmer is enabled. |
stripAnsi | boolean | true | Whether to strip terminal ANSI escape codes and styling (saves tokens). |
thresholdChars | number | 10000 | Global safety threshold (in characters). Recommended to exceed headChars + tailChars (default 6500). Outputs below threshold or within budget sum pass through with zero object allocations. |
headChars | number | 1500 | Global character budget for output head (keeps command invocation & starting context). |
tailChars | number | 5000 | Global character budget for output tail (keeps errors, stack traces, exit codes). |
excludeTools | string[] | ['read', 'read_image'] | Tool names excluded from trimming. |
overrides | Record<string, ToolOverride> | {} | Per-tool budget overrides and toggles. Supports custom thresholdChars, headChars, tailChars, stripAnsi, or enabled: false. |
semanticReducers | object | { enabled: true, ... } | Command-aware semantic reducers settings (enabled, git, packageManager, test). |
Escape Hatch (Bypass Mechanism)
When the model or user explicitly requires 100% untouched raw tool output for deep debugging, several escape hatches are supported:
- Command environment prefix (ideal for Bash commands):
DSH_TRIM_BYPASS=1 npm test # or DSH_NO_TRIM=1 cargo check - Inline comment directives (natural and clean):
git diff # no-trim # or node test.js // bypass-trim - Tool argument flag:
Pass
bypassTrim: trueornoTrim: truein the tool call arguments. - Global environment variable:
Set
DSH_TRIM_BYPASS=1on the process to globally pass through all outputs untouched.
What the Model Sees
When a tool output exceeds thresholdChars, the trimmer cleanly splices the head and tail, inserting a clear statistical notice:
<cleanly preserved head output ending at newline>
[... tool output trimmed: omitted 45,210 characters (~1,280 lines) ...]
<cleanly preserved tail output starting at newline>
License
Похожие плагины
dsh-web-ui (dsh-chat-recovery)
zhu1090093659/dsh-web-ui
billion-context
ranxianglei/billion-context
dsh-synapse
liangmianya/dsh-synapse
dsh-chat-import
nwflower/dsh-chat-import