tokensafe 4.5.5 → 4.6.0
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/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/batch_search.py +62 -48
- package/src/cross_stack.py +212 -0
- package/src/mcp_server.py +27 -1
- package/src/oumv_gateway.py +89 -1
- package/src/retrofit.py +74 -1
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
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": "MIT",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.6.0",
|
|
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.
|
|
4
|
+
"version": "4.6.0",
|
|
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
|
"logo": "assets/logo.png",
|
|
7
7
|
"developerName": "TokenSafe",
|
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.
|
|
6
|
+
"version": "4.6.0",
|
|
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.
|
|
26
|
+
"version": "4.6.0",
|
|
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.
|
|
42
|
+
"version": "4.6.0",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/batch_search.py
CHANGED
|
@@ -133,7 +133,9 @@ def _run_rg_query(
|
|
|
133
133
|
if not rg_bin:
|
|
134
134
|
return None
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
# --with-filename is mandatory: for a single-file target ripgrep omits the
|
|
137
|
+
# path prefix, so every output line would be unparseable below (silent 0 hits).
|
|
138
|
+
cmd = [rg_bin, "--no-heading", "--with-filename", "--line-number", "--color=never", "--max-count", str(max_results)]
|
|
137
139
|
if not is_regex:
|
|
138
140
|
cmd.append("--fixed-strings")
|
|
139
141
|
if not case_sensitive:
|
|
@@ -184,6 +186,18 @@ def _run_rg_query(
|
|
|
184
186
|
return None
|
|
185
187
|
|
|
186
188
|
|
|
189
|
+
def _iter_search_files(search_root: str, cwd: str):
|
|
190
|
+
"""Yields (full_path, rel_path) for an explicit file target or a directory tree."""
|
|
191
|
+
if os.path.isfile(search_root):
|
|
192
|
+
yield search_root, os.path.relpath(search_root, cwd)
|
|
193
|
+
return
|
|
194
|
+
for root, dirs, files in os.walk(search_root):
|
|
195
|
+
dirs[:] = [d for d in dirs if d not in IGNORED_DIRS and not d.startswith(".")]
|
|
196
|
+
for f in files:
|
|
197
|
+
full_path = os.path.join(root, f)
|
|
198
|
+
yield full_path, os.path.relpath(full_path, cwd)
|
|
199
|
+
|
|
200
|
+
|
|
187
201
|
def _run_python_text_search(
|
|
188
202
|
pattern: str,
|
|
189
203
|
cwd: str,
|
|
@@ -209,41 +223,41 @@ def _run_python_text_search(
|
|
|
209
223
|
|
|
210
224
|
matches = []
|
|
211
225
|
target_lower = pattern if case_sensitive else pattern.lower()
|
|
226
|
+
explicit_file = os.path.isfile(search_root)
|
|
212
227
|
|
|
213
|
-
for
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
for full_path, rel_p in _iter_search_files(search_root, cwd):
|
|
229
|
+
# An explicitly named file is searched as-is: extension, scope, and glob
|
|
230
|
+
# filters only make sense when walking a directory tree.
|
|
231
|
+
if not explicit_file:
|
|
232
|
+
ext = os.path.splitext(full_path)[1].lower()
|
|
217
233
|
if ext in IGNORED_EXTENSIONS:
|
|
218
234
|
continue
|
|
219
235
|
if scope == "code" and ext not in CODE_EXTENSIONS:
|
|
220
236
|
continue
|
|
221
|
-
|
|
222
|
-
rel_p = os.path.relpath(full_path, cwd)
|
|
223
|
-
if glob_filter and not (fnmatch.fnmatch(f, glob_filter) or fnmatch.fnmatch(rel_p, glob_filter)):
|
|
237
|
+
if glob_filter and not (fnmatch.fnmatch(os.path.basename(full_path), glob_filter) or fnmatch.fnmatch(rel_p, glob_filter)):
|
|
224
238
|
continue
|
|
225
239
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
240
|
+
try:
|
|
241
|
+
with open(full_path, "r", encoding="utf-8", errors="replace") as fp:
|
|
242
|
+
for line_idx, line in enumerate(fp):
|
|
243
|
+
hit = False
|
|
244
|
+
if regex:
|
|
245
|
+
hit = bool(regex.search(line))
|
|
246
|
+
elif case_sensitive:
|
|
247
|
+
hit = pattern in line
|
|
248
|
+
else:
|
|
249
|
+
hit = target_lower in line.lower()
|
|
250
|
+
|
|
251
|
+
if hit:
|
|
252
|
+
matches.append({
|
|
253
|
+
"file": rel_p,
|
|
254
|
+
"line": line_idx + 1,
|
|
255
|
+
"content": line.strip()[:180]
|
|
256
|
+
})
|
|
257
|
+
if len(matches) >= max_results:
|
|
258
|
+
return matches
|
|
259
|
+
except Exception:
|
|
260
|
+
continue
|
|
247
261
|
|
|
248
262
|
return matches
|
|
249
263
|
|
|
@@ -254,15 +268,18 @@ def _run_glob_search(pattern: str, cwd: str, path_filter: Optional[str] = None,
|
|
|
254
268
|
if not os.path.exists(search_root):
|
|
255
269
|
return []
|
|
256
270
|
|
|
271
|
+
if os.path.isfile(search_root):
|
|
272
|
+
rel_p = os.path.relpath(search_root, cwd)
|
|
273
|
+
if fnmatch.fnmatch(rel_p, pattern) or fnmatch.fnmatch(os.path.basename(search_root), pattern):
|
|
274
|
+
return [rel_p]
|
|
275
|
+
return []
|
|
276
|
+
|
|
257
277
|
results = []
|
|
258
|
-
for
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
results.append(rel_p)
|
|
264
|
-
if len(results) >= max_results:
|
|
265
|
-
return results
|
|
278
|
+
for full_path, rel_p in _iter_search_files(search_root, cwd):
|
|
279
|
+
if fnmatch.fnmatch(rel_p, pattern) or fnmatch.fnmatch(os.path.basename(full_path), pattern):
|
|
280
|
+
results.append(rel_p)
|
|
281
|
+
if len(results) >= max_results:
|
|
282
|
+
return results
|
|
266
283
|
return results
|
|
267
284
|
|
|
268
285
|
|
|
@@ -274,17 +291,14 @@ def _run_fuzzy_search(pattern: str, cwd: str, path_filter: Optional[str] = None,
|
|
|
274
291
|
|
|
275
292
|
pat_lower = pattern.lower().replace(" ", "")
|
|
276
293
|
results = []
|
|
277
|
-
for
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
results.append(rel_p)
|
|
286
|
-
if len(results) >= max_results:
|
|
287
|
-
return results
|
|
294
|
+
for _, rel_p in _iter_search_files(search_root, cwd):
|
|
295
|
+
name_lower = rel_p.lower()
|
|
296
|
+
# Subsequence match
|
|
297
|
+
it = iter(name_lower)
|
|
298
|
+
if all(ch in it for ch in pat_lower):
|
|
299
|
+
results.append(rel_p)
|
|
300
|
+
if len(results) >= max_results:
|
|
301
|
+
return results
|
|
288
302
|
return results
|
|
289
303
|
|
|
290
304
|
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unified Cross-Stack Intelligence Graph (OUMV spec §11).
|
|
3
|
+
|
|
4
|
+
Merges three independent evidence sources into one resource graph:
|
|
5
|
+
1. Static analysis (frontend API call sites -> backend endpoints, from the AST graph engine).
|
|
6
|
+
2. Live frontend runtime surface (mounted components / actions, provenance "runtime").
|
|
7
|
+
3. Live backend runtime surface (endpoints actually served, provenance "runtime").
|
|
8
|
+
|
|
9
|
+
Every node and edge carries EvidenceMetadata (spec §6.2). Missing runtime evidence
|
|
10
|
+
is reported explicitly instead of being inferred.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import time
|
|
14
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _static_evidence() -> Dict[str, str]:
|
|
18
|
+
return {"provenance": "static", "sourceAdapter": "tokensafe-graph-engine", "confidence": "probable"}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _runtime_evidence(source: str) -> Dict[str, str]:
|
|
22
|
+
return {"provenance": "runtime", "sourceAdapter": source, "confidence": "confirmed"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def build_unified_graph(
|
|
26
|
+
workspace_dir: Optional[str] = None,
|
|
27
|
+
fe: Optional[Dict[str, Any]] = None,
|
|
28
|
+
be: Optional[Dict[str, Any]] = None,
|
|
29
|
+
rpc_call: Optional[Callable[..., Any]] = None,
|
|
30
|
+
) -> Dict[str, Any]:
|
|
31
|
+
"""Builds the unified cross-stack graph for a workspace.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
workspace_dir: workspace root (defaults to the active workspace).
|
|
35
|
+
fe / be: live runtime descriptors from OUMVGateway.get_endpoints().
|
|
36
|
+
rpc_call: callable(url, method, params) used to observe live surfaces.
|
|
37
|
+
"""
|
|
38
|
+
from src.graph_engine import GraphEngine
|
|
39
|
+
from src.paths import get_active_workspace
|
|
40
|
+
|
|
41
|
+
ws = workspace_dir or get_active_workspace()
|
|
42
|
+
static = GraphEngine.get_instance(ws)
|
|
43
|
+
|
|
44
|
+
nodes: Dict[str, Dict[str, Any]] = {}
|
|
45
|
+
edges: List[Dict[str, Any]] = []
|
|
46
|
+
|
|
47
|
+
def _endpoint_node_id(method: Optional[str], route: str) -> str:
|
|
48
|
+
return f"backend.endpoint:{method or 'ANY'}:{route}"
|
|
49
|
+
|
|
50
|
+
# 1. Static backend endpoints
|
|
51
|
+
for rel_path, eps in getattr(static, "file_endpoints", {}).items():
|
|
52
|
+
for route, sym, method in eps:
|
|
53
|
+
node_id = _endpoint_node_id(method, route)
|
|
54
|
+
nodes.setdefault(node_id, {
|
|
55
|
+
"id": node_id,
|
|
56
|
+
"type": "backend.endpoint",
|
|
57
|
+
"route": route,
|
|
58
|
+
"method": method,
|
|
59
|
+
"file": rel_path,
|
|
60
|
+
"symbol": sym,
|
|
61
|
+
"evidence": _static_evidence(),
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
# 2. Static frontend action (API call) sites
|
|
65
|
+
for rel_path, calls in getattr(static, "file_api_calls", {}).items():
|
|
66
|
+
for route, sym, method in calls:
|
|
67
|
+
node_id = f"frontend.action:{method or 'ANY'}:{route}:{rel_path}:{sym or ''}"
|
|
68
|
+
nodes.setdefault(node_id, {
|
|
69
|
+
"id": node_id,
|
|
70
|
+
"type": "frontend.action",
|
|
71
|
+
"route": route,
|
|
72
|
+
"method": method,
|
|
73
|
+
"file": rel_path,
|
|
74
|
+
"symbol": sym,
|
|
75
|
+
"evidence": _static_evidence(),
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
# 3. Static cross-stack edges (frontend call -> backend endpoint)
|
|
79
|
+
for link in getattr(static, "api_links", []):
|
|
80
|
+
source = link["source"]
|
|
81
|
+
target = link["target"]
|
|
82
|
+
src_id = f"frontend.action:{source.get('method') or 'ANY'}:{source.get('route')}:{source.get('file')}:{source.get('symbol') or ''}"
|
|
83
|
+
dst_id = _endpoint_node_id(target.get("method"), target.get("route") or "")
|
|
84
|
+
edges.append({
|
|
85
|
+
"source": src_id,
|
|
86
|
+
"target": dst_id,
|
|
87
|
+
"relation": "calls",
|
|
88
|
+
"evidence": _static_evidence(),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
runtime_fe_ok = False
|
|
92
|
+
runtime_be_ok = False
|
|
93
|
+
|
|
94
|
+
# 4. Live backend surface: confirms endpoints actually served
|
|
95
|
+
if be and rpc_call:
|
|
96
|
+
try:
|
|
97
|
+
surface = rpc_call(be["url"], "oumv/observe", {"level": "L1"})
|
|
98
|
+
if isinstance(surface, dict):
|
|
99
|
+
runtime_be_ok = True
|
|
100
|
+
for ep in surface.get("endpoints", []) or []:
|
|
101
|
+
node_id = _endpoint_node_id(ep.get("method"), ep.get("path") or ep.get("route") or "")
|
|
102
|
+
if not node_id.endswith(":"):
|
|
103
|
+
if node_id in nodes:
|
|
104
|
+
nodes[node_id]["runtimeConfirmed"] = True
|
|
105
|
+
else:
|
|
106
|
+
nodes[node_id] = {
|
|
107
|
+
"id": node_id,
|
|
108
|
+
"type": "backend.endpoint",
|
|
109
|
+
"route": ep.get("path") or ep.get("route"),
|
|
110
|
+
"method": ep.get("method"),
|
|
111
|
+
"evidence": _runtime_evidence("live-backend-runtime"),
|
|
112
|
+
}
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
# 5. Live frontend surface: mounted components / actions
|
|
117
|
+
if fe and rpc_call:
|
|
118
|
+
try:
|
|
119
|
+
surface = rpc_call(fe["url"], "oumv/observe", {"level": "L1"})
|
|
120
|
+
if isinstance(surface, dict):
|
|
121
|
+
runtime_fe_ok = True
|
|
122
|
+
for comp in surface.get("components", []) or surface.get("elements", []) or []:
|
|
123
|
+
comp_id = comp.get("id") or comp.get("agentId") or comp.get("componentId")
|
|
124
|
+
if not comp_id:
|
|
125
|
+
continue
|
|
126
|
+
node_id = f"frontend.component:{comp_id}"
|
|
127
|
+
nodes.setdefault(node_id, {
|
|
128
|
+
"id": node_id,
|
|
129
|
+
"type": "frontend.component",
|
|
130
|
+
"evidence": _runtime_evidence("live-frontend-runtime"),
|
|
131
|
+
})
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
provenance_summary = {
|
|
136
|
+
"staticNodes": sum(1 for n in nodes.values() if n["evidence"]["provenance"] == "static"),
|
|
137
|
+
"runtimeNodes": sum(1 for n in nodes.values() if n["evidence"]["provenance"] == "runtime"),
|
|
138
|
+
"runtimeConfirmedEndpoints": sum(1 for n in nodes.values() if n.get("runtimeConfirmed")),
|
|
139
|
+
"edges": len(edges),
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
"mode": "UNIFIED_CROSS_STACK_GRAPH",
|
|
144
|
+
"workspace": ws,
|
|
145
|
+
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
146
|
+
"nodes": list(nodes.values()),
|
|
147
|
+
"edges": edges,
|
|
148
|
+
"provenanceSummary": provenance_summary,
|
|
149
|
+
"missingEvidence": [
|
|
150
|
+
"Frontend call origins are statically inferred; runtime fetch tracing is not yet recorded by the frontend bridge.",
|
|
151
|
+
],
|
|
152
|
+
"runtimes": {
|
|
153
|
+
"frontend": "live" if runtime_fe_ok else ("unreachable" if fe else "offline"),
|
|
154
|
+
"backend": "live" if runtime_be_ok else ("unreachable" if be else "offline"),
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def who_depends_on(target: str, graph: Dict[str, Any]) -> Dict[str, Any]:
|
|
160
|
+
"""Answers §11.4: which frontend resources call a given backend endpoint."""
|
|
161
|
+
t = (target or "").strip()
|
|
162
|
+
result: Dict[str, Any] = {
|
|
163
|
+
"query": "who_depends_on",
|
|
164
|
+
"target": t,
|
|
165
|
+
"frontendCallers": [],
|
|
166
|
+
"runtimeConfirmed": False,
|
|
167
|
+
"evidence": _static_evidence(),
|
|
168
|
+
}
|
|
169
|
+
if not t:
|
|
170
|
+
result["error"] = "target is required (e.g. '/api/orders' or 'POST /api/orders')"
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
t_lower = t.lower()
|
|
174
|
+
for edge in graph.get("edges", []):
|
|
175
|
+
target_route = (edge.get("target") or "").lower()
|
|
176
|
+
if t_lower in target_route:
|
|
177
|
+
result["frontendCallers"].append({
|
|
178
|
+
"source": edge["source"],
|
|
179
|
+
"relation": "calls",
|
|
180
|
+
"evidence": edge.get("evidence"),
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
nodes = {n["id"]: n for n in graph.get("nodes", [])}
|
|
184
|
+
for node_id, node in nodes.items():
|
|
185
|
+
if node.get("type") == "backend.endpoint" and t_lower in f"{node.get('method') or ''} {node.get('route') or ''}".lower():
|
|
186
|
+
if node.get("runtimeConfirmed"):
|
|
187
|
+
result["runtimeConfirmed"] = True
|
|
188
|
+
|
|
189
|
+
result["frontendCallers"] = result["frontendCallers"][:30]
|
|
190
|
+
return result
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def impact_from_graph(target: str, graph: Dict[str, Any]) -> Dict[str, Any]:
|
|
194
|
+
"""Graph-based impact view: affected cross-stack callers with suggested verification."""
|
|
195
|
+
callers = who_depends_on(target, graph)
|
|
196
|
+
verification_steps = [
|
|
197
|
+
f"oumv_verify(target='POST {target}') — in-memory endpoint check",
|
|
198
|
+
]
|
|
199
|
+
for caller in callers.get("frontendCallers", [])[:3]:
|
|
200
|
+
parts = caller["source"].split(":")
|
|
201
|
+
route_hint = parts[2] if len(parts) > 2 else caller["source"]
|
|
202
|
+
verification_steps.append(
|
|
203
|
+
f"oumv_understand(query='causality', target='{route_hint}') — confirm the calling code still matches"
|
|
204
|
+
)
|
|
205
|
+
return {
|
|
206
|
+
"query": "impact",
|
|
207
|
+
"target": target,
|
|
208
|
+
"frontendCallers": callers.get("frontendCallers", []),
|
|
209
|
+
"runtimeConfirmed": callers.get("runtimeConfirmed", False),
|
|
210
|
+
"suggestedVerification": verification_steps,
|
|
211
|
+
"missingEvidence": graph.get("missingEvidence", []),
|
|
212
|
+
}
|
package/src/mcp_server.py
CHANGED
|
@@ -42,7 +42,7 @@ from src.paths import get_active_workspace, is_plugin_or_system_dir
|
|
|
42
42
|
|
|
43
43
|
SERVER_INFO = {
|
|
44
44
|
"name": "tokensafe-mcp",
|
|
45
|
-
"version": "4.
|
|
45
|
+
"version": "4.6.0"
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
# MCP client attribution: the initialize handshake carries clientInfo, which
|
|
@@ -2685,6 +2685,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2685
2685
|
details={"cmd": str(verify or "")[:100], "reason": str(res.get("error") or "")}
|
|
2686
2686
|
)
|
|
2687
2687
|
return _fallback_error("apply_edits", str(res.get("error") or "verify command blocked"))
|
|
2688
|
+
applied_files = res.get("applied_files") or []
|
|
2688
2689
|
lines = []
|
|
2689
2690
|
if res.get("success"):
|
|
2690
2691
|
action_desc = "Validated" if dry_run else "Applied"
|
|
@@ -2713,6 +2714,31 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2713
2714
|
lines.append(f"Error: {v['error']}")
|
|
2714
2715
|
|
|
2715
2716
|
out_msg = {"content": [{"type": "text", "text": "\n".join(lines)}]}
|
|
2717
|
+
if applied_files:
|
|
2718
|
+
# Dashboards must see batch edits: without this the batch editor is
|
|
2719
|
+
# invisible in metrics while every single-file edit is counted.
|
|
2720
|
+
payload_text = "".join(
|
|
2721
|
+
str(h.get("target") or "") + str(h.get("replacement") or "")
|
|
2722
|
+
for e in (edits or []) if isinstance(e, dict)
|
|
2723
|
+
for h in (e.get("hunks") or []) if isinstance(h, dict)
|
|
2724
|
+
) + "".join(
|
|
2725
|
+
str(e.get("create") or "") for e in (edits or []) if isinstance(e, dict)
|
|
2726
|
+
)
|
|
2727
|
+
edit_tokens = count_tokens(payload_text)
|
|
2728
|
+
# Same convention as SCOPED_SEARCH: serial per-file round-trips cost
|
|
2729
|
+
# roughly an order of magnitude more than the consolidated payload.
|
|
2730
|
+
tracker.record_event(
|
|
2731
|
+
session_id=_mcp_session_id(),
|
|
2732
|
+
event_type="BATCH_EDIT",
|
|
2733
|
+
original_tokens=max(1500, edit_tokens * 8),
|
|
2734
|
+
optimized_tokens=edit_tokens,
|
|
2735
|
+
details={
|
|
2736
|
+
"files": len(applied_files),
|
|
2737
|
+
"hunks": sum(int(f.get("hunks") or 0) for f in applied_files),
|
|
2738
|
+
"dry_run": dry_run,
|
|
2739
|
+
"verify": bool(verify),
|
|
2740
|
+
},
|
|
2741
|
+
)
|
|
2716
2742
|
if not res.get("success"):
|
|
2717
2743
|
out_msg["isError"] = True
|
|
2718
2744
|
return out_msg
|
package/src/oumv_gateway.py
CHANGED
|
@@ -238,11 +238,61 @@ class OUMVGateway:
|
|
|
238
238
|
"framework": stack_info.get("backend", {}).get("framework", "None") if stack_info.get("backend") else "None",
|
|
239
239
|
"tip": "Static AST analysis active. When backend DevServer starts (port 8080/8000), live OUMV auto-connects."
|
|
240
240
|
},
|
|
241
|
+
"adapters": cls._adapter_lifecycle(stack_info, fe, be),
|
|
241
242
|
"staticIntelligence": "ACTIVE (L0/L1/L2 AST observation & cross-stack linking ready)",
|
|
242
243
|
"detectedStack": stack_info,
|
|
243
244
|
"workspace": ws,
|
|
244
245
|
}
|
|
245
246
|
|
|
247
|
+
@staticmethod
|
|
248
|
+
def _adapter_lifecycle(stack_info: Dict[str, Any], fe: Optional[Dict[str, Any]], be: Optional[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
249
|
+
"""Per-adapter lifecycle + health per the OUMV Adapter Contract (schemas/adapter.json)."""
|
|
250
|
+
adapters: List[Dict[str, Any]] = []
|
|
251
|
+
fe_detected = bool(stack_info.get("frontend"))
|
|
252
|
+
be_detected = bool(stack_info.get("backend"))
|
|
253
|
+
if not fe_detected and not be_detected:
|
|
254
|
+
return adapters
|
|
255
|
+
|
|
256
|
+
try:
|
|
257
|
+
from src.retrofit import get_adapters_catalog
|
|
258
|
+
catalog = get_adapters_catalog()
|
|
259
|
+
except Exception:
|
|
260
|
+
catalog = []
|
|
261
|
+
|
|
262
|
+
def _find_adapter(profile: str, provider: Optional[str]) -> Dict[str, Any]:
|
|
263
|
+
if provider:
|
|
264
|
+
for a in catalog:
|
|
265
|
+
if a.get("id") == f"{profile}/{provider}" and a.get("status") == "ready":
|
|
266
|
+
return a
|
|
267
|
+
for a in catalog:
|
|
268
|
+
if a.get("profile") == profile and a.get("status") == "ready":
|
|
269
|
+
return a
|
|
270
|
+
return {}
|
|
271
|
+
|
|
272
|
+
def _entry(profile: str, connected: Optional[Dict[str, Any]], detected: bool, provider: Optional[str] = None) -> Dict[str, Any]:
|
|
273
|
+
adapter = _find_adapter(profile, provider)
|
|
274
|
+
if connected:
|
|
275
|
+
state, health, detail = "ACTIVE", "healthy", f"Live runtime: {connected.get('name', 'unknown')}"
|
|
276
|
+
elif detected:
|
|
277
|
+
state, health, detail = "HANDSHAKE", "degraded", "Detected statically; runtime offline — hybrid static fallback active"
|
|
278
|
+
else:
|
|
279
|
+
state, health, detail = "DISCOVER", "unavailable", "Not detected in this workspace"
|
|
280
|
+
return {
|
|
281
|
+
"profile": profile,
|
|
282
|
+
"adapter": adapter.get("id", f"{profile}/unknown"),
|
|
283
|
+
"technology": adapter.get("technology"),
|
|
284
|
+
"capabilities": adapter.get("capabilities"),
|
|
285
|
+
"lifecycle": {"state": state, "health": {"status": health, "detail": detail}},
|
|
286
|
+
"security": {
|
|
287
|
+
"productionFailClosed": True,
|
|
288
|
+
"workspaceBoundary": True,
|
|
289
|
+
},
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
adapters.append(_entry("frontend", fe, fe_detected, (stack_info.get("frontend") or {}).get("provider")))
|
|
293
|
+
adapters.append(_entry("backend", be, be_detected, (stack_info.get("backend") or {}).get("provider")))
|
|
294
|
+
return adapters
|
|
295
|
+
|
|
246
296
|
# 2. Tool: oumv_observe
|
|
247
297
|
@classmethod
|
|
248
298
|
def observe(cls, level: str = "L0", target: Optional[str] = None, runtime: str = "auto") -> Any:
|
|
@@ -471,9 +521,47 @@ class OUMVGateway:
|
|
|
471
521
|
@classmethod
|
|
472
522
|
def verify(cls, target: str, action: str = "invoke", payload: Optional[dict] = None, runtime: str = "auto") -> Any:
|
|
473
523
|
url = cls._resolve_client_url(runtime=runtime, target=target)
|
|
474
|
-
|
|
524
|
+
res = cls._rpc_call(url, "oumv/verify", {
|
|
475
525
|
"target": target,
|
|
476
526
|
"componentId": target,
|
|
477
527
|
"action": action,
|
|
478
528
|
"payload": payload or {},
|
|
479
529
|
})
|
|
530
|
+
# Honest verification scope (spec §13): state exactly what was verified.
|
|
531
|
+
if isinstance(res, dict):
|
|
532
|
+
scope = res.setdefault("scope", {})
|
|
533
|
+
checked = scope.setdefault("checked", [])
|
|
534
|
+
checked_entry = "in-memory dispatch against live runtime"
|
|
535
|
+
if checked_entry not in checked:
|
|
536
|
+
checked.append(checked_entry)
|
|
537
|
+
scope.setdefault("notExecuted", [
|
|
538
|
+
"end-to-end browser flow",
|
|
539
|
+
"production behavior",
|
|
540
|
+
"full test suite",
|
|
541
|
+
])
|
|
542
|
+
return res
|
|
543
|
+
|
|
544
|
+
# 6. Tool: oumv_graph — unified cross-stack intelligence graph (spec §11)
|
|
545
|
+
@classmethod
|
|
546
|
+
def graph(cls, query: str = "overview", target: Optional[str] = None, workspace_dir: Optional[str] = None) -> Any:
|
|
547
|
+
"""Unified graph over static + runtime evidence, with §11.4-style queries."""
|
|
548
|
+
fe, be = cls.get_endpoints()
|
|
549
|
+
from src.cross_stack import build_unified_graph, who_depends_on, impact_from_graph
|
|
550
|
+
|
|
551
|
+
ws = workspace_dir or get_active_workspace()
|
|
552
|
+
|
|
553
|
+
q = (query or "overview").strip()
|
|
554
|
+
if q == "who_depends_on":
|
|
555
|
+
full = build_unified_graph(workspace_dir=ws, fe=fe, be=be, rpc_call=cls._rpc_call)
|
|
556
|
+
return who_depends_on(target or "", full)
|
|
557
|
+
if q == "impact":
|
|
558
|
+
full = build_unified_graph(workspace_dir=ws, fe=fe, be=be, rpc_call=cls._rpc_call)
|
|
559
|
+
return impact_from_graph(target or "", full)
|
|
560
|
+
|
|
561
|
+
g = build_unified_graph(workspace_dir=ws, fe=fe, be=be, rpc_call=cls._rpc_call)
|
|
562
|
+
if target:
|
|
563
|
+
t = target.lower()
|
|
564
|
+
g["nodes"] = [n for n in g["nodes"] if t in str(n).lower()][:50]
|
|
565
|
+
g["edges"] = [e for e in g["edges"] if t in (e["source"] + e["target"]).lower()][:50]
|
|
566
|
+
g["filteredBy"] = target
|
|
567
|
+
return g
|
package/src/retrofit.py
CHANGED
|
@@ -197,57 +197,130 @@ def generate_config(
|
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
200
|
-
"""Lists available OUMV adapters in the consolidated architecture.
|
|
200
|
+
"""Lists available OUMV adapters in the consolidated architecture.
|
|
201
|
+
|
|
202
|
+
Each entry follows the language-neutral OUMV Adapter Contract
|
|
203
|
+
(agent-oumv/schemas/adapter.json): identity, technology/package,
|
|
204
|
+
profiles, and baseline capabilities with constraints.
|
|
205
|
+
"""
|
|
201
206
|
return [
|
|
202
207
|
{
|
|
203
208
|
"id": "frontend/react",
|
|
204
209
|
"name": "React Adapter (Zustand, Redux, Context, useReducer)",
|
|
205
210
|
"profile": "frontend",
|
|
211
|
+
"profiles": ["frontend"],
|
|
206
212
|
"repo": "tokensafe-ui",
|
|
207
213
|
"mode": "hybrid",
|
|
208
214
|
"status": "ready",
|
|
209
215
|
"description": "Progressive AST component discovery + runtime action/state inspection",
|
|
216
|
+
"technology": {
|
|
217
|
+
"language": "typescript",
|
|
218
|
+
"framework": "react",
|
|
219
|
+
"package": {"manager": "npm", "name": "tokensafe-ui", "install": "npm install tokensafe-ui"},
|
|
220
|
+
},
|
|
221
|
+
"capabilities": [
|
|
222
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
223
|
+
{"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
224
|
+
{"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
225
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
226
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
227
|
+
],
|
|
210
228
|
},
|
|
211
229
|
{
|
|
212
230
|
"id": "frontend/solid",
|
|
213
231
|
"name": "SolidJS / TokenSafe UI Native Adapter",
|
|
214
232
|
"profile": "frontend",
|
|
233
|
+
"profiles": ["frontend"],
|
|
215
234
|
"repo": "tokensafe-ui",
|
|
216
235
|
"mode": "hybrid",
|
|
217
236
|
"status": "ready",
|
|
218
237
|
"description": "Fine-grained reactive signals causality + virtual DOM observer",
|
|
238
|
+
"technology": {
|
|
239
|
+
"language": "typescript",
|
|
240
|
+
"framework": "solidjs",
|
|
241
|
+
"package": {"manager": "npm", "name": "tokensafe-ui", "install": "npm install tokensafe-ui"},
|
|
242
|
+
},
|
|
243
|
+
"capabilities": [
|
|
244
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
245
|
+
{"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
246
|
+
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
247
|
+
{"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
248
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
249
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
250
|
+
],
|
|
219
251
|
},
|
|
220
252
|
{
|
|
221
253
|
"id": "frontend/vue",
|
|
222
254
|
"name": "Vue 3 Adapter (Composition API, Pinia)",
|
|
223
255
|
"profile": "frontend",
|
|
256
|
+
"profiles": ["frontend"],
|
|
224
257
|
"repo": "tokensafe-ui",
|
|
225
258
|
"mode": "hybrid",
|
|
226
259
|
"status": "ready",
|
|
227
260
|
"description": "Vue component hierarchy and store snapshot observer",
|
|
261
|
+
"technology": {
|
|
262
|
+
"language": "typescript",
|
|
263
|
+
"framework": "vue",
|
|
264
|
+
"package": {"manager": "npm", "name": "tokensafe-ui", "install": "npm install tokensafe-ui"},
|
|
265
|
+
},
|
|
266
|
+
"capabilities": [
|
|
267
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
268
|
+
{"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
269
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
270
|
+
],
|
|
228
271
|
},
|
|
229
272
|
{
|
|
230
273
|
"id": "backend/go",
|
|
231
274
|
"name": "Go Backend Adapter (Gin, Chi, net/http)",
|
|
232
275
|
"profile": "backend",
|
|
276
|
+
"profiles": ["backend"],
|
|
233
277
|
"repo": "tokensafe-backend/go",
|
|
234
278
|
"mode": "hybrid",
|
|
235
279
|
"status": "ready",
|
|
236
280
|
"description": "Go AST pre-flight compiler guard + transactional DB sandbox with rollback",
|
|
281
|
+
"technology": {
|
|
282
|
+
"language": "go",
|
|
283
|
+
"framework": "gin/chi/net-http",
|
|
284
|
+
"package": {
|
|
285
|
+
"manager": "go",
|
|
286
|
+
"name": "github.com/tokensafe-dev/tokensafe-backend/go",
|
|
287
|
+
"install": "go get github.com/tokensafe-dev/tokensafe-backend/go",
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
"capabilities": [
|
|
291
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
292
|
+
{"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
293
|
+
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": False, "limitations": ["requires observed request traces (TraceHandler or oumv/verify)"]}},
|
|
294
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
295
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
296
|
+
],
|
|
237
297
|
},
|
|
238
298
|
{
|
|
239
299
|
"id": "backend/fastapi",
|
|
240
300
|
"name": "Python FastAPI Adapter (Starlette, Pydantic)",
|
|
241
301
|
"profile": "backend",
|
|
302
|
+
"profiles": ["backend"],
|
|
242
303
|
"repo": "tokensafe-backend/python",
|
|
243
304
|
"mode": "hybrid",
|
|
244
305
|
"status": "ready",
|
|
245
306
|
"description": "FastAPI automatic route & schema introspection + SQLAlchemy dry-run sandbox",
|
|
307
|
+
"technology": {
|
|
308
|
+
"language": "python",
|
|
309
|
+
"framework": "fastapi",
|
|
310
|
+
"package": {"manager": "pip", "name": "tokensafe-python", "install": "pip install tokensafe-python"},
|
|
311
|
+
},
|
|
312
|
+
"capabilities": [
|
|
313
|
+
{"name": "observe.resources", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
314
|
+
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
315
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
316
|
+
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
317
|
+
],
|
|
246
318
|
},
|
|
247
319
|
{
|
|
248
320
|
"id": "backend/node",
|
|
249
321
|
"name": "Node.js Backend Adapter (Express, Fastify)",
|
|
250
322
|
"profile": "backend",
|
|
323
|
+
"profiles": ["backend"],
|
|
251
324
|
"repo": "tokensafe-backend/node",
|
|
252
325
|
"mode": "hybrid",
|
|
253
326
|
"status": "planned",
|
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.
|
|
252
|
+
"User-Agent": "TokenSafe-Sync/4.6.0"
|
|
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.
|
|
20
|
+
CURRENT_VERSION = "4.6.0"
|
|
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
|