dsh-optimize
Manifest validLong-session resource governor for DeepSeek Harness: measures the context each request actually carries, tracks per-session growth, warns before a session becomes expensive to run, and (optionally) trims the rendered history in the web UI.
dsh-optimize
Long-session resource governor for DeepSeek Harness.
A conversation that keeps growing gets expensive long before anything
compacts it: every step re-sends the retained history, the session log grows
without bound, and the web UI has more history to draw. dsh-optimize
measures that growth and reports it, so a heavy session is a visible fact
rather than a surprise.
What it does
- Measures what every outgoing request actually carries (message count,
characters, estimated token range) on each
agent/pre-step. - Reads the harness's own
contextPressureprojection on session events — the authoritative token figure, and O(1) — so the estimate above is never the only number kept. - Keeps a per-session record — requests, events, last and maximum request
weight, projected tokens, compaction count — in
$DSH_HOME/storages/dsh-optimize/state.json. - Logs a warning the first time a session crosses
warnTokens, and again atcriticalTokens, with the measured range. - Optionally (off by default) runs the session's own compaction engine
once the measured weight passes
compactAtTokens, through the sanctionedctx.agentPresets.serviceFor(agent, 'compaction')handle. The plugin decides when; the harness engine keeps deciding what to summarise. - Provides the
optimizehost service (snapshot(id),list(),flush()).
It does not change the system prompt, the tool schemas, or the request prefix, does not write session events, and does not touch the session log.
Install
dsh plugin --profile <profile> add dsh-optimize
Or from a checkout:
dsh plugin --profile <profile> add /path/to/dsh-optimize
Configure
The bundle patch ships the defaults; override them in your profile's patch
layer (~/.dsh/profiles/<profile>/cordis.patch.yml):
- id: dsh-optimize
config:
warnTokens: 120000
criticalTokens: 300000
autoCompact: false
compactAtTokens: 200000
compactCooldownMs: 300000
verbose: false
| Key | Default | Meaning |
|---|---|---|
warnTokens | 120000 | Estimated request weight that marks a session as heavy. |
criticalTokens | 300000 | Estimated request weight that marks a session as critical. |
autoCompact | false | Run the harness compaction engine over budget. |
compactAtTokens | 200000 | Measured weight at which automatic compaction may run. |
compactCooldownMs | 300000 | Minimum delay between two automatic compactions. |
verbose | false | Log every measured request, not only threshold crossings. |
The estimate is a range: Latin text is near four characters per token, CJK near
one and a half. The upper bound is the one compared against the thresholds, so
a mixed-language session errs towards reporting early. When the harness's
contextPressure projection is available, its number wins for the compaction
decision.
Notes on automatic compaction
- It is off by default, because it changes what the model sees. The
built-in engine already compacts when the routed model's window is nearly
full (ratio
0.8by default) or when the provider reports a context overflow; this option only makes it fire earlier, at your budget. - The engine is mounted inside the agent preset's isolate realm, so the only
sanctioned handle is
ctx.agentPresets.serviceFor(agent, 'compaction'). - Its thresholds are frozen at construction: nothing can retune the engine at
runtime, and changing
thresholdRatio/retainRatiomeans editing the preset row and re-mounting. - Compaction needs an idle agent; a request made mid-turn is refused with
busyand retried on a later check.
In the browser
The chat view mounts one DOM row per visible node of the loaded history and lays out every one of them; only the trajectory table virtualises. On a long session that is thousands of live rows.
- Lite rendering (on by default, switchable): a stylesheet puts
content-visibility: autoandcontain-intrinsic-size: auto 320pxon[data-chat-anchor-key], so the browser skips layout and paint for rows outside the scrollport. React still reconciles them exactly as before, and the remembered row height keeps scroll anchors stable. - Composer chip: shows the current state and how many rows are mounted; clicking it toggles lite rendering.
- Settings row: the same switch, under Settings → General.
The switch is persisted in localStorage under dsh-optimize:lite. Nothing
about the session is hidden or unloaded: every row stays mounted and reachable.
Roadmap
- A context-pressure readout in the composer chip, read from the harness's own
contextPressureprojection.
License
MIT.
Comments
Loading…
From the same category
by nexu-io
🎨 Best DeepSeek Harness Design Plugin. The open-source Claude Design alternative. 🖥️ Local-first desktop app. 🖼️ Your coding agent becomes the design engine: prototypes, landing pages, dashboards,
★ 98.5k
Apache-2.0
TypeScript
Sep 29, 2026
by Molunerfinn
:rocket: The Ultimate Image Uploader for Efficient Creators. Supports Obsidian, Typora, VS Code etc. and 60+ image hosting services (S3, GitHub, Cloudflare R2, Imgur, Aliyun OSS...). Paste, upload, d
★ 27.3k
MIT
TypeScript
Sep 24, 2026
by zhu1090093659
DeepSeek Harness (DSH) Web Plugin Aggregation Ecosystem · Everything is a plugin, distributed via the Creative Workshop
★ 8.1k
Apache-2.0
TypeScript
Sep 29, 2026
dsh plugin --profile web add dsh-webby YaoApp
✨ All your agents and workspaces in one place, on every device you own. Track tasks on a board, accessible from desktop, mobile, browser, or API. Self-hosted.
★ 8k
Go
Sep 28, 2026
by omdsh-dev
开放的侧边栏底座,支持三方拓展注册新侧边栏页面。内置文件渲染编辑/终端/侧边对话/Git/子代理页面 | Open sidebar foundation, supports third-party extensions to register new sidebar pages. Built-in file rendering/editing, terminal, side chat, Git,
★ 3.9k
↓ 49.8k/wk
MIT
TypeScript
Sep 28, 2026
dsh plugin --profile web add dsh-better-sidebarby ccch1mneyyy
DSH 官方公众号收录的 TUI 补位插件:Claude Code 风,鲸鱼顶栏/实时状态/流式思考/双击 Esc 回滚/上下文进度+TPS。npm 一键装。 DSH official WeChat featured TUI plugin — Claude Code style: whale bar, live status, streaming thoughts, double-Esc rol
★ 3.7k
↓ 10.1k/wk
MIT
TypeScript
Sep 29, 2026
dsh plugin --profile terminal add @deepseek-harness-tui/dsh-tui