tokensafe 4.6.1 → 4.6.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.
@@ -145,7 +145,9 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
145
145
  tool_counts: Dict[str, int] = {}
146
146
  disk_spills = 0
147
147
  tokensafe_calls = 0
148
- schema_matched = False
148
+ # Only branches that positively recognise a schema set this. The Antigravity
149
+ # catch-all matches any {"type": ...} line, so it must not count as recognition.
150
+ explicit_matched = False
149
151
  seen_claude_messages = set()
150
152
 
151
153
  timestamps: List[datetime.datetime] = []
@@ -196,7 +198,7 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
196
198
 
197
199
  # ZCode model-io schema
198
200
  if step.get("type") == "model_io" or ("request" in step and "response" in step and "model" in step):
199
- schema_matched = True
201
+ explicit_matched = True
200
202
  if detected_agent in ("antigravity", "unknown"):
201
203
  detected_agent = "zcode"
202
204
  llm_turns += 1
@@ -255,7 +257,7 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
255
257
  # Claude Code / Kimi JSONL schema
256
258
  msg = step.get("message") if isinstance(step.get("message"), dict) else None
257
259
  if msg is not None:
258
- schema_matched = True
260
+ explicit_matched = True
259
261
  # Claude Code writes one JSONL line per content block, all sharing
260
262
  # the same message.id and repeating the identical usage object.
261
263
  # Count the turn and its tokens once per message id.
@@ -299,7 +301,7 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
299
301
  # Codex event schema
300
302
  payload = step.get("payload") if isinstance(step.get("payload"), dict) else {}
301
303
  if step.get("type") == "event_msg" and payload.get("type") == "token_count":
302
- schema_matched = True
304
+ explicit_matched = True
303
305
  last_u = (payload.get("info") or {}).get("last_token_usage") or {}
304
306
  if isinstance(last_u, dict) and last_u:
305
307
  _track_ts(_parse_iso_ts(step.get("timestamp")))
@@ -318,8 +320,8 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
318
320
  s_type = step.get("type")
319
321
  tool_calls = step.get("tool_calls") or []
320
322
  if s_type or tool_calls or "created_at" in step:
321
- schema_matched = True
322
323
  if s_type == "PLANNER_RESPONSE" or tool_calls:
324
+ explicit_matched = explicit_matched or s_type == "PLANNER_RESPONSE"
323
325
  llm_turns += 1
324
326
  # Timestamps only on real turns: status/heartbeat steps would
325
327
  # otherwise fabricate "gaps" during long tool executions.
@@ -361,7 +363,7 @@ def analyze_transcript(file_path: str, agent_type: str = "antigravity") -> Dict[
361
363
  })
362
364
 
363
365
  schema_warning = None
364
- if not schema_matched:
366
+ if not explicit_matched and llm_turns == 0 and total_input == 0 and total_output == 0:
365
367
  schema_warning = "no recognized transcript schema matched; all metrics are zero"
366
368
  if detected_agent in ("auto", "", "antigravity"):
367
369
  detected_agent = "unknown"
@@ -398,8 +400,10 @@ def compare_transcripts(before_path: str, after_path: str) -> Dict[str, Any]:
398
400
  """
399
401
  Compares two transcripts (A/B testing before vs after TokenSafe optimization).
400
402
  """
401
- a = analyze_transcript(before_path)
402
- b = analyze_transcript(after_path)
403
+ # "auto" lets path-based agent detection decide; the old default label
404
+ # ("antigravity") mislabelled every Claude/Codex/ZCode transcript.
405
+ a = analyze_transcript(before_path, agent_type="auto")
406
+ b = analyze_transcript(after_path, agent_type="auto")
403
407
 
404
408
  if "error" in a:
405
409
  return {"error": f"Before transcript error: {a['error']}"}
@@ -503,4 +507,4 @@ def render_comparison_report(comp: Dict[str, Any]) -> str:
503
507
  lines.append(f"{label:<26} | {b_val:<12} | {a_val:<12} | {pct_str:<14}")
504
508
 
505
509
  lines.append("")
506
- return "\n".join(lines)
510
+ return "\n".join(lines)
@@ -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.6.1"
20
+ CURRENT_VERSION = "4.6.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