tokensafe 1.4.6 → 1.4.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Autonomous Zero-Loss Token Economy & Context Optimizer for AI Coding Agents",
5
5
  "main": "bin/tokensafe.js",
6
6
  "bin": {
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agy-token-optimizer",
3
3
  "displayName": "TokenSafe",
4
- "version": "1.4.6",
4
+ "version": "1.4.7",
5
5
  "description": "Zero-Loss Token Economy & Context Optimizer for AI Agents. Compresses prompts, slices AST/tool outputs, and prevents stuck loops.",
6
6
  "logo": "assets/logo.svg",
7
7
  "author": {
package/src/mcp_server.py CHANGED
@@ -31,7 +31,7 @@ from src.guard import TokenSafeGuard
31
31
 
32
32
  SERVER_INFO = {
33
33
  "name": "tokensafe-mcp",
34
- "version": "1.4.6"
34
+ "version": "1.4.7"
35
35
  }
36
36
 
37
37
  TOOLS = [
@@ -236,7 +236,7 @@ class TelemetrySync:
236
236
  total_sent = 0
237
237
  headers = {
238
238
  "Content-Type": "application/json",
239
- "User-Agent": "TokenSafe-Sync/1.4.6"
239
+ "User-Agent": "TokenSafe-Sync/1.4.7"
240
240
  }
241
241
  if active_key:
242
242
  headers["Authorization"] = f"Bearer {active_key}"
@@ -333,15 +333,7 @@ class TelemetrySync:
333
333
  creationflags=flags
334
334
  )
335
335
  except Exception:
336
- # Fallback to daemon thread if process spawn fails
337
- def _worker():
338
- try:
339
- cls.sync(timeout=2.0)
340
- except Exception:
341
- pass
342
-
343
- t = threading.Thread(target=_worker, daemon=True)
344
- t.start()
336
+ pass
345
337
 
346
338
 
347
339
  if __name__ == "__main__":
@@ -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 = "1.4.6"
19
+ CURRENT_VERSION = "1.4.7"
20
20
  CACHE_TTL = 86400 # 24 hours
21
21
 
22
22
  PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -317,18 +317,51 @@ class VersionChecker:
317
317
  force: bool = False
318
318
  ):
319
319
  """
320
- Dispatches notify_os_update in a background non-blocking thread.
320
+ Dispatches notify_os_update in a detached, non-blocking background OS process.
321
+ Avoids in-process daemon threads to prevent OpenSSL cleanup SIGSEGV races during fast CLI exit.
321
322
  """
322
- def _bg():
323
- try:
324
- cls.notify_os_update(
325
- current_version=current_version,
326
- license_key=license_key,
327
- force=force,
328
- timeout=1.5
329
- )
330
- except Exception:
331
- pass
323
+ now = int(time.time())
324
+ cached = cls.load_cache()
325
+ if not force and cached:
326
+ checked_at = cached.get("checked_at", 0)
327
+ update_available = cached.get("update_available", False)
328
+ latest = cached.get("latest_version", current_version)
329
+ last_notified_ver = cached.get("last_os_notify_version", "")
330
+ last_notified_at = cached.get("last_os_notify_at", 0)
331
+
332
+ # If cache is valid and no update is available, skip completely
333
+ if now - checked_at < CACHE_TTL and not update_available:
334
+ return
335
+
336
+ # If update is available but user was already notified within 24h, skip
337
+ if update_available and last_notified_ver == latest and (now - last_notified_at < CACHE_TTL):
338
+ return
332
339
 
333
- t = threading.Thread(target=_bg, daemon=True)
334
- t.start()
340
+ try:
341
+ flags = 0
342
+ if os.name == "nt":
343
+ flags = subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS
344
+ script_path = os.path.abspath(__file__)
345
+ cmd = [sys.executable, script_path, "--check-bg"]
346
+ if force:
347
+ cmd.append("--force")
348
+ subprocess.Popen(
349
+ cmd,
350
+ cwd=PROJECT_ROOT,
351
+ stdout=subprocess.DEVNULL,
352
+ stderr=subprocess.DEVNULL,
353
+ stdin=subprocess.DEVNULL,
354
+ start_new_session=(os.name != "nt"),
355
+ creationflags=flags
356
+ )
357
+ except Exception:
358
+ pass
359
+
360
+
361
+ if __name__ == "__main__":
362
+ if "--check-bg" in sys.argv:
363
+ try:
364
+ is_force = "--force" in sys.argv
365
+ VersionChecker.notify_os_update(force=is_force)
366
+ except Exception:
367
+ pass