rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:DaVinci-2nd/dsh-context-saver
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
A send-time context trimmer for DeepSeek Harness.
It trims only at the moment the context is submitted to the model. The local session log, the chat transcript, and the trajectory view stay complete. With the plugin disabled, or with every option off, the request is byte-identical to the untrimmed one.
English | 中文
What makes a long session expensive is not the number of turns, it is that every turn re-sends the same material:
This plugin removes that material from the outbound copy only; the local copy keeps everything.
Every model request in DSH passes through the llm/stream waterfall, which carries the complete messages about to be submitted.
The plugin takes the request there, builds a new message array from the enabled rules, and re-dispatches it with ctx.llm.stream(). The original request is deep-frozen and is never modified, and no session event is ever written, so:
session/event, the trajectory view, and exports keep the full history;The DeepSeek Messages adapter imposes hard structural rules. Every shape this plugin emits was designed around them and verified against the live API:
| Risk | Handling | Verified |
|---|---|---|
a tool_result without its tool_use |
tool-call blocks are never removed, only arguments becomes {} |
accepted |
a tool_use without an immediate result |
tool role messages are never removed, only their content is emptied |
accepted |
| thinking block count out of step with local replay metadata | reasoning blocks are never removed, only text is emptied and the signature kept |
accepted |
| an empty thinking block rejected | the real signature is still sent | accepted (empty + signature, empty without signature, and no thinking block all return 200) |
Compaction and session-title requests (purpose set) are never trimmed, so their own input cannot change underneath them.
The control sits in the composer tool row, next to the model and sandbox selectors. Clicking it opens a floating panel:
The panel is localized in Chinese and English and follows the DSH language setting. Settings are stored on this machine and apply to every session:
$DSH_HOME/dsh-context-saver/settings.json
The switch track uses a fixed mid-green (on, #22c55e) and neutral grey (off, #9aa0a6) rather than the theme's brand-primary / border-l2: in the dark theme those two aliases resolve to a near-white #f9fafb and a translucent white, so a white knob on them shows no visible state.
One turn is one user message plus the model output that follows it, so turn boundaries are the user messages.
With N turns in total, H leading turns kept, and T trailing turns kept:
N ≤ H + T nothing is stripped at all (the two retention windows overlap);Example: 17 turns, 7 leading, 8 trailing → turns 1–7 and 10–17 are kept and turns 8 and 9 are stripped (7 + 8 = 15 turns retained).
At least one turn is always kept at each end. The trailing turn carries the current question — emptying it would send a request with no question in it — and the leading one keeps the request starting on a user message. A configured
0is raised to1.
Two independent measurements, both against the live deepseek-flash endpoint.
A real 65-turn session log from this machine, replayed through the adapter's own serialization rules with the session's own 34 tool declarations:
| Prompt tokens | Reply | |
|---|---|---|
| Untrimmed | 867,787 | accepted |
| Trimmed (defaults) | 574,347 | accepted |
33.8% fewer prompt tokens on a long agentic session, and the model still answered correctly.
A 60-turn synthetic session with heavy repeated reads, comparing the request for turn N against the request for turn N+1 to measure prefix reuse:
| Configuration | Prompt tokens | Cache hit rate |
|---|---|---|
| Trimming off | 21,102 | 98.9% |
| Defaults (thinking + repeated reads) | 3,242 | 94.8% |
| Defaults + terminal | 3,242 | 94.8% |
| Defaults + terminal + middle | 1,847 | 90.1% |
So the default configuration sends 6.5× fewer prompt tokens at a 94.8% cache hit rate — the "90% or better" goal holds for every configuration.
dsh plugin add github:DaVinci-2nd/dsh-context-saver
Pin a commit for a reproducible install: dsh plugin add github:DaVinci-2nd/dsh-context-saver#<sha>.
The package is plain JavaScript with no build step and no prepare script, so a git install needs no allowBuilds permission.
Choose the directory in the plugin manager, or point install_bundle at it.
- insert:
- id: dsh-context-saver
name: dsh-context-saver
Remove that row, or uninstall the bundle from the plugin manager. The settings file can be deleted by hand.
| File | Role |
|---|---|
index.js |
Host half: the llm/stream interception and the settings route |
src/trim.js |
Pure trimming logic, side-effect free and unit tested |
src/settings.js |
Defaults and settings persistence |
client.js |
Browser half: the composer-row control and its floating panel |
locale/*.json |
Plugin Manager title and description (zh / en) |
test/trim.test.mjs |
Trimming tests |
node test/trim.test.mjs
MIT © 2026 DaVinci-2nd
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek-harness。