shrinkwrap-cli 0.1.2__tar.gz → 0.1.4__tar.gz
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.
- {shrinkwrap_cli-0.1.2/shrinkwrap_cli.egg-info → shrinkwrap_cli-0.1.4}/PKG-INFO +28 -3
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/README.md +27 -2
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/pyproject.toml +1 -1
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/__init__.py +1 -1
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/cli.py +35 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/engine/tracker.py +46 -14
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/proxy/config_manager.py +6 -3
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4/shrinkwrap_cli.egg-info}/PKG-INFO +28 -3
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/tests/test_engine.py +27 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/LICENSE +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/setup.cfg +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/benchmarks/corpus.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/benchmarks/runner.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/engine/compactor.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/engine/privacy.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/engine/retrieval_buffer.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/engine/tokenizer.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/gap_report/gap_report.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/proxy/http_proxy.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/proxy/stdio_proxy.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap/shell/guidance.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap_cli.egg-info/SOURCES.txt +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap_cli.egg-info/dependency_links.txt +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap_cli.egg-info/entry_points.txt +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/shrinkwrap_cli.egg-info/top_level.txt +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/tests/test_proxy.py +0 -0
- {shrinkwrap_cli-0.1.2 → shrinkwrap_cli-0.1.4}/tests/test_suite.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: shrinkwrap-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Drop-in 90%+ Token Compaction Proxy for MCP & AI Agent Tools
|
|
5
5
|
Author: ShrinkWrap Maintainers
|
|
6
6
|
License-Expression: MIT
|
|
@@ -23,9 +23,9 @@ Copy and paste this instruction into your AI coding assistant (Antigravity, Clau
|
|
|
23
23
|
```text
|
|
24
24
|
Please install and set up ShrinkWrap on my computer to reduce my MCP and tool token usage by ~90%:
|
|
25
25
|
1. Install shrinkwrap-cli: `pip install shrinkwrap-cli`
|
|
26
|
-
|
|
27
26
|
2. Auto-wrap active MCP configs: run `shrinkwrap install`
|
|
28
27
|
3. Verify setup: run `shrinkwrap status` and `shrinkwrap benchmark`
|
|
28
|
+
4. At the end of every run or task, run `shrinkwrap session --markdown` and include token savings in your final output.
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### Manual Installation
|
|
@@ -34,8 +34,14 @@ pip install shrinkwrap-cli
|
|
|
34
34
|
shrinkwrap install
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### Terminal Side-by-Side Visual Comparison
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
|
|
37
42
|
### Benchmark Summary & Token Savings
|
|
38
43
|
|
|
44
|
+
|
|
39
45
|
Measured across production developer payloads:
|
|
40
46
|
|
|
41
47
|
| Payload Benchmark | Tool Source | Strategy | Original Tokens | Compacted Tokens | Token Reduction |
|
|
@@ -161,13 +167,31 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
161
167
|
|
|
162
168
|
---
|
|
163
169
|
|
|
170
|
+
## Session Token Analytics & Agent End-of-Run Reporting
|
|
171
|
+
|
|
172
|
+
AI agents operating in multi-step task loops can report their exact tokens saved, reduction percentages, and estimated financial savings at the conclusion of a task.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Print active run session summary
|
|
176
|
+
shrinkwrap session
|
|
177
|
+
|
|
178
|
+
# Generate agent-ready Markdown snippet for final user turn responses
|
|
179
|
+
shrinkwrap session --markdown
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Output Example (`--markdown`):
|
|
183
|
+
> **ShrinkWrap Session Savings**: **42,478 tokens saved** (81.02% reduction across 5 tool invocations, ~$0.1274 USD saved).
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
164
187
|
## Command Reference
|
|
165
188
|
|
|
166
189
|
| Command | Usage | Description |
|
|
167
190
|
|---|---|---|
|
|
168
191
|
| `shrinkwrap install` | `shrinkwrap install [--dry-run]` | Auto-discover and wrap local MCP server configurations |
|
|
169
192
|
| `shrinkwrap wrap-stdio` | `shrinkwrap wrap-stdio -- <cmd> [args]` | Execute stdio proxy for target server command |
|
|
170
|
-
| `shrinkwrap
|
|
193
|
+
| `shrinkwrap session` | `shrinkwrap session [--markdown] [--json]` | Report token usage and savings for the current agent session |
|
|
194
|
+
| `shrinkwrap gain` | `shrinkwrap gain [--history] [--json] [--reset]` | Display cumulative token savings analytics and harness breakdowns |
|
|
171
195
|
| `shrinkwrap fetch` | `shrinkwrap fetch <sw-ref:handle>` | Retrieve raw payload from memory buffer |
|
|
172
196
|
| `shrinkwrap status` | `shrinkwrap status` | Display system status and capability gate information |
|
|
173
197
|
| `shrinkwrap benchmark` | `shrinkwrap benchmark` | Run benchmark test suite |
|
|
@@ -179,3 +203,4 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
179
203
|
## License
|
|
180
204
|
|
|
181
205
|
MIT License. See [LICENSE](LICENSE) for details.
|
|
206
|
+
|
|
@@ -12,9 +12,9 @@ Copy and paste this instruction into your AI coding assistant (Antigravity, Clau
|
|
|
12
12
|
```text
|
|
13
13
|
Please install and set up ShrinkWrap on my computer to reduce my MCP and tool token usage by ~90%:
|
|
14
14
|
1. Install shrinkwrap-cli: `pip install shrinkwrap-cli`
|
|
15
|
-
|
|
16
15
|
2. Auto-wrap active MCP configs: run `shrinkwrap install`
|
|
17
16
|
3. Verify setup: run `shrinkwrap status` and `shrinkwrap benchmark`
|
|
17
|
+
4. At the end of every run or task, run `shrinkwrap session --markdown` and include token savings in your final output.
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
### Manual Installation
|
|
@@ -23,8 +23,14 @@ pip install shrinkwrap-cli
|
|
|
23
23
|
shrinkwrap install
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
### Terminal Side-by-Side Visual Comparison
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
|
|
26
31
|
### Benchmark Summary & Token Savings
|
|
27
32
|
|
|
33
|
+
|
|
28
34
|
Measured across production developer payloads:
|
|
29
35
|
|
|
30
36
|
| Payload Benchmark | Tool Source | Strategy | Original Tokens | Compacted Tokens | Token Reduction |
|
|
@@ -150,13 +156,31 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
150
156
|
|
|
151
157
|
---
|
|
152
158
|
|
|
159
|
+
## Session Token Analytics & Agent End-of-Run Reporting
|
|
160
|
+
|
|
161
|
+
AI agents operating in multi-step task loops can report their exact tokens saved, reduction percentages, and estimated financial savings at the conclusion of a task.
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Print active run session summary
|
|
165
|
+
shrinkwrap session
|
|
166
|
+
|
|
167
|
+
# Generate agent-ready Markdown snippet for final user turn responses
|
|
168
|
+
shrinkwrap session --markdown
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Output Example (`--markdown`):
|
|
172
|
+
> **ShrinkWrap Session Savings**: **42,478 tokens saved** (81.02% reduction across 5 tool invocations, ~$0.1274 USD saved).
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
153
176
|
## Command Reference
|
|
154
177
|
|
|
155
178
|
| Command | Usage | Description |
|
|
156
179
|
|---|---|---|
|
|
157
180
|
| `shrinkwrap install` | `shrinkwrap install [--dry-run]` | Auto-discover and wrap local MCP server configurations |
|
|
158
181
|
| `shrinkwrap wrap-stdio` | `shrinkwrap wrap-stdio -- <cmd> [args]` | Execute stdio proxy for target server command |
|
|
159
|
-
| `shrinkwrap
|
|
182
|
+
| `shrinkwrap session` | `shrinkwrap session [--markdown] [--json]` | Report token usage and savings for the current agent session |
|
|
183
|
+
| `shrinkwrap gain` | `shrinkwrap gain [--history] [--json] [--reset]` | Display cumulative token savings analytics and harness breakdowns |
|
|
160
184
|
| `shrinkwrap fetch` | `shrinkwrap fetch <sw-ref:handle>` | Retrieve raw payload from memory buffer |
|
|
161
185
|
| `shrinkwrap status` | `shrinkwrap status` | Display system status and capability gate information |
|
|
162
186
|
| `shrinkwrap benchmark` | `shrinkwrap benchmark` | Run benchmark test suite |
|
|
@@ -168,3 +192,4 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
168
192
|
## License
|
|
169
193
|
|
|
170
194
|
MIT License. See [LICENSE](LICENSE) for details.
|
|
195
|
+
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "shrinkwrap-cli"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.4"
|
|
8
8
|
description = "Drop-in 90%+ Token Compaction Proxy for MCP & AI Agent Tools"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "ShrinkWrap Maintainers" }]
|
|
@@ -3,7 +3,7 @@ ShrinkWrap: Universal Token Compaction Proxy for MCP & AI Agent Tools.
|
|
|
3
3
|
Cuts tool token payloads by 90%+ before context ingestion while preserving exact data retrieval.
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
__version__ = "0.1.
|
|
6
|
+
__version__ = "0.1.4"
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
__coverage_status__ = "shell+mcp-proxy"
|
|
@@ -82,6 +82,30 @@ def print_gain_report(history: bool = False, reset: bool = False, output_json: b
|
|
|
82
82
|
for entry in hist[:20]:
|
|
83
83
|
print(f"{entry.get('timestamp', ''):<20} {entry.get('harness', ''):<14} {entry.get('tool', ''):<16} {entry.get('strategy', ''):<20} {entry.get('tokens_saved', 0):,} ({entry.get('savings_pct', 0.0)}%)")
|
|
84
84
|
|
|
85
|
+
def print_session_report(session_id: str = None, markdown: bool = False, output_json: bool = False):
|
|
86
|
+
sess = global_tracker.get_session_stats(session_id=session_id)
|
|
87
|
+
if output_json:
|
|
88
|
+
print(json.dumps(sess, indent=2))
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
invocations = sess.get("invocations", 0)
|
|
92
|
+
saved = sess.get("tokens_saved", 0)
|
|
93
|
+
pct = sess.get("savings_pct", 0.0)
|
|
94
|
+
usd = sess.get("est_usd_saved", 0.0)
|
|
95
|
+
sid = sess.get("session_id", "active")
|
|
96
|
+
|
|
97
|
+
if markdown:
|
|
98
|
+
print(f"> **ShrinkWrap Session Savings**: **{saved:,} tokens saved** ({pct}% reduction across {invocations} tool invocations, ~${usd:.4f} USD saved).")
|
|
99
|
+
else:
|
|
100
|
+
print("ShrinkWrap Session Token Summary")
|
|
101
|
+
print("================================")
|
|
102
|
+
print(f"Session ID: {sid}")
|
|
103
|
+
print(f"Tool Invocations: {invocations}")
|
|
104
|
+
print(f"Original Tokens: {sess.get('orig_tokens', 0):,}")
|
|
105
|
+
print(f"Compacted Tokens: {sess.get('comp_tokens', 0):,}")
|
|
106
|
+
print(f"Tokens Saved: {saved:,} ({pct}% reduction)")
|
|
107
|
+
print(f"Est. USD Saved: ${usd:.4f} USD")
|
|
108
|
+
|
|
85
109
|
def main():
|
|
86
110
|
parser = argparse.ArgumentParser(
|
|
87
111
|
prog="shrinkwrap",
|
|
@@ -107,6 +131,13 @@ def main():
|
|
|
107
131
|
stats_p.add_argument("--json", action="store_true", help="Output raw JSON data")
|
|
108
132
|
stats_p.add_argument("--reset", action="store_true", help="Reset analytics storage database")
|
|
109
133
|
|
|
134
|
+
# session
|
|
135
|
+
session_p = subparsers.add_parser("session", help="Display token summary for active agent run/session")
|
|
136
|
+
session_p.add_argument("--markdown", action="store_true", help="Output clean Markdown snippet for agent turn report")
|
|
137
|
+
session_p.add_argument("--json", action="store_true", help="Output raw JSON data")
|
|
138
|
+
session_p.add_argument("--session-id", type=str, help="Target session ID")
|
|
139
|
+
|
|
140
|
+
|
|
110
141
|
# fetch
|
|
111
142
|
fetch_p = subparsers.add_parser("fetch", help="Retrieve uncompacted payload from memory by reference handle")
|
|
112
143
|
fetch_p.add_argument("ref_handle", type=str, help="Reference handle (e.g. sw-ref:a1b2c3d4)")
|
|
@@ -152,7 +183,11 @@ def main():
|
|
|
152
183
|
elif args.subcommand in ("gain", "stats"):
|
|
153
184
|
print_gain_report(history=args.history, reset=args.reset, output_json=args.json)
|
|
154
185
|
|
|
186
|
+
elif args.subcommand == "session":
|
|
187
|
+
print_session_report(session_id=args.session_id, markdown=args.markdown, output_json=args.json)
|
|
188
|
+
|
|
155
189
|
elif args.subcommand == "fetch":
|
|
190
|
+
|
|
156
191
|
data = global_buffer.fetch(args.ref_handle)
|
|
157
192
|
if data is None:
|
|
158
193
|
print(f"Error: Reference handle '{args.ref_handle}' not found or expired.", file=sys.stderr)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Persistent Token Analytics Tracker for ShrinkWrap.
|
|
3
|
-
Records tokens processed, tokens saved, byte reductions, and detailed breakdowns per harness
|
|
4
|
-
Stores statistics persistently in ~/.shrinkwrap/stats.json.
|
|
2
|
+
Persistent Token Analytics & Session Tracker for ShrinkWrap.
|
|
3
|
+
Records tokens processed, tokens saved, byte reductions, and detailed breakdowns per harness, tool, and session ID.
|
|
5
4
|
"""
|
|
6
5
|
|
|
7
6
|
import os
|
|
@@ -13,14 +12,11 @@ from typing import Dict, Any, List, Optional
|
|
|
13
12
|
STATS_DIR = Path.home() / ".shrinkwrap"
|
|
14
13
|
STATS_FILE = STATS_DIR / "stats.json"
|
|
15
14
|
|
|
16
|
-
# Est cost per 1M input tokens (approx average across Claude 3.5 / GPT-4o)
|
|
17
15
|
EST_USD_PER_1M_TOKENS = 3.00
|
|
18
16
|
|
|
19
17
|
def detect_harness() -> str:
|
|
20
|
-
"""Detects active agent/harness environment from environment variables and process context."""
|
|
21
18
|
if os.getenv("SHRINKWRAP_HARNESS"):
|
|
22
19
|
return os.getenv("SHRINKWRAP_HARNESS")
|
|
23
|
-
|
|
24
20
|
env_str = str(os.environ).lower()
|
|
25
21
|
if "codex" in env_str:
|
|
26
22
|
return "codex"
|
|
@@ -32,6 +28,10 @@ def detect_harness() -> str:
|
|
|
32
28
|
return "antigravity"
|
|
33
29
|
return "generic-client"
|
|
34
30
|
|
|
31
|
+
def detect_session_id() -> str:
|
|
32
|
+
"""Returns explicit SHRINKWRAP_SESSION_ID if set, else falls back to process parent / default session."""
|
|
33
|
+
return os.getenv("SHRINKWRAP_SESSION_ID") or f"session_{time.strftime('%Y%m%d')}"
|
|
34
|
+
|
|
35
35
|
class TokenTracker:
|
|
36
36
|
def __init__(self, stats_path: Path = STATS_FILE):
|
|
37
37
|
self.stats_path = stats_path
|
|
@@ -55,7 +55,7 @@ class TokenTracker:
|
|
|
55
55
|
},
|
|
56
56
|
"by_harness": {},
|
|
57
57
|
"by_tool": {},
|
|
58
|
-
"
|
|
58
|
+
"by_session": {},
|
|
59
59
|
"history": []
|
|
60
60
|
}
|
|
61
61
|
self._save(initial_data)
|
|
@@ -84,9 +84,11 @@ class TokenTracker:
|
|
|
84
84
|
source_class: str = "stdio_mcp",
|
|
85
85
|
tool_name: str = "generic_tool",
|
|
86
86
|
strategy: str = "pass_through",
|
|
87
|
-
harness: Optional[str] = None
|
|
87
|
+
harness: Optional[str] = None,
|
|
88
|
+
session_id: Optional[str] = None
|
|
88
89
|
):
|
|
89
90
|
harness = harness or detect_harness()
|
|
91
|
+
session_id = session_id or detect_session_id()
|
|
90
92
|
tokens_saved = max(0, orig_tokens - comp_tokens)
|
|
91
93
|
bytes_saved = max(0, orig_bytes - comp_bytes)
|
|
92
94
|
was_compacted = comp_tokens < orig_tokens
|
|
@@ -118,17 +120,19 @@ class TokenTracker:
|
|
|
118
120
|
bt["comp_tokens"] += comp_tokens
|
|
119
121
|
bt["tokens_saved"] += tokens_saved
|
|
120
122
|
|
|
121
|
-
# Update
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
# Update by_session
|
|
124
|
+
by_sess = data.setdefault("by_session", {})
|
|
125
|
+
bs = by_sess.setdefault(session_id, {"invocations": 0, "orig_tokens": 0, "comp_tokens": 0, "tokens_saved": 0})
|
|
126
|
+
bs["invocations"] += 1
|
|
127
|
+
bs["orig_tokens"] += orig_tokens
|
|
128
|
+
bs["comp_tokens"] += comp_tokens
|
|
129
|
+
bs["tokens_saved"] += tokens_saved
|
|
127
130
|
|
|
128
131
|
# Record event in history (keep last 100 entries)
|
|
129
132
|
history_entry = {
|
|
130
133
|
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
131
134
|
"harness": harness,
|
|
135
|
+
"session_id": session_id,
|
|
132
136
|
"tool": tool_name,
|
|
133
137
|
"source_class": source_class,
|
|
134
138
|
"strategy": strategy,
|
|
@@ -145,6 +149,34 @@ class TokenTracker:
|
|
|
145
149
|
def get_stats(self) -> Dict[str, Any]:
|
|
146
150
|
return self._load()
|
|
147
151
|
|
|
152
|
+
def get_session_stats(self, session_id: Optional[str] = None) -> Dict[str, Any]:
|
|
153
|
+
session_id = session_id or detect_session_id()
|
|
154
|
+
data = self._load()
|
|
155
|
+
sess_data = data.get("by_session", {}).get(session_id)
|
|
156
|
+
if not sess_data:
|
|
157
|
+
return {
|
|
158
|
+
"session_id": session_id,
|
|
159
|
+
"invocations": 0,
|
|
160
|
+
"orig_tokens": 0,
|
|
161
|
+
"comp_tokens": 0,
|
|
162
|
+
"tokens_saved": 0,
|
|
163
|
+
"savings_pct": 0.0,
|
|
164
|
+
"est_usd_saved": 0.0
|
|
165
|
+
}
|
|
166
|
+
orig = sess_data.get("orig_tokens", 0)
|
|
167
|
+
saved = sess_data.get("tokens_saved", 0)
|
|
168
|
+
comp = sess_data.get("comp_tokens", 0)
|
|
169
|
+
pct = round((saved / orig * 100), 2) if orig > 0 else 0.0
|
|
170
|
+
usd = round((saved / 1_000_000.0) * EST_USD_PER_1M_TOKENS, 4)
|
|
171
|
+
return {
|
|
172
|
+
"session_id": session_id,
|
|
173
|
+
"invocations": sess_data.get("invocations", 0),
|
|
174
|
+
"orig_tokens": orig,
|
|
175
|
+
"comp_tokens": comp,
|
|
176
|
+
"tokens_saved": saved,
|
|
177
|
+
"savings_pct": pct,
|
|
178
|
+
"est_usd_saved": usd
|
|
179
|
+
}
|
|
148
180
|
|
|
149
181
|
def reset(self):
|
|
150
182
|
if self.stats_path.exists():
|
|
@@ -7,9 +7,12 @@ import os
|
|
|
7
7
|
import json
|
|
8
8
|
import shutil
|
|
9
9
|
from pathlib import Path
|
|
10
|
-
from typing import Dict, Any, List
|
|
10
|
+
from typing import Dict, Any, List, Tuple
|
|
11
11
|
|
|
12
12
|
KNOWN_CONFIG_PATHS = [
|
|
13
|
+
Path.home() / ".gemini" / "config" / "mcp_config.json",
|
|
14
|
+
Path.home() / ".gemini" / "mcp_config.json",
|
|
15
|
+
Path.home() / ".antigravity" / "mcp_config.json",
|
|
13
16
|
Path.home() / ".codex" / "config.json",
|
|
14
17
|
Path.home() / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json",
|
|
15
18
|
Path.home() / ".cursor" / "mcp.json",
|
|
@@ -41,9 +44,9 @@ class ConfigManager:
|
|
|
41
44
|
modified = False
|
|
42
45
|
for server_name, server_cfg in mcp_servers.items():
|
|
43
46
|
command = server_cfg.get("command")
|
|
47
|
+
if not command or command == "shrinkwrap":
|
|
48
|
+
continue # Skip remote/URL servers or already wrapped servers
|
|
44
49
|
args = server_cfg.get("args", [])
|
|
45
|
-
if command == "shrinkwrap":
|
|
46
|
-
continue # Already wrapped
|
|
47
50
|
|
|
48
51
|
# Wrap command: shrinkwrap wrap-stdio -- command args...
|
|
49
52
|
new_command = "shrinkwrap"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: shrinkwrap-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Drop-in 90%+ Token Compaction Proxy for MCP & AI Agent Tools
|
|
5
5
|
Author: ShrinkWrap Maintainers
|
|
6
6
|
License-Expression: MIT
|
|
@@ -23,9 +23,9 @@ Copy and paste this instruction into your AI coding assistant (Antigravity, Clau
|
|
|
23
23
|
```text
|
|
24
24
|
Please install and set up ShrinkWrap on my computer to reduce my MCP and tool token usage by ~90%:
|
|
25
25
|
1. Install shrinkwrap-cli: `pip install shrinkwrap-cli`
|
|
26
|
-
|
|
27
26
|
2. Auto-wrap active MCP configs: run `shrinkwrap install`
|
|
28
27
|
3. Verify setup: run `shrinkwrap status` and `shrinkwrap benchmark`
|
|
28
|
+
4. At the end of every run or task, run `shrinkwrap session --markdown` and include token savings in your final output.
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### Manual Installation
|
|
@@ -34,8 +34,14 @@ pip install shrinkwrap-cli
|
|
|
34
34
|
shrinkwrap install
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### Terminal Side-by-Side Visual Comparison
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
|
|
37
42
|
### Benchmark Summary & Token Savings
|
|
38
43
|
|
|
44
|
+
|
|
39
45
|
Measured across production developer payloads:
|
|
40
46
|
|
|
41
47
|
| Payload Benchmark | Tool Source | Strategy | Original Tokens | Compacted Tokens | Token Reduction |
|
|
@@ -161,13 +167,31 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
161
167
|
|
|
162
168
|
---
|
|
163
169
|
|
|
170
|
+
## Session Token Analytics & Agent End-of-Run Reporting
|
|
171
|
+
|
|
172
|
+
AI agents operating in multi-step task loops can report their exact tokens saved, reduction percentages, and estimated financial savings at the conclusion of a task.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Print active run session summary
|
|
176
|
+
shrinkwrap session
|
|
177
|
+
|
|
178
|
+
# Generate agent-ready Markdown snippet for final user turn responses
|
|
179
|
+
shrinkwrap session --markdown
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Output Example (`--markdown`):
|
|
183
|
+
> **ShrinkWrap Session Savings**: **42,478 tokens saved** (81.02% reduction across 5 tool invocations, ~$0.1274 USD saved).
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
164
187
|
## Command Reference
|
|
165
188
|
|
|
166
189
|
| Command | Usage | Description |
|
|
167
190
|
|---|---|---|
|
|
168
191
|
| `shrinkwrap install` | `shrinkwrap install [--dry-run]` | Auto-discover and wrap local MCP server configurations |
|
|
169
192
|
| `shrinkwrap wrap-stdio` | `shrinkwrap wrap-stdio -- <cmd> [args]` | Execute stdio proxy for target server command |
|
|
170
|
-
| `shrinkwrap
|
|
193
|
+
| `shrinkwrap session` | `shrinkwrap session [--markdown] [--json]` | Report token usage and savings for the current agent session |
|
|
194
|
+
| `shrinkwrap gain` | `shrinkwrap gain [--history] [--json] [--reset]` | Display cumulative token savings analytics and harness breakdowns |
|
|
171
195
|
| `shrinkwrap fetch` | `shrinkwrap fetch <sw-ref:handle>` | Retrieve raw payload from memory buffer |
|
|
172
196
|
| `shrinkwrap status` | `shrinkwrap status` | Display system status and capability gate information |
|
|
173
197
|
| `shrinkwrap benchmark` | `shrinkwrap benchmark` | Run benchmark test suite |
|
|
@@ -179,3 +203,4 @@ shrinkwrap rollback ~/.codex/config.json
|
|
|
179
203
|
## License
|
|
180
204
|
|
|
181
205
|
MIT License. See [LICENSE](LICENSE) for details.
|
|
206
|
+
|
|
@@ -29,3 +29,30 @@ def test_retrieval_buffer():
|
|
|
29
29
|
assert ref.startswith("sw-ref:")
|
|
30
30
|
fetched = global_buffer.fetch(ref)
|
|
31
31
|
assert fetched == data
|
|
32
|
+
|
|
33
|
+
def test_session_tracker(tmp_path):
|
|
34
|
+
from shrinkwrap.engine.tracker import TokenTracker
|
|
35
|
+
stats_file = tmp_path / "stats.json"
|
|
36
|
+
tracker = TokenTracker(stats_path=stats_file)
|
|
37
|
+
|
|
38
|
+
tracker.record_event(
|
|
39
|
+
orig_tokens=1000,
|
|
40
|
+
comp_tokens=100,
|
|
41
|
+
orig_bytes=5000,
|
|
42
|
+
comp_bytes=500,
|
|
43
|
+
source_class="mcp",
|
|
44
|
+
tool_name="test_tool",
|
|
45
|
+
strategy="structured_summary",
|
|
46
|
+
harness="test_agent",
|
|
47
|
+
session_id="test_session_123"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
sess = tracker.get_session_stats(session_id="test_session_123")
|
|
51
|
+
assert sess["session_id"] == "test_session_123"
|
|
52
|
+
assert sess["invocations"] == 1
|
|
53
|
+
assert sess["orig_tokens"] == 1000
|
|
54
|
+
assert sess["comp_tokens"] == 100
|
|
55
|
+
assert sess["tokens_saved"] == 900
|
|
56
|
+
assert sess["savings_pct"] == 90.0
|
|
57
|
+
assert sess["est_usd_saved"] > 0
|
|
58
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|