tokensafe 4.7.14 → 4.7.17
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 +4 -2
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +2 -2
- package/src/adapter_core.py +2 -2
- package/src/auto_inject.py +141 -7
- package/src/installer.py +1 -1
- package/src/mcp_server.py +1 -1
- package/src/oumv_gateway.py +44 -6
- package/src/retrofit.py +38 -8
- package/src/session_brief.py +5 -0
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/README.md
CHANGED
|
@@ -215,7 +215,7 @@ Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live
|
|
|
215
215
|
|
|
216
216
|
You install TokenSafe, open a project in your agent, and the first turn does the wiring:
|
|
217
217
|
|
|
218
|
-
1. **Detect** the stack (React/Vue + Vite, FastAPI, Go/Gin|Chi, or nothing supported).
|
|
218
|
+
1. **Detect** the stack (React/Vue + Vite, FastAPI, Go/Gin|Chi, Node/Express|Fastify, Next.js, Elysia on Bun, ASP.NET Core, or nothing supported).
|
|
219
219
|
2. **Activate** the adapters:
|
|
220
220
|
* frontend — `tokensafe dev` serves OUMV from an inline Vite config; **no file in the
|
|
221
221
|
repository changes**;
|
|
@@ -226,7 +226,9 @@ You install TokenSafe, open a project in your agent, and the first turn does the
|
|
|
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
228
|
* Next.js (App Router) — one generated `app/api/tokensafe/route.ts` Route Handler
|
|
229
|
-
(`createNextRouteHandlers`), server profile; `--revert` deletes the file
|
|
229
|
+
(`createNextRouteHandlers`), server profile; `--revert` deletes the file;
|
|
230
|
+
* Elysia (Bun) — one `app.use(oumv())` line before `app.listen()`
|
|
231
|
+
(`tokensafe-backend-node/elysia`), same markers and byte-exact revert.
|
|
230
232
|
3. **Brief the agent** — a short routing block (hook context and MCP `instructions`) says which
|
|
231
233
|
stack is worked through OUMV and which through the TokenSafe tools. Nothing is written into
|
|
232
234
|
the repository by the brief.
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.17",
|
|
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.17",
|
|
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.17",
|
|
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.17",
|
|
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.17",
|
|
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.17",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
|
@@ -113,9 +113,9 @@ TokenSafe actively maximizes provider KV-cache hit rates alongside token compres
|
|
|
113
113
|
TokenSafe integrates the **Universal Agent-Runtime Protocol (UARP / OUMV)** to inspect, reason about, edit, and verify Frontend (`tokensafe-ui`, React 18/19 + Vite, Vue 3) and Backend (`Go` Gin/Chi/net-http, `FastAPI`) services without heavy headless browsers or unconstrained shell curls.
|
|
114
114
|
|
|
115
115
|
### OUMV-First Policy, Zero-Footprint & Mixed Monorepos
|
|
116
|
-
- **Mandatory When Supported (Even Without Dev/Build Running)**: If the workspace contains a supported profile (`frontend/react`, `frontend/vue`, `frontend/solid`, `backend/go`, `backend/fastapi`), prefer `tokensafe:oumv` (`status` -> `observe` L0/L1/L2 -> `understand` impact -> `mutate` -> `verify`) BEFORE brute-force reading components or running `curl`/browsers. Static OUMV works offline even when the agent only reads and edits files.
|
|
116
|
+
- **Mandatory When Supported (Even Without Dev/Build Running)**: If the workspace contains a supported profile (`frontend/react`, `frontend/vue`, `frontend/solid`, `backend/go`, `backend/fastapi`, `backend/node` (Express/Fastify/Next.js), `backend/elysia`, `backend/aspnetcore`), prefer `tokensafe:oumv` (`status` -> `observe` L0/L1/L2 -> `understand` impact -> `mutate` -> `verify`) BEFORE brute-force reading components or running `curl`/browsers. Static OUMV works offline even when the agent only reads and edits files.
|
|
117
117
|
- **Zero-Footprint Vite+React (`tokensafe dev`)**: Running `tokensafe dev` (or `vite` / `npm run dev` rewritten automatically by `CommandSanitizer`) starts the project's Vite+React DevServer with `tokensafeReact()` injected in memory and runtime state stored under `~/.tokensafe/runtimes/<hash>.json` (sidecar L2 contracts in `~/.tokensafe/contracts/<hash>.json`) — leaving **0 modified/untracked files** in the repository.
|
|
118
|
-
- **Monorepo Capability Boundaries**: In mixed monorepos (e.g., `apps/web` in React + `apps/api` in Node.js/Express), check `oumv(action="status")` or `[TokenSafe OUMV Workspace Matrix]`. Use `tokensafe:oumv(runtime="frontend")` for React, and use `repo_map` + `smart_read_file` + `scoped_search` + normal tests for
|
|
118
|
+
- **Monorepo Capability Boundaries**: In mixed monorepos (e.g., `apps/web` in React + `apps/api` in Node.js/Express), check `oumv(action="status")` or `[TokenSafe OUMV Workspace Matrix]`. Use `tokensafe:oumv(runtime="frontend")` for React, and use `repo_map` + `smart_read_file` + `scoped_search` + normal tests for packages `oumv status` marks unsupported (Nest/Hono/Koa, a Bun worker with no HTTP server).
|
|
119
119
|
|
|
120
120
|
1. **LIVE RUNTIME HEALTH (`oumv(action="status")`)**:
|
|
121
121
|
- Call `tokensafe:oumv(action="status")` to inspect connection status and capabilities of running DevServers (Frontend ports 5173/3000, Backend ports 8080/8000).
|
package/src/adapter_core.py
CHANGED
|
@@ -45,7 +45,7 @@ TOKENSAFE_DIRECTIVES = (
|
|
|
45
45
|
"• When context budget reports warning/critical or Grade C/F: call 'tokensafe:session_context(action=\"compact\", transcript_path=...)' to fold history before continuing.\n"
|
|
46
46
|
"• Prohibited File Edits: NEVER use 'sed -i', 'perl -i', or stream editors to modify source files; ALWAYS use 'edit_file' with exact string targets. NEVER suppress errors with '2>/dev/null'.\n"
|
|
47
47
|
"• Prefer 'edit_file' over 'write_file' for existing files.\n"
|
|
48
|
-
"• Universal OUMV Protocol (Mandatory When Supported): If the workspace reports an OUMV-supported stack (React+Vite, Vue, Solid, Go, FastAPI), ALWAYS prefer the 'oumv' MCP tool (status/observe/understand/verify) before full file crawls, raw curl, or browser checks — even when only reading/editing files (static AST OUMV works offline; use 'tokensafe dev' for zero-footprint live Vite+React). Check capability boundaries in mixed monorepos (for unsupported stacks like backend/node Express/Fastify/Nest, use repo_map/smart_read_file/scoped_search).\n"
|
|
48
|
+
"• Universal OUMV Protocol (Mandatory When Supported): If the workspace reports an OUMV-supported stack (React+Vite, Vue, Solid, Go, FastAPI, Express/Fastify, Next.js, Elysia on Bun, ASP.NET Core), ALWAYS prefer the 'oumv' MCP tool (status/observe/understand/verify) before full file crawls, raw curl, or browser checks — even when only reading/editing files (static AST OUMV works offline; use 'tokensafe dev' for zero-footprint live Vite+React). Check capability boundaries in mixed monorepos (for unsupported stacks like backend/node Express/Fastify/Nest, use repo_map/smart_read_file/scoped_search).\n"
|
|
49
49
|
"• Multi-Root Sessions: the OUMV routing brief is classified PER workspace root (hosts that report several folders get every root listed). A single-root verdict never describes another repo — before editing a repo outside the listed roots, call 'oumv' with workspace_dir='<that repo>'; never conclude 'OUMV is unavailable' from one root's line."
|
|
50
50
|
)
|
|
51
51
|
|
|
@@ -489,7 +489,7 @@ def _gc_oumv_markers(data_dir: str) -> None:
|
|
|
489
489
|
|
|
490
490
|
def get_oumv_read_edit_advisory(workspace_dir: str, file_path: str, session_id: str = "") -> Optional[str]:
|
|
491
491
|
"""One-shot per-session advisory when reading/editing files inside an OUMV-supported stack
|
|
492
|
-
(React+Vite, Vue, Solid, Go, FastAPI) without having called `tokensafe:oumv` recently.
|
|
492
|
+
(React+Vite, Vue, Solid, Go, FastAPI, Express/Fastify, Next.js, Elysia on Bun, ASP.NET Core) without having called `tokensafe:oumv` recently.
|
|
493
493
|
|
|
494
494
|
Returns None immediately for unsupported stacks in mixed monorepos (e.g. backend/node),
|
|
495
495
|
when OUMV was already used in this workspace, or if already nudged in this session.
|
package/src/auto_inject.py
CHANGED
|
@@ -121,10 +121,16 @@ _SITECUSTOMIZE = '''"""TokenSafe OUMV autoload (generated) — see `tokensafe in
|
|
|
121
121
|
|
|
122
122
|
Mounts `mount_tokensafe(app)` on a FastAPI app the moment uvicorn resolves it.
|
|
123
123
|
Inert unless TOKENSAFE_OUMV_AUTOMOUNT=1, which `tokensafe run-backend` sets.
|
|
124
|
+
|
|
125
|
+
TOKENSAFE_OUMV_READ_ONLY=1 mounts the spec §8.5 read-only deployment: the writing
|
|
126
|
+
methods are not registered at all, so applyEdit/previewEdit/verify/build answer
|
|
127
|
+
-32601 instead of being refused by a handler.
|
|
124
128
|
"""
|
|
125
129
|
import os
|
|
126
130
|
|
|
127
131
|
if os.environ.get("TOKENSAFE_OUMV_AUTOMOUNT") == "1":
|
|
132
|
+
_READ_ONLY = os.environ.get("TOKENSAFE_OUMV_READ_ONLY") in ("1", "true", "yes", "on")
|
|
133
|
+
|
|
128
134
|
def _install():
|
|
129
135
|
try:
|
|
130
136
|
from tokensafe_python.adapters.fastapi import mount_tokensafe as _mount
|
|
@@ -141,7 +147,7 @@ if os.environ.get("TOKENSAFE_OUMV_AUTOMOUNT") == "1":
|
|
|
141
147
|
def _patched(import_str, *args, **kwargs):
|
|
142
148
|
app = _original(import_str, *args, **kwargs)
|
|
143
149
|
try:
|
|
144
|
-
_mount(app)
|
|
150
|
+
_mount(app, read_only=_READ_ONLY)
|
|
145
151
|
except Exception as exc: # never break the user's server
|
|
146
152
|
import sys
|
|
147
153
|
print(f"[tokensafe] OUMV autoload skipped: {exc}", file=sys.stderr)
|
|
@@ -281,7 +287,7 @@ def go_patch_state(workspace: str) -> Dict[str, Any]:
|
|
|
281
287
|
_GO_MODULE = "github.com/tokensafe-dev/tokensafe-backend/go"
|
|
282
288
|
# Keep in step with the backend release tag (go/vX.Y.Z): injection must never
|
|
283
289
|
# downgrade an adapter that is already newer than this pin.
|
|
284
|
-
_GO_MODULE_VERSION = "v0.
|
|
290
|
+
_GO_MODULE_VERSION = "v0.13.0"
|
|
285
291
|
|
|
286
292
|
|
|
287
293
|
def _version_tuple(tag: str):
|
|
@@ -552,7 +558,7 @@ def revert_go_patch(workspace: str) -> Dict[str, Any]:
|
|
|
552
558
|
# --------------------------------------------------------------------------- #
|
|
553
559
|
|
|
554
560
|
def _find_node_entrypoint(workspace: str) -> Optional[str]:
|
|
555
|
-
"""Finds the Node entry file that creates the framework app."""
|
|
561
|
+
"""Finds the Node/Bun entry file that creates the framework app."""
|
|
556
562
|
candidates: List[str] = []
|
|
557
563
|
pkg_path = os.path.join(workspace, "package.json")
|
|
558
564
|
try:
|
|
@@ -563,7 +569,11 @@ def _find_node_entrypoint(workspace: str) -> Optional[str]:
|
|
|
563
569
|
candidates.append(main)
|
|
564
570
|
except Exception:
|
|
565
571
|
pass
|
|
566
|
-
candidates += [
|
|
572
|
+
candidates += [
|
|
573
|
+
"src/index.js", "src/server.js", "src/app.js", "index.js", "server.js", "app.js",
|
|
574
|
+
# Bun/Elysia projects are TypeScript: `bun --watch src/index.ts` is the default script.
|
|
575
|
+
"src/index.ts", "src/server.ts", "src/app.ts", "index.ts", "server.ts", "app.ts",
|
|
576
|
+
]
|
|
567
577
|
for rel in candidates:
|
|
568
578
|
path = os.path.join(workspace, rel)
|
|
569
579
|
if os.path.isfile(path):
|
|
@@ -578,6 +588,9 @@ def _node_framework_of(workspace: str) -> Optional[str]:
|
|
|
578
588
|
deps = {**(pkg.get("dependencies") or {}), **(pkg.get("devDependencies") or {})}
|
|
579
589
|
except Exception:
|
|
580
590
|
return None
|
|
591
|
+
# Elysia implies Bun; a project that has both should get the Bun mount.
|
|
592
|
+
if "elysia" in deps:
|
|
593
|
+
return "elysia"
|
|
581
594
|
if "fastify" in deps:
|
|
582
595
|
return "fastify"
|
|
583
596
|
if "express" in deps:
|
|
@@ -675,6 +688,111 @@ def revert_node_patch(workspace: str) -> Dict[str, Any]:
|
|
|
675
688
|
return {"status": "reverted", "entrypoint": os.path.relpath(entrypoint, workspace)}
|
|
676
689
|
|
|
677
690
|
|
|
691
|
+
def _elysia_app_reference(source: str) -> Optional[Tuple[str, str, int]]:
|
|
692
|
+
"""(var, indent, insert_at) for the `.use(oumv())` line: before `listen` when present.
|
|
693
|
+
|
|
694
|
+
Elysia apps are usually a `.use(...)` chain ending in `app.listen(...)`. Injecting
|
|
695
|
+
before `listen` keeps the chain intact and runs after every route plugin, so the
|
|
696
|
+
route table `onStart` reads is complete. A file that exports the app without
|
|
697
|
+
listening falls back to the `new Elysia()` assignment.
|
|
698
|
+
"""
|
|
699
|
+
listen = re.search(r"(?m)^(?P<indent>[ \t]*)(?P<var>[A-Za-z_$][\w$]*)\.listen\(", source)
|
|
700
|
+
if listen:
|
|
701
|
+
return listen.group("var"), listen.group("indent"), listen.start()
|
|
702
|
+
created = re.search(
|
|
703
|
+
r"(?m)^(?P<indent>[ \t]*)(?:export\s+)?(?:const|let|var)\s+(?P<var>[A-Za-z_$][\w$]*)"
|
|
704
|
+
r"\s*=\s*new\s+Elysia\([^)]*\)[ \t]*;?[ \t]*$",
|
|
705
|
+
source,
|
|
706
|
+
)
|
|
707
|
+
if not created:
|
|
708
|
+
return None
|
|
709
|
+
line_end = source.find("\n", created.end())
|
|
710
|
+
insert_at = len(source) if line_end < 0 else line_end + 1
|
|
711
|
+
return created.group("var"), created.group("indent"), insert_at
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
def elysia_patch_state(workspace: str) -> Dict[str, Any]:
|
|
715
|
+
path = _find_node_entrypoint(workspace)
|
|
716
|
+
if not path or _node_framework_of(workspace) != "elysia":
|
|
717
|
+
return {"entrypoint": None, "patched": False, "framework": _node_framework_of(workspace)}
|
|
718
|
+
try:
|
|
719
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
720
|
+
source = f.read()
|
|
721
|
+
except OSError:
|
|
722
|
+
source = ""
|
|
723
|
+
return {
|
|
724
|
+
"entrypoint": os.path.relpath(path, workspace),
|
|
725
|
+
"patched": _MARK_BEGIN in source and _MARK_END in source,
|
|
726
|
+
"framework": "elysia",
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
def apply_elysia_patch(workspace: str, dry_run: bool = False) -> Dict[str, Any]:
|
|
731
|
+
"""Adds `app.use(oumv())` to an Elysia app, with a byte-exact backup."""
|
|
732
|
+
if _node_framework_of(workspace) != "elysia":
|
|
733
|
+
return {"status": "skipped", "reason": "no Elysia dependency in package.json"}
|
|
734
|
+
path = _find_node_entrypoint(workspace)
|
|
735
|
+
if not path:
|
|
736
|
+
return {"status": "skipped", "reason": "no Bun entrypoint found"}
|
|
737
|
+
|
|
738
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
739
|
+
source = f.read()
|
|
740
|
+
if _MARK_BEGIN in source:
|
|
741
|
+
return {"status": "already_patched", "entrypoint": os.path.relpath(path, workspace)}
|
|
742
|
+
|
|
743
|
+
ref = _elysia_app_reference(source)
|
|
744
|
+
if not ref:
|
|
745
|
+
return {
|
|
746
|
+
"status": "skipped",
|
|
747
|
+
"reason": f"could not find `new Elysia(...)` or `<app>.listen(...)` in {os.path.relpath(path, workspace)}",
|
|
748
|
+
}
|
|
749
|
+
var, indent, insert_at = ref
|
|
750
|
+
mount = (
|
|
751
|
+
f"{indent}{_MARK_BEGIN}\n"
|
|
752
|
+
f"{indent}const {{ oumv: _oumv }} = require('tokensafe-backend-node/elysia');\n"
|
|
753
|
+
f"{indent}{var}.use(_oumv());\n"
|
|
754
|
+
f"{indent}{_MARK_END}\n"
|
|
755
|
+
)
|
|
756
|
+
patched = source[:insert_at] + mount + source[insert_at:]
|
|
757
|
+
|
|
758
|
+
if dry_run:
|
|
759
|
+
return {
|
|
760
|
+
"status": "dry_run",
|
|
761
|
+
"entrypoint": os.path.relpath(path, workspace),
|
|
762
|
+
"framework": "elysia",
|
|
763
|
+
"preview": f"{var}.use(_oumv());",
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
backup_dir = _inject_dir(workspace)
|
|
767
|
+
os.makedirs(backup_dir, exist_ok=True)
|
|
768
|
+
backup_path = os.path.join(backup_dir, os.path.relpath(path, workspace).replace(os.sep, "__") + ".bak")
|
|
769
|
+
shutil.copy2(path, backup_path)
|
|
770
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
771
|
+
f.write(patched)
|
|
772
|
+
_write_manifest(workspace, "elysia", {"entrypoint": path, "backup": backup_path, "framework": "elysia"})
|
|
773
|
+
return {
|
|
774
|
+
"status": "patched",
|
|
775
|
+
"entrypoint": os.path.relpath(path, workspace),
|
|
776
|
+
"framework": "elysia",
|
|
777
|
+
"mode": "elysia_plugin",
|
|
778
|
+
"backup": backup_path,
|
|
779
|
+
"line": f"{var}.use(_oumv());",
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
def revert_elysia_patch(workspace: str) -> Dict[str, Any]:
|
|
784
|
+
manifest = _read_manifest(workspace, "elysia", ("elysia_plugin",))
|
|
785
|
+
if manifest is None:
|
|
786
|
+
return {"status": "clean", "reason": "no Elysia patch manifest"}
|
|
787
|
+
entrypoint = manifest.get("entrypoint")
|
|
788
|
+
backup = manifest.get("backup")
|
|
789
|
+
if not (entrypoint and backup and os.path.isfile(backup)):
|
|
790
|
+
return {"status": "error", "reason": "backup missing; restore manually"}
|
|
791
|
+
shutil.copy2(backup, entrypoint)
|
|
792
|
+
_delete_manifest(manifest)
|
|
793
|
+
return {"status": "reverted", "entrypoint": os.path.relpath(entrypoint, workspace)}
|
|
794
|
+
|
|
795
|
+
|
|
678
796
|
|
|
679
797
|
# Next.js App Router: the adapter is a Route Handler created by the npm package.
|
|
680
798
|
# Nothing is patched inside app components — one generated file mounts the
|
|
@@ -1018,17 +1136,17 @@ def revert_dotnet_patch(workspace: str) -> Dict[str, Any]:
|
|
|
1018
1136
|
# Pinned to the backend release: the sidecars are single files, so the cache is
|
|
1019
1137
|
# content-addressed by SHA-256 and a clean machine downloads the exact bytes the
|
|
1020
1138
|
# release was certified from. Bump both the tag and the hashes together.
|
|
1021
|
-
_SIDECAR_RELEASE_TAG = "v0.
|
|
1139
|
+
_SIDECAR_RELEASE_TAG = "v0.13.0"
|
|
1022
1140
|
_SIDECARS = {
|
|
1023
1141
|
"spring": (
|
|
1024
1142
|
"java/src/dev/tokensafe/oumv/OumvSpring.java",
|
|
1025
1143
|
"OumvSpring.java",
|
|
1026
|
-
"
|
|
1144
|
+
"a4defc121be23ce2266a1f7f8cfd361d5b5b1fe7ea85f818e5f322322ab2642e",
|
|
1027
1145
|
),
|
|
1028
1146
|
"php": (
|
|
1029
1147
|
"php/bin/oumv-php",
|
|
1030
1148
|
"oumv-php",
|
|
1031
|
-
"
|
|
1149
|
+
"3369ee5fd03ec9b16b7eaebc33cc003033cadcb1d325b3445661eba058405b5f",
|
|
1032
1150
|
),
|
|
1033
1151
|
}
|
|
1034
1152
|
|
|
@@ -1163,6 +1281,7 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
1163
1281
|
"fastapi": "backend/fastapi",
|
|
1164
1282
|
"go": "backend/go",
|
|
1165
1283
|
"node": "backend/node",
|
|
1284
|
+
"elysia": "backend/elysia",
|
|
1166
1285
|
"spring": "backend/spring",
|
|
1167
1286
|
"php": "backend/php",
|
|
1168
1287
|
"dotnet": "backend/aspnetcore",
|
|
@@ -1191,6 +1310,18 @@ def plan(workspace: str) -> Dict[str, Any]:
|
|
|
1191
1310
|
"description": "one AutoMount() line between tokensafe markers; byte-exact backup + --revert",
|
|
1192
1311
|
"install": install,
|
|
1193
1312
|
})
|
|
1313
|
+
elif provider == "elysia":
|
|
1314
|
+
state = elysia_patch_state(workspace)
|
|
1315
|
+
actions.append({
|
|
1316
|
+
"kind": "elysia_plugin_patch",
|
|
1317
|
+
"profile": "backend",
|
|
1318
|
+
"framework": "elysia",
|
|
1319
|
+
"writes_repo": True,
|
|
1320
|
+
"already_patched": state["patched"],
|
|
1321
|
+
"entrypoint": state["entrypoint"],
|
|
1322
|
+
"description": "one app.use(oumv()) line before app.listen() between tokensafe markers; byte-exact backup + --revert",
|
|
1323
|
+
"install": install or "bun add tokensafe-backend-node",
|
|
1324
|
+
})
|
|
1194
1325
|
elif provider == "node":
|
|
1195
1326
|
state = node_patch_state(workspace)
|
|
1196
1327
|
actions.append({
|
|
@@ -1286,6 +1417,8 @@ def apply(workspace: str, dry_run: bool = False, include_go: bool = True) -> Dic
|
|
|
1286
1417
|
|
|
1287
1418
|
if backend.get("provider") == "go" and include_go:
|
|
1288
1419
|
results["actions"].append({"kind": "go_one_line_patch", **apply_go_patch(workspace, dry_run=dry_run)})
|
|
1420
|
+
elif backend.get("provider") == "elysia":
|
|
1421
|
+
results["actions"].append({"kind": "elysia_plugin_patch", **apply_elysia_patch(workspace, dry_run=dry_run)})
|
|
1289
1422
|
elif backend.get("provider") == "node":
|
|
1290
1423
|
results["actions"].append({"kind": "node_one_line_patch", **apply_node_patch(workspace, dry_run=dry_run)})
|
|
1291
1424
|
elif backend.get("provider") == "dotnet":
|
|
@@ -1308,6 +1441,7 @@ def revert(workspace: str) -> Dict[str, Any]:
|
|
|
1308
1441
|
"workspace": workspace,
|
|
1309
1442
|
"go": revert_go_patch(workspace),
|
|
1310
1443
|
"node": revert_node_patch(workspace),
|
|
1444
|
+
"elysia": revert_elysia_patch(workspace),
|
|
1311
1445
|
"dotnet": revert_dotnet_patch(workspace),
|
|
1312
1446
|
"next": revert_next_patch(workspace),
|
|
1313
1447
|
}
|
package/src/installer.py
CHANGED
|
@@ -60,7 +60,7 @@ UNIFIED_TOKENSAFE_RULE = (
|
|
|
60
60
|
"`🛡️ **TokenSafe Security Guard**: Prevented secret / private key leak into git (<target_file>: <details>)`\n"
|
|
61
61
|
"11. **Proof-of-Savings Turn Footer (strictly English)**: Append on tool-using turns:\n"
|
|
62
62
|
"`⚡ **TokenSafe Turn Savings**: +<tokens> tokens saved on this turn (<breakdown in English>) | Cumulative Total: <total> tokens (≈$<usd> approx)`\n"
|
|
63
|
-
"12. **Universal OUMV Protocol (`oumv`)**: When a workspace profile is OUMV-supported (React+Vite, Vue, Solid, Go, FastAPI), "
|
|
63
|
+
"12. **Universal OUMV Protocol (`oumv`)**: When a workspace profile is OUMV-supported (React+Vite, Vue, Solid, Go, FastAPI, Express/Fastify, Next.js, Elysia on Bun, ASP.NET Core), "
|
|
64
64
|
"ALWAYS prefer `tokensafe:oumv(action='status'|'observe'|'understand'|'verify'|'mutate'|'graph', ...)` BEFORE full file crawls, raw curls, or browser checks — "
|
|
65
65
|
"static OUMV works offline on read/edit tasks too, and `tokensafe dev` starts zero-footprint live Vite+React RPC without touching repo files. "
|
|
66
66
|
"In mixed monorepos (e.g. React + Node.js), use `oumv` on supported profiles and `repo_map`/`smart_read_file`/`scoped_search` on unsupported stacks (e.g. `backend/node`).\n"
|
package/src/mcp_server.py
CHANGED
package/src/oumv_gateway.py
CHANGED
|
@@ -20,6 +20,12 @@ from src.paths import get_active_workspace
|
|
|
20
20
|
class OUMVRpcError(RuntimeError):
|
|
21
21
|
"""Raised when a live OUMV runtime explicitly returns a JSON-RPC error."""
|
|
22
22
|
|
|
23
|
+
def __init__(self, message: str, code: Optional[int] = None):
|
|
24
|
+
super().__init__(message)
|
|
25
|
+
# The JSON-RPC code, when the runtime sent one. Classification must not depend
|
|
26
|
+
# on the message text: every adapter words -32601 differently.
|
|
27
|
+
self.code = code
|
|
28
|
+
|
|
23
29
|
|
|
24
30
|
class OUMVUnsupportedMethodError(OUMVRpcError):
|
|
25
31
|
"""The runtime answered but does not implement the requested method.
|
|
@@ -291,12 +297,27 @@ class OUMVGateway:
|
|
|
291
297
|
"observeLevels": res.get("capabilities", {}).get("observe", {}).get("levels"),
|
|
292
298
|
"causality": res.get("capabilities", {}).get("understand", {}).get("causality"),
|
|
293
299
|
"occ": res.get("capabilities", {}).get("mutate", {}).get("occ"),
|
|
300
|
+
# Spec §8.5 (revision v1.11): a read-only deployment registers
|
|
301
|
+
# no writing method at all, so the answer is -32601 and this flag
|
|
302
|
+
# is the authoritative "do not edit behind its back" signal.
|
|
303
|
+
"readOnly": bool(res.get("capabilities", {}).get("readOnly")),
|
|
294
304
|
},
|
|
295
305
|
}
|
|
296
306
|
except Exception:
|
|
297
307
|
continue
|
|
298
308
|
return None
|
|
299
309
|
|
|
310
|
+
@classmethod
|
|
311
|
+
def _runtime_is_reachable(cls, url: Optional[str]) -> bool:
|
|
312
|
+
"""True when a live OUMV runtime answers a handshake at `url`."""
|
|
313
|
+
if not url:
|
|
314
|
+
return False
|
|
315
|
+
try:
|
|
316
|
+
res = cls._rpc_call(url, "oumv/handshake", {"protocolVersion": "1.6.0"}, timeout=0.35)
|
|
317
|
+
except Exception:
|
|
318
|
+
return False
|
|
319
|
+
return bool(res and isinstance(res, dict) and "runtimeInfo" in res)
|
|
320
|
+
|
|
300
321
|
@classmethod
|
|
301
322
|
def _rpc_call(cls, endpoint_url: str, method: str, params: Optional[dict] = None, timeout: float = 3.0) -> Any:
|
|
302
323
|
payload = json.dumps({
|
|
@@ -334,7 +355,7 @@ class OUMVGateway:
|
|
|
334
355
|
if isinstance(err, dict):
|
|
335
356
|
code = err.get("code")
|
|
336
357
|
msg = err.get("message") or str(err)
|
|
337
|
-
raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}")
|
|
358
|
+
raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}", code=code)
|
|
338
359
|
raise OUMVRpcError(f"JSON-RPC error from {endpoint_url}: {err}")
|
|
339
360
|
return data.get("result")
|
|
340
361
|
except urllib.error.HTTPError as exc:
|
|
@@ -342,7 +363,7 @@ class OUMVGateway:
|
|
|
342
363
|
# JSON-RPC envelope. Treat that as a protocol error (RuntimeError) so
|
|
343
364
|
# callers can fall back to offline operation instead of crashing on OSError.
|
|
344
365
|
code, msg = cls._http_error_detail(exc)
|
|
345
|
-
raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}") from exc
|
|
366
|
+
raise OUMVRpcError(f"JSON-RPC error ({code}) from {endpoint_url}: {msg}", code=code) from exc
|
|
346
367
|
except urllib.error.URLError as exc:
|
|
347
368
|
raise OUMVRpcError(f"runtime unreachable at {endpoint_url}: {exc.reason}") from exc
|
|
348
369
|
except (TimeoutError, OSError) as exc:
|
|
@@ -927,6 +948,7 @@ class OUMVGateway:
|
|
|
927
948
|
except Exception:
|
|
928
949
|
pass
|
|
929
950
|
|
|
951
|
+
url: Optional[str] = None
|
|
930
952
|
try:
|
|
931
953
|
url = cls._resolve_client_url(runtime=runtime, target=path, workspace_dir=workspace_dir)
|
|
932
954
|
return cls._rpc_call(url, "oumv/applyEdit", {
|
|
@@ -939,12 +961,28 @@ class OUMVGateway:
|
|
|
939
961
|
})
|
|
940
962
|
except RuntimeError as e:
|
|
941
963
|
if isinstance(e, OUMVRpcError) and not isinstance(e, OUMVUnsupportedMethodError):
|
|
942
|
-
|
|
964
|
+
# -32601 by code, or a message an older bridge only words that way.
|
|
965
|
+
method_missing = getattr(e, "code", None) == -32601 or any(
|
|
966
|
+
hint in str(e).lower() for hint in _UNSUPPORTED_HINTS
|
|
967
|
+
)
|
|
968
|
+
if not method_missing:
|
|
943
969
|
# Explicit safety rejection (conflict, syntax, permission): obey it.
|
|
944
970
|
raise
|
|
945
|
-
#
|
|
946
|
-
#
|
|
947
|
-
|
|
971
|
+
# Spec §8.5 (revision v1.11): a *live* runtime that does not register
|
|
972
|
+
# applyEdit has no write path on purpose (read-only deployment, or the
|
|
973
|
+
# production lock-down). The offline path below would silently restore
|
|
974
|
+
# the very write path the deployment removed, so refuse instead of
|
|
975
|
+
# editing behind its back. The fallback stays for a runtime that died
|
|
976
|
+
# mid-flight, where nothing is reachable to ask.
|
|
977
|
+
if cls._runtime_is_reachable(url):
|
|
978
|
+
raise RuntimeError(
|
|
979
|
+
"[OUMV PERMISSION_DENIED: -32007] the OUMV runtime is running read-only "
|
|
980
|
+
"(oumv/applyEdit is not registered, spec §8.5); the edit was refused instead "
|
|
981
|
+
"of being written offline behind its back."
|
|
982
|
+
)
|
|
983
|
+
# Nothing answered: the dev server is offline, so the same guarded edit
|
|
984
|
+
# is performed locally and the result says why.
|
|
985
|
+
e = OUMVUnsupportedMethodError(str(e), code=getattr(e, "code", None))
|
|
948
986
|
# Out-of-the-box direct fallback when live dev-servers are offline
|
|
949
987
|
if replacement is not None:
|
|
950
988
|
abs_path = os.path.normpath(os.path.join(ws, path))
|
package/src/retrofit.py
CHANGED
|
@@ -105,15 +105,17 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
|
|
|
105
105
|
managers.append("bun")
|
|
106
106
|
|
|
107
107
|
if node_fw:
|
|
108
|
-
|
|
108
|
+
is_elysia = node_fw == "elysia"
|
|
109
|
+
supported_fw = node_fw in ("express", "fastify", "elysia")
|
|
109
110
|
be_out = {
|
|
110
111
|
"framework": node_fw,
|
|
111
|
-
"provider": "
|
|
112
|
-
"adapter":
|
|
113
|
-
"language": "bun" if
|
|
112
|
+
"provider": "elysia" if is_elysia else "node",
|
|
113
|
+
"adapter": "tokensafe-backend/elysia" if is_elysia else "tokensafe-backend/node",
|
|
114
|
+
"language": "bun" if is_elysia else "node",
|
|
114
115
|
"root": rel_dir,
|
|
115
|
-
# Express/Fastify ship
|
|
116
|
-
#
|
|
116
|
+
# Express/Fastify ship the certified Node adapter; Elysia ships on the
|
|
117
|
+
# `tokensafe-backend-node/elysia` subpath and is certified L3 on Bun.
|
|
118
|
+
# Nest/Hono/Koa do not yet.
|
|
117
119
|
"oumv_supported": supported_fw,
|
|
118
120
|
"status": "ready" if supported_fw else "planned",
|
|
119
121
|
}
|
|
@@ -679,6 +681,34 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
679
681
|
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
680
682
|
],
|
|
681
683
|
},
|
|
684
|
+
{
|
|
685
|
+
"id": "backend/elysia",
|
|
686
|
+
"name": "Elysia Adapter for Bun (HTTP + SSE + WebSocket)",
|
|
687
|
+
"profile": "backend",
|
|
688
|
+
"profiles": ["backend"],
|
|
689
|
+
"repo": "tokensafe-backend/node",
|
|
690
|
+
"mode": "hybrid",
|
|
691
|
+
"status": "ready",
|
|
692
|
+
"description": "Elysia plugin on Bun: the runtime mounts as a Web Request/Response binding, the route table is read from the composed app, verify dispatches through app.handle, and read-only mode registers no mutating method (certified Level 3: HTTP 51/51, SSE 52/52, WS 49/49)",
|
|
693
|
+
"technology": {
|
|
694
|
+
"language": "typescript",
|
|
695
|
+
"framework": "elysia (bun)",
|
|
696
|
+
"package": {"manager": "bun", "name": "tokensafe-backend-node", "install": "bun add tokensafe-backend-node"},
|
|
697
|
+
},
|
|
698
|
+
"capabilities": [
|
|
699
|
+
{"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
700
|
+
{"name": "observe.surface", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
701
|
+
{"name": "observe.contract", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
702
|
+
{"name": "observe.source", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
703
|
+
{"name": "observe.traces", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
704
|
+
{"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
705
|
+
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
706
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": True, "requiresPermission": "permissions.mutate != false"}},
|
|
707
|
+
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
708
|
+
{"name": "verify.sandboxRollback", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["the adopter supplies sandbox.db.run (e.g. bun:sqlite)"]}},
|
|
709
|
+
{"name": "index.symbols", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
710
|
+
],
|
|
711
|
+
},
|
|
682
712
|
{
|
|
683
713
|
"id": "backend/next",
|
|
684
714
|
"name": "Next.js App Router Adapter (Route Handler, server profile)",
|
|
@@ -1184,8 +1214,8 @@ def is_path_in_supported_oumv_scope(workspace_dir: str, file_path: str, use_cach
|
|
|
1184
1214
|
if role == "backend":
|
|
1185
1215
|
if ext in (".go", ".py"):
|
|
1186
1216
|
return pkg
|
|
1187
|
-
# Express/Fastify adapters ship from npm; their sources are in scope.
|
|
1188
|
-
if pkg.get("provider")
|
|
1217
|
+
# Express/Fastify/Elysia adapters ship from npm; their sources are in scope.
|
|
1218
|
+
if pkg.get("provider") in ("node", "elysia") and ext in (".js", ".ts", ".mjs", ".cjs", ".jsx", ".tsx"):
|
|
1189
1219
|
return pkg
|
|
1190
1220
|
return None
|
|
1191
1221
|
return None
|
package/src/session_brief.py
CHANGED
|
@@ -48,6 +48,11 @@ _BACKEND_LINES = {
|
|
|
48
48
|
"(`mountTokensafe(app)` for Express, `registerTokensafe(app)` for Fastify); "
|
|
49
49
|
"then use tokensafe:oumv for endpoints/impact and oumv_verify for live checks."
|
|
50
50
|
),
|
|
51
|
+
"elysia": (
|
|
52
|
+
"backend elysia/{framework} (Bun): install `tokensafe-backend-node` and add "
|
|
53
|
+
"`app.use(require('tokensafe-backend-node/elysia').oumv())` before `app.listen()`; "
|
|
54
|
+
"then use tokensafe:oumv for endpoints/impact and oumv_verify for live checks."
|
|
55
|
+
),
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
|
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.17"
|
|
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.17"
|
|
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
|