tokensafe 4.7.12 → 4.7.14
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 +7 -3
- 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 -0
- package/src/__init__.py +1 -1
- package/src/auto_inject.py +133 -4
- package/src/batch_editor.py +40 -9
- package/src/graph_engine.py +298 -27
- package/src/mcp_server.py +102 -13
- package/src/oumv_gateway.py +149 -6
- package/src/retrofit.py +103 -13
- package/src/scoped_search.py +126 -0
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/src/retrofit.py
CHANGED
|
@@ -51,8 +51,19 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
|
|
|
51
51
|
|
|
52
52
|
has_vite = "vite" in deps
|
|
53
53
|
if "next" in deps:
|
|
54
|
-
#
|
|
55
|
-
|
|
54
|
+
# The App Router is served by the Node runtime as a Route Handler: there is
|
|
55
|
+
# no Vite dev server to patch, and the DOM bridge for client components is
|
|
56
|
+
# separate work. The server profile is what this adapter certifies.
|
|
57
|
+
fe_info.update({
|
|
58
|
+
"framework": "nextjs",
|
|
59
|
+
"provider": "node",
|
|
60
|
+
"profile": "backend",
|
|
61
|
+
"adapter": "tokensafe-backend-node/next",
|
|
62
|
+
"version": deps.get("next"),
|
|
63
|
+
"oumv_supported": True,
|
|
64
|
+
"status": "ready",
|
|
65
|
+
"note": "App Router Route Handler (server profile); client-component DOM bridge is not part of this adapter",
|
|
66
|
+
})
|
|
56
67
|
elif "react" in deps:
|
|
57
68
|
fe_info.update({"framework": "react", "provider": "react", "adapter": "tokensafe-ui/oumv/react", "version": deps.get("react"), "oumv_supported": has_vite, "status": "ready" if has_vite else "needs-vite"})
|
|
58
69
|
elif "vue" in deps:
|
|
@@ -77,18 +88,48 @@ def _detect_package_json_entry(pkg_json_path: str, rel_dir: str = ".") -> Tuple[
|
|
|
77
88
|
node_fw = "hono"
|
|
78
89
|
elif "koa" in deps:
|
|
79
90
|
node_fw = "koa"
|
|
91
|
+
elif "elysia" in deps:
|
|
92
|
+
node_fw = "elysia"
|
|
93
|
+
|
|
94
|
+
# Bun-only services (queue workers, cron jobs) declare no HTTP framework at
|
|
95
|
+
# all. They used to vanish from `packages` even though their manifest was
|
|
96
|
+
# listed in `detected_files`, so a monorepo looked fully covered when 4 of
|
|
97
|
+
# its 6 packages had no OUMV adapter.
|
|
98
|
+
pkg_dir = os.path.dirname(pkg_json_path)
|
|
99
|
+
bun_marker = (
|
|
100
|
+
any(key in deps for key in ("@types/bun", "bun-types", "elysia"))
|
|
101
|
+
or os.path.isfile(os.path.join(pkg_dir, "bun.lockb"))
|
|
102
|
+
or os.path.isfile(os.path.join(pkg_dir, "bun.lock"))
|
|
103
|
+
)
|
|
104
|
+
if bun_marker:
|
|
105
|
+
managers.append("bun")
|
|
80
106
|
|
|
81
107
|
if node_fw:
|
|
108
|
+
supported_fw = node_fw in ("express", "fastify")
|
|
82
109
|
be_out = {
|
|
83
110
|
"framework": node_fw,
|
|
84
|
-
"provider": "node",
|
|
85
|
-
"adapter": "tokensafe-backend/node",
|
|
86
|
-
"language": "node",
|
|
111
|
+
"provider": "bun" if node_fw == "elysia" else "node",
|
|
112
|
+
"adapter": None if node_fw == "elysia" else "tokensafe-backend/node",
|
|
113
|
+
"language": "bun" if node_fw == "elysia" else "node",
|
|
87
114
|
"root": rel_dir,
|
|
88
115
|
# Express/Fastify ship a certified adapter (npm tokensafe-backend-node);
|
|
89
|
-
# Nest/Hono/Koa do not yet.
|
|
90
|
-
"oumv_supported":
|
|
91
|
-
"status": "ready" if
|
|
116
|
+
# Elysia/Nest/Hono/Koa do not yet.
|
|
117
|
+
"oumv_supported": supported_fw,
|
|
118
|
+
"status": "ready" if supported_fw else "planned",
|
|
119
|
+
}
|
|
120
|
+
elif bun_marker and not fe_out:
|
|
121
|
+
# Bun runtime without a web framework: a worker/queue service, not a
|
|
122
|
+
# backend. A frontend package that merely uses Bun as its package
|
|
123
|
+
# manager is not a worker, so `fe_out` wins.
|
|
124
|
+
be_out = {
|
|
125
|
+
"framework": "bun",
|
|
126
|
+
"provider": "bun",
|
|
127
|
+
"adapter": None,
|
|
128
|
+
"language": "bun",
|
|
129
|
+
"root": rel_dir,
|
|
130
|
+
"role": "worker",
|
|
131
|
+
"oumv_supported": False,
|
|
132
|
+
"status": "planned",
|
|
92
133
|
}
|
|
93
134
|
|
|
94
135
|
if isinstance(pkg_data.get("workspaces"), (list, dict)):
|
|
@@ -156,7 +197,10 @@ def detect_project_stack(workspace_dir: str) -> Dict[str, Any]:
|
|
|
156
197
|
pkg_json_path = os.path.join(target_dir, "package.json")
|
|
157
198
|
if os.path.isfile(pkg_json_path):
|
|
158
199
|
_add_detected(os.path.relpath(pkg_json_path, workspace_dir))
|
|
159
|
-
fe_info, be_info,
|
|
200
|
+
fe_info, be_info, pkg_managers = _detect_package_json_entry(pkg_json_path, rel_dir=rel)
|
|
201
|
+
for manager in pkg_managers:
|
|
202
|
+
if manager not in stack["package_managers"]:
|
|
203
|
+
stack["package_managers"].append(manager)
|
|
160
204
|
if fe_info:
|
|
161
205
|
if not stack["frontend"]:
|
|
162
206
|
stack["frontend"] = fe_info
|
|
@@ -171,16 +215,33 @@ def detect_project_stack(workspace_dir: str) -> Dict[str, Any]:
|
|
|
171
215
|
"status": fe_info.get("status", "ready"),
|
|
172
216
|
})
|
|
173
217
|
if be_info:
|
|
174
|
-
|
|
218
|
+
role = be_info.get("role") or "backend"
|
|
219
|
+
if role == "backend" and not stack["backend"]:
|
|
175
220
|
stack["backend"] = be_info
|
|
176
|
-
|
|
177
|
-
"role":
|
|
221
|
+
entry = {
|
|
222
|
+
"role": role,
|
|
178
223
|
"path": rel,
|
|
179
224
|
"framework": be_info["framework"],
|
|
180
225
|
"provider": be_info["provider"],
|
|
181
226
|
"adapter": be_info["adapter"],
|
|
182
227
|
"oumvSupported": bool(be_info.get("oumv_supported", False)),
|
|
183
228
|
"status": be_info.get("status", "planned"),
|
|
229
|
+
}
|
|
230
|
+
if not entry["oumvSupported"]:
|
|
231
|
+
entry["reason"] = f"no OUMV adapter for {be_info['framework']} yet"
|
|
232
|
+
_add_package(entry)
|
|
233
|
+
if not fe_info and not be_info:
|
|
234
|
+
# Every manifest that was detected must also be accounted for: a
|
|
235
|
+
# package missing from `packages` reads as "not there", not "unsupported".
|
|
236
|
+
_add_package({
|
|
237
|
+
"role": "package",
|
|
238
|
+
"path": rel,
|
|
239
|
+
"framework": "node",
|
|
240
|
+
"provider": "node",
|
|
241
|
+
"adapter": None,
|
|
242
|
+
"oumvSupported": False,
|
|
243
|
+
"status": "unsupported",
|
|
244
|
+
"reason": "manifest present, but no supported frontend/backend framework was detected",
|
|
184
245
|
})
|
|
185
246
|
|
|
186
247
|
# Go Backend detection
|
|
@@ -618,6 +679,30 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
618
679
|
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
619
680
|
],
|
|
620
681
|
},
|
|
682
|
+
{
|
|
683
|
+
"id": "backend/next",
|
|
684
|
+
"name": "Next.js App Router Adapter (Route Handler, server profile)",
|
|
685
|
+
"profile": "backend",
|
|
686
|
+
"profiles": ["backend"],
|
|
687
|
+
"repo": "tokensafe-backend/node",
|
|
688
|
+
"mode": "hybrid",
|
|
689
|
+
"status": "ready",
|
|
690
|
+
"description": "App Router Route Handler (app/api/tokensafe/route.ts) serving JSON-RPC + SSE over the Node runtime; route surface read from app/**/route.{ts,tsx,js,jsx}, verify dispatched through an adopter-supplied Web handler; the client-component DOM bridge is separate work (certified Level 3)",
|
|
691
|
+
"technology": {
|
|
692
|
+
"language": "typescript",
|
|
693
|
+
"framework": "next (app router)",
|
|
694
|
+
"package": {"manager": "npm", "name": "tokensafe-backend-node", "install": "npm install --save-dev tokensafe-backend-node"},
|
|
695
|
+
},
|
|
696
|
+
"capabilities": [
|
|
697
|
+
{"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
698
|
+
{"name": "observe.surface", "constraints": {"readOnly": True, "developmentOnly": True, "note": "app/**/route.* scan"}},
|
|
699
|
+
{"name": "observe.source", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
700
|
+
{"name": "observe.traces", "constraints": {"readOnly": True, "developmentOnly": True, "note": "requires verifyFetch wiring"}},
|
|
701
|
+
{"name": "understand.impact", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
702
|
+
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": True, "requiresPermission": "permissions.mutate != false"}},
|
|
703
|
+
{"name": "verify.behavior", "constraints": {"readOnly": True, "developmentOnly": True, "note": "requires verifyFetch wiring"}},
|
|
704
|
+
],
|
|
705
|
+
},
|
|
621
706
|
{
|
|
622
707
|
"id": "backend/aspnetcore",
|
|
623
708
|
"name": "ASP.NET Core Adapter (minimal APIs, MVC controllers, EF Core)",
|
|
@@ -626,7 +711,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
626
711
|
"repo": "tokensafe-backend/dotnet",
|
|
627
712
|
"mode": "hybrid",
|
|
628
713
|
"status": "ready",
|
|
629
|
-
"description": "In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
|
|
714
|
+
"description": "In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, the full wire 1.6.0 surface (previewEdit, index, query, build, cancel), and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
|
|
630
715
|
"technology": {
|
|
631
716
|
"language": "csharp",
|
|
632
717
|
"framework": "aspnetcore",
|
|
@@ -641,6 +726,11 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
|
|
|
641
726
|
{"name": "observe.runtime_state", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
642
727
|
{"name": "understand.causality", "constraints": {"readOnly": True, "developmentOnly": False, "limitations": ["requires observed request traces (UseTokensafe middleware or oumv/verify)"]}},
|
|
643
728
|
{"name": "mutate.source", "constraints": {"readOnly": False, "developmentOnly": False, "requiresPermission": "permissions.mutate != false"}},
|
|
729
|
+
{"name": "mutate.preview", "constraints": {"readOnly": True, "developmentOnly": True, "requiresPermission": "permissions.mutate != false", "limitations": ["dry run of applyEdit's guard chain; nothing is written"]}},
|
|
730
|
+
{"name": "index.symbols", "constraints": {"readOnly": True, "developmentOnly": True}},
|
|
731
|
+
{"name": "observe.query", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["read-only SQL over the discovered DbContext; writes answer -32003"]}},
|
|
732
|
+
{"name": "verify.build", "constraints": {"readOnly": True, "developmentOnly": True, "limitations": ["OumvOptions.BuildCommand or params.command; honest skipped without one"]}},
|
|
733
|
+
{"name": "sessions.cancel", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
644
734
|
{"name": "verify.runtime_behavior", "constraints": {"readOnly": True, "developmentOnly": False}},
|
|
645
735
|
],
|
|
646
736
|
},
|
package/src/scoped_search.py
CHANGED
|
@@ -102,6 +102,73 @@ class ScopedSearch:
|
|
|
102
102
|
return per_file
|
|
103
103
|
return max(4, min(8, max_results // 3))
|
|
104
104
|
|
|
105
|
+
@classmethod
|
|
106
|
+
def _graph_symbol_index(cls, root_dir: str):
|
|
107
|
+
"""Cache-only view of the AST symbol index; never starts a repository crawl."""
|
|
108
|
+
try:
|
|
109
|
+
from src.graph_engine import CodeGraph
|
|
110
|
+
graph = CodeGraph(root_dir, use_disk_cache=True)
|
|
111
|
+
except Exception:
|
|
112
|
+
return None
|
|
113
|
+
return graph if graph.symbols else None
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def _symbol_matches(
|
|
117
|
+
cls,
|
|
118
|
+
query: str,
|
|
119
|
+
root_dir: str,
|
|
120
|
+
scope: str,
|
|
121
|
+
max_results: int,
|
|
122
|
+
per_file: int,
|
|
123
|
+
) -> Optional[List[Dict[str, Any]]]:
|
|
124
|
+
"""Exact declaration lookup across every indexed file.
|
|
125
|
+
|
|
126
|
+
An identifier query is a lookup, not a grep: the disk walk stops at a file
|
|
127
|
+
budget (2,500 by default) and therefore never reaches later packages, which
|
|
128
|
+
is why a symbol declared in `paidz-workers` answered "0 matches" while the
|
|
129
|
+
graph index held it. Returns None when this is not a symbol-shaped query or
|
|
130
|
+
no cache exists — the caller then falls back to the bounded disk scan.
|
|
131
|
+
"""
|
|
132
|
+
if not re.fullmatch(r"[A-Za-z_$][\w$]{2,}", query or ""):
|
|
133
|
+
return None
|
|
134
|
+
graph = cls._graph_symbol_index(root_dir)
|
|
135
|
+
if graph is None:
|
|
136
|
+
return None
|
|
137
|
+
q = query.lower()
|
|
138
|
+
suffix_ok = any(ch.isupper() for ch in query) or "_" in query
|
|
139
|
+
hits = []
|
|
140
|
+
for sym in graph.symbols.values():
|
|
141
|
+
name = sym.name.lower()
|
|
142
|
+
if name == q:
|
|
143
|
+
rank = 0
|
|
144
|
+
elif suffix_ok and name.endswith(q):
|
|
145
|
+
rank = 1
|
|
146
|
+
else:
|
|
147
|
+
continue
|
|
148
|
+
if not cls.is_match_file(os.path.basename(sym.file_path), sym.file_path, scope):
|
|
149
|
+
continue
|
|
150
|
+
hits.append((rank, sym))
|
|
151
|
+
if not hits:
|
|
152
|
+
return None
|
|
153
|
+
hits.sort(key=lambda item: (item[0], item[1].file_path, item[1].line_start))
|
|
154
|
+
per_file_cap = cls._resolve_per_file(per_file, max_results)
|
|
155
|
+
per_file_counts: Dict[str, int] = {}
|
|
156
|
+
matches: List[Dict[str, Any]] = []
|
|
157
|
+
for _, sym in hits:
|
|
158
|
+
if len(matches) >= max_results:
|
|
159
|
+
break
|
|
160
|
+
seen = per_file_counts.get(sym.file_path, 0)
|
|
161
|
+
if seen >= per_file_cap:
|
|
162
|
+
continue
|
|
163
|
+
per_file_counts[sym.file_path] = seen + 1
|
|
164
|
+
text = f"{sym.kind} {sym.name}"
|
|
165
|
+
if sym.signature:
|
|
166
|
+
text += f" — {sym.signature}"
|
|
167
|
+
if len(text) > 100:
|
|
168
|
+
text = text[:97] + "..."
|
|
169
|
+
matches.append({"file": sym.file_path, "line": sym.line_start, "text": text})
|
|
170
|
+
return matches
|
|
171
|
+
|
|
105
172
|
@classmethod
|
|
106
173
|
def search(
|
|
107
174
|
cls,
|
|
@@ -214,12 +281,14 @@ class ScopedSearch:
|
|
|
214
281
|
"success": True,
|
|
215
282
|
"query": query,
|
|
216
283
|
"scope": scope,
|
|
284
|
+
"source": "fts_trigram",
|
|
217
285
|
"files_matched": len(fts_hit_files),
|
|
218
286
|
"scanned_files": len(fts_hit_files),
|
|
219
287
|
"total_matches": len(fts_matches),
|
|
220
288
|
"overflow_matches": sum(overflow.values()),
|
|
221
289
|
"per_file_cap": per_file_cap,
|
|
222
290
|
"timed_out": False,
|
|
291
|
+
"partial": False,
|
|
223
292
|
"matches": fts_matches,
|
|
224
293
|
"markdown": cls._render_markdown(
|
|
225
294
|
query, fts_matches, len(fts_hit_files), False, max_results,
|
|
@@ -230,6 +299,44 @@ class ScopedSearch:
|
|
|
230
299
|
except Exception:
|
|
231
300
|
pass # Seamless fallback to disk scan
|
|
232
301
|
|
|
302
|
+
# Symbol fast path: an identifier is a lookup, and the AST index covers every
|
|
303
|
+
# file while the bounded disk walk below covers only the first 2,500.
|
|
304
|
+
if not regex_mode and not case_sensitive:
|
|
305
|
+
symbol_matches = cls._symbol_matches(query, root_dir, scope, max_results, per_file)
|
|
306
|
+
if symbol_matches is not None:
|
|
307
|
+
hit_files = {m["file"] for m in symbol_matches}
|
|
308
|
+
indexed = 0
|
|
309
|
+
try:
|
|
310
|
+
graph = cls._graph_symbol_index(root_dir)
|
|
311
|
+
indexed = len(graph.file_symbols) if graph else 0
|
|
312
|
+
except Exception:
|
|
313
|
+
indexed = 0
|
|
314
|
+
markdown = cls._render_markdown(
|
|
315
|
+
query, symbol_matches, indexed or len(hit_files), False, max_results,
|
|
316
|
+
hit_files=hit_files, scope=scope, root_dir=root_dir,
|
|
317
|
+
)
|
|
318
|
+
if indexed:
|
|
319
|
+
markdown += (
|
|
320
|
+
f"\n_Answered from the AST symbol index ({indexed} indexed files): "
|
|
321
|
+
f"declarations only, complete across the repository._"
|
|
322
|
+
)
|
|
323
|
+
return {
|
|
324
|
+
"success": True,
|
|
325
|
+
"query": query,
|
|
326
|
+
"scope": scope,
|
|
327
|
+
"source": "graph_symbol_index",
|
|
328
|
+
"files_matched": len(hit_files),
|
|
329
|
+
"scanned_files": indexed or len(hit_files),
|
|
330
|
+
"total_matches": len(symbol_matches),
|
|
331
|
+
"overflow_matches": 0,
|
|
332
|
+
"per_file_cap": cls._resolve_per_file(per_file, max_results),
|
|
333
|
+
"timed_out": False,
|
|
334
|
+
"partial": False,
|
|
335
|
+
"matches": symbol_matches,
|
|
336
|
+
"markdown": markdown,
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
233
340
|
matches: List[Dict[str, Any]] = []
|
|
234
341
|
total_scanned_files = 0
|
|
235
342
|
hit_files = set()
|
|
@@ -330,16 +437,35 @@ class ScopedSearch:
|
|
|
330
437
|
per_file_cap=per_file_cap,
|
|
331
438
|
)
|
|
332
439
|
|
|
440
|
+
partial = bool(timed_out or total_scanned_files >= max_scanned_files)
|
|
441
|
+
if partial and not matches:
|
|
442
|
+
markdown += (
|
|
443
|
+
"\n_Scan stopped at its safety budget, so coverage was partial: the match may live "
|
|
444
|
+
"in a file that was not reached. Narrow 'path'/'project_path' for an exhaustive scan._"
|
|
445
|
+
)
|
|
446
|
+
if re.fullmatch(r"[A-Za-z_$][\w$]{2,}", query or ""):
|
|
447
|
+
markdown += (
|
|
448
|
+
f"\n_Declaration lookup: `oumv(action='index', query='{query}')` searches the complete "
|
|
449
|
+
"AST symbol index instead of the bounded disk walk._"
|
|
450
|
+
)
|
|
451
|
+
|
|
333
452
|
return {
|
|
334
453
|
"success": True,
|
|
335
454
|
"query": query,
|
|
336
455
|
"scope": scope,
|
|
456
|
+
"source": "disk_scan",
|
|
337
457
|
"total_matches": len(matches),
|
|
338
458
|
"overflow_matches": sum(overflow.values()),
|
|
339
459
|
"per_file_cap": per_file_cap,
|
|
340
460
|
"files_matched": len(hit_files),
|
|
341
461
|
"scanned_files": total_scanned_files,
|
|
342
462
|
"timed_out": timed_out,
|
|
463
|
+
"partial": partial,
|
|
464
|
+
"coverage": {
|
|
465
|
+
"file_budget": max_scanned_files,
|
|
466
|
+
"time_budget_seconds": timeout_seconds,
|
|
467
|
+
"stopped_early": partial,
|
|
468
|
+
},
|
|
343
469
|
"matches": matches,
|
|
344
470
|
"markdown": markdown,
|
|
345
471
|
}
|
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.14"
|
|
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.14"
|
|
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
|