rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:Wildchiken/dsh-result-budget
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
English | 中文
Size every DeepSeek Harness tool result to the active model's context window. Local and on-device models with small windows are no longer flooded by a single cat or read, and the budget follows you when you switch models — nothing is tuned for one specific model.
dsh caps tool output with fixed numbers: read 2000 lines / 50 KB, bash 16 000 chars, spill-policy a fixed token count. Fine for a 128k cloud model, far too much for a 4k–32k local one:
read is ~13k tokens — an 8k-window model is full after one call.Before each step, for the results that arrived since the last one:
budget = max(ratio × (contextWindow − reservedOutput), minTokens) # capped by maxTokens if you set one
contextWindow and reserved output are resolved exactly like the official dsh-compaction-basic: the session's routed provider/model through llm.resolveModelInfo; reserved output is the request's maxTokens, else the model default.grep/head/tail for shell tools.read is different: it keeps complete lines from the start and names the exact offset to continue from. A hole in the middle of a paged file would be skipped silently, so no tail is kept. If not even one line fits, the notice points to bash instead of back to the same offset.compaction/prune shadow price, then a tool/result that replaces the node on the surface. It needs dsh-token-meter, which is in the base bundle.contextWindow (or if the lookup fails) fallbackTokens applies.With the defaults:
| Window (reserved output) | Per-result budget |
|---|---|
| 4k (1k) | ≈ 460 tokens |
| 8k (2k) | ≈ 920 tokens |
| 32k (4k) | ≈ 4300 tokens |
| 128k (8k) | ≈ 18 400 tokens (tools' own caps usually apply first) |
| unknown | 2000 tokens |
Six tasks with large tool output, run with Spark X2.6 4B on LM Studio through the DeepSeek Harness headless runner, with the plugin off and on (v0.2.1). Tasks, setup and raw results are in bench/.
| Window | Plugin off | Plugin on | Runs that hit the context limit (off / on) |
|---|---|---|---|
| 8k | 7 / 12 | 12 / 12 | 4 / 0 |
| 16k | 9 / 12 | 11 / 12 | 1 / 1, plus 2 timeouts off |
| 32k | 11 / 12 | 4 / 6 | 1 / 0 |
read cut before the line the model needed, and a grep with the key line in the removed middle. The 32k sample is small (6 runs with the plugin). For windows of 32k and up, raise ratio or leave the plugin off.Trimming by the room left in the context instead of a fixed share was also tested. It did better at 32k (12 / 12) and worse at 8k and 16k, so it was not released.
On small windows the host limits output too. pi-ai, the model client in DeepSeek Harness, sets max output = window − estimated input − 4096, at least 1. On an 8k window a context past about 4k tokens leaves the model one token, and the turn ends with max-tokens. That is behind most of the plugin-off failures above.
dsh plugin --profile <name> add "github:Wildchiken/dsh-result-budget"
As a bundle it applies to every agent in the profile.
Skip the bundle and list it in the preset's plugins — it then covers only that preset's agents:
- insert:
- id: preset-local
name: '@deepseek-ai/dsh-agent-preset'
config:
id: local
name: Local
plugins:
# ...the preset's own tools...
- id: result-budget
name: dsh-result-budget
config:
ratio: 0.15
Or compose it from your own plugin:
import { installResultBudget } from 'dsh-result-budget'
export function apply(ctx) {
ctx.inject(['llm'], (ctx) => installResultBudget(ctx, { ratio: 0.1 }))
}
| Key | Default | Meaning |
|---|---|---|
ratio |
0.15 |
Max share of the usable window one result may take, (0, 1] |
minTokens |
384 |
Budget floor |
maxTokens |
null |
Optional budget ceiling; none by default, so large-window models lose nothing |
fallbackTokens |
2000 |
Budget when the window is unknown |
headShare |
0.75 |
Share of the kept text taken from the start; the rest is the tail. Not used for read |
exclude |
[] |
Tool names to skip, * wildcards allowed, e.g. ["mcp_*"] |
Invalid config (unknown key, ratio out of range, non-positive integer, minTokens > maxTokens) fails at load time instead of silently falling back.
read. It runs first, and this plugin keeps the end of the text, where spill's notice sits. Results between this budget and spill's cap get no file.readLimit, maxOutputChars) can stay at their defaults; this plugin runs after them.offset and used grep instead.dsh-tool-output-budget came first and also bounds each result as it arrives and keeps the log intact. Its budget is a fixed character count. Choose it if you want one number for every model; choose this plugin if the budget should follow the model's window.
npm test
Node 20+ built-ins only; no runtime dependencies.
MIT
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: local-llm、deepseek-harness。