context-compress 2026.3.21 → 2026.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +258 -44
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -10
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/filter.d.ts +52 -0
- package/dist/cli/filter.d.ts.map +1 -0
- package/dist/cli/filter.js +200 -0
- package/dist/cli/filter.js.map +1 -0
- package/dist/cli/index.d.ts +8 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +19 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lite.d.ts +15 -0
- package/dist/cli/lite.d.ts.map +1 -0
- package/dist/cli/lite.js +37 -0
- package/dist/cli/lite.js.map +1 -0
- package/dist/cli/setup.d.ts +23 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +122 -21
- package/dist/cli/setup.js.map +1 -1
- package/dist/executor.d.ts +7 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +51 -4
- package/dist/executor.js.map +1 -1
- package/dist/filters.d.ts +52 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +719 -0
- package/dist/filters.js.map +1 -0
- package/dist/hooks/pretooluse.js +57 -0
- package/dist/hooks/pretooluse.js.map +1 -1
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +11 -0
- package/dist/network.js.map +1 -1
- package/dist/server.bundle.mjs +1333 -619
- package/dist/server.bundle.mjs.map +4 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +44 -610
- package/dist/server.js.map +1 -1
- package/dist/stats.d.ts +7 -1
- package/dist/stats.d.ts.map +1 -1
- package/dist/stats.js +65 -0
- package/dist/stats.js.map +1 -1
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +15 -2
- package/dist/store.js.map +1 -1
- package/dist/tools/batch-execute.d.ts +4 -0
- package/dist/tools/batch-execute.d.ts.map +1 -0
- package/dist/tools/batch-execute.js +75 -0
- package/dist/tools/batch-execute.js.map +1 -0
- package/dist/tools/context.d.ts +17 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +2 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/discover.d.ts +4 -0
- package/dist/tools/discover.d.ts.map +1 -0
- package/dist/tools/discover.js +65 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/execute-file.d.ts +4 -0
- package/dist/tools/execute-file.d.ts.map +1 -0
- package/dist/tools/execute-file.js +66 -0
- package/dist/tools/execute-file.js.map +1 -0
- package/dist/tools/execute.d.ts +4 -0
- package/dist/tools/execute.d.ts.map +1 -0
- package/dist/tools/execute.js +54 -0
- package/dist/tools/execute.js.map +1 -0
- package/dist/tools/fetch-and-index.d.ts +4 -0
- package/dist/tools/fetch-and-index.d.ts.map +1 -0
- package/dist/tools/fetch-and-index.js +91 -0
- package/dist/tools/fetch-and-index.js.map +1 -0
- package/dist/tools/index-content.d.ts +4 -0
- package/dist/tools/index-content.d.ts.map +1 -0
- package/dist/tools/index-content.js +85 -0
- package/dist/tools/index-content.js.map +1 -0
- package/dist/tools/search.d.ts +4 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +57 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/stats.d.ts +4 -0
- package/dist/tools/stats.d.ts.map +1 -0
- package/dist/tools/stats.js +10 -0
- package/dist/tools/stats.js.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/util/auto-mode.d.ts +40 -0
- package/dist/util/auto-mode.d.ts.map +1 -0
- package/dist/util/auto-mode.js +181 -0
- package/dist/util/auto-mode.js.map +1 -0
- package/dist/util/fetch-code.d.ts +10 -0
- package/dist/util/fetch-code.d.ts.map +1 -0
- package/dist/util/fetch-code.js +87 -0
- package/dist/util/fetch-code.js.map +1 -0
- package/dist/util/intent-filter.d.ts +17 -0
- package/dist/util/intent-filter.d.ts.map +1 -0
- package/dist/util/intent-filter.js +28 -0
- package/dist/util/intent-filter.js.map +1 -0
- package/dist/util/label.d.ts +4 -0
- package/dist/util/label.d.ts.map +1 -0
- package/dist/util/label.js +14 -0
- package/dist/util/label.js.map +1 -0
- package/dist/util/path.d.ts +8 -0
- package/dist/util/path.d.ts.map +1 -0
- package/dist/util/path.js +21 -0
- package/dist/util/path.js.map +1 -0
- package/dist/util/stream-compress.d.ts +36 -0
- package/dist/util/stream-compress.d.ts.map +1 -0
- package/dist/util/stream-compress.js +104 -0
- package/dist/util/stream-compress.js.map +1 -0
- package/dist/util/version.d.ts +2 -0
- package/dist/util/version.d.ts.map +1 -0
- package/dist/util/version.js +15 -0
- package/dist/util/version.js.map +1 -0
- package/docs/token-reduction-report.md +164 -88
- package/hooks/pretooluse.mjs +38 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -2,22 +2,75 @@
|
|
|
2
2
|
|
|
3
3
|
# context-compress
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Stop drowning your AI agent in shell output.**
|
|
6
|
+
Compress tool output before it hits the context window — through an MCP server, a drop-in CLI, or both.
|
|
6
7
|
|
|
7
|
-
[](https://github.com/Open330/context-compress/actions)
|
|
8
|
-
[](https://github.com/Open330/context-compress/actions/workflows/ci.yml)
|
|
9
|
+
[](https://www.npmjs.com/package/context-compress)
|
|
10
|
+
[](https://nodejs.org)
|
|
9
11
|
[](LICENSE)
|
|
10
12
|
[](tsconfig.json)
|
|
13
|
+
[](#contributing)
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[Quickstart for Agents](#quickstart-for-agents) · [Getting Started](#getting-started) · [How It Works](#how-it-works) · [Token Reduction](#token-reduction) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
|
|
15
|
+
[Quickstart](#quickstart) · [Compression Modes](#compression-modes) · [vs RTK](#head-to-head-with-rtk) · [How It Works](#how-it-works) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
19
|
+
<table align="center">
|
|
20
|
+
<tr>
|
|
21
|
+
<td align="center" width="25%">
|
|
22
|
+
|
|
23
|
+
**93%**
|
|
24
|
+
<br>token reduction
|
|
25
|
+
<br><sub>aggressive mode</sub>
|
|
26
|
+
|
|
27
|
+
</td>
|
|
28
|
+
<td align="center" width="25%">
|
|
29
|
+
|
|
30
|
+
**+10.5pp**
|
|
31
|
+
<br>over RTK
|
|
32
|
+
<br><sub>same commands</sub>
|
|
33
|
+
|
|
34
|
+
</td>
|
|
35
|
+
<td align="center" width="25%">
|
|
36
|
+
|
|
37
|
+
**4 modes**
|
|
38
|
+
<br>incl. LLM-judged
|
|
39
|
+
<br><sub>auto • aggressive • balanced • conservative</sub>
|
|
40
|
+
|
|
41
|
+
</td>
|
|
42
|
+
<td align="center" width="25%">
|
|
43
|
+
|
|
44
|
+
**8 MCP tools**
|
|
45
|
+
<br>+ standalone CLI
|
|
46
|
+
<br><sub>RTK-compatible wrap</sub>
|
|
47
|
+
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
</table>
|
|
51
|
+
|
|
18
52
|
---
|
|
19
53
|
|
|
20
|
-
## Quickstart
|
|
54
|
+
## Quickstart
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# 1. Install
|
|
58
|
+
npm install -g context-compress
|
|
59
|
+
|
|
60
|
+
# 2. One-line setup — registers the MCP server, installs the hook,
|
|
61
|
+
# enables transparent Bash compression
|
|
62
|
+
context-compress setup --auto
|
|
63
|
+
|
|
64
|
+
# 3. (optional) Pick a mode for the session
|
|
65
|
+
export CONTEXT_COMPRESS_MODE=balanced # or: aggressive, conservative, auto
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
That's it. Restart Claude Code and shell output is now compressed before it enters context.
|
|
69
|
+
|
|
70
|
+
> **Prefer no MCP at all?** `context-compress wrap "<cmd>"` compresses any shell command's output — drop-in for [RTK](https://github.com/rtk-ai/rtk). See [CLI](#cli).
|
|
71
|
+
|
|
72
|
+
<details>
|
|
73
|
+
<summary><b>Quickstart for AI agents</b> — paste this prompt and your agent will install it</summary>
|
|
21
74
|
|
|
22
75
|
<div><img src="https://quickstart-for-agents.vercel.app/api/header.svg?theme=claude-code&title=context-compress&lang=Agents&mascot=thinking" width="100%" /></div>
|
|
23
76
|
|
|
@@ -27,7 +80,7 @@ Raw data stays in sandboxed subprocesses, only concise summaries enter your cont
|
|
|
27
80
|
Saves ~99% of tokens on large outputs while keeping everything searchable via FTS5.
|
|
28
81
|
|
|
29
82
|
npm install -g context-compress
|
|
30
|
-
|
|
83
|
+
context-compress setup --auto
|
|
31
84
|
context-compress doctor
|
|
32
85
|
|
|
33
86
|
More info: https://github.com/Open330/context-compress
|
|
@@ -35,6 +88,8 @@ More info: https://github.com/Open330/context-compress
|
|
|
35
88
|
|
|
36
89
|
<div><img src="https://quickstart-for-agents.vercel.app/api/footer.svg?theme=claude-code&project=context-compress" width="100%" /></div>
|
|
37
90
|
|
|
91
|
+
</details>
|
|
92
|
+
|
|
38
93
|
---
|
|
39
94
|
|
|
40
95
|
## Why?
|
|
@@ -49,6 +104,11 @@ Before: git log --oneline -100 → 8.2KB into context
|
|
|
49
104
|
After: execute("git log ...") → 0.3KB summary + full data searchable in FTS5
|
|
50
105
|
```
|
|
51
106
|
|
|
107
|
+
It works in two modes that compose freely:
|
|
108
|
+
|
|
109
|
+
- **MCP server** — registers as a Claude Code MCP server with 8 tools (`execute`, `search`, `batch_execute`, `fetch_and_index`, `index`, `execute_file`, `stats`, `discover`). Agents call them directly when output would be large.
|
|
110
|
+
- **Standalone CLI** — `context-compress wrap "<cmd>"` runs any shell command and pipes the output through the same compression pipeline. Drop-in for [RTK](https://github.com/rtk-ai/rtk) and friends. The PreToolUse hook can route `Bash` calls through it transparently when `CONTEXT_COMPRESS_FILTER_BASH=1`.
|
|
111
|
+
|
|
52
112
|
> Based on [context-mode](https://github.com/mksglu/claude-context-mode) by Mert Koseoğlu — rewritten in TypeScript with security hardening, architectural improvements, and better DX.
|
|
53
113
|
|
|
54
114
|
---
|
|
@@ -61,7 +121,15 @@ After: execute("git log ...") → 0.3KB summary + full data searchable in FT
|
|
|
61
121
|
npm install -g context-compress
|
|
62
122
|
```
|
|
63
123
|
|
|
64
|
-
###
|
|
124
|
+
### One-line setup
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
context-compress setup --auto
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Writes `~/.claude/settings.json` for you: registers the MCP server, installs the PreToolUse hook, enables transparent Bash compression. Idempotent — re-running with the same paths makes zero changes. Preserves any unrelated user settings.
|
|
131
|
+
|
|
132
|
+
### Manual setup
|
|
65
133
|
|
|
66
134
|
```bash
|
|
67
135
|
claude mcp add context-compress -- node $(which context-compress)
|
|
@@ -115,7 +183,7 @@ context-compress doctor
|
|
|
115
183
|
└─────────────────────────────────────────────────────────┘
|
|
116
184
|
```
|
|
117
185
|
|
|
118
|
-
###
|
|
186
|
+
### 8 MCP Tools
|
|
119
187
|
|
|
120
188
|
| Tool | What it does |
|
|
121
189
|
|:-----|:-------------|
|
|
@@ -125,7 +193,8 @@ context-compress doctor
|
|
|
125
193
|
| **`search`** | BM25 search with Porter stemming → trigram → fuzzy fallback. |
|
|
126
194
|
| **`fetch_and_index`** | Fetch URL → HTML-to-markdown → auto-index. Preview only in context. |
|
|
127
195
|
| **`batch_execute`** | Run N commands + search in ONE call. Replaces 30+ tool calls. |
|
|
128
|
-
| **`stats`** |
|
|
196
|
+
| **`stats`** | Session + cumulative statistics: bytes saved, tokens avoided, savings ratio. |
|
|
197
|
+
| **`discover`** | Lists indexed sources, top searchable terms, and suggests next actions. |
|
|
129
198
|
|
|
130
199
|
### Supported Languages
|
|
131
200
|
|
|
@@ -135,6 +204,68 @@ context-compress doctor
|
|
|
135
204
|
|
|
136
205
|
---
|
|
137
206
|
|
|
207
|
+
## Compression Modes
|
|
208
|
+
|
|
209
|
+
context-compress offers four compression modes that trade fidelity for compactness. Pass `--mode` to the CLI, set `CONTEXT_COMPRESS_MODE` in your environment, or let the default (`balanced`) just work.
|
|
210
|
+
|
|
211
|
+
| Mode | Strategy | Use when |
|
|
212
|
+
|:--|:--|:--|
|
|
213
|
+
| `conservative` | ANSI strip only — preserves every byte of meaningful content | You need full fidelity, debugging output, archival logs |
|
|
214
|
+
| `balanced` *(default)* | Strip noise (progress bars, deprecation warnings, hint lines) — keep metadata (commit bodies, file dates, full test failures) | Day-to-day agent work where context might be re-read |
|
|
215
|
+
| `aggressive` | Drop metadata too — git log → oneline, ls -la → name+size, find lower threshold, grep grouped | Maximum token savings; agent will rarely need the dropped detail |
|
|
216
|
+
| `auto` | An LLM (Anthropic API or `claude -p`) picks one of the above per command, based on a 500-byte sample of the output. Decisions cached for 24h | You don't want to think about it — let the model judge per output |
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# CLI flag (per-call override)
|
|
220
|
+
context-compress wrap --mode aggressive "git log -50"
|
|
221
|
+
|
|
222
|
+
# Env var (set once for the session)
|
|
223
|
+
export CONTEXT_COMPRESS_MODE=aggressive
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The PreToolUse hook also forwards `CONTEXT_COMPRESS_MODE` automatically when wrapping Bash commands, so agents transparently get whatever mode you've configured.
|
|
227
|
+
|
|
228
|
+
### Head-to-head with [RTK](https://github.com/rtk-ai/rtk)
|
|
229
|
+
|
|
230
|
+
Reproduce locally:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
git clone https://github.com/rtk-ai/rtk /tmp/rtk && (cd /tmp/rtk && cargo build --release)
|
|
234
|
+
RTK_BIN=/tmp/rtk/target/release/rtk tsx scripts/benchmark-vs-rtk.ts
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Result on this repository (RTK 0.39.0 vs context-compress 2026.5.0):
|
|
238
|
+
|
|
239
|
+
| Command | Raw | RTK | CC `conservative` | CC `balanced` | CC `aggressive` | CC `auto` (LLM) |
|
|
240
|
+
|:--|--:|--:|--:|--:|--:|--:|
|
|
241
|
+
| `git status` | 577 B | 241 B (58%) | 577 B (0%) | 375 B (35%) | **187 B (68%)** | balanced (35%) |
|
|
242
|
+
| `git log -10` (full) | 21.3 KB | 3.2 KB (85%) | 21.3 KB (0%) | 4.6 KB (79%) | **947 B (96%)** | balanced (79%) |
|
|
243
|
+
| `git log -50` (full) | 36.9 KB | 10.1 KB (73%) | 36.9 KB (0%) | 12.3 KB (67%) | **3.2 KB (91%)** | balanced (67%) |
|
|
244
|
+
| `git diff --stat` | 425 B | 424 B (0%) | 425 B (0%) | 425 B (0%) | 425 B (0%) | balanced (0%) |
|
|
245
|
+
| `ls src/` | 149 B | 229 B (-54%) | 149 B (0%) | 149 B (0%) | 149 B (0%) | conservative (0%) |
|
|
246
|
+
| `ls -laR src/` | 3.8 KB | **229 B (94%)** | 3.8 KB (0%) | 3.1 KB (19%) | 877 B (78%) | aggressive (78%) |
|
|
247
|
+
| `find *.ts` | 1.0 KB | 589 B (44%) | 1.0 KB (0%) | **183 B (83%)** | **183 B (83%)** | aggressive (83%) |
|
|
248
|
+
| `npm test` | 21.8 KB | 114 B (99%) | 16.7 KB (24%) | **120 B (99%)** | **120 B (99%)** | balanced (99%) |
|
|
249
|
+
| **Overall** (byte-weighted) | **85.9 KB** | 15.0 KB (82.5%) | 80.8 KB (6.0%) | 21.2 KB (75.4%) | **6.0 KB (93.0%)** | 19.0 KB (77.9%) |
|
|
250
|
+
|
|
251
|
+
Three things to take from this table:
|
|
252
|
+
|
|
253
|
+
1. **`balanced` is competitive on its own.** The default mode hits ~75% reduction without dropping any metadata — agents get full commit headers, file perms/dates, and complete test failure detail. Only 7pp behind RTK while making a different fidelity trade-off.
|
|
254
|
+
2. **`aggressive` decisively wins on raw compression** — 93.0%, beating RTK by 10.5pp. Pick this when you want maximum token savings and the agent will rarely re-read the dropped detail.
|
|
255
|
+
3. **`auto` lets the model pick.** Per-command LLM judgment landed at 77.9% overall — between balanced and aggressive. The interesting result is *what* it picked: `balanced` for git/test outputs (where commit bodies and failure detail matter), `aggressive` for `ls -laR` and `find` (where the question is "what's there?", not "show me everything"), `conservative` for tiny outputs where compression is pointless.
|
|
256
|
+
|
|
257
|
+
Aggressive mode covers a wider command surface than the table above hints — it also handles `df` (drops pseudo-filesystems), `du` (top-N by size), `ps aux` (PID/%CPU/%MEM/CMD only, drops kernel threads), `npm ls` (strips tree-drawing chars + `deduped`/`extraneous` markers), and `grep`/`rg` (groups by file, truncates long lines).
|
|
258
|
+
|
|
259
|
+
What balanced now does (over conservative):
|
|
260
|
+
- `ls -l*` drops `total N`, `.`/`..` entries (universal noise) but keeps perms/dates
|
|
261
|
+
- `git log` keeps headers + first 3 body lines per commit, replacing the rest with `[+N lines omitted]`
|
|
262
|
+
- `find` / `ls -R` summarizes per-directory once output exceeds 20 entries
|
|
263
|
+
- Generic dedup/progress/group runs at 5KB instead of 10KB
|
|
264
|
+
|
|
265
|
+
> RTK has a single fixed compression strategy — comparable to context-compress `aggressive`. context-compress lets the agent choose: reach for `aggressive` when the question is "what changed", `balanced` when the question is "explain why".
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
138
269
|
## Token Reduction
|
|
139
270
|
|
|
140
271
|
context-compress achieves **99.2% token reduction** across a typical 12-operation coding session.
|
|
@@ -200,6 +331,18 @@ CONTEXT_COMPRESS_BLOCK_WEBFETCH=0
|
|
|
200
331
|
# Disable Read/Grep nudges
|
|
201
332
|
CONTEXT_COMPRESS_NUDGE_READ=0
|
|
202
333
|
CONTEXT_COMPRESS_NUDGE_GREP=0
|
|
334
|
+
|
|
335
|
+
# Compression mode: conservative | balanced (default) | aggressive | auto
|
|
336
|
+
CONTEXT_COMPRESS_MODE=balanced
|
|
337
|
+
|
|
338
|
+
# Auto mode prefers the Anthropic API when this is set (faster than `claude -p` fallback)
|
|
339
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
340
|
+
|
|
341
|
+
# RTK-style transparent Bash wrapping (default: off)
|
|
342
|
+
CONTEXT_COMPRESS_FILTER_BASH=1
|
|
343
|
+
|
|
344
|
+
# Override path to the context-compress binary used by the hook
|
|
345
|
+
CONTEXT_COMPRESS_BIN=/usr/local/bin/context-compress
|
|
203
346
|
```
|
|
204
347
|
|
|
205
348
|
### Config File
|
|
@@ -220,12 +363,24 @@ Create `.context-compress.json` in your project root or home directory:
|
|
|
220
363
|
## CLI
|
|
221
364
|
|
|
222
365
|
```bash
|
|
223
|
-
context-compress
|
|
224
|
-
context-compress setup
|
|
225
|
-
context-compress
|
|
226
|
-
context-compress
|
|
366
|
+
context-compress # Start MCP server (stdio)
|
|
367
|
+
context-compress setup # Detect runtimes, show install instructions
|
|
368
|
+
context-compress setup --auto # One-line: write ~/.claude/settings.json
|
|
369
|
+
context-compress init --auto # Alias for setup --auto
|
|
370
|
+
context-compress doctor # Diagnose: runtimes, hooks, FTS5, version
|
|
371
|
+
context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
|
|
372
|
+
|
|
373
|
+
# RTK-style transparent compression — use anywhere, agent doesn't need MCP
|
|
374
|
+
context-compress wrap "npm test" # default = balanced
|
|
375
|
+
context-compress wrap --mode aggressive "git log -50" # max compression
|
|
376
|
+
context-compress wrap --stream "tail -f /var/log/app.log" # line-by-line for long-running cmds
|
|
377
|
+
context-compress filter --cmd "git push" < captured.log # pipe filter
|
|
227
378
|
```
|
|
228
379
|
|
|
380
|
+
### Bash auto-wrap (transparent mode)
|
|
381
|
+
|
|
382
|
+
Set `CONTEXT_COMPRESS_FILTER_BASH=1` and the PreToolUse hook will route output-heavy `Bash` calls through `context-compress wrap` automatically — the agent doesn't need to call `execute()` to benefit. Combine with `CONTEXT_COMPRESS_MODE=aggressive` for maximum compression.
|
|
383
|
+
|
|
229
384
|
### Doctor Output Example
|
|
230
385
|
|
|
231
386
|
```
|
|
@@ -235,9 +390,10 @@ context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
|
|
|
235
390
|
[PASS] Language coverage: 7/11 (64%)
|
|
236
391
|
[PASS] Server test: OK
|
|
237
392
|
[PASS] PreToolUse hook configured
|
|
393
|
+
[PASS] Hook integrity: SHA-256 verified (a3f1c8d2e4...)
|
|
238
394
|
[PASS] FTS5 / better-sqlite3 works
|
|
239
395
|
|
|
240
|
-
Version: v2026.
|
|
396
|
+
Version: v2026.5.0
|
|
241
397
|
All checks passed.
|
|
242
398
|
```
|
|
243
399
|
|
|
@@ -248,46 +404,79 @@ context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
|
|
|
248
404
|
```
|
|
249
405
|
context-compress/
|
|
250
406
|
├── src/
|
|
251
|
-
│ ├── index.ts #
|
|
252
|
-
│ ├── server.ts #
|
|
253
|
-
│ ├── executor.ts # SubprocessExecutor
|
|
254
|
-
│ ├──
|
|
255
|
-
│ ├──
|
|
256
|
-
│ ├──
|
|
407
|
+
│ ├── index.ts # MCP server entry
|
|
408
|
+
│ ├── server.ts # Wires deps, registers tools (132 lines, was 845)
|
|
409
|
+
│ ├── executor.ts # SubprocessExecutor + ANSI/dedup pipeline
|
|
410
|
+
│ ├── filters.ts # Command-aware filters (git, npm, ls, find, ps, ...)
|
|
411
|
+
│ ├── store.ts # ContentStore (FTS5 + BM25 + Porter + trigram + Levenshtein)
|
|
412
|
+
│ ├── network.ts # SSRF / DNS rebinding protection
|
|
413
|
+
│ ├── stats.ts # Session + cumulative session tracker
|
|
414
|
+
│ ├── config.ts # Config: ENV → file → defaults
|
|
257
415
|
│ ├── snippet.ts # FTS5 snippet extraction
|
|
258
|
-
│ ├──
|
|
416
|
+
│ ├── logger.ts # Debug logger
|
|
259
417
|
│ ├── types.ts # Shared types
|
|
418
|
+
│ ├── utils.ts # detectInjectionPatterns, limitConcurrency, formatBytes
|
|
260
419
|
│ ├── runtime/
|
|
420
|
+
│ │ ├── index.ts # Parallel runtime detection + registry
|
|
261
421
|
│ │ ├── plugin.ts # LanguagePlugin interface
|
|
262
|
-
│ │
|
|
263
|
-
│
|
|
422
|
+
│ │ └── languages/ # 11 language plugins (js, ts, py, sh, rb, go, rs, php, pl, r, ex)
|
|
423
|
+
│ ├── tools/ # MCP tool handlers (one file per tool)
|
|
424
|
+
│ │ ├── context.ts # Shared ToolContext interface
|
|
425
|
+
│ │ ├── execute.ts
|
|
426
|
+
│ │ ├── execute-file.ts
|
|
427
|
+
│ │ ├── index-content.ts
|
|
428
|
+
│ │ ├── search.ts
|
|
429
|
+
│ │ ├── fetch-and-index.ts
|
|
430
|
+
│ │ ├── batch-execute.ts
|
|
431
|
+
│ │ ├── stats.ts
|
|
432
|
+
│ │ └── discover.ts
|
|
433
|
+
│ ├── util/ # Pure utilities (extracted from server.ts for testability)
|
|
434
|
+
│ │ ├── path.ts # isWithinProject (path-traversal safe)
|
|
435
|
+
│ │ ├── fetch-code.ts # buildFetchCode (HTML→md sandbox script)
|
|
436
|
+
│ │ ├── intent-filter.ts # createIntentFilter factory
|
|
437
|
+
│ │ ├── label.ts # compactLabel (compression levels)
|
|
438
|
+
│ │ ├── version.ts # getVersion (deduped across CLI commands)
|
|
439
|
+
│ │ ├── stream-compress.ts# Line-by-line StreamCompressor for `wrap --stream`
|
|
440
|
+
│ │ └── auto-mode.ts # LLM-driven mode selection (Anthropic API + claude CLI)
|
|
264
441
|
│ ├── hooks/
|
|
265
|
-
│ │ └── pretooluse.ts # PreToolUse hook (
|
|
442
|
+
│ │ └── pretooluse.ts # PreToolUse hook (curl/Bash/Read/Grep/WebFetch/Task)
|
|
266
443
|
│ └── cli/
|
|
267
|
-
│ ├── index.ts # CLI
|
|
268
|
-
│ ├──
|
|
269
|
-
│ ├──
|
|
270
|
-
│
|
|
444
|
+
│ ├── index.ts # CLI dispatcher
|
|
445
|
+
│ ├── lite.ts # Single-binary entry (filter+wrap only, no MCP)
|
|
446
|
+
│ ├── filter.ts # `filter` (stdin) + `wrap` (spawn) commands
|
|
447
|
+
│ ├── setup.ts # `setup` / `init` — interactive + --auto
|
|
448
|
+
│ ├── doctor.ts # `doctor` — diagnostics
|
|
449
|
+
│ └── uninstall.ts # `uninstall` — clean removal
|
|
271
450
|
├── tests/
|
|
272
|
-
│ ├── unit/ #
|
|
451
|
+
│ ├── unit/ # 18 unit test files (213 tests, all passing)
|
|
273
452
|
│ └── integration/ # 3 integration test files
|
|
274
|
-
├──
|
|
275
|
-
│
|
|
453
|
+
├── scripts/
|
|
454
|
+
│ ├── benchmark.ts # Synthetic compression benchmark
|
|
455
|
+
│ ├── benchmark-real.ts # Real-command benchmark on this repo
|
|
456
|
+
│ └── benchmark-vs-rtk.ts # Head-to-head vs RTK with --auto support
|
|
457
|
+
├── hooks/ # Pre-built hook bundle (shipped in npm package)
|
|
276
458
|
├── skills/ # Slash command definitions
|
|
277
|
-
|
|
459
|
+
├── docs/ # Token reduction report + architecture docs
|
|
460
|
+
└── dist/ # Compiled output (build artifact)
|
|
278
461
|
```
|
|
279
462
|
|
|
463
|
+
> `server.ts` is now thin (132 lines) — it constructs deps, builds a `ToolContext`, registers the 8 tool modules, and wires shutdown. All tool handlers live under `src/tools/`, all reusable helpers under `src/util/`.
|
|
464
|
+
|
|
280
465
|
---
|
|
281
466
|
|
|
282
467
|
## Security
|
|
283
468
|
|
|
284
469
|
| Threat | Mitigation |
|
|
285
470
|
|:-------|:-----------|
|
|
286
|
-
| Credential leakage | `passthroughEnvVars` defaults to `[]` — zero env vars passed unless opted in |
|
|
287
|
-
| Shell injection
|
|
288
|
-
|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
471
|
+
| Credential leakage | `passthroughEnvVars` defaults to `[]` — zero env vars passed to subprocesses unless opted in |
|
|
472
|
+
| Shell injection | `execFileSync` with array arguments throughout — no string interpolation into shells |
|
|
473
|
+
| SSRF / private-IP fetch | `fetch_and_index` blocks RFC1918, link-local, loopback, IPv4-mapped IPv6 (incl. hex form `::ffff:HHHH:HHHH`), CGNAT |
|
|
474
|
+
| DNS rebinding (TOCTOU) | `resolveAndValidate` + URL pinning to the resolved IP with original `Host` header preserved |
|
|
475
|
+
| Path traversal | `isWithinProject` uses `realpathSync` to defeat symlink escapes; falls back to string-prefix for not-yet-existing paths |
|
|
476
|
+
| Hook self-modification | Hooks are read-only — no `fs.writeFileSync` in `src/hooks/`. Hook integrity SHA-256 verified by `doctor` |
|
|
477
|
+
| Arbitrary code execution | No `upgrade` command — no `git clone` or `npm install` at runtime. Setup writes only to `~/.claude/settings.json` |
|
|
478
|
+
| Silent failures | `CONTEXT_COMPRESS_DEBUG=1` surfaces all catch-block errors to stderr |
|
|
479
|
+
| Subprocess sandboxing | OS-level sandboxing not enforced (by design for the MCP trust model). See [SECURITY.md](SECURITY.md) for the full trust model. |
|
|
291
480
|
|
|
292
481
|
---
|
|
293
482
|
|
|
@@ -297,11 +486,34 @@ context-compress/
|
|
|
297
486
|
git clone https://github.com/Open330/context-compress
|
|
298
487
|
cd context-compress
|
|
299
488
|
npm install
|
|
300
|
-
|
|
301
|
-
npm run
|
|
302
|
-
npm run
|
|
303
|
-
npm
|
|
304
|
-
npm run
|
|
489
|
+
|
|
490
|
+
npm run typecheck # Strict TS
|
|
491
|
+
npm run lint # Biome
|
|
492
|
+
npm test # All tests (unit + integration)
|
|
493
|
+
npm run test:unit # Unit tests only
|
|
494
|
+
|
|
495
|
+
npm run build # Compile + bundle MCP server + CLI
|
|
496
|
+
npm run build:hooks # Bundle the PreToolUse hook (with SHA-256)
|
|
497
|
+
npm run build:bin # Cross-compile single binaries via Bun (4 targets)
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Reproducing the benchmarks
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
# Synthetic — fast, reproducible, includes RTK-style commands
|
|
504
|
+
tsx scripts/benchmark.ts
|
|
505
|
+
|
|
506
|
+
# Real-world — runs actual commands in your repo
|
|
507
|
+
tsx scripts/benchmark-real.ts # full
|
|
508
|
+
tsx scripts/benchmark-real.ts --quick # skip npm test
|
|
509
|
+
|
|
510
|
+
# Head-to-head with RTK (build it first)
|
|
511
|
+
git clone https://github.com/rtk-ai/rtk /tmp/rtk
|
|
512
|
+
(cd /tmp/rtk && cargo build --release)
|
|
513
|
+
|
|
514
|
+
RTK_BIN=/tmp/rtk/target/release/rtk tsx scripts/benchmark-vs-rtk.ts
|
|
515
|
+
RTK_BIN=... tsx scripts/benchmark-vs-rtk.ts --auto # also run LLM-judged auto mode
|
|
516
|
+
RTK_BIN=... tsx scripts/benchmark-vs-rtk.ts --json # machine-readable
|
|
305
517
|
```
|
|
306
518
|
|
|
307
519
|
---
|
|
@@ -309,3 +521,5 @@ npm run build # Compile + bundle
|
|
|
309
521
|
## License
|
|
310
522
|
|
|
311
523
|
[MIT](LICENSE) — Based on [context-mode](https://github.com/mksglu/claude-context-mode) by Mert Koseoğlu.
|
|
524
|
+
|
|
525
|
+
> **Inspired by [RTK](https://github.com/rtk-ai/rtk)** for the command-aware filtering tactic. context-compress builds on the same idea with multi-mode trade-offs, an LLM-judged `auto` mode, MCP integration, sandbox execution, and a searchable knowledge base.
|
package/dist/cli/doctor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAsBA,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAiI9C"}
|
package/dist/cli/doctor.js
CHANGED
|
@@ -7,16 +7,8 @@ import Database from "better-sqlite3";
|
|
|
7
7
|
import { loadConfig } from "../config.js";
|
|
8
8
|
import { SubprocessExecutor } from "../executor.js";
|
|
9
9
|
import { detectRuntimes, getRuntimeSummary, hasBun } from "../runtime/index.js";
|
|
10
|
+
import { getVersion } from "../util/version.js";
|
|
10
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
function getVersion() {
|
|
12
|
-
try {
|
|
13
|
-
const pkg = JSON.parse(readFileSync(resolve(__dirname, "..", "..", "package.json"), "utf-8"));
|
|
14
|
-
return pkg.version ?? "unknown";
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return "unknown";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
12
|
function readSettings() {
|
|
21
13
|
try {
|
|
22
14
|
const path = resolve(homedir(), ".claude", "settings.json");
|
|
@@ -138,7 +130,7 @@ export async function doctor() {
|
|
|
138
130
|
console.log(` [FAIL] FTS5: ${msg}`);
|
|
139
131
|
}
|
|
140
132
|
// 6. Version
|
|
141
|
-
const version = getVersion();
|
|
133
|
+
const version = getVersion("unknown");
|
|
142
134
|
console.log(`\n Version: v${version}`);
|
|
143
135
|
// Summary
|
|
144
136
|
console.log();
|
package/dist/cli/doctor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,E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|
|
2
|
+
/**
|
|
3
|
+
* Apply the full context-compress output pipeline to a buffer.
|
|
4
|
+
*
|
|
5
|
+
* conservative: ANSI strip only — preserve everything else.
|
|
6
|
+
* balanced: ANSI strip → command filter (drops universal noise:
|
|
7
|
+
* progress bars, hint lines, ./.., 'total N', truncates
|
|
8
|
+
* git log bodies past 3 lines) → dedup/group (if >5KB).
|
|
9
|
+
* Preserves all metadata (perms, dates, commit headers).
|
|
10
|
+
* aggressive: balanced + aggressive command filters that drop metadata
|
|
11
|
+
* (git log → oneline, ls -la → name+size, etc.) and lower
|
|
12
|
+
* the dedup threshold to 2KB.
|
|
13
|
+
*
|
|
14
|
+
* Mirrors what SubprocessExecutor does internally so the same compression
|
|
15
|
+
* is available to standalone shell commands or other agents that don't
|
|
16
|
+
* route through the MCP execute() tool.
|
|
17
|
+
*/
|
|
18
|
+
export declare function compressOutput(stdout: string, originalCmd?: string, mode?: FilterMode): string;
|
|
19
|
+
/**
|
|
20
|
+
* Async variant that handles the "auto" meta-mode by asking an LLM to
|
|
21
|
+
* pick conservative/balanced/aggressive for the given command + output.
|
|
22
|
+
* Concrete modes route to the synchronous compressOutput.
|
|
23
|
+
*/
|
|
24
|
+
export declare function compressOutputAsync(stdout: string, originalCmd: string | undefined, mode?: RequestedMode): Promise<{
|
|
25
|
+
output: string;
|
|
26
|
+
resolvedMode: FilterMode;
|
|
27
|
+
autoSource?: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* `context-compress filter [--cmd '<orig>'] [--mode conservative|balanced|aggressive|auto]`
|
|
31
|
+
* Reads stdin, applies the pipeline, writes to stdout. Exits 0.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runFilter(args: string[]): Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* `context-compress wrap [--stream] -- <cmd ...>`
|
|
36
|
+
*
|
|
37
|
+
* Default (buffered): spawn cmd, capture all stdout, apply full pipeline,
|
|
38
|
+
* print filtered stdout, propagate child's exit code.
|
|
39
|
+
*
|
|
40
|
+
* `--stream`: emit filtered output line-by-line as the child produces it.
|
|
41
|
+
* Use for long-running commands (tail -f, cargo watch, builds with
|
|
42
|
+
* progressive output) where buffering would defer all output until exit.
|
|
43
|
+
* Stream mode applies ANSI strip + progress filter + adjacent dedup only —
|
|
44
|
+
* command-aware filters need the full output.
|
|
45
|
+
*
|
|
46
|
+
* Usage:
|
|
47
|
+
* context-compress wrap "npm test"
|
|
48
|
+
* context-compress wrap --stream "tail -f /var/log/app.log"
|
|
49
|
+
* context-compress wrap -- npm test
|
|
50
|
+
*/
|
|
51
|
+
export declare function runWrap(args: string[]): Promise<number>;
|
|
52
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/cli/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,UAAU,EACf,KAAK,aAAa,EAGlB,MAAM,eAAe,CAAC;AAUvB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,IAAI,GAAE,UAAyB,GAC7B,MAAM,CAgBR;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,GAAE,aAA4B,GAChC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAU5E;AAoBD;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAc/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA0C7D"}
|