tokensafe 4.6.0 → 4.6.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/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/hooks/pre_tool_use.py +26 -0
- package/hooks/session_start.py +8 -2
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +2 -2
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +6 -1
- package/src/adapter_core.py +66 -4
- package/src/batch_editor.py +174 -48
- package/src/batch_search.py +124 -26
- package/src/cli.py +28 -0
- package/src/command_sanitizer.py +94 -0
- package/src/guard.py +36 -0
- package/src/installer.py +55 -5
- package/src/mcp_server.py +161 -70
- package/src/oumv_gateway.py +171 -31
- package/src/proxy.py +11 -4
- package/src/retrofit.py +380 -99
- package/src/snapshot.py +98 -27
- package/src/telemetry_sync.py +1 -1
- package/src/transcript_analyzer.py +59 -36
- package/src/version_checker.py +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/hooks/pre_tool_use.py
CHANGED
|
@@ -174,6 +174,15 @@ def _handle(payload: dict) -> dict:
|
|
|
174
174
|
except Exception:
|
|
175
175
|
pass
|
|
176
176
|
|
|
177
|
+
if canon_tool == "edit" and not response.get("reason"):
|
|
178
|
+
try:
|
|
179
|
+
from src.adapter_core import get_oumv_read_edit_advisory
|
|
180
|
+
oumv_note = get_oumv_read_edit_advisory(hook_cwd, path or raw_path, conversation_id)
|
|
181
|
+
if oumv_note:
|
|
182
|
+
response["reason"] = oumv_note
|
|
183
|
+
except Exception:
|
|
184
|
+
pass
|
|
185
|
+
|
|
177
186
|
# 3. Output Guard (shared guard_write, v3.0.0): deny wholesale overwrite of
|
|
178
187
|
# large existing files to enforce edit_file; ask on small-delta writes.
|
|
179
188
|
if canon_tool == "write":
|
|
@@ -268,6 +277,14 @@ def _handle(payload: dict) -> dict:
|
|
|
268
277
|
|
|
269
278
|
# Step 3A: If model explicitly specified line range, respect it
|
|
270
279
|
if start_line is not None and end_line is not None:
|
|
280
|
+
if not response.get("reason"):
|
|
281
|
+
try:
|
|
282
|
+
from src.adapter_core import get_oumv_read_edit_advisory
|
|
283
|
+
oumv_note = get_oumv_read_edit_advisory(hook_cwd, path or raw_path, conversation_id)
|
|
284
|
+
if oumv_note:
|
|
285
|
+
response["reason"] = oumv_note
|
|
286
|
+
except Exception:
|
|
287
|
+
pass
|
|
271
288
|
return response
|
|
272
289
|
|
|
273
290
|
# Step 3B: If a specific symbol/function is targeted in user prompt, check graph-guided skeleton first
|
|
@@ -341,6 +358,15 @@ def _handle(payload: dict) -> dict:
|
|
|
341
358
|
)
|
|
342
359
|
return response
|
|
343
360
|
|
|
361
|
+
if not response.get("reason"):
|
|
362
|
+
try:
|
|
363
|
+
from src.adapter_core import get_oumv_read_edit_advisory
|
|
364
|
+
oumv_note = get_oumv_read_edit_advisory(hook_cwd, path or raw_path, conversation_id)
|
|
365
|
+
if oumv_note:
|
|
366
|
+
response["reason"] = oumv_note
|
|
367
|
+
except Exception:
|
|
368
|
+
pass
|
|
369
|
+
|
|
344
370
|
# 4. run_command Optimization & TokenSafe Guard
|
|
345
371
|
elif canon_tool == "bash":
|
|
346
372
|
from src.guard import TokenSafeGuard
|
package/hooks/session_start.py
CHANGED
|
@@ -105,15 +105,21 @@ def main():
|
|
|
105
105
|
try:
|
|
106
106
|
if workspace_paths:
|
|
107
107
|
from src.graph_engine import GraphEngine
|
|
108
|
+
from src.retrofit import format_oumv_workspace_brief
|
|
108
109
|
graph = GraphEngine.get_instance(workspace_root)
|
|
109
110
|
banner = graph.format_topology_banner()
|
|
111
|
+
oumv_brief = format_oumv_workspace_brief(workspace_root, include_live=True)
|
|
112
|
+
extra = []
|
|
110
113
|
if banner:
|
|
111
|
-
|
|
112
|
-
f"{directives}\n\n"
|
|
114
|
+
extra.append(
|
|
113
115
|
f"{banner}\n"
|
|
114
116
|
"⚡ Core God Nodes and dependency hubs mapped above. "
|
|
115
117
|
"Call 'tokensafe:repo_map(view=\"graph\", project_path=...)' for full dependency trees."
|
|
116
118
|
)
|
|
119
|
+
if oumv_brief:
|
|
120
|
+
extra.append(oumv_brief)
|
|
121
|
+
if extra:
|
|
122
|
+
directives = f"{directives}\n\n" + "\n".join(extra)
|
|
117
123
|
except Exception:
|
|
118
124
|
pass
|
|
119
125
|
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.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": "MIT",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.6.
|
|
4
|
+
"version": "4.6.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.6.
|
|
4
|
+
"version": "4.6.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
|
"logo": "assets/logo.png",
|
|
7
7
|
"developerName": "TokenSafe",
|
package/rules/AGENTS.md
CHANGED
|
@@ -28,7 +28,7 @@ Execute the specified action directly based on these extracted parameters.
|
|
|
28
28
|
6. **Compact Test Output Execution**: Run unit tests via `tokensafe tests [cmd]` or `tokensafe wrap '<cmd>'` so passing suites return a 1-line summary (`PASS: ...`), preserving full output only on failure.
|
|
29
29
|
7. **Multimodal Image Isolation (Prompt Cache Protection)**: Never load raw `.png`/`.jpg`/`.webp` screenshots into a long (>150k-token) coding session (triggers KV-cache invalidation). Delegate visual inspection to a subagent returning text-only findings.
|
|
30
30
|
8. **Startup Snapshot Utilization**: Check `[TokenSafe Workspace Snapshot]` on turn 1 before running exploratory `ls` or `git status`.
|
|
31
|
-
9. **Zero-Spill
|
|
31
|
+
9. **Zero-Spill Response Budget & Reversible Stash**: TokenSafe MCP responses are capped per response (not per block) at ~8.8 KB of UTF-8 text, with headroom left for JSON escaping, to prevent Antigravity `output.txt` disk spills. Folded content carries a `[TokenSafe folded: #hash ...]` anchor and is archived in the stash; call `tokensafe:run_helper(action="expand", hash="...")` to restore it. If the stash write fails, the response is still truncated and the marker states that the raw copy is unavailable.
|
|
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).
|
|
@@ -45,7 +45,7 @@ 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`)**:
|
|
48
|
+
7. **Universal OUMV Protocol (`oumv` — Mandatory When Supported)**: When a project uses an OUMV-supported stack (`frontend/react` Vite, `frontend/vue`, `frontend/solid`, `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+React, 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`).
|
|
49
49
|
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
50
|
|
|
51
51
|
### 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.
|
|
6
|
+
"version": "4.6.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.6.
|
|
26
|
+
"version": "4.6.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.6.
|
|
42
|
+
"version": "4.6.2",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
|
@@ -110,7 +110,12 @@ TokenSafe actively maximizes provider KV-cache hit rates alongside token compres
|
|
|
110
110
|
|
|
111
111
|
## Universal OUMV Protocol (Runtime Introspection & Verification)
|
|
112
112
|
|
|
113
|
-
TokenSafe integrates the **Universal Agent-Runtime Protocol (UARP / OUMV)** to inspect, reason about, edit, and verify
|
|
113
|
+
TokenSafe integrates the **Universal Agent-Runtime Protocol (UARP / OUMV)** to inspect, reason about, edit, and verify Frontend (`tokensafe-ui`, React 18/19 + Vite, Vue 3) and Backend (`Go` Gin/Chi/net-http, `FastAPI`) services without heavy headless browsers or unconstrained shell curls.
|
|
114
|
+
|
|
115
|
+
### OUMV-First Policy, Zero-Footprint & Mixed Monorepos
|
|
116
|
+
- **Mandatory When Supported (Even Without Dev/Build Running)**: If the workspace contains a supported profile (`frontend/react`, `frontend/vue`, `frontend/solid`, `backend/go`, `backend/fastapi`), prefer `tokensafe:oumv` (`status` -> `observe` L0/L1/L2 -> `understand` impact -> `mutate` -> `verify`) BEFORE brute-force reading components or running `curl`/browsers. Static OUMV works offline even when the agent only reads and edits files.
|
|
117
|
+
- **Zero-Footprint Vite+React (`tokensafe dev`)**: Running `tokensafe dev` (or `vite` / `npm run dev` rewritten automatically by `CommandSanitizer`) starts the project's Vite+React DevServer with `tokensafeReact()` injected in memory and runtime state stored under `~/.tokensafe/runtimes/<hash>.json` (sidecar L2 contracts in `~/.tokensafe/contracts/<hash>.json`) — leaving **0 modified/untracked files** in the repository.
|
|
118
|
+
- **Monorepo Capability Boundaries**: In mixed monorepos (e.g., `apps/web` in React + `apps/api` in Node.js/Express), check `oumv(action="status")` or `[TokenSafe OUMV Workspace Matrix]`. Use `tokensafe:oumv(runtime="frontend")` for React, and use `repo_map` + `smart_read_file` + `scoped_search` + normal tests for unsupported backends like `backend/node` (`status: planned`).
|
|
114
119
|
|
|
115
120
|
1. **LIVE RUNTIME HEALTH (`oumv(action="status")`)**:
|
|
116
121
|
- Call `tokensafe:oumv(action="status")` to inspect connection status and capabilities of running DevServers (Frontend ports 5173/3000, Backend ports 8080/8000).
|
package/src/adapter_core.py
CHANGED
|
@@ -44,7 +44,8 @@ TOKENSAFE_DIRECTIVES = (
|
|
|
44
44
|
"• Before large multi-step tasks: call 'tokensafe:session_context(action=\"budget\", model=...)' to check context headroom and Quality Score (Grade S-F).\n"
|
|
45
45
|
"• When context budget reports warning/critical or Grade C/F: call 'tokensafe:session_context(action=\"compact\", transcript_path=...)' to fold history before continuing.\n"
|
|
46
46
|
"• Prohibited File Edits: NEVER use 'sed -i', 'perl -i', or stream editors to modify source files; ALWAYS use 'edit_file' with exact string targets. NEVER suppress errors with '2>/dev/null'.\n"
|
|
47
|
-
"• Prefer 'edit_file' over 'write_file' for existing files
|
|
47
|
+
"• Prefer 'edit_file' over 'write_file' for existing files.\n"
|
|
48
|
+
"• Universal OUMV Protocol (Mandatory When Supported): If the workspace reports an OUMV-supported stack (React+Vite, Vue, Solid, Go, FastAPI), ALWAYS prefer the 'oumv' MCP tool (status/observe/understand/verify) before full file crawls, raw curl, or browser checks — even when only reading/editing files (static AST OUMV works offline; use 'tokensafe dev' for zero-footprint live Vite+React). Check capability boundaries in mixed monorepos (for unsupported stacks like backend/node Express/Fastify/Nest, use repo_map/smart_read_file/scoped_search)."
|
|
48
49
|
)
|
|
49
50
|
|
|
50
51
|
# High-precision deny patterns: secrets and irreversible destruction only.
|
|
@@ -456,6 +457,53 @@ def _extract_path(tool_input: Dict[str, Any]) -> str:
|
|
|
456
457
|
return ""
|
|
457
458
|
|
|
458
459
|
|
|
460
|
+
def get_oumv_read_edit_advisory(workspace_dir: str, file_path: str, session_id: str = "") -> Optional[str]:
|
|
461
|
+
"""One-shot per-session advisory when reading/editing files inside an OUMV-supported stack
|
|
462
|
+
(React+Vite, Vue, Solid, Go, FastAPI) without having called `tokensafe:oumv` recently.
|
|
463
|
+
|
|
464
|
+
Returns None immediately for unsupported stacks in mixed monorepos (e.g. backend/node),
|
|
465
|
+
when OUMV was already used in this workspace, or if already nudged in this session.
|
|
466
|
+
"""
|
|
467
|
+
if not file_path:
|
|
468
|
+
return None
|
|
469
|
+
try:
|
|
470
|
+
from src.paths import get_active_workspace, resolve_data_dir
|
|
471
|
+
from src.retrofit import is_path_in_supported_oumv_scope
|
|
472
|
+
from src.oumv_gateway import OUMVGateway
|
|
473
|
+
import hashlib
|
|
474
|
+
|
|
475
|
+
ws = workspace_dir or get_active_workspace()
|
|
476
|
+
if not ws or not os.path.isdir(ws):
|
|
477
|
+
return None
|
|
478
|
+
pkg = is_path_in_supported_oumv_scope(ws, file_path)
|
|
479
|
+
if not pkg:
|
|
480
|
+
return None
|
|
481
|
+
if OUMVGateway.was_recently_used(ws):
|
|
482
|
+
return None
|
|
483
|
+
|
|
484
|
+
sess_key = hashlib.sha256(f"{session_id or 'default'}:{os.path.realpath(ws)}".encode("utf-8")).hexdigest()[:16]
|
|
485
|
+
marker = os.path.join(resolve_data_dir(), f".oumv_nudge_{sess_key}")
|
|
486
|
+
if os.path.isfile(marker):
|
|
487
|
+
return None
|
|
488
|
+
os.makedirs(os.path.dirname(marker), exist_ok=True)
|
|
489
|
+
with open(marker, "w", encoding="utf-8") as f:
|
|
490
|
+
f.write(str(time.time()))
|
|
491
|
+
|
|
492
|
+
live_ports = OUMVGateway.get_live_ports(ws)
|
|
493
|
+
if live_ports:
|
|
494
|
+
return (
|
|
495
|
+
f"[TokenSafe OUMV]: Live {pkg.get('provider')}/{pkg.get('framework')} OUMV runtime is active (port {live_ports[0]}). "
|
|
496
|
+
f"Prefer tokensafe:oumv(action='observe'|'understand'|'verify') for live DOM/state/causality instead of manual file crawling."
|
|
497
|
+
)
|
|
498
|
+
vite_tip = "; run 'tokensafe dev' for zero-footprint live Vite+React RPC" if pkg.get("vite") else ""
|
|
499
|
+
return (
|
|
500
|
+
f"[TokenSafe OUMV]: '{os.path.basename(file_path)}' belongs to an OUMV-supported {pkg.get('provider')}/{pkg.get('framework')} stack. "
|
|
501
|
+
f"Use tokensafe:oumv(action='observe', level='L1') or oumv(action='understand', query='impact') first (works statically offline{vite_tip})."
|
|
502
|
+
)
|
|
503
|
+
except Exception:
|
|
504
|
+
return None
|
|
505
|
+
|
|
506
|
+
|
|
459
507
|
def _large_read_advisory(file_path: str, tool_input: Dict[str, Any]) -> Optional[str]:
|
|
460
508
|
"""Non-blocking advisory when an agent reads an entire large code file unbounded."""
|
|
461
509
|
if not file_path or not os.path.isfile(file_path):
|
|
@@ -609,6 +657,15 @@ def evaluate_cc_pre_tool_use(payload: Dict[str, Any], agent: str) -> Dict[str, A
|
|
|
609
657
|
)
|
|
610
658
|
except Exception:
|
|
611
659
|
pass
|
|
660
|
+
oumv_note = get_oumv_read_edit_advisory(cwd, file_path, session_id)
|
|
661
|
+
if oumv_note:
|
|
662
|
+
return {
|
|
663
|
+
"hookSpecificOutput": {
|
|
664
|
+
"hookEventName": "PreToolUse",
|
|
665
|
+
"permissionDecision": "allow",
|
|
666
|
+
"additionalContext": oumv_note,
|
|
667
|
+
}
|
|
668
|
+
}
|
|
612
669
|
return {}
|
|
613
670
|
|
|
614
671
|
if canon == "read":
|
|
@@ -616,13 +673,18 @@ def evaluate_cc_pre_tool_use(payload: Dict[str, Any], agent: str) -> Dict[str, A
|
|
|
616
673
|
verdict = guard_read(file_path, agent, session_id, transcript_path=tp)
|
|
617
674
|
if verdict["decision"] == "deny":
|
|
618
675
|
return _cc_decision("deny", verdict["reason"])
|
|
619
|
-
|
|
620
|
-
|
|
676
|
+
advisories = [
|
|
677
|
+
msg for msg in (
|
|
678
|
+
_large_read_advisory(file_path, tool_input),
|
|
679
|
+
get_oumv_read_edit_advisory(cwd, file_path, session_id),
|
|
680
|
+
) if msg
|
|
681
|
+
]
|
|
682
|
+
if advisories:
|
|
621
683
|
return {
|
|
622
684
|
"hookSpecificOutput": {
|
|
623
685
|
"hookEventName": "PreToolUse",
|
|
624
686
|
"permissionDecision": "allow",
|
|
625
|
-
"additionalContext":
|
|
687
|
+
"additionalContext": "\n".join(advisories),
|
|
626
688
|
}
|
|
627
689
|
}
|
|
628
690
|
return {}
|