tokensafe 2.6.0 → 2.7.0

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.
@@ -184,6 +184,12 @@ def main():
184
184
  response = handle(event, payload if isinstance(payload, dict) else {})
185
185
  except Exception:
186
186
  response = {}
187
+ if event in ("UserPromptSubmit", "PreToolUse", "PostToolUse", "Stop"):
188
+ try:
189
+ from src.telemetry_sync import TelemetrySync
190
+ TelemetrySync.sync_background(throttle_seconds=0.0 if event == "Stop" else 20.0)
191
+ except Exception:
192
+ pass
187
193
  print(json.dumps(response))
188
194
 
189
195
 
@@ -78,6 +78,12 @@ def main():
78
78
  response = _allow(event)
79
79
  if not isinstance(response, dict) or not response:
80
80
  response = _allow(event)
81
+ if event in ("beforeShellExecution", "beforeReadFile", "beforeSubmitPrompt", "stop"):
82
+ try:
83
+ from src.telemetry_sync import TelemetrySync
84
+ TelemetrySync.sync_background(throttle_seconds=0.0 if event == "stop" else 20.0)
85
+ except Exception:
86
+ pass
81
87
  print(json.dumps(response))
82
88
 
83
89
 
@@ -25,7 +25,7 @@ def main():
25
25
  # Non-blocking telemetry sync trigger (detached background process)
26
26
  try:
27
27
  from src.telemetry_sync import TelemetrySync
28
- TelemetrySync.sync_background(throttle_seconds=60.0)
28
+ TelemetrySync.sync_background(throttle_seconds=20.0)
29
29
  except Exception:
30
30
  pass
31
31
 
@@ -74,10 +74,10 @@ def main():
74
74
  tracker = MetricsTracker()
75
75
  inject_steps = []
76
76
 
77
- # 0. Asynchronous telemetry sync (detached & throttled to 60s)
77
+ # 0. Asynchronous telemetry sync (detached & throttled to 20s)
78
78
  try:
79
79
  from src.telemetry_sync import TelemetrySync
80
- TelemetrySync.sync_background(throttle_seconds=60.0)
80
+ TelemetrySync.sync_background(throttle_seconds=20.0)
81
81
  except Exception:
82
82
  pass
83
83
 
@@ -28,6 +28,15 @@ from src.license_manager import LicenseManager
28
28
  from src.secret_redactor import SecretRedactor
29
29
  from src.guard import TokenSafeGuard
30
30
 
31
+
32
+ def _trigger_bg_sync():
33
+ try:
34
+ from src.telemetry_sync import TelemetrySync
35
+ TelemetrySync.sync_background(throttle_seconds=20.0)
36
+ except Exception:
37
+ pass
38
+
39
+
31
40
  def main():
32
41
  try:
33
42
  raw_input = sys.stdin.read()
@@ -67,6 +76,7 @@ def main():
67
76
  "decision": "force_ask",
68
77
  "reason": loop_msg
69
78
  }))
79
+ _trigger_bg_sync()
70
80
  return
71
81
 
72
82
  response = {"decision": "allow"}
@@ -92,6 +102,7 @@ def main():
92
102
  "decision": "deny",
93
103
  "reason": f"šŸ›”ļø TokenSafe Guard: {guard_res.reason}"
94
104
  }))
105
+ _trigger_bg_sync()
95
106
  return
96
107
 
97
108
  # 3. Output Guard: Block write_file on large existing files to enforce edit_file
@@ -130,6 +141,7 @@ def main():
130
141
  f"Please use 'edit_file' with surgical Target and Replacement blocks instead."
131
142
  )
132
143
  }))
144
+ _trigger_bg_sync()
133
145
  return
134
146
 
135
147
  # 3. read_file Optimization (AST Windowing & Skeletonization).
@@ -256,6 +268,7 @@ def main():
256
268
  "decision": "deny",
257
269
  "reason": f"šŸ›”ļø TokenSafe Guard: {guard_res.reason}"
258
270
  }))
271
+ _trigger_bg_sync()
259
272
  return
260
273
  elif guard_res.warning_only:
261
274
  response["reason"] = f"āš ļø TokenSafe Guard Warning: {guard_res.reason}"
@@ -52,13 +52,13 @@ def main():
52
52
  from src.metrics import MetricsTracker
53
53
  tracker = MetricsTracker()
54
54
 
55
- # 1. Idle epilogue: final cloud sync + retention prune.
55
+ # 1. Turn-end / idle epilogue: cloud sync + idle retention prune.
56
+ try:
57
+ from src.telemetry_sync import TelemetrySync
58
+ TelemetrySync.sync_background(throttle_seconds=0.0 if fully_idle else 15.0)
59
+ except Exception:
60
+ pass
56
61
  if fully_idle:
57
- try:
58
- from src.telemetry_sync import TelemetrySync
59
- TelemetrySync.sync_background(throttle_seconds=0.0)
60
- except Exception:
61
- pass
62
62
  try:
63
63
  tracker.prune()
64
64
  except Exception:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
6
6
  "main": "bin/tokensafe.js",
7
7
  "bin": {
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "displayName": "TokenSafe",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
6
6
  "logo": "assets/logo.svg",
7
7
  "author": {
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "dev.tokensafe/tokensafe",
4
4
  "title": "TokenSafe",
5
5
  "description": "Reduce your AI bills by up to 99% locally: focused code, warm prompt caches & zero secret leaks.",
6
- "version": "2.6.0",
6
+ "version": "2.7.0",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -30,7 +30,7 @@
30
30
  "registryType": "npm",
31
31
  "registryBaseUrl": "https://registry.npmjs.org",
32
32
  "identifier": "tokensafe",
33
- "version": "2.6.0",
33
+ "version": "2.7.0",
34
34
  "runtimeHint": "npx",
35
35
  "transport": {
36
36
  "type": "stdio"
@@ -46,7 +46,7 @@
46
46
  "registryType": "pypi",
47
47
  "registryBaseUrl": "https://pypi.org",
48
48
  "identifier": "tokensafe",
49
- "version": "2.6.0",
49
+ "version": "2.7.0",
50
50
  "runtimeHint": "uvx",
51
51
  "transport": {
52
52
  "type": "stdio"
package/src/cli.py CHANGED
@@ -292,8 +292,7 @@ def main():
292
292
  elif command in ("graph", "nodes"):
293
293
  from src.graph_engine import GraphEngine
294
294
  target_dir = args[1] if len(args) > 1 else os.getcwd()
295
- graph = GraphEngine(target_dir)
296
- graph.index_workspace()
295
+ graph = GraphEngine.get_instance(target_dir)
297
296
  print(f"\nšŸ” TokenSafe Graph Engine — Knowledge Graph & Centrality Analysis")
298
297
  print(f" Indexed: {len(graph.file_symbols)} code files, {len(graph.symbols)} symbols\n")
299
298
  god_nodes = graph.get_god_nodes(top_n=7)
@@ -306,9 +305,8 @@ def main():
306
305
  elif command in ("map", "surface"):
307
306
  from src.graph_engine import GraphEngine
308
307
  target_dir = args[1] if len(args) > 1 else os.getcwd()
309
- graph = GraphEngine(target_dir)
310
- graph.index_workspace()
311
- out_file = os.path.join(target_dir, "tokensafe-out", "API_SURFACE.md")
308
+ graph = GraphEngine.get_instance(target_dir)
309
+ out_file = os.path.join(os.path.abspath(target_dir), "tokensafe-out", "API_SURFACE.md")
312
310
  graph.generate_api_surface(out_file)
313
311
  print(f"\nāœ“ Generated API Surface Map: {out_file} ({os.path.getsize(out_file):,} bytes)")
314
312
  print(f" AI agents can read this file in ~1.5k tokens instead of reading the entire repo.\n")
@@ -318,10 +316,9 @@ def main():
318
316
  if len(args) < 2:
319
317
  print("Usage: tokensafe skeleton <file_path> [target_symbol]")
320
318
  sys.exit(1)
321
- file_path = args[1]
319
+ file_path = os.path.abspath(args[1])
322
320
  target_symbol = args[2] if len(args) > 2 else None
323
- target_dir = os.path.dirname(os.path.abspath(file_path)) or os.getcwd()
324
- graph = GraphEngine(target_dir)
321
+ graph, _ = GraphEngine.for_file(file_path)
325
322
  res = graph.graph_guided_skeletonize(file_path, target_symbol)
326
323
  print(res)
327
324
 
@@ -36,7 +36,7 @@ class DependencyPrefetcher:
36
36
 
37
37
  if ext == ".py":
38
38
  imported_symbols = cls._parse_python_imports(content, file_dir)
39
- elif ext in (".ts", ".js", ".tsx", ".jsx"):
39
+ elif ext in (".ts", ".js", ".tsx", ".jsx", ".mjs", ".cjs"):
40
40
  imported_symbols = cls._parse_ts_imports(content, file_dir)
41
41
 
42
42
  if not imported_symbols:
@@ -129,7 +129,7 @@ class DependencyPrefetcher:
129
129
  # Resolve target file path (check .ts, .tsx, .js, /index.ts)
130
130
  base_target = os.path.normpath(os.path.join(current_dir, rel_path))
131
131
  resolved = None
132
- for ext in (".ts", ".tsx", ".js", ".jsx", "/index.ts", "/index.js"):
132
+ for ext in (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", "/index.ts", "/index.tsx", "/index.js", "/index.mjs"):
133
133
  candidate = f"{base_target}{ext}" if not ext.startswith("/") else f"{base_target}{ext}"
134
134
  if os.path.exists(candidate):
135
135
  resolved = candidate