DeepSHPlugins
toolshrink 專案預覽
GITHUB / COMMUNITY PROJECT

toolshrink

工具與整合TypeScriptMIT

按內容語義壓縮工具結果:13 個 reducer 在 tools/post-execute 階段按含義裁剪超長輸出(保留失敗的測試、丟棄 diff 上下文、對 JSON 與 CSV 抽樣、lint 問題按規則歸類、依賴庫的呼叫棧幀摺疊、檔案過多的目錄只給計數),完整原文落盤儲存並留一個定位符可取回。

11 Starsunclecode 更新時間 2026-08-19
訪問 GitHub 倉庫
toolshrink 專案預覽

專案介紹

中文

按內容語義壓縮工具結果:13 個 reducer 在 tools/post-execute 階段按含義裁剪超長輸出(保留失敗的測試、丟棄 diff 上下文、對 JSON 與 CSV 抽樣、lint 問題按規則歸類、依賴庫的呼叫棧幀摺疊、檔案過多的目錄只給計數),完整原文落盤儲存並留一個定位符可取回。

English

Content-aware tool-result reducer: 13 reducers cut oversized output by meaning at tools/post-execute (failing tests kept, diff context dropped, JSON and CSV sampled, lint problems grouped by rule, dependency stack frames collapsed, crowded directories counted), with full originals spilled to disk behind a locator.

專案資訊與收錄訊號

快照 2026-09-11
作者 / 組織
unclecode
倉庫
unclecode/toolshrink
GitHub Stars
11
Forks
0
開發語言
TypeScript
許可證
MIT
最近推送
2026-08-19
Manifest
資料中檢測到宣告

公開倉庫不自動等於可商用;許可證與當前相容性以原專案文件為準。Manifest 和資料評分不構成安裝安全認證。

資料評分

63/ 100
維護活躍
85
文件與實用資訊
50
生態關注度
31
安裝便捷訊號
100
專案宣告訊號
100

近 23 天仍在更新;標準命令一鍵安裝。

評分來自已有資料快照的五維模型,僅作瀏覽參考,不是實際使用評測或安全檢測結論。

安裝與使用

所有專案資料與許可均以對應 GitHub 倉庫為準。

dsh plugin --profile web add github:unclecode/toolshrink

複製命令不會自動執行。請先閱讀倉庫文件,確認環境要求與許可證。

專案截圖

倉庫 README

GitHub 原文

已儲存的倉庫文件快照;文件抓取時間未記錄,可能與上方目錄介紹處於不同版本。安裝前請核對當前倉庫說明。

儲存庫檔案保留原文,指令與授權文字不作自動改寫。

toolshrink

Cut large agent tool output by what it means, not by where it was cut.

I use Claude Code every day, and I always wanted to intervene in how it manages context. In the early days you could edit the session JSONL directly. Then that door closed.

When DeepSeek open-sourced Harness, where everything is a plugin, I looked inside. Tool output there is cut by size: keep the head, keep the tail, drop the middle. I read Codex and pi, and they do the same. None of them look at what the text contains.

That fails in a predictable way. Your test suite prints 5,000 passing lines and 3 failures in the middle. A size cut keeps the passes and throws away the failures. The model reads it, believes the run, and answers wrong.

So I built the shrinker I always wished Claude Code had. It reads the output first, recognizes its shape, and keeps the part that carries the information:

input: a vitest run, 31,958 chars, 805 lines, budget 2,000 chars

head+tail cut:   1,904 chars   the model learns: the summary
toolshrink:        255 chars   the model learns: which test failed,
                               why, at which line, and the summary

Everything removed is counted in a marker the model can read, and the complete original is saved to disk with a locator. Nothing is lost silently.

The cuts

Each cut recognizes one shape of text. The first one that recognizes the input runs. When none does, the size fallback runs, so the result always fits the budget.

CutRecognizesKeepsDrops
diffgit diff, patcheschanged lines, file and hunk headers, 1 context line each sideunchanged context
jsonone JSON valuethe structure, 3 samples per long array, 5 keys per wide object, countsrepeated records
testsvitest, jest, pytest, cargo test, go testfailures with their explanation, the summarypassing tests
buildtsc, cargo, gcc, webpack, esbuilderrors and warnings with their code frame, the summarybuild progress
stacktracenode, Python, Java, Ruby tracesthe message and frames in YOUR codedependency frames, counted
logtimestamped logserrors and warnings with the lines before them, the endingroutine lines
treefind, ls -R, file listingsthe structure, 8 entries per directory, countscrowded directories
repeatretry storms, progress spam2 samples per run plus "2,998 similar lines omitted"consecutive near-identical lines
linteslint, ruff, clippyeach rule with its count and example locations, worst filesrepeated occurrences of the same rule
installnpm, pip, pnpm, cargothe summary, versions, deprecations, vulnerabilities, errorsfetch and download progress
csvCSV, TSV, pipe tablesheader, 5 rows from the start, 2 from the end, row and column countsthe rows between
gitloggit log, both formatsthe 15 newest commits, the total, the authors with countsolder commits
sizeeverything (fallback)bash: the end · grep/read: the start · unknown: both endsthe rest, counted

Thirteen cuts ship today. Each one is a plain file with a shared interface, so adding your own is one file, not a fork.

Every cut follows four rules, taken from the three agents I read:

  • never return a partial line (from pi)
  • never split a UTF-16 surrogate pair (from DeepSeek Harness)
  • say exactly how much was removed: ... 15,903 characters, 401 lines omitted ... (from Codex)
  • a second pass changes nothing

Use it with DeepSeek Harness

One command:

dsh plugin --profile web add github:unclecode/toolshrink

That is the whole install. The package carries a dsh.bundle manifest, so the plugin mounts with a 50,000-character default budget on the next start. Change the budget from your own layer, ~/.dsh/cordis.patch.yml:

- id: toolshrink
  config:
    maxChars: 20000
    log: /tmp/toolshrink.log

Hacking on it instead? Clone, npm install && npm run build, and mount the adapter file by path with an insert row (see Adapter config below).

Adapter config

- insert:
    - id: toolshrink
      name: /path/to/toolshrink/adapters/harness/toolshrink.mjs
      config:
        maxChars: 50000        # cut above this many characters (default 50000)
        maxLines: 2000         # or above this many lines (default 2000)
        maxLineChars: 0        # cap single long lines, 0 = off (default 0)
        disable: [json]        # skip named cuts (default none)
        spillDir: ~/.dsh-toolshrink   # where full originals go
        log: /tmp/toolshrink.log      # one line per cut, omit for silence

The log line format: bash 64151 -> 2942 via tree+size.

Use it as a library

import { shrink, FileSpillStore } from 'toolshrink'

const out = shrink(bigText, { tool: 'bash', command: 'npm test' }, {
  budget: { maxChars: 20_000 },
  spill: new FileSpillStore({ dir: '/tmp/spills' }),  // optional
})

out.content   // the text to give the model
out.reduced   // false when the input already fit
out.strategy  // "tests", "diff+size", "size:tail", "none", ...
out.note      // one human-readable line about what happened
out.stats     // inputChars, outputChars, keptLines, droppedLines, ...

The hint (second argument) is optional and improves routing: tool picks the size direction, command helps detect test runs and diffs, path helps detect JSON and logs.

Write your own cut

A cut is one file that default-exports three members. The file name is the cut name.

// mycut.mjs
export default {
  name: 'mycut',
  // Cheap and certain. When unsure, return false: a wrong match is worse
  // than the size fallback.
  detect(text, hint) {
    return hint.command?.startsWith('kubectl') ?? false
  },
  // Return null to decline after a closer look; the next cut then tries.
  reduce(text, hint, budget) {
    const content = text.slice(0, budget.maxChars) // your real logic here
    return {
      content,
      reduced: true,
      strategy: 'mycut',
      note: 'kept the part I know matters',
      stats: {
        inputChars: text.length, inputLines: 0,
        outputChars: content.length, outputLines: 0,
      },
    }
  },
}

Use it:

import { shrink, loadReducers } from 'toolshrink'

const mine = await loadReducers('/path/to/my-cuts')   // reads the directory
shrink(text, hint, { extra: mine })                    // tried BEFORE built-ins

Or control the built-ins: { only: ['tests', 'diff'] } restricts and orders, { disable: ['json'] } skips.

Spill: nothing is lost

With a spill store, the complete original is saved before any cut, and the cut text ends with:

[full output saved as spill:bash-d63d2aebb643: directories sampled to 8 entries each]

store.load('spill:bash-d63d2aebb643') returns the original, byte for byte. Files are cleaned after 24 hours. The store is an interface; the default writes files, a host can plug its own storage.

What I saw in live use

With a 3,000-character budget, the agent got a 60,000-character find result cut down to its head. Its reply began: *"The output was truncated. Let me get a count by directory"* - it saw the omission marker, re-queried with aggregation, and answered correctly from 4,000 total characters instead of 60,000.

That is the design working: an honest marker turns a cut from silent data loss into a signal the model acts on. This is the intervention I always wanted, and now it is a YAML row.

TODO: cuts I want next

Each of these is one file with the same interface. Pick one and send a pull request.

CutRecognizesWould keep
semanticanything, given the agent's current goalthe chunks most relevant to the goal. Two stages: lexical scoring (BM25, no model needed), then optional embedding scoring for meaning beyond shared words
sqlquery results, EXPLAIN plansthe plan's expensive nodes, sampled result rows
dockerbuild and compose outputthe failing layer, the final image, dropped build chatter

The semantic cut is the interesting one: every cut above decides by SHAPE, this one would decide by RELEVANCE. It needs one extra input, a query for what the agent is working on right now, which the host adapter can pass through the hint.

Adapters for other agents

The library knows nothing about any agent. The Harness adapter is 70 lines: catch the result event, call shrink, return the replacement.

  • pi (earendil-works/pi) has an extension API with tool-result access.
  • Codex (openai/codex) has a plugin system in codex-rs/core-plugins.

Both adapters are open work. If you write one, a pull request is welcome.

License

MIT. Use it, change it, no need to ask.

Built by @unclecode, author of Crawl4AI Crawl4AI stars. Follow me on X for what I build next: x.com/unclecode.

使用前核對

安裝步驟、相容版本與授權範圍以原專案當前文件為準。Stars 和評分是快照中的導航訊號。

安裝與排錯 · 專案問題反饋

同類專案