tokensafe 4.6.1 → 4.6.2
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/hooks/__pycache__/claude_code_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/cursor_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/kimi_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_invocation.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_tool_use.cpython-312.pyc +0 -0
- package/hooks/__pycache__/session_start.cpython-312.pyc +0 -0
- package/hooks/__pycache__/stop_hook.cpython-312.pyc +0 -0
- package/hooks/__pycache__/zcode_hook.cpython-312.pyc +0 -0
- package/hooks/pre_tool_use.py +26 -0
- package/hooks/session_start.py +8 -2
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +1 -1
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +6 -1
- package/src/adapter_core.py +66 -4
- package/src/cli.py +28 -0
- package/src/command_sanitizer.py +94 -0
- package/src/guard.py +36 -0
- package/src/installer.py +55 -5
- package/src/mcp_server.py +18 -6
- package/src/oumv_gateway.py +171 -31
- package/src/proxy.py +11 -4
- package/src/retrofit.py +380 -99
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/src/retrofit.py
CHANGED
|
@@ -10,119 +10,260 @@ import time
|
|
|
10
10
|
from typing import Dict, Any, List, Optional, Tuple
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[Optional[Dict[str, Any]], Optional[Dict[str, Any]], List[str]]:
|
|
14
|
+
"""Inspects a single package.json for frontend or Node.js backend stack."""
|
|
15
|
+
fe_out: Optional[Dict[str, Any]] = None
|
|
16
|
+
be_out: Optional[Dict[str, Any]] = None
|
|
17
|
+
managers: List[str] = []
|
|
18
|
+
try:
|
|
19
|
+
with open(pkg_json_path, "r", encoding="utf-8") as f:
|
|
20
|
+
pkg_data = json.load(f)
|
|
21
|
+
deps = {
|
|
22
|
+
**pkg_data.get("dependencies", {}),
|
|
23
|
+
**pkg_data.get("devDependencies", {}),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
state_managers = []
|
|
27
|
+
if "zustand" in deps:
|
|
28
|
+
state_managers.append("zustand")
|
|
29
|
+
if "redux" in deps or "@reduxjs/toolkit" in deps:
|
|
30
|
+
state_managers.append("redux")
|
|
31
|
+
if "pinia" in deps:
|
|
32
|
+
state_managers.append("pinia")
|
|
33
|
+
if "jotai" in deps:
|
|
34
|
+
state_managers.append("jotai")
|
|
35
|
+
|
|
36
|
+
fe_info: Dict[str, Any] = {
|
|
37
|
+
"state_managers": state_managers,
|
|
38
|
+
"orm": "prisma" if "@prisma/client" in deps or "prisma" in deps else ("drizzle" if "drizzle-orm" in deps else None),
|
|
39
|
+
"vite": "vite" in deps,
|
|
40
|
+
"root": rel_dir,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if "next" in deps:
|
|
44
|
+
fe_info.update({"framework": "nextjs", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("next"), "oumv_supported": True, "status": "ready"})
|
|
45
|
+
elif "react" in deps:
|
|
46
|
+
fe_info.update({"framework": "react", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("react"), "oumv_supported": True, "status": "ready"})
|
|
47
|
+
elif "vue" in deps:
|
|
48
|
+
fe_info.update({"framework": "vue", "provider": "vue", "adapter": "tokensafe-ui/oumv/vue", "version": deps.get("vue"), "oumv_supported": True, "status": "ready"})
|
|
49
|
+
elif "solid-js" in deps or "@tokensafe-ui/core" in deps:
|
|
50
|
+
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"})
|
|
51
|
+
elif "svelte" in deps:
|
|
52
|
+
fe_info.update({"framework": "svelte", "provider": "svelte", "adapter": "tokensafe-ui/core", "version": deps.get("svelte"), "oumv_supported": True, "status": "ready"})
|
|
53
|
+
|
|
54
|
+
if "framework" in fe_info:
|
|
55
|
+
fe_out = fe_info
|
|
56
|
+
|
|
57
|
+
# Node.js backend frameworks (adapter status: planned / unsupported yet)
|
|
58
|
+
node_fw = None
|
|
59
|
+
if "@nestjs/core" in deps:
|
|
60
|
+
node_fw = "nestjs"
|
|
61
|
+
elif "fastify" in deps:
|
|
62
|
+
node_fw = "fastify"
|
|
63
|
+
elif "express" in deps:
|
|
64
|
+
node_fw = "express"
|
|
65
|
+
elif "hono" in deps:
|
|
66
|
+
node_fw = "hono"
|
|
67
|
+
elif "koa" in deps:
|
|
68
|
+
node_fw = "koa"
|
|
69
|
+
|
|
70
|
+
if node_fw:
|
|
71
|
+
be_out = {
|
|
72
|
+
"framework": node_fw,
|
|
73
|
+
"provider": "node",
|
|
74
|
+
"adapter": "tokensafe-backend/node",
|
|
75
|
+
"language": "node",
|
|
76
|
+
"root": rel_dir,
|
|
77
|
+
"oumv_supported": False,
|
|
78
|
+
"status": "planned",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if isinstance(pkg_data.get("workspaces"), (list, dict)):
|
|
82
|
+
managers.append("workspaces")
|
|
83
|
+
except Exception:
|
|
84
|
+
pass
|
|
85
|
+
return fe_out, be_out, managers
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _iter_monorepo_package_dirs(workspace_dir: str) -> List[str]:
|
|
89
|
+
"""Returns shallow package subdirectories (depth <= 2) for monorepo stack discovery."""
|
|
90
|
+
skip = {"node_modules", ".git", "dist", "build", ".next", ".venv", "venv", "__pycache__", ".tokensafe"}
|
|
91
|
+
candidates: List[str] = []
|
|
92
|
+
container_names = {"apps", "packages", "services", "frontend", "web", "client", "ui", "backend", "api", "server", "go", "python"}
|
|
93
|
+
try:
|
|
94
|
+
for entry in sorted(os.listdir(workspace_dir)):
|
|
95
|
+
if entry in skip or entry.startswith("."):
|
|
96
|
+
continue
|
|
97
|
+
full = os.path.join(workspace_dir, entry)
|
|
98
|
+
if not os.path.isdir(full):
|
|
99
|
+
continue
|
|
100
|
+
if entry in container_names or os.path.isfile(os.path.join(full, "package.json")) or os.path.isfile(os.path.join(full, "go.mod")) or os.path.isfile(os.path.join(full, "pyproject.toml")):
|
|
101
|
+
candidates.append(full)
|
|
102
|
+
if entry in ("apps", "packages", "services"):
|
|
103
|
+
try:
|
|
104
|
+
for sub in sorted(os.listdir(full)):
|
|
105
|
+
if sub in skip or sub.startswith("."):
|
|
106
|
+
continue
|
|
107
|
+
sub_full = os.path.join(full, sub)
|
|
108
|
+
if os.path.isdir(sub_full):
|
|
109
|
+
candidates.append(sub_full)
|
|
110
|
+
except OSError:
|
|
111
|
+
pass
|
|
112
|
+
except OSError:
|
|
113
|
+
pass
|
|
114
|
+
return candidates
|
|
115
|
+
|
|
116
|
+
|
|
13
117
|
def detect_project_stack(workspace_dir: str) -> Dict[str, Any]:
|
|
14
|
-
"""Inspects workspace manifests to detect frontend and backend frameworks."""
|
|
118
|
+
"""Inspects workspace and monorepo manifests to detect frontend and backend frameworks."""
|
|
15
119
|
stack: Dict[str, Any] = {
|
|
16
120
|
"workspace": workspace_dir,
|
|
17
121
|
"frontend": None,
|
|
18
122
|
"backend": None,
|
|
19
123
|
"package_managers": [],
|
|
20
124
|
"detected_files": [],
|
|
125
|
+
"packages": [],
|
|
21
126
|
}
|
|
22
127
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if
|
|
43
|
-
state_managers.append("jotai")
|
|
44
|
-
|
|
45
|
-
fe_info: Dict[str, Any] = {
|
|
46
|
-
"state_managers": state_managers,
|
|
47
|
-
"orm": "prisma" if "@prisma/client" in deps or "prisma" in deps else ("drizzle" if "drizzle-orm" in deps else None),
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if "next" in deps:
|
|
51
|
-
fe_info.update({"framework": "nextjs", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("next")})
|
|
52
|
-
elif "react" in deps:
|
|
53
|
-
fe_info.update({"framework": "react", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("react")})
|
|
54
|
-
elif "vue" in deps:
|
|
55
|
-
fe_info.update({"framework": "vue", "provider": "vue", "adapter": "tokensafe-ui/oumv/vue", "version": deps.get("vue")})
|
|
56
|
-
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")})
|
|
58
|
-
elif "svelte" in deps:
|
|
59
|
-
fe_info.update({"framework": "svelte", "provider": "svelte", "adapter": "tokensafe-ui/core", "version": deps.get("svelte")})
|
|
60
|
-
|
|
61
|
-
if "framework" in fe_info:
|
|
62
|
-
stack["frontend"] = fe_info
|
|
63
|
-
except Exception:
|
|
64
|
-
pass
|
|
65
|
-
|
|
66
|
-
# Lockfiles
|
|
67
|
-
for lock, pm in [("pnpm-lock.yaml", "pnpm"), ("bun.lockb", "bun"), ("bun.lock", "bun"), ("yarn.lock", "yarn"), ("package-lock.json", "npm")]:
|
|
68
|
-
if os.path.isfile(os.path.join(workspace_dir, lock)):
|
|
69
|
-
stack["package_managers"].append(pm)
|
|
70
|
-
stack["detected_files"].append(lock)
|
|
71
|
-
|
|
72
|
-
# 2. Go Backend detection (go.mod)
|
|
73
|
-
go_mod_path = os.path.join(workspace_dir, "go.mod")
|
|
74
|
-
if not os.path.isfile(go_mod_path) and os.path.isfile(os.path.join(workspace_dir, "go", "go.mod")):
|
|
75
|
-
go_mod_path = os.path.join(workspace_dir, "go", "go.mod")
|
|
76
|
-
|
|
77
|
-
if os.path.isfile(go_mod_path):
|
|
78
|
-
stack["detected_files"].append(os.path.relpath(go_mod_path, workspace_dir))
|
|
79
|
-
stack["package_managers"].append("go")
|
|
80
|
-
framework = "net/http"
|
|
81
|
-
try:
|
|
82
|
-
with open(go_mod_path, "r", encoding="utf-8") as f:
|
|
83
|
-
content = f.read()
|
|
84
|
-
if "github.com/gin-gonic/gin" in content:
|
|
85
|
-
framework = "gin"
|
|
86
|
-
elif "github.com/go-chi/chi" in content:
|
|
87
|
-
framework = "chi"
|
|
88
|
-
elif "github.com/labstack/echo" in content:
|
|
89
|
-
framework = "echo"
|
|
90
|
-
stack["backend"] = {"framework": framework, "provider": "go", "adapter": "tokensafe-backend/go", "language": "go"}
|
|
91
|
-
except Exception:
|
|
92
|
-
stack["backend"] = {"framework": "go", "provider": "go", "adapter": "tokensafe-backend/go", "language": "go"}
|
|
93
|
-
|
|
94
|
-
# 3. Python Backend detection (pyproject.toml, requirements.txt, setup.py)
|
|
95
|
-
py_files = [
|
|
96
|
-
os.path.join(workspace_dir, "pyproject.toml"),
|
|
97
|
-
os.path.join(workspace_dir, "python", "pyproject.toml"),
|
|
98
|
-
os.path.join(workspace_dir, "requirements.txt"),
|
|
99
|
-
]
|
|
100
|
-
for pf in py_files:
|
|
101
|
-
if os.path.isfile(pf):
|
|
102
|
-
stack["detected_files"].append(os.path.relpath(pf, workspace_dir))
|
|
103
|
-
stack["package_managers"].append("pip/python")
|
|
104
|
-
try:
|
|
105
|
-
with open(pf, "r", encoding="utf-8") as f:
|
|
106
|
-
c = f.read().lower()
|
|
107
|
-
framework = "python"
|
|
108
|
-
if "fastapi" in c:
|
|
109
|
-
framework = "fastapi"
|
|
110
|
-
elif "django" in c:
|
|
111
|
-
framework = "django"
|
|
112
|
-
elif "flask" in c:
|
|
113
|
-
framework = "flask"
|
|
114
|
-
elif "starlette" in c:
|
|
115
|
-
framework = "starlette"
|
|
128
|
+
def _scan_dir(target_dir: str):
|
|
129
|
+
rel = os.path.relpath(target_dir, workspace_dir) or "."
|
|
130
|
+
pkg_json_path = os.path.join(target_dir, "package.json")
|
|
131
|
+
if os.path.isfile(pkg_json_path):
|
|
132
|
+
stack["detected_files"].append(os.path.relpath(pkg_json_path, workspace_dir))
|
|
133
|
+
fe_info, be_info, _ = _detect_package_json_entry(pkg_json_path, rel_dir=rel)
|
|
134
|
+
if fe_info:
|
|
135
|
+
if not stack["frontend"]:
|
|
136
|
+
stack["frontend"] = fe_info
|
|
137
|
+
stack["packages"].append({
|
|
138
|
+
"role": "frontend",
|
|
139
|
+
"path": rel,
|
|
140
|
+
"framework": fe_info["framework"],
|
|
141
|
+
"provider": fe_info["provider"],
|
|
142
|
+
"adapter": fe_info["adapter"],
|
|
143
|
+
"vite": fe_info.get("vite", False),
|
|
144
|
+
"oumvSupported": bool(fe_info.get("oumv_supported", True)),
|
|
145
|
+
"status": fe_info.get("status", "ready"),
|
|
146
|
+
})
|
|
147
|
+
if be_info:
|
|
116
148
|
if not stack["backend"]:
|
|
117
|
-
stack["backend"] =
|
|
149
|
+
stack["backend"] = be_info
|
|
150
|
+
stack["packages"].append({
|
|
151
|
+
"role": "backend",
|
|
152
|
+
"path": rel,
|
|
153
|
+
"framework": be_info["framework"],
|
|
154
|
+
"provider": be_info["provider"],
|
|
155
|
+
"adapter": be_info["adapter"],
|
|
156
|
+
"oumvSupported": bool(be_info.get("oumv_supported", False)),
|
|
157
|
+
"status": be_info.get("status", "planned"),
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
# Go Backend detection
|
|
161
|
+
go_mod_path = os.path.join(target_dir, "go.mod")
|
|
162
|
+
if rel == "." and not os.path.isfile(go_mod_path) and os.path.isfile(os.path.join(target_dir, "go", "go.mod")):
|
|
163
|
+
go_mod_path = os.path.join(target_dir, "go", "go.mod")
|
|
164
|
+
if os.path.isfile(go_mod_path):
|
|
165
|
+
rel_mod = os.path.relpath(go_mod_path, workspace_dir)
|
|
166
|
+
if rel_mod not in stack["detected_files"]:
|
|
167
|
+
stack["detected_files"].append(rel_mod)
|
|
168
|
+
if "go" not in stack["package_managers"]:
|
|
169
|
+
stack["package_managers"].append("go")
|
|
170
|
+
framework = "net/http"
|
|
171
|
+
try:
|
|
172
|
+
with open(go_mod_path, "r", encoding="utf-8") as f:
|
|
173
|
+
content = f.read()
|
|
174
|
+
if "github.com/gin-gonic/gin" in content:
|
|
175
|
+
framework = "gin"
|
|
176
|
+
elif "github.com/go-chi/chi" in content:
|
|
177
|
+
framework = "chi"
|
|
178
|
+
elif "github.com/labstack/echo" in content:
|
|
179
|
+
framework = "echo"
|
|
180
|
+
except Exception:
|
|
181
|
+
pass
|
|
182
|
+
go_entry = {
|
|
183
|
+
"framework": framework,
|
|
184
|
+
"provider": "go",
|
|
185
|
+
"adapter": "tokensafe-backend/go",
|
|
186
|
+
"language": "go",
|
|
187
|
+
"root": os.path.dirname(rel_mod) or ".",
|
|
188
|
+
"oumv_supported": True,
|
|
189
|
+
"status": "ready",
|
|
190
|
+
}
|
|
191
|
+
if not stack["backend"] or not stack["backend"].get("oumv_supported", False):
|
|
192
|
+
stack["backend"] = go_entry
|
|
193
|
+
stack["packages"].append({
|
|
194
|
+
"role": "backend",
|
|
195
|
+
"path": go_entry["root"],
|
|
196
|
+
"framework": framework,
|
|
197
|
+
"provider": "go",
|
|
198
|
+
"adapter": "tokensafe-backend/go",
|
|
199
|
+
"oumvSupported": True,
|
|
200
|
+
"status": "ready",
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
# Python Backend detection
|
|
204
|
+
py_files = [
|
|
205
|
+
os.path.join(target_dir, "pyproject.toml"),
|
|
206
|
+
os.path.join(target_dir, "requirements.txt"),
|
|
207
|
+
]
|
|
208
|
+
if rel == ".":
|
|
209
|
+
py_files.insert(1, os.path.join(target_dir, "python", "pyproject.toml"))
|
|
210
|
+
for pf in py_files:
|
|
211
|
+
if os.path.isfile(pf):
|
|
212
|
+
rel_pf = os.path.relpath(pf, workspace_dir)
|
|
213
|
+
if rel_pf not in stack["detected_files"]:
|
|
214
|
+
stack["detected_files"].append(rel_pf)
|
|
215
|
+
if "pip/python" not in stack["package_managers"]:
|
|
216
|
+
stack["package_managers"].append("pip/python")
|
|
217
|
+
try:
|
|
218
|
+
with open(pf, "r", encoding="utf-8") as f:
|
|
219
|
+
c = f.read().lower()
|
|
220
|
+
framework = "python"
|
|
221
|
+
if "fastapi" in c:
|
|
222
|
+
framework = "fastapi"
|
|
223
|
+
elif "django" in c:
|
|
224
|
+
framework = "django"
|
|
225
|
+
elif "flask" in c:
|
|
226
|
+
framework = "flask"
|
|
227
|
+
elif "starlette" in c:
|
|
228
|
+
framework = "starlette"
|
|
229
|
+
supported = framework in ("fastapi", "starlette")
|
|
230
|
+
py_entry = {
|
|
118
231
|
"framework": framework,
|
|
119
232
|
"provider": "fastapi" if framework == "fastapi" else "python",
|
|
120
233
|
"adapter": "tokensafe-backend/python",
|
|
121
234
|
"language": "python",
|
|
235
|
+
"root": os.path.dirname(rel_pf) or ".",
|
|
236
|
+
"oumv_supported": supported,
|
|
237
|
+
"status": "ready" if supported else "planned",
|
|
122
238
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
239
|
+
if not stack["backend"]:
|
|
240
|
+
stack["backend"] = py_entry
|
|
241
|
+
stack["packages"].append({
|
|
242
|
+
"role": "backend",
|
|
243
|
+
"path": py_entry["root"],
|
|
244
|
+
"framework": framework,
|
|
245
|
+
"provider": py_entry["provider"],
|
|
246
|
+
"adapter": "tokensafe-backend/python",
|
|
247
|
+
"oumvSupported": supported,
|
|
248
|
+
"status": py_entry["status"],
|
|
249
|
+
})
|
|
250
|
+
except Exception:
|
|
251
|
+
pass
|
|
252
|
+
break
|
|
253
|
+
|
|
254
|
+
_scan_dir(workspace_dir)
|
|
255
|
+
if os.path.isfile(os.path.join(workspace_dir, "pnpm-workspace.yaml")):
|
|
256
|
+
stack["detected_files"].append("pnpm-workspace.yaml")
|
|
257
|
+
|
|
258
|
+
for lock, pm in [("pnpm-lock.yaml", "pnpm"), ("bun.lockb", "bun"), ("bun.lock", "bun"), ("yarn.lock", "yarn"), ("package-lock.json", "npm")]:
|
|
259
|
+
if os.path.isfile(os.path.join(workspace_dir, lock)):
|
|
260
|
+
if pm not in stack["package_managers"]:
|
|
261
|
+
stack["package_managers"].append(pm)
|
|
262
|
+
if lock not in stack["detected_files"]:
|
|
263
|
+
stack["detected_files"].append(lock)
|
|
264
|
+
|
|
265
|
+
for sub_dir in _iter_monorepo_package_dirs(workspace_dir):
|
|
266
|
+
_scan_dir(sub_dir)
|
|
126
267
|
|
|
127
268
|
return stack
|
|
128
269
|
|
|
@@ -333,7 +474,15 @@ def run_doctor(workspace_dir: str) -> Dict[str, Any]:
|
|
|
333
474
|
"""Diagnostics check for OUMV configuration, ports, lockfiles, and permissions."""
|
|
334
475
|
stack = detect_project_stack(workspace_dir)
|
|
335
476
|
conf_path = os.path.join(workspace_dir, ".tokensafe", "oumv.json")
|
|
336
|
-
|
|
477
|
+
runtime_paths = [
|
|
478
|
+
os.path.join(workspace_dir, ".tokensafe", "runtime.json"),
|
|
479
|
+
]
|
|
480
|
+
try:
|
|
481
|
+
from src.oumv_gateway import OUMVGateway
|
|
482
|
+
runtime_paths.insert(0, OUMVGateway.global_runtime_file(workspace_dir))
|
|
483
|
+
except Exception:
|
|
484
|
+
pass
|
|
485
|
+
runtime_path = next((p for p in runtime_paths if os.path.isfile(p)), runtime_paths[-1])
|
|
337
486
|
|
|
338
487
|
has_config = os.path.isfile(conf_path)
|
|
339
488
|
config_data: Dict[str, Any] = {}
|
|
@@ -426,3 +575,135 @@ class OUMVProjectContext:
|
|
|
426
575
|
if any(target.startswith(c) for c in ["#", ".", "[", "button", "input"]) or target.startswith("<") or target.endswith(".tsx") or target.endswith(".jsx"):
|
|
427
576
|
return "frontend"
|
|
428
577
|
return "auto"
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def resolve_zero_footprint_vite_command(
|
|
581
|
+
workspace_dir: str,
|
|
582
|
+
port: Optional[int] = None,
|
|
583
|
+
host: Optional[str] = None,
|
|
584
|
+
open_browser: bool = False,
|
|
585
|
+
) -> Tuple[List[str], str]:
|
|
586
|
+
"""Resolves zero-footprint tokensafe-ui Vite+React runner command without editing repo files."""
|
|
587
|
+
import shutil
|
|
588
|
+
import subprocess
|
|
589
|
+
|
|
590
|
+
ws = os.path.abspath(workspace_dir)
|
|
591
|
+
cli_flags: List[str] = []
|
|
592
|
+
if port is not None:
|
|
593
|
+
cli_flags.append(f"--port={port}")
|
|
594
|
+
if host:
|
|
595
|
+
cli_flags.append(f"--host={host}")
|
|
596
|
+
if open_browser:
|
|
597
|
+
cli_flags.append("--open")
|
|
598
|
+
|
|
599
|
+
# 1. Local project node_modules/.bin/tokensafe-ui (if present)
|
|
600
|
+
local_bin = os.path.join(ws, "node_modules", ".bin", "tokensafe-ui")
|
|
601
|
+
if os.path.isfile(local_bin):
|
|
602
|
+
return ([local_bin, "dev", ws, *cli_flags], "local node_modules")
|
|
603
|
+
|
|
604
|
+
# 2. Global tokensafe-ui binary on PATH
|
|
605
|
+
global_bin = shutil.which("tokensafe-ui")
|
|
606
|
+
if global_bin:
|
|
607
|
+
return ([global_bin, "dev", ws, *cli_flags], "global PATH")
|
|
608
|
+
|
|
609
|
+
# 3. npm global root package
|
|
610
|
+
try:
|
|
611
|
+
res = subprocess.run(["npm", "root", "-g"], capture_output=True, text=True, timeout=3)
|
|
612
|
+
if res.returncode == 0:
|
|
613
|
+
global_root = res.stdout.strip()
|
|
614
|
+
cli_js = os.path.join(global_root, "tokensafe-ui", "bin", "cli.js")
|
|
615
|
+
if os.path.isfile(cli_js):
|
|
616
|
+
return (["node", cli_js, "dev", ws, *cli_flags], "npm global root")
|
|
617
|
+
except Exception:
|
|
618
|
+
pass
|
|
619
|
+
|
|
620
|
+
# 4. Explicit override or npx fallback (zero edits to workspace package.json)
|
|
621
|
+
env_cli = os.environ.get("TOKENSAFE_UI_CLI")
|
|
622
|
+
if env_cli and os.path.isfile(env_cli):
|
|
623
|
+
return (["node", env_cli, "dev", ws, *cli_flags], "TOKENSAFE_UI_CLI")
|
|
624
|
+
|
|
625
|
+
npx_bin = shutil.which("npx") or "npx"
|
|
626
|
+
return ([npx_bin, "--yes", "tokensafe-ui", "dev", ws, *cli_flags], "npx tokensafe-ui")
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
def format_oumv_workspace_brief(workspace_dir: str, include_live: bool = False) -> str:
|
|
630
|
+
"""Builds a compact OUMV capability matrix banner for SessionStart and tokensafe-proxy.
|
|
631
|
+
|
|
632
|
+
Explicitly separates supported profiles (React+Vite, Vue, Solid, Go, FastAPI)
|
|
633
|
+
from unsupported stacks (e.g. Node.js express/fastify/nest in a monorepo), so agents
|
|
634
|
+
use OUMV where available without wasting turns probing unsupported subprojects.
|
|
635
|
+
"""
|
|
636
|
+
if not workspace_dir or not os.path.isdir(workspace_dir):
|
|
637
|
+
return ""
|
|
638
|
+
stack = detect_project_stack(workspace_dir)
|
|
639
|
+
packages = stack.get("packages") or []
|
|
640
|
+
parts: List[str] = []
|
|
641
|
+
seen_labels = set()
|
|
642
|
+
|
|
643
|
+
for pkg in packages:
|
|
644
|
+
loc = f" ({pkg['path']})" if pkg.get("path") and pkg["path"] != "." else ""
|
|
645
|
+
label = f"{pkg.get('provider')}/{pkg.get('framework')}{loc}"
|
|
646
|
+
if label in seen_labels:
|
|
647
|
+
continue
|
|
648
|
+
seen_labels.add(label)
|
|
649
|
+
if pkg.get("oumvSupported"):
|
|
650
|
+
run_hint = "; start live bridge via 'tokensafe dev'" if pkg.get("vite") else ""
|
|
651
|
+
parts.append(
|
|
652
|
+
f"{label}: OUMV SUPPORTED (use tokensafe:oumv observe/understand/mutate{run_hint})"
|
|
653
|
+
)
|
|
654
|
+
else:
|
|
655
|
+
parts.append(
|
|
656
|
+
f"{label}: OUMV UNSUPPORTED yet (planned — use repo_map/smart_read_file/scoped_search instead of oumv)"
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
if not parts:
|
|
660
|
+
return ""
|
|
661
|
+
|
|
662
|
+
if include_live:
|
|
663
|
+
try:
|
|
664
|
+
from src.oumv_gateway import OUMVGateway
|
|
665
|
+
fe, be = OUMVGateway.get_endpoints(workspace_dir=workspace_dir)
|
|
666
|
+
live_bits = []
|
|
667
|
+
if fe:
|
|
668
|
+
live_bits.append(f"FE LIVE {fe.get('url')}")
|
|
669
|
+
if be:
|
|
670
|
+
live_bits.append(f"BE LIVE {be.get('url')}")
|
|
671
|
+
if live_bits:
|
|
672
|
+
parts.append("LIVE RUNTIMES: " + ", ".join(live_bits) + " -> MUST inspect/verify via tokensafe:oumv")
|
|
673
|
+
except Exception:
|
|
674
|
+
pass
|
|
675
|
+
|
|
676
|
+
return "[TokenSafe OUMV Workspace Matrix | " + " | ".join(parts) + "]"
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def is_path_in_supported_oumv_scope(workspace_dir: str, file_path: str) -> Optional[Dict[str, Any]]:
|
|
680
|
+
"""Returns the supported stack entry owning `file_path`, or None if unsupported (e.g. backend/node)."""
|
|
681
|
+
if not workspace_dir or not file_path:
|
|
682
|
+
return None
|
|
683
|
+
ws_abs = os.path.realpath(os.path.abspath(workspace_dir))
|
|
684
|
+
f_abs = os.path.realpath(os.path.abspath(file_path if os.path.isabs(file_path) else os.path.join(ws_abs, file_path)))
|
|
685
|
+
if not (f_abs == ws_abs or f_abs.startswith(ws_abs + os.sep)):
|
|
686
|
+
return None
|
|
687
|
+
|
|
688
|
+
rel = os.path.relpath(f_abs, ws_abs).replace(os.sep, "/")
|
|
689
|
+
stack = detect_project_stack(ws_abs)
|
|
690
|
+
packages = stack.get("packages") or []
|
|
691
|
+
# Match most specific package path first
|
|
692
|
+
sorted_pkgs = sorted(
|
|
693
|
+
packages,
|
|
694
|
+
key=lambda p: (0 if p.get("path", ".") == "." else len(str(p.get("path", ".")))),
|
|
695
|
+
reverse=True,
|
|
696
|
+
)
|
|
697
|
+
for pkg in sorted_pkgs:
|
|
698
|
+
p_rel = str(pkg.get("path") or ".").replace(os.sep, "/").strip("/")
|
|
699
|
+
if p_rel == "." or rel == p_rel or rel.startswith(p_rel + "/"):
|
|
700
|
+
if not pkg.get("oumvSupported"):
|
|
701
|
+
return None
|
|
702
|
+
ext = os.path.splitext(f_abs)[1].lower()
|
|
703
|
+
role = pkg.get("role")
|
|
704
|
+
if role == "frontend" and ext in (".tsx", ".jsx", ".vue", ".ts", ".js"):
|
|
705
|
+
return pkg
|
|
706
|
+
if role == "backend" and ext in (".go", ".py"):
|
|
707
|
+
return pkg
|
|
708
|
+
return None
|
|
709
|
+
return None
|
package/src/telemetry_sync.py
CHANGED
|
@@ -249,7 +249,7 @@ class TelemetrySync:
|
|
|
249
249
|
current_last_id = last_id
|
|
250
250
|
headers = {
|
|
251
251
|
"Content-Type": "application/json",
|
|
252
|
-
"User-Agent": "TokenSafe-Sync/4.6.
|
|
252
|
+
"User-Agent": "TokenSafe-Sync/4.6.2"
|
|
253
253
|
}
|
|
254
254
|
if active_key:
|
|
255
255
|
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.6.
|
|
20
|
+
CURRENT_VERSION = "4.6.2"
|
|
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
|