rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:icrefin/dsh-context-usage-guard
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
Keeps the DeepSeek Harness composer's context-usage ring honest: an empty usage
sample during a retry no longer collapses it to 0%, and its percentage is
typeset at the size of the figures beside it.
English | 简体中文
A DeepSeek Harness (dsh) plugin that repairs two defects in the composer's context-usage ring — one in the value it shows, one in how large that value is drawn:
0% while a model request is being retried — the
host half; andOne line, in the composer footer:
182 steps · 238 tok/s 33.4M tok · Cache hit 94% ◯ 30%
↑
the ring's 30% was one pixel larger than every other figure
Mid-retry, the same ring read 0% instead of holding the last real reading:
◯ 0% → ◯ 6%
0% while a request is being retriedThe ring renders the session projection contextPressure. That projection takes
the newest usage sample as the current prompt size and publishes:
pressureTokens = usage.inputTokens + cacheReadTokens + cacheWriteTokens
projectedTokens = max(0, pressureTokens + surfaceTokens - sampledSurfaceTokens)
A model call that fails before the provider reports anything — a 429, a rate
limit, a timeout, a transport error, or a user cancellation — still ends its
stream with a usage chunk:
[ { "type": "chunk", "chunk": { "type": "usage", "usage": { "inputTokens": 0, "outputTokens": 0, "totalTokens": 0 } } },
{ "type": "chunk", "chunk": { "type": "finish", "reason": { "kind": "error",
"failure": { "code": "RATE_LIMIT", "message": "429: token_capacity_exceeded" } } } } ]
The adapter's accumulator starts at zero and nothing ever overwrote it, so this
sample is empty, not a measurement. But it is the newest sample, so
pressureTokens becomes 0, and because the sample is stamped at the current
surface total the projection publishes projectedTokens: 0. @deepseek-ai/dsh-llm-retry
then retries the same step — six times in the session this plugin was written
from — and the ring reads 0% for the whole storm, misreporting a context that
never changed.
Measured against the shipped contextPressure fold, replaying that session's
real events (test/fold.spec.ts):
| Replay | pressureTokens |
projectedTokens |
Ring |
|---|---|---|---|
| after the last successful call, before the retry | 64 389 | 64 389 | 6% |
| the failed attempt, unguarded | 0 | 0 | 0% ← the symptom |
| the failed attempt, guarded | 64 389 | 64 389 | 6% |
| the retried step finally succeeds | 64 575 | 64 575 | 6% |
The same footer band holds the session statistics and the ring, and the two shipped stylesheets disagree by one pixel about how big a figure is:
/* @deepseek-ai/dsh-client-ui-chat — StatsPills.module.css, the pills */
.Q51KRG_trigger { font-size: calc(var(--dsh-content-font-size-secondary,13px) - 1px) }
/* @deepseek-ai/dsh-client-ui-conversation — ContextMeter.module.css, the ring */
.JObwrW_trigger { font-size: var(--dsh-content-font-size-secondary,13px) }
Both prefixes are content-hashed per build — the pair above is what the
0.2.2-rc.2 packages installed here carry; the declarations are what matters,
and test/meter-typography.spec.ts re-reads them from the installed packages
rather than trusting this block.
So 30% renders about 8% larger than the 182 steps, 238 tok/s, 33.4M tok
and Cache hit 94% beside it, which reads as a different typeface. Measured on a
screenshot of that line: every other figure has a 12 px cap height, the ring's
has 13–14 px — a ratio of 1.08, exactly 13 ÷ 12. The meter's own breakdown
panel is already 12px, so the trigger is the outlier.
| Half | Surface | What it does |
|---|---|---|
| Host | llm/stream waterfall |
one listener that withholds an empty usage sample belonging to a failed attempt, so the projection keeps its last real reading |
| Browser | the document head |
one self-tagged stylesheet rule that puts the meter's percentage at the statistics pills' figure size |
Neither half adds a page, a route, a settings section or a stored file. The host
half declares inject: ['llm'], so the LLM service must exist first, and it
registers inside ctx.effect: cordis runs the disposer on unload, when the
profile patch disables the row, or at shutdown — a bare ctx.on would leak the
listener past unload.
One rule, applied to the chunk stream of every model call:
A usage sample whose every reported count is zero measures nothing. When it belongs to an attempt that ended in
errororaborted, it is dropped, so the previous real reading stands.
Everything else passes through untouched:
stop, tool-calls and
max-tokens are authoritative provider answers, so a zero there is left for
the consumer to judge;finish the retry
executor reads is preserved.The wrapper holds at most one usage chunk and releases it immediately
before the next chunk, so the only chunk whose position can change is the sample
that decides the outcome. A stream that ends without its terminal finish still
releases a held sample — the guard never swallows information it did not
positively decide to drop. Withholding the chunk is legal in the stream protocol:
usage may appear at most once and is never required, BlockAssembler.usage
stays undefined without it, and the agent loop already omits the durable
event's usage field rather than failing. Token accounting is unaffected — the
projection's usage fold adds an empty sample's buckets as zero anyway, which
test/fold.spec.ts pins directly.
The browser half adds one stylesheet rule that repeats the statistics declaration verbatim:
button[aria-haspopup="dialog"]:has(> svg > circle) {
font-size: calc(var(--dsh-content-font-size-secondary,13px) - 1px);
}
<svg> with
<circle> children — while the statistics pills draw <path> icons. A build
that re-hashes every class name cannot break the rule, and the pills can never
match it. Specificity (0,1,3) beats the shipped (0,1,0), so there is no
!important.line-height.test/meter-typography.spec.ts reads both declarations out
of the installed packages and fails when they converge, so a release that fixes
the trigger upstream says so instead of leaving a silent workaround behind.
The footer band as tools/preview.mjs renders it outside the GUI: the pills'
26 turns 182 steps · 238 tok/s and 33.4M tok · Cache hit 94%, and the ring's
30%, now share one figure size — all of it drawn from the installed
dsh-client-ui-chat and dsh-client-ui-conversation stylesheets. The figures
are a replay of plausible session projections, not a capture: the harness never
reads a session log, a profile or the network.
| Requirement | Version | Notes |
|---|---|---|
| DeepSeek Harness | >=0.2.2-rc.2 <0.2.3-0 |
the dsh range this build is pinned to (verified on 0.2.2-rc.2); peers are @deepseek-ai/cordis ~4.1.0, @deepseek-ai/dsh-llm 0.2.2-rc.2 and @deepseek-ai/schemastery ~3.19.0 |
| Node.js | >=24.9.0 |
engines.node in package.json |
| pnpm | 11.20.0 |
only for developing this repository: pnpm check and pnpm build |
| Google Chrome, Chromium or Edge | any recent | only for tools/preview.mjs, the screenshot harness |
The built halves are committed in lib/, so installing the plugin needs no build
step and no toolchain beyond the harness you install it into.
git clone https://github.com/icrefin/dsh-context-usage-guard.git
cd dsh-context-usage-guard
sh scripts/install.sh
scripts/install.sh packs dist/dsh-context-usage-guard-0.2.4.tgz and prints the
path to give the app. The desktop profile is owned by the Electron application,
so dsh plugin add refuses it: install the tarball from Settings → Plugins
(or with the plugin-manager tool), then restart. A bundle added to a running
profile cannot be imported by that process — its module path is not in the
resolution the harness computed at boot — and the browser half additionally needs
the page reloaded.
To run the suite before or after installing:
pnpm install
pnpm check # tsc over both halves, then 40 tests in five suites
Two operational notes:
node_modules alone, so a rebuilt tarball at the
same version does not reach the profile. Remove the bundle first, then install
it again — or bump the version.Remove the bundle from Settings → Plugins (or with the plugin-manager tool)
and restart. Nothing else is written: no route, no file, no stored state. The
stylesheet goes with the bundle — the client module system evicts any <style>
tagged for this package, and the plugin's own effect removes it even earlier.
The row's Config is the settings namespace, so the values live in the row's
config in <profile>/cordis.patch.yml:
- id: dsh-context-usage-guard
config:
enabled: true
logHeldSamples: false
| Field | Type | Default | Meaning |
|---|---|---|---|
enabled |
boolean | true |
While off, every stream is passed through untouched. |
logHeldSamples |
boolean | false |
Log one host line per withheld sample: route and failure code. |
Both fields are volatile, so a change applies to the next request with no reload. The defaults change nothing except the repair itself: a fresh install behaves like a stock one that keeps its context reading honest.
[dsh-context-usage-guard] held an empty usage sample from a failed request
(example-provider/example-model-v1, RATE_LIMIT); the context reading stays at its last value
dsh-token-meter registers
contextPressure internally and the registry shares a key rather than
replacing it, so a second registration cannot override the fold, and
re-registering the same key first would hijack a package this plugin does not
own. Repairing the fold's input is the narrow fix; the fold itself is left to
its owners.dsh-client-ui-conversation's input bar with no extension seat. The one
thing the browser half does is add a font-size declaration to the trigger the
statistics already prove is wrong; the ring, its icon, its colors, its hover
state and its dialog are the shipped ones.stop/tool-calls/max-tokens
answer with zero counts is still an answer. The plugin never overrides a
provider's own numbers.tools/preview.mjs renders the real bundle and the real stylesheets in headless
Chrome and fails unless the meter matches the pills; what the running app paints
with a user's own theme and font settings is not asserted automatically.llm/stream waterfall, which is where the harness routes model calls; a
provider reached around that service is neither guarded nor broken by this
plugin.The ring still reads 0%. Check that enabled is true. If it is, the
reading came from a call that completed successfully: the guard withholds empty
samples only from attempts that ended in error or aborted, and a successful
answer reporting zero is left for the consumer to judge. Once a retried step
succeeds, the next real usage sample takes the reading over again.
The percentage still looks larger than the figures beside it. The rule is
installed when the browser half registers, so a plugin installed into a running
app needs the restart described in Install and then a page reload.
After that, test/meter-typography.spec.ts is the authority: it fails when the
shipped declarations converge, which is the signal to delete the rule.
No held an empty usage sample line appears in the log. That line is behind
logHeldSamples, which defaults to false; the repair itself does not depend on
it. Turn it on and the next withheld sample prints the route and the failure code.
MIT — see LICENSE.
If this plugin keeps your context reading honest, a ⭐ star helps other DSH users find it.
Built for DeepSeek Harness 0.2.2-rc.2 · MIT · issues and pull requests are welcome.
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek-harness。