tokensafe 4.4.1 → 4.4.2
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/.codex-plugin/plugin.json +1 -1
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/mcp_server.py +1 -1
- package/src/telemetry_sync.py +1 -1
- package/src/type_slicer.py +35 -15
- package/src/version_checker.py +1 -1
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
5
5
|
"homepage": "https://tokensafe.dev",
|
|
6
6
|
"license": "MIT",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.2",
|
|
5
5
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
6
6
|
"main": "bin/tokensafe.js",
|
|
7
7
|
"bin": {
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.2",
|
|
5
5
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
6
6
|
"logo": "assets/logo.png",
|
|
7
7
|
"developerName": "TokenSafe",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "dev.tokensafe/tokensafe",
|
|
4
4
|
"title": "TokenSafe",
|
|
5
5
|
"description": "Your AI agent is smart enough to code all day. Local firewall & zero-loss runtime.",
|
|
6
|
-
"version": "4.4.
|
|
6
|
+
"version": "4.4.2",
|
|
7
7
|
"websiteUrl": "https://tokensafe.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/tokensafe-dev/tokensafe",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"registryType": "npm",
|
|
24
24
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
25
25
|
"identifier": "tokensafe",
|
|
26
|
-
"version": "4.4.
|
|
26
|
+
"version": "4.4.2",
|
|
27
27
|
"runtimeHint": "npx",
|
|
28
28
|
"transport": {
|
|
29
29
|
"type": "stdio"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"registryType": "pypi",
|
|
40
40
|
"registryBaseUrl": "https://pypi.org",
|
|
41
41
|
"identifier": "tokensafe",
|
|
42
|
-
"version": "4.4.
|
|
42
|
+
"version": "4.4.2",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/mcp_server.py
CHANGED
package/src/telemetry_sync.py
CHANGED
|
@@ -241,7 +241,7 @@ class TelemetrySync:
|
|
|
241
241
|
current_last_id = last_id
|
|
242
242
|
headers = {
|
|
243
243
|
"Content-Type": "application/json",
|
|
244
|
-
"User-Agent": "TokenSafe-Sync/4.4.
|
|
244
|
+
"User-Agent": "TokenSafe-Sync/4.4.2"
|
|
245
245
|
}
|
|
246
246
|
if active_key:
|
|
247
247
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/type_slicer.py
CHANGED
|
@@ -27,7 +27,10 @@ from src.paths import resolve_data_dir
|
|
|
27
27
|
class TypeSlicer:
|
|
28
28
|
"""Targeted extractor of external library types and interfaces."""
|
|
29
29
|
|
|
30
|
-
_mem_cache: "OrderedDict[str,
|
|
30
|
+
_mem_cache: "OrderedDict[str, Any]" = OrderedDict()
|
|
31
|
+
# Bumped whenever the slicing algorithm changes: stale slices cached under
|
|
32
|
+
# an older key format can never resurface through L1/L2/L3 (poisoning guard).
|
|
33
|
+
_SLICER_VERSION = "v2"
|
|
31
34
|
_mem_lock = threading.Lock()
|
|
32
35
|
_db_init_done = False
|
|
33
36
|
_db_init_lock = threading.Lock()
|
|
@@ -38,10 +41,10 @@ class TypeSlicer:
|
|
|
38
41
|
cls._mem_cache.clear()
|
|
39
42
|
|
|
40
43
|
@classmethod
|
|
41
|
-
def _mem_put(cls, key: str, val: str, max_items: int = 100) -> None:
|
|
44
|
+
def _mem_put(cls, key: str, val: str, dts_bytes: int = 0, max_items: int = 100) -> None:
|
|
42
45
|
"""Stores entry in LRU memory cache with fixed cap."""
|
|
43
46
|
with cls._mem_lock:
|
|
44
|
-
cls._mem_cache[key] = val
|
|
47
|
+
cls._mem_cache[key] = (val, dts_bytes)
|
|
45
48
|
cls._mem_cache.move_to_end(key)
|
|
46
49
|
if len(cls._mem_cache) > max_items:
|
|
47
50
|
cls._mem_cache.popitem(last=False)
|
|
@@ -283,19 +286,22 @@ class TypeSlicer:
|
|
|
283
286
|
except Exception:
|
|
284
287
|
pass
|
|
285
288
|
|
|
286
|
-
type_key = f"{pkg_name}@{version}::{sym}"
|
|
289
|
+
type_key = f"{pkg_name}@{version}::{sym}::{cls._SLICER_VERSION}"
|
|
287
290
|
|
|
288
291
|
# 1. Check L1 Memory
|
|
289
292
|
with cls._mem_lock:
|
|
290
293
|
if type_key in cls._mem_cache:
|
|
291
294
|
cls._mem_cache.move_to_end(type_key)
|
|
295
|
+
cached = cls._mem_cache[type_key]
|
|
296
|
+
code_val, dts_val = cached if isinstance(cached, tuple) else (cached, 0)
|
|
292
297
|
return {
|
|
293
298
|
"found": True,
|
|
294
299
|
"package": pkg_name,
|
|
295
300
|
"version": version,
|
|
296
301
|
"symbol": sym,
|
|
297
|
-
"type_code":
|
|
298
|
-
"source": "L1_memory"
|
|
302
|
+
"type_code": code_val,
|
|
303
|
+
"source": "L1_memory",
|
|
304
|
+
"_dts_bytes": dts_val
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
# 2. Check L2 SQLite
|
|
@@ -312,7 +318,7 @@ class TypeSlicer:
|
|
|
312
318
|
if row:
|
|
313
319
|
code = row[0]
|
|
314
320
|
dts_b = row[1] if len(row) > 1 and row[1] else 0
|
|
315
|
-
cls._mem_put(type_key, code, max_items=100)
|
|
321
|
+
cls._mem_put(type_key, code, dts_bytes=dts_b, max_items=100)
|
|
316
322
|
return {
|
|
317
323
|
"found": True,
|
|
318
324
|
"package": pkg_name,
|
|
@@ -336,15 +342,26 @@ class TypeSlicer:
|
|
|
336
342
|
from src.team_cache import TeamCache
|
|
337
343
|
team_val = TeamCache.get("3RD_PARTY_DTS", type_key, timeout=0.5)
|
|
338
344
|
if team_val:
|
|
339
|
-
|
|
345
|
+
code_block = team_val
|
|
346
|
+
dts_bytes = 0
|
|
347
|
+
if team_val.startswith("{"):
|
|
348
|
+
try:
|
|
349
|
+
p_val = json.loads(team_val)
|
|
350
|
+
if isinstance(p_val, dict) and "code" in p_val:
|
|
351
|
+
code_block = str(p_val["code"])
|
|
352
|
+
dts_bytes = int(p_val.get("dts_bytes", 0) or 0)
|
|
353
|
+
except Exception:
|
|
354
|
+
pass
|
|
355
|
+
|
|
356
|
+
cls._mem_put(type_key, code_block, dts_bytes=dts_bytes, max_items=100)
|
|
340
357
|
# Backfill L2
|
|
341
358
|
back_conn = None
|
|
342
359
|
try:
|
|
343
360
|
back_conn = sqlite3.connect(db_path, timeout=5.0)
|
|
344
361
|
back_conn.execute("""
|
|
345
|
-
INSERT OR REPLACE INTO type_cache (type_key, package_name, version, symbol, type_code, cached_at)
|
|
346
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
347
|
-
""", (type_key, pkg_name, version, sym,
|
|
362
|
+
INSERT OR REPLACE INTO type_cache (type_key, package_name, version, symbol, type_code, dts_bytes, cached_at)
|
|
363
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
364
|
+
""", (type_key, pkg_name, version, sym, code_block, dts_bytes, int(time.time())))
|
|
348
365
|
cls._maybe_evict(back_conn)
|
|
349
366
|
back_conn.commit()
|
|
350
367
|
except Exception:
|
|
@@ -360,8 +377,9 @@ class TypeSlicer:
|
|
|
360
377
|
"package": pkg_name,
|
|
361
378
|
"version": version,
|
|
362
379
|
"symbol": sym,
|
|
363
|
-
"type_code":
|
|
364
|
-
"source": "L3_team_cache"
|
|
380
|
+
"type_code": code_block,
|
|
381
|
+
"source": "L3_team_cache",
|
|
382
|
+
"_dts_bytes": dts_bytes
|
|
365
383
|
}
|
|
366
384
|
except Exception:
|
|
367
385
|
pass
|
|
@@ -397,7 +415,7 @@ class TypeSlicer:
|
|
|
397
415
|
}
|
|
398
416
|
|
|
399
417
|
# 5. Save to L1, L2 SQLite, and broadcast to L3 Team Sync
|
|
400
|
-
cls._mem_put(type_key, code_block, max_items=100)
|
|
418
|
+
cls._mem_put(type_key, code_block, dts_bytes=dts_bytes, max_items=100)
|
|
401
419
|
|
|
402
420
|
save_conn = None
|
|
403
421
|
try:
|
|
@@ -419,7 +437,9 @@ class TypeSlicer:
|
|
|
419
437
|
|
|
420
438
|
try:
|
|
421
439
|
from src.team_cache import TeamCache
|
|
422
|
-
|
|
440
|
+
payload = json.dumps({"code": code_block, "dts_bytes": dts_bytes}, ensure_ascii=False)
|
|
441
|
+
tokens_saved = max(30, (dts_bytes // 4) if dts_bytes else len(code_block) // 4)
|
|
442
|
+
TeamCache.put("3RD_PARTY_DTS", type_key, payload, tokens_saved=tokens_saved)
|
|
423
443
|
except Exception:
|
|
424
444
|
pass
|
|
425
445
|
|
package/src/version_checker.py
CHANGED
|
@@ -17,7 +17,7 @@ import urllib.request
|
|
|
17
17
|
import urllib.error
|
|
18
18
|
from typing import Dict, Any, Optional, Tuple
|
|
19
19
|
|
|
20
|
-
CURRENT_VERSION = "4.4.
|
|
20
|
+
CURRENT_VERSION = "4.4.2"
|
|
21
21
|
CACHE_TTL = 86400 # 24 hours
|
|
22
22
|
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
23
23
|
# answer for a full day — otherwise an update released right after an outage
|