tokensafe 1.3.10 → 1.3.11

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "description": "Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents",
5
5
  "main": "bin/tokensafe.js",
6
6
  "bin": {
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agy-token-optimizer",
3
3
  "displayName": "TokenSafe",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
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
@@ -2,5 +2,5 @@
2
2
  TokenSafe: Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents.
3
3
  """
4
4
 
5
- __version__ = "1.3.10"
5
+ __version__ = "1.3.11"
6
6
  __author__ = "TokenSafe Team"
@@ -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]:
@@ -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.10"
17
+ CURRENT_VERSION = "1.3.11"
18
18
  CACHE_TTL = 86400 # 24 hours
19
19
 
20
20
  PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))