context-compress 2026.3.22 → 2026.6.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.
Files changed (120) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/.claude-plugin/plugin.json +12 -0
  3. package/.codex-plugin/plugin.json +40 -0
  4. package/.mcp.json +11 -0
  5. package/README.md +275 -44
  6. package/dist/cli/doctor.d.ts.map +1 -1
  7. package/dist/cli/doctor.js +2 -10
  8. package/dist/cli/doctor.js.map +1 -1
  9. package/dist/cli/filter.d.ts +52 -0
  10. package/dist/cli/filter.d.ts.map +1 -0
  11. package/dist/cli/filter.js +200 -0
  12. package/dist/cli/filter.js.map +1 -0
  13. package/dist/cli/index.d.ts +8 -4
  14. package/dist/cli/index.d.ts.map +1 -1
  15. package/dist/cli/index.js +19 -6
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cli/lite.d.ts +15 -0
  18. package/dist/cli/lite.d.ts.map +1 -0
  19. package/dist/cli/lite.js +37 -0
  20. package/dist/cli/lite.js.map +1 -0
  21. package/dist/cli/setup.d.ts +23 -1
  22. package/dist/cli/setup.d.ts.map +1 -1
  23. package/dist/cli/setup.js +122 -21
  24. package/dist/cli/setup.js.map +1 -1
  25. package/dist/executor.d.ts.map +1 -1
  26. package/dist/executor.js +7 -4
  27. package/dist/executor.js.map +1 -1
  28. package/dist/filters.d.ts +39 -5
  29. package/dist/filters.d.ts.map +1 -1
  30. package/dist/filters.js +577 -25
  31. package/dist/filters.js.map +1 -1
  32. package/dist/hooks/pretooluse.js +57 -0
  33. package/dist/hooks/pretooluse.js.map +1 -1
  34. package/dist/network.d.ts.map +1 -1
  35. package/dist/network.js +11 -0
  36. package/dist/network.js.map +1 -1
  37. package/dist/server.bundle.mjs +1140 -641
  38. package/dist/server.bundle.mjs.map +4 -4
  39. package/dist/server.d.ts.map +1 -1
  40. package/dist/server.js +36 -612
  41. package/dist/server.js.map +1 -1
  42. package/dist/stats.js +1 -1
  43. package/dist/stats.js.map +1 -1
  44. package/dist/store.d.ts +1 -0
  45. package/dist/store.d.ts.map +1 -1
  46. package/dist/store.js +15 -2
  47. package/dist/store.js.map +1 -1
  48. package/dist/tools/batch-execute.d.ts +4 -0
  49. package/dist/tools/batch-execute.d.ts.map +1 -0
  50. package/dist/tools/batch-execute.js +75 -0
  51. package/dist/tools/batch-execute.js.map +1 -0
  52. package/dist/tools/context.d.ts +17 -0
  53. package/dist/tools/context.d.ts.map +1 -0
  54. package/dist/tools/context.js +2 -0
  55. package/dist/tools/context.js.map +1 -0
  56. package/dist/tools/discover.d.ts +4 -0
  57. package/dist/tools/discover.d.ts.map +1 -0
  58. package/dist/tools/discover.js +65 -0
  59. package/dist/tools/discover.js.map +1 -0
  60. package/dist/tools/execute-file.d.ts +4 -0
  61. package/dist/tools/execute-file.d.ts.map +1 -0
  62. package/dist/tools/execute-file.js +66 -0
  63. package/dist/tools/execute-file.js.map +1 -0
  64. package/dist/tools/execute.d.ts +4 -0
  65. package/dist/tools/execute.d.ts.map +1 -0
  66. package/dist/tools/execute.js +54 -0
  67. package/dist/tools/execute.js.map +1 -0
  68. package/dist/tools/fetch-and-index.d.ts +4 -0
  69. package/dist/tools/fetch-and-index.d.ts.map +1 -0
  70. package/dist/tools/fetch-and-index.js +91 -0
  71. package/dist/tools/fetch-and-index.js.map +1 -0
  72. package/dist/tools/index-content.d.ts +4 -0
  73. package/dist/tools/index-content.d.ts.map +1 -0
  74. package/dist/tools/index-content.js +85 -0
  75. package/dist/tools/index-content.js.map +1 -0
  76. package/dist/tools/search.d.ts +4 -0
  77. package/dist/tools/search.d.ts.map +1 -0
  78. package/dist/tools/search.js +57 -0
  79. package/dist/tools/search.js.map +1 -0
  80. package/dist/tools/stats.d.ts +4 -0
  81. package/dist/tools/stats.d.ts.map +1 -0
  82. package/dist/tools/stats.js +10 -0
  83. package/dist/tools/stats.js.map +1 -0
  84. package/dist/types.d.ts +0 -1
  85. package/dist/types.d.ts.map +1 -1
  86. package/dist/util/auto-mode.d.ts +40 -0
  87. package/dist/util/auto-mode.d.ts.map +1 -0
  88. package/dist/util/auto-mode.js +181 -0
  89. package/dist/util/auto-mode.js.map +1 -0
  90. package/dist/util/fetch-code.d.ts +10 -0
  91. package/dist/util/fetch-code.d.ts.map +1 -0
  92. package/dist/util/fetch-code.js +87 -0
  93. package/dist/util/fetch-code.js.map +1 -0
  94. package/dist/util/intent-filter.d.ts +17 -0
  95. package/dist/util/intent-filter.d.ts.map +1 -0
  96. package/dist/util/intent-filter.js +28 -0
  97. package/dist/util/intent-filter.js.map +1 -0
  98. package/dist/util/label.d.ts +4 -0
  99. package/dist/util/label.d.ts.map +1 -0
  100. package/dist/util/label.js +14 -0
  101. package/dist/util/label.js.map +1 -0
  102. package/dist/util/path.d.ts +8 -0
  103. package/dist/util/path.d.ts.map +1 -0
  104. package/dist/util/path.js +21 -0
  105. package/dist/util/path.js.map +1 -0
  106. package/dist/util/stream-compress.d.ts +36 -0
  107. package/dist/util/stream-compress.d.ts.map +1 -0
  108. package/dist/util/stream-compress.js +104 -0
  109. package/dist/util/stream-compress.js.map +1 -0
  110. package/dist/util/version.d.ts +2 -0
  111. package/dist/util/version.d.ts.map +1 -0
  112. package/dist/util/version.js +15 -0
  113. package/dist/util/version.js.map +1 -0
  114. package/docs/agentic-benchmark.md +110 -0
  115. package/docs/token-reduction-report.md +47 -18
  116. package/hooks/claude-codex-hooks.json +19 -0
  117. package/hooks/pretooluse.mjs +38 -0
  118. package/package.json +12 -8
  119. package/skills/context-compress-audit/SKILL.md +49 -0
  120. package/skills/context-compress-audit/agents/openai.yaml +13 -0
@@ -6,7 +6,7 @@
6
6
  > provides a detailed before/after comparison for 12 common operations,
7
7
  > and addresses the natural question: "doesn't less tokens mean losing context?"
8
8
 
9
- **Version**: 2026.3.21 | **Last updated**: 2026-03-22
9
+ **Version**: 2026.5.0 | **Last updated**: 2026-05-10
10
10
 
11
11
  ---
12
12
 
@@ -46,10 +46,28 @@ The worst part: **99% of that tool output is noise** — import statements, boil
46
46
 
47
47
  ---
48
48
 
49
- ## The Solution: 3-Layer Architecture
49
+ ## The Solution: 4-Layer Architecture
50
50
 
51
51
  context-compress doesn't delete data — it **defers** it. All data is preserved and searchable. Only the relevant parts enter context.
52
52
 
53
+ ### Layer 0: Command-Specific Output Filters (v2026.3.22)
54
+
55
+ Before generic compression, output passes through command-aware filters that strip noise specific to each tool:
56
+
57
+ | Command | What's Stripped | Typical Savings |
58
+ |:--|:--|:--|
59
+ | `git push/pull/fetch/clone` | Remote progress lines, object counting, delta resolution | 40-60% |
60
+ | `git status` | Hint lines (`use "git add"...`), blank lines | 20-30% |
61
+ | `npm/yarn/pnpm install` | Deprecation warnings, funding prompts, tree-drawing chars | 30-50% |
62
+ | `npm test / jest / vitest / pytest` | Passing test details, keeps only failures + summary | 70-95% |
63
+ | `cargo build / make / gradle` | Download progress, "Compiling X/Y", lock waits | 50-70% |
64
+ | `docker build` | Layer hash lines (` ---> abc123`), build context transfer | 30-50% |
65
+ | `ls -R / find / tree` | Directory grouping for large listings (50+ files) | 60-80% |
66
+
67
+ Additionally, all output passes through:
68
+ - **ANSI stripping**: Terminal escape codes (colors, cursor movement) are always removed — pure noise for LLMs
69
+ - **Progress line removal**: Spinner characters, percentage bars, download/ETA lines are filtered
70
+
53
71
  ### Layer 1: Sandbox Execution
54
72
 
55
73
  The agent writes code to process data. Only `console.log()` output enters context. 11 languages supported: JavaScript, TypeScript, Python, Shell, Ruby, Go, Rust, PHP, Perl, R, Elixir.
@@ -204,18 +222,28 @@ The following comparison uses realistic output sizes measured from the context-c
204
222
  | **After** | 200 | ~50 | `execute` with `intent: "errors"` → only issues shown |
205
223
  | **Saved** | | **~3,700** | **98.7% reduction** |
206
224
 
225
+ ### 13. npm test with ANSI + verbose output (~8KB, v2026.3.22)
226
+
227
+ | | Bytes | Tokens (est.) | Method |
228
+ |:--|--:|--:|:--|
229
+ | **Before** | 8,000 | ~2,000 | `Bash npm test` → full ANSI-colored verbose output in context |
230
+ | **After** | 350 | ~88 | Command filter strips ANSI + passing tests → only failures + summary |
231
+ | **Saved** | | **~1,912** | **95.6% reduction** |
232
+
233
+ **Pipeline**: ANSI stripping → command filter (test runner detection) → progress line removal → deduplication → smart truncation. All 5 layers applied automatically.
234
+
207
235
  ---
208
236
 
209
237
  ## Session Totals
210
238
 
211
- Combining all 12 operations from a single coding session:
239
+ Combining all 13 operations from a single coding session:
212
240
 
213
241
  ```
214
- BEFORE: 1,043 KB → ~261K tokens consumed (bytes/4 midpoint)
215
- AFTER: 9 KB → ~2.2K tokens consumed
242
+ BEFORE: 1,051 KB → ~263K tokens consumed (bytes/4 midpoint)
243
+ AFTER: 9 KB → ~2.3K tokens consumed
216
244
  ────────────────────────
217
- SAVED: 1,035 KB → ~259K tokens
218
- REDUCTION: 99.2%
245
+ SAVED: 1,042 KB → ~260K tokens
246
+ REDUCTION: 99.1%
219
247
  ```
220
248
 
221
249
  ---
@@ -229,21 +257,21 @@ Claude Code uses a 200K token context window.
229
257
  │ 200,000 token context window │
230
258
  │ │
231
259
  │ WITHOUT context-compress: │
232
- │ ████████████████████████████████████████████████████ ~131% │
233
- │ ← 12 operations OVERFLOW the window. Conversation lost. │
260
+ │ ████████████████████████████████████████████████████ ~132% │
261
+ │ ← 13 operations OVERFLOW the window. Conversation lost. │
234
262
  │ │
235
263
  │ WITH context-compress: │
236
- │ █ ~1.1% │
237
- │ ← 12 operations use ~1.1%. ~98.9% free for conversation. │
264
+ │ █ ~1.2% │
265
+ │ ← 13 operations use ~1.2%. ~98.8% free for conversation. │
238
266
  └─────────────────────────────────────────────────────────────┘
239
267
  ```
240
268
 
241
269
  | Metric | Before | After |
242
270
  |:--|--:|--:|
243
- | Tokens consumed (est.) | ~261,000 | ~2,200 |
244
- | % of context window | ~131% | ~1.1% |
245
- | Operations before compaction | ~9 | **~1,100** |
246
- | Conversation longevity | Short | **~119x longer** |
271
+ | Tokens consumed (est.) | ~263,000 | ~2,300 |
272
+ | % of context window | ~132% | ~1.2% |
273
+ | Operations before compaction | ~9 | **~1,080** |
274
+ | Conversation longevity | Short | **~117x longer** |
247
275
 
248
276
  ---
249
277
 
@@ -379,7 +407,7 @@ The other 55,701 bytes are still in FTS5 — fully searchable. Need the order ta
379
407
 
380
408
  ## Security and Reliability
381
409
 
382
- context-compress v2026.3.21 includes comprehensive security and reliability features:
410
+ context-compress v2026.5.0 includes comprehensive security and reliability features:
383
411
 
384
412
  ### Security
385
413
 
@@ -399,7 +427,8 @@ context-compress v2026.3.21 includes comprehensive security and reliability feat
399
427
  |:--|:--|
400
428
  | Graceful shutdown | Active subprocess tracking, SIGTERM/SIGINT cleanup, uncaughtException handling |
401
429
  | DB resilience | In-memory fallback on disk-full. WAL mode for crash recovery. Stale DB cleanup |
402
- | Output processing | Line deduplication, error grouping, smart 60/40 head/tail truncation |
430
+ | Output processing | ANSI stripping, progress line removal, command-specific filters, line deduplication, error grouping, smart 60/40 head/tail truncation |
431
+ | Cumulative stats | Cross-session token savings persisted to `stats.json` when `persistDb` is enabled |
403
432
  | Search fallback | 3-layer: Porter stemming → trigram (lazy) → Levenshtein fuzzy correction |
404
433
  | Configuration | ENV > file > defaults with Zod validation and sanity clamping |
405
434
 
@@ -501,6 +530,6 @@ The core principle:
501
530
 
502
531
  ---
503
532
 
504
- *Generated from real benchmarks on the context-compress v2026.3.21 codebase.*
533
+ *Generated from real benchmarks on the context-compress v2026.5.0 codebase.*
505
534
  *Token estimates use bytes/4 midpoint. Actual token counts may vary by 20-30% depending on content type.*
506
535
  *See SECURITY.md for the full trust model and security architecture.*
@@ -0,0 +1,19 @@
1
+ {
2
+ "description": "context-compress PreToolUse hooks for Claude-compatible plugin hosts",
3
+ "hooks": {
4
+ "PreToolUse": [
5
+ {
6
+ "matcher": "Bash|Read|Grep|WebFetch|Task",
7
+ "hooks": [
8
+ {
9
+ "type": "command",
10
+ "command": "command -v node >/dev/null 2>&1 && CONTEXT_COMPRESS_FILTER_BASH=1 CONTEXT_COMPRESS_BIN=\"node ${CLAUDE_PLUGIN_ROOT}/dist/cli/index.js\" node \"${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.mjs\" || exit 0",
11
+ "commandWindows": "if (Get-Command node -ErrorAction SilentlyContinue) { $env:CONTEXT_COMPRESS_FILTER_BASH='1'; $env:CONTEXT_COMPRESS_BIN='context-compress'; node \"$env:CLAUDE_PLUGIN_ROOT\\hooks\\pretooluse.mjs\" }",
12
+ "timeout": 5,
13
+ "statusMessage": "Protecting context window..."
14
+ }
15
+ ]
16
+ }
17
+ ]
18
+ }
19
+ }
@@ -6,6 +6,36 @@ var blockCurl = process.env.CONTEXT_COMPRESS_BLOCK_CURL !== "0";
6
6
  var blockWebFetch = process.env.CONTEXT_COMPRESS_BLOCK_WEBFETCH !== "0";
7
7
  var nudgeOnRead = process.env.CONTEXT_COMPRESS_NUDGE_READ !== "0";
8
8
  var nudgeOnGrep = process.env.CONTEXT_COMPRESS_NUDGE_GREP !== "0";
9
+ var filterBash = process.env.CONTEXT_COMPRESS_FILTER_BASH === "1";
10
+ var ccBin = process.env.CONTEXT_COMPRESS_BIN ?? "context-compress";
11
+ var ccMode = process.env.CONTEXT_COMPRESS_MODE;
12
+ var WRAP_TARGETS = [
13
+ /^git\s+(status|log|diff|show|blame|branch|stash\s+list|grep|ls-files)/,
14
+ /^(npm|yarn|pnpm|bun)\s+(install|i|add|test|run\s|update|outdated|audit|list|ls|view|info)/,
15
+ /^cargo\s+(build|test|check|run|clippy|tree|search|metadata)/,
16
+ /^(pytest|jest|mocha|vitest|tap|bats)\b/,
17
+ /^(find|grep|rg|fd|ag|ripgrep)\b/,
18
+ /^ls\s+(-R|-la|-al)/,
19
+ /^docker\s+(build|ps|logs|images|inspect|stats)/,
20
+ /^kubectl\s+(get|describe|logs|top|api-resources)/,
21
+ /^terraform\s+(plan|show|state\s+list|state\s+show|validate)/,
22
+ /^helm\s+(list|status|history|get)/,
23
+ /^(make|gradle|bazel|nx|turbo)\b/,
24
+ /^ps\s+(aux|-ef)/,
25
+ /^(top|htop)\b/,
26
+ /^(df|du)\b/,
27
+ /^(go|rustc)\s+(test|build|vet|run)/
28
+ ];
29
+ function shouldWrap(cmd) {
30
+ const trimmed = cmd.trim();
31
+ if (/(?:^|\s)(?:>|>>|\d?>&)\s*\S/.test(trimmed)) return false;
32
+ if (/\|/.test(trimmed)) return false;
33
+ if (/&&|\|\||;/.test(trimmed)) return false;
34
+ return WRAP_TARGETS.some((re) => re.test(trimmed));
35
+ }
36
+ function shellQuote(s) {
37
+ return `'${s.replace(/'/g, "'\\''")}'`;
38
+ }
9
39
  var raw = "";
10
40
  process.stdin.setEncoding("utf-8");
11
41
  for await (const chunk of process.stdin) raw += chunk;
@@ -37,6 +67,14 @@ if (tool === "Bash") {
37
67
  }
38
68
  });
39
69
  }
70
+ if (filterBash && shouldWrap(command)) {
71
+ const modeFlag = ccMode ? ` --mode ${ccMode}` : "";
72
+ respond({
73
+ updatedInput: {
74
+ command: `${ccBin} wrap${modeFlag} ${shellQuote(command)}`
75
+ }
76
+ });
77
+ }
40
78
  process.exit(0);
41
79
  }
42
80
  if (tool === "Read" && nudgeOnRead) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-compress",
3
- "version": "2026.3.22",
3
+ "version": "2026.6.0",
4
4
  "description": "Context-aware MCP server that compresses tool output for Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
@@ -12,12 +12,13 @@
12
12
  "build:hooks": "esbuild src/hooks/pretooluse.ts --bundle --platform=node --format=esm --outfile=hooks/pretooluse.mjs --target=node18 && node -e \"const{createHash}=require('crypto'),{readFileSync,writeFileSync}=require('fs');const h=createHash('sha256').update(readFileSync('hooks/pretooluse.mjs')).digest('hex');writeFileSync('hooks/pretooluse.sha256',h+'\\n')\"",
13
13
  "dev": "tsx src/index.ts",
14
14
  "typecheck": "tsc --noEmit",
15
- "lint": "biome check src/",
16
- "lint:fix": "biome check --write src/",
15
+ "lint": "biome check --max-diagnostics=200 src/",
16
+ "lint:fix": "biome check --write --max-diagnostics=200 src/",
17
17
  "test": "node --import tsx --test tests/**/*.test.ts",
18
18
  "test:unit": "node --import tsx --test tests/unit/*.test.ts",
19
19
  "test:integration": "node --import tsx --test tests/integration/*.test.ts",
20
- "clean": "rm -rf dist",
20
+ "clean": "rm -rf dist dist-bin",
21
+ "build:bin": "bun build --compile --target=bun-darwin-arm64 ./src/cli/lite.ts --outfile=./dist-bin/cc-lite-darwin-arm64 && bun build --compile --target=bun-darwin-x64 ./src/cli/lite.ts --outfile=./dist-bin/cc-lite-darwin-x64 && bun build --compile --target=bun-linux-x64 ./src/cli/lite.ts --outfile=./dist-bin/cc-lite-linux-x64 && bun build --compile --target=bun-linux-arm64 ./src/cli/lite.ts --outfile=./dist-bin/cc-lite-linux-arm64",
21
22
  "prepublishOnly": "npm run lint && npm run test && npm run build"
22
23
  },
23
24
  "engines": {
@@ -37,6 +38,9 @@
37
38
  "typescript": "^5.7.0"
38
39
  },
39
40
  "files": [
41
+ ".codex-plugin/",
42
+ ".claude-plugin/",
43
+ ".mcp.json",
40
44
  "dist/",
41
45
  "docs/",
42
46
  "hooks/",
@@ -45,10 +49,10 @@
45
49
  "README.md"
46
50
  ],
47
51
  "license": "MIT",
48
- "repository": {
49
- "type": "git",
50
- "url": "https://github.com/Open330/context-compress"
51
- },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/Open330/context-compress.git"
55
+ },
52
56
  "keywords": [
53
57
  "mcp",
54
58
  "claude",
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: context-compress-audit
3
+ description: Audit a repository, plugin setup, or agent session for raw Bash, Read, WebFetch, and MCP outputs that should be routed through context-compress instead. Use when asked to find context waste, raw tool output waste, missing plugin routing, or places where large command/file/web output still enters the agent context window.
4
+ ---
5
+
6
+ # Context-Compress Audit
7
+
8
+ Find places where large raw output can still enter the agent context window.
9
+
10
+ ## Procedure
11
+
12
+ 1. Run `mcp__context-compress__stats` first if the tool is available.
13
+ 2. Inspect setup surfaces that control routing:
14
+ - `.codex-plugin/plugin.json`
15
+ - `.claude-plugin/plugin.json`
16
+ - `.mcp.json`
17
+ - `hooks/`
18
+ - `skills/`
19
+ - README install instructions
20
+ 3. Search for risky guidance or examples that encourage raw output:
21
+ - `Bash` for tests, logs, `git log`, `git diff`, `curl`, `kubectl`, `docker`, `npm test`
22
+ - `Read` for large logs, bundled files, snapshots, CSV/JSON dumps
23
+ - `WebFetch` for documentation pages that should use `fetch_and_index`
24
+ - Playwright snapshots without a file/index/search path
25
+ 4. Report only actionable findings. Prefer one-line fixes that route work through:
26
+ - `batch_execute` for several commands plus searches
27
+ - `execute` for command/API output that must be analyzed first
28
+ - `execute_file` for large local files
29
+ - `fetch_and_index` plus `search` for web documentation
30
+
31
+ ## Output
32
+
33
+ Use this format:
34
+
35
+ ```md
36
+ ## Context-Compress Audit
37
+
38
+ - [severity] file:line - raw-output risk. Replace with <tool/workflow>.
39
+ - [severity] file:line - missing install/routing coverage. Add <specific fix>.
40
+
41
+ Summary: <N> findings, estimated impact <low|medium|high>.
42
+ ```
43
+
44
+ Severity:
45
+ - `high`: large output can enter context by default.
46
+ - `medium`: docs/examples teach a wasteful path.
47
+ - `low`: minor wording, missing cross-link, or optional setup gap.
48
+
49
+ If nothing meaningful is found, say `No raw-output waste found. Routing looks covered.`
@@ -0,0 +1,13 @@
1
+ interface:
2
+ display_name: "Context Compress Audit"
3
+ short_description: "Find raw-output context waste."
4
+ default_prompt: "Use $context-compress-audit to audit this project for raw tool output waste and missing routing."
5
+
6
+ dependencies:
7
+ tools:
8
+ - type: "mcp"
9
+ value: "context-compress"
10
+ description: "Context-compress MCP server for stats and indexed search."
11
+
12
+ policy:
13
+ allow_implicit_invocation: true