tokensafe 4.2.9 → 4.2.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/.codex-plugin/plugin.json +1 -1
- package/assets/logo.png +0 -0
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +2 -2
- package/server.json +3 -3
- package/src/dashboard.py +1 -0
- package/src/mcp_server.py +15 -2
- package/src/telemetry_sync.py +1 -1
- package/src/tokenizer.py +21 -15
- package/src/version_checker.py +1 -1
package/assets/logo.png
CHANGED
|
Binary file
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.11",
|
|
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.2.
|
|
4
|
+
"version": "4.2.11",
|
|
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,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.11",
|
|
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
|
-
"logo": "
|
|
6
|
+
"logo": "assets/logo.png",
|
|
7
7
|
"developerName": "TokenSafe",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "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.2.
|
|
6
|
+
"version": "4.2.11",
|
|
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.2.
|
|
26
|
+
"version": "4.2.11",
|
|
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.2.
|
|
42
|
+
"version": "4.2.11",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/dashboard.py
CHANGED
|
@@ -41,6 +41,7 @@ def render_bar(percentage: float, width: int = 24) -> str:
|
|
|
41
41
|
EVENT_NAMES = {
|
|
42
42
|
"PROMPT": "Prompt Compactor (TOCP)",
|
|
43
43
|
"TOOL_READ": "File Line Slicer (AST)",
|
|
44
|
+
"RAW_SLICE": "Raw Line Slice (explicit range)",
|
|
44
45
|
"AST_SKELETON": "AST Skeletonizer (Signatures)",
|
|
45
46
|
"GRAPH_SKELETON": "Graph-Guided Slicer (Call-Graph)",
|
|
46
47
|
"GRAPH_TOPOLOGY": "Architecture Graph (God Nodes)",
|
package/src/mcp_server.py
CHANGED
|
@@ -42,7 +42,7 @@ from src.paths import get_active_workspace, is_plugin_or_system_dir
|
|
|
42
42
|
|
|
43
43
|
SERVER_INFO = {
|
|
44
44
|
"name": "tokensafe-mcp",
|
|
45
|
-
"version": "4.2.
|
|
45
|
+
"version": "4.2.11"
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
# MCP client attribution: the initialize handshake carries clientInfo, which
|
|
@@ -1005,10 +1005,23 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
1005
1005
|
content, err = _read_line_slice(path, start_line, end_line)
|
|
1006
1006
|
if err:
|
|
1007
1007
|
return _fallback_error("smart_read_file", err)
|
|
1008
|
+
slice_lines = (content or "").splitlines()
|
|
1009
|
+
slice_first = start_line if start_line is not None else 1
|
|
1010
|
+
slice_last = slice_first + len(slice_lines) - 1 if slice_lines else max(1, slice_first - 1)
|
|
1011
|
+
range_label = f"{slice_first}-{slice_last}" if slice_lines else str(slice_first)
|
|
1008
1012
|
prefetch_block = ""
|
|
1009
1013
|
if not sym_clean or eff_dep_mode == "full":
|
|
1010
1014
|
prefetch_block, _ = DependencyPrefetcher.prefetch_for_file(path)
|
|
1011
|
-
|
|
1015
|
+
slice_header = f"// [TOCP Raw Slice: lines {range_label} of {os.path.basename(path)}]\n"
|
|
1016
|
+
delivered = (prefetch_block or "") + slice_header + (content or "")
|
|
1017
|
+
tracker.record_event(
|
|
1018
|
+
session_id=_mcp_session_id(),
|
|
1019
|
+
event_type="RAW_SLICE",
|
|
1020
|
+
original_tokens=max(200, st.st_size // 4),
|
|
1021
|
+
optimized_tokens=count_tokens(delivered),
|
|
1022
|
+
details={"file": os.path.basename(path), "lines": range_label, "symbol": sym_clean[:120]}
|
|
1023
|
+
)
|
|
1024
|
+
return {"content": [{"type": "text", "text": delivered}]}
|
|
1012
1025
|
|
|
1013
1026
|
if symbol:
|
|
1014
1027
|
# Team pre-warm hit: a teammate already skeletonized this symbol
|
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.2.
|
|
244
|
+
"User-Agent": "TokenSafe-Sync/4.2.11"
|
|
245
245
|
}
|
|
246
246
|
if active_key:
|
|
247
247
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/tokenizer.py
CHANGED
|
@@ -33,6 +33,16 @@ class TokenCounter:
|
|
|
33
33
|
r"""'s|'t|'re|'ve|'m|'ll|'d|[a-zA-Z\u00C0-\u024F\u0400-\u04FF_]+|\d{1,3}|[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\u3040-\u30FF\u31F0-\u31FF\uAC00-\uD7AF]+|[^\w\s]+|\s+"""
|
|
34
34
|
)
|
|
35
35
|
|
|
36
|
+
# Script detection via C-level regex scans — replaces per-char Python loops
|
|
37
|
+
# that previously dominated the hot path (~46% of runtime on mixed text).
|
|
38
|
+
_CYRILLIC_RE = re.compile(r"[\u0400-\u04FF]")
|
|
39
|
+
_CJK_RE = re.compile(
|
|
40
|
+
r"[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\u3040-\u30FF\u31F0-\u31FF\uAC00-\uD7AF]"
|
|
41
|
+
)
|
|
42
|
+
# English / code identifier subword split (hoisted: avoids the re-module
|
|
43
|
+
# cache lookup on every word of every payload).
|
|
44
|
+
_SUBWORD_REGEX = re.compile(r"[A-Z]?[a-z]+|[A-Z]+(?=[A-Z][a-z]|\d|\W|$)|\d+")
|
|
45
|
+
|
|
36
46
|
@classmethod
|
|
37
47
|
def count(cls, text: Optional[str]) -> int:
|
|
38
48
|
"""Calculate or estimate token count for any text."""
|
|
@@ -59,9 +69,9 @@ class TokenCounter:
|
|
|
59
69
|
# Check if whitespace
|
|
60
70
|
if chunk.isspace():
|
|
61
71
|
if "\n" in chunk:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
tokens +=
|
|
72
|
+
newlines = chunk.count("\n")
|
|
73
|
+
tokens += newlines
|
|
74
|
+
tokens += (len(chunk) - newlines) // 4
|
|
65
75
|
else:
|
|
66
76
|
# In BPE, single spaces are merged into adjacent word tokens (e.g. " world").
|
|
67
77
|
# Only indentations (e.g., 4 spaces) add extra tokens.
|
|
@@ -79,17 +89,13 @@ class TokenCounter:
|
|
|
79
89
|
tokens += max(1, (len(chunk) + 2) // 3)
|
|
80
90
|
continue
|
|
81
91
|
|
|
82
|
-
# Alphabetic words: Check script
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
or '\u31F0' <= char <= '\u31FF' # Katakana Phonetic Extensions
|
|
90
|
-
or '\uAC00' <= char <= '\uD7AF' # Hangul syllables
|
|
91
|
-
for char in chunk
|
|
92
|
-
)
|
|
92
|
+
# Alphabetic words: Check script. ASCII chunks (the dominant case for
|
|
93
|
+
# code and English payloads) cannot be Cyrillic or CJK — skip the scan.
|
|
94
|
+
if chunk.isascii():
|
|
95
|
+
is_cyrillic = is_cjk = False
|
|
96
|
+
else:
|
|
97
|
+
is_cyrillic = cls._CYRILLIC_RE.search(chunk) is not None
|
|
98
|
+
is_cjk = cls._CJK_RE.search(chunk) is not None
|
|
93
99
|
|
|
94
100
|
if is_cjk:
|
|
95
101
|
# CJK: typically ~1.8 tokens per character
|
|
@@ -106,7 +112,7 @@ class TokenCounter:
|
|
|
106
112
|
tokens += max(3, (len(chunk) + 2) // 3)
|
|
107
113
|
else:
|
|
108
114
|
# English / Code identifier
|
|
109
|
-
subwords =
|
|
115
|
+
subwords = cls._SUBWORD_REGEX.findall(chunk)
|
|
110
116
|
if subwords:
|
|
111
117
|
for sub in subwords:
|
|
112
118
|
if len(sub) <= 7:
|
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.2.
|
|
20
|
+
CURRENT_VERSION = "4.2.11"
|
|
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
|