tokensafe 1.4.13 → 1.4.14
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/README.md +24 -2
- package/bin/tokensafe.js +11 -1
- package/hooks/pre_invocation.py +1 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/src/command_sanitizer.py +42 -3
- package/src/compactor.py +3 -1
- package/src/deepseek_distiller.py +1 -1
- package/src/distiller.py +52 -1
- package/src/graph_engine.py +4 -1
- package/src/guard.py +54 -17
- package/src/installer.py +108 -1
- package/src/license_manager.py +39 -2
- package/src/loop_detector.py +73 -26
- package/src/mcp_server.py +58 -4
- package/src/metrics.py +46 -15
- package/src/skeletonizer.py +73 -10
- package/src/slicer.py +16 -6
- package/src/telemetry_sync.py +62 -12
- package/src/tokenizer.py +12 -3
- package/src/version_checker.py +20 -8
package/src/version_checker.py
CHANGED
|
@@ -16,8 +16,13 @@ import urllib.request
|
|
|
16
16
|
import urllib.error
|
|
17
17
|
from typing import Dict, Any, Optional, Tuple
|
|
18
18
|
|
|
19
|
-
CURRENT_VERSION = "1.4.
|
|
19
|
+
CURRENT_VERSION = "1.4.14"
|
|
20
20
|
CACHE_TTL = 86400 # 24 hours
|
|
21
|
+
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
22
|
+
# answer for a full day — otherwise an update released right after an outage
|
|
23
|
+
# stays invisible for up to 24h (this is exactly why the macOS dialog appeared
|
|
24
|
+
# "broken" while the backend was redeploying).
|
|
25
|
+
FALLBACK_CACHE_TTL = 900 # 15 minutes
|
|
21
26
|
|
|
22
27
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
23
28
|
DATA_DIR = os.path.join(PROJECT_ROOT, "data")
|
|
@@ -100,12 +105,14 @@ class VersionChecker:
|
|
|
100
105
|
|
|
101
106
|
if not force_fetch and cached:
|
|
102
107
|
checked_at = cached.get("checked_at", 0)
|
|
103
|
-
|
|
108
|
+
ttl = int(cached.get("ttl", CACHE_TTL))
|
|
109
|
+
if now - checked_at < ttl:
|
|
104
110
|
return cached
|
|
105
111
|
|
|
106
|
-
# Default payload
|
|
112
|
+
# Default payload (offline fallback — cached only briefly, see FALLBACK_CACHE_TTL)
|
|
107
113
|
payload = {
|
|
108
114
|
"checked_at": now,
|
|
115
|
+
"ttl": FALLBACK_CACHE_TTL,
|
|
109
116
|
"client_version": current_version,
|
|
110
117
|
"latest_version": current_version,
|
|
111
118
|
"min_supported_version": "1.1.0",
|
|
@@ -128,6 +135,7 @@ class VersionChecker:
|
|
|
128
135
|
if resp.status == 200:
|
|
129
136
|
data = json.loads(resp.read().decode("utf-8"))
|
|
130
137
|
data["checked_at"] = now
|
|
138
|
+
data.pop("ttl", None) # authoritative server answer: full 24h cache
|
|
131
139
|
cls.save_cache(data)
|
|
132
140
|
return data
|
|
133
141
|
except Exception:
|
|
@@ -181,14 +189,16 @@ class VersionChecker:
|
|
|
181
189
|
|
|
182
190
|
if plat == "darwin":
|
|
183
191
|
try:
|
|
192
|
+
# TCC-safe: driving Terminal.app via AppleScript requires an
|
|
193
|
+
# Automation permission prompt that background (hook-spawned)
|
|
194
|
+
# processes can never satisfy, which made "Update Now" silently fail.
|
|
195
|
+
# `do shell script` needs no such permission; prefer the explicit
|
|
196
|
+
# ~/.local/bin path because non-interactive shells lack the user PATH.
|
|
184
197
|
escaped_cmd = update_command.replace('"', '\\"')
|
|
185
198
|
apple_script = f'''
|
|
186
199
|
set dialogResult to display dialog "A new version of TokenSafe (v{latest_version}) is available.\\n\\nCurrent version: v{current_version}\\nLatest version: v{latest_version}\\n\\nWould you like to update now?" with title "TokenSafe Update Available" buttons {{"Later", "Update Now"}} default button "Update Now" with icon note
|
|
187
200
|
if button returned of dialogResult is "Update Now" then
|
|
188
|
-
|
|
189
|
-
activate
|
|
190
|
-
do script "{escaped_cmd}"
|
|
191
|
-
end tell
|
|
201
|
+
do shell script "if [ -x \\"$HOME/.local/bin/tokensafe\\" ]; then CMD=\\"$HOME/.local/bin/tokensafe\\"; else CMD=\\"{escaped_cmd}\\"; fi; nohup \\"$CMD\\" update > /tmp/tokensafe-update.log 2>&1 &"
|
|
192
202
|
end if
|
|
193
203
|
'''
|
|
194
204
|
subprocess.Popen(
|
|
@@ -330,7 +340,9 @@ class VersionChecker:
|
|
|
330
340
|
last_notified_at = cached.get("last_os_notify_at", 0)
|
|
331
341
|
|
|
332
342
|
# If cache is valid and no update is available, skip completely
|
|
333
|
-
|
|
343
|
+
# (ttl-aware: offline fallback entries expire after FALLBACK_CACHE_TTL)
|
|
344
|
+
ttl = int(cached.get("ttl", CACHE_TTL))
|
|
345
|
+
if now - checked_at < ttl and not update_available:
|
|
334
346
|
return
|
|
335
347
|
|
|
336
348
|
# If update is available but user was already notified within 24h, skip
|