tokensafe 1.4.13 → 1.4.15
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/__pycache__/pre_tool_use.cpython-313.pyc +0 -0
- 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 +34 -9
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.15"
|
|
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:
|
|
@@ -166,6 +174,11 @@ class VersionChecker:
|
|
|
166
174
|
|
|
167
175
|
return None
|
|
168
176
|
|
|
177
|
+
@staticmethod
|
|
178
|
+
def _posix_single_quote(text: str) -> str:
|
|
179
|
+
"""Quotes text for safe embedding inside a single-quoted shell string."""
|
|
180
|
+
return "'" + text.replace("'", "'\\''") + "'"
|
|
181
|
+
|
|
169
182
|
@classmethod
|
|
170
183
|
def show_os_dialog(
|
|
171
184
|
cls,
|
|
@@ -181,14 +194,24 @@ class VersionChecker:
|
|
|
181
194
|
|
|
182
195
|
if plat == "darwin":
|
|
183
196
|
try:
|
|
184
|
-
|
|
197
|
+
# TCC-safe: driving Terminal.app via AppleScript requires an Automation
|
|
198
|
+
# permission prompt that background (hook-spawned) processes can never
|
|
199
|
+
# satisfy, which made "Update Now" silently fail. `do shell script` needs
|
|
200
|
+
# no such permission. The updater runs inside a LOGIN shell so that
|
|
201
|
+
# profile-managed PATH entries (nvm, homebrew, volta, ~/.local/bin…)
|
|
202
|
+
# resolve the `tokensafe` executable; a bare non-interactive shell
|
|
203
|
+
# would not see them and log "command not found".
|
|
204
|
+
inner_cmd = f"nohup {update_command} > /tmp/tokensafe-update.log 2>&1 &"
|
|
205
|
+
shell_cmd = (
|
|
206
|
+
'SHELL_BIN=${SHELL:-/bin/zsh}; [ -x "$SHELL_BIN" ] || SHELL_BIN=/bin/zsh; '
|
|
207
|
+
f'nohup "$SHELL_BIN" -lc {cls._posix_single_quote(inner_cmd)} >/dev/null 2>&1 &'
|
|
208
|
+
)
|
|
209
|
+
# Escape the shell command for embedding inside an AppleScript string literal
|
|
210
|
+
escaped_shell = shell_cmd.replace("\\", "\\\\").replace('"', '\\"')
|
|
185
211
|
apple_script = f'''
|
|
186
212
|
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
213
|
if button returned of dialogResult is "Update Now" then
|
|
188
|
-
|
|
189
|
-
activate
|
|
190
|
-
do script "{escaped_cmd}"
|
|
191
|
-
end tell
|
|
214
|
+
do shell script "{escaped_shell}"
|
|
192
215
|
end if
|
|
193
216
|
'''
|
|
194
217
|
subprocess.Popen(
|
|
@@ -330,7 +353,9 @@ class VersionChecker:
|
|
|
330
353
|
last_notified_at = cached.get("last_os_notify_at", 0)
|
|
331
354
|
|
|
332
355
|
# If cache is valid and no update is available, skip completely
|
|
333
|
-
|
|
356
|
+
# (ttl-aware: offline fallback entries expire after FALLBACK_CACHE_TTL)
|
|
357
|
+
ttl = int(cached.get("ttl", CACHE_TTL))
|
|
358
|
+
if now - checked_at < ttl and not update_available:
|
|
334
359
|
return
|
|
335
360
|
|
|
336
361
|
# If update is available but user was already notified within 24h, skip
|