
Sarup
io.github.PHUICMT由 GitHub 账号 PHUICMT 发布v0.2.0更新于 Oct 29, 2026
Thai-first context compression; shrinks long Thai and English text, originals retrievable.
概览
Sarup 压缩冗长的泰文与英文文本以减少 token 用量,并缓存原文,供助手按字节完整取回。
- 可以做什么
- 按指定模式与保留比例压缩文本,返回压缩结果、哈希与 token 统计
- 凭哈希从缓存中取回逐字节一致的原文
- 查看本次会话累计节省的 token
- 可选通过 PostToolUse 钩子自动压缩 Read、Bash、Grep 的大量输出
- 适用场景
- 适合处理会占满上下文窗口的长篇泰文或英文文档、日志与工具输出,尤其是需要真正压缩泰文而非原样透传的场景。提供 query 参数可保留真正相关的句子。
- 运行要求
- 以 PyPI 包 sarup 通过 stdio 在本机运行,通常用 uvx 或 pip 启动,需要 Python 3.11。semantic、abstractive、pipeline 模式可选依赖 Ollama,不可用时回退到 extractive。SARUP_DB_PATH 指定 SQLite 缓存文件,钩子取回原文时必须设置。
安装
在 SourceWeft 中
- 打开 控制台中的 Sarup,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
สรุป · Sarup
Thai-first context compression for Claude Code. An MCP server that actually shrinks Thai (50–78% fewer tokens) and caches every original so nothing is ever lost. Measured for what matters too: whether Claude still answers correctly.
สรุป means "to summarize." Headroom routes Thai through
noop(0% savings) because its whitespace tokenizer can't find Thai word boundaries. Sarup uses PyThaiNLP segmentation, so it compresses Thai as well as English — and caches every original so nothing is ever lost.
Contents
- Highlights
- Why it's safe — the two-tier guarantee
- How it works
- Tools
- Compression modes
- Measured results
- Example
- Install
- Register with Claude Code
- Auto-compression hook
- Privacy & data
- Configuration
- Project structure
- Tech stack & techniques
- Testing
- Roadmap
- License
Highlights
- 🇹🇭 Real Thai compression — PyThaiNLP
newmmword segmentation, not whitespace. - ♻️ Lossless by guarantee — every compress caches the original;
verified: trueproves a byte-for-byte round-trip. - 🎚️ Five modes: from offline 1 ms TF-IDF to a 78%-savings cascade.
- 🧠 Optional local LLM — embeddings + rewrite via Ollama, with automatic offline fallback.
- 📏 Honest metrics: a real tokenizer (tiktoken) at runtime; Claude's own tokenizer and a Thai QA eval for the published numbers (Does Claude still get it right?).
- 🕳️ Visible gaps:
[…]marks every place sentences were dropped, so Claude retrieves instead of mistaking a nearby fact for the answer. - 🔌 Content-aware — JSON compaction, log dedup, and verbatim code-fence preservation built in.
- 🛟 Can't break Claude — it's an MCP tool, not an API proxy; if the server is down the tools just go away and Claude keeps working.
Why it's safe — the two-tier guarantee
Aggressive lossy compression is safe because the original is always one sarup_retrieve(hash)
away. This is how "maximum savings" and "100% accuracy" coexist — they live in different tiers.
How it works
Two entry points feed one engine: a cheap compressed view the model reads, and a lossless retrieval store that can restore the original byte-for-byte.
- Manual — the model calls
sarup_compress/sarup_retrieveitself. - Automatic — the hook intercepts large tool outputs, caches the original to
SARUP_DB_PATH, and substitutes the compressed view + a retrieval hash. Source code is skipped; small outputs pass through untouched.
Tools
sarup_compress arguments
Compression modes
¹ Measured on a 10-sentence Thai paragraph (522 tokens), rewrite model gemma4:12b. Every mode
stays 100% recoverable via the store; Ollama modes degrade gracefully to extractive when the
backend is down. (gemma4:e4b: pipeline 82.2%; June 2026, gemma3:12b: 88.1%.)
Extractive and semantic output is a verbatim subset of the input sentences, with […] on its
own line wherever sentences were dropped. Sentences carrying specifics (numbers, Thai digits,
identifiers like X-Api-Key) score higher than general statements, since those are what
questions ask about.
Measured results
Token counts via tiktoken cl100k_base. That is OpenAI's tokenizer and undercounts Claude,
most of all on Thai; bench\benchmark.py --claude adds a column from Claude's own tokenizer
(Anthropic count_tokens, needs an API key).
Does Claude still get it right?
Fewer tokens only help if the facts survive. bench\eval_qa.py compresses 8 Thai documents
(incident report, meeting notes, API docs, HR policy, product spec, support chat, README, sales
report; half line-per-sentence, half dense paragraphs) and asks Claude Opus 5.5 32 questions
from the compressed view alone, graded deterministically:
(gemma4:e4b scored the same: abstractive 91%, pipeline 59%, wrong 0.)
- wrong = 0 is the safety property: when a fact was dropped, Claude said so (abstain) and
in real use would call
sarup_retrieve. It did not guess from what was left. - abstain is the real cost of blind compression: about a third of specific questions need a
retrieval round-trip at
0.5. Know what you're looking for? Pass it asquery(+qrow). - abstractive keeps the most facts per token (91% at 42% saved) because a rewrite can keep
every number while dropping words; extraction can only drop whole sentences. It costs seconds
per document, so use it through
sarup_compress, not the hook. - In both evals no paraphrase changed a fact into a wrong one, but 8 documents can't prove a
rewrite never will, which is why the original stays one
sarup_retrieveaway. - Token counts here are Claude's own (from the answer calls' usage) and include the ~40-token
[sarup: …]footer, which weighs heavily on these short (~570-token) documents and fades on the large outputs the hook actually compresses. - 8 documents is a small sample; differences of a couple of questions between modes are noise.
Before the fixes this eval drove (Oct 2026): dense Thai paragraphs were not compressed at all
(the sentence splitter's model wasn't installed), extractive:0.5 answered 59% with one
confident wrong answer, and semantic:0.5 47%.
Example
A real sarup_compress call on a Thai paragraph (mode="auto", Ollama up → semantic):
The model keeps working on the 154-token view; the full 518-token original is one call away:
Install
As a Claude Code plugin (easiest)
Needs uv: the plugin runs Sarup through uvx, which fetches
Python and the dependencies on first use. Nothing to clone. In Claude Code:
That installs the MCP server, the auto-compression hook and the /sarup:sarup-setup skill.
The cache lives in the plugin's data directory, so it survives plugin updates. The first start
takes a few seconds while uvx builds the environment. From a shell instead:
claude plugin marketplace add PHUICMT/sarup, then claude plugin install sarup@sarup.
Ollama is optional. Without it everything works offline: the hook and the default
extractive mode never touch it, and asking for semantic, abstractive or pipeline
falls back to extractive with a setup field that names what to install. sarup_stats
shows what is available, and /sarup:sarup-setup walks through adding
Ollama and the models below.
From PyPI (any MCP client)
The package is sarup on PyPI. With uv, nothing to install
by hand; point any MCP client at uvx sarup:
In Claude Code without the plugin: claude mcp add sarup -s user -- uvx sarup. The hook is
uvx --from sarup sarup-hook --db <same file as SARUP_DB_PATH>. pip install sarup works
too and puts sarup and sarup-hook on PATH.
From a clone
One command (creates the venv, installs everything, registers the MCP server for all projects, idempotent):
Tip:
-All/--allinstalls a global/sarup-setupskill, so on any other machine you can just type/sarup-setupin Claude Code and it walks through the install. (Or runscripts/install-skill.ps1/install-skill.shon its own.)
Uninstall just as cleanly (only removes what Sarup added; -Purge/--purge also
deletes the venv + cache):
Manual install
Optional local-LLM modes (semantic / abstractive / pipeline) need Ollama:
Register with Claude Code
One-command setup (recommended). Detects this machine's paths, probes Ollama
(picks the best mode + models), and merges into .mcp.json / .claude/settings.json
without clobbering anything already there (a .bak is written first):
- No Ollama? It configures offline
extractivemode — still fully works. - Ollama up? It auto-selects
nomic-embed-text(semantic) + the best installed rewrite model (gemma4:12b→gemma4:e4b→gemma3:12b→qwen3) forsarup_compress. The hook staysextractiveeither way (it runs on every tool call).--pullfetches any missing models. - Idempotent — safe to re-run;
--globalwrites to~/.claudeinstead.
Manual — or add it yourself to your MCP config (e.g. .mcp.json or ~/.claude.json).
Replace <SARUP_DIR> with the absolute path where you cloned this repo (the installer
above fills these in for you):
On Linux/macOS the interpreter is
<SARUP_DIR>/.venv/bin/python.
Or run it directly over stdio:
Auto-compression hook
Skip manual tool calls entirely: install the PostToolUse hook and large Read/Bash/Grep
outputs are compressed before they enter context, with the original cached for retrieval.
Source-code reads are skipped for safety. Full setup in hooks/README.md.
Fixed in October 2026. Earlier versions returned the compressed text as a plain string. Claude Code only accepts
updatedToolOutputin the tool's own shape ({stdout, stderr, …}for Bash,{type, file: {content, …}}for Read) and silently dropped the string, so the hook never applied on any surface. It now keeps each tool's shape; verified on the CLI (2.1.289): the model receives the compressed view and the retrieval hash. To see what the hook does on your build, setSARUP_HOOK_LOGto a file path (one JSON line per call).
The plugin wires this up for you. From a clone, replace <SARUP_DIR> with your clone path, or
run install.py --with-hook:
Privacy & data
To guarantee recovery, Sarup caches the original content in the store. Two things to know:
- With
SARUP_DB_PATHset, originals are written to that SQLite file in plaintext (no encryption). Treat it like a cache of whatever you compressed. - If you compress tool outputs that contain secrets (e.g. a
.envdump or credentials in a log), those land in the cache too. The auto-hook skips source-code/config file reads, butBashoutput is fair game — review what you point it at.
*.db is git-ignored, so the cache never gets committed. For zero on-disk
footprint, leave SARUP_DB_PATH unset (memory-only; the MCP server then loses
the cache on restart, and the hook will not substitute — see the hook docs).
Configuration
Project structure
Tech stack & techniques
Python 3.11 · MCP · PyThaiNLP newmm · tiktoken · Ollama (optional) · SQLite · hatchling · pytest.
The technique behind each mode — TF-IDF scoring, embedding centrality, cascade pipeline, content routing, and graceful degradation — is documented in STACK.md.
Testing
The suite covers Thai NLP, the MCP tool contracts, every mode (including Ollama-fallback paths), the roundtrip-verify guarantee, and the auto-compression hook (incl. cross-process retrieval).
Quality is measured separately, since it needs a model: bench\eval_qa.py (see
Does Claude still get it right?). It runs on the local
claude CLI by default, or --backend api with an Anthropic API key; --dry-run and
--limit keep a check cheap; a full run is ~170 Claude calls.
Releasing
- Bump
versioninpyproject.tomlandserver.json(both places in it). - Push a matching tag:
git tag v0.2.0 && git push origin v0.2.0. Thepublishworkflow tests, builds and uploads to PyPI through trusted publishing (no token). - List the release in the MCP registry:
mcp-publisher login github, thenmcp-publisher publish(readsserver.json; themcp-namecomment at the top of this README proves the PyPI package belongs to it).
The plugin needs none of this: it installs from the repo and updates with each commit.
Roadmap
- Grow the QA eval past 8 documents (long tool outputs, logs, mixed code) before
changing defaults such as
auto→ semantic on the strength of it. - Move to
mcp2.x (pinned<2for now: 2.x droppedServer.list_tools). - Optional Typhoon 2.1 abstractive (blocked on an Ollama template fix).
- Per-content adaptive
target_ratio. - Published PyPI package (
sarup) and MCP registry listing (io.github.PHUICMT/sarup). - Installable as a Claude Code plugin.
License
MIT
来源:README.md,提交 abfc18c
工具
0版本历史
1- v0.2.0最新Oct 29, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分