tokensafe 2.4.0 → 2.4.2
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 +192 -435
- package/hooks/claude_code_hook.py +57 -5
- package/hooks/pre_invocation.py +26 -14
- package/package.json +1 -1
- package/plugin.json +2 -2
- package/rules/AGENTS.md +1 -0
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +4 -0
- package/skills/token-optimizer/references/mcp-tools.md +24 -0
- package/src/adapter_core.py +2 -0
- package/src/cli.py +9 -0
- package/src/governor.py +32 -3
- package/src/history_compactor.py +111 -28
- package/src/mcp_server.py +29 -11
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +21 -9
package/src/version_checker.py
CHANGED
|
@@ -16,7 +16,7 @@ import urllib.request
|
|
|
16
16
|
import urllib.error
|
|
17
17
|
from typing import Dict, Any, Optional, Tuple
|
|
18
18
|
|
|
19
|
-
CURRENT_VERSION = "2.4.
|
|
19
|
+
CURRENT_VERSION = "2.4.2"
|
|
20
20
|
CACHE_TTL = 86400 # 24 hours
|
|
21
21
|
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
22
22
|
# answer for a full day — otherwise an update released right after an outage
|
|
@@ -24,9 +24,18 @@ CACHE_TTL = 86400 # 24 hours
|
|
|
24
24
|
# "broken" while the backend was redeploying).
|
|
25
25
|
FALLBACK_CACHE_TTL = 900 # 15 minutes
|
|
26
26
|
|
|
27
|
+
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
28
|
+
# Script-mode guard: notify_os_update_background spawns this file directly
|
|
29
|
+
# (`python3 src/version_checker.py --check-bg`), which sets sys.path[0] to the
|
|
30
|
+
# src/ directory — `import src.*` fails unless PROJECT_ROOT is on the path
|
|
31
|
+
# FIRST. The old ordering (import before path setup) made every background
|
|
32
|
+
# update check die silently in the bare except of __main__, so version_cache.json
|
|
33
|
+
# was never written and the update dialog never appeared.
|
|
34
|
+
if PROJECT_ROOT not in sys.path:
|
|
35
|
+
sys.path.insert(0, PROJECT_ROOT)
|
|
36
|
+
|
|
27
37
|
from src.paths import resolve_data_dir
|
|
28
38
|
|
|
29
|
-
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
30
39
|
DATA_DIR = resolve_data_dir()
|
|
31
40
|
CACHE_FILE = os.path.join(DATA_DIR, "version_cache.json")
|
|
32
41
|
CLOUD_CHECK_URL = os.environ.get("TOKENSAFE_VERSION_URL", "https://api.tokensafe.dev/api/version/check")
|
|
@@ -351,19 +360,22 @@ class VersionChecker:
|
|
|
351
360
|
except OSError:
|
|
352
361
|
pass # claim is best-effort; never block the dialog entirely on fs errors
|
|
353
362
|
|
|
354
|
-
try:
|
|
355
|
-
cached["last_os_notify_version"] = latest
|
|
356
|
-
cached["last_os_notify_at"] = now
|
|
357
|
-
cls.save_cache(cached)
|
|
358
|
-
except Exception:
|
|
359
|
-
pass
|
|
360
|
-
|
|
361
363
|
try:
|
|
362
364
|
dispatched = cls.show_os_dialog(
|
|
363
365
|
current_version=current_version,
|
|
364
366
|
latest_version=latest,
|
|
365
367
|
update_command=cmd
|
|
366
368
|
)
|
|
369
|
+
if dispatched:
|
|
370
|
+
# Mark "notified" only after the dialog actually dispatched.
|
|
371
|
+
# Writing it earlier let a silently TCC-blocked osascript buy
|
|
372
|
+
# 24h of dialog silence without the user ever seeing anything.
|
|
373
|
+
try:
|
|
374
|
+
cached["last_os_notify_version"] = latest
|
|
375
|
+
cached["last_os_notify_at"] = now
|
|
376
|
+
cls.save_cache(cached)
|
|
377
|
+
except Exception:
|
|
378
|
+
pass
|
|
367
379
|
return dispatched
|
|
368
380
|
finally:
|
|
369
381
|
# Release the dialog claim so a future version can notify again.
|