tokensafe 4.7.13 → 4.7.15

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.13",
2
+ "version": "4.7.15",
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.13",
3
+ "version": "4.7.15",
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.13",
4
+ "version": "4.7.15",
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.13",
4
+ "version": "4.7.15",
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.13",
6
+ "version": "4.7.15",
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.13",
26
+ "version": "4.7.15",
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.13",
42
+ "version": "4.7.15",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
@@ -121,10 +121,16 @@ _SITECUSTOMIZE = '''"""TokenSafe OUMV autoload (generated) — see `tokensafe in
121
121
 
122
122
  Mounts `mount_tokensafe(app)` on a FastAPI app the moment uvicorn resolves it.
123
123
  Inert unless TOKENSAFE_OUMV_AUTOMOUNT=1, which `tokensafe run-backend` sets.
124
+
125
+ TOKENSAFE_OUMV_READ_ONLY=1 mounts the spec §8.5 read-only deployment: the writing
126
+ methods are not registered at all, so applyEdit/previewEdit/verify/build answer
127
+ -32601 instead of being refused by a handler.
124
128
  """
125
129
  import os
126
130
 
127
131
  if os.environ.get("TOKENSAFE_OUMV_AUTOMOUNT") == "1":
132
+ _READ_ONLY = os.environ.get("TOKENSAFE_OUMV_READ_ONLY") in ("1", "true", "yes", "on")
133
+
128
134
  def _install():
129
135
  try:
130
136
  from tokensafe_python.adapters.fastapi import mount_tokensafe as _mount
@@ -141,7 +147,7 @@ if os.environ.get("TOKENSAFE_OUMV_AUTOMOUNT") == "1":
141
147
  def _patched(import_str, *args, **kwargs):
142
148
  app = _original(import_str, *args, **kwargs)
143
149
  try:
144
- _mount(app)
150
+ _mount(app, read_only=_READ_ONLY)
145
151
  except Exception as exc: # never break the user's server
146
152
  import sys
147
153
  print(f"[tokensafe] OUMV autoload skipped: {exc}", file=sys.stderr)
@@ -281,7 +287,7 @@ def go_patch_state(workspace: str) -> Dict[str, Any]:
281
287
  _GO_MODULE = "github.com/tokensafe-dev/tokensafe-backend/go"
282
288
  # Keep in step with the backend release tag (go/vX.Y.Z): injection must never
283
289
  # downgrade an adapter that is already newer than this pin.
284
- _GO_MODULE_VERSION = "v0.11.0"
290
+ _GO_MODULE_VERSION = "v0.13.0"
285
291
 
286
292
 
287
293
  def _version_tuple(tag: str):
@@ -796,7 +802,7 @@ def _sidecar_cache_dir() -> str:
796
802
  _DOTNET_MARK_BEGIN = "// tokensafe:oumv:begin"
797
803
  _DOTNET_MARK_END = "// tokensafe:oumv:end"
798
804
  _DOTNET_PACKAGE = "TokenSafe.Oumv.AspNetCore"
799
- _DOTNET_PACKAGE_VERSION = "0.2.0"
805
+ _DOTNET_PACKAGE_VERSION = "0.3.0"
800
806
 
801
807
 
802
808
 
@@ -1018,17 +1024,17 @@ def revert_dotnet_patch(workspace: str) -> Dict[str, Any]:
1018
1024
  # Pinned to the backend release: the sidecars are single files, so the cache is
1019
1025
  # content-addressed by SHA-256 and a clean machine downloads the exact bytes the
1020
1026
  # release was certified from. Bump both the tag and the hashes together.
1021
- _SIDECAR_RELEASE_TAG = "v0.9.2"
1027
+ _SIDECAR_RELEASE_TAG = "v0.13.0"
1022
1028
  _SIDECARS = {
1023
1029
  "spring": (
1024
1030
  "java/src/dev/tokensafe/oumv/OumvSpring.java",
1025
1031
  "OumvSpring.java",
1026
- "45aa63f2c71cf25065f591ebd589b21c7c7c58d218f3dce45880af0e1f1e7d81",
1032
+ "a4defc121be23ce2266a1f7f8cfd361d5b5b1fe7ea85f818e5f322322ab2642e",
1027
1033
  ),
1028
1034
  "php": (
1029
1035
  "php/bin/oumv-php",
1030
1036
  "oumv-php",
1031
- "660e7f53cc3799bd700cea2173f672594a5b8bc33e26cfa91ee559aec66f325a",
1037
+ "3369ee5fd03ec9b16b7eaebc33cc003033cadcb1d325b3445661eba058405b5f",
1032
1038
  ),
1033
1039
  }
1034
1040
 
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.13"
47
+ "version": "4.7.15"
48
48
  }
49
49
 
50
50
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -20,6 +20,12 @@ from src.paths import get_active_workspace
20
20
  class OUMVRpcError(RuntimeError):
21
21
  """Raised when a live OUMV runtime explicitly returns a JSON-RPC error."""
22
22
 
23
+ def __init__(self, message: str, code: Optional[int] = None):
24
+ super().__init__(message)
25
+ # The JSON-RPC code, when the runtime sent one. Classification must not depend
26
+ # on the message text: every adapter words -32601 differently.
27
+ self.code = code
28
+
23
29
 
24
30
  class OUMVUnsupportedMethodError(OUMVRpcError):
25
31
  """The runtime answered but does not implement the requested method.
@@ -291,12 +297,27 @@ class OUMVGateway:
291
297
  "observeLevels": res.get("capabilities", {}).get("observe", {}).get("levels"),
292
298
  "causality": res.get("capabilities", {}).get("understand", {}).get("causality"),
293
299
  "occ": res.get("capabilities", {}).get("mutate", {}).get("occ"),
300
+ # Spec §8.5 (revision v1.11): a read-only deployment registers
301
+ # no writing method at all, so the answer is -32601 and this flag
302
+ # is the authoritative "do not edit behind its back" signal.
303
+ "readOnly": bool(res.get("capabilities", {}).get("readOnly")),
294
304
  },
295
305
  }
296
306
  except Exception:
297
307
  continue
298
308
  return None
299
309
 
310
+ @classmethod
311
+ def _runtime_is_reachable(cls, url: Optional[str]) -> bool:
312
+ """True when a live OUMV runtime answers a handshake at `url`."""
313
+ if not url:
314
+ return False
315
+ try:
316
+ res = cls._rpc_call(url, "oumv/handshake", {"protocolVersion": "1.6.0"}, timeout=0.35)
317
+ except Exception:
318
+ return False
319
+ return bool(res and isinstance(res, dict) and "runtimeInfo" in res)
320
+
300
321
  @classmethod
301
322
  def _rpc_call(cls, endpoint_url: str, method: str, params: Optional[dict] = None, timeout: float = 3.0) -> Any:
302
323
  payload = json.dumps({
@@ -334,7 +355,7 @@ class OUMVGateway:
334
355
  if isinstance(err, dict):
335
356
  code = err.get("code")
336
357
  msg = err.get("message") or str(err)
337
- raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}")
358
+ raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}", code=code)
338
359
  raise OUMVRpcError(f"JSON-RPC error from {endpoint_url}: {err}")
339
360
  return data.get("result")
340
361
  except urllib.error.HTTPError as exc:
@@ -342,7 +363,7 @@ class OUMVGateway:
342
363
  # JSON-RPC envelope. Treat that as a protocol error (RuntimeError) so
343
364
  # callers can fall back to offline operation instead of crashing on OSError.
344
365
  code, msg = cls._http_error_detail(exc)
345
- raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}") from exc
366
+ raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}", code=code) from exc
346
367
  except urllib.error.URLError as exc:
347
368
  raise OUMVRpcError(f"runtime unreachable at {endpoint_url}: {exc.reason}") from exc
348
369
  except (TimeoutError, OSError) as exc:
@@ -927,6 +948,7 @@ class OUMVGateway:
927
948
  except Exception:
928
949
  pass
929
950
 
951
+ url: Optional[str] = None
930
952
  try:
931
953
  url = cls._resolve_client_url(runtime=runtime, target=path, workspace_dir=workspace_dir)
932
954
  return cls._rpc_call(url, "oumv/applyEdit", {
@@ -939,12 +961,28 @@ class OUMVGateway:
939
961
  })
940
962
  except RuntimeError as e:
941
963
  if isinstance(e, OUMVRpcError) and not isinstance(e, OUMVUnsupportedMethodError):
942
- if not any(hint in str(e).lower() for hint in _UNSUPPORTED_HINTS):
964
+ # -32601 by code, or a message an older bridge only words that way.
965
+ method_missing = getattr(e, "code", None) == -32601 or any(
966
+ hint in str(e).lower() for hint in _UNSUPPORTED_HINTS
967
+ )
968
+ if not method_missing:
943
969
  # Explicit safety rejection (conflict, syntax, permission): obey it.
944
970
  raise
945
- # The runtime cannot mediate the edit at all; the offline path below
946
- # performs the same guarded edit and reports why.
947
- e = OUMVUnsupportedMethodError(str(e))
971
+ # Spec §8.5 (revision v1.11): a *live* runtime that does not register
972
+ # applyEdit has no write path on purpose (read-only deployment, or the
973
+ # production lock-down). The offline path below would silently restore
974
+ # the very write path the deployment removed, so refuse instead of
975
+ # editing behind its back. The fallback stays for a runtime that died
976
+ # mid-flight, where nothing is reachable to ask.
977
+ if cls._runtime_is_reachable(url):
978
+ raise RuntimeError(
979
+ "[OUMV PERMISSION_DENIED: -32007] the OUMV runtime is running read-only "
980
+ "(oumv/applyEdit is not registered, spec §8.5); the edit was refused instead "
981
+ "of being written offline behind its back."
982
+ )
983
+ # Nothing answered: the dev server is offline, so the same guarded edit
984
+ # is performed locally and the result says why.
985
+ e = OUMVUnsupportedMethodError(str(e), code=getattr(e, "code", None))
948
986
  # Out-of-the-box direct fallback when live dev-servers are offline
949
987
  if replacement is not None:
950
988
  abs_path = os.path.normpath(os.path.join(ws, path))
package/src/retrofit.py CHANGED
@@ -711,7 +711,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
711
711
  "repo": "tokensafe-backend/dotnet",
712
712
  "mode": "hybrid",
713
713
  "status": "ready",
714
- "description": "In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
714
+ "description": "In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, the full wire 1.6.0 surface (previewEdit, index, query, build, cancel), and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
715
715
  "technology": {
716
716
  "language": "csharp",
717
717
  "framework": "aspnetcore",
@@ -726,6 +726,11 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
726
726
  {"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": False}},
727
727
  {"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": False, "limitations": ["requires observed request traces (UseTokensafe middleware or oumv/verify)"]}},
728
728
  {"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
729
+ {"name": "mutate.preview", "constraints": {"readOnly": True, "developmentOnly": True, "requiresPermission": "permissions.mutate != false", "limitations": ["dry run of applyEdit's guard chain; nothing is written"]}},
730
+ {"name": "index.symbols", "constraints": {"readOnly": True, "developmentOnly": True}},
731
+ {"name": "observe.query", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["read-only SQL over the discovered DbContext; writes answer -32003"]}},
732
+ {"name": "verify.build", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["OumvOptions.BuildCommand or params.command; honest skipped without one"]}},
733
+ {"name": "sessions.cancel", "constraints": {"readOnly": True, "developmentOnly": False}},
729
734
  {"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
730
735
  ],
731
736
  },
@@ -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.13"
314
+ "User-Agent": "TokenSafe-Sync/4.7.15"
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.13"
20
+ CURRENT_VERSION = "4.7.15"
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