tokensafe 4.12.4 → 4.13.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/README.md +8 -6
- package/hooks/pre_invocation.py +8 -4
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +4 -3
- package/server.json +3 -3
- package/src/auto_inject.py +1070 -283
- package/src/backend_release.py +10 -0
- package/src/batch_editor.py +18 -8
- package/src/batch_search.py +39 -16
- package/src/bundle_probe.py +205 -0
- package/src/cli.py +76 -7
- package/src/fts_index.py +9 -0
- package/src/globmatch.py +124 -0
- package/src/governor.py +120 -44
- package/src/graph_engine.py +292 -14
- package/src/installer.py +3 -3
- package/src/mcp_server.py +153 -35
- package/src/metrics.py +7 -0
- package/src/oumv_brief.py +346 -0
- package/src/oumv_gateway.py +132 -43
- package/src/quality_score.py +46 -24
- package/src/retrofit.py +35 -11
- package/src/savings.py +1 -0
- package/src/scoped_search.py +238 -9
- package/src/session_brief.py +6 -1
- package/src/telemetry_sync.py +1 -1
- package/src/treesitter_backend.py +26 -1
- package/src/version_checker.py +1 -1
- package/src/web_reader.py +42 -0
- package/src/workspace_roots.py +246 -0
package/README.md
CHANGED
|
@@ -215,21 +215,23 @@ Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live
|
|
|
215
215
|
|
|
216
216
|
You install TokenSafe, open a project in your agent, and the first turn does the wiring:
|
|
217
217
|
|
|
218
|
-
1. **Detect** the stack (React/Vue/Solid/Angular + Vite, FastAPI, Flask, Django, Go/Gin|Chi, Node/Express|Fastify, Next.js, Elysia on Bun, ASP.NET Core, Spring, Laravel/Symfony, or nothing supported).
|
|
218
|
+
1. **Detect** the stack (React/Vue/Solid/Angular + Vite, FastAPI, Flask, Django, Go/Gin|Chi, Node/Express|Fastify, Next.js, Elysia on Bun, ASP.NET Core, Spring, Laravel/Symfony, or nothing supported) — every supported app in a monorepo, not just the first.
|
|
219
219
|
2. **Activate** the adapters:
|
|
220
220
|
* frontend — `tokensafe dev` serves OUMV from an inline Vite config; **no file in the
|
|
221
221
|
repository changes**;
|
|
222
222
|
* FastAPI — a global `~/.tokensafe/pyhooks/sitecustomize.py` mounts `mount_tokensafe(app)`
|
|
223
223
|
when the server runs through `tokensafe run-backend uvicorn ...`;
|
|
224
224
|
* Go — one `AutoMount()` line between `tokensafe:oumv` markers, byte-exact backup in
|
|
225
|
-
`~/.tokensafe/inject/`, `go build` validated
|
|
225
|
+
`~/.tokensafe/inject/`, `go build` validated; `--revert` restores the entrypoint and
|
|
226
|
+
`go.mod`/`go.sum` when they were not edited after inject (net/http gets a printed
|
|
227
|
+
manual recipe instead, and Echo is reported as planned);
|
|
226
228
|
* Node (Express/Fastify) — one `mountTokensafe(app)` / `registerTokensafe(app)` line, same
|
|
227
229
|
markers and byte-exact revert; ASP.NET Core — one `AddTokensafe()`/`UseTokensafe()` pair;
|
|
228
230
|
* Next.js (App Router) — three generated files: `app/api/tokensafe/route.ts`
|
|
229
231
|
(`createNextRouteHandlers`, bridge on), `app/api/tokensafe/bridge/route.ts` (the
|
|
230
232
|
browser bridge) and `instrumentation-client.ts` (`installNextBridge`, Next ≥ 15.3);
|
|
231
233
|
older Next gets the two route files plus a manual snippet. `--revert` deletes
|
|
232
|
-
exactly the files it created;
|
|
234
|
+
exactly the files it created and restores a pre-existing v1 route it upgraded;
|
|
233
235
|
* Elysia (Bun) — one `app.use(oumv())` line before `app.listen()`
|
|
234
236
|
(`tokensafe-backend-node/elysia`), same markers and byte-exact revert.
|
|
235
237
|
3. **Brief the agent** — a short routing block (hook context and MCP `instructions`) says which
|
|
@@ -239,8 +241,8 @@ You install TokenSafe, open a project in your agent, and the first turn does the
|
|
|
239
241
|
```bash
|
|
240
242
|
tokensafe inject --status # what would be wired, and where
|
|
241
243
|
tokensafe inject --dry-run # same, but explicit
|
|
242
|
-
tokensafe inject # apply
|
|
243
|
-
tokensafe inject --revert #
|
|
244
|
+
tokensafe inject # apply every detected app (config + Python autoload + adapter lines)
|
|
245
|
+
tokensafe inject --revert # undo every patch: Go entrypoint/modules, .NET csproj, Next files, Python hook, config
|
|
244
246
|
tokensafe create shop --template react-fastapi # greenfield with everything pre-wired
|
|
245
247
|
tokensafe oumv doctor # readiness: adapter installed? runtime live? blocking reasons
|
|
246
248
|
```
|
|
@@ -621,7 +623,7 @@ TokenSafe integrates with the [OUMV Protocol](https://github.com/tokensafe-dev/o
|
|
|
621
623
|
- **Frontend**: `tokensafe-ui/react`, `tokensafe-ui/vue`, and the zero-footprint Vite bridge (`tokensafe-ui/vite`) that also serves Solid (`--framework solid`) and Angular (`--framework angular`, Vite/Analog dev server), with a session token stored in the per-workspace descriptor (`~/.tokensafe/runtimes/<hash>.json`, mode 0600).
|
|
622
624
|
- **Backend**: Go (`gin`, `chi`, `stdhttp`), Node (`express`, `fastify`, `next`, `elysia`), Python (`fastapi`, `starlette`, `flask`, `django`), ASP.NET Core and the JDK/PHP sidecars in [`tokensafe-backend`](https://github.com/tokensafe-dev/tokensafe-backend) — eighteen manifests in the [OUMV adapter matrix](https://github.com/tokensafe-dev/oumv/blob/main/docs/ADAPTERS.md), every claim backed by a committed certificate.
|
|
623
625
|
- **Guarded Mutations, Enabled by Default**: `oumv_mutate` works out of the box on Solo and above and guards every write — mandatory OCC `expectedVersion`, workspace path jail, syntax pre-flight, backup of previous bytes. Opt out with `permissions.mutate: false` in `.tokensafe/oumv.json`.
|
|
624
|
-
- **Automatic Wiring CLI**: `tokensafe inject` activates
|
|
626
|
+
- **Automatic Wiring CLI**: `tokensafe inject` activates every detected app (Vite wrapper, Python autoload, marker-delimited Go/.NET lines), `tokensafe inject --revert` undoes every patch and restores pre-existing files, and `tokensafe oumv doctor` reports readiness with blocking reasons.
|
|
625
627
|
- **Greenfield Recipes**: `tokensafe create <name> --template react-fastapi|react-go|vue-gin|fastapi|gin` generates a normal project in your stack with OUMV already wired.
|
|
626
628
|
|
|
627
629
|
More documentation: [docs/OUMV.md](docs/OUMV.md) · [docs/AGENT_SETUP.md](docs/AGENT_SETUP.md) · [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) · [docs/API.md](docs/API.md) · [METRICS.md](METRICS.md)
|
package/hooks/pre_invocation.py
CHANGED
|
@@ -252,7 +252,9 @@ def _handle(payload: dict) -> dict:
|
|
|
252
252
|
history_tokens=history_mass,
|
|
253
253
|
transcript_path=transcript_path
|
|
254
254
|
)
|
|
255
|
-
|
|
255
|
+
used_pct = budget.get("used_pct")
|
|
256
|
+
if (budget.get("measurement") == "measured"
|
|
257
|
+
and used_pct is not None and used_pct >= 80):
|
|
256
258
|
already = tracker.get_last_event(conversation_id, "BUDGET_WARNING")
|
|
257
259
|
if not already:
|
|
258
260
|
if transcript_path:
|
|
@@ -260,9 +262,10 @@ def _handle(payload: dict) -> dict:
|
|
|
260
262
|
f"now to fold past turns before continuing.")
|
|
261
263
|
else:
|
|
262
264
|
action = budget["recommendation"]
|
|
265
|
+
token_count = budget.get("used_tokens") or budget.get("used_estimated") or 0
|
|
263
266
|
warn = (
|
|
264
|
-
f"🧠 **Context Budget:** ~{
|
|
265
|
-
f"({
|
|
267
|
+
f"🧠 **Context Budget:** ~{used_pct}% of the window measured "
|
|
268
|
+
f"({token_count:,}/{budget['window_tokens']:,} prompt tokens). {action}"
|
|
266
269
|
)
|
|
267
270
|
inject_steps.append({
|
|
268
271
|
"systemMessage": {
|
|
@@ -275,7 +278,8 @@ def _handle(payload: dict) -> dict:
|
|
|
275
278
|
event_type="BUDGET_WARNING",
|
|
276
279
|
original_tokens=0,
|
|
277
280
|
optimized_tokens=0,
|
|
278
|
-
details={"used_pct":
|
|
281
|
+
details={"used_pct": used_pct, "window": budget["window_tokens"],
|
|
282
|
+
"measurement": budget.get("measurement")}
|
|
279
283
|
)
|
|
280
284
|
except Exception:
|
|
281
285
|
pass
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.2",
|
|
4
4
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
5
5
|
"homepage": "https://tokensafe.dev",
|
|
6
6
|
"license": "Apache-2.0",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.13.2",
|
|
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.13.2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Your AI agent is smart enough to code all day. Now it actually can. Local runtime firewall & zero-loss context optimizer for AI coding agents.",
|
|
7
7
|
"logo": "assets/logo.png",
|
package/rules/AGENTS.md
CHANGED
|
@@ -32,10 +32,10 @@ Execute the specified action directly based on these extracted parameters.
|
|
|
32
32
|
|
|
33
33
|
### 3. Architecture & Code Navigation Directives (7 Consolidated MCP Tools)
|
|
34
34
|
1. **Search (`scoped_search`)**: Terminal `grep`/`egrep`/`rg`/`find` on source files are BLOCKED. Call `tokensafe:scoped_search(query, path=".", scope="code")` (supports `mode="auto|text|regex|glob|fuzzy|git"`) or pass `queries=[...]` for up to 20 concurrent queries in 1 call (<70ms local).
|
|
35
|
-
2. **Symbol, Bundle & External Type Reads (`
|
|
35
|
+
2. **Single-Call Brief, Symbol, Bundle & External Type Reads**: On an OUMV-supported stack call `tokensafe:oumv(action="brief", target="<file-or-symbol>")` first — it returns the skeleton, every call site (graph edges plus `confidence: probable` text-level references), public props and mutable module state in one call, so `observe` → `smart_read_file` → `understand` chains are no longer needed. Then use `tokensafe:smart_read_file(path, symbol)` (`dep_mode="signature"` default, `"full"` when needed, `force_full=true` on pointer miss; OpenAPI/Prisma/GraphQL/SQL auto-slice via `symbol`). Pass `targets=[{path, symbol}]` (2–8 targets) to bundle files with deduplicated imports, or `package_name` + `symbol` for 3rd-party `.d.ts` interfaces.
|
|
36
36
|
3. **Architecture, API Surface & Directory Trees (`repo_map`)**: First inspect God Nodes via `tokensafe:repo_map(view="graph", project_path=...)` before crawling files. Use `view="api"` for exported types/interfaces and `view="tree"` (never `ls -la`).
|
|
37
37
|
4. **Multi-File Edits (`apply_edits`)**: Batch >=2 hunks/files and optional `verify` commands in a single turn.
|
|
38
|
-
5. **Session & Context Hygiene (`session_context`)**: Call `tokensafe:session_context(action="budget", model=...)` before large tasks
|
|
38
|
+
5. **Session & Context Hygiene (`session_context`)**: Call `tokensafe:session_context(action="budget", model=...)` before large tasks. Act only on `measurement: "measured"`: `estimated` is a cumulative floor and `unknown` (with `used_pct: null`) means pass `transcript_path`; neither is a reason to compact. When a measured `warning`/`critical` appears, call `action="compact"` with `transcript_path`. Use `action="prune"` for superseded reads, `action="mistakes"` for anti-stuck dead-end memory, and `action="metrics"` for savings analytics (`total_saved_tokens_basis` labels measured vs estimated).
|
|
39
39
|
6. **Utilities (`run_helper`)**: Call `tokensafe:run_helper(action=...)` for:
|
|
40
40
|
- `"expand"` (`hash`): restore stashed `#hash` content
|
|
41
41
|
- `"web"` (`url`): fetch clean Markdown docs (-80-95% tokens, L1/L2/L3 cached)
|
|
@@ -45,7 +45,8 @@ Execute the specified action directly based on these extracted parameters.
|
|
|
45
45
|
- `"diff"` (`diff`): slice unified git diffs
|
|
46
46
|
- `"image"` (`image_path`, `max_edge=1024`): downscale screenshots (-50-75% vision tokens)
|
|
47
47
|
- `"compress"` (`prompt`): TOCP S-expression compression
|
|
48
|
-
|
|
48
|
+
- `"bundle-probe"` (`url`, `expect`, `reject?`, `chunks?`): fetch a live entry, follow its hashed chunks, return a found/missing table (stale CDN check in one call)
|
|
49
|
+
7. **Universal OUMV Protocol (`oumv` — Mandatory When Supported)**: When a project uses an OUMV-supported stack (`frontend/react` Vite, `frontend/vue`, `frontend/solid`, `frontend/angular`, `backend/go`, `backend/fastapi`), ALWAYS prefer `tokensafe:oumv(action="status"|"brief"|"observe"|"understand"|"verify"|"mutate"|"graph", ...)` BEFORE full file crawls, raw `curl`, or headless browsers — even for read/edit tasks (static AST OUMV works offline without running dev/build). For Vite frontends, use `tokensafe dev` to start live OUMV with zero repository footprint. In mixed monorepos (e.g. React + Node.js), inspect `oumv(action="status")` / `[TokenSafe OUMV Workspace Matrix]`: use `oumv` on supported profiles and fall back to `repo_map` + `smart_read_file` + `scoped_search` for unsupported stacks (`backend/node`). **Multi-root sessions**: the routing brief is classified per workspace root — a verdict for one repo NEVER applies to another. Before editing a repo outside the roots listed in the brief, call `tokensafe:oumv(action="status", workspace_dir="<that repo>")`; never conclude "OUMV is unavailable" from a single-root brief.
|
|
49
50
|
8. **Bounded Reads & Styles**: Never call raw `read_file` without `StartLine`/`EndLine` on files > 100 lines. `smart_read_file` preserves CSS/SCSS/Tailwind design tokens (`:root`, `@theme`) in full.
|
|
50
51
|
|
|
51
52
|
### 4. Turn Token Savings Footer (Proof-of-Savings — always in English)
|
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.13.2",
|
|
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.13.2",
|
|
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.13.2",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|