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/README.md +30 -1
- package/hooks/claude_code_hook.py +59 -1
- package/hooks/pre_tool_use.py +7 -32
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/adapter_core.py +71 -0
- package/src/cli.py +104 -6
- package/src/command_sanitizer.py +67 -26
- package/src/dashboard.py +26 -4
- package/src/distiller.py +41 -2
- package/src/governor.py +1 -0
- package/src/guard.py +0 -5
- package/src/installer.py +319 -4
- package/src/license_manager.py +31 -4
- package/src/mcp_server.py +24 -23
- package/src/metrics.py +25 -0
- package/src/proxy.py +455 -5
- package/src/result_ledger.py +314 -0
- package/src/scoped_search.py +33 -10
- package/src/slicer.py +0 -39
- package/src/telemetry_sync.py +1 -1
- package/src/tool_pruner.py +244 -0
- package/src/version_checker.py +1 -15
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": "
|
|
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": "
|
|
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
|
|
88
|
-
"symbol": {"type": "string", "description": "Optional:
|
|
89
|
-
"include_deps": {"type": "boolean", "description": "
|
|
90
|
-
"dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "
|
|
91
|
-
"force_full": {"type": "boolean", "description": "
|
|
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
|
|
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
|
|
111
|
-
"symbol": {"type": "string", "description": "Optional symbol to keep unfolded
|
|
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;
|
|
115
|
+
"description": "Up to 8 {path, symbol} targets; several symbols of one file = separate entries"
|
|
116
116
|
},
|
|
117
|
-
"include_deps": {"type": "boolean", "description": "
|
|
118
|
-
"dep_mode": {"type": "string", "enum": ["signature", "full"], "description": "
|
|
119
|
-
"force_full": {"type": "boolean", "description": "
|
|
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
|
|
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
|
|
250
|
+
"description": "Text, identifier, or symbol name"
|
|
251
251
|
},
|
|
252
252
|
"scope": {
|
|
253
253
|
"type": "string",
|
|
254
|
-
"description": "Filter
|
|
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
|
|
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
|
|
262
|
+
"description": "Optional root directory (defaults to current project)"
|
|
263
263
|
},
|
|
264
264
|
"max_results": {
|
|
265
265
|
"type": "integer",
|
|
266
|
-
"description": "
|
|
266
|
+
"description": "Max matching lines (default 25, max 100)"
|
|
267
267
|
},
|
|
268
268
|
"case_sensitive": {
|
|
269
269
|
"type": "boolean",
|
|
270
|
-
"description": "
|
|
270
|
+
"description": "Case-sensitive search (default false)"
|
|
271
271
|
},
|
|
272
272
|
"use_regex": {
|
|
273
273
|
"type": "boolean",
|
|
274
|
-
"description": "
|
|
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
|
-
|
|
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:
|