tokensafe 1.4.6 → 1.4.8
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/hooks/pre_invocation.py +4 -2
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/src/license_manager.py +32 -19
- package/src/mcp_server.py +1 -1
- package/src/telemetry_sync.py +3 -11
- package/src/version_checker.py +47 -14
package/hooks/pre_invocation.py
CHANGED
|
@@ -99,7 +99,8 @@ def main():
|
|
|
99
99
|
"target_file": compaction["target_file"],
|
|
100
100
|
"symbol": compaction["symbol"],
|
|
101
101
|
"traits": compaction["traits"],
|
|
102
|
-
"tier": tier
|
|
102
|
+
"tier": tier,
|
|
103
|
+
"model": payload.get("model") or os.environ.get("AGY_MODEL") or os.environ.get("MODEL") or "gemini-3.8-flash"
|
|
103
104
|
}
|
|
104
105
|
)
|
|
105
106
|
|
|
@@ -149,7 +150,8 @@ def main():
|
|
|
149
150
|
"turns": invocation_num,
|
|
150
151
|
"total_accum_orig": orig_hist_tokens,
|
|
151
152
|
"read_files": stats.get("read_files_count", 0),
|
|
152
|
-
"edited_files": stats.get("edited_files_count", 0)
|
|
153
|
+
"edited_files": stats.get("edited_files_count", 0),
|
|
154
|
+
"model": payload.get("model") or os.environ.get("AGY_MODEL") or os.environ.get("MODEL") or "gemini-3.8-flash"
|
|
153
155
|
}
|
|
154
156
|
)
|
|
155
157
|
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-token-optimizer",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.8",
|
|
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/license_manager.py
CHANGED
|
@@ -16,6 +16,8 @@ from typing import Dict, Any, Tuple, Optional
|
|
|
16
16
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
17
17
|
DATA_DIR = os.path.join(PROJECT_ROOT, "data")
|
|
18
18
|
LICENSE_FILE = os.path.join(DATA_DIR, "license.json")
|
|
19
|
+
GLOBAL_DATA_DIR = os.path.expanduser("~/.tokensafe")
|
|
20
|
+
GLOBAL_LICENSE_FILE = os.path.join(GLOBAL_DATA_DIR, "license.json")
|
|
19
21
|
|
|
20
22
|
# Master Public Key for client-side offline verification (RFC 8032 Ed25519)
|
|
21
23
|
DEFAULT_ED25519_PUBLIC_KEY = os.environ.get("TOKENSAFE_PUBLIC_KEY", "3911e2ffe5ad07ee23be392b88f238af302f9d3a0bf51881de8b5e0e6af71430")
|
|
@@ -276,34 +278,45 @@ class LicenseManager:
|
|
|
276
278
|
|
|
277
279
|
@classmethod
|
|
278
280
|
def get_active_license_key(cls) -> str:
|
|
279
|
-
"""Retrieves active raw license key string from env or
|
|
281
|
+
"""Retrieves active raw license key string from env or persistent license.json files."""
|
|
280
282
|
key = os.environ.get("TOKENSAFE_LICENSE_KEY", "").strip()
|
|
281
|
-
if not key
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
283
|
+
if not key:
|
|
284
|
+
for p in (LICENSE_FILE, GLOBAL_LICENSE_FILE):
|
|
285
|
+
if os.path.exists(p):
|
|
286
|
+
try:
|
|
287
|
+
with open(p, "r", encoding="utf-8") as f:
|
|
288
|
+
data = json.load(f)
|
|
289
|
+
candidate = data.get("license_key", "").strip()
|
|
290
|
+
if candidate:
|
|
291
|
+
key = candidate
|
|
292
|
+
break
|
|
293
|
+
except Exception:
|
|
294
|
+
pass
|
|
288
295
|
return key
|
|
289
296
|
|
|
290
297
|
@classmethod
|
|
291
298
|
def save_license(cls, license_key: str) -> Tuple[bool, str]:
|
|
292
|
-
"""Saves a verified license key to local persistent storage."""
|
|
299
|
+
"""Saves a verified license key to local and user global persistent storage."""
|
|
293
300
|
valid, payload, msg = cls.validate_license(license_key)
|
|
294
301
|
if not valid:
|
|
295
302
|
return False, f"Cannot save invalid license: {msg}"
|
|
296
303
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
record = {
|
|
305
|
+
"license_key": license_key,
|
|
306
|
+
"tier": payload.get("tier"),
|
|
307
|
+
"email": payload.get("email"),
|
|
308
|
+
"expires_at": payload.get("expires_at"),
|
|
309
|
+
"trial": payload.get("trial", False),
|
|
310
|
+
"saved_at": int(time.time())
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
for target_dir, target_file in ((DATA_DIR, LICENSE_FILE), (GLOBAL_DATA_DIR, GLOBAL_LICENSE_FILE)):
|
|
314
|
+
try:
|
|
315
|
+
os.makedirs(target_dir, exist_ok=True)
|
|
316
|
+
with open(target_file, "w", encoding="utf-8") as f:
|
|
317
|
+
json.dump(record, f, indent=2)
|
|
318
|
+
except Exception:
|
|
319
|
+
pass
|
|
307
320
|
|
|
308
321
|
tier_name = payload.get("tier", "").upper()
|
|
309
322
|
trial_note = " (7-Day Trial)" if payload.get("trial") else ""
|
package/src/mcp_server.py
CHANGED
package/src/telemetry_sync.py
CHANGED
|
@@ -215,7 +215,7 @@ class TelemetrySync:
|
|
|
215
215
|
except Exception:
|
|
216
216
|
ts_int = int(time.time())
|
|
217
217
|
|
|
218
|
-
model_name = "
|
|
218
|
+
model_name = os.environ.get("AGY_MODEL") or os.environ.get("MODEL") or "gemini-3.8-flash"
|
|
219
219
|
if r["details"]:
|
|
220
220
|
try:
|
|
221
221
|
det = json.loads(r["details"]) if isinstance(r["details"], str) else r["details"]
|
|
@@ -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.
|
|
239
|
+
"User-Agent": "TokenSafe-Sync/1.4.8"
|
|
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
|
-
|
|
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__":
|
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 = "1.4.
|
|
19
|
+
CURRENT_VERSION = "1.4.8"
|
|
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
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
334
|
-
|
|
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
|