tokensafe 4.7.6 → 4.7.8

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.
@@ -635,8 +635,10 @@ class OUMVGateway:
635
635
  report["backendError"] = str(e)
636
636
  return report
637
637
 
638
- # Cross-layer causality query
639
- if query == "causality" and runtime in ("auto", ""):
638
+ # Cross-layer causality query. Handled for every runtime value: with an
639
+ # explicit runtime this used to skip the static backbone entirely, and
640
+ # offline it fell through to the generic slice below.
641
+ if query == "causality":
640
642
  report = {
641
643
  "query": "causality",
642
644
  "target": target,
@@ -665,13 +667,34 @@ class OUMVGateway:
665
667
 
666
668
  return report
667
669
 
670
+ # Static L2 flow (offline contract): handler -> callees -> literal route.
671
+ if query == "flow":
672
+ report = graph.get_static_flow(target or "")
673
+ report.setdefault("query", "flow")
674
+ return report
675
+
668
676
  try:
677
+ # A live adapter may accept queries beyond the offline contract.
669
678
  url = cls._resolve_client_url(runtime=runtime, target=target, workspace_dir=workspace_dir)
670
679
  return cls._rpc_call(url, "oumv/understand", {"query": query, "target": target, "componentId": target})
671
680
  except RuntimeError:
672
- if query == "impact":
673
- return graph.get_static_impact(target or "")
674
- return graph.get_static_oumv_slice(level="L1", target=target)
681
+ # Prose in `query` is not a question: the offline contract answers
682
+ # impact/causality/flow only. Returning a surface dump here looked like
683
+ # an answer (level "L1", confidence "confirmed") to a query nobody parsed.
684
+ return {
685
+ "query": query,
686
+ "target": target,
687
+ "error": "UNSUPPORTED_QUERY",
688
+ "mode": "STATIC_SURFACE",
689
+ "supportedQueries": ["impact", "causality", "flow"],
690
+ "hint": (
691
+ "query is an enum, not text: 'impact' answers who depends on the target, "
692
+ "'causality' answers why state X / how frontend calls map to endpoints, "
693
+ "'flow' answers which client routes a handler reaches (L2). "
694
+ "For 'what this handler does', read the symbol with smart_read_file."
695
+ ),
696
+ "evidence": {"provenance": "static", "confidence": "confirmed", "sourceAdapter": "tokensafe-graph-engine"},
697
+ }
675
698
 
676
699
  @staticmethod
677
700
  def _static_cross_stack(graph: Any, target: Optional[str]) -> Dict[str, Any]:
@@ -801,7 +824,7 @@ class OUMVGateway:
801
824
 
802
825
  # 5. Tool: oumv_verify
803
826
  @classmethod
804
- def verify(cls, target: str, action: str = "invoke", payload: Optional[dict] = None, runtime: str = "auto", workspace_dir: Optional[str] = None) -> Any:
827
+ def verify(cls, target: str, action: str = "invoke", payload: Optional[dict] = None, runtime: str = "auto", workspace_dir: Optional[str] = None, sandbox: Optional[dict] = None) -> Any:
805
828
  cls.mark_oumv_used(workspace_dir)
806
829
  if runtime == "backend":
807
830
  _, be = cls.get_endpoints(workspace_dir=workspace_dir)
@@ -810,12 +833,17 @@ class OUMVGateway:
810
833
  if notice:
811
834
  return {"status": "unsupported", **notice}
812
835
  url = cls._resolve_client_url(runtime=runtime, target=target, workspace_dir=workspace_dir)
813
- res = cls._rpc_call(url, "oumv/verify", {
836
+ params = {
814
837
  "target": target,
815
838
  "componentId": target,
816
839
  "action": action,
817
840
  "payload": payload or {},
818
- })
841
+ }
842
+ # spec §4 (wire 1.4.0): the runtime decides whether it can honour the
843
+ # sandbox; we forward the request instead of guessing.
844
+ if isinstance(sandbox, dict) and sandbox.get("mode"):
845
+ params["sandbox"] = sandbox
846
+ res = cls._rpc_call(url, "oumv/verify", params)
819
847
  # Honest verification scope (spec §13): state exactly what was verified.
820
848
  if isinstance(res, dict):
821
849
  scope = res.setdefault("scope", {})
package/src/retrofit.py CHANGED
@@ -47,16 +47,18 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
47
47
  "root": rel_dir,
48
48
  }
49
49
 
50
+ has_vite = "vite" in deps
50
51
  if "next" in deps:
51
- fe_info.update({"framework": "nextjs", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("next"), "oumv_supported": True, "status": "ready"})
52
+ # Next has no Vite dev server; the zero-footprint plugin cannot mount there.
53
+ fe_info.update({"framework": "nextjs", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("next"), "oumv_supported": False, "status": "needs-vite"})
52
54
  elif "react" in deps:
53
- fe_info.update({"framework": "react", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("react"), "oumv_supported": True, "status": "ready"})
55
+ 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"})
54
56
  elif "vue" in deps:
55
- fe_info.update({"framework": "vue", "provider": "vue", "adapter": "tokensafe-ui/oumv/vue", "version": deps.get("vue"), "oumv_supported": True, "status": "ready"})
57
+ fe_info.update({"framework": "vue", "provider": "vue", "adapter": "tokensafe-ui/oumv/vue", "version": deps.get("vue"), "oumv_supported": has_vite, "status": "ready" if has_vite else "needs-vite"})
56
58
  elif "solid-js" in deps or "@tokensafe-ui/core" in deps:
57
- fe_info.update({"framework": "solid", "provider": "solid", "adapter": "tokensafe-ui/core", "version": deps.get("solid-js") or deps.get("@tokensafe-ui/core"), "oumv_supported": True, "status": "ready"})
59
+ fe_info.update({"framework": "solid", "provider": "solid", "adapter": "tokensafe-ui/core", "version": deps.get("solid-js") or deps.get("@tokensafe-ui/core"), "oumv_supported": False, "status": "planned"})
58
60
  elif "svelte" in deps:
59
- fe_info.update({"framework": "svelte", "provider": "svelte", "adapter": "tokensafe-ui/core", "version": deps.get("svelte"), "oumv_supported": True, "status": "ready"})
61
+ fe_info.update({"framework": "svelte", "provider": "svelte", "adapter": "tokensafe-ui/core", "version": deps.get("svelte"), "oumv_supported": False, "status": "planned"})
60
62
 
61
63
  if "framework" in fe_info:
62
64
  fe_out = fe_info
@@ -81,8 +83,10 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
81
83
  "adapter": "tokensafe-backend/node",
82
84
  "language": "node",
83
85
  "root": rel_dir,
84
- "oumv_supported": False,
85
- "status": "planned",
86
+ # Express/Fastify ship a certified adapter (npm tokensafe-backend-node);
87
+ # Nest/Hono/Koa do not yet.
88
+ "oumv_supported": node_fw in ("express", "fastify"),
89
+ "status": "ready" if node_fw in ("express", "fastify") else "planned",
86
90
  }
87
91
 
88
92
  if isinstance(pkg_data.get("workspaces"), (list, dict)):
@@ -244,7 +248,7 @@ def detect_project_stack(workspace_dir: str) -> Dict[str, Any]:
244
248
  framework = "flask"
245
249
  elif "starlette" in c:
246
250
  framework = "starlette"
247
- supported = framework in ("fastapi", "starlette")
251
+ supported = framework in ("fastapi",)
248
252
  py_entry = {
249
253
  "framework": framework,
250
254
  "provider": "fastapi" if framework == "fastapi" else "python",
@@ -271,6 +275,77 @@ def detect_project_stack(workspace_dir: str) -> Dict[str, Any]:
271
275
  pass
272
276
  break
273
277
 
278
+ # Spring (JDK-only sidecar) and PHP (Laravel/Symfony sidecar) detection.
279
+ # Both are source-level adapters: nothing is written into the project.
280
+ for java_manifest in ("pom.xml", "build.gradle", "build.gradle.kts"):
281
+ java_path = os.path.join(target_dir, java_manifest)
282
+ if not os.path.isfile(java_path):
283
+ continue
284
+ try:
285
+ with open(java_path, "r", encoding="utf-8", errors="replace") as f:
286
+ java_content = f.read().lower()
287
+ except Exception:
288
+ continue
289
+ if "spring-boot" in java_content or "org.springframework" in java_content:
290
+ _add_detected(os.path.relpath(java_path, workspace_dir))
291
+ sidecar = {
292
+ "framework": "spring",
293
+ "provider": "spring",
294
+ "adapter": "tokensafe-backend/java",
295
+ "language": "java",
296
+ "root": os.path.dirname(os.path.relpath(java_path, workspace_dir)) or ".",
297
+ "oumv_supported": True,
298
+ "status": "ready",
299
+ }
300
+ if not stack["backend"] or not stack["backend"].get("oumv_supported", False):
301
+ stack["backend"] = sidecar
302
+ _add_package({
303
+ "role": "backend",
304
+ "path": sidecar["root"],
305
+ "framework": "spring",
306
+ "provider": "spring",
307
+ "adapter": "tokensafe-backend/java",
308
+ "oumvSupported": True,
309
+ "status": "ready",
310
+ })
311
+ break
312
+
313
+ composer_path = os.path.join(target_dir, "composer.json")
314
+ if os.path.isfile(composer_path):
315
+ try:
316
+ with open(composer_path, "r", encoding="utf-8") as f:
317
+ composer = json.load(f)
318
+ requires = {**(composer.get("require") or {}), **(composer.get("require-dev") or {})}
319
+ except Exception:
320
+ requires = {}
321
+ php_framework = (
322
+ "laravel"
323
+ if any(str(name).startswith("laravel/") for name in requires)
324
+ else ("symfony" if any(str(name).startswith("symfony/") for name in requires) else None)
325
+ )
326
+ if php_framework:
327
+ _add_detected("composer.json")
328
+ sidecar = {
329
+ "framework": php_framework,
330
+ "provider": "php",
331
+ "adapter": "tokensafe-backend/php",
332
+ "language": "php",
333
+ "root": ".",
334
+ "oumv_supported": True,
335
+ "status": "ready",
336
+ }
337
+ if not stack["backend"] or not stack["backend"].get("oumv_supported", False):
338
+ stack["backend"] = sidecar
339
+ _add_package({
340
+ "role": "backend",
341
+ "path": ".",
342
+ "framework": php_framework,
343
+ "provider": "php",
344
+ "adapter": "tokensafe-backend/php",
345
+ "oumvSupported": True,
346
+ "status": "ready",
347
+ })
348
+
274
349
  _scan_dir(workspace_dir)
275
350
  if os.path.isfile(os.path.join(workspace_dir, "pnpm-workspace.yaml")):
276
351
  _add_detected("pnpm-workspace.yaml")
@@ -424,12 +499,12 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
424
499
  "profiles": ["frontend"],
425
500
  "repo": "tokensafe-ui",
426
501
  "mode": "hybrid",
427
- "status": "planned",
428
- "description": "Programmatic adapter exists (manual component registration); no Vite integration or OUMV certification yet — use static analysis for Vue today",
502
+ "status": "ready",
503
+ "description": "Vue 3 runtime adapter: tokensafe-ui() mounts /__oumv/rpc in the Vite dev server without touching the repo, reads the app instance through the bridge and is certified Level 3 in a real browser (agent-dom/certification/vue-vite-browser.json)",
429
504
  "technology": {
430
505
  "language": "typescript",
431
506
  "framework": "vue",
432
- "package": {"manager": "npm", "name": "tokensafe-ui", "install": "npm install tokensafe-ui"},
507
+ "package": {"manager": "npm", "name": "tokensafe-ui", "install": "npm install -D tokensafe-ui"},
433
508
  },
434
509
  "capabilities": [
435
510
  {"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
@@ -445,7 +520,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
445
520
  "repo": "tokensafe-backend/go",
446
521
  "mode": "hybrid",
447
522
  "status": "ready",
448
- "description": "Go AST pre-flight compiler guard + transactional DB sandbox with rollback",
523
+ "description": "Go AST pre-flight compiler guard + optional database/sql sandbox: verify.sandboxRollback runs the request in one transaction and rolls it back (opt-in via SetDBSandbox)",
449
524
  "technology": {
450
525
  "language": "go",
451
526
  "framework": "gin/chi/net-http",
@@ -471,7 +546,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
471
546
  "repo": "tokensafe-backend/python",
472
547
  "mode": "hybrid",
473
548
  "status": "ready",
474
- "description": "FastAPI automatic route & schema introspection + SQLAlchemy dry-run sandbox",
549
+ "description": "FastAPI automatic route & schema introspection + SQLAlchemy sandbox: verify.sandboxRollback needs a SQLAlchemy engine and an app that honours X-TokenSafe-Dry-Run; otherwise the result says not_applicable/unverified",
475
550
  "technology": {
476
551
  "language": "python",
477
552
  "framework": "fastapi",
@@ -510,6 +585,57 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
510
585
  {"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
511
586
  ],
512
587
  },
588
+ {
589
+ "id": "backend/spring",
590
+ "name": "Spring Boot Adapter (JDK-only sidecar)",
591
+ "profile": "backend",
592
+ "profiles": ["backend"],
593
+ "repo": "tokensafe-backend/java",
594
+ "mode": "sidecar",
595
+ "status": "ready",
596
+ "description": "Single-file JDK sidecar: scans @RestController mappings statically, serves HTTP and stdio, applies OCC edits and runs a real verify command. Certified Level 2 32/33 (no live request traces, L4 not advertised).",
597
+ "technology": {
598
+ "language": "java",
599
+ "framework": "spring",
600
+ "package": {
601
+ "manager": "binary",
602
+ "name": "OumvSpring.java",
603
+ "install": "tokensafe inject apply (caches the sidecar in ~/.tokensafe/sidecars)",
604
+ },
605
+ },
606
+ "capabilities": [
607
+ {"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
608
+ {"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": False}},
609
+ {"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": False}},
610
+ {"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
611
+ {"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
612
+ ],
613
+ },
614
+ {
615
+ "id": "backend/php",
616
+ "name": "Laravel / Symfony Adapter (PHP sidecar)",
617
+ "profile": "backend",
618
+ "profiles": ["backend"],
619
+ "repo": "tokensafe-backend/php",
620
+ "mode": "sidecar",
621
+ "status": "ready",
622
+ "description": "Dependency-free PHP sidecar: Laravel Route:: and Symfony #[Route] discovery, token_get_all handler ranges, php -l pre-flight, OCC edits and stdio. Certified Level 2 32/33 (no live traces).",
623
+ "technology": {
624
+ "language": "php",
625
+ "framework": "laravel | symfony",
626
+ "package": {
627
+ "manager": "binary",
628
+ "name": "oumv-php",
629
+ "install": "tokensafe inject apply (caches the sidecar in ~/.tokensafe/sidecars)",
630
+ },
631
+ },
632
+ "capabilities": [
633
+ {"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
634
+ {"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": False}},
635
+ {"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
636
+ {"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
637
+ ],
638
+ },
513
639
  ]
514
640
 
515
641
 
@@ -763,7 +889,7 @@ def resolve_zero_footprint_vite_command(
763
889
  host: Optional[str] = None,
764
890
  open_browser: bool = False,
765
891
  ) -> Tuple[List[str], str]:
766
- """Resolves zero-footprint tokensafe-ui Vite+React runner command without editing repo files."""
892
+ """Resolves the zero-footprint tokensafe-ui Vite runner command without editing repo files."""
767
893
  import shutil
768
894
 
769
895
  ws = os.path.abspath(workspace_dir)
@@ -774,6 +900,13 @@ def resolve_zero_footprint_vite_command(
774
900
  cli_flags.append(f"--host={host}")
775
901
  if open_browser:
776
902
  cli_flags.append("--open")
903
+ # `dev` defaults to React; a Vue project must say so explicitly or it gets the
904
+ # React controller and bridge.
905
+ stack = detect_project_stack(ws)
906
+ frontend = stack.get("frontend") or {}
907
+ framework = frontend.get("framework") if isinstance(frontend, dict) else None
908
+ if framework in ("react", "vue"):
909
+ cli_flags.append(f"--framework={framework}")
777
910
 
778
911
  resolved = resolve_tokensafe_ui_cli(ws)
779
912
  if resolved:
@@ -899,7 +1032,12 @@ def is_path_in_supported_oumv_scope(workspace_dir: str, file_path: str, use_cach
899
1032
  if "/" in rel and top in _FRONTEND_SOURCE_DIRS:
900
1033
  return pkg
901
1034
  return None
902
- if role == "backend" and ext in (".go", ".py"):
903
- return pkg
1035
+ if role == "backend":
1036
+ if ext in (".go", ".py"):
1037
+ return pkg
1038
+ # Express/Fastify adapters ship from npm; their sources are in scope.
1039
+ if pkg.get("provider") == "node" and ext in (".js", ".ts", ".mjs", ".cjs", ".jsx", ".tsx"):
1040
+ return pkg
1041
+ return None
904
1042
  return None
905
1043
  return None
@@ -25,9 +25,10 @@ _FRONTEND_LINES = {
25
25
  "before reading files; run `tokensafe dev` if no runtime is live."
26
26
  ),
27
27
  "vue": (
28
- "frontend {provider}/{framework}: no OUMV adapter yet (the Vite plugin serves no "
29
- "OUMV endpoints for Vue). Use tokensafe:repo_map, smart_read_file and scoped_search; "
30
- "verify UI changes with the app's own tests."
28
+ "frontend {provider}/{framework}: OUMV live via `tokensafe dev --framework vue` "
29
+ "(zero repo footprint, L0-L4, OCC edits; certified L3 in a browser). Call "
30
+ "tokensafe:oumv(action='observe', level='L1') before reading files; run "
31
+ "`tokensafe dev --framework vue` if no runtime is live."
31
32
  ),
32
33
  }
33
34
 
@@ -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.6"
314
+ "User-Agent": "TokenSafe-Sync/4.7.8"
315
315
  }
316
316
  if active_key:
317
317
  headers["Authorization"] = f"Bearer {active_key}"
@@ -17,7 +17,7 @@ import urllib.request
17
17
  import urllib.error
18
18
  from typing import Dict, Any, Optional, Tuple
19
19
 
20
- CURRENT_VERSION = "4.7.6"
20
+ CURRENT_VERSION = "4.7.8"
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