tokensafe 1.0.0__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.
Files changed (47) hide show
  1. tokensafe-1.0.0/LICENSE +21 -0
  2. tokensafe-1.0.0/MANIFEST.in +7 -0
  3. tokensafe-1.0.0/PKG-INFO +203 -0
  4. tokensafe-1.0.0/README.md +179 -0
  5. tokensafe-1.0.0/pyproject.toml +56 -0
  6. tokensafe-1.0.0/setup.cfg +4 -0
  7. tokensafe-1.0.0/src/__init__.py +6 -0
  8. tokensafe-1.0.0/src/benchmark.py +232 -0
  9. tokensafe-1.0.0/src/command_sanitizer.py +92 -0
  10. tokensafe-1.0.0/src/compactor.py +233 -0
  11. tokensafe-1.0.0/src/dashboard.py +312 -0
  12. tokensafe-1.0.0/src/deepseek_distiller.py +109 -0
  13. tokensafe-1.0.0/src/dependency_prefetcher.py +193 -0
  14. tokensafe-1.0.0/src/distiller.py +215 -0
  15. tokensafe-1.0.0/src/history_compactor.py +102 -0
  16. tokensafe-1.0.0/src/installer.py +384 -0
  17. tokensafe-1.0.0/src/license_manager.py +148 -0
  18. tokensafe-1.0.0/src/loop_detector.py +87 -0
  19. tokensafe-1.0.0/src/mcp_server.py +201 -0
  20. tokensafe-1.0.0/src/metrics.py +182 -0
  21. tokensafe-1.0.0/src/proxy.py +158 -0
  22. tokensafe-1.0.0/src/secret_redactor.py +134 -0
  23. tokensafe-1.0.0/src/skeletonizer.py +159 -0
  24. tokensafe-1.0.0/src/slicer.py +137 -0
  25. tokensafe-1.0.0/src/tokenizer.py +109 -0
  26. tokensafe-1.0.0/tests/test_benchmark.py +35 -0
  27. tokensafe-1.0.0/tests/test_command_sanitizer.py +44 -0
  28. tokensafe-1.0.0/tests/test_compactor.py +33 -0
  29. tokensafe-1.0.0/tests/test_deepseek_distiller.py +36 -0
  30. tokensafe-1.0.0/tests/test_dependency_prefetcher.py +63 -0
  31. tokensafe-1.0.0/tests/test_distiller.py +122 -0
  32. tokensafe-1.0.0/tests/test_history_compactor.py +47 -0
  33. tokensafe-1.0.0/tests/test_installer.py +105 -0
  34. tokensafe-1.0.0/tests/test_license_manager.py +42 -0
  35. tokensafe-1.0.0/tests/test_loop_detector.py +45 -0
  36. tokensafe-1.0.0/tests/test_mcp_server.py +28 -0
  37. tokensafe-1.0.0/tests/test_metrics.py +41 -0
  38. tokensafe-1.0.0/tests/test_output_guard.py +64 -0
  39. tokensafe-1.0.0/tests/test_secret_redactor.py +96 -0
  40. tokensafe-1.0.0/tests/test_skeletonizer.py +72 -0
  41. tokensafe-1.0.0/tests/test_slicer.py +46 -0
  42. tokensafe-1.0.0/tests/test_tokenizer.py +24 -0
  43. tokensafe-1.0.0/tokensafe.egg-info/PKG-INFO +203 -0
  44. tokensafe-1.0.0/tokensafe.egg-info/SOURCES.txt +45 -0
  45. tokensafe-1.0.0/tokensafe.egg-info/dependency_links.txt +1 -0
  46. tokensafe-1.0.0/tokensafe.egg-info/entry_points.txt +5 -0
  47. tokensafe-1.0.0/tokensafe.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Oleg Savelev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ include README.md
2
+ include LICENSE
3
+ exclude src/cloud_backend.py
4
+ exclude tests/test_cloud_backend.py
5
+ recursive-exclude data *
6
+ recursive-exclude frontend *
7
+ recursive-exclude landing *
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokensafe
3
+ Version: 1.0.0
4
+ Summary: Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents
5
+ Author-email: TokenSafe Team <support@tokensafe.dev>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://tokensafe.dev
8
+ Project-URL: Repository, https://github.com/NekoSin4eG/tokensafe
9
+ Project-URL: Documentation, https://tokensafe.dev
10
+ Project-URL: Issues, https://github.com/NekoSin4eG/tokensafe/issues
11
+ Keywords: ai,llm,tokens,token-optimization,context-window,cursor,claude,antigravity,codex,mcp,mcp-server,ast,proxy
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Build Tools
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: license-file
24
+
25
+ # โšก TokenSafe (`tokensafe`)
26
+
27
+ [![License: MIT](https://img.shields.io/badge/License-MIT-emerald.svg)](https://opensource.org/licenses/MIT)
28
+ [![SWE-bench: Verified](https://img.shields.io/badge/SWE--bench-61.8%25_to_92.1%25_Savings-06B6D4.svg)](https://tokensafe.dev#benchmarks)
29
+ [![Python: 3.10+](https://img.shields.io/badge/Python-3.10+-3B82F6.svg)](https://python.org)
30
+ [![Trial: 7 Days Free](https://img.shields.io/badge/Trial-7_Days_Free-10B981.svg)](https://tokensafe.dev#pricing)
31
+
32
+ > **Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents.**
33
+ > Slashes LLM token costs by **60%โ€“90%** with zero quality loss. Built for **Google Antigravity, OpenAI Codex, Cursor, Claude Desktop, Z.ai Code, Windsurf & Cline**.
34
+
35
+ ๐ŸŒ **Official Website:** [https://tokensafe.dev](https://tokensafe.dev)
36
+
37
+ ---
38
+
39
+ ## โšก 1-Click Universal Install
40
+
41
+ Install and connect TokenSafe to all detected AI coding agents on your machine in 5 seconds:
42
+
43
+ ```bash
44
+ curl -fsSL https://tokensafe.dev/install.sh | bash
45
+ ```
46
+
47
+ Or clone and run the interactive setup manually:
48
+
49
+ ```bash
50
+ git clone https://github.com/NekoSin4eG/tokensafe.git ~/.tokensafe
51
+ python3 ~/.tokensafe/src/installer.py
52
+ ```
53
+
54
+ ---
55
+
56
+ ## ๐Ÿš€ The Breakthrough: How It Saves 60%โ€“90% Tokens
57
+
58
+ Traditional AI code interactions suffer from massive context bloat:
59
+ 1. **The BPE Token Penalty:** Verbose natural language prompts and filler waste 40%โ€“70% of ingress context.
60
+ 2. **Bulk Tool Dumps:** Reading whole 800+ line files burns 5,000+ tokens per turn when only 20 lines are needed.
61
+ 3. **Stuck Loops & Bloated Diffs:** Terminal `git diff` and repetitive failed commands spiral context into overflow.
62
+
63
+ ### TokenSafe Solves All Three Autonomously:
64
+ - **TOCP Prompt Distillation:** Intercepts prompts and distills intent into lean S-Expressions via **Google Gemini (2.0 Flash), OpenAI ChatGPT (gpt-4o-mini), or DeepSeek-V3** (`-40% to -70%`). Automatically detects `GEMINI_API_KEY`, `OPENAI_API_KEY`, or `DEEPSEEK_API_KEY`.
65
+ - **AST Skeletonization & Slicing:** Folds inactive function bodies into signatures and windows targeted symbols (`-80% to -92%`).
66
+ - **Predictive Dependency Prefetcher:** Attaches imported symbol signatures to eliminate downstream exploratory `read_file` roundtrips.
67
+ - **Output Guard & Loop Guard:** Blocks destructive full-file rewrites on files $\ge 40$ lines and halts command loops.
68
+
69
+ ---
70
+
71
+ ## ๐Ÿค– Universal LLM Distillation Providers
72
+
73
+ TokenSafe supports any key you already have:
74
+
75
+ | Provider | Supported Model | Environment Variable | Config Key |
76
+ |---|---|---|---|
77
+ | **Google Gemini** | `gemini-2.0-flash`, `gemini-1.5-flash` | `GEMINI_API_KEY` | `gemini_api_key` |
78
+ | **OpenAI ChatGPT** | `gpt-4o-mini`, `gpt-4o` | `OPENAI_API_KEY` | `openai_api_key` |
79
+ | **DeepSeek** | `deepseek-chat` (DeepSeek-V3) | `DEEPSEEK_API_KEY` | `deepseek_api_key` |
80
+
81
+ Check active providers anytime with:
82
+ ```bash
83
+ tokensafe providers
84
+ ```
85
+
86
+ ---
87
+
88
+ ## ๐Ÿ“Š Zero-Loss SWE-bench Benchmark Results
89
+
90
+ Verified across 5 real-world production scenarios:
91
+
92
+ | Benchmark Scenario | Task Complexity | Baseline Tokens | TokenSafe Tokens | Reduction | Turn Speedup | Accuracy |
93
+ |---|---|---|---|---|---|---|
94
+ | **Django ORM N+1 Fix** | Multi-file query refactoring | 14,280 | **1,120** | **-92.1%** | +12% faster | 100% Pass |
95
+ | **FastAPI Async Race** | Concurrency bug investigation | 8,640 | **2,940** | **-65.9%** | +10% faster | 100% Pass |
96
+ | **TypeScript Redux Vault** | Full AST symbol refactoring | 18,400 | **2,130** | **-88.4%** | +9% faster | 100% Pass |
97
+ | **Stuck Command Loop** | Subprocess infinite loop | 22,100 | **2,400** | **-89.1%** | Stopped loop | 100% Pass |
98
+ | **Heavy Rewrite Guard** | Whole-file write attempt | 11,300 | **4,310** | **-61.8%** | Forced edit_file | 100% Pass |
99
+
100
+ ---
101
+
102
+ ## ๐Ÿ’Ž Pricing & 7-Day Free Trial
103
+
104
+ | Tier | Price | Highlights |
105
+ |---|---|---|
106
+ | **Hacker (Open-Core)** | **$0** (Free Forever) | 100k tokens/mo, Local Regex compactor, use own DeepSeek key |
107
+ | **Solo Developer** | **$9 / month** | **7-Day Free Trial**, Unlimited Managed DeepSeek-V3, AST Prefetcher, Output Guards |
108
+ | **Engineering Team** | **$29 / dev / mo** | **7-Day Free Trial**, Team Budget Caps, Centralized Ledger, B2B Docker Proxy |
109
+ | **Enterprise** | Custom | On-Premise Nuitka C-compiled Docker Proxy, Custom Compliance, SAML SSO |
110
+
111
+ ๐Ÿ‘‰ **[Start your 7-Day Free Trial on our website](https://tokensafe.dev#pricing)**
112
+
113
+ ---
114
+
115
+ ## ๐Ÿ› ๏ธ CLI Quickstart
116
+
117
+ ```bash
118
+ # View live savings dashboard in your terminal
119
+ tokensafe stats
120
+
121
+ # Open interactive Apple dark-mode HTML dashboard
122
+ tokensafe html
123
+
124
+ # Run the 5-scenario benchmark suite
125
+ tokensafe benchmark
126
+
127
+ # Run the local transparent AI proxy (127.0.0.1:8765/v1)
128
+ tokensafe proxy
129
+
130
+ # Activate your Pro License key
131
+ tokensafe activate TS1.eyJlbWFpbCI6...
132
+ ```
133
+
134
+ ---
135
+
136
+ ## ๐Ÿงช Unit Testing
137
+
138
+ ```bash
139
+ python3 -m unittest discover tests
140
+ ```
141
+ *Zero external runtime dependencies โ€” runs on standard Python 3.10+.*
142
+
143
+ ---
144
+
145
+ ## ๐Ÿ“„ License
146
+ MIT License. Commercial enterprise licenses available for on-premise B2B deployments.
147
+
148
+ ### Export Markdown Report
149
+ ```bash
150
+ ./bin/agy-tokens markdown
151
+ ```
152
+
153
+ ---
154
+
155
+ ## ๐Ÿ“‚ Project Structure
156
+
157
+ ```text
158
+ agy-token-optimizer/
159
+ โ”œโ”€โ”€ plugin.json # Antigravity plugin manifest
160
+ โ”œโ”€โ”€ hooks.json # Lifecycle hook declarations (PreInvocation, PreToolUse, PostToolUse)
161
+ โ”œโ”€โ”€ rules/
162
+ โ”‚ โ””โ”€โ”€ AGENTS.md # TOCP Protocol directives for LLM (prompt-cached)
163
+ โ”œโ”€โ”€ skills/
164
+ โ”‚ โ””โ”€โ”€ token-optimizer/
165
+ โ”‚ โ””โ”€โ”€ SKILL.md # On-demand Antigravity skill
166
+ โ”œโ”€โ”€ proto/
167
+ โ”‚ โ””โ”€โ”€ tocp.proto # Protocol Buffers contract
168
+ โ”œโ”€โ”€ src/
169
+ โ”‚ โ”œโ”€โ”€ tokenizer.py # Zero-dependency calibrated BPE token counter
170
+ โ”‚ โ”œโ”€โ”€ compactor.py # Semantic compactor (Natural Language -> TOCP S-Expr)
171
+ โ”‚ โ”œโ”€โ”€ slicer.py # AST & Line windowing tool optimizer
172
+ โ”‚ โ”œโ”€โ”€ metrics.py # Persistent SQLite metrics engine
173
+ โ”‚ โ””โ”€โ”€ dashboard.py # Visual ANSI terminal & Markdown generator
174
+ โ”œโ”€โ”€ hooks/
175
+ โ”‚ โ”œโ”€โ”€ pre_invocation.py # PreInvocation hook entry point
176
+ โ”‚ โ”œโ”€โ”€ pre_tool_use.py # PreToolUse hook entry point
177
+ โ”‚ โ””โ”€โ”€ post_tool_use.py # PostToolUse hook entry point
178
+ โ”œโ”€โ”€ bin/
179
+ โ”‚ โ””โ”€โ”€ agy-tokens # Executable CLI
180
+ โ”œโ”€โ”€ tests/ # Unit test suite (100% passing)
181
+ โ”œโ”€โ”€ install.sh # One-click installer for Antigravity
182
+ โ””โ”€โ”€ README.md
183
+ ```
184
+
185
+ ---
186
+
187
+ ## ๐Ÿ› ๏ธ Installation & Antigravity Setup
188
+
189
+ Run the installer:
190
+ ```bash
191
+ ./install.sh
192
+ ```
193
+ This symlinks the plugin directly into `~/.gemini/config/plugins/agy-token-optimizer`.
194
+ Antigravity automatically loads it on startup.
195
+
196
+ ---
197
+
198
+ ## ๐Ÿงช Running Unit Tests
199
+
200
+ ```bash
201
+ python3 -m unittest discover tests
202
+ ```
203
+ No external packages required โ€” runs on standard Python 3.10+.
@@ -0,0 +1,179 @@
1
+ # โšก TokenSafe (`tokensafe`)
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-emerald.svg)](https://opensource.org/licenses/MIT)
4
+ [![SWE-bench: Verified](https://img.shields.io/badge/SWE--bench-61.8%25_to_92.1%25_Savings-06B6D4.svg)](https://tokensafe.dev#benchmarks)
5
+ [![Python: 3.10+](https://img.shields.io/badge/Python-3.10+-3B82F6.svg)](https://python.org)
6
+ [![Trial: 7 Days Free](https://img.shields.io/badge/Trial-7_Days_Free-10B981.svg)](https://tokensafe.dev#pricing)
7
+
8
+ > **Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents.**
9
+ > Slashes LLM token costs by **60%โ€“90%** with zero quality loss. Built for **Google Antigravity, OpenAI Codex, Cursor, Claude Desktop, Z.ai Code, Windsurf & Cline**.
10
+
11
+ ๐ŸŒ **Official Website:** [https://tokensafe.dev](https://tokensafe.dev)
12
+
13
+ ---
14
+
15
+ ## โšก 1-Click Universal Install
16
+
17
+ Install and connect TokenSafe to all detected AI coding agents on your machine in 5 seconds:
18
+
19
+ ```bash
20
+ curl -fsSL https://tokensafe.dev/install.sh | bash
21
+ ```
22
+
23
+ Or clone and run the interactive setup manually:
24
+
25
+ ```bash
26
+ git clone https://github.com/NekoSin4eG/tokensafe.git ~/.tokensafe
27
+ python3 ~/.tokensafe/src/installer.py
28
+ ```
29
+
30
+ ---
31
+
32
+ ## ๐Ÿš€ The Breakthrough: How It Saves 60%โ€“90% Tokens
33
+
34
+ Traditional AI code interactions suffer from massive context bloat:
35
+ 1. **The BPE Token Penalty:** Verbose natural language prompts and filler waste 40%โ€“70% of ingress context.
36
+ 2. **Bulk Tool Dumps:** Reading whole 800+ line files burns 5,000+ tokens per turn when only 20 lines are needed.
37
+ 3. **Stuck Loops & Bloated Diffs:** Terminal `git diff` and repetitive failed commands spiral context into overflow.
38
+
39
+ ### TokenSafe Solves All Three Autonomously:
40
+ - **TOCP Prompt Distillation:** Intercepts prompts and distills intent into lean S-Expressions via **Google Gemini (2.0 Flash), OpenAI ChatGPT (gpt-4o-mini), or DeepSeek-V3** (`-40% to -70%`). Automatically detects `GEMINI_API_KEY`, `OPENAI_API_KEY`, or `DEEPSEEK_API_KEY`.
41
+ - **AST Skeletonization & Slicing:** Folds inactive function bodies into signatures and windows targeted symbols (`-80% to -92%`).
42
+ - **Predictive Dependency Prefetcher:** Attaches imported symbol signatures to eliminate downstream exploratory `read_file` roundtrips.
43
+ - **Output Guard & Loop Guard:** Blocks destructive full-file rewrites on files $\ge 40$ lines and halts command loops.
44
+
45
+ ---
46
+
47
+ ## ๐Ÿค– Universal LLM Distillation Providers
48
+
49
+ TokenSafe supports any key you already have:
50
+
51
+ | Provider | Supported Model | Environment Variable | Config Key |
52
+ |---|---|---|---|
53
+ | **Google Gemini** | `gemini-2.0-flash`, `gemini-1.5-flash` | `GEMINI_API_KEY` | `gemini_api_key` |
54
+ | **OpenAI ChatGPT** | `gpt-4o-mini`, `gpt-4o` | `OPENAI_API_KEY` | `openai_api_key` |
55
+ | **DeepSeek** | `deepseek-chat` (DeepSeek-V3) | `DEEPSEEK_API_KEY` | `deepseek_api_key` |
56
+
57
+ Check active providers anytime with:
58
+ ```bash
59
+ tokensafe providers
60
+ ```
61
+
62
+ ---
63
+
64
+ ## ๐Ÿ“Š Zero-Loss SWE-bench Benchmark Results
65
+
66
+ Verified across 5 real-world production scenarios:
67
+
68
+ | Benchmark Scenario | Task Complexity | Baseline Tokens | TokenSafe Tokens | Reduction | Turn Speedup | Accuracy |
69
+ |---|---|---|---|---|---|---|
70
+ | **Django ORM N+1 Fix** | Multi-file query refactoring | 14,280 | **1,120** | **-92.1%** | +12% faster | 100% Pass |
71
+ | **FastAPI Async Race** | Concurrency bug investigation | 8,640 | **2,940** | **-65.9%** | +10% faster | 100% Pass |
72
+ | **TypeScript Redux Vault** | Full AST symbol refactoring | 18,400 | **2,130** | **-88.4%** | +9% faster | 100% Pass |
73
+ | **Stuck Command Loop** | Subprocess infinite loop | 22,100 | **2,400** | **-89.1%** | Stopped loop | 100% Pass |
74
+ | **Heavy Rewrite Guard** | Whole-file write attempt | 11,300 | **4,310** | **-61.8%** | Forced edit_file | 100% Pass |
75
+
76
+ ---
77
+
78
+ ## ๐Ÿ’Ž Pricing & 7-Day Free Trial
79
+
80
+ | Tier | Price | Highlights |
81
+ |---|---|---|
82
+ | **Hacker (Open-Core)** | **$0** (Free Forever) | 100k tokens/mo, Local Regex compactor, use own DeepSeek key |
83
+ | **Solo Developer** | **$9 / month** | **7-Day Free Trial**, Unlimited Managed DeepSeek-V3, AST Prefetcher, Output Guards |
84
+ | **Engineering Team** | **$29 / dev / mo** | **7-Day Free Trial**, Team Budget Caps, Centralized Ledger, B2B Docker Proxy |
85
+ | **Enterprise** | Custom | On-Premise Nuitka C-compiled Docker Proxy, Custom Compliance, SAML SSO |
86
+
87
+ ๐Ÿ‘‰ **[Start your 7-Day Free Trial on our website](https://tokensafe.dev#pricing)**
88
+
89
+ ---
90
+
91
+ ## ๐Ÿ› ๏ธ CLI Quickstart
92
+
93
+ ```bash
94
+ # View live savings dashboard in your terminal
95
+ tokensafe stats
96
+
97
+ # Open interactive Apple dark-mode HTML dashboard
98
+ tokensafe html
99
+
100
+ # Run the 5-scenario benchmark suite
101
+ tokensafe benchmark
102
+
103
+ # Run the local transparent AI proxy (127.0.0.1:8765/v1)
104
+ tokensafe proxy
105
+
106
+ # Activate your Pro License key
107
+ tokensafe activate TS1.eyJlbWFpbCI6...
108
+ ```
109
+
110
+ ---
111
+
112
+ ## ๐Ÿงช Unit Testing
113
+
114
+ ```bash
115
+ python3 -m unittest discover tests
116
+ ```
117
+ *Zero external runtime dependencies โ€” runs on standard Python 3.10+.*
118
+
119
+ ---
120
+
121
+ ## ๐Ÿ“„ License
122
+ MIT License. Commercial enterprise licenses available for on-premise B2B deployments.
123
+
124
+ ### Export Markdown Report
125
+ ```bash
126
+ ./bin/agy-tokens markdown
127
+ ```
128
+
129
+ ---
130
+
131
+ ## ๐Ÿ“‚ Project Structure
132
+
133
+ ```text
134
+ agy-token-optimizer/
135
+ โ”œโ”€โ”€ plugin.json # Antigravity plugin manifest
136
+ โ”œโ”€โ”€ hooks.json # Lifecycle hook declarations (PreInvocation, PreToolUse, PostToolUse)
137
+ โ”œโ”€โ”€ rules/
138
+ โ”‚ โ””โ”€โ”€ AGENTS.md # TOCP Protocol directives for LLM (prompt-cached)
139
+ โ”œโ”€โ”€ skills/
140
+ โ”‚ โ””โ”€โ”€ token-optimizer/
141
+ โ”‚ โ””โ”€โ”€ SKILL.md # On-demand Antigravity skill
142
+ โ”œโ”€โ”€ proto/
143
+ โ”‚ โ””โ”€โ”€ tocp.proto # Protocol Buffers contract
144
+ โ”œโ”€โ”€ src/
145
+ โ”‚ โ”œโ”€โ”€ tokenizer.py # Zero-dependency calibrated BPE token counter
146
+ โ”‚ โ”œโ”€โ”€ compactor.py # Semantic compactor (Natural Language -> TOCP S-Expr)
147
+ โ”‚ โ”œโ”€โ”€ slicer.py # AST & Line windowing tool optimizer
148
+ โ”‚ โ”œโ”€โ”€ metrics.py # Persistent SQLite metrics engine
149
+ โ”‚ โ””โ”€โ”€ dashboard.py # Visual ANSI terminal & Markdown generator
150
+ โ”œโ”€โ”€ hooks/
151
+ โ”‚ โ”œโ”€โ”€ pre_invocation.py # PreInvocation hook entry point
152
+ โ”‚ โ”œโ”€โ”€ pre_tool_use.py # PreToolUse hook entry point
153
+ โ”‚ โ””โ”€โ”€ post_tool_use.py # PostToolUse hook entry point
154
+ โ”œโ”€โ”€ bin/
155
+ โ”‚ โ””โ”€โ”€ agy-tokens # Executable CLI
156
+ โ”œโ”€โ”€ tests/ # Unit test suite (100% passing)
157
+ โ”œโ”€โ”€ install.sh # One-click installer for Antigravity
158
+ โ””โ”€โ”€ README.md
159
+ ```
160
+
161
+ ---
162
+
163
+ ## ๐Ÿ› ๏ธ Installation & Antigravity Setup
164
+
165
+ Run the installer:
166
+ ```bash
167
+ ./install.sh
168
+ ```
169
+ This symlinks the plugin directly into `~/.gemini/config/plugins/agy-token-optimizer`.
170
+ Antigravity automatically loads it on startup.
171
+
172
+ ---
173
+
174
+ ## ๐Ÿงช Running Unit Tests
175
+
176
+ ```bash
177
+ python3 -m unittest discover tests
178
+ ```
179
+ No external packages required โ€” runs on standard Python 3.10+.
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tokensafe"
7
+ version = "1.0.0"
8
+ description = "Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "TokenSafe Team", email = "support@tokensafe.dev" }
12
+ ]
13
+ license = "MIT"
14
+ requires-python = ">=3.10"
15
+ keywords = [
16
+ "ai",
17
+ "llm",
18
+ "tokens",
19
+ "token-optimization",
20
+ "context-window",
21
+ "cursor",
22
+ "claude",
23
+ "antigravity",
24
+ "codex",
25
+ "mcp",
26
+ "mcp-server",
27
+ "ast",
28
+ "proxy"
29
+ ]
30
+ classifiers = [
31
+ "Development Status :: 5 - Production/Stable",
32
+ "Intended Audience :: Developers",
33
+ "Topic :: Software Development :: Build Tools",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.10",
36
+ "Programming Language :: Python :: 3.11",
37
+ "Programming Language :: Python :: 3.12",
38
+ "Programming Language :: Python :: 3.13"
39
+ ]
40
+ dependencies = []
41
+
42
+ [project.urls]
43
+ Homepage = "https://tokensafe.dev"
44
+ Repository = "https://github.com/NekoSin4eG/tokensafe"
45
+ Documentation = "https://tokensafe.dev"
46
+ Issues = "https://github.com/NekoSin4eG/tokensafe/issues"
47
+
48
+ [project.scripts]
49
+ tokensafe = "src.installer:main"
50
+ tokensafe-proxy = "src.proxy:main"
51
+ tokensafe-mcp = "src.mcp_server:main"
52
+ tokensafe-stats = "src.dashboard:main"
53
+
54
+ [tool.setuptools.packages.find]
55
+ include = ["src*"]
56
+ exclude = ["src.cloud_backend*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """
2
+ TokenSafe: Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents.
3
+ """
4
+
5
+ __version__ = "1.0.0"
6
+ __author__ = "TokenSafe Team"