tokensafe 4.5.0 → 4.5.1

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.
Files changed (62) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/bin/agy-tokens +10 -1
  3. package/bin/tokensafe.js +2 -1
  4. package/hooks/claude_code_hook.py +38 -126
  5. package/hooks/cursor_hook.py +45 -1
  6. package/hooks/kimi_hook.py +46 -90
  7. package/hooks/pre_invocation.py +23 -4
  8. package/hooks/pre_tool_use.py +40 -22
  9. package/hooks/session_start.py +28 -10
  10. package/hooks/zcode_hook.py +95 -0
  11. package/hooks.json +1 -1
  12. package/kimi.plugin.json +17 -1
  13. package/mcp_config.json +10 -4
  14. package/package.json +1 -1
  15. package/plugin.json +1 -1
  16. package/rules/AGENTS.md +24 -24
  17. package/server.json +3 -3
  18. package/skills/token-optimizer/SKILL.md +61 -86
  19. package/skills/token-optimizer/references/mcp-tools.md +32 -132
  20. package/src/adapter_core.py +231 -7
  21. package/src/batch_editor.py +73 -22
  22. package/src/batch_search.py +31 -11
  23. package/src/burn_monitor.py +581 -0
  24. package/src/cache_normalizer.py +2 -0
  25. package/src/cli.py +34 -4
  26. package/src/compactor.py +1 -1
  27. package/src/dashboard.py +17 -9
  28. package/src/diff_slicer.py +1 -1
  29. package/src/distiller.py +11 -1
  30. package/src/environment_auditor.py +30 -6
  31. package/src/format_parsers/ansi.py +1 -1
  32. package/src/format_parsers/lockfiles.py +22 -17
  33. package/src/format_parsers/tabular.py +6 -3
  34. package/src/fts_index.py +26 -20
  35. package/src/governor.py +2 -2
  36. package/src/graph_engine.py +31 -9
  37. package/src/guard.py +3 -3
  38. package/src/image_downscale.py +26 -0
  39. package/src/installer.py +61 -48
  40. package/src/license_manager.py +49 -16
  41. package/src/live_relay.py +9 -8
  42. package/src/mcp_server.py +487 -48
  43. package/src/metrics.py +10 -1
  44. package/src/mistakes.py +4 -2
  45. package/src/paths.py +4 -1
  46. package/src/proxy.py +302 -123
  47. package/src/result_ledger.py +39 -1
  48. package/src/schema_slicer.py +40 -18
  49. package/src/scoped_search.py +66 -23
  50. package/src/skeletonizer.py +22 -11
  51. package/src/slicer.py +6 -4
  52. package/src/stash.py +37 -7
  53. package/src/superseded.py +42 -23
  54. package/src/syntax_guard.py +2 -0
  55. package/src/team_cache.py +3 -0
  56. package/src/telemetry_sync.py +66 -53
  57. package/src/thinking_fold.py +50 -12
  58. package/src/transcript_analyzer.py +270 -68
  59. package/src/treesitter_backend.py +2 -0
  60. package/src/type_slicer.py +60 -18
  61. package/src/version_checker.py +1 -1
  62. package/src/web_reader.py +55 -22
package/src/metrics.py CHANGED
@@ -150,6 +150,9 @@ class MetricsTracker:
150
150
  user_ver = int(uv_row[0]) if uv_row else 0
151
151
  except Exception:
152
152
  user_ver = 0
153
+ if user_ver >= 3:
154
+ _INITIALIZED_METRICS_DBS.add(self.db_path)
155
+ return
153
156
  if user_ver >= 2:
154
157
  tbl = cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='events';").fetchone()
155
158
  if tbl is not None:
@@ -161,6 +164,10 @@ class MetricsTracker:
161
164
  "'GUARD_SECRET', 'GUARD_DESTRUCTIVE', 'GUARD_TLS_VERIFY_BYPASS', "
162
165
  "'GUARD_JUNK_READ', 'GUARD_INFINITE', 'GUARD_RAW_CODE_SEARCH');"
163
166
  )
167
+ try:
168
+ cursor.execute("PRAGMA user_version = 3;")
169
+ except sqlite3.Error:
170
+ pass
164
171
  _INITIALIZED_METRICS_DBS.add(self.db_path)
165
172
  return
166
173
  try:
@@ -250,7 +257,7 @@ class MetricsTracker:
250
257
  GROUP BY substr(timestamp, 1, 10)
251
258
  """, (cutoff_30,))
252
259
  try:
253
- cursor.execute("PRAGMA user_version = 2;")
260
+ cursor.execute("PRAGMA user_version = 3;")
254
261
  except sqlite3.Error:
255
262
  pass
256
263
  _INITIALIZED_METRICS_DBS.add(self.db_path)
@@ -829,6 +836,8 @@ class MetricsTracker:
829
836
  combined_where = " OR ".join(where_clauses)
830
837
 
831
838
  with self._get_connection() as conn:
839
+ conn.commit()
840
+ conn.execute("BEGIN IMMEDIATE")
832
841
  cursor = conn.cursor()
833
842
 
834
843
  # 1. Calculate aggregates for events to be pruned
package/src/mistakes.py CHANGED
@@ -200,7 +200,7 @@ class MistakesLedger:
200
200
  """Retrieves scrubbed dead-end summaries shared across team members with 300s TTL cache."""
201
201
  now = time.time()
202
202
  with cls._team_mistakes_lock:
203
- if cls._team_mistakes_cache and (now - cls._team_mistakes_fetched_at < 300.0):
203
+ if cls._team_mistakes_fetched_at > 0 and (now - cls._team_mistakes_fetched_at < 300.0):
204
204
  return list(cls._team_mistakes_cache)
205
205
 
206
206
  try:
@@ -226,7 +226,9 @@ class MistakesLedger:
226
226
  cls._team_mistakes_fetched_at = now
227
227
  return list(parsed)
228
228
  except Exception:
229
- return []
229
+ with cls._team_mistakes_lock:
230
+ cls._team_mistakes_fetched_at = now
231
+ return list(cls._team_mistakes_cache)
230
232
 
231
233
  @classmethod
232
234
  def should_force_ask(
package/src/paths.py CHANGED
@@ -134,11 +134,14 @@ def save_active_workspace(path: str) -> None:
134
134
  if is_plugin_or_system_dir(path):
135
135
  return
136
136
  try:
137
+ import threading
137
138
  data_dir = resolve_data_dir()
138
139
  os.makedirs(data_dir, exist_ok=True)
139
140
  marker = os.path.join(data_dir, ".active_workspace")
140
- with open(marker, "w", encoding="utf-8") as f:
141
+ tmp_marker = f"{marker}.tmp.{os.getpid()}.{threading.get_ident()}"
142
+ with open(tmp_marker, "w", encoding="utf-8") as f:
141
143
  f.write(os.path.abspath(path))
144
+ os.replace(tmp_marker, marker)
142
145
  except Exception:
143
146
  pass
144
147