Preface¶
In DeepSeek Harness (DSH), as conversation turns increase, each request must resend the full visible history. This not only increases token consumption but also causes decoding speed to decrease because the attention mechanism must process the entire KV cache. This plugin aims to solve this issue.
Plugin Purpose¶
dsh-history-fold is a DSH plugin that folds the oldest portion of visible history in a session into a single message, supported by a lossless local archive. It does not generate model summaries; instead, it provides a recoverable extractive index.
Core Features¶
- Lazy by default: After installation, it does not read, write, or log by default; it becomes active after configuration.
- Lossless archiving: Before performing a fold operation, all folded messages are written verbatim to a local archive file.
- No
node_modulesmodification: It uses the same public interface replacement mechanism as DSH’s built-in compressor, so upgrading DSH will not break this plugin. - Extractive index: Folded messages contain an index rather than a summary, pointing to the specific archive path.
- Hierarchical path index: When the index becomes too long, it automatically generates multi-level index files (tier files), each level pointing to an earlier tier, down to the original text.
- Recoverability: The archive file is a superset of the visible history, including all model reasoning processes, and its content can be fully restored.
Installation and Enablement¶
Install using the official command, and DSH must be restarted after installation.
dsh plugin add --profile web github:mili1360/dsh-history-fold
If you want to install from a local clone:
git clone https://github.com/mili1360/dsh-history-fold.git
dsh plugin add --profile web ./dsh-history-fold
The plugin takes effect only after restarting DSH.
Working Mechanism¶
When the visible history exceeds a threshold (determined by triggerRatio × contextWindow or the absolute triggerSurfaceTokens), the plugin performs the following steps:
- Node selection: Select the oldest node range to fold, retain the most recent nodes, and reduce the surface history to the target size (default approximately
0.18 × contextWindow). - Archive write: Write all messages in the fold range verbatim to
$DSH_HOME/history-fold/archive/<session>.jsonl. If the write fails, the fold operation is abandoned. - Message replacement: Replace the original range using
session.append('user/message', ...), setsurfaceOptoreplace, and preserve timeline order.
The folded message content typically looks like this:
[dsh-history-fold] 614 earlier messages (surface seqs 223995..387899) were folded out of the
visible history so this session stays fast.
NOTHING WAS DELETED. Their full text is archived at:
/…/.dsh/history-fold/archive/session-….jsonl
To read any of it verbatim, search that file with the pwsh or grep tools...
(sampled: every 3th of 614 folded messages)
[0] user/message (plugin) seq=223995: ...
Notes¶
- Version requirement: Supports DSH 0.2.0 only.
- Restart requirement: The DSH process must be restarted after installation or update.
- Data safety: All folded content is first written to local disk, then removed from the context, ensuring no data loss.
- License: MIT License.
Summary¶
By folding and archiving the oldest history, this plugin significantly reduces the context size for each request, thereby improving decoding speed and lowering token costs. Due to its lossless archiving and extractive index features, the history content can still be fully restored when needed.