tokensafe 4.7.18 → 4.7.20
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/bin/tokensafe.js +40 -17
- 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 +229 -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/bin/tokensafe.js
CHANGED
|
@@ -71,19 +71,40 @@ function venvPythonPath() {
|
|
|
71
71
|
/**
|
|
72
72
|
* Returns the interpreter's own path when it is a usable CPython >= 3.10,
|
|
73
73
|
* optionally requiring importable runtime dependencies. null otherwise.
|
|
74
|
+
*
|
|
75
|
+
* `command` is a name, a path, or an argv prefix for the Windows `py` launcher.
|
|
74
76
|
*/
|
|
75
|
-
function probePython(
|
|
77
|
+
function probePython(command, requireDeps) {
|
|
78
|
+
const argv = Array.isArray(command) ? command : [command];
|
|
76
79
|
const imports = requireDeps ? 'import sys, cryptography' : 'import sys';
|
|
77
80
|
const probe = `${imports}; assert sys.version_info >= (${MIN_PYTHON[0]}, ${MIN_PYTHON[1]}); print(sys.executable)`;
|
|
78
81
|
try {
|
|
79
|
-
const res = spawnSync(
|
|
82
|
+
const res = spawnSync(argv[0], [...argv.slice(1), '-c', probe], { encoding: 'utf-8', stdio: 'pipe', timeout: 20000 });
|
|
80
83
|
if (res.status !== 0) return null;
|
|
81
|
-
return (res.stdout || '').trim() ||
|
|
84
|
+
return (res.stdout || '').trim() || argv[0];
|
|
82
85
|
} catch (_) {
|
|
83
86
|
return null;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Interpreters to try, most specific first.
|
|
92
|
+
*
|
|
93
|
+
* The venv this launcher owns comes first, then the PATH names. On Windows the
|
|
94
|
+
* python.org installer can leave python.exe off PATH while `py` (the launcher)
|
|
95
|
+
* lands in C:\Windows regardless, so `py -3` is probed too: without it a
|
|
96
|
+
* perfectly good CPython is skipped and the 47 MB managed runtime downloads for
|
|
97
|
+
* nothing.
|
|
98
|
+
*/
|
|
99
|
+
function pythonCandidates() {
|
|
100
|
+
const candidates = [];
|
|
101
|
+
const venvPy = venvPythonPath();
|
|
102
|
+
if (fs.existsSync(venvPy)) candidates.push([venvPy]);
|
|
103
|
+
candidates.push(['python3'], ['python']);
|
|
104
|
+
if (process.platform === 'win32') candidates.push(['py', '-3']);
|
|
105
|
+
return candidates;
|
|
106
|
+
}
|
|
107
|
+
|
|
87
108
|
function moduleAvailable(cmd, name) {
|
|
88
109
|
try {
|
|
89
110
|
return spawnSync(cmd, ['-c', `import ${name}`], { stdio: 'pipe', timeout: 20000 }).status === 0;
|
|
@@ -373,12 +394,14 @@ async function findPython(options = {}) {
|
|
|
373
394
|
const { allowProvision = true, requireDeps = true } = options;
|
|
374
395
|
const pinned = (process.env.TOKENSAFE_PYTHON || '').trim();
|
|
375
396
|
if (pinned) {
|
|
376
|
-
|
|
377
|
-
if (
|
|
378
|
-
|
|
397
|
+
const withDeps = probePython(pinned, true);
|
|
398
|
+
if (withDeps) return withDeps;
|
|
399
|
+
const bare = probePython(pinned, false);
|
|
400
|
+
if (requireDeps && bare) {
|
|
401
|
+
const bootstrapped = bootstrapDependencies(bare);
|
|
379
402
|
if (bootstrapped) return bootstrapped;
|
|
380
403
|
}
|
|
381
|
-
if (!requireDeps &&
|
|
404
|
+
if (!requireDeps && bare) return bare;
|
|
382
405
|
fail(`TOKENSAFE_PYTHON=${pinned} is not a usable CPython ${MIN_PYTHON[0]}.${MIN_PYTHON[1]}+ with 'cryptography'.`);
|
|
383
406
|
}
|
|
384
407
|
|
|
@@ -389,28 +412,27 @@ async function findPython(options = {}) {
|
|
|
389
412
|
return allowProvision ? await ensureManagedRuntime() : null;
|
|
390
413
|
}
|
|
391
414
|
|
|
392
|
-
const candidates =
|
|
393
|
-
const venvPy = venvPythonPath();
|
|
394
|
-
if (fs.existsSync(venvPy)) candidates.push(venvPy);
|
|
395
|
-
candidates.push('python3', 'python');
|
|
415
|
+
const candidates = pythonCandidates();
|
|
396
416
|
|
|
397
417
|
if (!requireDeps) {
|
|
398
418
|
// `help` only prints: a bare interpreter is enough, and a dependency
|
|
399
419
|
// bootstrap there would turn a two-line reference into a pip install.
|
|
400
420
|
for (const cmd of candidates) {
|
|
401
|
-
|
|
421
|
+
const resolved = probePython(cmd, false);
|
|
422
|
+
if (resolved) return resolved;
|
|
402
423
|
}
|
|
403
424
|
return allowProvision ? await ensureManagedRuntime() : null;
|
|
404
425
|
}
|
|
405
426
|
|
|
406
427
|
for (const cmd of candidates) {
|
|
407
|
-
|
|
428
|
+
const resolved = probePython(cmd, true);
|
|
429
|
+
if (resolved) return resolved;
|
|
408
430
|
}
|
|
409
431
|
for (const cmd of candidates) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
432
|
+
const resolved = probePython(cmd, false);
|
|
433
|
+
if (!resolved) continue;
|
|
434
|
+
const bootstrapped = bootstrapDependencies(resolved);
|
|
435
|
+
if (bootstrapped) return bootstrapped;
|
|
414
436
|
}
|
|
415
437
|
|
|
416
438
|
return allowProvision ? await ensureManagedRuntime() : null;
|
|
@@ -503,6 +525,7 @@ if (require.main === module) {
|
|
|
503
525
|
loadManifest,
|
|
504
526
|
platformKey,
|
|
505
527
|
probePython,
|
|
528
|
+
pythonCandidates,
|
|
506
529
|
findRuntimePython,
|
|
507
530
|
sha256File,
|
|
508
531
|
installDeps,
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.20",
|
|
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.20",
|
|
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.20",
|
|
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.20",
|
|
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.20",
|
|
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.20",
|
|
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,185 @@ 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_files(workspace: str) -> List[Tuple[str, str]]:
|
|
889
|
+
app_dir, _ = _next_app_dir(workspace)
|
|
890
|
+
files: List[Tuple[str, str]] = [
|
|
891
|
+
(os.path.join(app_dir, *_NEXT_RPC_REL), _NEXT_RPC_SOURCE),
|
|
892
|
+
(os.path.join(app_dir, *_NEXT_BRIDGE_REL), _NEXT_BRIDGE_SOURCE),
|
|
893
|
+
]
|
|
894
|
+
# Next <15.3 never loads instrumentation-client, so writing it would be a file
|
|
895
|
+
# that pretends to work. Those apps get the two route files plus the manual
|
|
896
|
+
# snippet; the bridge itself is unchanged once the loader exists.
|
|
897
|
+
if next_bridge_mode(workspace) == "instrumentation":
|
|
898
|
+
files.append((_next_instrumentation_path(workspace), _NEXT_INSTRUMENTATION_SOURCE))
|
|
899
|
+
return files
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
def _parse_next_version(raw: Any) -> Optional[Tuple[int, int]]:
|
|
903
|
+
text = str(raw or "").strip().lstrip("^~>= v")
|
|
904
|
+
match = re.match(r"(\d+)(?:\.(\d+))?", text)
|
|
905
|
+
if not match:
|
|
906
|
+
return None
|
|
907
|
+
return int(match.group(1)), int(match.group(2) or 0)
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
def next_bridge_mode(workspace: str) -> str:
|
|
911
|
+
"""`instrumentation` when Next >= 15.3 can load the client, else `manual`."""
|
|
912
|
+
package_json = os.path.join(workspace, "package.json")
|
|
913
|
+
try:
|
|
914
|
+
with open(package_json, "r", encoding="utf-8") as handle:
|
|
915
|
+
data = json.load(handle)
|
|
916
|
+
except Exception:
|
|
917
|
+
return "manual"
|
|
918
|
+
deps = {}
|
|
919
|
+
for key in ("dependencies", "devDependencies"):
|
|
920
|
+
deps.update(data.get(key) or {})
|
|
921
|
+
version = _parse_next_version(deps.get("next"))
|
|
922
|
+
if version is None:
|
|
923
|
+
return "manual"
|
|
924
|
+
return "instrumentation" if version >= _NEXT_INSTRUMENTATION_MIN else "manual"
|
|
823
925
|
|
|
824
926
|
|
|
825
927
|
def next_patch_state(workspace: str) -> Dict[str, Any]:
|
|
826
|
-
|
|
827
|
-
|
|
928
|
+
files = _next_files(workspace)
|
|
929
|
+
existing = [path for path, _ in files if os.path.isfile(path)]
|
|
930
|
+
return {
|
|
931
|
+
"entrypoint": existing[0] if existing else None,
|
|
932
|
+
"patched": len(existing) == len(files),
|
|
933
|
+
"files": [os.path.relpath(path, workspace) for path, _ in files],
|
|
934
|
+
"missing": [os.path.relpath(path, workspace) for path, _ in files if not os.path.isfile(path)],
|
|
935
|
+
"bridge": next_bridge_mode(workspace),
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
def _next_route_has_bridge(path: str) -> bool:
|
|
940
|
+
try:
|
|
941
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
942
|
+
return "bridge: true" in handle.read()
|
|
943
|
+
except Exception:
|
|
944
|
+
return False
|
|
828
945
|
|
|
829
946
|
|
|
830
947
|
def apply_next_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
948
|
+
files = _next_files(workspace)
|
|
949
|
+
mode = next_bridge_mode(workspace)
|
|
950
|
+
entrypoint = os.path.relpath(files[0][0], workspace)
|
|
951
|
+
actions: List[Dict[str, str]] = []
|
|
952
|
+
owned: List[str] = []
|
|
953
|
+
|
|
954
|
+
for path, source in files:
|
|
955
|
+
rel = os.path.relpath(path, workspace)
|
|
956
|
+
if os.path.isfile(path):
|
|
957
|
+
if path == files[0][0] and not _next_route_has_bridge(path):
|
|
958
|
+
try:
|
|
959
|
+
current = open(path, "r", encoding="utf-8").read()
|
|
960
|
+
except Exception:
|
|
961
|
+
current = ""
|
|
962
|
+
if current != _NEXT_LEGACY_ROUTE_SOURCE:
|
|
963
|
+
return {
|
|
964
|
+
"status": "skipped",
|
|
965
|
+
"reason": f"{rel} exists without bridge: true — add it by hand or run `tokensafe inject --revert` first",
|
|
966
|
+
"entrypoint": rel,
|
|
967
|
+
}
|
|
968
|
+
actions.append({"path": rel, "action": "upgrade"})
|
|
969
|
+
owned.append(path)
|
|
970
|
+
else:
|
|
971
|
+
actions.append({"path": rel, "action": "keep"})
|
|
972
|
+
continue
|
|
973
|
+
actions.append({"path": rel, "action": "create"})
|
|
974
|
+
owned.append(path)
|
|
975
|
+
|
|
834
976
|
if dry_run:
|
|
835
|
-
return {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
977
|
+
return {
|
|
978
|
+
"status": "dry_run",
|
|
979
|
+
"entrypoint": entrypoint,
|
|
980
|
+
"bridge": mode,
|
|
981
|
+
"files": actions,
|
|
982
|
+
"would_create": [os.path.relpath(path, workspace) for path in owned],
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
created: List[str] = []
|
|
986
|
+
for path, source in files:
|
|
987
|
+
if os.path.isfile(path) and path not in owned:
|
|
988
|
+
continue
|
|
989
|
+
parent = os.path.dirname(path)
|
|
990
|
+
if parent:
|
|
991
|
+
os.makedirs(parent, exist_ok=True)
|
|
992
|
+
with open(path, "w", encoding="utf-8") as handle:
|
|
993
|
+
handle.write(source)
|
|
994
|
+
if path not in created:
|
|
995
|
+
created.append(path)
|
|
996
|
+
|
|
997
|
+
_write_manifest(workspace, "next", {
|
|
998
|
+
"entrypoint": files[0][0],
|
|
999
|
+
"framework": "nextjs",
|
|
1000
|
+
"mode": "next_route_v2",
|
|
1001
|
+
"bridge": mode,
|
|
1002
|
+
"files": [path for path, _ in files],
|
|
1003
|
+
"owned": owned or [path for path, _ in files],
|
|
1004
|
+
"created": created,
|
|
1005
|
+
})
|
|
1006
|
+
result: Dict[str, Any] = {
|
|
1007
|
+
"status": "patched" if created else "already_patched",
|
|
1008
|
+
"entrypoint": entrypoint,
|
|
1009
|
+
"bridge": mode,
|
|
1010
|
+
"files": actions,
|
|
1011
|
+
"created": [os.path.relpath(path, workspace) for path in created],
|
|
1012
|
+
}
|
|
1013
|
+
if mode == "manual":
|
|
1014
|
+
result["bridge_manual"] = {
|
|
1015
|
+
"reason": "instrumentation-client requires Next >= 15.3; load the bridge by hand in this app",
|
|
1016
|
+
"snippet": "import { installNextBridge } from 'tokensafe-backend-node/next-bridge';\ninstallNextBridge();",
|
|
1017
|
+
}
|
|
1018
|
+
return result
|
|
841
1019
|
|
|
842
1020
|
|
|
843
1021
|
def revert_next_patch(workspace: str) -> Dict[str, Any]:
|
|
844
|
-
manifest = _read_manifest(workspace, "next", ("next_route",))
|
|
1022
|
+
manifest = _read_manifest(workspace, "next", ("next_route", "next_route_v2"))
|
|
845
1023
|
if not manifest:
|
|
846
1024
|
return {"status": "nothing-to-revert"}
|
|
847
|
-
|
|
848
|
-
if
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1025
|
+
candidates = manifest.get("owned") or manifest.get("created") or []
|
|
1026
|
+
if not candidates and manifest.get("entrypoint"):
|
|
1027
|
+
candidates = [manifest["entrypoint"]]
|
|
1028
|
+
removed: List[str] = []
|
|
1029
|
+
for path in candidates:
|
|
1030
|
+
if path and os.path.isfile(path):
|
|
1031
|
+
os.remove(path)
|
|
1032
|
+
removed.append(path)
|
|
1033
|
+
# Remove only directories this adapter emptied, never a non-empty parent.
|
|
1034
|
+
for directory in sorted({os.path.dirname(path) for path in removed}, key=len, reverse=True):
|
|
1035
|
+
while os.path.abspath(directory) != os.path.abspath(workspace) and os.path.isdir(directory):
|
|
1036
|
+
try:
|
|
1037
|
+
os.rmdir(directory)
|
|
1038
|
+
except OSError:
|
|
1039
|
+
break
|
|
1040
|
+
directory = os.path.dirname(directory)
|
|
855
1041
|
_delete_manifest(manifest)
|
|
856
|
-
return {
|
|
1042
|
+
return {
|
|
1043
|
+
"status": "reverted",
|
|
1044
|
+
"entrypoint": manifest.get("entrypoint"),
|
|
1045
|
+
"removed": [os.path.relpath(path, workspace) for path in removed],
|
|
1046
|
+
}
|
|
857
1047
|
|
|
858
1048
|
|
|
859
1049
|
def detect_orm(workspace: str) -> Dict[str, Any]:
|
|
@@ -1278,10 +1468,22 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
1278
1468
|
"writes_repo": True,
|
|
1279
1469
|
"already_patched": next_state["patched"],
|
|
1280
1470
|
"entrypoint": next_state["entrypoint"] or next_route_path(workspace),
|
|
1281
|
-
"
|
|
1471
|
+
"files": next_state["files"],
|
|
1472
|
+
"missing": next_state["missing"],
|
|
1473
|
+
"bridge": next_state["bridge"],
|
|
1474
|
+
"description": (
|
|
1475
|
+
"three App Router files: api/tokensafe/route.ts (createNextRouteHandlers with bridge: true), "
|
|
1476
|
+
"api/tokensafe/bridge/route.ts (the browser bridge) and instrumentation-client.ts "
|
|
1477
|
+
"(installNextBridge). Server profile plus client components; delete them or --revert to unmount"
|
|
1478
|
+
),
|
|
1282
1479
|
"install": "npm install --save-dev tokensafe-backend-node",
|
|
1283
1480
|
"run": "next dev",
|
|
1284
1481
|
})
|
|
1482
|
+
if next_state["bridge"] == "manual":
|
|
1483
|
+
actions[-1]["bridge_manual"] = {
|
|
1484
|
+
"reason": "instrumentation-client requires Next >= 15.3; the route files are written, the client loader is not",
|
|
1485
|
+
"snippet": "import { installNextBridge } from 'tokensafe-backend-node/next-bridge';\ninstallNextBridge();",
|
|
1486
|
+
}
|
|
1285
1487
|
|
|
1286
1488
|
backend = stack.get("backend")
|
|
1287
1489
|
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.20"
|
|
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.20"
|
|
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
|