tokensafe 1.3.10 → 1.3.12
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 +22 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/src/__init__.py +1 -1
- package/src/distiller_cache.py +6 -0
- package/src/license_manager.py +4 -3
- package/src/version_checker.py +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,28 @@ Traditional AI code interactions suffer from massive context bloat:
|
|
|
93
93
|
|
|
94
94
|
---
|
|
95
95
|
|
|
96
|
+
## 🤯 The Accidental Side Effect: Your AI Stops Hallucinating
|
|
97
|
+
|
|
98
|
+
We originally built TokenSafe for a purely selfish reason: **to stop getting $400 monthly LLM API bills** from running autonomous coding agents.
|
|
99
|
+
|
|
100
|
+
Then something unexpected happened during real-world dogfooding.
|
|
101
|
+
|
|
102
|
+
Our agents didn't just get cheaper — **they wrote noticeably better code, stopped inventing imaginary methods, and eliminated cyclic regression bugs.**
|
|
103
|
+
|
|
104
|
+
Turns out, there's a simple reason for this:
|
|
105
|
+
> **Transformer models don't write bad code because they're stupid. They write bad code because we drown them in 15,000 lines of garbage.**
|
|
106
|
+
|
|
107
|
+
### How stripping 90% of token noise fixes AI code quality:
|
|
108
|
+
|
|
109
|
+
| What Usually Breaks the AI | How TokenSafe Fixes It | The Result |
|
|
110
|
+
| :--- | :--- | :--- |
|
|
111
|
+
| **"Lost in the Middle" Attention Fade**<br>Agent reads a 2,000-line file just to tweak a 10-line helper. The model loses track of imports and invents fictional methods. | **AST Skeletonizer** (`src/slicer.py`) collapses dead code into typed interfaces, keeping only target functions and 1-hop callees full. | **High-Density Signal.** The model sees 100% of the type contracts without drowning in unrelated loops. |
|
|
112
|
+
| **Terminal Log Poisoning**<br>`npm test` or `pytest` fails and dumps 4,000 lines of stack traces and lockfile diffs. The model panics and rewrites unrelated code. | **Command Sanitizer** (`src/command_sanitizer.py`) snips the matrix down to the exact failing assertion line and call frame. | **Laser Focus.** The agent fixes the actual bug instead of hallucinating workarounds for log noise. |
|
|
113
|
+
| **The 5-Attempt Doom Loop**<br>Agent tries a broken fix, fails, tries the exact same broken fix again, and oscillates until your session context limit catches fire. | **Anti-Stuck Loop Guard** (`src/loop_detector.py`) intercepts repeated tool calls and cyclic edits in flight. | **No Cascading Regressions.** The loop is halted before the agent can butcher working modules. |
|
|
114
|
+
| **Vague Human Prompts**<br>*"Hey, fix the auth bug but don't break the cache or whatever."* The model takes creative liberties and breaks three other files. | **TOCP Intent Compactor** (`src/compactor.py`) distills messy instructions into explicit S-Expressions with hard constraint boundaries. | **Zero Ambiguity.** The model executes `(DEBUG auth.ts [jwt] "fix 401 token expiry")` with strict parameter bounds. |
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
96
118
|
## 🛡️ The Hidden Context Killer: MCP Tool Schema Bloat
|
|
97
119
|
|
|
98
120
|
Why do AI coding agent quotas (like Antigravity's **5-Hour Limit** or Claude/OpenAI monthly token budgets) evaporate after just a few prompts?
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-token-optimizer",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.12",
|
|
5
5
|
"description": "Zero-Loss Token Economy & Context Optimizer for AI Agents. Compresses prompts, slices AST/tool outputs, and prevents stuck loops.",
|
|
6
6
|
"logo": "assets/logo.svg",
|
|
7
7
|
"author": {
|
package/src/__init__.py
CHANGED
package/src/distiller_cache.py
CHANGED
|
@@ -19,6 +19,7 @@ class DistillationCache:
|
|
|
19
19
|
_memory_cache: OrderedDict = OrderedDict()
|
|
20
20
|
_MAX_MEMORY_ENTRIES = 1000
|
|
21
21
|
_db_path: Optional[str] = None
|
|
22
|
+
_initialized_dbs: set = set()
|
|
22
23
|
_hits: int = 0
|
|
23
24
|
_misses: int = 0
|
|
24
25
|
|
|
@@ -46,6 +47,9 @@ class DistillationCache:
|
|
|
46
47
|
|
|
47
48
|
@classmethod
|
|
48
49
|
def _init_db(cls, conn: sqlite3.Connection):
|
|
50
|
+
db_path = cls._get_db_path()
|
|
51
|
+
if db_path in cls._initialized_dbs:
|
|
52
|
+
return
|
|
49
53
|
conn.execute("""
|
|
50
54
|
CREATE TABLE IF NOT EXISTS distillation_cache (
|
|
51
55
|
prompt_hash TEXT PRIMARY KEY,
|
|
@@ -57,6 +61,8 @@ class DistillationCache:
|
|
|
57
61
|
);
|
|
58
62
|
""")
|
|
59
63
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_distill_hash ON distillation_cache(prompt_hash);")
|
|
64
|
+
conn.commit()
|
|
65
|
+
cls._initialized_dbs.add(db_path)
|
|
60
66
|
|
|
61
67
|
@classmethod
|
|
62
68
|
def get(cls, prompt_text: str) -> Optional[str]:
|
package/src/license_manager.py
CHANGED
|
@@ -18,7 +18,7 @@ DATA_DIR = os.path.join(PROJECT_ROOT, "data")
|
|
|
18
18
|
LICENSE_FILE = os.path.join(DATA_DIR, "license.json")
|
|
19
19
|
|
|
20
20
|
# Master Public Key for client-side offline verification (RFC 8032 Ed25519)
|
|
21
|
-
DEFAULT_ED25519_PUBLIC_KEY = "
|
|
21
|
+
DEFAULT_ED25519_PUBLIC_KEY = os.environ.get("TOKENSAFE_PUBLIC_KEY", "3911e2ffe5ad07ee23be392b88f238af302f9d3a0bf51881de8b5e0e6af71430")
|
|
22
22
|
# Private key for cloud server signing (never distributed to client, loaded strictly from environment)
|
|
23
23
|
DEFAULT_ED25519_PRIVATE_KEY = os.environ.get("TOKENSAFE_PRIVATE_KEY", "")
|
|
24
24
|
# Rotated HMAC salt for backward compatibility with TS1 legacy licenses
|
|
@@ -170,7 +170,8 @@ class LicenseManager:
|
|
|
170
170
|
if not priv_hex:
|
|
171
171
|
raise ValueError("TOKENSAFE_PRIVATE_KEY environment variable is required to generate license signatures.")
|
|
172
172
|
priv_bytes = bytes.fromhex(priv_hex)
|
|
173
|
-
|
|
173
|
+
pub_hex = os.environ.get("TOKENSAFE_PUBLIC_KEY") or DEFAULT_ED25519_PUBLIC_KEY
|
|
174
|
+
pub_bytes = bytes.fromhex(pub_hex)
|
|
174
175
|
sig_raw = _ed25519_sign_bytes(payload_bytes, priv_bytes, pub_bytes)
|
|
175
176
|
sig_b64 = base64.urlsafe_b64encode(sig_raw).decode("ascii").rstrip("=")
|
|
176
177
|
return f"TS2.{payload_b64}.{sig_b64}"
|
|
@@ -211,7 +212,7 @@ class LicenseManager:
|
|
|
211
212
|
|
|
212
213
|
# 1. Asymmetric Ed25519 Verification (TS2)
|
|
213
214
|
if schema_ver == "TS2":
|
|
214
|
-
pub_hex = public_key or DEFAULT_ED25519_PUBLIC_KEY
|
|
215
|
+
pub_hex = public_key or os.environ.get("TOKENSAFE_PUBLIC_KEY") or DEFAULT_ED25519_PUBLIC_KEY
|
|
215
216
|
try:
|
|
216
217
|
pub_bytes = bytes.fromhex(pub_hex)
|
|
217
218
|
padded_sig = sig_part + "=" * (-len(sig_part) % 4)
|
package/src/version_checker.py
CHANGED
|
@@ -14,7 +14,7 @@ import urllib.request
|
|
|
14
14
|
import urllib.error
|
|
15
15
|
from typing import Dict, Any, Optional, Tuple
|
|
16
16
|
|
|
17
|
-
CURRENT_VERSION = "1.3.
|
|
17
|
+
CURRENT_VERSION = "1.3.12"
|
|
18
18
|
CACHE_TTL = 86400 # 24 hours
|
|
19
19
|
|
|
20
20
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|