tokensafe 4.7.8 → 4.7.10
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/.codex-plugin/plugin.json +1 -1
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/auto_inject.py +312 -33
- package/src/installer.py +17 -10
- package/src/mcp_server.py +133 -14
- package/src/oumv_gateway.py +376 -52
- package/src/retrofit.py +69 -10
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.10",
|
|
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.
|
|
4
|
+
"version": "4.7.10",
|
|
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.
|
|
4
|
+
"version": "4.7.10",
|
|
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.
|
|
6
|
+
"version": "4.7.10",
|
|
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.
|
|
26
|
+
"version": "4.7.10",
|
|
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.
|
|
42
|
+
"version": "4.7.10",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/auto_inject.py
CHANGED
|
@@ -18,6 +18,7 @@ Two very different injection strategies live here, because the runtimes differ:
|
|
|
18
18
|
|
|
19
19
|
from __future__ import annotations
|
|
20
20
|
|
|
21
|
+
import glob
|
|
21
22
|
import hashlib
|
|
22
23
|
import json
|
|
23
24
|
import os
|
|
@@ -63,6 +64,51 @@ def _inject_dir(workspace: str) -> str:
|
|
|
63
64
|
return os.path.join(_tokensafe_home(), _INJECT_DIRNAME, _workspace_id(workspace))
|
|
64
65
|
|
|
65
66
|
|
|
67
|
+
def _manifest_path(workspace: str, kind: str) -> str:
|
|
68
|
+
"""One manifest per adapter kind: a monorepo can carry a Go patch and a .NET
|
|
69
|
+
patch at once, and a single shared file would lose the first one's backup."""
|
|
70
|
+
return os.path.join(_inject_dir(workspace), "manifests", f"{kind}.json")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _write_manifest(workspace: str, kind: str, payload: Dict[str, Any]) -> str:
|
|
74
|
+
path = _manifest_path(workspace, kind)
|
|
75
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
76
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
77
|
+
json.dump(payload, f, indent=2)
|
|
78
|
+
return path
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _read_manifest(workspace: str, kind: str, legacy_modes: tuple) -> Optional[Dict[str, Any]]:
|
|
82
|
+
"""Own manifest first; a legacy single manifest.json only when its mode belongs
|
|
83
|
+
to this adapter (the old file was shared by every kind)."""
|
|
84
|
+
own = _manifest_path(workspace, kind)
|
|
85
|
+
if os.path.isfile(own):
|
|
86
|
+
try:
|
|
87
|
+
with open(own, "r", encoding="utf-8") as f:
|
|
88
|
+
data = json.load(f)
|
|
89
|
+
data["_manifest"] = own
|
|
90
|
+
return data
|
|
91
|
+
except Exception:
|
|
92
|
+
return None
|
|
93
|
+
legacy = os.path.join(_inject_dir(workspace), "manifest.json")
|
|
94
|
+
if os.path.isfile(legacy):
|
|
95
|
+
try:
|
|
96
|
+
with open(legacy, "r", encoding="utf-8") as f:
|
|
97
|
+
data = json.load(f)
|
|
98
|
+
except Exception:
|
|
99
|
+
return None
|
|
100
|
+
if data.get("mode") in legacy_modes:
|
|
101
|
+
data["_manifest"] = legacy
|
|
102
|
+
return data
|
|
103
|
+
return None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _delete_manifest(manifest: Dict[str, Any]) -> None:
|
|
107
|
+
path = manifest.get("_manifest")
|
|
108
|
+
if path and os.path.isfile(path):
|
|
109
|
+
os.unlink(path)
|
|
110
|
+
|
|
111
|
+
|
|
66
112
|
def pyhooks_dir() -> str:
|
|
67
113
|
return os.path.join(_tokensafe_home(), _PYHOOKS_DIRNAME)
|
|
68
114
|
|
|
@@ -235,7 +281,7 @@ def go_patch_state(workspace: str) -> Dict[str, Any]:
|
|
|
235
281
|
_GO_MODULE = "github.com/tokensafe-dev/tokensafe-backend/go"
|
|
236
282
|
# Keep in step with the backend release tag (go/vX.Y.Z): injection must never
|
|
237
283
|
# downgrade an adapter that is already newer than this pin.
|
|
238
|
-
_GO_MODULE_VERSION = "v0.
|
|
284
|
+
_GO_MODULE_VERSION = "v0.9.0"
|
|
239
285
|
|
|
240
286
|
|
|
241
287
|
def _version_tuple(tag: str):
|
|
@@ -454,17 +500,12 @@ def apply_go_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
|
454
500
|
"build_output": build_output[-1200:],
|
|
455
501
|
}
|
|
456
502
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
"mode": "serve" if wrapped is not None else "mount",
|
|
464
|
-
},
|
|
465
|
-
f,
|
|
466
|
-
indent=2,
|
|
467
|
-
)
|
|
503
|
+
_write_manifest(workspace, "go", {
|
|
504
|
+
"entrypoint": path,
|
|
505
|
+
"backup": backup_path,
|
|
506
|
+
"framework": framework,
|
|
507
|
+
"mode": "serve" if wrapped is not None else "mount",
|
|
508
|
+
})
|
|
468
509
|
|
|
469
510
|
return {
|
|
470
511
|
"status": "patched",
|
|
@@ -494,17 +535,15 @@ def _go_build(workspace: str) -> Tuple[bool, str]:
|
|
|
494
535
|
|
|
495
536
|
|
|
496
537
|
def revert_go_patch(workspace: str) -> Dict[str, Any]:
|
|
497
|
-
|
|
498
|
-
if
|
|
538
|
+
manifest = _read_manifest(workspace, "go", ("serve", "mount", "go_patch"))
|
|
539
|
+
if manifest is None:
|
|
499
540
|
return {"status": "nothing-to-revert"}
|
|
500
|
-
with open(manifest_path, "r", encoding="utf-8") as f:
|
|
501
|
-
manifest = json.load(f)
|
|
502
541
|
target = manifest.get("entrypoint")
|
|
503
542
|
backup = manifest.get("backup")
|
|
504
543
|
if not target or not backup or not os.path.isfile(backup):
|
|
505
544
|
return {"status": "error", "reason": "backup missing"}
|
|
506
545
|
shutil.copy2(backup, target)
|
|
507
|
-
|
|
546
|
+
_delete_manifest(manifest)
|
|
508
547
|
return {"status": "reverted", "entrypoint": os.path.relpath(target, workspace)}
|
|
509
548
|
|
|
510
549
|
|
|
@@ -612,8 +651,7 @@ def apply_node_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
|
612
651
|
shutil.copy2(path, backup_path)
|
|
613
652
|
with open(path, "w", encoding="utf-8") as f:
|
|
614
653
|
f.write(patched)
|
|
615
|
-
|
|
616
|
-
json.dump({"entrypoint": path, "backup": backup_path, "framework": framework, "mode": "node_mount"}, f, indent=2)
|
|
654
|
+
_write_manifest(workspace, "node", {"entrypoint": path, "backup": backup_path, "framework": framework})
|
|
617
655
|
return {
|
|
618
656
|
"status": "patched",
|
|
619
657
|
"entrypoint": os.path.relpath(path, workspace),
|
|
@@ -625,22 +663,15 @@ def apply_node_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
|
625
663
|
|
|
626
664
|
|
|
627
665
|
def revert_node_patch(workspace: str) -> Dict[str, Any]:
|
|
628
|
-
|
|
629
|
-
if
|
|
666
|
+
manifest = _read_manifest(workspace, "node", ("node_mount",))
|
|
667
|
+
if manifest is None:
|
|
630
668
|
return {"status": "clean", "reason": "no Node patch manifest"}
|
|
631
|
-
try:
|
|
632
|
-
with open(manifest_path, "r", encoding="utf-8") as f:
|
|
633
|
-
manifest = json.load(f)
|
|
634
|
-
except Exception as exc:
|
|
635
|
-
return {"status": "error", "reason": f"cannot read manifest: {exc}"}
|
|
636
|
-
if manifest.get("mode") != "node_mount":
|
|
637
|
-
return {"status": "clean", "reason": "manifest is not a Node patch"}
|
|
638
669
|
entrypoint = manifest.get("entrypoint")
|
|
639
670
|
backup = manifest.get("backup")
|
|
640
671
|
if not (entrypoint and backup and os.path.isfile(backup)):
|
|
641
672
|
return {"status": "error", "reason": "backup missing; restore manually"}
|
|
642
673
|
shutil.copy2(backup, entrypoint)
|
|
643
|
-
|
|
674
|
+
_delete_manifest(manifest)
|
|
644
675
|
return {"status": "reverted", "entrypoint": os.path.relpath(entrypoint, workspace)}
|
|
645
676
|
|
|
646
677
|
|
|
@@ -648,20 +679,249 @@ def _sidecar_cache_dir() -> str:
|
|
|
648
679
|
return os.path.join(_tokensafe_home(), "sidecars")
|
|
649
680
|
|
|
650
681
|
|
|
682
|
+
# --- ASP.NET Core -----------------------------------------------------------------
|
|
683
|
+
#
|
|
684
|
+
# The .NET adapter is a NuGet package with a middleware mount, so injection is the
|
|
685
|
+
# same shape as Go/Node: one visible, reversible block in Program.cs. The builder
|
|
686
|
+
# line is required only because ASP.NET Core does not expose the service collection
|
|
687
|
+
# after Build(), and EF Core DbContext discovery needs it.
|
|
688
|
+
|
|
689
|
+
_DOTNET_MARK_BEGIN = "// tokensafe:oumv:begin"
|
|
690
|
+
_DOTNET_MARK_END = "// tokensafe:oumv:end"
|
|
691
|
+
_DOTNET_PACKAGE = "TokenSafe.Oumv.AspNetCore"
|
|
692
|
+
_DOTNET_PACKAGE_VERSION = "0.1.1"
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def _dotnet_cli() -> str:
|
|
697
|
+
"""Resolves the dotnet executable: explicit override, then DOTNET_ROOT, then PATH.
|
|
698
|
+
|
|
699
|
+
A machine can carry an old SDK on PATH (this one had 7.0) while a current one
|
|
700
|
+
lives under DOTNET_ROOT; the build pre-flight must use the latter or a net10
|
|
701
|
+
project fails to compile for the wrong reason.
|
|
702
|
+
"""
|
|
703
|
+
override = os.environ.get("TOKENSAFE_DOTNET")
|
|
704
|
+
if override and os.path.isfile(override):
|
|
705
|
+
return override
|
|
706
|
+
root = os.environ.get("DOTNET_ROOT")
|
|
707
|
+
if root:
|
|
708
|
+
candidate = os.path.join(root, "dotnet.exe" if os.name == "nt" else "dotnet")
|
|
709
|
+
if os.path.isfile(candidate):
|
|
710
|
+
return candidate
|
|
711
|
+
return "dotnet"
|
|
712
|
+
|
|
713
|
+
def _dotnet_web_project(workspace: str) -> Optional[str]:
|
|
714
|
+
"""Finds a web csproj (Microsoft.NET.Sdk.Web or the ASP.NET Core framework reference)."""
|
|
715
|
+
for root, dirs, files in os.walk(workspace):
|
|
716
|
+
dirs[:] = [d for d in dirs if d not in ("bin", "obj", "node_modules", ".git", ".tokensafe")]
|
|
717
|
+
for name in files:
|
|
718
|
+
if not name.endswith(".csproj"):
|
|
719
|
+
continue
|
|
720
|
+
path = os.path.join(root, name)
|
|
721
|
+
try:
|
|
722
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
723
|
+
content = handle.read()
|
|
724
|
+
except OSError:
|
|
725
|
+
continue
|
|
726
|
+
if "Microsoft.NET.Sdk.Web" in content or "Microsoft.AspNetCore.App" in content:
|
|
727
|
+
return path
|
|
728
|
+
return None
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
def _find_dotnet_entrypoint(workspace: str, project: Optional[str] = None) -> Optional[str]:
|
|
732
|
+
"""Program.cs next to the web project (top-level statements), if present."""
|
|
733
|
+
if project:
|
|
734
|
+
candidate = os.path.join(os.path.dirname(project), "Program.cs")
|
|
735
|
+
if os.path.isfile(candidate):
|
|
736
|
+
return candidate
|
|
737
|
+
candidate = os.path.join(workspace, "Program.cs")
|
|
738
|
+
return candidate if os.path.isfile(candidate) else None
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
def dotnet_patch_state(workspace: str) -> Dict[str, Any]:
|
|
742
|
+
"""Reports whether the OUMV mount is already present in Program.cs."""
|
|
743
|
+
project = _dotnet_web_project(workspace)
|
|
744
|
+
entrypoint = _find_dotnet_entrypoint(workspace, project)
|
|
745
|
+
if not entrypoint:
|
|
746
|
+
return {"entrypoint": None, "patched": False, "project": project}
|
|
747
|
+
try:
|
|
748
|
+
with open(entrypoint, "r", encoding="utf-8") as handle:
|
|
749
|
+
source = handle.read()
|
|
750
|
+
except OSError:
|
|
751
|
+
return {"entrypoint": os.path.relpath(entrypoint, workspace), "patched": False, "project": project}
|
|
752
|
+
return {
|
|
753
|
+
"entrypoint": os.path.relpath(entrypoint, workspace),
|
|
754
|
+
"patched": _DOTNET_MARK_BEGIN in source and _DOTNET_MARK_END in source,
|
|
755
|
+
"project": os.path.relpath(project, workspace) if project else None,
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
def _dotnet_build(project: str) -> Tuple[bool, str]:
|
|
760
|
+
try:
|
|
761
|
+
result = subprocess.run(
|
|
762
|
+
[_dotnet_cli(), "build", project, "-c", "Release", "--nologo", "-v", "quiet"],
|
|
763
|
+
capture_output=True,
|
|
764
|
+
text=True,
|
|
765
|
+
timeout=600,
|
|
766
|
+
)
|
|
767
|
+
return result.returncode == 0, (result.stdout + result.stderr)[-1500:]
|
|
768
|
+
except FileNotFoundError:
|
|
769
|
+
return False, "dotnet SDK not found on PATH"
|
|
770
|
+
except subprocess.TimeoutExpired:
|
|
771
|
+
return False, "dotnet build timed out"
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
def _ensure_dotnet_dependency(project: str) -> Optional[str]:
|
|
775
|
+
"""Adds the NuGet package once; returns a note when the CLI could not do it."""
|
|
776
|
+
try:
|
|
777
|
+
with open(project, "r", encoding="utf-8") as handle:
|
|
778
|
+
content = handle.read()
|
|
779
|
+
except OSError:
|
|
780
|
+
return f"could not read {project}"
|
|
781
|
+
if _DOTNET_PACKAGE in content:
|
|
782
|
+
return None
|
|
783
|
+
try:
|
|
784
|
+
result = subprocess.run(
|
|
785
|
+
[_dotnet_cli(), "add", project, "package", _DOTNET_PACKAGE, "--version", _DOTNET_PACKAGE_VERSION],
|
|
786
|
+
capture_output=True,
|
|
787
|
+
text=True,
|
|
788
|
+
timeout=300,
|
|
789
|
+
)
|
|
790
|
+
except FileNotFoundError:
|
|
791
|
+
return f"dotnet SDK not found; add <PackageReference Include=\"{_DOTNET_PACKAGE}\" Version=\"{_DOTNET_PACKAGE_VERSION}\" /> manually"
|
|
792
|
+
except subprocess.TimeoutExpired:
|
|
793
|
+
return "dotnet add package timed out"
|
|
794
|
+
if result.returncode != 0:
|
|
795
|
+
return f"dotnet add package failed; add the PackageReference manually: {(result.stdout + result.stderr)[-300:]}"
|
|
796
|
+
return None
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
def apply_dotnet_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
800
|
+
"""Inserts `using`, `AddTokensafe()` and `UseTokensafe()` between tokensafe markers."""
|
|
801
|
+
project = _dotnet_web_project(workspace)
|
|
802
|
+
if not project:
|
|
803
|
+
return {"status": "skipped", "reason": "no ASP.NET Core (Microsoft.NET.Sdk.Web) project found"}
|
|
804
|
+
entrypoint = _find_dotnet_entrypoint(workspace, project)
|
|
805
|
+
if not entrypoint:
|
|
806
|
+
return {"status": "skipped", "reason": "no Program.cs next to the web project"}
|
|
807
|
+
|
|
808
|
+
with open(entrypoint, "r", encoding="utf-8") as handle:
|
|
809
|
+
source = handle.read()
|
|
810
|
+
if _DOTNET_MARK_BEGIN in source:
|
|
811
|
+
return {"status": "already_patched", "entrypoint": os.path.relpath(entrypoint, workspace)}
|
|
812
|
+
|
|
813
|
+
builder = re.search(
|
|
814
|
+
r"(?m)^(?P<indent>[ \t]*)(?:var|WebApplicationBuilder)\s+(?P<builder>\w+)\s*=\s*WebApplication\.CreateBuilder\(",
|
|
815
|
+
source,
|
|
816
|
+
)
|
|
817
|
+
app = re.search(
|
|
818
|
+
r"(?m)^(?P<indent>[ \t]*)(?:var|WebApplication)\s+(?P<app>\w+)\s*=\s*(?P<builder>\w+)\.Build\(\)\s*;",
|
|
819
|
+
source,
|
|
820
|
+
)
|
|
821
|
+
if not builder or not app:
|
|
822
|
+
return {
|
|
823
|
+
"status": "skipped",
|
|
824
|
+
"reason": "could not find `WebApplication.CreateBuilder(...)` and `builder.Build()` in Program.cs",
|
|
825
|
+
}
|
|
826
|
+
if builder.group("builder") != app.group("builder"):
|
|
827
|
+
return {"status": "skipped", "reason": "Program.cs builds the app from a different builder variable"}
|
|
828
|
+
|
|
829
|
+
def insertion(line_match: "re.Match[str]", body: str) -> Tuple[int, str]:
|
|
830
|
+
line_end = source.find("\n", line_match.end())
|
|
831
|
+
insert_at = len(source) if line_end < 0 else line_end + 1
|
|
832
|
+
indent = line_match.group("indent")
|
|
833
|
+
block = f"{_DOTNET_MARK_BEGIN}\n{indent}{body}\n{_DOTNET_MARK_END}\n"
|
|
834
|
+
return insert_at, block
|
|
835
|
+
|
|
836
|
+
services_at, services_block = insertion(
|
|
837
|
+
builder, f"{builder.group('builder')}.Services.AddTokensafe();"
|
|
838
|
+
)
|
|
839
|
+
mount_at, mount_block = insertion(app, f"{app.group('app')}.UseTokensafe();")
|
|
840
|
+
|
|
841
|
+
using_block = ""
|
|
842
|
+
if not re.search(r"(?m)^\s*using\s+TokenSafe\.Oumv\s*;", source):
|
|
843
|
+
using_lines = list(re.finditer(r"(?m)^using\s+[^;]+;\s*$", source))
|
|
844
|
+
using_block = f"{_DOTNET_MARK_BEGIN}\nusing TokenSafe.Oumv;\n{_DOTNET_MARK_END}\n"
|
|
845
|
+
if using_lines:
|
|
846
|
+
last = using_lines[-1]
|
|
847
|
+
line_end = source.find("\n", last.end())
|
|
848
|
+
using_at = len(source) if line_end < 0 else line_end + 1
|
|
849
|
+
else:
|
|
850
|
+
using_at = 0
|
|
851
|
+
|
|
852
|
+
patched = source
|
|
853
|
+
# Insert from the bottom up so earlier offsets stay valid.
|
|
854
|
+
for position, block in sorted(((services_at, services_block), (mount_at, mount_block)), reverse=True):
|
|
855
|
+
patched = patched[:position] + block + patched[position:]
|
|
856
|
+
if using_block:
|
|
857
|
+
patched = patched[:using_at] + using_block + patched[using_at:]
|
|
858
|
+
|
|
859
|
+
if dry_run:
|
|
860
|
+
return {
|
|
861
|
+
"status": "dry_run",
|
|
862
|
+
"entrypoint": os.path.relpath(entrypoint, workspace),
|
|
863
|
+
"preview": f"{builder.group('builder')}.Services.AddTokensafe();\n{app.group('app')}.UseTokensafe();",
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
backup_dir = _inject_dir(workspace)
|
|
867
|
+
os.makedirs(backup_dir, exist_ok=True)
|
|
868
|
+
backup_path = os.path.join(backup_dir, os.path.relpath(entrypoint, workspace).replace(os.sep, "__") + ".bak")
|
|
869
|
+
shutil.copy2(entrypoint, backup_path)
|
|
870
|
+
with open(entrypoint, "w", encoding="utf-8") as handle:
|
|
871
|
+
handle.write(patched)
|
|
872
|
+
|
|
873
|
+
dependency_note = _ensure_dotnet_dependency(project)
|
|
874
|
+
build_ok, build_output = _dotnet_build(project) if dependency_note is None else (False, "skipped")
|
|
875
|
+
if not build_ok:
|
|
876
|
+
shutil.copy2(backup_path, entrypoint)
|
|
877
|
+
os.unlink(backup_path)
|
|
878
|
+
return {
|
|
879
|
+
"status": "reverted",
|
|
880
|
+
"entrypoint": os.path.relpath(entrypoint, workspace),
|
|
881
|
+
"reason": dependency_note or "dotnet build failed",
|
|
882
|
+
"build": build_output[-800:],
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
_write_manifest(workspace, "dotnet",
|
|
886
|
+
{"entrypoint": entrypoint, "backup": backup_path, "framework": "aspnetcore"})
|
|
887
|
+
return {
|
|
888
|
+
"status": "patched",
|
|
889
|
+
"entrypoint": os.path.relpath(entrypoint, workspace),
|
|
890
|
+
"framework": "aspnetcore",
|
|
891
|
+
"mode": "dotnet_mount",
|
|
892
|
+
"backup": backup_path,
|
|
893
|
+
"line": f"{app.group('app')}.UseTokensafe();",
|
|
894
|
+
"dependency": f"{_DOTNET_PACKAGE}@{_DOTNET_PACKAGE_VERSION}",
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
def revert_dotnet_patch(workspace: str) -> Dict[str, Any]:
|
|
899
|
+
manifest = _read_manifest(workspace, "dotnet", ("dotnet_mount",))
|
|
900
|
+
if manifest is None:
|
|
901
|
+
return {"status": "clean", "reason": "no .NET patch manifest"}
|
|
902
|
+
entrypoint = manifest.get("entrypoint")
|
|
903
|
+
backup = manifest.get("backup")
|
|
904
|
+
if not (entrypoint and backup and os.path.isfile(backup)):
|
|
905
|
+
return {"status": "error", "reason": "backup missing; restore manually"}
|
|
906
|
+
shutil.copy2(backup, entrypoint)
|
|
907
|
+
_delete_manifest(manifest)
|
|
908
|
+
return {"status": "reverted", "entrypoint": os.path.relpath(entrypoint, workspace)}
|
|
909
|
+
|
|
910
|
+
|
|
651
911
|
# Pinned to the backend release: the sidecars are single files, so the cache is
|
|
652
912
|
# content-addressed by SHA-256 and a clean machine downloads the exact bytes the
|
|
653
913
|
# release was certified from. Bump both the tag and the hashes together.
|
|
654
|
-
_SIDECAR_RELEASE_TAG = "v0.
|
|
914
|
+
_SIDECAR_RELEASE_TAG = "v0.9.0"
|
|
655
915
|
_SIDECARS = {
|
|
656
916
|
"spring": (
|
|
657
917
|
"java/src/dev/tokensafe/oumv/OumvSpring.java",
|
|
658
918
|
"OumvSpring.java",
|
|
659
|
-
"
|
|
919
|
+
"011b770c69e182f339b36ef1002dbcf135e066744285354b64990ec3b595afb3",
|
|
660
920
|
),
|
|
661
921
|
"php": (
|
|
662
922
|
"php/bin/oumv-php",
|
|
663
923
|
"oumv-php",
|
|
664
|
-
"
|
|
924
|
+
"f22c19c050869d613989dea24edde0cacdc3d3fb876cd43834ca4e614ec89900",
|
|
665
925
|
),
|
|
666
926
|
}
|
|
667
927
|
|
|
@@ -784,6 +1044,7 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
784
1044
|
"node": "backend/node",
|
|
785
1045
|
"spring": "backend/spring",
|
|
786
1046
|
"php": "backend/php",
|
|
1047
|
+
"dotnet": "backend/aspnetcore",
|
|
787
1048
|
}.get(provider, "backend/go")
|
|
788
1049
|
entry = catalog.get(entry_id, {})
|
|
789
1050
|
install = entry.get("technology", {}).get("package", {}).get("install")
|
|
@@ -821,6 +1082,20 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
821
1082
|
"description": "one mountTokensafe(app)/registerTokensafe(app) line between tokensafe markers; byte-exact backup + --revert",
|
|
822
1083
|
"install": install or "npm install tokensafe-backend-node",
|
|
823
1084
|
})
|
|
1085
|
+
elif provider == "dotnet":
|
|
1086
|
+
state = dotnet_patch_state(workspace)
|
|
1087
|
+
actions.append({
|
|
1088
|
+
"kind": "dotnet_one_line_patch",
|
|
1089
|
+
"profile": "backend",
|
|
1090
|
+
"framework": "aspnetcore",
|
|
1091
|
+
"writes_repo": True,
|
|
1092
|
+
"already_patched": state["patched"],
|
|
1093
|
+
"entrypoint": state["entrypoint"],
|
|
1094
|
+
"project": state.get("project"),
|
|
1095
|
+
"description": "one AddTokensafe()/UseTokensafe() pair between tokensafe markers; byte-exact backup + --revert",
|
|
1096
|
+
"install": install or f"dotnet add package {_DOTNET_PACKAGE}",
|
|
1097
|
+
"run": "dotnet run",
|
|
1098
|
+
})
|
|
824
1099
|
elif provider in ("spring", "php"):
|
|
825
1100
|
sidecar_path, note = ensure_sidecar(provider)
|
|
826
1101
|
command = sidecar_run_command(provider, sidecar_path or "", workspace)
|
|
@@ -848,7 +1123,8 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
848
1123
|
"profiles": [p for p in ("frontend", "backend") if stack.get(p)],
|
|
849
1124
|
"actions": actions,
|
|
850
1125
|
"python_autoload_present": python_autoload_present(),
|
|
851
|
-
"revertable":
|
|
1126
|
+
"revertable": bool(glob.glob(os.path.join(_inject_dir(workspace), "manifests", "*.json")))
|
|
1127
|
+
or os.path.isfile(os.path.join(_inject_dir(workspace), "manifest.json")),
|
|
852
1128
|
}
|
|
853
1129
|
|
|
854
1130
|
|
|
@@ -884,6 +1160,8 @@ def apply(workspace: str, dry_run: bool = False, include_go: bool = True) -> Dic
|
|
|
884
1160
|
results["actions"].append({"kind": "go_one_line_patch", **apply_go_patch(workspace, dry_run=dry_run)})
|
|
885
1161
|
elif backend.get("provider") == "node":
|
|
886
1162
|
results["actions"].append({"kind": "node_one_line_patch", **apply_node_patch(workspace, dry_run=dry_run)})
|
|
1163
|
+
elif backend.get("provider") == "dotnet":
|
|
1164
|
+
results["actions"].append({"kind": "dotnet_one_line_patch", **apply_dotnet_patch(workspace, dry_run=dry_run)})
|
|
887
1165
|
elif backend.get("provider") in ("spring", "php"):
|
|
888
1166
|
sidecar_path, note = ensure_sidecar(backend["provider"])
|
|
889
1167
|
results["actions"].append({
|
|
@@ -902,4 +1180,5 @@ def revert(workspace: str) -> Dict[str, Any]:
|
|
|
902
1180
|
"workspace": workspace,
|
|
903
1181
|
"go": revert_go_patch(workspace),
|
|
904
1182
|
"node": revert_node_patch(workspace),
|
|
1183
|
+
"dotnet": revert_dotnet_patch(workspace),
|
|
905
1184
|
}
|
package/src/installer.py
CHANGED
|
@@ -2345,7 +2345,7 @@ WantedBy=default.target
|
|
|
2345
2345
|
"message": "; ".join(msgs) if msgs else "Cleaned"
|
|
2346
2346
|
}
|
|
2347
2347
|
|
|
2348
|
-
cls.restart_mcp_daemons()
|
|
2348
|
+
cls.restart_mcp_daemons(kill_running=True)
|
|
2349
2349
|
proj_report = cls.uninstall_project(os.getcwd())
|
|
2350
2350
|
|
|
2351
2351
|
purged = False
|
|
@@ -2429,7 +2429,7 @@ WantedBy=default.target
|
|
|
2429
2429
|
else:
|
|
2430
2430
|
print(f" \033[33m–\033[0m \033[1m{name}\033[0m: Nothing to remove")
|
|
2431
2431
|
|
|
2432
|
-
cls.restart_mcp_daemons()
|
|
2432
|
+
cls.restart_mcp_daemons(kill_running=True)
|
|
2433
2433
|
proj_rep = cls.uninstall_project(os.getcwd())
|
|
2434
2434
|
if proj_rep.get("cleaned_rules"):
|
|
2435
2435
|
print(f"\n\033[32m✔ Cleaned project rules from: {', '.join(proj_rep['cleaned_rules'])}\033[0m")
|
|
@@ -2482,10 +2482,16 @@ WantedBy=default.target
|
|
|
2482
2482
|
return False
|
|
2483
2483
|
|
|
2484
2484
|
@classmethod
|
|
2485
|
-
def restart_mcp_daemons(cls) -> int:
|
|
2485
|
+
def restart_mcp_daemons(cls, kill_running: bool = False) -> int:
|
|
2486
2486
|
"""
|
|
2487
|
-
Touches the MCP reload marker
|
|
2488
|
-
|
|
2487
|
+
Touches the MCP reload marker so auto-reconnecting IDEs (Antigravity, Cursor,
|
|
2488
|
+
Claude Code) spawn the updated version.
|
|
2489
|
+
|
|
2490
|
+
By default nothing is killed: running TokenSafe MCP servers belong to live
|
|
2491
|
+
sessions of any host, and a machine-wide SIGTERM during an update kills
|
|
2492
|
+
concurrent sessions' gateways (session-scoped MCP hosts never respawn them).
|
|
2493
|
+
Uninstall flows pass kill_running=True because removing TokenSafe should
|
|
2494
|
+
stop it everywhere.
|
|
2489
2495
|
"""
|
|
2490
2496
|
try:
|
|
2491
2497
|
# Data-dir resolution is context-independent (canonical
|
|
@@ -2500,7 +2506,7 @@ WantedBy=default.target
|
|
|
2500
2506
|
except Exception:
|
|
2501
2507
|
pass
|
|
2502
2508
|
|
|
2503
|
-
if os.name == "nt":
|
|
2509
|
+
if not kill_running or os.name == "nt":
|
|
2504
2510
|
return 0
|
|
2505
2511
|
|
|
2506
2512
|
my_pid = os.getpid()
|
|
@@ -2906,11 +2912,12 @@ WantedBy=default.target
|
|
|
2906
2912
|
except Exception:
|
|
2907
2913
|
pass
|
|
2908
2914
|
|
|
2909
|
-
# 6.
|
|
2915
|
+
# 6. Flag the reload so auto-reconnecting IDEs pick the new version.
|
|
2916
|
+
# Running servers are NOT killed: they belong to live sessions of
|
|
2917
|
+
# other agents, and session-scoped MCP hosts never respawn them.
|
|
2910
2918
|
restarted_count = cls.restart_mcp_daemons()
|
|
2911
|
-
if restarted_count
|
|
2912
|
-
print(f" {
|
|
2913
|
-
print(f" {CYAN}ℹ{RESET} Antigravity/Cursor/Claude Code reconnect automatically; reload MCP in Claude Desktop/VS Code if disconnected.")
|
|
2919
|
+
if restarted_count == 0:
|
|
2920
|
+
print(f" {CYAN}ℹ{RESET} Reload marker written; running sessions keep their current engine until restarted (by design).")
|
|
2914
2921
|
|
|
2915
2922
|
# 7. Proxy re-assertion (ultimate, default-on): TokenSafe is the default LLM
|
|
2916
2923
|
# route for every wire-able agent. Agent/app updates are known to rewrite
|