dsh-context-budget
Manifest validAdds per-route context window and compaction threshold fields to the Models settings page and a vendor-aware thinking-effort picker to the composer, writing llm-pi-ai capacities, reasoningEfforts, and
dsh-context-budget
English | 中文
Adds a "context window / compaction threshold / retain budget" group to every pi-ai provider card on DSH Web's Settings → Models page. Type the numbers once; the window and the compaction trigger take effect without a restart.
What it fixes
Third-party gateways are usually declared by hand (api + baseURL + models). Their model ids rarely match the built-in pi-ai catalog — grok-4.6 on a my-gateway route is not the catalog's x-ai/grok-4.6, because they belong to different routes — so capacity resolution falls through to the last level, defaultContextWindow, which is 262144. Meanwhile the compaction backend only accepts a ratio, so "compact at 600k" has no direct spelling.
This plugin turns both into two fields:
| Field | Written to | Effect |
|---|---|---|
| Context window | llm-pi-ai settings, providers.<route>.defaultContextWindow | Models on that route that neither their own entry nor the installed catalog sizes get your value immediately |
| Compaction threshold | the profile's cordis.patch.yml, compaction-basic modelPolicies[].thresholdRatio | The backend computes floor(contextWindow × ratio) — your absolute threshold |
| Retain budget (optional) | same row, modelPolicies[].retainTokens | Recent context kept verbatim; blank keeps the backend's 16% default |
| Thinking effort | llm-pi-ai settings, providers.<route>.models[].reasoningEfforts | The picker at the composer's bottom-right resolves levels by vendor and the selected one is sent to the model |
The threshold is stored as threshold / window, so changing the window later needs one more Apply to re-derive the ratio.
Thinking effort (bottom-right of the composer)
A hand-declared route has no catalog entry, so the adapter treats its models as non-reasoning — the model selector only ever says "this model provides no reasoning effort levels". This plugin puts the control at the bottom-right of the composer, right next to the model selector, and keeps it out of the settings card:
- it reads the session's current model and uses the levels the catalog already advertises for it, when there are any;
- otherwise it identifies the vendor from the model id and takes that vendor's level profile;
- when you pick a level and the model has never declared one, the plugin writes the profile into
models[i].reasoningEffortsfirst, then switches the session effort — without that declaration the adapter rejects the selection as unsupported.
Built-in vendor profiles, matched against the model id, first match wins:
| Vendor | Match | Levels |
|---|---|---|
| xAI | grok | off low high max |
| OpenAI | gpt / chatgpt / o1…o9 | minimal low medium high |
| Anthropic | claude | low medium high |
| DeepSeek | deepseek | off high |
gemini / gemma | minimal low medium high | |
| Qwen | qwen | off low medium high |
| Z.ai | glm / z-ai | off high |
| Moonshot | kimi / moonshot | off high |
| MiniMax | minimax | off low medium high |
The wire value is the level name itself (reasoning_effort for openai-completions, reasoning.effort for openai-responses). If your gateway spells one differently, edit the value side of that model's reasoningEfforts in settings.yaml — the name shown in the picker is unaffected.
A selected level is persisted in the session log's request/header and sent with the request.
Why the compaction engine is not replaced
compaction-basic computes thresholdTokens = floor(contextWindow × thresholdRatio), and contextWindow is re-resolved through llm.resolveModelInfo() on every agent/pre-step. Writing the ratio is therefore enough: the official durable transaction, replay reuse, and overflow recovery all stay in place, and this plugin only supplies two numbers the engine already accepts.
Install
dsh plugin --profile web add dsh-context-budget
Restart dsh web once, then open Settings → Models and expand any pi-ai provider card — the "Context budget" group sits inside it.
After a successful write, the profile's patch watcher (patchReload: live) recomposes in about a second. No second restart.
Validation
Rejected host-side with a reason before anything is written:
- window and threshold must be positive integers;
- the threshold must be smaller than the window;
- the derived ratio must land in
(0, 1)and stay abovecompaction-basic's default retain ratio0.16, which the backend would otherwise refuse to load; - a supplied retain budget must be smaller than the threshold;
- the route must enumerate at least one model id, because
modelPoliciesrows are exactprovider/modelpairs.
Safe writes
cordis.patch.yml is your own layer, and the plugin touches only the block it owns:
- one marked managed block; every other line — comments and foreign patch rows — is preserved;
- the previous file is copied to
cordis.patch.yml.contextbudget.bakfirst; - the result is re-parsed and every
provider/modelrow is verified on disk, with an immediate rollback on failure; - if a hand-written
- id: compaction-basicrow already exists, the plugin refuses and names the line instead of overwriting your configuration.
Known limits
- pi-ai routes only.
llm-deepseekalready exposescontextWindowin the official editor. defaultContextWindowis a fallback: it does not override acontextWindowalready written on a model entry, nor a model the installed catalog describes. For a pure catalog route, set capacities per model instead.- The window must match the gateway's real capability. Too large and requests fail with
CONTEXT_WINDOW_EXCEEDED, then burn an extra summarization request on overflow recovery. maxTokensis not one of the fields; it stays at 32768, so a 1M window leaves roughly 968k of usable input.- Compaction costs one extra summarization request, so a lower threshold means more of them.
Uninstall and rollback
dsh plugin --profile web remove dsh-context-budget
Removing the plugin does not undo its two durable effects; that choice is yours:
defaultContextWindowunderllm-pi-aisettings — delete the field to fall back to 262144;- the
# dsh-context-budget managed blocksection incordis.patch.yml— delete that block; everything around it is untouched.
Every write leaves cordis.patch.yml.contextbudget.bak behind for comparison or restore.
Development
node --check lib/index.js
node --check client.js
node test/pure.test.mjs # validation rules + managed-block write/rollback
node test/integration.test.mjs # apply() registration and patch-path resolution
node test/apply.test.mjs # full write flow against a mocked context
node test/client.test.mjs # client seat registration and card rendering
Neither suite needs a running Harness.
License
MIT
Compatibility
Versions
| Latest version | Published | Size |
|---|---|---|
| 0.1.0 | — | — |
| 0.2.0 | — | — |
Comments
Loading…
Similar plugins
by mouse985
Caps the routed model's context window from a chip on the right of the composer (32k / 64k / 128k / 256k / 512k / 1M, plus a revert) by writing the provider's own contextWindow setting, so automatic c
★ 2
MIT
JavaScript
Nov 20, 2026
dsh plugin --profile web add dsh-context-capContext fullness bands, the per-session compaction threshold derived from the model window, per-step cost computed from cache read and cache write rates, cache-hit, DeepSeek balance with the peak/off-
★ 0
dsh plugin --profile web add dsh-context-governorby xuanfenglajiao
Replaces the composer model menu with a recent-models list, an all-providers flyout and a draggable reasoning-effort slider; a Manage models row at the bottom of the flyout opens the Models settings d
★ 0
MIT
JavaScript
Nov 16, 2026
dsh plugin --profile web add dsh-effort-menuautomatically set reasoning efforts for self-defined models in Deepseek Harness
★ 0
MIT
JavaScript
dsh plugin --profile web add dsh-reasoning-adapterby AkotaP
DSH web plugin: a Model Capabilities page in Settings — manage per-model Context Window, Max Output, Input Modalities and Reasoning Levels (Default = drop the field), plus global preset lists.
★ 0
MIT
JavaScript
Nov 10, 2026
dsh plugin --profile web add dsh-model-tweaksby TacitSay
可配置的上下文压缩插件:总压缩 / 思考压缩 / 工具输出压缩,带左栏面板(DeepSeek Harness)
★ 1
MIT
JavaScript
Nov 8, 2026
dsh plugin --profile web add dsh-compact-arsenal