tokensafe 4.7.19 → 4.7.21
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/README.md +5 -2
- 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 +273 -27
- package/src/mcp_server.py +1 -1
- package/src/oumv_gateway.py +14 -0
- package/src/retrofit.py +13 -9
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/README.md
CHANGED
|
@@ -225,8 +225,11 @@ You install TokenSafe, open a project in your agent, and the first turn does the
|
|
|
225
225
|
`~/.tokensafe/inject/`, `go build` validated, `tokensafe inject --revert` restores it;
|
|
226
226
|
* Node (Express/Fastify) — one `mountTokensafe(app)` / `registerTokensafe(app)` line, same
|
|
227
227
|
markers and byte-exact revert; ASP.NET Core — one `AddTokensafe()`/`UseTokensafe()` pair;
|
|
228
|
-
* Next.js (App Router) —
|
|
229
|
-
(`createNextRouteHandlers
|
|
228
|
+
* Next.js (App Router) — three generated files: `app/api/tokensafe/route.ts`
|
|
229
|
+
(`createNextRouteHandlers`, bridge on), `app/api/tokensafe/bridge/route.ts` (the
|
|
230
|
+
browser bridge) and `instrumentation-client.ts` (`installNextBridge`, Next ≥ 15.3);
|
|
231
|
+
older Next gets the two route files plus a manual snippet. `--revert` deletes
|
|
232
|
+
exactly the files it created;
|
|
230
233
|
* Elysia (Bun) — one `app.use(oumv())` line before `app.listen()`
|
|
231
234
|
(`tokensafe-backend-node/elysia`), same markers and byte-exact revert.
|
|
232
235
|
3. **Brief the agent** — a short routing block (hook context and MCP `instructions`) says which
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.21",
|
|
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.21",
|
|
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.21",
|
|
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.21",
|
|
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.21",
|
|
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.21",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/auto_inject.py
CHANGED
|
@@ -801,10 +801,57 @@ def revert_elysia_patch(workspace: str) -> Dict[str, Any]:
|
|
|
801
801
|
|
|
802
802
|
|
|
803
803
|
# Next.js App Router: the adapter is a Route Handler created by the npm package.
|
|
804
|
-
# Nothing is patched inside app components —
|
|
805
|
-
#
|
|
806
|
-
|
|
807
|
-
|
|
804
|
+
# Nothing is patched inside app components — `tokensafe inject` writes three files
|
|
805
|
+
# (RPC route, bridge route, instrumentation-client) and `--revert` removes exactly
|
|
806
|
+
# what it created, so the worktree returns to its old shape.
|
|
807
|
+
_NEXT_RPC_REL = ("api", "tokensafe", "route.ts")
|
|
808
|
+
_NEXT_BRIDGE_REL = ("api", "tokensafe", "bridge", "route.ts")
|
|
809
|
+
_NEXT_INSTRUMENTATION = "instrumentation-client.ts"
|
|
810
|
+
# `instrumentation-client` exists since Next 15.3; older apps get the route files
|
|
811
|
+
# and a manual snippet instead of a pretend install.
|
|
812
|
+
_NEXT_INSTRUMENTATION_MIN = (15, 3)
|
|
813
|
+
|
|
814
|
+
_NEXT_RPC_SOURCE = """// TokenSafe OUMV Route Handler (App Router, wire 1.6.0).
|
|
815
|
+
// Generated by `tokensafe inject`; delete this file (or run `tokensafe inject --revert`) to unmount.
|
|
816
|
+
import { createNextRouteHandlers } from 'tokensafe-backend-node';
|
|
817
|
+
|
|
818
|
+
const handlers = createNextRouteHandlers({
|
|
819
|
+
workspaceDir: process.cwd(),
|
|
820
|
+
// Spec §7.4: binds this runtime to the page broker (BridgeBroker), so client
|
|
821
|
+
// components are observable and DOM-target verify reaches the live tab.
|
|
822
|
+
bridge: true,
|
|
823
|
+
publicUrl: `${process.env.TOKENSAFE_OUMV_PUBLIC_URL ?? 'http://127.0.0.1:3000'}/api/tokensafe`,
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
export const POST = handlers.POST;
|
|
827
|
+
export const GET = handlers.GET;
|
|
828
|
+
"""
|
|
829
|
+
|
|
830
|
+
_NEXT_BRIDGE_SOURCE = """// TokenSafe OUMV Bridge Route Handler (App Router, spec §7.4).
|
|
831
|
+
// Generated by `tokensafe inject`; delete this file (or run `tokensafe inject --revert`) to unmount.
|
|
832
|
+
// The page registers for a short-lived session token, pushes snapshots and
|
|
833
|
+
// traces, and receives observe/verify commands. 404 in production.
|
|
834
|
+
import { createNextBridgeHandlers } from 'tokensafe-backend-node';
|
|
835
|
+
|
|
836
|
+
const bridge = createNextBridgeHandlers({ workspaceDir: process.cwd() });
|
|
837
|
+
|
|
838
|
+
export const GET = bridge.GET;
|
|
839
|
+
export const POST = bridge.POST;
|
|
840
|
+
"""
|
|
841
|
+
|
|
842
|
+
_NEXT_INSTRUMENTATION_SOURCE = """// TokenSafe OUMV client bridge (spec §7.4).
|
|
843
|
+
// Generated by `tokensafe inject`; delete this file (or run `tokensafe inject --revert`) to unmount.
|
|
844
|
+
// Next >= 15.3 loads this module in the browser before the app code, which is
|
|
845
|
+
// what lets the bridge see client components. installNextBridge() is a no-op in
|
|
846
|
+
// a production build.
|
|
847
|
+
import { installNextBridge } from 'tokensafe-backend-node/next-bridge';
|
|
848
|
+
|
|
849
|
+
installNextBridge();
|
|
850
|
+
"""
|
|
851
|
+
|
|
852
|
+
# The v1 generator wrote one file without the bridge; kept verbatim so an upgrade
|
|
853
|
+
# can recognise its own output and replace it, and never a user-edited route.
|
|
854
|
+
_NEXT_LEGACY_ROUTE_SOURCE = """// TokenSafe OUMV Route Handler (App Router, wire 1.6.0).
|
|
808
855
|
// Generated by `tokensafe inject`; delete this file (or run `tokensafe inject --revert`) to unmount.
|
|
809
856
|
import { createNextRouteHandlers } from 'tokensafe-backend-node';
|
|
810
857
|
|
|
@@ -818,42 +865,229 @@ export const GET = handlers.GET;
|
|
|
818
865
|
"""
|
|
819
866
|
|
|
820
867
|
|
|
868
|
+
def _next_app_dir(workspace: str) -> Tuple[str, str]:
|
|
869
|
+
"""Next keeps the App Router at app/ or src/app/; both are first-class."""
|
|
870
|
+
src_app = os.path.join(workspace, "src", "app")
|
|
871
|
+
if os.path.isdir(src_app):
|
|
872
|
+
return src_app, "src"
|
|
873
|
+
return os.path.join(workspace, "app"), ""
|
|
874
|
+
|
|
875
|
+
|
|
821
876
|
def next_route_path(workspace: str) -> str:
|
|
822
|
-
|
|
877
|
+
app_dir, _ = _next_app_dir(workspace)
|
|
878
|
+
return os.path.join(app_dir, *_NEXT_RPC_REL)
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def _next_instrumentation_path(workspace: str) -> str:
|
|
882
|
+
_, source_root = _next_app_dir(workspace)
|
|
883
|
+
# Next resolves instrumentation-client from the project root, or src/ when the
|
|
884
|
+
# app itself lives under src/.
|
|
885
|
+
return os.path.join(workspace, source_root, _NEXT_INSTRUMENTATION) if source_root else os.path.join(workspace, _NEXT_INSTRUMENTATION)
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
def _next_instrumentation_candidates(workspace: str) -> List[str]:
|
|
889
|
+
"""Every extension Next would load, so we never shadow a user's own loader."""
|
|
890
|
+
base = os.path.splitext(_next_instrumentation_path(workspace))[0]
|
|
891
|
+
return [base + ext for ext in (".ts", ".js", ".tsx", ".jsx", ".mjs")]
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
def _next_existing_instrumentation(workspace: str) -> Optional[str]:
|
|
895
|
+
for path in _next_instrumentation_candidates(workspace):
|
|
896
|
+
if os.path.isfile(path):
|
|
897
|
+
return path
|
|
898
|
+
return None
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
def _file_mentions(path: Optional[str], needle: str) -> bool:
|
|
902
|
+
if not path or not os.path.isfile(path):
|
|
903
|
+
return False
|
|
904
|
+
try:
|
|
905
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
906
|
+
return needle in handle.read()
|
|
907
|
+
except Exception:
|
|
908
|
+
return False
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
def _next_instrumentation_installed(workspace: str) -> bool:
|
|
912
|
+
return _file_mentions(_next_existing_instrumentation(workspace), "installNextBridge")
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
def _next_files(workspace: str) -> List[Tuple[str, str]]:
|
|
916
|
+
app_dir, _ = _next_app_dir(workspace)
|
|
917
|
+
files: List[Tuple[str, str]] = [
|
|
918
|
+
(os.path.join(app_dir, *_NEXT_RPC_REL), _NEXT_RPC_SOURCE),
|
|
919
|
+
(os.path.join(app_dir, *_NEXT_BRIDGE_REL), _NEXT_BRIDGE_SOURCE),
|
|
920
|
+
]
|
|
921
|
+
# Next <15.3 never loads instrumentation-client, so writing it would be a file
|
|
922
|
+
# that pretends to work. Those apps get the two route files plus the manual
|
|
923
|
+
# snippet; the bridge itself is unchanged once the loader exists.
|
|
924
|
+
if next_bridge_mode(workspace) == "instrumentation":
|
|
925
|
+
existing = _next_existing_instrumentation(workspace)
|
|
926
|
+
if existing is None:
|
|
927
|
+
files.append((_next_instrumentation_path(workspace), _NEXT_INSTRUMENTATION_SOURCE))
|
|
928
|
+
# An existing loader is the user's file: never create a second one next to
|
|
929
|
+
# it. apply() reports whether it already calls installNextBridge().
|
|
930
|
+
return files
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
def _parse_next_version(raw: Any) -> Optional[Tuple[int, int]]:
|
|
934
|
+
text = str(raw or "").strip().lstrip("^~>= v")
|
|
935
|
+
match = re.match(r"(\d+)(?:\.(\d+))?", text)
|
|
936
|
+
if not match:
|
|
937
|
+
return None
|
|
938
|
+
return int(match.group(1)), int(match.group(2) or 0)
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
def next_bridge_mode(workspace: str) -> str:
|
|
942
|
+
"""`instrumentation` when Next >= 15.3 can load the client, else `manual`."""
|
|
943
|
+
package_json = os.path.join(workspace, "package.json")
|
|
944
|
+
try:
|
|
945
|
+
with open(package_json, "r", encoding="utf-8") as handle:
|
|
946
|
+
data = json.load(handle)
|
|
947
|
+
except Exception:
|
|
948
|
+
return "manual"
|
|
949
|
+
deps = {}
|
|
950
|
+
for key in ("dependencies", "devDependencies"):
|
|
951
|
+
deps.update(data.get(key) or {})
|
|
952
|
+
version = _parse_next_version(deps.get("next"))
|
|
953
|
+
if version is None:
|
|
954
|
+
return "manual"
|
|
955
|
+
return "instrumentation" if version >= _NEXT_INSTRUMENTATION_MIN else "manual"
|
|
823
956
|
|
|
824
957
|
|
|
825
958
|
def next_patch_state(workspace: str) -> Dict[str, Any]:
|
|
826
|
-
|
|
827
|
-
|
|
959
|
+
files = _next_files(workspace)
|
|
960
|
+
existing = [path for path, _ in files if os.path.isfile(path)]
|
|
961
|
+
loader = _next_existing_instrumentation(workspace)
|
|
962
|
+
installed = _next_instrumentation_installed(workspace)
|
|
963
|
+
mode = next_bridge_mode(workspace)
|
|
964
|
+
return {
|
|
965
|
+
"entrypoint": existing[0] if existing else None,
|
|
966
|
+
"patched": len(existing) == len(files) and (mode != "instrumentation" or installed),
|
|
967
|
+
"files": [os.path.relpath(path, workspace) for path, _ in files],
|
|
968
|
+
"missing": [os.path.relpath(path, workspace) for path, _ in files if not os.path.isfile(path)],
|
|
969
|
+
"bridge": mode,
|
|
970
|
+
"instrumentation": os.path.relpath(loader, workspace) if loader else None,
|
|
971
|
+
"instrumentation_installed": installed,
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
def _next_route_has_bridge(path: str) -> bool:
|
|
976
|
+
try:
|
|
977
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
978
|
+
return "bridge: true" in handle.read()
|
|
979
|
+
except Exception:
|
|
980
|
+
return False
|
|
828
981
|
|
|
829
982
|
|
|
830
983
|
def apply_next_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
984
|
+
files = _next_files(workspace)
|
|
985
|
+
mode = next_bridge_mode(workspace)
|
|
986
|
+
entrypoint = os.path.relpath(files[0][0], workspace)
|
|
987
|
+
actions: List[Dict[str, str]] = []
|
|
988
|
+
owned: List[str] = []
|
|
989
|
+
|
|
990
|
+
for path, source in files:
|
|
991
|
+
rel = os.path.relpath(path, workspace)
|
|
992
|
+
if os.path.isfile(path):
|
|
993
|
+
if path == files[0][0] and not _next_route_has_bridge(path):
|
|
994
|
+
try:
|
|
995
|
+
current = open(path, "r", encoding="utf-8").read()
|
|
996
|
+
except Exception:
|
|
997
|
+
current = ""
|
|
998
|
+
if current != _NEXT_LEGACY_ROUTE_SOURCE:
|
|
999
|
+
return {
|
|
1000
|
+
"status": "skipped",
|
|
1001
|
+
"reason": f"{rel} exists without bridge: true — add it by hand or run `tokensafe inject --revert` first",
|
|
1002
|
+
"entrypoint": rel,
|
|
1003
|
+
}
|
|
1004
|
+
actions.append({"path": rel, "action": "upgrade"})
|
|
1005
|
+
owned.append(path)
|
|
1006
|
+
else:
|
|
1007
|
+
actions.append({"path": rel, "action": "keep"})
|
|
1008
|
+
continue
|
|
1009
|
+
actions.append({"path": rel, "action": "create"})
|
|
1010
|
+
owned.append(path)
|
|
1011
|
+
|
|
834
1012
|
if dry_run:
|
|
835
|
-
return {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
1013
|
+
return {
|
|
1014
|
+
"status": "dry_run",
|
|
1015
|
+
"entrypoint": entrypoint,
|
|
1016
|
+
"bridge": mode,
|
|
1017
|
+
"files": actions,
|
|
1018
|
+
"would_create": [os.path.relpath(path, workspace) for path in owned],
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
created: List[str] = []
|
|
1022
|
+
for path, source in files:
|
|
1023
|
+
if os.path.isfile(path) and path not in owned:
|
|
1024
|
+
continue
|
|
1025
|
+
parent = os.path.dirname(path)
|
|
1026
|
+
if parent:
|
|
1027
|
+
os.makedirs(parent, exist_ok=True)
|
|
1028
|
+
with open(path, "w", encoding="utf-8") as handle:
|
|
1029
|
+
handle.write(source)
|
|
1030
|
+
if path not in created:
|
|
1031
|
+
created.append(path)
|
|
1032
|
+
|
|
1033
|
+
_write_manifest(workspace, "next", {
|
|
1034
|
+
"entrypoint": files[0][0],
|
|
1035
|
+
"framework": "nextjs",
|
|
1036
|
+
"mode": "next_route_v2",
|
|
1037
|
+
"bridge": mode,
|
|
1038
|
+
"files": [path for path, _ in files],
|
|
1039
|
+
"owned": owned or [path for path, _ in files],
|
|
1040
|
+
"created": created,
|
|
1041
|
+
})
|
|
1042
|
+
result: Dict[str, Any] = {
|
|
1043
|
+
"status": "patched" if created else "already_patched",
|
|
1044
|
+
"entrypoint": entrypoint,
|
|
1045
|
+
"bridge": mode,
|
|
1046
|
+
"files": actions,
|
|
1047
|
+
"created": [os.path.relpath(path, workspace) for path in created],
|
|
1048
|
+
}
|
|
1049
|
+
if mode == "manual":
|
|
1050
|
+
result["bridge_manual"] = {
|
|
1051
|
+
"reason": "instrumentation-client requires Next >= 15.3; load the bridge by hand in this app",
|
|
1052
|
+
"snippet": "import { installNextBridge } from 'tokensafe-backend-node/next-bridge';\ninstallNextBridge();",
|
|
1053
|
+
}
|
|
1054
|
+
else:
|
|
1055
|
+
loader = _next_existing_instrumentation(workspace)
|
|
1056
|
+
own_paths = {path for path, _ in files}
|
|
1057
|
+
if loader and loader not in own_paths and not _next_instrumentation_installed(workspace):
|
|
1058
|
+
result["bridge_manual"] = {
|
|
1059
|
+
"reason": f"{os.path.relpath(loader, workspace)} already exists — add the installer call to it instead of letting the engine shadow it",
|
|
1060
|
+
"snippet": "import { installNextBridge } from 'tokensafe-backend-node/next-bridge';\ninstallNextBridge();",
|
|
1061
|
+
}
|
|
1062
|
+
return result
|
|
841
1063
|
|
|
842
1064
|
|
|
843
1065
|
def revert_next_patch(workspace: str) -> Dict[str, Any]:
|
|
844
|
-
manifest = _read_manifest(workspace, "next", ("next_route",))
|
|
1066
|
+
manifest = _read_manifest(workspace, "next", ("next_route", "next_route_v2"))
|
|
845
1067
|
if not manifest:
|
|
846
1068
|
return {"status": "nothing-to-revert"}
|
|
847
|
-
|
|
848
|
-
if
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1069
|
+
candidates = manifest.get("owned") or manifest.get("created") or []
|
|
1070
|
+
if not candidates and manifest.get("entrypoint"):
|
|
1071
|
+
candidates = [manifest["entrypoint"]]
|
|
1072
|
+
removed: List[str] = []
|
|
1073
|
+
for path in candidates:
|
|
1074
|
+
if path and os.path.isfile(path):
|
|
1075
|
+
os.remove(path)
|
|
1076
|
+
removed.append(path)
|
|
1077
|
+
# Remove only directories this adapter emptied, never a non-empty parent.
|
|
1078
|
+
for directory in sorted({os.path.dirname(path) for path in removed}, key=len, reverse=True):
|
|
1079
|
+
while os.path.abspath(directory) != os.path.abspath(workspace) and os.path.isdir(directory):
|
|
1080
|
+
try:
|
|
1081
|
+
os.rmdir(directory)
|
|
1082
|
+
except OSError:
|
|
1083
|
+
break
|
|
1084
|
+
directory = os.path.dirname(directory)
|
|
855
1085
|
_delete_manifest(manifest)
|
|
856
|
-
return {
|
|
1086
|
+
return {
|
|
1087
|
+
"status": "reverted",
|
|
1088
|
+
"entrypoint": manifest.get("entrypoint"),
|
|
1089
|
+
"removed": [os.path.relpath(path, workspace) for path in removed],
|
|
1090
|
+
}
|
|
857
1091
|
|
|
858
1092
|
|
|
859
1093
|
def detect_orm(workspace: str) -> Dict[str, Any]:
|
|
@@ -1278,10 +1512,22 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
1278
1512
|
"writes_repo": True,
|
|
1279
1513
|
"already_patched": next_state["patched"],
|
|
1280
1514
|
"entrypoint": next_state["entrypoint"] or next_route_path(workspace),
|
|
1281
|
-
"
|
|
1515
|
+
"files": next_state["files"],
|
|
1516
|
+
"missing": next_state["missing"],
|
|
1517
|
+
"bridge": next_state["bridge"],
|
|
1518
|
+
"description": (
|
|
1519
|
+
"three App Router files: api/tokensafe/route.ts (createNextRouteHandlers with bridge: true), "
|
|
1520
|
+
"api/tokensafe/bridge/route.ts (the browser bridge) and instrumentation-client.ts "
|
|
1521
|
+
"(installNextBridge). Server profile plus client components; delete them or --revert to unmount"
|
|
1522
|
+
),
|
|
1282
1523
|
"install": "npm install --save-dev tokensafe-backend-node",
|
|
1283
1524
|
"run": "next dev",
|
|
1284
1525
|
})
|
|
1526
|
+
if next_state["bridge"] == "manual":
|
|
1527
|
+
actions[-1]["bridge_manual"] = {
|
|
1528
|
+
"reason": "instrumentation-client requires Next >= 15.3; the route files are written, the client loader is not",
|
|
1529
|
+
"snippet": "import { installNextBridge } from 'tokensafe-backend-node/next-bridge';\ninstallNextBridge();",
|
|
1530
|
+
}
|
|
1285
1531
|
|
|
1286
1532
|
backend = stack.get("backend")
|
|
1287
1533
|
if backend:
|
package/src/mcp_server.py
CHANGED
package/src/oumv_gateway.py
CHANGED
|
@@ -276,6 +276,9 @@ class OUMVGateway:
|
|
|
276
276
|
"healthy": True,
|
|
277
277
|
"source": "descriptor",
|
|
278
278
|
"capabilities": be_info.get("capabilities", {}),
|
|
279
|
+
# Spec §7.4: the descriptor names its browser bridge, so
|
|
280
|
+
# discovery knows client components are reachable.
|
|
281
|
+
**({"bridge": be_info.get("frontend")} if be_info.get("frontend") else {}),
|
|
279
282
|
}
|
|
280
283
|
except Exception:
|
|
281
284
|
pass
|
|
@@ -301,6 +304,17 @@ class OUMVGateway:
|
|
|
301
304
|
# no writing method at all, so the answer is -32601 and this flag
|
|
302
305
|
# is the authoritative "do not edit behind its back" signal.
|
|
303
306
|
"readOnly": bool(res.get("capabilities", {}).get("readOnly")),
|
|
307
|
+
# Spec §7.4 (revision v1.12): a browser bridge turns the
|
|
308
|
+
# server runtime into one that can see client components
|
|
309
|
+
# and dispatch DOM actions — surface both claims.
|
|
310
|
+
"bridge": {
|
|
311
|
+
"ephemeralDispatch": bool(
|
|
312
|
+
res.get("capabilities", {}).get("mutate", {}).get("ephemeralDispatch")
|
|
313
|
+
),
|
|
314
|
+
"surfaceDiff": bool(
|
|
315
|
+
res.get("capabilities", {}).get("verify", {}).get("surfaceDiff")
|
|
316
|
+
),
|
|
317
|
+
},
|
|
304
318
|
},
|
|
305
319
|
}
|
|
306
320
|
except Exception:
|
package/src/retrofit.py
CHANGED
|
@@ -51,9 +51,9 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
|
|
|
51
51
|
|
|
52
52
|
has_vite = "vite" in deps
|
|
53
53
|
if "next" in deps:
|
|
54
|
-
# The App Router is served by the Node runtime as a Route Handler
|
|
55
|
-
#
|
|
56
|
-
#
|
|
54
|
+
# The App Router is served by the Node runtime as a Route Handler; with
|
|
55
|
+
# the browser bridge (spec §7.4) the same adapter also covers client
|
|
56
|
+
# components through instrumentation-client.
|
|
57
57
|
fe_info.update({
|
|
58
58
|
"framework": "nextjs",
|
|
59
59
|
"provider": "node",
|
|
@@ -62,7 +62,7 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
|
|
|
62
62
|
"version": deps.get("next"),
|
|
63
63
|
"oumv_supported": True,
|
|
64
64
|
"status": "ready",
|
|
65
|
-
"note": "App Router Route Handler
|
|
65
|
+
"note": "App Router Route Handler plus the client-component browser bridge (instrumentation-client on Next >= 15.3); without a page, DOM targets answer -32008",
|
|
66
66
|
})
|
|
67
67
|
elif "react" in deps:
|
|
68
68
|
fe_info.update({"framework": "react", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("react"), "oumv_supported": has_vite, "status": "ready" if has_vite else "needs-vite"})
|
|
@@ -711,13 +711,13 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
711
711
|
},
|
|
712
712
|
{
|
|
713
713
|
"id": "backend/next",
|
|
714
|
-
"name": "Next.js App Router Adapter (Route Handler
|
|
714
|
+
"name": "Next.js App Router Adapter (Route Handler + browser bridge)",
|
|
715
715
|
"profile": "backend",
|
|
716
716
|
"profiles": ["backend"],
|
|
717
717
|
"repo": "tokensafe-backend/node",
|
|
718
718
|
"mode": "hybrid",
|
|
719
719
|
"status": "ready",
|
|
720
|
-
"description": "App Router Route Handler (app/api/tokensafe/route.ts) serving JSON-RPC + SSE over the Node runtime
|
|
720
|
+
"description": "App Router Route Handler (app/api/tokensafe/route.ts) serving JSON-RPC + SSE over the Node runtime, plus the spec §7.4 browser bridge: api/tokensafe/bridge/route.ts and instrumentation-client.ts register the live page, so observe L0-L2/L4 read client components and verify dispatches DOM actions with surfaceDiff. Route surface read from app/**/route.{ts,tsx,js,jsx}; server verify dispatched through an adopter-supplied Web handler (certified Level 3, fixtures v15)",
|
|
721
721
|
"technology": {
|
|
722
722
|
"language": "typescript",
|
|
723
723
|
"framework": "next (app router)",
|
|
@@ -725,12 +725,16 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
725
725
|
},
|
|
726
726
|
"capabilities": [
|
|
727
727
|
{"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
728
|
-
{"name": "observe.surface", "constraints": {"readOnly": True, "developmentOnly": True, "note": "app/**/route.* scan"}},
|
|
728
|
+
{"name": "observe.surface", "constraints": {"readOnly": True, "developmentOnly": True, "note": "app/**/route.* scan; with a page attached L1 also lists the interactive surface"}},
|
|
729
|
+
{"name": "observe.contract", "constraints": {"readOnly": True, "developmentOnly": True, "note": "L2 components come from the attached page's snapshot"}},
|
|
729
730
|
{"name": "observe.source", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
730
|
-
{"name": "observe.traces", "constraints": {"readOnly": True, "developmentOnly": True, "note": "
|
|
731
|
+
{"name": "observe.traces", "constraints": {"readOnly": True, "developmentOnly": True, "note": "server traces require verifyFetch wiring; with the bridge, L4 also carries browser traces"}},
|
|
731
732
|
{"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
733
|
+
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
732
734
|
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": True, "requiresPermission": "permissions.mutate != false"}},
|
|
733
|
-
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True, "note": "requires verifyFetch wiring"}},
|
|
735
|
+
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True, "note": "requires verifyFetch wiring for request targets"}},
|
|
736
|
+
{"name": "verify.surfaceDiff", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["emitted only when the verify ran against the attached page"]}},
|
|
737
|
+
{"name": "mutate.ephemeralDispatch", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["requires the bridge route + instrumentation-client (Next >= 15.3)", "dispatch writes no files and consumes no OCC token"]}},
|
|
734
738
|
],
|
|
735
739
|
},
|
|
736
740
|
{
|
package/src/telemetry_sync.py
CHANGED
|
@@ -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.
|
|
314
|
+
"User-Agent": "TokenSafe-Sync/4.7.21"
|
|
315
315
|
}
|
|
316
316
|
if active_key:
|
|
317
317
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/version_checker.py
CHANGED
|
@@ -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.
|
|
20
|
+
CURRENT_VERSION = "4.7.21"
|
|
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
|