tokensafe 2.8.4 → 3.0.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.
package/src/mcp_server.py CHANGED
@@ -42,7 +42,7 @@ from src.paths import get_active_workspace, is_plugin_or_system_dir
42
42
 
43
43
  SERVER_INFO = {
44
44
  "name": "tokensafe-mcp",
45
- "version": "2.8.4"
45
+ "version": "3.0.0"
46
46
  }
47
47
 
48
48
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -80,15 +80,15 @@ def _client_supports_pointers() -> bool:
80
80
  TOOLS = [
81
81
  {
82
82
  "name": "smart_read_file",
83
- "description": "Reads a code file using AST skeletonization and graph-guided slicing to save 90-99% context tokens. Automatically preserves target function/class implementation and 1-line 1-hop dependency signatures while folding inert code. Supports relative paths (e.g. 'src/index.ts'). Declarative schemas (OpenAPI, Prisma, GraphQL, SQL) are auto-sliced: pass model/type/table/endpoint as 'symbol' or omit for a compact overview. For 3+ related symbols across files prefer smart_bundle.",
83
+ "description": "AST-skeleton file reader: keeps the target function/class body + 1-line 1-hop dependency signatures, folds inert code (-90-99% tokens). Relative or absolute paths. Schema files (OpenAPI/Prisma/GraphQL/SQL) auto-slice via 'symbol'. For 3+ related symbols use smart_bundle instead.",
84
84
  "inputSchema": {
85
85
  "type": "object",
86
86
  "properties": {
87
- "path": {"type": "string", "description": "File path to read (relative to workspace or absolute, e.g. './src/index.ts')"},
88
- "symbol": {"type": "string", "description": "Optional: targeted function, method, class, component, or schema model/type to extract with 1-hop dependencies while folding surrounding code (omit for whole-file AST skeleton or schema overview)"},
89
- "include_deps": {"type": "boolean", "description": "Optional: whether to include 1-hop dependencies (default: true). Set false for 0-hop surgical isolation."},
90
- "dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "Optional: how 1-hop dependencies are returned when include_deps is true. 'signature' (default, -95%+ tokens) returns compact 1-line signatures; 'full' inlines full dependency bodies."},
91
- "force_full": {"type": "boolean", "description": "Optional: bypass session pointer deduplication and return the full skeleton directly (use only if your context was compacted or you are a fresh subagent lacking earlier reads)."},
87
+ "path": {"type": "string", "description": "File path (relative to workspace or absolute)"},
88
+ "symbol": {"type": "string", "description": "Optional: function/method/class/component or schema model/type/table to extract (omit for whole-file skeleton)"},
89
+ "include_deps": {"type": "boolean", "description": "Include 1-hop dependency signatures (default true)"},
90
+ "dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "'signature' (default) = 1-line dep signatures; 'full' = inline dependency bodies"},
91
+ "force_full": {"type": "boolean", "description": "Bypass pointer dedup — use only after context compaction or as a fresh subagent"},
92
92
  "start_line": {"type": "integer", "description": "Optional: starting line number"},
93
93
  "end_line": {"type": "integer", "description": "Optional: ending line number"}
94
94
  },
@@ -97,7 +97,7 @@ TOOLS = [
97
97
  },
98
98
  {
99
99
  "name": "smart_bundle",
100
- "description": "Reads 2-8 related symbols across multiple files as ONE merged context bundle: per-file AST skeletons with shared import lines deduplicated and merged 1-hop dependency signatures. Use it instead of 3+ separate smart_read_file calls on related code (one roundtrip, no duplicated imports/types). Supports relative paths (e.g. targets=[{'path': 'src/api.ts', 'symbol': 'handler'}]).",
100
+ "description": "Reads 2-8 related symbols across files as ONE merged bundle: per-file skeletons, deduplicated shared imports, merged 1-hop dep signatures. Replaces 3+ separate smart_read_file calls in a single roundtrip.",
101
101
  "inputSchema": {
102
102
  "type": "object",
103
103
  "properties": {
@@ -107,16 +107,16 @@ TOOLS = [
107
107
  "items": {
108
108
  "type": "object",
109
109
  "properties": {
110
- "path": {"type": "string", "description": "File path to code file (relative to workspace or absolute)"},
111
- "symbol": {"type": "string", "description": "Optional symbol to keep unfolded (class, function, or component name)"}
110
+ "path": {"type": "string", "description": "File path (relative or absolute)"},
111
+ "symbol": {"type": "string", "description": "Optional symbol to keep unfolded"}
112
112
  },
113
113
  "required": ["path"]
114
114
  },
115
- "description": "Up to 8 {path, symbol} targets; list several symbols of the same file as separate entries"
115
+ "description": "Up to 8 {path, symbol} targets; several symbols of one file = separate entries"
116
116
  },
117
- "include_deps": {"type": "boolean", "description": "Optional: include merged 1-hop dependency signatures (default: true)"},
118
- "dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "Optional: kept for parity with smart_read_file; signatures are always merged for bundles"},
119
- "force_full": {"type": "boolean", "description": "Optional: bypass session pointer deduplication"}
117
+ "include_deps": {"type": "boolean", "description": "Include merged 1-hop dep signatures (default true)"},
118
+ "dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "Parity only; bundles always merge signatures"},
119
+ "force_full": {"type": "boolean", "description": "Bypass session pointer dedup"}
120
120
  },
121
121
  "required": ["targets"]
122
122
  }
@@ -241,37 +241,37 @@ TOOLS = [
241
241
  },
242
242
  {
243
243
  "name": "scoped_search",
244
- "description": "Safe, token-bounded symbol and text search across the codebase. Replaces raw grep/find with clean, line-numbered markdown matches (-90% tokens).",
244
+ "description": "Safe, token-bounded symbol/text search replacing raw grep/find (-90% tokens). '|' or \\d in query auto-enables regex when use_regex is omitted; false forces literal.",
245
245
  "inputSchema": {
246
246
  "type": "object",
247
247
  "properties": {
248
248
  "query": {
249
249
  "type": "string",
250
- "description": "Text, identifier, or symbol name to search for"
250
+ "description": "Text, identifier, or symbol name"
251
251
  },
252
252
  "scope": {
253
253
  "type": "string",
254
- "description": "Filter scope: 'code', 'config', 'all', a file extension (e.g. 'go', 'ts', '*.py'), or a subfolder path (e.g. 'internal/promo') (default: 'all')"
254
+ "description": "Filter: 'code', 'config', 'all', extension ('go', '*.py'), or subfolder ('internal/promo') (default 'all')"
255
255
  },
256
256
  "path": {
257
257
  "type": "string",
258
- "description": "Directory or project path to search (alias for project_path, e.g. '.', './src', 'internal/promo')"
258
+ "description": "Directory to search (alias for project_path; relative or absolute)"
259
259
  },
260
260
  "project_path": {
261
261
  "type": "string",
262
- "description": "Optional root directory path (defaults to current project)"
262
+ "description": "Optional root directory (defaults to current project)"
263
263
  },
264
264
  "max_results": {
265
265
  "type": "integer",
266
- "description": "Maximum matching lines to return (default: 25, max: 100)"
266
+ "description": "Max matching lines (default 25, max 100)"
267
267
  },
268
268
  "case_sensitive": {
269
269
  "type": "boolean",
270
- "description": "Whether search is case-sensitive (default: false)"
270
+ "description": "Case-sensitive search (default false)"
271
271
  },
272
272
  "use_regex": {
273
273
  "type": "boolean",
274
- "description": "Whether query is a regular expression (default: false)"
274
+ "description": "Omit = auto-detect ('|', \\d → regex); false = literal; true = regex"
275
275
  }
276
276
  },
277
277
  "required": ["query"]
@@ -1536,7 +1536,8 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
1536
1536
 
1537
1537
  max_res = _safe_int(args.get("max_results"), 25, lo=1, hi=100)
1538
1538
  c_sens = bool(args.get("case_sensitive", False))
1539
- u_regex = bool(args.get("use_regex", False))
1539
+ raw_regex = args.get("use_regex")
1540
+ u_regex = None if raw_regex is None else bool(raw_regex)
1540
1541
 
1541
1542
  res = ScopedSearch.search(
1542
1543
  query=query,
package/src/metrics.py CHANGED
@@ -516,6 +516,31 @@ class MetricsTracker:
516
516
  # Largest contributor first
517
517
  return dict(sorted(by_agent.items(), key=lambda kv: kv[1]["saved_tokens"], reverse=True))
518
518
 
519
+ def get_weekly_saved(self, days: int = 7) -> Dict[str, Any]:
520
+ """Rolling-window savings totals for the quick `tokensafe status` view.
521
+ Reads raw events only (lifetime rollups have no timestamp and are
522
+ deliberately excluded — this is the recent-activity signal)."""
523
+ days = max(1, int(days))
524
+ cutoff = (datetime.now() - timedelta(days=days)).isoformat()
525
+ try:
526
+ with self._get_connection() as conn:
527
+ row = conn.cursor().execute(
528
+ """
529
+ SELECT COUNT(*) AS events,
530
+ COALESCE(SUM(saved_tokens), 0) AS saved_tokens,
531
+ COALESCE(SUM(est_usd_saved), 0.0) AS usd_saved
532
+ FROM events
533
+ WHERE timestamp >= ? AND saved_tokens > 0
534
+ """, (cutoff,)
535
+ ).fetchone()
536
+ return {
537
+ "events": int(row["events"] or 0),
538
+ "saved_tokens": int(row["saved_tokens"] or 0),
539
+ "usd_saved": round(float(row["usd_saved"] or 0.0), 4),
540
+ }
541
+ except Exception:
542
+ return {"events": 0, "saved_tokens": 0, "usd_saved": 0.0}
543
+
519
544
  def get_summary(self) -> Dict[str, Any]:
520
545
  """Returns cumulative statistics across all sessions, including lifetime rollups."""
521
546
  with self._get_connection() as conn: