Preface¶
In long sessions, DeepSeek Harness (DSH) uses compaction to replace earlier dialogue surfaces with summaries to control context length. The summary prompt asks the model to quote original text at key points, but the summary remains a model-generated derivative, and precise constraints, corrections, paths, numbers, and approval decisions may still be lost.
To keep these details within the model-visible context, one approach is to preserve the exact text of user-side inputs and interaction decisions and re-inject them after compression. dsh-lossless-anchors is a DSH plugin published by community maintainer EvannZhongg, categorized as “memory” in the SkillHub directory. It does not modify the DSH core, does not add new Session event types, and does not alter compaction-basic; instead, it leverages DSH’s built-in Session projections and PromptContext seams to implement the above approach.
What Is This¶
dsh-lossless-anchors (npm package name dsh-lossless-anchors, version 0.1.3 in current materials) records the exact text of a user message into a persistent projection after compaction has already “obscured” that message, and re-injects it in subsequent requests as a token-budgeted runtime-context snapshot.
The scope of guarantees stated in the plugin README needs to be distinguished:
- Guaranteed: Within the configured token budget, user-side anchors are verbatim originals (the only exception is budget-triggered truncation, which is explicitly disclosed within the block).
- Not guaranteed: Lossless compression of the entire conversation; assistant and tool history are still represented by the compaction summary.
In implementation, “obscured by compaction” means that the seq of that user/message is no longer present in the nodes of the current Session surface.
Core Functions¶
Persistent Projection and Injection Path¶
The plugin operates through four seams (all from the README):
- A persistent Session projection records user-side messages and their turns.
- An original
user/messagebecomes an anchor only when its seq is no longer in the current Session surface. - A dynamic
PromptContextrenders selected anchors as a single user-role runtime-context snapshot. - After compaction obscures that snapshot, the agent loop’s
RuntimeContextProjectionrebuilds it from the plugin’s persistent projection; it is also rebuilt duringagent/request-erroroverflow retries.
Replay, resume, and fork can rebuild the projection from the Session log without additional state files.
Which Messages Become Anchors¶
An anchor must simultaneously satisfy:
- The event is
user/message; source.kindfalls within the configuredincludeSources(default includesuser,user-question-reply,user-approval);- Its seq is not present in
Session.surface.nodesat request time.
Therefore, the current user prompt and the recent tail still on the surface will not be re-injected. Sources such as goal, plan-mode, agent-instructions, runtime-context, compact-checkpoint, etc., are not counted as user anchors by default.
Images are replaced during replay with [image omitted: <mediaType>, <w>x<h>]; files retain their display names and byte counts, and historical image bytes are not re-uploaded.
Budget and Truncation¶
The budget is estimated using charsPerToken (non-CJK) and cjkCharsPerToken (CJK), and accounts for the same block/role framing as a single DSH user message. Defaults are 4 and 1.6, making Chinese anchor blocks closer to the nominal token budget rather than uniformly inflating at 4 characters/token.
Truncation strategy overview (README order):
- Prefer the most recent obscured turn.
- Accept a candidate if it fits within
tokenBudget. - If the latest turn alone exceeds
tokenBudget, it may be retained up tohardMaxTokens. - If still over the limit, first discard the oldest anchor in that turn; if a single anchor is still too large, truncate it and annotate with
… [anchor truncated; full text remains in session log]. - Older turns fit within the remaining soft budget; otherwise, no older turns are considered.
- Omissions or truncations append a disclosure line within the block, e.g.,
[anchor budget: 2 older anchor message(s) elided; 1 anchor text(s) truncated to fit the configured budget].
The full original text always remains in the Session log; the “verbatim” guarantee holds only outside the budget-truncation path.
Model-Side Presentation¶
After compaction obscures the anchor, the next request carries a user-role runtime-context snapshot whose block contains a [Lossless User Anchors] heading, per-entry turn lines with timezone information, and the user’s original text. The system prompt registers instructions on how to interpret this block, and does so unconditionally from the first request, to avoid mid-session system prompt changes that would break prefix caching.
Anchor timestamp format is consistent with DSH’s durable time-context; if a message recorded a browser timezone, it is rendered in that timezone, otherwise the configured timeZone is used.
Installation and Activation¶
The plugin declares a dsh.bundle.patch, which inserts a lossless-anchors line at install time. package.json requires DSH version >=0.2.0-0 <0.3.0.
Local checkout:
dsh plugin --profile web add ./dsh-lossless-anchors
Install from GitHub (the repository tracks built lib/):
dsh plugin --profile web add github:EvannZhongg/dsh-lossless-anchors
If you need to hand-write the patch line, the README provides an example:
- insert:
- id: lossless-anchors
name: dsh-lossless-anchors
config:
tokenBudget: 2000
Configuration Notes¶
Set config for lossless-anchors in the bundle or patch. Full README example:
- id: lossless-anchors
config:
tokenBudget: 2000 # soft budget, calibrated tokens
hardMaxTokens: 3000 # absolute cap; defaults to ceil(tokenBudget * 1.5)
charsPerToken: 4 # calibrated characters per token for non-CJK text
cjkCharsPerToken: 1.6 # calibrated characters per token for CJK text
maxTurns: 32 # most-recent shadowed turns considered
maxAnchors: 256 # projection-state retention cap
includeSources:
- user
- user-question-reply
- user-approval
timeZone: Asia/Shanghai # zone for anchors whose message recorded none; defaults to the host zone
required: true # keep the context when optional runtime context is disabled
Common field meanings (default values see README table):
| Field | Summary |
|---|---|
tokenBudget |
Soft budget for the rendered block (calibrated tokens). The latest obscured turn may be retained alone up to hardMaxTokens. |
hardMaxTokens |
Absolute cap; must be >= tokenBudget, defaults to ceil(tokenBudget * 1.5). |
charsPerToken / cjkCharsPerToken |
Non-CJK / CJK characters-per-token calibration; dense code or JSON may warrant lowering the former. |
maxTurns |
Number of most recent obscured turns considered for selection. |
maxAnchors |
Retention cap for projection state; older anchors are dropped beyond this. |
includeSources |
List of source.kind values treated as user-side-authored. |
timeZone |
IANA timezone used when no browser timezone is recorded. |
required |
When true, this context is not suppressed even if includeRuntimeContext: false. |
Typical tuning: for long sessions with dense constraints, appropriately raise tokenBudget and hardMaxTokens; for predominantly Chinese content, keep the default cjkCharsPerToken: 1.6; if approval-type replies should also enter anchors, confirm that user-approval remains in includeSources.
Suitable Scenarios and Caveats¶
Suitable for: Long-running agent sessions relying on compaction, where the model needs to see the user’s exact wording, paths, numbers, or approval decisions beyond the summary; those who wish to extend DSH natively via projections and runtime context rather than forking the core.
Not intended as: A lossless archive of the entire conversation or a complete replay of assistant/tool history—the latter remains the responsibility of the compaction summary.
Security and operations: The plugin runs with the permissions of the current dsh process; review the repository source before installing and confirm the MIT license (package.json). SkillHub is a community plugin directory site with no official affiliation to DeepSeek / High-Flyer; the directory page shows 0 stars for the repository, which does not indicate the feature is unusable, but evaluate the maintainer and version (0.1.3) against your environment before use.
The DSH ecosystem emphasizes “everything is a plugin”; this plugin is one implementation focused on preserving user original text after compaction, and does not replace the integrity of the Session log itself.
Links¶
- SkillHub directory page: https://www.skillhub.cn/plugins/EvannZhongg/dsh-lossless-anchors
- GitHub repository: https://github.com/EvannZhongg/dsh-lossless-anchors