dsh-cc/dsh-cc--packages-context-context-crusher ↗★ 4

@dsh-cc/context-crusher

CCR reversible tool-output compression: compress large grep/log tool results, cache the original, retrieve it via context_retrieve 自动压缩大体积的工具输出并支持无损检索,适合处理大量日志或搜索结果的任务。

Package
@dsh-cc/context-crusher
Compatibility
Unverified
Harness peer range
>=0.2.0-rc.2
Cordis peer range
>=0.2.0-rc.2
Version
0.9.1-rc.1
License
Apache-2.0
Last updated
Oct 13, 2026

Install

This plugin has no verified bundle, or compatibility checks failed. Read the repository notes first. Read the full README ↗

@dsh-cc/context-crusher

English | 中文

CCR (Compress-Cache-Retrieve) reversible tool-output compression. A tools/post-execute listener compresses large grep/log-shaped tool results, caches the original in a content-addressed store, and appends a ccr:// marker; the context_retrieve({ hash }) tool restores the original verbatim. Compression is risk-free because the original is always one call away.

Gated flow

  1. tools/post-execute fires; the crusher is the OUTERMOST listener ({ prepend: true }, mounted before the hooks bridge) and composes post-next().
  2. A non-accept downstream decision passes through untouched.
  3. Gates, in order: disabled → protected tool (replace-semantics list) → short error (]— appended to every replaced result. Thecontext_retrievetool description references the sameccr://spelling; a test pins the pairing.hashissha256(original utf8)` hex, first 16 chars.

Store

$DSH_HOME/ccr/ /, projectKey = sha256(session cwd) first 16 hex (the worktree-path divergence from the TUI project-root convention is accepted: the store is self-consistent). Atomic temp+rename writes, plain UTF-8 envelope files, LRU 200 entries, TTL 3600 s, sweep-on-write (fire-and-forget). Corrupt/expired entries fail closed (corrupt / expired / unknown_hash).

Config

Namespace cc-context-compression (settings overlay re-read on every use; config defaults under it). protected-tools REPLACES the default list when explicitly set — not a union.

KeyDefaultMeaning
enabledfalseMaster flag; the feature is opt-in.
modedry-rundry-run measures only; on replaces.
min-bytes8192Minimum size before eligibility (token-meter tokens; the key keeps its legacy name).
min-savings-ratio0.4Minimum token saving fraction.
protected-toolsover-inclusive default listTools never crushed.
reducer-enabledfalseEvidence-preserving reducer master flag: eligible results go through a cheap-model side query instead of stub truncation (§3.2).
reducer-commandsover-inclusive default listRegex sources matched against the bash invocation command line to decide reducer eligibility; an invalid pattern is dropped, an empty list falls back to the defaults.
reducer-max-input-tokens30000Head/tail truncation threshold (tokens) for reducer input.
reducer-min-savings-ratio0.5Minimum size-gain ratio the reducer output must show to be applied.
reducer-max-tokens1024Side-query output token cap.
reducer-timeout-ms10000Side-query wall-clock budget in ms.
reducer-aliashaikuCheap-lane alias used for the side query.
defer-requests0Deferred externalization: eligible results enter the session unmodified and swap to the standard stub after this many counted main-loop sends; 0 disables deferral.
defer-margin1.5Suffix-cost gate multiplier for the deferred swap.
defer-max-age-ms1800000Sweep age (ms) for deferred residents that never swapped.
defer-urgency-tokensunset (inactive)Window-pressure override distance in tokens: when the session estimate comes within this distance of the model window, residents swap regardless of the gate. Inactive without a window source.

foldCounters convention

This package exports foldCounters(materials) for @dsh-cc/token-efficiency; any change to the marker/ledger shape MUST update the fold and its tests in the same PR.

Caveats

  • The transcript keeps the COMPRESSED form forever: TUI replay and command-export show the compressed blob (the original lives only in the store + ledger).
  • final-result dispatches and tool-definition finalizeContent bypass or follow the waterfall and may rewrite crushed content — residual bypass classes, best-effort coverage.
  • The marker is inert text; there is no auto-restore and no model-summarization.