tokensafe 4.7.5 → 4.7.6

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.5",
2
+ "version": "4.7.6",
3
3
  "name": "tokensafe",
4
4
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
5
5
  "author": {
package/kimi.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.7.5",
3
+ "version": "4.7.6",
4
4
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
5
5
  "homepage": "https://tokensafe.dev",
6
6
  "license": "Apache-2.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "4.7.5",
4
+ "version": "4.7.6",
5
5
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
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": "4.7.5",
4
+ "version": "4.7.6",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
7
7
  "logo": "assets/logo.png",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "dev.tokensafe/tokensafe",
4
4
  "title": "TokenSafe",
5
5
  "description": "Your AI agent is smart enough to code all day. Local firewall & zero-loss runtime.",
6
- "version": "4.7.5",
6
+ "version": "4.7.6",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -23,7 +23,7 @@
23
23
  "registryType": "npm",
24
24
  "registryBaseUrl": "https://registry.npmjs.org",
25
25
  "identifier": "tokensafe",
26
- "version": "4.7.5",
26
+ "version": "4.7.6",
27
27
  "runtimeHint": "npx",
28
28
  "transport": {
29
29
  "type": "stdio"
@@ -39,7 +39,7 @@
39
39
  "registryType": "pypi",
40
40
  "registryBaseUrl": "https://pypi.org",
41
41
  "identifier": "tokensafe",
42
- "version": "4.7.5",
42
+ "version": "4.7.6",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
package/src/mcp_server.py CHANGED
@@ -44,7 +44,7 @@ from src.session_context import current_root, current_session_id
44
44
 
45
45
  SERVER_INFO = {
46
46
  "name": "tokensafe-mcp",
47
- "version": "4.7.5"
47
+ "version": "4.7.6"
48
48
  }
49
49
 
50
50
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -430,7 +430,8 @@ FULL_TOOLS = [ { 'annotations': {'readOnlyHint': True},
430
430
  'target': { 'description': "Target component ID, route (e.g. 'POST "
431
431
  "/api/products'), or DOM element "
432
432
  "('#submit-btn')",
433
- 'type': 'string'}},
433
+ 'type': 'string'},
434
+ 'workspace_dir': {'type': 'string'}},
434
435
  'type': 'object'},
435
436
  'name': 'oumv_observe'},
436
437
  { 'annotations': {'readOnlyHint': True},
@@ -448,7 +449,8 @@ FULL_TOOLS = [ { 'annotations': {'readOnlyHint': True},
448
449
  'type': 'string'},
449
450
  'target': { 'description': 'Target component ID, state key, endpoint, '
450
451
  'or UI element',
451
- 'type': 'string'}},
452
+ 'type': 'string'},
453
+ 'workspace_dir': {'type': 'string'}},
452
454
  'type': 'object'},
453
455
  'name': 'oumv_understand'},
454
456
  { 'annotations': {'destructiveHint': False, 'readOnlyHint': False},
@@ -467,7 +469,8 @@ FULL_TOOLS = [ { 'annotations': {'readOnlyHint': True},
467
469
  "'backend', or 'auto')",
468
470
  'enum': ['frontend', 'backend', 'auto'],
469
471
  'type': 'string'},
470
- 'symbol': {'description': 'Target symbol to edit', 'type': 'string'}},
472
+ 'symbol': {'description': 'Target symbol to edit', 'type': 'string'},
473
+ 'workspace_dir': {'type': 'string'}},
471
474
  'required': ['path'],
472
475
  'type': 'object'},
473
476
  'name': 'oumv_mutate'},
@@ -488,7 +491,8 @@ FULL_TOOLS = [ { 'annotations': {'readOnlyHint': True},
488
491
  'type': 'string'},
489
492
  'target': { 'description': "Action target (component ID, e.g. 'cart', "
490
493
  "or 'POST /api/v1/orders' or '#submit-btn')",
491
- 'type': 'string'}},
494
+ 'type': 'string'},
495
+ 'workspace_dir': {'type': 'string'}},
492
496
  'required': ['target'],
493
497
  'type': 'object'},
494
498
  'name': 'oumv_verify'},
@@ -503,7 +507,8 @@ FULL_TOOLS = [ { 'annotations': {'readOnlyHint': True},
503
507
  'type': 'string'},
504
508
  'target': { 'description': "Target resource (e.g. '/api/orders' or "
505
509
  "'POST /api/orders')",
506
- 'type': 'string'}},
510
+ 'type': 'string'},
511
+ 'workspace_dir': {'type': 'string'}},
507
512
  'type': 'object'},
508
513
  'name': 'oumv_graph'},
509
514
  { 'annotations': {'readOnlyHint': False, 'destructiveHint': False},
@@ -780,7 +785,11 @@ TOOLS = [{'name': 'smart_read_file',
780
785
  'replacement': {'type': 'string'},
781
786
  'expectedVersion': {'type': 'string'},
782
787
  'verify_action': {'type': 'string'},
783
- 'payload': {'type': 'object'}}}},
788
+ 'payload': {'type': 'object'},
789
+ 'workspace_dir': {'type': 'string',
790
+ 'description': 'Target repo root; for '
791
+ 'status/observe/understand/verify/graph '
792
+ 'also accepted as path'}}}},
784
793
  {'name': 'run_helper',
785
794
  'annotations': {'readOnlyHint': False},
786
795
  'description': "Utilities: 'sanitize','guard','diff','deps','web','expand','image','compress'.",
@@ -1007,6 +1016,68 @@ def _resolve_project_root(args: dict) -> Tuple[Optional[str], Optional[str]]:
1007
1016
 
1008
1017
  return None, "Error: Invalid or root project_path. Please specify an explicit 'project_path' pointing to your project directory (e.g. project_path='/path/to/project')."
1009
1018
 
1019
+
1020
+ def _shared_batch_root(paths: List[str], real_cwd: str) -> Optional[str]:
1021
+ """Narrowest project directory that contains every absolute sub-query path.
1022
+
1023
+ Batch search is one root per call. When every explicit sub-query path lives
1024
+ outside the current root but inside one repo, that repo IS the root: rebasing
1025
+ there beats failing the call (agents batch a second checkout this way). Paths
1026
+ that share only a wide parent — the directory that also holds the current
1027
+ root, or two sibling repos — return None so the caller keeps the split rule.
1028
+ """
1029
+ try:
1030
+ shared = os.path.commonpath(paths)
1031
+ except ValueError:
1032
+ return None
1033
+ if os.path.isfile(shared):
1034
+ shared = os.path.dirname(shared)
1035
+ if not shared or shared == os.path.abspath(os.sep) or not os.path.isdir(shared):
1036
+ return None
1037
+
1038
+ def _swallows_cwd(candidate: str) -> bool:
1039
+ try:
1040
+ return os.path.commonpath([real_cwd, candidate]) == candidate
1041
+ except ValueError:
1042
+ return False
1043
+
1044
+ if _swallows_cwd(shared):
1045
+ return None
1046
+ # Prefer the enclosing project root, so a batch of sub-paths searches its
1047
+ # repo instead of just their common sub-directory.
1048
+ try:
1049
+ from src.graph_engine import GraphEngine
1050
+ shared = GraphEngine.find_project_root(shared)
1051
+ except Exception:
1052
+ pass
1053
+ if not os.path.isdir(shared) or _swallows_cwd(shared) or is_plugin_or_system_dir(shared):
1054
+ return None
1055
+ return shared
1056
+
1057
+
1058
+ def _oumv_workspace_arg(args: dict, allow_path: bool = False) -> Tuple[Optional[str], Optional[str]]:
1059
+ """Validated workspace root for an OUMV call; None means "use the active one".
1060
+
1061
+ The MCP server inherits the host process cwd, so without this an explicit
1062
+ target repo was either dropped (unadvertised property) or ignored, and the
1063
+ answer described the bound workspace. A root that does not exist now fails
1064
+ closed instead of reporting another repo's stack.
1065
+ """
1066
+ raw = str(args.get("workspace_dir") or "").strip()
1067
+ if not raw and allow_path:
1068
+ raw = str(args.get("path") or "").strip()
1069
+ if not raw:
1070
+ return None, None
1071
+ ws = os.path.abspath(raw)
1072
+ if os.path.isfile(ws):
1073
+ ws = os.path.dirname(ws)
1074
+ if not os.path.isdir(ws):
1075
+ return None, f"workspace_dir not found or not a directory: '{raw}'"
1076
+ if is_plugin_or_system_dir(ws):
1077
+ return None, f"refusing to use system root or plugin dir as workspace: '{ws}'"
1078
+ return ws, None
1079
+
1080
+
1010
1081
  MCP_TOOL_TIMEOUT = float(os.environ.get("TOKENSAFE_MCP_TIMEOUT", "8.0"))
1011
1082
 
1012
1083
 
@@ -1869,6 +1940,18 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
1869
1940
  action = str(args.get("action") or "status").strip().lower()
1870
1941
  if action not in _OUMV_ACTIONS:
1871
1942
  return _fallback_error("oumv", f"unknown action '{action}'")
1943
+ # Target-repo routing: the MCP server inherits the host's cwd, so an agent
1944
+ # inspecting a second repo (workspace_dir, or `path` for the read actions)
1945
+ # used to get the bound workspace's stack back with no error — a silently
1946
+ # wrong answer. Resolve the explicit root here and fail closed on a bad one.
1947
+ ws, ws_err = _oumv_workspace_arg(
1948
+ args,
1949
+ allow_path=action in ("status", "observe", "understand", "verify", "graph"),
1950
+ )
1951
+ if ws_err:
1952
+ return _fallback_error("oumv", ws_err)
1953
+ if ws:
1954
+ args = dict(args, workspace_dir=ws)
1872
1955
  mapped = _OUMV_ACTIONS[action]
1873
1956
  if action == "verify":
1874
1957
  args = dict(args, action=args.get("verify_action") or "invoke")
@@ -3149,7 +3232,10 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3149
3232
  elif name == "oumv_status":
3150
3233
  try:
3151
3234
  from src.oumv_gateway import OUMVGateway
3152
- ws = str(args.get("workspace_dir") or "").strip() or get_active_workspace() or os.getcwd()
3235
+ ws, ws_err = _oumv_workspace_arg(args, allow_path=True)
3236
+ if ws_err:
3237
+ return _fallback_error("oumv_status", ws_err)
3238
+ ws = ws or get_active_workspace() or os.getcwd()
3153
3239
  res = OUMVGateway.status(workspace_dir=ws)
3154
3240
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3155
3241
  except Exception as e:
@@ -3161,7 +3247,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3161
3247
  lvl = str(args.get("level") or "L0").strip()
3162
3248
  tgt = str(args.get("target") or "").strip() or None
3163
3249
  rt = str(args.get("runtime") or "auto").strip()
3164
- ws = str(args.get("workspace_dir") or "").strip() or None
3250
+ ws, ws_err = _oumv_workspace_arg(args)
3251
+ if ws_err:
3252
+ return _fallback_error("oumv_observe", ws_err)
3165
3253
  res = OUMVGateway.observe(level=lvl, target=tgt, runtime=rt, workspace_dir=ws)
3166
3254
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3167
3255
  except Exception as e:
@@ -3173,7 +3261,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3173
3261
  qry = str(args.get("query") or "causality").strip()
3174
3262
  tgt = str(args.get("target") or "").strip() or None
3175
3263
  rt = str(args.get("runtime") or "auto").strip()
3176
- ws = str(args.get("workspace_dir") or "").strip() or None
3264
+ ws, ws_err = _oumv_workspace_arg(args)
3265
+ if ws_err:
3266
+ return _fallback_error("oumv_understand", ws_err)
3177
3267
  res = OUMVGateway.understand(query=qry, target=tgt, runtime=rt, workspace_dir=ws)
3178
3268
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3179
3269
  except Exception as e:
@@ -3187,7 +3277,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3187
3277
  rep = args.get("replacement")
3188
3278
  ev = str(args.get("expectedVersion") or "").strip() or None
3189
3279
  rt = str(args.get("runtime") or "auto").strip()
3190
- ws = str(args.get("workspace_dir") or "").strip() or None
3280
+ ws, ws_err = _oumv_workspace_arg(args)
3281
+ if ws_err:
3282
+ return _fallback_error("oumv_mutate", ws_err)
3191
3283
  res = OUMVGateway.mutate(path=p, symbol=sym, replacement=rep, expected_version=ev, runtime=rt, workspace_dir=ws)
3192
3284
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3193
3285
  except Exception as e:
@@ -3200,7 +3292,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3200
3292
  act = str(args.get("action") or "invoke").strip()
3201
3293
  payload = args.get("payload") if isinstance(args.get("payload"), dict) else None
3202
3294
  rt = str(args.get("runtime") or "auto").strip()
3203
- ws = str(args.get("workspace_dir") or "").strip() or None
3295
+ ws, ws_err = _oumv_workspace_arg(args)
3296
+ if ws_err:
3297
+ return _fallback_error("oumv_verify", ws_err)
3204
3298
  res = OUMVGateway.verify(target=tgt, action=act, payload=payload, runtime=rt, workspace_dir=ws)
3205
3299
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3206
3300
  except Exception as e:
@@ -3211,7 +3305,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3211
3305
  from src.oumv_gateway import OUMVGateway
3212
3306
  qry = str(args.get("query") or "overview").strip()
3213
3307
  tgt = str(args.get("target") or "").strip() or None
3214
- ws = str(args.get("workspace_dir") or "").strip() or None
3308
+ ws, ws_err = _oumv_workspace_arg(args)
3309
+ if ws_err:
3310
+ return _fallback_error("oumv_graph", ws_err)
3215
3311
  res = OUMVGateway.graph(query=qry, target=tgt, workspace_dir=ws)
3216
3312
  return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
3217
3313
  except Exception as e:
@@ -3370,9 +3466,15 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3370
3466
 
3371
3467
  safe_queries: List[Dict[str, Any]] = []
3372
3468
  real_cwd = os.path.realpath(cwd)
3469
+ # Pass 1: resolve every sub-query path. A relative path that climbs out
3470
+ # of the root is still a hard error (traversal); absolute paths are an
3471
+ # explicit intent to search elsewhere, so they may be rebased below.
3472
+ q_copies: List[Any] = []
3473
+ path_abs: Dict[int, str] = {}
3474
+ outside: List[str] = []
3373
3475
  for q_item in queries:
3374
3476
  if not isinstance(q_item, dict):
3375
- safe_queries.append(q_item)
3477
+ q_copies.append(q_item)
3376
3478
  continue
3377
3479
  q_copy = dict(q_item)
3378
3480
  sub_p = q_copy.get("path")
@@ -3389,18 +3491,54 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
3389
3491
  except ValueError:
3390
3492
  inside = False
3391
3493
  if not inside:
3392
- return _fallback_error(
3393
- "batch_search",
3394
- f"subquery path '{sub_p}' resolves to '{sub_abs}', outside project root "
3395
- f"'{real_cwd}'. One call searches one root: pass that repo as cwd/project_path "
3396
- f"with repo-relative paths, and split queries for other repos into separate calls.",
3397
- )
3494
+ if not os.path.isabs(str(sub_p)):
3495
+ return _fallback_error(
3496
+ "batch_search",
3497
+ f"subquery path '{sub_p}' resolves to '{sub_abs}', outside project root "
3498
+ f"'{real_cwd}'. One call searches one root: pass that repo as cwd/project_path "
3499
+ f"with repo-relative paths, and split queries for other repos into separate calls.",
3500
+ )
3501
+ outside.append(sub_abs)
3502
+ path_abs[len(q_copies)] = sub_abs
3503
+ q_copies.append(q_copy)
3504
+
3505
+ rebased_from: Optional[str] = None
3506
+ if outside:
3507
+ shared_root = _shared_batch_root(outside, real_cwd) if len(outside) == len(path_abs) else None
3508
+ if not shared_root:
3509
+ detail = (
3510
+ "queries mix paths inside and outside it"
3511
+ if len(outside) != len(path_abs)
3512
+ else "they share no single enclosing project directory"
3513
+ )
3514
+ return _fallback_error(
3515
+ "batch_search",
3516
+ f"subquery paths resolve outside project root '{real_cwd}' and {detail}. "
3517
+ f"One call searches one root: pass that repo as cwd/project_path with "
3518
+ f"repo-relative paths, and split queries for other repos into separate calls.",
3519
+ )
3520
+ rebased_from = cwd
3521
+ cwd = shared_root
3522
+ real_cwd = os.path.realpath(shared_root)
3523
+ for idx, sub_abs in path_abs.items():
3524
+ if isinstance(q_copies[idx], dict):
3525
+ q_copies[idx]["path"] = os.path.relpath(sub_abs, shared_root)
3526
+
3527
+ for q_copy in q_copies:
3528
+ if not isinstance(q_copy, dict):
3529
+ safe_queries.append(q_copy)
3530
+ continue
3398
3531
  if is_quota_exceeded:
3399
3532
  q_copy["max_results"] = min(_safe_int(q_copy.get("max_results"), 3, lo=1, hi=100), 3)
3400
3533
  safe_queries.append(q_copy)
3401
3534
 
3402
3535
  res = execute_batch_search(queries=safe_queries, cwd=cwd)
3403
3536
  summary_md = res.get("summary_md", "")
3537
+ if rebased_from:
3538
+ summary_md = (
3539
+ f"// [TokenSafe: batch root auto-rebased to '{cwd}' (was '{rebased_from}') — "
3540
+ f"every subquery path lives there]\n" + summary_md
3541
+ )
3404
3542
  if is_quota_exceeded:
3405
3543
  banner = _quota_banner_if_due(quota, tracker, _mcp_session_id())
3406
3544
  current_tier = str(quota.get("tier") or "guest").lower()
@@ -311,7 +311,7 @@ class TelemetrySync:
311
311
  current_last_id = last_id
312
312
  headers = {
313
313
  "Content-Type": "application/json",
314
- "User-Agent": "TokenSafe-Sync/4.7.5"
314
+ "User-Agent": "TokenSafe-Sync/4.7.6"
315
315
  }
316
316
  if active_key:
317
317
  headers["Authorization"] = f"Bearer {active_key}"
@@ -17,7 +17,7 @@ import urllib.request
17
17
  import urllib.error
18
18
  from typing import Dict, Any, Optional, Tuple
19
19
 
20
- CURRENT_VERSION = "4.7.5"
20
+ CURRENT_VERSION = "4.7.6"
21
21
  CACHE_TTL = 86400 # 24 hours
22
22
  # When the cloud is unreachable we must NOT cache the synthesized "up to date"
23
23
  # answer for a full day — otherwise an update released right after an outage