tokensafe 4.12.3 → 4.13.1

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.12.3",
2
+ "version": "4.13.1",
3
3
  "name": "tokensafe",
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
  "author": {
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, `tokensafe inject --revert` restores it;
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 the safe parts (config + Python autoload + Go line)
243
- tokensafe inject --revert # restore the Go entrypoint byte-for-byte
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 adapters with zero repository footprint (Vite wrapper, Python autoload, one marker-delimited Go line), `tokensafe inject --revert` restores it, and `tokensafe oumv doctor` reports readiness with blocking reasons.
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)
@@ -252,7 +252,9 @@ def _handle(payload: dict) -> dict:
252
252
  history_tokens=history_mass,
253
253
  transcript_path=transcript_path
254
254
  )
255
- if budget["used_pct"] >= 80 and budget["instrumented_events"] >= 3:
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:** ~{budget['used_pct']}% of the estimated window used "
265
- f"({budget['used_estimated']:,}/{budget['window_tokens']:,} tokens). {action}"
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": budget["used_pct"], "window": budget["window_tokens"]}
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.12.3",
3
+ "version": "4.13.1",
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.12.3",
4
+ "version": "4.13.1",
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.12.3",
4
+ "version": "4.13.1",
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 (`smart_read_file`)**: Call `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.
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; when `warning`/`critical` or Grade C/F, 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.
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
- 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"|"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.
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.12.3",
6
+ "version": "4.13.1",
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.12.3",
26
+ "version": "4.13.1",
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.12.3",
42
+ "version": "4.13.1",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"