tokensafe 4.2.2 → 4.2.3

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.2",
2
+ "version": "4.2.3",
3
3
  "name": "tokensafe",
4
4
  "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
5
5
  "author": {
package/kimi.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.2.2",
3
+ "version": "4.2.3",
4
4
  "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous 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.2",
4
+ "version": "4.2.3",
5
5
  "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous 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.2.2",
4
+ "version": "4.2.3",
5
5
  "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
6
6
  "logo": "https://tokensafe.dev/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 agent isn't getting dumber, your context is full of trash. Local firewall & zero-loss runtime.",
6
- "version": "4.2.2",
6
+ "version": "4.2.3",
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": "4.2.2",
33
+ "version": "4.2.3",
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": "4.2.2",
49
+ "version": "4.2.3",
50
50
  "runtimeHint": "uvx",
51
51
  "transport": {
52
52
  "type": "stdio"
package/src/fts_index.py CHANGED
@@ -179,9 +179,13 @@ class CodeFTSIndex:
179
179
  continue # File unchanged
180
180
 
181
181
  files_to_index.append((rel_path, full_path, f_mtime, f_size))
182
- if scanned_files >= max_files:
182
+ # Cap the INDEXING work per run, never the walk: files
183
+ # beyond the cap must still enter found_paths, or the
184
+ # prune step below would treat them as deleted on every
185
+ # run (repos > max_files lost their tail permanently).
186
+ if len(files_to_index) >= max_files:
183
187
  break
184
- if scanned_files >= max_files:
188
+ if len(files_to_index) >= max_files:
185
189
  break
186
190
 
187
191
  # Index modified/new files in batches
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.2"
45
+ "version": "4.2.3"
46
46
  }
47
47
 
48
48
  # MCP client attribution: the initialize handshake carries clientInfo, which
package/src/stash.py CHANGED
@@ -58,8 +58,14 @@ def stash_block(content: str, source: str = "tool") -> Tuple[str, str]:
58
58
  )
59
59
 
60
60
  if chars_count > MAX_STASH_CHARS:
61
- # Don't exhaust local disk on massive blobs > 5MB
62
- return hash8, marker
61
+ # Don't exhaust local disk on massive blobs > 5MB — and don't advertise
62
+ # a restore path that would dead-end: without the stored file,
63
+ # expand_ref would return None ("not found or expired").
64
+ honest_marker = (
65
+ f"[TokenSafe folded: #{hash8} ({lines_count} lines / {chars_count} chars omitted) "
66
+ f"— content exceeds the 5 MB stash cap and was not archived]"
67
+ )
68
+ return hash8, honest_marker
63
69
 
64
70
  try:
65
71
  stash_dir = get_stash_dir()
package/src/superseded.py CHANGED
@@ -50,6 +50,8 @@ class SupersededPruner:
50
50
  # action_type: "READ" or "EDIT"
51
51
  file_actions: Dict[str, List[Tuple[int, str]]] = {}
52
52
  step_read_files: Dict[int, str] = {}
53
+ # Claude Code: tool_use ids map reads to their (later) result step
54
+ read_tool_ids: Dict[str, int] = {}
53
55
 
54
56
  for idx, step in enumerate(steps):
55
57
  if not isinstance(step, dict):
@@ -87,6 +89,9 @@ class SupersededPruner:
87
89
  if tname in _READ_TOOLS:
88
90
  file_actions.setdefault(fpath, []).append((idx, "READ"))
89
91
  step_read_files[idx] = fpath
92
+ tool_use_id = str(b.get("id") or "")
93
+ if tool_use_id:
94
+ read_tool_ids[tool_use_id] = idx
90
95
  elif tname in _EDIT_TOOLS:
91
96
  file_actions.setdefault(fpath, []).append((idx, "EDIT"))
92
97
 
@@ -107,25 +112,52 @@ class SupersededPruner:
107
112
  if not superseded_map:
108
113
  return steps, 0, 0, {"pruned_count": 0, "saved_tokens": 0}
109
114
 
115
+ # Claude Code transcripts: the tool RESULT for a read lives in a LATER
116
+ # step's tool_result block (matched by tool_use_id), so the tombstone
117
+ # must land there, not in the read's own (tool_use-only) step.
118
+ superseded_ids: Dict[str, Tuple[int, str, str]] = {}
119
+ for tid, step_idx in read_tool_ids.items():
120
+ if step_idx in superseded_map:
121
+ superseded_ids[tid] = superseded_map[step_idx]
122
+
110
123
  # Apply tombstoning to the tool results of the superseded steps
111
124
  pruned_steps: List[dict] = []
112
125
  orig_tokens_total = 0
113
126
  pruned_tokens_total = 0
114
127
  pruned_count = 0
115
128
 
129
+ def _carries_super_result(s: dict) -> bool:
130
+ """True when this step holds a tool_result whose tool_use_id is superseded."""
131
+ msg = s.get("message") if isinstance(s, dict) else None
132
+ mc = msg.get("content") if isinstance(msg, dict) else None
133
+ if not isinstance(mc, list):
134
+ return False
135
+ return any(
136
+ isinstance(b, dict) and str(b.get("tool_use_id") or "") in superseded_ids
137
+ for b in mc
138
+ )
139
+
116
140
  for idx, step in enumerate(steps):
117
- if idx not in superseded_map:
141
+ if idx not in superseded_map and not (
142
+ superseded_ids and isinstance(step, dict) and _carries_super_result(step)
143
+ ):
118
144
  pruned_steps.append(step)
119
145
  continue
120
146
 
121
- by_step, by_action, fpath = superseded_map[idx]
122
- fname = os.path.basename(fpath)
147
+ same_step = superseded_map.get(idx)
148
+ if same_step:
149
+ by_step, by_action, fpath = same_step
150
+ else:
151
+ # Result-only step (Claude Code): tombstones are chosen per
152
+ # tool_use_id below; the step-level fields stay unused.
153
+ by_step, by_action, fpath = None, None, None
154
+ fname = os.path.basename(fpath) if fpath else ""
123
155
  new_step = json.loads(json.dumps(step)) # deep copy
124
156
  modified = False
125
157
 
126
158
  # Check Antigravity output/content in this step or subsequent tool response step
127
159
  content = new_step.get("content")
128
- if isinstance(content, str) and len(content) > 150:
160
+ if same_step and isinstance(content, str) and len(content) > 150:
129
161
  orig_t = count_tokens(content)
130
162
  _, marker = stash_block(content, source="superseded_read")
131
163
  tombstone = (
@@ -137,17 +169,45 @@ class SupersededPruner:
137
169
  pruned_tokens_total += pruned_t
138
170
  modified = True
139
171
 
140
- # Claude Code message content tool_result blocks
172
+ # Claude Code message content tool_result blocks. Priority: match by
173
+ # tool_use_id (result trails the tool_use across steps); fall back to
174
+ # the same-step rule only for id-less formats (Antigravity exports).
141
175
  msg = new_step.get("message")
142
176
  if isinstance(msg, dict):
143
177
  mc = msg.get("content")
144
178
  if isinstance(mc, list):
145
179
  for block in mc:
146
- if isinstance(block, dict) and block.get("type") == "tool_result":
147
- tc = block.get("content")
148
- if isinstance(tc, str) and len(tc) > 150:
149
- orig_t = count_tokens(tc)
150
- _, marker = stash_block(tc, source="superseded_read")
180
+ if not isinstance(block, dict) or block.get("type") != "tool_result":
181
+ continue
182
+ tid = str(block.get("tool_use_id") or "")
183
+ mapping = superseded_ids.get(tid) if tid else None
184
+ if mapping is None and not tid:
185
+ mapping = superseded_map.get(idx)
186
+ if mapping is None:
187
+ continue
188
+ by_step, by_action, fpath = mapping
189
+ fname = os.path.basename(fpath)
190
+ tc = block.get("content")
191
+ if isinstance(tc, str) and len(tc) > 150:
192
+ orig_t = count_tokens(tc)
193
+ _, marker = stash_block(tc, source="superseded_read")
194
+ tombstone = (
195
+ f"[TokenSafe: Output superseded by step #{by_step + 1} ({by_action.lower()} {fname}) — {marker}]"
196
+ )
197
+ block["content"] = tombstone
198
+ pruned_t = count_tokens(tombstone)
199
+ orig_tokens_total += orig_t
200
+ pruned_tokens_total += pruned_t
201
+ modified = True
202
+ elif isinstance(tc, list) and tc:
203
+ # tool_result content can be a list of text blocks
204
+ text = "\n".join(
205
+ (b.get("text", "") if isinstance(b, dict) else str(b))
206
+ for b in tc
207
+ )
208
+ if len(text) > 150:
209
+ orig_t = count_tokens(text)
210
+ _, marker = stash_block(text, source="superseded_read")
151
211
  tombstone = (
152
212
  f"[TokenSafe: Output superseded by step #{by_step + 1} ({by_action.lower()} {fname}) — {marker}]"
153
213
  )
@@ -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.2"
244
+ "User-Agent": "TokenSafe-Sync/4.2.3"
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.2"
20
+ CURRENT_VERSION = "4.2.3"
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