tokensafe 3.1.3 → 3.1.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "3.1.3",
4
+ "version": "3.1.5",
5
5
  "description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
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": "3.1.3",
4
+ "version": "3.1.5",
5
5
  "description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
6
6
  "logo": "assets/logo.svg",
7
7
  "author": {
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "dev.tokensafe/tokensafe",
4
4
  "title": "TokenSafe",
5
5
  "description": "Reduce your AI bills by up to 99% locally: focused code, warm prompt caches & zero secret leaks.",
6
- "version": "3.1.3",
6
+ "version": "3.1.5",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -30,7 +30,7 @@
30
30
  "registryType": "npm",
31
31
  "registryBaseUrl": "https://registry.npmjs.org",
32
32
  "identifier": "tokensafe",
33
- "version": "3.1.3",
33
+ "version": "3.1.5",
34
34
  "runtimeHint": "npx",
35
35
  "transport": {
36
36
  "type": "stdio"
@@ -46,7 +46,7 @@
46
46
  "registryType": "pypi",
47
47
  "registryBaseUrl": "https://pypi.org",
48
48
  "identifier": "tokensafe",
49
- "version": "3.1.3",
49
+ "version": "3.1.5",
50
50
  "runtimeHint": "uvx",
51
51
  "transport": {
52
52
  "type": "stdio"
@@ -86,10 +86,16 @@ def _gate_all_top_level_defs_present(full_text: str, skel_text: str, ext: str =
86
86
 
87
87
 
88
88
  def _def_line_for(full_text: str, short: str) -> Optional[str]:
89
- """Language-agnostic: the first structural-definition line naming the symbol."""
89
+ """Language-agnostic: the first line that DEFINES the symbol — the keyword
90
+ followed by the symbol name as a word. A bare `short in s` also matches
91
+ annotation usages ('def connect(self, node: "Node", ...)') and picked the
92
+ WRONG line, failing the signature gate on real repos (QA sweep:
93
+ diagrams/__init__.py)."""
94
+ pattern = re.compile(
95
+ rf"\b(?:{_DEF_KEYWORD_RE.pattern[2:-2]})\s+{re.escape(short)}\b")
90
96
  for line in full_text.splitlines():
91
97
  s = line.strip()
92
- if short in s and _DEF_KEYWORD_RE.search(s):
98
+ if pattern.search(s):
93
99
  return s
94
100
  return None
95
101
 
@@ -99,7 +105,12 @@ def _gate_signature_line_match(full_text: str, skel_text: str, symbol: str) -> b
99
105
  (normalized) in the skeleton."""
100
106
  short = symbol.rsplit(".", 1)[-1]
101
107
  line = _def_line_for(full_text, short)
102
- return bool(line) and line in skel_text
108
+ if not line:
109
+ return False
110
+ # The skeletonizer normalizes signature quotes to single style
111
+ # (model="large" -> model='large') — compare modulo quote style
112
+ # (QA sweep: face_recognition/api.py).
113
+ return line in skel_text or line.replace('"', "'") in skel_text.replace('"', "'")
103
114
 
104
115
 
105
116
  def symbol_read_gates(full_text: str, skel_text: str, symbol: str, ext: str = ".py") -> Dict[str, bool]:
@@ -442,7 +453,7 @@ class RealRepoBenchmark:
442
453
  if not pattern:
443
454
  return {"status": "skipped", "reason": "no pattern pre-registered"}
444
455
  proc = subprocess.run(["git", "grep", "-n", pattern, "--", search_dir],
445
- cwd=root, capture_output=True, text=True, timeout=120)
456
+ cwd=root, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
446
457
  raw_lines = [ln for ln in (proc.stdout or "").splitlines() if ln.strip()]
447
458
  if not raw_lines:
448
459
  return {"status": "skipped", "reason": f"no matches for '{pattern}'"}
@@ -474,7 +485,7 @@ class RealRepoBenchmark:
474
485
 
475
486
  def measure_git_diff(self, root: str) -> Dict[str, Any]:
476
487
  count = subprocess.run(["git", "rev-list", "--count", "HEAD"], cwd=root,
477
- capture_output=True, text=True, timeout=60)
488
+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60)
478
489
  try:
479
490
  if int((count.stdout or "0").strip() or 0) < 2:
480
491
  return {"status": "skipped", "reason": "insufficient history for git diff"}
@@ -707,7 +718,7 @@ class RealRepoBenchmark:
707
718
  return {"status": "skipped", "reason": f"{junk} ({len(full_text.splitlines())} lines) is within the {cap_lines}-line cap — nothing to save"}
708
719
  if rewritten:
709
720
  capped = subprocess.run(rewritten, shell=True, cwd=root,
710
- capture_output=True, text=True, timeout=60)
721
+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60)
711
722
  capped_text = capped.stdout or ""
712
723
  note = f"rewritten: {rewritten}"
713
724
  else:
package/src/compactor.py CHANGED
@@ -267,7 +267,7 @@ class PromptCompactor:
267
267
  )
268
268
  FILE_REGEX = re.compile(
269
269
  r'(?:'
270
- r'(?:[\w\-\./\\][\w\-\./\\ ]*[\/\\])?[\w\-\.]+\.(?:' + "|".join(_FILE_EXTS) + r')\b'
270
+ r'(?:[\w\-\./\\@+()()][\w\-\./\\@+()() ]*[\/\\])?[\w\-\.+()()]+\.(?:' + "|".join(_FILE_EXTS) + r')\b'
271
271
  r'|(?:\.env(?:\.[\w\-]+)?|\.gitignore|\.dockerignore|\.prettierrc[\w\.\-]*|\.eslintrc[\w\.\-]*|\.npmignore|\.npmrc|\.yarnrc)'
272
272
  r'|\b(?:Dockerfile(?:\.[\w\-]+)?|Makefile|Procfile|Gemfile|Vagrantfile|Containerfile)\b'
273
273
  r'|\b(?:README(?:\.md)?|LICENSE|CHANGELOG(?:\.md)?)\b'
@@ -467,6 +467,22 @@ class PromptCompactor:
467
467
  # Extract file if present
468
468
  files = cls.FILE_REGEX.findall(distilled)
469
469
  target_file = cls._trim_path_noise(files[0]) if files else ""
470
+ # Path-fidelity anchor: the distiller LLM occasionally
471
+ # mangles or drops the file path; the ORIGINAL prompt is
472
+ # ground truth. If the distilled target does not appear
473
+ # verbatim in the source prompt, prefer the original's
474
+ # own first file match (deterministic, no LLM trust).
475
+ orig_files = cls.FILE_REGEX.findall(raw_text)
476
+ if orig_files:
477
+ orig_first = cls._trim_path_noise(orig_files[0])
478
+ if not target_file:
479
+ target_file = orig_first
480
+ elif target_file != orig_first and orig_first.endswith(target_file):
481
+ # Partial path: the LLM dropped leading segments
482
+ # ('lib/x.py' for 'activesupport/lib/x.py') —
483
+ # upgrade to the full original path (QA sweep:
484
+ # rails/linkswift).
485
+ target_file = orig_first
470
486
 
471
487
  # Extract symbol
472
488
  symbol = cls.extract_symbol(raw_text, target_file)
package/src/guard.py CHANGED
@@ -583,7 +583,7 @@ class TokenSafeGuard:
583
583
  try:
584
584
  res = subprocess.run(
585
585
  ["git", "-C", target_dir, "status", "--porcelain", "-uall"],
586
- capture_output=True, text=True, timeout=5
586
+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=5
587
587
  )
588
588
  if res.returncode == 0:
589
589
  for line in res.stdout.splitlines():
@@ -40,6 +40,45 @@ def parse_tool_arguments(raw: Any) -> Optional[dict]:
40
40
  return None
41
41
 
42
42
 
43
+ def _py_literals_outside_strings(s: str) -> str:
44
+ """Replaces Python literals (True/False/None) with JSON equivalents ONLY
45
+ outside string literals; string content is copied verbatim."""
46
+ out: List[str] = []
47
+ buf: List[str] = []
48
+ in_str = False
49
+ quote = ""
50
+ escaped = False
51
+
52
+ def _flush() -> None:
53
+ if buf:
54
+ seg = "".join(buf)
55
+ buf.clear()
56
+ seg = re.sub(r"\bTrue\b", "true", seg)
57
+ seg = re.sub(r"\bFalse\b", "false", seg)
58
+ seg = re.sub(r"\bNone\b", "null", seg)
59
+ out.append(seg)
60
+
61
+ for ch in s:
62
+ if in_str:
63
+ out.append(ch) # string content is data — copied verbatim
64
+ if escaped:
65
+ escaped = False
66
+ elif ch == "\\":
67
+ escaped = True
68
+ elif ch == quote:
69
+ in_str = False
70
+ continue
71
+ if ch in ('"', "'"):
72
+ _flush()
73
+ in_str = True
74
+ quote = ch
75
+ out.append(ch)
76
+ continue
77
+ buf.append(ch)
78
+ _flush()
79
+ return "".join(out)
80
+
81
+
43
82
  def repair_json(s: str) -> Optional[str]:
44
83
  """Best-effort repair of a broken JSON string. Returns repaired text that
45
84
  strict json.loads accepts, or None when nothing sensible can be produced."""
@@ -47,9 +86,12 @@ def repair_json(s: str) -> Optional[str]:
47
86
  if not s:
48
87
  return None
49
88
 
50
- py_fixed = re.sub(r"\bTrue\b", "true", s)
51
- py_fixed = re.sub(r"\bFalse\b", "false", py_fixed)
52
- py_fixed = re.sub(r"\bNone\b", "null", py_fixed)
89
+ # Python-literal replacement is STRING-AWARE: blind re.sub rewrote
90
+ # 'None'/'True' INSIDE string values — a music-index fixture keyed by
91
+ # artist names turned "Sixpence None the Richer" into "Sixpence null the
92
+ # Richer" and fabricated keys (QA sweep). Only literals OUTSIDE strings
93
+ # are Python dialect.
94
+ py_fixed = _py_literals_outside_strings(s)
53
95
 
54
96
  ctrl_fixed = _escape_control_chars_in_strings(py_fixed)
55
97
 
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": "3.1.3"
45
+ "version": "3.1.5"
46
46
  }
47
47
 
48
48
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -228,7 +228,7 @@ class TelemetrySync:
228
228
  current_last_id = last_id
229
229
  headers = {
230
230
  "Content-Type": "application/json",
231
- "User-Agent": "TokenSafe-Sync/3.1.3"
231
+ "User-Agent": "TokenSafe-Sync/3.1.5"
232
232
  }
233
233
  if active_key:
234
234
  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 = "3.1.3"
20
+ CURRENT_VERSION = "3.1.5"
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