tokensafe 4.13.2 → 4.14.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/README.md +12 -2
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/adapter_core.py +1 -1
- package/src/atomic_io.py +74 -0
- package/src/auto_inject.py +42 -3
- package/src/backend_release.py +3 -3
- package/src/batch_editor.py +2 -14
- package/src/cache_normalizer.py +1 -1
- package/src/cli.py +4 -0
- package/src/graph_engine.py +19 -0
- package/src/installer.py +4 -4
- package/src/mcp_server.py +124 -38
- package/src/oumv_gateway.py +221 -6
- package/src/retrofit.py +13 -7
- package/src/scoped_search.py +15 -7
- package/src/session_brief.py +171 -78
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/src/session_brief.py
CHANGED
|
@@ -43,34 +43,88 @@ _FRONTEND_LINES = {
|
|
|
43
43
|
"tokensafe:oumv(action='observe', level='L1') before reading files; run "
|
|
44
44
|
"`tokensafe dev --framework vue` if no runtime is live."
|
|
45
45
|
),
|
|
46
|
+
"nextjs": (
|
|
47
|
+
"frontend {provider}/{framework}: OUMV via `tokensafe inject` (App Router handler + browser "
|
|
48
|
+
"bridge, three generated files) or `tokensafe dev` for live browser RPC. Call "
|
|
49
|
+
"tokensafe:oumv(action='observe', level='L1') before reading files."
|
|
50
|
+
),
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
_NODE_MOUNT_LINE = (
|
|
54
|
+
"backend {provider}/{framework}: install `tokensafe-backend-node` and mount it "
|
|
55
|
+
"(`mountTokensafe(app)` for Express, `registerTokensafe(app)` for Fastify); "
|
|
56
|
+
"then use tokensafe:oumv for endpoints/impact and oumv_verify for live checks."
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Keyed by FRAMEWORK, not provider: the provider says which package ships the
|
|
60
|
+
# adapter; the framework says how it mounts. Flask/Django are WSGI and need an
|
|
61
|
+
# explicit mount (certified, but `tokensafe inject` cannot patch a WSGI host).
|
|
48
62
|
_BACKEND_LINES = {
|
|
49
63
|
"fastapi": (
|
|
50
64
|
"backend fastapi/fastapi: OUMV auto-mounts when the dev server runs through "
|
|
51
65
|
"`tokensafe run-backend uvicorn <module:app> --reload` (RPC at /__oumv/rpc). "
|
|
52
66
|
"Prefer tokensafe:oumv(action='observe'|'understand'|'mutate'|'verify') over grep/curl."
|
|
53
67
|
),
|
|
54
|
-
"
|
|
55
|
-
"backend {provider}/{framework}: OUMV mounts
|
|
56
|
-
"
|
|
57
|
-
"
|
|
68
|
+
"starlette": (
|
|
69
|
+
"backend {provider}/{framework}: OUMV auto-mounts via `tokensafe run-backend uvicorn "
|
|
70
|
+
"<module:app> --reload` (the same mount_tokensafe detects a plain-ASGI host; "
|
|
71
|
+
"mount_tokensafe_starlette is the explicit alias). Prefer tokensafe:oumv over grep/curl."
|
|
58
72
|
),
|
|
59
|
-
"
|
|
60
|
-
"backend
|
|
61
|
-
"
|
|
62
|
-
"
|
|
73
|
+
"flask": (
|
|
74
|
+
"backend {provider}/{framework} (WSGI, manual): mount explicitly in the app factory — "
|
|
75
|
+
"`from tokensafe_python.adapters.flask import mount_tokensafe; mount_tokensafe(app)` "
|
|
76
|
+
"(wraps app.wsgi_app); `tokensafe inject` cannot patch a WSGI host. Then use "
|
|
77
|
+
"tokensafe:oumv for endpoints/impact and oumv_verify."
|
|
63
78
|
),
|
|
64
|
-
"
|
|
65
|
-
"backend
|
|
66
|
-
"
|
|
67
|
-
"
|
|
79
|
+
"django": (
|
|
80
|
+
"backend {provider}/{framework} (WSGI, manual): mount explicitly in wsgi.py — "
|
|
81
|
+
"`from tokensafe_python.adapters.django import mount_tokensafe; "
|
|
82
|
+
"application = mount_tokensafe(application)`; `tokensafe inject` cannot patch a WSGI "
|
|
83
|
+
"host. Then use tokensafe:oumv for endpoints/impact and oumv_verify."
|
|
68
84
|
),
|
|
85
|
+
"express": _NODE_MOUNT_LINE,
|
|
86
|
+
"fastify": _NODE_MOUNT_LINE,
|
|
69
87
|
"elysia": (
|
|
70
88
|
"backend elysia/{framework} (Bun): install `tokensafe-backend-node` and add "
|
|
71
89
|
"`app.use(require('tokensafe-backend-node/elysia').oumv())` before `app.listen()`; "
|
|
72
90
|
"then use tokensafe:oumv for endpoints/impact and oumv_verify for live checks."
|
|
73
91
|
),
|
|
92
|
+
"gin": (
|
|
93
|
+
"backend {provider}/{framework}: OUMV mounts with one AutoMount line "
|
|
94
|
+
"(`tokensafe inject`, reversible; discovery included). Use tokensafe:oumv for "
|
|
95
|
+
"endpoints/source/impact, oumv_verify for in-process checks."
|
|
96
|
+
),
|
|
97
|
+
"chi": (
|
|
98
|
+
"backend {provider}/{framework}: OUMV mounts with one AutoMount line "
|
|
99
|
+
"(`tokensafe inject`, reversible; discovery included). Use tokensafe:oumv for "
|
|
100
|
+
"endpoints/source/impact, oumv_verify for in-process checks."
|
|
101
|
+
),
|
|
102
|
+
"net/http": (
|
|
103
|
+
"backend {provider}/{framework} (manual): replace `http.NewServeMux()` with "
|
|
104
|
+
"`rt := oumv.NewRuntime(...)` + `mux := oumvstdhttp.NewServeMux(rt)` + "
|
|
105
|
+
"`mux.Mount(\"/__oumv/rpc\")`; `tokensafe inject --status` prints the exact recipe. "
|
|
106
|
+
"Then use tokensafe:oumv and oumv_verify."
|
|
107
|
+
),
|
|
108
|
+
"spring": (
|
|
109
|
+
"backend {provider}/{framework} (Java): `tokensafe inject` caches the single-file "
|
|
110
|
+
"OumvSpring sidecar (nothing in the repo); run it via `tokensafe run-backend "
|
|
111
|
+
"--app-url <url>`; then use tokensafe:oumv and oumv_verify."
|
|
112
|
+
),
|
|
113
|
+
"laravel": (
|
|
114
|
+
"backend {provider}/{framework} (PHP): `tokensafe inject` caches the content-addressed "
|
|
115
|
+
"`oumv-php` sidecar (nothing in the repo); run it via `tokensafe run-backend "
|
|
116
|
+
"--app-url <url>`; then use tokensafe:oumv and oumv_verify."
|
|
117
|
+
),
|
|
118
|
+
"symfony": (
|
|
119
|
+
"backend {provider}/{framework} (PHP): `tokensafe inject` caches the content-addressed "
|
|
120
|
+
"`oumv-php` sidecar (nothing in the repo); run it via `tokensafe run-backend "
|
|
121
|
+
"--app-url <url>`; then use tokensafe:oumv and oumv_verify."
|
|
122
|
+
),
|
|
123
|
+
"aspnetcore": (
|
|
124
|
+
"backend {provider}/{framework}: `tokensafe inject` adds one reversible "
|
|
125
|
+
"`AddTokensafe()`/`UseTokensafe()` pair plus the TokenSafe.Oumv.AspNetCore "
|
|
126
|
+
"PackageReference; then use tokensafe:oumv and oumv_verify."
|
|
127
|
+
),
|
|
74
128
|
}
|
|
75
129
|
|
|
76
130
|
|
|
@@ -134,28 +188,47 @@ def _profile_supported(kind: str, entry: Dict[str, Any]) -> bool:
|
|
|
134
188
|
if isinstance(flag, bool):
|
|
135
189
|
return flag
|
|
136
190
|
table = _FRONTEND_LINES if kind == "frontend" else _BACKEND_LINES
|
|
137
|
-
template = table.get(str(entry.get("provider") or ""))
|
|
191
|
+
template = table.get(str(entry.get("framework") or entry.get("provider") or ""))
|
|
138
192
|
return bool(template) and "no OUMV adapter" not in template
|
|
139
193
|
|
|
140
194
|
|
|
195
|
+
def _routing_line(kind: str, entry: Dict[str, Any]) -> str:
|
|
196
|
+
"""One brief line for a detected profile — template, generic ready, or honest planned."""
|
|
197
|
+
provider = str(entry.get("provider") or "")
|
|
198
|
+
framework = str(entry.get("framework") or provider)
|
|
199
|
+
supported = _profile_supported(kind, entry)
|
|
200
|
+
table = _FRONTEND_LINES if kind == "frontend" else _BACKEND_LINES
|
|
201
|
+
template = table.get(framework) if supported else None
|
|
202
|
+
if template:
|
|
203
|
+
return "- " + template.format(provider=provider, framework=framework)
|
|
204
|
+
if supported:
|
|
205
|
+
adapter = str(entry.get("adapter") or "")
|
|
206
|
+
via = f" via {adapter}" if adapter else ""
|
|
207
|
+
live = "; start live bridge via `tokensafe dev`" if entry.get("vite") else ""
|
|
208
|
+
return (
|
|
209
|
+
f"- {kind} {provider}/{framework}: OUMV ready{via}{live}; call "
|
|
210
|
+
"tokensafe:oumv(action='status'|'observe'|'mutate') before reading files."
|
|
211
|
+
)
|
|
212
|
+
return (
|
|
213
|
+
f"- {provider}/{framework}: OUMV has no adapter yet — use "
|
|
214
|
+
"tokensafe:repo_map / scoped_search / smart_read_file instead of oumv."
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
141
218
|
def _stack_labels(stack: Dict[str, Any]) -> List[tuple]:
|
|
142
219
|
"""(kind, provider, framework, supported, adapter) per detected profile.
|
|
143
220
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
221
|
+
The detector's ``oumv_supported`` flag is authoritative; a routing template
|
|
222
|
+
only decides the wording, never whether a stack is supported (a template for
|
|
223
|
+
``python`` must not turn Flask or Django into "ready")."""
|
|
147
224
|
labels: List[tuple] = []
|
|
148
|
-
for kind
|
|
225
|
+
for kind in ("frontend", "backend"):
|
|
149
226
|
entry = stack.get(kind) or {}
|
|
150
227
|
provider = str(entry.get("provider") or "")
|
|
151
228
|
if not provider:
|
|
152
229
|
continue
|
|
153
230
|
framework = str(entry.get("framework") or provider)
|
|
154
|
-
|
|
155
|
-
if template is not None:
|
|
156
|
-
supported = "no OUMV adapter" not in template
|
|
157
|
-
else:
|
|
158
|
-
supported = _profile_supported(kind, entry)
|
|
231
|
+
supported = _profile_supported(kind, entry)
|
|
159
232
|
labels.append((kind, provider, framework, supported, str(entry.get("adapter") or "")))
|
|
160
233
|
return labels
|
|
161
234
|
|
|
@@ -218,14 +291,28 @@ def _activation(workspace: str, stack: Dict[str, Any]) -> List[str]:
|
|
|
218
291
|
for profile, item in readiness.items():
|
|
219
292
|
if item.get("ready"):
|
|
220
293
|
continue
|
|
294
|
+
framework = str(item.get("framework") or "")
|
|
221
295
|
if not item.get("supported", True):
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
296
|
+
# The routing line already says "no adapter yet"; repeating it here
|
|
297
|
+
# only burns brief budget.
|
|
298
|
+
continue
|
|
299
|
+
if item.get("status") == "manual":
|
|
300
|
+
# The routing line carries the exact mount recipe; add only the
|
|
301
|
+
# missing install step (net/http needs the go get, not a patch).
|
|
302
|
+
if framework in ("flask", "django"):
|
|
303
|
+
hints.append(
|
|
304
|
+
'activate backend (manual WSGI): `pip install "tokensafe-backend-python @ '
|
|
305
|
+
'git+https://github.com/tokensafe-dev/tokensafe-backend.git#subdirectory=python"`'
|
|
306
|
+
)
|
|
307
|
+
elif framework == "net/http":
|
|
308
|
+
hints.append(
|
|
309
|
+
f"activate backend: `go get github.com/tokensafe-dev/tokensafe-backend/go@{BACKEND_RELEASE_TAG}` "
|
|
310
|
+
"then `tokensafe inject --status` prints the mux recipe (no auto-patch)"
|
|
311
|
+
)
|
|
312
|
+
continue
|
|
313
|
+
if profile == "frontend":
|
|
227
314
|
hints.append("activate frontend: run `tokensafe dev` (installs nothing into the repo)")
|
|
228
|
-
elif
|
|
315
|
+
elif framework in ("fastapi", "starlette"):
|
|
229
316
|
hints.append('activate backend: `pip install "tokensafe-backend-python @ git+https://github.com/tokensafe-dev/tokensafe-backend.git#subdirectory=python"` then run the server via `tokensafe run-backend ...`')
|
|
230
317
|
elif item.get("provider") == "go":
|
|
231
318
|
hints.append(
|
|
@@ -237,6 +324,35 @@ def _activation(workspace: str, stack: Dict[str, Any]) -> List[str]:
|
|
|
237
324
|
return hints
|
|
238
325
|
|
|
239
326
|
|
|
327
|
+
def _truncate_by_rank(entries: List[tuple], max_chars: int) -> str:
|
|
328
|
+
"""Join brief lines, dropping the least important first until they fit.
|
|
329
|
+
|
|
330
|
+
The old tail-cut could remove the backend verdict (or a whole extra-root
|
|
331
|
+
line) because it only knew string order. Rank order keeps the title and the
|
|
332
|
+
backend/frontend verdicts whenever the limit allows them at all.
|
|
333
|
+
"""
|
|
334
|
+
if not entries:
|
|
335
|
+
return ""
|
|
336
|
+
total = sum(len(line) + 1 for _, line in entries) - 1
|
|
337
|
+
if total <= max_chars:
|
|
338
|
+
return "\n".join(line for _, line in entries)
|
|
339
|
+
keep = [True] * len(entries)
|
|
340
|
+
dropped = False
|
|
341
|
+
# Drop the highest rank first; among equals, the later line goes first.
|
|
342
|
+
for idx in sorted(range(len(entries)), key=lambda i: (entries[i][0], i), reverse=True):
|
|
343
|
+
if total <= max_chars - 2:
|
|
344
|
+
break
|
|
345
|
+
keep[idx] = False
|
|
346
|
+
dropped = True
|
|
347
|
+
total -= len(entries[idx][1]) + 1
|
|
348
|
+
brief = "\n".join(line for idx, (_, line) in enumerate(entries) if keep[idx])
|
|
349
|
+
if dropped:
|
|
350
|
+
brief += "\n…"
|
|
351
|
+
if len(brief) > max_chars:
|
|
352
|
+
brief = brief[: max_chars - 1].rstrip() + "…"
|
|
353
|
+
return brief
|
|
354
|
+
|
|
355
|
+
|
|
240
356
|
def build_workspace_brief(
|
|
241
357
|
workspace: Optional[str] = None,
|
|
242
358
|
include_live: bool = False,
|
|
@@ -269,55 +385,39 @@ def build_workspace_brief(
|
|
|
269
385
|
seen = {os.path.realpath(workspace)}
|
|
270
386
|
extra_lines = _extra_root_lines(extra_workspaces or [], seen)
|
|
271
387
|
|
|
272
|
-
|
|
388
|
+
# (rank, line) — lower rank is more important. Truncation drops the least
|
|
389
|
+
# important lines first, so the backend verdict can never be cut away while
|
|
390
|
+
# string-catalog hints survive. Output order stays as inserted.
|
|
391
|
+
entries: List[tuple] = [(0, "[TokenSafe OUMV routing brief]")]
|
|
273
392
|
if extra_lines:
|
|
274
|
-
|
|
393
|
+
entries.append((
|
|
394
|
+
2,
|
|
275
395
|
"- scope: per-root verdicts below; for any unlisted repo call "
|
|
276
|
-
"tokensafe:oumv(action='status', workspace_dir='<repo>')."
|
|
277
|
-
)
|
|
396
|
+
"tokensafe:oumv(action='status', workspace_dir='<repo>').",
|
|
397
|
+
))
|
|
278
398
|
else:
|
|
279
|
-
|
|
399
|
+
entries.append((
|
|
400
|
+
2,
|
|
280
401
|
"- scope: this verdict covers this root only; before editing another repo call "
|
|
281
|
-
"tokensafe:oumv(action='status', workspace_dir='<repo>')."
|
|
282
|
-
)
|
|
402
|
+
"tokensafe:oumv(action='status', workspace_dir='<repo>').",
|
|
403
|
+
))
|
|
283
404
|
for kind, entry in (("frontend", frontend), ("backend", backend)):
|
|
284
|
-
if
|
|
285
|
-
|
|
286
|
-
provider = str(entry.get("provider") or "")
|
|
287
|
-
framework = str(entry.get("framework") or provider)
|
|
288
|
-
supported = _profile_supported(kind, entry)
|
|
289
|
-
table = _FRONTEND_LINES if kind == "frontend" else _BACKEND_LINES
|
|
290
|
-
template = table.get(provider)
|
|
291
|
-
if template:
|
|
292
|
-
lines.append("- " + template.format(provider=provider, framework=framework))
|
|
293
|
-
elif _profile_supported(kind, entry):
|
|
294
|
-
# Provider without a routing template (e.g. Solid) but with a
|
|
295
|
-
# runtime-reported adapter: route through OUMV instead of greps.
|
|
296
|
-
adapter = str(entry.get("adapter") or "")
|
|
297
|
-
via = f" via {adapter}" if adapter else ""
|
|
298
|
-
live = "; start live bridge via `tokensafe dev`" if entry.get("vite") else ""
|
|
299
|
-
lines.append(
|
|
300
|
-
f"- {kind} {provider}/{framework}: OUMV ready{via}{live}; call "
|
|
301
|
-
"tokensafe:oumv(action='status'|'observe'|'mutate') before reading files."
|
|
302
|
-
)
|
|
303
|
-
else:
|
|
304
|
-
lines.append(
|
|
305
|
-
f"- {provider}/{framework}: OUMV has no adapter yet — use "
|
|
306
|
-
"tokensafe:repo_map / scoped_search / smart_read_file instead of oumv."
|
|
307
|
-
)
|
|
405
|
+
if entry:
|
|
406
|
+
entries.append((1 if kind == "backend" else 3, _routing_line(kind, entry)))
|
|
308
407
|
|
|
309
408
|
if extra_lines:
|
|
310
|
-
|
|
311
|
-
|
|
409
|
+
entries.append((5, "- other workspace roots:"))
|
|
410
|
+
entries.extend((6, line) for line in extra_lines)
|
|
312
411
|
|
|
313
412
|
permissions = _read_permissions(workspace)
|
|
314
413
|
if permissions:
|
|
315
414
|
mutate = permissions.get("mutate", True)
|
|
316
|
-
|
|
415
|
+
entries.append((
|
|
416
|
+
4,
|
|
317
417
|
"- mutations: "
|
|
318
418
|
+ ("enabled with guardrails (OCC version, path jail, syntax pre-flight, backups)"
|
|
319
|
-
if mutate else "disabled by .tokensafe/oumv.json (permissions.mutate=false)")
|
|
320
|
-
)
|
|
419
|
+
if mutate else "disabled by .tokensafe/oumv.json (permissions.mutate=false)"),
|
|
420
|
+
))
|
|
321
421
|
|
|
322
422
|
if include_live:
|
|
323
423
|
try:
|
|
@@ -329,32 +429,25 @@ def build_workspace_brief(
|
|
|
329
429
|
if item.get("url") or item.get("status") in ("OK", "LIVE"):
|
|
330
430
|
live.append(f"{profile}={item.get('url') or item.get('name', 'live')}")
|
|
331
431
|
if live:
|
|
332
|
-
|
|
432
|
+
entries.append((7, "- live runtimes: " + ", ".join(live) + " — inspect/verify via OUMV first"))
|
|
333
433
|
except Exception:
|
|
334
434
|
pass
|
|
335
435
|
|
|
336
436
|
hints = _activation(workspace, stack)
|
|
337
437
|
if hints:
|
|
338
|
-
|
|
438
|
+
entries.append((8, "- " + "; ".join(hints)))
|
|
339
439
|
|
|
340
440
|
# String catalogs: only mention `dict` where a catalog actually exists, so
|
|
341
441
|
# projects without i18n never pay for the line.
|
|
342
442
|
try:
|
|
343
443
|
from src.i18n_catalog import resolve_messages_dir
|
|
344
444
|
if resolve_messages_dir(workspace):
|
|
345
|
-
|
|
445
|
+
entries.append((
|
|
446
|
+
9,
|
|
346
447
|
"- string catalogs: review and patch via `tokensafe dict lint --locale <l>` then "
|
|
347
|
-
"`dict apply` — never read whole messages/*/*.ts files (smart_read_file returns a digest)"
|
|
348
|
-
)
|
|
448
|
+
"`dict apply` — never read whole messages/*/*.ts files (smart_read_file returns a digest)",
|
|
449
|
+
))
|
|
349
450
|
except Exception:
|
|
350
451
|
pass
|
|
351
452
|
|
|
352
|
-
|
|
353
|
-
if len(brief) > max_chars:
|
|
354
|
-
# Cut on a line boundary: a half-written path in a truncated root line
|
|
355
|
-
# is worse than a dropped tail line (the scope sentence stays at the top).
|
|
356
|
-
cut = brief[: max_chars - 1]
|
|
357
|
-
if "\n" in cut:
|
|
358
|
-
cut = cut.rsplit("\n", 1)[0]
|
|
359
|
-
brief = cut.rstrip() + "…"
|
|
360
|
-
return brief
|
|
453
|
+
return _truncate_by_rank(entries, max_chars)
|
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.
|
|
314
|
+
"User-Agent": "TokenSafe-Sync/4.14.0"
|
|
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.
|
|
20
|
+
CURRENT_VERSION = "4.14.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
|