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 v0.1 does
- Measures what every outgoing request actually carries (message count,
characters, estimated token range) on each
agent/pre-step.
- Keeps a per-session record — request count, last and maximum request weight,
when the session was first and last seen — in
$DSH_HOME/storages/dsh-optimize/state.json.
- Logs a warning the first time a session crosses
warnTokens, and again at
criticalTokens, with the measured range.
- Provides the
optimize host service (snapshot(id), list(), flush()).
It does not change what the model receives, 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
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. |
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.
Roadmap
- Browser half: a session-weight chip next to the composer, a "history window"
toggle that renders only the recent tail of a very long session, and collapse
of old tool output. The trajectory table already virtualises; the chat view
does not.
- Optional automatic compaction when a session passes the budget.
License
MIT.