tokensafe 4.2.8 → 4.2.10

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.2.8",
2
+ "version": "4.2.10",
3
3
  "name": "tokensafe",
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
  "author": {
@@ -31,6 +31,6 @@
31
31
  ],
32
32
  "websiteURL": "https://tokensafe.dev",
33
33
  "brandColor": "#10B981",
34
- "logo": "https://tokensafe.dev/logo.png"
34
+ "logo": "https://tokensafe.dev/ts-logo-black-256.png"
35
35
  }
36
36
  }
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="assets/logo.svg" alt="TokenSafe Logo" width="88" height="88" />
2
+ <img src="https://www.tokensafe.dev/ts-logo-transp-big.png" alt="TokenSafe Logo" width="88" height="88" />
3
3
  </p>
4
4
 
5
5
  <h1 align="center">TokenSafe</h1>
package/assets/logo.png CHANGED
Binary file
package/kimi.plugin.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.2.8",
3
+ "version": "4.2.10",
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",
7
- "logo": "https://tokensafe.dev/logo.png",
8
- "icon": "https://tokensafe.dev/logo.png",
9
- "iconUrl": "https://tokensafe.dev/logo.png",
7
+ "logo": "https://tokensafe.dev/ts-logo-black-256.png",
8
+ "icon": "https://tokensafe.dev/ts-logo-black-256.png",
9
+ "iconUrl": "https://tokensafe.dev/ts-logo-black-256.png",
10
10
  "author": {
11
11
  "name": "TokenSafe"
12
12
  },
@@ -15,8 +15,8 @@
15
15
  "shortDescription": "Stop coding agent context rot, destructive rewrites & secret leaks",
16
16
  "developerName": "TokenSafe",
17
17
  "websiteURL": "https://tokensafe.dev",
18
- "logo": "https://tokensafe.dev/logo.png",
19
- "iconUrl": "https://tokensafe.dev/logo.png"
18
+ "logo": "https://tokensafe.dev/ts-logo-black-256.png",
19
+ "iconUrl": "https://tokensafe.dev/ts-logo-black-256.png"
20
20
  },
21
21
  "skills": [
22
22
  "skills/token-optimizer"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "4.2.8",
4
+ "version": "4.2.10",
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.8",
4
+ "version": "4.2.10",
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": "https://tokensafe.dev/logo.png",
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.8",
6
+ "version": "4.2.10",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -16,13 +16,6 @@
16
16
  "sizes": [
17
17
  "96x96"
18
18
  ]
19
- },
20
- {
21
- "src": "https://tokensafe.dev/logo.svg",
22
- "mimeType": "image/svg+xml",
23
- "sizes": [
24
- "any"
25
- ]
26
19
  }
27
20
  ],
28
21
  "packages": [
@@ -30,7 +23,7 @@
30
23
  "registryType": "npm",
31
24
  "registryBaseUrl": "https://registry.npmjs.org",
32
25
  "identifier": "tokensafe",
33
- "version": "4.2.8",
26
+ "version": "4.2.10",
34
27
  "runtimeHint": "npx",
35
28
  "transport": {
36
29
  "type": "stdio"
@@ -46,7 +39,7 @@
46
39
  "registryType": "pypi",
47
40
  "registryBaseUrl": "https://pypi.org",
48
41
  "identifier": "tokensafe",
49
- "version": "4.2.8",
42
+ "version": "4.2.10",
50
43
  "runtimeHint": "uvx",
51
44
  "transport": {
52
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/installer.py CHANGED
@@ -1427,8 +1427,8 @@ WantedBy=default.target
1427
1427
  p["enabled"] = True
1428
1428
  p["updatedAt"] = iso_now
1429
1429
  p["originalSource"] = PROJECT_ROOT
1430
- p["iconUrl"] = "https://tokensafe.dev/logo.png"
1431
- p["logo"] = "https://tokensafe.dev/logo.png"
1430
+ p["iconUrl"] = "https://tokensafe.dev/ts-logo-black-256.png"
1431
+ p["logo"] = "https://tokensafe.dev/ts-logo-black-256.png"
1432
1432
  entry_found = True
1433
1433
  break
1434
1434
  if not entry_found:
@@ -1440,8 +1440,8 @@ WantedBy=default.target
1440
1440
  "updatedAt": iso_now,
1441
1441
  "originalSource": PROJECT_ROOT,
1442
1442
  "origin": "custom",
1443
- "iconUrl": "https://tokensafe.dev/logo.png",
1444
- "logo": "https://tokensafe.dev/logo.png"
1443
+ "iconUrl": "https://tokensafe.dev/ts-logo-black-256.png",
1444
+ "logo": "https://tokensafe.dev/ts-logo-black-256.png"
1445
1445
  })
1446
1446
  cls._atomic_write_json(installed_json, inst_data)
1447
1447
 
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.8"
45
+ "version": "4.2.10"
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
- return {"content": [{"type": "text", "text": (prefetch_block or "") + (content or "")}]}
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/proxy.py CHANGED
@@ -110,7 +110,9 @@ def _blocks_from_content(content: Any, role: str = "user") -> List[Dict[str, Any
110
110
  if not isinstance(blk, dict):
111
111
  continue
112
112
  btype = blk.get("type")
113
- if btype == "text" and isinstance(blk.get("text"), str):
113
+ # Empty text blocks are rejected by strict Anthropic mirrors (z.ai 1214)
114
+ # and carry no information — drop them at the source.
115
+ if btype == "text" and isinstance(blk.get("text"), str) and blk["text"]:
114
116
  nb = {"type": "text", "text": blk["text"]}
115
117
  if isinstance(blk.get("cache_control"), dict):
116
118
  nb["cache_control"] = blk["cache_control"]
@@ -169,9 +171,12 @@ def _translate_openai_payload_to_anthropic(payload: Dict[str, Any]) -> Dict[str,
169
171
 
170
172
  if role == "assistant":
171
173
  blocks: List[Dict[str, Any]] = _blocks_from_content(msg.get("content"), "assistant")
174
+ thinking = msg.get("_tokensafe_thinking") if isinstance(msg.get("_tokensafe_thinking"), list) else []
175
+ has_tool_use = False
172
176
  for tc in (msg.get("tool_calls") or []):
173
177
  if not isinstance(tc, dict):
174
178
  continue
179
+ has_tool_use = True
175
180
  fn = tc.get("function") or {}
176
181
  try:
177
182
  tool_input = json.loads(fn.get("arguments") or "{}")
@@ -188,9 +193,21 @@ def _translate_openai_payload_to_anthropic(payload: Dict[str, Any]) -> Dict[str,
188
193
  "name": fn.get("name") or "unknown",
189
194
  "input": tool_input,
190
195
  })
191
- if not blocks:
192
- blocks = [{"type": "text", "text": ""}]
193
- out_messages.append({"role": "assistant", "content": _collapse_plain_text(blocks) if len(blocks) == 1 and blocks[0].get("type") == "text" else blocks})
196
+ if not blocks and not thinking:
197
+ # An assistant turn with neither text, tool_use, nor thinking is
198
+ # illegal upstream (z.ai answers 1214 "messages parameter illegal").
199
+ continue
200
+ if thinking:
201
+ # Extended-thinking models (GLM via z.ai, Claude): assistant
202
+ # history must carry its thinking blocks back, signature included —
203
+ # thinking first, then text/tool_use. Dropping them (the old
204
+ # ingest behavior) trips strict mirrors with 1214.
205
+ content: Any = thinking + blocks if blocks else list(thinking)
206
+ elif len(blocks) == 1 and blocks[0].get("type") == "text":
207
+ content = _collapse_plain_text(blocks)
208
+ else:
209
+ content = blocks
210
+ out_messages.append({"role": "assistant", "content": content})
194
211
  elif role == "tool":
195
212
  tc_content = msg.get("content")
196
213
  text = tc_content if isinstance(tc_content, str) else json.dumps(tc_content, ensure_ascii=False)
@@ -203,7 +220,13 @@ def _translate_openai_payload_to_anthropic(payload: Dict[str, Any]) -> Dict[str,
203
220
  "content": [{"type": "tool_result", "tool_use_id": msg.get("tool_call_id") or "toolu_call", "content": text}],
204
221
  })
205
222
  elif role == "user":
206
- out_messages.append({"role": "user", "content": _collapse_plain_text(_blocks_from_content(msg.get("content"), "user")) or [{"type": "text", "text": ""}]})
223
+ blocks = _blocks_from_content(msg.get("content"), "user")
224
+ if not blocks:
225
+ # Empty user turns are rejected by strict mirrors — drop instead
226
+ # of emitting {"type":"text","text":""}; adjacent same-role
227
+ # messages are re-merged below, so alternation stays valid.
228
+ continue
229
+ out_messages.append({"role": "user", "content": _collapse_plain_text(blocks)})
207
230
 
208
231
  out: Dict[str, Any] = {
209
232
  "model": payload.get("model") or "claude-3-5-sonnet-latest",
@@ -366,12 +389,20 @@ def _translate_anthropic_payload_to_openai(payload: Dict[str, Any]) -> Dict[str,
366
389
  if role == "assistant":
367
390
  text_parts: List[str] = []
368
391
  tool_calls = []
392
+ thinking_blocks: List[Dict[str, Any]] = []
369
393
  blocks = content if isinstance(content, list) else ([{"type": "text", "text": content}] if isinstance(content, str) else [])
370
394
  for blk in blocks:
371
395
  if not isinstance(blk, dict):
372
396
  continue
373
397
  if blk.get("type") == "text" and isinstance(blk.get("text"), str):
374
398
  text_parts.append(blk["text"])
399
+ elif blk.get("type") in ("thinking", "redacted_thinking"):
400
+ # Side-channel: extended-thinking blocks must survive the
401
+ # OpenAI-form pipeline untouched so the outbound Anthropic
402
+ # translation can restore them (strict mirrors reject
403
+ # assistant history whose tool_use turns lost their thinking
404
+ # prefix — z.ai 1214 "messages parameter is illegal").
405
+ thinking_blocks.append(blk)
375
406
  elif blk.get("type") == "tool_use":
376
407
  tool_calls.append({
377
408
  "id": blk.get("id") or f"call_{blk.get('name', 'tool')}",
@@ -384,6 +415,8 @@ def _translate_anthropic_payload_to_openai(payload: Dict[str, Any]) -> Dict[str,
384
415
  m: Dict[str, Any] = {"role": "assistant", "content": "\n\n".join(text_parts) if text_parts else None}
385
416
  if tool_calls:
386
417
  m["tool_calls"] = tool_calls
418
+ if thinking_blocks:
419
+ m["_tokensafe_thinking"] = thinking_blocks
387
420
  out_messages.append(m)
388
421
  elif role == "user":
389
422
  blocks = content if isinstance(content, list) else ([{"type": "text", "text": content}] if isinstance(content, str) else [])
@@ -1091,6 +1124,12 @@ class TokenSafeProxyHandler(BaseHTTPRequestHandler):
1091
1124
  # itself speaks Anthropic (ingest): the pipeline ran on the internal
1092
1125
  # OpenAI form, and this puts it back into Anthropic shape for upstream.
1093
1126
  payload = _translate_openai_payload_to_anthropic(payload)
1127
+ else:
1128
+ # The ingest thinking side-channel is Anthropic-only — never leak it
1129
+ # into an OpenAI-dialect upstream request.
1130
+ for _m in payload.get("messages") or []:
1131
+ if isinstance(_m, dict):
1132
+ _m.pop("_tokensafe_thinking", None)
1094
1133
 
1095
1134
  headers = {"Content-Type": "application/json"}
1096
1135
  if provider == "anthropic":
@@ -1245,6 +1284,22 @@ class TokenSafeProxyHandler(BaseHTTPRequestHandler):
1245
1284
  with e:
1246
1285
  err_body = e.read()
1247
1286
  ctype = e.headers.get("Content-Type", "application/json") if e.headers else "application/json"
1287
+ # Permanent diagnostics: upstream rejections were previously forwarded
1288
+ # to the client without any server-side trace, making incidents like
1289
+ # z.ai 1214 undiagnosable from proxy.log alone.
1290
+ try:
1291
+ sys.stderr.write(
1292
+ f"[TokenSafe] {self.command} {self.path} -> upstream {e.code}: "
1293
+ f"{err_body[:400].decode('utf-8', 'replace')}\n"
1294
+ )
1295
+ if e.code == 400:
1296
+ sys.stderr.write(
1297
+ "[TokenSafe][debug] upstream-400 payload preview: "
1298
+ f"model={payload.get('model')!r} msgs={len(payload.get('messages') or [])} "
1299
+ f"body[:1200]={json.dumps(payload, ensure_ascii=False)[:1200]}\n"
1300
+ )
1301
+ except Exception:
1302
+ pass
1248
1303
  if provider == "anthropic" and not client_anthropic:
1249
1304
  err_body = _translate_anthropic_error_body(err_body)
1250
1305
  elif client_anthropic and provider != "anthropic":
@@ -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.8"
244
+ "User-Agent": "TokenSafe-Sync/4.2.10"
245
245
  }
246
246
  if active_key:
247
247
  headers["Authorization"] = f"Bearer {active_key}"
@@ -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.8"
20
+ CURRENT_VERSION = "4.2.10"
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