tokensafe 4.13.1 → 4.13.2

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.13.1",
2
+ "version": "4.13.2",
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.13.1",
3
+ "version": "4.13.2",
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.13.1",
4
+ "version": "4.13.2",
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.13.1",
4
+ "version": "4.13.2",
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.13.1",
6
+ "version": "4.13.2",
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.13.1",
26
+ "version": "4.13.2",
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.13.1",
42
+ "version": "4.13.2",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
@@ -267,11 +267,21 @@ def _config_state_path(workspace: str) -> str:
267
267
  def _write_config_state(workspace: str, path: str, created: bool) -> None:
268
268
  state_path = _config_state_path(workspace)
269
269
  os.makedirs(os.path.dirname(state_path), exist_ok=True)
270
- payload = {
271
- "path": path,
272
- "created": bool(created),
273
- "sha": _sha256_file(path) if created and path and os.path.isfile(path) else None,
274
- }
270
+ previous: Dict[str, Any] = {}
271
+ if os.path.isfile(state_path):
272
+ try:
273
+ with open(state_path, "r", encoding="utf-8") as handle:
274
+ previous = json.load(handle)
275
+ except Exception:
276
+ previous = {}
277
+ owned = bool(created)
278
+ sha = _sha256_file(path) if created and path and os.path.isfile(path) else None
279
+ # A second `inject` sees the file it created and would otherwise record
280
+ # `created: false`, leaving the config behind after --revert.
281
+ if not owned and previous.get("created") and previous.get("path") == path:
282
+ owned = True
283
+ sha = previous.get("sha") or (_sha256_file(path) if path and os.path.isfile(path) else None)
284
+ payload = {"path": path, "created": owned, "sha": sha}
275
285
  with open(state_path, "w", encoding="utf-8") as handle:
276
286
  json.dump(payload, handle, indent=2)
277
287
 
@@ -605,11 +615,6 @@ def apply_go_patch(workspace: str, dry_run: bool = False, root: str = ".") -> Di
605
615
  "snippet": _GO_MANUAL_SNIPPET,
606
616
  }
607
617
 
608
- if not dry_run:
609
- dep_error = _ensure_go_dependency(root_dir)
610
- if dep_error:
611
- return {"status": "skipped", "reason": dep_error}
612
-
613
618
  with open(path, "r", encoding="utf-8") as f:
614
619
  original = f.read()
615
620
 
@@ -661,7 +666,7 @@ def apply_go_patch(workspace: str, dry_run: bool = False, root: str = ".") -> Di
661
666
  backup_path = _backup_path(workspace, path)
662
667
  os.makedirs(os.path.dirname(backup_path), exist_ok=True)
663
668
  shutil.copy2(path, backup_path)
664
- module_backups: List[Dict[str, str]] = []
669
+ module_backups: List[Dict[str, Any]] = []
665
670
  for mod_file in ("go.mod", "go.sum"):
666
671
  src = os.path.join(root_dir, mod_file)
667
672
  if os.path.isfile(src):
@@ -672,7 +677,24 @@ def apply_go_patch(workspace: str, dry_run: bool = False, root: str = ".") -> Di
672
677
  "path": src,
673
678
  "backup": dst,
674
679
  "before_sha": _sha256_file(src),
680
+ "created": False,
675
681
  })
682
+ else:
683
+ # `go get` may create go.sum; revert must remove it, not leave it.
684
+ module_backups.append({"path": src, "backup": None, "before_sha": None, "created": True})
685
+
686
+ # The dependency must be added *after* the backups: `go get` rewrites
687
+ # go.mod/go.sum, and a backup taken afterwards would restore the dependency
688
+ # instead of the pre-inject bytes.
689
+ dep_error = _ensure_go_dependency(root_dir)
690
+ if dep_error:
691
+ if os.path.isfile(backup_path):
692
+ os.unlink(backup_path)
693
+ for module in module_backups:
694
+ backup = module.get("backup")
695
+ if backup and os.path.isfile(backup):
696
+ os.unlink(backup)
697
+ return {"status": "skipped", "reason": dep_error}
676
698
 
677
699
  with open(path, "w", encoding="utf-8") as f:
678
700
  f.write(patched)
@@ -682,7 +704,11 @@ def apply_go_patch(workspace: str, dry_run: bool = False, root: str = ".") -> Di
682
704
  if not build_ok:
683
705
  shutil.copy2(backup_path, path)
684
706
  for module in module_backups:
685
- shutil.copy2(module["backup"], module["path"])
707
+ if module.get("created"):
708
+ if os.path.isfile(module["path"]):
709
+ os.remove(module["path"])
710
+ elif module.get("backup"):
711
+ shutil.copy2(module["backup"], module["path"])
686
712
  first_error = next((line for line in build_output.splitlines() if line.strip()), "")
687
713
  return {
688
714
  "status": "reverted",
@@ -692,7 +718,8 @@ def apply_go_patch(workspace: str, dry_run: bool = False, root: str = ".") -> Di
692
718
  }
693
719
 
694
720
  for module in module_backups:
695
- module["after_sha"] = _sha256_file(module["path"])
721
+ if os.path.isfile(module["path"]):
722
+ module["after_sha"] = _sha256_file(module["path"])
696
723
  _write_manifest(workspace, "go", {
697
724
  "kind": "go",
698
725
  "app": root,
@@ -746,6 +773,16 @@ def revert_go_patch(
746
773
  for module in manifest.get("modules") or []:
747
774
  path, module_backup = module.get("path"), module.get("backup")
748
775
  after = module.get("after_sha")
776
+ if module.get("created"):
777
+ if not path or not os.path.isfile(path):
778
+ modules.append({"path": path or "?", "status": "absent"})
779
+ continue
780
+ if after and _sha256_file(path) != after:
781
+ modules.append({"path": os.path.relpath(path, workspace), "status": "modules_modified"})
782
+ continue
783
+ os.remove(path)
784
+ modules.append({"path": os.path.relpath(path, workspace), "status": "removed"})
785
+ continue
749
786
  if not (path and module_backup and os.path.isfile(module_backup)):
750
787
  modules.append({"path": path or "?", "status": "backup-missing"})
751
788
  continue
@@ -1979,6 +2016,7 @@ def ensure_sidecar(kind: str) -> Tuple[Optional[str], str]:
1979
2016
  os.path.join(here, "..", "tokensafe-backend"),
1980
2017
  ]
1981
2018
  local_mismatch = None
2019
+ explicit_mismatch = None
1982
2020
  for repo in repo_candidates:
1983
2021
  candidate = os.path.join(os.path.abspath(repo), rel_source)
1984
2022
  if not os.path.isfile(candidate):
@@ -1986,10 +2024,12 @@ def ensure_sidecar(kind: str) -> Tuple[Optional[str], str]:
1986
2024
  if _sha256_file(candidate) == expected_sha:
1987
2025
  return adopt(candidate, f"cached from local checkout matching {_SIDECAR_RELEASE_TAG}")
1988
2026
  local_mismatch = candidate
2027
+ if explicit_repo and os.path.abspath(repo) == os.path.abspath(env_repo):
2028
+ explicit_mismatch = candidate
1989
2029
 
1990
2030
  def explicit_unpinned(note: str) -> Tuple[Optional[str], str]:
1991
- if explicit_repo and local_mismatch:
1992
- return adopt(local_mismatch, f"unpinned (OUMV_BACKEND_REPO): {local_mismatch}")
2031
+ if explicit_repo and explicit_mismatch:
2032
+ return adopt(explicit_mismatch, f"unpinned (OUMV_BACKEND_REPO): {explicit_mismatch}")
1993
2033
  return None, note
1994
2034
 
1995
2035
  if os.environ.get("TOKENSAFE_SIDECAR_OFFLINE") == "1":
package/src/mcp_server.py CHANGED
@@ -46,7 +46,7 @@ from src.session_context import current_root, current_session_id
46
46
 
47
47
  SERVER_INFO = {
48
48
  "name": "tokensafe-mcp",
49
- "version": "4.13.1"
49
+ "version": "4.13.2"
50
50
  }
51
51
 
52
52
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -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.13.1"
314
+ "User-Agent": "TokenSafe-Sync/4.13.2"
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.13.1"
20
+ CURRENT_VERSION = "4.13.2"
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