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.
- package/.codex-plugin/plugin.json +1 -1
- package/hooks/__pycache__/claude_code_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/cursor_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/kimi_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_invocation.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_tool_use.cpython-312.pyc +0 -0
- package/hooks/__pycache__/session_start.cpython-312.pyc +0 -0
- package/hooks/__pycache__/stop_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/zcode_hook.cpython-312.pyc +0 -0
- package/hooks/pre_tool_use.py +17 -0
- package/hooks/session_start.py +12 -2
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +1 -1
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +6 -1
- package/src/adapter_core.py +91 -12
- package/src/batch_editor.py +36 -2
- package/src/batch_search.py +31 -5
- package/src/cli.py +57 -1
- package/src/command_sanitizer.py +126 -0
- package/src/guard.py +47 -0
- package/src/installer.py +61 -5
- package/src/mcp_server.py +92 -30
- package/src/oumv_gateway.py +326 -37
- package/src/proxy.py +11 -4
- package/src/retrofit.py +467 -99
- package/src/snapshot.py +3 -2
- package/src/telemetry_sync.py +6 -2
- package/src/transcript_analyzer.py +13 -9
- package/src/version_checker.py +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
402
|
-
|
|
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)
|
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.6.
|
|
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
|